Skip to content

Commit 29fceb0

Browse files
committed
Added "parent" field to document and collection references
1 parent 7763fd8 commit 29fceb0

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
@@ -297,6 +297,9 @@ actual class DocumentReference(val android: com.google.firebase.firestore.Docume
297297
actual val path: String
298298
get() = android.path
299299

300+
actual val parent: CollectionReference
301+
get() = CollectionReference(android.parent)
302+
300303
actual fun collection(collectionPath: String) = CollectionReference(android.collection(collectionPath))
301304

302305
actual suspend inline fun <reified T> set(data: T, encodeDefaults: Boolean, merge: Boolean) = when (merge) {
@@ -439,6 +442,9 @@ actual class CollectionReference(override val android: com.google.firebase.fires
439442
actual val document: DocumentReference
440443
get() = DocumentReference(android.document())
441444

445+
actual val parent: DocumentReference?
446+
get() = android.parent?.let{DocumentReference(it)}
447+
442448
actual fun document(documentPath: String) = DocumentReference(android.document(documentPath))
443449

444450
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
@@ -167,6 +167,7 @@ expect class DocumentReference {
167167
val id: String
168168
val path: String
169169
val snapshots: Flow<DocumentSnapshot>
170+
val parent: CollectionReference
170171

171172
fun collection(collectionPath: String): CollectionReference
172173
suspend fun get(): DocumentSnapshot
@@ -191,6 +192,7 @@ expect class DocumentReference {
191192
expect class CollectionReference : Query {
192193
val path: String
193194
val document: DocumentReference
195+
val parent: DocumentReference?
194196

195197
fun document(documentPath: String): DocumentReference
196198
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
@@ -218,6 +218,9 @@ actual class DocumentReference(val ios: FIRDocumentReference) {
218218
actual val path: String
219219
get() = ios.path
220220

221+
actual val parent: CollectionReference
222+
get() = CollectionReference(ios.parent)
223+
221224
actual fun collection(collectionPath: String) = CollectionReference(ios.collectionWithPath(collectionPath))
222225

223226
actual suspend inline fun <reified T> set(data: T, encodeDefaults: Boolean, merge: Boolean) =
@@ -326,6 +329,8 @@ actual class CollectionReference(override val ios: FIRCollectionReference) : Que
326329

327330
actual val document get() = DocumentReference(ios.documentWithAutoID())
328331

332+
actual val parent get() = ios.parent?.let{DocumentReference(it)}
333+
329334
actual fun document(documentPath: String) = DocumentReference(ios.documentWithPath(documentPath))
330335

331336
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
@@ -254,6 +254,9 @@ actual class DocumentReference(val js: firebase.firestore.DocumentReference) {
254254
actual val path: String
255255
get() = rethrow { js.path }
256256

257+
actual val parent: CollectionReference
258+
get() = rethrow { CollectionReference(js.parent) }
259+
257260
actual fun collection(collectionPath: String) = rethrow { CollectionReference(js.collection(collectionPath)) }
258261

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

388391
actual val document get() = rethrow { DocumentReference(js.doc()) }
389392

393+
actual val parent get() = rethrow { js.parent?.let{DocumentReference(it)} }
394+
390395
actual fun document(documentPath: String) = rethrow { DocumentReference(js.doc(documentPath)) }
391396

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

0 commit comments

Comments
 (0)