@firebase/firestore 3.4.4-canary.2dd99ae2d → 3.4.4-canary.434d87ee2

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 (112) 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 +149 -7
  9. package/dist/firestore/src/local/local_serializer.d.ts +7 -2
  10. package/dist/firestore/src/local/memory_index_manager.d.ts +11 -0
  11. package/dist/firestore/src/local/memory_persistence.d.ts +3 -2
  12. package/dist/firestore/src/local/memory_remote_document_cache.d.ts +1 -3
  13. package/dist/firestore/src/local/persistence.d.ts +2 -2
  14. package/dist/firestore/src/local/remote_document_cache.d.ts +3 -0
  15. package/dist/firestore/src/local/simple_db.d.ts +1 -0
  16. package/dist/firestore/src/model/field_index.d.ts +2 -2
  17. package/dist/firestore/test/unit/local/persistence_test_helpers.d.ts +1 -0
  18. package/dist/firestore/test/unit/local/test_index_manager.d.ts +11 -0
  19. package/dist/firestore/test/unit/local/test_remote_document_cache.d.ts +2 -0
  20. package/dist/firestore/test/unit/local/test_remote_document_change_buffer.d.ts +1 -1
  21. package/dist/firestore/test/util/helpers.d.ts +1 -1
  22. package/dist/index.d.ts +1 -2
  23. package/dist/index.esm2017.js +3329 -3095
  24. package/dist/index.esm2017.js.map +1 -1
  25. package/dist/index.esm5.js +3590 -3370
  26. package/dist/index.esm5.js.map +1 -1
  27. package/dist/index.node.cjs.js +446 -150
  28. package/dist/index.node.cjs.js.map +1 -1
  29. package/dist/index.node.mjs +446 -150
  30. package/dist/index.node.mjs.map +1 -1
  31. package/dist/index.rn.js +3536 -3302
  32. package/dist/index.rn.js.map +1 -1
  33. package/dist/internal.d.ts +175 -6
  34. package/dist/lite/firestore/src/api/snapshot.d.ts +1 -2
  35. package/dist/lite/firestore/src/core/target.d.ts +8 -4
  36. package/dist/lite/firestore/src/lite-api/query.d.ts +2 -2
  37. package/dist/lite/firestore/src/local/index_manager.d.ts +52 -0
  38. package/dist/lite/firestore/src/local/indexeddb_index_manager.d.ts +21 -2
  39. package/dist/lite/firestore/src/local/indexeddb_persistence.d.ts +4 -4
  40. package/dist/lite/firestore/src/local/indexeddb_remote_document_cache.d.ts +2 -8
  41. package/dist/lite/firestore/src/local/indexeddb_schema.d.ts +149 -7
  42. package/dist/lite/firestore/src/local/local_serializer.d.ts +7 -2
  43. package/dist/lite/firestore/src/local/memory_index_manager.d.ts +11 -0
  44. package/dist/lite/firestore/src/local/memory_persistence.d.ts +3 -2
  45. package/dist/lite/firestore/src/local/memory_remote_document_cache.d.ts +1 -3
  46. package/dist/lite/firestore/src/local/persistence.d.ts +2 -2
  47. package/dist/lite/firestore/src/local/remote_document_cache.d.ts +3 -0
  48. package/dist/lite/firestore/src/local/simple_db.d.ts +1 -0
  49. package/dist/lite/firestore/src/model/field_index.d.ts +2 -2
  50. package/dist/lite/firestore/test/unit/local/persistence_test_helpers.d.ts +1 -0
  51. package/dist/lite/firestore/test/unit/local/test_index_manager.d.ts +11 -0
  52. package/dist/lite/firestore/test/unit/local/test_remote_document_cache.d.ts +2 -0
  53. package/dist/lite/firestore/test/unit/local/test_remote_document_change_buffer.d.ts +1 -1
  54. package/dist/lite/firestore/test/util/helpers.d.ts +1 -1
  55. package/dist/lite/index.browser.esm2017.js +1146 -1143
  56. package/dist/lite/index.browser.esm2017.js.map +1 -1
  57. package/dist/lite/index.browser.esm5.js +332 -331
  58. package/dist/lite/index.browser.esm5.js.map +1 -1
  59. package/dist/lite/index.node.cjs.js +36 -29
  60. package/dist/lite/index.node.cjs.js.map +1 -1
  61. package/dist/lite/index.node.mjs +36 -29
  62. package/dist/lite/index.node.mjs.map +1 -1
  63. package/dist/lite/index.rn.esm2017.js +301 -298
  64. package/dist/lite/index.rn.esm2017.js.map +1 -1
  65. package/dist/lite/internal.d.ts +2 -2
  66. package/dist/lite/packages/firestore/dist/lite/index.browser.esm2017.d.ts +121 -121
  67. package/dist/lite/packages/firestore/src/api/snapshot.d.ts +1 -2
  68. package/dist/lite/packages/firestore/src/core/target.d.ts +8 -4
  69. package/dist/lite/packages/firestore/src/lite-api/query.d.ts +2 -2
  70. package/dist/lite/packages/firestore/src/local/index_manager.d.ts +52 -0
  71. package/dist/lite/packages/firestore/src/local/indexeddb_index_manager.d.ts +21 -2
  72. package/dist/lite/packages/firestore/src/local/indexeddb_persistence.d.ts +4 -4
  73. package/dist/lite/packages/firestore/src/local/indexeddb_remote_document_cache.d.ts +2 -8
  74. package/dist/lite/packages/firestore/src/local/indexeddb_schema.d.ts +149 -7
  75. package/dist/lite/packages/firestore/src/local/local_serializer.d.ts +7 -2
  76. package/dist/lite/packages/firestore/src/local/memory_index_manager.d.ts +11 -0
  77. package/dist/lite/packages/firestore/src/local/memory_persistence.d.ts +3 -2
  78. package/dist/lite/packages/firestore/src/local/memory_remote_document_cache.d.ts +1 -3
  79. package/dist/lite/packages/firestore/src/local/persistence.d.ts +2 -2
  80. package/dist/lite/packages/firestore/src/local/remote_document_cache.d.ts +3 -0
  81. package/dist/lite/packages/firestore/src/local/simple_db.d.ts +1 -0
  82. package/dist/lite/packages/firestore/src/model/field_index.d.ts +2 -2
  83. package/dist/lite/packages/firestore/test/unit/local/persistence_test_helpers.d.ts +1 -0
  84. package/dist/lite/packages/firestore/test/unit/local/test_index_manager.d.ts +11 -0
  85. package/dist/lite/packages/firestore/test/unit/local/test_remote_document_cache.d.ts +2 -0
  86. package/dist/lite/packages/firestore/test/unit/local/test_remote_document_change_buffer.d.ts +1 -1
  87. package/dist/lite/packages/firestore/test/util/helpers.d.ts +1 -1
  88. package/dist/lite/private.d.ts +2 -2
  89. package/dist/packages/firestore/dist/index.esm2017.d.ts +176 -176
  90. package/dist/packages/firestore/src/api/snapshot.d.ts +1 -2
  91. package/dist/packages/firestore/src/core/target.d.ts +8 -4
  92. package/dist/packages/firestore/src/lite-api/query.d.ts +2 -2
  93. package/dist/packages/firestore/src/local/index_manager.d.ts +52 -0
  94. package/dist/packages/firestore/src/local/indexeddb_index_manager.d.ts +21 -2
  95. package/dist/packages/firestore/src/local/indexeddb_persistence.d.ts +4 -4
  96. package/dist/packages/firestore/src/local/indexeddb_remote_document_cache.d.ts +2 -8
  97. package/dist/packages/firestore/src/local/indexeddb_schema.d.ts +149 -7
  98. package/dist/packages/firestore/src/local/local_serializer.d.ts +7 -2
  99. package/dist/packages/firestore/src/local/memory_index_manager.d.ts +11 -0
  100. package/dist/packages/firestore/src/local/memory_persistence.d.ts +3 -2
  101. package/dist/packages/firestore/src/local/memory_remote_document_cache.d.ts +1 -3
  102. package/dist/packages/firestore/src/local/persistence.d.ts +2 -2
  103. package/dist/packages/firestore/src/local/remote_document_cache.d.ts +3 -0
  104. package/dist/packages/firestore/src/local/simple_db.d.ts +1 -0
  105. package/dist/packages/firestore/src/model/field_index.d.ts +2 -2
  106. package/dist/packages/firestore/test/unit/local/persistence_test_helpers.d.ts +1 -0
  107. package/dist/packages/firestore/test/unit/local/test_index_manager.d.ts +11 -0
  108. package/dist/packages/firestore/test/unit/local/test_remote_document_cache.d.ts +2 -0
  109. package/dist/packages/firestore/test/unit/local/test_remote_document_change_buffer.d.ts +1 -1
  110. package/dist/packages/firestore/test/util/helpers.d.ts +1 -1
  111. package/dist/private.d.ts +175 -6
  112. package/package.json +9 -9
@@ -214,8 +214,8 @@ declare type BatchId = number;
214
214
  */
215
215
  declare class Bound {
216
216
  readonly position: Value[];
217
- readonly before: boolean;
218
- constructor(position: Value[], before: boolean);
217
+ readonly inclusive: boolean;
218
+ constructor(position: Value[], inclusive: boolean);
219
219
  }
220
220
 
221
221
  /**
@@ -1074,8 +1074,7 @@ export declare class DocumentSnapshot<T = DocumentData> extends DocumentSnapshot
1074
1074
  /** @hideconstructor protected */
1075
1075
  constructor(_firestore: Firestore, userDataWriter: AbstractUserDataWriter, key: _DocumentKey, document: Document_2 | null, metadata: SnapshotMetadata, converter: UntypedFirestoreDataConverter<T> | null);
1076
1076
  /**
1077
- * Property of the `DocumentSnapshot` that signals whether or not the data
1078
- * exists. True if the document exists.
1077
+ * Returns whether or not the data exists. True if the document exists.
1079
1078
  */
1080
1079
  exists(): this is QueryDocumentSnapshot<T>;
1081
1080
  /**
@@ -1324,6 +1323,45 @@ export declare function executeWrite(firestore: Firestore, mutations: Mutation[]
1324
1323
 
1325
1324
  declare type FieldFilterOp = 'OPERATOR_UNSPECIFIED' | 'LESS_THAN' | 'LESS_THAN_OR_EQUAL' | 'GREATER_THAN' | 'GREATER_THAN_OR_EQUAL' | 'EQUAL' | 'NOT_EQUAL' | 'ARRAY_CONTAINS' | 'IN' | 'ARRAY_CONTAINS_ANY' | 'NOT_IN';
1326
1325
 
1326
+ /**
1327
+ * An index definition for field indexes in Firestore.
1328
+ *
1329
+ * Every index is associated with a collection. The definition contains a list
1330
+ * of fields and their index kind (which can be `ASCENDING`, `DESCENDING` or
1331
+ * `CONTAINS` for ArrayContains/ArrayContainsAny queries).
1332
+ *
1333
+ * Unlike the backend, the SDK does not differentiate between collection or
1334
+ * collection group-scoped indices. Every index can be used for both single
1335
+ * collection and collection group queries.
1336
+ */
1337
+ declare class FieldIndex {
1338
+ /**
1339
+ * The index ID. Returns -1 if the index ID is not available (e.g. the index
1340
+ * has not yet been persisted).
1341
+ */
1342
+ readonly indexId: number;
1343
+ /** The collection ID this index applies to. */
1344
+ readonly collectionGroup: string;
1345
+ /** The field segments for this index. */
1346
+ readonly fields: IndexSegment[];
1347
+ /** Shows how up-to-date the index is for the current user. */
1348
+ readonly indexState: IndexState_2;
1349
+ /** An ID for an index that has not yet been added to persistence. */
1350
+ static UNKNOWN_ID: number;
1351
+ constructor(
1352
+ /**
1353
+ * The index ID. Returns -1 if the index ID is not available (e.g. the index
1354
+ * has not yet been persisted).
1355
+ */
1356
+ indexId: number,
1357
+ /** The collection ID this index applies to. */
1358
+ collectionGroup: string,
1359
+ /** The field segments for this index. */
1360
+ fields: IndexSegment[],
1361
+ /** Shows how up-to-date the index is for the current user. */
1362
+ indexState: IndexState_2);
1363
+ }
1364
+
1327
1365
  /**
1328
1366
  * Provides a set of fields that can be used to partially patch a document.
1329
1367
  * FieldMask is used in conjunction with ObjectValue.
@@ -2363,6 +2401,20 @@ declare interface IndexField {
2363
2401
 
2364
2402
  declare type IndexFieldMode = 'MODE_UNSPECIFIED' | 'ASCENDING' | 'DESCENDING';
2365
2403
 
2404
+ /** The type of the index, e.g. for which type of query it can be used. */
2405
+ declare const enum IndexKind {
2406
+ /**
2407
+ * Ordered index. Can be used for <, <=, ==, >=, >, !=, IN and NOT IN queries.
2408
+ */
2409
+ ASCENDING = 0,
2410
+ /**
2411
+ * Ordered index. Can be used for <, <=, ==, >=, >, !=, IN and NOT IN queries.
2412
+ */
2413
+ DESCENDING = 1,
2414
+ /** Contains index. Can be used for ArrayContains and ArrayContainsAny. */
2415
+ CONTAINS = 2
2416
+ }
2417
+
2366
2418
  /**
2367
2419
  * Represents a set of indexes that are used to execute queries efficiently.
2368
2420
  *
@@ -2386,10 +2438,125 @@ declare interface IndexManager {
2386
2438
  * path for a root-level collection).
2387
2439
  */
2388
2440
  getCollectionParents(transaction: PersistenceTransaction, collectionId: string): PersistencePromise<_ResourcePath[]>;
2441
+ /**
2442
+ * Adds a field path index.
2443
+ *
2444
+ * Values for this index are persisted via the index backfill, which runs
2445
+ * asynchronously in the background. Once the first values are written,
2446
+ * an index can be used to serve partial results for any matching queries.
2447
+ * Any unindexed portion of the database will continue to be served via
2448
+ * collection scons.
2449
+ */
2450
+ addFieldIndex(transaction: PersistenceTransaction, index: FieldIndex): PersistencePromise<void>;
2451
+ /** Removes the given field index and deletes all index values. */
2452
+ deleteFieldIndex(transaction: PersistenceTransaction, index: FieldIndex): PersistencePromise<void>;
2453
+ /**
2454
+ * Returns a list of field indexes that correspond to the specified collection
2455
+ * group.
2456
+ *
2457
+ * @param collectionGroup The collection group to get matching field indexes
2458
+ * for.
2459
+ * @return A collection of field indexes for the specified collection group.
2460
+ */
2461
+ getFieldIndexes(transaction: PersistenceTransaction, collectionGroup: string): PersistencePromise<FieldIndex[]>;
2462
+ /** Returns all configured field indexes. */
2463
+ getFieldIndexes(transaction: PersistenceTransaction): PersistencePromise<FieldIndex[]>;
2464
+ /**
2465
+ * Returns an index that can be used to serve the provided target. Returns
2466
+ * `null` if no index is configured.
2467
+ */
2468
+ getFieldIndex(transaction: PersistenceTransaction, target: Target): PersistencePromise<FieldIndex | null>;
2469
+ /**
2470
+ * Returns the documents that match the given target based on the provided
2471
+ * index.
2472
+ */
2473
+ getDocumentsMatchingTarget(transaction: PersistenceTransaction, fieldIndex: FieldIndex, target: Target): PersistencePromise<DocumentKeySet>;
2474
+ /**
2475
+ * Returns the next collection group to update. Returns `null` if no group
2476
+ * exists.
2477
+ */
2478
+ getNextCollectionGroupToUpdate(transaction: PersistenceTransaction): PersistencePromise<string | null>;
2479
+ /**
2480
+ * Sets the collection group's latest read time.
2481
+ *
2482
+ * This method updates the index offset for all field indices for the
2483
+ * collection group and increments their sequence number. Subsequent calls to
2484
+ * `getNextCollectionGroupToUpdate()` will return a different collection group
2485
+ * (unless only one collection group is configured).
2486
+ */
2487
+ updateCollectionGroup(transaction: PersistenceTransaction, collectionGroup: string, offset: IndexOffset): PersistencePromise<void>;
2488
+ /** Updates the index entries for the provided documents. */
2489
+ updateIndexEntries(transaction: PersistenceTransaction, documents: DocumentMap): PersistencePromise<void>;
2490
+ }
2491
+
2492
+ /**
2493
+ * Stores the latest read time, document and batch ID that were processed for an
2494
+ * index.
2495
+ */
2496
+ declare class IndexOffset {
2497
+ /**
2498
+ * The latest read time version that has been indexed by Firestore for this
2499
+ * field index.
2500
+ */
2501
+ readonly readTime: SnapshotVersion;
2502
+ /**
2503
+ * The key of the last document that was indexed for this query. Use
2504
+ * `DocumentKey.empty()` if no document has been indexed.
2505
+ */
2506
+ readonly documentKey: _DocumentKey;
2507
+ readonly largestBatchId: number;
2508
+ constructor(
2509
+ /**
2510
+ * The latest read time version that has been indexed by Firestore for this
2511
+ * field index.
2512
+ */
2513
+ readTime: SnapshotVersion,
2514
+ /**
2515
+ * The key of the last document that was indexed for this query. Use
2516
+ * `DocumentKey.empty()` if no document has been indexed.
2517
+ */
2518
+ documentKey: _DocumentKey, largestBatchId: number);
2519
+ /** The state of an index that has not yet been backfilled. */
2520
+ static min(): IndexOffset;
2521
+ }
2522
+
2523
+ /** An index component consisting of field path and index type. */
2524
+ declare class IndexSegment {
2525
+ /** The field path of the component. */
2526
+ readonly fieldPath: _FieldPath;
2527
+ /** The fields sorting order. */
2528
+ readonly kind: IndexKind;
2529
+ constructor(
2530
+ /** The field path of the component. */
2531
+ fieldPath: _FieldPath,
2532
+ /** The fields sorting order. */
2533
+ kind: IndexKind);
2389
2534
  }
2390
2535
 
2391
2536
  declare type IndexState = 'STATE_UNSPECIFIED' | 'CREATING' | 'READY' | 'ERROR';
2392
2537
 
2538
+ /**
2539
+ * Stores the "high water mark" that indicates how updated the Index is for the
2540
+ * current user.
2541
+ */
2542
+ declare class IndexState_2 {
2543
+ /**
2544
+ * Indicates when the index was last updated (relative to other indexes).
2545
+ */
2546
+ readonly sequenceNumber: number;
2547
+ /** The the latest indexed read time, document and batch id. */
2548
+ readonly offset: IndexOffset;
2549
+ constructor(
2550
+ /**
2551
+ * Indicates when the index was last updated (relative to other indexes).
2552
+ */
2553
+ sequenceNumber: number,
2554
+ /** The the latest indexed read time, document and batch id. */
2555
+ offset: IndexOffset);
2556
+ /** The state of an index that has not yet been backfilled. */
2557
+ static empty(): IndexState_2;
2558
+ }
2559
+
2393
2560
  /**
2394
2561
  * Initializes a new instance of {@link Firestore} with the provided settings.
2395
2562
  * Can only be called before any other function, including
@@ -3509,7 +3676,7 @@ declare interface Persistence {
3509
3676
  * extent possible (e.g. in the case of uid switching from
3510
3677
  * sally=&gt;jack=&gt;sally, sally's mutation queue will be preserved).
3511
3678
  */
3512
- getMutationQueue(user: User): MutationQueue;
3679
+ getMutationQueue(user: User, indexManager: IndexManager): MutationQueue;
3513
3680
  /**
3514
3681
  * Returns a TargetCache representing the persisted cache of targets.
3515
3682
  *
@@ -3542,7 +3709,7 @@ declare interface Persistence {
3542
3709
  * this is called. In particular, the memory-backed implementation does this
3543
3710
  * to emulate the persisted implementation to the extent possible.
3544
3711
  */
3545
- getIndexManager(): IndexManager;
3712
+ getIndexManager(user: User): IndexManager;
3546
3713
  /**
3547
3714
  * Performs an operation inside a persistence transaction. Any reads or writes
3548
3715
  * against persistence must be performed within a transaction. Writes will be
@@ -3953,6 +4120,8 @@ declare type Rejector = (error: Error) => void;
3953
4120
  * documents that are known to not exist.
3954
4121
  */
3955
4122
  declare interface RemoteDocumentCache {
4123
+ /** Sets the index manager to use for managing the collectionGroup index. */
4124
+ setIndexManager(indexManager: IndexManager): void;
3956
4125
  /**
3957
4126
  * Looks up an entry in the cache.
3958
4127
  *
@@ -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.
@@ -15,10 +15,12 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  import { BatchId, TargetId } from '../core/types';
18
+ import { IndexKind } from '../model/field_index';
18
19
  import { ResourcePath } from '../model/path';
19
20
  import { BundledQuery } from '../protos/firestore_bundle_proto';
20
21
  import { Document as ProtoDocument, DocumentsTarget as ProtoDocumentsTarget, QueryTarget as ProtoQueryTarget, Write as ProtoWrite } from '../protos/firestore_proto_api';
21
22
  import { EncodedResourcePath } from './encoded_resource_path';
23
+ export declare const INDEXING_SCHEMA_VERSION = 12;
22
24
  /**
23
25
  * Schema Version for the Web client:
24
26
  * 1. Initial version including Mutation Queue, Query Cache, and Remote
@@ -37,8 +39,9 @@ import { EncodedResourcePath } from './encoded_resource_path';
37
39
  * an auto-incrementing ID. This is required for Index-Free queries.
38
40
  * 10. Rewrite the canonical IDs to the explicit Protobuf-based format.
39
41
  * 11. Add bundles and named_queries for bundle support.
42
+ * 12. Add indexing support.
40
43
  */
41
- export declare const SCHEMA_VERSION = 11;
44
+ export declare const SCHEMA_VERSION: number;
42
45
  /**
43
46
  * Wrapper class to store timestamps (seconds and nanos) in IndexedDb objects.
44
47
  */
@@ -763,9 +766,7 @@ export declare class DbClientMetadata {
763
766
  /** Object keys in the 'clientMetadata' store are clientId strings. */
764
767
  export declare type DbClientMetadataKey = string;
765
768
  export declare type DbBundlesKey = string;
766
- /**
767
- * A object representing a bundle loaded by the SDK.
768
- */
769
+ /** An object representing a bundle loaded by the SDK. */
769
770
  export declare class DbBundle {
770
771
  /** The ID of the loaded bundle. */
771
772
  bundleId: string;
@@ -785,9 +786,7 @@ export declare class DbBundle {
785
786
  version: number);
786
787
  }
787
788
  export declare type DbNamedQueriesKey = string;
788
- /**
789
- * A object representing a named query loaded by the SDK via a bundle.
790
- */
789
+ /** An object representing a named query loaded by the SDK via a bundle. */
791
790
  export declare class DbNamedQuery {
792
791
  /** The name of the query. */
793
792
  name: string;
@@ -806,15 +805,158 @@ export declare class DbNamedQuery {
806
805
  /** The query saved in the bundle. */
807
806
  bundledQuery: BundledQuery);
808
807
  }
808
+ /** The key for each index consisting of just the index id. */
809
+ export declare type DbIndexConfigurationKey = number;
810
+ /** An object representing the global configuration for a field index. */
811
+ export declare class DbIndexConfiguration {
812
+ /**
813
+ * The index id for this entry. Undefined for indexes that are not yet
814
+ * persisted.
815
+ */
816
+ indexId: number | undefined;
817
+ /** The collection group this index belongs to. */
818
+ collectionGroup: string;
819
+ /** The fields to index for this index. */
820
+ fields: Array<[name: string, kind: IndexKind]>;
821
+ /** Name of the IndexedDb object store. */
822
+ static store: string;
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;
834
+ constructor(
835
+ /**
836
+ * The index id for this entry. Undefined for indexes that are not yet
837
+ * persisted.
838
+ */
839
+ indexId: number | undefined,
840
+ /** The collection group this index belongs to. */
841
+ collectionGroup: string,
842
+ /** The fields to index for this index. */
843
+ fields: Array<[name: string, kind: IndexKind]>);
844
+ }
845
+ /** The key for each index state consisting of the index id and its user id. */
846
+ export declare type DbIndexStateKey = [number, string];
847
+ /**
848
+ * An object describing how up-to-date the index backfill is for each user and
849
+ * index.
850
+ */
851
+ export declare class DbIndexState {
852
+ /** The index id for this entry. */
853
+ indexId: number;
854
+ /** The user id for this entry. */
855
+ uid: string;
856
+ /**
857
+ * A number that indicates when the index was last updated (relative to
858
+ * other indexes).
859
+ */
860
+ sequenceNumber: number;
861
+ /**
862
+ * The latest read time that has been indexed by Firestore for this field
863
+ * index. Set to `{seconds: 0, nanos: 0}` if no documents have been indexed.
864
+ */
865
+ readTime: DbTimestamp;
866
+ /**
867
+ * The last document that has been indexed for this field index. Empty if
868
+ * no documents have been indexed.
869
+ */
870
+ documentKey: EncodedResourcePath;
871
+ /**
872
+ * The largest mutation batch id that has been processed for this index. -1
873
+ * if no mutations have been indexed.
874
+ */
875
+ largestBatchId: number;
876
+ /** Name of the IndexedDb object store. */
877
+ static store: string;
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[];
889
+ constructor(
890
+ /** The index id for this entry. */
891
+ indexId: number,
892
+ /** The user id for this entry. */
893
+ uid: string,
894
+ /**
895
+ * A number that indicates when the index was last updated (relative to
896
+ * other indexes).
897
+ */
898
+ sequenceNumber: number,
899
+ /**
900
+ * The latest read time that has been indexed by Firestore for this field
901
+ * index. Set to `{seconds: 0, nanos: 0}` if no documents have been indexed.
902
+ */
903
+ readTime: DbTimestamp,
904
+ /**
905
+ * The last document that has been indexed for this field index. Empty if
906
+ * no documents have been indexed.
907
+ */
908
+ documentKey: EncodedResourcePath,
909
+ /**
910
+ * The largest mutation batch id that has been processed for this index. -1
911
+ * if no mutations have been indexed.
912
+ */
913
+ largestBatchId: number);
914
+ }
915
+ /**
916
+ * The key for each index entry consists of the index id and its user id,
917
+ * the encoded array and directional value for the indexed fields as well as
918
+ * the encoded document path for the indexed document.
919
+ */
920
+ export declare type DbIndexEntryKey = [number, string, Uint8Array, Uint8Array, string];
921
+ /** An object that stores the encoded entries for all documents and fields. */
922
+ export declare class DbIndexEntry {
923
+ /** The index id for this entry. */
924
+ indexId: number;
925
+ /** The user id for this entry. */
926
+ uid: string;
927
+ /** The encoded array index value for this entry. */
928
+ arrayValue: Uint8Array;
929
+ /** The encoded directional value for equality and inequality filters. */
930
+ directionalValue: Uint8Array;
931
+ /** The document key this entry points to. */
932
+ documentKey: EncodedResourcePath;
933
+ /** Name of the IndexedDb object store. */
934
+ static store: string;
935
+ static keyPath: string[];
936
+ constructor(
937
+ /** The index id for this entry. */
938
+ indexId: number,
939
+ /** The user id for this entry. */
940
+ uid: string,
941
+ /** The encoded array index value for this entry. */
942
+ arrayValue: Uint8Array,
943
+ /** The encoded directional value for equality and inequality filters. */
944
+ directionalValue: Uint8Array,
945
+ /** The document key this entry points to. */
946
+ documentKey: EncodedResourcePath);
947
+ }
809
948
  export declare const V1_STORES: string[];
810
949
  export declare const V3_STORES: string[];
811
950
  export declare const V4_STORES: string[];
812
951
  export declare const V6_STORES: string[];
813
952
  export declare const V8_STORES: string[];
814
953
  export declare const V11_STORES: string[];
954
+ export declare const V12_STORES: string[];
815
955
  /**
816
956
  * The list of all default IndexedDB stores used throughout the SDK. This is
817
957
  * used when creating transactions so that access across all stores is done
818
958
  * atomically.
819
959
  */
820
960
  export declare const ALL_STORES: string[];
961
+ /** Returns the object stores for the provided schema. */
962
+ export declare function getObjectStores(schemaVersion: number): string[];