Skip to content

Tests for sum and average. #7000

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Feb 8, 2023
5 changes: 4 additions & 1 deletion common/api-review/firestore-lite.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export interface AggregateSpec {

// @public
export type AggregateSpecData<T extends AggregateSpec> = {
[P in keyof T]: T[P] extends AggregateField<infer U> ? U : never;
[P in keyof T as TrimBackticks<P>]: T[P] extends AggregateField<infer U> ? U : never;
};

// @public
Expand Down Expand Up @@ -401,6 +401,9 @@ export interface TransactionOptions {
readonly maxAttempts?: number;
}

// @public
export type TrimBackticks<T> = T extends `\`${infer Body}\`` ? Body : T;

// @public
export type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;

Expand Down
5 changes: 4 additions & 1 deletion common/api-review/firestore.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export interface AggregateSpec {

// @public
export type AggregateSpecData<T extends AggregateSpec> = {
[P in keyof T]: T[P] extends AggregateField<infer U> ? U : never;
[P in keyof T as TrimBackticks<P>]: T[P] extends AggregateField<infer U> ? U : never;
};

// @public
Expand Down Expand Up @@ -575,6 +575,9 @@ export interface TransactionOptions {
readonly maxAttempts?: number;
}

// @public
export type TrimBackticks<T> = T extends `\`${infer Body}\`` ? Body : T;

// @public
export type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;

Expand Down
6 changes: 4 additions & 2 deletions packages/firestore/lite/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ export {
getAggregate,
count,
sum,
average
average,
aggregateFieldEqual
} from '../src/lite-api/aggregate';

export {
Expand All @@ -42,7 +43,8 @@ export {
AggregateSpec,
AggregateSpecData,
AggregateQuerySnapshot,
AggregateType
AggregateType,
TrimBackticks
} from '../src/lite-api/aggregate_types';

export { FirestoreSettings as Settings } from '../src/lite-api/settings';
Expand Down
4 changes: 3 additions & 1 deletion packages/firestore/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@ export {
getAggregateFromServer,
count,
sum,
average
average,
aggregateFieldEqual
} from './api/aggregate';

export {
AggregateField,
AggregateFieldType,
AggregateSpec,
AggregateSpecData,
TrimBackticks,
AggregateQuerySnapshot,
AggregateType
} from './lite-api/aggregate_types';
Expand Down
6 changes: 2 additions & 4 deletions packages/firestore/src/api/aggregate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export {
aggregateQuerySnapshotEqual,
count,
sum,
average
average,
aggregateFieldEqual
} from '../lite-api/aggregate';

/**
Expand Down Expand Up @@ -107,9 +108,6 @@ export function getAggregateFromServer<T extends AggregateSpec>(
const client = ensureFirestoreConfigured(firestore);

const internalAggregates = mapToArray(aggregateSpec, (aggregate, alias) => {
// TODO (sum/avg) should alias validation be performed or should that be
// delegated to the backend?

return new AggregateImpl(
alias,
aggregate._aggregateType,
Expand Down
4 changes: 1 addition & 3 deletions packages/firestore/src/lite-api/aggregate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,6 @@ export function getAggregate<T extends AggregateSpec>(
const datastore = getDatastore(firestore);

const internalAggregates = mapToArray(aggregateSpec, (aggregate, alias) => {
// TODO (sum/avg) should alias validation be performed or should that be
// delegated to the backend?

return new AggregateImpl(
alias,
aggregate._aggregateType,
Expand Down Expand Up @@ -164,6 +161,7 @@ export function count(): AggregateField<number> {
*
* @param left Compare this AggregateField to the `right`.
* @param right Compare this AggregateField to the `left`.
* @internal TODO (sum/avg) remove when public
*/
export function aggregateFieldEqual(
left: AggregateField<unknown>,
Expand Down
11 changes: 10 additions & 1 deletion packages/firestore/src/lite-api/aggregate_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,18 @@ export interface AggregateSpec {
* from the input `AggregateSpec`.
*/
export type AggregateSpecData<T extends AggregateSpec> = {
[P in keyof T]: T[P] extends AggregateField<infer U> ? U : never;
[P in keyof T as TrimBackticks<P>]: T[P] extends AggregateField<infer U>
? U
: never;
};

/**
* Removes enclosing backticks.
* type Foo = '`Foo`'
* type TrimmedFoo = TrimBackticks<Foo>; // 'Foo'
*/
export type TrimBackticks<T> = T extends `\`${infer Body}\`` ? Body : T;

/**
* The results of executing an aggregation query.
*/
Expand Down
Loading