Skip to content

Commit 8d0f686

Browse files
committed
Commit not working yet.
1 parent 352eb47 commit 8d0f686

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

packages/firestore/exp/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ export {
3232
disableNetwork,
3333
enableNetwork,
3434
terminate,
35-
useFirestoreEmulator
35+
useFirestoreEmulator,
36+
loadBundle,
37+
namedQuery
3638
} from '../src/exp/database';
3739

3840
export { Settings, PersistenceSettings } from '../src/exp/settings';

packages/firestore/src/exp/database.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ import {
3232
FirestoreClient,
3333
firestoreClientDisableNetwork,
3434
firestoreClientEnableNetwork,
35+
firestoreClientGetNamedQuery,
36+
firestoreClientLoadBundle,
3537
firestoreClientWaitForPendingWrites,
3638
setOfflineComponentProvider,
3739
setOnlineComponentProvider
@@ -52,6 +54,9 @@ import { cast } from '../util/input_validation';
5254
import { Deferred } from '../util/promise';
5355

5456
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';
5560

5661
export { useFirestoreEmulator } from '../lite/database';
5762

@@ -460,6 +465,56 @@ export function terminate(firestore: FirebaseFirestore): Promise<void> {
460465
return firestore._delete();
461466
}
462467

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+
463518
function verifyNotInitialized(firestore: FirebaseFirestore): void {
464519
if (firestore._initialized || firestore._terminated) {
465520
throw new FirestoreError(

0 commit comments

Comments
 (0)