Skip to content

Commit 123f953

Browse files
committed
move to a separate file.
1 parent bad3afc commit 123f953

File tree

3 files changed

+105
-53
lines changed

3 files changed

+105
-53
lines changed

packages/firestore/src/api.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,9 @@ export {
220220
export { isBase64Available as _isBase64Available } from './platform/base64';
221221
export { DatabaseId as _DatabaseId } from './core/database_info';
222222
export {
223-
queryToProtoQueryTarget as _queryToQueryTargetProto,
224-
aggregationQueryToProtoRunAggregationQueryRequest as _aggregationQueryToProtoRunAggregationQueryRequest
225-
} from './remote/serializer';
223+
_internalQueryToProtoQueryTarget,
224+
_internalAggregationQueryToProtoRunAggregationQueryRequest
225+
} from './remote/internal_serializer';
226226
export {
227227
cast as _cast,
228228
validateIsNotUsedTogether as _validateIsNotUsedTogether
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/**
2+
* @license
3+
* Copyright 2017 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 { ensureFirestoreConfigured, Firestore } from '../api/database';
19+
import { AggregateImpl } from '../core/aggregate';
20+
import { queryToAggregateTarget, queryToTarget } from '../core/query';
21+
import { AggregateSpec } from '../lite-api/aggregate_types';
22+
import { Query } from '../lite-api/reference';
23+
import { cast } from '../util/input_validation';
24+
import { mapToArray } from '../util/obj';
25+
26+
import { toQueryTarget, toRunAggregationQueryRequest } from './serializer';
27+
28+
/**
29+
* @internal
30+
* @private
31+
*
32+
* This function is for internal use only.
33+
*
34+
* Returns
35+
* ```
36+
* {
37+
* queryTarget: QueryTarget;
38+
* parent: ResourcePath
39+
* }
40+
* ```
41+
* which contains the proto representation of the given query. Returns `null` if
42+
* the Firestore client associated with the given query has not been initialized
43+
* or has been terminated.
44+
*
45+
* @param query - The Query to convert to proto representation.
46+
*/
47+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
48+
export function _internalQueryToProtoQueryTarget(query: Query): any {
49+
const firestore = cast(query.firestore, Firestore);
50+
const client = ensureFirestoreConfigured(firestore);
51+
const serializer = client._onlineComponents?.datastore.serializer;
52+
if (serializer === undefined) {
53+
return null;
54+
}
55+
return toQueryTarget(serializer!, queryToTarget(query._query));
56+
}
57+
58+
/**
59+
* @internal
60+
* @private
61+
*
62+
* This function is for internal use only.
63+
*
64+
* Returns
65+
* {
66+
* request: RunAggregationQueryRequest;
67+
* aliasMap: Record<string, string>;
68+
* parent: ResourcePath;
69+
* }
70+
* which contains the proto representation of the given aggregation query.
71+
* Returns null if the Firestore client associated with the given query has not
72+
* been initialized or has been terminated.
73+
*
74+
* @param query - The Query to convert to proto representation.
75+
* @param aggregateSpec - The set of aggregations and their aliases.
76+
*/
77+
export function _internalAggregationQueryToProtoRunAggregationQueryRequest<
78+
AggregateSpecType extends AggregateSpec
79+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
80+
>(query: Query, aggregateSpec: AggregateSpecType): any {
81+
const aggregates = mapToArray(aggregateSpec, (aggregate, alias) => {
82+
return new AggregateImpl(
83+
alias,
84+
aggregate.aggregateType,
85+
aggregate._internalFieldPath
86+
);
87+
});
88+
const firestore = cast(query.firestore, Firestore);
89+
const client = ensureFirestoreConfigured(firestore);
90+
const serializer = client._onlineComponents?.datastore.serializer;
91+
if (serializer === undefined) {
92+
return null;
93+
}
94+
95+
return toRunAggregationQueryRequest(
96+
serializer!,
97+
queryToAggregateTarget(query._query),
98+
aggregates
99+
);
100+
}

packages/firestore/src/remote/serializer.ts

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

18-
import { Aggregate, AggregateImpl } from '../core/aggregate';
18+
import { Aggregate } from '../core/aggregate';
1919
import { Bound } from '../core/bound';
2020
import { DatabaseId } from '../core/database_info';
2121
import {
@@ -32,7 +32,6 @@ import {
3232
newQuery,
3333
newQueryForPath,
3434
Query,
35-
queryToAggregateTarget,
3635
queryToTarget
3736
} from '../core/query';
3837
import { SnapshotVersion } from '../core/snapshot_version';
@@ -94,7 +93,7 @@ import { debugAssert, fail, hardAssert } from '../util/assert';
9493
import { ByteString } from '../util/byte_string';
9594
import { Code, FirestoreError } from '../util/error';
9695
import { isNullOrUndefined } from '../util/types';
97-
import { Query as ApiQuery } from '../lite-api/reference';
96+
9897
import { ExistenceFilter } from './existence_filter';
9998
import { Serializer } from './number_serializer';
10099
import { mapCodeFromRpcCode } from './rpc_error';
@@ -105,10 +104,6 @@ import {
105104
WatchTargetChange,
106105
WatchTargetChangeState
107106
} from './watch_change';
108-
import { AggregateSpec } from '../lite-api/aggregate_types';
109-
import { mapToArray } from '../util/obj';
110-
import {ensureFirestoreConfigured, Firestore} from "../api/database";
111-
import {cast} from "../util/input_validation";
112107

113108
const DIRECTIONS = (() => {
114109
const dirs: { [dir: string]: ProtoOrderDirection } = {};
@@ -905,49 +900,6 @@ export function toQueryTarget(
905900
return { queryTarget, parent };
906901
}
907902

908-
export function queryToProtoQueryTarget(
909-
query: ApiQuery
910-
): { queryTarget: ProtoQueryTarget; parent: ResourcePath } | null {
911-
const firestore = cast(query.firestore, Firestore);
912-
const client = ensureFirestoreConfigured(firestore);
913-
const serializer = client._onlineComponents?.datastore.serializer;
914-
if (serializer === undefined) {
915-
return null;
916-
}
917-
return toQueryTarget(serializer!, queryToTarget(query._query));
918-
}
919-
920-
export function aggregationQueryToProtoRunAggregationQueryRequest<
921-
AggregateSpecType extends AggregateSpec
922-
>(
923-
query: ApiQuery,
924-
aggregateSpec: AggregateSpecType
925-
): {
926-
request: ProtoRunAggregationQueryRequest;
927-
aliasMap: Record<string, string>;
928-
parent: ResourcePath;
929-
} | null {
930-
const aggregates = mapToArray(aggregateSpec, (aggregate, alias) => {
931-
return new AggregateImpl(
932-
alias,
933-
aggregate.aggregateType,
934-
aggregate._internalFieldPath
935-
);
936-
});
937-
const firestore = cast(query.firestore, Firestore);
938-
const client = ensureFirestoreConfigured(firestore);
939-
const serializer = client._onlineComponents?.datastore.serializer;
940-
if (serializer === undefined) {
941-
return null;
942-
}
943-
944-
return toRunAggregationQueryRequest(
945-
serializer!,
946-
queryToAggregateTarget(query._query),
947-
aggregates
948-
);
949-
}
950-
951903
export function toRunAggregationQueryRequest(
952904
serializer: JsonProtoSerializer,
953905
target: Target,

0 commit comments

Comments
 (0)