Skip to content

Commit

Permalink
move to a separate file.
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsannas committed Apr 17, 2024
1 parent bad3afc commit 6c36bde
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 53 deletions.
6 changes: 3 additions & 3 deletions packages/firestore/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,9 @@ export {
export { isBase64Available as _isBase64Available } from './platform/base64';
export { DatabaseId as _DatabaseId } from './core/database_info';
export {
queryToProtoQueryTarget as _queryToQueryTargetProto,
aggregationQueryToProtoRunAggregationQueryRequest as _aggregationQueryToProtoRunAggregationQueryRequest
} from './remote/serializer';
_internalQueryToProtoQueryTarget,
_internalAggregationQueryToProtoRunAggregationQueryRequest
} from './remote/internal_serializer';
export {
cast as _cast,
validateIsNotUsedTogether as _validateIsNotUsedTogether
Expand Down
97 changes: 97 additions & 0 deletions packages/firestore/src/remote/internal_serializer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/**
* @license
* Copyright 2017 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { Query } from '../lite-api/reference';
import { cast } from '../util/input_validation';
import { ensureFirestoreConfigured, Firestore } from '../api/database';

Check failure on line 20 in packages/firestore/src/remote/internal_serializer.ts

View workflow job for this annotation

GitHub Actions / Lint

`../api/database` import should occur before import of `../lite-api/reference`
import { queryToAggregateTarget, queryToTarget } from '../core/query';

Check failure on line 21 in packages/firestore/src/remote/internal_serializer.ts

View workflow job for this annotation

GitHub Actions / Lint

`../core/query` import should occur before import of `../lite-api/reference`
import { AggregateSpec } from '../lite-api/aggregate_types';

Check failure on line 22 in packages/firestore/src/remote/internal_serializer.ts

View workflow job for this annotation

GitHub Actions / Lint

`../lite-api/aggregate_types` import should occur before import of `../lite-api/reference`
import { mapToArray } from '../util/obj';
import { AggregateImpl } from '../core/aggregate';

Check failure on line 24 in packages/firestore/src/remote/internal_serializer.ts

View workflow job for this annotation

GitHub Actions / Lint

There should be at least one empty line between import groups

Check failure on line 24 in packages/firestore/src/remote/internal_serializer.ts

View workflow job for this annotation

GitHub Actions / Lint

`../core/aggregate` import should occur before import of `../lite-api/reference`
import { toQueryTarget, toRunAggregationQueryRequest } from './serializer';

/**
* @internal
* @private
*
* This function is for internal use only.
*
* Returns
* ```
* {
* queryTarget: QueryTarget;
* parent: ResourcePath
* }
* ```
* which contains the proto representation of the given query. Returns `null` if
* the Firestore client associated with the given query has not been initialized
* or has been terminated.
*
* @param query - The Query to convert to proto representation.
*/
export function _internalQueryToProtoQueryTarget(query: Query): any {

Check failure on line 46 in packages/firestore/src/remote/internal_serializer.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
const firestore = cast(query.firestore, Firestore);
const client = ensureFirestoreConfigured(firestore);
const serializer = client._onlineComponents?.datastore.serializer;
if (serializer === undefined) {
return null;
}
return toQueryTarget(serializer!, queryToTarget(query._query));
}

/**
* @internal
* @private
*
* This function is for internal use only.
*
* Returns
* {
* request: RunAggregationQueryRequest;
* aliasMap: Record<string, string>;
* parent: ResourcePath;
* }
* which contains the proto representation of the given aggregation query.
* Returns null if the Firestore client associated with the given query has not
* been initialized or has been terminated.
*
* @param query - The Query to convert to proto representation.
* @param aggregateSpec - The set of aggregations and their aliases.
*/
export function _internalAggregationQueryToProtoRunAggregationQueryRequest<
AggregateSpecType extends AggregateSpec
>(query: Query, aggregateSpec: AggregateSpecType): any {

Check failure on line 77 in packages/firestore/src/remote/internal_serializer.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
const aggregates = mapToArray(aggregateSpec, (aggregate, alias) => {
return new AggregateImpl(
alias,
aggregate.aggregateType,
aggregate._internalFieldPath
);
});
const firestore = cast(query.firestore, Firestore);
const client = ensureFirestoreConfigured(firestore);
const serializer = client._onlineComponents?.datastore.serializer;
if (serializer === undefined) {
return null;
}

return toRunAggregationQueryRequest(
serializer!,
queryToAggregateTarget(query._query),
aggregates
);
}
52 changes: 2 additions & 50 deletions packages/firestore/src/remote/serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import { Aggregate, AggregateImpl } from '../core/aggregate';
import { Aggregate } from '../core/aggregate';
import { Bound } from '../core/bound';
import { DatabaseId } from '../core/database_info';
import {
Expand All @@ -32,7 +32,6 @@ import {
newQuery,
newQueryForPath,
Query,
queryToAggregateTarget,
queryToTarget
} from '../core/query';
import { SnapshotVersion } from '../core/snapshot_version';
Expand Down Expand Up @@ -94,7 +93,7 @@ import { debugAssert, fail, hardAssert } from '../util/assert';
import { ByteString } from '../util/byte_string';
import { Code, FirestoreError } from '../util/error';
import { isNullOrUndefined } from '../util/types';
import { Query as ApiQuery } from '../lite-api/reference';

import { ExistenceFilter } from './existence_filter';
import { Serializer } from './number_serializer';
import { mapCodeFromRpcCode } from './rpc_error';
Expand All @@ -105,10 +104,6 @@ import {
WatchTargetChange,
WatchTargetChangeState
} from './watch_change';
import { AggregateSpec } from '../lite-api/aggregate_types';
import { mapToArray } from '../util/obj';
import {ensureFirestoreConfigured, Firestore} from "../api/database";
import {cast} from "../util/input_validation";

const DIRECTIONS = (() => {
const dirs: { [dir: string]: ProtoOrderDirection } = {};
Expand Down Expand Up @@ -905,49 +900,6 @@ export function toQueryTarget(
return { queryTarget, parent };
}

export function queryToProtoQueryTarget(
query: ApiQuery
): { queryTarget: ProtoQueryTarget; parent: ResourcePath } | null {
const firestore = cast(query.firestore, Firestore);
const client = ensureFirestoreConfigured(firestore);
const serializer = client._onlineComponents?.datastore.serializer;
if (serializer === undefined) {
return null;
}
return toQueryTarget(serializer!, queryToTarget(query._query));
}

export function aggregationQueryToProtoRunAggregationQueryRequest<
AggregateSpecType extends AggregateSpec
>(
query: ApiQuery,
aggregateSpec: AggregateSpecType
): {
request: ProtoRunAggregationQueryRequest;
aliasMap: Record<string, string>;
parent: ResourcePath;
} | null {
const aggregates = mapToArray(aggregateSpec, (aggregate, alias) => {
return new AggregateImpl(
alias,
aggregate.aggregateType,
aggregate._internalFieldPath
);
});
const firestore = cast(query.firestore, Firestore);
const client = ensureFirestoreConfigured(firestore);
const serializer = client._onlineComponents?.datastore.serializer;
if (serializer === undefined) {
return null;
}

return toRunAggregationQueryRequest(
serializer!,
queryToAggregateTarget(query._query),
aggregates
);
}

export function toRunAggregationQueryRequest(
serializer: JsonProtoSerializer,
target: Target,
Expand Down

0 comments on commit 6c36bde

Please sign in to comment.