2017-09-28 12:48:28 +00:00
# import "RNFirebaseFirestore.h"
2017-10-03 16:23:28 +00:00
# if __has _include ( < FirebaseFirestore / FirebaseFirestore . h > )
2017-09-28 12:48:28 +00:00
# import < Firebase . h >
# import "RNFirebaseEvents.h"
# import "RNFirebaseFirestoreCollectionReference.h"
# import "RNFirebaseFirestoreDocumentReference.h"
@ implementation RNFirebaseFirestore
RCT_EXPORT _MODULE ( ) ;
- ( id ) init {
self = [ super init ] ;
if ( self ! = nil ) {
2018-03-04 23:47:10 +00:00
_transactions = [ [ NSMutableDictionary alloc ] init ] ;
_transactionQueue = dispatch_queue _create ( "io.invertase.react-native-firebase.firestore" , DISPATCH_QUEUE _CONCURRENT ) ;
2017-09-28 12:48:28 +00:00
}
return self ;
}
2018-03-04 23:47:10 +00:00
/ * *
* TRANSACTIONS
* /
RCT_EXPORT _METHOD ( transactionGetDocument : ( NSString * ) appDisplayName
transactionId : ( nonnull NSNumber * ) transactionId
path : ( NSString * ) path
resolver : ( RCTPromiseResolveBlock ) resolve
rejecter : ( RCTPromiseRejectBlock ) reject ) {
__block NSMutableDictionary * transactionState ;
dispatch_sync ( _transactionQueue , ^ {
transactionState = _transactions [ [ transactionId stringValue ] ] ;
} ) ;
if ( ! transactionState ) {
NSLog ( @ "transactionGetDocument called for non-existant transactionId %@" , transactionId ) ;
return ;
}
NSError * error = nil ;
FIRTransaction * transaction = [ transactionState valueForKey : @ "transaction" ] ;
FIRDocumentReference * ref = [ self getDocumentForAppPath : appDisplayName path : path ] . ref ;
FIRDocumentSnapshot * snapshot = [ transaction getDocument : ref error : & error ] ;
if ( error ! = nil ) {
[ RNFirebaseFirestore promiseRejectException : reject error : error ] ;
} else {
NSDictionary * snapshotDict = [ RNFirebaseFirestoreDocumentReference snapshotToDictionary : snapshot ] ;
NSString * path = snapshotDict [ @ "path" ] ;
if ( path = = nil ) {
[ snapshotDict setValue : ref . path forKey : @ "path" ] ;
}
resolve ( snapshotDict ) ;
}
}
RCT_EXPORT _METHOD ( transactionDispose : ( NSString * ) appDisplayName
transactionId : ( nonnull NSNumber * ) transactionId ) {
__block NSMutableDictionary * transactionState ;
dispatch_sync ( _transactionQueue , ^ {
transactionState = _transactions [ [ transactionId stringValue ] ] ;
} ) ;
if ( ! transactionState ) {
NSLog ( @ "transactionGetDocument called for non-existant transactionId %@" , transactionId ) ;
return ;
}
dispatch_semaphore _t semaphore = [ transactionState valueForKey : @ "semaphore" ] ;
[ transactionState setValue : @ true forKey : @ "abort" ] ;
dispatch_semaphore _signal ( semaphore ) ;
}
RCT_EXPORT _METHOD ( transactionApplyBuffer : ( NSString * ) appDisplayName
transactionId : ( nonnull NSNumber * ) transactionId
commandBuffer : ( NSArray * ) commandBuffer ) {
__block NSMutableDictionary * transactionState ;
dispatch_sync ( _transactionQueue , ^ {
transactionState = _transactions [ [ transactionId stringValue ] ] ;
} ) ;
if ( ! transactionState ) {
NSLog ( @ "transactionGetDocument called for non-existant transactionId %@" , transactionId ) ;
return ;
}
dispatch_semaphore _t semaphore = [ transactionState valueForKey : @ "semaphore" ] ;
[ transactionState setValue : commandBuffer forKey : @ "commandBuffer" ] ;
dispatch_semaphore _signal ( semaphore ) ;
}
RCT_EXPORT _METHOD ( transactionBegin : ( NSString * ) appDisplayName
transactionId : ( nonnull NSNumber * ) transactionId ) {
FIRFirestore * firestore = [ RNFirebaseFirestore getFirestoreForApp : appDisplayName ] ;
__block BOOL aborted = false ;
dispatch_async ( _transactionQueue , ^ {
NSMutableDictionary * transactionState = [ NSMutableDictionary new ] ;
dispatch_semaphore _t semaphore = dispatch_semaphore _create ( 0 ) ;
transactionState [ @ "semaphore" ] = semaphore ;
[ firestore runTransactionWithBlock : ^ id ( FIRTransaction * transaction , NSError * * errorPointer ) {
transactionState [ @ "transaction" ] = transaction ;
// Build and send transaction update event
dispatch_barrier _async ( _transactionQueue , ^ {
[ _transactions setValue : transactionState forKey : [ transactionId stringValue ] ] ;
NSMutableDictionary * eventMap = [ NSMutableDictionary new ] ;
eventMap [ @ "type" ] = @ "update" ;
eventMap [ @ "id" ] = transactionId ;
eventMap [ @ "appName" ] = appDisplayName ;
[ RNFirebaseUtil sendJSEvent : self name : FIRESTORE_TRANSACTION _EVENT body : eventMap ] ;
} ) ;
// wait for the js event handler to call transactionApplyBuffer
// this wait occurs on the RNFirestore Worker Queue so if transactionApplyBuffer fails to
// signal the semaphore then no further blocks will be executed by RNFirestore until the timeout expires
dispatch_time _t delayTime = dispatch_time ( DISPATCH_TIME _NOW , 3000 * NSEC_PER _SEC ) ;
BOOL timedOut = dispatch_semaphore _wait ( semaphore , delayTime ) ! = 0 ;
aborted = [ transactionState valueForKey : @ "abort" ] ;
// dispose of transaction dictionary
dispatch_barrier _async ( _transactionQueue , ^ {
[ _transactions removeObjectForKey : [ transactionId stringValue ] ] ;
} ) ;
if ( aborted ) {
* errorPointer = [ NSError errorWithDomain : FIRFirestoreErrorDomain code : FIRFirestoreErrorCodeAborted userInfo : @ { } ] ;
return nil ;
}
if ( timedOut ) {
* errorPointer = [ NSError errorWithDomain : FIRFirestoreErrorDomain code : FIRFirestoreErrorCodeDeadlineExceeded userInfo : @ { } ] ;
return nil ;
}
NSArray * commandBuffer = [ transactionState valueForKey : @ "commandBuffer" ] ;
for ( NSDictionary * command in commandBuffer ) {
NSString * type = command [ @ "type" ] ;
NSString * path = command [ @ "path" ] ;
NSDictionary * data = [ RNFirebaseFirestoreDocumentReference parseJSMap : firestore jsMap : command [ @ "data" ] ] ;
FIRDocumentReference * ref = [ firestore documentWithPath : path ] ;
if ( [ type isEqualToString : @ "delete" ] ) {
[ transaction deleteDocument : ref ] ;
} else if ( [ type isEqualToString : @ "set" ] ) {
NSDictionary * options = command [ @ "options" ] ;
if ( options && options [ @ "merge" ] ) {
[ transaction setData : data forDocument : ref options : [ FIRSetOptions merge ] ] ;
} else {
[ transaction setData : data forDocument : ref ] ;
}
} else if ( [ type isEqualToString : @ "update" ] ) {
[ transaction updateData : data forDocument : ref ] ;
}
}
return nil ;
} completion : ^ ( id result , NSError * error ) {
if ( aborted = = NO ) {
NSMutableDictionary * eventMap = [ NSMutableDictionary new ] ;
eventMap [ @ "id" ] = transactionId ;
eventMap [ @ "appName" ] = appDisplayName ;
if ( error ! = nil ) {
eventMap [ @ "type" ] = @ "error" ;
eventMap [ @ "error" ] = [ RNFirebaseFirestore getJSError : error ] ;
} else {
eventMap [ @ "type" ] = @ "complete" ;
}
[ RNFirebaseUtil sendJSEvent : self name : FIRESTORE_TRANSACTION _EVENT body : eventMap ] ;
}
} ] ;
} ) ;
}
/ * *
* TRANSACTIONS END
* /
2018-03-27 16:31:25 +00:00
RCT_EXPORT _METHOD ( disableNetwork : ( NSString * ) appDisplayName
resolver : ( RCTPromiseResolveBlock ) resolve
rejecter : ( RCTPromiseRejectBlock ) reject ) {
FIRFirestore * firestore = [ RNFirebaseFirestore getFirestoreForApp : appDisplayName ] ;
[ firestore disableNetworkWithCompletion : ^ ( NSError * _Nullable error ) {
if ( error ) {
[ RNFirebaseFirestore promiseRejectException : reject error : error ] ;
} else {
resolve ( nil ) ;
}
} ] ;
}
2018-03-04 23:47:10 +00:00
RCT_EXPORT _METHOD ( enableLogging : ( BOOL ) enabled ) {
2017-11-28 08:02:05 +00:00
[ FIRFirestore enableLogging : enabled ] ;
}
2018-03-27 16:31:25 +00:00
RCT_EXPORT _METHOD ( enableNetwork : ( NSString * ) appDisplayName
resolver : ( RCTPromiseResolveBlock ) resolve
rejecter : ( RCTPromiseRejectBlock ) reject ) {
FIRFirestore * firestore = [ RNFirebaseFirestore getFirestoreForApp : appDisplayName ] ;
[ firestore enableNetworkWithCompletion : ^ ( NSError * _Nullable error ) {
if ( error ) {
[ RNFirebaseFirestore promiseRejectException : reject error : error ] ;
} else {
resolve ( nil ) ;
}
} ] ;
}
2018-03-04 23:47:10 +00:00
RCT_EXPORT _METHOD ( collectionGet : ( NSString * ) appDisplayName
path : ( NSString * ) path
filters : ( NSArray * ) filters
orders : ( NSArray * ) orders
options : ( NSDictionary * ) options
resolver : ( RCTPromiseResolveBlock ) resolve
rejecter : ( RCTPromiseRejectBlock ) reject ) {
2018-01-03 20:00:38 +00:00
[ [ self getCollectionForAppPath : appDisplayName path : path filters : filters orders : orders options : options ] get : resolve rejecter : reject ] ;
2017-09-28 12:48:28 +00:00
}
2018-03-04 23:47:10 +00:00
RCT_EXPORT _METHOD ( collectionOffSnapshot : ( NSString * ) appDisplayName
path : ( NSString * ) path
filters : ( NSArray * ) filters
orders : ( NSArray * ) orders
options : ( NSDictionary * ) options
listenerId : ( nonnull NSString * ) listenerId ) {
2017-10-03 09:12:25 +00:00
[ RNFirebaseFirestoreCollectionReference offSnapshot : listenerId ] ;
}
2018-03-04 23:47:10 +00:00
RCT_EXPORT _METHOD ( collectionOnSnapshot : ( NSString * ) appDisplayName
path : ( NSString * ) path
filters : ( NSArray * ) filters
orders : ( NSArray * ) orders
options : ( NSDictionary * ) options
listenerId : ( nonnull NSString * ) listenerId
queryListenOptions : ( NSDictionary * ) queryListenOptions ) {
2018-01-03 20:00:38 +00:00
RNFirebaseFirestoreCollectionReference * ref = [ self getCollectionForAppPath : appDisplayName path : path filters : filters orders : orders options : options ] ;
2017-10-06 11:00:40 +00:00
[ ref onSnapshot : listenerId queryListenOptions : queryListenOptions ] ;
2017-10-03 09:12:25 +00:00
}
2018-03-04 23:47:10 +00:00
RCT_EXPORT _METHOD ( documentBatch : ( NSString * ) appDisplayName
writes : ( NSArray * ) writes
resolver : ( RCTPromiseResolveBlock ) resolve
rejecter : ( RCTPromiseRejectBlock ) reject ) {
2018-01-03 20:00:38 +00:00
FIRFirestore * firestore = [ RNFirebaseFirestore getFirestoreForApp : appDisplayName ] ;
2017-09-28 12:48:28 +00:00
FIRWriteBatch * batch = [ firestore batch ] ;
2017-10-03 16:23:28 +00:00
2017-09-28 12:48:28 +00:00
for ( NSDictionary * write in writes ) {
NSString * type = write [ @ "type" ] ;
NSString * path = write [ @ "path" ] ;
2017-10-10 16:22:12 +00:00
NSDictionary * data = [ RNFirebaseFirestoreDocumentReference parseJSMap : firestore jsMap : write [ @ "data" ] ] ;
2017-10-03 16:23:28 +00:00
2017-09-28 12:48:28 +00:00
FIRDocumentReference * ref = [ firestore documentWithPath : path ] ;
2017-10-03 16:23:28 +00:00
2017-09-28 12:48:28 +00:00
if ( [ type isEqualToString : @ "DELETE" ] ) {
batch = [ batch deleteDocument : ref ] ;
} else if ( [ type isEqualToString : @ "SET" ] ) {
NSDictionary * options = write [ @ "options" ] ;
if ( options && options [ @ "merge" ] ) {
batch = [ batch setData : data forDocument : ref options : [ FIRSetOptions merge ] ] ;
} else {
batch = [ batch setData : data forDocument : ref ] ;
}
} else if ( [ type isEqualToString : @ "UPDATE" ] ) {
batch = [ batch updateData : data forDocument : ref ] ;
}
}
2018-03-04 23:47:10 +00:00
[ batch commitWithCompletion : ^ ( NSError * _Nullable error ) {
2017-09-28 12:48:28 +00:00
if ( error ) {
[ RNFirebaseFirestore promiseRejectException : reject error : error ] ;
} else {
2017-10-05 09:18:24 +00:00
resolve ( nil ) ;
2017-09-28 12:48:28 +00:00
}
} ] ;
}
2018-03-04 23:47:10 +00:00
RCT_EXPORT _METHOD ( documentDelete : ( NSString * ) appDisplayName
path : ( NSString * ) path
resolver : ( RCTPromiseResolveBlock ) resolve
rejecter : ( RCTPromiseRejectBlock ) reject ) {
2018-01-03 20:00:38 +00:00
[ [ self getDocumentForAppPath : appDisplayName path : path ] delete : resolve rejecter : reject ] ;
2017-09-28 12:48:28 +00:00
}
2018-03-04 23:47:10 +00:00
RCT_EXPORT _METHOD ( documentGet : ( NSString * ) appDisplayName
path : ( NSString * ) path
resolver : ( RCTPromiseResolveBlock ) resolve
rejecter : ( RCTPromiseRejectBlock ) reject ) {
2018-01-03 20:00:38 +00:00
[ [ self getDocumentForAppPath : appDisplayName path : path ] get : resolve rejecter : reject ] ;
2017-09-28 12:48:28 +00:00
}
2018-03-04 23:47:10 +00:00
RCT_EXPORT _METHOD ( documentGetAll : ( NSString * ) appDisplayName
documents : ( NSString * ) documents
resolver : ( RCTPromiseResolveBlock ) resolve
rejecter : ( RCTPromiseRejectBlock ) reject ) {
2017-09-28 12:48:28 +00:00
// Not supported on iOS out of the box
}
2018-03-04 23:47:10 +00:00
RCT_EXPORT _METHOD ( documentOffSnapshot : ( NSString * ) appDisplayName
path : ( NSString * ) path
listenerId : ( nonnull NSString * ) listenerId ) {
2017-10-03 09:12:25 +00:00
[ RNFirebaseFirestoreDocumentReference offSnapshot : listenerId ] ;
2017-10-02 14:45:07 +00:00
}
2018-03-04 23:47:10 +00:00
RCT_EXPORT _METHOD ( documentOnSnapshot : ( NSString * ) appDisplayName
path : ( NSString * ) path
listenerId : ( nonnull NSString * ) listenerId
docListenOptions : ( NSDictionary * ) docListenOptions ) {
2018-01-03 20:00:38 +00:00
RNFirebaseFirestoreDocumentReference * ref = [ self getDocumentForAppPath : appDisplayName path : path ] ;
2017-10-06 11:00:40 +00:00
[ ref onSnapshot : listenerId docListenOptions : docListenOptions ] ;
2017-10-02 14:45:07 +00:00
}
2018-03-04 23:47:10 +00:00
RCT_EXPORT _METHOD ( documentSet : ( NSString * ) appDisplayName
path : ( NSString * ) path
data : ( NSDictionary * ) data
options : ( NSDictionary * ) options
resolver : ( RCTPromiseResolveBlock ) resolve
rejecter : ( RCTPromiseRejectBlock ) reject ) {
2018-01-03 20:00:38 +00:00
[ [ self getDocumentForAppPath : appDisplayName path : path ] set : data options : options resolver : resolve rejecter : reject ] ;
2017-09-28 12:48:28 +00:00
}
2018-03-04 23:47:10 +00:00
RCT_EXPORT _METHOD ( documentUpdate : ( NSString * ) appDisplayName
path : ( NSString * ) path
data : ( NSDictionary * ) data
resolver : ( RCTPromiseResolveBlock ) resolve
rejecter : ( RCTPromiseRejectBlock ) reject ) {
2018-01-03 20:00:38 +00:00
[ [ self getDocumentForAppPath : appDisplayName path : path ] update : data resolver : resolve rejecter : reject ] ;
2017-09-28 12:48:28 +00:00
}
/ *
* INTERNALS / UTILS
* /
+ ( void ) promiseRejectException : ( RCTPromiseRejectBlock ) reject error : ( NSError * ) error {
2017-10-02 14:45:07 +00:00
NSDictionary * jsError = [ RNFirebaseFirestore getJSError : error ] ;
reject ( [ jsError valueForKey : @ "code" ] , [ jsError valueForKey : @ "message" ] , error ) ;
2017-09-28 12:48:28 +00:00
}
2018-01-03 20:00:38 +00:00
+ ( FIRFirestore * ) getFirestoreForApp : ( NSString * ) appDisplayName {
FIRApp * app = [ RNFirebaseUtil getApp : appDisplayName ] ;
2017-09-28 12:48:28 +00:00
return [ FIRFirestore firestoreForApp : app ] ;
}
2018-01-03 20:00:38 +00:00
- ( RNFirebaseFirestoreCollectionReference * ) getCollectionForAppPath : ( NSString * ) appDisplayName path : ( NSString * ) path filters : ( NSArray * ) filters orders : ( NSArray * ) orders options : ( NSDictionary * ) options {
return [ [ RNFirebaseFirestoreCollectionReference alloc ] initWithPathAndModifiers : self appDisplayName : appDisplayName path : path filters : filters orders : orders options : options ] ;
2017-10-02 14:45:07 +00:00
}
2018-01-03 20:00:38 +00:00
- ( RNFirebaseFirestoreDocumentReference * ) getDocumentForAppPath : ( NSString * ) appDisplayName path : ( NSString * ) path {
return [ [ RNFirebaseFirestoreDocumentReference alloc ] initWithPath : self appDisplayName : appDisplayName path : path ] ;
2017-10-02 14:45:07 +00:00
}
// TODO : Move to error util for use in other modules
+ ( NSString * ) getMessageWithService : ( NSString * ) message service : ( NSString * ) service fullCode : ( NSString * ) fullCode {
return [ NSString stringWithFormat : @ "%@: %@ (%@)." , service , message , [ fullCode lowercaseString ] ] ;
}
+ ( NSString * ) getCodeWithService : ( NSString * ) service code : ( NSString * ) code {
return [ NSString stringWithFormat : @ "%@/%@" , [ service lowercaseString ] , [ code lowercaseString ] ] ;
}
+ ( NSDictionary * ) getJSError : ( NSError * ) nativeError {
NSMutableDictionary * errorMap = [ [ NSMutableDictionary alloc ] init ] ;
[ errorMap setValue : @ ( nativeError . code ) forKey : @ "nativeErrorCode" ] ;
[ errorMap setValue : [ nativeError localizedDescription ] forKey : @ "nativeErrorMessage" ] ;
2017-10-03 16:23:28 +00:00
2017-10-02 14:45:07 +00:00
NSString * code ;
NSString * message ;
NSString * service = @ "Firestore" ;
2017-10-03 16:23:28 +00:00
2017-10-02 14:45:07 +00:00
switch ( nativeError . code ) {
2017-10-05 09:32:14 +00:00
case FIRFirestoreErrorCodeOK :
code = [ RNFirebaseFirestore getCodeWithService : service code : @ "ok" ] ;
message = [ RNFirebaseFirestore getMessageWithService : @ "Ok." service : service fullCode : code ] ;
break ;
case FIRFirestoreErrorCodeCancelled :
code = [ RNFirebaseFirestore getCodeWithService : service code : @ "cancelled" ] ;
message = [ RNFirebaseFirestore getMessageWithService : @ "The operation was cancelled." service : service fullCode : code ] ;
break ;
case FIRFirestoreErrorCodeUnknown :
code = [ RNFirebaseFirestore getCodeWithService : service code : @ "unknown" ] ;
message = [ RNFirebaseFirestore getMessageWithService : @ "Unknown error or an error from a different error domain." service : service fullCode : code ] ;
break ;
case FIRFirestoreErrorCodeInvalidArgument :
code = [ RNFirebaseFirestore getCodeWithService : service code : @ "invalid-argument" ] ;
message = [ RNFirebaseFirestore getMessageWithService : @ "Client specified an invalid argument." service : service fullCode : code ] ;
break ;
case FIRFirestoreErrorCodeDeadlineExceeded :
code = [ RNFirebaseFirestore getCodeWithService : service code : @ "deadline-exceeded" ] ;
message = [ RNFirebaseFirestore getMessageWithService : @ "Deadline expired before operation could complete." service : service fullCode : code ] ;
break ;
case FIRFirestoreErrorCodeNotFound :
code = [ RNFirebaseFirestore getCodeWithService : service code : @ "not-found" ] ;
message = [ RNFirebaseFirestore getMessageWithService : @ "Some requested document was not found." service : service fullCode : code ] ;
break ;
case FIRFirestoreErrorCodeAlreadyExists :
code = [ RNFirebaseFirestore getCodeWithService : service code : @ "already-exists" ] ;
message = [ RNFirebaseFirestore getMessageWithService : @ "Some document that we attempted to create already exists." service : service fullCode : code ] ;
break ;
case FIRFirestoreErrorCodePermissionDenied :
code = [ RNFirebaseFirestore getCodeWithService : service code : @ "permission-denied" ] ;
message = [ RNFirebaseFirestore getMessageWithService : @ "The caller does not have permission to execute the specified operation." service : service fullCode : code ] ;
break ;
case FIRFirestoreErrorCodeResourceExhausted :
code = [ RNFirebaseFirestore getCodeWithService : service code : @ "resource-exhausted" ] ;
message = [ RNFirebaseFirestore getMessageWithService : @ "Some resource has been exhausted, perhaps a per-user quota, or perhaps the entire file system is out of space." service : service fullCode : code ] ;
break ;
case FIRFirestoreErrorCodeFailedPrecondition :
code = [ RNFirebaseFirestore getCodeWithService : service code : @ "failed-precondition" ] ;
message = [ RNFirebaseFirestore getMessageWithService : @ "Operation was rejected because the system is not in a state required for the operation`s execution." service : service fullCode : code ] ;
break ;
case FIRFirestoreErrorCodeAborted :
code = [ RNFirebaseFirestore getCodeWithService : service code : @ "aborted" ] ;
message = [ RNFirebaseFirestore getMessageWithService : @ "The operation was aborted, typically due to a concurrency issue like transaction aborts, etc." service : service fullCode : code ] ;
break ;
case FIRFirestoreErrorCodeOutOfRange :
code = [ RNFirebaseFirestore getCodeWithService : service code : @ "out-of-range" ] ;
message = [ RNFirebaseFirestore getMessageWithService : @ "Operation was attempted past the valid range." service : service fullCode : code ] ;
break ;
case FIRFirestoreErrorCodeUnimplemented :
code = [ RNFirebaseFirestore getCodeWithService : service code : @ "unimplemented" ] ;
message = [ RNFirebaseFirestore getMessageWithService : @ "Operation is not implemented or not supported/enabled." service : service fullCode : code ] ;
break ;
case FIRFirestoreErrorCodeInternal :
code = [ RNFirebaseFirestore getCodeWithService : service code : @ "internal" ] ;
message = [ RNFirebaseFirestore getMessageWithService : @ "Internal errors." service : service fullCode : code ] ;
break ;
case FIRFirestoreErrorCodeUnavailable :
code = [ RNFirebaseFirestore getCodeWithService : service code : @ "unavailable" ] ;
message = [ RNFirebaseFirestore getMessageWithService : @ "The service is currently unavailable." service : service fullCode : code ] ;
break ;
case FIRFirestoreErrorCodeDataLoss :
code = [ RNFirebaseFirestore getCodeWithService : service code : @ "data-loss" ] ;
message = [ RNFirebaseFirestore getMessageWithService : @ "Unrecoverable data loss or corruption." service : service fullCode : code ] ;
break ;
case FIRFirestoreErrorCodeUnauthenticated :
code = [ RNFirebaseFirestore getCodeWithService : service code : @ "unauthenticated" ] ;
message = [ RNFirebaseFirestore getMessageWithService : @ "The request does not have valid authentication credentials for the operation." service : service fullCode : code ] ;
break ;
2017-10-02 14:45:07 +00:00
default :
code = [ RNFirebaseFirestore getCodeWithService : service code : @ "unknown" ] ;
message = [ RNFirebaseFirestore getMessageWithService : @ "An unknown error occurred." service : service fullCode : code ] ;
break ;
}
2017-10-03 16:23:28 +00:00
2017-10-02 14:45:07 +00:00
[ errorMap setValue : code forKey : @ "code" ] ;
[ errorMap setValue : message forKey : @ "message" ] ;
2017-10-03 16:23:28 +00:00
2017-10-02 14:45:07 +00:00
return errorMap ;
2017-09-28 12:48:28 +00:00
}
- ( NSArray < NSString * > * ) supportedEvents {
2018-03-04 23:47:10 +00:00
return @ [ FIRESTORE_COLLECTION _SYNC _EVENT , FIRESTORE_DOCUMENT _SYNC _EVENT , FIRESTORE_TRANSACTION _EVENT ] ;
2017-09-28 12:48:28 +00:00
}
2018-03-04 23:47:10 +00:00
+ ( BOOL ) requiresMainQueueSetup {
2017-10-12 08:18:01 +00:00
return YES ;
}
2017-09-28 12:48:28 +00:00
@ end
# else
@ implementation RNFirebaseFirestore
@ end
# endif
2018-03-04 23:47:10 +00:00