Skip to content

Commit f921d25

Browse files
committed
do normal api
1 parent 8d5257f commit f921d25

File tree

4 files changed

+222
-137
lines changed

4 files changed

+222
-137
lines changed

packages/firestore/src/api/aggregate.ts

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
import { AggregateField, AggregateSpec, Query } from '../api';
18+
import {AggregateField, AggregateSpec, DocumentData, Query} from '../api';
1919
import { AggregateImpl } from '../core/aggregate';
2020
import { firestoreClientRunAggregateQuery } from '../core/firestore_client';
2121
import { count } from '../lite-api/aggregate';
@@ -57,9 +57,7 @@ export {
5757
* retrieved from `snapshot.data().count`, where `snapshot` is the
5858
* `AggregateQuerySnapshot` to which the returned Promise resolves.
5959
*/
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>> {
6361
const countQuerySpec: { count: AggregateField<number> } = {
6462
count: count()
6563
};
@@ -101,10 +99,7 @@ export function getCountFromServer(
10199
* ```
102100
* @internal TODO (sum/avg) remove when public
103101
*/
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>> {
108103
const firestore = cast(query.firestore, Firestore);
109104
const client = ensureFirestoreConfigured(firestore);
110105

@@ -133,16 +128,11 @@ export function getAggregateFromServer<T extends AggregateSpec>(
133128
* @param aggregateResult Core aggregation result
134129
* @internal
135130
*/
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> {
141132
const userDataWriter = new ExpUserDataWriter(firestore);
142-
const querySnapshot = new AggregateQuerySnapshot<T>(
133+
return new AggregateQuerySnapshot<AggregateSpecType, AppType, DbType>(
143134
query,
144135
userDataWriter,
145136
aggregateResult
146137
);
147-
return querySnapshot;
148138
}

0 commit comments

Comments
 (0)