Skip to content
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

Fix OnDisconnect failing to updateChildren #494

Merged
merged 15 commits into from
May 4, 2024
Merged
Show file tree
Hide file tree
Changes from 12 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
4 changes: 2 additions & 2 deletions firebase-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gitlive/firebase-app",
"version": "1.11.1",
"version": "1.12.0",
"description": "Wrapper around firebase for usage in Kotlin Multiplatform projects",
"main": "firebase-app.js",
"scripts": {
Expand All @@ -23,7 +23,7 @@
},
"homepage": "https://github.com/GitLiveApp/firebase-kotlin-sdk",
"dependencies": {
"@gitlive/firebase-common": "1.11.1",
"@gitlive/firebase-common": "1.12.0",
"firebase": "9.19.1",
"kotlin": "1.8.20",
"kotlinx-coroutines-core": "1.6.4"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@

package dev.gitlive.firebase.auth

import dev.gitlive.firebase.*
import dev.gitlive.firebase.Firebase
import dev.gitlive.firebase.FirebaseOptions
import dev.gitlive.firebase.apps
import dev.gitlive.firebase.initialize
import dev.gitlive.firebase.runBlockingTest
import dev.gitlive.firebase.runTest
import kotlin.random.Random
import kotlin.test.*

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

package dev.gitlive.firebase.auth

import dev.gitlive.firebase.*
import dev.gitlive.firebase.Firebase
import dev.gitlive.firebase.FirebaseApp
import dev.gitlive.firebase.FirebaseException
import dev.gitlive.firebase.FirebaseNetworkException
import dev.gitlive.firebase.auth.externals.*
import kotlinx.coroutines.await
import kotlinx.coroutines.channels.awaitClose
Expand Down
182 changes: 182 additions & 0 deletions firebase-common-internal/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSetTree

/*
* Copyright (c) 2020 GitLive Ltd. Use of this source code is governed by the Apache 2.0 license.
*/

version = project.property("firebase-common-internal.version") as String

plugins {
id("com.android.library")
kotlin("multiplatform")
kotlin("plugin.serialization")
}

android {
val minSdkVersion: Int by project
val compileSdkVersion: Int by project

compileSdk = compileSdkVersion
namespace = "dev.gitlive.firebase.common.internal"
defaultConfig {
minSdk = minSdkVersion
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}

testOptions {
unitTests.apply {
isIncludeAndroidResources = true
}
}

packaging {
resources.pickFirsts.add("META-INF/kotlinx-serialization-core.kotlin_module")
resources.pickFirsts.add("META-INF/AL2.0")
resources.pickFirsts.add("META-INF/LGPL2.1")
}
lint {
abortOnError = false
}
}

kotlin {

targets.configureEach {
compilations.configureEach {
kotlinOptions.freeCompilerArgs += "-Xexpect-actual-classes"
}
}

@Suppress("OPT_IN_USAGE")
androidTarget {
instrumentedTestVariant.sourceSetTree.set(KotlinSourceSetTree.test)
unitTestVariant.sourceSetTree.set(KotlinSourceSetTree.test)
publishAllLibraryVariants()
compilations.configureEach {
kotlinOptions {
jvmTarget = "11"
}
}
}

jvm {
compilations.getByName("main") {
kotlinOptions {
jvmTarget = "17"
}
}
compilations.getByName("test") {
kotlinOptions {
jvmTarget = "17"
}
}
}

val supportIosTarget = project.property("skipIosTarget") != "true"

if (supportIosTarget) {
iosArm64()
iosX64()
iosSimulatorArm64()
}

js(IR) {
useCommonJs()
nodejs {
testTask(
Action {
useKarma {
useChromeHeadless()
}
}
)
}
browser {
testTask(
Action {
useKarma {
useChromeHeadless()
}
}
)
}
}

sourceSets {
all {
languageSettings.apply {
val apiVersion: String by project
val languageVersion: String by project
this.apiVersion = apiVersion
this.languageVersion = languageVersion
progressiveMode = true
optIn("kotlinx.coroutines.ExperimentalCoroutinesApi")
optIn("kotlinx.serialization.ExperimentalSerializationApi")
optIn("kotlinx.serialization.InternalSerializationApi")
}
}

getByName("commonMain") {
val serializationVersion: String by project

dependencies {
implementation(project(":firebase-common"))
api("org.jetbrains.kotlinx:kotlinx-serialization-core:$serializationVersion")
}
}

getByName("commonTest") {
dependencies {
implementation(project(":test-utils"))
}
}

getByName("androidMain") {
dependencies {
api("com.google.firebase:firebase-common-ktx")
}
}

getByName("jsMain") {
dependencies {
api(npm("firebase", "10.6.0"))
}
}

getByName("jvmMain") {
kotlin.srcDir("src/androidMain/kotlin")
}

getByName("jvmTest") {
dependencies {
implementation(kotlin("test-junit"))
}
kotlin.srcDir("src/androidAndroidTest/kotlin")
}
}
}

if (project.property("firebase-common.skipIosTests") == "true") {
tasks.forEach {
if (it.name.contains("ios", true) && it.name.contains("test", true)) { it.enabled = false }
}
}

if (project.property("firebase-common.skipJsTests") == "true") {
tasks.forEach {
if (it.name.contains("js", true) && it.name.contains("test", true)) { it.enabled = false }
}
}

signing {
val signingKey: String? by project
val signingPassword: String? by project
useInMemoryPgpKeys(signingKey, signingPassword)
sign(publishing.publications)
}

32 changes: 32 additions & 0 deletions firebase-common-internal/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "@gitlive/firebase-common-internal",
"version": "1.12.0",
"description": "Wrapper around firebase for usage in Kotlin Multiplatform projects",
"main": "firebase-common-internal.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/GitLiveApp/firebase-kotlin-sdk.git"
},
"keywords": [
"kotlin",
"multiplatform",
"kotlin-js",
"firebase"
],
"author": "dev.gitlive",
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/GitLiveApp/firebase-kotlin-multiplatform-sdk/issues"
},
"homepage": "https://github.com/GitLiveApp/firebase-kotlin-multiplatform-sdk",
"dependencies": {
"@gitlive/firebase-common": "1.12.0",
"firebase": "9.19.1",
"kotlin": "1.8.20",
"kotlinx-coroutines-core": "1.6.4",
"kotlinx-serialization-kotlinx-serialization-runtime": "1.3.2"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@file:JvmName("AndroidEncodedObject")
package dev.gitlive.firebase.internal

val EncodedObject.android: Map<String, Any?> get() = raw

@PublishedApi
internal actual fun Any.asNativeMap(): Map<*, *>? = this as? Map<*, *>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright (c) 2020 GitLive Ltd. Use of this source code is governed by the Apache 2.0 license.
*/

package dev.gitlive.firebase
package dev.gitlive.firebase.internal

import kotlinx.serialization.descriptors.PolymorphicKind
import kotlinx.serialization.descriptors.SerialDescriptor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright (c) 2020 GitLive Ltd. Use of this source code is governed by the Apache 2.0 license.
*/

package dev.gitlive.firebase
package dev.gitlive.firebase.internal

import kotlinx.serialization.descriptors.PolymorphicKind
import kotlinx.serialization.descriptors.SerialDescriptor
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package dev.gitlive.firebase.internal

import dev.gitlive.firebase.DecodeSettings
import dev.gitlive.firebase.EncodeDecodeSettingsBuilder
import dev.gitlive.firebase.EncodeSettings
import kotlinx.serialization.modules.EmptySerializersModule
import kotlinx.serialization.modules.SerializersModule

@PublishedApi
internal data class EncodeSettingsImpl internal constructor(
override val encodeDefaults: Boolean,
override val serializersModule: SerializersModule,
) : EncodeSettings {

@PublishedApi
internal class Builder : EncodeSettings.Builder {
override var encodeDefaults: Boolean = true
override var serializersModule: SerializersModule = EmptySerializersModule()
}
}

@PublishedApi
internal class DecodeSettingsImpl internal constructor(
override val serializersModule: SerializersModule = EmptySerializersModule(),
) : DecodeSettings {

@PublishedApi
internal class Builder : DecodeSettings.Builder {
override var serializersModule: SerializersModule = EmptySerializersModule()
}
}

@PublishedApi
internal class EncodeDecodeSettingsBuilderImpl : EncodeDecodeSettingsBuilder {

override var encodeDefaults: Boolean = true
override var serializersModule: SerializersModule = EmptySerializersModule()
}

@PublishedApi
internal fun EncodeSettings.Builder.buildEncodeSettings(): EncodeSettings = EncodeSettingsImpl(encodeDefaults, serializersModule)
@PublishedApi
internal fun DecodeSettings.Builder.buildDecodeSettings(): DecodeSettings = DecodeSettingsImpl(serializersModule)
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package dev.gitlive.firebase.internal

import kotlin.jvm.JvmInline

/**
* Platform specific object for storing encoded data that can be used for methods that explicitly require an object.
* This is essentially a [Map] of [String] and [Any]? (as represented by [raw]) but since [encode] gives a platform specific value, this method wraps that.
*/
sealed interface EncodedObject {
val raw: Map<String, Any?>
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whats the purpose of still exposing this to clients?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Figured it would be useful. Moved to an internal get method now (cant be value due to JS weirdness)


@JvmInline
@PublishedApi
internal value class EncodedObjectImpl(override val raw: Map<String, Any?>) : EncodedObject

@PublishedApi
internal expect fun Any.asNativeMap(): Map<*, *>?

@PublishedApi
internal fun Map<*, *>.asEncodedObject(): EncodedObject = map { (key, value) ->
if (key is String) {
key to value
} else {
throw IllegalArgumentException("Expected a String key but received $key")
}
}.toMap().let(::EncodedObjectImpl)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.gitlive.firebase
package dev.gitlive.firebase.internal

import dev.gitlive.firebase.FirebaseClassDiscriminator
import kotlinx.serialization.DeserializationStrategy
import kotlinx.serialization.SerializationStrategy
import kotlinx.serialization.descriptors.SerialDescriptor
Expand Down
Loading
Loading