Skip to content

Commit 4e7c5af

Browse files
committed
Relaxing query restrictions.
1 parent 8c0f205 commit 4e7c5af

File tree

3 files changed

+5
-169
lines changed

3 files changed

+5
-169
lines changed

packages/firestore/src/core/query.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,6 @@ export function queryMatchesAllDocuments(query: Query): boolean {
165165
);
166166
}
167167

168-
export function queryContainsCompositeFilters(query: Query): boolean {
169-
return (
170-
query.filters.find(filter => filter instanceof CompositeFilter) !==
171-
undefined
172-
);
173-
}
174-
175168
export function getFirstOrderByField(query: Query): FieldPath | null {
176169
return query.explicitOrderBy.length > 0
177170
? query.explicitOrderBy[0].field

packages/firestore/src/lite-api/query.ts

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,43 +1050,27 @@ function validateDisjunctiveFilterElements(
10501050
`'${operator.toString()}' filters.`
10511051
);
10521052
}
1053-
if (value.length > 10) {
1054-
throw new FirestoreError(
1055-
Code.INVALID_ARGUMENT,
1056-
`Invalid Query. '${operator.toString()}' filters support a ` +
1057-
'maximum of 10 elements in the value array.'
1058-
);
1059-
}
10601053
}
10611054

10621055
/**
10631056
* Given an operator, returns the set of operators that cannot be used with it.
10641057
*
1065-
* Operators in a query must adhere to the following set of rules:
1066-
* 1. Only one array operator is allowed.
1067-
* 2. Only one disjunctive operator is allowed.
1068-
* 3. `NOT_EQUAL` cannot be used with another `NOT_EQUAL` operator.
1069-
* 4. `NOT_IN` cannot be used with array, disjunctive, or `NOT_EQUAL` operators.
1058+
* This is not a comprehensive check, and this function should be removed in the
1059+
* long term. Validations should occur in the Firestore backend.
10701060
*
1071-
* Array operators: `ARRAY_CONTAINS`, `ARRAY_CONTAINS_ANY`
1072-
* Disjunctive operators: `IN`, `ARRAY_CONTAINS_ANY`, `NOT_IN`
1061+
* Operators in a query must adhere to the following set of rules:
1062+
* 1. Only one inequality per query.
1063+
* 2. `NOT_IN` cannot be used with array, disjunctive, or `NOT_EQUAL` operators.
10731064
*/
10741065
function conflictingOps(op: Operator): Operator[] {
10751066
switch (op) {
10761067
case Operator.NOT_EQUAL:
10771068
return [Operator.NOT_EQUAL, Operator.NOT_IN];
1078-
case Operator.ARRAY_CONTAINS:
10791069
case Operator.ARRAY_CONTAINS_ANY:
1080-
return [
1081-
Operator.ARRAY_CONTAINS,
1082-
Operator.ARRAY_CONTAINS_ANY,
1083-
Operator.NOT_IN
1084-
];
10851070
case Operator.IN:
10861071
return [Operator.NOT_IN];
10871072
case Operator.NOT_IN:
10881073
return [
1089-
Operator.ARRAY_CONTAINS,
10901074
Operator.ARRAY_CONTAINS_ANY,
10911075
Operator.IN,
10921076
Operator.NOT_IN,

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

Lines changed: 0 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -894,51 +894,6 @@ apiDescribe('Validation:', (persistence: boolean) => {
894894
}
895895
);
896896

897-
validationIt(persistence, 'with multiple array filters fail', db => {
898-
expect(() =>
899-
query(
900-
collection(db, 'test'),
901-
where('foo', 'array-contains', 1),
902-
where('foo', 'array-contains', 2)
903-
)
904-
).to.throw(
905-
"Invalid query. You cannot use more than one 'array-contains' filter."
906-
);
907-
908-
expect(() =>
909-
query(
910-
collection(db, 'test'),
911-
where('foo', 'array-contains', 1),
912-
where('foo', 'array-contains-any', [2, 3])
913-
)
914-
).to.throw(
915-
"Invalid query. You cannot use 'array-contains-any' filters with " +
916-
"'array-contains' filters."
917-
);
918-
919-
expect(() =>
920-
query(
921-
collection(db, 'test'),
922-
where('foo', 'array-contains-any', [2, 3]),
923-
where('foo', 'array-contains', 1)
924-
)
925-
).to.throw(
926-
"Invalid query. You cannot use 'array-contains' filters with " +
927-
"'array-contains-any' filters."
928-
);
929-
930-
expect(() =>
931-
query(
932-
collection(db, 'test'),
933-
where('foo', 'not-in', [2, 3]),
934-
where('foo', 'array-contains', 1)
935-
)
936-
).to.throw(
937-
"Invalid query. You cannot use 'array-contains' filters with " +
938-
"'not-in' filters."
939-
);
940-
});
941-
942897
validationIt(persistence, 'with != and not-in filters fail', db => {
943898
expect(() =>
944899
query(
@@ -972,17 +927,6 @@ apiDescribe('Validation:', (persistence: boolean) => {
972927
"Invalid query. You cannot use more than one 'not-in' filter."
973928
);
974929

975-
expect(() =>
976-
query(
977-
collection(db, 'test'),
978-
where('foo', 'array-contains-any', [1, 2]),
979-
where('foo', 'array-contains-any', [2, 3])
980-
)
981-
).to.throw(
982-
"Invalid query. You cannot use more than one 'array-contains-any'" +
983-
' filter.'
984-
);
985-
986930
expect(() =>
987931
query(
988932
collection(db, 'test'),
@@ -1024,55 +968,6 @@ apiDescribe('Validation:', (persistence: boolean) => {
1024968
).to.throw(
1025969
"Invalid query. You cannot use 'not-in' filters with 'in' filters."
1026970
);
1027-
1028-
// This is redundant with the above tests, but makes sure our validation
1029-
// doesn't get confused.
1030-
expect(() =>
1031-
query(
1032-
collection(db, 'test'),
1033-
where('foo', 'in', [2, 3]),
1034-
where('foo', 'array-contains', 1),
1035-
where('foo', 'array-contains-any', [2])
1036-
)
1037-
).to.throw(
1038-
"Invalid query. You cannot use 'array-contains-any' filters with 'array-contains' filters."
1039-
);
1040-
1041-
expect(() =>
1042-
query(
1043-
collection(db, 'test'),
1044-
where('foo', 'array-contains', 1),
1045-
where('foo', 'in', [2, 3]),
1046-
where('foo', 'array-contains-any', [2])
1047-
)
1048-
).to.throw(
1049-
"Invalid query. You cannot use 'array-contains-any' filters with " +
1050-
"'array-contains' filters."
1051-
);
1052-
1053-
expect(() =>
1054-
query(
1055-
collection(db, 'test'),
1056-
where('foo', 'not-in', [2, 3]),
1057-
where('foo', 'array-contains', 2),
1058-
where('foo', 'array-contains-any', [2])
1059-
)
1060-
).to.throw(
1061-
"Invalid query. You cannot use 'array-contains' filters with " +
1062-
"'not-in' filters."
1063-
);
1064-
1065-
expect(() =>
1066-
query(
1067-
collection(db, 'test'),
1068-
where('foo', 'array-contains', 2),
1069-
where('foo', 'in', [2]),
1070-
where('foo', 'not-in', [2, 3])
1071-
)
1072-
).to.throw(
1073-
"Invalid query. You cannot use 'not-in' filters with " +
1074-
"'array-contains' filters."
1075-
);
1076971
});
1077972

1078973
validationIt(
@@ -1094,17 +989,6 @@ apiDescribe('Validation:', (persistence: boolean) => {
1094989
where('foo', 'array-contains', 1)
1095990
)
1096991
).not.to.throw();
1097-
1098-
expect(() =>
1099-
query(
1100-
collection(db, 'test'),
1101-
where('foo', 'in', [2, 3]),
1102-
where('foo', 'array-contains', 1),
1103-
where('foo', 'array-contains', 2)
1104-
)
1105-
).to.throw(
1106-
"Invalid query. You cannot use more than one 'array-contains' filter."
1107-
);
1108992
}
1109993
);
1110994

@@ -1125,31 +1009,6 @@ apiDescribe('Validation:', (persistence: boolean) => {
11251009
"'array-contains-any' filters."
11261010
);
11271011

1128-
expect(() =>
1129-
query(
1130-
collection(db, 'test'),
1131-
// The 10 element max includes duplicates.
1132-
where('foo', 'in', [1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 9])
1133-
)
1134-
).to.throw(
1135-
"Invalid Query. 'in' filters support a maximum of 10 elements in " +
1136-
'the value array.'
1137-
);
1138-
1139-
expect(() =>
1140-
query(
1141-
collection(db, 'test'),
1142-
where(
1143-
'foo',
1144-
'array-contains-any',
1145-
[1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 9]
1146-
)
1147-
)
1148-
).to.throw(
1149-
"Invalid Query. 'array-contains-any' filters support a maximum of " +
1150-
'10 elements in the value array.'
1151-
);
1152-
11531012
expect(() =>
11541013
query(collection(db, 'test'), where('foo', 'in', []))
11551014
).to.throw(

0 commit comments

Comments
 (0)