Skip to content

Commit

Permalink
Merge master into release
Browse files Browse the repository at this point in the history
  • Loading branch information
google-oss-bot authored Oct 10, 2023
2 parents c0e1ce5 + 02e2518 commit 6c74255
Show file tree
Hide file tree
Showing 34 changed files with 1,388 additions and 726 deletions.
6 changes: 6 additions & 0 deletions .changeset/beige-oranges-eat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@firebase/firestore": minor
"firebase": minor
---

Support sum and average aggregations.
6 changes: 6 additions & 0 deletions .changeset/flat-cups-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@firebase/firestore': minor
'firebase': minor
---

Added a default template type parameter to withConverter() functions to improve backwards compatibility with the v9 SDK
40 changes: 20 additions & 20 deletions .github/workflows/test-all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ jobs:
build:
name: Build the SDK
runs-on: ubuntu-latest
env:
NODE_OPTIONS: "--max_old_space_size=4096"
steps:
# Install Chrome so the correct version of webdriver can be installed by chromedriver when
# setting up the repo. This must be done to build and execute Auth properly.
Expand All @@ -28,8 +30,6 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: 16.x
- name: Bump Node memory limit
run: echo "NODE_OPTIONS=--max_old_space_size=4096" >> $GITHUB_ENV
- name: Test setup and yarn install
run: |
cp config/ci.config.json config/project.json
Expand All @@ -54,12 +54,13 @@ jobs:
name: (bulk) Node.js and Browser (Chrome) Tests
needs: build
runs-on: ubuntu-latest
env:
NODE_OPTIONS: "--max_old_space_size=4096"
steps:
# install Chrome first, so the correct version of webdriver can be installed by chromedriver when setting up the repo
- name: install Chrome stable
run: |
sudo apt-get update
sudo apt-get install google-chrome-stable
npx @puppeteer/browsers install chrome@stable
- name: Download build archive
uses: actions/download-artifact@v3
with:
Expand All @@ -70,8 +71,6 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: 16.x
- name: Bump Node memory limit
run: echo "NODE_OPTIONS=--max_old_space_size=4096" >> $GITHUB_ENV
- name: Test setup and yarn install
run: |
cp config/ci.config.json config/project.json
Expand All @@ -98,12 +97,14 @@ jobs:
name: (Auth) Node.js and Browser (Chrome) Tests
needs: build
runs-on: ubuntu-latest
env:
NODE_OPTIONS: "--max_old_space_size=4096"
steps:
# install Chrome first, so the correct version of webdriver can be installed by chromedriver
# when setting up the repo
- name: install Chrome stable
run: |
npx @puppeteer/browsers install chrome@stable
- name: install Chrome stable
run: |
npx @puppeteer/browsers install chrome@stable
- name: Download build archive
uses: actions/download-artifact@v3
with:
Expand All @@ -114,8 +115,6 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: 16.x
- name: Bump Node memory limit
run: echo "NODE_OPTIONS=--max_old_space_size=4096" >> $GITHUB_ENV
- name: Test setup and yarn install
run: |
cp config/ci.config.json config/project.json
Expand All @@ -141,12 +140,16 @@ jobs:
name: (Firestore) Node.js and Browser (Chrome) Tests
needs: build
runs-on: ubuntu-latest
if: false
# Disable test for now since it's failing 100% of the time since
# https://github.com/firebase/firebase-js-sdk/pull/7453 and it needs to be investigated.
env:
NODE_OPTIONS: "--max_old_space_size=4096"
steps:
# install Chrome so the correct version of webdriver can be installed by chromedriver when setting up the repo
- name: install Chrome stable
run: |
sudo apt-get update
sudo apt-get install google-chrome-stable
npx @puppeteer/browsers install chrome@stable
- name: Download build archive
uses: actions/download-artifact@v3
with:
Expand All @@ -157,8 +160,6 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: 16.x
- name: Bump Node memory limit
run: echo "NODE_OPTIONS=--max_old_space_size=4096" >> $GITHUB_ENV
- name: Test setup and yarn install
run: |
cp config/ci.config.json config/project.json
Expand All @@ -171,6 +172,7 @@ jobs:
node scripts/print_test_logs.js
env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_CLI_TOKEN }}
EXPERIMENTAL_MODE: true
- name: Generate coverage file
run: yarn ci:coverage
- name: Run coverage
Expand All @@ -179,7 +181,6 @@ jobs:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: ./lcov-all.info
continue-on-error: true

test-firestore-integration:
strategy:
fail-fast: false
Expand All @@ -188,12 +189,13 @@ jobs:
name: Firestore Integration Tests (${{ matrix.persistence }})
needs: build
runs-on: ubuntu-latest
env:
NODE_OPTIONS: "--max_old_space_size=4096"
steps:
# install Chrome so the correct version of webdriver can be installed by chromedriver when setting up the repo
- name: install Chrome stable
run: |
sudo apt-get update
sudo apt-get install google-chrome-stable
npx @puppeteer/browsers install chrome@stable
- name: Download build archive
uses: actions/download-artifact@v3
with:
Expand All @@ -204,8 +206,6 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: 16.x
- name: Bump Node memory limit
run: echo "NODE_OPTIONS=--max_old_space_size=4096" >> $GITHUB_ENV
- run: cp config/ci.config.json config/project.json
- run: yarn
- run: yarn build:${{ matrix.persistence }}
Expand Down
22 changes: 19 additions & 3 deletions .github/workflows/test-changed-firestore-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,24 @@ jobs:
with:
# This makes Actions fetch all Git history so run-changed script can diff properly.
fetch-depth: 0
- uses: 'google-github-actions/auth@v0'
with:
credentials_json: '${{ secrets.JSSDK_ACTIONS_SA_KEY }}'
# create composite indexes with Terraform
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
- name: Terraform Init
run: |
cp config/ci.config.json config/project.json
cd packages/firestore
terraform init
continue-on-error: true
- name: Terraform Apply
if: github.event_name == 'pull_request'
run: |
cd packages/firestore
terraform apply -var-file=../../config/project.json -auto-approve
continue-on-error: true
- name: Set up Node (16)
uses: actions/setup-node@v3
with:
Expand All @@ -24,9 +42,7 @@ jobs:
- name: Bump Node memory limit
run: echo "NODE_OPTIONS=--max_old_space_size=4096" >> $GITHUB_ENV
- name: Test setup and yarn install
run: |
cp config/ci.config.json config/project.json
yarn
run: yarn
- name: build
run: yarn build:changed firestore-integration
- name: Run tests if firestore or its dependencies has changed
Expand Down
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,10 @@ tsdoc-metadata.json
# generated html docs
docs-rut/
docs/
toc/
toc/

# generated Terraform docs
.terraform/*
.terraform.lock.hcl
*.tfstate
*.tfstate.*
27 changes: 23 additions & 4 deletions common/api-review/firestore-lite.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@ export type AddPrefixToKeys<Prefix extends string, T extends Record<string, unkn

// @public
export class AggregateField<T> {
readonly aggregateType: AggregateType;
readonly type = "AggregateField";
}

// @public
export type AggregateFieldType = AggregateField<number | null>;
export function aggregateFieldEqual(left: AggregateField<unknown>, right: AggregateField<unknown>): boolean;

// @public
export type AggregateFieldType = ReturnType<typeof sum> | ReturnType<typeof average> | ReturnType<typeof count>;

// @public
export class AggregateQuerySnapshot<AggregateSpecType extends AggregateSpec, AppModelType = DocumentData, DbModelType extends DocumentData = DocumentData> {
Expand All @@ -46,6 +50,9 @@ export type AggregateSpecData<T extends AggregateSpec> = {
[P in keyof T]: T[P] extends AggregateField<infer U> ? U : never;
};

// @public
export type AggregateType = 'count' | 'avg' | 'sum';

// @public
export function and(...queryConstraints: QueryFilterConstraint[]): QueryCompositeFilterConstraint;

Expand All @@ -55,6 +62,9 @@ export function arrayRemove(...elements: unknown[]): FieldValue;
// @public
export function arrayUnion(...elements: unknown[]): FieldValue;

// @public
export function average(field: string | FieldPath): AggregateField<number | null>;

// @public
export class Bytes {
static fromBase64String(base64: string): Bytes;
Expand Down Expand Up @@ -86,7 +96,7 @@ export class CollectionReference<AppModelType = DocumentData, DbModelType extend
get parent(): DocumentReference<DocumentData, DocumentData> | null;
get path(): string;
readonly type = "collection";
withConverter<NewAppModelType, NewDbModelType extends DocumentData>(converter: FirestoreDataConverter<NewAppModelType, NewDbModelType>): CollectionReference<NewAppModelType, NewDbModelType>;
withConverter<NewAppModelType, NewDbModelType extends DocumentData = DocumentData>(converter: FirestoreDataConverter<NewAppModelType, NewDbModelType>): CollectionReference<NewAppModelType, NewDbModelType>;
withConverter(converter: null): CollectionReference<DocumentData, DocumentData>;
}

Expand All @@ -95,6 +105,9 @@ export function connectFirestoreEmulator(firestore: Firestore, host: string, por
mockUserToken?: EmulatorMockTokenOptions | string;
}): void;

// @public
export function count(): AggregateField<number>;

// @public
export function deleteDoc<AppModelType, DbModelType extends DocumentData>(reference: DocumentReference<AppModelType, DbModelType>): Promise<void>;

Expand Down Expand Up @@ -126,7 +139,7 @@ export class DocumentReference<AppModelType = DocumentData, DbModelType extends
get parent(): CollectionReference<AppModelType, DbModelType>;
get path(): string;
readonly type = "document";
withConverter<NewAppModelType, NewDbModelType extends DocumentData>(converter: FirestoreDataConverter<NewAppModelType, NewDbModelType>): DocumentReference<NewAppModelType, NewDbModelType>;
withConverter<NewAppModelType, NewDbModelType extends DocumentData = DocumentData>(converter: FirestoreDataConverter<NewAppModelType, NewDbModelType>): DocumentReference<NewAppModelType, NewDbModelType>;
withConverter(converter: null): DocumentReference<DocumentData, DocumentData>;
}

Expand Down Expand Up @@ -201,6 +214,9 @@ export class GeoPoint {
};
}

// @public
export function getAggregate<AggregateSpecType extends AggregateSpec, AppModelType, DbModelType extends DocumentData>(query: Query<AppModelType, DbModelType>, aggregateSpec: AggregateSpecType): Promise<AggregateQuerySnapshot<AggregateSpecType, AppModelType, DbModelType>>;

// @public
export function getCount<AppModelType, DbModelType extends DocumentData>(query: Query<AppModelType, DbModelType>): Promise<AggregateQuerySnapshot<{
count: AggregateField<number>;
Expand Down Expand Up @@ -270,7 +286,7 @@ export class Query<AppModelType = DocumentData, DbModelType extends DocumentData
readonly firestore: Firestore;
readonly type: 'query' | 'collection';
withConverter(converter: null): Query<DocumentData, DocumentData>;
withConverter<NewAppModelType, NewDbModelType extends DocumentData>(converter: FirestoreDataConverter<NewAppModelType, NewDbModelType>): Query<NewAppModelType, NewDbModelType>;
withConverter<NewAppModelType, NewDbModelType extends DocumentData = DocumentData>(converter: FirestoreDataConverter<NewAppModelType, NewDbModelType>): Query<NewAppModelType, NewDbModelType>;
}

// @public
Expand Down Expand Up @@ -388,6 +404,9 @@ export function startAt<AppModelType, DbModelType extends DocumentData>(snapshot
// @public
export function startAt(...fieldValues: unknown[]): QueryStartAtConstraint;

// @public
export function sum(field: string | FieldPath): AggregateField<number>;

// @public
export function terminate(firestore: Firestore): Promise<void>;

Expand Down
27 changes: 23 additions & 4 deletions common/api-review/firestore.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@ export type AddPrefixToKeys<Prefix extends string, T extends Record<string, unkn

// @public
export class AggregateField<T> {
readonly aggregateType: AggregateType;
readonly type = "AggregateField";
}

// @public
export type AggregateFieldType = AggregateField<number | null>;
export function aggregateFieldEqual(left: AggregateField<unknown>, right: AggregateField<unknown>): boolean;

// @public
export type AggregateFieldType = ReturnType<typeof sum> | ReturnType<typeof average> | ReturnType<typeof count>;

// @public
export class AggregateQuerySnapshot<AggregateSpecType extends AggregateSpec, AppModelType = DocumentData, DbModelType extends DocumentData = DocumentData> {
Expand All @@ -46,6 +50,9 @@ export type AggregateSpecData<T extends AggregateSpec> = {
[P in keyof T]: T[P] extends AggregateField<infer U> ? U : never;
};

// @public
export type AggregateType = 'count' | 'avg' | 'sum';

// @public
export function and(...queryConstraints: QueryFilterConstraint[]): QueryCompositeFilterConstraint;

Expand All @@ -55,6 +62,9 @@ export function arrayRemove(...elements: unknown[]): FieldValue;
// @public
export function arrayUnion(...elements: unknown[]): FieldValue;

// @public
export function average(field: string | FieldPath): AggregateField<number | null>;

// @public
export class Bytes {
static fromBase64String(base64: string): Bytes;
Expand Down Expand Up @@ -92,7 +102,7 @@ export class CollectionReference<AppModelType = DocumentData, DbModelType extend
get parent(): DocumentReference<DocumentData, DocumentData> | null;
get path(): string;
readonly type = "collection";
withConverter<NewAppModelType, NewDbModelType extends DocumentData>(converter: FirestoreDataConverter<NewAppModelType, NewDbModelType>): CollectionReference<NewAppModelType, NewDbModelType>;
withConverter<NewAppModelType, NewDbModelType extends DocumentData = DocumentData>(converter: FirestoreDataConverter<NewAppModelType, NewDbModelType>): CollectionReference<NewAppModelType, NewDbModelType>;
withConverter(converter: null): CollectionReference<DocumentData, DocumentData>;
}

Expand All @@ -101,6 +111,9 @@ export function connectFirestoreEmulator(firestore: Firestore, host: string, por
mockUserToken?: EmulatorMockTokenOptions | string;
}): void;

// @public
export function count(): AggregateField<number>;

// @public
export function deleteAllPersistentCacheIndexes(indexManager: PersistentCacheIndexManager): void;

Expand Down Expand Up @@ -152,7 +165,7 @@ export class DocumentReference<AppModelType = DocumentData, DbModelType extends
get parent(): CollectionReference<AppModelType, DbModelType>;
get path(): string;
readonly type = "document";
withConverter<NewAppModelType, NewDbModelType extends DocumentData>(converter: FirestoreDataConverter<NewAppModelType, NewDbModelType>): DocumentReference<NewAppModelType, NewDbModelType>;
withConverter<NewAppModelType, NewDbModelType extends DocumentData = DocumentData>(converter: FirestoreDataConverter<NewAppModelType, NewDbModelType>): DocumentReference<NewAppModelType, NewDbModelType>;
withConverter(converter: null): DocumentReference<DocumentData, DocumentData>;
}

Expand Down Expand Up @@ -260,6 +273,9 @@ export class GeoPoint {
};
}

// @public
export function getAggregateFromServer<AggregateSpecType extends AggregateSpec, AppModelType, DbModelType extends DocumentData>(query: Query<AppModelType, DbModelType>, aggregateSpec: AggregateSpecType): Promise<AggregateQuerySnapshot<AggregateSpecType, AppModelType, DbModelType>>;

// @public
export function getCountFromServer<AppModelType, DbModelType extends DocumentData>(query: Query<AppModelType, DbModelType>): Promise<AggregateQuerySnapshot<{
count: AggregateField<number>;
Expand Down Expand Up @@ -525,7 +541,7 @@ export class Query<AppModelType = DocumentData, DbModelType extends DocumentData
readonly firestore: Firestore;
readonly type: 'query' | 'collection';
withConverter(converter: null): Query<DocumentData, DocumentData>;
withConverter<NewAppModelType, NewDbModelType extends DocumentData>(converter: FirestoreDataConverter<NewAppModelType, NewDbModelType>): Query<NewAppModelType, NewDbModelType>;
withConverter<NewAppModelType, NewDbModelType extends DocumentData = DocumentData>(converter: FirestoreDataConverter<NewAppModelType, NewDbModelType>): Query<NewAppModelType, NewDbModelType>;
}

// @public
Expand Down Expand Up @@ -661,6 +677,9 @@ export function startAt<AppModelType, DbModelType extends DocumentData>(snapshot
// @public
export function startAt(...fieldValues: unknown[]): QueryStartAtConstraint;

// @public
export function sum(field: string | FieldPath): AggregateField<number>;

// @public
export type TaskState = 'Error' | 'Running' | 'Success';

Expand Down
Loading

0 comments on commit 6c74255

Please sign in to comment.