@firebase/firestore 3.4.9-canary.f84cacd70 → 3.4.10

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 (107) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/firestore/src/core/component_provider.d.ts +11 -6
  3. package/dist/firestore/src/local/document_overlay_cache.d.ts +1 -1
  4. package/dist/firestore/src/local/index_backfiller.d.ts +44 -0
  5. package/dist/firestore/src/local/index_manager.d.ts +2 -0
  6. package/dist/firestore/src/local/indexeddb_document_overlay_cache.d.ts +1 -1
  7. package/dist/firestore/src/local/indexeddb_index_manager.d.ts +1 -0
  8. package/dist/firestore/src/local/local_documents_view.d.ts +20 -4
  9. package/dist/firestore/src/local/local_store.d.ts +9 -0
  10. package/dist/firestore/src/local/lru_garbage_collector_impl.d.ts +5 -5
  11. package/dist/firestore/src/local/memory_document_overlay_cache.d.ts +1 -1
  12. package/dist/firestore/src/local/memory_index_manager.d.ts +1 -0
  13. package/dist/firestore/src/local/persistence.d.ts +3 -5
  14. package/dist/firestore/src/local/persistence_promise.d.ts +11 -0
  15. package/dist/firestore/src/model/collections.d.ts +6 -2
  16. package/dist/firestore/src/model/mutation_batch.d.ts +2 -3
  17. package/dist/firestore/src/util/async_queue.d.ts +5 -1
  18. package/dist/firestore/test/unit/local/index_backfiller.test.d.ts +17 -0
  19. package/dist/firestore/test/unit/local/test_document_overlay_cache.d.ts +1 -1
  20. package/dist/firestore/test/unit/specs/spec_test_components.d.ts +5 -3
  21. package/dist/firestore/test/util/helpers.d.ts +1 -0
  22. package/dist/index.esm2017.js +7499 -7351
  23. package/dist/index.esm2017.js.map +1 -1
  24. package/dist/index.esm5.js +8227 -7997
  25. package/dist/index.esm5.js.map +1 -1
  26. package/dist/index.node.cjs.js +1552 -1309
  27. package/dist/index.node.cjs.js.map +1 -1
  28. package/dist/index.node.mjs +1552 -1309
  29. package/dist/index.node.mjs.map +1 -1
  30. package/dist/index.rn.js +7491 -7342
  31. package/dist/index.rn.js.map +1 -1
  32. package/dist/internal.d.ts +146 -16
  33. package/dist/lite/firestore/src/core/component_provider.d.ts +11 -6
  34. package/dist/lite/firestore/src/local/document_overlay_cache.d.ts +1 -1
  35. package/dist/lite/firestore/src/local/index_backfiller.d.ts +44 -0
  36. package/dist/lite/firestore/src/local/index_manager.d.ts +2 -0
  37. package/dist/lite/firestore/src/local/indexeddb_document_overlay_cache.d.ts +1 -1
  38. package/dist/lite/firestore/src/local/indexeddb_index_manager.d.ts +1 -0
  39. package/dist/lite/firestore/src/local/local_documents_view.d.ts +20 -4
  40. package/dist/lite/firestore/src/local/local_store.d.ts +9 -0
  41. package/dist/lite/firestore/src/local/lru_garbage_collector_impl.d.ts +5 -5
  42. package/dist/lite/firestore/src/local/memory_document_overlay_cache.d.ts +1 -1
  43. package/dist/lite/firestore/src/local/memory_index_manager.d.ts +1 -0
  44. package/dist/lite/firestore/src/local/persistence.d.ts +3 -5
  45. package/dist/lite/firestore/src/local/persistence_promise.d.ts +11 -0
  46. package/dist/lite/firestore/src/model/collections.d.ts +6 -2
  47. package/dist/lite/firestore/src/model/mutation_batch.d.ts +2 -3
  48. package/dist/lite/firestore/src/util/async_queue.d.ts +5 -1
  49. package/dist/lite/firestore/test/unit/local/index_backfiller.test.d.ts +17 -0
  50. package/dist/lite/firestore/test/unit/local/test_document_overlay_cache.d.ts +1 -1
  51. package/dist/lite/firestore/test/unit/specs/spec_test_components.d.ts +5 -3
  52. package/dist/lite/firestore/test/util/helpers.d.ts +1 -0
  53. package/dist/lite/index.browser.esm2017.js +2 -2
  54. package/dist/lite/index.browser.esm2017.js.map +1 -1
  55. package/dist/lite/index.browser.esm5.js +2 -2
  56. package/dist/lite/index.browser.esm5.js.map +1 -1
  57. package/dist/lite/index.node.cjs.js +2 -2
  58. package/dist/lite/index.node.cjs.js.map +1 -1
  59. package/dist/lite/index.node.mjs +2 -2
  60. package/dist/lite/index.node.mjs.map +1 -1
  61. package/dist/lite/index.rn.esm2017.js +2 -2
  62. package/dist/lite/index.rn.esm2017.js.map +1 -1
  63. package/dist/lite/internal.d.ts +5 -1
  64. package/dist/lite/packages/firestore/src/core/component_provider.d.ts +11 -6
  65. package/dist/lite/packages/firestore/src/local/document_overlay_cache.d.ts +1 -1
  66. package/dist/lite/packages/firestore/src/local/index_backfiller.d.ts +44 -0
  67. package/dist/lite/packages/firestore/src/local/index_manager.d.ts +2 -0
  68. package/dist/lite/packages/firestore/src/local/indexeddb_document_overlay_cache.d.ts +1 -1
  69. package/dist/lite/packages/firestore/src/local/indexeddb_index_manager.d.ts +1 -0
  70. package/dist/lite/packages/firestore/src/local/local_documents_view.d.ts +20 -4
  71. package/dist/lite/packages/firestore/src/local/local_store.d.ts +9 -0
  72. package/dist/lite/packages/firestore/src/local/lru_garbage_collector_impl.d.ts +5 -5
  73. package/dist/lite/packages/firestore/src/local/memory_document_overlay_cache.d.ts +1 -1
  74. package/dist/lite/packages/firestore/src/local/memory_index_manager.d.ts +1 -0
  75. package/dist/lite/packages/firestore/src/local/persistence.d.ts +3 -5
  76. package/dist/lite/packages/firestore/src/local/persistence_promise.d.ts +11 -0
  77. package/dist/lite/packages/firestore/src/model/collections.d.ts +6 -2
  78. package/dist/lite/packages/firestore/src/model/mutation_batch.d.ts +2 -3
  79. package/dist/lite/packages/firestore/src/util/async_queue.d.ts +5 -1
  80. package/dist/lite/packages/firestore/test/unit/local/index_backfiller.test.d.ts +17 -0
  81. package/dist/lite/packages/firestore/test/unit/local/test_document_overlay_cache.d.ts +1 -1
  82. package/dist/lite/packages/firestore/test/unit/specs/spec_test_components.d.ts +5 -3
  83. package/dist/lite/packages/firestore/test/util/helpers.d.ts +1 -0
  84. package/dist/lite/private.d.ts +5 -1
  85. package/dist/packages/firestore/dist/index.esm2017.d.ts +200 -200
  86. package/dist/packages/firestore/src/core/component_provider.d.ts +11 -6
  87. package/dist/packages/firestore/src/local/document_overlay_cache.d.ts +1 -1
  88. package/dist/packages/firestore/src/local/index_backfiller.d.ts +44 -0
  89. package/dist/packages/firestore/src/local/index_manager.d.ts +2 -0
  90. package/dist/packages/firestore/src/local/indexeddb_document_overlay_cache.d.ts +1 -1
  91. package/dist/packages/firestore/src/local/indexeddb_index_manager.d.ts +1 -0
  92. package/dist/packages/firestore/src/local/local_documents_view.d.ts +20 -4
  93. package/dist/packages/firestore/src/local/local_store.d.ts +9 -0
  94. package/dist/packages/firestore/src/local/lru_garbage_collector_impl.d.ts +5 -5
  95. package/dist/packages/firestore/src/local/memory_document_overlay_cache.d.ts +1 -1
  96. package/dist/packages/firestore/src/local/memory_index_manager.d.ts +1 -0
  97. package/dist/packages/firestore/src/local/persistence.d.ts +3 -5
  98. package/dist/packages/firestore/src/local/persistence_promise.d.ts +11 -0
  99. package/dist/packages/firestore/src/model/collections.d.ts +6 -2
  100. package/dist/packages/firestore/src/model/mutation_batch.d.ts +2 -3
  101. package/dist/packages/firestore/src/util/async_queue.d.ts +5 -1
  102. package/dist/packages/firestore/test/unit/local/index_backfiller.test.d.ts +17 -0
  103. package/dist/packages/firestore/test/unit/local/test_document_overlay_cache.d.ts +1 -1
  104. package/dist/packages/firestore/test/unit/specs/spec_test_components.d.ts +5 -3
  105. package/dist/packages/firestore/test/util/helpers.d.ts +1 -0
  106. package/dist/private.d.ts +146 -16
  107. package/package.json +9 -9
@@ -984,7 +984,7 @@ declare interface DocumentOverlayCache {
984
984
  * Gets the saved overlay mutation for the given document keys. Skips keys for
985
985
  * which there are no overlays.
986
986
  */
987
- getOverlays(transaction: PersistenceTransaction, keys: DocumentKeySet): PersistencePromise<OverlayMap>;
987
+ getOverlays(transaction: PersistenceTransaction, keys: _DocumentKey[]): PersistencePromise<OverlayMap>;
988
988
  /**
989
989
  * Saves the given document mutation map to persistence as overlays.
990
990
  * All overlays will have their largest batch id set to `largestBatchId`.
@@ -2253,16 +2253,6 @@ declare interface FirstPartyCredentialsSettings {
2253
2253
  */
2254
2254
  declare type FulfilledHandler<T, R> = ((result: T) => R | PersistencePromise<R>) | null;
2255
2255
 
2256
- /**
2257
- * Interface implemented by the LRU scheduler to start(), stop() and restart
2258
- * garbage collection.
2259
- */
2260
- declare interface GarbageCollectionScheduler {
2261
- readonly started: boolean;
2262
- start(localStore: LocalStore): void;
2263
- stop(): void;
2264
- }
2265
-
2266
2256
  /**
2267
2257
  * @license
2268
2258
  * Copyright 2017 Google LLC
@@ -2560,6 +2550,8 @@ declare interface IndexManager {
2560
2550
  * and returns the minimum offset of them all.
2561
2551
  */
2562
2552
  getMinOffset(transaction: PersistenceTransaction, target: Target): PersistencePromise<IndexOffset>;
2553
+ /** Returns the minimum offset for the given collection group. */
2554
+ getMinOffsetFromCollectionGroup(transaction: PersistenceTransaction, collectionGroup: string): PersistencePromise<IndexOffset>;
2563
2555
  }
2564
2556
 
2565
2557
  /**
@@ -2834,8 +2826,119 @@ export declare interface LoadBundleTaskProgress {
2834
2826
  taskState: TaskState;
2835
2827
  }
2836
2828
 
2829
+ /**
2830
+ * A readonly view of the local state of all documents we're tracking (i.e. we
2831
+ * have a cached version in remoteDocumentCache or local mutations for the
2832
+ * document). The view is computed by applying the mutations in the
2833
+ * MutationQueue to the RemoteDocumentCache.
2834
+ */
2835
+ declare class LocalDocumentsView {
2836
+ readonly remoteDocumentCache: RemoteDocumentCache;
2837
+ readonly mutationQueue: MutationQueue;
2838
+ readonly documentOverlayCache: DocumentOverlayCache;
2839
+ readonly indexManager: IndexManager;
2840
+ constructor(remoteDocumentCache: RemoteDocumentCache, mutationQueue: MutationQueue, documentOverlayCache: DocumentOverlayCache, indexManager: IndexManager);
2841
+ /**
2842
+ * Get the local view of the document identified by `key`.
2843
+ *
2844
+ * @returns Local view of the document or null if we don't have any cached
2845
+ * state for it.
2846
+ */
2847
+ getDocument(transaction: PersistenceTransaction, key: _DocumentKey): PersistencePromise<Document_2>;
2848
+ /**
2849
+ * Gets the local view of the documents identified by `keys`.
2850
+ *
2851
+ * If we don't have cached state for a document in `keys`, a NoDocument will
2852
+ * be stored for that key in the resulting set.
2853
+ */
2854
+ getDocuments(transaction: PersistenceTransaction, keys: DocumentKeySet): PersistencePromise<DocumentMap>;
2855
+ /**
2856
+ * Similar to `getDocuments`, but creates the local view from the given
2857
+ * `baseDocs` without retrieving documents from the local store.
2858
+ *
2859
+ * @param transaction - The transaction this operation is scoped to.
2860
+ * @param docs - The documents to apply local mutations to get the local views.
2861
+ * @param existenceStateChanged - The set of document keys whose existence state
2862
+ * is changed. This is useful to determine if some documents overlay needs
2863
+ * to be recalculated.
2864
+ */
2865
+ getLocalViewOfDocuments(transaction: PersistenceTransaction, docs: MutableDocumentMap, existenceStateChanged?: DocumentKeySet): PersistencePromise<DocumentMap>;
2866
+ /**
2867
+ * Gets the overlayed documents for the given document map, which will include
2868
+ * the local view of those documents and a `FieldMask` indicating which fields
2869
+ * are mutated locally, `null` if overlay is a Set or Delete mutation.
2870
+ */
2871
+ getOverlayedDocuments(transaction: PersistenceTransaction, docs: MutableDocumentMap): PersistencePromise<OverlayedDocumentMap>;
2872
+ /**
2873
+ * Fetches the overlays for {@code docs} and adds them to provided overlay map
2874
+ * if the map does not already contain an entry for the given document key.
2875
+ */
2876
+ private populateOverlays;
2877
+ /**
2878
+ * Computes the local view for the given documents.
2879
+ *
2880
+ * @param docs - The documents to compute views for. It also has the base
2881
+ * version of the documents.
2882
+ * @param overlays - The overlays that need to be applied to the given base
2883
+ * version of the documents.
2884
+ * @param existenceStateChanged - A set of documents whose existence states
2885
+ * might have changed. This is used to determine if we need to re-calculate
2886
+ * overlays from mutation queues.
2887
+ * @return A map represents the local documents view.
2888
+ */
2889
+ computeViews(transaction: PersistenceTransaction, docs: MutableDocumentMap, overlays: OverlayMap, existenceStateChanged: DocumentKeySet): PersistencePromise<OverlayedDocumentMap>;
2890
+ private recalculateAndSaveOverlays;
2891
+ /**
2892
+ * Recalculates overlays by reading the documents from remote document cache
2893
+ * first, and saves them after they are calculated.
2894
+ */
2895
+ recalculateAndSaveOverlaysForDocumentKeys(transaction: PersistenceTransaction, documentKeys: DocumentKeySet): PersistencePromise<DocumentKeyMap<FieldMask | null>>;
2896
+ /**
2897
+ * Performs a query against the local view of all documents.
2898
+ *
2899
+ * @param transaction - The persistence transaction.
2900
+ * @param query - The query to match documents against.
2901
+ * @param offset - Read time and key to start scanning by (exclusive).
2902
+ */
2903
+ getDocumentsMatchingQuery(transaction: PersistenceTransaction, query: Query_2, offset: IndexOffset): PersistencePromise<DocumentMap>;
2904
+ /**
2905
+ * Given a collection group, returns the next documents that follow the provided offset, along
2906
+ * with an updated batch ID.
2907
+ *
2908
+ * <p>The documents returned by this method are ordered by remote version from the provided
2909
+ * offset. If there are no more remote documents after the provided offset, documents with
2910
+ * mutations in order of batch id from the offset are returned. Since all documents in a batch are
2911
+ * returned together, the total number of documents returned can exceed {@code count}.
2912
+ *
2913
+ * @param transaction
2914
+ * @param collectionGroup The collection group for the documents.
2915
+ * @param offset The offset to index into.
2916
+ * @param count The number of documents to return
2917
+ * @return A LocalWriteResult with the documents that follow the provided offset and the last processed batch id.
2918
+ */
2919
+ getNextDocuments(transaction: PersistenceTransaction, collectionGroup: string, offset: IndexOffset, count: number): PersistencePromise<LocalWriteResult>;
2920
+ private getDocumentsMatchingDocumentQuery;
2921
+ private getDocumentsMatchingCollectionGroupQuery;
2922
+ private getDocumentsMatchingCollectionQuery;
2923
+ /** Returns a base document that can be used to apply `overlay`. */
2924
+ private getBaseDocument;
2925
+ }
2926
+
2837
2927
  declare interface LocalStore {
2838
2928
  collectGarbage(garbageCollector: LruGarbageCollector): Promise<LruResults>;
2929
+ /** Manages the list of active field and collection indices. */
2930
+ indexManager: IndexManager;
2931
+ /**
2932
+ * The "local" view of all documents (layering mutationQueue on top of
2933
+ * remoteDocumentCache).
2934
+ */
2935
+ localDocuments: LocalDocumentsView;
2936
+ }
2937
+
2938
+ /** The result of a write to the local store. */
2939
+ declare interface LocalWriteResult {
2940
+ batchId: BatchId;
2941
+ changes: DocumentMap;
2839
2942
  }
2840
2943
  export { LogLevel }
2841
2944
 
@@ -3061,7 +3164,7 @@ declare class MutationBatch {
3061
3164
  * this batch. Returns a `DocumentKey` to `Mutation` map which can be used to
3062
3165
  * replace all the mutation applications.
3063
3166
  */
3064
- applyToLocalDocumentSet(documentMap: DocumentKeyMap<OverlayedDocument>, documentsWithoutRemoteVersion: DocumentKeySet): MutationMap;
3167
+ applyToLocalDocumentSet(documentMap: OverlayedDocumentMap, documentsWithoutRemoteVersion: DocumentKeySet): MutationMap;
3065
3168
  keys(): DocumentKeySet;
3066
3169
  isEqual(other: MutationBatch): boolean;
3067
3170
  }
@@ -3085,7 +3188,7 @@ declare class MutationBatchResult {
3085
3188
  static from(batch: MutationBatch, commitVersion: SnapshotVersion, results: MutationResult[]): MutationBatchResult;
3086
3189
  }
3087
3190
 
3088
- declare type MutationMap = ObjectMap<_DocumentKey, Mutation>;
3191
+ declare type MutationMap = DocumentKeyMap<Mutation>;
3089
3192
 
3090
3193
  /** A queue of mutations to apply to the remote store. */
3091
3194
  declare interface MutationQueue {
@@ -3391,7 +3494,8 @@ declare interface OfflineComponentProvider {
3391
3494
  persistence: Persistence;
3392
3495
  sharedClientState: SharedClientState;
3393
3496
  localStore: LocalStore;
3394
- gcScheduler: GarbageCollectionScheduler | null;
3497
+ gcScheduler: Scheduler | null;
3498
+ indexBackfillerScheduler: Scheduler | null;
3395
3499
  synchronizeTabs: boolean;
3396
3500
  initialize(cfg: ComponentConfiguration): Promise<void>;
3397
3501
  terminate(): Promise<void>;
@@ -3713,7 +3817,9 @@ declare class OverlayedDocument {
3713
3817
  mutatedFields: FieldMask | null);
3714
3818
  }
3715
3819
 
3716
- declare type OverlayMap = ObjectMap<_DocumentKey, Overlay>;
3820
+ declare type OverlayedDocumentMap = DocumentKeyMap<OverlayedDocument>;
3821
+
3822
+ declare type OverlayMap = DocumentKeyMap<Overlay>;
3717
3823
 
3718
3824
  declare interface ParseContext {
3719
3825
  readonly databaseId: _DatabaseId;
@@ -3932,6 +4038,17 @@ declare class PersistencePromise<T> {
3932
4038
  static forEach<R>(collection: {
3933
4039
  forEach: (cb: (r: R) => void) => void;
3934
4040
  }, f: (r: R) => PersistencePromise<void>): PersistencePromise<void>;
4041
+ /**
4042
+ * Concurrently map all array elements through asynchronous function.
4043
+ */
4044
+ static mapArray<T, U>(array: T[], f: (t: T) => PersistencePromise<U>): PersistencePromise<U[]>;
4045
+ /**
4046
+ * An alternative to recursive PersistencePromise calls, that avoids
4047
+ * potential memory problems from unbounded chains of promises.
4048
+ *
4049
+ * The `action` will be called repeatedly while `condition` is true.
4050
+ */
4051
+ static doWhile(condition: () => boolean, action: () => PersistencePromise<void>): PersistencePromise<void>;
3935
4052
  }
3936
4053
 
3937
4054
  /**
@@ -4565,6 +4682,15 @@ export declare class _ResourcePath extends BasePath<_ResourcePath> {
4565
4682
  */
4566
4683
  export declare function runTransaction<T>(firestore: Firestore, updateFunction: (transaction: Transaction) => Promise<T>, options?: TransactionOptions): Promise<T>;
4567
4684
 
4685
+ /**
4686
+ * Interface to schedule periodic tasks within SDK.
4687
+ */
4688
+ declare interface Scheduler {
4689
+ readonly started: boolean;
4690
+ start(): void;
4691
+ stop(): void;
4692
+ }
4693
+
4568
4694
  /**
4569
4695
  * Returns a sentinel used with {@link @firebase/firestore/lite#(setDoc:1)} or {@link @firebase/firestore/lite#(updateDoc:1)} to
4570
4696
  * include a server-generated timestamp in the written data.
@@ -5404,7 +5530,11 @@ declare const enum TimerId {
5404
5530
  * A timer used to retry operations scheduled via retryable AsyncQueue
5405
5531
  * operations.
5406
5532
  */
5407
- AsyncQueueRetry = "async_queue_retry"
5533
+ AsyncQueueRetry = "async_queue_retry",
5534
+ /**
5535
+ * A timer used to periodically attempt index backfill.
5536
+ */
5537
+ IndexBackfill = "index_backfill"
5408
5538
  }
5409
5539
 
5410
5540
  /**
@@ -18,7 +18,7 @@ import { CredentialsProvider } from '../api/credentials';
18
18
  import { User } from '../auth/user';
19
19
  import { IndexedDbPersistence } from '../local/indexeddb_persistence';
20
20
  import { LocalStore } from '../local/local_store';
21
- import { GarbageCollectionScheduler, Persistence } from '../local/persistence';
21
+ import { Scheduler, Persistence } from '../local/persistence';
22
22
  import { ClientId, SharedClientState } from '../local/shared_client_state';
23
23
  import { Datastore } from '../remote/datastore';
24
24
  import { RemoteStore } from '../remote/remote_store';
@@ -44,7 +44,8 @@ export interface OfflineComponentProvider {
44
44
  persistence: Persistence;
45
45
  sharedClientState: SharedClientState;
46
46
  localStore: LocalStore;
47
- gcScheduler: GarbageCollectionScheduler | null;
47
+ gcScheduler: Scheduler | null;
48
+ indexBackfillerScheduler: Scheduler | null;
48
49
  synchronizeTabs: boolean;
49
50
  initialize(cfg: ComponentConfiguration): Promise<void>;
50
51
  terminate(): Promise<void>;
@@ -57,11 +58,13 @@ export declare class MemoryOfflineComponentProvider implements OfflineComponentP
57
58
  persistence: Persistence;
58
59
  sharedClientState: SharedClientState;
59
60
  localStore: LocalStore;
60
- gcScheduler: GarbageCollectionScheduler | null;
61
+ gcScheduler: Scheduler | null;
62
+ indexBackfillerScheduler: Scheduler | null;
61
63
  synchronizeTabs: boolean;
62
64
  serializer: JsonProtoSerializer;
63
65
  initialize(cfg: ComponentConfiguration): Promise<void>;
64
- createGarbageCollectionScheduler(cfg: ComponentConfiguration): GarbageCollectionScheduler | null;
66
+ createGarbageCollectionScheduler(cfg: ComponentConfiguration, localStore: LocalStore): Scheduler | null;
67
+ createIndexBackfillerScheduler(cfg: ComponentConfiguration, localStore: LocalStore): Scheduler | null;
65
68
  createLocalStore(cfg: ComponentConfiguration): LocalStore;
66
69
  createPersistence(cfg: ComponentConfiguration): Persistence;
67
70
  createSharedClientState(cfg: ComponentConfiguration): SharedClientState;
@@ -77,12 +80,14 @@ export declare class IndexedDbOfflineComponentProvider extends MemoryOfflineComp
77
80
  persistence: IndexedDbPersistence;
78
81
  sharedClientState: SharedClientState;
79
82
  localStore: LocalStore;
80
- gcScheduler: GarbageCollectionScheduler | null;
83
+ gcScheduler: Scheduler | null;
84
+ indexBackfillerScheduler: Scheduler | null;
81
85
  synchronizeTabs: boolean;
82
86
  constructor(onlineComponentProvider: OnlineComponentProvider, cacheSizeBytes: number | undefined, forceOwnership: boolean | undefined);
83
87
  initialize(cfg: ComponentConfiguration): Promise<void>;
84
88
  createLocalStore(cfg: ComponentConfiguration): LocalStore;
85
- createGarbageCollectionScheduler(cfg: ComponentConfiguration): GarbageCollectionScheduler | null;
89
+ createGarbageCollectionScheduler(cfg: ComponentConfiguration, localStore: LocalStore): Scheduler | null;
90
+ createIndexBackfillerScheduler(cfg: ComponentConfiguration, localStore: LocalStore): Scheduler | null;
86
91
  createPersistence(cfg: ComponentConfiguration): IndexedDbPersistence;
87
92
  createSharedClientState(cfg: ComponentConfiguration): SharedClientState;
88
93
  }
@@ -40,7 +40,7 @@ export interface DocumentOverlayCache {
40
40
  * Gets the saved overlay mutation for the given document keys. Skips keys for
41
41
  * which there are no overlays.
42
42
  */
43
- getOverlays(transaction: PersistenceTransaction, keys: DocumentKeySet): PersistencePromise<OverlayMap>;
43
+ getOverlays(transaction: PersistenceTransaction, keys: DocumentKey[]): PersistencePromise<OverlayMap>;
44
44
  /**
45
45
  * Saves the given document mutation map to persistence as overlays.
46
46
  * All overlays will have their largest batch id set to `largestBatchId`.
@@ -0,0 +1,44 @@
1
+ import { AsyncQueue } from '../util/async_queue';
2
+ import { LocalStore } from './local_store';
3
+ import { Persistence, Scheduler } from './persistence';
4
+ /** This class is responsible for the scheduling of Index Backfiller. */
5
+ export declare class IndexBackfillerScheduler implements Scheduler {
6
+ private readonly asyncQueue;
7
+ private readonly backfiller;
8
+ private task;
9
+ constructor(asyncQueue: AsyncQueue, backfiller: IndexBackfiller);
10
+ start(): void;
11
+ stop(): void;
12
+ get started(): boolean;
13
+ private schedule;
14
+ }
15
+ /** Implements the steps for backfilling indexes. */
16
+ export declare class IndexBackfiller {
17
+ /**
18
+ * LocalStore provides access to IndexManager and LocalDocumentView.
19
+ * These properties will update when the user changes. Consequently,
20
+ * making a local copy of IndexManager and LocalDocumentView will require
21
+ * updates over time. The simpler solution is to rely on LocalStore to have
22
+ * an up-to-date references to IndexManager and LocalDocumentStore.
23
+ */
24
+ private readonly localStore;
25
+ private readonly persistence;
26
+ constructor(
27
+ /**
28
+ * LocalStore provides access to IndexManager and LocalDocumentView.
29
+ * These properties will update when the user changes. Consequently,
30
+ * making a local copy of IndexManager and LocalDocumentView will require
31
+ * updates over time. The simpler solution is to rely on LocalStore to have
32
+ * an up-to-date references to IndexManager and LocalDocumentStore.
33
+ */
34
+ localStore: LocalStore, persistence: Persistence);
35
+ backfill(maxDocumentsToProcess?: number): Promise<number>;
36
+ /** Writes index entries until the cap is reached. Returns the number of documents processed. */
37
+ private writeIndexEntries;
38
+ /**
39
+ * Writes entries for the provided collection group. Returns the number of documents processed.
40
+ */
41
+ private writeEntriesForCollectionGroup;
42
+ /** Returns the next offset based on the provided documents. */
43
+ private getNewOffset;
44
+ }
@@ -114,4 +114,6 @@ export interface IndexManager {
114
114
  * and returns the minimum offset of them all.
115
115
  */
116
116
  getMinOffset(transaction: PersistenceTransaction, target: Target): PersistencePromise<IndexOffset>;
117
+ /** Returns the minimum offset for the given collection group. */
118
+ getMinOffsetFromCollectionGroup(transaction: PersistenceTransaction, collectionGroup: string): PersistencePromise<IndexOffset>;
117
119
  }
@@ -36,7 +36,7 @@ export declare class IndexedDbDocumentOverlayCache implements DocumentOverlayCac
36
36
  constructor(serializer: LocalSerializer, userId: string);
37
37
  static forUser(serializer: LocalSerializer, user: User): IndexedDbDocumentOverlayCache;
38
38
  getOverlay(transaction: PersistenceTransaction, key: DocumentKey): PersistencePromise<Overlay | null>;
39
- getOverlays(transaction: PersistenceTransaction, keys: DocumentKeySet): PersistencePromise<OverlayMap>;
39
+ getOverlays(transaction: PersistenceTransaction, keys: DocumentKey[]): PersistencePromise<OverlayMap>;
40
40
  saveOverlays(transaction: PersistenceTransaction, largestBatchId: number, overlays: MutationMap): PersistencePromise<void>;
41
41
  removeOverlaysForBatchId(transaction: PersistenceTransaction, documentKeys: DocumentKeySet, batchId: number): PersistencePromise<void>;
42
42
  getOverlaysForCollection(transaction: PersistenceTransaction, collection: ResourcePath, sinceBatchId: number): PersistencePromise<OverlayMap>;
@@ -128,5 +128,6 @@ export declare class IndexedDbIndexManager implements IndexManager {
128
128
  * '[foo > 2 && foo != 3]` becomes `[foo > 2 && < 3, foo > 3]`.
129
129
  */
130
130
  private createRange;
131
+ getMinOffsetFromCollectionGroup(transaction: PersistenceTransaction, collectionGroup: string): PersistencePromise<IndexOffset>;
131
132
  getMinOffset(transaction: PersistenceTransaction, target: Target): PersistencePromise<IndexOffset>;
132
133
  }
@@ -15,15 +15,15 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  import { Query } from '../core/query';
18
- import { DocumentKeySet, OverlayMap, DocumentMap, MutableDocumentMap, DocumentKeyMap } from '../model/collections';
18
+ import { DocumentKeySet, OverlayMap, DocumentMap, MutableDocumentMap, DocumentKeyMap, OverlayedDocumentMap } from '../model/collections';
19
19
  import { Document } from '../model/document';
20
20
  import { DocumentKey } from '../model/document_key';
21
21
  import { IndexOffset } from '../model/field_index';
22
22
  import { FieldMask } from '../model/field_mask';
23
23
  import { DocumentOverlayCache } from './document_overlay_cache';
24
24
  import { IndexManager } from './index_manager';
25
+ import { LocalWriteResult } from './local_store_impl';
25
26
  import { MutationQueue } from './mutation_queue';
26
- import { OverlayedDocument } from './overlayed_document';
27
27
  import { PersistencePromise } from './persistence_promise';
28
28
  import { PersistenceTransaction } from './persistence_transaction';
29
29
  import { RemoteDocumentCache } from './remote_document_cache';
@@ -69,7 +69,7 @@ export declare class LocalDocumentsView {
69
69
  * the local view of those documents and a `FieldMask` indicating which fields
70
70
  * are mutated locally, `null` if overlay is a Set or Delete mutation.
71
71
  */
72
- getOverlayedDocuments(transaction: PersistenceTransaction, docs: MutableDocumentMap): PersistencePromise<DocumentKeyMap<OverlayedDocument>>;
72
+ getOverlayedDocuments(transaction: PersistenceTransaction, docs: MutableDocumentMap): PersistencePromise<OverlayedDocumentMap>;
73
73
  /**
74
74
  * Fetches the overlays for {@code docs} and adds them to provided overlay map
75
75
  * if the map does not already contain an entry for the given document key.
@@ -87,7 +87,7 @@ export declare class LocalDocumentsView {
87
87
  * overlays from mutation queues.
88
88
  * @return A map represents the local documents view.
89
89
  */
90
- computeViews(transaction: PersistenceTransaction, docs: MutableDocumentMap, overlays: OverlayMap, existenceStateChanged: DocumentKeySet): PersistencePromise<DocumentKeyMap<OverlayedDocument>>;
90
+ computeViews(transaction: PersistenceTransaction, docs: MutableDocumentMap, overlays: OverlayMap, existenceStateChanged: DocumentKeySet): PersistencePromise<OverlayedDocumentMap>;
91
91
  private recalculateAndSaveOverlays;
92
92
  /**
93
93
  * Recalculates overlays by reading the documents from remote document cache
@@ -102,6 +102,22 @@ export declare class LocalDocumentsView {
102
102
  * @param offset - Read time and key to start scanning by (exclusive).
103
103
  */
104
104
  getDocumentsMatchingQuery(transaction: PersistenceTransaction, query: Query, offset: IndexOffset): PersistencePromise<DocumentMap>;
105
+ /**
106
+ * Given a collection group, returns the next documents that follow the provided offset, along
107
+ * with an updated batch ID.
108
+ *
109
+ * <p>The documents returned by this method are ordered by remote version from the provided
110
+ * offset. If there are no more remote documents after the provided offset, documents with
111
+ * mutations in order of batch id from the offset are returned. Since all documents in a batch are
112
+ * returned together, the total number of documents returned can exceed {@code count}.
113
+ *
114
+ * @param transaction
115
+ * @param collectionGroup The collection group for the documents.
116
+ * @param offset The offset to index into.
117
+ * @param count The number of documents to return
118
+ * @return A LocalWriteResult with the documents that follow the provided offset and the last processed batch id.
119
+ */
120
+ getNextDocuments(transaction: PersistenceTransaction, collectionGroup: string, offset: IndexOffset, count: number): PersistencePromise<LocalWriteResult>;
105
121
  private getDocumentsMatchingDocumentQuery;
106
122
  private getDocumentsMatchingCollectionGroupQuery;
107
123
  private getDocumentsMatchingCollectionQuery;
@@ -15,9 +15,18 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  import { FirestoreError } from '../util/error';
18
+ import { IndexManager } from './index_manager';
19
+ import { LocalDocumentsView } from './local_documents_view';
18
20
  import { LruGarbageCollector, LruResults } from './lru_garbage_collector';
19
21
  export interface LocalStore {
20
22
  collectGarbage(garbageCollector: LruGarbageCollector): Promise<LruResults>;
23
+ /** Manages the list of active field and collection indices. */
24
+ indexManager: IndexManager;
25
+ /**
26
+ * The "local" view of all documents (layering mutationQueue on top of
27
+ * remoteDocumentCache).
28
+ */
29
+ localDocuments: LocalDocumentsView;
21
30
  }
22
31
  /**
23
32
  * Verifies the error thrown by a LocalStore operation. If a LocalStore
@@ -17,19 +17,19 @@
17
17
  import { AsyncQueue } from '../util/async_queue';
18
18
  import { LocalStore } from './local_store';
19
19
  import { LruDelegate, LruGarbageCollector, LruParams } from './lru_garbage_collector';
20
- import { GarbageCollectionScheduler } from './persistence';
20
+ import { Scheduler } from './persistence';
21
21
  export declare const LRU_MINIMUM_CACHE_SIZE_BYTES: number;
22
22
  /**
23
23
  * This class is responsible for the scheduling of LRU garbage collection. It handles checking
24
24
  * whether or not GC is enabled, as well as which delay to use before the next run.
25
25
  */
26
- export declare class LruScheduler implements GarbageCollectionScheduler {
26
+ export declare class LruScheduler implements Scheduler {
27
27
  private readonly garbageCollector;
28
28
  private readonly asyncQueue;
29
- private hasRun;
29
+ private readonly localStore;
30
30
  private gcTask;
31
- constructor(garbageCollector: LruGarbageCollector, asyncQueue: AsyncQueue);
32
- start(localStore: LocalStore): void;
31
+ constructor(garbageCollector: LruGarbageCollector, asyncQueue: AsyncQueue, localStore: LocalStore);
32
+ start(): void;
33
33
  stop(): void;
34
34
  get started(): boolean;
35
35
  private scheduleGC;
@@ -28,7 +28,7 @@ export declare class MemoryDocumentOverlayCache implements DocumentOverlayCache
28
28
  private overlays;
29
29
  private overlayByBatchId;
30
30
  getOverlay(transaction: PersistenceTransaction, key: DocumentKey): PersistencePromise<Overlay | null>;
31
- getOverlays(transaction: PersistenceTransaction, keys: DocumentKeySet): PersistencePromise<OverlayMap>;
31
+ getOverlays(transaction: PersistenceTransaction, keys: DocumentKey[]): PersistencePromise<OverlayMap>;
32
32
  saveOverlays(transaction: PersistenceTransaction, largestBatchId: number, overlays: MutationMap): PersistencePromise<void>;
33
33
  removeOverlaysForBatchId(transaction: PersistenceTransaction, documentKeys: DocumentKeySet, batchId: number): PersistencePromise<void>;
34
34
  getOverlaysForCollection(transaction: PersistenceTransaction, collection: ResourcePath, sinceBatchId: number): PersistencePromise<OverlayMap>;
@@ -36,6 +36,7 @@ export declare class MemoryIndexManager implements IndexManager {
36
36
  getFieldIndexes(transaction: PersistenceTransaction, collectionGroup?: string): PersistencePromise<FieldIndex[]>;
37
37
  getNextCollectionGroupToUpdate(transaction: PersistenceTransaction): PersistencePromise<string | null>;
38
38
  getMinOffset(transaction: PersistenceTransaction, target: Target): PersistencePromise<IndexOffset>;
39
+ getMinOffsetFromCollectionGroup(transaction: PersistenceTransaction, collectionGroup: string): PersistencePromise<IndexOffset>;
39
40
  updateCollectionGroup(transaction: PersistenceTransaction, collectionGroup: string, offset: IndexOffset): PersistencePromise<void>;
40
41
  updateIndexEntries(transaction: PersistenceTransaction, documents: DocumentMap): PersistencePromise<void>;
41
42
  }
@@ -20,7 +20,6 @@ import { DocumentKey } from '../model/document_key';
20
20
  import { BundleCache } from './bundle_cache';
21
21
  import { DocumentOverlayCache } from './document_overlay_cache';
22
22
  import { IndexManager } from './index_manager';
23
- import { LocalStore } from './local_store';
24
23
  import { MutationQueue } from './mutation_queue';
25
24
  import { PersistencePromise } from './persistence_promise';
26
25
  import { PersistenceTransaction, PersistenceTransactionMode } from './persistence_transaction';
@@ -204,11 +203,10 @@ export interface Persistence {
204
203
  runTransaction<T>(action: string, mode: PersistenceTransactionMode, transactionOperation: (transaction: PersistenceTransaction) => PersistencePromise<T>): Promise<T>;
205
204
  }
206
205
  /**
207
- * Interface implemented by the LRU scheduler to start(), stop() and restart
208
- * garbage collection.
206
+ * Interface to schedule periodic tasks within SDK.
209
207
  */
210
- export interface GarbageCollectionScheduler {
208
+ export interface Scheduler {
211
209
  readonly started: boolean;
212
- start(localStore: LocalStore): void;
210
+ start(): void;
213
211
  stop(): void;
214
212
  }
@@ -69,4 +69,15 @@ export declare class PersistencePromise<T> {
69
69
  static forEach<R>(collection: {
70
70
  forEach: (cb: (r: R) => void) => void;
71
71
  }, f: (r: R) => PersistencePromise<void>): PersistencePromise<void>;
72
+ /**
73
+ * Concurrently map all array elements through asynchronous function.
74
+ */
75
+ static mapArray<T, U>(array: T[], f: (t: T) => PersistencePromise<U>): PersistencePromise<U[]>;
76
+ /**
77
+ * An alternative to recursive PersistencePromise calls, that avoids
78
+ * potential memory problems from unbounded chains of promises.
79
+ *
80
+ * The `action` will be called repeatedly while `condition` is true.
81
+ */
82
+ static doWhile(condition: () => boolean, action: () => PersistencePromise<void>): PersistencePromise<void>;
72
83
  }
@@ -16,6 +16,7 @@
16
16
  */
17
17
  import { SnapshotVersion } from '../core/snapshot_version';
18
18
  import { TargetId } from '../core/types';
19
+ import { OverlayedDocument } from '../local/overlayed_document';
19
20
  import { ObjectMap } from '../util/obj_map';
20
21
  import { SortedMap } from '../util/sorted_map';
21
22
  import { SortedSet } from '../util/sorted_set';
@@ -32,9 +33,12 @@ export interface DocumentSizeEntries {
32
33
  }
33
34
  export declare type DocumentMap = SortedMap<DocumentKey, Document>;
34
35
  export declare function documentMap(...docs: Document[]): DocumentMap;
35
- export declare type OverlayMap = ObjectMap<DocumentKey, Overlay>;
36
+ export declare type OverlayedDocumentMap = DocumentKeyMap<OverlayedDocument>;
37
+ export declare function newOverlayedDocumentMap(): OverlayedDocumentMap;
38
+ export declare function convertOverlayedDocumentMapToDocumentMap(collection: OverlayedDocumentMap): DocumentMap;
39
+ export declare type OverlayMap = DocumentKeyMap<Overlay>;
36
40
  export declare function newOverlayMap(): OverlayMap;
37
- export declare type MutationMap = ObjectMap<DocumentKey, Mutation>;
41
+ export declare type MutationMap = DocumentKeyMap<Mutation>;
38
42
  export declare function newMutationMap(): MutationMap;
39
43
  export declare type DocumentKeyMap<T> = ObjectMap<DocumentKey, T>;
40
44
  export declare function newDocumentKeyMap<T>(): DocumentKeyMap<T>;
@@ -17,8 +17,7 @@
17
17
  import { SnapshotVersion } from '../core/snapshot_version';
18
18
  import { BatchId } from '../core/types';
19
19
  import { Timestamp } from '../lite-api/timestamp';
20
- import { OverlayedDocument } from '../local/overlayed_document';
21
- import { DocumentKeySet, MutationMap, DocumentVersionMap, DocumentKeyMap } from './collections';
20
+ import { DocumentKeySet, MutationMap, DocumentVersionMap, OverlayedDocumentMap } from './collections';
22
21
  import { MutableDocument } from './document';
23
22
  import { FieldMask } from './field_mask';
24
23
  import { Mutation, MutationResult } from './mutation';
@@ -65,7 +64,7 @@ export declare class MutationBatch {
65
64
  * this batch. Returns a `DocumentKey` to `Mutation` map which can be used to
66
65
  * replace all the mutation applications.
67
66
  */
68
- applyToLocalDocumentSet(documentMap: DocumentKeyMap<OverlayedDocument>, documentsWithoutRemoteVersion: DocumentKeySet): MutationMap;
67
+ applyToLocalDocumentSet(documentMap: OverlayedDocumentMap, documentsWithoutRemoteVersion: DocumentKeySet): MutationMap;
69
68
  keys(): DocumentKeySet;
70
69
  isEqual(other: MutationBatch): boolean;
71
70
  }
@@ -59,7 +59,11 @@ export declare const enum TimerId {
59
59
  * A timer used to retry operations scheduled via retryable AsyncQueue
60
60
  * operations.
61
61
  */
62
- AsyncQueueRetry = "async_queue_retry"
62
+ AsyncQueueRetry = "async_queue_retry",
63
+ /**
64
+ * A timer used to periodically attempt index backfill.
65
+ */
66
+ IndexBackfill = "index_backfill"
63
67
  }
64
68
  /**
65
69
  * Represents an operation scheduled to be run in the future on an AsyncQueue.
@@ -0,0 +1,17 @@
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
+ export {};
@@ -31,7 +31,7 @@ export declare class TestDocumentOverlayCache {
31
31
  constructor(persistence: Persistence, cache: DocumentOverlayCache);
32
32
  saveOverlays(largestBatch: number, data: MutationMap): Promise<void>;
33
33
  getOverlay(key: DocumentKey): Promise<Overlay | null>;
34
- getOverlays(keys: DocumentKeySet): Promise<OverlayMap>;
34
+ getOverlays(keys: DocumentKey[]): Promise<OverlayMap>;
35
35
  getOverlayMutation(docKey: string): Promise<Mutation | null>;
36
36
  getOverlaysForCollection(path: ResourcePath, sinceBatchId: number): Promise<OverlayMap>;
37
37
  getOverlaysForCollectionGroup(collectionGroup: string, sinceBatchId: number, count: number): Promise<OverlayMap>;