[types] add 'withApp' module type

This commit is contained in:
Salakar
2019-02-10 05:48:24 +00:00
parent 12fd6c6fd2
commit 07f0968b99
7 changed files with 98 additions and 56 deletions

View File

@@ -15,8 +15,6 @@
*
*/
import {FirebaseApp} from "./index";
export interface NativeFirebaseError extends Error {
/**
* Firebase error code, e.g. `auth/invalid-email`
@@ -44,15 +42,6 @@ export interface NativeFirebaseError extends Error {
readonly nativeErrorMessage: string;
}
export type ReactNativeFirebaseModuleAndStatics<M, S = {}> = {
(): M;
/**
* This React Native Firebase module version.
*/
readonly SDK_VERSION: string;
} & S;
export type FirebaseOptions = {
/**
* The Google App ID that is used to uniquely identify an instance of an app.
@@ -85,7 +74,6 @@ export type FirebaseOptions = {
*/
storageBucket?: string;
/**
* The Project Number from the Google Developer's console, for example "012345678901", used to
* configure Google Cloud Messaging.
@@ -254,3 +242,21 @@ export namespace App {
readonly SDK_VERSION: string;
}
}
export type ReactNativeFirebaseModuleAndStatics<M, S = {}> = {
(): M;
/**
* This React Native Firebase module version.
*/
readonly SDK_VERSION: string;
} & S;
export type ReactNativeFirebaseModuleAndStaticsWithApp<M, S = {}> = {
(app?: FirebaseApp): M;
/**
* This React Native Firebase module version.
*/
readonly SDK_VERSION: string;
} & S;

View File

@@ -19,6 +19,11 @@ export type ReactNativeFirebaseModuleAndStatics<M, S = {}> = {
+SDK_VERSION: string;
} & S;
export type ReactNativeFirebaseModuleAndStaticsWithApp<M, S = {}> = {
(): M;
+SDK_VERSION: string;
} & S;
export type FirebaseOptions = {
appId: string;
apiKey?: string;

View File

@@ -17,6 +17,7 @@
import {
ReactNativeFirebaseModule,
ReactNativeFirebaseModuleAndStaticsWithApp,
ReactNativeFirebaseNamespace,
} from '@react-native-firebase/app-types';
@@ -141,7 +142,7 @@ export namespace Functions {
/**
* Uppercase + underscored variables of @Functions.FunctionsErrorCode
*/
HttpsErrorCode: {} & HttpsErrorCode,
HttpsErrorCode: {} & HttpsErrorCode;
}
/**
@@ -185,13 +186,10 @@ declare module '@react-native-firebase/functions' {
*/
export const firebase: {} & ReactNativeFirebaseNamespace;
const FunctionsDefaultExport: {
(app?: FirebaseApp): Functions.Module;
/**
* This React Native Firebase Functions module version.
*/
readonly SDK_VERSION: string;
} & Functions.Statics;
const FunctionsDefaultExport: ReactNativeFirebaseModuleAndStaticsWithApp<
Functions.Module,
Functions.Statics
>;
/**
* @example
* ```js
@@ -213,13 +211,7 @@ declare module '@react-native-firebase/app-types' {
* write and deploy an HTTPS Callable function in Cloud Functions,
* and then add client logic to call the function from your app.
*/
functions: {
(app?: FirebaseApp): Functions.Module;
/**
* This React Native Firebase Functions module version.
*/
readonly SDK_VERSION: string;
} & Functions.Statics;
functions: ReactNativeFirebaseModuleAndStaticsWithApp<Functions.Module, Functions.Statics>;
}
interface FirebaseApp {
@@ -228,6 +220,8 @@ declare module '@react-native-firebase/app-types' {
* directly from a Firebase app. To call a function from your app in this way,
* write and deploy an HTTPS Callable function in Cloud Functions,
* and then add client logic to call the function from your app.
*
* @param region The region you deployed your functions to. Defaults to 'us-central1'.
*/
functions?(region?: string): Functions.Module;
}

View File

@@ -15,9 +15,7 @@
*
*/
import {
ReactNativeFirebaseModule,
} from '@react-native-firebase/app-types/index.js.flow';
import { ReactNativeFirebaseModule } from '@react-native-firebase/app-types/index.js.flow';
/**
* The set of Firebase Functions status codes. The codes are the same at the
@@ -160,7 +158,10 @@ interface Module extends ReactNativeFirebaseModule {
}
declare module '@react-native-firebase/functions' {
import type { FirebaseApp, ReactNativeFirebaseNamespace } from '@react-native-firebase/app-types';
import type {
ReactNativeFirebaseNamespace,
ReactNativeFirebaseModuleAndStaticsWithApp,
} from '@react-native-firebase/app-types/index.js.flow';
declare export var HttpsErrorCode: {} & HttpsErrorCode;
@@ -173,13 +174,7 @@ declare module '@react-native-firebase/functions' {
*/
declare export var firebase: {} & ReactNativeFirebaseNamespace;
declare var FunctionsDefaultExport: {
(app?: FirebaseApp): Module,
/**
* This React Native Firebase Functions module version.
*/
SDK_VERSION: string,
} & Statics;
declare var FunctionsDefaultExport: ReactNativeFirebaseModuleAndStaticsWithApp<Module, Statics>;
/**
* @example
* ```js
@@ -201,13 +196,7 @@ declare module '@react-native-firebase/app-types' {
* write and deploy an HTTPS Callable function in Cloud Functions,
* and then add client logic to call the function from your app.
*/
functions: {
(app?: FirebaseApp): Module,
/**
* This React Native Firebase Functions module version.
*/
SDK_VERSION: string,
} & Statics;
functions: ReactNativeFirebaseModuleAndStaticsWithApp<Module, Statics>;
}
declare interface FirebaseApp {

View File

@@ -18,7 +18,7 @@
import {
ReactNativeFirebaseModule,
ReactNativeFirebaseNamespace,
ReactNativeFirebaseModuleAndStatics,
ReactNativeFirebaseModuleAndStaticsWithApp,
} from '@react-native-firebase/app-types';
/**
@@ -69,7 +69,10 @@ export namespace Iid {
}
declare module '@react-native-firebase/iid' {
import { ReactNativeFirebaseNamespace } from '@react-native-firebase/app-types';
import {
ReactNativeFirebaseModuleAndStaticsWithApp,
ReactNativeFirebaseNamespace
} from '@react-native-firebase/app-types';
const FirebaseNamespaceExport: {} & ReactNativeFirebaseNamespace;
@@ -82,7 +85,7 @@ declare module '@react-native-firebase/iid' {
*/
export const firebase = FirebaseNamespaceExport;
const IidDefaultExport: ReactNativeFirebaseModuleAndStatics<Iid.Module, Iid.Statics>;
const IidDefaultExport: ReactNativeFirebaseModuleAndStaticsWithApp<Iid.Module, Iid.Statics>;
/**
* @example
* ```js
@@ -105,7 +108,7 @@ declare module '@react-native-firebase/app-types' {
* An Instance ID is long lived except when you call delete, the app is restored on a new device, the user
* uninstalls/reinstall the app or the user clears the app data (clearing data applies to Android only).
*/
iid: ReactNativeFirebaseModuleAndStatics<Iid.Module, Iid.Statics>;
iid: ReactNativeFirebaseModuleAndStaticsWithApp<Iid.Module, Iid.Statics>;
}
interface FirebaseApp {

View File

@@ -21,13 +21,43 @@ import type { ReactNativeFirebaseModule } from '@react-native-firebase/app-types
export interface Statics {}
export interface Module extends ReactNativeFirebaseModule {
/**
* Returns a identifier that uniquely identifies the app instance.
*
* Once an Instance ID is generated, Firebase periodically sends information about the application
* and the device it's running on to the Firebase backend. To stop this, see `delete()`.
*/
get(): Promise<string>;
/**
* Delete the Instance ID and all data associated with it. This stops the periodic sending of data to the Firebase
* backend that was started when the Instance ID was generated.
*
* A new Instance ID is asynchronously generated unless auto initialisation is turned off.
*/
delete(): Promise<void>;
/**
* Returns a token that authorizes an Entity to perform an action on behalf of the application.
*
* @param authorizedEntity Entity authorized by the token. Defaults to the apps `messagingSenderId` option.
* @param scope Action authorized for authorizedEntity. Defaults to '*'.
*/
getToken(authorizedEntity?: string, scope?: string): Promise<string>;
/**
* Revokes access to a scope for an entity previously authorized by `getToken()`.
*
* @param authorizedEntity Entity authorized by the token. Defaults to the apps' `messagingSenderId` option.
* @param scope Action authorized for authorizedEntity. Defaults to '*'.
*/
deleteToken(authorizedEntity?: string, scope?: string): Promise<void>;
}
declare module '@react-native-firebase/iid' {
import type {
ReactNativeFirebaseNamespace,
ReactNativeFirebaseModuleAndStatics,
ReactNativeFirebaseModuleAndStaticsWithApp,
} from '@react-native-firebase/app-types/index.js.flow';
/**
* @example
@@ -45,25 +75,37 @@ declare module '@react-native-firebase/iid' {
* iid().X(...);
* ```
*/
declare export default ReactNativeFirebaseModuleAndStatics<Module, Statics>;
declare export default ReactNativeFirebaseModuleAndStaticsWithApp<Module, Statics>;
}
/**
* Attach namespace to `firebase.` and `FirebaseApp.`.
*/
declare module '@react-native-firebase/app-types' {
import type { ReactNativeFirebaseModuleAndStatics } from '@react-native-firebase/app-types/index.js.flow';
import type { ReactNativeFirebaseModuleAndStaticsWithApp } from '@react-native-firebase/app-types/index.js.flow';
declare interface ReactNativeFirebaseNamespace {
/**
* Iid
* Firebase Instance ID provides a unique identifier for each instance of your app and a mechanism to authenticate
* and authorize actions for it (for example: sending FCM messages).
*
* An Instance ID is long lived except when you call delete, the app is restored on a new device, the user
* uninstalls/reinstall the app or the user clears the app data (clearing data applies to Android only).
*
* @firebase iid
*/
iid: ReactNativeFirebaseModuleAndStatics<Module, Statics>;
iid: ReactNativeFirebaseModuleAndStaticsWithApp<Module, Statics>;
}
declare interface FirebaseApp {
/**
* Iid
* Firebase Instance ID provides a unique identifier for each instance of your app and a mechanism to authenticate
* and authorize actions for it (for example: sending FCM messages).
*
* An Instance ID is long lived except when you call delete, the app is restored on a new device, the user
* uninstalls/reinstall the app or the user clears the app data (clearing data applies to Android only).
*
* @firebase iid
*/
iid(): Module;
}

View File

@@ -1,4 +1,5 @@
import firebase from 'react-native-firebase';
import '@react-native-firebase/iid';
import analytics, { Analytics } from '@react-native-firebase/analytics';
import functions, {
firebase as boopy,
@@ -6,13 +7,15 @@ import functions, {
HttpsErrorCode,
} from '@react-native-firebase/functions';
firebase.app;
boopy.apps[0].options.projectId;
analytics.SDK_VERSION;
functions.SDK_VERSION;
const httpsCallable = firebase.functions(firebase.app()).httpsCallable('foo');
functions;
firebase.iid().get();
firebase.analytics().resetAnalyticsData();
httpsCallable({ foo: 1 })
.then(result => {
result.data;