@firebase/firestore 3.1.1 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/firestore/src/register.d.ts +1 -1
- package/dist/firestore/src/remote/persistent_stream.d.ts +5 -1
- package/dist/firestore/src/util/async_queue.d.ts +4 -2
- package/dist/index.esm2017.js +1055 -1047
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.esm5.js +1483 -1474
- package/dist/index.esm5.js.map +1 -1
- package/dist/index.node.cjs.js +7049 -9102
- package/dist/index.node.cjs.js.map +1 -1
- package/dist/{index.node.cjs.esm2017.js → index.node.mjs} +51 -20
- package/dist/index.node.mjs.map +1 -0
- package/dist/index.rn.js +534 -526
- package/dist/index.rn.js.map +1 -1
- package/dist/internal.d.ts +4 -2
- package/dist/lite/firestore/src/register.d.ts +1 -1
- package/dist/lite/firestore/src/remote/persistent_stream.d.ts +5 -1
- package/dist/lite/firestore/src/util/async_queue.d.ts +4 -2
- package/dist/lite/index.browser.esm2017.js +2 -2
- package/dist/lite/index.browser.esm2017.js.map +1 -1
- package/dist/lite/index.browser.esm5.js +2 -2
- package/dist/lite/index.browser.esm5.js.map +1 -1
- package/dist/lite/index.node.cjs.js +1804 -2261
- package/dist/lite/index.node.cjs.js.map +1 -1
- package/dist/lite/{index.node.esm2017.js → index.node.mjs} +3 -3
- package/dist/lite/index.node.mjs.map +1 -0
- package/dist/lite/index.rn.esm2017.js +2 -2
- package/dist/lite/index.rn.esm2017.js.map +1 -1
- package/dist/lite/internal.d.ts +4 -2
- package/dist/lite/packages/firestore/src/register.d.ts +1 -1
- package/dist/lite/packages/firestore/src/remote/persistent_stream.d.ts +5 -1
- package/dist/lite/packages/firestore/src/util/async_queue.d.ts +4 -2
- package/dist/lite/private.d.ts +4 -2
- package/dist/packages/firestore/dist/index.esm2017.d.ts +102 -102
- package/dist/packages/firestore/src/register.d.ts +1 -1
- package/dist/packages/firestore/src/remote/persistent_stream.d.ts +5 -1
- package/dist/packages/firestore/src/util/async_queue.d.ts +4 -2
- package/dist/private.d.ts +4 -2
- package/lite/package.json +1 -1
- package/package.json +15 -9
- package/dist/index.node.cjs.esm2017.js.map +0 -1
- package/dist/lite/firestore/dist/lite/index.node.esm2017.d.ts +0 -1195
- package/dist/lite/index.node.esm2017.js.map +0 -1
- package/dist/packages/firestore/dist/index.node.cjs.esm2017.d.ts +0 -1844
|
@@ -4,13 +4,13 @@ import { Logger, LogLevel } from '@firebase/logger';
|
|
|
4
4
|
import { inspect, TextEncoder, TextDecoder } from 'util';
|
|
5
5
|
import { createMockUserToken, getModularInstance, deepEqual, getUA, isIndexedDBAvailable, isSafari } from '@firebase/util';
|
|
6
6
|
import { randomBytes as randomBytes$1 } from 'crypto';
|
|
7
|
+
import module from 'module';
|
|
7
8
|
import { credentials, loadPackageDefinition, Metadata } from '@grpc/grpc-js';
|
|
8
|
-
import { version as version$2 } from '@grpc/grpc-js/package.json';
|
|
9
9
|
import { resolve, join } from 'path';
|
|
10
10
|
import { loadSync } from '@grpc/proto-loader';
|
|
11
11
|
|
|
12
12
|
const name = "@firebase/firestore";
|
|
13
|
-
const version$1 = "3.
|
|
13
|
+
const version$1 = "3.2.0";
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* @license
|
|
@@ -63,7 +63,7 @@ User.GOOGLE_CREDENTIALS = new User('google-credentials-uid');
|
|
|
63
63
|
User.FIRST_PARTY = new User('first-party-uid');
|
|
64
64
|
User.MOCK_USER = new User('mock-user');
|
|
65
65
|
|
|
66
|
-
const version = "9.
|
|
66
|
+
const version = "9.2.0";
|
|
67
67
|
|
|
68
68
|
/**
|
|
69
69
|
* @license
|
|
@@ -14236,8 +14236,13 @@ function nodePromise(action) {
|
|
|
14236
14236
|
* See the License for the specific language governing permissions and
|
|
14237
14237
|
* limitations under the License.
|
|
14238
14238
|
*/
|
|
14239
|
+
// This is a hack fix for Node ES modules to use `require`.
|
|
14240
|
+
// @ts-ignore To avoid using `--module es2020` flag.
|
|
14241
|
+
const require = module.createRequire(import.meta.url);
|
|
14242
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
14243
|
+
const { version: grpcVersion } = require('@grpc/grpc-js/package.json');
|
|
14239
14244
|
const LOG_TAG$9 = 'Connection';
|
|
14240
|
-
const X_GOOG_API_CLIENT_VALUE = `gl-node/${process.versions.node} fire/${SDK_VERSION} grpc/${
|
|
14245
|
+
const X_GOOG_API_CLIENT_VALUE = `gl-node/${process.versions.node} fire/${SDK_VERSION} grpc/${grpcVersion}`;
|
|
14241
14246
|
function createMetadata(databasePath, token, appId) {
|
|
14242
14247
|
hardAssert(token === null || token.type === 'OAuth');
|
|
14243
14248
|
const metadata = new Metadata();
|
|
@@ -14668,6 +14673,8 @@ class ExponentialBackoff {
|
|
|
14668
14673
|
const LOG_TAG$7 = 'PersistentStream';
|
|
14669
14674
|
/** The time a stream stays open after it is marked idle. */
|
|
14670
14675
|
const IDLE_TIMEOUT_MS = 60 * 1000;
|
|
14676
|
+
/** The time a stream stays open until we consider it healthy. */
|
|
14677
|
+
const HEALTHY_TIMEOUT_MS = 10 * 1000;
|
|
14671
14678
|
/**
|
|
14672
14679
|
* A PersistentStream is an abstract base class that represents a streaming RPC
|
|
14673
14680
|
* to the Firestore backend. It's built on top of the connections own support
|
|
@@ -14701,9 +14708,10 @@ const IDLE_TIMEOUT_MS = 60 * 1000;
|
|
|
14701
14708
|
* ListenerType: The type of the listener that will be used for callbacks
|
|
14702
14709
|
*/
|
|
14703
14710
|
class PersistentStream {
|
|
14704
|
-
constructor(queue, connectionTimerId, idleTimerId, connection, credentialsProvider, listener) {
|
|
14711
|
+
constructor(queue, connectionTimerId, idleTimerId, healthTimerId, connection, credentialsProvider, listener) {
|
|
14705
14712
|
this.queue = queue;
|
|
14706
14713
|
this.idleTimerId = idleTimerId;
|
|
14714
|
+
this.healthTimerId = healthTimerId;
|
|
14707
14715
|
this.connection = connection;
|
|
14708
14716
|
this.credentialsProvider = credentialsProvider;
|
|
14709
14717
|
this.listener = listener;
|
|
@@ -14715,6 +14723,7 @@ class PersistentStream {
|
|
|
14715
14723
|
*/
|
|
14716
14724
|
this.closeCount = 0;
|
|
14717
14725
|
this.idleTimer = null;
|
|
14726
|
+
this.healthCheck = null;
|
|
14718
14727
|
this.stream = null;
|
|
14719
14728
|
this.backoff = new ExponentialBackoff(queue, connectionTimerId);
|
|
14720
14729
|
}
|
|
@@ -14727,15 +14736,16 @@ class PersistentStream {
|
|
|
14727
14736
|
*/
|
|
14728
14737
|
isStarted() {
|
|
14729
14738
|
return (this.state === 1 /* Starting */ ||
|
|
14730
|
-
this.state ===
|
|
14731
|
-
this.
|
|
14739
|
+
this.state === 5 /* Backoff */ ||
|
|
14740
|
+
this.isOpen());
|
|
14732
14741
|
}
|
|
14733
14742
|
/**
|
|
14734
14743
|
* Returns true if the underlying RPC is open (the onOpen() listener has been
|
|
14735
14744
|
* called) and the stream is ready for outbound requests.
|
|
14736
14745
|
*/
|
|
14737
14746
|
isOpen() {
|
|
14738
|
-
return this.state === 2 /* Open
|
|
14747
|
+
return (this.state === 2 /* Open */ ||
|
|
14748
|
+
this.state === 3 /* Healthy */);
|
|
14739
14749
|
}
|
|
14740
14750
|
/**
|
|
14741
14751
|
* Starts the RPC. Only allowed if isStarted() returns false. The stream is
|
|
@@ -14745,7 +14755,7 @@ class PersistentStream {
|
|
|
14745
14755
|
* When start returns, isStarted() will return true.
|
|
14746
14756
|
*/
|
|
14747
14757
|
start() {
|
|
14748
|
-
if (this.state ===
|
|
14758
|
+
if (this.state === 4 /* Error */) {
|
|
14749
14759
|
this.performBackoff();
|
|
14750
14760
|
return;
|
|
14751
14761
|
}
|
|
@@ -14811,6 +14821,13 @@ class PersistentStream {
|
|
|
14811
14821
|
this.idleTimer = null;
|
|
14812
14822
|
}
|
|
14813
14823
|
}
|
|
14824
|
+
/** Cancels the health check delayed operation. */
|
|
14825
|
+
cancelHealthCheck() {
|
|
14826
|
+
if (this.healthCheck) {
|
|
14827
|
+
this.healthCheck.cancel();
|
|
14828
|
+
this.healthCheck = null;
|
|
14829
|
+
}
|
|
14830
|
+
}
|
|
14814
14831
|
/**
|
|
14815
14832
|
* Closes the stream and cleans up as necessary:
|
|
14816
14833
|
*
|
|
@@ -14827,11 +14844,12 @@ class PersistentStream {
|
|
|
14827
14844
|
async close(finalState, error) {
|
|
14828
14845
|
// Cancel any outstanding timers (they're guaranteed not to execute).
|
|
14829
14846
|
this.cancelIdleCheck();
|
|
14847
|
+
this.cancelHealthCheck();
|
|
14830
14848
|
this.backoff.cancel();
|
|
14831
14849
|
// Invalidates any stream-related callbacks (e.g. from auth or the
|
|
14832
14850
|
// underlying stream), guaranteeing they won't execute.
|
|
14833
14851
|
this.closeCount++;
|
|
14834
|
-
if (finalState !==
|
|
14852
|
+
if (finalState !== 4 /* Error */) {
|
|
14835
14853
|
// If this is an intentional close ensure we don't delay our next connection attempt.
|
|
14836
14854
|
this.backoff.reset();
|
|
14837
14855
|
}
|
|
@@ -14841,9 +14859,15 @@ class PersistentStream {
|
|
|
14841
14859
|
logError('Using maximum backoff delay to prevent overloading the backend.');
|
|
14842
14860
|
this.backoff.resetToMax();
|
|
14843
14861
|
}
|
|
14844
|
-
else if (error &&
|
|
14845
|
-
|
|
14846
|
-
|
|
14862
|
+
else if (error &&
|
|
14863
|
+
error.code === Code.UNAUTHENTICATED &&
|
|
14864
|
+
this.state !== 3 /* Healthy */) {
|
|
14865
|
+
// "unauthenticated" error means the token was rejected. This should rarely
|
|
14866
|
+
// happen since both Auth and AppCheck ensure a sufficient TTL when we
|
|
14867
|
+
// request a token. If a user manually resets their system clock this can
|
|
14868
|
+
// fail, however. In this case, we should get a Code.UNAUTHENTICATED error
|
|
14869
|
+
// before we received the first message and we need to invalidate the token
|
|
14870
|
+
// to ensure that we fetch a new token.
|
|
14847
14871
|
this.credentialsProvider.invalidateToken();
|
|
14848
14872
|
}
|
|
14849
14873
|
// Clean up the underlying stream because we are no longer interested in events.
|
|
@@ -14892,6 +14916,12 @@ class PersistentStream {
|
|
|
14892
14916
|
this.stream.onOpen(() => {
|
|
14893
14917
|
dispatchIfNotClosed(() => {
|
|
14894
14918
|
this.state = 2 /* Open */;
|
|
14919
|
+
this.healthCheck = this.queue.enqueueAfterDelay(this.healthTimerId, HEALTHY_TIMEOUT_MS, () => {
|
|
14920
|
+
if (this.isOpen()) {
|
|
14921
|
+
this.state = 3 /* Healthy */;
|
|
14922
|
+
}
|
|
14923
|
+
return Promise.resolve();
|
|
14924
|
+
});
|
|
14895
14925
|
return this.listener.onOpen();
|
|
14896
14926
|
});
|
|
14897
14927
|
});
|
|
@@ -14907,7 +14937,7 @@ class PersistentStream {
|
|
|
14907
14937
|
});
|
|
14908
14938
|
}
|
|
14909
14939
|
performBackoff() {
|
|
14910
|
-
this.state =
|
|
14940
|
+
this.state = 5 /* Backoff */;
|
|
14911
14941
|
this.backoff.backoffAndRun(async () => {
|
|
14912
14942
|
this.state = 0 /* Initial */;
|
|
14913
14943
|
this.start();
|
|
@@ -14921,7 +14951,7 @@ class PersistentStream {
|
|
|
14921
14951
|
// we never expect this to happen because if we stop a stream ourselves,
|
|
14922
14952
|
// this callback will never be called. To prevent cases where we retry
|
|
14923
14953
|
// without a backoff accidentally, we set the stream to error in all cases.
|
|
14924
|
-
return this.close(
|
|
14954
|
+
return this.close(4 /* Error */, error);
|
|
14925
14955
|
}
|
|
14926
14956
|
/**
|
|
14927
14957
|
* Returns a "dispatcher" function that dispatches operations onto the
|
|
@@ -14952,7 +14982,7 @@ class PersistentStream {
|
|
|
14952
14982
|
*/
|
|
14953
14983
|
class PersistentListenStream extends PersistentStream {
|
|
14954
14984
|
constructor(queue, connection, credentials, serializer, listener) {
|
|
14955
|
-
super(queue, "listen_stream_connection_backoff" /* ListenStreamConnectionBackoff */, "listen_stream_idle" /* ListenStreamIdle */, connection, credentials, listener);
|
|
14985
|
+
super(queue, "listen_stream_connection_backoff" /* ListenStreamConnectionBackoff */, "listen_stream_idle" /* ListenStreamIdle */, "health_check_timeout" /* HealthCheckTimeout */, connection, credentials, listener);
|
|
14956
14986
|
this.serializer = serializer;
|
|
14957
14987
|
}
|
|
14958
14988
|
startRpc(token) {
|
|
@@ -15011,7 +15041,7 @@ class PersistentListenStream extends PersistentStream {
|
|
|
15011
15041
|
*/
|
|
15012
15042
|
class PersistentWriteStream extends PersistentStream {
|
|
15013
15043
|
constructor(queue, connection, credentials, serializer, listener) {
|
|
15014
|
-
super(queue, "write_stream_connection_backoff" /* WriteStreamConnectionBackoff */, "write_stream_idle" /* WriteStreamIdle */, connection, credentials, listener);
|
|
15044
|
+
super(queue, "write_stream_connection_backoff" /* WriteStreamConnectionBackoff */, "write_stream_idle" /* WriteStreamIdle */, "health_check_timeout" /* HealthCheckTimeout */, connection, credentials, listener);
|
|
15015
15045
|
this.serializer = serializer;
|
|
15016
15046
|
this.handshakeComplete_ = false;
|
|
15017
15047
|
}
|
|
@@ -20776,12 +20806,12 @@ function verifyNotInitialized(firestore) {
|
|
|
20776
20806
|
* See the License for the specific language governing permissions and
|
|
20777
20807
|
* limitations under the License.
|
|
20778
20808
|
*/
|
|
20779
|
-
function registerFirestore(variant) {
|
|
20809
|
+
function registerFirestore(variant, useFetchStreams = true) {
|
|
20780
20810
|
setSDKVersion(SDK_VERSION$1);
|
|
20781
20811
|
_registerComponent(new Component('firestore', (container, { options: settings }) => {
|
|
20782
20812
|
const app = container.getProvider('app').getImmediate();
|
|
20783
20813
|
const firestoreInstance = new Firestore(app, new FirebaseCredentialsProvider(container.getProvider('auth-internal')));
|
|
20784
|
-
settings = Object.assign({ useFetchStreams
|
|
20814
|
+
settings = Object.assign({ useFetchStreams }, settings);
|
|
20785
20815
|
firestoreInstance._setSettings(settings);
|
|
20786
20816
|
return firestoreInstance;
|
|
20787
20817
|
}, "PUBLIC" /* PUBLIC */));
|
|
@@ -23307,6 +23337,7 @@ class Transaction extends Transaction$1 {
|
|
|
23307
23337
|
* rejected promise with the corresponding failure error is returned.
|
|
23308
23338
|
*/
|
|
23309
23339
|
function runTransaction(firestore, updateFunction) {
|
|
23340
|
+
firestore = cast(firestore, Firestore);
|
|
23310
23341
|
const client = ensureFirestoreConfigured(firestore);
|
|
23311
23342
|
return firestoreClientTransaction(client, internalTransaction => updateFunction(new Transaction(firestore, internalTransaction)));
|
|
23312
23343
|
}
|
|
@@ -23449,4 +23480,4 @@ function writeBatch(firestore) {
|
|
|
23449
23480
|
registerFirestore('node');
|
|
23450
23481
|
|
|
23451
23482
|
export { AbstractUserDataWriter, Bytes, CACHE_SIZE_UNLIMITED, CollectionReference, DocumentReference, DocumentSnapshot, FieldPath, FieldValue, Firestore, FirestoreError, GeoPoint, LoadBundleTask, Query, QueryConstraint, QueryDocumentSnapshot, QuerySnapshot, SnapshotMetadata, Timestamp, Transaction, WriteBatch, DatabaseId as _DatabaseId, DocumentKey as _DocumentKey, EmptyCredentialsProvider as _EmptyCredentialsProvider, FieldPath$1 as _FieldPath, cast as _cast, debugAssert as _debugAssert, isBase64Available as _isBase64Available, logWarn as _logWarn, validateIsNotUsedTogether as _validateIsNotUsedTogether, addDoc, arrayRemove, arrayUnion, clearIndexedDbPersistence, collection, collectionGroup, connectFirestoreEmulator, deleteDoc, deleteField, disableNetwork, doc, documentId, enableIndexedDbPersistence, enableMultiTabIndexedDbPersistence, enableNetwork, endAt, endBefore, ensureFirestoreConfigured, executeWrite, getDoc, getDocFromCache, getDocFromServer, getDocs, getDocsFromCache, getDocsFromServer, getFirestore, increment, initializeFirestore, limit, limitToLast, loadBundle, namedQuery, onSnapshot, onSnapshotsInSync, orderBy, query, queryEqual, refEqual, runTransaction, serverTimestamp, setDoc, setLogLevel, snapshotEqual, startAfter, startAt, terminate, updateDoc, waitForPendingWrites, where, writeBatch };
|
|
23452
|
-
//# sourceMappingURL=index.node.
|
|
23483
|
+
//# sourceMappingURL=index.node.mjs.map
|