|
15 | 15 | * limitations under the License.
|
16 | 16 | */
|
17 | 17 |
|
18 |
| -import { AggregateField, AggregateSpec, Query } from '../api'; |
| 18 | +import {AggregateField, AggregateSpec, DocumentData, Query} from '../api'; |
19 | 19 | import { AggregateImpl } from '../core/aggregate';
|
20 | 20 | import { firestoreClientRunAggregateQuery } from '../core/firestore_client';
|
21 | 21 | import { count } from '../lite-api/aggregate';
|
@@ -57,9 +57,7 @@ export {
|
57 | 57 | * retrieved from `snapshot.data().count`, where `snapshot` is the
|
58 | 58 | * `AggregateQuerySnapshot` to which the returned Promise resolves.
|
59 | 59 | */
|
60 |
| -export function getCountFromServer( |
61 |
| - query: Query<unknown> |
62 |
| -): Promise<AggregateQuerySnapshot<{ count: AggregateField<number> }>> { |
| 60 | +export function getCountFromServer<AppType = DocumentData, DbType extends DocumentData = AppType extends DocumentData ? AppType : DocumentData>(query: Query<AppType, DbType>): Promise<AggregateQuerySnapshot<{ count: AggregateField<number> }, AppType, DbType>> { |
63 | 61 | const countQuerySpec: { count: AggregateField<number> } = {
|
64 | 62 | count: count()
|
65 | 63 | };
|
@@ -101,10 +99,7 @@ export function getCountFromServer(
|
101 | 99 | * ```
|
102 | 100 | * @internal TODO (sum/avg) remove when public
|
103 | 101 | */
|
104 |
| -export function getAggregateFromServer<T extends AggregateSpec>( |
105 |
| - query: Query<unknown>, |
106 |
| - aggregateSpec: T |
107 |
| -): Promise<AggregateQuerySnapshot<T>> { |
| 102 | +export function getAggregateFromServer<AggregateSpecType extends AggregateSpec, AppType = DocumentData, DbType extends DocumentData = AppType extends DocumentData ? AppType : DocumentData>(query: Query<AppType, DbType>, aggregateSpec: AggregateSpecType): Promise<AggregateQuerySnapshot<AggregateSpecType, AppType, DbType>> { |
108 | 103 | const firestore = cast(query.firestore, Firestore);
|
109 | 104 | const client = ensureFirestoreConfigured(firestore);
|
110 | 105 |
|
@@ -133,16 +128,11 @@ export function getAggregateFromServer<T extends AggregateSpec>(
|
133 | 128 | * @param aggregateResult Core aggregation result
|
134 | 129 | * @internal
|
135 | 130 | */
|
136 |
| -function convertToAggregateQuerySnapshot<T extends AggregateSpec>( |
137 |
| - firestore: Firestore, |
138 |
| - query: Query<unknown>, |
139 |
| - aggregateResult: ObjectValue |
140 |
| -): AggregateQuerySnapshot<T> { |
| 131 | +function convertToAggregateQuerySnapshot<AggregateSpecType extends AggregateSpec, AppType, DbType extends DocumentData>(firestore: Firestore, query: Query<AppType, DbType>, aggregateResult: ObjectValue): AggregateQuerySnapshot<AggregateSpecType, AppType, DbType> { |
141 | 132 | const userDataWriter = new ExpUserDataWriter(firestore);
|
142 |
| - const querySnapshot = new AggregateQuerySnapshot<T>( |
| 133 | + return new AggregateQuerySnapshot<AggregateSpecType, AppType, DbType>( |
143 | 134 | query,
|
144 | 135 | userDataWriter,
|
145 | 136 | aggregateResult
|
146 | 137 | );
|
147 |
| - return querySnapshot; |
148 | 138 | }
|
0 commit comments