@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
@@ -8,7 +8,7 @@ import { credentials, loadPackageDefinition, Metadata } from '@grpc/grpc-js';
8
8
  import { fromJSON } from '@grpc/proto-loader';
9
9
 
10
10
  const name = "@firebase/firestore";
11
- const version$1 = "3.4.3";
11
+ const version$1 = "3.4.4-canary.aaeab08ac";
12
12
 
13
13
  /**
14
14
  * @license
@@ -61,7 +61,7 @@ User.GOOGLE_CREDENTIALS = new User('google-credentials-uid');
61
61
  User.FIRST_PARTY = new User('first-party-uid');
62
62
  User.MOCK_USER = new User('mock-user');
63
63
 
64
- const version = "9.6.3";
64
+ const version = "9.6.5-canary.aaeab08ac";
65
65
 
66
66
  /**
67
67
  * @license
@@ -3445,6 +3445,9 @@ class DocumentKey {
3445
3445
  static fromName(name) {
3446
3446
  return new DocumentKey(ResourcePath.fromString(name).popFirst(5));
3447
3447
  }
3448
+ static empty() {
3449
+ return new DocumentKey(ResourcePath.emptyPath());
3450
+ }
3448
3451
  /** Returns true if the document is in the specified collectionId. */
3449
3452
  hasCollectionId(collectionId) {
3450
3453
  return (this.path.length >= 2 &&
@@ -4093,10 +4096,11 @@ function extractFieldMask(value) {
4093
4096
  * from all views.
4094
4097
  */
4095
4098
  class MutableDocument {
4096
- constructor(key, documentType, version, data, documentState) {
4099
+ constructor(key, documentType, version, readTime, data, documentState) {
4097
4100
  this.key = key;
4098
4101
  this.documentType = documentType;
4099
4102
  this.version = version;
4103
+ this.readTime = readTime;
4100
4104
  this.data = data;
4101
4105
  this.documentState = documentState;
4102
4106
  }
@@ -4105,18 +4109,18 @@ class MutableDocument {
4105
4109
  * base document for mutations.
4106
4110
  */
4107
4111
  static newInvalidDocument(documentKey) {
4108
- return new MutableDocument(documentKey, 0 /* INVALID */, SnapshotVersion.min(), ObjectValue.empty(), 0 /* SYNCED */);
4112
+ return new MutableDocument(documentKey, 0 /* INVALID */, SnapshotVersion.min(), SnapshotVersion.min(), ObjectValue.empty(), 0 /* SYNCED */);
4109
4113
  }
4110
4114
  /**
4111
4115
  * Creates a new document that is known to exist with the given data at the
4112
4116
  * given version.
4113
4117
  */
4114
4118
  static newFoundDocument(documentKey, version, value) {
4115
- return new MutableDocument(documentKey, 1 /* FOUND_DOCUMENT */, version, value, 0 /* SYNCED */);
4119
+ return new MutableDocument(documentKey, 1 /* FOUND_DOCUMENT */, version, SnapshotVersion.min(), value, 0 /* SYNCED */);
4116
4120
  }
4117
4121
  /** Creates a new document that is known to not exist at the given version. */
4118
4122
  static newNoDocument(documentKey, version) {
4119
- return new MutableDocument(documentKey, 2 /* NO_DOCUMENT */, version, ObjectValue.empty(), 0 /* SYNCED */);
4123
+ return new MutableDocument(documentKey, 2 /* NO_DOCUMENT */, version, SnapshotVersion.min(), ObjectValue.empty(), 0 /* SYNCED */);
4120
4124
  }
4121
4125
  /**
4122
4126
  * Creates a new document that is known to exist at the given version but
@@ -4124,7 +4128,7 @@ class MutableDocument {
4124
4128
  * base document).
4125
4129
  */
4126
4130
  static newUnknownDocument(documentKey, version) {
4127
- return new MutableDocument(documentKey, 3 /* UNKNOWN_DOCUMENT */, version, ObjectValue.empty(), 2 /* HAS_COMMITTED_MUTATIONS */);
4131
+ return new MutableDocument(documentKey, 3 /* UNKNOWN_DOCUMENT */, version, SnapshotVersion.min(), ObjectValue.empty(), 2 /* HAS_COMMITTED_MUTATIONS */);
4128
4132
  }
4129
4133
  /**
4130
4134
  * Changes the document type to indicate that it exists and that its version
@@ -4168,6 +4172,10 @@ class MutableDocument {
4168
4172
  this.documentState = 1 /* HAS_LOCAL_MUTATIONS */;
4169
4173
  return this;
4170
4174
  }
4175
+ setReadTime(readTime) {
4176
+ this.readTime = readTime;
4177
+ return this;
4178
+ }
4171
4179
  get hasLocalMutations() {
4172
4180
  return this.documentState === 1 /* HAS_LOCAL_MUTATIONS */;
4173
4181
  }
@@ -4198,7 +4206,7 @@ class MutableDocument {
4198
4206
  this.data.isEqual(other.data));
4199
4207
  }
4200
4208
  mutableCopy() {
4201
- return new MutableDocument(this.key, this.documentType, this.version, this.data.clone(), this.documentState);
4209
+ return new MutableDocument(this.key, this.documentType, this.version, this.readTime, this.data.clone(), this.documentState);
4202
4210
  }
4203
4211
  toString() {
4204
4212
  return (`Document(${this.key}, ${this.version}, ${JSON.stringify(this.data.value)}, ` +
@@ -7068,6 +7076,7 @@ class WatchChangeAggregator {
7068
7076
  resolvedLimboDocuments = resolvedLimboDocuments.add(key);
7069
7077
  }
7070
7078
  });
7079
+ this.pendingDocumentUpdates.forEach((_, doc) => doc.setReadTime(snapshotVersion));
7071
7080
  const remoteEvent = new RemoteEvent(snapshotVersion, targetChanges, this.pendingTargetResets, this.pendingDocumentUpdates, resolvedLimboDocuments);
7072
7081
  this.pendingDocumentUpdates = mutableDocumentMap();
7073
7082
  this.pendingDocumentTargetMapping = documentTargetMap();
@@ -8188,29 +8197,34 @@ class LocalSerializer {
8188
8197
  }
8189
8198
  /** Decodes a remote document from storage locally to a Document. */
8190
8199
  function fromDbRemoteDocument(localSerializer, remoteDoc) {
8200
+ let doc;
8191
8201
  if (remoteDoc.document) {
8192
- return fromDocument(localSerializer.remoteSerializer, remoteDoc.document, !!remoteDoc.hasCommittedMutations);
8202
+ doc = fromDocument(localSerializer.remoteSerializer, remoteDoc.document, !!remoteDoc.hasCommittedMutations);
8193
8203
  }
8194
8204
  else if (remoteDoc.noDocument) {
8195
8205
  const key = DocumentKey.fromSegments(remoteDoc.noDocument.path);
8196
8206
  const version = fromDbTimestamp(remoteDoc.noDocument.readTime);
8197
- const document = MutableDocument.newNoDocument(key, version);
8198
- return remoteDoc.hasCommittedMutations
8199
- ? document.setHasCommittedMutations()
8200
- : document;
8207
+ doc = MutableDocument.newNoDocument(key, version);
8208
+ if (remoteDoc.hasCommittedMutations) {
8209
+ doc.setHasCommittedMutations();
8210
+ }
8201
8211
  }
8202
8212
  else if (remoteDoc.unknownDocument) {
8203
8213
  const key = DocumentKey.fromSegments(remoteDoc.unknownDocument.path);
8204
8214
  const version = fromDbTimestamp(remoteDoc.unknownDocument.version);
8205
- return MutableDocument.newUnknownDocument(key, version);
8215
+ doc = MutableDocument.newUnknownDocument(key, version);
8206
8216
  }
8207
8217
  else {
8208
8218
  return fail();
8209
8219
  }
8220
+ if (remoteDoc.readTime) {
8221
+ doc.setReadTime(fromDbTimestampKey(remoteDoc.readTime));
8222
+ }
8223
+ return doc;
8210
8224
  }
8211
8225
  /** Encodes a document for storage locally. */
8212
- function toDbRemoteDocument(localSerializer, document, readTime) {
8213
- const dbReadTime = toDbTimestampKey(readTime);
8226
+ function toDbRemoteDocument(localSerializer, document) {
8227
+ const dbReadTime = toDbTimestampKey(document.readTime);
8214
8228
  const parentPath = document.key.path.popLast().toArray();
8215
8229
  if (document.isFoundDocument()) {
8216
8230
  const doc = toDocument(localSerializer.remoteSerializer, document);
@@ -8221,10 +8235,10 @@ function toDbRemoteDocument(localSerializer, document, readTime) {
8221
8235
  }
8222
8236
  else if (document.isNoDocument()) {
8223
8237
  const path = document.key.path.toArray();
8224
- const readTime = toDbTimestamp(document.version);
8238
+ const version = toDbTimestamp(document.version);
8225
8239
  const hasCommittedMutations = document.hasCommittedMutations;
8226
8240
  return new DbRemoteDocument(
8227
- /* unknownDocument= */ null, new DbNoDocument(path, readTime),
8241
+ /* unknownDocument= */ null, new DbNoDocument(path, version),
8228
8242
  /* document= */ null, hasCommittedMutations, dbReadTime, parentPath);
8229
8243
  }
8230
8244
  else if (document.isUnknownDocument()) {
@@ -9753,7 +9767,7 @@ class IndexedDbLruDelegateImpl {
9753
9767
  // Our size accounting requires us to read all documents before
9754
9768
  // removing them.
9755
9769
  return changeBuffer.getEntry(txn, docKey).next(() => {
9756
- changeBuffer.removeEntry(docKey);
9770
+ changeBuffer.removeEntry(docKey, SnapshotVersion.min());
9757
9771
  return documentTargetStore(txn).delete(sentinelKey$1(docKey));
9758
9772
  });
9759
9773
  }
@@ -9966,27 +9980,19 @@ class ObjectMap {
9966
9980
  */
9967
9981
  class RemoteDocumentChangeBuffer {
9968
9982
  constructor() {
9969
- // A mapping of document key to the new cache entry that should be written (or null if any
9970
- // existing cache entry should be removed).
9983
+ // A mapping of document key to the new cache entry that should be written.
9971
9984
  this.changes = new ObjectMap(key => key.toString(), (l, r) => l.isEqual(r));
9972
9985
  this.changesApplied = false;
9973
9986
  }
9974
- getReadTime(key) {
9975
- const change = this.changes.get(key);
9976
- if (change) {
9977
- return change.readTime;
9978
- }
9979
- return SnapshotVersion.min();
9980
- }
9981
9987
  /**
9982
9988
  * Buffers a `RemoteDocumentCache.addEntry()` call.
9983
9989
  *
9984
9990
  * You can only modify documents that have already been retrieved via
9985
9991
  * `getEntry()/getEntries()` (enforced via IndexedDbs `apply()`).
9986
9992
  */
9987
- addEntry(document, readTime) {
9993
+ addEntry(document) {
9988
9994
  this.assertNotApplied();
9989
- this.changes.set(document.key, { document, readTime });
9995
+ this.changes.set(document.key, document);
9990
9996
  }
9991
9997
  /**
9992
9998
  * Buffers a `RemoteDocumentCache.removeEntry()` call.
@@ -9994,12 +10000,9 @@ class RemoteDocumentChangeBuffer {
9994
10000
  * You can only remove documents that have already been retrieved via
9995
10001
  * `getEntry()/getEntries()` (enforced via IndexedDbs `apply()`).
9996
10002
  */
9997
- removeEntry(key, readTime = null) {
10003
+ removeEntry(key, readTime) {
9998
10004
  this.assertNotApplied();
9999
- this.changes.set(key, {
10000
- document: MutableDocument.newInvalidDocument(key),
10001
- readTime
10002
- });
10005
+ this.changes.set(key, MutableDocument.newInvalidDocument(key).setReadTime(readTime));
10003
10006
  }
10004
10007
  /**
10005
10008
  * Looks up an entry in the cache. The buffered changes will first be checked,
@@ -10016,7 +10019,7 @@ class RemoteDocumentChangeBuffer {
10016
10019
  this.assertNotApplied();
10017
10020
  const bufferedEntry = this.changes.get(documentKey);
10018
10021
  if (bufferedEntry !== undefined) {
10019
- return PersistencePromise.resolve(bufferedEntry.document);
10022
+ return PersistencePromise.resolve(bufferedEntry);
10020
10023
  }
10021
10024
  else {
10022
10025
  return this.getFromCache(transaction, documentKey);
@@ -10227,7 +10230,7 @@ class IndexedDbRemoteDocumentCacheImpl {
10227
10230
  if (key.length !== immediateChildrenPathLength) {
10228
10231
  return;
10229
10232
  }
10230
- const document = fromDbRemoteDocument(this.serializer, dbRemoteDoc);
10233
+ const document = this.maybeDecodeDocument(DocumentKey.fromSegments(key), dbRemoteDoc);
10231
10234
  if (!query.path.isPrefixOf(document.key.path)) {
10232
10235
  control.done();
10233
10236
  }
@@ -10255,8 +10258,8 @@ class IndexedDbRemoteDocumentCacheImpl {
10255
10258
  return documentGlobalStore(txn).put(DbRemoteDocumentGlobal.key, metadata);
10256
10259
  }
10257
10260
  /**
10258
- * Decodes `remoteDoc` and returns the document (or null, if the document
10259
- * corresponds to the format used for sentinel deletes).
10261
+ * Decodes `dbRemoteDoc` and returns the document (or an invalid document if
10262
+ * the document corresponds to the format used for sentinel deletes).
10260
10263
  */
10261
10264
  maybeDecodeDocument(documentKey, dbRemoteDoc) {
10262
10265
  if (dbRemoteDoc) {
@@ -10350,8 +10353,8 @@ class IndexedDbRemoteDocumentChangeBuffer extends RemoteDocumentChangeBuffer {
10350
10353
  let collectionParents = new SortedSet((l, r) => primitiveComparator(l.canonicalString(), r.canonicalString()));
10351
10354
  this.changes.forEach((key, documentChange) => {
10352
10355
  const previousSize = this.documentSizes.get(key);
10353
- if (documentChange.document.isValidDocument()) {
10354
- const doc = toDbRemoteDocument(this.documentCache.serializer, documentChange.document, this.getReadTime(key));
10356
+ if (documentChange.isValidDocument()) {
10357
+ const doc = toDbRemoteDocument(this.documentCache.serializer, documentChange);
10355
10358
  collectionParents = collectionParents.add(key.path.popLast());
10356
10359
  const size = dbDocumentSize(doc);
10357
10360
  sizeDelta += size - previousSize;
@@ -10364,7 +10367,7 @@ class IndexedDbRemoteDocumentChangeBuffer extends RemoteDocumentChangeBuffer {
10364
10367
  // RemoteDocumentCache. This entry is represented by a NoDocument
10365
10368
  // with a version of 0 and ignored by `maybeDecodeDocument()` but
10366
10369
  // preserved in `getNewDocumentChanges()`.
10367
- const deletedDoc = toDbRemoteDocument(this.documentCache.serializer, MutableDocument.newNoDocument(key, SnapshotVersion.min()), this.getReadTime(key));
10370
+ const deletedDoc = toDbRemoteDocument(this.documentCache.serializer, documentChange.convertToNoDocument(SnapshotVersion.min()));
10368
10371
  promises.push(this.documentCache.addEntry(transaction, key, deletedDoc));
10369
10372
  }
10370
10373
  else {
@@ -11951,14 +11954,14 @@ function localStoreApplyRemoteEventToLocalCache(localStore, remoteEvent) {
11951
11954
  }
11952
11955
  });
11953
11956
  let changedDocs = mutableDocumentMap();
11954
- remoteEvent.documentUpdates.forEach((key, doc) => {
11957
+ remoteEvent.documentUpdates.forEach(key => {
11955
11958
  if (remoteEvent.resolvedLimboDocuments.has(key)) {
11956
11959
  promises.push(localStoreImpl.persistence.referenceDelegate.updateLimboDocument(txn, key));
11957
11960
  }
11958
11961
  });
11959
11962
  // Each loop iteration only affects its "own" doc, so it's safe to get all the remote
11960
11963
  // documents in advance in a single call.
11961
- promises.push(populateDocumentChangeBuffer(txn, documentBuffer, remoteEvent.documentUpdates, remoteVersion, undefined).next(result => {
11964
+ promises.push(populateDocumentChangeBuffer(txn, documentBuffer, remoteEvent.documentUpdates).next(result => {
11962
11965
  changedDocs = result;
11963
11966
  }));
11964
11967
  // HACK: The only reason we allow a null snapshot version is so that we
@@ -11999,17 +12002,13 @@ function localStoreApplyRemoteEventToLocalCache(localStore, remoteEvent) {
11999
12002
  * Note: this function will use `documentVersions` if it is defined;
12000
12003
  * when it is not defined, resorts to `globalVersion`.
12001
12004
  */
12002
- function populateDocumentChangeBuffer(txn, documentBuffer, documents, globalVersion,
12003
- // TODO(wuandy): We could add `readTime` to MaybeDocument instead to remove
12004
- // this parameter.
12005
- documentVersions) {
12005
+ function populateDocumentChangeBuffer(txn, documentBuffer, documents) {
12006
12006
  let updatedKeys = documentKeySet();
12007
12007
  documents.forEach(k => (updatedKeys = updatedKeys.add(k)));
12008
12008
  return documentBuffer.getEntries(txn, updatedKeys).next(existingDocs => {
12009
12009
  let changedDocs = mutableDocumentMap();
12010
12010
  documents.forEach((key, doc) => {
12011
12011
  const existingDoc = existingDocs.get(key);
12012
- const docReadTime = (documentVersions === null || documentVersions === void 0 ? void 0 : documentVersions.get(key)) || globalVersion;
12013
12012
  // Note: The order of the steps below is important, since we want
12014
12013
  // to ensure that rejected limbo resolutions (which fabricate
12015
12014
  // NoDocuments with SnapshotVersion.min()) never add documents to
@@ -12018,14 +12017,14 @@ documentVersions) {
12018
12017
  // NoDocuments with SnapshotVersion.min() are used in manufactured
12019
12018
  // events. We remove these documents from cache since we lost
12020
12019
  // access.
12021
- documentBuffer.removeEntry(key, docReadTime);
12020
+ documentBuffer.removeEntry(key, doc.readTime);
12022
12021
  changedDocs = changedDocs.insert(key, doc);
12023
12022
  }
12024
12023
  else if (!existingDoc.isValidDocument() ||
12025
12024
  doc.version.compareTo(existingDoc.version) > 0 ||
12026
12025
  (doc.version.compareTo(existingDoc.version) === 0 &&
12027
12026
  existingDoc.hasPendingWrites)) {
12028
- documentBuffer.addEntry(doc, docReadTime);
12027
+ documentBuffer.addEntry(doc);
12029
12028
  changedDocs = changedDocs.insert(key, doc);
12030
12029
  }
12031
12030
  else {
@@ -12279,7 +12278,8 @@ function applyWriteToRemoteDocuments(localStoreImpl, txn, batchResult, documentB
12279
12278
  // We use the commitVersion as the readTime rather than the
12280
12279
  // document's updateTime since the updateTime is not advanced
12281
12280
  // for updates that do not modify the underlying document.
12282
- documentBuffer.addEntry(doc, batchResult.commitVersion);
12281
+ doc.setReadTime(batchResult.commitVersion);
12282
+ documentBuffer.addEntry(doc);
12283
12283
  }
12284
12284
  }
12285
12285
  });
@@ -12380,14 +12380,14 @@ async function localStoreApplyBundledDocuments(localStore, bundleConverter, docu
12380
12380
  const localStoreImpl = debugCast(localStore);
12381
12381
  let documentKeys = documentKeySet();
12382
12382
  let documentMap = mutableDocumentMap();
12383
- let versionMap = documentVersionMap();
12384
12383
  for (const bundleDoc of documents) {
12385
12384
  const documentKey = bundleConverter.toDocumentKey(bundleDoc.metadata.name);
12386
12385
  if (bundleDoc.document) {
12387
12386
  documentKeys = documentKeys.add(documentKey);
12388
12387
  }
12389
- documentMap = documentMap.insert(documentKey, bundleConverter.toMutableDocument(bundleDoc));
12390
- versionMap = versionMap.insert(documentKey, bundleConverter.toSnapshotVersion(bundleDoc.metadata.readTime));
12388
+ const doc = bundleConverter.toMutableDocument(bundleDoc);
12389
+ doc.setReadTime(bundleConverter.toSnapshotVersion(bundleDoc.metadata.readTime));
12390
+ documentMap = documentMap.insert(documentKey, doc);
12391
12391
  }
12392
12392
  const documentBuffer = localStoreImpl.remoteDocuments.newChangeBuffer({
12393
12393
  trackRemovals: true // Make sure document removals show up in `getNewDocumentChanges()`
@@ -12396,7 +12396,7 @@ async function localStoreApplyBundledDocuments(localStore, bundleConverter, docu
12396
12396
  // they will not get garbage collected right away.
12397
12397
  const umbrellaTargetData = await localStoreAllocateTarget(localStoreImpl, umbrellaTarget(bundleName));
12398
12398
  return localStoreImpl.persistence.runTransaction('Apply bundle documents', 'readwrite', txn => {
12399
- return populateDocumentChangeBuffer(txn, documentBuffer, documentMap, SnapshotVersion.min(), versionMap)
12399
+ return populateDocumentChangeBuffer(txn, documentBuffer, documentMap)
12400
12400
  .next(changedDocs => {
12401
12401
  documentBuffer.apply(txn);
12402
12402
  return changedDocs;
@@ -12877,15 +12877,14 @@ class MemoryRemoteDocumentCacheImpl {
12877
12877
  * All calls of `addEntry` are required to go through the RemoteDocumentChangeBuffer
12878
12878
  * returned by `newChangeBuffer()`.
12879
12879
  */
12880
- addEntry(transaction, doc, readTime) {
12880
+ addEntry(transaction, doc) {
12881
12881
  const key = doc.key;
12882
12882
  const entry = this.docs.get(key);
12883
12883
  const previousSize = entry ? entry.size : 0;
12884
12884
  const currentSize = this.sizer(doc);
12885
12885
  this.docs = this.docs.insert(key, {
12886
12886
  document: doc.mutableCopy(),
12887
- size: currentSize,
12888
- readTime
12887
+ size: currentSize
12889
12888
  });
12890
12889
  this.size += currentSize - previousSize;
12891
12890
  return this.indexManager.addToCollectionParentIndex(transaction, key.path.popLast());
@@ -12926,11 +12925,11 @@ class MemoryRemoteDocumentCacheImpl {
12926
12925
  const prefix = new DocumentKey(query.path.child(''));
12927
12926
  const iterator = this.docs.getIteratorFrom(prefix);
12928
12927
  while (iterator.hasNext()) {
12929
- const { key, value: { document, readTime } } = iterator.getNext();
12928
+ const { key, value: { document } } = iterator.getNext();
12930
12929
  if (!query.path.isPrefixOf(key.path)) {
12931
12930
  break;
12932
12931
  }
12933
- if (readTime.compareTo(sinceReadTime) <= 0) {
12932
+ if (document.readTime.compareTo(sinceReadTime) <= 0) {
12934
12933
  continue;
12935
12934
  }
12936
12935
  if (!queryMatches(query, document)) {
@@ -12974,8 +12973,8 @@ class MemoryRemoteDocumentChangeBuffer extends RemoteDocumentChangeBuffer {
12974
12973
  applyChanges(transaction) {
12975
12974
  const promises = [];
12976
12975
  this.changes.forEach((key, doc) => {
12977
- if (doc.document.isValidDocument()) {
12978
- promises.push(this.documentCache.addEntry(transaction, doc.document, this.getReadTime(key)));
12976
+ if (doc.isValidDocument()) {
12977
+ promises.push(this.documentCache.addEntry(transaction, doc));
12979
12978
  }
12980
12979
  else {
12981
12980
  this.documentCache.removeEntry(key);
@@ -13288,7 +13287,7 @@ class MemoryEagerDelegate {
13288
13287
  const key = DocumentKey.fromPath(path);
13289
13288
  return this.isReferenced(txn, key).next(isReferenced => {
13290
13289
  if (!isReferenced) {
13291
- changeBuffer.removeEntry(key);
13290
+ changeBuffer.removeEntry(key, SnapshotVersion.min());
13292
13291
  }
13293
13292
  });
13294
13293
  }).next(() => {
@@ -17068,6 +17067,40 @@ const nested = {
17068
17067
  id: 2
17069
17068
  }
17070
17069
  }
17070
+ },
17071
+ methodSignature: {
17072
+ rule: "repeated",
17073
+ type: "string",
17074
+ id: 1051,
17075
+ extend: "google.protobuf.MethodOptions"
17076
+ },
17077
+ defaultHost: {
17078
+ type: "string",
17079
+ id: 1049,
17080
+ extend: "google.protobuf.ServiceOptions"
17081
+ },
17082
+ oauthScopes: {
17083
+ type: "string",
17084
+ id: 1050,
17085
+ extend: "google.protobuf.ServiceOptions"
17086
+ },
17087
+ fieldBehavior: {
17088
+ rule: "repeated",
17089
+ type: "google.api.FieldBehavior",
17090
+ id: 1052,
17091
+ extend: "google.protobuf.FieldOptions"
17092
+ },
17093
+ FieldBehavior: {
17094
+ values: {
17095
+ FIELD_BEHAVIOR_UNSPECIFIED: 0,
17096
+ OPTIONAL: 1,
17097
+ REQUIRED: 2,
17098
+ OUTPUT_ONLY: 3,
17099
+ INPUT_ONLY: 4,
17100
+ IMMUTABLE: 5,
17101
+ UNORDERED_LIST: 6,
17102
+ NON_EMPTY_DEFAULT: 7
17103
+ }
17071
17104
  }
17072
17105
  }
17073
17106
  },
@@ -20311,6 +20344,9 @@ async function syncEngineRejectListen(syncEngine, targetId, err) {
20311
20344
  // store to purge a document. However, it would be tricky to keep all of
20312
20345
  // the local store's invariants with another method.
20313
20346
  let documentUpdates = new SortedMap(DocumentKey.comparator);
20347
+ // TODO(b/217189216): This limbo document should ideally have a read time,
20348
+ // so that it is picked up by any read-time based scans. The backend,
20349
+ // however, does not send a read time for target removals.
20314
20350
  documentUpdates = documentUpdates.insert(limboKey, MutableDocument.newNoDocument(limboKey, SnapshotVersion.min()));
20315
20351
  const resolvedLimboDocuments = documentKeySet().add(limboKey);
20316
20352
  const event = new RemoteEvent(SnapshotVersion.min(),
@@ -21878,13 +21914,16 @@ class FirestoreClient {
21878
21914
  this.user = User.UNAUTHENTICATED;
21879
21915
  this.clientId = AutoId.newId();
21880
21916
  this.authCredentialListener = () => Promise.resolve();
21917
+ this.appCheckCredentialListener = () => Promise.resolve();
21881
21918
  this.authCredentials.start(asyncQueue, async (user) => {
21882
21919
  logDebug(LOG_TAG$2, 'Received user=', user.uid);
21883
21920
  await this.authCredentialListener(user);
21884
21921
  this.user = user;
21885
21922
  });
21886
- // Register an empty credentials change listener to activate token refresh.
21887
- this.appCheckCredentials.start(asyncQueue, () => Promise.resolve());
21923
+ this.appCheckCredentials.start(asyncQueue, newAppCheckToken => {
21924
+ logDebug(LOG_TAG$2, 'Received new app check token=', newAppCheckToken);
21925
+ return this.appCheckCredentialListener(newAppCheckToken, this.user);
21926
+ });
21888
21927
  }
21889
21928
  async getConfiguration() {
21890
21929
  return {
@@ -21900,6 +21939,9 @@ class FirestoreClient {
21900
21939
  setCredentialChangeListener(listener) {
21901
21940
  this.authCredentialListener = listener;
21902
21941
  }
21942
+ setAppCheckTokenChangeListener(listener) {
21943
+ this.appCheckCredentialListener = listener;
21944
+ }
21903
21945
  /**
21904
21946
  * Checks that the client has not been terminated. Ensures that other methods on
21905
21947
  * this class cannot be called after the client is terminated.
@@ -21961,6 +22003,7 @@ async function setOnlineComponentProvider(client, onlineComponentProvider) {
21961
22003
  // The CredentialChangeListener of the online component provider takes
21962
22004
  // precedence over the offline component provider.
21963
22005
  client.setCredentialChangeListener(user => remoteStoreHandleCredentialChange(onlineComponentProvider.remoteStore, user));
22006
+ client.setAppCheckTokenChangeListener((_, user) => remoteStoreHandleCredentialChange(onlineComponentProvider.remoteStore, user));
21964
22007
  client.onlineComponents = onlineComponentProvider;
21965
22008
  }
21966
22009
  async function ensureOfflineComponents(client) {
@@ -23513,13 +23556,13 @@ function terminate(firestore) {
23513
23556
  /**
23514
23557
  * Loads a Firestore bundle into the local cache.
23515
23558
  *
23516
- * @param firestore - The {@link Firestore} instance to load bundles for for.
23517
- * @param bundleData - An object representing the bundle to be loaded. Valid objects are
23518
- * `ArrayBuffer`, `ReadableStream<Uint8Array>` or `string`.
23559
+ * @param firestore - The {@link Firestore} instance to load bundles for.
23560
+ * @param bundleData - An object representing the bundle to be loaded. Valid
23561
+ * objects are `ArrayBuffer`, `ReadableStream<Uint8Array>` or `string`.
23519
23562
  *
23520
- * @returns
23521
- * A `LoadBundleTask` object, which notifies callers with progress updates, and completion
23522
- * or error events. It can be used as a `Promise<LoadBundleTaskProgress>`.
23563
+ * @returns A `LoadBundleTask` object, which notifies callers with progress
23564
+ * updates, and completion or error events. It can be used as a
23565
+ * `Promise<LoadBundleTaskProgress>`.
23523
23566
  */
23524
23567
  function loadBundle(firestore, bundleData) {
23525
23568
  firestore = cast(firestore, Firestore);
@@ -23529,11 +23572,16 @@ function loadBundle(firestore, bundleData) {
23529
23572
  return resultTask;
23530
23573
  }
23531
23574
  /**
23532
- * Reads a Firestore {@link Query} from local cache, identified by the given name.
23575
+ * Reads a Firestore {@link Query} from local cache, identified by the given
23576
+ * name.
23533
23577
  *
23534
23578
  * The named queries are packaged into bundles on the server side (along
23535
- * with resulting documents), and loaded to local cache using `loadBundle`. Once in local
23536
- * cache, use this method to extract a {@link Query} by name.
23579
+ * with resulting documents), and loaded to local cache using `loadBundle`. Once
23580
+ * in local cache, use this method to extract a {@link Query} by name.
23581
+ *
23582
+ * @param firestore - The {@link Firestore} instance to read the query from.
23583
+ * @param name - The name of the query.
23584
+ * @returns A `Promise` that is resolved with the Query or `null`.
23537
23585
  */
23538
23586
  function namedQuery(firestore, name) {
23539
23587
  firestore = cast(firestore, Firestore);
@@ -26223,6 +26271,190 @@ function writeBatch(firestore) {
26223
26271
  return new WriteBatch(firestore, mutations => executeWrite(firestore, mutations));
26224
26272
  }
26225
26273
 
26274
+ /**
26275
+ * @license
26276
+ * Copyright 2021 Google LLC
26277
+ *
26278
+ * Licensed under the Apache License, Version 2.0 (the "License");
26279
+ * you may not use this file except in compliance with the License.
26280
+ * You may obtain a copy of the License at
26281
+ *
26282
+ * http://www.apache.org/licenses/LICENSE-2.0
26283
+ *
26284
+ * Unless required by applicable law or agreed to in writing, software
26285
+ * distributed under the License is distributed on an "AS IS" BASIS,
26286
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
26287
+ * See the License for the specific language governing permissions and
26288
+ * limitations under the License.
26289
+ */
26290
+ /**
26291
+ * The initial mutation batch id for each index. Gets updated during index
26292
+ * backfill.
26293
+ */
26294
+ const INITIAL_LARGEST_BATCH_ID = -1;
26295
+ /**
26296
+ * The initial sequence number for each index. Gets updated during index
26297
+ * backfill.
26298
+ */
26299
+ const INITIAL_SEQUENCE_NUMBER = 0;
26300
+ /**
26301
+ * An index definition for field indexes in Firestore.
26302
+ *
26303
+ * Every index is associated with a collection. The definition contains a list
26304
+ * of fields and their index kind (which can be `ASCENDING`, `DESCENDING` or
26305
+ * `CONTAINS` for ArrayContains/ArrayContainsAny queries).
26306
+ *
26307
+ * Unlike the backend, the SDK does not differentiate between collection or
26308
+ * collection group-scoped indices. Every index can be used for both single
26309
+ * collection and collection group queries.
26310
+ */
26311
+ class FieldIndex {
26312
+ constructor(
26313
+ /**
26314
+ * The index ID. Returns -1 if the index ID is not available (e.g. the index
26315
+ * has not yet been persisted).
26316
+ */
26317
+ indexId,
26318
+ /** The collection ID this index applies to. */
26319
+ collectionGroup,
26320
+ /** The field segments for this index. */
26321
+ segments,
26322
+ /** Shows how up-to-date the index is for the current user. */
26323
+ indexState) {
26324
+ this.indexId = indexId;
26325
+ this.collectionGroup = collectionGroup;
26326
+ this.segments = segments;
26327
+ this.indexState = indexState;
26328
+ }
26329
+ }
26330
+ /** An ID for an index that has not yet been added to persistence. */
26331
+ FieldIndex.UNKNOWN_ID = -1;
26332
+ /** An index component consisting of field path and index type. */
26333
+ class IndexSegment {
26334
+ constructor(
26335
+ /** The field path of the component. */
26336
+ fieldPath,
26337
+ /** The fields sorting order. */
26338
+ kind) {
26339
+ this.fieldPath = fieldPath;
26340
+ this.kind = kind;
26341
+ }
26342
+ }
26343
+ /**
26344
+ * Stores the "high water mark" that indicates how updated the Index is for the
26345
+ * current user.
26346
+ */
26347
+ class IndexState {
26348
+ constructor(
26349
+ /**
26350
+ * Indicates when the index was last updated (relative to other indexes).
26351
+ */
26352
+ sequenceNumber,
26353
+ /** The the latest indexed read time, document and batch id. */
26354
+ offset) {
26355
+ this.sequenceNumber = sequenceNumber;
26356
+ this.offset = offset;
26357
+ }
26358
+ /** The state of an index that has not yet been backfilled. */
26359
+ static empty() {
26360
+ return new IndexState(INITIAL_SEQUENCE_NUMBER, IndexOffset.min());
26361
+ }
26362
+ }
26363
+ /**
26364
+ * Stores the latest read time, document and batch ID that were processed for an
26365
+ * index.
26366
+ */
26367
+ class IndexOffset {
26368
+ constructor(
26369
+ /**
26370
+ * The latest read time version that has been indexed by Firestore for this
26371
+ * field index.
26372
+ */
26373
+ readTime,
26374
+ /**
26375
+ * The key of the last document that was indexed for this query. Use
26376
+ * `DocumentKey.empty()` if no document has been indexed.
26377
+ */
26378
+ documentKey,
26379
+ /*
26380
+ * The largest mutation batch id that's been processed by Firestore.
26381
+ */
26382
+ largestBatchId) {
26383
+ this.readTime = readTime;
26384
+ this.documentKey = documentKey;
26385
+ this.largestBatchId = largestBatchId;
26386
+ }
26387
+ /** The state of an index that has not yet been backfilled. */
26388
+ static min() {
26389
+ return new IndexOffset(SnapshotVersion.min(), DocumentKey.empty(), INITIAL_LARGEST_BATCH_ID);
26390
+ }
26391
+ }
26392
+
26393
+ /**
26394
+ * @license
26395
+ * Copyright 2021 Google LLC
26396
+ *
26397
+ * Licensed under the Apache License, Version 2.0 (the "License");
26398
+ * you may not use this file except in compliance with the License.
26399
+ * You may obtain a copy of the License at
26400
+ *
26401
+ * http://www.apache.org/licenses/LICENSE-2.0
26402
+ *
26403
+ * Unless required by applicable law or agreed to in writing, software
26404
+ * distributed under the License is distributed on an "AS IS" BASIS,
26405
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
26406
+ * See the License for the specific language governing permissions and
26407
+ * limitations under the License.
26408
+ */
26409
+ function setIndexConfiguration(firestore, jsonOrConfiguration) {
26410
+ firestore = cast(firestore, Firestore);
26411
+ ensureFirestoreConfigured(firestore);
26412
+ const indexConfiguration = typeof jsonOrConfiguration === 'string'
26413
+ ? tryParseJson(jsonOrConfiguration)
26414
+ : jsonOrConfiguration;
26415
+ const parsedIndexes = [];
26416
+ // PORTING NOTE: We don't return an error if the user has not enabled
26417
+ // persistence since `enableIndexeddbPersistence()` can fail on the Web.
26418
+ if (Array.isArray(indexConfiguration.indexes)) {
26419
+ for (const index of indexConfiguration.indexes) {
26420
+ const collectionGroup = tryGetString(index, 'collectionGroup');
26421
+ const segments = [];
26422
+ if (Array.isArray(index.fields)) {
26423
+ for (const field of index.fields) {
26424
+ const fieldPathString = tryGetString(field, 'fieldPath');
26425
+ const fieldPath = fieldPathFromDotSeparatedString('setIndexConfiguration', fieldPathString);
26426
+ if (field.arrayConfig === 'CONTAINS') {
26427
+ segments.push(new IndexSegment(fieldPath, 2 /* CONTAINS */));
26428
+ }
26429
+ else if (field.order === 'ASCENDING') {
26430
+ segments.push(new IndexSegment(fieldPath, 0 /* ASCENDING */));
26431
+ }
26432
+ else if (field.order === 'DESCENDING') {
26433
+ segments.push(new IndexSegment(fieldPath, 1 /* DESCENDING */));
26434
+ }
26435
+ }
26436
+ }
26437
+ parsedIndexes.push(new FieldIndex(FieldIndex.UNKNOWN_ID, collectionGroup, segments, IndexState.empty()));
26438
+ }
26439
+ }
26440
+ // TODO(indexing): Configure indexes
26441
+ return Promise.resolve();
26442
+ }
26443
+ function tryParseJson(json) {
26444
+ try {
26445
+ return JSON.parse(json);
26446
+ }
26447
+ catch (e) {
26448
+ throw new FirestoreError(Code.INVALID_ARGUMENT, 'Failed to parse JSON:' + e.message);
26449
+ }
26450
+ }
26451
+ function tryGetString(data, property) {
26452
+ if (typeof data[property] !== 'string') {
26453
+ throw new FirestoreError(Code.INVALID_ARGUMENT, 'Missing string value for: ' + property);
26454
+ }
26455
+ return data[property];
26456
+ }
26457
+
26226
26458
  /**
26227
26459
  * @license
26228
26460
  * Copyright 2021 Google LLC
@@ -26241,5 +26473,5 @@ function writeBatch(firestore) {
26241
26473
  */
26242
26474
  registerFirestore('node');
26243
26475
 
26244
- export { AbstractUserDataWriter, Bytes, CACHE_SIZE_UNLIMITED, CollectionReference, DocumentReference, DocumentSnapshot, FieldPath, FieldValue, Firestore, FirestoreError, GeoPoint, LoadBundleTask, Query, QueryConstraint, QueryDocumentSnapshot, QuerySnapshot, SnapshotMetadata, Timestamp, Transaction, WriteBatch, DatabaseId as _DatabaseId, DocumentKey as _DocumentKey, EmptyAppCheckTokenProvider as _EmptyAppCheckTokenProvider, EmptyAuthCredentialsProvider as _EmptyAuthCredentialsProvider, FieldPath$1 as _FieldPath, cast as _cast, debugAssert as _debugAssert, isBase64Available as _isBase64Available, logWarn as _logWarn, validateIsNotUsedTogether as _validateIsNotUsedTogether, addDoc, arrayRemove, arrayUnion, clearIndexedDbPersistence, collection, collectionGroup, connectFirestoreEmulator, deleteDoc, deleteField, disableNetwork, doc, documentId, enableIndexedDbPersistence, enableMultiTabIndexedDbPersistence, enableNetwork, endAt, endBefore, ensureFirestoreConfigured, executeWrite, getDoc, getDocFromCache, getDocFromServer, getDocs, getDocsFromCache, getDocsFromServer, getFirestore, increment, initializeFirestore, limit, limitToLast, loadBundle, namedQuery, onSnapshot, onSnapshotsInSync, orderBy, query, queryEqual, refEqual, runTransaction, serverTimestamp, setDoc, setLogLevel, snapshotEqual, startAfter, startAt, terminate, updateDoc, waitForPendingWrites, where, writeBatch };
26476
+ export { AbstractUserDataWriter, Bytes, CACHE_SIZE_UNLIMITED, CollectionReference, DocumentReference, DocumentSnapshot, FieldPath, FieldValue, Firestore, FirestoreError, GeoPoint, LoadBundleTask, Query, QueryConstraint, QueryDocumentSnapshot, QuerySnapshot, SnapshotMetadata, Timestamp, Transaction, WriteBatch, DatabaseId as _DatabaseId, DocumentKey as _DocumentKey, EmptyAppCheckTokenProvider as _EmptyAppCheckTokenProvider, EmptyAuthCredentialsProvider as _EmptyAuthCredentialsProvider, FieldPath$1 as _FieldPath, cast as _cast, debugAssert as _debugAssert, isBase64Available as _isBase64Available, logWarn as _logWarn, setIndexConfiguration as _setIndexConfiguration, validateIsNotUsedTogether as _validateIsNotUsedTogether, addDoc, arrayRemove, arrayUnion, clearIndexedDbPersistence, collection, collectionGroup, connectFirestoreEmulator, deleteDoc, deleteField, disableNetwork, doc, documentId, enableIndexedDbPersistence, enableMultiTabIndexedDbPersistence, enableNetwork, endAt, endBefore, ensureFirestoreConfigured, executeWrite, getDoc, getDocFromCache, getDocFromServer, getDocs, getDocsFromCache, getDocsFromServer, getFirestore, increment, initializeFirestore, limit, limitToLast, loadBundle, namedQuery, onSnapshot, onSnapshotsInSync, orderBy, query, queryEqual, refEqual, runTransaction, serverTimestamp, setDoc, setLogLevel, snapshotEqual, startAfter, startAt, terminate, updateDoc, waitForPendingWrites, where, writeBatch };
26245
26477
  //# sourceMappingURL=index.node.mjs.map