@firebase/firestore 3.4.5-canary.2b98b28f2 → 3.4.5-canary.2d672cead
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/document_overlay_cache.d.ts +4 -5
- package/dist/firestore/src/local/indexeddb_document_overlay_cache.d.ts +4 -5
- package/dist/firestore/src/local/indexeddb_index_manager.d.ts +1 -1
- package/dist/firestore/src/local/indexeddb_schema.d.ts +34 -553
- package/dist/firestore/src/local/indexeddb_sentinels.d.ts +238 -0
- package/dist/firestore/src/local/indexeddb_target_cache.d.ts +2 -1
- package/dist/firestore/src/local/local_serializer.d.ts +2 -1
- package/dist/firestore/src/local/memory_document_overlay_cache.d.ts +4 -5
- package/dist/firestore/src/model/collections.d.ts +7 -0
- package/dist/firestore/src/util/obj_map.d.ts +3 -0
- package/dist/firestore/test/unit/local/test_document_overlay_cache.d.ts +4 -4
- package/dist/index.esm2017.js +3143 -3655
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.esm5.js +3305 -3756
- package/dist/index.esm5.js.map +1 -1
- package/dist/index.node.cjs.js +483 -929
- package/dist/index.node.cjs.js.map +1 -1
- package/dist/index.node.mjs +483 -929
- package/dist/index.node.mjs.map +1 -1
- package/dist/index.rn.js +3168 -3680
- package/dist/index.rn.js.map +1 -1
- package/dist/internal.d.ts +10 -3
- package/dist/lite/firestore/src/local/document_overlay_cache.d.ts +4 -5
- package/dist/lite/firestore/src/local/indexeddb_document_overlay_cache.d.ts +4 -5
- package/dist/lite/firestore/src/local/indexeddb_index_manager.d.ts +1 -1
- package/dist/lite/firestore/src/local/indexeddb_schema.d.ts +34 -553
- package/dist/lite/firestore/src/local/indexeddb_sentinels.d.ts +238 -0
- package/dist/lite/firestore/src/local/indexeddb_target_cache.d.ts +2 -1
- package/dist/lite/firestore/src/local/local_serializer.d.ts +2 -1
- package/dist/lite/firestore/src/local/memory_document_overlay_cache.d.ts +4 -5
- package/dist/lite/firestore/src/model/collections.d.ts +7 -0
- package/dist/lite/firestore/src/util/obj_map.d.ts +3 -0
- package/dist/lite/firestore/test/unit/local/test_document_overlay_cache.d.ts +4 -4
- package/dist/lite/index.browser.esm2017.js +72 -72
- package/dist/lite/index.browser.esm2017.js.map +1 -1
- package/dist/lite/index.browser.esm5.js +8 -8
- package/dist/lite/index.node.cjs.js +2 -2
- package/dist/lite/index.node.mjs +2 -2
- package/dist/lite/index.node.mjs.map +1 -1
- package/dist/lite/index.rn.esm2017.js +83 -83
- package/dist/lite/packages/firestore/dist/lite/index.browser.esm2017.d.ts +18 -18
- package/dist/lite/packages/firestore/src/local/document_overlay_cache.d.ts +4 -5
- package/dist/lite/packages/firestore/src/local/indexeddb_document_overlay_cache.d.ts +4 -5
- package/dist/lite/packages/firestore/src/local/indexeddb_index_manager.d.ts +1 -1
- package/dist/lite/packages/firestore/src/local/indexeddb_schema.d.ts +34 -553
- package/dist/lite/packages/firestore/src/local/indexeddb_sentinels.d.ts +238 -0
- package/dist/lite/packages/firestore/src/local/indexeddb_target_cache.d.ts +2 -1
- package/dist/lite/packages/firestore/src/local/local_serializer.d.ts +2 -1
- package/dist/lite/packages/firestore/src/local/memory_document_overlay_cache.d.ts +4 -5
- package/dist/lite/packages/firestore/src/model/collections.d.ts +7 -0
- package/dist/lite/packages/firestore/src/util/obj_map.d.ts +3 -0
- package/dist/lite/packages/firestore/test/unit/local/test_document_overlay_cache.d.ts +4 -4
- package/dist/packages/firestore/dist/index.esm2017.d.ts +163 -163
- package/dist/packages/firestore/src/local/document_overlay_cache.d.ts +4 -5
- package/dist/packages/firestore/src/local/indexeddb_document_overlay_cache.d.ts +4 -5
- package/dist/packages/firestore/src/local/indexeddb_index_manager.d.ts +1 -1
- package/dist/packages/firestore/src/local/indexeddb_schema.d.ts +34 -553
- package/dist/packages/firestore/src/local/indexeddb_sentinels.d.ts +238 -0
- package/dist/packages/firestore/src/local/indexeddb_target_cache.d.ts +2 -1
- package/dist/packages/firestore/src/local/local_serializer.d.ts +2 -1
- package/dist/packages/firestore/src/local/memory_document_overlay_cache.d.ts +4 -5
- package/dist/packages/firestore/src/model/collections.d.ts +7 -0
- package/dist/packages/firestore/src/util/obj_map.d.ts +3 -0
- package/dist/packages/firestore/test/unit/local/test_document_overlay_cache.d.ts +4 -4
- package/dist/private.d.ts +10 -3
- package/package.json +9 -9
package/dist/index.node.mjs
CHANGED
|
@@ -8,7 +8,7 @@ import * as grpc from '@grpc/grpc-js';
|
|
|
8
8
|
import * as protoLoader from '@grpc/proto-loader';
|
|
9
9
|
|
|
10
10
|
const name = "@firebase/firestore";
|
|
11
|
-
const version$1 = "3.4.5-canary.
|
|
11
|
+
const version$1 = "3.4.5-canary.2d672cead";
|
|
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.7-canary.
|
|
64
|
+
const version = "9.6.7-canary.2d672cead";
|
|
65
65
|
|
|
66
66
|
/**
|
|
67
67
|
* @license
|
|
@@ -1199,55 +1199,23 @@ function decodeResourcePath(path) {
|
|
|
1199
1199
|
}
|
|
1200
1200
|
return new ResourcePath(segments);
|
|
1201
1201
|
}
|
|
1202
|
+
|
|
1202
1203
|
/**
|
|
1203
|
-
*
|
|
1204
|
-
*
|
|
1205
|
-
*
|
|
1206
|
-
*
|
|
1207
|
-
*
|
|
1208
|
-
*
|
|
1209
|
-
*
|
|
1210
|
-
*
|
|
1211
|
-
* 4. Multi-Tab Support.
|
|
1212
|
-
* 5. Removal of held write acks.
|
|
1213
|
-
* 6. Create document global for tracking document cache size.
|
|
1214
|
-
* 7. Ensure every cached document has a sentinel row with a sequence number.
|
|
1215
|
-
* 8. Add collection-parent index for Collection Group queries.
|
|
1216
|
-
* 9. Change RemoteDocumentChanges store to be keyed by readTime rather than
|
|
1217
|
-
* an auto-incrementing ID. This is required for Index-Free queries.
|
|
1218
|
-
* 10. Rewrite the canonical IDs to the explicit Protobuf-based format.
|
|
1219
|
-
* 11. Add bundles and named_queries for bundle support.
|
|
1220
|
-
* 12. Add document overlays.
|
|
1221
|
-
* 13. Add indexing support.
|
|
1222
|
-
*/
|
|
1223
|
-
const SCHEMA_VERSION = 12;
|
|
1224
|
-
/**
|
|
1225
|
-
* Wrapper class to store timestamps (seconds and nanos) in IndexedDb objects.
|
|
1226
|
-
*/
|
|
1227
|
-
class DbTimestamp {
|
|
1228
|
-
constructor(seconds, nanoseconds) {
|
|
1229
|
-
this.seconds = seconds;
|
|
1230
|
-
this.nanoseconds = nanoseconds;
|
|
1231
|
-
}
|
|
1232
|
-
}
|
|
1233
|
-
/**
|
|
1234
|
-
* A singleton object to be stored in the 'owner' store in IndexedDb.
|
|
1204
|
+
* @license
|
|
1205
|
+
* Copyright 2022 Google LLC
|
|
1206
|
+
*
|
|
1207
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1208
|
+
* you may not use this file except in compliance with the License.
|
|
1209
|
+
* You may obtain a copy of the License at
|
|
1210
|
+
*
|
|
1211
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1235
1212
|
*
|
|
1236
|
-
*
|
|
1237
|
-
*
|
|
1238
|
-
*
|
|
1239
|
-
*
|
|
1240
|
-
*
|
|
1213
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
1214
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1215
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1216
|
+
* See the License for the specific language governing permissions and
|
|
1217
|
+
* limitations under the License.
|
|
1241
1218
|
*/
|
|
1242
|
-
class DbPrimaryClient {
|
|
1243
|
-
constructor(ownerId,
|
|
1244
|
-
/** Whether to allow shared access from multiple tabs. */
|
|
1245
|
-
allowTabSynchronization, leaseTimestampMs) {
|
|
1246
|
-
this.ownerId = ownerId;
|
|
1247
|
-
this.allowTabSynchronization = allowTabSynchronization;
|
|
1248
|
-
this.leaseTimestampMs = leaseTimestampMs;
|
|
1249
|
-
}
|
|
1250
|
-
}
|
|
1251
1219
|
/**
|
|
1252
1220
|
* Name of the IndexedDb object store.
|
|
1253
1221
|
*
|
|
@@ -1255,239 +1223,62 @@ class DbPrimaryClient {
|
|
|
1255
1223
|
* older clients that only supported single locked access to the persistence
|
|
1256
1224
|
* layer.
|
|
1257
1225
|
*/
|
|
1258
|
-
|
|
1226
|
+
const DbPrimaryClientStore = 'owner';
|
|
1259
1227
|
/**
|
|
1260
1228
|
* The key string used for the single object that exists in the
|
|
1261
1229
|
* DbPrimaryClient store.
|
|
1262
1230
|
*/
|
|
1263
|
-
|
|
1264
|
-
/**
|
|
1265
|
-
* An object to be stored in the 'mutationQueues' store in IndexedDb.
|
|
1266
|
-
*
|
|
1267
|
-
* Each user gets a single queue of MutationBatches to apply to the server.
|
|
1268
|
-
* DbMutationQueue tracks the metadata about the queue.
|
|
1269
|
-
*/
|
|
1270
|
-
class DbMutationQueue {
|
|
1271
|
-
constructor(
|
|
1272
|
-
/**
|
|
1273
|
-
* The normalized user ID to which this queue belongs.
|
|
1274
|
-
*/
|
|
1275
|
-
userId,
|
|
1276
|
-
/**
|
|
1277
|
-
* An identifier for the highest numbered batch that has been acknowledged
|
|
1278
|
-
* by the server. All MutationBatches in this queue with batchIds less
|
|
1279
|
-
* than or equal to this value are considered to have been acknowledged by
|
|
1280
|
-
* the server.
|
|
1281
|
-
*
|
|
1282
|
-
* NOTE: this is deprecated and no longer used by the code.
|
|
1283
|
-
*/
|
|
1284
|
-
lastAcknowledgedBatchId,
|
|
1285
|
-
/**
|
|
1286
|
-
* A stream token that was previously sent by the server.
|
|
1287
|
-
*
|
|
1288
|
-
* See StreamingWriteRequest in datastore.proto for more details about
|
|
1289
|
-
* usage.
|
|
1290
|
-
*
|
|
1291
|
-
* After sending this token, earlier tokens may not be used anymore so
|
|
1292
|
-
* only a single stream token is retained.
|
|
1293
|
-
*
|
|
1294
|
-
* NOTE: this is deprecated and no longer used by the code.
|
|
1295
|
-
*/
|
|
1296
|
-
lastStreamToken) {
|
|
1297
|
-
this.userId = userId;
|
|
1298
|
-
this.lastAcknowledgedBatchId = lastAcknowledgedBatchId;
|
|
1299
|
-
this.lastStreamToken = lastStreamToken;
|
|
1300
|
-
}
|
|
1301
|
-
}
|
|
1231
|
+
const DbPrimaryClientKey = 'owner';
|
|
1302
1232
|
/** Name of the IndexedDb object store. */
|
|
1303
|
-
|
|
1233
|
+
const DbMutationQueueStore = 'mutationQueues';
|
|
1304
1234
|
/** Keys are automatically assigned via the userId property. */
|
|
1305
|
-
|
|
1306
|
-
/**
|
|
1307
|
-
* An object to be stored in the 'mutations' store in IndexedDb.
|
|
1308
|
-
*
|
|
1309
|
-
* Represents a batch of user-level mutations intended to be sent to the server
|
|
1310
|
-
* in a single write. Each user-level batch gets a separate DbMutationBatch
|
|
1311
|
-
* with a new batchId.
|
|
1312
|
-
*/
|
|
1313
|
-
class DbMutationBatch {
|
|
1314
|
-
constructor(
|
|
1315
|
-
/**
|
|
1316
|
-
* The normalized user ID to which this batch belongs.
|
|
1317
|
-
*/
|
|
1318
|
-
userId,
|
|
1319
|
-
/**
|
|
1320
|
-
* An identifier for this batch, allocated using an auto-generated key.
|
|
1321
|
-
*/
|
|
1322
|
-
batchId,
|
|
1323
|
-
/**
|
|
1324
|
-
* The local write time of the batch, stored as milliseconds since the
|
|
1325
|
-
* epoch.
|
|
1326
|
-
*/
|
|
1327
|
-
localWriteTimeMs,
|
|
1328
|
-
/**
|
|
1329
|
-
* A list of "mutations" that represent a partial base state from when this
|
|
1330
|
-
* write batch was initially created. During local application of the write
|
|
1331
|
-
* batch, these baseMutations are applied prior to the real writes in order
|
|
1332
|
-
* to override certain document fields from the remote document cache. This
|
|
1333
|
-
* is necessary in the case of non-idempotent writes (e.g. `increment()`
|
|
1334
|
-
* transforms) to make sure that the local view of the modified documents
|
|
1335
|
-
* doesn't flicker if the remote document cache receives the result of the
|
|
1336
|
-
* non-idempotent write before the write is removed from the queue.
|
|
1337
|
-
*
|
|
1338
|
-
* These mutations are never sent to the backend.
|
|
1339
|
-
*/
|
|
1340
|
-
baseMutations,
|
|
1341
|
-
/**
|
|
1342
|
-
* A list of mutations to apply. All mutations will be applied atomically.
|
|
1343
|
-
*
|
|
1344
|
-
* Mutations are serialized via toMutation().
|
|
1345
|
-
*/
|
|
1346
|
-
mutations) {
|
|
1347
|
-
this.userId = userId;
|
|
1348
|
-
this.batchId = batchId;
|
|
1349
|
-
this.localWriteTimeMs = localWriteTimeMs;
|
|
1350
|
-
this.baseMutations = baseMutations;
|
|
1351
|
-
this.mutations = mutations;
|
|
1352
|
-
}
|
|
1353
|
-
}
|
|
1235
|
+
const DbMutationQueueKeyPath = 'userId';
|
|
1354
1236
|
/** Name of the IndexedDb object store. */
|
|
1355
|
-
|
|
1237
|
+
const DbMutationBatchStore = 'mutations';
|
|
1356
1238
|
/** Keys are automatically assigned via the userId, batchId properties. */
|
|
1357
|
-
|
|
1239
|
+
const DbMutationBatchKeyPath = 'batchId';
|
|
1358
1240
|
/** The index name for lookup of mutations by user. */
|
|
1359
|
-
|
|
1241
|
+
const DbMutationBatchUserMutationsIndex = 'userMutationsIndex';
|
|
1360
1242
|
/** The user mutations index is keyed by [userId, batchId] pairs. */
|
|
1361
|
-
|
|
1243
|
+
const DbMutationBatchUserMutationsKeyPath = ['userId', 'batchId'];
|
|
1362
1244
|
/**
|
|
1363
|
-
*
|
|
1364
|
-
*
|
|
1365
|
-
* A manually maintained index of all the mutation batches that affect a given
|
|
1366
|
-
* document key. The rows in this table are references based on the contents of
|
|
1367
|
-
* DbMutationBatch.mutations.
|
|
1245
|
+
* Creates a [userId] key for use in the DbDocumentMutations index to iterate
|
|
1246
|
+
* over all of a user's document mutations.
|
|
1368
1247
|
*/
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
/**
|
|
1372
|
-
* Creates a [userId] key for use in the DbDocumentMutations index to iterate
|
|
1373
|
-
* over all of a user's document mutations.
|
|
1374
|
-
*/
|
|
1375
|
-
static prefixForUser(userId) {
|
|
1376
|
-
return [userId];
|
|
1377
|
-
}
|
|
1378
|
-
/**
|
|
1379
|
-
* Creates a [userId, encodedPath] key for use in the DbDocumentMutations
|
|
1380
|
-
* index to iterate over all at document mutations for a given path or lower.
|
|
1381
|
-
*/
|
|
1382
|
-
static prefixForPath(userId, path) {
|
|
1383
|
-
return [userId, encodeResourcePath(path)];
|
|
1384
|
-
}
|
|
1385
|
-
/**
|
|
1386
|
-
* Creates a full index key of [userId, encodedPath, batchId] for inserting
|
|
1387
|
-
* and deleting into the DbDocumentMutations index.
|
|
1388
|
-
*/
|
|
1389
|
-
static key(userId, path, batchId) {
|
|
1390
|
-
return [userId, encodeResourcePath(path), batchId];
|
|
1391
|
-
}
|
|
1248
|
+
function newDbDocumentMutationPrefixForUser(userId) {
|
|
1249
|
+
return [userId];
|
|
1392
1250
|
}
|
|
1393
|
-
DbDocumentMutation.store = 'documentMutations';
|
|
1394
|
-
/**
|
|
1395
|
-
* Because we store all the useful information for this store in the key,
|
|
1396
|
-
* there is no useful information to store as the value. The raw (unencoded)
|
|
1397
|
-
* path cannot be stored because IndexedDb doesn't store prototype
|
|
1398
|
-
* information.
|
|
1399
|
-
*/
|
|
1400
|
-
DbDocumentMutation.PLACEHOLDER = new DbDocumentMutation();
|
|
1401
1251
|
/**
|
|
1402
|
-
*
|
|
1403
|
-
*
|
|
1252
|
+
* Creates a [userId, encodedPath] key for use in the DbDocumentMutations
|
|
1253
|
+
* index to iterate over all at document mutations for a given path or lower.
|
|
1404
1254
|
*/
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
this.path = path;
|
|
1408
|
-
this.readTime = readTime;
|
|
1409
|
-
}
|
|
1255
|
+
function newDbDocumentMutationPrefixForPath(userId, path) {
|
|
1256
|
+
return [userId, encodeResourcePath(path)];
|
|
1410
1257
|
}
|
|
1411
1258
|
/**
|
|
1412
|
-
*
|
|
1413
|
-
*
|
|
1259
|
+
* Creates a full index key of [userId, encodedPath, batchId] for inserting
|
|
1260
|
+
* and deleting into the DbDocumentMutations index.
|
|
1414
1261
|
*/
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
this.path = path;
|
|
1418
|
-
this.version = version;
|
|
1419
|
-
}
|
|
1262
|
+
function newDbDocumentMutationKey(userId, path, batchId) {
|
|
1263
|
+
return [userId, encodeResourcePath(path), batchId];
|
|
1420
1264
|
}
|
|
1421
1265
|
/**
|
|
1422
|
-
*
|
|
1423
|
-
*
|
|
1424
|
-
*
|
|
1425
|
-
*
|
|
1426
|
-
* - A "no document" representing a document that is known not to exist (at
|
|
1427
|
-
* some version).
|
|
1428
|
-
* - An "unknown document" representing a document that is known to exist (at
|
|
1429
|
-
* some version) but whose contents are unknown.
|
|
1430
|
-
*
|
|
1431
|
-
* Note: This is the persisted equivalent of a MaybeDocument and could perhaps
|
|
1432
|
-
* be made more general if necessary.
|
|
1266
|
+
* Because we store all the useful information for this store in the key,
|
|
1267
|
+
* there is no useful information to store as the value. The raw (unencoded)
|
|
1268
|
+
* path cannot be stored because IndexedDb doesn't store prototype
|
|
1269
|
+
* information.
|
|
1433
1270
|
*/
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
// inside the encoded documents). During our next migration, we should
|
|
1438
|
-
// rewrite the primary key as parentPath + document ID which would allow us
|
|
1439
|
-
// to drop one value.
|
|
1440
|
-
constructor(
|
|
1441
|
-
/**
|
|
1442
|
-
* Set to an instance of DbUnknownDocument if the data for a document is
|
|
1443
|
-
* not known, but it is known that a document exists at the specified
|
|
1444
|
-
* version (e.g. it had a successful update applied to it)
|
|
1445
|
-
*/
|
|
1446
|
-
unknownDocument,
|
|
1447
|
-
/**
|
|
1448
|
-
* Set to an instance of a DbNoDocument if it is known that no document
|
|
1449
|
-
* exists.
|
|
1450
|
-
*/
|
|
1451
|
-
noDocument,
|
|
1452
|
-
/**
|
|
1453
|
-
* Set to an instance of a Document if there's a cached version of the
|
|
1454
|
-
* document.
|
|
1455
|
-
*/
|
|
1456
|
-
document,
|
|
1457
|
-
/**
|
|
1458
|
-
* Documents that were written to the remote document store based on
|
|
1459
|
-
* a write acknowledgment are marked with `hasCommittedMutations`. These
|
|
1460
|
-
* documents are potentially inconsistent with the backend's copy and use
|
|
1461
|
-
* the write's commit version as their document version.
|
|
1462
|
-
*/
|
|
1463
|
-
hasCommittedMutations,
|
|
1464
|
-
/**
|
|
1465
|
-
* When the document was read from the backend. Undefined for data written
|
|
1466
|
-
* prior to schema version 9.
|
|
1467
|
-
*/
|
|
1468
|
-
readTime,
|
|
1469
|
-
/**
|
|
1470
|
-
* The path of the collection this document is part of. Undefined for data
|
|
1471
|
-
* written prior to schema version 9.
|
|
1472
|
-
*/
|
|
1473
|
-
parentPath) {
|
|
1474
|
-
this.unknownDocument = unknownDocument;
|
|
1475
|
-
this.noDocument = noDocument;
|
|
1476
|
-
this.document = document;
|
|
1477
|
-
this.hasCommittedMutations = hasCommittedMutations;
|
|
1478
|
-
this.readTime = readTime;
|
|
1479
|
-
this.parentPath = parentPath;
|
|
1480
|
-
}
|
|
1481
|
-
}
|
|
1482
|
-
DbRemoteDocument.store = 'remoteDocuments';
|
|
1271
|
+
const DbDocumentMutationPlaceholder = {};
|
|
1272
|
+
const DbDocumentMutationStore = 'documentMutations';
|
|
1273
|
+
const DbRemoteDocumentStore = 'remoteDocuments';
|
|
1483
1274
|
/**
|
|
1484
1275
|
* An index that provides access to all entries sorted by read time (which
|
|
1485
1276
|
* corresponds to the last modification time of each row).
|
|
1486
1277
|
*
|
|
1487
1278
|
* This index is used to provide a changelog for Multi-Tab.
|
|
1488
1279
|
*/
|
|
1489
|
-
|
|
1490
|
-
|
|
1280
|
+
const DbRemoteDocumentReadTimeIndex = 'readTimeIndex';
|
|
1281
|
+
const DbRemoteDocumentReadTimeIndexPath = 'readTime';
|
|
1491
1282
|
/**
|
|
1492
1283
|
* An index that provides access to documents in a collection sorted by read
|
|
1493
1284
|
* time.
|
|
@@ -1495,310 +1286,55 @@ DbRemoteDocument.readTimeIndexPath = 'readTime';
|
|
|
1495
1286
|
* This index is used to allow the RemoteDocumentCache to fetch newly changed
|
|
1496
1287
|
* documents in a collection.
|
|
1497
1288
|
*/
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
* documents in the document cache.
|
|
1507
|
-
*/
|
|
1508
|
-
constructor(byteSize) {
|
|
1509
|
-
this.byteSize = byteSize;
|
|
1510
|
-
}
|
|
1511
|
-
}
|
|
1512
|
-
DbRemoteDocumentGlobal.store = 'remoteDocumentGlobal';
|
|
1513
|
-
DbRemoteDocumentGlobal.key = 'remoteDocumentGlobalKey';
|
|
1514
|
-
/**
|
|
1515
|
-
* An object to be stored in the 'targets' store in IndexedDb.
|
|
1516
|
-
*
|
|
1517
|
-
* This is based on and should be kept in sync with the proto used in the iOS
|
|
1518
|
-
* client.
|
|
1519
|
-
*
|
|
1520
|
-
* Each query the client listens to against the server is tracked on disk so
|
|
1521
|
-
* that the query can be efficiently resumed on restart.
|
|
1522
|
-
*/
|
|
1523
|
-
class DbTarget {
|
|
1524
|
-
constructor(
|
|
1525
|
-
/**
|
|
1526
|
-
* An auto-generated sequential numeric identifier for the query.
|
|
1527
|
-
*
|
|
1528
|
-
* Queries are stored using their canonicalId as the key, but these
|
|
1529
|
-
* canonicalIds can be quite long so we additionally assign a unique
|
|
1530
|
-
* queryId which can be used by referenced data structures (e.g.
|
|
1531
|
-
* indexes) to minimize the on-disk cost.
|
|
1532
|
-
*/
|
|
1533
|
-
targetId,
|
|
1534
|
-
/**
|
|
1535
|
-
* The canonical string representing this query. This is not unique.
|
|
1536
|
-
*/
|
|
1537
|
-
canonicalId,
|
|
1538
|
-
/**
|
|
1539
|
-
* The last readTime received from the Watch Service for this query.
|
|
1540
|
-
*
|
|
1541
|
-
* This is the same value as TargetChange.read_time in the protos.
|
|
1542
|
-
*/
|
|
1543
|
-
readTime,
|
|
1544
|
-
/**
|
|
1545
|
-
* An opaque, server-assigned token that allows watching a query to be
|
|
1546
|
-
* resumed after disconnecting without retransmitting all the data
|
|
1547
|
-
* that matches the query. The resume token essentially identifies a
|
|
1548
|
-
* point in time from which the server should resume sending results.
|
|
1549
|
-
*
|
|
1550
|
-
* This is related to the snapshotVersion in that the resumeToken
|
|
1551
|
-
* effectively also encodes that value, but the resumeToken is opaque
|
|
1552
|
-
* and sometimes encodes additional information.
|
|
1553
|
-
*
|
|
1554
|
-
* A consequence of this is that the resumeToken should be used when
|
|
1555
|
-
* asking the server to reason about where this client is in the watch
|
|
1556
|
-
* stream, but the client should use the snapshotVersion for its own
|
|
1557
|
-
* purposes.
|
|
1558
|
-
*
|
|
1559
|
-
* This is the same value as TargetChange.resume_token in the protos.
|
|
1560
|
-
*/
|
|
1561
|
-
resumeToken,
|
|
1562
|
-
/**
|
|
1563
|
-
* A sequence number representing the last time this query was
|
|
1564
|
-
* listened to, used for garbage collection purposes.
|
|
1565
|
-
*
|
|
1566
|
-
* Conventionally this would be a timestamp value, but device-local
|
|
1567
|
-
* clocks are unreliable and they must be able to create new listens
|
|
1568
|
-
* even while disconnected. Instead this should be a monotonically
|
|
1569
|
-
* increasing number that's incremented on each listen call.
|
|
1570
|
-
*
|
|
1571
|
-
* This is different from the queryId since the queryId is an
|
|
1572
|
-
* immutable identifier assigned to the Query on first use while
|
|
1573
|
-
* lastListenSequenceNumber is updated every time the query is
|
|
1574
|
-
* listened to.
|
|
1575
|
-
*/
|
|
1576
|
-
lastListenSequenceNumber,
|
|
1577
|
-
/**
|
|
1578
|
-
* Denotes the maximum snapshot version at which the associated query view
|
|
1579
|
-
* contained no limbo documents. Undefined for data written prior to
|
|
1580
|
-
* schema version 9.
|
|
1581
|
-
*/
|
|
1582
|
-
lastLimboFreeSnapshotVersion,
|
|
1583
|
-
/**
|
|
1584
|
-
* The query for this target.
|
|
1585
|
-
*
|
|
1586
|
-
* Because canonical ids are not unique we must store the actual query. We
|
|
1587
|
-
* use the proto to have an object we can persist without having to
|
|
1588
|
-
* duplicate translation logic to and from a `Query` object.
|
|
1589
|
-
*/
|
|
1590
|
-
query) {
|
|
1591
|
-
this.targetId = targetId;
|
|
1592
|
-
this.canonicalId = canonicalId;
|
|
1593
|
-
this.readTime = readTime;
|
|
1594
|
-
this.resumeToken = resumeToken;
|
|
1595
|
-
this.lastListenSequenceNumber = lastListenSequenceNumber;
|
|
1596
|
-
this.lastLimboFreeSnapshotVersion = lastLimboFreeSnapshotVersion;
|
|
1597
|
-
this.query = query;
|
|
1598
|
-
}
|
|
1599
|
-
}
|
|
1600
|
-
DbTarget.store = 'targets';
|
|
1289
|
+
const DbRemoteDocumentCollectionReadTimeIndex = 'collectionReadTimeIndex';
|
|
1290
|
+
const DbRemoteDocumentCollectionReadTimeIndexPath = [
|
|
1291
|
+
'parentPath',
|
|
1292
|
+
'readTime'
|
|
1293
|
+
];
|
|
1294
|
+
const DbRemoteDocumentGlobalStore = 'remoteDocumentGlobal';
|
|
1295
|
+
const DbRemoteDocumentGlobalKey = 'remoteDocumentGlobalKey';
|
|
1296
|
+
const DbTargetStore = 'targets';
|
|
1601
1297
|
/** Keys are automatically assigned via the targetId property. */
|
|
1602
|
-
|
|
1298
|
+
const DbTargetKeyPath = 'targetId';
|
|
1603
1299
|
/** The name of the queryTargets index. */
|
|
1604
|
-
|
|
1300
|
+
const DbTargetQueryTargetsIndexName = 'queryTargetsIndex';
|
|
1605
1301
|
/**
|
|
1606
1302
|
* The index of all canonicalIds to the targets that they match. This is not
|
|
1607
1303
|
* a unique mapping because canonicalId does not promise a unique name for all
|
|
1608
1304
|
* possible queries, so we append the targetId to make the mapping unique.
|
|
1609
1305
|
*/
|
|
1610
|
-
|
|
1611
|
-
/**
|
|
1612
|
-
* An object representing an association between a target and a document, or a
|
|
1613
|
-
* sentinel row marking the last sequence number at which a document was used.
|
|
1614
|
-
* Each document cached must have a corresponding sentinel row before lru
|
|
1615
|
-
* garbage collection is enabled.
|
|
1616
|
-
*
|
|
1617
|
-
* The target associations and sentinel rows are co-located so that orphaned
|
|
1618
|
-
* documents and their sequence numbers can be identified efficiently via a scan
|
|
1619
|
-
* of this store.
|
|
1620
|
-
*/
|
|
1621
|
-
class DbTargetDocument {
|
|
1622
|
-
constructor(
|
|
1623
|
-
/**
|
|
1624
|
-
* The targetId identifying a target or 0 for a sentinel row.
|
|
1625
|
-
*/
|
|
1626
|
-
targetId,
|
|
1627
|
-
/**
|
|
1628
|
-
* The path to the document, as encoded in the key.
|
|
1629
|
-
*/
|
|
1630
|
-
path,
|
|
1631
|
-
/**
|
|
1632
|
-
* If this is a sentinel row, this should be the sequence number of the last
|
|
1633
|
-
* time the document specified by `path` was used. Otherwise, it should be
|
|
1634
|
-
* `undefined`.
|
|
1635
|
-
*/
|
|
1636
|
-
sequenceNumber) {
|
|
1637
|
-
this.targetId = targetId;
|
|
1638
|
-
this.path = path;
|
|
1639
|
-
this.sequenceNumber = sequenceNumber;
|
|
1640
|
-
}
|
|
1641
|
-
}
|
|
1306
|
+
const DbTargetQueryTargetsKeyPath = ['canonicalId', 'targetId'];
|
|
1642
1307
|
/** Name of the IndexedDb object store. */
|
|
1643
|
-
|
|
1308
|
+
const DbTargetDocumentStore = 'targetDocuments';
|
|
1644
1309
|
/** Keys are automatically assigned via the targetId, path properties. */
|
|
1645
|
-
|
|
1310
|
+
const DbTargetDocumentKeyPath = ['targetId', 'path'];
|
|
1646
1311
|
/** The index name for the reverse index. */
|
|
1647
|
-
|
|
1312
|
+
const DbTargetDocumentDocumentTargetsIndex = 'documentTargetsIndex';
|
|
1648
1313
|
/** We also need to create the reverse index for these properties. */
|
|
1649
|
-
|
|
1650
|
-
/**
|
|
1651
|
-
* A record of global state tracked across all Targets, tracked separately
|
|
1652
|
-
* to avoid the need for extra indexes.
|
|
1653
|
-
*
|
|
1654
|
-
* This should be kept in-sync with the proto used in the iOS client.
|
|
1655
|
-
*/
|
|
1656
|
-
class DbTargetGlobal {
|
|
1657
|
-
constructor(
|
|
1658
|
-
/**
|
|
1659
|
-
* The highest numbered target id across all targets.
|
|
1660
|
-
*
|
|
1661
|
-
* See DbTarget.targetId.
|
|
1662
|
-
*/
|
|
1663
|
-
highestTargetId,
|
|
1664
|
-
/**
|
|
1665
|
-
* The highest numbered lastListenSequenceNumber across all targets.
|
|
1666
|
-
*
|
|
1667
|
-
* See DbTarget.lastListenSequenceNumber.
|
|
1668
|
-
*/
|
|
1669
|
-
highestListenSequenceNumber,
|
|
1670
|
-
/**
|
|
1671
|
-
* A global snapshot version representing the last consistent snapshot we
|
|
1672
|
-
* received from the backend. This is monotonically increasing and any
|
|
1673
|
-
* snapshots received from the backend prior to this version (e.g. for
|
|
1674
|
-
* targets resumed with a resumeToken) should be suppressed (buffered)
|
|
1675
|
-
* until the backend has caught up to this snapshot version again. This
|
|
1676
|
-
* prevents our cache from ever going backwards in time.
|
|
1677
|
-
*/
|
|
1678
|
-
lastRemoteSnapshotVersion,
|
|
1679
|
-
/**
|
|
1680
|
-
* The number of targets persisted.
|
|
1681
|
-
*/
|
|
1682
|
-
targetCount) {
|
|
1683
|
-
this.highestTargetId = highestTargetId;
|
|
1684
|
-
this.highestListenSequenceNumber = highestListenSequenceNumber;
|
|
1685
|
-
this.lastRemoteSnapshotVersion = lastRemoteSnapshotVersion;
|
|
1686
|
-
this.targetCount = targetCount;
|
|
1687
|
-
}
|
|
1688
|
-
}
|
|
1314
|
+
const DbTargetDocumentDocumentTargetsKeyPath = ['path', 'targetId'];
|
|
1689
1315
|
/**
|
|
1690
1316
|
* The key string used for the single object that exists in the
|
|
1691
1317
|
* DbTargetGlobal store.
|
|
1692
1318
|
*/
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
/**
|
|
1696
|
-
* An object representing an association between a Collection id (e.g. 'messages')
|
|
1697
|
-
* to a parent path (e.g. '/chats/123') that contains it as a (sub)collection.
|
|
1698
|
-
* This is used to efficiently find all collections to query when performing
|
|
1699
|
-
* a Collection Group query.
|
|
1700
|
-
*/
|
|
1701
|
-
class DbCollectionParent {
|
|
1702
|
-
constructor(
|
|
1703
|
-
/**
|
|
1704
|
-
* The collectionId (e.g. 'messages')
|
|
1705
|
-
*/
|
|
1706
|
-
collectionId,
|
|
1707
|
-
/**
|
|
1708
|
-
* The path to the parent (either a document location or an empty path for
|
|
1709
|
-
* a root-level collection).
|
|
1710
|
-
*/
|
|
1711
|
-
parent) {
|
|
1712
|
-
this.collectionId = collectionId;
|
|
1713
|
-
this.parent = parent;
|
|
1714
|
-
}
|
|
1715
|
-
}
|
|
1319
|
+
const DbTargetGlobalKey = 'targetGlobalKey';
|
|
1320
|
+
const DbTargetGlobalStore = 'targetGlobal';
|
|
1716
1321
|
/** Name of the IndexedDb object store. */
|
|
1717
|
-
|
|
1322
|
+
const DbCollectionParentStore = 'collectionParents';
|
|
1718
1323
|
/** Keys are automatically assigned via the collectionId, parent properties. */
|
|
1719
|
-
|
|
1720
|
-
/**
|
|
1721
|
-
* A record of the metadata state of each client.
|
|
1722
|
-
*
|
|
1723
|
-
* PORTING NOTE: This is used to synchronize multi-tab state and does not need
|
|
1724
|
-
* to be ported to iOS or Android.
|
|
1725
|
-
*/
|
|
1726
|
-
class DbClientMetadata {
|
|
1727
|
-
constructor(
|
|
1728
|
-
// Note: Previous schema versions included a field
|
|
1729
|
-
// "lastProcessedDocumentChangeId". Don't use anymore.
|
|
1730
|
-
/** The auto-generated client id assigned at client startup. */
|
|
1731
|
-
clientId,
|
|
1732
|
-
/** The last time this state was updated. */
|
|
1733
|
-
updateTimeMs,
|
|
1734
|
-
/** Whether the client's network connection is enabled. */
|
|
1735
|
-
networkEnabled,
|
|
1736
|
-
/** Whether this client is running in a foreground tab. */
|
|
1737
|
-
inForeground) {
|
|
1738
|
-
this.clientId = clientId;
|
|
1739
|
-
this.updateTimeMs = updateTimeMs;
|
|
1740
|
-
this.networkEnabled = networkEnabled;
|
|
1741
|
-
this.inForeground = inForeground;
|
|
1742
|
-
}
|
|
1743
|
-
}
|
|
1324
|
+
const DbCollectionParentKeyPath = ['collectionId', 'parent'];
|
|
1744
1325
|
/** Name of the IndexedDb object store. */
|
|
1745
|
-
|
|
1326
|
+
const DbClientMetadataStore = 'clientMetadata';
|
|
1746
1327
|
/** Keys are automatically assigned via the clientId properties. */
|
|
1747
|
-
|
|
1748
|
-
/** An object representing a bundle loaded by the SDK. */
|
|
1749
|
-
class DbBundle {
|
|
1750
|
-
constructor(
|
|
1751
|
-
/** The ID of the loaded bundle. */
|
|
1752
|
-
bundleId,
|
|
1753
|
-
/** The create time of the loaded bundle. */
|
|
1754
|
-
createTime,
|
|
1755
|
-
/** The schema version of the loaded bundle. */
|
|
1756
|
-
version) {
|
|
1757
|
-
this.bundleId = bundleId;
|
|
1758
|
-
this.createTime = createTime;
|
|
1759
|
-
this.version = version;
|
|
1760
|
-
}
|
|
1761
|
-
}
|
|
1328
|
+
const DbClientMetadataKeyPath = 'clientId';
|
|
1762
1329
|
/** Name of the IndexedDb object store. */
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
/** An object representing a named query loaded by the SDK via a bundle. */
|
|
1766
|
-
class DbNamedQuery {
|
|
1767
|
-
constructor(
|
|
1768
|
-
/** The name of the query. */
|
|
1769
|
-
name,
|
|
1770
|
-
/** The read time of the results saved in the bundle from the named query. */
|
|
1771
|
-
readTime,
|
|
1772
|
-
/** The query saved in the bundle. */
|
|
1773
|
-
bundledQuery) {
|
|
1774
|
-
this.name = name;
|
|
1775
|
-
this.readTime = readTime;
|
|
1776
|
-
this.bundledQuery = bundledQuery;
|
|
1777
|
-
}
|
|
1778
|
-
}
|
|
1330
|
+
const DbBundleStore = 'bundles';
|
|
1331
|
+
const DbBundleKeyPath = 'bundleId';
|
|
1779
1332
|
/** Name of the IndexedDb object store. */
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
/** An object representing the global configuration for a field index. */
|
|
1783
|
-
class DbIndexConfiguration {
|
|
1784
|
-
constructor(
|
|
1785
|
-
/**
|
|
1786
|
-
* The index id for this entry. Undefined for indexes that are not yet
|
|
1787
|
-
* persisted.
|
|
1788
|
-
*/
|
|
1789
|
-
indexId,
|
|
1790
|
-
/** The collection group this index belongs to. */
|
|
1791
|
-
collectionGroup,
|
|
1792
|
-
/** The fields to index for this index. */
|
|
1793
|
-
fields) {
|
|
1794
|
-
this.indexId = indexId;
|
|
1795
|
-
this.collectionGroup = collectionGroup;
|
|
1796
|
-
this.fields = fields;
|
|
1797
|
-
}
|
|
1798
|
-
}
|
|
1333
|
+
const DbNamedQueryStore = 'namedQueries';
|
|
1334
|
+
const DbNamedQueryKeyPath = 'name';
|
|
1799
1335
|
/** Name of the IndexedDb object store. */
|
|
1800
|
-
|
|
1801
|
-
|
|
1336
|
+
const DbIndexConfigurationStore = 'indexConfiguration';
|
|
1337
|
+
const DbIndexConfigurationKeyPath = 'indexId';
|
|
1802
1338
|
/**
|
|
1803
1339
|
* An index that provides access to the index configurations by collection
|
|
1804
1340
|
* group.
|
|
@@ -1807,49 +1343,11 @@ DbIndexConfiguration.keyPath = 'indexId';
|
|
|
1807
1343
|
* not possible here as the Web client supports concurrent access to
|
|
1808
1344
|
* persistence via multi-tab.
|
|
1809
1345
|
*/
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
/**
|
|
1813
|
-
* An object describing how up-to-date the index backfill is for each user and
|
|
1814
|
-
* index.
|
|
1815
|
-
*/
|
|
1816
|
-
class DbIndexState {
|
|
1817
|
-
constructor(
|
|
1818
|
-
/** The index id for this entry. */
|
|
1819
|
-
indexId,
|
|
1820
|
-
/** The user id for this entry. */
|
|
1821
|
-
uid,
|
|
1822
|
-
/**
|
|
1823
|
-
* A number that indicates when the index was last updated (relative to
|
|
1824
|
-
* other indexes).
|
|
1825
|
-
*/
|
|
1826
|
-
sequenceNumber,
|
|
1827
|
-
/**
|
|
1828
|
-
* The latest read time that has been indexed by Firestore for this field
|
|
1829
|
-
* index. Set to `{seconds: 0, nanos: 0}` if no documents have been indexed.
|
|
1830
|
-
*/
|
|
1831
|
-
readTime,
|
|
1832
|
-
/**
|
|
1833
|
-
* The last document that has been indexed for this field index. Empty if
|
|
1834
|
-
* no documents have been indexed.
|
|
1835
|
-
*/
|
|
1836
|
-
documentKey,
|
|
1837
|
-
/**
|
|
1838
|
-
* The largest mutation batch id that has been processed for this index. -1
|
|
1839
|
-
* if no mutations have been indexed.
|
|
1840
|
-
*/
|
|
1841
|
-
largestBatchId) {
|
|
1842
|
-
this.indexId = indexId;
|
|
1843
|
-
this.uid = uid;
|
|
1844
|
-
this.sequenceNumber = sequenceNumber;
|
|
1845
|
-
this.readTime = readTime;
|
|
1846
|
-
this.documentKey = documentKey;
|
|
1847
|
-
this.largestBatchId = largestBatchId;
|
|
1848
|
-
}
|
|
1849
|
-
}
|
|
1346
|
+
const DbIndexConfigurationCollectionGroupIndex = 'collectionGroupIndex';
|
|
1347
|
+
const DbIndexConfigurationCollectionGroupIndexPath = 'collectionGroup';
|
|
1850
1348
|
/** Name of the IndexedDb object store. */
|
|
1851
|
-
|
|
1852
|
-
|
|
1349
|
+
const DbIndexStateStore = 'indexState';
|
|
1350
|
+
const DbIndexStateKeyPath = ['indexId', 'uid'];
|
|
1853
1351
|
/**
|
|
1854
1352
|
* An index that provides access to documents in a collection sorted by last
|
|
1855
1353
|
* update time. Used by the backfiller.
|
|
@@ -1858,108 +1356,66 @@ DbIndexState.keyPath = ['indexId', 'uid'];
|
|
|
1858
1356
|
* not possible here as the Web client supports concurrent access to
|
|
1859
1357
|
* persistence via multi-tab.
|
|
1860
1358
|
*/
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
/** An object that stores the encoded entries for all documents and fields. */
|
|
1864
|
-
class DbIndexEntry {
|
|
1865
|
-
constructor(
|
|
1866
|
-
/** The index id for this entry. */
|
|
1867
|
-
indexId,
|
|
1868
|
-
/** The user id for this entry. */
|
|
1869
|
-
uid,
|
|
1870
|
-
/** The encoded array index value for this entry. */
|
|
1871
|
-
arrayValue,
|
|
1872
|
-
/** The encoded directional value for equality and inequality filters. */
|
|
1873
|
-
directionalValue,
|
|
1874
|
-
/** The document key this entry points to. */
|
|
1875
|
-
documentKey) {
|
|
1876
|
-
this.indexId = indexId;
|
|
1877
|
-
this.uid = uid;
|
|
1878
|
-
this.arrayValue = arrayValue;
|
|
1879
|
-
this.directionalValue = directionalValue;
|
|
1880
|
-
this.documentKey = documentKey;
|
|
1881
|
-
}
|
|
1882
|
-
}
|
|
1359
|
+
const DbIndexStateSequenceNumberIndex = 'sequenceNumberIndex';
|
|
1360
|
+
const DbIndexStateSequenceNumberIndexPath = ['uid', 'sequenceNumber'];
|
|
1883
1361
|
/** Name of the IndexedDb object store. */
|
|
1884
|
-
|
|
1885
|
-
|
|
1362
|
+
const DbIndexEntryStore = 'indexEntries';
|
|
1363
|
+
const DbIndexEntryKeyPath = [
|
|
1886
1364
|
'indexId',
|
|
1887
1365
|
'uid',
|
|
1888
1366
|
'arrayValue',
|
|
1889
1367
|
'directionalValue',
|
|
1890
|
-
'documentKey'
|
|
1891
|
-
];
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
constructor(
|
|
1899
|
-
/** The user ID to whom this overlay belongs. */
|
|
1900
|
-
userId,
|
|
1901
|
-
/** The path to the collection that contains the document. */
|
|
1902
|
-
collectionPath,
|
|
1903
|
-
/** The ID (key) of the document within the collection. */
|
|
1904
|
-
documentId,
|
|
1905
|
-
/** The collection group to which the document belongs. */
|
|
1906
|
-
collectionGroup,
|
|
1907
|
-
/** The largest batch ID that's been applied for this overlay. */
|
|
1908
|
-
largestBatchId,
|
|
1909
|
-
/** The overlay mutation. */
|
|
1910
|
-
overlayMutation) {
|
|
1911
|
-
this.userId = userId;
|
|
1912
|
-
this.collectionPath = collectionPath;
|
|
1913
|
-
this.documentId = documentId;
|
|
1914
|
-
this.collectionGroup = collectionGroup;
|
|
1915
|
-
this.largestBatchId = largestBatchId;
|
|
1916
|
-
this.overlayMutation = overlayMutation;
|
|
1917
|
-
}
|
|
1918
|
-
}
|
|
1368
|
+
'documentKey'
|
|
1369
|
+
];
|
|
1370
|
+
const DbIndexEntryDocumentKeyIndex = 'documentKeyIndex';
|
|
1371
|
+
const DbIndexEntryDocumentKeyIndexPath = [
|
|
1372
|
+
'indexId',
|
|
1373
|
+
'uid',
|
|
1374
|
+
'documentKey'
|
|
1375
|
+
];
|
|
1919
1376
|
/** Name of the IndexedDb object store. */
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1377
|
+
const DbDocumentOverlayStore = 'documentOverlays';
|
|
1378
|
+
const DbDocumentOverlayKeyPath = [
|
|
1379
|
+
'userId',
|
|
1380
|
+
'collectionPath',
|
|
1381
|
+
'documentId'
|
|
1382
|
+
];
|
|
1383
|
+
const DbDocumentOverlayCollectionPathOverlayIndex = 'collectionPathOverlayIndex';
|
|
1384
|
+
const DbDocumentOverlayCollectionPathOverlayIndexPath = [
|
|
1924
1385
|
'userId',
|
|
1925
1386
|
'collectionPath',
|
|
1926
1387
|
'largestBatchId'
|
|
1927
1388
|
];
|
|
1928
|
-
|
|
1929
|
-
|
|
1389
|
+
const DbDocumentOverlayCollectionGroupOverlayIndex = 'collectionGroupOverlayIndex';
|
|
1390
|
+
const DbDocumentOverlayCollectionGroupOverlayIndexPath = [
|
|
1930
1391
|
'userId',
|
|
1931
1392
|
'collectionGroup',
|
|
1932
1393
|
'largestBatchId'
|
|
1933
1394
|
];
|
|
1934
1395
|
// Visible for testing
|
|
1935
1396
|
const V1_STORES = [
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1397
|
+
DbMutationQueueStore,
|
|
1398
|
+
DbMutationBatchStore,
|
|
1399
|
+
DbDocumentMutationStore,
|
|
1400
|
+
DbRemoteDocumentStore,
|
|
1401
|
+
DbTargetStore,
|
|
1402
|
+
DbPrimaryClientStore,
|
|
1403
|
+
DbTargetGlobalStore,
|
|
1404
|
+
DbTargetDocumentStore
|
|
1944
1405
|
];
|
|
1945
|
-
// V2 is no longer usable (see comment at top of file)
|
|
1946
1406
|
// Visible for testing
|
|
1947
1407
|
const V3_STORES = V1_STORES;
|
|
1948
1408
|
// Note: DbRemoteDocumentChanges is no longer used and dropped with v9.
|
|
1949
|
-
const V4_STORES = [...V3_STORES,
|
|
1950
|
-
|
|
1951
|
-
const
|
|
1952
|
-
|
|
1953
|
-
const
|
|
1954
|
-
// V9 does not change the set of stores.
|
|
1955
|
-
// V10 does not change the set of stores.
|
|
1956
|
-
const V11_STORES = [...V8_STORES, DbBundle.store, DbNamedQuery.store];
|
|
1957
|
-
const V12_STORES = [...V11_STORES, DbDocumentOverlay.store];
|
|
1409
|
+
const V4_STORES = [...V3_STORES, DbClientMetadataStore];
|
|
1410
|
+
const V6_STORES = [...V4_STORES, DbRemoteDocumentGlobalStore];
|
|
1411
|
+
const V8_STORES = [...V6_STORES, DbCollectionParentStore];
|
|
1412
|
+
const V11_STORES = [...V8_STORES, DbBundleStore, DbNamedQueryStore];
|
|
1413
|
+
const V12_STORES = [...V11_STORES, DbDocumentOverlayStore];
|
|
1958
1414
|
const V13_STORES = [
|
|
1959
1415
|
...V12_STORES,
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1416
|
+
DbIndexConfigurationStore,
|
|
1417
|
+
DbIndexStateStore,
|
|
1418
|
+
DbIndexEntryStore
|
|
1963
1419
|
];
|
|
1964
1420
|
/** Returns the object stores for the provided schema. */
|
|
1965
1421
|
function getObjectStores(schemaVersion) {
|
|
@@ -5676,6 +5132,116 @@ function compareDocs(orderBy, d1, d2) {
|
|
|
5676
5132
|
}
|
|
5677
5133
|
}
|
|
5678
5134
|
|
|
5135
|
+
/**
|
|
5136
|
+
* @license
|
|
5137
|
+
* Copyright 2017 Google LLC
|
|
5138
|
+
*
|
|
5139
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5140
|
+
* you may not use this file except in compliance with the License.
|
|
5141
|
+
* You may obtain a copy of the License at
|
|
5142
|
+
*
|
|
5143
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
5144
|
+
*
|
|
5145
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
5146
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
5147
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
5148
|
+
* See the License for the specific language governing permissions and
|
|
5149
|
+
* limitations under the License.
|
|
5150
|
+
*/
|
|
5151
|
+
/**
|
|
5152
|
+
* A map implementation that uses objects as keys. Objects must have an
|
|
5153
|
+
* associated equals function and must be immutable. Entries in the map are
|
|
5154
|
+
* stored together with the key being produced from the mapKeyFn. This map
|
|
5155
|
+
* automatically handles collisions of keys.
|
|
5156
|
+
*/
|
|
5157
|
+
class ObjectMap {
|
|
5158
|
+
constructor(mapKeyFn, equalsFn) {
|
|
5159
|
+
this.mapKeyFn = mapKeyFn;
|
|
5160
|
+
this.equalsFn = equalsFn;
|
|
5161
|
+
/**
|
|
5162
|
+
* The inner map for a key/value pair. Due to the possibility of collisions we
|
|
5163
|
+
* keep a list of entries that we do a linear search through to find an actual
|
|
5164
|
+
* match. Note that collisions should be rare, so we still expect near
|
|
5165
|
+
* constant time lookups in practice.
|
|
5166
|
+
*/
|
|
5167
|
+
this.inner = {};
|
|
5168
|
+
/** The number of entries stored in the map */
|
|
5169
|
+
this.innerSize = 0;
|
|
5170
|
+
}
|
|
5171
|
+
/** Get a value for this key, or undefined if it does not exist. */
|
|
5172
|
+
get(key) {
|
|
5173
|
+
const id = this.mapKeyFn(key);
|
|
5174
|
+
const matches = this.inner[id];
|
|
5175
|
+
if (matches === undefined) {
|
|
5176
|
+
return undefined;
|
|
5177
|
+
}
|
|
5178
|
+
for (const [otherKey, value] of matches) {
|
|
5179
|
+
if (this.equalsFn(otherKey, key)) {
|
|
5180
|
+
return value;
|
|
5181
|
+
}
|
|
5182
|
+
}
|
|
5183
|
+
return undefined;
|
|
5184
|
+
}
|
|
5185
|
+
has(key) {
|
|
5186
|
+
return this.get(key) !== undefined;
|
|
5187
|
+
}
|
|
5188
|
+
/** Put this key and value in the map. */
|
|
5189
|
+
set(key, value) {
|
|
5190
|
+
const id = this.mapKeyFn(key);
|
|
5191
|
+
const matches = this.inner[id];
|
|
5192
|
+
if (matches === undefined) {
|
|
5193
|
+
this.inner[id] = [[key, value]];
|
|
5194
|
+
this.innerSize++;
|
|
5195
|
+
return;
|
|
5196
|
+
}
|
|
5197
|
+
for (let i = 0; i < matches.length; i++) {
|
|
5198
|
+
if (this.equalsFn(matches[i][0], key)) {
|
|
5199
|
+
// This is updating an existing entry and does not increase `innerSize`.
|
|
5200
|
+
matches[i] = [key, value];
|
|
5201
|
+
return;
|
|
5202
|
+
}
|
|
5203
|
+
}
|
|
5204
|
+
matches.push([key, value]);
|
|
5205
|
+
this.innerSize++;
|
|
5206
|
+
}
|
|
5207
|
+
/**
|
|
5208
|
+
* Remove this key from the map. Returns a boolean if anything was deleted.
|
|
5209
|
+
*/
|
|
5210
|
+
delete(key) {
|
|
5211
|
+
const id = this.mapKeyFn(key);
|
|
5212
|
+
const matches = this.inner[id];
|
|
5213
|
+
if (matches === undefined) {
|
|
5214
|
+
return false;
|
|
5215
|
+
}
|
|
5216
|
+
for (let i = 0; i < matches.length; i++) {
|
|
5217
|
+
if (this.equalsFn(matches[i][0], key)) {
|
|
5218
|
+
if (matches.length === 1) {
|
|
5219
|
+
delete this.inner[id];
|
|
5220
|
+
}
|
|
5221
|
+
else {
|
|
5222
|
+
matches.splice(i, 1);
|
|
5223
|
+
}
|
|
5224
|
+
this.innerSize--;
|
|
5225
|
+
return true;
|
|
5226
|
+
}
|
|
5227
|
+
}
|
|
5228
|
+
return false;
|
|
5229
|
+
}
|
|
5230
|
+
forEach(fn) {
|
|
5231
|
+
forEach(this.inner, (_, entries) => {
|
|
5232
|
+
for (const [k, v] of entries) {
|
|
5233
|
+
fn(k, v);
|
|
5234
|
+
}
|
|
5235
|
+
});
|
|
5236
|
+
}
|
|
5237
|
+
isEmpty() {
|
|
5238
|
+
return isEmpty(this.inner);
|
|
5239
|
+
}
|
|
5240
|
+
size() {
|
|
5241
|
+
return this.innerSize;
|
|
5242
|
+
}
|
|
5243
|
+
}
|
|
5244
|
+
|
|
5679
5245
|
/**
|
|
5680
5246
|
* @license
|
|
5681
5247
|
* Copyright 2017 Google LLC
|
|
@@ -6387,6 +5953,9 @@ const EMPTY_DOCUMENT_MAP = new SortedMap(DocumentKey.comparator);
|
|
|
6387
5953
|
function documentMap() {
|
|
6388
5954
|
return EMPTY_DOCUMENT_MAP;
|
|
6389
5955
|
}
|
|
5956
|
+
function newOverlayMap() {
|
|
5957
|
+
return new ObjectMap(key => key.toString(), (l, r) => l.isEqual(r));
|
|
5958
|
+
}
|
|
6390
5959
|
const EMPTY_DOCUMENT_VERSION_MAP = new SortedMap(DocumentKey.comparator);
|
|
6391
5960
|
function documentVersionMap() {
|
|
6392
5961
|
return EMPTY_DOCUMENT_VERSION_MAP;
|
|
@@ -9065,30 +8634,36 @@ function fromDbRemoteDocument(localSerializer, remoteDoc) {
|
|
|
9065
8634
|
}
|
|
9066
8635
|
/** Encodes a document for storage locally. */
|
|
9067
8636
|
function toDbRemoteDocument(localSerializer, document) {
|
|
9068
|
-
const dbReadTime = toDbTimestampKey(document.readTime);
|
|
9069
8637
|
const parentPath = document.key.path.popLast().toArray();
|
|
8638
|
+
const readTime = toDbTimestampKey(document.readTime);
|
|
9070
8639
|
if (document.isFoundDocument()) {
|
|
9071
8640
|
const doc = toDocument(localSerializer.remoteSerializer, document);
|
|
9072
8641
|
const hasCommittedMutations = document.hasCommittedMutations;
|
|
9073
|
-
return
|
|
9074
|
-
|
|
9075
|
-
|
|
8642
|
+
return {
|
|
8643
|
+
document: doc,
|
|
8644
|
+
hasCommittedMutations,
|
|
8645
|
+
readTime,
|
|
8646
|
+
parentPath
|
|
8647
|
+
};
|
|
9076
8648
|
}
|
|
9077
8649
|
else if (document.isNoDocument()) {
|
|
9078
8650
|
const path = document.key.path.toArray();
|
|
9079
|
-
const version = toDbTimestamp(document.version);
|
|
9080
8651
|
const hasCommittedMutations = document.hasCommittedMutations;
|
|
9081
|
-
return
|
|
9082
|
-
|
|
9083
|
-
|
|
8652
|
+
return {
|
|
8653
|
+
noDocument: { path, readTime: toDbTimestamp(document.version) },
|
|
8654
|
+
hasCommittedMutations,
|
|
8655
|
+
readTime,
|
|
8656
|
+
parentPath
|
|
8657
|
+
};
|
|
9084
8658
|
}
|
|
9085
8659
|
else if (document.isUnknownDocument()) {
|
|
9086
8660
|
const path = document.key.path.toArray();
|
|
9087
|
-
|
|
9088
|
-
|
|
9089
|
-
|
|
9090
|
-
|
|
9091
|
-
|
|
8661
|
+
return {
|
|
8662
|
+
unknownDocument: { path, version: toDbTimestamp(document.version) },
|
|
8663
|
+
hasCommittedMutations: true,
|
|
8664
|
+
readTime,
|
|
8665
|
+
parentPath
|
|
8666
|
+
};
|
|
9092
8667
|
}
|
|
9093
8668
|
else {
|
|
9094
8669
|
return fail();
|
|
@@ -9104,7 +8679,7 @@ function fromDbTimestampKey(dbTimestampKey) {
|
|
|
9104
8679
|
}
|
|
9105
8680
|
function toDbTimestamp(snapshotVersion) {
|
|
9106
8681
|
const timestamp = snapshotVersion.toTimestamp();
|
|
9107
|
-
return
|
|
8682
|
+
return { seconds: timestamp.seconds, nanoseconds: timestamp.nanoseconds };
|
|
9108
8683
|
}
|
|
9109
8684
|
function fromDbTimestamp(dbTimestamp) {
|
|
9110
8685
|
const timestamp = new Timestamp(dbTimestamp.seconds, dbTimestamp.nanoseconds);
|
|
@@ -9114,7 +8689,13 @@ function fromDbTimestamp(dbTimestamp) {
|
|
|
9114
8689
|
function toDbMutationBatch(localSerializer, userId, batch) {
|
|
9115
8690
|
const serializedBaseMutations = batch.baseMutations.map(m => toMutation(localSerializer.remoteSerializer, m));
|
|
9116
8691
|
const serializedMutations = batch.mutations.map(m => toMutation(localSerializer.remoteSerializer, m));
|
|
9117
|
-
return
|
|
8692
|
+
return {
|
|
8693
|
+
userId,
|
|
8694
|
+
batchId: batch.batchId,
|
|
8695
|
+
localWriteTimeMs: batch.localWriteTime.toMillis(),
|
|
8696
|
+
baseMutations: serializedBaseMutations,
|
|
8697
|
+
mutations: serializedMutations
|
|
8698
|
+
};
|
|
9118
8699
|
}
|
|
9119
8700
|
/** Decodes a DbMutationBatch into a MutationBatch */
|
|
9120
8701
|
function fromDbMutationBatch(localSerializer, dbBatch) {
|
|
@@ -9170,7 +8751,15 @@ function toDbTarget(localSerializer, targetData) {
|
|
|
9170
8751
|
// convert it to a base64 string for storage.
|
|
9171
8752
|
const resumeToken = targetData.resumeToken.toBase64();
|
|
9172
8753
|
// lastListenSequenceNumber is always 0 until we do real GC.
|
|
9173
|
-
return
|
|
8754
|
+
return {
|
|
8755
|
+
targetId: targetData.targetId,
|
|
8756
|
+
canonicalId: canonifyTarget(targetData.target),
|
|
8757
|
+
readTime: dbTimestamp,
|
|
8758
|
+
resumeToken,
|
|
8759
|
+
lastListenSequenceNumber: targetData.sequenceNumber,
|
|
8760
|
+
lastLimboFreeSnapshotVersion: dbLastLimboFreeTimestamp,
|
|
8761
|
+
query: queryProto
|
|
8762
|
+
};
|
|
9174
8763
|
}
|
|
9175
8764
|
/**
|
|
9176
8765
|
* A helper function for figuring out what kind of query has been stored.
|
|
@@ -9249,7 +8838,14 @@ function fromDbDocumentOverlay(localSerializer, dbDocumentOverlay) {
|
|
|
9249
8838
|
/** Decodes an Overlay model object into a DbDocumentOverlay object. */
|
|
9250
8839
|
function toDbDocumentOverlay(localSerializer, userId, overlay) {
|
|
9251
8840
|
const [_, collectionPath, documentId] = toDbDocumentOverlayKey(userId, overlay.mutation.key);
|
|
9252
|
-
return
|
|
8841
|
+
return {
|
|
8842
|
+
userId,
|
|
8843
|
+
collectionPath,
|
|
8844
|
+
documentId,
|
|
8845
|
+
collectionGroup: overlay.mutation.key.getCollectionGroup(),
|
|
8846
|
+
largestBatchId: overlay.largestBatchId,
|
|
8847
|
+
overlayMutation: toMutation(localSerializer.remoteSerializer, overlay.mutation)
|
|
8848
|
+
};
|
|
9253
8849
|
}
|
|
9254
8850
|
/**
|
|
9255
8851
|
* Returns the DbDocumentOverlayKey corresponding to the given user and
|
|
@@ -9261,7 +8857,11 @@ function toDbDocumentOverlayKey(userId, docKey) {
|
|
|
9261
8857
|
return [userId, collectionPath, docId];
|
|
9262
8858
|
}
|
|
9263
8859
|
function toDbIndexConfiguration(index) {
|
|
9264
|
-
return
|
|
8860
|
+
return {
|
|
8861
|
+
indexId: index.indexId,
|
|
8862
|
+
collectionGroup: index.collectionGroup,
|
|
8863
|
+
fields: index.fields.map(s => [s.fieldPath.canonicalString(), s.kind])
|
|
8864
|
+
};
|
|
9265
8865
|
}
|
|
9266
8866
|
function fromDbIndexConfiguration(index, state) {
|
|
9267
8867
|
const decodedState = state
|
|
@@ -9271,7 +8871,14 @@ function fromDbIndexConfiguration(index, state) {
|
|
|
9271
8871
|
return new FieldIndex(index.indexId, index.collectionGroup, decodedSegments, decodedState);
|
|
9272
8872
|
}
|
|
9273
8873
|
function toDbIndexState(indexId, user, sequenceNumber, offset) {
|
|
9274
|
-
return
|
|
8874
|
+
return {
|
|
8875
|
+
indexId,
|
|
8876
|
+
uid: user.uid || '',
|
|
8877
|
+
sequenceNumber,
|
|
8878
|
+
readTime: toDbTimestamp(offset.readTime),
|
|
8879
|
+
documentKey: encodeResourcePath(offset.documentKey.path),
|
|
8880
|
+
largestBatchId: offset.largestBatchId
|
|
8881
|
+
};
|
|
9275
8882
|
}
|
|
9276
8883
|
|
|
9277
8884
|
/**
|
|
@@ -9322,13 +8929,13 @@ class IndexedDbBundleCache {
|
|
|
9322
8929
|
* Helper to get a typed SimpleDbStore for the bundles object store.
|
|
9323
8930
|
*/
|
|
9324
8931
|
function bundlesStore(txn) {
|
|
9325
|
-
return getStore(txn,
|
|
8932
|
+
return getStore(txn, DbBundleStore);
|
|
9326
8933
|
}
|
|
9327
8934
|
/**
|
|
9328
8935
|
* Helper to get a typed SimpleDbStore for the namedQueries object store.
|
|
9329
8936
|
*/
|
|
9330
8937
|
function namedQueriesStore(txn) {
|
|
9331
|
-
return getStore(txn,
|
|
8938
|
+
return getStore(txn, DbNamedQueryStore);
|
|
9332
8939
|
}
|
|
9333
8940
|
|
|
9334
8941
|
/**
|
|
@@ -9375,7 +8982,7 @@ class IndexedDbDocumentOverlayCache {
|
|
|
9375
8982
|
}
|
|
9376
8983
|
saveOverlays(transaction, largestBatchId, overlays) {
|
|
9377
8984
|
const promises = [];
|
|
9378
|
-
overlays.forEach(mutation => {
|
|
8985
|
+
overlays.forEach((_, mutation) => {
|
|
9379
8986
|
const overlay = new Overlay(largestBatchId, mutation);
|
|
9380
8987
|
promises.push(this.saveOverlay(transaction, overlay));
|
|
9381
8988
|
});
|
|
@@ -9390,19 +8997,19 @@ class IndexedDbDocumentOverlayCache {
|
|
|
9390
8997
|
const range = IDBKeyRange.bound([this.userId, collectionPath, batchId], [this.userId, collectionPath, batchId + 1],
|
|
9391
8998
|
/*lowerOpen=*/ false,
|
|
9392
8999
|
/*upperOpen=*/ true);
|
|
9393
|
-
promises.push(documentOverlayStore(transaction).deleteAll(
|
|
9000
|
+
promises.push(documentOverlayStore(transaction).deleteAll(DbDocumentOverlayCollectionPathOverlayIndex, range));
|
|
9394
9001
|
});
|
|
9395
9002
|
return PersistencePromise.waitFor(promises);
|
|
9396
9003
|
}
|
|
9397
9004
|
getOverlaysForCollection(transaction, collection, sinceBatchId) {
|
|
9398
|
-
const result =
|
|
9005
|
+
const result = newOverlayMap();
|
|
9399
9006
|
const collectionPath = encodeResourcePath(collection);
|
|
9400
9007
|
// We want batch IDs larger than `sinceBatchId`, and so the lower bound
|
|
9401
9008
|
// is not inclusive.
|
|
9402
9009
|
const range = IDBKeyRange.bound([this.userId, collectionPath, sinceBatchId], [this.userId, collectionPath, Number.POSITIVE_INFINITY],
|
|
9403
9010
|
/*lowerOpen=*/ true);
|
|
9404
9011
|
return documentOverlayStore(transaction)
|
|
9405
|
-
.loadAll(
|
|
9012
|
+
.loadAll(DbDocumentOverlayCollectionPathOverlayIndex, range)
|
|
9406
9013
|
.next(dbOverlays => {
|
|
9407
9014
|
for (const dbOverlay of dbOverlays) {
|
|
9408
9015
|
const overlay = fromDbDocumentOverlay(this.serializer, dbOverlay);
|
|
@@ -9412,7 +9019,7 @@ class IndexedDbDocumentOverlayCache {
|
|
|
9412
9019
|
});
|
|
9413
9020
|
}
|
|
9414
9021
|
getOverlaysForCollectionGroup(transaction, collectionGroup, sinceBatchId, count) {
|
|
9415
|
-
const result =
|
|
9022
|
+
const result = newOverlayMap();
|
|
9416
9023
|
let currentBatchId = undefined;
|
|
9417
9024
|
// We want batch IDs larger than `sinceBatchId`, and so the lower bound
|
|
9418
9025
|
// is not inclusive.
|
|
@@ -9420,7 +9027,7 @@ class IndexedDbDocumentOverlayCache {
|
|
|
9420
9027
|
/*lowerOpen=*/ true);
|
|
9421
9028
|
return documentOverlayStore(transaction)
|
|
9422
9029
|
.iterate({
|
|
9423
|
-
index:
|
|
9030
|
+
index: DbDocumentOverlayCollectionGroupOverlayIndex,
|
|
9424
9031
|
range
|
|
9425
9032
|
}, (_, dbOverlay, control) => {
|
|
9426
9033
|
// We do not want to return partial batch overlays, even if the size
|
|
@@ -9428,7 +9035,7 @@ class IndexedDbDocumentOverlayCache {
|
|
|
9428
9035
|
// continue to aggregate results even after the result size exceeds
|
|
9429
9036
|
// `count` if there are more overlays from the `currentBatchId`.
|
|
9430
9037
|
const overlay = fromDbDocumentOverlay(this.serializer, dbOverlay);
|
|
9431
|
-
if (result.size < count ||
|
|
9038
|
+
if (result.size() < count ||
|
|
9432
9039
|
overlay.largestBatchId === currentBatchId) {
|
|
9433
9040
|
result.set(overlay.getKey(), overlay);
|
|
9434
9041
|
currentBatchId = overlay.largestBatchId;
|
|
@@ -9447,7 +9054,7 @@ class IndexedDbDocumentOverlayCache {
|
|
|
9447
9054
|
* Helper to get a typed SimpleDbStore for the document overlay object store.
|
|
9448
9055
|
*/
|
|
9449
9056
|
function documentOverlayStore(txn) {
|
|
9450
|
-
return getStore(txn,
|
|
9057
|
+
return getStore(txn, DbDocumentOverlayStore);
|
|
9451
9058
|
}
|
|
9452
9059
|
|
|
9453
9060
|
/**
|
|
@@ -10202,107 +9809,6 @@ class TargetIndexMatcher {
|
|
|
10202
9809
|
}
|
|
10203
9810
|
}
|
|
10204
9811
|
|
|
10205
|
-
/**
|
|
10206
|
-
* @license
|
|
10207
|
-
* Copyright 2017 Google LLC
|
|
10208
|
-
*
|
|
10209
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
10210
|
-
* you may not use this file except in compliance with the License.
|
|
10211
|
-
* You may obtain a copy of the License at
|
|
10212
|
-
*
|
|
10213
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10214
|
-
*
|
|
10215
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
10216
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
10217
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
10218
|
-
* See the License for the specific language governing permissions and
|
|
10219
|
-
* limitations under the License.
|
|
10220
|
-
*/
|
|
10221
|
-
/**
|
|
10222
|
-
* A map implementation that uses objects as keys. Objects must have an
|
|
10223
|
-
* associated equals function and must be immutable. Entries in the map are
|
|
10224
|
-
* stored together with the key being produced from the mapKeyFn. This map
|
|
10225
|
-
* automatically handles collisions of keys.
|
|
10226
|
-
*/
|
|
10227
|
-
class ObjectMap {
|
|
10228
|
-
constructor(mapKeyFn, equalsFn) {
|
|
10229
|
-
this.mapKeyFn = mapKeyFn;
|
|
10230
|
-
this.equalsFn = equalsFn;
|
|
10231
|
-
/**
|
|
10232
|
-
* The inner map for a key/value pair. Due to the possibility of collisions we
|
|
10233
|
-
* keep a list of entries that we do a linear search through to find an actual
|
|
10234
|
-
* match. Note that collisions should be rare, so we still expect near
|
|
10235
|
-
* constant time lookups in practice.
|
|
10236
|
-
*/
|
|
10237
|
-
this.inner = {};
|
|
10238
|
-
}
|
|
10239
|
-
/** Get a value for this key, or undefined if it does not exist. */
|
|
10240
|
-
get(key) {
|
|
10241
|
-
const id = this.mapKeyFn(key);
|
|
10242
|
-
const matches = this.inner[id];
|
|
10243
|
-
if (matches === undefined) {
|
|
10244
|
-
return undefined;
|
|
10245
|
-
}
|
|
10246
|
-
for (const [otherKey, value] of matches) {
|
|
10247
|
-
if (this.equalsFn(otherKey, key)) {
|
|
10248
|
-
return value;
|
|
10249
|
-
}
|
|
10250
|
-
}
|
|
10251
|
-
return undefined;
|
|
10252
|
-
}
|
|
10253
|
-
has(key) {
|
|
10254
|
-
return this.get(key) !== undefined;
|
|
10255
|
-
}
|
|
10256
|
-
/** Put this key and value in the map. */
|
|
10257
|
-
set(key, value) {
|
|
10258
|
-
const id = this.mapKeyFn(key);
|
|
10259
|
-
const matches = this.inner[id];
|
|
10260
|
-
if (matches === undefined) {
|
|
10261
|
-
this.inner[id] = [[key, value]];
|
|
10262
|
-
return;
|
|
10263
|
-
}
|
|
10264
|
-
for (let i = 0; i < matches.length; i++) {
|
|
10265
|
-
if (this.equalsFn(matches[i][0], key)) {
|
|
10266
|
-
matches[i] = [key, value];
|
|
10267
|
-
return;
|
|
10268
|
-
}
|
|
10269
|
-
}
|
|
10270
|
-
matches.push([key, value]);
|
|
10271
|
-
}
|
|
10272
|
-
/**
|
|
10273
|
-
* Remove this key from the map. Returns a boolean if anything was deleted.
|
|
10274
|
-
*/
|
|
10275
|
-
delete(key) {
|
|
10276
|
-
const id = this.mapKeyFn(key);
|
|
10277
|
-
const matches = this.inner[id];
|
|
10278
|
-
if (matches === undefined) {
|
|
10279
|
-
return false;
|
|
10280
|
-
}
|
|
10281
|
-
for (let i = 0; i < matches.length; i++) {
|
|
10282
|
-
if (this.equalsFn(matches[i][0], key)) {
|
|
10283
|
-
if (matches.length === 1) {
|
|
10284
|
-
delete this.inner[id];
|
|
10285
|
-
}
|
|
10286
|
-
else {
|
|
10287
|
-
matches.splice(i, 1);
|
|
10288
|
-
}
|
|
10289
|
-
return true;
|
|
10290
|
-
}
|
|
10291
|
-
}
|
|
10292
|
-
return false;
|
|
10293
|
-
}
|
|
10294
|
-
forEach(fn) {
|
|
10295
|
-
forEach(this.inner, (_, entries) => {
|
|
10296
|
-
for (const [k, v] of entries) {
|
|
10297
|
-
fn(k, v);
|
|
10298
|
-
}
|
|
10299
|
-
});
|
|
10300
|
-
}
|
|
10301
|
-
isEmpty() {
|
|
10302
|
-
return isEmpty(this.inner);
|
|
10303
|
-
}
|
|
10304
|
-
}
|
|
10305
|
-
|
|
10306
9812
|
/**
|
|
10307
9813
|
* @license
|
|
10308
9814
|
* Copyright 2019 Google LLC
|
|
@@ -10555,7 +10061,7 @@ class IndexedDbIndexManager {
|
|
|
10555
10061
|
return subTargets;
|
|
10556
10062
|
}
|
|
10557
10063
|
/**
|
|
10558
|
-
* Constructs a key range query on `
|
|
10064
|
+
* Constructs a key range query on `DbIndexEntryStore` that unions all
|
|
10559
10065
|
* bounds.
|
|
10560
10066
|
*/
|
|
10561
10067
|
generateIndexRanges(indexId, arrayValues, lowerBounds, lowerBoundInclusive, upperBounds, upperBoundInclusive, notInValues) {
|
|
@@ -10707,7 +10213,7 @@ class IndexedDbIndexManager {
|
|
|
10707
10213
|
const indexes = indexConfigurationStore(transaction);
|
|
10708
10214
|
const states = indexStateStore(transaction);
|
|
10709
10215
|
return (collectionGroup
|
|
10710
|
-
? indexes.loadAll(
|
|
10216
|
+
? indexes.loadAll(DbIndexConfigurationCollectionGroupIndex, IDBKeyRange.bound(collectionGroup, collectionGroup))
|
|
10711
10217
|
: indexes.loadAll()).next(indexConfigs => {
|
|
10712
10218
|
const result = [];
|
|
10713
10219
|
return PersistencePromise.forEach(indexConfigs, (indexConfig) => {
|
|
@@ -10737,7 +10243,7 @@ class IndexedDbIndexManager {
|
|
|
10737
10243
|
const indexes = indexConfigurationStore(transaction);
|
|
10738
10244
|
const states = indexStateStore(transaction);
|
|
10739
10245
|
return this.getNextSequenceNumber(transaction).next(nextSequenceNumber => indexes
|
|
10740
|
-
.loadAll(
|
|
10246
|
+
.loadAll(DbIndexConfigurationCollectionGroupIndex, IDBKeyRange.bound(collectionGroup, collectionGroup))
|
|
10741
10247
|
.next(configs => PersistencePromise.forEach(configs, (config) => states.put(toDbIndexState(config.indexId, this.user, nextSequenceNumber, offset)))));
|
|
10742
10248
|
}
|
|
10743
10249
|
updateIndexEntries(transaction, documents) {
|
|
@@ -10768,7 +10274,13 @@ class IndexedDbIndexManager {
|
|
|
10768
10274
|
}
|
|
10769
10275
|
addIndexEntry(transaction, document, indexEntry) {
|
|
10770
10276
|
const indexEntries = indexEntriesStore(transaction);
|
|
10771
|
-
return indexEntries.put(
|
|
10277
|
+
return indexEntries.put({
|
|
10278
|
+
indexId: indexEntry.indexId,
|
|
10279
|
+
uid: this.uid,
|
|
10280
|
+
arrayValue: indexEntry.arrayValue,
|
|
10281
|
+
directionalValue: indexEntry.directionalValue,
|
|
10282
|
+
documentKey: encodeResourcePath(document.key.path)
|
|
10283
|
+
});
|
|
10772
10284
|
}
|
|
10773
10285
|
deleteIndexEntry(transaction, document, indexEntry) {
|
|
10774
10286
|
const indexEntries = indexEntriesStore(transaction);
|
|
@@ -10785,7 +10297,7 @@ class IndexedDbIndexManager {
|
|
|
10785
10297
|
let results = new SortedSet(indexEntryComparator);
|
|
10786
10298
|
return indexEntries
|
|
10787
10299
|
.iterate({
|
|
10788
|
-
index:
|
|
10300
|
+
index: DbIndexEntryDocumentKeyIndex,
|
|
10789
10301
|
range: IDBKeyRange.only([
|
|
10790
10302
|
fieldIndex.indexId,
|
|
10791
10303
|
this.uid,
|
|
@@ -10839,7 +10351,7 @@ class IndexedDbIndexManager {
|
|
|
10839
10351
|
const states = indexStateStore(transaction);
|
|
10840
10352
|
return states
|
|
10841
10353
|
.iterate({
|
|
10842
|
-
index:
|
|
10354
|
+
index: DbIndexStateSequenceNumberIndex,
|
|
10843
10355
|
reverse: true,
|
|
10844
10356
|
range: IDBKeyRange.upperBound([this.uid, Number.MAX_SAFE_INTEGER])
|
|
10845
10357
|
}, (_, state, controller) => {
|
|
@@ -10904,25 +10416,25 @@ class IndexedDbIndexManager {
|
|
|
10904
10416
|
* document store.
|
|
10905
10417
|
*/
|
|
10906
10418
|
function collectionParentsStore(txn) {
|
|
10907
|
-
return getStore(txn,
|
|
10419
|
+
return getStore(txn, DbCollectionParentStore);
|
|
10908
10420
|
}
|
|
10909
10421
|
/**
|
|
10910
10422
|
* Helper to get a typed SimpleDbStore for the index entry object store.
|
|
10911
10423
|
*/
|
|
10912
10424
|
function indexEntriesStore(txn) {
|
|
10913
|
-
return getStore(txn,
|
|
10425
|
+
return getStore(txn, DbIndexEntryStore);
|
|
10914
10426
|
}
|
|
10915
10427
|
/**
|
|
10916
10428
|
* Helper to get a typed SimpleDbStore for the index configuration object store.
|
|
10917
10429
|
*/
|
|
10918
10430
|
function indexConfigurationStore(txn) {
|
|
10919
|
-
return getStore(txn,
|
|
10431
|
+
return getStore(txn, DbIndexConfigurationStore);
|
|
10920
10432
|
}
|
|
10921
10433
|
/**
|
|
10922
10434
|
* Helper to get a typed SimpleDbStore for the index state object store.
|
|
10923
10435
|
*/
|
|
10924
10436
|
function indexStateStore(txn) {
|
|
10925
|
-
return getStore(txn,
|
|
10437
|
+
return getStore(txn, DbIndexStateStore);
|
|
10926
10438
|
}
|
|
10927
10439
|
|
|
10928
10440
|
/**
|
|
@@ -10946,8 +10458,8 @@ function indexStateStore(txn) {
|
|
|
10946
10458
|
* @returns A PersistencePromise of the document mutations that were removed.
|
|
10947
10459
|
*/
|
|
10948
10460
|
function removeMutationBatch(txn, userId, batch) {
|
|
10949
|
-
const mutationStore = txn.store(
|
|
10950
|
-
const indexTxn = txn.store(
|
|
10461
|
+
const mutationStore = txn.store(DbMutationBatchStore);
|
|
10462
|
+
const indexTxn = txn.store(DbDocumentMutationStore);
|
|
10951
10463
|
const promises = [];
|
|
10952
10464
|
const range = IDBKeyRange.only(batch.batchId);
|
|
10953
10465
|
let numDeleted = 0;
|
|
@@ -10960,7 +10472,7 @@ function removeMutationBatch(txn, userId, batch) {
|
|
|
10960
10472
|
}));
|
|
10961
10473
|
const removedDocuments = [];
|
|
10962
10474
|
for (const mutation of batch.mutations) {
|
|
10963
|
-
const indexKey =
|
|
10475
|
+
const indexKey = newDbDocumentMutationKey(userId, mutation.key.path, batch.batchId);
|
|
10964
10476
|
promises.push(indexTxn.delete(indexKey));
|
|
10965
10477
|
removedDocuments.push(mutation.key);
|
|
10966
10478
|
}
|
|
@@ -11049,7 +10561,7 @@ class IndexedDbMutationQueue {
|
|
|
11049
10561
|
let empty = true;
|
|
11050
10562
|
const range = IDBKeyRange.bound([this.userId, Number.NEGATIVE_INFINITY], [this.userId, Number.POSITIVE_INFINITY]);
|
|
11051
10563
|
return mutationsStore(transaction)
|
|
11052
|
-
.iterate({ index:
|
|
10564
|
+
.iterate({ index: DbMutationBatchUserMutationsIndex, range }, (key, value, control) => {
|
|
11053
10565
|
empty = false;
|
|
11054
10566
|
control.done();
|
|
11055
10567
|
})
|
|
@@ -11074,10 +10586,10 @@ class IndexedDbMutationQueue {
|
|
|
11074
10586
|
const promises = [];
|
|
11075
10587
|
let collectionParents = new SortedSet((l, r) => primitiveComparator(l.canonicalString(), r.canonicalString()));
|
|
11076
10588
|
for (const mutation of mutations) {
|
|
11077
|
-
const indexKey =
|
|
10589
|
+
const indexKey = newDbDocumentMutationKey(this.userId, mutation.key.path, batchId);
|
|
11078
10590
|
collectionParents = collectionParents.add(mutation.key.path.popLast());
|
|
11079
10591
|
promises.push(mutationStore.put(dbBatch));
|
|
11080
|
-
promises.push(documentStore.put(indexKey,
|
|
10592
|
+
promises.push(documentStore.put(indexKey, DbDocumentMutationPlaceholder));
|
|
11081
10593
|
}
|
|
11082
10594
|
collectionParents.forEach(parent => {
|
|
11083
10595
|
promises.push(this.indexManager.addToCollectionParentIndex(transaction, parent));
|
|
@@ -11128,7 +10640,7 @@ class IndexedDbMutationQueue {
|
|
|
11128
10640
|
const range = IDBKeyRange.lowerBound([this.userId, nextBatchId]);
|
|
11129
10641
|
let foundBatch = null;
|
|
11130
10642
|
return mutationsStore(transaction)
|
|
11131
|
-
.iterate({ index:
|
|
10643
|
+
.iterate({ index: DbMutationBatchUserMutationsIndex, range }, (key, dbBatch, control) => {
|
|
11132
10644
|
if (dbBatch.userId === this.userId) {
|
|
11133
10645
|
hardAssert(dbBatch.batchId >= nextBatchId);
|
|
11134
10646
|
foundBatch = fromDbMutationBatch(this.serializer, dbBatch);
|
|
@@ -11144,7 +10656,7 @@ class IndexedDbMutationQueue {
|
|
|
11144
10656
|
]);
|
|
11145
10657
|
let batchId = BATCHID_UNKNOWN;
|
|
11146
10658
|
return mutationsStore(transaction)
|
|
11147
|
-
.iterate({ index:
|
|
10659
|
+
.iterate({ index: DbMutationBatchUserMutationsIndex, range, reverse: true }, (key, dbBatch, control) => {
|
|
11148
10660
|
batchId = dbBatch.batchId;
|
|
11149
10661
|
control.done();
|
|
11150
10662
|
})
|
|
@@ -11153,13 +10665,13 @@ class IndexedDbMutationQueue {
|
|
|
11153
10665
|
getAllMutationBatches(transaction) {
|
|
11154
10666
|
const range = IDBKeyRange.bound([this.userId, BATCHID_UNKNOWN], [this.userId, Number.POSITIVE_INFINITY]);
|
|
11155
10667
|
return mutationsStore(transaction)
|
|
11156
|
-
.loadAll(
|
|
10668
|
+
.loadAll(DbMutationBatchUserMutationsIndex, range)
|
|
11157
10669
|
.next(dbBatches => dbBatches.map(dbBatch => fromDbMutationBatch(this.serializer, dbBatch)));
|
|
11158
10670
|
}
|
|
11159
10671
|
getAllMutationBatchesAffectingDocumentKey(transaction, documentKey) {
|
|
11160
10672
|
// Scan the document-mutation index starting with a prefix starting with
|
|
11161
10673
|
// the given documentKey.
|
|
11162
|
-
const indexPrefix =
|
|
10674
|
+
const indexPrefix = newDbDocumentMutationPrefixForPath(this.userId, documentKey.path);
|
|
11163
10675
|
const indexStart = IDBKeyRange.lowerBound(indexPrefix);
|
|
11164
10676
|
const results = [];
|
|
11165
10677
|
return documentMutationsStore(transaction)
|
|
@@ -11194,7 +10706,7 @@ class IndexedDbMutationQueue {
|
|
|
11194
10706
|
let uniqueBatchIDs = new SortedSet(primitiveComparator);
|
|
11195
10707
|
const promises = [];
|
|
11196
10708
|
documentKeys.forEach(documentKey => {
|
|
11197
|
-
const indexStart =
|
|
10709
|
+
const indexStart = newDbDocumentMutationPrefixForPath(this.userId, documentKey.path);
|
|
11198
10710
|
const range = IDBKeyRange.lowerBound(indexStart);
|
|
11199
10711
|
const promise = documentMutationsStore(transaction).iterate({ range }, (indexKey, _, control) => {
|
|
11200
10712
|
const [userID, encodedPath, batchID] = indexKey;
|
|
@@ -11230,7 +10742,7 @@ class IndexedDbMutationQueue {
|
|
|
11230
10742
|
// Since we don't yet index the actual properties in the mutations, our
|
|
11231
10743
|
// current approach is to just return all mutation batches that affect
|
|
11232
10744
|
// documents in the collection being queried.
|
|
11233
|
-
const indexPrefix =
|
|
10745
|
+
const indexPrefix = newDbDocumentMutationPrefixForPath(this.userId, queryPath);
|
|
11234
10746
|
const indexStart = IDBKeyRange.lowerBound(indexPrefix);
|
|
11235
10747
|
// Collect up unique batchIDs encountered during a scan of the index. Use a
|
|
11236
10748
|
// SortedSet to accumulate batch IDs so they can be traversed in order in a
|
|
@@ -11302,7 +10814,7 @@ class IndexedDbMutationQueue {
|
|
|
11302
10814
|
}
|
|
11303
10815
|
// Verify that there are no entries in the documentMutations index if
|
|
11304
10816
|
// the queue is empty.
|
|
11305
|
-
const startRange = IDBKeyRange.lowerBound(
|
|
10817
|
+
const startRange = IDBKeyRange.lowerBound(newDbDocumentMutationPrefixForUser(this.userId));
|
|
11306
10818
|
const danglingMutationReferences = [];
|
|
11307
10819
|
return documentMutationsStore(txn)
|
|
11308
10820
|
.iterate({ range: startRange }, (key, _, control) => {
|
|
@@ -11330,9 +10842,11 @@ class IndexedDbMutationQueue {
|
|
|
11330
10842
|
return mutationQueuesStore(transaction)
|
|
11331
10843
|
.get(this.userId)
|
|
11332
10844
|
.next((metadata) => {
|
|
11333
|
-
return (metadata ||
|
|
11334
|
-
|
|
11335
|
-
|
|
10845
|
+
return (metadata || {
|
|
10846
|
+
userId: this.userId,
|
|
10847
|
+
lastAcknowledgedBatchId: BATCHID_UNKNOWN,
|
|
10848
|
+
lastStreamToken: ''
|
|
10849
|
+
});
|
|
11336
10850
|
});
|
|
11337
10851
|
}
|
|
11338
10852
|
}
|
|
@@ -11341,7 +10855,7 @@ class IndexedDbMutationQueue {
|
|
|
11341
10855
|
* mutation for the given key.
|
|
11342
10856
|
*/
|
|
11343
10857
|
function mutationQueueContainsKey(txn, userId, key) {
|
|
11344
|
-
const indexKey =
|
|
10858
|
+
const indexKey = newDbDocumentMutationPrefixForPath(userId, key.path);
|
|
11345
10859
|
const encodedPath = indexKey[1];
|
|
11346
10860
|
const startRange = IDBKeyRange.lowerBound(indexKey);
|
|
11347
10861
|
let containsKey = false;
|
|
@@ -11373,19 +10887,19 @@ function mutationQueuesContainKey(txn, docKey) {
|
|
|
11373
10887
|
* Helper to get a typed SimpleDbStore for the mutations object store.
|
|
11374
10888
|
*/
|
|
11375
10889
|
function mutationsStore(txn) {
|
|
11376
|
-
return getStore(txn,
|
|
10890
|
+
return getStore(txn, DbMutationBatchStore);
|
|
11377
10891
|
}
|
|
11378
10892
|
/**
|
|
11379
10893
|
* Helper to get a typed SimpleDbStore for the mutationQueues object store.
|
|
11380
10894
|
*/
|
|
11381
10895
|
function documentMutationsStore(txn) {
|
|
11382
|
-
return getStore(txn,
|
|
10896
|
+
return getStore(txn, DbDocumentMutationStore);
|
|
11383
10897
|
}
|
|
11384
10898
|
/**
|
|
11385
10899
|
* Helper to get a typed SimpleDbStore for the mutationQueues object store.
|
|
11386
10900
|
*/
|
|
11387
10901
|
function mutationQueuesStore(txn) {
|
|
11388
|
-
return getStore(txn,
|
|
10902
|
+
return getStore(txn, DbMutationQueueStore);
|
|
11389
10903
|
}
|
|
11390
10904
|
|
|
11391
10905
|
/**
|
|
@@ -11549,14 +11063,14 @@ class IndexedDbTargetCache {
|
|
|
11549
11063
|
}
|
|
11550
11064
|
retrieveMetadata(transaction) {
|
|
11551
11065
|
return globalTargetStore(transaction)
|
|
11552
|
-
.get(
|
|
11066
|
+
.get(DbTargetGlobalKey)
|
|
11553
11067
|
.next(metadata => {
|
|
11554
11068
|
hardAssert(metadata !== null);
|
|
11555
11069
|
return metadata;
|
|
11556
11070
|
});
|
|
11557
11071
|
}
|
|
11558
11072
|
saveMetadata(transaction, metadata) {
|
|
11559
|
-
return globalTargetStore(transaction).put(
|
|
11073
|
+
return globalTargetStore(transaction).put(DbTargetGlobalKey, metadata);
|
|
11560
11074
|
}
|
|
11561
11075
|
saveTargetData(transaction, targetData) {
|
|
11562
11076
|
return targetsStore(transaction).put(toDbTarget(this.serializer, targetData));
|
|
@@ -11589,7 +11103,7 @@ class IndexedDbTargetCache {
|
|
|
11589
11103
|
const range = IDBKeyRange.bound([canonicalId, Number.NEGATIVE_INFINITY], [canonicalId, Number.POSITIVE_INFINITY]);
|
|
11590
11104
|
let result = null;
|
|
11591
11105
|
return targetsStore(transaction)
|
|
11592
|
-
.iterate({ range, index:
|
|
11106
|
+
.iterate({ range, index: DbTargetQueryTargetsIndexName }, (key, value, control) => {
|
|
11593
11107
|
const found = fromDbTarget(value);
|
|
11594
11108
|
// After finding a potential match, check that the target is
|
|
11595
11109
|
// actually equal to the requested target.
|
|
@@ -11607,7 +11121,7 @@ class IndexedDbTargetCache {
|
|
|
11607
11121
|
const store = documentTargetStore(txn);
|
|
11608
11122
|
keys.forEach(key => {
|
|
11609
11123
|
const path = encodeResourcePath(key.path);
|
|
11610
|
-
promises.push(store.put(
|
|
11124
|
+
promises.push(store.put({ targetId, path }));
|
|
11611
11125
|
promises.push(this.referenceDelegate.addReference(txn, targetId, key));
|
|
11612
11126
|
});
|
|
11613
11127
|
return PersistencePromise.waitFor(promises);
|
|
@@ -11653,7 +11167,7 @@ class IndexedDbTargetCache {
|
|
|
11653
11167
|
let count = 0;
|
|
11654
11168
|
return documentTargetStore(txn)
|
|
11655
11169
|
.iterate({
|
|
11656
|
-
index:
|
|
11170
|
+
index: DbTargetDocumentDocumentTargetsIndex,
|
|
11657
11171
|
keysOnly: true,
|
|
11658
11172
|
range
|
|
11659
11173
|
}, ([targetId, path], _, control) => {
|
|
@@ -11692,19 +11206,19 @@ class IndexedDbTargetCache {
|
|
|
11692
11206
|
* Helper to get a typed SimpleDbStore for the queries object store.
|
|
11693
11207
|
*/
|
|
11694
11208
|
function targetsStore(txn) {
|
|
11695
|
-
return getStore(txn,
|
|
11209
|
+
return getStore(txn, DbTargetStore);
|
|
11696
11210
|
}
|
|
11697
11211
|
/**
|
|
11698
11212
|
* Helper to get a typed SimpleDbStore for the target globals object store.
|
|
11699
11213
|
*/
|
|
11700
11214
|
function globalTargetStore(txn) {
|
|
11701
|
-
return getStore(txn,
|
|
11215
|
+
return getStore(txn, DbTargetGlobalStore);
|
|
11702
11216
|
}
|
|
11703
11217
|
/**
|
|
11704
11218
|
* Helper to get a typed SimpleDbStore for the document target object store.
|
|
11705
11219
|
*/
|
|
11706
11220
|
function documentTargetStore(txn) {
|
|
11707
|
-
return getStore(txn,
|
|
11221
|
+
return getStore(txn, DbTargetDocumentStore);
|
|
11708
11222
|
}
|
|
11709
11223
|
|
|
11710
11224
|
/**
|
|
@@ -12118,7 +11632,7 @@ class IndexedDbLruDelegateImpl {
|
|
|
12118
11632
|
let nextPath;
|
|
12119
11633
|
return store
|
|
12120
11634
|
.iterate({
|
|
12121
|
-
index:
|
|
11635
|
+
index: DbTargetDocumentDocumentTargetsIndex
|
|
12122
11636
|
}, ([targetId, docKey], { path, sequenceNumber }) => {
|
|
12123
11637
|
if (targetId === 0) {
|
|
12124
11638
|
// if nextToReport is valid, report it, this is a new key so the
|
|
@@ -12160,7 +11674,7 @@ function sentinelKey$1(key) {
|
|
|
12160
11674
|
* store.
|
|
12161
11675
|
*/
|
|
12162
11676
|
function sentinelRow(key, sequenceNumber) {
|
|
12163
|
-
return
|
|
11677
|
+
return { targetId: 0, path: encodeResourcePath(key.path), sequenceNumber };
|
|
12164
11678
|
}
|
|
12165
11679
|
function writeSentinelKey(txn, key) {
|
|
12166
11680
|
return documentTargetStore(txn).put(sentinelRow(key, txn.currentSequenceNumber));
|
|
@@ -12434,7 +11948,7 @@ class IndexedDbRemoteDocumentCacheImpl {
|
|
|
12434
11948
|
const readTimeKey = toDbTimestampKey(sinceReadTime);
|
|
12435
11949
|
iterationOptions.range = IDBKeyRange.lowerBound([collectionKey, readTimeKey],
|
|
12436
11950
|
/* open= */ true);
|
|
12437
|
-
iterationOptions.index =
|
|
11951
|
+
iterationOptions.index = DbRemoteDocumentCollectionReadTimeIndex;
|
|
12438
11952
|
}
|
|
12439
11953
|
return remoteDocumentsStore(transaction)
|
|
12440
11954
|
.iterate(iterationOptions, (key, dbRemoteDoc, control) => {
|
|
@@ -12464,14 +11978,14 @@ class IndexedDbRemoteDocumentCacheImpl {
|
|
|
12464
11978
|
}
|
|
12465
11979
|
getMetadata(txn) {
|
|
12466
11980
|
return documentGlobalStore(txn)
|
|
12467
|
-
.get(
|
|
11981
|
+
.get(DbRemoteDocumentGlobalKey)
|
|
12468
11982
|
.next(metadata => {
|
|
12469
11983
|
hardAssert(!!metadata);
|
|
12470
11984
|
return metadata;
|
|
12471
11985
|
});
|
|
12472
11986
|
}
|
|
12473
11987
|
setMetadata(txn, metadata) {
|
|
12474
|
-
return documentGlobalStore(txn).put(
|
|
11988
|
+
return documentGlobalStore(txn).put(DbRemoteDocumentGlobalKey, metadata);
|
|
12475
11989
|
}
|
|
12476
11990
|
/**
|
|
12477
11991
|
* Decodes `dbRemoteDoc` and returns the document (or an invalid document if
|
|
@@ -12506,7 +12020,7 @@ function remoteDocumentCacheGetNewDocumentChanges(remoteDocumentCache, transacti
|
|
|
12506
12020
|
const documentsStore = remoteDocumentsStore(transaction);
|
|
12507
12021
|
const range = IDBKeyRange.lowerBound(lastReadTime, true);
|
|
12508
12022
|
return documentsStore
|
|
12509
|
-
.iterate({ index:
|
|
12023
|
+
.iterate({ index: DbRemoteDocumentReadTimeIndex, range }, (_, dbRemoteDoc) => {
|
|
12510
12024
|
// Unlike `getEntry()` and others, `getNewDocumentChanges()` parses
|
|
12511
12025
|
// the documents directly since we want to keep sentinel deletes.
|
|
12512
12026
|
const doc = fromDbRemoteDocument(remoteDocumentCacheImpl.serializer, dbRemoteDoc);
|
|
@@ -12530,7 +12044,7 @@ function remoteDocumentCacheGetLastReadTime(transaction) {
|
|
|
12530
12044
|
// If there are no existing entries, we return SnapshotVersion.min().
|
|
12531
12045
|
let readTime = SnapshotVersion.min();
|
|
12532
12046
|
return documentsStore
|
|
12533
|
-
.iterate({ index:
|
|
12047
|
+
.iterate({ index: DbRemoteDocumentReadTimeIndex, reverse: true }, (key, dbRemoteDoc, control) => {
|
|
12534
12048
|
if (dbRemoteDoc.readTime) {
|
|
12535
12049
|
readTime = fromDbTimestampKey(dbRemoteDoc.readTime);
|
|
12536
12050
|
}
|
|
@@ -12618,17 +12132,39 @@ class IndexedDbRemoteDocumentChangeBuffer extends RemoteDocumentChangeBuffer {
|
|
|
12618
12132
|
}
|
|
12619
12133
|
}
|
|
12620
12134
|
function documentGlobalStore(txn) {
|
|
12621
|
-
return getStore(txn,
|
|
12135
|
+
return getStore(txn, DbRemoteDocumentGlobalStore);
|
|
12622
12136
|
}
|
|
12623
12137
|
/**
|
|
12624
12138
|
* Helper to get a typed SimpleDbStore for the remoteDocuments object store.
|
|
12625
12139
|
*/
|
|
12626
12140
|
function remoteDocumentsStore(txn) {
|
|
12627
|
-
return getStore(txn,
|
|
12141
|
+
return getStore(txn, DbRemoteDocumentStore);
|
|
12628
12142
|
}
|
|
12629
12143
|
function dbKey(docKey) {
|
|
12630
12144
|
return docKey.path.toArray();
|
|
12631
12145
|
}
|
|
12146
|
+
/**
|
|
12147
|
+
* Schema Version for the Web client:
|
|
12148
|
+
* 1. Initial version including Mutation Queue, Query Cache, and Remote
|
|
12149
|
+
* Document Cache
|
|
12150
|
+
* 2. Used to ensure a targetGlobal object exists and add targetCount to it. No
|
|
12151
|
+
* longer required because migration 3 unconditionally clears it.
|
|
12152
|
+
* 3. Dropped and re-created Query Cache to deal with cache corruption related
|
|
12153
|
+
* to limbo resolution. Addresses
|
|
12154
|
+
* https://github.com/firebase/firebase-ios-sdk/issues/1548
|
|
12155
|
+
* 4. Multi-Tab Support.
|
|
12156
|
+
* 5. Removal of held write acks.
|
|
12157
|
+
* 6. Create document global for tracking document cache size.
|
|
12158
|
+
* 7. Ensure every cached document has a sentinel row with a sequence number.
|
|
12159
|
+
* 8. Add collection-parent index for Collection Group queries.
|
|
12160
|
+
* 9. Change RemoteDocumentChanges store to be keyed by readTime rather than
|
|
12161
|
+
* an auto-incrementing ID. This is required for Index-Free queries.
|
|
12162
|
+
* 10. Rewrite the canonical IDs to the explicit Protobuf-based format.
|
|
12163
|
+
* 11. Add bundles and named_queries for bundle support.
|
|
12164
|
+
* 12. Add document overlays.
|
|
12165
|
+
* 13. Add indexing support.
|
|
12166
|
+
*/
|
|
12167
|
+
const SCHEMA_VERSION = 12;
|
|
12632
12168
|
|
|
12633
12169
|
/**
|
|
12634
12170
|
* @license
|
|
@@ -12738,27 +12274,27 @@ class SchemaConverter {
|
|
|
12738
12274
|
return p;
|
|
12739
12275
|
}
|
|
12740
12276
|
addDocumentGlobal(txn) {
|
|
12741
|
-
let
|
|
12277
|
+
let byteSize = 0;
|
|
12742
12278
|
return txn
|
|
12743
|
-
.store(
|
|
12279
|
+
.store(DbRemoteDocumentStore)
|
|
12744
12280
|
.iterate((_, doc) => {
|
|
12745
|
-
|
|
12281
|
+
byteSize += dbDocumentSize(doc);
|
|
12746
12282
|
})
|
|
12747
12283
|
.next(() => {
|
|
12748
|
-
const metadata =
|
|
12284
|
+
const metadata = { byteSize };
|
|
12749
12285
|
return txn
|
|
12750
|
-
.store(
|
|
12751
|
-
.put(
|
|
12286
|
+
.store(DbRemoteDocumentGlobalStore)
|
|
12287
|
+
.put(DbRemoteDocumentGlobalKey, metadata);
|
|
12752
12288
|
});
|
|
12753
12289
|
}
|
|
12754
12290
|
removeAcknowledgedMutations(txn) {
|
|
12755
|
-
const queuesStore = txn.store(
|
|
12756
|
-
const mutationsStore = txn.store(
|
|
12291
|
+
const queuesStore = txn.store(DbMutationQueueStore);
|
|
12292
|
+
const mutationsStore = txn.store(DbMutationBatchStore);
|
|
12757
12293
|
return queuesStore.loadAll().next(queues => {
|
|
12758
12294
|
return PersistencePromise.forEach(queues, (queue) => {
|
|
12759
12295
|
const range = IDBKeyRange.bound([queue.userId, BATCHID_UNKNOWN], [queue.userId, queue.lastAcknowledgedBatchId]);
|
|
12760
12296
|
return mutationsStore
|
|
12761
|
-
.loadAll(
|
|
12297
|
+
.loadAll(DbMutationBatchUserMutationsIndex, range)
|
|
12762
12298
|
.next(dbBatches => {
|
|
12763
12299
|
return PersistencePromise.forEach(dbBatches, (dbBatch) => {
|
|
12764
12300
|
hardAssert(dbBatch.userId === queue.userId);
|
|
@@ -12774,12 +12310,16 @@ class SchemaConverter {
|
|
|
12774
12310
|
* with a sequence number. Missing rows are given the most recently used sequence number.
|
|
12775
12311
|
*/
|
|
12776
12312
|
ensureSequenceNumbers(txn) {
|
|
12777
|
-
const documentTargetStore = txn.store(
|
|
12778
|
-
const documentsStore = txn.store(
|
|
12779
|
-
const globalTargetStore = txn.store(
|
|
12780
|
-
return globalTargetStore.get(
|
|
12313
|
+
const documentTargetStore = txn.store(DbTargetDocumentStore);
|
|
12314
|
+
const documentsStore = txn.store(DbRemoteDocumentStore);
|
|
12315
|
+
const globalTargetStore = txn.store(DbTargetGlobalStore);
|
|
12316
|
+
return globalTargetStore.get(DbTargetGlobalKey).next(metadata => {
|
|
12781
12317
|
const writeSentinelKey = (path) => {
|
|
12782
|
-
return documentTargetStore.put(
|
|
12318
|
+
return documentTargetStore.put({
|
|
12319
|
+
targetId: 0,
|
|
12320
|
+
path: encodeResourcePath(path),
|
|
12321
|
+
sequenceNumber: metadata.highestListenSequenceNumber
|
|
12322
|
+
});
|
|
12783
12323
|
};
|
|
12784
12324
|
const promises = [];
|
|
12785
12325
|
return documentsStore
|
|
@@ -12800,10 +12340,10 @@ class SchemaConverter {
|
|
|
12800
12340
|
}
|
|
12801
12341
|
createCollectionParentIndex(db, txn) {
|
|
12802
12342
|
// Create the index.
|
|
12803
|
-
db.createObjectStore(
|
|
12804
|
-
keyPath:
|
|
12343
|
+
db.createObjectStore(DbCollectionParentStore, {
|
|
12344
|
+
keyPath: DbCollectionParentKeyPath
|
|
12805
12345
|
});
|
|
12806
|
-
const collectionParentsStore = txn.store(
|
|
12346
|
+
const collectionParentsStore = txn.store(DbCollectionParentStore);
|
|
12807
12347
|
// Helper to add an index entry iff we haven't already written it.
|
|
12808
12348
|
const cache = new MemoryCollectionParentIndex();
|
|
12809
12349
|
const addEntry = (collectionPath) => {
|
|
@@ -12818,7 +12358,7 @@ class SchemaConverter {
|
|
|
12818
12358
|
};
|
|
12819
12359
|
// Index existing remote documents.
|
|
12820
12360
|
return txn
|
|
12821
|
-
.store(
|
|
12361
|
+
.store(DbRemoteDocumentStore)
|
|
12822
12362
|
.iterate({ keysOnly: true }, (pathSegments, _) => {
|
|
12823
12363
|
const path = new ResourcePath(pathSegments);
|
|
12824
12364
|
return addEntry(path.popLast());
|
|
@@ -12826,7 +12366,7 @@ class SchemaConverter {
|
|
|
12826
12366
|
.next(() => {
|
|
12827
12367
|
// Index existing mutations.
|
|
12828
12368
|
return txn
|
|
12829
|
-
.store(
|
|
12369
|
+
.store(DbDocumentMutationStore)
|
|
12830
12370
|
.iterate({ keysOnly: true }, ([userID, encodedPath, batchId], _) => {
|
|
12831
12371
|
const path = decodeResourcePath(encodedPath);
|
|
12832
12372
|
return addEntry(path.popLast());
|
|
@@ -12834,7 +12374,7 @@ class SchemaConverter {
|
|
|
12834
12374
|
});
|
|
12835
12375
|
}
|
|
12836
12376
|
rewriteCanonicalIds(txn) {
|
|
12837
|
-
const targetStore = txn.store(
|
|
12377
|
+
const targetStore = txn.store(DbTargetStore);
|
|
12838
12378
|
return targetStore.iterate((key, originalDbTarget) => {
|
|
12839
12379
|
const originalTargetData = fromDbTarget(originalDbTarget);
|
|
12840
12380
|
const updatedDbTarget = toDbTarget(this.serializer, originalTargetData);
|
|
@@ -12846,59 +12386,59 @@ function sentinelKey(path) {
|
|
|
12846
12386
|
return [0, encodeResourcePath(path)];
|
|
12847
12387
|
}
|
|
12848
12388
|
function createPrimaryClientStore(db) {
|
|
12849
|
-
db.createObjectStore(
|
|
12389
|
+
db.createObjectStore(DbPrimaryClientStore);
|
|
12850
12390
|
}
|
|
12851
12391
|
function createMutationQueue(db) {
|
|
12852
|
-
db.createObjectStore(
|
|
12853
|
-
keyPath:
|
|
12392
|
+
db.createObjectStore(DbMutationQueueStore, {
|
|
12393
|
+
keyPath: DbMutationQueueKeyPath
|
|
12854
12394
|
});
|
|
12855
|
-
const mutationBatchesStore = db.createObjectStore(
|
|
12856
|
-
keyPath:
|
|
12395
|
+
const mutationBatchesStore = db.createObjectStore(DbMutationBatchStore, {
|
|
12396
|
+
keyPath: DbMutationBatchKeyPath,
|
|
12857
12397
|
autoIncrement: true
|
|
12858
12398
|
});
|
|
12859
|
-
mutationBatchesStore.createIndex(
|
|
12860
|
-
db.createObjectStore(
|
|
12399
|
+
mutationBatchesStore.createIndex(DbMutationBatchUserMutationsIndex, DbMutationBatchUserMutationsKeyPath, { unique: true });
|
|
12400
|
+
db.createObjectStore(DbDocumentMutationStore);
|
|
12861
12401
|
}
|
|
12862
12402
|
/**
|
|
12863
12403
|
* Upgrade function to migrate the 'mutations' store from V1 to V3. Loads
|
|
12864
12404
|
* and rewrites all data.
|
|
12865
12405
|
*/
|
|
12866
12406
|
function upgradeMutationBatchSchemaAndMigrateData(db, txn) {
|
|
12867
|
-
const v1MutationsStore = txn.store(
|
|
12407
|
+
const v1MutationsStore = txn.store(DbMutationBatchStore);
|
|
12868
12408
|
return v1MutationsStore.loadAll().next(existingMutations => {
|
|
12869
|
-
db.deleteObjectStore(
|
|
12870
|
-
const mutationsStore = db.createObjectStore(
|
|
12871
|
-
keyPath:
|
|
12409
|
+
db.deleteObjectStore(DbMutationBatchStore);
|
|
12410
|
+
const mutationsStore = db.createObjectStore(DbMutationBatchStore, {
|
|
12411
|
+
keyPath: DbMutationBatchKeyPath,
|
|
12872
12412
|
autoIncrement: true
|
|
12873
12413
|
});
|
|
12874
|
-
mutationsStore.createIndex(
|
|
12875
|
-
const v3MutationsStore = txn.store(
|
|
12414
|
+
mutationsStore.createIndex(DbMutationBatchUserMutationsIndex, DbMutationBatchUserMutationsKeyPath, { unique: true });
|
|
12415
|
+
const v3MutationsStore = txn.store(DbMutationBatchStore);
|
|
12876
12416
|
const writeAll = existingMutations.map(mutation => v3MutationsStore.put(mutation));
|
|
12877
12417
|
return PersistencePromise.waitFor(writeAll);
|
|
12878
12418
|
});
|
|
12879
12419
|
}
|
|
12880
12420
|
function createRemoteDocumentCache(db) {
|
|
12881
|
-
db.createObjectStore(
|
|
12421
|
+
db.createObjectStore(DbRemoteDocumentStore);
|
|
12882
12422
|
}
|
|
12883
12423
|
function createDocumentGlobalStore(db) {
|
|
12884
|
-
db.createObjectStore(
|
|
12424
|
+
db.createObjectStore(DbRemoteDocumentGlobalStore);
|
|
12885
12425
|
}
|
|
12886
12426
|
function createQueryCache(db) {
|
|
12887
|
-
const targetDocumentsStore = db.createObjectStore(
|
|
12888
|
-
keyPath:
|
|
12427
|
+
const targetDocumentsStore = db.createObjectStore(DbTargetDocumentStore, {
|
|
12428
|
+
keyPath: DbTargetDocumentKeyPath
|
|
12889
12429
|
});
|
|
12890
|
-
targetDocumentsStore.createIndex(
|
|
12891
|
-
const targetStore = db.createObjectStore(
|
|
12892
|
-
keyPath:
|
|
12430
|
+
targetDocumentsStore.createIndex(DbTargetDocumentDocumentTargetsIndex, DbTargetDocumentDocumentTargetsKeyPath, { unique: true });
|
|
12431
|
+
const targetStore = db.createObjectStore(DbTargetStore, {
|
|
12432
|
+
keyPath: DbTargetKeyPath
|
|
12893
12433
|
});
|
|
12894
12434
|
// NOTE: This is unique only because the TargetId is the suffix.
|
|
12895
|
-
targetStore.createIndex(
|
|
12896
|
-
db.createObjectStore(
|
|
12435
|
+
targetStore.createIndex(DbTargetQueryTargetsIndexName, DbTargetQueryTargetsKeyPath, { unique: true });
|
|
12436
|
+
db.createObjectStore(DbTargetGlobalStore);
|
|
12897
12437
|
}
|
|
12898
12438
|
function dropQueryCache(db) {
|
|
12899
|
-
db.deleteObjectStore(
|
|
12900
|
-
db.deleteObjectStore(
|
|
12901
|
-
db.deleteObjectStore(
|
|
12439
|
+
db.deleteObjectStore(DbTargetDocumentStore);
|
|
12440
|
+
db.deleteObjectStore(DbTargetStore);
|
|
12441
|
+
db.deleteObjectStore(DbTargetGlobalStore);
|
|
12902
12442
|
}
|
|
12903
12443
|
function dropRemoteDocumentChangesStore(db) {
|
|
12904
12444
|
if (db.objectStoreNames.contains('remoteDocumentChanges')) {
|
|
@@ -12911,58 +12451,60 @@ function dropRemoteDocumentChangesStore(db) {
|
|
|
12911
12451
|
* @param txn - The version upgrade transaction for indexeddb
|
|
12912
12452
|
*/
|
|
12913
12453
|
function writeEmptyTargetGlobalEntry(txn) {
|
|
12914
|
-
const globalStore = txn.store(
|
|
12915
|
-
const metadata =
|
|
12916
|
-
|
|
12917
|
-
|
|
12918
|
-
|
|
12919
|
-
|
|
12454
|
+
const globalStore = txn.store(DbTargetGlobalStore);
|
|
12455
|
+
const metadata = {
|
|
12456
|
+
highestTargetId: 0,
|
|
12457
|
+
highestListenSequenceNumber: 0,
|
|
12458
|
+
lastRemoteSnapshotVersion: SnapshotVersion.min().toTimestamp(),
|
|
12459
|
+
targetCount: 0
|
|
12460
|
+
};
|
|
12461
|
+
return globalStore.put(DbTargetGlobalKey, metadata);
|
|
12920
12462
|
}
|
|
12921
12463
|
/**
|
|
12922
12464
|
* Creates indices on the RemoteDocuments store used for both multi-tab
|
|
12923
12465
|
* and Index-Free queries.
|
|
12924
12466
|
*/
|
|
12925
12467
|
function createRemoteDocumentReadTimeIndex(txn) {
|
|
12926
|
-
const remoteDocumentStore = txn.objectStore(
|
|
12927
|
-
remoteDocumentStore.createIndex(
|
|
12928
|
-
remoteDocumentStore.createIndex(
|
|
12468
|
+
const remoteDocumentStore = txn.objectStore(DbRemoteDocumentStore);
|
|
12469
|
+
remoteDocumentStore.createIndex(DbRemoteDocumentReadTimeIndex, DbRemoteDocumentReadTimeIndexPath, { unique: false });
|
|
12470
|
+
remoteDocumentStore.createIndex(DbRemoteDocumentCollectionReadTimeIndex, DbRemoteDocumentCollectionReadTimeIndexPath, { unique: false });
|
|
12929
12471
|
}
|
|
12930
12472
|
function createClientMetadataStore(db) {
|
|
12931
|
-
db.createObjectStore(
|
|
12932
|
-
keyPath:
|
|
12473
|
+
db.createObjectStore(DbClientMetadataStore, {
|
|
12474
|
+
keyPath: DbClientMetadataKeyPath
|
|
12933
12475
|
});
|
|
12934
12476
|
}
|
|
12935
12477
|
function createBundlesStore(db) {
|
|
12936
|
-
db.createObjectStore(
|
|
12937
|
-
keyPath:
|
|
12478
|
+
db.createObjectStore(DbBundleStore, {
|
|
12479
|
+
keyPath: DbBundleKeyPath
|
|
12938
12480
|
});
|
|
12939
12481
|
}
|
|
12940
12482
|
function createNamedQueriesStore(db) {
|
|
12941
|
-
db.createObjectStore(
|
|
12942
|
-
keyPath:
|
|
12483
|
+
db.createObjectStore(DbNamedQueryStore, {
|
|
12484
|
+
keyPath: DbNamedQueryKeyPath
|
|
12943
12485
|
});
|
|
12944
12486
|
}
|
|
12945
12487
|
function createFieldIndex(db) {
|
|
12946
|
-
const indexConfiguratioStore = db.createObjectStore(
|
|
12947
|
-
keyPath:
|
|
12488
|
+
const indexConfiguratioStore = db.createObjectStore(DbIndexConfigurationStore, {
|
|
12489
|
+
keyPath: DbIndexConfigurationKeyPath,
|
|
12948
12490
|
autoIncrement: true
|
|
12949
12491
|
});
|
|
12950
|
-
indexConfiguratioStore.createIndex(
|
|
12951
|
-
const indexStateStore = db.createObjectStore(
|
|
12952
|
-
keyPath:
|
|
12492
|
+
indexConfiguratioStore.createIndex(DbIndexConfigurationCollectionGroupIndex, DbIndexConfigurationCollectionGroupIndexPath, { unique: false });
|
|
12493
|
+
const indexStateStore = db.createObjectStore(DbIndexStateStore, {
|
|
12494
|
+
keyPath: DbIndexStateKeyPath
|
|
12953
12495
|
});
|
|
12954
|
-
indexStateStore.createIndex(
|
|
12955
|
-
const indexEntryStore = db.createObjectStore(
|
|
12956
|
-
keyPath:
|
|
12496
|
+
indexStateStore.createIndex(DbIndexStateSequenceNumberIndex, DbIndexStateSequenceNumberIndexPath, { unique: false });
|
|
12497
|
+
const indexEntryStore = db.createObjectStore(DbIndexEntryStore, {
|
|
12498
|
+
keyPath: DbIndexEntryKeyPath
|
|
12957
12499
|
});
|
|
12958
|
-
indexEntryStore.createIndex(
|
|
12500
|
+
indexEntryStore.createIndex(DbIndexEntryDocumentKeyIndex, DbIndexEntryDocumentKeyIndexPath, { unique: false });
|
|
12959
12501
|
}
|
|
12960
12502
|
function createDocumentOverlayStore(db) {
|
|
12961
|
-
const documentOverlayStore = db.createObjectStore(
|
|
12962
|
-
keyPath:
|
|
12503
|
+
const documentOverlayStore = db.createObjectStore(DbDocumentOverlayStore, {
|
|
12504
|
+
keyPath: DbDocumentOverlayKeyPath
|
|
12963
12505
|
});
|
|
12964
|
-
documentOverlayStore.createIndex(
|
|
12965
|
-
documentOverlayStore.createIndex(
|
|
12506
|
+
documentOverlayStore.createIndex(DbDocumentOverlayCollectionPathOverlayIndex, DbDocumentOverlayCollectionPathOverlayIndexPath, { unique: false });
|
|
12507
|
+
documentOverlayStore.createIndex(DbDocumentOverlayCollectionGroupOverlayIndex, DbDocumentOverlayCollectionGroupOverlayIndexPath, { unique: false });
|
|
12966
12508
|
}
|
|
12967
12509
|
|
|
12968
12510
|
/**
|
|
@@ -13210,7 +12752,12 @@ class IndexedDbPersistence {
|
|
|
13210
12752
|
return this.runTransaction('updateClientMetadataAndTryBecomePrimary', 'readwrite', txn => {
|
|
13211
12753
|
const metadataStore = clientMetadataStore(txn);
|
|
13212
12754
|
return metadataStore
|
|
13213
|
-
.put(
|
|
12755
|
+
.put({
|
|
12756
|
+
clientId: this.clientId,
|
|
12757
|
+
updateTimeMs: Date.now(),
|
|
12758
|
+
networkEnabled: this.networkEnabled,
|
|
12759
|
+
inForeground: this.inForeground
|
|
12760
|
+
})
|
|
13214
12761
|
.next(() => {
|
|
13215
12762
|
if (this.isPrimary) {
|
|
13216
12763
|
return this.verifyPrimaryLease(txn).next(success => {
|
|
@@ -13256,7 +12803,7 @@ class IndexedDbPersistence {
|
|
|
13256
12803
|
}
|
|
13257
12804
|
verifyPrimaryLease(txn) {
|
|
13258
12805
|
const store = primaryClientStore(txn);
|
|
13259
|
-
return store.get(
|
|
12806
|
+
return store.get(DbPrimaryClientKey).next(primaryClient => {
|
|
13260
12807
|
return PersistencePromise.resolve(this.isLocalClient(primaryClient));
|
|
13261
12808
|
});
|
|
13262
12809
|
}
|
|
@@ -13274,7 +12821,7 @@ class IndexedDbPersistence {
|
|
|
13274
12821
|
!this.isWithinAge(this.lastGarbageCollectionTime, MAX_CLIENT_AGE_MS)) {
|
|
13275
12822
|
this.lastGarbageCollectionTime = Date.now();
|
|
13276
12823
|
const inactiveClients = await this.runTransaction('maybeGarbageCollectMultiClientState', 'readwrite-primary', txn => {
|
|
13277
|
-
const metadataStore = getStore(txn,
|
|
12824
|
+
const metadataStore = getStore(txn, DbClientMetadataStore);
|
|
13278
12825
|
return metadataStore.loadAll().next(existingClients => {
|
|
13279
12826
|
const active = this.filterActiveClients(existingClients, MAX_CLIENT_AGE_MS);
|
|
13280
12827
|
const inactive = existingClients.filter(client => active.indexOf(client) === -1);
|
|
@@ -13328,7 +12875,7 @@ class IndexedDbPersistence {
|
|
|
13328
12875
|
}
|
|
13329
12876
|
const store = primaryClientStore(txn);
|
|
13330
12877
|
return store
|
|
13331
|
-
.get(
|
|
12878
|
+
.get(DbPrimaryClientKey)
|
|
13332
12879
|
.next(currentPrimary => {
|
|
13333
12880
|
const currentLeaseIsValid = currentPrimary !== null &&
|
|
13334
12881
|
this.isWithinAge(currentPrimary.leaseTimestampMs, MAX_PRIMARY_ELIGIBLE_AGE_MS) &&
|
|
@@ -13409,7 +12956,7 @@ class IndexedDbPersistence {
|
|
|
13409
12956
|
this.detachWindowUnloadHook();
|
|
13410
12957
|
// Use `SimpleDb.runTransaction` directly to avoid failing if another tab
|
|
13411
12958
|
// has obtained the primary lease.
|
|
13412
|
-
await this.simpleDb.runTransaction('shutdown', 'readwrite', [
|
|
12959
|
+
await this.simpleDb.runTransaction('shutdown', 'readwrite', [DbPrimaryClientStore, DbClientMetadataStore], simpleDbTxn => {
|
|
13413
12960
|
const persistenceTransaction = new IndexedDbTransaction(simpleDbTxn, ListenSequence.INVALID);
|
|
13414
12961
|
return this.releasePrimaryLeaseIfHeld(persistenceTransaction).next(() => this.removeClientMetadata(persistenceTransaction));
|
|
13415
12962
|
});
|
|
@@ -13516,7 +13063,7 @@ class IndexedDbPersistence {
|
|
|
13516
13063
|
// be turned off.
|
|
13517
13064
|
verifyAllowTabSynchronization(txn) {
|
|
13518
13065
|
const store = primaryClientStore(txn);
|
|
13519
|
-
return store.get(
|
|
13066
|
+
return store.get(DbPrimaryClientKey).next(currentPrimary => {
|
|
13520
13067
|
const currentLeaseIsValid = currentPrimary !== null &&
|
|
13521
13068
|
this.isWithinAge(currentPrimary.leaseTimestampMs, MAX_PRIMARY_ELIGIBLE_AGE_MS) &&
|
|
13522
13069
|
!this.isClientZombied(currentPrimary.ownerId);
|
|
@@ -13534,8 +13081,12 @@ class IndexedDbPersistence {
|
|
|
13534
13081
|
* method does not verify that the client is eligible for this lease.
|
|
13535
13082
|
*/
|
|
13536
13083
|
acquireOrExtendPrimaryLease(txn) {
|
|
13537
|
-
const newPrimary =
|
|
13538
|
-
|
|
13084
|
+
const newPrimary = {
|
|
13085
|
+
ownerId: this.clientId,
|
|
13086
|
+
allowTabSynchronization: this.allowTabSynchronization,
|
|
13087
|
+
leaseTimestampMs: Date.now()
|
|
13088
|
+
};
|
|
13089
|
+
return primaryClientStore(txn).put(DbPrimaryClientKey, newPrimary);
|
|
13539
13090
|
}
|
|
13540
13091
|
static isAvailable() {
|
|
13541
13092
|
return SimpleDb.isAvailable();
|
|
@@ -13543,10 +13094,10 @@ class IndexedDbPersistence {
|
|
|
13543
13094
|
/** Checks the primary lease and removes it if we are the current primary. */
|
|
13544
13095
|
releasePrimaryLeaseIfHeld(txn) {
|
|
13545
13096
|
const store = primaryClientStore(txn);
|
|
13546
|
-
return store.get(
|
|
13097
|
+
return store.get(DbPrimaryClientKey).next(primaryClient => {
|
|
13547
13098
|
if (this.isLocalClient(primaryClient)) {
|
|
13548
13099
|
logDebug(LOG_TAG$d, 'Releasing primary lease.');
|
|
13549
|
-
return store.delete(
|
|
13100
|
+
return store.delete(DbPrimaryClientKey);
|
|
13550
13101
|
}
|
|
13551
13102
|
else {
|
|
13552
13103
|
return PersistencePromise.resolve();
|
|
@@ -13680,13 +13231,13 @@ class IndexedDbPersistence {
|
|
|
13680
13231
|
* Helper to get a typed SimpleDbStore for the primary client object store.
|
|
13681
13232
|
*/
|
|
13682
13233
|
function primaryClientStore(txn) {
|
|
13683
|
-
return getStore(txn,
|
|
13234
|
+
return getStore(txn, DbPrimaryClientStore);
|
|
13684
13235
|
}
|
|
13685
13236
|
/**
|
|
13686
13237
|
* Helper to get a typed SimpleDbStore for the client metadata object store.
|
|
13687
13238
|
*/
|
|
13688
13239
|
function clientMetadataStore(txn) {
|
|
13689
|
-
return getStore(txn,
|
|
13240
|
+
return getStore(txn, DbClientMetadataStore);
|
|
13690
13241
|
}
|
|
13691
13242
|
/**
|
|
13692
13243
|
* Generates a string used as a prefix when storing data in IndexedDB and
|
|
@@ -14749,7 +14300,7 @@ class MemoryDocumentOverlayCache {
|
|
|
14749
14300
|
return PersistencePromise.resolve(this.overlays.get(key));
|
|
14750
14301
|
}
|
|
14751
14302
|
saveOverlays(transaction, largestBatchId, overlays) {
|
|
14752
|
-
overlays.forEach(mutation => {
|
|
14303
|
+
overlays.forEach((_, mutation) => {
|
|
14753
14304
|
this.saveOverlay(transaction, largestBatchId, mutation);
|
|
14754
14305
|
});
|
|
14755
14306
|
return PersistencePromise.resolve();
|
|
@@ -14763,7 +14314,7 @@ class MemoryDocumentOverlayCache {
|
|
|
14763
14314
|
return PersistencePromise.resolve();
|
|
14764
14315
|
}
|
|
14765
14316
|
getOverlaysForCollection(transaction, collection, sinceBatchId) {
|
|
14766
|
-
const result =
|
|
14317
|
+
const result = newOverlayMap();
|
|
14767
14318
|
const immediateChildrenPathLength = collection.length + 1;
|
|
14768
14319
|
const prefix = new DocumentKey(collection.child(''));
|
|
14769
14320
|
const iter = this.overlays.getIteratorFrom(prefix);
|
|
@@ -14797,19 +14348,19 @@ class MemoryDocumentOverlayCache {
|
|
|
14797
14348
|
if (overlay.largestBatchId > sinceBatchId) {
|
|
14798
14349
|
let overlaysForBatchId = batchIdToOverlays.get(overlay.largestBatchId);
|
|
14799
14350
|
if (overlaysForBatchId === null) {
|
|
14800
|
-
overlaysForBatchId =
|
|
14351
|
+
overlaysForBatchId = newOverlayMap();
|
|
14801
14352
|
batchIdToOverlays = batchIdToOverlays.insert(overlay.largestBatchId, overlaysForBatchId);
|
|
14802
14353
|
}
|
|
14803
14354
|
overlaysForBatchId.set(overlay.getKey(), overlay);
|
|
14804
14355
|
}
|
|
14805
14356
|
}
|
|
14806
|
-
const result =
|
|
14357
|
+
const result = newOverlayMap();
|
|
14807
14358
|
const batchIter = batchIdToOverlays.getIterator();
|
|
14808
14359
|
while (batchIter.hasNext()) {
|
|
14809
14360
|
const entry = batchIter.getNext();
|
|
14810
14361
|
const overlays = entry.value;
|
|
14811
|
-
overlays.forEach((
|
|
14812
|
-
if (result.size >= count) {
|
|
14362
|
+
overlays.forEach((key, overlay) => result.set(key, overlay));
|
|
14363
|
+
if (result.size() >= count) {
|
|
14813
14364
|
break;
|
|
14814
14365
|
}
|
|
14815
14366
|
}
|
|
@@ -14822,16 +14373,19 @@ class MemoryDocumentOverlayCache {
|
|
|
14822
14373
|
// Remove the association of the overlay to its batch id.
|
|
14823
14374
|
const existing = this.overlays.get(mutation.key);
|
|
14824
14375
|
if (existing !== null) {
|
|
14825
|
-
this.overlayByBatchId
|
|
14376
|
+
const newSet = this.overlayByBatchId
|
|
14377
|
+
.get(existing.largestBatchId)
|
|
14378
|
+
.delete(mutation.key);
|
|
14379
|
+
this.overlayByBatchId.set(existing.largestBatchId, newSet);
|
|
14826
14380
|
}
|
|
14827
14381
|
this.overlays = this.overlays.insert(mutation.key, new Overlay(largestBatchId, mutation));
|
|
14828
14382
|
// Create the association of this overlay to the given largestBatchId.
|
|
14829
14383
|
let batch = this.overlayByBatchId.get(largestBatchId);
|
|
14830
14384
|
if (batch === undefined) {
|
|
14831
|
-
batch =
|
|
14385
|
+
batch = documentKeySet();
|
|
14832
14386
|
this.overlayByBatchId.set(largestBatchId, batch);
|
|
14833
14387
|
}
|
|
14834
|
-
batch.add(mutation.key);
|
|
14388
|
+
this.overlayByBatchId.set(largestBatchId, batch.add(mutation.key));
|
|
14835
14389
|
}
|
|
14836
14390
|
}
|
|
14837
14391
|
|