From c5faa90c72047be4edc217a7565fd5acf6029d54 Mon Sep 17 00:00:00 2001 From: Alex / KATT Date: Sat, 7 Oct 2023 14:12:30 +0200 Subject: [PATCH] chore: restructure files (#45) - move all sync stuff to `./sync` - move all async stuff to `./async` - make sure async stuff "extends" the sync stuff - project only has 1 index file - tests prioritize to `import` from the root index file in order to ensure they're actually exported --- README.md | 2 + src/async/asyncTypes.ts | 6 +-- src/async/deserializeAsync.test.ts | 5 +-- src/async/deserializeAsync.ts | 2 +- src/{ => async}/handlers/tsonAsyncIterable.ts | 4 +- src/{ => async}/handlers/tsonPromise.test.ts | 32 +++++++--------- src/{ => async}/handlers/tsonPromise.ts | 4 +- src/{internals => async}/iterableUtils.ts | 0 src/async/serializeAsync.ts | 2 +- src/handlers/index.ts | 14 ------- src/index.test.ts | 2 +- src/index.ts | 37 ++++++++++++++----- src/internals/getNonce.ts | 2 +- src/internals/isTsonTuple.ts | 2 +- src/sync/createTson.ts | 2 +- src/sync/deserialize.ts | 2 +- src/{ => sync}/handlers/tsonBigint.test.ts | 6 +-- src/{ => sync}/handlers/tsonBigint.ts | 2 +- src/{ => sync}/handlers/tsonDate.test.ts | 3 +- src/{ => sync}/handlers/tsonDate.ts | 2 +- src/{ => sync}/handlers/tsonMap.test.ts | 3 +- src/{ => sync}/handlers/tsonMap.ts | 2 +- .../handlers/tsonNumberGuard.test.ts | 5 +-- src/{ => sync}/handlers/tsonNumberGuard.ts | 2 +- src/{ => sync}/handlers/tsonRegExp.test.ts | 3 +- src/{ => sync}/handlers/tsonRegExp.ts | 2 +- src/{ => sync}/handlers/tsonSet.test.ts | 3 +- src/{ => sync}/handlers/tsonSet.ts | 2 +- src/{ => sync}/handlers/tsonSymbol.test.ts | 3 +- src/{ => sync}/handlers/tsonSymbol.ts | 2 +- src/{ => sync}/handlers/tsonURL.test.ts | 3 +- src/{ => sync}/handlers/tsonURL.ts | 2 +- src/{ => sync}/handlers/tsonUndefined.test.ts | 3 +- src/{ => sync}/handlers/tsonUndefined.ts | 2 +- .../handlers/tsonUnknownObjectGuard.test.ts | 8 ++-- .../handlers/tsonUnknownObjectGuard.ts | 6 +-- src/sync/serialize.ts | 2 +- src/{ => sync}/stringify.test.ts | 12 +++--- src/{types.test.ts => sync/syncTypes.test.ts} | 5 +-- src/{types.ts => sync/syncTypes.ts} | 0 40 files changed, 95 insertions(+), 106 deletions(-) rename src/{ => async}/handlers/tsonAsyncIterable.ts (92%) rename src/{ => async}/handlers/tsonPromise.test.ts (95%) rename src/{ => async}/handlers/tsonPromise.ts (92%) rename src/{internals => async}/iterableUtils.ts (100%) delete mode 100644 src/handlers/index.ts rename src/{ => sync}/handlers/tsonBigint.test.ts (83%) rename src/{ => sync}/handlers/tsonBigint.ts (78%) rename src/{ => sync}/handlers/tsonDate.test.ts (76%) rename src/{ => sync}/handlers/tsonDate.ts (81%) rename src/{ => sync}/handlers/tsonMap.test.ts (78%) rename src/{ => sync}/handlers/tsonMap.ts (82%) rename src/{ => sync}/handlers/tsonNumberGuard.test.ts (81%) rename src/{ => sync}/handlers/tsonNumberGuard.ts (88%) rename src/{ => sync}/handlers/tsonRegExp.test.ts (87%) rename src/{ => sync}/handlers/tsonRegExp.ts (87%) rename src/{ => sync}/handlers/tsonSet.test.ts (78%) rename src/{ => sync}/handlers/tsonSet.ts (80%) rename src/{ => sync}/handlers/tsonSymbol.test.ts (83%) rename src/{ => sync}/handlers/tsonSymbol.ts (83%) rename src/{ => sync}/handlers/tsonURL.test.ts (87%) rename src/{ => sync}/handlers/tsonURL.ts (80%) rename src/{ => sync}/handlers/tsonUndefined.test.ts (78%) rename src/{ => sync}/handlers/tsonUndefined.ts (77%) rename src/{ => sync}/handlers/tsonUnknownObjectGuard.test.ts (85%) rename src/{ => sync}/handlers/tsonUnknownObjectGuard.ts (82%) rename src/{ => sync}/stringify.test.ts (80%) rename src/{types.test.ts => sync/syncTypes.test.ts} (79%) rename src/{types.ts => sync/syncTypes.ts} (100%) diff --git a/README.md b/README.md index 4b0fdfcc..2632105a 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,8 @@ import { createTson, // Serialize `bigint` tsonBigint, + // Serialize `Date` + tsonDate, // Serialize `Map`s tsonMap, // **throws** when encountering Infinity or NaN diff --git a/src/async/asyncTypes.ts b/src/async/asyncTypes.ts index 6e215671..bc2989ee 100644 --- a/src/async/asyncTypes.ts +++ b/src/async/asyncTypes.ts @@ -1,7 +1,7 @@ import { TsonError } from "../errors.js"; -import { TsonType } from "../types.js"; -import { TsonBranded, TsonTypeTesterCustom } from "../types.js"; -import { serialized } from "../types.js"; +import { TsonType } from "../sync/syncTypes.js"; +import { TsonBranded, TsonTypeTesterCustom } from "../sync/syncTypes.js"; +import { serialized } from "../sync/syncTypes.js"; export type TsonAsyncStringifierIterable = AsyncIterable & { [serialized]: TValue; diff --git a/src/async/deserializeAsync.test.ts b/src/async/deserializeAsync.test.ts index 16cdb49b..005c46f9 100644 --- a/src/async/deserializeAsync.test.ts +++ b/src/async/deserializeAsync.test.ts @@ -7,12 +7,9 @@ import { tsonPromise, } from "../index.js"; import { assert } from "../internals/assert.js"; -import { - mapIterable, - readableStreamToAsyncIterable, -} from "../internals/iterableUtils.js"; import { createTestServer } from "../internals/testUtils.js"; import { TsonAsyncOptions } from "./asyncTypes.js"; +import { mapIterable, readableStreamToAsyncIterable } from "./iterableUtils.js"; test("deserialize variable chunk length", async () => { const tson = createTsonAsync({ diff --git a/src/async/deserializeAsync.ts b/src/async/deserializeAsync.ts index 4eeae8bd..70093371 100644 --- a/src/async/deserializeAsync.ts +++ b/src/async/deserializeAsync.ts @@ -8,7 +8,7 @@ import { TsonNonce, TsonSerialized, TsonTransformerSerializeDeserialize, -} from "../types.js"; +} from "../sync/syncTypes.js"; import { TsonAsyncIndex, TsonAsyncOptions, diff --git a/src/handlers/tsonAsyncIterable.ts b/src/async/handlers/tsonAsyncIterable.ts similarity index 92% rename from src/handlers/tsonAsyncIterable.ts rename to src/async/handlers/tsonAsyncIterable.ts index b9b96a52..34a2fa4b 100644 --- a/src/handlers/tsonAsyncIterable.ts +++ b/src/async/handlers/tsonAsyncIterable.ts @@ -1,5 +1,5 @@ -import { TsonAsyncType } from "../async/asyncTypes.js"; -import { TsonPromiseRejectionError } from "../errors.js"; +import { TsonPromiseRejectionError } from "../../errors.js"; +import { TsonAsyncType } from "../asyncTypes.js"; const ITERATOR_VALUE = 0; const ITERATOR_ERROR = 1; diff --git a/src/handlers/tsonPromise.test.ts b/src/async/handlers/tsonPromise.test.ts similarity index 95% rename from src/handlers/tsonPromise.test.ts rename to src/async/handlers/tsonPromise.test.ts index d7ae1db6..9e311f99 100644 --- a/src/handlers/tsonPromise.test.ts +++ b/src/async/handlers/tsonPromise.test.ts @@ -1,26 +1,25 @@ import { assert, expect, test } from "vitest"; -import { TsonAsyncOptions } from "../async/asyncTypes.js"; import { - createTsonParseAsync, - createTsonParseAsyncInner, -} from "../async/deserializeAsync.js"; -import { - TsonAsyncValueTuple, + TsonAsyncOptions, + TsonType, createAsyncTsonSerialize, + createTsonAsync, + createTsonParseAsync, createTsonStringifyAsync, -} from "../async/serializeAsync.js"; -import { createTsonAsync, tsonPromise } from "../index.js"; -import { - mapIterable, - readableStreamToAsyncIterable, -} from "../internals/iterableUtils.js"; + tsonPromise, +} from "../../index.js"; import { createTestServer, waitError, waitFor, -} from "../internals/testUtils.js"; -import { TsonSerialized, TsonType } from "../types.js"; +} from "../../internals/testUtils.js"; +import { createTsonParseAsyncInner } from "../deserializeAsync.js"; +import { + mapIterable, + readableStreamToAsyncIterable, +} from "../iterableUtils.js"; +import { TsonAsyncValueTuple } from "../serializeAsync.js"; const createPromise = (result: () => T, wait = 1) => { return new Promise((resolve, reject) => { @@ -284,10 +283,7 @@ test("stringifier - promise in promise", async () => { buffer.push(value.trimEnd()); } - const full = JSON.parse(buffer.join("")) as [ - TsonSerialized, - TsonAsyncValueTuple[], - ]; + const full = JSON.parse(buffer.join("")) as [unknown, TsonAsyncValueTuple[]]; const [head, values] = full; expect(head).toMatchInlineSnapshot(` diff --git a/src/handlers/tsonPromise.ts b/src/async/handlers/tsonPromise.ts similarity index 92% rename from src/handlers/tsonPromise.ts rename to src/async/handlers/tsonPromise.ts index 086f8345..aab14544 100644 --- a/src/handlers/tsonPromise.ts +++ b/src/async/handlers/tsonPromise.ts @@ -1,5 +1,5 @@ -import { TsonAsyncType } from "../async/asyncTypes.js"; -import { TsonPromiseRejectionError } from "../errors.js"; +import { TsonPromiseRejectionError } from "../../errors.js"; +import { TsonAsyncType } from "../asyncTypes.js"; function isPromise(value: unknown): value is Promise { return ( diff --git a/src/internals/iterableUtils.ts b/src/async/iterableUtils.ts similarity index 100% rename from src/internals/iterableUtils.ts rename to src/async/iterableUtils.ts diff --git a/src/async/serializeAsync.ts b/src/async/serializeAsync.ts index 29bf8543..bf3951ba 100644 --- a/src/async/serializeAsync.ts +++ b/src/async/serializeAsync.ts @@ -11,7 +11,7 @@ import { TsonTypeHandlerKey, TsonTypeTesterCustom, TsonTypeTesterPrimitive, -} from "../types.js"; +} from "../sync/syncTypes.js"; import { TsonAsyncIndex, TsonAsyncOptions, diff --git a/src/handlers/index.ts b/src/handlers/index.ts deleted file mode 100644 index 49c84855..00000000 --- a/src/handlers/index.ts +++ /dev/null @@ -1,14 +0,0 @@ -export * from "./tsonBigint.js"; -export * from "./tsonDate.js"; -export * from "./tsonRegExp.js"; -export * from "./tsonSet.js"; -export * from "./tsonMap.js"; -export * from "./tsonUndefined.js"; -export * from "./tsonUnknownObjectGuard.js"; -export * from "./tsonNumberGuard.js"; -export * from "./tsonURL.js"; -export * from "./tsonSymbol.js"; - -// Async types -export * from "./tsonPromise.js"; -export * from "./tsonAsyncIterable.js"; diff --git a/src/index.test.ts b/src/index.test.ts index 3e0b1a49..a4b6dd4a 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -8,7 +8,7 @@ import { tsonPromise, } from "./index.js"; import { expectError, waitError, waitFor } from "./internals/testUtils.js"; -import { TsonSerialized } from "./types.js"; +import { TsonSerialized } from "./sync/syncTypes.js"; test("multiple handlers for primitive string found", () => { const stringHandler: TsonType = { diff --git a/src/index.ts b/src/index.ts index 2c4975c7..b263389e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,15 +1,32 @@ -// async -export { createTsonAsync } from "./async/createTsonAsync.js"; -export { createTsonParseAsync } from "./async/deserializeAsync.js"; -export { createTsonStringifyAsync } from "./async/serializeAsync.js"; - -// sync +// --- sync -- export { createTson } from "./sync/createTson.js"; export { createTsonDeserialize, createTsonParser } from "./sync/deserialize.js"; export { createTsonSerialize, createTsonStringify } from "./sync/serialize.js"; -export * from "./handlers/index.js"; +export type { TsonType } from "./sync/syncTypes.js"; +export type { TsonOptions } from "./sync/syncTypes.js"; + +// type handlers +export * from "./sync/handlers/tsonBigint.js"; +export * from "./sync/handlers/tsonDate.js"; +export * from "./sync/handlers/tsonRegExp.js"; +export * from "./sync/handlers/tsonSet.js"; +export * from "./sync/handlers/tsonMap.js"; +export * from "./sync/handlers/tsonUndefined.js"; +export * from "./sync/handlers/tsonUnknownObjectGuard.js"; +export * from "./sync/handlers/tsonNumberGuard.js"; +export * from "./sync/handlers/tsonURL.js"; +export * from "./sync/handlers/tsonSymbol.js"; -// types +// --- async -- export type { TsonAsyncOptions } from "./async/asyncTypes.js"; -export type { TsonType } from "./types.js"; -export type { TsonOptions } from "./types.js"; + +export { createTsonAsync } from "./async/createTsonAsync.js"; +export { createTsonParseAsync } from "./async/deserializeAsync.js"; +export { + createAsyncTsonSerialize, + createTsonStringifyAsync, +} from "./async/serializeAsync.js"; + +// type handlers +export * from "./async/handlers/tsonAsyncIterable.js"; +export * from "./async/handlers/tsonPromise.js"; diff --git a/src/internals/getNonce.ts b/src/internals/getNonce.ts index abe97f60..cdee3d6a 100644 --- a/src/internals/getNonce.ts +++ b/src/internals/getNonce.ts @@ -1,4 +1,4 @@ -import { TsonNonce } from "../types.js"; +import { TsonNonce } from "../sync/syncTypes.js"; const randomString = () => Math.random().toString(36).slice(2); diff --git a/src/internals/isTsonTuple.ts b/src/internals/isTsonTuple.ts index 2a462c45..e2107222 100644 --- a/src/internals/isTsonTuple.ts +++ b/src/internals/isTsonTuple.ts @@ -1,4 +1,4 @@ -import { TsonTuple } from "../types.js"; +import { TsonTuple } from "../sync/syncTypes.js"; export function isTsonTuple(v: unknown, nonce: string): v is TsonTuple { return Array.isArray(v) && v.length === 3 && v[2] === nonce; diff --git a/src/sync/createTson.ts b/src/sync/createTson.ts index 3b600b80..a5eba7fa 100644 --- a/src/sync/createTson.ts +++ b/src/sync/createTson.ts @@ -1,6 +1,6 @@ -import { TsonOptions } from "../types.js"; import { createTsonDeserialize, createTsonParser } from "./deserialize.js"; import { createTsonSerialize, createTsonStringify } from "./serialize.js"; +import { TsonOptions } from "./syncTypes.js"; export const createTson = (opts: TsonOptions) => ({ deserialize: createTsonDeserialize(opts), diff --git a/src/sync/deserialize.ts b/src/sync/deserialize.ts index f19aee74..da27568a 100644 --- a/src/sync/deserialize.ts +++ b/src/sync/deserialize.ts @@ -7,7 +7,7 @@ import { TsonParseFn, TsonSerialized, TsonTransformerSerializeDeserialize, -} from "../types.js"; +} from "./syncTypes.js"; type WalkFn = (value: unknown) => unknown; type WalkerFactory = (nonce: TsonNonce) => WalkFn; diff --git a/src/handlers/tsonBigint.test.ts b/src/sync/handlers/tsonBigint.test.ts similarity index 83% rename from src/handlers/tsonBigint.test.ts rename to src/sync/handlers/tsonBigint.test.ts index 023c6279..a1ebd236 100644 --- a/src/handlers/tsonBigint.test.ts +++ b/src/sync/handlers/tsonBigint.test.ts @@ -1,8 +1,6 @@ import { expect, test } from "vitest"; -import { createTson } from "../index.js"; -import { tsonMap, tsonSet } from "./index.js"; -import { tsonBigint } from "./tsonBigint.js"; +import { createTson, tsonBigint, tsonMap, tsonSet } from "../../index.js"; test("bigint", () => { const t = createTson({ @@ -10,7 +8,7 @@ test("bigint", () => { }); { - // bigint + // bigint` const expected = 1n; const stringified = t.stringify(expected); diff --git a/src/handlers/tsonBigint.ts b/src/sync/handlers/tsonBigint.ts similarity index 78% rename from src/handlers/tsonBigint.ts rename to src/sync/handlers/tsonBigint.ts index 2d0d0523..0559852a 100644 --- a/src/handlers/tsonBigint.ts +++ b/src/sync/handlers/tsonBigint.ts @@ -1,4 +1,4 @@ -import { TsonType } from "../types.js"; +import { TsonType } from "../syncTypes.js"; export const tsonBigint: TsonType = { deserialize: (v) => BigInt(v), diff --git a/src/handlers/tsonDate.test.ts b/src/sync/handlers/tsonDate.test.ts similarity index 76% rename from src/handlers/tsonDate.test.ts rename to src/sync/handlers/tsonDate.test.ts index 0bbb7bdf..362db6fb 100644 --- a/src/handlers/tsonDate.test.ts +++ b/src/sync/handlers/tsonDate.test.ts @@ -1,7 +1,6 @@ import { expect, test } from "vitest"; -import { createTson } from "../index.js"; -import { tsonDate } from "./index.js"; +import { createTson, tsonDate } from "../../index.js"; test("Date", () => { const ctx = createTson({ diff --git a/src/handlers/tsonDate.ts b/src/sync/handlers/tsonDate.ts similarity index 81% rename from src/handlers/tsonDate.ts rename to src/sync/handlers/tsonDate.ts index 36ab43e8..f2d2ca05 100644 --- a/src/handlers/tsonDate.ts +++ b/src/sync/handlers/tsonDate.ts @@ -1,4 +1,4 @@ -import { TsonType } from "../types.js"; +import { TsonType } from "../syncTypes.js"; export const tsonDate: TsonType = { deserialize: (value) => new Date(value), diff --git a/src/handlers/tsonMap.test.ts b/src/sync/handlers/tsonMap.test.ts similarity index 78% rename from src/handlers/tsonMap.test.ts rename to src/sync/handlers/tsonMap.test.ts index a750ca73..c19264bd 100644 --- a/src/handlers/tsonMap.test.ts +++ b/src/sync/handlers/tsonMap.test.ts @@ -1,7 +1,6 @@ import { expect, test } from "vitest"; -import { createTson } from "../index.js"; -import { tsonMap } from "./index.js"; +import { createTson, tsonMap } from "../../index.js"; test("Map", () => { const t = createTson({ diff --git a/src/handlers/tsonMap.ts b/src/sync/handlers/tsonMap.ts similarity index 82% rename from src/handlers/tsonMap.ts rename to src/sync/handlers/tsonMap.ts index 11266a53..daf7f8da 100644 --- a/src/handlers/tsonMap.ts +++ b/src/sync/handlers/tsonMap.ts @@ -1,4 +1,4 @@ -import { TsonType } from "../types.js"; +import { TsonType } from "../syncTypes.js"; export const tsonMap: TsonType, [unknown, unknown][]> = { deserialize: (v) => new Map(v), diff --git a/src/handlers/tsonNumberGuard.test.ts b/src/sync/handlers/tsonNumberGuard.test.ts similarity index 81% rename from src/handlers/tsonNumberGuard.test.ts rename to src/sync/handlers/tsonNumberGuard.test.ts index 52a1c084..b5713517 100644 --- a/src/handlers/tsonNumberGuard.test.ts +++ b/src/sync/handlers/tsonNumberGuard.test.ts @@ -1,8 +1,7 @@ import { expect, test } from "vitest"; -import { createTson } from "../index.js"; -import { expectError } from "../internals/testUtils.js"; -import { tsonNumberGuard } from "./index.js"; +import { createTson, tsonNumberGuard } from "../../index.js"; +import { expectError } from "../../internals/testUtils.js"; test("number", () => { const t = createTson({ diff --git a/src/handlers/tsonNumberGuard.ts b/src/sync/handlers/tsonNumberGuard.ts similarity index 88% rename from src/handlers/tsonNumberGuard.ts rename to src/sync/handlers/tsonNumberGuard.ts index f27b2782..c3b4da57 100644 --- a/src/handlers/tsonNumberGuard.ts +++ b/src/sync/handlers/tsonNumberGuard.ts @@ -1,4 +1,4 @@ -import { TsonType } from "../types.js"; +import { TsonType } from "../syncTypes.js"; /** * Prevents `NaN` and `Infinity` from being serialized diff --git a/src/handlers/tsonRegExp.test.ts b/src/sync/handlers/tsonRegExp.test.ts similarity index 87% rename from src/handlers/tsonRegExp.test.ts rename to src/sync/handlers/tsonRegExp.test.ts index ddddb7c0..3e495553 100644 --- a/src/handlers/tsonRegExp.test.ts +++ b/src/sync/handlers/tsonRegExp.test.ts @@ -1,7 +1,6 @@ import { expect, test } from "vitest"; -import { createTson } from "../index.js"; -import { tsonRegExp } from "./index.js"; +import { createTson, tsonRegExp } from "../../index.js"; test("regex", () => { const t = createTson({ diff --git a/src/handlers/tsonRegExp.ts b/src/sync/handlers/tsonRegExp.ts similarity index 87% rename from src/handlers/tsonRegExp.ts rename to src/sync/handlers/tsonRegExp.ts index eab9c544..e19189c5 100644 --- a/src/handlers/tsonRegExp.ts +++ b/src/sync/handlers/tsonRegExp.ts @@ -1,4 +1,4 @@ -import { TsonType } from "../types.js"; +import { TsonType } from "../syncTypes.js"; export const tsonRegExp: TsonType = { deserialize: (str) => { diff --git a/src/handlers/tsonSet.test.ts b/src/sync/handlers/tsonSet.test.ts similarity index 78% rename from src/handlers/tsonSet.test.ts rename to src/sync/handlers/tsonSet.test.ts index 4c4bf4e4..62f43624 100644 --- a/src/handlers/tsonSet.test.ts +++ b/src/sync/handlers/tsonSet.test.ts @@ -1,7 +1,6 @@ import { expect, test } from "vitest"; -import { createTson } from "../index.js"; -import { tsonSet } from "./index.js"; +import { createTson, tsonSet } from "../../index.js"; test("Set", () => { const t = createTson({ diff --git a/src/handlers/tsonSet.ts b/src/sync/handlers/tsonSet.ts similarity index 80% rename from src/handlers/tsonSet.ts rename to src/sync/handlers/tsonSet.ts index 4b8fe6fe..19a00422 100644 --- a/src/handlers/tsonSet.ts +++ b/src/sync/handlers/tsonSet.ts @@ -1,4 +1,4 @@ -import { TsonType } from "../types.js"; +import { TsonType } from "../syncTypes.js"; export const tsonSet: TsonType, unknown[]> = { deserialize: (v) => new Set(v), diff --git a/src/handlers/tsonSymbol.test.ts b/src/sync/handlers/tsonSymbol.test.ts similarity index 83% rename from src/handlers/tsonSymbol.test.ts rename to src/sync/handlers/tsonSymbol.test.ts index 5d7f9749..9af7bfb7 100644 --- a/src/handlers/tsonSymbol.test.ts +++ b/src/sync/handlers/tsonSymbol.test.ts @@ -1,7 +1,6 @@ import { expect, test } from "vitest"; -import { createTson } from "../index.js"; -import { tsonSymbol } from "./index.js"; +import { createTson, tsonSymbol } from "../../index.js"; test("symbol", () => { const symbol1 = Symbol("foo"); diff --git a/src/handlers/tsonSymbol.ts b/src/sync/handlers/tsonSymbol.ts similarity index 83% rename from src/handlers/tsonSymbol.ts rename to src/sync/handlers/tsonSymbol.ts index bedc6217..bd8584af 100644 --- a/src/handlers/tsonSymbol.ts +++ b/src/sync/handlers/tsonSymbol.ts @@ -1,4 +1,4 @@ -import { TsonType } from "../types.js"; +import { TsonType } from "../syncTypes.js"; export const tsonSymbol = ( symbol: T, diff --git a/src/handlers/tsonURL.test.ts b/src/sync/handlers/tsonURL.test.ts similarity index 87% rename from src/handlers/tsonURL.test.ts rename to src/sync/handlers/tsonURL.test.ts index c06f7bee..bf02c254 100644 --- a/src/handlers/tsonURL.test.ts +++ b/src/sync/handlers/tsonURL.test.ts @@ -1,7 +1,6 @@ import { expect, test } from "vitest"; -import { createTson } from "../index.js"; -import { tsonURL } from "./index.js"; +import { createTson, tsonURL } from "../../index.js"; test("URL", () => { const ctx = createTson({ diff --git a/src/handlers/tsonURL.ts b/src/sync/handlers/tsonURL.ts similarity index 80% rename from src/handlers/tsonURL.ts rename to src/sync/handlers/tsonURL.ts index 33a05ae9..7eaefb6b 100644 --- a/src/handlers/tsonURL.ts +++ b/src/sync/handlers/tsonURL.ts @@ -1,4 +1,4 @@ -import { TsonType } from "../types.js"; +import { TsonType } from "../syncTypes.js"; export const tsonURL: TsonType = { deserialize: (value) => new URL(value), diff --git a/src/handlers/tsonUndefined.test.ts b/src/sync/handlers/tsonUndefined.test.ts similarity index 78% rename from src/handlers/tsonUndefined.test.ts rename to src/sync/handlers/tsonUndefined.test.ts index 8cd97d9d..ea1fc471 100644 --- a/src/handlers/tsonUndefined.test.ts +++ b/src/sync/handlers/tsonUndefined.test.ts @@ -1,7 +1,6 @@ import { expect, test } from "vitest"; -import { createTson } from "../index.js"; -import { tsonUndefined } from "./index.js"; +import { createTson, tsonUndefined } from "../../index.js"; test("undefined", () => { const ctx = createTson({ diff --git a/src/handlers/tsonUndefined.ts b/src/sync/handlers/tsonUndefined.ts similarity index 77% rename from src/handlers/tsonUndefined.ts rename to src/sync/handlers/tsonUndefined.ts index 4d638e5f..8f0cc625 100644 --- a/src/handlers/tsonUndefined.ts +++ b/src/sync/handlers/tsonUndefined.ts @@ -1,4 +1,4 @@ -import { TsonType } from "../types.js"; +import { TsonType } from "../syncTypes.js"; export const tsonUndefined: TsonType = { deserialize: () => undefined, diff --git a/src/handlers/tsonUnknownObjectGuard.test.ts b/src/sync/handlers/tsonUnknownObjectGuard.test.ts similarity index 85% rename from src/handlers/tsonUnknownObjectGuard.test.ts rename to src/sync/handlers/tsonUnknownObjectGuard.test.ts index 098dba58..0739c857 100644 --- a/src/handlers/tsonUnknownObjectGuard.test.ts +++ b/src/sync/handlers/tsonUnknownObjectGuard.test.ts @@ -1,12 +1,12 @@ import { assert, expect, test } from "vitest"; -import { createTson } from "../index.js"; -import { expectError } from "../internals/testUtils.js"; -import { tsonSet } from "./index.js"; import { TsonUnknownObjectGuardError, + createTson, + tsonSet, tsonUnknownObjectGuard, -} from "./tsonUnknownObjectGuard.js"; +} from "../../index.js"; +import { expectError } from "../../internals/testUtils.js"; test("guard unwanted objects", () => { // Sets are okay, but not Maps diff --git a/src/handlers/tsonUnknownObjectGuard.ts b/src/sync/handlers/tsonUnknownObjectGuard.ts similarity index 82% rename from src/handlers/tsonUnknownObjectGuard.ts rename to src/sync/handlers/tsonUnknownObjectGuard.ts index a3115d8f..f4316d7e 100644 --- a/src/handlers/tsonUnknownObjectGuard.ts +++ b/src/sync/handlers/tsonUnknownObjectGuard.ts @@ -1,6 +1,6 @@ -import { TsonError } from "../errors.js"; -import { isPlainObject } from "../internals/isPlainObject.js"; -import { TsonType } from "../types.js"; +import { TsonError } from "../../errors.js"; +import { isPlainObject } from "../../internals/isPlainObject.js"; +import { TsonType } from "../syncTypes.js"; export class TsonUnknownObjectGuardError extends TsonError { /** diff --git a/src/sync/serialize.ts b/src/sync/serialize.ts index a793abaf..b0f9ac92 100644 --- a/src/sync/serialize.ts +++ b/src/sync/serialize.ts @@ -13,7 +13,7 @@ import { TsonTypeHandlerKey, TsonTypeTesterCustom, TsonTypeTesterPrimitive, -} from "../types.js"; +} from "./syncTypes.js"; type WalkFn = (value: unknown) => unknown; type WalkerFactory = (nonce: TsonNonce) => WalkFn; diff --git a/src/stringify.test.ts b/src/sync/stringify.test.ts similarity index 80% rename from src/stringify.test.ts rename to src/sync/stringify.test.ts index d14831bd..cc8735fe 100644 --- a/src/stringify.test.ts +++ b/src/sync/stringify.test.ts @@ -1,10 +1,12 @@ import { expect, test } from "vitest"; -import { tsonBigint } from "./handlers/tsonBigint.js"; -import { tsonMap } from "./handlers/tsonMap.js"; -import { tsonSet } from "./handlers/tsonSet.js"; -import { tsonUndefined } from "./handlers/tsonUndefined.js"; -import { createTson } from "./sync/createTson.js"; +import { + createTson, + tsonBigint, + tsonMap, + tsonSet, + tsonUndefined, +} from "../index.js"; test("lets have a look at the stringified output", () => { const t = createTson({ diff --git a/src/types.test.ts b/src/sync/syncTypes.test.ts similarity index 79% rename from src/types.test.ts rename to src/sync/syncTypes.test.ts index f6d57d1d..a8f38426 100644 --- a/src/types.test.ts +++ b/src/sync/syncTypes.test.ts @@ -1,8 +1,7 @@ import { expectTypeOf, test } from "vitest"; -import { tsonBigint } from "./handlers/tsonBigint.js"; -import { createTson } from "./sync/createTson.js"; -import "./types.js"; +import { createTson, tsonBigint } from "../index.js"; +import "./syncTypes.js"; test("types", () => { const t = createTson({ diff --git a/src/types.ts b/src/sync/syncTypes.ts similarity index 100% rename from src/types.ts rename to src/sync/syncTypes.ts