Skip to content

Commit e316f61

Browse files
authored
Merge branch 'master' into feature/fix-gcm-sender0id
2 parents 91cbba7 + a2f103d commit e316f61

File tree

73 files changed

+2705
-1437
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+2705
-1437
lines changed

README.md

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ The following libraries are available for the various Firebase products.
1616

1717
| Service or Product | Gradle Dependency | API Coverage |
1818
|---------------------------------------------------------------------------------|:-------------------------------------------------------------------------------------------------------------------------------|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
19-
| [Authentication](https://firebase.google.com/docs/auth) | [`dev.gitlive:firebase-auth:1.10.4`](https://search.maven.org/artifact/dev.gitlive/firebase-auth/1.10.4/pom) | [![80%](https://img.shields.io/badge/-80%25-green?style=flat-square)](/firebase-auth/src/commonMain/kotlin/dev/gitlive/firebase/auth/auth.kt) |
20-
| [Realtime Database](https://firebase.google.com/docs/database) | [`dev.gitlive:firebase-database:1.10.4`](https://search.maven.org/artifact/dev.gitlive/firebase-database/1.10.4/pom) | [![70%](https://img.shields.io/badge/-70%25-orange?style=flat-square)](/firebase-database/src/commonMain/kotlin/dev/gitlive/firebase/database/database.kt) |
21-
| [Cloud Firestore](https://firebase.google.com/docs/firestore) | [`dev.gitlive:firebase-firestore:1.10.4`](https://search.maven.org/artifact/dev.gitlive/firebase-firestore/1.10.4/pom) | [![60%](https://img.shields.io/badge/-60%25-orange?style=flat-square)](/firebase-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore/firestore.kt) |
22-
| [Cloud Functions](https://firebase.google.com/docs/functions) | [`dev.gitlive:firebase-functions:1.10.4`](https://search.maven.org/artifact/dev.gitlive/firebase-functions/1.10.4/pom) | [![80%](https://img.shields.io/badge/-80%25-green?style=flat-square)](/firebase-functions/src/commonMain/kotlin/dev/gitlive/firebase/functions/functions.kt) |
23-
| [Cloud Messaging](https://firebase.google.com/docs/cloud-messaging) | [`dev.gitlive:firebase-messaging:1.10.4`](https://search.maven.org/artifact/dev.gitlive/firebase-messaging/1.10.4/pom) | ![0%](https://img.shields.io/badge/-0%25-lightgrey?style=flat-square) |
24-
| [Cloud Storage](https://firebase.google.com/docs/storage) | [`dev.gitlive:firebase-storage:1.10.4`](https://search.maven.org/artifact/dev.gitlive/firebase-storage/1.10.4/pom) | [![40%](https://img.shields.io/badge/-40%25-orange?style=flat-square)](/firebase-storage/src/commonMain/kotlin/dev/gitlive/firebase/storage/storage.kt) |
25-
| [Installations](https://firebase.google.com/docs/projects/manage-installations) | [`dev.gitlive:firebase-installations:1.10.4`](https://search.maven.org/artifact/dev.gitlive/firebase-installations/1.10.4/pom) | [![90%](https://img.shields.io/badge/-90%25-green?style=flat-square)](/firebase-installations/src/commonMain/kotlin/dev/gitlive/firebase/installations/installations.kt) |
26-
| [Remote Config](https://firebase.google.com/docs/remote-config) | [`dev.gitlive:firebase-config:1.10.4`](https://search.maven.org/artifact/dev.gitlive/firebase-config/1.10.4/pom) | [![20%](https://img.shields.io/badge/-20%25-orange?style=flat-square)](/firebase-config/src/commonMain/kotlin/dev/gitlive/firebase/remoteconfig/FirebaseRemoteConfig.kt) |
27-
| [Performance](https://firebase.google.com/docs/perf-mon) | [`dev.gitlive:firebase-perf:1.10.4`](https://search.maven.org/artifact/dev.gitlive/firebase-perf/1.10.4/pom) | [![1%](https://img.shields.io/badge/-1%25-orange?style=flat-square)](/firebase-perf/src/commonMain/kotlin/dev/gitlive/firebase/perf/performance.kt) |
28-
| [Crashlytics](https://firebase.google.com/docs/crashlytics) | [`dev.gitlive:firebase-crashlytics:1.10.4`](https://search.maven.org/artifact/dev.gitlive/firebase-crashlytics/1.10.4/pom) | [![80%](https://img.shields.io/badge/-1%25-orange?style=flat-square)](/firebase-crashlytics/src/commonMain/kotlin/dev/gitlive/firebase/crashlytics/crashlytics.kt) |
19+
| [Authentication](https://firebase.google.com/docs/auth) | [`dev.gitlive:firebase-auth:1.12.0`](https://search.maven.org/artifact/dev.gitlive/firebase-auth/1.12.0/pom) | [![80%](https://img.shields.io/badge/-80%25-green?style=flat-square)](/firebase-auth/src/commonMain/kotlin/dev/gitlive/firebase/auth/auth.kt) |
20+
| [Realtime Database](https://firebase.google.com/docs/database) | [`dev.gitlive:firebase-database:1.12.0`](https://search.maven.org/artifact/dev.gitlive/firebase-database/1.12.0/pom) | [![70%](https://img.shields.io/badge/-70%25-orange?style=flat-square)](/firebase-database/src/commonMain/kotlin/dev/gitlive/firebase/database/database.kt) |
21+
| [Cloud Firestore](https://firebase.google.com/docs/firestore) | [`dev.gitlive:firebase-firestore:1.12.0`](https://search.maven.org/artifact/dev.gitlive/firebase-firestore/1.12.0/pom) | [![60%](https://img.shields.io/badge/-60%25-orange?style=flat-square)](/firebase-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore/firestore.kt) |
22+
| [Cloud Functions](https://firebase.google.com/docs/functions) | [`dev.gitlive:firebase-functions:1.12.0`](https://search.maven.org/artifact/dev.gitlive/firebase-functions/1.12.0/pom) | [![80%](https://img.shields.io/badge/-80%25-green?style=flat-square)](/firebase-functions/src/commonMain/kotlin/dev/gitlive/firebase/functions/functions.kt) |
23+
| [Cloud Messaging](https://firebase.google.com/docs/cloud-messaging) | [`dev.gitlive:firebase-messaging:1.12.0`](https://search.maven.org/artifact/dev.gitlive/firebase-messaging/1.12.0/pom) | ![0%](https://img.shields.io/badge/-0%25-lightgrey?style=flat-square) |
24+
| [Cloud Storage](https://firebase.google.com/docs/storage) | [`dev.gitlive:firebase-storage:1.12.0`](https://search.maven.org/artifact/dev.gitlive/firebase-storage/1.12.0/pom) | [![40%](https://img.shields.io/badge/-40%25-orange?style=flat-square)](/firebase-storage/src/commonMain/kotlin/dev/gitlive/firebase/storage/storage.kt) |
25+
| [Installations](https://firebase.google.com/docs/projects/manage-installations) | [`dev.gitlive:firebase-installations:1.12.0`](https://search.maven.org/artifact/dev.gitlive/firebase-installations/1.12.0/pom) | [![90%](https://img.shields.io/badge/-90%25-green?style=flat-square)](/firebase-installations/src/commonMain/kotlin/dev/gitlive/firebase/installations/installations.kt) |
26+
| [Remote Config](https://firebase.google.com/docs/remote-config) | [`dev.gitlive:firebase-config:1.12.0`](https://search.maven.org/artifact/dev.gitlive/firebase-config/1.12.0/pom) | [![20%](https://img.shields.io/badge/-20%25-orange?style=flat-square)](/firebase-config/src/commonMain/kotlin/dev/gitlive/firebase/remoteconfig/FirebaseRemoteConfig.kt) |
27+
| [Performance](https://firebase.google.com/docs/perf-mon) | [`dev.gitlive:firebase-perf:1.12.0`](https://search.maven.org/artifact/dev.gitlive/firebase-perf/1.12.0/pom) | [![1%](https://img.shields.io/badge/-1%25-orange?style=flat-square)](/firebase-perf/src/commonMain/kotlin/dev/gitlive/firebase/perf/performance.kt) |
28+
| [Crashlytics](https://firebase.google.com/docs/crashlytics) | [`dev.gitlive:firebase-crashlytics:1.12.0`](https://search.maven.org/artifact/dev.gitlive/firebase-crashlytics/1.12.0/pom) | [![80%](https://img.shields.io/badge/-1%25-orange?style=flat-square)](/firebase-crashlytics/src/commonMain/kotlin/dev/gitlive/firebase/crashlytics/crashlytics.kt) |
2929

3030
Is the Firebase library or API you need missing? [Create an issue](https://github.com/GitLiveApp/firebase-kotlin-sdk/issues/new?labels=API+coverage&template=increase-api-coverage.md&title=Add+%5Bclass+name%5D.%5Bfunction+name%5D+to+%5Blibrary+name%5D+for+%5Bplatform+names%5D) to request additional API coverage or be awesome and [submit a PR](https://github.com/GitLiveApp/firebase-kotlin-sdk/fork)
3131

@@ -70,8 +70,8 @@ The Firebase Kotlin SDK uses Kotlin serialization to read and write custom class
7070

7171
```groovy
7272
plugins {
73-
kotlin("multiplatform") version "1.8.21" // or kotlin("jvm") or any other kotlin plugin
74-
kotlin("plugin.serialization") version "1.8.21"
73+
kotlin("multiplatform") version "1.9.20" // or kotlin("jvm") or any other kotlin plugin
74+
kotlin("plugin.serialization") version "1.9.20"
7575
}
7676
```
7777

@@ -85,13 +85,43 @@ data class City(val name: String)
8585
Instances of these classes can now be passed [along with their serializer](https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/serializers.md#introduction-to-serializers) to the SDK:
8686

8787
```kotlin
88-
db.collection("cities").document("LA").set(City.serializer(), city, encodeDefaults = true)
88+
db.collection("cities").document("LA").set(City.serializer(), city) { encodeDefaults = true }
8989
```
9090

91-
The `encodeDefaults` parameter is optional and defaults to `true`, set this to false to omit writing optional properties if they are equal to theirs default values.
91+
The `buildSettings` closure is optional and allows for configuring serialization behaviour.
92+
93+
Setting the `encodeDefaults` parameter is optional and defaults to `true`, set this to false to omit writing optional properties if they are equal to theirs default values.
9294
Using [@EncodeDefault](https://kotlinlang.org/api/kotlinx.serialization/kotlinx-serialization-core/kotlinx.serialization/-encode-default/) on properties is a recommended way to locally override the behavior set with `encodeDefaults`.
9395

94-
You can also omit the serializer but this is discouraged due to a [current limitation on Kotlin/JS and Kotlin/Native](https://github.com/Kotlin/kotlinx.serialization/issues/1116#issuecomment-704342452)
96+
You can also omit the serializer if it can be inferred using `serializer<KType>()`.
97+
To support [contextual serialization](https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/serializers.md#contextual-serialization) or [open polymorphism](https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/polymorphism.md#open-polymorphism) the `serializersModule` can be overridden in the `buildSettings` closure:
98+
99+
```kotlin
100+
@Serializable
101+
abstract class AbstractCity {
102+
abstract val name: String
103+
}
104+
105+
@Serializable
106+
@SerialName("capital")
107+
data class Capital(override val name: String, val isSeatOfGovernment: Boolean) : AbstractCity()
108+
109+
val module = SerializersModule {
110+
polymorphic(AbstractCity::class, AbstractCity.serializer()) {
111+
subclass(Capital::class, Capital.serializer())
112+
}
113+
}
114+
115+
val city = Capital("London", true)
116+
db.collection("cities").document("UK").set(AbstractCity.serializer(), city) {
117+
encodeDefaults = true
118+
serializersModule = module
119+
120+
}
121+
val storedCity = db.collection("cities").document("UK").get().data(AbstractCity.serializer()) {
122+
serializersModule = module
123+
}
124+
```
95125

96126
<h4><a href="https://firebase.google.com/docs/firestore/manage-data/add-data#server_timestamp">Server Timestamp</a></h3>
97127

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ subprojects {
117117
"commonTestImplementation"(kotlin("test-common"))
118118
"commonTestImplementation"(kotlin("test-annotations-common"))
119119
if (this@afterEvaluate.name != "firebase-crashlytics") {
120-
"jvmMainApi"("dev.gitlive:firebase-java-sdk:0.3.0")
120+
"jvmMainApi"("dev.gitlive:firebase-java-sdk:0.4.0")
121121
"jvmMainApi"("org.jetbrains.kotlinx:kotlinx-coroutines-play-services:$coroutinesVersion") {
122122
exclude("com.google.android.gms")
123123
}

firebase-app/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@gitlive/firebase-app",
3-
"version": "1.11.0",
3+
"version": "1.11.1",
44
"description": "Wrapper around firebase for usage in Kotlin Multiplatform projects",
55
"main": "firebase-app.js",
66
"scripts": {
@@ -23,7 +23,7 @@
2323
},
2424
"homepage": "https://github.com/GitLiveApp/firebase-kotlin-sdk",
2525
"dependencies": {
26-
"@gitlive/firebase-common": "1.11.0",
26+
"@gitlive/firebase-common": "1.11.1",
2727
"firebase": "9.19.1",
2828
"kotlin": "1.8.20",
2929
"kotlinx-coroutines-core": "1.6.4"

firebase-auth/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@gitlive/firebase-auth",
3-
"version": "1.11.0",
3+
"version": "1.12.0",
44
"description": "Wrapper around firebase for usage in Kotlin Multiplatform projects",
55
"main": "firebase-auth.js",
66
"scripts": {
@@ -23,7 +23,7 @@
2323
},
2424
"homepage": "https://github.com/GitLiveApp/firebase-kotlin-sdk",
2525
"dependencies": {
26-
"@gitlive/firebase-app": "1.11.0",
26+
"@gitlive/firebase-app": "1.12.0",
2727
"firebase": "9.19.1",
2828
"kotlin": "1.8.20",
2929
"kotlinx-coroutines-core": "1.6.4"

firebase-common/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@gitlive/firebase-common",
3-
"version": "1.11.0",
3+
"version": "1.11.1",
44
"description": "Wrapper around firebase for usage in Kotlin Multiplatform projects",
55
"main": "firebase-common.js",
66
"scripts": {

firebase-common/src/androidMain/kotlin/dev/gitlive/firebase/_decoders.kt

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,41 @@
44

55
package dev.gitlive.firebase
66

7-
import kotlinx.serialization.encoding.CompositeDecoder
87
import kotlinx.serialization.descriptors.PolymorphicKind
98
import kotlinx.serialization.descriptors.SerialDescriptor
109
import kotlinx.serialization.descriptors.StructureKind
10+
import kotlinx.serialization.encoding.CompositeDecoder
1111

12-
actual fun FirebaseDecoder.structureDecoder(descriptor: SerialDescriptor): CompositeDecoder = when(descriptor.kind) {
13-
StructureKind.CLASS, StructureKind.OBJECT, PolymorphicKind.SEALED -> (value as Map<*, *>).let { map ->
14-
FirebaseClassDecoder(map.size, { map.containsKey(it) }) { desc, index ->
15-
val elementName = desc.getElementName(index)
16-
if (desc.kind is PolymorphicKind && elementName == "value") {
17-
map
18-
} else {
19-
map[desc.getElementName(index)]
20-
}
21-
}
22-
}
23-
StructureKind.LIST ->
24-
when(value) {
25-
is List<*> -> value
26-
is Map<*, *> -> value.asSequence()
27-
.sortedBy { (it) -> it.toString().toIntOrNull() }
28-
.map { (_, it) -> it }
29-
.toList()
30-
else -> error("unexpected type, got $value when expecting a list")
31-
}
32-
.let { FirebaseCompositeDecoder(it.size) { _, index -> it[index] } }
33-
StructureKind.MAP -> (value as Map<*, *>).entries.toList().let {
34-
FirebaseCompositeDecoder(it.size) { _, index -> it[index/2].run { if(index % 2 == 0) key else value } }
35-
}
36-
else -> TODO("The firebase-kotlin-sdk does not support $descriptor for serialization yet")
12+
actual fun FirebaseDecoder.structureDecoder(descriptor: SerialDescriptor, polymorphicIsNested: Boolean): CompositeDecoder = when (descriptor.kind) {
13+
StructureKind.CLASS, StructureKind.OBJECT -> decodeAsMap(false)
14+
StructureKind.LIST -> (value as? List<*>).orEmpty().let {
15+
FirebaseCompositeDecoder(it.size, settings) { _, index -> it[index] }
3716
}
3817

18+
StructureKind.MAP -> (value as? Map<*, *>).orEmpty().entries.toList().let {
19+
FirebaseCompositeDecoder(
20+
it.size,
21+
settings
22+
) { _, index -> it[index / 2].run { if (index % 2 == 0) key else value } }
23+
}
24+
25+
is PolymorphicKind -> decodeAsMap(polymorphicIsNested)
26+
else -> TODO("The firebase-kotlin-sdk does not support $descriptor for serialization yet")
27+
}
28+
3929
actual fun getPolymorphicType(value: Any?, discriminator: String): String =
40-
(value as Map<*,*>)[discriminator] as String
30+
(value as? Map<*,*>).orEmpty()[discriminator] as String
31+
32+
private fun FirebaseDecoder.decodeAsMap(isNestedPolymorphic: Boolean): CompositeDecoder = (value as? Map<*, *>).orEmpty().let { map ->
33+
FirebaseClassDecoder(map.size, settings, { map.containsKey(it) }) { desc, index ->
34+
if (isNestedPolymorphic) {
35+
if (desc.getElementName(index) == "value")
36+
map
37+
else {
38+
map[desc.getElementName(index)]
39+
}
40+
} else {
41+
map[desc.getElementName(index)]
42+
}
43+
}
44+
}

firebase-common/src/androidMain/kotlin/dev/gitlive/firebase/_encoders.kt

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,30 @@
44

55
package dev.gitlive.firebase
66

7+
import kotlinx.serialization.descriptors.PolymorphicKind
78
import kotlinx.serialization.descriptors.SerialDescriptor
89
import kotlinx.serialization.descriptors.StructureKind
910
import kotlin.collections.set
1011

1112
actual fun FirebaseEncoder.structureEncoder(descriptor: SerialDescriptor): FirebaseCompositeEncoder = when(descriptor.kind) {
1213
StructureKind.LIST -> mutableListOf<Any?>()
1314
.also { value = it }
14-
.let { FirebaseCompositeEncoder(shouldEncodeElementDefault) { _, index, value -> it.add(index, value) } }
15+
.let { FirebaseCompositeEncoder(settings) { _, index, value -> it.add(index, value) } }
1516
StructureKind.MAP -> mutableListOf<Any?>()
16-
.let { FirebaseCompositeEncoder(shouldEncodeElementDefault, { value = it.chunked(2).associate { (k, v) -> k to v } }) { _, _, value -> it.add(value) } }
17-
StructureKind.CLASS, StructureKind.OBJECT -> mutableMapOf<Any?, Any?>()
18-
.also { value = it }
19-
.let { FirebaseCompositeEncoder(shouldEncodeElementDefault,
17+
.let { FirebaseCompositeEncoder(settings, { value = it.chunked(2).associate { (k, v) -> k to v } }) { _, _, value -> it.add(value) } }
18+
StructureKind.CLASS, StructureKind.OBJECT -> encodeAsMap(descriptor)
19+
is PolymorphicKind -> encodeAsMap(descriptor)
20+
else -> TODO("The firebase-kotlin-sdk does not support $descriptor for serialization yet")
21+
}
22+
23+
private fun FirebaseEncoder.encodeAsMap(descriptor: SerialDescriptor): FirebaseCompositeEncoder = mutableMapOf<Any?, Any?>()
24+
.also { value = it }
25+
.let {
26+
FirebaseCompositeEncoder(
27+
settings,
2028
setPolymorphicType = { discriminator, type ->
2129
it[discriminator] = type
2230
},
2331
set = { _, index, value -> it[descriptor.getElementName(index)] = value }
24-
) }
25-
else -> TODO("The firebase-kotlin-sdk does not support $descriptor for serialization yet")
26-
}
32+
)
33+
}

0 commit comments

Comments
 (0)