Skip to content

Commit

Permalink
OR Query public API (#7053)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
MarkDuckworth committed Mar 6, 2023
1 parent 722325a commit 5ba5243
Show file tree
Hide file tree
Showing 12 changed files with 552 additions and 75 deletions.
6 changes: 6 additions & 0 deletions .changeset/sweet-rats-compete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@firebase/firestore": minor
'firebase': minor
---

OR Query public API
17 changes: 17 additions & 0 deletions common/api-review/firestore-lite.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ export type AggregateSpecData<T extends AggregateSpec> = {
[P in keyof T]: T[P] extends AggregateField<infer U> ? U : never;
};

// @public
export function and(...queryConstraints: QueryFilterConstraint[]): QueryCompositeFilterConstraint;

// @public
export function arrayRemove(...elements: unknown[]): FieldValue;

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

// @public
export function or(...queryConstraints: QueryFilterConstraint[]): QueryCompositeFilterConstraint;

// @public
export function orderBy(fieldPath: string | FieldPath, directionStr?: OrderByDirection): QueryOrderByConstraint;

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

// @public
export function query<T>(query: Query<T>, compositeFilter: QueryCompositeFilterConstraint, ...queryConstraints: QueryNonFilterConstraint[]): Query<T>;

// @public
export function query<T>(query: Query<T>, ...queryConstraints: QueryConstraint[]): Query<T>;

// @public
export class QueryCompositeFilterConstraint {
readonly type: 'or' | 'and';
}

// @public
export abstract class QueryConstraint {
abstract readonly type: QueryConstraintType;
Expand Down Expand Up @@ -288,6 +302,9 @@ export class QueryFieldFilterConstraint extends QueryConstraint {
readonly type = "where";
}

// @public
export type QueryFilterConstraint = QueryFieldFilterConstraint | QueryCompositeFilterConstraint;

// @public
export class QueryLimitConstraint extends QueryConstraint {
readonly type: 'limit' | 'limitToLast';
Expand Down
17 changes: 17 additions & 0 deletions common/api-review/firestore.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ export type AggregateSpecData<T extends AggregateSpec> = {
[P in keyof T]: T[P] extends AggregateField<infer U> ? U : never;
};

// @public
export function and(...queryConstraints: QueryFilterConstraint[]): QueryCompositeFilterConstraint;

// @public
export function arrayRemove(...elements: unknown[]): FieldValue;

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

// @public
export function or(...queryConstraints: QueryFilterConstraint[]): QueryCompositeFilterConstraint;

// @public
export function orderBy(fieldPath: string | FieldPath, directionStr?: OrderByDirection): QueryOrderByConstraint;

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

// @public
export function query<T>(query: Query<T>, compositeFilter: QueryCompositeFilterConstraint, ...queryConstraints: QueryNonFilterConstraint[]): Query<T>;

// @public
export function query<T>(query: Query<T>, ...queryConstraints: QueryConstraint[]): Query<T>;

// @public
export class QueryCompositeFilterConstraint {
readonly type: 'or' | 'and';
}

// @public
export abstract class QueryConstraint {
abstract readonly type: QueryConstraintType;
Expand Down Expand Up @@ -441,6 +455,9 @@ export class QueryFieldFilterConstraint extends QueryConstraint {
readonly type = "where";
}

// @public
export type QueryFilterConstraint = QueryFieldFilterConstraint | QueryCompositeFilterConstraint;

// @public
export class QueryLimitConstraint extends QueryConstraint {
readonly type: 'limit' | 'limitToLast';
Expand Down
92 changes: 89 additions & 3 deletions docs-devsite/firestore_.md

Large diffs are not rendered by default.

35 changes: 35 additions & 0 deletions docs-devsite/firestore_.querycompositefilterconstraint.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
Project: /docs/reference/js/_project.yaml
Book: /docs/reference/_book.yaml
page_type: reference

{% comment %}
DO NOT EDIT THIS FILE!
This is generated by the JS SDK team, and any local changes will be
overwritten. Changes should be made in the source code at
https://github.com/firebase/firebase-js-sdk
{% endcomment %}

# QueryCompositeFilterConstraint class
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`<!-- -->.

<b>Signature:</b>

```typescript
export declare class QueryCompositeFilterConstraint
```

## Properties

| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [type](./firestore_.querycompositefilterconstraint.md#querycompositefilterconstrainttype) | | 'or' \| 'and' | The type of this query constraint |

## QueryCompositeFilterConstraint.type

The type of this query constraint

<b>Signature:</b>

```typescript
readonly type: 'or' | 'and';
```
2 changes: 1 addition & 1 deletion docs-devsite/firestore_.queryconstraint.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ https://github.com/firebase/firebase-js-sdk
{% endcomment %}

# QueryConstraint class
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`<!-- -->.
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`<!-- -->.

<b>Signature:</b>

Expand Down

0 comments on commit 5ba5243

Please sign in to comment.