15
15
* limitations under the License.
16
16
*/
17
17
18
- import { DocumentData , LoadBundleTask , Query } from '@firebase/firestore-types' ;
19
-
20
18
/**
21
19
* <code>firebase</code> is a global namespace from which all Firebase
22
20
* services are accessed.
@@ -8291,10 +8289,28 @@ declare namespace firebase.firestore {
8291
8289
*/
8292
8290
terminate ( ) : Promise < void > ;
8293
8291
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
+ */
8294
8303
loadBundle (
8295
- bundleData : ArrayBuffer | ReadableStream < ArrayBuffer > | string
8304
+ bundleData : ArrayBuffer | ReadableStream < Uint8Array > | string
8296
8305
) : LoadBundleTask ;
8297
8306
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
+ */
8298
8314
namedQuery ( name : string ) : Promise < Query < DocumentData > | null > ;
8299
8315
8300
8316
/**
@@ -8303,31 +8319,77 @@ declare namespace firebase.firestore {
8303
8319
INTERNAL : { delete : ( ) => Promise < void > } ;
8304
8320
}
8305
8321
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
+ */
8307
8340
onProgress (
8308
8341
next ?: ( progress : LoadBundleTaskProgress ) => any ,
8309
8342
error ?: ( error : Error ) => any ,
8310
8343
complete ?: ( ) => void
8311
8344
) : void ;
8312
8345
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
+ */
8313
8355
then < T , R > (
8314
8356
onFulfilled ?: ( a : LoadBundleTaskProgress ) => T | PromiseLike < T > ,
8315
8357
onRejected ?: ( a : Error ) => R | PromiseLike < R >
8316
8358
) : Promise < T | R > ;
8317
8359
8360
+ /**
8361
+ * Implements the `Promise<LoadBundleTaskProgress>.catch` interface.
8362
+ *
8363
+ * @param onRejected
8364
+ * Called when an error occurs during bundle loading.
8365
+ */
8318
8366
catch < R > (
8319
8367
onRejected : ( a : Error ) => R | PromiseLike < R >
8320
8368
) : Promise < R | LoadBundleTaskProgress > ;
8321
8369
}
8322
8370
8371
+ /**
8372
+ * Represents a progress update or a final state from loading bundles.
8373
+ */
8323
8374
export interface LoadBundleTaskProgress {
8375
+ /** How many documents have been loaded. */
8324
8376
documentsLoaded : number ;
8377
+ /** How many documents are in the bundle being loaded. */
8325
8378
totalDocuments : number ;
8379
+ /** How many bytes have been loaded. */
8326
8380
bytesLoaded : number ;
8381
+ /** How many bytes are in the bundle being loaded. */
8327
8382
totalBytes : number ;
8383
+ /** Current task state. */
8328
8384
taskState : TaskState ;
8329
8385
}
8330
8386
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
+ */
8331
8393
export type TaskState = 'Error' | 'Running' | 'Success' ;
8332
8394
8333
8395
/**
0 commit comments