@@ -94,7 +94,7 @@ import { debugAssert, fail, hardAssert } from '../util/assert';
94
94
import { ByteString } from '../util/byte_string' ;
95
95
import { Code , FirestoreError } from '../util/error' ;
96
96
import { isNullOrUndefined } from '../util/types' ;
97
-
97
+ import { Query as ApiQuery } from '../lite-api/reference' ;
98
98
import { ExistenceFilter } from './existence_filter' ;
99
99
import { Serializer } from './number_serializer' ;
100
100
import { mapCodeFromRpcCode } from './rpc_error' ;
@@ -107,6 +107,8 @@ import {
107
107
} from './watch_change' ;
108
108
import { AggregateSpec } from '../lite-api/aggregate_types' ;
109
109
import { mapToArray } from '../util/obj' ;
110
+ import { ensureFirestoreConfigured , Firestore } from "../api/database" ;
111
+ import { cast } from "../util/input_validation" ;
110
112
111
113
const DIRECTIONS = ( ( ) => {
112
114
const dirs : { [ dir : string ] : ProtoOrderDirection } = { } ;
@@ -904,33 +906,44 @@ export function toQueryTarget(
904
906
}
905
907
906
908
export function queryToProtoQueryTarget (
907
- serializer : JsonProtoSerializer ,
908
- query : Query
909
- ) : { queryTarget : ProtoQueryTarget ; parent : ResourcePath } {
910
- return toQueryTarget ( serializer , queryToTarget ( query ) ) ;
909
+ query : ApiQuery
910
+ ) : { queryTarget : ProtoQueryTarget ; parent : ResourcePath } | null {
911
+ const firestore = cast ( query . firestore , Firestore ) ;
912
+ const client = ensureFirestoreConfigured ( firestore ) ;
913
+ const serializer = client . _onlineComponents ?. datastore . serializer ;
914
+ if ( serializer === undefined ) {
915
+ return null ;
916
+ }
917
+ return toQueryTarget ( serializer ! , queryToTarget ( query . _query ) ) ;
911
918
}
912
919
913
920
export function aggregationQueryToProtoRunAggregationQueryRequest <
914
921
AggregateSpecType extends AggregateSpec
915
922
> (
916
- serializer : JsonProtoSerializer ,
917
- query : Query ,
923
+ query : ApiQuery ,
918
924
aggregateSpec : AggregateSpecType
919
925
) : {
920
926
request : ProtoRunAggregationQueryRequest ;
921
927
aliasMap : Record < string , string > ;
922
928
parent : ResourcePath ;
923
- } {
929
+ } | null {
924
930
const aggregates = mapToArray ( aggregateSpec , ( aggregate , alias ) => {
925
931
return new AggregateImpl (
926
932
alias ,
927
933
aggregate . aggregateType ,
928
934
aggregate . _internalFieldPath
929
935
) ;
930
936
} ) ;
937
+ const firestore = cast ( query . firestore , Firestore ) ;
938
+ const client = ensureFirestoreConfigured ( firestore ) ;
939
+ const serializer = client . _onlineComponents ?. datastore . serializer ;
940
+ if ( serializer === undefined ) {
941
+ return null ;
942
+ }
943
+
931
944
return toRunAggregationQueryRequest (
932
- serializer ,
933
- queryToAggregateTarget ( query ) ,
945
+ serializer ! ,
946
+ queryToAggregateTarget ( query . _query ) ,
934
947
aggregates
935
948
) ;
936
949
}
0 commit comments