@@ -71,19 +71,19 @@ actual class FirebaseFirestore(jsFirestore: Firestore) {
71
71
var js: Firestore = jsFirestore
72
72
private set
73
73
74
- actual fun collection (collectionPath : String ) = rethrow { CollectionReference (jsCollection(js, collectionPath)) }
74
+ actual fun collection (collectionPath : String ) = rethrow { CollectionReference (NativeCollectionReference ( jsCollection(js, collectionPath) )) }
75
75
76
76
actual fun collectionGroup (collectionId : String ) = rethrow { Query (jsCollectionGroup(js, collectionId)) }
77
77
78
- actual fun document (documentPath : String ) = rethrow { DocumentReference (doc(js, documentPath)) }
78
+ actual fun document (documentPath : String ) = rethrow { DocumentReference (NativeDocumentReference ( doc(js, documentPath) )) }
79
79
80
- actual fun batch () = rethrow { WriteBatch (writeBatch(js)) }
80
+ actual fun batch () = rethrow { WriteBatch (NativeWriteBatch ( writeBatch(js) )) }
81
81
82
82
actual fun setLoggingEnabled (loggingEnabled : Boolean ) =
83
83
rethrow { setLogLevel( if (loggingEnabled) " error" else " silent" ) }
84
84
85
85
actual suspend fun <T > runTransaction (func : suspend Transaction .() -> T ) =
86
- rethrow { jsRunTransaction(js, { GlobalScope .promise { Transaction (it ).func() } } ).await() }
86
+ rethrow { jsRunTransaction(js, { GlobalScope .promise { Transaction (NativeTransaction (it) ).func() } } ).await() }
87
87
88
88
actual suspend fun clearPersistence () =
89
89
rethrow { clearIndexedDbPersistence(js).await() }
@@ -110,37 +110,38 @@ actual class FirebaseFirestore(jsFirestore: Firestore) {
110
110
}
111
111
}
112
112
113
- val SetOptions .js: Json get() = when (this ) {
113
+ internal val SetOptions .js: Json get() = when (this ) {
114
114
is SetOptions .Merge -> json(" merge" to true )
115
115
is SetOptions .Overwrite -> json(" merge" to false )
116
116
is SetOptions .MergeFields -> json(" mergeFields" to fields.toTypedArray())
117
117
is SetOptions .MergeFieldPaths -> json(" mergeFields" to encodedFieldPaths.toTypedArray())
118
118
}
119
119
120
- actual class WriteBatch (val js : JsWriteBatch ) : BaseWriteBatch() {
120
+ @PublishedApi
121
+ internal actual class NativeWriteBatch (val js : JsWriteBatch ) {
121
122
122
- override fun setEncoded (
123
+ actual fun setEncoded (
123
124
documentRef : DocumentReference ,
124
125
encodedData : Any ,
125
126
setOptions : SetOptions
126
- ): BaseWriteBatch = rethrow { js.set(documentRef.js, encodedData, setOptions.js) }.let { this }
127
+ ): NativeWriteBatch = rethrow { js.set(documentRef.js, encodedData, setOptions.js) }.let { this }
127
128
128
- override fun updateEncoded (documentRef : DocumentReference , encodedData : Any ): BaseWriteBatch = rethrow { js.update(documentRef.js, encodedData) }
129
+ actual fun updateEncoded (documentRef : DocumentReference , encodedData : Any ): NativeWriteBatch = rethrow { js.update(documentRef.js, encodedData) }
129
130
.let { this }
130
131
131
- override fun updateEncodedFieldsAndValues (
132
+ actual fun updateEncodedFieldsAndValues (
132
133
documentRef : DocumentReference ,
133
134
encodedFieldsAndValues : List <Pair <String , Any ?>>
134
- ): BaseWriteBatch = rethrow {
135
+ ): NativeWriteBatch = rethrow {
135
136
encodedFieldsAndValues.performUpdate { field, value, moreFieldsAndValues ->
136
137
js.update(documentRef.js, field, value, * moreFieldsAndValues)
137
138
}
138
139
}.let { this }
139
140
140
- override fun updateEncodedFieldPathsAndValues (
141
+ actual fun updateEncodedFieldPathsAndValues (
141
142
documentRef : DocumentReference ,
142
143
encodedFieldsAndValues : List <Pair <EncodedFieldPath , Any ?>>
143
- ): BaseWriteBatch = rethrow {
144
+ ): NativeWriteBatch = rethrow {
144
145
encodedFieldsAndValues.performUpdate { field, value, moreFieldsAndValues ->
145
146
js.update(documentRef.js, field, value, * moreFieldsAndValues)
146
147
}
@@ -153,33 +154,36 @@ actual class WriteBatch(val js: JsWriteBatch) : BaseWriteBatch() {
153
154
actual suspend fun commit () = rethrow { js.commit().await() }
154
155
}
155
156
156
- actual class Transaction ( val js : JsTransaction ) : BaseTransaction () {
157
+ val WriteBatch .js get () = native.js
157
158
158
- override fun setEncoded (
159
+ @PublishedApi
160
+ internal actual class NativeTransaction (val js : JsTransaction ) {
161
+
162
+ actual fun setEncoded (
159
163
documentRef : DocumentReference ,
160
164
encodedData : Any ,
161
165
setOptions : SetOptions
162
- ): BaseTransaction = rethrow {
166
+ ): NativeTransaction = rethrow {
163
167
js.set(documentRef.js, encodedData, setOptions.js)
164
168
}
165
169
.let { this }
166
170
167
- override fun updateEncoded (documentRef : DocumentReference , encodedData : Any ): BaseTransaction = rethrow { js.update(documentRef.js, encodedData) }
171
+ actual fun updateEncoded (documentRef : DocumentReference , encodedData : Any ): NativeTransaction = rethrow { js.update(documentRef.js, encodedData) }
168
172
.let { this }
169
173
170
- override fun updateEncodedFieldsAndValues (
174
+ actual fun updateEncodedFieldsAndValues (
171
175
documentRef : DocumentReference ,
172
176
encodedFieldsAndValues : List <Pair <String , Any ?>>
173
- ): BaseTransaction = rethrow {
177
+ ): NativeTransaction = rethrow {
174
178
encodedFieldsAndValues.performUpdate { field, value, moreFieldsAndValues ->
175
179
js.update(documentRef.js, field, value, * moreFieldsAndValues)
176
180
}
177
181
}.let { this }
178
182
179
- override fun updateEncodedFieldPathsAndValues (
183
+ actual fun updateEncodedFieldPathsAndValues (
180
184
documentRef : DocumentReference ,
181
185
encodedFieldsAndValues : List <Pair <EncodedFieldPath , Any ?>>
182
- ): BaseTransaction = rethrow {
186
+ ): NativeTransaction = rethrow {
183
187
encodedFieldsAndValues.performUpdate { field, value, moreFieldsAndValues ->
184
188
js.update(documentRef.js, field, value, * moreFieldsAndValues)
185
189
}
@@ -190,48 +194,50 @@ actual class Transaction(val js: JsTransaction) : BaseTransaction() {
190
194
.let { this }
191
195
192
196
actual suspend fun get (documentRef : DocumentReference ) =
193
- rethrow { DocumentSnapshot (js.get(documentRef.js).await()) }
197
+ rethrow { NativeDocumentSnapshot (js.get(documentRef.js).await()) }
194
198
}
195
199
200
+ val Transaction .js get() = native.js
201
+
196
202
/* * A class representing a platform specific Firebase DocumentReference. */
197
- actual typealias NativeDocumentReference = JsDocumentReference
203
+ actual typealias NativeDocumentReferenceType = JsDocumentReference
198
204
199
- @Serializable(with = DocumentReferenceSerializer :: class )
200
- actual class DocumentReference actual constructor(internal actual val nativeValue : NativeDocumentReference ) : BaseDocumentReference( ) {
201
- val js: NativeDocumentReference = nativeValue
205
+ @PublishedApi
206
+ internal actual class NativeDocumentReference actual constructor(actual val nativeValue : NativeDocumentReferenceType ) {
207
+ val js: NativeDocumentReferenceType = nativeValue
202
208
203
209
actual val id: String
204
210
get() = rethrow { js.id }
205
211
206
212
actual val path: String
207
213
get() = rethrow { js.path }
208
214
209
- actual val parent: CollectionReference
210
- get() = rethrow { CollectionReference (js.parent) }
215
+ actual val parent: NativeCollectionReference
216
+ get() = rethrow { NativeCollectionReference (js.parent) }
211
217
212
- actual fun collection (collectionPath : String ) = rethrow { CollectionReference (jsCollection(js, collectionPath)) }
218
+ actual fun collection (collectionPath : String ) = rethrow { NativeCollectionReference (jsCollection(js, collectionPath)) }
213
219
214
- actual suspend fun get () = rethrow { DocumentSnapshot ( getDoc(js).await()) }
220
+ actual suspend fun get () = rethrow { NativeDocumentSnapshot ( getDoc(js).await()) }
215
221
216
- actual val snapshots: Flow <DocumentSnapshot > get() = snapshots()
222
+ actual val snapshots: Flow <NativeDocumentSnapshot > get() = snapshots()
217
223
218
- actual fun snapshots (includeMetadataChanges : Boolean ) = callbackFlow<DocumentSnapshot > {
224
+ actual fun snapshots (includeMetadataChanges : Boolean ) = callbackFlow<NativeDocumentSnapshot > {
219
225
val unsubscribe = onSnapshot(
220
226
js,
221
227
json(" includeMetadataChanges" to includeMetadataChanges),
222
- { trySend(DocumentSnapshot (it)) },
228
+ { trySend(NativeDocumentSnapshot (it)) },
223
229
{ close(errorToException(it)) }
224
230
)
225
231
awaitClose { unsubscribe() }
226
232
}
227
233
228
- override suspend fun setEncoded (encodedData : Any , setOptions : SetOptions ) = rethrow {
234
+ actual suspend fun setEncoded (encodedData : Any , setOptions : SetOptions ) = rethrow {
229
235
setDoc(js, encodedData, setOptions.js).await()
230
236
}
231
237
232
- override suspend fun updateEncoded (encodedData : Any ) = rethrow { jsUpdate(js, encodedData).await() }
238
+ actual suspend fun updateEncoded (encodedData : Any ) = rethrow { jsUpdate(js, encodedData).await() }
233
239
234
- override suspend fun updateEncodedFieldsAndValues (encodedFieldsAndValues : List <Pair <String , Any ?>>) {
240
+ actual suspend fun updateEncodedFieldsAndValues (encodedFieldsAndValues : List <Pair <String , Any ?>>) {
235
241
rethrow {
236
242
encodedFieldsAndValues.takeUnless { encodedFieldsAndValues.isEmpty() }
237
243
?.performUpdate { field, value, moreFieldsAndValues ->
@@ -241,7 +247,7 @@ actual class DocumentReference actual constructor(internal actual val nativeValu
241
247
}
242
248
}
243
249
244
- override suspend fun updateEncodedFieldPathsAndValues (encodedFieldsAndValues : List <Pair <EncodedFieldPath , Any ?>>) {
250
+ actual suspend fun updateEncodedFieldPathsAndValues (encodedFieldsAndValues : List <Pair <EncodedFieldPath , Any ?>>) {
245
251
rethrow {
246
252
encodedFieldsAndValues.takeUnless { encodedFieldsAndValues.isEmpty() }
247
253
?.performUpdate { field, value, moreFieldsAndValues ->
@@ -250,15 +256,18 @@ actual class DocumentReference actual constructor(internal actual val nativeValu
250
256
}
251
257
}
252
258
253
- override suspend fun delete () = rethrow { deleteDoc(js).await() }
259
+ actual suspend fun delete () = rethrow { deleteDoc(js).await() }
254
260
255
261
override fun equals (other : Any? ): Boolean =
256
- this == = other || other is DocumentReference && refEqual(nativeValue, other.nativeValue)
262
+ this == = other || other is NativeDocumentReference && refEqual(nativeValue, other.nativeValue)
257
263
override fun hashCode (): Int = nativeValue.hashCode()
258
264
override fun toString (): String = " DocumentReference(path=$path )"
259
265
}
260
266
261
- actual data class NativeQuery (val js : JsQuery )
267
+ val DocumentReference .js get() = native.js
268
+
269
+ @PublishedApi
270
+ internal actual open class NativeQuery (open val js : JsQuery )
262
271
263
272
actual open class Query internal actual constructor(nativeQuery : NativeQuery ) {
264
273
@@ -356,38 +365,41 @@ actual open class Query internal actual constructor(nativeQuery: NativeQuery) {
356
365
}
357
366
}
358
367
359
- actual class CollectionReference (override val js : JsCollectionReference ) : BaseCollectionReference(NativeQuery (js)) {
368
+ @PublishedApi
369
+ internal actual class NativeCollectionReference (override val js : JsCollectionReference ) : NativeQuery(js) {
360
370
361
371
actual val path: String
362
372
get() = rethrow { js.path }
363
373
364
- actual val document get() = rethrow { DocumentReference (doc(js)) }
374
+ actual val document get() = rethrow { NativeDocumentReference (doc(js)) }
365
375
366
- actual val parent get() = rethrow { js.parent?.let {DocumentReference (it)} }
376
+ actual val parent get() = rethrow { js.parent?.let { NativeDocumentReference (it) } }
367
377
368
- actual fun document (documentPath : String ) = rethrow { DocumentReference (doc(js, documentPath)) }
378
+ actual fun document (documentPath : String ) = rethrow { NativeDocumentReference (doc(js, documentPath)) }
369
379
370
- override suspend fun addEncoded (data : Any ) = rethrow {
371
- DocumentReference (addDoc(js, data).await())
380
+ actual suspend fun addEncoded (data : Any ) = rethrow {
381
+ NativeDocumentReference (addDoc(js, data).await())
372
382
}
373
383
}
374
384
385
+ val CollectionReference .js get() = native.js
386
+
375
387
actual class FirebaseFirestoreException (cause : Throwable , val code : FirestoreExceptionCode ) : FirebaseException(code.toString(), cause)
376
388
377
389
@Suppress(" EXTENSION_SHADOWED_BY_MEMBER" )
378
390
actual val FirebaseFirestoreException .code: FirestoreExceptionCode get() = code
379
391
380
392
actual class QuerySnapshot (val js : JsQuerySnapshot ) {
381
393
actual val documents
382
- get() = js.docs.map { DocumentSnapshot (it ) }
394
+ get() = js.docs.map { DocumentSnapshot (NativeDocumentSnapshot (it) ) }
383
395
actual val documentChanges
384
396
get() = js.docChanges().map { DocumentChange (it) }
385
397
actual val metadata: SnapshotMetadata get() = SnapshotMetadata (js.metadata)
386
398
}
387
399
388
400
actual class DocumentChange (val js : JsDocumentChange ) {
389
401
actual val document: DocumentSnapshot
390
- get() = DocumentSnapshot (js.doc)
402
+ get() = DocumentSnapshot (NativeDocumentSnapshot ( js.doc) )
391
403
actual val newIndex: Int
392
404
get() = js.newIndex
393
405
actual val oldIndex: Int
@@ -396,16 +408,17 @@ actual class DocumentChange(val js: JsDocumentChange) {
396
408
get() = ChangeType .values().first { it.jsString == js.type }
397
409
}
398
410
399
- actual class DocumentSnapshot (val js : JsDocumentSnapshot ) : BaseDocumentSnapshot() {
411
+ @PublishedApi
412
+ internal actual class NativeDocumentSnapshot (val js : JsDocumentSnapshot ) {
400
413
401
414
actual val id get() = rethrow { js.id }
402
- actual val reference get() = rethrow { DocumentReference (js.ref) }
415
+ actual val reference get() = rethrow { NativeDocumentReference (js.ref) }
403
416
404
- override fun getEncoded (field : String , serverTimestampBehavior : ServerTimestampBehavior ): Any? = rethrow {
417
+ actual fun getEncoded (field : String , serverTimestampBehavior : ServerTimestampBehavior ): Any? = rethrow {
405
418
js.get(field, getTimestampsOptions(serverTimestampBehavior))
406
419
}
407
420
408
- override fun encodedData (serverTimestampBehavior : ServerTimestampBehavior ): Any? = rethrow {
421
+ actual fun encodedData (serverTimestampBehavior : ServerTimestampBehavior ): Any? = rethrow {
409
422
js.data(getTimestampsOptions(serverTimestampBehavior))
410
423
}
411
424
@@ -417,6 +430,8 @@ actual class DocumentSnapshot(val js: JsDocumentSnapshot) : BaseDocumentSnapshot
417
430
json(" serverTimestamps" to serverTimestampBehavior.name.lowercase())
418
431
}
419
432
433
+ val DocumentSnapshot .js get() = native.js
434
+
420
435
actual class SnapshotMetadata (val js : JsSnapshotMetadata ) {
421
436
actual val hasPendingWrites: Boolean get() = js.hasPendingWrites
422
437
actual val isFromCache: Boolean get() = js.fromCache
0 commit comments