mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2025-09-03 23:29:46 +00:00
Revert "more annotations to god of annotations"
This reverts commit f8a8808508
.
This commit is contained in:
@@ -8,13 +8,11 @@ import io.ktor.http.cio.websocket.*
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.channelFlow
|
||||
import kotlinx.serialization.DeserializationStrategy
|
||||
import kotlin.js.JsExport
|
||||
|
||||
/**
|
||||
* @param checkReconnection This lambda will be called when it is required to reconnect to websocket to establish
|
||||
* connection. Must return true in case if must be reconnected. By default always reconnecting
|
||||
*/
|
||||
@JsExport
|
||||
inline fun <T> HttpClient.createStandardWebsocketFlow(
|
||||
url: String,
|
||||
crossinline checkReconnection: (Throwable?) -> Boolean = { true },
|
||||
@@ -62,7 +60,6 @@ inline fun <T> HttpClient.createStandardWebsocketFlow(
|
||||
* @param checkReconnection This lambda will be called when it is required to reconnect to websocket to establish
|
||||
* connection. Must return true in case if must be reconnected. By default always reconnecting
|
||||
*/
|
||||
@JsExport
|
||||
inline fun <T> HttpClient.createStandardWebsocketFlow(
|
||||
url: String,
|
||||
crossinline checkReconnection: (Throwable?) -> Boolean = { true },
|
||||
|
@@ -5,11 +5,9 @@ import io.ktor.client.HttpClient
|
||||
import io.ktor.client.request.get
|
||||
import io.ktor.client.request.post
|
||||
import kotlinx.serialization.*
|
||||
import kotlin.js.JsExport
|
||||
|
||||
typealias BodyPair<T> = Pair<SerializationStrategy<T>, T>
|
||||
|
||||
@JsExport
|
||||
suspend fun <ResultType> HttpClient.uniget(
|
||||
url: String,
|
||||
resultDeserializer: DeserializationStrategy<ResultType>
|
||||
@@ -20,13 +18,11 @@ suspend fun <ResultType> HttpClient.uniget(
|
||||
}
|
||||
|
||||
|
||||
@JsExport
|
||||
fun <T> SerializationStrategy<T>.encodeUrlQueryValue(value: T) = standardKtorSerialFormat.encodeHex(
|
||||
this,
|
||||
value
|
||||
)
|
||||
|
||||
@JsExport
|
||||
suspend fun <BodyType, ResultType> HttpClient.unipost(
|
||||
url: String,
|
||||
bodyInfo: BodyPair<BodyType>,
|
||||
|
@@ -1,8 +1,5 @@
|
||||
package dev.inmo.micro_utils.ktor.common
|
||||
|
||||
import kotlin.js.JsExport
|
||||
|
||||
@JsExport
|
||||
fun buildStandardUrl(
|
||||
basePart: String,
|
||||
subpart: String,
|
||||
@@ -11,7 +8,6 @@ fun buildStandardUrl(
|
||||
parameters
|
||||
)
|
||||
|
||||
@JsExport
|
||||
fun buildStandardUrl(
|
||||
basePart: String,
|
||||
subpart: String,
|
||||
@@ -20,7 +16,6 @@ fun buildStandardUrl(
|
||||
parameters
|
||||
)
|
||||
|
||||
@JsExport
|
||||
fun buildStandardUrl(
|
||||
basePart: String,
|
||||
subpart: String,
|
||||
|
@@ -1,7 +1,3 @@
|
||||
package dev.inmo.micro_utils.ktor.common
|
||||
|
||||
import kotlin.js.JsExport
|
||||
|
||||
@JsExport
|
||||
@Deprecated("Will be removed in next major release as useless")
|
||||
object CorrectCloseException : Exception()
|
||||
|
@@ -1,10 +1,7 @@
|
||||
package dev.inmo.micro_utils.ktor.common
|
||||
|
||||
import kotlin.js.JsExport
|
||||
|
||||
private val schemaRegex = Regex("^[^:]*://")
|
||||
|
||||
@JsExport
|
||||
val String.asCorrectWebSocketUrl: String
|
||||
get() = if (startsWith("ws")) {
|
||||
this
|
||||
|
@@ -1,18 +1,15 @@
|
||||
package dev.inmo.micro_utils.ktor.common
|
||||
|
||||
import com.soywiz.klock.DateTime
|
||||
import kotlin.js.JsExport
|
||||
|
||||
typealias FromToDateTime = Pair<DateTime?, DateTime?>
|
||||
|
||||
@JsExport
|
||||
val FromToDateTime.asFromToUrlPart: QueryParams
|
||||
get() = mapOf(
|
||||
"from" to first ?.unixMillis ?.toString(),
|
||||
"to" to second ?.unixMillis ?.toString()
|
||||
)
|
||||
|
||||
@JsExport
|
||||
val QueryParams.extractFromToDateTime: FromToDateTime
|
||||
get() = FromToDateTime(
|
||||
get("from") ?.toDoubleOrNull() ?.let { DateTime(it) },
|
||||
|
@@ -1,29 +1,22 @@
|
||||
package dev.inmo.micro_utils.ktor.common
|
||||
|
||||
import kotlin.js.JsExport
|
||||
|
||||
typealias QueryParam = Pair<String, String?>
|
||||
typealias QueryParams = Map<String, String?>
|
||||
|
||||
@JsExport
|
||||
val QueryParams.asUrlQuery: String
|
||||
get() = keys.joinToString("&") { "${it}${get(it) ?.let { value -> "=$value" }}" }
|
||||
|
||||
@JsExport
|
||||
val List<QueryParam>.asUrlQuery: String
|
||||
get() = joinToString("&") { (key, value) -> "${key}${value ?.let { _ -> "=$value" }}" }
|
||||
|
||||
@JsExport
|
||||
fun String.includeQueryParams(
|
||||
queryParams: QueryParams
|
||||
): String = "$this${if(queryParams.isNotEmpty()) "${if (contains("?")) "&" else "?"}${queryParams.asUrlQuery}" else ""}"
|
||||
|
||||
@JsExport
|
||||
fun String.includeQueryParams(
|
||||
queryParams: List<QueryParam>
|
||||
): String = "$this${if (contains("?")) "&" else "?"}${queryParams.asUrlQuery}"
|
||||
|
||||
@JsExport
|
||||
val String.parseUrlQuery: QueryParams
|
||||
get() = split("&").map {
|
||||
it.split("=").let { pair ->
|
||||
|
@@ -2,36 +2,28 @@ package dev.inmo.micro_utils.ktor.common
|
||||
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.cbor.Cbor
|
||||
import kotlin.js.JsExport
|
||||
|
||||
typealias StandardKtorSerialFormat = BinaryFormat
|
||||
typealias StandardKtorSerialInputData = ByteArray
|
||||
@JsExport
|
||||
val standardKtorSerialFormat: StandardKtorSerialFormat = Cbor { }
|
||||
|
||||
@JsExport
|
||||
inline fun <T> StandardKtorSerialFormat.decodeDefault(
|
||||
deserializationStrategy: DeserializationStrategy<T>,
|
||||
input: StandardKtorSerialInputData
|
||||
): T = decodeFromByteArray(deserializationStrategy, input)
|
||||
|
||||
@JsExport
|
||||
inline fun <T> StandardKtorSerialFormat.encodeDefault(
|
||||
serializationStrategy: SerializationStrategy<T>,
|
||||
data: T
|
||||
): StandardKtorSerialInputData = encodeToByteArray(serializationStrategy, data)
|
||||
|
||||
@JsExport
|
||||
@Deprecated("Will be removed in next major release due to useless")
|
||||
val cbor = Cbor {}
|
||||
|
||||
@JsExport
|
||||
inline fun <T> StandardKtorSerialFormat.decodeHex(
|
||||
deserializationStrategy: DeserializationStrategy<T>,
|
||||
input: String
|
||||
): T = decodeFromHexString(deserializationStrategy, input)
|
||||
|
||||
@JsExport
|
||||
inline fun <T> StandardKtorSerialFormat.encodeHex(
|
||||
serializationStrategy: SerializationStrategy<T>,
|
||||
data: T
|
||||
|
@@ -9,6 +9,13 @@ import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.collect
|
||||
import kotlinx.serialization.SerializationStrategy
|
||||
|
||||
private suspend fun DefaultWebSocketSession.checkReceivedAndCloseIfExists() {
|
||||
if (incoming.poll() != null) {
|
||||
close()
|
||||
throw CorrectCloseException
|
||||
}
|
||||
}
|
||||
|
||||
fun <T> Route.includeWebsocketHandling(
|
||||
suburl: String,
|
||||
flow: Flow<T>,
|
||||
|
Reference in New Issue
Block a user