Skip to content

Mila/count add api interface #6499

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 5 commits into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions common/api-review/firestore.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,30 @@ export type AddPrefixToKeys<Prefix extends string, T extends Record<string, unkn
[K in keyof T & string as `${Prefix}.${K}`]+?: T[K];
};

Copy link
Contributor Author

@milaGGL milaGGL Aug 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

auto-updated file by API Extractor

// @public (undocumented)
export class AggregateQuery<T = DocumentData> {
// (undocumented)
readonly query: Query<T>;
// (undocumented)
readonly type = "AggregateQuery";
}

// @public (undocumented)
export function aggregateQueryEqual(left: AggregateQuery, right: AggregateQuery): boolean;

// @public (undocumented)
export class AggregateQuerySnapshot {
// (undocumented)
getCount(): number | null;
// (undocumented)
readonly query: AggregateQuery;
// (undocumented)
readonly type = "AggregateQuerySnapshot";
}

// @public (undocumented)
export function aggregateQuerySnapshotEqual(left: AggregateQuerySnapshot, right: AggregateQuerySnapshot): boolean;

// @public
export function arrayRemove(...elements: unknown[]): FieldValue;

Expand Down Expand Up @@ -69,6 +93,9 @@ export function connectFirestoreEmulator(firestore: Firestore, host: string, por
mockUserToken?: EmulatorMockTokenOptions | string;
}): void;

// @public (undocumented)
export function countQuery(query: Query): AggregateQuery;

// @public
export function deleteDoc(reference: DocumentReference<unknown>): Promise<void>;

Expand Down Expand Up @@ -209,6 +236,9 @@ export class GeoPoint {
};
}

// @public (undocumented)
export function getAggregateFromServerDirect(query: AggregateQuery): Promise<AggregateQuerySnapshot>;

// @public
export function getDoc<T>(reference: DocumentReference<T>): Promise<DocumentSnapshot<T>>;

Expand Down
9 changes: 9 additions & 0 deletions packages/firestore/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@
* limitations under the License.
*/

export {
AggregateQuery,
AggregateQuerySnapshot,
aggregateQueryEqual,
aggregateQuerySnapshotEqual,
countQuery,
getAggregateFromServerDirect
} from './api/aggregate';

export { FieldPath, documentId } from './api/field_path';

export {
Expand Down
25 changes: 25 additions & 0 deletions packages/firestore/src/api/aggregate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* @license
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

export {
AggregateQuery,
AggregateQuerySnapshot,
aggregateQueryEqual,
aggregateQuerySnapshotEqual,
countQuery,
getAggregateFromServerDirect
} from '../lite-api/aggregate';
69 changes: 69 additions & 0 deletions packages/firestore/src/lite-api/aggregate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* @license
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { DocumentData, Query, queryEqual } from './reference';

export class AggregateQuery<T = DocumentData> {
readonly type = 'AggregateQuery';
readonly query: Query<T>;

/** @hideconstructor */
constructor(query: Query<T>) {
this.query = query;
}
}

export class AggregateQuerySnapshot {
readonly type = 'AggregateQuerySnapshot';
readonly query: AggregateQuery;

/** @hideconstructor */
constructor(query: AggregateQuery, readonly _count: number) {
this.query = query;
}

getCount(): number | null {
return this._count;
}
}

export function countQuery(query: Query): AggregateQuery {
return new AggregateQuery(query);
}

export function getAggregateFromServerDirect(
query: AggregateQuery
): Promise<AggregateQuerySnapshot> {
return Promise.resolve(new AggregateQuerySnapshot(query, 42));
}

export function aggregateQueryEqual(
left: AggregateQuery,
right: AggregateQuery
): boolean {
return queryEqual(left.query, right.query);
}

export function aggregateQuerySnapshotEqual(
left: AggregateQuerySnapshot,
right: AggregateQuerySnapshot
): boolean {
return (
aggregateQueryEqual(left.query, right.query) &&
left.getCount() === right.getCount()
);
}