From c4dd19dd002ae1d041adad6531fff76c4683299c Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 28 Oct 2021 17:50:28 +0600 Subject: [PATCH 1/6] start 0.7.4 --- CHANGELOG.md | 2 ++ gradle.properties | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3cf67c882a4..85fc346b4e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Changelog +## 0.7.4 + ## 0.7.3 * `Versions`: diff --git a/gradle.properties b/gradle.properties index 26dd44c7d83..20f356055d4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -45,5 +45,5 @@ dokka_version=1.5.31 # Project data group=dev.inmo -version=0.7.3 -android_code_version=77 +version=0.7.4 +android_code_version=78 From 162294d6c679c83bfef99c6a4be70868de555dae Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 28 Oct 2021 18:02:02 +0600 Subject: [PATCH 2/6] either --- CHANGELOG.md | 3 ++ .../dev/inmo/micro_utils/common/Either.kt | 45 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 common/src/commonMain/kotlin/dev/inmo/micro_utils/common/Either.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 85fc346b4e7..a088166fe30 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## 0.7.4 +* `Common`: + * New type `Either` + ## 0.7.3 * `Versions`: diff --git a/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/Either.kt b/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/Either.kt new file mode 100644 index 00000000000..20625edbd41 --- /dev/null +++ b/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/Either.kt @@ -0,0 +1,45 @@ +package dev.inmo.micro_utils.common + +/** + * Realization of this interface will contains at least one not null - [t1] or [t2] + * + * @see EitherFirst + * @see EitherSecond + * @see Either.Companion.first + * @see Either.Companion.second + * @see Either.onFirst + * @see Either.onSecond + */ +sealed interface Either { + val t1: T1? + val t2: T2? + + companion object +} + +data class EitherFirst( + override val t1: T1 +) : Either { + override val t2: T2? + get() = null +} + +data class EitherSecond( + override val t2: T2 +) : Either { + override val t1: T1? + get() = null +} + +inline fun Either.Companion.first(t1: T1): Either = EitherFirst(t1) +inline fun Either.Companion.second(t1: T1): Either = EitherFirst(t1) + +inline fun > E.onFirst(crossinline block: (T1) -> Unit): E { + if (this is EitherFirst<*, *>) block(t1 as T1) + return this +} + +inline fun > E.onSecond(crossinline block: (T2) -> Unit): E { + if (this is EitherSecond<*, *>) block(t2 as T2) + return this +} From 8cd0775a6c3f526842c4cb30f31fdb3d5deb222c Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 28 Oct 2021 18:42:05 +0600 Subject: [PATCH 3/6] update kdocs of Either --- .../dev/inmo/micro_utils/common/Either.kt | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/Either.kt b/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/Either.kt index 20625edbd41..700580015b3 100644 --- a/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/Either.kt +++ b/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/Either.kt @@ -17,6 +17,9 @@ sealed interface Either { companion object } +/** + * This type [Either] will always have not nullable [t1] + */ data class EitherFirst( override val t1: T1 ) : Either { @@ -24,6 +27,9 @@ data class EitherFirst( get() = null } +/** + * This type [Either] will always have not nullable [t2] + */ data class EitherSecond( override val t2: T2 ) : Either { @@ -31,15 +37,29 @@ data class EitherSecond( get() = null } +/** + * @return New instance of [EitherFirst] + */ inline fun Either.Companion.first(t1: T1): Either = EitherFirst(t1) +/** + * @return New instance of [EitherSecond] + */ inline fun Either.Companion.second(t1: T1): Either = EitherFirst(t1) +/** + * Will call [block] in case when [Either.t1] of [this] is not null + */ inline fun > E.onFirst(crossinline block: (T1) -> Unit): E { - if (this is EitherFirst<*, *>) block(t1 as T1) + val t1 = t1 + t1 ?.let(block) return this } +/** + * Will call [block] in case when [Either.t2] of [this] is not null + */ inline fun > E.onSecond(crossinline block: (T2) -> Unit): E { - if (this is EitherSecond<*, *>) block(t2 as T2) + val t2 = t2 + t2 ?.let(block) return this } From 67a10506469ce5df63a42e4371126027ae725e44 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 28 Oct 2021 18:46:53 +0600 Subject: [PATCH 4/6] solution for #105 --- CHANGELOG.md | 3 +++ .../serialization/typed_serializer/TypedSerializer.kt | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a088166fe30..b0b608b203f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ * `Common`: * New type `Either` +* `Serialization`: + * `TypedSerializer` + * New factory fun which accept vararg pairs of type and its serializer ## 0.7.3 diff --git a/serialization/typed_serializer/src/commonMain/kotlin/dev/inmo/micro_utils/serialization/typed_serializer/TypedSerializer.kt b/serialization/typed_serializer/src/commonMain/kotlin/dev/inmo/micro_utils/serialization/typed_serializer/TypedSerializer.kt index 5e2632433cd..804a0bc637e 100644 --- a/serialization/typed_serializer/src/commonMain/kotlin/dev/inmo/micro_utils/serialization/typed_serializer/TypedSerializer.kt +++ b/serialization/typed_serializer/src/commonMain/kotlin/dev/inmo/micro_utils/serialization/typed_serializer/TypedSerializer.kt @@ -86,3 +86,7 @@ operator fun TypedSerializer.minusAssign(kClass: KClass) { inline fun TypedSerializer( presetSerializers: Map> = emptyMap() ) = TypedSerializer(T::class, presetSerializers) + +inline fun TypedSerializer( + vararg presetSerializers: Pair> +) = TypedSerializer(presetSerializers.toMap()) From 02c3d397ad96bf1da295947eccc26400b4b6d95e Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 29 Oct 2021 13:40:53 +0600 Subject: [PATCH 5/6] solution of #104 --- CHANGELOG.md | 8 ++++++++ .../repos/crud/AbstractMutableAndroidCRUDRepo.kt | 12 +++++++----- .../repos/exposed/AbstractExposedWriteCRUDRepo.kt | 9 +++++---- .../repos/exposed/keyvalue/ExposedKeyValueRepo.kt | 4 ++-- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b0b608b203f..38d6e7ccd84 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,14 @@ * `Serialization`: * `TypedSerializer` * New factory fun which accept vararg pairs of type and its serializer +* `Repos`: + * `Common` (`Android`): + * `AbstractMutableAndroidCRUDRepo` flows now will have extra buffer capacity instead of reply. It means that + android crud repo _WILL NOT_ send previous events to the + * `Exposed`: + * New parameter `AbstractExposedWriteCRUDRepo#replyCacheInFlows` + * KeyValue realization `ExposedKeyValueRepo` properties `_onNewValue` and `_onValueRemoved` now are available in + inheritors ## 0.7.3 diff --git a/repos/common/src/main/kotlin/dev/inmo/micro_utils/repos/crud/AbstractMutableAndroidCRUDRepo.kt b/repos/common/src/main/kotlin/dev/inmo/micro_utils/repos/crud/AbstractMutableAndroidCRUDRepo.kt index fc016c19a5c..29103d3f2ab 100644 --- a/repos/common/src/main/kotlin/dev/inmo/micro_utils/repos/crud/AbstractMutableAndroidCRUDRepo.kt +++ b/repos/common/src/main/kotlin/dev/inmo/micro_utils/repos/crud/AbstractMutableAndroidCRUDRepo.kt @@ -6,13 +6,15 @@ import dev.inmo.micro_utils.repos.* import kotlinx.coroutines.flow.* abstract class AbstractMutableAndroidCRUDRepo( - helper: StandardSQLHelper + helper: StandardSQLHelper, + replyInFlows: Int = 0, + extraBufferCapacityInFlows: Int = 64 ) : WriteStandardCRUDRepo, AbstractAndroidCRUDRepo(helper), StandardCRUDRepo { - protected val newObjectsChannel = MutableSharedFlow(64) - protected val updateObjectsChannel = MutableSharedFlow(64) - protected val deleteObjectsIdsChannel = MutableSharedFlow(64) + protected val newObjectsChannel = MutableSharedFlow(replyInFlows, extraBufferCapacityInFlows) + protected val updateObjectsChannel = MutableSharedFlow(replyInFlows, extraBufferCapacityInFlows) + protected val deleteObjectsIdsChannel = MutableSharedFlow(replyInFlows, extraBufferCapacityInFlows) override val newObjectsFlow: Flow = newObjectsChannel.asSharedFlow() override val updatedObjectsFlow: Flow = updateObjectsChannel.asSharedFlow() override val deletedObjectsIdsFlow: Flow = deleteObjectsIdsChannel.asSharedFlow() @@ -102,4 +104,4 @@ abstract class AbstractMutableAndroidCRUDRepo( flowsChannelsSize: Int = 0, - tableName: String = "" + tableName: String = "", + replyCacheInFlows: Int = 0 ) : AbstractExposedReadCRUDRepo(tableName), ExposedCRUDRepo, WriteStandardCRUDRepo { - protected val newObjectsChannel = MutableSharedFlow(flowsChannelsSize) - protected val updateObjectsChannel = MutableSharedFlow(flowsChannelsSize) - protected val deleteObjectsIdsChannel = MutableSharedFlow(flowsChannelsSize) + protected val newObjectsChannel = MutableSharedFlow(replyCacheInFlows, flowsChannelsSize) + protected val updateObjectsChannel = MutableSharedFlow(replyCacheInFlows, flowsChannelsSize) + protected val deleteObjectsIdsChannel = MutableSharedFlow(replyCacheInFlows, flowsChannelsSize) override val newObjectsFlow: Flow = newObjectsChannel.asSharedFlow() override val updatedObjectsFlow: Flow = updateObjectsChannel.asSharedFlow() diff --git a/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/keyvalue/ExposedKeyValueRepo.kt b/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/keyvalue/ExposedKeyValueRepo.kt index 74a2bef1c9d..ee50149845a 100644 --- a/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/keyvalue/ExposedKeyValueRepo.kt +++ b/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/keyvalue/ExposedKeyValueRepo.kt @@ -19,8 +19,8 @@ open class ExposedKeyValueRepo( valueColumnAllocator, tableName ) { - private val _onNewValue = MutableSharedFlow>() - private val _onValueRemoved = MutableSharedFlow() + protected val _onNewValue = MutableSharedFlow>() + protected val _onValueRemoved = MutableSharedFlow() override val onNewValue: Flow> = _onNewValue.asSharedFlow() override val onValueRemoved: Flow = _onValueRemoved.asSharedFlow() From 69d6e63846203eeb1fa39b8ff8720f40d42353c3 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 29 Oct 2021 13:51:59 +0600 Subject: [PATCH 6/6] getAllBy* --- CHANGELOG.md | 3 +++ .../micro_utils/pagination/utils/GetAll.kt | 26 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 38d6e7ccd84..d5c02ed3735 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,9 @@ * New parameter `AbstractExposedWriteCRUDRepo#replyCacheInFlows` * KeyValue realization `ExposedKeyValueRepo` properties `_onNewValue` and `_onValueRemoved` now are available in inheritors +* `Pagination`: + * `Common`: + * New types `getAllBy*` for current, next and custom paging ## 0.7.3 diff --git a/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/utils/GetAll.kt b/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/utils/GetAll.kt index 5ad674cb746..8012a89e47d 100644 --- a/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/utils/GetAll.kt +++ b/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/utils/GetAll.kt @@ -16,6 +16,16 @@ suspend fun getAll( return results.toList() } +suspend fun R.getAllBy( + initialPagination: Pagination = FirstPagePagination(), + paginationMapper: R.(PaginationResult) -> Pagination?, + block: suspend R.(Pagination) -> PaginationResult +): List = getAll( + initialPagination, + { paginationMapper(it) }, + { block(it) } +) + suspend fun getAllWithNextPaging( initialPagination: Pagination = FirstPagePagination(), block: suspend (Pagination) -> PaginationResult @@ -25,6 +35,14 @@ suspend fun getAllWithNextPaging( block ) +suspend fun R.getAllByWithNextPaging( + initialPagination: Pagination = FirstPagePagination(), + block: suspend R.(Pagination) -> PaginationResult +): List = getAllWithNextPaging( + initialPagination, + { block(it) } +) + suspend fun getAllWithCurrentPaging( initialPagination: Pagination = FirstPagePagination(), block: suspend (Pagination) -> PaginationResult @@ -33,3 +51,11 @@ suspend fun getAllWithCurrentPaging( { it.currentPageIfNotEmpty() }, block ) + +suspend fun R.getAllByWithCurrentPaging( + initialPagination: Pagination = FirstPagePagination(), + block: suspend R.(Pagination) -> PaginationResult +): List = getAllWithCurrentPaging( + initialPagination, + { block(it) } +)