|
15 | 15 | * limitations under the License.
|
16 | 16 | */
|
17 | 17 |
|
| 18 | +import { CompositeFilterOpEnum } from '../protos/firestore_proto_api'; |
18 | 19 | import { invokeRunAggregationQueryRpc } from '../remote/datastore';
|
19 | 20 | import { hardAssert } from '../util/assert';
|
20 | 21 | import { cast } from '../util/input_validation';
|
@@ -82,19 +83,24 @@ export function getAggregateFromServerDirect(
|
82 | 83 |
|
83 | 84 | return invokeRunAggregationQueryRpc(datastore, aggregateQuery).then(
|
84 | 85 | result => {
|
85 |
| - const aggregationFields = new Map<string, any>(); |
| 86 | + hardAssert( |
| 87 | + result[0] !== undefined, |
| 88 | + 'Aggregation fields are missing from result.' |
| 89 | + ); |
86 | 90 |
|
87 |
| - for (const [key, value] of Object.entries(result[0])) { |
88 |
| - aggregationFields.set(key, userDataWriter.convertValue(value)); |
89 |
| - } |
90 |
| - const countField = aggregationFields.get('count_alias'); |
| 91 | + const countField = (result[0] as any).count_alias; |
| 92 | + hardAssert( |
| 93 | + countField !== undefined, |
| 94 | + 'Count field is missing from result.' |
| 95 | + ); |
91 | 96 |
|
| 97 | + const countAggregateResult = userDataWriter.convertValue(countField); |
92 | 98 | hardAssert(
|
93 |
| - countField !== undefined && typeof countField === 'number', |
94 |
| - 'Count aggeragte field is invalid. countField:' + countField |
| 99 | + typeof countAggregateResult === 'number', |
| 100 | + 'Count aggeragte field is not a number: ' + countAggregateResult |
95 | 101 | );
|
96 | 102 | return Promise.resolve(
|
97 |
| - new AggregateQuerySnapshot(aggregateQuery, countField!) |
| 103 | + new AggregateQuerySnapshot(aggregateQuery, countAggregateResult) |
98 | 104 | );
|
99 | 105 | }
|
100 | 106 | );
|
|
0 commit comments