@@ -223,8 +223,9 @@ function transformQueryKeyValue(className, key, value, schema) {
223
223
}
224
224
225
225
// Handle query constraints
226
- if ( transformConstraint ( value , expectedTypeIsArray ) !== CannotTransform ) {
227
- return { key, value : transformConstraint ( value , expectedTypeIsArray ) } ;
226
+ const transformedConstraint = transformConstraint ( value , expectedTypeIsArray ) ;
227
+ if ( transformedConstraint !== CannotTransform ) {
228
+ return { key, value : transformedConstraint } ;
228
229
}
229
230
230
231
if ( expectedTypeIsArray && ! ( value instanceof Array ) ) {
@@ -508,7 +509,14 @@ function transformConstraint(constraint, inArray) {
508
509
if ( typeof constraint !== 'object' || ! constraint ) {
509
510
return CannotTransform ;
510
511
}
511
-
512
+ const transformFunction = inArray ? transformInteriorAtom : transformTopLevelAtom ;
513
+ const transformer = ( atom ) => {
514
+ const result = transformFunction ( atom ) ;
515
+ if ( result === CannotTransform ) {
516
+ throw new Parse . Error ( Parse . Error . INVALID_JSON , `bad atom: ${ JSON . stringify ( atom ) } ` ) ;
517
+ }
518
+ return result ;
519
+ }
512
520
// keys is the constraints in reverse alphabetical order.
513
521
// This is a hack so that:
514
522
// $regex is handled before $options
@@ -524,10 +532,7 @@ function transformConstraint(constraint, inArray) {
524
532
case '$exists' :
525
533
case '$ne' :
526
534
case '$eq' :
527
- answer [ key ] = inArray ? transformInteriorAtom ( constraint [ key ] ) : transformTopLevelAtom ( constraint [ key ] ) ;
528
- if ( answer [ key ] === CannotTransform ) {
529
- throw new Parse . Error ( Parse . Error . INVALID_JSON , `bad atom: ${ constraint [ key ] } ` ) ;
530
- }
535
+ answer [ key ] = transformer ( constraint [ key ] ) ;
531
536
break ;
532
537
533
538
case '$in' :
@@ -536,12 +541,14 @@ function transformConstraint(constraint, inArray) {
536
541
if ( ! ( arr instanceof Array ) ) {
537
542
throw new Parse . Error ( Parse . Error . INVALID_JSON , 'bad ' + key + ' value' ) ;
538
543
}
539
- answer [ key ] = arr . map ( value => {
540
- const result = inArray ? transformInteriorAtom ( value ) : transformTopLevelAtom ( value ) ;
541
- if ( result === CannotTransform ) {
542
- throw new Parse . Error ( Parse . Error . INVALID_JSON , `bad atom: ${ value } ` ) ;
543
- }
544
- return result ;
544
+ answer [ key ] = _ . flatMap ( arr , value => {
545
+ return ( ( atom ) => {
546
+ if ( Array . isArray ( atom ) ) {
547
+ return value . map ( transformer ) ;
548
+ } else {
549
+ return transformer ( atom ) ;
550
+ }
551
+ } ) ( value ) ;
545
552
} ) ;
546
553
break ;
547
554
}
0 commit comments