@firebase/firestore 3.4.13 → 3.4.14-canary.04dcdbb0f

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 (102) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/firestore/src/api/credentials.d.ts +13 -3
  3. package/dist/firestore/src/api/database.d.ts +34 -3
  4. package/dist/firestore/src/api/index_configuration.d.ts +7 -8
  5. package/dist/firestore/src/api.d.ts +1 -1
  6. package/dist/firestore/src/core/database_info.d.ts +4 -0
  7. package/dist/firestore/src/lite-api/database.d.ts +51 -7
  8. package/dist/firestore/src/local/indexeddb_schema.d.ts +1 -3
  9. package/dist/firestore/src/local/local_store_impl.d.ts +2 -0
  10. package/dist/firestore/src/util/array.d.ts +18 -0
  11. package/dist/firestore/test/integration/api/provider.test.d.ts +17 -0
  12. package/dist/firestore/test/integration/util/firebase_export.d.ts +2 -1
  13. package/dist/firestore/test/integration/util/helpers.d.ts +1 -0
  14. package/dist/firestore/test/unit/local/counting_query_engine.d.ts +11 -0
  15. package/dist/firestore/test/unit/local/local_store_indexeddb.test.d.ts +17 -0
  16. package/dist/firestore/test/unit/specs/index_spec.test.d.ts +17 -0
  17. package/dist/firestore/test/unit/specs/spec_builder.d.ts +5 -0
  18. package/dist/firestore/test/unit/specs/spec_test_runner.d.ts +8 -0
  19. package/dist/firestore/test/unit/util/array.test.d.ts +17 -0
  20. package/dist/index.d.ts +15 -4
  21. package/dist/index.esm2017.js +3793 -3646
  22. package/dist/index.esm2017.js.map +1 -1
  23. package/dist/index.esm5.js +3762 -3648
  24. package/dist/index.esm5.js.map +1 -1
  25. package/dist/index.node.cjs.js +295 -93
  26. package/dist/index.node.cjs.js.map +1 -1
  27. package/dist/index.node.mjs +295 -93
  28. package/dist/index.node.mjs.map +1 -1
  29. package/dist/index.rn.js +3732 -3586
  30. package/dist/index.rn.js.map +1 -1
  31. package/dist/internal.d.ts +53 -19
  32. package/dist/lite/firestore/src/api/credentials.d.ts +13 -3
  33. package/dist/lite/firestore/src/api/database.d.ts +34 -3
  34. package/dist/lite/firestore/src/api/index_configuration.d.ts +7 -8
  35. package/dist/lite/firestore/src/api.d.ts +1 -1
  36. package/dist/lite/firestore/src/core/database_info.d.ts +4 -0
  37. package/dist/lite/firestore/src/lite-api/database.d.ts +51 -7
  38. package/dist/lite/firestore/src/local/indexeddb_schema.d.ts +1 -3
  39. package/dist/lite/firestore/src/local/local_store_impl.d.ts +2 -0
  40. package/dist/lite/firestore/src/util/array.d.ts +18 -0
  41. package/dist/lite/firestore/test/integration/api/provider.test.d.ts +17 -0
  42. package/dist/lite/firestore/test/integration/util/firebase_export.d.ts +2 -1
  43. package/dist/lite/firestore/test/integration/util/helpers.d.ts +1 -0
  44. package/dist/lite/firestore/test/unit/local/counting_query_engine.d.ts +11 -0
  45. package/dist/lite/firestore/test/unit/local/local_store_indexeddb.test.d.ts +17 -0
  46. package/dist/lite/firestore/test/unit/specs/index_spec.test.d.ts +17 -0
  47. package/dist/lite/firestore/test/unit/specs/spec_builder.d.ts +5 -0
  48. package/dist/lite/firestore/test/unit/specs/spec_test_runner.d.ts +8 -0
  49. package/dist/lite/firestore/test/unit/util/array.test.d.ts +17 -0
  50. package/dist/lite/index.browser.esm2017.js +273 -277
  51. package/dist/lite/index.browser.esm2017.js.map +1 -1
  52. package/dist/lite/index.browser.esm5.js +506 -493
  53. package/dist/lite/index.browser.esm5.js.map +1 -1
  54. package/dist/lite/index.d.ts +15 -4
  55. package/dist/lite/index.node.cjs.js +71 -61
  56. package/dist/lite/index.node.cjs.js.map +1 -1
  57. package/dist/lite/index.node.mjs +71 -61
  58. package/dist/lite/index.node.mjs.map +1 -1
  59. package/dist/lite/index.rn.esm2017.js +273 -277
  60. package/dist/lite/index.rn.esm2017.js.map +1 -1
  61. package/dist/lite/internal.d.ts +58 -7
  62. package/dist/lite/packages/firestore/dist/lite/index.browser.esm2017.d.ts +29 -66
  63. package/dist/lite/packages/firestore/src/api/credentials.d.ts +13 -3
  64. package/dist/lite/packages/firestore/src/api/database.d.ts +34 -3
  65. package/dist/lite/packages/firestore/src/api/index_configuration.d.ts +7 -8
  66. package/dist/lite/packages/firestore/src/api.d.ts +1 -1
  67. package/dist/lite/packages/firestore/src/core/database_info.d.ts +4 -0
  68. package/dist/lite/packages/firestore/src/lite-api/database.d.ts +51 -7
  69. package/dist/lite/packages/firestore/src/local/indexeddb_schema.d.ts +1 -3
  70. package/dist/lite/packages/firestore/src/local/local_store_impl.d.ts +2 -0
  71. package/dist/lite/packages/firestore/src/util/array.d.ts +18 -0
  72. package/dist/lite/packages/firestore/test/integration/api/provider.test.d.ts +17 -0
  73. package/dist/lite/packages/firestore/test/integration/util/firebase_export.d.ts +2 -1
  74. package/dist/lite/packages/firestore/test/integration/util/helpers.d.ts +1 -0
  75. package/dist/lite/packages/firestore/test/unit/local/counting_query_engine.d.ts +11 -0
  76. package/dist/lite/packages/firestore/test/unit/local/local_store_indexeddb.test.d.ts +17 -0
  77. package/dist/lite/packages/firestore/test/unit/specs/index_spec.test.d.ts +17 -0
  78. package/dist/lite/packages/firestore/test/unit/specs/spec_builder.d.ts +5 -0
  79. package/dist/lite/packages/firestore/test/unit/specs/spec_test_runner.d.ts +8 -0
  80. package/dist/lite/packages/firestore/test/unit/util/array.test.d.ts +17 -0
  81. package/dist/lite/private.d.ts +25 -7
  82. package/dist/packages/firestore/dist/index.esm2017.d.ts +208 -203
  83. package/dist/packages/firestore/src/api/credentials.d.ts +13 -3
  84. package/dist/packages/firestore/src/api/database.d.ts +34 -3
  85. package/dist/packages/firestore/src/api/index_configuration.d.ts +7 -8
  86. package/dist/packages/firestore/src/api.d.ts +1 -1
  87. package/dist/packages/firestore/src/core/database_info.d.ts +4 -0
  88. package/dist/packages/firestore/src/lite-api/database.d.ts +51 -7
  89. package/dist/packages/firestore/src/local/indexeddb_schema.d.ts +1 -3
  90. package/dist/packages/firestore/src/local/local_store_impl.d.ts +2 -0
  91. package/dist/packages/firestore/src/util/array.d.ts +18 -0
  92. package/dist/packages/firestore/test/integration/api/provider.test.d.ts +17 -0
  93. package/dist/packages/firestore/test/integration/util/firebase_export.d.ts +2 -1
  94. package/dist/packages/firestore/test/integration/util/helpers.d.ts +1 -0
  95. package/dist/packages/firestore/test/unit/local/counting_query_engine.d.ts +11 -0
  96. package/dist/packages/firestore/test/unit/local/local_store_indexeddb.test.d.ts +17 -0
  97. package/dist/packages/firestore/test/unit/specs/index_spec.test.d.ts +17 -0
  98. package/dist/packages/firestore/test/unit/specs/spec_builder.d.ts +5 -0
  99. package/dist/packages/firestore/test/unit/specs/spec_test_runner.d.ts +8 -0
  100. package/dist/packages/firestore/test/unit/util/array.test.d.ts +17 -0
  101. package/dist/private.d.ts +25 -8
  102. package/package.json +11 -9
@@ -687,15 +687,25 @@ export declare function getDoc<T>(reference: DocumentReference<T>): Promise<Docu
687
687
  */
688
688
  export declare function getDocs<T>(query: Query<T>): Promise<QuerySnapshot<T>>;
689
689
  /**
690
- * Returns the existing `Firestore` instance that is associated with the
690
+ * Returns the existing default {@link Firestore} instance that is associated with the
691
+ * default {@link @firebase/app#FirebaseApp}. If no instance exists, initializes a new
692
+ * instance with default settings.
693
+ *
694
+ * @returns The {@link Firestore} instance of the provided app.
695
+ */
696
+ export declare function getFirestore(): Firestore;
697
+ /**
698
+ * Returns the existing default {@link Firestore} instance that is associated with the
691
699
  * provided {@link @firebase/app#FirebaseApp}. If no instance exists, initializes a new
692
700
  * instance with default settings.
693
701
  *
694
- * @param app - The {@link @firebase/app#FirebaseApp} instance that the returned `Firestore`
702
+ * @param app - The {@link @firebase/app#FirebaseApp} instance that the returned {@link Firestore}
695
703
  * instance is associated with.
696
- * @returns The `Firestore` instance of the provided app.
704
+ * @returns The {@link Firestore} instance of the provided app.
697
705
  */
698
- export declare function getFirestore(app?: FirebaseApp): Firestore;
706
+ export declare function getFirestore(app: FirebaseApp): Firestore;
707
+ /* Excluded declaration from this release type: getFirestore */
708
+ /* Excluded declaration from this release type: getFirestore */
699
709
  /**
700
710
  * Returns a special value that can be used with {@link @firebase/firestore/lite#(setDoc:1)} or {@link
701
711
  * @firebase/firestore/lite#(updateDoc:1)} that tells the server to increment the field's current value by
@@ -728,6 +738,7 @@ export declare function increment(n: number): FieldValue;
728
738
  * @returns A newly initialized `Firestore` instance.
729
739
  */
730
740
  export declare function initializeFirestore(app: FirebaseApp, settings: Settings): Firestore;
741
+ /* Excluded declaration from this release type: initializeFirestore */
731
742
  /**
732
743
  * Creates a {@link QueryConstraint} that only returns the first matching documents.
733
744
  *
@@ -14,7 +14,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
14
14
 
15
15
  var nodeFetch__default = /*#__PURE__*/_interopDefaultLegacy(nodeFetch);
16
16
 
17
- const version$1 = "3.4.13";
17
+ const version$1 = "3.4.14-canary.04dcdbb0f";
18
18
 
19
19
  /**
20
20
  * @license
@@ -67,7 +67,7 @@ User.GOOGLE_CREDENTIALS = new User('google-credentials-uid');
67
67
  User.FIRST_PARTY = new User('first-party-uid');
68
68
  User.MOCK_USER = new User('mock-user');
69
69
 
70
- const version = "9.9.1";
70
+ const version = "9.9.3-canary.04dcdbb0f";
71
71
 
72
72
  /**
73
73
  * @license
@@ -514,19 +514,41 @@ class LiteAuthCredentialsProvider {
514
514
  * safer to keep the implementation as-is.
515
515
  */
516
516
  class FirstPartyToken {
517
- constructor(gapi, sessionIndex, iamToken) {
517
+ constructor(gapi, sessionIndex, iamToken, authTokenFactory) {
518
+ this.gapi = gapi;
519
+ this.sessionIndex = sessionIndex;
520
+ this.iamToken = iamToken;
521
+ this.authTokenFactory = authTokenFactory;
518
522
  this.type = 'FirstParty';
519
523
  this.user = User.FIRST_PARTY;
520
- this.headers = new Map();
521
- this.headers.set('X-Goog-AuthUser', sessionIndex);
522
- const authHeader = gapi['auth']['getAuthHeaderValueForFirstParty']([]);
523
- if (authHeader) {
524
- this.headers.set('Authorization', authHeader);
524
+ this._headers = new Map();
525
+ }
526
+ /** Gets an authorization token, using a provided factory function, or falling back to First Party GAPI. */
527
+ getAuthToken() {
528
+ if (this.authTokenFactory) {
529
+ return this.authTokenFactory();
525
530
  }
526
- if (iamToken) {
527
- this.headers.set('X-Goog-Iam-Authorization-Token', iamToken);
531
+ else {
532
+ // Make sure this really is a Gapi client.
533
+ hardAssert(!!(typeof this.gapi === 'object' &&
534
+ this.gapi !== null &&
535
+ this.gapi['auth'] &&
536
+ this.gapi['auth']['getAuthHeaderValueForFirstParty']));
537
+ return this.gapi['auth']['getAuthHeaderValueForFirstParty']([]);
528
538
  }
529
539
  }
540
+ get headers() {
541
+ this._headers.set('X-Goog-AuthUser', this.sessionIndex);
542
+ // Use array notation to prevent minification
543
+ const authHeaderTokenValue = this.getAuthToken();
544
+ if (authHeaderTokenValue) {
545
+ this._headers.set('Authorization', authHeaderTokenValue);
546
+ }
547
+ if (this.iamToken) {
548
+ this._headers.set('X-Goog-Iam-Authorization-Token', this.iamToken);
549
+ }
550
+ return this._headers;
551
+ }
530
552
  }
531
553
  /*
532
554
  * Provides user credentials required for the Firestore JavaScript SDK
@@ -534,13 +556,14 @@ class FirstPartyToken {
534
556
  * to applications hosted by Google.
535
557
  */
536
558
  class FirstPartyAuthCredentialsProvider {
537
- constructor(gapi, sessionIndex, iamToken) {
559
+ constructor(gapi, sessionIndex, iamToken, authTokenFactory) {
538
560
  this.gapi = gapi;
539
561
  this.sessionIndex = sessionIndex;
540
562
  this.iamToken = iamToken;
563
+ this.authTokenFactory = authTokenFactory;
541
564
  }
542
565
  getToken() {
543
- return Promise.resolve(new FirstPartyToken(this.gapi, this.sessionIndex, this.iamToken));
566
+ return Promise.resolve(new FirstPartyToken(this.gapi, this.sessionIndex, this.iamToken, this.authTokenFactory));
544
567
  }
545
568
  start(asyncQueue, changeListener) {
546
569
  // Fire with initial uid.
@@ -597,12 +620,7 @@ function makeAuthCredentialsProvider(credentials) {
597
620
  switch (credentials['type']) {
598
621
  case 'gapi':
599
622
  const client = credentials['client'];
600
- // Make sure this really is a Gapi client.
601
- hardAssert(!!(typeof client === 'object' &&
602
- client !== null &&
603
- client['auth'] &&
604
- client['auth']['getAuthHeaderValueForFirstParty']));
605
- return new FirstPartyAuthCredentialsProvider(client, credentials['sessionIndex'] || '0', credentials['iamToken'] || null);
623
+ return new FirstPartyAuthCredentialsProvider(client, credentials['sessionIndex'] || '0', credentials['iamToken'] || null, credentials['authTokenFactory'] || null);
606
624
  case 'provider':
607
625
  return credentials['client'];
608
626
  default:
@@ -677,6 +695,12 @@ class DatabaseId {
677
695
  other.projectId === this.projectId &&
678
696
  other.database === this.database);
679
697
  }
698
+ }
699
+ function databaseIdFromApp(app, database) {
700
+ if (!Object.prototype.hasOwnProperty.apply(app.options, ['projectId'])) {
701
+ throw new FirestoreError(Code.INVALID_ARGUMENT, '"projectId" not provided in firebase.initializeApp.');
702
+ }
703
+ return new DatabaseId(app.options.projectId, database);
680
704
  }
681
705
 
682
706
  /**
@@ -5161,9 +5185,11 @@ class FirestoreSettingsImpl {
5161
5185
  */
5162
5186
  class Firestore {
5163
5187
  /** @hideconstructor */
5164
- constructor(databaseIdOrApp, _authCredentials, _appCheckCredentials) {
5188
+ constructor(_authCredentials, _appCheckCredentials, _databaseId, _app) {
5165
5189
  this._authCredentials = _authCredentials;
5166
5190
  this._appCheckCredentials = _appCheckCredentials;
5191
+ this._databaseId = _databaseId;
5192
+ this._app = _app;
5167
5193
  /**
5168
5194
  * Whether it's a Firestore or Firestore Lite instance.
5169
5195
  */
@@ -5171,13 +5197,6 @@ class Firestore {
5171
5197
  this._persistenceKey = '(lite)';
5172
5198
  this._settings = new FirestoreSettingsImpl({});
5173
5199
  this._settingsFrozen = false;
5174
- if (databaseIdOrApp instanceof DatabaseId) {
5175
- this._databaseId = databaseIdOrApp;
5176
- }
5177
- else {
5178
- this._app = databaseIdOrApp;
5179
- this._databaseId = databaseIdFromApp(databaseIdOrApp);
5180
- }
5181
5200
  }
5182
5201
  /**
5183
5202
  * The {@link @firebase/app#FirebaseApp} associated with this `Firestore` service
@@ -5240,41 +5259,27 @@ class Firestore {
5240
5259
  return Promise.resolve();
5241
5260
  }
5242
5261
  }
5243
- function databaseIdFromApp(app) {
5244
- if (!Object.prototype.hasOwnProperty.apply(app.options, ['projectId'])) {
5245
- throw new FirestoreError(Code.INVALID_ARGUMENT, '"projectId" not provided in firebase.initializeApp.');
5262
+ function initializeFirestore(app$1, settings, databaseId) {
5263
+ if (!databaseId) {
5264
+ databaseId = DEFAULT_DATABASE_NAME;
5246
5265
  }
5247
- return new DatabaseId(app.options.projectId);
5248
- }
5249
- /**
5250
- * Initializes a new instance of Cloud Firestore with the provided settings.
5251
- * Can only be called before any other functions, including
5252
- * {@link getFirestore}. If the custom settings are empty, this function is
5253
- * equivalent to calling {@link getFirestore}.
5254
- *
5255
- * @param app - The {@link @firebase/app#FirebaseApp} with which the `Firestore` instance will
5256
- * be associated.
5257
- * @param settings - A settings object to configure the `Firestore` instance.
5258
- * @returns A newly initialized `Firestore` instance.
5259
- */
5260
- function initializeFirestore(app$1, settings) {
5261
5266
  const provider = app._getProvider(app$1, 'firestore/lite');
5262
- if (provider.isInitialized()) {
5267
+ if (provider.isInitialized(databaseId)) {
5263
5268
  throw new FirestoreError(Code.FAILED_PRECONDITION, 'Firestore can only be initialized once per app.');
5264
5269
  }
5265
- return provider.initialize({ options: settings });
5270
+ return provider.initialize({
5271
+ options: settings,
5272
+ instanceIdentifier: databaseId
5273
+ });
5266
5274
  }
5267
- /**
5268
- * Returns the existing `Firestore` instance that is associated with the
5269
- * provided {@link @firebase/app#FirebaseApp}. If no instance exists, initializes a new
5270
- * instance with default settings.
5271
- *
5272
- * @param app - The {@link @firebase/app#FirebaseApp} instance that the returned `Firestore`
5273
- * instance is associated with.
5274
- * @returns The `Firestore` instance of the provided app.
5275
- */
5276
- function getFirestore(app$1 = app.getApp()) {
5277
- return app._getProvider(app$1, 'firestore/lite').getImmediate();
5275
+ function getFirestore(appOrDatabaseId, optionalDatabaseId) {
5276
+ const app$1 = typeof appOrDatabaseId === 'object' ? appOrDatabaseId : app.getApp();
5277
+ const databaseId = typeof appOrDatabaseId === 'string'
5278
+ ? appOrDatabaseId
5279
+ : optionalDatabaseId || '(default)';
5280
+ return app._getProvider(app$1, 'firestore/lite').getImmediate({
5281
+ identifier: databaseId
5282
+ });
5278
5283
  }
5279
5284
  /**
5280
5285
  * Modify this instance to communicate with the Cloud Firestore emulator.
@@ -5362,14 +5367,14 @@ function terminate(firestore) {
5362
5367
  */
5363
5368
  function registerFirestore() {
5364
5369
  setSDKVersion(`${app.SDK_VERSION}_lite`);
5365
- app._registerComponent(new component.Component('firestore/lite', (container, { options: settings }) => {
5370
+ app._registerComponent(new component.Component('firestore/lite', (container, { instanceIdentifier: databaseId, options: settings }) => {
5366
5371
  const app = container.getProvider('app').getImmediate();
5367
- const firestoreInstance = new Firestore(app, new LiteAuthCredentialsProvider(container.getProvider('auth-internal')), new LiteAppCheckTokenProvider(container.getProvider('app-check-internal')));
5372
+ const firestoreInstance = new Firestore(new LiteAuthCredentialsProvider(container.getProvider('auth-internal')), new LiteAppCheckTokenProvider(container.getProvider('app-check-internal')), databaseIdFromApp(app, databaseId), app);
5368
5373
  if (settings) {
5369
5374
  firestoreInstance._setSettings(settings);
5370
5375
  }
5371
5376
  return firestoreInstance;
5372
- }, 'PUBLIC'));
5377
+ }, 'PUBLIC').setMultipleInstances(true));
5373
5378
  // RUNTIME_ENV and BUILD_TARGET are replaced by real values during the compilation
5374
5379
  app.registerVersion('firestore-lite', version$1, 'node');
5375
5380
  app.registerVersion('firestore-lite', version$1, 'cjs5');
@@ -7780,7 +7785,7 @@ class Transaction$1 {
7780
7785
  docVersion = doc.version;
7781
7786
  }
7782
7787
  else if (doc.isNoDocument()) {
7783
- // For deleted docs, we must use baseVersion 0 when we overwrite them.
7788
+ // Represent a deleted doc using SnapshotVersion.min().
7784
7789
  docVersion = SnapshotVersion.min();
7785
7790
  }
7786
7791
  else {
@@ -7804,7 +7809,12 @@ class Transaction$1 {
7804
7809
  precondition(key) {
7805
7810
  const version = this.readVersions.get(key.toString());
7806
7811
  if (!this.writtenDocs.has(key.toString()) && version) {
7807
- return Precondition.updateTime(version);
7812
+ if (version.isEqual(SnapshotVersion.min())) {
7813
+ return Precondition.exists(false);
7814
+ }
7815
+ else {
7816
+ return Precondition.updateTime(version);
7817
+ }
7808
7818
  }
7809
7819
  else {
7810
7820
  return Precondition.none();