From b3bac8015ac44a9cdf7ae85fe65301259b5e9ea7 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 26 Apr 2022 13:35:00 +0600 Subject: [PATCH 01/10] start 0.10.0 --- CHANGELOG.md | 2 ++ gradle.properties | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f656e7402d1..fe5616b2d4e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Changelog +## 0.10.0 + ## 0.9.24 * `Ktor`: diff --git a/gradle.properties b/gradle.properties index 7b86c0ae8a7..d66cba7e505 100644 --- a/gradle.properties +++ b/gradle.properties @@ -14,5 +14,5 @@ crypto_js_version=4.1.1 # Project data group=dev.inmo -version=0.9.24 -android_code_version=114 +version=0.10.0 +android_code_version=115 From eba44cd3944a53bcaacade20ab63c81a63e54bdf Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 26 Apr 2022 13:36:55 +0600 Subject: [PATCH 02/10] update dependencies --- CHANGELOG.md | 7 +++++++ gradle/libs.versions.toml | 12 ++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fe5616b2d4e..a5a201cb3d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ ## 0.10.0 +* `Versions`: + * `Kotlin`: `1.6.10` -> `1.6.21` + * `Compose`: `1.1.1` -> `1.2.0-alpha01-dev675` + * `Exposed`: `0.37.3` -> `0.38.2` + * `Ktor`: `1.6.8` -> `2.0.0` + * `Dokka`: `1.6.10` -> `1.6.21` + ## 0.9.24 * `Ktor`: diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index e269769e4c8..fb6f4318a75 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,19 +1,19 @@ [versions] -kt = "1.6.10" +kt = "1.6.21" kt-serialization = "1.3.2" kt-coroutines = "1.6.1" -jb-compose = "1.1.1" -jb-exposed = "0.37.3" -jb-dokka = "1.6.10" +jb-compose = "1.2.0-alpha01-dev675" +jb-exposed = "0.38.2" +jb-dokka = "1.6.21" klock = "2.7.0" uuid = "0.4.0" -ktor = "1.6.8" +ktor = "2.0.0" -gh-release = "2.2.12" +gh-release = "2.3.7" android-gradle = "7.0.4" dexcount = "3.0.1" From 8364020671d582ea5456a46a0bf82ae042d752ef Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 27 Apr 2022 14:39:21 +0600 Subject: [PATCH 03/10] migration onto new ktor and other dependencies --- build.gradle | 1 + .../dev/inmo/micro_utils/common/Either.kt | 7 --- .../inmo/micro_utils/common/DiffUtilsTests.kt | 19 +++++--- .../coroutines/compose/FlowToState.kt | 1 + gradle/libs.versions.toml | 2 + .../ktor/client/FlowsWebsockets.kt | 6 +-- .../ktor/client/StandardHttpClientGetPost.kt | 17 ++++--- .../ktor/client/ActualTemporalUpload.kt | 7 +-- ktor/server/build.gradle | 3 +- .../micro_utils/ktor/server/FlowsWebsocket.kt | 14 +++--- .../ktor/server/ServerRoutingShortcuts.kt | 44 ++++++++++--------- .../micro_utils/ktor/server/StartServer.kt | 2 +- .../TemporalFilesRoutingConfigurator.kt | 10 ++--- .../ApplicationCachingHeadersConfigurator.kt | 9 ++-- .../ApplicationRoutingConfigurator.kt | 9 ++-- .../ApplicationSessionsConfigurator.kt | 9 ++-- .../KtorApplicationConfigurator.kt | 2 +- .../configurators/StatusPagesConfigurator.kt | 9 ++-- .../generator/src/main/kotlin/Main.kt | 5 ++- .../micro_utils/mime_types/MimeTypeTools.kt | 4 +- .../pagination/ServerPaginationHelpers.kt | 2 +- .../server/crud/KtorReadStandardCrudRepo.kt | 6 +-- .../ktor/server/crud/KtorStandardCrudRepo.kt | 4 +- .../server/crud/KtorWriteStandardCrudRepo.kt | 5 +-- .../key_value/KtorStandartKeyValueRepo.kt | 6 +-- .../key_value/KtorStandartReadKeyValueRepo.kt | 6 +-- .../KtorStandartWriteKeyValueRepo.kt | 4 +- .../ConfigureOneToManyKeyValueRepoRoutes.kt | 6 +-- ...onfigureOneToManyReadKeyValueRepoRoutes.kt | 7 ++- ...nfigureOneToManyWriteKeyValueRepoRoutes.kt | 5 +-- settings.gradle | 6 +++ 31 files changed, 127 insertions(+), 110 deletions(-) diff --git a/build.gradle b/build.gradle index 38310db4281..714b2f1f80c 100644 --- a/build.gradle +++ b/build.gradle @@ -21,6 +21,7 @@ allprojects { mavenLocal() mavenCentral() google() + maven { url "https://maven.pkg.jetbrains.space/public/p/compose/dev" } } // temporal crutch until legacy tests will be stabled or legacy target will be removed 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 682f3c9c4f7..595967582d1 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 @@ -27,13 +27,6 @@ sealed interface Either { @Deprecated("Use optionalT2 instead", ReplaceWith("optionalT2")) val t2: T2? get() = optionalT2.dataOrNull() - - companion object { - fun serializer( - t1Serializer: KSerializer, - t2Serializer: KSerializer, - ): KSerializer> = EitherSerializer(t1Serializer, t2Serializer) - } } class EitherSerializer( diff --git a/common/src/commonTest/kotlin/dev/inmo/micro_utils/common/DiffUtilsTests.kt b/common/src/commonTest/kotlin/dev/inmo/micro_utils/common/DiffUtilsTests.kt index 251c750026b..96916e4d175 100644 --- a/common/src/commonTest/kotlin/dev/inmo/micro_utils/common/DiffUtilsTests.kt +++ b/common/src/commonTest/kotlin/dev/inmo/micro_utils/common/DiffUtilsTests.kt @@ -32,7 +32,7 @@ class DiffUtilsTests { val withIndex = oldList.withIndex() for (count in 1 .. (floor(oldList.size.toFloat() / 2).toInt())) { - for ((i, v) in withIndex) { + for ((i, _) in withIndex) { if (i + count > oldList.lastIndex) { continue } @@ -55,7 +55,7 @@ class DiffUtilsTests { val withIndex = oldList.withIndex() for (step in oldList.indices) { - for ((i, v) in withIndex) { + for ((i, _) in withIndex) { val mutable = oldList.toMutableList() val changes = ( if (step == 0) i until oldList.size else (i until oldList.size step step) @@ -104,7 +104,7 @@ class DiffUtilsTests { val withIndex = oldList.withIndex() for (count in 1 .. (floor(oldList.size.toFloat() / 2).toInt())) { - for ((i, v) in withIndex) { + for ((i, _) in withIndex) { if (i + count > oldList.lastIndex) { continue } @@ -129,15 +129,20 @@ class DiffUtilsTests { val withIndex = oldList.withIndex() for (step in oldList.indices) { - for ((i, v) in withIndex) { + for ((i, _) in withIndex) { val mutable = oldList.toMutableList() - val changes = ( - if (step == 0) i until oldList.size else (i until oldList.size step step) - ).map { index -> + + val newList = if (step == 0) { + i until oldList.size + } else { + i until oldList.size step step + } + newList.forEach { index -> IndexedValue(index, mutable[index]) to IndexedValue(index, "changed$index").also { mutable[index] = it.value } } + val mutableOldList = oldList.toMutableList() mutableOldList.applyDiff(mutable) assertEquals( diff --git a/coroutines/compose/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/compose/FlowToState.kt b/coroutines/compose/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/compose/FlowToState.kt index 22c1b7be83a..7c6d856b22d 100644 --- a/coroutines/compose/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/compose/FlowToState.kt +++ b/coroutines/compose/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/compose/FlowToState.kt @@ -16,6 +16,7 @@ fun Flow.toMutableState( return state } +@Suppress("NOTHING_TO_INLINE") inline fun StateFlow.toMutableState( scope: CoroutineScope ): MutableState = toMutableState(value, scope) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index fb6f4318a75..8a12bd46d70 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -46,6 +46,8 @@ ktor-server = { module = "io.ktor:ktor-server", version.ref = "ktor" } ktor-server-cio = { module = "io.ktor:ktor-server-cio", version.ref = "ktor" } ktor-server-host-common = { module = "io.ktor:ktor-server-host-common", version.ref = "ktor" } ktor-websockets = { module = "io.ktor:ktor-websockets", version.ref = "ktor" } +ktor-server-websockets = { module = "io.ktor:ktor-server-websockets", version.ref = "ktor" } +ktor-server-statusPages = { module = "io.ktor:ktor-server-status-pages", version.ref = "ktor" } klock = { module = "com.soywiz.korlibs.klock:klock", version.ref = "klock" } diff --git a/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/ktor/client/FlowsWebsockets.kt b/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/ktor/client/FlowsWebsockets.kt index 048c92dae3d..599bb3b366d 100644 --- a/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/ktor/client/FlowsWebsockets.kt +++ b/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/ktor/client/FlowsWebsockets.kt @@ -3,10 +3,10 @@ package dev.inmo.micro_utils.ktor.client import dev.inmo.micro_utils.coroutines.safely import dev.inmo.micro_utils.ktor.common.* import io.ktor.client.HttpClient -import io.ktor.client.features.websocket.ws +import io.ktor.client.plugins.websocket.ws import io.ktor.client.request.HttpRequestBuilder -import io.ktor.http.cio.websocket.Frame -import io.ktor.http.cio.websocket.readBytes +import io.ktor.websocket.Frame +import io.ktor.websocket.readBytes import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.channelFlow import kotlinx.serialization.DeserializationStrategy diff --git a/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/ktor/client/StandardHttpClientGetPost.kt b/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/ktor/client/StandardHttpClientGetPost.kt index c7922e312ac..69a0f37e4cd 100644 --- a/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/ktor/client/StandardHttpClientGetPost.kt +++ b/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/ktor/client/StandardHttpClientGetPost.kt @@ -6,6 +6,7 @@ import dev.inmo.micro_utils.ktor.common.* import io.ktor.client.HttpClient import io.ktor.client.request.* import io.ktor.client.request.forms.* +import io.ktor.client.statement.readBytes import io.ktor.http.* import io.ktor.utils.io.core.ByteReadPacket import kotlinx.serialization.* @@ -103,10 +104,10 @@ suspend fun HttpClient.uniget( url: String, resultDeserializer: DeserializationStrategy, serialFormat: StandardKtorSerialFormat = standardKtorSerialFormat -) = get( +) = get( url ).let { - serialFormat.decodeDefault(resultDeserializer, it) + serialFormat.decodeDefault(resultDeserializer, it.readBytes()) } @@ -123,10 +124,12 @@ suspend fun HttpClient.unipost( bodyInfo: BodyPair, resultDeserializer: DeserializationStrategy, serialFormat: StandardKtorSerialFormat = standardKtorSerialFormat -) = post(url) { - body = serialFormat.encodeDefault(bodyInfo.first, bodyInfo.second) +) = post(url) { + setBody( + serialFormat.encodeDefault(bodyInfo.first, bodyInfo.second) + ) }.let { - serialFormat.decodeDefault(resultDeserializer, it) + serialFormat.decodeDefault(resultDeserializer, it.readBytes()) } suspend fun HttpClient.unimultipart( @@ -139,7 +142,7 @@ suspend fun HttpClient.unimultipart( dataHeadersBuilder: HeadersBuilder.() -> Unit = {}, requestBuilder: HttpRequestBuilder.() -> Unit = {}, serialFormat: StandardKtorSerialFormat = standardKtorSerialFormat -): ResultType = submitFormWithBinaryData( +): ResultType = submitFormWithBinaryData( url, formData = formData { append( @@ -155,7 +158,7 @@ suspend fun HttpClient.unimultipart( } ) { requestBuilder() -}.let { serialFormat.decodeDefault(resultDeserializer, it) } +}.let { serialFormat.decodeDefault(resultDeserializer, it.readBytes()) } suspend fun HttpClient.unimultipart( url: String, diff --git a/ktor/client/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/client/ActualTemporalUpload.kt b/ktor/client/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/client/ActualTemporalUpload.kt index f7fbdf9c727..0dcd0dde1f4 100644 --- a/ktor/client/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/client/ActualTemporalUpload.kt +++ b/ktor/client/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/client/ActualTemporalUpload.kt @@ -4,9 +4,10 @@ import dev.inmo.micro_utils.common.MPPFile import dev.inmo.micro_utils.common.filename import dev.inmo.micro_utils.ktor.common.TemporalFileId import io.ktor.client.HttpClient -import io.ktor.client.features.onUpload +import io.ktor.client.plugins.onUpload import io.ktor.client.request.forms.formData import io.ktor.client.request.forms.submitFormWithBinaryData +import io.ktor.client.statement.bodyAsText import io.ktor.http.Headers import io.ktor.http.HttpHeaders import java.net.URLConnection @@ -20,7 +21,7 @@ actual suspend fun HttpClient.tempUpload( onUpload: (Long, Long) -> Unit ): TemporalFileId { val inputProvider = file.inputProvider() - val fileId = submitFormWithBinaryData( + val fileId = submitFormWithBinaryData( fullTempUploadDraftPath, formData = formData { append( @@ -34,6 +35,6 @@ actual suspend fun HttpClient.tempUpload( } ) { onUpload(onUpload) - } + }.bodyAsText() return TemporalFileId(fileId) } diff --git a/ktor/server/build.gradle b/ktor/server/build.gradle index ecf783c0bb2..f42b279e88f 100644 --- a/ktor/server/build.gradle +++ b/ktor/server/build.gradle @@ -19,7 +19,8 @@ kotlin { api libs.ktor.server api libs.ktor.server.cio api libs.ktor.server.host.common - api libs.ktor.websockets + api libs.ktor.server.websockets + api libs.ktor.server.statusPages } } } diff --git a/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/FlowsWebsocket.kt b/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/FlowsWebsocket.kt index 01aaaf2952f..973c47bb418 100644 --- a/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/FlowsWebsocket.kt +++ b/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/FlowsWebsocket.kt @@ -2,13 +2,13 @@ package dev.inmo.micro_utils.ktor.server import dev.inmo.micro_utils.coroutines.safely import dev.inmo.micro_utils.ktor.common.* -import io.ktor.application.featureOrNull -import io.ktor.application.install import io.ktor.http.URLProtocol -import io.ktor.http.cio.websocket.* -import io.ktor.routing.Route -import io.ktor.routing.application -import io.ktor.websocket.* +import io.ktor.server.application.install +import io.ktor.server.application.pluginOrNull +import io.ktor.server.routing.Route +import io.ktor.server.routing.application +import io.ktor.server.websocket.* +import io.ktor.websocket.send import kotlinx.coroutines.flow.Flow import kotlinx.serialization.SerializationStrategy @@ -19,7 +19,7 @@ fun Route.includeWebsocketHandling( converter: suspend WebSocketServerSession.(T) -> StandardKtorSerialInputData? ) { application.apply { - featureOrNull(io.ktor.websocket.WebSockets) ?: install(io.ktor.websocket.WebSockets) + pluginOrNull(WebSockets) ?: install(WebSockets) } webSocket(suburl, protocol.name) { safely { diff --git a/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/ServerRoutingShortcuts.kt b/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/ServerRoutingShortcuts.kt index a31acf31ea8..e0adaaeb0fc 100644 --- a/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/ServerRoutingShortcuts.kt +++ b/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/ServerRoutingShortcuts.kt @@ -3,25 +3,23 @@ package dev.inmo.micro_utils.ktor.server import dev.inmo.micro_utils.common.* import dev.inmo.micro_utils.coroutines.safely import dev.inmo.micro_utils.ktor.common.* -import io.ktor.application.ApplicationCall -import io.ktor.application.call import io.ktor.http.* -import io.ktor.http.content.PartData -import io.ktor.http.content.forEachPart -import io.ktor.request.receive -import io.ktor.request.receiveMultipart -import io.ktor.response.respond -import io.ktor.response.respondBytes -import io.ktor.routing.Route -import io.ktor.util.asStream -import io.ktor.util.cio.writeChannel +import io.ktor.http.content.* +import io.ktor.server.application.ApplicationCall +import io.ktor.server.application.call +import io.ktor.server.request.receive +import io.ktor.server.request.receiveMultipart +import io.ktor.server.response.respond +import io.ktor.server.response.respondBytes +import io.ktor.server.routing.Route +import io.ktor.server.websocket.WebSocketServerSession import io.ktor.util.pipeline.PipelineContext -import io.ktor.utils.io.core.* -import io.ktor.websocket.WebSocketServerSession +import io.ktor.utils.io.core.Input +import io.ktor.utils.io.core.use +import io.ktor.utils.io.streams.asInput import kotlinx.coroutines.flow.Flow -import kotlinx.serialization.* -import java.io.File -import java.io.File.createTempFile +import kotlinx.serialization.DeserializationStrategy +import kotlinx.serialization.SerializationStrategy class UnifiedRouter( val serialFormat: StandardKtorSerialFormat = standardKtorSerialFormat, @@ -134,7 +132,7 @@ suspend fun ApplicationCall.uniloadMultipart( is PartData.FormItem -> onFormItem(it) is PartData.FileItem -> { when (it.name) { - "bytes" -> resultInput = it.provider() + "bytes" -> resultInput = it.streamProvider().asInput() else -> onCustomFileItem(it) } } @@ -156,7 +154,7 @@ suspend fun ApplicationCall.uniloadMultipart( onFormItem, { if (it.name == "data") { - data = standardKtorSerialFormat.decodeDefault(deserializer, it.provider().readBytes()).optional + data = standardKtorSerialFormat.decodeDefault(deserializer, it.streamProvider().readBytes()).optional } else { onCustomFileItem(it) } @@ -197,11 +195,13 @@ suspend fun ApplicationCall.uniloadMultipartFile( ".${name.extension}" ).apply { outputStream().use { fileStream -> - it.provider().asStream().copyTo(fileStream) + it.streamProvider().use { + it.copyTo(fileStream) + } } } } - "data" -> data = standardKtorSerialFormat.decodeDefault(deserializer, it.provider().readBytes()).optional + "data" -> data = standardKtorSerialFormat.decodeDefault(deserializer, it.streamProvider().readBytes()).optional else -> onCustomFileItem(it) } } @@ -239,7 +239,9 @@ suspend fun ApplicationCall.uniloadMultipartFile( ".${name.extension}" ).apply { outputStream().use { fileStream -> - it.provider().asStream().copyTo(fileStream) + it.streamProvider().use { + it.copyTo(fileStream) + } } } } else { diff --git a/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/StartServer.kt b/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/StartServer.kt index 51948300ba2..821403521f6 100644 --- a/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/StartServer.kt +++ b/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/StartServer.kt @@ -1,7 +1,7 @@ package dev.inmo.micro_utils.ktor.server import dev.inmo.micro_utils.ktor.server.configurators.KtorApplicationConfigurator -import io.ktor.application.Application +import io.ktor.server.application.Application import io.ktor.server.cio.CIO import io.ktor.server.cio.CIOApplicationEngine import io.ktor.server.engine.* diff --git a/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/TemporalFilesRoutingConfigurator.kt b/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/TemporalFilesRoutingConfigurator.kt index 9d33c127cbf..e5f2fa6c36e 100644 --- a/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/TemporalFilesRoutingConfigurator.kt +++ b/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/TemporalFilesRoutingConfigurator.kt @@ -7,14 +7,14 @@ import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions import dev.inmo.micro_utils.ktor.common.DefaultTemporalFilesSubPath import dev.inmo.micro_utils.ktor.common.TemporalFileId import dev.inmo.micro_utils.ktor.server.configurators.ApplicationRoutingConfigurator -import io.ktor.application.call import io.ktor.http.HttpStatusCode import io.ktor.http.content.PartData import io.ktor.http.content.streamProvider -import io.ktor.request.receiveMultipart -import io.ktor.response.respond -import io.ktor.routing.Route -import io.ktor.routing.post +import io.ktor.server.application.call +import io.ktor.server.request.receiveMultipart +import io.ktor.server.response.respond +import io.ktor.server.routing.Route +import io.ktor.server.routing.post import kotlinx.coroutines.* import kotlinx.coroutines.flow.* import kotlinx.coroutines.sync.Mutex diff --git a/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/configurators/ApplicationCachingHeadersConfigurator.kt b/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/configurators/ApplicationCachingHeadersConfigurator.kt index eaf14f1f637..1cabb3710ec 100644 --- a/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/configurators/ApplicationCachingHeadersConfigurator.kt +++ b/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/configurators/ApplicationCachingHeadersConfigurator.kt @@ -1,14 +1,15 @@ package dev.inmo.micro_utils.ktor.server.configurators -import io.ktor.application.Application -import io.ktor.application.install -import io.ktor.features.CachingHeaders +import io.ktor.server.application.Application +import io.ktor.server.application.install +import io.ktor.server.plugins.cachingheaders.CachingHeaders +import io.ktor.server.plugins.cachingheaders.CachingHeadersConfig import kotlinx.serialization.Contextual data class ApplicationCachingHeadersConfigurator( private val elements: List<@Contextual Element> ) : KtorApplicationConfigurator { - fun interface Element { operator fun CachingHeaders.Configuration.invoke() } + fun interface Element { operator fun CachingHeadersConfig.invoke() } override fun Application.configure() { install(CachingHeaders) { diff --git a/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/configurators/ApplicationRoutingConfigurator.kt b/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/configurators/ApplicationRoutingConfigurator.kt index 2550dcb813b..3c008d79b87 100644 --- a/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/configurators/ApplicationRoutingConfigurator.kt +++ b/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/configurators/ApplicationRoutingConfigurator.kt @@ -1,8 +1,9 @@ package dev.inmo.micro_utils.ktor.server.configurators -import io.ktor.application.* -import io.ktor.routing.Route -import io.ktor.routing.Routing +import dev.inmo.micro_utils.ktor.server.configurators.ApplicationRoutingConfigurator.Element +import io.ktor.server.application.* +import io.ktor.server.routing.Route +import io.ktor.server.routing.Routing import kotlinx.serialization.Contextual import kotlinx.serialization.Serializable @@ -18,7 +19,7 @@ class ApplicationRoutingConfigurator( } override fun Application.configure() { - featureOrNull(Routing) ?.apply { + pluginOrNull(Routing) ?.apply { rootInstaller.apply { invoke() } } ?: install(Routing) { rootInstaller.apply { invoke() } diff --git a/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/configurators/ApplicationSessionsConfigurator.kt b/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/configurators/ApplicationSessionsConfigurator.kt index 4ed2d16b009..38d7b1a31b9 100644 --- a/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/configurators/ApplicationSessionsConfigurator.kt +++ b/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/configurators/ApplicationSessionsConfigurator.kt @@ -1,14 +1,15 @@ package dev.inmo.micro_utils.ktor.server.configurators -import io.ktor.application.Application -import io.ktor.application.install -import io.ktor.sessions.Sessions +import io.ktor.server.application.Application +import io.ktor.server.application.install +import io.ktor.server.sessions.Sessions +import io.ktor.server.sessions.SessionsConfig import kotlinx.serialization.Contextual class ApplicationSessionsConfigurator( private val elements: List<@Contextual Element> ) : KtorApplicationConfigurator { - fun interface Element { operator fun Sessions.Configuration.invoke() } + fun interface Element { operator fun SessionsConfig.invoke() } override fun Application.configure() { install(Sessions) { diff --git a/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/configurators/KtorApplicationConfigurator.kt b/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/configurators/KtorApplicationConfigurator.kt index dcc877c8fa8..424be129bdc 100644 --- a/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/configurators/KtorApplicationConfigurator.kt +++ b/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/configurators/KtorApplicationConfigurator.kt @@ -1,6 +1,6 @@ package dev.inmo.micro_utils.ktor.server.configurators -import io.ktor.application.Application +import io.ktor.server.application.Application interface KtorApplicationConfigurator { fun Application.configure() diff --git a/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/configurators/StatusPagesConfigurator.kt b/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/configurators/StatusPagesConfigurator.kt index 7e25ba1482b..b880d433d0d 100644 --- a/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/configurators/StatusPagesConfigurator.kt +++ b/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/configurators/StatusPagesConfigurator.kt @@ -1,14 +1,15 @@ package dev.inmo.micro_utils.ktor.server.configurators -import io.ktor.application.Application -import io.ktor.application.install -import io.ktor.features.StatusPages +import io.ktor.server.application.Application +import io.ktor.server.application.install +import io.ktor.server.plugins.statuspages.StatusPages +import io.ktor.server.plugins.statuspages.StatusPagesConfig import kotlinx.serialization.Contextual class StatusPagesConfigurator( private val elements: List<@Contextual Element> ) : KtorApplicationConfigurator { - fun interface Element { operator fun StatusPages.Configuration.invoke() } + fun interface Element { operator fun StatusPagesConfig.invoke() } override fun Application.configure() { install(StatusPages) { diff --git a/language_codes/generator/src/main/kotlin/Main.kt b/language_codes/generator/src/main/kotlin/Main.kt index 7e368fcdf66..e4fa658ec7a 100644 --- a/language_codes/generator/src/main/kotlin/Main.kt +++ b/language_codes/generator/src/main/kotlin/Main.kt @@ -1,5 +1,6 @@ import io.ktor.client.HttpClient import io.ktor.client.request.get +import io.ktor.client.statement.bodyAsText import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import kotlinx.serialization.builtins.ListSerializer @@ -164,7 +165,7 @@ suspend fun main(vararg args: String) { val ietfLanguageCodes = json.decodeFromString( ListSerializer(LanguageCode.serializer()), - client.get(ietfLanguageCodesLink) + client.get(ietfLanguageCodesLink).bodyAsText() ).map { it.copy( title = it.title @@ -175,7 +176,7 @@ suspend fun main(vararg args: String) { } val ietfLanguageCodesWithTagsMap = json.decodeFromString( ListSerializer(LanguageCodeWithTag.serializer()), - client.get(ietfLanguageCodesAdditionalTagsLink) + client.get(ietfLanguageCodesAdditionalTagsLink).bodyAsText() ).filter { it.withSubtag != it.tag }.groupBy { it.tag } val tags = ietfLanguageCodes.map { diff --git a/mime_types/src/commonMain/kotlin/dev/inmo/micro_utils/mime_types/MimeTypeTools.kt b/mime_types/src/commonMain/kotlin/dev/inmo/micro_utils/mime_types/MimeTypeTools.kt index dd285d2f834..a23a7df9304 100644 --- a/mime_types/src/commonMain/kotlin/dev/inmo/micro_utils/mime_types/MimeTypeTools.kt +++ b/mime_types/src/commonMain/kotlin/dev/inmo/micro_utils/mime_types/MimeTypeTools.kt @@ -1,7 +1,6 @@ package dev.inmo.micro_utils.mime_types -import kotlinx.serialization.KSerializer -import kotlinx.serialization.Serializer +import kotlinx.serialization.* import kotlinx.serialization.descriptors.* import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder @@ -16,6 +15,7 @@ fun mimeType(raw: String) = mimesCache.getOrPut(raw) { internal fun parseMimeType(raw: String): MimeType = CustomMimeType(raw) +@Suppress("OPT_IN_USAGE") @Serializer(MimeType::class) object MimeTypeSerializer : KSerializer { override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("mimeType", PrimitiveKind.STRING) diff --git a/pagination/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/pagination/ServerPaginationHelpers.kt b/pagination/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/pagination/ServerPaginationHelpers.kt index 7c68d913a5a..c89a972ff58 100644 --- a/pagination/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/pagination/ServerPaginationHelpers.kt +++ b/pagination/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/pagination/ServerPaginationHelpers.kt @@ -1,7 +1,7 @@ package dev.inmo.micro_utils.pagination -import io.ktor.application.ApplicationCall import io.ktor.http.Parameters +import io.ktor.server.application.ApplicationCall val Parameters.extractPagination: Pagination get() = SimplePagination( diff --git a/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/crud/KtorReadStandardCrudRepo.kt b/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/crud/KtorReadStandardCrudRepo.kt index 82cba432cd2..75053535d03 100644 --- a/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/crud/KtorReadStandardCrudRepo.kt +++ b/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/crud/KtorReadStandardCrudRepo.kt @@ -7,10 +7,10 @@ import dev.inmo.micro_utils.pagination.PaginationResult import dev.inmo.micro_utils.pagination.extractPagination import dev.inmo.micro_utils.repos.ReadStandardCRUDRepo import dev.inmo.micro_utils.repos.ktor.common.crud.* -import io.ktor.application.call import io.ktor.http.ContentType -import io.ktor.routing.Route -import io.ktor.routing.get +import io.ktor.server.application.call +import io.ktor.server.routing.Route +import io.ktor.server.routing.get import kotlinx.serialization.KSerializer import kotlinx.serialization.builtins.serializer diff --git a/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/crud/KtorStandardCrudRepo.kt b/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/crud/KtorStandardCrudRepo.kt index 08685719ec8..d3fd8832d05 100644 --- a/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/crud/KtorStandardCrudRepo.kt +++ b/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/crud/KtorStandardCrudRepo.kt @@ -6,8 +6,8 @@ import dev.inmo.micro_utils.ktor.server.UnifiedRouter import dev.inmo.micro_utils.ktor.server.standardKtorSerialFormatContentType import dev.inmo.micro_utils.repos.StandardCRUDRepo import io.ktor.http.ContentType -import io.ktor.routing.Route -import io.ktor.routing.route +import io.ktor.server.routing.Route +import io.ktor.server.routing.route import kotlinx.serialization.KSerializer fun Route.configureStandardCrudRepoRoutes( diff --git a/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/crud/KtorWriteStandardCrudRepo.kt b/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/crud/KtorWriteStandardCrudRepo.kt index 79f04e84945..f993ab22292 100644 --- a/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/crud/KtorWriteStandardCrudRepo.kt +++ b/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/crud/KtorWriteStandardCrudRepo.kt @@ -5,10 +5,9 @@ import dev.inmo.micro_utils.ktor.common.standardKtorSerialFormat import dev.inmo.micro_utils.ktor.server.* import dev.inmo.micro_utils.repos.WriteStandardCRUDRepo import dev.inmo.micro_utils.repos.ktor.common.crud.* -import io.ktor.application.call import io.ktor.http.ContentType -import io.ktor.routing.Route -import io.ktor.routing.post +import io.ktor.server.routing.Route +import io.ktor.server.routing.post import kotlinx.serialization.KSerializer import kotlinx.serialization.builtins.* diff --git a/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/key_value/KtorStandartKeyValueRepo.kt b/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/key_value/KtorStandartKeyValueRepo.kt index d2cc8f19f04..0ed4f5d1a68 100644 --- a/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/key_value/KtorStandartKeyValueRepo.kt +++ b/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/key_value/KtorStandartKeyValueRepo.kt @@ -6,8 +6,8 @@ import dev.inmo.micro_utils.ktor.server.UnifiedRouter import dev.inmo.micro_utils.ktor.server.standardKtorSerialFormatContentType import dev.inmo.micro_utils.repos.StandardKeyValueRepo import io.ktor.http.ContentType -import io.ktor.routing.Route -import io.ktor.routing.route +import io.ktor.server.routing.Route +import io.ktor.server.routing.route import kotlinx.serialization.KSerializer fun Route.configureStandardKeyValueRepoRoutes( @@ -43,4 +43,4 @@ fun Route.configureStandartKeyValueRepoRoutes( valueNullableSerializer: KSerializer, serialFormat: StandardKtorSerialFormat = standardKtorSerialFormat, serialFormatContentType: ContentType = standardKtorSerialFormatContentType -) = configureStandardKeyValueRepoRoutes(baseSubpart, originalRepo, keySerializer, valueSerializer, valueNullableSerializer, UnifiedRouter(serialFormat, serialFormatContentType)) \ No newline at end of file +) = configureStandardKeyValueRepoRoutes(baseSubpart, originalRepo, keySerializer, valueSerializer, valueNullableSerializer, UnifiedRouter(serialFormat, serialFormatContentType)) diff --git a/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/key_value/KtorStandartReadKeyValueRepo.kt b/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/key_value/KtorStandartReadKeyValueRepo.kt index fd5511914e9..843b935fe18 100644 --- a/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/key_value/KtorStandartReadKeyValueRepo.kt +++ b/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/key_value/KtorStandartReadKeyValueRepo.kt @@ -8,10 +8,10 @@ import dev.inmo.micro_utils.pagination.extractPagination import dev.inmo.micro_utils.repos.ReadStandardKeyValueRepo import dev.inmo.micro_utils.repos.ktor.common.key_value.* import dev.inmo.micro_utils.repos.ktor.common.valueParameterName -import io.ktor.application.call import io.ktor.http.ContentType -import io.ktor.routing.Route -import io.ktor.routing.get +import io.ktor.server.application.call +import io.ktor.server.routing.Route +import io.ktor.server.routing.get import kotlinx.serialization.KSerializer import kotlinx.serialization.builtins.serializer diff --git a/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/key_value/KtorStandartWriteKeyValueRepo.kt b/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/key_value/KtorStandartWriteKeyValueRepo.kt index 56b6e18f413..85179e81771 100644 --- a/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/key_value/KtorStandartWriteKeyValueRepo.kt +++ b/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/key_value/KtorStandartWriteKeyValueRepo.kt @@ -6,8 +6,8 @@ import dev.inmo.micro_utils.ktor.server.* import dev.inmo.micro_utils.repos.WriteStandardKeyValueRepo import dev.inmo.micro_utils.repos.ktor.common.key_value.* import io.ktor.http.ContentType -import io.ktor.routing.Route -import io.ktor.routing.post +import io.ktor.server.routing.Route +import io.ktor.server.routing.post import kotlinx.serialization.KSerializer import kotlinx.serialization.builtins.* diff --git a/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/one_to_many/ConfigureOneToManyKeyValueRepoRoutes.kt b/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/one_to_many/ConfigureOneToManyKeyValueRepoRoutes.kt index 23a16dba545..4f2c694c25d 100644 --- a/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/one_to_many/ConfigureOneToManyKeyValueRepoRoutes.kt +++ b/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/one_to_many/ConfigureOneToManyKeyValueRepoRoutes.kt @@ -6,8 +6,8 @@ import dev.inmo.micro_utils.ktor.server.UnifiedRouter import dev.inmo.micro_utils.ktor.server.standardKtorSerialFormatContentType import dev.inmo.micro_utils.repos.OneToManyKeyValueRepo import io.ktor.http.ContentType -import io.ktor.routing.Route -import io.ktor.routing.route +import io.ktor.server.routing.Route +import io.ktor.server.routing.route import kotlinx.serialization.KSerializer fun Route.configureOneToManyKeyValueRepoRoutes( @@ -32,4 +32,4 @@ fun Route.configureOneToManyKeyValueRepoRoutes( serialFormatContentType: ContentType = standardKtorSerialFormatContentType ) = configureOneToManyKeyValueRepoRoutes( baseSubpart, originalRepo, keySerializer, valueSerializer, UnifiedRouter(serialFormat, serialFormatContentType) -) \ No newline at end of file +) diff --git a/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/one_to_many/ConfigureOneToManyReadKeyValueRepoRoutes.kt b/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/one_to_many/ConfigureOneToManyReadKeyValueRepoRoutes.kt index df0743a1d09..c0795d2280b 100644 --- a/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/one_to_many/ConfigureOneToManyReadKeyValueRepoRoutes.kt +++ b/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/one_to_many/ConfigureOneToManyReadKeyValueRepoRoutes.kt @@ -6,15 +6,14 @@ import dev.inmo.micro_utils.ktor.server.* import dev.inmo.micro_utils.pagination.PaginationResult import dev.inmo.micro_utils.pagination.extractPagination import dev.inmo.micro_utils.repos.ReadOneToManyKeyValueRepo -import dev.inmo.micro_utils.repos.ktor.common.* import dev.inmo.micro_utils.repos.ktor.common.keyParameterName import dev.inmo.micro_utils.repos.ktor.common.one_to_many.* import dev.inmo.micro_utils.repos.ktor.common.valueParameterName import dev.inmo.micro_utils.repos.ktor.common.reversedParameterName -import io.ktor.application.call import io.ktor.http.ContentType -import io.ktor.routing.Route -import io.ktor.routing.get +import io.ktor.server.application.call +import io.ktor.server.routing.Route +import io.ktor.server.routing.get import kotlinx.serialization.KSerializer import kotlinx.serialization.builtins.serializer diff --git a/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/one_to_many/ConfigureOneToManyWriteKeyValueRepoRoutes.kt b/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/one_to_many/ConfigureOneToManyWriteKeyValueRepoRoutes.kt index 2ef6ee6c450..dbef2f3e416 100644 --- a/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/one_to_many/ConfigureOneToManyWriteKeyValueRepoRoutes.kt +++ b/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/one_to_many/ConfigureOneToManyWriteKeyValueRepoRoutes.kt @@ -5,10 +5,9 @@ import dev.inmo.micro_utils.ktor.common.standardKtorSerialFormat import dev.inmo.micro_utils.ktor.server.* import dev.inmo.micro_utils.repos.WriteOneToManyKeyValueRepo import dev.inmo.micro_utils.repos.ktor.common.one_to_many.* -import io.ktor.application.call import io.ktor.http.ContentType -import io.ktor.routing.Route -import io.ktor.routing.post +import io.ktor.server.routing.Route +import io.ktor.server.routing.post import kotlinx.serialization.KSerializer import kotlinx.serialization.builtins.* diff --git a/settings.gradle b/settings.gradle index d7471ac4ccc..6a599f4b73f 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,3 +1,9 @@ +pluginManagement { + repositories { + gradlePluginPortal() + } +} + rootProject.name='micro_utils' String[] includes = [ From 175dd980f8db3f0671867df50ab08b9a0341481e Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 27 Apr 2022 15:15:03 +0600 Subject: [PATCH 04/10] several warnings fixes --- .../kotlin/dev/inmo/micro_utils/common/Annotations.kt | 2 ++ .../kotlin/dev/inmo/micro_utils/common/DiffUtils.kt | 6 +++++- .../kotlin/dev/inmo/micro_utils/common/Either.kt | 2 +- .../dev/inmo/micro_utils/ktor/common/StandardSerializer.kt | 2 ++ .../dev/inmo/micro_utils/pagination/WalkPagination.kt | 1 + .../kotlin/dev/inmo/micro_utils/repos/MapperRepo.kt | 1 + .../dev/inmo/micro_utils/repos/mappers/KeyValueMappers.kt | 3 ++- .../micro_utils/repos/mappers/OneToManyKeyValueMappers.kt | 1 + .../dev/inmo/micro_utils/repos/FileStandardKeyValueRepo.kt | 4 +++- .../dev/inmo/micro_utils/repos/keyvalue/KeyValueStore.kt | 7 ++++++- 10 files changed, 24 insertions(+), 5 deletions(-) diff --git a/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/Annotations.kt b/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/Annotations.kt index 4501df28077..a317e27471a 100644 --- a/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/Annotations.kt +++ b/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/Annotations.kt @@ -1,3 +1,5 @@ +@file:Suppress("OPT_IN_IS_NOT_ENABLED") + package dev.inmo.micro_utils.common @RequiresOptIn( diff --git a/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/DiffUtils.kt b/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/DiffUtils.kt index ab8c6d2ebc6..c1da3f3aa72 100644 --- a/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/DiffUtils.kt +++ b/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/DiffUtils.kt @@ -43,6 +43,7 @@ private inline fun performChanges( if (oldOneEqualToNewObject || newOneEqualToOldObject) { changedList.addAll( potentialChanges.take(i).mapNotNull { + @Suppress("UNCHECKED_CAST") if (it.first != null && it.second != null) it as Pair, IndexedValue> else null } ) @@ -121,7 +122,10 @@ fun Iterable.calculateDiff( when { oldObject === newObject || (oldObject == newObject && !strictComparison) -> { - changedObjects.addAll(potentiallyChangedObjects.map { it as Pair, IndexedValue> }) + changedObjects.addAll(potentiallyChangedObjects.map { + @Suppress("UNCHECKED_CAST") + it as Pair, IndexedValue> + }) potentiallyChangedObjects.clear() } else -> { 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 595967582d1..c07426febe1 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 @@ -33,7 +33,7 @@ class EitherSerializer( t1Serializer: KSerializer, t2Serializer: KSerializer, ) : KSerializer> { - @OptIn(ExperimentalSerializationApi::class, InternalSerializationApi::class) + @OptIn(InternalSerializationApi::class) override val descriptor: SerialDescriptor = buildSerialDescriptor( "TypedSerializer", SerialKind.CONTEXTUAL diff --git a/ktor/common/src/commonMain/kotlin/dev/inmo/micro_utils/ktor/common/StandardSerializer.kt b/ktor/common/src/commonMain/kotlin/dev/inmo/micro_utils/ktor/common/StandardSerializer.kt index 5d088c9721b..0e7163665e0 100644 --- a/ktor/common/src/commonMain/kotlin/dev/inmo/micro_utils/ktor/common/StandardSerializer.kt +++ b/ktor/common/src/commonMain/kotlin/dev/inmo/micro_utils/ktor/common/StandardSerializer.kt @@ -1,3 +1,5 @@ +@file:Suppress("NOTHING_TO_INLINE") + package dev.inmo.micro_utils.ktor.common import kotlinx.serialization.* diff --git a/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/WalkPagination.kt b/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/WalkPagination.kt index 05c1087fed8..e46baf20d68 100644 --- a/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/WalkPagination.kt +++ b/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/WalkPagination.kt @@ -27,4 +27,5 @@ inline fun PaginationResult.thisPageIfNotEmpty(): PaginationResult? = null } +@Suppress("NOTHING_TO_INLINE") inline fun PaginationResult.currentPageIfNotEmpty() = thisPageIfNotEmpty() 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 3d25d74ee2a..313c7970f60 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 @@ -1,5 +1,6 @@ package dev.inmo.micro_utils.repos +@Suppress("UNCHECKED_CAST") interface MapperRepo { suspend fun FromKey.toOutKey() = this as ToKey suspend fun FromValue.toOutValue() = this as ToValue 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 ed67d4c9e4e..3644852d713 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 @@ -126,9 +126,10 @@ inline fun mapper(keyFromToTo, valueFromToTo, keyToToFrom, valueToToFrom) ) +@Suppress("DELEGATED_MEMBER_HIDES_SUPERTYPE_OVERRIDE") open class MapperStandardKeyValueRepo( private val to: StandardKeyValueRepo, - mapper: MapperRepo + private val mapper: MapperRepo ) : StandardKeyValueRepo, MapperRepo by mapper, ReadStandardKeyValueRepo by MapperReadStandardKeyValueRepo(to, 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 97b872a7b1c..74751f79518 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 @@ -132,6 +132,7 @@ inline fun mapper(keyFromToTo, valueFromToTo, keyToToFrom, valueToToFrom) ) +@Suppress("DELEGATED_MEMBER_HIDES_SUPERTYPE_OVERRIDE") open class MapperOneToManyKeyValueRepo( private val to: OneToManyKeyValueRepo, mapper: MapperRepo diff --git a/repos/common/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/FileStandardKeyValueRepo.kt b/repos/common/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/FileStandardKeyValueRepo.kt index 9afb05be768..5e93cfc10e6 100644 --- a/repos/common/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/FileStandardKeyValueRepo.kt +++ b/repos/common/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/FileStandardKeyValueRepo.kt @@ -175,9 +175,11 @@ class FileWriteStandardKeyValueRepo( } @Warning("Files watching will not correctly works on Android Platform with version of API lower than API 26") +@Suppress("DELEGATED_MEMBER_HIDES_SUPERTYPE_OVERRIDE") class FileStandardKeyValueRepo( folder: File, filesChangedProcessingScope: CoroutineScope? = null ) : StandardKeyValueRepo, WriteStandardKeyValueRepo by FileWriteStandardKeyValueRepo(folder, filesChangedProcessingScope), - ReadStandardKeyValueRepo by FileReadStandardKeyValueRepo(folder) \ No newline at end of file + ReadStandardKeyValueRepo by FileReadStandardKeyValueRepo(folder) { +} diff --git a/repos/common/src/main/kotlin/dev/inmo/micro_utils/repos/keyvalue/KeyValueStore.kt b/repos/common/src/main/kotlin/dev/inmo/micro_utils/repos/keyvalue/KeyValueStore.kt index 20ce4d8274e..bc863224c42 100644 --- a/repos/common/src/main/kotlin/dev/inmo/micro_utils/repos/keyvalue/KeyValueStore.kt +++ b/repos/common/src/main/kotlin/dev/inmo/micro_utils/repos/keyvalue/KeyValueStore.kt @@ -16,6 +16,7 @@ fun Context.keyValueStore( name: String = "default", cacheValues: Boolean = false ): StandardKeyValueRepo { + @Suppress("UNCHECKED_CAST") return cache.getOrPut(name) { KeyValueStore(this, name, cacheValues) } as KeyValueStore @@ -62,6 +63,7 @@ class KeyValueStore internal constructor ( } override suspend fun get(k: String): T? { + @Suppress("UNCHECKED_CAST") return (cachedData ?. get(k) ?: sharedPreferences.all[k]) as? T } @@ -73,7 +75,10 @@ class KeyValueStore internal constructor ( PaginationResult( it.page, it.pagesNumber, - it.results.map { it as T }.let { if (reversed) it.reversed() else it }, + it.results.map { + @Suppress("UNCHECKED_CAST") + it as T + }.let { if (reversed) it.reversed() else it }, it.size ) } From db10fe1b2ca2dd6e6406034197ffc7b3c064226f Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 27 Apr 2022 18:24:51 +0600 Subject: [PATCH 05/10] several fixes --- .../ktor/client/StandardHttpClientGetPost.kt | 11 +++++------ .../micro_utils/ktor/server/ServerRoutingShortcuts.kt | 9 ++++----- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/ktor/client/StandardHttpClientGetPost.kt b/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/ktor/client/StandardHttpClientGetPost.kt index 69a0f37e4cd..8ac3e7d571a 100644 --- a/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/ktor/client/StandardHttpClientGetPost.kt +++ b/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/ktor/client/StandardHttpClientGetPost.kt @@ -4,6 +4,7 @@ import dev.inmo.micro_utils.common.MPPFile import dev.inmo.micro_utils.common.filename import dev.inmo.micro_utils.ktor.common.* import io.ktor.client.HttpClient +import io.ktor.client.call.body import io.ktor.client.request.* import io.ktor.client.request.forms.* import io.ktor.client.statement.readBytes @@ -104,10 +105,8 @@ suspend fun HttpClient.uniget( url: String, resultDeserializer: DeserializationStrategy, serialFormat: StandardKtorSerialFormat = standardKtorSerialFormat -) = get( - url -).let { - serialFormat.decodeDefault(resultDeserializer, it.readBytes()) +) = get(url).let { + serialFormat.decodeDefault(resultDeserializer, it.body()) } @@ -129,7 +128,7 @@ suspend fun HttpClient.unipost( serialFormat.encodeDefault(bodyInfo.first, bodyInfo.second) ) }.let { - serialFormat.decodeDefault(resultDeserializer, it.readBytes()) + serialFormat.decodeDefault(resultDeserializer, it.body()) } suspend fun HttpClient.unimultipart( @@ -158,7 +157,7 @@ suspend fun HttpClient.unimultipart( } ) { requestBuilder() -}.let { serialFormat.decodeDefault(resultDeserializer, it.readBytes()) } +}.let { serialFormat.decodeDefault(resultDeserializer, it.body()) } suspend fun HttpClient.unimultipart( url: String, diff --git a/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/ServerRoutingShortcuts.kt b/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/ServerRoutingShortcuts.kt index e0adaaeb0fc..cc4bb0e9d37 100644 --- a/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/ServerRoutingShortcuts.kt +++ b/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/ServerRoutingShortcuts.kt @@ -14,8 +14,7 @@ import io.ktor.server.response.respondBytes import io.ktor.server.routing.Route import io.ktor.server.websocket.WebSocketServerSession import io.ktor.util.pipeline.PipelineContext -import io.ktor.utils.io.core.Input -import io.ktor.utils.io.core.use +import io.ktor.utils.io.core.* import io.ktor.utils.io.streams.asInput import kotlinx.coroutines.flow.Flow import kotlinx.serialization.DeserializationStrategy @@ -132,7 +131,7 @@ suspend fun ApplicationCall.uniloadMultipart( is PartData.FormItem -> onFormItem(it) is PartData.FileItem -> { when (it.name) { - "bytes" -> resultInput = it.streamProvider().asInput() + "bytes" -> resultInput = it.provider() else -> onCustomFileItem(it) } } @@ -154,7 +153,7 @@ suspend fun ApplicationCall.uniloadMultipart( onFormItem, { if (it.name == "data") { - data = standardKtorSerialFormat.decodeDefault(deserializer, it.streamProvider().readBytes()).optional + data = standardKtorSerialFormat.decodeDefault(deserializer, it.provider().readBytes()).optional } else { onCustomFileItem(it) } @@ -201,7 +200,7 @@ suspend fun ApplicationCall.uniloadMultipartFile( } } } - "data" -> data = standardKtorSerialFormat.decodeDefault(deserializer, it.streamProvider().readBytes()).optional + "data" -> data = standardKtorSerialFormat.decodeDefault(deserializer, it.provider().readBytes()).optional else -> onCustomFileItem(it) } } From fba84c8ac87b518dc0b8f473e6fd1c533ad00a07 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 27 Apr 2022 18:30:28 +0600 Subject: [PATCH 06/10] optimize imports in ktor server --- .../dev/inmo/micro_utils/ktor/server/ServerRoutingShortcuts.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/ServerRoutingShortcuts.kt b/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/ServerRoutingShortcuts.kt index cc4bb0e9d37..b2b4e93d751 100644 --- a/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/ServerRoutingShortcuts.kt +++ b/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/ServerRoutingShortcuts.kt @@ -15,7 +15,6 @@ import io.ktor.server.routing.Route import io.ktor.server.websocket.WebSocketServerSession import io.ktor.util.pipeline.PipelineContext import io.ktor.utils.io.core.* -import io.ktor.utils.io.streams.asInput import kotlinx.coroutines.flow.Flow import kotlinx.serialization.DeserializationStrategy import kotlinx.serialization.SerializationStrategy From 0d2b92337802b5a220830cda0107bb28ba729f0a Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 28 Apr 2022 18:16:14 +0600 Subject: [PATCH 07/10] fix signature of createStandardWebsocketFlow --- .../kotlin/dev/inmo/micro_utils/ktor/client/FlowsWebsockets.kt | 2 +- .../inmo/micro_utils/ktor/client/StandardHttpClientGetPost.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/ktor/client/FlowsWebsockets.kt b/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/ktor/client/FlowsWebsockets.kt index 599bb3b366d..b348acbd21a 100644 --- a/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/ktor/client/FlowsWebsockets.kt +++ b/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/ktor/client/FlowsWebsockets.kt @@ -65,8 +65,8 @@ inline fun HttpClient.createStandardWebsocketFlow( */ inline fun HttpClient.createStandardWebsocketFlow( url: String, - crossinline checkReconnection: (Throwable?) -> Boolean = { true }, deserializer: DeserializationStrategy, + crossinline checkReconnection: (Throwable?) -> Boolean = { true }, serialFormat: StandardKtorSerialFormat = standardKtorSerialFormat, noinline requestBuilder: HttpRequestBuilder.() -> Unit = {}, ) = createStandardWebsocketFlow( diff --git a/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/ktor/client/StandardHttpClientGetPost.kt b/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/ktor/client/StandardHttpClientGetPost.kt index 8ac3e7d571a..2e91d9acccd 100644 --- a/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/ktor/client/StandardHttpClientGetPost.kt +++ b/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/ktor/client/StandardHttpClientGetPost.kt @@ -90,7 +90,7 @@ class UnifiedRequester( checkReconnection: (Throwable?) -> Boolean, deserializer: DeserializationStrategy, requestBuilder: HttpRequestBuilder.() -> Unit = {}, - ) = client.createStandardWebsocketFlow(url, checkReconnection, deserializer, serialFormat, requestBuilder) + ) = client.createStandardWebsocketFlow(url, deserializer, checkReconnection, serialFormat, requestBuilder) fun createStandardWebsocketFlow( url: String, From a13cc9e9610711e02fb3de50a72953afe6b56920 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 28 Apr 2022 18:40:18 +0600 Subject: [PATCH 08/10] add error propagation for websockets when websockets has not been installed --- .../dev/inmo/micro_utils/ktor/client/FlowsWebsockets.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/ktor/client/FlowsWebsockets.kt b/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/ktor/client/FlowsWebsockets.kt index b348acbd21a..176f75ee809 100644 --- a/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/ktor/client/FlowsWebsockets.kt +++ b/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/ktor/client/FlowsWebsockets.kt @@ -3,6 +3,8 @@ package dev.inmo.micro_utils.ktor.client import dev.inmo.micro_utils.coroutines.safely import dev.inmo.micro_utils.ktor.common.* import io.ktor.client.HttpClient +import io.ktor.client.plugins.pluginOrNull +import io.ktor.client.plugins.websocket.WebSockets import io.ktor.client.plugins.websocket.ws import io.ktor.client.request.HttpRequestBuilder import io.ktor.websocket.Frame @@ -21,6 +23,8 @@ inline fun HttpClient.createStandardWebsocketFlow( noinline requestBuilder: HttpRequestBuilder.() -> Unit = {}, crossinline conversation: suspend (StandardKtorSerialInputData) -> T ): Flow { + pluginOrNull(WebSockets) ?: error("Plugin $WebSockets must be installed for using createStandardWebsocketFlow") + val correctedUrl = url.asCorrectWebSocketUrl return channelFlow { From 9b9e7dd88f9ae9bf17884992dd714f5f420ec8f9 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 28 Apr 2022 19:43:52 +0600 Subject: [PATCH 09/10] fixes in websockets --- .../ktor/client/FlowsWebsockets.kt | 40 +++++++++---------- .../ktor/client/StandardHttpClientGetPost.kt | 4 +- .../micro_utils/ktor/server/FlowsWebsocket.kt | 6 +-- .../ktor/server/ServerRoutingShortcuts.kt | 2 +- 4 files changed, 25 insertions(+), 27 deletions(-) diff --git a/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/ktor/client/FlowsWebsockets.kt b/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/ktor/client/FlowsWebsockets.kt index 176f75ee809..1b59ee4f2dd 100644 --- a/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/ktor/client/FlowsWebsockets.kt +++ b/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/ktor/client/FlowsWebsockets.kt @@ -1,5 +1,6 @@ package dev.inmo.micro_utils.ktor.client +import dev.inmo.micro_utils.coroutines.runCatchingSafely import dev.inmo.micro_utils.coroutines.safely import dev.inmo.micro_utils.ktor.common.* import io.ktor.client.HttpClient @@ -11,6 +12,7 @@ import io.ktor.websocket.Frame import io.ktor.websocket.readBytes import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.channelFlow +import kotlinx.coroutines.isActive import kotlinx.serialization.DeserializationStrategy /** @@ -19,7 +21,7 @@ import kotlinx.serialization.DeserializationStrategy */ inline fun HttpClient.createStandardWebsocketFlow( url: String, - crossinline checkReconnection: (Throwable?) -> Boolean = { true }, + crossinline checkReconnection: suspend (Throwable?) -> Boolean = { true }, noinline requestBuilder: HttpRequestBuilder.() -> Unit = {}, crossinline conversation: suspend (StandardKtorSerialInputData) -> T ): Flow { @@ -28,36 +30,32 @@ inline fun HttpClient.createStandardWebsocketFlow( val correctedUrl = url.asCorrectWebSocketUrl return channelFlow { - val producerScope = this@channelFlow do { - val reconnect = try { - safely { - ws(correctedUrl, requestBuilder) { - for (received in incoming) { - when (received) { - is Frame.Binary -> producerScope.send(conversation(received.readBytes())) - else -> { - producerScope.close() - return@ws - } + val reconnect = runCatchingSafely { + ws(correctedUrl, requestBuilder) { + for (received in incoming) { + when (received) { + is Frame.Binary -> send(conversation(received.data)) + else -> { + close() + return@ws } } } } checkReconnection(null) - } catch (e: Throwable) { + }.getOrElse { e -> checkReconnection(e).also { if (!it) { - producerScope.close(e) + close(e) } } } - } while (reconnect) - if (!producerScope.isClosedForSend) { - safely( - { it.printStackTrace() } - ) { - producerScope.close() + } while (reconnect && isActive) + + if (isActive) { + safely { + close() } } } @@ -70,7 +68,7 @@ inline fun HttpClient.createStandardWebsocketFlow( inline fun HttpClient.createStandardWebsocketFlow( url: String, deserializer: DeserializationStrategy, - crossinline checkReconnection: (Throwable?) -> Boolean = { true }, + crossinline checkReconnection: suspend (Throwable?) -> Boolean = { true }, serialFormat: StandardKtorSerialFormat = standardKtorSerialFormat, noinline requestBuilder: HttpRequestBuilder.() -> Unit = {}, ) = createStandardWebsocketFlow( diff --git a/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/ktor/client/StandardHttpClientGetPost.kt b/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/ktor/client/StandardHttpClientGetPost.kt index 2e91d9acccd..21c5b28aede 100644 --- a/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/ktor/client/StandardHttpClientGetPost.kt +++ b/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/ktor/client/StandardHttpClientGetPost.kt @@ -87,7 +87,7 @@ class UnifiedRequester( fun createStandardWebsocketFlow( url: String, - checkReconnection: (Throwable?) -> Boolean, + checkReconnection: suspend (Throwable?) -> Boolean, deserializer: DeserializationStrategy, requestBuilder: HttpRequestBuilder.() -> Unit = {}, ) = client.createStandardWebsocketFlow(url, deserializer, checkReconnection, serialFormat, requestBuilder) @@ -96,7 +96,7 @@ class UnifiedRequester( url: String, deserializer: DeserializationStrategy, requestBuilder: HttpRequestBuilder.() -> Unit = {}, - ) = createStandardWebsocketFlow(url, { true }, deserializer, requestBuilder) + ) = createStandardWebsocketFlow(url, { true }, deserializer, requestBuilder) } val defaultRequester = UnifiedRequester() diff --git a/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/FlowsWebsocket.kt b/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/FlowsWebsocket.kt index 973c47bb418..446307ad93a 100644 --- a/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/FlowsWebsocket.kt +++ b/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/FlowsWebsocket.kt @@ -15,13 +15,13 @@ import kotlinx.serialization.SerializationStrategy fun Route.includeWebsocketHandling( suburl: String, flow: Flow, - protocol: URLProtocol = URLProtocol.WS, + protocol: URLProtocol? = null, converter: suspend WebSocketServerSession.(T) -> StandardKtorSerialInputData? ) { application.apply { pluginOrNull(WebSockets) ?: install(WebSockets) } - webSocket(suburl, protocol.name) { + webSocket(suburl, protocol ?.name) { safely { flow.collect { converter(it) ?.let { data -> @@ -37,7 +37,7 @@ fun Route.includeWebsocketHandling( flow: Flow, serializer: SerializationStrategy, serialFormat: StandardKtorSerialFormat = standardKtorSerialFormat, - protocol: URLProtocol = URLProtocol.WS, + protocol: URLProtocol? = null, filter: (suspend WebSocketServerSession.(T) -> Boolean)? = null ) = includeWebsocketHandling( suburl, diff --git a/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/ServerRoutingShortcuts.kt b/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/ServerRoutingShortcuts.kt index b2b4e93d751..962f72e2404 100644 --- a/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/ServerRoutingShortcuts.kt +++ b/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/ServerRoutingShortcuts.kt @@ -27,7 +27,7 @@ class UnifiedRouter( suburl: String, flow: Flow, serializer: SerializationStrategy, - protocol: URLProtocol = URLProtocol.WS, + protocol: URLProtocol? = null, filter: (suspend WebSocketServerSession.(T) -> Boolean)? = null ) = includeWebsocketHandling(suburl, flow, serializer, serialFormat, protocol, filter) From ef530624b97ab226a9c320f25f42920182bf96cf Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 28 Apr 2022 20:30:08 +0600 Subject: [PATCH 10/10] remove redundant pluginManagement --- settings.gradle | 6 ------ 1 file changed, 6 deletions(-) diff --git a/settings.gradle b/settings.gradle index 6a599f4b73f..d7471ac4ccc 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,9 +1,3 @@ -pluginManagement { - repositories { - gradlePluginPortal() - } -} - rootProject.name='micro_utils' String[] includes = [