1
1
import {
2
- firebase ,
3
2
DocumentSnapshot as DocumentSnapshotBase ,
3
+ FieldValue ,
4
+ firebase ,
4
5
GeoPoint ,
5
- isDocumentReference , FieldValue
6
+ isDocumentReference
6
7
} from "./firebase-common" ;
7
8
import * as firebaseMessaging from "./messaging/messaging" ;
8
9
import * as application from "tns-core-modules/application/application" ;
@@ -112,17 +113,17 @@ firebase.addAppDelegateMethods = appDelegate => {
112
113
let result = false ;
113
114
if ( typeof ( FBSDKApplicationDelegate ) !== "undefined" ) {
114
115
result = FBSDKApplicationDelegate . sharedInstance ( ) . applicationOpenURLSourceApplicationAnnotation (
115
- application ,
116
- url ,
117
- options . valueForKey ( UIApplicationOpenURLOptionsSourceApplicationKey ) ,
118
- options . valueForKey ( UIApplicationOpenURLOptionsAnnotationKey ) ) ;
116
+ application ,
117
+ url ,
118
+ options . valueForKey ( UIApplicationOpenURLOptionsSourceApplicationKey ) ,
119
+ options . valueForKey ( UIApplicationOpenURLOptionsAnnotationKey ) ) ;
119
120
}
120
121
121
122
if ( typeof ( GIDSignIn ) !== "undefined" ) {
122
123
result = result || GIDSignIn . sharedInstance ( ) . handleURLSourceApplicationAnnotation (
123
- url ,
124
- options . valueForKey ( UIApplicationOpenURLOptionsSourceApplicationKey ) ,
125
- options . valueForKey ( UIApplicationOpenURLOptionsAnnotationKey ) ) ;
124
+ url ,
125
+ options . valueForKey ( UIApplicationOpenURLOptionsSourceApplicationKey ) ,
126
+ options . valueForKey ( UIApplicationOpenURLOptionsAnnotationKey ) ) ;
126
127
}
127
128
128
129
if ( typeof ( FIRDynamicLink ) !== "undefined" ) {
@@ -475,7 +476,7 @@ firebase.getRemoteConfig = arg => {
475
476
476
477
const onCompletion = ( remoteConfigFetchStatus , error ) => {
477
478
if ( remoteConfigFetchStatus === FIRRemoteConfigFetchStatus . Success ||
478
- remoteConfigFetchStatus === FIRRemoteConfigFetchStatus . Throttled ) {
479
+ remoteConfigFetchStatus === FIRRemoteConfigFetchStatus . Throttled ) {
479
480
480
481
const activated = firebaseRemoteConfig . activateFetched ( ) ;
481
482
@@ -742,22 +743,22 @@ firebase.login = arg => {
742
743
firActionCodeSettings . handleCodeInApp = true ;
743
744
firActionCodeSettings . setIOSBundleID ( arg . emailLinkOptions . iOS ? arg . emailLinkOptions . iOS . bundleId : NSBundle . mainBundle . bundleIdentifier ) ;
744
745
firActionCodeSettings . setAndroidPackageNameInstallIfNotAvailableMinimumVersion (
745
- arg . emailLinkOptions . android ? arg . emailLinkOptions . android . packageName : NSBundle . mainBundle . bundleIdentifier ,
746
- arg . emailLinkOptions . android ? arg . emailLinkOptions . android . installApp || false : false ,
747
- arg . emailLinkOptions . android ? arg . emailLinkOptions . android . minimumVersion || "1" : "1" ) ;
746
+ arg . emailLinkOptions . android ? arg . emailLinkOptions . android . packageName : NSBundle . mainBundle . bundleIdentifier ,
747
+ arg . emailLinkOptions . android ? arg . emailLinkOptions . android . installApp || false : false ,
748
+ arg . emailLinkOptions . android ? arg . emailLinkOptions . android . minimumVersion || "1" : "1" ) ;
748
749
fAuth . sendSignInLinkToEmailActionCodeSettingsCompletion (
749
- arg . emailLinkOptions . email ,
750
- firActionCodeSettings ,
751
- ( error : NSError ) => {
752
- if ( error ) {
753
- reject ( error . localizedDescription ) ;
754
- return ;
750
+ arg . emailLinkOptions . email ,
751
+ firActionCodeSettings ,
752
+ ( error : NSError ) => {
753
+ if ( error ) {
754
+ reject ( error . localizedDescription ) ;
755
+ return ;
756
+ }
757
+ // The link was successfully sent.
758
+ // Save the email locally so you don't need to ask the user for it again if they open the link on the same device.
759
+ firebase . rememberEmailForEmailLinkLogin ( arg . emailLinkOptions . email ) ;
760
+ resolve ( ) ;
755
761
}
756
- // The link was successfully sent.
757
- // Save the email locally so you don't need to ask the user for it again if they open the link on the same device.
758
- firebase . rememberEmailForEmailLinkLogin ( arg . emailLinkOptions . email ) ;
759
- resolve ( ) ;
760
- }
761
762
) ;
762
763
763
764
} else if ( arg . type === firebase . LoginType . PHONE ) {
@@ -801,14 +802,14 @@ firebase.login = arg => {
801
802
fAuth . signInAndRetrieveDataWithCustomTokenCompletion ( arg . customOptions . token , onCompletionWithAuthResult ) ;
802
803
} else if ( arg . customOptions . tokenProviderFn ) {
803
804
arg . customOptions . tokenProviderFn ( )
804
- . then (
805
- token => {
806
- fAuth . signInAndRetrieveDataWithCustomTokenCompletion ( token , onCompletionWithAuthResult ) ;
807
- } ,
808
- error => {
809
- reject ( error ) ;
810
- }
811
- ) ;
805
+ . then (
806
+ token => {
807
+ fAuth . signInAndRetrieveDataWithCustomTokenCompletion ( token , onCompletionWithAuthResult ) ;
808
+ } ,
809
+ error => {
810
+ reject ( error ) ;
811
+ }
812
+ ) ;
812
813
}
813
814
814
815
} else if ( arg . type === firebase . LoginType . FACEBOOK ) {
@@ -856,9 +857,9 @@ firebase.login = arg => {
856
857
}
857
858
858
859
fbSDKLoginManager . logInWithReadPermissionsFromViewControllerHandler (
859
- scope ,
860
- null , // the viewcontroller param can be null since by default topmost is taken
861
- onFacebookCompletion ) ;
860
+ scope ,
861
+ null , // the viewcontroller param can be null since by default topmost is taken
862
+ onFacebookCompletion ) ;
862
863
863
864
} else if ( arg . type === firebase . LoginType . GOOGLE ) {
864
865
if ( typeof ( GIDSignIn ) === "undefined" ) {
@@ -1194,15 +1195,15 @@ firebase.addValueEventListener = (updateCallback, path) => {
1194
1195
try {
1195
1196
const where = path === undefined ? FIRDatabase . database ( ) . reference ( ) : FIRDatabase . database ( ) . reference ( ) . childByAppendingPath ( path ) ;
1196
1197
const listener = where . observeEventTypeWithBlockWithCancelBlock (
1197
- FIRDataEventType . Value ,
1198
- snapshot => {
1199
- updateCallback ( firebase . getCallbackData ( 'ValueChanged' , snapshot ) ) ;
1200
- } ,
1201
- firebaseError => {
1202
- updateCallback ( {
1203
- error : firebaseError . localizedDescription
1198
+ FIRDataEventType . Value ,
1199
+ snapshot => {
1200
+ updateCallback ( firebase . getCallbackData ( 'ValueChanged' , snapshot ) ) ;
1201
+ } ,
1202
+ firebaseError => {
1203
+ updateCallback ( {
1204
+ error : firebaseError . localizedDescription
1205
+ } ) ;
1204
1206
} ) ;
1205
- } ) ;
1206
1207
resolve ( {
1207
1208
path : path ,
1208
1209
listeners : [ listener ]
@@ -1219,13 +1220,13 @@ firebase.getValue = path => {
1219
1220
try {
1220
1221
const where = path === undefined ? FIRDatabase . database ( ) . reference ( ) : FIRDatabase . database ( ) . reference ( ) . childByAppendingPath ( path ) ;
1221
1222
const listener = where . observeSingleEventOfTypeWithBlockWithCancelBlock (
1222
- FIRDataEventType . Value ,
1223
- snapshot => {
1224
- resolve ( firebase . getCallbackData ( 'ValueChanged' , snapshot ) ) ;
1225
- } ,
1226
- firebaseError => {
1227
- reject ( firebaseError . localizedDescription ) ;
1228
- } ) ;
1223
+ FIRDataEventType . Value ,
1224
+ snapshot => {
1225
+ resolve ( firebase . getCallbackData ( 'ValueChanged' , snapshot ) ) ;
1226
+ } ,
1227
+ firebaseError => {
1228
+ reject ( firebaseError . localizedDescription ) ;
1229
+ } ) ;
1229
1230
} catch ( ex ) {
1230
1231
console . log ( "Error in firebase.getValue: " + ex ) ;
1231
1232
reject ( ex ) ;
@@ -1549,18 +1550,18 @@ firebase.firestore.WriteBatch = (nativeWriteBatch: FIRWriteBatch): firestore.Wri
1549
1550
fixSpecialFields ( data ) ;
1550
1551
nativeWriteBatch . setDataForDocumentMerge ( < any > data , documentRef . ios , options && options . merge ) ;
1551
1552
return this ;
1552
- }
1553
+ } ;
1553
1554
1554
1555
public update = ( documentRef : firestore . DocumentReference , data : firestore . UpdateData ) : firestore . WriteBatch => {
1555
1556
fixSpecialFields ( data ) ;
1556
1557
nativeWriteBatch . updateDataForDocument ( < any > data , documentRef . ios ) ;
1557
1558
return this ;
1558
- }
1559
+ } ;
1559
1560
1560
1561
public delete = ( documentRef : firestore . DocumentReference ) : firestore . WriteBatch => {
1561
1562
nativeWriteBatch . deleteDocument ( documentRef . ios ) ;
1562
1563
return this ;
1563
- }
1564
+ } ;
1564
1565
1565
1566
commit ( ) : Promise < void > {
1566
1567
return new Promise < void > ( ( resolve , reject ) => {
@@ -1612,11 +1613,11 @@ firebase.firestore.Transaction = (nativeTransaction: FIRTransaction): firestore.
1612
1613
firebase . firestore . runTransaction = ( updateFunction : ( transaction : firestore . Transaction ) => Promise < any > ) : Promise < void > => {
1613
1614
return new Promise < void > ( ( resolve , reject ) => {
1614
1615
FIRFirestore . firestore ( ) . runTransactionWithBlockCompletion (
1615
- ( nativeTransaction : FIRTransaction , err : any ) => {
1616
- const tx = new firebase . firestore . Transaction ( nativeTransaction ) ;
1617
- return updateFunction ( tx ) ;
1618
- } ,
1619
- ( result , error : NSError ) => error ? reject ( error . localizedDescription ) : resolve ( ) ) ;
1616
+ ( nativeTransaction : FIRTransaction , err : any ) => {
1617
+ const tx = new firebase . firestore . Transaction ( nativeTransaction ) ;
1618
+ return updateFunction ( tx ) ;
1619
+ } ,
1620
+ ( result , error : NSError ) => error ? reject ( error . localizedDescription ) : resolve ( ) ) ;
1620
1621
} ) ;
1621
1622
} ;
1622
1623
@@ -1740,24 +1741,24 @@ firebase.firestore.add = (collectionPath: string, document: any): Promise<firest
1740
1741
fixSpecialFields ( document ) ;
1741
1742
const defaultFirestore = FIRFirestore . firestore ( ) ;
1742
1743
const fIRDocumentReference = defaultFirestore
1743
- . collectionWithPath ( collectionPath )
1744
- . addDocumentWithDataCompletion ( document , ( error : NSError ) => {
1745
- if ( error ) {
1746
- reject ( error . localizedDescription ) ;
1747
- } else {
1748
- resolve ( {
1749
- discriminator : "docRef" ,
1750
- id : fIRDocumentReference . documentID ,
1751
- path : fIRDocumentReference . path ,
1752
- collection : cp => firebase . firestore . collection ( cp ) ,
1753
- set : ( data : any , options ?: firestore . SetOptions ) => firebase . firestore . set ( collectionPath , fIRDocumentReference . documentID , data , options ) ,
1754
- get : ( ) => firebase . firestore . getDocument ( collectionPath , fIRDocumentReference . documentID ) ,
1755
- update : ( data : any ) => firebase . firestore . update ( collectionPath , fIRDocumentReference . documentID , data ) ,
1756
- delete : ( ) => firebase . firestore . delete ( collectionPath , fIRDocumentReference . documentID ) ,
1757
- onSnapshot : ( callback : ( doc : DocumentSnapshot ) => void ) => firebase . firestore . onDocumentSnapshot ( fIRDocumentReference , callback )
1758
- } ) ;
1759
- }
1760
- } ) ;
1744
+ . collectionWithPath ( collectionPath )
1745
+ . addDocumentWithDataCompletion ( document , ( error : NSError ) => {
1746
+ if ( error ) {
1747
+ reject ( error . localizedDescription ) ;
1748
+ } else {
1749
+ resolve ( {
1750
+ discriminator : "docRef" ,
1751
+ id : fIRDocumentReference . documentID ,
1752
+ path : fIRDocumentReference . path ,
1753
+ collection : cp => firebase . firestore . collection ( cp ) ,
1754
+ set : ( data : any , options ?: firestore . SetOptions ) => firebase . firestore . set ( collectionPath , fIRDocumentReference . documentID , data , options ) ,
1755
+ get : ( ) => firebase . firestore . getDocument ( collectionPath , fIRDocumentReference . documentID ) ,
1756
+ update : ( data : any ) => firebase . firestore . update ( collectionPath , fIRDocumentReference . documentID , data ) ,
1757
+ delete : ( ) => firebase . firestore . delete ( collectionPath , fIRDocumentReference . documentID ) ,
1758
+ onSnapshot : ( callback : ( doc : DocumentSnapshot ) => void ) => firebase . firestore . onDocumentSnapshot ( fIRDocumentReference , callback )
1759
+ } ) ;
1760
+ }
1761
+ } ) ;
1761
1762
1762
1763
} catch ( ex ) {
1763
1764
console . log ( "Error in firebase.firestore.add: " + ex ) ;
@@ -1777,8 +1778,8 @@ firebase.firestore.set = (collectionPath: string, documentPath: string, document
1777
1778
fixSpecialFields ( document ) ;
1778
1779
1779
1780
const docRef : FIRDocumentReference = FIRFirestore . firestore ( )
1780
- . collectionWithPath ( collectionPath )
1781
- . documentWithPath ( documentPath ) ;
1781
+ . collectionWithPath ( collectionPath )
1782
+ . documentWithPath ( documentPath ) ;
1782
1783
1783
1784
if ( options && options . merge ) {
1784
1785
docRef . setDataMergeCompletion ( document , true , ( error : NSError ) => {
@@ -1816,7 +1817,9 @@ function fixSpecialFields(item) {
1816
1817
}
1817
1818
1818
1819
function fixSpecialField ( item ) : any {
1819
- if ( item === "SERVER_TIMESTAMP" ) {
1820
+ if ( item === null ) {
1821
+ return null ;
1822
+ } else if ( item === "SERVER_TIMESTAMP" ) {
1820
1823
return FIRFieldValue . fieldValueForServerTimestamp ( ) ;
1821
1824
} else if ( item instanceof FieldValue ) {
1822
1825
const fieldValue : FieldValue = item ;
@@ -1853,8 +1856,8 @@ firebase.firestore.update = (collectionPath: string, documentPath: string, docum
1853
1856
fixSpecialFields ( document ) ;
1854
1857
1855
1858
const docRef : FIRDocumentReference = FIRFirestore . firestore ( )
1856
- . collectionWithPath ( collectionPath )
1857
- . documentWithPath ( documentPath ) ;
1859
+ . collectionWithPath ( collectionPath )
1860
+ . documentWithPath ( documentPath ) ;
1858
1861
1859
1862
docRef . updateDataCompletion ( document , ( error : NSError ) => {
1860
1863
if ( error ) {
@@ -1879,8 +1882,8 @@ firebase.firestore.delete = (collectionPath: string, documentPath: string): Prom
1879
1882
}
1880
1883
1881
1884
const docRef : FIRDocumentReference = FIRFirestore . firestore ( )
1882
- . collectionWithPath ( collectionPath )
1883
- . documentWithPath ( documentPath ) ;
1885
+ . collectionWithPath ( collectionPath )
1886
+ . documentWithPath ( documentPath ) ;
1884
1887
1885
1888
docRef . deleteDocumentWithCompletion ( ( error : NSError ) => {
1886
1889
if ( error ) {
@@ -1907,14 +1910,14 @@ firebase.firestore.getCollection = (collectionPath: string): Promise<firestore.Q
1907
1910
1908
1911
const defaultFirestore = FIRFirestore . firestore ( ) ;
1909
1912
defaultFirestore
1910
- . collectionWithPath ( collectionPath )
1911
- . getDocumentsWithCompletion ( ( snapshot : FIRQuerySnapshot , error : NSError ) => {
1912
- if ( error ) {
1913
- reject ( error . localizedDescription ) ;
1914
- } else {
1915
- resolve ( new QuerySnapshot ( snapshot ) ) ;
1916
- }
1917
- } ) ;
1913
+ . collectionWithPath ( collectionPath )
1914
+ . getDocumentsWithCompletion ( ( snapshot : FIRQuerySnapshot , error : NSError ) => {
1915
+ if ( error ) {
1916
+ reject ( error . localizedDescription ) ;
1917
+ } else {
1918
+ resolve ( new QuerySnapshot ( snapshot ) ) ;
1919
+ }
1920
+ } ) ;
1918
1921
1919
1922
} catch ( ex ) {
1920
1923
console . log ( "Error in firebase.firestore.getCollection: " + ex ) ;
@@ -1936,15 +1939,15 @@ firebase.firestore.getDocument = (collectionPath: string, documentPath: string):
1936
1939
}
1937
1940
1938
1941
FIRFirestore . firestore ( )
1939
- . collectionWithPath ( collectionPath )
1940
- . documentWithPath ( documentPath )
1941
- . getDocumentWithCompletion ( ( snapshot : FIRDocumentSnapshot , error : NSError ) => {
1942
- if ( error ) {
1943
- reject ( error . localizedDescription ) ;
1944
- } else {
1945
- resolve ( new DocumentSnapshot ( snapshot ) ) ;
1946
- }
1947
- } ) ;
1942
+ . collectionWithPath ( collectionPath )
1943
+ . documentWithPath ( documentPath )
1944
+ . getDocumentWithCompletion ( ( snapshot : FIRDocumentSnapshot , error : NSError ) => {
1945
+ if ( error ) {
1946
+ reject ( error . localizedDescription ) ;
1947
+ } else {
1948
+ resolve ( new DocumentSnapshot ( snapshot ) ) ;
1949
+ }
1950
+ } ) ;
1948
1951
1949
1952
} catch ( ex ) {
1950
1953
console . log ( "Error in firebase.firestore.getDocument: " + ex ) ;
@@ -2099,10 +2102,14 @@ function convertDocRef(docRef: FIRDocumentReference): firestore.DocumentReferenc
2099
2102
2100
2103
function convertDocChangeType ( type : FIRDocumentChangeType ) {
2101
2104
switch ( type ) {
2102
- case FIRDocumentChangeType . Added : return 'added' ;
2103
- case FIRDocumentChangeType . Modified : return 'modified' ;
2104
- case FIRDocumentChangeType . Removed : return 'removed' ;
2105
- default : throw new Error ( 'Unknown DocumentChangeType' ) ;
2105
+ case FIRDocumentChangeType . Added :
2106
+ return 'added' ;
2107
+ case FIRDocumentChangeType . Modified :
2108
+ return 'modified' ;
2109
+ case FIRDocumentChangeType . Removed :
2110
+ return 'removed' ;
2111
+ default :
2112
+ throw new Error ( 'Unknown DocumentChangeType' ) ;
2106
2113
}
2107
2114
}
2108
2115
@@ -2113,9 +2120,8 @@ function convertDocument(qDoc: FIRQueryDocumentSnapshot): firestore.QueryDocumen
2113
2120
export class QuerySnapshot implements firestore . QuerySnapshot {
2114
2121
private _docSnapshots : firestore . QueryDocumentSnapshot [ ] ;
2115
2122
2116
- constructor (
2117
- private snapshot : FIRQuerySnapshot ,
2118
- ) { }
2123
+ constructor ( private snapshot : FIRQuerySnapshot ) {
2124
+ }
2119
2125
2120
2126
get docs ( ) : firestore . QueryDocumentSnapshot [ ] {
2121
2127
const getSnapshots = ( ) => {
@@ -2139,7 +2145,9 @@ export class QuerySnapshot implements firestore.QuerySnapshot {
2139
2145
docSnapshots = this . docs as firestore . DocumentSnapshot [ ] ; // It's safe to cast, as our document snapshot already has the data() method
2140
2146
2141
2147
docChanges ( options ?: firestore . SnapshotListenOptions ) : firestore . DocumentChange [ ] {
2142
- if ( options ) { console . info ( 'No options support yet, for docChanges()' ) ; }
2148
+ if ( options ) {
2149
+ console . info ( 'No options support yet, for docChanges()' ) ;
2150
+ }
2143
2151
const docChanges : firestore . DocumentChange [ ] = [ ] ;
2144
2152
const jChanges : NSArray < FIRDocumentChange > = this . snapshot . documentChanges ;
2145
2153
for ( let i = 0 ; i < jChanges . count ; i ++ ) {
0 commit comments