diff --git a/CHANGELOG.md b/CHANGELOG.md index 2584b79624b..8a4f3d85761 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,20 @@ # Changelog +## 0.18.0 + +**ALL PREVIOUSLY DEPRECATED FUNCTIONALITY HAVE BEEN REMOVED** + +* `Versions`: + * `Android Fragments`: `1.5.6` -> `1.5.7` +* `Ktor`: + * `Server`: + * Now it is possible to take query parameters as list +* `Repos`: + * `Common`: + * New `WriteKeyValuesRepo.removeWithValue` + * `Cache`: + * Rename full caching factories functions to `fullyCached` + ## 0.17.8 * `Versions`: diff --git a/coroutines/compose/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/compose/FlowToMutableState.kt b/coroutines/compose/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/compose/FlowToMutableState.kt deleted file mode 100644 index 92fba8f2176..00000000000 --- a/coroutines/compose/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/compose/FlowToMutableState.kt +++ /dev/null @@ -1,21 +0,0 @@ -package dev.inmo.micro_utils.coroutines.compose - -import androidx.compose.runtime.MutableState -import androidx.compose.runtime.mutableStateOf -import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.StateFlow - -@Deprecated("Duplicated functionality", ReplaceWith("asMutableComposeState(initial, scope)", "dev.inmo.micro_utils.coroutines.compose.asMutableComposeState")) -fun Flow.toMutableState( - initial: T, - scope: CoroutineScope -): MutableState = asMutableComposeState(initial, scope) - -@Deprecated("Duplicated functionality", ReplaceWith("asMutableComposeState(scope)", "dev.inmo.micro_utils.coroutines.compose.asMutableComposeState")) -@Suppress("NOTHING_TO_INLINE") -inline fun StateFlow.toMutableState( - scope: CoroutineScope -): MutableState = asMutableComposeState(scope) - diff --git a/gradle.properties b/gradle.properties index 1a2aae47273..5db53e2a94f 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.8 -android_code_version=190 +version=0.18.0 +android_code_version=191 diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 644de2f1e94..250c3e379c5 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -30,13 +30,13 @@ dexcount = "4.0.0" android-coreKtx = "1.10.0" android-recyclerView = "1.3.0" android-appCompat = "1.6.1" -android-fragment = "1.5.6" +android-fragment = "1.5.7" android-espresso = "3.5.1" android-test = "1.1.5" android-props-minSdk = "21" android-props-compileSdk = "33" -android-props-buildTools = "33.0.1" +android-props-buildTools = "33.0.2" [libraries] diff --git a/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/QueryParameters.kt b/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/QueryParameters.kt index 053d316c631..241adfb6290 100644 --- a/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/QueryParameters.kt +++ b/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/QueryParameters.kt @@ -12,10 +12,22 @@ suspend fun ApplicationCall.getParameterOrSendError( } } +suspend fun ApplicationCall.getParametersOrSendError( + field: String +) = parameters.getAll(field).also { + if (it == null) { + respond(HttpStatusCode.BadRequest, "Request must contains $field") + } +} + fun ApplicationCall.getQueryParameter( field: String ) = request.queryParameters[field] +fun ApplicationCall.getQueryParameters( + field: String +) = request.queryParameters.getAll(field) + suspend fun ApplicationCall.getQueryParameterOrSendError( field: String ) = getQueryParameter(field).also { @@ -23,3 +35,11 @@ suspend fun ApplicationCall.getQueryParameterOrSendError( respond(HttpStatusCode.BadRequest, "Request query parameters must contains $field") } } + +suspend fun ApplicationCall.getQueryParametersOrSendError( + field: String +) = getQueryParameters(field).also { + if (it == null) { + respond(HttpStatusCode.BadRequest, "Request query parameters must contains $field") + } +} diff --git a/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/fallback/crud/AutoRecacheWriteCRUDRepo.kt b/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/fallback/crud/AutoRecacheWriteCRUDRepo.kt index ca15411096e..f3ff4c15ff2 100644 --- a/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/fallback/crud/AutoRecacheWriteCRUDRepo.kt +++ b/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/fallback/crud/AutoRecacheWriteCRUDRepo.kt @@ -21,9 +21,9 @@ open class AutoRecacheWriteCRUDRepo( protected val idGetter: (RegisteredObject) -> Id ) : WriteCRUDRepo, FallbackCacheRepo { override val deletedObjectsIdsFlow: Flow - get() = (originalRepo.deletedObjectsIdsFlow + kvCache.onValueRemoved).distinctUntilChanged() + get() = (originalRepo.deletedObjectsIdsFlow).distinctUntilChanged() override val newObjectsFlow: Flow - get() = (originalRepo.newObjectsFlow + kvCache.onNewValue.map { it.second }).distinctUntilChanged() + get() = (originalRepo.newObjectsFlow).distinctUntilChanged() override val updatedObjectsFlow: Flow get() = originalRepo.updatedObjectsFlow diff --git a/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/fallback/keyvalue/AutoRecacheWriteKeyValueRepo.kt b/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/fallback/keyvalue/AutoRecacheWriteKeyValueRepo.kt index 8a725629b36..68f18b5391e 100644 --- a/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/fallback/keyvalue/AutoRecacheWriteKeyValueRepo.kt +++ b/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/fallback/keyvalue/AutoRecacheWriteKeyValueRepo.kt @@ -17,10 +17,10 @@ open class AutoRecacheWriteKeyValueRepo( protected val kvCache: FullKVCache = FullKVCache() ) : WriteKeyValueRepo, FallbackCacheRepo { override val onValueRemoved: Flow - get() = (originalRepo.onValueRemoved + kvCache.onValueRemoved).distinctUntilChanged() + get() = (originalRepo.onValueRemoved).distinctUntilChanged() override val onNewValue: Flow> - get() = (originalRepo.onNewValue + kvCache.onNewValue).distinctUntilChanged() + get() = (originalRepo.onNewValue).distinctUntilChanged() private val onRemovingUpdatesListeningJob = originalRepo.onValueRemoved.subscribeSafelyWithoutExceptions(scope) { kvCache.unset(it) diff --git a/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/fallback/keyvalues/AutoRecacheWriteKeyValuesRepo.kt b/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/fallback/keyvalues/AutoRecacheWriteKeyValuesRepo.kt index 73cf0551472..cd34593ec3c 100644 --- a/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/fallback/keyvalues/AutoRecacheWriteKeyValuesRepo.kt +++ b/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/fallback/keyvalues/AutoRecacheWriteKeyValuesRepo.kt @@ -7,6 +7,7 @@ import dev.inmo.micro_utils.pagination.utils.doForAllWithNextPaging import dev.inmo.micro_utils.repos.WriteKeyValuesRepo import dev.inmo.micro_utils.repos.cache.cache.FullKVCache import dev.inmo.micro_utils.repos.cache.FallbackCacheRepo +import dev.inmo.micro_utils.repos.pagination.maxPagePagination import dev.inmo.micro_utils.repos.set import dev.inmo.micro_utils.repos.unset import kotlinx.coroutines.CoroutineScope @@ -24,7 +25,7 @@ open class AutoRecacheWriteKeyValuesRepo( override val onNewValue: Flow> get() = originalRepo.onNewValue override val onDataCleared: Flow - get() = (originalRepo.onDataCleared + kvCache.onValueRemoved).distinctUntilChanged() + get() = (originalRepo.onDataCleared).distinctUntilChanged() private val onDataClearedListeningJob = originalRepo.onDataCleared.subscribeSafelyWithoutExceptions(scope) { kvCache.unset(it) @@ -50,7 +51,7 @@ open class AutoRecacheWriteKeyValuesRepo( override suspend fun clearWithValue(v: RegisteredObject) { originalRepo.clearWithValue(v) - doForAllWithNextPaging(FirstPagePagination(kvCache.count().takeIf { it < Int.MAX_VALUE } ?.toInt() ?: Int.MAX_VALUE)) { + doForAllWithNextPaging(kvCache.maxPagePagination()) { kvCache.keys(it).also { it.results.forEach { id -> kvCache.get(id) ?.takeIf { it.contains(v) } ?.let { @@ -73,6 +74,19 @@ open class AutoRecacheWriteKeyValuesRepo( } } + override suspend fun removeWithValue(v: RegisteredObject) { + originalRepo.removeWithValue(v) + doForAllWithNextPaging(kvCache.maxPagePagination()) { + kvCache.keys(it).also { + it.results.forEach { id -> + kvCache.get(id) ?.takeIf { it.contains(v) } ?.let { + kvCache.set(id, it - v) + } + } + } + } + } + override suspend fun add(toAdd: Map>) { originalRepo.add(toAdd) toAdd.forEach { (k, v) -> diff --git a/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/full/FullCRUDCacheRepo.kt b/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/full/FullCRUDCacheRepo.kt index 7d8c236c6ad..f5b55e92148 100644 --- a/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/full/FullCRUDCacheRepo.kt +++ b/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/full/FullCRUDCacheRepo.kt @@ -102,8 +102,15 @@ open class FullCRUDCacheRepo( } } +fun CRUDRepo.fullyCached( + kvCache: FullKVCache = FullKVCache(), + scope: CoroutineScope = CoroutineScope(Dispatchers.Default), + idGetter: (ObjectType) -> IdType +) = FullCRUDCacheRepo(this, kvCache, scope, idGetter) + +@Deprecated("Renamed", ReplaceWith("this.fullyCached(kvCache, scope, idGetter)", "dev.inmo.micro_utils.repos.cache.full.fullyCached")) fun CRUDRepo.cached( kvCache: FullKVCache, scope: CoroutineScope = CoroutineScope(Dispatchers.Default), idGetter: (ObjectType) -> IdType -) = FullCRUDCacheRepo(this, kvCache, scope, idGetter) +) = fullyCached(kvCache, scope, idGetter) diff --git a/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/full/FullKeyValueCacheRepo.kt b/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/full/FullKeyValueCacheRepo.kt index 8a985d017be..39e96edc1a8 100644 --- a/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/full/FullKeyValueCacheRepo.kt +++ b/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/full/FullKeyValueCacheRepo.kt @@ -117,7 +117,13 @@ open class FullKeyValueCacheRepo( } } +fun KeyValueRepo.fullyCached( + kvCache: FullKVCache = FullKVCache(), + scope: CoroutineScope = CoroutineScope(Dispatchers.Default) +) = FullKeyValueCacheRepo(this, kvCache, scope) + +@Deprecated("Renamed", ReplaceWith("this.fullyCached(kvCache, scope)", "dev.inmo.micro_utils.repos.cache.full.fullyCached")) fun KeyValueRepo.cached( kvCache: FullKVCache, scope: CoroutineScope = CoroutineScope(Dispatchers.Default) -) = FullKeyValueCacheRepo(this, kvCache, scope) +) = fullyCached(kvCache, scope) diff --git a/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/full/FullKeyValuesCacheRepo.kt b/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/full/FullKeyValuesCacheRepo.kt index fc4bf34db0b..0946cb5c8fe 100644 --- a/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/full/FullKeyValuesCacheRepo.kt +++ b/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/full/FullKeyValuesCacheRepo.kt @@ -157,8 +157,18 @@ open class FullKeyValuesCacheRepo( override suspend fun invalidate() { kvCache.actualizeAll(parentRepo) } + + override suspend fun removeWithValue(v: Value) { + super.removeWithValue(v) + } } +fun KeyValuesRepo.fullyCached( + kvCache: FullKVCache> = FullKVCache(), + scope: CoroutineScope = CoroutineScope(Dispatchers.Default) +) = FullKeyValuesCacheRepo(this, kvCache, scope) + +@Deprecated("Renamed", ReplaceWith("this.fullyCached(kvCache, scope)", "dev.inmo.micro_utils.repos.cache.full.fullyCached")) fun KeyValuesRepo.caching( kvCache: FullKVCache>, scope: CoroutineScope = CoroutineScope(Dispatchers.Default) diff --git a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/KeyValuesRepo.kt b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/KeyValuesRepo.kt index 1754abb70b8..57e8a6331c9 100644 --- a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/KeyValuesRepo.kt +++ b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/KeyValuesRepo.kt @@ -1,6 +1,7 @@ package dev.inmo.micro_utils.repos import dev.inmo.micro_utils.pagination.* +import dev.inmo.micro_utils.pagination.utils.doForAllWithNextPaging import dev.inmo.micro_utils.pagination.utils.getAllWithNextPaging import kotlinx.coroutines.flow.Flow @@ -44,9 +45,23 @@ interface WriteKeyValuesRepo : Repo { suspend fun add(toAdd: Map>) + /** + * Removes [Value]s by passed [Key]s without full clear of all data by [Key] + */ suspend fun remove(toRemove: Map>) + /** + * Removes [v] without full clear of all data by [Key]s with [v] + */ + suspend fun removeWithValue(v: Value) + + /** + * Fully clear all data by [k] + */ suspend fun clear(k: Key) + /** + * Clear [v] **with** full clear of all data by [Key]s with [v] + */ suspend fun clearWithValue(v: Value) suspend fun set(toSet: Map>) { @@ -100,6 +115,21 @@ interface KeyValuesRepo : ReadKeyValuesRepo, WriteKeyVal keysResult.currentPageIfNotEmpty() } } + suspend override fun removeWithValue(v: Value) { + val toRemove = mutableMapOf>() + + doForAllWithNextPaging { + keys(it).also { + it.results.forEach { + if (contains(it, v)) { + toRemove[it] = listOf(v) + } + } + } + } + + remove(toRemove) + } } typealias OneToManyKeyValueRepo = KeyValuesRepo 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 93b165e4c58..fbedd977906 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 @@ -97,6 +97,8 @@ open class MapperWriteKeyValuesRepo( }.toMap() ) + override suspend fun removeWithValue(v: FromValue) = to.removeWithValue(v.toOutValue()) + override suspend fun set(toSet: Map>) { to.set( toSet.map { (k, vs) -> k.toOutKey() to vs.map { v -> v.toOutValue() } }.toMap() diff --git a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/transforms/kvs/KeyValuesFromKeyValueRepo.kt b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/transforms/kvs/KeyValuesFromKeyValueRepo.kt index 7473599f14f..8248959b704 100644 --- a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/transforms/kvs/KeyValuesFromKeyValueRepo.kt +++ b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/transforms/kvs/KeyValuesFromKeyValueRepo.kt @@ -4,6 +4,7 @@ import dev.inmo.micro_utils.pagination.FirstPagePagination import dev.inmo.micro_utils.pagination.utils.doForAllWithNextPaging import dev.inmo.micro_utils.repos.KeyValueRepo import dev.inmo.micro_utils.repos.KeyValuesRepo +import dev.inmo.micro_utils.repos.set import dev.inmo.micro_utils.repos.unset import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableSharedFlow @@ -60,6 +61,24 @@ open class KeyValuesFromKeyValueRepo>() + + doForAllWithNextPaging { + original.keys(it).also { + it.results.forEach { + val data = original.get(it) ?: return@forEach + + if (v in data) { + toRemove[it] = listOf(v) + } + } + } + } + + remove(toRemove) + } + override suspend fun add(toAdd: Map>) { original.set( toAdd.mapNotNull { (k, adding) -> diff --git a/repos/common/src/main/kotlin/dev/inmo/micro_utils/repos/onetomany/OneToManyAndroidRepo.kt b/repos/common/src/main/kotlin/dev/inmo/micro_utils/repos/onetomany/OneToManyAndroidRepo.kt index 11a29614c39..b923563760b 100644 --- a/repos/common/src/main/kotlin/dev/inmo/micro_utils/repos/onetomany/OneToManyAndroidRepo.kt +++ b/repos/common/src/main/kotlin/dev/inmo/micro_utils/repos/onetomany/OneToManyAndroidRepo.kt @@ -6,6 +6,7 @@ import dev.inmo.micro_utils.common.mapNotNullA import dev.inmo.micro_utils.pagination.* import dev.inmo.micro_utils.pagination.utils.reverse import dev.inmo.micro_utils.repos.* +import dev.inmo.micro_utils.repos.crud.asId import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.asSharedFlow @@ -260,6 +261,19 @@ class OneToManyAndroidRepo( _onValueRemoved.emit(k to v) } } + + override suspend fun removeWithValue(v: Value) { + helper.blockingWritableTransaction { + val keys = select(tableName, idColumnArray, "$valueColumnName=?", arrayOf(v.valueAsString())).map { + it.asId.keyFromString() + } + keys.filter { + delete(tableName, "$idColumnName=? AND $valueColumnName=?", arrayOf(it.keyAsString(), v.valueAsString())) > 0 + } + }.forEach { k -> + _onValueRemoved.emit(k to v) + } + } } fun OneToManyAndroidRepo( diff --git a/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/onetomany/ExposedKeyValuesRepo.kt b/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/onetomany/ExposedKeyValuesRepo.kt index 9b79231c8bc..456f2c3106d 100644 --- a/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/onetomany/ExposedKeyValuesRepo.kt +++ b/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/onetomany/ExposedKeyValuesRepo.kt @@ -5,6 +5,7 @@ import dev.inmo.micro_utils.repos.exposed.ColumnAllocator import kotlinx.coroutines.flow.* import org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq +import org.jetbrains.exposed.sql.SqlExpressionBuilder.inList import org.jetbrains.exposed.sql.transactions.transaction typealias ExposedOneToManyKeyValueRepo1 = ExposedKeyValuesRepo @@ -66,9 +67,36 @@ open class ExposedKeyValuesRepo( } } + override suspend fun removeWithValue(v: Value) { + transaction(database) { + val keys = select { selectByValue(v) }.map { it.asKey } + deleteWhere { SqlExpressionBuilder.selectByValue(v) } + keys + }.forEach { + _onValueRemoved.emit(it to v) + } + } + override suspend fun clear(k: Key) { transaction(database) { deleteWhere { keyColumn.eq(k) } }.also { _onDataCleared.emit(k) } } + + override suspend fun clearWithValue(v: Value) { + transaction(database) { + val toClear = select { selectByValue(v) } + .asSequence() + .map { it.asKey to it.asObject } + .groupBy { it.first } + .mapValues { it.value.map { it.second } } + deleteWhere { keyColumn.inList(toClear.keys) } + toClear + }.forEach { + it.value.forEach { v -> + _onValueRemoved.emit(it.key to v) + } + _onDataCleared.emit(it.key) + } + } } diff --git a/repos/inmemory/src/commonMain/kotlin/dev/inmo/micro_utils/repos/MapKeyValuesRepo.kt b/repos/inmemory/src/commonMain/kotlin/dev/inmo/micro_utils/repos/MapKeyValuesRepo.kt index cfe8dff41e8..48acbabd108 100644 --- a/repos/inmemory/src/commonMain/kotlin/dev/inmo/micro_utils/repos/MapKeyValuesRepo.kt +++ b/repos/inmemory/src/commonMain/kotlin/dev/inmo/micro_utils/repos/MapKeyValuesRepo.kt @@ -87,13 +87,27 @@ class MapWriteKeyValuesRepo( } } + override suspend fun removeWithValue(v: Value) { + map.forEach { (k, values) -> + if (values.remove(v)) { + _onValueRemoved.emit(k to v) + } + } + } + override suspend fun clear(k: Key) { map.remove(k) ?.also { _onDataCleared.emit(k) } } override suspend fun clearWithValue(v: Value) { - map.forEach { (k, values) -> - if (values.remove(v)) _onValueRemoved.emit(k to v) + map.filter { (_, values) -> + values.contains(v) + }.forEach { + map.remove(it.key) ?.onEach { v -> + _onValueRemoved.emit(it.key to v) + } ?.also { _ -> + _onDataCleared.emit(it.key) + } } } } diff --git a/repos/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/repos/ktor/client/key/values/KtorWriteKeyValuesRepoClient.kt b/repos/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/repos/ktor/client/key/values/KtorWriteKeyValuesRepoClient.kt index 37f14d66b49..5fe28f0a7af 100644 --- a/repos/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/repos/ktor/client/key/values/KtorWriteKeyValuesRepoClient.kt +++ b/repos/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/repos/ktor/client/key/values/KtorWriteKeyValuesRepoClient.kt @@ -47,6 +47,17 @@ class KtorWriteKeyValuesRepoClient( }.throwOnUnsuccess { "Unable to remove $toRemove" } } + @OptIn(InternalAPI::class) + override suspend fun removeWithValue(v: Value) { + httpClient.post( + buildStandardUrl(baseUrl, removeWithValueRoute) + ) { + body = v + bodyType = valueTypeInfo + contentType(contentType) + }.throwOnUnsuccess { "Unable to remove $v" } + } + @OptIn(InternalAPI::class) override suspend fun clear(k: Key) { httpClient.post( diff --git a/repos/ktor/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/ktor/common/one_to_many/OneToManyRoutes.kt b/repos/ktor/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/ktor/common/one_to_many/OneToManyRoutes.kt index 3bd568bb3a4..00b895d6cbe 100644 --- a/repos/ktor/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/ktor/common/one_to_many/OneToManyRoutes.kt +++ b/repos/ktor/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/ktor/common/one_to_many/OneToManyRoutes.kt @@ -13,6 +13,7 @@ const val onDataClearedRoute = "onDataCleared" const val addRoute = "add" const val removeRoute = "remove" +const val removeWithValueRoute = "removeWithValue" const val clearRoute = "clear" const val clearWithValueRoute = "clearWithValue" const val setRoute = "set" diff --git a/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/key/values/KtorWriteKeyValuesRepoRoutes.kt b/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/key/values/KtorWriteKeyValuesRepoRoutes.kt index 0a37c28f67c..3f78ca0a7be 100644 --- a/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/key/values/KtorWriteKeyValuesRepoRoutes.kt +++ b/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/key/values/KtorWriteKeyValuesRepoRoutes.kt @@ -46,6 +46,11 @@ inline fun Route.configureWriteKeyValue call.respond(HttpStatusCode.OK) } + post(removeWithValueRoute) { + originalRepo.removeWithValue(call.receive()) + call.respond(HttpStatusCode.OK) + } + post(clearRoute) { originalRepo.clear(call.receive()) call.respond(HttpStatusCode.OK) diff --git a/startup/launcher/src/commonMain/kotlin/Start.kt b/startup/launcher/src/commonMain/kotlin/Start.kt deleted file mode 100644 index 3c3c715f50d..00000000000 --- a/startup/launcher/src/commonMain/kotlin/Start.kt +++ /dev/null @@ -1,17 +0,0 @@ -package dev.inmo.micro_utils.startup.launcher - -import dev.inmo.micro_utils.startup.launcher.StartLauncherPlugin.setupDI -import kotlinx.serialization.json.JsonObject -import org.koin.core.KoinApplication - -/** - * Will create [KoinApplication], init, load modules using [StartLauncherPlugin] and start plugins using the same base - * plugin - * - * @param rawConfig It is expected that this [JsonObject] will contain serialized [Config] ([StartLauncherPlugin] will - * deserialize it in its [StartLauncherPlugin.setupDI] - */ -@Deprecated("Fully replaced with StartLauncherPlugin#start", ReplaceWith("StartLauncherPlugin.start(rawConfig)", "dev.inmo.micro_utils.startup.launcher.StartLauncherPlugin")) -suspend fun start(rawConfig: JsonObject) { - StartLauncherPlugin.start(rawConfig) -} diff --git a/startup/launcher/src/jsMain/kotlin/PluginsStarter.kt b/startup/launcher/src/jsMain/kotlin/PluginsStarter.kt deleted file mode 100644 index c0a9944becf..00000000000 --- a/startup/launcher/src/jsMain/kotlin/PluginsStarter.kt +++ /dev/null @@ -1,25 +0,0 @@ -package dev.inmo.micro_utils.startup.launcher - -import dev.inmo.kslog.common.KSLog -import dev.inmo.kslog.common.i -import kotlinx.serialization.json.JsonObject -import kotlinx.serialization.json.jsonObject - -@Deprecated("Useless due to including of the same functionality in StrtLauncherPlugin") -object PluginsStarter { - init { - KSLog.default = KSLog("Launcher") - } - - /** - * It is expected that you have registered all the [dev.inmo.micro_utils.startup.plugin.StartPlugin]s of your JS - * app inside of [dev.inmo.micro_utils.startup.plugin.StartPluginSerializer] using its - * [dev.inmo.micro_utils.startup.plugin.StartPluginSerializer.registerPlugin] method - */ - suspend fun startPlugins(json: JsonObject) = StartLauncherPlugin.start(json) - /** - * Will convert [config] to [JsonObject] with auto registration of [dev.inmo.micro_utils.startup.plugin.StartPlugin]s - * in [dev.inmo.micro_utils.startup.plugin.StartPluginSerializer] - */ - suspend fun startPlugins(config: Config) = StartLauncherPlugin.start(config) -}