@firebase/firestore 3.4.4-canary.eaa517069 → 3.4.5-2022116201138

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/CHANGELOG.md +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 +19 -0
  8. package/dist/firestore/src/local/indexeddb_persistence.d.ts +2 -0
  9. package/dist/firestore/src/local/indexeddb_schema.d.ts +48 -2
  10. package/dist/firestore/src/local/local_serializer.d.ts +12 -1
  11. package/dist/firestore/src/local/memory_document_overlay_cache.d.ts +37 -0
  12. package/dist/firestore/src/local/memory_persistence.d.ts +3 -0
  13. package/dist/firestore/src/local/persistence.d.ts +6 -0
  14. package/dist/firestore/src/model/document_key.d.ts +5 -0
  15. package/dist/firestore/src/model/overlay.d.ts +32 -0
  16. package/dist/firestore/src/platform/node/grpc_connection.d.ts +2 -2
  17. package/dist/firestore/src/platform/node/load_protos.d.ts +2 -2
  18. package/dist/firestore/src/util/sorted_set.d.ts +18 -0
  19. package/dist/firestore/test/unit/local/document_overlay_cache.test.d.ts +1 -0
  20. package/dist/firestore/test/unit/local/test_document_overlay_cache.d.ts +38 -0
  21. package/dist/index.esm2017.js +4182 -3394
  22. package/dist/index.esm2017.js.map +1 -1
  23. package/dist/index.esm5.js +3916 -3226
  24. package/dist/index.esm5.js.map +1 -1
  25. package/dist/index.node.cjs.js +1241 -42
  26. package/dist/index.node.cjs.js.map +1 -1
  27. package/dist/index.node.mjs +1221 -43
  28. package/dist/index.node.mjs.map +1 -1
  29. package/dist/index.rn.js +4148 -3360
  30. package/dist/index.rn.js.map +1 -1
  31. package/dist/internal.d.ts +75 -0
  32. package/dist/lite/firestore/src/api/credentials.d.ts +1 -0
  33. package/dist/lite/firestore/src/index/index_byte_encoder.d.ts +18 -1
  34. package/dist/lite/firestore/src/index/index_entry.d.ts +26 -0
  35. package/dist/lite/firestore/src/local/document_overlay_cache.d.ts +72 -0
  36. package/dist/lite/firestore/src/local/indexeddb_document_overlay_cache.d.ts +45 -0
  37. package/dist/lite/firestore/src/local/indexeddb_index_manager.d.ts +19 -0
  38. package/dist/lite/firestore/src/local/indexeddb_persistence.d.ts +2 -0
  39. package/dist/lite/firestore/src/local/indexeddb_schema.d.ts +48 -2
  40. package/dist/lite/firestore/src/local/local_serializer.d.ts +12 -1
  41. package/dist/lite/firestore/src/local/memory_document_overlay_cache.d.ts +37 -0
  42. package/dist/lite/firestore/src/local/memory_persistence.d.ts +3 -0
  43. package/dist/lite/firestore/src/local/persistence.d.ts +6 -0
  44. package/dist/lite/firestore/src/model/document_key.d.ts +5 -0
  45. package/dist/lite/firestore/src/model/overlay.d.ts +32 -0
  46. package/dist/lite/firestore/src/platform/node/grpc_connection.d.ts +2 -2
  47. package/dist/lite/firestore/src/platform/node/load_protos.d.ts +2 -2
  48. package/dist/lite/firestore/src/util/sorted_set.d.ts +18 -0
  49. package/dist/lite/firestore/test/unit/local/document_overlay_cache.test.d.ts +1 -0
  50. package/dist/lite/firestore/test/unit/local/test_document_overlay_cache.d.ts +38 -0
  51. package/dist/lite/index.browser.esm2017.js +11 -2
  52. package/dist/lite/index.browser.esm2017.js.map +1 -1
  53. package/dist/lite/index.browser.esm5.js +49 -37
  54. package/dist/lite/index.browser.esm5.js.map +1 -1
  55. package/dist/lite/index.node.cjs.js +13 -2
  56. package/dist/lite/index.node.cjs.js.map +1 -1
  57. package/dist/lite/index.node.mjs +13 -2
  58. package/dist/lite/index.node.mjs.map +1 -1
  59. package/dist/lite/index.rn.esm2017.js +46 -37
  60. package/dist/lite/index.rn.esm2017.js.map +1 -1
  61. package/dist/lite/internal.d.ts +5 -0
  62. package/dist/lite/packages/firestore/src/api/credentials.d.ts +1 -0
  63. package/dist/lite/packages/firestore/src/index/index_byte_encoder.d.ts +18 -1
  64. package/dist/lite/packages/firestore/src/index/index_entry.d.ts +26 -0
  65. package/dist/lite/packages/firestore/src/local/document_overlay_cache.d.ts +72 -0
  66. package/dist/lite/packages/firestore/src/local/indexeddb_document_overlay_cache.d.ts +45 -0
  67. package/dist/lite/packages/firestore/src/local/indexeddb_index_manager.d.ts +19 -0
  68. package/dist/lite/packages/firestore/src/local/indexeddb_persistence.d.ts +2 -0
  69. package/dist/lite/packages/firestore/src/local/indexeddb_schema.d.ts +48 -2
  70. package/dist/lite/packages/firestore/src/local/local_serializer.d.ts +12 -1
  71. package/dist/lite/packages/firestore/src/local/memory_document_overlay_cache.d.ts +37 -0
  72. package/dist/lite/packages/firestore/src/local/memory_persistence.d.ts +3 -0
  73. package/dist/lite/packages/firestore/src/local/persistence.d.ts +6 -0
  74. package/dist/lite/packages/firestore/src/model/document_key.d.ts +5 -0
  75. package/dist/lite/packages/firestore/src/model/overlay.d.ts +32 -0
  76. package/dist/lite/packages/firestore/src/platform/node/grpc_connection.d.ts +2 -2
  77. package/dist/lite/packages/firestore/src/platform/node/load_protos.d.ts +2 -2
  78. package/dist/lite/packages/firestore/src/util/sorted_set.d.ts +18 -0
  79. package/dist/lite/packages/firestore/test/unit/local/document_overlay_cache.test.d.ts +1 -0
  80. package/dist/lite/packages/firestore/test/unit/local/test_document_overlay_cache.d.ts +38 -0
  81. package/dist/packages/firestore/dist/index.esm2017.d.ts +188 -185
  82. package/dist/packages/firestore/src/api/credentials.d.ts +1 -0
  83. package/dist/packages/firestore/src/index/index_byte_encoder.d.ts +18 -1
  84. package/dist/packages/firestore/src/index/index_entry.d.ts +26 -0
  85. package/dist/packages/firestore/src/local/document_overlay_cache.d.ts +72 -0
  86. package/dist/packages/firestore/src/local/indexeddb_document_overlay_cache.d.ts +45 -0
  87. package/dist/packages/firestore/src/local/indexeddb_index_manager.d.ts +19 -0
  88. package/dist/packages/firestore/src/local/indexeddb_persistence.d.ts +2 -0
  89. package/dist/packages/firestore/src/local/indexeddb_schema.d.ts +48 -2
  90. package/dist/packages/firestore/src/local/local_serializer.d.ts +12 -1
  91. package/dist/packages/firestore/src/local/memory_document_overlay_cache.d.ts +37 -0
  92. package/dist/packages/firestore/src/local/memory_persistence.d.ts +3 -0
  93. package/dist/packages/firestore/src/local/persistence.d.ts +6 -0
  94. package/dist/packages/firestore/src/model/document_key.d.ts +5 -0
  95. package/dist/packages/firestore/src/model/overlay.d.ts +32 -0
  96. package/dist/packages/firestore/src/platform/node/grpc_connection.d.ts +2 -2
  97. package/dist/packages/firestore/src/platform/node/load_protos.d.ts +2 -2
  98. package/dist/packages/firestore/src/util/sorted_set.d.ts +18 -0
  99. package/dist/packages/firestore/test/unit/local/document_overlay_cache.test.d.ts +1 -0
  100. package/dist/packages/firestore/test/unit/local/test_document_overlay_cache.d.ts +38 -0
  101. package/dist/private.d.ts +70 -0
  102. package/package.json +9 -9
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @firebase/firestore
2
2
 
3
+ ## 3.4.5-2022116201138
4
+
5
+ ### Patch Changes
6
+
7
+ - [`bb8f37c3e`](https://github.com/firebase/firebase-js-sdk/commit/bb8f37c3e83e73876d14fa751cb04ae5e1367394) [#5993](https://github.com/firebase/firebase-js-sdk/pull/5993) - Fixed a bug that caused Firestore streams to get restarted with the same App Check token.
8
+
9
+ * [`f5ac47fb1`](https://github.com/firebase/firebase-js-sdk/commit/f5ac47fb1a44f7b985fcae1d934e1ffb6ba41d67) [#5982](https://github.com/firebase/firebase-js-sdk/pull/5982) - On browsers that support IndexedDB V3, we now invoke `transaction.commit()` to speed up data processing.
10
+
11
+ - [`c1b9cf120`](https://github.com/firebase/firebase-js-sdk/commit/c1b9cf1201807fc177a89c9613c06130524563e4) [#5985](https://github.com/firebase/firebase-js-sdk/pull/5985) - Some database operations now use `IndexedDB.getAll()` on browsers where support is availbe.
12
+
13
+ * [`e9619685b`](https://github.com/firebase/firebase-js-sdk/commit/e9619685b9153f7d6f8767e09e2e1eacc337df76) [#5980](https://github.com/firebase/firebase-js-sdk/pull/5980) - Queries are now send to the backend before the SDK starts local processing, which reduces overall Query latency.
14
+
3
15
  ## 3.4.4
4
16
 
5
17
  ### Patch Changes
@@ -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
+ }
@@ -53,9 +53,28 @@ export declare class IndexedDbIndexManager implements IndexManager {
53
53
  deleteFieldIndex(transaction: PersistenceTransaction, index: FieldIndex): PersistencePromise<void>;
54
54
  getDocumentsMatchingTarget(transaction: PersistenceTransaction, fieldIndex: FieldIndex, target: Target): PersistencePromise<DocumentKeySet>;
55
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;
56
64
  getFieldIndexes(transaction: PersistenceTransaction, collectionGroup?: string): PersistencePromise<FieldIndex[]>;
57
65
  getNextCollectionGroupToUpdate(transaction: PersistenceTransaction): PersistencePromise<string | null>;
58
66
  updateCollectionGroup(transaction: PersistenceTransaction, collectionGroup: string, offset: IndexOffset): PersistencePromise<void>;
59
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;
60
79
  private getNextSequenceNumber;
61
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';
@@ -211,6 +212,7 @@ export declare class IndexedDbPersistence implements Persistence {
211
212
  getTargetCache(): IndexedDbTargetCache;
212
213
  getRemoteDocumentCache(): IndexedDbRemoteDocumentCache;
213
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
  /**
@@ -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
  /**
@@ -933,6 +934,8 @@ export declare class DbIndexEntry {
933
934
  /** Name of the IndexedDb object store. */
934
935
  static store: string;
935
936
  static keyPath: string[];
937
+ static documentKeyIndex: string;
938
+ static documentKeyIndexPath: string[];
936
939
  constructor(
937
940
  /** The index id for this entry. */
938
941
  indexId: number,
@@ -945,6 +948,48 @@ export declare class DbIndexEntry {
945
948
  /** The document key this entry points to. */
946
949
  documentKey: EncodedResourcePath);
947
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
+ }
948
993
  export declare const V1_STORES: string[];
949
994
  export declare const V3_STORES: string[];
950
995
  export declare const V4_STORES: string[];
@@ -952,6 +997,7 @@ export declare const V6_STORES: string[];
952
997
  export declare const V8_STORES: string[];
953
998
  export declare const V11_STORES: string[];
954
999
  export declare const V12_STORES: string[];
1000
+ export declare const V13_STORES: string[];
955
1001
  /**
956
1002
  * The list of all default IndexedDB stores used throughout the SDK. This is
957
1003
  * used when creating transactions so that access across all stores is done
@@ -19,11 +19,13 @@ import { BundleMetadata, NamedQuery } from '../core/bundle';
19
19
  import { Query } from '../core/query';
20
20
  import { SnapshotVersion } from '../core/snapshot_version';
21
21
  import { MutableDocument } from '../model/document';
22
+ import { DocumentKey } from '../model/document_key';
22
23
  import { FieldIndex, IndexOffset } from '../model/field_index';
23
24
  import { MutationBatch } from '../model/mutation_batch';
25
+ import { Overlay } from '../model/overlay';
24
26
  import { BundledQuery as ProtoBundledQuery, BundleMetadata as ProtoBundleMetadata, NamedQuery as ProtoNamedQuery } from '../protos/firestore_bundle_proto';
25
27
  import { JsonProtoSerializer } from '../remote/serializer';
26
- import { DbBundle, DbIndexConfiguration, DbIndexState, DbMutationBatch, DbNamedQuery, DbRemoteDocument, DbTarget, DbTimestampKey } from './indexeddb_schema';
28
+ import { DbBundle, DbDocumentOverlay, DbDocumentOverlayKey, DbIndexConfiguration, DbIndexState, DbMutationBatch, DbNamedQuery, DbRemoteDocument, DbTarget, DbTimestampKey } from './indexeddb_schema';
27
29
  import { TargetData } from './target_data';
28
30
  /** Serializer for values stored in the LocalStore. */
29
31
  export declare class LocalSerializer {
@@ -63,6 +65,15 @@ export declare function fromBundledQuery(bundledQuery: ProtoBundledQuery): Query
63
65
  export declare function fromProtoNamedQuery(namedQuery: ProtoNamedQuery): NamedQuery;
64
66
  /** Decodes a BundleMetadata proto into a BundleMetadata object. */
65
67
  export declare function fromBundleMetadata(metadata: ProtoBundleMetadata): BundleMetadata;
68
+ /** Encodes a DbDocumentOverlay object to an Overlay model object. */
69
+ export declare function fromDbDocumentOverlay(localSerializer: LocalSerializer, dbDocumentOverlay: DbDocumentOverlay): Overlay;
70
+ /** Decodes an Overlay model object into a DbDocumentOverlay object. */
71
+ export declare function toDbDocumentOverlay(localSerializer: LocalSerializer, userId: string, overlay: Overlay): DbDocumentOverlay;
72
+ /**
73
+ * Returns the DbDocumentOverlayKey corresponding to the given user and
74
+ * document key.
75
+ */
76
+ export declare function toDbDocumentOverlayKey(userId: string, docKey: DocumentKey): DbDocumentOverlayKey;
66
77
  export declare function toDbIndexConfiguration(index: FieldIndex): DbIndexConfiguration;
67
78
  export declare function fromDbIndexConfiguration(index: DbIndexConfiguration, state: DbIndexState | null): FieldIndex;
68
79
  export declare function toDbIndexState(indexId: number, user: User, sequenceNumber: number, offset: IndexOffset): DbIndexState;
@@ -0,0 +1,37 @@
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 { DocumentOverlayCache } from './document_overlay_cache';
23
+ import { PersistencePromise } from './persistence_promise';
24
+ import { PersistenceTransaction } from './persistence_transaction';
25
+ /**
26
+ * An in-memory implementation of DocumentOverlayCache.
27
+ */
28
+ export declare class MemoryDocumentOverlayCache implements DocumentOverlayCache {
29
+ private overlays;
30
+ private overlayByBatchId;
31
+ getOverlay(transaction: PersistenceTransaction, key: DocumentKey): PersistencePromise<Overlay | null>;
32
+ saveOverlays(transaction: PersistenceTransaction, largestBatchId: number, overlays: Map<DocumentKey, Mutation>): PersistencePromise<void>;
33
+ removeOverlaysForBatchId(transaction: PersistenceTransaction, documentKeys: DocumentKeySet, batchId: number): PersistencePromise<void>;
34
+ getOverlaysForCollection(transaction: PersistenceTransaction, collection: ResourcePath, sinceBatchId: number): PersistencePromise<Map<DocumentKey, Overlay>>;
35
+ getOverlaysForCollectionGroup(transaction: PersistenceTransaction, collectionGroup: string, sinceBatchId: number, count: number): PersistencePromise<Map<DocumentKey, Overlay>>;
36
+ private saveOverlay;
37
+ }
@@ -19,6 +19,7 @@ import { ListenSequenceNumber, TargetId } from '../core/types';
19
19
  import { Document } from '../model/document';
20
20
  import { DocumentKey } from '../model/document_key';
21
21
  import { JsonProtoSerializer } from '../remote/serializer';
22
+ import { DocumentOverlayCache } from './document_overlay_cache';
22
23
  import { IndexManager } from './index_manager';
23
24
  import { ActiveTargets, LruDelegate, LruGarbageCollector, LruParams } from './lru_garbage_collector';
24
25
  import { MemoryBundleCache } from './memory_bundle_cache';
@@ -44,6 +45,7 @@ export declare class MemoryPersistence implements Persistence {
44
45
  */
45
46
  private readonly indexManager;
46
47
  private mutationQueues;
48
+ private overlays;
47
49
  private readonly remoteDocumentCache;
48
50
  private readonly targetCache;
49
51
  private readonly bundleCache;
@@ -64,6 +66,7 @@ export declare class MemoryPersistence implements Persistence {
64
66
  setDatabaseDeletedListener(): void;
65
67
  setNetworkEnabled(): void;
66
68
  getIndexManager(user: User): MemoryIndexManager;
69
+ getDocumentOverlayCache(user: User): DocumentOverlayCache;
67
70
  getMutationQueue(user: User, indexManager: IndexManager): MutationQueue;
68
71
  getTargetCache(): MemoryTargetCache;
69
72
  getRemoteDocumentCache(): MemoryRemoteDocumentCache;
@@ -18,6 +18,7 @@ import { User } from '../auth/user';
18
18
  import { TargetId } from '../core/types';
19
19
  import { DocumentKey } from '../model/document_key';
20
20
  import { BundleCache } from './bundle_cache';
21
+ import { DocumentOverlayCache } from './document_overlay_cache';
21
22
  import { IndexManager } from './index_manager';
22
23
  import { LocalStore } from './local_store';
23
24
  import { MutationQueue } from './mutation_queue';
@@ -174,6 +175,11 @@ export interface Persistence {
174
175
  * to emulate the persisted implementation to the extent possible.
175
176
  */
176
177
  getIndexManager(user: User): IndexManager;
178
+ /**
179
+ * Returns a DocumentOverlayCache representing the documents that are mutated
180
+ * locally.
181
+ */
182
+ getDocumentOverlayCache(user: User): DocumentOverlayCache;
177
183
  /**
178
184
  * Performs an operation inside a persistence transaction. Any reads or writes
179
185
  * against persistence must be performed within a transaction. Writes will be
@@ -24,8 +24,13 @@ export declare class DocumentKey {
24
24
  static fromPath(path: string): DocumentKey;
25
25
  static fromName(name: string): DocumentKey;
26
26
  static empty(): DocumentKey;
27
+ get collectionGroup(): string;
27
28
  /** Returns true if the document is in the specified collectionId. */
28
29
  hasCollectionId(collectionId: string): boolean;
30
+ /** Returns the collection group (i.e. the name of the parent collection) for this key. */
31
+ getCollectionGroup(): string;
32
+ /** Returns the fully qualified path to the parent collection. */
33
+ getCollectionPath(): ResourcePath;
29
34
  isEqual(other: DocumentKey | null): boolean;
30
35
  toString(): string;
31
36
  static comparator(k1: DocumentKey, k2: DocumentKey): number;
@@ -0,0 +1,32 @@
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 './document_key';
18
+ import { Mutation } from './mutation';
19
+ /**
20
+ * Representation of an overlay computed by Firestore.
21
+ *
22
+ * Holds information about a mutation and the largest batch id in Firestore when
23
+ * the mutation was created.
24
+ */
25
+ export declare class Overlay {
26
+ readonly largestBatchId: number;
27
+ readonly mutation: Mutation;
28
+ constructor(largestBatchId: number, mutation: Mutation);
29
+ getKey(): DocumentKey;
30
+ isEqual(other: Overlay | null): boolean;
31
+ toString(): string;
32
+ }
@@ -14,7 +14,7 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- import { GrpcObject } from '@grpc/grpc-js';
17
+ import * as grpc from '@grpc/grpc-js';
18
18
  import { Token } from '../../api/credentials';
19
19
  import { DatabaseInfo } from '../../core/database_info';
20
20
  import { Connection, Stream } from '../../remote/connection';
@@ -26,7 +26,7 @@ export declare class GrpcConnection implements Connection {
26
26
  private readonly databasePath;
27
27
  private readonly firestore;
28
28
  private cachedStub;
29
- constructor(protos: GrpcObject, databaseInfo: DatabaseInfo);
29
+ constructor(protos: grpc.GrpcObject, databaseInfo: DatabaseInfo);
30
30
  private ensureActiveStub;
31
31
  invokeRPC<Req, Resp>(rpcName: string, path: string, request: Req, authToken: Token | null, appCheckToken: Token | null): Promise<Resp>;
32
32
  invokeStreamingRPC<Req, Resp>(rpcName: string, path: string, request: Req, authToken: Token | null, appCheckToken: Token | null): Promise<Resp[]>;
@@ -14,7 +14,7 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- import { GrpcObject } from '@grpc/grpc-js';
17
+ import * as grpc from '@grpc/grpc-js';
18
18
  import { IConversionOptions, Root } from 'protobufjs';
19
19
  /** Used by tests so we can match @grpc/proto-loader behavior. */
20
20
  export declare const protoLoaderOptions: IConversionOptions;
@@ -23,6 +23,6 @@ export declare const protoLoaderOptions: IConversionOptions;
23
23
  *
24
24
  * @returns The GrpcObject representing our protos.
25
25
  */
26
- export declare function loadProtos(): GrpcObject;
26
+ export declare function loadProtos(): grpc.GrpcObject;
27
27
  /** Used by tests so we can directly create ProtobufJS proto message objects from JSON protos. */
28
28
  export declare function loadRawProtos(): Root;
@@ -60,3 +60,21 @@ export declare class SortedSetIterator<T> {
60
60
  getNext(): T;
61
61
  hasNext(): boolean;
62
62
  }
63
+ /**
64
+ * Compares two sorted sets for equality using their natural ordering. The
65
+ * method computes the intersection and invokes `onAdd` for every element that
66
+ * is in `after` but not `before`. `onRemove` is invoked for every element in
67
+ * `before` but missing from `after`.
68
+ *
69
+ * The method creates a copy of both `before` and `after` and runs in O(n log
70
+ * n), where n is the size of the two lists.
71
+ *
72
+ * @param before - The elements that exist in the original set.
73
+ * @param after - The elements to diff against the original set.
74
+ * @param comparator - The comparator for the elements in before and after.
75
+ * @param onAdd - A function to invoke for every element that is part of `
76
+ * after` but not `before`.
77
+ * @param onRemove - A function to invoke for every element that is part of
78
+ * `before` but not `after`.
79
+ */
80
+ export declare function diffSortedSets<T>(before: SortedSet<T>, after: SortedSet<T>, comparator: (l: T, r: T) => number, onAdd: (entry: T) => void, onRemove: (entry: T) => void): void;
@@ -0,0 +1,38 @@
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 { DocumentOverlayCache } from '../../../src/local/document_overlay_cache';
18
+ import { Persistence } from '../../../src/local/persistence';
19
+ import { DocumentKeySet } from '../../../src/model/collections';
20
+ import { DocumentKey } from '../../../src/model/document_key';
21
+ import { Mutation } from '../../../src/model/mutation';
22
+ import { Overlay } from '../../../src/model/overlay';
23
+ import { ResourcePath } from '../../../src/model/path';
24
+ /**
25
+ * A wrapper around a DocumentOverlayCache that automatically creates a
26
+ * transaction around every operation to reduce test boilerplate.
27
+ */
28
+ export declare class TestDocumentOverlayCache {
29
+ private persistence;
30
+ private cache;
31
+ constructor(persistence: Persistence, cache: DocumentOverlayCache);
32
+ saveOverlays(largestBatch: number, data: Map<DocumentKey, Mutation>): Promise<void>;
33
+ getOverlay(key: DocumentKey): Promise<Overlay | null>;
34
+ getOverlayMutation(docKey: string): Promise<Mutation | null>;
35
+ getOverlaysForCollection(path: ResourcePath, sinceBatchId: number): Promise<Map<DocumentKey, Overlay>>;
36
+ getOverlaysForCollectionGroup(collectionGroup: string, sinceBatchId: number, count: number): Promise<Map<DocumentKey, Overlay>>;
37
+ removeOverlaysForBatchId(documentKeys: DocumentKeySet, batchId: number): Promise<void>;
38
+ }