@@ -144,8 +144,10 @@ module.exports = Any.extend({
144144
145145 if ( schema . $_terms . dependencies ) {
146146 for ( const dep of schema . $_terms . dependencies ) {
147- if ( dep . key &&
148- dep . key . resolve ( value , state , prefs , null , { shadow : false } ) === undefined ) {
147+ if (
148+ dep . key !== null &&
149+ internals . isPresent ( dep . options ) ( dep . key . resolve ( value , state , prefs , null , { shadow : false } ) ) === false
150+ ) {
149151
150152 continue ;
151153 }
@@ -595,7 +597,7 @@ internals.dependency = function (schema, rel, key, peers, options) {
595597 options = peers . length > 1 && typeof peers [ peers . length - 1 ] === 'object' ? peers . pop ( ) : { } ;
596598 }
597599
598- Common . assertOptions ( options , [ 'separator' ] ) ;
600+ Common . assertOptions ( options , [ 'separator' , 'isPresent' ] ) ;
599601
600602 peers = [ ] . concat ( peers ) ;
601603
@@ -618,7 +620,7 @@ internals.dependency = function (schema, rel, key, peers, options) {
618620
619621 const obj = schema . clone ( ) ;
620622 obj . $_terms . dependencies = obj . $_terms . dependencies || [ ] ;
621- obj . $_terms . dependencies . push ( new internals . Dependency ( rel , key , paths , peers ) ) ;
623+ obj . $_terms . dependencies . push ( new internals . Dependency ( rel , key , paths , peers , options ) ) ;
622624 return obj ;
623625} ;
624626
@@ -630,8 +632,9 @@ internals.dependencies = {
630632 const missing = [ ] ;
631633 const present = [ ] ;
632634 const count = dep . peers . length ;
635+ const isPresent = internals . isPresent ( dep . options ) ;
633636 for ( const peer of dep . peers ) {
634- if ( peer . resolve ( value , state , prefs , null , { shadow : false } ) === undefined ) {
637+ if ( isPresent ( peer . resolve ( value , state , prefs , null , { shadow : false } ) ) === false ) {
635638 missing . push ( peer . key ) ;
636639 }
637640 else {
@@ -657,8 +660,9 @@ internals.dependencies = {
657660 nand ( schema , dep , value , state , prefs ) {
658661
659662 const present = [ ] ;
663+ const isPresent = internals . isPresent ( dep . options ) ;
660664 for ( const peer of dep . peers ) {
661- if ( peer . resolve ( value , state , prefs , null , { shadow : false } ) !== undefined ) {
665+ if ( isPresent ( peer . resolve ( value , state , prefs , null , { shadow : false } ) ) ) {
662666 present . push ( peer . key ) ;
663667 }
664668 }
@@ -682,8 +686,9 @@ internals.dependencies = {
682686
683687 or ( schema , dep , value , state , prefs ) {
684688
689+ const isPresent = internals . isPresent ( dep . options ) ;
685690 for ( const peer of dep . peers ) {
686- if ( peer . resolve ( value , state , prefs , null , { shadow : false } ) !== undefined ) {
691+ if ( isPresent ( peer . resolve ( value , state , prefs , null , { shadow : false } ) ) ) {
687692 return ;
688693 }
689694 }
@@ -700,8 +705,9 @@ internals.dependencies = {
700705 oxor ( schema , dep , value , state , prefs ) {
701706
702707 const present = [ ] ;
708+ const isPresent = internals . isPresent ( dep . options ) ;
703709 for ( const peer of dep . peers ) {
704- if ( peer . resolve ( value , state , prefs , null , { shadow : false } ) !== undefined ) {
710+ if ( isPresent ( peer . resolve ( value , state , prefs , null , { shadow : false } ) ) ) {
705711 present . push ( peer . key ) ;
706712 }
707713 }
@@ -720,8 +726,9 @@ internals.dependencies = {
720726
721727 with ( schema , dep , value , state , prefs ) {
722728
729+ const isPresent = internals . isPresent ( dep . options ) ;
723730 for ( const peer of dep . peers ) {
724- if ( peer . resolve ( value , state , prefs , null , { shadow : false } ) === undefined ) {
731+ if ( isPresent ( peer . resolve ( value , state , prefs , null , { shadow : false } ) ) === false ) {
725732 return {
726733 code : 'object.with' ,
727734 context : {
@@ -737,8 +744,9 @@ internals.dependencies = {
737744
738745 without ( schema , dep , value , state , prefs ) {
739746
747+ const isPresent = internals . isPresent ( dep . options ) ;
740748 for ( const peer of dep . peers ) {
741- if ( peer . resolve ( value , state , prefs , null , { shadow : false } ) !== undefined ) {
749+ if ( isPresent ( peer . resolve ( value , state , prefs , null , { shadow : false } ) ) ) {
742750 return {
743751 code : 'object.without' ,
744752 context : {
@@ -755,8 +763,9 @@ internals.dependencies = {
755763 xor ( schema , dep , value , state , prefs ) {
756764
757765 const present = [ ] ;
766+ const isPresent = internals . isPresent ( dep . options ) ;
758767 for ( const peer of dep . peers ) {
759- if ( peer . resolve ( value , state , prefs , null , { shadow : false } ) !== undefined ) {
768+ if ( isPresent ( peer . resolve ( value , state , prefs , null , { shadow : false } ) ) ) {
760769 present . push ( peer . key ) ;
761770 }
762771 }
@@ -787,6 +796,12 @@ internals.keysToLabels = function (schema, keys) {
787796} ;
788797
789798
799+ internals . isPresent = function ( options ) {
800+
801+ return typeof options . isPresent === 'function' ? options . isPresent : ( resolved ) => resolved !== undefined ;
802+ } ;
803+
804+
790805internals . rename = function ( schema , value , state , prefs , errors ) {
791806
792807 const renamed = { } ;
@@ -992,12 +1007,13 @@ internals.unknown = function (schema, value, unprocessed, errors, state, prefs)
9921007
9931008internals . Dependency = class {
9941009
995- constructor ( rel , key , peers , paths ) {
1010+ constructor ( rel , key , peers , paths , options ) {
9961011
9971012 this . rel = rel ;
9981013 this . key = key ;
9991014 this . peers = peers ;
10001015 this . paths = paths ;
1016+ this . options = options ;
10011017 }
10021018
10031019 describe ( ) {
@@ -1012,7 +1028,11 @@ internals.Dependency = class {
10121028 }
10131029
10141030 if ( this . peers [ 0 ] . separator !== '.' ) {
1015- desc . options = { separator : this . peers [ 0 ] . separator } ;
1031+ desc . options = { ...desc . options , separator : this . peers [ 0 ] . separator } ;
1032+ }
1033+
1034+ if ( this . options . isPresent ) {
1035+ desc . options = { ...desc . options , isPresent : this . options . isPresent } ;
10161036 }
10171037
10181038 return desc ;
0 commit comments