@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
@@ -6,7 +6,7 @@ import { FirebaseError, createMockUserToken, getModularInstance } from '@firebas
6
6
  import nodeFetch from 'node-fetch';
7
7
  import { randomBytes as randomBytes$1 } from 'crypto';
8
8
 
9
- const version$1 = "3.4.13";
9
+ const version$1 = "3.4.14-canary.04dcdbb0f";
10
10
 
11
11
  /**
12
12
  * @license
@@ -59,7 +59,7 @@ User.GOOGLE_CREDENTIALS = new User('google-credentials-uid');
59
59
  User.FIRST_PARTY = new User('first-party-uid');
60
60
  User.MOCK_USER = new User('mock-user');
61
61
 
62
- const version = "9.9.1";
62
+ const version = "9.9.3-canary.04dcdbb0f";
63
63
 
64
64
  /**
65
65
  * @license
@@ -506,19 +506,41 @@ class LiteAuthCredentialsProvider {
506
506
  * safer to keep the implementation as-is.
507
507
  */
508
508
  class FirstPartyToken {
509
- constructor(gapi, sessionIndex, iamToken) {
509
+ constructor(gapi, sessionIndex, iamToken, authTokenFactory) {
510
+ this.gapi = gapi;
511
+ this.sessionIndex = sessionIndex;
512
+ this.iamToken = iamToken;
513
+ this.authTokenFactory = authTokenFactory;
510
514
  this.type = 'FirstParty';
511
515
  this.user = User.FIRST_PARTY;
512
- this.headers = new Map();
513
- this.headers.set('X-Goog-AuthUser', sessionIndex);
514
- const authHeader = gapi['auth']['getAuthHeaderValueForFirstParty']([]);
515
- if (authHeader) {
516
- this.headers.set('Authorization', authHeader);
516
+ this._headers = new Map();
517
+ }
518
+ /** Gets an authorization token, using a provided factory function, or falling back to First Party GAPI. */
519
+ getAuthToken() {
520
+ if (this.authTokenFactory) {
521
+ return this.authTokenFactory();
517
522
  }
518
- if (iamToken) {
519
- this.headers.set('X-Goog-Iam-Authorization-Token', iamToken);
523
+ else {
524
+ // Make sure this really is a Gapi client.
525
+ hardAssert(!!(typeof this.gapi === 'object' &&
526
+ this.gapi !== null &&
527
+ this.gapi['auth'] &&
528
+ this.gapi['auth']['getAuthHeaderValueForFirstParty']));
529
+ return this.gapi['auth']['getAuthHeaderValueForFirstParty']([]);
520
530
  }
521
531
  }
532
+ get headers() {
533
+ this._headers.set('X-Goog-AuthUser', this.sessionIndex);
534
+ // Use array notation to prevent minification
535
+ const authHeaderTokenValue = this.getAuthToken();
536
+ if (authHeaderTokenValue) {
537
+ this._headers.set('Authorization', authHeaderTokenValue);
538
+ }
539
+ if (this.iamToken) {
540
+ this._headers.set('X-Goog-Iam-Authorization-Token', this.iamToken);
541
+ }
542
+ return this._headers;
543
+ }
522
544
  }
523
545
  /*
524
546
  * Provides user credentials required for the Firestore JavaScript SDK
@@ -526,13 +548,14 @@ class FirstPartyToken {
526
548
  * to applications hosted by Google.
527
549
  */
528
550
  class FirstPartyAuthCredentialsProvider {
529
- constructor(gapi, sessionIndex, iamToken) {
551
+ constructor(gapi, sessionIndex, iamToken, authTokenFactory) {
530
552
  this.gapi = gapi;
531
553
  this.sessionIndex = sessionIndex;
532
554
  this.iamToken = iamToken;
555
+ this.authTokenFactory = authTokenFactory;
533
556
  }
534
557
  getToken() {
535
- return Promise.resolve(new FirstPartyToken(this.gapi, this.sessionIndex, this.iamToken));
558
+ return Promise.resolve(new FirstPartyToken(this.gapi, this.sessionIndex, this.iamToken, this.authTokenFactory));
536
559
  }
537
560
  start(asyncQueue, changeListener) {
538
561
  // Fire with initial uid.
@@ -589,12 +612,7 @@ function makeAuthCredentialsProvider(credentials) {
589
612
  switch (credentials['type']) {
590
613
  case 'gapi':
591
614
  const client = credentials['client'];
592
- // Make sure this really is a Gapi client.
593
- hardAssert(!!(typeof client === 'object' &&
594
- client !== null &&
595
- client['auth'] &&
596
- client['auth']['getAuthHeaderValueForFirstParty']));
597
- return new FirstPartyAuthCredentialsProvider(client, credentials['sessionIndex'] || '0', credentials['iamToken'] || null);
615
+ return new FirstPartyAuthCredentialsProvider(client, credentials['sessionIndex'] || '0', credentials['iamToken'] || null, credentials['authTokenFactory'] || null);
598
616
  case 'provider':
599
617
  return credentials['client'];
600
618
  default:
@@ -669,6 +687,12 @@ class DatabaseId {
669
687
  other.projectId === this.projectId &&
670
688
  other.database === this.database);
671
689
  }
690
+ }
691
+ function databaseIdFromApp(app, database) {
692
+ if (!Object.prototype.hasOwnProperty.apply(app.options, ['projectId'])) {
693
+ throw new FirestoreError(Code.INVALID_ARGUMENT, '"projectId" not provided in firebase.initializeApp.');
694
+ }
695
+ return new DatabaseId(app.options.projectId, database);
672
696
  }
673
697
 
674
698
  /**
@@ -5153,9 +5177,11 @@ class FirestoreSettingsImpl {
5153
5177
  */
5154
5178
  class Firestore {
5155
5179
  /** @hideconstructor */
5156
- constructor(databaseIdOrApp, _authCredentials, _appCheckCredentials) {
5180
+ constructor(_authCredentials, _appCheckCredentials, _databaseId, _app) {
5157
5181
  this._authCredentials = _authCredentials;
5158
5182
  this._appCheckCredentials = _appCheckCredentials;
5183
+ this._databaseId = _databaseId;
5184
+ this._app = _app;
5159
5185
  /**
5160
5186
  * Whether it's a Firestore or Firestore Lite instance.
5161
5187
  */
@@ -5163,13 +5189,6 @@ class Firestore {
5163
5189
  this._persistenceKey = '(lite)';
5164
5190
  this._settings = new FirestoreSettingsImpl({});
5165
5191
  this._settingsFrozen = false;
5166
- if (databaseIdOrApp instanceof DatabaseId) {
5167
- this._databaseId = databaseIdOrApp;
5168
- }
5169
- else {
5170
- this._app = databaseIdOrApp;
5171
- this._databaseId = databaseIdFromApp(databaseIdOrApp);
5172
- }
5173
5192
  }
5174
5193
  /**
5175
5194
  * The {@link @firebase/app#FirebaseApp} associated with this `Firestore` service
@@ -5232,41 +5251,27 @@ class Firestore {
5232
5251
  return Promise.resolve();
5233
5252
  }
5234
5253
  }
5235
- function databaseIdFromApp(app) {
5236
- if (!Object.prototype.hasOwnProperty.apply(app.options, ['projectId'])) {
5237
- throw new FirestoreError(Code.INVALID_ARGUMENT, '"projectId" not provided in firebase.initializeApp.');
5254
+ function initializeFirestore(app, settings, databaseId) {
5255
+ if (!databaseId) {
5256
+ databaseId = DEFAULT_DATABASE_NAME;
5238
5257
  }
5239
- return new DatabaseId(app.options.projectId);
5240
- }
5241
- /**
5242
- * Initializes a new instance of Cloud Firestore with the provided settings.
5243
- * Can only be called before any other functions, including
5244
- * {@link getFirestore}. If the custom settings are empty, this function is
5245
- * equivalent to calling {@link getFirestore}.
5246
- *
5247
- * @param app - The {@link @firebase/app#FirebaseApp} with which the `Firestore` instance will
5248
- * be associated.
5249
- * @param settings - A settings object to configure the `Firestore` instance.
5250
- * @returns A newly initialized `Firestore` instance.
5251
- */
5252
- function initializeFirestore(app, settings) {
5253
5258
  const provider = _getProvider(app, 'firestore/lite');
5254
- if (provider.isInitialized()) {
5259
+ if (provider.isInitialized(databaseId)) {
5255
5260
  throw new FirestoreError(Code.FAILED_PRECONDITION, 'Firestore can only be initialized once per app.');
5256
5261
  }
5257
- return provider.initialize({ options: settings });
5262
+ return provider.initialize({
5263
+ options: settings,
5264
+ instanceIdentifier: databaseId
5265
+ });
5258
5266
  }
5259
- /**
5260
- * Returns the existing `Firestore` instance that is associated with the
5261
- * provided {@link @firebase/app#FirebaseApp}. If no instance exists, initializes a new
5262
- * instance with default settings.
5263
- *
5264
- * @param app - The {@link @firebase/app#FirebaseApp} instance that the returned `Firestore`
5265
- * instance is associated with.
5266
- * @returns The `Firestore` instance of the provided app.
5267
- */
5268
- function getFirestore(app = getApp()) {
5269
- return _getProvider(app, 'firestore/lite').getImmediate();
5267
+ function getFirestore(appOrDatabaseId, optionalDatabaseId) {
5268
+ const app = typeof appOrDatabaseId === 'object' ? appOrDatabaseId : getApp();
5269
+ const databaseId = typeof appOrDatabaseId === 'string'
5270
+ ? appOrDatabaseId
5271
+ : optionalDatabaseId || '(default)';
5272
+ return _getProvider(app, 'firestore/lite').getImmediate({
5273
+ identifier: databaseId
5274
+ });
5270
5275
  }
5271
5276
  /**
5272
5277
  * Modify this instance to communicate with the Cloud Firestore emulator.
@@ -5354,14 +5359,14 @@ function terminate(firestore) {
5354
5359
  */
5355
5360
  function registerFirestore() {
5356
5361
  setSDKVersion(`${SDK_VERSION$1}_lite`);
5357
- _registerComponent(new Component('firestore/lite', (container, { options: settings }) => {
5362
+ _registerComponent(new Component('firestore/lite', (container, { instanceIdentifier: databaseId, options: settings }) => {
5358
5363
  const app = container.getProvider('app').getImmediate();
5359
- const firestoreInstance = new Firestore(app, new LiteAuthCredentialsProvider(container.getProvider('auth-internal')), new LiteAppCheckTokenProvider(container.getProvider('app-check-internal')));
5364
+ const firestoreInstance = new Firestore(new LiteAuthCredentialsProvider(container.getProvider('auth-internal')), new LiteAppCheckTokenProvider(container.getProvider('app-check-internal')), databaseIdFromApp(app, databaseId), app);
5360
5365
  if (settings) {
5361
5366
  firestoreInstance._setSettings(settings);
5362
5367
  }
5363
5368
  return firestoreInstance;
5364
- }, 'PUBLIC'));
5369
+ }, 'PUBLIC').setMultipleInstances(true));
5365
5370
  // RUNTIME_ENV and BUILD_TARGET are replaced by real values during the compilation
5366
5371
  registerVersion('firestore-lite', version$1, 'node');
5367
5372
  registerVersion('firestore-lite', version$1, 'esm2017');
@@ -7772,7 +7777,7 @@ class Transaction$1 {
7772
7777
  docVersion = doc.version;
7773
7778
  }
7774
7779
  else if (doc.isNoDocument()) {
7775
- // For deleted docs, we must use baseVersion 0 when we overwrite them.
7780
+ // Represent a deleted doc using SnapshotVersion.min().
7776
7781
  docVersion = SnapshotVersion.min();
7777
7782
  }
7778
7783
  else {
@@ -7796,7 +7801,12 @@ class Transaction$1 {
7796
7801
  precondition(key) {
7797
7802
  const version = this.readVersions.get(key.toString());
7798
7803
  if (!this.writtenDocs.has(key.toString()) && version) {
7799
- return Precondition.updateTime(version);
7804
+ if (version.isEqual(SnapshotVersion.min())) {
7805
+ return Precondition.exists(false);
7806
+ }
7807
+ else {
7808
+ return Precondition.updateTime(version);
7809
+ }
7800
7810
  }
7801
7811
  else {
7802
7812
  return Precondition.none();