From a36425a9058cb9519bbc37011e242605317f40ca Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 8 Jan 2023 13:51:34 +0600 Subject: [PATCH 1/6] start 0.16.6 --- CHANGELOG.md | 2 ++ gradle.properties | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 40ef91743ef..9acd16b57df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Changelog +## 0.16.6 + ## 0.16.5 * `Versions`: diff --git a/gradle.properties b/gradle.properties index 4c9d532cfcc..878a2c04bba 100644 --- a/gradle.properties +++ b/gradle.properties @@ -14,5 +14,5 @@ crypto_js_version=4.1.1 # Project data group=dev.inmo -version=0.16.5 -android_code_version=173 +version=0.16.6 +android_code_version=174 From 66fc6df3d7cfbbcb6fb874f0cd7f0b73732fb616 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 8 Jan 2023 13:52:53 +0600 Subject: [PATCH 2/6] Improvements in 'StartLauncherPlugin#start' methods --- CHANGELOG.md | 4 ++ .../commonMain/kotlin/StartLauncherPlugin.kt | 40 ++++++++++--------- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9acd16b57df..490aa1884ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## 0.16.6 +* `Startup`: + * `Launcher`: + * Improvements in `StartLauncherPlugin#start` methods + ## 0.16.5 * `Versions`: diff --git a/startup/launcher/src/commonMain/kotlin/StartLauncherPlugin.kt b/startup/launcher/src/commonMain/kotlin/StartLauncherPlugin.kt index da77a40d929..6d7289da2bd 100644 --- a/startup/launcher/src/commonMain/kotlin/StartLauncherPlugin.kt +++ b/startup/launcher/src/commonMain/kotlin/StartLauncherPlugin.kt @@ -14,6 +14,7 @@ import kotlinx.coroutines.launch import kotlinx.serialization.SerialFormat import kotlinx.serialization.StringFormat import kotlinx.serialization.json.JsonObject +import kotlinx.serialization.json.decodeFromJsonElement import kotlinx.serialization.json.jsonObject import org.koin.core.Koin import org.koin.core.KoinApplication @@ -93,18 +94,19 @@ object StartLauncherPlugin : StartPlugin { /** * Will create [KoinApplication], init, load modules using [StartLauncherPlugin] and start plugins using the same base - * plugin + * plugin. It is basic [start] method which accepts both [config] and [rawConfig] which suppose to be the same or + * at least [rawConfig] must contain serialized variant of [config] * * @param rawConfig It is expected that this [JsonObject] will contain serialized [Config] ([StartLauncherPlugin] will * deserialize it in its [StartLauncherPlugin.setupDI] */ - suspend fun start(rawConfig: JsonObject) { + suspend fun start(config: Config, rawConfig: JsonObject) { logger.i("Start initialization") val koinApp = KoinApplication.init() koinApp.modules( module { - setupDI(rawConfig) + setupDI(config, rawConfig) } ) logger.i("Modules loaded") @@ -116,26 +118,26 @@ object StartLauncherPlugin : StartPlugin { } /** - * Will create [KoinApplication], init, load modules using [StartLauncherPlugin] and start plugins using the same base - * plugin + * Call [start] with deserialized [Config] as config and [rawConfig] as is * - * @param config In difference with other [start] method here config is already deserialized and this config will - * be converted to [JsonObject] as raw config. That means that all plugins from [config] will receive - * serialized version of [config] in [StartPlugin.setupDI] method + * @param rawConfig It is expected that this [JsonObject] will contain serialized [Config] + */ + suspend fun start(rawConfig: JsonObject) { + + start(defaultJson.decodeFromJsonElement(Config.serializer(), rawConfig), rawConfig) + + } + + /** + * Call [start] with deserialized [Config] as is and serialize it to [JsonObject] to pass as the first parameter + * to the basic [start] method + * + * @param config Will be converted to [JsonObject] as raw config. That means that all plugins from [config] will + * receive serialized version of [config] in [StartPlugin.setupDI] method */ suspend fun start(config: Config) { - logger.i("Start initialization") - val koinApp = KoinApplication.init() - logger.i("Koin app created") - koinApp.modules( - module { - setupDI(config) - } - ) - startKoin(koinApp) - logger.i("Koin started") - startPlugin(koinApp.koin) + start(config, defaultJson.encodeToJsonElement(Config.serializer(), config).jsonObject) } } From 99c0f06b726b545413c410a3b082fd628777c534 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 14 Jan 2023 13:15:59 +0600 Subject: [PATCH 3/6] repos update --- CHANGELOG.md | 4 ++ .../ktor/client/crud/KtorCRUDRepoClient.kt | 43 +++++++++++++- .../client/crud/KtorWriteCrudRepoClient.kt | 23 ++++---- .../key/value/KtorKeyValueRepoClient.kt | 22 ++++++- .../key/value/KtorWriteKeyValueRepoClient.kt | 16 ++--- .../key/values/KtorKeyValuesRepoClient.kt | 59 ++++++++++++++++++- .../values/KtorWriteKeyValuesRepoClient.kt | 23 ++++---- 7 files changed, 158 insertions(+), 32 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 490aa1884ac..90662b6203b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ * `Startup`: * `Launcher`: * Improvements in `StartLauncherPlugin#start` methods +* `Repos`: + * `Ktor`: + * `Client`: + * All clients repos got opportunity to customize their flows ## 0.16.5 diff --git a/repos/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/repos/ktor/client/crud/KtorCRUDRepoClient.kt b/repos/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/repos/ktor/client/crud/KtorCRUDRepoClient.kt index 51f79547dcc..811ce434cd1 100644 --- a/repos/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/repos/ktor/client/crud/KtorCRUDRepoClient.kt +++ b/repos/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/repos/ktor/client/crud/KtorCRUDRepoClient.kt @@ -1,12 +1,17 @@ package dev.inmo.micro_utils.repos.ktor.client.crud +import dev.inmo.micro_utils.ktor.client.createStandardWebsocketFlow import dev.inmo.micro_utils.ktor.common.* import dev.inmo.micro_utils.pagination.PaginationResult import dev.inmo.micro_utils.repos.* +import dev.inmo.micro_utils.repos.ktor.common.crud.deletedObjectsIdsFlowRouting +import dev.inmo.micro_utils.repos.ktor.common.crud.newObjectsFlowRouting +import dev.inmo.micro_utils.repos.ktor.common.crud.updatedObjectsFlowRouting import io.ktor.client.HttpClient import io.ktor.http.ContentType import io.ktor.util.reflect.TypeInfo import io.ktor.util.reflect.typeInfo +import kotlinx.coroutines.flow.Flow import kotlinx.serialization.* class KtorCRUDRepoClient ( @@ -21,6 +26,15 @@ class KtorCRUDRepoClient ( baseUrl: String, httpClient: HttpClient, contentType: ContentType, + newObjectsFlow: Flow = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, newObjectsFlowRouting), + ), + updatedObjectsFlow: Flow = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, updatedObjectsFlowRouting), + ), + deletedObjectsIdsFlow: Flow = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, deletedObjectsIdsFlowRouting), + ), noinline idSerializer: suspend (IdType) -> String ) = KtorCRUDRepoClient( KtorReadCRUDRepoClient( @@ -35,7 +49,10 @@ class KtorCRUDRepoClient ( KtorWriteCrudRepoClient( baseUrl, httpClient, - contentType + contentType, + newObjectsFlow, + updatedObjectsFlow, + deletedObjectsIdsFlow ) ) @@ -44,11 +61,23 @@ class KtorCRUDRepoClient ( subpart: String, httpClient: HttpClient, contentType: ContentType, + newObjectsFlow: Flow = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, newObjectsFlowRouting), + ), + updatedObjectsFlow: Flow = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, updatedObjectsFlowRouting), + ), + deletedObjectsIdsFlow: Flow = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, deletedObjectsIdsFlowRouting), + ), noinline idSerializer: suspend (IdType) -> String ) = KtorCRUDRepoClient( buildStandardUrl(baseUrl, subpart), httpClient, contentType, + newObjectsFlow, + updatedObjectsFlow, + deletedObjectsIdsFlow, idSerializer ) } @@ -80,11 +109,23 @@ inline fun KtorCRUDRepo subpart: String, httpClient: HttpClient, contentType: ContentType, + newObjectsFlow: Flow = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, newObjectsFlowRouting), + ), + updatedObjectsFlow: Flow = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, updatedObjectsFlowRouting), + ), + deletedObjectsIdsFlow: Flow = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, deletedObjectsIdsFlowRouting), + ), noinline idSerializer: suspend (IdType) -> String ) = KtorCRUDRepoClient( buildStandardUrl(baseUrl, subpart), httpClient, contentType, + newObjectsFlow, + updatedObjectsFlow, + deletedObjectsIdsFlow, idSerializer ) diff --git a/repos/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/repos/ktor/client/crud/KtorWriteCrudRepoClient.kt b/repos/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/repos/ktor/client/crud/KtorWriteCrudRepoClient.kt index 76270d80271..3fd3de7f319 100644 --- a/repos/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/repos/ktor/client/crud/KtorWriteCrudRepoClient.kt +++ b/repos/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/repos/ktor/client/crud/KtorWriteCrudRepoClient.kt @@ -53,19 +53,22 @@ class KtorWriteCrudRepoClient ( inline operator fun invoke( baseUrl: String, httpClient: HttpClient, - contentType: ContentType + contentType: ContentType, + newObjectsFlow: Flow = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, newObjectsFlowRouting), + ), + updatedObjectsFlow: Flow = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, updatedObjectsFlowRouting), + ), + deletedObjectsIdsFlow: Flow = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, deletedObjectsIdsFlowRouting), + ), ) = KtorWriteCrudRepoClient( baseUrl, httpClient, - httpClient.createStandardWebsocketFlow( - buildStandardUrl(baseUrl, newObjectsFlowRouting), - ), - httpClient.createStandardWebsocketFlow( - buildStandardUrl(baseUrl, updatedObjectsFlowRouting), - ), - httpClient.createStandardWebsocketFlow( - buildStandardUrl(baseUrl, deletedObjectsIdsFlowRouting), - ), + newObjectsFlow, + updatedObjectsFlow, + deletedObjectsIdsFlow, { contentType(contentType) setBody(it) diff --git a/repos/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/repos/ktor/client/key/value/KtorKeyValueRepoClient.kt b/repos/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/repos/ktor/client/key/value/KtorKeyValueRepoClient.kt index b0f6aca4ad3..c6f2b27d9c2 100644 --- a/repos/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/repos/ktor/client/key/value/KtorKeyValueRepoClient.kt +++ b/repos/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/repos/ktor/client/key/value/KtorKeyValueRepoClient.kt @@ -1,10 +1,14 @@ package dev.inmo.micro_utils.repos.ktor.client.key.value +import dev.inmo.micro_utils.ktor.client.createStandardWebsocketFlow import dev.inmo.micro_utils.ktor.common.* import dev.inmo.micro_utils.repos.* +import dev.inmo.micro_utils.repos.ktor.common.key_value.onNewValueRoute +import dev.inmo.micro_utils.repos.ktor.common.key_value.onValueRemovedRoute import io.ktor.client.HttpClient import io.ktor.http.ContentType import io.ktor.http.encodeURLQueryComponent +import kotlinx.coroutines.flow.Flow import kotlinx.serialization.* class KtorKeyValueRepoClient ( @@ -20,6 +24,12 @@ class KtorKeyValueRepoClient ( httpClient: HttpClient, contentType: ContentType, noinline idSerializer: suspend (Key) -> String, + onNewValue: Flow> = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, onNewValueRoute), + ), + onValueRemoved: Flow = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, onValueRemovedRoute), + ), noinline valueSerializer: suspend (Value) -> String ) = KtorKeyValueRepoClient( KtorReadKeyValueRepoClient( @@ -28,7 +38,9 @@ class KtorKeyValueRepoClient ( KtorWriteKeyValueRepoClient( baseUrl, httpClient, - contentType + contentType, + onNewValue, + onValueRemoved ) ) inline operator fun invoke( @@ -37,12 +49,20 @@ class KtorKeyValueRepoClient ( httpClient: HttpClient, contentType: ContentType, noinline idSerializer: suspend (Key) -> String, + onNewValue: Flow> = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, onNewValueRoute), + ), + onValueRemoved: Flow = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, onValueRemovedRoute), + ), noinline valueSerializer: suspend (Value) -> String ) = KtorKeyValueRepoClient( buildStandardUrl(baseUrl, subpart), httpClient, contentType, idSerializer, + onNewValue, + onValueRemoved, valueSerializer ) } diff --git a/repos/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/repos/ktor/client/key/value/KtorWriteKeyValueRepoClient.kt b/repos/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/repos/ktor/client/key/value/KtorWriteKeyValueRepoClient.kt index b8c2ca06f5e..12de3b5538a 100644 --- a/repos/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/repos/ktor/client/key/value/KtorWriteKeyValueRepoClient.kt +++ b/repos/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/repos/ktor/client/key/value/KtorWriteKeyValueRepoClient.kt @@ -60,17 +60,19 @@ class KtorWriteKeyValueRepoClient( inline operator fun invoke( baseUrl: String, httpClient: HttpClient, - contentType: ContentType + contentType: ContentType, + onNewValue: Flow> = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, onNewValueRoute), + ), + onValueRemoved: Flow = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, onValueRemovedRoute), + ), ) = KtorWriteKeyValueRepoClient( baseUrl, httpClient, contentType, - httpClient.createStandardWebsocketFlow( - buildStandardUrl(baseUrl, onNewValueRoute), - ), - httpClient.createStandardWebsocketFlow( - buildStandardUrl(baseUrl, onValueRemovedRoute), - ), + onNewValue, + onValueRemoved, typeInfo>(), typeInfo>(), typeInfo>() diff --git a/repos/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/repos/ktor/client/key/values/KtorKeyValuesRepoClient.kt b/repos/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/repos/ktor/client/key/values/KtorKeyValuesRepoClient.kt index 3913fecd742..467b7a664ac 100644 --- a/repos/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/repos/ktor/client/key/values/KtorKeyValuesRepoClient.kt +++ b/repos/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/repos/ktor/client/key/values/KtorKeyValuesRepoClient.kt @@ -1,10 +1,15 @@ package dev.inmo.micro_utils.repos.ktor.client.key.values +import dev.inmo.micro_utils.ktor.client.createStandardWebsocketFlow import dev.inmo.micro_utils.ktor.common.* import dev.inmo.micro_utils.repos.* +import dev.inmo.micro_utils.repos.ktor.common.one_to_many.onDataClearedRoute +import dev.inmo.micro_utils.repos.ktor.common.one_to_many.onNewValueRoute +import dev.inmo.micro_utils.repos.ktor.common.one_to_many.onValueRemovedRoute import io.ktor.client.HttpClient import io.ktor.http.ContentType import io.ktor.http.encodeURLQueryComponent +import kotlinx.coroutines.flow.Flow import kotlinx.serialization.* class KtorKeyValuesRepoClient ( @@ -20,6 +25,15 @@ class KtorKeyValuesRepoClient ( httpClient: HttpClient, contentType: ContentType, noinline keySerializer: suspend (Key) -> String, + onNewValue: Flow> = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, onNewValueRoute), + ), + onValueRemoved: Flow> = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, onValueRemovedRoute), + ), + onDataCleared: Flow = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, onDataClearedRoute), + ), noinline valueSerializer: suspend (Value) -> String ) = KtorKeyValuesRepoClient( KtorReadKeyValuesRepoClient( @@ -32,7 +46,10 @@ class KtorKeyValuesRepoClient ( KtorWriteKeyValuesRepoClient( baseUrl, httpClient, - contentType + contentType, + onNewValue, + onValueRemoved, + onDataCleared ) ) inline operator fun invoke( @@ -41,12 +58,24 @@ class KtorKeyValuesRepoClient ( httpClient: HttpClient, contentType: ContentType, noinline keySerializer: suspend (Key) -> String, + onNewValue: Flow> = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, onNewValueRoute), + ), + onValueRemoved: Flow> = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, onValueRemovedRoute), + ), + onDataCleared: Flow = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, onDataClearedRoute), + ), noinline valueSerializer: suspend (Value) -> String ) = KtorKeyValuesRepoClient( buildStandardUrl(baseUrl, subpart), httpClient, contentType, keySerializer, + onNewValue, + onValueRemoved, + onDataCleared, valueSerializer ) } @@ -59,13 +88,25 @@ inline fun KtorKeyValuesRepoClient( keySerializer: SerializationStrategy, valueSerializer: SerializationStrategy, serialFormat: StringFormat, + onNewValue: Flow> = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, onNewValueRoute), + ), + onValueRemoved: Flow> = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, onValueRemovedRoute), + ), + onDataCleared: Flow = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, onDataClearedRoute), + ), ) = KtorKeyValuesRepoClient( baseUrl, httpClient, contentType, { serialFormat.encodeToString(keySerializer, it).encodeURLQueryComponent() - } + }, + onNewValue, + onValueRemoved, + onDataCleared ) { serialFormat.encodeToString(valueSerializer, it).encodeURLQueryComponent() } @@ -77,13 +118,25 @@ inline fun KtorKeyValuesRepoClient( keySerializer: SerializationStrategy, valueSerializer: SerializationStrategy, serialFormat: BinaryFormat, + onNewValue: Flow> = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, onNewValueRoute), + ), + onValueRemoved: Flow> = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, onValueRemovedRoute), + ), + onDataCleared: Flow = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, onDataClearedRoute), + ), ) = KtorKeyValuesRepoClient( baseUrl, httpClient, contentType, { serialFormat.encodeHex(keySerializer, it) - } + }, + onNewValue, + onValueRemoved, + onDataCleared ) { serialFormat.encodeHex(valueSerializer, it) } 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 900ae7612cc..37f14d66b49 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 @@ -84,20 +84,23 @@ class KtorWriteKeyValuesRepoClient( inline operator fun invoke( baseUrl: String, httpClient: HttpClient, - contentType: ContentType + contentType: ContentType, + onNewValue: Flow> = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, onNewValueRoute), + ), + onValueRemoved: Flow> = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, onValueRemovedRoute), + ), + onDataCleared: Flow = httpClient.createStandardWebsocketFlow( + buildStandardUrl(baseUrl, onDataClearedRoute), + ), ) = KtorWriteKeyValuesRepoClient( baseUrl, httpClient, contentType, - httpClient.createStandardWebsocketFlow( - buildStandardUrl(baseUrl, onNewValueRoute), - ), - httpClient.createStandardWebsocketFlow( - buildStandardUrl(baseUrl, onValueRemovedRoute), - ), - httpClient.createStandardWebsocketFlow( - buildStandardUrl(baseUrl, onDataClearedRoute), - ), + onNewValue, + onValueRemoved, + onDataCleared, typeInfo(), typeInfo(), typeInfo>>() From e0bdd5dfdc53434aaae92a31361267aa0d489542 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 14 Jan 2023 13:22:07 +0600 Subject: [PATCH 4/6] improvements in microutils --- CHANGELOG.md | 1 + startup/launcher/src/jvmMain/kotlin/Main.kt | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 90662b6203b..eb88cd2b971 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ * `Startup`: * `Launcher`: * Improvements in `StartLauncherPlugin#start` methods + * Add opportunity to pass second argument on `JVM` platform as log level * `Repos`: * `Ktor`: * `Client`: diff --git a/startup/launcher/src/jvmMain/kotlin/Main.kt b/startup/launcher/src/jvmMain/kotlin/Main.kt index d49fe5d99d7..21d5ffe216f 100644 --- a/startup/launcher/src/jvmMain/kotlin/Main.kt +++ b/startup/launcher/src/jvmMain/kotlin/Main.kt @@ -1,6 +1,7 @@ package dev.inmo.micro_utils.startup.launcher import dev.inmo.kslog.common.KSLog +import dev.inmo.kslog.common.LogLevel import dev.inmo.kslog.common.i import kotlinx.serialization.json.jsonObject import java.io.File @@ -23,10 +24,25 @@ import java.io.File * In that case in `build/distributions` folder you will be able to find zip and tar files with all required * tools for application running (via their `bin/app_name` binary). In that case yoy will not need to pass * `--args=...` and launch will look like `./bin/app_name sample.config.json` + * + * ## Debug mode + * + * You may pass the second parameter, one of [LogLevel] enum variants to setup [KSLog] minimal logging level. Sample: + * + * ```bash + * ./gradlew run --args="sample.config.json DEBUG" // enable debugging output + * ``` + * + * OR + * ```bash + * ./gradlew run --args="sample.config.json WARNING" // enable logging since WARNING + * ``` + * + * **Default level is [LogLevel.INFO]** */ suspend fun main(args: Array) { - KSLog.default = KSLog("Launcher") + KSLog.default = KSLog("Launcher", args.getOrNull(1) ?.let { LogLevel.valueOf(it) } ?: LogLevel.INFO) val (configPath) = args val file = File(configPath) KSLog.i("Start read config from ${file.absolutePath}") From f44a78a5f5772d3b69a2bc48d960d17ba9555bdb Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 14 Jan 2023 15:20:52 +0600 Subject: [PATCH 5/6] small improvement of openBaseWebSocketFlow --- .../dev/inmo/micro_utils/ktor/client/NewFlowsWebsockets.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/ktor/client/NewFlowsWebsockets.kt b/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/ktor/client/NewFlowsWebsockets.kt index 95fc92cde3c..95c281f78eb 100644 --- a/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/ktor/client/NewFlowsWebsockets.kt +++ b/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/ktor/client/NewFlowsWebsockets.kt @@ -19,7 +19,7 @@ import kotlinx.coroutines.isActive * connection. Must return true in case if must be reconnected. By default always reconnecting */ @Warning("This feature is internal and should not be used directly. It is can be changed without any notification and warranty on compile-time or other guaranties") -inline fun openBaseWebSocketFlow( +inline fun openBaseWebSocketFlow( noinline checkReconnection: suspend (Throwable?) -> Boolean = { true }, noinline webSocketSessionRequest: suspend SendChannel.() -> Unit ): Flow { @@ -57,7 +57,7 @@ inline fun HttpClient.openWebSocketFlow( ): Flow { pluginOrNull(WebSockets) ?: error("Plugin $WebSockets must be installed for using createStandardWebsocketFlow") - return openBaseWebSocketFlow(checkReconnection) { + return openBaseWebSocketFlow(checkReconnection) { val block: suspend DefaultClientWebSocketSession.() -> Unit = { while (isActive) { send(receiveDeserialized()) From 592c5f373256e1afdd6a443cd7afc3917ae25bb3 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 14 Jan 2023 20:17:57 +0600 Subject: [PATCH 6/6] Column extensions eqOrIsNull and neqOrIsNotNull --- CHANGELOG.md | 2 ++ .../repos/exposed/ColumnEqOrNull.kt | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/ColumnEqOrNull.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index eb88cd2b971..24e11781c26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ * `Ktor`: * `Client`: * All clients repos got opportunity to customize their flows + * `Exposed`: + * Extensions `eqOrIsNull` and `neqOrIsNotNull` for `Column` ## 0.16.5 diff --git a/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/ColumnEqOrNull.kt b/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/ColumnEqOrNull.kt new file mode 100644 index 00000000000..29bc98f6251 --- /dev/null +++ b/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/ColumnEqOrNull.kt @@ -0,0 +1,23 @@ +package dev.inmo.micro_utils.repos.exposed + +import org.jetbrains.exposed.sql.Column +import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq +import org.jetbrains.exposed.sql.SqlExpressionBuilder.isNotNull +import org.jetbrains.exposed.sql.SqlExpressionBuilder.isNull +import org.jetbrains.exposed.sql.SqlExpressionBuilder.neq + +fun Column.eqOrIsNull( + value: T? +) = if (value == null) { + isNull() +} else { + eq(value) +} + +fun Column.neqOrIsNotNull( + value: T? +) = if (value == null) { + isNotNull() +} else { + neq(value) +}