Skip to content

Commit

Permalink
Fix codestyle and run apiDump
Browse files Browse the repository at this point in the history
  • Loading branch information
marychatte committed Oct 8, 2024
1 parent 14708d0 commit 9ce8ec5
Show file tree
Hide file tree
Showing 13 changed files with 186 additions and 111 deletions.
59 changes: 32 additions & 27 deletions ktor-client/ktor-client-core/api/ktor-client-core.api

Large diffs are not rendered by default.

46 changes: 26 additions & 20 deletions ktor-client/ktor-client-core/api/ktor-client-core.klib.api

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ public class ClientSSESessionWithDeserialization(
delegate: SSESessionWithDeserialization
) : SSESessionWithDeserialization by delegate


/**
* Deserializer interface for transforming field `data` of `ServerSentEvent` into desired data object.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import io.ktor.sse.*
import io.ktor.util.*
import io.ktor.util.logging.*
import io.ktor.util.pipeline.*
import io.ktor.util.reflect.*
import io.ktor.utils.io.*
import kotlinx.coroutines.flow.*
import kotlin.coroutines.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,11 +476,14 @@ class ServerSentEventsTest : ClientLoader(timeoutSeconds = 120) {

test { client ->
assertFailsWith<SSEClientException> {
client.sse({ url("$TEST_SERVER/sse/person") }, object : Deserializer {
override fun deserialize(typeInfo: TypeInfo, data: String): Any {
return Data(data)
client.sse(
{ url("$TEST_SERVER/sse/person") },
object : Deserializer {
override fun deserialize(typeInfo: TypeInfo, data: String): Any {
return Data(data)
}
}
}) {
) {
incoming.single().apply {
val data = deserialize<Person>(data)
assertEquals("Name 0", data?.name)
Expand All @@ -500,20 +503,26 @@ class ServerSentEventsTest : ClientLoader(timeoutSeconds = 120) {
}

test { client ->
client.sse({ url("$TEST_SERVER/sse/person") }, object : Deserializer {
override fun deserialize(typeInfo: TypeInfo, data: String): Any {
return Person1(data)
client.sse(
{ url("$TEST_SERVER/sse/person") },
object : Deserializer {
override fun deserialize(typeInfo: TypeInfo, data: String): Any {
return Person1(data)
}
}
}) {
) {
incoming.single().apply {
assertEquals("Name 0", deserialize<Person1>(data)?.name)
}
}
client.sse({ url("$TEST_SERVER/sse/person") }, deserialize = object : Deserializer {
override fun deserialize(typeInfo: TypeInfo, data: String): Any {
return Person2(data)
client.sse(
{ url("$TEST_SERVER/sse/person") },
deserialize = object : Deserializer {
override fun deserialize(typeInfo: TypeInfo, data: String): Any {
return Person2(data)
}
}
}) {
) {
incoming.single().apply {
assertEquals("Name 0", deserialize<Person2>(data)?.middleName)
}
Expand All @@ -534,14 +543,17 @@ class ServerSentEventsTest : ClientLoader(timeoutSeconds = 120) {
}

test { client ->
client.sse({
url("$TEST_SERVER/sse/json")
}, deserialize = object : Deserializer {
override fun deserialize(typeInfo: TypeInfo, data: String): Any {
val serializer = Json.serializersModule.serializer(typeInfo.kotlinType!!)
return Json.decodeFromString(serializer, data) ?: Exception()
client.sse(
{
url("$TEST_SERVER/sse/json")
},
deserialize = object : Deserializer {
override fun deserialize(typeInfo: TypeInfo, data: String): Any {
val serializer = Json.serializersModule.serializer(typeInfo.kotlinType!!)
return Json.decodeFromString(serializer, data) ?: Exception()
}
}
}) {
) {
var firstIsCustomer = true
incoming.collect { event: ParameterizedServerSentEvent<String> ->
if (firstIsCustomer) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
public final class io/ktor/server/sse/RoutingKt {
public static final fun sse (Lio/ktor/server/routing/Route;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)V
public static final fun sse (Lio/ktor/server/routing/Route;Lio/ktor/server/sse/Serializer;Lkotlin/jvm/functions/Function2;)V
public static final fun sse (Lio/ktor/server/routing/Route;Ljava/lang/String;Lio/ktor/server/sse/Serializer;Lkotlin/jvm/functions/Function2;)V
public static final fun sse (Lio/ktor/server/routing/Route;Ljava/lang/String;Lkotlin/jvm/functions/Function2;)V
public static final fun sse (Lio/ktor/server/routing/Route;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)V
public static final fun sse (Lio/ktor/server/routing/Route;Lkotlin/jvm/functions/Function2;)V
public static synthetic fun sse$default (Lio/ktor/server/routing/Route;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)V
public static synthetic fun sse$default (Lio/ktor/server/routing/Route;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)V
}

public final class io/ktor/server/sse/SSEKt {
public static final fun getSSE ()Lio/ktor/server/application/ApplicationPlugin;
}

public final class io/ktor/server/sse/SSEServerContent : io/ktor/http/content/OutgoingContent$WriteChannelContent {
public fun <init> (Lio/ktor/server/application/ApplicationCall;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)V
public fun <init> (Lio/ktor/server/application/ApplicationCall;Lio/ktor/server/sse/Serializer;Lkotlin/jvm/functions/Function2;)V
public final fun getCall ()Lio/ktor/server/application/ApplicationCall;
public fun getContentType ()Lio/ktor/http/ContentType;
public final fun getHandle ()Lkotlin/jvm/functions/Function2;
public final fun getSerialize ()Lkotlin/jvm/functions/Function1;
public final fun getSerialize ()Lio/ktor/server/sse/Serializer;
public fun toString ()Ljava/lang/String;
public fun writeTo (Lio/ktor/utils/io/ByteWriteChannel;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
}
Expand All @@ -42,10 +40,14 @@ public final class io/ktor/server/sse/SSESessionWithDeserialization$DefaultImpls
}

public abstract interface class io/ktor/server/sse/SSESessionWithSerialization : io/ktor/server/sse/SSESession {
public abstract fun getSerializer ()Lkotlin/jvm/functions/Function1;
public abstract fun getSerializer ()Lio/ktor/server/sse/Serializer;
}

public final class io/ktor/server/sse/SSESessionWithSerialization$DefaultImpls {
public static fun send (Lio/ktor/server/sse/SSESessionWithSerialization;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Long;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
}

public abstract interface class io/ktor/server/sse/Serializer {
public abstract fun serialize (Lio/ktor/util/reflect/TypeInfo;Ljava/lang/Object;)Ljava/lang/String;
}

Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,21 @@ abstract interface io.ktor.server.sse/SSESession : kotlinx.coroutines/CoroutineS
abstract fun <get-call>(): io.ktor.server.application/ApplicationCall // io.ktor.server.sse/SSESession.call.<get-call>|<get-call>(){}[0]

abstract suspend fun close() // io.ktor.server.sse/SSESession.close|close(){}[0]
abstract suspend fun send(io.ktor.sse/ServerSentEvent<kotlin/String>) // io.ktor.server.sse/SSESession.send|send(io.ktor.sse.ServerSentEvent<kotlin.String>){}[0]
abstract suspend fun send(io.ktor.sse/ServerSentEvent) // io.ktor.server.sse/SSESession.send|send(io.ktor.sse.ServerSentEvent){}[0]
open suspend fun send(kotlin/String? = ..., kotlin/String? = ..., kotlin/String? = ..., kotlin/Long? = ..., kotlin/String? = ...) // io.ktor.server.sse/SSESession.send|send(kotlin.String?;kotlin.String?;kotlin.String?;kotlin.Long?;kotlin.String?){}[0]
}

abstract interface io.ktor.server.sse/SSESessionWithSerialization : io.ktor.server.sse/SSESession { // io.ktor.server.sse/SSESessionWithSerialization|null[0]
abstract val serializer // io.ktor.server.sse/SSESessionWithSerialization.serializer|{}serializer[0]
abstract fun <get-serializer>(): kotlin/Function1<io.ktor.util.reflect/TypeInfo, kotlin/Function1<kotlin/Any, kotlin/String>> // io.ktor.server.sse/SSESessionWithSerialization.serializer.<get-serializer>|<get-serializer>(){}[0]
abstract fun <get-serializer>(): io.ktor.server.sse/Serializer // io.ktor.server.sse/SSESessionWithSerialization.serializer.<get-serializer>|<get-serializer>(){}[0]
}

abstract interface io.ktor.server.sse/Serializer { // io.ktor.server.sse/Serializer|null[0]
abstract fun serialize(io.ktor.util.reflect/TypeInfo, kotlin/Any): kotlin/String // io.ktor.server.sse/Serializer.serialize|serialize(io.ktor.util.reflect.TypeInfo;kotlin.Any){}[0]
}

final class <#A: io.ktor.server.sse/SSESession> io.ktor.server.sse/SSEServerContent : io.ktor.http.content/OutgoingContent.WriteChannelContent { // io.ktor.server.sse/SSEServerContent|null[0]
constructor <init>(io.ktor.server.application/ApplicationCall, kotlin/Function1<io.ktor.util.reflect/TypeInfo, kotlin/Function1<kotlin/Any, kotlin/String>>?, kotlin.coroutines/SuspendFunction1<#A, kotlin/Unit>) // io.ktor.server.sse/SSEServerContent.<init>|<init>(io.ktor.server.application.ApplicationCall;kotlin.Function1<io.ktor.util.reflect.TypeInfo,kotlin.Function1<kotlin.Any,kotlin.String>>?;kotlin.coroutines.SuspendFunction1<1:0,kotlin.Unit>){}[0]
constructor <init>(io.ktor.server.application/ApplicationCall, io.ktor.server.sse/Serializer?, kotlin.coroutines/SuspendFunction1<#A, kotlin/Unit>) // io.ktor.server.sse/SSEServerContent.<init>|<init>(io.ktor.server.application.ApplicationCall;io.ktor.server.sse.Serializer?;kotlin.coroutines.SuspendFunction1<1:0,kotlin.Unit>){}[0]

final val call // io.ktor.server.sse/SSEServerContent.call|{}call[0]
final fun <get-call>(): io.ktor.server.application/ApplicationCall // io.ktor.server.sse/SSEServerContent.call.<get-call>|<get-call>(){}[0]
Expand All @@ -30,7 +34,7 @@ final class <#A: io.ktor.server.sse/SSESession> io.ktor.server.sse/SSEServerCont
final val handle // io.ktor.server.sse/SSEServerContent.handle|{}handle[0]
final fun <get-handle>(): kotlin.coroutines/SuspendFunction1<#A, kotlin/Unit> // io.ktor.server.sse/SSEServerContent.handle.<get-handle>|<get-handle>(){}[0]
final val serialize // io.ktor.server.sse/SSEServerContent.serialize|{}serialize[0]
final fun <get-serialize>(): kotlin/Function1<io.ktor.util.reflect/TypeInfo, kotlin/Function1<kotlin/Any, kotlin/String>>? // io.ktor.server.sse/SSEServerContent.serialize.<get-serialize>|<get-serialize>(){}[0]
final fun <get-serialize>(): io.ktor.server.sse/Serializer? // io.ktor.server.sse/SSEServerContent.serialize.<get-serialize>|<get-serialize>(){}[0]

final fun toString(): kotlin/String // io.ktor.server.sse/SSEServerContent.toString|toString(){}[0]
final suspend fun writeTo(io.ktor.utils.io/ByteWriteChannel) // io.ktor.server.sse/SSEServerContent.writeTo|writeTo(io.ktor.utils.io.ByteWriteChannel){}[0]
Expand All @@ -39,10 +43,10 @@ final class <#A: io.ktor.server.sse/SSESession> io.ktor.server.sse/SSEServerCont
final val io.ktor.server.sse/SSE // io.ktor.server.sse/SSE|{}SSE[0]
final fun <get-SSE>(): io.ktor.server.application/ApplicationPlugin<kotlin/Unit> // io.ktor.server.sse/SSE.<get-SSE>|<get-SSE>(){}[0]

final fun (io.ktor.server.routing/Route).io.ktor.server.sse/sse(io.ktor.server.sse/Serializer, kotlin.coroutines/SuspendFunction1<io.ktor.server.sse/SSESessionWithSerialization, kotlin/Unit>) // io.ktor.server.sse/sse|[email protected](io.ktor.server.sse.Serializer;kotlin.coroutines.SuspendFunction1<io.ktor.server.sse.SSESessionWithSerialization,kotlin.Unit>){}[0]
final fun (io.ktor.server.routing/Route).io.ktor.server.sse/sse(kotlin.coroutines/SuspendFunction1<io.ktor.server.sse/SSESession, kotlin/Unit>) // io.ktor.server.sse/sse|[email protected](kotlin.coroutines.SuspendFunction1<io.ktor.server.sse.SSESession,kotlin.Unit>){}[0]
final fun (io.ktor.server.routing/Route).io.ktor.server.sse/sse(kotlin/Function1<io.ktor.util.reflect/TypeInfo, kotlin/Function1<kotlin/Any, kotlin/String>> = ..., kotlin.coroutines/SuspendFunction1<io.ktor.server.sse/SSESessionWithSerialization, kotlin/Unit>) // io.ktor.server.sse/sse|[email protected](kotlin.Function1<io.ktor.util.reflect.TypeInfo,kotlin.Function1<kotlin.Any,kotlin.String>>;kotlin.coroutines.SuspendFunction1<io.ktor.server.sse.SSESessionWithSerialization,kotlin.Unit>){}[0]
final fun (io.ktor.server.routing/Route).io.ktor.server.sse/sse(kotlin/String, io.ktor.server.sse/Serializer, kotlin.coroutines/SuspendFunction1<io.ktor.server.sse/SSESessionWithSerialization, kotlin/Unit>) // io.ktor.server.sse/sse|[email protected](kotlin.String;io.ktor.server.sse.Serializer;kotlin.coroutines.SuspendFunction1<io.ktor.server.sse.SSESessionWithSerialization,kotlin.Unit>){}[0]
final fun (io.ktor.server.routing/Route).io.ktor.server.sse/sse(kotlin/String, kotlin.coroutines/SuspendFunction1<io.ktor.server.sse/SSESession, kotlin/Unit>) // io.ktor.server.sse/sse|[email protected](kotlin.String;kotlin.coroutines.SuspendFunction1<io.ktor.server.sse.SSESession,kotlin.Unit>){}[0]
final fun (io.ktor.server.routing/Route).io.ktor.server.sse/sse(kotlin/String, kotlin/Function1<io.ktor.util.reflect/TypeInfo, kotlin/Function1<kotlin/Any, kotlin/String>> = ..., kotlin.coroutines/SuspendFunction1<io.ktor.server.sse/SSESessionWithSerialization, kotlin/Unit>) // io.ktor.server.sse/sse|[email protected](kotlin.String;kotlin.Function1<io.ktor.util.reflect.TypeInfo,kotlin.Function1<kotlin.Any,kotlin.String>>;kotlin.coroutines.SuspendFunction1<io.ktor.server.sse.SSESessionWithSerialization,kotlin.Unit>){}[0]
final suspend inline fun <#A: reified kotlin/Any> (io.ktor.server.sse/SSESessionWithSerialization).io.ktor.server.sse/sendSerialized(#A) // io.ktor.server.sse/sendSerialized|[email protected](0:0){0§<kotlin.Any>}[0]
final suspend inline fun <#A: reified kotlin/Any> (io.ktor.server.sse/SSESessionWithSerialization).io.ktor.server.sse/sendSerialized(#A? = ..., kotlin/String? = ..., kotlin/String? = ..., kotlin/Long? = ..., kotlin/String? = ...) // io.ktor.server.sse/sendSerialized|[email protected](0:0?;kotlin.String?;kotlin.String?;kotlin.Long?;kotlin.String?){0§<kotlin.Any>}[0]
final suspend inline fun <#A: reified kotlin/Any> (io.ktor.server.sse/SSESessionWithSerialization).io.ktor.server.sse/sendSerialized(io.ktor.sse/ServerSentEvent<#A>) // io.ktor.server.sse/sendSerialized|[email protected](io.ktor.sse.ServerSentEvent<0:0>){0§<kotlin.Any>}[0]
final suspend inline fun <#A: reified kotlin/Any> (io.ktor.server.sse/SSESessionWithSerialization).io.ktor.server.sse/sendSerialized(io.ktor.sse/ParameterizedServerSentEvent<#A>) // io.ktor.server.sse/sendSerialized|[email protected](io.ktor.sse.ParameterizedServerSentEvent<0:0>){0§<kotlin.Any>}[0]
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package io.ktor.server.sse
import io.ktor.http.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
import io.ktor.util.reflect.*

/**
* Adds a route to handle Server-Sent Events (SSE) at the specified [path] using the provided [handler].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import io.ktor.http.*
import io.ktor.http.content.*
import io.ktor.server.application.*
import io.ktor.server.request.*
import io.ktor.util.reflect.*
import io.ktor.utils.io.*
import kotlinx.coroutines.*

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ public suspend inline fun <reified T : Any> SSESessionWithSerialization.sendSeri
send(ServerSentEvent(serializer.serialize(typeInfo<T>(), data)))
}


/**
* Serializer interface for transforming data object into field `data` of `ServerSentEvent`.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,19 +202,22 @@ class ServerSentEventsTest {
fun testSerializerInRoute() = testApplication {
install(SSE)
routing {
sse("/person", object : Serializer {
override fun serialize(typeInfo: TypeInfo, data: Any): String {
return when (typeInfo.type) {
Person1::class -> {
"Age ${(data as Person1).age}"
}

else -> {
data.toString()
sse(
"/person",
object : Serializer {
override fun serialize(typeInfo: TypeInfo, data: Any): String {
return when (typeInfo.type) {
Person1::class -> {
"Age ${(data as Person1).age}"
}

else -> {
data.toString()
}
}
}
}
}) {
) {
repeat(10) {
sendSerialized(Person1(it))
}
Expand Down Expand Up @@ -250,8 +253,7 @@ class ServerSentEventsTest {
}
}
}
})
{
}) {
sendSerialized(Person1(22))
sendSerialized(Person2(123456))
}
Expand Down Expand Up @@ -281,12 +283,15 @@ class ServerSentEventsTest {
fun testJsonDeserializer() = testApplication {
install(SSE)
routing {
sse("/json", object : Serializer {
override fun serialize(typeInfo: TypeInfo, data: Any): String {
val serializer = Json.serializersModule.serializer(typeInfo.kotlinType!!)
return Json.encodeToString(serializer, data)
sse(
"/json",
object : Serializer {
override fun serialize(typeInfo: TypeInfo, data: Any): String {
val serializer = Json.serializersModule.serializer(typeInfo.kotlinType!!)
return Json.encodeToString(serializer, data)
}
}
}) {
) {
sendSerialized(Customer(0, "Jet", "Brains"))
sendSerialized(Product(0, listOf(100, 200)))
}
Expand Down
Loading

0 comments on commit 9ce8ec5

Please sign in to comment.