Skip to content

Commit b6edf5a

Browse files
authored
Adding the RTDB typings back (#140)
* Adding the RTDB typings back * Updated RTDB typings
1 parent 3757aa9 commit b6edf5a

File tree

2 files changed

+115
-15
lines changed

2 files changed

+115
-15
lines changed

src/index.d.ts

+113-13
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616

1717
import {Bucket} from '@google-cloud/storage';
18-
import * as _rtdb from '@firebase/database';
1918
import * as _firestore from '@google-cloud/firestore';
2019

2120
declare namespace admin {
@@ -175,6 +174,119 @@ declare namespace admin.credential {
175174
function refreshToken(refreshTokenPathOrObject: string|Object): admin.credential.Credential;
176175
}
177176

177+
declare namespace admin.database {
178+
interface Database {
179+
app: admin.app.App;
180+
181+
goOffline(): void;
182+
goOnline(): void;
183+
ref(path?: string): admin.database.Reference;
184+
refFromURL(url: string): admin.database.Reference;
185+
}
186+
187+
interface DataSnapshot {
188+
key: string|null;
189+
ref: admin.database.Reference;
190+
191+
child(path: string): admin.database.DataSnapshot;
192+
exists(): boolean;
193+
exportVal(): any;
194+
forEach(action: (a: admin.database.DataSnapshot) => boolean): boolean;
195+
getPriority(): string|number|null;
196+
hasChild(path: string): boolean;
197+
hasChildren(): boolean;
198+
numChildren(): number;
199+
toJSON(): Object | null;
200+
val(): any;
201+
}
202+
203+
interface OnDisconnect {
204+
cancel(onComplete?: (a: Error|null) => any): Promise<void>;
205+
remove(onComplete?: (a: Error|null) => any): Promise<void>;
206+
set(value: any, onComplete?: (a: Error|null) => any): Promise<void>;
207+
setWithPriority(
208+
value: any,
209+
priority: number|string|null,
210+
onComplete?: (a: Error|null) => any
211+
): Promise<void>;
212+
update(values: Object, onComplete?: (a: Error|null) => any): Promise<void>;
213+
}
214+
215+
type EventType = 'value' | 'child_added' | 'child_changed' | 'child_moved' | 'child_removed';
216+
217+
interface Query {
218+
ref: admin.database.Reference;
219+
220+
endAt(value: number|string|boolean|null, key?: string): admin.database.Query;
221+
equalTo(value: number|string|boolean|null, key?: string): admin.database.Query;
222+
isEqual(other: admin.database.Query|null): boolean;
223+
limitToFirst(limit: number): admin.database.Query;
224+
limitToLast(limit: number): admin.database.Query;
225+
off(
226+
eventType?: admin.database.EventType,
227+
callback?: (a: admin.database.DataSnapshot, b?: string|null) => any,
228+
context?: Object|null
229+
): void;
230+
on(
231+
eventType: admin.database.EventType,
232+
callback: (a: admin.database.DataSnapshot|null, b?: string) => any,
233+
cancelCallbackOrContext?: Object|null,
234+
context?: Object|null
235+
): (a: admin.database.DataSnapshot|null, b?: string) => any;
236+
once(
237+
eventType: admin.database.EventType,
238+
successCallback?: (a: admin.database.DataSnapshot, b?: string) => any,
239+
failureCallbackOrContext?: Object|null,
240+
context?: Object|null
241+
): Promise<any>;
242+
orderByChild(path: string): admin.database.Query;
243+
orderByKey(): admin.database.Query;
244+
orderByPriority(): admin.database.Query;
245+
orderByValue(): admin.database.Query;
246+
startAt(value: number|string|boolean|null, key?: string): admin.database.Query;
247+
toJSON(): Object;
248+
toString(): string;
249+
}
250+
251+
interface Reference extends admin.database.Query {
252+
key: string|null;
253+
parent: admin.database.Reference|null;
254+
root: admin.database.Reference;
255+
path: string;
256+
257+
child(path: string): admin.database.Reference;
258+
onDisconnect(): admin.database.OnDisconnect;
259+
push(value?: any, onComplete?: (a: Error|null) => any): admin.database.ThenableReference;
260+
remove(onComplete?: (a: Error|null) => any): Promise<void>;
261+
set(value: any, onComplete?: (a: Error|null) => any): Promise<void>;
262+
setPriority(
263+
priority: string|number|null,
264+
onComplete: (a: Error|null) => any
265+
): Promise<void>;
266+
setWithPriority(
267+
newVal: any, newPriority: string|number|null,
268+
onComplete?: (a: Error|null) => any
269+
): Promise<void>;
270+
transaction(
271+
transactionUpdate: (a: any) => any,
272+
onComplete?: (a: Error|null, b: boolean, c: admin.database.DataSnapshot|null) => any,
273+
applyLocally?: boolean
274+
): Promise<{
275+
committed: boolean,
276+
snapshot: admin.database.DataSnapshot|null
277+
}>;
278+
update(values: Object, onComplete?: (a: Error|null) => any): Promise<void>;
279+
}
280+
281+
interface ThenableReference extends admin.database.Reference, PromiseLike<any> {}
282+
283+
function enableLogging(logger?: boolean|((message: string) => any), persistent?: boolean): any;
284+
}
285+
286+
declare namespace admin.database.ServerValue {
287+
var TIMESTAMP: number;
288+
}
289+
178290
declare namespace admin.messaging {
179291
type DataMessagePayload = {
180292
[key: string]: string;
@@ -295,18 +407,6 @@ declare namespace admin.storage {
295407
}
296408
}
297409

298-
declare namespace admin.database {
299-
export import Database = _rtdb.Database;
300-
export import Reference = _rtdb.Reference;
301-
export import Query = _rtdb.Query;
302-
export import ServerValue = _rtdb.ServerValue;
303-
export import enableLogging = _rtdb.enableLogging;
304-
export import OnDisconnect = _rtdb.OnDisconnect;
305-
export import DataSnapshot = _rtdb.DataSnapshot;
306-
307-
type EventType = 'value' | 'child_added' | 'child_changed' | 'child_moved' | 'child_removed';
308-
}
309-
310410
declare namespace admin.firestore {
311411
export import FieldPath = _firestore.FieldPath;
312412
export import FieldValue = _firestore.FieldValue;

test/integration/typescript/src/example.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ describe('Init App', () => {
3232

3333
it('Should return a Database client', () => {
3434
const db = admin.database(app);
35-
expect(db).to.be.instanceOf(admin.database.Database);
35+
expect(db).to.be.instanceOf((admin.database as any).Database);
3636
});
3737

3838
it('Should return a Database client for URL', () => {
3939
const db = app.database('https://other-mock.firebaseio.com');
40-
expect(db).to.be.instanceOf(admin.database.Database);
40+
expect(db).to.be.instanceOf((admin.database as any).Database);
4141
});
4242

4343
it('Should return a Database ServerValue', () => {

0 commit comments

Comments
 (0)