diff --git a/.flowconfig b/.flowconfig index e3db9bc6..c297a19a 100644 --- a/.flowconfig +++ b/.flowconfig @@ -80,7 +80,6 @@ node_modules/fbjs/lib [libs] -lib/types/flow.js node_modules/react-native/Libraries/react-native/react-native-interface.js node_modules/react-native/flow node_modules/fbjs/flow/lib diff --git a/lib/modules/admob/index.js b/lib/modules/admob/index.js index 9aa0c7b9..2ca393cb 100644 --- a/lib/modules/admob/index.js +++ b/lib/modules/admob/index.js @@ -1,3 +1,7 @@ +/** + * @flow + * AdMob representation wrapper + */ import ModuleBase from './../../utils/ModuleBase'; import Interstitial from './Interstitial'; diff --git a/lib/modules/analytics/index.js b/lib/modules/analytics/index.js index f468759f..a66927eb 100644 --- a/lib/modules/analytics/index.js +++ b/lib/modules/analytics/index.js @@ -1,4 +1,7 @@ -// @flow +/** + * @flow + * Analytics representation wrapper + */ import ModuleBase from './../../utils/ModuleBase'; const AlphaNumericUnderscore = /^[a-zA-Z0-9_]+$/; @@ -116,3 +119,5 @@ export default class Analytics extends ModuleBase { } } } + +export const statics = {}; diff --git a/lib/modules/auth/User.js b/lib/modules/auth/User.js index 2fc7616e..c15f4f5d 100644 --- a/lib/modules/auth/User.js +++ b/lib/modules/auth/User.js @@ -5,6 +5,7 @@ import INTERNALS from '../../utils/internals'; import type Auth from './'; +import type { AuthCredential } from '../../types'; type NativeUser = { displayName?: string, diff --git a/lib/modules/auth/index.js b/lib/modules/auth/index.js index a13f0e91..67abfe8a 100644 --- a/lib/modules/auth/index.js +++ b/lib/modules/auth/index.js @@ -17,8 +17,14 @@ import FacebookAuthProvider from './providers/FacebookAuthProvider'; import PhoneAuthListener from './PhoneAuthListener'; +import type { AuthCredential } from '../../types'; import type FirebaseApp from '../core/firebase-app'; +type AuthResult = { + authenticated: boolean, + user: Object|null +} | null; + export default class Auth extends ModuleBase { static _NAMESPACE = 'auth'; static _NATIVE_MODULE = 'RNFirebaseAuth'; diff --git a/lib/modules/auth/providers/EmailAuthProvider.js b/lib/modules/auth/providers/EmailAuthProvider.js index b995687f..a82e3ffc 100644 --- a/lib/modules/auth/providers/EmailAuthProvider.js +++ b/lib/modules/auth/providers/EmailAuthProvider.js @@ -2,6 +2,8 @@ * @flow * EmailAuthProvider representation wrapper */ +import type { AuthCredential } from '../../../types'; + const providerId = 'password'; export default class EmailAuthProvider { diff --git a/lib/modules/auth/providers/FacebookAuthProvider.js b/lib/modules/auth/providers/FacebookAuthProvider.js index b60bf027..b6e12ad4 100644 --- a/lib/modules/auth/providers/FacebookAuthProvider.js +++ b/lib/modules/auth/providers/FacebookAuthProvider.js @@ -2,6 +2,8 @@ * @flow * FacebookAuthProvider representation wrapper */ +import type { AuthCredential } from '../../../types'; + const providerId = 'facebook.com'; export default class FacebookAuthProvider { diff --git a/lib/modules/auth/providers/GithubAuthProvider.js b/lib/modules/auth/providers/GithubAuthProvider.js index 4500ce40..aa89701f 100644 --- a/lib/modules/auth/providers/GithubAuthProvider.js +++ b/lib/modules/auth/providers/GithubAuthProvider.js @@ -2,6 +2,8 @@ * @flow * GithubAuthProvider representation wrapper */ +import type { AuthCredential } from '../../../types'; + const providerId = 'github.com'; export default class GithubAuthProvider { diff --git a/lib/modules/auth/providers/GoogleAuthProvider.js b/lib/modules/auth/providers/GoogleAuthProvider.js index 717aa0ce..a9fde23b 100644 --- a/lib/modules/auth/providers/GoogleAuthProvider.js +++ b/lib/modules/auth/providers/GoogleAuthProvider.js @@ -2,6 +2,8 @@ * @flow * EmailAuthProvider representation wrapper */ +import type { AuthCredential } from '../../../types'; + const providerId = 'google.com'; export default class GoogleAuthProvider { diff --git a/lib/modules/auth/providers/PhoneAuthProvider.js b/lib/modules/auth/providers/PhoneAuthProvider.js index 6ac1cc57..fb2ce8cb 100644 --- a/lib/modules/auth/providers/PhoneAuthProvider.js +++ b/lib/modules/auth/providers/PhoneAuthProvider.js @@ -2,6 +2,8 @@ * @flow * PhoneAuthProvider representation wrapper */ +import type { AuthCredential } from '../../../types'; + const providerId = 'phone'; export default class PhoneAuthProvider { diff --git a/lib/modules/auth/providers/TwitterAuthProvider.js b/lib/modules/auth/providers/TwitterAuthProvider.js index 7f6cf902..0f2c6dad 100644 --- a/lib/modules/auth/providers/TwitterAuthProvider.js +++ b/lib/modules/auth/providers/TwitterAuthProvider.js @@ -2,6 +2,8 @@ * @flow * TwitterAuthProvider representation wrapper */ +import type { AuthCredential } from '../../../types'; + const providerId = 'twitter.com'; export default class TwitterAuthProvider { diff --git a/lib/modules/config/index.js b/lib/modules/config/index.js index a78f6a1d..07562a37 100644 --- a/lib/modules/config/index.js +++ b/lib/modules/config/index.js @@ -139,3 +139,5 @@ export default class RemoteConfig extends ModuleBase { this._native.setDefaultsFromResource(resource); } } + +export const statics = {}; diff --git a/lib/modules/core/firebase-app.js b/lib/modules/core/firebase-app.js index efa40c39..a582385b 100644 --- a/lib/modules/core/firebase-app.js +++ b/lib/modules/core/firebase-app.js @@ -8,38 +8,58 @@ import { isObject, isAndroid } from '../../utils'; import AdMob, { statics as AdMobStatics } from '../admob'; import Auth, { statics as AuthStatics } from '../auth'; -import Analytics from '../analytics'; -import Crash from '../crash'; -import Performance from '../perf'; -import RemoteConfig from '../config'; -import Storage, { statics as StorageStatics } from '../storage'; +import Analytics, { statics as AnalyticsStatics } from '../analytics'; +import Config, { statics as ConfigStatics } from '../config'; +import Crash, { statics as CrashStatics } from '../crash'; import Database, { statics as DatabaseStatics } from '../database'; -import Messaging, { statics as MessagingStatics } from '../messaging'; import Firestore, { statics as FirestoreStatics } from '../firestore'; import Links, { statics as LinksStatics } from '../links'; +import Messaging, { statics as MessagingStatics } from '../messaging'; +import Performance, { statics as PerformanceStatics } from '../perf'; +import Storage, { statics as StorageStatics } from '../storage'; import Utils, { statics as UtilsStatics } from '../utils'; +import type { + AdMobModule, + AnalyticsModule, + AuthModule, + ConfigModule, + CrashModule, + DatabaseModule, + FirebaseModule, + FirebaseModuleAndStatics, + FirebaseOptions, + FirebaseStatics, + FirestoreModule, + LinksModule, + MessagingModule, + PerformanceModule, + StorageModule, + UtilsModule, +} from '../../types'; + const FirebaseCoreModule = NativeModules.RNFirebase; + export default class FirebaseApp { _extendedProps: { [string] : boolean }; _initialized: boolean; _name: string; - _namespaces: { [string]: Object }; + _namespaces: { [string]: FirebaseModule }; _nativeInitialized: boolean; _options: FirebaseOptions; - admob: () => AdMob; - auth: () => Auth; - analytics: () => Analytics; - config: () => RemoteConfig; - crash: () => Crash; - database: () => Database; - firestore: () => Firestore; - links: () => Links; - messaging: () => Messaging; - perf: () => Performance; - storage: () => Storage; - utils: () => Utils; + admob: AdMobModule; + analytics: AnalyticsModule; + auth: AuthModule; + config: ConfigModule; + crash: CrashModule; + database: DatabaseModule; + firestore: FirestoreModule; + links: LinksModule; + messaging: MessagingModule; + perf: PerformanceModule; + storage: StorageModule; + utils: UtilsModule; constructor(name: string, options: FirebaseOptions) { this._name = name; @@ -52,15 +72,15 @@ export default class FirebaseApp { // modules this.admob = this._staticsOrModuleInstance(AdMobStatics, AdMob); + this.analytics = this._staticsOrModuleInstance(AnalyticsStatics, Analytics); this.auth = this._staticsOrModuleInstance(AuthStatics, Auth); - this.analytics = this._staticsOrModuleInstance({}, Analytics); - this.config = this._staticsOrModuleInstance({}, RemoteConfig); - this.crash = this._staticsOrModuleInstance({}, Crash); + this.config = this._staticsOrModuleInstance(ConfigStatics, Config); + this.crash = this._staticsOrModuleInstance(CrashStatics, Crash); this.database = this._staticsOrModuleInstance(DatabaseStatics, Database); this.firestore = this._staticsOrModuleInstance(FirestoreStatics, Firestore); this.links = this._staticsOrModuleInstance(LinksStatics, Links); this.messaging = this._staticsOrModuleInstance(MessagingStatics, Messaging); - this.perf = this._staticsOrModuleInstance({}, Performance); + this.perf = this._staticsOrModuleInstance(PerformanceStatics, Performance); this.storage = this._staticsOrModuleInstance(StorageStatics, Storage); this.utils = this._staticsOrModuleInstance(UtilsStatics, Utils); this._extendedProps = {}; @@ -171,8 +191,8 @@ export default class FirebaseApp { * @return {function()} * @private */ - _staticsOrModuleInstance(statics: Object = {}, InstanceClass: Class<*>) { - const getInstance = () => { + _staticsOrModuleInstance(statics: S, InstanceClass: Class): FirebaseModuleAndStatics { + const getInstance = (): M => { const _name = `_${InstanceClass._NAMESPACE}`; if (isAndroid && InstanceClass._NAMESPACE !== Utils._NAMESPACE && !INTERNALS.FLAGS.checkedPlayServices) { @@ -187,10 +207,8 @@ export default class FirebaseApp { return this._namespaces[_name]; }; - Object.assign(getInstance, statics, { + return Object.assign(getInstance, statics, { nativeModuleExists: !!NativeModules[InstanceClass._NATIVE_MODULE], }); - - return getInstance; } } diff --git a/lib/modules/core/firebase.js b/lib/modules/core/firebase.js index b9a036f9..37e055c6 100644 --- a/lib/modules/core/firebase.js +++ b/lib/modules/core/firebase.js @@ -11,34 +11,53 @@ import { isObject, isString } from '../../utils'; // module imports import AdMob, { statics as AdMobStatics } from '../admob'; import Auth, { statics as AuthStatics } from '../auth'; -import Analytics from '../analytics'; -import Crash from '../crash'; -import Performance from '../perf'; -import Links, { statics as LinksStatics } from '../links'; -import RemoteConfig from '../config'; -import Storage, { statics as StorageStatics } from '../storage'; +import Analytics, { statics as AnalyticsStatics } from '../analytics'; +import Config, { statics as ConfigStatics } from '../config'; +import Crash, { statics as CrashStatics } from '../crash'; import Database, { statics as DatabaseStatics } from '../database'; -import Messaging, { statics as MessagingStatics } from '../messaging'; import Firestore, { statics as FirestoreStatics } from '../firestore'; +import Links, { statics as LinksStatics } from '../links'; +import Messaging, { statics as MessagingStatics } from '../messaging'; +import Performance, { statics as PerformanceStatics } from '../perf'; +import Storage, { statics as StorageStatics } from '../storage'; import Utils, { statics as UtilsStatics } from '../utils'; +import type { + AdMobModule, + AnalyticsModule, + AuthModule, + ConfigModule, + CrashModule, + DatabaseModule, + FirebaseModule, + FirebaseModuleAndStatics, + FirebaseOptions, + FirebaseStatics, + FirestoreModule, + LinksModule, + MessagingModule, + PerformanceModule, + StorageModule, + UtilsModule, +} from '../../types'; + const FirebaseCoreModule = NativeModules.RNFirebase; class FirebaseCore { _nativeEmitters: { [string]: NativeEventEmitter }; _nativeSubscriptions: { [string]: boolean }; - admob: () => AdMob; - auth: () => Auth; - analytics: () => Analytics; - config: () => RemoteConfig; - crash: () => Crash; - database: () => Database; - firestore: () => Firestore; - links: () => Links; - messaging: () => Messaging; - perf: () => Performance; - storage: () => Storage; - utils: () => Utils; + admob: AdMobModule; + analytics: AnalyticsModule; + auth: AuthModule; + config: ConfigModule; + crash: CrashModule; + database: DatabaseModule; + firestore: FirestoreModule; + links: LinksModule; + messaging: MessagingModule; + perf: PerformanceModule; + storage: StorageModule; + utils: UtilsModule; constructor() { this._nativeEmitters = {}; @@ -52,15 +71,15 @@ class FirebaseCore { // modules this.admob = this._appNamespaceOrStatics(AdMobStatics, AdMob); + this.analytics = this._appNamespaceOrStatics(AnalyticsStatics, Analytics); this.auth = this._appNamespaceOrStatics(AuthStatics, Auth); - this.analytics = this._appNamespaceOrStatics({}, Analytics); - this.config = this._appNamespaceOrStatics({}, RemoteConfig); - this.crash = this._appNamespaceOrStatics({}, Crash); + this.config = this._appNamespaceOrStatics(ConfigStatics, Config); + this.crash = this._appNamespaceOrStatics(CrashStatics, Crash); this.database = this._appNamespaceOrStatics(DatabaseStatics, Database); this.firestore = this._appNamespaceOrStatics(FirestoreStatics, Firestore); this.links = this._appNamespaceOrStatics(LinksStatics, Links); this.messaging = this._appNamespaceOrStatics(MessagingStatics, Messaging); - this.perf = this._appNamespaceOrStatics(DatabaseStatics, Performance); + this.perf = this._appNamespaceOrStatics(PerformanceStatics, Performance); this.storage = this._appNamespaceOrStatics(StorageStatics, Storage); this.utils = this._appNamespaceOrStatics(UtilsStatics, Utils); } @@ -160,7 +179,7 @@ class FirebaseCore { * A (read-only) array of all initialized apps. * @return {Array} */ - get apps(): Array { + get apps(): Array { return Object.values(INTERNALS.APPS); } @@ -201,7 +220,7 @@ class FirebaseCore { * @return {function(FirebaseApp=)} * @private */ - _appNamespaceOrStatics(statics: Object = {}, InstanceClass: Class<*>): Function { + _appNamespaceOrStatics(statics: S, InstanceClass: Class): FirebaseModuleAndStatics { const namespace = InstanceClass._NAMESPACE; const getNamespace = (app?: FirebaseApp) => { @@ -216,11 +235,9 @@ class FirebaseCore { return INTERNALS.APPS[_app._name][namespace](_app); }; - Object.assign(getNamespace, statics, { + return Object.assign(getNamespace, statics, { nativeModuleExists: !!NativeModules[InstanceClass._NATIVE_MODULE], }); - - return getNamespace; } /** diff --git a/lib/modules/crash/index.js b/lib/modules/crash/index.js index 2fa2ad74..70a677e7 100644 --- a/lib/modules/crash/index.js +++ b/lib/modules/crash/index.js @@ -1,5 +1,10 @@ -// @flow -import ModuleBase from './../../utils/ModuleBase'; +/** + * @flow + * Crash Reporting representation wrapper + */ +import ModuleBase from '../../utils/ModuleBase'; + +import type { FirebaseError } from '../../types'; export default class Crash extends ModuleBase { static _NAMESPACE = 'crash'; @@ -71,3 +76,5 @@ export default class Crash extends ModuleBase { this._native.report(errorMessage); } } + +export const statics = {}; diff --git a/lib/modules/database/query.js b/lib/modules/database/query.js index ce1e41b0..9cd75760 100644 --- a/lib/modules/database/query.js +++ b/lib/modules/database/query.js @@ -3,7 +3,9 @@ */ import Reference from './reference.js'; -import { objectToUniqueId } from './../../utils'; +import { objectToUniqueId } from '../../utils'; + +import type { DatabaseModifier } from '../../types'; // todo doc methods diff --git a/lib/modules/database/reference.js b/lib/modules/database/reference.js index c5ff9e2c..afed604a 100644 --- a/lib/modules/database/reference.js +++ b/lib/modules/database/reference.js @@ -5,7 +5,7 @@ import Query from './query.js'; import Snapshot from './snapshot'; import Disconnect from './disconnect'; -import ReferenceBase from './../../utils/ReferenceBase'; +import ReferenceBase from '../../utils/ReferenceBase'; import { promiseOrCallback, @@ -15,10 +15,12 @@ import { tryJSONParse, tryJSONStringify, generatePushID, -} from './../../utils'; +} from '../../utils'; import INTERNALS from '../../utils/internals'; +import type { DatabaseModifier, FirebaseError } from '../../types'; + // track all event registrations by path let listeners = 0; @@ -35,6 +37,13 @@ const ReferenceEventTypes = { child_moved: 'child_moved', }; +type DatabaseListener = { + listenerId: number; + eventName: string; + successCallback: Function; + failureCallback?: Function; +} + /** * @typedef {String} ReferenceLocation - Path to location in the database, relative * to the root reference. Consists of a path where segments are separated by a diff --git a/lib/modules/firestore/CollectionReference.js b/lib/modules/firestore/CollectionReference.js index 6a906be9..7b0794bf 100644 --- a/lib/modules/firestore/CollectionReference.js +++ b/lib/modules/firestore/CollectionReference.js @@ -7,6 +7,7 @@ import Query from './Query'; import { firestoreAutoId } from '../../utils'; import type Firestore from './'; +import type { FirestoreQueryDirection, FirestoreQueryOperator } from '../../types'; import type Path from './Path'; import type QuerySnapshot from './QuerySnapshot'; diff --git a/lib/modules/firestore/DocumentChange.js b/lib/modules/firestore/DocumentChange.js index ffcda39d..c0656d0a 100644 --- a/lib/modules/firestore/DocumentChange.js +++ b/lib/modules/firestore/DocumentChange.js @@ -5,6 +5,7 @@ import DocumentSnapshot from './DocumentSnapshot'; import type Firestore from './'; +import type { FirestoreNativeDocumentChange } from '../../types'; /** * @class DocumentChange diff --git a/lib/modules/firestore/DocumentReference.js b/lib/modules/firestore/DocumentReference.js index aff4d304..b47c88c6 100644 --- a/lib/modules/firestore/DocumentReference.js +++ b/lib/modules/firestore/DocumentReference.js @@ -8,6 +8,7 @@ import { buildNativeMap } from './utils/serialize'; import { firestoreAutoId, isFunction, isObject, isString } from '../../utils'; import type Firestore from './'; +import type { FirestoreNativeDocumentSnapshot, FirestoreWriteOptions } from '../../types'; import type Path from './Path'; type DocumentListenOptions = { diff --git a/lib/modules/firestore/DocumentSnapshot.js b/lib/modules/firestore/DocumentSnapshot.js index ab2bb378..dc74fe4c 100644 --- a/lib/modules/firestore/DocumentSnapshot.js +++ b/lib/modules/firestore/DocumentSnapshot.js @@ -7,6 +7,7 @@ import Path from './Path'; import { parseNativeMap } from './utils/serialize'; import type Firestore from './'; +import type { FirestoreNativeDocumentSnapshot, FirestoreSnapshotMetadata } from '../../types'; /** * @class DocumentSnapshot diff --git a/lib/modules/firestore/Query.js b/lib/modules/firestore/Query.js index 81561b47..507399ff 100644 --- a/lib/modules/firestore/Query.js +++ b/lib/modules/firestore/Query.js @@ -8,6 +8,7 @@ import { buildNativeArray, buildTypeMap } from './utils/serialize'; import { firestoreAutoId, isFunction, isObject } from '../../utils'; import type Firestore from './'; +import type { FirestoreQueryDirection, FirestoreQueryOperator } from '../../types'; import type Path from './Path'; const DIRECTIONS: { [FirestoreQueryDirection]: string } = { diff --git a/lib/modules/firestore/QuerySnapshot.js b/lib/modules/firestore/QuerySnapshot.js index 659815aa..67d57f5e 100644 --- a/lib/modules/firestore/QuerySnapshot.js +++ b/lib/modules/firestore/QuerySnapshot.js @@ -6,6 +6,7 @@ import DocumentChange from './DocumentChange'; import DocumentSnapshot from './DocumentSnapshot'; import type Firestore from './'; +import type { FirestoreNativeDocumentChange, FirestoreNativeDocumentSnapshot, FirestoreSnapshotMetadata } from '../../types'; import type Query from './Query'; type QuerySnapshotNativeData = { diff --git a/lib/modules/firestore/WriteBatch.js b/lib/modules/firestore/WriteBatch.js index 77318c3c..6d687ac9 100644 --- a/lib/modules/firestore/WriteBatch.js +++ b/lib/modules/firestore/WriteBatch.js @@ -7,6 +7,7 @@ import { isObject, isString } from '../../utils'; import type DocumentReference from './DocumentReference'; import type Firestore from './'; +import type { FirestoreWriteOptions } from '../../types'; type DocumentWrite = { data?: Object, diff --git a/lib/modules/firestore/index.js b/lib/modules/firestore/index.js index b1270c97..8d463a20 100644 --- a/lib/modules/firestore/index.js +++ b/lib/modules/firestore/index.js @@ -31,10 +31,7 @@ type DocumentSyncEvent = { path: string, } -/** - * @class Firestore - */ -export default class Firestore extends ModuleBase { +class FirestoreInternalModule extends ModuleBase { static _NAMESPACE = 'firestore'; static _NATIVE_MODULE = 'RNFirebaseFirestore'; @@ -44,14 +41,14 @@ export default class Firestore extends ModuleBase { super(firebaseApp, options, true); this._referencePath = new Path([]); - this.addListener( + super.addListener( // sub to internal native event - this fans out to // public event name: onCollectionSnapshot super._getAppEventName('firestore_collection_sync_event'), this._onCollectionSyncEvent.bind(this), ); - this.addListener( + super.addListener( // sub to internal native event - this fans out to // public event name: onDocumentSnapshot super._getAppEventName('firestore_document_sync_event'), @@ -59,58 +56,6 @@ export default class Firestore extends ModuleBase { ); } - batch(): WriteBatch { - return new WriteBatch(this); - } - - /** - * - * @param collectionPath - * @returns {CollectionReference} - */ - collection(collectionPath: string): CollectionReference { - const path = this._referencePath.child(collectionPath); - if (!path.isCollection) { - throw new Error('Argument "collectionPath" must point to a collection.'); - } - - return new CollectionReference(this, path); - } - - /** - * - * @param documentPath - * @returns {DocumentReference} - */ - doc(documentPath: string): DocumentReference { - const path = this._referencePath.child(documentPath); - if (!path.isDocument) { - throw new Error('Argument "documentPath" must point to a document.'); - } - - return new DocumentReference(this, path); - } - - enablePersistence(): Promise { - throw new Error('Persistence is enabled by default on the Firestore SDKs'); - } - - runTransaction(): Promise { - throw new Error('firebase.firestore().runTransaction() coming soon'); - } - - setLogLevel(): void { - throw new Error(INTERNALS.STRINGS.ERROR_UNSUPPORTED_MODULE_METHOD(Firestore, 'setLogLevel')); - } - - settings(): void { - throw new Error('firebase.firestore().settings() coming soon'); - } - - /** - * INTERNALS - */ - /** * Internal collection sync listener * @param event @@ -138,6 +83,63 @@ export default class Firestore extends ModuleBase { } } +/** + * @class Firestore + */ +export default class Firestore extends FirestoreInternalModule { + constructor(firebaseApp: FirebaseApp, options: Object = {}) { + super(firebaseApp, options); + } + + batch(): WriteBatch { + return new WriteBatch(this); + } + + /** + * + * @param collectionPath + * @returns {CollectionReference} + */ + collection(collectionPath: string): CollectionReference { + const path = super._referencePath.child(collectionPath); + if (!path.isCollection) { + throw new Error('Argument "collectionPath" must point to a collection.'); + } + + return new CollectionReference(this, path); + } + + /** + * + * @param documentPath + * @returns {DocumentReference} + */ + doc(documentPath: string): DocumentReference { + const path = super._referencePath.child(documentPath); + if (!path.isDocument) { + throw new Error('Argument "documentPath" must point to a document.'); + } + + return new DocumentReference(this, path); + } + + enablePersistence(): Promise { + throw new Error('Persistence is enabled by default on the Firestore SDKs'); + } + + runTransaction(): Promise { + throw new Error('firebase.firestore().runTransaction() coming soon'); + } + + setLogLevel(): void { + throw new Error(INTERNALS.STRINGS.ERROR_UNSUPPORTED_MODULE_METHOD(Firestore, 'setLogLevel')); + } + + settings(): void { + throw new Error('firebase.firestore().settings() coming soon'); + } +} + export const statics = { FieldValue, GeoPoint, diff --git a/lib/modules/firestore/utils/serialize.js b/lib/modules/firestore/utils/serialize.js index 74fd2697..a3ae0c50 100644 --- a/lib/modules/firestore/utils/serialize.js +++ b/lib/modules/firestore/utils/serialize.js @@ -9,6 +9,7 @@ import Path from '../Path'; import { typeOf } from '../../../utils'; import type Firestore from '../'; +import type { FirestoreTypeMap } from '../../../types'; /* * Functions that build up the data needed to represent diff --git a/lib/modules/perf/index.js b/lib/modules/perf/index.js index 3d25ecfb..496ce59a 100644 --- a/lib/modules/perf/index.js +++ b/lib/modules/perf/index.js @@ -29,3 +29,5 @@ export default class PerformanceMonitoring extends ModuleBase { return new Trace(this, trace); } } + +export const statics = {}; diff --git a/lib/modules/utils/index.js b/lib/modules/utils/index.js index 4054dc93..c7325462 100644 --- a/lib/modules/utils/index.js +++ b/lib/modules/utils/index.js @@ -5,11 +5,20 @@ import { NativeModules } from 'react-native'; import INTERNALS from '../../utils/internals'; import { isIOS } from '../../utils'; +import ModuleBase from '../../utils/ModuleBase'; import PACKAGE from '../../../package.json'; const FirebaseCoreModule = NativeModules.RNFirebase; -export default class RNFirebaseUtils { +type GoogleApiAvailabilityType = { + status: number, + isAvailable: boolean, + isUserResolvableError?: boolean, + hasResolution?: boolean, + error?: string +} + +export default class RNFirebaseUtils extends ModuleBase { static _NAMESPACE = 'utils'; static _NATIVE_DISABLED = true; static _NATIVE_MODULE = 'RNFirebaseUtils'; @@ -105,7 +114,7 @@ export default class RNFirebaseUtils { * @android * @param bool */ - set errorOnMissingPlayServices(bool: Boolean) { + set errorOnMissingPlayServices(bool: boolean) { INTERNALS.OPTIONS.errorOnMissingPlayServices = bool; } @@ -114,7 +123,7 @@ export default class RNFirebaseUtils { * @android * @param bool */ - set promptOnMissingPlayServices(bool: Boolean) { + set promptOnMissingPlayServices(bool: boolean) { INTERNALS.OPTIONS.promptOnMissingPlayServices = bool; } } diff --git a/lib/types/flow.js b/lib/types/flow.js deleted file mode 100644 index 71c478e8..00000000 --- a/lib/types/flow.js +++ /dev/null @@ -1,93 +0,0 @@ -/* eslint-disable */ -/* Core types */ -declare class FirebaseError { - message: string, - name: string, - code: string, - stack: string, - path: string, - details: string, - modifiers: string -}; - -declare type FirebaseOptions = { - apiKey: string, - appId: string, - databaseURL: string, - messagingSenderId: string, - projectId: string, - storageBucket: string, -} - -/* Auth types */ - -declare type AuthResult = { - authenticated: boolean, - user: Object|null -} | null; - -declare type AuthCredential = { - providerId: string, - token: string, - secret: string -}; - -/* Database types */ - -declare type DatabaseListener = { - listenerId: number; - eventName: string; - successCallback: Function; - failureCallback?: Function; -}; - -declare type DatabaseModifier = { - type: 'orderBy' | 'limit' | 'filter'; - name?: string; - key?: string; - limit?: number; - value?: any; - valueType?: string; -}; - -/* Firestore types */ - -declare type FirestoreNativeDocumentChange = { - document: FirestoreNativeDocumentSnapshot, - newIndex: number, - oldIndex: number, - type: string, -} - -declare type FirestoreNativeDocumentSnapshot = { - data: { [string]: FirestoreTypeMap }, - metadata: FirestoreSnapshotMetadata, - path: string, -} - -declare type FirestoreSnapshotMetadata = { - fromCache: boolean, - hasPendingWrites: boolean, -} - -declare type FirestoreQueryDirection = 'DESC' | 'desc' | 'ASC' | 'asc'; -declare type FirestoreQueryOperator = '<' | '<=' | '=' | '==' | '>' | '>='; - -declare type FirestoreTypeMap = { - type: 'array' | 'boolean' | 'date' | 'fieldvalue' | 'geopoint' | 'null' | 'number' | 'object' | 'reference' | 'string', - value: any, -} - -declare type FirestoreWriteOptions = { - merge?: boolean, -} - -/* Util types */ - -declare type GoogleApiAvailabilityType = { - status: number, - isAvailable: boolean, - isUserResolvableError?: boolean, - hasResolution?: boolean, - error?: string -}; diff --git a/lib/types/index.js b/lib/types/index.js new file mode 100644 index 00000000..40b53a3a --- /dev/null +++ b/lib/types/index.js @@ -0,0 +1,187 @@ +/* @flow */ +import type AdMob from '../modules/admob'; +import { typeof statics as AdMobStatics } from '../modules/admob'; +import type Analytics from '../modules/analytics'; +import { typeof statics as AnalyticsStatics } from '../modules/analytics'; +import type Auth from '../modules/auth'; +import { typeof statics as AuthStatics } from '../modules/auth'; +import type Config from '../modules/config'; +import { typeof statics as ConfigStatics } from '../modules/config'; +import type Crash from '../modules/crash'; +import { typeof statics as CrashStatics } from '../modules/crash'; +import type Database from '../modules/database'; +import { typeof statics as DatabaseStatics } from '../modules/database'; +import type Firestore from '../modules/firestore'; +import { typeof statics as FirestoreStatics } from '../modules/firestore'; +import type Links from '../modules/links'; +import { typeof statics as LinksStatics } from '../modules/links'; +import type Messaging from '../modules/messaging'; +import { typeof statics as MessagingStatics } from '../modules/messaging'; +import type ModuleBase from '../utils/ModuleBase'; +import type Performance from '../modules/perf'; +import { typeof statics as PerformanceStatics } from '../modules/perf'; +import type Storage from '../modules/storage'; +import { typeof statics as StorageStatics } from '../modules/storage'; +import type Utils from '../modules/utils'; +import { typeof statics as UtilsStatics } from '../modules/utils'; + +/* Core types */ +export type FirebaseError = { + message: string, + name: string, + code: string, + stack: string, + path: string, + details: string, + modifiers: string +} + +export type FirebaseModule = $Subtype; + +export type FirebaseModuleName = 'admob' | 'analytics' | 'auth' | 'config' | 'crash' | 'database' + | 'firestore' | 'links' | 'messaging' | 'perf' | 'storage' | 'utils'; + +export type FirebaseOptions = { + apiKey: string, + appId: string, + databaseURL: string, + messagingSenderId: string, + projectId: string, + storageBucket: string, +} + +export type FirebaseModuleAndStatics = { + (): M, + nativeModuleExists: boolean, +} & S; + +export type FirebaseStatics = $Subtype; + +/* Admob types */ + +export type AdMobModule = { + (): AdMob, + nativeModuleExists: boolean, +} & AdMobStatics; + +/* Analytics types */ + +export type AnalyticsModule = { + (): Analytics, + nativeModuleExists: boolean, +} & AnalyticsStatics; + +/* Remote Config types */ + +export type ConfigModule = { + (): Config, + nativeModuleExists: boolean, +} & ConfigStatics; + +export type AuthCredential = { + providerId: string, + token: string, + secret: string +} + +/* Auth types */ + +export type AuthModule = { + (): Auth, + nativeModuleExists: boolean, +} & AuthStatics; + +/* Crash types */ + +export type CrashModule = { + (): Crash, + nativeModuleExists: boolean, +} & CrashStatics; + +/* Database types */ + +export type DatabaseModule = { + (): Database, + nativeModuleExists: boolean, +} & DatabaseStatics; + +export type DatabaseModifier = { + type: 'orderBy' | 'limit' | 'filter'; + name?: string; + key?: string; + limit?: number; + value?: any; + valueType?: string; +} + +/* Firestore types */ + +export type FirestoreModule = { + (): Firestore, + nativeModuleExists: boolean, +} & FirestoreStatics; + +export type FirestoreNativeDocumentChange = { + document: FirestoreNativeDocumentSnapshot, + newIndex: number, + oldIndex: number, + type: string, +} + +export type FirestoreNativeDocumentSnapshot = { + data: { [string]: FirestoreTypeMap }, + metadata: FirestoreSnapshotMetadata, + path: string, +} + +export type FirestoreSnapshotMetadata = { + fromCache: boolean, + hasPendingWrites: boolean, +} + +export type FirestoreQueryDirection = 'DESC' | 'desc' | 'ASC' | 'asc'; +export type FirestoreQueryOperator = '<' | '<=' | '=' | '==' | '>' | '>='; + +export type FirestoreTypeMap = { + type: 'array' | 'boolean' | 'date' | 'fieldvalue' | 'geopoint' | 'null' | 'number' | 'object' | 'reference' | 'string', + value: any, +} + +export type FirestoreWriteOptions = { + merge?: boolean, +} + +/* Links types */ + +export type LinksModule = { + (): Links, + nativeModuleExists: boolean, +} & LinksStatics; + +/* Messaging types */ + +export type MessagingModule = { + (): Messaging, + nativeModuleExists: boolean, +} & MessagingStatics; + +/* Performance types */ + +export type PerformanceModule = { + (): Performance, + nativeModuleExists: boolean, +} & PerformanceStatics; + +/* Storage types */ + +export type StorageModule = { + (): Storage, + nativeModuleExists: boolean, +} & StorageStatics; + +/* Utils types */ + +export type UtilsModule = { + (): Utils, + nativeModuleExists: boolean, +} & UtilsStatics; diff --git a/lib/utils/ModuleBase.js b/lib/utils/ModuleBase.js index bbb0042d..5bed12a6 100644 --- a/lib/utils/ModuleBase.js +++ b/lib/utils/ModuleBase.js @@ -9,6 +9,7 @@ import FirebaseCore from '../modules/core/firebase'; import { nativeWithApp } from '../utils'; import type FirebaseApp from '../modules/core/firebase-app'; +import type { FirebaseModuleName } from '../types'; const logs = {}; @@ -53,7 +54,7 @@ export default class ModuleBase { _namespace: string; _firebaseApp: FirebaseApp; _eventEmitter: Object; - static _NAMESPACE: string; + static _NAMESPACE: FirebaseModuleName; static _NATIVE_MODULE: string; /** diff --git a/lib/utils/SyncTree.js b/lib/utils/SyncTree.js index d8349ef4..6cd4acb1 100644 --- a/lib/utils/SyncTree.js +++ b/lib/utils/SyncTree.js @@ -3,10 +3,10 @@ */ import { NativeEventEmitter } from 'react-native'; -import INTERNALS from './../internals'; -import DatabaseSnapshot from './../modules/database/snapshot'; -import DatabaseReference from './../modules/database/reference'; -import { isString, nativeToJSError } from './../utils'; +import INTERNALS from './internals'; +import DatabaseSnapshot from '../modules/database/snapshot'; +import DatabaseReference from '../modules/database/reference'; +import { isString, nativeToJSError } from '../utils'; type Registration = { key: string, diff --git a/lib/utils/internals.js b/lib/utils/internals.js index 87cd42b2..efab8da1 100644 --- a/lib/utils/internals.js +++ b/lib/utils/internals.js @@ -7,6 +7,8 @@ import EventEmitter from './emitter/EventEmitter'; import ModuleBase from './ModuleBase'; import SyncTree from './SyncTree'; +import type FirebaseApp from '../modules/core/firebase-app'; + const DEFAULT_APP_NAME = Platform.OS === 'ios' ? '__FIRAPP_DEFAULT' : '[DEFAULT]'; const NAMESPACE_PODS = { @@ -53,6 +55,8 @@ const PLAY_SERVICES_CODES = { }, }; +const APPS: { [string]: FirebaseApp } = {}; + export default { // default options OPTIONS: { @@ -66,9 +70,7 @@ export default { }, // track all initialized firebase apps - APPS: { - [DEFAULT_APP_NAME]: null, - }, + APPS, STRINGS: { WARN_INITIALIZE_DEPRECATION: 'Deprecation: Calling \'initializeApp()\' for apps that are already initialised natively ' + diff --git a/package-lock.json b/package-lock.json index df11263f..ba380f04 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "react-native-firebase", - "version": "3.1.0", + "version": "3.1.1-alpha.11", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index ac77b3dd..f3663876 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-firebase", - "version": "3.1.1-alpha.4", + "version": "3.1.1-alpha.11", "author": "Invertase (http://invertase.io)", "description": "A well tested, feature rich Firebase implementation for React Native, supporting iOS & Android. Individual module support for Admob, Analytics, Auth, Crash Reporting, Cloud Firestore, Database, Dynamic Links, Messaging (FCM), Remote Config, Storage and Performance.", "main": "dist/index.js", @@ -20,9 +20,6 @@ "tests-watch-start": "npm run test-cli watch init start", "tests-watch-stop": "npm run test-cli watch stop" }, - "files": [ - "dist" - ], "repository": { "type": "git", "url": "https://github.com/invertase/react-native-firebase.git" diff --git a/tests/ios/Podfile.lock b/tests/ios/Podfile.lock index f6bb69d9..71d4438c 100644 --- a/tests/ios/Podfile.lock +++ b/tests/ios/Podfile.lock @@ -150,7 +150,7 @@ PODS: - React/Core - React/fishhook - React/RCTBlob - - RNFirebase (3.1.0): + - RNFirebase (3.1.1-alpha.11): - React - yoga (0.49.1.React) @@ -208,7 +208,7 @@ SPEC CHECKSUMS: nanopb: 5601e6bca2dbf1ed831b519092ec110f66982ca3 Protobuf: 03eef2ee0b674770735cf79d9c4d3659cf6908e8 React: cf892fb84b7d06bf5fea7f328e554c6dcabe85ee - RNFirebase: 1b8adf4dfe740fbc4a69a147715c2edfd041eb92 + RNFirebase: e959075eb2f348c3586cd92973543b80e373b29c yoga: 3abf02d6d9aeeb139b4c930eb1367feae690a35a PODFILE CHECKSUM: b5674be55653f5dda937c8b794d0479900643d45