@@ -6,12 +6,12 @@ package dev.gitlive.firebase.database
66
77import cocoapods.FirebaseDatabase.*
88import cocoapods.FirebaseDatabase.FIRDataEventType.*
9- import dev.gitlive.firebase.encode
109import dev.gitlive.firebase.Firebase
1110import dev.gitlive.firebase.FirebaseApp
1211import dev.gitlive.firebase.database.ChildEvent.Type
1312import dev.gitlive.firebase.database.ChildEvent.Type.*
1413import dev.gitlive.firebase.decode
14+ import dev.gitlive.firebase.encode
1515import kotlinx.coroutines.CompletableDeferred
1616import kotlinx.coroutines.FlowPreview
1717import kotlinx.coroutines.channels.awaitClose
@@ -23,7 +23,8 @@ import kotlinx.coroutines.selects.select
2323import kotlinx.serialization.DeserializationStrategy
2424import kotlinx.serialization.KSerializer
2525import kotlinx.serialization.SerializationStrategy
26- import platform.Foundation.*
26+ import platform.Foundation.NSError
27+ import platform.Foundation.allObjects
2728import kotlin.collections.component1
2829import kotlin.collections.component2
2930
@@ -103,7 +104,7 @@ actual open class Query internal constructor(
103104 val handle = ios.observeEventType(
104105 FIRDataEventTypeValue ,
105106 withBlock = { snapShot ->
106- trySend(DataSnapshot (snapShot!! ))
107+ trySend(DataSnapshot (snapShot!! , persistenceEnabled ))
107108 }
108109 ) { close(DatabaseException (it.toString(), null )) }
109110 awaitClose { ios.removeObserverWithHandle(handle) }
@@ -114,7 +115,7 @@ actual open class Query internal constructor(
114115 ios.observeEventType(
115116 type.toEventType(),
116117 andPreviousSiblingKeyWithBlock = { snapShot, key ->
117- trySend(ChildEvent (DataSnapshot (snapShot!! ), type, key))
118+ trySend(ChildEvent (DataSnapshot (snapShot!! , persistenceEnabled ), type, key))
118119 }
119120 ) { close(DatabaseException (it.toString(), null )) }
120121 }
@@ -168,7 +169,7 @@ actual class DatabaseReference internal constructor(
168169 if (error != null ) {
169170 deferred.completeExceptionally(DatabaseException (error.toString(), null ))
170171 } else {
171- deferred.complete(DataSnapshot (snapshot!! ))
172+ deferred.complete(DataSnapshot (snapshot!! , persistenceEnabled ))
172173 }
173174 },
174175 withLocalEvents = false
@@ -178,20 +179,28 @@ actual class DatabaseReference internal constructor(
178179}
179180
180181@Suppress(" UNCHECKED_CAST" )
181- actual class DataSnapshot internal constructor(val ios : FIRDataSnapshot ) {
182+ actual class DataSnapshot internal constructor(
183+ val ios : FIRDataSnapshot ,
184+ private val persistenceEnabled : Boolean
185+ ) {
182186
183187 actual val exists get() = ios.exists()
184188
185189 actual val key: String? get() = ios.key
186190
191+ actual val ref: DatabaseReference get() = DatabaseReference (ios.ref, persistenceEnabled)
192+
193+ actual val value get() = ios.value
194+
187195 actual inline fun <reified T > value () =
188196 decode<T >(value = ios.value)
189197
190198 actual fun <T > value (strategy : DeserializationStrategy <T >) =
191199 decode(strategy, ios.value)
192200
193- actual fun child (path : String ) = DataSnapshot (ios.childSnapshotForPath(path))
194- actual val children: Iterable <DataSnapshot > get() = ios.children.allObjects.map { DataSnapshot (it as FIRDataSnapshot ) }
201+ actual fun child (path : String ) = DataSnapshot (ios.childSnapshotForPath(path), persistenceEnabled)
202+ actual val hasChildren get() = ios.hasChildren()
203+ actual val children: Iterable <DataSnapshot > get() = ios.children.allObjects.map { DataSnapshot (it as FIRDataSnapshot , persistenceEnabled) }
195204}
196205
197206actual class OnDisconnect internal constructor(
0 commit comments