diff --git a/firebase-auth/src/iosMain/kotlin/dev/gitlive/firebase/auth/auth.kt b/firebase-auth/src/iosMain/kotlin/dev/gitlive/firebase/auth/auth.kt index b659b0c68..30cbc9cf0 100644 --- a/firebase-auth/src/iosMain/kotlin/dev/gitlive/firebase/auth/auth.kt +++ b/firebase-auth/src/iosMain/kotlin/dev/gitlive/firebase/auth/auth.kt @@ -31,7 +31,7 @@ public actual fun Firebase.auth(app: FirebaseApp): FirebaseAuth = FirebaseAuth( public actual class FirebaseAuth internal constructor(internal val ios: FIRAuth) { public actual val currentUser: FirebaseUser? - get() = ios.currentUser?.let { FirebaseUser(it) } + get() = ios.currentUser()?.let { FirebaseUser(it) } public actual val authStateChanged: Flow get() = callbackFlow { val handle = ios.addAuthStateDidChangeListener { _, user -> trySend(user?.let { FirebaseUser(it) }) } @@ -44,7 +44,7 @@ public actual class FirebaseAuth internal constructor(internal val ios: FIRAuth) } public actual var languageCode: String - get() = ios.languageCode ?: "" + get() = ios.languageCode() ?: "" set(value) { ios.setLanguageCode(value) } @@ -90,15 +90,15 @@ public actual class FirebaseAuth internal constructor(internal val ios: FIRAuth) public actual suspend fun checkActionCode(code: String): T { val result: FIRActionCodeInfo = ios.awaitResult { checkActionCode(code, it) } @Suppress("UNCHECKED_CAST") - return when (result.operation) { + return when (result.operation()) { FIRActionCodeOperationEmailLink -> SignInWithEmailLink - FIRActionCodeOperationVerifyEmail -> VerifyEmail(result.email!!) - FIRActionCodeOperationPasswordReset -> PasswordReset(result.email!!) - FIRActionCodeOperationRecoverEmail -> RecoverEmail(result.email!!, result.previousEmail!!) - FIRActionCodeOperationVerifyAndChangeEmail -> VerifyBeforeChangeEmail(result.email!!, result.previousEmail!!) - FIRActionCodeOperationRevertSecondFactorAddition -> RevertSecondFactorAddition(result.email!!, null) - FIRActionCodeOperationUnknown -> throw UnsupportedOperationException(result.operation.toString()) - else -> throw UnsupportedOperationException(result.operation.toString()) + FIRActionCodeOperationVerifyEmail -> VerifyEmail(result.email()) + FIRActionCodeOperationPasswordReset -> PasswordReset(result.email()) + FIRActionCodeOperationRecoverEmail -> RecoverEmail(result.email(), result.previousEmail()!!) + FIRActionCodeOperationVerifyAndChangeEmail -> VerifyBeforeChangeEmail(result.email(), result.previousEmail()!!) + FIRActionCodeOperationRevertSecondFactorAddition -> RevertSecondFactorAddition(result.email(), null) + FIRActionCodeOperationUnknown -> throw UnsupportedOperationException(result.operation().toString()) + else -> throw UnsupportedOperationException(result.operation().toString()) } as T } @@ -108,7 +108,7 @@ public val AuthResult.ios: FIRAuthDataResult get() = ios public actual class AuthResult internal constructor(internal val ios: FIRAuthDataResult) { public actual val user: FirebaseUser? - get() = FirebaseUser(ios.user) + get() = FirebaseUser(ios.user()) } public val AuthTokenResult.ios: FIRAuthTokenResult get() = ios @@ -116,23 +116,23 @@ public actual class AuthTokenResult(internal val ios: FIRAuthTokenResult) { // actual val authTimestamp: Long // get() = ios.authDate public actual val claims: Map - get() = ios.claims.map { it.key.toString() to it.value as Any }.toMap() + get() = ios.claims().map { it.key.toString() to it.value as Any }.toMap() // actual val expirationTimestamp: Long // get() = ios.expirationDate // actual val issuedAtTimestamp: Long // get() = ios.issuedAtDate public actual val signInProvider: String? - get() = ios.signInProvider + get() = ios.signInProvider() public actual val token: String? - get() = ios.token + get() = ios.token() } internal fun ActionCodeSettings.toIos() = FIRActionCodeSettings().also { - it.URL = NSURL.URLWithString(url) + it.setURL(NSURL.URLWithString(url)) androidPackageName?.run { it.setAndroidPackageName(packageName, installIfNotAvailable, minimumVersion) } - it.dynamicLinkDomain = dynamicLinkDomain - it.handleCodeInApp = canHandleCodeInApp + it.setDynamicLinkDomain(dynamicLinkDomain) + it.setHandleCodeInApp(canHandleCodeInApp) iOSBundleId?.run { it.setIOSBundleID(this) } } @@ -184,47 +184,55 @@ internal suspend inline fun T.await(function: T.(callback: (NSError?) -> Uni } private fun NSError.toException() = when (domain) { + // codes from AuthErrors.swift: https://github.com/firebase/firebase-ios-sdk/blob/ + // 2f6ac4c2c61cd57c7ea727009e187b7e1163d613/FirebaseAuth/Sources/Swift/Utilities/ + // AuthErrors.swift#L51 FIRAuthErrorDomain -> when (code) { - FIRAuthErrorCodeInvalidActionCode, - FIRAuthErrorCodeExpiredActionCode, + 17030L, // AuthErrorCode.invalidActionCode + 17029L, // AuthErrorCode.expiredActionCode -> FirebaseAuthActionCodeException(toString()) - FIRAuthErrorCodeInvalidEmail -> FirebaseAuthEmailException(toString()) - - FIRAuthErrorCodeCaptchaCheckFailed, - FIRAuthErrorCodeInvalidPhoneNumber, - FIRAuthErrorCodeMissingPhoneNumber, - FIRAuthErrorCodeInvalidVerificationID, - FIRAuthErrorCodeInvalidVerificationCode, - FIRAuthErrorCodeMissingVerificationID, - FIRAuthErrorCodeMissingVerificationCode, - FIRAuthErrorCodeUserTokenExpired, - FIRAuthErrorCodeInvalidCredential, + 17008L, // AuthErrorCode.invalidEmail + -> FirebaseAuthEmailException(toString()) + + 17056L, // AuthErrorCode.captchaCheckFailed + 17042L, // AuthErrorCode.invalidPhoneNumber + 17041L, // AuthErrorCode.missingPhoneNumber + 17046L, // AuthErrorCode.invalidVerificationID + 17044L, // AuthErrorCode.invalidVerificationCode + 17045L, // AuthErrorCode.missingVerificationID + 17043L, // AuthErrorCode.missingVerificationCode + 17021L, // AuthErrorCode.userTokenExpired + 17004L, // AuthErrorCode.invalidCredential -> FirebaseAuthInvalidCredentialsException(toString()) - FIRAuthErrorCodeWeakPassword -> FirebaseAuthWeakPasswordException(toString()) + 17026L, // AuthErrorCode.weakPassword + -> FirebaseAuthWeakPasswordException(toString()) - FIRAuthErrorCodeInvalidUserToken -> FirebaseAuthInvalidUserException(toString()) + 17017L, // AuthErrorCode.invalidUserToken + -> FirebaseAuthInvalidUserException(toString()) - FIRAuthErrorCodeRequiresRecentLogin -> FirebaseAuthRecentLoginRequiredException(toString()) + 17014L, // AuthErrorCode.requiresRecentLogin + -> FirebaseAuthRecentLoginRequiredException(toString()) - FIRAuthErrorCodeSecondFactorAlreadyEnrolled, - FIRAuthErrorCodeSecondFactorRequired, - FIRAuthErrorCodeMaximumSecondFactorCountExceeded, - FIRAuthErrorCodeMultiFactorInfoNotFound, + 17087L, // AuthErrorCode.secondFactorAlreadyEnrolled + 17078L, // AuthErrorCode.secondFactorRequired + 17088L, // AuthErrorCode.maximumSecondFactorCountExceeded + 17084L, // AuthErrorCode.multiFactorInfoNotFound -> FirebaseAuthMultiFactorException(toString()) - FIRAuthErrorCodeEmailAlreadyInUse, - FIRAuthErrorCodeAccountExistsWithDifferentCredential, - FIRAuthErrorCodeCredentialAlreadyInUse, + 17007L, // AuthErrorCode.emailAlreadyInUse + 17012L, // AuthErrorCode.accountExistsWithDifferentCredential + 17025L, // AuthErrorCode.credentialAlreadyInUse -> FirebaseAuthUserCollisionException(toString()) - FIRAuthErrorCodeWebContextAlreadyPresented, - FIRAuthErrorCodeWebContextCancelled, - FIRAuthErrorCodeWebInternalError, + 17057L, // AuthErrorCode.webContextAlreadyPresented + 17058L, // AuthErrorCode.webContextCancelled + 17062L, // AuthErrorCode.webInternalError -> FirebaseAuthWebException(toString()) - FIRAuthErrorCodeNetworkError -> FirebaseNetworkException(toString()) + 17020L, // AuthErrorCode.networkError + -> FirebaseNetworkException(toString()) else -> FirebaseAuthException(toString()) } diff --git a/firebase-auth/src/iosMain/kotlin/dev/gitlive/firebase/auth/credentials.kt b/firebase-auth/src/iosMain/kotlin/dev/gitlive/firebase/auth/credentials.kt index 08387a0e1..5a2084bb9 100644 --- a/firebase-auth/src/iosMain/kotlin/dev/gitlive/firebase/auth/credentials.kt +++ b/firebase-auth/src/iosMain/kotlin/dev/gitlive/firebase/auth/credentials.kt @@ -8,7 +8,7 @@ import cocoapods.FirebaseAuth.* public actual open class AuthCredential(public open val ios: FIRAuthCredential) { public actual val providerId: String - get() = ios.provider + get() = ios.provider() } public actual class PhoneAuthCredential(override val ios: FIRPhoneAuthCredential) : AuthCredential(ios) diff --git a/firebase-auth/src/iosMain/kotlin/dev/gitlive/firebase/auth/multifactor.kt b/firebase-auth/src/iosMain/kotlin/dev/gitlive/firebase/auth/multifactor.kt index f389b6abb..3d2c814e5 100644 --- a/firebase-auth/src/iosMain/kotlin/dev/gitlive/firebase/auth/multifactor.kt +++ b/firebase-auth/src/iosMain/kotlin/dev/gitlive/firebase/auth/multifactor.kt @@ -10,7 +10,7 @@ public val MultiFactor.ios: FIRMultiFactor get() = ios public actual class MultiFactor(internal val ios: FIRMultiFactor) { public actual val enrolledFactors: List - get() = ios.enrolledFactors.mapNotNull { info -> (info as? FIRMultiFactorInfo)?.let { MultiFactorInfo(it) } } + get() = ios.enrolledFactors().mapNotNull { info -> (info as? FIRMultiFactorInfo)?.let { MultiFactorInfo(it) } } public actual suspend fun enroll(multiFactorAssertion: MultiFactorAssertion, displayName: String?): Unit = ios.await { enrollWithAssertion(multiFactorAssertion.ios, displayName, it) } public actual suspend fun getSession(): MultiFactorSession = MultiFactorSession(ios.awaitResult { getSessionWithCompletion(completion = it) }) public actual suspend fun unenroll(multiFactorInfo: MultiFactorInfo): Unit = ios.await { unenrollWithInfo(multiFactorInfo.ios, it) } @@ -21,20 +21,20 @@ public val MultiFactorInfo.ios: FIRMultiFactorInfo get() = ios public actual class MultiFactorInfo(internal val ios: FIRMultiFactorInfo) { public actual val displayName: String? - get() = ios.displayName + get() = ios.displayName() public actual val enrollmentTime: Double - get() = ios.enrollmentDate.timeIntervalSinceReferenceDate + get() = ios.enrollmentDate().timeIntervalSinceReferenceDate public actual val factorId: String - get() = ios.factorID + get() = ios.factorID() public actual val uid: String - get() = ios.UID + get() = ios.UID() } public val MultiFactorAssertion.ios: FIRMultiFactorAssertion get() = ios public actual class MultiFactorAssertion(internal val ios: FIRMultiFactorAssertion) { public actual val factorId: String - get() = ios.factorID + get() = ios.factorID() } public val MultiFactorSession.ios: FIRMultiFactorSession get() = ios @@ -44,9 +44,9 @@ public actual class MultiFactorSession(internal val ios: FIRMultiFactorSession) public val MultiFactorResolver.ios: FIRMultiFactorResolver get() = ios public actual class MultiFactorResolver(internal val ios: FIRMultiFactorResolver) { - public actual val auth: FirebaseAuth = FirebaseAuth(ios.auth) - public actual val hints: List = ios.hints.mapNotNull { hint -> (hint as? FIRMultiFactorInfo)?.let { MultiFactorInfo(it) } } - public actual val session: MultiFactorSession = MultiFactorSession(ios.session) + public actual val auth: FirebaseAuth = FirebaseAuth(ios.auth()) + public actual val hints: List = ios.hints().mapNotNull { hint -> (hint as? FIRMultiFactorInfo)?.let { MultiFactorInfo(it) } } + public actual val session: MultiFactorSession = MultiFactorSession(ios.session()) public actual suspend fun resolveSignIn(assertion: MultiFactorAssertion): AuthResult = AuthResult(ios.awaitResult { resolveSignInWithAssertion(assertion.ios, it) }) } diff --git a/firebase-auth/src/iosMain/kotlin/dev/gitlive/firebase/auth/user.kt b/firebase-auth/src/iosMain/kotlin/dev/gitlive/firebase/auth/user.kt index f2f6c67cc..d37fc20c0 100644 --- a/firebase-auth/src/iosMain/kotlin/dev/gitlive/firebase/auth/user.kt +++ b/firebase-auth/src/iosMain/kotlin/dev/gitlive/firebase/auth/user.kt @@ -14,27 +14,27 @@ public val FirebaseUser.ios: FIRUser get() = ios public actual class FirebaseUser internal constructor(internal val ios: FIRUser) { public actual val uid: String - get() = ios.uid + get() = ios.uid() public actual val displayName: String? - get() = ios.displayName + get() = ios.displayName() public actual val email: String? - get() = ios.email + get() = ios.email() public actual val phoneNumber: String? - get() = ios.phoneNumber + get() = ios.phoneNumber() public actual val photoURL: String? - get() = ios.photoURL?.absoluteString + get() = ios.photoURL()?.absoluteString public actual val isAnonymous: Boolean - get() = ios.anonymous + get() = ios.anonymous() public actual val isEmailVerified: Boolean - get() = ios.emailVerified + get() = ios.emailVerified() public actual val metaData: UserMetaData? - get() = UserMetaData(ios.metadata) + get() = UserMetaData(ios.metadata()) public actual val multiFactor: MultiFactor - get() = MultiFactor(ios.multiFactor) + get() = MultiFactor(ios.multiFactor()) public actual val providerData: List - get() = ios.providerData.mapNotNull { provider -> (provider as? FIRUserInfoProtocol)?.let { UserInfo(it) } } + get() = ios.providerData().mapNotNull { provider -> (provider as? FIRUserInfoProtocol)?.let { UserInfo(it) } } public actual val providerId: String - get() = ios.providerID + get() = ios.providerID() public actual suspend fun delete(): Unit = ios.await { deleteWithCompletion(it) } @@ -85,24 +85,24 @@ public val UserInfo.ios: FIRUserInfoProtocol get() = ios public actual class UserInfo(internal val ios: FIRUserInfoProtocol) { public actual val displayName: String? - get() = ios.displayName + get() = ios.displayName() public actual val email: String? - get() = ios.email + get() = ios.email() public actual val phoneNumber: String? - get() = ios.phoneNumber + get() = ios.phoneNumber() public actual val photoURL: String? - get() = ios.photoURL?.absoluteString + get() = ios.photoURL()?.absoluteString public actual val providerId: String - get() = ios.providerID + get() = ios.providerID() public actual val uid: String - get() = ios.uid + get() = ios.uid() } public val UserMetaData.ios: FIRUserMetadata get() = ios public actual class UserMetaData(internal val ios: FIRUserMetadata) { public actual val creationTime: Double? - get() = ios.creationDate?.timeIntervalSinceReferenceDate + get() = ios.creationDate()?.timeIntervalSinceReferenceDate public actual val lastSignInTime: Double? - get() = ios.lastSignInDate?.timeIntervalSinceReferenceDate + get() = ios.lastSignInDate()?.timeIntervalSinceReferenceDate } diff --git a/firebase-common-internal/api/android/firebase-common-internal.api b/firebase-common-internal/api/android/firebase-common-internal.api index 44393d3b9..49e83fd95 100644 --- a/firebase-common-internal/api/android/firebase-common-internal.api +++ b/firebase-common-internal/api/android/firebase-common-internal.api @@ -78,59 +78,9 @@ public final class dev/gitlive/firebase/internal/EncodersKt { public static final fun encode (Lkotlinx/serialization/SerializationStrategy;Ljava/lang/Object;Z)Ljava/lang/Object; public static final fun encodeAsObject (Lkotlinx/serialization/SerializationStrategy;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ldev/gitlive/firebase/internal/EncodedObject; public static synthetic fun encodeAsObject$default (Lkotlinx/serialization/SerializationStrategy;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ldev/gitlive/firebase/internal/EncodedObject; - public static final fun withSerializer (Ljava/lang/Object;Lkotlinx/serialization/SerializationStrategy;)Ljava/lang/Object; -} - -public final class dev/gitlive/firebase/internal/FirebaseClassDecoder : dev/gitlive/firebase/internal/FirebaseCompositeDecoder { - public fun (ILdev/gitlive/firebase/DecodeSettings;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)V - public fun decodeElementIndex (Lkotlinx/serialization/descriptors/SerialDescriptor;)I - public fun decodeSequentially ()Z -} - -public class dev/gitlive/firebase/internal/FirebaseCompositeDecoder : kotlinx/serialization/encoding/CompositeDecoder { - public fun (ILdev/gitlive/firebase/DecodeSettings;Lkotlin/jvm/functions/Function2;)V - public fun decodeBooleanElement (Lkotlinx/serialization/descriptors/SerialDescriptor;I)Z - public fun decodeByteElement (Lkotlinx/serialization/descriptors/SerialDescriptor;I)B - public fun decodeCharElement (Lkotlinx/serialization/descriptors/SerialDescriptor;I)C - public fun decodeCollectionSize (Lkotlinx/serialization/descriptors/SerialDescriptor;)I - public fun decodeDoubleElement (Lkotlinx/serialization/descriptors/SerialDescriptor;I)D - public fun decodeElementIndex (Lkotlinx/serialization/descriptors/SerialDescriptor;)I - public fun decodeFloatElement (Lkotlinx/serialization/descriptors/SerialDescriptor;I)F - public fun decodeInlineElement (Lkotlinx/serialization/descriptors/SerialDescriptor;I)Lkotlinx/serialization/encoding/Decoder; - public fun decodeIntElement (Lkotlinx/serialization/descriptors/SerialDescriptor;I)I - public fun decodeLongElement (Lkotlinx/serialization/descriptors/SerialDescriptor;I)J - public fun decodeNullableSerializableElement (Lkotlinx/serialization/descriptors/SerialDescriptor;ILkotlinx/serialization/DeserializationStrategy;Ljava/lang/Object;)Ljava/lang/Object; - public fun decodeSequentially ()Z - public fun decodeSerializableElement (Lkotlinx/serialization/descriptors/SerialDescriptor;ILkotlinx/serialization/DeserializationStrategy;Ljava/lang/Object;)Ljava/lang/Object; - public fun decodeShortElement (Lkotlinx/serialization/descriptors/SerialDescriptor;I)S - public fun decodeStringElement (Lkotlinx/serialization/descriptors/SerialDescriptor;I)Ljava/lang/String; - public fun endStructure (Lkotlinx/serialization/descriptors/SerialDescriptor;)V - public fun getSerializersModule ()Lkotlinx/serialization/modules/SerializersModule; -} - -public class dev/gitlive/firebase/internal/FirebaseCompositeEncoder : kotlinx/serialization/encoding/CompositeEncoder { - public fun (Ldev/gitlive/firebase/EncodeSettings;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;)V - public synthetic fun (Ldev/gitlive/firebase/EncodeSettings;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;ILkotlin/jvm/internal/DefaultConstructorMarker;)V - public fun encodeBooleanElement (Lkotlinx/serialization/descriptors/SerialDescriptor;IZ)V - public fun encodeByteElement (Lkotlinx/serialization/descriptors/SerialDescriptor;IB)V - public fun encodeCharElement (Lkotlinx/serialization/descriptors/SerialDescriptor;IC)V - public fun encodeDoubleElement (Lkotlinx/serialization/descriptors/SerialDescriptor;ID)V - public fun encodeFloatElement (Lkotlinx/serialization/descriptors/SerialDescriptor;IF)V - public fun encodeInlineElement (Lkotlinx/serialization/descriptors/SerialDescriptor;I)Lkotlinx/serialization/encoding/Encoder; - public fun encodeIntElement (Lkotlinx/serialization/descriptors/SerialDescriptor;II)V - public fun encodeLongElement (Lkotlinx/serialization/descriptors/SerialDescriptor;IJ)V - public fun encodeNullableSerializableElement (Lkotlinx/serialization/descriptors/SerialDescriptor;ILkotlinx/serialization/SerializationStrategy;Ljava/lang/Object;)V - public final fun encodeObject (Lkotlinx/serialization/descriptors/SerialDescriptor;ILjava/lang/Object;)V - public final fun encodePolymorphicClassDiscriminator (Ljava/lang/String;Ljava/lang/String;)V - public fun encodeSerializableElement (Lkotlinx/serialization/descriptors/SerialDescriptor;ILkotlinx/serialization/SerializationStrategy;Ljava/lang/Object;)V - public fun encodeShortElement (Lkotlinx/serialization/descriptors/SerialDescriptor;IS)V - public fun encodeStringElement (Lkotlinx/serialization/descriptors/SerialDescriptor;ILjava/lang/String;)V - public fun endStructure (Lkotlinx/serialization/descriptors/SerialDescriptor;)V - public fun getSerializersModule ()Lkotlinx/serialization/modules/SerializersModule; - public fun shouldEncodeElementDefault (Lkotlinx/serialization/descriptors/SerialDescriptor;I)Z } -public final class dev/gitlive/firebase/internal/FirebaseDecoder : kotlinx/serialization/encoding/Decoder { +public final class dev/gitlive/firebase/internal/FirebaseDecoderImpl : dev/gitlive/firebase/FirebaseDecoder { public fun (Ljava/lang/Object;)V public fun (Ljava/lang/Object;Ldev/gitlive/firebase/DecodeSettings;)V public fun beginStructure (Lkotlinx/serialization/descriptors/SerialDescriptor;)Lkotlinx/serialization/encoding/CompositeDecoder; @@ -153,7 +103,7 @@ public final class dev/gitlive/firebase/internal/FirebaseDecoder : kotlinx/seria public final fun getValue ()Ljava/lang/Object; } -public final class dev/gitlive/firebase/internal/FirebaseEncoder : kotlinx/serialization/encoding/Encoder { +public final class dev/gitlive/firebase/internal/FirebaseEncoderImpl : dev/gitlive/firebase/FirebaseEncoder { public fun (Ldev/gitlive/firebase/EncodeSettings;)V public fun (Z)V public fun beginCollection (Lkotlinx/serialization/descriptors/SerialDescriptor;I)Lkotlinx/serialization/encoding/CompositeEncoder; @@ -217,25 +167,3 @@ public final class dev/gitlive/firebase/internal/SpecialValueSerializer : kotlin public fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V } -public final class dev/gitlive/firebase/internal/ValueWithSerializer { - public fun (Ljava/lang/Object;Lkotlinx/serialization/SerializationStrategy;)V - public final fun component1 ()Ljava/lang/Object; - public final fun component2 ()Lkotlinx/serialization/SerializationStrategy; - public final fun copy (Ljava/lang/Object;Lkotlinx/serialization/SerializationStrategy;)Ldev/gitlive/firebase/internal/ValueWithSerializer; - public static synthetic fun copy$default (Ldev/gitlive/firebase/internal/ValueWithSerializer;Ljava/lang/Object;Lkotlinx/serialization/SerializationStrategy;ILjava/lang/Object;)Ldev/gitlive/firebase/internal/ValueWithSerializer; - public fun equals (Ljava/lang/Object;)Z - public final fun getSerializer ()Lkotlinx/serialization/SerializationStrategy; - public final fun getValue ()Ljava/lang/Object; - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class dev/gitlive/firebase/internal/_decodersKt { - public static final fun getPolymorphicType (Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/String; - public static final fun structureDecoder (Ldev/gitlive/firebase/internal/FirebaseDecoder;Lkotlinx/serialization/descriptors/SerialDescriptor;Z)Lkotlinx/serialization/encoding/CompositeDecoder; -} - -public final class dev/gitlive/firebase/internal/_encodersKt { - public static final fun structureEncoder (Ldev/gitlive/firebase/internal/FirebaseEncoder;Lkotlinx/serialization/descriptors/SerialDescriptor;)Ldev/gitlive/firebase/internal/FirebaseCompositeEncoder; -} - diff --git a/firebase-common-internal/api/jvm/firebase-common-internal.api b/firebase-common-internal/api/jvm/firebase-common-internal.api index 44393d3b9..49e83fd95 100644 --- a/firebase-common-internal/api/jvm/firebase-common-internal.api +++ b/firebase-common-internal/api/jvm/firebase-common-internal.api @@ -78,59 +78,9 @@ public final class dev/gitlive/firebase/internal/EncodersKt { public static final fun encode (Lkotlinx/serialization/SerializationStrategy;Ljava/lang/Object;Z)Ljava/lang/Object; public static final fun encodeAsObject (Lkotlinx/serialization/SerializationStrategy;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ldev/gitlive/firebase/internal/EncodedObject; public static synthetic fun encodeAsObject$default (Lkotlinx/serialization/SerializationStrategy;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ldev/gitlive/firebase/internal/EncodedObject; - public static final fun withSerializer (Ljava/lang/Object;Lkotlinx/serialization/SerializationStrategy;)Ljava/lang/Object; -} - -public final class dev/gitlive/firebase/internal/FirebaseClassDecoder : dev/gitlive/firebase/internal/FirebaseCompositeDecoder { - public fun (ILdev/gitlive/firebase/DecodeSettings;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)V - public fun decodeElementIndex (Lkotlinx/serialization/descriptors/SerialDescriptor;)I - public fun decodeSequentially ()Z -} - -public class dev/gitlive/firebase/internal/FirebaseCompositeDecoder : kotlinx/serialization/encoding/CompositeDecoder { - public fun (ILdev/gitlive/firebase/DecodeSettings;Lkotlin/jvm/functions/Function2;)V - public fun decodeBooleanElement (Lkotlinx/serialization/descriptors/SerialDescriptor;I)Z - public fun decodeByteElement (Lkotlinx/serialization/descriptors/SerialDescriptor;I)B - public fun decodeCharElement (Lkotlinx/serialization/descriptors/SerialDescriptor;I)C - public fun decodeCollectionSize (Lkotlinx/serialization/descriptors/SerialDescriptor;)I - public fun decodeDoubleElement (Lkotlinx/serialization/descriptors/SerialDescriptor;I)D - public fun decodeElementIndex (Lkotlinx/serialization/descriptors/SerialDescriptor;)I - public fun decodeFloatElement (Lkotlinx/serialization/descriptors/SerialDescriptor;I)F - public fun decodeInlineElement (Lkotlinx/serialization/descriptors/SerialDescriptor;I)Lkotlinx/serialization/encoding/Decoder; - public fun decodeIntElement (Lkotlinx/serialization/descriptors/SerialDescriptor;I)I - public fun decodeLongElement (Lkotlinx/serialization/descriptors/SerialDescriptor;I)J - public fun decodeNullableSerializableElement (Lkotlinx/serialization/descriptors/SerialDescriptor;ILkotlinx/serialization/DeserializationStrategy;Ljava/lang/Object;)Ljava/lang/Object; - public fun decodeSequentially ()Z - public fun decodeSerializableElement (Lkotlinx/serialization/descriptors/SerialDescriptor;ILkotlinx/serialization/DeserializationStrategy;Ljava/lang/Object;)Ljava/lang/Object; - public fun decodeShortElement (Lkotlinx/serialization/descriptors/SerialDescriptor;I)S - public fun decodeStringElement (Lkotlinx/serialization/descriptors/SerialDescriptor;I)Ljava/lang/String; - public fun endStructure (Lkotlinx/serialization/descriptors/SerialDescriptor;)V - public fun getSerializersModule ()Lkotlinx/serialization/modules/SerializersModule; -} - -public class dev/gitlive/firebase/internal/FirebaseCompositeEncoder : kotlinx/serialization/encoding/CompositeEncoder { - public fun (Ldev/gitlive/firebase/EncodeSettings;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;)V - public synthetic fun (Ldev/gitlive/firebase/EncodeSettings;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;ILkotlin/jvm/internal/DefaultConstructorMarker;)V - public fun encodeBooleanElement (Lkotlinx/serialization/descriptors/SerialDescriptor;IZ)V - public fun encodeByteElement (Lkotlinx/serialization/descriptors/SerialDescriptor;IB)V - public fun encodeCharElement (Lkotlinx/serialization/descriptors/SerialDescriptor;IC)V - public fun encodeDoubleElement (Lkotlinx/serialization/descriptors/SerialDescriptor;ID)V - public fun encodeFloatElement (Lkotlinx/serialization/descriptors/SerialDescriptor;IF)V - public fun encodeInlineElement (Lkotlinx/serialization/descriptors/SerialDescriptor;I)Lkotlinx/serialization/encoding/Encoder; - public fun encodeIntElement (Lkotlinx/serialization/descriptors/SerialDescriptor;II)V - public fun encodeLongElement (Lkotlinx/serialization/descriptors/SerialDescriptor;IJ)V - public fun encodeNullableSerializableElement (Lkotlinx/serialization/descriptors/SerialDescriptor;ILkotlinx/serialization/SerializationStrategy;Ljava/lang/Object;)V - public final fun encodeObject (Lkotlinx/serialization/descriptors/SerialDescriptor;ILjava/lang/Object;)V - public final fun encodePolymorphicClassDiscriminator (Ljava/lang/String;Ljava/lang/String;)V - public fun encodeSerializableElement (Lkotlinx/serialization/descriptors/SerialDescriptor;ILkotlinx/serialization/SerializationStrategy;Ljava/lang/Object;)V - public fun encodeShortElement (Lkotlinx/serialization/descriptors/SerialDescriptor;IS)V - public fun encodeStringElement (Lkotlinx/serialization/descriptors/SerialDescriptor;ILjava/lang/String;)V - public fun endStructure (Lkotlinx/serialization/descriptors/SerialDescriptor;)V - public fun getSerializersModule ()Lkotlinx/serialization/modules/SerializersModule; - public fun shouldEncodeElementDefault (Lkotlinx/serialization/descriptors/SerialDescriptor;I)Z } -public final class dev/gitlive/firebase/internal/FirebaseDecoder : kotlinx/serialization/encoding/Decoder { +public final class dev/gitlive/firebase/internal/FirebaseDecoderImpl : dev/gitlive/firebase/FirebaseDecoder { public fun (Ljava/lang/Object;)V public fun (Ljava/lang/Object;Ldev/gitlive/firebase/DecodeSettings;)V public fun beginStructure (Lkotlinx/serialization/descriptors/SerialDescriptor;)Lkotlinx/serialization/encoding/CompositeDecoder; @@ -153,7 +103,7 @@ public final class dev/gitlive/firebase/internal/FirebaseDecoder : kotlinx/seria public final fun getValue ()Ljava/lang/Object; } -public final class dev/gitlive/firebase/internal/FirebaseEncoder : kotlinx/serialization/encoding/Encoder { +public final class dev/gitlive/firebase/internal/FirebaseEncoderImpl : dev/gitlive/firebase/FirebaseEncoder { public fun (Ldev/gitlive/firebase/EncodeSettings;)V public fun (Z)V public fun beginCollection (Lkotlinx/serialization/descriptors/SerialDescriptor;I)Lkotlinx/serialization/encoding/CompositeEncoder; @@ -217,25 +167,3 @@ public final class dev/gitlive/firebase/internal/SpecialValueSerializer : kotlin public fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V } -public final class dev/gitlive/firebase/internal/ValueWithSerializer { - public fun (Ljava/lang/Object;Lkotlinx/serialization/SerializationStrategy;)V - public final fun component1 ()Ljava/lang/Object; - public final fun component2 ()Lkotlinx/serialization/SerializationStrategy; - public final fun copy (Ljava/lang/Object;Lkotlinx/serialization/SerializationStrategy;)Ldev/gitlive/firebase/internal/ValueWithSerializer; - public static synthetic fun copy$default (Ldev/gitlive/firebase/internal/ValueWithSerializer;Ljava/lang/Object;Lkotlinx/serialization/SerializationStrategy;ILjava/lang/Object;)Ldev/gitlive/firebase/internal/ValueWithSerializer; - public fun equals (Ljava/lang/Object;)Z - public final fun getSerializer ()Lkotlinx/serialization/SerializationStrategy; - public final fun getValue ()Ljava/lang/Object; - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class dev/gitlive/firebase/internal/_decodersKt { - public static final fun getPolymorphicType (Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/String; - public static final fun structureDecoder (Ldev/gitlive/firebase/internal/FirebaseDecoder;Lkotlinx/serialization/descriptors/SerialDescriptor;Z)Lkotlinx/serialization/encoding/CompositeDecoder; -} - -public final class dev/gitlive/firebase/internal/_encodersKt { - public static final fun structureEncoder (Ldev/gitlive/firebase/internal/FirebaseEncoder;Lkotlinx/serialization/descriptors/SerialDescriptor;)Ldev/gitlive/firebase/internal/FirebaseCompositeEncoder; -} - diff --git a/firebase-common-internal/src/androidMain/kotlin/dev/gitlive/firebase/internal/_decoders.kt b/firebase-common-internal/src/androidMain/kotlin/dev/gitlive/firebase/internal/_decoders.kt index 77644ccfe..4b477364c 100644 --- a/firebase-common-internal/src/androidMain/kotlin/dev/gitlive/firebase/internal/_decoders.kt +++ b/firebase-common-internal/src/androidMain/kotlin/dev/gitlive/firebase/internal/_decoders.kt @@ -9,7 +9,7 @@ import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.descriptors.StructureKind import kotlinx.serialization.encoding.CompositeDecoder -public actual fun FirebaseDecoder.structureDecoder(descriptor: SerialDescriptor, polymorphicIsNested: Boolean): CompositeDecoder = when (descriptor.kind) { +internal actual fun FirebaseDecoderImpl.structureDecoder(descriptor: SerialDescriptor, polymorphicIsNested: Boolean): CompositeDecoder = when (descriptor.kind) { StructureKind.CLASS, StructureKind.OBJECT -> decodeAsMap(false) StructureKind.LIST -> (value as? List<*>).orEmpty().let { FirebaseCompositeDecoder(it.size, settings) { _, index -> it[index] } @@ -26,10 +26,10 @@ public actual fun FirebaseDecoder.structureDecoder(descriptor: SerialDescriptor, else -> TODO("The firebase-kotlin-sdk does not support $descriptor for serialization yet") } -public actual fun getPolymorphicType(value: Any?, discriminator: String): String = +internal actual fun getPolymorphicType(value: Any?, discriminator: String): String = (value as? Map<*, *>).orEmpty()[discriminator] as String -private fun FirebaseDecoder.decodeAsMap(isNestedPolymorphic: Boolean): CompositeDecoder = (value as? Map<*, *>).orEmpty().let { map -> +private fun FirebaseDecoderImpl.decodeAsMap(isNestedPolymorphic: Boolean): CompositeDecoder = (value as? Map<*, *>).orEmpty().let { map -> FirebaseClassDecoder(map.size, settings, { map.containsKey(it) }) { desc, index -> if (isNestedPolymorphic) { if (desc.getElementName(index) == "value") { 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 e8d3aca10..eb7be3ba2 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 @@ -9,7 +9,7 @@ import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.descriptors.StructureKind import kotlin.collections.set -public actual fun FirebaseEncoder.structureEncoder(descriptor: SerialDescriptor): FirebaseCompositeEncoder = when (descriptor.kind) { +internal actual fun FirebaseEncoderImpl.structureEncoder(descriptor: SerialDescriptor): FirebaseCompositeEncoder = when (descriptor.kind) { StructureKind.LIST -> mutableListOf() .also { value = it } .let { FirebaseCompositeEncoder(settings) { _, index, value -> it.add(index, value) } } @@ -20,7 +20,7 @@ public actual fun FirebaseEncoder.structureEncoder(descriptor: SerialDescriptor) else -> TODO("The firebase-kotlin-sdk does not support $descriptor for serialization yet") } -private fun FirebaseEncoder.encodeAsMap(descriptor: SerialDescriptor): FirebaseCompositeEncoder = mutableMapOf() +private fun FirebaseEncoderImpl.encodeAsMap(descriptor: SerialDescriptor): FirebaseCompositeEncoder = mutableMapOf() .also { value = it } .let { FirebaseCompositeEncoder( diff --git a/firebase-common-internal/src/commonMain/kotlin/dev/gitlive/firebase/internal/Polymorphic.kt b/firebase-common-internal/src/commonMain/kotlin/dev/gitlive/firebase/internal/Polymorphic.kt index 77bb77dc7..2297be79b 100644 --- a/firebase-common-internal/src/commonMain/kotlin/dev/gitlive/firebase/internal/Polymorphic.kt +++ b/firebase-common-internal/src/commonMain/kotlin/dev/gitlive/firebase/internal/Polymorphic.kt @@ -12,7 +12,7 @@ import kotlinx.serialization.internal.AbstractPolymorphicSerializer * See https://github.com/Kotlin/kotlinx.serialization/blob/master/formats/json/commonMain/src/kotlinx/serialization/json/internal/Polymorphic.kt */ @Suppress("UNCHECKED_CAST") -internal fun FirebaseEncoder.encodePolymorphically( +internal fun FirebaseEncoderImpl.encodePolymorphically( serializer: SerializationStrategy, value: T, ifPolymorphic: (String) -> Unit, @@ -34,7 +34,7 @@ internal fun FirebaseEncoder.encodePolymorphically( } @Suppress("UNCHECKED_CAST") -internal fun FirebaseDecoder.decodeSerializableValuePolymorphic( +internal fun FirebaseDecoderImpl.decodeSerializableValuePolymorphic( value: Any?, deserializer: DeserializationStrategy, ): T { diff --git a/firebase-common-internal/src/commonMain/kotlin/dev/gitlive/firebase/internal/decoders.kt b/firebase-common-internal/src/commonMain/kotlin/dev/gitlive/firebase/internal/decoders.kt index 084bc4f62..27952ac7d 100644 --- a/firebase-common-internal/src/commonMain/kotlin/dev/gitlive/firebase/internal/decoders.kt +++ b/firebase-common-internal/src/commonMain/kotlin/dev/gitlive/firebase/internal/decoders.kt @@ -5,6 +5,7 @@ package dev.gitlive.firebase.internal import dev.gitlive.firebase.DecodeSettings +import dev.gitlive.firebase.FirebaseDecoder import kotlinx.serialization.DeserializationStrategy import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.SerializationException @@ -31,12 +32,13 @@ public inline fun decode(strategy: DeserializationStrategy, value: Any?, @PublishedApi internal fun decode(strategy: DeserializationStrategy, value: Any?, decodeSettings: DecodeSettings): T { require(value != null || strategy.descriptor.isNullable) { "Value was null for non-nullable type ${strategy.descriptor.serialName}" } - return FirebaseDecoder(value, decodeSettings).decodeSerializableValue(strategy) + return FirebaseDecoderImpl(value, decodeSettings).decodeSerializableValue(strategy) } -public expect fun FirebaseDecoder.structureDecoder(descriptor: SerialDescriptor, polymorphicIsNested: Boolean): CompositeDecoder -public expect fun getPolymorphicType(value: Any?, discriminator: String): String +internal expect fun FirebaseDecoderImpl.structureDecoder(descriptor: SerialDescriptor, polymorphicIsNested: Boolean): CompositeDecoder +internal expect fun getPolymorphicType(value: Any?, discriminator: String): String -public class FirebaseDecoder(public val value: Any?, internal val settings: DecodeSettings) : Decoder { +@PublishedApi +internal class FirebaseDecoderImpl(val value: Any?, internal val settings: DecodeSettings) : FirebaseDecoder { public constructor(value: Any?) : this(value, DecodeSettingsImpl()) @@ -68,12 +70,12 @@ public class FirebaseDecoder(public val value: Any?, internal val settings: Deco override fun decodeNull(): Nothing? = decodeNull(value) - override fun decodeInline(descriptor: SerialDescriptor): Decoder = FirebaseDecoder(value, settings) + override fun decodeInline(descriptor: SerialDescriptor): Decoder = FirebaseDecoderImpl(value, settings) override fun decodeSerializableValue(deserializer: DeserializationStrategy): T = decodeSerializableValuePolymorphic(value, deserializer) } -public class FirebaseClassDecoder( +internal class FirebaseClassDecoder( size: Int, settings: DecodeSettings, private val containsKey: (name: String) -> Boolean, @@ -91,7 +93,7 @@ public class FirebaseClassDecoder( ?: DECODE_DONE } -public open class FirebaseCompositeDecoder( +internal open class FirebaseCompositeDecoder( private val size: Int, internal val settings: DecodeSettings, private val get: (descriptor: SerialDescriptor, index: Int) -> Any?, @@ -111,7 +113,7 @@ public open class FirebaseCompositeDecoder( deserializer: DeserializationStrategy, previousValue: T?, ): T = decodeElement(descriptor, index) { - deserializer.deserialize(FirebaseDecoder(it, settings)) + deserializer.deserialize(FirebaseDecoderImpl(it, settings)) } override fun decodeBooleanElement(descriptor: SerialDescriptor, index: Int): Boolean = @@ -160,7 +162,7 @@ public open class FirebaseCompositeDecoder( @ExperimentalSerializationApi override fun decodeInlineElement(descriptor: SerialDescriptor, index: Int): Decoder = decodeElement(descriptor, index) { - FirebaseDecoder(it, settings) + FirebaseDecoderImpl(it, settings) } private fun decodeElement(descriptor: SerialDescriptor, index: Int, decoder: (Any?) -> T): T = try { 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 c6c9e4abf..767688ad0 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,6 +5,7 @@ package dev.gitlive.firebase.internal import dev.gitlive.firebase.EncodeSettings +import dev.gitlive.firebase.FirebaseEncoder import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.SerializationStrategy import kotlinx.serialization.descriptors.SerialDescriptor @@ -22,7 +23,7 @@ public inline fun encode(strategy: SerializationStrategy, value: T, build @PublishedApi internal fun encode(strategy: SerializationStrategy, value: T, encodeSettings: EncodeSettings): Any? = - FirebaseEncoder(encodeSettings).apply { encodeSerializableValue(strategy, value) }.value + FirebaseEncoderImpl(encodeSettings).apply { encodeSerializableValue(strategy, value) }.value @Deprecated("Deprecated. Use builder instead", replaceWith = ReplaceWith("encode(value) { this.encodeDefaults = shouldEncodeElementDefault }")) public inline fun encode(value: T, shouldEncodeElementDefault: Boolean): Any? = encode(value) { @@ -60,31 +61,17 @@ public inline fun encodeAsObject(value: T, buildSettings: Enco @PublishedApi internal inline fun encode(value: T, encodeSettings: EncodeSettings): Any? = value?.let { - FirebaseEncoder(encodeSettings).apply { - if (it is ValueWithSerializer<*> && it.value is T) { - @Suppress("UNCHECKED_CAST") - (it as ValueWithSerializer).let { - encodeSerializableValue(it.serializer, it.value) - } - } else { - encodeSerializableValue(it.firebaseSerializer(), it) - } + FirebaseEncoderImpl(encodeSettings).apply { + encodeSerializableValue(it.firebaseSerializer(), it) }.value } -/** - * An extension which which serializer to use for value. Handy in updating fields by name or path - * where using annotation is not possible - * @return a value with a custom serializer. - */ -public fun T.withSerializer(serializer: SerializationStrategy): Any = ValueWithSerializer(this, serializer) -public data class ValueWithSerializer(val value: T, val serializer: SerializationStrategy) - -public expect fun FirebaseEncoder.structureEncoder(descriptor: SerialDescriptor): FirebaseCompositeEncoder +internal expect fun FirebaseEncoderImpl.structureEncoder(descriptor: SerialDescriptor): FirebaseCompositeEncoder -public class FirebaseEncoder( +@PublishedApi +internal class FirebaseEncoderImpl( internal val settings: EncodeSettings, -) : Encoder { +) : FirebaseEncoder { public constructor(shouldEncodeElementDefault: Boolean) : this( EncodeSettingsImpl.Builder().apply { this.encodeDefaults = shouldEncodeElementDefault }.buildEncodeSettings(), @@ -162,19 +149,13 @@ public class FirebaseEncoder( } } -public open class FirebaseCompositeEncoder( +internal open class FirebaseCompositeEncoder( private val settings: EncodeSettings, private val end: () -> Unit = {}, private val setPolymorphicType: (String, String) -> Unit = { _, _ -> }, private val set: (descriptor: SerialDescriptor, index: Int, value: Any?) -> Unit, ) : CompositeEncoder { -// private fun SerializationStrategy.toFirebase(): SerializationStrategy = when(descriptor.kind) { -// StructureKind.MAP -> FirebaseMapSerializer(descriptor.getElementDescriptor(1)) as SerializationStrategy -// StructureKind.LIST -> FirebaseListSerializer(descriptor.getElementDescriptor(0)) as SerializationStrategy -// else -> this -// } - override val serializersModule: SerializersModule = settings.serializersModule override fun endStructure(descriptor: SerialDescriptor): Unit = end() @@ -190,7 +171,7 @@ public open class FirebaseCompositeEncoder( descriptor, index, value?.let { - FirebaseEncoder(settings).apply { + FirebaseEncoderImpl(settings).apply { encodeSerializableValue(serializer, value) }.value }, @@ -204,7 +185,7 @@ public open class FirebaseCompositeEncoder( ): Unit = set( descriptor, index, - FirebaseEncoder(settings).apply { + FirebaseEncoderImpl(settings).apply { encodeSerializableValue(serializer, value) }.value, ) @@ -231,7 +212,7 @@ public open class FirebaseCompositeEncoder( @ExperimentalSerializationApi override fun encodeInlineElement(descriptor: SerialDescriptor, index: Int): Encoder = - FirebaseEncoder(settings) + FirebaseEncoderImpl(settings) public fun encodePolymorphicClassDiscriminator(discriminator: String, type: String) { setPolymorphicType(discriminator, type) diff --git a/firebase-common-internal/src/commonMain/kotlin/dev/gitlive/firebase/internal/serializers.kt b/firebase-common-internal/src/commonMain/kotlin/dev/gitlive/firebase/internal/serializers.kt index 41f319f88..cb1b1fb00 100644 --- a/firebase-common-internal/src/commonMain/kotlin/dev/gitlive/firebase/internal/serializers.kt +++ b/firebase-common-internal/src/commonMain/kotlin/dev/gitlive/firebase/internal/serializers.kt @@ -128,14 +128,14 @@ public class SpecialValueSerializer( override val descriptor: SerialDescriptor = buildClassSerialDescriptor(serialName) { } override fun serialize(encoder: Encoder, value: T) { - if (encoder is FirebaseEncoder) { + if (encoder is FirebaseEncoderImpl) { encoder.value = toNativeValue(value) } else { throw SerializationException("This serializer must be used with FirebaseEncoder") } } - override fun deserialize(decoder: Decoder): T = if (decoder is FirebaseDecoder) { + override fun deserialize(decoder: Decoder): T = if (decoder is FirebaseDecoderImpl) { fromNativeValue(decoder.value) } else { throw SerializationException("This serializer must be used with FirebaseDecoder") diff --git a/firebase-common-internal/src/iosMain/kotlin/dev/gitlive/firebase/internal/_decoders.kt b/firebase-common-internal/src/iosMain/kotlin/dev/gitlive/firebase/internal/_decoders.kt index 00400b622..561d4c762 100644 --- a/firebase-common-internal/src/iosMain/kotlin/dev/gitlive/firebase/internal/_decoders.kt +++ b/firebase-common-internal/src/iosMain/kotlin/dev/gitlive/firebase/internal/_decoders.kt @@ -9,7 +9,7 @@ import kotlinx.serialization.descriptors.PolymorphicKind import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.descriptors.StructureKind -public actual fun FirebaseDecoder.structureDecoder(descriptor: SerialDescriptor, polymorphicIsNested: Boolean): CompositeDecoder = when (descriptor.kind) { +internal actual fun FirebaseDecoderImpl.structureDecoder(descriptor: SerialDescriptor, polymorphicIsNested: Boolean): CompositeDecoder = when (descriptor.kind) { StructureKind.CLASS, StructureKind.OBJECT -> decodeAsMap(false) StructureKind.LIST -> decodeAsList() StructureKind.MAP -> (value as? Map<*, *>).orEmpty().entries.toList().let { @@ -19,13 +19,13 @@ public actual fun FirebaseDecoder.structureDecoder(descriptor: SerialDescriptor, else -> TODO("The firebase-kotlin-sdk does not support $descriptor for serialization yet") } -public actual fun getPolymorphicType(value: Any?, discriminator: String): String = +internal actual fun getPolymorphicType(value: Any?, discriminator: String): String = (value as? Map<*, *>).orEmpty()[discriminator] as String -private fun FirebaseDecoder.decodeAsList(): CompositeDecoder = (value as? List<*>).orEmpty().let { +private fun FirebaseDecoderImpl.decodeAsList(): CompositeDecoder = (value as? List<*>).orEmpty().let { FirebaseCompositeDecoder(it.size, settings) { _, index -> it[index] } } -private fun FirebaseDecoder.decodeAsMap(isNestedPolymorphic: Boolean): CompositeDecoder = (value as? Map<*, *>).orEmpty().let { map -> +private fun FirebaseDecoderImpl.decodeAsMap(isNestedPolymorphic: Boolean): CompositeDecoder = (value as? Map<*, *>).orEmpty().let { map -> FirebaseClassDecoder(map.size, settings, { map.containsKey(it) }) { desc, index -> if (isNestedPolymorphic) { if (desc.getElementName(index) == "value") { 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 efd200c20..bab44db4e 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 @@ -9,7 +9,7 @@ import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.descriptors.StructureKind import kotlin.collections.set -public actual fun FirebaseEncoder.structureEncoder(descriptor: SerialDescriptor): FirebaseCompositeEncoder = when (descriptor.kind) { +internal actual fun FirebaseEncoderImpl.structureEncoder(descriptor: SerialDescriptor): FirebaseCompositeEncoder = when (descriptor.kind) { StructureKind.LIST -> encodeAsList() StructureKind.MAP -> mutableListOf() .let { FirebaseCompositeEncoder(settings, { value = it.chunked(2).associate { (k, v) -> k to v } }) { _, _, value -> it.add(value) } } @@ -18,10 +18,10 @@ public actual fun FirebaseEncoder.structureEncoder(descriptor: SerialDescriptor) else -> TODO("The firebase-kotlin-sdk does not support $descriptor for serialization yet") } -private fun FirebaseEncoder.encodeAsList(): FirebaseCompositeEncoder = mutableListOf() +private fun FirebaseEncoderImpl.encodeAsList(): FirebaseCompositeEncoder = mutableListOf() .also { value = it } .let { FirebaseCompositeEncoder(settings) { _, index, value -> it.add(index, value) } } -private fun FirebaseEncoder.encodeAsMap(descriptor: SerialDescriptor): FirebaseCompositeEncoder = mutableMapOf() +private fun FirebaseEncoderImpl.encodeAsMap(descriptor: SerialDescriptor): FirebaseCompositeEncoder = mutableMapOf() .also { value = it } .let { FirebaseCompositeEncoder( diff --git a/firebase-common-internal/src/jsMain/kotlin/dev/gitlive/firebase/internal/_decoders.kt b/firebase-common-internal/src/jsMain/kotlin/dev/gitlive/firebase/internal/_decoders.kt index 05701df40..1787c1cc4 100644 --- a/firebase-common-internal/src/jsMain/kotlin/dev/gitlive/firebase/internal/_decoders.kt +++ b/firebase-common-internal/src/jsMain/kotlin/dev/gitlive/firebase/internal/_decoders.kt @@ -11,7 +11,7 @@ import kotlinx.serialization.descriptors.StructureKind import kotlinx.serialization.encoding.CompositeDecoder import kotlin.js.Json -public actual fun FirebaseDecoder.structureDecoder(descriptor: SerialDescriptor, polymorphicIsNested: Boolean): CompositeDecoder = when (descriptor.kind) { +internal actual fun FirebaseDecoderImpl.structureDecoder(descriptor: SerialDescriptor, polymorphicIsNested: Boolean): CompositeDecoder = when (descriptor.kind) { StructureKind.CLASS, StructureKind.OBJECT -> decodeAsMap(false) StructureKind.LIST -> decodeAsList() StructureKind.MAP -> (js("Object").entries(value) as Array>).let { @@ -39,15 +39,15 @@ public actual fun FirebaseDecoder.structureDecoder(descriptor: SerialDescriptor, } @Suppress("UNCHECKED_CAST_TO_EXTERNAL_INTERFACE") -public actual fun getPolymorphicType(value: Any?, discriminator: String): String = +internal actual fun getPolymorphicType(value: Any?, discriminator: String): String = (value as Json)[discriminator] as String -private fun FirebaseDecoder.decodeAsList(): CompositeDecoder = (value as Array<*>).let { +private fun FirebaseDecoderImpl.decodeAsList(): CompositeDecoder = (value as Array<*>).let { FirebaseCompositeDecoder(it.size, settings) { _, index -> it[index] } } @Suppress("UNCHECKED_CAST_TO_EXTERNAL_INTERFACE") -private fun FirebaseDecoder.decodeAsMap(isNestedPolymorphic: Boolean): CompositeDecoder = (value as Json).let { json -> +private fun FirebaseDecoderImpl.decodeAsMap(isNestedPolymorphic: Boolean): CompositeDecoder = (value as Json).let { json -> FirebaseClassDecoder(js("Object").keys(value).length as Int, settings, { json[it] != undefined }) { desc, index -> if (isNestedPolymorphic) { if (desc.getElementName(index) == "value") { 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 1e21549a0..7121128d0 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 @@ -9,7 +9,7 @@ import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.descriptors.StructureKind import kotlin.js.json -public actual fun FirebaseEncoder.structureEncoder(descriptor: SerialDescriptor): FirebaseCompositeEncoder = when (descriptor.kind) { +internal actual fun FirebaseEncoderImpl.structureEncoder(descriptor: SerialDescriptor): FirebaseCompositeEncoder = when (descriptor.kind) { StructureKind.LIST -> encodeAsList(descriptor) StructureKind.MAP -> { val map = json() @@ -28,10 +28,10 @@ public actual fun FirebaseEncoder.structureEncoder(descriptor: SerialDescriptor) else -> TODO("The firebase-kotlin-sdk does not support $descriptor for serialization yet") } -private fun FirebaseEncoder.encodeAsList(descriptor: SerialDescriptor): FirebaseCompositeEncoder = Array(descriptor.elementsCount) { null } +private fun FirebaseEncoderImpl.encodeAsList(descriptor: SerialDescriptor): FirebaseCompositeEncoder = Array(descriptor.elementsCount) { null } .also { value = it } .let { FirebaseCompositeEncoder(settings) { _, index, value -> it[index] = value } } -private fun FirebaseEncoder.encodeAsMap(descriptor: SerialDescriptor): FirebaseCompositeEncoder = json() +private fun FirebaseEncoderImpl.encodeAsMap(descriptor: SerialDescriptor): FirebaseCompositeEncoder = json() .also { value = it } .let { FirebaseCompositeEncoder( diff --git a/firebase-common/api/android/firebase-common.api b/firebase-common/api/android/firebase-common.api index 2b70a6e8a..9724b86d4 100644 --- a/firebase-common/api/android/firebase-common.api +++ b/firebase-common/api/android/firebase-common.api @@ -33,3 +33,38 @@ public synthetic class dev/gitlive/firebase/FirebaseClassDiscriminator$Impl : de public final synthetic fun discriminator ()Ljava/lang/String; } +public abstract interface class dev/gitlive/firebase/FirebaseDecoder : kotlinx/serialization/encoding/Decoder { +} + +public final class dev/gitlive/firebase/FirebaseDecoder$DefaultImpls { + public static fun decodeNullableSerializableValue (Ldev/gitlive/firebase/FirebaseDecoder;Lkotlinx/serialization/DeserializationStrategy;)Ljava/lang/Object; + public static fun decodeSerializableValue (Ldev/gitlive/firebase/FirebaseDecoder;Lkotlinx/serialization/DeserializationStrategy;)Ljava/lang/Object; +} + +public abstract interface class dev/gitlive/firebase/FirebaseEncoder : kotlinx/serialization/encoding/Encoder { +} + +public final class dev/gitlive/firebase/FirebaseEncoder$DefaultImpls { + public static fun beginCollection (Ldev/gitlive/firebase/FirebaseEncoder;Lkotlinx/serialization/descriptors/SerialDescriptor;I)Lkotlinx/serialization/encoding/CompositeEncoder; + public static fun encodeNotNullMark (Ldev/gitlive/firebase/FirebaseEncoder;)V + public static fun encodeNullableSerializableValue (Ldev/gitlive/firebase/FirebaseEncoder;Lkotlinx/serialization/SerializationStrategy;Ljava/lang/Object;)V + public static fun encodeSerializableValue (Ldev/gitlive/firebase/FirebaseEncoder;Lkotlinx/serialization/SerializationStrategy;Ljava/lang/Object;)V +} + +public final class dev/gitlive/firebase/ValueWithSerializer { + public fun (Ljava/lang/Object;Lkotlinx/serialization/SerializationStrategy;)V + public final fun component1 ()Ljava/lang/Object; + public final fun component2 ()Lkotlinx/serialization/SerializationStrategy; + public final fun copy (Ljava/lang/Object;Lkotlinx/serialization/SerializationStrategy;)Ldev/gitlive/firebase/ValueWithSerializer; + public static synthetic fun copy$default (Ldev/gitlive/firebase/ValueWithSerializer;Ljava/lang/Object;Lkotlinx/serialization/SerializationStrategy;ILjava/lang/Object;)Ldev/gitlive/firebase/ValueWithSerializer; + public fun equals (Ljava/lang/Object;)Z + public final fun getSerializer ()Lkotlinx/serialization/SerializationStrategy; + public final fun getValue ()Ljava/lang/Object; + public fun hashCode ()I + public fun toString ()Ljava/lang/String; +} + +public final class dev/gitlive/firebase/ValueWithSerializerKt { + public static final fun withSerializer (Ljava/lang/Object;Lkotlinx/serialization/SerializationStrategy;)Ljava/lang/Object; +} + diff --git a/firebase-common/api/jvm/firebase-common.api b/firebase-common/api/jvm/firebase-common.api index 2b70a6e8a..9724b86d4 100644 --- a/firebase-common/api/jvm/firebase-common.api +++ b/firebase-common/api/jvm/firebase-common.api @@ -33,3 +33,38 @@ public synthetic class dev/gitlive/firebase/FirebaseClassDiscriminator$Impl : de public final synthetic fun discriminator ()Ljava/lang/String; } +public abstract interface class dev/gitlive/firebase/FirebaseDecoder : kotlinx/serialization/encoding/Decoder { +} + +public final class dev/gitlive/firebase/FirebaseDecoder$DefaultImpls { + public static fun decodeNullableSerializableValue (Ldev/gitlive/firebase/FirebaseDecoder;Lkotlinx/serialization/DeserializationStrategy;)Ljava/lang/Object; + public static fun decodeSerializableValue (Ldev/gitlive/firebase/FirebaseDecoder;Lkotlinx/serialization/DeserializationStrategy;)Ljava/lang/Object; +} + +public abstract interface class dev/gitlive/firebase/FirebaseEncoder : kotlinx/serialization/encoding/Encoder { +} + +public final class dev/gitlive/firebase/FirebaseEncoder$DefaultImpls { + public static fun beginCollection (Ldev/gitlive/firebase/FirebaseEncoder;Lkotlinx/serialization/descriptors/SerialDescriptor;I)Lkotlinx/serialization/encoding/CompositeEncoder; + public static fun encodeNotNullMark (Ldev/gitlive/firebase/FirebaseEncoder;)V + public static fun encodeNullableSerializableValue (Ldev/gitlive/firebase/FirebaseEncoder;Lkotlinx/serialization/SerializationStrategy;Ljava/lang/Object;)V + public static fun encodeSerializableValue (Ldev/gitlive/firebase/FirebaseEncoder;Lkotlinx/serialization/SerializationStrategy;Ljava/lang/Object;)V +} + +public final class dev/gitlive/firebase/ValueWithSerializer { + public fun (Ljava/lang/Object;Lkotlinx/serialization/SerializationStrategy;)V + public final fun component1 ()Ljava/lang/Object; + public final fun component2 ()Lkotlinx/serialization/SerializationStrategy; + public final fun copy (Ljava/lang/Object;Lkotlinx/serialization/SerializationStrategy;)Ldev/gitlive/firebase/ValueWithSerializer; + public static synthetic fun copy$default (Ldev/gitlive/firebase/ValueWithSerializer;Ljava/lang/Object;Lkotlinx/serialization/SerializationStrategy;ILjava/lang/Object;)Ldev/gitlive/firebase/ValueWithSerializer; + public fun equals (Ljava/lang/Object;)Z + public final fun getSerializer ()Lkotlinx/serialization/SerializationStrategy; + public final fun getValue ()Ljava/lang/Object; + public fun hashCode ()I + public fun toString ()Ljava/lang/String; +} + +public final class dev/gitlive/firebase/ValueWithSerializerKt { + public static final fun withSerializer (Ljava/lang/Object;Lkotlinx/serialization/SerializationStrategy;)Ljava/lang/Object; +} + diff --git a/firebase-common/src/commonMain/kotlin/dev/gitlive/firebase/FirebaseDecoder.kt b/firebase-common/src/commonMain/kotlin/dev/gitlive/firebase/FirebaseDecoder.kt new file mode 100644 index 000000000..2dbf07b44 --- /dev/null +++ b/firebase-common/src/commonMain/kotlin/dev/gitlive/firebase/FirebaseDecoder.kt @@ -0,0 +1,5 @@ +package dev.gitlive.firebase + +import kotlinx.serialization.encoding.Decoder + +public interface FirebaseDecoder : Decoder diff --git a/firebase-common/src/commonMain/kotlin/dev/gitlive/firebase/FirebaseEncoder.kt b/firebase-common/src/commonMain/kotlin/dev/gitlive/firebase/FirebaseEncoder.kt new file mode 100644 index 000000000..f33f69fbb --- /dev/null +++ b/firebase-common/src/commonMain/kotlin/dev/gitlive/firebase/FirebaseEncoder.kt @@ -0,0 +1,5 @@ +package dev.gitlive.firebase + +import kotlinx.serialization.encoding.Encoder + +public interface FirebaseEncoder : Encoder 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 db1f7f344..e393d118b 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,7 +1,7 @@ package dev.gitlive.firebase.database -import dev.gitlive.firebase.internal.FirebaseDecoder -import dev.gitlive.firebase.internal.FirebaseEncoder +import dev.gitlive.firebase.FirebaseEncoder +import dev.gitlive.firebase.FirebaseDecoder import dev.gitlive.firebase.internal.SpecialValueSerializer import kotlinx.serialization.KSerializer import kotlinx.serialization.Serializable 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 945230bc7..10fa9341f 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.firestore.internal.NativeDocumentReference -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 561dcb201..d2717474d 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,6 +1,6 @@ package dev.gitlive.firebase.firestore -import dev.gitlive.firebase.internal.FirebaseEncoder +import dev.gitlive.firebase.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 cb46e1792..7228704bc 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,5 +1,6 @@ package dev.gitlive.firebase.firestore +import dev.gitlive.firebase.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/TimestampSerializer.kt b/firebase-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore/TimestampSerializer.kt index f970b0801..791e4d6f5 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,5 +1,7 @@ package dev.gitlive.firebase.firestore +import dev.gitlive.firebase.FirebaseEncoder +import dev.gitlive.firebase.FirebaseDecoder import dev.gitlive.firebase.internal.SpecialValueSerializer import dev.gitlive.firebase.firestore.DoubleAsTimestampSerializer.SERVER_TIMESTAMP import kotlinx.serialization.KSerializer 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 672d5f0ea..d6625b1b9 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 @@ -12,7 +12,7 @@ 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.internal.withSerializer +import dev.gitlive.firebase.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/Timestamp.kt b/firebase-firestore/src/iosMain/kotlin/dev/gitlive/firebase/firestore/Timestamp.kt index d0eb95602..8497833e8 100644 --- a/firebase-firestore/src/iosMain/kotlin/dev/gitlive/firebase/firestore/Timestamp.kt +++ b/firebase-firestore/src/iosMain/kotlin/dev/gitlive/firebase/firestore/Timestamp.kt @@ -1,6 +1,6 @@ package dev.gitlive.firebase.firestore -import cocoapods.FirebaseFirestoreInternal.FIRTimestamp +import cocoapods.FirebaseCore.FIRTimestamp import kotlinx.serialization.Serializable /** A class representing a platform specific Firebase Timestamp. */ diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 9561276bc..c2a38ad9b 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -16,7 +16,7 @@ kotlinx-datetime = "0.6.1" kotlinter = "4.4.1" settings-api = "2.0" settings-language = "2.0" -firebase-cocoapods = "10.28.0" +firebase-cocoapods = "11.1.0" ios-deploymentTarget = "13.0" test-logger-plugin = "4.0.0" dokka = "1.9.20"