16
16
*/
17
17
18
18
import { CredentialsProvider } from '../api/credentials' ;
19
- import { MaybeDocument } from '../model/document' ;
19
+ import { MaybeDocument , Document } from '../model/document' ;
20
20
import { DocumentKey } from '../model/document_key' ;
21
21
import { Mutation , MutationResult } from '../model/mutation' ;
22
22
import * as api from '../protos/firestore_proto_api' ;
@@ -31,6 +31,7 @@ import {
31
31
WriteStreamListener
32
32
} from './persistent_stream' ;
33
33
import { AsyncQueue } from '../util/async_queue' ;
34
+ import { Query } from '../core/query' ;
34
35
35
36
/**
36
37
* Datastore and its related methods are a wrapper around the external Google
@@ -149,6 +150,33 @@ export async function invokeBatchGetDocumentsRpc(
149
150
return result ;
150
151
}
151
152
153
+ export async function invokeRunQueryRpc (
154
+ datastore : Datastore ,
155
+ query : Query
156
+ ) : Promise < Document [ ] > {
157
+ const datastoreImpl = debugCast ( datastore , DatastoreImpl ) ;
158
+ const { structuredQuery, parent } = datastoreImpl . serializer . toQueryTarget (
159
+ query . toTarget ( )
160
+ ) ;
161
+ const params = {
162
+ database : datastoreImpl . serializer . encodedDatabaseId ,
163
+ parent,
164
+ structuredQuery
165
+ } ;
166
+
167
+ const response = await datastoreImpl . invokeStreamingRPC <
168
+ api . RunQueryRequest ,
169
+ api . RunQueryResponse
170
+ > ( 'RunQuery' , params ) ;
171
+
172
+ return (
173
+ response
174
+ // Omit RunQueryResponses that only contain readTimes.
175
+ . filter ( proto => ! ! proto . document )
176
+ . map ( proto => datastoreImpl . serializer . fromDocument ( proto . document ! ) )
177
+ ) ;
178
+ }
179
+
152
180
export function newPersistentWriteStream (
153
181
datastore : Datastore ,
154
182
queue : AsyncQueue ,
0 commit comments