@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.
- package/dist/firestore/src/local/indexeddb_index_manager.d.ts +10 -2
- package/dist/firestore/src/local/indexeddb_persistence.d.ts +4 -4
- package/dist/firestore/src/local/indexeddb_remote_document_cache.d.ts +2 -8
- package/dist/firestore/src/local/indexeddb_schema.d.ts +35 -7
- package/dist/firestore/src/local/local_serializer.d.ts +7 -2
- package/dist/firestore/src/local/memory_persistence.d.ts +3 -2
- package/dist/firestore/src/local/memory_remote_document_cache.d.ts +1 -3
- package/dist/firestore/src/local/persistence.d.ts +2 -2
- package/dist/firestore/src/local/remote_document_cache.d.ts +3 -0
- package/dist/firestore/src/local/simple_db.d.ts +1 -0
- package/dist/firestore/src/model/field_index.d.ts +2 -2
- package/dist/firestore/test/unit/local/persistence_test_helpers.d.ts +1 -0
- package/dist/firestore/test/unit/local/test_index_manager.d.ts +11 -0
- package/dist/firestore/test/unit/local/test_remote_document_cache.d.ts +2 -0
- package/dist/firestore/test/unit/local/test_remote_document_change_buffer.d.ts +1 -1
- package/dist/index.esm2017.js +2660 -2578
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.esm5.js +2928 -2807
- package/dist/index.esm5.js.map +1 -1
- package/dist/index.node.cjs.js +205 -81
- package/dist/index.node.cjs.js.map +1 -1
- package/dist/index.node.mjs +205 -81
- package/dist/index.node.mjs.map +1 -1
- package/dist/index.rn.js +2813 -2735
- package/dist/index.rn.js.map +1 -1
- package/dist/internal.d.ts +6 -4
- package/dist/lite/firestore/src/local/indexeddb_index_manager.d.ts +10 -2
- package/dist/lite/firestore/src/local/indexeddb_persistence.d.ts +4 -4
- package/dist/lite/firestore/src/local/indexeddb_remote_document_cache.d.ts +2 -8
- package/dist/lite/firestore/src/local/indexeddb_schema.d.ts +35 -7
- package/dist/lite/firestore/src/local/local_serializer.d.ts +7 -2
- package/dist/lite/firestore/src/local/memory_persistence.d.ts +3 -2
- package/dist/lite/firestore/src/local/memory_remote_document_cache.d.ts +1 -3
- package/dist/lite/firestore/src/local/persistence.d.ts +2 -2
- package/dist/lite/firestore/src/local/remote_document_cache.d.ts +3 -0
- package/dist/lite/firestore/src/local/simple_db.d.ts +1 -0
- package/dist/lite/firestore/src/model/field_index.d.ts +2 -2
- package/dist/lite/firestore/test/unit/local/persistence_test_helpers.d.ts +1 -0
- package/dist/lite/firestore/test/unit/local/test_index_manager.d.ts +11 -0
- package/dist/lite/firestore/test/unit/local/test_remote_document_cache.d.ts +2 -0
- package/dist/lite/firestore/test/unit/local/test_remote_document_change_buffer.d.ts +1 -1
- package/dist/lite/index.browser.esm2017.js +1112 -1112
- package/dist/lite/index.browser.esm2017.js.map +1 -1
- package/dist/lite/index.browser.esm5.js +14 -14
- package/dist/lite/index.browser.esm5.js.map +1 -1
- package/dist/lite/index.node.cjs.js +2 -2
- package/dist/lite/index.node.cjs.js.map +1 -1
- package/dist/lite/index.node.mjs +2 -2
- package/dist/lite/index.node.mjs.map +1 -1
- package/dist/lite/index.rn.esm2017.js +2 -2
- package/dist/lite/index.rn.esm2017.js.map +1 -1
- package/dist/lite/packages/firestore/dist/lite/index.browser.esm2017.d.ts +112 -112
- package/dist/lite/packages/firestore/src/local/indexeddb_index_manager.d.ts +10 -2
- package/dist/lite/packages/firestore/src/local/indexeddb_persistence.d.ts +4 -4
- package/dist/lite/packages/firestore/src/local/indexeddb_remote_document_cache.d.ts +2 -8
- package/dist/lite/packages/firestore/src/local/indexeddb_schema.d.ts +35 -7
- package/dist/lite/packages/firestore/src/local/local_serializer.d.ts +7 -2
- package/dist/lite/packages/firestore/src/local/memory_persistence.d.ts +3 -2
- package/dist/lite/packages/firestore/src/local/memory_remote_document_cache.d.ts +1 -3
- package/dist/lite/packages/firestore/src/local/persistence.d.ts +2 -2
- package/dist/lite/packages/firestore/src/local/remote_document_cache.d.ts +3 -0
- package/dist/lite/packages/firestore/src/local/simple_db.d.ts +1 -0
- package/dist/lite/packages/firestore/src/model/field_index.d.ts +2 -2
- package/dist/lite/packages/firestore/test/unit/local/persistence_test_helpers.d.ts +1 -0
- package/dist/lite/packages/firestore/test/unit/local/test_index_manager.d.ts +11 -0
- package/dist/lite/packages/firestore/test/unit/local/test_remote_document_cache.d.ts +2 -0
- package/dist/lite/packages/firestore/test/unit/local/test_remote_document_change_buffer.d.ts +1 -1
- package/dist/packages/firestore/dist/index.esm2017.d.ts +174 -174
- package/dist/packages/firestore/src/local/indexeddb_index_manager.d.ts +10 -2
- package/dist/packages/firestore/src/local/indexeddb_persistence.d.ts +4 -4
- package/dist/packages/firestore/src/local/indexeddb_remote_document_cache.d.ts +2 -8
- package/dist/packages/firestore/src/local/indexeddb_schema.d.ts +35 -7
- package/dist/packages/firestore/src/local/local_serializer.d.ts +7 -2
- package/dist/packages/firestore/src/local/memory_persistence.d.ts +3 -2
- package/dist/packages/firestore/src/local/memory_remote_document_cache.d.ts +1 -3
- package/dist/packages/firestore/src/local/persistence.d.ts +2 -2
- package/dist/packages/firestore/src/local/remote_document_cache.d.ts +3 -0
- package/dist/packages/firestore/src/local/simple_db.d.ts +1 -0
- package/dist/packages/firestore/src/model/field_index.d.ts +2 -2
- package/dist/packages/firestore/test/unit/local/persistence_test_helpers.d.ts +1 -0
- package/dist/packages/firestore/test/unit/local/test_index_manager.d.ts +11 -0
- package/dist/packages/firestore/test/unit/local/test_remote_document_cache.d.ts +2 -0
- package/dist/packages/firestore/test/unit/local/test_remote_document_change_buffer.d.ts +1 -1
- package/dist/private.d.ts +6 -4
- package/package.json +9 -9
package/dist/index.node.mjs
CHANGED
|
@@ -8,7 +8,7 @@ import { credentials, loadPackageDefinition, Metadata } from '@grpc/grpc-js';
|
|
|
8
8
|
import { fromJSON } from '@grpc/proto-loader';
|
|
9
9
|
|
|
10
10
|
const name = "@firebase/firestore";
|
|
11
|
-
const version$1 = "3.4.4-canary.
|
|
11
|
+
const version$1 = "3.4.4-canary.434d87ee2";
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* @license
|
|
@@ -61,7 +61,7 @@ User.GOOGLE_CREDENTIALS = new User('google-credentials-uid');
|
|
|
61
61
|
User.FIRST_PARTY = new User('first-party-uid');
|
|
62
62
|
User.MOCK_USER = new User('mock-user');
|
|
63
63
|
|
|
64
|
-
const version = "9.6.
|
|
64
|
+
const version = "9.6.6-canary.434d87ee2";
|
|
65
65
|
|
|
66
66
|
/**
|
|
67
67
|
* @license
|
|
@@ -1774,7 +1774,10 @@ DbNamedQuery.keyPath = 'name';
|
|
|
1774
1774
|
/** An object representing the global configuration for a field index. */
|
|
1775
1775
|
class DbIndexConfiguration {
|
|
1776
1776
|
constructor(
|
|
1777
|
-
/**
|
|
1777
|
+
/**
|
|
1778
|
+
* The index id for this entry. Undefined for indexes that are not yet
|
|
1779
|
+
* persisted.
|
|
1780
|
+
*/
|
|
1778
1781
|
indexId,
|
|
1779
1782
|
/** The collection group this index belongs to. */
|
|
1780
1783
|
collectionGroup,
|
|
@@ -1788,6 +1791,16 @@ class DbIndexConfiguration {
|
|
|
1788
1791
|
/** Name of the IndexedDb object store. */
|
|
1789
1792
|
DbIndexConfiguration.store = 'indexConfiguration';
|
|
1790
1793
|
DbIndexConfiguration.keyPath = 'indexId';
|
|
1794
|
+
/**
|
|
1795
|
+
* An index that provides access to the index configurations by collection
|
|
1796
|
+
* group.
|
|
1797
|
+
*
|
|
1798
|
+
* PORTING NOTE: iOS and Android maintain this index in-memory, but this is
|
|
1799
|
+
* not possible here as the Web client supports concurrent access to
|
|
1800
|
+
* persistence via multi-tab.
|
|
1801
|
+
*/
|
|
1802
|
+
DbIndexConfiguration.collectionGroupIndex = 'collectionGroupIndex';
|
|
1803
|
+
DbIndexConfiguration.collectionGroupIndexPath = 'collectionGroup';
|
|
1791
1804
|
/**
|
|
1792
1805
|
* An object describing how up-to-date the index backfill is for each user and
|
|
1793
1806
|
* index.
|
|
@@ -1829,8 +1842,18 @@ class DbIndexState {
|
|
|
1829
1842
|
/** Name of the IndexedDb object store. */
|
|
1830
1843
|
DbIndexState.store = 'indexState';
|
|
1831
1844
|
DbIndexState.keyPath = ['indexId', 'uid'];
|
|
1845
|
+
/**
|
|
1846
|
+
* An index that provides access to documents in a collection sorted by last
|
|
1847
|
+
* update time. Used by the backfiller.
|
|
1848
|
+
*
|
|
1849
|
+
* PORTING NOTE: iOS and Android maintain this index in-memory, but this is
|
|
1850
|
+
* not possible here as the Web client supports concurrent access to
|
|
1851
|
+
* persistence via multi-tab.
|
|
1852
|
+
*/
|
|
1853
|
+
DbIndexState.sequenceNumberIndex = 'sequenceNumberIndex';
|
|
1854
|
+
DbIndexState.sequenceNumberIndexPath = ['uid', 'sequenceNumber'];
|
|
1832
1855
|
/** An object that stores the encoded entries for all documents and fields. */
|
|
1833
|
-
class
|
|
1856
|
+
class DbIndexEntry {
|
|
1834
1857
|
constructor(
|
|
1835
1858
|
/** The index id for this entry. */
|
|
1836
1859
|
indexId,
|
|
@@ -1850,8 +1873,8 @@ class DbIndexEntries {
|
|
|
1850
1873
|
}
|
|
1851
1874
|
}
|
|
1852
1875
|
/** Name of the IndexedDb object store. */
|
|
1853
|
-
|
|
1854
|
-
|
|
1876
|
+
DbIndexEntry.store = 'indexEntries';
|
|
1877
|
+
DbIndexEntry.keyPath = [
|
|
1855
1878
|
'indexId',
|
|
1856
1879
|
'uid',
|
|
1857
1880
|
'arrayValue',
|
|
@@ -1881,18 +1904,24 @@ const V8_STORES = [...V6_STORES, DbCollectionParent.store];
|
|
|
1881
1904
|
// V9 does not change the set of stores.
|
|
1882
1905
|
// V10 does not change the set of stores.
|
|
1883
1906
|
const V11_STORES = [...V8_STORES, DbBundle.store, DbNamedQuery.store];
|
|
1884
|
-
[
|
|
1907
|
+
const V12_STORES = [
|
|
1885
1908
|
...V11_STORES,
|
|
1886
1909
|
DbIndexConfiguration.store,
|
|
1887
1910
|
DbIndexState.store,
|
|
1888
|
-
|
|
1911
|
+
DbIndexEntry.store
|
|
1889
1912
|
];
|
|
1890
|
-
/**
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1913
|
+
/** Returns the object stores for the provided schema. */
|
|
1914
|
+
function getObjectStores(schemaVersion) {
|
|
1915
|
+
if (schemaVersion === 12) {
|
|
1916
|
+
return V12_STORES;
|
|
1917
|
+
}
|
|
1918
|
+
else if (schemaVersion === 11) {
|
|
1919
|
+
return V11_STORES;
|
|
1920
|
+
}
|
|
1921
|
+
else {
|
|
1922
|
+
fail();
|
|
1923
|
+
}
|
|
1924
|
+
}
|
|
1896
1925
|
|
|
1897
1926
|
/**
|
|
1898
1927
|
* @license
|
|
@@ -2189,6 +2218,15 @@ class SimpleDbTransaction {
|
|
|
2189
2218
|
this.transaction.abort();
|
|
2190
2219
|
}
|
|
2191
2220
|
}
|
|
2221
|
+
maybeCommit() {
|
|
2222
|
+
// If the browser supports V3 IndexedDB, we invoke commit() explicitly to
|
|
2223
|
+
// speed up index DB processing if the event loop remains blocks.
|
|
2224
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2225
|
+
const maybeV3IndexedDb = this.transaction;
|
|
2226
|
+
if (!this.aborted && typeof maybeV3IndexedDb.commit === 'function') {
|
|
2227
|
+
maybeV3IndexedDb.commit();
|
|
2228
|
+
}
|
|
2229
|
+
}
|
|
2192
2230
|
/**
|
|
2193
2231
|
* Returns a SimpleDbStore<KeyType, ValueType> for the specified store. All
|
|
2194
2232
|
* operations performed on the SimpleDbStore happen within the context of this
|
|
@@ -2385,6 +2423,10 @@ class SimpleDb {
|
|
|
2385
2423
|
this.db = await this.ensureDb(action);
|
|
2386
2424
|
const transaction = SimpleDbTransaction.open(this.db, action, readonly ? 'readonly' : 'readwrite', objectStores);
|
|
2387
2425
|
const transactionFnResult = transactionFn(transaction)
|
|
2426
|
+
.next(result => {
|
|
2427
|
+
transaction.maybeCommit();
|
|
2428
|
+
return result;
|
|
2429
|
+
})
|
|
2388
2430
|
.catch(error => {
|
|
2389
2431
|
// Abort the transaction if there was an error.
|
|
2390
2432
|
transaction.abort(error);
|
|
@@ -4417,12 +4459,12 @@ class FieldIndex {
|
|
|
4417
4459
|
/** The collection ID this index applies to. */
|
|
4418
4460
|
collectionGroup,
|
|
4419
4461
|
/** The field segments for this index. */
|
|
4420
|
-
|
|
4462
|
+
fields,
|
|
4421
4463
|
/** Shows how up-to-date the index is for the current user. */
|
|
4422
4464
|
indexState) {
|
|
4423
4465
|
this.indexId = indexId;
|
|
4424
4466
|
this.collectionGroup = collectionGroup;
|
|
4425
|
-
this.
|
|
4467
|
+
this.fields = fields;
|
|
4426
4468
|
this.indexState = indexState;
|
|
4427
4469
|
}
|
|
4428
4470
|
}
|
|
@@ -8683,6 +8725,19 @@ function fromBundleMetadata(metadata) {
|
|
|
8683
8725
|
version: metadata.version,
|
|
8684
8726
|
createTime: fromVersion(metadata.createTime)
|
|
8685
8727
|
};
|
|
8728
|
+
}
|
|
8729
|
+
function toDbIndexConfiguration(index) {
|
|
8730
|
+
return new DbIndexConfiguration(index.indexId, index.collectionGroup, index.fields.map(s => [s.fieldPath.canonicalString(), s.kind]));
|
|
8731
|
+
}
|
|
8732
|
+
function fromDbIndexConfiguration(index, state) {
|
|
8733
|
+
const decodedState = state
|
|
8734
|
+
? new IndexState(state.sequenceNumber, new IndexOffset(fromDbTimestamp(state.readTime), new DocumentKey(decodeResourcePath(state.documentKey)), state.largestBatchId))
|
|
8735
|
+
: IndexState.empty();
|
|
8736
|
+
const decodedSegments = index.fields.map(([fieldPath, kind]) => new IndexSegment(FieldPath$1.fromServerFormat(fieldPath), kind));
|
|
8737
|
+
return new FieldIndex(index.indexId, index.collectionGroup, decodedSegments, decodedState);
|
|
8738
|
+
}
|
|
8739
|
+
function toDbIndexState(indexId, user, sequenceNumber, offset) {
|
|
8740
|
+
return new DbIndexState(indexId, user.uid || '', sequenceNumber, toDbTimestamp(offset.readTime), encodeResourcePath(offset.documentKey.path), offset.largestBatchId);
|
|
8686
8741
|
}
|
|
8687
8742
|
|
|
8688
8743
|
/**
|
|
@@ -8855,17 +8910,22 @@ class MemoryCollectionParentIndex {
|
|
|
8855
8910
|
*/
|
|
8856
8911
|
/**
|
|
8857
8912
|
* A persisted implementation of IndexManager.
|
|
8913
|
+
*
|
|
8914
|
+
* PORTING NOTE: Unlike iOS and Android, the Web SDK does not memoize index
|
|
8915
|
+
* data as it supports multi-tab access.
|
|
8858
8916
|
*/
|
|
8859
8917
|
class IndexedDbIndexManager {
|
|
8860
|
-
constructor() {
|
|
8918
|
+
constructor(user) {
|
|
8919
|
+
this.user = user;
|
|
8861
8920
|
/**
|
|
8862
8921
|
* An in-memory copy of the index entries we've already written since the SDK
|
|
8863
8922
|
* launched. Used to avoid re-writing the same entry repeatedly.
|
|
8864
8923
|
*
|
|
8865
|
-
* This is *NOT* a complete cache of what's in persistence and so can never be
|
|
8866
|
-
* satisfy reads.
|
|
8924
|
+
* This is *NOT* a complete cache of what's in persistence and so can never be
|
|
8925
|
+
* used to satisfy reads.
|
|
8867
8926
|
*/
|
|
8868
8927
|
this.collectionParentsCache = new MemoryCollectionParentIndex();
|
|
8928
|
+
this.uid = user.uid || '';
|
|
8869
8929
|
}
|
|
8870
8930
|
/**
|
|
8871
8931
|
* Adds a new entry to the collection parent index.
|
|
@@ -8913,12 +8973,25 @@ class IndexedDbIndexManager {
|
|
|
8913
8973
|
});
|
|
8914
8974
|
}
|
|
8915
8975
|
addFieldIndex(transaction, index) {
|
|
8916
|
-
// TODO(indexing):
|
|
8917
|
-
|
|
8976
|
+
// TODO(indexing): Verify that the auto-incrementing index ID works in
|
|
8977
|
+
// Safari & Firefox.
|
|
8978
|
+
const indexes = indexConfigurationStore(transaction);
|
|
8979
|
+
const dbIndex = toDbIndexConfiguration(index);
|
|
8980
|
+
delete dbIndex.indexId; // `indexId` is auto-populated by IndexedDb
|
|
8981
|
+
return indexes.add(dbIndex).next();
|
|
8918
8982
|
}
|
|
8919
8983
|
deleteFieldIndex(transaction, index) {
|
|
8920
|
-
|
|
8921
|
-
|
|
8984
|
+
const indexes = indexConfigurationStore(transaction);
|
|
8985
|
+
const states = indexStateStore(transaction);
|
|
8986
|
+
const entries = indexEntriesStore(transaction);
|
|
8987
|
+
return indexes
|
|
8988
|
+
.delete(index.indexId)
|
|
8989
|
+
.next(() => states.delete(IDBKeyRange.bound([index.indexId], [index.indexId + 1],
|
|
8990
|
+
/*lowerOpen=*/ false,
|
|
8991
|
+
/*upperOpen=*/ true)))
|
|
8992
|
+
.next(() => entries.delete(IDBKeyRange.bound([index.indexId], [index.indexId + 1],
|
|
8993
|
+
/*lowerOpen=*/ false,
|
|
8994
|
+
/*upperOpen=*/ true)));
|
|
8922
8995
|
}
|
|
8923
8996
|
getDocumentsMatchingTarget(transaction, fieldIndex, target) {
|
|
8924
8997
|
// TODO(indexing): Implement
|
|
@@ -8929,21 +9002,55 @@ class IndexedDbIndexManager {
|
|
|
8929
9002
|
return PersistencePromise.resolve(null);
|
|
8930
9003
|
}
|
|
8931
9004
|
getFieldIndexes(transaction, collectionGroup) {
|
|
8932
|
-
|
|
8933
|
-
|
|
9005
|
+
const indexes = indexConfigurationStore(transaction);
|
|
9006
|
+
const states = indexStateStore(transaction);
|
|
9007
|
+
return (collectionGroup
|
|
9008
|
+
? indexes.loadAll(DbIndexConfiguration.collectionGroupIndex, IDBKeyRange.bound(collectionGroup, collectionGroup))
|
|
9009
|
+
: indexes.loadAll()).next(indexConfigs => {
|
|
9010
|
+
const result = [];
|
|
9011
|
+
return PersistencePromise.forEach(indexConfigs, (indexConfig) => {
|
|
9012
|
+
return states
|
|
9013
|
+
.get([indexConfig.indexId, this.uid])
|
|
9014
|
+
.next(indexState => {
|
|
9015
|
+
result.push(fromDbIndexConfiguration(indexConfig, indexState));
|
|
9016
|
+
});
|
|
9017
|
+
}).next(() => result);
|
|
9018
|
+
});
|
|
8934
9019
|
}
|
|
8935
9020
|
getNextCollectionGroupToUpdate(transaction) {
|
|
8936
|
-
|
|
8937
|
-
|
|
9021
|
+
return this.getFieldIndexes(transaction).next(indexes => {
|
|
9022
|
+
if (indexes.length === 0) {
|
|
9023
|
+
return null;
|
|
9024
|
+
}
|
|
9025
|
+
indexes.sort((l, r) => l.indexState.sequenceNumber - r.indexState.sequenceNumber);
|
|
9026
|
+
return indexes[0].collectionGroup;
|
|
9027
|
+
});
|
|
8938
9028
|
}
|
|
8939
9029
|
updateCollectionGroup(transaction, collectionGroup, offset) {
|
|
8940
|
-
|
|
8941
|
-
|
|
9030
|
+
const indexes = indexConfigurationStore(transaction);
|
|
9031
|
+
const states = indexStateStore(transaction);
|
|
9032
|
+
return this.getNextSequenceNumber(transaction).next(nextSequenceNumber => indexes
|
|
9033
|
+
.loadAll(DbIndexConfiguration.collectionGroupIndex, IDBKeyRange.bound(collectionGroup, collectionGroup))
|
|
9034
|
+
.next(configs => PersistencePromise.forEach(configs, (config) => states.put(toDbIndexState(config.indexId, this.user, nextSequenceNumber, offset)))));
|
|
8942
9035
|
}
|
|
8943
9036
|
updateIndexEntries(transaction, documents) {
|
|
8944
9037
|
// TODO(indexing): Implement
|
|
8945
9038
|
return PersistencePromise.resolve();
|
|
8946
9039
|
}
|
|
9040
|
+
getNextSequenceNumber(transaction) {
|
|
9041
|
+
let nextSequenceNumber = 1;
|
|
9042
|
+
const states = indexStateStore(transaction);
|
|
9043
|
+
return states
|
|
9044
|
+
.iterate({
|
|
9045
|
+
index: DbIndexState.sequenceNumberIndex,
|
|
9046
|
+
reverse: true,
|
|
9047
|
+
range: IDBKeyRange.upperBound([this.uid, Number.MAX_SAFE_INTEGER])
|
|
9048
|
+
}, (_, state, controller) => {
|
|
9049
|
+
controller.done();
|
|
9050
|
+
nextSequenceNumber = state.sequenceNumber + 1;
|
|
9051
|
+
})
|
|
9052
|
+
.next(() => nextSequenceNumber);
|
|
9053
|
+
}
|
|
8947
9054
|
}
|
|
8948
9055
|
/**
|
|
8949
9056
|
* Helper to get a typed SimpleDbStore for the collectionParents
|
|
@@ -8951,6 +9058,24 @@ class IndexedDbIndexManager {
|
|
|
8951
9058
|
*/
|
|
8952
9059
|
function collectionParentsStore(txn) {
|
|
8953
9060
|
return getStore(txn, DbCollectionParent.store);
|
|
9061
|
+
}
|
|
9062
|
+
/**
|
|
9063
|
+
* Helper to get a typed SimpleDbStore for the index entry object store.
|
|
9064
|
+
*/
|
|
9065
|
+
function indexEntriesStore(txn) {
|
|
9066
|
+
return getStore(txn, DbIndexEntry.store);
|
|
9067
|
+
}
|
|
9068
|
+
/**
|
|
9069
|
+
* Helper to get a typed SimpleDbStore for the index configuration object store.
|
|
9070
|
+
*/
|
|
9071
|
+
function indexConfigurationStore(txn) {
|
|
9072
|
+
return getStore(txn, DbIndexConfiguration.store);
|
|
9073
|
+
}
|
|
9074
|
+
/**
|
|
9075
|
+
* Helper to get a typed SimpleDbStore for the index state object store.
|
|
9076
|
+
*/
|
|
9077
|
+
function indexStateStore(txn) {
|
|
9078
|
+
return getStore(txn, DbIndexState.store);
|
|
8954
9079
|
}
|
|
8955
9080
|
|
|
8956
9081
|
/**
|
|
@@ -10420,12 +10545,10 @@ class RemoteDocumentChangeBuffer {
|
|
|
10420
10545
|
* `newIndexedDbRemoteDocumentCache()`.
|
|
10421
10546
|
*/
|
|
10422
10547
|
class IndexedDbRemoteDocumentCacheImpl {
|
|
10423
|
-
|
|
10424
|
-
* @param serializer - The document serializer.
|
|
10425
|
-
* @param indexManager - The query indexes that need to be maintained.
|
|
10426
|
-
*/
|
|
10427
|
-
constructor(serializer, indexManager) {
|
|
10548
|
+
constructor(serializer) {
|
|
10428
10549
|
this.serializer = serializer;
|
|
10550
|
+
}
|
|
10551
|
+
setIndexManager(indexManager) {
|
|
10429
10552
|
this.indexManager = indexManager;
|
|
10430
10553
|
}
|
|
10431
10554
|
/**
|
|
@@ -10621,14 +10744,9 @@ class IndexedDbRemoteDocumentCacheImpl {
|
|
|
10621
10744
|
return MutableDocument.newInvalidDocument(documentKey);
|
|
10622
10745
|
}
|
|
10623
10746
|
}
|
|
10624
|
-
/**
|
|
10625
|
-
|
|
10626
|
-
|
|
10627
|
-
* @param serializer - The document serializer.
|
|
10628
|
-
* @param indexManager - The query indexes that need to be maintained.
|
|
10629
|
-
*/
|
|
10630
|
-
function newIndexedDbRemoteDocumentCache(serializer, indexManager) {
|
|
10631
|
-
return new IndexedDbRemoteDocumentCacheImpl(serializer, indexManager);
|
|
10747
|
+
/** Creates a new IndexedDbRemoteDocumentCache. */
|
|
10748
|
+
function newIndexedDbRemoteDocumentCache(serializer) {
|
|
10749
|
+
return new IndexedDbRemoteDocumentCacheImpl(serializer);
|
|
10632
10750
|
}
|
|
10633
10751
|
/**
|
|
10634
10752
|
* Returns the set of documents that have changed since the specified read
|
|
@@ -11074,14 +11192,17 @@ function createNamedQueriesStore(db) {
|
|
|
11074
11192
|
});
|
|
11075
11193
|
}
|
|
11076
11194
|
function createFieldIndex(db) {
|
|
11077
|
-
db.createObjectStore(DbIndexConfiguration.store, {
|
|
11078
|
-
keyPath: DbIndexConfiguration.keyPath
|
|
11195
|
+
const indexConfiguratioStore = db.createObjectStore(DbIndexConfiguration.store, {
|
|
11196
|
+
keyPath: DbIndexConfiguration.keyPath,
|
|
11197
|
+
autoIncrement: true
|
|
11079
11198
|
});
|
|
11080
|
-
|
|
11199
|
+
indexConfiguratioStore.createIndex(DbIndexConfiguration.collectionGroupIndex, DbIndexConfiguration.collectionGroupIndexPath, { unique: false });
|
|
11200
|
+
const indexStateStore = db.createObjectStore(DbIndexState.store, {
|
|
11081
11201
|
keyPath: DbIndexState.keyPath
|
|
11082
11202
|
});
|
|
11083
|
-
|
|
11084
|
-
|
|
11203
|
+
indexStateStore.createIndex(DbIndexState.sequenceNumberIndex, DbIndexState.sequenceNumberIndexPath, { unique: false });
|
|
11204
|
+
db.createObjectStore(DbIndexEntry.store, {
|
|
11205
|
+
keyPath: DbIndexEntry.keyPath
|
|
11085
11206
|
});
|
|
11086
11207
|
}
|
|
11087
11208
|
|
|
@@ -11194,7 +11315,7 @@ class IndexedDbPersistence {
|
|
|
11194
11315
|
* If set to true, forcefully obtains database access. Existing tabs will
|
|
11195
11316
|
* no longer be able to access IndexedDB.
|
|
11196
11317
|
*/
|
|
11197
|
-
forceOwningTab) {
|
|
11318
|
+
forceOwningTab, schemaVersion = SCHEMA_VERSION) {
|
|
11198
11319
|
this.allowTabSynchronization = allowTabSynchronization;
|
|
11199
11320
|
this.persistenceKey = persistenceKey;
|
|
11200
11321
|
this.clientId = clientId;
|
|
@@ -11203,6 +11324,7 @@ class IndexedDbPersistence {
|
|
|
11203
11324
|
this.document = document;
|
|
11204
11325
|
this.sequenceNumberSyncer = sequenceNumberSyncer;
|
|
11205
11326
|
this.forceOwningTab = forceOwningTab;
|
|
11327
|
+
this.schemaVersion = schemaVersion;
|
|
11206
11328
|
this.listenSequence = null;
|
|
11207
11329
|
this._started = false;
|
|
11208
11330
|
this.isPrimary = false;
|
|
@@ -11224,10 +11346,9 @@ class IndexedDbPersistence {
|
|
|
11224
11346
|
this.referenceDelegate = new IndexedDbLruDelegateImpl(this, lruParams);
|
|
11225
11347
|
this.dbName = persistenceKey + MAIN_DATABASE;
|
|
11226
11348
|
this.serializer = new LocalSerializer(serializer);
|
|
11227
|
-
this.simpleDb = new SimpleDb(this.dbName,
|
|
11349
|
+
this.simpleDb = new SimpleDb(this.dbName, this.schemaVersion, new SchemaConverter(this.serializer));
|
|
11228
11350
|
this.targetCache = new IndexedDbTargetCache(this.referenceDelegate, this.serializer);
|
|
11229
|
-
this.
|
|
11230
|
-
this.remoteDocumentCache = newIndexedDbRemoteDocumentCache(this.serializer, this.indexManager);
|
|
11351
|
+
this.remoteDocumentCache = newIndexedDbRemoteDocumentCache(this.serializer);
|
|
11231
11352
|
this.bundleCache = new IndexedDbBundleCache();
|
|
11232
11353
|
if (this.window && this.window.localStorage) {
|
|
11233
11354
|
this.webStorage = this.window.localStorage;
|
|
@@ -11563,8 +11684,8 @@ class IndexedDbPersistence {
|
|
|
11563
11684
|
get started() {
|
|
11564
11685
|
return this._started;
|
|
11565
11686
|
}
|
|
11566
|
-
getMutationQueue(user) {
|
|
11567
|
-
return IndexedDbMutationQueue.forUser(user, this.serializer,
|
|
11687
|
+
getMutationQueue(user, indexManager) {
|
|
11688
|
+
return IndexedDbMutationQueue.forUser(user, this.serializer, indexManager, this.referenceDelegate);
|
|
11568
11689
|
}
|
|
11569
11690
|
getTargetCache() {
|
|
11570
11691
|
return this.targetCache;
|
|
@@ -11572,8 +11693,8 @@ class IndexedDbPersistence {
|
|
|
11572
11693
|
getRemoteDocumentCache() {
|
|
11573
11694
|
return this.remoteDocumentCache;
|
|
11574
11695
|
}
|
|
11575
|
-
getIndexManager() {
|
|
11576
|
-
return
|
|
11696
|
+
getIndexManager(user) {
|
|
11697
|
+
return new IndexedDbIndexManager(user);
|
|
11577
11698
|
}
|
|
11578
11699
|
getBundleCache() {
|
|
11579
11700
|
return this.bundleCache;
|
|
@@ -11581,11 +11702,12 @@ class IndexedDbPersistence {
|
|
|
11581
11702
|
runTransaction(action, mode, transactionOperation) {
|
|
11582
11703
|
logDebug(LOG_TAG$d, 'Starting transaction:', action);
|
|
11583
11704
|
const simpleDbMode = mode === 'readonly' ? 'readonly' : 'readwrite';
|
|
11705
|
+
const objectStores = getObjectStores(this.schemaVersion);
|
|
11584
11706
|
let persistenceTransaction;
|
|
11585
11707
|
// Do all transactions as readwrite against all object stores, since we
|
|
11586
11708
|
// are the only reader/writer.
|
|
11587
11709
|
return this.simpleDb
|
|
11588
|
-
.runTransaction(action, simpleDbMode,
|
|
11710
|
+
.runTransaction(action, simpleDbMode, objectStores, simpleDbTxn => {
|
|
11589
11711
|
persistenceTransaction = new IndexedDbTransaction(simpleDbTxn, this.listenSequence
|
|
11590
11712
|
? this.listenSequence.next()
|
|
11591
11713
|
: ListenSequence.INVALID);
|
|
@@ -12083,11 +12205,18 @@ class LocalStoreImpl {
|
|
|
12083
12205
|
* PORTING NOTE: This is only used for multi-tab synchronization.
|
|
12084
12206
|
*/
|
|
12085
12207
|
this.lastDocumentChangeReadTime = SnapshotVersion.min();
|
|
12086
|
-
this.mutationQueue = persistence.getMutationQueue(initialUser);
|
|
12087
12208
|
this.remoteDocuments = persistence.getRemoteDocumentCache();
|
|
12088
12209
|
this.targetCache = persistence.getTargetCache();
|
|
12089
|
-
this.localDocuments = new LocalDocumentsView(this.remoteDocuments, this.mutationQueue, this.persistence.getIndexManager());
|
|
12090
12210
|
this.bundleCache = persistence.getBundleCache();
|
|
12211
|
+
this.initializeUserComponents(initialUser);
|
|
12212
|
+
}
|
|
12213
|
+
initializeUserComponents(user) {
|
|
12214
|
+
// TODO(indexing): Add spec tests that test these components change after a
|
|
12215
|
+
// user change
|
|
12216
|
+
this.indexManager = this.persistence.getIndexManager(user);
|
|
12217
|
+
this.mutationQueue = this.persistence.getMutationQueue(user, this.indexManager);
|
|
12218
|
+
this.localDocuments = new LocalDocumentsView(this.remoteDocuments, this.mutationQueue, this.indexManager);
|
|
12219
|
+
this.remoteDocuments.setIndexManager(this.indexManager);
|
|
12091
12220
|
this.queryEngine.setLocalDocumentsView(this.localDocuments);
|
|
12092
12221
|
}
|
|
12093
12222
|
collectGarbage(garbageCollector) {
|
|
@@ -12109,8 +12238,6 @@ persistence, queryEngine, initialUser, serializer) {
|
|
|
12109
12238
|
// change.
|
|
12110
12239
|
async function localStoreHandleUserChange(localStore, user) {
|
|
12111
12240
|
const localStoreImpl = debugCast(localStore);
|
|
12112
|
-
let newMutationQueue = localStoreImpl.mutationQueue;
|
|
12113
|
-
let newLocalDocuments = localStoreImpl.localDocuments;
|
|
12114
12241
|
const result = await localStoreImpl.persistence.runTransaction('Handle user change', 'readonly', txn => {
|
|
12115
12242
|
// Swap out the mutation queue, grabbing the pending mutation batches
|
|
12116
12243
|
// before and after.
|
|
@@ -12119,11 +12246,8 @@ async function localStoreHandleUserChange(localStore, user) {
|
|
|
12119
12246
|
.getAllMutationBatches(txn)
|
|
12120
12247
|
.next(promisedOldBatches => {
|
|
12121
12248
|
oldBatches = promisedOldBatches;
|
|
12122
|
-
|
|
12123
|
-
|
|
12124
|
-
// MutationQueue.
|
|
12125
|
-
newLocalDocuments = new LocalDocumentsView(localStoreImpl.remoteDocuments, newMutationQueue, localStoreImpl.persistence.getIndexManager());
|
|
12126
|
-
return newMutationQueue.getAllMutationBatches(txn);
|
|
12249
|
+
localStoreImpl.initializeUserComponents(user);
|
|
12250
|
+
return localStoreImpl.mutationQueue.getAllMutationBatches(txn);
|
|
12127
12251
|
})
|
|
12128
12252
|
.next(newBatches => {
|
|
12129
12253
|
const removedBatchIds = [];
|
|
@@ -12144,7 +12268,7 @@ async function localStoreHandleUserChange(localStore, user) {
|
|
|
12144
12268
|
}
|
|
12145
12269
|
// Return the set of all (potentially) changed documents and the list
|
|
12146
12270
|
// of mutation batch IDs that were affected by change.
|
|
12147
|
-
return
|
|
12271
|
+
return localStoreImpl.localDocuments
|
|
12148
12272
|
.getDocuments(txn, changedKeys)
|
|
12149
12273
|
.next(affectedDocuments => {
|
|
12150
12274
|
return {
|
|
@@ -12155,9 +12279,6 @@ async function localStoreHandleUserChange(localStore, user) {
|
|
|
12155
12279
|
});
|
|
12156
12280
|
});
|
|
12157
12281
|
});
|
|
12158
|
-
localStoreImpl.mutationQueue = newMutationQueue;
|
|
12159
|
-
localStoreImpl.localDocuments = newLocalDocuments;
|
|
12160
|
-
localStoreImpl.queryEngine.setLocalDocumentsView(localStoreImpl.localDocuments);
|
|
12161
12282
|
return result;
|
|
12162
12283
|
}
|
|
12163
12284
|
/* Accepts locally generated Mutations and commit them to storage. */
|
|
@@ -13223,14 +13344,16 @@ class MemoryRemoteDocumentCacheImpl {
|
|
|
13223
13344
|
* expected to just return 0 to avoid unnecessarily doing the work of
|
|
13224
13345
|
* calculating the size.
|
|
13225
13346
|
*/
|
|
13226
|
-
constructor(
|
|
13227
|
-
this.indexManager = indexManager;
|
|
13347
|
+
constructor(sizer) {
|
|
13228
13348
|
this.sizer = sizer;
|
|
13229
13349
|
/** Underlying cache of documents and their read times. */
|
|
13230
13350
|
this.docs = documentEntryMap();
|
|
13231
13351
|
/** Size of all cached documents. */
|
|
13232
13352
|
this.size = 0;
|
|
13233
13353
|
}
|
|
13354
|
+
setIndexManager(indexManager) {
|
|
13355
|
+
this.indexManager = indexManager;
|
|
13356
|
+
}
|
|
13234
13357
|
/**
|
|
13235
13358
|
* Adds the supplied entry to the cache and updates the cache size as appropriate.
|
|
13236
13359
|
*
|
|
@@ -13314,13 +13437,12 @@ class MemoryRemoteDocumentCacheImpl {
|
|
|
13314
13437
|
/**
|
|
13315
13438
|
* Creates a new memory-only RemoteDocumentCache.
|
|
13316
13439
|
*
|
|
13317
|
-
* @param indexManager - A class that manages collection group indices.
|
|
13318
13440
|
* @param sizer - Used to assess the size of a document. For eager GC, this is
|
|
13319
13441
|
* expected to just return 0 to avoid unnecessarily doing the work of
|
|
13320
13442
|
* calculating the size.
|
|
13321
13443
|
*/
|
|
13322
|
-
function newMemoryRemoteDocumentCache(
|
|
13323
|
-
return new MemoryRemoteDocumentCacheImpl(
|
|
13444
|
+
function newMemoryRemoteDocumentCache(sizer) {
|
|
13445
|
+
return new MemoryRemoteDocumentCacheImpl(sizer);
|
|
13324
13446
|
}
|
|
13325
13447
|
/**
|
|
13326
13448
|
* Handles the details of adding and updating documents in the MemoryRemoteDocumentCache.
|
|
@@ -13521,7 +13643,7 @@ class MemoryPersistence {
|
|
|
13521
13643
|
this.targetCache = new MemoryTargetCache(this);
|
|
13522
13644
|
const sizer = (doc) => this.referenceDelegate.documentSize(doc);
|
|
13523
13645
|
this.indexManager = new MemoryIndexManager();
|
|
13524
|
-
this.remoteDocumentCache = newMemoryRemoteDocumentCache(
|
|
13646
|
+
this.remoteDocumentCache = newMemoryRemoteDocumentCache(sizer);
|
|
13525
13647
|
this.serializer = new LocalSerializer(serializer);
|
|
13526
13648
|
this.bundleCache = new MemoryBundleCache(this.serializer);
|
|
13527
13649
|
}
|
|
@@ -13542,13 +13664,15 @@ class MemoryPersistence {
|
|
|
13542
13664
|
setNetworkEnabled() {
|
|
13543
13665
|
// No op.
|
|
13544
13666
|
}
|
|
13545
|
-
getIndexManager() {
|
|
13667
|
+
getIndexManager(user) {
|
|
13668
|
+
// We do not currently support indices for memory persistence, so we can
|
|
13669
|
+
// return the same shared instance of the memory index manager.
|
|
13546
13670
|
return this.indexManager;
|
|
13547
13671
|
}
|
|
13548
|
-
getMutationQueue(user) {
|
|
13672
|
+
getMutationQueue(user, indexManager) {
|
|
13549
13673
|
let queue = this.mutationQueues[user.toKey()];
|
|
13550
13674
|
if (!queue) {
|
|
13551
|
-
queue = new MemoryMutationQueue(
|
|
13675
|
+
queue = new MemoryMutationQueue(indexManager, this.referenceDelegate);
|
|
13552
13676
|
this.mutationQueues[user.toKey()] = queue;
|
|
13553
13677
|
}
|
|
13554
13678
|
return queue;
|
|
@@ -20511,12 +20635,12 @@ async function syncEngineListen(syncEngine, query) {
|
|
|
20511
20635
|
}
|
|
20512
20636
|
else {
|
|
20513
20637
|
const targetData = await localStoreAllocateTarget(syncEngineImpl.localStore, queryToTarget(query));
|
|
20514
|
-
const status = syncEngineImpl.sharedClientState.addLocalQueryTarget(targetData.targetId);
|
|
20515
|
-
targetId = targetData.targetId;
|
|
20516
|
-
viewSnapshot = await initializeViewAndComputeSnapshot(syncEngineImpl, query, targetId, status === 'current');
|
|
20517
20638
|
if (syncEngineImpl.isPrimaryClient) {
|
|
20518
20639
|
remoteStoreListen(syncEngineImpl.remoteStore, targetData);
|
|
20519
20640
|
}
|
|
20641
|
+
const status = syncEngineImpl.sharedClientState.addLocalQueryTarget(targetData.targetId);
|
|
20642
|
+
targetId = targetData.targetId;
|
|
20643
|
+
viewSnapshot = await initializeViewAndComputeSnapshot(syncEngineImpl, query, targetId, status === 'current');
|
|
20520
20644
|
}
|
|
20521
20645
|
return viewSnapshot;
|
|
20522
20646
|
}
|