Revert "migrations onto new libraries"

This reverts commit 647cd7d7b4.
This commit is contained in:
InsanusMokrassar 2024-07-30 23:30:11 +06:00
parent 647cd7d7b4
commit 17ba4980d5
21 changed files with 83 additions and 93 deletions

View File

@ -1,19 +1,19 @@
[versions] [versions]
kt = "2.0.20-RC" kt = "2.0.0"
kt-serialization = "1.7.1" kt-serialization = "1.7.1"
kt-coroutines = "1.8.1" kt-coroutines = "1.8.1"
kslog = "1.3.4" kslog = "1.3.4"
jb-compose = "1.7.0-dev1750" jb-compose = "1.7.0-dev1742"
jb-exposed = "0.51.1" jb-exposed = "0.51.1"
jb-dokka = "1.9.20" jb-dokka = "1.9.20"
korlibs = "5.4.0" korlibs = "5.4.0"
uuid = "0.8.4" uuid = "0.8.4"
ktor = "3.0.0-beta-2" ktor = "2.3.11"
gh-release = "2.5.2" gh-release = "2.5.2"

View File

@ -1,3 +1,3 @@
package dev.inmo.micro_utils.ktor.client package dev.inmo.micro_utils.ktor.client
typealias OnUploadCallback = suspend (uploaded: Long, count: Long?) -> Unit typealias OnUploadCallback = suspend (uploaded: Long, count: Long) -> Unit

View File

@ -1,8 +1,10 @@
package dev.inmo.micro_utils.ktor.common package dev.inmo.micro_utils.ktor.common
import io.ktor.utils.io.core.Input import io.ktor.utils.io.core.Input
import kotlinx.io.asSink import io.ktor.utils.io.core.copyTo
import io.ktor.utils.io.streams.asOutput
import java.io.File import java.io.File
import java.io.InputStream
import java.util.UUID import java.util.UUID
fun Input.downloadToTempFile( fun Input.downloadToTempFile(
@ -15,7 +17,7 @@ fun Input.downloadToTempFile(
folder folder
).apply { ).apply {
outputStream().use { outputStream().use {
this@downloadToTempFile.transferTo(it.asSink()) copyTo(it.asOutput())
} }
deleteOnExit() deleteOnExit()
} }

View File

@ -1,9 +1,8 @@
package dev.inmo.micro_utils.ktor.server package dev.inmo.micro_utils.ktor.server
import io.ktor.server.application.ApplicationCall import io.ktor.server.application.ApplicationCall
import io.ktor.server.http.*
import io.ktor.server.response.responseType import io.ktor.server.response.responseType
import io.ktor.utils.io.InternalAPI import io.ktor.util.InternalAPI
import io.ktor.util.reflect.TypeInfo import io.ktor.util.reflect.TypeInfo
@InternalAPI @InternalAPI
@ -12,5 +11,5 @@ suspend fun <T : Any> ApplicationCall.respond(
typeInfo: TypeInfo typeInfo: TypeInfo
) { ) {
response.responseType = typeInfo response.responseType = typeInfo
respond(message, typeInfo) response.pipeline.execute(this, message as Any)
} }

View File

@ -2,19 +2,21 @@ package dev.inmo.micro_utils.ktor.server
import com.benasher44.uuid.uuid4 import com.benasher44.uuid.uuid4
import io.ktor.http.content.PartData import io.ktor.http.content.PartData
import io.ktor.util.cio.* import io.ktor.utils.io.copyTo
import io.ktor.utils.io.* import io.ktor.utils.io.core.copyTo
import io.ktor.utils.io.jvm.javaio.copyTo import io.ktor.utils.io.jvm.javaio.copyTo
import kotlinx.io.asSink import io.ktor.utils.io.streams.asOutput
import java.io.File import java.io.File
suspend fun PartData.FileItem.download(target: File) { fun PartData.FileItem.download(target: File) {
provider().copyAndClose( provider().use { input ->
target.writeChannel() target.outputStream().asOutput().use {
) input.copyTo(it)
}
}
} }
suspend fun PartData.FileItem.downloadToTemporalFile(): File { fun PartData.FileItem.downloadToTemporalFile(): File {
val outputFile = File.createTempFile(uuid4().toString(), ".temp").apply { val outputFile = File.createTempFile(uuid4().toString(), ".temp").apply {
deleteOnExit() deleteOnExit()
} }
@ -25,7 +27,7 @@ suspend fun PartData.FileItem.downloadToTemporalFile(): File {
fun PartData.BinaryItem.download(target: File) { fun PartData.BinaryItem.download(target: File) {
provider().use { input -> provider().use { input ->
target.outputStream().use { target.outputStream().use {
input.transferTo(it.asSink()) input.copyTo(it.asOutput())
} }
} }
} }

View File

@ -5,14 +5,14 @@ import dev.inmo.micro_utils.ktor.common.*
import io.ktor.http.URLProtocol import io.ktor.http.URLProtocol
import io.ktor.server.application.install import io.ktor.server.application.install
import io.ktor.server.application.pluginOrNull import io.ktor.server.application.pluginOrNull
import io.ktor.server.routing.Routing import io.ktor.server.routing.Route
import io.ktor.server.routing.application import io.ktor.server.routing.application
import io.ktor.server.websocket.* import io.ktor.server.websocket.*
import io.ktor.websocket.send import io.ktor.websocket.send
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.serialization.SerializationStrategy import kotlinx.serialization.SerializationStrategy
inline fun <reified T : Any> Routing.includeWebsocketHandling( inline fun <reified T : Any> Route.includeWebsocketHandling(
suburl: String, suburl: String,
flow: Flow<T>, flow: Flow<T>,
protocol: URLProtocol? = null, protocol: URLProtocol? = null,

View File

@ -1,7 +1,7 @@
package dev.inmo.micro_utils.ktor.server package dev.inmo.micro_utils.ktor.server
import dev.inmo.micro_utils.ktor.server.configurators.KtorApplicationConfigurator import dev.inmo.micro_utils.ktor.server.configurators.KtorApplicationConfigurator
import io.ktor.server.application.* import io.ktor.server.application.Application
import io.ktor.server.cio.CIO import io.ktor.server.cio.CIO
import io.ktor.server.cio.CIOApplicationEngine import io.ktor.server.cio.CIOApplicationEngine
import io.ktor.server.engine.* import io.ktor.server.engine.*
@ -11,22 +11,20 @@ fun <TEngine : ApplicationEngine, TConfiguration : ApplicationEngine.Configurati
engine: ApplicationEngineFactory<TEngine, TConfiguration>, engine: ApplicationEngineFactory<TEngine, TConfiguration>,
host: String = "localhost", host: String = "localhost",
port: Int = Random.nextInt(1024, 65535), port: Int = Random.nextInt(1024, 65535),
additionalEngineEnvironmentConfigurator: EngineConnectorBuilder.() -> Unit = {}, additionalEngineEnvironmentConfigurator: ApplicationEngineEnvironmentBuilder.() -> Unit = {},
additionalConfigurationConfigurator: TConfiguration.() -> Unit = {}, additionalConfigurationConfigurator: TConfiguration.() -> Unit = {},
environment: ApplicationEnvironment = applicationEnvironment(),
block: Application.() -> Unit block: Application.() -> Unit
): EmbeddedServer<TEngine, TConfiguration> = embeddedServer<TEngine, TConfiguration>( ): TEngine = embeddedServer(
engine, engine,
environment, applicationEngineEnvironment {
{ module(block)
connector { connector {
this.host = host this.host = host
this.port = port this.port = port
additionalEngineEnvironmentConfigurator()
} }
additionalConfigurationConfigurator() additionalEngineEnvironmentConfigurator()
}, },
module = block additionalConfigurationConfigurator
) )
/** /**
@ -37,17 +35,15 @@ fun <TEngine : ApplicationEngine, TConfiguration : ApplicationEngine.Configurati
fun createKtorServer( fun createKtorServer(
host: String = "localhost", host: String = "localhost",
port: Int = Random.nextInt(1024, 65535), port: Int = Random.nextInt(1024, 65535),
additionalEngineEnvironmentConfigurator: EngineConnectorBuilder.() -> Unit = {}, additionalEngineEnvironmentConfigurator: ApplicationEngineEnvironmentBuilder.() -> Unit = {},
additionalConfigurationConfigurator: CIOApplicationEngine.Configuration.() -> Unit = {}, additionalConfigurationConfigurator: CIOApplicationEngine.Configuration.() -> Unit = {},
environment: ApplicationEnvironment = applicationEnvironment(),
block: Application.() -> Unit block: Application.() -> Unit
): EmbeddedServer<CIOApplicationEngine, CIOApplicationEngine.Configuration> = createKtorServer( ): CIOApplicationEngine = createKtorServer(
CIO, CIO,
host, host,
port, port,
additionalEngineEnvironmentConfigurator, additionalEngineEnvironmentConfigurator,
additionalConfigurationConfigurator, additionalConfigurationConfigurator,
environment,
block block
) )
@ -55,17 +51,15 @@ fun <TEngine : ApplicationEngine, TConfiguration : ApplicationEngine.Configurati
engine: ApplicationEngineFactory<TEngine, TConfiguration>, engine: ApplicationEngineFactory<TEngine, TConfiguration>,
host: String = "localhost", host: String = "localhost",
port: Int = Random.nextInt(1024, 65535), port: Int = Random.nextInt(1024, 65535),
additionalEngineEnvironmentConfigurator: EngineConnectorBuilder.() -> Unit = {}, additionalEngineEnvironmentConfigurator: ApplicationEngineEnvironmentBuilder.() -> Unit = {},
additionalConfigurationConfigurator: TConfiguration.() -> Unit = {}, additionalConfigurationConfigurator: TConfiguration.() -> Unit = {},
environment: ApplicationEnvironment = applicationEnvironment(),
configurators: List<KtorApplicationConfigurator> configurators: List<KtorApplicationConfigurator>
): EmbeddedServer<TEngine, TConfiguration> = createKtorServer( ): TEngine = createKtorServer(
engine, engine,
host, host,
port, port,
additionalEngineEnvironmentConfigurator, additionalEngineEnvironmentConfigurator,
additionalConfigurationConfigurator, additionalConfigurationConfigurator
environment,
) { ) {
configurators.forEach { it.apply { configure() } } configurators.forEach { it.apply { configure() } }
} }
@ -79,7 +73,6 @@ fun createKtorServer(
host: String = "localhost", host: String = "localhost",
port: Int = Random.nextInt(1024, 65535), port: Int = Random.nextInt(1024, 65535),
configurators: List<KtorApplicationConfigurator>, configurators: List<KtorApplicationConfigurator>,
additionalEngineEnvironmentConfigurator: EngineConnectorBuilder.() -> Unit = {}, additionalEngineEnvironmentConfigurator: ApplicationEngineEnvironmentBuilder.() -> Unit = {},
additionalConfigurationConfigurator: CIOApplicationEngine.Configuration.() -> Unit = {}, additionalConfigurationConfigurator: CIOApplicationEngine.Configuration.() -> Unit = {},
environment: ApplicationEnvironment = applicationEnvironment(), ): ApplicationEngine = createKtorServer(CIO, host, port, additionalEngineEnvironmentConfigurator, additionalConfigurationConfigurator, configurators)
): EmbeddedServer<CIOApplicationEngine, CIOApplicationEngine.Configuration> = createKtorServer(CIO, host, port, additionalEngineEnvironmentConfigurator, additionalConfigurationConfigurator, environment, configurators)

View File

@ -14,10 +14,9 @@ import io.ktor.server.application.call
import io.ktor.server.request.receiveMultipart import io.ktor.server.request.receiveMultipart
import io.ktor.server.response.respond import io.ktor.server.response.respond
import io.ktor.server.response.respondText import io.ktor.server.response.respondText
import io.ktor.server.routing.Routing import io.ktor.server.routing.Route
import io.ktor.server.routing.post import io.ktor.server.routing.post
import kotlinx.coroutines.* import kotlinx.coroutines.*
import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.flow.* import kotlinx.coroutines.flow.*
import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock import kotlinx.coroutines.sync.withLock
@ -27,10 +26,7 @@ import java.nio.file.attribute.FileTime
class TemporalFilesRoutingConfigurator( class TemporalFilesRoutingConfigurator(
private val subpath: String = DefaultTemporalFilesSubPath, private val subpath: String = DefaultTemporalFilesSubPath,
private val temporalFilesUtilizer: TemporalFilesUtilizer = TemporalFilesUtilizer, private val temporalFilesUtilizer: TemporalFilesUtilizer = TemporalFilesUtilizer
filesFlowReplay: Int = 0,
filesFlowExtraBufferCapacity: Int = Int.MAX_VALUE,
filesFlowOnBufferOverflow: BufferOverflow = BufferOverflow.SUSPEND
) : ApplicationRoutingConfigurator.Element { ) : ApplicationRoutingConfigurator.Element {
interface TemporalFilesUtilizer { interface TemporalFilesUtilizer {
fun start(filesMap: MutableMap<TemporalFileId, MPPFile>, filesMutex: Mutex, onNewFileFlow: Flow<TemporalFileId>): Job fun start(filesMap: MutableMap<TemporalFileId, MPPFile>, filesMutex: Mutex, onNewFileFlow: Flow<TemporalFileId>): Job
@ -78,14 +74,10 @@ class TemporalFilesRoutingConfigurator(
private val temporalFilesMap = mutableMapOf<TemporalFileId, MPPFile>() private val temporalFilesMap = mutableMapOf<TemporalFileId, MPPFile>()
private val temporalFilesMutex = Mutex() private val temporalFilesMutex = Mutex()
private val filesFlow = MutableSharedFlow<TemporalFileId>( private val filesFlow = MutableSharedFlow<TemporalFileId>()
replay = filesFlowReplay,
extraBufferCapacity = filesFlowExtraBufferCapacity,
onBufferOverflow = filesFlowOnBufferOverflow
)
val utilizerJob = temporalFilesUtilizer.start(temporalFilesMap, temporalFilesMutex, filesFlow.asSharedFlow()) val utilizerJob = temporalFilesUtilizer.start(temporalFilesMap, temporalFilesMutex, filesFlow.asSharedFlow())
override fun Routing.invoke() { override fun Route.invoke() {
post(subpath) { post(subpath) {
val multipart = call.receiveMultipart() val multipart = call.receiveMultipart()
@ -119,7 +111,7 @@ class TemporalFilesRoutingConfigurator(
temporalFilesMap[fileId] = file temporalFilesMap[fileId] = file
} }
call.respondText(fileId.string) call.respondText(fileId.string)
filesFlow.emit(fileId) launchSafelyWithoutExceptions { filesFlow.emit(fileId) }
} ?: call.respond(HttpStatusCode.BadRequest) } ?: call.respond(HttpStatusCode.BadRequest)
} }
} }

View File

@ -6,7 +6,6 @@ import dev.inmo.micro_utils.ktor.common.downloadToTempFile
import io.ktor.http.content.* import io.ktor.http.content.*
import io.ktor.server.application.ApplicationCall import io.ktor.server.application.ApplicationCall
import io.ktor.server.request.receiveMultipart import io.ktor.server.request.receiveMultipart
import io.ktor.utils.io.*
import io.ktor.utils.io.core.* import io.ktor.utils.io.core.*
import kotlinx.coroutines.currentCoroutineContext import kotlinx.coroutines.currentCoroutineContext
import kotlinx.coroutines.isActive import kotlinx.coroutines.isActive
@ -48,7 +47,7 @@ suspend fun ApplicationCall.uniloadMultipart(
onBinaryChannelItem onBinaryChannelItem
) { ) {
when (it.name) { when (it.name) {
"bytes" -> resultInput = it.provider().readBuffer() "bytes" -> resultInput = it.provider()
else -> onCustomFileItem(it) else -> onCustomFileItem(it)
} }
} }

View File

@ -2,7 +2,8 @@ package dev.inmo.micro_utils.ktor.server.configurators
import dev.inmo.micro_utils.ktor.server.configurators.ApplicationRoutingConfigurator.Element import dev.inmo.micro_utils.ktor.server.configurators.ApplicationRoutingConfigurator.Element
import io.ktor.server.application.* import io.ktor.server.application.*
import io.ktor.server.routing.* import io.ktor.server.routing.Route
import io.ktor.server.routing.Routing
import kotlinx.serialization.Contextual import kotlinx.serialization.Contextual
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
@ -10,7 +11,7 @@ import kotlinx.serialization.Serializable
class ApplicationRoutingConfigurator( class ApplicationRoutingConfigurator(
private val elements: List<@Contextual Element> private val elements: List<@Contextual Element>
) : KtorApplicationConfigurator { ) : KtorApplicationConfigurator {
fun interface Element { operator fun Routing.invoke() } fun interface Element { operator fun Route.invoke() }
private val rootInstaller = Element { private val rootInstaller = Element {
elements.forEach { elements.forEach {
it.apply { invoke() } it.apply { invoke() }
@ -18,7 +19,9 @@ class ApplicationRoutingConfigurator(
} }
override fun Application.configure() { override fun Application.configure() {
routing { pluginOrNull(Routing) ?.apply {
rootInstaller.apply { invoke() }
} ?: install(Routing) {
rootInstaller.apply { invoke() } rootInstaller.apply { invoke() }
} }
} }

View File

@ -8,7 +8,7 @@ import dev.inmo.micro_utils.repos.ktor.common.key_value.*
import io.ktor.client.HttpClient import io.ktor.client.HttpClient
import io.ktor.client.request.post import io.ktor.client.request.post
import io.ktor.http.* import io.ktor.http.*
import io.ktor.utils.io.InternalAPI import io.ktor.util.InternalAPI
import io.ktor.util.reflect.TypeInfo import io.ktor.util.reflect.TypeInfo
import io.ktor.util.reflect.typeInfo import io.ktor.util.reflect.typeInfo
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow

View File

@ -8,7 +8,7 @@ import dev.inmo.micro_utils.repos.ktor.common.one_to_many.*
import io.ktor.client.HttpClient import io.ktor.client.HttpClient
import io.ktor.client.request.post import io.ktor.client.request.post
import io.ktor.http.* import io.ktor.http.*
import io.ktor.utils.io.InternalAPI import io.ktor.util.InternalAPI
import io.ktor.util.reflect.TypeInfo import io.ktor.util.reflect.TypeInfo
import io.ktor.util.reflect.typeInfo import io.ktor.util.reflect.typeInfo
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow

View File

@ -2,10 +2,10 @@ package dev.inmo.micro_utils.repos.ktor.server.crud
import dev.inmo.micro_utils.ktor.common.* import dev.inmo.micro_utils.ktor.common.*
import dev.inmo.micro_utils.repos.CRUDRepo import dev.inmo.micro_utils.repos.CRUDRepo
import io.ktor.server.routing.Routing import io.ktor.server.routing.Route
import kotlinx.serialization.* import kotlinx.serialization.*
inline fun <reified ObjectType : Any, reified IdType : Any, reified InputValue : Any> Routing.configureCRUDRepoRoutes( inline fun <reified ObjectType : Any, reified IdType : Any, reified InputValue : Any> Route.configureCRUDRepoRoutes(
originalRepo: CRUDRepo<ObjectType, IdType, InputValue>, originalRepo: CRUDRepo<ObjectType, IdType, InputValue>,
noinline idDeserializer: suspend (String) -> IdType noinline idDeserializer: suspend (String) -> IdType
) { ) {
@ -13,7 +13,7 @@ inline fun <reified ObjectType : Any, reified IdType : Any, reified InputValue :
configureWriteCRUDRepoRoutes(originalRepo) configureWriteCRUDRepoRoutes(originalRepo)
} }
inline fun <reified ObjectType : Any, reified IdType : Any, reified InputValue : Any> Routing.configureCRUDRepoRoutes( inline fun <reified ObjectType : Any, reified IdType : Any, reified InputValue : Any> Route.configureCRUDRepoRoutes(
originalRepo: CRUDRepo<ObjectType, IdType, InputValue>, originalRepo: CRUDRepo<ObjectType, IdType, InputValue>,
idsSerializer: KSerializer<IdType>, idsSerializer: KSerializer<IdType>,
serialFormat: StringFormat serialFormat: StringFormat
@ -21,7 +21,7 @@ inline fun <reified ObjectType : Any, reified IdType : Any, reified InputValue :
serialFormat.decodeFromString(idsSerializer, it) serialFormat.decodeFromString(idsSerializer, it)
} }
inline fun <reified ObjectType : Any, reified IdType : Any, reified InputValue : Any> Routing.configureCRUDRepoRoutes( inline fun <reified ObjectType : Any, reified IdType : Any, reified InputValue : Any> Route.configureCRUDRepoRoutes(
originalRepo: CRUDRepo<ObjectType, IdType, InputValue>, originalRepo: CRUDRepo<ObjectType, IdType, InputValue>,
idsSerializer: KSerializer<IdType>, idsSerializer: KSerializer<IdType>,
serialFormat: BinaryFormat serialFormat: BinaryFormat

View File

@ -11,11 +11,11 @@ import dev.inmo.micro_utils.repos.ktor.common.idParameterName
import io.ktor.http.HttpStatusCode import io.ktor.http.HttpStatusCode
import io.ktor.server.application.call import io.ktor.server.application.call
import io.ktor.server.response.respond import io.ktor.server.response.respond
import io.ktor.server.routing.Routing import io.ktor.server.routing.Route
import io.ktor.server.routing.get import io.ktor.server.routing.get
import kotlinx.serialization.* import kotlinx.serialization.*
inline fun <reified ObjectType, reified IdType> Routing.configureReadCRUDRepoRoutes( inline fun <reified ObjectType, reified IdType> Route.configureReadCRUDRepoRoutes(
originalRepo: ReadCRUDRepo<ObjectType, IdType>, originalRepo: ReadCRUDRepo<ObjectType, IdType>,
noinline idDeserializer: suspend (String) -> IdType noinline idDeserializer: suspend (String) -> IdType
) { ) {
@ -65,7 +65,7 @@ inline fun <reified ObjectType, reified IdType> Routing.configureReadCRUDRepoRou
} }
} }
inline fun <reified ObjectType, reified IdType> Routing.configureReadCRUDRepoRoutes( inline fun <reified ObjectType, reified IdType> Route.configureReadCRUDRepoRoutes(
originalRepo: ReadCRUDRepo<ObjectType, IdType>, originalRepo: ReadCRUDRepo<ObjectType, IdType>,
idsSerializer: KSerializer<IdType>, idsSerializer: KSerializer<IdType>,
serialFormat: StringFormat serialFormat: StringFormat
@ -73,7 +73,7 @@ inline fun <reified ObjectType, reified IdType> Routing.configureReadCRUDRepoRou
serialFormat.decodeFromString(idsSerializer, it) serialFormat.decodeFromString(idsSerializer, it)
} }
inline fun <reified ObjectType, reified IdType> Routing.configureReadCRUDRepoRoutes( inline fun <reified ObjectType, reified IdType> Route.configureReadCRUDRepoRoutes(
originalRepo: ReadCRUDRepo<ObjectType, IdType>, originalRepo: ReadCRUDRepo<ObjectType, IdType>,
idsSerializer: KSerializer<IdType>, idsSerializer: KSerializer<IdType>,
serialFormat: BinaryFormat serialFormat: BinaryFormat

View File

@ -7,10 +7,10 @@ import io.ktor.http.HttpStatusCode
import io.ktor.server.application.call import io.ktor.server.application.call
import io.ktor.server.request.receive import io.ktor.server.request.receive
import io.ktor.server.response.respond import io.ktor.server.response.respond
import io.ktor.server.routing.Routing import io.ktor.server.routing.Route
import io.ktor.server.routing.post import io.ktor.server.routing.post
inline fun <reified ObjectType : Any, reified IdType : Any, reified InputValue : Any> Routing.configureWriteCRUDRepoRoutes( inline fun <reified ObjectType : Any, reified IdType : Any, reified InputValue : Any> Route.configureWriteCRUDRepoRoutes(
originalRepo: WriteCRUDRepo<ObjectType, IdType, InputValue> originalRepo: WriteCRUDRepo<ObjectType, IdType, InputValue>
) { ) {
includeWebsocketHandling( includeWebsocketHandling(

View File

@ -3,10 +3,10 @@ package dev.inmo.micro_utils.repos.ktor.server.key.value
import dev.inmo.micro_utils.ktor.common.* import dev.inmo.micro_utils.ktor.common.*
import dev.inmo.micro_utils.repos.KeyValueRepo import dev.inmo.micro_utils.repos.KeyValueRepo
import io.ktor.http.* import io.ktor.http.*
import io.ktor.server.routing.Routing import io.ktor.server.routing.Route
import kotlinx.serialization.* import kotlinx.serialization.*
inline fun <reified Key : Any, reified Value : Any> Routing.configureKeyValueRepoRoutes ( inline fun <reified Key : Any, reified Value : Any> Route.configureKeyValueRepoRoutes (
originalRepo: KeyValueRepo<Key, Value>, originalRepo: KeyValueRepo<Key, Value>,
noinline idDeserializer: suspend (String) -> Key, noinline idDeserializer: suspend (String) -> Key,
noinline valueDeserializer: suspend (String) -> Value noinline valueDeserializer: suspend (String) -> Value
@ -15,7 +15,7 @@ inline fun <reified Key : Any, reified Value : Any> Routing.configureKeyValueRep
configureWriteKeyValueRepoRoutes(originalRepo) configureWriteKeyValueRepoRoutes(originalRepo)
} }
inline fun <reified Key : Any, reified Value : Any> Routing.configureKeyValueRepoRoutes( inline fun <reified Key : Any, reified Value : Any> Route.configureKeyValueRepoRoutes(
originalRepo: KeyValueRepo<Key, Value>, originalRepo: KeyValueRepo<Key, Value>,
idsSerializer: DeserializationStrategy<Key>, idsSerializer: DeserializationStrategy<Key>,
valueSerializer: DeserializationStrategy<Value>, valueSerializer: DeserializationStrategy<Value>,
@ -30,7 +30,7 @@ inline fun <reified Key : Any, reified Value : Any> Routing.configureKeyValueRep
} }
) )
inline fun <reified Key : Any, reified Value : Any> Routing.configureKeyValueRepoRoutes( inline fun <reified Key : Any, reified Value : Any> Route.configureKeyValueRepoRoutes(
originalRepo: KeyValueRepo<Key, Value>, originalRepo: KeyValueRepo<Key, Value>,
idsSerializer: DeserializationStrategy<Key>, idsSerializer: DeserializationStrategy<Key>,
valueSerializer: DeserializationStrategy<Value>, valueSerializer: DeserializationStrategy<Value>,

View File

@ -14,14 +14,14 @@ import dev.inmo.micro_utils.repos.ktor.common.reversedParameterName
import io.ktor.http.* import io.ktor.http.*
import io.ktor.server.application.call import io.ktor.server.application.call
import io.ktor.server.response.respond import io.ktor.server.response.respond
import io.ktor.server.routing.Routing import io.ktor.server.routing.Route
import io.ktor.server.routing.get import io.ktor.server.routing.get
import io.ktor.utils.io.InternalAPI import io.ktor.util.InternalAPI
import io.ktor.util.reflect.typeInfo import io.ktor.util.reflect.typeInfo
import kotlinx.serialization.* import kotlinx.serialization.*
@OptIn(InternalAPI::class) @OptIn(InternalAPI::class)
inline fun <reified Key, reified Value> Routing.configureReadKeyValueRepoRoutes ( inline fun <reified Key, reified Value> Route.configureReadKeyValueRepoRoutes (
originalRepo: ReadKeyValueRepo<Key, Value>, originalRepo: ReadKeyValueRepo<Key, Value>,
noinline idDeserializer: suspend (String) -> Key, noinline idDeserializer: suspend (String) -> Key,
noinline valueDeserializer: suspend (String) -> Value noinline valueDeserializer: suspend (String) -> Value
@ -79,7 +79,7 @@ inline fun <reified Key, reified Value> Routing.configureReadKeyValueRepoRoutes
} }
} }
inline fun <reified Key, reified Value> Routing.configureReadKeyValueRepoRoutes( inline fun <reified Key, reified Value> Route.configureReadKeyValueRepoRoutes(
originalRepo: ReadKeyValueRepo<Key, Value>, originalRepo: ReadKeyValueRepo<Key, Value>,
idsSerializer: DeserializationStrategy<Key>, idsSerializer: DeserializationStrategy<Key>,
valueSerializer: DeserializationStrategy<Value>, valueSerializer: DeserializationStrategy<Value>,
@ -94,7 +94,7 @@ inline fun <reified Key, reified Value> Routing.configureReadKeyValueRepoRoutes(
} }
) )
inline fun <reified Key, reified Value> Routing.configureReadKeyValueRepoRoutes( inline fun <reified Key, reified Value> Route.configureReadKeyValueRepoRoutes(
originalRepo: ReadKeyValueRepo<Key, Value>, originalRepo: ReadKeyValueRepo<Key, Value>,
idsSerializer: DeserializationStrategy<Key>, idsSerializer: DeserializationStrategy<Key>,
valueSerializer: DeserializationStrategy<Value>, valueSerializer: DeserializationStrategy<Value>,

View File

@ -7,11 +7,11 @@ import io.ktor.http.HttpStatusCode
import io.ktor.server.application.call import io.ktor.server.application.call
import io.ktor.server.request.receive import io.ktor.server.request.receive
import io.ktor.server.response.respond import io.ktor.server.response.respond
import io.ktor.server.routing.Routing import io.ktor.server.routing.Route
import io.ktor.server.routing.post import io.ktor.server.routing.post
import io.ktor.util.reflect.typeInfo import io.ktor.util.reflect.typeInfo
inline fun <reified Key : Any, reified Value : Any> Routing.configureWriteKeyValueRepoRoutes ( inline fun <reified Key : Any, reified Value : Any> Route.configureWriteKeyValueRepoRoutes (
originalRepo: WriteKeyValueRepo<Key, Value> originalRepo: WriteKeyValueRepo<Key, Value>
) { ) {
includeWebsocketHandling( includeWebsocketHandling(

View File

@ -3,10 +3,10 @@ package dev.inmo.micro_utils.repos.ktor.server.key.values
import dev.inmo.micro_utils.ktor.common.* import dev.inmo.micro_utils.ktor.common.*
import dev.inmo.micro_utils.repos.* import dev.inmo.micro_utils.repos.*
import io.ktor.http.* import io.ktor.http.*
import io.ktor.server.routing.Routing import io.ktor.server.routing.Route
import kotlinx.serialization.* import kotlinx.serialization.*
inline fun <reified Key : Any, reified Value : Any> Routing.configureKeyValuesRepoRoutes ( inline fun <reified Key : Any, reified Value : Any> Route.configureKeyValuesRepoRoutes (
originalRepo: KeyValuesRepo<Key, Value>, originalRepo: KeyValuesRepo<Key, Value>,
noinline keyDeserializer: suspend (String) -> Key, noinline keyDeserializer: suspend (String) -> Key,
noinline valueDeserializer: suspend (String) -> Value noinline valueDeserializer: suspend (String) -> Value
@ -15,7 +15,7 @@ inline fun <reified Key : Any, reified Value : Any> Routing.configureKeyValuesRe
configureWriteKeyValuesRepoRoutes(originalRepo) configureWriteKeyValuesRepoRoutes(originalRepo)
} }
inline fun <reified Key : Any, reified Value : Any> Routing.configureKeyValuesRepoRoutes( inline fun <reified Key : Any, reified Value : Any> Route.configureKeyValuesRepoRoutes(
originalRepo: KeyValuesRepo<Key, Value>, originalRepo: KeyValuesRepo<Key, Value>,
keySerializer: DeserializationStrategy<Key>, keySerializer: DeserializationStrategy<Key>,
valueSerializer: DeserializationStrategy<Value>, valueSerializer: DeserializationStrategy<Value>,
@ -30,7 +30,7 @@ inline fun <reified Key : Any, reified Value : Any> Routing.configureKeyValuesRe
} }
) )
inline fun <reified Key : Any, reified Value : Any> Routing.configureKeyValuesRepoRoutes( inline fun <reified Key : Any, reified Value : Any> Route.configureKeyValuesRepoRoutes(
originalRepo: KeyValuesRepo<Key, Value>, originalRepo: KeyValuesRepo<Key, Value>,
keySerializer: DeserializationStrategy<Key>, keySerializer: DeserializationStrategy<Key>,
valueSerializer: DeserializationStrategy<Value>, valueSerializer: DeserializationStrategy<Value>,

View File

@ -12,14 +12,14 @@ import dev.inmo.micro_utils.repos.ktor.common.one_to_many.*
import io.ktor.http.* import io.ktor.http.*
import io.ktor.server.application.call import io.ktor.server.application.call
import io.ktor.server.response.respond import io.ktor.server.response.respond
import io.ktor.server.routing.Routing import io.ktor.server.routing.Route
import io.ktor.server.routing.get import io.ktor.server.routing.get
import io.ktor.utils.io.InternalAPI import io.ktor.util.InternalAPI
import io.ktor.util.reflect.typeInfo import io.ktor.util.reflect.typeInfo
import kotlinx.serialization.* import kotlinx.serialization.*
@OptIn(InternalAPI::class) @OptIn(InternalAPI::class)
inline fun <reified Key, reified Value> Routing.configureReadKeyValuesRepoRoutes ( inline fun <reified Key, reified Value> Route.configureReadKeyValuesRepoRoutes (
originalRepo: ReadKeyValuesRepo<Key, Value>, originalRepo: ReadKeyValuesRepo<Key, Value>,
noinline keyDeserializer: suspend (String) -> Key, noinline keyDeserializer: suspend (String) -> Key,
noinline valueDeserializer: suspend (String) -> Value noinline valueDeserializer: suspend (String) -> Value
@ -76,7 +76,7 @@ inline fun <reified Key, reified Value> Routing.configureReadKeyValuesRepoRoutes
} }
} }
inline fun <reified Key, reified Value> Routing.configureReadKeyValuesRepoRoutes( inline fun <reified Key, reified Value> Route.configureReadKeyValuesRepoRoutes(
originalRepo: ReadKeyValuesRepo<Key, Value>, originalRepo: ReadKeyValuesRepo<Key, Value>,
keySerializer: DeserializationStrategy<Key>, keySerializer: DeserializationStrategy<Key>,
valueSerializer: DeserializationStrategy<Value>, valueSerializer: DeserializationStrategy<Value>,
@ -91,7 +91,7 @@ inline fun <reified Key, reified Value> Routing.configureReadKeyValuesRepoRoutes
} }
) )
inline fun <reified Key, reified Value> Routing.configureReadKeyValuesRepoRoutes( inline fun <reified Key, reified Value> Route.configureReadKeyValuesRepoRoutes(
originalRepo: ReadKeyValuesRepo<Key, Value>, originalRepo: ReadKeyValuesRepo<Key, Value>,
keySerializer: DeserializationStrategy<Key>, keySerializer: DeserializationStrategy<Key>,
valueSerializer: DeserializationStrategy<Value>, valueSerializer: DeserializationStrategy<Value>,

View File

@ -7,11 +7,11 @@ import io.ktor.http.HttpStatusCode
import io.ktor.server.application.call import io.ktor.server.application.call
import io.ktor.server.request.receive import io.ktor.server.request.receive
import io.ktor.server.response.respond import io.ktor.server.response.respond
import io.ktor.server.routing.Routing import io.ktor.server.routing.Route
import io.ktor.server.routing.post import io.ktor.server.routing.post
import io.ktor.util.reflect.typeInfo import io.ktor.util.reflect.typeInfo
inline fun <reified Key : Any, reified Value : Any> Routing.configureWriteKeyValuesRepoRoutes ( inline fun <reified Key : Any, reified Value : Any> Route.configureWriteKeyValuesRepoRoutes (
originalRepo: WriteKeyValuesRepo<Key, Value> originalRepo: WriteKeyValuesRepo<Key, Value>
) { ) {
includeWebsocketHandling( includeWebsocketHandling(