@firebase/firestore 3.4.4-canary.d04b608f2 → 3.4.4-canary.f5ac47fb1

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 (64) 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 +11 -0
  6. package/dist/firestore/src/local/indexeddb_schema.d.ts +121 -7
  7. package/dist/firestore/src/local/memory_index_manager.d.ts +11 -0
  8. package/dist/firestore/src/local/simple_db.d.ts +1 -0
  9. package/dist/firestore/test/util/helpers.d.ts +1 -1
  10. package/dist/index.d.ts +1 -2
  11. package/dist/index.esm2017.js +2514 -2352
  12. package/dist/index.esm2017.js.map +1 -1
  13. package/dist/index.esm5.js +3147 -3040
  14. package/dist/index.esm5.js.map +1 -1
  15. package/dist/index.node.cjs.js +280 -95
  16. package/dist/index.node.cjs.js.map +1 -1
  17. package/dist/index.node.mjs +280 -95
  18. package/dist/index.node.mjs.map +1 -1
  19. package/dist/index.rn.js +2561 -2395
  20. package/dist/index.rn.js.map +1 -1
  21. package/dist/internal.d.ts +171 -4
  22. package/dist/lite/firestore/src/api/snapshot.d.ts +1 -2
  23. package/dist/lite/firestore/src/core/target.d.ts +8 -4
  24. package/dist/lite/firestore/src/lite-api/query.d.ts +2 -2
  25. package/dist/lite/firestore/src/local/index_manager.d.ts +52 -0
  26. package/dist/lite/firestore/src/local/indexeddb_index_manager.d.ts +11 -0
  27. package/dist/lite/firestore/src/local/indexeddb_schema.d.ts +121 -7
  28. package/dist/lite/firestore/src/local/memory_index_manager.d.ts +11 -0
  29. package/dist/lite/firestore/src/local/simple_db.d.ts +1 -0
  30. package/dist/lite/firestore/test/util/helpers.d.ts +1 -1
  31. package/dist/lite/index.browser.esm2017.js +301 -298
  32. package/dist/lite/index.browser.esm2017.js.map +1 -1
  33. package/dist/lite/index.browser.esm5.js +327 -326
  34. package/dist/lite/index.browser.esm5.js.map +1 -1
  35. package/dist/lite/index.node.cjs.js +36 -29
  36. package/dist/lite/index.node.cjs.js.map +1 -1
  37. package/dist/lite/index.node.mjs +36 -29
  38. package/dist/lite/index.node.mjs.map +1 -1
  39. package/dist/lite/index.rn.esm2017.js +357 -354
  40. package/dist/lite/index.rn.esm2017.js.map +1 -1
  41. package/dist/lite/internal.d.ts +2 -2
  42. package/dist/lite/packages/firestore/dist/lite/index.browser.esm2017.d.ts +90 -90
  43. package/dist/lite/packages/firestore/src/api/snapshot.d.ts +1 -2
  44. package/dist/lite/packages/firestore/src/core/target.d.ts +8 -4
  45. package/dist/lite/packages/firestore/src/lite-api/query.d.ts +2 -2
  46. package/dist/lite/packages/firestore/src/local/index_manager.d.ts +52 -0
  47. package/dist/lite/packages/firestore/src/local/indexeddb_index_manager.d.ts +11 -0
  48. package/dist/lite/packages/firestore/src/local/indexeddb_schema.d.ts +121 -7
  49. package/dist/lite/packages/firestore/src/local/memory_index_manager.d.ts +11 -0
  50. package/dist/lite/packages/firestore/src/local/simple_db.d.ts +1 -0
  51. package/dist/lite/packages/firestore/test/util/helpers.d.ts +1 -1
  52. package/dist/lite/private.d.ts +2 -2
  53. package/dist/packages/firestore/dist/index.esm2017.d.ts +78 -78
  54. package/dist/packages/firestore/src/api/snapshot.d.ts +1 -2
  55. package/dist/packages/firestore/src/core/target.d.ts +8 -4
  56. package/dist/packages/firestore/src/lite-api/query.d.ts +2 -2
  57. package/dist/packages/firestore/src/local/index_manager.d.ts +52 -0
  58. package/dist/packages/firestore/src/local/indexeddb_index_manager.d.ts +11 -0
  59. package/dist/packages/firestore/src/local/indexeddb_schema.d.ts +121 -7
  60. package/dist/packages/firestore/src/local/memory_index_manager.d.ts +11 -0
  61. package/dist/packages/firestore/src/local/simple_db.d.ts +1 -0
  62. package/dist/packages/firestore/test/util/helpers.d.ts +1 -1
  63. package/dist/private.d.ts +171 -4
  64. package/package.json +9 -9
@@ -12,7 +12,7 @@ var grpcJs = require('@grpc/grpc-js');
12
12
  var protoLoader = require('@grpc/proto-loader');
13
13
 
14
14
  const name = "@firebase/firestore";
15
- const version$1 = "3.4.4-canary.d04b608f2";
15
+ const version$1 = "3.4.4-canary.f5ac47fb1";
16
16
 
17
17
  /**
18
18
  * @license
@@ -65,7 +65,7 @@ User.GOOGLE_CREDENTIALS = new User('google-credentials-uid');
65
65
  User.FIRST_PARTY = new User('first-party-uid');
66
66
  User.MOCK_USER = new User('mock-user');
67
67
 
68
- const version = "9.6.5-canary.d04b608f2";
68
+ const version = "9.6.6-canary.f5ac47fb1";
69
69
 
70
70
  /**
71
71
  * @license
@@ -1196,23 +1196,6 @@ function decodeResourcePath(path) {
1196
1196
  }
1197
1197
  return new ResourcePath(segments);
1198
1198
  }
1199
-
1200
- /**
1201
- * @license
1202
- * Copyright 2017 Google LLC
1203
- *
1204
- * Licensed under the Apache License, Version 2.0 (the "License");
1205
- * you may not use this file except in compliance with the License.
1206
- * You may obtain a copy of the License at
1207
- *
1208
- * http://www.apache.org/licenses/LICENSE-2.0
1209
- *
1210
- * Unless required by applicable law or agreed to in writing, software
1211
- * distributed under the License is distributed on an "AS IS" BASIS,
1212
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1213
- * See the License for the specific language governing permissions and
1214
- * limitations under the License.
1215
- */
1216
1199
  /**
1217
1200
  * Schema Version for the Web client:
1218
1201
  * 1. Initial version including Mutation Queue, Query Cache, and Remote
@@ -1231,6 +1214,7 @@ function decodeResourcePath(path) {
1231
1214
  * an auto-incrementing ID. This is required for Index-Free queries.
1232
1215
  * 10. Rewrite the canonical IDs to the explicit Protobuf-based format.
1233
1216
  * 11. Add bundles and named_queries for bundle support.
1217
+ * 12. Add indexing support.
1234
1218
  */
1235
1219
  const SCHEMA_VERSION = 11;
1236
1220
  /**
@@ -1757,9 +1741,7 @@ class DbClientMetadata {
1757
1741
  DbClientMetadata.store = 'clientMetadata';
1758
1742
  /** Keys are automatically assigned via the clientId properties. */
1759
1743
  DbClientMetadata.keyPath = 'clientId';
1760
- /**
1761
- * A object representing a bundle loaded by the SDK.
1762
- */
1744
+ /** An object representing a bundle loaded by the SDK. */
1763
1745
  class DbBundle {
1764
1746
  constructor(
1765
1747
  /** The ID of the loaded bundle. */
@@ -1776,9 +1758,7 @@ class DbBundle {
1776
1758
  /** Name of the IndexedDb object store. */
1777
1759
  DbBundle.store = 'bundles';
1778
1760
  DbBundle.keyPath = 'bundleId';
1779
- /**
1780
- * A object representing a named query loaded by the SDK via a bundle.
1781
- */
1761
+ /** An object representing a named query loaded by the SDK via a bundle. */
1782
1762
  class DbNamedQuery {
1783
1763
  constructor(
1784
1764
  /** The name of the query. */
@@ -1795,6 +1775,93 @@ class DbNamedQuery {
1795
1775
  /** Name of the IndexedDb object store. */
1796
1776
  DbNamedQuery.store = 'namedQueries';
1797
1777
  DbNamedQuery.keyPath = 'name';
1778
+ /** An object representing the global configuration for a field index. */
1779
+ class DbIndexConfiguration {
1780
+ constructor(
1781
+ /** The index id for this entry. */
1782
+ indexId,
1783
+ /** The collection group this index belongs to. */
1784
+ collectionGroup,
1785
+ /** The fields to index for this index. */
1786
+ fields) {
1787
+ this.indexId = indexId;
1788
+ this.collectionGroup = collectionGroup;
1789
+ this.fields = fields;
1790
+ }
1791
+ }
1792
+ /** Name of the IndexedDb object store. */
1793
+ DbIndexConfiguration.store = 'indexConfiguration';
1794
+ DbIndexConfiguration.keyPath = 'indexId';
1795
+ /**
1796
+ * An object describing how up-to-date the index backfill is for each user and
1797
+ * index.
1798
+ */
1799
+ class DbIndexState {
1800
+ constructor(
1801
+ /** The index id for this entry. */
1802
+ indexId,
1803
+ /** The user id for this entry. */
1804
+ uid,
1805
+ /**
1806
+ * A number that indicates when the index was last updated (relative to
1807
+ * other indexes).
1808
+ */
1809
+ sequenceNumber,
1810
+ /**
1811
+ * The latest read time that has been indexed by Firestore for this field
1812
+ * index. Set to `{seconds: 0, nanos: 0}` if no documents have been indexed.
1813
+ */
1814
+ readTime,
1815
+ /**
1816
+ * The last document that has been indexed for this field index. Empty if
1817
+ * no documents have been indexed.
1818
+ */
1819
+ documentKey,
1820
+ /**
1821
+ * The largest mutation batch id that has been processed for this index. -1
1822
+ * if no mutations have been indexed.
1823
+ */
1824
+ largestBatchId) {
1825
+ this.indexId = indexId;
1826
+ this.uid = uid;
1827
+ this.sequenceNumber = sequenceNumber;
1828
+ this.readTime = readTime;
1829
+ this.documentKey = documentKey;
1830
+ this.largestBatchId = largestBatchId;
1831
+ }
1832
+ }
1833
+ /** Name of the IndexedDb object store. */
1834
+ DbIndexState.store = 'indexState';
1835
+ DbIndexState.keyPath = ['indexId', 'uid'];
1836
+ /** An object that stores the encoded entries for all documents and fields. */
1837
+ class DbIndexEntries {
1838
+ constructor(
1839
+ /** The index id for this entry. */
1840
+ indexId,
1841
+ /** The user id for this entry. */
1842
+ uid,
1843
+ /** The encoded array index value for this entry. */
1844
+ arrayValue,
1845
+ /** The encoded directional value for equality and inequality filters. */
1846
+ directionalValue,
1847
+ /** The document key this entry points to. */
1848
+ documentKey) {
1849
+ this.indexId = indexId;
1850
+ this.uid = uid;
1851
+ this.arrayValue = arrayValue;
1852
+ this.directionalValue = directionalValue;
1853
+ this.documentKey = documentKey;
1854
+ }
1855
+ }
1856
+ /** Name of the IndexedDb object store. */
1857
+ DbIndexEntries.store = 'indexEntries';
1858
+ DbIndexEntries.keyPath = [
1859
+ 'indexId',
1860
+ 'uid',
1861
+ 'arrayValue',
1862
+ 'directionalValue',
1863
+ 'documentKey'
1864
+ ];
1798
1865
  // Visible for testing
1799
1866
  const V1_STORES = [
1800
1867
  DbMutationQueue.store,
@@ -1809,7 +1876,6 @@ const V1_STORES = [
1809
1876
  // V2 is no longer usable (see comment at top of file)
1810
1877
  // Visible for testing
1811
1878
  const V3_STORES = V1_STORES;
1812
- // Visible for testing
1813
1879
  // Note: DbRemoteDocumentChanges is no longer used and dropped with v9.
1814
1880
  const V4_STORES = [...V3_STORES, DbClientMetadata.store];
1815
1881
  // V5 does not change the set of stores.
@@ -1819,6 +1885,12 @@ const V8_STORES = [...V6_STORES, DbCollectionParent.store];
1819
1885
  // V9 does not change the set of stores.
1820
1886
  // V10 does not change the set of stores.
1821
1887
  const V11_STORES = [...V8_STORES, DbBundle.store, DbNamedQuery.store];
1888
+ [
1889
+ ...V11_STORES,
1890
+ DbIndexConfiguration.store,
1891
+ DbIndexState.store,
1892
+ DbIndexEntries.store
1893
+ ];
1822
1894
  /**
1823
1895
  * The list of all default IndexedDB stores used throughout the SDK. This is
1824
1896
  * used when creating transactions so that access across all stores is done
@@ -2121,6 +2193,15 @@ class SimpleDbTransaction {
2121
2193
  this.transaction.abort();
2122
2194
  }
2123
2195
  }
2196
+ maybeCommit() {
2197
+ // If the browser supports V3 IndexedDB, we invoke commit() explicitly to
2198
+ // speed up index DB processing if the event loop remains blocks.
2199
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2200
+ const maybeV3IndexedDb = this.transaction;
2201
+ if (!this.aborted && typeof maybeV3IndexedDb.commit === 'function') {
2202
+ maybeV3IndexedDb.commit();
2203
+ }
2204
+ }
2124
2205
  /**
2125
2206
  * Returns a SimpleDbStore<KeyType, ValueType> for the specified store. All
2126
2207
  * operations performed on the SimpleDbStore happen within the context of this
@@ -2317,6 +2398,10 @@ class SimpleDb {
2317
2398
  this.db = await this.ensureDb(action);
2318
2399
  const transaction = SimpleDbTransaction.open(this.db, action, readonly ? 'readonly' : 'readwrite', objectStores);
2319
2400
  const transactionFnResult = transactionFn(transaction)
2401
+ .next(result => {
2402
+ transaction.maybeCommit();
2403
+ return result;
2404
+ })
2320
2405
  .catch(error => {
2321
2406
  // Abort the transaction if there was an error.
2322
2407
  transaction.abort(error);
@@ -4464,27 +4549,29 @@ function newTarget(path, collectionGroup = null, orderBy = [], filters = [], lim
4464
4549
  function canonifyTarget(target) {
4465
4550
  const targetImpl = debugCast(target);
4466
4551
  if (targetImpl.memoizedCanonicalId === null) {
4467
- let canonicalId = targetImpl.path.canonicalString();
4552
+ let str = targetImpl.path.canonicalString();
4468
4553
  if (targetImpl.collectionGroup !== null) {
4469
- canonicalId += '|cg:' + targetImpl.collectionGroup;
4554
+ str += '|cg:' + targetImpl.collectionGroup;
4470
4555
  }
4471
- canonicalId += '|f:';
4472
- canonicalId += targetImpl.filters.map(f => canonifyFilter(f)).join(',');
4473
- canonicalId += '|ob:';
4474
- canonicalId += targetImpl.orderBy.map(o => canonifyOrderBy(o)).join(',');
4556
+ str += '|f:';
4557
+ str += targetImpl.filters.map(f => canonifyFilter(f)).join(',');
4558
+ str += '|ob:';
4559
+ str += targetImpl.orderBy.map(o => canonifyOrderBy(o)).join(',');
4475
4560
  if (!isNullOrUndefined(targetImpl.limit)) {
4476
- canonicalId += '|l:';
4477
- canonicalId += targetImpl.limit;
4561
+ str += '|l:';
4562
+ str += targetImpl.limit;
4478
4563
  }
4479
4564
  if (targetImpl.startAt) {
4480
- canonicalId += '|lb:';
4481
- canonicalId += canonifyBound(targetImpl.startAt);
4565
+ str += '|lb:';
4566
+ str += targetImpl.startAt.inclusive ? 'b:' : 'a:';
4567
+ str += targetImpl.startAt.position.map(p => canonicalId(p)).join(',');
4482
4568
  }
4483
4569
  if (targetImpl.endAt) {
4484
- canonicalId += '|ub:';
4485
- canonicalId += canonifyBound(targetImpl.endAt);
4570
+ str += '|ub:';
4571
+ str += targetImpl.endAt.inclusive ? 'a:' : 'b:';
4572
+ str += targetImpl.endAt.position.map(p => canonicalId(p)).join(',');
4486
4573
  }
4487
- targetImpl.memoizedCanonicalId = canonicalId;
4574
+ targetImpl.memoizedCanonicalId = str;
4488
4575
  }
4489
4576
  return targetImpl.memoizedCanonicalId;
4490
4577
  }
@@ -4507,10 +4594,14 @@ function stringifyTarget(target) {
4507
4594
  .join(', ')}]`;
4508
4595
  }
4509
4596
  if (target.startAt) {
4510
- str += ', startAt: ' + canonifyBound(target.startAt);
4597
+ str += ', startAt: ';
4598
+ str += target.startAt.inclusive ? 'b:' : 'a:';
4599
+ str += target.startAt.position.map(p => canonicalId(p)).join(',');
4511
4600
  }
4512
4601
  if (target.endAt) {
4513
- str += ', endAt: ' + canonifyBound(target.endAt);
4602
+ str += ', endAt: ';
4603
+ str += target.endAt.inclusive ? 'a:' : 'b:';
4604
+ str += target.endAt.position.map(p => canonicalId(p)).join(',');
4514
4605
  }
4515
4606
  return `Target(${str})`;
4516
4607
  }
@@ -4733,7 +4824,6 @@ class ArrayContainsAnyFilter extends FieldFilter {
4733
4824
  return other.arrayValue.values.some(val => arrayValueContains(this.value.arrayValue, val));
4734
4825
  }
4735
4826
  }
4736
- // TODO(indexing): Change Bound.before to "inclusive"
4737
4827
  /**
4738
4828
  * Represents a bound of a query.
4739
4829
  *
@@ -4749,17 +4839,11 @@ class ArrayContainsAnyFilter extends FieldFilter {
4749
4839
  * just after the provided values.
4750
4840
  */
4751
4841
  class Bound {
4752
- constructor(position, before) {
4842
+ constructor(position, inclusive) {
4753
4843
  this.position = position;
4754
- this.before = before;
4844
+ this.inclusive = inclusive;
4755
4845
  }
4756
4846
  }
4757
- function canonifyBound(bound) {
4758
- // TODO(b/29183165): Make this collision robust.
4759
- return `${bound.before ? 'b' : 'a'}:${bound.position
4760
- .map(p => canonicalId(p))
4761
- .join(',')}`;
4762
- }
4763
4847
  /**
4764
4848
  * An ordering on a field, in some Direction. Direction defaults to ASCENDING.
4765
4849
  */
@@ -4779,11 +4863,7 @@ function stringifyOrderBy(orderBy) {
4779
4863
  function orderByEquals(left, right) {
4780
4864
  return left.dir === right.dir && left.field.isEqual(right.field);
4781
4865
  }
4782
- /**
4783
- * Returns true if a document sorts before a bound using the provided sort
4784
- * order.
4785
- */
4786
- function sortsBeforeDocument(bound, orderBy, doc) {
4866
+ function boundCompareToDocument(bound, orderBy, doc) {
4787
4867
  let comparison = 0;
4788
4868
  for (let i = 0; i < bound.position.length; i++) {
4789
4869
  const orderByComponent = orderBy[i];
@@ -4802,7 +4882,23 @@ function sortsBeforeDocument(bound, orderBy, doc) {
4802
4882
  break;
4803
4883
  }
4804
4884
  }
4805
- return bound.before ? comparison <= 0 : comparison < 0;
4885
+ return comparison;
4886
+ }
4887
+ /**
4888
+ * Returns true if a document sorts after a bound using the provided sort
4889
+ * order.
4890
+ */
4891
+ function boundSortsAfterDocument(bound, orderBy, doc) {
4892
+ const comparison = boundCompareToDocument(bound, orderBy, doc);
4893
+ return bound.inclusive ? comparison >= 0 : comparison > 0;
4894
+ }
4895
+ /**
4896
+ * Returns true if a document sorts before a bound using the provided sort
4897
+ * order.
4898
+ */
4899
+ function boundSortsBeforeDocument(bound, orderBy, doc) {
4900
+ const comparison = boundCompareToDocument(bound, orderBy, doc);
4901
+ return bound.inclusive ? comparison <= 0 : comparison < 0;
4806
4902
  }
4807
4903
  function boundEquals(left, right) {
4808
4904
  if (left === null) {
@@ -4811,7 +4907,7 @@ function boundEquals(left, right) {
4811
4907
  else if (right === null) {
4812
4908
  return false;
4813
4909
  }
4814
- if (left.before !== right.before ||
4910
+ if (left.inclusive !== right.inclusive ||
4815
4911
  left.position.length !== right.position.length) {
4816
4912
  return false;
4817
4913
  }
@@ -5015,10 +5111,10 @@ function queryToTarget(query) {
5015
5111
  }
5016
5112
  // We need to swap the cursors to match the now-flipped query ordering.
5017
5113
  const startAt = queryImpl.endAt
5018
- ? new Bound(queryImpl.endAt.position, !queryImpl.endAt.before)
5114
+ ? new Bound(queryImpl.endAt.position, !queryImpl.endAt.inclusive)
5019
5115
  : null;
5020
5116
  const endAt = queryImpl.startAt
5021
- ? new Bound(queryImpl.startAt.position, !queryImpl.startAt.before)
5117
+ ? new Bound(queryImpl.startAt.position, !queryImpl.startAt.inclusive)
5022
5118
  : null;
5023
5119
  // Now return as a LimitType.First query.
5024
5120
  queryImpl.memoizedTarget = newTarget(queryImpl.path, queryImpl.collectionGroup, orderBys, queryImpl.filters, queryImpl.limit, startAt, endAt);
@@ -5106,11 +5202,11 @@ function queryMatchesFilters(query, doc) {
5106
5202
  /** Makes sure a document is within the bounds, if provided. */
5107
5203
  function queryMatchesBounds(query, doc) {
5108
5204
  if (query.startAt &&
5109
- !sortsBeforeDocument(query.startAt, queryOrderBy(query), doc)) {
5205
+ !boundSortsBeforeDocument(query.startAt, queryOrderBy(query), doc)) {
5110
5206
  return false;
5111
5207
  }
5112
5208
  if (query.endAt &&
5113
- sortsBeforeDocument(query.endAt, queryOrderBy(query), doc)) {
5209
+ !boundSortsAfterDocument(query.endAt, queryOrderBy(query), doc)) {
5114
5210
  return false;
5115
5211
  }
5116
5212
  return true;
@@ -7989,10 +8085,10 @@ function toQueryTarget(serializer, target) {
7989
8085
  result.structuredQuery.limit = limit;
7990
8086
  }
7991
8087
  if (target.startAt) {
7992
- result.structuredQuery.startAt = toCursor(target.startAt);
8088
+ result.structuredQuery.startAt = toStartAtCursor(target.startAt);
7993
8089
  }
7994
8090
  if (target.endAt) {
7995
- result.structuredQuery.endAt = toCursor(target.endAt);
8091
+ result.structuredQuery.endAt = toEndAtCursor(target.endAt);
7996
8092
  }
7997
8093
  return result;
7998
8094
  }
@@ -8025,11 +8121,11 @@ function convertQueryTargetToQuery(target) {
8025
8121
  }
8026
8122
  let startAt = null;
8027
8123
  if (query.startAt) {
8028
- startAt = fromCursor(query.startAt);
8124
+ startAt = fromStartAtCursor(query.startAt);
8029
8125
  }
8030
8126
  let endAt = null;
8031
8127
  if (query.endAt) {
8032
- endAt = fromCursor(query.endAt);
8128
+ endAt = fromEndAtCursor(query.endAt);
8033
8129
  }
8034
8130
  return newQuery(path, collectionGroup, orderBy, filterBy, limit, "F" /* First */, startAt, endAt);
8035
8131
  }
@@ -8120,16 +8216,27 @@ function toOrder(orderBys) {
8120
8216
  function fromOrder(orderBys) {
8121
8217
  return orderBys.map(order => fromPropertyOrder(order));
8122
8218
  }
8123
- function toCursor(cursor) {
8219
+ function toStartAtCursor(cursor) {
8220
+ return {
8221
+ before: cursor.inclusive,
8222
+ values: cursor.position
8223
+ };
8224
+ }
8225
+ function toEndAtCursor(cursor) {
8124
8226
  return {
8125
- before: cursor.before,
8227
+ before: !cursor.inclusive,
8126
8228
  values: cursor.position
8127
8229
  };
8128
8230
  }
8129
- function fromCursor(cursor) {
8130
- const before = !!cursor.before;
8231
+ function fromStartAtCursor(cursor) {
8232
+ const inclusive = !!cursor.before;
8233
+ const position = cursor.values || [];
8234
+ return new Bound(position, inclusive);
8235
+ }
8236
+ function fromEndAtCursor(cursor) {
8237
+ const inclusive = !cursor.before;
8131
8238
  const position = cursor.values || [];
8132
- return new Bound(position, before);
8239
+ return new Bound(position, inclusive);
8133
8240
  }
8134
8241
  // visible for testing
8135
8242
  function toDirection(dir) {
@@ -8682,6 +8789,38 @@ class MemoryIndexManager {
8682
8789
  getCollectionParents(transaction, collectionId) {
8683
8790
  return PersistencePromise.resolve(this.collectionParentIndex.getEntries(collectionId));
8684
8791
  }
8792
+ addFieldIndex(transaction, index) {
8793
+ // Field indices are not supported with memory persistence.
8794
+ return PersistencePromise.resolve();
8795
+ }
8796
+ deleteFieldIndex(transaction, index) {
8797
+ // Field indices are not supported with memory persistence.
8798
+ return PersistencePromise.resolve();
8799
+ }
8800
+ getDocumentsMatchingTarget(transaction, fieldIndex, target) {
8801
+ // Field indices are not supported with memory persistence.
8802
+ return PersistencePromise.resolve(documentKeySet());
8803
+ }
8804
+ getFieldIndex(transaction, target) {
8805
+ // Field indices are not supported with memory persistence.
8806
+ return PersistencePromise.resolve(null);
8807
+ }
8808
+ getFieldIndexes(transaction, collectionGroup) {
8809
+ // Field indices are not supported with memory persistence.
8810
+ return PersistencePromise.resolve([]);
8811
+ }
8812
+ getNextCollectionGroupToUpdate(transaction) {
8813
+ // Field indices are not supported with memory persistence.
8814
+ return PersistencePromise.resolve(null);
8815
+ }
8816
+ updateCollectionGroup(transaction, collectionGroup, offset) {
8817
+ // Field indices are not supported with memory persistence.
8818
+ return PersistencePromise.resolve();
8819
+ }
8820
+ updateIndexEntries(transaction, documents) {
8821
+ // Field indices are not supported with memory persistence.
8822
+ return PersistencePromise.resolve();
8823
+ }
8685
8824
  }
8686
8825
  /**
8687
8826
  * Internal implementation of the collection-parent index exposed by MemoryIndexManager.
@@ -8790,6 +8929,38 @@ class IndexedDbIndexManager {
8790
8929
  return parentPaths;
8791
8930
  });
8792
8931
  }
8932
+ addFieldIndex(transaction, index) {
8933
+ // TODO(indexing): Implement
8934
+ return PersistencePromise.resolve();
8935
+ }
8936
+ deleteFieldIndex(transaction, index) {
8937
+ // TODO(indexing): Implement
8938
+ return PersistencePromise.resolve();
8939
+ }
8940
+ getDocumentsMatchingTarget(transaction, fieldIndex, target) {
8941
+ // TODO(indexing): Implement
8942
+ return PersistencePromise.resolve(documentKeySet());
8943
+ }
8944
+ getFieldIndex(transaction, target) {
8945
+ // TODO(indexing): Implement
8946
+ return PersistencePromise.resolve(null);
8947
+ }
8948
+ getFieldIndexes(transaction, collectionGroup) {
8949
+ // TODO(indexing): Implement
8950
+ return PersistencePromise.resolve([]);
8951
+ }
8952
+ getNextCollectionGroupToUpdate(transaction) {
8953
+ // TODO(indexing): Implement
8954
+ return PersistencePromise.resolve(null);
8955
+ }
8956
+ updateCollectionGroup(transaction, collectionGroup, offset) {
8957
+ // TODO(indexing): Implement
8958
+ return PersistencePromise.resolve();
8959
+ }
8960
+ updateIndexEntries(transaction, documents) {
8961
+ // TODO(indexing): Implement
8962
+ return PersistencePromise.resolve();
8963
+ }
8793
8964
  }
8794
8965
  /**
8795
8966
  * Helper to get a typed SimpleDbStore for the collectionParents
@@ -10641,9 +10812,6 @@ class SchemaConverter {
10641
10812
  * and local feature development.
10642
10813
  */
10643
10814
  createOrUpgrade(db, txn, fromVersion, toVersion) {
10644
- hardAssert(fromVersion < toVersion &&
10645
- fromVersion >= 0 &&
10646
- toVersion <= SCHEMA_VERSION);
10647
10815
  const simpleDbTransaction = new SimpleDbTransaction('createOrUpgrade', txn);
10648
10816
  if (fromVersion < 1 && toVersion >= 1) {
10649
10817
  createPrimaryClientStore(db);
@@ -10710,6 +10878,11 @@ class SchemaConverter {
10710
10878
  createNamedQueriesStore(db);
10711
10879
  });
10712
10880
  }
10881
+ if (fromVersion < 12 && toVersion >= 12) {
10882
+ p = p.next(() => {
10883
+ createFieldIndex(db);
10884
+ });
10885
+ }
10713
10886
  return p;
10714
10887
  }
10715
10888
  addDocumentGlobal(txn) {
@@ -10916,6 +11089,17 @@ function createNamedQueriesStore(db) {
10916
11089
  db.createObjectStore(DbNamedQuery.store, {
10917
11090
  keyPath: DbNamedQuery.keyPath
10918
11091
  });
11092
+ }
11093
+ function createFieldIndex(db) {
11094
+ db.createObjectStore(DbIndexConfiguration.store, {
11095
+ keyPath: DbIndexConfiguration.keyPath
11096
+ });
11097
+ db.createObjectStore(DbIndexState.store, {
11098
+ keyPath: DbIndexState.keyPath
11099
+ });
11100
+ db.createObjectStore(DbIndexEntries.store, {
11101
+ keyPath: DbIndexEntries.keyPath
11102
+ });
10919
11103
  }
10920
11104
 
10921
11105
  /**
@@ -20344,12 +20528,12 @@ async function syncEngineListen(syncEngine, query) {
20344
20528
  }
20345
20529
  else {
20346
20530
  const targetData = await localStoreAllocateTarget(syncEngineImpl.localStore, queryToTarget(query));
20347
- const status = syncEngineImpl.sharedClientState.addLocalQueryTarget(targetData.targetId);
20348
- targetId = targetData.targetId;
20349
- viewSnapshot = await initializeViewAndComputeSnapshot(syncEngineImpl, query, targetId, status === 'current');
20350
20531
  if (syncEngineImpl.isPrimaryClient) {
20351
20532
  remoteStoreListen(syncEngineImpl.remoteStore, targetData);
20352
20533
  }
20534
+ const status = syncEngineImpl.sharedClientState.addLocalQueryTarget(targetData.targetId);
20535
+ targetId = targetData.targetId;
20536
+ viewSnapshot = await initializeViewAndComputeSnapshot(syncEngineImpl, query, targetId, status === 'current');
20353
20537
  }
20354
20538
  return viewSnapshot;
20355
20539
  }
@@ -24857,8 +25041,7 @@ class DocumentSnapshot extends DocumentSnapshot$1 {
24857
25041
  this.metadata = metadata;
24858
25042
  }
24859
25043
  /**
24860
- * Property of the `DocumentSnapshot` that signals whether or not the data
24861
- * exists. True if the document exists.
25044
+ * Returns whether or not the data exists. True if the document exists.
24862
25045
  */
24863
25046
  exists() {
24864
25047
  return super.exists();
@@ -25232,51 +25415,53 @@ function limitToLast(limit) {
25232
25415
  return new QueryLimitConstraint('limitToLast', limit, "L" /* Last */);
25233
25416
  }
25234
25417
  class QueryStartAtConstraint extends QueryConstraint {
25235
- constructor(type, _docOrFields, _before) {
25418
+ constructor(type, _docOrFields, _inclusive) {
25236
25419
  super();
25237
25420
  this.type = type;
25238
25421
  this._docOrFields = _docOrFields;
25239
- this._before = _before;
25422
+ this._inclusive = _inclusive;
25240
25423
  }
25241
25424
  _apply(query) {
25242
- const bound = newQueryBoundFromDocOrFields(query, this.type, this._docOrFields, this._before);
25425
+ const bound = newQueryBoundFromDocOrFields(query, this.type, this._docOrFields, this._inclusive);
25243
25426
  return new Query(query.firestore, query.converter, queryWithStartAt(query._query, bound));
25244
25427
  }
25245
25428
  }
25246
25429
  function startAt(...docOrFields) {
25247
- return new QueryStartAtConstraint('startAt', docOrFields, /*before=*/ true);
25430
+ return new QueryStartAtConstraint('startAt', docOrFields,
25431
+ /*inclusive=*/ true);
25248
25432
  }
25249
25433
  function startAfter(...docOrFields) {
25250
25434
  return new QueryStartAtConstraint('startAfter', docOrFields,
25251
- /*before=*/ false);
25435
+ /*inclusive=*/ false);
25252
25436
  }
25253
25437
  class QueryEndAtConstraint extends QueryConstraint {
25254
- constructor(type, _docOrFields, _before) {
25438
+ constructor(type, _docOrFields, _inclusive) {
25255
25439
  super();
25256
25440
  this.type = type;
25257
25441
  this._docOrFields = _docOrFields;
25258
- this._before = _before;
25442
+ this._inclusive = _inclusive;
25259
25443
  }
25260
25444
  _apply(query) {
25261
- const bound = newQueryBoundFromDocOrFields(query, this.type, this._docOrFields, this._before);
25445
+ const bound = newQueryBoundFromDocOrFields(query, this.type, this._docOrFields, this._inclusive);
25262
25446
  return new Query(query.firestore, query.converter, queryWithEndAt(query._query, bound));
25263
25447
  }
25264
25448
  }
25265
25449
  function endBefore(...docOrFields) {
25266
- return new QueryEndAtConstraint('endBefore', docOrFields, /*before=*/ true);
25450
+ return new QueryEndAtConstraint('endBefore', docOrFields,
25451
+ /*inclusive=*/ false);
25267
25452
  }
25268
25453
  function endAt(...docOrFields) {
25269
- return new QueryEndAtConstraint('endAt', docOrFields, /*before=*/ false);
25454
+ return new QueryEndAtConstraint('endAt', docOrFields, /*inclusive=*/ true);
25270
25455
  }
25271
25456
  /** Helper function to create a bound from a document or fields */
25272
- function newQueryBoundFromDocOrFields(query, methodName, docOrFields, before) {
25457
+ function newQueryBoundFromDocOrFields(query, methodName, docOrFields, inclusive) {
25273
25458
  docOrFields[0] = util$1.getModularInstance(docOrFields[0]);
25274
25459
  if (docOrFields[0] instanceof DocumentSnapshot$1) {
25275
- return newQueryBoundFromDocument(query._query, query.firestore._databaseId, methodName, docOrFields[0]._document, before);
25460
+ return newQueryBoundFromDocument(query._query, query.firestore._databaseId, methodName, docOrFields[0]._document, inclusive);
25276
25461
  }
25277
25462
  else {
25278
25463
  const reader = newUserDataReader(query.firestore);
25279
- return newQueryBoundFromFields(query._query, query.firestore._databaseId, reader, methodName, docOrFields, before);
25464
+ return newQueryBoundFromFields(query._query, query.firestore._databaseId, reader, methodName, docOrFields, inclusive);
25280
25465
  }
25281
25466
  }
25282
25467
  function newQueryFilter(query, methodName, dataReader, databaseId, fieldPath, op, value) {
@@ -25334,7 +25519,7 @@ function newQueryOrderBy(query, fieldPath, direction) {
25334
25519
  * of the query or if any of the fields in the order by are an uncommitted
25335
25520
  * server timestamp.
25336
25521
  */
25337
- function newQueryBoundFromDocument(query, databaseId, methodName, doc, before) {
25522
+ function newQueryBoundFromDocument(query, databaseId, methodName, doc, inclusive) {
25338
25523
  if (!doc) {
25339
25524
  throw new FirestoreError(Code.NOT_FOUND, `Can't use a DocumentSnapshot that doesn't exist for ` +
25340
25525
  `${methodName}().`);
@@ -25371,12 +25556,12 @@ function newQueryBoundFromDocument(query, databaseId, methodName, doc, before) {
25371
25556
  }
25372
25557
  }
25373
25558
  }
25374
- return new Bound(components, before);
25559
+ return new Bound(components, inclusive);
25375
25560
  }
25376
25561
  /**
25377
25562
  * Converts a list of field values to a `Bound` for the given query.
25378
25563
  */
25379
- function newQueryBoundFromFields(query, databaseId, dataReader, methodName, values, before) {
25564
+ function newQueryBoundFromFields(query, databaseId, dataReader, methodName, values, inclusive) {
25380
25565
  // Use explicit order by's because it has to match the query the user made
25381
25566
  const orderBy = query.explicitOrderBy;
25382
25567
  if (values.length > orderBy.length) {
@@ -25413,7 +25598,7 @@ function newQueryBoundFromFields(query, databaseId, dataReader, methodName, valu
25413
25598
  components.push(wrapped);
25414
25599
  }
25415
25600
  }
25416
- return new Bound(components, before);
25601
+ return new Bound(components, inclusive);
25417
25602
  }
25418
25603
  /**
25419
25604
  * Parses the given `documentIdValue` into a `ReferenceValue`, throwing