Skip to content

Commit d2031e3

Browse files
committed
Added "parent" field to document and collection references
(cherry picked from commit 29fceb0)
1 parent 7af9843 commit d2031e3

File tree

6 files changed

+21
-1
lines changed

6 files changed

+21
-1
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ subprojects {
197197
dependencies {
198198
"commonMainImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2")
199199
"androidMainImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.5.2")
200-
"androidMainImplementation"(platform("com.google.firebase:firebase-bom:28.4.1"))
200+
"androidMainImplementation"(platform("com.google.firebase:firebase-bom:29.0.1"))
201201
"commonTestImplementation"(kotlin("test-common"))
202202
"commonTestImplementation"(kotlin("test-annotations-common"))
203203
"commonTestImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2")

firebase-common/src/jsMain/kotlin/dev/gitlive/firebase/externals.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ external object firebase {
383383

384384
open class CollectionReference : Query {
385385
val path: String
386+
val parent: DocumentReference?
386387
fun doc(path: String = definedExternally): DocumentReference
387388
fun add(data: Any): Promise<DocumentReference>
388389
}
@@ -419,6 +420,7 @@ external object firebase {
419420
open class DocumentReference {
420421
val id: String
421422
val path: String
423+
val parent: CollectionReference
422424

423425
fun collection(path: String): CollectionReference
424426
fun get(options: Any? = definedExternally): Promise<DocumentSnapshot>

firebase-firestore/src/androidMain/kotlin/dev/gitlive/firebase/firestore/firestore.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,9 @@ actual class DocumentReference(val android: com.google.firebase.firestore.Docume
227227
actual val path: String
228228
get() = android.path
229229

230+
actual val parent: CollectionReference
231+
get() = CollectionReference(android.parent)
232+
230233
actual fun collection(collectionPath: String) = CollectionReference(android.collection(collectionPath))
231234

232235
actual suspend inline fun <reified T> set(data: T, encodeDefaults: Boolean, merge: Boolean) = when(merge) {
@@ -367,6 +370,9 @@ actual class CollectionReference(override val android: com.google.firebase.fires
367370
actual val document: DocumentReference
368371
get() = DocumentReference(android.document())
369372

373+
actual val parent: DocumentReference?
374+
get() = android.parent?.let{DocumentReference(it)}
375+
370376
actual fun document(documentPath: String) = DocumentReference(android.document(documentPath))
371377

372378
actual suspend inline fun <reified T> add(data: T, encodeDefaults: Boolean) =

firebase-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore/firestore.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ expect class DocumentReference {
105105
val id: String
106106
val path: String
107107
val snapshots: Flow<DocumentSnapshot>
108+
val parent: CollectionReference
108109

109110
fun collection(collectionPath: String): CollectionReference
110111
suspend fun get(): DocumentSnapshot
@@ -129,6 +130,7 @@ expect class DocumentReference {
129130
expect class CollectionReference : Query {
130131
val path: String
131132
val document: DocumentReference
133+
val parent: DocumentReference?
132134

133135
fun document(documentPath: String): DocumentReference
134136
suspend inline fun <reified T> add(data: T, encodeDefaults: Boolean = true): DocumentReference

firebase-firestore/src/iosMain/kotlin/dev/gitlive/firebase/firestore/firestore.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ actual class DocumentReference(val ios: FIRDocumentReference) {
174174
actual val path: String
175175
get() = ios.path
176176

177+
actual val parent: CollectionReference
178+
get() = CollectionReference(ios.parent)
179+
177180
actual fun collection(collectionPath: String) = CollectionReference(ios.collectionWithPath(collectionPath))
178181

179182
actual suspend inline fun <reified T> set(data: T, encodeDefaults: Boolean, merge: Boolean) =
@@ -282,6 +285,8 @@ actual class CollectionReference(override val ios: FIRCollectionReference) : Que
282285

283286
actual val document get() = DocumentReference(ios.documentWithAutoID())
284287

288+
actual val parent get() = ios.parent?.let{DocumentReference(it)}
289+
285290
actual fun document(documentPath: String) = DocumentReference(ios.documentWithPath(documentPath))
286291

287292
actual suspend inline fun <reified T> add(data: T, encodeDefaults: Boolean) =

firebase-firestore/src/jsMain/kotlin/dev/gitlive/firebase/firestore/firestore.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@ actual class DocumentReference(val js: firebase.firestore.DocumentReference) {
214214
actual val path: String
215215
get() = rethrow { js.path }
216216

217+
actual val parent: CollectionReference
218+
get() = rethrow { CollectionReference(js.parent) }
219+
217220
actual fun collection(collectionPath: String) = rethrow { CollectionReference(js.collection(collectionPath)) }
218221

219222
actual suspend inline fun <reified T> set(data: T, encodeDefaults: Boolean, merge: Boolean) =
@@ -347,6 +350,8 @@ actual class CollectionReference(override val js: firebase.firestore.CollectionR
347350

348351
actual val document get() = rethrow { DocumentReference(js.doc()) }
349352

353+
actual val parent get() = rethrow { js.parent?.let{DocumentReference(it)} }
354+
350355
actual fun document(documentPath: String) = rethrow { DocumentReference(js.doc(documentPath)) }
351356

352357
actual suspend inline fun <reified T> add(data: T, encodeDefaults: Boolean) =

0 commit comments

Comments
 (0)