File tree Expand file tree Collapse file tree 5 files changed +39
-2
lines changed
firebase-common/src/jsMain/kotlin/dev/gitlive/firebase
androidMain/kotlin/dev/gitlive/firebase/firestore
commonMain/kotlin/dev/gitlive/firebase/firestore
iosMain/kotlin/dev/gitlive/firebase/firestore
jsMain/kotlin/dev/gitlive/firebase/firestore Expand file tree Collapse file tree 5 files changed +39
-2
lines changed Original file line number Diff line number Diff line change @@ -366,16 +366,23 @@ external object firebase {
366
366
open class QuerySnapshot {
367
367
val docs: Array <DocumentSnapshot >
368
368
val empty: Boolean
369
+ val metadata: SnapshotMetadata
369
370
}
370
371
371
372
open class DocumentSnapshot {
372
373
val id: String
373
374
val ref: DocumentReference
374
375
val exists: Boolean
376
+ val metadata: SnapshotMetadata
375
377
fun data (options : Any? = definedExternally): Any?
376
378
fun get (fieldPath : Any , options : Any? = definedExternally): Any?
377
379
}
378
380
381
+ open class SnapshotMetadata {
382
+ val hasPendingWrites: Boolean
383
+ val fromCache: Boolean
384
+ }
385
+
379
386
open class DocumentReference {
380
387
val id: String
381
388
val path: String
Original file line number Diff line number Diff line change @@ -335,6 +335,7 @@ actual typealias FirestoreExceptionCode = com.google.firebase.firestore.Firebase
335
335
actual class QuerySnapshot (val android : com.google.firebase.firestore.QuerySnapshot ) {
336
336
actual val documents
337
337
get() = android.documents.map { DocumentSnapshot (it) }
338
+ actual val metadata: SnapshotMetadata get() = SnapshotMetadata (android.metadata)
338
339
}
339
340
340
341
@Suppress(" UNCHECKED_CAST" )
@@ -355,6 +356,13 @@ actual class DocumentSnapshot(val android: com.google.firebase.firestore.Documen
355
356
actual fun contains (field : String ) = android.contains(field)
356
357
357
358
actual val exists get() = android.exists()
359
+
360
+ actual val metadata: SnapshotMetadata get() = SnapshotMetadata (android.metadata)
361
+ }
362
+
363
+ actual class SnapshotMetadata (val android : com.google.firebase.firestore.SnapshotMetadata ) {
364
+ actual val hasPendingWrites: Boolean get() = android.hasPendingWrites()
365
+ actual val isFromCache: Boolean get() = android.isFromCache()
358
366
}
359
367
360
368
actual typealias FieldPath = com.google.firebase.firestore.FieldPath
Original file line number Diff line number Diff line change @@ -147,6 +147,7 @@ expect enum class FirestoreExceptionCode {
147
147
148
148
expect class QuerySnapshot {
149
149
val documents: List <DocumentSnapshot >
150
+ val metadata: SnapshotMetadata
150
151
}
151
152
152
153
expect class DocumentSnapshot {
@@ -162,6 +163,12 @@ expect class DocumentSnapshot {
162
163
val exists: Boolean
163
164
val id: String
164
165
val reference: DocumentReference
166
+ val metadata: SnapshotMetadata
167
+ }
168
+
169
+ expect class SnapshotMetadata {
170
+ val hasPendingWrites: Boolean
171
+ val isFromCache: Boolean
165
172
}
166
173
167
174
expect class FieldPath
Original file line number Diff line number Diff line change @@ -284,6 +284,7 @@ fun NSError.toException() = when(domain) {
284
284
actual class QuerySnapshot (val ios : FIRQuerySnapshot ) {
285
285
actual val documents
286
286
get() = ios.documents.map { DocumentSnapshot (it as FIRDocumentSnapshot ) }
287
+ actual val metadata: SnapshotMetadata get() = SnapshotMetadata (ios.metadata)
287
288
}
288
289
289
290
@Suppress(" UNCHECKED_CAST" )
@@ -305,6 +306,13 @@ actual class DocumentSnapshot(val ios: FIRDocumentSnapshot) {
305
306
actual fun contains (field : String ) = ios.valueForField(field) != null
306
307
307
308
actual val exists get() = ios.exists
309
+
310
+ actual val metadata: SnapshotMetadata get() = SnapshotMetadata (ios.metadata)
311
+ }
312
+
313
+ actual class SnapshotMetadata (val ios : FIRSnapshotMetadata ) {
314
+ actual val hasPendingWrites: Boolean get() = ios.pendingWrites
315
+ actual val isFromCache: Boolean get() = ios.fromCache
308
316
}
309
317
310
318
actual typealias FieldPath = FIRFieldPath
Original file line number Diff line number Diff line change @@ -317,14 +317,15 @@ actual val FirebaseFirestoreException.code: FirestoreExceptionCode get() = code
317
317
actual class QuerySnapshot (val js : firebase.firestore.QuerySnapshot ) {
318
318
actual val documents
319
319
get() = js.docs.map { DocumentSnapshot (it) }
320
+ actual val metadata: SnapshotMetadata get() = SnapshotMetadata (js.metadata)
320
321
}
321
322
322
323
actual class DocumentSnapshot (val js : firebase.firestore.DocumentSnapshot ) {
323
324
324
325
actual val id get() = rethrow { js.id }
325
326
actual val reference get() = rethrow { DocumentReference (js.ref) }
326
327
327
- actual inline fun <reified T : Any > data (): T =
328
+ actual inline fun <reified T : Any > data (): T =
328
329
rethrow { decode<T >(value = js.data()) }
329
330
330
331
actual fun <T > data (strategy : DeserializationStrategy <T >): T =
@@ -337,7 +338,13 @@ actual class DocumentSnapshot(val js: firebase.firestore.DocumentSnapshot) {
337
338
rethrow { decode(strategy, js.get(field)) }
338
339
339
340
actual fun contains (field : String ) = rethrow { js.get(field) != undefined }
340
- actual val exists get() = rethrow { js.exists }
341
+ actual val exists get() = rethrow { js.exists }
342
+ actual val metadata: SnapshotMetadata get() = SnapshotMetadata (js.metadata)
343
+ }
344
+
345
+ actual class SnapshotMetadata (val js : firebase.firestore.SnapshotMetadata ) {
346
+ actual val hasPendingWrites: Boolean get() = js.hasPendingWrites
347
+ actual val isFromCache: Boolean get() = js.fromCache
341
348
}
342
349
343
350
actual typealias FieldPath = Any
You can’t perform that action at this time.
0 commit comments