@@ -30,15 +30,6 @@ actual val Firebase.firestore get() =
30
30
actual fun Firebase.firestore (app : FirebaseApp ) =
31
31
FirebaseFirestore (com.google.firebase.firestore.FirebaseFirestore .getInstance(app.android))
32
32
33
- @Suppress(" DeferredIsResult" )
34
- @PublishedApi
35
- internal fun Task<Void>.asUnitDeferred (): Deferred <Unit > = CompletableDeferred <Unit >()
36
- .apply {
37
- asDeferred().invokeOnCompletion { exception ->
38
- if (exception == null ) complete(Unit ) else completeExceptionally(exception)
39
- }
40
- }
41
-
42
33
actual class FirebaseFirestore (val android : com.google.firebase.firestore.FirebaseFirestore ) {
43
34
44
35
actual fun collection (collectionPath : String ) = CollectionReference (android.collection(collectionPath))
@@ -91,8 +82,6 @@ val SetOptions.android: com.google.firebase.firestore.SetOptions? get() = when (
91
82
92
83
actual class WriteBatch (val android : com.google.firebase.firestore.WriteBatch ) : BaseWriteBatch() {
93
84
94
- actual val async = Async (android)
95
-
96
85
override fun setEncoded (
97
86
documentRef : DocumentReference ,
98
87
encodedData : Any ,
@@ -123,11 +112,8 @@ actual class WriteBatch(val android: com.google.firebase.firestore.WriteBatch) :
123
112
actual fun delete (documentRef : DocumentReference ) =
124
113
android.delete(documentRef.android).let { this }
125
114
126
- actual suspend fun commit () = async.commit().await()
127
-
128
- @Suppress(" DeferredIsResult" )
129
- actual class Async (private val android : com.google.firebase.firestore.WriteBatch ) {
130
- actual fun commit (): Deferred <Unit > = android.commit().asUnitDeferred()
115
+ actual suspend fun commit () {
116
+ android.commit().await()
131
117
}
132
118
}
133
119
@@ -183,13 +169,40 @@ actual class DocumentReference actual constructor(internal actual val nativeValu
183
169
actual val parent: CollectionReference
184
170
get() = CollectionReference (android.parent)
185
171
186
- override val async = Async (android)
187
-
188
172
actual fun collection (collectionPath : String ) = CollectionReference (android.collection(collectionPath))
189
173
190
174
actual suspend fun get () =
191
175
DocumentSnapshot (android.get().await())
192
176
177
+ override suspend fun setEncoded (encodedData : Any , setOptions : SetOptions ) {
178
+ val task = (setOptions.android?.let {
179
+ android.set(encodedData, it)
180
+ } ? : android.set(encodedData))
181
+ task.await()
182
+ }
183
+
184
+ @Suppress(" UNCHECKED_CAST" )
185
+ override suspend fun updateEncoded (encodedData : Any ) {
186
+ android.update(encodedData as Map <String , Any >).await()
187
+ }
188
+
189
+ override suspend fun updateEncodedFieldsAndValues (encodedFieldsAndValues : List <Pair <String , Any ?>>) {
190
+ encodedFieldsAndValues.takeUnless { encodedFieldsAndValues.isEmpty() }?.let {
191
+ android.update(encodedFieldsAndValues.toMap())
192
+ }?.await()
193
+ }
194
+
195
+ override suspend fun updateEncodedFieldPathsAndValues (encodedFieldsAndValues : List <Pair <EncodedFieldPath , Any ?>>) {
196
+ encodedFieldsAndValues.takeUnless { encodedFieldsAndValues.isEmpty() }
197
+ ?.performUpdate { field, value, moreFieldsAndValues ->
198
+ android.update(field, value, * moreFieldsAndValues)
199
+ }?.await()
200
+ }
201
+
202
+ override suspend fun delete () {
203
+ android.delete().await()
204
+ }
205
+
193
206
actual val snapshots: Flow <DocumentSnapshot > get() = snapshots()
194
207
195
208
actual fun snapshots (includeMetadataChanges : Boolean ) = callbackFlow {
@@ -205,29 +218,6 @@ actual class DocumentReference actual constructor(internal actual val nativeValu
205
218
this == = other || other is DocumentReference && nativeValue == other.nativeValue
206
219
override fun hashCode (): Int = nativeValue.hashCode()
207
220
override fun toString (): String = nativeValue.toString()
208
-
209
- @Suppress(" DeferredIsResult" )
210
- class Async (@PublishedApi internal val android : NativeDocumentReference ) : BaseDocumentReference.Async() {
211
-
212
- override fun setEncoded (encodedData : Any , setOptions : SetOptions ): Deferred <Unit > = (setOptions.android?.let {
213
- android.set(encodedData, it)
214
- } ? : android.set(encodedData)).asUnitDeferred()
215
-
216
- @Suppress(" UNCHECKED_CAST" )
217
- override fun updateEncoded (encodedData : Any ): Deferred <Unit > = android.update(encodedData as Map <String , Any >).asUnitDeferred()
218
-
219
- override fun updateEncodedFieldsAndValues (encodedFieldsAndValues : List <Pair <String , Any ?>>): Deferred <Unit > = encodedFieldsAndValues.takeUnless { encodedFieldsAndValues.isEmpty() }?.let {
220
- android.update(encodedFieldsAndValues.toMap())
221
- }?.asUnitDeferred() ? : CompletableDeferred (Unit )
222
-
223
- override fun updateEncodedFieldPathsAndValues (encodedFieldsAndValues : List <Pair <EncodedFieldPath , Any ?>>): Deferred <Unit > = encodedFieldsAndValues.takeUnless { encodedFieldsAndValues.isEmpty() }
224
- ?.performUpdate { field, value, moreFieldsAndValues ->
225
- android.update(field, value, * moreFieldsAndValues)
226
- }?.asUnitDeferred() ? : CompletableDeferred (Unit )
227
-
228
- override fun delete () =
229
- android.delete().asUnitDeferred()
230
- }
231
221
}
232
222
233
223
actual typealias NativeQuery = AndroidQuery
@@ -345,7 +335,6 @@ actual class CollectionReference(override val android: com.google.firebase.fires
345
335
346
336
actual val path: String
347
337
get() = android.path
348
- override val async = Async (android)
349
338
350
339
actual val document: DocumentReference
351
340
get() = DocumentReference (android.document())
@@ -355,10 +344,7 @@ actual class CollectionReference(override val android: com.google.firebase.fires
355
344
356
345
actual fun document (documentPath : String ) = DocumentReference (android.document(documentPath))
357
346
358
- @Suppress(" DeferredIsResult" )
359
- class Async (@PublishedApi internal val android : com.google.firebase.firestore.CollectionReference ) : BaseCollectionReference.Async() {
360
- override fun addEncoded (data : Any ): Deferred <DocumentReference > = android.add(data).asDeferred().convert(::DocumentReference )
361
- }
347
+ override suspend fun addEncoded (data : Any ) = DocumentReference (android.add(data).await())
362
348
}
363
349
364
350
actual typealias FirebaseFirestoreException = com.google.firebase.firestore.FirebaseFirestoreException
0 commit comments