@firebase/firestore 3.4.8-canary.7b58dabdf → 3.4.8-canary.9417675e6

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 (65) hide show
  1. package/dist/firestore/src/core/query.d.ts +2 -4
  2. package/dist/firestore/src/local/index_manager.d.ts +5 -0
  3. package/dist/firestore/src/local/indexeddb_index_manager.d.ts +1 -0
  4. package/dist/firestore/src/local/indexeddb_schema.d.ts +1 -0
  5. package/dist/firestore/src/local/local_documents_view.d.ts +1 -1
  6. package/dist/firestore/src/local/memory_index_manager.d.ts +1 -0
  7. package/dist/firestore/src/local/query_engine.d.ts +44 -5
  8. package/dist/firestore/src/model/collections.d.ts +1 -1
  9. package/dist/firestore/src/util/misc.d.ts +3 -0
  10. package/dist/firestore/test/unit/local/counting_query_engine.d.ts +2 -1
  11. package/dist/index.esm2017.js +2611 -2562
  12. package/dist/index.esm2017.js.map +1 -1
  13. package/dist/index.esm5.js +2899 -2854
  14. package/dist/index.esm5.js.map +1 -1
  15. package/dist/index.node.cjs.js +132 -54
  16. package/dist/index.node.cjs.js.map +1 -1
  17. package/dist/index.node.mjs +132 -54
  18. package/dist/index.node.mjs.map +1 -1
  19. package/dist/index.rn.js +2679 -2630
  20. package/dist/index.rn.js.map +1 -1
  21. package/dist/internal.d.ts +5 -0
  22. package/dist/lite/firestore/src/core/query.d.ts +2 -4
  23. package/dist/lite/firestore/src/local/index_manager.d.ts +5 -0
  24. package/dist/lite/firestore/src/local/indexeddb_index_manager.d.ts +1 -0
  25. package/dist/lite/firestore/src/local/indexeddb_schema.d.ts +1 -0
  26. package/dist/lite/firestore/src/local/local_documents_view.d.ts +1 -1
  27. package/dist/lite/firestore/src/local/memory_index_manager.d.ts +1 -0
  28. package/dist/lite/firestore/src/local/query_engine.d.ts +44 -5
  29. package/dist/lite/firestore/src/model/collections.d.ts +1 -1
  30. package/dist/lite/firestore/src/util/misc.d.ts +3 -0
  31. package/dist/lite/firestore/test/unit/local/counting_query_engine.d.ts +2 -1
  32. package/dist/lite/index.browser.esm2017.js +402 -406
  33. package/dist/lite/index.browser.esm2017.js.map +1 -1
  34. package/dist/lite/index.browser.esm5.js +380 -384
  35. package/dist/lite/index.browser.esm5.js.map +1 -1
  36. package/dist/lite/index.node.cjs.js +5 -7
  37. package/dist/lite/index.node.cjs.js.map +1 -1
  38. package/dist/lite/index.node.mjs +5 -7
  39. package/dist/lite/index.node.mjs.map +1 -1
  40. package/dist/lite/index.rn.esm2017.js +1176 -1180
  41. package/dist/lite/index.rn.esm2017.js.map +1 -1
  42. package/dist/lite/packages/firestore/dist/lite/index.browser.esm2017.d.ts +97 -97
  43. package/dist/lite/packages/firestore/src/core/query.d.ts +2 -4
  44. package/dist/lite/packages/firestore/src/local/index_manager.d.ts +5 -0
  45. package/dist/lite/packages/firestore/src/local/indexeddb_index_manager.d.ts +1 -0
  46. package/dist/lite/packages/firestore/src/local/indexeddb_schema.d.ts +1 -0
  47. package/dist/lite/packages/firestore/src/local/local_documents_view.d.ts +1 -1
  48. package/dist/lite/packages/firestore/src/local/memory_index_manager.d.ts +1 -0
  49. package/dist/lite/packages/firestore/src/local/query_engine.d.ts +44 -5
  50. package/dist/lite/packages/firestore/src/model/collections.d.ts +1 -1
  51. package/dist/lite/packages/firestore/src/util/misc.d.ts +3 -0
  52. package/dist/lite/packages/firestore/test/unit/local/counting_query_engine.d.ts +2 -1
  53. package/dist/packages/firestore/dist/index.esm2017.d.ts +168 -168
  54. package/dist/packages/firestore/src/core/query.d.ts +2 -4
  55. package/dist/packages/firestore/src/local/index_manager.d.ts +5 -0
  56. package/dist/packages/firestore/src/local/indexeddb_index_manager.d.ts +1 -0
  57. package/dist/packages/firestore/src/local/indexeddb_schema.d.ts +1 -0
  58. package/dist/packages/firestore/src/local/local_documents_view.d.ts +1 -1
  59. package/dist/packages/firestore/src/local/memory_index_manager.d.ts +1 -0
  60. package/dist/packages/firestore/src/local/query_engine.d.ts +44 -5
  61. package/dist/packages/firestore/src/model/collections.d.ts +1 -1
  62. package/dist/packages/firestore/src/util/misc.d.ts +3 -0
  63. package/dist/packages/firestore/test/unit/local/counting_query_engine.d.ts +2 -1
  64. package/dist/private.d.ts +5 -0
  65. package/package.json +9 -9
@@ -33,7 +33,7 @@ var grpc__namespace = /*#__PURE__*/_interopNamespace(grpc);
33
33
  var protoLoader__namespace = /*#__PURE__*/_interopNamespace(protoLoader);
34
34
 
35
35
  const name = "@firebase/firestore";
36
- const version$1 = "3.4.8-canary.7b58dabdf";
36
+ const version$1 = "3.4.8-canary.9417675e6";
37
37
 
38
38
  /**
39
39
  * @license
@@ -86,7 +86,7 @@ User.GOOGLE_CREDENTIALS = new User('google-credentials-uid');
86
86
  User.FIRST_PARTY = new User('first-party-uid');
87
87
  User.MOCK_USER = new User('mock-user');
88
88
 
89
- const version = "9.6.11-canary.7b58dabdf";
89
+ const version = "9.6.11-canary.9417675e6";
90
90
 
91
91
  /**
92
92
  * @license
@@ -5739,7 +5739,7 @@ function asCollectionQueryAtPath(query, path) {
5739
5739
  * Returns true if this query does not specify any query constraints that
5740
5740
  * could remove results.
5741
5741
  */
5742
- function matchesAllDocuments(query) {
5742
+ function queryMatchesAllDocuments(query) {
5743
5743
  return (query.filters.length === 0 &&
5744
5744
  query.limit === null &&
5745
5745
  query.startAt == null &&
@@ -5748,12 +5748,6 @@ function matchesAllDocuments(query) {
5748
5748
  (query.explicitOrderBy.length === 1 &&
5749
5749
  query.explicitOrderBy[0].field.isKeyField())));
5750
5750
  }
5751
- function hasLimitToFirst(query) {
5752
- return !isNullOrUndefined(query.limit) && query.limitType === "F" /* First */;
5753
- }
5754
- function hasLimitToLast(query) {
5755
- return !isNullOrUndefined(query.limit) && query.limitType === "L" /* Last */;
5756
- }
5757
5751
  function getFirstOrderByField(query) {
5758
5752
  return query.explicitOrderBy.length > 0
5759
5753
  ? query.explicitOrderBy[0].field
@@ -6137,8 +6131,12 @@ function mutableDocumentMap() {
6137
6131
  return EMPTY_MUTABLE_DOCUMENT_MAP;
6138
6132
  }
6139
6133
  const EMPTY_DOCUMENT_MAP = new SortedMap(DocumentKey.comparator);
6140
- function documentMap() {
6141
- return EMPTY_DOCUMENT_MAP;
6134
+ function documentMap(...docs) {
6135
+ let map = EMPTY_DOCUMENT_MAP;
6136
+ for (const doc of docs) {
6137
+ map = map.insert(doc.key, doc);
6138
+ }
6139
+ return map;
6142
6140
  }
6143
6141
  function newOverlayMap() {
6144
6142
  return new ObjectMap(key => key.toString(), (l, r) => l.isEqual(r));
@@ -10043,6 +10041,9 @@ class MemoryIndexManager {
10043
10041
  // Field indices are not supported with memory persistence.
10044
10042
  return PersistencePromise.resolve(null);
10045
10043
  }
10044
+ getMinOffset(transaction, target) {
10045
+ return PersistencePromise.resolve(IndexOffset.min());
10046
+ }
10046
10047
  updateCollectionGroup(transaction, collectionGroup, offset) {
10047
10048
  // Field indices are not supported with memory persistence.
10048
10049
  return PersistencePromise.resolve();
@@ -10269,9 +10270,9 @@ class IndexedDbIndexManager {
10269
10270
  const upperBound = upperBounds
10270
10271
  ? this.generateUpperBound(indexId, arrayValue, upperBounds[i % scansPerArrayElement], upperBoundInclusive)
10271
10272
  : this.generateEmptyBound(indexId + 1);
10272
- indexRanges.push(...this.createRange(lowerBound, upperBound, notInValues.map((notIn // make non-nullable
10273
- ) => this.generateLowerBound(indexId, arrayValue, notIn,
10274
- /* inclusive= */ true))));
10273
+ const notInBound = notInValues.map(notIn => this.generateLowerBound(indexId, arrayValue, notIn,
10274
+ /* inclusive= */ true));
10275
+ indexRanges.push(...this.createRange(lowerBound, upperBound, notInBound));
10275
10276
  }
10276
10277
  return indexRanges;
10277
10278
  }
@@ -10311,15 +10312,18 @@ class IndexedDbIndexManager {
10311
10312
  });
10312
10313
  }
10313
10314
  getIndexType(transaction, target) {
10314
- // TODO(orqueries): We should look at the subtargets here
10315
- return this.getFieldIndex(transaction, target).next(index => {
10316
- if (!index) {
10317
- return 0 /* NONE */;
10318
- }
10319
- return index.fields.length < targetGetSegmentCount(target)
10320
- ? 1 /* PARTIAL */
10321
- : 2 /* FULL */;
10322
- });
10315
+ let indexType = 2 /* FULL */;
10316
+ return PersistencePromise.forEach(this.getSubTargets(target), (target) => {
10317
+ return this.getFieldIndex(transaction, target).next(index => {
10318
+ if (!index) {
10319
+ indexType = 0 /* NONE */;
10320
+ }
10321
+ else if (indexType !== 0 /* NONE */ &&
10322
+ index.fields.length < targetGetSegmentCount(target)) {
10323
+ indexType = 1 /* PARTIAL */;
10324
+ }
10325
+ });
10326
+ }).next(() => indexType);
10323
10327
  }
10324
10328
  /**
10325
10329
  * Returns the byte encoded form of the directional values in the field index.
@@ -10580,7 +10584,7 @@ class IndexedDbIndexManager {
10580
10584
  * '[foo > 2 && foo != 3]` becomes `[foo > 2 && < 3, foo > 3]`.
10581
10585
  */
10582
10586
  createRange(lower, upper, notInValues) {
10583
- // The notIb values need to be sorted and unique so that we can return a
10587
+ // The notIn values need to be sorted and unique so that we can return a
10584
10588
  // sorted set of non-overlapping ranges.
10585
10589
  notInValues = notInValues
10586
10590
  .sort((l, r) => indexEntryComparator(l, r))
@@ -10626,6 +10630,20 @@ class IndexedDbIndexManager {
10626
10630
  }
10627
10631
  return ranges;
10628
10632
  }
10633
+ getMinOffset(transaction, target) {
10634
+ let offset;
10635
+ return PersistencePromise.forEach(this.getSubTargets(target), (target) => {
10636
+ return this.getFieldIndex(transaction, target).next(index => {
10637
+ if (!index) {
10638
+ offset = IndexOffset.min();
10639
+ }
10640
+ else if (!offset ||
10641
+ indexOffsetComparator(index.indexState.offset, offset) < 0) {
10642
+ offset = index.indexState.offset;
10643
+ }
10644
+ });
10645
+ }).next(() => offset);
10646
+ }
10629
10647
  }
10630
10648
  /**
10631
10649
  * Helper to get a typed SimpleDbStore for the collectionParents
@@ -13796,7 +13814,7 @@ class LocalStoreImpl {
13796
13814
  this.mutationQueue = this.persistence.getMutationQueue(user, this.indexManager);
13797
13815
  this.localDocuments = new LocalDocumentsView(this.remoteDocuments, this.mutationQueue, this.indexManager);
13798
13816
  this.remoteDocuments.setIndexManager(this.indexManager);
13799
- this.queryEngine.setLocalDocumentsView(this.localDocuments);
13817
+ this.queryEngine.initialize(this.localDocuments, this.indexManager);
13800
13818
  }
13801
13819
  collectGarbage(garbageCollector) {
13802
13820
  return this.persistence.runTransaction('Collect garbage', 'readwrite-primary', txn => garbageCollector.collect(txn, this.targetDataByTarget));
@@ -15538,10 +15556,30 @@ class MemoryEagerDelegate {
15538
15556
  * limitations under the License.
15539
15557
  */
15540
15558
  /**
15541
- * A query engine that takes advantage of the target document mapping in the
15542
- * QueryCache. Query execution is optimized by only reading the documents that
15543
- * previously matched a query plus any documents that were edited after the
15544
- * query was last listened to.
15559
+ * The Firestore query engine.
15560
+ *
15561
+ * Firestore queries can be executed in three modes. The Query Engine determines
15562
+ * what mode to use based on what data is persisted. The mode only determines
15563
+ * the runtime complexity of the query - the result set is equivalent across all
15564
+ * implementations.
15565
+ *
15566
+ * The Query engine will use indexed-based execution if a user has configured
15567
+ * any index that can be used to execute query (via `setIndexConfiguration()`).
15568
+ * Otherwise, the engine will try to optimize the query by re-using a previously
15569
+ * persisted query result. If that is not possible, the query will be executed
15570
+ * via a full collection scan.
15571
+ *
15572
+ * Index-based execution is the default when available. The query engine
15573
+ * supports partial indexed execution and merges the result from the index
15574
+ * lookup with documents that have not yet been indexed. The index evaluation
15575
+ * matches the backend's format and as such, the SDK can use indexing for all
15576
+ * queries that the backend supports.
15577
+ *
15578
+ * If no index exists, the query engine tries to take advantage of the target
15579
+ * document mapping in the TargetCache. These mappings exists for all queries
15580
+ * that have been synced with the backend at least once and allow the query
15581
+ * engine to only read documents that previously matched a query plus any
15582
+ * documents that were edited after the query was last listened to.
15545
15583
  *
15546
15584
  * There are some cases when this optimization is not guaranteed to produce
15547
15585
  * the same results as full collection scans. In these cases, query
@@ -15556,16 +15594,41 @@ class MemoryEagerDelegate {
15556
15594
  * - Queries that have never been CURRENT or free of limbo documents.
15557
15595
  */
15558
15596
  class QueryEngine {
15597
+ constructor() {
15598
+ this.initialized = false;
15599
+ }
15559
15600
  /** Sets the document view to query against. */
15560
- setLocalDocumentsView(localDocuments) {
15601
+ initialize(localDocuments, indexManager) {
15561
15602
  this.localDocumentsView = localDocuments;
15603
+ this.indexManager = indexManager;
15604
+ this.initialized = true;
15562
15605
  }
15563
15606
  /** Returns all local documents matching the specified query. */
15564
15607
  getDocumentsMatchingQuery(transaction, query, lastLimboFreeSnapshotVersion, remoteKeys) {
15565
- // Queries that match all documents don't benefit from using
15566
- // key-based lookups. It is more efficient to scan all documents in a
15567
- // collection, rather than to perform individual lookups.
15568
- if (matchesAllDocuments(query)) {
15608
+ return this.performQueryUsingIndex(transaction, query)
15609
+ .next(result => result
15610
+ ? result
15611
+ : this.performQueryUsingRemoteKeys(transaction, query, remoteKeys, lastLimboFreeSnapshotVersion))
15612
+ .next(result => result ? result : this.executeFullCollectionScan(transaction, query));
15613
+ }
15614
+ /**
15615
+ * Performs an indexed query that evaluates the query based on a collection's
15616
+ * persisted index values. Returns `null` if an index is not available.
15617
+ */
15618
+ performQueryUsingIndex(transaction, query) {
15619
+ {
15620
+ return PersistencePromise.resolve(null);
15621
+ }
15622
+ }
15623
+ /**
15624
+ * Performs a query based on the target's persisted query mapping. Returns
15625
+ * `null` if the mapping is not available or cannot be used.
15626
+ */
15627
+ performQueryUsingRemoteKeys(transaction, query, remoteKeys, lastLimboFreeSnapshotVersion) {
15628
+ if (queryMatchesAllDocuments(query)) {
15629
+ // Queries that match all documents don't benefit from using
15630
+ // key-based lookups. It is more efficient to scan all documents in a
15631
+ // collection, rather than to perform individual lookups.
15569
15632
  return this.executeFullCollectionScan(transaction, query);
15570
15633
  }
15571
15634
  // Queries that have never seen a snapshot without limbo free documents
@@ -15575,8 +15638,7 @@ class QueryEngine {
15575
15638
  }
15576
15639
  return this.localDocumentsView.getDocuments(transaction, remoteKeys).next(documents => {
15577
15640
  const previousResults = this.applyQuery(query, documents);
15578
- if ((hasLimitToFirst(query) || hasLimitToLast(query)) &&
15579
- this.needsRefill(query.limitType, previousResults, remoteKeys, lastLimboFreeSnapshotVersion)) {
15641
+ if (this.needsRefill(query, previousResults, remoteKeys, lastLimboFreeSnapshotVersion)) {
15580
15642
  return this.executeFullCollectionScan(transaction, query);
15581
15643
  }
15582
15644
  if (getLogLevel() <= logger.LogLevel.DEBUG) {
@@ -15584,15 +15646,7 @@ class QueryEngine {
15584
15646
  }
15585
15647
  // Retrieve all results for documents that were updated since the last
15586
15648
  // limbo-document free remote snapshot.
15587
- return this.localDocumentsView.getDocumentsMatchingQuery(transaction, query, newIndexOffsetSuccessorFromReadTime(lastLimboFreeSnapshotVersion, INITIAL_LARGEST_BATCH_ID)).next(updatedResults => {
15588
- // We merge `previousResults` into `updateResults`, since
15589
- // `updateResults` is already a DocumentMap. If a document is
15590
- // contained in both lists, then its contents are the same.
15591
- previousResults.forEach(doc => {
15592
- updatedResults = updatedResults.insert(doc.key, doc);
15593
- });
15594
- return updatedResults;
15595
- });
15649
+ return this.appendRemainingResults(transaction, previousResults, query, newIndexOffsetSuccessorFromReadTime(lastLimboFreeSnapshotVersion, INITIAL_LARGEST_BATCH_ID));
15596
15650
  });
15597
15651
  }
15598
15652
  /** Applies the query filter and sorting to the provided documents. */
@@ -15611,6 +15665,7 @@ class QueryEngine {
15611
15665
  * Determines if a limit query needs to be refilled from cache, making it
15612
15666
  * ineligible for index-free execution.
15613
15667
  *
15668
+ * @param query The query.
15614
15669
  * @param sortedPreviousResults - The documents that matched the query when it
15615
15670
  * was last synchronized, sorted by the query's comparator.
15616
15671
  * @param remoteKeys - The document keys that matched the query at the last
@@ -15618,10 +15673,14 @@ class QueryEngine {
15618
15673
  * @param limboFreeSnapshotVersion - The version of the snapshot when the
15619
15674
  * query was last synchronized.
15620
15675
  */
15621
- needsRefill(limitType, sortedPreviousResults, remoteKeys, limboFreeSnapshotVersion) {
15622
- // The query needs to be refilled if a previously matching document no
15623
- // longer matches.
15676
+ needsRefill(query, sortedPreviousResults, remoteKeys, limboFreeSnapshotVersion) {
15677
+ if (query.limit === null) {
15678
+ // Queries without limits do not need to be refilled.
15679
+ return false;
15680
+ }
15624
15681
  if (remoteKeys.size !== sortedPreviousResults.size) {
15682
+ // The query needs to be refilled if a previously matching document no
15683
+ // longer matches.
15625
15684
  return true;
15626
15685
  }
15627
15686
  // Limit queries are not eligible for index-free query execution if there is
@@ -15632,7 +15691,7 @@ class QueryEngine {
15632
15691
  // the boundary of the limit itself did not change and documents from cache
15633
15692
  // will continue to be "rejected" by this boundary. Therefore, we can ignore
15634
15693
  // any modifications that don't affect the last document.
15635
- const docAtLimitEdge = limitType === "F" /* First */
15694
+ const docAtLimitEdge = query.limitType === "F" /* First */
15636
15695
  ? sortedPreviousResults.last()
15637
15696
  : sortedPreviousResults.first();
15638
15697
  if (!docAtLimitEdge) {
@@ -15648,6 +15707,22 @@ class QueryEngine {
15648
15707
  }
15649
15708
  return this.localDocumentsView.getDocumentsMatchingQuery(transaction, query, IndexOffset.min());
15650
15709
  }
15710
+ /**
15711
+ * Combines the results from an indexed execution with the remaining documents
15712
+ * that have not yet been indexed.
15713
+ */
15714
+ appendRemainingResults(transaction, indexedResults, query, offset) {
15715
+ // Retrieve all results for documents that were updated since the offset.
15716
+ return this.localDocumentsView
15717
+ .getDocumentsMatchingQuery(transaction, query, offset)
15718
+ .next(remainingResults => {
15719
+ // Merge with existing results
15720
+ indexedResults.forEach(d => {
15721
+ remainingResults = remainingResults.insert(d.key, d);
15722
+ });
15723
+ return remainingResults;
15724
+ });
15725
+ }
15651
15726
  }
15652
15727
 
15653
15728
  /**
@@ -21907,10 +21982,12 @@ class View {
21907
21982
  //
21908
21983
  // Note that this should never get used in a refill (when previousChanges is
21909
21984
  // set), because there will only be adds -- no deletes or updates.
21910
- const lastDocInLimit = hasLimitToFirst(this.query) && oldDocumentSet.size === this.query.limit
21985
+ const lastDocInLimit = this.query.limitType === "F" /* First */ &&
21986
+ oldDocumentSet.size === this.query.limit
21911
21987
  ? oldDocumentSet.last()
21912
21988
  : null;
21913
- const firstDocInLimit = hasLimitToLast(this.query) && oldDocumentSet.size === this.query.limit
21989
+ const firstDocInLimit = this.query.limitType === "L" /* Last */ &&
21990
+ oldDocumentSet.size === this.query.limit
21914
21991
  ? oldDocumentSet.first()
21915
21992
  : null;
21916
21993
  docChanges.inorderTraversal((key, entry) => {
@@ -21983,9 +22060,9 @@ class View {
21983
22060
  }
21984
22061
  });
21985
22062
  // Drop documents out to meet limit/limitToLast requirement.
21986
- if (hasLimitToFirst(this.query) || hasLimitToLast(this.query)) {
22063
+ if (this.query.limit !== null) {
21987
22064
  while (newDocumentSet.size > this.query.limit) {
21988
- const oldDoc = hasLimitToFirst(this.query)
22065
+ const oldDoc = this.query.limitType === "F" /* First */
21989
22066
  ? newDocumentSet.last()
21990
22067
  : newDocumentSet.first();
21991
22068
  newDocumentSet = newDocumentSet.delete(oldDoc.key);
@@ -27116,7 +27193,8 @@ function snapshotEqual(left, right) {
27116
27193
  * limitations under the License.
27117
27194
  */
27118
27195
  function validateHasExplicitOrderByForLimitToLast(query) {
27119
- if (hasLimitToLast(query) && query.explicitOrderBy.length === 0) {
27196
+ if (query.limitType === "L" /* Last */ &&
27197
+ query.explicitOrderBy.length === 0) {
27120
27198
  throw new FirestoreError(Code.UNIMPLEMENTED, 'limitToLast() queries require specifying at least one orderBy() clause');
27121
27199
  }
27122
27200
  }