Skip to content

Commit b68b20e

Browse files
Copy & Paste existing docs
1 parent 80e4219 commit b68b20e

File tree

17 files changed

+1358
-29
lines changed

17 files changed

+1358
-29
lines changed

packages/firestore/exp/src/api/database.ts

Lines changed: 124 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,10 @@ export interface Settings extends LiteSettings {
7171
}
7272

7373
/**
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()`}.
7678
*/
7779
export class FirebaseFirestore
7880
extends LiteFirestore
@@ -173,6 +175,12 @@ export class FirebaseFirestore
173175
}
174176
}
175177

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+
*/
176184
export function initializeFirestore(
177185
app: FirebaseApp,
178186
settings: Settings
@@ -201,6 +209,27 @@ export function getFirestore(app: FirebaseApp): FirebaseFirestore {
201209
return _getProvider(app, 'firestore-exp').getImmediate() as FirebaseFirestore;
202210
}
203211

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+
*/
204233
export function enableIndexedDbPersistence(
205234
firestore: FirebaseFirestore,
206235
persistenceSettings?: PersistenceSettings
@@ -234,6 +263,27 @@ export function enableIndexedDbPersistence(
234263
});
235264
}
236265

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+
*/
237287
export function enableMultiTabIndexedDbPersistence(
238288
firestore: FirebaseFirestore
239289
): Promise<void> {
@@ -265,6 +315,26 @@ export function enableMultiTabIndexedDbPersistence(
265315
});
266316
}
267317

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+
*/
268338
export function clearIndexedDbPersistence(
269339
firestore: FirebaseFirestore
270340
): Promise<void> {
@@ -290,6 +360,20 @@ export function clearIndexedDbPersistence(
290360
return deferred.promise;
291361
}
292362

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+
*/
293377
export function waitForPendingWrites(
294378
firestore: FirebaseFirestore
295379
): Promise<void> {
@@ -303,6 +387,14 @@ export function waitForPendingWrites(
303387
return deferred.promise;
304388
}
305389

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+
*/
306398
export function enableNetwork(firestore: FirebaseFirestore): Promise<void> {
307399
firestore._verifyNotTerminated();
308400

@@ -314,6 +406,16 @@ export function enableNetwork(firestore: FirebaseFirestore): Promise<void> {
314406
});
315407
}
316408

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+
*/
317419
export function disableNetwork(firestore: FirebaseFirestore): Promise<void> {
318420
firestore._verifyNotTerminated();
319421

@@ -325,6 +427,26 @@ export function disableNetwork(firestore: FirebaseFirestore): Promise<void> {
325427
});
326428
}
327429

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+
*/
328450
export function terminate(firestore: FirebaseFirestore): Promise<void> {
329451
_removeServiceInstance(firestore.app, 'firestore-exp');
330452
return firestore._delete();

0 commit comments

Comments
 (0)