Skip to content

Add database-exp #4197

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 10 commits into from
Jan 21, 2021
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
2 changes: 1 addition & 1 deletion .github/workflows/test-changed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ jobs:
cp config/ci.config.json config/project.json
yarn
- name: build
run: yarn build:changed core
run: yarn build:changed core --buildAppExp
- name: Run tests on changed packages
run: xvfb-run yarn test:changed core
10 changes: 9 additions & 1 deletion packages/database/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,13 @@ module.exports = {
'no-restricted-globals': 'off',
'no-throw-literal': 'off',
'id-blacklist': 'off'
}
},
overrides: [
{
files: ['**/*.d.ts'],
rules: {
'@typescript-eslint/no-explicit-any': 'off'
}
}
]
};
17 changes: 17 additions & 0 deletions packages/database/.idea/runConfigurations/All_Tests.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

137 changes: 137 additions & 0 deletions packages/database/exp-types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/**
* @license
* Copyright 2017 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 { FirebaseApp } from '@firebase/app-types';

export { getDatabase } from '../src/exp/Database';

export interface DataSnapshot {
child(path: string): DataSnapshot;
exists(): boolean;
exportVal(): any;
forEach(action: (a: DataSnapshot) => boolean | void): boolean;
getPriority(): string | number | null;
hasChild(path: string): boolean;
hasChildren(): boolean;
key: string | null;
numChildren(): number;
ref: Reference;
toJSON(): object | null;
val(): any;
}

export interface Database {
app: FirebaseApp;
useEmulator(host: string, port: number): void;
goOffline(): void;
goOnline(): void;
ref(path?: string | Reference): Reference;
refFromURL(url: string): Reference;
}

export interface OnDisconnect {
cancel(onComplete?: (a: Error | null) => any): Promise<void>;
remove(onComplete?: (a: Error | null) => any): Promise<void>;
set(value: any, onComplete?: (a: Error | null) => any): Promise<void>;
setWithPriority(
value: any,
priority: number | string | null,
onComplete?: (a: Error | null) => any
): Promise<any>;
update(values: object, onComplete?: (a: Error | null) => any): Promise<any>;
}

type EventType =
| 'value'
| 'child_added'
| 'child_changed'
| 'child_moved'
| 'child_removed';

export interface Query {
endAt(value: number | string | boolean | null, key?: string): Query;
equalTo(value: number | string | boolean | null, key?: string): Query;
isEqual(other: Query | null): boolean;
limitToFirst(limit: number): Query;
limitToLast(limit: number): Query;
off(
eventType?: EventType,
callback?: (a: DataSnapshot, b?: string | null) => any,
context?: object | null
): void;
get(): Promise<DataSnapshot>;
on(
eventType: EventType,
callback: (a: DataSnapshot, b?: string | null) => any,
cancelCallbackOrContext?: ((a: Error) => any) | object | null,
context?: object | null
): (a: DataSnapshot, b?: string | null) => any;
once(
eventType: EventType,
successCallback?: (a: DataSnapshot, b?: string | null) => any,
failureCallbackOrContext?: ((a: Error) => void) | object | null,
context?: object | null
): Promise<DataSnapshot>;
orderByChild(path: string): Query;
orderByKey(): Query;
orderByPriority(): Query;
orderByValue(): Query;
ref: Reference;
startAt(value: number | string | boolean | null, key?: string): Query;
toJSON(): object;
toString(): string;
}

export interface Reference extends Query {
child(path: string): Reference;
key: string | null;
onDisconnect(): OnDisconnect;
parent: Reference | null;
push(value?: any, onComplete?: (a: Error | null) => any): ThenableReference;
remove(onComplete?: (a: Error | null) => any): Promise<any>;
root: Reference;
set(value: any, onComplete?: (a: Error | null) => any): Promise<any>;
setPriority(
priority: string | number | null,
onComplete: (a: Error | null) => any
): Promise<any>;
setWithPriority(
newVal: any,
newPriority: string | number | null,
onComplete?: (a: Error | null) => any
): Promise<any>;
transaction(
transactionUpdate: (a: any) => any,
onComplete?: (a: Error | null, b: boolean, c: DataSnapshot | null) => any,
applyLocally?: boolean
): Promise<any>;
update(values: object, onComplete?: (a: Error | null) => any): Promise<any>;
}

export interface ServerValue {
TIMESTAMP: object;
increment(delta: number): object;
}

export interface ThenableReference
extends Reference,
Pick<Promise<Reference>, 'then' | 'catch'> {}

export function enableLogging(
logger?: boolean | ((a: string) => any),
persistent?: boolean
): any;
58 changes: 58 additions & 0 deletions packages/database/exp/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* @license
* Copyright 2020 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.
*/

// eslint-disable-next-line import/no-extraneous-dependencies
import { _registerComponent, registerVersion } from '@firebase/app-exp';
import { Component, ComponentType } from '@firebase/component';

import { version } from '../package.json';
import { FirebaseDatabase } from '../src/exp/Database';

export {
getDatabase,
FirebaseDatabase,
ServerValue
} from '../src/exp/Database';
export { EventType } from '../src/core/view/Event';
export { DataSnapshot } from '../src/api/DataSnapshot';
export { Query } from '../src/api/Query';
export { Reference } from '../src/api/Reference';
export { OnDisconnect } from '../src/api/onDisconnect';
export { enableLogging } from '../src/core/util/util';

declare module '@firebase/component' {
interface NameServiceMapping {
'database-exp': FirebaseDatabase;
}
}

function registerDatabase(): void {
_registerComponent(
new Component(
'database-exp',
(container, url) => {
const app = container.getProvider('app-exp').getImmediate()!;
const authProvider = container.getProvider('auth-internal');
return new FirebaseDatabase(app, authProvider, url);
},
ComponentType.PUBLIC
).setMultipleInstances(true)
);
registerVersion('database-exp', version, 'node');
}

registerDatabase();
9 changes: 9 additions & 0 deletions packages/database/exp/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "@firebase/database-exp",
"description": "A version of the Realtime Database SDK that is compatible with the tree-shakeable Firebase SDK",
"main": "../dist/exp/index.node.cjs.js",
"browser": "../dist/exp/index.esm.js",
"module": "../dist/exp/index.esm.js",
"esm2017": "../dist/exp/index.esm2017.js",
"typings": "../exp-types/index.d.ts"
}
1 change: 1 addition & 0 deletions packages/database/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// eslint-disable-next-line import/no-extraneous-dependencies
import firebase from '@firebase/app';
import { FirebaseNamespace } from '@firebase/app-types';
Expand Down
4 changes: 3 additions & 1 deletion packages/database/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
"scripts": {
"lint": "eslint -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
"lint:fix": "eslint --fix -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
"build": "rollup -c",
"build": "run-p build:classic build:exp",
"build:classic": "rollup -c rollup.config.js",
"build:exp": "rollup -c rollup.config.exp.js",
"build:deps": "lerna run --scope @firebase/'{app,database}' --include-dependencies build",
"dev": "rollup -c -w",
"test": "run-p lint test:emulator",
Expand Down
96 changes: 96 additions & 0 deletions packages/database/rollup.config.exp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/**
* @license
* Copyright 2018 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 json from '@rollup/plugin-json';
import typescriptPlugin from 'rollup-plugin-typescript2';
import typescript from 'typescript';
import path from 'path';
import { importPathTransformer } from '../../scripts/exp/ts-transform-import-path';

import pkg from './exp/package.json';

const deps = Object.keys(
Object.assign({}, pkg.peerDependencies, pkg.dependencies)
);

/**
* ES5 Builds
*/
const es5BuildPlugins = [
typescriptPlugin({
typescript,
transformers: [importPathTransformer]
}),
json()
];

const es5Builds = [
/**
* Node.js Build
*/
{
input: 'exp/index.ts',
output: [
{ file: path.resolve('exp', pkg.main), format: 'cjs', sourcemap: true }
],
plugins: es5BuildPlugins,
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
},
/**
* Browser Builds
*/
{
input: 'exp/index.ts',
output: [
{ file: path.resolve('exp', pkg.module), format: 'es', sourcemap: true }
],
plugins: es5BuildPlugins,
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
}
];

/**
* ES2017 Builds
*/
const es2017BuildPlugins = [
typescriptPlugin({
typescript,
tsconfigOverride: {
compilerOptions: {
target: 'es2017'
}
},
transformers: [importPathTransformer]
}),
json({ preferConst: true })
];

const es2017Builds = [
/**
* Browser Build
*/
{
input: 'exp/index.ts',
output: [
{ file: path.resolve('exp', pkg.esm2017), format: 'es', sourcemap: true }
],
plugins: es2017BuildPlugins,
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
}
];

export default [...es5Builds, ...es2017Builds];
6 changes: 3 additions & 3 deletions packages/database/src/api/Database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export class Database implements FirebaseService {
}

get app(): FirebaseApp {
return this.repo_.app;
return this.repo_.app as FirebaseApp;
}

/**
Expand Down Expand Up @@ -183,13 +183,13 @@ export class Database implements FirebaseService {
}

// Make individual repo go offline.
goOffline() {
goOffline(): void {
validateArgCount('database.goOffline', 0, 0, arguments.length);
this.checkDeleted_('goOffline');
this.repo_.interrupt();
}

goOnline() {
goOnline(): void {
validateArgCount('database.goOnline', 0, 0, arguments.length);
this.checkDeleted_('goOnline');
this.repo_.resume();
Expand Down
Loading