@firebase/firestore 3.4.4-canary.4cec42313 → 3.4.4-canary.50de44c2e

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 (128) hide show
  1. package/dist/firestore/src/api/snapshot.d.ts +1 -2
  2. package/dist/firestore/src/core/target.d.ts +8 -4
  3. package/dist/firestore/src/lite-api/query.d.ts +2 -2
  4. package/dist/firestore/src/local/index_manager.d.ts +52 -0
  5. package/dist/firestore/src/local/indexeddb_index_manager.d.ts +21 -2
  6. package/dist/firestore/src/local/indexeddb_persistence.d.ts +4 -4
  7. package/dist/firestore/src/local/indexeddb_remote_document_cache.d.ts +2 -8
  8. package/dist/firestore/src/local/indexeddb_schema.d.ts +35 -7
  9. package/dist/firestore/src/local/local_documents_view.d.ts +0 -1
  10. package/dist/firestore/src/local/local_serializer.d.ts +7 -2
  11. package/dist/firestore/src/local/memory_index_manager.d.ts +11 -0
  12. package/dist/firestore/src/local/memory_persistence.d.ts +3 -2
  13. package/dist/firestore/src/local/memory_remote_document_cache.d.ts +1 -3
  14. package/dist/firestore/src/local/persistence.d.ts +2 -2
  15. package/dist/firestore/src/local/remote_document_cache.d.ts +7 -9
  16. package/dist/firestore/src/local/simple_db.d.ts +1 -0
  17. package/dist/firestore/src/model/field_index.d.ts +2 -2
  18. package/dist/firestore/src/model/target_index_matcher.d.ts +70 -0
  19. package/dist/firestore/test/unit/local/counting_query_engine.d.ts +3 -3
  20. package/dist/firestore/test/unit/local/persistence_test_helpers.d.ts +1 -0
  21. package/dist/firestore/test/unit/local/test_index_manager.d.ts +11 -0
  22. package/dist/firestore/test/unit/local/test_remote_document_cache.d.ts +4 -2
  23. package/dist/firestore/test/unit/local/test_remote_document_change_buffer.d.ts +1 -1
  24. package/dist/firestore/test/unit/model/target_index_matcher.test.d.ts +17 -0
  25. package/dist/firestore/test/util/helpers.d.ts +1 -1
  26. package/dist/index.d.ts +1 -2
  27. package/dist/index.esm2017.js +2967 -2808
  28. package/dist/index.esm2017.js.map +1 -1
  29. package/dist/index.esm5.js +2870 -2698
  30. package/dist/index.esm5.js.map +1 -1
  31. package/dist/index.node.cjs.js +397 -203
  32. package/dist/index.node.cjs.js.map +1 -1
  33. package/dist/index.node.mjs +397 -203
  34. package/dist/index.node.mjs.map +1 -1
  35. package/dist/index.rn.js +3215 -3060
  36. package/dist/index.rn.js.map +1 -1
  37. package/dist/internal.d.ts +178 -14
  38. package/dist/lite/firestore/src/api/snapshot.d.ts +1 -2
  39. package/dist/lite/firestore/src/core/target.d.ts +8 -4
  40. package/dist/lite/firestore/src/lite-api/query.d.ts +2 -2
  41. package/dist/lite/firestore/src/local/index_manager.d.ts +52 -0
  42. package/dist/lite/firestore/src/local/indexeddb_index_manager.d.ts +21 -2
  43. package/dist/lite/firestore/src/local/indexeddb_persistence.d.ts +4 -4
  44. package/dist/lite/firestore/src/local/indexeddb_remote_document_cache.d.ts +2 -8
  45. package/dist/lite/firestore/src/local/indexeddb_schema.d.ts +35 -7
  46. package/dist/lite/firestore/src/local/local_documents_view.d.ts +0 -1
  47. package/dist/lite/firestore/src/local/local_serializer.d.ts +7 -2
  48. package/dist/lite/firestore/src/local/memory_index_manager.d.ts +11 -0
  49. package/dist/lite/firestore/src/local/memory_persistence.d.ts +3 -2
  50. package/dist/lite/firestore/src/local/memory_remote_document_cache.d.ts +1 -3
  51. package/dist/lite/firestore/src/local/persistence.d.ts +2 -2
  52. package/dist/lite/firestore/src/local/remote_document_cache.d.ts +7 -9
  53. package/dist/lite/firestore/src/local/simple_db.d.ts +1 -0
  54. package/dist/lite/firestore/src/model/field_index.d.ts +2 -2
  55. package/dist/lite/firestore/src/model/target_index_matcher.d.ts +70 -0
  56. package/dist/lite/firestore/test/unit/local/counting_query_engine.d.ts +3 -3
  57. package/dist/lite/firestore/test/unit/local/persistence_test_helpers.d.ts +1 -0
  58. package/dist/lite/firestore/test/unit/local/test_index_manager.d.ts +11 -0
  59. package/dist/lite/firestore/test/unit/local/test_remote_document_cache.d.ts +4 -2
  60. package/dist/lite/firestore/test/unit/local/test_remote_document_change_buffer.d.ts +1 -1
  61. package/dist/lite/firestore/test/unit/model/target_index_matcher.test.d.ts +17 -0
  62. package/dist/lite/firestore/test/util/helpers.d.ts +1 -1
  63. package/dist/lite/index.browser.esm2017.js +1146 -1143
  64. package/dist/lite/index.browser.esm2017.js.map +1 -1
  65. package/dist/lite/index.browser.esm5.js +332 -331
  66. package/dist/lite/index.browser.esm5.js.map +1 -1
  67. package/dist/lite/index.node.cjs.js +36 -29
  68. package/dist/lite/index.node.cjs.js.map +1 -1
  69. package/dist/lite/index.node.mjs +36 -29
  70. package/dist/lite/index.node.mjs.map +1 -1
  71. package/dist/lite/index.rn.esm2017.js +301 -298
  72. package/dist/lite/index.rn.esm2017.js.map +1 -1
  73. package/dist/lite/internal.d.ts +2 -2
  74. package/dist/lite/packages/firestore/dist/lite/index.browser.esm2017.d.ts +121 -121
  75. package/dist/lite/packages/firestore/src/api/snapshot.d.ts +1 -2
  76. package/dist/lite/packages/firestore/src/core/target.d.ts +8 -4
  77. package/dist/lite/packages/firestore/src/lite-api/query.d.ts +2 -2
  78. package/dist/lite/packages/firestore/src/local/index_manager.d.ts +52 -0
  79. package/dist/lite/packages/firestore/src/local/indexeddb_index_manager.d.ts +21 -2
  80. package/dist/lite/packages/firestore/src/local/indexeddb_persistence.d.ts +4 -4
  81. package/dist/lite/packages/firestore/src/local/indexeddb_remote_document_cache.d.ts +2 -8
  82. package/dist/lite/packages/firestore/src/local/indexeddb_schema.d.ts +35 -7
  83. package/dist/lite/packages/firestore/src/local/local_documents_view.d.ts +0 -1
  84. package/dist/lite/packages/firestore/src/local/local_serializer.d.ts +7 -2
  85. package/dist/lite/packages/firestore/src/local/memory_index_manager.d.ts +11 -0
  86. package/dist/lite/packages/firestore/src/local/memory_persistence.d.ts +3 -2
  87. package/dist/lite/packages/firestore/src/local/memory_remote_document_cache.d.ts +1 -3
  88. package/dist/lite/packages/firestore/src/local/persistence.d.ts +2 -2
  89. package/dist/lite/packages/firestore/src/local/remote_document_cache.d.ts +7 -9
  90. package/dist/lite/packages/firestore/src/local/simple_db.d.ts +1 -0
  91. package/dist/lite/packages/firestore/src/model/field_index.d.ts +2 -2
  92. package/dist/lite/packages/firestore/src/model/target_index_matcher.d.ts +70 -0
  93. package/dist/lite/packages/firestore/test/unit/local/counting_query_engine.d.ts +3 -3
  94. package/dist/lite/packages/firestore/test/unit/local/persistence_test_helpers.d.ts +1 -0
  95. package/dist/lite/packages/firestore/test/unit/local/test_index_manager.d.ts +11 -0
  96. package/dist/lite/packages/firestore/test/unit/local/test_remote_document_cache.d.ts +4 -2
  97. package/dist/lite/packages/firestore/test/unit/local/test_remote_document_change_buffer.d.ts +1 -1
  98. package/dist/lite/packages/firestore/test/unit/model/target_index_matcher.test.d.ts +17 -0
  99. package/dist/lite/packages/firestore/test/util/helpers.d.ts +1 -1
  100. package/dist/lite/private.d.ts +2 -2
  101. package/dist/packages/firestore/dist/index.esm2017.d.ts +143 -143
  102. package/dist/packages/firestore/src/api/snapshot.d.ts +1 -2
  103. package/dist/packages/firestore/src/core/target.d.ts +8 -4
  104. package/dist/packages/firestore/src/lite-api/query.d.ts +2 -2
  105. package/dist/packages/firestore/src/local/index_manager.d.ts +52 -0
  106. package/dist/packages/firestore/src/local/indexeddb_index_manager.d.ts +21 -2
  107. package/dist/packages/firestore/src/local/indexeddb_persistence.d.ts +4 -4
  108. package/dist/packages/firestore/src/local/indexeddb_remote_document_cache.d.ts +2 -8
  109. package/dist/packages/firestore/src/local/indexeddb_schema.d.ts +35 -7
  110. package/dist/packages/firestore/src/local/local_documents_view.d.ts +0 -1
  111. package/dist/packages/firestore/src/local/local_serializer.d.ts +7 -2
  112. package/dist/packages/firestore/src/local/memory_index_manager.d.ts +11 -0
  113. package/dist/packages/firestore/src/local/memory_persistence.d.ts +3 -2
  114. package/dist/packages/firestore/src/local/memory_remote_document_cache.d.ts +1 -3
  115. package/dist/packages/firestore/src/local/persistence.d.ts +2 -2
  116. package/dist/packages/firestore/src/local/remote_document_cache.d.ts +7 -9
  117. package/dist/packages/firestore/src/local/simple_db.d.ts +1 -0
  118. package/dist/packages/firestore/src/model/field_index.d.ts +2 -2
  119. package/dist/packages/firestore/src/model/target_index_matcher.d.ts +70 -0
  120. package/dist/packages/firestore/test/unit/local/counting_query_engine.d.ts +3 -3
  121. package/dist/packages/firestore/test/unit/local/persistence_test_helpers.d.ts +1 -0
  122. package/dist/packages/firestore/test/unit/local/test_index_manager.d.ts +11 -0
  123. package/dist/packages/firestore/test/unit/local/test_remote_document_cache.d.ts +4 -2
  124. package/dist/packages/firestore/test/unit/local/test_remote_document_change_buffer.d.ts +1 -1
  125. package/dist/packages/firestore/test/unit/model/target_index_matcher.test.d.ts +17 -0
  126. package/dist/packages/firestore/test/util/helpers.d.ts +1 -1
  127. package/dist/private.d.ts +178 -14
  128. package/package.json +9 -9
@@ -198,8 +198,7 @@ export declare class DocumentSnapshot<T = DocumentData> extends LiteDocumentSnap
198
198
  /** @hideconstructor protected */
199
199
  constructor(_firestore: Firestore, userDataWriter: AbstractUserDataWriter, key: DocumentKey, document: Document | null, metadata: SnapshotMetadata, converter: UntypedFirestoreDataConverter<T> | null);
200
200
  /**
201
- * Property of the `DocumentSnapshot` that signals whether or not the data
202
- * exists. True if the document exists.
201
+ * Returns whether or not the data exists. True if the document exists.
203
202
  */
204
203
  exists(): this is QueryDocumentSnapshot<T>;
205
204
  /**
@@ -176,10 +176,9 @@ export declare class ArrayContainsAnyFilter extends FieldFilter {
176
176
  */
177
177
  export declare class Bound {
178
178
  readonly position: ProtoValue[];
179
- readonly before: boolean;
180
- constructor(position: ProtoValue[], before: boolean);
179
+ readonly inclusive: boolean;
180
+ constructor(position: ProtoValue[], inclusive: boolean);
181
181
  }
182
- export declare function canonifyBound(bound: Bound): string;
183
182
  /**
184
183
  * An ordering on a field, in some Direction. Direction defaults to ASCENDING.
185
184
  */
@@ -191,9 +190,14 @@ export declare class OrderBy {
191
190
  export declare function canonifyOrderBy(orderBy: OrderBy): string;
192
191
  export declare function stringifyOrderBy(orderBy: OrderBy): string;
193
192
  export declare function orderByEquals(left: OrderBy, right: OrderBy): boolean;
193
+ /**
194
+ * Returns true if a document sorts after a bound using the provided sort
195
+ * order.
196
+ */
197
+ export declare function boundSortsAfterDocument(bound: Bound, orderBy: OrderBy[], doc: Document): boolean;
194
198
  /**
195
199
  * Returns true if a document sorts before a bound using the provided sort
196
200
  * order.
197
201
  */
198
- export declare function sortsBeforeDocument(bound: Bound, orderBy: OrderBy[], doc: Document): boolean;
202
+ export declare function boundSortsBeforeDocument(bound: Bound, orderBy: OrderBy[], doc: Document): boolean;
199
203
  export declare function boundEquals(left: Bound | null, right: Bound | null): boolean;
@@ -196,8 +196,8 @@ export declare function newQueryOrderBy(query: InternalQuery, fieldPath: Interna
196
196
  * of the query or if any of the fields in the order by are an uncommitted
197
197
  * server timestamp.
198
198
  */
199
- export declare function newQueryBoundFromDocument(query: InternalQuery, databaseId: DatabaseId, methodName: string, doc: Document | null, before: boolean): Bound;
199
+ export declare function newQueryBoundFromDocument(query: InternalQuery, databaseId: DatabaseId, methodName: string, doc: Document | null, inclusive: boolean): Bound;
200
200
  /**
201
201
  * Converts a list of field values to a `Bound` for the given query.
202
202
  */
203
- export declare function newQueryBoundFromFields(query: InternalQuery, databaseId: DatabaseId, dataReader: UserDataReader, methodName: string, values: unknown[], before: boolean): Bound;
203
+ export declare function newQueryBoundFromFields(query: InternalQuery, databaseId: DatabaseId, dataReader: UserDataReader, methodName: string, values: unknown[], inclusive: boolean): Bound;
@@ -14,6 +14,9 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
+ import { Target } from '../core/target';
18
+ import { DocumentKeySet, DocumentMap } from '../model/collections';
19
+ import { FieldIndex, IndexOffset } from '../model/field_index';
17
20
  import { ResourcePath } from '../model/path';
18
21
  import { PersistencePromise } from './persistence_promise';
19
22
  import { PersistenceTransaction } from './persistence_transaction';
@@ -40,4 +43,53 @@ export interface IndexManager {
40
43
  * path for a root-level collection).
41
44
  */
42
45
  getCollectionParents(transaction: PersistenceTransaction, collectionId: string): PersistencePromise<ResourcePath[]>;
46
+ /**
47
+ * Adds a field path index.
48
+ *
49
+ * Values for this index are persisted via the index backfill, which runs
50
+ * asynchronously in the background. Once the first values are written,
51
+ * an index can be used to serve partial results for any matching queries.
52
+ * Any unindexed portion of the database will continue to be served via
53
+ * collection scons.
54
+ */
55
+ addFieldIndex(transaction: PersistenceTransaction, index: FieldIndex): PersistencePromise<void>;
56
+ /** Removes the given field index and deletes all index values. */
57
+ deleteFieldIndex(transaction: PersistenceTransaction, index: FieldIndex): PersistencePromise<void>;
58
+ /**
59
+ * Returns a list of field indexes that correspond to the specified collection
60
+ * group.
61
+ *
62
+ * @param collectionGroup The collection group to get matching field indexes
63
+ * for.
64
+ * @return A collection of field indexes for the specified collection group.
65
+ */
66
+ getFieldIndexes(transaction: PersistenceTransaction, collectionGroup: string): PersistencePromise<FieldIndex[]>;
67
+ /** Returns all configured field indexes. */
68
+ getFieldIndexes(transaction: PersistenceTransaction): PersistencePromise<FieldIndex[]>;
69
+ /**
70
+ * Returns an index that can be used to serve the provided target. Returns
71
+ * `null` if no index is configured.
72
+ */
73
+ getFieldIndex(transaction: PersistenceTransaction, target: Target): PersistencePromise<FieldIndex | null>;
74
+ /**
75
+ * Returns the documents that match the given target based on the provided
76
+ * index.
77
+ */
78
+ getDocumentsMatchingTarget(transaction: PersistenceTransaction, fieldIndex: FieldIndex, target: Target): PersistencePromise<DocumentKeySet>;
79
+ /**
80
+ * Returns the next collection group to update. Returns `null` if no group
81
+ * exists.
82
+ */
83
+ getNextCollectionGroupToUpdate(transaction: PersistenceTransaction): PersistencePromise<string | null>;
84
+ /**
85
+ * Sets the collection group's latest read time.
86
+ *
87
+ * This method updates the index offset for all field indices for the
88
+ * collection group and increments their sequence number. Subsequent calls to
89
+ * `getNextCollectionGroupToUpdate()` will return a different collection group
90
+ * (unless only one collection group is configured).
91
+ */
92
+ updateCollectionGroup(transaction: PersistenceTransaction, collectionGroup: string, offset: IndexOffset): PersistencePromise<void>;
93
+ /** Updates the index entries for the provided documents. */
94
+ updateIndexEntries(transaction: PersistenceTransaction, documents: DocumentMap): PersistencePromise<void>;
43
95
  }
@@ -14,22 +14,32 @@
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';
18
+ import { Target } from '../core/target';
19
+ import { DocumentKeySet, DocumentMap } from '../model/collections';
20
+ import { FieldIndex, IndexOffset } from '../model/field_index';
17
21
  import { ResourcePath } from '../model/path';
18
22
  import { IndexManager } from './index_manager';
19
23
  import { PersistencePromise } from './persistence_promise';
20
24
  import { PersistenceTransaction } from './persistence_transaction';
21
25
  /**
22
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.
23
30
  */
24
31
  export declare class IndexedDbIndexManager implements IndexManager {
32
+ private user;
25
33
  /**
26
34
  * An in-memory copy of the index entries we've already written since the SDK
27
35
  * launched. Used to avoid re-writing the same entry repeatedly.
28
36
  *
29
- * This is *NOT* a complete cache of what's in persistence and so can never be used to
30
- * satisfy reads.
37
+ * This is *NOT* a complete cache of what's in persistence and so can never be
38
+ * used to satisfy reads.
31
39
  */
32
40
  private collectionParentsCache;
41
+ private uid;
42
+ constructor(user: User);
33
43
  /**
34
44
  * Adds a new entry to the collection parent index.
35
45
  *
@@ -39,4 +49,13 @@ export declare class IndexedDbIndexManager implements IndexManager {
39
49
  */
40
50
  addToCollectionParentIndex(transaction: PersistenceTransaction, collectionPath: ResourcePath): PersistencePromise<void>;
41
51
  getCollectionParents(transaction: PersistenceTransaction, collectionId: string): PersistencePromise<ResourcePath[]>;
52
+ addFieldIndex(transaction: PersistenceTransaction, index: FieldIndex): PersistencePromise<void>;
53
+ deleteFieldIndex(transaction: PersistenceTransaction, index: FieldIndex): PersistencePromise<void>;
54
+ getDocumentsMatchingTarget(transaction: PersistenceTransaction, fieldIndex: FieldIndex, target: Target): PersistencePromise<DocumentKeySet>;
55
+ getFieldIndex(transaction: PersistenceTransaction, target: Target): PersistencePromise<FieldIndex | null>;
56
+ getFieldIndexes(transaction: PersistenceTransaction, collectionGroup?: string): PersistencePromise<FieldIndex[]>;
57
+ getNextCollectionGroupToUpdate(transaction: PersistenceTransaction): PersistencePromise<string | null>;
58
+ updateCollectionGroup(transaction: PersistenceTransaction, collectionGroup: string, offset: IndexOffset): PersistencePromise<void>;
59
+ updateIndexEntries(transaction: PersistenceTransaction, documents: DocumentMap): PersistencePromise<void>;
60
+ private getNextSequenceNumber;
42
61
  }
@@ -99,6 +99,7 @@ export declare class IndexedDbPersistence implements Persistence {
99
99
  * no longer be able to access IndexedDB.
100
100
  */
101
101
  private readonly forceOwningTab;
102
+ private readonly schemaVersion;
102
103
  private simpleDb;
103
104
  private listenSequence;
104
105
  private _started;
@@ -118,7 +119,6 @@ export declare class IndexedDbPersistence implements Persistence {
118
119
  /** A listener to notify on primary state changes. */
119
120
  private primaryStateListener;
120
121
  private readonly targetCache;
121
- private readonly indexManager;
122
122
  private readonly remoteDocumentCache;
123
123
  private readonly bundleCache;
124
124
  private readonly webStorage;
@@ -133,7 +133,7 @@ export declare class IndexedDbPersistence implements Persistence {
133
133
  * If set to true, forcefully obtains database access. Existing tabs will
134
134
  * no longer be able to access IndexedDB.
135
135
  */
136
- forceOwningTab: boolean);
136
+ forceOwningTab: boolean, schemaVersion?: number);
137
137
  /**
138
138
  * Attempt to start IndexedDb persistence.
139
139
  *
@@ -207,10 +207,10 @@ export declare class IndexedDbPersistence implements Persistence {
207
207
  */
208
208
  getActiveClients(): Promise<ClientId[]>;
209
209
  get started(): boolean;
210
- getMutationQueue(user: User): IndexedDbMutationQueue;
210
+ getMutationQueue(user: User, indexManager: IndexManager): IndexedDbMutationQueue;
211
211
  getTargetCache(): IndexedDbTargetCache;
212
212
  getRemoteDocumentCache(): IndexedDbRemoteDocumentCache;
213
- getIndexManager(): IndexManager;
213
+ getIndexManager(user: User): IndexManager;
214
214
  getBundleCache(): BundleCache;
215
215
  runTransaction<T>(action: string, mode: PersistenceTransactionMode, transactionOperation: (transaction: PersistenceTransaction) => PersistencePromise<T>): Promise<T>;
216
216
  /**
@@ -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.
@@ -809,22 +809,38 @@ export declare class DbNamedQuery {
809
809
  export declare type DbIndexConfigurationKey = number;
810
810
  /** An object representing the global configuration for a field index. */
811
811
  export declare class DbIndexConfiguration {
812
- /** The index id for this entry. */
813
- indexId: number;
812
+ /**
813
+ * The index id for this entry. Undefined for indexes that are not yet
814
+ * persisted.
815
+ */
816
+ indexId: number | undefined;
814
817
  /** The collection group this index belongs to. */
815
818
  collectionGroup: string;
816
819
  /** The fields to index for this index. */
817
- fields: [[name: string, kind: IndexKind]];
820
+ fields: Array<[name: string, kind: IndexKind]>;
818
821
  /** Name of the IndexedDb object store. */
819
822
  static store: string;
820
823
  static keyPath: string;
824
+ /**
825
+ * An index that provides access to the index configurations by collection
826
+ * group.
827
+ *
828
+ * PORTING NOTE: iOS and Android maintain this index in-memory, but this is
829
+ * not possible here as the Web client supports concurrent access to
830
+ * persistence via multi-tab.
831
+ */
832
+ static collectionGroupIndex: string;
833
+ static collectionGroupIndexPath: string;
821
834
  constructor(
822
- /** The index id for this entry. */
823
- indexId: number,
835
+ /**
836
+ * The index id for this entry. Undefined for indexes that are not yet
837
+ * persisted.
838
+ */
839
+ indexId: number | undefined,
824
840
  /** The collection group this index belongs to. */
825
841
  collectionGroup: string,
826
842
  /** The fields to index for this index. */
827
- fields: [[name: string, kind: IndexKind]]);
843
+ fields: Array<[name: string, kind: IndexKind]>);
828
844
  }
829
845
  /** The key for each index state consisting of the index id and its user id. */
830
846
  export declare type DbIndexStateKey = [number, string];
@@ -860,6 +876,16 @@ export declare class DbIndexState {
860
876
  /** Name of the IndexedDb object store. */
861
877
  static store: string;
862
878
  static keyPath: string[];
879
+ /**
880
+ * An index that provides access to documents in a collection sorted by last
881
+ * update time. Used by the backfiller.
882
+ *
883
+ * PORTING NOTE: iOS and Android maintain this index in-memory, but this is
884
+ * not possible here as the Web client supports concurrent access to
885
+ * persistence via multi-tab.
886
+ */
887
+ static sequenceNumberIndex: string;
888
+ static sequenceNumberIndexPath: string[];
863
889
  constructor(
864
890
  /** The index id for this entry. */
865
891
  indexId: number,
@@ -893,7 +919,7 @@ export declare class DbIndexState {
893
919
  */
894
920
  export declare type DbIndexEntryKey = [number, string, Uint8Array, Uint8Array, string];
895
921
  /** An object that stores the encoded entries for all documents and fields. */
896
- export declare class DbIndexEntries {
922
+ export declare class DbIndexEntry {
897
923
  /** The index id for this entry. */
898
924
  indexId: number;
899
925
  /** The user id for this entry. */
@@ -932,3 +958,5 @@ export declare const V12_STORES: string[];
932
958
  * atomically.
933
959
  */
934
960
  export declare const ALL_STORES: string[];
961
+ /** Returns the object stores for the provided schema. */
962
+ 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
  }
@@ -14,14 +14,16 @@
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 { BundleMetadata, NamedQuery } from '../core/bundle';
18
19
  import { Query } from '../core/query';
19
20
  import { SnapshotVersion } from '../core/snapshot_version';
20
21
  import { MutableDocument } from '../model/document';
22
+ import { FieldIndex, IndexOffset } from '../model/field_index';
21
23
  import { MutationBatch } from '../model/mutation_batch';
22
- import { BundleMetadata as ProtoBundleMetadata, NamedQuery as ProtoNamedQuery, BundledQuery as ProtoBundledQuery } from '../protos/firestore_bundle_proto';
24
+ import { BundledQuery as ProtoBundledQuery, BundleMetadata as ProtoBundleMetadata, NamedQuery as ProtoNamedQuery } from '../protos/firestore_bundle_proto';
23
25
  import { JsonProtoSerializer } from '../remote/serializer';
24
- import { DbBundle, DbMutationBatch, DbNamedQuery, DbRemoteDocument, DbTarget, DbTimestampKey } from './indexeddb_schema';
26
+ import { DbBundle, DbIndexConfiguration, DbIndexState, DbMutationBatch, DbNamedQuery, DbRemoteDocument, DbTarget, DbTimestampKey } from './indexeddb_schema';
25
27
  import { TargetData } from './target_data';
26
28
  /** Serializer for values stored in the LocalStore. */
27
29
  export declare class LocalSerializer {
@@ -61,3 +63,6 @@ export declare function fromBundledQuery(bundledQuery: ProtoBundledQuery): Query
61
63
  export declare function fromProtoNamedQuery(namedQuery: ProtoNamedQuery): NamedQuery;
62
64
  /** Decodes a BundleMetadata proto into a BundleMetadata object. */
63
65
  export declare function fromBundleMetadata(metadata: ProtoBundleMetadata): BundleMetadata;
66
+ export declare function toDbIndexConfiguration(index: FieldIndex): DbIndexConfiguration;
67
+ export declare function fromDbIndexConfiguration(index: DbIndexConfiguration, state: DbIndexState | null): FieldIndex;
68
+ export declare function toDbIndexState(indexId: number, user: User, sequenceNumber: number, offset: IndexOffset): DbIndexState;
@@ -14,6 +14,9 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
+ import { Target } from '../core/target';
18
+ import { DocumentKeySet, DocumentMap } from '../model/collections';
19
+ import { FieldIndex, IndexOffset } from '../model/field_index';
17
20
  import { ResourcePath } from '../model/path';
18
21
  import { IndexManager } from './index_manager';
19
22
  import { PersistencePromise } from './persistence_promise';
@@ -25,6 +28,14 @@ export declare class MemoryIndexManager implements IndexManager {
25
28
  private collectionParentIndex;
26
29
  addToCollectionParentIndex(transaction: PersistenceTransaction, collectionPath: ResourcePath): PersistencePromise<void>;
27
30
  getCollectionParents(transaction: PersistenceTransaction, collectionId: string): PersistencePromise<ResourcePath[]>;
31
+ addFieldIndex(transaction: PersistenceTransaction, index: FieldIndex): PersistencePromise<void>;
32
+ deleteFieldIndex(transaction: PersistenceTransaction, index: FieldIndex): PersistencePromise<void>;
33
+ getDocumentsMatchingTarget(transaction: PersistenceTransaction, fieldIndex: FieldIndex, target: Target): PersistencePromise<DocumentKeySet>;
34
+ getFieldIndex(transaction: PersistenceTransaction, target: Target): PersistencePromise<FieldIndex | null>;
35
+ getFieldIndexes(transaction: PersistenceTransaction, collectionGroup?: string): PersistencePromise<FieldIndex[]>;
36
+ getNextCollectionGroupToUpdate(transaction: PersistenceTransaction): PersistencePromise<string | null>;
37
+ updateCollectionGroup(transaction: PersistenceTransaction, collectionGroup: string, offset: IndexOffset): PersistencePromise<void>;
38
+ updateIndexEntries(transaction: PersistenceTransaction, documents: DocumentMap): PersistencePromise<void>;
28
39
  }
29
40
  /**
30
41
  * Internal implementation of the collection-parent index exposed by MemoryIndexManager.
@@ -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 { IndexManager } from './index_manager';
22
23
  import { ActiveTargets, LruDelegate, LruGarbageCollector, LruParams } from './lru_garbage_collector';
23
24
  import { MemoryBundleCache } from './memory_bundle_cache';
24
25
  import { MemoryIndexManager } from './memory_index_manager';
@@ -62,8 +63,8 @@ export declare class MemoryPersistence implements Persistence {
62
63
  get started(): boolean;
63
64
  setDatabaseDeletedListener(): void;
64
65
  setNetworkEnabled(): void;
65
- getIndexManager(): MemoryIndexManager;
66
- getMutationQueue(user: User): MutationQueue;
66
+ getIndexManager(user: User): MemoryIndexManager;
67
+ getMutationQueue(user: User, indexManager: IndexManager): MutationQueue;
67
68
  getTargetCache(): MemoryTargetCache;
68
69
  getRemoteDocumentCache(): MemoryRemoteDocumentCache;
69
70
  getBundleCache(): MemoryBundleCache;
@@ -16,7 +16,6 @@
16
16
  */
17
17
  import { Document } from '../model/document';
18
18
  import { DocumentKey } from '../model/document_key';
19
- import { IndexManager } from './index_manager';
20
19
  import { PersistencePromise } from './persistence_promise';
21
20
  import { PersistenceTransaction } from './persistence_transaction';
22
21
  import { RemoteDocumentCache } from './remote_document_cache';
@@ -27,9 +26,8 @@ export interface MemoryRemoteDocumentCache extends RemoteDocumentCache {
27
26
  /**
28
27
  * Creates a new memory-only RemoteDocumentCache.
29
28
  *
30
- * @param indexManager - A class that manages collection group indices.
31
29
  * @param sizer - Used to assess the size of a document. For eager GC, this is
32
30
  * expected to just return 0 to avoid unnecessarily doing the work of
33
31
  * calculating the size.
34
32
  */
35
- export declare function newMemoryRemoteDocumentCache(indexManager: IndexManager, sizer: DocumentSizer): MemoryRemoteDocumentCache;
33
+ export declare function newMemoryRemoteDocumentCache(sizer: DocumentSizer): MemoryRemoteDocumentCache;
@@ -140,7 +140,7 @@ export interface Persistence {
140
140
  * extent possible (e.g. in the case of uid switching from
141
141
  * sally=&gt;jack=&gt;sally, sally's mutation queue will be preserved).
142
142
  */
143
- getMutationQueue(user: User): MutationQueue;
143
+ getMutationQueue(user: User, indexManager: IndexManager): MutationQueue;
144
144
  /**
145
145
  * Returns a TargetCache representing the persisted cache of targets.
146
146
  *
@@ -173,7 +173,7 @@ export interface Persistence {
173
173
  * this is called. In particular, the memory-backed implementation does this
174
174
  * to emulate the persisted implementation to the extent possible.
175
175
  */
176
- getIndexManager(): IndexManager;
176
+ getIndexManager(user: User): IndexManager;
177
177
  /**
178
178
  * Performs an operation inside a persistence transaction. Any reads or writes
179
179
  * against persistence must be performed within a transaction. Writes will be
@@ -14,11 +14,12 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- import { Query } from '../core/query';
18
17
  import { SnapshotVersion } from '../core/snapshot_version';
19
18
  import { DocumentKeySet, MutableDocumentMap } from '../model/collections';
20
19
  import { MutableDocument } from '../model/document';
21
20
  import { DocumentKey } from '../model/document_key';
21
+ import { ResourcePath } from '../model/path';
22
+ import { IndexManager } from './index_manager';
22
23
  import { PersistencePromise } from './persistence_promise';
23
24
  import { PersistenceTransaction } from './persistence_transaction';
24
25
  import { RemoteDocumentChangeBuffer } from './remote_document_change_buffer';
@@ -30,6 +31,8 @@ import { RemoteDocumentChangeBuffer } from './remote_document_change_buffer';
30
31
  * documents that are known to not exist.
31
32
  */
32
33
  export interface RemoteDocumentCache {
34
+ /** Sets the index manager to use for managing the collectionGroup index. */
35
+ setIndexManager(indexManager: IndexManager): void;
33
36
  /**
34
37
  * Looks up an entry in the cache.
35
38
  *
@@ -47,19 +50,14 @@ export interface RemoteDocumentCache {
47
50
  */
48
51
  getEntries(transaction: PersistenceTransaction, documentKeys: DocumentKeySet): PersistencePromise<MutableDocumentMap>;
49
52
  /**
50
- * Executes a query against the cached Document entries.
53
+ * Returns the documents from the provided collection.
51
54
  *
52
- * Implementations may return extra documents if convenient. The results
53
- * should be re-filtered by the consumer before presenting them to the user.
54
- *
55
- * Cached NoDocument entries have no bearing on query results.
56
- *
57
- * @param query - The query to match documents against.
55
+ * @param collection - The collection to read.
58
56
  * @param sinceReadTime - If not set to SnapshotVersion.min(), return only
59
57
  * documents that have been read since this snapshot version (exclusive).
60
58
  * @returns The set of matching documents.
61
59
  */
62
- getDocumentsMatchingQuery(transaction: PersistenceTransaction, query: Query, sinceReadTime: SnapshotVersion): PersistencePromise<MutableDocumentMap>;
60
+ getAll(transaction: PersistenceTransaction, collection: ResourcePath, sinceReadTime: SnapshotVersion): PersistencePromise<MutableDocumentMap>;
63
61
  /**
64
62
  * Provides access to add or update the contents of the cache. The buffer
65
63
  * handles proper size accounting for the change.
@@ -36,6 +36,7 @@ export declare class SimpleDbTransaction {
36
36
  constructor(action: string, transaction: IDBTransaction);
37
37
  get completionPromise(): Promise<void>;
38
38
  abort(error?: Error): void;
39
+ maybeCommit(): void;
39
40
  /**
40
41
  * Returns a SimpleDbStore<KeyType, ValueType> for the specified store. All
41
42
  * operations performed on the SimpleDbStore happen within the context of this
@@ -43,7 +43,7 @@ export declare class FieldIndex {
43
43
  /** The collection ID this index applies to. */
44
44
  readonly collectionGroup: string;
45
45
  /** The field segments for this index. */
46
- readonly segments: IndexSegment[];
46
+ readonly fields: IndexSegment[];
47
47
  /** Shows how up-to-date the index is for the current user. */
48
48
  readonly indexState: IndexState;
49
49
  /** An ID for an index that has not yet been added to persistence. */
@@ -57,7 +57,7 @@ export declare class FieldIndex {
57
57
  /** The collection ID this index applies to. */
58
58
  collectionGroup: string,
59
59
  /** The field segments for this index. */
60
- segments: IndexSegment[],
60
+ fields: IndexSegment[],
61
61
  /** Shows how up-to-date the index is for the current user. */
62
62
  indexState: IndexState);
63
63
  }
@@ -0,0 +1,70 @@
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 { Target } from '../core/target';
18
+ import { FieldIndex } from './field_index';
19
+ /**
20
+ * A light query planner for Firestore.
21
+ *
22
+ * This class matches a `FieldIndex` against a Firestore Query `Target`. It
23
+ * determines whether a given index can be used to serve the specified target.
24
+ *
25
+ * The following table showcases some possible index configurations:
26
+ *
27
+ * Query | Index
28
+ * -----------------------------------------------------------------------------
29
+ * where('a', '==', 'a').where('b', '==', 'b') | a ASC, b DESC
30
+ * where('a', '==', 'a').where('b', '==', 'b') | a ASC
31
+ * where('a', '==', 'a').where('b', '==', 'b') | b DESC
32
+ * where('a', '>=', 'a').orderBy('a') | a ASC
33
+ * where('a', '>=', 'a').orderBy('a', 'desc') | a DESC
34
+ * where('a', '>=', 'a').orderBy('a').orderBy('b') | a ASC, b ASC
35
+ * where('a', '>=', 'a').orderBy('a').orderBy('b') | a ASC
36
+ * where('a', 'array-contains', 'a').orderBy('b') | a CONTAINS, b ASCENDING
37
+ * where('a', 'array-contains', 'a').orderBy('b') | a CONTAINS
38
+ */
39
+ export declare class TargetIndexMatcher {
40
+ private readonly collectionId;
41
+ private readonly inequalityFilter?;
42
+ private readonly equalityFilters;
43
+ private readonly orderBys;
44
+ constructor(target: Target);
45
+ /**
46
+ * Returns whether the index can be used to serve the TargetIndexMatcher's
47
+ * target.
48
+ *
49
+ * An index is considered capable of serving the target when:
50
+ * - The target uses all index segments for its filters and orderBy clauses.
51
+ * The target can have additional filter and orderBy clauses, but not
52
+ * fewer.
53
+ * - If an ArrayContains/ArrayContainsAnyfilter is used, the index must also
54
+ * have a corresponding `CONTAINS` segment.
55
+ * - All directional index segments can be mapped to the target as a series of
56
+ * equality filters, a single inequality filter and a series of orderBy
57
+ * clauses.
58
+ * - The segments that represent the equality filters may appear out of order.
59
+ * - The optional segment for the inequality filter must appear after all
60
+ * equality segments.
61
+ * - The segments that represent that orderBy clause of the target must appear
62
+ * in order after all equality and inequality segments. Single orderBy
63
+ * clauses cannot be skipped, but a continuous orderBy suffix may be
64
+ * omitted.
65
+ */
66
+ servedByIndex(index: FieldIndex): boolean;
67
+ private hasMatchingEqualityFilter;
68
+ private matchesFilter;
69
+ private matchesOrderBy;
70
+ }
@@ -31,7 +31,7 @@ export declare class CountingQueryEngine extends QueryEngine {
31
31
  * `getAllMutationBatchesAffectingQuery()` API (since the last call to
32
32
  * `resetCounts()`)
33
33
  */
34
- mutationsReadByQuery: number;
34
+ mutationsReadByCollection: number;
35
35
  /**
36
36
  * The number of mutations returned by the MutationQueue's
37
37
  * `getAllMutationBatchesAffectingDocumentKey()` and
@@ -41,9 +41,9 @@ export declare class CountingQueryEngine extends QueryEngine {
41
41
  mutationsReadByKey: number;
42
42
  /**
43
43
  * The number of documents returned by the RemoteDocumentCache's
44
- * `getDocumentsMatchingQuery()` API (since the last call to `resetCounts()`)
44
+ * `getAll()` API (since the last call to `resetCounts()`)
45
45
  */
46
- documentsReadByQuery: number;
46
+ documentsReadByCollection: number;
47
47
  /**
48
48
  * The number of documents returned by the RemoteDocumentCache's `getEntry()`
49
49
  * and `getEntries()` APIs (since the last call to `resetCounts()`)
@@ -54,6 +54,7 @@ export declare function testIndexedDbPersistence(options?: {
54
54
  dontPurgeData?: boolean;
55
55
  synchronizeTabs?: boolean;
56
56
  queue?: AsyncQueue;
57
+ schemaVersion?: number;
57
58
  }, lruParams?: LruParams): Promise<IndexedDbPersistence>;
58
59
  /** Creates and starts a MemoryPersistence instance for testing. */
59
60
  export declare function testMemoryEagerPersistence(): Promise<MemoryPersistence>;
@@ -14,8 +14,11 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
+ import { Target } from '../../../src/core/target';
17
18
  import { IndexManager } from '../../../src/local/index_manager';
18
19
  import { Persistence } from '../../../src/local/persistence';
20
+ import { DocumentKeySet, DocumentMap } from '../../../src/model/collections';
21
+ import { FieldIndex, IndexOffset } from '../../../src/model/field_index';
19
22
  import { ResourcePath } from '../../../src/model/path';
20
23
  /**
21
24
  * A wrapper around IndexManager that automatically creates a
@@ -27,4 +30,12 @@ export declare class TestIndexManager {
27
30
  constructor(persistence: Persistence, indexManager: IndexManager);
28
31
  addToCollectionParentIndex(collectionPath: ResourcePath): Promise<void>;
29
32
  getCollectionParents(collectionId: string): Promise<ResourcePath[]>;
33
+ addFieldIndex(index: FieldIndex): Promise<void>;
34
+ deleteFieldIndex(index: FieldIndex): Promise<void>;
35
+ getFieldIndexes(collectionGroup?: string): Promise<FieldIndex[]>;
36
+ getFieldIndex(target: Target): Promise<FieldIndex | null>;
37
+ getDocumentsMatchingTarget(fieldIndex: FieldIndex, target: Target): Promise<DocumentKeySet>;
38
+ getNextCollectionGroupToUpdate(): Promise<string | null>;
39
+ updateCollectionGroup(collectionGroup: string, offset: IndexOffset): Promise<void>;
40
+ updateIndexEntries(documents: DocumentMap): Promise<void>;
30
41
  }