Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
cool
Browse files Browse the repository at this point in the history
  • Loading branch information
KATT committed Oct 13, 2023
1 parent 19e6dcd commit 46e26c2
Show file tree
Hide file tree
Showing 11 changed files with 16 additions and 191 deletions.
25 changes: 0 additions & 25 deletions examples/sse/package.json

This file was deleted.

18 changes: 0 additions & 18 deletions examples/sse/src/index.html

This file was deleted.

91 changes: 0 additions & 91 deletions examples/sse/src/server.ts

This file was deleted.

21 changes: 0 additions & 21 deletions examples/sse/src/shared.ts

This file was deleted.

11 changes: 0 additions & 11 deletions examples/sse/tsconfig.json

This file was deleted.

7 changes: 7 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions src/async/createTsonAsync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import {
} from "./serializeAsync.js";

/**
* @internal
*
* Only used for testing - when using the async you gotta pick which one you want
* @internal
*/
export const createTsonAsync = (opts: TsonAsyncOptions) => ({
parseJsonStream: createTsonParseAsync(opts),
Expand Down
16 changes: 3 additions & 13 deletions src/async/deserializeAsync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,12 @@ import {
} from "../sync/syncTypes.js";
import { TsonStreamInterruptedError } from "./asyncErrors.js";
import {
BrandSerialized,
TsonAsyncIndex,
TsonAsyncOptions,
TsonAsyncStringifierIterable,
TsonAsyncType,
} from "./asyncTypes.js";
import {
createReadableStream,
mapIterable,
readableStreamToAsyncIterable,
} from "./iterableUtils.js";
import { createReadableStream } from "./iterableUtils.js";
import { TsonAsyncValueTuple } from "./serializeAsync.js";

type WalkFn = (value: unknown) => unknown;
Expand Down Expand Up @@ -85,13 +80,8 @@ export function createTsonDeserializer(opts: TsonAsyncOptions) {

const idx = serializedValue as TsonAsyncIndex;

let controller: ReadableStreamDefaultController<unknown> =
null as unknown as ReadableStreamDefaultController<unknown>;
const readable = new ReadableStream<unknown>({
start(c) {
controller = c;
},
});
const [readable, controller] = createReadableStream();

// the `start` method is called "immediately when the object is constructed"
// [MDN](http://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/ReadableStream)
// so we're guaranteed that the controller is set in the cache
Expand Down
4 changes: 2 additions & 2 deletions src/async/iterableUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assert } from "../internals/assert";
import { assert } from "../internals/assert.js";

export async function* readableStreamToAsyncIterable<T>(
stream: ReadableStream<T>,
Expand Down Expand Up @@ -34,7 +34,7 @@ export async function* mapIterable<T, TValue>(
}
}

export function createReadableStream<TValue>() {
export function createReadableStream<TValue = unknown>() {
let controller: ReadableStreamDefaultController<TValue> =
null as unknown as ReadableStreamDefaultController<TValue>;
const stream = new ReadableStream<TValue>({
Expand Down
9 changes: 2 additions & 7 deletions src/async/serializeAsync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
TsonAsyncOptions,
TsonAsyncStringifier,
} from "./asyncTypes.js";
import { createReadableStream } from "./iterableUtils.js";

type WalkFn = (value: unknown) => unknown;

Expand Down Expand Up @@ -253,13 +254,7 @@ export function createTsonSSEResponse(opts: TsonAsyncOptions) {
const serialize = createAsyncTsonSerialize(opts);

return <TValue>(value: TValue) => {
let controller: ReadableStreamDefaultController<unknown> =
null as unknown as ReadableStreamDefaultController<unknown>;
const readable = new ReadableStream<unknown>({
start(c) {
controller = c;
},
});
const [readable, controller] = createReadableStream();

async function iterate() {
const [head, iterable] = serialize(value);
Expand Down
2 changes: 1 addition & 1 deletion src/async/sse.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-unnecessary-condition */
import { EventSourcePolyfill, NativeEventSource } from "event-source-polyfill";
import { expect, test } from "vitest";
global.EventSource = NativeEventSource || EventSourcePolyfill;
(global as any).EventSource = NativeEventSource || EventSourcePolyfill;

import { TsonAsyncOptions, tsonAsyncIterable, tsonPromise } from "../index.js";
import { createTestServer, sleep } from "../internals/testUtils.js";
Expand Down

0 comments on commit 46e26c2

Please sign in to comment.