-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
146 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Coerces given headers to an empty Object in case not present. | ||
// Conceptually, diff between missing headers and empty headers | ||
// should be treated the same. | ||
const coerceHeaders = (headers) => { | ||
return !headers ? {} : headers; | ||
}; | ||
|
||
module.exports = { coerceHeaders }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const evolve = require('../../utils/evolve'); | ||
const { coerceHeaders } = require('./coerceHeaders'); | ||
|
||
const coercionMap = { | ||
headers: coerceHeaders | ||
}; | ||
|
||
// Coercion uses strict evolve to ensure the properties | ||
// set in expected schema are set on the result object, | ||
// even if not present in data object. This is what | ||
// coercion is about, in the end. | ||
const coerce = evolve(coercionMap, { strict: true }); | ||
const coerceWeak = evolve(coercionMap); | ||
|
||
module.exports = { coerce, coerceWeak }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters