Skip to content

Commit 40598b9

Browse files
author
Brian Chen
authored
Merge 9f80809 into f900417
2 parents f900417 + 9f80809 commit 40598b9

File tree

12 files changed

+152
-142
lines changed

12 files changed

+152
-142
lines changed

.changeset/shiny-forks-pull.md

Lines changed: 0 additions & 7 deletions
This file was deleted.

packages/firebase/index.d.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9073,20 +9073,17 @@ declare namespace firebase.firestore {
90739073

90749074
/**
90759075
* Filter conditions in a `Query.where()` clause are specified using the
9076-
* strings '<', '<=', '==', '!=', '>=', '>', 'array-contains', 'in',
9077-
* 'array-contains-any', and 'not-in'.
9076+
* strings '<', '<=', '==', '>=', '>', 'array-contains', 'in', and 'array-contains-any'.
90789077
*/
90799078
export type WhereFilterOp =
90809079
| '<'
90819080
| '<='
90829081
| '=='
9083-
| '!='
90849082
| '>='
90859083
| '>'
90869084
| 'array-contains'
90879085
| 'in'
9088-
| 'array-contains-any'
9089-
| 'not-in';
9086+
| 'array-contains-any';
90909087

90919088
/**
90929089
* A `Query` refers to a Query which you can read or listen to. You can also

packages/firestore-types/index.d.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,13 +294,11 @@ export type WhereFilterOp =
294294
| '<'
295295
| '<='
296296
| '=='
297-
| '!='
298297
| '>='
299298
| '>'
300299
| 'array-contains'
301300
| 'in'
302-
| 'array-contains-any'
303-
| 'not-in';
301+
| 'array-contains-any';
304302

305303
export class Query<T = DocumentData> {
306304
protected constructor();

packages/firestore/exp-types/index.d.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,13 +277,11 @@ export type WhereFilterOp =
277277
| '<'
278278
| '<='
279279
| '=='
280-
| '!='
281280
| '>='
282281
| '>'
283282
| 'array-contains'
284283
| 'in'
285-
| 'array-contains-any'
286-
| 'not-in';
284+
| 'array-contains-any';
287285

288286
export class Query<T = DocumentData> {
289287
protected constructor();

packages/firestore/lite-types/index.d.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,11 @@ export type WhereFilterOp =
227227
| '<'
228228
| '<='
229229
| '=='
230-
| '!='
231230
| '>='
232231
| '>'
233232
| 'array-contains'
234233
| 'in'
235-
| 'array-contains-any'
236-
| 'not-in';
234+
| 'array-contains-any';
237235

238236
export class Query<T = DocumentData> {
239237
protected constructor();

packages/firestore/src/api/database.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1882,20 +1882,24 @@ export class Query<T = DocumentData> implements PublicQuery<T> {
18821882
validateExactNumberOfArgs('Query.where', arguments, 3);
18831883
validateDefined('Query.where', 3, value);
18841884

1885-
// Enumerated from the WhereFilterOp type in index.d.ts.
1886-
const whereFilterOpEnums = [
1887-
Operator.LESS_THAN,
1888-
Operator.LESS_THAN_OR_EQUAL,
1889-
Operator.EQUAL,
1890-
Operator.NOT_EQUAL,
1891-
Operator.GREATER_THAN_OR_EQUAL,
1892-
Operator.GREATER_THAN,
1893-
Operator.ARRAY_CONTAINS,
1894-
Operator.IN,
1895-
Operator.ARRAY_CONTAINS_ANY,
1896-
Operator.NOT_IN
1897-
];
1898-
const op = validateStringEnum('Query.where', whereFilterOpEnums, 2, opStr);
1885+
// TODO(ne-queries): Add 'not-in' and '!=' to validation.
1886+
let op: Operator;
1887+
if ((opStr as unknown) === 'not-in' || (opStr as unknown) === '!=') {
1888+
op = opStr as Operator;
1889+
} else {
1890+
// Enumerated from the WhereFilterOp type in index.d.ts.
1891+
const whereFilterOpEnums = [
1892+
Operator.LESS_THAN,
1893+
Operator.LESS_THAN_OR_EQUAL,
1894+
Operator.EQUAL,
1895+
Operator.GREATER_THAN_OR_EQUAL,
1896+
Operator.GREATER_THAN,
1897+
Operator.ARRAY_CONTAINS,
1898+
Operator.IN,
1899+
Operator.ARRAY_CONTAINS_ANY
1900+
];
1901+
op = validateStringEnum('Query.where', whereFilterOpEnums, 2, opStr);
1902+
}
18991903

19001904
const fieldPath = fieldPathFromArgument('Query.where', field);
19011905
const filter = newQueryFilter(

packages/firestore/src/core/query.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -605,17 +605,19 @@ export class FieldFilter extends Filter {
605605
}
606606
} else if (isNullValue(value)) {
607607
if (op !== Operator.EQUAL && op !== Operator.NOT_EQUAL) {
608+
// TODO(ne-queries): Update error message to include != comparison.
608609
throw new FirestoreError(
609610
Code.INVALID_ARGUMENT,
610-
"Invalid query. Null only supports '==' and '!=' comparisons."
611+
'Invalid query. Null supports only equality comparisons.'
611612
);
612613
}
613614
return new FieldFilter(field, op, value);
614615
} else if (isNanValue(value)) {
615616
if (op !== Operator.EQUAL && op !== Operator.NOT_EQUAL) {
617+
// TODO(ne-queries): Update error message to include != comparison.
616618
throw new FirestoreError(
617619
Code.INVALID_ARGUMENT,
618-
"Invalid query. NaN only supports '==' and '!=' comparisons."
620+
'Invalid query. NaN supports only equality comparisons.'
619621
);
620622
}
621623
return new FieldFilter(field, op, value);
@@ -709,8 +711,7 @@ export class FieldFilter extends Filter {
709711
Operator.LESS_THAN_OR_EQUAL,
710712
Operator.GREATER_THAN,
711713
Operator.GREATER_THAN_OR_EQUAL,
712-
Operator.NOT_EQUAL,
713-
Operator.NOT_IN
714+
Operator.NOT_EQUAL
714715
].indexOf(this.op) >= 0
715716
);
716717
}

packages/firestore/test/integration/api/database.test.ts

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import { EventsAccumulator } from '../util/events_accumulator';
2525
import * as firebaseExport from '../util/firebase_export';
2626
import {
2727
apiDescribe,
28+
notEqualOp,
29+
notInOp,
2830
withTestCollection,
2931
withTestDb,
3032
withTestDbs,
@@ -642,6 +644,14 @@ apiDescribe('Database', (persistence: boolean) => {
642644
});
643645
});
644646

647+
it('inequality and NOT_IN on different fields works', () => {
648+
return withTestCollection(persistence, {}, async coll => {
649+
expect(() =>
650+
coll.where('x', '>=', 32).where('y', notInOp, [1, 2])
651+
).not.to.throw();
652+
});
653+
});
654+
645655
it('inequality and array-contains-any on different fields works', () => {
646656
return withTestCollection(persistence, {}, async coll => {
647657
expect(() =>
@@ -659,8 +669,12 @@ apiDescribe('Database', (persistence: boolean) => {
659669

660670
it('!= same as orderBy works.', () => {
661671
return withTestCollection(persistence, {}, async coll => {
662-
expect(() => coll.where('x', '!=', 32).orderBy('x')).not.to.throw();
663-
expect(() => coll.orderBy('x').where('x', '!=', 32)).not.to.throw();
672+
expect(() =>
673+
coll.where('x', notEqualOp, 32).orderBy('x')
674+
).not.to.throw();
675+
expect(() =>
676+
coll.orderBy('x').where('x', notEqualOp, 32)
677+
).not.to.throw();
664678
});
665679
});
666680

@@ -678,10 +692,10 @@ apiDescribe('Database', (persistence: boolean) => {
678692
it('!= same as first orderBy works.', () => {
679693
return withTestCollection(persistence, {}, async coll => {
680694
expect(() =>
681-
coll.where('x', '!=', 32).orderBy('x').orderBy('y')
695+
coll.where('x', notEqualOp, 32).orderBy('x').orderBy('y')
682696
).not.to.throw();
683697
expect(() =>
684-
coll.orderBy('x').where('x', '!=', 32).orderBy('y')
698+
coll.orderBy('x').where('x', notEqualOp, 32).orderBy('y')
685699
).not.to.throw();
686700
});
687701
});
@@ -706,6 +720,14 @@ apiDescribe('Database', (persistence: boolean) => {
706720
});
707721
});
708722

723+
it('NOT_IN different than orderBy works', () => {
724+
return withTestCollection(persistence, {}, async coll => {
725+
expect(() =>
726+
coll.orderBy('x').where('y', notInOp, [1, 2])
727+
).not.to.throw();
728+
});
729+
});
730+
709731
it('array-contains-any different than orderBy works', () => {
710732
return withTestCollection(persistence, {}, async coll => {
711733
expect(() =>

0 commit comments

Comments
 (0)