@firebase/firestore 3.5.0 → 3.6.0-canary.03d1fabcb

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.
Files changed (122) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/firestore/lite/index.d.ts +2 -0
  3. package/dist/firestore/src/api/aggregate.d.ts +43 -0
  4. package/dist/firestore/src/api/database.d.ts +15 -15
  5. package/dist/firestore/src/api.d.ts +2 -0
  6. package/dist/firestore/src/core/count_query_runner.d.ts +32 -0
  7. package/dist/firestore/src/core/firestore_client.d.ts +5 -0
  8. package/dist/firestore/src/core/view.d.ts +1 -0
  9. package/dist/firestore/src/core/view_snapshot.d.ts +3 -2
  10. package/dist/firestore/src/lite-api/aggregate.d.ts +48 -0
  11. package/dist/firestore/src/lite-api/aggregate_types.d.ts +69 -0
  12. package/dist/firestore/src/lite-api/database.d.ts +7 -7
  13. package/dist/firestore/src/platform/node/grpc_connection.d.ts +1 -0
  14. package/dist/firestore/src/protos/firestore_proto_api.d.ts +28 -0
  15. package/dist/firestore/src/remote/connection.d.ts +7 -0
  16. package/dist/firestore/src/remote/datastore.d.ts +2 -0
  17. package/dist/firestore/src/remote/remote_event.d.ts +2 -2
  18. package/dist/firestore/src/remote/rest_connection.d.ts +1 -0
  19. package/dist/firestore/src/remote/serializer.d.ts +2 -1
  20. package/dist/firestore/test/integration/api/aggregation.test.d.ts +17 -0
  21. package/dist/firestore/test/integration/api_internal/aggregation.test.d.ts +17 -0
  22. package/dist/firestore/test/integration/util/helpers.d.ts +1 -0
  23. package/dist/firestore/test/unit/specs/spec_test_components.d.ts +1 -0
  24. package/dist/firestore/test/util/api_helpers.d.ts +1 -1
  25. package/dist/index.d.ts +196 -14
  26. package/dist/index.esm2017.js +4630 -4428
  27. package/dist/index.esm2017.js.map +1 -1
  28. package/dist/index.esm5.js +4705 -4500
  29. package/dist/index.esm5.js.map +1 -1
  30. package/dist/index.node.cjs.js +1020 -632
  31. package/dist/index.node.cjs.js.map +1 -1
  32. package/dist/index.node.mjs +1018 -634
  33. package/dist/index.node.mjs.map +1 -1
  34. package/dist/index.rn.js +4634 -4432
  35. package/dist/index.rn.js.map +1 -1
  36. package/dist/internal.d.ts +144 -21
  37. package/dist/lite/firestore/lite/index.d.ts +2 -0
  38. package/dist/lite/firestore/src/api/aggregate.d.ts +43 -0
  39. package/dist/lite/firestore/src/api/database.d.ts +15 -15
  40. package/dist/lite/firestore/src/api.d.ts +2 -0
  41. package/dist/lite/firestore/src/core/count_query_runner.d.ts +32 -0
  42. package/dist/lite/firestore/src/core/firestore_client.d.ts +5 -0
  43. package/dist/lite/firestore/src/core/view.d.ts +1 -0
  44. package/dist/lite/firestore/src/core/view_snapshot.d.ts +3 -2
  45. package/dist/lite/firestore/src/lite-api/aggregate.d.ts +48 -0
  46. package/dist/lite/firestore/src/lite-api/aggregate_types.d.ts +69 -0
  47. package/dist/lite/firestore/src/lite-api/database.d.ts +7 -7
  48. package/dist/lite/firestore/src/platform/node/grpc_connection.d.ts +1 -0
  49. package/dist/lite/firestore/src/protos/firestore_proto_api.d.ts +28 -0
  50. package/dist/lite/firestore/src/remote/connection.d.ts +7 -0
  51. package/dist/lite/firestore/src/remote/datastore.d.ts +2 -0
  52. package/dist/lite/firestore/src/remote/remote_event.d.ts +2 -2
  53. package/dist/lite/firestore/src/remote/rest_connection.d.ts +1 -0
  54. package/dist/lite/firestore/src/remote/serializer.d.ts +2 -1
  55. package/dist/lite/firestore/test/integration/api/aggregation.test.d.ts +17 -0
  56. package/dist/lite/firestore/test/integration/api_internal/aggregation.test.d.ts +17 -0
  57. package/dist/lite/firestore/test/integration/util/helpers.d.ts +1 -0
  58. package/dist/lite/firestore/test/unit/specs/spec_test_components.d.ts +1 -0
  59. package/dist/lite/firestore/test/util/api_helpers.d.ts +1 -1
  60. package/dist/lite/index.browser.esm2017.js +1247 -1086
  61. package/dist/lite/index.browser.esm2017.js.map +1 -1
  62. package/dist/lite/index.browser.esm5.js +1392 -1233
  63. package/dist/lite/index.browser.esm5.js.map +1 -1
  64. package/dist/lite/index.d.ts +84 -4
  65. package/dist/lite/index.node.cjs.js +254 -63
  66. package/dist/lite/index.node.cjs.js.map +1 -1
  67. package/dist/lite/index.node.mjs +252 -65
  68. package/dist/lite/index.node.mjs.map +1 -1
  69. package/dist/lite/index.rn.esm2017.js +1254 -1093
  70. package/dist/lite/index.rn.esm2017.js.map +1 -1
  71. package/dist/lite/internal.d.ts +121 -6
  72. package/dist/lite/packages/firestore/dist/lite/index.browser.esm2017.d.ts +227 -142
  73. package/dist/lite/packages/firestore/lite/index.d.ts +2 -0
  74. package/dist/lite/packages/firestore/src/api/aggregate.d.ts +43 -0
  75. package/dist/lite/packages/firestore/src/api/database.d.ts +15 -15
  76. package/dist/lite/packages/firestore/src/api.d.ts +2 -0
  77. package/dist/lite/packages/firestore/src/core/count_query_runner.d.ts +32 -0
  78. package/dist/lite/packages/firestore/src/core/firestore_client.d.ts +5 -0
  79. package/dist/lite/packages/firestore/src/core/view.d.ts +1 -0
  80. package/dist/lite/packages/firestore/src/core/view_snapshot.d.ts +3 -2
  81. package/dist/lite/packages/firestore/src/lite-api/aggregate.d.ts +48 -0
  82. package/dist/lite/packages/firestore/src/lite-api/aggregate_types.d.ts +69 -0
  83. package/dist/lite/packages/firestore/src/lite-api/database.d.ts +7 -7
  84. package/dist/lite/packages/firestore/src/platform/node/grpc_connection.d.ts +1 -0
  85. package/dist/lite/packages/firestore/src/protos/firestore_proto_api.d.ts +28 -0
  86. package/dist/lite/packages/firestore/src/remote/connection.d.ts +7 -0
  87. package/dist/lite/packages/firestore/src/remote/datastore.d.ts +2 -0
  88. package/dist/lite/packages/firestore/src/remote/remote_event.d.ts +2 -2
  89. package/dist/lite/packages/firestore/src/remote/rest_connection.d.ts +1 -0
  90. package/dist/lite/packages/firestore/src/remote/serializer.d.ts +2 -1
  91. package/dist/lite/packages/firestore/test/integration/api/aggregation.test.d.ts +17 -0
  92. package/dist/lite/packages/firestore/test/integration/api_internal/aggregation.test.d.ts +17 -0
  93. package/dist/lite/packages/firestore/test/integration/util/helpers.d.ts +1 -0
  94. package/dist/lite/packages/firestore/test/unit/specs/spec_test_components.d.ts +1 -0
  95. package/dist/lite/packages/firestore/test/util/api_helpers.d.ts +1 -1
  96. package/dist/lite/private.d.ts +119 -4
  97. package/dist/packages/firestore/dist/index.esm2017.d.ts +336 -254
  98. package/dist/packages/firestore/lite/index.d.ts +2 -0
  99. package/dist/packages/firestore/src/api/aggregate.d.ts +43 -0
  100. package/dist/packages/firestore/src/api/database.d.ts +15 -15
  101. package/dist/packages/firestore/src/api.d.ts +2 -0
  102. package/dist/packages/firestore/src/core/count_query_runner.d.ts +32 -0
  103. package/dist/packages/firestore/src/core/firestore_client.d.ts +5 -0
  104. package/dist/packages/firestore/src/core/view.d.ts +1 -0
  105. package/dist/packages/firestore/src/core/view_snapshot.d.ts +3 -2
  106. package/dist/packages/firestore/src/lite-api/aggregate.d.ts +48 -0
  107. package/dist/packages/firestore/src/lite-api/aggregate_types.d.ts +69 -0
  108. package/dist/packages/firestore/src/lite-api/database.d.ts +7 -7
  109. package/dist/packages/firestore/src/platform/node/grpc_connection.d.ts +1 -0
  110. package/dist/packages/firestore/src/protos/firestore_proto_api.d.ts +28 -0
  111. package/dist/packages/firestore/src/remote/connection.d.ts +7 -0
  112. package/dist/packages/firestore/src/remote/datastore.d.ts +2 -0
  113. package/dist/packages/firestore/src/remote/remote_event.d.ts +2 -2
  114. package/dist/packages/firestore/src/remote/rest_connection.d.ts +1 -0
  115. package/dist/packages/firestore/src/remote/serializer.d.ts +2 -1
  116. package/dist/packages/firestore/test/integration/api/aggregation.test.d.ts +17 -0
  117. package/dist/packages/firestore/test/integration/api_internal/aggregation.test.d.ts +17 -0
  118. package/dist/packages/firestore/test/integration/util/helpers.d.ts +1 -0
  119. package/dist/packages/firestore/test/unit/specs/spec_test_components.d.ts +1 -0
  120. package/dist/packages/firestore/test/util/api_helpers.d.ts +1 -1
  121. package/dist/private.d.ts +239 -23
  122. package/package.json +9 -9
@@ -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.5.0";
17
+ const version$1 = "3.6.0-canary.03d1fabcb";
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.10.0";
70
+ const version = "9.11.0-canary.03d1fabcb";
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,16 @@ function getFirestore(appOrDatabaseId, optionalDatabaseId) {
5277
5311
  const databaseId = typeof appOrDatabaseId === 'string'
5278
5312
  ? appOrDatabaseId
5279
5313
  : optionalDatabaseId || '(default)';
5280
- return app._getProvider(app$1, 'firestore/lite').getImmediate({
5314
+ const db = app._getProvider(app$1, 'firestore/lite').getImmediate({
5281
5315
  identifier: databaseId
5282
5316
  });
5317
+ if (!db._initialized) {
5318
+ const emulator = util.getDefaultEmulatorHostnameAndPort('firestore');
5319
+ if (emulator) {
5320
+ connectFirestoreEmulator(db, ...emulator);
5321
+ }
5322
+ }
5323
+ return db;
5283
5324
  }
5284
5325
  /**
5285
5326
  * Modify this instance to communicate with the Cloud Firestore emulator.
@@ -5332,7 +5373,7 @@ function connectFirestoreEmulator(firestore, host, port, options = {}) {
5332
5373
  * response from the server will not be resolved.
5333
5374
  *
5334
5375
  * To restart after termination, create a new instance of `Firestore` with
5335
- * {@link getFirestore}.
5376
+ * {@link (getFirestore:1)}.
5336
5377
  *
5337
5378
  * Note: Under normal circumstances, calling `terminate()` is not required. This
5338
5379
  * function is useful only when you want to force this instance to release all of
@@ -5380,6 +5421,100 @@ function registerFirestore() {
5380
5421
  app.registerVersion('firestore-lite', version$1, 'cjs5');
5381
5422
  }
5382
5423
 
5424
+ /**
5425
+ * @license
5426
+ * Copyright 2022 Google LLC
5427
+ *
5428
+ * Licensed under the Apache License, Version 2.0 (the "License");
5429
+ * you may not use this file except in compliance with the License.
5430
+ * You may obtain a copy of the License at
5431
+ *
5432
+ * http://www.apache.org/licenses/LICENSE-2.0
5433
+ *
5434
+ * Unless required by applicable law or agreed to in writing, software
5435
+ * distributed under the License is distributed on an "AS IS" BASIS,
5436
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
5437
+ * See the License for the specific language governing permissions and
5438
+ * limitations under the License.
5439
+ */
5440
+ /**
5441
+ * Represents an aggregation that can be performed by Firestore.
5442
+ */
5443
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
5444
+ class AggregateField {
5445
+ constructor() {
5446
+ /** A type string to uniquely identify instances of this class. */
5447
+ this.type = 'AggregateField';
5448
+ }
5449
+ }
5450
+ /**
5451
+ * The results of executing an aggregation query.
5452
+ */
5453
+ class AggregateQuerySnapshot {
5454
+ /** @hideconstructor */
5455
+ constructor(query, _data) {
5456
+ this._data = _data;
5457
+ /** A type string to uniquely identify instances of this class. */
5458
+ this.type = 'AggregateQuerySnapshot';
5459
+ this.query = query;
5460
+ }
5461
+ /**
5462
+ * Returns the results of the aggregations performed over the underlying
5463
+ * query.
5464
+ *
5465
+ * The keys of the returned object will be the same as those of the
5466
+ * `AggregateSpec` object specified to the aggregation method, and the values
5467
+ * will be the corresponding aggregation result.
5468
+ *
5469
+ * @returns The results of the aggregations performed over the underlying
5470
+ * query.
5471
+ */
5472
+ data() {
5473
+ return this._data;
5474
+ }
5475
+ }
5476
+
5477
+ /**
5478
+ * @license
5479
+ * Copyright 2022 Google LLC
5480
+ *
5481
+ * Licensed under the Apache License, Version 2.0 (the "License");
5482
+ * you may not use this file except in compliance with the License.
5483
+ * You may obtain a copy of the License at
5484
+ *
5485
+ * http://www.apache.org/licenses/LICENSE-2.0
5486
+ *
5487
+ * Unless required by applicable law or agreed to in writing, software
5488
+ * distributed under the License is distributed on an "AS IS" BASIS,
5489
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
5490
+ * See the License for the specific language governing permissions and
5491
+ * limitations under the License.
5492
+ */
5493
+ /**
5494
+ * CountQueryRunner encapsulates the logic needed to run the count aggregation
5495
+ * queries.
5496
+ */
5497
+ class CountQueryRunner {
5498
+ constructor(query, datastore, userDataWriter) {
5499
+ this.query = query;
5500
+ this.datastore = datastore;
5501
+ this.userDataWriter = userDataWriter;
5502
+ }
5503
+ run() {
5504
+ return invokeRunAggregationQueryRpc(this.datastore, this.query._query).then(result => {
5505
+ hardAssert(result[0] !== undefined);
5506
+ const counts = Object.entries(result[0])
5507
+ .filter(([key, value]) => key === 'count_alias')
5508
+ .map(([key, value]) => this.userDataWriter.convertValue(value));
5509
+ const countValue = counts[0];
5510
+ hardAssert(typeof countValue === 'number');
5511
+ return Promise.resolve(new AggregateQuerySnapshot(this.query, {
5512
+ count: countValue
5513
+ }));
5514
+ });
5515
+ }
5516
+ }
5517
+
5383
5518
  /**
5384
5519
  * @license
5385
5520
  * Copyright 2020 Google LLC
@@ -5611,64 +5746,6 @@ function queryEqual(left, right) {
5611
5746
  return false;
5612
5747
  }
5613
5748
 
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
5749
  /**
5673
5750
  * @license
5674
5751
  * Copyright 2020 Google LLC
@@ -5750,6 +5827,64 @@ class Bytes {
5750
5827
  }
5751
5828
  }
5752
5829
 
5830
+ /**
5831
+ * @license
5832
+ * Copyright 2020 Google LLC
5833
+ *
5834
+ * Licensed under the Apache License, Version 2.0 (the "License");
5835
+ * you may not use this file except in compliance with the License.
5836
+ * You may obtain a copy of the License at
5837
+ *
5838
+ * http://www.apache.org/licenses/LICENSE-2.0
5839
+ *
5840
+ * Unless required by applicable law or agreed to in writing, software
5841
+ * distributed under the License is distributed on an "AS IS" BASIS,
5842
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
5843
+ * See the License for the specific language governing permissions and
5844
+ * limitations under the License.
5845
+ */
5846
+ /**
5847
+ * A `FieldPath` refers to a field in a document. The path may consist of a
5848
+ * single field name (referring to a top-level field in the document), or a
5849
+ * list of field names (referring to a nested field in the document).
5850
+ *
5851
+ * Create a `FieldPath` by providing field names. If more than one field
5852
+ * name is provided, the path will point to a nested field in a document.
5853
+ */
5854
+ class FieldPath {
5855
+ /**
5856
+ * Creates a `FieldPath` from the provided field names. If more than one field
5857
+ * name is provided, the path will point to a nested field in a document.
5858
+ *
5859
+ * @param fieldNames - A list of field names.
5860
+ */
5861
+ constructor(...fieldNames) {
5862
+ for (let i = 0; i < fieldNames.length; ++i) {
5863
+ if (fieldNames[i].length === 0) {
5864
+ throw new FirestoreError(Code.INVALID_ARGUMENT, `Invalid field name at argument $(i + 1). ` +
5865
+ 'Field names must not be empty.');
5866
+ }
5867
+ }
5868
+ this._internalPath = new FieldPath$1(fieldNames);
5869
+ }
5870
+ /**
5871
+ * Returns true if this `FieldPath` is equal to the provided one.
5872
+ *
5873
+ * @param other - The `FieldPath` to compare against.
5874
+ * @returns true if this `FieldPath` is equal to the provided one.
5875
+ */
5876
+ isEqual(other) {
5877
+ return this._internalPath.isEqual(other._internalPath);
5878
+ }
5879
+ }
5880
+ /**
5881
+ * Returns a special sentinel `FieldPath` to refer to the ID of a document.
5882
+ * It can be used in queries to sort or filter by the document ID.
5883
+ */
5884
+ function documentId() {
5885
+ return new FieldPath(DOCUMENT_KEY_NAME);
5886
+ }
5887
+
5753
5888
  /**
5754
5889
  * @license
5755
5890
  * Copyright 2020 Google LLC
@@ -7458,6 +7593,58 @@ function addDoc(reference, data) {
7458
7593
  ]).then(() => docRef);
7459
7594
  }
7460
7595
 
7596
+ /**
7597
+ * @license
7598
+ * Copyright 2022 Google LLC
7599
+ *
7600
+ * Licensed under the Apache License, Version 2.0 (the "License");
7601
+ * you may not use this file except in compliance with the License.
7602
+ * You may obtain a copy of the License at
7603
+ *
7604
+ * http://www.apache.org/licenses/LICENSE-2.0
7605
+ *
7606
+ * Unless required by applicable law or agreed to in writing, software
7607
+ * distributed under the License is distributed on an "AS IS" BASIS,
7608
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7609
+ * See the License for the specific language governing permissions and
7610
+ * limitations under the License.
7611
+ */
7612
+ /**
7613
+ * Calculates the number of documents in the result set of the given query,
7614
+ * without actually downloading the documents.
7615
+ *
7616
+ * Using this function to count the documents is efficient because only the
7617
+ * final count, not the documents' data, is downloaded. This function can even
7618
+ * count the documents if the result set would be prohibitively large to
7619
+ * download entirely (e.g. thousands of documents).
7620
+ *
7621
+ * @param query - The query whose result set size to calculate.
7622
+ * @returns A Promise that will be resolved with the count; the count can be
7623
+ * retrieved from `snapshot.data().count`, where `snapshot` is the
7624
+ * `AggregateQuerySnapshot` to which the returned Promise resolves.
7625
+ */
7626
+ function getCount(query) {
7627
+ const firestore = cast(query.firestore, Firestore);
7628
+ const datastore = getDatastore(firestore);
7629
+ const userDataWriter = new LiteUserDataWriter(firestore);
7630
+ return new CountQueryRunner(query, datastore, userDataWriter).run();
7631
+ }
7632
+ /**
7633
+ * Compares two `AggregateQuerySnapshot` instances for equality.
7634
+ *
7635
+ * Two `AggregateQuerySnapshot` instances are considered "equal" if they have
7636
+ * underlying queries that compare equal, and the same data.
7637
+ *
7638
+ * @param left - The first `AggregateQuerySnapshot` to compare.
7639
+ * @param right - The second `AggregateQuerySnapshot` to compare.
7640
+ *
7641
+ * @returns `true` if the objects are "equal", as defined above, or `false`
7642
+ * otherwise.
7643
+ */
7644
+ function aggregateQuerySnapshotEqual(left, right) {
7645
+ return (queryEqual(left.query, right.query) && util.deepEqual(left.data(), right.data()));
7646
+ }
7647
+
7461
7648
  /**
7462
7649
  * @license
7463
7650
  * Copyright 2020 Google LLC
@@ -8450,6 +8637,8 @@ function runTransaction(firestore, updateFunction, options) {
8450
8637
  */
8451
8638
  registerFirestore();
8452
8639
 
8640
+ exports.AggregateField = AggregateField;
8641
+ exports.AggregateQuerySnapshot = AggregateQuerySnapshot;
8453
8642
  exports.Bytes = Bytes;
8454
8643
  exports.CollectionReference = CollectionReference;
8455
8644
  exports.DocumentReference = DocumentReference;
@@ -8467,6 +8656,7 @@ exports.Timestamp = Timestamp;
8467
8656
  exports.Transaction = Transaction;
8468
8657
  exports.WriteBatch = WriteBatch;
8469
8658
  exports.addDoc = addDoc;
8659
+ exports.aggregateQuerySnapshotEqual = aggregateQuerySnapshotEqual;
8470
8660
  exports.arrayRemove = arrayRemove;
8471
8661
  exports.arrayUnion = arrayUnion;
8472
8662
  exports.collection = collection;
@@ -8478,6 +8668,7 @@ exports.doc = doc;
8478
8668
  exports.documentId = documentId;
8479
8669
  exports.endAt = endAt;
8480
8670
  exports.endBefore = endBefore;
8671
+ exports.getCount = getCount;
8481
8672
  exports.getDoc = getDoc;
8482
8673
  exports.getDocs = getDocs;
8483
8674
  exports.getFirestore = getFirestore;