@firebase/firestore 3.4.3-canary.e28b0e413 → 3.4.4-202211222730
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/CHANGELOG.md +10 -0
- package/dist/firestore/src/api/{query.d.ts → filter.d.ts} +0 -0
- package/dist/firestore/src/api.d.ts +1 -1
- package/dist/firestore/src/core/database_info.d.ts +1 -0
- package/dist/firestore/src/core/target.d.ts +26 -1
- package/dist/firestore/src/local/indexeddb_schema.d.ts +121 -7
- package/dist/firestore/src/local/local_serializer.d.ts +1 -1
- package/dist/firestore/src/local/remote_document_change_buffer.d.ts +3 -12
- package/dist/firestore/src/model/document.d.ts +7 -0
- package/dist/firestore/src/model/document_key.d.ts +1 -0
- package/dist/firestore/src/model/field_index.d.ts +87 -7
- package/dist/firestore/src/model/values.d.ts +7 -0
- package/dist/firestore/test/unit/local/test_remote_document_cache.d.ts +1 -1
- package/dist/firestore/test/unit/model/field_index.test.d.ts +17 -0
- package/dist/firestore/test/unit/model/target.test.d.ts +17 -0
- package/dist/firestore/test/util/helpers.d.ts +8 -2
- package/dist/index.esm2017.js +3407 -3232
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.esm5.js +3736 -3630
- package/dist/index.esm5.js.map +1 -1
- package/dist/index.node.cjs.js +412 -177
- package/dist/index.node.cjs.js.map +1 -1
- package/dist/index.node.mjs +412 -177
- package/dist/index.node.mjs.map +1 -1
- package/dist/index.rn.js +3408 -3271
- package/dist/index.rn.js.map +1 -1
- package/dist/internal.d.ts +12 -12
- package/dist/lite/firestore/src/api/{query.d.ts → filter.d.ts} +0 -0
- package/dist/lite/firestore/src/api.d.ts +1 -1
- package/dist/lite/firestore/src/core/database_info.d.ts +1 -0
- package/dist/lite/firestore/src/core/target.d.ts +26 -1
- package/dist/lite/firestore/src/local/indexeddb_schema.d.ts +121 -7
- package/dist/lite/firestore/src/local/local_serializer.d.ts +1 -1
- package/dist/lite/firestore/src/local/remote_document_change_buffer.d.ts +3 -12
- package/dist/lite/firestore/src/model/document.d.ts +7 -0
- package/dist/lite/firestore/src/model/document_key.d.ts +1 -0
- package/dist/lite/firestore/src/model/field_index.d.ts +87 -7
- package/dist/lite/firestore/src/model/values.d.ts +7 -0
- package/dist/lite/firestore/test/unit/local/test_remote_document_cache.d.ts +1 -1
- package/dist/lite/firestore/test/unit/model/field_index.test.d.ts +17 -0
- package/dist/lite/firestore/test/unit/model/target.test.d.ts +17 -0
- package/dist/lite/firestore/test/util/helpers.d.ts +8 -2
- package/dist/lite/index.browser.esm2017.js +80 -69
- package/dist/lite/index.browser.esm2017.js.map +1 -1
- package/dist/lite/index.browser.esm5.js +94 -87
- package/dist/lite/index.browser.esm5.js.map +1 -1
- package/dist/lite/index.node.cjs.js +20 -8
- package/dist/lite/index.node.cjs.js.map +1 -1
- package/dist/lite/index.node.mjs +20 -8
- package/dist/lite/index.node.mjs.map +1 -1
- package/dist/lite/index.rn.esm2017.js +99 -88
- package/dist/lite/index.rn.esm2017.js.map +1 -1
- package/dist/lite/internal.d.ts +9 -0
- package/dist/lite/packages/firestore/dist/lite/index.browser.esm2017.d.ts +20 -19
- package/dist/lite/packages/firestore/src/api/{query.d.ts → filter.d.ts} +0 -0
- package/dist/lite/packages/firestore/src/api.d.ts +1 -1
- package/dist/lite/packages/firestore/src/core/database_info.d.ts +1 -0
- package/dist/lite/packages/firestore/src/core/target.d.ts +26 -1
- package/dist/lite/packages/firestore/src/local/indexeddb_schema.d.ts +121 -7
- package/dist/lite/packages/firestore/src/local/local_serializer.d.ts +1 -1
- package/dist/lite/packages/firestore/src/local/remote_document_change_buffer.d.ts +3 -12
- package/dist/lite/packages/firestore/src/model/document.d.ts +7 -0
- package/dist/lite/packages/firestore/src/model/document_key.d.ts +1 -0
- package/dist/lite/packages/firestore/src/model/field_index.d.ts +87 -7
- package/dist/lite/packages/firestore/src/model/values.d.ts +7 -0
- package/dist/lite/packages/firestore/test/unit/local/test_remote_document_cache.d.ts +1 -1
- package/dist/lite/packages/firestore/test/unit/model/field_index.test.d.ts +17 -0
- package/dist/lite/packages/firestore/test/unit/model/target.test.d.ts +17 -0
- package/dist/lite/packages/firestore/test/util/helpers.d.ts +8 -2
- package/dist/lite/private.d.ts +7 -0
- package/dist/packages/firestore/dist/index.esm2017.d.ts +181 -179
- package/dist/packages/firestore/src/api/{query.d.ts → filter.d.ts} +0 -0
- package/dist/packages/firestore/src/api.d.ts +1 -1
- package/dist/packages/firestore/src/core/database_info.d.ts +1 -0
- package/dist/packages/firestore/src/core/target.d.ts +26 -1
- package/dist/packages/firestore/src/local/indexeddb_schema.d.ts +121 -7
- package/dist/packages/firestore/src/local/local_serializer.d.ts +1 -1
- package/dist/packages/firestore/src/local/remote_document_change_buffer.d.ts +3 -12
- package/dist/packages/firestore/src/model/document.d.ts +7 -0
- package/dist/packages/firestore/src/model/document_key.d.ts +1 -0
- package/dist/packages/firestore/src/model/field_index.d.ts +87 -7
- package/dist/packages/firestore/src/model/values.d.ts +7 -0
- package/dist/packages/firestore/test/unit/local/test_remote_document_cache.d.ts +1 -1
- package/dist/packages/firestore/test/unit/model/field_index.test.d.ts +17 -0
- package/dist/packages/firestore/test/unit/model/target.test.d.ts +17 -0
- package/dist/packages/firestore/test/util/helpers.d.ts +8 -2
- package/dist/private.d.ts +10 -12
- package/package.json +10 -10
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.
|
|
11
|
+
const version$1 = "3.4.4-202211222730";
|
|
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-202211222730";
|
|
65
65
|
|
|
66
66
|
/**
|
|
67
67
|
* @license
|
|
@@ -1192,23 +1192,6 @@ function decodeResourcePath(path) {
|
|
|
1192
1192
|
}
|
|
1193
1193
|
return new ResourcePath(segments);
|
|
1194
1194
|
}
|
|
1195
|
-
|
|
1196
|
-
/**
|
|
1197
|
-
* @license
|
|
1198
|
-
* Copyright 2017 Google LLC
|
|
1199
|
-
*
|
|
1200
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1201
|
-
* you may not use this file except in compliance with the License.
|
|
1202
|
-
* You may obtain a copy of the License at
|
|
1203
|
-
*
|
|
1204
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1205
|
-
*
|
|
1206
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
1207
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1208
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1209
|
-
* See the License for the specific language governing permissions and
|
|
1210
|
-
* limitations under the License.
|
|
1211
|
-
*/
|
|
1212
1195
|
/**
|
|
1213
1196
|
* Schema Version for the Web client:
|
|
1214
1197
|
* 1. Initial version including Mutation Queue, Query Cache, and Remote
|
|
@@ -1227,6 +1210,7 @@ function decodeResourcePath(path) {
|
|
|
1227
1210
|
* an auto-incrementing ID. This is required for Index-Free queries.
|
|
1228
1211
|
* 10. Rewrite the canonical IDs to the explicit Protobuf-based format.
|
|
1229
1212
|
* 11. Add bundles and named_queries for bundle support.
|
|
1213
|
+
* 12. Add indexing support.
|
|
1230
1214
|
*/
|
|
1231
1215
|
const SCHEMA_VERSION = 11;
|
|
1232
1216
|
/**
|
|
@@ -1753,9 +1737,7 @@ class DbClientMetadata {
|
|
|
1753
1737
|
DbClientMetadata.store = 'clientMetadata';
|
|
1754
1738
|
/** Keys are automatically assigned via the clientId properties. */
|
|
1755
1739
|
DbClientMetadata.keyPath = 'clientId';
|
|
1756
|
-
/**
|
|
1757
|
-
* A object representing a bundle loaded by the SDK.
|
|
1758
|
-
*/
|
|
1740
|
+
/** An object representing a bundle loaded by the SDK. */
|
|
1759
1741
|
class DbBundle {
|
|
1760
1742
|
constructor(
|
|
1761
1743
|
/** The ID of the loaded bundle. */
|
|
@@ -1772,9 +1754,7 @@ class DbBundle {
|
|
|
1772
1754
|
/** Name of the IndexedDb object store. */
|
|
1773
1755
|
DbBundle.store = 'bundles';
|
|
1774
1756
|
DbBundle.keyPath = 'bundleId';
|
|
1775
|
-
/**
|
|
1776
|
-
* A object representing a named query loaded by the SDK via a bundle.
|
|
1777
|
-
*/
|
|
1757
|
+
/** An object representing a named query loaded by the SDK via a bundle. */
|
|
1778
1758
|
class DbNamedQuery {
|
|
1779
1759
|
constructor(
|
|
1780
1760
|
/** The name of the query. */
|
|
@@ -1791,6 +1771,93 @@ class DbNamedQuery {
|
|
|
1791
1771
|
/** Name of the IndexedDb object store. */
|
|
1792
1772
|
DbNamedQuery.store = 'namedQueries';
|
|
1793
1773
|
DbNamedQuery.keyPath = 'name';
|
|
1774
|
+
/** An object representing the global configuration for a field index. */
|
|
1775
|
+
class DbIndexConfiguration {
|
|
1776
|
+
constructor(
|
|
1777
|
+
/** The index id for this entry. */
|
|
1778
|
+
indexId,
|
|
1779
|
+
/** The collection group this index belongs to. */
|
|
1780
|
+
collectionGroup,
|
|
1781
|
+
/** The fields to index for this index. */
|
|
1782
|
+
fields) {
|
|
1783
|
+
this.indexId = indexId;
|
|
1784
|
+
this.collectionGroup = collectionGroup;
|
|
1785
|
+
this.fields = fields;
|
|
1786
|
+
}
|
|
1787
|
+
}
|
|
1788
|
+
/** Name of the IndexedDb object store. */
|
|
1789
|
+
DbIndexConfiguration.store = 'indexConfiguration';
|
|
1790
|
+
DbIndexConfiguration.keyPath = 'indexId';
|
|
1791
|
+
/**
|
|
1792
|
+
* An object describing how up-to-date the index backfill is for each user and
|
|
1793
|
+
* index.
|
|
1794
|
+
*/
|
|
1795
|
+
class DbIndexState {
|
|
1796
|
+
constructor(
|
|
1797
|
+
/** The index id for this entry. */
|
|
1798
|
+
indexId,
|
|
1799
|
+
/** The user id for this entry. */
|
|
1800
|
+
uid,
|
|
1801
|
+
/**
|
|
1802
|
+
* A number that indicates when the index was last updated (relative to
|
|
1803
|
+
* other indexes).
|
|
1804
|
+
*/
|
|
1805
|
+
sequenceNumber,
|
|
1806
|
+
/**
|
|
1807
|
+
* The latest read time that has been indexed by Firestore for this field
|
|
1808
|
+
* index. Set to `{seconds: 0, nanos: 0}` if no documents have been indexed.
|
|
1809
|
+
*/
|
|
1810
|
+
readTime,
|
|
1811
|
+
/**
|
|
1812
|
+
* The last document that has been indexed for this field index. Empty if
|
|
1813
|
+
* no documents have been indexed.
|
|
1814
|
+
*/
|
|
1815
|
+
documentKey,
|
|
1816
|
+
/**
|
|
1817
|
+
* The largest mutation batch id that has been processed for this index. -1
|
|
1818
|
+
* if no mutations have been indexed.
|
|
1819
|
+
*/
|
|
1820
|
+
largestBatchId) {
|
|
1821
|
+
this.indexId = indexId;
|
|
1822
|
+
this.uid = uid;
|
|
1823
|
+
this.sequenceNumber = sequenceNumber;
|
|
1824
|
+
this.readTime = readTime;
|
|
1825
|
+
this.documentKey = documentKey;
|
|
1826
|
+
this.largestBatchId = largestBatchId;
|
|
1827
|
+
}
|
|
1828
|
+
}
|
|
1829
|
+
/** Name of the IndexedDb object store. */
|
|
1830
|
+
DbIndexState.store = 'indexState';
|
|
1831
|
+
DbIndexState.keyPath = ['indexId', 'uid'];
|
|
1832
|
+
/** An object that stores the encoded entries for all documents and fields. */
|
|
1833
|
+
class DbIndexEntries {
|
|
1834
|
+
constructor(
|
|
1835
|
+
/** The index id for this entry. */
|
|
1836
|
+
indexId,
|
|
1837
|
+
/** The user id for this entry. */
|
|
1838
|
+
uid,
|
|
1839
|
+
/** The encoded array index value for this entry. */
|
|
1840
|
+
arrayValue,
|
|
1841
|
+
/** The encoded directional value for equality and inequality filters. */
|
|
1842
|
+
directionalValue,
|
|
1843
|
+
/** The document key this entry points to. */
|
|
1844
|
+
documentKey) {
|
|
1845
|
+
this.indexId = indexId;
|
|
1846
|
+
this.uid = uid;
|
|
1847
|
+
this.arrayValue = arrayValue;
|
|
1848
|
+
this.directionalValue = directionalValue;
|
|
1849
|
+
this.documentKey = documentKey;
|
|
1850
|
+
}
|
|
1851
|
+
}
|
|
1852
|
+
/** Name of the IndexedDb object store. */
|
|
1853
|
+
DbIndexEntries.store = 'indexEntries';
|
|
1854
|
+
DbIndexEntries.keyPath = [
|
|
1855
|
+
'indexId',
|
|
1856
|
+
'uid',
|
|
1857
|
+
'arrayValue',
|
|
1858
|
+
'directionalValue',
|
|
1859
|
+
'documentKey'
|
|
1860
|
+
];
|
|
1794
1861
|
// Visible for testing
|
|
1795
1862
|
const V1_STORES = [
|
|
1796
1863
|
DbMutationQueue.store,
|
|
@@ -1805,7 +1872,6 @@ const V1_STORES = [
|
|
|
1805
1872
|
// V2 is no longer usable (see comment at top of file)
|
|
1806
1873
|
// Visible for testing
|
|
1807
1874
|
const V3_STORES = V1_STORES;
|
|
1808
|
-
// Visible for testing
|
|
1809
1875
|
// Note: DbRemoteDocumentChanges is no longer used and dropped with v9.
|
|
1810
1876
|
const V4_STORES = [...V3_STORES, DbClientMetadata.store];
|
|
1811
1877
|
// V5 does not change the set of stores.
|
|
@@ -1815,6 +1881,12 @@ const V8_STORES = [...V6_STORES, DbCollectionParent.store];
|
|
|
1815
1881
|
// V9 does not change the set of stores.
|
|
1816
1882
|
// V10 does not change the set of stores.
|
|
1817
1883
|
const V11_STORES = [...V8_STORES, DbBundle.store, DbNamedQuery.store];
|
|
1884
|
+
[
|
|
1885
|
+
...V11_STORES,
|
|
1886
|
+
DbIndexConfiguration.store,
|
|
1887
|
+
DbIndexState.store,
|
|
1888
|
+
DbIndexEntries.store
|
|
1889
|
+
];
|
|
1818
1890
|
/**
|
|
1819
1891
|
* The list of all default IndexedDB stores used throughout the SDK. This is
|
|
1820
1892
|
* used when creating transactions so that access across all stores is done
|
|
@@ -3374,6 +3446,75 @@ function getLocalWriteTime(value) {
|
|
|
3374
3446
|
return new Timestamp(localWriteTime.seconds, localWriteTime.nanos);
|
|
3375
3447
|
}
|
|
3376
3448
|
|
|
3449
|
+
/**
|
|
3450
|
+
* @license
|
|
3451
|
+
* Copyright 2017 Google LLC
|
|
3452
|
+
*
|
|
3453
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
3454
|
+
* you may not use this file except in compliance with the License.
|
|
3455
|
+
* You may obtain a copy of the License at
|
|
3456
|
+
*
|
|
3457
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
3458
|
+
*
|
|
3459
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
3460
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
3461
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
3462
|
+
* See the License for the specific language governing permissions and
|
|
3463
|
+
* limitations under the License.
|
|
3464
|
+
*/
|
|
3465
|
+
class DatabaseInfo {
|
|
3466
|
+
/**
|
|
3467
|
+
* Constructs a DatabaseInfo using the provided host, databaseId and
|
|
3468
|
+
* persistenceKey.
|
|
3469
|
+
*
|
|
3470
|
+
* @param databaseId - The database to use.
|
|
3471
|
+
* @param appId - The Firebase App Id.
|
|
3472
|
+
* @param persistenceKey - A unique identifier for this Firestore's local
|
|
3473
|
+
* storage (used in conjunction with the databaseId).
|
|
3474
|
+
* @param host - The Firestore backend host to connect to.
|
|
3475
|
+
* @param ssl - Whether to use SSL when connecting.
|
|
3476
|
+
* @param forceLongPolling - Whether to use the forceLongPolling option
|
|
3477
|
+
* when using WebChannel as the network transport.
|
|
3478
|
+
* @param autoDetectLongPolling - Whether to use the detectBufferingProxy
|
|
3479
|
+
* option when using WebChannel as the network transport.
|
|
3480
|
+
* @param useFetchStreams Whether to use the Fetch API instead of
|
|
3481
|
+
* XMLHTTPRequest
|
|
3482
|
+
*/
|
|
3483
|
+
constructor(databaseId, appId, persistenceKey, host, ssl, forceLongPolling, autoDetectLongPolling, useFetchStreams) {
|
|
3484
|
+
this.databaseId = databaseId;
|
|
3485
|
+
this.appId = appId;
|
|
3486
|
+
this.persistenceKey = persistenceKey;
|
|
3487
|
+
this.host = host;
|
|
3488
|
+
this.ssl = ssl;
|
|
3489
|
+
this.forceLongPolling = forceLongPolling;
|
|
3490
|
+
this.autoDetectLongPolling = autoDetectLongPolling;
|
|
3491
|
+
this.useFetchStreams = useFetchStreams;
|
|
3492
|
+
}
|
|
3493
|
+
}
|
|
3494
|
+
/** The default database name for a project. */
|
|
3495
|
+
const DEFAULT_DATABASE_NAME = '(default)';
|
|
3496
|
+
/**
|
|
3497
|
+
* Represents the database ID a Firestore client is associated with.
|
|
3498
|
+
* @internal
|
|
3499
|
+
*/
|
|
3500
|
+
class DatabaseId {
|
|
3501
|
+
constructor(projectId, database) {
|
|
3502
|
+
this.projectId = projectId;
|
|
3503
|
+
this.database = database ? database : DEFAULT_DATABASE_NAME;
|
|
3504
|
+
}
|
|
3505
|
+
static empty() {
|
|
3506
|
+
return new DatabaseId('', '');
|
|
3507
|
+
}
|
|
3508
|
+
get isDefaultDatabase() {
|
|
3509
|
+
return this.database === DEFAULT_DATABASE_NAME;
|
|
3510
|
+
}
|
|
3511
|
+
isEqual(other) {
|
|
3512
|
+
return (other instanceof DatabaseId &&
|
|
3513
|
+
other.projectId === this.projectId &&
|
|
3514
|
+
other.database === this.database);
|
|
3515
|
+
}
|
|
3516
|
+
}
|
|
3517
|
+
|
|
3377
3518
|
/**
|
|
3378
3519
|
* @license
|
|
3379
3520
|
* Copyright 2017 Google LLC
|
|
@@ -3445,6 +3586,9 @@ class DocumentKey {
|
|
|
3445
3586
|
static fromName(name) {
|
|
3446
3587
|
return new DocumentKey(ResourcePath.fromString(name).popFirst(5));
|
|
3447
3588
|
}
|
|
3589
|
+
static empty() {
|
|
3590
|
+
return new DocumentKey(ResourcePath.emptyPath());
|
|
3591
|
+
}
|
|
3448
3592
|
/** Returns true if the document is in the specified collectionId. */
|
|
3449
3593
|
hasCollectionId(collectionId) {
|
|
3450
3594
|
return (this.path.length >= 2 &&
|
|
@@ -4093,10 +4237,11 @@ function extractFieldMask(value) {
|
|
|
4093
4237
|
* from all views.
|
|
4094
4238
|
*/
|
|
4095
4239
|
class MutableDocument {
|
|
4096
|
-
constructor(key, documentType, version, data, documentState) {
|
|
4240
|
+
constructor(key, documentType, version, readTime, data, documentState) {
|
|
4097
4241
|
this.key = key;
|
|
4098
4242
|
this.documentType = documentType;
|
|
4099
4243
|
this.version = version;
|
|
4244
|
+
this.readTime = readTime;
|
|
4100
4245
|
this.data = data;
|
|
4101
4246
|
this.documentState = documentState;
|
|
4102
4247
|
}
|
|
@@ -4105,18 +4250,18 @@ class MutableDocument {
|
|
|
4105
4250
|
* base document for mutations.
|
|
4106
4251
|
*/
|
|
4107
4252
|
static newInvalidDocument(documentKey) {
|
|
4108
|
-
return new MutableDocument(documentKey, 0 /* INVALID */, SnapshotVersion.min(), ObjectValue.empty(), 0 /* SYNCED */);
|
|
4253
|
+
return new MutableDocument(documentKey, 0 /* INVALID */, SnapshotVersion.min(), SnapshotVersion.min(), ObjectValue.empty(), 0 /* SYNCED */);
|
|
4109
4254
|
}
|
|
4110
4255
|
/**
|
|
4111
4256
|
* Creates a new document that is known to exist with the given data at the
|
|
4112
4257
|
* given version.
|
|
4113
4258
|
*/
|
|
4114
4259
|
static newFoundDocument(documentKey, version, value) {
|
|
4115
|
-
return new MutableDocument(documentKey, 1 /* FOUND_DOCUMENT */, version, value, 0 /* SYNCED */);
|
|
4260
|
+
return new MutableDocument(documentKey, 1 /* FOUND_DOCUMENT */, version, SnapshotVersion.min(), value, 0 /* SYNCED */);
|
|
4116
4261
|
}
|
|
4117
4262
|
/** Creates a new document that is known to not exist at the given version. */
|
|
4118
4263
|
static newNoDocument(documentKey, version) {
|
|
4119
|
-
return new MutableDocument(documentKey, 2 /* NO_DOCUMENT */, version, ObjectValue.empty(), 0 /* SYNCED */);
|
|
4264
|
+
return new MutableDocument(documentKey, 2 /* NO_DOCUMENT */, version, SnapshotVersion.min(), ObjectValue.empty(), 0 /* SYNCED */);
|
|
4120
4265
|
}
|
|
4121
4266
|
/**
|
|
4122
4267
|
* Creates a new document that is known to exist at the given version but
|
|
@@ -4124,7 +4269,7 @@ class MutableDocument {
|
|
|
4124
4269
|
* base document).
|
|
4125
4270
|
*/
|
|
4126
4271
|
static newUnknownDocument(documentKey, version) {
|
|
4127
|
-
return new MutableDocument(documentKey, 3 /* UNKNOWN_DOCUMENT */, version, ObjectValue.empty(), 2 /* HAS_COMMITTED_MUTATIONS */);
|
|
4272
|
+
return new MutableDocument(documentKey, 3 /* UNKNOWN_DOCUMENT */, version, SnapshotVersion.min(), ObjectValue.empty(), 2 /* HAS_COMMITTED_MUTATIONS */);
|
|
4128
4273
|
}
|
|
4129
4274
|
/**
|
|
4130
4275
|
* Changes the document type to indicate that it exists and that its version
|
|
@@ -4168,6 +4313,10 @@ class MutableDocument {
|
|
|
4168
4313
|
this.documentState = 1 /* HAS_LOCAL_MUTATIONS */;
|
|
4169
4314
|
return this;
|
|
4170
4315
|
}
|
|
4316
|
+
setReadTime(readTime) {
|
|
4317
|
+
this.readTime = readTime;
|
|
4318
|
+
return this;
|
|
4319
|
+
}
|
|
4171
4320
|
get hasLocalMutations() {
|
|
4172
4321
|
return this.documentState === 1 /* HAS_LOCAL_MUTATIONS */;
|
|
4173
4322
|
}
|
|
@@ -4198,7 +4347,7 @@ class MutableDocument {
|
|
|
4198
4347
|
this.data.isEqual(other.data));
|
|
4199
4348
|
}
|
|
4200
4349
|
mutableCopy() {
|
|
4201
|
-
return new MutableDocument(this.key, this.documentType, this.version, this.data.clone(), this.documentState);
|
|
4350
|
+
return new MutableDocument(this.key, this.documentType, this.version, this.readTime, this.data.clone(), this.documentState);
|
|
4202
4351
|
}
|
|
4203
4352
|
toString() {
|
|
4204
4353
|
return (`Document(${this.key}, ${this.version}, ${JSON.stringify(this.data.value)}, ` +
|
|
@@ -4221,6 +4370,125 @@ function compareDocumentsByField(field, d1, d2) {
|
|
|
4221
4370
|
}
|
|
4222
4371
|
}
|
|
4223
4372
|
|
|
4373
|
+
/**
|
|
4374
|
+
* @license
|
|
4375
|
+
* Copyright 2021 Google LLC
|
|
4376
|
+
*
|
|
4377
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4378
|
+
* you may not use this file except in compliance with the License.
|
|
4379
|
+
* You may obtain a copy of the License at
|
|
4380
|
+
*
|
|
4381
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
4382
|
+
*
|
|
4383
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
4384
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
4385
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
4386
|
+
* See the License for the specific language governing permissions and
|
|
4387
|
+
* limitations under the License.
|
|
4388
|
+
*/
|
|
4389
|
+
/**
|
|
4390
|
+
* The initial mutation batch id for each index. Gets updated during index
|
|
4391
|
+
* backfill.
|
|
4392
|
+
*/
|
|
4393
|
+
const INITIAL_LARGEST_BATCH_ID = -1;
|
|
4394
|
+
/**
|
|
4395
|
+
* The initial sequence number for each index. Gets updated during index
|
|
4396
|
+
* backfill.
|
|
4397
|
+
*/
|
|
4398
|
+
const INITIAL_SEQUENCE_NUMBER = 0;
|
|
4399
|
+
/**
|
|
4400
|
+
* An index definition for field indexes in Firestore.
|
|
4401
|
+
*
|
|
4402
|
+
* Every index is associated with a collection. The definition contains a list
|
|
4403
|
+
* of fields and their index kind (which can be `ASCENDING`, `DESCENDING` or
|
|
4404
|
+
* `CONTAINS` for ArrayContains/ArrayContainsAny queries).
|
|
4405
|
+
*
|
|
4406
|
+
* Unlike the backend, the SDK does not differentiate between collection or
|
|
4407
|
+
* collection group-scoped indices. Every index can be used for both single
|
|
4408
|
+
* collection and collection group queries.
|
|
4409
|
+
*/
|
|
4410
|
+
class FieldIndex {
|
|
4411
|
+
constructor(
|
|
4412
|
+
/**
|
|
4413
|
+
* The index ID. Returns -1 if the index ID is not available (e.g. the index
|
|
4414
|
+
* has not yet been persisted).
|
|
4415
|
+
*/
|
|
4416
|
+
indexId,
|
|
4417
|
+
/** The collection ID this index applies to. */
|
|
4418
|
+
collectionGroup,
|
|
4419
|
+
/** The field segments for this index. */
|
|
4420
|
+
segments,
|
|
4421
|
+
/** Shows how up-to-date the index is for the current user. */
|
|
4422
|
+
indexState) {
|
|
4423
|
+
this.indexId = indexId;
|
|
4424
|
+
this.collectionGroup = collectionGroup;
|
|
4425
|
+
this.segments = segments;
|
|
4426
|
+
this.indexState = indexState;
|
|
4427
|
+
}
|
|
4428
|
+
}
|
|
4429
|
+
/** An ID for an index that has not yet been added to persistence. */
|
|
4430
|
+
FieldIndex.UNKNOWN_ID = -1;
|
|
4431
|
+
/** An index component consisting of field path and index type. */
|
|
4432
|
+
class IndexSegment {
|
|
4433
|
+
constructor(
|
|
4434
|
+
/** The field path of the component. */
|
|
4435
|
+
fieldPath,
|
|
4436
|
+
/** The fields sorting order. */
|
|
4437
|
+
kind) {
|
|
4438
|
+
this.fieldPath = fieldPath;
|
|
4439
|
+
this.kind = kind;
|
|
4440
|
+
}
|
|
4441
|
+
}
|
|
4442
|
+
/**
|
|
4443
|
+
* Stores the "high water mark" that indicates how updated the Index is for the
|
|
4444
|
+
* current user.
|
|
4445
|
+
*/
|
|
4446
|
+
class IndexState {
|
|
4447
|
+
constructor(
|
|
4448
|
+
/**
|
|
4449
|
+
* Indicates when the index was last updated (relative to other indexes).
|
|
4450
|
+
*/
|
|
4451
|
+
sequenceNumber,
|
|
4452
|
+
/** The the latest indexed read time, document and batch id. */
|
|
4453
|
+
offset) {
|
|
4454
|
+
this.sequenceNumber = sequenceNumber;
|
|
4455
|
+
this.offset = offset;
|
|
4456
|
+
}
|
|
4457
|
+
/** The state of an index that has not yet been backfilled. */
|
|
4458
|
+
static empty() {
|
|
4459
|
+
return new IndexState(INITIAL_SEQUENCE_NUMBER, IndexOffset.min());
|
|
4460
|
+
}
|
|
4461
|
+
}
|
|
4462
|
+
/**
|
|
4463
|
+
* Stores the latest read time, document and batch ID that were processed for an
|
|
4464
|
+
* index.
|
|
4465
|
+
*/
|
|
4466
|
+
class IndexOffset {
|
|
4467
|
+
constructor(
|
|
4468
|
+
/**
|
|
4469
|
+
* The latest read time version that has been indexed by Firestore for this
|
|
4470
|
+
* field index.
|
|
4471
|
+
*/
|
|
4472
|
+
readTime,
|
|
4473
|
+
/**
|
|
4474
|
+
* The key of the last document that was indexed for this query. Use
|
|
4475
|
+
* `DocumentKey.empty()` if no document has been indexed.
|
|
4476
|
+
*/
|
|
4477
|
+
documentKey,
|
|
4478
|
+
/*
|
|
4479
|
+
* The largest mutation batch id that's been processed by Firestore.
|
|
4480
|
+
*/
|
|
4481
|
+
largestBatchId) {
|
|
4482
|
+
this.readTime = readTime;
|
|
4483
|
+
this.documentKey = documentKey;
|
|
4484
|
+
this.largestBatchId = largestBatchId;
|
|
4485
|
+
}
|
|
4486
|
+
/** The state of an index that has not yet been backfilled. */
|
|
4487
|
+
static min() {
|
|
4488
|
+
return new IndexOffset(SnapshotVersion.min(), DocumentKey.empty(), INITIAL_LARGEST_BATCH_ID);
|
|
4489
|
+
}
|
|
4490
|
+
}
|
|
4491
|
+
|
|
4224
4492
|
/**
|
|
4225
4493
|
* @license
|
|
4226
4494
|
* Copyright 2019 Google LLC
|
|
@@ -4345,7 +4613,7 @@ function targetEquals(left, right) {
|
|
|
4345
4613
|
}
|
|
4346
4614
|
return boundEquals(left.endAt, right.endAt);
|
|
4347
4615
|
}
|
|
4348
|
-
function
|
|
4616
|
+
function targetIsDocumentTarget(target) {
|
|
4349
4617
|
return (DocumentKey.isDocumentKey(target.path) &&
|
|
4350
4618
|
target.collectionGroup === null &&
|
|
4351
4619
|
target.filters.length === 0);
|
|
@@ -4533,6 +4801,7 @@ class ArrayContainsAnyFilter extends FieldFilter {
|
|
|
4533
4801
|
return other.arrayValue.values.some(val => arrayValueContains(this.value.arrayValue, val));
|
|
4534
4802
|
}
|
|
4535
4803
|
}
|
|
4804
|
+
// TODO(indexing): Change Bound.before to "inclusive"
|
|
4536
4805
|
/**
|
|
4537
4806
|
* Represents a bound of a query.
|
|
4538
4807
|
*
|
|
@@ -6990,7 +7259,7 @@ class WatchChangeAggregator {
|
|
|
6990
7259
|
const targetData = this.targetDataForActiveTarget(targetId);
|
|
6991
7260
|
if (targetData) {
|
|
6992
7261
|
const target = targetData.target;
|
|
6993
|
-
if (
|
|
7262
|
+
if (targetIsDocumentTarget(target)) {
|
|
6994
7263
|
if (expectedCount === 0) {
|
|
6995
7264
|
// The existence filter told us the document does not exist. We deduce
|
|
6996
7265
|
// that this document does not exist and apply a deleted document to
|
|
@@ -7025,7 +7294,7 @@ class WatchChangeAggregator {
|
|
|
7025
7294
|
this.targetStates.forEach((targetState, targetId) => {
|
|
7026
7295
|
const targetData = this.targetDataForActiveTarget(targetId);
|
|
7027
7296
|
if (targetData) {
|
|
7028
|
-
if (targetState.current &&
|
|
7297
|
+
if (targetState.current && targetIsDocumentTarget(targetData.target)) {
|
|
7029
7298
|
// Document queries for document that don't exist can produce an empty
|
|
7030
7299
|
// result set. To update our local cache, we synthesize a document
|
|
7031
7300
|
// delete if we have not previously received the document. This
|
|
@@ -7068,6 +7337,7 @@ class WatchChangeAggregator {
|
|
|
7068
7337
|
resolvedLimboDocuments = resolvedLimboDocuments.add(key);
|
|
7069
7338
|
}
|
|
7070
7339
|
});
|
|
7340
|
+
this.pendingDocumentUpdates.forEach((_, doc) => doc.setReadTime(snapshotVersion));
|
|
7071
7341
|
const remoteEvent = new RemoteEvent(snapshotVersion, targetChanges, this.pendingTargetResets, this.pendingDocumentUpdates, resolvedLimboDocuments);
|
|
7072
7342
|
this.pendingDocumentUpdates = mutableDocumentMap();
|
|
7073
7343
|
this.pendingDocumentTargetMapping = documentTargetMap();
|
|
@@ -7860,7 +8130,7 @@ function toLabel(serializer, purpose) {
|
|
|
7860
8130
|
function toTarget(serializer, targetData) {
|
|
7861
8131
|
let result;
|
|
7862
8132
|
const target = targetData.target;
|
|
7863
|
-
if (
|
|
8133
|
+
if (targetIsDocumentTarget(target)) {
|
|
7864
8134
|
result = { documents: toDocumentsTarget(serializer, target) };
|
|
7865
8135
|
}
|
|
7866
8136
|
else {
|
|
@@ -8188,29 +8458,34 @@ class LocalSerializer {
|
|
|
8188
8458
|
}
|
|
8189
8459
|
/** Decodes a remote document from storage locally to a Document. */
|
|
8190
8460
|
function fromDbRemoteDocument(localSerializer, remoteDoc) {
|
|
8461
|
+
let doc;
|
|
8191
8462
|
if (remoteDoc.document) {
|
|
8192
|
-
|
|
8463
|
+
doc = fromDocument(localSerializer.remoteSerializer, remoteDoc.document, !!remoteDoc.hasCommittedMutations);
|
|
8193
8464
|
}
|
|
8194
8465
|
else if (remoteDoc.noDocument) {
|
|
8195
8466
|
const key = DocumentKey.fromSegments(remoteDoc.noDocument.path);
|
|
8196
8467
|
const version = fromDbTimestamp(remoteDoc.noDocument.readTime);
|
|
8197
|
-
|
|
8198
|
-
|
|
8199
|
-
|
|
8200
|
-
|
|
8468
|
+
doc = MutableDocument.newNoDocument(key, version);
|
|
8469
|
+
if (remoteDoc.hasCommittedMutations) {
|
|
8470
|
+
doc.setHasCommittedMutations();
|
|
8471
|
+
}
|
|
8201
8472
|
}
|
|
8202
8473
|
else if (remoteDoc.unknownDocument) {
|
|
8203
8474
|
const key = DocumentKey.fromSegments(remoteDoc.unknownDocument.path);
|
|
8204
8475
|
const version = fromDbTimestamp(remoteDoc.unknownDocument.version);
|
|
8205
|
-
|
|
8476
|
+
doc = MutableDocument.newUnknownDocument(key, version);
|
|
8206
8477
|
}
|
|
8207
8478
|
else {
|
|
8208
8479
|
return fail();
|
|
8209
8480
|
}
|
|
8481
|
+
if (remoteDoc.readTime) {
|
|
8482
|
+
doc.setReadTime(fromDbTimestampKey(remoteDoc.readTime));
|
|
8483
|
+
}
|
|
8484
|
+
return doc;
|
|
8210
8485
|
}
|
|
8211
8486
|
/** Encodes a document for storage locally. */
|
|
8212
|
-
function toDbRemoteDocument(localSerializer, document
|
|
8213
|
-
const dbReadTime = toDbTimestampKey(readTime);
|
|
8487
|
+
function toDbRemoteDocument(localSerializer, document) {
|
|
8488
|
+
const dbReadTime = toDbTimestampKey(document.readTime);
|
|
8214
8489
|
const parentPath = document.key.path.popLast().toArray();
|
|
8215
8490
|
if (document.isFoundDocument()) {
|
|
8216
8491
|
const doc = toDocument(localSerializer.remoteSerializer, document);
|
|
@@ -8221,10 +8496,10 @@ function toDbRemoteDocument(localSerializer, document, readTime) {
|
|
|
8221
8496
|
}
|
|
8222
8497
|
else if (document.isNoDocument()) {
|
|
8223
8498
|
const path = document.key.path.toArray();
|
|
8224
|
-
const
|
|
8499
|
+
const version = toDbTimestamp(document.version);
|
|
8225
8500
|
const hasCommittedMutations = document.hasCommittedMutations;
|
|
8226
8501
|
return new DbRemoteDocument(
|
|
8227
|
-
/* unknownDocument= */ null, new DbNoDocument(path,
|
|
8502
|
+
/* unknownDocument= */ null, new DbNoDocument(path, version),
|
|
8228
8503
|
/* document= */ null, hasCommittedMutations, dbReadTime, parentPath);
|
|
8229
8504
|
}
|
|
8230
8505
|
else if (document.isUnknownDocument()) {
|
|
@@ -8305,7 +8580,7 @@ function toDbTarget(localSerializer, targetData) {
|
|
|
8305
8580
|
const dbTimestamp = toDbTimestamp(targetData.snapshotVersion);
|
|
8306
8581
|
const dbLastLimboFreeTimestamp = toDbTimestamp(targetData.lastLimboFreeSnapshotVersion);
|
|
8307
8582
|
let queryProto;
|
|
8308
|
-
if (
|
|
8583
|
+
if (targetIsDocumentTarget(targetData.target)) {
|
|
8309
8584
|
queryProto = toDocumentsTarget(localSerializer.remoteSerializer, targetData.target);
|
|
8310
8585
|
}
|
|
8311
8586
|
else {
|
|
@@ -9753,7 +10028,7 @@ class IndexedDbLruDelegateImpl {
|
|
|
9753
10028
|
// Our size accounting requires us to read all documents before
|
|
9754
10029
|
// removing them.
|
|
9755
10030
|
return changeBuffer.getEntry(txn, docKey).next(() => {
|
|
9756
|
-
changeBuffer.removeEntry(docKey);
|
|
10031
|
+
changeBuffer.removeEntry(docKey, SnapshotVersion.min());
|
|
9757
10032
|
return documentTargetStore(txn).delete(sentinelKey$1(docKey));
|
|
9758
10033
|
});
|
|
9759
10034
|
}
|
|
@@ -9966,27 +10241,19 @@ class ObjectMap {
|
|
|
9966
10241
|
*/
|
|
9967
10242
|
class RemoteDocumentChangeBuffer {
|
|
9968
10243
|
constructor() {
|
|
9969
|
-
// A mapping of document key to the new cache entry that should be written
|
|
9970
|
-
// existing cache entry should be removed).
|
|
10244
|
+
// A mapping of document key to the new cache entry that should be written.
|
|
9971
10245
|
this.changes = new ObjectMap(key => key.toString(), (l, r) => l.isEqual(r));
|
|
9972
10246
|
this.changesApplied = false;
|
|
9973
10247
|
}
|
|
9974
|
-
getReadTime(key) {
|
|
9975
|
-
const change = this.changes.get(key);
|
|
9976
|
-
if (change) {
|
|
9977
|
-
return change.readTime;
|
|
9978
|
-
}
|
|
9979
|
-
return SnapshotVersion.min();
|
|
9980
|
-
}
|
|
9981
10248
|
/**
|
|
9982
10249
|
* Buffers a `RemoteDocumentCache.addEntry()` call.
|
|
9983
10250
|
*
|
|
9984
10251
|
* You can only modify documents that have already been retrieved via
|
|
9985
10252
|
* `getEntry()/getEntries()` (enforced via IndexedDbs `apply()`).
|
|
9986
10253
|
*/
|
|
9987
|
-
addEntry(document
|
|
10254
|
+
addEntry(document) {
|
|
9988
10255
|
this.assertNotApplied();
|
|
9989
|
-
this.changes.set(document.key,
|
|
10256
|
+
this.changes.set(document.key, document);
|
|
9990
10257
|
}
|
|
9991
10258
|
/**
|
|
9992
10259
|
* Buffers a `RemoteDocumentCache.removeEntry()` call.
|
|
@@ -9994,12 +10261,9 @@ class RemoteDocumentChangeBuffer {
|
|
|
9994
10261
|
* You can only remove documents that have already been retrieved via
|
|
9995
10262
|
* `getEntry()/getEntries()` (enforced via IndexedDbs `apply()`).
|
|
9996
10263
|
*/
|
|
9997
|
-
removeEntry(key, readTime
|
|
10264
|
+
removeEntry(key, readTime) {
|
|
9998
10265
|
this.assertNotApplied();
|
|
9999
|
-
this.changes.set(key,
|
|
10000
|
-
document: MutableDocument.newInvalidDocument(key),
|
|
10001
|
-
readTime
|
|
10002
|
-
});
|
|
10266
|
+
this.changes.set(key, MutableDocument.newInvalidDocument(key).setReadTime(readTime));
|
|
10003
10267
|
}
|
|
10004
10268
|
/**
|
|
10005
10269
|
* Looks up an entry in the cache. The buffered changes will first be checked,
|
|
@@ -10016,7 +10280,7 @@ class RemoteDocumentChangeBuffer {
|
|
|
10016
10280
|
this.assertNotApplied();
|
|
10017
10281
|
const bufferedEntry = this.changes.get(documentKey);
|
|
10018
10282
|
if (bufferedEntry !== undefined) {
|
|
10019
|
-
return PersistencePromise.resolve(bufferedEntry
|
|
10283
|
+
return PersistencePromise.resolve(bufferedEntry);
|
|
10020
10284
|
}
|
|
10021
10285
|
else {
|
|
10022
10286
|
return this.getFromCache(transaction, documentKey);
|
|
@@ -10227,7 +10491,7 @@ class IndexedDbRemoteDocumentCacheImpl {
|
|
|
10227
10491
|
if (key.length !== immediateChildrenPathLength) {
|
|
10228
10492
|
return;
|
|
10229
10493
|
}
|
|
10230
|
-
const document =
|
|
10494
|
+
const document = this.maybeDecodeDocument(DocumentKey.fromSegments(key), dbRemoteDoc);
|
|
10231
10495
|
if (!query.path.isPrefixOf(document.key.path)) {
|
|
10232
10496
|
control.done();
|
|
10233
10497
|
}
|
|
@@ -10255,8 +10519,8 @@ class IndexedDbRemoteDocumentCacheImpl {
|
|
|
10255
10519
|
return documentGlobalStore(txn).put(DbRemoteDocumentGlobal.key, metadata);
|
|
10256
10520
|
}
|
|
10257
10521
|
/**
|
|
10258
|
-
* Decodes `
|
|
10259
|
-
* corresponds to the format used for sentinel deletes).
|
|
10522
|
+
* Decodes `dbRemoteDoc` and returns the document (or an invalid document if
|
|
10523
|
+
* the document corresponds to the format used for sentinel deletes).
|
|
10260
10524
|
*/
|
|
10261
10525
|
maybeDecodeDocument(documentKey, dbRemoteDoc) {
|
|
10262
10526
|
if (dbRemoteDoc) {
|
|
@@ -10350,8 +10614,8 @@ class IndexedDbRemoteDocumentChangeBuffer extends RemoteDocumentChangeBuffer {
|
|
|
10350
10614
|
let collectionParents = new SortedSet((l, r) => primitiveComparator(l.canonicalString(), r.canonicalString()));
|
|
10351
10615
|
this.changes.forEach((key, documentChange) => {
|
|
10352
10616
|
const previousSize = this.documentSizes.get(key);
|
|
10353
|
-
if (documentChange.
|
|
10354
|
-
const doc = toDbRemoteDocument(this.documentCache.serializer, documentChange
|
|
10617
|
+
if (documentChange.isValidDocument()) {
|
|
10618
|
+
const doc = toDbRemoteDocument(this.documentCache.serializer, documentChange);
|
|
10355
10619
|
collectionParents = collectionParents.add(key.path.popLast());
|
|
10356
10620
|
const size = dbDocumentSize(doc);
|
|
10357
10621
|
sizeDelta += size - previousSize;
|
|
@@ -10364,7 +10628,7 @@ class IndexedDbRemoteDocumentChangeBuffer extends RemoteDocumentChangeBuffer {
|
|
|
10364
10628
|
// RemoteDocumentCache. This entry is represented by a NoDocument
|
|
10365
10629
|
// with a version of 0 and ignored by `maybeDecodeDocument()` but
|
|
10366
10630
|
// preserved in `getNewDocumentChanges()`.
|
|
10367
|
-
const deletedDoc = toDbRemoteDocument(this.documentCache.serializer,
|
|
10631
|
+
const deletedDoc = toDbRemoteDocument(this.documentCache.serializer, documentChange.convertToNoDocument(SnapshotVersion.min()));
|
|
10368
10632
|
promises.push(this.documentCache.addEntry(transaction, key, deletedDoc));
|
|
10369
10633
|
}
|
|
10370
10634
|
else {
|
|
@@ -10445,9 +10709,6 @@ class SchemaConverter {
|
|
|
10445
10709
|
* and local feature development.
|
|
10446
10710
|
*/
|
|
10447
10711
|
createOrUpgrade(db, txn, fromVersion, toVersion) {
|
|
10448
|
-
hardAssert(fromVersion < toVersion &&
|
|
10449
|
-
fromVersion >= 0 &&
|
|
10450
|
-
toVersion <= SCHEMA_VERSION);
|
|
10451
10712
|
const simpleDbTransaction = new SimpleDbTransaction('createOrUpgrade', txn);
|
|
10452
10713
|
if (fromVersion < 1 && toVersion >= 1) {
|
|
10453
10714
|
createPrimaryClientStore(db);
|
|
@@ -10514,6 +10775,11 @@ class SchemaConverter {
|
|
|
10514
10775
|
createNamedQueriesStore(db);
|
|
10515
10776
|
});
|
|
10516
10777
|
}
|
|
10778
|
+
if (fromVersion < 12 && toVersion >= 12) {
|
|
10779
|
+
p = p.next(() => {
|
|
10780
|
+
createFieldIndex(db);
|
|
10781
|
+
});
|
|
10782
|
+
}
|
|
10517
10783
|
return p;
|
|
10518
10784
|
}
|
|
10519
10785
|
addDocumentGlobal(txn) {
|
|
@@ -10720,6 +10986,17 @@ function createNamedQueriesStore(db) {
|
|
|
10720
10986
|
db.createObjectStore(DbNamedQuery.store, {
|
|
10721
10987
|
keyPath: DbNamedQuery.keyPath
|
|
10722
10988
|
});
|
|
10989
|
+
}
|
|
10990
|
+
function createFieldIndex(db) {
|
|
10991
|
+
db.createObjectStore(DbIndexConfiguration.store, {
|
|
10992
|
+
keyPath: DbIndexConfiguration.keyPath
|
|
10993
|
+
});
|
|
10994
|
+
db.createObjectStore(DbIndexState.store, {
|
|
10995
|
+
keyPath: DbIndexState.keyPath
|
|
10996
|
+
});
|
|
10997
|
+
db.createObjectStore(DbIndexEntries.store, {
|
|
10998
|
+
keyPath: DbIndexEntries.keyPath
|
|
10999
|
+
});
|
|
10723
11000
|
}
|
|
10724
11001
|
|
|
10725
11002
|
/**
|
|
@@ -11951,14 +12228,14 @@ function localStoreApplyRemoteEventToLocalCache(localStore, remoteEvent) {
|
|
|
11951
12228
|
}
|
|
11952
12229
|
});
|
|
11953
12230
|
let changedDocs = mutableDocumentMap();
|
|
11954
|
-
remoteEvent.documentUpdates.forEach(
|
|
12231
|
+
remoteEvent.documentUpdates.forEach(key => {
|
|
11955
12232
|
if (remoteEvent.resolvedLimboDocuments.has(key)) {
|
|
11956
12233
|
promises.push(localStoreImpl.persistence.referenceDelegate.updateLimboDocument(txn, key));
|
|
11957
12234
|
}
|
|
11958
12235
|
});
|
|
11959
12236
|
// Each loop iteration only affects its "own" doc, so it's safe to get all the remote
|
|
11960
12237
|
// documents in advance in a single call.
|
|
11961
|
-
promises.push(populateDocumentChangeBuffer(txn, documentBuffer, remoteEvent.documentUpdates
|
|
12238
|
+
promises.push(populateDocumentChangeBuffer(txn, documentBuffer, remoteEvent.documentUpdates).next(result => {
|
|
11962
12239
|
changedDocs = result;
|
|
11963
12240
|
}));
|
|
11964
12241
|
// HACK: The only reason we allow a null snapshot version is so that we
|
|
@@ -11999,17 +12276,13 @@ function localStoreApplyRemoteEventToLocalCache(localStore, remoteEvent) {
|
|
|
11999
12276
|
* Note: this function will use `documentVersions` if it is defined;
|
|
12000
12277
|
* when it is not defined, resorts to `globalVersion`.
|
|
12001
12278
|
*/
|
|
12002
|
-
function populateDocumentChangeBuffer(txn, documentBuffer, documents
|
|
12003
|
-
// TODO(wuandy): We could add `readTime` to MaybeDocument instead to remove
|
|
12004
|
-
// this parameter.
|
|
12005
|
-
documentVersions) {
|
|
12279
|
+
function populateDocumentChangeBuffer(txn, documentBuffer, documents) {
|
|
12006
12280
|
let updatedKeys = documentKeySet();
|
|
12007
12281
|
documents.forEach(k => (updatedKeys = updatedKeys.add(k)));
|
|
12008
12282
|
return documentBuffer.getEntries(txn, updatedKeys).next(existingDocs => {
|
|
12009
12283
|
let changedDocs = mutableDocumentMap();
|
|
12010
12284
|
documents.forEach((key, doc) => {
|
|
12011
12285
|
const existingDoc = existingDocs.get(key);
|
|
12012
|
-
const docReadTime = (documentVersions === null || documentVersions === void 0 ? void 0 : documentVersions.get(key)) || globalVersion;
|
|
12013
12286
|
// Note: The order of the steps below is important, since we want
|
|
12014
12287
|
// to ensure that rejected limbo resolutions (which fabricate
|
|
12015
12288
|
// NoDocuments with SnapshotVersion.min()) never add documents to
|
|
@@ -12018,14 +12291,14 @@ documentVersions) {
|
|
|
12018
12291
|
// NoDocuments with SnapshotVersion.min() are used in manufactured
|
|
12019
12292
|
// events. We remove these documents from cache since we lost
|
|
12020
12293
|
// access.
|
|
12021
|
-
documentBuffer.removeEntry(key,
|
|
12294
|
+
documentBuffer.removeEntry(key, doc.readTime);
|
|
12022
12295
|
changedDocs = changedDocs.insert(key, doc);
|
|
12023
12296
|
}
|
|
12024
12297
|
else if (!existingDoc.isValidDocument() ||
|
|
12025
12298
|
doc.version.compareTo(existingDoc.version) > 0 ||
|
|
12026
12299
|
(doc.version.compareTo(existingDoc.version) === 0 &&
|
|
12027
12300
|
existingDoc.hasPendingWrites)) {
|
|
12028
|
-
documentBuffer.addEntry(doc
|
|
12301
|
+
documentBuffer.addEntry(doc);
|
|
12029
12302
|
changedDocs = changedDocs.insert(key, doc);
|
|
12030
12303
|
}
|
|
12031
12304
|
else {
|
|
@@ -12279,7 +12552,8 @@ function applyWriteToRemoteDocuments(localStoreImpl, txn, batchResult, documentB
|
|
|
12279
12552
|
// We use the commitVersion as the readTime rather than the
|
|
12280
12553
|
// document's updateTime since the updateTime is not advanced
|
|
12281
12554
|
// for updates that do not modify the underlying document.
|
|
12282
|
-
|
|
12555
|
+
doc.setReadTime(batchResult.commitVersion);
|
|
12556
|
+
documentBuffer.addEntry(doc);
|
|
12283
12557
|
}
|
|
12284
12558
|
}
|
|
12285
12559
|
});
|
|
@@ -12380,14 +12654,14 @@ async function localStoreApplyBundledDocuments(localStore, bundleConverter, docu
|
|
|
12380
12654
|
const localStoreImpl = debugCast(localStore);
|
|
12381
12655
|
let documentKeys = documentKeySet();
|
|
12382
12656
|
let documentMap = mutableDocumentMap();
|
|
12383
|
-
let versionMap = documentVersionMap();
|
|
12384
12657
|
for (const bundleDoc of documents) {
|
|
12385
12658
|
const documentKey = bundleConverter.toDocumentKey(bundleDoc.metadata.name);
|
|
12386
12659
|
if (bundleDoc.document) {
|
|
12387
12660
|
documentKeys = documentKeys.add(documentKey);
|
|
12388
12661
|
}
|
|
12389
|
-
|
|
12390
|
-
|
|
12662
|
+
const doc = bundleConverter.toMutableDocument(bundleDoc);
|
|
12663
|
+
doc.setReadTime(bundleConverter.toSnapshotVersion(bundleDoc.metadata.readTime));
|
|
12664
|
+
documentMap = documentMap.insert(documentKey, doc);
|
|
12391
12665
|
}
|
|
12392
12666
|
const documentBuffer = localStoreImpl.remoteDocuments.newChangeBuffer({
|
|
12393
12667
|
trackRemovals: true // Make sure document removals show up in `getNewDocumentChanges()`
|
|
@@ -12396,7 +12670,7 @@ async function localStoreApplyBundledDocuments(localStore, bundleConverter, docu
|
|
|
12396
12670
|
// they will not get garbage collected right away.
|
|
12397
12671
|
const umbrellaTargetData = await localStoreAllocateTarget(localStoreImpl, umbrellaTarget(bundleName));
|
|
12398
12672
|
return localStoreImpl.persistence.runTransaction('Apply bundle documents', 'readwrite', txn => {
|
|
12399
|
-
return populateDocumentChangeBuffer(txn, documentBuffer, documentMap
|
|
12673
|
+
return populateDocumentChangeBuffer(txn, documentBuffer, documentMap)
|
|
12400
12674
|
.next(changedDocs => {
|
|
12401
12675
|
documentBuffer.apply(txn);
|
|
12402
12676
|
return changedDocs;
|
|
@@ -12877,15 +13151,14 @@ class MemoryRemoteDocumentCacheImpl {
|
|
|
12877
13151
|
* All calls of `addEntry` are required to go through the RemoteDocumentChangeBuffer
|
|
12878
13152
|
* returned by `newChangeBuffer()`.
|
|
12879
13153
|
*/
|
|
12880
|
-
addEntry(transaction, doc
|
|
13154
|
+
addEntry(transaction, doc) {
|
|
12881
13155
|
const key = doc.key;
|
|
12882
13156
|
const entry = this.docs.get(key);
|
|
12883
13157
|
const previousSize = entry ? entry.size : 0;
|
|
12884
13158
|
const currentSize = this.sizer(doc);
|
|
12885
13159
|
this.docs = this.docs.insert(key, {
|
|
12886
13160
|
document: doc.mutableCopy(),
|
|
12887
|
-
size: currentSize
|
|
12888
|
-
readTime
|
|
13161
|
+
size: currentSize
|
|
12889
13162
|
});
|
|
12890
13163
|
this.size += currentSize - previousSize;
|
|
12891
13164
|
return this.indexManager.addToCollectionParentIndex(transaction, key.path.popLast());
|
|
@@ -12926,11 +13199,11 @@ class MemoryRemoteDocumentCacheImpl {
|
|
|
12926
13199
|
const prefix = new DocumentKey(query.path.child(''));
|
|
12927
13200
|
const iterator = this.docs.getIteratorFrom(prefix);
|
|
12928
13201
|
while (iterator.hasNext()) {
|
|
12929
|
-
const { key, value: { document
|
|
13202
|
+
const { key, value: { document } } = iterator.getNext();
|
|
12930
13203
|
if (!query.path.isPrefixOf(key.path)) {
|
|
12931
13204
|
break;
|
|
12932
13205
|
}
|
|
12933
|
-
if (readTime.compareTo(sinceReadTime) <= 0) {
|
|
13206
|
+
if (document.readTime.compareTo(sinceReadTime) <= 0) {
|
|
12934
13207
|
continue;
|
|
12935
13208
|
}
|
|
12936
13209
|
if (!queryMatches(query, document)) {
|
|
@@ -12974,8 +13247,8 @@ class MemoryRemoteDocumentChangeBuffer extends RemoteDocumentChangeBuffer {
|
|
|
12974
13247
|
applyChanges(transaction) {
|
|
12975
13248
|
const promises = [];
|
|
12976
13249
|
this.changes.forEach((key, doc) => {
|
|
12977
|
-
if (doc.
|
|
12978
|
-
promises.push(this.documentCache.addEntry(transaction, doc
|
|
13250
|
+
if (doc.isValidDocument()) {
|
|
13251
|
+
promises.push(this.documentCache.addEntry(transaction, doc));
|
|
12979
13252
|
}
|
|
12980
13253
|
else {
|
|
12981
13254
|
this.documentCache.removeEntry(key);
|
|
@@ -13288,7 +13561,7 @@ class MemoryEagerDelegate {
|
|
|
13288
13561
|
const key = DocumentKey.fromPath(path);
|
|
13289
13562
|
return this.isReferenced(txn, key).next(isReferenced => {
|
|
13290
13563
|
if (!isReferenced) {
|
|
13291
|
-
changeBuffer.removeEntry(key);
|
|
13564
|
+
changeBuffer.removeEntry(key, SnapshotVersion.min());
|
|
13292
13565
|
}
|
|
13293
13566
|
});
|
|
13294
13567
|
}).next(() => {
|
|
@@ -17068,6 +17341,40 @@ const nested = {
|
|
|
17068
17341
|
id: 2
|
|
17069
17342
|
}
|
|
17070
17343
|
}
|
|
17344
|
+
},
|
|
17345
|
+
methodSignature: {
|
|
17346
|
+
rule: "repeated",
|
|
17347
|
+
type: "string",
|
|
17348
|
+
id: 1051,
|
|
17349
|
+
extend: "google.protobuf.MethodOptions"
|
|
17350
|
+
},
|
|
17351
|
+
defaultHost: {
|
|
17352
|
+
type: "string",
|
|
17353
|
+
id: 1049,
|
|
17354
|
+
extend: "google.protobuf.ServiceOptions"
|
|
17355
|
+
},
|
|
17356
|
+
oauthScopes: {
|
|
17357
|
+
type: "string",
|
|
17358
|
+
id: 1050,
|
|
17359
|
+
extend: "google.protobuf.ServiceOptions"
|
|
17360
|
+
},
|
|
17361
|
+
fieldBehavior: {
|
|
17362
|
+
rule: "repeated",
|
|
17363
|
+
type: "google.api.FieldBehavior",
|
|
17364
|
+
id: 1052,
|
|
17365
|
+
extend: "google.protobuf.FieldOptions"
|
|
17366
|
+
},
|
|
17367
|
+
FieldBehavior: {
|
|
17368
|
+
values: {
|
|
17369
|
+
FIELD_BEHAVIOR_UNSPECIFIED: 0,
|
|
17370
|
+
OPTIONAL: 1,
|
|
17371
|
+
REQUIRED: 2,
|
|
17372
|
+
OUTPUT_ONLY: 3,
|
|
17373
|
+
INPUT_ONLY: 4,
|
|
17374
|
+
IMMUTABLE: 5,
|
|
17375
|
+
UNORDERED_LIST: 6,
|
|
17376
|
+
NON_EMPTY_DEFAULT: 7
|
|
17377
|
+
}
|
|
17071
17378
|
}
|
|
17072
17379
|
}
|
|
17073
17380
|
},
|
|
@@ -20311,6 +20618,9 @@ async function syncEngineRejectListen(syncEngine, targetId, err) {
|
|
|
20311
20618
|
// store to purge a document. However, it would be tricky to keep all of
|
|
20312
20619
|
// the local store's invariants with another method.
|
|
20313
20620
|
let documentUpdates = new SortedMap(DocumentKey.comparator);
|
|
20621
|
+
// TODO(b/217189216): This limbo document should ideally have a read time,
|
|
20622
|
+
// so that it is picked up by any read-time based scans. The backend,
|
|
20623
|
+
// however, does not send a read time for target removals.
|
|
20314
20624
|
documentUpdates = documentUpdates.insert(limboKey, MutableDocument.newNoDocument(limboKey, SnapshotVersion.min()));
|
|
20315
20625
|
const resolvedLimboDocuments = documentKeySet().add(limboKey);
|
|
20316
20626
|
const event = new RemoteEvent(SnapshotVersion.min(),
|
|
@@ -22255,72 +22565,6 @@ function createBundleReader(data, serializer) {
|
|
|
22255
22565
|
return newBundleReader(toByteStreamReader(content), serializer);
|
|
22256
22566
|
}
|
|
22257
22567
|
|
|
22258
|
-
/**
|
|
22259
|
-
* @license
|
|
22260
|
-
* Copyright 2017 Google LLC
|
|
22261
|
-
*
|
|
22262
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
22263
|
-
* you may not use this file except in compliance with the License.
|
|
22264
|
-
* You may obtain a copy of the License at
|
|
22265
|
-
*
|
|
22266
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
22267
|
-
*
|
|
22268
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
22269
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
22270
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
22271
|
-
* See the License for the specific language governing permissions and
|
|
22272
|
-
* limitations under the License.
|
|
22273
|
-
*/
|
|
22274
|
-
class DatabaseInfo {
|
|
22275
|
-
/**
|
|
22276
|
-
* Constructs a DatabaseInfo using the provided host, databaseId and
|
|
22277
|
-
* persistenceKey.
|
|
22278
|
-
*
|
|
22279
|
-
* @param databaseId - The database to use.
|
|
22280
|
-
* @param appId - The Firebase App Id.
|
|
22281
|
-
* @param persistenceKey - A unique identifier for this Firestore's local
|
|
22282
|
-
* storage (used in conjunction with the databaseId).
|
|
22283
|
-
* @param host - The Firestore backend host to connect to.
|
|
22284
|
-
* @param ssl - Whether to use SSL when connecting.
|
|
22285
|
-
* @param forceLongPolling - Whether to use the forceLongPolling option
|
|
22286
|
-
* when using WebChannel as the network transport.
|
|
22287
|
-
* @param autoDetectLongPolling - Whether to use the detectBufferingProxy
|
|
22288
|
-
* option when using WebChannel as the network transport.
|
|
22289
|
-
* @param useFetchStreams Whether to use the Fetch API instead of
|
|
22290
|
-
* XMLHTTPRequest
|
|
22291
|
-
*/
|
|
22292
|
-
constructor(databaseId, appId, persistenceKey, host, ssl, forceLongPolling, autoDetectLongPolling, useFetchStreams) {
|
|
22293
|
-
this.databaseId = databaseId;
|
|
22294
|
-
this.appId = appId;
|
|
22295
|
-
this.persistenceKey = persistenceKey;
|
|
22296
|
-
this.host = host;
|
|
22297
|
-
this.ssl = ssl;
|
|
22298
|
-
this.forceLongPolling = forceLongPolling;
|
|
22299
|
-
this.autoDetectLongPolling = autoDetectLongPolling;
|
|
22300
|
-
this.useFetchStreams = useFetchStreams;
|
|
22301
|
-
}
|
|
22302
|
-
}
|
|
22303
|
-
/** The default database name for a project. */
|
|
22304
|
-
const DEFAULT_DATABASE_NAME = '(default)';
|
|
22305
|
-
/**
|
|
22306
|
-
* Represents the database ID a Firestore client is associated with.
|
|
22307
|
-
* @internal
|
|
22308
|
-
*/
|
|
22309
|
-
class DatabaseId {
|
|
22310
|
-
constructor(projectId, database) {
|
|
22311
|
-
this.projectId = projectId;
|
|
22312
|
-
this.database = database ? database : DEFAULT_DATABASE_NAME;
|
|
22313
|
-
}
|
|
22314
|
-
get isDefaultDatabase() {
|
|
22315
|
-
return this.database === DEFAULT_DATABASE_NAME;
|
|
22316
|
-
}
|
|
22317
|
-
isEqual(other) {
|
|
22318
|
-
return (other instanceof DatabaseId &&
|
|
22319
|
-
other.projectId === this.projectId &&
|
|
22320
|
-
other.database === this.database);
|
|
22321
|
-
}
|
|
22322
|
-
}
|
|
22323
|
-
|
|
22324
22568
|
/**
|
|
22325
22569
|
* @license
|
|
22326
22570
|
* Copyright 2020 Google LLC
|
|
@@ -26234,17 +26478,6 @@ function writeBatch(firestore) {
|
|
|
26234
26478
|
ensureFirestoreConfigured(firestore);
|
|
26235
26479
|
return new WriteBatch(firestore, mutations => executeWrite(firestore, mutations));
|
|
26236
26480
|
}
|
|
26237
|
-
/** An index component consisting of field path and index type. */
|
|
26238
|
-
class Segment {
|
|
26239
|
-
constructor(
|
|
26240
|
-
/** The field path of the component. */
|
|
26241
|
-
fieldPath,
|
|
26242
|
-
/** The fields sorting order. */
|
|
26243
|
-
kind) {
|
|
26244
|
-
this.fieldPath = fieldPath;
|
|
26245
|
-
this.kind = kind;
|
|
26246
|
-
}
|
|
26247
|
-
}
|
|
26248
26481
|
|
|
26249
26482
|
/**
|
|
26250
26483
|
* @license
|
|
@@ -26268,27 +26501,29 @@ function setIndexConfiguration(firestore, jsonOrConfiguration) {
|
|
|
26268
26501
|
const indexConfiguration = typeof jsonOrConfiguration === 'string'
|
|
26269
26502
|
? tryParseJson(jsonOrConfiguration)
|
|
26270
26503
|
: jsonOrConfiguration;
|
|
26504
|
+
const parsedIndexes = [];
|
|
26271
26505
|
// PORTING NOTE: We don't return an error if the user has not enabled
|
|
26272
26506
|
// persistence since `enableIndexeddbPersistence()` can fail on the Web.
|
|
26273
26507
|
if (Array.isArray(indexConfiguration.indexes)) {
|
|
26274
26508
|
for (const index of indexConfiguration.indexes) {
|
|
26275
|
-
tryGetString(index, 'collectionGroup');
|
|
26509
|
+
const collectionGroup = tryGetString(index, 'collectionGroup');
|
|
26276
26510
|
const segments = [];
|
|
26277
26511
|
if (Array.isArray(index.fields)) {
|
|
26278
26512
|
for (const field of index.fields) {
|
|
26279
26513
|
const fieldPathString = tryGetString(field, 'fieldPath');
|
|
26280
26514
|
const fieldPath = fieldPathFromDotSeparatedString('setIndexConfiguration', fieldPathString);
|
|
26281
26515
|
if (field.arrayConfig === 'CONTAINS') {
|
|
26282
|
-
segments.push(new
|
|
26516
|
+
segments.push(new IndexSegment(fieldPath, 2 /* CONTAINS */));
|
|
26283
26517
|
}
|
|
26284
26518
|
else if (field.order === 'ASCENDING') {
|
|
26285
|
-
segments.push(new
|
|
26519
|
+
segments.push(new IndexSegment(fieldPath, 0 /* ASCENDING */));
|
|
26286
26520
|
}
|
|
26287
26521
|
else if (field.order === 'DESCENDING') {
|
|
26288
|
-
segments.push(new
|
|
26522
|
+
segments.push(new IndexSegment(fieldPath, 1 /* DESCENDING */));
|
|
26289
26523
|
}
|
|
26290
26524
|
}
|
|
26291
26525
|
}
|
|
26526
|
+
parsedIndexes.push(new FieldIndex(FieldIndex.UNKNOWN_ID, collectionGroup, segments, IndexState.empty()));
|
|
26292
26527
|
}
|
|
26293
26528
|
}
|
|
26294
26529
|
// TODO(indexing): Configure indexes
|