Skip to content

Commit c31f159

Browse files
committed
WIP: [internal] Query/AggregateQuery to proto representation.
1 parent 4be78a3 commit c31f159

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

packages/firestore/src/api.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,10 @@ export {
219219
*/
220220
export { isBase64Available as _isBase64Available } from './platform/base64';
221221
export { DatabaseId as _DatabaseId } from './core/database_info';
222+
export {
223+
queryToProtoQueryTarget as _queryToQueryTargetProto,
224+
aggregationQueryToProtoRunAggregationQueryRequest as _aggregationQueryToProtoRunAggregationQueryRequest
225+
} from './remote/serializer';
222226
export {
223227
cast as _cast,
224228
validateIsNotUsedTogether as _validateIsNotUsedTogether

packages/firestore/src/remote/serializer.ts

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
import { Aggregate } from '../core/aggregate';
18+
import { Aggregate, AggregateImpl } from '../core/aggregate';
1919
import { Bound } from '../core/bound';
2020
import { DatabaseId } from '../core/database_info';
2121
import {
@@ -32,6 +32,7 @@ import {
3232
newQuery,
3333
newQueryForPath,
3434
Query,
35+
queryToAggregateTarget,
3536
queryToTarget
3637
} from '../core/query';
3738
import { SnapshotVersion } from '../core/snapshot_version';
@@ -104,6 +105,8 @@ import {
104105
WatchTargetChange,
105106
WatchTargetChangeState
106107
} from './watch_change';
108+
import { AggregateSpec } from '../lite-api/aggregate_types';
109+
import { mapToArray } from '../util/obj';
107110

108111
const DIRECTIONS = (() => {
109112
const dirs: { [dir: string]: ProtoOrderDirection } = {};
@@ -900,6 +903,38 @@ export function toQueryTarget(
900903
return { queryTarget, parent };
901904
}
902905

906+
export function queryToProtoQueryTarget(
907+
serializer: JsonProtoSerializer,
908+
query: Query
909+
): { queryTarget: ProtoQueryTarget; parent: ResourcePath } {
910+
return toQueryTarget(serializer, queryToTarget(query));
911+
}
912+
913+
export function aggregationQueryToProtoRunAggregationQueryRequest<
914+
AggregateSpecType extends AggregateSpec
915+
>(
916+
serializer: JsonProtoSerializer,
917+
query: Query,
918+
aggregateSpec: AggregateSpecType
919+
): {
920+
request: ProtoRunAggregationQueryRequest;
921+
aliasMap: Record<string, string>;
922+
parent: ResourcePath;
923+
} {
924+
const aggregates = mapToArray(aggregateSpec, (aggregate, alias) => {
925+
return new AggregateImpl(
926+
alias,
927+
aggregate.aggregateType,
928+
aggregate._internalFieldPath
929+
);
930+
});
931+
return toRunAggregationQueryRequest(
932+
serializer,
933+
queryToAggregateTarget(query),
934+
aggregates
935+
);
936+
}
937+
903938
export function toRunAggregationQueryRequest(
904939
serializer: JsonProtoSerializer,
905940
target: Target,

0 commit comments

Comments
 (0)