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

fix: tsonAsyncIterator -> tsonAsyncIterable #66

Merged
merged 1 commit into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/async/src/shared.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
TsonAsyncOptions,
tsonAsyncIterator,
tsonAsyncIterable,
tsonBigint,
tsonPromise,
} from "tupleson";
Expand All @@ -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,
],
Expand Down
20 changes: 10 additions & 10 deletions src/async/deserializeAsync.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
TsonType,
createTsonAsync,
createTsonParseAsync,
tsonAsyncIterator,
tsonAsyncIterable,
tsonBigint,
tsonPromise,
} from "../index.js";
Expand All @@ -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* () {
Expand Down Expand Up @@ -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],
});

{
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -259,7 +259,7 @@ test("iterator error", async () => {

// ------------- server -------------------
const opts: TsonAsyncOptions = {
types: [tsonPromise, tsonAsyncIterator, tsonCustomError],
types: [tsonPromise, tsonAsyncIterable, tsonCustomError],
};

const server = await createTestServer({
Expand Down Expand Up @@ -351,7 +351,7 @@ test("values missing when stream ends", async () => {
}

const opts = {
types: [tsonPromise, tsonAsyncIterator],
types: [tsonPromise, tsonAsyncIterable],
} satisfies TsonAsyncOptions;

const parseOptions = {
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -566,7 +566,7 @@ test("e2e: simulated server crash", async () => {

// ------------- server -------------------
const opts = {
types: [tsonPromise, tsonAsyncIterator],
types: [tsonPromise, tsonAsyncIterable],
} satisfies TsonAsyncOptions;

const parseOptions = {
Expand Down Expand Up @@ -666,7 +666,7 @@ test("e2e: client aborted request", async () => {
type MockObj = ReturnType<typeof createMockObj>;
const opts = {
nonce: () => "__tson",
types: [tsonPromise, tsonAsyncIterator],
types: [tsonPromise, tsonAsyncIterable],
} satisfies TsonAsyncOptions;

const parseOptions = {
Expand Down
10 changes: 5 additions & 5 deletions src/async/handlers/tsonAsyncIterable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ 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<unknown> {
function isAsyncIterable(value: unknown): value is AsyncIterable<unknown> {
return (
!!value &&
typeof value === "object" &&
typeof (value as any)[Symbol.asyncIterator] === "function"
);
}

export const tsonAsyncIterator: TsonAsyncType<
export const tsonAsyncIterable: TsonAsyncType<
AsyncIterable<unknown>,
SerializedIteratorResult
SerializedIterableResult
> = {
async: true,
deserialize: (opts) => {
Expand Down Expand Up @@ -65,5 +65,5 @@ export const tsonAsyncIterator: TsonAsyncType<
yield [ITERATOR_ERROR, err];
}
},
test: isAsyncIterator,
test: isAsyncIterable,
};
6 changes: 3 additions & 3 deletions src/async/serializeAsync.test.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions src/extend/openai.test.ts
Original file line number Diff line number Diff line change
@@ -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"];
Expand All @@ -15,7 +15,7 @@ test.skipIf(!apiKey)("openai", async () => {

const tson = createTsonAsync({
nonce: () => "__tson",
types: [tsonAsyncIterator, tsonPromise],
types: [tsonAsyncIterable, tsonPromise],
});

const stringified = tson.stringify({
Expand Down
Loading