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 committed Aug 4, 2022
2 parents 7272e7b + 1076551 commit 091e573
Show file tree
Hide file tree
Showing 56 changed files with 1,397 additions and 633 deletions.
5 changes: 5 additions & 0 deletions .changeset/calm-pugs-leave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@firebase/app': patch
---

Prevent core app from throwing if IndexedDB heartbeat functions throw.
5 changes: 5 additions & 0 deletions .changeset/five-yaks-travel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@firebase/firestore': patch
---

Add internal implementation of setIndexConfiguration
5 changes: 5 additions & 0 deletions .changeset/honest-waves-brake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@firebase/firestore': patch
---

Expose client side indexing feature with `setIndexConfiguration`.
7 changes: 7 additions & 0 deletions .changeset/kind-pots-admire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@firebase/database': patch
'@firebase/database-compat': patch
'@firebase/database-types': patch
---

Updated type of action parameter for DataSnapshot#forEach
5 changes: 4 additions & 1 deletion .github/workflows/check-changeset.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: Check Changeset

on: pull_request
on:
pull_request:
branches-ignore:
- release

env:
GITHUB_PULL_REQUEST_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
Expand Down
11 changes: 9 additions & 2 deletions .github/workflows/release-prod.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
name: Production Release

on: workflow_dispatch
on:
workflow_dispatch:
inputs:
release-branch:
description: 'Release branch'
type: string
default: 'release'
required: true

jobs:
deploy:
Expand All @@ -20,7 +27,7 @@ jobs:
with:
# Release script requires git history and tags.
fetch-depth: 0
ref: release
ref: ${{ github.event.inputs.release-branch }}
token: ${{ secrets.OSS_BOT_GITHUB_TOKEN }}
- name: Yarn install
run: yarn
Expand Down
80 changes: 55 additions & 25 deletions .github/workflows/test-changed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,61 @@ name: Test Modified Packages
on: pull_request

jobs:
test:
name: Test Packages With Changed Files
test-chrome:
name: Test Packages With Changed Files in Chrome and Node
runs-on: ubuntu-latest

steps:
- name: Checkout Repo
uses: actions/checkout@master
with:
# This makes Actions fetch all Git history so run-changed script can diff properly.
fetch-depth: 0
- name: Set up Node (14)
uses: actions/setup-node@v2
with:
node-version: 14.x
- name: install Chrome stable
run: |
sudo apt-get update
sudo apt-get install google-chrome-stable
- 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
- name: build
run: yarn build:changed core
- name: Run tests on changed packages
run: xvfb-run yarn test:changed core
- name: Checkout Repo
uses: actions/checkout@master
with:
# This makes Actions fetch all Git history so run-changed script can diff properly.
fetch-depth: 0
- name: Set up Node (14)
uses: actions/setup-node@v2
with:
node-version: 14.x
- name: install Chrome stable
run: |
sudo apt-get update
sudo apt-get install google-chrome-stable
- 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
- name: build
run: yarn build:changed core
- name: Run tests on changed packages
run: xvfb-run yarn test:changed core

test-firefox:
name: Test Packages With Changed Files in Firefox
runs-on: ubuntu-latest

steps:
- name: Checkout Repo
uses: actions/checkout@master
with:
fetch-depth: 0
- name: Set up Node (14)
uses: actions/setup-node@v2
with:
node-version: 14.x
- name: install Firefox stable
run: |
sudo apt-get update
sudo apt-get install firefox
- 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
- name: build
run: yarn build:changed core
- name: Run tests on changed packages
run: xvfb-run yarn test:changed core
env:
BROWSERS: 'Firefox'
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,5 @@ tsdoc-metadata.json

# generated html docs
docs-*/
docs/
docs/
toc/
4 changes: 3 additions & 1 deletion common/api-review/database.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ export class DataSnapshot {
child(path: string): DataSnapshot;
exists(): boolean;
exportVal(): any;
forEach(action: (child: DataSnapshot) => boolean | void): boolean;
forEach(action: (child: DataSnapshot & {
key: string;
}) => boolean | void): boolean;
hasChild(path: string): boolean;
hasChildren(): boolean;
get key(): string | null;
Expand Down
30 changes: 30 additions & 0 deletions common/api-review/firestore.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,30 @@ export function getFirestore(app?: FirebaseApp): Firestore;
// @public
export function increment(n: number): FieldValue;

// @public
export interface Index {
// (undocumented)
[key: string]: unknown;
readonly collectionGroup: string;
readonly fields?: IndexField[];
}

// @public
export interface IndexConfiguration {
// (undocumented)
[key: string]: unknown;
readonly indexes?: Index[];
}

// @public
export interface IndexField {
// (undocumented)
[key: string]: unknown;
readonly arrayConfig?: 'CONTAINS';
readonly fieldPath: string;
readonly order?: 'ASCENDING' | 'DESCENDING';
}

// @public
export function initializeFirestore(app: FirebaseApp, settings: FirestoreSettings): Firestore;

Expand Down Expand Up @@ -396,6 +420,12 @@ export function setDoc<T>(reference: DocumentReference<T>, data: WithFieldValue<
// @public
export function setDoc<T>(reference: DocumentReference<T>, data: PartialWithFieldValue<T>, options: SetOptions): Promise<void>;

// @public
export function setIndexConfiguration(firestore: Firestore, configuration: IndexConfiguration): Promise<void>;

// @public
export function setIndexConfiguration(firestore: Firestore, json: string): Promise<void>;

// @public
export function setLogLevel(logLevel: LogLevel): void;

Expand Down
2 changes: 1 addition & 1 deletion config/karma.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const config = {
// start these browsers
// available browser launchers:
// https://npmjs.org/browse/keyword/karma-launcher
browsers: ['ChromeHeadless'],
browsers: process.env?.BROWSERS?.split(',') ?? ['ChromeHeadless'],

webpack: webpackTestConfig,

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
"sinon": "9.2.4",
"sinon-chai": "3.7.0",
"source-map-loader": "1.1.3",
"terser": "5.13.1",
"terser": "5.14.2",
"ts-loader": "8.4.0",
"ts-node": "10.7.0",
"tslint": "6.1.3",
Expand Down
32 changes: 16 additions & 16 deletions packages/app/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ export const enum AppError {
APP_DELETED = 'app-deleted',
INVALID_APP_ARGUMENT = 'invalid-app-argument',
INVALID_LOG_ARGUMENT = 'invalid-log-argument',
STORAGE_OPEN = 'storage-open',
STORAGE_GET = 'storage-get',
STORAGE_WRITE = 'storage-set',
STORAGE_DELETE = 'storage-delete'
IDB_OPEN = 'idb-open',
IDB_GET = 'idb-get',
IDB_WRITE = 'idb-set',
IDB_DELETE = 'idb-delete'
}

const ERRORS: ErrorMap<AppError> = {
Expand All @@ -43,14 +43,14 @@ const ERRORS: ErrorMap<AppError> = {
'Firebase App instance.',
[AppError.INVALID_LOG_ARGUMENT]:
'First argument to `onLog` must be null or a function.',
[AppError.STORAGE_OPEN]:
'Error thrown when opening storage. Original error: {$originalErrorMessage}.',
[AppError.STORAGE_GET]:
'Error thrown when reading from storage. Original error: {$originalErrorMessage}.',
[AppError.STORAGE_WRITE]:
'Error thrown when writing to storage. Original error: {$originalErrorMessage}.',
[AppError.STORAGE_DELETE]:
'Error thrown when deleting from storage. Original error: {$originalErrorMessage}.'
[AppError.IDB_OPEN]:
'Error thrown when opening IndexedDB. Original error: {$originalErrorMessage}.',
[AppError.IDB_GET]:
'Error thrown when reading from IndexedDB. Original error: {$originalErrorMessage}.',
[AppError.IDB_WRITE]:
'Error thrown when writing to IndexedDB. Original error: {$originalErrorMessage}.',
[AppError.IDB_DELETE]:
'Error thrown when deleting from IndexedDB. Original error: {$originalErrorMessage}.'
};

interface ErrorParams {
Expand All @@ -59,10 +59,10 @@ interface ErrorParams {
[AppError.DUPLICATE_APP]: { appName: string };
[AppError.APP_DELETED]: { appName: string };
[AppError.INVALID_APP_ARGUMENT]: { appName: string };
[AppError.STORAGE_OPEN]: { originalErrorMessage?: string };
[AppError.STORAGE_GET]: { originalErrorMessage?: string };
[AppError.STORAGE_WRITE]: { originalErrorMessage?: string };
[AppError.STORAGE_DELETE]: { originalErrorMessage?: string };
[AppError.IDB_OPEN]: { originalErrorMessage?: string };
[AppError.IDB_GET]: { originalErrorMessage?: string };
[AppError.IDB_WRITE]: { originalErrorMessage?: string };
[AppError.IDB_DELETE]: { originalErrorMessage?: string };
}

export const ERROR_FACTORY = new ErrorFactory<AppError, ErrorParams>(
Expand Down
77 changes: 77 additions & 0 deletions packages/app/src/indexeddb.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/**
* @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 { expect } from 'chai';
import '../test/setup';
import { match, stub } from 'sinon';
import {
readHeartbeatsFromIndexedDB,
writeHeartbeatsToIndexedDB
} from './indexeddb';
import { FirebaseApp } from './public-types';
import { AppError } from './errors';
import { HeartbeatsInIndexedDB } from './types';

/**
* Mostly testing failure cases. heartbeatService.test.ts tests read-write
* more extensively.
*/

describe('IndexedDB functions', () => {
it('readHeartbeatsFromIndexedDB warns if IndexedDB.open() throws', async () => {
const warnStub = stub(console, 'warn');
if (typeof window !== 'undefined') {
// Ensure that indexedDB.open() fails in browser. It will always fail in Node.
stub(window.indexedDB, 'open').throws(new Error('abcd'));
await readHeartbeatsFromIndexedDB({
name: 'testname',
options: { appId: 'test-app-id' }
} as FirebaseApp);
expect(warnStub).to.be.calledWith(match.any, match(AppError.IDB_GET));
} else {
await readHeartbeatsFromIndexedDB({
name: 'testname',
options: { appId: 'test-app-id' }
} as FirebaseApp);
expect(warnStub).to.be.calledWith(match.any, match(AppError.IDB_GET));
}
});
it('writeHeartbeatsToIndexedDB warns if IndexedDB.open() throws', async () => {
const warnStub = stub(console, 'warn');
if (typeof window !== 'undefined') {
// Ensure that indexedDB.open() fails in browser. It will always fail in Node.
stub(window.indexedDB, 'open').throws(new Error('abcd'));
await writeHeartbeatsToIndexedDB(
{
name: 'testname',
options: { appId: 'test-app-id' }
} as FirebaseApp,
{} as HeartbeatsInIndexedDB
);
expect(warnStub).to.be.calledWith(match.any, match(AppError.IDB_WRITE));
} else {
await writeHeartbeatsToIndexedDB(
{
name: 'testname',
options: { appId: 'test-app-id' }
} as FirebaseApp,
{} as HeartbeatsInIndexedDB
);
expect(warnStub).to.be.calledWith(match.any, match(AppError.IDB_WRITE));
}
});
});
Loading

0 comments on commit 091e573

Please sign in to comment.