Skip to content

Commit fb90580

Browse files
Add database-exp (#4197)
* Add database-exp * Lint * Fix yarn build * Use instance identifier * lint * Update packages/database/package.json Co-authored-by: Feiyang <[email protected]> * Review * Remove initializeDatabase * Minor build fixes (#4317) * always build app exp because storage and database will need it * transform imports from @firebase/app-exp to @firebase/app Co-authored-by: Feiyang <[email protected]>
1 parent 743e134 commit fb90580

File tree

15 files changed

+559
-12
lines changed

15 files changed

+559
-12
lines changed

.github/workflows/test-changed.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ jobs:
2828
cp config/ci.config.json config/project.json
2929
yarn
3030
- name: build
31-
run: yarn build:changed core
31+
run: yarn build:changed core --buildAppExp
3232
- name: Run tests on changed packages
3333
run: xvfb-run yarn test:changed core

packages/database/.eslintrc.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,13 @@ module.exports = {
3131
'no-restricted-globals': 'off',
3232
'no-throw-literal': 'off',
3333
'id-blacklist': 'off'
34-
}
34+
},
35+
overrides: [
36+
{
37+
files: ['**/*.d.ts'],
38+
rules: {
39+
'@typescript-eslint/no-explicit-any': 'off'
40+
}
41+
}
42+
]
3543
};

packages/database/.idea/runConfigurations/All_Tests.xml

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
/**
2+
* @license
3+
* Copyright 2017 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import { FirebaseApp } from '@firebase/app-types';
19+
20+
export { getDatabase } from '../src/exp/Database';
21+
22+
export interface DataSnapshot {
23+
child(path: string): DataSnapshot;
24+
exists(): boolean;
25+
exportVal(): any;
26+
forEach(action: (a: DataSnapshot) => boolean | void): boolean;
27+
getPriority(): string | number | null;
28+
hasChild(path: string): boolean;
29+
hasChildren(): boolean;
30+
key: string | null;
31+
numChildren(): number;
32+
ref: Reference;
33+
toJSON(): object | null;
34+
val(): any;
35+
}
36+
37+
export interface Database {
38+
app: FirebaseApp;
39+
useEmulator(host: string, port: number): void;
40+
goOffline(): void;
41+
goOnline(): void;
42+
ref(path?: string | Reference): Reference;
43+
refFromURL(url: string): Reference;
44+
}
45+
46+
export interface OnDisconnect {
47+
cancel(onComplete?: (a: Error | null) => any): Promise<void>;
48+
remove(onComplete?: (a: Error | null) => any): Promise<void>;
49+
set(value: any, onComplete?: (a: Error | null) => any): Promise<void>;
50+
setWithPriority(
51+
value: any,
52+
priority: number | string | null,
53+
onComplete?: (a: Error | null) => any
54+
): Promise<any>;
55+
update(values: object, onComplete?: (a: Error | null) => any): Promise<any>;
56+
}
57+
58+
type EventType =
59+
| 'value'
60+
| 'child_added'
61+
| 'child_changed'
62+
| 'child_moved'
63+
| 'child_removed';
64+
65+
export interface Query {
66+
endAt(value: number | string | boolean | null, key?: string): Query;
67+
equalTo(value: number | string | boolean | null, key?: string): Query;
68+
isEqual(other: Query | null): boolean;
69+
limitToFirst(limit: number): Query;
70+
limitToLast(limit: number): Query;
71+
off(
72+
eventType?: EventType,
73+
callback?: (a: DataSnapshot, b?: string | null) => any,
74+
context?: object | null
75+
): void;
76+
get(): Promise<DataSnapshot>;
77+
on(
78+
eventType: EventType,
79+
callback: (a: DataSnapshot, b?: string | null) => any,
80+
cancelCallbackOrContext?: ((a: Error) => any) | object | null,
81+
context?: object | null
82+
): (a: DataSnapshot, b?: string | null) => any;
83+
once(
84+
eventType: EventType,
85+
successCallback?: (a: DataSnapshot, b?: string | null) => any,
86+
failureCallbackOrContext?: ((a: Error) => void) | object | null,
87+
context?: object | null
88+
): Promise<DataSnapshot>;
89+
orderByChild(path: string): Query;
90+
orderByKey(): Query;
91+
orderByPriority(): Query;
92+
orderByValue(): Query;
93+
ref: Reference;
94+
startAt(value: number | string | boolean | null, key?: string): Query;
95+
toJSON(): object;
96+
toString(): string;
97+
}
98+
99+
export interface Reference extends Query {
100+
child(path: string): Reference;
101+
key: string | null;
102+
onDisconnect(): OnDisconnect;
103+
parent: Reference | null;
104+
push(value?: any, onComplete?: (a: Error | null) => any): ThenableReference;
105+
remove(onComplete?: (a: Error | null) => any): Promise<any>;
106+
root: Reference;
107+
set(value: any, onComplete?: (a: Error | null) => any): Promise<any>;
108+
setPriority(
109+
priority: string | number | null,
110+
onComplete: (a: Error | null) => any
111+
): Promise<any>;
112+
setWithPriority(
113+
newVal: any,
114+
newPriority: string | number | null,
115+
onComplete?: (a: Error | null) => any
116+
): Promise<any>;
117+
transaction(
118+
transactionUpdate: (a: any) => any,
119+
onComplete?: (a: Error | null, b: boolean, c: DataSnapshot | null) => any,
120+
applyLocally?: boolean
121+
): Promise<any>;
122+
update(values: object, onComplete?: (a: Error | null) => any): Promise<any>;
123+
}
124+
125+
export interface ServerValue {
126+
TIMESTAMP: object;
127+
increment(delta: number): object;
128+
}
129+
130+
export interface ThenableReference
131+
extends Reference,
132+
Pick<Promise<Reference>, 'then' | 'catch'> {}
133+
134+
export function enableLogging(
135+
logger?: boolean | ((a: string) => any),
136+
persistent?: boolean
137+
): any;

packages/database/exp/index.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/**
2+
* @license
3+
* Copyright 2020 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
// eslint-disable-next-line import/no-extraneous-dependencies
19+
import { _registerComponent, registerVersion } from '@firebase/app-exp';
20+
import { Component, ComponentType } from '@firebase/component';
21+
22+
import { version } from '../package.json';
23+
import { FirebaseDatabase } from '../src/exp/Database';
24+
25+
export {
26+
getDatabase,
27+
FirebaseDatabase,
28+
ServerValue
29+
} from '../src/exp/Database';
30+
export { EventType } from '../src/core/view/Event';
31+
export { DataSnapshot } from '../src/api/DataSnapshot';
32+
export { Query } from '../src/api/Query';
33+
export { Reference } from '../src/api/Reference';
34+
export { OnDisconnect } from '../src/api/onDisconnect';
35+
export { enableLogging } from '../src/core/util/util';
36+
37+
declare module '@firebase/component' {
38+
interface NameServiceMapping {
39+
'database-exp': FirebaseDatabase;
40+
}
41+
}
42+
43+
function registerDatabase(): void {
44+
_registerComponent(
45+
new Component(
46+
'database-exp',
47+
(container, url) => {
48+
const app = container.getProvider('app-exp').getImmediate()!;
49+
const authProvider = container.getProvider('auth-internal');
50+
return new FirebaseDatabase(app, authProvider, url);
51+
},
52+
ComponentType.PUBLIC
53+
).setMultipleInstances(true)
54+
);
55+
registerVersion('database-exp', version, 'node');
56+
}
57+
58+
registerDatabase();

packages/database/exp/package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "@firebase/database-exp",
3+
"description": "A version of the Realtime Database SDK that is compatible with the tree-shakeable Firebase SDK",
4+
"main": "../dist/exp/index.node.cjs.js",
5+
"browser": "../dist/exp/index.esm.js",
6+
"module": "../dist/exp/index.esm.js",
7+
"esm2017": "../dist/exp/index.esm2017.js",
8+
"typings": "../exp-types/index.d.ts"
9+
}

packages/database/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17+
1718
// eslint-disable-next-line import/no-extraneous-dependencies
1819
import firebase from '@firebase/app';
1920
import { FirebaseNamespace } from '@firebase/app-types';

packages/database/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
"scripts": {
1414
"lint": "eslint -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
1515
"lint:fix": "eslint --fix -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
16-
"build": "rollup -c",
16+
"build": "run-p build:classic build:exp",
17+
"build:classic": "rollup -c rollup.config.js",
18+
"build:exp": "rollup -c rollup.config.exp.js",
1719
"build:deps": "lerna run --scope @firebase/'{app,database}' --include-dependencies build",
1820
"dev": "rollup -c -w",
1921
"test": "run-p lint test:emulator",
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/**
2+
* @license
3+
* Copyright 2018 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import json from '@rollup/plugin-json';
19+
import typescriptPlugin from 'rollup-plugin-typescript2';
20+
import typescript from 'typescript';
21+
import path from 'path';
22+
import { importPathTransformer } from '../../scripts/exp/ts-transform-import-path';
23+
24+
import pkg from './exp/package.json';
25+
26+
const deps = Object.keys(
27+
Object.assign({}, pkg.peerDependencies, pkg.dependencies)
28+
);
29+
30+
/**
31+
* ES5 Builds
32+
*/
33+
const es5BuildPlugins = [
34+
typescriptPlugin({
35+
typescript,
36+
transformers: [importPathTransformer]
37+
}),
38+
json()
39+
];
40+
41+
const es5Builds = [
42+
/**
43+
* Node.js Build
44+
*/
45+
{
46+
input: 'exp/index.ts',
47+
output: [
48+
{ file: path.resolve('exp', pkg.main), format: 'cjs', sourcemap: true }
49+
],
50+
plugins: es5BuildPlugins,
51+
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
52+
},
53+
/**
54+
* Browser Builds
55+
*/
56+
{
57+
input: 'exp/index.ts',
58+
output: [
59+
{ file: path.resolve('exp', pkg.module), format: 'es', sourcemap: true }
60+
],
61+
plugins: es5BuildPlugins,
62+
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
63+
}
64+
];
65+
66+
/**
67+
* ES2017 Builds
68+
*/
69+
const es2017BuildPlugins = [
70+
typescriptPlugin({
71+
typescript,
72+
tsconfigOverride: {
73+
compilerOptions: {
74+
target: 'es2017'
75+
}
76+
},
77+
transformers: [importPathTransformer]
78+
}),
79+
json({ preferConst: true })
80+
];
81+
82+
const es2017Builds = [
83+
/**
84+
* Browser Build
85+
*/
86+
{
87+
input: 'exp/index.ts',
88+
output: [
89+
{ file: path.resolve('exp', pkg.esm2017), format: 'es', sourcemap: true }
90+
],
91+
plugins: es2017BuildPlugins,
92+
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
93+
}
94+
];
95+
96+
export default [...es5Builds, ...es2017Builds];

packages/database/src/api/Database.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export class Database implements FirebaseService {
8888
}
8989

9090
get app(): FirebaseApp {
91-
return this.repo_.app;
91+
return this.repo_.app as FirebaseApp;
9292
}
9393

9494
/**
@@ -183,13 +183,13 @@ export class Database implements FirebaseService {
183183
}
184184

185185
// Make individual repo go offline.
186-
goOffline() {
186+
goOffline(): void {
187187
validateArgCount('database.goOffline', 0, 0, arguments.length);
188188
this.checkDeleted_('goOffline');
189189
this.repo_.interrupt();
190190
}
191191

192-
goOnline() {
192+
goOnline(): void {
193193
validateArgCount('database.goOnline', 0, 0, arguments.length);
194194
this.checkDeleted_('goOnline');
195195
this.repo_.resume();

0 commit comments

Comments
 (0)