Skip to content

Commit e7704bc

Browse files
committed
use undefined instead of null in js
use array instead of list in js structureEncoder
1 parent 2178b93 commit e7704bc

File tree

11 files changed

+46
-33
lines changed

11 files changed

+46
-33
lines changed

firebase-app/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@teamhubapp/firebase-app",
3-
"version": "0.1.0-dev9",
3+
"version": "0.1.0-dev12",
44
"description": "Wrapper around firebase for usage in Kotlin Multiplatform projects",
55
"main": "firebase-app.js",
66
"scripts": {
@@ -23,10 +23,10 @@
2323
},
2424
"homepage": "https://github.com/TeamHubApp/firebase-kotlin-multiplatform-sdk",
2525
"dependencies": {
26-
"@teamhubapp/firebase-common": "0.1.0-dev9",
26+
"@teamhubapp/firebase-common": "0.1.0-dev12",
2727
"firebase": "6.2.3",
2828
"kotlin": "1.3.61",
29-
"kotlinx-coroutines-core": "1.3.3"
29+
"kotlinx-coroutines-core": "1.3.2"
3030
}
3131
}
3232

firebase-app/src/jsMain/kotlin/dev/teamhub/firebase/firebase.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ actual fun Firebase.apps(context: Any?) = firebase.apps.map { FirebaseApp(it) }
3131
private fun FirebaseOptions.toJson() = json(
3232
"apiKey" to apiKey,
3333
"applicationId" to applicationId,
34-
"databaseURL" to databaseUrl,
35-
"storageBucket" to storageBucket,
36-
"projectId" to projectId,
37-
"gaTrackingId" to gaTrackingId
34+
"databaseURL" to (databaseUrl ?: undefined),
35+
"storageBucket" to (storageBucket ?: undefined),
36+
"projectId" to (projectId ?: undefined),
37+
"gaTrackingId" to (gaTrackingId ?: undefined)
3838
)
3939

4040
actual open class FirebaseException(code: String?, cause: Throwable) : Exception("$code: ${cause.message}", cause)

firebase-auth/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@teamhubapp/firebase-auth",
3-
"version": "0.1.0-dev9",
3+
"version": "0.1.0-dev12",
44
"description": "Wrapper around firebase for usage in Kotlin Multiplatform projects",
55
"main": "firebase-auth.js",
66
"scripts": {
@@ -23,10 +23,10 @@
2323
},
2424
"homepage": "https://github.com/TeamHubApp/firebase-kotlin-multiplatform-sdk",
2525
"dependencies": {
26-
"@teamhubapp/firebase-app": "0.1.0-dev9",
26+
"@teamhubapp/firebase-app": "0.1.0-dev12",
2727
"firebase": "6.2.3",
2828
"kotlin": "1.3.61",
29-
"kotlinx-coroutines-core": "1.3.3"
29+
"kotlinx-coroutines-core": "1.3.2"
3030
}
3131
}
3232

firebase-common/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@teamhubapp/firebase-common",
3-
"version": "0.1.0-dev9",
3+
"version": "0.1.0-dev14",
44
"description": "Wrapper around firebase for usage in Kotlin Multiplatform projects",
55
"main": "firebase-common.js",
66
"scripts": {
@@ -25,7 +25,7 @@
2525
"dependencies": {
2626
"firebase": "6.2.3",
2727
"kotlin": "1.3.61",
28-
"kotlinx-coroutines-core": "1.3.3",
28+
"kotlinx-coroutines-core": "1.3.2",
2929
"@cachet/kotlinx-serialization-runtime": "0.14.0-rc.2"
3030
}
3131
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package dev.teamhub.firebase
2+
3+
import kotlinx.serialization.Serializable
4+
import kotlinx.serialization.serializer
5+
import kotlin.test.Test
6+
import kotlin.test.assertEquals
7+
8+
@Serializable
9+
data class TestData(val map: Map<String, String>)
10+
11+
class EncodersTest {
12+
@Test
13+
fun `encode a map`() {
14+
val encoded = encode<TestData>(TestData::class.serializer(), TestData(mapOf("key" to "value")))
15+
assertEquals(mapOf("key" to "value"), (encoded as Map<String, Any>)["map"])
16+
}
17+
}

firebase-common/src/commonMain/kotlin/dev/teamhub/firebase/encoders.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,13 @@ abstract class TimestampEncoder(internal val positiveInfinity: Any) {
8484
}
8585
}
8686

87-
open class FirebaseCompositeEncoder(
87+
open class FirebaseCompositeEncoder constructor(
8888
positiveInfinity: Any,
89-
private val end: () -> Unit = {},
9089
private val set: (desc: SerialDescriptor, index: Int, value: Any?) -> Unit
9190
): TimestampEncoder(positiveInfinity), CompositeEncoder {
9291

9392
override val context = EmptyModule
9493

95-
override fun endStructure(desc: SerialDescriptor) {
96-
super.endStructure(desc)
97-
}
98-
9994
private fun <T> SerializationStrategy<T>.toFirebase(): SerializationStrategy<T> = when(this) {
10095
is MapLikeSerializer<*, *, *, *> -> FirebaseMapSerializer() as SerializationStrategy<T>
10196
is ListLikeSerializer<*, *, *> -> FirebaseListSerializer() as SerializationStrategy<T>

firebase-common/src/jsMain/kotlin/dev/teamhub/firebase/_encoders.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ import kotlinx.serialization.StructureKind
77
import kotlin.js.json
88

99
actual fun FirebaseEncoder.structureEncoder(desc: SerialDescriptor, vararg typeParams: KSerializer<*>): CompositeEncoder = when(desc.kind as StructureKind) {
10-
StructureKind.LIST -> mutableListOf<Any?>()
11-
.let { FirebaseCompositeEncoder(positiveInfinity, { value = it.toTypedArray() }) { _, index, value -> it.add(index, value) } }
10+
StructureKind.LIST -> Array<Any?>(desc.elementsCount) { null }
11+
.also { value = it }
12+
.let { FirebaseCompositeEncoder(positiveInfinity) { _, index, value -> it[index] = value } }
1213
StructureKind.MAP, StructureKind.CLASS -> json()
1314
.also { value = it }
1415
.let { FirebaseCompositeEncoder(positiveInfinity) { _, index, value -> it[desc.getElementName(index)] = value } }

firebase-database/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@teamhubapp/firebase-database",
3-
"version": "0.1.0-dev9",
3+
"version": "0.1.0-dev12",
44
"description": "Wrapper around firebase for usage in Kotlin Multiplatform projects",
55
"main": "firebase-database.js",
66
"scripts": {
@@ -23,10 +23,10 @@
2323
},
2424
"homepage": "https://github.com/TeamHubApp/firebase-kotlin-multiplatform-sdk",
2525
"dependencies": {
26-
"@teamhubapp/firebase-app": "0.1.0-dev9",
26+
"@teamhubapp/firebase-app": "0.1.0-dev12",
2727
"firebase": "6.2.3",
2828
"kotlin": "1.3.61",
29-
"kotlinx-coroutines-core": "1.3.3"
29+
"kotlinx-coroutines-core": "1.3.2"
3030
}
3131
}
3232

firebase-database/src/jsMain/kotlin/dev/teamhub/firebase/database/database.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ actual open class Query internal constructor(open val js: firebase.database.Quer
7070
awaitClose { rethrow { listeners.forEach { (eventType, listener) -> js.off(eventType, listener) } } }
7171
}
7272

73-
actual fun startAt(value: String, key: String?) = Query(js.startAt(value, key))
73+
actual fun startAt(value: String, key: String?) = Query(js.startAt(value, key ?: undefined))
7474

75-
actual fun startAt(value: Double, key: String?) = Query(js.startAt(value, key))
75+
actual fun startAt(value: Double, key: String?) = Query(js.startAt(value, key ?: undefined))
7676

77-
actual fun startAt(value: Boolean, key: String?) = Query(js.startAt(value, key))
77+
actual fun startAt(value: Boolean, key: String?) = Query(js.startAt(value, key ?: undefined))
7878

7979
override fun toString() = js.toString()
8080

@@ -137,7 +137,7 @@ actual class OnDisconnect internal constructor(val js: firebase.database.OnDisco
137137
}
138138

139139
actual class DatabaseException(error: dynamic) :
140-
RuntimeException("${error?.code}: ${error.message}", error.unsafeCast<Throwable>())
140+
RuntimeException("${error.code ?: "UNKNOWN"}: ${error.message}", error.unsafeCast<Throwable>())
141141

142142
inline fun <T, R> T.rethrow(function: T.() -> R): R = dev.teamhub.firebase.database.rethrow { function() }
143143

firebase-firestore/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@teamhubapp/firebase-firestore",
3-
"version": "0.1.0-dev9",
3+
"version": "0.1.0-dev12",
44
"description": "Wrapper around firebase for usage in Kotlin Multiplatform projects",
55
"main": "firebase-firestore.js",
66
"scripts": {
@@ -23,10 +23,10 @@
2323
},
2424
"homepage": "https://github.com/TeamHubApp/firebase-kotlin-sdk",
2525
"dependencies": {
26-
"@teamhubapp/firebase-app": "0.1.0-dev9",
26+
"@teamhubapp/firebase-app": "0.1.0-dev12",
2727
"firebase": "6.2.3",
2828
"kotlin": "1.3.61",
29-
"kotlinx-coroutines-core": "1.3.3"
29+
"kotlinx-coroutines-core": "1.3.2"
3030
}
3131
}
3232

0 commit comments

Comments
 (0)