Skip to content

Commit 6c36bde

Browse files
committed
move to a separate file.
1 parent bad3afc commit 6c36bde

File tree

3 files changed

+102
-53
lines changed

3 files changed

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

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)