Skip to content

Commit 5c653d1

Browse files
committed
Add JSDoc for bundles
1 parent cc8dd9c commit 5c653d1

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed

packages/firebase/index.d.ts

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8291,10 +8291,26 @@ declare namespace firebase.firestore {
82918291
*/
82928292
terminate(): Promise<void>;
82938293

8294+
/**
8295+
* Loads a Firestore bundle into the local cache.
8296+
*
8297+
* @param bundleData An object representing the bundle to be load, could be a `ArrayBuffer`,
8298+
* a `ReadableStream<Uint8Array>` or a `string`.
8299+
*
8300+
* @return A `LoadBundleTask` object, which notifies callers with progress update, completion
8301+
* or error event. 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 that is associated to a given name.
8309+
*
8310+
* The named queries are from bundles, and saved as a result of `loadBundle`. `namedQuery`
8311+
* retrieves the queries used to built the bundles, saving the need to manually construct
8312+
* those queries.
8313+
*/
82988314
namedQuery(name: string): Promise<Query<DocumentData> | null>;
82998315

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

8322+
/**
8323+
* Represents the task of loading a Firestore bundle. It provides progress of the bundle
8324+
* loading, task completion and error events should they be any.
8325+
*
8326+
* It can be used as a `Promise<LoadBundleTaskProgress>`.
8327+
*/
83068328
export interface LoadBundleTask {
8329+
/**
8330+
* Registers functions to listen to bundle loading progresses.
8331+
* @param next Called there is a progress update from bundle loading, typically whenever
8332+
* a Firestore document is loaded it will generate a progress update.
8333+
* @param error Called when there is an error occurred from loading the bundle. The task
8334+
* aborts after reporting the error, and there should be no more updates after this.
8335+
* @param complete Called when the loading task is complete.
8336+
*/
83078337
onProgress(
83088338
next?: (progress: LoadBundleTaskProgress) => any,
83098339
error?: (error: Error) => any,
83108340
complete?: () => void
83118341
): void;
83128342

8343+
/**
8344+
* Implements a `Promise<LoadBundleTaskProgress>` interface.
8345+
*
8346+
* @param onFulfilled It is called with the compeltion `LoadBundleTaskProgress` when the
8347+
* loading task completes.
8348+
* @param onRejected It is called when there is an error occurred from loading the bundle.
8349+
*/
83138350
then<T, R>(
83148351
onFulfilled?: (a: LoadBundleTaskProgress) => T | PromiseLike<T>,
83158352
onRejected?: (a: Error) => R | PromiseLike<R>
83168353
): Promise<T | R>;
83178354

8355+
/**
8356+
* Implements a `Promise<LoadBundleTaskProgress>` interface.
8357+
*
8358+
* @param onRejected It is called when there is an error occurred from loading the bundle.
8359+
*/
83188360
catch<R>(
83198361
onRejected: (a: Error) => R | PromiseLike<R>
83208362
): Promise<R | LoadBundleTaskProgress>;
83218363
}
83228364

8365+
/**
8366+
* Represents a progress update or a final state from loading bundles.
8367+
*/
83238368
export interface LoadBundleTaskProgress {
8369+
/** How many documents have been loaded. */
83248370
documentsLoaded: number;
8371+
/** How many documents are in the bundle being loaded. */
83258372
totalDocuments: number;
8373+
/** How many bytes have been loaded. */
83268374
bytesLoaded: number;
8375+
/** How many bytes are in the bundle being loaded. */
83278376
totalBytes: number;
8377+
/** Current task state. */
83288378
taskState: TaskState;
83298379
}
83308380

8381+
/**
8382+
* Represents the state of bundle loading tasks.
8383+
*
8384+
* Both 'Error' and 'Success' are sinking state: task will abort or complete and there will
8385+
* be no more updates after they are reported.
8386+
*/
83318387
export type TaskState = 'Error' | 'Running' | 'Success';
83328388

83338389
/**

packages/firestore-types/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ 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>;

0 commit comments

Comments
 (0)