15
15
* limitations under the License.
16
16
*/
17
17
18
- import { Aggregate } from '../core/aggregate' ;
18
+ import { Aggregate , AggregateImpl } from '../core/aggregate' ;
19
19
import { Bound } from '../core/bound' ;
20
20
import { DatabaseId } from '../core/database_info' ;
21
21
import {
@@ -32,6 +32,7 @@ import {
32
32
newQuery ,
33
33
newQueryForPath ,
34
34
Query ,
35
+ queryToAggregateTarget ,
35
36
queryToTarget
36
37
} from '../core/query' ;
37
38
import { SnapshotVersion } from '../core/snapshot_version' ;
@@ -104,6 +105,8 @@ import {
104
105
WatchTargetChange ,
105
106
WatchTargetChangeState
106
107
} from './watch_change' ;
108
+ import { AggregateSpec } from '../lite-api/aggregate_types' ;
109
+ import { mapToArray } from '../util/obj' ;
107
110
108
111
const DIRECTIONS = ( ( ) => {
109
112
const dirs : { [ dir : string ] : ProtoOrderDirection } = { } ;
@@ -900,6 +903,38 @@ export function toQueryTarget(
900
903
return { queryTarget, parent } ;
901
904
}
902
905
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
+
903
938
export function toRunAggregationQueryRequest (
904
939
serializer : JsonProtoSerializer ,
905
940
target : Target ,
0 commit comments