@firebase/firestore 3.4.3 → 3.4.4-canary.aaeab08ac

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 (81) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/firestore/src/api/database.d.ts +14 -9
  3. package/dist/firestore/src/api/index_configuration.d.ts +117 -0
  4. package/dist/firestore/src/api.d.ts +1 -0
  5. package/dist/firestore/src/core/firestore_client.d.ts +2 -0
  6. package/dist/firestore/src/local/local_serializer.d.ts +1 -1
  7. package/dist/firestore/src/local/remote_document_change_buffer.d.ts +3 -12
  8. package/dist/firestore/src/model/document.d.ts +7 -0
  9. package/dist/firestore/src/model/document_key.d.ts +1 -0
  10. package/dist/firestore/src/model/field_index.d.ts +152 -0
  11. package/dist/firestore/test/integration/api/index_configuration.test.d.ts +17 -0
  12. package/dist/firestore/test/unit/local/test_remote_document_cache.d.ts +1 -1
  13. package/dist/firestore/test/unit/model/field_index.test.d.ts +17 -0
  14. package/dist/firestore/test/util/helpers.d.ts +6 -0
  15. package/dist/index.d.ts +15 -9
  16. package/dist/index.esm2017.js +1204 -1052
  17. package/dist/index.esm2017.js.map +1 -1
  18. package/dist/index.esm5.js +1862 -1720
  19. package/dist/index.esm5.js.map +1 -1
  20. package/dist/index.node.cjs.js +308 -75
  21. package/dist/index.node.cjs.js.map +1 -1
  22. package/dist/index.node.mjs +308 -76
  23. package/dist/index.node.mjs.map +1 -1
  24. package/dist/index.rn.js +1204 -1052
  25. package/dist/index.rn.js.map +1 -1
  26. package/dist/internal.d.ts +131 -21
  27. package/dist/lite/firestore/src/api/database.d.ts +14 -9
  28. package/dist/lite/firestore/src/api/index_configuration.d.ts +117 -0
  29. package/dist/lite/firestore/src/api.d.ts +1 -0
  30. package/dist/lite/firestore/src/core/firestore_client.d.ts +2 -0
  31. package/dist/lite/firestore/src/local/local_serializer.d.ts +1 -1
  32. package/dist/lite/firestore/src/local/remote_document_change_buffer.d.ts +3 -12
  33. package/dist/lite/firestore/src/model/document.d.ts +7 -0
  34. package/dist/lite/firestore/src/model/document_key.d.ts +1 -0
  35. package/dist/lite/firestore/src/model/field_index.d.ts +152 -0
  36. package/dist/lite/firestore/test/integration/api/index_configuration.test.d.ts +17 -0
  37. package/dist/lite/firestore/test/unit/local/test_remote_document_cache.d.ts +1 -1
  38. package/dist/lite/firestore/test/unit/model/field_index.test.d.ts +17 -0
  39. package/dist/lite/firestore/test/util/helpers.d.ts +6 -0
  40. package/dist/lite/index.browser.esm2017.js +76 -69
  41. package/dist/lite/index.browser.esm2017.js.map +1 -1
  42. package/dist/lite/index.browser.esm5.js +52 -47
  43. package/dist/lite/index.browser.esm5.js.map +1 -1
  44. package/dist/lite/index.node.cjs.js +16 -8
  45. package/dist/lite/index.node.cjs.js.map +1 -1
  46. package/dist/lite/index.node.mjs +16 -8
  47. package/dist/lite/index.node.mjs.map +1 -1
  48. package/dist/lite/index.rn.esm2017.js +95 -88
  49. package/dist/lite/index.rn.esm2017.js.map +1 -1
  50. package/dist/lite/internal.d.ts +8 -0
  51. package/dist/lite/packages/firestore/dist/lite/index.browser.esm2017.d.ts +19 -19
  52. package/dist/lite/packages/firestore/src/api/database.d.ts +14 -9
  53. package/dist/lite/packages/firestore/src/api/index_configuration.d.ts +117 -0
  54. package/dist/lite/packages/firestore/src/api.d.ts +1 -0
  55. package/dist/lite/packages/firestore/src/core/firestore_client.d.ts +2 -0
  56. package/dist/lite/packages/firestore/src/local/local_serializer.d.ts +1 -1
  57. package/dist/lite/packages/firestore/src/local/remote_document_change_buffer.d.ts +3 -12
  58. package/dist/lite/packages/firestore/src/model/document.d.ts +7 -0
  59. package/dist/lite/packages/firestore/src/model/document_key.d.ts +1 -0
  60. package/dist/lite/packages/firestore/src/model/field_index.d.ts +152 -0
  61. package/dist/lite/packages/firestore/test/integration/api/index_configuration.test.d.ts +17 -0
  62. package/dist/lite/packages/firestore/test/unit/local/test_remote_document_cache.d.ts +1 -1
  63. package/dist/lite/packages/firestore/test/unit/model/field_index.test.d.ts +17 -0
  64. package/dist/lite/packages/firestore/test/util/helpers.d.ts +6 -0
  65. package/dist/lite/private.d.ts +7 -0
  66. package/dist/packages/firestore/dist/index.esm2017.d.ts +34 -12
  67. package/dist/packages/firestore/src/api/database.d.ts +14 -9
  68. package/dist/packages/firestore/src/api/index_configuration.d.ts +117 -0
  69. package/dist/packages/firestore/src/api.d.ts +1 -0
  70. package/dist/packages/firestore/src/core/firestore_client.d.ts +2 -0
  71. package/dist/packages/firestore/src/local/local_serializer.d.ts +1 -1
  72. package/dist/packages/firestore/src/local/remote_document_change_buffer.d.ts +3 -12
  73. package/dist/packages/firestore/src/model/document.d.ts +7 -0
  74. package/dist/packages/firestore/src/model/document_key.d.ts +1 -0
  75. package/dist/packages/firestore/src/model/field_index.d.ts +152 -0
  76. package/dist/packages/firestore/test/integration/api/index_configuration.test.d.ts +17 -0
  77. package/dist/packages/firestore/test/unit/local/test_remote_document_cache.d.ts +1 -1
  78. package/dist/packages/firestore/test/unit/model/field_index.test.d.ts +17 -0
  79. package/dist/packages/firestore/test/util/helpers.d.ts +6 -0
  80. package/dist/private.d.ts +34 -21
  81. package/package.json +10 -10
@@ -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.3";
15
+ const version$1 = "3.4.4-canary.aaeab08ac";
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.3";
68
+ const version = "9.6.5-canary.aaeab08ac";
69
69
 
70
70
  /**
71
71
  * @license
@@ -3449,6 +3449,9 @@ class DocumentKey {
3449
3449
  static fromName(name) {
3450
3450
  return new DocumentKey(ResourcePath.fromString(name).popFirst(5));
3451
3451
  }
3452
+ static empty() {
3453
+ return new DocumentKey(ResourcePath.emptyPath());
3454
+ }
3452
3455
  /** Returns true if the document is in the specified collectionId. */
3453
3456
  hasCollectionId(collectionId) {
3454
3457
  return (this.path.length >= 2 &&
@@ -4097,10 +4100,11 @@ function extractFieldMask(value) {
4097
4100
  * from all views.
4098
4101
  */
4099
4102
  class MutableDocument {
4100
- constructor(key, documentType, version, data, documentState) {
4103
+ constructor(key, documentType, version, readTime, data, documentState) {
4101
4104
  this.key = key;
4102
4105
  this.documentType = documentType;
4103
4106
  this.version = version;
4107
+ this.readTime = readTime;
4104
4108
  this.data = data;
4105
4109
  this.documentState = documentState;
4106
4110
  }
@@ -4109,18 +4113,18 @@ class MutableDocument {
4109
4113
  * base document for mutations.
4110
4114
  */
4111
4115
  static newInvalidDocument(documentKey) {
4112
- return new MutableDocument(documentKey, 0 /* INVALID */, SnapshotVersion.min(), ObjectValue.empty(), 0 /* SYNCED */);
4116
+ return new MutableDocument(documentKey, 0 /* INVALID */, SnapshotVersion.min(), SnapshotVersion.min(), ObjectValue.empty(), 0 /* SYNCED */);
4113
4117
  }
4114
4118
  /**
4115
4119
  * Creates a new document that is known to exist with the given data at the
4116
4120
  * given version.
4117
4121
  */
4118
4122
  static newFoundDocument(documentKey, version, value) {
4119
- return new MutableDocument(documentKey, 1 /* FOUND_DOCUMENT */, version, value, 0 /* SYNCED */);
4123
+ return new MutableDocument(documentKey, 1 /* FOUND_DOCUMENT */, version, SnapshotVersion.min(), value, 0 /* SYNCED */);
4120
4124
  }
4121
4125
  /** Creates a new document that is known to not exist at the given version. */
4122
4126
  static newNoDocument(documentKey, version) {
4123
- return new MutableDocument(documentKey, 2 /* NO_DOCUMENT */, version, ObjectValue.empty(), 0 /* SYNCED */);
4127
+ return new MutableDocument(documentKey, 2 /* NO_DOCUMENT */, version, SnapshotVersion.min(), ObjectValue.empty(), 0 /* SYNCED */);
4124
4128
  }
4125
4129
  /**
4126
4130
  * Creates a new document that is known to exist at the given version but
@@ -4128,7 +4132,7 @@ class MutableDocument {
4128
4132
  * base document).
4129
4133
  */
4130
4134
  static newUnknownDocument(documentKey, version) {
4131
- return new MutableDocument(documentKey, 3 /* UNKNOWN_DOCUMENT */, version, ObjectValue.empty(), 2 /* HAS_COMMITTED_MUTATIONS */);
4135
+ return new MutableDocument(documentKey, 3 /* UNKNOWN_DOCUMENT */, version, SnapshotVersion.min(), ObjectValue.empty(), 2 /* HAS_COMMITTED_MUTATIONS */);
4132
4136
  }
4133
4137
  /**
4134
4138
  * Changes the document type to indicate that it exists and that its version
@@ -4172,6 +4176,10 @@ class MutableDocument {
4172
4176
  this.documentState = 1 /* HAS_LOCAL_MUTATIONS */;
4173
4177
  return this;
4174
4178
  }
4179
+ setReadTime(readTime) {
4180
+ this.readTime = readTime;
4181
+ return this;
4182
+ }
4175
4183
  get hasLocalMutations() {
4176
4184
  return this.documentState === 1 /* HAS_LOCAL_MUTATIONS */;
4177
4185
  }
@@ -4202,7 +4210,7 @@ class MutableDocument {
4202
4210
  this.data.isEqual(other.data));
4203
4211
  }
4204
4212
  mutableCopy() {
4205
- return new MutableDocument(this.key, this.documentType, this.version, this.data.clone(), this.documentState);
4213
+ return new MutableDocument(this.key, this.documentType, this.version, this.readTime, this.data.clone(), this.documentState);
4206
4214
  }
4207
4215
  toString() {
4208
4216
  return (`Document(${this.key}, ${this.version}, ${JSON.stringify(this.data.value)}, ` +
@@ -7072,6 +7080,7 @@ class WatchChangeAggregator {
7072
7080
  resolvedLimboDocuments = resolvedLimboDocuments.add(key);
7073
7081
  }
7074
7082
  });
7083
+ this.pendingDocumentUpdates.forEach((_, doc) => doc.setReadTime(snapshotVersion));
7075
7084
  const remoteEvent = new RemoteEvent(snapshotVersion, targetChanges, this.pendingTargetResets, this.pendingDocumentUpdates, resolvedLimboDocuments);
7076
7085
  this.pendingDocumentUpdates = mutableDocumentMap();
7077
7086
  this.pendingDocumentTargetMapping = documentTargetMap();
@@ -8192,29 +8201,34 @@ class LocalSerializer {
8192
8201
  }
8193
8202
  /** Decodes a remote document from storage locally to a Document. */
8194
8203
  function fromDbRemoteDocument(localSerializer, remoteDoc) {
8204
+ let doc;
8195
8205
  if (remoteDoc.document) {
8196
- return fromDocument(localSerializer.remoteSerializer, remoteDoc.document, !!remoteDoc.hasCommittedMutations);
8206
+ doc = fromDocument(localSerializer.remoteSerializer, remoteDoc.document, !!remoteDoc.hasCommittedMutations);
8197
8207
  }
8198
8208
  else if (remoteDoc.noDocument) {
8199
8209
  const key = DocumentKey.fromSegments(remoteDoc.noDocument.path);
8200
8210
  const version = fromDbTimestamp(remoteDoc.noDocument.readTime);
8201
- const document = MutableDocument.newNoDocument(key, version);
8202
- return remoteDoc.hasCommittedMutations
8203
- ? document.setHasCommittedMutations()
8204
- : document;
8211
+ doc = MutableDocument.newNoDocument(key, version);
8212
+ if (remoteDoc.hasCommittedMutations) {
8213
+ doc.setHasCommittedMutations();
8214
+ }
8205
8215
  }
8206
8216
  else if (remoteDoc.unknownDocument) {
8207
8217
  const key = DocumentKey.fromSegments(remoteDoc.unknownDocument.path);
8208
8218
  const version = fromDbTimestamp(remoteDoc.unknownDocument.version);
8209
- return MutableDocument.newUnknownDocument(key, version);
8219
+ doc = MutableDocument.newUnknownDocument(key, version);
8210
8220
  }
8211
8221
  else {
8212
8222
  return fail();
8213
8223
  }
8224
+ if (remoteDoc.readTime) {
8225
+ doc.setReadTime(fromDbTimestampKey(remoteDoc.readTime));
8226
+ }
8227
+ return doc;
8214
8228
  }
8215
8229
  /** Encodes a document for storage locally. */
8216
- function toDbRemoteDocument(localSerializer, document, readTime) {
8217
- const dbReadTime = toDbTimestampKey(readTime);
8230
+ function toDbRemoteDocument(localSerializer, document) {
8231
+ const dbReadTime = toDbTimestampKey(document.readTime);
8218
8232
  const parentPath = document.key.path.popLast().toArray();
8219
8233
  if (document.isFoundDocument()) {
8220
8234
  const doc = toDocument(localSerializer.remoteSerializer, document);
@@ -8225,10 +8239,10 @@ function toDbRemoteDocument(localSerializer, document, readTime) {
8225
8239
  }
8226
8240
  else if (document.isNoDocument()) {
8227
8241
  const path = document.key.path.toArray();
8228
- const readTime = toDbTimestamp(document.version);
8242
+ const version = toDbTimestamp(document.version);
8229
8243
  const hasCommittedMutations = document.hasCommittedMutations;
8230
8244
  return new DbRemoteDocument(
8231
- /* unknownDocument= */ null, new DbNoDocument(path, readTime),
8245
+ /* unknownDocument= */ null, new DbNoDocument(path, version),
8232
8246
  /* document= */ null, hasCommittedMutations, dbReadTime, parentPath);
8233
8247
  }
8234
8248
  else if (document.isUnknownDocument()) {
@@ -9757,7 +9771,7 @@ class IndexedDbLruDelegateImpl {
9757
9771
  // Our size accounting requires us to read all documents before
9758
9772
  // removing them.
9759
9773
  return changeBuffer.getEntry(txn, docKey).next(() => {
9760
- changeBuffer.removeEntry(docKey);
9774
+ changeBuffer.removeEntry(docKey, SnapshotVersion.min());
9761
9775
  return documentTargetStore(txn).delete(sentinelKey$1(docKey));
9762
9776
  });
9763
9777
  }
@@ -9970,27 +9984,19 @@ class ObjectMap {
9970
9984
  */
9971
9985
  class RemoteDocumentChangeBuffer {
9972
9986
  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).
9987
+ // A mapping of document key to the new cache entry that should be written.
9975
9988
  this.changes = new ObjectMap(key => key.toString(), (l, r) => l.isEqual(r));
9976
9989
  this.changesApplied = false;
9977
9990
  }
9978
- getReadTime(key) {
9979
- const change = this.changes.get(key);
9980
- if (change) {
9981
- return change.readTime;
9982
- }
9983
- return SnapshotVersion.min();
9984
- }
9985
9991
  /**
9986
9992
  * Buffers a `RemoteDocumentCache.addEntry()` call.
9987
9993
  *
9988
9994
  * You can only modify documents that have already been retrieved via
9989
9995
  * `getEntry()/getEntries()` (enforced via IndexedDbs `apply()`).
9990
9996
  */
9991
- addEntry(document, readTime) {
9997
+ addEntry(document) {
9992
9998
  this.assertNotApplied();
9993
- this.changes.set(document.key, { document, readTime });
9999
+ this.changes.set(document.key, document);
9994
10000
  }
9995
10001
  /**
9996
10002
  * Buffers a `RemoteDocumentCache.removeEntry()` call.
@@ -9998,12 +10004,9 @@ class RemoteDocumentChangeBuffer {
9998
10004
  * You can only remove documents that have already been retrieved via
9999
10005
  * `getEntry()/getEntries()` (enforced via IndexedDbs `apply()`).
10000
10006
  */
10001
- removeEntry(key, readTime = null) {
10007
+ removeEntry(key, readTime) {
10002
10008
  this.assertNotApplied();
10003
- this.changes.set(key, {
10004
- document: MutableDocument.newInvalidDocument(key),
10005
- readTime
10006
- });
10009
+ this.changes.set(key, MutableDocument.newInvalidDocument(key).setReadTime(readTime));
10007
10010
  }
10008
10011
  /**
10009
10012
  * Looks up an entry in the cache. The buffered changes will first be checked,
@@ -10020,7 +10023,7 @@ class RemoteDocumentChangeBuffer {
10020
10023
  this.assertNotApplied();
10021
10024
  const bufferedEntry = this.changes.get(documentKey);
10022
10025
  if (bufferedEntry !== undefined) {
10023
- return PersistencePromise.resolve(bufferedEntry.document);
10026
+ return PersistencePromise.resolve(bufferedEntry);
10024
10027
  }
10025
10028
  else {
10026
10029
  return this.getFromCache(transaction, documentKey);
@@ -10231,7 +10234,7 @@ class IndexedDbRemoteDocumentCacheImpl {
10231
10234
  if (key.length !== immediateChildrenPathLength) {
10232
10235
  return;
10233
10236
  }
10234
- const document = fromDbRemoteDocument(this.serializer, dbRemoteDoc);
10237
+ const document = this.maybeDecodeDocument(DocumentKey.fromSegments(key), dbRemoteDoc);
10235
10238
  if (!query.path.isPrefixOf(document.key.path)) {
10236
10239
  control.done();
10237
10240
  }
@@ -10259,8 +10262,8 @@ class IndexedDbRemoteDocumentCacheImpl {
10259
10262
  return documentGlobalStore(txn).put(DbRemoteDocumentGlobal.key, metadata);
10260
10263
  }
10261
10264
  /**
10262
- * Decodes `remoteDoc` and returns the document (or null, if the document
10263
- * corresponds to the format used for sentinel deletes).
10265
+ * Decodes `dbRemoteDoc` and returns the document (or an invalid document if
10266
+ * the document corresponds to the format used for sentinel deletes).
10264
10267
  */
10265
10268
  maybeDecodeDocument(documentKey, dbRemoteDoc) {
10266
10269
  if (dbRemoteDoc) {
@@ -10354,8 +10357,8 @@ class IndexedDbRemoteDocumentChangeBuffer extends RemoteDocumentChangeBuffer {
10354
10357
  let collectionParents = new SortedSet((l, r) => primitiveComparator(l.canonicalString(), r.canonicalString()));
10355
10358
  this.changes.forEach((key, documentChange) => {
10356
10359
  const previousSize = this.documentSizes.get(key);
10357
- if (documentChange.document.isValidDocument()) {
10358
- const doc = toDbRemoteDocument(this.documentCache.serializer, documentChange.document, this.getReadTime(key));
10360
+ if (documentChange.isValidDocument()) {
10361
+ const doc = toDbRemoteDocument(this.documentCache.serializer, documentChange);
10359
10362
  collectionParents = collectionParents.add(key.path.popLast());
10360
10363
  const size = dbDocumentSize(doc);
10361
10364
  sizeDelta += size - previousSize;
@@ -10368,7 +10371,7 @@ class IndexedDbRemoteDocumentChangeBuffer extends RemoteDocumentChangeBuffer {
10368
10371
  // RemoteDocumentCache. This entry is represented by a NoDocument
10369
10372
  // with a version of 0 and ignored by `maybeDecodeDocument()` but
10370
10373
  // preserved in `getNewDocumentChanges()`.
10371
- const deletedDoc = toDbRemoteDocument(this.documentCache.serializer, MutableDocument.newNoDocument(key, SnapshotVersion.min()), this.getReadTime(key));
10374
+ const deletedDoc = toDbRemoteDocument(this.documentCache.serializer, documentChange.convertToNoDocument(SnapshotVersion.min()));
10372
10375
  promises.push(this.documentCache.addEntry(transaction, key, deletedDoc));
10373
10376
  }
10374
10377
  else {
@@ -11955,14 +11958,14 @@ function localStoreApplyRemoteEventToLocalCache(localStore, remoteEvent) {
11955
11958
  }
11956
11959
  });
11957
11960
  let changedDocs = mutableDocumentMap();
11958
- remoteEvent.documentUpdates.forEach((key, doc) => {
11961
+ remoteEvent.documentUpdates.forEach(key => {
11959
11962
  if (remoteEvent.resolvedLimboDocuments.has(key)) {
11960
11963
  promises.push(localStoreImpl.persistence.referenceDelegate.updateLimboDocument(txn, key));
11961
11964
  }
11962
11965
  });
11963
11966
  // Each loop iteration only affects its "own" doc, so it's safe to get all the remote
11964
11967
  // documents in advance in a single call.
11965
- promises.push(populateDocumentChangeBuffer(txn, documentBuffer, remoteEvent.documentUpdates, remoteVersion, undefined).next(result => {
11968
+ promises.push(populateDocumentChangeBuffer(txn, documentBuffer, remoteEvent.documentUpdates).next(result => {
11966
11969
  changedDocs = result;
11967
11970
  }));
11968
11971
  // HACK: The only reason we allow a null snapshot version is so that we
@@ -12003,17 +12006,13 @@ function localStoreApplyRemoteEventToLocalCache(localStore, remoteEvent) {
12003
12006
  * Note: this function will use `documentVersions` if it is defined;
12004
12007
  * when it is not defined, resorts to `globalVersion`.
12005
12008
  */
12006
- function populateDocumentChangeBuffer(txn, documentBuffer, documents, globalVersion,
12007
- // TODO(wuandy): We could add `readTime` to MaybeDocument instead to remove
12008
- // this parameter.
12009
- documentVersions) {
12009
+ function populateDocumentChangeBuffer(txn, documentBuffer, documents) {
12010
12010
  let updatedKeys = documentKeySet();
12011
12011
  documents.forEach(k => (updatedKeys = updatedKeys.add(k)));
12012
12012
  return documentBuffer.getEntries(txn, updatedKeys).next(existingDocs => {
12013
12013
  let changedDocs = mutableDocumentMap();
12014
12014
  documents.forEach((key, doc) => {
12015
12015
  const existingDoc = existingDocs.get(key);
12016
- const docReadTime = (documentVersions === null || documentVersions === void 0 ? void 0 : documentVersions.get(key)) || globalVersion;
12017
12016
  // Note: The order of the steps below is important, since we want
12018
12017
  // to ensure that rejected limbo resolutions (which fabricate
12019
12018
  // NoDocuments with SnapshotVersion.min()) never add documents to
@@ -12022,14 +12021,14 @@ documentVersions) {
12022
12021
  // NoDocuments with SnapshotVersion.min() are used in manufactured
12023
12022
  // events. We remove these documents from cache since we lost
12024
12023
  // access.
12025
- documentBuffer.removeEntry(key, docReadTime);
12024
+ documentBuffer.removeEntry(key, doc.readTime);
12026
12025
  changedDocs = changedDocs.insert(key, doc);
12027
12026
  }
12028
12027
  else if (!existingDoc.isValidDocument() ||
12029
12028
  doc.version.compareTo(existingDoc.version) > 0 ||
12030
12029
  (doc.version.compareTo(existingDoc.version) === 0 &&
12031
12030
  existingDoc.hasPendingWrites)) {
12032
- documentBuffer.addEntry(doc, docReadTime);
12031
+ documentBuffer.addEntry(doc);
12033
12032
  changedDocs = changedDocs.insert(key, doc);
12034
12033
  }
12035
12034
  else {
@@ -12283,7 +12282,8 @@ function applyWriteToRemoteDocuments(localStoreImpl, txn, batchResult, documentB
12283
12282
  // We use the commitVersion as the readTime rather than the
12284
12283
  // document's updateTime since the updateTime is not advanced
12285
12284
  // for updates that do not modify the underlying document.
12286
- documentBuffer.addEntry(doc, batchResult.commitVersion);
12285
+ doc.setReadTime(batchResult.commitVersion);
12286
+ documentBuffer.addEntry(doc);
12287
12287
  }
12288
12288
  }
12289
12289
  });
@@ -12384,14 +12384,14 @@ async function localStoreApplyBundledDocuments(localStore, bundleConverter, docu
12384
12384
  const localStoreImpl = debugCast(localStore);
12385
12385
  let documentKeys = documentKeySet();
12386
12386
  let documentMap = mutableDocumentMap();
12387
- let versionMap = documentVersionMap();
12388
12387
  for (const bundleDoc of documents) {
12389
12388
  const documentKey = bundleConverter.toDocumentKey(bundleDoc.metadata.name);
12390
12389
  if (bundleDoc.document) {
12391
12390
  documentKeys = documentKeys.add(documentKey);
12392
12391
  }
12393
- documentMap = documentMap.insert(documentKey, bundleConverter.toMutableDocument(bundleDoc));
12394
- versionMap = versionMap.insert(documentKey, bundleConverter.toSnapshotVersion(bundleDoc.metadata.readTime));
12392
+ const doc = bundleConverter.toMutableDocument(bundleDoc);
12393
+ doc.setReadTime(bundleConverter.toSnapshotVersion(bundleDoc.metadata.readTime));
12394
+ documentMap = documentMap.insert(documentKey, doc);
12395
12395
  }
12396
12396
  const documentBuffer = localStoreImpl.remoteDocuments.newChangeBuffer({
12397
12397
  trackRemovals: true // Make sure document removals show up in `getNewDocumentChanges()`
@@ -12400,7 +12400,7 @@ async function localStoreApplyBundledDocuments(localStore, bundleConverter, docu
12400
12400
  // they will not get garbage collected right away.
12401
12401
  const umbrellaTargetData = await localStoreAllocateTarget(localStoreImpl, umbrellaTarget(bundleName));
12402
12402
  return localStoreImpl.persistence.runTransaction('Apply bundle documents', 'readwrite', txn => {
12403
- return populateDocumentChangeBuffer(txn, documentBuffer, documentMap, SnapshotVersion.min(), versionMap)
12403
+ return populateDocumentChangeBuffer(txn, documentBuffer, documentMap)
12404
12404
  .next(changedDocs => {
12405
12405
  documentBuffer.apply(txn);
12406
12406
  return changedDocs;
@@ -12881,15 +12881,14 @@ class MemoryRemoteDocumentCacheImpl {
12881
12881
  * All calls of `addEntry` are required to go through the RemoteDocumentChangeBuffer
12882
12882
  * returned by `newChangeBuffer()`.
12883
12883
  */
12884
- addEntry(transaction, doc, readTime) {
12884
+ addEntry(transaction, doc) {
12885
12885
  const key = doc.key;
12886
12886
  const entry = this.docs.get(key);
12887
12887
  const previousSize = entry ? entry.size : 0;
12888
12888
  const currentSize = this.sizer(doc);
12889
12889
  this.docs = this.docs.insert(key, {
12890
12890
  document: doc.mutableCopy(),
12891
- size: currentSize,
12892
- readTime
12891
+ size: currentSize
12893
12892
  });
12894
12893
  this.size += currentSize - previousSize;
12895
12894
  return this.indexManager.addToCollectionParentIndex(transaction, key.path.popLast());
@@ -12930,11 +12929,11 @@ class MemoryRemoteDocumentCacheImpl {
12930
12929
  const prefix = new DocumentKey(query.path.child(''));
12931
12930
  const iterator = this.docs.getIteratorFrom(prefix);
12932
12931
  while (iterator.hasNext()) {
12933
- const { key, value: { document, readTime } } = iterator.getNext();
12932
+ const { key, value: { document } } = iterator.getNext();
12934
12933
  if (!query.path.isPrefixOf(key.path)) {
12935
12934
  break;
12936
12935
  }
12937
- if (readTime.compareTo(sinceReadTime) <= 0) {
12936
+ if (document.readTime.compareTo(sinceReadTime) <= 0) {
12938
12937
  continue;
12939
12938
  }
12940
12939
  if (!queryMatches(query, document)) {
@@ -12978,8 +12977,8 @@ class MemoryRemoteDocumentChangeBuffer extends RemoteDocumentChangeBuffer {
12978
12977
  applyChanges(transaction) {
12979
12978
  const promises = [];
12980
12979
  this.changes.forEach((key, doc) => {
12981
- if (doc.document.isValidDocument()) {
12982
- promises.push(this.documentCache.addEntry(transaction, doc.document, this.getReadTime(key)));
12980
+ if (doc.isValidDocument()) {
12981
+ promises.push(this.documentCache.addEntry(transaction, doc));
12983
12982
  }
12984
12983
  else {
12985
12984
  this.documentCache.removeEntry(key);
@@ -13292,7 +13291,7 @@ class MemoryEagerDelegate {
13292
13291
  const key = DocumentKey.fromPath(path);
13293
13292
  return this.isReferenced(txn, key).next(isReferenced => {
13294
13293
  if (!isReferenced) {
13295
- changeBuffer.removeEntry(key);
13294
+ changeBuffer.removeEntry(key, SnapshotVersion.min());
13296
13295
  }
13297
13296
  });
13298
13297
  }).next(() => {
@@ -17072,6 +17071,40 @@ const nested = {
17072
17071
  id: 2
17073
17072
  }
17074
17073
  }
17074
+ },
17075
+ methodSignature: {
17076
+ rule: "repeated",
17077
+ type: "string",
17078
+ id: 1051,
17079
+ extend: "google.protobuf.MethodOptions"
17080
+ },
17081
+ defaultHost: {
17082
+ type: "string",
17083
+ id: 1049,
17084
+ extend: "google.protobuf.ServiceOptions"
17085
+ },
17086
+ oauthScopes: {
17087
+ type: "string",
17088
+ id: 1050,
17089
+ extend: "google.protobuf.ServiceOptions"
17090
+ },
17091
+ fieldBehavior: {
17092
+ rule: "repeated",
17093
+ type: "google.api.FieldBehavior",
17094
+ id: 1052,
17095
+ extend: "google.protobuf.FieldOptions"
17096
+ },
17097
+ FieldBehavior: {
17098
+ values: {
17099
+ FIELD_BEHAVIOR_UNSPECIFIED: 0,
17100
+ OPTIONAL: 1,
17101
+ REQUIRED: 2,
17102
+ OUTPUT_ONLY: 3,
17103
+ INPUT_ONLY: 4,
17104
+ IMMUTABLE: 5,
17105
+ UNORDERED_LIST: 6,
17106
+ NON_EMPTY_DEFAULT: 7
17107
+ }
17075
17108
  }
17076
17109
  }
17077
17110
  },
@@ -20315,6 +20348,9 @@ async function syncEngineRejectListen(syncEngine, targetId, err) {
20315
20348
  // store to purge a document. However, it would be tricky to keep all of
20316
20349
  // the local store's invariants with another method.
20317
20350
  let documentUpdates = new SortedMap(DocumentKey.comparator);
20351
+ // TODO(b/217189216): This limbo document should ideally have a read time,
20352
+ // so that it is picked up by any read-time based scans. The backend,
20353
+ // however, does not send a read time for target removals.
20318
20354
  documentUpdates = documentUpdates.insert(limboKey, MutableDocument.newNoDocument(limboKey, SnapshotVersion.min()));
20319
20355
  const resolvedLimboDocuments = documentKeySet().add(limboKey);
20320
20356
  const event = new RemoteEvent(SnapshotVersion.min(),
@@ -21882,13 +21918,16 @@ class FirestoreClient {
21882
21918
  this.user = User.UNAUTHENTICATED;
21883
21919
  this.clientId = AutoId.newId();
21884
21920
  this.authCredentialListener = () => Promise.resolve();
21921
+ this.appCheckCredentialListener = () => Promise.resolve();
21885
21922
  this.authCredentials.start(asyncQueue, async (user) => {
21886
21923
  logDebug(LOG_TAG$2, 'Received user=', user.uid);
21887
21924
  await this.authCredentialListener(user);
21888
21925
  this.user = user;
21889
21926
  });
21890
- // Register an empty credentials change listener to activate token refresh.
21891
- this.appCheckCredentials.start(asyncQueue, () => Promise.resolve());
21927
+ this.appCheckCredentials.start(asyncQueue, newAppCheckToken => {
21928
+ logDebug(LOG_TAG$2, 'Received new app check token=', newAppCheckToken);
21929
+ return this.appCheckCredentialListener(newAppCheckToken, this.user);
21930
+ });
21892
21931
  }
21893
21932
  async getConfiguration() {
21894
21933
  return {
@@ -21904,6 +21943,9 @@ class FirestoreClient {
21904
21943
  setCredentialChangeListener(listener) {
21905
21944
  this.authCredentialListener = listener;
21906
21945
  }
21946
+ setAppCheckTokenChangeListener(listener) {
21947
+ this.appCheckCredentialListener = listener;
21948
+ }
21907
21949
  /**
21908
21950
  * Checks that the client has not been terminated. Ensures that other methods on
21909
21951
  * this class cannot be called after the client is terminated.
@@ -21965,6 +22007,7 @@ async function setOnlineComponentProvider(client, onlineComponentProvider) {
21965
22007
  // The CredentialChangeListener of the online component provider takes
21966
22008
  // precedence over the offline component provider.
21967
22009
  client.setCredentialChangeListener(user => remoteStoreHandleCredentialChange(onlineComponentProvider.remoteStore, user));
22010
+ client.setAppCheckTokenChangeListener((_, user) => remoteStoreHandleCredentialChange(onlineComponentProvider.remoteStore, user));
21968
22011
  client.onlineComponents = onlineComponentProvider;
21969
22012
  }
21970
22013
  async function ensureOfflineComponents(client) {
@@ -23517,13 +23560,13 @@ function terminate(firestore) {
23517
23560
  /**
23518
23561
  * Loads a Firestore bundle into the local cache.
23519
23562
  *
23520
- * @param firestore - The {@link Firestore} instance to load bundles for for.
23521
- * @param bundleData - An object representing the bundle to be loaded. Valid objects are
23522
- * `ArrayBuffer`, `ReadableStream<Uint8Array>` or `string`.
23563
+ * @param firestore - The {@link Firestore} instance to load bundles for.
23564
+ * @param bundleData - An object representing the bundle to be loaded. Valid
23565
+ * objects are `ArrayBuffer`, `ReadableStream<Uint8Array>` or `string`.
23523
23566
  *
23524
- * @returns
23525
- * A `LoadBundleTask` object, which notifies callers with progress updates, and completion
23526
- * or error events. It can be used as a `Promise<LoadBundleTaskProgress>`.
23567
+ * @returns A `LoadBundleTask` object, which notifies callers with progress
23568
+ * updates, and completion or error events. It can be used as a
23569
+ * `Promise<LoadBundleTaskProgress>`.
23527
23570
  */
23528
23571
  function loadBundle(firestore, bundleData) {
23529
23572
  firestore = cast(firestore, Firestore);
@@ -23533,11 +23576,16 @@ function loadBundle(firestore, bundleData) {
23533
23576
  return resultTask;
23534
23577
  }
23535
23578
  /**
23536
- * Reads a Firestore {@link Query} from local cache, identified by the given name.
23579
+ * Reads a Firestore {@link Query} from local cache, identified by the given
23580
+ * name.
23537
23581
  *
23538
23582
  * The named queries are packaged into bundles on the server side (along
23539
- * with resulting documents), and loaded to local cache using `loadBundle`. Once in local
23540
- * cache, use this method to extract a {@link Query} by name.
23583
+ * with resulting documents), and loaded to local cache using `loadBundle`. Once
23584
+ * in local cache, use this method to extract a {@link Query} by name.
23585
+ *
23586
+ * @param firestore - The {@link Firestore} instance to read the query from.
23587
+ * @param name - The name of the query.
23588
+ * @returns A `Promise` that is resolved with the Query or `null`.
23541
23589
  */
23542
23590
  function namedQuery(firestore, name) {
23543
23591
  firestore = cast(firestore, Firestore);
@@ -26227,6 +26275,190 @@ function writeBatch(firestore) {
26227
26275
  return new WriteBatch(firestore, mutations => executeWrite(firestore, mutations));
26228
26276
  }
26229
26277
 
26278
+ /**
26279
+ * @license
26280
+ * Copyright 2021 Google LLC
26281
+ *
26282
+ * Licensed under the Apache License, Version 2.0 (the "License");
26283
+ * you may not use this file except in compliance with the License.
26284
+ * You may obtain a copy of the License at
26285
+ *
26286
+ * http://www.apache.org/licenses/LICENSE-2.0
26287
+ *
26288
+ * Unless required by applicable law or agreed to in writing, software
26289
+ * distributed under the License is distributed on an "AS IS" BASIS,
26290
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
26291
+ * See the License for the specific language governing permissions and
26292
+ * limitations under the License.
26293
+ */
26294
+ /**
26295
+ * The initial mutation batch id for each index. Gets updated during index
26296
+ * backfill.
26297
+ */
26298
+ const INITIAL_LARGEST_BATCH_ID = -1;
26299
+ /**
26300
+ * The initial sequence number for each index. Gets updated during index
26301
+ * backfill.
26302
+ */
26303
+ const INITIAL_SEQUENCE_NUMBER = 0;
26304
+ /**
26305
+ * An index definition for field indexes in Firestore.
26306
+ *
26307
+ * Every index is associated with a collection. The definition contains a list
26308
+ * of fields and their index kind (which can be `ASCENDING`, `DESCENDING` or
26309
+ * `CONTAINS` for ArrayContains/ArrayContainsAny queries).
26310
+ *
26311
+ * Unlike the backend, the SDK does not differentiate between collection or
26312
+ * collection group-scoped indices. Every index can be used for both single
26313
+ * collection and collection group queries.
26314
+ */
26315
+ class FieldIndex {
26316
+ constructor(
26317
+ /**
26318
+ * The index ID. Returns -1 if the index ID is not available (e.g. the index
26319
+ * has not yet been persisted).
26320
+ */
26321
+ indexId,
26322
+ /** The collection ID this index applies to. */
26323
+ collectionGroup,
26324
+ /** The field segments for this index. */
26325
+ segments,
26326
+ /** Shows how up-to-date the index is for the current user. */
26327
+ indexState) {
26328
+ this.indexId = indexId;
26329
+ this.collectionGroup = collectionGroup;
26330
+ this.segments = segments;
26331
+ this.indexState = indexState;
26332
+ }
26333
+ }
26334
+ /** An ID for an index that has not yet been added to persistence. */
26335
+ FieldIndex.UNKNOWN_ID = -1;
26336
+ /** An index component consisting of field path and index type. */
26337
+ class IndexSegment {
26338
+ constructor(
26339
+ /** The field path of the component. */
26340
+ fieldPath,
26341
+ /** The fields sorting order. */
26342
+ kind) {
26343
+ this.fieldPath = fieldPath;
26344
+ this.kind = kind;
26345
+ }
26346
+ }
26347
+ /**
26348
+ * Stores the "high water mark" that indicates how updated the Index is for the
26349
+ * current user.
26350
+ */
26351
+ class IndexState {
26352
+ constructor(
26353
+ /**
26354
+ * Indicates when the index was last updated (relative to other indexes).
26355
+ */
26356
+ sequenceNumber,
26357
+ /** The the latest indexed read time, document and batch id. */
26358
+ offset) {
26359
+ this.sequenceNumber = sequenceNumber;
26360
+ this.offset = offset;
26361
+ }
26362
+ /** The state of an index that has not yet been backfilled. */
26363
+ static empty() {
26364
+ return new IndexState(INITIAL_SEQUENCE_NUMBER, IndexOffset.min());
26365
+ }
26366
+ }
26367
+ /**
26368
+ * Stores the latest read time, document and batch ID that were processed for an
26369
+ * index.
26370
+ */
26371
+ class IndexOffset {
26372
+ constructor(
26373
+ /**
26374
+ * The latest read time version that has been indexed by Firestore for this
26375
+ * field index.
26376
+ */
26377
+ readTime,
26378
+ /**
26379
+ * The key of the last document that was indexed for this query. Use
26380
+ * `DocumentKey.empty()` if no document has been indexed.
26381
+ */
26382
+ documentKey,
26383
+ /*
26384
+ * The largest mutation batch id that's been processed by Firestore.
26385
+ */
26386
+ largestBatchId) {
26387
+ this.readTime = readTime;
26388
+ this.documentKey = documentKey;
26389
+ this.largestBatchId = largestBatchId;
26390
+ }
26391
+ /** The state of an index that has not yet been backfilled. */
26392
+ static min() {
26393
+ return new IndexOffset(SnapshotVersion.min(), DocumentKey.empty(), INITIAL_LARGEST_BATCH_ID);
26394
+ }
26395
+ }
26396
+
26397
+ /**
26398
+ * @license
26399
+ * Copyright 2021 Google LLC
26400
+ *
26401
+ * Licensed under the Apache License, Version 2.0 (the "License");
26402
+ * you may not use this file except in compliance with the License.
26403
+ * You may obtain a copy of the License at
26404
+ *
26405
+ * http://www.apache.org/licenses/LICENSE-2.0
26406
+ *
26407
+ * Unless required by applicable law or agreed to in writing, software
26408
+ * distributed under the License is distributed on an "AS IS" BASIS,
26409
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
26410
+ * See the License for the specific language governing permissions and
26411
+ * limitations under the License.
26412
+ */
26413
+ function setIndexConfiguration(firestore, jsonOrConfiguration) {
26414
+ firestore = cast(firestore, Firestore);
26415
+ ensureFirestoreConfigured(firestore);
26416
+ const indexConfiguration = typeof jsonOrConfiguration === 'string'
26417
+ ? tryParseJson(jsonOrConfiguration)
26418
+ : jsonOrConfiguration;
26419
+ const parsedIndexes = [];
26420
+ // PORTING NOTE: We don't return an error if the user has not enabled
26421
+ // persistence since `enableIndexeddbPersistence()` can fail on the Web.
26422
+ if (Array.isArray(indexConfiguration.indexes)) {
26423
+ for (const index of indexConfiguration.indexes) {
26424
+ const collectionGroup = tryGetString(index, 'collectionGroup');
26425
+ const segments = [];
26426
+ if (Array.isArray(index.fields)) {
26427
+ for (const field of index.fields) {
26428
+ const fieldPathString = tryGetString(field, 'fieldPath');
26429
+ const fieldPath = fieldPathFromDotSeparatedString('setIndexConfiguration', fieldPathString);
26430
+ if (field.arrayConfig === 'CONTAINS') {
26431
+ segments.push(new IndexSegment(fieldPath, 2 /* CONTAINS */));
26432
+ }
26433
+ else if (field.order === 'ASCENDING') {
26434
+ segments.push(new IndexSegment(fieldPath, 0 /* ASCENDING */));
26435
+ }
26436
+ else if (field.order === 'DESCENDING') {
26437
+ segments.push(new IndexSegment(fieldPath, 1 /* DESCENDING */));
26438
+ }
26439
+ }
26440
+ }
26441
+ parsedIndexes.push(new FieldIndex(FieldIndex.UNKNOWN_ID, collectionGroup, segments, IndexState.empty()));
26442
+ }
26443
+ }
26444
+ // TODO(indexing): Configure indexes
26445
+ return Promise.resolve();
26446
+ }
26447
+ function tryParseJson(json) {
26448
+ try {
26449
+ return JSON.parse(json);
26450
+ }
26451
+ catch (e) {
26452
+ throw new FirestoreError(Code.INVALID_ARGUMENT, 'Failed to parse JSON:' + e.message);
26453
+ }
26454
+ }
26455
+ function tryGetString(data, property) {
26456
+ if (typeof data[property] !== 'string') {
26457
+ throw new FirestoreError(Code.INVALID_ARGUMENT, 'Missing string value for: ' + property);
26458
+ }
26459
+ return data[property];
26460
+ }
26461
+
26230
26462
  /**
26231
26463
  * @license
26232
26464
  * Copyright 2021 Google LLC
@@ -26274,6 +26506,7 @@ exports._cast = cast;
26274
26506
  exports._debugAssert = debugAssert;
26275
26507
  exports._isBase64Available = isBase64Available;
26276
26508
  exports._logWarn = logWarn;
26509
+ exports._setIndexConfiguration = setIndexConfiguration;
26277
26510
  exports._validateIsNotUsedTogether = validateIsNotUsedTogether;
26278
26511
  exports.addDoc = addDoc;
26279
26512
  exports.arrayRemove = arrayRemove;