@@ -3,7 +3,9 @@ import { AndroidActivityResultEventData } from "tns-core-modules/application";
33import lazy from "tns-core-modules/utils/lazy" ;
44import { ad as AndroidUtils } from "tns-core-modules/utils/utils" ;
55import {
6- DataSnapshot , FBData , FBDataSingleEvent , FBErrorData , FirebaseQueryResult ,
6+ DataSnapshot ,
7+ FBDataSingleEvent ,
8+ FBErrorData ,
79 firestore ,
810 GetAuthTokenOptions ,
911 GetAuthTokenResult ,
@@ -27,6 +29,11 @@ const gmsTasks = (<any>com.google.android.gms).tasks;
2729class DocumentSnapshot extends DocumentSnapshotBase {
2830 android : com . google . firebase . firestore . DocumentSnapshot ;
2931
32+ metadata = {
33+ fromCache : this . snapshot . getMetadata ( ) . isFromCache ( ) ,
34+ hasPendingWrites : this . snapshot . getMetadata ( ) . hasPendingWrites ( )
35+ } ;
36+
3037 constructor ( public snapshot : com . google . firebase . firestore . DocumentSnapshot ) {
3138 super ( snapshot ? snapshot . getId ( ) : null , snapshot . exists ( ) , firebase . toJsObject ( snapshot . getData ( ) ) , convertDocRef ( snapshot . getReference ( ) ) ) ;
3239 this . android = snapshot ;
@@ -2229,7 +2236,7 @@ firebase.firestore.collection = (collectionPath: string): firestore.CollectionRe
22292236 where : ( fieldPath : string , opStr : firestore . WhereFilterOp , value : any ) => firebase . firestore . where ( collectionPath , fieldPath , opStr , value ) ,
22302237 orderBy : ( fieldPath : string , directionStr : firestore . OrderByDirection ) : firestore . Query => firebase . firestore . orderBy ( collectionPath , fieldPath , directionStr , collectionRef ) ,
22312238 limit : ( limit : number ) : firestore . Query => firebase . firestore . limit ( collectionPath , limit , collectionRef ) ,
2232- onSnapshot : ( optionsOrCallback : any , callback ?: ( snapshot : QuerySnapshot ) => void ) => firebase . firestore . onCollectionSnapshot ( collectionRef , optionsOrCallback , callback ) ,
2239+ onSnapshot : ( optionsOrCallback : firestore . SnapshotListenOptions | ( ( snapshot : QuerySnapshot ) => void ) , callback ?: ( snapshot : QuerySnapshot ) => void ) => firebase . firestore . onCollectionSnapshot ( collectionRef , optionsOrCallback , callback ) ,
22332240 startAfter : ( snapshot : DocumentSnapshot ) : firestore . Query => firebase . firestore . startAfter ( collectionPath , snapshot , collectionRef ) ,
22342241 startAt : ( snapshot : DocumentSnapshot ) : firestore . Query => firebase . firestore . startAt ( collectionPath , snapshot , collectionRef ) ,
22352242 endAt : ( snapshot : DocumentSnapshot ) : firestore . Query => firebase . firestore . endAt ( collectionPath , snapshot , collectionRef ) ,
@@ -2242,9 +2249,16 @@ firebase.firestore.collection = (collectionPath: string): firestore.CollectionRe
22422249 }
22432250} ;
22442251
2245- firebase . firestore . onDocumentSnapshot = ( docRef : com . google . firebase . firestore . DocumentReference , callback : ( doc : DocumentSnapshot ) => void ) : ( ) => void => {
2246- const listener = docRef . addSnapshotListener ( new com . google . firebase . firestore . EventListener ( {
2247- onEvent : ( ( snapshot : com . google . firebase . firestore . DocumentSnapshot , exception ) => {
2252+ firebase . firestore . onDocumentSnapshot = ( docRef : com . google . firebase . firestore . DocumentReference , optionsOrCallback : firestore . SnapshotListenOptions | ( ( snapshot : DocumentSnapshot ) => void ) , callback : ( doc : DocumentSnapshot ) => void ) : ( ) => void => {
2253+ let options = com . google . firebase . firestore . MetadataChanges . EXCLUDE ;
2254+ if ( ( typeof optionsOrCallback ) === "function" ) {
2255+ callback = < ( snapshot : DocumentSnapshot ) => void > optionsOrCallback ;
2256+ } else if ( ( < firestore . SnapshotListenOptions > optionsOrCallback ) . includeMetadataChanges ) {
2257+ options = com . google . firebase . firestore . MetadataChanges . INCLUDE ;
2258+ }
2259+
2260+ const listener = docRef . addSnapshotListener ( options , new com . google . firebase . firestore . EventListener ( {
2261+ onEvent : ( ( snapshot : com . google . firebase . firestore . DocumentSnapshot , exception : com . google . firebase . firestore . FirebaseFirestoreException ) => {
22482262 if ( exception === null ) {
22492263 callback ( new DocumentSnapshot ( snapshot ) ) ;
22502264 }
@@ -2255,11 +2269,11 @@ firebase.firestore.onDocumentSnapshot = (docRef: com.google.firebase.firestore.D
22552269 return ( ) => listener . remove ( ) ;
22562270} ;
22572271
2258- firebase . firestore . onCollectionSnapshot = ( colRef : com . google . firebase . firestore . CollectionReference , optionsOrCallback : any , callback : ( snapshot : QuerySnapshot ) => void ) : ( ) => void => {
2272+ firebase . firestore . onCollectionSnapshot = ( colRef : com . google . firebase . firestore . CollectionReference , optionsOrCallback : firestore . SnapshotListenOptions | ( ( snapshot : QuerySnapshot ) => void ) , callback : ( snapshot : QuerySnapshot ) => void ) : ( ) => void => {
22592273 let options = com . google . firebase . firestore . MetadataChanges . EXCLUDE ;
2260- if ( ( typeof optionsOrCallback ) === ' function' ) {
2261- callback = optionsOrCallback ;
2262- } else if ( optionsOrCallback . includeMetadataChanges ) {
2274+ if ( ( typeof optionsOrCallback ) === " function" ) {
2275+ callback = < ( snapshot : QuerySnapshot ) => void > optionsOrCallback ;
2276+ } else if ( ( < firestore . SnapshotListenOptions > optionsOrCallback ) . includeMetadataChanges ) {
22632277 options = com . google . firebase . firestore . MetadataChanges . INCLUDE ;
22642278 }
22652279
@@ -2288,7 +2302,7 @@ firebase.firestore._getDocumentReference = (javaObj: JDocumentReference, collect
22882302 get : ( ) => firebase . firestore . getDocument ( collectionPath , javaObj . getId ( ) ) ,
22892303 update : ( data : any ) => firebase . firestore . update ( collectionPath , javaObj . getId ( ) , data ) ,
22902304 delete : ( ) => firebase . firestore . delete ( collectionPath , javaObj . getId ( ) ) ,
2291- onSnapshot : ( callback : ( doc : DocumentSnapshot ) => void ) => firebase . firestore . onDocumentSnapshot ( javaObj , callback ) ,
2305+ onSnapshot : ( optionsOrCallback : firestore . SnapshotListenOptions | ( ( snapshot : DocumentSnapshot ) => void ) , callback : ( doc : DocumentSnapshot ) => void ) => firebase . firestore . onDocumentSnapshot ( javaObj , optionsOrCallback , callback ) ,
22922306 android : javaObj
22932307 } ;
22942308} ;
@@ -2349,7 +2363,7 @@ firebase.firestore.add = (collectionPath: string, document: any): Promise<firest
23492363 get : ( ) => firebase . firestore . getDocument ( collectionPath , docRef . getId ( ) ) ,
23502364 update : ( data : any ) => firebase . firestore . update ( collectionPath , docRef . getId ( ) , data ) ,
23512365 delete : ( ) => firebase . firestore . delete ( collectionPath , docRef . getId ( ) ) ,
2352- onSnapshot : ( callback : ( doc : DocumentSnapshot ) => void ) => firebase . firestore . onDocumentSnapshot ( docRef , callback )
2366+ onSnapshot : ( optionsOrCallback : firestore . SnapshotListenOptions | ( ( snapshot : DocumentSnapshot ) => void ) , callback : ( doc : DocumentSnapshot ) => void ) => firebase . firestore . onDocumentSnapshot ( docRef , optionsOrCallback , callback )
23532367 } ) ;
23542368 }
23552369 } ) ;
@@ -2565,7 +2579,7 @@ firebase.firestore._getQuery = (collectionPath: string, query: com.google.fireba
25652579 where : ( fp : string , os : firestore . WhereFilterOp , v : any ) : firestore . Query => firebase . firestore . where ( collectionPath , fp , os , v , query ) ,
25662580 orderBy : ( fp : string , directionStr : firestore . OrderByDirection ) : firestore . Query => firebase . firestore . orderBy ( collectionPath , fp , directionStr , query ) ,
25672581 limit : ( limit : number ) : firestore . Query => firebase . firestore . limit ( collectionPath , limit , query ) ,
2568- onSnapshot : ( optionsOrCallback : any , callback ?: ( snapshot : QuerySnapshot ) => void ) => firebase . firestore . onCollectionSnapshot ( query , optionsOrCallback , callback ) ,
2582+ onSnapshot : ( optionsOrCallback : firestore . SnapshotListenOptions | ( ( snapshot : QuerySnapshot ) => void ) , callback ?: ( snapshot : QuerySnapshot ) => void ) => firebase . firestore . onCollectionSnapshot ( query , optionsOrCallback , callback ) ,
25692583 startAfter : ( snapshot : DocumentSnapshot ) => firebase . firestore . startAfter ( collectionPath , snapshot , query ) ,
25702584 startAt : ( snapshot : DocumentSnapshot ) => firebase . firestore . startAt ( collectionPath , snapshot , query ) ,
25712585 endAt : ( snapshot : DocumentSnapshot ) => firebase . firestore . endAt ( collectionPath , snapshot , query ) ,
@@ -2649,7 +2663,7 @@ function convertDocRef(docRef: JDocumentReference): firestore.DocumentReference
26492663 get : ( ) => firebase . firestore . getDocument ( collectionPath , docRef . getId ( ) ) ,
26502664 update : ( data : any ) => firebase . firestore . update ( collectionPath , docRef . getId ( ) , data ) ,
26512665 delete : ( ) => firebase . firestore . delete ( collectionPath , docRef . getId ( ) ) ,
2652- onSnapshot : ( callback : ( doc : DocumentSnapshot ) => void ) => firebase . firestore . onDocumentSnapshot ( docRef , callback ) ,
2666+ onSnapshot : ( optionsOrCallback : firestore . SnapshotListenOptions | ( ( doc : DocumentSnapshot ) => void ) , callback : ( doc : DocumentSnapshot ) => void ) => firebase . firestore . onDocumentSnapshot ( docRef , optionsOrCallback , callback ) ,
26532667 android : docRef
26542668 } ;
26552669}
@@ -2679,6 +2693,7 @@ export class QuerySnapshot implements firestore.QuerySnapshot {
26792693
26802694 metadata = {
26812695 fromCache : this . snapshot . getMetadata ( ) . isFromCache ( ) ,
2696+ hasPendingWrites : this . snapshot . getMetadata ( ) . hasPendingWrites ( )
26822697 } ;
26832698
26842699 get docs ( ) : firestore . QueryDocumentSnapshot [ ] {
0 commit comments