@@ -32,6 +32,8 @@ import {
32
32
FirestoreClient ,
33
33
firestoreClientDisableNetwork ,
34
34
firestoreClientEnableNetwork ,
35
+ firestoreClientGetNamedQuery ,
36
+ firestoreClientLoadBundle ,
35
37
firestoreClientWaitForPendingWrites ,
36
38
setOfflineComponentProvider ,
37
39
setOnlineComponentProvider
@@ -52,6 +54,9 @@ import { cast } from '../util/input_validation';
52
54
import { Deferred } from '../util/promise' ;
53
55
54
56
import { PersistenceSettings , Settings } from './settings' ;
57
+ // TODO(wuandy): This line does not seem right, and it is causing circular dep.
58
+ import { LoadBundleTask } from '../api/bundle' ;
59
+ import { Query } from '../lite/reference' ;
55
60
56
61
export { useFirestoreEmulator } from '../lite/database' ;
57
62
@@ -460,6 +465,56 @@ export function terminate(firestore: FirebaseFirestore): Promise<void> {
460
465
return firestore . _delete ( ) ;
461
466
}
462
467
468
+ /**
469
+ * Loads a Firestore bundle into the local cache.
470
+ *
471
+ * @param firestore - The `Firestore` instance to load bundles for for.
472
+ * @param bundleData
473
+ * An object representing the bundle to be loaded. Valid objects are `ArrayBuffer`,
474
+ * `ReadableStream<Uint8Array>` or `string`.
475
+ *
476
+ * @return
477
+ * A `LoadBundleTask` object, which notifies callers with progress updates, and completion
478
+ * or error events. It can be used as a `Promise<LoadBundleTaskProgress>`.
479
+ */
480
+ export function loadBundle (
481
+ firestore : FirebaseFirestore ,
482
+ bundleData : ReadableStream < Uint8Array > | ArrayBuffer | string
483
+ ) : LoadBundleTask {
484
+ firestore = cast ( firestore , FirebaseFirestore ) ;
485
+ const client = ensureFirestoreConfigured ( firestore ) ;
486
+ const resultTask = new LoadBundleTask ( ) ;
487
+ firestoreClientLoadBundle (
488
+ client ,
489
+ firestore . _databaseId ,
490
+ bundleData ,
491
+ resultTask
492
+ ) ;
493
+ return resultTask ;
494
+ }
495
+
496
+ /**
497
+ * Reads a Firestore `Query` from local cache, identified by the given name.
498
+ *
499
+ * The named queries are packaged into bundles on the server side (along
500
+ * with resulting documents), and loaded to local cache using `loadBundle`. Once in local
501
+ * cache, use this method to extract a `Query` by name.
502
+ */
503
+ export function namedQuery (
504
+ firestore : FirebaseFirestore ,
505
+ name : string
506
+ ) : Promise < Query | null > {
507
+ firestore = cast ( firestore , FirebaseFirestore ) ;
508
+ const client = ensureFirestoreConfigured ( firestore ) ;
509
+ return firestoreClientGetNamedQuery ( client , name ) . then ( namedQuery => {
510
+ if ( ! namedQuery ) {
511
+ return null ;
512
+ }
513
+
514
+ return new Query ( firestore , null , namedQuery . query ) ;
515
+ } ) ;
516
+ }
517
+
463
518
function verifyNotInitialized ( firestore : FirebaseFirestore ) : void {
464
519
if ( firestore . _initialized || firestore . _terminated ) {
465
520
throw new FirestoreError (
0 commit comments