Skip to content

Commit 29f957a

Browse files
authored
Merge 29e76c9 into a5b8d3a
2 parents a5b8d3a + 29e76c9 commit 29f957a

File tree

3 files changed

+69
-7
lines changed

3 files changed

+69
-7
lines changed

packages/firebase/index.d.ts

Lines changed: 66 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
* limitations under the License.
1616
*/
1717

18-
import { DocumentData, LoadBundleTask, Query } from '@firebase/firestore-types';
19-
2018
/**
2119
* <code>firebase</code> is a global namespace from which all Firebase
2220
* services are accessed.
@@ -8291,10 +8289,28 @@ declare namespace firebase.firestore {
82918289
*/
82928290
terminate(): Promise<void>;
82938291

8292+
/**
8293+
* Loads a Firestore bundle into the local cache.
8294+
*
8295+
* @param bundleData
8296+
* An object representing the bundle to be loaded. Valid objects are `ArrayBuffer`,
8297+
* `ReadableStream<Uint8Array>` or `string`.
8298+
*
8299+
* @return
8300+
* A `LoadBundleTask` object, which notifies callers with progress updates, and completion
8301+
* or error events. It can be used as a `Promise<LoadBundleTaskProgress>`.
8302+
*/
82948303
loadBundle(
8295-
bundleData: ArrayBuffer | ReadableStream<ArrayBuffer> | string
8304+
bundleData: ArrayBuffer | ReadableStream<Uint8Array> | string
82968305
): LoadBundleTask;
82978306

8307+
/**
8308+
* Reads a Firestore `Query` from local cache, identified by the given name.
8309+
*
8310+
* The named queries are packaged into bundles on the server side (along
8311+
* with resulting documents), and loaded to local cache using `loadBundle`. Once in local
8312+
* cache, use this method to extract a `Query` by name.
8313+
*/
82988314
namedQuery(name: string): Promise<Query<DocumentData> | null>;
82998315

83008316
/**
@@ -8303,31 +8319,77 @@ declare namespace firebase.firestore {
83038319
INTERNAL: { delete: () => Promise<void> };
83048320
}
83058321

8306-
export interface LoadBundleTask {
8322+
/**
8323+
* Represents the task of loading a Firestore bundle. It provides progress of bundle
8324+
* loading, as well as task completion and error events.
8325+
*
8326+
* The API is compatible with `Promise<LoadBundleTaskProgress>`.
8327+
*/
8328+
export interface LoadBundleTask extends PromiseLike<LoadBundleTaskProgress> {
8329+
/**
8330+
* Registers functions to listen to bundle loading progress events.
8331+
* @param next
8332+
* Called when there is a progress update from bundle loading. Typically `next` calls occur
8333+
* each time a Firestore document is loaded from the bundle.
8334+
* @param error
8335+
* Called when an error occurs during bundle loading. The task aborts after reporting the
8336+
* error, and there should be no more updates after this.
8337+
* @param complete
8338+
* Called when the loading task is complete.
8339+
*/
83078340
onProgress(
83088341
next?: (progress: LoadBundleTaskProgress) => any,
83098342
error?: (error: Error) => any,
83108343
complete?: () => void
83118344
): void;
83128345

8346+
/**
8347+
* Implements the `Promise<LoadBundleTaskProgress>.then` interface.
8348+
*
8349+
* @param onFulfilled
8350+
* Called on the completion of the loading task with a final `LoadBundleTaskProgress` update.
8351+
* The update will always have its `taskState` set to `"Success"`.
8352+
* @param onRejected
8353+
* Called when an error occurs during bundle loading.
8354+
*/
83138355
then<T, R>(
83148356
onFulfilled?: (a: LoadBundleTaskProgress) => T | PromiseLike<T>,
83158357
onRejected?: (a: Error) => R | PromiseLike<R>
83168358
): Promise<T | R>;
83178359

8360+
/**
8361+
* Implements the `Promise<LoadBundleTaskProgress>.catch` interface.
8362+
*
8363+
* @param onRejected
8364+
* Called when an error occurs during bundle loading.
8365+
*/
83188366
catch<R>(
83198367
onRejected: (a: Error) => R | PromiseLike<R>
83208368
): Promise<R | LoadBundleTaskProgress>;
83218369
}
83228370

8371+
/**
8372+
* Represents a progress update or a final state from loading bundles.
8373+
*/
83238374
export interface LoadBundleTaskProgress {
8375+
/** How many documents have been loaded. */
83248376
documentsLoaded: number;
8377+
/** How many documents are in the bundle being loaded. */
83258378
totalDocuments: number;
8379+
/** How many bytes have been loaded. */
83268380
bytesLoaded: number;
8381+
/** How many bytes are in the bundle being loaded. */
83278382
totalBytes: number;
8383+
/** Current task state. */
83288384
taskState: TaskState;
83298385
}
83308386

8387+
/**
8388+
* Represents the state of bundle loading tasks.
8389+
*
8390+
* Both 'Error' and 'Success' are sinking state: task will abort or complete and there will
8391+
* be no more updates after they are reported.
8392+
*/
83318393
export type TaskState = 'Error' | 'Running' | 'Success';
83328394

83338395
/**

packages/firestore-types/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,15 @@ export class FirebaseFirestore {
9797
terminate(): Promise<void>;
9898

9999
loadBundle(
100-
bundleData: ArrayBuffer | ReadableStream<ArrayBuffer> | string
100+
bundleData: ArrayBuffer | ReadableStream<Uint8Array> | string
101101
): LoadBundleTask;
102102

103103
namedQuery(name: string): Promise<Query<DocumentData> | null>;
104104

105105
INTERNAL: { delete: () => Promise<void> };
106106
}
107107

108-
export interface LoadBundleTask {
108+
export interface LoadBundleTask extends PromiseLike<LoadBundleTaskProgress> {
109109
onProgress(
110110
next?: (progress: LoadBundleTaskProgress) => any,
111111
error?: (error: Error) => any,

packages/firestore/exp-types/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ export function snapshotEqual<T>(
516516
right: DocumentSnapshot<T> | QuerySnapshot<T>
517517
): boolean;
518518

519-
export interface LoadBundleTask {
519+
export interface LoadBundleTask extends PromiseLike<LoadBundleTaskProgress> {
520520
onProgress(
521521
next?: (progress: LoadBundleTaskProgress) => any,
522522
error?: (error: Error) => any,

0 commit comments

Comments
 (0)