Skip to content

Add database@exp API #4614

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 6 commits into from
Mar 12, 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
44 changes: 42 additions & 2 deletions packages/database/exp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,48 @@ import { Component, ComponentType } from '@firebase/component';
import { version } from '../package.json';
import { FirebaseDatabase } from '../src/exp/Database';

export { getDatabase, ServerValue } from '../src/exp/Database';
export { enableLogging } from '../src/core/util/util';
export {
enableLogging,
getDatabase,
goOffline,
goOnline,
ref,
refFromURL,
useDatabaseEmulator
} from '../src/exp/Database';
export {
OnDisconnect,
Reference,
ThenableReference
} from '../src/exp/Reference';
export { DataSnapshot } from '../src/exp/DataSnapshot';
export {
ListenOptions,
Query,
QueryConstraint,
Unsubscribe,
endAt,
endBefore,
equalTo,
get,
limitToFirst,
limitToLast,
off,
onChildAdded,
onChildChanged,
onChildMoved,
onChildRemoved,
onValue,
orderByChild,
orderByKey,
orderByPriority,
orderByValue,
query,
startAfter,
startAt
} from '../src/exp/Query';
export { increment, serverTimestamp } from '../src/exp/ServerValue';
export { runTransaction, TransactionOptions } from '../src/exp/Transaction';

declare module '@firebase/component' {
interface NameServiceMapping {
Expand Down
68 changes: 68 additions & 0 deletions packages/database/src/exp/DataSnapshot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
* @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.
*/

import { Reference } from './Reference';

export class DataSnapshot {
private constructor() {}
priority: string | number | null;
size: number;
key: string | null;
ref: Reference;

child(path: string): DataSnapshot {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return {} as any;
}

exists(): boolean {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return {} as any;
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
exportVal(): any {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return {} as any;
}

forEach(action: (child: DataSnapshot) => boolean | void): boolean {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return {} as any;
}

hasChild(path: string): boolean {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return {} as any;
}

hasChildren(): boolean {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return {} as any;
}

toJSON(): object | null {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return {} as any;
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
val(): any {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return {} as any;
}
}
112 changes: 44 additions & 68 deletions packages/database/src/exp/Database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,91 +18,27 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { _FirebaseService, _getProvider, FirebaseApp } from '@firebase/app-exp';
import { Reference } from '../api/Reference';
import { repoManagerDatabaseFromApp } from '../core/RepoManager';
import { FirebaseAuthInternalName } from '@firebase/auth-interop-types';
import { Database } from '../api/Database';
import { Provider } from '@firebase/component';

/**
* Class representing a Firebase Realtime Database.
*/
export class FirebaseDatabase implements _FirebaseService {
static readonly ServerValue = Database.ServerValue;

private _delegate: Database;
readonly 'type' = 'database';

constructor(
readonly app: FirebaseApp,
authProvider: Provider<FirebaseAuthInternalName>,
databaseUrl?: string
) {
this._delegate = repoManagerDatabaseFromApp(
this.app,
authProvider,
databaseUrl,
undefined
);
}

/**
* Modify this instance to communicate with the Realtime Database emulator.
*
* <p>Note: This method must be called before performing any other operation.
*
* @param host - the emulator host (ex: localhost)
* @param port - the emulator port (ex: 8080)
*/
useEmulator(host: string, port: number): void {
this._delegate.useEmulator(host, port);
}

/**
* Returns a reference to the root or to the path specified in the provided
* argument.
*
* @param path - The relative string path or an existing Reference to a
* database location.
* @throws If a Reference is provided, throws if it does not belong to the
* same project.
* @returns Firebase reference.
*/
ref(path?: string): Reference;
ref(path?: Reference): Reference;
ref(path?: string | Reference): Reference {
return typeof path === 'string'
? this._delegate.ref(path)
: this._delegate.ref(path);
}

/**
* Returns a reference to the root or the path specified in url.
* We throw a exception if the url is not in the same domain as the
* current repo.
* @param url - A URL that refers to a database location.
* @returns A Firebase reference.
*/
refFromURL(url: string): Reference {
return this._delegate.refFromURL(url);
}

goOffline(): void {
this._delegate.goOffline();
}

goOnline(): void {
this._delegate.goOnline();
}
) {}

_delete(): Promise<void> {
return this._delegate.INTERNAL.delete();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return {} as any;
}

_setDatabaseUrl(url: string) {}
}

const ServerValue = Database.ServerValue;
export { ServerValue };

/**
* Returns the instance of the Realtime Database SDK that is associated
* with the provided {@link FirebaseApp}. Initializes a new instance with
Expand All @@ -120,3 +56,43 @@ export function getDatabase(app: FirebaseApp, url?: string): FirebaseDatabase {
identifier: url
}) as FirebaseDatabase;
}

export function useDatabaseEmulator(
db: FirebaseDatabase,
host: string,
port: number
): void {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return {} as any;
}

export function goOffline(db: FirebaseDatabase): void {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return {} as any;
}

export function goOnline(db: FirebaseDatabase): void {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return {} as any;
}

export function ref(
db: FirebaseDatabase,
path?: string | Reference
): Reference {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return {} as any;
}

export function refFromURL(db: FirebaseDatabase, url: string): Reference {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return {} as any;
}

export function enableLogging(
logger?: boolean | ((message: string) => unknown),
persistent?: boolean
): void {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return {} as any;
}
Loading