@@ -24,51 +24,67 @@ const checkCondition = (condition, fieldName) => {
2424 return condition . forEach ( ( item ) => checkCondition ( item , fieldName ) ) ;
2525 }
2626
27+ if ( condition . hasOwnProperty ( 'and' ) && ! Array . isArray ( condition . and ) ) {
28+ throw new DefaultSchemaError ( `
29+ Error occured in field definition with "name" property: "${ fieldName } ".
30+ 'and' property in a field condition must be an array! Received: ${ typeof condition . and } .
31+ ` ) ;
32+ }
33+
34+ if ( condition . hasOwnProperty ( 'or' ) && ! Array . isArray ( condition . and ) ) {
35+ throw new DefaultSchemaError ( `
36+ Error occured in field definition with "name" property: "${ fieldName } ".
37+ 'or' propery in a field condition must be an array! Received: ${ typeof condition . and } .
38+ ` ) ;
39+ }
40+
2741 if ( typeof condition !== 'object' ) {
2842 throw new DefaultSchemaError ( `
2943 Error occured in field definition with name: "${ fieldName } ".
3044 Field condition must be an object, received ${ Array . isArray ( condition ) ? 'array' : typeof condition } !
3145 ` ) ;
3246 }
3347
34- if ( ! condition . hasOwnProperty ( 'when' ) ) {
35- throw new DefaultSchemaError ( `
48+ if ( ! condition . hasOwnProperty ( 'and' ) && ! condition . hasOwnProperty ( 'or' ) && ! condition . hasOwnProperty ( 'not' ) ) {
49+ if ( ! condition . hasOwnProperty ( 'when' ) ) {
50+ throw new DefaultSchemaError ( `
3651 Error occured in field definition with "name" property: "${ fieldName } ".
3752 Field condition must have "when" property! Properties received: [${ Object . keys ( condition ) } ].
3853 ` ) ;
39- }
54+ }
4055
41- if ( ! ( typeof condition . when === 'string' || Array . isArray ( condition . when ) ) ) {
42- throw new DefaultSchemaError ( `
56+ if ( ! ( typeof condition . when === 'string' || Array . isArray ( condition . when ) ) ) {
57+ throw new DefaultSchemaError ( `
4358 Error occured in field definition with name: "${ fieldName } ".
4459 Field condition property "when" must be oof type "string", ${ typeof condition . when } received!].
4560 ` ) ;
46- }
61+ }
4762
48- if (
49- ! condition . hasOwnProperty ( 'is' ) &&
50- ! condition . hasOwnProperty ( 'isEmpty' ) &&
51- ! condition . hasOwnProperty ( 'isNotEmpty' ) &&
52- ! condition . hasOwnProperty ( 'pattern' )
53- ) {
54- throw new DefaultSchemaError ( `
63+ if (
64+ ! condition . hasOwnProperty ( 'is' ) &&
65+ ! condition . hasOwnProperty ( 'isEmpty' ) &&
66+ ! condition . hasOwnProperty ( 'isNotEmpty' ) &&
67+ ! condition . hasOwnProperty ( 'pattern' )
68+ ) {
69+ throw new DefaultSchemaError ( `
5570 Error occured in field definition with name: "${ fieldName } ".
5671 Field condition must have one of "is", "isEmpty", "isNotEmpty", "pattern" property! Properties received: [${ Object . keys ( condition ) } ].
5772 ` ) ;
58- }
73+ }
5974
60- if ( condition . hasOwnProperty ( 'notMatch' ) && ! condition . hasOwnProperty ( 'pattern' ) && ! condition . hasOwnProperty ( 'is' ) ) {
61- throw new DefaultSchemaError ( `
75+ if ( condition . hasOwnProperty ( 'notMatch' ) && ! condition . hasOwnProperty ( 'pattern' ) && ! condition . hasOwnProperty ( 'is' ) ) {
76+ throw new DefaultSchemaError ( `
6277 Error occured in field definition with name: "${ fieldName } ".
6378 Field condition must have "pattern" or "is" property when "notMatch" is set! Properties received: [${ Object . keys ( condition ) } ].
6479 ` ) ;
65- }
80+ }
6681
67- if ( condition . hasOwnProperty ( 'pattern' ) && ! ( condition . pattern instanceof RegExp ) && typeof condition . pattern !== 'string' ) {
68- throw new DefaultSchemaError ( `
82+ if ( condition . hasOwnProperty ( 'pattern' ) && ! ( condition . pattern instanceof RegExp ) && typeof condition . pattern !== 'string' ) {
83+ throw new DefaultSchemaError ( `
6984 Error occured in field definition with name: "${ fieldName } ".
7085 Field condition must have "pattern" of instance "RegExp" or "string"! Instance received: [${ condition . pattern . constructor . name } ].
7186 ` ) ;
87+ }
7288 }
7389} ;
7490
0 commit comments