@@ -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 ) , callback ?: ( snapshot : QuerySnapshot ) => void ) => firebase . firestore . onCollectionSnapshot ( collectionRef , optionsOrCallback , callback ) ,
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 ;
@@ -2331,18 +2315,49 @@ firebase.firestore.onCollectionSnapshot = (colRef: com.google.firebase.firestore
23312315 return ( ) => listener . remove ( ) ;
23322316} ;
23332317
2334- firebase . firestore . _getDocumentReference = ( javaObj : JDocumentReference , collectionPath , documentPath ) : firestore . DocumentReference => {
2318+ firebase . firestore . _getDocumentReference = ( docRef ?: JDocumentReference ) : firestore . DocumentReference => {
2319+ if ( ! docRef ) {
2320+ return null ;
2321+ }
2322+
2323+ const collectionPath = docRef . getParent ( ) . getPath ( ) ;
2324+
23352325 return {
23362326 discriminator : "docRef" ,
2337- id : javaObj . getId ( ) ,
2338- path : javaObj . getPath ( ) ,
2339- collection : cp => firebase . firestore . collection ( `${ collectionPath } /${ documentPath } /${ cp } ` ) ,
2340- set : ( data : any , options ?: firestore . SetOptions ) => firebase . firestore . set ( collectionPath , javaObj . getId ( ) , data , options ) ,
2341- get : ( ) => firebase . firestore . getDocument ( collectionPath , javaObj . getId ( ) ) ,
2342- update : ( data : any ) => firebase . firestore . update ( collectionPath , javaObj . getId ( ) , data ) ,
2343- delete : ( ) => firebase . firestore . delete ( collectionPath , javaObj . getId ( ) ) ,
2344- onSnapshot : ( optionsOrCallback : firestore . SnapshotListenOptions | ( ( snapshot : DocumentSnapshot ) => void ) , callback : ( doc : DocumentSnapshot ) => void ) => firebase . firestore . onDocumentSnapshot ( javaObj , optionsOrCallback , callback ) ,
2345- android : javaObj
2327+ id : docRef . getId ( ) ,
2328+ parent : firebase . firestore . _getCollectionReference ( docRef . getParent ( ) ) ,
2329+ path : docRef . getPath ( ) ,
2330+ collection : cp => firebase . firestore . collection ( `${ collectionPath } /${ docRef . getId ( ) } /${ cp } ` ) ,
2331+ set : ( data : any , options ?: firestore . SetOptions ) => firebase . firestore . set ( collectionPath , docRef . getId ( ) , data , options ) ,
2332+ get : ( ) => firebase . firestore . getDocument ( collectionPath , docRef . getId ( ) ) ,
2333+ update : ( data : any ) => firebase . firestore . update ( collectionPath , docRef . getId ( ) , data ) ,
2334+ delete : ( ) => firebase . firestore . delete ( collectionPath , docRef . getId ( ) ) ,
2335+ onSnapshot : ( optionsOrCallback : firestore . SnapshotListenOptions | ( ( doc : DocumentSnapshot ) => void ) , callback : ( doc : DocumentSnapshot ) => void ) => firebase . firestore . onDocumentSnapshot ( docRef , optionsOrCallback , callback ) ,
2336+ android : docRef
2337+ } ;
2338+ } ;
2339+
2340+ firebase . firestore . _getCollectionReference = ( colRef ?: JCollectionReference ) : firestore . CollectionReference => {
2341+ if ( ! colRef ) {
2342+ return null ;
2343+ }
2344+
2345+ const collectionPath = colRef . getPath ( ) ;
2346+
2347+ return {
2348+ id : colRef . getId ( ) ,
2349+ parent : firebase . firestore . _getDocumentReference ( colRef . getParent ( ) ) ,
2350+ doc : ( documentPath ?: string ) => firebase . firestore . doc ( collectionPath , documentPath ) ,
2351+ add : document => firebase . firestore . add ( collectionPath , document ) ,
2352+ get : ( ) => firebase . firestore . get ( collectionPath ) ,
2353+ where : ( fieldPath : string , opStr : firestore . WhereFilterOp , value : any ) => firebase . firestore . where ( collectionPath , fieldPath , opStr , value ) ,
2354+ orderBy : ( fieldPath : string , directionStr : firestore . OrderByDirection ) : firestore . Query => firebase . firestore . orderBy ( collectionPath , fieldPath , directionStr , colRef ) ,
2355+ limit : ( limit : number ) : firestore . Query => firebase . firestore . limit ( collectionPath , limit , colRef ) ,
2356+ onSnapshot : ( optionsOrCallback : firestore . SnapshotListenOptions | ( ( snapshot : QuerySnapshot ) => void ) , callback ?: ( snapshot : QuerySnapshot ) => void ) => firebase . firestore . onCollectionSnapshot ( colRef , optionsOrCallback , callback ) ,
2357+ startAfter : ( snapshot : DocumentSnapshot ) : firestore . Query => firebase . firestore . startAfter ( collectionPath , snapshot , colRef ) ,
2358+ startAt : ( snapshot : DocumentSnapshot ) : firestore . Query => firebase . firestore . startAt ( collectionPath , snapshot , colRef ) ,
2359+ endAt : ( snapshot : DocumentSnapshot ) : firestore . Query => firebase . firestore . endAt ( collectionPath , snapshot , colRef ) ,
2360+ endBefore : ( snapshot : DocumentSnapshot ) : firestore . Query => firebase . firestore . endBefore ( collectionPath , snapshot , colRef ) ,
23462361 } ;
23472362} ;
23482363
@@ -2361,7 +2376,7 @@ firebase.firestore.doc = (collectionPath: string, documentPath?: string): firest
23612376 const db = com . google . firebase . firestore . FirebaseFirestore . getInstance ( ) ;
23622377 const colRef : com . google . firebase . firestore . CollectionReference = db . collection ( collectionPath ) ;
23632378 const docRef : com . google . firebase . firestore . DocumentReference = documentPath ? colRef . document ( documentPath ) : colRef . document ( ) ;
2364- return firebase . firestore . _getDocumentReference ( docRef , collectionPath , documentPath ) ;
2379+ return firebase . firestore . _getDocumentReference ( docRef ) ;
23652380 } catch ( ex ) {
23662381 console . log ( "Error in firebase.firestore.doc: " + ex ) ;
23672382 return null ;
@@ -2375,9 +2390,7 @@ firebase.firestore.docRef = (documentPath: string): firestore.DocumentReference
23752390 }
23762391
23772392 const db : com . google . firebase . firestore . FirebaseFirestore = com . google . firebase . firestore . FirebaseFirestore . getInstance ( ) ;
2378- const docRef : JDocumentReference = db . document ( documentPath ) ;
2379-
2380- return convertDocRef ( docRef ) ;
2393+ return firebase . firestore . _getDocumentReference ( db . document ( documentPath ) ) ;
23812394} ;
23822395
23832396firebase . firestore . add = ( collectionPath : string , document : any ) : Promise < firestore . DocumentReference > => {
@@ -2393,17 +2406,7 @@ firebase.firestore.add = (collectionPath: string, document: any): Promise<firest
23932406
23942407 const onSuccessListener = new gmsTasks . OnSuccessListener ( {
23952408 onSuccess : ( docRef : com . google . firebase . firestore . DocumentReference ) => {
2396- resolve ( {
2397- discriminator : "docRef" ,
2398- id : docRef . getId ( ) ,
2399- path : docRef . getPath ( ) ,
2400- collection : cp => firebase . firestore . collection ( cp ) ,
2401- set : ( data : any , options ?: firestore . SetOptions ) => firebase . firestore . set ( collectionPath , docRef . getId ( ) , data , options ) ,
2402- get : ( ) => firebase . firestore . getDocument ( collectionPath , docRef . getId ( ) ) ,
2403- update : ( data : any ) => firebase . firestore . update ( collectionPath , docRef . getId ( ) , data ) ,
2404- delete : ( ) => firebase . firestore . delete ( collectionPath , docRef . getId ( ) ) ,
2405- onSnapshot : ( optionsOrCallback : firestore . SnapshotListenOptions | ( ( snapshot : DocumentSnapshot ) => void ) , callback : ( doc : DocumentSnapshot ) => void ) => firebase . firestore . onDocumentSnapshot ( docRef , optionsOrCallback , callback )
2406- } ) ;
2409+ resolve ( firebase . firestore . _getDocumentReference ( docRef ) )
24072410 }
24082411 } ) ;
24092412
@@ -2689,23 +2692,7 @@ firebase.firestore.endBefore = (collectionPath: string, snapshot: DocumentSnapsh
26892692} ;
26902693
26912694export type JDocumentReference = com . google . firebase . firestore . DocumentReference ;
2692-
2693- function convertDocRef ( docRef : JDocumentReference ) : firestore . DocumentReference {
2694- const collectionPath = docRef . getParent ( ) . getPath ( ) ;
2695-
2696- return {
2697- discriminator : "docRef" ,
2698- id : docRef . getId ( ) ,
2699- path : docRef . getPath ( ) ,
2700- collection : cp => firebase . firestore . collection ( `${ collectionPath } /${ docRef . getId ( ) } /${ cp } ` ) ,
2701- set : ( data : any , options ?: firestore . SetOptions ) => firebase . firestore . set ( collectionPath , docRef . getId ( ) , data , options ) ,
2702- get : ( ) => firebase . firestore . getDocument ( collectionPath , docRef . getId ( ) ) ,
2703- update : ( data : any ) => firebase . firestore . update ( collectionPath , docRef . getId ( ) , data ) ,
2704- delete : ( ) => firebase . firestore . delete ( collectionPath , docRef . getId ( ) ) ,
2705- onSnapshot : ( optionsOrCallback : firestore . SnapshotListenOptions | ( ( doc : DocumentSnapshot ) => void ) , callback : ( doc : DocumentSnapshot ) => void ) => firebase . firestore . onDocumentSnapshot ( docRef , optionsOrCallback , callback ) ,
2706- android : docRef
2707- } ;
2708- }
2695+ export type JCollectionReference = com . google . firebase . firestore . CollectionReference ;
27092696
27102697function convertDocChangeType ( type : com . google . firebase . firestore . DocumentChange . Type ) {
27112698 switch ( type ) {
0 commit comments