-
Notifications
You must be signed in to change notification settings - Fork 948
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
Add database-exp #4197
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
48adfd9
Add database-exp
schmidt-sebastian 7c0a165
Lint
schmidt-sebastian 863734d
Fix yarn build
schmidt-sebastian e6e3201
Use instance identifier
schmidt-sebastian 34a75e0
lint
schmidt-sebastian 467ce9d
Update packages/database/package.json
schmidt-sebastian 9132776
Review
schmidt-sebastian 0c9b7be
Merge branch 'mrschmidt/database-exp' of github.com:firebase/firebase…
schmidt-sebastian 3e63d39
Remove initializeDatabase
schmidt-sebastian 03aee06
Minor build fixes (#4317)
Feiyang1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
/** | ||
* @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 { initializeDatabase, 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 class FirebaseDatabase implements Database { | ||
private constructor(); | ||
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/** | ||
* @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, | ||
initializeDatabase, | ||
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()!; | ||
return ((app, auth) => new FirebaseDatabase(app, auth, url))( | ||
app, | ||
container.getProvider('auth-internal') | ||
); | ||
Feiyang1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
ComponentType.PUBLIC | ||
).setMultipleInstances(true) | ||
); | ||
registerVersion('database-exp', version, 'node'); | ||
} | ||
|
||
registerDatabase(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/** | ||
* @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 pkg from './exp/package.json'; | ||
|
||
const deps = Object.keys( | ||
Object.assign({}, pkg.peerDependencies, pkg.dependencies) | ||
); | ||
|
||
/** | ||
* ES5 Builds | ||
*/ | ||
const es5BuildPlugins = [ | ||
typescriptPlugin({ | ||
typescript | ||
}), | ||
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' | ||
} | ||
} | ||
}), | ||
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]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.