@firebase/firestore 3.4.4-canary.0482aa5b7 → 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 (85) hide show
  1. package/dist/firestore/src/local/indexeddb_index_manager.d.ts +10 -2
  2. package/dist/firestore/src/local/indexeddb_persistence.d.ts +4 -4
  3. package/dist/firestore/src/local/indexeddb_remote_document_cache.d.ts +2 -8
  4. package/dist/firestore/src/local/indexeddb_schema.d.ts +35 -7
  5. package/dist/firestore/src/local/local_serializer.d.ts +7 -2
  6. package/dist/firestore/src/local/memory_persistence.d.ts +3 -2
  7. package/dist/firestore/src/local/memory_remote_document_cache.d.ts +1 -3
  8. package/dist/firestore/src/local/persistence.d.ts +2 -2
  9. package/dist/firestore/src/local/remote_document_cache.d.ts +3 -0
  10. package/dist/firestore/src/local/simple_db.d.ts +1 -0
  11. package/dist/firestore/src/model/field_index.d.ts +2 -2
  12. package/dist/firestore/test/unit/local/persistence_test_helpers.d.ts +1 -0
  13. package/dist/firestore/test/unit/local/test_index_manager.d.ts +11 -0
  14. package/dist/firestore/test/unit/local/test_remote_document_cache.d.ts +2 -0
  15. package/dist/firestore/test/unit/local/test_remote_document_change_buffer.d.ts +1 -1
  16. package/dist/index.esm2017.js +2660 -2578
  17. package/dist/index.esm2017.js.map +1 -1
  18. package/dist/index.esm5.js +2928 -2807
  19. package/dist/index.esm5.js.map +1 -1
  20. package/dist/index.node.cjs.js +205 -81
  21. package/dist/index.node.cjs.js.map +1 -1
  22. package/dist/index.node.mjs +205 -81
  23. package/dist/index.node.mjs.map +1 -1
  24. package/dist/index.rn.js +2813 -2735
  25. package/dist/index.rn.js.map +1 -1
  26. package/dist/internal.d.ts +6 -4
  27. package/dist/lite/firestore/src/local/indexeddb_index_manager.d.ts +10 -2
  28. package/dist/lite/firestore/src/local/indexeddb_persistence.d.ts +4 -4
  29. package/dist/lite/firestore/src/local/indexeddb_remote_document_cache.d.ts +2 -8
  30. package/dist/lite/firestore/src/local/indexeddb_schema.d.ts +35 -7
  31. package/dist/lite/firestore/src/local/local_serializer.d.ts +7 -2
  32. package/dist/lite/firestore/src/local/memory_persistence.d.ts +3 -2
  33. package/dist/lite/firestore/src/local/memory_remote_document_cache.d.ts +1 -3
  34. package/dist/lite/firestore/src/local/persistence.d.ts +2 -2
  35. package/dist/lite/firestore/src/local/remote_document_cache.d.ts +3 -0
  36. package/dist/lite/firestore/src/local/simple_db.d.ts +1 -0
  37. package/dist/lite/firestore/src/model/field_index.d.ts +2 -2
  38. package/dist/lite/firestore/test/unit/local/persistence_test_helpers.d.ts +1 -0
  39. package/dist/lite/firestore/test/unit/local/test_index_manager.d.ts +11 -0
  40. package/dist/lite/firestore/test/unit/local/test_remote_document_cache.d.ts +2 -0
  41. package/dist/lite/firestore/test/unit/local/test_remote_document_change_buffer.d.ts +1 -1
  42. package/dist/lite/index.browser.esm2017.js +1112 -1112
  43. package/dist/lite/index.browser.esm2017.js.map +1 -1
  44. package/dist/lite/index.browser.esm5.js +14 -14
  45. package/dist/lite/index.browser.esm5.js.map +1 -1
  46. package/dist/lite/index.node.cjs.js +2 -2
  47. package/dist/lite/index.node.cjs.js.map +1 -1
  48. package/dist/lite/index.node.mjs +2 -2
  49. package/dist/lite/index.node.mjs.map +1 -1
  50. package/dist/lite/index.rn.esm2017.js +2 -2
  51. package/dist/lite/index.rn.esm2017.js.map +1 -1
  52. package/dist/lite/packages/firestore/dist/lite/index.browser.esm2017.d.ts +112 -112
  53. package/dist/lite/packages/firestore/src/local/indexeddb_index_manager.d.ts +10 -2
  54. package/dist/lite/packages/firestore/src/local/indexeddb_persistence.d.ts +4 -4
  55. package/dist/lite/packages/firestore/src/local/indexeddb_remote_document_cache.d.ts +2 -8
  56. package/dist/lite/packages/firestore/src/local/indexeddb_schema.d.ts +35 -7
  57. package/dist/lite/packages/firestore/src/local/local_serializer.d.ts +7 -2
  58. package/dist/lite/packages/firestore/src/local/memory_persistence.d.ts +3 -2
  59. package/dist/lite/packages/firestore/src/local/memory_remote_document_cache.d.ts +1 -3
  60. package/dist/lite/packages/firestore/src/local/persistence.d.ts +2 -2
  61. package/dist/lite/packages/firestore/src/local/remote_document_cache.d.ts +3 -0
  62. package/dist/lite/packages/firestore/src/local/simple_db.d.ts +1 -0
  63. package/dist/lite/packages/firestore/src/model/field_index.d.ts +2 -2
  64. package/dist/lite/packages/firestore/test/unit/local/persistence_test_helpers.d.ts +1 -0
  65. package/dist/lite/packages/firestore/test/unit/local/test_index_manager.d.ts +11 -0
  66. package/dist/lite/packages/firestore/test/unit/local/test_remote_document_cache.d.ts +2 -0
  67. package/dist/lite/packages/firestore/test/unit/local/test_remote_document_change_buffer.d.ts +1 -1
  68. package/dist/packages/firestore/dist/index.esm2017.d.ts +174 -174
  69. package/dist/packages/firestore/src/local/indexeddb_index_manager.d.ts +10 -2
  70. package/dist/packages/firestore/src/local/indexeddb_persistence.d.ts +4 -4
  71. package/dist/packages/firestore/src/local/indexeddb_remote_document_cache.d.ts +2 -8
  72. package/dist/packages/firestore/src/local/indexeddb_schema.d.ts +35 -7
  73. package/dist/packages/firestore/src/local/local_serializer.d.ts +7 -2
  74. package/dist/packages/firestore/src/local/memory_persistence.d.ts +3 -2
  75. package/dist/packages/firestore/src/local/memory_remote_document_cache.d.ts +1 -3
  76. package/dist/packages/firestore/src/local/persistence.d.ts +2 -2
  77. package/dist/packages/firestore/src/local/remote_document_cache.d.ts +3 -0
  78. package/dist/packages/firestore/src/local/simple_db.d.ts +1 -0
  79. package/dist/packages/firestore/src/model/field_index.d.ts +2 -2
  80. package/dist/packages/firestore/test/unit/local/persistence_test_helpers.d.ts +1 -0
  81. package/dist/packages/firestore/test/unit/local/test_index_manager.d.ts +11 -0
  82. package/dist/packages/firestore/test/unit/local/test_remote_document_cache.d.ts +2 -0
  83. package/dist/packages/firestore/test/unit/local/test_remote_document_change_buffer.d.ts +1 -1
  84. package/dist/private.d.ts +6 -4
  85. 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.0482aa5b7";
15
+ const version$1 = "3.4.4-canary.434d87ee2";
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.0482aa5b7";
68
+ const version = "9.6.6-canary.434d87ee2";
69
69
 
70
70
  /**
71
71
  * @license
@@ -1778,7 +1778,10 @@ DbNamedQuery.keyPath = 'name';
1778
1778
  /** An object representing the global configuration for a field index. */
1779
1779
  class DbIndexConfiguration {
1780
1780
  constructor(
1781
- /** The index id for this entry. */
1781
+ /**
1782
+ * The index id for this entry. Undefined for indexes that are not yet
1783
+ * persisted.
1784
+ */
1782
1785
  indexId,
1783
1786
  /** The collection group this index belongs to. */
1784
1787
  collectionGroup,
@@ -1792,6 +1795,16 @@ class DbIndexConfiguration {
1792
1795
  /** Name of the IndexedDb object store. */
1793
1796
  DbIndexConfiguration.store = 'indexConfiguration';
1794
1797
  DbIndexConfiguration.keyPath = 'indexId';
1798
+ /**
1799
+ * An index that provides access to the index configurations by collection
1800
+ * group.
1801
+ *
1802
+ * PORTING NOTE: iOS and Android maintain this index in-memory, but this is
1803
+ * not possible here as the Web client supports concurrent access to
1804
+ * persistence via multi-tab.
1805
+ */
1806
+ DbIndexConfiguration.collectionGroupIndex = 'collectionGroupIndex';
1807
+ DbIndexConfiguration.collectionGroupIndexPath = 'collectionGroup';
1795
1808
  /**
1796
1809
  * An object describing how up-to-date the index backfill is for each user and
1797
1810
  * index.
@@ -1833,8 +1846,18 @@ class DbIndexState {
1833
1846
  /** Name of the IndexedDb object store. */
1834
1847
  DbIndexState.store = 'indexState';
1835
1848
  DbIndexState.keyPath = ['indexId', 'uid'];
1849
+ /**
1850
+ * An index that provides access to documents in a collection sorted by last
1851
+ * update time. Used by the backfiller.
1852
+ *
1853
+ * PORTING NOTE: iOS and Android maintain this index in-memory, but this is
1854
+ * not possible here as the Web client supports concurrent access to
1855
+ * persistence via multi-tab.
1856
+ */
1857
+ DbIndexState.sequenceNumberIndex = 'sequenceNumberIndex';
1858
+ DbIndexState.sequenceNumberIndexPath = ['uid', 'sequenceNumber'];
1836
1859
  /** An object that stores the encoded entries for all documents and fields. */
1837
- class DbIndexEntries {
1860
+ class DbIndexEntry {
1838
1861
  constructor(
1839
1862
  /** The index id for this entry. */
1840
1863
  indexId,
@@ -1854,8 +1877,8 @@ class DbIndexEntries {
1854
1877
  }
1855
1878
  }
1856
1879
  /** Name of the IndexedDb object store. */
1857
- DbIndexEntries.store = 'indexEntries';
1858
- DbIndexEntries.keyPath = [
1880
+ DbIndexEntry.store = 'indexEntries';
1881
+ DbIndexEntry.keyPath = [
1859
1882
  'indexId',
1860
1883
  'uid',
1861
1884
  'arrayValue',
@@ -1885,18 +1908,24 @@ const V8_STORES = [...V6_STORES, DbCollectionParent.store];
1885
1908
  // V9 does not change the set of stores.
1886
1909
  // V10 does not change the set of stores.
1887
1910
  const V11_STORES = [...V8_STORES, DbBundle.store, DbNamedQuery.store];
1888
- [
1911
+ const V12_STORES = [
1889
1912
  ...V11_STORES,
1890
1913
  DbIndexConfiguration.store,
1891
1914
  DbIndexState.store,
1892
- DbIndexEntries.store
1915
+ DbIndexEntry.store
1893
1916
  ];
1894
- /**
1895
- * The list of all default IndexedDB stores used throughout the SDK. This is
1896
- * used when creating transactions so that access across all stores is done
1897
- * atomically.
1898
- */
1899
- const ALL_STORES = V11_STORES;
1917
+ /** Returns the object stores for the provided schema. */
1918
+ function getObjectStores(schemaVersion) {
1919
+ if (schemaVersion === 12) {
1920
+ return V12_STORES;
1921
+ }
1922
+ else if (schemaVersion === 11) {
1923
+ return V11_STORES;
1924
+ }
1925
+ else {
1926
+ fail();
1927
+ }
1928
+ }
1900
1929
 
1901
1930
  /**
1902
1931
  * @license
@@ -2193,6 +2222,15 @@ class SimpleDbTransaction {
2193
2222
  this.transaction.abort();
2194
2223
  }
2195
2224
  }
2225
+ maybeCommit() {
2226
+ // If the browser supports V3 IndexedDB, we invoke commit() explicitly to
2227
+ // speed up index DB processing if the event loop remains blocks.
2228
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2229
+ const maybeV3IndexedDb = this.transaction;
2230
+ if (!this.aborted && typeof maybeV3IndexedDb.commit === 'function') {
2231
+ maybeV3IndexedDb.commit();
2232
+ }
2233
+ }
2196
2234
  /**
2197
2235
  * Returns a SimpleDbStore<KeyType, ValueType> for the specified store. All
2198
2236
  * operations performed on the SimpleDbStore happen within the context of this
@@ -2389,6 +2427,10 @@ class SimpleDb {
2389
2427
  this.db = await this.ensureDb(action);
2390
2428
  const transaction = SimpleDbTransaction.open(this.db, action, readonly ? 'readonly' : 'readwrite', objectStores);
2391
2429
  const transactionFnResult = transactionFn(transaction)
2430
+ .next(result => {
2431
+ transaction.maybeCommit();
2432
+ return result;
2433
+ })
2392
2434
  .catch(error => {
2393
2435
  // Abort the transaction if there was an error.
2394
2436
  transaction.abort(error);
@@ -4421,12 +4463,12 @@ class FieldIndex {
4421
4463
  /** The collection ID this index applies to. */
4422
4464
  collectionGroup,
4423
4465
  /** The field segments for this index. */
4424
- segments,
4466
+ fields,
4425
4467
  /** Shows how up-to-date the index is for the current user. */
4426
4468
  indexState) {
4427
4469
  this.indexId = indexId;
4428
4470
  this.collectionGroup = collectionGroup;
4429
- this.segments = segments;
4471
+ this.fields = fields;
4430
4472
  this.indexState = indexState;
4431
4473
  }
4432
4474
  }
@@ -8687,6 +8729,19 @@ function fromBundleMetadata(metadata) {
8687
8729
  version: metadata.version,
8688
8730
  createTime: fromVersion(metadata.createTime)
8689
8731
  };
8732
+ }
8733
+ function toDbIndexConfiguration(index) {
8734
+ return new DbIndexConfiguration(index.indexId, index.collectionGroup, index.fields.map(s => [s.fieldPath.canonicalString(), s.kind]));
8735
+ }
8736
+ function fromDbIndexConfiguration(index, state) {
8737
+ const decodedState = state
8738
+ ? new IndexState(state.sequenceNumber, new IndexOffset(fromDbTimestamp(state.readTime), new DocumentKey(decodeResourcePath(state.documentKey)), state.largestBatchId))
8739
+ : IndexState.empty();
8740
+ const decodedSegments = index.fields.map(([fieldPath, kind]) => new IndexSegment(FieldPath$1.fromServerFormat(fieldPath), kind));
8741
+ return new FieldIndex(index.indexId, index.collectionGroup, decodedSegments, decodedState);
8742
+ }
8743
+ function toDbIndexState(indexId, user, sequenceNumber, offset) {
8744
+ return new DbIndexState(indexId, user.uid || '', sequenceNumber, toDbTimestamp(offset.readTime), encodeResourcePath(offset.documentKey.path), offset.largestBatchId);
8690
8745
  }
8691
8746
 
8692
8747
  /**
@@ -8859,17 +8914,22 @@ class MemoryCollectionParentIndex {
8859
8914
  */
8860
8915
  /**
8861
8916
  * A persisted implementation of IndexManager.
8917
+ *
8918
+ * PORTING NOTE: Unlike iOS and Android, the Web SDK does not memoize index
8919
+ * data as it supports multi-tab access.
8862
8920
  */
8863
8921
  class IndexedDbIndexManager {
8864
- constructor() {
8922
+ constructor(user) {
8923
+ this.user = user;
8865
8924
  /**
8866
8925
  * An in-memory copy of the index entries we've already written since the SDK
8867
8926
  * launched. Used to avoid re-writing the same entry repeatedly.
8868
8927
  *
8869
- * This is *NOT* a complete cache of what's in persistence and so can never be used to
8870
- * satisfy reads.
8928
+ * This is *NOT* a complete cache of what's in persistence and so can never be
8929
+ * used to satisfy reads.
8871
8930
  */
8872
8931
  this.collectionParentsCache = new MemoryCollectionParentIndex();
8932
+ this.uid = user.uid || '';
8873
8933
  }
8874
8934
  /**
8875
8935
  * Adds a new entry to the collection parent index.
@@ -8917,12 +8977,25 @@ class IndexedDbIndexManager {
8917
8977
  });
8918
8978
  }
8919
8979
  addFieldIndex(transaction, index) {
8920
- // TODO(indexing): Implement
8921
- return PersistencePromise.resolve();
8980
+ // TODO(indexing): Verify that the auto-incrementing index ID works in
8981
+ // Safari & Firefox.
8982
+ const indexes = indexConfigurationStore(transaction);
8983
+ const dbIndex = toDbIndexConfiguration(index);
8984
+ delete dbIndex.indexId; // `indexId` is auto-populated by IndexedDb
8985
+ return indexes.add(dbIndex).next();
8922
8986
  }
8923
8987
  deleteFieldIndex(transaction, index) {
8924
- // TODO(indexing): Implement
8925
- return PersistencePromise.resolve();
8988
+ const indexes = indexConfigurationStore(transaction);
8989
+ const states = indexStateStore(transaction);
8990
+ const entries = indexEntriesStore(transaction);
8991
+ return indexes
8992
+ .delete(index.indexId)
8993
+ .next(() => states.delete(IDBKeyRange.bound([index.indexId], [index.indexId + 1],
8994
+ /*lowerOpen=*/ false,
8995
+ /*upperOpen=*/ true)))
8996
+ .next(() => entries.delete(IDBKeyRange.bound([index.indexId], [index.indexId + 1],
8997
+ /*lowerOpen=*/ false,
8998
+ /*upperOpen=*/ true)));
8926
8999
  }
8927
9000
  getDocumentsMatchingTarget(transaction, fieldIndex, target) {
8928
9001
  // TODO(indexing): Implement
@@ -8933,21 +9006,55 @@ class IndexedDbIndexManager {
8933
9006
  return PersistencePromise.resolve(null);
8934
9007
  }
8935
9008
  getFieldIndexes(transaction, collectionGroup) {
8936
- // TODO(indexing): Implement
8937
- return PersistencePromise.resolve([]);
9009
+ const indexes = indexConfigurationStore(transaction);
9010
+ const states = indexStateStore(transaction);
9011
+ return (collectionGroup
9012
+ ? indexes.loadAll(DbIndexConfiguration.collectionGroupIndex, IDBKeyRange.bound(collectionGroup, collectionGroup))
9013
+ : indexes.loadAll()).next(indexConfigs => {
9014
+ const result = [];
9015
+ return PersistencePromise.forEach(indexConfigs, (indexConfig) => {
9016
+ return states
9017
+ .get([indexConfig.indexId, this.uid])
9018
+ .next(indexState => {
9019
+ result.push(fromDbIndexConfiguration(indexConfig, indexState));
9020
+ });
9021
+ }).next(() => result);
9022
+ });
8938
9023
  }
8939
9024
  getNextCollectionGroupToUpdate(transaction) {
8940
- // TODO(indexing): Implement
8941
- return PersistencePromise.resolve(null);
9025
+ return this.getFieldIndexes(transaction).next(indexes => {
9026
+ if (indexes.length === 0) {
9027
+ return null;
9028
+ }
9029
+ indexes.sort((l, r) => l.indexState.sequenceNumber - r.indexState.sequenceNumber);
9030
+ return indexes[0].collectionGroup;
9031
+ });
8942
9032
  }
8943
9033
  updateCollectionGroup(transaction, collectionGroup, offset) {
8944
- // TODO(indexing): Implement
8945
- return PersistencePromise.resolve();
9034
+ const indexes = indexConfigurationStore(transaction);
9035
+ const states = indexStateStore(transaction);
9036
+ return this.getNextSequenceNumber(transaction).next(nextSequenceNumber => indexes
9037
+ .loadAll(DbIndexConfiguration.collectionGroupIndex, IDBKeyRange.bound(collectionGroup, collectionGroup))
9038
+ .next(configs => PersistencePromise.forEach(configs, (config) => states.put(toDbIndexState(config.indexId, this.user, nextSequenceNumber, offset)))));
8946
9039
  }
8947
9040
  updateIndexEntries(transaction, documents) {
8948
9041
  // TODO(indexing): Implement
8949
9042
  return PersistencePromise.resolve();
8950
9043
  }
9044
+ getNextSequenceNumber(transaction) {
9045
+ let nextSequenceNumber = 1;
9046
+ const states = indexStateStore(transaction);
9047
+ return states
9048
+ .iterate({
9049
+ index: DbIndexState.sequenceNumberIndex,
9050
+ reverse: true,
9051
+ range: IDBKeyRange.upperBound([this.uid, Number.MAX_SAFE_INTEGER])
9052
+ }, (_, state, controller) => {
9053
+ controller.done();
9054
+ nextSequenceNumber = state.sequenceNumber + 1;
9055
+ })
9056
+ .next(() => nextSequenceNumber);
9057
+ }
8951
9058
  }
8952
9059
  /**
8953
9060
  * Helper to get a typed SimpleDbStore for the collectionParents
@@ -8955,6 +9062,24 @@ class IndexedDbIndexManager {
8955
9062
  */
8956
9063
  function collectionParentsStore(txn) {
8957
9064
  return getStore(txn, DbCollectionParent.store);
9065
+ }
9066
+ /**
9067
+ * Helper to get a typed SimpleDbStore for the index entry object store.
9068
+ */
9069
+ function indexEntriesStore(txn) {
9070
+ return getStore(txn, DbIndexEntry.store);
9071
+ }
9072
+ /**
9073
+ * Helper to get a typed SimpleDbStore for the index configuration object store.
9074
+ */
9075
+ function indexConfigurationStore(txn) {
9076
+ return getStore(txn, DbIndexConfiguration.store);
9077
+ }
9078
+ /**
9079
+ * Helper to get a typed SimpleDbStore for the index state object store.
9080
+ */
9081
+ function indexStateStore(txn) {
9082
+ return getStore(txn, DbIndexState.store);
8958
9083
  }
8959
9084
 
8960
9085
  /**
@@ -10424,12 +10549,10 @@ class RemoteDocumentChangeBuffer {
10424
10549
  * `newIndexedDbRemoteDocumentCache()`.
10425
10550
  */
10426
10551
  class IndexedDbRemoteDocumentCacheImpl {
10427
- /**
10428
- * @param serializer - The document serializer.
10429
- * @param indexManager - The query indexes that need to be maintained.
10430
- */
10431
- constructor(serializer, indexManager) {
10552
+ constructor(serializer) {
10432
10553
  this.serializer = serializer;
10554
+ }
10555
+ setIndexManager(indexManager) {
10433
10556
  this.indexManager = indexManager;
10434
10557
  }
10435
10558
  /**
@@ -10625,14 +10748,9 @@ class IndexedDbRemoteDocumentCacheImpl {
10625
10748
  return MutableDocument.newInvalidDocument(documentKey);
10626
10749
  }
10627
10750
  }
10628
- /**
10629
- * Creates a new IndexedDbRemoteDocumentCache.
10630
- *
10631
- * @param serializer - The document serializer.
10632
- * @param indexManager - The query indexes that need to be maintained.
10633
- */
10634
- function newIndexedDbRemoteDocumentCache(serializer, indexManager) {
10635
- return new IndexedDbRemoteDocumentCacheImpl(serializer, indexManager);
10751
+ /** Creates a new IndexedDbRemoteDocumentCache. */
10752
+ function newIndexedDbRemoteDocumentCache(serializer) {
10753
+ return new IndexedDbRemoteDocumentCacheImpl(serializer);
10636
10754
  }
10637
10755
  /**
10638
10756
  * Returns the set of documents that have changed since the specified read
@@ -11078,14 +11196,17 @@ function createNamedQueriesStore(db) {
11078
11196
  });
11079
11197
  }
11080
11198
  function createFieldIndex(db) {
11081
- db.createObjectStore(DbIndexConfiguration.store, {
11082
- keyPath: DbIndexConfiguration.keyPath
11199
+ const indexConfiguratioStore = db.createObjectStore(DbIndexConfiguration.store, {
11200
+ keyPath: DbIndexConfiguration.keyPath,
11201
+ autoIncrement: true
11083
11202
  });
11084
- db.createObjectStore(DbIndexState.store, {
11203
+ indexConfiguratioStore.createIndex(DbIndexConfiguration.collectionGroupIndex, DbIndexConfiguration.collectionGroupIndexPath, { unique: false });
11204
+ const indexStateStore = db.createObjectStore(DbIndexState.store, {
11085
11205
  keyPath: DbIndexState.keyPath
11086
11206
  });
11087
- db.createObjectStore(DbIndexEntries.store, {
11088
- keyPath: DbIndexEntries.keyPath
11207
+ indexStateStore.createIndex(DbIndexState.sequenceNumberIndex, DbIndexState.sequenceNumberIndexPath, { unique: false });
11208
+ db.createObjectStore(DbIndexEntry.store, {
11209
+ keyPath: DbIndexEntry.keyPath
11089
11210
  });
11090
11211
  }
11091
11212
 
@@ -11198,7 +11319,7 @@ class IndexedDbPersistence {
11198
11319
  * If set to true, forcefully obtains database access. Existing tabs will
11199
11320
  * no longer be able to access IndexedDB.
11200
11321
  */
11201
- forceOwningTab) {
11322
+ forceOwningTab, schemaVersion = SCHEMA_VERSION) {
11202
11323
  this.allowTabSynchronization = allowTabSynchronization;
11203
11324
  this.persistenceKey = persistenceKey;
11204
11325
  this.clientId = clientId;
@@ -11207,6 +11328,7 @@ class IndexedDbPersistence {
11207
11328
  this.document = document;
11208
11329
  this.sequenceNumberSyncer = sequenceNumberSyncer;
11209
11330
  this.forceOwningTab = forceOwningTab;
11331
+ this.schemaVersion = schemaVersion;
11210
11332
  this.listenSequence = null;
11211
11333
  this._started = false;
11212
11334
  this.isPrimary = false;
@@ -11228,10 +11350,9 @@ class IndexedDbPersistence {
11228
11350
  this.referenceDelegate = new IndexedDbLruDelegateImpl(this, lruParams);
11229
11351
  this.dbName = persistenceKey + MAIN_DATABASE;
11230
11352
  this.serializer = new LocalSerializer(serializer);
11231
- this.simpleDb = new SimpleDb(this.dbName, SCHEMA_VERSION, new SchemaConverter(this.serializer));
11353
+ this.simpleDb = new SimpleDb(this.dbName, this.schemaVersion, new SchemaConverter(this.serializer));
11232
11354
  this.targetCache = new IndexedDbTargetCache(this.referenceDelegate, this.serializer);
11233
- this.indexManager = new IndexedDbIndexManager();
11234
- this.remoteDocumentCache = newIndexedDbRemoteDocumentCache(this.serializer, this.indexManager);
11355
+ this.remoteDocumentCache = newIndexedDbRemoteDocumentCache(this.serializer);
11235
11356
  this.bundleCache = new IndexedDbBundleCache();
11236
11357
  if (this.window && this.window.localStorage) {
11237
11358
  this.webStorage = this.window.localStorage;
@@ -11567,8 +11688,8 @@ class IndexedDbPersistence {
11567
11688
  get started() {
11568
11689
  return this._started;
11569
11690
  }
11570
- getMutationQueue(user) {
11571
- return IndexedDbMutationQueue.forUser(user, this.serializer, this.indexManager, this.referenceDelegate);
11691
+ getMutationQueue(user, indexManager) {
11692
+ return IndexedDbMutationQueue.forUser(user, this.serializer, indexManager, this.referenceDelegate);
11572
11693
  }
11573
11694
  getTargetCache() {
11574
11695
  return this.targetCache;
@@ -11576,8 +11697,8 @@ class IndexedDbPersistence {
11576
11697
  getRemoteDocumentCache() {
11577
11698
  return this.remoteDocumentCache;
11578
11699
  }
11579
- getIndexManager() {
11580
- return this.indexManager;
11700
+ getIndexManager(user) {
11701
+ return new IndexedDbIndexManager(user);
11581
11702
  }
11582
11703
  getBundleCache() {
11583
11704
  return this.bundleCache;
@@ -11585,11 +11706,12 @@ class IndexedDbPersistence {
11585
11706
  runTransaction(action, mode, transactionOperation) {
11586
11707
  logDebug(LOG_TAG$d, 'Starting transaction:', action);
11587
11708
  const simpleDbMode = mode === 'readonly' ? 'readonly' : 'readwrite';
11709
+ const objectStores = getObjectStores(this.schemaVersion);
11588
11710
  let persistenceTransaction;
11589
11711
  // Do all transactions as readwrite against all object stores, since we
11590
11712
  // are the only reader/writer.
11591
11713
  return this.simpleDb
11592
- .runTransaction(action, simpleDbMode, ALL_STORES, simpleDbTxn => {
11714
+ .runTransaction(action, simpleDbMode, objectStores, simpleDbTxn => {
11593
11715
  persistenceTransaction = new IndexedDbTransaction(simpleDbTxn, this.listenSequence
11594
11716
  ? this.listenSequence.next()
11595
11717
  : ListenSequence.INVALID);
@@ -12087,11 +12209,18 @@ class LocalStoreImpl {
12087
12209
  * PORTING NOTE: This is only used for multi-tab synchronization.
12088
12210
  */
12089
12211
  this.lastDocumentChangeReadTime = SnapshotVersion.min();
12090
- this.mutationQueue = persistence.getMutationQueue(initialUser);
12091
12212
  this.remoteDocuments = persistence.getRemoteDocumentCache();
12092
12213
  this.targetCache = persistence.getTargetCache();
12093
- this.localDocuments = new LocalDocumentsView(this.remoteDocuments, this.mutationQueue, this.persistence.getIndexManager());
12094
12214
  this.bundleCache = persistence.getBundleCache();
12215
+ this.initializeUserComponents(initialUser);
12216
+ }
12217
+ initializeUserComponents(user) {
12218
+ // TODO(indexing): Add spec tests that test these components change after a
12219
+ // user change
12220
+ this.indexManager = this.persistence.getIndexManager(user);
12221
+ this.mutationQueue = this.persistence.getMutationQueue(user, this.indexManager);
12222
+ this.localDocuments = new LocalDocumentsView(this.remoteDocuments, this.mutationQueue, this.indexManager);
12223
+ this.remoteDocuments.setIndexManager(this.indexManager);
12095
12224
  this.queryEngine.setLocalDocumentsView(this.localDocuments);
12096
12225
  }
12097
12226
  collectGarbage(garbageCollector) {
@@ -12113,8 +12242,6 @@ persistence, queryEngine, initialUser, serializer) {
12113
12242
  // change.
12114
12243
  async function localStoreHandleUserChange(localStore, user) {
12115
12244
  const localStoreImpl = debugCast(localStore);
12116
- let newMutationQueue = localStoreImpl.mutationQueue;
12117
- let newLocalDocuments = localStoreImpl.localDocuments;
12118
12245
  const result = await localStoreImpl.persistence.runTransaction('Handle user change', 'readonly', txn => {
12119
12246
  // Swap out the mutation queue, grabbing the pending mutation batches
12120
12247
  // before and after.
@@ -12123,11 +12250,8 @@ async function localStoreHandleUserChange(localStore, user) {
12123
12250
  .getAllMutationBatches(txn)
12124
12251
  .next(promisedOldBatches => {
12125
12252
  oldBatches = promisedOldBatches;
12126
- newMutationQueue = localStoreImpl.persistence.getMutationQueue(user);
12127
- // Recreate our LocalDocumentsView using the new
12128
- // MutationQueue.
12129
- newLocalDocuments = new LocalDocumentsView(localStoreImpl.remoteDocuments, newMutationQueue, localStoreImpl.persistence.getIndexManager());
12130
- return newMutationQueue.getAllMutationBatches(txn);
12253
+ localStoreImpl.initializeUserComponents(user);
12254
+ return localStoreImpl.mutationQueue.getAllMutationBatches(txn);
12131
12255
  })
12132
12256
  .next(newBatches => {
12133
12257
  const removedBatchIds = [];
@@ -12148,7 +12272,7 @@ async function localStoreHandleUserChange(localStore, user) {
12148
12272
  }
12149
12273
  // Return the set of all (potentially) changed documents and the list
12150
12274
  // of mutation batch IDs that were affected by change.
12151
- return newLocalDocuments
12275
+ return localStoreImpl.localDocuments
12152
12276
  .getDocuments(txn, changedKeys)
12153
12277
  .next(affectedDocuments => {
12154
12278
  return {
@@ -12159,9 +12283,6 @@ async function localStoreHandleUserChange(localStore, user) {
12159
12283
  });
12160
12284
  });
12161
12285
  });
12162
- localStoreImpl.mutationQueue = newMutationQueue;
12163
- localStoreImpl.localDocuments = newLocalDocuments;
12164
- localStoreImpl.queryEngine.setLocalDocumentsView(localStoreImpl.localDocuments);
12165
12286
  return result;
12166
12287
  }
12167
12288
  /* Accepts locally generated Mutations and commit them to storage. */
@@ -13227,14 +13348,16 @@ class MemoryRemoteDocumentCacheImpl {
13227
13348
  * expected to just return 0 to avoid unnecessarily doing the work of
13228
13349
  * calculating the size.
13229
13350
  */
13230
- constructor(indexManager, sizer) {
13231
- this.indexManager = indexManager;
13351
+ constructor(sizer) {
13232
13352
  this.sizer = sizer;
13233
13353
  /** Underlying cache of documents and their read times. */
13234
13354
  this.docs = documentEntryMap();
13235
13355
  /** Size of all cached documents. */
13236
13356
  this.size = 0;
13237
13357
  }
13358
+ setIndexManager(indexManager) {
13359
+ this.indexManager = indexManager;
13360
+ }
13238
13361
  /**
13239
13362
  * Adds the supplied entry to the cache and updates the cache size as appropriate.
13240
13363
  *
@@ -13318,13 +13441,12 @@ class MemoryRemoteDocumentCacheImpl {
13318
13441
  /**
13319
13442
  * Creates a new memory-only RemoteDocumentCache.
13320
13443
  *
13321
- * @param indexManager - A class that manages collection group indices.
13322
13444
  * @param sizer - Used to assess the size of a document. For eager GC, this is
13323
13445
  * expected to just return 0 to avoid unnecessarily doing the work of
13324
13446
  * calculating the size.
13325
13447
  */
13326
- function newMemoryRemoteDocumentCache(indexManager, sizer) {
13327
- return new MemoryRemoteDocumentCacheImpl(indexManager, sizer);
13448
+ function newMemoryRemoteDocumentCache(sizer) {
13449
+ return new MemoryRemoteDocumentCacheImpl(sizer);
13328
13450
  }
13329
13451
  /**
13330
13452
  * Handles the details of adding and updating documents in the MemoryRemoteDocumentCache.
@@ -13525,7 +13647,7 @@ class MemoryPersistence {
13525
13647
  this.targetCache = new MemoryTargetCache(this);
13526
13648
  const sizer = (doc) => this.referenceDelegate.documentSize(doc);
13527
13649
  this.indexManager = new MemoryIndexManager();
13528
- this.remoteDocumentCache = newMemoryRemoteDocumentCache(this.indexManager, sizer);
13650
+ this.remoteDocumentCache = newMemoryRemoteDocumentCache(sizer);
13529
13651
  this.serializer = new LocalSerializer(serializer);
13530
13652
  this.bundleCache = new MemoryBundleCache(this.serializer);
13531
13653
  }
@@ -13546,13 +13668,15 @@ class MemoryPersistence {
13546
13668
  setNetworkEnabled() {
13547
13669
  // No op.
13548
13670
  }
13549
- getIndexManager() {
13671
+ getIndexManager(user) {
13672
+ // We do not currently support indices for memory persistence, so we can
13673
+ // return the same shared instance of the memory index manager.
13550
13674
  return this.indexManager;
13551
13675
  }
13552
- getMutationQueue(user) {
13676
+ getMutationQueue(user, indexManager) {
13553
13677
  let queue = this.mutationQueues[user.toKey()];
13554
13678
  if (!queue) {
13555
- queue = new MemoryMutationQueue(this.indexManager, this.referenceDelegate);
13679
+ queue = new MemoryMutationQueue(indexManager, this.referenceDelegate);
13556
13680
  this.mutationQueues[user.toKey()] = queue;
13557
13681
  }
13558
13682
  return queue;
@@ -20515,12 +20639,12 @@ async function syncEngineListen(syncEngine, query) {
20515
20639
  }
20516
20640
  else {
20517
20641
  const targetData = await localStoreAllocateTarget(syncEngineImpl.localStore, queryToTarget(query));
20518
- const status = syncEngineImpl.sharedClientState.addLocalQueryTarget(targetData.targetId);
20519
- targetId = targetData.targetId;
20520
- viewSnapshot = await initializeViewAndComputeSnapshot(syncEngineImpl, query, targetId, status === 'current');
20521
20642
  if (syncEngineImpl.isPrimaryClient) {
20522
20643
  remoteStoreListen(syncEngineImpl.remoteStore, targetData);
20523
20644
  }
20645
+ const status = syncEngineImpl.sharedClientState.addLocalQueryTarget(targetData.targetId);
20646
+ targetId = targetData.targetId;
20647
+ viewSnapshot = await initializeViewAndComputeSnapshot(syncEngineImpl, query, targetId, status === 'current');
20524
20648
  }
20525
20649
  return viewSnapshot;
20526
20650
  }