diff --git a/examples/async/src/shared.ts b/examples/async/src/shared.ts index a84353cf..cc973f9d 100644 --- a/examples/async/src/shared.ts +++ b/examples/async/src/shared.ts @@ -1,6 +1,6 @@ import { TsonAsyncOptions, - tsonAsyncIterator, + tsonAsyncIterable, tsonBigint, tsonPromise, } from "tupleson"; @@ -14,7 +14,7 @@ export const tsonOptions: TsonAsyncOptions = { // Allow serialization of promises tsonPromise, // Allow serialization of async iterators - tsonAsyncIterator, + tsonAsyncIterable, // Allow serialization of bigints tsonBigint, ], diff --git a/src/async/deserializeAsync.test.ts b/src/async/deserializeAsync.test.ts index eca5d930..166a78ea 100644 --- a/src/async/deserializeAsync.test.ts +++ b/src/async/deserializeAsync.test.ts @@ -6,7 +6,7 @@ import { TsonType, createTsonAsync, createTsonParseAsync, - tsonAsyncIterator, + tsonAsyncIterable, tsonBigint, tsonPromise, } from "../index.js"; @@ -24,7 +24,7 @@ import { mapIterable, readableStreamToAsyncIterable } from "./iterableUtils.js"; test("deserialize variable chunk length", async () => { const tson = createTsonAsync({ nonce: () => "__tson", - types: [tsonAsyncIterator, tsonPromise, tsonBigint], + types: [tsonAsyncIterable, tsonPromise, tsonBigint], }); { const iterable = (async function* () { @@ -62,7 +62,7 @@ test("deserialize variable chunk length", async () => { test("deserialize async iterable", async () => { const tson = createTsonAsync({ nonce: () => "__tson", - types: [tsonAsyncIterator, tsonPromise, tsonBigint], + types: [tsonAsyncIterable, tsonPromise, tsonBigint], }); { @@ -95,7 +95,7 @@ test("deserialize async iterable", async () => { test("stringify async iterable + promise", async () => { const tson = createTsonAsync({ nonce: () => "__tson", - types: [tsonAsyncIterator, tsonPromise, tsonBigint], + types: [tsonAsyncIterable, tsonPromise, tsonBigint], }); const parseOptions = { @@ -158,7 +158,7 @@ test("e2e: stringify async iterable and promise over the network", async () => { // ------------- server ------------------- const opts: TsonAsyncOptions = { - types: [tsonPromise, tsonAsyncIterator, tsonBigint], + types: [tsonPromise, tsonAsyncIterable, tsonBigint], }; const server = await createTestServer({ @@ -259,7 +259,7 @@ test("iterator error", async () => { // ------------- server ------------------- const opts: TsonAsyncOptions = { - types: [tsonPromise, tsonAsyncIterator, tsonCustomError], + types: [tsonPromise, tsonAsyncIterable, tsonCustomError], }; const server = await createTestServer({ @@ -351,7 +351,7 @@ test("values missing when stream ends", async () => { } const opts = { - types: [tsonPromise, tsonAsyncIterator], + types: [tsonPromise, tsonAsyncIterable], } satisfies TsonAsyncOptions; const parseOptions = { @@ -477,7 +477,7 @@ test("1 iterator completed but another never finishes", async () => { } const opts = { - types: [tsonPromise, tsonAsyncIterator], + types: [tsonPromise, tsonAsyncIterable], } satisfies TsonAsyncOptions; const parseOptions = { @@ -566,7 +566,7 @@ test("e2e: simulated server crash", async () => { // ------------- server ------------------- const opts = { - types: [tsonPromise, tsonAsyncIterator], + types: [tsonPromise, tsonAsyncIterable], } satisfies TsonAsyncOptions; const parseOptions = { @@ -666,7 +666,7 @@ test("e2e: client aborted request", async () => { type MockObj = ReturnType; const opts = { nonce: () => "__tson", - types: [tsonPromise, tsonAsyncIterator], + types: [tsonPromise, tsonAsyncIterable], } satisfies TsonAsyncOptions; const parseOptions = { diff --git a/src/async/handlers/tsonAsyncIterable.ts b/src/async/handlers/tsonAsyncIterable.ts index 0117d04b..8a99cfc1 100644 --- a/src/async/handlers/tsonAsyncIterable.ts +++ b/src/async/handlers/tsonAsyncIterable.ts @@ -7,11 +7,11 @@ import { TsonAsyncType } from "../asyncTypes.js"; const ITERATOR_VALUE = 0; const ITERATOR_ERROR = 1; const ITERATOR_DONE = 2; -type SerializedIteratorResult = +type SerializedIterableResult = | [typeof ITERATOR_DONE] | [typeof ITERATOR_ERROR, unknown] | [typeof ITERATOR_VALUE, unknown]; -function isAsyncIterator(value: unknown): value is AsyncIterable { +function isAsyncIterable(value: unknown): value is AsyncIterable { return ( !!value && typeof value === "object" && @@ -19,9 +19,9 @@ function isAsyncIterator(value: unknown): value is AsyncIterable { ); } -export const tsonAsyncIterator: TsonAsyncType< +export const tsonAsyncIterable: TsonAsyncType< AsyncIterable, - SerializedIteratorResult + SerializedIterableResult > = { async: true, deserialize: (opts) => { @@ -65,5 +65,5 @@ export const tsonAsyncIterator: TsonAsyncType< yield [ITERATOR_ERROR, err]; } }, - test: isAsyncIterator, + test: isAsyncIterable, }; diff --git a/src/async/serializeAsync.test.ts b/src/async/serializeAsync.test.ts index d47a50c1..fff5c652 100644 --- a/src/async/serializeAsync.test.ts +++ b/src/async/serializeAsync.test.ts @@ -1,6 +1,6 @@ import { expect, test } from "vitest"; -import { tsonAsyncIterator, tsonBigint, tsonPromise } from "../index.js"; +import { tsonAsyncIterable, tsonBigint, tsonPromise } from "../index.js"; import { sleep } from "../internals/testUtils.js"; import { createAsyncTsonSerialize, @@ -103,7 +103,7 @@ test("serialize 2 promises", async () => { test("serialize async iterable", async () => { const serialize = createAsyncTsonSerialize({ nonce: () => "__tson", - types: [tsonAsyncIterator], + types: [tsonAsyncIterable], }); async function* iterable() { @@ -160,7 +160,7 @@ test("serialize async iterable", async () => { test("stringify async iterable + promise", async () => { const stringify = createTsonStringifyAsync({ nonce: () => "__tson", - types: [tsonAsyncIterator, tsonPromise, tsonBigint], + types: [tsonAsyncIterable, tsonPromise, tsonBigint], }); async function* iterable() { diff --git a/src/extend/openai.test.ts b/src/extend/openai.test.ts index 88c6c07b..6ba0d466 100644 --- a/src/extend/openai.test.ts +++ b/src/extend/openai.test.ts @@ -1,7 +1,7 @@ import OpenAI from "openai"; import { expect, test } from "vitest"; -import { createTsonAsync, tsonAsyncIterator, tsonPromise } from "../index.js"; +import { createTsonAsync, tsonAsyncIterable, tsonPromise } from "../index.js"; import { assert } from "../internals/assert.js"; const apiKey = process.env["OPENAI_API_KEY"]; @@ -15,7 +15,7 @@ test.skipIf(!apiKey)("openai", async () => { const tson = createTsonAsync({ nonce: () => "__tson", - types: [tsonAsyncIterator, tsonPromise], + types: [tsonAsyncIterable, tsonPromise], }); const stringified = tson.stringify({