diff --git a/src/async/createTsonAsync.ts b/src/async/createTsonAsync.ts index 21c1189..7ad472d 100644 --- a/src/async/createTsonAsync.ts +++ b/src/async/createTsonAsync.ts @@ -2,9 +2,11 @@ import { TsonAsyncOptions } from "./asyncTypes.js"; import { createTsonParseAsync, createTsonParseEventSource, + createTsonParseJsonStreamResponse, } from "./deserializeAsync.js"; import { createTsonSSEResponse, + createTsonSerializeJsonStreamResponse, createTsonStreamAsync, } from "./serializeAsync.js"; @@ -13,8 +15,10 @@ import { * @internal */ export const createTsonAsync = (opts: TsonAsyncOptions) => ({ - createEventSourceParser: createTsonParseEventSource(opts), + createEventSource: createTsonParseEventSource(opts), + fromJsonStreamResponse: createTsonParseJsonStreamResponse(opts), parseJsonStream: createTsonParseAsync(opts), stringifyJsonStream: createTsonStreamAsync(opts), + toJsonStreamResponse: createTsonSerializeJsonStreamResponse, toSSEResponse: createTsonSSEResponse(opts), }); diff --git a/src/async/deserializeAsync.ts b/src/async/deserializeAsync.ts index 5e44dd3..61d8ad9 100644 --- a/src/async/deserializeAsync.ts +++ b/src/async/deserializeAsync.ts @@ -285,10 +285,6 @@ export function createTsonParseEventSource(opts: TsonAsyncOptions) { signal?.addEventListener("abort", onAbort); - // eventSource.addEventListener("head", (e) => { - // controller.enqueue(JSON.parse(e.data)); - // }); - eventSource.onmessage = (msg) => { // eslint-disable-next-line @typescript-eslint/no-unsafe-argument controller.enqueue(JSON.parse(msg.data)); @@ -296,6 +292,7 @@ export function createTsonParseEventSource(opts: TsonAsyncOptions) { eventSource.addEventListener("close", () => { controller.close(); + eventSource.close(); }); const iterable = readableStreamToAsyncIterable(stream); diff --git a/src/async/sse.test.ts b/src/async/sse.test.ts index cd7622e..e1228d4 100644 --- a/src/async/sse.test.ts +++ b/src/async/sse.test.ts @@ -86,7 +86,7 @@ test("SSE response test", async () => { { // e2e const ac = new AbortController(); - const shape = await tson.createEventSourceParser(server.url, { + const shape = await tson.createEventSource(server.url, { signal: ac.signal, });