From 9f7d3cbf4eb41084c1ceb439417f89882c4397a4 Mon Sep 17 00:00:00 2001 From: Gijs van Veen Date: Sat, 13 Apr 2024 12:03:04 +0200 Subject: [PATCH 1/2] Move parts of the firebase-common module to new firebase-common-internal New module to explicitly mark difference between Common properties that are public facing and those that should be internal --- firebase-app/package.json | 4 +- .../kotlin/dev/gitlive/firebase/auth/auth.kt | 7 +- .../kotlin/dev/gitlive/firebase/auth/auth.kt | 4 +- firebase-common-internal/build.gradle.kts | 182 ++++++++++++++++++ firebase-common-internal/package.json | 32 +++ .../gitlive/firebase/internal}/_decoders.kt | 2 +- .../gitlive/firebase/internal}/_encoders.kt | 8 +- .../firebase/internal/EncodeDecodeSettings.kt | 43 +++++ .../gitlive/firebase/internal}/Polymorphic.kt | 3 +- .../gitlive/firebase/internal}/decoders.kt | 9 +- .../gitlive/firebase/internal}/encoders.kt | 19 +- .../internal}/reencodeTransformation.kt | 3 +- .../gitlive/firebase/internal}/serializers.kt | 2 +- .../firebase/internal}/EncodersTest.kt | 52 ++++- .../gitlive/firebase/internal}/_decoders.kt | 2 +- .../gitlive/firebase/internal}/_encoders.kt | 7 +- .../gitlive/firebase/internal}/_decoders.kt | 2 +- .../gitlive/firebase/internal}/_encoders.kt | 11 +- firebase-common/package.json | 2 +- .../dev/gitlive/firebase/EncodedObject.kt | 9 + .../gitlive/firebase/EncodeDecodeSettings.kt | 39 +--- .../dev/gitlive/firebase/EncodedObject.kt | 13 ++ .../dev/gitlive/firebase/EncodedObject.kt | 9 + .../dev/gitlive/firebase/EncodedObject.kt | 12 ++ firebase-config/package.json | 4 +- firebase-crashlytics/package.json | 2 +- firebase-database/build.gradle.kts | 3 +- firebase-database/package.json | 4 +- .../dev/gitlive/firebase/database/database.kt | 4 +- .../gitlive/firebase/database/ServerValue.kt | 6 +- .../dev/gitlive/firebase/database/database.kt | 4 +- .../dev/gitlive/firebase/database/database.kt | 4 +- .../dev/gitlive/firebase/database/database.kt | 4 +- .../firebase/database/externals/database.kt | 2 +- .../dev/gitlive/firebase/database/database.kt | 1 - firebase-firestore/build.gradle.kts | 3 +- firebase-firestore/package.json | 4 +- .../firestore/DocumentReferenceSerializer.kt | 4 +- .../firestore/FieldValueSerializer.kt | 4 +- .../firebase/firestore/GeoPointSerializer.kt | 2 +- .../firebase/firestore/TimestampSerializer.kt | 3 +- .../gitlive/firebase/firestore/encoders.kt | 2 +- .../gitlive/firebase/firestore/firestore.kt | 9 +- .../firebase/firestore/FieldValueTests.kt | 2 +- .../firebase/firestore/GeoPointTests.kt | 4 +- .../firebase/firestore/TimestampTests.kt | 6 +- .../gitlive/firebase/firestore/firestore.kt | 4 +- .../gitlive/firebase/firestore/GeoPoint.kt | 1 - .../gitlive/firebase/firestore/firestore.kt | 5 +- .../firebase/firestore/ContextSwitchTest.kt | 7 +- firebase-functions/build.gradle.kts | 3 +- firebase-functions/package.json | 4 +- .../gitlive/firebase/functions/functions.kt | 2 +- .../gitlive/firebase/functions/functions.kt | 7 +- .../gitlive/firebase/functions/functions.kt | 7 +- .../gitlive/firebase/functions/functions.kt | 14 +- firebase-installations/package.json | 2 +- .../firebase/installations/installations.kt | 4 +- firebase-perf/package.json | 2 +- .../gitlive/firebase/perf/metrics/Trace.kt | 5 +- .../gitlive/firebase/perf/metrics/Trace.kt | 5 +- .../dev/gitlive/firebase/perf/performance.kt | 9 +- .../gitlive/firebase/perf/metrics/Trace.kt | 6 +- firebase-storage/package.json | 2 +- gradle.properties | 3 + settings.gradle.kts | 3 + 66 files changed, 502 insertions(+), 150 deletions(-) create mode 100644 firebase-common-internal/build.gradle.kts create mode 100644 firebase-common-internal/package.json rename {firebase-common/src/androidMain/kotlin/dev/gitlive/firebase => firebase-common-internal/src/androidMain/kotlin/dev/gitlive/firebase/internal}/_decoders.kt (97%) rename {firebase-common/src/androidMain/kotlin/dev/gitlive/firebase => firebase-common-internal/src/androidMain/kotlin/dev/gitlive/firebase/internal}/_encoders.kt (91%) create mode 100644 firebase-common-internal/src/commonMain/kotlin/dev/gitlive/firebase/internal/EncodeDecodeSettings.kt rename {firebase-common/src/commonMain/kotlin/dev/gitlive/firebase => firebase-common-internal/src/commonMain/kotlin/dev/gitlive/firebase/internal}/Polymorphic.kt (96%) rename {firebase-common/src/commonMain/kotlin/dev/gitlive/firebase => firebase-common-internal/src/commonMain/kotlin/dev/gitlive/firebase/internal}/decoders.kt (97%) rename {firebase-common/src/commonMain/kotlin/dev/gitlive/firebase => firebase-common-internal/src/commonMain/kotlin/dev/gitlive/firebase/internal}/encoders.kt (93%) rename {firebase-common/src/commonMain/kotlin/dev/gitlive/firebase => firebase-common-internal/src/commonMain/kotlin/dev/gitlive/firebase/internal}/reencodeTransformation.kt (90%) rename {firebase-common/src/commonMain/kotlin/dev/gitlive/firebase => firebase-common-internal/src/commonMain/kotlin/dev/gitlive/firebase/internal}/serializers.kt (99%) rename {firebase-common/src/commonTest/kotlin/dev/gitlive/firebase => firebase-common-internal/src/commonTest/kotlin/dev/gitlive/firebase/internal}/EncodersTest.kt (93%) rename {firebase-common/src/iosMain/kotlin/dev/gitlive/firebase => firebase-common-internal/src/iosMain/kotlin/dev/gitlive/firebase/internal}/_decoders.kt (97%) rename {firebase-common/src/iosMain/kotlin/dev/gitlive/firebase => firebase-common-internal/src/iosMain/kotlin/dev/gitlive/firebase/internal}/_encoders.kt (94%) rename {firebase-common/src/jsMain/kotlin/dev/gitlive/firebase => firebase-common-internal/src/jsMain/kotlin/dev/gitlive/firebase/internal}/_decoders.kt (98%) rename {firebase-common/src/jsMain/kotlin/dev/gitlive/firebase => firebase-common-internal/src/jsMain/kotlin/dev/gitlive/firebase/internal}/_encoders.kt (94%) create mode 100644 firebase-common/src/androidMain/kotlin/dev/gitlive/firebase/EncodedObject.kt create mode 100644 firebase-common/src/commonMain/kotlin/dev/gitlive/firebase/EncodedObject.kt create mode 100644 firebase-common/src/iosMain/kotlin/dev/gitlive/firebase/EncodedObject.kt create mode 100644 firebase-common/src/jsMain/kotlin/dev/gitlive/firebase/EncodedObject.kt diff --git a/firebase-app/package.json b/firebase-app/package.json index 81138414d..397e36723 100644 --- a/firebase-app/package.json +++ b/firebase-app/package.json @@ -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": { @@ -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" diff --git a/firebase-auth/src/commonTest/kotlin/dev/gitlive/firebase/auth/auth.kt b/firebase-auth/src/commonTest/kotlin/dev/gitlive/firebase/auth/auth.kt index ceaf34929..0c36bea7b 100644 --- a/firebase-auth/src/commonTest/kotlin/dev/gitlive/firebase/auth/auth.kt +++ b/firebase-auth/src/commonTest/kotlin/dev/gitlive/firebase/auth/auth.kt @@ -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.* diff --git a/firebase-auth/src/jsMain/kotlin/dev/gitlive/firebase/auth/auth.kt b/firebase-auth/src/jsMain/kotlin/dev/gitlive/firebase/auth/auth.kt index 9bfc2e61b..f2db371b4 100644 --- a/firebase-auth/src/jsMain/kotlin/dev/gitlive/firebase/auth/auth.kt +++ b/firebase-auth/src/jsMain/kotlin/dev/gitlive/firebase/auth/auth.kt @@ -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 diff --git a/firebase-common-internal/build.gradle.kts b/firebase-common-internal/build.gradle.kts new file mode 100644 index 000000000..8a62d7c47 --- /dev/null +++ b/firebase-common-internal/build.gradle.kts @@ -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) +} + diff --git a/firebase-common-internal/package.json b/firebase-common-internal/package.json new file mode 100644 index 000000000..e5bfd8389 --- /dev/null +++ b/firebase-common-internal/package.json @@ -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" + } +} diff --git a/firebase-common/src/androidMain/kotlin/dev/gitlive/firebase/_decoders.kt b/firebase-common-internal/src/androidMain/kotlin/dev/gitlive/firebase/internal/_decoders.kt similarity index 97% rename from firebase-common/src/androidMain/kotlin/dev/gitlive/firebase/_decoders.kt rename to firebase-common-internal/src/androidMain/kotlin/dev/gitlive/firebase/internal/_decoders.kt index ae930a08a..83b71cad6 100644 --- a/firebase-common/src/androidMain/kotlin/dev/gitlive/firebase/_decoders.kt +++ b/firebase-common-internal/src/androidMain/kotlin/dev/gitlive/firebase/internal/_decoders.kt @@ -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 diff --git a/firebase-common/src/androidMain/kotlin/dev/gitlive/firebase/_encoders.kt b/firebase-common-internal/src/androidMain/kotlin/dev/gitlive/firebase/internal/_encoders.kt similarity index 91% rename from firebase-common/src/androidMain/kotlin/dev/gitlive/firebase/_encoders.kt rename to firebase-common-internal/src/androidMain/kotlin/dev/gitlive/firebase/internal/_encoders.kt index 6ade4a9e0..0a8ce569b 100644 --- a/firebase-common/src/androidMain/kotlin/dev/gitlive/firebase/_encoders.kt +++ b/firebase-common-internal/src/androidMain/kotlin/dev/gitlive/firebase/internal/_encoders.kt @@ -2,18 +2,14 @@ * 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 dev.gitlive.firebase.EncodedObject import kotlinx.serialization.descriptors.PolymorphicKind import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.descriptors.StructureKind -import java.lang.IllegalArgumentException import kotlin.collections.set -actual interface EncodedObject : Map { - actual val raw: Map -} - @PublishedApi internal data class EncodedObjectImpl internal constructor(override val raw: Map) : EncodedObject, Map by raw diff --git a/firebase-common-internal/src/commonMain/kotlin/dev/gitlive/firebase/internal/EncodeDecodeSettings.kt b/firebase-common-internal/src/commonMain/kotlin/dev/gitlive/firebase/internal/EncodeDecodeSettings.kt new file mode 100644 index 000000000..0a1fdda8f --- /dev/null +++ b/firebase-common-internal/src/commonMain/kotlin/dev/gitlive/firebase/internal/EncodeDecodeSettings.kt @@ -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) diff --git a/firebase-common/src/commonMain/kotlin/dev/gitlive/firebase/Polymorphic.kt b/firebase-common-internal/src/commonMain/kotlin/dev/gitlive/firebase/internal/Polymorphic.kt similarity index 96% rename from firebase-common/src/commonMain/kotlin/dev/gitlive/firebase/Polymorphic.kt rename to firebase-common-internal/src/commonMain/kotlin/dev/gitlive/firebase/internal/Polymorphic.kt index 41563d527..5998f26cb 100644 --- a/firebase-common/src/commonMain/kotlin/dev/gitlive/firebase/Polymorphic.kt +++ b/firebase-common-internal/src/commonMain/kotlin/dev/gitlive/firebase/internal/Polymorphic.kt @@ -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 diff --git a/firebase-common/src/commonMain/kotlin/dev/gitlive/firebase/decoders.kt b/firebase-common-internal/src/commonMain/kotlin/dev/gitlive/firebase/internal/decoders.kt similarity index 97% rename from firebase-common/src/commonMain/kotlin/dev/gitlive/firebase/decoders.kt rename to firebase-common-internal/src/commonMain/kotlin/dev/gitlive/firebase/internal/decoders.kt index 3822399d2..bdac459bd 100644 --- a/firebase-common/src/commonMain/kotlin/dev/gitlive/firebase/decoders.kt +++ b/firebase-common-internal/src/commonMain/kotlin/dev/gitlive/firebase/internal/decoders.kt @@ -2,8 +2,9 @@ * 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 dev.gitlive.firebase.DecodeSettings import kotlinx.serialization.DeserializationStrategy import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.SerializationException @@ -16,7 +17,7 @@ import kotlinx.serialization.serializer inline fun decode(value: Any?): T = decode(value) {} inline fun decode(value: Any?, buildSettings: DecodeSettings.Builder.() -> Unit): T = - decode(value, DecodeSettings.BuilderImpl().apply(buildSettings).buildDecodeSettings()) + decode(value, DecodeSettingsImpl.Builder().apply(buildSettings).buildDecodeSettings()) @PublishedApi internal inline fun decode(value: Any?, decodeSettings: DecodeSettings): T { @@ -25,7 +26,7 @@ internal inline fun decode(value: Any?, decodeSettings: DecodeSettin } fun decode(strategy: DeserializationStrategy, value: Any?): T = decode(strategy, value) {} inline fun decode(strategy: DeserializationStrategy, value: Any?, buildSettings: DecodeSettings.Builder.() -> Unit): T = - decode(strategy, value, DecodeSettings.BuilderImpl().apply(buildSettings).buildDecodeSettings()) + decode(strategy, value, DecodeSettingsImpl.Builder().apply(buildSettings).buildDecodeSettings()) @PublishedApi internal fun decode(strategy: DeserializationStrategy, value: Any?, decodeSettings: DecodeSettings): T { @@ -37,7 +38,7 @@ expect fun getPolymorphicType(value: Any?, discriminator: String): String class FirebaseDecoder(val value: Any?, internal val settings: DecodeSettings) : Decoder { - constructor(value: Any?) : this(value, DecodeSettings()) + constructor(value: Any?) : this(value, DecodeSettingsImpl()) override val serializersModule: SerializersModule = settings.serializersModule diff --git a/firebase-common/src/commonMain/kotlin/dev/gitlive/firebase/encoders.kt b/firebase-common-internal/src/commonMain/kotlin/dev/gitlive/firebase/internal/encoders.kt similarity index 93% rename from firebase-common/src/commonMain/kotlin/dev/gitlive/firebase/encoders.kt rename to firebase-common-internal/src/commonMain/kotlin/dev/gitlive/firebase/internal/encoders.kt index 54a3d4472..11a06bdaf 100644 --- a/firebase-common/src/commonMain/kotlin/dev/gitlive/firebase/encoders.kt +++ b/firebase-common-internal/src/commonMain/kotlin/dev/gitlive/firebase/internal/encoders.kt @@ -2,8 +2,10 @@ * 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 dev.gitlive.firebase.EncodeSettings +import dev.gitlive.firebase.EncodedObject import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.SerializationStrategy import kotlinx.serialization.descriptors.SerialDescriptor @@ -11,15 +13,6 @@ import kotlinx.serialization.encoding.CompositeEncoder import kotlinx.serialization.encoding.Encoder import kotlinx.serialization.modules.SerializersModule -/** - * 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. - * - * Created using [encodeAsObject]. It is not recommended to encode to this manually. - */ -expect interface EncodedObject { - val raw: Map -} @Deprecated("Deprecated. Use builder instead", replaceWith = ReplaceWith("encode(strategy, value) { encodeDefaults = shouldEncodeElementDefault }")) fun encode(strategy: SerializationStrategy, value: T, shouldEncodeElementDefault: Boolean): Any? = encode(strategy, value) { @@ -27,7 +20,7 @@ fun encode(strategy: SerializationStrategy, value: T, shouldEncodeElement } inline fun encode(strategy: SerializationStrategy, value: T, buildSettings: EncodeSettings.Builder.() -> Unit) = - encode(strategy, value, EncodeSettings.BuilderImpl().apply(buildSettings).buildEncodeSettings()) + encode(strategy, value, EncodeSettingsImpl.Builder().apply(buildSettings).buildEncodeSettings()) @PublishedApi internal inline fun encode(strategy: SerializationStrategy, value: T, encodeSettings: EncodeSettings): Any? = @@ -39,7 +32,7 @@ inline fun encode(value: T, shouldEncodeElementDefault: Boolean): An } inline fun encode(value: T, buildSettings: EncodeSettings.Builder.() -> Unit = {}) = - encode(value, EncodeSettings.BuilderImpl().apply(buildSettings).buildEncodeSettings()) + encode(value, EncodeSettingsImpl.Builder().apply(buildSettings).buildEncodeSettings()) /** * Encodes data as an [EncodedObject]. @@ -111,7 +104,7 @@ class FirebaseEncoder( ) : Encoder { constructor(shouldEncodeElementDefault: Boolean) : this( - EncodeSettings.BuilderImpl().apply { this.encodeDefaults = shouldEncodeElementDefault }.buildEncodeSettings() + EncodeSettingsImpl.Builder().apply { this.encodeDefaults = shouldEncodeElementDefault }.buildEncodeSettings() ) var value: Any? = null diff --git a/firebase-common/src/commonMain/kotlin/dev/gitlive/firebase/reencodeTransformation.kt b/firebase-common-internal/src/commonMain/kotlin/dev/gitlive/firebase/internal/reencodeTransformation.kt similarity index 90% rename from firebase-common/src/commonMain/kotlin/dev/gitlive/firebase/reencodeTransformation.kt rename to firebase-common-internal/src/commonMain/kotlin/dev/gitlive/firebase/internal/reencodeTransformation.kt index 7c9704157..f7e08d1a1 100644 --- a/firebase-common/src/commonMain/kotlin/dev/gitlive/firebase/reencodeTransformation.kt +++ b/firebase-common-internal/src/commonMain/kotlin/dev/gitlive/firebase/internal/reencodeTransformation.kt @@ -1,5 +1,6 @@ -package dev.gitlive.firebase +package dev.gitlive.firebase.internal +import dev.gitlive.firebase.EncodeDecodeSettingsBuilder import kotlinx.serialization.KSerializer inline fun reencodeTransformation(value: Any?, builder: EncodeDecodeSettingsBuilder.() -> Unit = {}, transform: (T) -> T): Any? { diff --git a/firebase-common/src/commonMain/kotlin/dev/gitlive/firebase/serializers.kt b/firebase-common-internal/src/commonMain/kotlin/dev/gitlive/firebase/internal/serializers.kt similarity index 99% rename from firebase-common/src/commonMain/kotlin/dev/gitlive/firebase/serializers.kt rename to firebase-common-internal/src/commonMain/kotlin/dev/gitlive/firebase/internal/serializers.kt index 68e9def69..2598bdfa6 100644 --- a/firebase-common/src/commonMain/kotlin/dev/gitlive/firebase/serializers.kt +++ b/firebase-common-internal/src/commonMain/kotlin/dev/gitlive/firebase/internal/serializers.kt @@ -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.KSerializer import kotlinx.serialization.SerializationException diff --git a/firebase-common/src/commonTest/kotlin/dev/gitlive/firebase/EncodersTest.kt b/firebase-common-internal/src/commonTest/kotlin/dev/gitlive/firebase/internal/EncodersTest.kt similarity index 93% rename from firebase-common/src/commonTest/kotlin/dev/gitlive/firebase/EncodersTest.kt rename to firebase-common-internal/src/commonTest/kotlin/dev/gitlive/firebase/internal/EncodersTest.kt index 3c3c7b420..124a431e4 100644 --- a/firebase-common/src/commonTest/kotlin/dev/gitlive/firebase/EncodersTest.kt +++ b/firebase-common-internal/src/commonTest/kotlin/dev/gitlive/firebase/internal/EncodersTest.kt @@ -2,8 +2,11 @@ * 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 dev.gitlive.firebase.nativeAssertEquals +import dev.gitlive.firebase.nativeListOf +import dev.gitlive.firebase.nativeMapOf import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import kotlinx.serialization.builtins.ListSerializer @@ -420,7 +423,10 @@ class EncodersTest { @Test fun encodeAsObject() { val testDataClass = TestData(mapOf("key" to "value"), mapOf(1 to 1), true, null, ValueClass(42)) - val encodedObject = encodeAsObject(TestData.serializer(), testDataClass) { encodeDefaults = false } + val encodedObject = encodeAsObject( + TestData.serializer(), + testDataClass + ) { encodeDefaults = false } nativeAssertEquals(mapOf("map" to nativeMapOf("key" to "value"), "otherMap" to nativeMapOf(1 to 1), "bool" to true, "valueClass" to 42), encodedObject.raw) @@ -429,17 +435,45 @@ class EncodersTest { assertEquals(emptyMap(), encodeAsObject(TestObject).raw) - assertFailsWith { encodeAsObject(true) } + assertFailsWith { + encodeAsObject( + true + ) + } assertFailsWith { encodeAsObject(42) } assertFailsWith { encodeAsObject(8.toShort()) } assertFailsWith { encodeAsObject(Int.MAX_VALUE.toLong() + 3) } - assertFailsWith { encodeAsObject(0x03F) } - assertFailsWith { encodeAsObject(3.33) } - assertFailsWith { encodeAsObject(6.65f) } + assertFailsWith { + encodeAsObject( + 0x03F + ) + } + assertFailsWith { + encodeAsObject( + 3.33 + ) + } + assertFailsWith { + encodeAsObject( + 6.65f + ) + } assertFailsWith { encodeAsObject("Test") } - assertFailsWith { encodeAsObject(ValueClass(2)) } - assertFailsWith { encodeAsObject(mapOf(1 to "one")) } - assertFailsWith { encodeAsObject(listOf("one")) } + assertFailsWith { + encodeAsObject( + ValueClass(2) + ) + } + assertFailsWith { + encodeAsObject( + mapOf(1 to "one") + ) + } + assertFailsWith { + encodeAsObject( + listOf("one") + ) + } } private inline fun assertEncode(value: T) { diff --git a/firebase-common/src/iosMain/kotlin/dev/gitlive/firebase/_decoders.kt b/firebase-common-internal/src/iosMain/kotlin/dev/gitlive/firebase/internal/_decoders.kt similarity index 97% rename from firebase-common/src/iosMain/kotlin/dev/gitlive/firebase/_decoders.kt rename to firebase-common-internal/src/iosMain/kotlin/dev/gitlive/firebase/internal/_decoders.kt index 43589a7a9..c479c5bd6 100644 --- a/firebase-common/src/iosMain/kotlin/dev/gitlive/firebase/_decoders.kt +++ b/firebase-common-internal/src/iosMain/kotlin/dev/gitlive/firebase/internal/_decoders.kt @@ -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.encoding.CompositeDecoder import kotlinx.serialization.descriptors.PolymorphicKind diff --git a/firebase-common/src/iosMain/kotlin/dev/gitlive/firebase/_encoders.kt b/firebase-common-internal/src/iosMain/kotlin/dev/gitlive/firebase/internal/_encoders.kt similarity index 94% rename from firebase-common/src/iosMain/kotlin/dev/gitlive/firebase/_encoders.kt rename to firebase-common-internal/src/iosMain/kotlin/dev/gitlive/firebase/internal/_encoders.kt index aaa584adb..72eac41d9 100644 --- a/firebase-common/src/iosMain/kotlin/dev/gitlive/firebase/_encoders.kt +++ b/firebase-common-internal/src/iosMain/kotlin/dev/gitlive/firebase/internal/_encoders.kt @@ -2,17 +2,14 @@ * 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 dev.gitlive.firebase.EncodedObject import kotlinx.serialization.descriptors.PolymorphicKind import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.descriptors.StructureKind import kotlin.collections.set -actual interface EncodedObject : Map { - actual val raw: Map -} - @PublishedApi internal data class InternalEncodedObject internal constructor( override val raw: Map diff --git a/firebase-common/src/jsMain/kotlin/dev/gitlive/firebase/_decoders.kt b/firebase-common-internal/src/jsMain/kotlin/dev/gitlive/firebase/internal/_decoders.kt similarity index 98% rename from firebase-common/src/jsMain/kotlin/dev/gitlive/firebase/_decoders.kt rename to firebase-common-internal/src/jsMain/kotlin/dev/gitlive/firebase/internal/_decoders.kt index a849dd190..167fc7f8e 100644 --- a/firebase-common/src/jsMain/kotlin/dev/gitlive/firebase/_decoders.kt +++ b/firebase-common-internal/src/jsMain/kotlin/dev/gitlive/firebase/internal/_decoders.kt @@ -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.PrimitiveKind diff --git a/firebase-common/src/jsMain/kotlin/dev/gitlive/firebase/_encoders.kt b/firebase-common-internal/src/jsMain/kotlin/dev/gitlive/firebase/internal/_encoders.kt similarity index 94% rename from firebase-common/src/jsMain/kotlin/dev/gitlive/firebase/_encoders.kt rename to firebase-common-internal/src/jsMain/kotlin/dev/gitlive/firebase/internal/_encoders.kt index b742128cf..0c8ea424c 100644 --- a/firebase-common/src/jsMain/kotlin/dev/gitlive/firebase/_encoders.kt +++ b/firebase-common-internal/src/jsMain/kotlin/dev/gitlive/firebase/internal/_encoders.kt @@ -2,21 +2,18 @@ * 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 dev.gitlive.firebase.EncodedObject import kotlinx.serialization.descriptors.PolymorphicKind import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.descriptors.StructureKind import kotlin.js.Json import kotlin.js.json -actual interface EncodedObject { - actual val raw: Map - val json: Json -} - @PublishedApi -internal class InternalEncodedObject internal constructor(override val raw: Map) : EncodedObject { +internal class InternalEncodedObject internal constructor(override val raw: Map) : + EncodedObject { override val json: Json get() = json(*raw.entries.map { (key, value) -> key to value }.toTypedArray()) } diff --git a/firebase-common/package.json b/firebase-common/package.json index e5826e53d..5723b5918 100644 --- a/firebase-common/package.json +++ b/firebase-common/package.json @@ -1,6 +1,6 @@ { "name": "@gitlive/firebase-common", - "version": "1.11.1", + "version": "1.12.0", "description": "Wrapper around firebase for usage in Kotlin Multiplatform projects", "main": "firebase-common.js", "scripts": { diff --git a/firebase-common/src/androidMain/kotlin/dev/gitlive/firebase/EncodedObject.kt b/firebase-common/src/androidMain/kotlin/dev/gitlive/firebase/EncodedObject.kt new file mode 100644 index 000000000..a176bcbeb --- /dev/null +++ b/firebase-common/src/androidMain/kotlin/dev/gitlive/firebase/EncodedObject.kt @@ -0,0 +1,9 @@ +/* + * Copyright (c) 2020 GitLive Ltd. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.gitlive.firebase + +actual interface EncodedObject : Map { + actual val raw: Map +} diff --git a/firebase-common/src/commonMain/kotlin/dev/gitlive/firebase/EncodeDecodeSettings.kt b/firebase-common/src/commonMain/kotlin/dev/gitlive/firebase/EncodeDecodeSettings.kt index 076f208dc..81b7690db 100644 --- a/firebase-common/src/commonMain/kotlin/dev/gitlive/firebase/EncodeDecodeSettings.kt +++ b/firebase-common/src/commonMain/kotlin/dev/gitlive/firebase/EncodeDecodeSettings.kt @@ -6,65 +6,38 @@ import kotlinx.serialization.modules.SerializersModule /** * Settings used to configure encoding/decoding */ -sealed class EncodeDecodeSettings { +sealed interface EncodeDecodeSettings { /** * The [SerializersModule] to use for serialization. This allows for polymorphic serialization on runtime */ - abstract val serializersModule: SerializersModule + val serializersModule: SerializersModule } /** * [EncodeDecodeSettings] used when encoding an object * @property encodeDefaults if `true` this will explicitly encode elements even if they are their default value - * @param serializersModule the [SerializersModule] to use for serialization. This allows for polymorphic serialization on runtime */ -data class EncodeSettings internal constructor( - val encodeDefaults: Boolean, - override val serializersModule: SerializersModule, -) : EncodeDecodeSettings() { +interface EncodeSettings : EncodeDecodeSettings { + + val encodeDefaults: Boolean interface Builder { var encodeDefaults: Boolean var serializersModule: SerializersModule } - - @PublishedApi - internal class BuilderImpl : Builder { - override var encodeDefaults: Boolean = true - override var serializersModule: SerializersModule = EmptySerializersModule() - } } /** * [EncodeDecodeSettings] used when decoding an object * @param serializersModule the [SerializersModule] to use for deserialization. This allows for polymorphic serialization on runtime */ -data class DecodeSettings internal constructor( - override val serializersModule: SerializersModule = EmptySerializersModule(), -) : EncodeDecodeSettings() { +interface DecodeSettings : EncodeDecodeSettings { interface Builder { var serializersModule: SerializersModule } - - @PublishedApi - internal class BuilderImpl : Builder { - override var serializersModule: SerializersModule = EmptySerializersModule() - } } interface EncodeDecodeSettingsBuilder : EncodeSettings.Builder, DecodeSettings.Builder - -@PublishedApi -internal class EncodeDecodeSettingsBuilderImpl : EncodeDecodeSettingsBuilder { - - override var encodeDefaults: Boolean = true - override var serializersModule: SerializersModule = EmptySerializersModule() -} - -@PublishedApi -internal fun EncodeSettings.Builder.buildEncodeSettings(): EncodeSettings = EncodeSettings(encodeDefaults, serializersModule) -@PublishedApi -internal fun DecodeSettings.Builder.buildDecodeSettings(): DecodeSettings = DecodeSettings(serializersModule) diff --git a/firebase-common/src/commonMain/kotlin/dev/gitlive/firebase/EncodedObject.kt b/firebase-common/src/commonMain/kotlin/dev/gitlive/firebase/EncodedObject.kt new file mode 100644 index 000000000..1e773d16e --- /dev/null +++ b/firebase-common/src/commonMain/kotlin/dev/gitlive/firebase/EncodedObject.kt @@ -0,0 +1,13 @@ +/* + * Copyright (c) 2020 GitLive Ltd. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.gitlive.firebase + +/** + * 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. + */ +expect interface EncodedObject { + val raw: Map +} diff --git a/firebase-common/src/iosMain/kotlin/dev/gitlive/firebase/EncodedObject.kt b/firebase-common/src/iosMain/kotlin/dev/gitlive/firebase/EncodedObject.kt new file mode 100644 index 000000000..6fa97683a --- /dev/null +++ b/firebase-common/src/iosMain/kotlin/dev/gitlive/firebase/EncodedObject.kt @@ -0,0 +1,9 @@ +/* + * Copyright (c) 2020 GitLive Ltd. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.gitlive.firebase + +actual interface EncodedObject : Map { + actual val raw: Map +} diff --git a/firebase-common/src/jsMain/kotlin/dev/gitlive/firebase/EncodedObject.kt b/firebase-common/src/jsMain/kotlin/dev/gitlive/firebase/EncodedObject.kt new file mode 100644 index 000000000..864deebf3 --- /dev/null +++ b/firebase-common/src/jsMain/kotlin/dev/gitlive/firebase/EncodedObject.kt @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2020 GitLive Ltd. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.gitlive.firebase + +import kotlin.js.Json + +actual interface EncodedObject { + actual val raw: Map + val json: Json +} diff --git a/firebase-config/package.json b/firebase-config/package.json index 454740a67..e6c4057d0 100644 --- a/firebase-config/package.json +++ b/firebase-config/package.json @@ -1,6 +1,6 @@ { "name": "@gitlive/firebase-config", - "version": "1.11.1", + "version": "1.12.0", "description": "Wrapper around firebase for usage in Kotlin Multiplatform projects", "main": "firebase-config.js", "scripts": { @@ -23,7 +23,7 @@ }, "homepage": "https://github.com/GitLiveApp/firebase-kotlin-sdk", "dependencies": { - "@gitlive/firebase-app": "1.11.1", + "@gitlive/firebase-app": "1.12.0", "firebase": "9.19.1", "kotlin": "1.8.20", "kotlinx-coroutines-core": "1.6.4" diff --git a/firebase-crashlytics/package.json b/firebase-crashlytics/package.json index 8b0981a1a..435166e4f 100644 --- a/firebase-crashlytics/package.json +++ b/firebase-crashlytics/package.json @@ -23,7 +23,7 @@ }, "homepage": "https://github.com/GitLiveApp/firebase-kotlin-sdk", "dependencies": { - "@gitlive/firebase-app": "1.11.1", + "@gitlive/firebase-app": "1.12.0", "firebase": "9.19.1", "kotlin": "1.6.10", "kotlinx-coroutines-core": "1.6.1-native-mt" diff --git a/firebase-database/build.gradle.kts b/firebase-database/build.gradle.kts index 1b92b443c..fbcb06c43 100644 --- a/firebase-database/build.gradle.kts +++ b/firebase-database/build.gradle.kts @@ -143,7 +143,8 @@ kotlin { getByName("commonMain") { dependencies { api(project(":firebase-app")) - implementation(project(":firebase-common")) + api(project(":firebase-common")) + implementation(project(":firebase-common-internal")) } } diff --git a/firebase-database/package.json b/firebase-database/package.json index 090086c4a..a2910b27a 100644 --- a/firebase-database/package.json +++ b/firebase-database/package.json @@ -1,6 +1,6 @@ { "name": "@gitlive/firebase-database", - "version": "1.11.1", + "version": "1.12.0", "description": "Wrapper around firebase for usage in Kotlin Multiplatform projects", "main": "firebase-database.js", "scripts": { @@ -23,7 +23,7 @@ }, "homepage": "https://github.com/GitLiveApp/firebase-kotlin-sdk", "dependencies": { - "@gitlive/firebase-app": "1.11.1", + "@gitlive/firebase-app": "1.12.0", "firebase": "9.19.1", "kotlin": "1.8.20", "kotlinx-coroutines-core": "1.6.4" diff --git a/firebase-database/src/androidMain/kotlin/dev/gitlive/firebase/database/database.kt b/firebase-database/src/androidMain/kotlin/dev/gitlive/firebase/database/database.kt index 98b3b5a99..f5949e386 100644 --- a/firebase-database/src/androidMain/kotlin/dev/gitlive/firebase/database/database.kt +++ b/firebase-database/src/androidMain/kotlin/dev/gitlive/firebase/database/database.kt @@ -18,8 +18,8 @@ import dev.gitlive.firebase.Firebase import dev.gitlive.firebase.FirebaseApp import dev.gitlive.firebase.database.ChildEvent.Type import dev.gitlive.firebase.database.FirebaseDatabase.Companion.FirebaseDatabase -import dev.gitlive.firebase.decode -import dev.gitlive.firebase.reencodeTransformation +import dev.gitlive.firebase.internal.decode +import dev.gitlive.firebase.internal.reencodeTransformation import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.channels.trySendBlocking diff --git a/firebase-database/src/commonMain/kotlin/dev/gitlive/firebase/database/ServerValue.kt b/firebase-database/src/commonMain/kotlin/dev/gitlive/firebase/database/ServerValue.kt index c93ba746a..b9a31cdf4 100644 --- a/firebase-database/src/commonMain/kotlin/dev/gitlive/firebase/database/ServerValue.kt +++ b/firebase-database/src/commonMain/kotlin/dev/gitlive/firebase/database/ServerValue.kt @@ -1,8 +1,8 @@ package dev.gitlive.firebase.database -import dev.gitlive.firebase.FirebaseDecoder -import dev.gitlive.firebase.FirebaseEncoder -import dev.gitlive.firebase.SpecialValueSerializer +import dev.gitlive.firebase.internal.FirebaseDecoder +import dev.gitlive.firebase.internal.FirebaseEncoder +import dev.gitlive.firebase.internal.SpecialValueSerializer import kotlinx.serialization.KSerializer import kotlinx.serialization.Serializable import kotlinx.serialization.SerializationException diff --git a/firebase-database/src/commonMain/kotlin/dev/gitlive/firebase/database/database.kt b/firebase-database/src/commonMain/kotlin/dev/gitlive/firebase/database/database.kt index 7d46135d0..631197f2e 100644 --- a/firebase-database/src/commonMain/kotlin/dev/gitlive/firebase/database/database.kt +++ b/firebase-database/src/commonMain/kotlin/dev/gitlive/firebase/database/database.kt @@ -14,8 +14,8 @@ import dev.gitlive.firebase.database.ChildEvent.Type.ADDED import dev.gitlive.firebase.database.ChildEvent.Type.CHANGED import dev.gitlive.firebase.database.ChildEvent.Type.MOVED import dev.gitlive.firebase.database.ChildEvent.Type.REMOVED -import dev.gitlive.firebase.encode -import dev.gitlive.firebase.encodeAsObject +import dev.gitlive.firebase.internal.encode +import dev.gitlive.firebase.internal.encodeAsObject import kotlinx.coroutines.flow.Flow import kotlinx.serialization.DeserializationStrategy import kotlinx.serialization.KSerializer diff --git a/firebase-database/src/iosMain/kotlin/dev/gitlive/firebase/database/database.kt b/firebase-database/src/iosMain/kotlin/dev/gitlive/firebase/database/database.kt index 64f551dc0..1783c7432 100644 --- a/firebase-database/src/iosMain/kotlin/dev/gitlive/firebase/database/database.kt +++ b/firebase-database/src/iosMain/kotlin/dev/gitlive/firebase/database/database.kt @@ -24,8 +24,8 @@ import dev.gitlive.firebase.database.ChildEvent.Type.ADDED import dev.gitlive.firebase.database.ChildEvent.Type.CHANGED import dev.gitlive.firebase.database.ChildEvent.Type.MOVED import dev.gitlive.firebase.database.ChildEvent.Type.REMOVED -import dev.gitlive.firebase.decode -import dev.gitlive.firebase.reencodeTransformation +import dev.gitlive.firebase.internal.decode +import dev.gitlive.firebase.internal.reencodeTransformation import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.FlowPreview import kotlinx.coroutines.channels.awaitClose diff --git a/firebase-database/src/jsMain/kotlin/dev/gitlive/firebase/database/database.kt b/firebase-database/src/jsMain/kotlin/dev/gitlive/firebase/database/database.kt index ba3e720b2..725b8c4bd 100644 --- a/firebase-database/src/jsMain/kotlin/dev/gitlive/firebase/database/database.kt +++ b/firebase-database/src/jsMain/kotlin/dev/gitlive/firebase/database/database.kt @@ -28,8 +28,8 @@ import dev.gitlive.firebase.database.externals.ref import dev.gitlive.firebase.database.externals.remove import dev.gitlive.firebase.database.externals.set import dev.gitlive.firebase.database.externals.update -import dev.gitlive.firebase.decode -import dev.gitlive.firebase.reencodeTransformation +import dev.gitlive.firebase.internal.decode +import dev.gitlive.firebase.internal.reencodeTransformation import kotlinx.coroutines.asDeferred import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.coroutineScope diff --git a/firebase-database/src/jsMain/kotlin/dev/gitlive/firebase/database/externals/database.kt b/firebase-database/src/jsMain/kotlin/dev/gitlive/firebase/database/externals/database.kt index 52f71422b..b9390b21b 100644 --- a/firebase-database/src/jsMain/kotlin/dev/gitlive/firebase/database/externals/database.kt +++ b/firebase-database/src/jsMain/kotlin/dev/gitlive/firebase/database/externals/database.kt @@ -3,7 +3,7 @@ package dev.gitlive.firebase.database.externals -import dev.gitlive.firebase.* +import dev.gitlive.firebase.Unsubscribe import dev.gitlive.firebase.externals.FirebaseApp import kotlin.js.Promise diff --git a/firebase-database/src/jvmTest/kotlin/dev/gitlive/firebase/database/database.kt b/firebase-database/src/jvmTest/kotlin/dev/gitlive/firebase/database/database.kt index 27668d277..1ddad5625 100644 --- a/firebase-database/src/jvmTest/kotlin/dev/gitlive/firebase/database/database.kt +++ b/firebase-database/src/jvmTest/kotlin/dev/gitlive/firebase/database/database.kt @@ -5,7 +5,6 @@ @file:JvmName("tests") package dev.gitlive.firebase.database - actual val emulatorHost: String = "10.0.2.2" actual val context: Any = Unit diff --git a/firebase-firestore/build.gradle.kts b/firebase-firestore/build.gradle.kts index b6cf58b99..4e861b3d0 100644 --- a/firebase-firestore/build.gradle.kts +++ b/firebase-firestore/build.gradle.kts @@ -156,7 +156,8 @@ kotlin { getByName("commonMain") { dependencies { api(project(":firebase-app")) - implementation(project(":firebase-common")) + api(project(":firebase-common")) + implementation(project(":firebase-common-internal")) } } diff --git a/firebase-firestore/package.json b/firebase-firestore/package.json index eed05cf10..1a5e44bd0 100644 --- a/firebase-firestore/package.json +++ b/firebase-firestore/package.json @@ -1,6 +1,6 @@ { "name": "@gitlive/firebase-firestore", - "version": "1.11.1", + "version": "1.12.0", "description": "Wrapper around firebase for usage in Kotlin Multiplatform projects", "main": "firebase-firestore.js", "scripts": { @@ -23,7 +23,7 @@ }, "homepage": "https://github.com/GitLiveApp/firebase-kotlin-sdk", "dependencies": { - "@gitlive/firebase-app": "1.11.1", + "@gitlive/firebase-app": "1.12.0", "firebase": "9.19.1", "kotlin": "1.8.20", "kotlinx-coroutines-core": "1.6.4" diff --git a/firebase-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore/DocumentReferenceSerializer.kt b/firebase-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore/DocumentReferenceSerializer.kt index 0f2f8fe30..79951b4a3 100644 --- a/firebase-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore/DocumentReferenceSerializer.kt +++ b/firebase-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore/DocumentReferenceSerializer.kt @@ -1,7 +1,7 @@ package dev.gitlive.firebase.firestore -import dev.gitlive.firebase.FirebaseEncoder -import dev.gitlive.firebase.SpecialValueSerializer +import dev.gitlive.firebase.internal.FirebaseEncoder +import dev.gitlive.firebase.internal.SpecialValueSerializer import kotlinx.serialization.KSerializer import kotlinx.serialization.SerializationException diff --git a/firebase-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore/FieldValueSerializer.kt b/firebase-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore/FieldValueSerializer.kt index 2dc95492f..5b53d2f95 100644 --- a/firebase-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore/FieldValueSerializer.kt +++ b/firebase-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore/FieldValueSerializer.kt @@ -1,7 +1,7 @@ package dev.gitlive.firebase.firestore -import dev.gitlive.firebase.FirebaseEncoder -import dev.gitlive.firebase.SpecialValueSerializer +import dev.gitlive.firebase.internal.FirebaseEncoder +import dev.gitlive.firebase.internal.SpecialValueSerializer import kotlinx.serialization.KSerializer import kotlinx.serialization.SerializationException diff --git a/firebase-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore/GeoPointSerializer.kt b/firebase-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore/GeoPointSerializer.kt index 221456628..e96308cee 100644 --- a/firebase-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore/GeoPointSerializer.kt +++ b/firebase-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore/GeoPointSerializer.kt @@ -1,6 +1,6 @@ package dev.gitlive.firebase.firestore -import dev.gitlive.firebase.SpecialValueSerializer +import dev.gitlive.firebase.internal.SpecialValueSerializer import kotlinx.serialization.KSerializer import kotlinx.serialization.SerializationException diff --git a/firebase-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore/TimestampSerializer.kt b/firebase-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore/TimestampSerializer.kt index 92fe32f17..4d126d277 100644 --- a/firebase-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore/TimestampSerializer.kt +++ b/firebase-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore/TimestampSerializer.kt @@ -1,7 +1,6 @@ package dev.gitlive.firebase.firestore -import dev.gitlive.firebase.SpecialValueSerializer -import dev.gitlive.firebase.firestore.* +import dev.gitlive.firebase.internal.SpecialValueSerializer import dev.gitlive.firebase.firestore.DoubleAsTimestampSerializer.serverTimestamp import kotlinx.serialization.KSerializer import kotlinx.serialization.SerializationException diff --git a/firebase-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore/encoders.kt b/firebase-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore/encoders.kt index 04a3f32cf..b5f1960dd 100644 --- a/firebase-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore/encoders.kt +++ b/firebase-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore/encoders.kt @@ -11,5 +11,5 @@ internal inline fun encode(value: T, buildSettings: EncodeSettings.B if (value?.let(::isSpecialValue) == true) { value } else { - dev.gitlive.firebase.encode(value, buildSettings) + dev.gitlive.firebase.internal.encode(value, buildSettings) } diff --git a/firebase-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore/firestore.kt b/firebase-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore/firestore.kt index 0aaf75146..0f1935672 100644 --- a/firebase-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore/firestore.kt +++ b/firebase-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore/firestore.kt @@ -4,7 +4,14 @@ package dev.gitlive.firebase.firestore -import dev.gitlive.firebase.* +import dev.gitlive.firebase.DecodeSettings +import dev.gitlive.firebase.EncodeSettings +import dev.gitlive.firebase.EncodedObject +import dev.gitlive.firebase.Firebase +import dev.gitlive.firebase.FirebaseApp +import dev.gitlive.firebase.FirebaseException +import dev.gitlive.firebase.internal.decode +import dev.gitlive.firebase.internal.encodeAsObject import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.map import kotlinx.serialization.DeserializationStrategy diff --git a/firebase-firestore/src/commonTest/kotlin/dev/gitlive/firebase/firestore/FieldValueTests.kt b/firebase-firestore/src/commonTest/kotlin/dev/gitlive/firebase/firestore/FieldValueTests.kt index ad4b5374b..96c5350e8 100644 --- a/firebase-firestore/src/commonTest/kotlin/dev/gitlive/firebase/firestore/FieldValueTests.kt +++ b/firebase-firestore/src/commonTest/kotlin/dev/gitlive/firebase/firestore/FieldValueTests.kt @@ -1,6 +1,6 @@ package dev.gitlive.firebase.firestore -import dev.gitlive.firebase.firebaseSerializer +import dev.gitlive.firebase.internal.firebaseSerializer import dev.gitlive.firebase.runTest import kotlin.test.Test import kotlin.test.assertEquals diff --git a/firebase-firestore/src/commonTest/kotlin/dev/gitlive/firebase/firestore/GeoPointTests.kt b/firebase-firestore/src/commonTest/kotlin/dev/gitlive/firebase/firestore/GeoPointTests.kt index 216621064..b97eb8378 100644 --- a/firebase-firestore/src/commonTest/kotlin/dev/gitlive/firebase/firestore/GeoPointTests.kt +++ b/firebase-firestore/src/commonTest/kotlin/dev/gitlive/firebase/firestore/GeoPointTests.kt @@ -1,6 +1,8 @@ package dev.gitlive.firebase.firestore -import dev.gitlive.firebase.* +import dev.gitlive.firebase.internal.decode +import dev.gitlive.firebase.internal.firebaseSerializer +import dev.gitlive.firebase.runTest import kotlinx.serialization.Serializable import kotlin.test.Test import kotlin.test.assertEquals diff --git a/firebase-firestore/src/commonTest/kotlin/dev/gitlive/firebase/firestore/TimestampTests.kt b/firebase-firestore/src/commonTest/kotlin/dev/gitlive/firebase/firestore/TimestampTests.kt index 8c2541ba9..625a3f68c 100644 --- a/firebase-firestore/src/commonTest/kotlin/dev/gitlive/firebase/firestore/TimestampTests.kt +++ b/firebase-firestore/src/commonTest/kotlin/dev/gitlive/firebase/firestore/TimestampTests.kt @@ -1,8 +1,8 @@ package dev.gitlive.firebase.firestore -import dev.gitlive.firebase.decode -import dev.gitlive.firebase.encode -import dev.gitlive.firebase.firebaseSerializer +import dev.gitlive.firebase.internal.decode +import dev.gitlive.firebase.internal.encode +import dev.gitlive.firebase.internal.firebaseSerializer import dev.gitlive.firebase.nativeAssertEquals import dev.gitlive.firebase.nativeMapOf import dev.gitlive.firebase.runTest diff --git a/firebase-firestore/src/commonTest/kotlin/dev/gitlive/firebase/firestore/firestore.kt b/firebase-firestore/src/commonTest/kotlin/dev/gitlive/firebase/firestore/firestore.kt index f04c93853..facdfb006 100644 --- a/firebase-firestore/src/commonTest/kotlin/dev/gitlive/firebase/firestore/firestore.kt +++ b/firebase-firestore/src/commonTest/kotlin/dev/gitlive/firebase/firestore/firestore.kt @@ -7,11 +7,11 @@ package dev.gitlive.firebase.firestore import dev.gitlive.firebase.Firebase import dev.gitlive.firebase.FirebaseOptions import dev.gitlive.firebase.apps -import dev.gitlive.firebase.decode +import dev.gitlive.firebase.internal.decode import dev.gitlive.firebase.initialize import dev.gitlive.firebase.runBlockingTest import dev.gitlive.firebase.runTest -import dev.gitlive.firebase.withSerializer +import dev.gitlive.firebase.internal.withSerializer import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.async import kotlinx.coroutines.delay diff --git a/firebase-firestore/src/iosMain/kotlin/dev/gitlive/firebase/firestore/GeoPoint.kt b/firebase-firestore/src/iosMain/kotlin/dev/gitlive/firebase/firestore/GeoPoint.kt index 7e54257da..409760667 100644 --- a/firebase-firestore/src/iosMain/kotlin/dev/gitlive/firebase/firestore/GeoPoint.kt +++ b/firebase-firestore/src/iosMain/kotlin/dev/gitlive/firebase/firestore/GeoPoint.kt @@ -3,7 +3,6 @@ package dev.gitlive.firebase.firestore import cocoapods.FirebaseFirestoreInternal.FIRGeoPoint import kotlinx.serialization.Serializable - /** A class representing a platform specific Firebase GeoPoint. */ actual typealias NativeGeoPoint = FIRGeoPoint diff --git a/firebase-firestore/src/iosMain/kotlin/dev/gitlive/firebase/firestore/firestore.kt b/firebase-firestore/src/iosMain/kotlin/dev/gitlive/firebase/firestore/firestore.kt index 17f021f6a..6a391825c 100644 --- a/firebase-firestore/src/iosMain/kotlin/dev/gitlive/firebase/firestore/firestore.kt +++ b/firebase-firestore/src/iosMain/kotlin/dev/gitlive/firebase/firestore/firestore.kt @@ -6,7 +6,10 @@ package dev.gitlive.firebase.firestore import cocoapods.FirebaseFirestoreInternal.* import cocoapods.FirebaseFirestoreInternal.FIRDocumentChangeType.* -import dev.gitlive.firebase.* +import dev.gitlive.firebase.EncodedObject +import dev.gitlive.firebase.Firebase +import dev.gitlive.firebase.FirebaseApp +import dev.gitlive.firebase.FirebaseException import kotlinx.cinterop.* import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.channels.awaitClose diff --git a/firebase-firestore/src/iosTest/kotlin/dev/gitlive/firebase/firestore/ContextSwitchTest.kt b/firebase-firestore/src/iosTest/kotlin/dev/gitlive/firebase/firestore/ContextSwitchTest.kt index ac4e668eb..d59d4980a 100644 --- a/firebase-firestore/src/iosTest/kotlin/dev/gitlive/firebase/firestore/ContextSwitchTest.kt +++ b/firebase-firestore/src/iosTest/kotlin/dev/gitlive/firebase/firestore/ContextSwitchTest.kt @@ -1,6 +1,10 @@ package dev.gitlive.firebase.firestore -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 kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.MainScope import kotlinx.coroutines.async @@ -22,7 +26,6 @@ import kotlin.test.BeforeTest import kotlin.test.Test import kotlin.test.assertEquals - private val backgroundContext = newSingleThreadContext("background") /** * This function performs is intended to test object sharing across several threads. diff --git a/firebase-functions/build.gradle.kts b/firebase-functions/build.gradle.kts index 0e30f2e50..e164aee90 100644 --- a/firebase-functions/build.gradle.kts +++ b/firebase-functions/build.gradle.kts @@ -132,7 +132,8 @@ kotlin { getByName("commonMain") { dependencies { api(project(":firebase-app")) - implementation(project(":firebase-common")) + api(project(":firebase-common")) + implementation(project(":firebase-common-internal")) } } diff --git a/firebase-functions/package.json b/firebase-functions/package.json index 0e5277af7..585e2773f 100644 --- a/firebase-functions/package.json +++ b/firebase-functions/package.json @@ -1,6 +1,6 @@ { "name": "@gitlive/firebase-functions", - "version": "1.11.1", + "version": "1.12.0", "description": "Wrapper around firebase for usage in Kotlin Multiplatform projects", "main": "firebase-functions.js", "scripts": { @@ -23,7 +23,7 @@ }, "homepage": "https://github.com/GitLiveApp/firebase-kotlin-sdk", "dependencies": { - "@gitlive/firebase-app": "1.11.1", + "@gitlive/firebase-app": "1.12.0", "firebase": "9.19.1", "kotlin": "1.8.20", "kotlinx-coroutines-core": "1.6.4" diff --git a/firebase-functions/src/androidMain/kotlin/dev/gitlive/firebase/functions/functions.kt b/firebase-functions/src/androidMain/kotlin/dev/gitlive/firebase/functions/functions.kt index d93f743ec..e4a72b95d 100644 --- a/firebase-functions/src/androidMain/kotlin/dev/gitlive/firebase/functions/functions.kt +++ b/firebase-functions/src/androidMain/kotlin/dev/gitlive/firebase/functions/functions.kt @@ -7,7 +7,7 @@ package dev.gitlive.firebase.functions import dev.gitlive.firebase.DecodeSettings import dev.gitlive.firebase.Firebase import dev.gitlive.firebase.FirebaseApp -import dev.gitlive.firebase.decode +import dev.gitlive.firebase.internal.decode import kotlinx.coroutines.tasks.await import kotlinx.serialization.DeserializationStrategy import java.util.concurrent.TimeUnit diff --git a/firebase-functions/src/commonMain/kotlin/dev/gitlive/firebase/functions/functions.kt b/firebase-functions/src/commonMain/kotlin/dev/gitlive/firebase/functions/functions.kt index 9a152a430..24a999463 100644 --- a/firebase-functions/src/commonMain/kotlin/dev/gitlive/firebase/functions/functions.kt +++ b/firebase-functions/src/commonMain/kotlin/dev/gitlive/firebase/functions/functions.kt @@ -4,7 +4,12 @@ package dev.gitlive.firebase.functions -import dev.gitlive.firebase.* +import dev.gitlive.firebase.DecodeSettings +import dev.gitlive.firebase.EncodeSettings +import dev.gitlive.firebase.Firebase +import dev.gitlive.firebase.FirebaseApp +import dev.gitlive.firebase.FirebaseException +import dev.gitlive.firebase.internal.encode import kotlinx.serialization.DeserializationStrategy import kotlinx.serialization.SerializationStrategy diff --git a/firebase-functions/src/iosMain/kotlin/dev/gitlive/firebase/functions/functions.kt b/firebase-functions/src/iosMain/kotlin/dev/gitlive/firebase/functions/functions.kt index 907508278..04e0b608a 100644 --- a/firebase-functions/src/iosMain/kotlin/dev/gitlive/firebase/functions/functions.kt +++ b/firebase-functions/src/iosMain/kotlin/dev/gitlive/firebase/functions/functions.kt @@ -7,10 +7,13 @@ package dev.gitlive.firebase.functions import cocoapods.FirebaseFunctions.FIRFunctions import cocoapods.FirebaseFunctions.FIRHTTPSCallable import cocoapods.FirebaseFunctions.FIRHTTPSCallableResult -import dev.gitlive.firebase.* +import dev.gitlive.firebase.DecodeSettings +import dev.gitlive.firebase.Firebase +import dev.gitlive.firebase.FirebaseApp +import dev.gitlive.firebase.FirebaseException +import dev.gitlive.firebase.internal.decode import kotlinx.coroutines.CompletableDeferred import kotlinx.serialization.DeserializationStrategy -import kotlinx.serialization.SerializationStrategy import platform.Foundation.NSError actual val Firebase.functions diff --git a/firebase-functions/src/jsMain/kotlin/dev/gitlive/firebase/functions/functions.kt b/firebase-functions/src/jsMain/kotlin/dev/gitlive/firebase/functions/functions.kt index b8b9b7bee..cc6f8f100 100644 --- a/firebase-functions/src/jsMain/kotlin/dev/gitlive/firebase/functions/functions.kt +++ b/firebase-functions/src/jsMain/kotlin/dev/gitlive/firebase/functions/functions.kt @@ -4,11 +4,19 @@ package dev.gitlive.firebase.functions -import dev.gitlive.firebase.* -import dev.gitlive.firebase.functions.externals.* +import dev.gitlive.firebase.DecodeSettings +import dev.gitlive.firebase.Firebase +import dev.gitlive.firebase.FirebaseApp +import dev.gitlive.firebase.FirebaseException +import dev.gitlive.firebase.functions.externals.Functions +import dev.gitlive.firebase.functions.externals.HttpsCallable +import dev.gitlive.firebase.functions.externals.connectFunctionsEmulator +import dev.gitlive.firebase.functions.externals.getFunctions +import dev.gitlive.firebase.functions.externals.httpsCallable +import dev.gitlive.firebase.functions.externals.invoke +import dev.gitlive.firebase.internal.decode import kotlinx.coroutines.await import kotlinx.serialization.DeserializationStrategy -import kotlinx.serialization.SerializationStrategy import kotlin.js.json import dev.gitlive.firebase.functions.externals.HttpsCallableResult as JsHttpsCallableResult diff --git a/firebase-installations/package.json b/firebase-installations/package.json index ab86a6f71..d4b77bb64 100644 --- a/firebase-installations/package.json +++ b/firebase-installations/package.json @@ -23,7 +23,7 @@ }, "homepage": "https://github.com/GitLiveApp/firebase-kotlin-sdk", "dependencies": { - "@gitlive/firebase-app": "1.11.1", + "@gitlive/firebase-app": "1.12.0", "firebase": "9.19.1", "kotlin": "1.8.20", "kotlinx-coroutines-core": "1.6.4" diff --git a/firebase-installations/src/jsMain/kotlin/dev/gitlive/firebase/installations/installations.kt b/firebase-installations/src/jsMain/kotlin/dev/gitlive/firebase/installations/installations.kt index 7329c3626..b1ddce4e0 100644 --- a/firebase-installations/src/jsMain/kotlin/dev/gitlive/firebase/installations/installations.kt +++ b/firebase-installations/src/jsMain/kotlin/dev/gitlive/firebase/installations/installations.kt @@ -1,6 +1,8 @@ package dev.gitlive.firebase.installations -import dev.gitlive.firebase.* +import dev.gitlive.firebase.Firebase +import dev.gitlive.firebase.FirebaseApp +import dev.gitlive.firebase.FirebaseException import dev.gitlive.firebase.installations.externals.* import kotlinx.coroutines.await diff --git a/firebase-perf/package.json b/firebase-perf/package.json index f454d775c..c51f39a2c 100644 --- a/firebase-perf/package.json +++ b/firebase-perf/package.json @@ -23,7 +23,7 @@ }, "homepage": "https://github.com/GitLiveApp/firebase-kotlin-sdk", "dependencies": { - "@gitlive/firebase-app": "1.11.1", + "@gitlive/firebase-app": "1.12.0", "firebase": "9.19.1", "kotlin": "1.6.10", "kotlinx-coroutines-core": "1.6.1-native-mt" diff --git a/firebase-perf/src/androidInstrumentedTest/kotlin/dev/gitlive/firebase/perf/metrics/Trace.kt b/firebase-perf/src/androidInstrumentedTest/kotlin/dev/gitlive/firebase/perf/metrics/Trace.kt index 6768f9247..894b90f25 100644 --- a/firebase-perf/src/androidInstrumentedTest/kotlin/dev/gitlive/firebase/perf/metrics/Trace.kt +++ b/firebase-perf/src/androidInstrumentedTest/kotlin/dev/gitlive/firebase/perf/metrics/Trace.kt @@ -1,6 +1,9 @@ package dev.gitlive.firebase.perf.metrics -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.perf.FirebasePerformance import dev.gitlive.firebase.perf.context import dev.gitlive.firebase.perf.performance diff --git a/firebase-perf/src/commonTest/kotlin/dev/gitlive/firebase/perf/metrics/Trace.kt b/firebase-perf/src/commonTest/kotlin/dev/gitlive/firebase/perf/metrics/Trace.kt index 65ccafb65..252bf751f 100644 --- a/firebase-perf/src/commonTest/kotlin/dev/gitlive/firebase/perf/metrics/Trace.kt +++ b/firebase-perf/src/commonTest/kotlin/dev/gitlive/firebase/perf/metrics/Trace.kt @@ -1,6 +1,9 @@ package dev.gitlive.firebase.perf.metrics -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.perf.FirebasePerformance import dev.gitlive.firebase.perf.IgnoreForAndroidUnitTest import dev.gitlive.firebase.perf.context diff --git a/firebase-perf/src/commonTest/kotlin/dev/gitlive/firebase/perf/performance.kt b/firebase-perf/src/commonTest/kotlin/dev/gitlive/firebase/perf/performance.kt index fae090c5c..6ca689abc 100644 --- a/firebase-perf/src/commonTest/kotlin/dev/gitlive/firebase/perf/performance.kt +++ b/firebase-perf/src/commonTest/kotlin/dev/gitlive/firebase/perf/performance.kt @@ -4,10 +4,13 @@ package dev.gitlive.firebase.perf -import dev.gitlive.firebase.* -import kotlinx.coroutines.CoroutineScope +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 kotlinx.coroutines.delay -import kotlinx.coroutines.test.TestResult import kotlin.test.* import kotlin.time.Duration.Companion.seconds diff --git a/firebase-perf/src/jsTest/kotlin/dev/gitlive/firebase/perf/metrics/Trace.kt b/firebase-perf/src/jsTest/kotlin/dev/gitlive/firebase/perf/metrics/Trace.kt index c732a4a82..0b7499ed0 100644 --- a/firebase-perf/src/jsTest/kotlin/dev/gitlive/firebase/perf/metrics/Trace.kt +++ b/firebase-perf/src/jsTest/kotlin/dev/gitlive/firebase/perf/metrics/Trace.kt @@ -1,10 +1,14 @@ package dev.gitlive.firebase.perf.metrics -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.perf.FirebasePerformance import dev.gitlive.firebase.perf.context import dev.gitlive.firebase.perf.performance import dev.gitlive.firebase.runBlockingTest +import dev.gitlive.firebase.runTest import kotlin.test.AfterTest import kotlin.test.BeforeTest import kotlin.test.Test diff --git a/firebase-storage/package.json b/firebase-storage/package.json index 67f721da8..db6ab752b 100644 --- a/firebase-storage/package.json +++ b/firebase-storage/package.json @@ -23,7 +23,7 @@ }, "homepage": "https://github.com/GitLiveApp/firebase-kotlin-sdk", "dependencies": { - "@gitlive/firebase-app": "1.11.1", + "@gitlive/firebase-app": "1.12.0", "firebase": "9.19.1", "kotlin": "1.6.10", "kotlinx-coroutines-core": "1.6.1-native-mt" diff --git a/gradle.properties b/gradle.properties index 3fb471e2b..e8d09666a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -25,6 +25,7 @@ firebase-app.skipIosTests=false # We are skipping auth ios tests due to an issue with keychain and simulator. firebase-auth.skipIosTests=true firebase-common.skipIosTests=false +firebase-common-internal.skipIosTests=false firebase-config.skipIosTests=false firebase-database.skipIosTests=false firebase-firestore.skipIosTests=false @@ -38,6 +39,7 @@ firebase-storage.skipIosTests=false firebase-app.skipJsTests=false firebase-auth.skipJsTests=false firebase-common.skipJsTests=false +firebase-common-internal.skipJsTests=false firebase-config.skipJsTests=false firebase-database.skipJsTests=false firebase-firestore.skipJsTests=false @@ -50,6 +52,7 @@ firebase-storage.skipJsTests=false firebase-app.version=1.12.0 firebase-auth.version=1.12.0 firebase-common.version=1.12.0 +firebase-common-internal.version=1.12.0 firebase-config.version=1.12.0 firebase-database.version=1.12.0 firebase-firestore.version=1.12.0 diff --git a/settings.gradle.kts b/settings.gradle.kts index dd80bfd3a..68af478a5 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -2,6 +2,7 @@ include( "firebase-app", "firebase-auth", "firebase-common", + "firebase-common-internal", "firebase-config", "firebase-database", "firebase-firestore", @@ -20,5 +21,7 @@ pluginManagement { kotlin("multiplatform") version kotlinVersion kotlin("native.cocoapods") version kotlinVersion kotlin("plugin.serialization") version kotlinVersion + id("com.android.application") version "8.1.3" + id("org.jetbrains.kotlin.android") version "1.9.0" } } From a629f9a38d52af285c5235af68ed942e5f04514e Mon Sep 17 00:00:00 2001 From: Gijs van Veen Date: Sun, 14 Apr 2024 22:53:56 +0200 Subject: [PATCH 2/2] moved EncodedData to internal --- .../firebase/internal/EncodedObject.kt | 7 ++++ .../gitlive/firebase/internal/_encoders.kt | 10 ----- .../firebase/internal/EncodedObject.kt | 27 ++++++++++++++ .../dev/gitlive/firebase/internal/encoders.kt | 16 -------- .../firebase/internal/EncodedObject.kt | 6 +++ .../gitlive/firebase/internal/_encoders.kt | 12 ------ .../firebase/internal/EncodedObject.kt | 32 ++++++++++++++++ .../gitlive/firebase/internal/_encoders.kt | 37 ------------------- .../dev/gitlive/firebase/EncodedObject.kt | 9 ----- .../dev/gitlive/firebase/EncodedObject.kt | 13 ------- .../dev/gitlive/firebase/EncodedObject.kt | 9 ----- .../dev/gitlive/firebase/EncodedObject.kt | 12 ------ .../dev/gitlive/firebase/database/database.kt | 7 ++-- .../dev/gitlive/firebase/database/database.kt | 2 +- .../dev/gitlive/firebase/database/database.kt | 7 ++-- .../dev/gitlive/firebase/database/database.kt | 7 ++-- .../gitlive/firebase/firestore/firestore.kt | 23 ++++++------ .../gitlive/firebase/firestore/firestore.kt | 2 +- .../gitlive/firebase/firestore/firestore.kt | 35 +++++++++--------- .../gitlive/firebase/firestore/firestore.kt | 19 +++++----- 20 files changed, 126 insertions(+), 166 deletions(-) create mode 100644 firebase-common-internal/src/androidMain/kotlin/dev/gitlive/firebase/internal/EncodedObject.kt create mode 100644 firebase-common-internal/src/commonMain/kotlin/dev/gitlive/firebase/internal/EncodedObject.kt create mode 100644 firebase-common-internal/src/iosMain/kotlin/dev/gitlive/firebase/internal/EncodedObject.kt create mode 100644 firebase-common-internal/src/jsMain/kotlin/dev/gitlive/firebase/internal/EncodedObject.kt delete mode 100644 firebase-common/src/androidMain/kotlin/dev/gitlive/firebase/EncodedObject.kt delete mode 100644 firebase-common/src/commonMain/kotlin/dev/gitlive/firebase/EncodedObject.kt delete mode 100644 firebase-common/src/iosMain/kotlin/dev/gitlive/firebase/EncodedObject.kt delete mode 100644 firebase-common/src/jsMain/kotlin/dev/gitlive/firebase/EncodedObject.kt diff --git a/firebase-common-internal/src/androidMain/kotlin/dev/gitlive/firebase/internal/EncodedObject.kt b/firebase-common-internal/src/androidMain/kotlin/dev/gitlive/firebase/internal/EncodedObject.kt new file mode 100644 index 000000000..6d7f8d63a --- /dev/null +++ b/firebase-common-internal/src/androidMain/kotlin/dev/gitlive/firebase/internal/EncodedObject.kt @@ -0,0 +1,7 @@ +@file:JvmName("AndroidEncodedObject") +package dev.gitlive.firebase.internal + +val EncodedObject.android: Map get() = raw + +@PublishedApi +internal actual fun Any.asNativeMap(): Map<*, *>? = this as? Map<*, *> diff --git a/firebase-common-internal/src/androidMain/kotlin/dev/gitlive/firebase/internal/_encoders.kt b/firebase-common-internal/src/androidMain/kotlin/dev/gitlive/firebase/internal/_encoders.kt index 0a8ce569b..d4f8316fc 100644 --- a/firebase-common-internal/src/androidMain/kotlin/dev/gitlive/firebase/internal/_encoders.kt +++ b/firebase-common-internal/src/androidMain/kotlin/dev/gitlive/firebase/internal/_encoders.kt @@ -4,21 +4,11 @@ package dev.gitlive.firebase.internal -import dev.gitlive.firebase.EncodedObject import kotlinx.serialization.descriptors.PolymorphicKind import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.descriptors.StructureKind import kotlin.collections.set -@PublishedApi -internal data class EncodedObjectImpl internal constructor(override val raw: Map) : EncodedObject, Map by raw - -@PublishedApi -internal actual fun Map.asEncodedObject(): EncodedObject = EncodedObjectImpl(this) - -@PublishedApi -internal actual fun Any.asNativeMap(): Map<*, *>? = this as? Map<*, *> - actual fun FirebaseEncoder.structureEncoder(descriptor: SerialDescriptor): FirebaseCompositeEncoder = when(descriptor.kind) { StructureKind.LIST -> mutableListOf() .also { value = it } diff --git a/firebase-common-internal/src/commonMain/kotlin/dev/gitlive/firebase/internal/EncodedObject.kt b/firebase-common-internal/src/commonMain/kotlin/dev/gitlive/firebase/internal/EncodedObject.kt new file mode 100644 index 000000000..e02664500 --- /dev/null +++ b/firebase-common-internal/src/commonMain/kotlin/dev/gitlive/firebase/internal/EncodedObject.kt @@ -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 +} + +@JvmInline +@PublishedApi +internal value class EncodedObjectImpl(override val raw: Map) : 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) diff --git a/firebase-common-internal/src/commonMain/kotlin/dev/gitlive/firebase/internal/encoders.kt b/firebase-common-internal/src/commonMain/kotlin/dev/gitlive/firebase/internal/encoders.kt index 11a06bdaf..0015e3cfd 100644 --- a/firebase-common-internal/src/commonMain/kotlin/dev/gitlive/firebase/internal/encoders.kt +++ b/firebase-common-internal/src/commonMain/kotlin/dev/gitlive/firebase/internal/encoders.kt @@ -5,7 +5,6 @@ package dev.gitlive.firebase.internal import dev.gitlive.firebase.EncodeSettings -import dev.gitlive.firebase.EncodedObject import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.SerializationStrategy import kotlinx.serialization.descriptors.SerialDescriptor @@ -74,21 +73,6 @@ internal inline fun encode(value: T, encodeSettings: EncodeSettings) }.value } -@PublishedApi -expect internal 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().asEncodedObject() - -@PublishedApi -internal expect fun Map.asEncodedObject(): EncodedObject - /** * An extension which which serializer to use for value. Handy in updating fields by name or path * where using annotation is not possible diff --git a/firebase-common-internal/src/iosMain/kotlin/dev/gitlive/firebase/internal/EncodedObject.kt b/firebase-common-internal/src/iosMain/kotlin/dev/gitlive/firebase/internal/EncodedObject.kt new file mode 100644 index 000000000..c261934f1 --- /dev/null +++ b/firebase-common-internal/src/iosMain/kotlin/dev/gitlive/firebase/internal/EncodedObject.kt @@ -0,0 +1,6 @@ +package dev.gitlive.firebase.internal + +val EncodedObject.ios: Map get() = raw.mapKeys { (key, _) -> key } + +@PublishedApi +internal actual fun Any.asNativeMap(): Map<*, *>? = this as? Map<*, *> diff --git a/firebase-common-internal/src/iosMain/kotlin/dev/gitlive/firebase/internal/_encoders.kt b/firebase-common-internal/src/iosMain/kotlin/dev/gitlive/firebase/internal/_encoders.kt index 72eac41d9..966a7e64e 100644 --- a/firebase-common-internal/src/iosMain/kotlin/dev/gitlive/firebase/internal/_encoders.kt +++ b/firebase-common-internal/src/iosMain/kotlin/dev/gitlive/firebase/internal/_encoders.kt @@ -4,23 +4,11 @@ package dev.gitlive.firebase.internal -import dev.gitlive.firebase.EncodedObject import kotlinx.serialization.descriptors.PolymorphicKind import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.descriptors.StructureKind import kotlin.collections.set -@PublishedApi -internal data class InternalEncodedObject internal constructor( - override val raw: Map -) : EncodedObject, Map by raw.mapKeys({ (key, _) -> key }) - -@PublishedApi -internal actual fun Map.asEncodedObject(): EncodedObject = InternalEncodedObject(this) - -@PublishedApi -internal actual fun Any.asNativeMap(): Map<*, *>? = this as? Map<*, *> - actual fun FirebaseEncoder.structureEncoder(descriptor: SerialDescriptor): FirebaseCompositeEncoder = when(descriptor.kind) { StructureKind.LIST -> encodeAsList() StructureKind.MAP -> mutableListOf() diff --git a/firebase-common-internal/src/jsMain/kotlin/dev/gitlive/firebase/internal/EncodedObject.kt b/firebase-common-internal/src/jsMain/kotlin/dev/gitlive/firebase/internal/EncodedObject.kt new file mode 100644 index 000000000..5fc84a829 --- /dev/null +++ b/firebase-common-internal/src/jsMain/kotlin/dev/gitlive/firebase/internal/EncodedObject.kt @@ -0,0 +1,32 @@ +package dev.gitlive.firebase.internal + +import kotlin.js.Json +import kotlin.js.json + +val EncodedObject.js: Json get() = json(*raw.entries.map { (key, value) -> key to value }.toTypedArray()) + +@PublishedApi +internal actual fun Any.asNativeMap(): Map<*, *>? { + val json = when (this) { + is Number -> null + is Boolean -> null + is String -> null + is Map<*, *> -> { + if (keys.all { it is String }) { + this as Json + } else { + null + } + } + is Collection<*> -> null + is Array<*> -> null + else -> { + this as Json + } + } ?: return null + val mutableMap = mutableMapOf() + for (key in js("Object").keys(json)) { + mutableMap[key] = json[key] + } + return mutableMap.toMap() +} diff --git a/firebase-common-internal/src/jsMain/kotlin/dev/gitlive/firebase/internal/_encoders.kt b/firebase-common-internal/src/jsMain/kotlin/dev/gitlive/firebase/internal/_encoders.kt index 0c8ea424c..5cf22b6bd 100644 --- a/firebase-common-internal/src/jsMain/kotlin/dev/gitlive/firebase/internal/_encoders.kt +++ b/firebase-common-internal/src/jsMain/kotlin/dev/gitlive/firebase/internal/_encoders.kt @@ -4,48 +4,11 @@ package dev.gitlive.firebase.internal -import dev.gitlive.firebase.EncodedObject import kotlinx.serialization.descriptors.PolymorphicKind import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.descriptors.StructureKind -import kotlin.js.Json import kotlin.js.json -@PublishedApi -internal class InternalEncodedObject internal constructor(override val raw: Map) : - EncodedObject { - override val json: Json get() = json(*raw.entries.map { (key, value) -> key to value }.toTypedArray()) -} - -@PublishedApi -internal actual fun Map.asEncodedObject(): EncodedObject = InternalEncodedObject(this) - -@PublishedApi -internal actual fun Any.asNativeMap(): Map<*, *>? { - val json = when (this) { - is Number -> null - is Boolean -> null - is String -> null - is Map<*, *> -> { - if (keys.all { it is String }) { - this as Json - } else { - null - } - } - is Collection<*> -> null - is Array<*> -> null - else -> { - this as Json - } - } ?: return null - val mutableMap = mutableMapOf() - for (key in js("Object").keys(json)) { - mutableMap[key] = json[key] - } - return mutableMap.toMap() -} - actual fun FirebaseEncoder.structureEncoder(descriptor: SerialDescriptor): FirebaseCompositeEncoder = when(descriptor.kind) { StructureKind.LIST -> encodeAsList(descriptor) StructureKind.MAP -> { diff --git a/firebase-common/src/androidMain/kotlin/dev/gitlive/firebase/EncodedObject.kt b/firebase-common/src/androidMain/kotlin/dev/gitlive/firebase/EncodedObject.kt deleted file mode 100644 index a176bcbeb..000000000 --- a/firebase-common/src/androidMain/kotlin/dev/gitlive/firebase/EncodedObject.kt +++ /dev/null @@ -1,9 +0,0 @@ -/* - * Copyright (c) 2020 GitLive Ltd. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.gitlive.firebase - -actual interface EncodedObject : Map { - actual val raw: Map -} diff --git a/firebase-common/src/commonMain/kotlin/dev/gitlive/firebase/EncodedObject.kt b/firebase-common/src/commonMain/kotlin/dev/gitlive/firebase/EncodedObject.kt deleted file mode 100644 index 1e773d16e..000000000 --- a/firebase-common/src/commonMain/kotlin/dev/gitlive/firebase/EncodedObject.kt +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright (c) 2020 GitLive Ltd. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.gitlive.firebase - -/** - * 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. - */ -expect interface EncodedObject { - val raw: Map -} diff --git a/firebase-common/src/iosMain/kotlin/dev/gitlive/firebase/EncodedObject.kt b/firebase-common/src/iosMain/kotlin/dev/gitlive/firebase/EncodedObject.kt deleted file mode 100644 index 6fa97683a..000000000 --- a/firebase-common/src/iosMain/kotlin/dev/gitlive/firebase/EncodedObject.kt +++ /dev/null @@ -1,9 +0,0 @@ -/* - * Copyright (c) 2020 GitLive Ltd. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.gitlive.firebase - -actual interface EncodedObject : Map { - actual val raw: Map -} diff --git a/firebase-common/src/jsMain/kotlin/dev/gitlive/firebase/EncodedObject.kt b/firebase-common/src/jsMain/kotlin/dev/gitlive/firebase/EncodedObject.kt deleted file mode 100644 index 864deebf3..000000000 --- a/firebase-common/src/jsMain/kotlin/dev/gitlive/firebase/EncodedObject.kt +++ /dev/null @@ -1,12 +0,0 @@ -/* - * Copyright (c) 2020 GitLive Ltd. Use of this source code is governed by the Apache 2.0 license. - */ - -package dev.gitlive.firebase - -import kotlin.js.Json - -actual interface EncodedObject { - actual val raw: Map - val json: Json -} diff --git a/firebase-database/src/androidMain/kotlin/dev/gitlive/firebase/database/database.kt b/firebase-database/src/androidMain/kotlin/dev/gitlive/firebase/database/database.kt index f5949e386..0e14cb8fb 100644 --- a/firebase-database/src/androidMain/kotlin/dev/gitlive/firebase/database/database.kt +++ b/firebase-database/src/androidMain/kotlin/dev/gitlive/firebase/database/database.kt @@ -13,11 +13,12 @@ import com.google.firebase.database.Transaction import com.google.firebase.database.ValueEventListener import dev.gitlive.firebase.DecodeSettings import dev.gitlive.firebase.EncodeDecodeSettingsBuilder -import dev.gitlive.firebase.EncodedObject +import dev.gitlive.firebase.internal.EncodedObject import dev.gitlive.firebase.Firebase import dev.gitlive.firebase.FirebaseApp import dev.gitlive.firebase.database.ChildEvent.Type import dev.gitlive.firebase.database.FirebaseDatabase.Companion.FirebaseDatabase +import dev.gitlive.firebase.internal.android import dev.gitlive.firebase.internal.decode import dev.gitlive.firebase.internal.reencodeTransformation import kotlinx.coroutines.CompletableDeferred @@ -207,7 +208,7 @@ internal actual class NativeDatabaseReference internal constructor( .run { Unit } actual suspend fun updateEncodedChildren(encodedUpdate: EncodedObject) = - android.updateChildren(encodedUpdate) + android.updateChildren(encodedUpdate.android) .run { if(persistenceEnabled) await() else awaitWhileOnline(database) } .run { Unit } @@ -297,7 +298,7 @@ internal actual class NativeOnDisconnect internal constructor( .run { Unit } actual suspend fun updateEncodedChildren(encodedUpdate: EncodedObject) = - android.updateChildren(encodedUpdate) + android.updateChildren(encodedUpdate.android) .run { if(persistenceEnabled) await() else awaitWhileOnline(database) } .run { Unit } } diff --git a/firebase-database/src/commonMain/kotlin/dev/gitlive/firebase/database/database.kt b/firebase-database/src/commonMain/kotlin/dev/gitlive/firebase/database/database.kt index 631197f2e..55df2a2e5 100644 --- a/firebase-database/src/commonMain/kotlin/dev/gitlive/firebase/database/database.kt +++ b/firebase-database/src/commonMain/kotlin/dev/gitlive/firebase/database/database.kt @@ -7,7 +7,7 @@ package dev.gitlive.firebase.database import dev.gitlive.firebase.DecodeSettings import dev.gitlive.firebase.EncodeDecodeSettingsBuilder import dev.gitlive.firebase.EncodeSettings -import dev.gitlive.firebase.EncodedObject +import dev.gitlive.firebase.internal.EncodedObject import dev.gitlive.firebase.Firebase import dev.gitlive.firebase.FirebaseApp import dev.gitlive.firebase.database.ChildEvent.Type.ADDED diff --git a/firebase-database/src/iosMain/kotlin/dev/gitlive/firebase/database/database.kt b/firebase-database/src/iosMain/kotlin/dev/gitlive/firebase/database/database.kt index 1783c7432..45fad1aa4 100644 --- a/firebase-database/src/iosMain/kotlin/dev/gitlive/firebase/database/database.kt +++ b/firebase-database/src/iosMain/kotlin/dev/gitlive/firebase/database/database.kt @@ -16,7 +16,6 @@ import cocoapods.FirebaseDatabase.FIRDatabaseReference import cocoapods.FirebaseDatabase.FIRTransactionResult import dev.gitlive.firebase.DecodeSettings import dev.gitlive.firebase.EncodeDecodeSettingsBuilder -import dev.gitlive.firebase.EncodedObject import dev.gitlive.firebase.Firebase import dev.gitlive.firebase.FirebaseApp import dev.gitlive.firebase.database.ChildEvent.Type @@ -24,7 +23,9 @@ import dev.gitlive.firebase.database.ChildEvent.Type.ADDED import dev.gitlive.firebase.database.ChildEvent.Type.CHANGED import dev.gitlive.firebase.database.ChildEvent.Type.MOVED import dev.gitlive.firebase.database.ChildEvent.Type.REMOVED +import dev.gitlive.firebase.internal.EncodedObject import dev.gitlive.firebase.internal.decode +import dev.gitlive.firebase.internal.ios import dev.gitlive.firebase.internal.reencodeTransformation import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.FlowPreview @@ -170,7 +171,7 @@ internal actual class NativeDatabaseReference internal constructor( } actual suspend fun updateEncodedChildren(encodedUpdate: EncodedObject) { - ios.await(persistenceEnabled) { updateChildValues(encodedUpdate, it) } + ios.await(persistenceEnabled) { updateChildValues(encodedUpdate.ios, it) } } actual suspend fun removeValue() { @@ -241,7 +242,7 @@ internal actual class NativeOnDisconnect internal constructor( } actual suspend fun updateEncodedChildren(encodedUpdate: EncodedObject) { - ios.await(persistenceEnabled) { onDisconnectUpdateChildValues(encodedUpdate, it) } + ios.await(persistenceEnabled) { onDisconnectUpdateChildValues(encodedUpdate.ios, it) } } } diff --git a/firebase-database/src/jsMain/kotlin/dev/gitlive/firebase/database/database.kt b/firebase-database/src/jsMain/kotlin/dev/gitlive/firebase/database/database.kt index 725b8c4bd..c5aeb4941 100644 --- a/firebase-database/src/jsMain/kotlin/dev/gitlive/firebase/database/database.kt +++ b/firebase-database/src/jsMain/kotlin/dev/gitlive/firebase/database/database.kt @@ -6,7 +6,6 @@ package dev.gitlive.firebase.database import dev.gitlive.firebase.DecodeSettings import dev.gitlive.firebase.EncodeDecodeSettingsBuilder -import dev.gitlive.firebase.EncodedObject import dev.gitlive.firebase.Firebase import dev.gitlive.firebase.FirebaseApp import dev.gitlive.firebase.database.externals.CancelCallback @@ -28,7 +27,9 @@ import dev.gitlive.firebase.database.externals.ref import dev.gitlive.firebase.database.externals.remove import dev.gitlive.firebase.database.externals.set import dev.gitlive.firebase.database.externals.update +import dev.gitlive.firebase.internal.EncodedObject import dev.gitlive.firebase.internal.decode +import dev.gitlive.firebase.internal.js import dev.gitlive.firebase.internal.reencodeTransformation import kotlinx.coroutines.asDeferred import kotlinx.coroutines.channels.awaitClose @@ -183,7 +184,7 @@ internal actual class NativeDatabaseReference internal constructor( } actual suspend fun updateEncodedChildren(encodedUpdate: EncodedObject) = - rethrow { update(js, encodedUpdate.json).awaitWhileOnline(database) } + rethrow { update(js, encodedUpdate.js).awaitWhileOnline(database) } actual suspend fun runTransaction(strategy: KSerializer, buildSettings: EncodeDecodeSettingsBuilder.() -> Unit, transactionUpdate: (currentData: T) -> T): DataSnapshot { @@ -235,7 +236,7 @@ internal actual class NativeOnDisconnect internal constructor( rethrow { js.set(encodedValue).awaitWhileOnline(database) } actual suspend fun updateEncodedChildren(encodedUpdate: EncodedObject) = - rethrow { js.update(encodedUpdate.json).awaitWhileOnline(database) } + rethrow { js.update(encodedUpdate.js).awaitWhileOnline(database) } } diff --git a/firebase-firestore/src/androidMain/kotlin/dev/gitlive/firebase/firestore/firestore.kt b/firebase-firestore/src/androidMain/kotlin/dev/gitlive/firebase/firestore/firestore.kt index a035a9957..e45037420 100644 --- a/firebase-firestore/src/androidMain/kotlin/dev/gitlive/firebase/firestore/firestore.kt +++ b/firebase-firestore/src/androidMain/kotlin/dev/gitlive/firebase/firestore/firestore.kt @@ -6,9 +6,10 @@ package dev.gitlive.firebase.firestore import com.google.firebase.firestore.MetadataChanges -import dev.gitlive.firebase.EncodedObject +import dev.gitlive.firebase.internal.EncodedObject import dev.gitlive.firebase.Firebase import dev.gitlive.firebase.FirebaseApp +import dev.gitlive.firebase.internal.android import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.callbackFlow @@ -84,12 +85,12 @@ internal actual class NativeWriteBatchWrapper actual internal constructor(actual encodedData: EncodedObject, setOptions: SetOptions ): NativeWriteBatchWrapper = (setOptions.android?.let { - native.set(documentRef.android, encodedData, it) - } ?: native.set(documentRef.android, encodedData)).let { + native.set(documentRef.android, encodedData.android, it) + } ?: native.set(documentRef.android, encodedData.android)).let { this } - actual fun updateEncoded(documentRef: DocumentReference, encodedData: EncodedObject) = native.update(documentRef.android, encodedData).let { this } + actual fun updateEncoded(documentRef: DocumentReference, encodedData: EncodedObject) = native.update(documentRef.android, encodedData.android).let { this } actual fun updateEncodedFieldsAndValues( documentRef: DocumentReference, @@ -126,12 +127,12 @@ internal actual class NativeTransactionWrapper actual internal constructor(actua setOptions: SetOptions ): NativeTransactionWrapper { setOptions.android?.let { - native.set(documentRef.android, encodedData, it) - } ?: native.set(documentRef.android, encodedData) + native.set(documentRef.android, encodedData.android, it) + } ?: native.set(documentRef.android, encodedData.android) return this } - actual fun updateEncoded(documentRef: DocumentReference, encodedData: EncodedObject) = native.update(documentRef.android, encodedData).let { this } + actual fun updateEncoded(documentRef: DocumentReference, encodedData: EncodedObject) = native.update(documentRef.android, encodedData.android).let { this } actual fun updateEncodedFieldsAndValues( documentRef: DocumentReference, @@ -178,13 +179,13 @@ internal actual class NativeDocumentReference actual constructor(actual val nati actual suspend fun setEncoded(encodedData: EncodedObject, setOptions: SetOptions) { val task = (setOptions.android?.let { - android.set(encodedData, it) - } ?: android.set(encodedData)) + android.set(encodedData.android, it) + } ?: android.set(encodedData.android)) task.await() } actual suspend fun updateEncoded(encodedData: EncodedObject) { - android.update(encodedData).await() + android.update(encodedData.android).await() } actual suspend fun updateEncodedFieldsAndValues(encodedFieldsAndValues: List>) { @@ -350,7 +351,7 @@ internal actual class NativeCollectionReferenceWrapper internal actual construct actual fun document(documentPath: String) = NativeDocumentReference(native.document(documentPath)) - actual suspend fun addEncoded(data: EncodedObject) = NativeDocumentReference(native.add(data).await()) + actual suspend fun addEncoded(data: EncodedObject) = NativeDocumentReference(native.add(data.android).await()) } val CollectionReference.android get() = native diff --git a/firebase-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore/firestore.kt b/firebase-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore/firestore.kt index 0f1935672..5923e53d5 100644 --- a/firebase-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore/firestore.kt +++ b/firebase-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore/firestore.kt @@ -6,7 +6,7 @@ package dev.gitlive.firebase.firestore import dev.gitlive.firebase.DecodeSettings import dev.gitlive.firebase.EncodeSettings -import dev.gitlive.firebase.EncodedObject +import dev.gitlive.firebase.internal.EncodedObject import dev.gitlive.firebase.Firebase import dev.gitlive.firebase.FirebaseApp import dev.gitlive.firebase.FirebaseException diff --git a/firebase-firestore/src/iosMain/kotlin/dev/gitlive/firebase/firestore/firestore.kt b/firebase-firestore/src/iosMain/kotlin/dev/gitlive/firebase/firestore/firestore.kt index 6a391825c..b2c676ecf 100644 --- a/firebase-firestore/src/iosMain/kotlin/dev/gitlive/firebase/firestore/firestore.kt +++ b/firebase-firestore/src/iosMain/kotlin/dev/gitlive/firebase/firestore/firestore.kt @@ -6,10 +6,11 @@ package dev.gitlive.firebase.firestore import cocoapods.FirebaseFirestoreInternal.* import cocoapods.FirebaseFirestoreInternal.FIRDocumentChangeType.* -import dev.gitlive.firebase.EncodedObject import dev.gitlive.firebase.Firebase import dev.gitlive.firebase.FirebaseApp import dev.gitlive.firebase.FirebaseException +import dev.gitlive.firebase.internal.EncodedObject +import dev.gitlive.firebase.internal.ios import kotlinx.cinterop.* import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.channels.awaitClose @@ -80,13 +81,13 @@ internal actual class NativeWriteBatchWrapper actual constructor(actual val nati encodedData: EncodedObject, setOptions: SetOptions ): NativeWriteBatchWrapper = when (setOptions) { - is SetOptions.Merge -> native.setData(encodedData, documentRef.ios, true) - is SetOptions.Overwrite -> native.setData(encodedData, documentRef.ios, false) - is SetOptions.MergeFields -> native.setData(encodedData, documentRef.ios, setOptions.fields) - is SetOptions.MergeFieldPaths -> native.setData(encodedData, documentRef.ios, setOptions.encodedFieldPaths) + is SetOptions.Merge -> native.setData(encodedData.ios, documentRef.ios, true) + is SetOptions.Overwrite -> native.setData(encodedData.ios, documentRef.ios, false) + is SetOptions.MergeFields -> native.setData(encodedData.ios, documentRef.ios, setOptions.fields) + is SetOptions.MergeFieldPaths -> native.setData(encodedData.ios, documentRef.ios, setOptions.encodedFieldPaths) }.let { this } - actual fun updateEncoded(documentRef: DocumentReference, encodedData: EncodedObject): NativeWriteBatchWrapper = native.updateData(encodedData, documentRef.ios).let { this } + actual fun updateEncoded(documentRef: DocumentReference, encodedData: EncodedObject): NativeWriteBatchWrapper = native.updateData(encodedData.ios, documentRef.ios).let { this } actual fun updateEncodedFieldsAndValues( documentRef: DocumentReference, @@ -122,13 +123,13 @@ internal actual class NativeTransactionWrapper actual constructor(actual val nat encodedData: EncodedObject, setOptions: SetOptions ): NativeTransactionWrapper = when (setOptions) { - is SetOptions.Merge -> native.setData(encodedData, documentRef.ios, true) - is SetOptions.Overwrite -> native.setData(encodedData, documentRef.ios, false) - is SetOptions.MergeFields -> native.setData(encodedData, documentRef.ios, setOptions.fields) - is SetOptions.MergeFieldPaths -> native.setData(encodedData, documentRef.ios, setOptions.encodedFieldPaths) + is SetOptions.Merge -> native.setData(encodedData.ios, documentRef.ios, true) + is SetOptions.Overwrite -> native.setData(encodedData.ios, documentRef.ios, false) + is SetOptions.MergeFields -> native.setData(encodedData.ios, documentRef.ios, setOptions.fields) + is SetOptions.MergeFieldPaths -> native.setData(encodedData.ios, documentRef.ios, setOptions.encodedFieldPaths) }.let { this } - actual fun updateEncoded(documentRef: DocumentReference, encodedData: EncodedObject): NativeTransactionWrapper = native.updateData(encodedData, documentRef.ios).let { this } + actual fun updateEncoded(documentRef: DocumentReference, encodedData: EncodedObject): NativeTransactionWrapper = native.updateData(encodedData.ios, documentRef.ios).let { this } actual fun updateEncodedFieldsAndValues( documentRef: DocumentReference, @@ -189,15 +190,15 @@ internal actual class NativeDocumentReference actual constructor(actual val nati actual suspend fun setEncoded(encodedData: EncodedObject, setOptions: SetOptions) = await { when (setOptions) { - is SetOptions.Merge -> ios.setData(encodedData, true, it) - is SetOptions.Overwrite -> ios.setData(encodedData, false, it) - is SetOptions.MergeFields -> ios.setData(encodedData, setOptions.fields, it) - is SetOptions.MergeFieldPaths -> ios.setData(encodedData, setOptions.encodedFieldPaths, it) + is SetOptions.Merge -> ios.setData(encodedData.ios, true, it) + is SetOptions.Overwrite -> ios.setData(encodedData.ios, false, it) + is SetOptions.MergeFields -> ios.setData(encodedData.ios, setOptions.fields, it) + is SetOptions.MergeFieldPaths -> ios.setData(encodedData.ios, setOptions.encodedFieldPaths, it) } } actual suspend fun updateEncoded(encodedData: EncodedObject) = await { - ios.updateData(encodedData, it) + ios.updateData(encodedData.ios, it) } actual suspend fun updateEncodedFieldsAndValues(encodedFieldsAndValues: List>) = await { @@ -313,7 +314,7 @@ internal actual class NativeCollectionReferenceWrapper internal actual construct actual fun document(documentPath: String) = NativeDocumentReference(native.documentWithPath(documentPath)) - actual suspend fun addEncoded(data: EncodedObject) = NativeDocumentReference(await { native.addDocumentWithData(data, it) }) + actual suspend fun addEncoded(data: EncodedObject) = NativeDocumentReference(await { native.addDocumentWithData(data.ios, it) }) } val CollectionReference.ios get() = native diff --git a/firebase-firestore/src/jsMain/kotlin/dev/gitlive/firebase/firestore/firestore.kt b/firebase-firestore/src/jsMain/kotlin/dev/gitlive/firebase/firestore/firestore.kt index c6b3effff..8161313f3 100644 --- a/firebase-firestore/src/jsMain/kotlin/dev/gitlive/firebase/firestore/firestore.kt +++ b/firebase-firestore/src/jsMain/kotlin/dev/gitlive/firebase/firestore/firestore.kt @@ -4,7 +4,6 @@ package dev.gitlive.firebase.firestore -import dev.gitlive.firebase.EncodedObject import dev.gitlive.firebase.Firebase import dev.gitlive.firebase.FirebaseApp import dev.gitlive.firebase.FirebaseException @@ -16,7 +15,6 @@ import dev.gitlive.firebase.firestore.externals.clearIndexedDbPersistence import dev.gitlive.firebase.firestore.externals.connectFirestoreEmulator import dev.gitlive.firebase.firestore.externals.deleteDoc import dev.gitlive.firebase.firestore.externals.doc -import dev.gitlive.firebase.firestore.externals.documentId as jsDocumentId import dev.gitlive.firebase.firestore.externals.enableIndexedDbPersistence import dev.gitlive.firebase.firestore.externals.getDoc import dev.gitlive.firebase.firestore.externals.getDocs @@ -30,6 +28,8 @@ import dev.gitlive.firebase.firestore.externals.refEqual import dev.gitlive.firebase.firestore.externals.setDoc import dev.gitlive.firebase.firestore.externals.setLogLevel import dev.gitlive.firebase.firestore.externals.writeBatch +import dev.gitlive.firebase.internal.EncodedObject +import dev.gitlive.firebase.internal.js import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.await import kotlinx.coroutines.channels.awaitClose @@ -51,6 +51,7 @@ import dev.gitlive.firebase.firestore.externals.WriteBatch as JsWriteBatch import dev.gitlive.firebase.firestore.externals.collection as jsCollection import dev.gitlive.firebase.firestore.externals.collectionGroup as jsCollectionGroup import dev.gitlive.firebase.firestore.externals.disableNetwork as jsDisableNetwork +import dev.gitlive.firebase.firestore.externals.documentId as jsDocumentId import dev.gitlive.firebase.firestore.externals.enableNetwork as jsEnableNetwork import dev.gitlive.firebase.firestore.externals.endAt as jsEndAt import dev.gitlive.firebase.firestore.externals.endBefore as jsEndBefore @@ -131,9 +132,9 @@ internal actual class NativeWriteBatchWrapper actual internal constructor(actual documentRef: DocumentReference, encodedData: EncodedObject, setOptions: SetOptions - ): NativeWriteBatchWrapper = rethrow { js.set(documentRef.js, encodedData.json, setOptions.js) }.let { this } + ): NativeWriteBatchWrapper = rethrow { js.set(documentRef.js, encodedData.js, setOptions.js) }.let { this } - actual fun updateEncoded(documentRef: DocumentReference, encodedData: EncodedObject): NativeWriteBatchWrapper = rethrow { js.update(documentRef.js, encodedData.json) } + actual fun updateEncoded(documentRef: DocumentReference, encodedData: EncodedObject): NativeWriteBatchWrapper = rethrow { js.update(documentRef.js, encodedData.js) } .let { this } actual fun updateEncodedFieldsAndValues( @@ -177,11 +178,11 @@ internal actual class NativeTransactionWrapper actual internal constructor(actua encodedData: EncodedObject, setOptions: SetOptions ): NativeTransactionWrapper = rethrow { - js.set(documentRef.js, encodedData.json, setOptions.js) + js.set(documentRef.js, encodedData.js, setOptions.js) } .let { this } - actual fun updateEncoded(documentRef: DocumentReference, encodedData: EncodedObject): NativeTransactionWrapper = rethrow { js.update(documentRef.js, encodedData.json) } + actual fun updateEncoded(documentRef: DocumentReference, encodedData: EncodedObject): NativeTransactionWrapper = rethrow { js.update(documentRef.js, encodedData.js) } .let { this } actual fun updateEncodedFieldsAndValues( @@ -245,10 +246,10 @@ internal actual class NativeDocumentReference actual constructor(actual val nati } actual suspend fun setEncoded(encodedData: EncodedObject, setOptions: SetOptions) = rethrow { - setDoc(js, encodedData.json, setOptions.js).await() + setDoc(js, encodedData.js, setOptions.js).await() } - actual suspend fun updateEncoded(encodedData: EncodedObject) = rethrow { jsUpdate(js, encodedData.json).await() } + actual suspend fun updateEncoded(encodedData: EncodedObject) = rethrow { jsUpdate(js, encodedData.js).await() } actual suspend fun updateEncodedFieldsAndValues(encodedFieldsAndValues: List>) { rethrow { @@ -398,7 +399,7 @@ internal actual class NativeCollectionReferenceWrapper actual internal construct actual fun document(documentPath: String) = rethrow { NativeDocumentReference(doc(js, documentPath)) } actual suspend fun addEncoded(data: EncodedObject) = rethrow { - NativeDocumentReference(addDoc(js, data.json).await()) + NativeDocumentReference(addDoc(js, data.js).await()) } }