-
Notifications
You must be signed in to change notification settings - Fork 943
[internal] Query/AggregateQuery to proto representation #8177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c31f159
WIP: [internal] Query/AggregateQuery to proto representation.
ehsannas bad3afc
using api classes.
ehsannas 123f953
move to a separate file.
ehsannas ad13216
Only return the QueryTarget object.
ehsannas e695a33
declare interface to avoid minification.
ehsannas 406b62b
lint fix.
ehsannas b0bd072
attempt to avoid minification of ToRunAggregationQueryRequestReturnType.
ehsannas 596dadb
allow skipping aliasing.
ehsannas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,89 @@ | ||
/** | ||
* @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 { ensureFirestoreConfigured, Firestore } from '../api/database'; | ||
import { AggregateImpl } from '../core/aggregate'; | ||
import { queryToAggregateTarget, queryToTarget } from '../core/query'; | ||
import { AggregateSpec } from '../lite-api/aggregate_types'; | ||
import { Query } from '../lite-api/reference'; | ||
import { cast } from '../util/input_validation'; | ||
import { mapToArray } from '../util/obj'; | ||
|
||
import { toQueryTarget, toRunAggregationQueryRequest } from './serializer'; | ||
|
||
/** | ||
* @internal | ||
* @private | ||
* | ||
* This function is for internal use only. | ||
* | ||
* Returns the `QueryTarget` 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. | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
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)).queryTarget; | ||
} | ||
|
||
/** | ||
* @internal | ||
* @private | ||
* | ||
* This function is for internal use only. | ||
* | ||
* Returns `RunAggregationQueryRequest` which contains the proto representation | ||
* of the given aggregation query request. 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 | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
>(query: Query, aggregateSpec: AggregateSpecType): any { | ||
ehsannas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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( | ||
ehsannas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
serializer!, | ||
queryToAggregateTarget(query._query), | ||
aggregates, | ||
/* skipAliasing= */ true | ||
).request; | ||
} |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.