@firebase/firestore 3.5.0 → 3.6.0
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/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/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/index.d.ts +196 -14
- package/dist/index.esm2017.js +4616 -4413
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.esm5.js +4608 -4402
- package/dist/index.esm5.js.map +1 -1
- package/dist/index.node.cjs.js +994 -613
- package/dist/index.node.cjs.js.map +1 -1
- package/dist/index.node.mjs +992 -615
- package/dist/index.node.mjs.map +1 -1
- package/dist/index.rn.js +4622 -4419
- package/dist/index.rn.js.map +1 -1
- package/dist/internal.d.ts +139 -17
- 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/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/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/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/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/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/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/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/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/private.d.ts +234 -19
- package/package.json +6 -6
package/dist/lite/index.d.ts
CHANGED
|
@@ -35,6 +35,69 @@ export declare function addDoc<T>(reference: CollectionReference<T>, data: WithF
|
|
|
35
35
|
export declare type AddPrefixToKeys<Prefix extends string, T extends Record<string, unknown>> = {
|
|
36
36
|
[K in keyof T & string as `${Prefix}.${K}`]+?: T[K];
|
|
37
37
|
};
|
|
38
|
+
/**
|
|
39
|
+
* Represents an aggregation that can be performed by Firestore.
|
|
40
|
+
*/
|
|
41
|
+
export declare class AggregateField<T> {
|
|
42
|
+
/** A type string to uniquely identify instances of this class. */
|
|
43
|
+
type: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The union of all `AggregateField` types that are supported by Firestore.
|
|
47
|
+
*/
|
|
48
|
+
export declare type AggregateFieldType = AggregateField<number>;
|
|
49
|
+
/**
|
|
50
|
+
* The results of executing an aggregation query.
|
|
51
|
+
*/
|
|
52
|
+
export declare class AggregateQuerySnapshot<T extends AggregateSpec> {
|
|
53
|
+
/** A type string to uniquely identify instances of this class. */
|
|
54
|
+
readonly type = "AggregateQuerySnapshot";
|
|
55
|
+
/**
|
|
56
|
+
* The underlying query over which the aggregations recorded in this
|
|
57
|
+
* `AggregateQuerySnapshot` were performed.
|
|
58
|
+
*/
|
|
59
|
+
readonly query: Query<unknown>;
|
|
60
|
+
private constructor();
|
|
61
|
+
/**
|
|
62
|
+
* Returns the results of the aggregations performed over the underlying
|
|
63
|
+
* query.
|
|
64
|
+
*
|
|
65
|
+
* The keys of the returned object will be the same as those of the
|
|
66
|
+
* `AggregateSpec` object specified to the aggregation method, and the values
|
|
67
|
+
* will be the corresponding aggregation result.
|
|
68
|
+
*
|
|
69
|
+
* @returns The results of the aggregations performed over the underlying
|
|
70
|
+
* query.
|
|
71
|
+
*/
|
|
72
|
+
data(): AggregateSpecData<T>;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Compares two `AggregateQuerySnapshot` instances for equality.
|
|
76
|
+
*
|
|
77
|
+
* Two `AggregateQuerySnapshot` instances are considered "equal" if they have
|
|
78
|
+
* underlying queries that compare equal, and the same data.
|
|
79
|
+
*
|
|
80
|
+
* @param left - The first `AggregateQuerySnapshot` to compare.
|
|
81
|
+
* @param right - The second `AggregateQuerySnapshot` to compare.
|
|
82
|
+
*
|
|
83
|
+
* @returns `true` if the objects are "equal", as defined above, or `false`
|
|
84
|
+
* otherwise.
|
|
85
|
+
*/
|
|
86
|
+
export declare function aggregateQuerySnapshotEqual<T extends AggregateSpec>(left: AggregateQuerySnapshot<T>, right: AggregateQuerySnapshot<T>): boolean;
|
|
87
|
+
/**
|
|
88
|
+
* A type whose property values are all `AggregateField` objects.
|
|
89
|
+
*/
|
|
90
|
+
export declare interface AggregateSpec {
|
|
91
|
+
[field: string]: AggregateFieldType;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* A type whose keys are taken from an `AggregateSpec`, and whose values are the
|
|
95
|
+
* result of the aggregation performed by the corresponding `AggregateField`
|
|
96
|
+
* from the input `AggregateSpec`.
|
|
97
|
+
*/
|
|
98
|
+
export declare type AggregateSpecData<T extends AggregateSpec> = {
|
|
99
|
+
[P in keyof T]: T[P] extends AggregateField<infer U> ? U : never;
|
|
100
|
+
};
|
|
38
101
|
/**
|
|
39
102
|
* Returns a special value that can be used with {@link (setDoc:1)} or {@link
|
|
40
103
|
* updateDoc:1} that tells the server to remove the given elements from any
|
|
@@ -466,7 +529,7 @@ export declare abstract class FieldValue {
|
|
|
466
529
|
/**
|
|
467
530
|
* The Cloud Firestore service interface.
|
|
468
531
|
*
|
|
469
|
-
* Do not call this constructor directly. Instead, use {@link getFirestore}.
|
|
532
|
+
* Do not call this constructor directly. Instead, use {@link (getFirestore:1)}.
|
|
470
533
|
*/
|
|
471
534
|
export declare class Firestore {
|
|
472
535
|
/**
|
|
@@ -659,6 +722,23 @@ export declare class GeoPoint {
|
|
|
659
722
|
longitude: number;
|
|
660
723
|
};
|
|
661
724
|
}
|
|
725
|
+
/**
|
|
726
|
+
* Calculates the number of documents in the result set of the given query,
|
|
727
|
+
* without actually downloading the documents.
|
|
728
|
+
*
|
|
729
|
+
* Using this function to count the documents is efficient because only the
|
|
730
|
+
* final count, not the documents' data, is downloaded. This function can even
|
|
731
|
+
* count the documents if the result set would be prohibitively large to
|
|
732
|
+
* download entirely (e.g. thousands of documents).
|
|
733
|
+
*
|
|
734
|
+
* @param query - The query whose result set size to calculate.
|
|
735
|
+
* @returns A Promise that will be resolved with the count; the count can be
|
|
736
|
+
* retrieved from `snapshot.data().count`, where `snapshot` is the
|
|
737
|
+
* `AggregateQuerySnapshot` to which the returned Promise resolves.
|
|
738
|
+
*/
|
|
739
|
+
export declare function getCount(query: Query<unknown>): Promise<AggregateQuerySnapshot<{
|
|
740
|
+
count: AggregateField<number>;
|
|
741
|
+
}>>;
|
|
662
742
|
/**
|
|
663
743
|
* Reads the document referred to by the specified document reference.
|
|
664
744
|
*
|
|
@@ -729,8 +809,8 @@ export declare function increment(n: number): FieldValue;
|
|
|
729
809
|
/**
|
|
730
810
|
* Initializes a new instance of Cloud Firestore with the provided settings.
|
|
731
811
|
* Can only be called before any other functions, including
|
|
732
|
-
* {@link getFirestore}. If the custom settings are empty, this function is
|
|
733
|
-
* equivalent to calling {@link getFirestore}.
|
|
812
|
+
* {@link (getFirestore:1)}. If the custom settings are empty, this function is
|
|
813
|
+
* equivalent to calling {@link (getFirestore:1)}.
|
|
734
814
|
*
|
|
735
815
|
* @param app - The {@link @firebase/app#FirebaseApp} with which the `Firestore` instance will
|
|
736
816
|
* be associated.
|
|
@@ -1089,7 +1169,7 @@ export declare function startAt(...fieldValues: unknown[]): QueryConstraint;
|
|
|
1089
1169
|
* response from the server will not be resolved.
|
|
1090
1170
|
*
|
|
1091
1171
|
* To restart after termination, create a new instance of `Firestore` with
|
|
1092
|
-
* {@link getFirestore}.
|
|
1172
|
+
* {@link (getFirestore:1)}.
|
|
1093
1173
|
*
|
|
1094
1174
|
* Note: Under normal circumstances, calling `terminate()` is not required. This
|
|
1095
1175
|
* function is useful only when you want to force this instance to release all of
|
|
@@ -14,7 +14,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
14
14
|
|
|
15
15
|
var nodeFetch__default = /*#__PURE__*/_interopDefaultLegacy(nodeFetch);
|
|
16
16
|
|
|
17
|
-
const version$1 = "3.
|
|
17
|
+
const version$1 = "3.6.0";
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* @license
|
|
@@ -67,7 +67,7 @@ User.GOOGLE_CREDENTIALS = new User('google-credentials-uid');
|
|
|
67
67
|
User.FIRST_PARTY = new User('first-party-uid');
|
|
68
68
|
User.MOCK_USER = new User('mock-user');
|
|
69
69
|
|
|
70
|
-
const version = "9.
|
|
70
|
+
const version = "9.11.0";
|
|
71
71
|
|
|
72
72
|
/**
|
|
73
73
|
* @license
|
|
@@ -1211,6 +1211,7 @@ const RPC_NAME_URL_MAPPING = {};
|
|
|
1211
1211
|
RPC_NAME_URL_MAPPING['BatchGetDocuments'] = 'batchGet';
|
|
1212
1212
|
RPC_NAME_URL_MAPPING['Commit'] = 'commit';
|
|
1213
1213
|
RPC_NAME_URL_MAPPING['RunQuery'] = 'runQuery';
|
|
1214
|
+
RPC_NAME_URL_MAPPING['RunAggregationQuery'] = 'runAggregationQuery';
|
|
1214
1215
|
const RPC_URL_VERSION = 'v1';
|
|
1215
1216
|
// SDK_VERSION is updated to different value at runtime depending on the entry point,
|
|
1216
1217
|
// so we need to get its value when we need it in a function.
|
|
@@ -1234,6 +1235,11 @@ class RestConnection {
|
|
|
1234
1235
|
this.databaseId.database +
|
|
1235
1236
|
'/documents';
|
|
1236
1237
|
}
|
|
1238
|
+
get shouldResourcePathBeIncludedInRequest() {
|
|
1239
|
+
// Both `invokeRPC()` and `invokeStreamingRPC()` use their `path` arguments to determine
|
|
1240
|
+
// where to run the query, and expect the `request` to NOT specify the "path".
|
|
1241
|
+
return false;
|
|
1242
|
+
}
|
|
1237
1243
|
invokeRPC(rpcName, path, req, authToken, appCheckToken) {
|
|
1238
1244
|
const url = this.makeUrl(rpcName, path);
|
|
1239
1245
|
logDebug(LOG_TAG$3, 'Sending: ', url, req);
|
|
@@ -4569,6 +4575,21 @@ function toQueryTarget(serializer, target) {
|
|
|
4569
4575
|
}
|
|
4570
4576
|
return result;
|
|
4571
4577
|
}
|
|
4578
|
+
function toRunAggregationQueryRequest(serializer, target) {
|
|
4579
|
+
const queryTarget = toQueryTarget(serializer, target);
|
|
4580
|
+
return {
|
|
4581
|
+
structuredAggregationQuery: {
|
|
4582
|
+
aggregations: [
|
|
4583
|
+
{
|
|
4584
|
+
count: {},
|
|
4585
|
+
alias: 'count_alias'
|
|
4586
|
+
}
|
|
4587
|
+
],
|
|
4588
|
+
structuredQuery: queryTarget.structuredQuery
|
|
4589
|
+
},
|
|
4590
|
+
parent: queryTarget.parent
|
|
4591
|
+
};
|
|
4592
|
+
}
|
|
4572
4593
|
function toFilter(filters) {
|
|
4573
4594
|
if (filters.length === 0) {
|
|
4574
4595
|
return;
|
|
@@ -4971,6 +4992,19 @@ async function invokeRunQueryRpc(datastore, query) {
|
|
|
4971
4992
|
// Omit RunQueryResponses that only contain readTimes.
|
|
4972
4993
|
.filter(proto => !!proto.document)
|
|
4973
4994
|
.map(proto => fromDocument(datastoreImpl.serializer, proto.document, undefined)));
|
|
4995
|
+
}
|
|
4996
|
+
async function invokeRunAggregationQueryRpc(datastore, query) {
|
|
4997
|
+
const datastoreImpl = debugCast(datastore);
|
|
4998
|
+
const request = toRunAggregationQueryRequest(datastoreImpl.serializer, queryToTarget(query));
|
|
4999
|
+
const parent = request.parent;
|
|
5000
|
+
if (!datastoreImpl.connection.shouldResourcePathBeIncludedInRequest) {
|
|
5001
|
+
delete request.parent;
|
|
5002
|
+
}
|
|
5003
|
+
const response = await datastoreImpl.invokeStreamingRPC('RunAggregationQuery', parent, request, /*expectedResponseCount=*/ 1);
|
|
5004
|
+
return (response
|
|
5005
|
+
// Omit RunAggregationQueryResponse that only contain readTimes.
|
|
5006
|
+
.filter(proto => !!proto.result)
|
|
5007
|
+
.map(proto => proto.result.aggregateFields));
|
|
4974
5008
|
}
|
|
4975
5009
|
|
|
4976
5010
|
/**
|
|
@@ -5181,7 +5215,7 @@ class FirestoreSettingsImpl {
|
|
|
5181
5215
|
/**
|
|
5182
5216
|
* The Cloud Firestore service interface.
|
|
5183
5217
|
*
|
|
5184
|
-
* Do not call this constructor directly. Instead, use {@link getFirestore}.
|
|
5218
|
+
* Do not call this constructor directly. Instead, use {@link (getFirestore:1)}.
|
|
5185
5219
|
*/
|
|
5186
5220
|
class Firestore {
|
|
5187
5221
|
/** @hideconstructor */
|
|
@@ -5277,9 +5311,17 @@ function getFirestore(appOrDatabaseId, optionalDatabaseId) {
|
|
|
5277
5311
|
const databaseId = typeof appOrDatabaseId === 'string'
|
|
5278
5312
|
? appOrDatabaseId
|
|
5279
5313
|
: optionalDatabaseId || '(default)';
|
|
5280
|
-
|
|
5314
|
+
const db = app._getProvider(app$1, 'firestore/lite').getImmediate({
|
|
5281
5315
|
identifier: databaseId
|
|
5282
5316
|
});
|
|
5317
|
+
if (!db._initialized) {
|
|
5318
|
+
const firestoreEmulatorHost = util.getDefaultEmulatorHost('firestore');
|
|
5319
|
+
if (firestoreEmulatorHost) {
|
|
5320
|
+
const [host, port] = firestoreEmulatorHost.split(':');
|
|
5321
|
+
connectFirestoreEmulator(db, host, parseInt(port, 10));
|
|
5322
|
+
}
|
|
5323
|
+
}
|
|
5324
|
+
return db;
|
|
5283
5325
|
}
|
|
5284
5326
|
/**
|
|
5285
5327
|
* Modify this instance to communicate with the Cloud Firestore emulator.
|
|
@@ -5332,7 +5374,7 @@ function connectFirestoreEmulator(firestore, host, port, options = {}) {
|
|
|
5332
5374
|
* response from the server will not be resolved.
|
|
5333
5375
|
*
|
|
5334
5376
|
* To restart after termination, create a new instance of `Firestore` with
|
|
5335
|
-
* {@link getFirestore}.
|
|
5377
|
+
* {@link (getFirestore:1)}.
|
|
5336
5378
|
*
|
|
5337
5379
|
* Note: Under normal circumstances, calling `terminate()` is not required. This
|
|
5338
5380
|
* function is useful only when you want to force this instance to release all of
|
|
@@ -5380,6 +5422,100 @@ function registerFirestore() {
|
|
|
5380
5422
|
app.registerVersion('firestore-lite', version$1, 'cjs5');
|
|
5381
5423
|
}
|
|
5382
5424
|
|
|
5425
|
+
/**
|
|
5426
|
+
* @license
|
|
5427
|
+
* Copyright 2022 Google LLC
|
|
5428
|
+
*
|
|
5429
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5430
|
+
* you may not use this file except in compliance with the License.
|
|
5431
|
+
* You may obtain a copy of the License at
|
|
5432
|
+
*
|
|
5433
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
5434
|
+
*
|
|
5435
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
5436
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
5437
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
5438
|
+
* See the License for the specific language governing permissions and
|
|
5439
|
+
* limitations under the License.
|
|
5440
|
+
*/
|
|
5441
|
+
/**
|
|
5442
|
+
* Represents an aggregation that can be performed by Firestore.
|
|
5443
|
+
*/
|
|
5444
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
5445
|
+
class AggregateField {
|
|
5446
|
+
constructor() {
|
|
5447
|
+
/** A type string to uniquely identify instances of this class. */
|
|
5448
|
+
this.type = 'AggregateField';
|
|
5449
|
+
}
|
|
5450
|
+
}
|
|
5451
|
+
/**
|
|
5452
|
+
* The results of executing an aggregation query.
|
|
5453
|
+
*/
|
|
5454
|
+
class AggregateQuerySnapshot {
|
|
5455
|
+
/** @hideconstructor */
|
|
5456
|
+
constructor(query, _data) {
|
|
5457
|
+
this._data = _data;
|
|
5458
|
+
/** A type string to uniquely identify instances of this class. */
|
|
5459
|
+
this.type = 'AggregateQuerySnapshot';
|
|
5460
|
+
this.query = query;
|
|
5461
|
+
}
|
|
5462
|
+
/**
|
|
5463
|
+
* Returns the results of the aggregations performed over the underlying
|
|
5464
|
+
* query.
|
|
5465
|
+
*
|
|
5466
|
+
* The keys of the returned object will be the same as those of the
|
|
5467
|
+
* `AggregateSpec` object specified to the aggregation method, and the values
|
|
5468
|
+
* will be the corresponding aggregation result.
|
|
5469
|
+
*
|
|
5470
|
+
* @returns The results of the aggregations performed over the underlying
|
|
5471
|
+
* query.
|
|
5472
|
+
*/
|
|
5473
|
+
data() {
|
|
5474
|
+
return this._data;
|
|
5475
|
+
}
|
|
5476
|
+
}
|
|
5477
|
+
|
|
5478
|
+
/**
|
|
5479
|
+
* @license
|
|
5480
|
+
* Copyright 2022 Google LLC
|
|
5481
|
+
*
|
|
5482
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5483
|
+
* you may not use this file except in compliance with the License.
|
|
5484
|
+
* You may obtain a copy of the License at
|
|
5485
|
+
*
|
|
5486
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
5487
|
+
*
|
|
5488
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
5489
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
5490
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
5491
|
+
* See the License for the specific language governing permissions and
|
|
5492
|
+
* limitations under the License.
|
|
5493
|
+
*/
|
|
5494
|
+
/**
|
|
5495
|
+
* CountQueryRunner encapsulates the logic needed to run the count aggregation
|
|
5496
|
+
* queries.
|
|
5497
|
+
*/
|
|
5498
|
+
class CountQueryRunner {
|
|
5499
|
+
constructor(query, datastore, userDataWriter) {
|
|
5500
|
+
this.query = query;
|
|
5501
|
+
this.datastore = datastore;
|
|
5502
|
+
this.userDataWriter = userDataWriter;
|
|
5503
|
+
}
|
|
5504
|
+
run() {
|
|
5505
|
+
return invokeRunAggregationQueryRpc(this.datastore, this.query._query).then(result => {
|
|
5506
|
+
hardAssert(result[0] !== undefined);
|
|
5507
|
+
const counts = Object.entries(result[0])
|
|
5508
|
+
.filter(([key, value]) => key === 'count_alias')
|
|
5509
|
+
.map(([key, value]) => this.userDataWriter.convertValue(value));
|
|
5510
|
+
const countValue = counts[0];
|
|
5511
|
+
hardAssert(typeof countValue === 'number');
|
|
5512
|
+
return Promise.resolve(new AggregateQuerySnapshot(this.query, {
|
|
5513
|
+
count: countValue
|
|
5514
|
+
}));
|
|
5515
|
+
});
|
|
5516
|
+
}
|
|
5517
|
+
}
|
|
5518
|
+
|
|
5383
5519
|
/**
|
|
5384
5520
|
* @license
|
|
5385
5521
|
* Copyright 2020 Google LLC
|
|
@@ -5611,64 +5747,6 @@ function queryEqual(left, right) {
|
|
|
5611
5747
|
return false;
|
|
5612
5748
|
}
|
|
5613
5749
|
|
|
5614
|
-
/**
|
|
5615
|
-
* @license
|
|
5616
|
-
* Copyright 2020 Google LLC
|
|
5617
|
-
*
|
|
5618
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5619
|
-
* you may not use this file except in compliance with the License.
|
|
5620
|
-
* You may obtain a copy of the License at
|
|
5621
|
-
*
|
|
5622
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
5623
|
-
*
|
|
5624
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
5625
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
5626
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
5627
|
-
* See the License for the specific language governing permissions and
|
|
5628
|
-
* limitations under the License.
|
|
5629
|
-
*/
|
|
5630
|
-
/**
|
|
5631
|
-
* A `FieldPath` refers to a field in a document. The path may consist of a
|
|
5632
|
-
* single field name (referring to a top-level field in the document), or a
|
|
5633
|
-
* list of field names (referring to a nested field in the document).
|
|
5634
|
-
*
|
|
5635
|
-
* Create a `FieldPath` by providing field names. If more than one field
|
|
5636
|
-
* name is provided, the path will point to a nested field in a document.
|
|
5637
|
-
*/
|
|
5638
|
-
class FieldPath {
|
|
5639
|
-
/**
|
|
5640
|
-
* Creates a `FieldPath` from the provided field names. If more than one field
|
|
5641
|
-
* name is provided, the path will point to a nested field in a document.
|
|
5642
|
-
*
|
|
5643
|
-
* @param fieldNames - A list of field names.
|
|
5644
|
-
*/
|
|
5645
|
-
constructor(...fieldNames) {
|
|
5646
|
-
for (let i = 0; i < fieldNames.length; ++i) {
|
|
5647
|
-
if (fieldNames[i].length === 0) {
|
|
5648
|
-
throw new FirestoreError(Code.INVALID_ARGUMENT, `Invalid field name at argument $(i + 1). ` +
|
|
5649
|
-
'Field names must not be empty.');
|
|
5650
|
-
}
|
|
5651
|
-
}
|
|
5652
|
-
this._internalPath = new FieldPath$1(fieldNames);
|
|
5653
|
-
}
|
|
5654
|
-
/**
|
|
5655
|
-
* Returns true if this `FieldPath` is equal to the provided one.
|
|
5656
|
-
*
|
|
5657
|
-
* @param other - The `FieldPath` to compare against.
|
|
5658
|
-
* @returns true if this `FieldPath` is equal to the provided one.
|
|
5659
|
-
*/
|
|
5660
|
-
isEqual(other) {
|
|
5661
|
-
return this._internalPath.isEqual(other._internalPath);
|
|
5662
|
-
}
|
|
5663
|
-
}
|
|
5664
|
-
/**
|
|
5665
|
-
* Returns a special sentinel `FieldPath` to refer to the ID of a document.
|
|
5666
|
-
* It can be used in queries to sort or filter by the document ID.
|
|
5667
|
-
*/
|
|
5668
|
-
function documentId() {
|
|
5669
|
-
return new FieldPath(DOCUMENT_KEY_NAME);
|
|
5670
|
-
}
|
|
5671
|
-
|
|
5672
5750
|
/**
|
|
5673
5751
|
* @license
|
|
5674
5752
|
* Copyright 2020 Google LLC
|
|
@@ -5750,6 +5828,64 @@ class Bytes {
|
|
|
5750
5828
|
}
|
|
5751
5829
|
}
|
|
5752
5830
|
|
|
5831
|
+
/**
|
|
5832
|
+
* @license
|
|
5833
|
+
* Copyright 2020 Google LLC
|
|
5834
|
+
*
|
|
5835
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5836
|
+
* you may not use this file except in compliance with the License.
|
|
5837
|
+
* You may obtain a copy of the License at
|
|
5838
|
+
*
|
|
5839
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
5840
|
+
*
|
|
5841
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
5842
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
5843
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
5844
|
+
* See the License for the specific language governing permissions and
|
|
5845
|
+
* limitations under the License.
|
|
5846
|
+
*/
|
|
5847
|
+
/**
|
|
5848
|
+
* A `FieldPath` refers to a field in a document. The path may consist of a
|
|
5849
|
+
* single field name (referring to a top-level field in the document), or a
|
|
5850
|
+
* list of field names (referring to a nested field in the document).
|
|
5851
|
+
*
|
|
5852
|
+
* Create a `FieldPath` by providing field names. If more than one field
|
|
5853
|
+
* name is provided, the path will point to a nested field in a document.
|
|
5854
|
+
*/
|
|
5855
|
+
class FieldPath {
|
|
5856
|
+
/**
|
|
5857
|
+
* Creates a `FieldPath` from the provided field names. If more than one field
|
|
5858
|
+
* name is provided, the path will point to a nested field in a document.
|
|
5859
|
+
*
|
|
5860
|
+
* @param fieldNames - A list of field names.
|
|
5861
|
+
*/
|
|
5862
|
+
constructor(...fieldNames) {
|
|
5863
|
+
for (let i = 0; i < fieldNames.length; ++i) {
|
|
5864
|
+
if (fieldNames[i].length === 0) {
|
|
5865
|
+
throw new FirestoreError(Code.INVALID_ARGUMENT, `Invalid field name at argument $(i + 1). ` +
|
|
5866
|
+
'Field names must not be empty.');
|
|
5867
|
+
}
|
|
5868
|
+
}
|
|
5869
|
+
this._internalPath = new FieldPath$1(fieldNames);
|
|
5870
|
+
}
|
|
5871
|
+
/**
|
|
5872
|
+
* Returns true if this `FieldPath` is equal to the provided one.
|
|
5873
|
+
*
|
|
5874
|
+
* @param other - The `FieldPath` to compare against.
|
|
5875
|
+
* @returns true if this `FieldPath` is equal to the provided one.
|
|
5876
|
+
*/
|
|
5877
|
+
isEqual(other) {
|
|
5878
|
+
return this._internalPath.isEqual(other._internalPath);
|
|
5879
|
+
}
|
|
5880
|
+
}
|
|
5881
|
+
/**
|
|
5882
|
+
* Returns a special sentinel `FieldPath` to refer to the ID of a document.
|
|
5883
|
+
* It can be used in queries to sort or filter by the document ID.
|
|
5884
|
+
*/
|
|
5885
|
+
function documentId() {
|
|
5886
|
+
return new FieldPath(DOCUMENT_KEY_NAME);
|
|
5887
|
+
}
|
|
5888
|
+
|
|
5753
5889
|
/**
|
|
5754
5890
|
* @license
|
|
5755
5891
|
* Copyright 2020 Google LLC
|
|
@@ -7458,6 +7594,58 @@ function addDoc(reference, data) {
|
|
|
7458
7594
|
]).then(() => docRef);
|
|
7459
7595
|
}
|
|
7460
7596
|
|
|
7597
|
+
/**
|
|
7598
|
+
* @license
|
|
7599
|
+
* Copyright 2022 Google LLC
|
|
7600
|
+
*
|
|
7601
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7602
|
+
* you may not use this file except in compliance with the License.
|
|
7603
|
+
* You may obtain a copy of the License at
|
|
7604
|
+
*
|
|
7605
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
7606
|
+
*
|
|
7607
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
7608
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
7609
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
7610
|
+
* See the License for the specific language governing permissions and
|
|
7611
|
+
* limitations under the License.
|
|
7612
|
+
*/
|
|
7613
|
+
/**
|
|
7614
|
+
* Calculates the number of documents in the result set of the given query,
|
|
7615
|
+
* without actually downloading the documents.
|
|
7616
|
+
*
|
|
7617
|
+
* Using this function to count the documents is efficient because only the
|
|
7618
|
+
* final count, not the documents' data, is downloaded. This function can even
|
|
7619
|
+
* count the documents if the result set would be prohibitively large to
|
|
7620
|
+
* download entirely (e.g. thousands of documents).
|
|
7621
|
+
*
|
|
7622
|
+
* @param query - The query whose result set size to calculate.
|
|
7623
|
+
* @returns A Promise that will be resolved with the count; the count can be
|
|
7624
|
+
* retrieved from `snapshot.data().count`, where `snapshot` is the
|
|
7625
|
+
* `AggregateQuerySnapshot` to which the returned Promise resolves.
|
|
7626
|
+
*/
|
|
7627
|
+
function getCount(query) {
|
|
7628
|
+
const firestore = cast(query.firestore, Firestore);
|
|
7629
|
+
const datastore = getDatastore(firestore);
|
|
7630
|
+
const userDataWriter = new LiteUserDataWriter(firestore);
|
|
7631
|
+
return new CountQueryRunner(query, datastore, userDataWriter).run();
|
|
7632
|
+
}
|
|
7633
|
+
/**
|
|
7634
|
+
* Compares two `AggregateQuerySnapshot` instances for equality.
|
|
7635
|
+
*
|
|
7636
|
+
* Two `AggregateQuerySnapshot` instances are considered "equal" if they have
|
|
7637
|
+
* underlying queries that compare equal, and the same data.
|
|
7638
|
+
*
|
|
7639
|
+
* @param left - The first `AggregateQuerySnapshot` to compare.
|
|
7640
|
+
* @param right - The second `AggregateQuerySnapshot` to compare.
|
|
7641
|
+
*
|
|
7642
|
+
* @returns `true` if the objects are "equal", as defined above, or `false`
|
|
7643
|
+
* otherwise.
|
|
7644
|
+
*/
|
|
7645
|
+
function aggregateQuerySnapshotEqual(left, right) {
|
|
7646
|
+
return (queryEqual(left.query, right.query) && util.deepEqual(left.data(), right.data()));
|
|
7647
|
+
}
|
|
7648
|
+
|
|
7461
7649
|
/**
|
|
7462
7650
|
* @license
|
|
7463
7651
|
* Copyright 2020 Google LLC
|
|
@@ -8450,6 +8638,8 @@ function runTransaction(firestore, updateFunction, options) {
|
|
|
8450
8638
|
*/
|
|
8451
8639
|
registerFirestore();
|
|
8452
8640
|
|
|
8641
|
+
exports.AggregateField = AggregateField;
|
|
8642
|
+
exports.AggregateQuerySnapshot = AggregateQuerySnapshot;
|
|
8453
8643
|
exports.Bytes = Bytes;
|
|
8454
8644
|
exports.CollectionReference = CollectionReference;
|
|
8455
8645
|
exports.DocumentReference = DocumentReference;
|
|
@@ -8467,6 +8657,7 @@ exports.Timestamp = Timestamp;
|
|
|
8467
8657
|
exports.Transaction = Transaction;
|
|
8468
8658
|
exports.WriteBatch = WriteBatch;
|
|
8469
8659
|
exports.addDoc = addDoc;
|
|
8660
|
+
exports.aggregateQuerySnapshotEqual = aggregateQuerySnapshotEqual;
|
|
8470
8661
|
exports.arrayRemove = arrayRemove;
|
|
8471
8662
|
exports.arrayUnion = arrayUnion;
|
|
8472
8663
|
exports.collection = collection;
|
|
@@ -8478,6 +8669,7 @@ exports.doc = doc;
|
|
|
8478
8669
|
exports.documentId = documentId;
|
|
8479
8670
|
exports.endAt = endAt;
|
|
8480
8671
|
exports.endBefore = endBefore;
|
|
8672
|
+
exports.getCount = getCount;
|
|
8481
8673
|
exports.getDoc = getDoc;
|
|
8482
8674
|
exports.getDocs = getDocs;
|
|
8483
8675
|
exports.getFirestore = getFirestore;
|