@@ -61,10 +61,21 @@ function serializeSetMembership(symbol: string): SetOperatorSerializer {
6161 } ;
6262}
6363
64+ const serializeAnyMembership = serializeSetMembership ( '' ) ;
65+
6466const SET_OPERATOR_SERIALIZERS : Record < string , SetOperatorSerializer > = {
65- 'is-any' : serializeSetMembership ( '' ) ,
67+ 'is-any' : serializeAnyMembership ,
6668 'is-not-any' : serializeSetMembership ( '-' ) ,
67- 'is-all' : ( field , values , config ) => `(${ values . map ( value => `${ field } :${ serializeScalarValue ( value , config ) } ` ) . join ( '+' ) } )`
69+ 'is-all' : ( field , values , config ) => {
70+ // NQL's all-of operator is a `+`-separated value list: `label:[a+b]`.
71+ // A single value is identical to any-of (and `[a]` is `$in` regardless),
72+ // so only emit the all-of form for two or more values.
73+ if ( values . length === 1 ) {
74+ return serializeAnyMembership ( field , values , config ) ;
75+ }
76+
77+ return `${ field } :[${ values . map ( value => serializeScalarValue ( value , config ) ) . join ( '+' ) } ]` ;
78+ }
6879} ;
6980
7081const UNQUOTED_TOKEN_PATTERN = / ^ [ A - Z a - z 0 - 9 _ . - ] + $ / ;
@@ -135,7 +146,7 @@ export function scalarCodec(config?: CodecConfig): FilterCodec {
135146 const comparator = extractComparator ( node as Record < string , unknown > ) ;
136147 const field = getCodecField ( config , ctx . key ) ;
137148
138- if ( ! comparator || comparator . field !== field ) {
149+ if ( ! comparator || comparator . field !== field && comparator . field !== ctx . matchedKey ) {
139150 return null ;
140151 }
141152
@@ -178,7 +189,7 @@ export function textCodec(config?: CodecConfig): FilterCodec {
178189 const comparator = extractComparator ( node as Record < string , unknown > ) ;
179190 const field = getCodecField ( config , ctx . key ) ;
180191
181- if ( ! comparator || comparator . field !== field ) {
192+ if ( ! comparator || comparator . field !== field && comparator . field !== ctx . matchedKey ) {
182193 return null ;
183194 }
184195
@@ -237,7 +248,7 @@ export function setCodec(config?: CodecConfig): FilterCodec {
237248 const comparator = extractComparator ( node as Record < string , unknown > ) ;
238249 const field = getCodecField ( config , ctx . key ) ;
239250
240- if ( ! comparator || comparator . field !== field ) {
251+ if ( ! comparator || comparator . field !== field && comparator . field !== ctx . matchedKey ) {
241252 return null ;
242253 }
243254
@@ -249,6 +260,14 @@ export function setCodec(config?: CodecConfig): FilterCodec {
249260 } ;
250261 }
251262
263+ if ( comparator . operator === '$all' && Array . isArray ( comparator . value ) ) {
264+ return {
265+ field : ctx . key ,
266+ operator : 'is-all' ,
267+ values : comparator . value
268+ } ;
269+ }
270+
252271 if ( comparator . operator === '$nin' && Array . isArray ( comparator . value ) ) {
253272 return {
254273 field : ctx . key ,
@@ -299,7 +318,7 @@ export function numberCodec(config?: CodecConfig): FilterCodec {
299318 const comparator = extractComparator ( node as Record < string , unknown > ) ;
300319 const field = getCodecField ( config , ctx . key ) ;
301320
302- if ( ! comparator || comparator . field !== field || typeof comparator . value !== 'number' ) {
321+ if ( ! comparator || comparator . field !== field && comparator . field !== ctx . matchedKey || typeof comparator . value !== 'number' ) {
303322 return null ;
304323 }
305324
@@ -371,7 +390,7 @@ export function dateCodec(config?: CodecConfig): FilterCodec {
371390 const comparator = extractComparator ( node as Record < string , unknown > ) ;
372391 const field = getCodecField ( config , ctx . key ) ;
373392
374- if ( ! comparator || comparator . field !== field ) {
393+ if ( ! comparator || comparator . field !== field && comparator . field !== ctx . matchedKey ) {
375394 return null ;
376395 }
377396
0 commit comments