Merge remote-tracking branch 'origin/master'

This commit is contained in:
Salakar 2017-11-28 12:27:43 +00:00
commit 8abc544ac3
36 changed files with 406 additions and 209 deletions

View File

@ -80,7 +80,6 @@
node_modules/fbjs/lib node_modules/fbjs/lib
[libs] [libs]
lib/types/flow.js
node_modules/react-native/Libraries/react-native/react-native-interface.js node_modules/react-native/Libraries/react-native/react-native-interface.js
node_modules/react-native/flow node_modules/react-native/flow
node_modules/fbjs/flow/lib node_modules/fbjs/flow/lib

View File

@ -1,3 +1,7 @@
/**
* @flow
* AdMob representation wrapper
*/
import ModuleBase from './../../utils/ModuleBase'; import ModuleBase from './../../utils/ModuleBase';
import Interstitial from './Interstitial'; import Interstitial from './Interstitial';

View File

@ -1,4 +1,7 @@
// @flow /**
* @flow
* Analytics representation wrapper
*/
import ModuleBase from './../../utils/ModuleBase'; import ModuleBase from './../../utils/ModuleBase';
const AlphaNumericUnderscore = /^[a-zA-Z0-9_]+$/; const AlphaNumericUnderscore = /^[a-zA-Z0-9_]+$/;
@ -116,3 +119,5 @@ export default class Analytics extends ModuleBase {
} }
} }
} }
export const statics = {};

View File

@ -5,6 +5,7 @@
import INTERNALS from '../../utils/internals'; import INTERNALS from '../../utils/internals';
import type Auth from './'; import type Auth from './';
import type { AuthCredential } from '../../types';
type NativeUser = { type NativeUser = {
displayName?: string, displayName?: string,

View File

@ -17,8 +17,14 @@ import FacebookAuthProvider from './providers/FacebookAuthProvider';
import PhoneAuthListener from './PhoneAuthListener'; import PhoneAuthListener from './PhoneAuthListener';
import type { AuthCredential } from '../../types';
import type FirebaseApp from '../core/firebase-app'; import type FirebaseApp from '../core/firebase-app';
type AuthResult = {
authenticated: boolean,
user: Object|null
} | null;
export default class Auth extends ModuleBase { export default class Auth extends ModuleBase {
static _NAMESPACE = 'auth'; static _NAMESPACE = 'auth';
static _NATIVE_MODULE = 'RNFirebaseAuth'; static _NATIVE_MODULE = 'RNFirebaseAuth';

View File

@ -2,6 +2,8 @@
* @flow * @flow
* EmailAuthProvider representation wrapper * EmailAuthProvider representation wrapper
*/ */
import type { AuthCredential } from '../../../types';
const providerId = 'password'; const providerId = 'password';
export default class EmailAuthProvider { export default class EmailAuthProvider {

View File

@ -2,6 +2,8 @@
* @flow * @flow
* FacebookAuthProvider representation wrapper * FacebookAuthProvider representation wrapper
*/ */
import type { AuthCredential } from '../../../types';
const providerId = 'facebook.com'; const providerId = 'facebook.com';
export default class FacebookAuthProvider { export default class FacebookAuthProvider {

View File

@ -2,6 +2,8 @@
* @flow * @flow
* GithubAuthProvider representation wrapper * GithubAuthProvider representation wrapper
*/ */
import type { AuthCredential } from '../../../types';
const providerId = 'github.com'; const providerId = 'github.com';
export default class GithubAuthProvider { export default class GithubAuthProvider {

View File

@ -2,6 +2,8 @@
* @flow * @flow
* EmailAuthProvider representation wrapper * EmailAuthProvider representation wrapper
*/ */
import type { AuthCredential } from '../../../types';
const providerId = 'google.com'; const providerId = 'google.com';
export default class GoogleAuthProvider { export default class GoogleAuthProvider {

View File

@ -2,6 +2,8 @@
* @flow * @flow
* PhoneAuthProvider representation wrapper * PhoneAuthProvider representation wrapper
*/ */
import type { AuthCredential } from '../../../types';
const providerId = 'phone'; const providerId = 'phone';
export default class PhoneAuthProvider { export default class PhoneAuthProvider {

View File

@ -2,6 +2,8 @@
* @flow * @flow
* TwitterAuthProvider representation wrapper * TwitterAuthProvider representation wrapper
*/ */
import type { AuthCredential } from '../../../types';
const providerId = 'twitter.com'; const providerId = 'twitter.com';
export default class TwitterAuthProvider { export default class TwitterAuthProvider {

View File

@ -139,3 +139,5 @@ export default class RemoteConfig extends ModuleBase {
this._native.setDefaultsFromResource(resource); this._native.setDefaultsFromResource(resource);
} }
} }
export const statics = {};

View File

@ -8,38 +8,58 @@ import { isObject, isAndroid } from '../../utils';
import AdMob, { statics as AdMobStatics } from '../admob'; import AdMob, { statics as AdMobStatics } from '../admob';
import Auth, { statics as AuthStatics } from '../auth'; import Auth, { statics as AuthStatics } from '../auth';
import Analytics from '../analytics'; import Analytics, { statics as AnalyticsStatics } from '../analytics';
import Crash from '../crash'; import Config, { statics as ConfigStatics } from '../config';
import Performance from '../perf'; import Crash, { statics as CrashStatics } from '../crash';
import RemoteConfig from '../config';
import Storage, { statics as StorageStatics } from '../storage';
import Database, { statics as DatabaseStatics } from '../database'; import Database, { statics as DatabaseStatics } from '../database';
import Messaging, { statics as MessagingStatics } from '../messaging';
import Firestore, { statics as FirestoreStatics } from '../firestore'; import Firestore, { statics as FirestoreStatics } from '../firestore';
import Links, { statics as LinksStatics } from '../links'; 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 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; const FirebaseCoreModule = NativeModules.RNFirebase;
export default class FirebaseApp { export default class FirebaseApp {
_extendedProps: { [string] : boolean }; _extendedProps: { [string] : boolean };
_initialized: boolean; _initialized: boolean;
_name: string; _name: string;
_namespaces: { [string]: Object }; _namespaces: { [string]: FirebaseModule };
_nativeInitialized: boolean; _nativeInitialized: boolean;
_options: FirebaseOptions; _options: FirebaseOptions;
admob: () => AdMob; admob: AdMobModule;
auth: () => Auth; analytics: AnalyticsModule;
analytics: () => Analytics; auth: AuthModule;
config: () => RemoteConfig; config: ConfigModule;
crash: () => Crash; crash: CrashModule;
database: () => Database; database: DatabaseModule;
firestore: () => Firestore; firestore: FirestoreModule;
links: () => Links; links: LinksModule;
messaging: () => Messaging; messaging: MessagingModule;
perf: () => Performance; perf: PerformanceModule;
storage: () => Storage; storage: StorageModule;
utils: () => Utils; utils: UtilsModule;
constructor(name: string, options: FirebaseOptions) { constructor(name: string, options: FirebaseOptions) {
this._name = name; this._name = name;
@ -52,15 +72,15 @@ export default class FirebaseApp {
// modules // modules
this.admob = this._staticsOrModuleInstance(AdMobStatics, AdMob); this.admob = this._staticsOrModuleInstance(AdMobStatics, AdMob);
this.analytics = this._staticsOrModuleInstance(AnalyticsStatics, Analytics);
this.auth = this._staticsOrModuleInstance(AuthStatics, Auth); this.auth = this._staticsOrModuleInstance(AuthStatics, Auth);
this.analytics = this._staticsOrModuleInstance({}, Analytics); this.config = this._staticsOrModuleInstance(ConfigStatics, Config);
this.config = this._staticsOrModuleInstance({}, RemoteConfig); this.crash = this._staticsOrModuleInstance(CrashStatics, Crash);
this.crash = this._staticsOrModuleInstance({}, Crash);
this.database = this._staticsOrModuleInstance(DatabaseStatics, Database); this.database = this._staticsOrModuleInstance(DatabaseStatics, Database);
this.firestore = this._staticsOrModuleInstance(FirestoreStatics, Firestore); this.firestore = this._staticsOrModuleInstance(FirestoreStatics, Firestore);
this.links = this._staticsOrModuleInstance(LinksStatics, Links); this.links = this._staticsOrModuleInstance(LinksStatics, Links);
this.messaging = this._staticsOrModuleInstance(MessagingStatics, Messaging); this.messaging = this._staticsOrModuleInstance(MessagingStatics, Messaging);
this.perf = this._staticsOrModuleInstance({}, Performance); this.perf = this._staticsOrModuleInstance(PerformanceStatics, Performance);
this.storage = this._staticsOrModuleInstance(StorageStatics, Storage); this.storage = this._staticsOrModuleInstance(StorageStatics, Storage);
this.utils = this._staticsOrModuleInstance(UtilsStatics, Utils); this.utils = this._staticsOrModuleInstance(UtilsStatics, Utils);
this._extendedProps = {}; this._extendedProps = {};
@ -171,8 +191,8 @@ export default class FirebaseApp {
* @return {function()} * @return {function()}
* @private * @private
*/ */
_staticsOrModuleInstance(statics: Object = {}, InstanceClass: Class<*>) { _staticsOrModuleInstance<M: FirebaseModule, S:FirebaseStatics>(statics: S, InstanceClass: Class<M>): FirebaseModuleAndStatics<M, S> {
const getInstance = () => { const getInstance = (): M => {
const _name = `_${InstanceClass._NAMESPACE}`; const _name = `_${InstanceClass._NAMESPACE}`;
if (isAndroid && InstanceClass._NAMESPACE !== Utils._NAMESPACE && !INTERNALS.FLAGS.checkedPlayServices) { if (isAndroid && InstanceClass._NAMESPACE !== Utils._NAMESPACE && !INTERNALS.FLAGS.checkedPlayServices) {
@ -187,10 +207,8 @@ export default class FirebaseApp {
return this._namespaces[_name]; return this._namespaces[_name];
}; };
Object.assign(getInstance, statics, { return Object.assign(getInstance, statics, {
nativeModuleExists: !!NativeModules[InstanceClass._NATIVE_MODULE], nativeModuleExists: !!NativeModules[InstanceClass._NATIVE_MODULE],
}); });
return getInstance;
} }
} }

View File

@ -11,34 +11,53 @@ import { isObject, isString } from '../../utils';
// module imports // module imports
import AdMob, { statics as AdMobStatics } from '../admob'; import AdMob, { statics as AdMobStatics } from '../admob';
import Auth, { statics as AuthStatics } from '../auth'; import Auth, { statics as AuthStatics } from '../auth';
import Analytics from '../analytics'; import Analytics, { statics as AnalyticsStatics } from '../analytics';
import Crash from '../crash'; import Config, { statics as ConfigStatics } from '../config';
import Performance from '../perf'; import Crash, { statics as CrashStatics } from '../crash';
import Links, { statics as LinksStatics } from '../links';
import RemoteConfig from '../config';
import Storage, { statics as StorageStatics } from '../storage';
import Database, { statics as DatabaseStatics } from '../database'; import Database, { statics as DatabaseStatics } from '../database';
import Messaging, { statics as MessagingStatics } from '../messaging';
import Firestore, { statics as FirestoreStatics } from '../firestore'; 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 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; const FirebaseCoreModule = NativeModules.RNFirebase;
class FirebaseCore { class FirebaseCore {
_nativeEmitters: { [string]: NativeEventEmitter }; _nativeEmitters: { [string]: NativeEventEmitter };
_nativeSubscriptions: { [string]: boolean }; _nativeSubscriptions: { [string]: boolean };
admob: () => AdMob; admob: AdMobModule;
auth: () => Auth; analytics: AnalyticsModule;
analytics: () => Analytics; auth: AuthModule;
config: () => RemoteConfig; config: ConfigModule;
crash: () => Crash; crash: CrashModule;
database: () => Database; database: DatabaseModule;
firestore: () => Firestore; firestore: FirestoreModule;
links: () => Links; links: LinksModule;
messaging: () => Messaging; messaging: MessagingModule;
perf: () => Performance; perf: PerformanceModule;
storage: () => Storage; storage: StorageModule;
utils: () => Utils; utils: UtilsModule;
constructor() { constructor() {
this._nativeEmitters = {}; this._nativeEmitters = {};
@ -52,15 +71,15 @@ class FirebaseCore {
// modules // modules
this.admob = this._appNamespaceOrStatics(AdMobStatics, AdMob); this.admob = this._appNamespaceOrStatics(AdMobStatics, AdMob);
this.analytics = this._appNamespaceOrStatics(AnalyticsStatics, Analytics);
this.auth = this._appNamespaceOrStatics(AuthStatics, Auth); this.auth = this._appNamespaceOrStatics(AuthStatics, Auth);
this.analytics = this._appNamespaceOrStatics({}, Analytics); this.config = this._appNamespaceOrStatics(ConfigStatics, Config);
this.config = this._appNamespaceOrStatics({}, RemoteConfig); this.crash = this._appNamespaceOrStatics(CrashStatics, Crash);
this.crash = this._appNamespaceOrStatics({}, Crash);
this.database = this._appNamespaceOrStatics(DatabaseStatics, Database); this.database = this._appNamespaceOrStatics(DatabaseStatics, Database);
this.firestore = this._appNamespaceOrStatics(FirestoreStatics, Firestore); this.firestore = this._appNamespaceOrStatics(FirestoreStatics, Firestore);
this.links = this._appNamespaceOrStatics(LinksStatics, Links); this.links = this._appNamespaceOrStatics(LinksStatics, Links);
this.messaging = this._appNamespaceOrStatics(MessagingStatics, Messaging); 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.storage = this._appNamespaceOrStatics(StorageStatics, Storage);
this.utils = this._appNamespaceOrStatics(UtilsStatics, Utils); this.utils = this._appNamespaceOrStatics(UtilsStatics, Utils);
} }
@ -160,7 +179,7 @@ class FirebaseCore {
* A (read-only) array of all initialized apps. * A (read-only) array of all initialized apps.
* @return {Array} * @return {Array}
*/ */
get apps(): Array<Object> { get apps(): Array<FirebaseApp> {
return Object.values(INTERNALS.APPS); return Object.values(INTERNALS.APPS);
} }
@ -201,7 +220,7 @@ class FirebaseCore {
* @return {function(FirebaseApp=)} * @return {function(FirebaseApp=)}
* @private * @private
*/ */
_appNamespaceOrStatics(statics: Object = {}, InstanceClass: Class<*>): Function { _appNamespaceOrStatics<M: FirebaseModule, S: FirebaseStatics>(statics: S, InstanceClass: Class<M>): FirebaseModuleAndStatics<M, S> {
const namespace = InstanceClass._NAMESPACE; const namespace = InstanceClass._NAMESPACE;
const getNamespace = (app?: FirebaseApp) => { const getNamespace = (app?: FirebaseApp) => {
@ -216,11 +235,9 @@ class FirebaseCore {
return INTERNALS.APPS[_app._name][namespace](_app); return INTERNALS.APPS[_app._name][namespace](_app);
}; };
Object.assign(getNamespace, statics, { return Object.assign(getNamespace, statics, {
nativeModuleExists: !!NativeModules[InstanceClass._NATIVE_MODULE], nativeModuleExists: !!NativeModules[InstanceClass._NATIVE_MODULE],
}); });
return getNamespace;
} }
/** /**

View File

@ -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 { export default class Crash extends ModuleBase {
static _NAMESPACE = 'crash'; static _NAMESPACE = 'crash';
@ -71,3 +76,5 @@ export default class Crash extends ModuleBase {
this._native.report(errorMessage); this._native.report(errorMessage);
} }
} }
export const statics = {};

View File

@ -3,7 +3,9 @@
*/ */
import Reference from './reference.js'; import Reference from './reference.js';
import { objectToUniqueId } from './../../utils'; import { objectToUniqueId } from '../../utils';
import type { DatabaseModifier } from '../../types';
// todo doc methods // todo doc methods

View File

@ -5,7 +5,7 @@
import Query from './query.js'; import Query from './query.js';
import Snapshot from './snapshot'; import Snapshot from './snapshot';
import Disconnect from './disconnect'; import Disconnect from './disconnect';
import ReferenceBase from './../../utils/ReferenceBase'; import ReferenceBase from '../../utils/ReferenceBase';
import { import {
promiseOrCallback, promiseOrCallback,
@ -15,10 +15,12 @@ import {
tryJSONParse, tryJSONParse,
tryJSONStringify, tryJSONStringify,
generatePushID, generatePushID,
} from './../../utils'; } from '../../utils';
import INTERNALS from '../../utils/internals'; import INTERNALS from '../../utils/internals';
import type { DatabaseModifier, FirebaseError } from '../../types';
// track all event registrations by path // track all event registrations by path
let listeners = 0; let listeners = 0;
@ -35,6 +37,13 @@ const ReferenceEventTypes = {
child_moved: 'child_moved', child_moved: 'child_moved',
}; };
type DatabaseListener = {
listenerId: number;
eventName: string;
successCallback: Function;
failureCallback?: Function;
}
/** /**
* @typedef {String} ReferenceLocation - Path to location in the database, relative * @typedef {String} ReferenceLocation - Path to location in the database, relative
* to the root reference. Consists of a path where segments are separated by a * to the root reference. Consists of a path where segments are separated by a

View File

@ -7,6 +7,7 @@ import Query from './Query';
import { firestoreAutoId } from '../../utils'; import { firestoreAutoId } from '../../utils';
import type Firestore from './'; import type Firestore from './';
import type { FirestoreQueryDirection, FirestoreQueryOperator } from '../../types';
import type Path from './Path'; import type Path from './Path';
import type QuerySnapshot from './QuerySnapshot'; import type QuerySnapshot from './QuerySnapshot';

View File

@ -5,6 +5,7 @@
import DocumentSnapshot from './DocumentSnapshot'; import DocumentSnapshot from './DocumentSnapshot';
import type Firestore from './'; import type Firestore from './';
import type { FirestoreNativeDocumentChange } from '../../types';
/** /**
* @class DocumentChange * @class DocumentChange

View File

@ -8,6 +8,7 @@ import { buildNativeMap } from './utils/serialize';
import { firestoreAutoId, isFunction, isObject, isString } from '../../utils'; import { firestoreAutoId, isFunction, isObject, isString } from '../../utils';
import type Firestore from './'; import type Firestore from './';
import type { FirestoreNativeDocumentSnapshot, FirestoreWriteOptions } from '../../types';
import type Path from './Path'; import type Path from './Path';
type DocumentListenOptions = { type DocumentListenOptions = {

View File

@ -7,6 +7,7 @@ import Path from './Path';
import { parseNativeMap } from './utils/serialize'; import { parseNativeMap } from './utils/serialize';
import type Firestore from './'; import type Firestore from './';
import type { FirestoreNativeDocumentSnapshot, FirestoreSnapshotMetadata } from '../../types';
/** /**
* @class DocumentSnapshot * @class DocumentSnapshot

View File

@ -8,6 +8,7 @@ import { buildNativeArray, buildTypeMap } from './utils/serialize';
import { firestoreAutoId, isFunction, isObject } from '../../utils'; import { firestoreAutoId, isFunction, isObject } from '../../utils';
import type Firestore from './'; import type Firestore from './';
import type { FirestoreQueryDirection, FirestoreQueryOperator } from '../../types';
import type Path from './Path'; import type Path from './Path';
const DIRECTIONS: { [FirestoreQueryDirection]: string } = { const DIRECTIONS: { [FirestoreQueryDirection]: string } = {

View File

@ -6,6 +6,7 @@ import DocumentChange from './DocumentChange';
import DocumentSnapshot from './DocumentSnapshot'; import DocumentSnapshot from './DocumentSnapshot';
import type Firestore from './'; import type Firestore from './';
import type { FirestoreNativeDocumentChange, FirestoreNativeDocumentSnapshot, FirestoreSnapshotMetadata } from '../../types';
import type Query from './Query'; import type Query from './Query';
type QuerySnapshotNativeData = { type QuerySnapshotNativeData = {

View File

@ -7,6 +7,7 @@ import { isObject, isString } from '../../utils';
import type DocumentReference from './DocumentReference'; import type DocumentReference from './DocumentReference';
import type Firestore from './'; import type Firestore from './';
import type { FirestoreWriteOptions } from '../../types';
type DocumentWrite = { type DocumentWrite = {
data?: Object, data?: Object,

View File

@ -33,10 +33,7 @@ type DocumentSyncEvent = {
path: string, path: string,
} }
/** class FirestoreInternalModule extends ModuleBase {
* @class Firestore
*/
export default class Firestore extends ModuleBase {
static _NAMESPACE = 'firestore'; static _NAMESPACE = 'firestore';
static _NATIVE_MODULE = 'RNFirebaseFirestore'; static _NATIVE_MODULE = 'RNFirebaseFirestore';
@ -46,14 +43,14 @@ export default class Firestore extends ModuleBase {
super(firebaseApp, options, true); super(firebaseApp, options, true);
this._referencePath = new Path([]); this._referencePath = new Path([]);
this.addListener( super.addListener(
// sub to internal native event - this fans out to // sub to internal native event - this fans out to
// public event name: onCollectionSnapshot // public event name: onCollectionSnapshot
super._getAppEventName('firestore_collection_sync_event'), super._getAppEventName('firestore_collection_sync_event'),
this._onCollectionSyncEvent.bind(this), this._onCollectionSyncEvent.bind(this),
); );
this.addListener( super.addListener(
// sub to internal native event - this fans out to // sub to internal native event - this fans out to
// public event name: onDocumentSnapshot // public event name: onDocumentSnapshot
super._getAppEventName('firestore_document_sync_event'), super._getAppEventName('firestore_document_sync_event'),
@ -61,6 +58,41 @@ export default class Firestore extends ModuleBase {
); );
} }
/**
* Internal collection sync listener
* @param event
* @private
*/
_onCollectionSyncEvent(event: CollectionSyncEvent) {
if (event.error) {
this.emit(super._getAppEventName(`onQuerySnapshotError:${event.listenerId}`), event.error);
} else {
this.emit(super._getAppEventName(`onQuerySnapshot:${event.listenerId}`), event.querySnapshot);
}
}
/**
* Internal document sync listener
* @param event
* @private
*/
_onDocumentSyncEvent(event: DocumentSyncEvent) {
if (event.error) {
this.emit(super._getAppEventName(`onDocumentSnapshotError:${event.listenerId}`), event.error);
} else {
this.emit(super._getAppEventName(`onDocumentSnapshot:${event.listenerId}`), event.documentSnapshot);
}
}
}
/**
* @class Firestore
*/
export default class Firestore extends FirestoreInternalModule {
constructor(firebaseApp: FirebaseApp, options: Object = {}) {
super(firebaseApp, options);
}
batch(): WriteBatch { batch(): WriteBatch {
return new WriteBatch(this); return new WriteBatch(this);
} }
@ -108,36 +140,6 @@ export default class Firestore extends ModuleBase {
settings(): void { settings(): void {
throw new Error('firebase.firestore().settings() coming soon'); throw new Error('firebase.firestore().settings() coming soon');
} }
/**
* INTERNALS
*/
/**
* Internal collection sync listener
* @param event
* @private
*/
_onCollectionSyncEvent(event: CollectionSyncEvent) {
if (event.error) {
this.emit(super._getAppEventName(`onQuerySnapshotError:${event.listenerId}`), event.error);
} else {
this.emit(super._getAppEventName(`onQuerySnapshot:${event.listenerId}`), event.querySnapshot);
}
}
/**
* Internal document sync listener
* @param event
* @private
*/
_onDocumentSyncEvent(event: DocumentSyncEvent) {
if (event.error) {
this.emit(super._getAppEventName(`onDocumentSnapshotError:${event.listenerId}`), event.error);
} else {
this.emit(super._getAppEventName(`onDocumentSnapshot:${event.listenerId}`), event.documentSnapshot);
}
}
} }
export const statics = { export const statics = {

View File

@ -9,6 +9,7 @@ import Path from '../Path';
import { typeOf } from '../../../utils'; import { typeOf } from '../../../utils';
import type Firestore from '../'; import type Firestore from '../';
import type { FirestoreTypeMap } from '../../../types';
/* /*
* Functions that build up the data needed to represent * Functions that build up the data needed to represent

View File

@ -29,3 +29,5 @@ export default class PerformanceMonitoring extends ModuleBase {
return new Trace(this, trace); return new Trace(this, trace);
} }
} }
export const statics = {};

View File

@ -5,11 +5,20 @@ import { NativeModules } from 'react-native';
import INTERNALS from '../../utils/internals'; import INTERNALS from '../../utils/internals';
import { isIOS } from '../../utils'; import { isIOS } from '../../utils';
import ModuleBase from '../../utils/ModuleBase';
import PACKAGE from '../../../package.json'; import PACKAGE from '../../../package.json';
const FirebaseCoreModule = NativeModules.RNFirebase; 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 _NAMESPACE = 'utils';
static _NATIVE_DISABLED = true; static _NATIVE_DISABLED = true;
static _NATIVE_MODULE = 'RNFirebaseUtils'; static _NATIVE_MODULE = 'RNFirebaseUtils';
@ -105,7 +114,7 @@ export default class RNFirebaseUtils {
* @android * @android
* @param bool * @param bool
*/ */
set errorOnMissingPlayServices(bool: Boolean) { set errorOnMissingPlayServices(bool: boolean) {
INTERNALS.OPTIONS.errorOnMissingPlayServices = bool; INTERNALS.OPTIONS.errorOnMissingPlayServices = bool;
} }
@ -114,7 +123,7 @@ export default class RNFirebaseUtils {
* @android * @android
* @param bool * @param bool
*/ */
set promptOnMissingPlayServices(bool: Boolean) { set promptOnMissingPlayServices(bool: boolean) {
INTERNALS.OPTIONS.promptOnMissingPlayServices = bool; INTERNALS.OPTIONS.promptOnMissingPlayServices = bool;
} }
} }

View File

@ -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
};

187
lib/types/index.js Normal file
View File

@ -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<ModuleBase>;
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: FirebaseModule, S: FirebaseStatics> = {
(): M,
nativeModuleExists: boolean,
} & S;
export type FirebaseStatics = $Subtype<Object>;
/* 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;

View File

@ -9,6 +9,7 @@ import FirebaseCore from '../modules/core/firebase';
import { nativeWithApp } from '../utils'; import { nativeWithApp } from '../utils';
import type FirebaseApp from '../modules/core/firebase-app'; import type FirebaseApp from '../modules/core/firebase-app';
import type { FirebaseModuleName } from '../types';
const logs = {}; const logs = {};
@ -53,7 +54,7 @@ export default class ModuleBase {
_namespace: string; _namespace: string;
_firebaseApp: FirebaseApp; _firebaseApp: FirebaseApp;
_eventEmitter: Object; _eventEmitter: Object;
static _NAMESPACE: string; static _NAMESPACE: FirebaseModuleName;
static _NATIVE_MODULE: string; static _NATIVE_MODULE: string;
/** /**

View File

@ -4,9 +4,9 @@
import { NativeEventEmitter } from 'react-native'; import { NativeEventEmitter } from 'react-native';
import INTERNALS from './internals'; import INTERNALS from './internals';
import DatabaseSnapshot from './../modules/database/snapshot'; import DatabaseSnapshot from '../modules/database/snapshot';
import DatabaseReference from './../modules/database/reference'; import DatabaseReference from '../modules/database/reference';
import { isString, nativeToJSError } from './../utils'; import { isString, nativeToJSError } from '../utils';
type Registration = { type Registration = {
key: string, key: string,

View File

@ -7,6 +7,8 @@ import EventEmitter from './emitter/EventEmitter';
import ModuleBase from './ModuleBase'; import ModuleBase from './ModuleBase';
import SyncTree from './SyncTree'; import SyncTree from './SyncTree';
import type FirebaseApp from '../modules/core/firebase-app';
const DEFAULT_APP_NAME = Platform.OS === 'ios' ? '__FIRAPP_DEFAULT' : '[DEFAULT]'; const DEFAULT_APP_NAME = Platform.OS === 'ios' ? '__FIRAPP_DEFAULT' : '[DEFAULT]';
const NAMESPACE_PODS = { const NAMESPACE_PODS = {
@ -53,6 +55,8 @@ const PLAY_SERVICES_CODES = {
}, },
}; };
const APPS: { [string]: FirebaseApp } = {};
export default { export default {
// default options // default options
OPTIONS: { OPTIONS: {
@ -66,9 +70,7 @@ export default {
}, },
// track all initialized firebase apps // track all initialized firebase apps
APPS: { APPS,
[DEFAULT_APP_NAME]: null,
},
STRINGS: { STRINGS: {
WARN_INITIALIZE_DEPRECATION: 'Deprecation: Calling \'initializeApp()\' for apps that are already initialised natively ' + WARN_INITIALIZE_DEPRECATION: 'Deprecation: Calling \'initializeApp()\' for apps that are already initialised natively ' +

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "react-native-firebase", "name": "react-native-firebase",
"version": "3.1.0", "version": "3.1.1-alpha.11",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View File

@ -1,6 +1,6 @@
{ {
"name": "react-native-firebase", "name": "react-native-firebase",
"version": "3.1.1-alpha.4", "version": "3.1.1-alpha.11",
"author": "Invertase <contact@invertase.io> (http://invertase.io)", "author": "Invertase <contact@invertase.io> (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.", "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", "main": "dist/index.js",
@ -20,9 +20,6 @@
"tests-watch-start": "npm run test-cli watch init start", "tests-watch-start": "npm run test-cli watch init start",
"tests-watch-stop": "npm run test-cli watch stop" "tests-watch-stop": "npm run test-cli watch stop"
}, },
"files": [
"dist"
],
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/invertase/react-native-firebase.git" "url": "https://github.com/invertase/react-native-firebase.git"

View File

@ -150,7 +150,7 @@ PODS:
- React/Core - React/Core
- React/fishhook - React/fishhook
- React/RCTBlob - React/RCTBlob
- RNFirebase (3.1.0): - RNFirebase (3.1.1-alpha.11):
- React - React
- yoga (0.49.1.React) - yoga (0.49.1.React)
@ -208,7 +208,7 @@ SPEC CHECKSUMS:
nanopb: 5601e6bca2dbf1ed831b519092ec110f66982ca3 nanopb: 5601e6bca2dbf1ed831b519092ec110f66982ca3
Protobuf: 03eef2ee0b674770735cf79d9c4d3659cf6908e8 Protobuf: 03eef2ee0b674770735cf79d9c4d3659cf6908e8
React: cf892fb84b7d06bf5fea7f328e554c6dcabe85ee React: cf892fb84b7d06bf5fea7f328e554c6dcabe85ee
RNFirebase: 1b8adf4dfe740fbc4a69a147715c2edfd041eb92 RNFirebase: e959075eb2f348c3586cd92973543b80e373b29c
yoga: 3abf02d6d9aeeb139b4c930eb1367feae690a35a yoga: 3abf02d6d9aeeb139b4c930eb1367feae690a35a
PODFILE CHECKSUM: b5674be55653f5dda937c8b794d0479900643d45 PODFILE CHECKSUM: b5674be55653f5dda937c8b794d0479900643d45