-
Notifications
You must be signed in to change notification settings - Fork 889
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
102 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
import { queryToAggregateTarget, queryToTarget } from '../core/query'; | ||
import { AggregateSpec } from '../lite-api/aggregate_types'; | ||
import { mapToArray } from '../util/obj'; | ||
import { AggregateImpl } from '../core/aggregate'; | ||
Check failure on line 24 in packages/firestore/src/remote/internal_serializer.ts GitHub Actions / Lint
|
||
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 { | ||
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 { | ||
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 | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters