Skip to content

Commit 2235c77

Browse files
authored
Merge b5af575 into fa07ffa
2 parents fa07ffa + b5af575 commit 2235c77

File tree

7 files changed

+65
-58
lines changed

7 files changed

+65
-58
lines changed

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

+1-7
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,16 @@ export type AddPrefixToKeys<Prefix extends string, T extends Record<string, unkn
1919

2020
// @public
2121
export class AggregateField<T> {
22-
// (undocumented)
2322
type: string;
2423
}
2524

2625
// @public
27-
export type AggregateFieldType = ReturnType<typeof count>;
26+
export type AggregateFieldType = AggregateField<number>;
2827

2928
// @public
3029
export class AggregateQuerySnapshot<T extends AggregateSpec> {
3130
data(): AggregateSpecData<T>;
32-
// (undocumented)
3331
readonly query: Query<unknown>;
34-
// (undocumented)
3532
readonly type = "AggregateQuerySnapshot";
3633
}
3734

@@ -95,9 +92,6 @@ export function connectFirestoreEmulator(firestore: Firestore, host: string, por
9592
mockUserToken?: EmulatorMockTokenOptions | string;
9693
}): void;
9794

98-
// @public
99-
export function count(): AggregateField<number>;
100-
10195
// @public
10296
export function deleteDoc(reference: DocumentReference<unknown>): Promise<void>;
10397

common/api-review/firestore.api.md

+1-7
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,16 @@ export type AddPrefixToKeys<Prefix extends string, T extends Record<string, unkn
1919

2020
// @public
2121
export class AggregateField<T> {
22-
// (undocumented)
2322
type: string;
2423
}
2524

2625
// @public
27-
export type AggregateFieldType = ReturnType<typeof count>;
26+
export type AggregateFieldType = AggregateField<number>;
2827

2928
// @public
3029
export class AggregateQuerySnapshot<T extends AggregateSpec> {
3130
data(): AggregateSpecData<T>;
32-
// (undocumented)
3331
readonly query: Query<unknown>;
34-
// (undocumented)
3532
readonly type = "AggregateQuerySnapshot";
3633
}
3734

@@ -101,9 +98,6 @@ export function connectFirestoreEmulator(firestore: Firestore, host: string, por
10198
mockUserToken?: EmulatorMockTokenOptions | string;
10299
}): void;
103100

104-
// @public
105-
export function count(): AggregateField<number>;
106-
107101
// @public
108102
export function deleteDoc(reference: DocumentReference<unknown>): Promise<void>;
109103

packages/firestore/lite/index.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ export {
3737
AggregateFieldType,
3838
AggregateSpec,
3939
AggregateSpecData,
40-
AggregateQuerySnapshot,
41-
count
40+
AggregateQuerySnapshot
4241
} from '../src/lite-api/aggregate_types';
4342

4443
export { FirestoreSettings as Settings } from '../src/lite-api/settings';

packages/firestore/src/api.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ export {
2525
AggregateFieldType,
2626
AggregateSpec,
2727
AggregateSpecData,
28-
AggregateQuerySnapshot,
29-
count
28+
AggregateQuerySnapshot
3029
} from './lite-api/aggregate_types';
3130

3231
export { FieldPath, documentId } from './api/field_path';

packages/firestore/src/api/aggregate.ts

+17-4
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,25 @@ import { ExpUserDataWriter } from './reference_impl';
2929
export { aggregateQuerySnapshotEqual } from '../lite-api/aggregate';
3030

3131
/**
32-
* Executes the query and returns the results as a `AggregateQuerySnapshot` from the
33-
* server. Returns an error if the network is not available.
32+
* Calculates the number of documents in the result set of the given query,
33+
* without actually downloading the documents.
3434
*
35-
* @param query - The `Query` to execute.
35+
* Using this function to count the documents is efficient because only the
36+
* final count, not the documents' data, is downloaded. This function can even
37+
* count the documents if the result set would be prohibitively large to
38+
* download entirely (e.g. thousands of documents).
3639
*
37-
* @returns A `Promise` that will be resolved with the results of the query.
40+
* The result received from the server is presented, unaltered, without
41+
* considering any local state. That is, documents in the local cache are not
42+
* taken into consideration, neither are local modifications not yet
43+
* synchronized with the server. Previously-downloaded results, if any, are not
44+
* used: every request using this source necessarily involves a round trip to
45+
* the server.
46+
*
47+
* @param query - The query whose result set size to calculate.
48+
* @returns A Promise that will be resolved with the count; the count can be
49+
* retrieved from `snapshot.data().count`, where `snapshot` is the
50+
* `AggregateQuerySnapshot` to which the returned Promise resolves.
3851
*/
3952
export function getCountFromServer(
4053
query: Query<unknown>

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

+16-10
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,18 @@ import { Query, queryEqual } from './reference';
3131
import { LiteUserDataWriter } from './reference_impl';
3232

3333
/**
34-
* Counts the number of documents in the result set of the given query, ignoring
35-
* any locally-cached data and any locally-pending writes and simply surfacing
36-
* whatever the server returns. If the server cannot be reached then the
37-
* returned promise will be rejected.
34+
* Calculates the number of documents in the result set of the given query,
35+
* without actually downloading the documents.
3836
*
39-
* @param query - The `Query` to execute.
37+
* Using this function to count the documents is efficient because only the
38+
* final count, not the documents' data, is downloaded. This function can even
39+
* count the documents if the result set would be prohibitively large to
40+
* download entirely (e.g. thousands of documents).
4041
*
41-
* @returns An `AggregateQuerySnapshot` that contains the number of documents.
42+
* @param query - The query whose result set size to calculate.
43+
* @returns A Promise that will be resolved with the count; the count can be
44+
* retrieved from `snapshot.data().count`, where `snapshot` is the
45+
* `AggregateQuerySnapshot` to which the returned Promise resolves.
4246
*/
4347
export function getCount(
4448
query: Query<unknown>
@@ -51,13 +55,15 @@ export function getCount(
5155

5256
/**
5357
* Compares two `AggregateQuerySnapshot` instances for equality.
58+
*
5459
* Two `AggregateQuerySnapshot` instances are considered "equal" if they have
55-
* the same underlying query, and the same data.
60+
* underlying queries that compare equal, and the same data.
5661
*
57-
* @param left - The `AggregateQuerySnapshot` to compare.
58-
* @param right - The `AggregateQuerySnapshot` to compare.
62+
* @param left - The first `AggregateQuerySnapshot` to compare.
63+
* @param right - The second `AggregateQuerySnapshot` to compare.
5964
*
60-
* @returns true if the AggregateQuerySnapshots are equal.
65+
* @returns `true` if the objects are "equal", as defined above, or `false`
66+
* otherwise.
6167
*/
6268
export function aggregateQuerySnapshotEqual<T extends AggregateSpec>(
6369
left: AggregateQuerySnapshot<T>,

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

+28-26
Original file line numberDiff line numberDiff line change
@@ -18,64 +18,66 @@
1818
import { Query } from './reference';
1919

2020
/**
21-
* An `AggregateField`that captures input type T.
21+
* Represents an aggregation that can be performed by Firestore.
2222
*/
2323
// eslint-disable-next-line @typescript-eslint/no-unused-vars
2424
export class AggregateField<T> {
25+
/** A type string to uniquely identify instances of this class. */
2526
type = 'AggregateField';
2627
}
2728

2829
/**
29-
* Creates and returns an aggregation field that counts the documents in the result set.
30-
* @returns An `AggregateField` object with number input type.
30+
* The union of all `AggregateField` types that are supported by Firestore.
3131
*/
32-
export function count(): AggregateField<number> {
33-
return new AggregateField<number>();
34-
}
32+
export type AggregateFieldType = AggregateField<number>;
3533

3634
/**
37-
* The union of all `AggregateField` types that are returned from the factory
38-
* functions.
39-
*/
40-
export type AggregateFieldType = ReturnType<typeof count>;
41-
42-
/**
43-
* A type whose values are all `AggregateField` objects.
44-
* This is used as an argument to the "getter" functions, and the snapshot will
45-
* map the same names to the corresponding values.
35+
* A type whose property values are all `AggregateField` objects.
4636
*/
4737
export interface AggregateSpec {
4838
[field: string]: AggregateFieldType;
4939
}
5040

5141
/**
52-
* A type whose keys are taken from an `AggregateSpec` type, and whose values
53-
* are the result of the aggregation performed by the corresponding
54-
* `AggregateField` from the input `AggregateSpec`.
42+
* A type whose keys are taken from an `AggregateSpec`, and whose values are the
43+
* result of the aggregation performed by the corresponding `AggregateField`
44+
* from the input `AggregateSpec`.
5545
*/
5646
export type AggregateSpecData<T extends AggregateSpec> = {
5747
[P in keyof T]: T[P] extends AggregateField<infer U> ? U : never;
5848
};
5949

6050
/**
61-
* An `AggregateQuerySnapshot` contains the results of running an aggregate query.
51+
* The results of executing an aggregation query.
6252
*/
6353
export class AggregateQuerySnapshot<T extends AggregateSpec> {
54+
/** A type string to uniquely identify instances of this class. */
6455
readonly type = 'AggregateQuerySnapshot';
6556

57+
/**
58+
* The underlying query over which the aggregations recorded in this
59+
* `AggregateQuerySnapshot` were performed.
60+
*/
61+
readonly query: Query<unknown>;
62+
6663
/** @hideconstructor */
6764
constructor(
68-
readonly query: Query<unknown>,
65+
query: Query<unknown>,
6966
private readonly _data: AggregateSpecData<T>
70-
) {}
67+
) {
68+
this.query = query;
69+
}
7170

7271
/**
73-
* The results of the requested aggregations. The keys of the returned object
74-
* will be the same as those of the `AggregateSpec` object specified to the
75-
* aggregation method, and the values will be the corresponding aggregation
76-
* result.
72+
* Returns the results of the aggregations performed over the underlying
73+
* query.
74+
*
75+
* The keys of the returned object will be the same as those of the
76+
* `AggregateSpec` object specified to the aggregation method, and the values
77+
* will be the corresponding aggregation result.
7778
*
78-
* @returns The aggregation statistics result of running a query.
79+
* @returns The results of the aggregations performed over the underlying
80+
* query.
7981
*/
8082
data(): AggregateSpecData<T> {
8183
return this._data;

0 commit comments

Comments
 (0)