@firebase/firestore 3.7.3-canary.37dd6f6f4 → 3.7.3-canary.7e237cd47
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/lite/index.d.ts +1 -1
- package/dist/firestore/src/api/filter.d.ts +1 -1
- package/dist/firestore/src/api.d.ts +1 -1
- package/dist/firestore/src/core/bound.d.ts +49 -0
- package/dist/firestore/src/core/filter.d.ts +134 -0
- package/dist/firestore/src/core/order_by.d.ts +35 -0
- package/dist/firestore/src/core/query.d.ts +5 -6
- package/dist/firestore/src/core/target.d.ts +4 -120
- package/dist/firestore/src/lite-api/query.d.ts +273 -66
- package/dist/firestore/src/local/indexeddb_index_manager.d.ts +2 -0
- package/dist/firestore/src/protos/firestore_proto_api.d.ts +1 -1
- package/dist/firestore/src/remote/serializer.d.ts +10 -3
- package/dist/firestore/src/util/logic_utils.d.ts +52 -0
- package/dist/firestore/src/util/types.d.ts +1 -1
- package/dist/firestore/test/lite/helpers.d.ts +1 -1
- package/dist/firestore/test/unit/core/filter.test.d.ts +17 -0
- package/dist/firestore/test/unit/specs/spec_test_runner.d.ts +1 -1
- package/dist/firestore/test/unit/util/logic_utils.test.d.ts +17 -0
- package/dist/firestore/test/util/helpers.d.ts +5 -1
- package/dist/firestore/test/util/test_platform.d.ts +2 -2
- package/dist/index.d.ts +138 -62
- package/dist/index.esm2017.js +4271 -3734
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.esm5.js +4959 -4404
- package/dist/index.esm5.js.map +1 -1
- package/dist/index.node.cjs.js +1609 -874
- package/dist/index.node.cjs.js.map +1 -1
- package/dist/index.node.mjs +1602 -875
- package/dist/index.node.mjs.map +1 -1
- package/dist/index.rn.js +4496 -3959
- package/dist/index.rn.js.map +1 -1
- package/dist/internal.d.ts +320 -65
- package/dist/lite/firestore/lite/index.d.ts +1 -1
- package/dist/lite/firestore/src/api/filter.d.ts +1 -1
- package/dist/lite/firestore/src/api.d.ts +1 -1
- package/dist/lite/firestore/src/core/bound.d.ts +49 -0
- package/dist/lite/firestore/src/core/filter.d.ts +134 -0
- package/dist/lite/firestore/src/core/order_by.d.ts +35 -0
- package/dist/lite/firestore/src/core/query.d.ts +5 -6
- package/dist/lite/firestore/src/core/target.d.ts +4 -120
- package/dist/lite/firestore/src/lite-api/query.d.ts +273 -66
- package/dist/lite/firestore/src/local/indexeddb_index_manager.d.ts +2 -0
- package/dist/lite/firestore/src/protos/firestore_proto_api.d.ts +1 -1
- package/dist/lite/firestore/src/remote/serializer.d.ts +10 -3
- package/dist/lite/firestore/src/util/logic_utils.d.ts +52 -0
- package/dist/lite/firestore/src/util/types.d.ts +1 -1
- package/dist/lite/firestore/test/lite/helpers.d.ts +1 -1
- package/dist/lite/firestore/test/unit/core/filter.test.d.ts +17 -0
- package/dist/lite/firestore/test/unit/specs/spec_test_runner.d.ts +1 -1
- package/dist/lite/firestore/test/unit/util/logic_utils.test.d.ts +17 -0
- package/dist/lite/firestore/test/util/helpers.d.ts +5 -1
- package/dist/lite/firestore/test/util/test_platform.d.ts +2 -2
- package/dist/lite/index.browser.esm2017.js +2059 -1779
- package/dist/lite/index.browser.esm2017.js.map +1 -1
- package/dist/lite/index.browser.esm5.js +2218 -1997
- package/dist/lite/index.browser.esm5.js.map +1 -1
- package/dist/lite/index.d.ts +138 -62
- package/dist/lite/index.node.cjs.js +2165 -1788
- package/dist/lite/index.node.cjs.js.map +1 -1
- package/dist/lite/index.node.mjs +2158 -1789
- package/dist/lite/index.node.mjs.map +1 -1
- package/dist/lite/index.rn.esm2017.js +2203 -1922
- package/dist/lite/index.rn.esm2017.js.map +1 -1
- package/dist/lite/internal.d.ts +320 -65
- package/dist/lite/packages/firestore/dist/lite/index.browser.esm2017.d.ts +322 -174
- package/dist/lite/packages/firestore/lite/index.d.ts +1 -1
- package/dist/lite/packages/firestore/rollup.config.debug.d.ts +1 -1
- package/dist/lite/packages/firestore/src/api/filter.d.ts +1 -1
- package/dist/lite/packages/firestore/src/api.d.ts +1 -1
- package/dist/lite/packages/firestore/src/core/bound.d.ts +49 -0
- package/dist/lite/packages/firestore/src/core/filter.d.ts +134 -0
- package/dist/lite/packages/firestore/src/core/order_by.d.ts +35 -0
- package/dist/lite/packages/firestore/src/core/query.d.ts +5 -6
- package/dist/lite/packages/firestore/src/core/target.d.ts +4 -120
- package/dist/lite/packages/firestore/src/lite-api/query.d.ts +273 -66
- package/dist/lite/packages/firestore/src/local/indexeddb_index_manager.d.ts +2 -0
- package/dist/lite/packages/firestore/src/protos/firestore_proto_api.d.ts +1 -1
- package/dist/lite/packages/firestore/src/remote/serializer.d.ts +10 -3
- package/dist/lite/packages/firestore/src/util/logic_utils.d.ts +52 -0
- package/dist/lite/packages/firestore/src/util/types.d.ts +1 -1
- package/dist/lite/packages/firestore/test/lite/helpers.d.ts +1 -1
- package/dist/lite/packages/firestore/test/unit/core/filter.test.d.ts +17 -0
- package/dist/lite/packages/firestore/test/unit/specs/spec_test_runner.d.ts +1 -1
- package/dist/lite/packages/firestore/test/unit/util/logic_utils.test.d.ts +17 -0
- package/dist/lite/packages/firestore/test/util/helpers.d.ts +5 -1
- package/dist/lite/packages/firestore/test/util/test_platform.d.ts +2 -2
- package/dist/lite/private.d.ts +232 -65
- package/dist/packages/firestore/dist/index.esm2017.d.ts +368 -208
- package/dist/packages/firestore/lite/index.d.ts +1 -1
- package/dist/packages/firestore/rollup.config.debug.d.ts +1 -1
- package/dist/packages/firestore/src/api/filter.d.ts +1 -1
- package/dist/packages/firestore/src/api.d.ts +1 -1
- package/dist/packages/firestore/src/core/bound.d.ts +49 -0
- package/dist/packages/firestore/src/core/filter.d.ts +134 -0
- package/dist/packages/firestore/src/core/order_by.d.ts +35 -0
- package/dist/packages/firestore/src/core/query.d.ts +5 -6
- package/dist/packages/firestore/src/core/target.d.ts +4 -120
- package/dist/packages/firestore/src/lite-api/query.d.ts +273 -66
- package/dist/packages/firestore/src/local/indexeddb_index_manager.d.ts +2 -0
- package/dist/packages/firestore/src/protos/firestore_proto_api.d.ts +1 -1
- package/dist/packages/firestore/src/remote/serializer.d.ts +10 -3
- package/dist/packages/firestore/src/util/logic_utils.d.ts +52 -0
- package/dist/packages/firestore/src/util/types.d.ts +1 -1
- package/dist/packages/firestore/test/lite/helpers.d.ts +1 -1
- package/dist/packages/firestore/test/unit/core/filter.test.d.ts +17 -0
- package/dist/packages/firestore/test/unit/specs/spec_test_runner.d.ts +1 -1
- package/dist/packages/firestore/test/unit/util/logic_utils.test.d.ts +17 -0
- package/dist/packages/firestore/test/util/helpers.d.ts +5 -1
- package/dist/packages/firestore/test/util/test_platform.d.ts +2 -2
- package/dist/private.d.ts +232 -65
- package/package.json +13 -11
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.7.3-canary.
|
|
11
|
+
const version$1 = "3.7.3-canary.7e237cd47";
|
|
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.14.0-canary.
|
|
64
|
+
const version = "9.14.0-canary.7e237cd47";
|
|
65
65
|
|
|
66
66
|
/**
|
|
67
67
|
* @license
|
|
@@ -1499,11 +1499,11 @@ class FieldIndex {
|
|
|
1499
1499
|
FieldIndex.UNKNOWN_ID = -1;
|
|
1500
1500
|
/** Returns the ArrayContains/ArrayContainsAny segment for this index. */
|
|
1501
1501
|
function fieldIndexGetArraySegment(fieldIndex) {
|
|
1502
|
-
return fieldIndex.fields.find(s => s.kind === 2 /* CONTAINS */);
|
|
1502
|
+
return fieldIndex.fields.find(s => s.kind === 2 /* IndexKind.CONTAINS */);
|
|
1503
1503
|
}
|
|
1504
1504
|
/** Returns all directional (ascending/descending) segments for this index. */
|
|
1505
1505
|
function fieldIndexGetDirectionalSegments(fieldIndex) {
|
|
1506
|
-
return fieldIndex.fields.filter(s => s.kind !== 2 /* CONTAINS */);
|
|
1506
|
+
return fieldIndex.fields.filter(s => s.kind !== 2 /* IndexKind.CONTAINS */);
|
|
1507
1507
|
}
|
|
1508
1508
|
/**
|
|
1509
1509
|
* Returns the order of the document key component for the given index.
|
|
@@ -1513,7 +1513,7 @@ function fieldIndexGetDirectionalSegments(fieldIndex) {
|
|
|
1513
1513
|
function fieldIndexGetKeyOrder(fieldIndex) {
|
|
1514
1514
|
const directionalSegments = fieldIndexGetDirectionalSegments(fieldIndex);
|
|
1515
1515
|
return directionalSegments.length === 0
|
|
1516
|
-
? 0 /* ASCENDING */
|
|
1516
|
+
? 0 /* IndexKind.ASCENDING */
|
|
1517
1517
|
: directionalSegments[directionalSegments.length - 1].kind;
|
|
1518
1518
|
}
|
|
1519
1519
|
/**
|
|
@@ -2627,7 +2627,7 @@ class IndexBackfillerScheduler {
|
|
|
2627
2627
|
}
|
|
2628
2628
|
schedule(delay) {
|
|
2629
2629
|
logDebug(LOG_TAG$h, `Scheduled in ${delay}ms`);
|
|
2630
|
-
this.task = this.asyncQueue.enqueueAfterDelay("index_backfill" /* IndexBackfill */, delay, async () => {
|
|
2630
|
+
this.task = this.asyncQueue.enqueueAfterDelay("index_backfill" /* TimerId.IndexBackfill */, delay, async () => {
|
|
2631
2631
|
this.task = null;
|
|
2632
2632
|
try {
|
|
2633
2633
|
const documentsProcessed = await this.backfiller.backfill();
|
|
@@ -4423,40 +4423,40 @@ const MIN_VALUE = {
|
|
|
4423
4423
|
/** Extracts the backend's type order for the provided value. */
|
|
4424
4424
|
function typeOrder(value) {
|
|
4425
4425
|
if ('nullValue' in value) {
|
|
4426
|
-
return 0 /* NullValue */;
|
|
4426
|
+
return 0 /* TypeOrder.NullValue */;
|
|
4427
4427
|
}
|
|
4428
4428
|
else if ('booleanValue' in value) {
|
|
4429
|
-
return 1 /* BooleanValue */;
|
|
4429
|
+
return 1 /* TypeOrder.BooleanValue */;
|
|
4430
4430
|
}
|
|
4431
4431
|
else if ('integerValue' in value || 'doubleValue' in value) {
|
|
4432
|
-
return 2 /* NumberValue */;
|
|
4432
|
+
return 2 /* TypeOrder.NumberValue */;
|
|
4433
4433
|
}
|
|
4434
4434
|
else if ('timestampValue' in value) {
|
|
4435
|
-
return 3 /* TimestampValue */;
|
|
4435
|
+
return 3 /* TypeOrder.TimestampValue */;
|
|
4436
4436
|
}
|
|
4437
4437
|
else if ('stringValue' in value) {
|
|
4438
|
-
return 5 /* StringValue */;
|
|
4438
|
+
return 5 /* TypeOrder.StringValue */;
|
|
4439
4439
|
}
|
|
4440
4440
|
else if ('bytesValue' in value) {
|
|
4441
|
-
return 6 /* BlobValue */;
|
|
4441
|
+
return 6 /* TypeOrder.BlobValue */;
|
|
4442
4442
|
}
|
|
4443
4443
|
else if ('referenceValue' in value) {
|
|
4444
|
-
return 7 /* RefValue */;
|
|
4444
|
+
return 7 /* TypeOrder.RefValue */;
|
|
4445
4445
|
}
|
|
4446
4446
|
else if ('geoPointValue' in value) {
|
|
4447
|
-
return 8 /* GeoPointValue */;
|
|
4447
|
+
return 8 /* TypeOrder.GeoPointValue */;
|
|
4448
4448
|
}
|
|
4449
4449
|
else if ('arrayValue' in value) {
|
|
4450
|
-
return 9 /* ArrayValue */;
|
|
4450
|
+
return 9 /* TypeOrder.ArrayValue */;
|
|
4451
4451
|
}
|
|
4452
4452
|
else if ('mapValue' in value) {
|
|
4453
4453
|
if (isServerTimestamp(value)) {
|
|
4454
|
-
return 4 /* ServerTimestampValue */;
|
|
4454
|
+
return 4 /* TypeOrder.ServerTimestampValue */;
|
|
4455
4455
|
}
|
|
4456
4456
|
else if (isMaxValue(value)) {
|
|
4457
|
-
return 9007199254740991 /* MaxValue */;
|
|
4457
|
+
return 9007199254740991 /* TypeOrder.MaxValue */;
|
|
4458
4458
|
}
|
|
4459
|
-
return 10 /* ObjectValue */;
|
|
4459
|
+
return 10 /* TypeOrder.ObjectValue */;
|
|
4460
4460
|
}
|
|
4461
4461
|
else {
|
|
4462
4462
|
return fail();
|
|
@@ -4473,29 +4473,29 @@ function valueEquals(left, right) {
|
|
|
4473
4473
|
return false;
|
|
4474
4474
|
}
|
|
4475
4475
|
switch (leftType) {
|
|
4476
|
-
case 0 /* NullValue */:
|
|
4476
|
+
case 0 /* TypeOrder.NullValue */:
|
|
4477
4477
|
return true;
|
|
4478
|
-
case 1 /* BooleanValue */:
|
|
4478
|
+
case 1 /* TypeOrder.BooleanValue */:
|
|
4479
4479
|
return left.booleanValue === right.booleanValue;
|
|
4480
|
-
case 4 /* ServerTimestampValue */:
|
|
4480
|
+
case 4 /* TypeOrder.ServerTimestampValue */:
|
|
4481
4481
|
return getLocalWriteTime(left).isEqual(getLocalWriteTime(right));
|
|
4482
|
-
case 3 /* TimestampValue */:
|
|
4482
|
+
case 3 /* TypeOrder.TimestampValue */:
|
|
4483
4483
|
return timestampEquals(left, right);
|
|
4484
|
-
case 5 /* StringValue */:
|
|
4484
|
+
case 5 /* TypeOrder.StringValue */:
|
|
4485
4485
|
return left.stringValue === right.stringValue;
|
|
4486
|
-
case 6 /* BlobValue */:
|
|
4486
|
+
case 6 /* TypeOrder.BlobValue */:
|
|
4487
4487
|
return blobEquals(left, right);
|
|
4488
|
-
case 7 /* RefValue */:
|
|
4488
|
+
case 7 /* TypeOrder.RefValue */:
|
|
4489
4489
|
return left.referenceValue === right.referenceValue;
|
|
4490
|
-
case 8 /* GeoPointValue */:
|
|
4490
|
+
case 8 /* TypeOrder.GeoPointValue */:
|
|
4491
4491
|
return geoPointEquals(left, right);
|
|
4492
|
-
case 2 /* NumberValue */:
|
|
4492
|
+
case 2 /* TypeOrder.NumberValue */:
|
|
4493
4493
|
return numberEquals(left, right);
|
|
4494
|
-
case 9 /* ArrayValue */:
|
|
4494
|
+
case 9 /* TypeOrder.ArrayValue */:
|
|
4495
4495
|
return arrayEquals(left.arrayValue.values || [], right.arrayValue.values || [], valueEquals);
|
|
4496
|
-
case 10 /* ObjectValue */:
|
|
4496
|
+
case 10 /* TypeOrder.ObjectValue */:
|
|
4497
4497
|
return objectEquals(left, right);
|
|
4498
|
-
case 9007199254740991 /* MaxValue */:
|
|
4498
|
+
case 9007199254740991 /* TypeOrder.MaxValue */:
|
|
4499
4499
|
return true;
|
|
4500
4500
|
default:
|
|
4501
4501
|
return fail();
|
|
@@ -4568,28 +4568,28 @@ function valueCompare(left, right) {
|
|
|
4568
4568
|
return primitiveComparator(leftType, rightType);
|
|
4569
4569
|
}
|
|
4570
4570
|
switch (leftType) {
|
|
4571
|
-
case 0 /* NullValue */:
|
|
4572
|
-
case 9007199254740991 /* MaxValue */:
|
|
4571
|
+
case 0 /* TypeOrder.NullValue */:
|
|
4572
|
+
case 9007199254740991 /* TypeOrder.MaxValue */:
|
|
4573
4573
|
return 0;
|
|
4574
|
-
case 1 /* BooleanValue */:
|
|
4574
|
+
case 1 /* TypeOrder.BooleanValue */:
|
|
4575
4575
|
return primitiveComparator(left.booleanValue, right.booleanValue);
|
|
4576
|
-
case 2 /* NumberValue */:
|
|
4576
|
+
case 2 /* TypeOrder.NumberValue */:
|
|
4577
4577
|
return compareNumbers(left, right);
|
|
4578
|
-
case 3 /* TimestampValue */:
|
|
4578
|
+
case 3 /* TypeOrder.TimestampValue */:
|
|
4579
4579
|
return compareTimestamps(left.timestampValue, right.timestampValue);
|
|
4580
|
-
case 4 /* ServerTimestampValue */:
|
|
4580
|
+
case 4 /* TypeOrder.ServerTimestampValue */:
|
|
4581
4581
|
return compareTimestamps(getLocalWriteTime(left), getLocalWriteTime(right));
|
|
4582
|
-
case 5 /* StringValue */:
|
|
4582
|
+
case 5 /* TypeOrder.StringValue */:
|
|
4583
4583
|
return primitiveComparator(left.stringValue, right.stringValue);
|
|
4584
|
-
case 6 /* BlobValue */:
|
|
4584
|
+
case 6 /* TypeOrder.BlobValue */:
|
|
4585
4585
|
return compareBlobs(left.bytesValue, right.bytesValue);
|
|
4586
|
-
case 7 /* RefValue */:
|
|
4586
|
+
case 7 /* TypeOrder.RefValue */:
|
|
4587
4587
|
return compareReferences(left.referenceValue, right.referenceValue);
|
|
4588
|
-
case 8 /* GeoPointValue */:
|
|
4588
|
+
case 8 /* TypeOrder.GeoPointValue */:
|
|
4589
4589
|
return compareGeoPoints(left.geoPointValue, right.geoPointValue);
|
|
4590
|
-
case 9 /* ArrayValue */:
|
|
4590
|
+
case 9 /* TypeOrder.ArrayValue */:
|
|
4591
4591
|
return compareArrays(left.arrayValue, right.arrayValue);
|
|
4592
|
-
case 10 /* ObjectValue */:
|
|
4592
|
+
case 10 /* TypeOrder.ObjectValue */:
|
|
4593
4593
|
return compareMaps(left.mapValue, right.mapValue);
|
|
4594
4594
|
default:
|
|
4595
4595
|
throw fail();
|
|
@@ -5155,18 +5155,18 @@ class MutableDocument {
|
|
|
5155
5155
|
* base document for mutations.
|
|
5156
5156
|
*/
|
|
5157
5157
|
static newInvalidDocument(documentKey) {
|
|
5158
|
-
return new MutableDocument(documentKey, 0 /* INVALID */, SnapshotVersion.min(), SnapshotVersion.min(), ObjectValue.empty(), 0 /* SYNCED */);
|
|
5158
|
+
return new MutableDocument(documentKey, 0 /* DocumentType.INVALID */, SnapshotVersion.min(), SnapshotVersion.min(), ObjectValue.empty(), 0 /* DocumentState.SYNCED */);
|
|
5159
5159
|
}
|
|
5160
5160
|
/**
|
|
5161
5161
|
* Creates a new document that is known to exist with the given data at the
|
|
5162
5162
|
* given version.
|
|
5163
5163
|
*/
|
|
5164
5164
|
static newFoundDocument(documentKey, version, value) {
|
|
5165
|
-
return new MutableDocument(documentKey, 1 /* FOUND_DOCUMENT */, version, SnapshotVersion.min(), value, 0 /* SYNCED */);
|
|
5165
|
+
return new MutableDocument(documentKey, 1 /* DocumentType.FOUND_DOCUMENT */, version, SnapshotVersion.min(), value, 0 /* DocumentState.SYNCED */);
|
|
5166
5166
|
}
|
|
5167
5167
|
/** Creates a new document that is known to not exist at the given version. */
|
|
5168
5168
|
static newNoDocument(documentKey, version) {
|
|
5169
|
-
return new MutableDocument(documentKey, 2 /* NO_DOCUMENT */, version, SnapshotVersion.min(), ObjectValue.empty(), 0 /* SYNCED */);
|
|
5169
|
+
return new MutableDocument(documentKey, 2 /* DocumentType.NO_DOCUMENT */, version, SnapshotVersion.min(), ObjectValue.empty(), 0 /* DocumentState.SYNCED */);
|
|
5170
5170
|
}
|
|
5171
5171
|
/**
|
|
5172
5172
|
* Creates a new document that is known to exist at the given version but
|
|
@@ -5174,7 +5174,7 @@ class MutableDocument {
|
|
|
5174
5174
|
* base document).
|
|
5175
5175
|
*/
|
|
5176
5176
|
static newUnknownDocument(documentKey, version) {
|
|
5177
|
-
return new MutableDocument(documentKey, 3 /* UNKNOWN_DOCUMENT */, version, SnapshotVersion.min(), ObjectValue.empty(), 2 /* HAS_COMMITTED_MUTATIONS */);
|
|
5177
|
+
return new MutableDocument(documentKey, 3 /* DocumentType.UNKNOWN_DOCUMENT */, version, SnapshotVersion.min(), ObjectValue.empty(), 2 /* DocumentState.HAS_COMMITTED_MUTATIONS */);
|
|
5178
5178
|
}
|
|
5179
5179
|
/**
|
|
5180
5180
|
* Changes the document type to indicate that it exists and that its version
|
|
@@ -5182,9 +5182,9 @@ class MutableDocument {
|
|
|
5182
5182
|
*/
|
|
5183
5183
|
convertToFoundDocument(version, value) {
|
|
5184
5184
|
this.version = version;
|
|
5185
|
-
this.documentType = 1 /* FOUND_DOCUMENT */;
|
|
5185
|
+
this.documentType = 1 /* DocumentType.FOUND_DOCUMENT */;
|
|
5186
5186
|
this.data = value;
|
|
5187
|
-
this.documentState = 0 /* SYNCED */;
|
|
5187
|
+
this.documentState = 0 /* DocumentState.SYNCED */;
|
|
5188
5188
|
return this;
|
|
5189
5189
|
}
|
|
5190
5190
|
/**
|
|
@@ -5193,9 +5193,9 @@ class MutableDocument {
|
|
|
5193
5193
|
*/
|
|
5194
5194
|
convertToNoDocument(version) {
|
|
5195
5195
|
this.version = version;
|
|
5196
|
-
this.documentType = 2 /* NO_DOCUMENT */;
|
|
5196
|
+
this.documentType = 2 /* DocumentType.NO_DOCUMENT */;
|
|
5197
5197
|
this.data = ObjectValue.empty();
|
|
5198
|
-
this.documentState = 0 /* SYNCED */;
|
|
5198
|
+
this.documentState = 0 /* DocumentState.SYNCED */;
|
|
5199
5199
|
return this;
|
|
5200
5200
|
}
|
|
5201
5201
|
/**
|
|
@@ -5205,17 +5205,17 @@ class MutableDocument {
|
|
|
5205
5205
|
*/
|
|
5206
5206
|
convertToUnknownDocument(version) {
|
|
5207
5207
|
this.version = version;
|
|
5208
|
-
this.documentType = 3 /* UNKNOWN_DOCUMENT */;
|
|
5208
|
+
this.documentType = 3 /* DocumentType.UNKNOWN_DOCUMENT */;
|
|
5209
5209
|
this.data = ObjectValue.empty();
|
|
5210
|
-
this.documentState = 2 /* HAS_COMMITTED_MUTATIONS */;
|
|
5210
|
+
this.documentState = 2 /* DocumentState.HAS_COMMITTED_MUTATIONS */;
|
|
5211
5211
|
return this;
|
|
5212
5212
|
}
|
|
5213
5213
|
setHasCommittedMutations() {
|
|
5214
|
-
this.documentState = 2 /* HAS_COMMITTED_MUTATIONS */;
|
|
5214
|
+
this.documentState = 2 /* DocumentState.HAS_COMMITTED_MUTATIONS */;
|
|
5215
5215
|
return this;
|
|
5216
5216
|
}
|
|
5217
5217
|
setHasLocalMutations() {
|
|
5218
|
-
this.documentState = 1 /* HAS_LOCAL_MUTATIONS */;
|
|
5218
|
+
this.documentState = 1 /* DocumentState.HAS_LOCAL_MUTATIONS */;
|
|
5219
5219
|
this.version = SnapshotVersion.min();
|
|
5220
5220
|
return this;
|
|
5221
5221
|
}
|
|
@@ -5224,25 +5224,25 @@ class MutableDocument {
|
|
|
5224
5224
|
return this;
|
|
5225
5225
|
}
|
|
5226
5226
|
get hasLocalMutations() {
|
|
5227
|
-
return this.documentState === 1 /* HAS_LOCAL_MUTATIONS */;
|
|
5227
|
+
return this.documentState === 1 /* DocumentState.HAS_LOCAL_MUTATIONS */;
|
|
5228
5228
|
}
|
|
5229
5229
|
get hasCommittedMutations() {
|
|
5230
|
-
return this.documentState === 2 /* HAS_COMMITTED_MUTATIONS */;
|
|
5230
|
+
return this.documentState === 2 /* DocumentState.HAS_COMMITTED_MUTATIONS */;
|
|
5231
5231
|
}
|
|
5232
5232
|
get hasPendingWrites() {
|
|
5233
5233
|
return this.hasLocalMutations || this.hasCommittedMutations;
|
|
5234
5234
|
}
|
|
5235
5235
|
isValidDocument() {
|
|
5236
|
-
return this.documentType !== 0 /* INVALID */;
|
|
5236
|
+
return this.documentType !== 0 /* DocumentType.INVALID */;
|
|
5237
5237
|
}
|
|
5238
5238
|
isFoundDocument() {
|
|
5239
|
-
return this.documentType === 1 /* FOUND_DOCUMENT */;
|
|
5239
|
+
return this.documentType === 1 /* DocumentType.FOUND_DOCUMENT */;
|
|
5240
5240
|
}
|
|
5241
5241
|
isNoDocument() {
|
|
5242
|
-
return this.documentType === 2 /* NO_DOCUMENT */;
|
|
5242
|
+
return this.documentType === 2 /* DocumentType.NO_DOCUMENT */;
|
|
5243
5243
|
}
|
|
5244
5244
|
isUnknownDocument() {
|
|
5245
|
-
return this.documentType === 3 /* UNKNOWN_DOCUMENT */;
|
|
5245
|
+
return this.documentType === 3 /* DocumentType.UNKNOWN_DOCUMENT */;
|
|
5246
5246
|
}
|
|
5247
5247
|
isEqual(other) {
|
|
5248
5248
|
return (other instanceof MutableDocument &&
|
|
@@ -5278,7 +5278,7 @@ function compareDocumentsByField(field, d1, d2) {
|
|
|
5278
5278
|
|
|
5279
5279
|
/**
|
|
5280
5280
|
* @license
|
|
5281
|
-
* Copyright
|
|
5281
|
+
* Copyright 2022 Google LLC
|
|
5282
5282
|
*
|
|
5283
5283
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5284
5284
|
* you may not use this file except in compliance with the License.
|
|
@@ -5292,453 +5292,344 @@ function compareDocumentsByField(field, d1, d2) {
|
|
|
5292
5292
|
* See the License for the specific language governing permissions and
|
|
5293
5293
|
* limitations under the License.
|
|
5294
5294
|
*/
|
|
5295
|
-
|
|
5296
|
-
|
|
5297
|
-
|
|
5298
|
-
|
|
5299
|
-
|
|
5300
|
-
|
|
5301
|
-
|
|
5302
|
-
|
|
5303
|
-
|
|
5304
|
-
|
|
5305
|
-
|
|
5295
|
+
/**
|
|
5296
|
+
* Represents a bound of a query.
|
|
5297
|
+
*
|
|
5298
|
+
* The bound is specified with the given components representing a position and
|
|
5299
|
+
* whether it's just before or just after the position (relative to whatever the
|
|
5300
|
+
* query order is).
|
|
5301
|
+
*
|
|
5302
|
+
* The position represents a logical index position for a query. It's a prefix
|
|
5303
|
+
* of values for the (potentially implicit) order by clauses of a query.
|
|
5304
|
+
*
|
|
5305
|
+
* Bound provides a function to determine whether a document comes before or
|
|
5306
|
+
* after a bound. This is influenced by whether the position is just before or
|
|
5307
|
+
* just after the provided values.
|
|
5308
|
+
*/
|
|
5309
|
+
class Bound {
|
|
5310
|
+
constructor(position, inclusive) {
|
|
5311
|
+
this.position = position;
|
|
5312
|
+
this.inclusive = inclusive;
|
|
5313
|
+
}
|
|
5314
|
+
}
|
|
5315
|
+
function boundCompareToDocument(bound, orderBy, doc) {
|
|
5316
|
+
let comparison = 0;
|
|
5317
|
+
for (let i = 0; i < bound.position.length; i++) {
|
|
5318
|
+
const orderByComponent = orderBy[i];
|
|
5319
|
+
const component = bound.position[i];
|
|
5320
|
+
if (orderByComponent.field.isKeyField()) {
|
|
5321
|
+
comparison = DocumentKey.comparator(DocumentKey.fromName(component.referenceValue), doc.key);
|
|
5322
|
+
}
|
|
5323
|
+
else {
|
|
5324
|
+
const docValue = doc.data.field(orderByComponent.field);
|
|
5325
|
+
comparison = valueCompare(component, docValue);
|
|
5326
|
+
}
|
|
5327
|
+
if (orderByComponent.dir === "desc" /* Direction.DESCENDING */) {
|
|
5328
|
+
comparison = comparison * -1;
|
|
5329
|
+
}
|
|
5330
|
+
if (comparison !== 0) {
|
|
5331
|
+
break;
|
|
5332
|
+
}
|
|
5306
5333
|
}
|
|
5334
|
+
return comparison;
|
|
5307
5335
|
}
|
|
5308
5336
|
/**
|
|
5309
|
-
*
|
|
5310
|
-
*
|
|
5337
|
+
* Returns true if a document sorts after a bound using the provided sort
|
|
5338
|
+
* order.
|
|
5339
|
+
*/
|
|
5340
|
+
function boundSortsAfterDocument(bound, orderBy, doc) {
|
|
5341
|
+
const comparison = boundCompareToDocument(bound, orderBy, doc);
|
|
5342
|
+
return bound.inclusive ? comparison >= 0 : comparison > 0;
|
|
5343
|
+
}
|
|
5344
|
+
/**
|
|
5345
|
+
* Returns true if a document sorts before a bound using the provided sort
|
|
5346
|
+
* order.
|
|
5347
|
+
*/
|
|
5348
|
+
function boundSortsBeforeDocument(bound, orderBy, doc) {
|
|
5349
|
+
const comparison = boundCompareToDocument(bound, orderBy, doc);
|
|
5350
|
+
return bound.inclusive ? comparison <= 0 : comparison < 0;
|
|
5351
|
+
}
|
|
5352
|
+
function boundEquals(left, right) {
|
|
5353
|
+
if (left === null) {
|
|
5354
|
+
return right === null;
|
|
5355
|
+
}
|
|
5356
|
+
else if (right === null) {
|
|
5357
|
+
return false;
|
|
5358
|
+
}
|
|
5359
|
+
if (left.inclusive !== right.inclusive ||
|
|
5360
|
+
left.position.length !== right.position.length) {
|
|
5361
|
+
return false;
|
|
5362
|
+
}
|
|
5363
|
+
for (let i = 0; i < left.position.length; i++) {
|
|
5364
|
+
const leftPosition = left.position[i];
|
|
5365
|
+
const rightPosition = right.position[i];
|
|
5366
|
+
if (!valueEquals(leftPosition, rightPosition)) {
|
|
5367
|
+
return false;
|
|
5368
|
+
}
|
|
5369
|
+
}
|
|
5370
|
+
return true;
|
|
5371
|
+
}
|
|
5372
|
+
|
|
5373
|
+
/**
|
|
5374
|
+
* @license
|
|
5375
|
+
* Copyright 2022 Google LLC
|
|
5311
5376
|
*
|
|
5312
|
-
*
|
|
5313
|
-
*
|
|
5314
|
-
*
|
|
5377
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5378
|
+
* you may not use this file except in compliance with the License.
|
|
5379
|
+
* You may obtain a copy of the License at
|
|
5380
|
+
*
|
|
5381
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
5382
|
+
*
|
|
5383
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
5384
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
5385
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
5386
|
+
* See the License for the specific language governing permissions and
|
|
5387
|
+
* limitations under the License.
|
|
5315
5388
|
*/
|
|
5316
|
-
|
|
5317
|
-
return new TargetImpl(path, collectionGroup, orderBy, filters, limit, startAt, endAt);
|
|
5389
|
+
class Filter {
|
|
5318
5390
|
}
|
|
5319
|
-
|
|
5320
|
-
|
|
5321
|
-
|
|
5322
|
-
|
|
5323
|
-
|
|
5324
|
-
|
|
5391
|
+
class FieldFilter extends Filter {
|
|
5392
|
+
constructor(field, op, value) {
|
|
5393
|
+
super();
|
|
5394
|
+
this.field = field;
|
|
5395
|
+
this.op = op;
|
|
5396
|
+
this.value = value;
|
|
5397
|
+
}
|
|
5398
|
+
/**
|
|
5399
|
+
* Creates a filter based on the provided arguments.
|
|
5400
|
+
*/
|
|
5401
|
+
static create(field, op, value) {
|
|
5402
|
+
if (field.isKeyField()) {
|
|
5403
|
+
if (op === "in" /* Operator.IN */ || op === "not-in" /* Operator.NOT_IN */) {
|
|
5404
|
+
return this.createKeyFieldInFilter(field, op, value);
|
|
5405
|
+
}
|
|
5406
|
+
else {
|
|
5407
|
+
return new KeyFieldFilter(field, op, value);
|
|
5408
|
+
}
|
|
5325
5409
|
}
|
|
5326
|
-
|
|
5327
|
-
|
|
5328
|
-
str += '|ob:';
|
|
5329
|
-
str += targetImpl.orderBy.map(o => canonifyOrderBy(o)).join(',');
|
|
5330
|
-
if (!isNullOrUndefined(targetImpl.limit)) {
|
|
5331
|
-
str += '|l:';
|
|
5332
|
-
str += targetImpl.limit;
|
|
5410
|
+
else if (op === "array-contains" /* Operator.ARRAY_CONTAINS */) {
|
|
5411
|
+
return new ArrayContainsFilter(field, value);
|
|
5333
5412
|
}
|
|
5334
|
-
if (
|
|
5335
|
-
|
|
5336
|
-
str += targetImpl.startAt.inclusive ? 'b:' : 'a:';
|
|
5337
|
-
str += targetImpl.startAt.position.map(p => canonicalId(p)).join(',');
|
|
5413
|
+
else if (op === "in" /* Operator.IN */) {
|
|
5414
|
+
return new InFilter(field, value);
|
|
5338
5415
|
}
|
|
5339
|
-
if (
|
|
5340
|
-
|
|
5341
|
-
|
|
5342
|
-
|
|
5416
|
+
else if (op === "not-in" /* Operator.NOT_IN */) {
|
|
5417
|
+
return new NotInFilter(field, value);
|
|
5418
|
+
}
|
|
5419
|
+
else if (op === "array-contains-any" /* Operator.ARRAY_CONTAINS_ANY */) {
|
|
5420
|
+
return new ArrayContainsAnyFilter(field, value);
|
|
5421
|
+
}
|
|
5422
|
+
else {
|
|
5423
|
+
return new FieldFilter(field, op, value);
|
|
5343
5424
|
}
|
|
5344
|
-
targetImpl.memoizedCanonicalId = str;
|
|
5345
5425
|
}
|
|
5346
|
-
|
|
5347
|
-
|
|
5348
|
-
|
|
5349
|
-
|
|
5350
|
-
if (target.collectionGroup !== null) {
|
|
5351
|
-
str += ' collectionGroup=' + target.collectionGroup;
|
|
5426
|
+
static createKeyFieldInFilter(field, op, value) {
|
|
5427
|
+
return op === "in" /* Operator.IN */
|
|
5428
|
+
? new KeyFieldInFilter(field, value)
|
|
5429
|
+
: new KeyFieldNotInFilter(field, value);
|
|
5352
5430
|
}
|
|
5353
|
-
|
|
5354
|
-
|
|
5355
|
-
|
|
5356
|
-
|
|
5431
|
+
matches(doc) {
|
|
5432
|
+
const other = doc.data.field(this.field);
|
|
5433
|
+
// Types do not have to match in NOT_EQUAL filters.
|
|
5434
|
+
if (this.op === "!=" /* Operator.NOT_EQUAL */) {
|
|
5435
|
+
return (other !== null &&
|
|
5436
|
+
this.matchesComparison(valueCompare(other, this.value)));
|
|
5437
|
+
}
|
|
5438
|
+
// Only compare types with matching backend order (such as double and int).
|
|
5439
|
+
return (other !== null &&
|
|
5440
|
+
typeOrder(this.value) === typeOrder(other) &&
|
|
5441
|
+
this.matchesComparison(valueCompare(other, this.value)));
|
|
5357
5442
|
}
|
|
5358
|
-
|
|
5359
|
-
|
|
5443
|
+
matchesComparison(comparison) {
|
|
5444
|
+
switch (this.op) {
|
|
5445
|
+
case "<" /* Operator.LESS_THAN */:
|
|
5446
|
+
return comparison < 0;
|
|
5447
|
+
case "<=" /* Operator.LESS_THAN_OR_EQUAL */:
|
|
5448
|
+
return comparison <= 0;
|
|
5449
|
+
case "==" /* Operator.EQUAL */:
|
|
5450
|
+
return comparison === 0;
|
|
5451
|
+
case "!=" /* Operator.NOT_EQUAL */:
|
|
5452
|
+
return comparison !== 0;
|
|
5453
|
+
case ">" /* Operator.GREATER_THAN */:
|
|
5454
|
+
return comparison > 0;
|
|
5455
|
+
case ">=" /* Operator.GREATER_THAN_OR_EQUAL */:
|
|
5456
|
+
return comparison >= 0;
|
|
5457
|
+
default:
|
|
5458
|
+
return fail();
|
|
5459
|
+
}
|
|
5360
5460
|
}
|
|
5361
|
-
|
|
5362
|
-
|
|
5363
|
-
.
|
|
5364
|
-
.
|
|
5461
|
+
isInequality() {
|
|
5462
|
+
return ([
|
|
5463
|
+
"<" /* Operator.LESS_THAN */,
|
|
5464
|
+
"<=" /* Operator.LESS_THAN_OR_EQUAL */,
|
|
5465
|
+
">" /* Operator.GREATER_THAN */,
|
|
5466
|
+
">=" /* Operator.GREATER_THAN_OR_EQUAL */,
|
|
5467
|
+
"!=" /* Operator.NOT_EQUAL */,
|
|
5468
|
+
"not-in" /* Operator.NOT_IN */
|
|
5469
|
+
].indexOf(this.op) >= 0);
|
|
5365
5470
|
}
|
|
5366
|
-
|
|
5367
|
-
|
|
5368
|
-
str += target.startAt.inclusive ? 'b:' : 'a:';
|
|
5369
|
-
str += target.startAt.position.map(p => canonicalId(p)).join(',');
|
|
5471
|
+
getFlattenedFilters() {
|
|
5472
|
+
return [this];
|
|
5370
5473
|
}
|
|
5371
|
-
|
|
5372
|
-
|
|
5373
|
-
|
|
5374
|
-
|
|
5474
|
+
getFilters() {
|
|
5475
|
+
return [this];
|
|
5476
|
+
}
|
|
5477
|
+
getFirstInequalityField() {
|
|
5478
|
+
if (this.isInequality()) {
|
|
5479
|
+
return this.field;
|
|
5480
|
+
}
|
|
5481
|
+
return null;
|
|
5375
5482
|
}
|
|
5376
|
-
return `Target(${str})`;
|
|
5377
5483
|
}
|
|
5378
|
-
|
|
5379
|
-
|
|
5380
|
-
|
|
5484
|
+
class CompositeFilter extends Filter {
|
|
5485
|
+
constructor(filters, op) {
|
|
5486
|
+
super();
|
|
5487
|
+
this.filters = filters;
|
|
5488
|
+
this.op = op;
|
|
5489
|
+
this.memoizedFlattenedFilters = null;
|
|
5381
5490
|
}
|
|
5382
|
-
|
|
5383
|
-
|
|
5491
|
+
/**
|
|
5492
|
+
* Creates a filter based on the provided arguments.
|
|
5493
|
+
*/
|
|
5494
|
+
static create(filters, op) {
|
|
5495
|
+
return new CompositeFilter(filters, op);
|
|
5384
5496
|
}
|
|
5385
|
-
|
|
5386
|
-
if (
|
|
5387
|
-
return false
|
|
5497
|
+
matches(doc) {
|
|
5498
|
+
if (compositeFilterIsConjunction(this)) {
|
|
5499
|
+
// For conjunctions, all filters must match, so return false if any filter doesn't match.
|
|
5500
|
+
return this.filters.find(filter => !filter.matches(doc)) === undefined;
|
|
5501
|
+
}
|
|
5502
|
+
else {
|
|
5503
|
+
// For disjunctions, at least one filter should match.
|
|
5504
|
+
return this.filters.find(filter => filter.matches(doc)) !== undefined;
|
|
5388
5505
|
}
|
|
5389
5506
|
}
|
|
5390
|
-
|
|
5391
|
-
|
|
5392
|
-
|
|
5393
|
-
for (let i = 0; i < left.filters.length; i++) {
|
|
5394
|
-
if (!filterEquals(left.filters[i], right.filters[i])) {
|
|
5395
|
-
return false;
|
|
5507
|
+
getFlattenedFilters() {
|
|
5508
|
+
if (this.memoizedFlattenedFilters !== null) {
|
|
5509
|
+
return this.memoizedFlattenedFilters;
|
|
5396
5510
|
}
|
|
5511
|
+
this.memoizedFlattenedFilters = this.filters.reduce((result, subfilter) => {
|
|
5512
|
+
return result.concat(subfilter.getFlattenedFilters());
|
|
5513
|
+
}, []);
|
|
5514
|
+
return this.memoizedFlattenedFilters;
|
|
5397
5515
|
}
|
|
5398
|
-
|
|
5399
|
-
|
|
5516
|
+
// Returns a mutable copy of `this.filters`
|
|
5517
|
+
getFilters() {
|
|
5518
|
+
return Object.assign([], this.filters);
|
|
5400
5519
|
}
|
|
5401
|
-
|
|
5402
|
-
|
|
5520
|
+
getFirstInequalityField() {
|
|
5521
|
+
const found = this.findFirstMatchingFilter(filter => filter.isInequality());
|
|
5522
|
+
if (found !== null) {
|
|
5523
|
+
return found.field;
|
|
5524
|
+
}
|
|
5525
|
+
return null;
|
|
5403
5526
|
}
|
|
5404
|
-
|
|
5405
|
-
|
|
5527
|
+
// Performs a depth-first search to find and return the first FieldFilter in the composite filter
|
|
5528
|
+
// that satisfies the predicate. Returns `null` if none of the FieldFilters satisfy the
|
|
5529
|
+
// predicate.
|
|
5530
|
+
findFirstMatchingFilter(predicate) {
|
|
5531
|
+
for (const fieldFilter of this.getFlattenedFilters()) {
|
|
5532
|
+
if (predicate(fieldFilter)) {
|
|
5533
|
+
return fieldFilter;
|
|
5534
|
+
}
|
|
5535
|
+
}
|
|
5536
|
+
return null;
|
|
5406
5537
|
}
|
|
5407
|
-
return boundEquals(left.endAt, right.endAt);
|
|
5408
5538
|
}
|
|
5409
|
-
function
|
|
5410
|
-
return
|
|
5411
|
-
target.collectionGroup === null &&
|
|
5412
|
-
target.filters.length === 0);
|
|
5539
|
+
function compositeFilterIsConjunction(compositeFilter) {
|
|
5540
|
+
return compositeFilter.op === "and" /* CompositeOperator.AND */;
|
|
5413
5541
|
}
|
|
5414
|
-
|
|
5415
|
-
|
|
5416
|
-
return target.filters.filter(f => f instanceof FieldFilter && f.field.isEqual(path));
|
|
5542
|
+
function compositeFilterIsDisjunction(compositeFilter) {
|
|
5543
|
+
return compositeFilter.op === "or" /* CompositeOperator.OR */;
|
|
5417
5544
|
}
|
|
5418
5545
|
/**
|
|
5419
|
-
* Returns
|
|
5420
|
-
* filters. Returns `null` if there are no such filters.
|
|
5546
|
+
* Returns true if this filter is a conjunction of field filters only. Returns false otherwise.
|
|
5421
5547
|
*/
|
|
5422
|
-
function
|
|
5423
|
-
|
|
5424
|
-
|
|
5425
|
-
return null;
|
|
5426
|
-
}
|
|
5427
|
-
for (const fieldFilter of targetGetFieldFiltersForPath(target, segment.fieldPath)) {
|
|
5428
|
-
switch (fieldFilter.op) {
|
|
5429
|
-
case "array-contains-any" /* ARRAY_CONTAINS_ANY */:
|
|
5430
|
-
return fieldFilter.value.arrayValue.values || [];
|
|
5431
|
-
case "array-contains" /* ARRAY_CONTAINS */:
|
|
5432
|
-
return [fieldFilter.value];
|
|
5433
|
-
// Remaining filters are not array filters.
|
|
5434
|
-
}
|
|
5435
|
-
}
|
|
5436
|
-
return null;
|
|
5548
|
+
function compositeFilterIsFlatConjunction(compositeFilter) {
|
|
5549
|
+
return (compositeFilterIsFlat(compositeFilter) &&
|
|
5550
|
+
compositeFilterIsConjunction(compositeFilter));
|
|
5437
5551
|
}
|
|
5438
5552
|
/**
|
|
5439
|
-
* Returns
|
|
5440
|
-
* `null` if there are no such filters.
|
|
5553
|
+
* Returns true if this filter does not contain any composite filters. Returns false otherwise.
|
|
5441
5554
|
*/
|
|
5442
|
-
function
|
|
5443
|
-
const
|
|
5444
|
-
|
|
5445
|
-
|
|
5446
|
-
switch (fieldFilter.op) {
|
|
5447
|
-
case "==" /* EQUAL */:
|
|
5448
|
-
case "in" /* IN */:
|
|
5449
|
-
// Encode equality prefix, which is encoded in the index value before
|
|
5450
|
-
// the inequality (e.g. `a == 'a' && b != 'b'` is encoded to
|
|
5451
|
-
// `value != 'ab'`).
|
|
5452
|
-
values.set(segment.fieldPath.canonicalString(), fieldFilter.value);
|
|
5453
|
-
break;
|
|
5454
|
-
case "not-in" /* NOT_IN */:
|
|
5455
|
-
case "!=" /* NOT_EQUAL */:
|
|
5456
|
-
// NotIn/NotEqual is always a suffix. There cannot be any remaining
|
|
5457
|
-
// segments and hence we can return early here.
|
|
5458
|
-
values.set(segment.fieldPath.canonicalString(), fieldFilter.value);
|
|
5459
|
-
return Array.from(values.values());
|
|
5460
|
-
// Remaining filters cannot be used as notIn bounds.
|
|
5461
|
-
}
|
|
5555
|
+
function compositeFilterIsFlat(compositeFilter) {
|
|
5556
|
+
for (const filter of compositeFilter.filters) {
|
|
5557
|
+
if (filter instanceof CompositeFilter) {
|
|
5558
|
+
return false;
|
|
5462
5559
|
}
|
|
5463
5560
|
}
|
|
5464
|
-
return
|
|
5561
|
+
return true;
|
|
5465
5562
|
}
|
|
5466
|
-
|
|
5467
|
-
|
|
5468
|
-
|
|
5469
|
-
|
|
5470
|
-
|
|
5471
|
-
|
|
5472
|
-
|
|
5473
|
-
|
|
5474
|
-
// For each segment, retrieve a lower bound if there is a suitable filter or
|
|
5475
|
-
// startAt.
|
|
5476
|
-
for (const segment of fieldIndexGetDirectionalSegments(fieldIndex)) {
|
|
5477
|
-
const segmentBound = segment.kind === 0 /* ASCENDING */
|
|
5478
|
-
? targetGetAscendingBound(target, segment.fieldPath, target.startAt)
|
|
5479
|
-
: targetGetDescendingBound(target, segment.fieldPath, target.startAt);
|
|
5480
|
-
values.push(segmentBound.value);
|
|
5481
|
-
inclusive && (inclusive = segmentBound.inclusive);
|
|
5563
|
+
function canonifyFilter(filter) {
|
|
5564
|
+
if (filter instanceof FieldFilter) {
|
|
5565
|
+
// TODO(b/29183165): Technically, this won't be unique if two values have
|
|
5566
|
+
// the same description, such as the int 3 and the string "3". So we should
|
|
5567
|
+
// add the types in here somehow, too.
|
|
5568
|
+
return (filter.field.canonicalString() +
|
|
5569
|
+
filter.op.toString() +
|
|
5570
|
+
canonicalId(filter.value));
|
|
5482
5571
|
}
|
|
5483
|
-
|
|
5484
|
-
|
|
5485
|
-
|
|
5486
|
-
|
|
5487
|
-
|
|
5488
|
-
|
|
5489
|
-
*/
|
|
5490
|
-
function targetGetUpperBound(target, fieldIndex) {
|
|
5491
|
-
const values = [];
|
|
5492
|
-
let inclusive = true;
|
|
5493
|
-
// For each segment, retrieve an upper bound if there is a suitable filter or
|
|
5494
|
-
// endAt.
|
|
5495
|
-
for (const segment of fieldIndexGetDirectionalSegments(fieldIndex)) {
|
|
5496
|
-
const segmentBound = segment.kind === 0 /* ASCENDING */
|
|
5497
|
-
? targetGetDescendingBound(target, segment.fieldPath, target.endAt)
|
|
5498
|
-
: targetGetAscendingBound(target, segment.fieldPath, target.endAt);
|
|
5499
|
-
values.push(segmentBound.value);
|
|
5500
|
-
inclusive && (inclusive = segmentBound.inclusive);
|
|
5572
|
+
else {
|
|
5573
|
+
// filter instanceof CompositeFilter
|
|
5574
|
+
const canonicalIdsString = filter.filters
|
|
5575
|
+
.map(filter => canonifyFilter(filter))
|
|
5576
|
+
.join(',');
|
|
5577
|
+
return `${filter.op}(${canonicalIdsString})`;
|
|
5501
5578
|
}
|
|
5502
|
-
return new Bound(values, inclusive);
|
|
5503
5579
|
}
|
|
5504
|
-
|
|
5505
|
-
|
|
5506
|
-
|
|
5507
|
-
*/
|
|
5508
|
-
function targetGetAscendingBound(target, fieldPath, bound) {
|
|
5509
|
-
let value = MIN_VALUE;
|
|
5510
|
-
let inclusive = true;
|
|
5511
|
-
// Process all filters to find a value for the current field segment
|
|
5512
|
-
for (const fieldFilter of targetGetFieldFiltersForPath(target, fieldPath)) {
|
|
5513
|
-
let filterValue = MIN_VALUE;
|
|
5514
|
-
let filterInclusive = true;
|
|
5515
|
-
switch (fieldFilter.op) {
|
|
5516
|
-
case "<" /* LESS_THAN */:
|
|
5517
|
-
case "<=" /* LESS_THAN_OR_EQUAL */:
|
|
5518
|
-
filterValue = valuesGetLowerBound(fieldFilter.value);
|
|
5519
|
-
break;
|
|
5520
|
-
case "==" /* EQUAL */:
|
|
5521
|
-
case "in" /* IN */:
|
|
5522
|
-
case ">=" /* GREATER_THAN_OR_EQUAL */:
|
|
5523
|
-
filterValue = fieldFilter.value;
|
|
5524
|
-
break;
|
|
5525
|
-
case ">" /* GREATER_THAN */:
|
|
5526
|
-
filterValue = fieldFilter.value;
|
|
5527
|
-
filterInclusive = false;
|
|
5528
|
-
break;
|
|
5529
|
-
case "!=" /* NOT_EQUAL */:
|
|
5530
|
-
case "not-in" /* NOT_IN */:
|
|
5531
|
-
filterValue = MIN_VALUE;
|
|
5532
|
-
break;
|
|
5533
|
-
// Remaining filters cannot be used as lower bounds.
|
|
5534
|
-
}
|
|
5535
|
-
if (lowerBoundCompare({ value, inclusive }, { value: filterValue, inclusive: filterInclusive }) < 0) {
|
|
5536
|
-
value = filterValue;
|
|
5537
|
-
inclusive = filterInclusive;
|
|
5538
|
-
}
|
|
5539
|
-
}
|
|
5540
|
-
// If there is an additional bound, compare the values against the existing
|
|
5541
|
-
// range to see if we can narrow the scope.
|
|
5542
|
-
if (bound !== null) {
|
|
5543
|
-
for (let i = 0; i < target.orderBy.length; ++i) {
|
|
5544
|
-
const orderBy = target.orderBy[i];
|
|
5545
|
-
if (orderBy.field.isEqual(fieldPath)) {
|
|
5546
|
-
const cursorValue = bound.position[i];
|
|
5547
|
-
if (lowerBoundCompare({ value, inclusive }, { value: cursorValue, inclusive: bound.inclusive }) < 0) {
|
|
5548
|
-
value = cursorValue;
|
|
5549
|
-
inclusive = bound.inclusive;
|
|
5550
|
-
}
|
|
5551
|
-
break;
|
|
5552
|
-
}
|
|
5553
|
-
}
|
|
5580
|
+
function filterEquals(f1, f2) {
|
|
5581
|
+
if (f1 instanceof FieldFilter) {
|
|
5582
|
+
return fieldFilterEquals(f1, f2);
|
|
5554
5583
|
}
|
|
5555
|
-
|
|
5556
|
-
|
|
5557
|
-
/**
|
|
5558
|
-
* Returns the value to use as the upper bound for ascending index segment at
|
|
5559
|
-
* the provided `fieldPath` (or the lower bound for a descending segment).
|
|
5560
|
-
*/
|
|
5561
|
-
function targetGetDescendingBound(target, fieldPath, bound) {
|
|
5562
|
-
let value = MAX_VALUE;
|
|
5563
|
-
let inclusive = true;
|
|
5564
|
-
// Process all filters to find a value for the current field segment
|
|
5565
|
-
for (const fieldFilter of targetGetFieldFiltersForPath(target, fieldPath)) {
|
|
5566
|
-
let filterValue = MAX_VALUE;
|
|
5567
|
-
let filterInclusive = true;
|
|
5568
|
-
switch (fieldFilter.op) {
|
|
5569
|
-
case ">=" /* GREATER_THAN_OR_EQUAL */:
|
|
5570
|
-
case ">" /* GREATER_THAN */:
|
|
5571
|
-
filterValue = valuesGetUpperBound(fieldFilter.value);
|
|
5572
|
-
filterInclusive = false;
|
|
5573
|
-
break;
|
|
5574
|
-
case "==" /* EQUAL */:
|
|
5575
|
-
case "in" /* IN */:
|
|
5576
|
-
case "<=" /* LESS_THAN_OR_EQUAL */:
|
|
5577
|
-
filterValue = fieldFilter.value;
|
|
5578
|
-
break;
|
|
5579
|
-
case "<" /* LESS_THAN */:
|
|
5580
|
-
filterValue = fieldFilter.value;
|
|
5581
|
-
filterInclusive = false;
|
|
5582
|
-
break;
|
|
5583
|
-
case "!=" /* NOT_EQUAL */:
|
|
5584
|
-
case "not-in" /* NOT_IN */:
|
|
5585
|
-
filterValue = MAX_VALUE;
|
|
5586
|
-
break;
|
|
5587
|
-
// Remaining filters cannot be used as upper bounds.
|
|
5588
|
-
}
|
|
5589
|
-
if (upperBoundCompare({ value, inclusive }, { value: filterValue, inclusive: filterInclusive }) > 0) {
|
|
5590
|
-
value = filterValue;
|
|
5591
|
-
inclusive = filterInclusive;
|
|
5592
|
-
}
|
|
5584
|
+
else if (f1 instanceof CompositeFilter) {
|
|
5585
|
+
return compositeFilterEquals(f1, f2);
|
|
5593
5586
|
}
|
|
5594
|
-
|
|
5595
|
-
|
|
5596
|
-
if (bound !== null) {
|
|
5597
|
-
for (let i = 0; i < target.orderBy.length; ++i) {
|
|
5598
|
-
const orderBy = target.orderBy[i];
|
|
5599
|
-
if (orderBy.field.isEqual(fieldPath)) {
|
|
5600
|
-
const cursorValue = bound.position[i];
|
|
5601
|
-
if (upperBoundCompare({ value, inclusive }, { value: cursorValue, inclusive: bound.inclusive }) > 0) {
|
|
5602
|
-
value = cursorValue;
|
|
5603
|
-
inclusive = bound.inclusive;
|
|
5604
|
-
}
|
|
5605
|
-
break;
|
|
5606
|
-
}
|
|
5607
|
-
}
|
|
5587
|
+
else {
|
|
5588
|
+
fail();
|
|
5608
5589
|
}
|
|
5609
|
-
return { value, inclusive };
|
|
5610
5590
|
}
|
|
5611
|
-
|
|
5612
|
-
|
|
5613
|
-
|
|
5614
|
-
|
|
5615
|
-
|
|
5616
|
-
|
|
5617
|
-
|
|
5618
|
-
|
|
5619
|
-
|
|
5620
|
-
|
|
5621
|
-
|
|
5622
|
-
|
|
5623
|
-
// ARRAY_CONTAINS or ARRAY_CONTAINS_ANY filters must be counted separately.
|
|
5624
|
-
// For instance, it is possible to have an index for "a ARRAY a ASC". Even
|
|
5625
|
-
// though these are on the same field, they should be counted as two
|
|
5626
|
-
// separate segments in an index.
|
|
5627
|
-
if (fieldFilter.op === "array-contains" /* ARRAY_CONTAINS */ ||
|
|
5628
|
-
fieldFilter.op === "array-contains-any" /* ARRAY_CONTAINS_ANY */) {
|
|
5629
|
-
hasArraySegment = true;
|
|
5630
|
-
}
|
|
5631
|
-
else {
|
|
5632
|
-
fields = fields.add(fieldFilter.field);
|
|
5633
|
-
}
|
|
5634
|
-
}
|
|
5635
|
-
for (const orderBy of target.orderBy) {
|
|
5636
|
-
// __name__ is not an explicit segment of any index, so we don't need to
|
|
5637
|
-
// count it.
|
|
5638
|
-
if (!orderBy.field.isKeyField()) {
|
|
5639
|
-
fields = fields.add(orderBy.field);
|
|
5640
|
-
}
|
|
5591
|
+
function fieldFilterEquals(f1, f2) {
|
|
5592
|
+
return (f2 instanceof FieldFilter &&
|
|
5593
|
+
f1.op === f2.op &&
|
|
5594
|
+
f1.field.isEqual(f2.field) &&
|
|
5595
|
+
valueEquals(f1.value, f2.value));
|
|
5596
|
+
}
|
|
5597
|
+
function compositeFilterEquals(f1, f2) {
|
|
5598
|
+
if (f2 instanceof CompositeFilter &&
|
|
5599
|
+
f1.op === f2.op &&
|
|
5600
|
+
f1.filters.length === f2.filters.length) {
|
|
5601
|
+
const subFiltersMatch = f1.filters.reduce((result, f1Filter, index) => result && filterEquals(f1Filter, f2.filters[index]), true);
|
|
5602
|
+
return subFiltersMatch;
|
|
5641
5603
|
}
|
|
5642
|
-
return
|
|
5604
|
+
return false;
|
|
5643
5605
|
}
|
|
5644
|
-
|
|
5606
|
+
/**
|
|
5607
|
+
* Returns a new composite filter that contains all filter from
|
|
5608
|
+
* `compositeFilter` plus all the given filters in `otherFilters`.
|
|
5609
|
+
*/
|
|
5610
|
+
function compositeFilterWithAddedFilters(compositeFilter, otherFilters) {
|
|
5611
|
+
const mergedFilters = compositeFilter.filters.concat(otherFilters);
|
|
5612
|
+
return CompositeFilter.create(mergedFilters, compositeFilter.op);
|
|
5645
5613
|
}
|
|
5646
|
-
|
|
5647
|
-
|
|
5648
|
-
|
|
5649
|
-
|
|
5650
|
-
this.op = op;
|
|
5651
|
-
this.value = value;
|
|
5652
|
-
}
|
|
5653
|
-
/**
|
|
5654
|
-
* Creates a filter based on the provided arguments.
|
|
5655
|
-
*/
|
|
5656
|
-
static create(field, op, value) {
|
|
5657
|
-
if (field.isKeyField()) {
|
|
5658
|
-
if (op === "in" /* IN */ || op === "not-in" /* NOT_IN */) {
|
|
5659
|
-
return this.createKeyFieldInFilter(field, op, value);
|
|
5660
|
-
}
|
|
5661
|
-
else {
|
|
5662
|
-
return new KeyFieldFilter(field, op, value);
|
|
5663
|
-
}
|
|
5664
|
-
}
|
|
5665
|
-
else if (op === "array-contains" /* ARRAY_CONTAINS */) {
|
|
5666
|
-
return new ArrayContainsFilter(field, value);
|
|
5667
|
-
}
|
|
5668
|
-
else if (op === "in" /* IN */) {
|
|
5669
|
-
return new InFilter(field, value);
|
|
5670
|
-
}
|
|
5671
|
-
else if (op === "not-in" /* NOT_IN */) {
|
|
5672
|
-
return new NotInFilter(field, value);
|
|
5673
|
-
}
|
|
5674
|
-
else if (op === "array-contains-any" /* ARRAY_CONTAINS_ANY */) {
|
|
5675
|
-
return new ArrayContainsAnyFilter(field, value);
|
|
5676
|
-
}
|
|
5677
|
-
else {
|
|
5678
|
-
return new FieldFilter(field, op, value);
|
|
5679
|
-
}
|
|
5680
|
-
}
|
|
5681
|
-
static createKeyFieldInFilter(field, op, value) {
|
|
5682
|
-
return op === "in" /* IN */
|
|
5683
|
-
? new KeyFieldInFilter(field, value)
|
|
5684
|
-
: new KeyFieldNotInFilter(field, value);
|
|
5685
|
-
}
|
|
5686
|
-
matches(doc) {
|
|
5687
|
-
const other = doc.data.field(this.field);
|
|
5688
|
-
// Types do not have to match in NOT_EQUAL filters.
|
|
5689
|
-
if (this.op === "!=" /* NOT_EQUAL */) {
|
|
5690
|
-
return (other !== null &&
|
|
5691
|
-
this.matchesComparison(valueCompare(other, this.value)));
|
|
5692
|
-
}
|
|
5693
|
-
// Only compare types with matching backend order (such as double and int).
|
|
5694
|
-
return (other !== null &&
|
|
5695
|
-
typeOrder(this.value) === typeOrder(other) &&
|
|
5696
|
-
this.matchesComparison(valueCompare(other, this.value)));
|
|
5614
|
+
/** Returns a debug description for `filter`. */
|
|
5615
|
+
function stringifyFilter(filter) {
|
|
5616
|
+
if (filter instanceof FieldFilter) {
|
|
5617
|
+
return stringifyFieldFilter(filter);
|
|
5697
5618
|
}
|
|
5698
|
-
|
|
5699
|
-
|
|
5700
|
-
case "<" /* LESS_THAN */:
|
|
5701
|
-
return comparison < 0;
|
|
5702
|
-
case "<=" /* LESS_THAN_OR_EQUAL */:
|
|
5703
|
-
return comparison <= 0;
|
|
5704
|
-
case "==" /* EQUAL */:
|
|
5705
|
-
return comparison === 0;
|
|
5706
|
-
case "!=" /* NOT_EQUAL */:
|
|
5707
|
-
return comparison !== 0;
|
|
5708
|
-
case ">" /* GREATER_THAN */:
|
|
5709
|
-
return comparison > 0;
|
|
5710
|
-
case ">=" /* GREATER_THAN_OR_EQUAL */:
|
|
5711
|
-
return comparison >= 0;
|
|
5712
|
-
default:
|
|
5713
|
-
return fail();
|
|
5714
|
-
}
|
|
5619
|
+
else if (filter instanceof CompositeFilter) {
|
|
5620
|
+
return stringifyCompositeFilter(filter);
|
|
5715
5621
|
}
|
|
5716
|
-
|
|
5717
|
-
return
|
|
5718
|
-
"<" /* LESS_THAN */,
|
|
5719
|
-
"<=" /* LESS_THAN_OR_EQUAL */,
|
|
5720
|
-
">" /* GREATER_THAN */,
|
|
5721
|
-
">=" /* GREATER_THAN_OR_EQUAL */,
|
|
5722
|
-
"!=" /* NOT_EQUAL */,
|
|
5723
|
-
"not-in" /* NOT_IN */
|
|
5724
|
-
].indexOf(this.op) >= 0);
|
|
5622
|
+
else {
|
|
5623
|
+
return 'Filter';
|
|
5725
5624
|
}
|
|
5726
5625
|
}
|
|
5727
|
-
function
|
|
5728
|
-
|
|
5729
|
-
|
|
5730
|
-
|
|
5731
|
-
|
|
5732
|
-
filter.op.toString() +
|
|
5733
|
-
canonicalId(filter.value));
|
|
5734
|
-
}
|
|
5735
|
-
function filterEquals(f1, f2) {
|
|
5736
|
-
return (f1.op === f2.op &&
|
|
5737
|
-
f1.field.isEqual(f2.field) &&
|
|
5738
|
-
valueEquals(f1.value, f2.value));
|
|
5626
|
+
function stringifyCompositeFilter(filter) {
|
|
5627
|
+
return (filter.op.toString() +
|
|
5628
|
+
` {` +
|
|
5629
|
+
filter.getFilters().map(stringifyFilter).join(' ,') +
|
|
5630
|
+
'}');
|
|
5739
5631
|
}
|
|
5740
|
-
|
|
5741
|
-
function stringifyFilter(filter) {
|
|
5632
|
+
function stringifyFieldFilter(filter) {
|
|
5742
5633
|
return `${filter.field.canonicalString()} ${filter.op} ${canonicalId(filter.value)}`;
|
|
5743
5634
|
}
|
|
5744
5635
|
/** Filter that matches on key fields (i.e. '__name__'). */
|
|
@@ -5755,8 +5646,8 @@ class KeyFieldFilter extends FieldFilter {
|
|
|
5755
5646
|
/** Filter that matches on key fields within an array. */
|
|
5756
5647
|
class KeyFieldInFilter extends FieldFilter {
|
|
5757
5648
|
constructor(field, value) {
|
|
5758
|
-
super(field, "in" /* IN */, value);
|
|
5759
|
-
this.keys = extractDocumentKeysFromArrayValue("in" /* IN */, value);
|
|
5649
|
+
super(field, "in" /* Operator.IN */, value);
|
|
5650
|
+
this.keys = extractDocumentKeysFromArrayValue("in" /* Operator.IN */, value);
|
|
5760
5651
|
}
|
|
5761
5652
|
matches(doc) {
|
|
5762
5653
|
return this.keys.some(key => key.isEqual(doc.key));
|
|
@@ -5765,8 +5656,8 @@ class KeyFieldInFilter extends FieldFilter {
|
|
|
5765
5656
|
/** Filter that matches on key fields not present within an array. */
|
|
5766
5657
|
class KeyFieldNotInFilter extends FieldFilter {
|
|
5767
5658
|
constructor(field, value) {
|
|
5768
|
-
super(field, "not-in" /* NOT_IN */, value);
|
|
5769
|
-
this.keys = extractDocumentKeysFromArrayValue("not-in" /* NOT_IN */, value);
|
|
5659
|
+
super(field, "not-in" /* Operator.NOT_IN */, value);
|
|
5660
|
+
this.keys = extractDocumentKeysFromArrayValue("not-in" /* Operator.NOT_IN */, value);
|
|
5770
5661
|
}
|
|
5771
5662
|
matches(doc) {
|
|
5772
5663
|
return !this.keys.some(key => key.isEqual(doc.key));
|
|
@@ -5781,7 +5672,7 @@ function extractDocumentKeysFromArrayValue(op, value) {
|
|
|
5781
5672
|
/** A Filter that implements the array-contains operator. */
|
|
5782
5673
|
class ArrayContainsFilter extends FieldFilter {
|
|
5783
5674
|
constructor(field, value) {
|
|
5784
|
-
super(field, "array-contains" /* ARRAY_CONTAINS */, value);
|
|
5675
|
+
super(field, "array-contains" /* Operator.ARRAY_CONTAINS */, value);
|
|
5785
5676
|
}
|
|
5786
5677
|
matches(doc) {
|
|
5787
5678
|
const other = doc.data.field(this.field);
|
|
@@ -5791,7 +5682,7 @@ class ArrayContainsFilter extends FieldFilter {
|
|
|
5791
5682
|
/** A Filter that implements the IN operator. */
|
|
5792
5683
|
class InFilter extends FieldFilter {
|
|
5793
5684
|
constructor(field, value) {
|
|
5794
|
-
super(field, "in" /* IN */, value);
|
|
5685
|
+
super(field, "in" /* Operator.IN */, value);
|
|
5795
5686
|
}
|
|
5796
5687
|
matches(doc) {
|
|
5797
5688
|
const other = doc.data.field(this.field);
|
|
@@ -5801,7 +5692,7 @@ class InFilter extends FieldFilter {
|
|
|
5801
5692
|
/** A Filter that implements the not-in operator. */
|
|
5802
5693
|
class NotInFilter extends FieldFilter {
|
|
5803
5694
|
constructor(field, value) {
|
|
5804
|
-
super(field, "not-in" /* NOT_IN */, value);
|
|
5695
|
+
super(field, "not-in" /* Operator.NOT_IN */, value);
|
|
5805
5696
|
}
|
|
5806
5697
|
matches(doc) {
|
|
5807
5698
|
if (arrayValueContains(this.value.arrayValue, { nullValue: 'NULL_VALUE' })) {
|
|
@@ -5814,7 +5705,7 @@ class NotInFilter extends FieldFilter {
|
|
|
5814
5705
|
/** A Filter that implements the array-contains-any operator. */
|
|
5815
5706
|
class ArrayContainsAnyFilter extends FieldFilter {
|
|
5816
5707
|
constructor(field, value) {
|
|
5817
|
-
super(field, "array-contains-any" /* ARRAY_CONTAINS_ANY */, value);
|
|
5708
|
+
super(field, "array-contains-any" /* Operator.ARRAY_CONTAINS_ANY */, value);
|
|
5818
5709
|
}
|
|
5819
5710
|
matches(doc) {
|
|
5820
5711
|
const other = doc.data.field(this.field);
|
|
@@ -5823,32 +5714,29 @@ class ArrayContainsAnyFilter extends FieldFilter {
|
|
|
5823
5714
|
}
|
|
5824
5715
|
return other.arrayValue.values.some(val => arrayValueContains(this.value.arrayValue, val));
|
|
5825
5716
|
}
|
|
5826
|
-
}
|
|
5717
|
+
}
|
|
5718
|
+
|
|
5827
5719
|
/**
|
|
5828
|
-
*
|
|
5720
|
+
* @license
|
|
5721
|
+
* Copyright 2022 Google LLC
|
|
5829
5722
|
*
|
|
5830
|
-
*
|
|
5831
|
-
*
|
|
5832
|
-
*
|
|
5723
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5724
|
+
* you may not use this file except in compliance with the License.
|
|
5725
|
+
* You may obtain a copy of the License at
|
|
5833
5726
|
*
|
|
5834
|
-
*
|
|
5835
|
-
* of values for the (potentially implicit) order by clauses of a query.
|
|
5727
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
5836
5728
|
*
|
|
5837
|
-
*
|
|
5838
|
-
*
|
|
5839
|
-
*
|
|
5729
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
5730
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
5731
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
5732
|
+
* See the License for the specific language governing permissions and
|
|
5733
|
+
* limitations under the License.
|
|
5840
5734
|
*/
|
|
5841
|
-
class Bound {
|
|
5842
|
-
constructor(position, inclusive) {
|
|
5843
|
-
this.position = position;
|
|
5844
|
-
this.inclusive = inclusive;
|
|
5845
|
-
}
|
|
5846
|
-
}
|
|
5847
5735
|
/**
|
|
5848
5736
|
* An ordering on a field, in some Direction. Direction defaults to ASCENDING.
|
|
5849
5737
|
*/
|
|
5850
5738
|
class OrderBy {
|
|
5851
|
-
constructor(field, dir = "asc" /* ASCENDING */) {
|
|
5739
|
+
constructor(field, dir = "asc" /* Direction.ASCENDING */) {
|
|
5852
5740
|
this.field = field;
|
|
5853
5741
|
this.dir = dir;
|
|
5854
5742
|
}
|
|
@@ -5862,63 +5750,375 @@ function stringifyOrderBy(orderBy) {
|
|
|
5862
5750
|
}
|
|
5863
5751
|
function orderByEquals(left, right) {
|
|
5864
5752
|
return left.dir === right.dir && left.field.isEqual(right.field);
|
|
5753
|
+
}
|
|
5754
|
+
|
|
5755
|
+
/**
|
|
5756
|
+
* @license
|
|
5757
|
+
* Copyright 2019 Google LLC
|
|
5758
|
+
*
|
|
5759
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5760
|
+
* you may not use this file except in compliance with the License.
|
|
5761
|
+
* You may obtain a copy of the License at
|
|
5762
|
+
*
|
|
5763
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
5764
|
+
*
|
|
5765
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
5766
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
5767
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
5768
|
+
* See the License for the specific language governing permissions and
|
|
5769
|
+
* limitations under the License.
|
|
5770
|
+
*/
|
|
5771
|
+
// Visible for testing
|
|
5772
|
+
class TargetImpl {
|
|
5773
|
+
constructor(path, collectionGroup = null, orderBy = [], filters = [], limit = null, startAt = null, endAt = null) {
|
|
5774
|
+
this.path = path;
|
|
5775
|
+
this.collectionGroup = collectionGroup;
|
|
5776
|
+
this.orderBy = orderBy;
|
|
5777
|
+
this.filters = filters;
|
|
5778
|
+
this.limit = limit;
|
|
5779
|
+
this.startAt = startAt;
|
|
5780
|
+
this.endAt = endAt;
|
|
5781
|
+
this.memoizedCanonicalId = null;
|
|
5782
|
+
}
|
|
5865
5783
|
}
|
|
5866
|
-
|
|
5867
|
-
|
|
5868
|
-
|
|
5869
|
-
|
|
5870
|
-
|
|
5871
|
-
|
|
5872
|
-
|
|
5784
|
+
/**
|
|
5785
|
+
* Initializes a Target with a path and optional additional query constraints.
|
|
5786
|
+
* Path must currently be empty if this is a collection group query.
|
|
5787
|
+
*
|
|
5788
|
+
* NOTE: you should always construct `Target` from `Query.toTarget` instead of
|
|
5789
|
+
* using this factory method, because `Query` provides an implicit `orderBy`
|
|
5790
|
+
* property.
|
|
5791
|
+
*/
|
|
5792
|
+
function newTarget(path, collectionGroup = null, orderBy = [], filters = [], limit = null, startAt = null, endAt = null) {
|
|
5793
|
+
return new TargetImpl(path, collectionGroup, orderBy, filters, limit, startAt, endAt);
|
|
5794
|
+
}
|
|
5795
|
+
function canonifyTarget(target) {
|
|
5796
|
+
const targetImpl = debugCast(target);
|
|
5797
|
+
if (targetImpl.memoizedCanonicalId === null) {
|
|
5798
|
+
let str = targetImpl.path.canonicalString();
|
|
5799
|
+
if (targetImpl.collectionGroup !== null) {
|
|
5800
|
+
str += '|cg:' + targetImpl.collectionGroup;
|
|
5873
5801
|
}
|
|
5874
|
-
|
|
5875
|
-
|
|
5876
|
-
|
|
5802
|
+
str += '|f:';
|
|
5803
|
+
str += targetImpl.filters.map(f => canonifyFilter(f)).join(',');
|
|
5804
|
+
str += '|ob:';
|
|
5805
|
+
str += targetImpl.orderBy.map(o => canonifyOrderBy(o)).join(',');
|
|
5806
|
+
if (!isNullOrUndefined(targetImpl.limit)) {
|
|
5807
|
+
str += '|l:';
|
|
5808
|
+
str += targetImpl.limit;
|
|
5877
5809
|
}
|
|
5878
|
-
if (
|
|
5879
|
-
|
|
5810
|
+
if (targetImpl.startAt) {
|
|
5811
|
+
str += '|lb:';
|
|
5812
|
+
str += targetImpl.startAt.inclusive ? 'b:' : 'a:';
|
|
5813
|
+
str += targetImpl.startAt.position.map(p => canonicalId(p)).join(',');
|
|
5880
5814
|
}
|
|
5881
|
-
if (
|
|
5882
|
-
|
|
5815
|
+
if (targetImpl.endAt) {
|
|
5816
|
+
str += '|ub:';
|
|
5817
|
+
str += targetImpl.endAt.inclusive ? 'a:' : 'b:';
|
|
5818
|
+
str += targetImpl.endAt.position.map(p => canonicalId(p)).join(',');
|
|
5883
5819
|
}
|
|
5820
|
+
targetImpl.memoizedCanonicalId = str;
|
|
5884
5821
|
}
|
|
5885
|
-
return
|
|
5822
|
+
return targetImpl.memoizedCanonicalId;
|
|
5823
|
+
}
|
|
5824
|
+
function stringifyTarget(target) {
|
|
5825
|
+
let str = target.path.canonicalString();
|
|
5826
|
+
if (target.collectionGroup !== null) {
|
|
5827
|
+
str += ' collectionGroup=' + target.collectionGroup;
|
|
5828
|
+
}
|
|
5829
|
+
if (target.filters.length > 0) {
|
|
5830
|
+
str += `, filters: [${target.filters
|
|
5831
|
+
.map(f => stringifyFilter(f))
|
|
5832
|
+
.join(', ')}]`;
|
|
5833
|
+
}
|
|
5834
|
+
if (!isNullOrUndefined(target.limit)) {
|
|
5835
|
+
str += ', limit: ' + target.limit;
|
|
5836
|
+
}
|
|
5837
|
+
if (target.orderBy.length > 0) {
|
|
5838
|
+
str += `, orderBy: [${target.orderBy
|
|
5839
|
+
.map(o => stringifyOrderBy(o))
|
|
5840
|
+
.join(', ')}]`;
|
|
5841
|
+
}
|
|
5842
|
+
if (target.startAt) {
|
|
5843
|
+
str += ', startAt: ';
|
|
5844
|
+
str += target.startAt.inclusive ? 'b:' : 'a:';
|
|
5845
|
+
str += target.startAt.position.map(p => canonicalId(p)).join(',');
|
|
5846
|
+
}
|
|
5847
|
+
if (target.endAt) {
|
|
5848
|
+
str += ', endAt: ';
|
|
5849
|
+
str += target.endAt.inclusive ? 'a:' : 'b:';
|
|
5850
|
+
str += target.endAt.position.map(p => canonicalId(p)).join(',');
|
|
5851
|
+
}
|
|
5852
|
+
return `Target(${str})`;
|
|
5853
|
+
}
|
|
5854
|
+
function targetEquals(left, right) {
|
|
5855
|
+
if (left.limit !== right.limit) {
|
|
5856
|
+
return false;
|
|
5857
|
+
}
|
|
5858
|
+
if (left.orderBy.length !== right.orderBy.length) {
|
|
5859
|
+
return false;
|
|
5860
|
+
}
|
|
5861
|
+
for (let i = 0; i < left.orderBy.length; i++) {
|
|
5862
|
+
if (!orderByEquals(left.orderBy[i], right.orderBy[i])) {
|
|
5863
|
+
return false;
|
|
5864
|
+
}
|
|
5865
|
+
}
|
|
5866
|
+
if (left.filters.length !== right.filters.length) {
|
|
5867
|
+
return false;
|
|
5868
|
+
}
|
|
5869
|
+
for (let i = 0; i < left.filters.length; i++) {
|
|
5870
|
+
if (!filterEquals(left.filters[i], right.filters[i])) {
|
|
5871
|
+
return false;
|
|
5872
|
+
}
|
|
5873
|
+
}
|
|
5874
|
+
if (left.collectionGroup !== right.collectionGroup) {
|
|
5875
|
+
return false;
|
|
5876
|
+
}
|
|
5877
|
+
if (!left.path.isEqual(right.path)) {
|
|
5878
|
+
return false;
|
|
5879
|
+
}
|
|
5880
|
+
if (!boundEquals(left.startAt, right.startAt)) {
|
|
5881
|
+
return false;
|
|
5882
|
+
}
|
|
5883
|
+
return boundEquals(left.endAt, right.endAt);
|
|
5884
|
+
}
|
|
5885
|
+
function targetIsDocumentTarget(target) {
|
|
5886
|
+
return (DocumentKey.isDocumentKey(target.path) &&
|
|
5887
|
+
target.collectionGroup === null &&
|
|
5888
|
+
target.filters.length === 0);
|
|
5889
|
+
}
|
|
5890
|
+
/** Returns the field filters that target the given field path. */
|
|
5891
|
+
function targetGetFieldFiltersForPath(target, path) {
|
|
5892
|
+
return target.filters.filter(f => f instanceof FieldFilter && f.field.isEqual(path));
|
|
5886
5893
|
}
|
|
5887
5894
|
/**
|
|
5888
|
-
* Returns
|
|
5889
|
-
*
|
|
5895
|
+
* Returns the values that are used in ARRAY_CONTAINS or ARRAY_CONTAINS_ANY
|
|
5896
|
+
* filters. Returns `null` if there are no such filters.
|
|
5890
5897
|
*/
|
|
5891
|
-
function
|
|
5892
|
-
const
|
|
5893
|
-
|
|
5898
|
+
function targetGetArrayValues(target, fieldIndex) {
|
|
5899
|
+
const segment = fieldIndexGetArraySegment(fieldIndex);
|
|
5900
|
+
if (segment === undefined) {
|
|
5901
|
+
return null;
|
|
5902
|
+
}
|
|
5903
|
+
for (const fieldFilter of targetGetFieldFiltersForPath(target, segment.fieldPath)) {
|
|
5904
|
+
switch (fieldFilter.op) {
|
|
5905
|
+
case "array-contains-any" /* Operator.ARRAY_CONTAINS_ANY */:
|
|
5906
|
+
return fieldFilter.value.arrayValue.values || [];
|
|
5907
|
+
case "array-contains" /* Operator.ARRAY_CONTAINS */:
|
|
5908
|
+
return [fieldFilter.value];
|
|
5909
|
+
// Remaining filters are not array filters.
|
|
5910
|
+
}
|
|
5911
|
+
}
|
|
5912
|
+
return null;
|
|
5894
5913
|
}
|
|
5895
5914
|
/**
|
|
5896
|
-
* Returns
|
|
5897
|
-
*
|
|
5915
|
+
* Returns the list of values that are used in != or NOT_IN filters. Returns
|
|
5916
|
+
* `null` if there are no such filters.
|
|
5898
5917
|
*/
|
|
5899
|
-
function
|
|
5900
|
-
const
|
|
5901
|
-
|
|
5918
|
+
function targetGetNotInValues(target, fieldIndex) {
|
|
5919
|
+
const values = new Map();
|
|
5920
|
+
for (const segment of fieldIndexGetDirectionalSegments(fieldIndex)) {
|
|
5921
|
+
for (const fieldFilter of targetGetFieldFiltersForPath(target, segment.fieldPath)) {
|
|
5922
|
+
switch (fieldFilter.op) {
|
|
5923
|
+
case "==" /* Operator.EQUAL */:
|
|
5924
|
+
case "in" /* Operator.IN */:
|
|
5925
|
+
// Encode equality prefix, which is encoded in the index value before
|
|
5926
|
+
// the inequality (e.g. `a == 'a' && b != 'b'` is encoded to
|
|
5927
|
+
// `value != 'ab'`).
|
|
5928
|
+
values.set(segment.fieldPath.canonicalString(), fieldFilter.value);
|
|
5929
|
+
break;
|
|
5930
|
+
case "not-in" /* Operator.NOT_IN */:
|
|
5931
|
+
case "!=" /* Operator.NOT_EQUAL */:
|
|
5932
|
+
// NotIn/NotEqual is always a suffix. There cannot be any remaining
|
|
5933
|
+
// segments and hence we can return early here.
|
|
5934
|
+
values.set(segment.fieldPath.canonicalString(), fieldFilter.value);
|
|
5935
|
+
return Array.from(values.values());
|
|
5936
|
+
// Remaining filters cannot be used as notIn bounds.
|
|
5937
|
+
}
|
|
5938
|
+
}
|
|
5939
|
+
}
|
|
5940
|
+
return null;
|
|
5902
5941
|
}
|
|
5903
|
-
|
|
5904
|
-
|
|
5905
|
-
|
|
5942
|
+
/**
|
|
5943
|
+
* Returns a lower bound of field values that can be used as a starting point to
|
|
5944
|
+
* scan the index defined by `fieldIndex`. Returns `MIN_VALUE` if no lower bound
|
|
5945
|
+
* exists.
|
|
5946
|
+
*/
|
|
5947
|
+
function targetGetLowerBound(target, fieldIndex) {
|
|
5948
|
+
const values = [];
|
|
5949
|
+
let inclusive = true;
|
|
5950
|
+
// For each segment, retrieve a lower bound if there is a suitable filter or
|
|
5951
|
+
// startAt.
|
|
5952
|
+
for (const segment of fieldIndexGetDirectionalSegments(fieldIndex)) {
|
|
5953
|
+
const segmentBound = segment.kind === 0 /* IndexKind.ASCENDING */
|
|
5954
|
+
? targetGetAscendingBound(target, segment.fieldPath, target.startAt)
|
|
5955
|
+
: targetGetDescendingBound(target, segment.fieldPath, target.startAt);
|
|
5956
|
+
values.push(segmentBound.value);
|
|
5957
|
+
inclusive && (inclusive = segmentBound.inclusive);
|
|
5958
|
+
}
|
|
5959
|
+
return new Bound(values, inclusive);
|
|
5960
|
+
}
|
|
5961
|
+
/**
|
|
5962
|
+
* Returns an upper bound of field values that can be used as an ending point
|
|
5963
|
+
* when scanning the index defined by `fieldIndex`. Returns `MAX_VALUE` if no
|
|
5964
|
+
* upper bound exists.
|
|
5965
|
+
*/
|
|
5966
|
+
function targetGetUpperBound(target, fieldIndex) {
|
|
5967
|
+
const values = [];
|
|
5968
|
+
let inclusive = true;
|
|
5969
|
+
// For each segment, retrieve an upper bound if there is a suitable filter or
|
|
5970
|
+
// endAt.
|
|
5971
|
+
for (const segment of fieldIndexGetDirectionalSegments(fieldIndex)) {
|
|
5972
|
+
const segmentBound = segment.kind === 0 /* IndexKind.ASCENDING */
|
|
5973
|
+
? targetGetDescendingBound(target, segment.fieldPath, target.endAt)
|
|
5974
|
+
: targetGetAscendingBound(target, segment.fieldPath, target.endAt);
|
|
5975
|
+
values.push(segmentBound.value);
|
|
5976
|
+
inclusive && (inclusive = segmentBound.inclusive);
|
|
5977
|
+
}
|
|
5978
|
+
return new Bound(values, inclusive);
|
|
5979
|
+
}
|
|
5980
|
+
/**
|
|
5981
|
+
* Returns the value to use as the lower bound for ascending index segment at
|
|
5982
|
+
* the provided `fieldPath` (or the upper bound for an descending segment).
|
|
5983
|
+
*/
|
|
5984
|
+
function targetGetAscendingBound(target, fieldPath, bound) {
|
|
5985
|
+
let value = MIN_VALUE;
|
|
5986
|
+
let inclusive = true;
|
|
5987
|
+
// Process all filters to find a value for the current field segment
|
|
5988
|
+
for (const fieldFilter of targetGetFieldFiltersForPath(target, fieldPath)) {
|
|
5989
|
+
let filterValue = MIN_VALUE;
|
|
5990
|
+
let filterInclusive = true;
|
|
5991
|
+
switch (fieldFilter.op) {
|
|
5992
|
+
case "<" /* Operator.LESS_THAN */:
|
|
5993
|
+
case "<=" /* Operator.LESS_THAN_OR_EQUAL */:
|
|
5994
|
+
filterValue = valuesGetLowerBound(fieldFilter.value);
|
|
5995
|
+
break;
|
|
5996
|
+
case "==" /* Operator.EQUAL */:
|
|
5997
|
+
case "in" /* Operator.IN */:
|
|
5998
|
+
case ">=" /* Operator.GREATER_THAN_OR_EQUAL */:
|
|
5999
|
+
filterValue = fieldFilter.value;
|
|
6000
|
+
break;
|
|
6001
|
+
case ">" /* Operator.GREATER_THAN */:
|
|
6002
|
+
filterValue = fieldFilter.value;
|
|
6003
|
+
filterInclusive = false;
|
|
6004
|
+
break;
|
|
6005
|
+
case "!=" /* Operator.NOT_EQUAL */:
|
|
6006
|
+
case "not-in" /* Operator.NOT_IN */:
|
|
6007
|
+
filterValue = MIN_VALUE;
|
|
6008
|
+
break;
|
|
6009
|
+
// Remaining filters cannot be used as lower bounds.
|
|
6010
|
+
}
|
|
6011
|
+
if (lowerBoundCompare({ value, inclusive }, { value: filterValue, inclusive: filterInclusive }) < 0) {
|
|
6012
|
+
value = filterValue;
|
|
6013
|
+
inclusive = filterInclusive;
|
|
6014
|
+
}
|
|
6015
|
+
}
|
|
6016
|
+
// If there is an additional bound, compare the values against the existing
|
|
6017
|
+
// range to see if we can narrow the scope.
|
|
6018
|
+
if (bound !== null) {
|
|
6019
|
+
for (let i = 0; i < target.orderBy.length; ++i) {
|
|
6020
|
+
const orderBy = target.orderBy[i];
|
|
6021
|
+
if (orderBy.field.isEqual(fieldPath)) {
|
|
6022
|
+
const cursorValue = bound.position[i];
|
|
6023
|
+
if (lowerBoundCompare({ value, inclusive }, { value: cursorValue, inclusive: bound.inclusive }) < 0) {
|
|
6024
|
+
value = cursorValue;
|
|
6025
|
+
inclusive = bound.inclusive;
|
|
6026
|
+
}
|
|
6027
|
+
break;
|
|
6028
|
+
}
|
|
6029
|
+
}
|
|
6030
|
+
}
|
|
6031
|
+
return { value, inclusive };
|
|
6032
|
+
}
|
|
6033
|
+
/**
|
|
6034
|
+
* Returns the value to use as the upper bound for ascending index segment at
|
|
6035
|
+
* the provided `fieldPath` (or the lower bound for a descending segment).
|
|
6036
|
+
*/
|
|
6037
|
+
function targetGetDescendingBound(target, fieldPath, bound) {
|
|
6038
|
+
let value = MAX_VALUE;
|
|
6039
|
+
let inclusive = true;
|
|
6040
|
+
// Process all filters to find a value for the current field segment
|
|
6041
|
+
for (const fieldFilter of targetGetFieldFiltersForPath(target, fieldPath)) {
|
|
6042
|
+
let filterValue = MAX_VALUE;
|
|
6043
|
+
let filterInclusive = true;
|
|
6044
|
+
switch (fieldFilter.op) {
|
|
6045
|
+
case ">=" /* Operator.GREATER_THAN_OR_EQUAL */:
|
|
6046
|
+
case ">" /* Operator.GREATER_THAN */:
|
|
6047
|
+
filterValue = valuesGetUpperBound(fieldFilter.value);
|
|
6048
|
+
filterInclusive = false;
|
|
6049
|
+
break;
|
|
6050
|
+
case "==" /* Operator.EQUAL */:
|
|
6051
|
+
case "in" /* Operator.IN */:
|
|
6052
|
+
case "<=" /* Operator.LESS_THAN_OR_EQUAL */:
|
|
6053
|
+
filterValue = fieldFilter.value;
|
|
6054
|
+
break;
|
|
6055
|
+
case "<" /* Operator.LESS_THAN */:
|
|
6056
|
+
filterValue = fieldFilter.value;
|
|
6057
|
+
filterInclusive = false;
|
|
6058
|
+
break;
|
|
6059
|
+
case "!=" /* Operator.NOT_EQUAL */:
|
|
6060
|
+
case "not-in" /* Operator.NOT_IN */:
|
|
6061
|
+
filterValue = MAX_VALUE;
|
|
6062
|
+
break;
|
|
6063
|
+
// Remaining filters cannot be used as upper bounds.
|
|
6064
|
+
}
|
|
6065
|
+
if (upperBoundCompare({ value, inclusive }, { value: filterValue, inclusive: filterInclusive }) > 0) {
|
|
6066
|
+
value = filterValue;
|
|
6067
|
+
inclusive = filterInclusive;
|
|
6068
|
+
}
|
|
5906
6069
|
}
|
|
5907
|
-
|
|
5908
|
-
|
|
6070
|
+
// If there is an additional bound, compare the values against the existing
|
|
6071
|
+
// range to see if we can narrow the scope.
|
|
6072
|
+
if (bound !== null) {
|
|
6073
|
+
for (let i = 0; i < target.orderBy.length; ++i) {
|
|
6074
|
+
const orderBy = target.orderBy[i];
|
|
6075
|
+
if (orderBy.field.isEqual(fieldPath)) {
|
|
6076
|
+
const cursorValue = bound.position[i];
|
|
6077
|
+
if (upperBoundCompare({ value, inclusive }, { value: cursorValue, inclusive: bound.inclusive }) > 0) {
|
|
6078
|
+
value = cursorValue;
|
|
6079
|
+
inclusive = bound.inclusive;
|
|
6080
|
+
}
|
|
6081
|
+
break;
|
|
6082
|
+
}
|
|
6083
|
+
}
|
|
5909
6084
|
}
|
|
5910
|
-
|
|
5911
|
-
|
|
5912
|
-
|
|
6085
|
+
return { value, inclusive };
|
|
6086
|
+
}
|
|
6087
|
+
/** Returns the number of segments of a perfect index for this target. */
|
|
6088
|
+
function targetGetSegmentCount(target) {
|
|
6089
|
+
let fields = new SortedSet(FieldPath$1.comparator);
|
|
6090
|
+
let hasArraySegment = false;
|
|
6091
|
+
for (const filter of target.filters) {
|
|
6092
|
+
for (const subFilter of filter.getFlattenedFilters()) {
|
|
6093
|
+
// __name__ is not an explicit segment of any index, so we don't need to
|
|
6094
|
+
// count it.
|
|
6095
|
+
if (subFilter.field.isKeyField()) {
|
|
6096
|
+
continue;
|
|
6097
|
+
}
|
|
6098
|
+
// ARRAY_CONTAINS or ARRAY_CONTAINS_ANY filters must be counted separately.
|
|
6099
|
+
// For instance, it is possible to have an index for "a ARRAY a ASC". Even
|
|
6100
|
+
// though these are on the same field, they should be counted as two
|
|
6101
|
+
// separate segments in an index.
|
|
6102
|
+
if (subFilter.op === "array-contains" /* Operator.ARRAY_CONTAINS */ ||
|
|
6103
|
+
subFilter.op === "array-contains-any" /* Operator.ARRAY_CONTAINS_ANY */) {
|
|
6104
|
+
hasArraySegment = true;
|
|
6105
|
+
}
|
|
6106
|
+
else {
|
|
6107
|
+
fields = fields.add(subFilter.field);
|
|
6108
|
+
}
|
|
6109
|
+
}
|
|
5913
6110
|
}
|
|
5914
|
-
for (
|
|
5915
|
-
|
|
5916
|
-
|
|
5917
|
-
if (!
|
|
5918
|
-
|
|
6111
|
+
for (const orderBy of target.orderBy) {
|
|
6112
|
+
// __name__ is not an explicit segment of any index, so we don't need to
|
|
6113
|
+
// count it.
|
|
6114
|
+
if (!orderBy.field.isKeyField()) {
|
|
6115
|
+
fields = fields.add(orderBy.field);
|
|
5919
6116
|
}
|
|
5920
6117
|
}
|
|
5921
|
-
return
|
|
6118
|
+
return fields.size + (hasArraySegment ? 1 : 0);
|
|
6119
|
+
}
|
|
6120
|
+
function targetHasLimit(target) {
|
|
6121
|
+
return target.limit !== null;
|
|
5922
6122
|
}
|
|
5923
6123
|
|
|
5924
6124
|
/**
|
|
@@ -5949,7 +6149,7 @@ class QueryImpl {
|
|
|
5949
6149
|
* Initializes a Query with a path and optional additional query constraints.
|
|
5950
6150
|
* Path must currently be empty if this is a collection group query.
|
|
5951
6151
|
*/
|
|
5952
|
-
constructor(path, collectionGroup = null, explicitOrderBy = [], filters = [], limit = null, limitType = "F" /* First */, startAt = null, endAt = null) {
|
|
6152
|
+
constructor(path, collectionGroup = null, explicitOrderBy = [], filters = [], limit = null, limitType = "F" /* LimitType.First */, startAt = null, endAt = null) {
|
|
5953
6153
|
this.path = path;
|
|
5954
6154
|
this.collectionGroup = collectionGroup;
|
|
5955
6155
|
this.explicitOrderBy = explicitOrderBy;
|
|
@@ -6003,20 +6203,9 @@ function getFirstOrderByField(query) {
|
|
|
6003
6203
|
}
|
|
6004
6204
|
function getInequalityFilterField(query) {
|
|
6005
6205
|
for (const filter of query.filters) {
|
|
6006
|
-
|
|
6007
|
-
|
|
6008
|
-
|
|
6009
|
-
}
|
|
6010
|
-
return null;
|
|
6011
|
-
}
|
|
6012
|
-
/**
|
|
6013
|
-
* Checks if any of the provided Operators are included in the query and
|
|
6014
|
-
* returns the first one that is, or null if none are.
|
|
6015
|
-
*/
|
|
6016
|
-
function findFilterOperator(query, operators) {
|
|
6017
|
-
for (const filter of query.filters) {
|
|
6018
|
-
if (operators.indexOf(filter.op) >= 0) {
|
|
6019
|
-
return filter.op;
|
|
6206
|
+
const result = filter.getFirstInequalityField();
|
|
6207
|
+
if (result !== null) {
|
|
6208
|
+
return result;
|
|
6020
6209
|
}
|
|
6021
6210
|
}
|
|
6022
6211
|
return null;
|
|
@@ -6062,7 +6251,7 @@ function queryOrderBy(query) {
|
|
|
6062
6251
|
if (!inequalityField.isKeyField()) {
|
|
6063
6252
|
queryImpl.memoizedOrderBy.push(new OrderBy(inequalityField));
|
|
6064
6253
|
}
|
|
6065
|
-
queryImpl.memoizedOrderBy.push(new OrderBy(FieldPath$1.keyField(), "asc" /* ASCENDING */));
|
|
6254
|
+
queryImpl.memoizedOrderBy.push(new OrderBy(FieldPath$1.keyField(), "asc" /* Direction.ASCENDING */));
|
|
6066
6255
|
}
|
|
6067
6256
|
else {
|
|
6068
6257
|
let foundKeyOrdering = false;
|
|
@@ -6078,7 +6267,7 @@ function queryOrderBy(query) {
|
|
|
6078
6267
|
const lastDirection = queryImpl.explicitOrderBy.length > 0
|
|
6079
6268
|
? queryImpl.explicitOrderBy[queryImpl.explicitOrderBy.length - 1]
|
|
6080
6269
|
.dir
|
|
6081
|
-
: "asc" /* ASCENDING */;
|
|
6270
|
+
: "asc" /* Direction.ASCENDING */;
|
|
6082
6271
|
queryImpl.memoizedOrderBy.push(new OrderBy(FieldPath$1.keyField(), lastDirection));
|
|
6083
6272
|
}
|
|
6084
6273
|
}
|
|
@@ -6091,16 +6280,16 @@ function queryOrderBy(query) {
|
|
|
6091
6280
|
function queryToTarget(query) {
|
|
6092
6281
|
const queryImpl = debugCast(query);
|
|
6093
6282
|
if (!queryImpl.memoizedTarget) {
|
|
6094
|
-
if (queryImpl.limitType === "F" /* First */) {
|
|
6283
|
+
if (queryImpl.limitType === "F" /* LimitType.First */) {
|
|
6095
6284
|
queryImpl.memoizedTarget = newTarget(queryImpl.path, queryImpl.collectionGroup, queryOrderBy(queryImpl), queryImpl.filters, queryImpl.limit, queryImpl.startAt, queryImpl.endAt);
|
|
6096
6285
|
}
|
|
6097
6286
|
else {
|
|
6098
6287
|
// Flip the orderBy directions since we want the last results
|
|
6099
6288
|
const orderBys = [];
|
|
6100
6289
|
for (const orderBy of queryOrderBy(queryImpl)) {
|
|
6101
|
-
const dir = orderBy.dir === "desc" /* DESCENDING */
|
|
6102
|
-
? "asc" /* ASCENDING */
|
|
6103
|
-
: "desc" /* DESCENDING */;
|
|
6290
|
+
const dir = orderBy.dir === "desc" /* Direction.DESCENDING */
|
|
6291
|
+
? "asc" /* Direction.ASCENDING */
|
|
6292
|
+
: "desc" /* Direction.DESCENDING */;
|
|
6104
6293
|
orderBys.push(new OrderBy(orderBy.field, dir));
|
|
6105
6294
|
}
|
|
6106
6295
|
// We need to swap the cursors to match the now-flipped query ordering.
|
|
@@ -6117,6 +6306,8 @@ function queryToTarget(query) {
|
|
|
6117
6306
|
return queryImpl.memoizedTarget;
|
|
6118
6307
|
}
|
|
6119
6308
|
function queryWithAddedFilter(query, filter) {
|
|
6309
|
+
filter.getFirstInequalityField();
|
|
6310
|
+
getInequalityFilterField(query);
|
|
6120
6311
|
const newFilters = query.filters.concat([filter]);
|
|
6121
6312
|
return new QueryImpl(query.path, query.collectionGroup, query.explicitOrderBy.slice(), newFilters, query.limit, query.limitType, query.startAt, query.endAt);
|
|
6122
6313
|
}
|
|
@@ -6177,7 +6368,13 @@ function queryMatchesPathAndCollectionGroup(query, doc) {
|
|
|
6177
6368
|
* in the results.
|
|
6178
6369
|
*/
|
|
6179
6370
|
function queryMatchesOrderBy(query, doc) {
|
|
6180
|
-
|
|
6371
|
+
// We must use `queryOrderBy()` to get the list of all orderBys (both implicit and explicit).
|
|
6372
|
+
// Note that for OR queries, orderBy applies to all disjunction terms and implicit orderBys must
|
|
6373
|
+
// be taken into account. For example, the query "a > 1 || b==1" has an implicit "orderBy a" due
|
|
6374
|
+
// to the inequality, and is evaluated as "a > 1 orderBy a || b==1 orderBy a".
|
|
6375
|
+
// A document with content of {b:1} matches the filters, but does not match the orderBy because
|
|
6376
|
+
// it's missing the field 'a'.
|
|
6377
|
+
for (const orderBy of queryOrderBy(query)) {
|
|
6181
6378
|
// order by key always matches
|
|
6182
6379
|
if (!orderBy.field.isKeyField() && doc.data.field(orderBy.field) === null) {
|
|
6183
6380
|
return false;
|
|
@@ -6239,9 +6436,9 @@ function compareDocs(orderBy, d1, d2) {
|
|
|
6239
6436
|
? DocumentKey.comparator(d1.key, d2.key)
|
|
6240
6437
|
: compareDocumentsByField(orderBy.field, d1, d2);
|
|
6241
6438
|
switch (orderBy.dir) {
|
|
6242
|
-
case "asc" /* ASCENDING */:
|
|
6439
|
+
case "asc" /* Direction.ASCENDING */:
|
|
6243
6440
|
return comparison;
|
|
6244
|
-
case "desc" /* DESCENDING */:
|
|
6441
|
+
case "desc" /* Direction.DESCENDING */:
|
|
6245
6442
|
return -1 * comparison;
|
|
6246
6443
|
default:
|
|
6247
6444
|
return fail();
|
|
@@ -6927,10 +7124,10 @@ function mutationEquals(left, right) {
|
|
|
6927
7124
|
if (!fieldTransformsAreEqual(left.fieldTransforms, right.fieldTransforms)) {
|
|
6928
7125
|
return false;
|
|
6929
7126
|
}
|
|
6930
|
-
if (left.type === 0 /* Set */) {
|
|
7127
|
+
if (left.type === 0 /* MutationType.Set */) {
|
|
6931
7128
|
return left.value.isEqual(right.value);
|
|
6932
7129
|
}
|
|
6933
|
-
if (left.type === 1 /* Patch */) {
|
|
7130
|
+
if (left.type === 1 /* MutationType.Patch */) {
|
|
6934
7131
|
return (left.data.isEqual(right.data) &&
|
|
6935
7132
|
left.fieldMask.isEqual(right.fieldMask));
|
|
6936
7133
|
}
|
|
@@ -6947,7 +7144,7 @@ class SetMutation extends Mutation {
|
|
|
6947
7144
|
this.value = value;
|
|
6948
7145
|
this.precondition = precondition;
|
|
6949
7146
|
this.fieldTransforms = fieldTransforms;
|
|
6950
|
-
this.type = 0 /* Set */;
|
|
7147
|
+
this.type = 0 /* MutationType.Set */;
|
|
6951
7148
|
}
|
|
6952
7149
|
getFieldMask() {
|
|
6953
7150
|
return null;
|
|
@@ -6999,7 +7196,7 @@ class PatchMutation extends Mutation {
|
|
|
6999
7196
|
this.fieldMask = fieldMask;
|
|
7000
7197
|
this.precondition = precondition;
|
|
7001
7198
|
this.fieldTransforms = fieldTransforms;
|
|
7002
|
-
this.type = 1 /* Patch */;
|
|
7199
|
+
this.type = 1 /* MutationType.Patch */;
|
|
7003
7200
|
}
|
|
7004
7201
|
getFieldMask() {
|
|
7005
7202
|
return this.fieldMask;
|
|
@@ -7101,7 +7298,7 @@ class DeleteMutation extends Mutation {
|
|
|
7101
7298
|
super();
|
|
7102
7299
|
this.key = key;
|
|
7103
7300
|
this.precondition = precondition;
|
|
7104
|
-
this.type = 2 /* Delete */;
|
|
7301
|
+
this.type = 2 /* MutationType.Delete */;
|
|
7105
7302
|
this.fieldTransforms = [];
|
|
7106
7303
|
}
|
|
7107
7304
|
getFieldMask() {
|
|
@@ -7135,7 +7332,7 @@ class VerifyMutation extends Mutation {
|
|
|
7135
7332
|
super();
|
|
7136
7333
|
this.key = key;
|
|
7137
7334
|
this.precondition = precondition;
|
|
7138
|
-
this.type = 3 /* Verify */;
|
|
7335
|
+
this.type = 3 /* MutationType.Verify */;
|
|
7139
7336
|
this.fieldTransforms = [];
|
|
7140
7337
|
}
|
|
7141
7338
|
getFieldMask() {
|
|
@@ -7764,13 +7961,13 @@ class TargetState {
|
|
|
7764
7961
|
let removedDocuments = documentKeySet();
|
|
7765
7962
|
this.documentChanges.forEach((key, changeType) => {
|
|
7766
7963
|
switch (changeType) {
|
|
7767
|
-
case 0 /* Added */:
|
|
7964
|
+
case 0 /* ChangeType.Added */:
|
|
7768
7965
|
addedDocuments = addedDocuments.add(key);
|
|
7769
7966
|
break;
|
|
7770
|
-
case 2 /* Modified */:
|
|
7967
|
+
case 2 /* ChangeType.Modified */:
|
|
7771
7968
|
modifiedDocuments = modifiedDocuments.add(key);
|
|
7772
7969
|
break;
|
|
7773
|
-
case 1 /* Removed */:
|
|
7970
|
+
case 1 /* ChangeType.Removed */:
|
|
7774
7971
|
removedDocuments = removedDocuments.add(key);
|
|
7775
7972
|
break;
|
|
7776
7973
|
default:
|
|
@@ -7846,12 +8043,12 @@ class WatchChangeAggregator {
|
|
|
7846
8043
|
this.forEachTarget(targetChange, targetId => {
|
|
7847
8044
|
const targetState = this.ensureTargetState(targetId);
|
|
7848
8045
|
switch (targetChange.state) {
|
|
7849
|
-
case 0 /* NoChange */:
|
|
8046
|
+
case 0 /* WatchTargetChangeState.NoChange */:
|
|
7850
8047
|
if (this.isActiveTarget(targetId)) {
|
|
7851
8048
|
targetState.updateResumeToken(targetChange.resumeToken);
|
|
7852
8049
|
}
|
|
7853
8050
|
break;
|
|
7854
|
-
case 1 /* Added */:
|
|
8051
|
+
case 1 /* WatchTargetChangeState.Added */:
|
|
7855
8052
|
// We need to decrement the number of pending acks needed from watch
|
|
7856
8053
|
// for this targetId.
|
|
7857
8054
|
targetState.recordTargetResponse();
|
|
@@ -7863,7 +8060,7 @@ class WatchChangeAggregator {
|
|
|
7863
8060
|
}
|
|
7864
8061
|
targetState.updateResumeToken(targetChange.resumeToken);
|
|
7865
8062
|
break;
|
|
7866
|
-
case 2 /* Removed */:
|
|
8063
|
+
case 2 /* WatchTargetChangeState.Removed */:
|
|
7867
8064
|
// We need to keep track of removed targets to we can post-filter and
|
|
7868
8065
|
// remove any target changes.
|
|
7869
8066
|
// We need to decrement the number of pending acks needed from watch
|
|
@@ -7873,13 +8070,13 @@ class WatchChangeAggregator {
|
|
|
7873
8070
|
this.removeTarget(targetId);
|
|
7874
8071
|
}
|
|
7875
8072
|
break;
|
|
7876
|
-
case 3 /* Current */:
|
|
8073
|
+
case 3 /* WatchTargetChangeState.Current */:
|
|
7877
8074
|
if (this.isActiveTarget(targetId)) {
|
|
7878
8075
|
targetState.markCurrent();
|
|
7879
8076
|
targetState.updateResumeToken(targetChange.resumeToken);
|
|
7880
8077
|
}
|
|
7881
8078
|
break;
|
|
7882
|
-
case 4 /* Reset */:
|
|
8079
|
+
case 4 /* WatchTargetChangeState.Reset */:
|
|
7883
8080
|
if (this.isActiveTarget(targetId)) {
|
|
7884
8081
|
// Reset the target and synthesizes removes for all existing
|
|
7885
8082
|
// documents. The backend will re-add any documents that still
|
|
@@ -7989,7 +8186,7 @@ class WatchChangeAggregator {
|
|
|
7989
8186
|
targets.forEachWhile(targetId => {
|
|
7990
8187
|
const targetData = this.targetDataForActiveTarget(targetId);
|
|
7991
8188
|
if (targetData &&
|
|
7992
|
-
targetData.purpose !== 2 /* LimboResolution */) {
|
|
8189
|
+
targetData.purpose !== 2 /* TargetPurpose.LimboResolution */) {
|
|
7993
8190
|
isOnlyLimboTarget = false;
|
|
7994
8191
|
return false;
|
|
7995
8192
|
}
|
|
@@ -8016,8 +8213,8 @@ class WatchChangeAggregator {
|
|
|
8016
8213
|
return;
|
|
8017
8214
|
}
|
|
8018
8215
|
const changeType = this.targetContainsDocument(targetId, document.key)
|
|
8019
|
-
? 2 /* Modified */
|
|
8020
|
-
: 0 /* Added */;
|
|
8216
|
+
? 2 /* ChangeType.Modified */
|
|
8217
|
+
: 0 /* ChangeType.Added */;
|
|
8021
8218
|
const targetState = this.ensureTargetState(targetId);
|
|
8022
8219
|
targetState.addDocumentChange(document.key, changeType);
|
|
8023
8220
|
this.pendingDocumentUpdates = this.pendingDocumentUpdates.insert(document.key, document);
|
|
@@ -8038,7 +8235,7 @@ class WatchChangeAggregator {
|
|
|
8038
8235
|
}
|
|
8039
8236
|
const targetState = this.ensureTargetState(targetId);
|
|
8040
8237
|
if (this.targetContainsDocument(targetId, key)) {
|
|
8041
|
-
targetState.addDocumentChange(key, 1 /* Removed */);
|
|
8238
|
+
targetState.addDocumentChange(key, 1 /* ChangeType.Removed */);
|
|
8042
8239
|
}
|
|
8043
8240
|
else {
|
|
8044
8241
|
// The document may have entered and left the target before we raised a
|
|
@@ -8163,22 +8360,28 @@ function snapshotChangesMap() {
|
|
|
8163
8360
|
*/
|
|
8164
8361
|
const DIRECTIONS = (() => {
|
|
8165
8362
|
const dirs = {};
|
|
8166
|
-
dirs["asc" /* ASCENDING */] = 'ASCENDING';
|
|
8167
|
-
dirs["desc" /* DESCENDING */] = 'DESCENDING';
|
|
8363
|
+
dirs["asc" /* Direction.ASCENDING */] = 'ASCENDING';
|
|
8364
|
+
dirs["desc" /* Direction.DESCENDING */] = 'DESCENDING';
|
|
8168
8365
|
return dirs;
|
|
8169
8366
|
})();
|
|
8170
8367
|
const OPERATORS = (() => {
|
|
8171
8368
|
const ops = {};
|
|
8172
|
-
ops["<" /* LESS_THAN */] = 'LESS_THAN';
|
|
8173
|
-
ops["<=" /* LESS_THAN_OR_EQUAL */] = 'LESS_THAN_OR_EQUAL';
|
|
8174
|
-
ops[">" /* GREATER_THAN */] = 'GREATER_THAN';
|
|
8175
|
-
ops[">=" /* GREATER_THAN_OR_EQUAL */] = 'GREATER_THAN_OR_EQUAL';
|
|
8176
|
-
ops["==" /* EQUAL */] = 'EQUAL';
|
|
8177
|
-
ops["!=" /* NOT_EQUAL */] = 'NOT_EQUAL';
|
|
8178
|
-
ops["array-contains" /* ARRAY_CONTAINS */] = 'ARRAY_CONTAINS';
|
|
8179
|
-
ops["in" /* IN */] = 'IN';
|
|
8180
|
-
ops["not-in" /* NOT_IN */] = 'NOT_IN';
|
|
8181
|
-
ops["array-contains-any" /* ARRAY_CONTAINS_ANY */] = 'ARRAY_CONTAINS_ANY';
|
|
8369
|
+
ops["<" /* Operator.LESS_THAN */] = 'LESS_THAN';
|
|
8370
|
+
ops["<=" /* Operator.LESS_THAN_OR_EQUAL */] = 'LESS_THAN_OR_EQUAL';
|
|
8371
|
+
ops[">" /* Operator.GREATER_THAN */] = 'GREATER_THAN';
|
|
8372
|
+
ops[">=" /* Operator.GREATER_THAN_OR_EQUAL */] = 'GREATER_THAN_OR_EQUAL';
|
|
8373
|
+
ops["==" /* Operator.EQUAL */] = 'EQUAL';
|
|
8374
|
+
ops["!=" /* Operator.NOT_EQUAL */] = 'NOT_EQUAL';
|
|
8375
|
+
ops["array-contains" /* Operator.ARRAY_CONTAINS */] = 'ARRAY_CONTAINS';
|
|
8376
|
+
ops["in" /* Operator.IN */] = 'IN';
|
|
8377
|
+
ops["not-in" /* Operator.NOT_IN */] = 'NOT_IN';
|
|
8378
|
+
ops["array-contains-any" /* Operator.ARRAY_CONTAINS_ANY */] = 'ARRAY_CONTAINS_ANY';
|
|
8379
|
+
return ops;
|
|
8380
|
+
})();
|
|
8381
|
+
const COMPOSITE_OPERATORS = (() => {
|
|
8382
|
+
const ops = {};
|
|
8383
|
+
ops["and" /* CompositeOperator.AND */] = 'AND';
|
|
8384
|
+
ops["or" /* CompositeOperator.OR */] = 'OR';
|
|
8182
8385
|
return ops;
|
|
8183
8386
|
})();
|
|
8184
8387
|
function assertPresent(value, description) {
|
|
@@ -8476,19 +8679,19 @@ function fromWatchChange(serializer, change) {
|
|
|
8476
8679
|
}
|
|
8477
8680
|
function fromWatchTargetChangeState(state) {
|
|
8478
8681
|
if (state === 'NO_CHANGE') {
|
|
8479
|
-
return 0 /* NoChange */;
|
|
8682
|
+
return 0 /* WatchTargetChangeState.NoChange */;
|
|
8480
8683
|
}
|
|
8481
8684
|
else if (state === 'ADD') {
|
|
8482
|
-
return 1 /* Added */;
|
|
8685
|
+
return 1 /* WatchTargetChangeState.Added */;
|
|
8483
8686
|
}
|
|
8484
8687
|
else if (state === 'REMOVE') {
|
|
8485
|
-
return 2 /* Removed */;
|
|
8688
|
+
return 2 /* WatchTargetChangeState.Removed */;
|
|
8486
8689
|
}
|
|
8487
8690
|
else if (state === 'CURRENT') {
|
|
8488
|
-
return 3 /* Current */;
|
|
8691
|
+
return 3 /* WatchTargetChangeState.Current */;
|
|
8489
8692
|
}
|
|
8490
8693
|
else if (state === 'RESET') {
|
|
8491
|
-
return 4 /* Reset */;
|
|
8694
|
+
return 4 /* WatchTargetChangeState.Reset */;
|
|
8492
8695
|
}
|
|
8493
8696
|
else {
|
|
8494
8697
|
return fail();
|
|
@@ -8706,7 +8909,7 @@ function toQueryTarget(serializer, target) {
|
|
|
8706
8909
|
result.parent = toQueryPath(serializer, path.popLast());
|
|
8707
8910
|
result.structuredQuery.from = [{ collectionId: path.lastSegment() }];
|
|
8708
8911
|
}
|
|
8709
|
-
const where =
|
|
8912
|
+
const where = toFilters(target.filters);
|
|
8710
8913
|
if (where) {
|
|
8711
8914
|
result.structuredQuery.where = where;
|
|
8712
8915
|
}
|
|
@@ -8758,7 +8961,7 @@ function convertQueryTargetToQuery(target) {
|
|
|
8758
8961
|
}
|
|
8759
8962
|
let filterBy = [];
|
|
8760
8963
|
if (query.where) {
|
|
8761
|
-
filterBy =
|
|
8964
|
+
filterBy = fromFilters(query.where);
|
|
8762
8965
|
}
|
|
8763
8966
|
let orderBy = [];
|
|
8764
8967
|
if (query.orderBy) {
|
|
@@ -8776,7 +8979,7 @@ function convertQueryTargetToQuery(target) {
|
|
|
8776
8979
|
if (query.endAt) {
|
|
8777
8980
|
endAt = fromEndAtCursor(query.endAt);
|
|
8778
8981
|
}
|
|
8779
|
-
return newQuery(path, collectionGroup, orderBy, filterBy, limit, "F" /* First */, startAt, endAt);
|
|
8982
|
+
return newQuery(path, collectionGroup, orderBy, filterBy, limit, "F" /* LimitType.First */, startAt, endAt);
|
|
8780
8983
|
}
|
|
8781
8984
|
function fromQueryTarget(target) {
|
|
8782
8985
|
return queryToTarget(convertQueryTargetToQuery(target));
|
|
@@ -8794,11 +8997,11 @@ function toListenRequestLabels(serializer, targetData) {
|
|
|
8794
8997
|
}
|
|
8795
8998
|
function toLabel(serializer, purpose) {
|
|
8796
8999
|
switch (purpose) {
|
|
8797
|
-
case 0 /* Listen */:
|
|
9000
|
+
case 0 /* TargetPurpose.Listen */:
|
|
8798
9001
|
return null;
|
|
8799
|
-
case 1 /* ExistenceFilterMismatch */:
|
|
9002
|
+
case 1 /* TargetPurpose.ExistenceFilterMismatch */:
|
|
8800
9003
|
return 'existence-filter-mismatch';
|
|
8801
|
-
case 2 /* LimboResolution */:
|
|
9004
|
+
case 2 /* TargetPurpose.LimboResolution */:
|
|
8802
9005
|
return 'limbo-document';
|
|
8803
9006
|
default:
|
|
8804
9007
|
return fail();
|
|
@@ -8825,32 +9028,29 @@ function toTarget(serializer, targetData) {
|
|
|
8825
9028
|
}
|
|
8826
9029
|
return result;
|
|
8827
9030
|
}
|
|
8828
|
-
function
|
|
9031
|
+
function toFilters(filters) {
|
|
8829
9032
|
if (filters.length === 0) {
|
|
8830
9033
|
return;
|
|
8831
9034
|
}
|
|
8832
|
-
|
|
8833
|
-
|
|
8834
|
-
|
|
8835
|
-
|
|
8836
|
-
|
|
9035
|
+
return toFilter(CompositeFilter.create(filters, "and" /* CompositeOperator.AND */));
|
|
9036
|
+
}
|
|
9037
|
+
function fromFilters(filter) {
|
|
9038
|
+
const result = fromFilter(filter);
|
|
9039
|
+
if (result instanceof CompositeFilter &&
|
|
9040
|
+
compositeFilterIsFlatConjunction(result)) {
|
|
9041
|
+
return result.getFilters();
|
|
8837
9042
|
}
|
|
8838
|
-
return
|
|
9043
|
+
return [result];
|
|
8839
9044
|
}
|
|
8840
9045
|
function fromFilter(filter) {
|
|
8841
|
-
if (
|
|
8842
|
-
return
|
|
8843
|
-
}
|
|
8844
|
-
else if (filter.unaryFilter !== undefined) {
|
|
8845
|
-
return [fromUnaryFilter(filter)];
|
|
9046
|
+
if (filter.unaryFilter !== undefined) {
|
|
9047
|
+
return fromUnaryFilter(filter);
|
|
8846
9048
|
}
|
|
8847
9049
|
else if (filter.fieldFilter !== undefined) {
|
|
8848
|
-
return
|
|
9050
|
+
return fromFieldFilter(filter);
|
|
8849
9051
|
}
|
|
8850
9052
|
else if (filter.compositeFilter !== undefined) {
|
|
8851
|
-
return filter
|
|
8852
|
-
.filters.map(f => fromFilter(f))
|
|
8853
|
-
.reduce((accum, current) => accum.concat(current));
|
|
9053
|
+
return fromCompositeFilter(filter);
|
|
8854
9054
|
}
|
|
8855
9055
|
else {
|
|
8856
9056
|
return fail();
|
|
@@ -8895,9 +9095,9 @@ function toDirection(dir) {
|
|
|
8895
9095
|
function fromDirection(dir) {
|
|
8896
9096
|
switch (dir) {
|
|
8897
9097
|
case 'ASCENDING':
|
|
8898
|
-
return "asc" /* ASCENDING */;
|
|
9098
|
+
return "asc" /* Direction.ASCENDING */;
|
|
8899
9099
|
case 'DESCENDING':
|
|
8900
|
-
return "desc" /* DESCENDING */;
|
|
9100
|
+
return "desc" /* Direction.DESCENDING */;
|
|
8901
9101
|
default:
|
|
8902
9102
|
return undefined;
|
|
8903
9103
|
}
|
|
@@ -8906,34 +9106,47 @@ function fromDirection(dir) {
|
|
|
8906
9106
|
function toOperatorName(op) {
|
|
8907
9107
|
return OPERATORS[op];
|
|
8908
9108
|
}
|
|
9109
|
+
function toCompositeOperatorName(op) {
|
|
9110
|
+
return COMPOSITE_OPERATORS[op];
|
|
9111
|
+
}
|
|
8909
9112
|
function fromOperatorName(op) {
|
|
8910
9113
|
switch (op) {
|
|
8911
9114
|
case 'EQUAL':
|
|
8912
|
-
return "==" /* EQUAL */;
|
|
9115
|
+
return "==" /* Operator.EQUAL */;
|
|
8913
9116
|
case 'NOT_EQUAL':
|
|
8914
|
-
return "!=" /* NOT_EQUAL */;
|
|
9117
|
+
return "!=" /* Operator.NOT_EQUAL */;
|
|
8915
9118
|
case 'GREATER_THAN':
|
|
8916
|
-
return ">" /* GREATER_THAN */;
|
|
9119
|
+
return ">" /* Operator.GREATER_THAN */;
|
|
8917
9120
|
case 'GREATER_THAN_OR_EQUAL':
|
|
8918
|
-
return ">=" /* GREATER_THAN_OR_EQUAL */;
|
|
9121
|
+
return ">=" /* Operator.GREATER_THAN_OR_EQUAL */;
|
|
8919
9122
|
case 'LESS_THAN':
|
|
8920
|
-
return "<" /* LESS_THAN */;
|
|
9123
|
+
return "<" /* Operator.LESS_THAN */;
|
|
8921
9124
|
case 'LESS_THAN_OR_EQUAL':
|
|
8922
|
-
return "<=" /* LESS_THAN_OR_EQUAL */;
|
|
9125
|
+
return "<=" /* Operator.LESS_THAN_OR_EQUAL */;
|
|
8923
9126
|
case 'ARRAY_CONTAINS':
|
|
8924
|
-
return "array-contains" /* ARRAY_CONTAINS */;
|
|
9127
|
+
return "array-contains" /* Operator.ARRAY_CONTAINS */;
|
|
8925
9128
|
case 'IN':
|
|
8926
|
-
return "in" /* IN */;
|
|
9129
|
+
return "in" /* Operator.IN */;
|
|
8927
9130
|
case 'NOT_IN':
|
|
8928
|
-
return "not-in" /* NOT_IN */;
|
|
9131
|
+
return "not-in" /* Operator.NOT_IN */;
|
|
8929
9132
|
case 'ARRAY_CONTAINS_ANY':
|
|
8930
|
-
return "array-contains-any" /* ARRAY_CONTAINS_ANY */;
|
|
9133
|
+
return "array-contains-any" /* Operator.ARRAY_CONTAINS_ANY */;
|
|
8931
9134
|
case 'OPERATOR_UNSPECIFIED':
|
|
8932
9135
|
return fail();
|
|
8933
9136
|
default:
|
|
8934
9137
|
return fail();
|
|
8935
9138
|
}
|
|
8936
9139
|
}
|
|
9140
|
+
function fromCompositeOperatorName(op) {
|
|
9141
|
+
switch (op) {
|
|
9142
|
+
case 'AND':
|
|
9143
|
+
return "and" /* CompositeOperator.AND */;
|
|
9144
|
+
case 'OR':
|
|
9145
|
+
return "or" /* CompositeOperator.OR */;
|
|
9146
|
+
default:
|
|
9147
|
+
return fail();
|
|
9148
|
+
}
|
|
9149
|
+
}
|
|
8937
9150
|
function toFieldPathReference(path) {
|
|
8938
9151
|
return { fieldPath: path.canonicalString() };
|
|
8939
9152
|
}
|
|
@@ -8950,12 +9163,32 @@ function toPropertyOrder(orderBy) {
|
|
|
8950
9163
|
function fromPropertyOrder(orderBy) {
|
|
8951
9164
|
return new OrderBy(fromFieldPathReference(orderBy.field), fromDirection(orderBy.direction));
|
|
8952
9165
|
}
|
|
8953
|
-
function fromFieldFilter(filter) {
|
|
8954
|
-
return FieldFilter.create(fromFieldPathReference(filter.fieldFilter.field), fromOperatorName(filter.fieldFilter.op), filter.fieldFilter.value);
|
|
8955
|
-
}
|
|
8956
9166
|
// visible for testing
|
|
9167
|
+
function toFilter(filter) {
|
|
9168
|
+
if (filter instanceof FieldFilter) {
|
|
9169
|
+
return toUnaryOrFieldFilter(filter);
|
|
9170
|
+
}
|
|
9171
|
+
else if (filter instanceof CompositeFilter) {
|
|
9172
|
+
return toCompositeFilter(filter);
|
|
9173
|
+
}
|
|
9174
|
+
else {
|
|
9175
|
+
return fail();
|
|
9176
|
+
}
|
|
9177
|
+
}
|
|
9178
|
+
function toCompositeFilter(filter) {
|
|
9179
|
+
const protos = filter.getFilters().map(filter => toFilter(filter));
|
|
9180
|
+
if (protos.length === 1) {
|
|
9181
|
+
return protos[0];
|
|
9182
|
+
}
|
|
9183
|
+
return {
|
|
9184
|
+
compositeFilter: {
|
|
9185
|
+
op: toCompositeOperatorName(filter.op),
|
|
9186
|
+
filters: protos
|
|
9187
|
+
}
|
|
9188
|
+
};
|
|
9189
|
+
}
|
|
8957
9190
|
function toUnaryOrFieldFilter(filter) {
|
|
8958
|
-
if (filter.op === "==" /* EQUAL */) {
|
|
9191
|
+
if (filter.op === "==" /* Operator.EQUAL */) {
|
|
8959
9192
|
if (isNanValue(filter.value)) {
|
|
8960
9193
|
return {
|
|
8961
9194
|
unaryFilter: {
|
|
@@ -8973,7 +9206,7 @@ function toUnaryOrFieldFilter(filter) {
|
|
|
8973
9206
|
};
|
|
8974
9207
|
}
|
|
8975
9208
|
}
|
|
8976
|
-
else if (filter.op === "!=" /* NOT_EQUAL */) {
|
|
9209
|
+
else if (filter.op === "!=" /* Operator.NOT_EQUAL */) {
|
|
8977
9210
|
if (isNanValue(filter.value)) {
|
|
8978
9211
|
return {
|
|
8979
9212
|
unaryFilter: {
|
|
@@ -9003,22 +9236,22 @@ function fromUnaryFilter(filter) {
|
|
|
9003
9236
|
switch (filter.unaryFilter.op) {
|
|
9004
9237
|
case 'IS_NAN':
|
|
9005
9238
|
const nanField = fromFieldPathReference(filter.unaryFilter.field);
|
|
9006
|
-
return FieldFilter.create(nanField, "==" /* EQUAL */, {
|
|
9239
|
+
return FieldFilter.create(nanField, "==" /* Operator.EQUAL */, {
|
|
9007
9240
|
doubleValue: NaN
|
|
9008
9241
|
});
|
|
9009
9242
|
case 'IS_NULL':
|
|
9010
9243
|
const nullField = fromFieldPathReference(filter.unaryFilter.field);
|
|
9011
|
-
return FieldFilter.create(nullField, "==" /* EQUAL */, {
|
|
9244
|
+
return FieldFilter.create(nullField, "==" /* Operator.EQUAL */, {
|
|
9012
9245
|
nullValue: 'NULL_VALUE'
|
|
9013
9246
|
});
|
|
9014
9247
|
case 'IS_NOT_NAN':
|
|
9015
9248
|
const notNanField = fromFieldPathReference(filter.unaryFilter.field);
|
|
9016
|
-
return FieldFilter.create(notNanField, "!=" /* NOT_EQUAL */, {
|
|
9249
|
+
return FieldFilter.create(notNanField, "!=" /* Operator.NOT_EQUAL */, {
|
|
9017
9250
|
doubleValue: NaN
|
|
9018
9251
|
});
|
|
9019
9252
|
case 'IS_NOT_NULL':
|
|
9020
9253
|
const notNullField = fromFieldPathReference(filter.unaryFilter.field);
|
|
9021
|
-
return FieldFilter.create(notNullField, "!=" /* NOT_EQUAL */, {
|
|
9254
|
+
return FieldFilter.create(notNullField, "!=" /* Operator.NOT_EQUAL */, {
|
|
9022
9255
|
nullValue: 'NULL_VALUE'
|
|
9023
9256
|
});
|
|
9024
9257
|
case 'OPERATOR_UNSPECIFIED':
|
|
@@ -9027,6 +9260,12 @@ function fromUnaryFilter(filter) {
|
|
|
9027
9260
|
return fail();
|
|
9028
9261
|
}
|
|
9029
9262
|
}
|
|
9263
|
+
function fromFieldFilter(filter) {
|
|
9264
|
+
return FieldFilter.create(fromFieldPathReference(filter.fieldFilter.field), fromOperatorName(filter.fieldFilter.op), filter.fieldFilter.value);
|
|
9265
|
+
}
|
|
9266
|
+
function fromCompositeFilter(filter) {
|
|
9267
|
+
return CompositeFilter.create(filter.compositeFilter.filters.map(filter => fromFilter(filter)), fromCompositeOperatorName(filter.compositeFilter.op));
|
|
9268
|
+
}
|
|
9030
9269
|
function toDocumentMask(fieldMask) {
|
|
9031
9270
|
const canonicalFields = [];
|
|
9032
9271
|
fieldMask.fields.forEach(field => canonicalFields.push(field.canonicalString()));
|
|
@@ -9266,7 +9505,7 @@ function fromDbTarget(dbTarget) {
|
|
|
9266
9505
|
else {
|
|
9267
9506
|
target = fromQueryTarget(dbTarget.query);
|
|
9268
9507
|
}
|
|
9269
|
-
return new TargetData(target, dbTarget.targetId, 0 /* Listen */, dbTarget.lastListenSequenceNumber, version, lastLimboFreeSnapshotVersion, ByteString.fromBase64String(dbTarget.resumeToken));
|
|
9508
|
+
return new TargetData(target, dbTarget.targetId, 0 /* TargetPurpose.Listen */, dbTarget.lastListenSequenceNumber, version, lastLimboFreeSnapshotVersion, ByteString.fromBase64String(dbTarget.resumeToken));
|
|
9270
9509
|
}
|
|
9271
9510
|
/** Encodes TargetData into a DbTarget for storage locally. */
|
|
9272
9511
|
function toDbTarget(localSerializer, targetData) {
|
|
@@ -9343,7 +9582,7 @@ function fromBundledQuery(bundledQuery) {
|
|
|
9343
9582
|
structuredQuery: bundledQuery.structuredQuery
|
|
9344
9583
|
});
|
|
9345
9584
|
if (bundledQuery.limitType === 'LAST') {
|
|
9346
|
-
return queryWithLimit(query, query.limit, "L" /* Last */);
|
|
9585
|
+
return queryWithLimit(query, query.limit, "L" /* LimitType.Last */);
|
|
9347
9586
|
}
|
|
9348
9587
|
return query;
|
|
9349
9588
|
}
|
|
@@ -10118,7 +10357,7 @@ class IndexByteEncoder {
|
|
|
10118
10357
|
this.orderedCode.seed(encodedBytes);
|
|
10119
10358
|
}
|
|
10120
10359
|
forKind(kind) {
|
|
10121
|
-
return kind === 0 /* ASCENDING */ ? this.ascending : this.descending;
|
|
10360
|
+
return kind === 0 /* IndexKind.ASCENDING */ ? this.ascending : this.descending;
|
|
10122
10361
|
}
|
|
10123
10362
|
encodedBytes() {
|
|
10124
10363
|
return this.orderedCode.encodedBytes();
|
|
@@ -10273,6 +10512,7 @@ class TargetIndexMatcher {
|
|
|
10273
10512
|
* omitted.
|
|
10274
10513
|
*/
|
|
10275
10514
|
servedByIndex(index) {
|
|
10515
|
+
hardAssert(index.collectionGroup === this.collectionId);
|
|
10276
10516
|
// If there is an array element, find a matching filter.
|
|
10277
10517
|
const arraySegment = fieldIndexGetArraySegment(index);
|
|
10278
10518
|
if (arraySegment !== undefined &&
|
|
@@ -10336,19 +10576,268 @@ class TargetIndexMatcher {
|
|
|
10336
10576
|
if (filter === undefined || !filter.field.isEqual(segment.fieldPath)) {
|
|
10337
10577
|
return false;
|
|
10338
10578
|
}
|
|
10339
|
-
const isArrayOperator = filter.op === "array-contains" /* ARRAY_CONTAINS */ ||
|
|
10340
|
-
filter.op === "array-contains-any" /* ARRAY_CONTAINS_ANY */;
|
|
10341
|
-
return (segment.kind === 2 /* CONTAINS */) === isArrayOperator;
|
|
10579
|
+
const isArrayOperator = filter.op === "array-contains" /* Operator.ARRAY_CONTAINS */ ||
|
|
10580
|
+
filter.op === "array-contains-any" /* Operator.ARRAY_CONTAINS_ANY */;
|
|
10581
|
+
return (segment.kind === 2 /* IndexKind.CONTAINS */) === isArrayOperator;
|
|
10342
10582
|
}
|
|
10343
10583
|
matchesOrderBy(orderBy, segment) {
|
|
10344
10584
|
if (!orderBy.field.isEqual(segment.fieldPath)) {
|
|
10345
10585
|
return false;
|
|
10346
10586
|
}
|
|
10347
|
-
return ((segment.kind === 0 /* ASCENDING */ &&
|
|
10348
|
-
orderBy.dir === "asc" /* ASCENDING */) ||
|
|
10349
|
-
(segment.kind === 1 /* DESCENDING */ &&
|
|
10350
|
-
orderBy.dir === "desc" /* DESCENDING */));
|
|
10587
|
+
return ((segment.kind === 0 /* IndexKind.ASCENDING */ &&
|
|
10588
|
+
orderBy.dir === "asc" /* Direction.ASCENDING */) ||
|
|
10589
|
+
(segment.kind === 1 /* IndexKind.DESCENDING */ &&
|
|
10590
|
+
orderBy.dir === "desc" /* Direction.DESCENDING */));
|
|
10591
|
+
}
|
|
10592
|
+
}
|
|
10593
|
+
|
|
10594
|
+
/**
|
|
10595
|
+
* @license
|
|
10596
|
+
* Copyright 2022 Google LLC
|
|
10597
|
+
*
|
|
10598
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
10599
|
+
* you may not use this file except in compliance with the License.
|
|
10600
|
+
* You may obtain a copy of the License at
|
|
10601
|
+
*
|
|
10602
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10603
|
+
*
|
|
10604
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
10605
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
10606
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
10607
|
+
* See the License for the specific language governing permissions and
|
|
10608
|
+
* limitations under the License.
|
|
10609
|
+
*/
|
|
10610
|
+
/**
|
|
10611
|
+
* Provides utility functions that help with boolean logic transformations needed for handling
|
|
10612
|
+
* complex filters used in queries.
|
|
10613
|
+
*/
|
|
10614
|
+
/**
|
|
10615
|
+
* The `in` filter is only a syntactic sugar over a disjunction of equalities. For instance: `a in
|
|
10616
|
+
* [1,2,3]` is in fact `a==1 || a==2 || a==3`. This method expands any `in` filter in the given
|
|
10617
|
+
* input into a disjunction of equality filters and returns the expanded filter.
|
|
10618
|
+
*/
|
|
10619
|
+
function computeInExpansion(filter) {
|
|
10620
|
+
var _a, _b;
|
|
10621
|
+
hardAssert(filter instanceof FieldFilter || filter instanceof CompositeFilter);
|
|
10622
|
+
if (filter instanceof FieldFilter) {
|
|
10623
|
+
if (filter instanceof InFilter) {
|
|
10624
|
+
const expandedFilters = ((_b = (_a = filter.value.arrayValue) === null || _a === void 0 ? void 0 : _a.values) === null || _b === void 0 ? void 0 : _b.map(value => FieldFilter.create(filter.field, "==" /* Operator.EQUAL */, value))) || [];
|
|
10625
|
+
return CompositeFilter.create(expandedFilters, "or" /* CompositeOperator.OR */);
|
|
10626
|
+
}
|
|
10627
|
+
else {
|
|
10628
|
+
// We have reached other kinds of field filters.
|
|
10629
|
+
return filter;
|
|
10630
|
+
}
|
|
10631
|
+
}
|
|
10632
|
+
// We have a composite filter.
|
|
10633
|
+
const expandedFilters = filter.filters.map(subfilter => computeInExpansion(subfilter));
|
|
10634
|
+
return CompositeFilter.create(expandedFilters, filter.op);
|
|
10635
|
+
}
|
|
10636
|
+
/**
|
|
10637
|
+
* Given a composite filter, returns the list of terms in its disjunctive normal form.
|
|
10638
|
+
*
|
|
10639
|
+
* <p>Each element in the return value is one term of the resulting DNF. For instance: For the
|
|
10640
|
+
* input: (A || B) && C, the DNF form is: (A && C) || (B && C), and the return value is a list
|
|
10641
|
+
* with two elements: a composite filter that performs (A && C), and a composite filter that
|
|
10642
|
+
* performs (B && C).
|
|
10643
|
+
*
|
|
10644
|
+
* @param filter the composite filter to calculate DNF transform for.
|
|
10645
|
+
* @return the terms in the DNF transform.
|
|
10646
|
+
*/
|
|
10647
|
+
function getDnfTerms(filter) {
|
|
10648
|
+
if (filter.getFilters().length === 0) {
|
|
10649
|
+
return [];
|
|
10650
|
+
}
|
|
10651
|
+
const result = computeDistributedNormalForm(computeInExpansion(filter));
|
|
10652
|
+
hardAssert(isDisjunctiveNormalForm(result));
|
|
10653
|
+
if (isSingleFieldFilter(result) || isFlatConjunction(result)) {
|
|
10654
|
+
return [result];
|
|
10655
|
+
}
|
|
10656
|
+
return result.getFilters();
|
|
10657
|
+
}
|
|
10658
|
+
/** Returns true if the given filter is a single field filter. e.g. (a == 10). */
|
|
10659
|
+
function isSingleFieldFilter(filter) {
|
|
10660
|
+
return filter instanceof FieldFilter;
|
|
10661
|
+
}
|
|
10662
|
+
/**
|
|
10663
|
+
* Returns true if the given filter is the conjunction of one or more field filters. e.g. (a == 10
|
|
10664
|
+
* && b == 20)
|
|
10665
|
+
*/
|
|
10666
|
+
function isFlatConjunction(filter) {
|
|
10667
|
+
return (filter instanceof CompositeFilter &&
|
|
10668
|
+
compositeFilterIsFlatConjunction(filter));
|
|
10669
|
+
}
|
|
10670
|
+
/**
|
|
10671
|
+
* Returns whether or not the given filter is in disjunctive normal form (DNF).
|
|
10672
|
+
*
|
|
10673
|
+
* <p>In boolean logic, a disjunctive normal form (DNF) is a canonical normal form of a logical
|
|
10674
|
+
* formula consisting of a disjunction of conjunctions; it can also be described as an OR of ANDs.
|
|
10675
|
+
*
|
|
10676
|
+
* <p>For more info, visit: https://en.wikipedia.org/wiki/Disjunctive_normal_form
|
|
10677
|
+
*/
|
|
10678
|
+
function isDisjunctiveNormalForm(filter) {
|
|
10679
|
+
return (isSingleFieldFilter(filter) ||
|
|
10680
|
+
isFlatConjunction(filter) ||
|
|
10681
|
+
isDisjunctionOfFieldFiltersAndFlatConjunctions(filter));
|
|
10682
|
+
}
|
|
10683
|
+
/**
|
|
10684
|
+
* Returns true if the given filter is the disjunction of one or more "flat conjunctions" and
|
|
10685
|
+
* field filters. e.g. (a == 10) || (b==20 && c==30)
|
|
10686
|
+
*/
|
|
10687
|
+
function isDisjunctionOfFieldFiltersAndFlatConjunctions(filter) {
|
|
10688
|
+
if (filter instanceof CompositeFilter) {
|
|
10689
|
+
if (compositeFilterIsDisjunction(filter)) {
|
|
10690
|
+
for (const subFilter of filter.getFilters()) {
|
|
10691
|
+
if (!isSingleFieldFilter(subFilter) && !isFlatConjunction(subFilter)) {
|
|
10692
|
+
return false;
|
|
10693
|
+
}
|
|
10694
|
+
}
|
|
10695
|
+
return true;
|
|
10696
|
+
}
|
|
10697
|
+
}
|
|
10698
|
+
return false;
|
|
10699
|
+
}
|
|
10700
|
+
function computeDistributedNormalForm(filter) {
|
|
10701
|
+
hardAssert(filter instanceof FieldFilter || filter instanceof CompositeFilter);
|
|
10702
|
+
if (filter instanceof FieldFilter) {
|
|
10703
|
+
return filter;
|
|
10704
|
+
}
|
|
10705
|
+
if (filter.filters.length === 1) {
|
|
10706
|
+
return computeDistributedNormalForm(filter.filters[0]);
|
|
10707
|
+
}
|
|
10708
|
+
// Compute DNF for each of the subfilters first
|
|
10709
|
+
const result = filter.filters.map(subfilter => computeDistributedNormalForm(subfilter));
|
|
10710
|
+
let newFilter = CompositeFilter.create(result, filter.op);
|
|
10711
|
+
newFilter = applyAssociation(newFilter);
|
|
10712
|
+
if (isDisjunctiveNormalForm(newFilter)) {
|
|
10713
|
+
return newFilter;
|
|
10714
|
+
}
|
|
10715
|
+
hardAssert(newFilter instanceof CompositeFilter);
|
|
10716
|
+
hardAssert(compositeFilterIsConjunction(newFilter));
|
|
10717
|
+
hardAssert(newFilter.filters.length > 1);
|
|
10718
|
+
return newFilter.filters.reduce((runningResult, filter) => applyDistribution(runningResult, filter));
|
|
10719
|
+
}
|
|
10720
|
+
function applyDistribution(lhs, rhs) {
|
|
10721
|
+
hardAssert(lhs instanceof FieldFilter || lhs instanceof CompositeFilter);
|
|
10722
|
+
hardAssert(rhs instanceof FieldFilter || rhs instanceof CompositeFilter);
|
|
10723
|
+
let result;
|
|
10724
|
+
if (lhs instanceof FieldFilter) {
|
|
10725
|
+
if (rhs instanceof FieldFilter) {
|
|
10726
|
+
// FieldFilter FieldFilter
|
|
10727
|
+
result = applyDistributionFieldFilters(lhs, rhs);
|
|
10728
|
+
}
|
|
10729
|
+
else {
|
|
10730
|
+
// FieldFilter CompositeFilter
|
|
10731
|
+
result = applyDistributionFieldAndCompositeFilters(lhs, rhs);
|
|
10732
|
+
}
|
|
10733
|
+
}
|
|
10734
|
+
else {
|
|
10735
|
+
if (rhs instanceof FieldFilter) {
|
|
10736
|
+
// CompositeFilter FieldFilter
|
|
10737
|
+
result = applyDistributionFieldAndCompositeFilters(rhs, lhs);
|
|
10738
|
+
}
|
|
10739
|
+
else {
|
|
10740
|
+
// CompositeFilter CompositeFilter
|
|
10741
|
+
result = applyDistributionCompositeFilters(lhs, rhs);
|
|
10742
|
+
}
|
|
10743
|
+
}
|
|
10744
|
+
return applyAssociation(result);
|
|
10745
|
+
}
|
|
10746
|
+
function applyDistributionFieldFilters(lhs, rhs) {
|
|
10747
|
+
// Conjunction distribution for two field filters is the conjunction of them.
|
|
10748
|
+
return CompositeFilter.create([lhs, rhs], "and" /* CompositeOperator.AND */);
|
|
10749
|
+
}
|
|
10750
|
+
function applyDistributionCompositeFilters(lhs, rhs) {
|
|
10751
|
+
hardAssert(lhs.filters.length > 0 && rhs.filters.length > 0);
|
|
10752
|
+
// There are four cases:
|
|
10753
|
+
// (A & B) & (C & D) --> (A & B & C & D)
|
|
10754
|
+
// (A & B) & (C | D) --> (A & B & C) | (A & B & D)
|
|
10755
|
+
// (A | B) & (C & D) --> (C & D & A) | (C & D & B)
|
|
10756
|
+
// (A | B) & (C | D) --> (A & C) | (A & D) | (B & C) | (B & D)
|
|
10757
|
+
// Case 1 is a merge.
|
|
10758
|
+
if (compositeFilterIsConjunction(lhs) && compositeFilterIsConjunction(rhs)) {
|
|
10759
|
+
return compositeFilterWithAddedFilters(lhs, rhs.getFilters());
|
|
10760
|
+
}
|
|
10761
|
+
// Case 2,3,4 all have at least one side (lhs or rhs) that is a disjunction. In all three cases
|
|
10762
|
+
// we should take each element of the disjunction and distribute it over the other side, and
|
|
10763
|
+
// return the disjunction of the distribution results.
|
|
10764
|
+
const disjunctionSide = compositeFilterIsDisjunction(lhs) ? lhs : rhs;
|
|
10765
|
+
const otherSide = compositeFilterIsDisjunction(lhs) ? rhs : lhs;
|
|
10766
|
+
const results = disjunctionSide.filters.map(subfilter => applyDistribution(subfilter, otherSide));
|
|
10767
|
+
return CompositeFilter.create(results, "or" /* CompositeOperator.OR */);
|
|
10768
|
+
}
|
|
10769
|
+
function applyDistributionFieldAndCompositeFilters(fieldFilter, compositeFilter) {
|
|
10770
|
+
// There are two cases:
|
|
10771
|
+
// A & (B & C) --> (A & B & C)
|
|
10772
|
+
// A & (B | C) --> (A & B) | (A & C)
|
|
10773
|
+
if (compositeFilterIsConjunction(compositeFilter)) {
|
|
10774
|
+
// Case 1
|
|
10775
|
+
return compositeFilterWithAddedFilters(compositeFilter, fieldFilter.getFilters());
|
|
10776
|
+
}
|
|
10777
|
+
else {
|
|
10778
|
+
// Case 2
|
|
10779
|
+
const newFilters = compositeFilter.filters.map(subfilter => applyDistribution(fieldFilter, subfilter));
|
|
10780
|
+
return CompositeFilter.create(newFilters, "or" /* CompositeOperator.OR */);
|
|
10781
|
+
}
|
|
10782
|
+
}
|
|
10783
|
+
/**
|
|
10784
|
+
* Applies the associativity property to the given filter and returns the resulting filter.
|
|
10785
|
+
*
|
|
10786
|
+
* <ul>
|
|
10787
|
+
* <li>A | (B | C) == (A | B) | C == (A | B | C)
|
|
10788
|
+
* <li>A & (B & C) == (A & B) & C == (A & B & C)
|
|
10789
|
+
* </ul>
|
|
10790
|
+
*
|
|
10791
|
+
* <p>For more info, visit: https://en.wikipedia.org/wiki/Associative_property#Propositional_logic
|
|
10792
|
+
*/
|
|
10793
|
+
function applyAssociation(filter) {
|
|
10794
|
+
hardAssert(filter instanceof FieldFilter || filter instanceof CompositeFilter);
|
|
10795
|
+
if (filter instanceof FieldFilter) {
|
|
10796
|
+
return filter;
|
|
10797
|
+
}
|
|
10798
|
+
const filters = filter.getFilters();
|
|
10799
|
+
// If the composite filter only contains 1 filter, apply associativity to it.
|
|
10800
|
+
if (filters.length === 1) {
|
|
10801
|
+
return applyAssociation(filters[0]);
|
|
10802
|
+
}
|
|
10803
|
+
// Associativity applied to a flat composite filter results is itself.
|
|
10804
|
+
if (compositeFilterIsFlat(filter)) {
|
|
10805
|
+
return filter;
|
|
10806
|
+
}
|
|
10807
|
+
// First apply associativity to all subfilters. This will in turn recursively apply
|
|
10808
|
+
// associativity to all nested composite filters and field filters.
|
|
10809
|
+
const updatedFilters = filters.map(subfilter => applyAssociation(subfilter));
|
|
10810
|
+
// For composite subfilters that perform the same kind of logical operation as `compositeFilter`
|
|
10811
|
+
// take out their filters and add them to `compositeFilter`. For example:
|
|
10812
|
+
// compositeFilter = (A | (B | C | D))
|
|
10813
|
+
// compositeSubfilter = (B | C | D)
|
|
10814
|
+
// Result: (A | B | C | D)
|
|
10815
|
+
// Note that the `compositeSubfilter` has been eliminated, and its filters (B, C, D) have been
|
|
10816
|
+
// added to the top-level "compositeFilter".
|
|
10817
|
+
const newSubfilters = [];
|
|
10818
|
+
updatedFilters.forEach(subfilter => {
|
|
10819
|
+
if (subfilter instanceof FieldFilter) {
|
|
10820
|
+
newSubfilters.push(subfilter);
|
|
10821
|
+
}
|
|
10822
|
+
else if (subfilter instanceof CompositeFilter) {
|
|
10823
|
+
if (subfilter.op === filter.op) {
|
|
10824
|
+
// compositeFilter: (A | (B | C))
|
|
10825
|
+
// compositeSubfilter: (B | C)
|
|
10826
|
+
// Result: (A | B | C)
|
|
10827
|
+
newSubfilters.push(...subfilter.filters);
|
|
10828
|
+
}
|
|
10829
|
+
else {
|
|
10830
|
+
// compositeFilter: (A | (B & C))
|
|
10831
|
+
// compositeSubfilter: (B & C)
|
|
10832
|
+
// Result: (A | (B & C))
|
|
10833
|
+
newSubfilters.push(subfilter);
|
|
10834
|
+
}
|
|
10835
|
+
}
|
|
10836
|
+
});
|
|
10837
|
+
if (newSubfilters.length === 1) {
|
|
10838
|
+
return newSubfilters[0];
|
|
10351
10839
|
}
|
|
10840
|
+
return CompositeFilter.create(newSubfilters, filter.op);
|
|
10352
10841
|
}
|
|
10353
10842
|
|
|
10354
10843
|
/**
|
|
@@ -10395,7 +10884,7 @@ class MemoryIndexManager {
|
|
|
10395
10884
|
}
|
|
10396
10885
|
getIndexType(transaction, target) {
|
|
10397
10886
|
// Field indices are not supported with memory persistence.
|
|
10398
|
-
return PersistencePromise.resolve(0 /* NONE */);
|
|
10887
|
+
return PersistencePromise.resolve(0 /* IndexType.NONE */);
|
|
10399
10888
|
}
|
|
10400
10889
|
getFieldIndexes(transaction, collectionGroup) {
|
|
10401
10890
|
// Field indices are not supported with memory persistence.
|
|
@@ -10618,8 +11107,14 @@ class IndexedDbIndexManager {
|
|
|
10618
11107
|
if (subTargets) {
|
|
10619
11108
|
return subTargets;
|
|
10620
11109
|
}
|
|
10621
|
-
|
|
10622
|
-
|
|
11110
|
+
if (target.filters.length === 0) {
|
|
11111
|
+
subTargets = [target];
|
|
11112
|
+
}
|
|
11113
|
+
else {
|
|
11114
|
+
// There is an implicit AND operation between all the filters stored in the target
|
|
11115
|
+
const dnf = getDnfTerms(CompositeFilter.create(target.filters, "and" /* CompositeOperator.AND */));
|
|
11116
|
+
subTargets = dnf.map(term => newTarget(target.path, target.collectionGroup, target.orderBy, term.getFilters(), target.limit, target.startAt, target.endAt));
|
|
11117
|
+
}
|
|
10623
11118
|
this.targetToDnfSubTargets.set(target, subTargets);
|
|
10624
11119
|
return subTargets;
|
|
10625
11120
|
}
|
|
@@ -10677,18 +11172,29 @@ class IndexedDbIndexManager {
|
|
|
10677
11172
|
});
|
|
10678
11173
|
}
|
|
10679
11174
|
getIndexType(transaction, target) {
|
|
10680
|
-
let indexType = 2 /* FULL */;
|
|
10681
|
-
|
|
11175
|
+
let indexType = 2 /* IndexType.FULL */;
|
|
11176
|
+
const subTargets = this.getSubTargets(target);
|
|
11177
|
+
return PersistencePromise.forEach(subTargets, (target) => {
|
|
10682
11178
|
return this.getFieldIndex(transaction, target).next(index => {
|
|
10683
11179
|
if (!index) {
|
|
10684
|
-
indexType = 0 /* NONE */;
|
|
11180
|
+
indexType = 0 /* IndexType.NONE */;
|
|
10685
11181
|
}
|
|
10686
|
-
else if (indexType !== 0 /* NONE */ &&
|
|
11182
|
+
else if (indexType !== 0 /* IndexType.NONE */ &&
|
|
10687
11183
|
index.fields.length < targetGetSegmentCount(target)) {
|
|
10688
|
-
indexType = 1 /* PARTIAL */;
|
|
11184
|
+
indexType = 1 /* IndexType.PARTIAL */;
|
|
10689
11185
|
}
|
|
10690
11186
|
});
|
|
10691
|
-
}).next(() =>
|
|
11187
|
+
}).next(() => {
|
|
11188
|
+
// OR queries have more than one sub-target (one sub-target per DNF term). We currently consider
|
|
11189
|
+
// OR queries that have a `limit` to have a partial index. For such queries we perform sorting
|
|
11190
|
+
// and apply the limit in memory as a post-processing step.
|
|
11191
|
+
if (targetHasLimit(target) &&
|
|
11192
|
+
subTargets.length > 1 &&
|
|
11193
|
+
indexType === 2 /* IndexType.FULL */) {
|
|
11194
|
+
return 1 /* IndexType.PARTIAL */;
|
|
11195
|
+
}
|
|
11196
|
+
return indexType;
|
|
11197
|
+
});
|
|
10692
11198
|
}
|
|
10693
11199
|
/**
|
|
10694
11200
|
* Returns the byte encoded form of the directional values in the field index.
|
|
@@ -10710,7 +11216,7 @@ class IndexedDbIndexManager {
|
|
|
10710
11216
|
/** Encodes a single value to the ascending index format. */
|
|
10711
11217
|
encodeSingleElement(value) {
|
|
10712
11218
|
const encoder = new IndexByteEncoder();
|
|
10713
|
-
FirestoreIndexValueWriter.INSTANCE.writeIndexValue(value, encoder.forKind(0 /* ASCENDING */));
|
|
11219
|
+
FirestoreIndexValueWriter.INSTANCE.writeIndexValue(value, encoder.forKind(0 /* IndexKind.ASCENDING */));
|
|
10714
11220
|
return encoder.encodedBytes();
|
|
10715
11221
|
}
|
|
10716
11222
|
/**
|
|
@@ -10726,15 +11232,15 @@ class IndexedDbIndexManager {
|
|
|
10726
11232
|
* Encodes the given field values according to the specification in `target`.
|
|
10727
11233
|
* For IN queries, a list of possible values is returned.
|
|
10728
11234
|
*/
|
|
10729
|
-
encodeValues(fieldIndex, target,
|
|
10730
|
-
if (
|
|
11235
|
+
encodeValues(fieldIndex, target, values) {
|
|
11236
|
+
if (values === null) {
|
|
10731
11237
|
return [];
|
|
10732
11238
|
}
|
|
10733
11239
|
let encoders = [];
|
|
10734
11240
|
encoders.push(new IndexByteEncoder());
|
|
10735
|
-
let
|
|
11241
|
+
let valueIdx = 0;
|
|
10736
11242
|
for (const segment of fieldIndexGetDirectionalSegments(fieldIndex)) {
|
|
10737
|
-
const value =
|
|
11243
|
+
const value = values[valueIdx++];
|
|
10738
11244
|
for (const encoder of encoders) {
|
|
10739
11245
|
if (this.isInFilter(target, segment.fieldPath) && isArray(value)) {
|
|
10740
11246
|
encoders = this.expandIndexValues(encoders, segment, value);
|
|
@@ -10785,7 +11291,7 @@ class IndexedDbIndexManager {
|
|
|
10785
11291
|
isInFilter(target, fieldPath) {
|
|
10786
11292
|
return !!target.filters.find(f => f instanceof FieldFilter &&
|
|
10787
11293
|
f.field.isEqual(fieldPath) &&
|
|
10788
|
-
(f.op === "in" /* IN */ || f.op === "not-in" /* NOT_IN */));
|
|
11294
|
+
(f.op === "in" /* Operator.IN */ || f.op === "not-in" /* Operator.NOT_IN */));
|
|
10789
11295
|
}
|
|
10790
11296
|
getFieldIndexes(transaction, collectionGroup) {
|
|
10791
11297
|
const indexes = indexConfigurationStore(transaction);
|
|
@@ -10974,24 +11480,36 @@ class IndexedDbIndexManager {
|
|
|
10974
11480
|
bounds.push(upper);
|
|
10975
11481
|
const ranges = [];
|
|
10976
11482
|
for (let i = 0; i < bounds.length; i += 2) {
|
|
10977
|
-
|
|
11483
|
+
// If we encounter two bounds that will create an unmatchable key range,
|
|
11484
|
+
// then we return an empty set of key ranges.
|
|
11485
|
+
if (this.isRangeMatchable(bounds[i], bounds[i + 1])) {
|
|
11486
|
+
return [];
|
|
11487
|
+
}
|
|
11488
|
+
const lowerBound = [
|
|
10978
11489
|
bounds[i].indexId,
|
|
10979
11490
|
this.uid,
|
|
10980
11491
|
bounds[i].arrayValue,
|
|
10981
11492
|
bounds[i].directionalValue,
|
|
10982
11493
|
EMPTY_VALUE,
|
|
10983
11494
|
[]
|
|
10984
|
-
]
|
|
11495
|
+
];
|
|
11496
|
+
const upperBound = [
|
|
10985
11497
|
bounds[i + 1].indexId,
|
|
10986
11498
|
this.uid,
|
|
10987
11499
|
bounds[i + 1].arrayValue,
|
|
10988
11500
|
bounds[i + 1].directionalValue,
|
|
10989
11501
|
EMPTY_VALUE,
|
|
10990
11502
|
[]
|
|
10991
|
-
]
|
|
11503
|
+
];
|
|
11504
|
+
ranges.push(IDBKeyRange.bound(lowerBound, upperBound));
|
|
10992
11505
|
}
|
|
10993
11506
|
return ranges;
|
|
10994
11507
|
}
|
|
11508
|
+
isRangeMatchable(lowerBound, upperBound) {
|
|
11509
|
+
// If lower bound is greater than the upper bound, then the key
|
|
11510
|
+
// range can never be matched.
|
|
11511
|
+
return indexEntryComparator(lowerBound, upperBound) > 0;
|
|
11512
|
+
}
|
|
10995
11513
|
getMinOffsetFromCollectionGroup(transaction, collectionGroup) {
|
|
10996
11514
|
return this.getFieldIndexes(transaction, collectionGroup).next(getMinOffsetFromFieldIndexes);
|
|
10997
11515
|
}
|
|
@@ -11968,7 +12486,7 @@ class LruScheduler {
|
|
|
11968
12486
|
}
|
|
11969
12487
|
scheduleGC(delay) {
|
|
11970
12488
|
logDebug(LOG_TAG$e, `Garbage collection scheduled in ${delay}ms`);
|
|
11971
|
-
this.gcTask = this.asyncQueue.enqueueAfterDelay("lru_garbage_collection" /* LruGarbageCollection */, delay, async () => {
|
|
12489
|
+
this.gcTask = this.asyncQueue.enqueueAfterDelay("lru_garbage_collection" /* TimerId.LruGarbageCollection */, delay, async () => {
|
|
11972
12490
|
this.gcTask = null;
|
|
11973
12491
|
try {
|
|
11974
12492
|
await this.localStore.collectGarbage(this.garbageCollector);
|
|
@@ -13165,7 +13683,7 @@ class LocalDocumentsView {
|
|
|
13165
13683
|
}
|
|
13166
13684
|
/** Returns a base document that can be used to apply `overlay`. */
|
|
13167
13685
|
getBaseDocument(transaction, key, overlay) {
|
|
13168
|
-
return overlay === null || overlay.mutation.type === 1 /* Patch */
|
|
13686
|
+
return overlay === null || overlay.mutation.type === 1 /* MutationType.Patch */
|
|
13169
13687
|
? this.remoteDocumentCache.getEntry(transaction, key)
|
|
13170
13688
|
: PersistencePromise.resolve(MutableDocument.newInvalidDocument(key));
|
|
13171
13689
|
}
|
|
@@ -14918,7 +15436,7 @@ class IndexedDbPersistence {
|
|
|
14918
15436
|
* extend or acquire the primary lease if the client is eligible.
|
|
14919
15437
|
*/
|
|
14920
15438
|
scheduleClientMetadataAndPrimaryLeaseRefreshes() {
|
|
14921
|
-
this.clientMetadataRefresher = this.queue.enqueueAfterDelay("client_metadata_refresh" /* ClientMetadataRefresh */, CLIENT_METADATA_REFRESH_INTERVAL_MS, () => {
|
|
15439
|
+
this.clientMetadataRefresher = this.queue.enqueueAfterDelay("client_metadata_refresh" /* TimerId.ClientMetadataRefresh */, CLIENT_METADATA_REFRESH_INTERVAL_MS, () => {
|
|
14922
15440
|
return this.updateClientMetadataAndTryBecomePrimary()
|
|
14923
15441
|
.then(() => this.maybeGarbageCollectMultiClientState())
|
|
14924
15442
|
.then(() => this.scheduleClientMetadataAndPrimaryLeaseRefreshes());
|
|
@@ -15928,7 +16446,7 @@ function localStoreAllocateTarget(localStore, target) {
|
|
|
15928
16446
|
return localStoreImpl.targetCache
|
|
15929
16447
|
.allocateTargetId(txn)
|
|
15930
16448
|
.next(targetId => {
|
|
15931
|
-
targetData = new TargetData(target, targetId, 0 /* Listen */, txn.currentSequenceNumber);
|
|
16449
|
+
targetData = new TargetData(target, targetId, 0 /* TargetPurpose.Listen */, txn.currentSequenceNumber);
|
|
15932
16450
|
return localStoreImpl.targetCache
|
|
15933
16451
|
.addTargetData(txn, targetData)
|
|
15934
16452
|
.next(() => targetData);
|
|
@@ -16350,11 +16868,11 @@ class QueryEngine {
|
|
|
16350
16868
|
return this.indexManager
|
|
16351
16869
|
.getIndexType(transaction, target)
|
|
16352
16870
|
.next(indexType => {
|
|
16353
|
-
if (indexType === 0 /* NONE */) {
|
|
16871
|
+
if (indexType === 0 /* IndexType.NONE */) {
|
|
16354
16872
|
// The target cannot be served from any index.
|
|
16355
16873
|
return null;
|
|
16356
16874
|
}
|
|
16357
|
-
if (query.limit !== null && indexType === 1 /* PARTIAL */) {
|
|
16875
|
+
if (query.limit !== null && indexType === 1 /* IndexType.PARTIAL */) {
|
|
16358
16876
|
// We cannot apply a limit for targets that are served using a partial
|
|
16359
16877
|
// index. If a partial index will be used to serve the target, the
|
|
16360
16878
|
// query may return a superset of documents that match the target
|
|
@@ -16362,7 +16880,7 @@ class QueryEngine {
|
|
|
16362
16880
|
// may return the correct set of documents in the wrong order (e.g. if
|
|
16363
16881
|
// the index doesn't include a segment for one of the orderBys).
|
|
16364
16882
|
// Therefore, a limit should not be applied in such cases.
|
|
16365
|
-
query = queryWithLimit(query, null, "F" /* First */);
|
|
16883
|
+
query = queryWithLimit(query, null, "F" /* LimitType.First */);
|
|
16366
16884
|
target = queryToTarget(query);
|
|
16367
16885
|
}
|
|
16368
16886
|
return this.indexManager
|
|
@@ -16383,7 +16901,7 @@ class QueryEngine {
|
|
|
16383
16901
|
// query's filters are included in the result set. The SDK
|
|
16384
16902
|
// can then apply the limit once all local edits are
|
|
16385
16903
|
// incorporated.
|
|
16386
|
-
return this.performQueryUsingIndex(transaction, queryWithLimit(query, null, "F" /* First */));
|
|
16904
|
+
return this.performQueryUsingIndex(transaction, queryWithLimit(query, null, "F" /* LimitType.First */));
|
|
16387
16905
|
}
|
|
16388
16906
|
return this.appendRemainingResults(transaction, previousResults, query, offset);
|
|
16389
16907
|
});
|
|
@@ -16462,7 +16980,7 @@ class QueryEngine {
|
|
|
16462
16980
|
// the boundary of the limit itself did not change and documents from cache
|
|
16463
16981
|
// will continue to be "rejected" by this boundary. Therefore, we can ignore
|
|
16464
16982
|
// any modifications that don't affect the last document.
|
|
16465
|
-
const docAtLimitEdge = query.limitType === "F" /* First */
|
|
16983
|
+
const docAtLimitEdge = query.limitType === "F" /* LimitType.First */
|
|
16466
16984
|
? sortedPreviousResults.last()
|
|
16467
16985
|
: sortedPreviousResults.first();
|
|
16468
16986
|
if (!docAtLimitEdge) {
|
|
@@ -17383,7 +17901,7 @@ function nodePromise(action) {
|
|
|
17383
17901
|
*/
|
|
17384
17902
|
// TODO: Fetch runtime version from grpc-js/package.json instead
|
|
17385
17903
|
// when there's a cleaner way to dynamic require JSON in both Node ESM and CJS
|
|
17386
|
-
const grpcVersion = '1.3
|
|
17904
|
+
const grpcVersion = '1.7.3';
|
|
17387
17905
|
const LOG_TAG$9 = 'Connection';
|
|
17388
17906
|
const X_GOOG_API_CLIENT_VALUE = `gl-node/${process.versions.node} fire/${SDK_VERSION} grpc/${grpcVersion}`;
|
|
17389
17907
|
function createMetadata(databasePath, authToken, appCheckToken, appId) {
|
|
@@ -19831,7 +20349,8 @@ const nested = {
|
|
|
19831
20349
|
Operator: {
|
|
19832
20350
|
values: {
|
|
19833
20351
|
OPERATOR_UNSPECIFIED: 0,
|
|
19834
|
-
AND: 1
|
|
20352
|
+
AND: 1,
|
|
20353
|
+
OR: 2
|
|
19835
20354
|
}
|
|
19836
20355
|
}
|
|
19837
20356
|
}
|
|
@@ -20707,7 +21226,7 @@ class PersistentStream {
|
|
|
20707
21226
|
this.authCredentialsProvider = authCredentialsProvider;
|
|
20708
21227
|
this.appCheckCredentialsProvider = appCheckCredentialsProvider;
|
|
20709
21228
|
this.listener = listener;
|
|
20710
|
-
this.state = 0 /* Initial */;
|
|
21229
|
+
this.state = 0 /* PersistentStreamState.Initial */;
|
|
20711
21230
|
/**
|
|
20712
21231
|
* A close count that's incremented every time the stream is closed; used by
|
|
20713
21232
|
* getCloseGuardedDispatcher() to invalidate callbacks that happen after
|
|
@@ -20727,8 +21246,8 @@ class PersistentStream {
|
|
|
20727
21246
|
* outbound requests.
|
|
20728
21247
|
*/
|
|
20729
21248
|
isStarted() {
|
|
20730
|
-
return (this.state === 1 /* Starting */ ||
|
|
20731
|
-
this.state === 5 /* Backoff */ ||
|
|
21249
|
+
return (this.state === 1 /* PersistentStreamState.Starting */ ||
|
|
21250
|
+
this.state === 5 /* PersistentStreamState.Backoff */ ||
|
|
20732
21251
|
this.isOpen());
|
|
20733
21252
|
}
|
|
20734
21253
|
/**
|
|
@@ -20736,8 +21255,8 @@ class PersistentStream {
|
|
|
20736
21255
|
* called) and the stream is ready for outbound requests.
|
|
20737
21256
|
*/
|
|
20738
21257
|
isOpen() {
|
|
20739
|
-
return (this.state === 2 /* Open */ ||
|
|
20740
|
-
this.state === 3 /* Healthy */);
|
|
21258
|
+
return (this.state === 2 /* PersistentStreamState.Open */ ||
|
|
21259
|
+
this.state === 3 /* PersistentStreamState.Healthy */);
|
|
20741
21260
|
}
|
|
20742
21261
|
/**
|
|
20743
21262
|
* Starts the RPC. Only allowed if isStarted() returns false. The stream is
|
|
@@ -20747,7 +21266,7 @@ class PersistentStream {
|
|
|
20747
21266
|
* When start returns, isStarted() will return true.
|
|
20748
21267
|
*/
|
|
20749
21268
|
start() {
|
|
20750
|
-
if (this.state === 4 /* Error */) {
|
|
21269
|
+
if (this.state === 4 /* PersistentStreamState.Error */) {
|
|
20751
21270
|
this.performBackoff();
|
|
20752
21271
|
return;
|
|
20753
21272
|
}
|
|
@@ -20761,7 +21280,7 @@ class PersistentStream {
|
|
|
20761
21280
|
*/
|
|
20762
21281
|
async stop() {
|
|
20763
21282
|
if (this.isStarted()) {
|
|
20764
|
-
await this.close(0 /* Initial */);
|
|
21283
|
+
await this.close(0 /* PersistentStreamState.Initial */);
|
|
20765
21284
|
}
|
|
20766
21285
|
}
|
|
20767
21286
|
/**
|
|
@@ -20773,7 +21292,7 @@ class PersistentStream {
|
|
|
20773
21292
|
* inhibit backoff if required.
|
|
20774
21293
|
*/
|
|
20775
21294
|
inhibitBackoff() {
|
|
20776
|
-
this.state = 0 /* Initial */;
|
|
21295
|
+
this.state = 0 /* PersistentStreamState.Initial */;
|
|
20777
21296
|
this.backoff.reset();
|
|
20778
21297
|
}
|
|
20779
21298
|
/**
|
|
@@ -20803,7 +21322,7 @@ class PersistentStream {
|
|
|
20803
21322
|
if (this.isOpen()) {
|
|
20804
21323
|
// When timing out an idle stream there's no reason to force the stream into backoff when
|
|
20805
21324
|
// it restarts so set the stream state to Initial instead of Error.
|
|
20806
|
-
return this.close(0 /* Initial */);
|
|
21325
|
+
return this.close(0 /* PersistentStreamState.Initial */);
|
|
20807
21326
|
}
|
|
20808
21327
|
}
|
|
20809
21328
|
/** Marks the stream as active again. */
|
|
@@ -20841,7 +21360,7 @@ class PersistentStream {
|
|
|
20841
21360
|
// Invalidates any stream-related callbacks (e.g. from auth or the
|
|
20842
21361
|
// underlying stream), guaranteeing they won't execute.
|
|
20843
21362
|
this.closeCount++;
|
|
20844
|
-
if (finalState !== 4 /* Error */) {
|
|
21363
|
+
if (finalState !== 4 /* PersistentStreamState.Error */) {
|
|
20845
21364
|
// If this is an intentional close ensure we don't delay our next connection attempt.
|
|
20846
21365
|
this.backoff.reset();
|
|
20847
21366
|
}
|
|
@@ -20853,7 +21372,7 @@ class PersistentStream {
|
|
|
20853
21372
|
}
|
|
20854
21373
|
else if (error &&
|
|
20855
21374
|
error.code === Code.UNAUTHENTICATED &&
|
|
20856
|
-
this.state !== 3 /* Healthy */) {
|
|
21375
|
+
this.state !== 3 /* PersistentStreamState.Healthy */) {
|
|
20857
21376
|
// "unauthenticated" error means the token was rejected. This should rarely
|
|
20858
21377
|
// happen since both Auth and AppCheck ensure a sufficient TTL when we
|
|
20859
21378
|
// request a token. If a user manually resets their system clock this can
|
|
@@ -20881,7 +21400,7 @@ class PersistentStream {
|
|
|
20881
21400
|
*/
|
|
20882
21401
|
tearDown() { }
|
|
20883
21402
|
auth() {
|
|
20884
|
-
this.state = 1 /* Starting */;
|
|
21403
|
+
this.state = 1 /* PersistentStreamState.Starting */;
|
|
20885
21404
|
const dispatchIfNotClosed = this.getCloseGuardedDispatcher(this.closeCount);
|
|
20886
21405
|
// TODO(mikelehen): Just use dispatchIfNotClosed, but see TODO below.
|
|
20887
21406
|
const closeCount = this.closeCount;
|
|
@@ -20911,10 +21430,10 @@ class PersistentStream {
|
|
|
20911
21430
|
this.stream = this.startRpc(authToken, appCheckToken);
|
|
20912
21431
|
this.stream.onOpen(() => {
|
|
20913
21432
|
dispatchIfNotClosed(() => {
|
|
20914
|
-
this.state = 2 /* Open */;
|
|
21433
|
+
this.state = 2 /* PersistentStreamState.Open */;
|
|
20915
21434
|
this.healthCheck = this.queue.enqueueAfterDelay(this.healthTimerId, HEALTHY_TIMEOUT_MS, () => {
|
|
20916
21435
|
if (this.isOpen()) {
|
|
20917
|
-
this.state = 3 /* Healthy */;
|
|
21436
|
+
this.state = 3 /* PersistentStreamState.Healthy */;
|
|
20918
21437
|
}
|
|
20919
21438
|
return Promise.resolve();
|
|
20920
21439
|
});
|
|
@@ -20933,9 +21452,9 @@ class PersistentStream {
|
|
|
20933
21452
|
});
|
|
20934
21453
|
}
|
|
20935
21454
|
performBackoff() {
|
|
20936
|
-
this.state = 5 /* Backoff */;
|
|
21455
|
+
this.state = 5 /* PersistentStreamState.Backoff */;
|
|
20937
21456
|
this.backoff.backoffAndRun(async () => {
|
|
20938
|
-
this.state = 0 /* Initial */;
|
|
21457
|
+
this.state = 0 /* PersistentStreamState.Initial */;
|
|
20939
21458
|
this.start();
|
|
20940
21459
|
});
|
|
20941
21460
|
}
|
|
@@ -20947,7 +21466,7 @@ class PersistentStream {
|
|
|
20947
21466
|
// we never expect this to happen because if we stop a stream ourselves,
|
|
20948
21467
|
// this callback will never be called. To prevent cases where we retry
|
|
20949
21468
|
// without a backoff accidentally, we set the stream to error in all cases.
|
|
20950
|
-
return this.close(4 /* Error */, error);
|
|
21469
|
+
return this.close(4 /* PersistentStreamState.Error */, error);
|
|
20951
21470
|
}
|
|
20952
21471
|
/**
|
|
20953
21472
|
* Returns a "dispatcher" function that dispatches operations onto the
|
|
@@ -20978,7 +21497,7 @@ class PersistentStream {
|
|
|
20978
21497
|
*/
|
|
20979
21498
|
class PersistentListenStream extends PersistentStream {
|
|
20980
21499
|
constructor(queue, connection, authCredentials, appCheckCredentials, serializer, listener) {
|
|
20981
|
-
super(queue, "listen_stream_connection_backoff" /* ListenStreamConnectionBackoff */, "listen_stream_idle" /* ListenStreamIdle */, "health_check_timeout" /* HealthCheckTimeout */, connection, authCredentials, appCheckCredentials, listener);
|
|
21500
|
+
super(queue, "listen_stream_connection_backoff" /* TimerId.ListenStreamConnectionBackoff */, "listen_stream_idle" /* TimerId.ListenStreamIdle */, "health_check_timeout" /* TimerId.HealthCheckTimeout */, connection, authCredentials, appCheckCredentials, listener);
|
|
20982
21501
|
this.serializer = serializer;
|
|
20983
21502
|
}
|
|
20984
21503
|
startRpc(authToken, appCheckToken) {
|
|
@@ -21037,7 +21556,7 @@ class PersistentListenStream extends PersistentStream {
|
|
|
21037
21556
|
*/
|
|
21038
21557
|
class PersistentWriteStream extends PersistentStream {
|
|
21039
21558
|
constructor(queue, connection, authCredentials, appCheckCredentials, serializer, listener) {
|
|
21040
|
-
super(queue, "write_stream_connection_backoff" /* WriteStreamConnectionBackoff */, "write_stream_idle" /* WriteStreamIdle */, "health_check_timeout" /* HealthCheckTimeout */, connection, authCredentials, appCheckCredentials, listener);
|
|
21559
|
+
super(queue, "write_stream_connection_backoff" /* TimerId.WriteStreamConnectionBackoff */, "write_stream_idle" /* TimerId.WriteStreamIdle */, "health_check_timeout" /* TimerId.HealthCheckTimeout */, connection, authCredentials, appCheckCredentials, listener);
|
|
21041
21560
|
this.serializer = serializer;
|
|
21042
21561
|
this.handshakeComplete_ = false;
|
|
21043
21562
|
}
|
|
@@ -21296,7 +21815,7 @@ class OnlineStateTracker {
|
|
|
21296
21815
|
this.asyncQueue = asyncQueue;
|
|
21297
21816
|
this.onlineStateHandler = onlineStateHandler;
|
|
21298
21817
|
/** The current OnlineState. */
|
|
21299
|
-
this.state = "Unknown" /* Unknown */;
|
|
21818
|
+
this.state = "Unknown" /* OnlineState.Unknown */;
|
|
21300
21819
|
/**
|
|
21301
21820
|
* A count of consecutive failures to open the stream. If it reaches the
|
|
21302
21821
|
* maximum defined by MAX_WATCH_STREAM_FAILURES, we'll set the OnlineState to
|
|
@@ -21325,12 +21844,12 @@ class OnlineStateTracker {
|
|
|
21325
21844
|
*/
|
|
21326
21845
|
handleWatchStreamStart() {
|
|
21327
21846
|
if (this.watchStreamFailures === 0) {
|
|
21328
|
-
this.setAndBroadcast("Unknown" /* Unknown */);
|
|
21329
|
-
this.onlineStateTimer = this.asyncQueue.enqueueAfterDelay("online_state_timeout" /* OnlineStateTimeout */, ONLINE_STATE_TIMEOUT_MS, () => {
|
|
21847
|
+
this.setAndBroadcast("Unknown" /* OnlineState.Unknown */);
|
|
21848
|
+
this.onlineStateTimer = this.asyncQueue.enqueueAfterDelay("online_state_timeout" /* TimerId.OnlineStateTimeout */, ONLINE_STATE_TIMEOUT_MS, () => {
|
|
21330
21849
|
this.onlineStateTimer = null;
|
|
21331
21850
|
this.logClientOfflineWarningIfNecessary(`Backend didn't respond within ${ONLINE_STATE_TIMEOUT_MS / 1000} ` +
|
|
21332
21851
|
`seconds.`);
|
|
21333
|
-
this.setAndBroadcast("Offline" /* Offline */);
|
|
21852
|
+
this.setAndBroadcast("Offline" /* OnlineState.Offline */);
|
|
21334
21853
|
// NOTE: handleWatchStreamFailure() will continue to increment
|
|
21335
21854
|
// watchStreamFailures even though we are already marked Offline,
|
|
21336
21855
|
// but this is non-harmful.
|
|
@@ -21345,8 +21864,8 @@ class OnlineStateTracker {
|
|
|
21345
21864
|
* actually transition to the 'Offline' state.
|
|
21346
21865
|
*/
|
|
21347
21866
|
handleWatchStreamFailure(error) {
|
|
21348
|
-
if (this.state === "Online" /* Online */) {
|
|
21349
|
-
this.setAndBroadcast("Unknown" /* Unknown */);
|
|
21867
|
+
if (this.state === "Online" /* OnlineState.Online */) {
|
|
21868
|
+
this.setAndBroadcast("Unknown" /* OnlineState.Unknown */);
|
|
21350
21869
|
}
|
|
21351
21870
|
else {
|
|
21352
21871
|
this.watchStreamFailures++;
|
|
@@ -21354,7 +21873,7 @@ class OnlineStateTracker {
|
|
|
21354
21873
|
this.clearOnlineStateTimer();
|
|
21355
21874
|
this.logClientOfflineWarningIfNecessary(`Connection failed ${MAX_WATCH_STREAM_FAILURES} ` +
|
|
21356
21875
|
`times. Most recent error: ${error.toString()}`);
|
|
21357
|
-
this.setAndBroadcast("Offline" /* Offline */);
|
|
21876
|
+
this.setAndBroadcast("Offline" /* OnlineState.Offline */);
|
|
21358
21877
|
}
|
|
21359
21878
|
}
|
|
21360
21879
|
}
|
|
@@ -21368,7 +21887,7 @@ class OnlineStateTracker {
|
|
|
21368
21887
|
set(newState) {
|
|
21369
21888
|
this.clearOnlineStateTimer();
|
|
21370
21889
|
this.watchStreamFailures = 0;
|
|
21371
|
-
if (newState === "Online" /* Online */) {
|
|
21890
|
+
if (newState === "Online" /* OnlineState.Online */) {
|
|
21372
21891
|
// We've connected to watch at least once. Don't warn the developer
|
|
21373
21892
|
// about being offline going forward.
|
|
21374
21893
|
this.shouldWarnClientIsOffline = false;
|
|
@@ -21495,7 +22014,7 @@ function newRemoteStore(localStore, datastore, asyncQueue, onlineStateHandler, c
|
|
|
21495
22014
|
/** Re-enables the network. Idempotent. */
|
|
21496
22015
|
function remoteStoreEnableNetwork(remoteStore) {
|
|
21497
22016
|
const remoteStoreImpl = debugCast(remoteStore);
|
|
21498
|
-
remoteStoreImpl.offlineCauses.delete(0 /* UserDisabled */);
|
|
22017
|
+
remoteStoreImpl.offlineCauses.delete(0 /* OfflineCause.UserDisabled */);
|
|
21499
22018
|
return enableNetworkInternal(remoteStoreImpl);
|
|
21500
22019
|
}
|
|
21501
22020
|
async function enableNetworkInternal(remoteStoreImpl) {
|
|
@@ -21511,10 +22030,10 @@ async function enableNetworkInternal(remoteStoreImpl) {
|
|
|
21511
22030
|
*/
|
|
21512
22031
|
async function remoteStoreDisableNetwork(remoteStore) {
|
|
21513
22032
|
const remoteStoreImpl = debugCast(remoteStore);
|
|
21514
|
-
remoteStoreImpl.offlineCauses.add(0 /* UserDisabled */);
|
|
22033
|
+
remoteStoreImpl.offlineCauses.add(0 /* OfflineCause.UserDisabled */);
|
|
21515
22034
|
await disableNetworkInternal(remoteStoreImpl);
|
|
21516
22035
|
// Set the OnlineState to Offline so get()s return from cache, etc.
|
|
21517
|
-
remoteStoreImpl.onlineStateTracker.set("Offline" /* Offline */);
|
|
22036
|
+
remoteStoreImpl.onlineStateTracker.set("Offline" /* OnlineState.Offline */);
|
|
21518
22037
|
}
|
|
21519
22038
|
async function disableNetworkInternal(remoteStoreImpl) {
|
|
21520
22039
|
for (const networkStatusHandler of remoteStoreImpl.onNetworkStatusChange) {
|
|
@@ -21524,12 +22043,12 @@ async function disableNetworkInternal(remoteStoreImpl) {
|
|
|
21524
22043
|
async function remoteStoreShutdown(remoteStore) {
|
|
21525
22044
|
const remoteStoreImpl = debugCast(remoteStore);
|
|
21526
22045
|
logDebug(LOG_TAG$5, 'RemoteStore shutting down.');
|
|
21527
|
-
remoteStoreImpl.offlineCauses.add(5 /* Shutdown */);
|
|
22046
|
+
remoteStoreImpl.offlineCauses.add(5 /* OfflineCause.Shutdown */);
|
|
21528
22047
|
await disableNetworkInternal(remoteStoreImpl);
|
|
21529
22048
|
remoteStoreImpl.connectivityMonitor.shutdown();
|
|
21530
22049
|
// Set the OnlineState to Unknown (rather than Offline) to avoid potentially
|
|
21531
22050
|
// triggering spurious listener events with cached data, etc.
|
|
21532
|
-
remoteStoreImpl.onlineStateTracker.set("Unknown" /* Unknown */);
|
|
22051
|
+
remoteStoreImpl.onlineStateTracker.set("Unknown" /* OnlineState.Unknown */);
|
|
21533
22052
|
}
|
|
21534
22053
|
/**
|
|
21535
22054
|
* Starts new listen for the given target. Uses resume token if provided. It
|
|
@@ -21569,7 +22088,7 @@ function remoteStoreUnlisten(remoteStore, targetId) {
|
|
|
21569
22088
|
// Revert to OnlineState.Unknown if the watch stream is not open and we
|
|
21570
22089
|
// have no listeners, since without any listens to send we cannot
|
|
21571
22090
|
// confirm if the stream is healthy and upgrade to OnlineState.Online.
|
|
21572
|
-
remoteStoreImpl.onlineStateTracker.set("Unknown" /* Unknown */);
|
|
22091
|
+
remoteStoreImpl.onlineStateTracker.set("Unknown" /* OnlineState.Unknown */);
|
|
21573
22092
|
}
|
|
21574
22093
|
}
|
|
21575
22094
|
}
|
|
@@ -21630,14 +22149,14 @@ async function onWatchStreamClose(remoteStoreImpl, error) {
|
|
|
21630
22149
|
// No need to restart watch stream because there are no active targets.
|
|
21631
22150
|
// The online state is set to unknown because there is no active attempt
|
|
21632
22151
|
// at establishing a connection
|
|
21633
|
-
remoteStoreImpl.onlineStateTracker.set("Unknown" /* Unknown */);
|
|
22152
|
+
remoteStoreImpl.onlineStateTracker.set("Unknown" /* OnlineState.Unknown */);
|
|
21634
22153
|
}
|
|
21635
22154
|
}
|
|
21636
22155
|
async function onWatchStreamChange(remoteStoreImpl, watchChange, snapshotVersion) {
|
|
21637
22156
|
// Mark the client as online since we got a message from the server
|
|
21638
|
-
remoteStoreImpl.onlineStateTracker.set("Online" /* Online */);
|
|
22157
|
+
remoteStoreImpl.onlineStateTracker.set("Online" /* OnlineState.Online */);
|
|
21639
22158
|
if (watchChange instanceof WatchTargetChange &&
|
|
21640
|
-
watchChange.state === 2 /* Removed */ &&
|
|
22159
|
+
watchChange.state === 2 /* WatchTargetChangeState.Removed */ &&
|
|
21641
22160
|
watchChange.cause) {
|
|
21642
22161
|
// There was an error on a target, don't wait for a consistent snapshot
|
|
21643
22162
|
// to raise events
|
|
@@ -21685,10 +22204,10 @@ async function onWatchStreamChange(remoteStoreImpl, watchChange, snapshotVersion
|
|
|
21685
22204
|
*/
|
|
21686
22205
|
async function disableNetworkUntilRecovery(remoteStoreImpl, e, op) {
|
|
21687
22206
|
if (isIndexedDbTransactionError(e)) {
|
|
21688
|
-
remoteStoreImpl.offlineCauses.add(1 /* IndexedDbFailed */);
|
|
22207
|
+
remoteStoreImpl.offlineCauses.add(1 /* OfflineCause.IndexedDbFailed */);
|
|
21689
22208
|
// Disable network and raise offline snapshots
|
|
21690
22209
|
await disableNetworkInternal(remoteStoreImpl);
|
|
21691
|
-
remoteStoreImpl.onlineStateTracker.set("Offline" /* Offline */);
|
|
22210
|
+
remoteStoreImpl.onlineStateTracker.set("Offline" /* OnlineState.Offline */);
|
|
21692
22211
|
if (!op) {
|
|
21693
22212
|
// Use a simple read operation to determine if IndexedDB recovered.
|
|
21694
22213
|
// Ideally, we would expose a health check directly on SimpleDb, but
|
|
@@ -21699,7 +22218,7 @@ async function disableNetworkUntilRecovery(remoteStoreImpl, e, op) {
|
|
|
21699
22218
|
remoteStoreImpl.asyncQueue.enqueueRetryable(async () => {
|
|
21700
22219
|
logDebug(LOG_TAG$5, 'Retrying IndexedDB access');
|
|
21701
22220
|
await op();
|
|
21702
|
-
remoteStoreImpl.offlineCauses.delete(1 /* IndexedDbFailed */);
|
|
22221
|
+
remoteStoreImpl.offlineCauses.delete(1 /* OfflineCause.IndexedDbFailed */);
|
|
21703
22222
|
await enableNetworkInternal(remoteStoreImpl);
|
|
21704
22223
|
});
|
|
21705
22224
|
}
|
|
@@ -21750,7 +22269,7 @@ function raiseWatchSnapshot(remoteStoreImpl, snapshotVersion) {
|
|
|
21750
22269
|
// mismatch, but don't actually retain that in listenTargets. This ensures
|
|
21751
22270
|
// that we flag the first re-listen this way without impacting future
|
|
21752
22271
|
// listens of this target (that might happen e.g. on reconnect).
|
|
21753
|
-
const requestTargetData = new TargetData(targetData.target, targetId, 1 /* ExistenceFilterMismatch */, targetData.sequenceNumber);
|
|
22272
|
+
const requestTargetData = new TargetData(targetData.target, targetId, 1 /* TargetPurpose.ExistenceFilterMismatch */, targetData.sequenceNumber);
|
|
21754
22273
|
sendWatchRequest(remoteStoreImpl, requestTargetData);
|
|
21755
22274
|
});
|
|
21756
22275
|
return remoteStoreImpl.remoteSyncer.applyRemoteEvent(remoteEvent);
|
|
@@ -21881,10 +22400,10 @@ async function handleWriteError(remoteStoreImpl, error) {
|
|
|
21881
22400
|
}
|
|
21882
22401
|
async function restartNetwork(remoteStore) {
|
|
21883
22402
|
const remoteStoreImpl = debugCast(remoteStore);
|
|
21884
|
-
remoteStoreImpl.offlineCauses.add(4 /* ConnectivityChange */);
|
|
22403
|
+
remoteStoreImpl.offlineCauses.add(4 /* OfflineCause.ConnectivityChange */);
|
|
21885
22404
|
await disableNetworkInternal(remoteStoreImpl);
|
|
21886
|
-
remoteStoreImpl.onlineStateTracker.set("Unknown" /* Unknown */);
|
|
21887
|
-
remoteStoreImpl.offlineCauses.delete(4 /* ConnectivityChange */);
|
|
22405
|
+
remoteStoreImpl.onlineStateTracker.set("Unknown" /* OnlineState.Unknown */);
|
|
22406
|
+
remoteStoreImpl.offlineCauses.delete(4 /* OfflineCause.ConnectivityChange */);
|
|
21888
22407
|
await enableNetworkInternal(remoteStoreImpl);
|
|
21889
22408
|
}
|
|
21890
22409
|
async function remoteStoreHandleCredentialChange(remoteStore, user) {
|
|
@@ -21895,14 +22414,14 @@ async function remoteStoreHandleCredentialChange(remoteStore, user) {
|
|
|
21895
22414
|
// Tear down and re-create our network streams. This will ensure we get a
|
|
21896
22415
|
// fresh auth token for the new user and re-fill the write pipeline with
|
|
21897
22416
|
// new mutations from the LocalStore (since mutations are per-user).
|
|
21898
|
-
remoteStoreImpl.offlineCauses.add(3 /* CredentialChange */);
|
|
22417
|
+
remoteStoreImpl.offlineCauses.add(3 /* OfflineCause.CredentialChange */);
|
|
21899
22418
|
await disableNetworkInternal(remoteStoreImpl);
|
|
21900
22419
|
if (usesNetwork) {
|
|
21901
22420
|
// Don't set the network status to Unknown if we are offline.
|
|
21902
|
-
remoteStoreImpl.onlineStateTracker.set("Unknown" /* Unknown */);
|
|
22421
|
+
remoteStoreImpl.onlineStateTracker.set("Unknown" /* OnlineState.Unknown */);
|
|
21903
22422
|
}
|
|
21904
22423
|
await remoteStoreImpl.remoteSyncer.handleCredentialChange(user);
|
|
21905
|
-
remoteStoreImpl.offlineCauses.delete(3 /* CredentialChange */);
|
|
22424
|
+
remoteStoreImpl.offlineCauses.delete(3 /* OfflineCause.CredentialChange */);
|
|
21906
22425
|
await enableNetworkInternal(remoteStoreImpl);
|
|
21907
22426
|
}
|
|
21908
22427
|
/**
|
|
@@ -21911,13 +22430,13 @@ async function remoteStoreHandleCredentialChange(remoteStore, user) {
|
|
|
21911
22430
|
async function remoteStoreApplyPrimaryState(remoteStore, isPrimary) {
|
|
21912
22431
|
const remoteStoreImpl = debugCast(remoteStore);
|
|
21913
22432
|
if (isPrimary) {
|
|
21914
|
-
remoteStoreImpl.offlineCauses.delete(2 /* IsSecondary */);
|
|
22433
|
+
remoteStoreImpl.offlineCauses.delete(2 /* OfflineCause.IsSecondary */);
|
|
21915
22434
|
await enableNetworkInternal(remoteStoreImpl);
|
|
21916
22435
|
}
|
|
21917
22436
|
else if (!isPrimary) {
|
|
21918
|
-
remoteStoreImpl.offlineCauses.add(2 /* IsSecondary */);
|
|
22437
|
+
remoteStoreImpl.offlineCauses.add(2 /* OfflineCause.IsSecondary */);
|
|
21919
22438
|
await disableNetworkInternal(remoteStoreImpl);
|
|
21920
|
-
remoteStoreImpl.onlineStateTracker.set("Unknown" /* Unknown */);
|
|
22439
|
+
remoteStoreImpl.onlineStateTracker.set("Unknown" /* OnlineState.Unknown */);
|
|
21921
22440
|
}
|
|
21922
22441
|
}
|
|
21923
22442
|
/**
|
|
@@ -21943,7 +22462,7 @@ function ensureWatchStream(remoteStoreImpl) {
|
|
|
21943
22462
|
startWatchStream(remoteStoreImpl);
|
|
21944
22463
|
}
|
|
21945
22464
|
else {
|
|
21946
|
-
remoteStoreImpl.onlineStateTracker.set("Unknown" /* Unknown */);
|
|
22465
|
+
remoteStoreImpl.onlineStateTracker.set("Unknown" /* OnlineState.Unknown */);
|
|
21947
22466
|
}
|
|
21948
22467
|
}
|
|
21949
22468
|
else {
|
|
@@ -22274,46 +22793,46 @@ class DocumentChangeSet {
|
|
|
22274
22793
|
return;
|
|
22275
22794
|
}
|
|
22276
22795
|
// Merge the new change with the existing change.
|
|
22277
|
-
if (change.type !== 0 /* Added */ &&
|
|
22278
|
-
oldChange.type === 3 /* Metadata */) {
|
|
22796
|
+
if (change.type !== 0 /* ChangeType.Added */ &&
|
|
22797
|
+
oldChange.type === 3 /* ChangeType.Metadata */) {
|
|
22279
22798
|
this.changeMap = this.changeMap.insert(key, change);
|
|
22280
22799
|
}
|
|
22281
|
-
else if (change.type === 3 /* Metadata */ &&
|
|
22282
|
-
oldChange.type !== 1 /* Removed */) {
|
|
22800
|
+
else if (change.type === 3 /* ChangeType.Metadata */ &&
|
|
22801
|
+
oldChange.type !== 1 /* ChangeType.Removed */) {
|
|
22283
22802
|
this.changeMap = this.changeMap.insert(key, {
|
|
22284
22803
|
type: oldChange.type,
|
|
22285
22804
|
doc: change.doc
|
|
22286
22805
|
});
|
|
22287
22806
|
}
|
|
22288
|
-
else if (change.type === 2 /* Modified */ &&
|
|
22289
|
-
oldChange.type === 2 /* Modified */) {
|
|
22807
|
+
else if (change.type === 2 /* ChangeType.Modified */ &&
|
|
22808
|
+
oldChange.type === 2 /* ChangeType.Modified */) {
|
|
22290
22809
|
this.changeMap = this.changeMap.insert(key, {
|
|
22291
|
-
type: 2 /* Modified */,
|
|
22810
|
+
type: 2 /* ChangeType.Modified */,
|
|
22292
22811
|
doc: change.doc
|
|
22293
22812
|
});
|
|
22294
22813
|
}
|
|
22295
|
-
else if (change.type === 2 /* Modified */ &&
|
|
22296
|
-
oldChange.type === 0 /* Added */) {
|
|
22814
|
+
else if (change.type === 2 /* ChangeType.Modified */ &&
|
|
22815
|
+
oldChange.type === 0 /* ChangeType.Added */) {
|
|
22297
22816
|
this.changeMap = this.changeMap.insert(key, {
|
|
22298
|
-
type: 0 /* Added */,
|
|
22817
|
+
type: 0 /* ChangeType.Added */,
|
|
22299
22818
|
doc: change.doc
|
|
22300
22819
|
});
|
|
22301
22820
|
}
|
|
22302
|
-
else if (change.type === 1 /* Removed */ &&
|
|
22303
|
-
oldChange.type === 0 /* Added */) {
|
|
22821
|
+
else if (change.type === 1 /* ChangeType.Removed */ &&
|
|
22822
|
+
oldChange.type === 0 /* ChangeType.Added */) {
|
|
22304
22823
|
this.changeMap = this.changeMap.remove(key);
|
|
22305
22824
|
}
|
|
22306
|
-
else if (change.type === 1 /* Removed */ &&
|
|
22307
|
-
oldChange.type === 2 /* Modified */) {
|
|
22825
|
+
else if (change.type === 1 /* ChangeType.Removed */ &&
|
|
22826
|
+
oldChange.type === 2 /* ChangeType.Modified */) {
|
|
22308
22827
|
this.changeMap = this.changeMap.insert(key, {
|
|
22309
|
-
type: 1 /* Removed */,
|
|
22828
|
+
type: 1 /* ChangeType.Removed */,
|
|
22310
22829
|
doc: oldChange.doc
|
|
22311
22830
|
});
|
|
22312
22831
|
}
|
|
22313
|
-
else if (change.type === 0 /* Added */ &&
|
|
22314
|
-
oldChange.type === 1 /* Removed */) {
|
|
22832
|
+
else if (change.type === 0 /* ChangeType.Added */ &&
|
|
22833
|
+
oldChange.type === 1 /* ChangeType.Removed */) {
|
|
22315
22834
|
this.changeMap = this.changeMap.insert(key, {
|
|
22316
|
-
type: 2 /* Modified */,
|
|
22835
|
+
type: 2 /* ChangeType.Modified */,
|
|
22317
22836
|
doc: change.doc
|
|
22318
22837
|
});
|
|
22319
22838
|
}
|
|
@@ -22352,7 +22871,7 @@ class ViewSnapshot {
|
|
|
22352
22871
|
static fromInitialDocuments(query, documents, mutatedKeys, fromCache, hasCachedResults) {
|
|
22353
22872
|
const changes = [];
|
|
22354
22873
|
documents.forEach(doc => {
|
|
22355
|
-
changes.push({ type: 0 /* Added */, doc });
|
|
22874
|
+
changes.push({ type: 0 /* ChangeType.Added */, doc });
|
|
22356
22875
|
});
|
|
22357
22876
|
return new ViewSnapshot(query, documents, DocumentSet.emptySet(documents), changes, mutatedKeys, fromCache,
|
|
22358
22877
|
/* syncStateChanged= */ true,
|
|
@@ -22418,7 +22937,7 @@ function newEventManager() {
|
|
|
22418
22937
|
class EventManagerImpl {
|
|
22419
22938
|
constructor() {
|
|
22420
22939
|
this.queries = new ObjectMap(q => canonifyQuery(q), queryEquals);
|
|
22421
|
-
this.onlineState = "Unknown" /* Unknown */;
|
|
22940
|
+
this.onlineState = "Unknown" /* OnlineState.Unknown */;
|
|
22422
22941
|
this.snapshotsInSyncListeners = new Set();
|
|
22423
22942
|
}
|
|
22424
22943
|
}
|
|
@@ -22549,7 +23068,7 @@ class QueryListener {
|
|
|
22549
23068
|
*/
|
|
22550
23069
|
this.raisedInitialEvent = false;
|
|
22551
23070
|
this.snap = null;
|
|
22552
|
-
this.onlineState = "Unknown" /* Unknown */;
|
|
23071
|
+
this.onlineState = "Unknown" /* OnlineState.Unknown */;
|
|
22553
23072
|
this.options = options || {};
|
|
22554
23073
|
}
|
|
22555
23074
|
/**
|
|
@@ -22563,7 +23082,7 @@ class QueryListener {
|
|
|
22563
23082
|
// Remove the metadata only changes.
|
|
22564
23083
|
const docChanges = [];
|
|
22565
23084
|
for (const docChange of snap.docChanges) {
|
|
22566
|
-
if (docChange.type !== 3 /* Metadata */) {
|
|
23085
|
+
if (docChange.type !== 3 /* ChangeType.Metadata */) {
|
|
22567
23086
|
docChanges.push(docChange);
|
|
22568
23087
|
}
|
|
22569
23088
|
}
|
|
@@ -22606,7 +23125,7 @@ class QueryListener {
|
|
|
22606
23125
|
}
|
|
22607
23126
|
// NOTE: We consider OnlineState.Unknown as online (it should become Offline
|
|
22608
23127
|
// or Online if we wait long enough).
|
|
22609
|
-
const maybeOnline = onlineState !== "Offline" /* Offline */;
|
|
23128
|
+
const maybeOnline = onlineState !== "Offline" /* OnlineState.Offline */;
|
|
22610
23129
|
// Don't raise the event if we're online, aren't synced yet (checked
|
|
22611
23130
|
// above) and are waiting for a sync.
|
|
22612
23131
|
if (this.options.waitForSyncWhenOnline && maybeOnline) {
|
|
@@ -22616,7 +23135,7 @@ class QueryListener {
|
|
|
22616
23135
|
// or we are offline.
|
|
22617
23136
|
return (!snap.docs.isEmpty() ||
|
|
22618
23137
|
snap.hasCachedResults ||
|
|
22619
|
-
onlineState === "Offline" /* Offline */);
|
|
23138
|
+
onlineState === "Offline" /* OnlineState.Offline */);
|
|
22620
23139
|
}
|
|
22621
23140
|
shouldRaiseEvent(snap) {
|
|
22622
23141
|
// We don't need to handle includeDocumentMetadataChanges here because
|
|
@@ -22675,10 +23194,10 @@ class LocalViewChanges {
|
|
|
22675
23194
|
let removedKeys = documentKeySet();
|
|
22676
23195
|
for (const docChange of viewSnapshot.docChanges) {
|
|
22677
23196
|
switch (docChange.type) {
|
|
22678
|
-
case 0 /* Added */:
|
|
23197
|
+
case 0 /* ChangeType.Added */:
|
|
22679
23198
|
addedKeys = addedKeys.add(docChange.doc.key);
|
|
22680
23199
|
break;
|
|
22681
|
-
case 1 /* Removed */:
|
|
23200
|
+
case 1 /* ChangeType.Removed */:
|
|
22682
23201
|
removedKeys = removedKeys.add(docChange.doc.key);
|
|
22683
23202
|
break;
|
|
22684
23203
|
// do nothing
|
|
@@ -22926,11 +23445,11 @@ class View {
|
|
|
22926
23445
|
//
|
|
22927
23446
|
// Note that this should never get used in a refill (when previousChanges is
|
|
22928
23447
|
// set), because there will only be adds -- no deletes or updates.
|
|
22929
|
-
const lastDocInLimit = this.query.limitType === "F" /* First */ &&
|
|
23448
|
+
const lastDocInLimit = this.query.limitType === "F" /* LimitType.First */ &&
|
|
22930
23449
|
oldDocumentSet.size === this.query.limit
|
|
22931
23450
|
? oldDocumentSet.last()
|
|
22932
23451
|
: null;
|
|
22933
|
-
const firstDocInLimit = this.query.limitType === "L" /* Last */ &&
|
|
23452
|
+
const firstDocInLimit = this.query.limitType === "L" /* LimitType.Last */ &&
|
|
22934
23453
|
oldDocumentSet.size === this.query.limit
|
|
22935
23454
|
? oldDocumentSet.first()
|
|
22936
23455
|
: null;
|
|
@@ -22953,7 +23472,7 @@ class View {
|
|
|
22953
23472
|
if (!docsEqual) {
|
|
22954
23473
|
if (!this.shouldWaitForSyncedDocument(oldDoc, newDoc)) {
|
|
22955
23474
|
changeSet.track({
|
|
22956
|
-
type: 2 /* Modified */,
|
|
23475
|
+
type: 2 /* ChangeType.Modified */,
|
|
22957
23476
|
doc: newDoc
|
|
22958
23477
|
});
|
|
22959
23478
|
changeApplied = true;
|
|
@@ -22969,16 +23488,16 @@ class View {
|
|
|
22969
23488
|
}
|
|
22970
23489
|
}
|
|
22971
23490
|
else if (oldDocHadPendingMutations !== newDocHasPendingMutations) {
|
|
22972
|
-
changeSet.track({ type: 3 /* Metadata */, doc: newDoc });
|
|
23491
|
+
changeSet.track({ type: 3 /* ChangeType.Metadata */, doc: newDoc });
|
|
22973
23492
|
changeApplied = true;
|
|
22974
23493
|
}
|
|
22975
23494
|
}
|
|
22976
23495
|
else if (!oldDoc && newDoc) {
|
|
22977
|
-
changeSet.track({ type: 0 /* Added */, doc: newDoc });
|
|
23496
|
+
changeSet.track({ type: 0 /* ChangeType.Added */, doc: newDoc });
|
|
22978
23497
|
changeApplied = true;
|
|
22979
23498
|
}
|
|
22980
23499
|
else if (oldDoc && !newDoc) {
|
|
22981
|
-
changeSet.track({ type: 1 /* Removed */, doc: oldDoc });
|
|
23500
|
+
changeSet.track({ type: 1 /* ChangeType.Removed */, doc: oldDoc });
|
|
22982
23501
|
changeApplied = true;
|
|
22983
23502
|
if (lastDocInLimit || firstDocInLimit) {
|
|
22984
23503
|
// A doc was removed from a full limit query. We'll need to
|
|
@@ -23006,12 +23525,12 @@ class View {
|
|
|
23006
23525
|
// Drop documents out to meet limit/limitToLast requirement.
|
|
23007
23526
|
if (this.query.limit !== null) {
|
|
23008
23527
|
while (newDocumentSet.size > this.query.limit) {
|
|
23009
|
-
const oldDoc = this.query.limitType === "F" /* First */
|
|
23528
|
+
const oldDoc = this.query.limitType === "F" /* LimitType.First */
|
|
23010
23529
|
? newDocumentSet.last()
|
|
23011
23530
|
: newDocumentSet.first();
|
|
23012
23531
|
newDocumentSet = newDocumentSet.delete(oldDoc.key);
|
|
23013
23532
|
newMutatedKeys = newMutatedKeys.delete(oldDoc.key);
|
|
23014
|
-
changeSet.track({ type: 1 /* Removed */, doc: oldDoc });
|
|
23533
|
+
changeSet.track({ type: 1 /* ChangeType.Removed */, doc: oldDoc });
|
|
23015
23534
|
}
|
|
23016
23535
|
}
|
|
23017
23536
|
return {
|
|
@@ -23059,7 +23578,7 @@ class View {
|
|
|
23059
23578
|
? this.updateLimboDocuments()
|
|
23060
23579
|
: [];
|
|
23061
23580
|
const synced = this.limboDocuments.size === 0 && this.current;
|
|
23062
|
-
const newSyncState = synced ? 1 /* Synced */ : 0 /* Local */;
|
|
23581
|
+
const newSyncState = synced ? 1 /* SyncState.Synced */ : 0 /* SyncState.Local */;
|
|
23063
23582
|
const syncStateChanged = newSyncState !== this.syncState;
|
|
23064
23583
|
this.syncState = newSyncState;
|
|
23065
23584
|
if (changes.length === 0 && !syncStateChanged) {
|
|
@@ -23067,7 +23586,7 @@ class View {
|
|
|
23067
23586
|
return { limboChanges };
|
|
23068
23587
|
}
|
|
23069
23588
|
else {
|
|
23070
|
-
const snap = new ViewSnapshot(this.query, docChanges.documentSet, oldDocs, changes, docChanges.mutatedKeys, newSyncState === 0 /* Local */, syncStateChanged,
|
|
23589
|
+
const snap = new ViewSnapshot(this.query, docChanges.documentSet, oldDocs, changes, docChanges.mutatedKeys, newSyncState === 0 /* SyncState.Local */, syncStateChanged,
|
|
23071
23590
|
/* excludesMetadataChanges= */ false, targetChange
|
|
23072
23591
|
? targetChange.resumeToken.approximateByteSize() > 0
|
|
23073
23592
|
: false);
|
|
@@ -23082,7 +23601,7 @@ class View {
|
|
|
23082
23601
|
* ViewChange if the view's syncState changes as a result.
|
|
23083
23602
|
*/
|
|
23084
23603
|
applyOnlineStateChange(onlineState) {
|
|
23085
|
-
if (this.current && onlineState === "Offline" /* Offline */) {
|
|
23604
|
+
if (this.current && onlineState === "Offline" /* OnlineState.Offline */) {
|
|
23086
23605
|
// If we're offline, set `current` to false and then call applyChanges()
|
|
23087
23606
|
// to refresh our syncState and generate a ViewChange as appropriate. We
|
|
23088
23607
|
// are guaranteed to get a new TargetChange that sets `current` back to
|
|
@@ -23197,22 +23716,22 @@ class View {
|
|
|
23197
23716
|
*/
|
|
23198
23717
|
// PORTING NOTE: Multi-tab only.
|
|
23199
23718
|
computeInitialSnapshot() {
|
|
23200
|
-
return ViewSnapshot.fromInitialDocuments(this.query, this.documentSet, this.mutatedKeys, this.syncState === 0 /* Local */, this.hasCachedResults);
|
|
23719
|
+
return ViewSnapshot.fromInitialDocuments(this.query, this.documentSet, this.mutatedKeys, this.syncState === 0 /* SyncState.Local */, this.hasCachedResults);
|
|
23201
23720
|
}
|
|
23202
23721
|
}
|
|
23203
23722
|
function compareChangeType(c1, c2) {
|
|
23204
23723
|
const order = (change) => {
|
|
23205
23724
|
switch (change) {
|
|
23206
|
-
case 0 /* Added */:
|
|
23725
|
+
case 0 /* ChangeType.Added */:
|
|
23207
23726
|
return 1;
|
|
23208
|
-
case 2 /* Modified */:
|
|
23727
|
+
case 2 /* ChangeType.Modified */:
|
|
23209
23728
|
return 2;
|
|
23210
|
-
case 3 /* Metadata */:
|
|
23729
|
+
case 3 /* ChangeType.Metadata */:
|
|
23211
23730
|
// A metadata change is converted to a modified change at the public
|
|
23212
23731
|
// api layer. Since we sort by document key and then change type,
|
|
23213
23732
|
// metadata and modified changes must be sorted equivalently.
|
|
23214
23733
|
return 2;
|
|
23215
|
-
case 1 /* Removed */:
|
|
23734
|
+
case 1 /* ChangeType.Removed */:
|
|
23216
23735
|
return 0;
|
|
23217
23736
|
default:
|
|
23218
23737
|
return fail();
|
|
@@ -23330,7 +23849,7 @@ class SyncEngineImpl {
|
|
|
23330
23849
|
/** Stores user callbacks waiting for all pending writes to be acknowledged. */
|
|
23331
23850
|
this.pendingWritesCallbacks = new Map();
|
|
23332
23851
|
this.limboTargetIdGenerator = TargetIdGenerator.forSyncEngine();
|
|
23333
|
-
this.onlineState = "Unknown" /* Unknown */;
|
|
23852
|
+
this.onlineState = "Unknown" /* OnlineState.Unknown */;
|
|
23334
23853
|
// The primary state is set to `true` or `false` immediately after Firestore
|
|
23335
23854
|
// startup. In the interim, a client should only be considered primary if
|
|
23336
23855
|
// `isPrimary` is true.
|
|
@@ -23394,7 +23913,7 @@ async function initializeViewAndComputeSnapshot(syncEngineImpl, query, targetId,
|
|
|
23394
23913
|
/* usePreviousResults= */ true);
|
|
23395
23914
|
const view = new View(query, queryResult.remoteKeys);
|
|
23396
23915
|
const viewDocChanges = view.computeDocChanges(queryResult.documents);
|
|
23397
|
-
const synthesizedTargetChange = TargetChange.createSynthesizedTargetChangeForCurrentChange(targetId, current && syncEngineImpl.onlineState !== "Offline" /* Offline */, resumeToken);
|
|
23916
|
+
const synthesizedTargetChange = TargetChange.createSynthesizedTargetChangeForCurrentChange(targetId, current && syncEngineImpl.onlineState !== "Offline" /* OnlineState.Offline */, resumeToken);
|
|
23398
23917
|
const viewChange = view.applyChanges(viewDocChanges,
|
|
23399
23918
|
/* updateLimboDocuments= */ syncEngineImpl.isPrimaryClient, synthesizedTargetChange);
|
|
23400
23919
|
updateTrackedLimbos(syncEngineImpl, targetId, viewChange.limboChanges);
|
|
@@ -23520,9 +24039,9 @@ function syncEngineApplyOnlineStateChange(syncEngine, onlineState, source) {
|
|
|
23520
24039
|
// tab remains online) and only apply the primary tab's online state from
|
|
23521
24040
|
// SharedClientState.
|
|
23522
24041
|
if ((syncEngineImpl.isPrimaryClient &&
|
|
23523
|
-
source === 0 /* RemoteStore */) ||
|
|
24042
|
+
source === 0 /* OnlineStateSource.RemoteStore */) ||
|
|
23524
24043
|
(!syncEngineImpl.isPrimaryClient &&
|
|
23525
|
-
source === 1 /* SharedClientState */)) {
|
|
24044
|
+
source === 1 /* OnlineStateSource.SharedClientState */)) {
|
|
23526
24045
|
const newViewSnapshots = [];
|
|
23527
24046
|
syncEngineImpl.queryViewsByQuery.forEach((query, queryView) => {
|
|
23528
24047
|
const viewChange = queryView.view.applyOnlineStateChange(onlineState);
|
|
@@ -23790,7 +24309,7 @@ function pumpEnqueuedLimboResolutions(syncEngineImpl) {
|
|
|
23790
24309
|
syncEngineImpl.activeLimboResolutionsByTarget.set(limboTargetId, new LimboResolution(key));
|
|
23791
24310
|
syncEngineImpl.activeLimboTargetsByKey =
|
|
23792
24311
|
syncEngineImpl.activeLimboTargetsByKey.insert(key, limboTargetId);
|
|
23793
|
-
remoteStoreListen(syncEngineImpl.remoteStore, new TargetData(queryToTarget(newQueryForPath(key.path)), limboTargetId, 2 /* LimboResolution */, ListenSequence.INVALID));
|
|
24312
|
+
remoteStoreListen(syncEngineImpl.remoteStore, new TargetData(queryToTarget(newQueryForPath(key.path)), limboTargetId, 2 /* TargetPurpose.LimboResolution */, ListenSequence.INVALID));
|
|
23794
24313
|
}
|
|
23795
24314
|
}
|
|
23796
24315
|
async function syncEngineEmitNewSnapsAndNotifyLocalStore(syncEngine, changes, remoteEvent) {
|
|
@@ -24043,7 +24562,7 @@ async function synchronizeQueryViewsAndRaiseSnapshots(syncEngine, targets, trans
|
|
|
24043
24562
|
*/
|
|
24044
24563
|
// PORTING NOTE: Multi-Tab only.
|
|
24045
24564
|
function synthesizeTargetToQuery(target) {
|
|
24046
|
-
return newQuery(target.path, target.collectionGroup, target.orderBy, target.filters, target.limit, "F" /* First */, target.startAt, target.endAt);
|
|
24565
|
+
return newQuery(target.path, target.collectionGroup, target.orderBy, target.filters, target.limit, "F" /* LimitType.First */, target.startAt, target.endAt);
|
|
24047
24566
|
}
|
|
24048
24567
|
/** Returns the IDs of the clients that are currently active. */
|
|
24049
24568
|
// PORTING NOTE: Multi-Tab only.
|
|
@@ -24374,7 +24893,7 @@ class OnlineComponentProvider {
|
|
|
24374
24893
|
this.eventManager = this.createEventManager(cfg);
|
|
24375
24894
|
this.syncEngine = this.createSyncEngine(cfg,
|
|
24376
24895
|
/* startAsPrimary=*/ !offlineComponentProvider.synchronizeTabs);
|
|
24377
|
-
this.sharedClientState.onlineStateHandler = onlineState => syncEngineApplyOnlineStateChange(this.syncEngine, onlineState, 1 /* SharedClientState */);
|
|
24896
|
+
this.sharedClientState.onlineStateHandler = onlineState => syncEngineApplyOnlineStateChange(this.syncEngine, onlineState, 1 /* OnlineStateSource.SharedClientState */);
|
|
24378
24897
|
this.remoteStore.remoteSyncer.handleCredentialChange =
|
|
24379
24898
|
syncEngineHandleCredentialChange.bind(null, this.syncEngine);
|
|
24380
24899
|
await remoteStoreApplyPrimaryState(this.remoteStore, this.syncEngine.isPrimaryClient);
|
|
@@ -24388,7 +24907,7 @@ class OnlineComponentProvider {
|
|
|
24388
24907
|
return newDatastore(cfg.authCredentials, cfg.appCheckCredentials, connection, serializer);
|
|
24389
24908
|
}
|
|
24390
24909
|
createRemoteStore(cfg) {
|
|
24391
|
-
return newRemoteStore(this.localStore, this.datastore, cfg.asyncQueue, onlineState => syncEngineApplyOnlineStateChange(this.syncEngine, onlineState, 0 /* RemoteStore */), newConnectivityMonitor());
|
|
24910
|
+
return newRemoteStore(this.localStore, this.datastore, cfg.asyncQueue, onlineState => syncEngineApplyOnlineStateChange(this.syncEngine, onlineState, 0 /* OnlineStateSource.RemoteStore */), newConnectivityMonitor());
|
|
24392
24911
|
}
|
|
24393
24912
|
createSyncEngine(cfg, startAsPrimary) {
|
|
24394
24913
|
return newSyncEngine(this.localStore, this.remoteStore, this.eventManager, this.sharedClientState, cfg.initialUser, cfg.maxConcurrentLimboResolutions, startAsPrimary);
|
|
@@ -25145,7 +25664,7 @@ class TransactionRunner {
|
|
|
25145
25664
|
this.updateFunction = updateFunction;
|
|
25146
25665
|
this.deferred = deferred;
|
|
25147
25666
|
this.attemptsRemaining = options.maxAttempts;
|
|
25148
|
-
this.backoff = new ExponentialBackoff(this.asyncQueue, "transaction_retry" /* TransactionRetry */);
|
|
25667
|
+
this.backoff = new ExponentialBackoff(this.asyncQueue, "transaction_retry" /* TimerId.TransactionRetry */);
|
|
25149
25668
|
}
|
|
25150
25669
|
/** Runs the transaction and sets the result on deferred. */
|
|
25151
25670
|
run() {
|
|
@@ -26178,7 +26697,7 @@ class AsyncQueueImpl {
|
|
|
26178
26697
|
// List of TimerIds to fast-forward delays for.
|
|
26179
26698
|
this.timerIdsToSkip = [];
|
|
26180
26699
|
// Backoff timer used to schedule retries for retryable operations
|
|
26181
|
-
this.backoff = new ExponentialBackoff(this, "async_queue_retry" /* AsyncQueueRetry */);
|
|
26700
|
+
this.backoff = new ExponentialBackoff(this, "async_queue_retry" /* TimerId.AsyncQueueRetry */);
|
|
26182
26701
|
// Visibility handler that triggers an immediate retry of all retryable
|
|
26183
26702
|
// operations. Meant to speed up recovery when we regain file system access
|
|
26184
26703
|
// after page comes into foreground.
|
|
@@ -26348,7 +26867,7 @@ class AsyncQueueImpl {
|
|
|
26348
26867
|
this.delayedOperations.sort((a, b) => a.targetTimeMs - b.targetTimeMs);
|
|
26349
26868
|
for (const op of this.delayedOperations) {
|
|
26350
26869
|
op.skipDelay();
|
|
26351
|
-
if (lastTimerId !== "all" /* All */ && op.timerId === lastTimerId) {
|
|
26870
|
+
if (lastTimerId !== "all" /* TimerId.All */ && op.timerId === lastTimerId) {
|
|
26352
26871
|
break;
|
|
26353
26872
|
}
|
|
26354
26873
|
}
|
|
@@ -27261,12 +27780,12 @@ class ParsedUpdateData {
|
|
|
27261
27780
|
}
|
|
27262
27781
|
function isWrite(dataSource) {
|
|
27263
27782
|
switch (dataSource) {
|
|
27264
|
-
case 0 /* Set */: // fall through
|
|
27265
|
-
case 2 /* MergeSet */: // fall through
|
|
27266
|
-
case 1 /* Update */:
|
|
27783
|
+
case 0 /* UserDataSource.Set */: // fall through
|
|
27784
|
+
case 2 /* UserDataSource.MergeSet */: // fall through
|
|
27785
|
+
case 1 /* UserDataSource.Update */:
|
|
27267
27786
|
return true;
|
|
27268
|
-
case 3 /* Argument */:
|
|
27269
|
-
case 4 /* ArrayArgument */:
|
|
27787
|
+
case 3 /* UserDataSource.Argument */:
|
|
27788
|
+
case 4 /* UserDataSource.ArrayArgument */:
|
|
27270
27789
|
return false;
|
|
27271
27790
|
default:
|
|
27272
27791
|
throw fail();
|
|
@@ -27391,8 +27910,8 @@ function newUserDataReader(firestore) {
|
|
|
27391
27910
|
/** Parse document data from a set() call. */
|
|
27392
27911
|
function parseSetData(userDataReader, methodName, targetDoc, input, hasConverter, options = {}) {
|
|
27393
27912
|
const context = userDataReader.createContext(options.merge || options.mergeFields
|
|
27394
|
-
? 2 /* MergeSet */
|
|
27395
|
-
: 0 /* Set */, methodName, targetDoc, hasConverter);
|
|
27913
|
+
? 2 /* UserDataSource.MergeSet */
|
|
27914
|
+
: 0 /* UserDataSource.Set */, methodName, targetDoc, hasConverter);
|
|
27396
27915
|
validatePlainObject('Data must be an object, but it was:', context, input);
|
|
27397
27916
|
const updateData = parseObject(input, context);
|
|
27398
27917
|
let fieldMask;
|
|
@@ -27423,12 +27942,12 @@ function parseSetData(userDataReader, methodName, targetDoc, input, hasConverter
|
|
|
27423
27942
|
}
|
|
27424
27943
|
class DeleteFieldValueImpl extends FieldValue {
|
|
27425
27944
|
_toFieldTransform(context) {
|
|
27426
|
-
if (context.dataSource === 2 /* MergeSet */) {
|
|
27945
|
+
if (context.dataSource === 2 /* UserDataSource.MergeSet */) {
|
|
27427
27946
|
// No transform to add for a delete, but we need to add it to our
|
|
27428
27947
|
// fieldMask so it gets deleted.
|
|
27429
27948
|
context.fieldMask.push(context.path);
|
|
27430
27949
|
}
|
|
27431
|
-
else if (context.dataSource === 1 /* Update */) {
|
|
27950
|
+
else if (context.dataSource === 1 /* UserDataSource.Update */) {
|
|
27432
27951
|
throw context.createError(`${this._methodName}() can only appear at the top level ` +
|
|
27433
27952
|
'of your update data');
|
|
27434
27953
|
}
|
|
@@ -27461,7 +27980,7 @@ class DeleteFieldValueImpl extends FieldValue {
|
|
|
27461
27980
|
*/
|
|
27462
27981
|
function createSentinelChildContext(fieldValue, context, arrayElement) {
|
|
27463
27982
|
return new ParseContextImpl({
|
|
27464
|
-
dataSource: 3 /* Argument */,
|
|
27983
|
+
dataSource: 3 /* UserDataSource.Argument */,
|
|
27465
27984
|
targetDoc: context.settings.targetDoc,
|
|
27466
27985
|
methodName: fieldValue._methodName,
|
|
27467
27986
|
arrayElement
|
|
@@ -27525,7 +28044,7 @@ class NumericIncrementFieldValueImpl extends FieldValue {
|
|
|
27525
28044
|
}
|
|
27526
28045
|
/** Parse update data from an update() call. */
|
|
27527
28046
|
function parseUpdateData(userDataReader, methodName, targetDoc, input) {
|
|
27528
|
-
const context = userDataReader.createContext(1 /* Update */, methodName, targetDoc);
|
|
28047
|
+
const context = userDataReader.createContext(1 /* UserDataSource.Update */, methodName, targetDoc);
|
|
27529
28048
|
validatePlainObject('Data must be an object, but it was:', context, input);
|
|
27530
28049
|
const fieldMaskPaths = [];
|
|
27531
28050
|
const updateData = ObjectValue.empty();
|
|
@@ -27552,7 +28071,7 @@ function parseUpdateData(userDataReader, methodName, targetDoc, input) {
|
|
|
27552
28071
|
}
|
|
27553
28072
|
/** Parse update data from a list of field/value arguments. */
|
|
27554
28073
|
function parseUpdateVarargs(userDataReader, methodName, targetDoc, field, value, moreFieldsAndValues) {
|
|
27555
|
-
const context = userDataReader.createContext(1 /* Update */, methodName, targetDoc);
|
|
28074
|
+
const context = userDataReader.createContext(1 /* UserDataSource.Update */, methodName, targetDoc);
|
|
27556
28075
|
const keys = [fieldPathFromArgument$1(methodName, field, targetDoc)];
|
|
27557
28076
|
const values = [value];
|
|
27558
28077
|
if (moreFieldsAndValues.length % 2 !== 0) {
|
|
@@ -27599,7 +28118,7 @@ function parseUpdateVarargs(userDataReader, methodName, targetDoc, field, value,
|
|
|
27599
28118
|
* contain additional arrays (e.g. the operand of an `in` query).
|
|
27600
28119
|
*/
|
|
27601
28120
|
function parseQueryValue(userDataReader, methodName, input, allowArrays = false) {
|
|
27602
|
-
const context = userDataReader.createContext(allowArrays ? 4 /* ArrayArgument */ : 3 /* Argument */, methodName);
|
|
28121
|
+
const context = userDataReader.createContext(allowArrays ? 4 /* UserDataSource.ArrayArgument */ : 3 /* UserDataSource.Argument */, methodName);
|
|
27603
28122
|
const parsed = parseData(input, context);
|
|
27604
28123
|
return parsed;
|
|
27605
28124
|
}
|
|
@@ -27649,7 +28168,7 @@ function parseData(input, context) {
|
|
|
27649
28168
|
// contain additional arrays (each representing an individual field
|
|
27650
28169
|
// value), so we disable this validation.
|
|
27651
28170
|
if (context.settings.arrayElement &&
|
|
27652
|
-
context.dataSource !== 4 /* ArrayArgument */) {
|
|
28171
|
+
context.dataSource !== 4 /* UserDataSource.ArrayArgument */) {
|
|
27653
28172
|
throw context.createError('Nested arrays are not supported');
|
|
27654
28173
|
}
|
|
27655
28174
|
return parseArray(input, context);
|
|
@@ -28031,164 +28550,334 @@ function fieldPathFromArgument(methodName, arg) {
|
|
|
28031
28550
|
* limitations under the License.
|
|
28032
28551
|
*/
|
|
28033
28552
|
function validateHasExplicitOrderByForLimitToLast(query) {
|
|
28034
|
-
if (query.limitType === "L" /* Last */ &&
|
|
28553
|
+
if (query.limitType === "L" /* LimitType.Last */ &&
|
|
28035
28554
|
query.explicitOrderBy.length === 0) {
|
|
28036
28555
|
throw new FirestoreError(Code.UNIMPLEMENTED, 'limitToLast() queries require specifying at least one orderBy() clause');
|
|
28037
28556
|
}
|
|
28038
28557
|
}
|
|
28558
|
+
/**
|
|
28559
|
+
* An `AppliableConstraint` is an abstraction of a constraint that can be applied
|
|
28560
|
+
* to a Firestore query.
|
|
28561
|
+
*/
|
|
28562
|
+
class AppliableConstraint {
|
|
28563
|
+
}
|
|
28039
28564
|
/**
|
|
28040
28565
|
* A `QueryConstraint` is used to narrow the set of documents returned by a
|
|
28041
28566
|
* Firestore query. `QueryConstraint`s are created by invoking {@link where},
|
|
28042
|
-
* {@link orderBy}, {@link
|
|
28043
|
-
* endBefore
|
|
28567
|
+
* {@link orderBy}, {@link startAt}, {@link startAfter}, {@link
|
|
28568
|
+
* endBefore}, {@link endAt}, {@link limit}, {@link limitToLast} and
|
|
28044
28569
|
* can then be passed to {@link query} to create a new query instance that
|
|
28045
28570
|
* also contains this `QueryConstraint`.
|
|
28046
28571
|
*/
|
|
28047
|
-
class QueryConstraint {
|
|
28572
|
+
class QueryConstraint extends AppliableConstraint {
|
|
28048
28573
|
}
|
|
28049
|
-
|
|
28050
|
-
|
|
28051
|
-
|
|
28052
|
-
|
|
28053
|
-
|
|
28054
|
-
|
|
28055
|
-
|
|
28056
|
-
* existing or new constraints.
|
|
28057
|
-
*/
|
|
28058
|
-
function query(query, ...queryConstraints) {
|
|
28574
|
+
function query(query, queryConstraint, ...additionalQueryConstraints) {
|
|
28575
|
+
let queryConstraints = [];
|
|
28576
|
+
if (queryConstraint instanceof AppliableConstraint) {
|
|
28577
|
+
queryConstraints.push(queryConstraint);
|
|
28578
|
+
}
|
|
28579
|
+
queryConstraints = queryConstraints.concat(additionalQueryConstraints);
|
|
28580
|
+
validateQueryConstraintArray(queryConstraints);
|
|
28059
28581
|
for (const constraint of queryConstraints) {
|
|
28060
28582
|
query = constraint._apply(query);
|
|
28061
28583
|
}
|
|
28062
28584
|
return query;
|
|
28063
28585
|
}
|
|
28064
|
-
|
|
28586
|
+
/**
|
|
28587
|
+
* A `QueryFieldFilterConstraint` is used to narrow the set of documents returned by
|
|
28588
|
+
* a Firestore query by filtering on one or more document fields.
|
|
28589
|
+
* `QueryFieldFilterConstraint`s are created by invoking {@link where} and can then
|
|
28590
|
+
* be passed to {@link query} to create a new query instance that also contains
|
|
28591
|
+
* this `QueryFieldFilterConstraint`.
|
|
28592
|
+
*/
|
|
28593
|
+
class QueryFieldFilterConstraint extends QueryConstraint {
|
|
28594
|
+
/**
|
|
28595
|
+
* @internal
|
|
28596
|
+
*/
|
|
28065
28597
|
constructor(_field, _op, _value) {
|
|
28066
28598
|
super();
|
|
28067
28599
|
this._field = _field;
|
|
28068
28600
|
this._op = _op;
|
|
28069
28601
|
this._value = _value;
|
|
28602
|
+
/** The type of this query constraint */
|
|
28070
28603
|
this.type = 'where';
|
|
28071
28604
|
}
|
|
28605
|
+
static _create(_field, _op, _value) {
|
|
28606
|
+
return new QueryFieldFilterConstraint(_field, _op, _value);
|
|
28607
|
+
}
|
|
28072
28608
|
_apply(query) {
|
|
28609
|
+
const filter = this._parse(query);
|
|
28610
|
+
validateNewFieldFilter(query._query, filter);
|
|
28611
|
+
return new Query(query.firestore, query.converter, queryWithAddedFilter(query._query, filter));
|
|
28612
|
+
}
|
|
28613
|
+
_parse(query) {
|
|
28073
28614
|
const reader = newUserDataReader(query.firestore);
|
|
28074
28615
|
const filter = newQueryFilter(query._query, 'where', reader, query.firestore._databaseId, this._field, this._op, this._value);
|
|
28075
|
-
return
|
|
28616
|
+
return filter;
|
|
28076
28617
|
}
|
|
28077
28618
|
}
|
|
28078
28619
|
/**
|
|
28079
|
-
* Creates a {@link
|
|
28080
|
-
* specified field and that the value should satisfy the
|
|
28081
|
-
* provided.
|
|
28620
|
+
* Creates a {@link QueryFieldFilterConstraint} that enforces that documents
|
|
28621
|
+
* must contain the specified field and that the value should satisfy the
|
|
28622
|
+
* relation constraint provided.
|
|
28082
28623
|
*
|
|
28083
28624
|
* @param fieldPath - The path to compare
|
|
28084
28625
|
* @param opStr - The operation string (e.g "<", "<=", "==", "<",
|
|
28085
28626
|
* "<=", "!=").
|
|
28086
28627
|
* @param value - The value for comparison
|
|
28087
|
-
* @returns The created {@link
|
|
28628
|
+
* @returns The created {@link QueryFieldFilterConstraint}.
|
|
28088
28629
|
*/
|
|
28089
28630
|
function where(fieldPath, opStr, value) {
|
|
28090
28631
|
const op = opStr;
|
|
28091
28632
|
const field = fieldPathFromArgument('where', fieldPath);
|
|
28092
|
-
return
|
|
28633
|
+
return QueryFieldFilterConstraint._create(field, op, value);
|
|
28634
|
+
}
|
|
28635
|
+
/**
|
|
28636
|
+
* A `QueryCompositeFilterConstraint` is used to narrow the set of documents
|
|
28637
|
+
* returned by a Firestore query by performing the logical OR or AND of multiple
|
|
28638
|
+
* {@link QueryFieldFilterConstraint}s or {@link QueryCompositeFilterConstraint}s.
|
|
28639
|
+
* `QueryCompositeFilterConstraint`s are created by invoking {@link or} or
|
|
28640
|
+
* {@link and} and can then be passed to {@link query} to create a new query
|
|
28641
|
+
* instance that also contains the `QueryCompositeFilterConstraint`.
|
|
28642
|
+
* @internal TODO remove this internal tag with OR Query support in the server
|
|
28643
|
+
*/
|
|
28644
|
+
class QueryCompositeFilterConstraint extends AppliableConstraint {
|
|
28645
|
+
/**
|
|
28646
|
+
* @internal
|
|
28647
|
+
*/
|
|
28648
|
+
constructor(
|
|
28649
|
+
/** The type of this query constraint */
|
|
28650
|
+
type, _queryConstraints) {
|
|
28651
|
+
super();
|
|
28652
|
+
this.type = type;
|
|
28653
|
+
this._queryConstraints = _queryConstraints;
|
|
28654
|
+
}
|
|
28655
|
+
static _create(type, _queryConstraints) {
|
|
28656
|
+
return new QueryCompositeFilterConstraint(type, _queryConstraints);
|
|
28657
|
+
}
|
|
28658
|
+
_parse(query) {
|
|
28659
|
+
const parsedFilters = this._queryConstraints
|
|
28660
|
+
.map(queryConstraint => {
|
|
28661
|
+
return queryConstraint._parse(query);
|
|
28662
|
+
})
|
|
28663
|
+
.filter(parsedFilter => parsedFilter.getFilters().length > 0);
|
|
28664
|
+
if (parsedFilters.length === 1) {
|
|
28665
|
+
return parsedFilters[0];
|
|
28666
|
+
}
|
|
28667
|
+
return CompositeFilter.create(parsedFilters, this._getOperator());
|
|
28668
|
+
}
|
|
28669
|
+
_apply(query) {
|
|
28670
|
+
const parsedFilter = this._parse(query);
|
|
28671
|
+
if (parsedFilter.getFilters().length === 0) {
|
|
28672
|
+
// Return the existing query if not adding any more filters (e.g. an empty
|
|
28673
|
+
// composite filter).
|
|
28674
|
+
return query;
|
|
28675
|
+
}
|
|
28676
|
+
validateNewFilter(query._query, parsedFilter);
|
|
28677
|
+
return new Query(query.firestore, query.converter, queryWithAddedFilter(query._query, parsedFilter));
|
|
28678
|
+
}
|
|
28679
|
+
_getQueryConstraints() {
|
|
28680
|
+
return this._queryConstraints;
|
|
28681
|
+
}
|
|
28682
|
+
_getOperator() {
|
|
28683
|
+
return this.type === 'and' ? "and" /* CompositeOperator.AND */ : "or" /* CompositeOperator.OR */;
|
|
28684
|
+
}
|
|
28685
|
+
}
|
|
28686
|
+
/**
|
|
28687
|
+
* Creates a {@link QueryCompositeFilterConstraint} that performs a logical OR
|
|
28688
|
+
* of all the provided {@link QueryFilterConstraint}s.
|
|
28689
|
+
*
|
|
28690
|
+
* @param queryConstraints - Optional. The {@link QueryFilterConstraint}s
|
|
28691
|
+
* for OR operation. These must be created with calls to {@link where},
|
|
28692
|
+
* {@link or}, or {@link and}.
|
|
28693
|
+
* @returns The created {@link QueryCompositeFilterConstraint}.
|
|
28694
|
+
* @internal TODO remove this internal tag with OR Query support in the server
|
|
28695
|
+
*/
|
|
28696
|
+
function or(...queryConstraints) {
|
|
28697
|
+
// Only support QueryFilterConstraints
|
|
28698
|
+
queryConstraints.forEach(queryConstraint => validateQueryFilterConstraint('or', queryConstraint));
|
|
28699
|
+
return QueryCompositeFilterConstraint._create("or" /* CompositeOperator.OR */, queryConstraints);
|
|
28700
|
+
}
|
|
28701
|
+
/**
|
|
28702
|
+
* Creates a {@link QueryCompositeFilterConstraint} that performs a logical AND
|
|
28703
|
+
* of all the provided {@link QueryFilterConstraint}s.
|
|
28704
|
+
*
|
|
28705
|
+
* @param queryConstraints - Optional. The {@link QueryFilterConstraint}s
|
|
28706
|
+
* for AND operation. These must be created with calls to {@link where},
|
|
28707
|
+
* {@link or}, or {@link and}.
|
|
28708
|
+
* @returns The created {@link QueryCompositeFilterConstraint}.
|
|
28709
|
+
* @internal TODO remove this internal tag with OR Query support in the server
|
|
28710
|
+
*/
|
|
28711
|
+
function and(...queryConstraints) {
|
|
28712
|
+
// Only support QueryFilterConstraints
|
|
28713
|
+
queryConstraints.forEach(queryConstraint => validateQueryFilterConstraint('and', queryConstraint));
|
|
28714
|
+
return QueryCompositeFilterConstraint._create("and" /* CompositeOperator.AND */, queryConstraints);
|
|
28093
28715
|
}
|
|
28716
|
+
/**
|
|
28717
|
+
* A `QueryOrderByConstraint` is used to sort the set of documents returned by a
|
|
28718
|
+
* Firestore query. `QueryOrderByConstraint`s are created by invoking
|
|
28719
|
+
* {@link orderBy} and can then be passed to {@link query} to create a new query
|
|
28720
|
+
* instance that also contains this `QueryOrderByConstraint`.
|
|
28721
|
+
*
|
|
28722
|
+
* Note: Documents that do not contain the orderBy field will not be present in
|
|
28723
|
+
* the query result.
|
|
28724
|
+
*/
|
|
28094
28725
|
class QueryOrderByConstraint extends QueryConstraint {
|
|
28726
|
+
/**
|
|
28727
|
+
* @internal
|
|
28728
|
+
*/
|
|
28095
28729
|
constructor(_field, _direction) {
|
|
28096
28730
|
super();
|
|
28097
28731
|
this._field = _field;
|
|
28098
28732
|
this._direction = _direction;
|
|
28733
|
+
/** The type of this query constraint */
|
|
28099
28734
|
this.type = 'orderBy';
|
|
28100
28735
|
}
|
|
28736
|
+
static _create(_field, _direction) {
|
|
28737
|
+
return new QueryOrderByConstraint(_field, _direction);
|
|
28738
|
+
}
|
|
28101
28739
|
_apply(query) {
|
|
28102
28740
|
const orderBy = newQueryOrderBy(query._query, this._field, this._direction);
|
|
28103
28741
|
return new Query(query.firestore, query.converter, queryWithAddedOrderBy(query._query, orderBy));
|
|
28104
28742
|
}
|
|
28105
28743
|
}
|
|
28106
28744
|
/**
|
|
28107
|
-
* Creates a {@link
|
|
28745
|
+
* Creates a {@link QueryOrderByConstraint} that sorts the query result by the
|
|
28108
28746
|
* specified field, optionally in descending order instead of ascending.
|
|
28109
28747
|
*
|
|
28748
|
+
* Note: Documents that do not contain the specified field will not be present
|
|
28749
|
+
* in the query result.
|
|
28750
|
+
*
|
|
28110
28751
|
* @param fieldPath - The field to sort by.
|
|
28111
28752
|
* @param directionStr - Optional direction to sort by ('asc' or 'desc'). If
|
|
28112
28753
|
* not specified, order will be ascending.
|
|
28113
|
-
* @returns The created {@link
|
|
28754
|
+
* @returns The created {@link QueryOrderByConstraint}.
|
|
28114
28755
|
*/
|
|
28115
28756
|
function orderBy(fieldPath, directionStr = 'asc') {
|
|
28116
28757
|
const direction = directionStr;
|
|
28117
28758
|
const path = fieldPathFromArgument('orderBy', fieldPath);
|
|
28118
|
-
return
|
|
28759
|
+
return QueryOrderByConstraint._create(path, direction);
|
|
28119
28760
|
}
|
|
28761
|
+
/**
|
|
28762
|
+
* A `QueryLimitConstraint` is used to limit the number of documents returned by
|
|
28763
|
+
* a Firestore query.
|
|
28764
|
+
* `QueryLimitConstraint`s are created by invoking {@link limit} or
|
|
28765
|
+
* {@link limitToLast} and can then be passed to {@link query} to create a new
|
|
28766
|
+
* query instance that also contains this `QueryLimitConstraint`.
|
|
28767
|
+
*/
|
|
28120
28768
|
class QueryLimitConstraint extends QueryConstraint {
|
|
28121
|
-
|
|
28769
|
+
/**
|
|
28770
|
+
* @internal
|
|
28771
|
+
*/
|
|
28772
|
+
constructor(
|
|
28773
|
+
/** The type of this query constraint */
|
|
28774
|
+
type, _limit, _limitType) {
|
|
28122
28775
|
super();
|
|
28123
28776
|
this.type = type;
|
|
28124
28777
|
this._limit = _limit;
|
|
28125
28778
|
this._limitType = _limitType;
|
|
28126
28779
|
}
|
|
28780
|
+
static _create(type, _limit, _limitType) {
|
|
28781
|
+
return new QueryLimitConstraint(type, _limit, _limitType);
|
|
28782
|
+
}
|
|
28127
28783
|
_apply(query) {
|
|
28128
28784
|
return new Query(query.firestore, query.converter, queryWithLimit(query._query, this._limit, this._limitType));
|
|
28129
28785
|
}
|
|
28130
28786
|
}
|
|
28131
28787
|
/**
|
|
28132
|
-
* Creates a {@link
|
|
28788
|
+
* Creates a {@link QueryLimitConstraint} that only returns the first matching
|
|
28789
|
+
* documents.
|
|
28133
28790
|
*
|
|
28134
28791
|
* @param limit - The maximum number of items to return.
|
|
28135
|
-
* @returns The created {@link
|
|
28792
|
+
* @returns The created {@link QueryLimitConstraint}.
|
|
28136
28793
|
*/
|
|
28137
28794
|
function limit(limit) {
|
|
28138
28795
|
validatePositiveNumber('limit', limit);
|
|
28139
|
-
return
|
|
28796
|
+
return QueryLimitConstraint._create('limit', limit, "F" /* LimitType.First */);
|
|
28140
28797
|
}
|
|
28141
28798
|
/**
|
|
28142
|
-
* Creates a {@link
|
|
28799
|
+
* Creates a {@link QueryLimitConstraint} that only returns the last matching
|
|
28800
|
+
* documents.
|
|
28143
28801
|
*
|
|
28144
28802
|
* You must specify at least one `orderBy` clause for `limitToLast` queries,
|
|
28145
28803
|
* otherwise an exception will be thrown during execution.
|
|
28146
28804
|
*
|
|
28147
28805
|
* @param limit - The maximum number of items to return.
|
|
28148
|
-
* @returns The created {@link
|
|
28806
|
+
* @returns The created {@link QueryLimitConstraint}.
|
|
28149
28807
|
*/
|
|
28150
28808
|
function limitToLast(limit) {
|
|
28151
28809
|
validatePositiveNumber('limitToLast', limit);
|
|
28152
|
-
return
|
|
28810
|
+
return QueryLimitConstraint._create('limitToLast', limit, "L" /* LimitType.Last */);
|
|
28153
28811
|
}
|
|
28812
|
+
/**
|
|
28813
|
+
* A `QueryStartAtConstraint` is used to exclude documents from the start of a
|
|
28814
|
+
* result set returned by a Firestore query.
|
|
28815
|
+
* `QueryStartAtConstraint`s are created by invoking {@link (startAt:1)} or
|
|
28816
|
+
* {@link (startAfter:1)} and can then be passed to {@link query} to create a
|
|
28817
|
+
* new query instance that also contains this `QueryStartAtConstraint`.
|
|
28818
|
+
*/
|
|
28154
28819
|
class QueryStartAtConstraint extends QueryConstraint {
|
|
28155
|
-
|
|
28820
|
+
/**
|
|
28821
|
+
* @internal
|
|
28822
|
+
*/
|
|
28823
|
+
constructor(
|
|
28824
|
+
/** The type of this query constraint */
|
|
28825
|
+
type, _docOrFields, _inclusive) {
|
|
28156
28826
|
super();
|
|
28157
28827
|
this.type = type;
|
|
28158
28828
|
this._docOrFields = _docOrFields;
|
|
28159
28829
|
this._inclusive = _inclusive;
|
|
28160
28830
|
}
|
|
28831
|
+
static _create(type, _docOrFields, _inclusive) {
|
|
28832
|
+
return new QueryStartAtConstraint(type, _docOrFields, _inclusive);
|
|
28833
|
+
}
|
|
28161
28834
|
_apply(query) {
|
|
28162
28835
|
const bound = newQueryBoundFromDocOrFields(query, this.type, this._docOrFields, this._inclusive);
|
|
28163
28836
|
return new Query(query.firestore, query.converter, queryWithStartAt(query._query, bound));
|
|
28164
28837
|
}
|
|
28165
28838
|
}
|
|
28166
28839
|
function startAt(...docOrFields) {
|
|
28167
|
-
return
|
|
28840
|
+
return QueryStartAtConstraint._create('startAt', docOrFields,
|
|
28168
28841
|
/*inclusive=*/ true);
|
|
28169
28842
|
}
|
|
28170
28843
|
function startAfter(...docOrFields) {
|
|
28171
|
-
return
|
|
28844
|
+
return QueryStartAtConstraint._create('startAfter', docOrFields,
|
|
28172
28845
|
/*inclusive=*/ false);
|
|
28173
28846
|
}
|
|
28847
|
+
/**
|
|
28848
|
+
* A `QueryEndAtConstraint` is used to exclude documents from the end of a
|
|
28849
|
+
* result set returned by a Firestore query.
|
|
28850
|
+
* `QueryEndAtConstraint`s are created by invoking {@link (endAt:1)} or
|
|
28851
|
+
* {@link (endBefore:1)} and can then be passed to {@link query} to create a new
|
|
28852
|
+
* query instance that also contains this `QueryEndAtConstraint`.
|
|
28853
|
+
*/
|
|
28174
28854
|
class QueryEndAtConstraint extends QueryConstraint {
|
|
28175
|
-
|
|
28855
|
+
/**
|
|
28856
|
+
* @internal
|
|
28857
|
+
*/
|
|
28858
|
+
constructor(
|
|
28859
|
+
/** The type of this query constraint */
|
|
28860
|
+
type, _docOrFields, _inclusive) {
|
|
28176
28861
|
super();
|
|
28177
28862
|
this.type = type;
|
|
28178
28863
|
this._docOrFields = _docOrFields;
|
|
28179
28864
|
this._inclusive = _inclusive;
|
|
28180
28865
|
}
|
|
28866
|
+
static _create(type, _docOrFields, _inclusive) {
|
|
28867
|
+
return new QueryEndAtConstraint(type, _docOrFields, _inclusive);
|
|
28868
|
+
}
|
|
28181
28869
|
_apply(query) {
|
|
28182
28870
|
const bound = newQueryBoundFromDocOrFields(query, this.type, this._docOrFields, this._inclusive);
|
|
28183
28871
|
return new Query(query.firestore, query.converter, queryWithEndAt(query._query, bound));
|
|
28184
28872
|
}
|
|
28185
28873
|
}
|
|
28186
28874
|
function endBefore(...docOrFields) {
|
|
28187
|
-
return
|
|
28875
|
+
return QueryEndAtConstraint._create('endBefore', docOrFields,
|
|
28188
28876
|
/*inclusive=*/ false);
|
|
28189
28877
|
}
|
|
28190
28878
|
function endAt(...docOrFields) {
|
|
28191
|
-
return
|
|
28879
|
+
return QueryEndAtConstraint._create('endAt', docOrFields,
|
|
28880
|
+
/*inclusive=*/ true);
|
|
28192
28881
|
}
|
|
28193
28882
|
/** Helper function to create a bound from a document or fields */
|
|
28194
28883
|
function newQueryBoundFromDocOrFields(query, methodName, docOrFields, inclusive) {
|
|
@@ -28204,10 +28893,10 @@ function newQueryBoundFromDocOrFields(query, methodName, docOrFields, inclusive)
|
|
|
28204
28893
|
function newQueryFilter(query, methodName, dataReader, databaseId, fieldPath, op, value) {
|
|
28205
28894
|
let fieldValue;
|
|
28206
28895
|
if (fieldPath.isKeyField()) {
|
|
28207
|
-
if (op === "array-contains" /* ARRAY_CONTAINS */ || op === "array-contains-any" /* ARRAY_CONTAINS_ANY */) {
|
|
28896
|
+
if (op === "array-contains" /* Operator.ARRAY_CONTAINS */ || op === "array-contains-any" /* Operator.ARRAY_CONTAINS_ANY */) {
|
|
28208
28897
|
throw new FirestoreError(Code.INVALID_ARGUMENT, `Invalid Query. You can't perform '${op}' queries on documentId().`);
|
|
28209
28898
|
}
|
|
28210
|
-
else if (op === "in" /* IN */ || op === "not-in" /* NOT_IN */) {
|
|
28899
|
+
else if (op === "in" /* Operator.IN */ || op === "not-in" /* Operator.NOT_IN */) {
|
|
28211
28900
|
validateDisjunctiveFilterElements(value, op);
|
|
28212
28901
|
const referenceList = [];
|
|
28213
28902
|
for (const arrayValue of value) {
|
|
@@ -28220,16 +28909,15 @@ function newQueryFilter(query, methodName, dataReader, databaseId, fieldPath, op
|
|
|
28220
28909
|
}
|
|
28221
28910
|
}
|
|
28222
28911
|
else {
|
|
28223
|
-
if (op === "in" /* IN */ ||
|
|
28224
|
-
op === "not-in" /* NOT_IN */ ||
|
|
28225
|
-
op === "array-contains-any" /* ARRAY_CONTAINS_ANY */) {
|
|
28912
|
+
if (op === "in" /* Operator.IN */ ||
|
|
28913
|
+
op === "not-in" /* Operator.NOT_IN */ ||
|
|
28914
|
+
op === "array-contains-any" /* Operator.ARRAY_CONTAINS_ANY */) {
|
|
28226
28915
|
validateDisjunctiveFilterElements(value, op);
|
|
28227
28916
|
}
|
|
28228
28917
|
fieldValue = parseQueryValue(dataReader, methodName, value,
|
|
28229
|
-
/* allowArrays= */ op === "in" /* IN */ || op === "not-in" /* NOT_IN */);
|
|
28918
|
+
/* allowArrays= */ op === "in" /* Operator.IN */ || op === "not-in" /* Operator.NOT_IN */);
|
|
28230
28919
|
}
|
|
28231
28920
|
const filter = FieldFilter.create(fieldPath, op, fieldValue);
|
|
28232
|
-
validateNewFilter(query, filter);
|
|
28233
28921
|
return filter;
|
|
28234
28922
|
}
|
|
28235
28923
|
function newQueryOrderBy(query, fieldPath, direction) {
|
|
@@ -28399,62 +29087,84 @@ function validateDisjunctiveFilterElements(value, operator) {
|
|
|
28399
29087
|
*/
|
|
28400
29088
|
function conflictingOps(op) {
|
|
28401
29089
|
switch (op) {
|
|
28402
|
-
case "!=" /* NOT_EQUAL */:
|
|
28403
|
-
return ["!=" /* NOT_EQUAL */, "not-in" /* NOT_IN */];
|
|
28404
|
-
case "array-contains" /* ARRAY_CONTAINS */:
|
|
29090
|
+
case "!=" /* Operator.NOT_EQUAL */:
|
|
29091
|
+
return ["!=" /* Operator.NOT_EQUAL */, "not-in" /* Operator.NOT_IN */];
|
|
29092
|
+
case "array-contains" /* Operator.ARRAY_CONTAINS */:
|
|
28405
29093
|
return [
|
|
28406
|
-
"array-contains" /* ARRAY_CONTAINS */,
|
|
28407
|
-
"array-contains-any" /* ARRAY_CONTAINS_ANY */,
|
|
28408
|
-
"not-in" /* NOT_IN */
|
|
29094
|
+
"array-contains" /* Operator.ARRAY_CONTAINS */,
|
|
29095
|
+
"array-contains-any" /* Operator.ARRAY_CONTAINS_ANY */,
|
|
29096
|
+
"not-in" /* Operator.NOT_IN */
|
|
28409
29097
|
];
|
|
28410
|
-
case "in" /* IN */:
|
|
28411
|
-
return ["array-contains-any" /* ARRAY_CONTAINS_ANY */, "in" /* IN */, "not-in" /* NOT_IN */];
|
|
28412
|
-
case "array-contains-any" /* ARRAY_CONTAINS_ANY */:
|
|
29098
|
+
case "in" /* Operator.IN */:
|
|
29099
|
+
return ["array-contains-any" /* Operator.ARRAY_CONTAINS_ANY */, "in" /* Operator.IN */, "not-in" /* Operator.NOT_IN */];
|
|
29100
|
+
case "array-contains-any" /* Operator.ARRAY_CONTAINS_ANY */:
|
|
28413
29101
|
return [
|
|
28414
|
-
"array-contains" /* ARRAY_CONTAINS */,
|
|
28415
|
-
"array-contains-any" /* ARRAY_CONTAINS_ANY */,
|
|
28416
|
-
"in" /* IN */,
|
|
28417
|
-
"not-in" /* NOT_IN */
|
|
29102
|
+
"array-contains" /* Operator.ARRAY_CONTAINS */,
|
|
29103
|
+
"array-contains-any" /* Operator.ARRAY_CONTAINS_ANY */,
|
|
29104
|
+
"in" /* Operator.IN */,
|
|
29105
|
+
"not-in" /* Operator.NOT_IN */
|
|
28418
29106
|
];
|
|
28419
|
-
case "not-in" /* NOT_IN */:
|
|
29107
|
+
case "not-in" /* Operator.NOT_IN */:
|
|
28420
29108
|
return [
|
|
28421
|
-
"array-contains" /* ARRAY_CONTAINS */,
|
|
28422
|
-
"array-contains-any" /* ARRAY_CONTAINS_ANY */,
|
|
28423
|
-
"in" /* IN */,
|
|
28424
|
-
"not-in" /* NOT_IN */,
|
|
28425
|
-
"!=" /* NOT_EQUAL */
|
|
29109
|
+
"array-contains" /* Operator.ARRAY_CONTAINS */,
|
|
29110
|
+
"array-contains-any" /* Operator.ARRAY_CONTAINS_ANY */,
|
|
29111
|
+
"in" /* Operator.IN */,
|
|
29112
|
+
"not-in" /* Operator.NOT_IN */,
|
|
29113
|
+
"!=" /* Operator.NOT_EQUAL */
|
|
28426
29114
|
];
|
|
28427
29115
|
default:
|
|
28428
29116
|
return [];
|
|
28429
29117
|
}
|
|
28430
29118
|
}
|
|
28431
|
-
function
|
|
28432
|
-
if (
|
|
28433
|
-
const
|
|
28434
|
-
|
|
29119
|
+
function validateNewFieldFilter(query, fieldFilter) {
|
|
29120
|
+
if (fieldFilter.isInequality()) {
|
|
29121
|
+
const existingInequality = getInequalityFilterField(query);
|
|
29122
|
+
const newInequality = fieldFilter.field;
|
|
29123
|
+
if (existingInequality !== null &&
|
|
29124
|
+
!existingInequality.isEqual(newInequality)) {
|
|
28435
29125
|
throw new FirestoreError(Code.INVALID_ARGUMENT, 'Invalid query. All where filters with an inequality' +
|
|
28436
29126
|
' (<, <=, !=, not-in, >, or >=) must be on the same field. But you have' +
|
|
28437
|
-
` inequality filters on '${
|
|
28438
|
-
` and '${
|
|
29127
|
+
` inequality filters on '${existingInequality.toString()}'` +
|
|
29128
|
+
` and '${newInequality.toString()}'`);
|
|
28439
29129
|
}
|
|
28440
29130
|
const firstOrderByField = getFirstOrderByField(query);
|
|
28441
29131
|
if (firstOrderByField !== null) {
|
|
28442
|
-
validateOrderByAndInequalityMatch(query,
|
|
29132
|
+
validateOrderByAndInequalityMatch(query, newInequality, firstOrderByField);
|
|
28443
29133
|
}
|
|
28444
29134
|
}
|
|
28445
|
-
const conflictingOp =
|
|
29135
|
+
const conflictingOp = findOpInsideFilters(query.filters, conflictingOps(fieldFilter.op));
|
|
28446
29136
|
if (conflictingOp !== null) {
|
|
28447
29137
|
// Special case when it's a duplicate op to give a slightly clearer error message.
|
|
28448
|
-
if (conflictingOp ===
|
|
29138
|
+
if (conflictingOp === fieldFilter.op) {
|
|
28449
29139
|
throw new FirestoreError(Code.INVALID_ARGUMENT, 'Invalid query. You cannot use more than one ' +
|
|
28450
|
-
`'${
|
|
29140
|
+
`'${fieldFilter.op.toString()}' filter.`);
|
|
28451
29141
|
}
|
|
28452
29142
|
else {
|
|
28453
|
-
throw new FirestoreError(Code.INVALID_ARGUMENT, `Invalid query. You cannot use '${
|
|
29143
|
+
throw new FirestoreError(Code.INVALID_ARGUMENT, `Invalid query. You cannot use '${fieldFilter.op.toString()}' filters ` +
|
|
28454
29144
|
`with '${conflictingOp.toString()}' filters.`);
|
|
28455
29145
|
}
|
|
28456
29146
|
}
|
|
28457
29147
|
}
|
|
29148
|
+
function validateNewFilter(query, filter) {
|
|
29149
|
+
let testQuery = query;
|
|
29150
|
+
const subFilters = filter.getFlattenedFilters();
|
|
29151
|
+
for (const subFilter of subFilters) {
|
|
29152
|
+
validateNewFieldFilter(testQuery, subFilter);
|
|
29153
|
+
testQuery = queryWithAddedFilter(testQuery, subFilter);
|
|
29154
|
+
}
|
|
29155
|
+
}
|
|
29156
|
+
// Checks if any of the provided filter operators are included in the given list of filters and
|
|
29157
|
+
// returns the first one that is, or null if none are.
|
|
29158
|
+
function findOpInsideFilters(filters, operators) {
|
|
29159
|
+
for (const filter of filters) {
|
|
29160
|
+
for (const fieldFilter of filter.getFlattenedFilters()) {
|
|
29161
|
+
if (operators.indexOf(fieldFilter.op) >= 0) {
|
|
29162
|
+
return fieldFilter.op;
|
|
29163
|
+
}
|
|
29164
|
+
}
|
|
29165
|
+
}
|
|
29166
|
+
return null;
|
|
29167
|
+
}
|
|
28458
29168
|
function validateNewOrderBy(query, orderBy) {
|
|
28459
29169
|
if (getFirstOrderByField(query) === null) {
|
|
28460
29170
|
// This is the first order by. It must match any inequality.
|
|
@@ -28472,6 +29182,24 @@ function validateOrderByAndInequalityMatch(baseQuery, inequality, orderBy) {
|
|
|
28472
29182
|
`as your first argument to orderBy(), but your first orderBy() ` +
|
|
28473
29183
|
`is on field '${orderBy.toString()}' instead.`);
|
|
28474
29184
|
}
|
|
29185
|
+
}
|
|
29186
|
+
function validateQueryFilterConstraint(functionName, queryConstraint) {
|
|
29187
|
+
if (!(queryConstraint instanceof QueryFieldFilterConstraint) &&
|
|
29188
|
+
!(queryConstraint instanceof QueryCompositeFilterConstraint)) {
|
|
29189
|
+
throw new FirestoreError(Code.INVALID_ARGUMENT, `Function ${functionName}() requires AppliableConstraints created with a call to 'where(...)', 'or(...)', or 'and(...)'.`);
|
|
29190
|
+
}
|
|
29191
|
+
}
|
|
29192
|
+
function validateQueryConstraintArray(queryConstraint) {
|
|
29193
|
+
const compositeFilterCount = queryConstraint.filter(filter => filter instanceof QueryCompositeFilterConstraint).length;
|
|
29194
|
+
const fieldFilterCount = queryConstraint.filter(filter => filter instanceof QueryFieldFilterConstraint).length;
|
|
29195
|
+
if (compositeFilterCount > 1 ||
|
|
29196
|
+
(compositeFilterCount > 0 && fieldFilterCount > 0)) {
|
|
29197
|
+
throw new FirestoreError(Code.INVALID_ARGUMENT, 'InvalidQuery. When using composite filters, you cannot use ' +
|
|
29198
|
+
'more than one filter at the top level. Consider nesting the multiple ' +
|
|
29199
|
+
'filters within an `and(...)` statement. For example: ' +
|
|
29200
|
+
'change `query(query, where(...), or(...))` to ' +
|
|
29201
|
+
'`query(query, and(where(...), or(...)))`.');
|
|
29202
|
+
}
|
|
28475
29203
|
}
|
|
28476
29204
|
|
|
28477
29205
|
/**
|
|
@@ -28499,27 +29227,27 @@ function validateOrderByAndInequalityMatch(baseQuery, inequality, orderBy) {
|
|
|
28499
29227
|
class AbstractUserDataWriter {
|
|
28500
29228
|
convertValue(value, serverTimestampBehavior = 'none') {
|
|
28501
29229
|
switch (typeOrder(value)) {
|
|
28502
|
-
case 0 /* NullValue */:
|
|
29230
|
+
case 0 /* TypeOrder.NullValue */:
|
|
28503
29231
|
return null;
|
|
28504
|
-
case 1 /* BooleanValue */:
|
|
29232
|
+
case 1 /* TypeOrder.BooleanValue */:
|
|
28505
29233
|
return value.booleanValue;
|
|
28506
|
-
case 2 /* NumberValue */:
|
|
29234
|
+
case 2 /* TypeOrder.NumberValue */:
|
|
28507
29235
|
return normalizeNumber(value.integerValue || value.doubleValue);
|
|
28508
|
-
case 3 /* TimestampValue */:
|
|
29236
|
+
case 3 /* TypeOrder.TimestampValue */:
|
|
28509
29237
|
return this.convertTimestamp(value.timestampValue);
|
|
28510
|
-
case 4 /* ServerTimestampValue */:
|
|
29238
|
+
case 4 /* TypeOrder.ServerTimestampValue */:
|
|
28511
29239
|
return this.convertServerTimestamp(value, serverTimestampBehavior);
|
|
28512
|
-
case 5 /* StringValue */:
|
|
29240
|
+
case 5 /* TypeOrder.StringValue */:
|
|
28513
29241
|
return value.stringValue;
|
|
28514
|
-
case 6 /* BlobValue */:
|
|
29242
|
+
case 6 /* TypeOrder.BlobValue */:
|
|
28515
29243
|
return this.convertBytes(normalizeByteString(value.bytesValue));
|
|
28516
|
-
case 7 /* RefValue */:
|
|
29244
|
+
case 7 /* TypeOrder.RefValue */:
|
|
28517
29245
|
return this.convertReference(value.referenceValue);
|
|
28518
|
-
case 8 /* GeoPointValue */:
|
|
29246
|
+
case 8 /* TypeOrder.GeoPointValue */:
|
|
28519
29247
|
return this.convertGeoPoint(value.geoPointValue);
|
|
28520
|
-
case 9 /* ArrayValue */:
|
|
29248
|
+
case 9 /* TypeOrder.ArrayValue */:
|
|
28521
29249
|
return this.convertArray(value.arrayValue, serverTimestampBehavior);
|
|
28522
|
-
case 10 /* ObjectValue */:
|
|
29250
|
+
case 10 /* TypeOrder.ObjectValue */:
|
|
28523
29251
|
return this.convertObject(value.mapValue, serverTimestampBehavior);
|
|
28524
29252
|
default:
|
|
28525
29253
|
throw fail();
|
|
@@ -28861,16 +29589,16 @@ function changesFromSnapshot(querySnapshot, includeMetadataChanges) {
|
|
|
28861
29589
|
// to lookup the index of a document.
|
|
28862
29590
|
let indexTracker = querySnapshot._snapshot.oldDocs;
|
|
28863
29591
|
return querySnapshot._snapshot.docChanges
|
|
28864
|
-
.filter(change => includeMetadataChanges || change.type !== 3 /* Metadata */)
|
|
29592
|
+
.filter(change => includeMetadataChanges || change.type !== 3 /* ChangeType.Metadata */)
|
|
28865
29593
|
.map(change => {
|
|
28866
29594
|
const doc = new QueryDocumentSnapshot(querySnapshot._firestore, querySnapshot._userDataWriter, change.doc.key, change.doc, new SnapshotMetadata(querySnapshot._snapshot.mutatedKeys.has(change.doc.key), querySnapshot._snapshot.fromCache), querySnapshot.query.converter);
|
|
28867
29595
|
let oldIndex = -1;
|
|
28868
29596
|
let newIndex = -1;
|
|
28869
|
-
if (change.type !== 0 /* Added */) {
|
|
29597
|
+
if (change.type !== 0 /* ChangeType.Added */) {
|
|
28870
29598
|
oldIndex = indexTracker.indexOf(change.doc.key);
|
|
28871
29599
|
indexTracker = indexTracker.delete(change.doc.key);
|
|
28872
29600
|
}
|
|
28873
|
-
if (change.type !== 1 /* Removed */) {
|
|
29601
|
+
if (change.type !== 1 /* ChangeType.Removed */) {
|
|
28874
29602
|
indexTracker = indexTracker.add(change.doc);
|
|
28875
29603
|
newIndex = indexTracker.indexOf(change.doc.key);
|
|
28876
29604
|
}
|
|
@@ -28885,12 +29613,12 @@ function changesFromSnapshot(querySnapshot, includeMetadataChanges) {
|
|
|
28885
29613
|
}
|
|
28886
29614
|
function resultChangeType(type) {
|
|
28887
29615
|
switch (type) {
|
|
28888
|
-
case 0 /* Added */:
|
|
29616
|
+
case 0 /* ChangeType.Added */:
|
|
28889
29617
|
return 'added';
|
|
28890
|
-
case 2 /* Modified */:
|
|
28891
|
-
case 3 /* Metadata */:
|
|
29618
|
+
case 2 /* ChangeType.Modified */:
|
|
29619
|
+
case 3 /* ChangeType.Metadata */:
|
|
28892
29620
|
return 'modified';
|
|
28893
|
-
case 1 /* Removed */:
|
|
29621
|
+
case 1 /* ChangeType.Removed */:
|
|
28894
29622
|
return 'removed';
|
|
28895
29623
|
default:
|
|
28896
29624
|
return fail();
|
|
@@ -29724,13 +30452,13 @@ function parseIndexes(jsonOrConfiguration) {
|
|
|
29724
30452
|
const fieldPathString = tryGetString(field, 'fieldPath');
|
|
29725
30453
|
const fieldPath = fieldPathFromDotSeparatedString('setIndexConfiguration', fieldPathString);
|
|
29726
30454
|
if (field.arrayConfig === 'CONTAINS') {
|
|
29727
|
-
segments.push(new IndexSegment(fieldPath, 2 /* CONTAINS */));
|
|
30455
|
+
segments.push(new IndexSegment(fieldPath, 2 /* IndexKind.CONTAINS */));
|
|
29728
30456
|
}
|
|
29729
30457
|
else if (field.order === 'ASCENDING') {
|
|
29730
|
-
segments.push(new IndexSegment(fieldPath, 0 /* ASCENDING */));
|
|
30458
|
+
segments.push(new IndexSegment(fieldPath, 0 /* IndexKind.ASCENDING */));
|
|
29731
30459
|
}
|
|
29732
30460
|
else if (field.order === 'DESCENDING') {
|
|
29733
|
-
segments.push(new IndexSegment(fieldPath, 1 /* DESCENDING */));
|
|
30461
|
+
segments.push(new IndexSegment(fieldPath, 1 /* IndexKind.DESCENDING */));
|
|
29734
30462
|
}
|
|
29735
30463
|
}
|
|
29736
30464
|
}
|
|
@@ -29740,12 +30468,11 @@ function parseIndexes(jsonOrConfiguration) {
|
|
|
29740
30468
|
return parsedIndexes;
|
|
29741
30469
|
}
|
|
29742
30470
|
function tryParseJson(json) {
|
|
29743
|
-
var _a;
|
|
29744
30471
|
try {
|
|
29745
30472
|
return JSON.parse(json);
|
|
29746
30473
|
}
|
|
29747
30474
|
catch (e) {
|
|
29748
|
-
throw new FirestoreError(Code.INVALID_ARGUMENT, 'Failed to parse JSON: ' + (
|
|
30475
|
+
throw new FirestoreError(Code.INVALID_ARGUMENT, 'Failed to parse JSON: ' + (e === null || e === void 0 ? void 0 : e.message));
|
|
29749
30476
|
}
|
|
29750
30477
|
}
|
|
29751
30478
|
function tryGetString(data, property) {
|
|
@@ -29773,5 +30500,5 @@ function tryGetString(data, property) {
|
|
|
29773
30500
|
*/
|
|
29774
30501
|
registerFirestore('node');
|
|
29775
30502
|
|
|
29776
|
-
export { AbstractUserDataWriter, AggregateField, AggregateQuerySnapshot, Bytes, CACHE_SIZE_UNLIMITED, CollectionReference, DocumentReference, DocumentSnapshot, FieldPath, FieldValue, Firestore, FirestoreError, GeoPoint, LoadBundleTask, Query, QueryConstraint, QueryDocumentSnapshot, QuerySnapshot, SnapshotMetadata, Timestamp, Transaction, WriteBatch, DatabaseId as _DatabaseId, DocumentKey as _DocumentKey, EmptyAppCheckTokenProvider as _EmptyAppCheckTokenProvider, EmptyAuthCredentialsProvider as _EmptyAuthCredentialsProvider, FieldPath$1 as _FieldPath, cast as _cast, debugAssert as _debugAssert, isBase64Available as _isBase64Available, logWarn as _logWarn, validateIsNotUsedTogether as _validateIsNotUsedTogether, addDoc, aggregateQuerySnapshotEqual, arrayRemove, arrayUnion, clearIndexedDbPersistence, collection, collectionGroup, connectFirestoreEmulator, deleteDoc, deleteField, disableNetwork, doc, documentId, enableIndexedDbPersistence, enableMultiTabIndexedDbPersistence, enableNetwork, endAt, endBefore, ensureFirestoreConfigured, executeWrite, getCountFromServer, getDoc, getDocFromCache, getDocFromServer, getDocs, getDocsFromCache, getDocsFromServer, getFirestore, increment, initializeFirestore, limit, limitToLast, loadBundle, namedQuery, onSnapshot, onSnapshotsInSync, orderBy, query, queryEqual, refEqual, runTransaction, serverTimestamp, setDoc, setIndexConfiguration, setLogLevel, snapshotEqual, startAfter, startAt, terminate, updateDoc, waitForPendingWrites, where, writeBatch };
|
|
30503
|
+
export { AbstractUserDataWriter, AggregateField, AggregateQuerySnapshot, Bytes, CACHE_SIZE_UNLIMITED, CollectionReference, DocumentReference, DocumentSnapshot, FieldPath, FieldValue, Firestore, FirestoreError, GeoPoint, LoadBundleTask, Query, QueryCompositeFilterConstraint, QueryConstraint, QueryDocumentSnapshot, QueryEndAtConstraint, QueryFieldFilterConstraint, QueryLimitConstraint, QueryOrderByConstraint, QuerySnapshot, QueryStartAtConstraint, SnapshotMetadata, Timestamp, Transaction, WriteBatch, DatabaseId as _DatabaseId, DocumentKey as _DocumentKey, EmptyAppCheckTokenProvider as _EmptyAppCheckTokenProvider, EmptyAuthCredentialsProvider as _EmptyAuthCredentialsProvider, FieldPath$1 as _FieldPath, cast as _cast, debugAssert as _debugAssert, isBase64Available as _isBase64Available, logWarn as _logWarn, validateIsNotUsedTogether as _validateIsNotUsedTogether, addDoc, aggregateQuerySnapshotEqual, and, arrayRemove, arrayUnion, clearIndexedDbPersistence, collection, collectionGroup, connectFirestoreEmulator, deleteDoc, deleteField, disableNetwork, doc, documentId, enableIndexedDbPersistence, enableMultiTabIndexedDbPersistence, enableNetwork, endAt, endBefore, ensureFirestoreConfigured, executeWrite, getCountFromServer, getDoc, getDocFromCache, getDocFromServer, getDocs, getDocsFromCache, getDocsFromServer, getFirestore, increment, initializeFirestore, limit, limitToLast, loadBundle, namedQuery, onSnapshot, onSnapshotsInSync, or, orderBy, query, queryEqual, refEqual, runTransaction, serverTimestamp, setDoc, setIndexConfiguration, setLogLevel, snapshotEqual, startAfter, startAt, terminate, updateDoc, waitForPendingWrites, where, writeBatch };
|
|
29777
30504
|
//# sourceMappingURL=index.node.mjs.map
|