Skip to content

Commit 9d72403

Browse files
authored
Merge branch 'master' into ios-support
2 parents 8679203 + e7704bc commit 9d72403

File tree

13 files changed

+64
-35
lines changed

13 files changed

+64
-35
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
🔓 <a href="https://teamhub.typeform.com/to/uSS8cv">Request Early Access</a>
66
<h4></h4>
77

8-
The Firebase Kotlin SDK implements the client-side libraries used by applications using Firebase services.
8+
The Firebase Kotlin SDK is a Kotlin-first SDK for Firebase. It's API is similar to the [Firebase Android SDK Kotlin Extensions](https://firebase.github.io/firebase-android-sdk/reference/kotlin/firebase-ktx/) but it also supports multiplatform projects, enabling you to use Firebase directly from your common source targeting *iOS*, *Android* or *JS*.
9+
10+
## Kotlin-first design
911

10-
It a light-weight Kotlin layer that mirrors the [Firebase Android SDK Kotlin Extensions](https://firebase.github.io/firebase-android-sdk/reference/kotlin/firebase-ktx/) but connects to the correct native Firebase SDK for each target platform, enabling you to use Firebase directly from your common source in multiplatform projects targeting *iOS*, *Android* or *JS*.
1112

1213
## Available libraries
1314

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/build.gradle.kts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ plugins {
44
id("com.android.library")
55
kotlin("multiplatform")
66
kotlin("native.cocoapods")
7+
kotlin("plugin.serialization") version "1.3.61"
78
`maven-publish`
89
}
910
repositories {
@@ -80,6 +81,12 @@ kotlin {
8081
}
8182
kotlin.srcDir("src/androidMain/kotlin")
8283
}
84+
val jvmTest by getting {
85+
dependencies {
86+
implementation(kotlin("test-junit"))
87+
}
88+
kotlin.srcDir("src/androidTest/kotlin")
89+
}
8390
val iosMain by getting {
8491
dependencies {
8592
implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:0.14.0")

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: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package dev.teamhub.firebase
22

33
import kotlinx.serialization.*
4+
import kotlinx.serialization.internal.ListLikeSerializer
5+
import kotlinx.serialization.internal.MapLikeSerializer
46
import kotlinx.serialization.modules.EmptyModule
57

68
fun <T> encode(strategy: SerializationStrategy<T> , value: T, positiveInfinity: Any = Double.POSITIVE_INFINITY): Any? =
@@ -82,23 +84,24 @@ abstract class TimestampEncoder(internal val positiveInfinity: Any) {
8284
}
8385
}
8486

85-
open class FirebaseCompositeEncoder(
87+
open class FirebaseCompositeEncoder constructor(
8688
positiveInfinity: Any,
87-
private val end: () -> Unit = {},
8889
private val set: (desc: SerialDescriptor, index: Int, value: Any?) -> Unit
8990
): TimestampEncoder(positiveInfinity), CompositeEncoder {
9091

9192
override val context = EmptyModule
9293

93-
override fun endStructure(desc: SerialDescriptor) {
94-
super.endStructure(desc)
94+
private fun <T> SerializationStrategy<T>.toFirebase(): SerializationStrategy<T> = when(this) {
95+
is MapLikeSerializer<*, *, *, *> -> FirebaseMapSerializer() as SerializationStrategy<T>
96+
is ListLikeSerializer<*, *, *> -> FirebaseListSerializer() as SerializationStrategy<T>
97+
else -> this
9598
}
9699

97100
override fun <T : Any> encodeNullableSerializableElement(desc: SerialDescriptor, index: Int, serializer: SerializationStrategy<T>, value: T?) =
98-
set(desc, index, value?.let { FirebaseEncoder(positiveInfinity).apply { encode(serializer, value) }.value })
101+
set(desc, index, value?.let { FirebaseEncoder(positiveInfinity).apply { encode(serializer.toFirebase(), value) }.value })
99102

100103
override fun <T> encodeSerializableElement(desc: SerialDescriptor, index: Int, serializer: SerializationStrategy<T>, value: T) =
101-
set(desc, index, FirebaseEncoder(positiveInfinity).apply { encode(serializer, value) }.value)
104+
set(desc, index, FirebaseEncoder(positiveInfinity).apply { encode(serializer.toFirebase(), value) }.value)
102105

103106
override fun encodeNonSerializableElement(desc: SerialDescriptor, index: Int, value: Any) = set(desc, index, value)
104107

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

0 commit comments

Comments
 (0)