forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
firebase.d.ts
341 lines (329 loc) · 11.9 KB
/
firebase.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
// Type definitions for Firebase API 2.0.2
// Project: https://www.firebase.com/docs/javascript/firebase
// Definitions by: Vincent Botone <https://github.com/vbortone/>, Shin1 Kashimura <https://github.com/in-async/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
interface FirebaseAuthResult {
auth: any;
expires: number;
}
interface FirebaseDataSnapshot {
/**
* Returns true if this DataSnapshot contains any data.
* It is slightly more efficient than using snapshot.val() !== null.
*/
exists(): boolean;
/**
* Gets the JavaScript object representation of the DataSnapshot.
*/
val(): any;
/**
* Gets a DataSnapshot for the location at the specified relative path.
*/
child(childPath: string): FirebaseDataSnapshot;
/**
* Enumerates through the DataSnapshot’s children (in the default order).
*/
forEach(childAction: (childSnapshot: FirebaseDataSnapshot) => void): boolean;
forEach(childAction: (childSnapshot: FirebaseDataSnapshot) => boolean): boolean;
/**
* Returns true if the specified child exists.
*/
hasChild(childPath: string): boolean;
/**
* Returns true if the DataSnapshot has any children.
*/
hasChildren(): boolean;
/**
* Gets the key name of the location that generated this DataSnapshot.
*/
key(): string;
/**
* @deprecated Use key() instead.
* Gets the key name of the location that generated this DataSnapshot.
*/
name(): string;
/**
* Gets the number of children for this DataSnapshot.
*/
numChildren(): number;
/**
* Gets the Firebase reference for the location that generated this DataSnapshot.
*/
ref(): Firebase;
/**
* Gets the priority of the data in this DataSnapshot.
* @returns {string, number, null} The priority, or null if no priority was set.
*/
getPriority(): any; // string or number
/**
* Exports the entire contents of the DataSnapshot as a JavaScript object.
*/
exportVal(): Object;
}
interface FirebaseOnDisconnect {
/**
* Ensures the data at this location is set to the specified value when the client is disconnected
* (due to closing the browser, navigating to a new page, or network issues).
*/
set(value: any, onComplete?: (error: any) => void): void;
/**
* Ensures the data at this location is set to the specified value and priority when the client is disconnected
* (due to closing the browser, navigating to a new page, or network issues).
*/
setWithPriority(value: any, priority: string, onComplete?: (error: any) => void): void;
setWithPriority(value: any, priority: number, onComplete?: (error: any) => void): void;
/**
* Writes the enumerated children at this Firebase location when the client is disconnected
* (due to closing the browser, navigating to a new page, or network issues).
*/
update(value: Object, onComplete?: (error: any) => void): void;
/**
* Ensures the data at this location is deleted when the client is disconnected
* (due to closing the browser, navigating to a new page, or network issues).
*/
remove(onComplete?: (error: any) => void): void;
/**
* Cancels all previously queued onDisconnect() set or update events for this location and all children.
*/
cancel(onComplete?: (error: any) => void): void;
}
interface FirebaseQuery {
/**
* Listens for data changes at a particular location.
*/
on(eventType: string, callback: (dataSnapshot: FirebaseDataSnapshot, prevChildName?: string) => void, cancelCallback?: (error: any) => void, context?: Object): (dataSnapshot: FirebaseDataSnapshot, prevChildName?: string) => void;
/**
* Detaches a callback previously attached with on().
*/
off(eventType?: string, callback?: (dataSnapshot: FirebaseDataSnapshot, prevChildName?: string) => void, context?: Object): void;
/**
* Listens for exactly one event of the specified event type, and then stops listening.
*/
once(eventType: string, successCallback: (dataSnapshot: FirebaseDataSnapshot) => void, context?: Object): void;
once(eventType: string, successCallback: (dataSnapshot: FirebaseDataSnapshot) => void, failureCallback?: (error: any) => void, context?: Object): void;
/**
* Generates a new Query object ordered by the specified child key.
*/
orderByChild(key: string): FirebaseQuery;
/**
* Generates a new Query object ordered by key name.
*/
orderByKey(): FirebaseQuery;
/**
* Generates a new Query object ordered by child values.
*/
orderByValue(): FirebaseQuery;
/**
* Generates a new Query object ordered by priority.
*/
orderByPriority(): FirebaseQuery;
/**
* @deprecated Use limitToFirst() and limitToLast() instead.
* Generates a new Query object limited to the specified number of children.
*/
limit(limit: number): FirebaseQuery;
/**
* Creates a Query with the specified starting point.
* The generated Query includes children which match the specified starting point.
*/
startAt(value: string, key?: string): FirebaseQuery;
startAt(value: number, key?: string): FirebaseQuery;
/**
* Creates a Query with the specified ending point.
* The generated Query includes children which match the specified ending point.
*/
endAt(value: string, key?: string): FirebaseQuery;
endAt(value: number, key?: string): FirebaseQuery;
/**
* Creates a Query which includes children which match the specified value.
*/
equalTo(value: string, key?: string): FirebaseQuery;
equalTo(value: number, key?: string): FirebaseQuery;
/**
* Generates a new Query object limited to the first certain number of children.
*/
limitToFirst(limit: number): FirebaseQuery;
/**
* Generates a new Query object limited to the last certain number of children.
*/
limitToLast(limit: number): FirebaseQuery;
/**
* Gets a Firebase reference to the Query's location.
*/
ref(): Firebase;
}
interface Firebase extends FirebaseQuery {
/**
* @deprecated Use authWithCustomToken() instead.
* Authenticates a Firebase client using the provided authentication token or Firebase Secret.
*/
auth(authToken: string, onComplete?: (error: any, result: FirebaseAuthResult) => void, onCancel?:(error: any) => void): void;
/**
* Authenticates a Firebase client using an authentication token or Firebase Secret.
*/
authWithCustomToken(autoToken: string, onComplete: (error: any, authData: FirebaseAuthData) => void, options?:Object): void;
/**
* Authenticates a Firebase client using a new, temporary guest account.
*/
authAnonymously(onComplete: (error: any, authData: FirebaseAuthData) => void, options?: Object): void;
/**
* Authenticates a Firebase client using an email / password combination.
*/
authWithPassword(credentials: FirebaseCredentials, onComplete: (error: any, authData: FirebaseAuthData) => void, options?: Object): void;
/**
* Authenticates a Firebase client using a popup-based OAuth flow.
*/
authWithOAuthPopup(provider: string, onComplete:(error: any, authData: FirebaseAuthData) => void, options?: Object): void;
/**
* Authenticates a Firebase client using a redirect-based OAuth flow.
*/
authWithOAuthRedirect(provider: string, onComplete: (error: any) => void, options?: Object): void;
/**
* Authenticates a Firebase client using OAuth access tokens or credentials.
*/
authWithOAuthToken(provider: string, credentials: string, onComplete: (error: any, authData: FirebaseAuthData) => void, options?: Object): void;
authWithOAuthToken(provider: string, credentials: Object, onComplete: (error: any, authData: FirebaseAuthData) => void, options?: Object): void;
/**
* Synchronously access the current authentication state of the client.
*/
getAuth(): FirebaseAuthData;
/**
* Listen for changes to the client's authentication state.
*/
onAuth(onComplete: (authData: FirebaseAuthData) => void, context?: Object): void;
/**
* Detaches a callback previously attached with onAuth().
*/
offAuth(onComplete: (authData: FirebaseAuthData) => void, context?: Object): void;
/**
* Unauthenticates a Firebase client.
*/
unauth(): void;
/**
* Gets a Firebase reference for the location at the specified relative path.
*/
child(childPath: string): Firebase;
/**
* Gets a Firebase reference to the parent location.
*/
parent(): Firebase;
/**
* Gets a Firebase reference to the root of the Firebase.
*/
root(): Firebase;
/**
* Returns the last token in a Firebase location.
*/
key(): string;
/**
* @deprecated Use key() instead.
* Returns the last token in a Firebase location.
*/
name(): string;
/**
* Gets the absolute URL corresponding to this Firebase reference's location.
*/
toString(): string;
/**
* Writes data to this Firebase location.
*/
set(value: any, onComplete?: (error: any) => void): void;
/**
* Writes the enumerated children to this Firebase location.
*/
update(value: Object, onComplete?: (error: any) => void): void;
/**
* Removes the data at this Firebase location.
*/
remove(onComplete?: (error: any) => void): void;
/**
* Generates a new child location using a unique name and returns a Firebase reference to it.
* @returns {Firebase} A Firebase reference for the generated location.
*/
push(value?: any, onComplete?: (error: any) => void): Firebase;
/**
* Writes data to this Firebase location. Like set() but also specifies the priority for that data.
*/
setWithPriority(value: any, priority: string, onComplete?: (error: any) => void): void;
setWithPriority(value: any, priority: number, onComplete?: (error: any) => void): void;
/**
* Sets a priority for the data at this Firebase location.
*/
setPriority(priority: string, onComplete?: (error: any) => void): void;
setPriority(priority: number, onComplete?: (error: any) => void): void;
/**
* Atomically modifies the data at this location.
*/
transaction(updateFunction: (currentData: any)=> any, onComplete?: (error: any, committed: boolean, snapshot: FirebaseDataSnapshot) => void, applyLocally?: boolean): void;
/**
* Creates a new user account using an email / password combination.
*/
createUser(credentials: FirebaseCredentials, onComplete: (error: any) => void): void;
/**
* Updates the email associated with an email / password user account.
*/
changeEmail(credentials: FirebaseChangeEmailCredentials, onComplete: (error: any) => void): void;
/**
* Change the password of an existing user using an email / password combination.
*/
changePassword(credentials: FirebaseChangePasswordCredentials, onComplete: (error: any) => void): void;
/**
* Removes an existing user account using an email / password combination.
*/
removeUser(credentials: FirebaseCredentials, onComplete: (error: any) => void): void;
/**
* Sends a password-reset email to the owner of the account, containing a token that may be used to authenticate and change the user password.
*/
resetPassword(credentials: FirebaseResetPasswordCredentials, onComplete: (error: any) => void): void;
onDisconnect(): FirebaseOnDisconnect;
}
interface FirebaseStatic {
/**
* Constructs a new Firebase reference from a full Firebase URL.
*/
new (firebaseURL: string): Firebase;
/**
* Manually disconnects the Firebase client from the server and disables automatic reconnection.
*/
goOffline(): void;
/**
* Manually reestablishes a connection to the Firebase server and enables automatic reconnection.
*/
goOnline(): void;
ServerValue: {
/**
* A placeholder value for auto-populating the current timestamp
* (time since the Unix epoch, in milliseconds) by the Firebase servers.
*/
TIMESTAMP: any;
};
}
declare var Firebase: FirebaseStatic;
declare module 'firebase' {
export = Firebase;
}
// Reference: https://www.firebase.com/docs/web/api/firebase/getauth.html
interface FirebaseAuthData {
uid: string;
provider: string;
token: string;
expires: number;
auth: Object;
}
interface FirebaseCredentials {
email: string;
password: string;
}
interface FirebaseChangePasswordCredentials {
email: string;
oldPassword: string;
newPassword: string;
}
interface FirebaseChangeEmailCredentials {
oldEmail: string;
newEmail: string;
password: string;
}
interface FirebaseResetPasswordCredentials {
email: string;
}