@firebase/firestore 3.4.4-202202622812 → 3.4.4-canary.4cec42313

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 (88) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/dist/firestore/src/api/{query.d.ts → filter.d.ts} +0 -0
  3. package/dist/firestore/src/api.d.ts +1 -1
  4. package/dist/firestore/src/core/database_info.d.ts +1 -0
  5. package/dist/firestore/src/core/target.d.ts +26 -1
  6. package/dist/firestore/src/local/indexeddb_schema.d.ts +121 -7
  7. package/dist/firestore/src/local/local_serializer.d.ts +1 -1
  8. package/dist/firestore/src/local/remote_document_change_buffer.d.ts +3 -12
  9. package/dist/firestore/src/model/document.d.ts +7 -0
  10. package/dist/firestore/src/model/document_key.d.ts +1 -0
  11. package/dist/firestore/src/model/field_index.d.ts +87 -7
  12. package/dist/firestore/src/model/values.d.ts +7 -0
  13. package/dist/firestore/test/unit/local/test_remote_document_cache.d.ts +1 -1
  14. package/dist/firestore/test/unit/model/field_index.test.d.ts +17 -0
  15. package/dist/firestore/test/unit/model/target.test.d.ts +17 -0
  16. package/dist/firestore/test/util/helpers.d.ts +8 -2
  17. package/dist/index.esm2017.js +3421 -3246
  18. package/dist/index.esm2017.js.map +1 -1
  19. package/dist/index.esm5.js +3736 -3630
  20. package/dist/index.esm5.js.map +1 -1
  21. package/dist/index.node.cjs.js +412 -177
  22. package/dist/index.node.cjs.js.map +1 -1
  23. package/dist/index.node.mjs +412 -177
  24. package/dist/index.node.mjs.map +1 -1
  25. package/dist/index.rn.js +3408 -3271
  26. package/dist/index.rn.js.map +1 -1
  27. package/dist/internal.d.ts +12 -12
  28. package/dist/lite/firestore/src/api/{query.d.ts → filter.d.ts} +0 -0
  29. package/dist/lite/firestore/src/api.d.ts +1 -1
  30. package/dist/lite/firestore/src/core/database_info.d.ts +1 -0
  31. package/dist/lite/firestore/src/core/target.d.ts +26 -1
  32. package/dist/lite/firestore/src/local/indexeddb_schema.d.ts +121 -7
  33. package/dist/lite/firestore/src/local/local_serializer.d.ts +1 -1
  34. package/dist/lite/firestore/src/local/remote_document_change_buffer.d.ts +3 -12
  35. package/dist/lite/firestore/src/model/document.d.ts +7 -0
  36. package/dist/lite/firestore/src/model/document_key.d.ts +1 -0
  37. package/dist/lite/firestore/src/model/field_index.d.ts +87 -7
  38. package/dist/lite/firestore/src/model/values.d.ts +7 -0
  39. package/dist/lite/firestore/test/unit/local/test_remote_document_cache.d.ts +1 -1
  40. package/dist/lite/firestore/test/unit/model/field_index.test.d.ts +17 -0
  41. package/dist/lite/firestore/test/unit/model/target.test.d.ts +17 -0
  42. package/dist/lite/firestore/test/util/helpers.d.ts +8 -2
  43. package/dist/lite/index.browser.esm2017.js +20 -9
  44. package/dist/lite/index.browser.esm2017.js.map +1 -1
  45. package/dist/lite/index.browser.esm5.js +88 -81
  46. package/dist/lite/index.browser.esm5.js.map +1 -1
  47. package/dist/lite/index.node.cjs.js +20 -8
  48. package/dist/lite/index.node.cjs.js.map +1 -1
  49. package/dist/lite/index.node.mjs +20 -8
  50. package/dist/lite/index.node.mjs.map +1 -1
  51. package/dist/lite/index.rn.esm2017.js +20 -9
  52. package/dist/lite/index.rn.esm2017.js.map +1 -1
  53. package/dist/lite/internal.d.ts +9 -0
  54. package/dist/lite/packages/firestore/dist/lite/index.browser.esm2017.d.ts +1 -0
  55. package/dist/lite/packages/firestore/src/api/{query.d.ts → filter.d.ts} +0 -0
  56. package/dist/lite/packages/firestore/src/api.d.ts +1 -1
  57. package/dist/lite/packages/firestore/src/core/database_info.d.ts +1 -0
  58. package/dist/lite/packages/firestore/src/core/target.d.ts +26 -1
  59. package/dist/lite/packages/firestore/src/local/indexeddb_schema.d.ts +121 -7
  60. package/dist/lite/packages/firestore/src/local/local_serializer.d.ts +1 -1
  61. package/dist/lite/packages/firestore/src/local/remote_document_change_buffer.d.ts +3 -12
  62. package/dist/lite/packages/firestore/src/model/document.d.ts +7 -0
  63. package/dist/lite/packages/firestore/src/model/document_key.d.ts +1 -0
  64. package/dist/lite/packages/firestore/src/model/field_index.d.ts +87 -7
  65. package/dist/lite/packages/firestore/src/model/values.d.ts +7 -0
  66. package/dist/lite/packages/firestore/test/unit/local/test_remote_document_cache.d.ts +1 -1
  67. package/dist/lite/packages/firestore/test/unit/model/field_index.test.d.ts +17 -0
  68. package/dist/lite/packages/firestore/test/unit/model/target.test.d.ts +17 -0
  69. package/dist/lite/packages/firestore/test/util/helpers.d.ts +8 -2
  70. package/dist/lite/private.d.ts +7 -0
  71. package/dist/packages/firestore/dist/index.esm2017.d.ts +182 -180
  72. package/dist/packages/firestore/src/api/{query.d.ts → filter.d.ts} +0 -0
  73. package/dist/packages/firestore/src/api.d.ts +1 -1
  74. package/dist/packages/firestore/src/core/database_info.d.ts +1 -0
  75. package/dist/packages/firestore/src/core/target.d.ts +26 -1
  76. package/dist/packages/firestore/src/local/indexeddb_schema.d.ts +121 -7
  77. package/dist/packages/firestore/src/local/local_serializer.d.ts +1 -1
  78. package/dist/packages/firestore/src/local/remote_document_change_buffer.d.ts +3 -12
  79. package/dist/packages/firestore/src/model/document.d.ts +7 -0
  80. package/dist/packages/firestore/src/model/document_key.d.ts +1 -0
  81. package/dist/packages/firestore/src/model/field_index.d.ts +87 -7
  82. package/dist/packages/firestore/src/model/values.d.ts +7 -0
  83. package/dist/packages/firestore/test/unit/local/test_remote_document_cache.d.ts +1 -1
  84. package/dist/packages/firestore/test/unit/model/field_index.test.d.ts +17 -0
  85. package/dist/packages/firestore/test/unit/model/target.test.d.ts +17 -0
  86. package/dist/packages/firestore/test/util/helpers.d.ts +8 -2
  87. package/dist/private.d.ts +10 -12
  88. package/package.json +9 -9
@@ -12,7 +12,7 @@ var grpcJs = require('@grpc/grpc-js');
12
12
  var protoLoader = require('@grpc/proto-loader');
13
13
 
14
14
  const name = "@firebase/firestore";
15
- const version$1 = "3.4.4-202202622812";
15
+ const version$1 = "3.4.4-canary.4cec42313";
16
16
 
17
17
  /**
18
18
  * @license
@@ -65,7 +65,7 @@ User.GOOGLE_CREDENTIALS = new User('google-credentials-uid');
65
65
  User.FIRST_PARTY = new User('first-party-uid');
66
66
  User.MOCK_USER = new User('mock-user');
67
67
 
68
- const version = "9.6.5-202202622812";
68
+ const version = "9.6.5-canary.4cec42313";
69
69
 
70
70
  /**
71
71
  * @license
@@ -1196,23 +1196,6 @@ function decodeResourcePath(path) {
1196
1196
  }
1197
1197
  return new ResourcePath(segments);
1198
1198
  }
1199
-
1200
- /**
1201
- * @license
1202
- * Copyright 2017 Google LLC
1203
- *
1204
- * Licensed under the Apache License, Version 2.0 (the "License");
1205
- * you may not use this file except in compliance with the License.
1206
- * You may obtain a copy of the License at
1207
- *
1208
- * http://www.apache.org/licenses/LICENSE-2.0
1209
- *
1210
- * Unless required by applicable law or agreed to in writing, software
1211
- * distributed under the License is distributed on an "AS IS" BASIS,
1212
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1213
- * See the License for the specific language governing permissions and
1214
- * limitations under the License.
1215
- */
1216
1199
  /**
1217
1200
  * Schema Version for the Web client:
1218
1201
  * 1. Initial version including Mutation Queue, Query Cache, and Remote
@@ -1231,6 +1214,7 @@ function decodeResourcePath(path) {
1231
1214
  * an auto-incrementing ID. This is required for Index-Free queries.
1232
1215
  * 10. Rewrite the canonical IDs to the explicit Protobuf-based format.
1233
1216
  * 11. Add bundles and named_queries for bundle support.
1217
+ * 12. Add indexing support.
1234
1218
  */
1235
1219
  const SCHEMA_VERSION = 11;
1236
1220
  /**
@@ -1757,9 +1741,7 @@ class DbClientMetadata {
1757
1741
  DbClientMetadata.store = 'clientMetadata';
1758
1742
  /** Keys are automatically assigned via the clientId properties. */
1759
1743
  DbClientMetadata.keyPath = 'clientId';
1760
- /**
1761
- * A object representing a bundle loaded by the SDK.
1762
- */
1744
+ /** An object representing a bundle loaded by the SDK. */
1763
1745
  class DbBundle {
1764
1746
  constructor(
1765
1747
  /** The ID of the loaded bundle. */
@@ -1776,9 +1758,7 @@ class DbBundle {
1776
1758
  /** Name of the IndexedDb object store. */
1777
1759
  DbBundle.store = 'bundles';
1778
1760
  DbBundle.keyPath = 'bundleId';
1779
- /**
1780
- * A object representing a named query loaded by the SDK via a bundle.
1781
- */
1761
+ /** An object representing a named query loaded by the SDK via a bundle. */
1782
1762
  class DbNamedQuery {
1783
1763
  constructor(
1784
1764
  /** The name of the query. */
@@ -1795,6 +1775,93 @@ class DbNamedQuery {
1795
1775
  /** Name of the IndexedDb object store. */
1796
1776
  DbNamedQuery.store = 'namedQueries';
1797
1777
  DbNamedQuery.keyPath = 'name';
1778
+ /** An object representing the global configuration for a field index. */
1779
+ class DbIndexConfiguration {
1780
+ constructor(
1781
+ /** The index id for this entry. */
1782
+ indexId,
1783
+ /** The collection group this index belongs to. */
1784
+ collectionGroup,
1785
+ /** The fields to index for this index. */
1786
+ fields) {
1787
+ this.indexId = indexId;
1788
+ this.collectionGroup = collectionGroup;
1789
+ this.fields = fields;
1790
+ }
1791
+ }
1792
+ /** Name of the IndexedDb object store. */
1793
+ DbIndexConfiguration.store = 'indexConfiguration';
1794
+ DbIndexConfiguration.keyPath = 'indexId';
1795
+ /**
1796
+ * An object describing how up-to-date the index backfill is for each user and
1797
+ * index.
1798
+ */
1799
+ class DbIndexState {
1800
+ constructor(
1801
+ /** The index id for this entry. */
1802
+ indexId,
1803
+ /** The user id for this entry. */
1804
+ uid,
1805
+ /**
1806
+ * A number that indicates when the index was last updated (relative to
1807
+ * other indexes).
1808
+ */
1809
+ sequenceNumber,
1810
+ /**
1811
+ * The latest read time that has been indexed by Firestore for this field
1812
+ * index. Set to `{seconds: 0, nanos: 0}` if no documents have been indexed.
1813
+ */
1814
+ readTime,
1815
+ /**
1816
+ * The last document that has been indexed for this field index. Empty if
1817
+ * no documents have been indexed.
1818
+ */
1819
+ documentKey,
1820
+ /**
1821
+ * The largest mutation batch id that has been processed for this index. -1
1822
+ * if no mutations have been indexed.
1823
+ */
1824
+ largestBatchId) {
1825
+ this.indexId = indexId;
1826
+ this.uid = uid;
1827
+ this.sequenceNumber = sequenceNumber;
1828
+ this.readTime = readTime;
1829
+ this.documentKey = documentKey;
1830
+ this.largestBatchId = largestBatchId;
1831
+ }
1832
+ }
1833
+ /** Name of the IndexedDb object store. */
1834
+ DbIndexState.store = 'indexState';
1835
+ DbIndexState.keyPath = ['indexId', 'uid'];
1836
+ /** An object that stores the encoded entries for all documents and fields. */
1837
+ class DbIndexEntries {
1838
+ constructor(
1839
+ /** The index id for this entry. */
1840
+ indexId,
1841
+ /** The user id for this entry. */
1842
+ uid,
1843
+ /** The encoded array index value for this entry. */
1844
+ arrayValue,
1845
+ /** The encoded directional value for equality and inequality filters. */
1846
+ directionalValue,
1847
+ /** The document key this entry points to. */
1848
+ documentKey) {
1849
+ this.indexId = indexId;
1850
+ this.uid = uid;
1851
+ this.arrayValue = arrayValue;
1852
+ this.directionalValue = directionalValue;
1853
+ this.documentKey = documentKey;
1854
+ }
1855
+ }
1856
+ /** Name of the IndexedDb object store. */
1857
+ DbIndexEntries.store = 'indexEntries';
1858
+ DbIndexEntries.keyPath = [
1859
+ 'indexId',
1860
+ 'uid',
1861
+ 'arrayValue',
1862
+ 'directionalValue',
1863
+ 'documentKey'
1864
+ ];
1798
1865
  // Visible for testing
1799
1866
  const V1_STORES = [
1800
1867
  DbMutationQueue.store,
@@ -1809,7 +1876,6 @@ const V1_STORES = [
1809
1876
  // V2 is no longer usable (see comment at top of file)
1810
1877
  // Visible for testing
1811
1878
  const V3_STORES = V1_STORES;
1812
- // Visible for testing
1813
1879
  // Note: DbRemoteDocumentChanges is no longer used and dropped with v9.
1814
1880
  const V4_STORES = [...V3_STORES, DbClientMetadata.store];
1815
1881
  // V5 does not change the set of stores.
@@ -1819,6 +1885,12 @@ const V8_STORES = [...V6_STORES, DbCollectionParent.store];
1819
1885
  // V9 does not change the set of stores.
1820
1886
  // V10 does not change the set of stores.
1821
1887
  const V11_STORES = [...V8_STORES, DbBundle.store, DbNamedQuery.store];
1888
+ [
1889
+ ...V11_STORES,
1890
+ DbIndexConfiguration.store,
1891
+ DbIndexState.store,
1892
+ DbIndexEntries.store
1893
+ ];
1822
1894
  /**
1823
1895
  * The list of all default IndexedDB stores used throughout the SDK. This is
1824
1896
  * used when creating transactions so that access across all stores is done
@@ -3378,6 +3450,75 @@ function getLocalWriteTime(value) {
3378
3450
  return new Timestamp(localWriteTime.seconds, localWriteTime.nanos);
3379
3451
  }
3380
3452
 
3453
+ /**
3454
+ * @license
3455
+ * Copyright 2017 Google LLC
3456
+ *
3457
+ * Licensed under the Apache License, Version 2.0 (the "License");
3458
+ * you may not use this file except in compliance with the License.
3459
+ * You may obtain a copy of the License at
3460
+ *
3461
+ * http://www.apache.org/licenses/LICENSE-2.0
3462
+ *
3463
+ * Unless required by applicable law or agreed to in writing, software
3464
+ * distributed under the License is distributed on an "AS IS" BASIS,
3465
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3466
+ * See the License for the specific language governing permissions and
3467
+ * limitations under the License.
3468
+ */
3469
+ class DatabaseInfo {
3470
+ /**
3471
+ * Constructs a DatabaseInfo using the provided host, databaseId and
3472
+ * persistenceKey.
3473
+ *
3474
+ * @param databaseId - The database to use.
3475
+ * @param appId - The Firebase App Id.
3476
+ * @param persistenceKey - A unique identifier for this Firestore's local
3477
+ * storage (used in conjunction with the databaseId).
3478
+ * @param host - The Firestore backend host to connect to.
3479
+ * @param ssl - Whether to use SSL when connecting.
3480
+ * @param forceLongPolling - Whether to use the forceLongPolling option
3481
+ * when using WebChannel as the network transport.
3482
+ * @param autoDetectLongPolling - Whether to use the detectBufferingProxy
3483
+ * option when using WebChannel as the network transport.
3484
+ * @param useFetchStreams Whether to use the Fetch API instead of
3485
+ * XMLHTTPRequest
3486
+ */
3487
+ constructor(databaseId, appId, persistenceKey, host, ssl, forceLongPolling, autoDetectLongPolling, useFetchStreams) {
3488
+ this.databaseId = databaseId;
3489
+ this.appId = appId;
3490
+ this.persistenceKey = persistenceKey;
3491
+ this.host = host;
3492
+ this.ssl = ssl;
3493
+ this.forceLongPolling = forceLongPolling;
3494
+ this.autoDetectLongPolling = autoDetectLongPolling;
3495
+ this.useFetchStreams = useFetchStreams;
3496
+ }
3497
+ }
3498
+ /** The default database name for a project. */
3499
+ const DEFAULT_DATABASE_NAME = '(default)';
3500
+ /**
3501
+ * Represents the database ID a Firestore client is associated with.
3502
+ * @internal
3503
+ */
3504
+ class DatabaseId {
3505
+ constructor(projectId, database) {
3506
+ this.projectId = projectId;
3507
+ this.database = database ? database : DEFAULT_DATABASE_NAME;
3508
+ }
3509
+ static empty() {
3510
+ return new DatabaseId('', '');
3511
+ }
3512
+ get isDefaultDatabase() {
3513
+ return this.database === DEFAULT_DATABASE_NAME;
3514
+ }
3515
+ isEqual(other) {
3516
+ return (other instanceof DatabaseId &&
3517
+ other.projectId === this.projectId &&
3518
+ other.database === this.database);
3519
+ }
3520
+ }
3521
+
3381
3522
  /**
3382
3523
  * @license
3383
3524
  * Copyright 2017 Google LLC
@@ -3449,6 +3590,9 @@ class DocumentKey {
3449
3590
  static fromName(name) {
3450
3591
  return new DocumentKey(ResourcePath.fromString(name).popFirst(5));
3451
3592
  }
3593
+ static empty() {
3594
+ return new DocumentKey(ResourcePath.emptyPath());
3595
+ }
3452
3596
  /** Returns true if the document is in the specified collectionId. */
3453
3597
  hasCollectionId(collectionId) {
3454
3598
  return (this.path.length >= 2 &&
@@ -4097,10 +4241,11 @@ function extractFieldMask(value) {
4097
4241
  * from all views.
4098
4242
  */
4099
4243
  class MutableDocument {
4100
- constructor(key, documentType, version, data, documentState) {
4244
+ constructor(key, documentType, version, readTime, data, documentState) {
4101
4245
  this.key = key;
4102
4246
  this.documentType = documentType;
4103
4247
  this.version = version;
4248
+ this.readTime = readTime;
4104
4249
  this.data = data;
4105
4250
  this.documentState = documentState;
4106
4251
  }
@@ -4109,18 +4254,18 @@ class MutableDocument {
4109
4254
  * base document for mutations.
4110
4255
  */
4111
4256
  static newInvalidDocument(documentKey) {
4112
- return new MutableDocument(documentKey, 0 /* INVALID */, SnapshotVersion.min(), ObjectValue.empty(), 0 /* SYNCED */);
4257
+ return new MutableDocument(documentKey, 0 /* INVALID */, SnapshotVersion.min(), SnapshotVersion.min(), ObjectValue.empty(), 0 /* SYNCED */);
4113
4258
  }
4114
4259
  /**
4115
4260
  * Creates a new document that is known to exist with the given data at the
4116
4261
  * given version.
4117
4262
  */
4118
4263
  static newFoundDocument(documentKey, version, value) {
4119
- return new MutableDocument(documentKey, 1 /* FOUND_DOCUMENT */, version, value, 0 /* SYNCED */);
4264
+ return new MutableDocument(documentKey, 1 /* FOUND_DOCUMENT */, version, SnapshotVersion.min(), value, 0 /* SYNCED */);
4120
4265
  }
4121
4266
  /** Creates a new document that is known to not exist at the given version. */
4122
4267
  static newNoDocument(documentKey, version) {
4123
- return new MutableDocument(documentKey, 2 /* NO_DOCUMENT */, version, ObjectValue.empty(), 0 /* SYNCED */);
4268
+ return new MutableDocument(documentKey, 2 /* NO_DOCUMENT */, version, SnapshotVersion.min(), ObjectValue.empty(), 0 /* SYNCED */);
4124
4269
  }
4125
4270
  /**
4126
4271
  * Creates a new document that is known to exist at the given version but
@@ -4128,7 +4273,7 @@ class MutableDocument {
4128
4273
  * base document).
4129
4274
  */
4130
4275
  static newUnknownDocument(documentKey, version) {
4131
- return new MutableDocument(documentKey, 3 /* UNKNOWN_DOCUMENT */, version, ObjectValue.empty(), 2 /* HAS_COMMITTED_MUTATIONS */);
4276
+ return new MutableDocument(documentKey, 3 /* UNKNOWN_DOCUMENT */, version, SnapshotVersion.min(), ObjectValue.empty(), 2 /* HAS_COMMITTED_MUTATIONS */);
4132
4277
  }
4133
4278
  /**
4134
4279
  * Changes the document type to indicate that it exists and that its version
@@ -4172,6 +4317,10 @@ class MutableDocument {
4172
4317
  this.documentState = 1 /* HAS_LOCAL_MUTATIONS */;
4173
4318
  return this;
4174
4319
  }
4320
+ setReadTime(readTime) {
4321
+ this.readTime = readTime;
4322
+ return this;
4323
+ }
4175
4324
  get hasLocalMutations() {
4176
4325
  return this.documentState === 1 /* HAS_LOCAL_MUTATIONS */;
4177
4326
  }
@@ -4202,7 +4351,7 @@ class MutableDocument {
4202
4351
  this.data.isEqual(other.data));
4203
4352
  }
4204
4353
  mutableCopy() {
4205
- return new MutableDocument(this.key, this.documentType, this.version, this.data.clone(), this.documentState);
4354
+ return new MutableDocument(this.key, this.documentType, this.version, this.readTime, this.data.clone(), this.documentState);
4206
4355
  }
4207
4356
  toString() {
4208
4357
  return (`Document(${this.key}, ${this.version}, ${JSON.stringify(this.data.value)}, ` +
@@ -4225,6 +4374,125 @@ function compareDocumentsByField(field, d1, d2) {
4225
4374
  }
4226
4375
  }
4227
4376
 
4377
+ /**
4378
+ * @license
4379
+ * Copyright 2021 Google LLC
4380
+ *
4381
+ * Licensed under the Apache License, Version 2.0 (the "License");
4382
+ * you may not use this file except in compliance with the License.
4383
+ * You may obtain a copy of the License at
4384
+ *
4385
+ * http://www.apache.org/licenses/LICENSE-2.0
4386
+ *
4387
+ * Unless required by applicable law or agreed to in writing, software
4388
+ * distributed under the License is distributed on an "AS IS" BASIS,
4389
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
4390
+ * See the License for the specific language governing permissions and
4391
+ * limitations under the License.
4392
+ */
4393
+ /**
4394
+ * The initial mutation batch id for each index. Gets updated during index
4395
+ * backfill.
4396
+ */
4397
+ const INITIAL_LARGEST_BATCH_ID = -1;
4398
+ /**
4399
+ * The initial sequence number for each index. Gets updated during index
4400
+ * backfill.
4401
+ */
4402
+ const INITIAL_SEQUENCE_NUMBER = 0;
4403
+ /**
4404
+ * An index definition for field indexes in Firestore.
4405
+ *
4406
+ * Every index is associated with a collection. The definition contains a list
4407
+ * of fields and their index kind (which can be `ASCENDING`, `DESCENDING` or
4408
+ * `CONTAINS` for ArrayContains/ArrayContainsAny queries).
4409
+ *
4410
+ * Unlike the backend, the SDK does not differentiate between collection or
4411
+ * collection group-scoped indices. Every index can be used for both single
4412
+ * collection and collection group queries.
4413
+ */
4414
+ class FieldIndex {
4415
+ constructor(
4416
+ /**
4417
+ * The index ID. Returns -1 if the index ID is not available (e.g. the index
4418
+ * has not yet been persisted).
4419
+ */
4420
+ indexId,
4421
+ /** The collection ID this index applies to. */
4422
+ collectionGroup,
4423
+ /** The field segments for this index. */
4424
+ segments,
4425
+ /** Shows how up-to-date the index is for the current user. */
4426
+ indexState) {
4427
+ this.indexId = indexId;
4428
+ this.collectionGroup = collectionGroup;
4429
+ this.segments = segments;
4430
+ this.indexState = indexState;
4431
+ }
4432
+ }
4433
+ /** An ID for an index that has not yet been added to persistence. */
4434
+ FieldIndex.UNKNOWN_ID = -1;
4435
+ /** An index component consisting of field path and index type. */
4436
+ class IndexSegment {
4437
+ constructor(
4438
+ /** The field path of the component. */
4439
+ fieldPath,
4440
+ /** The fields sorting order. */
4441
+ kind) {
4442
+ this.fieldPath = fieldPath;
4443
+ this.kind = kind;
4444
+ }
4445
+ }
4446
+ /**
4447
+ * Stores the "high water mark" that indicates how updated the Index is for the
4448
+ * current user.
4449
+ */
4450
+ class IndexState {
4451
+ constructor(
4452
+ /**
4453
+ * Indicates when the index was last updated (relative to other indexes).
4454
+ */
4455
+ sequenceNumber,
4456
+ /** The the latest indexed read time, document and batch id. */
4457
+ offset) {
4458
+ this.sequenceNumber = sequenceNumber;
4459
+ this.offset = offset;
4460
+ }
4461
+ /** The state of an index that has not yet been backfilled. */
4462
+ static empty() {
4463
+ return new IndexState(INITIAL_SEQUENCE_NUMBER, IndexOffset.min());
4464
+ }
4465
+ }
4466
+ /**
4467
+ * Stores the latest read time, document and batch ID that were processed for an
4468
+ * index.
4469
+ */
4470
+ class IndexOffset {
4471
+ constructor(
4472
+ /**
4473
+ * The latest read time version that has been indexed by Firestore for this
4474
+ * field index.
4475
+ */
4476
+ readTime,
4477
+ /**
4478
+ * The key of the last document that was indexed for this query. Use
4479
+ * `DocumentKey.empty()` if no document has been indexed.
4480
+ */
4481
+ documentKey,
4482
+ /*
4483
+ * The largest mutation batch id that's been processed by Firestore.
4484
+ */
4485
+ largestBatchId) {
4486
+ this.readTime = readTime;
4487
+ this.documentKey = documentKey;
4488
+ this.largestBatchId = largestBatchId;
4489
+ }
4490
+ /** The state of an index that has not yet been backfilled. */
4491
+ static min() {
4492
+ return new IndexOffset(SnapshotVersion.min(), DocumentKey.empty(), INITIAL_LARGEST_BATCH_ID);
4493
+ }
4494
+ }
4495
+
4228
4496
  /**
4229
4497
  * @license
4230
4498
  * Copyright 2019 Google LLC
@@ -4349,7 +4617,7 @@ function targetEquals(left, right) {
4349
4617
  }
4350
4618
  return boundEquals(left.endAt, right.endAt);
4351
4619
  }
4352
- function isDocumentTarget(target) {
4620
+ function targetIsDocumentTarget(target) {
4353
4621
  return (DocumentKey.isDocumentKey(target.path) &&
4354
4622
  target.collectionGroup === null &&
4355
4623
  target.filters.length === 0);
@@ -4537,6 +4805,7 @@ class ArrayContainsAnyFilter extends FieldFilter {
4537
4805
  return other.arrayValue.values.some(val => arrayValueContains(this.value.arrayValue, val));
4538
4806
  }
4539
4807
  }
4808
+ // TODO(indexing): Change Bound.before to "inclusive"
4540
4809
  /**
4541
4810
  * Represents a bound of a query.
4542
4811
  *
@@ -6994,7 +7263,7 @@ class WatchChangeAggregator {
6994
7263
  const targetData = this.targetDataForActiveTarget(targetId);
6995
7264
  if (targetData) {
6996
7265
  const target = targetData.target;
6997
- if (isDocumentTarget(target)) {
7266
+ if (targetIsDocumentTarget(target)) {
6998
7267
  if (expectedCount === 0) {
6999
7268
  // The existence filter told us the document does not exist. We deduce
7000
7269
  // that this document does not exist and apply a deleted document to
@@ -7029,7 +7298,7 @@ class WatchChangeAggregator {
7029
7298
  this.targetStates.forEach((targetState, targetId) => {
7030
7299
  const targetData = this.targetDataForActiveTarget(targetId);
7031
7300
  if (targetData) {
7032
- if (targetState.current && isDocumentTarget(targetData.target)) {
7301
+ if (targetState.current && targetIsDocumentTarget(targetData.target)) {
7033
7302
  // Document queries for document that don't exist can produce an empty
7034
7303
  // result set. To update our local cache, we synthesize a document
7035
7304
  // delete if we have not previously received the document. This
@@ -7072,6 +7341,7 @@ class WatchChangeAggregator {
7072
7341
  resolvedLimboDocuments = resolvedLimboDocuments.add(key);
7073
7342
  }
7074
7343
  });
7344
+ this.pendingDocumentUpdates.forEach((_, doc) => doc.setReadTime(snapshotVersion));
7075
7345
  const remoteEvent = new RemoteEvent(snapshotVersion, targetChanges, this.pendingTargetResets, this.pendingDocumentUpdates, resolvedLimboDocuments);
7076
7346
  this.pendingDocumentUpdates = mutableDocumentMap();
7077
7347
  this.pendingDocumentTargetMapping = documentTargetMap();
@@ -7864,7 +8134,7 @@ function toLabel(serializer, purpose) {
7864
8134
  function toTarget(serializer, targetData) {
7865
8135
  let result;
7866
8136
  const target = targetData.target;
7867
- if (isDocumentTarget(target)) {
8137
+ if (targetIsDocumentTarget(target)) {
7868
8138
  result = { documents: toDocumentsTarget(serializer, target) };
7869
8139
  }
7870
8140
  else {
@@ -8192,29 +8462,34 @@ class LocalSerializer {
8192
8462
  }
8193
8463
  /** Decodes a remote document from storage locally to a Document. */
8194
8464
  function fromDbRemoteDocument(localSerializer, remoteDoc) {
8465
+ let doc;
8195
8466
  if (remoteDoc.document) {
8196
- return fromDocument(localSerializer.remoteSerializer, remoteDoc.document, !!remoteDoc.hasCommittedMutations);
8467
+ doc = fromDocument(localSerializer.remoteSerializer, remoteDoc.document, !!remoteDoc.hasCommittedMutations);
8197
8468
  }
8198
8469
  else if (remoteDoc.noDocument) {
8199
8470
  const key = DocumentKey.fromSegments(remoteDoc.noDocument.path);
8200
8471
  const version = fromDbTimestamp(remoteDoc.noDocument.readTime);
8201
- const document = MutableDocument.newNoDocument(key, version);
8202
- return remoteDoc.hasCommittedMutations
8203
- ? document.setHasCommittedMutations()
8204
- : document;
8472
+ doc = MutableDocument.newNoDocument(key, version);
8473
+ if (remoteDoc.hasCommittedMutations) {
8474
+ doc.setHasCommittedMutations();
8475
+ }
8205
8476
  }
8206
8477
  else if (remoteDoc.unknownDocument) {
8207
8478
  const key = DocumentKey.fromSegments(remoteDoc.unknownDocument.path);
8208
8479
  const version = fromDbTimestamp(remoteDoc.unknownDocument.version);
8209
- return MutableDocument.newUnknownDocument(key, version);
8480
+ doc = MutableDocument.newUnknownDocument(key, version);
8210
8481
  }
8211
8482
  else {
8212
8483
  return fail();
8213
8484
  }
8485
+ if (remoteDoc.readTime) {
8486
+ doc.setReadTime(fromDbTimestampKey(remoteDoc.readTime));
8487
+ }
8488
+ return doc;
8214
8489
  }
8215
8490
  /** Encodes a document for storage locally. */
8216
- function toDbRemoteDocument(localSerializer, document, readTime) {
8217
- const dbReadTime = toDbTimestampKey(readTime);
8491
+ function toDbRemoteDocument(localSerializer, document) {
8492
+ const dbReadTime = toDbTimestampKey(document.readTime);
8218
8493
  const parentPath = document.key.path.popLast().toArray();
8219
8494
  if (document.isFoundDocument()) {
8220
8495
  const doc = toDocument(localSerializer.remoteSerializer, document);
@@ -8225,10 +8500,10 @@ function toDbRemoteDocument(localSerializer, document, readTime) {
8225
8500
  }
8226
8501
  else if (document.isNoDocument()) {
8227
8502
  const path = document.key.path.toArray();
8228
- const readTime = toDbTimestamp(document.version);
8503
+ const version = toDbTimestamp(document.version);
8229
8504
  const hasCommittedMutations = document.hasCommittedMutations;
8230
8505
  return new DbRemoteDocument(
8231
- /* unknownDocument= */ null, new DbNoDocument(path, readTime),
8506
+ /* unknownDocument= */ null, new DbNoDocument(path, version),
8232
8507
  /* document= */ null, hasCommittedMutations, dbReadTime, parentPath);
8233
8508
  }
8234
8509
  else if (document.isUnknownDocument()) {
@@ -8309,7 +8584,7 @@ function toDbTarget(localSerializer, targetData) {
8309
8584
  const dbTimestamp = toDbTimestamp(targetData.snapshotVersion);
8310
8585
  const dbLastLimboFreeTimestamp = toDbTimestamp(targetData.lastLimboFreeSnapshotVersion);
8311
8586
  let queryProto;
8312
- if (isDocumentTarget(targetData.target)) {
8587
+ if (targetIsDocumentTarget(targetData.target)) {
8313
8588
  queryProto = toDocumentsTarget(localSerializer.remoteSerializer, targetData.target);
8314
8589
  }
8315
8590
  else {
@@ -9757,7 +10032,7 @@ class IndexedDbLruDelegateImpl {
9757
10032
  // Our size accounting requires us to read all documents before
9758
10033
  // removing them.
9759
10034
  return changeBuffer.getEntry(txn, docKey).next(() => {
9760
- changeBuffer.removeEntry(docKey);
10035
+ changeBuffer.removeEntry(docKey, SnapshotVersion.min());
9761
10036
  return documentTargetStore(txn).delete(sentinelKey$1(docKey));
9762
10037
  });
9763
10038
  }
@@ -9970,27 +10245,19 @@ class ObjectMap {
9970
10245
  */
9971
10246
  class RemoteDocumentChangeBuffer {
9972
10247
  constructor() {
9973
- // A mapping of document key to the new cache entry that should be written (or null if any
9974
- // existing cache entry should be removed).
10248
+ // A mapping of document key to the new cache entry that should be written.
9975
10249
  this.changes = new ObjectMap(key => key.toString(), (l, r) => l.isEqual(r));
9976
10250
  this.changesApplied = false;
9977
10251
  }
9978
- getReadTime(key) {
9979
- const change = this.changes.get(key);
9980
- if (change) {
9981
- return change.readTime;
9982
- }
9983
- return SnapshotVersion.min();
9984
- }
9985
10252
  /**
9986
10253
  * Buffers a `RemoteDocumentCache.addEntry()` call.
9987
10254
  *
9988
10255
  * You can only modify documents that have already been retrieved via
9989
10256
  * `getEntry()/getEntries()` (enforced via IndexedDbs `apply()`).
9990
10257
  */
9991
- addEntry(document, readTime) {
10258
+ addEntry(document) {
9992
10259
  this.assertNotApplied();
9993
- this.changes.set(document.key, { document, readTime });
10260
+ this.changes.set(document.key, document);
9994
10261
  }
9995
10262
  /**
9996
10263
  * Buffers a `RemoteDocumentCache.removeEntry()` call.
@@ -9998,12 +10265,9 @@ class RemoteDocumentChangeBuffer {
9998
10265
  * You can only remove documents that have already been retrieved via
9999
10266
  * `getEntry()/getEntries()` (enforced via IndexedDbs `apply()`).
10000
10267
  */
10001
- removeEntry(key, readTime = null) {
10268
+ removeEntry(key, readTime) {
10002
10269
  this.assertNotApplied();
10003
- this.changes.set(key, {
10004
- document: MutableDocument.newInvalidDocument(key),
10005
- readTime
10006
- });
10270
+ this.changes.set(key, MutableDocument.newInvalidDocument(key).setReadTime(readTime));
10007
10271
  }
10008
10272
  /**
10009
10273
  * Looks up an entry in the cache. The buffered changes will first be checked,
@@ -10020,7 +10284,7 @@ class RemoteDocumentChangeBuffer {
10020
10284
  this.assertNotApplied();
10021
10285
  const bufferedEntry = this.changes.get(documentKey);
10022
10286
  if (bufferedEntry !== undefined) {
10023
- return PersistencePromise.resolve(bufferedEntry.document);
10287
+ return PersistencePromise.resolve(bufferedEntry);
10024
10288
  }
10025
10289
  else {
10026
10290
  return this.getFromCache(transaction, documentKey);
@@ -10231,7 +10495,7 @@ class IndexedDbRemoteDocumentCacheImpl {
10231
10495
  if (key.length !== immediateChildrenPathLength) {
10232
10496
  return;
10233
10497
  }
10234
- const document = fromDbRemoteDocument(this.serializer, dbRemoteDoc);
10498
+ const document = this.maybeDecodeDocument(DocumentKey.fromSegments(key), dbRemoteDoc);
10235
10499
  if (!query.path.isPrefixOf(document.key.path)) {
10236
10500
  control.done();
10237
10501
  }
@@ -10259,8 +10523,8 @@ class IndexedDbRemoteDocumentCacheImpl {
10259
10523
  return documentGlobalStore(txn).put(DbRemoteDocumentGlobal.key, metadata);
10260
10524
  }
10261
10525
  /**
10262
- * Decodes `remoteDoc` and returns the document (or null, if the document
10263
- * corresponds to the format used for sentinel deletes).
10526
+ * Decodes `dbRemoteDoc` and returns the document (or an invalid document if
10527
+ * the document corresponds to the format used for sentinel deletes).
10264
10528
  */
10265
10529
  maybeDecodeDocument(documentKey, dbRemoteDoc) {
10266
10530
  if (dbRemoteDoc) {
@@ -10354,8 +10618,8 @@ class IndexedDbRemoteDocumentChangeBuffer extends RemoteDocumentChangeBuffer {
10354
10618
  let collectionParents = new SortedSet((l, r) => primitiveComparator(l.canonicalString(), r.canonicalString()));
10355
10619
  this.changes.forEach((key, documentChange) => {
10356
10620
  const previousSize = this.documentSizes.get(key);
10357
- if (documentChange.document.isValidDocument()) {
10358
- const doc = toDbRemoteDocument(this.documentCache.serializer, documentChange.document, this.getReadTime(key));
10621
+ if (documentChange.isValidDocument()) {
10622
+ const doc = toDbRemoteDocument(this.documentCache.serializer, documentChange);
10359
10623
  collectionParents = collectionParents.add(key.path.popLast());
10360
10624
  const size = dbDocumentSize(doc);
10361
10625
  sizeDelta += size - previousSize;
@@ -10368,7 +10632,7 @@ class IndexedDbRemoteDocumentChangeBuffer extends RemoteDocumentChangeBuffer {
10368
10632
  // RemoteDocumentCache. This entry is represented by a NoDocument
10369
10633
  // with a version of 0 and ignored by `maybeDecodeDocument()` but
10370
10634
  // preserved in `getNewDocumentChanges()`.
10371
- const deletedDoc = toDbRemoteDocument(this.documentCache.serializer, MutableDocument.newNoDocument(key, SnapshotVersion.min()), this.getReadTime(key));
10635
+ const deletedDoc = toDbRemoteDocument(this.documentCache.serializer, documentChange.convertToNoDocument(SnapshotVersion.min()));
10372
10636
  promises.push(this.documentCache.addEntry(transaction, key, deletedDoc));
10373
10637
  }
10374
10638
  else {
@@ -10449,9 +10713,6 @@ class SchemaConverter {
10449
10713
  * and local feature development.
10450
10714
  */
10451
10715
  createOrUpgrade(db, txn, fromVersion, toVersion) {
10452
- hardAssert(fromVersion < toVersion &&
10453
- fromVersion >= 0 &&
10454
- toVersion <= SCHEMA_VERSION);
10455
10716
  const simpleDbTransaction = new SimpleDbTransaction('createOrUpgrade', txn);
10456
10717
  if (fromVersion < 1 && toVersion >= 1) {
10457
10718
  createPrimaryClientStore(db);
@@ -10518,6 +10779,11 @@ class SchemaConverter {
10518
10779
  createNamedQueriesStore(db);
10519
10780
  });
10520
10781
  }
10782
+ if (fromVersion < 12 && toVersion >= 12) {
10783
+ p = p.next(() => {
10784
+ createFieldIndex(db);
10785
+ });
10786
+ }
10521
10787
  return p;
10522
10788
  }
10523
10789
  addDocumentGlobal(txn) {
@@ -10724,6 +10990,17 @@ function createNamedQueriesStore(db) {
10724
10990
  db.createObjectStore(DbNamedQuery.store, {
10725
10991
  keyPath: DbNamedQuery.keyPath
10726
10992
  });
10993
+ }
10994
+ function createFieldIndex(db) {
10995
+ db.createObjectStore(DbIndexConfiguration.store, {
10996
+ keyPath: DbIndexConfiguration.keyPath
10997
+ });
10998
+ db.createObjectStore(DbIndexState.store, {
10999
+ keyPath: DbIndexState.keyPath
11000
+ });
11001
+ db.createObjectStore(DbIndexEntries.store, {
11002
+ keyPath: DbIndexEntries.keyPath
11003
+ });
10727
11004
  }
10728
11005
 
10729
11006
  /**
@@ -11955,14 +12232,14 @@ function localStoreApplyRemoteEventToLocalCache(localStore, remoteEvent) {
11955
12232
  }
11956
12233
  });
11957
12234
  let changedDocs = mutableDocumentMap();
11958
- remoteEvent.documentUpdates.forEach((key, doc) => {
12235
+ remoteEvent.documentUpdates.forEach(key => {
11959
12236
  if (remoteEvent.resolvedLimboDocuments.has(key)) {
11960
12237
  promises.push(localStoreImpl.persistence.referenceDelegate.updateLimboDocument(txn, key));
11961
12238
  }
11962
12239
  });
11963
12240
  // Each loop iteration only affects its "own" doc, so it's safe to get all the remote
11964
12241
  // documents in advance in a single call.
11965
- promises.push(populateDocumentChangeBuffer(txn, documentBuffer, remoteEvent.documentUpdates, remoteVersion, undefined).next(result => {
12242
+ promises.push(populateDocumentChangeBuffer(txn, documentBuffer, remoteEvent.documentUpdates).next(result => {
11966
12243
  changedDocs = result;
11967
12244
  }));
11968
12245
  // HACK: The only reason we allow a null snapshot version is so that we
@@ -12003,17 +12280,13 @@ function localStoreApplyRemoteEventToLocalCache(localStore, remoteEvent) {
12003
12280
  * Note: this function will use `documentVersions` if it is defined;
12004
12281
  * when it is not defined, resorts to `globalVersion`.
12005
12282
  */
12006
- function populateDocumentChangeBuffer(txn, documentBuffer, documents, globalVersion,
12007
- // TODO(wuandy): We could add `readTime` to MaybeDocument instead to remove
12008
- // this parameter.
12009
- documentVersions) {
12283
+ function populateDocumentChangeBuffer(txn, documentBuffer, documents) {
12010
12284
  let updatedKeys = documentKeySet();
12011
12285
  documents.forEach(k => (updatedKeys = updatedKeys.add(k)));
12012
12286
  return documentBuffer.getEntries(txn, updatedKeys).next(existingDocs => {
12013
12287
  let changedDocs = mutableDocumentMap();
12014
12288
  documents.forEach((key, doc) => {
12015
12289
  const existingDoc = existingDocs.get(key);
12016
- const docReadTime = (documentVersions === null || documentVersions === void 0 ? void 0 : documentVersions.get(key)) || globalVersion;
12017
12290
  // Note: The order of the steps below is important, since we want
12018
12291
  // to ensure that rejected limbo resolutions (which fabricate
12019
12292
  // NoDocuments with SnapshotVersion.min()) never add documents to
@@ -12022,14 +12295,14 @@ documentVersions) {
12022
12295
  // NoDocuments with SnapshotVersion.min() are used in manufactured
12023
12296
  // events. We remove these documents from cache since we lost
12024
12297
  // access.
12025
- documentBuffer.removeEntry(key, docReadTime);
12298
+ documentBuffer.removeEntry(key, doc.readTime);
12026
12299
  changedDocs = changedDocs.insert(key, doc);
12027
12300
  }
12028
12301
  else if (!existingDoc.isValidDocument() ||
12029
12302
  doc.version.compareTo(existingDoc.version) > 0 ||
12030
12303
  (doc.version.compareTo(existingDoc.version) === 0 &&
12031
12304
  existingDoc.hasPendingWrites)) {
12032
- documentBuffer.addEntry(doc, docReadTime);
12305
+ documentBuffer.addEntry(doc);
12033
12306
  changedDocs = changedDocs.insert(key, doc);
12034
12307
  }
12035
12308
  else {
@@ -12283,7 +12556,8 @@ function applyWriteToRemoteDocuments(localStoreImpl, txn, batchResult, documentB
12283
12556
  // We use the commitVersion as the readTime rather than the
12284
12557
  // document's updateTime since the updateTime is not advanced
12285
12558
  // for updates that do not modify the underlying document.
12286
- documentBuffer.addEntry(doc, batchResult.commitVersion);
12559
+ doc.setReadTime(batchResult.commitVersion);
12560
+ documentBuffer.addEntry(doc);
12287
12561
  }
12288
12562
  }
12289
12563
  });
@@ -12384,14 +12658,14 @@ async function localStoreApplyBundledDocuments(localStore, bundleConverter, docu
12384
12658
  const localStoreImpl = debugCast(localStore);
12385
12659
  let documentKeys = documentKeySet();
12386
12660
  let documentMap = mutableDocumentMap();
12387
- let versionMap = documentVersionMap();
12388
12661
  for (const bundleDoc of documents) {
12389
12662
  const documentKey = bundleConverter.toDocumentKey(bundleDoc.metadata.name);
12390
12663
  if (bundleDoc.document) {
12391
12664
  documentKeys = documentKeys.add(documentKey);
12392
12665
  }
12393
- documentMap = documentMap.insert(documentKey, bundleConverter.toMutableDocument(bundleDoc));
12394
- versionMap = versionMap.insert(documentKey, bundleConverter.toSnapshotVersion(bundleDoc.metadata.readTime));
12666
+ const doc = bundleConverter.toMutableDocument(bundleDoc);
12667
+ doc.setReadTime(bundleConverter.toSnapshotVersion(bundleDoc.metadata.readTime));
12668
+ documentMap = documentMap.insert(documentKey, doc);
12395
12669
  }
12396
12670
  const documentBuffer = localStoreImpl.remoteDocuments.newChangeBuffer({
12397
12671
  trackRemovals: true // Make sure document removals show up in `getNewDocumentChanges()`
@@ -12400,7 +12674,7 @@ async function localStoreApplyBundledDocuments(localStore, bundleConverter, docu
12400
12674
  // they will not get garbage collected right away.
12401
12675
  const umbrellaTargetData = await localStoreAllocateTarget(localStoreImpl, umbrellaTarget(bundleName));
12402
12676
  return localStoreImpl.persistence.runTransaction('Apply bundle documents', 'readwrite', txn => {
12403
- return populateDocumentChangeBuffer(txn, documentBuffer, documentMap, SnapshotVersion.min(), versionMap)
12677
+ return populateDocumentChangeBuffer(txn, documentBuffer, documentMap)
12404
12678
  .next(changedDocs => {
12405
12679
  documentBuffer.apply(txn);
12406
12680
  return changedDocs;
@@ -12881,15 +13155,14 @@ class MemoryRemoteDocumentCacheImpl {
12881
13155
  * All calls of `addEntry` are required to go through the RemoteDocumentChangeBuffer
12882
13156
  * returned by `newChangeBuffer()`.
12883
13157
  */
12884
- addEntry(transaction, doc, readTime) {
13158
+ addEntry(transaction, doc) {
12885
13159
  const key = doc.key;
12886
13160
  const entry = this.docs.get(key);
12887
13161
  const previousSize = entry ? entry.size : 0;
12888
13162
  const currentSize = this.sizer(doc);
12889
13163
  this.docs = this.docs.insert(key, {
12890
13164
  document: doc.mutableCopy(),
12891
- size: currentSize,
12892
- readTime
13165
+ size: currentSize
12893
13166
  });
12894
13167
  this.size += currentSize - previousSize;
12895
13168
  return this.indexManager.addToCollectionParentIndex(transaction, key.path.popLast());
@@ -12930,11 +13203,11 @@ class MemoryRemoteDocumentCacheImpl {
12930
13203
  const prefix = new DocumentKey(query.path.child(''));
12931
13204
  const iterator = this.docs.getIteratorFrom(prefix);
12932
13205
  while (iterator.hasNext()) {
12933
- const { key, value: { document, readTime } } = iterator.getNext();
13206
+ const { key, value: { document } } = iterator.getNext();
12934
13207
  if (!query.path.isPrefixOf(key.path)) {
12935
13208
  break;
12936
13209
  }
12937
- if (readTime.compareTo(sinceReadTime) <= 0) {
13210
+ if (document.readTime.compareTo(sinceReadTime) <= 0) {
12938
13211
  continue;
12939
13212
  }
12940
13213
  if (!queryMatches(query, document)) {
@@ -12978,8 +13251,8 @@ class MemoryRemoteDocumentChangeBuffer extends RemoteDocumentChangeBuffer {
12978
13251
  applyChanges(transaction) {
12979
13252
  const promises = [];
12980
13253
  this.changes.forEach((key, doc) => {
12981
- if (doc.document.isValidDocument()) {
12982
- promises.push(this.documentCache.addEntry(transaction, doc.document, this.getReadTime(key)));
13254
+ if (doc.isValidDocument()) {
13255
+ promises.push(this.documentCache.addEntry(transaction, doc));
12983
13256
  }
12984
13257
  else {
12985
13258
  this.documentCache.removeEntry(key);
@@ -13292,7 +13565,7 @@ class MemoryEagerDelegate {
13292
13565
  const key = DocumentKey.fromPath(path);
13293
13566
  return this.isReferenced(txn, key).next(isReferenced => {
13294
13567
  if (!isReferenced) {
13295
- changeBuffer.removeEntry(key);
13568
+ changeBuffer.removeEntry(key, SnapshotVersion.min());
13296
13569
  }
13297
13570
  });
13298
13571
  }).next(() => {
@@ -17072,6 +17345,40 @@ const nested = {
17072
17345
  id: 2
17073
17346
  }
17074
17347
  }
17348
+ },
17349
+ methodSignature: {
17350
+ rule: "repeated",
17351
+ type: "string",
17352
+ id: 1051,
17353
+ extend: "google.protobuf.MethodOptions"
17354
+ },
17355
+ defaultHost: {
17356
+ type: "string",
17357
+ id: 1049,
17358
+ extend: "google.protobuf.ServiceOptions"
17359
+ },
17360
+ oauthScopes: {
17361
+ type: "string",
17362
+ id: 1050,
17363
+ extend: "google.protobuf.ServiceOptions"
17364
+ },
17365
+ fieldBehavior: {
17366
+ rule: "repeated",
17367
+ type: "google.api.FieldBehavior",
17368
+ id: 1052,
17369
+ extend: "google.protobuf.FieldOptions"
17370
+ },
17371
+ FieldBehavior: {
17372
+ values: {
17373
+ FIELD_BEHAVIOR_UNSPECIFIED: 0,
17374
+ OPTIONAL: 1,
17375
+ REQUIRED: 2,
17376
+ OUTPUT_ONLY: 3,
17377
+ INPUT_ONLY: 4,
17378
+ IMMUTABLE: 5,
17379
+ UNORDERED_LIST: 6,
17380
+ NON_EMPTY_DEFAULT: 7
17381
+ }
17075
17382
  }
17076
17383
  }
17077
17384
  },
@@ -20315,6 +20622,9 @@ async function syncEngineRejectListen(syncEngine, targetId, err) {
20315
20622
  // store to purge a document. However, it would be tricky to keep all of
20316
20623
  // the local store's invariants with another method.
20317
20624
  let documentUpdates = new SortedMap(DocumentKey.comparator);
20625
+ // TODO(b/217189216): This limbo document should ideally have a read time,
20626
+ // so that it is picked up by any read-time based scans. The backend,
20627
+ // however, does not send a read time for target removals.
20318
20628
  documentUpdates = documentUpdates.insert(limboKey, MutableDocument.newNoDocument(limboKey, SnapshotVersion.min()));
20319
20629
  const resolvedLimboDocuments = documentKeySet().add(limboKey);
20320
20630
  const event = new RemoteEvent(SnapshotVersion.min(),
@@ -22259,72 +22569,6 @@ function createBundleReader(data, serializer) {
22259
22569
  return newBundleReader(toByteStreamReader(content), serializer);
22260
22570
  }
22261
22571
 
22262
- /**
22263
- * @license
22264
- * Copyright 2017 Google LLC
22265
- *
22266
- * Licensed under the Apache License, Version 2.0 (the "License");
22267
- * you may not use this file except in compliance with the License.
22268
- * You may obtain a copy of the License at
22269
- *
22270
- * http://www.apache.org/licenses/LICENSE-2.0
22271
- *
22272
- * Unless required by applicable law or agreed to in writing, software
22273
- * distributed under the License is distributed on an "AS IS" BASIS,
22274
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22275
- * See the License for the specific language governing permissions and
22276
- * limitations under the License.
22277
- */
22278
- class DatabaseInfo {
22279
- /**
22280
- * Constructs a DatabaseInfo using the provided host, databaseId and
22281
- * persistenceKey.
22282
- *
22283
- * @param databaseId - The database to use.
22284
- * @param appId - The Firebase App Id.
22285
- * @param persistenceKey - A unique identifier for this Firestore's local
22286
- * storage (used in conjunction with the databaseId).
22287
- * @param host - The Firestore backend host to connect to.
22288
- * @param ssl - Whether to use SSL when connecting.
22289
- * @param forceLongPolling - Whether to use the forceLongPolling option
22290
- * when using WebChannel as the network transport.
22291
- * @param autoDetectLongPolling - Whether to use the detectBufferingProxy
22292
- * option when using WebChannel as the network transport.
22293
- * @param useFetchStreams Whether to use the Fetch API instead of
22294
- * XMLHTTPRequest
22295
- */
22296
- constructor(databaseId, appId, persistenceKey, host, ssl, forceLongPolling, autoDetectLongPolling, useFetchStreams) {
22297
- this.databaseId = databaseId;
22298
- this.appId = appId;
22299
- this.persistenceKey = persistenceKey;
22300
- this.host = host;
22301
- this.ssl = ssl;
22302
- this.forceLongPolling = forceLongPolling;
22303
- this.autoDetectLongPolling = autoDetectLongPolling;
22304
- this.useFetchStreams = useFetchStreams;
22305
- }
22306
- }
22307
- /** The default database name for a project. */
22308
- const DEFAULT_DATABASE_NAME = '(default)';
22309
- /**
22310
- * Represents the database ID a Firestore client is associated with.
22311
- * @internal
22312
- */
22313
- class DatabaseId {
22314
- constructor(projectId, database) {
22315
- this.projectId = projectId;
22316
- this.database = database ? database : DEFAULT_DATABASE_NAME;
22317
- }
22318
- get isDefaultDatabase() {
22319
- return this.database === DEFAULT_DATABASE_NAME;
22320
- }
22321
- isEqual(other) {
22322
- return (other instanceof DatabaseId &&
22323
- other.projectId === this.projectId &&
22324
- other.database === this.database);
22325
- }
22326
- }
22327
-
22328
22572
  /**
22329
22573
  * @license
22330
22574
  * Copyright 2020 Google LLC
@@ -26238,17 +26482,6 @@ function writeBatch(firestore) {
26238
26482
  ensureFirestoreConfigured(firestore);
26239
26483
  return new WriteBatch(firestore, mutations => executeWrite(firestore, mutations));
26240
26484
  }
26241
- /** An index component consisting of field path and index type. */
26242
- class Segment {
26243
- constructor(
26244
- /** The field path of the component. */
26245
- fieldPath,
26246
- /** The fields sorting order. */
26247
- kind) {
26248
- this.fieldPath = fieldPath;
26249
- this.kind = kind;
26250
- }
26251
- }
26252
26485
 
26253
26486
  /**
26254
26487
  * @license
@@ -26272,27 +26505,29 @@ function setIndexConfiguration(firestore, jsonOrConfiguration) {
26272
26505
  const indexConfiguration = typeof jsonOrConfiguration === 'string'
26273
26506
  ? tryParseJson(jsonOrConfiguration)
26274
26507
  : jsonOrConfiguration;
26508
+ const parsedIndexes = [];
26275
26509
  // PORTING NOTE: We don't return an error if the user has not enabled
26276
26510
  // persistence since `enableIndexeddbPersistence()` can fail on the Web.
26277
26511
  if (Array.isArray(indexConfiguration.indexes)) {
26278
26512
  for (const index of indexConfiguration.indexes) {
26279
- tryGetString(index, 'collectionGroup');
26513
+ const collectionGroup = tryGetString(index, 'collectionGroup');
26280
26514
  const segments = [];
26281
26515
  if (Array.isArray(index.fields)) {
26282
26516
  for (const field of index.fields) {
26283
26517
  const fieldPathString = tryGetString(field, 'fieldPath');
26284
26518
  const fieldPath = fieldPathFromDotSeparatedString('setIndexConfiguration', fieldPathString);
26285
26519
  if (field.arrayConfig === 'CONTAINS') {
26286
- segments.push(new Segment(fieldPath, 2 /* CONTAINS */));
26520
+ segments.push(new IndexSegment(fieldPath, 2 /* CONTAINS */));
26287
26521
  }
26288
26522
  else if (field.order === 'ASCENDING') {
26289
- segments.push(new Segment(fieldPath, 0 /* ASCENDING */));
26523
+ segments.push(new IndexSegment(fieldPath, 0 /* ASCENDING */));
26290
26524
  }
26291
26525
  else if (field.order === 'DESCENDING') {
26292
- segments.push(new Segment(fieldPath, 1 /* DESCENDING */));
26526
+ segments.push(new IndexSegment(fieldPath, 1 /* DESCENDING */));
26293
26527
  }
26294
26528
  }
26295
26529
  }
26530
+ parsedIndexes.push(new FieldIndex(FieldIndex.UNKNOWN_ID, collectionGroup, segments, IndexState.empty()));
26296
26531
  }
26297
26532
  }
26298
26533
  // TODO(indexing): Configure indexes