Skip to content

Commit 52d3f9c

Browse files
authored
Merge 0a2f104 into 598e948
2 parents 598e948 + 0a2f104 commit 52d3f9c

File tree

4 files changed

+133
-0
lines changed

4 files changed

+133
-0
lines changed

common/api-review/firestore.api.md

+30
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,30 @@ export type AddPrefixToKeys<Prefix extends string, T extends Record<string, unkn
1717
[K in keyof T & string as `${Prefix}.${K}`]+?: T[K];
1818
};
1919

20+
// @public (undocumented)
21+
export class AggregateQuery<T = DocumentData> {
22+
// (undocumented)
23+
readonly query: Query<T>;
24+
// (undocumented)
25+
readonly type = "AggregateQuery";
26+
}
27+
28+
// @public (undocumented)
29+
export function aggregateQueryEqual(left: AggregateQuery, right: AggregateQuery): boolean;
30+
31+
// @public (undocumented)
32+
export class AggregateQuerySnapshot {
33+
// (undocumented)
34+
getCount(): number | null;
35+
// (undocumented)
36+
readonly query: AggregateQuery;
37+
// (undocumented)
38+
readonly type = "AggregateQuerySnapshot";
39+
}
40+
41+
// @public (undocumented)
42+
export function aggregateQuerySnapshotEqual(left: AggregateQuerySnapshot, right: AggregateQuerySnapshot): boolean;
43+
2044
// @public
2145
export function arrayRemove(...elements: unknown[]): FieldValue;
2246

@@ -69,6 +93,9 @@ export function connectFirestoreEmulator(firestore: Firestore, host: string, por
6993
mockUserToken?: EmulatorMockTokenOptions | string;
7094
}): void;
7195

96+
// @public (undocumented)
97+
export function countQuery(query: Query): AggregateQuery;
98+
7299
// @public
73100
export function deleteDoc(reference: DocumentReference<unknown>): Promise<void>;
74101

@@ -209,6 +236,9 @@ export class GeoPoint {
209236
};
210237
}
211238

239+
// @public (undocumented)
240+
export function getAggregateFromServerDirect(query: AggregateQuery): Promise<AggregateQuerySnapshot>;
241+
212242
// @public
213243
export function getDoc<T>(reference: DocumentReference<T>): Promise<DocumentSnapshot<T>>;
214244

packages/firestore/src/api.ts

+9
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@
1515
* limitations under the License.
1616
*/
1717

18+
export {
19+
AggregateQuery,
20+
AggregateQuerySnapshot,
21+
aggregateQueryEqual,
22+
aggregateQuerySnapshotEqual,
23+
countQuery,
24+
getAggregateFromServerDirect
25+
} from './api/aggregate';
26+
1827
export { FieldPath, documentId } from './api/field_path';
1928

2029
export {
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* @license
3+
* Copyright 2022 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
export {
19+
AggregateQuery,
20+
AggregateQuerySnapshot,
21+
aggregateQueryEqual,
22+
aggregateQuerySnapshotEqual,
23+
countQuery,
24+
getAggregateFromServerDirect
25+
} from '../lite-api/aggregate';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/**
2+
* @license
3+
* Copyright 2022 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import { DocumentData, Query, queryEqual } from './reference';
19+
20+
export class AggregateQuery<T = DocumentData> {
21+
readonly type = 'AggregateQuery';
22+
readonly query: Query<T>;
23+
24+
/** @hideconstructor */
25+
constructor(query: Query<T>) {
26+
this.query = query;
27+
}
28+
}
29+
30+
export class AggregateQuerySnapshot {
31+
readonly type = 'AggregateQuerySnapshot';
32+
readonly query: AggregateQuery;
33+
34+
/** @hideconstructor */
35+
constructor(query: AggregateQuery, readonly _count: number) {
36+
this.query = query;
37+
}
38+
39+
getCount(): number | null {
40+
return this._count;
41+
}
42+
}
43+
44+
export function countQuery(query: Query): AggregateQuery {
45+
return new AggregateQuery(query);
46+
}
47+
48+
export function getAggregateFromServerDirect(
49+
query: AggregateQuery
50+
): Promise<AggregateQuerySnapshot> {
51+
return Promise.resolve(new AggregateQuerySnapshot(query, 42));
52+
}
53+
54+
export function aggregateQueryEqual(
55+
left: AggregateQuery,
56+
right: AggregateQuery
57+
): boolean {
58+
return queryEqual(left.query, right.query);
59+
}
60+
61+
export function aggregateQuerySnapshotEqual(
62+
left: AggregateQuerySnapshot,
63+
right: AggregateQuerySnapshot
64+
): boolean {
65+
return (
66+
aggregateQueryEqual(left.query, right.query) &&
67+
left.getCount() === right.getCount()
68+
);
69+
}

0 commit comments

Comments
 (0)