@firebase/firestore 3.4.4-canary.f5ac47fb1 → 3.4.5

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 (151) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/firestore/src/api/credentials.d.ts +1 -0
  3. package/dist/firestore/src/index/index_byte_encoder.d.ts +18 -1
  4. package/dist/firestore/src/index/index_entry.d.ts +26 -0
  5. package/dist/firestore/src/local/document_overlay_cache.d.ts +72 -0
  6. package/dist/firestore/src/local/indexeddb_document_overlay_cache.d.ts +45 -0
  7. package/dist/firestore/src/local/indexeddb_index_manager.d.ts +29 -2
  8. package/dist/firestore/src/local/indexeddb_persistence.d.ts +6 -4
  9. package/dist/firestore/src/local/indexeddb_remote_document_cache.d.ts +2 -8
  10. package/dist/firestore/src/local/indexeddb_schema.d.ts +83 -9
  11. package/dist/firestore/src/local/local_documents_view.d.ts +0 -1
  12. package/dist/firestore/src/local/local_serializer.d.ts +18 -2
  13. package/dist/firestore/src/local/memory_document_overlay_cache.d.ts +37 -0
  14. package/dist/firestore/src/local/memory_persistence.d.ts +6 -2
  15. package/dist/firestore/src/local/memory_remote_document_cache.d.ts +1 -3
  16. package/dist/firestore/src/local/persistence.d.ts +8 -2
  17. package/dist/firestore/src/local/remote_document_cache.d.ts +7 -9
  18. package/dist/firestore/src/model/document_key.d.ts +5 -0
  19. package/dist/firestore/src/model/field_index.d.ts +2 -2
  20. package/dist/firestore/src/model/overlay.d.ts +32 -0
  21. package/dist/firestore/src/model/target_index_matcher.d.ts +70 -0
  22. package/dist/firestore/src/platform/node/grpc_connection.d.ts +2 -2
  23. package/dist/firestore/src/platform/node/load_protos.d.ts +2 -2
  24. package/dist/firestore/src/util/sorted_set.d.ts +18 -0
  25. package/dist/firestore/test/unit/local/counting_query_engine.d.ts +3 -3
  26. package/dist/firestore/test/unit/local/document_overlay_cache.test.d.ts +1 -0
  27. package/dist/firestore/test/unit/local/persistence_test_helpers.d.ts +1 -0
  28. package/dist/firestore/test/unit/local/test_document_overlay_cache.d.ts +38 -0
  29. package/dist/firestore/test/unit/local/test_index_manager.d.ts +11 -0
  30. package/dist/firestore/test/unit/local/test_remote_document_cache.d.ts +4 -2
  31. package/dist/firestore/test/unit/local/test_remote_document_change_buffer.d.ts +1 -1
  32. package/dist/firestore/test/unit/model/target_index_matcher.test.d.ts +17 -0
  33. package/dist/index.esm2017.js +4367 -3517
  34. package/dist/index.esm2017.js.map +1 -1
  35. package/dist/index.esm5.js +4226 -3437
  36. package/dist/index.esm5.js.map +1 -1
  37. package/dist/index.node.cjs.js +1519 -242
  38. package/dist/index.node.cjs.js.map +1 -1
  39. package/dist/index.node.mjs +1501 -245
  40. package/dist/index.node.mjs.map +1 -1
  41. package/dist/index.rn.js +4355 -3509
  42. package/dist/index.rn.js.map +1 -1
  43. package/dist/internal.d.ts +84 -12
  44. package/dist/lite/firestore/src/api/credentials.d.ts +1 -0
  45. package/dist/lite/firestore/src/index/index_byte_encoder.d.ts +18 -1
  46. package/dist/lite/firestore/src/index/index_entry.d.ts +26 -0
  47. package/dist/lite/firestore/src/local/document_overlay_cache.d.ts +72 -0
  48. package/dist/lite/firestore/src/local/indexeddb_document_overlay_cache.d.ts +45 -0
  49. package/dist/lite/firestore/src/local/indexeddb_index_manager.d.ts +29 -2
  50. package/dist/lite/firestore/src/local/indexeddb_persistence.d.ts +6 -4
  51. package/dist/lite/firestore/src/local/indexeddb_remote_document_cache.d.ts +2 -8
  52. package/dist/lite/firestore/src/local/indexeddb_schema.d.ts +83 -9
  53. package/dist/lite/firestore/src/local/local_documents_view.d.ts +0 -1
  54. package/dist/lite/firestore/src/local/local_serializer.d.ts +18 -2
  55. package/dist/lite/firestore/src/local/memory_document_overlay_cache.d.ts +37 -0
  56. package/dist/lite/firestore/src/local/memory_persistence.d.ts +6 -2
  57. package/dist/lite/firestore/src/local/memory_remote_document_cache.d.ts +1 -3
  58. package/dist/lite/firestore/src/local/persistence.d.ts +8 -2
  59. package/dist/lite/firestore/src/local/remote_document_cache.d.ts +7 -9
  60. package/dist/lite/firestore/src/model/document_key.d.ts +5 -0
  61. package/dist/lite/firestore/src/model/field_index.d.ts +2 -2
  62. package/dist/lite/firestore/src/model/overlay.d.ts +32 -0
  63. package/dist/lite/firestore/src/model/target_index_matcher.d.ts +70 -0
  64. package/dist/lite/firestore/src/platform/node/grpc_connection.d.ts +2 -2
  65. package/dist/lite/firestore/src/platform/node/load_protos.d.ts +2 -2
  66. package/dist/lite/firestore/src/util/sorted_set.d.ts +18 -0
  67. package/dist/lite/firestore/test/unit/local/counting_query_engine.d.ts +3 -3
  68. package/dist/lite/firestore/test/unit/local/document_overlay_cache.test.d.ts +1 -0
  69. package/dist/lite/firestore/test/unit/local/persistence_test_helpers.d.ts +1 -0
  70. package/dist/lite/firestore/test/unit/local/test_document_overlay_cache.d.ts +38 -0
  71. package/dist/lite/firestore/test/unit/local/test_index_manager.d.ts +11 -0
  72. package/dist/lite/firestore/test/unit/local/test_remote_document_cache.d.ts +4 -2
  73. package/dist/lite/firestore/test/unit/local/test_remote_document_change_buffer.d.ts +1 -1
  74. package/dist/lite/firestore/test/unit/model/target_index_matcher.test.d.ts +17 -0
  75. package/dist/lite/index.browser.esm2017.js +1121 -1112
  76. package/dist/lite/index.browser.esm2017.js.map +1 -1
  77. package/dist/lite/index.browser.esm5.js +60 -48
  78. package/dist/lite/index.browser.esm5.js.map +1 -1
  79. package/dist/lite/index.node.cjs.js +13 -2
  80. package/dist/lite/index.node.cjs.js.map +1 -1
  81. package/dist/lite/index.node.mjs +13 -2
  82. package/dist/lite/index.node.mjs.map +1 -1
  83. package/dist/lite/index.rn.esm2017.js +46 -37
  84. package/dist/lite/index.rn.esm2017.js.map +1 -1
  85. package/dist/lite/internal.d.ts +5 -0
  86. package/dist/lite/packages/firestore/dist/lite/index.browser.esm2017.d.ts +112 -112
  87. package/dist/lite/packages/firestore/src/api/credentials.d.ts +1 -0
  88. package/dist/lite/packages/firestore/src/index/index_byte_encoder.d.ts +18 -1
  89. package/dist/lite/packages/firestore/src/index/index_entry.d.ts +26 -0
  90. package/dist/lite/packages/firestore/src/local/document_overlay_cache.d.ts +72 -0
  91. package/dist/lite/packages/firestore/src/local/indexeddb_document_overlay_cache.d.ts +45 -0
  92. package/dist/lite/packages/firestore/src/local/indexeddb_index_manager.d.ts +29 -2
  93. package/dist/lite/packages/firestore/src/local/indexeddb_persistence.d.ts +6 -4
  94. package/dist/lite/packages/firestore/src/local/indexeddb_remote_document_cache.d.ts +2 -8
  95. package/dist/lite/packages/firestore/src/local/indexeddb_schema.d.ts +83 -9
  96. package/dist/lite/packages/firestore/src/local/local_documents_view.d.ts +0 -1
  97. package/dist/lite/packages/firestore/src/local/local_serializer.d.ts +18 -2
  98. package/dist/lite/packages/firestore/src/local/memory_document_overlay_cache.d.ts +37 -0
  99. package/dist/lite/packages/firestore/src/local/memory_persistence.d.ts +6 -2
  100. package/dist/lite/packages/firestore/src/local/memory_remote_document_cache.d.ts +1 -3
  101. package/dist/lite/packages/firestore/src/local/persistence.d.ts +8 -2
  102. package/dist/lite/packages/firestore/src/local/remote_document_cache.d.ts +7 -9
  103. package/dist/lite/packages/firestore/src/model/document_key.d.ts +5 -0
  104. package/dist/lite/packages/firestore/src/model/field_index.d.ts +2 -2
  105. package/dist/lite/packages/firestore/src/model/overlay.d.ts +32 -0
  106. package/dist/lite/packages/firestore/src/model/target_index_matcher.d.ts +70 -0
  107. package/dist/lite/packages/firestore/src/platform/node/grpc_connection.d.ts +2 -2
  108. package/dist/lite/packages/firestore/src/platform/node/load_protos.d.ts +2 -2
  109. package/dist/lite/packages/firestore/src/util/sorted_set.d.ts +18 -0
  110. package/dist/lite/packages/firestore/test/unit/local/counting_query_engine.d.ts +3 -3
  111. package/dist/lite/packages/firestore/test/unit/local/document_overlay_cache.test.d.ts +1 -0
  112. package/dist/lite/packages/firestore/test/unit/local/persistence_test_helpers.d.ts +1 -0
  113. package/dist/lite/packages/firestore/test/unit/local/test_document_overlay_cache.d.ts +38 -0
  114. package/dist/lite/packages/firestore/test/unit/local/test_index_manager.d.ts +11 -0
  115. package/dist/lite/packages/firestore/test/unit/local/test_remote_document_cache.d.ts +4 -2
  116. package/dist/lite/packages/firestore/test/unit/local/test_remote_document_change_buffer.d.ts +1 -1
  117. package/dist/lite/packages/firestore/test/unit/model/target_index_matcher.test.d.ts +17 -0
  118. package/dist/packages/firestore/dist/index.esm2017.d.ts +187 -184
  119. package/dist/packages/firestore/src/api/credentials.d.ts +1 -0
  120. package/dist/packages/firestore/src/index/index_byte_encoder.d.ts +18 -1
  121. package/dist/packages/firestore/src/index/index_entry.d.ts +26 -0
  122. package/dist/packages/firestore/src/local/document_overlay_cache.d.ts +72 -0
  123. package/dist/packages/firestore/src/local/indexeddb_document_overlay_cache.d.ts +45 -0
  124. package/dist/packages/firestore/src/local/indexeddb_index_manager.d.ts +29 -2
  125. package/dist/packages/firestore/src/local/indexeddb_persistence.d.ts +6 -4
  126. package/dist/packages/firestore/src/local/indexeddb_remote_document_cache.d.ts +2 -8
  127. package/dist/packages/firestore/src/local/indexeddb_schema.d.ts +83 -9
  128. package/dist/packages/firestore/src/local/local_documents_view.d.ts +0 -1
  129. package/dist/packages/firestore/src/local/local_serializer.d.ts +18 -2
  130. package/dist/packages/firestore/src/local/memory_document_overlay_cache.d.ts +37 -0
  131. package/dist/packages/firestore/src/local/memory_persistence.d.ts +6 -2
  132. package/dist/packages/firestore/src/local/memory_remote_document_cache.d.ts +1 -3
  133. package/dist/packages/firestore/src/local/persistence.d.ts +8 -2
  134. package/dist/packages/firestore/src/local/remote_document_cache.d.ts +7 -9
  135. package/dist/packages/firestore/src/model/document_key.d.ts +5 -0
  136. package/dist/packages/firestore/src/model/field_index.d.ts +2 -2
  137. package/dist/packages/firestore/src/model/overlay.d.ts +32 -0
  138. package/dist/packages/firestore/src/model/target_index_matcher.d.ts +70 -0
  139. package/dist/packages/firestore/src/platform/node/grpc_connection.d.ts +2 -2
  140. package/dist/packages/firestore/src/platform/node/load_protos.d.ts +2 -2
  141. package/dist/packages/firestore/src/util/sorted_set.d.ts +18 -0
  142. package/dist/packages/firestore/test/unit/local/counting_query_engine.d.ts +3 -3
  143. package/dist/packages/firestore/test/unit/local/document_overlay_cache.test.d.ts +1 -0
  144. package/dist/packages/firestore/test/unit/local/persistence_test_helpers.d.ts +1 -0
  145. package/dist/packages/firestore/test/unit/local/test_document_overlay_cache.d.ts +38 -0
  146. package/dist/packages/firestore/test/unit/local/test_index_manager.d.ts +11 -0
  147. package/dist/packages/firestore/test/unit/local/test_remote_document_cache.d.ts +4 -2
  148. package/dist/packages/firestore/test/unit/local/test_remote_document_change_buffer.d.ts +1 -1
  149. package/dist/packages/firestore/test/unit/model/target_index_matcher.test.d.ts +17 -0
  150. package/dist/private.d.ts +79 -12
  151. package/package.json +9 -9
@@ -938,8 +938,13 @@ export declare class _DocumentKey {
938
938
  static fromPath(path: string): _DocumentKey;
939
939
  static fromName(name: string): _DocumentKey;
940
940
  static empty(): _DocumentKey;
941
+ get collectionGroup(): string;
941
942
  /** Returns true if the document is in the specified collectionId. */
942
943
  hasCollectionId(collectionId: string): boolean;
944
+ /** Returns the collection group (i.e. the name of the parent collection) for this key. */
945
+ getCollectionGroup(): string;
946
+ /** Returns the fully qualified path to the parent collection. */
947
+ getCollectionPath(): _ResourcePath;
943
948
  isEqual(other: _DocumentKey | null): boolean;
944
949
  toString(): string;
945
950
  static comparator(k1: _DocumentKey, k2: _DocumentKey): number;
@@ -957,6 +962,56 @@ declare type DocumentKeySet = SortedSet<_DocumentKey>;
957
962
 
958
963
  declare type DocumentMap = SortedMap<_DocumentKey, Document_2>;
959
964
 
965
+ /**
966
+ * Provides methods to read and write document overlays.
967
+ *
968
+ * An overlay is a saved mutation, that gives a local view of a document when
969
+ * applied to the remote version of the document.
970
+ *
971
+ * Each overlay stores the largest batch ID that is included in the overlay,
972
+ * which allows us to remove the overlay once all batches leading up to it have
973
+ * been acknowledged.
974
+ */
975
+ declare interface DocumentOverlayCache {
976
+ /**
977
+ * Gets the saved overlay mutation for the given document key.
978
+ * Returns null if there is no overlay for that key.
979
+ */
980
+ getOverlay(transaction: PersistenceTransaction, key: _DocumentKey): PersistencePromise<Overlay | null>;
981
+ /**
982
+ * Saves the given document mutation map to persistence as overlays.
983
+ * All overlays will have their largest batch id set to `largestBatchId`.
984
+ */
985
+ saveOverlays(transaction: PersistenceTransaction, largestBatchId: number, overlays: Map<_DocumentKey, Mutation>): PersistencePromise<void>;
986
+ /** Removes overlays for the given document keys and batch ID. */
987
+ removeOverlaysForBatchId(transaction: PersistenceTransaction, documentKeys: DocumentKeySet, batchId: number): PersistencePromise<void>;
988
+ /**
989
+ * Returns all saved overlays for the given collection.
990
+ *
991
+ * @param transaction - The persistence transaction to use for this operation.
992
+ * @param collection - The collection path to get the overlays for.
993
+ * @param sinceBatchId - The minimum batch ID to filter by (exclusive).
994
+ * Only overlays that contain a change past `sinceBatchId` are returned.
995
+ * @returns Mapping of each document key in the collection to its overlay.
996
+ */
997
+ getOverlaysForCollection(transaction: PersistenceTransaction, collection: _ResourcePath, sinceBatchId: number): PersistencePromise<Map<_DocumentKey, Overlay>>;
998
+ /**
999
+ * Returns `count` overlays with a batch ID higher than `sinceBatchId` for the
1000
+ * provided collection group, processed by ascending batch ID. The method
1001
+ * always returns all overlays for a batch even if the last batch contains
1002
+ * more documents than the remaining limit.
1003
+ *
1004
+ * @param transaction - The persistence transaction used for this operation.
1005
+ * @param collectionGroup - The collection group to get the overlays for.
1006
+ * @param sinceBatchId - The minimum batch ID to filter by (exclusive).
1007
+ * Only overlays that contain a change past `sinceBatchId` are returned.
1008
+ * @param count - The number of overlays to return. Can be exceeded if the last
1009
+ * batch contains more entries.
1010
+ * @return Mapping of each document key in the collection group to its overlay.
1011
+ */
1012
+ getOverlaysForCollectionGroup(transaction: PersistenceTransaction, collectionGroup: string, sinceBatchId: number, count: number): PersistencePromise<Map<_DocumentKey, Overlay>>;
1013
+ }
1014
+
960
1015
  /**
961
1016
  * A `DocumentReference` refers to a document location in a Firestore database
962
1017
  * and can be used to write, read, or listen to the location. The document at
@@ -1343,7 +1398,7 @@ declare class FieldIndex {
1343
1398
  /** The collection ID this index applies to. */
1344
1399
  readonly collectionGroup: string;
1345
1400
  /** The field segments for this index. */
1346
- readonly segments: IndexSegment[];
1401
+ readonly fields: IndexSegment[];
1347
1402
  /** Shows how up-to-date the index is for the current user. */
1348
1403
  readonly indexState: IndexState_2;
1349
1404
  /** An ID for an index that has not yet been added to persistence. */
@@ -1357,7 +1412,7 @@ declare class FieldIndex {
1357
1412
  /** The collection ID this index applies to. */
1358
1413
  collectionGroup: string,
1359
1414
  /** The field segments for this index. */
1360
- segments: IndexSegment[],
1415
+ fields: IndexSegment[],
1361
1416
  /** Shows how up-to-date the index is for the current user. */
1362
1417
  indexState: IndexState_2);
1363
1418
  }
@@ -3573,6 +3628,21 @@ export declare type OrderByDirection = 'desc' | 'asc';
3573
3628
 
3574
3629
  declare type OrderDirection = 'DIRECTION_UNSPECIFIED' | 'ASCENDING' | 'DESCENDING';
3575
3630
 
3631
+ /**
3632
+ * Representation of an overlay computed by Firestore.
3633
+ *
3634
+ * Holds information about a mutation and the largest batch id in Firestore when
3635
+ * the mutation was created.
3636
+ */
3637
+ declare class Overlay {
3638
+ readonly largestBatchId: number;
3639
+ readonly mutation: Mutation;
3640
+ constructor(largestBatchId: number, mutation: Mutation);
3641
+ getKey(): _DocumentKey;
3642
+ isEqual(other: Overlay | null): boolean;
3643
+ toString(): string;
3644
+ }
3645
+
3576
3646
  declare interface ParseContext {
3577
3647
  readonly databaseId: _DatabaseId;
3578
3648
  readonly ignoreUndefinedProperties: boolean;
@@ -3676,7 +3746,7 @@ declare interface Persistence {
3676
3746
  * extent possible (e.g. in the case of uid switching from
3677
3747
  * sally=&gt;jack=&gt;sally, sally's mutation queue will be preserved).
3678
3748
  */
3679
- getMutationQueue(user: User): MutationQueue;
3749
+ getMutationQueue(user: User, indexManager: IndexManager): MutationQueue;
3680
3750
  /**
3681
3751
  * Returns a TargetCache representing the persisted cache of targets.
3682
3752
  *
@@ -3709,7 +3779,12 @@ declare interface Persistence {
3709
3779
  * this is called. In particular, the memory-backed implementation does this
3710
3780
  * to emulate the persisted implementation to the extent possible.
3711
3781
  */
3712
- getIndexManager(): IndexManager;
3782
+ getIndexManager(user: User): IndexManager;
3783
+ /**
3784
+ * Returns a DocumentOverlayCache representing the documents that are mutated
3785
+ * locally.
3786
+ */
3787
+ getDocumentOverlayCache(user: User): DocumentOverlayCache;
3713
3788
  /**
3714
3789
  * Performs an operation inside a persistence transaction. Any reads or writes
3715
3790
  * against persistence must be performed within a transaction. Writes will be
@@ -4120,6 +4195,8 @@ declare type Rejector = (error: Error) => void;
4120
4195
  * documents that are known to not exist.
4121
4196
  */
4122
4197
  declare interface RemoteDocumentCache {
4198
+ /** Sets the index manager to use for managing the collectionGroup index. */
4199
+ setIndexManager(indexManager: IndexManager): void;
4123
4200
  /**
4124
4201
  * Looks up an entry in the cache.
4125
4202
  *
@@ -4137,19 +4214,14 @@ declare interface RemoteDocumentCache {
4137
4214
  */
4138
4215
  getEntries(transaction: PersistenceTransaction, documentKeys: DocumentKeySet): PersistencePromise<MutableDocumentMap>;
4139
4216
  /**
4140
- * Executes a query against the cached Document entries.
4141
- *
4142
- * Implementations may return extra documents if convenient. The results
4143
- * should be re-filtered by the consumer before presenting them to the user.
4144
- *
4145
- * Cached NoDocument entries have no bearing on query results.
4217
+ * Returns the documents from the provided collection.
4146
4218
  *
4147
- * @param query - The query to match documents against.
4219
+ * @param collection - The collection to read.
4148
4220
  * @param sinceReadTime - If not set to SnapshotVersion.min(), return only
4149
4221
  * documents that have been read since this snapshot version (exclusive).
4150
4222
  * @returns The set of matching documents.
4151
4223
  */
4152
- getDocumentsMatchingQuery(transaction: PersistenceTransaction, query: Query_2, sinceReadTime: SnapshotVersion): PersistencePromise<MutableDocumentMap>;
4224
+ getAll(transaction: PersistenceTransaction, collection: _ResourcePath, sinceReadTime: SnapshotVersion): PersistencePromise<MutableDocumentMap>;
4153
4225
  /**
4154
4226
  * Provides access to add or update the contents of the cache. The buffer
4155
4227
  * handles proper size accounting for the change.
@@ -176,6 +176,7 @@ export declare class FirebaseAppCheckTokenProvider implements CredentialsProvide
176
176
  private tokenListener;
177
177
  private forceRefresh;
178
178
  private appCheck;
179
+ private latestAppCheckToken;
179
180
  constructor(appCheckProvider: Provider<AppCheckInternalComponentName>);
180
181
  start(asyncQueue: AsyncQueue, changeListener: CredentialChangeListener<string>): void;
181
182
  getToken(): Promise<Token | null>;
@@ -1,3 +1,20 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2021 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { IndexKind } from '../model/field_index';
1
18
  import { DirectionalIndexByteEncoder } from './directional_index_byte_encoder';
2
19
  /**
3
20
  * Implements `DirectionalIndexByteEncoder` using `OrderedCodeWriter` for the
@@ -8,7 +25,7 @@ export declare class IndexByteEncoder {
8
25
  private ascending;
9
26
  private descending;
10
27
  seed(encodedBytes: Uint8Array): void;
11
- forKind(kind: 'asc' | 'desc'): DirectionalIndexByteEncoder;
28
+ forKind(kind: IndexKind): DirectionalIndexByteEncoder;
12
29
  encodedBytes(): Uint8Array;
13
30
  reset(): void;
14
31
  }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { DocumentKey } from '../model/document_key';
18
+ /** Represents an index entry saved by the SDK in persisted storage. */
19
+ export declare class IndexEntry {
20
+ readonly indexId: number;
21
+ readonly documentKey: DocumentKey;
22
+ readonly arrayValue: Uint8Array;
23
+ readonly directionalValue: Uint8Array;
24
+ constructor(indexId: number, documentKey: DocumentKey, arrayValue: Uint8Array, directionalValue: Uint8Array);
25
+ }
26
+ export declare function indexEntryComparator(left: IndexEntry, right: IndexEntry): number;
@@ -0,0 +1,72 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { DocumentKeySet } from '../model/collections';
18
+ import { DocumentKey } from '../model/document_key';
19
+ import { Mutation } from '../model/mutation';
20
+ import { Overlay } from '../model/overlay';
21
+ import { ResourcePath } from '../model/path';
22
+ import { PersistencePromise } from './persistence_promise';
23
+ import { PersistenceTransaction } from './persistence_transaction';
24
+ /**
25
+ * Provides methods to read and write document overlays.
26
+ *
27
+ * An overlay is a saved mutation, that gives a local view of a document when
28
+ * applied to the remote version of the document.
29
+ *
30
+ * Each overlay stores the largest batch ID that is included in the overlay,
31
+ * which allows us to remove the overlay once all batches leading up to it have
32
+ * been acknowledged.
33
+ */
34
+ export interface DocumentOverlayCache {
35
+ /**
36
+ * Gets the saved overlay mutation for the given document key.
37
+ * Returns null if there is no overlay for that key.
38
+ */
39
+ getOverlay(transaction: PersistenceTransaction, key: DocumentKey): PersistencePromise<Overlay | null>;
40
+ /**
41
+ * Saves the given document mutation map to persistence as overlays.
42
+ * All overlays will have their largest batch id set to `largestBatchId`.
43
+ */
44
+ saveOverlays(transaction: PersistenceTransaction, largestBatchId: number, overlays: Map<DocumentKey, Mutation>): PersistencePromise<void>;
45
+ /** Removes overlays for the given document keys and batch ID. */
46
+ removeOverlaysForBatchId(transaction: PersistenceTransaction, documentKeys: DocumentKeySet, batchId: number): PersistencePromise<void>;
47
+ /**
48
+ * Returns all saved overlays for the given collection.
49
+ *
50
+ * @param transaction - The persistence transaction to use for this operation.
51
+ * @param collection - The collection path to get the overlays for.
52
+ * @param sinceBatchId - The minimum batch ID to filter by (exclusive).
53
+ * Only overlays that contain a change past `sinceBatchId` are returned.
54
+ * @returns Mapping of each document key in the collection to its overlay.
55
+ */
56
+ getOverlaysForCollection(transaction: PersistenceTransaction, collection: ResourcePath, sinceBatchId: number): PersistencePromise<Map<DocumentKey, Overlay>>;
57
+ /**
58
+ * Returns `count` overlays with a batch ID higher than `sinceBatchId` for the
59
+ * provided collection group, processed by ascending batch ID. The method
60
+ * always returns all overlays for a batch even if the last batch contains
61
+ * more documents than the remaining limit.
62
+ *
63
+ * @param transaction - The persistence transaction used for this operation.
64
+ * @param collectionGroup - The collection group to get the overlays for.
65
+ * @param sinceBatchId - The minimum batch ID to filter by (exclusive).
66
+ * Only overlays that contain a change past `sinceBatchId` are returned.
67
+ * @param count - The number of overlays to return. Can be exceeded if the last
68
+ * batch contains more entries.
69
+ * @return Mapping of each document key in the collection group to its overlay.
70
+ */
71
+ getOverlaysForCollectionGroup(transaction: PersistenceTransaction, collectionGroup: string, sinceBatchId: number, count: number): PersistencePromise<Map<DocumentKey, Overlay>>;
72
+ }
@@ -0,0 +1,45 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { User } from '../auth/user';
18
+ import { DocumentKeySet } from '../model/collections';
19
+ import { DocumentKey } from '../model/document_key';
20
+ import { Mutation } from '../model/mutation';
21
+ import { Overlay } from '../model/overlay';
22
+ import { ResourcePath } from '../model/path';
23
+ import { DocumentOverlayCache } from './document_overlay_cache';
24
+ import { LocalSerializer } from './local_serializer';
25
+ import { PersistencePromise } from './persistence_promise';
26
+ import { PersistenceTransaction } from './persistence_transaction';
27
+ /**
28
+ * Implementation of DocumentOverlayCache using IndexedDb.
29
+ */
30
+ export declare class IndexedDbDocumentOverlayCache implements DocumentOverlayCache {
31
+ private readonly serializer;
32
+ private readonly userId;
33
+ /**
34
+ * @param serializer - The document serializer.
35
+ * @param userId - The userId for which we are accessing overlays.
36
+ */
37
+ constructor(serializer: LocalSerializer, userId: string);
38
+ static forUser(serializer: LocalSerializer, user: User): IndexedDbDocumentOverlayCache;
39
+ getOverlay(transaction: PersistenceTransaction, key: DocumentKey): PersistencePromise<Overlay | null>;
40
+ saveOverlays(transaction: PersistenceTransaction, largestBatchId: number, overlays: Map<DocumentKey, Mutation>): PersistencePromise<void>;
41
+ removeOverlaysForBatchId(transaction: PersistenceTransaction, documentKeys: DocumentKeySet, batchId: number): PersistencePromise<void>;
42
+ getOverlaysForCollection(transaction: PersistenceTransaction, collection: ResourcePath, sinceBatchId: number): PersistencePromise<Map<DocumentKey, Overlay>>;
43
+ getOverlaysForCollectionGroup(transaction: PersistenceTransaction, collectionGroup: string, sinceBatchId: number, count: number): PersistencePromise<Map<DocumentKey, Overlay>>;
44
+ private saveOverlay;
45
+ }
@@ -14,6 +14,7 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
+ import { User } from '../auth/user';
17
18
  import { Target } from '../core/target';
18
19
  import { DocumentKeySet, DocumentMap } from '../model/collections';
19
20
  import { FieldIndex, IndexOffset } from '../model/field_index';
@@ -23,16 +24,22 @@ import { PersistencePromise } from './persistence_promise';
23
24
  import { PersistenceTransaction } from './persistence_transaction';
24
25
  /**
25
26
  * A persisted implementation of IndexManager.
27
+ *
28
+ * PORTING NOTE: Unlike iOS and Android, the Web SDK does not memoize index
29
+ * data as it supports multi-tab access.
26
30
  */
27
31
  export declare class IndexedDbIndexManager implements IndexManager {
32
+ private user;
28
33
  /**
29
34
  * An in-memory copy of the index entries we've already written since the SDK
30
35
  * launched. Used to avoid re-writing the same entry repeatedly.
31
36
  *
32
- * This is *NOT* a complete cache of what's in persistence and so can never be used to
33
- * satisfy reads.
37
+ * This is *NOT* a complete cache of what's in persistence and so can never be
38
+ * used to satisfy reads.
34
39
  */
35
40
  private collectionParentsCache;
41
+ private uid;
42
+ constructor(user: User);
36
43
  /**
37
44
  * Adds a new entry to the collection parent index.
38
45
  *
@@ -46,8 +53,28 @@ export declare class IndexedDbIndexManager implements IndexManager {
46
53
  deleteFieldIndex(transaction: PersistenceTransaction, index: FieldIndex): PersistencePromise<void>;
47
54
  getDocumentsMatchingTarget(transaction: PersistenceTransaction, fieldIndex: FieldIndex, target: Target): PersistencePromise<DocumentKeySet>;
48
55
  getFieldIndex(transaction: PersistenceTransaction, target: Target): PersistencePromise<FieldIndex | null>;
56
+ /**
57
+ * Returns the byte encoded form of the directional values in the field index.
58
+ * Returns `null` if the document does not have all fields specified in the
59
+ * index.
60
+ */
61
+ private encodeDirectionalElements;
62
+ /** Encodes a single value to the ascending index format. */
63
+ private encodeSingleElement;
49
64
  getFieldIndexes(transaction: PersistenceTransaction, collectionGroup?: string): PersistencePromise<FieldIndex[]>;
50
65
  getNextCollectionGroupToUpdate(transaction: PersistenceTransaction): PersistencePromise<string | null>;
51
66
  updateCollectionGroup(transaction: PersistenceTransaction, collectionGroup: string, offset: IndexOffset): PersistencePromise<void>;
52
67
  updateIndexEntries(transaction: PersistenceTransaction, documents: DocumentMap): PersistencePromise<void>;
68
+ private addIndexEntry;
69
+ private deleteIndexEntry;
70
+ private getExistingIndexEntries;
71
+ /** Creates the index entries for the given document. */
72
+ private computeIndexEntries;
73
+ /**
74
+ * Updates the index entries for the provided document by deleting entries
75
+ * that are no longer referenced in `newEntries` and adding all newly added
76
+ * entries.
77
+ */
78
+ private updateEntries;
79
+ private getNextSequenceNumber;
53
80
  }
@@ -21,6 +21,7 @@ import { JsonProtoSerializer } from '../remote/serializer';
21
21
  import { AsyncQueue } from '../util/async_queue';
22
22
  import { DocumentLike, WindowLike } from '../util/types';
23
23
  import { BundleCache } from './bundle_cache';
24
+ import { DocumentOverlayCache } from './document_overlay_cache';
24
25
  import { IndexManager } from './index_manager';
25
26
  import { IndexedDbLruDelegateImpl } from './indexeddb_lru_delegate_impl';
26
27
  import { IndexedDbMutationQueue } from './indexeddb_mutation_queue';
@@ -99,6 +100,7 @@ export declare class IndexedDbPersistence implements Persistence {
99
100
  * no longer be able to access IndexedDB.
100
101
  */
101
102
  private readonly forceOwningTab;
103
+ private readonly schemaVersion;
102
104
  private simpleDb;
103
105
  private listenSequence;
104
106
  private _started;
@@ -118,7 +120,6 @@ export declare class IndexedDbPersistence implements Persistence {
118
120
  /** A listener to notify on primary state changes. */
119
121
  private primaryStateListener;
120
122
  private readonly targetCache;
121
- private readonly indexManager;
122
123
  private readonly remoteDocumentCache;
123
124
  private readonly bundleCache;
124
125
  private readonly webStorage;
@@ -133,7 +134,7 @@ export declare class IndexedDbPersistence implements Persistence {
133
134
  * If set to true, forcefully obtains database access. Existing tabs will
134
135
  * no longer be able to access IndexedDB.
135
136
  */
136
- forceOwningTab: boolean);
137
+ forceOwningTab: boolean, schemaVersion?: number);
137
138
  /**
138
139
  * Attempt to start IndexedDb persistence.
139
140
  *
@@ -207,10 +208,11 @@ export declare class IndexedDbPersistence implements Persistence {
207
208
  */
208
209
  getActiveClients(): Promise<ClientId[]>;
209
210
  get started(): boolean;
210
- getMutationQueue(user: User): IndexedDbMutationQueue;
211
+ getMutationQueue(user: User, indexManager: IndexManager): IndexedDbMutationQueue;
211
212
  getTargetCache(): IndexedDbTargetCache;
212
213
  getRemoteDocumentCache(): IndexedDbRemoteDocumentCache;
213
- getIndexManager(): IndexManager;
214
+ getIndexManager(user: User): IndexManager;
215
+ getDocumentOverlayCache(user: User): DocumentOverlayCache;
214
216
  getBundleCache(): BundleCache;
215
217
  runTransaction<T>(action: string, mode: PersistenceTransactionMode, transactionOperation: (transaction: PersistenceTransaction) => PersistencePromise<T>): Promise<T>;
216
218
  /**
@@ -17,7 +17,6 @@
17
17
  import { SnapshotVersion } from '../core/snapshot_version';
18
18
  import { MutableDocumentMap } from '../model/collections';
19
19
  import { MutableDocument } from '../model/document';
20
- import { IndexManager } from './index_manager';
21
20
  import { LocalSerializer } from './local_serializer';
22
21
  import { PersistencePromise } from './persistence_promise';
23
22
  import { PersistenceTransaction } from './persistence_transaction';
@@ -28,13 +27,8 @@ export interface DocumentSizeEntry {
28
27
  }
29
28
  export interface IndexedDbRemoteDocumentCache extends RemoteDocumentCache {
30
29
  }
31
- /**
32
- * Creates a new IndexedDbRemoteDocumentCache.
33
- *
34
- * @param serializer - The document serializer.
35
- * @param indexManager - The query indexes that need to be maintained.
36
- */
37
- export declare function newIndexedDbRemoteDocumentCache(serializer: LocalSerializer, indexManager: IndexManager): IndexedDbRemoteDocumentCache;
30
+ /** Creates a new IndexedDbRemoteDocumentCache. */
31
+ export declare function newIndexedDbRemoteDocumentCache(serializer: LocalSerializer): IndexedDbRemoteDocumentCache;
38
32
  /**
39
33
  * Returns the set of documents that have changed since the specified read
40
34
  * time.
@@ -20,7 +20,7 @@ import { ResourcePath } from '../model/path';
20
20
  import { BundledQuery } from '../protos/firestore_bundle_proto';
21
21
  import { Document as ProtoDocument, DocumentsTarget as ProtoDocumentsTarget, QueryTarget as ProtoQueryTarget, Write as ProtoWrite } from '../protos/firestore_proto_api';
22
22
  import { EncodedResourcePath } from './encoded_resource_path';
23
- export declare const INDEXING_SCHEMA_VERSION = 12;
23
+ export declare const INDEXING_SCHEMA_VERSION = 13;
24
24
  /**
25
25
  * Schema Version for the Web client:
26
26
  * 1. Initial version including Mutation Queue, Query Cache, and Remote
@@ -39,7 +39,8 @@ export declare const INDEXING_SCHEMA_VERSION = 12;
39
39
  * an auto-incrementing ID. This is required for Index-Free queries.
40
40
  * 10. Rewrite the canonical IDs to the explicit Protobuf-based format.
41
41
  * 11. Add bundles and named_queries for bundle support.
42
- * 12. Add indexing support.
42
+ * 12. Add document overlays.
43
+ * 13. Add indexing support.
43
44
  */
44
45
  export declare const SCHEMA_VERSION: number;
45
46
  /**
@@ -809,22 +810,38 @@ export declare class DbNamedQuery {
809
810
  export declare type DbIndexConfigurationKey = number;
810
811
  /** An object representing the global configuration for a field index. */
811
812
  export declare class DbIndexConfiguration {
812
- /** The index id for this entry. */
813
- indexId: number;
813
+ /**
814
+ * The index id for this entry. Undefined for indexes that are not yet
815
+ * persisted.
816
+ */
817
+ indexId: number | undefined;
814
818
  /** The collection group this index belongs to. */
815
819
  collectionGroup: string;
816
820
  /** The fields to index for this index. */
817
- fields: [[name: string, kind: IndexKind]];
821
+ fields: Array<[name: string, kind: IndexKind]>;
818
822
  /** Name of the IndexedDb object store. */
819
823
  static store: string;
820
824
  static keyPath: string;
825
+ /**
826
+ * An index that provides access to the index configurations by collection
827
+ * group.
828
+ *
829
+ * PORTING NOTE: iOS and Android maintain this index in-memory, but this is
830
+ * not possible here as the Web client supports concurrent access to
831
+ * persistence via multi-tab.
832
+ */
833
+ static collectionGroupIndex: string;
834
+ static collectionGroupIndexPath: string;
821
835
  constructor(
822
- /** The index id for this entry. */
823
- indexId: number,
836
+ /**
837
+ * The index id for this entry. Undefined for indexes that are not yet
838
+ * persisted.
839
+ */
840
+ indexId: number | undefined,
824
841
  /** The collection group this index belongs to. */
825
842
  collectionGroup: string,
826
843
  /** The fields to index for this index. */
827
- fields: [[name: string, kind: IndexKind]]);
844
+ fields: Array<[name: string, kind: IndexKind]>);
828
845
  }
829
846
  /** The key for each index state consisting of the index id and its user id. */
830
847
  export declare type DbIndexStateKey = [number, string];
@@ -860,6 +877,16 @@ export declare class DbIndexState {
860
877
  /** Name of the IndexedDb object store. */
861
878
  static store: string;
862
879
  static keyPath: string[];
880
+ /**
881
+ * An index that provides access to documents in a collection sorted by last
882
+ * update time. Used by the backfiller.
883
+ *
884
+ * PORTING NOTE: iOS and Android maintain this index in-memory, but this is
885
+ * not possible here as the Web client supports concurrent access to
886
+ * persistence via multi-tab.
887
+ */
888
+ static sequenceNumberIndex: string;
889
+ static sequenceNumberIndexPath: string[];
863
890
  constructor(
864
891
  /** The index id for this entry. */
865
892
  indexId: number,
@@ -893,7 +920,7 @@ export declare class DbIndexState {
893
920
  */
894
921
  export declare type DbIndexEntryKey = [number, string, Uint8Array, Uint8Array, string];
895
922
  /** An object that stores the encoded entries for all documents and fields. */
896
- export declare class DbIndexEntries {
923
+ export declare class DbIndexEntry {
897
924
  /** The index id for this entry. */
898
925
  indexId: number;
899
926
  /** The user id for this entry. */
@@ -907,6 +934,8 @@ export declare class DbIndexEntries {
907
934
  /** Name of the IndexedDb object store. */
908
935
  static store: string;
909
936
  static keyPath: string[];
937
+ static documentKeyIndex: string;
938
+ static documentKeyIndexPath: string[];
910
939
  constructor(
911
940
  /** The index id for this entry. */
912
941
  indexId: number,
@@ -919,6 +948,48 @@ export declare class DbIndexEntries {
919
948
  /** The document key this entry points to. */
920
949
  documentKey: EncodedResourcePath);
921
950
  }
951
+ export declare type DbDocumentOverlayKey = [
952
+ string,
953
+ string,
954
+ string
955
+ ];
956
+ /**
957
+ * An object representing a document overlay.
958
+ */
959
+ export declare class DbDocumentOverlay {
960
+ /** The user ID to whom this overlay belongs. */
961
+ userId: string;
962
+ /** The path to the collection that contains the document. */
963
+ collectionPath: string;
964
+ /** The ID (key) of the document within the collection. */
965
+ documentId: string;
966
+ /** The collection group to which the document belongs. */
967
+ collectionGroup: string;
968
+ /** The largest batch ID that's been applied for this overlay. */
969
+ largestBatchId: number;
970
+ /** The overlay mutation. */
971
+ overlayMutation: ProtoWrite;
972
+ /** Name of the IndexedDb object store. */
973
+ static store: string;
974
+ static keyPath: string[];
975
+ static collectionPathOverlayIndex: string;
976
+ static collectionPathOverlayIndexPath: string[];
977
+ static collectionGroupOverlayIndex: string;
978
+ static collectionGroupOverlayIndexPath: string[];
979
+ constructor(
980
+ /** The user ID to whom this overlay belongs. */
981
+ userId: string,
982
+ /** The path to the collection that contains the document. */
983
+ collectionPath: string,
984
+ /** The ID (key) of the document within the collection. */
985
+ documentId: string,
986
+ /** The collection group to which the document belongs. */
987
+ collectionGroup: string,
988
+ /** The largest batch ID that's been applied for this overlay. */
989
+ largestBatchId: number,
990
+ /** The overlay mutation. */
991
+ overlayMutation: ProtoWrite);
992
+ }
922
993
  export declare const V1_STORES: string[];
923
994
  export declare const V3_STORES: string[];
924
995
  export declare const V4_STORES: string[];
@@ -926,9 +997,12 @@ export declare const V6_STORES: string[];
926
997
  export declare const V8_STORES: string[];
927
998
  export declare const V11_STORES: string[];
928
999
  export declare const V12_STORES: string[];
1000
+ export declare const V13_STORES: string[];
929
1001
  /**
930
1002
  * The list of all default IndexedDB stores used throughout the SDK. This is
931
1003
  * used when creating transactions so that access across all stores is done
932
1004
  * atomically.
933
1005
  */
934
1006
  export declare const ALL_STORES: string[];
1007
+ /** Returns the object stores for the provided schema. */
1008
+ export declare function getObjectStores(schemaVersion: number): string[];
@@ -69,5 +69,4 @@ export declare class LocalDocumentsView {
69
69
  private getDocumentsMatchingDocumentQuery;
70
70
  private getDocumentsMatchingCollectionGroupQuery;
71
71
  private getDocumentsMatchingCollectionQuery;
72
- private addMissingBaseDocuments;
73
72
  }