Skip to content

Commit 79670bc

Browse files
committed
fix circular dependency between count_query_runner.ts and lite-api/aggregate.ts
1 parent e2cb6a1 commit 79670bc

File tree

5 files changed

+97
-74
lines changed

5 files changed

+97
-74
lines changed

packages/firestore/lite/index.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,18 @@
2727
import { registerFirestore } from './register';
2828
registerFirestore();
2929

30+
export {
31+
aggregateQuerySnapshotEqual,
32+
getCount
33+
} from '../src/lite-api/aggregate';
3034
export {
3135
AggregateField,
3236
AggregateFieldType,
3337
AggregateSpec,
3438
AggregateSpecData,
3539
AggregateQuerySnapshot,
36-
aggregateQuerySnapshotEqual,
37-
count,
38-
getCount
39-
} from '../src/lite-api/aggregate';
40+
count
41+
} from '../src/lite-api/aggregate_types';
4042

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

packages/firestore/src/api/aggregate.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,23 @@
1717

1818
import { Query } from '../api';
1919
import { firestoreClientRunCountQuery } from '../core/firestore_client';
20-
import { AggregateField, AggregateQuerySnapshot } from '../lite-api/aggregate';
20+
import { AggregateField, AggregateQuerySnapshot } from '../lite-api/aggregate_types';
2121
import { cast } from '../util/input_validation';
2222

2323
import { ensureFirestoreConfigured, Firestore } from './database';
2424
import { ExpUserDataWriter } from './reference_impl';
2525

26+
export {
27+
aggregateQuerySnapshotEqual
28+
} from '../lite-api/aggregate';
2629
export {
2730
AggregateField,
2831
AggregateFieldType,
2932
AggregateSpec,
3033
AggregateSpecData,
3134
AggregateQuerySnapshot,
32-
count,
33-
aggregateQuerySnapshotEqual
34-
} from '../lite-api/aggregate';
35+
count
36+
} from '../lite-api/aggregate_types';
3537

3638
/**
3739
* Executes the query and returns the results as a `AggregateQuerySnapshot` from the

packages/firestore/src/core/count_query_runner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717

1818
import { AbstractUserDataWriter, Query } from '../api';
19-
import { AggregateField, AggregateQuerySnapshot } from '../lite-api/aggregate';
19+
import { AggregateField, AggregateQuerySnapshot } from '../lite-api/aggregate_types';
2020
import { Value } from '../protos/firestore_proto_api';
2121
import { Datastore, invokeRunAggregationQueryRpc } from '../remote/datastore';
2222
import { hardAssert } from '../util/assert';

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

Lines changed: 1 addition & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -19,76 +19,12 @@ import { deepEqual } from '@firebase/util';
1919
import { CountQueryRunner } from '../core/count_query_runner';
2020
import { cast } from '../util/input_validation';
2121

22+
import { AggregateField, AggregateQuerySnapshot, AggregateSpec } from './aggregate_types';
2223
import { getDatastore } from './components';
2324
import { Firestore } from './database';
2425
import { Query, queryEqual } from './reference';
2526
import { LiteUserDataWriter } from './reference_impl';
2627

27-
/**
28-
* An `AggregateField`that captures input type T.
29-
*/
30-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
31-
export class AggregateField<T> {
32-
type = 'AggregateField';
33-
}
34-
35-
/**
36-
* Creates and returns an aggregation field that counts the documents in the result set.
37-
* @returns An `AggregateField` object with number input type.
38-
*/
39-
export function count(): AggregateField<number> {
40-
return new AggregateField<number>();
41-
}
42-
43-
/**
44-
* The union of all `AggregateField` types that are returned from the factory
45-
* functions.
46-
*/
47-
export type AggregateFieldType = ReturnType<typeof count>;
48-
49-
/**
50-
* A type whose values are all `AggregateField` objects.
51-
* This is used as an argument to the "getter" functions, and the snapshot will
52-
* map the same names to the corresponding values.
53-
*/
54-
export interface AggregateSpec {
55-
[field: string]: AggregateFieldType;
56-
}
57-
58-
/**
59-
* A type whose keys are taken from an `AggregateSpec` type, and whose values
60-
* are the result of the aggregation performed by the corresponding
61-
* `AggregateField` from the input `AggregateSpec`.
62-
*/
63-
export type AggregateSpecData<T extends AggregateSpec> = {
64-
[P in keyof T]: T[P] extends AggregateField<infer U> ? U : never;
65-
};
66-
67-
/**
68-
* An `AggregateQuerySnapshot` contains the results of running an aggregate query.
69-
*/
70-
export class AggregateQuerySnapshot<T extends AggregateSpec> {
71-
readonly type = 'AggregateQuerySnapshot';
72-
73-
/** @hideconstructor */
74-
constructor(
75-
readonly query: Query<unknown>,
76-
private readonly _data: AggregateSpecData<T>
77-
) {}
78-
79-
/**
80-
* The results of the requested aggregations. The keys of the returned object
81-
* will be the same as those of the `AggregateSpec` object specified to the
82-
* aggregation method, and the values will be the corresponding aggregation
83-
* result.
84-
*
85-
* @returns The aggregation statistics result of running a query.
86-
*/
87-
data(): AggregateSpecData<T> {
88-
return this._data;
89-
}
90-
}
91-
9228
/**
9329
* Counts the number of documents in the result set of the given query, ignoring
9430
* any locally-cached data and any locally-pending writes and simply surfacing
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/**
2+
* @license
3+
* Copyright 2022 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import { Query } from './reference';
19+
20+
/**
21+
* An `AggregateField`that captures input type T.
22+
*/
23+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
24+
export class AggregateField<T> {
25+
type = 'AggregateField';
26+
}
27+
28+
/**
29+
* Creates and returns an aggregation field that counts the documents in the result set.
30+
* @returns An `AggregateField` object with number input type.
31+
*/
32+
export function count(): AggregateField<number> {
33+
return new AggregateField<number>();
34+
}
35+
36+
/**
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.
46+
*/
47+
export interface AggregateSpec {
48+
[field: string]: AggregateFieldType;
49+
}
50+
51+
/**
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`.
55+
*/
56+
export type AggregateSpecData<T extends AggregateSpec> = {
57+
[P in keyof T]: T[P] extends AggregateField<infer U> ? U : never;
58+
};
59+
60+
/**
61+
* An `AggregateQuerySnapshot` contains the results of running an aggregate query.
62+
*/
63+
export class AggregateQuerySnapshot<T extends AggregateSpec> {
64+
readonly type = 'AggregateQuerySnapshot';
65+
66+
/** @hideconstructor */
67+
constructor(
68+
readonly query: Query<unknown>,
69+
private readonly _data: AggregateSpecData<T>
70+
) {}
71+
72+
/**
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.
77+
*
78+
* @returns The aggregation statistics result of running a query.
79+
*/
80+
data(): AggregateSpecData<T> {
81+
return this._data;
82+
}
83+
}

0 commit comments

Comments
 (0)