Skip to content

Commit f914afd

Browse files
committed
change AggregateQuery type to unknwon
1 parent 60bce4a commit f914afd

File tree

2 files changed

+28
-39
lines changed

2 files changed

+28
-39
lines changed

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

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,21 @@ import { LiteUserDataWriter } from './reference_impl';
3030
* in test mocks. Subclassing is not supported in production code and new SDK releases may break
3131
* code that does so.
3232
*/
33-
export class AggregateQuery<T = DocumentData> {
33+
export class AggregateQuery {
3434
readonly type = 'AggregateQuery';
3535
/**
3636
* The query on which you called {@link countQuery} in order to get this
3737
* `AggregateQuery`.
3838
* Query type is set to unknown to avoid error caused by query type converter.
3939
* might change it back to T after testing if the error do exist or not
4040
*/
41-
readonly query: Query<T>;
41+
readonly query: Query<unknown>;
4242

4343
/** @hideconstructor */
44-
constructor(query: Query<T>) {
44+
constructor(query: Query<unknown>) {
4545
this.query = query;
4646
}
4747

48-
/** Returns the base {@link Query} for this aggregate query. */
49-
getQuery(): Query<T> {
50-
return this.query;
51-
}
5248
}
5349

5450
/**
@@ -61,25 +57,18 @@ export class AggregateQuery<T = DocumentData> {
6157
export class AggregateQuerySnapshot {
6258
readonly type = 'AggregateQuerySnapshot';
6359
readonly query: AggregateQuery;
64-
readonly count: number | null;
6560

6661
/** @hideconstructor */
67-
constructor(query: AggregateQuery, count: number | null) {
62+
constructor(query: AggregateQuery, private readonly _count: number) {
6863
this.query = query;
69-
this.count = count;
70-
}
71-
72-
/** @return The original {@link AggregateQuery} this snapshot is a result of. */
73-
getQuery(): AggregateQuery {
74-
return this.query;
7564
}
7665

7766
/**
7867
* @return The result of a document count aggregation. Returns null if no count aggregation is
7968
* available in the result.
8069
*/
8170
getCount(): number | null {
82-
return this.count;
71+
return this._count;
8372
}
8473
}
8574

@@ -89,15 +78,15 @@ export class AggregateQuerySnapshot {
8978
* @return An {@link AggregateQuery} object that can be used to count the number of documents in
9079
* the result set of this query.
9180
*/
92-
export function countQuery<T>(query: Query<T>): AggregateQuery<T> {
81+
export function countQuery(query: Query<unknown>): AggregateQuery {
9382
/**
9483
* TODO(mila): add the "count" aggregateField to the params after the AggregateQuery is updated.
9584
*/
9685
return new AggregateQuery(query);
9786
}
9887

99-
export function getAggregateFromServerDirect<T>(
100-
aggregateQuery: AggregateQuery<T>
88+
export function getAggregateFromServerDirect(
89+
aggregateQuery: AggregateQuery
10190
): Promise<AggregateQuerySnapshot> {
10291
const firestore = cast(aggregateQuery.query.firestore, Firestore);
10392
const datastore = getDatastore(firestore);

packages/firestore/test/lite/integration.test.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2046,12 +2046,12 @@ describe('withConverter() support', () => {
20462046

20472047
describe('countQuery()', () => {
20482048
const converter = {
2049-
toFirestore(value: string): DocumentData {
2050-
return { key: value };
2049+
toFirestore(input: { id: string, content: string}): DocumentData {
2050+
return { key: input.id, value:input.content };
20512051
},
2052-
fromFirestore(snapshot: QueryDocumentSnapshot): string {
2052+
fromFirestore(snapshot: QueryDocumentSnapshot): {id: string, content: string} {
20532053
const data = snapshot.data();
2054-
return data.value;
2054+
return {content:data.value, id:data.documentId} ;
20552055
}
20562056
};
20572057

@@ -2139,40 +2139,40 @@ describe('countQuery()', () => {
21392139

21402140
it.only('test collection count with converter on query', () => {
21412141
const testDocs = [
2142-
{ key: 'a' },
2143-
{ key: 'b' },
2144-
{ key: 'c' },
2145-
{ key: 'a' },
2146-
{ key: 'b' },
2147-
{ key: 'c' }
2142+
{ key: 'a', value:"Adam" },
2143+
{ key: 'b' , value: "Bob"},
2144+
{ key: 'c', value: "Chris" },
2145+
{ key: 'a', value:"Anna" },
2146+
{ key: 'b' , value: "Bill"},
2147+
{ key: 'c', value: "Cooper" }
21482148
];
21492149
//testing out the converter impact on the AggregateQuery type
21502150
return withTestCollectionAndInitialData(testDocs, async collection => {
2151-
let query_ = query(collection).withConverter(converter);
2151+
let query_ = query(collection, where('key', '==', 'a')).withConverter(converter);
21522152

21532153
const countQuery_ = countQuery(query_);
21542154
const snapshot = await getAggregateFromServerDirect(countQuery_);
2155-
expect(snapshot.getCount()).to.equal(6);
2155+
expect(snapshot.getCount()).to.equal(2);
21562156
});
21572157
});
21582158

21592159
it.only('test collection count with converter on collection', () => {
21602160
const testDocs = [
2161-
{ key: 'a' },
2162-
{ key: 'b' },
2163-
{ key: 'c' },
2164-
{ key: 'a' },
2165-
{ key: 'b' },
2166-
{ key: 'c' }
2161+
{ key: 'a', value:"Adam" },
2162+
{ key: 'b' , value: "Bob"},
2163+
{ key: 'c', value: "Chris" },
2164+
{ key: 'a', value:"Anna" },
2165+
{ key: 'b' , value: "Bill"},
2166+
{ key: 'c', value: "Cooper" }
21672167
];
21682168
//testing out the converter impact on the AggregateQuery type
21692169
return withTestCollectionAndInitialData(testDocs, async collection => {
21702170
const ref = collection.withConverter(converter);
2171-
let query_ = query(ref);
2171+
let query_ = query(ref,where('key', '==', 'a'));
21722172

21732173
const countQuery_ = countQuery(query_);
21742174
const snapshot = await getAggregateFromServerDirect(countQuery_);
2175-
expect(snapshot.getCount()).to.equal(6);
2175+
expect(snapshot.getCount()).to.equal(2);
21762176
});
21772177
});
21782178
});

0 commit comments

Comments
 (0)