From 2b6a70c9b2624cdb069336ecbcc08073d82db1ce Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Wed, 10 Mar 2021 15:31:53 -0700 Subject: [PATCH 1/6] Add database@exp API --- packages/database/src/exp/DataSnapshot.ts | 66 +++++ packages/database/src/exp/Database.ts | 110 +++----- packages/database/src/exp/Query.ts | 315 ++++++++++++++++++++++ packages/database/src/exp/Reference.ts | 90 +++++++ packages/database/src/exp/ServerValue.ts | 26 ++ packages/database/src/exp/Transaction.ts | 31 +++ 6 files changed, 572 insertions(+), 66 deletions(-) create mode 100644 packages/database/src/exp/DataSnapshot.ts create mode 100644 packages/database/src/exp/Query.ts create mode 100644 packages/database/src/exp/Reference.ts create mode 100644 packages/database/src/exp/ServerValue.ts create mode 100644 packages/database/src/exp/Transaction.ts diff --git a/packages/database/src/exp/DataSnapshot.ts b/packages/database/src/exp/DataSnapshot.ts new file mode 100644 index 00000000000..82c587b876a --- /dev/null +++ b/packages/database/src/exp/DataSnapshot.ts @@ -0,0 +1,66 @@ +/** + * @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; + } + + 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; + } + + val(): any { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return {} as any; + } +} diff --git a/packages/database/src/exp/Database.ts b/packages/database/src/exp/Database.ts index 25bc3ae3693..76102db279e 100644 --- a/packages/database/src/exp/Database.ts +++ b/packages/database/src/exp/Database.ts @@ -27,82 +27,20 @@ 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, databaseUrl?: string - ) { - this._delegate = repoManagerDatabaseFromApp( - this.app, - authProvider, - databaseUrl, - undefined - ); - } - - /** - * Modify this instance to communicate with the Realtime Database emulator. - * - *

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 { - 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 @@ -120,3 +58,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; +} diff --git a/packages/database/src/exp/Query.ts b/packages/database/src/exp/Query.ts new file mode 100644 index 00000000000..57f23d5350b --- /dev/null +++ b/packages/database/src/exp/Query.ts @@ -0,0 +1,315 @@ +/** + * @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'; +import { DataSnapshot } from './DataSnapshot'; + +export class Query { + protected constructor() {} + ref: Reference; + + isEqual(other: Query | null): boolean { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return {} as any; + } + + toJSON(): object { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return {} as any; + } + + toString(): string { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return {} as any; + } +} + +export function get(query: Query): Promise { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return {} as any; +} + +export type Unsubscribe = () => {}; +export interface ListenOptions { + readonly onlyOnce?: boolean; +} + +export function onValue( + query: Query, + callback: (snapshot: DataSnapshot) => unknown, + cancelCallback?: (error: Error) => unknown +): Unsubscribe; +export function onValue( + query: Query, + callback: (snapshot: DataSnapshot) => unknown, + options: ListenOptions +): Unsubscribe; +export function onValue( + query: Query, + callback: (snapshot: DataSnapshot) => unknown, + cancelCallback: (error: Error) => unknown, + options: ListenOptions +): Unsubscribe; +export function onValue( + query: Query, + callback: (snapshot: DataSnapshot) => unknown, + cancelCallbackOrListenOptions?: ((error: Error) => unknown) | ListenOptions, + options?: ListenOptions +): Unsubscribe { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return {} as any; +} + +export function onChildAdded( + query: Query, + callback: ( + snapshot: DataSnapshot, + previousChildName?: string | null + ) => unknown, + cancelCallback?: (error: Error) => unknown +): Unsubscribe; +export function onChildAdded( + query: Query, + callback: ( + snapshot: DataSnapshot, + previousChildName: string | null + ) => unknown, + options: ListenOptions +): Unsubscribe; +export function onChildAdded( + query: Query, + callback: ( + snapshot: DataSnapshot, + previousChildName: string | null + ) => unknown, + cancelCallback: (error: Error) => unknown, + options: ListenOptions +): Unsubscribe; +export function onChildAdded( + query: Query, + callback: ( + snapshot: DataSnapshot, + previousChildName: string | null + ) => unknown, + cancelCallbackOrListenOptions?: ((error: Error) => unknown) | ListenOptions, + options?: ListenOptions +): Unsubscribe { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return {} as any; +} + +export function onChildChanged( + query: Query, + callback: ( + snapshot: DataSnapshot, + previousChildName: string | null + ) => unknown, + cancelCallback?: (error: Error) => unknown +): Unsubscribe; +export function onChildChanged( + query: Query, + callback: ( + snapshot: DataSnapshot, + previousChildName: string | null + ) => unknown, + options: ListenOptions +): Unsubscribe; +export function onChildChanged( + query: Query, + callback: ( + snapshot: DataSnapshot, + previousChildName: string | null + ) => unknown, + cancelCallback: (error: Error) => unknown, + options: ListenOptions +): Unsubscribe; +export function onChildChanged( + query: Query, + callback: ( + snapshot: DataSnapshot, + previousChildName: string | null + ) => unknown, + cancelCallbackOrListenOptions?: ((error: Error) => unknown) | ListenOptions, + options?: ListenOptions +): Unsubscribe { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return {} as any; +} + +export function onChildMoved( + query: Query, + callback: ( + snapshot: DataSnapshot, + previousChildName: string | null + ) => unknown, + cancelCallback?: (error: Error) => unknown +): Unsubscribe; +export function onChildMoved( + query: Query, + callback: ( + snapshot: DataSnapshot, + previousChildName: string | null + ) => unknown, + options: ListenOptions +): Unsubscribe; +export function onChildMoved( + query: Query, + callback: ( + snapshot: DataSnapshot, + previousChildName: string | null + ) => unknown, + cancelCallback: (error: Error) => unknown, + options: ListenOptions +): Unsubscribe; +export function onChildMoved( + query: Query, + callback: ( + snapshot: DataSnapshot, + previousChildName: string | null + ) => unknown, + cancelCallbackOrListenOptions?: ((error: Error) => unknown) | ListenOptions, + options?: ListenOptions +): Unsubscribe { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return {} as any; +} + +export function onChildRemoved( + query: Query, + callback: (snapshot: DataSnapshot) => unknown, + cancelCallback?: (error: Error) => unknown +): Unsubscribe; +export function onChildRemoved( + query: Query, + callback: (snapshot: DataSnapshot) => unknown, + options: ListenOptions +): Unsubscribe; +export function onChildRemoved( + query: Query, + callback: (snapshot: DataSnapshot) => unknown, + cancelCallback: (error: Error) => unknown, + options: ListenOptions +): Unsubscribe; +export function onChildRemoved( + query: Query, + callback: (snapshot: DataSnapshot) => unknown, + cancelCallbackOrListenOptions?: ((error: Error) => unknown) | ListenOptions, + options?: ListenOptions +): Unsubscribe { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return {} as any; +} + +export function off( + query: Query, + callback?: ( + snapshot: DataSnapshot, + previousChildName?: string | null + ) => unknown +): void { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return {} as any; +} + +export interface QueryConstraint { + type: + | 'endAt' + | 'endBefore' + | 'startAt' + | 'startAfter' + | 'limitToFirst' + | 'limitToLast' + | 'orderByChild' + | 'orderByKey' + | 'orderByPriority' + | 'orderByValue' + | 'equalTo'; +} +export function endAt( + value: number | string | boolean | null, + key?: string +): QueryConstraint { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return {} as any; +} + +export function endBefore( + value: number | string | boolean | null, + key?: string +): QueryConstraint { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return {} as any; +} + +export function startAt( + value: number | string | boolean | null, + key?: string +): QueryConstraint { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return {} as any; +} + +export function startAfter( + value: number | string | boolean | null, + key?: string +): QueryConstraint { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return {} as any; +} + +export function limitToFirst(limit: number): QueryConstraint { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return {} as any; +} + +export function limitToLast(limit: number): QueryConstraint { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return {} as any; +} + +export function orderByChild(path: string): QueryConstraint { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return {} as any; +} + +export function orderByKey(): QueryConstraint { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return {} as any; +} + +export function orderByPriority(): QueryConstraint { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return {} as any; +} + +export function orderByValue(): QueryConstraint { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return {} as any; +} + +export function equalTo( + value: number | string | boolean | null, + key?: string +): QueryConstraint { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return {} as any; +} + +export function query(query: Query, ...constraints: QueryConstraint[]): Query { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return {} as any; +} diff --git a/packages/database/src/exp/Reference.ts b/packages/database/src/exp/Reference.ts new file mode 100644 index 00000000000..00e85ab53cf --- /dev/null +++ b/packages/database/src/exp/Reference.ts @@ -0,0 +1,90 @@ +/** + * @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 { Query } from './Query'; + +export class Reference extends Query { + private constructor() { + super(); + } + + key: string | null; + parent: Reference | null; + root: Reference; +} + +export interface OnDisconnect { + cancel(): Promise; + remove(): Promise; + set(value: unknown): Promise; + setWithPriority( + value: unknown, + priority: number | string | null + ): Promise; + update(values: object): Promise; +} + +export interface ThenableReference + extends Reference, + Pick, 'then' | 'catch'> {} + +export function child(ref: Reference, path: string): Reference { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return {} as any; +} + +export function onDisconnect(ref: Reference): OnDisconnect { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return {} as any; +} + +export function push(ref: Reference, value?: unknown): ThenableReference { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return {} as any; +} + +export function remove(ref: Reference): Promise { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return {} as any; +} + +export function set(ref: Reference, value: unknown): Promise { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return {} as any; +} + +export function setPriority( + ref: Reference, + priority: string | number | null +): Promise { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return {} as any; +} + +export function setWithPriority( + ref: Reference, + newVal: unknown, + newPriority: string | number | null +): Promise { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return {} as any; +} + +export function update(ref: Reference, values: object): Promise { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return {} as any; +} diff --git a/packages/database/src/exp/ServerValue.ts b/packages/database/src/exp/ServerValue.ts new file mode 100644 index 00000000000..fff9f29b52f --- /dev/null +++ b/packages/database/src/exp/ServerValue.ts @@ -0,0 +1,26 @@ +/** + * @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. + */ + +export function serverTimestamp(): object { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return {} as any; +} + +export function increment(delta: number): object { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return {} as any; +} diff --git a/packages/database/src/exp/Transaction.ts b/packages/database/src/exp/Transaction.ts new file mode 100644 index 00000000000..03aa713178e --- /dev/null +++ b/packages/database/src/exp/Transaction.ts @@ -0,0 +1,31 @@ +/** + * @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 interface TransactionOptions { + readonly applyLocally?: boolean; +} + +export function runTransaction( + ref: Reference, + transactionUpdate: (currentData: any) => unknown, + options?: TransactionOptions +): Promise { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return {} as any; +} From 5ed4633d77839cdf985470595b170afd1057f6c3 Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Wed, 10 Mar 2021 15:36:44 -0700 Subject: [PATCH 2/6] Lint --- packages/database/src/exp/DataSnapshot.ts | 2 ++ packages/database/src/exp/Database.ts | 2 -- packages/database/src/exp/Reference.ts | 2 +- packages/database/src/exp/Transaction.ts | 1 + 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/database/src/exp/DataSnapshot.ts b/packages/database/src/exp/DataSnapshot.ts index 82c587b876a..b2a3ea9dd60 100644 --- a/packages/database/src/exp/DataSnapshot.ts +++ b/packages/database/src/exp/DataSnapshot.ts @@ -34,6 +34,7 @@ export class DataSnapshot { 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; @@ -59,6 +60,7 @@ export class DataSnapshot { 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; diff --git a/packages/database/src/exp/Database.ts b/packages/database/src/exp/Database.ts index 76102db279e..8ad71116a18 100644 --- a/packages/database/src/exp/Database.ts +++ b/packages/database/src/exp/Database.ts @@ -18,9 +18,7 @@ // 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'; /** diff --git a/packages/database/src/exp/Reference.ts b/packages/database/src/exp/Reference.ts index 00e85ab53cf..278e0cce361 100644 --- a/packages/database/src/exp/Reference.ts +++ b/packages/database/src/exp/Reference.ts @@ -34,7 +34,7 @@ export interface OnDisconnect { setWithPriority( value: unknown, priority: number | string | null - ): Promise; + ): Promise; update(values: object): Promise; } diff --git a/packages/database/src/exp/Transaction.ts b/packages/database/src/exp/Transaction.ts index 03aa713178e..a848c3eb173 100644 --- a/packages/database/src/exp/Transaction.ts +++ b/packages/database/src/exp/Transaction.ts @@ -23,6 +23,7 @@ export interface TransactionOptions { export function runTransaction( ref: Reference, + // eslint-disable-next-line @typescript-eslint/no-explicit-any transactionUpdate: (currentData: any) => unknown, options?: TransactionOptions ): Promise { From b099eb9a5b02f28f9bc566b553ec762db881fa59 Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Wed, 10 Mar 2021 16:33:22 -0700 Subject: [PATCH 3/6] Exports --- packages/database/exp/index.ts | 44 ++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/packages/database/exp/index.ts b/packages/database/exp/index.ts index 49084283906..690033b027c 100644 --- a/packages/database/exp/index.ts +++ b/packages/database/exp/index.ts @@ -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 { + getDatabase, + ref, + enableLogging, + goOffline, + refFromURL, + goOnline, + useDatabaseEmulator +} from '../src/exp/Database'; +export { + Reference, + ThenableReference, + OnDisconnect +} from '../src/exp/Reference'; +export { DataSnapshot } from '../src/exp/DataSnapshot'; +export { + Query, + query, + ListenOptions, + QueryConstraint, + endAt, + endBefore, + startAt, + startAfter, + limitToLast, + Unsubscribe, + equalTo, + get, + limitToFirst, + off, + onChildAdded, + onChildChanged, + onChildMoved, + onChildRemoved, + onValue, + orderByChild, + orderByKey, + orderByPriority, + orderByValue +} from '../src/exp/Query'; +export { serverTimestamp, increment } from '../src/exp/ServerValue'; +export { TransactionOptions, runTransaction } from '../src/exp/Transaction'; declare module '@firebase/component' { interface NameServiceMapping { From 6c55d8a27656d785141cf9e3ee83a710ea45233c Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Wed, 10 Mar 2021 16:34:42 -0700 Subject: [PATCH 4/6] Sort exports --- packages/database/exp/index.ts | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/packages/database/exp/index.ts b/packages/database/exp/index.ts index 690033b027c..d7dd48db5d0 100644 --- a/packages/database/exp/index.ts +++ b/packages/database/exp/index.ts @@ -23,34 +23,31 @@ import { version } from '../package.json'; import { FirebaseDatabase } from '../src/exp/Database'; export { - getDatabase, - ref, enableLogging, + getDatabase, goOffline, - refFromURL, goOnline, + ref, + refFromURL, useDatabaseEmulator } from '../src/exp/Database'; export { + OnDisconnect, Reference, - ThenableReference, - OnDisconnect + ThenableReference } from '../src/exp/Reference'; export { DataSnapshot } from '../src/exp/DataSnapshot'; export { - Query, - query, ListenOptions, + Query, QueryConstraint, + Unsubscribe, endAt, endBefore, - startAt, - startAfter, - limitToLast, - Unsubscribe, equalTo, get, limitToFirst, + limitToLast, off, onChildAdded, onChildChanged, @@ -60,10 +57,13 @@ export { orderByChild, orderByKey, orderByPriority, - orderByValue + orderByValue, + query, + startAfter, + startAt } from '../src/exp/Query'; -export { serverTimestamp, increment } from '../src/exp/ServerValue'; -export { TransactionOptions, runTransaction } from '../src/exp/Transaction'; +export { increment, serverTimestamp } from '../src/exp/ServerValue'; +export { runTransaction, TransactionOptions } from '../src/exp/Transaction'; declare module '@firebase/component' { interface NameServiceMapping { From 4ecc0e505744903240d07e628603ccf66e164b7f Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Thu, 11 Mar 2021 12:50:42 -0700 Subject: [PATCH 5/6] Update tests --- .../database/test/exp/integration.test.ts | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/packages/database/test/exp/integration.test.ts b/packages/database/test/exp/integration.test.ts index b446870cbe2..d220330c142 100644 --- a/packages/database/test/exp/integration.test.ts +++ b/packages/database/test/exp/integration.test.ts @@ -20,13 +20,19 @@ import { initializeApp, deleteApp } from '@firebase/app-exp'; import { expect } from 'chai'; import { DATABASE_ADDRESS, DATABASE_URL } from '../helpers/util'; -import { getDatabase } from '../../exp/index'; +import { + getDatabase, + goOffline, + goOnline, + ref, + refFromURL +} from '../../exp/index'; export function createTestApp() { return initializeApp({ databaseURL: DATABASE_URL }); } -describe('Database Tests', () => { +describe.skip('Database Tests', () => { let defaultApp; beforeEach(() => { @@ -48,7 +54,7 @@ describe('Database Tests', () => { const db = getDatabase(defaultApp, 'http://foo.bar.com'); expect(db).to.be.ok; // The URL is assumed to be secure if no port is specified. - expect(db.ref().toString()).to.equal('https://foo.bar.com/'); + expect(ref(db).toString()).to.equal('https://foo.bar.com/'); }); it('Can get app', () => { @@ -58,33 +64,33 @@ describe('Database Tests', () => { it('Can set and ge tref', async () => { const db = getDatabase(defaultApp); - await db.ref('foo/bar').set('foobar'); - const snap = await db.ref('foo/bar').get(); + await ref(db, 'foo/bar').set('foobar'); + const snap = await ref(db, 'foo/bar').get(); expect(snap.val()).to.equal('foobar'); }); it('Can get refFromUrl', async () => { const db = getDatabase(defaultApp); - await db.refFromURL(`${DATABASE_ADDRESS}/foo/bar`).get(); + await refFromURL(db, `${DATABASE_ADDRESS}/foo/bar`).get(); }); it('Can goOffline/goOnline', async () => { const db = getDatabase(defaultApp); - db.goOffline(); + goOffline(db); try { - await db.ref('foo/bar').get(); + await ref(db, 'foo/bar').get(); expect.fail('Should have failed since we are offline'); } catch (e) { expect(e.message).to.equal('Error: Client is offline.'); } - db.goOnline(); - await db.ref('foo/bar').get(); + goOnline(db); + await ref(db, 'foo/bar').get(); }); it('Can delete app', async () => { const db = getDatabase(defaultApp); await deleteApp(defaultApp); - expect(() => db.ref()).to.throw('Cannot call ref on a deleted database.'); + expect(() => ref(db)).to.throw('Cannot call ref on a deleted database.'); defaultApp = undefined; }); }); From 8ac6aa81f882dc67da48ca43c6e9f27ab19afdc8 Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Thu, 11 Mar 2021 16:46:08 -0700 Subject: [PATCH 6/6] Update integration.test.ts --- packages/database/test/exp/integration.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/database/test/exp/integration.test.ts b/packages/database/test/exp/integration.test.ts index d220330c142..8c13e2348e1 100644 --- a/packages/database/test/exp/integration.test.ts +++ b/packages/database/test/exp/integration.test.ts @@ -32,6 +32,7 @@ export function createTestApp() { return initializeApp({ databaseURL: DATABASE_URL }); } +// TODO(database-exp): Re-enable these tests describe.skip('Database Tests', () => { let defaultApp;