Skip to content

WIP: [internal] Query/AggregateQuery to proto representation 2 #8174

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/firestore/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ 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';
export {
cast as _cast,
validateIsNotUsedTogether as _validateIsNotUsedTogether
Expand Down
52 changes: 50 additions & 2 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 } from '../core/aggregate';
import { Aggregate, AggregateImpl } from '../core/aggregate';
import { Bound } from '../core/bound';
import { DatabaseId } from '../core/database_info';
import {
Expand All @@ -32,6 +32,7 @@
newQuery,
newQueryForPath,
Query,
queryToAggregateTarget,
queryToTarget
} from '../core/query';
import { SnapshotVersion } from '../core/snapshot_version';
Expand Down Expand Up @@ -93,17 +94,21 @@
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';

Check failure on line 97 in packages/firestore/src/remote/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 97 in packages/firestore/src/remote/serializer.ts

View workflow job for this annotation

GitHub Actions / Lint

`../lite-api/reference` import should occur before import of `../lite-api/timestamp`
import { ExistenceFilter } from './existence_filter';
import { Serializer } from './number_serializer';
import { mapCodeFromRpcCode } from './rpc_error';
import {

Check failure on line 101 in packages/firestore/src/remote/serializer.ts

View workflow job for this annotation

GitHub Actions / Lint

There should be at least one empty line between import groups
DocumentWatchChange,
ExistenceFilterChange,
WatchChange,
WatchTargetChange,
WatchTargetChangeState
} from './watch_change';
import { AggregateSpec } from '../lite-api/aggregate_types';

Check failure on line 108 in packages/firestore/src/remote/serializer.ts

View workflow job for this annotation

GitHub Actions / Lint

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

Check failure on line 109 in packages/firestore/src/remote/serializer.ts

View workflow job for this annotation

GitHub Actions / Lint

`../util/obj` import should occur before import of `../util/types`
import {ensureFirestoreConfigured, Firestore} from "../api/database";

Check failure on line 110 in packages/firestore/src/remote/serializer.ts

View workflow job for this annotation

GitHub Actions / Lint

`../api/database` import should occur before import of `../core/aggregate`
import {cast} from "../util/input_validation";

Check failure on line 111 in packages/firestore/src/remote/serializer.ts

View workflow job for this annotation

GitHub Actions / Lint

`../util/input_validation` import should occur before import of `../util/types`

const DIRECTIONS = (() => {
const dirs: { [dir: string]: ProtoOrderDirection } = {};
Expand Down Expand Up @@ -900,6 +905,49 @@
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
Loading