@@ -36,7 +36,7 @@ class DocumentSnapshot extends DocumentSnapshotBase {
3636 } ;
3737
3838 constructor ( public snapshot : com . google . firebase . firestore . DocumentSnapshot ) {
39- super ( snapshot ? snapshot . getId ( ) : null , snapshot . exists ( ) , firebase . toJsObject ( snapshot . getData ( ) ) , convertDocRef ( snapshot . getReference ( ) ) ) ;
39+ super ( snapshot ? snapshot . getId ( ) : null , snapshot . exists ( ) , firebase . toJsObject ( snapshot . getData ( ) ) , firebase . firestore . _getDocumentReference ( snapshot . getReference ( ) ) ) ;
4040 this . android = snapshot ;
4141 }
4242}
@@ -2265,23 +2265,7 @@ firebase.firestore.collection = (collectionPath: string): firestore.CollectionRe
22652265 }
22662266
22672267 const db = com . google . firebase . firestore . FirebaseFirestore . getInstance ( ) ;
2268- const collectionRef : com . google . firebase . firestore . CollectionReference = db . collection ( collectionPath ) ;
2269-
2270- return {
2271- id : collectionRef . getId ( ) ,
2272- doc : ( documentPath ?: string ) => firebase . firestore . doc ( collectionPath , documentPath ) ,
2273- add : document => firebase . firestore . add ( collectionPath , document ) ,
2274- get : ( ) => firebase . firestore . get ( collectionPath ) ,
2275- where : ( fieldPath : string , opStr : firestore . WhereFilterOp , value : any ) => firebase . firestore . where ( collectionPath , fieldPath , opStr , value ) ,
2276- orderBy : ( fieldPath : string , directionStr : firestore . OrderByDirection ) : firestore . Query => firebase . firestore . orderBy ( collectionPath , fieldPath , directionStr , collectionRef ) ,
2277- limit : ( limit : number ) : firestore . Query => firebase . firestore . limit ( collectionPath , limit , collectionRef ) ,
2278- onSnapshot : ( optionsOrCallback : firestore . SnapshotListenOptions | ( ( snapshot : QuerySnapshot ) => void ) , callbackOrOnError ?: ( snapshotOrError : QuerySnapshot | Error ) => void , onError ?: ( error : Error ) => void ) => firebase . firestore . onCollectionSnapshot ( collectionRef , optionsOrCallback , callbackOrOnError , onError ) ,
2279- startAfter : ( snapshot : DocumentSnapshot ) : firestore . Query => firebase . firestore . startAfter ( collectionPath , snapshot , collectionRef ) ,
2280- startAt : ( snapshot : DocumentSnapshot ) : firestore . Query => firebase . firestore . startAt ( collectionPath , snapshot , collectionRef ) ,
2281- endAt : ( snapshot : DocumentSnapshot ) : firestore . Query => firebase . firestore . endAt ( collectionPath , snapshot , collectionRef ) ,
2282- endBefore : ( snapshot : DocumentSnapshot ) : firestore . Query => firebase . firestore . endBefore ( collectionPath , snapshot , collectionRef ) ,
2283- } ;
2284-
2268+ return firebase . firestore . _getCollectionReference ( db . collection ( collectionPath ) ) ;
22852269 } catch ( ex ) {
22862270 console . log ( "Error in firebase.firestore.collection: " + ex ) ;
22872271 return null ;
@@ -2351,19 +2335,49 @@ firebase.firestore.onCollectionSnapshot = (colRef: com.google.firebase.firestore
23512335 return ( ) => listener . remove ( ) ;
23522336} ;
23532337
2354- firebase . firestore . _getDocumentReference = ( javaObj : JDocumentReference , collectionPath , documentPath ) : firestore . DocumentReference => {
2338+ firebase . firestore . _getDocumentReference = ( docRef ?: JDocumentReference ) : firestore . DocumentReference => {
2339+ if ( ! docRef ) {
2340+ return null ;
2341+ }
2342+
2343+ const collectionPath = docRef . getParent ( ) . getPath ( ) ;
2344+
23552345 return {
23562346 discriminator : "docRef" ,
2357- id : javaObj . getId ( ) ,
2358- path : javaObj . getPath ( ) ,
2359- collection : cp => firebase . firestore . collection ( `${ collectionPath } /${ documentPath } /${ cp } ` ) ,
2360- set : ( data : any , options ?: firestore . SetOptions ) => firebase . firestore . set ( collectionPath , javaObj . getId ( ) , data , options ) ,
2361- get : ( ) => firebase . firestore . getDocument ( collectionPath , javaObj . getId ( ) ) ,
2362- update : ( data : any ) => firebase . firestore . update ( collectionPath , javaObj . getId ( ) , data ) ,
2363- delete : ( ) => firebase . firestore . delete ( collectionPath , javaObj . getId ( ) ) ,
2364- onSnapshot : ( optionsOrCallback : firestore . SnapshotListenOptions | ( ( snapshot : DocumentSnapshot ) => void ) , callbackOrOnError ?: ( docOrError : DocumentSnapshot | Error ) => void ,
2365- onError ?: ( error : Error ) => void ) => firebase . firestore . onDocumentSnapshot ( javaObj , optionsOrCallback , callbackOrOnError , onError ) ,
2366- android : javaObj
2347+ id : docRef . getId ( ) ,
2348+ parent : firebase . firestore . _getCollectionReference ( docRef . getParent ( ) ) ,
2349+ path : docRef . getPath ( ) ,
2350+ collection : cp => firebase . firestore . collection ( `${ collectionPath } /${ docRef . getId ( ) } /${ cp } ` ) ,
2351+ set : ( data : any , options ?: firestore . SetOptions ) => firebase . firestore . set ( collectionPath , docRef . getId ( ) , data , options ) ,
2352+ get : ( ) => firebase . firestore . getDocument ( collectionPath , docRef . getId ( ) ) ,
2353+ update : ( data : any ) => firebase . firestore . update ( collectionPath , docRef . getId ( ) , data ) ,
2354+ delete : ( ) => firebase . firestore . delete ( collectionPath , docRef . getId ( ) ) ,
2355+ onSnapshot : ( optionsOrCallback : firestore . SnapshotListenOptions | ( ( snapshot : DocumentSnapshot ) => void ) , callbackOrOnError ?: ( docOrError : DocumentSnapshot | Error ) => void , onError ?: ( error : Error ) => void ) => firebase . firestore . onDocumentSnapshot ( javaObj , optionsOrCallback , callbackOrOnError , onError ) ,
2356+ android : docRef
2357+ } ;
2358+ } ;
2359+
2360+ firebase . firestore . _getCollectionReference = ( colRef ?: JCollectionReference ) : firestore . CollectionReference => {
2361+ if ( ! colRef ) {
2362+ return null ;
2363+ }
2364+
2365+ const collectionPath = colRef . getPath ( ) ;
2366+
2367+ return {
2368+ id : colRef . getId ( ) ,
2369+ parent : firebase . firestore . _getDocumentReference ( colRef . getParent ( ) ) ,
2370+ doc : ( documentPath ?: string ) => firebase . firestore . doc ( collectionPath , documentPath ) ,
2371+ add : document => firebase . firestore . add ( collectionPath , document ) ,
2372+ get : ( ) => firebase . firestore . get ( collectionPath ) ,
2373+ where : ( fieldPath : string , opStr : firestore . WhereFilterOp , value : any ) => firebase . firestore . where ( collectionPath , fieldPath , opStr , value ) ,
2374+ orderBy : ( fieldPath : string , directionStr : firestore . OrderByDirection ) : firestore . Query => firebase . firestore . orderBy ( collectionPath , fieldPath , directionStr , colRef ) ,
2375+ limit : ( limit : number ) : firestore . Query => firebase . firestore . limit ( collectionPath , limit , colRef ) ,
2376+ onSnapshot : ( optionsOrCallback : firestore . SnapshotListenOptions | ( ( snapshot : QuerySnapshot ) => void ) , callback ?: ( snapshot : QuerySnapshot ) => void ) => firebase . firestore . onCollectionSnapshot ( colRef , optionsOrCallback , callback ) ,
2377+ startAfter : ( snapshot : DocumentSnapshot ) : firestore . Query => firebase . firestore . startAfter ( collectionPath , snapshot , colRef ) ,
2378+ startAt : ( snapshot : DocumentSnapshot ) : firestore . Query => firebase . firestore . startAt ( collectionPath , snapshot , colRef ) ,
2379+ endAt : ( snapshot : DocumentSnapshot ) : firestore . Query => firebase . firestore . endAt ( collectionPath , snapshot , colRef ) ,
2380+ endBefore : ( snapshot : DocumentSnapshot ) : firestore . Query => firebase . firestore . endBefore ( collectionPath , snapshot , colRef ) ,
23672381 } ;
23682382} ;
23692383
@@ -2382,7 +2396,7 @@ firebase.firestore.doc = (collectionPath: string, documentPath?: string): firest
23822396 const db = com . google . firebase . firestore . FirebaseFirestore . getInstance ( ) ;
23832397 const colRef : com . google . firebase . firestore . CollectionReference = db . collection ( collectionPath ) ;
23842398 const docRef : com . google . firebase . firestore . DocumentReference = documentPath ? colRef . document ( documentPath ) : colRef . document ( ) ;
2385- return firebase . firestore . _getDocumentReference ( docRef , collectionPath , documentPath ) ;
2399+ return firebase . firestore . _getDocumentReference ( docRef ) ;
23862400 } catch ( ex ) {
23872401 console . log ( "Error in firebase.firestore.doc: " + ex ) ;
23882402 return null ;
@@ -2396,9 +2410,7 @@ firebase.firestore.docRef = (documentPath: string): firestore.DocumentReference
23962410 }
23972411
23982412 const db : com . google . firebase . firestore . FirebaseFirestore = com . google . firebase . firestore . FirebaseFirestore . getInstance ( ) ;
2399- const docRef : JDocumentReference = db . document ( documentPath ) ;
2400-
2401- return convertDocRef ( docRef ) ;
2413+ return firebase . firestore . _getDocumentReference ( db . document ( documentPath ) ) ;
24022414} ;
24032415
24042416firebase . firestore . add = ( collectionPath : string , document : any ) : Promise < firestore . DocumentReference > => {
@@ -2414,18 +2426,7 @@ firebase.firestore.add = (collectionPath: string, document: any): Promise<firest
24142426
24152427 const onSuccessListener = new gmsTasks . OnSuccessListener ( {
24162428 onSuccess : ( docRef : com . google . firebase . firestore . DocumentReference ) => {
2417- resolve ( {
2418- discriminator : "docRef" ,
2419- id : docRef . getId ( ) ,
2420- path : docRef . getPath ( ) ,
2421- collection : cp => firebase . firestore . collection ( cp ) ,
2422- set : ( data : any , options ?: firestore . SetOptions ) => firebase . firestore . set ( collectionPath , docRef . getId ( ) , data , options ) ,
2423- get : ( ) => firebase . firestore . getDocument ( collectionPath , docRef . getId ( ) ) ,
2424- update : ( data : any ) => firebase . firestore . update ( collectionPath , docRef . getId ( ) , data ) ,
2425- delete : ( ) => firebase . firestore . delete ( collectionPath , docRef . getId ( ) ) ,
2426- onSnapshot : ( optionsOrCallback : firestore . SnapshotListenOptions | ( ( snapshot : DocumentSnapshot ) => void ) , callbackOrOnError ?: ( docOrError : DocumentSnapshot | Error ) => void ,
2427- onError ?: ( error : Error ) => void ) => firebase . firestore . onDocumentSnapshot ( docRef , optionsOrCallback , callbackOrOnError , onError )
2428- } ) ;
2429+ resolve ( firebase . firestore . _getDocumentReference ( docRef ) )
24292430 }
24302431 } ) ;
24312432
@@ -2711,24 +2712,7 @@ firebase.firestore.endBefore = (collectionPath: string, snapshot: DocumentSnapsh
27112712} ;
27122713
27132714export type JDocumentReference = com . google . firebase . firestore . DocumentReference ;
2714-
2715- function convertDocRef ( docRef : JDocumentReference ) : firestore . DocumentReference {
2716- const collectionPath = docRef . getParent ( ) . getPath ( ) ;
2717-
2718- return {
2719- discriminator : "docRef" ,
2720- id : docRef . getId ( ) ,
2721- path : docRef . getPath ( ) ,
2722- collection : cp => firebase . firestore . collection ( `${ collectionPath } /${ docRef . getId ( ) } /${ cp } ` ) ,
2723- set : ( data : any , options ?: firestore . SetOptions ) => firebase . firestore . set ( collectionPath , docRef . getId ( ) , data , options ) ,
2724- get : ( ) => firebase . firestore . getDocument ( collectionPath , docRef . getId ( ) ) ,
2725- update : ( data : any ) => firebase . firestore . update ( collectionPath , docRef . getId ( ) , data ) ,
2726- delete : ( ) => firebase . firestore . delete ( collectionPath , docRef . getId ( ) ) ,
2727- onSnapshot : ( optionsOrCallback : firestore . SnapshotListenOptions | ( ( snapshot : DocumentSnapshot ) => void ) , callbackOrOnError ?: ( docOrError : DocumentSnapshot | Error ) => void ,
2728- onError ?: ( error : Error ) => void ) => firebase . firestore . onDocumentSnapshot ( docRef , optionsOrCallback , callbackOrOnError , onError ) ,
2729- android : docRef
2730- } ;
2731- }
2715+ export type JCollectionReference = com . google . firebase . firestore . CollectionReference ;
27322716
27332717function convertDocChangeType ( type : com . google . firebase . firestore . DocumentChange . Type ) {
27342718 switch ( type ) {
0 commit comments