mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-11-26 03:58:45 +00:00
parent
9ba4d98c30
commit
e68735d061
@ -1,19 +1,19 @@
|
||||
[versions]
|
||||
|
||||
kt = "2.0.20-RC"
|
||||
kt = "2.0.0"
|
||||
kt-serialization = "1.7.1"
|
||||
kt-coroutines = "1.8.1"
|
||||
|
||||
kslog = "1.3.4"
|
||||
|
||||
jb-compose = "1.7.0-dev1750"
|
||||
jb-compose = "1.7.0-dev1742"
|
||||
jb-exposed = "0.51.1"
|
||||
jb-dokka = "1.9.20"
|
||||
|
||||
korlibs = "5.4.0"
|
||||
uuid = "0.8.4"
|
||||
|
||||
ktor = "3.0.0-beta-2"
|
||||
ktor = "2.3.11"
|
||||
|
||||
gh-release = "2.5.2"
|
||||
|
||||
|
@ -1,3 +1,3 @@
|
||||
package dev.inmo.micro_utils.ktor.client
|
||||
|
||||
typealias OnUploadCallback = suspend (uploaded: Long, count: Long?) -> Unit
|
||||
typealias OnUploadCallback = suspend (uploaded: Long, count: Long) -> Unit
|
||||
|
@ -1,8 +1,10 @@
|
||||
package dev.inmo.micro_utils.ktor.common
|
||||
|
||||
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.InputStream
|
||||
import java.util.UUID
|
||||
|
||||
fun Input.downloadToTempFile(
|
||||
@ -15,7 +17,7 @@ fun Input.downloadToTempFile(
|
||||
folder
|
||||
).apply {
|
||||
outputStream().use {
|
||||
this@downloadToTempFile.transferTo(it.asSink())
|
||||
copyTo(it.asOutput())
|
||||
}
|
||||
deleteOnExit()
|
||||
}
|
||||
|
@ -1,9 +1,8 @@
|
||||
package dev.inmo.micro_utils.ktor.server
|
||||
|
||||
import io.ktor.server.application.ApplicationCall
|
||||
import io.ktor.server.http.*
|
||||
import io.ktor.server.response.responseType
|
||||
import io.ktor.utils.io.InternalAPI
|
||||
import io.ktor.util.InternalAPI
|
||||
import io.ktor.util.reflect.TypeInfo
|
||||
|
||||
@InternalAPI
|
||||
@ -12,5 +11,5 @@ suspend fun <T : Any> ApplicationCall.respond(
|
||||
typeInfo: TypeInfo
|
||||
) {
|
||||
response.responseType = typeInfo
|
||||
respond(message, typeInfo)
|
||||
response.pipeline.execute(this, message as Any)
|
||||
}
|
||||
|
@ -2,19 +2,21 @@ package dev.inmo.micro_utils.ktor.server
|
||||
|
||||
import com.benasher44.uuid.uuid4
|
||||
import io.ktor.http.content.PartData
|
||||
import io.ktor.util.cio.*
|
||||
import io.ktor.utils.io.*
|
||||
import io.ktor.utils.io.copyTo
|
||||
import io.ktor.utils.io.core.copyTo
|
||||
import io.ktor.utils.io.jvm.javaio.copyTo
|
||||
import kotlinx.io.asSink
|
||||
import io.ktor.utils.io.streams.asOutput
|
||||
import java.io.File
|
||||
|
||||
suspend fun PartData.FileItem.download(target: File) {
|
||||
provider().copyAndClose(
|
||||
target.writeChannel()
|
||||
)
|
||||
fun PartData.FileItem.download(target: File) {
|
||||
provider().use { input ->
|
||||
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 {
|
||||
deleteOnExit()
|
||||
}
|
||||
@ -25,7 +27,7 @@ suspend fun PartData.FileItem.downloadToTemporalFile(): File {
|
||||
fun PartData.BinaryItem.download(target: File) {
|
||||
provider().use { input ->
|
||||
target.outputStream().use {
|
||||
input.transferTo(it.asSink())
|
||||
input.copyTo(it.asOutput())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,14 +5,14 @@ import dev.inmo.micro_utils.ktor.common.*
|
||||
import io.ktor.http.URLProtocol
|
||||
import io.ktor.server.application.install
|
||||
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.websocket.*
|
||||
import io.ktor.websocket.send
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.serialization.SerializationStrategy
|
||||
|
||||
inline fun <reified T : Any> Routing.includeWebsocketHandling(
|
||||
inline fun <reified T : Any> Route.includeWebsocketHandling(
|
||||
suburl: String,
|
||||
flow: Flow<T>,
|
||||
protocol: URLProtocol? = null,
|
||||
|
@ -1,7 +1,7 @@
|
||||
package dev.inmo.micro_utils.ktor.server
|
||||
|
||||
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.CIOApplicationEngine
|
||||
import io.ktor.server.engine.*
|
||||
@ -11,22 +11,20 @@ fun <TEngine : ApplicationEngine, TConfiguration : ApplicationEngine.Configurati
|
||||
engine: ApplicationEngineFactory<TEngine, TConfiguration>,
|
||||
host: String = "localhost",
|
||||
port: Int = Random.nextInt(1024, 65535),
|
||||
additionalEngineEnvironmentConfigurator: EngineConnectorBuilder.() -> Unit = {},
|
||||
additionalEngineEnvironmentConfigurator: ApplicationEngineEnvironmentBuilder.() -> Unit = {},
|
||||
additionalConfigurationConfigurator: TConfiguration.() -> Unit = {},
|
||||
environment: ApplicationEnvironment = applicationEnvironment(),
|
||||
block: Application.() -> Unit
|
||||
): EmbeddedServer<TEngine, TConfiguration> = embeddedServer<TEngine, TConfiguration>(
|
||||
): TEngine = embeddedServer(
|
||||
engine,
|
||||
environment,
|
||||
{
|
||||
applicationEngineEnvironment {
|
||||
module(block)
|
||||
connector {
|
||||
this.host = host
|
||||
this.port = port
|
||||
additionalEngineEnvironmentConfigurator()
|
||||
}
|
||||
additionalConfigurationConfigurator()
|
||||
additionalEngineEnvironmentConfigurator()
|
||||
},
|
||||
module = block
|
||||
additionalConfigurationConfigurator
|
||||
)
|
||||
|
||||
/**
|
||||
@ -37,17 +35,15 @@ fun <TEngine : ApplicationEngine, TConfiguration : ApplicationEngine.Configurati
|
||||
fun createKtorServer(
|
||||
host: String = "localhost",
|
||||
port: Int = Random.nextInt(1024, 65535),
|
||||
additionalEngineEnvironmentConfigurator: EngineConnectorBuilder.() -> Unit = {},
|
||||
additionalEngineEnvironmentConfigurator: ApplicationEngineEnvironmentBuilder.() -> Unit = {},
|
||||
additionalConfigurationConfigurator: CIOApplicationEngine.Configuration.() -> Unit = {},
|
||||
environment: ApplicationEnvironment = applicationEnvironment(),
|
||||
block: Application.() -> Unit
|
||||
): EmbeddedServer<CIOApplicationEngine, CIOApplicationEngine.Configuration> = createKtorServer(
|
||||
): CIOApplicationEngine = createKtorServer(
|
||||
CIO,
|
||||
host,
|
||||
port,
|
||||
additionalEngineEnvironmentConfigurator,
|
||||
additionalConfigurationConfigurator,
|
||||
environment,
|
||||
block
|
||||
)
|
||||
|
||||
@ -55,17 +51,15 @@ fun <TEngine : ApplicationEngine, TConfiguration : ApplicationEngine.Configurati
|
||||
engine: ApplicationEngineFactory<TEngine, TConfiguration>,
|
||||
host: String = "localhost",
|
||||
port: Int = Random.nextInt(1024, 65535),
|
||||
additionalEngineEnvironmentConfigurator: EngineConnectorBuilder.() -> Unit = {},
|
||||
additionalEngineEnvironmentConfigurator: ApplicationEngineEnvironmentBuilder.() -> Unit = {},
|
||||
additionalConfigurationConfigurator: TConfiguration.() -> Unit = {},
|
||||
environment: ApplicationEnvironment = applicationEnvironment(),
|
||||
configurators: List<KtorApplicationConfigurator>
|
||||
): EmbeddedServer<TEngine, TConfiguration> = createKtorServer(
|
||||
): TEngine = createKtorServer(
|
||||
engine,
|
||||
host,
|
||||
port,
|
||||
additionalEngineEnvironmentConfigurator,
|
||||
additionalConfigurationConfigurator,
|
||||
environment,
|
||||
additionalConfigurationConfigurator
|
||||
) {
|
||||
configurators.forEach { it.apply { configure() } }
|
||||
}
|
||||
@ -79,7 +73,6 @@ fun createKtorServer(
|
||||
host: String = "localhost",
|
||||
port: Int = Random.nextInt(1024, 65535),
|
||||
configurators: List<KtorApplicationConfigurator>,
|
||||
additionalEngineEnvironmentConfigurator: EngineConnectorBuilder.() -> Unit = {},
|
||||
additionalEngineEnvironmentConfigurator: ApplicationEngineEnvironmentBuilder.() -> Unit = {},
|
||||
additionalConfigurationConfigurator: CIOApplicationEngine.Configuration.() -> Unit = {},
|
||||
environment: ApplicationEnvironment = applicationEnvironment(),
|
||||
): EmbeddedServer<CIOApplicationEngine, CIOApplicationEngine.Configuration> = createKtorServer(CIO, host, port, additionalEngineEnvironmentConfigurator, additionalConfigurationConfigurator, environment, configurators)
|
||||
): ApplicationEngine = createKtorServer(CIO, host, port, additionalEngineEnvironmentConfigurator, additionalConfigurationConfigurator, configurators)
|
||||
|
@ -14,10 +14,9 @@ import io.ktor.server.application.call
|
||||
import io.ktor.server.request.receiveMultipart
|
||||
import io.ktor.server.response.respond
|
||||
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 kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.channels.BufferOverflow
|
||||
import kotlinx.coroutines.flow.*
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
import kotlinx.coroutines.sync.withLock
|
||||
@ -27,10 +26,7 @@ import java.nio.file.attribute.FileTime
|
||||
|
||||
class TemporalFilesRoutingConfigurator(
|
||||
private val subpath: String = DefaultTemporalFilesSubPath,
|
||||
private val temporalFilesUtilizer: TemporalFilesUtilizer = TemporalFilesUtilizer,
|
||||
filesFlowReplay: Int = 0,
|
||||
filesFlowExtraBufferCapacity: Int = Int.MAX_VALUE,
|
||||
filesFlowOnBufferOverflow: BufferOverflow = BufferOverflow.SUSPEND
|
||||
private val temporalFilesUtilizer: TemporalFilesUtilizer = TemporalFilesUtilizer
|
||||
) : ApplicationRoutingConfigurator.Element {
|
||||
interface TemporalFilesUtilizer {
|
||||
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 temporalFilesMutex = Mutex()
|
||||
private val filesFlow = MutableSharedFlow<TemporalFileId>(
|
||||
replay = filesFlowReplay,
|
||||
extraBufferCapacity = filesFlowExtraBufferCapacity,
|
||||
onBufferOverflow = filesFlowOnBufferOverflow
|
||||
)
|
||||
private val filesFlow = MutableSharedFlow<TemporalFileId>()
|
||||
val utilizerJob = temporalFilesUtilizer.start(temporalFilesMap, temporalFilesMutex, filesFlow.asSharedFlow())
|
||||
|
||||
override fun Routing.invoke() {
|
||||
override fun Route.invoke() {
|
||||
post(subpath) {
|
||||
val multipart = call.receiveMultipart()
|
||||
|
||||
@ -119,7 +111,7 @@ class TemporalFilesRoutingConfigurator(
|
||||
temporalFilesMap[fileId] = file
|
||||
}
|
||||
call.respondText(fileId.string)
|
||||
filesFlow.emit(fileId)
|
||||
launchSafelyWithoutExceptions { filesFlow.emit(fileId) }
|
||||
} ?: call.respond(HttpStatusCode.BadRequest)
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ import dev.inmo.micro_utils.ktor.common.downloadToTempFile
|
||||
import io.ktor.http.content.*
|
||||
import io.ktor.server.application.ApplicationCall
|
||||
import io.ktor.server.request.receiveMultipart
|
||||
import io.ktor.utils.io.*
|
||||
import io.ktor.utils.io.core.*
|
||||
import kotlinx.coroutines.currentCoroutineContext
|
||||
import kotlinx.coroutines.isActive
|
||||
@ -48,7 +47,7 @@ suspend fun ApplicationCall.uniloadMultipart(
|
||||
onBinaryChannelItem
|
||||
) {
|
||||
when (it.name) {
|
||||
"bytes" -> resultInput = it.provider().readBuffer()
|
||||
"bytes" -> resultInput = it.provider()
|
||||
else -> onCustomFileItem(it)
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,8 @@ package dev.inmo.micro_utils.ktor.server.configurators
|
||||
|
||||
import dev.inmo.micro_utils.ktor.server.configurators.ApplicationRoutingConfigurator.Element
|
||||
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.Serializable
|
||||
|
||||
@ -10,7 +11,7 @@ import kotlinx.serialization.Serializable
|
||||
class ApplicationRoutingConfigurator(
|
||||
private val elements: List<@Contextual Element>
|
||||
) : KtorApplicationConfigurator {
|
||||
fun interface Element { operator fun Routing.invoke() }
|
||||
fun interface Element { operator fun Route.invoke() }
|
||||
private val rootInstaller = Element {
|
||||
elements.forEach {
|
||||
it.apply { invoke() }
|
||||
@ -18,7 +19,9 @@ class ApplicationRoutingConfigurator(
|
||||
}
|
||||
|
||||
override fun Application.configure() {
|
||||
routing {
|
||||
pluginOrNull(Routing) ?.apply {
|
||||
rootInstaller.apply { invoke() }
|
||||
} ?: install(Routing) {
|
||||
rootInstaller.apply { invoke() }
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import dev.inmo.micro_utils.repos.ktor.common.key_value.*
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.request.post
|
||||
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 kotlinx.coroutines.flow.Flow
|
||||
|
@ -8,7 +8,7 @@ import dev.inmo.micro_utils.repos.ktor.common.one_to_many.*
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.request.post
|
||||
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 kotlinx.coroutines.flow.Flow
|
||||
|
@ -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.repos.CRUDRepo
|
||||
import io.ktor.server.routing.Routing
|
||||
import io.ktor.server.routing.Route
|
||||
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>,
|
||||
noinline idDeserializer: suspend (String) -> IdType
|
||||
) {
|
||||
@ -13,7 +13,7 @@ inline fun <reified ObjectType : Any, reified IdType : Any, reified InputValue :
|
||||
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>,
|
||||
idsSerializer: KSerializer<IdType>,
|
||||
serialFormat: StringFormat
|
||||
@ -21,7 +21,7 @@ inline fun <reified ObjectType : Any, reified IdType : Any, reified InputValue :
|
||||
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>,
|
||||
idsSerializer: KSerializer<IdType>,
|
||||
serialFormat: BinaryFormat
|
||||
|
@ -11,11 +11,11 @@ import dev.inmo.micro_utils.repos.ktor.common.idParameterName
|
||||
import io.ktor.http.HttpStatusCode
|
||||
import io.ktor.server.application.call
|
||||
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 kotlinx.serialization.*
|
||||
|
||||
inline fun <reified ObjectType, reified IdType> Routing.configureReadCRUDRepoRoutes(
|
||||
inline fun <reified ObjectType, reified IdType> Route.configureReadCRUDRepoRoutes(
|
||||
originalRepo: ReadCRUDRepo<ObjectType, 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>,
|
||||
idsSerializer: KSerializer<IdType>,
|
||||
serialFormat: StringFormat
|
||||
@ -73,7 +73,7 @@ inline fun <reified ObjectType, reified IdType> Routing.configureReadCRUDRepoRou
|
||||
serialFormat.decodeFromString(idsSerializer, it)
|
||||
}
|
||||
|
||||
inline fun <reified ObjectType, reified IdType> Routing.configureReadCRUDRepoRoutes(
|
||||
inline fun <reified ObjectType, reified IdType> Route.configureReadCRUDRepoRoutes(
|
||||
originalRepo: ReadCRUDRepo<ObjectType, IdType>,
|
||||
idsSerializer: KSerializer<IdType>,
|
||||
serialFormat: BinaryFormat
|
||||
|
@ -7,10 +7,10 @@ import io.ktor.http.HttpStatusCode
|
||||
import io.ktor.server.application.call
|
||||
import io.ktor.server.request.receive
|
||||
import io.ktor.server.response.respond
|
||||
import io.ktor.server.routing.Routing
|
||||
import io.ktor.server.routing.Route
|
||||
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>
|
||||
) {
|
||||
includeWebsocketHandling(
|
||||
|
@ -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.repos.KeyValueRepo
|
||||
import io.ktor.http.*
|
||||
import io.ktor.server.routing.Routing
|
||||
import io.ktor.server.routing.Route
|
||||
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>,
|
||||
noinline idDeserializer: suspend (String) -> Key,
|
||||
noinline valueDeserializer: suspend (String) -> Value
|
||||
@ -15,7 +15,7 @@ inline fun <reified Key : Any, reified Value : Any> Routing.configureKeyValueRep
|
||||
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>,
|
||||
idsSerializer: DeserializationStrategy<Key>,
|
||||
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>,
|
||||
idsSerializer: DeserializationStrategy<Key>,
|
||||
valueSerializer: DeserializationStrategy<Value>,
|
||||
|
@ -14,14 +14,14 @@ import dev.inmo.micro_utils.repos.ktor.common.reversedParameterName
|
||||
import io.ktor.http.*
|
||||
import io.ktor.server.application.call
|
||||
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.utils.io.InternalAPI
|
||||
import io.ktor.util.InternalAPI
|
||||
import io.ktor.util.reflect.typeInfo
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@OptIn(InternalAPI::class)
|
||||
inline fun <reified Key, reified Value> Routing.configureReadKeyValueRepoRoutes (
|
||||
inline fun <reified Key, reified Value> Route.configureReadKeyValueRepoRoutes (
|
||||
originalRepo: ReadKeyValueRepo<Key, Value>,
|
||||
noinline idDeserializer: suspend (String) -> Key,
|
||||
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>,
|
||||
idsSerializer: DeserializationStrategy<Key>,
|
||||
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>,
|
||||
idsSerializer: DeserializationStrategy<Key>,
|
||||
valueSerializer: DeserializationStrategy<Value>,
|
||||
|
@ -7,11 +7,11 @@ import io.ktor.http.HttpStatusCode
|
||||
import io.ktor.server.application.call
|
||||
import io.ktor.server.request.receive
|
||||
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.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>
|
||||
) {
|
||||
includeWebsocketHandling(
|
||||
|
@ -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.repos.*
|
||||
import io.ktor.http.*
|
||||
import io.ktor.server.routing.Routing
|
||||
import io.ktor.server.routing.Route
|
||||
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>,
|
||||
noinline keyDeserializer: suspend (String) -> Key,
|
||||
noinline valueDeserializer: suspend (String) -> Value
|
||||
@ -15,7 +15,7 @@ inline fun <reified Key : Any, reified Value : Any> Routing.configureKeyValuesRe
|
||||
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>,
|
||||
keySerializer: DeserializationStrategy<Key>,
|
||||
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>,
|
||||
keySerializer: DeserializationStrategy<Key>,
|
||||
valueSerializer: DeserializationStrategy<Value>,
|
||||
|
@ -12,14 +12,14 @@ import dev.inmo.micro_utils.repos.ktor.common.one_to_many.*
|
||||
import io.ktor.http.*
|
||||
import io.ktor.server.application.call
|
||||
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.utils.io.InternalAPI
|
||||
import io.ktor.util.InternalAPI
|
||||
import io.ktor.util.reflect.typeInfo
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@OptIn(InternalAPI::class)
|
||||
inline fun <reified Key, reified Value> Routing.configureReadKeyValuesRepoRoutes (
|
||||
inline fun <reified Key, reified Value> Route.configureReadKeyValuesRepoRoutes (
|
||||
originalRepo: ReadKeyValuesRepo<Key, Value>,
|
||||
noinline keyDeserializer: suspend (String) -> Key,
|
||||
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>,
|
||||
keySerializer: DeserializationStrategy<Key>,
|
||||
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>,
|
||||
keySerializer: DeserializationStrategy<Key>,
|
||||
valueSerializer: DeserializationStrategy<Value>,
|
||||
|
@ -7,11 +7,11 @@ import io.ktor.http.HttpStatusCode
|
||||
import io.ktor.server.application.call
|
||||
import io.ktor.server.request.receive
|
||||
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.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>
|
||||
) {
|
||||
includeWebsocketHandling(
|
||||
|
Loading…
Reference in New Issue
Block a user