@@ -78,24 +78,24 @@ export class DocumentReference<T = firestore.DocumentData>
78
78
79
79
constructor (
80
80
readonly firestore : Firestore ,
81
- key : DocumentKey ,
81
+ readonly _path : ResourcePath ,
82
82
readonly _converter : firestore . FirestoreDataConverter < T > | null
83
83
) {
84
- super ( firestore . _databaseId , key , _converter ) ;
84
+ super ( firestore . _databaseId , new DocumentKey ( _path ) , _converter ) ;
85
85
}
86
86
87
87
get id ( ) : string {
88
- return this . _key . path . lastSegment ( ) ;
88
+ return this . _path . lastSegment ( ) ;
89
89
}
90
90
91
91
get path ( ) : string {
92
- return this . _key . path . canonicalString ( ) ;
92
+ return this . _path . canonicalString ( ) ;
93
93
}
94
94
95
95
withConverter < U > (
96
96
converter : firestore . FirestoreDataConverter < U >
97
97
) : firestore . DocumentReference < U > {
98
- return new DocumentReference < U > ( this . firestore , this . _key , converter ) ;
98
+ return new DocumentReference < U > ( this . firestore , this . _path , converter ) ;
99
99
}
100
100
}
101
101
@@ -320,8 +320,8 @@ export function collection(
320
320
'a DocumentReference or FirebaseFirestore'
321
321
) ;
322
322
}
323
- const absolutePath = ResourcePath . fromString (
324
- ` ${ parent . path } / ${ relativePath } `
323
+ const absolutePath = ResourcePath . fromString ( parent . path ) . child (
324
+ ResourcePath . fromString ( relativePath )
325
325
) ;
326
326
validateCollectionPath ( absolutePath ) ;
327
327
return new CollectionReference (
@@ -385,11 +385,7 @@ export function doc<T>(
385
385
if ( parent instanceof Firestore ) {
386
386
const absolutePath = ResourcePath . fromString ( relativePath ! ) ;
387
387
validateDocumentPath ( absolutePath ) ;
388
- return new DocumentReference (
389
- parent ,
390
- new DocumentKey ( absolutePath ) ,
391
- /* converter= */ null
392
- ) ;
388
+ return new DocumentReference ( parent , absolutePath , /* converter= */ null ) ;
393
389
} else {
394
390
if (
395
391
! ( parent instanceof DocumentReference ) &&
@@ -401,13 +397,13 @@ export function doc<T>(
401
397
'a DocumentReference or FirebaseFirestore'
402
398
) ;
403
399
}
404
- const absolutePath = ResourcePath . fromString (
405
- ` ${ parent . path } / ${ relativePath } `
400
+ const absolutePath = parent . _path . child (
401
+ ResourcePath . fromString ( relativePath ! )
406
402
) ;
407
403
validateDocumentPath ( absolutePath ) ;
408
404
return new DocumentReference (
409
405
parent . firestore ,
410
- new DocumentKey ( absolutePath ) ,
406
+ absolutePath ,
411
407
parent instanceof CollectionReference ? parent . _converter : null
412
408
) ;
413
409
}
@@ -429,7 +425,7 @@ export function parent<T>(
429
425
} else {
430
426
return new DocumentReference (
431
427
child . firestore ,
432
- new DocumentKey ( parentPath ) ,
428
+ parentPath ,
433
429
/* converter= */ null
434
430
) ;
435
431
}
0 commit comments