Skip to content

Commit 5ba5243

Browse files
OR Query public API (#7053)
* Relaxing in restrictions. * Additional testing. * Relaxing query restrictions. * Code cleanup. * Removing compat tests that perform validation on the old query restrictions. * Making OR Queries public. * Enabling tests for or queries and configuring tests that require composite indexes to only run against the emulator. * Create sweet-rats-compete.md * Fixing documentation errors revealed by the doc change check. * Removing and renaming tests based on PR feedback. * Correcting the change type in the changeset file. * Disable tests that have multiple ins or array-contains-any per query.
1 parent 722325a commit 5ba5243

12 files changed

+552
-75
lines changed

.changeset/sweet-rats-compete.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@firebase/firestore": minor
3+
'firebase': minor
4+
---
5+
6+
OR Query public API

common/api-review/firestore-lite.api.md

+17
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ export type AggregateSpecData<T extends AggregateSpec> = {
4646
[P in keyof T]: T[P] extends AggregateField<infer U> ? U : never;
4747
};
4848

49+
// @public
50+
export function and(...queryConstraints: QueryFilterConstraint[]): QueryCompositeFilterConstraint;
51+
4952
// @public
5053
export function arrayRemove(...elements: unknown[]): FieldValue;
5154

@@ -234,6 +237,9 @@ export type NestedUpdateFields<T extends Record<string, unknown>> = UnionToInter
234237
[K in keyof T & string]: ChildUpdateFields<K, T[K]>;
235238
}[keyof T & string]>;
236239

240+
// @public
241+
export function or(...queryConstraints: QueryFilterConstraint[]): QueryCompositeFilterConstraint;
242+
237243
// @public
238244
export function orderBy(fieldPath: string | FieldPath, directionStr?: OrderByDirection): QueryOrderByConstraint;
239245

@@ -258,9 +264,17 @@ export class Query<T = DocumentData> {
258264
withConverter<U>(converter: FirestoreDataConverter<U>): Query<U>;
259265
}
260266

267+
// @public
268+
export function query<T>(query: Query<T>, compositeFilter: QueryCompositeFilterConstraint, ...queryConstraints: QueryNonFilterConstraint[]): Query<T>;
269+
261270
// @public
262271
export function query<T>(query: Query<T>, ...queryConstraints: QueryConstraint[]): Query<T>;
263272

273+
// @public
274+
export class QueryCompositeFilterConstraint {
275+
readonly type: 'or' | 'and';
276+
}
277+
264278
// @public
265279
export abstract class QueryConstraint {
266280
abstract readonly type: QueryConstraintType;
@@ -288,6 +302,9 @@ export class QueryFieldFilterConstraint extends QueryConstraint {
288302
readonly type = "where";
289303
}
290304

305+
// @public
306+
export type QueryFilterConstraint = QueryFieldFilterConstraint | QueryCompositeFilterConstraint;
307+
291308
// @public
292309
export class QueryLimitConstraint extends QueryConstraint {
293310
readonly type: 'limit' | 'limitToLast';

common/api-review/firestore.api.md

+17
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ export type AggregateSpecData<T extends AggregateSpec> = {
4646
[P in keyof T]: T[P] extends AggregateField<infer U> ? U : never;
4747
};
4848

49+
// @public
50+
export function and(...queryConstraints: QueryFilterConstraint[]): QueryCompositeFilterConstraint;
51+
4952
// @public
5053
export function arrayRemove(...elements: unknown[]): FieldValue;
5154

@@ -382,6 +385,9 @@ export function onSnapshotsInSync(firestore: Firestore, observer: {
382385
// @public
383386
export function onSnapshotsInSync(firestore: Firestore, onSync: () => void): Unsubscribe;
384387

388+
// @public
389+
export function or(...queryConstraints: QueryFilterConstraint[]): QueryCompositeFilterConstraint;
390+
385391
// @public
386392
export function orderBy(fieldPath: string | FieldPath, directionStr?: OrderByDirection): QueryOrderByConstraint;
387393

@@ -411,9 +417,17 @@ export class Query<T = DocumentData> {
411417
withConverter<U>(converter: FirestoreDataConverter<U>): Query<U>;
412418
}
413419

420+
// @public
421+
export function query<T>(query: Query<T>, compositeFilter: QueryCompositeFilterConstraint, ...queryConstraints: QueryNonFilterConstraint[]): Query<T>;
422+
414423
// @public
415424
export function query<T>(query: Query<T>, ...queryConstraints: QueryConstraint[]): Query<T>;
416425

426+
// @public
427+
export class QueryCompositeFilterConstraint {
428+
readonly type: 'or' | 'and';
429+
}
430+
417431
// @public
418432
export abstract class QueryConstraint {
419433
abstract readonly type: QueryConstraintType;
@@ -441,6 +455,9 @@ export class QueryFieldFilterConstraint extends QueryConstraint {
441455
readonly type = "where";
442456
}
443457

458+
// @public
459+
export type QueryFilterConstraint = QueryFieldFilterConstraint | QueryCompositeFilterConstraint;
460+
444461
// @public
445462
export class QueryLimitConstraint extends QueryConstraint {
446463
readonly type: 'limit' | 'limitToLast';

docs-devsite/firestore_.md

+89-3
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Project: /docs/reference/js/_project.yaml
2+
Book: /docs/reference/_book.yaml
3+
page_type: reference
4+
5+
{% comment %}
6+
DO NOT EDIT THIS FILE!
7+
This is generated by the JS SDK team, and any local changes will be
8+
overwritten. Changes should be made in the source code at
9+
https://github.com/firebase/firebase-js-sdk
10+
{% endcomment %}
11+
12+
# QueryCompositeFilterConstraint class
13+
A `QueryCompositeFilterConstraint` is used to narrow the set of documents returned by a Firestore query by performing the logical OR or AND of multiple [QueryFieldFilterConstraint](./firestore_.queryfieldfilterconstraint.md#queryfieldfilterconstraint_class)<!-- -->s or [QueryCompositeFilterConstraint](./firestore_.querycompositefilterconstraint.md#querycompositefilterconstraint_class)<!-- -->s. `QueryCompositeFilterConstraint`<!-- -->s are created by invoking [or()](./firestore_.md#or) or [and()](./firestore_.md#and) and can then be passed to [query()](./firestore_.md#query) to create a new query instance that also contains the `QueryCompositeFilterConstraint`<!-- -->.
14+
15+
<b>Signature:</b>
16+
17+
```typescript
18+
export declare class QueryCompositeFilterConstraint
19+
```
20+
21+
## Properties
22+
23+
| Property | Modifiers | Type | Description |
24+
| --- | --- | --- | --- |
25+
| [type](./firestore_.querycompositefilterconstraint.md#querycompositefilterconstrainttype) | | 'or' \| 'and' | The type of this query constraint |
26+
27+
## QueryCompositeFilterConstraint.type
28+
29+
The type of this query constraint
30+
31+
<b>Signature:</b>
32+
33+
```typescript
34+
readonly type: 'or' | 'and';
35+
```

docs-devsite/firestore_.queryconstraint.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ https://github.com/firebase/firebase-js-sdk
1010
{% endcomment %}
1111

1212
# QueryConstraint class
13-
A `QueryConstraint` is used to narrow the set of documents returned by a Firestore query. `QueryConstraint`<!-- -->s are created by invoking [where()](./firestore_.md#where)<!-- -->, [orderBy()](./firestore_.md#orderby)<!-- -->, , , , , [limit()](./firestore_.md#limit)<!-- -->, [limitToLast()](./firestore_.md#limittolast) and can then be passed to [query()](./firestore_.md#query) to create a new query instance that also contains this `QueryConstraint`<!-- -->.
13+
A `QueryConstraint` is used to narrow the set of documents returned by a Firestore query. `QueryConstraint`<!-- -->s are created by invoking [where()](./firestore_.md#where)<!-- -->, [orderBy()](./firestore_.md#orderby)<!-- -->, [startAt()](./firestore_.md#startat)<!-- -->, [startAfter()](./firestore_.md#startafter)<!-- -->, [endBefore()](./firestore_.md#endbefore)<!-- -->, [endAt()](./firestore_.md#endat)<!-- -->, [limit()](./firestore_.md#limit)<!-- -->, [limitToLast()](./firestore_.md#limittolast) and can then be passed to [query()](./firestore_.md#query) to create a new query instance that also contains this `QueryConstraint`<!-- -->.
1414

1515
<b>Signature:</b>
1616

0 commit comments

Comments
 (0)