Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit 6ea853c

Browse files
Better TS definition
1 parent f25cc82 commit 6ea853c

File tree

1 file changed

+93
-82
lines changed

1 file changed

+93
-82
lines changed

firebase.d.ts

Lines changed: 93 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,60 @@
1-
declare module "nativescript-firebase" {
1+
declare namespace firebase {
22

33
/**
44
* The allowed values for LoginOptions.type.
55
*/
66
export enum LoginType {
7-
/**
8-
* No further data is required.
9-
*/
10-
ANONYMOUS,
11-
/**
12-
* This requires you to pass in email and password properties as well.
13-
*/
14-
PASSWORD,
15-
/**
16-
* This requires you to pass either an authentication token generated by your backend server
17-
* or the tokenProviderFn function that returns a promise to provide the token.
18-
* See: https://firebase.google.com/docs/auth/server
19-
*/
20-
CUSTOM,
21-
/**
22-
* This requires you to setup Facebook Auth in the Firebase console,
23-
* as well as uncommenting the SDK includes in include.gradle (Android) and Podfile (iOS).
24-
*/
25-
FACEBOOK,
26-
/**
27-
* This requires you to setup Google Sign In in the Firebase console,
28-
* as well as uncommenting the SDK includes in include.gradle (Android) and Podfile (iOS).
29-
*/
30-
GOOGLE
7+
/**
8+
* No further data is required.
9+
*/
10+
ANONYMOUS,
11+
/**
12+
* This requires you to pass in email and password properties as well.
13+
*/
14+
PASSWORD,
15+
/**
16+
* This requires you to pass either an authentication token generated by your backend server
17+
* or the tokenProviderFn function that returns a promise to provide the token.
18+
* See: https://firebase.google.com/docs/auth/server
19+
*/
20+
CUSTOM,
21+
/**
22+
* This requires you to setup Facebook Auth in the Firebase console,
23+
* as well as uncommenting the SDK includes in include.gradle (Android) and Podfile (iOS).
24+
*/
25+
FACEBOOK,
26+
/**
27+
* This requires you to setup Google Sign In in the Firebase console,
28+
* as well as uncommenting the SDK includes in include.gradle (Android) and Podfile (iOS).
29+
*/
30+
GOOGLE
3131
}
3232

3333
/**
3434
* The allowed values for QueryOptions.orderBy.type.
3535
*/
3636
export enum QueryOrderByType {
37-
KEY,
38-
VALUE,
39-
CHILD,
40-
PRIORITY
37+
KEY,
38+
VALUE,
39+
CHILD,
40+
PRIORITY
4141
}
4242

4343
/**
4444
* The allowed values for QueryOptions.range.type.
4545
*/
4646
export enum QueryRangeType {
47-
START_AT,
48-
END_AT,
49-
EQUAL_TO
47+
START_AT,
48+
END_AT,
49+
EQUAL_TO
5050
}
5151

5252
/**
5353
* The allowed values for QueryOptions.limit.type.
5454
*/
5555
export enum QueryLimitType {
56-
FIRST,
57-
LAST
56+
FIRST,
57+
LAST
5858
}
5959

6060
export interface ServerValue {
@@ -142,6 +142,13 @@ declare module "nativescript-firebase" {
142142
singleEvent?: boolean;
143143
}
144144

145+
export interface GetAuthTokenOptions {
146+
/**
147+
* Default false.
148+
*/
149+
forceRefresh?: boolean;
150+
}
151+
145152
/**
146153
* The options object passed into the login function.
147154
*/
@@ -353,7 +360,7 @@ declare module "nativescript-firebase" {
353360

354361
/**
355362
* You can get updates during upload by passing a function, example:
356-
*
363+
*
357364
* onProgress: function(status) {
358365
* console.log("Uploaded fraction: " + status.fractionCompleted);
359366
* console.log("Percentage complete: " + status.percentageCompleted);
@@ -363,7 +370,6 @@ declare module "nativescript-firebase" {
363370
}
364371

365372
export interface UploadFileResult {
366-
367373
}
368374

369375
export interface DownloadFileOptions {
@@ -423,24 +429,8 @@ declare module "nativescript-firebase" {
423429
log: string;
424430
}
425431

426-
export function init(options: InitOptions): Promise<any>;
427-
428-
// Database
429-
export function push(path: string, value: any): Promise<PushResult>;
430-
export function setValue(path: string, value: any): Promise<any>;
431-
export function update(path: string, value: any): Promise<any>;
432-
export function remove(path: string): Promise<any>;
433-
export function query(onValueEvent: (data: FBData) => void, path: string, options: QueryOptions): Promise<any>;
434-
export function addChildEventListener(onChildEvent: (data: FBData) => void, path: string): Promise<AddEventListenerResult>;
435-
export function addValueEventListener(onValueEvent: (data: FBData) => void, path: string): Promise<AddEventListenerResult>;
436-
export function removeEventListeners(listeners: Array<any>, path: string): Promise<any>;
437-
/**
438-
* Tells the client to keep its local cache in sync with the server automatically.
439-
*/
440-
export function keepInSync(path: string, switchOn: boolean): Promise<any>;
441-
442432
// Analytics, nicely grouped in its own module
443-
export module analytics {
433+
namespace analytics {
444434
export interface LogEventParameter {
445435
key: string;
446436
value: string;
@@ -456,7 +446,7 @@ declare module "nativescript-firebase" {
456446
* Each (predefined) event has its own set of optional parameters, see
457447
* https://firebase.google.com/docs/reference/android/com/google/firebase/analytics/FirebaseAnalytics.Param
458448
* Example:
459-
*
449+
*
460450
* parameters: [{
461451
* key: "item_name",
462452
* value: "abc"
@@ -474,31 +464,52 @@ declare module "nativescript-firebase" {
474464
function setUserProperty(options: SetUserPropertyOptions): Promise<any>;
475465
}
476466

477-
// Auth
478-
export function login(options: LoginOptions): Promise<User>;
479-
export function logout(): Promise<any>;
480-
export function createUser(options: CreateUserOptions): Promise<CreateUserResult>;
481-
export function deleteUser(): Promise<any>;
482-
export function resetPassword(options: ResetPasswordOptions): Promise<any>;
483-
export function changePassword(options: ChangePasswordOptions): Promise<any>;
484-
export function addAuthStateListener(listener: AuthStateChangeListener): boolean;
485-
export function removeAuthStateListener(listener: AuthStateChangeListener): boolean;
486-
export function hasAuthStateListener(listener: AuthStateChangeListener): boolean;
487-
export function getCurrentUser(): Promise<User>;
488-
489-
// FCM
490-
export function addOnMessageReceivedCallback(onMessageReceived: (data: Message) => void): Promise<any>;
491-
export function addOnPushTokenReceivedCallback(onPushTokenReceived: (data: string) => void): Promise<any>;
492-
493-
// remote config
494-
export function getRemoteConfig(options: GetRemoteConfigOptions): Promise<GetRemoteConfigResult>;
495-
496-
// storage
497-
export function uploadFile(options: UploadFileOptions): Promise<UploadFileResult>;
498-
export function downloadFile(options: DownloadFileOptions): Promise<any>;
499-
export function getDownloadUrl(options: GetDownloadUrlOptions): Promise<string>;
500-
export function deleteFile(options: DeleteFileOptions): Promise<any>;
501-
502-
// crash logging
503-
// export function sendCrashLog(options: SendCrashLogOptions): Promise<any>;
504-
}
467+
interface Firebase {
468+
init(options: InitOptions): Promise<any>;
469+
470+
// Database
471+
push(path: string, value: any): Promise<PushResult>;
472+
setValue(path: string, value: any): Promise<any>;
473+
update(path: string, value: any): Promise<any>;
474+
remove(path: string): Promise<any>;
475+
query(onValueEvent: (data: FBData) => void, path: string, options: QueryOptions): Promise<any>;
476+
addChildEventListener(onChildEvent: (data: FBData) => void, path: string): Promise<AddEventListenerResult>;
477+
addValueEventListener(onValueEvent: (data: FBData) => void, path: string): Promise<AddEventListenerResult>;
478+
removeEventListeners(listeners: Array<any>, path: string): Promise<any>;
479+
/**
480+
* Tells the client to keep its local cache in sync with the server automatically.
481+
*/
482+
keepInSync(path: string, switchOn: boolean): Promise<any>;
483+
484+
// Auth
485+
login(options: LoginOptions): Promise<User>;
486+
getAuthToken(option: GetAuthTokenOptions): Promise<string>;
487+
logout(): Promise<any>;
488+
createUser(options: CreateUserOptions): Promise<CreateUserResult>;
489+
deleteUser(): Promise<any>;
490+
resetPassword(options: ResetPasswordOptions): Promise<any>;
491+
changePassword(options: ChangePasswordOptions): Promise<any>;
492+
addAuthStateListener(listener: AuthStateChangeListener): boolean;
493+
removeAuthStateListener(listener: AuthStateChangeListener): boolean;
494+
hasAuthStateListener(listener: AuthStateChangeListener): boolean;
495+
getCurrentUser(): Promise<User>;
496+
497+
// FCM
498+
addOnMessageReceivedCallback(onMessageReceived: (data: Message) => void): Promise<any>;
499+
addOnPushTokenReceivedCallback(onPushTokenReceived: (data: string) => void): Promise<any>;
500+
501+
// remote config
502+
getRemoteConfig(options: GetRemoteConfigOptions): Promise<GetRemoteConfigResult>;
503+
504+
// storage
505+
uploadFile(options: UploadFileOptions): Promise<UploadFileResult>;
506+
downloadFile(options: DownloadFileOptions): Promise<any>;
507+
getDownloadUrl(options: GetDownloadUrlOptions): Promise<string>;
508+
deleteFile(options: DeleteFileOptions): Promise<any>;
509+
510+
// crash logging
511+
// sendCrashLog(options: SendCrashLogOptions): Promise<any>;
512+
}
513+
}
514+
515+
export = firebase;

0 commit comments

Comments
 (0)