UNPKG

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