Skip to content

Commit 4bccd8f

Browse files
authored
make waitForPendingWrites public (#2109)
* make waitForPendingWrites public * update tests as well. * Fix CHANGELOG.md * fixing nits. * fix version in changelog * addressing document nits.
1 parent c99ad64 commit 4bccd8f

File tree

6 files changed

+65
-37
lines changed

6 files changed

+65
-37
lines changed

packages/firebase/index.d.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6222,6 +6222,22 @@ declare namespace firebase.firestore {
62226222
*/
62236223
disableNetwork(): Promise<void>;
62246224

6225+
/**
6226+
* Waits until all currently pending writes for the active user have been acknowledged by the
6227+
* backend.
6228+
*
6229+
* The returned Promise resolves immediately if there are no outstanding writes. Otherwise, the
6230+
* Promise waits for all previously issued writes (including those written in a previous app
6231+
* session), but it does not wait for writes that were added after the method is called. If you
6232+
* want to wait for additional writes, call `waitForPendingWrites()` again.
6233+
*
6234+
* Any outstanding `waitForPendingWrites()` Promises are rejected during user changes.
6235+
*
6236+
* @return A Promise which resolves when all currently pending writes have been
6237+
* acknowledged by the backend.
6238+
*/
6239+
waitForPendingWrites(): Promise<void>;
6240+
62256241
/**
62266242
* @hidden
62276243
*/

packages/firestore-types/index.d.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,22 @@ export class FirebaseFirestore {
276276
*/
277277
disableNetwork(): Promise<void>;
278278

279+
/**
280+
* Waits until all currently pending writes for the active user have been acknowledged by the
281+
* backend.
282+
*
283+
* The returned Promise resolves immediately if there are no outstanding writes. Otherwise, the
284+
* Promise waits for all previously issued writes (including those written in a previous app
285+
* session), but it does not wait for writes that were added after the method is called. If you
286+
* want to wait for additional writes, call `waitForPendingWrites()` again.
287+
*
288+
* Any outstanding `waitForPendingWrites()` Promises are rejected during user changes.
289+
*
290+
* @return A Promise which resolves when all currently pending writes have been
291+
* acknowledged by the backend.
292+
*/
293+
waitForPendingWrites(): Promise<void>;
294+
279295
INTERNAL: { delete: () => Promise<void> };
280296
}
281297

packages/firestore/CHANGELOG.md

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,41 @@
11

2-
# Unreleased
2+
# Unreleased (1.5.0)
3+
- [feature] Added a `Firestore.waitForPendingWrites()` method that
4+
allows users to wait until all pending writes are acknowledged by the
5+
Firestore backend.
6+
7+
# 1.4.10
8+
- [changed] Transactions now perform exponential backoff before retrying.
9+
This means transactions on highly contended documents are more likely to
10+
succeed.
11+
12+
# 1.4.6
13+
- [changed] Transactions are now more flexible. Some sequences of operations
14+
that were previously incorrectly disallowed are now allowed. For example,
15+
after reading a document that doesn't exist, you can now set it multiple
16+
times successfully in a transaction.
17+
18+
# 1.4.5
19+
- [fixed] Fixed an issue where query results were temporarily missing
20+
documents that previously had not matched but had been updated to now
21+
match the query (https://github.com/firebase/firebase-android-sdk/issues/155).
22+
23+
# 1.4.4
324
- [fixed] Fixed an internal assertion that was triggered when an update
425
with a `FieldValue.serverTimestamp()` and an update with a
526
`FieldValue.increment()` were pending for the same document.
6-
- [feature] Added `clearPersistence()`, which clears the persistent storage
7-
including pending writes and cached documents. This is intended to help
8-
write reliable tests (#449).
27+
28+
# 1.4.0
929
- [changed] Added logging and a custom error message to help users hitting
1030
https://bugs.webkit.org/show_bug.cgi?id=197050 (a bug in iOS 12.2 causing
1131
the SDK to potentially crash when persistence is enabled).
1232
- [fixed] Fixed an issue for environments missing `window.addEventListener`,
1333
such as in React Native with Expo (#1824).
14-
- [changed] Transactions are now more flexible. Some sequences of operations
15-
that were previously incorrectly disallowed are now allowed. For example,
16-
after reading a document that doesn't exist, you can now set it multiple
17-
times successfully in a transaction.
18-
- [changed] Transactions now perform exponential backoff before retrying.
19-
This means transactions on highly contended documents are more likely to
20-
succeed.
34+
35+
# 1.3.5
36+
- [feature] Added `clearPersistence()`, which clears the persistent storage
37+
including pending writes and cached documents. This is intended to help
38+
write reliable tests (#449).
2139

2240
# 1.3.3
2341
- [changed] Firestore now recovers more quickly after network connectivity

packages/firestore/src/api/database.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -468,21 +468,7 @@ export class Firestore implements firestore.FirebaseFirestore, FirebaseService {
468468
return this._firestoreClient!.clientShutdown;
469469
}
470470

471-
/**
472-
* Waits until all currently pending writes for the active user have been acknowledged by the
473-
* backend.
474-
*
475-
* The returned Promise resolves immediately if there are no outstanding writes. Otherwise, the
476-
* Promise waits for all previously issued writes (including those written in a previous app
477-
* session), but it does not wait for writes that were added after the method is called. If you
478-
* wish to wait for additional writes, you have to call `waitForPendingWrites()` again.
479-
*
480-
* Any outstanding `waitForPendingWrites()` Promises are rejected during user changes.
481-
*
482-
* @return A Promise which resolves when all currently pending writes have been
483-
* acknowledged by the backend.
484-
*/
485-
_waitForPendingWrites(): Promise<void> {
471+
waitForPendingWrites(): Promise<void> {
486472
this.ensureClientConfigured();
487473
return this._firestoreClient!.waitForPendingWrites();
488474
}

packages/firestore/test/integration/api/database.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import {
3838
withTestDoc,
3939
withTestDocAndInitialData,
4040
DEFAULT_SETTINGS,
41-
waitForPendingWrites,
4241
withMockCredentialProviderTestDb
4342
} from '../util/helpers';
4443
import { User } from '../../../src/auth/user';
@@ -1146,7 +1145,7 @@ apiDescribe('Database', (persistence: boolean) => {
11461145
await firestore.disableNetwork();
11471146

11481147
const pendingWrites = docRef.set({ foo: 'bar' });
1149-
const awaitPendingWrites = waitForPendingWrites(firestore);
1148+
const awaitPendingWrites = firestore.waitForPendingWrites();
11501149

11511150
// pending writes can receive acknowledgements now.
11521151
await firestore.enableNetwork();
@@ -1162,7 +1161,7 @@ apiDescribe('Database', (persistence: boolean) => {
11621161
// Prevent pending writes receiving acknowledgement.
11631162
await db.disableNetwork();
11641163
db.doc('abc/123').set({ foo: 'bar' });
1165-
const awaitPendingWrite = waitForPendingWrites(db);
1164+
const awaitPendingWrite = db.waitForPendingWrites();
11661165

11671166
mockCredentialsProvider.triggerUserChange(new User('user_1'));
11681167

@@ -1181,7 +1180,7 @@ apiDescribe('Database', (persistence: boolean) => {
11811180

11821181
// `awaitsPendingWrites` is created when there is no pending writes, it will resolve
11831182
// immediately even if we are offline.
1184-
await waitForPendingWrites(firestore);
1183+
await firestore.waitForPendingWrites();
11851184
});
11861185
});
11871186
});

packages/firestore/test/integration/util/helpers.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -363,13 +363,6 @@ export function shutdownDb(db: firestore.FirebaseFirestore): Promise<void> {
363363
return (db as any)._shutdown();
364364
}
365365

366-
export function waitForPendingWrites(
367-
db: firestore.FirebaseFirestore
368-
): Promise<void> {
369-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
370-
return (db as any)._waitForPendingWrites();
371-
}
372-
373366
// TODO(in-queries): This exists just so we don't have to do the cast
374367
// repeatedly. Once we expose 'array-contains-any' publicly we can remove it and
375368
// just use 'array-contains-any' in all the tests.

0 commit comments

Comments
 (0)