@@ -40,7 +40,10 @@ function proxyContext(context) {
4040const availableModifiers = {
4141 not : {
4242 simple : fn => value => ! fn ( value ) ,
43- async : fn => value => Promise . resolve ( fn ( value ) ) . then ( result => ! result )
43+ async : fn => value =>
44+ Promise . resolve ( fn ( value ) )
45+ . then ( result => ! result )
46+ . catch ( e => true )
4447 } ,
4548
4649 some : {
@@ -57,7 +60,7 @@ const availableModifiers = {
5760 return Promise . all (
5861 split ( value ) . map ( item => {
5962 try {
60- return fn ( item ) ;
63+ return fn ( item ) . catch ( e => false ) ;
6164 } catch ( ex ) {
6265 return false ;
6366 }
@@ -206,21 +209,40 @@ function isIntegerPolyfill(value) {
206209}
207210
208211function testSchema ( schema ) {
209- return value => {
210- const causes = [ ] ;
211- Object . keys ( schema ) . forEach ( key => {
212- const nestedValidation = schema [ key ] ;
213- try {
214- nestedValidation . check ( ( value || { } ) [ key ] ) ;
215- } catch ( ex ) {
216- ex . target = key ;
217- causes . push ( ex ) ;
212+ return {
213+ simple : value => {
214+ const causes = [ ] ;
215+ Object . keys ( schema ) . forEach ( key => {
216+ const nestedValidation = schema [ key ] ;
217+ try {
218+ nestedValidation . check ( ( value || { } ) [ key ] ) ;
219+ } catch ( ex ) {
220+ ex . target = key ;
221+ causes . push ( ex ) ;
222+ }
223+ } ) ;
224+ if ( causes . length > 0 ) {
225+ throw causes ;
218226 }
219- } ) ;
220- if ( causes . length > 0 ) {
221- throw causes ;
227+ return true ;
228+ } ,
229+ async : value => {
230+ const causes = [ ] ;
231+ const nested = Object . keys ( schema ) . map ( key => {
232+ const nestedValidation = schema [ key ] ;
233+ return nestedValidation . testAsync ( ( value || { } ) [ key ] ) . catch ( ex => {
234+ ex . target = key ;
235+ causes . push ( ex ) ;
236+ } ) ;
237+ } ) ;
238+ return Promise . all ( nested ) . then ( values => {
239+ if ( causes . length > 0 ) {
240+ throw causes ;
241+ }
242+
243+ return true ;
244+ } ) ;
222245 }
223- return true ;
224246 } ;
225247}
226248
0 commit comments