diff --git a/packages/app-types/index.d.ts b/packages/app-types/index.d.ts index 857b528b..43c7b642 100644 --- a/packages/app-types/index.d.ts +++ b/packages/app-types/index.d.ts @@ -15,252 +15,4 @@ * */ -export interface NativeFirebaseError extends Error { - /** - * Firebase error code, e.g. `auth/invalid-email` - */ - readonly code: string; - /** - * Firebase error message - */ - readonly message: string; - - /** - * The firebase module namespace that this error originated from, e.g. 'analytics' - */ - readonly namespace: string; - - /** - * The native sdks returned error code, different per platform - */ - readonly nativeErrorCode: string | number; - - /** - * The native sdks returned error message, different per platform - */ - readonly nativeErrorMessage: string; -} - -export type FirebaseOptions = { - /** - * The Google App ID that is used to uniquely identify an instance of an app. - */ - appId: string; - - /** - * An API key used for authenticating requests from your app, e.g. - * "AIzaSyDdVgKwhZl0sTTTLZ7iTmt1r3N2cJLnaDk", used to identify your app to Google servers. - */ - apiKey?: string; - - /** - * The database root URL, e.g. "http://abc-xyz-123.firebaseio.com". - */ - databaseURL?: string; - - /** - * The Project ID from the Firebase console, for example "abc-xyz-123". - */ - projectId: string; - - /** - * The tracking ID for Google Analytics, e.g. "UA-12345678-1", used to configure Google Analytics. - */ - gaTrackingId?: string; - - /** - * The Google Cloud Storage bucket name, e.g. "abc-xyz-123.storage.firebase.com". - */ - storageBucket?: string; - - /** - * The Project Number from the Google Developer's console, for example "012345678901", used to - * configure Google Cloud Messaging. - */ - messagingSenderId?: string; - - /** - * iOS only - The OAuth2 client ID for iOS application used to authenticate Google users, for example - * "12345.apps.googleusercontent.com", used for signing in with Google. - */ - clientId?: string; - - /** - * iOS only - The Android client ID used in Google AppInvite when an iOS app has its Android version, for - * example "12345.apps.googleusercontent.com". - */ - androidClientId?: string; - - /** - * iOS only - The URL scheme used to set up Durable Deep Link service. - */ - deepLinkURLScheme?: string; - [name: string]: any; -}; - -export interface FirebaseAppConfig { - /** - * The Firebase App name, defaults to [DEFAULT] if none provided. - */ - name?: string; - - /** - * - */ - automaticDataCollectionEnabled?: boolean; - - /** - * If set to true it indicates that Firebase should close database connections - * automatically when the app is in the background. Disabled by default. - */ - automaticResourceManagement?: boolean; -} - -export interface FirebaseApp { - /** - * The name (identifier) for this App. '[DEFAULT]' is the default App. - */ - readonly name: string; - - /** - * The (read-only) configuration options from the app initialization. - */ - readonly options: FirebaseOptions; - - /** - * Make this app unusable and free up resources. - */ - delete(): Promise; -} - -export interface FirebaseJSON { - -} - -export interface ReactNativeFirebaseNamespace { - /** - * Create (and initialize) a FirebaseApp. - * - * @param options Options to configure the services used in the App. - * @param config The optional config for your firebase app - */ - initializeApp(options: FirebaseOptions, config?: FirebaseAppConfig): FirebaseApp; - - /** - * Create (and initialize) a FirebaseApp. - * - * @param options Options to configure the services used in the App. - * @param name The optional name of the app to initialize ('[DEFAULT]' if - * omitted) - */ - initializeApp(options: FirebaseOptions, name?: string): FirebaseApp; - - /** - * Retrieve an instance of a FirebaseApp. - * - * @example - * ```js - * const app = firebase.app('foo'); - * ``` - * - * @param name The optional name of the app to return ('[DEFAULT]' if omitted) - */ - app(name?: string): FirebaseApp; - - /** - * A (read-only) array of all the initialized Apps. - */ - apps: FirebaseApp[]; - - /** - * The current React Native Firebase version. - */ - readonly SDK_VERSION: string; -} - -export class ReactNativeFirebaseModule { - app: FirebaseApp; -} - -/** - * - * @firebase app - */ -export namespace App { - export interface FirebaseApp { - /** - * The name (identifier) for this App. '[DEFAULT]' is the default App. - */ - readonly name: string; - - /** - * The (read-only) configuration options from the app initialization. - */ - readonly options: FirebaseOptions; - - /** - * Make this app unusable and free up resources. - */ - delete(): Promise; - } - - export interface ReactNativeFirebaseNamespace { - /** - * Create (and initialize) a FirebaseApp. - * - * @param options Options to configure the services used in the App. - * @param config The optional config for your firebase app - */ - initializeApp(options: FirebaseOptions, config?: FirebaseAppConfig): FirebaseApp; - - /** - * Create (and initialize) a FirebaseApp. - * - * @param options Options to configure the services used in the App. - * @param name The optional name of the app to initialize ('[DEFAULT]' if - * omitted) - */ - initializeApp(options: FirebaseOptions, name?: string): FirebaseApp; - - /** - * Retrieve an instance of a FirebaseApp. - * - * @example - * ```js - * const app = firebase.app('foo'); - * ``` - * - * @param name The optional name of the app to return ('[DEFAULT]' if omitted) - */ - app(name?: string): FirebaseApp; - - /** - * A (read-only) array of all the initialized Apps. - */ - apps: FirebaseApp[]; - - /** - * The current React Native Firebase version. - */ - readonly SDK_VERSION: string; - } -} - -export type ReactNativeFirebaseModuleAndStatics = { - (): M; - - /** - * This React Native Firebase module version. - */ - readonly SDK_VERSION: string; -} & S; - -export type ReactNativeFirebaseModuleAndStaticsWithApp = { - (app?: FirebaseApp): M; - - /** - * This React Native Firebase module version. - */ - readonly SDK_VERSION: string; -} & S; diff --git a/packages/app/lib/index.d.ts b/packages/app/lib/index.d.ts index 1fbe56fa..023695d6 100644 --- a/packages/app/lib/index.d.ts +++ b/packages/app/lib/index.d.ts @@ -15,27 +15,194 @@ * */ -import { ReactNativeFirebaseNamespace } from '@react-native-firebase/app-types'; - /** - * @firebase firebase + * @firebase app */ +export namespace ReactNativeFirebase { + export interface NativeFirebaseError extends Error { + /** + * Firebase error code, e.g. `auth/invalid-email` + */ + readonly code: string; + + /** + * Firebase error message + */ + readonly message: string; + + /** + * The firebase module namespace that this error originated from, e.g. 'analytics' + */ + readonly namespace: string; + + /** + * The native sdks returned error code, different per platform + */ + readonly nativeErrorCode: string | number; + + /** + * The native sdks returned error message, different per platform + */ + readonly nativeErrorMessage: string; + } + + export type FirebaseAppOptions = { + /** + * The Google App ID that is used to uniquely identify an instance of an app. + */ + appId: string; + + /** + * An API key used for authenticating requests from your app, e.g. + * "AIzaSyDdVgKwhZl0sTTTLZ7iTmt1r3N2cJLnaDk", used to identify your app to Google servers. + */ + apiKey?: string; + + /** + * The database root URL, e.g. "http://abc-xyz-123.firebaseio.com". + */ + databaseURL?: string; + + /** + * The Project ID from the Firebase console, for example "abc-xyz-123". + */ + projectId: string; + + /** + * The tracking ID for Google Analytics, e.g. "UA-12345678-1", used to configure Google Analytics. + */ + gaTrackingId?: string; + + /** + * The Google Cloud Storage bucket name, e.g. "abc-xyz-123.storage.firebase.com". + */ + storageBucket?: string; + + /** + * The Project Number from the Google Developer's console, for example "012345678901", used to + * configure Google Cloud Messaging. + */ + messagingSenderId?: string; + + /** + * iOS only - The OAuth2 client ID for iOS application used to authenticate Google users, for example + * "12345.apps.googleusercontent.com", used for signing in with Google. + */ + clientId?: string; + + /** + * iOS only - The Android client ID used in Google AppInvite when an iOS app has its Android version, for + * example "12345.apps.googleusercontent.com". + */ + androidClientId?: string; + + /** + * iOS only - The URL scheme used to set up Durable Deep Link service. + */ + deepLinkURLScheme?: string; + [name: string]: any; + }; + + export interface FirebaseAppConfig { + /** + * The Firebase App name, defaults to [DEFAULT] if none provided. + */ + name?: string; + + /** + * + */ + automaticDataCollectionEnabled?: boolean; + + /** + * If set to true it indicates that Firebase should close database connections + * automatically when the app is in the background. Disabled by default. + */ + automaticResourceManagement?: boolean; + } + + export interface FirebaseApp { + /** + * The name (identifier) for this App. '[DEFAULT]' is the default App. + */ + readonly name: string; + + /** + * The (read-only) configuration options from the app initialization. + */ + readonly options: FirebaseAppOptions; + + /** + * Make this app unusable and free up resources. + */ + delete(): Promise; + } + + export interface Module { + /** + * Create (and initialize) a FirebaseApp. + * + * @param options Options to configure the services used in the App. + * @param config The optional config for your firebase app + */ + initializeApp(options: FirebaseAppOptions, config?: FirebaseAppConfig): FirebaseApp; + + /** + * Create (and initialize) a FirebaseApp. + * + * @param options Options to configure the services used in the App. + * @param name The optional name of the app to initialize ('[DEFAULT]' if + * omitted) + */ + initializeApp(options: FirebaseAppOptions, name?: string): FirebaseApp; + + /** + * Retrieve an instance of a FirebaseApp. + * + * @example + * ```js + * const app = firebase.app('foo'); + * ``` + * + * @param name The optional name of the app to return ('[DEFAULT]' if omitted) + */ + app(name?: string): FirebaseApp; + + /** + * A (read-only) array of all the initialized Apps. + */ + apps: FirebaseApp[]; + + /** + * The current React Native Firebase version. + */ + readonly SDK_VERSION: string; + } + + export class FirebaseModule { + app: FirebaseApp; + } + + export type FirebaseModuleWithStatics = { + (): M; + + /** + * This React Native Firebase module version. + */ + readonly SDK_VERSION: string; + } & S; + + export type FirebaseModuleWithStaticsAndApp = { + (app?: FirebaseApp): M; + + /** + * This React Native Firebase module version. + */ + readonly SDK_VERSION: string; + } & S; +} + declare module '@react-native-firebase/app' { - import { ReactNativeFirebaseNamespace, FirebaseJSON } from '@react-native-firebase/app-types'; - const ReactNativeFirebase: {} & ReactNativeFirebaseNamespace; - export default ReactNativeFirebase; - const FirebaseJSON: {} & FirebaseJSON; - export const FirebaseJSON; -} - -declare module '@react-native-firebase/app-types' { - interface ReactNativeFirebaseNamespace { - utils?: { - (app?: FirebaseApp): FirebaseUtilsModule; - }; - } - - interface FirebaseApp { - utils?(app?: FirebaseApp): FirebaseUtilsModule; - } + const module: {} & ReactNativeFirebase.Module; + export default module; } diff --git a/packages/perf/type-test.ts b/packages/perf/type-test.ts new file mode 100644 index 00000000..cfddd1a5 --- /dev/null +++ b/packages/perf/type-test.ts @@ -0,0 +1,17 @@ +import firebase from '@react-native-firebase/app'; +import { firebase as firebaseFromModule } from '@react-native-firebase/perf'; + +// checks module exists at root +console.log(firebase.perf().app.name); + +// checks module exists at app level +console.log(firebase.app().perf().app.name); + +// checks statics exist +console.log(firebase.perf.SDK_VERSION); + +// checks root exists +console.log(firebase.SDK_VERSION); + +// checks firebase named export exists on module +console.log(firebaseFromModule.SDK_VERSION); diff --git a/packages/storage/lib/index.d.ts b/packages/storage/lib/index.d.ts index ed66ab4b..50f47fd0 100644 --- a/packages/storage/lib/index.d.ts +++ b/packages/storage/lib/index.d.ts @@ -15,12 +15,7 @@ * */ -import { - NativeFirebaseError, - ReactNativeFirebaseModule, - ReactNativeFirebaseModuleAndStatics, - ReactNativeFirebaseNamespace, -} from '@react-native-firebase/app-types'; +import { ReactNativeFirebase } from '@react-native-firebase/app'; /** * Firebase Cloud Storage package for React Native. @@ -59,6 +54,9 @@ import { * @firebase storage */ export namespace Storage { + import FirebaseModule = ReactNativeFirebase.FirebaseModule; + import NativeFirebaseError = ReactNativeFirebase.NativeFirebaseError; + /** * Possible string formats used for uploading via `StorageReference.putString()` * @@ -1026,7 +1024,7 @@ export namespace Storage { * ``` * */ - export class Module extends ReactNativeFirebaseModule { + export class Module extends FirebaseModule { /** * Returns the maximum time to retry an upload if a failure occurs. * @@ -1130,26 +1128,27 @@ export namespace Storage { } declare module '@react-native-firebase/storage' { - import { ReactNativeFirebaseNamespace } from '@react-native-firebase/app-types'; + import ReactNativeFirebaseModule = ReactNativeFirebase.Module; + import FirebaseModuleWithStatics = ReactNativeFirebase.FirebaseModuleWithStatics; - const FirebaseNamespaceExport: {} & ReactNativeFirebaseNamespace; + const firebaseNamedExport: {} & ReactNativeFirebaseModule; + export const firebase = firebaseNamedExport; - export const firebase = FirebaseNamespaceExport; - - const StorageDefaultExport: ReactNativeFirebaseModuleAndStatics; - - export default StorageDefaultExport; + const module: FirebaseModuleWithStatics; + export default module; } /** * Attach namespace to `firebase.` and `FirebaseApp.`. */ -declare module '@react-native-firebase/app-types' { - interface ReactNativeFirebaseNamespace { - storage: ReactNativeFirebaseModuleAndStatics; - } - - interface FirebaseApp { - storage?(bucket?: string): Storage.Module; +declare module '@react-native-firebase/app' { + namespace ReactNativeFirebase { + import FirebaseModuleWithStatics = ReactNativeFirebase.FirebaseModuleWithStatics; + interface Module { + storage: FirebaseModuleWithStatics; + } + interface FirebaseApp { + storage(bucket?: string): Storage.Module; + } } } diff --git a/packages/storage/type-test.ts b/packages/storage/type-test.ts new file mode 100644 index 00000000..c26e7e15 --- /dev/null +++ b/packages/storage/type-test.ts @@ -0,0 +1,17 @@ +import firebase from '@react-native-firebase/app'; +import { firebase as firebaseFromModule } from '@react-native-firebase/storage'; + +// checks module exists at root +console.log(firebase.storage().app.name); + +// checks module exists at app level +console.log(firebase.app().storage().app.name); + +// checks statics exist +console.log(firebase.storage.SDK_VERSION); + +// checks root exists +console.log(firebase.SDK_VERSION); + +// checks firebase named export exists on module +console.log(firebaseFromModule.SDK_VERSION); diff --git a/packages/utils/.npmignore b/packages/utils/.npmignore index d9fa30e5..29e5aa19 100644 --- a/packages/utils/.npmignore +++ b/packages/utils/.npmignore @@ -63,3 +63,4 @@ android/.settings *.coverage.json .circleci .eslintignore +type-test.ts diff --git a/packages/utils/lib/index.d.ts b/packages/utils/lib/index.d.ts index 1f37bd1b..b409e2d4 100644 --- a/packages/utils/lib/index.d.ts +++ b/packages/utils/lib/index.d.ts @@ -15,11 +15,7 @@ * */ -import { - ReactNativeFirebaseModule, - ReactNativeFirebaseNamespace, - ReactNativeFirebaseModuleAndStatics, -} from '@react-native-firebase/app-types'; +import { ReactNativeFirebase } from '@react-native-firebase/app'; /** * React Native Firebase Utilities package. @@ -58,6 +54,8 @@ import { * @firebase utils */ export namespace Utils { + import FirebaseModule = ReactNativeFirebase.FirebaseModule; + export interface Statics {} /** @@ -73,7 +71,7 @@ export namespace Utils { * const defaultAppUtils = firebase.utils(); * ``` */ - export class Module extends ReactNativeFirebaseModule { + export class Module extends FirebaseModule { /** * Returns true if this app is running inside a Firebase Test Lab environment. Always returns false on iOS. * @@ -84,47 +82,34 @@ export namespace Utils { } declare module '@react-native-firebase/utils' { - import { ReactNativeFirebaseNamespace } from '@react-native-firebase/app-types'; + import ReactNativeFirebaseModule = ReactNativeFirebase.Module; + import FirebaseModuleWithStatics = ReactNativeFirebase.FirebaseModuleWithStatics; - const FirebaseNamespaceExport: {} & ReactNativeFirebaseNamespace; + const firebaseNamedExport: {} & ReactNativeFirebaseModule; + export const firebase = firebaseNamedExport; - /** - * @example - * ```js - * import { firebase } from '@react-native-firebase/utils'; - * firebase.utils().X(...); - * ``` - */ - export const firebase = FirebaseNamespaceExport; - - const UtilsDefaultExport: ReactNativeFirebaseModuleAndStatics; - /** - * @example - * ```js - * import utils from '@react-native-firebase/utils'; - * utils().X(...); - * ``` - */ - export default UtilsDefaultExport; + const module: FirebaseModuleWithStatics; + export default module; } /** * Attach namespace to `firebase.` and `FirebaseApp.`. */ -declare module '@react-native-firebase/app-types' { - interface ReactNativeFirebaseNamespace { - /** - * Utils provides a collection of utilities to aid in using Firebase - * and related services inside React Native, e.g. Test Lab helpers - * and Google Play Services version helpers. - */ - utils: ReactNativeFirebaseModuleAndStatics; - } +declare module '@react-native-firebase/app' { + namespace ReactNativeFirebase { + import FirebaseModuleWithStatics = ReactNativeFirebase.FirebaseModuleWithStatics; - interface FirebaseApp { - /** - * Utils - */ - utils(): Utils.Module; + interface Module { + /** + * Utils provides a collection of utilities to aid in using Firebase + * and related services inside React Native, e.g. Test Lab helpers + * and Google Play Services version helpers. + */ + utils: FirebaseModuleWithStatics; + } + + interface FirebaseApp { + utils(): Utils.Module; + } } } diff --git a/packages/utils/type-test.ts b/packages/utils/type-test.ts new file mode 100644 index 00000000..5b655858 --- /dev/null +++ b/packages/utils/type-test.ts @@ -0,0 +1,17 @@ +import firebase from '@react-native-firebase/app'; +import { firebase as firebaseFromModule } from '@react-native-firebase/utils'; + +// checks module exists at root +console.log(firebase.utils().app.name); + +// checks module exists at app level +console.log(firebase.app().utils().app.name); + +// checks statics exist +console.log(firebase.utils.SDK_VERSION); + +// checks root exists +console.log(firebase.SDK_VERSION); + +// checks firebase named export exists on module +console.log(firebaseFromModule.SDK_VERSION); diff --git a/tests/type-test.ts b/tests/type-test.ts deleted file mode 100644 index 0b81f2d5..00000000 --- a/tests/type-test.ts +++ /dev/null @@ -1,39 +0,0 @@ -import '@react-native-firebase/storage'; -import '@react-native-firebase/perf'; -import '@react-native-firebase/functions'; - -import { VisionCloudTextRecognizerModelType } from '@react-native-firebase/ml-vision'; - -console.log(VisionCloudTextRecognizerModelType.SPARSE_MODEL); - -// -// const foo = async () => { -// const task = firebase -// .app() -// .storage('gs://foo') -// .ref('foo') -// .putFile(''); -// -// task.on(firebase.storage.TaskEvent.STATE_CHANGED, taskSnapshot => { -// if (taskSnapshot.state === firebase.storage.TaskState.) { -// console.log('cancelling task!'); -// taskSnapshot.task.cancel(); -// } -// }); -// -// task.catch(e => { -// return 'bar'; -// }); -// -// task.then(snapshot => { -// snapshot.metadata.bucket; -// return 'foo'; -// }); -// -// firebase.storage.TaskState.CANCELLED; -// firebase.storage.TaskEvent.STATE_CHANGED; -// firebase.perf().newHttpMetric('', 'GET'); -// // firebase.functions.HttpsErrorCode.ABORTED; -// }; -// -// foo(); diff --git a/tsconfig.json b/tsconfig.json index 8a4137ae..75cfd6e7 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,7 @@ { - "include": ["packages/**/lib/*.d.ts", "packages/app-types/index.d.ts"], + "include": ["packages/**/lib/*.d.ts", "packages/**/type-test.ts"], "compilerOptions": { + "noEmit": true, "target": "es5", "module": "commonjs", "declaration": true,