diff --git a/CHANGELOG.md b/CHANGELOG.md index e8649aa41f8..45dcb68db3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## 0.3.2 + +* `Versions`: + * `Coroutines`: `1.4.1` -> `1.4.2` +* `Repos`: + * `Common`: + * New inline function `mapper` for simplier creating of `MapperRepo` objects + * Extensions `withMapper` for keyvalue repos and onetomany repos + ## 0.3.1 **ANDROID PACKAGES** diff --git a/gradle.properties b/gradle.properties index 22e751c045b..7e3b86a25a2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,7 +12,7 @@ kotlin_coroutines_version=1.4.1 kotlin_serialisation_core_version=1.0.1 kotlin_exposed_version=0.28.1 -ktor_version=1.4.1 +ktor_version=1.4.2 klockVersion=1.12.1 @@ -41,5 +41,5 @@ dokka_version=1.4.0 # Project data group=dev.inmo -version=0.3.1 -android_code_version=1 +version=0.3.2 +android_code_version=2 diff --git a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/MapperRepo.kt b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/MapperRepo.kt index 334077a007f..3d25d74ee2a 100644 --- a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/MapperRepo.kt +++ b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/MapperRepo.kt @@ -6,4 +6,16 @@ interface MapperRepo { suspend fun ToKey.toInnerKey() = this as FromKey suspend fun ToValue.toInnerValue() = this as FromValue -} \ No newline at end of file +} + +inline fun mapper( + crossinline keyFromToTo: suspend FromKey.() -> ToKey = { this as ToKey }, + crossinline valueFromToTo: suspend FromValue.() -> ToValue = { this as ToValue }, + crossinline keyToToFrom: suspend ToKey.() -> FromKey = { this as FromKey }, + crossinline valueToToFrom: suspend ToValue.() -> FromValue = { this as FromValue }, +) = object : MapperRepo { + override suspend fun FromKey.toOutKey(): ToKey = keyFromToTo() + override suspend fun FromValue.toOutValue(): ToValue = valueFromToTo() + override suspend fun ToKey.toInnerKey(): FromKey = keyToToFrom() + override suspend fun ToValue.toInnerValue(): FromValue = valueToToFrom() +} diff --git a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/mappers/KeyValueMappers.kt b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/mappers/KeyValueMappers.kt index 75d4f860079..6a770683a4d 100644 --- a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/mappers/KeyValueMappers.kt +++ b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/mappers/KeyValueMappers.kt @@ -51,6 +51,11 @@ open class MapperReadStandardKeyValueRepo( override suspend fun count(): Long = to.count() } +@Suppress("NOTHING_TO_INLINE") +inline fun ReadStandardKeyValueRepo.withMapper( + mapper: MapperRepo +): ReadStandardKeyValueRepo = MapperReadStandardKeyValueRepo(this, mapper) + open class MapperWriteStandardKeyValueRepo( private val to: WriteStandardKeyValueRepo, mapper: MapperRepo @@ -75,6 +80,11 @@ open class MapperWriteStandardKeyValueRepo( ) } +@Suppress("NOTHING_TO_INLINE") +inline fun WriteStandardKeyValueRepo.withMapper( + mapper: MapperRepo +): WriteStandardKeyValueRepo = MapperWriteStandardKeyValueRepo(this, mapper) + open class MapperStandardKeyValueRepo( private val to: StandardKeyValueRepo, mapper: MapperRepo @@ -82,3 +92,8 @@ open class MapperStandardKeyValueRepo( MapperRepo by mapper, ReadStandardKeyValueRepo by MapperReadStandardKeyValueRepo(to, mapper), WriteStandardKeyValueRepo by MapperWriteStandardKeyValueRepo(to, mapper) + +@Suppress("NOTHING_TO_INLINE") +inline fun StandardKeyValueRepo.withMapper( + mapper: MapperRepo +): StandardKeyValueRepo = MapperStandardKeyValueRepo(this, mapper) diff --git a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/mappers/OneToManyKeyValueMappers.kt b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/mappers/OneToManyKeyValueMappers.kt index 37c1602b203..b3fbddd9db7 100644 --- a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/mappers/OneToManyKeyValueMappers.kt +++ b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/mappers/OneToManyKeyValueMappers.kt @@ -49,6 +49,11 @@ open class MapperReadOneToManyKeyValueRepo( override suspend fun count(k: FromKey): Long = to.count(k.toOutKey()) } +@Suppress("NOTHING_TO_INLINE") +inline fun ReadOneToManyKeyValueRepo.withMapper( + mapper: MapperRepo +): ReadOneToManyKeyValueRepo = MapperReadOneToManyKeyValueRepo(this, mapper) + open class MapperWriteOneToManyKeyValueRepo( private val to: WriteOneToManyKeyValueRepo, mapper: MapperRepo @@ -78,6 +83,11 @@ open class MapperWriteOneToManyKeyValueRepo( override suspend fun clear(k: FromKey) = to.clear(k.toOutKey()) } +@Suppress("NOTHING_TO_INLINE") +inline fun WriteOneToManyKeyValueRepo.withMapper( + mapper: MapperRepo +): WriteOneToManyKeyValueRepo = MapperWriteOneToManyKeyValueRepo(this, mapper) + open class MapperOneToManyKeyValueRepo( private val to: OneToManyKeyValueRepo, mapper: MapperRepo @@ -85,3 +95,8 @@ open class MapperOneToManyKeyValueRepo( MapperRepo by mapper, ReadOneToManyKeyValueRepo by MapperReadOneToManyKeyValueRepo(to, mapper), WriteOneToManyKeyValueRepo by MapperWriteOneToManyKeyValueRepo(to, mapper) + +@Suppress("NOTHING_TO_INLINE") +inline fun OneToManyKeyValueRepo.withMapper( + mapper: MapperRepo +): OneToManyKeyValueRepo = MapperOneToManyKeyValueRepo(this, mapper)