|
18 | 18 | import { Query } from './reference'; |
19 | 19 |
|
20 | 20 | /** |
21 | | - * An `AggregateField`that captures input type T. |
| 21 | + * Represents an aggregation that can be performed by Firestore. |
22 | 22 | */ |
23 | 23 | // eslint-disable-next-line @typescript-eslint/no-unused-vars |
24 | 24 | export class AggregateField<T> { |
| 25 | + /** A type string to uniquely identify instances of this class. */ |
25 | 26 | type = 'AggregateField'; |
26 | 27 | } |
27 | 28 |
|
28 | 29 | /** |
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. |
31 | 31 | */ |
32 | | -export function count(): AggregateField<number> { |
33 | | - return new AggregateField<number>(); |
34 | | -} |
| 32 | +export type AggregateFieldType = AggregateField<number>; |
35 | 33 |
|
36 | 34 | /** |
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. |
46 | 36 | */ |
47 | 37 | export interface AggregateSpec { |
48 | 38 | [field: string]: AggregateFieldType; |
49 | 39 | } |
50 | 40 |
|
51 | 41 | /** |
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`. |
55 | 45 | */ |
56 | 46 | export type AggregateSpecData<T extends AggregateSpec> = { |
57 | 47 | [P in keyof T]: T[P] extends AggregateField<infer U> ? U : never; |
58 | 48 | }; |
59 | 49 |
|
60 | 50 | /** |
61 | | - * An `AggregateQuerySnapshot` contains the results of running an aggregate query. |
| 51 | + * The results of executing an aggregation query. |
62 | 52 | */ |
63 | 53 | export class AggregateQuerySnapshot<T extends AggregateSpec> { |
| 54 | + /** A type string to uniquely identify instances of this class. */ |
64 | 55 | readonly type = 'AggregateQuerySnapshot'; |
65 | 56 |
|
| 57 | + /** |
| 58 | + * The underlying query over which the aggregations recorded in this |
| 59 | + * `AggregateQuerySnapshot` were performed. |
| 60 | + */ |
| 61 | + readonly query: Query<unknown>; |
| 62 | + |
66 | 63 | /** @hideconstructor */ |
67 | 64 | constructor( |
68 | | - readonly query: Query<unknown>, |
| 65 | + query: Query<unknown>, |
69 | 66 | private readonly _data: AggregateSpecData<T> |
70 | | - ) {} |
| 67 | + ) { |
| 68 | + this.query = query; |
| 69 | + } |
71 | 70 |
|
72 | 71 | /** |
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. |
77 | 78 | * |
78 | | - * @returns The aggregation statistics result of running a query. |
| 79 | + * @returns The results of the aggregations performed over the underlying |
| 80 | + * query. |
79 | 81 | */ |
80 | 82 | data(): AggregateSpecData<T> { |
81 | 83 | return this._data; |
|
0 commit comments