UNPKG

4.74 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright 2017 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
18import { FirebaseApp } from '@firebase/app-types';
19
20export interface DataSnapshot {
21 child(path: string): DataSnapshot;
22 exists(): boolean;
23 exportVal(): any;
24 forEach(action: (a: DataSnapshot) => boolean | void): boolean;
25 getPriority(): string | number | null;
26 hasChild(path: string): boolean;
27 hasChildren(): boolean;
28 key: string | null;
29 numChildren(): number;
30 ref: Reference;
31 toJSON(): Object | null;
32 val(): any;
33}
34
35export interface Database {
36 app: FirebaseApp;
37 useEmulator(host: string, port: number): void;
38 goOffline(): void;
39 goOnline(): void;
40 ref(path?: string | Reference): Reference;
41 refFromURL(url: string): Reference;
42}
43
44export class FirebaseDatabase implements Database {
45 private constructor();
46 app: FirebaseApp;
47 useEmulator(host: string, port: number): void;
48 goOffline(): void;
49 goOnline(): void;
50 ref(path?: string | Reference): Reference;
51 refFromURL(url: string): Reference;
52}
53
54export interface OnDisconnect {
55 cancel(onComplete?: (a: Error | null) => any): Promise<void>;
56 remove(onComplete?: (a: Error | null) => any): Promise<void>;
57 set(value: any, onComplete?: (a: Error | null) => any): Promise<void>;
58 setWithPriority(
59 value: any,
60 priority: number | string | null,
61 onComplete?: (a: Error | null) => any
62 ): Promise<any>;
63 update(values: Object, onComplete?: (a: Error | null) => any): Promise<any>;
64}
65
66type EventType =
67 | 'value'
68 | 'child_added'
69 | 'child_changed'
70 | 'child_moved'
71 | 'child_removed';
72
73export interface Query {
74 endBefore(value: number | string | boolean | null, key?: string): Query;
75 endAt(value: number | string | boolean | null, key?: string): Query;
76 equalTo(value: number | string | boolean | null, key?: string): Query;
77 isEqual(other: Query | null): boolean;
78 limitToFirst(limit: number): Query;
79 limitToLast(limit: number): Query;
80 off(
81 eventType?: EventType,
82 callback?: (a: DataSnapshot, b?: string | null) => any,
83 context?: Object | null
84 ): void;
85 get(): Promise<DataSnapshot>;
86 on(
87 eventType: EventType,
88 callback: (a: DataSnapshot, b?: string | null) => any,
89 cancelCallbackOrContext?: ((a: Error) => any) | Object | null,
90 context?: Object | null
91 ): (a: DataSnapshot | null, b?: string | null) => any;
92 once(
93 eventType: EventType,
94 successCallback?: (a: DataSnapshot, b?: string | null) => any,
95 failureCallbackOrContext?: ((a: Error) => void) | Object | null,
96 context?: Object | null
97 ): Promise<DataSnapshot>;
98 orderByChild(path: string): Query;
99 orderByKey(): Query;
100 orderByPriority(): Query;
101 orderByValue(): Query;
102 ref: Reference;
103 startAt(value: number | string | boolean | null, key?: string): Query;
104 startAfter(value: number | string | boolean | null, key?: string): Query;
105 toJSON(): Object;
106 toString(): string;
107}
108
109export interface Reference extends Query {
110 child(path: string): Reference;
111 key: string | null;
112 onDisconnect(): OnDisconnect;
113 parent: Reference | null;
114 push(value?: any, onComplete?: (a: Error | null) => any): ThenableReference;
115 remove(onComplete?: (a: Error | null) => any): Promise<any>;
116 root: Reference;
117 set(value: any, onComplete?: (a: Error | null) => any): Promise<any>;
118 setPriority(
119 priority: string | number | null,
120 onComplete: (a: Error | null) => any
121 ): Promise<any>;
122 setWithPriority(
123 newVal: any,
124 newPriority: string | number | null,
125 onComplete?: (a: Error | null) => any
126 ): Promise<any>;
127 transaction(
128 transactionUpdate: (a: any) => any,
129 onComplete?: (a: Error | null, b: boolean, c: DataSnapshot | null) => any,
130 applyLocally?: boolean
131 ): Promise<any>;
132 update(values: Object, onComplete?: (a: Error | null) => any): Promise<any>;
133}
134
135export interface ServerValue {
136 TIMESTAMP: Object;
137 increment(delta: number): Object;
138}
139
140export interface ThenableReference
141 extends Reference,
142 Pick<Promise<Reference>, 'then' | 'catch'> {}
143
144export function enableLogging(
145 logger?: boolean | ((a: string) => any),
146 persistent?: boolean
147): any;
148
149declare module '@firebase/component' {
150 interface NameServiceMapping {
151 'database': FirebaseDatabase;
152 }
153}
154
\No newline at end of file