@firebase/firestore 3.5.0 → 3.6.0-canary.0a112bd2a
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/dist/firestore/lite/index.d.ts +2 -0
- package/dist/firestore/src/api/aggregate.d.ts +43 -0
- package/dist/firestore/src/api/database.d.ts +15 -15
- package/dist/firestore/src/api.d.ts +2 -0
- package/dist/firestore/src/core/count_query_runner.d.ts +32 -0
- package/dist/firestore/src/core/firestore_client.d.ts +5 -0
- package/dist/firestore/src/core/view.d.ts +1 -0
- package/dist/firestore/src/core/view_snapshot.d.ts +3 -2
- package/dist/firestore/src/lite-api/aggregate.d.ts +48 -0
- package/dist/firestore/src/lite-api/aggregate_types.d.ts +69 -0
- package/dist/firestore/src/lite-api/database.d.ts +7 -7
- package/dist/firestore/src/platform/node/grpc_connection.d.ts +1 -0
- package/dist/firestore/src/protos/firestore_proto_api.d.ts +28 -0
- package/dist/firestore/src/remote/connection.d.ts +7 -0
- package/dist/firestore/src/remote/datastore.d.ts +2 -0
- package/dist/firestore/src/remote/remote_event.d.ts +2 -2
- package/dist/firestore/src/remote/rest_connection.d.ts +1 -0
- package/dist/firestore/src/remote/serializer.d.ts +2 -1
- package/dist/firestore/test/integration/api/aggregation.test.d.ts +17 -0
- package/dist/firestore/test/integration/api_internal/aggregation.test.d.ts +17 -0
- package/dist/firestore/test/integration/util/helpers.d.ts +1 -0
- package/dist/firestore/test/unit/specs/spec_test_components.d.ts +1 -0
- package/dist/firestore/test/util/api_helpers.d.ts +1 -1
- package/dist/index.d.ts +196 -14
- package/dist/index.esm2017.js +4633 -4428
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.esm5.js +4706 -4498
- package/dist/index.esm5.js.map +1 -1
- package/dist/index.node.cjs.js +1021 -632
- package/dist/index.node.cjs.js.map +1 -1
- package/dist/index.node.mjs +1019 -634
- package/dist/index.node.mjs.map +1 -1
- package/dist/index.rn.js +4637 -4432
- package/dist/index.rn.js.map +1 -1
- package/dist/internal.d.ts +144 -21
- package/dist/lite/firestore/lite/index.d.ts +2 -0
- package/dist/lite/firestore/src/api/aggregate.d.ts +43 -0
- package/dist/lite/firestore/src/api/database.d.ts +15 -15
- package/dist/lite/firestore/src/api.d.ts +2 -0
- package/dist/lite/firestore/src/core/count_query_runner.d.ts +32 -0
- package/dist/lite/firestore/src/core/firestore_client.d.ts +5 -0
- package/dist/lite/firestore/src/core/view.d.ts +1 -0
- package/dist/lite/firestore/src/core/view_snapshot.d.ts +3 -2
- package/dist/lite/firestore/src/lite-api/aggregate.d.ts +48 -0
- package/dist/lite/firestore/src/lite-api/aggregate_types.d.ts +69 -0
- package/dist/lite/firestore/src/lite-api/database.d.ts +7 -7
- package/dist/lite/firestore/src/platform/node/grpc_connection.d.ts +1 -0
- package/dist/lite/firestore/src/protos/firestore_proto_api.d.ts +28 -0
- package/dist/lite/firestore/src/remote/connection.d.ts +7 -0
- package/dist/lite/firestore/src/remote/datastore.d.ts +2 -0
- package/dist/lite/firestore/src/remote/remote_event.d.ts +2 -2
- package/dist/lite/firestore/src/remote/rest_connection.d.ts +1 -0
- package/dist/lite/firestore/src/remote/serializer.d.ts +2 -1
- package/dist/lite/firestore/test/integration/api/aggregation.test.d.ts +17 -0
- package/dist/lite/firestore/test/integration/api_internal/aggregation.test.d.ts +17 -0
- package/dist/lite/firestore/test/integration/util/helpers.d.ts +1 -0
- package/dist/lite/firestore/test/unit/specs/spec_test_components.d.ts +1 -0
- package/dist/lite/firestore/test/util/api_helpers.d.ts +1 -1
- package/dist/lite/index.browser.esm2017.js +1250 -1086
- package/dist/lite/index.browser.esm2017.js.map +1 -1
- package/dist/lite/index.browser.esm5.js +1394 -1232
- package/dist/lite/index.browser.esm5.js.map +1 -1
- package/dist/lite/index.d.ts +84 -4
- package/dist/lite/index.node.cjs.js +255 -63
- package/dist/lite/index.node.cjs.js.map +1 -1
- package/dist/lite/index.node.mjs +253 -65
- package/dist/lite/index.node.mjs.map +1 -1
- package/dist/lite/index.rn.esm2017.js +1257 -1093
- package/dist/lite/index.rn.esm2017.js.map +1 -1
- package/dist/lite/internal.d.ts +121 -6
- package/dist/lite/packages/firestore/dist/lite/index.browser.esm2017.d.ts +227 -142
- package/dist/lite/packages/firestore/lite/index.d.ts +2 -0
- package/dist/lite/packages/firestore/src/api/aggregate.d.ts +43 -0
- package/dist/lite/packages/firestore/src/api/database.d.ts +15 -15
- package/dist/lite/packages/firestore/src/api.d.ts +2 -0
- package/dist/lite/packages/firestore/src/core/count_query_runner.d.ts +32 -0
- package/dist/lite/packages/firestore/src/core/firestore_client.d.ts +5 -0
- package/dist/lite/packages/firestore/src/core/view.d.ts +1 -0
- package/dist/lite/packages/firestore/src/core/view_snapshot.d.ts +3 -2
- package/dist/lite/packages/firestore/src/lite-api/aggregate.d.ts +48 -0
- package/dist/lite/packages/firestore/src/lite-api/aggregate_types.d.ts +69 -0
- package/dist/lite/packages/firestore/src/lite-api/database.d.ts +7 -7
- package/dist/lite/packages/firestore/src/platform/node/grpc_connection.d.ts +1 -0
- package/dist/lite/packages/firestore/src/protos/firestore_proto_api.d.ts +28 -0
- package/dist/lite/packages/firestore/src/remote/connection.d.ts +7 -0
- package/dist/lite/packages/firestore/src/remote/datastore.d.ts +2 -0
- package/dist/lite/packages/firestore/src/remote/remote_event.d.ts +2 -2
- package/dist/lite/packages/firestore/src/remote/rest_connection.d.ts +1 -0
- package/dist/lite/packages/firestore/src/remote/serializer.d.ts +2 -1
- package/dist/lite/packages/firestore/test/integration/api/aggregation.test.d.ts +17 -0
- package/dist/lite/packages/firestore/test/integration/api_internal/aggregation.test.d.ts +17 -0
- package/dist/lite/packages/firestore/test/integration/util/helpers.d.ts +1 -0
- package/dist/lite/packages/firestore/test/unit/specs/spec_test_components.d.ts +1 -0
- package/dist/lite/packages/firestore/test/util/api_helpers.d.ts +1 -1
- package/dist/lite/private.d.ts +119 -4
- package/dist/packages/firestore/dist/index.esm2017.d.ts +336 -254
- package/dist/packages/firestore/lite/index.d.ts +2 -0
- package/dist/packages/firestore/src/api/aggregate.d.ts +43 -0
- package/dist/packages/firestore/src/api/database.d.ts +15 -15
- package/dist/packages/firestore/src/api.d.ts +2 -0
- package/dist/packages/firestore/src/core/count_query_runner.d.ts +32 -0
- package/dist/packages/firestore/src/core/firestore_client.d.ts +5 -0
- package/dist/packages/firestore/src/core/view.d.ts +1 -0
- package/dist/packages/firestore/src/core/view_snapshot.d.ts +3 -2
- package/dist/packages/firestore/src/lite-api/aggregate.d.ts +48 -0
- package/dist/packages/firestore/src/lite-api/aggregate_types.d.ts +69 -0
- package/dist/packages/firestore/src/lite-api/database.d.ts +7 -7
- package/dist/packages/firestore/src/platform/node/grpc_connection.d.ts +1 -0
- package/dist/packages/firestore/src/protos/firestore_proto_api.d.ts +28 -0
- package/dist/packages/firestore/src/remote/connection.d.ts +7 -0
- package/dist/packages/firestore/src/remote/datastore.d.ts +2 -0
- package/dist/packages/firestore/src/remote/remote_event.d.ts +2 -2
- package/dist/packages/firestore/src/remote/rest_connection.d.ts +1 -0
- package/dist/packages/firestore/src/remote/serializer.d.ts +2 -1
- package/dist/packages/firestore/test/integration/api/aggregation.test.d.ts +17 -0
- package/dist/packages/firestore/test/integration/api_internal/aggregation.test.d.ts +17 -0
- package/dist/packages/firestore/test/integration/util/helpers.d.ts +1 -0
- package/dist/packages/firestore/test/unit/specs/spec_test_components.d.ts +1 -0
- package/dist/packages/firestore/test/util/api_helpers.d.ts +1 -1
- package/dist/private.d.ts +239 -23
- package/package.json +9 -9
package/dist/index.node.mjs
CHANGED
|
@@ -2,13 +2,13 @@ import { _getProvider, getApp, _removeServiceInstance, _registerComponent, regis
|
|
|
2
2
|
import { Component } from '@firebase/component';
|
|
3
3
|
import { Logger, LogLevel } from '@firebase/logger';
|
|
4
4
|
import { inspect, TextEncoder, TextDecoder } from 'util';
|
|
5
|
-
import { FirebaseError, createMockUserToken, getModularInstance, deepEqual, getUA, isIndexedDBAvailable, isSafari } from '@firebase/util';
|
|
5
|
+
import { FirebaseError, createMockUserToken, getModularInstance, deepEqual, getDefaultEmulatorHost, getUA, isIndexedDBAvailable, isSafari } from '@firebase/util';
|
|
6
6
|
import { randomBytes as randomBytes$1 } from 'crypto';
|
|
7
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.
|
|
11
|
+
const version$1 = "3.6.0-canary.0a112bd2a";
|
|
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.
|
|
64
|
+
const version = "9.11.0-canary.0a112bd2a";
|
|
65
65
|
|
|
66
66
|
/**
|
|
67
67
|
* @license
|
|
@@ -7566,9 +7566,9 @@ class RemoteEvent {
|
|
|
7566
7566
|
* CURRENT status change to a View, for queries executed in a different tab.
|
|
7567
7567
|
*/
|
|
7568
7568
|
// PORTING NOTE: Multi-tab only
|
|
7569
|
-
static createSynthesizedRemoteEventForCurrentChange(targetId, current) {
|
|
7569
|
+
static createSynthesizedRemoteEventForCurrentChange(targetId, current, resumeToken) {
|
|
7570
7570
|
const targetChanges = new Map();
|
|
7571
|
-
targetChanges.set(targetId, TargetChange.createSynthesizedTargetChangeForCurrentChange(targetId, current));
|
|
7571
|
+
targetChanges.set(targetId, TargetChange.createSynthesizedTargetChangeForCurrentChange(targetId, current, resumeToken));
|
|
7572
7572
|
return new RemoteEvent(SnapshotVersion.min(), targetChanges, targetIdSet(), mutableDocumentMap(), documentKeySet());
|
|
7573
7573
|
}
|
|
7574
7574
|
}
|
|
@@ -7621,8 +7621,8 @@ class TargetChange {
|
|
|
7621
7621
|
* apply a CURRENT status change to a View (for queries executed in a different
|
|
7622
7622
|
* tab) or for new queries (to raise snapshots with correct CURRENT status).
|
|
7623
7623
|
*/
|
|
7624
|
-
static createSynthesizedTargetChangeForCurrentChange(targetId, current) {
|
|
7625
|
-
return new TargetChange(
|
|
7624
|
+
static createSynthesizedTargetChangeForCurrentChange(targetId, current, resumeToken) {
|
|
7625
|
+
return new TargetChange(resumeToken, current, documentKeySet(), documentKeySet(), documentKeySet());
|
|
7626
7626
|
}
|
|
7627
7627
|
}
|
|
7628
7628
|
|
|
@@ -8726,6 +8726,21 @@ function toQueryTarget(serializer, target) {
|
|
|
8726
8726
|
}
|
|
8727
8727
|
return result;
|
|
8728
8728
|
}
|
|
8729
|
+
function toRunAggregationQueryRequest(serializer, target) {
|
|
8730
|
+
const queryTarget = toQueryTarget(serializer, target);
|
|
8731
|
+
return {
|
|
8732
|
+
structuredAggregationQuery: {
|
|
8733
|
+
aggregations: [
|
|
8734
|
+
{
|
|
8735
|
+
count: {},
|
|
8736
|
+
alias: 'count_alias'
|
|
8737
|
+
}
|
|
8738
|
+
],
|
|
8739
|
+
structuredQuery: queryTarget.structuredQuery
|
|
8740
|
+
},
|
|
8741
|
+
parent: queryTarget.parent
|
|
8742
|
+
};
|
|
8743
|
+
}
|
|
8729
8744
|
function convertQueryTargetToQuery(target) {
|
|
8730
8745
|
let path = fromQueryPath(target.parent);
|
|
8731
8746
|
const query = target.structuredQuery;
|
|
@@ -16112,7 +16127,8 @@ function localStoreGetNewDocumentChanges(localStore, collectionGroup) {
|
|
|
16112
16127
|
/** Sets the collection group's maximum read time from the given documents. */
|
|
16113
16128
|
// PORTING NOTE: Multi-Tab only.
|
|
16114
16129
|
function setMaxReadTime(localStoreImpl, collectionGroup, changedDocs) {
|
|
16115
|
-
let readTime =
|
|
16130
|
+
let readTime = localStoreImpl.collectionGroupReadTime.get(collectionGroup) ||
|
|
16131
|
+
SnapshotVersion.min();
|
|
16116
16132
|
changedDocs.forEach((_, doc) => {
|
|
16117
16133
|
if (doc.readTime.compareTo(readTime) > 0) {
|
|
16118
16134
|
readTime = doc.readTime;
|
|
@@ -17404,6 +17420,11 @@ class GrpcConnection {
|
|
|
17404
17420
|
this.firestore = protos['google']['firestore']['v1'];
|
|
17405
17421
|
this.databasePath = `projects/${databaseInfo.databaseId.projectId}/databases/${databaseInfo.databaseId.database}`;
|
|
17406
17422
|
}
|
|
17423
|
+
get shouldResourcePathBeIncludedInRequest() {
|
|
17424
|
+
// Both `invokeRPC()` and `invokeStreamingRPC()` ignore their `path` arguments, and expect
|
|
17425
|
+
// the "path" to be part of the given `request`.
|
|
17426
|
+
return true;
|
|
17427
|
+
}
|
|
17407
17428
|
ensureActiveStub() {
|
|
17408
17429
|
if (!this.cachedStub) {
|
|
17409
17430
|
logDebug(LOG_TAG$9, 'Creating Firestore stub.');
|
|
@@ -18450,6 +18471,15 @@ const nested = {
|
|
|
18450
18471
|
ruby_package: "Google::Cloud::Firestore::V1"
|
|
18451
18472
|
},
|
|
18452
18473
|
nested: {
|
|
18474
|
+
AggregationResult: {
|
|
18475
|
+
fields: {
|
|
18476
|
+
aggregateFields: {
|
|
18477
|
+
keyType: "string",
|
|
18478
|
+
type: "Value",
|
|
18479
|
+
id: 2
|
|
18480
|
+
}
|
|
18481
|
+
}
|
|
18482
|
+
},
|
|
18453
18483
|
DocumentMask: {
|
|
18454
18484
|
fields: {
|
|
18455
18485
|
fieldPaths: {
|
|
@@ -18800,6 +18830,29 @@ const nested = {
|
|
|
18800
18830
|
}
|
|
18801
18831
|
]
|
|
18802
18832
|
},
|
|
18833
|
+
RunAggregationQuery: {
|
|
18834
|
+
requestType: "RunAggregationQueryRequest",
|
|
18835
|
+
responseType: "RunAggregationQueryResponse",
|
|
18836
|
+
responseStream: true,
|
|
18837
|
+
options: {
|
|
18838
|
+
"(google.api.http).post": "/v1/{parent=projects/*/databases/*/documents}:runAggregationQuery",
|
|
18839
|
+
"(google.api.http).body": "*",
|
|
18840
|
+
"(google.api.http).additional_bindings.post": "/v1/{parent=projects/*/databases/*/documents/*/**}:runAggregationQuery",
|
|
18841
|
+
"(google.api.http).additional_bindings.body": "*"
|
|
18842
|
+
},
|
|
18843
|
+
parsedOptions: [
|
|
18844
|
+
{
|
|
18845
|
+
"(google.api.http)": {
|
|
18846
|
+
post: "/v1/{parent=projects/*/databases/*/documents}:runAggregationQuery",
|
|
18847
|
+
body: "*",
|
|
18848
|
+
additional_bindings: {
|
|
18849
|
+
post: "/v1/{parent=projects/*/databases/*/documents/*/**}:runAggregationQuery",
|
|
18850
|
+
body: "*"
|
|
18851
|
+
}
|
|
18852
|
+
}
|
|
18853
|
+
}
|
|
18854
|
+
]
|
|
18855
|
+
},
|
|
18803
18856
|
PartitionQuery: {
|
|
18804
18857
|
requestType: "PartitionQueryRequest",
|
|
18805
18858
|
responseType: "PartitionQueryResponse",
|
|
@@ -19291,6 +19344,63 @@ const nested = {
|
|
|
19291
19344
|
}
|
|
19292
19345
|
}
|
|
19293
19346
|
},
|
|
19347
|
+
RunAggregationQueryRequest: {
|
|
19348
|
+
oneofs: {
|
|
19349
|
+
queryType: {
|
|
19350
|
+
oneof: [
|
|
19351
|
+
"structuredAggregationQuery"
|
|
19352
|
+
]
|
|
19353
|
+
},
|
|
19354
|
+
consistencySelector: {
|
|
19355
|
+
oneof: [
|
|
19356
|
+
"transaction",
|
|
19357
|
+
"newTransaction",
|
|
19358
|
+
"readTime"
|
|
19359
|
+
]
|
|
19360
|
+
}
|
|
19361
|
+
},
|
|
19362
|
+
fields: {
|
|
19363
|
+
parent: {
|
|
19364
|
+
type: "string",
|
|
19365
|
+
id: 1,
|
|
19366
|
+
options: {
|
|
19367
|
+
"(google.api.field_behavior)": "REQUIRED"
|
|
19368
|
+
}
|
|
19369
|
+
},
|
|
19370
|
+
structuredAggregationQuery: {
|
|
19371
|
+
type: "StructuredAggregationQuery",
|
|
19372
|
+
id: 2
|
|
19373
|
+
},
|
|
19374
|
+
transaction: {
|
|
19375
|
+
type: "bytes",
|
|
19376
|
+
id: 4
|
|
19377
|
+
},
|
|
19378
|
+
newTransaction: {
|
|
19379
|
+
type: "TransactionOptions",
|
|
19380
|
+
id: 5
|
|
19381
|
+
},
|
|
19382
|
+
readTime: {
|
|
19383
|
+
type: "google.protobuf.Timestamp",
|
|
19384
|
+
id: 6
|
|
19385
|
+
}
|
|
19386
|
+
}
|
|
19387
|
+
},
|
|
19388
|
+
RunAggregationQueryResponse: {
|
|
19389
|
+
fields: {
|
|
19390
|
+
result: {
|
|
19391
|
+
type: "AggregationResult",
|
|
19392
|
+
id: 1
|
|
19393
|
+
},
|
|
19394
|
+
transaction: {
|
|
19395
|
+
type: "bytes",
|
|
19396
|
+
id: 2
|
|
19397
|
+
},
|
|
19398
|
+
readTime: {
|
|
19399
|
+
type: "google.protobuf.Timestamp",
|
|
19400
|
+
id: 3
|
|
19401
|
+
}
|
|
19402
|
+
}
|
|
19403
|
+
},
|
|
19294
19404
|
PartitionQueryRequest: {
|
|
19295
19405
|
oneofs: {
|
|
19296
19406
|
queryType: {
|
|
@@ -19827,6 +19937,57 @@ const nested = {
|
|
|
19827
19937
|
}
|
|
19828
19938
|
}
|
|
19829
19939
|
},
|
|
19940
|
+
StructuredAggregationQuery: {
|
|
19941
|
+
oneofs: {
|
|
19942
|
+
queryType: {
|
|
19943
|
+
oneof: [
|
|
19944
|
+
"structuredQuery"
|
|
19945
|
+
]
|
|
19946
|
+
}
|
|
19947
|
+
},
|
|
19948
|
+
fields: {
|
|
19949
|
+
structuredQuery: {
|
|
19950
|
+
type: "StructuredQuery",
|
|
19951
|
+
id: 1
|
|
19952
|
+
},
|
|
19953
|
+
aggregations: {
|
|
19954
|
+
rule: "repeated",
|
|
19955
|
+
type: "Aggregation",
|
|
19956
|
+
id: 3
|
|
19957
|
+
}
|
|
19958
|
+
},
|
|
19959
|
+
nested: {
|
|
19960
|
+
Aggregation: {
|
|
19961
|
+
oneofs: {
|
|
19962
|
+
operator: {
|
|
19963
|
+
oneof: [
|
|
19964
|
+
"count"
|
|
19965
|
+
]
|
|
19966
|
+
}
|
|
19967
|
+
},
|
|
19968
|
+
fields: {
|
|
19969
|
+
count: {
|
|
19970
|
+
type: "Count",
|
|
19971
|
+
id: 1
|
|
19972
|
+
},
|
|
19973
|
+
alias: {
|
|
19974
|
+
type: "string",
|
|
19975
|
+
id: 7
|
|
19976
|
+
}
|
|
19977
|
+
},
|
|
19978
|
+
nested: {
|
|
19979
|
+
Count: {
|
|
19980
|
+
fields: {
|
|
19981
|
+
upTo: {
|
|
19982
|
+
type: "google.protobuf.Int64Value",
|
|
19983
|
+
id: 1
|
|
19984
|
+
}
|
|
19985
|
+
}
|
|
19986
|
+
}
|
|
19987
|
+
}
|
|
19988
|
+
}
|
|
19989
|
+
}
|
|
19990
|
+
},
|
|
19830
19991
|
Cursor: {
|
|
19831
19992
|
fields: {
|
|
19832
19993
|
values: {
|
|
@@ -21067,6 +21228,19 @@ async function invokeBatchGetDocumentsRpc(datastore, keys) {
|
|
|
21067
21228
|
});
|
|
21068
21229
|
return result;
|
|
21069
21230
|
}
|
|
21231
|
+
async function invokeRunAggregationQueryRpc(datastore, query) {
|
|
21232
|
+
const datastoreImpl = debugCast(datastore);
|
|
21233
|
+
const request = toRunAggregationQueryRequest(datastoreImpl.serializer, queryToTarget(query));
|
|
21234
|
+
const parent = request.parent;
|
|
21235
|
+
if (!datastoreImpl.connection.shouldResourcePathBeIncludedInRequest) {
|
|
21236
|
+
delete request.parent;
|
|
21237
|
+
}
|
|
21238
|
+
const response = await datastoreImpl.invokeStreamingRPC('RunAggregationQuery', parent, request, /*expectedResponseCount=*/ 1);
|
|
21239
|
+
return (response
|
|
21240
|
+
// Omit RunAggregationQueryResponse that only contain readTimes.
|
|
21241
|
+
.filter(proto => !!proto.result)
|
|
21242
|
+
.map(proto => proto.result.aggregateFields));
|
|
21243
|
+
}
|
|
21070
21244
|
function newPersistentWriteStream(datastore, queue, listener) {
|
|
21071
21245
|
const datastoreImpl = debugCast(datastore);
|
|
21072
21246
|
datastoreImpl.verifyInitialized();
|
|
@@ -22163,7 +22337,7 @@ class DocumentChangeSet {
|
|
|
22163
22337
|
}
|
|
22164
22338
|
}
|
|
22165
22339
|
class ViewSnapshot {
|
|
22166
|
-
constructor(query, docs, oldDocs, docChanges, mutatedKeys, fromCache, syncStateChanged, excludesMetadataChanges) {
|
|
22340
|
+
constructor(query, docs, oldDocs, docChanges, mutatedKeys, fromCache, syncStateChanged, excludesMetadataChanges, hasCachedResults) {
|
|
22167
22341
|
this.query = query;
|
|
22168
22342
|
this.docs = docs;
|
|
22169
22343
|
this.oldDocs = oldDocs;
|
|
@@ -22172,22 +22346,24 @@ class ViewSnapshot {
|
|
|
22172
22346
|
this.fromCache = fromCache;
|
|
22173
22347
|
this.syncStateChanged = syncStateChanged;
|
|
22174
22348
|
this.excludesMetadataChanges = excludesMetadataChanges;
|
|
22349
|
+
this.hasCachedResults = hasCachedResults;
|
|
22175
22350
|
}
|
|
22176
22351
|
/** Returns a view snapshot as if all documents in the snapshot were added. */
|
|
22177
|
-
static fromInitialDocuments(query, documents, mutatedKeys, fromCache) {
|
|
22352
|
+
static fromInitialDocuments(query, documents, mutatedKeys, fromCache, hasCachedResults) {
|
|
22178
22353
|
const changes = [];
|
|
22179
22354
|
documents.forEach(doc => {
|
|
22180
22355
|
changes.push({ type: 0 /* Added */, doc });
|
|
22181
22356
|
});
|
|
22182
22357
|
return new ViewSnapshot(query, documents, DocumentSet.emptySet(documents), changes, mutatedKeys, fromCache,
|
|
22183
22358
|
/* syncStateChanged= */ true,
|
|
22184
|
-
/* excludesMetadataChanges= */ false);
|
|
22359
|
+
/* excludesMetadataChanges= */ false, hasCachedResults);
|
|
22185
22360
|
}
|
|
22186
22361
|
get hasPendingWrites() {
|
|
22187
22362
|
return !this.mutatedKeys.isEmpty();
|
|
22188
22363
|
}
|
|
22189
22364
|
isEqual(other) {
|
|
22190
22365
|
if (this.fromCache !== other.fromCache ||
|
|
22366
|
+
this.hasCachedResults !== other.hasCachedResults ||
|
|
22191
22367
|
this.syncStateChanged !== other.syncStateChanged ||
|
|
22192
22368
|
!this.mutatedKeys.isEqual(other.mutatedKeys) ||
|
|
22193
22369
|
!queryEquals(this.query, other.query) ||
|
|
@@ -22392,7 +22568,7 @@ class QueryListener {
|
|
|
22392
22568
|
}
|
|
22393
22569
|
}
|
|
22394
22570
|
snap = new ViewSnapshot(snap.query, snap.docs, snap.oldDocs, docChanges, snap.mutatedKeys, snap.fromCache, snap.syncStateChanged,
|
|
22395
|
-
/* excludesMetadataChanges= */ true);
|
|
22571
|
+
/* excludesMetadataChanges= */ true, snap.hasCachedResults);
|
|
22396
22572
|
}
|
|
22397
22573
|
let raisedEvent = false;
|
|
22398
22574
|
if (!this.raisedInitialEvent) {
|
|
@@ -22436,8 +22612,11 @@ class QueryListener {
|
|
|
22436
22612
|
if (this.options.waitForSyncWhenOnline && maybeOnline) {
|
|
22437
22613
|
return false;
|
|
22438
22614
|
}
|
|
22439
|
-
// Raise data from cache if we have any documents
|
|
22440
|
-
|
|
22615
|
+
// Raise data from cache if we have any documents, have cached results before,
|
|
22616
|
+
// or we are offline.
|
|
22617
|
+
return (!snap.docs.isEmpty() ||
|
|
22618
|
+
snap.hasCachedResults ||
|
|
22619
|
+
onlineState === "Offline" /* Offline */);
|
|
22441
22620
|
}
|
|
22442
22621
|
shouldRaiseEvent(snap) {
|
|
22443
22622
|
// We don't need to handle includeDocumentMetadataChanges here because
|
|
@@ -22457,7 +22636,7 @@ class QueryListener {
|
|
|
22457
22636
|
return false;
|
|
22458
22637
|
}
|
|
22459
22638
|
raiseInitialEvent(snap) {
|
|
22460
|
-
snap = ViewSnapshot.fromInitialDocuments(snap.query, snap.docs, snap.mutatedKeys, snap.fromCache);
|
|
22639
|
+
snap = ViewSnapshot.fromInitialDocuments(snap.query, snap.docs, snap.mutatedKeys, snap.fromCache, snap.hasCachedResults);
|
|
22461
22640
|
this.raisedInitialEvent = true;
|
|
22462
22641
|
this.queryObserver.next(snap);
|
|
22463
22642
|
}
|
|
@@ -22694,6 +22873,7 @@ class View {
|
|
|
22694
22873
|
this.query = query;
|
|
22695
22874
|
this._syncedDocuments = _syncedDocuments;
|
|
22696
22875
|
this.syncState = null;
|
|
22876
|
+
this.hasCachedResults = false;
|
|
22697
22877
|
/**
|
|
22698
22878
|
* A flag whether the view is current with the backend. A view is considered
|
|
22699
22879
|
* current after it has seen the current flag from the backend and did not
|
|
@@ -22888,7 +23068,9 @@ class View {
|
|
|
22888
23068
|
}
|
|
22889
23069
|
else {
|
|
22890
23070
|
const snap = new ViewSnapshot(this.query, docChanges.documentSet, oldDocs, changes, docChanges.mutatedKeys, newSyncState === 0 /* Local */, syncStateChanged,
|
|
22891
|
-
/* excludesMetadataChanges= */ false
|
|
23071
|
+
/* excludesMetadataChanges= */ false, targetChange
|
|
23072
|
+
? targetChange.resumeToken.approximateByteSize() > 0
|
|
23073
|
+
: false);
|
|
22892
23074
|
return {
|
|
22893
23075
|
snapshot: snap,
|
|
22894
23076
|
limboChanges
|
|
@@ -23015,7 +23197,7 @@ class View {
|
|
|
23015
23197
|
*/
|
|
23016
23198
|
// PORTING NOTE: Multi-tab only.
|
|
23017
23199
|
computeInitialSnapshot() {
|
|
23018
|
-
return ViewSnapshot.fromInitialDocuments(this.query, this.documentSet, this.mutatedKeys, this.syncState === 0 /* Local
|
|
23200
|
+
return ViewSnapshot.fromInitialDocuments(this.query, this.documentSet, this.mutatedKeys, this.syncState === 0 /* Local */, this.hasCachedResults);
|
|
23019
23201
|
}
|
|
23020
23202
|
}
|
|
23021
23203
|
function compareChangeType(c1, c2) {
|
|
@@ -23195,7 +23377,7 @@ async function syncEngineListen(syncEngine, query) {
|
|
|
23195
23377
|
}
|
|
23196
23378
|
const status = syncEngineImpl.sharedClientState.addLocalQueryTarget(targetData.targetId);
|
|
23197
23379
|
targetId = targetData.targetId;
|
|
23198
|
-
viewSnapshot = await initializeViewAndComputeSnapshot(syncEngineImpl, query, targetId, status === 'current');
|
|
23380
|
+
viewSnapshot = await initializeViewAndComputeSnapshot(syncEngineImpl, query, targetId, status === 'current', targetData.resumeToken);
|
|
23199
23381
|
}
|
|
23200
23382
|
return viewSnapshot;
|
|
23201
23383
|
}
|
|
@@ -23203,7 +23385,7 @@ async function syncEngineListen(syncEngine, query) {
|
|
|
23203
23385
|
* Registers a view for a previously unknown query and computes its initial
|
|
23204
23386
|
* snapshot.
|
|
23205
23387
|
*/
|
|
23206
|
-
async function initializeViewAndComputeSnapshot(syncEngineImpl, query, targetId, current) {
|
|
23388
|
+
async function initializeViewAndComputeSnapshot(syncEngineImpl, query, targetId, current, resumeToken) {
|
|
23207
23389
|
// PORTING NOTE: On Web only, we inject the code that registers new Limbo
|
|
23208
23390
|
// targets based on view changes. This allows us to only depend on Limbo
|
|
23209
23391
|
// changes when user code includes queries.
|
|
@@ -23212,7 +23394,7 @@ async function initializeViewAndComputeSnapshot(syncEngineImpl, query, targetId,
|
|
|
23212
23394
|
/* usePreviousResults= */ true);
|
|
23213
23395
|
const view = new View(query, queryResult.remoteKeys);
|
|
23214
23396
|
const viewDocChanges = view.computeDocChanges(queryResult.documents);
|
|
23215
|
-
const synthesizedTargetChange = TargetChange.createSynthesizedTargetChangeForCurrentChange(targetId, current && syncEngineImpl.onlineState !== "Offline" /* Offline
|
|
23397
|
+
const synthesizedTargetChange = TargetChange.createSynthesizedTargetChangeForCurrentChange(targetId, current && syncEngineImpl.onlineState !== "Offline" /* Offline */, resumeToken);
|
|
23216
23398
|
const viewChange = view.applyChanges(viewDocChanges,
|
|
23217
23399
|
/* updateLimboDocuments= */ syncEngineImpl.isPrimaryClient, synthesizedTargetChange);
|
|
23218
23400
|
updateTrackedLimbos(syncEngineImpl, targetId, viewChange.limboChanges);
|
|
@@ -23624,10 +23806,15 @@ async function syncEngineEmitNewSnapsAndNotifyLocalStore(syncEngine, changes, re
|
|
|
23624
23806
|
queriesProcessed.push(syncEngineImpl
|
|
23625
23807
|
.applyDocChanges(queryView, changes, remoteEvent)
|
|
23626
23808
|
.then(viewSnapshot => {
|
|
23627
|
-
|
|
23809
|
+
// If there are changes, or we are handling a global snapshot, notify
|
|
23810
|
+
// secondary clients to update query state.
|
|
23811
|
+
if (viewSnapshot || remoteEvent) {
|
|
23628
23812
|
if (syncEngineImpl.isPrimaryClient) {
|
|
23629
|
-
syncEngineImpl.sharedClientState.updateQueryState(queryView.targetId, viewSnapshot.fromCache ? 'not-current' : 'current');
|
|
23813
|
+
syncEngineImpl.sharedClientState.updateQueryState(queryView.targetId, (viewSnapshot === null || viewSnapshot === void 0 ? void 0 : viewSnapshot.fromCache) ? 'not-current' : 'current');
|
|
23630
23814
|
}
|
|
23815
|
+
}
|
|
23816
|
+
// Update views if there are actual changes.
|
|
23817
|
+
if (!!viewSnapshot) {
|
|
23631
23818
|
newSnaps.push(viewSnapshot);
|
|
23632
23819
|
const docChanges = LocalViewChanges.fromSnapshot(queryView.targetId, viewSnapshot);
|
|
23633
23820
|
docChangesInAllViews.push(docChanges);
|
|
@@ -23837,7 +24024,7 @@ async function synchronizeQueryViewsAndRaiseSnapshots(syncEngine, targets, trans
|
|
|
23837
24024
|
const target = await localStoreGetCachedTarget(syncEngineImpl.localStore, targetId);
|
|
23838
24025
|
targetData = await localStoreAllocateTarget(syncEngineImpl.localStore, target);
|
|
23839
24026
|
await initializeViewAndComputeSnapshot(syncEngineImpl, synthesizeTargetToQuery(target), targetId,
|
|
23840
|
-
/*current=*/ false);
|
|
24027
|
+
/*current=*/ false, targetData.resumeToken);
|
|
23841
24028
|
}
|
|
23842
24029
|
activeQueries.push(targetData);
|
|
23843
24030
|
}
|
|
@@ -23880,7 +24067,7 @@ async function syncEngineApplyTargetState(syncEngine, targetId, state, error) {
|
|
|
23880
24067
|
case 'current':
|
|
23881
24068
|
case 'not-current': {
|
|
23882
24069
|
const changes = await localStoreGetNewDocumentChanges(syncEngineImpl.localStore, queryCollectionGroup(query[0]));
|
|
23883
|
-
const synthesizedRemoteEvent = RemoteEvent.createSynthesizedRemoteEventForCurrentChange(targetId, state === 'current');
|
|
24070
|
+
const synthesizedRemoteEvent = RemoteEvent.createSynthesizedRemoteEventForCurrentChange(targetId, state === 'current', ByteString.EMPTY_BYTE_STRING);
|
|
23884
24071
|
await syncEngineEmitNewSnapsAndNotifyLocalStore(syncEngineImpl, changes, synthesizedRemoteEvent);
|
|
23885
24072
|
break;
|
|
23886
24073
|
}
|
|
@@ -23910,7 +24097,7 @@ async function syncEngineApplyActiveTargetsChange(syncEngine, added, removed) {
|
|
|
23910
24097
|
const target = await localStoreGetCachedTarget(syncEngineImpl.localStore, targetId);
|
|
23911
24098
|
const targetData = await localStoreAllocateTarget(syncEngineImpl.localStore, target);
|
|
23912
24099
|
await initializeViewAndComputeSnapshot(syncEngineImpl, synthesizeTargetToQuery(target), targetData.targetId,
|
|
23913
|
-
/*current=*/ false);
|
|
24100
|
+
/*current=*/ false, targetData.resumeToken);
|
|
23914
24101
|
remoteStoreListen(syncEngineImpl.remoteStore, targetData);
|
|
23915
24102
|
}
|
|
23916
24103
|
for (const targetId of removed) {
|
|
@@ -24673,6 +24860,100 @@ function newBundleReader(reader, serializer) {
|
|
|
24673
24860
|
return new BundleReaderImpl(reader, serializer);
|
|
24674
24861
|
}
|
|
24675
24862
|
|
|
24863
|
+
/**
|
|
24864
|
+
* @license
|
|
24865
|
+
* Copyright 2022 Google LLC
|
|
24866
|
+
*
|
|
24867
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
24868
|
+
* you may not use this file except in compliance with the License.
|
|
24869
|
+
* You may obtain a copy of the License at
|
|
24870
|
+
*
|
|
24871
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
24872
|
+
*
|
|
24873
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
24874
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
24875
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
24876
|
+
* See the License for the specific language governing permissions and
|
|
24877
|
+
* limitations under the License.
|
|
24878
|
+
*/
|
|
24879
|
+
/**
|
|
24880
|
+
* Represents an aggregation that can be performed by Firestore.
|
|
24881
|
+
*/
|
|
24882
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
24883
|
+
class AggregateField {
|
|
24884
|
+
constructor() {
|
|
24885
|
+
/** A type string to uniquely identify instances of this class. */
|
|
24886
|
+
this.type = 'AggregateField';
|
|
24887
|
+
}
|
|
24888
|
+
}
|
|
24889
|
+
/**
|
|
24890
|
+
* The results of executing an aggregation query.
|
|
24891
|
+
*/
|
|
24892
|
+
class AggregateQuerySnapshot {
|
|
24893
|
+
/** @hideconstructor */
|
|
24894
|
+
constructor(query, _data) {
|
|
24895
|
+
this._data = _data;
|
|
24896
|
+
/** A type string to uniquely identify instances of this class. */
|
|
24897
|
+
this.type = 'AggregateQuerySnapshot';
|
|
24898
|
+
this.query = query;
|
|
24899
|
+
}
|
|
24900
|
+
/**
|
|
24901
|
+
* Returns the results of the aggregations performed over the underlying
|
|
24902
|
+
* query.
|
|
24903
|
+
*
|
|
24904
|
+
* The keys of the returned object will be the same as those of the
|
|
24905
|
+
* `AggregateSpec` object specified to the aggregation method, and the values
|
|
24906
|
+
* will be the corresponding aggregation result.
|
|
24907
|
+
*
|
|
24908
|
+
* @returns The results of the aggregations performed over the underlying
|
|
24909
|
+
* query.
|
|
24910
|
+
*/
|
|
24911
|
+
data() {
|
|
24912
|
+
return this._data;
|
|
24913
|
+
}
|
|
24914
|
+
}
|
|
24915
|
+
|
|
24916
|
+
/**
|
|
24917
|
+
* @license
|
|
24918
|
+
* Copyright 2022 Google LLC
|
|
24919
|
+
*
|
|
24920
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
24921
|
+
* you may not use this file except in compliance with the License.
|
|
24922
|
+
* You may obtain a copy of the License at
|
|
24923
|
+
*
|
|
24924
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
24925
|
+
*
|
|
24926
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
24927
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
24928
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
24929
|
+
* See the License for the specific language governing permissions and
|
|
24930
|
+
* limitations under the License.
|
|
24931
|
+
*/
|
|
24932
|
+
/**
|
|
24933
|
+
* CountQueryRunner encapsulates the logic needed to run the count aggregation
|
|
24934
|
+
* queries.
|
|
24935
|
+
*/
|
|
24936
|
+
class CountQueryRunner {
|
|
24937
|
+
constructor(query, datastore, userDataWriter) {
|
|
24938
|
+
this.query = query;
|
|
24939
|
+
this.datastore = datastore;
|
|
24940
|
+
this.userDataWriter = userDataWriter;
|
|
24941
|
+
}
|
|
24942
|
+
run() {
|
|
24943
|
+
return invokeRunAggregationQueryRpc(this.datastore, this.query._query).then(result => {
|
|
24944
|
+
hardAssert(result[0] !== undefined);
|
|
24945
|
+
const counts = Object.entries(result[0])
|
|
24946
|
+
.filter(([key, value]) => key === 'count_alias')
|
|
24947
|
+
.map(([key, value]) => this.userDataWriter.convertValue(value));
|
|
24948
|
+
const countValue = counts[0];
|
|
24949
|
+
hardAssert(typeof countValue === 'number');
|
|
24950
|
+
return Promise.resolve(new AggregateQuerySnapshot(this.query, {
|
|
24951
|
+
count: countValue
|
|
24952
|
+
}));
|
|
24953
|
+
});
|
|
24954
|
+
}
|
|
24955
|
+
}
|
|
24956
|
+
|
|
24676
24957
|
/**
|
|
24677
24958
|
* @license
|
|
24678
24959
|
* Copyright 2017 Google LLC
|
|
@@ -25229,6 +25510,26 @@ function firestoreClientTransaction(client, updateFunction, options) {
|
|
|
25229
25510
|
});
|
|
25230
25511
|
return deferred.promise;
|
|
25231
25512
|
}
|
|
25513
|
+
function firestoreClientRunCountQuery(client, query, userDataWriter) {
|
|
25514
|
+
const deferred = new Deferred();
|
|
25515
|
+
client.asyncQueue.enqueueAndForget(async () => {
|
|
25516
|
+
try {
|
|
25517
|
+
const remoteStore = await getRemoteStore(client);
|
|
25518
|
+
if (!canUseNetwork(remoteStore)) {
|
|
25519
|
+
deferred.reject(new FirestoreError(Code.UNAVAILABLE, 'Failed to get count result because the client is offline.'));
|
|
25520
|
+
}
|
|
25521
|
+
else {
|
|
25522
|
+
const datastore = await getDatastore(client);
|
|
25523
|
+
const result = new CountQueryRunner(query, datastore, userDataWriter).run();
|
|
25524
|
+
deferred.resolve(result);
|
|
25525
|
+
}
|
|
25526
|
+
}
|
|
25527
|
+
catch (e) {
|
|
25528
|
+
deferred.reject(e);
|
|
25529
|
+
}
|
|
25530
|
+
});
|
|
25531
|
+
return deferred.promise;
|
|
25532
|
+
}
|
|
25232
25533
|
async function readDocumentFromCache(localStore, docKey, result) {
|
|
25233
25534
|
try {
|
|
25234
25535
|
const document = await localStoreReadDocument(localStore, docKey);
|
|
@@ -25484,7 +25785,7 @@ class FirestoreSettingsImpl {
|
|
|
25484
25785
|
/**
|
|
25485
25786
|
* The Cloud Firestore service interface.
|
|
25486
25787
|
*
|
|
25487
|
-
* Do not call this constructor directly. Instead, use {@link getFirestore}.
|
|
25788
|
+
* Do not call this constructor directly. Instead, use {@link (getFirestore:1)}.
|
|
25488
25789
|
*/
|
|
25489
25790
|
class Firestore$1 {
|
|
25490
25791
|
/** @hideconstructor */
|
|
@@ -26226,7 +26527,7 @@ const CACHE_SIZE_UNLIMITED = LRU_COLLECTION_DISABLED;
|
|
|
26226
26527
|
/**
|
|
26227
26528
|
* The Cloud Firestore service interface.
|
|
26228
26529
|
*
|
|
26229
|
-
* Do not call this constructor directly. Instead, use {@link getFirestore}.
|
|
26530
|
+
* Do not call this constructor directly. Instead, use {@link (getFirestore:1)}.
|
|
26230
26531
|
*/
|
|
26231
26532
|
class Firestore extends Firestore$1 {
|
|
26232
26533
|
/** @hideconstructor */
|
|
@@ -26251,8 +26552,8 @@ class Firestore extends Firestore$1 {
|
|
|
26251
26552
|
/**
|
|
26252
26553
|
* Initializes a new instance of {@link Firestore} with the provided settings.
|
|
26253
26554
|
* Can only be called before any other function, including
|
|
26254
|
-
* {@link getFirestore}. If the custom settings are empty, this function is
|
|
26255
|
-
* equivalent to calling {@link getFirestore}.
|
|
26555
|
+
* {@link (getFirestore:1)}. If the custom settings are empty, this function is
|
|
26556
|
+
* equivalent to calling {@link (getFirestore:1)}.
|
|
26256
26557
|
*
|
|
26257
26558
|
* @param app - The {@link @firebase/app#FirebaseApp} with which the {@link Firestore} instance will
|
|
26258
26559
|
* be associated.
|
|
@@ -26295,9 +26596,17 @@ function getFirestore(appOrDatabaseId, optionalDatabaseId) {
|
|
|
26295
26596
|
const databaseId = typeof appOrDatabaseId === 'string'
|
|
26296
26597
|
? appOrDatabaseId
|
|
26297
26598
|
: optionalDatabaseId || DEFAULT_DATABASE_NAME;
|
|
26298
|
-
|
|
26599
|
+
const db = _getProvider(app, 'firestore').getImmediate({
|
|
26299
26600
|
identifier: databaseId
|
|
26300
26601
|
});
|
|
26602
|
+
if (!db._initialized) {
|
|
26603
|
+
const firestoreEmulatorHost = getDefaultEmulatorHost('firestore');
|
|
26604
|
+
if (firestoreEmulatorHost) {
|
|
26605
|
+
const [host, port] = firestoreEmulatorHost.split(':');
|
|
26606
|
+
connectFirestoreEmulator(db, host, parseInt(port, 10));
|
|
26607
|
+
}
|
|
26608
|
+
}
|
|
26609
|
+
return db;
|
|
26301
26610
|
}
|
|
26302
26611
|
/**
|
|
26303
26612
|
* @internal
|
|
@@ -26319,7 +26628,7 @@ function configureFirestore(firestore) {
|
|
|
26319
26628
|
* Attempts to enable persistent storage, if possible.
|
|
26320
26629
|
*
|
|
26321
26630
|
* Must be called before any other functions (other than
|
|
26322
|
-
* {@link initializeFirestore}, {@link getFirestore} or
|
|
26631
|
+
* {@link initializeFirestore}, {@link (getFirestore:1)} or
|
|
26323
26632
|
* {@link clearIndexedDbPersistence}.
|
|
26324
26633
|
*
|
|
26325
26634
|
* If this fails, `enableIndexedDbPersistence()` will reject the promise it
|
|
@@ -26443,7 +26752,7 @@ function canFallbackFromIndexedDbError(error) {
|
|
|
26443
26752
|
* Must be called while the {@link Firestore} instance is not started (after the app is
|
|
26444
26753
|
* terminated or when the app is first initialized). On startup, this function
|
|
26445
26754
|
* must be called before other functions (other than {@link
|
|
26446
|
-
* initializeFirestore} or {@link getFirestore})). If the {@link Firestore}
|
|
26755
|
+
* initializeFirestore} or {@link (getFirestore:1)})). If the {@link Firestore}
|
|
26447
26756
|
* instance is still running, the promise will be rejected with the error code
|
|
26448
26757
|
* of `failed-precondition`.
|
|
26449
26758
|
*
|
|
@@ -26527,7 +26836,7 @@ function disableNetwork(firestore) {
|
|
|
26527
26836
|
* may be used. Any other function will throw a `FirestoreError`.
|
|
26528
26837
|
*
|
|
26529
26838
|
* To restart after termination, create a new instance of FirebaseFirestore with
|
|
26530
|
-
* {@link getFirestore}.
|
|
26839
|
+
* {@link (getFirestore:1)}.
|
|
26531
26840
|
*
|
|
26532
26841
|
* Termination does not cancel any pending writes, and any promises that are
|
|
26533
26842
|
* awaiting a response from the server will not be resolved. If you have
|
|
@@ -26626,7 +26935,7 @@ function registerFirestore(variant, useFetchStreams = true) {
|
|
|
26626
26935
|
|
|
26627
26936
|
/**
|
|
26628
26937
|
* @license
|
|
26629
|
-
* Copyright
|
|
26938
|
+
* Copyright 2017 Google LLC
|
|
26630
26939
|
*
|
|
26631
26940
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
26632
26941
|
* you may not use this file except in compliance with the License.
|
|
@@ -26640,46 +26949,24 @@ function registerFirestore(variant, useFetchStreams = true) {
|
|
|
26640
26949
|
* See the License for the specific language governing permissions and
|
|
26641
26950
|
* limitations under the License.
|
|
26642
26951
|
*/
|
|
26952
|
+
function isPartialObserver(obj) {
|
|
26953
|
+
return implementsAnyMethods(obj, ['next', 'error', 'complete']);
|
|
26954
|
+
}
|
|
26643
26955
|
/**
|
|
26644
|
-
*
|
|
26645
|
-
*
|
|
26646
|
-
* list of field names (referring to a nested field in the document).
|
|
26647
|
-
*
|
|
26648
|
-
* Create a `FieldPath` by providing field names. If more than one field
|
|
26649
|
-
* name is provided, the path will point to a nested field in a document.
|
|
26956
|
+
* Returns true if obj is an object and contains at least one of the specified
|
|
26957
|
+
* methods.
|
|
26650
26958
|
*/
|
|
26651
|
-
|
|
26652
|
-
|
|
26653
|
-
|
|
26654
|
-
* name is provided, the path will point to a nested field in a document.
|
|
26655
|
-
*
|
|
26656
|
-
* @param fieldNames - A list of field names.
|
|
26657
|
-
*/
|
|
26658
|
-
constructor(...fieldNames) {
|
|
26659
|
-
for (let i = 0; i < fieldNames.length; ++i) {
|
|
26660
|
-
if (fieldNames[i].length === 0) {
|
|
26661
|
-
throw new FirestoreError(Code.INVALID_ARGUMENT, `Invalid field name at argument $(i + 1). ` +
|
|
26662
|
-
'Field names must not be empty.');
|
|
26663
|
-
}
|
|
26664
|
-
}
|
|
26665
|
-
this._internalPath = new FieldPath$1(fieldNames);
|
|
26959
|
+
function implementsAnyMethods(obj, methods) {
|
|
26960
|
+
if (typeof obj !== 'object' || obj === null) {
|
|
26961
|
+
return false;
|
|
26666
26962
|
}
|
|
26667
|
-
|
|
26668
|
-
|
|
26669
|
-
|
|
26670
|
-
|
|
26671
|
-
|
|
26672
|
-
*/
|
|
26673
|
-
isEqual(other) {
|
|
26674
|
-
return this._internalPath.isEqual(other._internalPath);
|
|
26963
|
+
const object = obj;
|
|
26964
|
+
for (const method of methods) {
|
|
26965
|
+
if (method in object && typeof object[method] === 'function') {
|
|
26966
|
+
return true;
|
|
26967
|
+
}
|
|
26675
26968
|
}
|
|
26676
|
-
|
|
26677
|
-
/**
|
|
26678
|
-
* Returns a special sentinel `FieldPath` to refer to the ID of a document.
|
|
26679
|
-
* It can be used in queries to sort or filter by the document ID.
|
|
26680
|
-
*/
|
|
26681
|
-
function documentId() {
|
|
26682
|
-
return new FieldPath(DOCUMENT_KEY_NAME);
|
|
26969
|
+
return false;
|
|
26683
26970
|
}
|
|
26684
26971
|
|
|
26685
26972
|
/**
|
|
@@ -26780,11 +27067,69 @@ class Bytes {
|
|
|
26780
27067
|
* limitations under the License.
|
|
26781
27068
|
*/
|
|
26782
27069
|
/**
|
|
26783
|
-
*
|
|
26784
|
-
*
|
|
26785
|
-
|
|
26786
|
-
|
|
26787
|
-
|
|
27070
|
+
* A `FieldPath` refers to a field in a document. The path may consist of a
|
|
27071
|
+
* single field name (referring to a top-level field in the document), or a
|
|
27072
|
+
* list of field names (referring to a nested field in the document).
|
|
27073
|
+
*
|
|
27074
|
+
* Create a `FieldPath` by providing field names. If more than one field
|
|
27075
|
+
* name is provided, the path will point to a nested field in a document.
|
|
27076
|
+
*/
|
|
27077
|
+
class FieldPath {
|
|
27078
|
+
/**
|
|
27079
|
+
* Creates a `FieldPath` from the provided field names. If more than one field
|
|
27080
|
+
* name is provided, the path will point to a nested field in a document.
|
|
27081
|
+
*
|
|
27082
|
+
* @param fieldNames - A list of field names.
|
|
27083
|
+
*/
|
|
27084
|
+
constructor(...fieldNames) {
|
|
27085
|
+
for (let i = 0; i < fieldNames.length; ++i) {
|
|
27086
|
+
if (fieldNames[i].length === 0) {
|
|
27087
|
+
throw new FirestoreError(Code.INVALID_ARGUMENT, `Invalid field name at argument $(i + 1). ` +
|
|
27088
|
+
'Field names must not be empty.');
|
|
27089
|
+
}
|
|
27090
|
+
}
|
|
27091
|
+
this._internalPath = new FieldPath$1(fieldNames);
|
|
27092
|
+
}
|
|
27093
|
+
/**
|
|
27094
|
+
* Returns true if this `FieldPath` is equal to the provided one.
|
|
27095
|
+
*
|
|
27096
|
+
* @param other - The `FieldPath` to compare against.
|
|
27097
|
+
* @returns true if this `FieldPath` is equal to the provided one.
|
|
27098
|
+
*/
|
|
27099
|
+
isEqual(other) {
|
|
27100
|
+
return this._internalPath.isEqual(other._internalPath);
|
|
27101
|
+
}
|
|
27102
|
+
}
|
|
27103
|
+
/**
|
|
27104
|
+
* Returns a special sentinel `FieldPath` to refer to the ID of a document.
|
|
27105
|
+
* It can be used in queries to sort or filter by the document ID.
|
|
27106
|
+
*/
|
|
27107
|
+
function documentId() {
|
|
27108
|
+
return new FieldPath(DOCUMENT_KEY_NAME);
|
|
27109
|
+
}
|
|
27110
|
+
|
|
27111
|
+
/**
|
|
27112
|
+
* @license
|
|
27113
|
+
* Copyright 2020 Google LLC
|
|
27114
|
+
*
|
|
27115
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
27116
|
+
* you may not use this file except in compliance with the License.
|
|
27117
|
+
* You may obtain a copy of the License at
|
|
27118
|
+
*
|
|
27119
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
27120
|
+
*
|
|
27121
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
27122
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
27123
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
27124
|
+
* See the License for the specific language governing permissions and
|
|
27125
|
+
* limitations under the License.
|
|
27126
|
+
*/
|
|
27127
|
+
/**
|
|
27128
|
+
* Sentinel values that can be used when writing document fields with `set()`
|
|
27129
|
+
* or `update()`.
|
|
27130
|
+
*/
|
|
27131
|
+
class FieldValue {
|
|
27132
|
+
/**
|
|
26788
27133
|
* @param _methodName - The public API endpoint that returns this class.
|
|
26789
27134
|
* @hideconstructor
|
|
26790
27135
|
*/
|
|
@@ -27685,378 +28030,87 @@ function fieldPathFromArgument(methodName, arg) {
|
|
|
27685
28030
|
* See the License for the specific language governing permissions and
|
|
27686
28031
|
* limitations under the License.
|
|
27687
28032
|
*/
|
|
28033
|
+
function validateHasExplicitOrderByForLimitToLast(query) {
|
|
28034
|
+
if (query.limitType === "L" /* Last */ &&
|
|
28035
|
+
query.explicitOrderBy.length === 0) {
|
|
28036
|
+
throw new FirestoreError(Code.UNIMPLEMENTED, 'limitToLast() queries require specifying at least one orderBy() clause');
|
|
28037
|
+
}
|
|
28038
|
+
}
|
|
27688
28039
|
/**
|
|
27689
|
-
*
|
|
28040
|
+
* A `QueryConstraint` is used to narrow the set of documents returned by a
|
|
28041
|
+
* Firestore query. `QueryConstraint`s are created by invoking {@link where},
|
|
28042
|
+
* {@link orderBy}, {@link (startAt:1)}, {@link (startAfter:1)}, {@link
|
|
28043
|
+
* endBefore:1}, {@link (endAt:1)}, {@link limit} or {@link limitToLast} and
|
|
28044
|
+
* can then be passed to {@link query} to create a new query instance that
|
|
28045
|
+
* also contains this `QueryConstraint`.
|
|
27690
28046
|
*/
|
|
27691
|
-
class
|
|
27692
|
-
/** @hideconstructor */
|
|
27693
|
-
constructor(hasPendingWrites, fromCache) {
|
|
27694
|
-
this.hasPendingWrites = hasPendingWrites;
|
|
27695
|
-
this.fromCache = fromCache;
|
|
27696
|
-
}
|
|
27697
|
-
/**
|
|
27698
|
-
* Returns true if this `SnapshotMetadata` is equal to the provided one.
|
|
27699
|
-
*
|
|
27700
|
-
* @param other - The `SnapshotMetadata` to compare against.
|
|
27701
|
-
* @returns true if this `SnapshotMetadata` is equal to the provided one.
|
|
27702
|
-
*/
|
|
27703
|
-
isEqual(other) {
|
|
27704
|
-
return (this.hasPendingWrites === other.hasPendingWrites &&
|
|
27705
|
-
this.fromCache === other.fromCache);
|
|
27706
|
-
}
|
|
28047
|
+
class QueryConstraint {
|
|
27707
28048
|
}
|
|
27708
28049
|
/**
|
|
27709
|
-
*
|
|
27710
|
-
*
|
|
27711
|
-
* get a specific field.
|
|
28050
|
+
* Creates a new immutable instance of {@link Query} that is extended to also include
|
|
28051
|
+
* additional query constraints.
|
|
27712
28052
|
*
|
|
27713
|
-
*
|
|
27714
|
-
*
|
|
27715
|
-
*
|
|
28053
|
+
* @param query - The {@link Query} instance to use as a base for the new constraints.
|
|
28054
|
+
* @param queryConstraints - The list of {@link QueryConstraint}s to apply.
|
|
28055
|
+
* @throws if any of the provided query constraints cannot be combined with the
|
|
28056
|
+
* existing or new constraints.
|
|
27716
28057
|
*/
|
|
27717
|
-
|
|
27718
|
-
|
|
27719
|
-
|
|
27720
|
-
super(_firestore, userDataWriter, key, document, converter);
|
|
27721
|
-
this._firestore = _firestore;
|
|
27722
|
-
this._firestoreImpl = _firestore;
|
|
27723
|
-
this.metadata = metadata;
|
|
27724
|
-
}
|
|
27725
|
-
/**
|
|
27726
|
-
* Returns whether or not the data exists. True if the document exists.
|
|
27727
|
-
*/
|
|
27728
|
-
exists() {
|
|
27729
|
-
return super.exists();
|
|
28058
|
+
function query(query, ...queryConstraints) {
|
|
28059
|
+
for (const constraint of queryConstraints) {
|
|
28060
|
+
query = constraint._apply(query);
|
|
27730
28061
|
}
|
|
27731
|
-
|
|
27732
|
-
|
|
27733
|
-
|
|
27734
|
-
|
|
27735
|
-
|
|
27736
|
-
|
|
27737
|
-
|
|
27738
|
-
|
|
27739
|
-
|
|
27740
|
-
* the snapshot (for example the desired behavior for server timestamps that
|
|
27741
|
-
* have not yet been set to their final value).
|
|
27742
|
-
* @returns An `Object` containing all fields in the document or `undefined` if
|
|
27743
|
-
* the document doesn't exist.
|
|
27744
|
-
*/
|
|
27745
|
-
data(options = {}) {
|
|
27746
|
-
if (!this._document) {
|
|
27747
|
-
return undefined;
|
|
27748
|
-
}
|
|
27749
|
-
else if (this._converter) {
|
|
27750
|
-
// We only want to use the converter and create a new DocumentSnapshot
|
|
27751
|
-
// if a converter has been provided.
|
|
27752
|
-
const snapshot = new QueryDocumentSnapshot(this._firestore, this._userDataWriter, this._key, this._document, this.metadata,
|
|
27753
|
-
/* converter= */ null);
|
|
27754
|
-
return this._converter.fromFirestore(snapshot, options);
|
|
27755
|
-
}
|
|
27756
|
-
else {
|
|
27757
|
-
return this._userDataWriter.convertValue(this._document.data.value, options.serverTimestamps);
|
|
27758
|
-
}
|
|
28062
|
+
return query;
|
|
28063
|
+
}
|
|
28064
|
+
class QueryFilterConstraint extends QueryConstraint {
|
|
28065
|
+
constructor(_field, _op, _value) {
|
|
28066
|
+
super();
|
|
28067
|
+
this._field = _field;
|
|
28068
|
+
this._op = _op;
|
|
28069
|
+
this._value = _value;
|
|
28070
|
+
this.type = 'where';
|
|
27759
28071
|
}
|
|
27760
|
-
|
|
27761
|
-
|
|
27762
|
-
|
|
27763
|
-
|
|
27764
|
-
* By default, a `serverTimestamp()` that has not yet been set to
|
|
27765
|
-
* its final value will be returned as `null`. You can override this by
|
|
27766
|
-
* passing an options object.
|
|
27767
|
-
*
|
|
27768
|
-
* @param fieldPath - The path (for example 'foo' or 'foo.bar') to a specific
|
|
27769
|
-
* field.
|
|
27770
|
-
* @param options - An options object to configure how the field is retrieved
|
|
27771
|
-
* from the snapshot (for example the desired behavior for server timestamps
|
|
27772
|
-
* that have not yet been set to their final value).
|
|
27773
|
-
* @returns The data at the specified field location or undefined if no such
|
|
27774
|
-
* field exists in the document.
|
|
27775
|
-
*/
|
|
27776
|
-
// We are using `any` here to avoid an explicit cast by our users.
|
|
27777
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
27778
|
-
get(fieldPath, options = {}) {
|
|
27779
|
-
if (this._document) {
|
|
27780
|
-
const value = this._document.data.field(fieldPathFromArgument('DocumentSnapshot.get', fieldPath));
|
|
27781
|
-
if (value !== null) {
|
|
27782
|
-
return this._userDataWriter.convertValue(value, options.serverTimestamps);
|
|
27783
|
-
}
|
|
27784
|
-
}
|
|
27785
|
-
return undefined;
|
|
28072
|
+
_apply(query) {
|
|
28073
|
+
const reader = newUserDataReader(query.firestore);
|
|
28074
|
+
const filter = newQueryFilter(query._query, 'where', reader, query.firestore._databaseId, this._field, this._op, this._value);
|
|
28075
|
+
return new Query(query.firestore, query.converter, queryWithAddedFilter(query._query, filter));
|
|
27786
28076
|
}
|
|
27787
28077
|
}
|
|
27788
28078
|
/**
|
|
27789
|
-
*
|
|
27790
|
-
*
|
|
27791
|
-
*
|
|
27792
|
-
* specific field.
|
|
28079
|
+
* Creates a {@link QueryConstraint} that enforces that documents must contain the
|
|
28080
|
+
* specified field and that the value should satisfy the relation constraint
|
|
28081
|
+
* provided.
|
|
27793
28082
|
*
|
|
27794
|
-
*
|
|
27795
|
-
*
|
|
27796
|
-
*
|
|
27797
|
-
*
|
|
28083
|
+
* @param fieldPath - The path to compare
|
|
28084
|
+
* @param opStr - The operation string (e.g "<", "<=", "==", "<",
|
|
28085
|
+
* "<=", "!=").
|
|
28086
|
+
* @param value - The value for comparison
|
|
28087
|
+
* @returns The created {@link Query}.
|
|
27798
28088
|
*/
|
|
27799
|
-
|
|
27800
|
-
|
|
27801
|
-
|
|
27802
|
-
|
|
27803
|
-
|
|
27804
|
-
|
|
27805
|
-
|
|
27806
|
-
|
|
27807
|
-
|
|
27808
|
-
|
|
27809
|
-
|
|
27810
|
-
|
|
27811
|
-
|
|
27812
|
-
|
|
27813
|
-
|
|
27814
|
-
return super.data(options);
|
|
28089
|
+
function where(fieldPath, opStr, value) {
|
|
28090
|
+
const op = opStr;
|
|
28091
|
+
const field = fieldPathFromArgument('where', fieldPath);
|
|
28092
|
+
return new QueryFilterConstraint(field, op, value);
|
|
28093
|
+
}
|
|
28094
|
+
class QueryOrderByConstraint extends QueryConstraint {
|
|
28095
|
+
constructor(_field, _direction) {
|
|
28096
|
+
super();
|
|
28097
|
+
this._field = _field;
|
|
28098
|
+
this._direction = _direction;
|
|
28099
|
+
this.type = 'orderBy';
|
|
28100
|
+
}
|
|
28101
|
+
_apply(query) {
|
|
28102
|
+
const orderBy = newQueryOrderBy(query._query, this._field, this._direction);
|
|
28103
|
+
return new Query(query.firestore, query.converter, queryWithAddedOrderBy(query._query, orderBy));
|
|
27815
28104
|
}
|
|
27816
28105
|
}
|
|
27817
28106
|
/**
|
|
27818
|
-
*
|
|
27819
|
-
*
|
|
27820
|
-
*
|
|
27821
|
-
*
|
|
27822
|
-
*
|
|
27823
|
-
|
|
27824
|
-
|
|
27825
|
-
/** @hideconstructor */
|
|
27826
|
-
constructor(_firestore, _userDataWriter, query, _snapshot) {
|
|
27827
|
-
this._firestore = _firestore;
|
|
27828
|
-
this._userDataWriter = _userDataWriter;
|
|
27829
|
-
this._snapshot = _snapshot;
|
|
27830
|
-
this.metadata = new SnapshotMetadata(_snapshot.hasPendingWrites, _snapshot.fromCache);
|
|
27831
|
-
this.query = query;
|
|
27832
|
-
}
|
|
27833
|
-
/** An array of all the documents in the `QuerySnapshot`. */
|
|
27834
|
-
get docs() {
|
|
27835
|
-
const result = [];
|
|
27836
|
-
this.forEach(doc => result.push(doc));
|
|
27837
|
-
return result;
|
|
27838
|
-
}
|
|
27839
|
-
/** The number of documents in the `QuerySnapshot`. */
|
|
27840
|
-
get size() {
|
|
27841
|
-
return this._snapshot.docs.size;
|
|
27842
|
-
}
|
|
27843
|
-
/** True if there are no documents in the `QuerySnapshot`. */
|
|
27844
|
-
get empty() {
|
|
27845
|
-
return this.size === 0;
|
|
27846
|
-
}
|
|
27847
|
-
/**
|
|
27848
|
-
* Enumerates all of the documents in the `QuerySnapshot`.
|
|
27849
|
-
*
|
|
27850
|
-
* @param callback - A callback to be called with a `QueryDocumentSnapshot` for
|
|
27851
|
-
* each document in the snapshot.
|
|
27852
|
-
* @param thisArg - The `this` binding for the callback.
|
|
27853
|
-
*/
|
|
27854
|
-
forEach(callback, thisArg) {
|
|
27855
|
-
this._snapshot.docs.forEach(doc => {
|
|
27856
|
-
callback.call(thisArg, new QueryDocumentSnapshot(this._firestore, this._userDataWriter, doc.key, doc, new SnapshotMetadata(this._snapshot.mutatedKeys.has(doc.key), this._snapshot.fromCache), this.query.converter));
|
|
27857
|
-
});
|
|
27858
|
-
}
|
|
27859
|
-
/**
|
|
27860
|
-
* Returns an array of the documents changes since the last snapshot. If this
|
|
27861
|
-
* is the first snapshot, all documents will be in the list as 'added'
|
|
27862
|
-
* changes.
|
|
27863
|
-
*
|
|
27864
|
-
* @param options - `SnapshotListenOptions` that control whether metadata-only
|
|
27865
|
-
* changes (i.e. only `DocumentSnapshot.metadata` changed) should trigger
|
|
27866
|
-
* snapshot events.
|
|
27867
|
-
*/
|
|
27868
|
-
docChanges(options = {}) {
|
|
27869
|
-
const includeMetadataChanges = !!options.includeMetadataChanges;
|
|
27870
|
-
if (includeMetadataChanges && this._snapshot.excludesMetadataChanges) {
|
|
27871
|
-
throw new FirestoreError(Code.INVALID_ARGUMENT, 'To include metadata changes with your document changes, you must ' +
|
|
27872
|
-
'also pass { includeMetadataChanges:true } to onSnapshot().');
|
|
27873
|
-
}
|
|
27874
|
-
if (!this._cachedChanges ||
|
|
27875
|
-
this._cachedChangesIncludeMetadataChanges !== includeMetadataChanges) {
|
|
27876
|
-
this._cachedChanges = changesFromSnapshot(this, includeMetadataChanges);
|
|
27877
|
-
this._cachedChangesIncludeMetadataChanges = includeMetadataChanges;
|
|
27878
|
-
}
|
|
27879
|
-
return this._cachedChanges;
|
|
27880
|
-
}
|
|
27881
|
-
}
|
|
27882
|
-
/** Calculates the array of `DocumentChange`s for a given `ViewSnapshot`. */
|
|
27883
|
-
function changesFromSnapshot(querySnapshot, includeMetadataChanges) {
|
|
27884
|
-
if (querySnapshot._snapshot.oldDocs.isEmpty()) {
|
|
27885
|
-
let index = 0;
|
|
27886
|
-
return querySnapshot._snapshot.docChanges.map(change => {
|
|
27887
|
-
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);
|
|
27888
|
-
return {
|
|
27889
|
-
type: 'added',
|
|
27890
|
-
doc,
|
|
27891
|
-
oldIndex: -1,
|
|
27892
|
-
newIndex: index++
|
|
27893
|
-
};
|
|
27894
|
-
});
|
|
27895
|
-
}
|
|
27896
|
-
else {
|
|
27897
|
-
// A `DocumentSet` that is updated incrementally as changes are applied to use
|
|
27898
|
-
// to lookup the index of a document.
|
|
27899
|
-
let indexTracker = querySnapshot._snapshot.oldDocs;
|
|
27900
|
-
return querySnapshot._snapshot.docChanges
|
|
27901
|
-
.filter(change => includeMetadataChanges || change.type !== 3 /* Metadata */)
|
|
27902
|
-
.map(change => {
|
|
27903
|
-
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);
|
|
27904
|
-
let oldIndex = -1;
|
|
27905
|
-
let newIndex = -1;
|
|
27906
|
-
if (change.type !== 0 /* Added */) {
|
|
27907
|
-
oldIndex = indexTracker.indexOf(change.doc.key);
|
|
27908
|
-
indexTracker = indexTracker.delete(change.doc.key);
|
|
27909
|
-
}
|
|
27910
|
-
if (change.type !== 1 /* Removed */) {
|
|
27911
|
-
indexTracker = indexTracker.add(change.doc);
|
|
27912
|
-
newIndex = indexTracker.indexOf(change.doc.key);
|
|
27913
|
-
}
|
|
27914
|
-
return {
|
|
27915
|
-
type: resultChangeType(change.type),
|
|
27916
|
-
doc,
|
|
27917
|
-
oldIndex,
|
|
27918
|
-
newIndex
|
|
27919
|
-
};
|
|
27920
|
-
});
|
|
27921
|
-
}
|
|
27922
|
-
}
|
|
27923
|
-
function resultChangeType(type) {
|
|
27924
|
-
switch (type) {
|
|
27925
|
-
case 0 /* Added */:
|
|
27926
|
-
return 'added';
|
|
27927
|
-
case 2 /* Modified */:
|
|
27928
|
-
case 3 /* Metadata */:
|
|
27929
|
-
return 'modified';
|
|
27930
|
-
case 1 /* Removed */:
|
|
27931
|
-
return 'removed';
|
|
27932
|
-
default:
|
|
27933
|
-
return fail();
|
|
27934
|
-
}
|
|
27935
|
-
}
|
|
27936
|
-
// TODO(firestoreexp): Add tests for snapshotEqual with different snapshot
|
|
27937
|
-
// metadata
|
|
27938
|
-
/**
|
|
27939
|
-
* Returns true if the provided snapshots are equal.
|
|
27940
|
-
*
|
|
27941
|
-
* @param left - A snapshot to compare.
|
|
27942
|
-
* @param right - A snapshot to compare.
|
|
27943
|
-
* @returns true if the snapshots are equal.
|
|
27944
|
-
*/
|
|
27945
|
-
function snapshotEqual(left, right) {
|
|
27946
|
-
if (left instanceof DocumentSnapshot && right instanceof DocumentSnapshot) {
|
|
27947
|
-
return (left._firestore === right._firestore &&
|
|
27948
|
-
left._key.isEqual(right._key) &&
|
|
27949
|
-
(left._document === null
|
|
27950
|
-
? right._document === null
|
|
27951
|
-
: left._document.isEqual(right._document)) &&
|
|
27952
|
-
left._converter === right._converter);
|
|
27953
|
-
}
|
|
27954
|
-
else if (left instanceof QuerySnapshot && right instanceof QuerySnapshot) {
|
|
27955
|
-
return (left._firestore === right._firestore &&
|
|
27956
|
-
queryEqual(left.query, right.query) &&
|
|
27957
|
-
left.metadata.isEqual(right.metadata) &&
|
|
27958
|
-
left._snapshot.isEqual(right._snapshot));
|
|
27959
|
-
}
|
|
27960
|
-
return false;
|
|
27961
|
-
}
|
|
27962
|
-
|
|
27963
|
-
/**
|
|
27964
|
-
* @license
|
|
27965
|
-
* Copyright 2020 Google LLC
|
|
27966
|
-
*
|
|
27967
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
27968
|
-
* you may not use this file except in compliance with the License.
|
|
27969
|
-
* You may obtain a copy of the License at
|
|
27970
|
-
*
|
|
27971
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
27972
|
-
*
|
|
27973
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
27974
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
27975
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
27976
|
-
* See the License for the specific language governing permissions and
|
|
27977
|
-
* limitations under the License.
|
|
27978
|
-
*/
|
|
27979
|
-
function validateHasExplicitOrderByForLimitToLast(query) {
|
|
27980
|
-
if (query.limitType === "L" /* Last */ &&
|
|
27981
|
-
query.explicitOrderBy.length === 0) {
|
|
27982
|
-
throw new FirestoreError(Code.UNIMPLEMENTED, 'limitToLast() queries require specifying at least one orderBy() clause');
|
|
27983
|
-
}
|
|
27984
|
-
}
|
|
27985
|
-
/**
|
|
27986
|
-
* A `QueryConstraint` is used to narrow the set of documents returned by a
|
|
27987
|
-
* Firestore query. `QueryConstraint`s are created by invoking {@link where},
|
|
27988
|
-
* {@link orderBy}, {@link (startAt:1)}, {@link (startAfter:1)}, {@link
|
|
27989
|
-
* endBefore:1}, {@link (endAt:1)}, {@link limit} or {@link limitToLast} and
|
|
27990
|
-
* can then be passed to {@link query} to create a new query instance that
|
|
27991
|
-
* also contains this `QueryConstraint`.
|
|
27992
|
-
*/
|
|
27993
|
-
class QueryConstraint {
|
|
27994
|
-
}
|
|
27995
|
-
/**
|
|
27996
|
-
* Creates a new immutable instance of {@link Query} that is extended to also include
|
|
27997
|
-
* additional query constraints.
|
|
27998
|
-
*
|
|
27999
|
-
* @param query - The {@link Query} instance to use as a base for the new constraints.
|
|
28000
|
-
* @param queryConstraints - The list of {@link QueryConstraint}s to apply.
|
|
28001
|
-
* @throws if any of the provided query constraints cannot be combined with the
|
|
28002
|
-
* existing or new constraints.
|
|
28003
|
-
*/
|
|
28004
|
-
function query(query, ...queryConstraints) {
|
|
28005
|
-
for (const constraint of queryConstraints) {
|
|
28006
|
-
query = constraint._apply(query);
|
|
28007
|
-
}
|
|
28008
|
-
return query;
|
|
28009
|
-
}
|
|
28010
|
-
class QueryFilterConstraint extends QueryConstraint {
|
|
28011
|
-
constructor(_field, _op, _value) {
|
|
28012
|
-
super();
|
|
28013
|
-
this._field = _field;
|
|
28014
|
-
this._op = _op;
|
|
28015
|
-
this._value = _value;
|
|
28016
|
-
this.type = 'where';
|
|
28017
|
-
}
|
|
28018
|
-
_apply(query) {
|
|
28019
|
-
const reader = newUserDataReader(query.firestore);
|
|
28020
|
-
const filter = newQueryFilter(query._query, 'where', reader, query.firestore._databaseId, this._field, this._op, this._value);
|
|
28021
|
-
return new Query(query.firestore, query.converter, queryWithAddedFilter(query._query, filter));
|
|
28022
|
-
}
|
|
28023
|
-
}
|
|
28024
|
-
/**
|
|
28025
|
-
* Creates a {@link QueryConstraint} that enforces that documents must contain the
|
|
28026
|
-
* specified field and that the value should satisfy the relation constraint
|
|
28027
|
-
* provided.
|
|
28028
|
-
*
|
|
28029
|
-
* @param fieldPath - The path to compare
|
|
28030
|
-
* @param opStr - The operation string (e.g "<", "<=", "==", "<",
|
|
28031
|
-
* "<=", "!=").
|
|
28032
|
-
* @param value - The value for comparison
|
|
28033
|
-
* @returns The created {@link Query}.
|
|
28034
|
-
*/
|
|
28035
|
-
function where(fieldPath, opStr, value) {
|
|
28036
|
-
const op = opStr;
|
|
28037
|
-
const field = fieldPathFromArgument('where', fieldPath);
|
|
28038
|
-
return new QueryFilterConstraint(field, op, value);
|
|
28039
|
-
}
|
|
28040
|
-
class QueryOrderByConstraint extends QueryConstraint {
|
|
28041
|
-
constructor(_field, _direction) {
|
|
28042
|
-
super();
|
|
28043
|
-
this._field = _field;
|
|
28044
|
-
this._direction = _direction;
|
|
28045
|
-
this.type = 'orderBy';
|
|
28046
|
-
}
|
|
28047
|
-
_apply(query) {
|
|
28048
|
-
const orderBy = newQueryOrderBy(query._query, this._field, this._direction);
|
|
28049
|
-
return new Query(query.firestore, query.converter, queryWithAddedOrderBy(query._query, orderBy));
|
|
28050
|
-
}
|
|
28051
|
-
}
|
|
28052
|
-
/**
|
|
28053
|
-
* Creates a {@link QueryConstraint} that sorts the query result by the
|
|
28054
|
-
* specified field, optionally in descending order instead of ascending.
|
|
28055
|
-
*
|
|
28056
|
-
* @param fieldPath - The field to sort by.
|
|
28057
|
-
* @param directionStr - Optional direction to sort by ('asc' or 'desc'). If
|
|
28058
|
-
* not specified, order will be ascending.
|
|
28059
|
-
* @returns The created {@link Query}.
|
|
28107
|
+
* Creates a {@link QueryConstraint} that sorts the query result by the
|
|
28108
|
+
* specified field, optionally in descending order instead of ascending.
|
|
28109
|
+
*
|
|
28110
|
+
* @param fieldPath - The field to sort by.
|
|
28111
|
+
* @param directionStr - Optional direction to sort by ('asc' or 'desc'). If
|
|
28112
|
+
* not specified, order will be ascending.
|
|
28113
|
+
* @returns The created {@link Query}.
|
|
28060
28114
|
*/
|
|
28061
28115
|
function orderBy(fieldPath, directionStr = 'asc') {
|
|
28062
28116
|
const direction = directionStr;
|
|
@@ -28420,31 +28474,6 @@ function validateOrderByAndInequalityMatch(baseQuery, inequality, orderBy) {
|
|
|
28420
28474
|
}
|
|
28421
28475
|
}
|
|
28422
28476
|
|
|
28423
|
-
/**
|
|
28424
|
-
* @license
|
|
28425
|
-
* Copyright 2022 Google LLC
|
|
28426
|
-
*
|
|
28427
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
28428
|
-
* you may not use this file except in compliance with the License.
|
|
28429
|
-
* You may obtain a copy of the License at
|
|
28430
|
-
*
|
|
28431
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
28432
|
-
*
|
|
28433
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
28434
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
28435
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
28436
|
-
* See the License for the specific language governing permissions and
|
|
28437
|
-
* limitations under the License.
|
|
28438
|
-
*/
|
|
28439
|
-
const DEFAULT_TRANSACTION_OPTIONS = {
|
|
28440
|
-
maxAttempts: 5
|
|
28441
|
-
};
|
|
28442
|
-
function validateTransactionOptions(options) {
|
|
28443
|
-
if (options.maxAttempts < 1) {
|
|
28444
|
-
throw new FirestoreError(Code.INVALID_ARGUMENT, 'Max attempts must be at least 1');
|
|
28445
|
-
}
|
|
28446
|
-
}
|
|
28447
|
-
|
|
28448
28477
|
/**
|
|
28449
28478
|
* @license
|
|
28450
28479
|
* Copyright 2020 Google LLC
|
|
@@ -28619,221 +28648,276 @@ class LiteUserDataWriter extends AbstractUserDataWriter {
|
|
|
28619
28648
|
* limitations under the License.
|
|
28620
28649
|
*/
|
|
28621
28650
|
/**
|
|
28622
|
-
*
|
|
28623
|
-
*
|
|
28624
|
-
* A `WriteBatch` object can be acquired by calling {@link writeBatch}. It
|
|
28625
|
-
* provides methods for adding writes to the write batch. None of the writes
|
|
28626
|
-
* will be committed (or visible locally) until {@link WriteBatch.commit} is
|
|
28627
|
-
* called.
|
|
28651
|
+
* Metadata about a snapshot, describing the state of the snapshot.
|
|
28628
28652
|
*/
|
|
28629
|
-
class
|
|
28653
|
+
class SnapshotMetadata {
|
|
28630
28654
|
/** @hideconstructor */
|
|
28631
|
-
constructor(
|
|
28632
|
-
this.
|
|
28633
|
-
this.
|
|
28634
|
-
this._mutations = [];
|
|
28635
|
-
this._committed = false;
|
|
28636
|
-
this._dataReader = newUserDataReader(_firestore);
|
|
28655
|
+
constructor(hasPendingWrites, fromCache) {
|
|
28656
|
+
this.hasPendingWrites = hasPendingWrites;
|
|
28657
|
+
this.fromCache = fromCache;
|
|
28637
28658
|
}
|
|
28638
|
-
|
|
28639
|
-
|
|
28640
|
-
|
|
28641
|
-
|
|
28642
|
-
|
|
28643
|
-
|
|
28644
|
-
|
|
28659
|
+
/**
|
|
28660
|
+
* Returns true if this `SnapshotMetadata` is equal to the provided one.
|
|
28661
|
+
*
|
|
28662
|
+
* @param other - The `SnapshotMetadata` to compare against.
|
|
28663
|
+
* @returns true if this `SnapshotMetadata` is equal to the provided one.
|
|
28664
|
+
*/
|
|
28665
|
+
isEqual(other) {
|
|
28666
|
+
return (this.hasPendingWrites === other.hasPendingWrites &&
|
|
28667
|
+
this.fromCache === other.fromCache);
|
|
28645
28668
|
}
|
|
28646
|
-
|
|
28647
|
-
|
|
28648
|
-
|
|
28649
|
-
|
|
28650
|
-
|
|
28651
|
-
|
|
28652
|
-
|
|
28653
|
-
|
|
28654
|
-
|
|
28655
|
-
|
|
28656
|
-
|
|
28657
|
-
|
|
28658
|
-
|
|
28659
|
-
|
|
28660
|
-
this.
|
|
28661
|
-
|
|
28669
|
+
}
|
|
28670
|
+
/**
|
|
28671
|
+
* A `DocumentSnapshot` contains data read from a document in your Firestore
|
|
28672
|
+
* database. The data can be extracted with `.data()` or `.get(<field>)` to
|
|
28673
|
+
* get a specific field.
|
|
28674
|
+
*
|
|
28675
|
+
* For a `DocumentSnapshot` that points to a non-existing document, any data
|
|
28676
|
+
* access will return 'undefined'. You can use the `exists()` method to
|
|
28677
|
+
* explicitly verify a document's existence.
|
|
28678
|
+
*/
|
|
28679
|
+
class DocumentSnapshot extends DocumentSnapshot$1 {
|
|
28680
|
+
/** @hideconstructor protected */
|
|
28681
|
+
constructor(_firestore, userDataWriter, key, document, metadata, converter) {
|
|
28682
|
+
super(_firestore, userDataWriter, key, document, converter);
|
|
28683
|
+
this._firestore = _firestore;
|
|
28684
|
+
this._firestoreImpl = _firestore;
|
|
28685
|
+
this.metadata = metadata;
|
|
28662
28686
|
}
|
|
28663
28687
|
/**
|
|
28664
|
-
*
|
|
28665
|
-
*
|
|
28666
|
-
* @param documentRef - A reference to the document to be deleted.
|
|
28667
|
-
* @returns This `WriteBatch` instance. Used for chaining method calls.
|
|
28688
|
+
* Returns whether or not the data exists. True if the document exists.
|
|
28668
28689
|
*/
|
|
28669
|
-
|
|
28670
|
-
|
|
28671
|
-
const ref = validateReference(documentRef, this._firestore);
|
|
28672
|
-
this._mutations = this._mutations.concat(new DeleteMutation(ref._key, Precondition.none()));
|
|
28673
|
-
return this;
|
|
28690
|
+
exists() {
|
|
28691
|
+
return super.exists();
|
|
28674
28692
|
}
|
|
28675
28693
|
/**
|
|
28676
|
-
*
|
|
28694
|
+
* Retrieves all fields in the document as an `Object`. Returns `undefined` if
|
|
28695
|
+
* the document doesn't exist.
|
|
28677
28696
|
*
|
|
28678
|
-
*
|
|
28679
|
-
*
|
|
28680
|
-
*
|
|
28681
|
-
* until the client is online, use the full Firestore SDK.
|
|
28697
|
+
* By default, `serverTimestamp()` values that have not yet been
|
|
28698
|
+
* set to their final value will be returned as `null`. You can override
|
|
28699
|
+
* this by passing an options object.
|
|
28682
28700
|
*
|
|
28683
|
-
* @
|
|
28684
|
-
*
|
|
28685
|
-
*
|
|
28701
|
+
* @param options - An options object to configure how data is retrieved from
|
|
28702
|
+
* the snapshot (for example the desired behavior for server timestamps that
|
|
28703
|
+
* have not yet been set to their final value).
|
|
28704
|
+
* @returns An `Object` containing all fields in the document or `undefined` if
|
|
28705
|
+
* the document doesn't exist.
|
|
28686
28706
|
*/
|
|
28687
|
-
|
|
28688
|
-
this.
|
|
28689
|
-
|
|
28690
|
-
|
|
28691
|
-
|
|
28707
|
+
data(options = {}) {
|
|
28708
|
+
if (!this._document) {
|
|
28709
|
+
return undefined;
|
|
28710
|
+
}
|
|
28711
|
+
else if (this._converter) {
|
|
28712
|
+
// We only want to use the converter and create a new DocumentSnapshot
|
|
28713
|
+
// if a converter has been provided.
|
|
28714
|
+
const snapshot = new QueryDocumentSnapshot(this._firestore, this._userDataWriter, this._key, this._document, this.metadata,
|
|
28715
|
+
/* converter= */ null);
|
|
28716
|
+
return this._converter.fromFirestore(snapshot, options);
|
|
28717
|
+
}
|
|
28718
|
+
else {
|
|
28719
|
+
return this._userDataWriter.convertValue(this._document.data.value, options.serverTimestamps);
|
|
28692
28720
|
}
|
|
28693
|
-
return Promise.resolve();
|
|
28694
28721
|
}
|
|
28695
|
-
|
|
28696
|
-
|
|
28697
|
-
|
|
28698
|
-
|
|
28722
|
+
/**
|
|
28723
|
+
* Retrieves the field specified by `fieldPath`. Returns `undefined` if the
|
|
28724
|
+
* document or field doesn't exist.
|
|
28725
|
+
*
|
|
28726
|
+
* By default, a `serverTimestamp()` that has not yet been set to
|
|
28727
|
+
* its final value will be returned as `null`. You can override this by
|
|
28728
|
+
* passing an options object.
|
|
28729
|
+
*
|
|
28730
|
+
* @param fieldPath - The path (for example 'foo' or 'foo.bar') to a specific
|
|
28731
|
+
* field.
|
|
28732
|
+
* @param options - An options object to configure how the field is retrieved
|
|
28733
|
+
* from the snapshot (for example the desired behavior for server timestamps
|
|
28734
|
+
* that have not yet been set to their final value).
|
|
28735
|
+
* @returns The data at the specified field location or undefined if no such
|
|
28736
|
+
* field exists in the document.
|
|
28737
|
+
*/
|
|
28738
|
+
// We are using `any` here to avoid an explicit cast by our users.
|
|
28739
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
28740
|
+
get(fieldPath, options = {}) {
|
|
28741
|
+
if (this._document) {
|
|
28742
|
+
const value = this._document.data.field(fieldPathFromArgument('DocumentSnapshot.get', fieldPath));
|
|
28743
|
+
if (value !== null) {
|
|
28744
|
+
return this._userDataWriter.convertValue(value, options.serverTimestamps);
|
|
28745
|
+
}
|
|
28699
28746
|
}
|
|
28747
|
+
return undefined;
|
|
28700
28748
|
}
|
|
28701
28749
|
}
|
|
28702
|
-
function validateReference(documentRef, firestore) {
|
|
28703
|
-
documentRef = getModularInstance(documentRef);
|
|
28704
|
-
if (documentRef.firestore !== firestore) {
|
|
28705
|
-
throw new FirestoreError(Code.INVALID_ARGUMENT, 'Provided document reference is from a different Firestore instance.');
|
|
28706
|
-
}
|
|
28707
|
-
else {
|
|
28708
|
-
return documentRef;
|
|
28709
|
-
}
|
|
28710
|
-
}
|
|
28711
|
-
|
|
28712
28750
|
/**
|
|
28713
|
-
*
|
|
28714
|
-
*
|
|
28715
|
-
*
|
|
28716
|
-
*
|
|
28717
|
-
* you may not use this file except in compliance with the License.
|
|
28718
|
-
* You may obtain a copy of the License at
|
|
28719
|
-
*
|
|
28720
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
28751
|
+
* A `QueryDocumentSnapshot` contains data read from a document in your
|
|
28752
|
+
* Firestore database as part of a query. The document is guaranteed to exist
|
|
28753
|
+
* and its data can be extracted with `.data()` or `.get(<field>)` to get a
|
|
28754
|
+
* specific field.
|
|
28721
28755
|
*
|
|
28722
|
-
*
|
|
28723
|
-
*
|
|
28724
|
-
*
|
|
28725
|
-
*
|
|
28726
|
-
* limitations under the License.
|
|
28756
|
+
* A `QueryDocumentSnapshot` offers the same API surface as a
|
|
28757
|
+
* `DocumentSnapshot`. Since query results contain only existing documents, the
|
|
28758
|
+
* `exists` property will always be true and `data()` will never return
|
|
28759
|
+
* 'undefined'.
|
|
28727
28760
|
*/
|
|
28728
|
-
|
|
28729
|
-
|
|
28761
|
+
class QueryDocumentSnapshot extends DocumentSnapshot {
|
|
28762
|
+
/**
|
|
28763
|
+
* Retrieves all fields in the document as an `Object`.
|
|
28764
|
+
*
|
|
28765
|
+
* By default, `serverTimestamp()` values that have not yet been
|
|
28766
|
+
* set to their final value will be returned as `null`. You can override
|
|
28767
|
+
* this by passing an options object.
|
|
28768
|
+
*
|
|
28769
|
+
* @override
|
|
28770
|
+
* @param options - An options object to configure how data is retrieved from
|
|
28771
|
+
* the snapshot (for example the desired behavior for server timestamps that
|
|
28772
|
+
* have not yet been set to their final value).
|
|
28773
|
+
* @returns An `Object` containing all fields in the document.
|
|
28774
|
+
*/
|
|
28775
|
+
data(options = {}) {
|
|
28776
|
+
return super.data(options);
|
|
28777
|
+
}
|
|
28778
|
+
}
|
|
28730
28779
|
/**
|
|
28731
|
-
* A
|
|
28732
|
-
*
|
|
28733
|
-
*
|
|
28734
|
-
*
|
|
28735
|
-
*
|
|
28780
|
+
* A `QuerySnapshot` contains zero or more `DocumentSnapshot` objects
|
|
28781
|
+
* representing the results of a query. The documents can be accessed as an
|
|
28782
|
+
* array via the `docs` property or enumerated using the `forEach` method. The
|
|
28783
|
+
* number of documents can be determined via the `empty` and `size`
|
|
28784
|
+
* properties.
|
|
28736
28785
|
*/
|
|
28737
|
-
class
|
|
28786
|
+
class QuerySnapshot {
|
|
28738
28787
|
/** @hideconstructor */
|
|
28739
|
-
constructor(_firestore,
|
|
28788
|
+
constructor(_firestore, _userDataWriter, query, _snapshot) {
|
|
28740
28789
|
this._firestore = _firestore;
|
|
28741
|
-
this.
|
|
28742
|
-
this.
|
|
28790
|
+
this._userDataWriter = _userDataWriter;
|
|
28791
|
+
this._snapshot = _snapshot;
|
|
28792
|
+
this.metadata = new SnapshotMetadata(_snapshot.hasPendingWrites, _snapshot.fromCache);
|
|
28793
|
+
this.query = query;
|
|
28794
|
+
}
|
|
28795
|
+
/** An array of all the documents in the `QuerySnapshot`. */
|
|
28796
|
+
get docs() {
|
|
28797
|
+
const result = [];
|
|
28798
|
+
this.forEach(doc => result.push(doc));
|
|
28799
|
+
return result;
|
|
28800
|
+
}
|
|
28801
|
+
/** The number of documents in the `QuerySnapshot`. */
|
|
28802
|
+
get size() {
|
|
28803
|
+
return this._snapshot.docs.size;
|
|
28804
|
+
}
|
|
28805
|
+
/** True if there are no documents in the `QuerySnapshot`. */
|
|
28806
|
+
get empty() {
|
|
28807
|
+
return this.size === 0;
|
|
28743
28808
|
}
|
|
28744
28809
|
/**
|
|
28745
|
-
*
|
|
28810
|
+
* Enumerates all of the documents in the `QuerySnapshot`.
|
|
28746
28811
|
*
|
|
28747
|
-
* @param
|
|
28748
|
-
*
|
|
28812
|
+
* @param callback - A callback to be called with a `QueryDocumentSnapshot` for
|
|
28813
|
+
* each document in the snapshot.
|
|
28814
|
+
* @param thisArg - The `this` binding for the callback.
|
|
28749
28815
|
*/
|
|
28750
|
-
|
|
28751
|
-
|
|
28752
|
-
|
|
28753
|
-
return this._transaction.lookup([ref._key]).then(docs => {
|
|
28754
|
-
if (!docs || docs.length !== 1) {
|
|
28755
|
-
return fail();
|
|
28756
|
-
}
|
|
28757
|
-
const doc = docs[0];
|
|
28758
|
-
if (doc.isFoundDocument()) {
|
|
28759
|
-
return new DocumentSnapshot$1(this._firestore, userDataWriter, doc.key, doc, ref.converter);
|
|
28760
|
-
}
|
|
28761
|
-
else if (doc.isNoDocument()) {
|
|
28762
|
-
return new DocumentSnapshot$1(this._firestore, userDataWriter, ref._key, null, ref.converter);
|
|
28763
|
-
}
|
|
28764
|
-
else {
|
|
28765
|
-
throw fail();
|
|
28766
|
-
}
|
|
28816
|
+
forEach(callback, thisArg) {
|
|
28817
|
+
this._snapshot.docs.forEach(doc => {
|
|
28818
|
+
callback.call(thisArg, new QueryDocumentSnapshot(this._firestore, this._userDataWriter, doc.key, doc, new SnapshotMetadata(this._snapshot.mutatedKeys.has(doc.key), this._snapshot.fromCache), this.query.converter));
|
|
28767
28819
|
});
|
|
28768
28820
|
}
|
|
28769
|
-
set(documentRef, value, options) {
|
|
28770
|
-
const ref = validateReference(documentRef, this._firestore);
|
|
28771
|
-
const convertedValue = applyFirestoreDataConverter(ref.converter, value, options);
|
|
28772
|
-
const parsed = parseSetData(this._dataReader, 'Transaction.set', ref._key, convertedValue, ref.converter !== null, options);
|
|
28773
|
-
this._transaction.set(ref._key, parsed);
|
|
28774
|
-
return this;
|
|
28775
|
-
}
|
|
28776
|
-
update(documentRef, fieldOrUpdateData, value, ...moreFieldsAndValues) {
|
|
28777
|
-
const ref = validateReference(documentRef, this._firestore);
|
|
28778
|
-
// For Compat types, we have to "extract" the underlying types before
|
|
28779
|
-
// performing validation.
|
|
28780
|
-
fieldOrUpdateData = getModularInstance(fieldOrUpdateData);
|
|
28781
|
-
let parsed;
|
|
28782
|
-
if (typeof fieldOrUpdateData === 'string' ||
|
|
28783
|
-
fieldOrUpdateData instanceof FieldPath) {
|
|
28784
|
-
parsed = parseUpdateVarargs(this._dataReader, 'Transaction.update', ref._key, fieldOrUpdateData, value, moreFieldsAndValues);
|
|
28785
|
-
}
|
|
28786
|
-
else {
|
|
28787
|
-
parsed = parseUpdateData(this._dataReader, 'Transaction.update', ref._key, fieldOrUpdateData);
|
|
28788
|
-
}
|
|
28789
|
-
this._transaction.update(ref._key, parsed);
|
|
28790
|
-
return this;
|
|
28791
|
-
}
|
|
28792
28821
|
/**
|
|
28793
|
-
*
|
|
28822
|
+
* Returns an array of the documents changes since the last snapshot. If this
|
|
28823
|
+
* is the first snapshot, all documents will be in the list as 'added'
|
|
28824
|
+
* changes.
|
|
28794
28825
|
*
|
|
28795
|
-
* @param
|
|
28796
|
-
*
|
|
28826
|
+
* @param options - `SnapshotListenOptions` that control whether metadata-only
|
|
28827
|
+
* changes (i.e. only `DocumentSnapshot.metadata` changed) should trigger
|
|
28828
|
+
* snapshot events.
|
|
28797
28829
|
*/
|
|
28798
|
-
|
|
28799
|
-
const
|
|
28800
|
-
this.
|
|
28801
|
-
|
|
28830
|
+
docChanges(options = {}) {
|
|
28831
|
+
const includeMetadataChanges = !!options.includeMetadataChanges;
|
|
28832
|
+
if (includeMetadataChanges && this._snapshot.excludesMetadataChanges) {
|
|
28833
|
+
throw new FirestoreError(Code.INVALID_ARGUMENT, 'To include metadata changes with your document changes, you must ' +
|
|
28834
|
+
'also pass { includeMetadataChanges:true } to onSnapshot().');
|
|
28835
|
+
}
|
|
28836
|
+
if (!this._cachedChanges ||
|
|
28837
|
+
this._cachedChangesIncludeMetadataChanges !== includeMetadataChanges) {
|
|
28838
|
+
this._cachedChanges = changesFromSnapshot(this, includeMetadataChanges);
|
|
28839
|
+
this._cachedChangesIncludeMetadataChanges = includeMetadataChanges;
|
|
28840
|
+
}
|
|
28841
|
+
return this._cachedChanges;
|
|
28842
|
+
}
|
|
28843
|
+
}
|
|
28844
|
+
/** Calculates the array of `DocumentChange`s for a given `ViewSnapshot`. */
|
|
28845
|
+
function changesFromSnapshot(querySnapshot, includeMetadataChanges) {
|
|
28846
|
+
if (querySnapshot._snapshot.oldDocs.isEmpty()) {
|
|
28847
|
+
let index = 0;
|
|
28848
|
+
return querySnapshot._snapshot.docChanges.map(change => {
|
|
28849
|
+
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);
|
|
28850
|
+
return {
|
|
28851
|
+
type: 'added',
|
|
28852
|
+
doc,
|
|
28853
|
+
oldIndex: -1,
|
|
28854
|
+
newIndex: index++
|
|
28855
|
+
};
|
|
28856
|
+
});
|
|
28857
|
+
}
|
|
28858
|
+
else {
|
|
28859
|
+
// A `DocumentSet` that is updated incrementally as changes are applied to use
|
|
28860
|
+
// to lookup the index of a document.
|
|
28861
|
+
let indexTracker = querySnapshot._snapshot.oldDocs;
|
|
28862
|
+
return querySnapshot._snapshot.docChanges
|
|
28863
|
+
.filter(change => includeMetadataChanges || change.type !== 3 /* Metadata */)
|
|
28864
|
+
.map(change => {
|
|
28865
|
+
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);
|
|
28866
|
+
let oldIndex = -1;
|
|
28867
|
+
let newIndex = -1;
|
|
28868
|
+
if (change.type !== 0 /* Added */) {
|
|
28869
|
+
oldIndex = indexTracker.indexOf(change.doc.key);
|
|
28870
|
+
indexTracker = indexTracker.delete(change.doc.key);
|
|
28871
|
+
}
|
|
28872
|
+
if (change.type !== 1 /* Removed */) {
|
|
28873
|
+
indexTracker = indexTracker.add(change.doc);
|
|
28874
|
+
newIndex = indexTracker.indexOf(change.doc.key);
|
|
28875
|
+
}
|
|
28876
|
+
return {
|
|
28877
|
+
type: resultChangeType(change.type),
|
|
28878
|
+
doc,
|
|
28879
|
+
oldIndex,
|
|
28880
|
+
newIndex
|
|
28881
|
+
};
|
|
28882
|
+
});
|
|
28883
|
+
}
|
|
28884
|
+
}
|
|
28885
|
+
function resultChangeType(type) {
|
|
28886
|
+
switch (type) {
|
|
28887
|
+
case 0 /* Added */:
|
|
28888
|
+
return 'added';
|
|
28889
|
+
case 2 /* Modified */:
|
|
28890
|
+
case 3 /* Metadata */:
|
|
28891
|
+
return 'modified';
|
|
28892
|
+
case 1 /* Removed */:
|
|
28893
|
+
return 'removed';
|
|
28894
|
+
default:
|
|
28895
|
+
return fail();
|
|
28802
28896
|
}
|
|
28803
|
-
}
|
|
28804
|
-
|
|
28805
|
-
/**
|
|
28806
|
-
* @license
|
|
28807
|
-
* Copyright 2017 Google LLC
|
|
28808
|
-
*
|
|
28809
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
28810
|
-
* you may not use this file except in compliance with the License.
|
|
28811
|
-
* You may obtain a copy of the License at
|
|
28812
|
-
*
|
|
28813
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
28814
|
-
*
|
|
28815
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
28816
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
28817
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
28818
|
-
* See the License for the specific language governing permissions and
|
|
28819
|
-
* limitations under the License.
|
|
28820
|
-
*/
|
|
28821
|
-
function isPartialObserver(obj) {
|
|
28822
|
-
return implementsAnyMethods(obj, ['next', 'error', 'complete']);
|
|
28823
28897
|
}
|
|
28898
|
+
// TODO(firestoreexp): Add tests for snapshotEqual with different snapshot
|
|
28899
|
+
// metadata
|
|
28824
28900
|
/**
|
|
28825
|
-
* Returns true if
|
|
28826
|
-
*
|
|
28901
|
+
* Returns true if the provided snapshots are equal.
|
|
28902
|
+
*
|
|
28903
|
+
* @param left - A snapshot to compare.
|
|
28904
|
+
* @param right - A snapshot to compare.
|
|
28905
|
+
* @returns true if the snapshots are equal.
|
|
28827
28906
|
*/
|
|
28828
|
-
function
|
|
28829
|
-
if (
|
|
28830
|
-
return
|
|
28907
|
+
function snapshotEqual(left, right) {
|
|
28908
|
+
if (left instanceof DocumentSnapshot && right instanceof DocumentSnapshot) {
|
|
28909
|
+
return (left._firestore === right._firestore &&
|
|
28910
|
+
left._key.isEqual(right._key) &&
|
|
28911
|
+
(left._document === null
|
|
28912
|
+
? right._document === null
|
|
28913
|
+
: left._document.isEqual(right._document)) &&
|
|
28914
|
+
left._converter === right._converter);
|
|
28831
28915
|
}
|
|
28832
|
-
|
|
28833
|
-
|
|
28834
|
-
|
|
28835
|
-
|
|
28836
|
-
|
|
28916
|
+
else if (left instanceof QuerySnapshot && right instanceof QuerySnapshot) {
|
|
28917
|
+
return (left._firestore === right._firestore &&
|
|
28918
|
+
queryEqual(left.query, right.query) &&
|
|
28919
|
+
left.metadata.isEqual(right.metadata) &&
|
|
28920
|
+
left._snapshot.isEqual(right._snapshot));
|
|
28837
28921
|
}
|
|
28838
28922
|
return false;
|
|
28839
28923
|
}
|
|
@@ -29102,6 +29186,307 @@ function convertToDocSnapshot(firestore, ref, snapshot) {
|
|
|
29102
29186
|
return new DocumentSnapshot(firestore, userDataWriter, ref._key, doc, new SnapshotMetadata(snapshot.hasPendingWrites, snapshot.fromCache), ref.converter);
|
|
29103
29187
|
}
|
|
29104
29188
|
|
|
29189
|
+
/**
|
|
29190
|
+
* @license
|
|
29191
|
+
* Copyright 2022 Google LLC
|
|
29192
|
+
*
|
|
29193
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
29194
|
+
* you may not use this file except in compliance with the License.
|
|
29195
|
+
* You may obtain a copy of the License at
|
|
29196
|
+
*
|
|
29197
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
29198
|
+
*
|
|
29199
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
29200
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
29201
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
29202
|
+
* See the License for the specific language governing permissions and
|
|
29203
|
+
* limitations under the License.
|
|
29204
|
+
*/
|
|
29205
|
+
/**
|
|
29206
|
+
* Compares two `AggregateQuerySnapshot` instances for equality.
|
|
29207
|
+
*
|
|
29208
|
+
* Two `AggregateQuerySnapshot` instances are considered "equal" if they have
|
|
29209
|
+
* underlying queries that compare equal, and the same data.
|
|
29210
|
+
*
|
|
29211
|
+
* @param left - The first `AggregateQuerySnapshot` to compare.
|
|
29212
|
+
* @param right - The second `AggregateQuerySnapshot` to compare.
|
|
29213
|
+
*
|
|
29214
|
+
* @returns `true` if the objects are "equal", as defined above, or `false`
|
|
29215
|
+
* otherwise.
|
|
29216
|
+
*/
|
|
29217
|
+
function aggregateQuerySnapshotEqual(left, right) {
|
|
29218
|
+
return (queryEqual(left.query, right.query) && deepEqual(left.data(), right.data()));
|
|
29219
|
+
}
|
|
29220
|
+
|
|
29221
|
+
/**
|
|
29222
|
+
* @license
|
|
29223
|
+
* Copyright 2022 Google LLC
|
|
29224
|
+
*
|
|
29225
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
29226
|
+
* you may not use this file except in compliance with the License.
|
|
29227
|
+
* You may obtain a copy of the License at
|
|
29228
|
+
*
|
|
29229
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
29230
|
+
*
|
|
29231
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
29232
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
29233
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
29234
|
+
* See the License for the specific language governing permissions and
|
|
29235
|
+
* limitations under the License.
|
|
29236
|
+
*/
|
|
29237
|
+
/**
|
|
29238
|
+
* Calculates the number of documents in the result set of the given query,
|
|
29239
|
+
* without actually downloading the documents.
|
|
29240
|
+
*
|
|
29241
|
+
* Using this function to count the documents is efficient because only the
|
|
29242
|
+
* final count, not the documents' data, is downloaded. This function can even
|
|
29243
|
+
* count the documents if the result set would be prohibitively large to
|
|
29244
|
+
* download entirely (e.g. thousands of documents).
|
|
29245
|
+
*
|
|
29246
|
+
* The result received from the server is presented, unaltered, without
|
|
29247
|
+
* considering any local state. That is, documents in the local cache are not
|
|
29248
|
+
* taken into consideration, neither are local modifications not yet
|
|
29249
|
+
* synchronized with the server. Previously-downloaded results, if any, are not
|
|
29250
|
+
* used: every request using this source necessarily involves a round trip to
|
|
29251
|
+
* the server.
|
|
29252
|
+
*
|
|
29253
|
+
* @param query - The query whose result set size to calculate.
|
|
29254
|
+
* @returns A Promise that will be resolved with the count; the count can be
|
|
29255
|
+
* retrieved from `snapshot.data().count`, where `snapshot` is the
|
|
29256
|
+
* `AggregateQuerySnapshot` to which the returned Promise resolves.
|
|
29257
|
+
*/
|
|
29258
|
+
function getCountFromServer(query) {
|
|
29259
|
+
const firestore = cast(query.firestore, Firestore);
|
|
29260
|
+
const client = ensureFirestoreConfigured(firestore);
|
|
29261
|
+
const userDataWriter = new ExpUserDataWriter(firestore);
|
|
29262
|
+
return firestoreClientRunCountQuery(client, query, userDataWriter);
|
|
29263
|
+
}
|
|
29264
|
+
|
|
29265
|
+
/**
|
|
29266
|
+
* @license
|
|
29267
|
+
* Copyright 2022 Google LLC
|
|
29268
|
+
*
|
|
29269
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
29270
|
+
* you may not use this file except in compliance with the License.
|
|
29271
|
+
* You may obtain a copy of the License at
|
|
29272
|
+
*
|
|
29273
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
29274
|
+
*
|
|
29275
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
29276
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
29277
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
29278
|
+
* See the License for the specific language governing permissions and
|
|
29279
|
+
* limitations under the License.
|
|
29280
|
+
*/
|
|
29281
|
+
const DEFAULT_TRANSACTION_OPTIONS = {
|
|
29282
|
+
maxAttempts: 5
|
|
29283
|
+
};
|
|
29284
|
+
function validateTransactionOptions(options) {
|
|
29285
|
+
if (options.maxAttempts < 1) {
|
|
29286
|
+
throw new FirestoreError(Code.INVALID_ARGUMENT, 'Max attempts must be at least 1');
|
|
29287
|
+
}
|
|
29288
|
+
}
|
|
29289
|
+
|
|
29290
|
+
/**
|
|
29291
|
+
* @license
|
|
29292
|
+
* Copyright 2020 Google LLC
|
|
29293
|
+
*
|
|
29294
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
29295
|
+
* you may not use this file except in compliance with the License.
|
|
29296
|
+
* You may obtain a copy of the License at
|
|
29297
|
+
*
|
|
29298
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
29299
|
+
*
|
|
29300
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
29301
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
29302
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
29303
|
+
* See the License for the specific language governing permissions and
|
|
29304
|
+
* limitations under the License.
|
|
29305
|
+
*/
|
|
29306
|
+
/**
|
|
29307
|
+
* A write batch, used to perform multiple writes as a single atomic unit.
|
|
29308
|
+
*
|
|
29309
|
+
* A `WriteBatch` object can be acquired by calling {@link writeBatch}. It
|
|
29310
|
+
* provides methods for adding writes to the write batch. None of the writes
|
|
29311
|
+
* will be committed (or visible locally) until {@link WriteBatch.commit} is
|
|
29312
|
+
* called.
|
|
29313
|
+
*/
|
|
29314
|
+
class WriteBatch {
|
|
29315
|
+
/** @hideconstructor */
|
|
29316
|
+
constructor(_firestore, _commitHandler) {
|
|
29317
|
+
this._firestore = _firestore;
|
|
29318
|
+
this._commitHandler = _commitHandler;
|
|
29319
|
+
this._mutations = [];
|
|
29320
|
+
this._committed = false;
|
|
29321
|
+
this._dataReader = newUserDataReader(_firestore);
|
|
29322
|
+
}
|
|
29323
|
+
set(documentRef, data, options) {
|
|
29324
|
+
this._verifyNotCommitted();
|
|
29325
|
+
const ref = validateReference(documentRef, this._firestore);
|
|
29326
|
+
const convertedValue = applyFirestoreDataConverter(ref.converter, data, options);
|
|
29327
|
+
const parsed = parseSetData(this._dataReader, 'WriteBatch.set', ref._key, convertedValue, ref.converter !== null, options);
|
|
29328
|
+
this._mutations.push(parsed.toMutation(ref._key, Precondition.none()));
|
|
29329
|
+
return this;
|
|
29330
|
+
}
|
|
29331
|
+
update(documentRef, fieldOrUpdateData, value, ...moreFieldsAndValues) {
|
|
29332
|
+
this._verifyNotCommitted();
|
|
29333
|
+
const ref = validateReference(documentRef, this._firestore);
|
|
29334
|
+
// For Compat types, we have to "extract" the underlying types before
|
|
29335
|
+
// performing validation.
|
|
29336
|
+
fieldOrUpdateData = getModularInstance(fieldOrUpdateData);
|
|
29337
|
+
let parsed;
|
|
29338
|
+
if (typeof fieldOrUpdateData === 'string' ||
|
|
29339
|
+
fieldOrUpdateData instanceof FieldPath) {
|
|
29340
|
+
parsed = parseUpdateVarargs(this._dataReader, 'WriteBatch.update', ref._key, fieldOrUpdateData, value, moreFieldsAndValues);
|
|
29341
|
+
}
|
|
29342
|
+
else {
|
|
29343
|
+
parsed = parseUpdateData(this._dataReader, 'WriteBatch.update', ref._key, fieldOrUpdateData);
|
|
29344
|
+
}
|
|
29345
|
+
this._mutations.push(parsed.toMutation(ref._key, Precondition.exists(true)));
|
|
29346
|
+
return this;
|
|
29347
|
+
}
|
|
29348
|
+
/**
|
|
29349
|
+
* Deletes the document referred to by the provided {@link DocumentReference}.
|
|
29350
|
+
*
|
|
29351
|
+
* @param documentRef - A reference to the document to be deleted.
|
|
29352
|
+
* @returns This `WriteBatch` instance. Used for chaining method calls.
|
|
29353
|
+
*/
|
|
29354
|
+
delete(documentRef) {
|
|
29355
|
+
this._verifyNotCommitted();
|
|
29356
|
+
const ref = validateReference(documentRef, this._firestore);
|
|
29357
|
+
this._mutations = this._mutations.concat(new DeleteMutation(ref._key, Precondition.none()));
|
|
29358
|
+
return this;
|
|
29359
|
+
}
|
|
29360
|
+
/**
|
|
29361
|
+
* Commits all of the writes in this write batch as a single atomic unit.
|
|
29362
|
+
*
|
|
29363
|
+
* The result of these writes will only be reflected in document reads that
|
|
29364
|
+
* occur after the returned promise resolves. If the client is offline, the
|
|
29365
|
+
* write fails. If you would like to see local modifications or buffer writes
|
|
29366
|
+
* until the client is online, use the full Firestore SDK.
|
|
29367
|
+
*
|
|
29368
|
+
* @returns A `Promise` resolved once all of the writes in the batch have been
|
|
29369
|
+
* successfully written to the backend as an atomic unit (note that it won't
|
|
29370
|
+
* resolve while you're offline).
|
|
29371
|
+
*/
|
|
29372
|
+
commit() {
|
|
29373
|
+
this._verifyNotCommitted();
|
|
29374
|
+
this._committed = true;
|
|
29375
|
+
if (this._mutations.length > 0) {
|
|
29376
|
+
return this._commitHandler(this._mutations);
|
|
29377
|
+
}
|
|
29378
|
+
return Promise.resolve();
|
|
29379
|
+
}
|
|
29380
|
+
_verifyNotCommitted() {
|
|
29381
|
+
if (this._committed) {
|
|
29382
|
+
throw new FirestoreError(Code.FAILED_PRECONDITION, 'A write batch can no longer be used after commit() ' +
|
|
29383
|
+
'has been called.');
|
|
29384
|
+
}
|
|
29385
|
+
}
|
|
29386
|
+
}
|
|
29387
|
+
function validateReference(documentRef, firestore) {
|
|
29388
|
+
documentRef = getModularInstance(documentRef);
|
|
29389
|
+
if (documentRef.firestore !== firestore) {
|
|
29390
|
+
throw new FirestoreError(Code.INVALID_ARGUMENT, 'Provided document reference is from a different Firestore instance.');
|
|
29391
|
+
}
|
|
29392
|
+
else {
|
|
29393
|
+
return documentRef;
|
|
29394
|
+
}
|
|
29395
|
+
}
|
|
29396
|
+
|
|
29397
|
+
/**
|
|
29398
|
+
* @license
|
|
29399
|
+
* Copyright 2020 Google LLC
|
|
29400
|
+
*
|
|
29401
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
29402
|
+
* you may not use this file except in compliance with the License.
|
|
29403
|
+
* You may obtain a copy of the License at
|
|
29404
|
+
*
|
|
29405
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
29406
|
+
*
|
|
29407
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
29408
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
29409
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
29410
|
+
* See the License for the specific language governing permissions and
|
|
29411
|
+
* limitations under the License.
|
|
29412
|
+
*/
|
|
29413
|
+
// TODO(mrschmidt) Consider using `BaseTransaction` as the base class in the
|
|
29414
|
+
// legacy SDK.
|
|
29415
|
+
/**
|
|
29416
|
+
* A reference to a transaction.
|
|
29417
|
+
*
|
|
29418
|
+
* The `Transaction` object passed to a transaction's `updateFunction` provides
|
|
29419
|
+
* the methods to read and write data within the transaction context. See
|
|
29420
|
+
* {@link runTransaction}.
|
|
29421
|
+
*/
|
|
29422
|
+
class Transaction$1 {
|
|
29423
|
+
/** @hideconstructor */
|
|
29424
|
+
constructor(_firestore, _transaction) {
|
|
29425
|
+
this._firestore = _firestore;
|
|
29426
|
+
this._transaction = _transaction;
|
|
29427
|
+
this._dataReader = newUserDataReader(_firestore);
|
|
29428
|
+
}
|
|
29429
|
+
/**
|
|
29430
|
+
* Reads the document referenced by the provided {@link DocumentReference}.
|
|
29431
|
+
*
|
|
29432
|
+
* @param documentRef - A reference to the document to be read.
|
|
29433
|
+
* @returns A `DocumentSnapshot` with the read data.
|
|
29434
|
+
*/
|
|
29435
|
+
get(documentRef) {
|
|
29436
|
+
const ref = validateReference(documentRef, this._firestore);
|
|
29437
|
+
const userDataWriter = new LiteUserDataWriter(this._firestore);
|
|
29438
|
+
return this._transaction.lookup([ref._key]).then(docs => {
|
|
29439
|
+
if (!docs || docs.length !== 1) {
|
|
29440
|
+
return fail();
|
|
29441
|
+
}
|
|
29442
|
+
const doc = docs[0];
|
|
29443
|
+
if (doc.isFoundDocument()) {
|
|
29444
|
+
return new DocumentSnapshot$1(this._firestore, userDataWriter, doc.key, doc, ref.converter);
|
|
29445
|
+
}
|
|
29446
|
+
else if (doc.isNoDocument()) {
|
|
29447
|
+
return new DocumentSnapshot$1(this._firestore, userDataWriter, ref._key, null, ref.converter);
|
|
29448
|
+
}
|
|
29449
|
+
else {
|
|
29450
|
+
throw fail();
|
|
29451
|
+
}
|
|
29452
|
+
});
|
|
29453
|
+
}
|
|
29454
|
+
set(documentRef, value, options) {
|
|
29455
|
+
const ref = validateReference(documentRef, this._firestore);
|
|
29456
|
+
const convertedValue = applyFirestoreDataConverter(ref.converter, value, options);
|
|
29457
|
+
const parsed = parseSetData(this._dataReader, 'Transaction.set', ref._key, convertedValue, ref.converter !== null, options);
|
|
29458
|
+
this._transaction.set(ref._key, parsed);
|
|
29459
|
+
return this;
|
|
29460
|
+
}
|
|
29461
|
+
update(documentRef, fieldOrUpdateData, value, ...moreFieldsAndValues) {
|
|
29462
|
+
const ref = validateReference(documentRef, this._firestore);
|
|
29463
|
+
// For Compat types, we have to "extract" the underlying types before
|
|
29464
|
+
// performing validation.
|
|
29465
|
+
fieldOrUpdateData = getModularInstance(fieldOrUpdateData);
|
|
29466
|
+
let parsed;
|
|
29467
|
+
if (typeof fieldOrUpdateData === 'string' ||
|
|
29468
|
+
fieldOrUpdateData instanceof FieldPath) {
|
|
29469
|
+
parsed = parseUpdateVarargs(this._dataReader, 'Transaction.update', ref._key, fieldOrUpdateData, value, moreFieldsAndValues);
|
|
29470
|
+
}
|
|
29471
|
+
else {
|
|
29472
|
+
parsed = parseUpdateData(this._dataReader, 'Transaction.update', ref._key, fieldOrUpdateData);
|
|
29473
|
+
}
|
|
29474
|
+
this._transaction.update(ref._key, parsed);
|
|
29475
|
+
return this;
|
|
29476
|
+
}
|
|
29477
|
+
/**
|
|
29478
|
+
* Deletes the document referred to by the provided {@link DocumentReference}.
|
|
29479
|
+
*
|
|
29480
|
+
* @param documentRef - A reference to the document to be deleted.
|
|
29481
|
+
* @returns This `Transaction` instance. Used for chaining method calls.
|
|
29482
|
+
*/
|
|
29483
|
+
delete(documentRef) {
|
|
29484
|
+
const ref = validateReference(documentRef, this._firestore);
|
|
29485
|
+
this._transaction.delete(ref._key);
|
|
29486
|
+
return this;
|
|
29487
|
+
}
|
|
29488
|
+
}
|
|
29489
|
+
|
|
29105
29490
|
/**
|
|
29106
29491
|
* @license
|
|
29107
29492
|
* Copyright 2020 Google LLC
|
|
@@ -29387,5 +29772,5 @@ function tryGetString(data, property) {
|
|
|
29387
29772
|
*/
|
|
29388
29773
|
registerFirestore('node');
|
|
29389
29774
|
|
|
29390
|
-
export { AbstractUserDataWriter, 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, arrayRemove, arrayUnion, clearIndexedDbPersistence, collection, collectionGroup, connectFirestoreEmulator, deleteDoc, deleteField, disableNetwork, doc, documentId, enableIndexedDbPersistence, enableMultiTabIndexedDbPersistence, enableNetwork, endAt, endBefore, ensureFirestoreConfigured, executeWrite, 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 };
|
|
29775
|
+
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 };
|
|
29391
29776
|
//# sourceMappingURL=index.node.mjs.map
|