react-native-firebase/lib/modules/core/firebase.js

225 lines
5.1 KiB
JavaScript
Raw Normal View History

2017-03-02 13:10:10 +00:00
/**
* @flow
*/
import { NativeModules } from 'react-native';
2017-03-02 13:10:10 +00:00
import APPS from '../../utils/apps';
import INTERNALS from '../../utils/internals';
import App from './app';
2018-01-09 17:31:54 +00:00
import VERSION from '../../version';
// module imports
2018-01-25 18:25:39 +00:00
import {
statics as AdMobStatics,
MODULE_NAME as AdmobModuleName,
} from '../admob';
import { statics as AuthStatics, MODULE_NAME as AuthModuleName } from '../auth';
2018-01-25 18:25:39 +00:00
import {
statics as AnalyticsStatics,
MODULE_NAME as AnalyticsModuleName,
} from '../analytics';
import {
statics as ConfigStatics,
MODULE_NAME as ConfigModuleName,
} from '../config';
import {
statics as CrashStatics,
MODULE_NAME as CrashModuleName,
} from '../crash';
import {
statics as CrashlyticsStatics,
MODULE_NAME as CrashlyticsModuleName,
} from '../crashlytics';
2018-01-25 18:25:39 +00:00
import {
statics as DatabaseStatics,
MODULE_NAME as DatabaseModuleName,
} from '../database';
import {
statics as FirestoreStatics,
MODULE_NAME as FirestoreModuleName,
} from '../firestore';
import {
statics as InstanceIdStatics,
MODULE_NAME as InstanceIdModuleName,
2018-03-23 14:59:00 +00:00
} from '../iid';
import {
statics as InvitesStatics,
MODULE_NAME as InvitesModuleName,
} from '../invites';
2018-01-25 18:25:39 +00:00
import {
statics as LinksStatics,
MODULE_NAME as LinksModuleName,
} from '../links';
import {
statics as MessagingStatics,
MODULE_NAME as MessagingModuleName,
} from '../messaging';
import {
statics as NotificationsStatics,
MODULE_NAME as NotificationsModuleName,
} from '../notifications';
2018-01-25 18:25:39 +00:00
import {
statics as PerformanceStatics,
MODULE_NAME as PerfModuleName,
} from '../perf';
import {
statics as StorageStatics,
MODULE_NAME as StorageModuleName,
} from '../storage';
import {
statics as UtilsStatics,
MODULE_NAME as UtilsModuleName,
} from '../utils';
2017-11-23 17:29:40 +00:00
import type {
AdMobModule,
AnalyticsModule,
AuthModule,
ConfigModule,
CrashModule,
CrashlyticsModule,
2017-11-23 17:29:40 +00:00
DatabaseModule,
FirebaseOptions,
FirestoreModule,
InstanceIdModule,
InvitesModule,
2017-11-23 17:29:40 +00:00
LinksModule,
MessagingModule,
NotificationsModule,
2017-11-23 17:29:40 +00:00
PerformanceModule,
StorageModule,
UtilsModule,
} from '../../types';
const FirebaseCoreModule = NativeModules.RNFirebase;
2017-03-02 13:10:10 +00:00
class Firebase {
2017-11-23 17:29:40 +00:00
admob: AdMobModule;
analytics: AnalyticsModule;
auth: AuthModule;
config: ConfigModule;
crash: CrashModule;
crashlytics: CrashlyticsModule;
2017-11-23 17:29:40 +00:00
database: DatabaseModule;
firestore: FirestoreModule;
2018-03-23 14:59:00 +00:00
iid: InstanceIdModule;
invites: InvitesModule;
2017-11-23 17:29:40 +00:00
links: LinksModule;
messaging: MessagingModule;
notifications: NotificationsModule;
2017-11-23 17:29:40 +00:00
perf: PerformanceModule;
storage: StorageModule;
utils: UtilsModule;
constructor() {
if (!FirebaseCoreModule) {
2018-01-25 18:25:39 +00:00
throw new Error(INTERNALS.STRINGS.ERROR_MISSING_CORE);
}
APPS.initializeNativeApps();
2017-07-18 05:04:12 +00:00
// modules
this.admob = APPS.moduleAndStatics('admob', AdMobStatics, AdmobModuleName);
2018-01-25 18:25:39 +00:00
this.analytics = APPS.moduleAndStatics(
'analytics',
AnalyticsStatics,
AnalyticsModuleName
);
this.auth = APPS.moduleAndStatics('auth', AuthStatics, AuthModuleName);
2018-01-25 18:25:39 +00:00
this.config = APPS.moduleAndStatics(
'config',
ConfigStatics,
ConfigModuleName
);
this.crash = APPS.moduleAndStatics('crash', CrashStatics, CrashModuleName);
this.crashlytics = APPS.moduleAndStatics(
'crashlytics',
CrashlyticsStatics,
CrashlyticsModuleName
);
2018-01-25 18:25:39 +00:00
this.database = APPS.moduleAndStatics(
'database',
DatabaseStatics,
DatabaseModuleName
);
this.firestore = APPS.moduleAndStatics(
'firestore',
FirestoreStatics,
FirestoreModuleName
);
2018-03-23 14:59:00 +00:00
this.iid = APPS.moduleAndStatics(
'iid',
InstanceIdStatics,
InstanceIdModuleName
);
this.invites = APPS.moduleAndStatics(
'invites',
InvitesStatics,
InvitesModuleName
);
this.links = APPS.moduleAndStatics('links', LinksStatics, LinksModuleName);
2018-01-25 18:25:39 +00:00
this.messaging = APPS.moduleAndStatics(
'messaging',
MessagingStatics,
MessagingModuleName
);
this.notifications = APPS.moduleAndStatics(
'notifications',
NotificationsStatics,
NotificationsModuleName
);
2018-01-25 18:25:39 +00:00
this.perf = APPS.moduleAndStatics(
'perf',
PerformanceStatics,
PerfModuleName
);
this.storage = APPS.moduleAndStatics(
'storage',
StorageStatics,
StorageModuleName
);
this.utils = APPS.moduleAndStatics('utils', UtilsStatics, UtilsModuleName);
}
2017-04-04 16:58:20 +00:00
2017-03-02 13:10:10 +00:00
/**
* Web SDK initializeApp
2017-03-02 13:10:10 +00:00
*
* @param options
* @param name
* @return {*}
2017-03-02 13:10:10 +00:00
*/
initializeApp(options: FirebaseOptions, name: string): App {
return APPS.initializeApp(options, name);
2017-03-02 13:10:10 +00:00
}
/**
* Retrieves a Firebase app instance.
*
* When called with no arguments, the default app is returned.
* When an app name is provided, the app corresponding to that name is returned.
*
2017-03-02 13:10:10 +00:00
* @param name
* @return {*}
2017-03-02 13:10:10 +00:00
*/
app(name?: string): App {
return APPS.app(name);
}
2017-03-02 13:10:10 +00:00
/**
* A (read-only) array of all initialized apps.
* @return {Array}
*/
get apps(): Array<App> {
return APPS.apps();
}
2018-01-09 17:31:54 +00:00
/**
* The current SDK version.
* @return {string}
*/
get SDK_VERSION(): string {
return VERSION;
}
2017-03-02 13:10:10 +00:00
}
export default new Firebase();