Skip to content

Commit

Permalink
Change ServerSentEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
marychatte committed Oct 10, 2024
1 parent 937c39f commit 19f01fe
Show file tree
Hide file tree
Showing 12 changed files with 200 additions and 119 deletions.
55 changes: 28 additions & 27 deletions ktor-client/ktor-client-core/api/ktor-client-core.api

Large diffs are not rendered by default.

42 changes: 22 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 @@ -27,7 +27,7 @@ public interface SSESessionWithDeserialization : CoroutineScope {
/**
* An incoming server-sent events flow.
*/
public val incoming: Flow<ParameterizedServerSentEvent<String>>
public val incoming: Flow<ServerSentEventParsed<String>>

/**
* Deserializer for transforming field `data` of `ServerSentEvent` into desired data object.
Expand Down Expand Up @@ -56,7 +56,7 @@ public inline fun <reified T> SSESessionWithDeserialization.deserialize(data: St
* @return The deserialized object of type [T], or null if deserialization is not successful.
*/
public inline fun <reified T> SSESessionWithDeserialization.deserialize(
event: ParameterizedServerSentEvent<String>
event: ServerSentEventParsed<String>
): T? = deserialize(event.data)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ public val SSE: ClientPlugin<SSEConfig> = createClientPlugin(
ClientSSESessionWithDeserialization(
context,
object : SSESessionWithDeserialization {
override val incoming: Flow<ParameterizedServerSentEvent<String>> =
override val incoming: Flow<ServerSentEventParsed<String>> =
session.incoming.map { event: ServerSentEvent ->
ParameterizedServerSentEvent(event.data, event.event, event.id, event.retry, event.comments)
ServerSentEventParsed(event.data, event.event, event.id, event.retry, event.comments)
}

override val deserializer: (TypeInfo, String) -> Any = deserializer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ class ServerSentEventsTest : ClientLoader(timeoutSeconds = 120) {
Json.decodeFromString(serializer, jsonString) ?: Exception()
}) {
var firstIsCustomer = true
incoming.collect { event: ParameterizedServerSentEvent<String> ->
incoming.collect { event: ServerSentEventParsed<String> ->
if (firstIsCustomer) {
val customer = deserialize<Customer>(event.data)
assertEquals(1, customer?.id)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
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;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;Ljava/lang/String;Lkotlin/jvm/functions/Function2;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 static final fun sse (Lio/ktor/server/routing/Route;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)V
public static synthetic fun sse$default (Lio/ktor/server/routing/Route;Ljava/lang/String;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)V
public static synthetic fun sse$default (Lio/ktor/server/routing/Route;Lkotlin/jvm/functions/Function2;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;Lkotlin/jvm/functions/Function2;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 ()Lkotlin/jvm/functions/Function2;
public fun toString ()Ljava/lang/String;
public fun writeTo (Lio/ktor/utils/io/ByteWriteChannel;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
}
Expand All @@ -33,16 +33,8 @@ public final class io/ktor/server/sse/SSESession$DefaultImpls {
public static synthetic fun send$default (Lio/ktor/server/sse/SSESession;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Long;Ljava/lang/String;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
}

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

public final class io/ktor/server/sse/SSESessionWithDeserialization$DefaultImpls {
public static fun send (Lio/ktor/server/sse/SSESessionWithDeserialization;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/SSESessionWithSerialization : io/ktor/server/sse/SSESession {
public abstract fun getSerializer ()Lkotlin/jvm/functions/Function1;
public abstract fun getSerializer ()Lkotlin/jvm/functions/Function2;
}

public final class io/ktor/server/sse/SSESessionWithSerialization$DefaultImpls {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ 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>(): kotlin/Function2<io.ktor.util.reflect/TypeInfo, kotlin/Any, kotlin/String> // io.ktor.server.sse/SSESessionWithSerialization.serializer.<get-serializer>|<get-serializer>(){}[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, kotlin/Function2<io.ktor.util.reflect/TypeInfo, kotlin/Any, kotlin/String>?, kotlin.coroutines/SuspendFunction1<#A, kotlin/Unit>) // io.ktor.server.sse/SSEServerContent.<init>|<init>(io.ktor.server.application.ApplicationCall;kotlin.Function2<io.ktor.util.reflect.TypeInfo,kotlin.Any,kotlin.String>?;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 +30,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>(): kotlin/Function2<io.ktor.util.reflect/TypeInfo, kotlin/Any, kotlin/String>? // 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 @@ -40,9 +40,9 @@ 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(kotlin.coroutines/SuspendFunction1<io.ktor.server.sse/SSESession, kotlin/Unit>) // io.ktor.server.sse/sse|sse@io.ktor.server.routing.Route(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|sse@io.ktor.server.routing.Route(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/Function2<io.ktor.util.reflect/TypeInfo, kotlin/Any, kotlin/String> = ..., kotlin.coroutines/SuspendFunction1<io.ktor.server.sse/SSESessionWithSerialization, kotlin/Unit>) // io.ktor.server.sse/sse|sse@io.ktor.server.routing.Route(kotlin.Function2<io.ktor.util.reflect.TypeInfo,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, kotlin.coroutines/SuspendFunction1<io.ktor.server.sse/SSESession, kotlin/Unit>) // io.ktor.server.sse/sse|sse@io.ktor.server.routing.Route(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|sse@io.ktor.server.routing.Route(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|sendSerialized@io.ktor.server.sse.SSESessionWithSerialization(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|sendSerialized@io.ktor.server.sse.SSESessionWithSerialization(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|sendSerialized@io.ktor.server.sse.SSESessionWithSerialization(io.ktor.sse.ServerSentEvent<0:0>){0§<kotlin.Any>}[0]
final fun (io.ktor.server.routing/Route).io.ktor.server.sse/sse(kotlin/String, kotlin/Function2<io.ktor.util.reflect/TypeInfo, kotlin/Any, kotlin/String> = ..., kotlin.coroutines/SuspendFunction1<io.ktor.server.sse/SSESessionWithSerialization, kotlin/Unit>) // io.ktor.server.sse/sse|sse@io.ktor.server.routing.Route(kotlin.String;kotlin.Function2<io.ktor.util.reflect.TypeInfo,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/send(#A) // io.ktor.server.sse/send|send@io.ktor.server.sse.SSESessionWithSerialization(0:0){0§<kotlin.Any>}[0]
final suspend inline fun <#A: reified kotlin/Any> (io.ktor.server.sse/SSESessionWithSerialization).io.ktor.server.sse/send(#A? = ..., kotlin/String? = ..., kotlin/String? = ..., kotlin/Long? = ..., kotlin/String? = ...) // io.ktor.server.sse/send|send@io.ktor.server.sse.SSESessionWithSerialization(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/send(io.ktor.sse/ServerSentEventParsed<#A>) // io.ktor.server.sse/send|send@io.ktor.server.sse.SSESessionWithSerialization(io.ktor.sse.ServerSentEventParsed<0:0>){0§<kotlin.Any>}[0]
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ public interface SSESessionWithSerialization : SSESession {
public val serializer: (TypeInfo, Any) -> String
}

public suspend inline fun <reified T : Any> SSESessionWithSerialization.sendSerialized(
event: ParameterizedServerSentEvent<T>
) {
public suspend inline fun <reified T : Any> SSESessionWithSerialization.send(event: ServerSentEventParsed<T>) {
send(
ServerSentEvent(
event.data?.let {
Expand All @@ -87,16 +85,16 @@ public suspend inline fun <reified T : Any> SSESessionWithSerialization.sendSeri
)
}

public suspend inline fun <reified T : Any> SSESessionWithSerialization.sendSerialized(
public suspend inline fun <reified T : Any> SSESessionWithSerialization.send(
data: T? = null,
event: String? = null,
id: String? = null,
retry: Long? = null,
comments: String? = null
) {
sendSerialized(ParameterizedServerSentEvent(data, event, id, retry, comments))
send(ServerSentEventParsed(data, event, id, retry, comments))
}

public suspend inline fun <reified T : Any> SSESessionWithSerialization.sendSerialized(data: T) {
public suspend inline fun <reified T : Any> SSESessionWithSerialization.send(data: T) {
send(ServerSentEvent(serializer(typeInfo<T>(), data)))
}
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ class ServerSentEventsTest {
}
}) {
repeat(10) {
sendSerialized(Person1(it))
send(Person1(it))
}
}
}
Expand Down Expand Up @@ -246,8 +246,8 @@ class ServerSentEventsTest {
}
}
}) {
sendSerialized(Person1(22))
sendSerialized(Person2(123456))
send(Person1(22))
send(Person2(123456))
}
}

Expand Down Expand Up @@ -279,8 +279,8 @@ class ServerSentEventsTest {
val serializer = Json.serializersModule.serializer(typeInfo.kotlinType!!)
Json.encodeToString(serializer, it)
}) {
sendSerialized(Customer(0, "Jet", "Brains"))
sendSerialized(Product(0, listOf(100, 200)))
send(Customer(0, "Jet", "Brains"))
send(Product(0, listOf(100, 200)))
}
}

Expand Down
Loading

0 comments on commit 19f01fe

Please sign in to comment.