@@ -71,8 +71,10 @@ export interface Settings extends LiteSettings {
71
71
}
72
72
73
73
/**
74
- * The root reference to the Firestore database and the entry point for the
75
- * tree-shakeable SDK.
74
+ * The Cloud Firestore service interface.
75
+ *
76
+ * Do not call this constructor directly. Instead, use {@link getFirestore()
77
+ * `getFirestore()`}.
76
78
*/
77
79
export class FirebaseFirestore
78
80
extends LiteFirestore
@@ -173,6 +175,12 @@ export class FirebaseFirestore
173
175
}
174
176
}
175
177
178
+ /**
179
+ * Specifies custom settings to be used to configure the `Firestore`
180
+ * instance. Must be set before invoking any other methods.
181
+ *
182
+ * @param settings The settings to use.
183
+ */
176
184
export function initializeFirestore (
177
185
app : FirebaseApp ,
178
186
settings : Settings
@@ -201,6 +209,27 @@ export function getFirestore(app: FirebaseApp): FirebaseFirestore {
201
209
return _getProvider ( app , 'firestore-exp' ) . getImmediate ( ) as FirebaseFirestore ;
202
210
}
203
211
212
+ /**
213
+ * Attempts to enable persistent storage, if possible.
214
+ *
215
+ * Must be called before any other methods (other than settings() and
216
+ * clearPersistence()).
217
+ *
218
+ * If this fails, enablePersistence() will reject the promise it returns.
219
+ * Note that even after this failure, the firestore instance will remain
220
+ * usable, however offline persistence will be disabled.
221
+ *
222
+ * There are several reasons why this can fail, which can be identified by
223
+ * the `code` on the error.
224
+ *
225
+ * * failed-precondition: The app is already open in another browser tab.
226
+ * * unimplemented: The browser is incompatible with the offline
227
+ * persistence implementation.
228
+ *
229
+ * @param settings Optional settings object to configure persistence.
230
+ * @return A promise that represents successfully enabling persistent
231
+ * storage.
232
+ */
204
233
export function enableIndexedDbPersistence (
205
234
firestore : FirebaseFirestore ,
206
235
persistenceSettings ?: PersistenceSettings
@@ -234,6 +263,27 @@ export function enableIndexedDbPersistence(
234
263
} ) ;
235
264
}
236
265
266
+ /**
267
+ * Attempts to enable persistent storage, if possible.
268
+ *
269
+ * Must be called before any other methods (other than settings() and
270
+ * clearPersistence()).
271
+ *
272
+ * If this fails, enablePersistence() will reject the promise it returns.
273
+ * Note that even after this failure, the firestore instance will remain
274
+ * usable, however offline persistence will be disabled.
275
+ *
276
+ * There are several reasons why this can fail, which can be identified by
277
+ * the `code` on the error.
278
+ *
279
+ * * failed-precondition: The app is already open in another browser tab.
280
+ * * unimplemented: The browser is incompatible with the offline
281
+ * persistence implementation.
282
+ *
283
+ * @param settings Optional settings object to configure persistence.
284
+ * @return A promise that represents successfully enabling persistent
285
+ * storage.
286
+ */
237
287
export function enableMultiTabIndexedDbPersistence (
238
288
firestore : FirebaseFirestore
239
289
) : Promise < void > {
@@ -265,6 +315,26 @@ export function enableMultiTabIndexedDbPersistence(
265
315
} ) ;
266
316
}
267
317
318
+ /**
319
+ * Clears the persistent storage. This includes pending writes and cached
320
+ * documents.
321
+ *
322
+ * Must be called while the firestore instance is not started (after the app
323
+ * is shutdown or when the app is first initialized). On startup, this
324
+ * method must be called before other methods (other than settings()). If
325
+ * the firestore instance is still running, the promise will be rejected
326
+ * with the error code of `failed-precondition`.
327
+ *
328
+ * Note: clearPersistence() is primarily intended to help write reliable
329
+ * tests that use Cloud Firestore. It uses an efficient mechanism for
330
+ * dropping existing data but does not attempt to securely overwrite or
331
+ * otherwise make cached data unrecoverable. For applications that are
332
+ * sensitive to the disclosure of cached data in between user sessions, we
333
+ * strongly recommend not enabling persistence at all.
334
+ *
335
+ * @return A promise that is resolved when the persistent storage is
336
+ * cleared. Otherwise, the promise is rejected with an error.
337
+ */
268
338
export function clearIndexedDbPersistence (
269
339
firestore : FirebaseFirestore
270
340
) : Promise < void > {
@@ -290,6 +360,20 @@ export function clearIndexedDbPersistence(
290
360
return deferred . promise ;
291
361
}
292
362
363
+ /**
364
+ * Waits until all currently pending writes for the active user have been acknowledged by the
365
+ * backend.
366
+ *
367
+ * The returned Promise resolves immediately if there are no outstanding writes. Otherwise, the
368
+ * Promise waits for all previously issued writes (including those written in a previous app
369
+ * session), but it does not wait for writes that were added after the method is called. If you
370
+ * want to wait for additional writes, call `waitForPendingWrites()` again.
371
+ *
372
+ * Any outstanding `waitForPendingWrites()` Promises are rejected during user changes.
373
+ *
374
+ * @return A Promise which resolves when all currently pending writes have been
375
+ * acknowledged by the backend.
376
+ */
293
377
export function waitForPendingWrites (
294
378
firestore : FirebaseFirestore
295
379
) : Promise < void > {
@@ -303,6 +387,14 @@ export function waitForPendingWrites(
303
387
return deferred . promise ;
304
388
}
305
389
390
+ /**
391
+ * Re-enables use of the network for this Firestore instance after a prior
392
+ * call to {@link firebase.firestore.Firestore.disableNetwork
393
+ * `disableNetwork()`}.
394
+ *
395
+ * @return A promise that is resolved once the network has been
396
+ * enabled.
397
+ */
306
398
export function enableNetwork ( firestore : FirebaseFirestore ) : Promise < void > {
307
399
firestore . _verifyNotTerminated ( ) ;
308
400
@@ -314,6 +406,16 @@ export function enableNetwork(firestore: FirebaseFirestore): Promise<void> {
314
406
} ) ;
315
407
}
316
408
409
+ /**
410
+ * Disables network usage for this instance. It can be re-enabled via
411
+ * {@link firebase.firestore.Firestore.enableNetwork `enableNetwork()`}. While
412
+ * the network is disabled, any snapshot listeners or get() calls will return
413
+ * results from cache, and any write operations will be queued until the network
414
+ * is restored.
415
+ *
416
+ * @return A promise that is resolved once the network has been
417
+ * disabled.
418
+ */
317
419
export function disableNetwork ( firestore : FirebaseFirestore ) : Promise < void > {
318
420
firestore . _verifyNotTerminated ( ) ;
319
421
@@ -325,6 +427,26 @@ export function disableNetwork(firestore: FirebaseFirestore): Promise<void> {
325
427
} ) ;
326
428
}
327
429
430
+ /**
431
+ * Terminates this Firestore instance.
432
+ *
433
+ * After calling `terminate()` only the `clearPersistence()` method may be used. Any other method
434
+ * will throw a `FirestoreError`.
435
+ *
436
+ * To restart after termination, create a new instance of FirebaseFirestore with
437
+ * `firebase.firestore()`.
438
+ *
439
+ * Termination does not cancel any pending writes, and any promises that are awaiting a response
440
+ * from the server will not be resolved. If you have persistence enabled, the next time you
441
+ * start this instance, it will resume sending these writes to the server.
442
+ *
443
+ * Note: Under normal circumstances, calling `terminate()` is not required. This
444
+ * method is useful only when you want to force this instance to release all of its resources or
445
+ * in combination with `clearPersistence()` to ensure that all local state is destroyed
446
+ * between test runs.
447
+ *
448
+ * @return A promise that is resolved when the instance has been successfully terminated.
449
+ */
328
450
export function terminate ( firestore : FirebaseFirestore ) : Promise < void > {
329
451
_removeServiceInstance ( firestore . app , 'firestore-exp' ) ;
330
452
return firestore . _delete ( ) ;
0 commit comments