Skip to content

Commit 975da07

Browse files
Add database@exp API (#4614)
1 parent 13686cb commit 975da07

File tree

8 files changed

+635
-81
lines changed

8 files changed

+635
-81
lines changed

packages/database/exp/index.ts

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,48 @@ import { Component, ComponentType } from '@firebase/component';
2222
import { version } from '../package.json';
2323
import { FirebaseDatabase } from '../src/exp/Database';
2424

25-
export { getDatabase, ServerValue } from '../src/exp/Database';
26-
export { enableLogging } from '../src/core/util/util';
25+
export {
26+
enableLogging,
27+
getDatabase,
28+
goOffline,
29+
goOnline,
30+
ref,
31+
refFromURL,
32+
useDatabaseEmulator
33+
} from '../src/exp/Database';
34+
export {
35+
OnDisconnect,
36+
Reference,
37+
ThenableReference
38+
} from '../src/exp/Reference';
39+
export { DataSnapshot } from '../src/exp/DataSnapshot';
40+
export {
41+
ListenOptions,
42+
Query,
43+
QueryConstraint,
44+
Unsubscribe,
45+
endAt,
46+
endBefore,
47+
equalTo,
48+
get,
49+
limitToFirst,
50+
limitToLast,
51+
off,
52+
onChildAdded,
53+
onChildChanged,
54+
onChildMoved,
55+
onChildRemoved,
56+
onValue,
57+
orderByChild,
58+
orderByKey,
59+
orderByPriority,
60+
orderByValue,
61+
query,
62+
startAfter,
63+
startAt
64+
} from '../src/exp/Query';
65+
export { increment, serverTimestamp } from '../src/exp/ServerValue';
66+
export { runTransaction, TransactionOptions } from '../src/exp/Transaction';
2767

2868
declare module '@firebase/component' {
2969
interface NameServiceMapping {
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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+
import { Reference } from './Reference';
19+
20+
export class DataSnapshot {
21+
private constructor() {}
22+
priority: string | number | null;
23+
size: number;
24+
key: string | null;
25+
ref: Reference;
26+
27+
child(path: string): DataSnapshot {
28+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
29+
return {} as any;
30+
}
31+
32+
exists(): boolean {
33+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
34+
return {} as any;
35+
}
36+
37+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
38+
exportVal(): any {
39+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
40+
return {} as any;
41+
}
42+
43+
forEach(action: (child: DataSnapshot) => boolean | void): boolean {
44+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
45+
return {} as any;
46+
}
47+
48+
hasChild(path: string): boolean {
49+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
50+
return {} as any;
51+
}
52+
53+
hasChildren(): boolean {
54+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
55+
return {} as any;
56+
}
57+
58+
toJSON(): object | null {
59+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
60+
return {} as any;
61+
}
62+
63+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
64+
val(): any {
65+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
66+
return {} as any;
67+
}
68+
}

packages/database/src/exp/Database.ts

Lines changed: 44 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -18,91 +18,27 @@
1818
// eslint-disable-next-line import/no-extraneous-dependencies
1919
import { _FirebaseService, _getProvider, FirebaseApp } from '@firebase/app-exp';
2020
import { Reference } from '../api/Reference';
21-
import { repoManagerDatabaseFromApp } from '../core/RepoManager';
2221
import { FirebaseAuthInternalName } from '@firebase/auth-interop-types';
23-
import { Database } from '../api/Database';
2422
import { Provider } from '@firebase/component';
2523

2624
/**
2725
* Class representing a Firebase Realtime Database.
2826
*/
2927
export class FirebaseDatabase implements _FirebaseService {
30-
static readonly ServerValue = Database.ServerValue;
31-
32-
private _delegate: Database;
28+
readonly 'type' = 'database';
3329

3430
constructor(
3531
readonly app: FirebaseApp,
3632
authProvider: Provider<FirebaseAuthInternalName>,
3733
databaseUrl?: string
38-
) {
39-
this._delegate = repoManagerDatabaseFromApp(
40-
this.app,
41-
authProvider,
42-
databaseUrl,
43-
undefined
44-
);
45-
}
46-
47-
/**
48-
* Modify this instance to communicate with the Realtime Database emulator.
49-
*
50-
* <p>Note: This method must be called before performing any other operation.
51-
*
52-
* @param host - the emulator host (ex: localhost)
53-
* @param port - the emulator port (ex: 8080)
54-
*/
55-
useEmulator(host: string, port: number): void {
56-
this._delegate.useEmulator(host, port);
57-
}
58-
59-
/**
60-
* Returns a reference to the root or to the path specified in the provided
61-
* argument.
62-
*
63-
* @param path - The relative string path or an existing Reference to a
64-
* database location.
65-
* @throws If a Reference is provided, throws if it does not belong to the
66-
* same project.
67-
* @returns Firebase reference.
68-
*/
69-
ref(path?: string): Reference;
70-
ref(path?: Reference): Reference;
71-
ref(path?: string | Reference): Reference {
72-
return typeof path === 'string'
73-
? this._delegate.ref(path)
74-
: this._delegate.ref(path);
75-
}
76-
77-
/**
78-
* Returns a reference to the root or the path specified in url.
79-
* We throw a exception if the url is not in the same domain as the
80-
* current repo.
81-
* @param url - A URL that refers to a database location.
82-
* @returns A Firebase reference.
83-
*/
84-
refFromURL(url: string): Reference {
85-
return this._delegate.refFromURL(url);
86-
}
87-
88-
goOffline(): void {
89-
this._delegate.goOffline();
90-
}
91-
92-
goOnline(): void {
93-
this._delegate.goOnline();
94-
}
34+
) {}
9535

9636
_delete(): Promise<void> {
97-
return this._delegate.INTERNAL.delete();
37+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
38+
return {} as any;
9839
}
99-
100-
_setDatabaseUrl(url: string) {}
10140
}
10241

103-
const ServerValue = Database.ServerValue;
104-
export { ServerValue };
105-
10642
/**
10743
* Returns the instance of the Realtime Database SDK that is associated
10844
* with the provided {@link FirebaseApp}. Initializes a new instance with
@@ -120,3 +56,43 @@ export function getDatabase(app: FirebaseApp, url?: string): FirebaseDatabase {
12056
identifier: url
12157
}) as FirebaseDatabase;
12258
}
59+
60+
export function useDatabaseEmulator(
61+
db: FirebaseDatabase,
62+
host: string,
63+
port: number
64+
): void {
65+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
66+
return {} as any;
67+
}
68+
69+
export function goOffline(db: FirebaseDatabase): void {
70+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
71+
return {} as any;
72+
}
73+
74+
export function goOnline(db: FirebaseDatabase): void {
75+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
76+
return {} as any;
77+
}
78+
79+
export function ref(
80+
db: FirebaseDatabase,
81+
path?: string | Reference
82+
): Reference {
83+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
84+
return {} as any;
85+
}
86+
87+
export function refFromURL(db: FirebaseDatabase, url: string): Reference {
88+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
89+
return {} as any;
90+
}
91+
92+
export function enableLogging(
93+
logger?: boolean | ((message: string) => unknown),
94+
persistent?: boolean
95+
): void {
96+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
97+
return {} as any;
98+
}

0 commit comments

Comments
 (0)