Skip to content

make waitForPendingWrites public #2109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions packages/firebase/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6222,6 +6222,22 @@ declare namespace firebase.firestore {
*/
disableNetwork(): Promise<void>;

/**
* Waits until all currently pending writes for the active user have been acknowledged by the
* backend.
*
* The returned Promise resolves immediately if there are no outstanding writes. Otherwise, the
* Promise waits for all previously issued writes (including those written in a previous app
* session), but it does not wait for writes that were added after the method is called. If you
* want to wait for additional writes, call `waitForPendingWrites()` again.
*
* Any outstanding `waitForPendingWrites()` Promises are rejected during user changes.
*
* @return A Promise which resolves when all currently pending writes have been
* acknowledged by the backend.
*/
waitForPendingWrites(): Promise<void>;

/**
* @hidden
*/
Expand Down
16 changes: 16 additions & 0 deletions packages/firestore-types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,22 @@ export class FirebaseFirestore {
*/
disableNetwork(): Promise<void>;

/**
* Waits until all currently pending writes for the active user have been acknowledged by the
* backend.
*
* The returned Promise resolves immediately if there are no outstanding writes. Otherwise, the
* Promise waits for all previously issued writes (including those written in a previous app
* session), but it does not wait for writes that were added after the method is called. If you
* want to wait for additional writes, call `waitForPendingWrites()` again.
*
* Any outstanding `waitForPendingWrites()` Promises are rejected during user changes.
*
* @return A Promise which resolves when all currently pending writes have been
* acknowledged by the backend.
*/
waitForPendingWrites(): Promise<void>;

INTERNAL: { delete: () => Promise<void> };
}

Expand Down
40 changes: 29 additions & 11 deletions packages/firestore/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,41 @@

# Unreleased
# Unreleased (1.5.0)
- [feature] Added a `Firestore.waitForPendingWrites()` method that
allows users to wait until all pending writes are acknowledged by the
Firestore backend.

# 1.4.10
- [changed] Transactions now perform exponential backoff before retrying.
This means transactions on highly contended documents are more likely to
succeed.

# 1.4.6
- [changed] Transactions are now more flexible. Some sequences of operations
that were previously incorrectly disallowed are now allowed. For example,
after reading a document that doesn't exist, you can now set it multiple
times successfully in a transaction.

# 1.4.5
- [fixed] Fixed an issue where query results were temporarily missing
documents that previously had not matched but had been updated to now
match the query (https://github.com/firebase/firebase-android-sdk/issues/155).

# 1.4.4
- [fixed] Fixed an internal assertion that was triggered when an update
with a `FieldValue.serverTimestamp()` and an update with a
`FieldValue.increment()` were pending for the same document.
- [feature] Added `clearPersistence()`, which clears the persistent storage
including pending writes and cached documents. This is intended to help
write reliable tests (#449).

# 1.4.0
- [changed] Added logging and a custom error message to help users hitting
https://bugs.webkit.org/show_bug.cgi?id=197050 (a bug in iOS 12.2 causing
the SDK to potentially crash when persistence is enabled).
- [fixed] Fixed an issue for environments missing `window.addEventListener`,
such as in React Native with Expo (#1824).
- [changed] Transactions are now more flexible. Some sequences of operations
that were previously incorrectly disallowed are now allowed. For example,
after reading a document that doesn't exist, you can now set it multiple
times successfully in a transaction.
- [changed] Transactions now perform exponential backoff before retrying.
This means transactions on highly contended documents are more likely to
succeed.

# 1.3.5
- [feature] Added `clearPersistence()`, which clears the persistent storage
including pending writes and cached documents. This is intended to help
write reliable tests (#449).

# 1.3.3
- [changed] Firestore now recovers more quickly after network connectivity
Expand Down
16 changes: 1 addition & 15 deletions packages/firestore/src/api/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -468,21 +468,7 @@ export class Firestore implements firestore.FirebaseFirestore, FirebaseService {
return this._firestoreClient!.clientShutdown;
}

/**
* Waits until all currently pending writes for the active user have been acknowledged by the
* backend.
*
* The returned Promise resolves immediately if there are no outstanding writes. Otherwise, the
* Promise waits for all previously issued writes (including those written in a previous app
* session), but it does not wait for writes that were added after the method is called. If you
* wish to wait for additional writes, you have to call `waitForPendingWrites()` again.
*
* Any outstanding `waitForPendingWrites()` Promises are rejected during user changes.
*
* @return A Promise which resolves when all currently pending writes have been
* acknowledged by the backend.
*/
_waitForPendingWrites(): Promise<void> {
waitForPendingWrites(): Promise<void> {
this.ensureClientConfigured();
return this._firestoreClient!.waitForPendingWrites();
}
Expand Down
7 changes: 3 additions & 4 deletions packages/firestore/test/integration/api/database.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import {
withTestDoc,
withTestDocAndInitialData,
DEFAULT_SETTINGS,
waitForPendingWrites,
withMockCredentialProviderTestDb
} from '../util/helpers';
import { User } from '../../../src/auth/user';
Expand Down Expand Up @@ -1146,7 +1145,7 @@ apiDescribe('Database', (persistence: boolean) => {
await firestore.disableNetwork();

const pendingWrites = docRef.set({ foo: 'bar' });
const awaitPendingWrites = waitForPendingWrites(firestore);
const awaitPendingWrites = firestore.waitForPendingWrites();

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

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

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

// `awaitsPendingWrites` is created when there is no pending writes, it will resolve
// immediately even if we are offline.
await waitForPendingWrites(firestore);
await firestore.waitForPendingWrites();
});
});
});
7 changes: 0 additions & 7 deletions packages/firestore/test/integration/util/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,13 +363,6 @@ export function shutdownDb(db: firestore.FirebaseFirestore): Promise<void> {
return (db as any)._shutdown();
}

export function waitForPendingWrites(
db: firestore.FirebaseFirestore
): Promise<void> {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return (db as any)._waitForPendingWrites();
}

// TODO(in-queries): This exists just so we don't have to do the cast
// repeatedly. Once we expose 'array-contains-any' publicly we can remove it and
// just use 'array-contains-any' in all the tests.
Expand Down