@firebase/firestore 3.1.1 → 3.2.0-canary.0b3ca78eb

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.
Files changed (50) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/firestore/src/register.d.ts +1 -1
  3. package/dist/firestore/src/remote/persistent_stream.d.ts +5 -1
  4. package/dist/firestore/src/util/async_queue.d.ts +4 -2
  5. package/dist/index.esm2017.js +534 -526
  6. package/dist/index.esm2017.js.map +1 -1
  7. package/dist/index.esm5.js +757 -748
  8. package/dist/index.esm5.js.map +1 -1
  9. package/dist/index.node.cjs.js +7054 -9102
  10. package/dist/index.node.cjs.js.map +1 -1
  11. package/dist/{index.node.cjs.esm2017.js → index.node.mjs} +57 -21
  12. package/dist/index.node.mjs.map +1 -0
  13. package/dist/index.rn.js +534 -526
  14. package/dist/index.rn.js.map +1 -1
  15. package/dist/internal.d.ts +4 -2
  16. package/dist/lite/firestore/src/register.d.ts +1 -1
  17. package/dist/lite/firestore/src/remote/persistent_stream.d.ts +5 -1
  18. package/dist/lite/firestore/src/util/async_queue.d.ts +4 -2
  19. package/dist/lite/index.browser.esm2017.js +2 -2
  20. package/dist/lite/index.browser.esm2017.js.map +1 -1
  21. package/dist/lite/index.browser.esm5.js +2 -2
  22. package/dist/lite/index.browser.esm5.js.map +1 -1
  23. package/dist/lite/index.node.cjs.js +1804 -2261
  24. package/dist/lite/index.node.cjs.js.map +1 -1
  25. package/dist/lite/{index.node.esm2017.js → index.node.mjs} +3 -3
  26. package/dist/lite/index.node.mjs.map +1 -0
  27. package/dist/lite/index.rn.esm2017.js +69 -69
  28. package/dist/lite/index.rn.esm2017.js.map +1 -1
  29. package/dist/lite/internal.d.ts +4 -2
  30. package/dist/lite/packages/firestore/rollup.config.d.ts +6 -6
  31. package/dist/lite/packages/firestore/rollup.config.debug.d.ts +1 -1
  32. package/dist/lite/packages/firestore/rollup.config.lite.d.ts +6 -6
  33. package/dist/lite/packages/firestore/src/register.d.ts +1 -1
  34. package/dist/lite/packages/firestore/src/remote/persistent_stream.d.ts +5 -1
  35. package/dist/lite/packages/firestore/src/util/async_queue.d.ts +4 -2
  36. package/dist/lite/private.d.ts +4 -2
  37. package/dist/packages/firestore/dist/index.esm2017.d.ts +38 -38
  38. package/dist/packages/firestore/rollup.config.d.ts +6 -6
  39. package/dist/packages/firestore/rollup.config.debug.d.ts +1 -1
  40. package/dist/packages/firestore/rollup.config.lite.d.ts +6 -6
  41. package/dist/packages/firestore/src/register.d.ts +1 -1
  42. package/dist/packages/firestore/src/remote/persistent_stream.d.ts +5 -1
  43. package/dist/packages/firestore/src/util/async_queue.d.ts +4 -2
  44. package/dist/private.d.ts +4 -2
  45. package/lite/package.json +1 -1
  46. package/package.json +24 -15
  47. package/dist/index.node.cjs.esm2017.js.map +0 -1
  48. package/dist/lite/firestore/dist/lite/index.node.esm2017.d.ts +0 -1195
  49. package/dist/lite/index.node.esm2017.js.map +0 -1
  50. package/dist/packages/firestore/dist/index.node.cjs.esm2017.d.ts +0 -1844
@@ -4,13 +4,14 @@ 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
- import { resolve, join } from 'path';
9
+ import { dirname, resolve, join } from 'path';
10
+ import { fileURLToPath } from 'url';
10
11
  import { loadSync } from '@grpc/proto-loader';
11
12
 
12
13
  const name = "@firebase/firestore";
13
- const version$1 = "3.1.1";
14
+ const version$1 = "3.2.0-canary.0b3ca78eb";
14
15
 
15
16
  /**
16
17
  * @license
@@ -63,7 +64,7 @@ User.GOOGLE_CREDENTIALS = new User('google-credentials-uid');
63
64
  User.FIRST_PARTY = new User('first-party-uid');
64
65
  User.MOCK_USER = new User('mock-user');
65
66
 
66
- const version = "9.1.3";
67
+ const version = "9.2.0-canary.0b3ca78eb";
67
68
 
68
69
  /**
69
70
  * @license
@@ -14236,8 +14237,13 @@ function nodePromise(action) {
14236
14237
  * See the License for the specific language governing permissions and
14237
14238
  * limitations under the License.
14238
14239
  */
14240
+ // This is a hack fix for Node ES modules to use `require`.
14241
+ // @ts-ignore To avoid using `--module es2020` flag.
14242
+ const require = module.createRequire(import.meta.url);
14243
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
14244
+ const { version: grpcVersion } = require('@grpc/grpc-js/package.json');
14239
14245
  const LOG_TAG$9 = 'Connection';
14240
- const X_GOOG_API_CLIENT_VALUE = `gl-node/${process.versions.node} fire/${SDK_VERSION} grpc/${version$2}`;
14246
+ const X_GOOG_API_CLIENT_VALUE = `gl-node/${process.versions.node} fire/${SDK_VERSION} grpc/${grpcVersion}`;
14241
14247
  function createMetadata(databasePath, token, appId) {
14242
14248
  hardAssert(token === null || token.type === 'OAuth');
14243
14249
  const metadata = new Metadata();
@@ -14401,6 +14407,10 @@ class GrpcConnection {
14401
14407
  * See the License for the specific language governing permissions and
14402
14408
  * limitations under the License.
14403
14409
  */
14410
+ // __filename and __dirname globals are unavailable in ES modules
14411
+ // @ts-ignore To avoid using `--module es2020` flag.
14412
+ const __filename = fileURLToPath(import.meta.url);
14413
+ const __dirname = dirname(__filename);
14404
14414
  /** Used by tests so we can match @grpc/proto-loader behavior. */
14405
14415
  const protoLoaderOptions = {
14406
14416
  longs: String,
@@ -14668,6 +14678,8 @@ class ExponentialBackoff {
14668
14678
  const LOG_TAG$7 = 'PersistentStream';
14669
14679
  /** The time a stream stays open after it is marked idle. */
14670
14680
  const IDLE_TIMEOUT_MS = 60 * 1000;
14681
+ /** The time a stream stays open until we consider it healthy. */
14682
+ const HEALTHY_TIMEOUT_MS = 10 * 1000;
14671
14683
  /**
14672
14684
  * A PersistentStream is an abstract base class that represents a streaming RPC
14673
14685
  * to the Firestore backend. It's built on top of the connections own support
@@ -14701,9 +14713,10 @@ const IDLE_TIMEOUT_MS = 60 * 1000;
14701
14713
  * ListenerType: The type of the listener that will be used for callbacks
14702
14714
  */
14703
14715
  class PersistentStream {
14704
- constructor(queue, connectionTimerId, idleTimerId, connection, credentialsProvider, listener) {
14716
+ constructor(queue, connectionTimerId, idleTimerId, healthTimerId, connection, credentialsProvider, listener) {
14705
14717
  this.queue = queue;
14706
14718
  this.idleTimerId = idleTimerId;
14719
+ this.healthTimerId = healthTimerId;
14707
14720
  this.connection = connection;
14708
14721
  this.credentialsProvider = credentialsProvider;
14709
14722
  this.listener = listener;
@@ -14715,6 +14728,7 @@ class PersistentStream {
14715
14728
  */
14716
14729
  this.closeCount = 0;
14717
14730
  this.idleTimer = null;
14731
+ this.healthCheck = null;
14718
14732
  this.stream = null;
14719
14733
  this.backoff = new ExponentialBackoff(queue, connectionTimerId);
14720
14734
  }
@@ -14727,15 +14741,16 @@ class PersistentStream {
14727
14741
  */
14728
14742
  isStarted() {
14729
14743
  return (this.state === 1 /* Starting */ ||
14730
- this.state === 2 /* Open */ ||
14731
- this.state === 4 /* Backoff */);
14744
+ this.state === 5 /* Backoff */ ||
14745
+ this.isOpen());
14732
14746
  }
14733
14747
  /**
14734
14748
  * Returns true if the underlying RPC is open (the onOpen() listener has been
14735
14749
  * called) and the stream is ready for outbound requests.
14736
14750
  */
14737
14751
  isOpen() {
14738
- return this.state === 2 /* Open */;
14752
+ return (this.state === 2 /* Open */ ||
14753
+ this.state === 3 /* Healthy */);
14739
14754
  }
14740
14755
  /**
14741
14756
  * Starts the RPC. Only allowed if isStarted() returns false. The stream is
@@ -14745,7 +14760,7 @@ class PersistentStream {
14745
14760
  * When start returns, isStarted() will return true.
14746
14761
  */
14747
14762
  start() {
14748
- if (this.state === 3 /* Error */) {
14763
+ if (this.state === 4 /* Error */) {
14749
14764
  this.performBackoff();
14750
14765
  return;
14751
14766
  }
@@ -14811,6 +14826,13 @@ class PersistentStream {
14811
14826
  this.idleTimer = null;
14812
14827
  }
14813
14828
  }
14829
+ /** Cancels the health check delayed operation. */
14830
+ cancelHealthCheck() {
14831
+ if (this.healthCheck) {
14832
+ this.healthCheck.cancel();
14833
+ this.healthCheck = null;
14834
+ }
14835
+ }
14814
14836
  /**
14815
14837
  * Closes the stream and cleans up as necessary:
14816
14838
  *
@@ -14827,11 +14849,12 @@ class PersistentStream {
14827
14849
  async close(finalState, error) {
14828
14850
  // Cancel any outstanding timers (they're guaranteed not to execute).
14829
14851
  this.cancelIdleCheck();
14852
+ this.cancelHealthCheck();
14830
14853
  this.backoff.cancel();
14831
14854
  // Invalidates any stream-related callbacks (e.g. from auth or the
14832
14855
  // underlying stream), guaranteeing they won't execute.
14833
14856
  this.closeCount++;
14834
- if (finalState !== 3 /* Error */) {
14857
+ if (finalState !== 4 /* Error */) {
14835
14858
  // If this is an intentional close ensure we don't delay our next connection attempt.
14836
14859
  this.backoff.reset();
14837
14860
  }
@@ -14841,9 +14864,15 @@ class PersistentStream {
14841
14864
  logError('Using maximum backoff delay to prevent overloading the backend.');
14842
14865
  this.backoff.resetToMax();
14843
14866
  }
14844
- else if (error && error.code === Code.UNAUTHENTICATED) {
14845
- // "unauthenticated" error means the token was rejected. Try force refreshing it in case it
14846
- // just expired.
14867
+ else if (error &&
14868
+ error.code === Code.UNAUTHENTICATED &&
14869
+ this.state !== 3 /* Healthy */) {
14870
+ // "unauthenticated" error means the token was rejected. This should rarely
14871
+ // happen since both Auth and AppCheck ensure a sufficient TTL when we
14872
+ // request a token. If a user manually resets their system clock this can
14873
+ // fail, however. In this case, we should get a Code.UNAUTHENTICATED error
14874
+ // before we received the first message and we need to invalidate the token
14875
+ // to ensure that we fetch a new token.
14847
14876
  this.credentialsProvider.invalidateToken();
14848
14877
  }
14849
14878
  // Clean up the underlying stream because we are no longer interested in events.
@@ -14892,6 +14921,12 @@ class PersistentStream {
14892
14921
  this.stream.onOpen(() => {
14893
14922
  dispatchIfNotClosed(() => {
14894
14923
  this.state = 2 /* Open */;
14924
+ this.healthCheck = this.queue.enqueueAfterDelay(this.healthTimerId, HEALTHY_TIMEOUT_MS, () => {
14925
+ if (this.isOpen()) {
14926
+ this.state = 3 /* Healthy */;
14927
+ }
14928
+ return Promise.resolve();
14929
+ });
14895
14930
  return this.listener.onOpen();
14896
14931
  });
14897
14932
  });
@@ -14907,7 +14942,7 @@ class PersistentStream {
14907
14942
  });
14908
14943
  }
14909
14944
  performBackoff() {
14910
- this.state = 4 /* Backoff */;
14945
+ this.state = 5 /* Backoff */;
14911
14946
  this.backoff.backoffAndRun(async () => {
14912
14947
  this.state = 0 /* Initial */;
14913
14948
  this.start();
@@ -14921,7 +14956,7 @@ class PersistentStream {
14921
14956
  // we never expect this to happen because if we stop a stream ourselves,
14922
14957
  // this callback will never be called. To prevent cases where we retry
14923
14958
  // without a backoff accidentally, we set the stream to error in all cases.
14924
- return this.close(3 /* Error */, error);
14959
+ return this.close(4 /* Error */, error);
14925
14960
  }
14926
14961
  /**
14927
14962
  * Returns a "dispatcher" function that dispatches operations onto the
@@ -14952,7 +14987,7 @@ class PersistentStream {
14952
14987
  */
14953
14988
  class PersistentListenStream extends PersistentStream {
14954
14989
  constructor(queue, connection, credentials, serializer, listener) {
14955
- super(queue, "listen_stream_connection_backoff" /* ListenStreamConnectionBackoff */, "listen_stream_idle" /* ListenStreamIdle */, connection, credentials, listener);
14990
+ super(queue, "listen_stream_connection_backoff" /* ListenStreamConnectionBackoff */, "listen_stream_idle" /* ListenStreamIdle */, "health_check_timeout" /* HealthCheckTimeout */, connection, credentials, listener);
14956
14991
  this.serializer = serializer;
14957
14992
  }
14958
14993
  startRpc(token) {
@@ -15011,7 +15046,7 @@ class PersistentListenStream extends PersistentStream {
15011
15046
  */
15012
15047
  class PersistentWriteStream extends PersistentStream {
15013
15048
  constructor(queue, connection, credentials, serializer, listener) {
15014
- super(queue, "write_stream_connection_backoff" /* WriteStreamConnectionBackoff */, "write_stream_idle" /* WriteStreamIdle */, connection, credentials, listener);
15049
+ super(queue, "write_stream_connection_backoff" /* WriteStreamConnectionBackoff */, "write_stream_idle" /* WriteStreamIdle */, "health_check_timeout" /* HealthCheckTimeout */, connection, credentials, listener);
15015
15050
  this.serializer = serializer;
15016
15051
  this.handshakeComplete_ = false;
15017
15052
  }
@@ -20776,12 +20811,12 @@ function verifyNotInitialized(firestore) {
20776
20811
  * See the License for the specific language governing permissions and
20777
20812
  * limitations under the License.
20778
20813
  */
20779
- function registerFirestore(variant) {
20814
+ function registerFirestore(variant, useFetchStreams = true) {
20780
20815
  setSDKVersion(SDK_VERSION$1);
20781
20816
  _registerComponent(new Component('firestore', (container, { options: settings }) => {
20782
20817
  const app = container.getProvider('app').getImmediate();
20783
20818
  const firestoreInstance = new Firestore(app, new FirebaseCredentialsProvider(container.getProvider('auth-internal')));
20784
- settings = Object.assign({ useFetchStreams: true }, settings);
20819
+ settings = Object.assign({ useFetchStreams }, settings);
20785
20820
  firestoreInstance._setSettings(settings);
20786
20821
  return firestoreInstance;
20787
20822
  }, "PUBLIC" /* PUBLIC */));
@@ -23307,6 +23342,7 @@ class Transaction extends Transaction$1 {
23307
23342
  * rejected promise with the corresponding failure error is returned.
23308
23343
  */
23309
23344
  function runTransaction(firestore, updateFunction) {
23345
+ firestore = cast(firestore, Firestore);
23310
23346
  const client = ensureFirestoreConfigured(firestore);
23311
23347
  return firestoreClientTransaction(client, internalTransaction => updateFunction(new Transaction(firestore, internalTransaction)));
23312
23348
  }
@@ -23449,4 +23485,4 @@ function writeBatch(firestore) {
23449
23485
  registerFirestore('node');
23450
23486
 
23451
23487
  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.cjs.esm2017.js.map
23488
+ //# sourceMappingURL=index.node.mjs.map