-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: validation for store.add() (#165)
- Loading branch information
Showing
7 changed files
with
262 additions
and
3 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
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,40 @@ | ||
module.exports = validate | ||
|
||
var Promise = require('lie') | ||
|
||
function validate (state, doc) { | ||
if (state.validate === undefined) { | ||
return Promise.resolve() | ||
} | ||
|
||
return Promise.resolve() | ||
|
||
.then(function () { | ||
return state.validate(doc) | ||
}) | ||
.catch(function (rejectValue) { | ||
var error = new Error() | ||
|
||
if (rejectValue instanceof Error) { | ||
Object.keys(rejectValue).map(function (key) { | ||
error[key] = rejectValue[key] | ||
}) | ||
|
||
if (rejectValue.message) { | ||
error.message = rejectValue.message | ||
} else { | ||
error.message = 'document validation failed' | ||
} | ||
} else { | ||
if (typeof rejectValue === 'string') { | ||
error.message = rejectValue | ||
} else { | ||
error.message = 'check error value for more details' | ||
error.value = rejectValue | ||
} | ||
} | ||
|
||
error.name = 'ValidationError' | ||
throw error | ||
}) | ||
} |
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