Skip to content

Map null in map to undefined for JS database #493

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ internal actual class NativeOnDisconnect internal constructor(
rethrow { js.set(encodedValue).awaitWhileOnline(database) }

actual suspend fun updateEncodedChildren(encodedUpdate: Map<String, Any?>) =
rethrow { js.update(encodedUpdate).awaitWhileOnline(database) }
rethrow { js.update(encodedUpdate.mapValues { (_, value) -> value ?: undefined }).awaitWhileOnline(database) }

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ internal actual class NativeWriteBatch(val js: JsWriteBatch) {
documentRef: DocumentReference,
encodedFieldsAndValues: List<Pair<String, Any?>>
): NativeWriteBatch = rethrow {
encodedFieldsAndValues.performUpdate { field, value, moreFieldsAndValues ->
encodedFieldsAndValues.performUpdateWithUndefined { field, value, moreFieldsAndValues ->
js.update(documentRef.js, field, value, *moreFieldsAndValues)
}
}.let { this }
Expand All @@ -143,7 +143,7 @@ internal actual class NativeWriteBatch(val js: JsWriteBatch) {
documentRef: DocumentReference,
encodedFieldsAndValues: List<Pair<EncodedFieldPath, Any?>>
): NativeWriteBatch = rethrow {
encodedFieldsAndValues.performUpdate { field, value, moreFieldsAndValues ->
encodedFieldsAndValues.performUpdateWithUndefined { field, value, moreFieldsAndValues ->
js.update(documentRef.js, field, value, *moreFieldsAndValues)
}
}.let { this }
Expand Down Expand Up @@ -176,7 +176,7 @@ internal actual class NativeTransaction(val js: JsTransaction) {
documentRef: DocumentReference,
encodedFieldsAndValues: List<Pair<String, Any?>>
): NativeTransaction = rethrow {
encodedFieldsAndValues.performUpdate { field, value, moreFieldsAndValues ->
encodedFieldsAndValues.performUpdateWithUndefined { field, value, moreFieldsAndValues ->
js.update(documentRef.js, field, value, *moreFieldsAndValues)
}
}.let { this }
Expand All @@ -185,7 +185,7 @@ internal actual class NativeTransaction(val js: JsTransaction) {
documentRef: DocumentReference,
encodedFieldsAndValues: List<Pair<EncodedFieldPath, Any?>>
): NativeTransaction = rethrow {
encodedFieldsAndValues.performUpdate { field, value, moreFieldsAndValues ->
encodedFieldsAndValues.performUpdateWithUndefined { field, value, moreFieldsAndValues ->
js.update(documentRef.js, field, value, *moreFieldsAndValues)
}
}.let { this }
Expand Down Expand Up @@ -241,7 +241,7 @@ internal actual class NativeDocumentReference actual constructor(actual val nati
actual suspend fun updateEncodedFieldsAndValues(encodedFieldsAndValues: List<Pair<String, Any?>>) {
rethrow {
encodedFieldsAndValues.takeUnless { encodedFieldsAndValues.isEmpty() }
?.performUpdate { field, value, moreFieldsAndValues ->
?.performUpdateWithUndefined { field, value, moreFieldsAndValues ->
jsUpdate(js, field, value, *moreFieldsAndValues)
}
?.await()
Expand All @@ -251,7 +251,7 @@ internal actual class NativeDocumentReference actual constructor(actual val nati
actual suspend fun updateEncodedFieldPathsAndValues(encodedFieldsAndValues: List<Pair<EncodedFieldPath, Any?>>) {
rethrow {
encodedFieldsAndValues.takeUnless { encodedFieldsAndValues.isEmpty() }
?.performUpdate { field, value, moreFieldsAndValues ->
?.performUpdateWithUndefined { field, value, moreFieldsAndValues ->
jsUpdate(js, field, value, *moreFieldsAndValues)
}?.await()
}
Expand Down Expand Up @@ -543,3 +543,7 @@ fun entriesOf(jsObject: dynamic): List<Pair<String, Any?>> =
// from: https://discuss.kotlinlang.org/t/how-to-access-native-js-object-as-a-map-string-any/509/8
fun mapOf(jsObject: dynamic): Map<String, Any?> =
entriesOf(jsObject).toMap()

internal fun <K, R> List<Pair<K, Any?>>.performUpdateWithUndefined(
update: (K, Any?, Array<Any?>) -> R
) = map { (key, value) -> key to (value ?: undefined) }.performUpdate(update)
Loading