Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workaround for XCode 13 Fixes#255 #256

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ buildscript {
}
}
dependencies {
classpath("com.android.tools.build:gradle:7.0.1")
classpath("com.android.tools.build:gradle:7.0.4")
classpath("com.adarshr:gradle-test-logger-plugin:2.1.1")
}
}
Expand Down Expand Up @@ -49,6 +49,9 @@ subprojects {
mavenLocal()
google()
mavenCentral()
maven {
setUrl("https://maven.pkg.jetbrains.space/public/p/kotlinx-coroutines/maven")
}
}

tasks.withType<Sign>().configureEach {
Expand Down Expand Up @@ -195,9 +198,9 @@ subprojects {
}

dependencies {
"commonMainImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2")
"commonMainImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.1-new-mm-dev2")
"androidMainImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.5.2")
"androidMainImplementation"(platform("com.google.firebase:firebase-bom:28.4.1"))
"androidMainImplementation"(platform("com.google.firebase:firebase-bom:29.0.3"))
"commonTestImplementation"(kotlin("test-common"))
"commonTestImplementation"(kotlin("test-annotations-common"))
"commonTestImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2")
Expand Down
2 changes: 1 addition & 1 deletion firebase-app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ kotlin {
compilations.getByName("main") {
cinterops.create("FirebaseCore") {
compilerOpts(nativeFrameworkPaths.map { "-F$it" })
extraOpts("-verbose")
extraOpts("-verbose","-compiler-option", "-DNS_FORMAT_ARGUMENT(A)=")
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion firebase-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gitlive/firebase-app",
"version": "1.0.0",
"version": "1.4.3",
"description": "Wrapper around firebase for usage in Kotlin Multiplatform projects",
"main": "firebase-app.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion firebase-app/src/nativeInterop/cinterop/Cartfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
binary "https://dl.google.com/dl/firebase/ios/carthage/FirebaseAnalyticsBinary.json" == 8.8.0
binary "https://dl.google.com/dl/firebase/ios/carthage/FirebaseAnalyticsBinary.json" == 8.10.0
2 changes: 1 addition & 1 deletion firebase-auth/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ kotlin {
compilations.getByName("main") {
cinterops.create("FirebaseAuth") {
compilerOpts(nativeFrameworkPaths.map { "-F$it" })
extraOpts("-verbose")
extraOpts("-verbose","-compiler-option", "-DNS_FORMAT_ARGUMENT(A)=")
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion firebase-auth/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gitlive/firebase-auth",
"version": "1.0.0",
"version": "1.4.3",
"description": "Wrapper around firebase for usage in Kotlin Multiplatform projects",
"main": "firebase-auth.js",
"scripts": {
Expand Down
20 changes: 10 additions & 10 deletions firebase-auth/src/iosMain/kotlin/dev/gitlive/firebase/auth/auth.kt
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ internal suspend inline fun <T> T.await(function: T.(callback: (NSError?) -> Uni
private fun NSError.toException() = when(domain) {
FIRAuthErrorDomain -> when(code) {
FIRAuthErrorCodeInvalidActionCode,
FIRAuthErrorCodeExpiredActionCode -> FirebaseAuthActionCodeException(toString())
FIRAuthErrorCodeExpiredActionCode -> FirebaseAuthActionCodeException(localizedDescription)

FIRAuthErrorCodeInvalidEmail -> FirebaseAuthEmailException(toString())
FIRAuthErrorCodeInvalidEmail -> FirebaseAuthEmailException(localizedDescription)

FIRAuthErrorCodeCaptchaCheckFailed,
FIRAuthErrorCodeInvalidPhoneNumber,
Expand All @@ -187,26 +187,26 @@ private fun NSError.toException() = when(domain) {
FIRAuthErrorCodeMissingVerificationID,
FIRAuthErrorCodeMissingVerificationCode,
FIRAuthErrorCodeWeakPassword,
FIRAuthErrorCodeInvalidCredential -> FirebaseAuthInvalidCredentialsException(toString())
FIRAuthErrorCodeInvalidCredential -> FirebaseAuthInvalidCredentialsException(localizedDescription)

FIRAuthErrorCodeInvalidUserToken -> FirebaseAuthInvalidUserException(toString())
FIRAuthErrorCodeInvalidUserToken -> FirebaseAuthInvalidUserException(localizedDescription)

FIRAuthErrorCodeRequiresRecentLogin -> FirebaseAuthRecentLoginRequiredException(toString())
FIRAuthErrorCodeRequiresRecentLogin -> FirebaseAuthRecentLoginRequiredException(localizedDescription)

FIRAuthErrorCodeSecondFactorAlreadyEnrolled,
FIRAuthErrorCodeSecondFactorRequired,
FIRAuthErrorCodeMaximumSecondFactorCountExceeded,
FIRAuthErrorCodeMultiFactorInfoNotFound -> FirebaseAuthMultiFactorException(toString())
FIRAuthErrorCodeMultiFactorInfoNotFound -> FirebaseAuthMultiFactorException(localizedDescription)

FIRAuthErrorCodeEmailAlreadyInUse,
FIRAuthErrorCodeAccountExistsWithDifferentCredential,
FIRAuthErrorCodeCredentialAlreadyInUse -> FirebaseAuthUserCollisionException(toString())
FIRAuthErrorCodeCredentialAlreadyInUse -> FirebaseAuthUserCollisionException(localizedDescription)

FIRAuthErrorCodeWebContextAlreadyPresented,
FIRAuthErrorCodeWebContextCancelled,
FIRAuthErrorCodeWebInternalError -> FirebaseAuthWebException(toString())
FIRAuthErrorCodeWebInternalError -> FirebaseAuthWebException(localizedDescription)

else -> FirebaseAuthException(toString())
else -> FirebaseAuthException(localizedDescription)
}
else -> FirebaseAuthException(toString())
else -> FirebaseAuthException(localizedDescription)
}
2 changes: 1 addition & 1 deletion firebase-auth/src/nativeInterop/cinterop/Cartfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
binary "https://dl.google.com/dl/firebase/ios/carthage/FirebaseAuthBinary.json" == 8.8.0
binary "https://dl.google.com/dl/firebase/ios/carthage/FirebaseAuthBinary.json" == 8.10.0
1 change: 1 addition & 0 deletions firebase-common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ kotlin {
val androidMain by getting {
dependencies {
api("com.google.firebase:firebase-common-ktx")
api("com.google.firebase:firebase-firestore-ktx")
}
}

Expand Down
2 changes: 1 addition & 1 deletion firebase-common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gitlive/firebase-common",
"version": "1.0.0",
"version": "1.4.3",
"description": "Wrapper around firebase for usage in Kotlin Multiplatform projects",
"main": "firebase-common.js",
"scripts": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import kotlinx.serialization.SerializationException
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.descriptors.StructureKind

actual fun FirebaseDecoder.structureDecoder(descriptor: SerialDescriptor, decodeDouble: (value: Any?) -> Double?): CompositeDecoder = when(descriptor.kind as StructureKind) {
actual fun FirebaseDecoder.structureDecoder(descriptor: SerialDescriptor): CompositeDecoder = when(descriptor.kind as StructureKind) {
StructureKind.CLASS, StructureKind.OBJECT -> (value as Map<*, *>).let { map ->
FirebaseClassDecoder(decodeDouble, map.size, { map.containsKey(it) }) { desc, index -> map[desc.getElementName(index)] }
FirebaseClassDecoder(map.size, { map.containsKey(it) }, {v -> getDecoder(v)}) { desc, index -> map[desc.getElementName(index)] }
}
StructureKind.LIST -> (value as List<*>).let {
FirebaseCompositeDecoder(decodeDouble, it.size) { _, index -> it[index] }
FirebaseCompositeDecoder(it.size, {v -> getDecoder(v)}) { _, index -> it[index] }
}
StructureKind.MAP -> (value as Map<*, *>).entries.toList().let {
FirebaseCompositeDecoder(decodeDouble, it.size) { _, index -> it[index/2].run { if(index % 2 == 0) key else value } }
FirebaseCompositeDecoder(it.size, {v -> getDecoder(v)}) { _, index -> it[index/2].run { if(index % 2 == 0) key else value } }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,30 @@

package dev.gitlive.firebase

import kotlinx.serialization.encoding.CompositeEncoder
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.descriptors.StructureKind
import kotlinx.serialization.encoding.CompositeEncoder
import kotlin.collections.set

actual fun FirebaseEncoder.structureEncoder(descriptor: SerialDescriptor): CompositeEncoder = when(descriptor.kind as StructureKind) {
actual fun FirebaseEncoder.structureEncoder(descriptor: SerialDescriptor): CompositeEncoder = when (descriptor.kind as StructureKind) {
StructureKind.LIST -> mutableListOf<Any?>()
.also { value = it }
.let { FirebaseCompositeEncoder(shouldEncodeElementDefault, positiveInfinity) { _, index, value -> it.add(index, value) } }
.let { FirebaseCompositeEncoder(shouldEncodeElementDefault, {getEncoder(shouldEncodeElementDefault)}) { _, index, value -> it.add(index, value) } }
StructureKind.MAP -> mutableListOf<Any?>()
.let { FirebaseCompositeEncoder(shouldEncodeElementDefault, positiveInfinity, { value = it.chunked(2).associate { (k, v) -> k to v } }) { _, _, value -> it.add(value) } }
StructureKind.CLASS, StructureKind.OBJECT -> mutableMapOf<Any?, Any?>()
.let {
FirebaseCompositeEncoder(
shouldEncodeElementDefault,
{getEncoder(shouldEncodeElementDefault)},
{ value = it.chunked(2).associate { (k, v) -> k to v } }) { _, _, value -> it.add(value) }
}
StructureKind.OBJECT, StructureKind.CLASS -> mutableMapOf<Any?, Any?>()
.also { value = it }
.let { FirebaseCompositeEncoder(shouldEncodeElementDefault, positiveInfinity) { _, index, value -> it[descriptor.getElementName(index)] = value } }
.let {
FirebaseCompositeEncoder(shouldEncodeElementDefault, {getEncoder(shouldEncodeElementDefault)}) { _, index, value ->
it[descriptor.getElementName(
index
)] = value
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,29 @@ import kotlinx.serialization.modules.SerializersModule
import kotlinx.serialization.serializer

@Suppress("UNCHECKED_CAST")
inline fun <reified T> decode(value: Any?, noinline decodeDouble: (value: Any?) -> Double? = { null }): T {
inline fun <reified T> decode(value: Any?): T {
val strategy = serializer<T>()
return decode(strategy as DeserializationStrategy<T>, value, decodeDouble)
return decode(strategy as DeserializationStrategy<T>, value)
}

fun <T> decode(strategy: DeserializationStrategy<T>, value: Any?, decodeDouble: (value: Any?) -> Double? = { null }): T {
fun <T> decode(strategy: DeserializationStrategy<T>, value: Any?): T {
require(value != null || strategy.descriptor.isNullable) { "Value was null for non-nullable type ${strategy.descriptor.serialName}" }
return FirebaseDecoder(value, decodeDouble).decodeSerializableValue(strategy)
return FirebaseDecoder(value).decodeSerializableValue(strategy)
}

expect fun FirebaseDecoder.structureDecoder(descriptor: SerialDescriptor, decodeDouble: (value: Any?) -> Double?): CompositeDecoder
expect fun FirebaseDecoder.structureDecoder(descriptor: SerialDescriptor): CompositeDecoder

class FirebaseDecoder(internal val value: Any?, private val decodeDouble: (value: Any?) -> Double?) : Decoder {
open class FirebaseDecoder(internal val value: Any?) : Decoder {
open fun getDecoder(value: Any?) : FirebaseDecoder = FirebaseDecoder(value)

override val serializersModule: SerializersModule
get() = EmptySerializersModule

override fun beginStructure(descriptor: SerialDescriptor) = structureDecoder(descriptor, decodeDouble)
override fun beginStructure(descriptor: SerialDescriptor) = structureDecoder(descriptor)

override fun decodeString() = decodeString(value)

override fun decodeDouble() = decodeDouble(value, decodeDouble)
override fun decodeDouble() = decodeDouble(value)

override fun decodeLong() = decodeLong(value)

Expand All @@ -60,15 +61,15 @@ class FirebaseDecoder(internal val value: Any?, private val decodeDouble: (value
override fun decodeNull() = decodeNull(value)

@ExperimentalSerializationApi
override fun decodeInline(inlineDescriptor: SerialDescriptor) = FirebaseDecoder(value, decodeDouble)
override fun decodeInline(inlineDescriptor: SerialDescriptor) = FirebaseDecoder(value)
}

class FirebaseClassDecoder(
decodeDouble: (value: Any?) -> Double?,
size: Int,
private val containsKey: (name: String) -> Boolean,
getDecoder: (Any?)->FirebaseDecoder,
get: (descriptor: SerialDescriptor, index: Int) -> Any?
) : FirebaseCompositeDecoder(decodeDouble, size, get) {
) : FirebaseCompositeDecoder(size, getDecoder, get) {
private var index: Int = 0

override fun decodeSequentially() = false
Expand All @@ -81,8 +82,8 @@ class FirebaseClassDecoder(
}

open class FirebaseCompositeDecoder constructor(
private val decodeDouble: (value: Any?) -> Double?,
private val size: Int,
private val getDecoder: (Any?)->FirebaseDecoder,
private val get: (descriptor: SerialDescriptor, index: Int) -> Any?
): CompositeDecoder {

Expand All @@ -99,15 +100,15 @@ open class FirebaseCompositeDecoder constructor(
index: Int,
deserializer: DeserializationStrategy<T>,
previousValue: T?
) = deserializer.deserialize(FirebaseDecoder(get(descriptor, index), decodeDouble))
) = deserializer.deserialize(getDecoder(get(descriptor, index)))

override fun decodeBooleanElement(descriptor: SerialDescriptor, index: Int) = decodeBoolean(get(descriptor, index))

override fun decodeByteElement(descriptor: SerialDescriptor, index: Int) = decodeByte(get(descriptor, index))

override fun decodeCharElement(descriptor: SerialDescriptor, index: Int) = decodeChar(get(descriptor, index))

override fun decodeDoubleElement(descriptor: SerialDescriptor, index: Int) = decodeDouble(get(descriptor, index), decodeDouble)
override fun decodeDoubleElement(descriptor: SerialDescriptor, index: Int) = decodeDouble(get(descriptor, index))

override fun decodeFloatElement(descriptor: SerialDescriptor, index: Int) = decodeFloat(get(descriptor, index))

Expand All @@ -133,15 +134,15 @@ open class FirebaseCompositeDecoder constructor(

@ExperimentalSerializationApi
override fun decodeInlineElement(descriptor: SerialDescriptor, index: Int): Decoder =
FirebaseDecoder(get(descriptor, index), decodeDouble)
getDecoder(get(descriptor, index))
}

private fun decodeString(value: Any?) = value.toString()

private fun decodeDouble(value: Any?, decodeDouble: (value: Any?) -> Double?) = when(value) {
private fun decodeDouble(value: Any?) = when(value) {
is Number -> value.toDouble()
is String -> value.toDouble()
else -> decodeDouble(value) ?: throw SerializationException("Expected $value to be double")
else -> throw SerializationException("Expected $value to be double")
}

private fun decodeLong(value: Any?) = when(value) {
Expand Down
Loading