From 4be1d93f609fd58412949c701ca7fc804975f748 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 9 Mar 2023 21:49:15 +0600 Subject: [PATCH 1/5] start 0.17.4 --- CHANGELOG.md | 2 ++ gradle.properties | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d23d1cf5cfc..50220cc2871 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Changelog +## 0.17.4 + ## 0.17.3 * `Common`: diff --git a/gradle.properties b/gradle.properties index 7d16fe68871..79aae800ee7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -14,5 +14,5 @@ crypto_js_version=4.1.1 # Project data group=dev.inmo -version=0.17.3 -android_code_version=185 +version=0.17.4 +android_code_version=186 From f5f75117810bbeab9ee4a9e79d93545814f5d77b Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 9 Mar 2023 21:55:07 +0600 Subject: [PATCH 2/5] add mapper serializer --- CHANGELOG.md | 4 ++++ serialization/mapper/build.gradle | 7 ++++++ .../src/commonMain/kotlin/MapperSerializer.kt | 22 +++++++++++++++++++ settings.gradle | 1 + 4 files changed, 34 insertions(+) create mode 100644 serialization/mapper/build.gradle create mode 100644 serialization/mapper/src/commonMain/kotlin/MapperSerializer.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 50220cc2871..a80f27c4420 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## 0.17.4 +* `Serialization`: + * `Mapper`: + * Module inited + ## 0.17.3 * `Common`: diff --git a/serialization/mapper/build.gradle b/serialization/mapper/build.gradle new file mode 100644 index 00000000000..7c54502f100 --- /dev/null +++ b/serialization/mapper/build.gradle @@ -0,0 +1,7 @@ +plugins { + id "org.jetbrains.kotlin.multiplatform" + id "org.jetbrains.kotlin.plugin.serialization" + id "com.android.library" +} + +apply from: "$mppProjectWithSerializationPresetPath" diff --git a/serialization/mapper/src/commonMain/kotlin/MapperSerializer.kt b/serialization/mapper/src/commonMain/kotlin/MapperSerializer.kt new file mode 100644 index 00000000000..c18343deb82 --- /dev/null +++ b/serialization/mapper/src/commonMain/kotlin/MapperSerializer.kt @@ -0,0 +1,22 @@ +package dev.inmo.micro_utils.serialization.mapper + +import kotlinx.serialization.KSerializer +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder + +class MapperSerializer( + private val base: KSerializer, + private val serialize: (O) -> I, + private val deserialize: (I) -> O +) : KSerializer { + override val descriptor: SerialDescriptor = base.descriptor + + override fun deserialize(decoder: Decoder): O { + return deserialize(base.deserialize(decoder)) + } + + override fun serialize(encoder: Encoder, value: O) { + base.serialize(encoder, serialize(value)) + } +} diff --git a/settings.gradle b/settings.gradle index 6d422fe4e63..ec21091c550 100644 --- a/settings.gradle +++ b/settings.gradle @@ -37,6 +37,7 @@ String[] includes = [ ":serialization:base64", ":serialization:encapsulator", ":serialization:typed_serializer", + ":serialization:mapper", ":startup:plugin", ":startup:launcher", From b3f468f9018a40c2d8dda9ad425aa91cc61c723c Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 9 Mar 2023 22:21:11 +0600 Subject: [PATCH 3/5] add docs to mapper serialization and allow to use them as supertypes --- .../src/commonMain/kotlin/Extensions.kt | 99 +++++++++++++++++++ .../kotlin/MapperDeserializationStrategy.kt | 26 +++++ .../kotlin/MapperSerializationStrategy.kt | 25 +++++ .../src/commonMain/kotlin/MapperSerializer.kt | 10 +- 4 files changed, 159 insertions(+), 1 deletion(-) create mode 100644 serialization/mapper/src/commonMain/kotlin/Extensions.kt create mode 100644 serialization/mapper/src/commonMain/kotlin/MapperDeserializationStrategy.kt create mode 100644 serialization/mapper/src/commonMain/kotlin/MapperSerializationStrategy.kt diff --git a/serialization/mapper/src/commonMain/kotlin/Extensions.kt b/serialization/mapper/src/commonMain/kotlin/Extensions.kt new file mode 100644 index 00000000000..ca0f5b2a096 --- /dev/null +++ b/serialization/mapper/src/commonMain/kotlin/Extensions.kt @@ -0,0 +1,99 @@ +package dev.inmo.micro_utils.serialization.mapper + +import kotlinx.serialization.DeserializationStrategy +import kotlinx.serialization.InternalSerializationApi +import kotlinx.serialization.KSerializer +import kotlinx.serialization.SerializationStrategy +import kotlinx.serialization.serializer +import kotlin.reflect.KClass + +/** + * Will create [MapperSerializationStrategy] to allow you to map [O] to [I] using [serialize] lambda during + * serialization process + */ +inline fun SerializationStrategy.mapSerialization( + noinline serialize: (O) -> I +) = MapperSerializationStrategy( + this, + serialize +) + +/** + * Will create [MapperDeserializationStrategy] to allow you to map [I] to [O] using [deserialize] lambda during + * deserialization process + */ +inline fun DeserializationStrategy.mapDeserialization( + noinline deserialize: (I) -> O +) = MapperDeserializationStrategy( + this, + deserialize +) + +/** + * Will create [MapperSerializer] to allow you to map [O] to [I] and vice verse using [serialize]/[deserialize] lambda during + * serialization/deserialization process + */ +inline fun KSerializer.mapFullSerialization( + noinline serialize: (O) -> I, + noinline deserialize: (I) -> O +) = MapperSerializer( + this, + serialize, + deserialize +) + +/** + * Will create [MapperSerializationStrategy] to allow you to map [O] to [I] using [serialize] lambda during + * serialization process + */ +@OptIn(InternalSerializationApi::class) +inline fun KClass.mapSerialization( + serializer: SerializationStrategy = serializer(), + noinline serialize: (O) -> I +) = serializer.mapSerialization(serialize) + +/** + * Will create [MapperDeserializationStrategy] to allow you to map [I] to [O] using [deserialize] lambda during + * deserialization process + */ +@OptIn(InternalSerializationApi::class) +inline fun KClass.mapDeserialization( + serializer: DeserializationStrategy = serializer(), + noinline deserialize: (I) -> O +) = serializer.mapDeserialization(deserialize) + +/** + * Will create [MapperSerializer] to allow you to map [O] to [I] and vice verse using [serialize]/[deserialize] lambda during + * serialization/deserialization process + */ +@OptIn(InternalSerializationApi::class) +inline fun KClass.mapFullSerialization( + serializer: KSerializer = serializer(), + noinline serialize: (O) -> I, + noinline deserialize: (I) -> O +) = serializer.mapFullSerialization(serialize, deserialize) + +/** + * Will create [MapperSerializationStrategy] to allow you to map [O] to [I] using [serialize] lambda during + * serialization process + */ +inline fun mappedSerializationStrategy( + noinline serialize: (O) -> I, +) = serializer().mapSerialization(serialize) + +/** + * Will create [MapperDeserializationStrategy] to allow you to map [I] to [O] using [deserialize] lambda during + * deserialization process + */ +inline fun mappedDeserializationStrategy( + noinline deserialize: (I) -> O +) = serializer().mapDeserialization(deserialize) + +/** + * Will create [MapperSerializer] to allow you to map [O] to [I] and vice verse using [serialize]/[deserialize] lambda during + * serialization/deserialization process + */ +inline fun mappedSerializer( + noinline serialize: (O) -> I, + noinline deserialize: (I) -> O +) = serializer().mapFullSerialization(serialize, deserialize) diff --git a/serialization/mapper/src/commonMain/kotlin/MapperDeserializationStrategy.kt b/serialization/mapper/src/commonMain/kotlin/MapperDeserializationStrategy.kt new file mode 100644 index 00000000000..bf36ef9fe4b --- /dev/null +++ b/serialization/mapper/src/commonMain/kotlin/MapperDeserializationStrategy.kt @@ -0,0 +1,26 @@ +package dev.inmo.micro_utils.serialization.mapper + +import kotlinx.serialization.DeserializationStrategy +import kotlinx.serialization.KSerializer +import kotlinx.serialization.SerializationStrategy +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder + +/** + * Use this serializer when you have deserializable type [I] and want to map it to some [O] in process of + * deserialization + * + * @param base Serializer for [I] + * @param deserialize Will be used in [deserialize] method to convert deserialized by [base] [I] to [O] + */ +open class MapperDeserializationStrategy( + private val base: DeserializationStrategy, + private val deserialize: (I) -> O +) : DeserializationStrategy { + override val descriptor: SerialDescriptor = base.descriptor + + override fun deserialize(decoder: Decoder): O { + return deserialize(base.deserialize(decoder)) + } +} diff --git a/serialization/mapper/src/commonMain/kotlin/MapperSerializationStrategy.kt b/serialization/mapper/src/commonMain/kotlin/MapperSerializationStrategy.kt new file mode 100644 index 00000000000..4772932915c --- /dev/null +++ b/serialization/mapper/src/commonMain/kotlin/MapperSerializationStrategy.kt @@ -0,0 +1,25 @@ +package dev.inmo.micro_utils.serialization.mapper + +import kotlinx.serialization.KSerializer +import kotlinx.serialization.SerializationStrategy +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder + +/** + * Use this serializer when you have serializable type [I] and want to map it to some [O] in process of + * serialization + * + * @param base Serializer for [I] + * @param serialize Will be used in [serialize] method to convert incoming [O] to [I] and serialize with [base] + */ +open class MapperSerializationStrategy( + private val base: SerializationStrategy, + private val serialize: (O) -> I +) : SerializationStrategy { + override val descriptor: SerialDescriptor = base.descriptor + + override fun serialize(encoder: Encoder, value: O) { + base.serialize(encoder, serialize(value)) + } +} diff --git a/serialization/mapper/src/commonMain/kotlin/MapperSerializer.kt b/serialization/mapper/src/commonMain/kotlin/MapperSerializer.kt index c18343deb82..2df9a1ba334 100644 --- a/serialization/mapper/src/commonMain/kotlin/MapperSerializer.kt +++ b/serialization/mapper/src/commonMain/kotlin/MapperSerializer.kt @@ -5,7 +5,15 @@ import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder -class MapperSerializer( +/** + * Use this serializer when you have serializable type [I] and want to map it to some [O] in process of + * serialization/deserialization + * + * @param base Serializer for [I] + * @param serialize Will be used in [serialize] method to convert incoming [O] to [I] and serialize with [base] + * @param deserialize Will be used in [deserialize] method to convert deserialized by [base] [I] to [O] + */ +open class MapperSerializer( private val base: KSerializer, private val serialize: (O) -> I, private val deserialize: (I) -> O From 555956087de2430af62a9ec5277c29db2e1eb63f Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 9 Mar 2023 22:23:56 +0600 Subject: [PATCH 4/5] add android manifest to mapper module --- serialization/mapper/src/main/AndroidManifest.xml | 1 + 1 file changed, 1 insertion(+) create mode 100644 serialization/mapper/src/main/AndroidManifest.xml diff --git a/serialization/mapper/src/main/AndroidManifest.xml b/serialization/mapper/src/main/AndroidManifest.xml new file mode 100644 index 00000000000..08f765f84fe --- /dev/null +++ b/serialization/mapper/src/main/AndroidManifest.xml @@ -0,0 +1 @@ + From c9e320b72aa09a9ea49ccbee966128e21185f8b3 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 9 Mar 2023 23:22:33 +0600 Subject: [PATCH 5/5] update compose version --- CHANGELOG.md | 2 ++ gradle/libs.versions.toml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a80f27c4420..f698e2d57ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ * `Serialization`: * `Mapper`: * Module inited +* `Versions`: + * `Compose`: `1.3.1-rc02` -> `1.3.1` ## 0.17.3 diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 0fa2c526a9e..f066efbc714 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -6,7 +6,7 @@ kt-coroutines = "1.6.4" kslog = "1.0.0" -jb-compose = "1.3.1-rc01" +jb-compose = "1.3.1" jb-exposed = "0.41.1" jb-dokka = "1.7.20"