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

Commit

Permalink
Merge branch 'main' into knip
Browse files Browse the repository at this point in the history
  • Loading branch information
KATT authored Oct 7, 2023
2 parents 7311768 + c5faa90 commit 0cbc767
Show file tree
Hide file tree
Showing 40 changed files with 95 additions and 106 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ import {
createTson,
// Serialize `bigint`
tsonBigint,
// Serialize `Date`
tsonDate,
// Serialize `Map`s
tsonMap,
// **throws** when encountering Infinity or NaN
Expand Down
6 changes: 3 additions & 3 deletions src/async/asyncTypes.ts
Original file line number Diff line number Diff line change
@@ -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<TValue> = AsyncIterable<string> & {
[serialized]: TValue;
Expand Down
5 changes: 1 addition & 4 deletions src/async/deserializeAsync.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion src/async/deserializeAsync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
TsonNonce,
TsonSerialized,
TsonTransformerSerializeDeserialize,
} from "../types.js";
} from "../sync/syncTypes.js";
import {
TsonAsyncIndex,
TsonAsyncOptions,
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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 = <T>(result: () => T, wait = 1) => {
return new Promise<T>((resolve, reject) => {
Expand Down Expand Up @@ -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(`
Expand Down
Original file line number Diff line number Diff line change
@@ -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<unknown> {
return (
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/async/serializeAsync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
TsonTypeHandlerKey,
TsonTypeTesterCustom,
TsonTypeTesterPrimitive,
} from "../types.js";
} from "../sync/syncTypes.js";
import {
TsonAsyncIndex,
TsonAsyncOptions,
Expand Down
14 changes: 0 additions & 14 deletions src/handlers/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, never> = {
Expand Down
37 changes: 27 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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";
2 changes: 1 addition & 1 deletion src/internals/getNonce.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TsonNonce } from "../types.js";
import { TsonNonce } from "../sync/syncTypes.js";

const randomString = () => Math.random().toString(36).slice(2);

Expand Down
2 changes: 1 addition & 1 deletion src/internals/isTsonTuple.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/sync/createTson.ts
Original file line number Diff line number Diff line change
@@ -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),
Expand Down
2 changes: 1 addition & 1 deletion src/sync/deserialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
TsonParseFn,
TsonSerialized,
TsonTransformerSerializeDeserialize,
} from "../types.js";
} from "./syncTypes.js";

type WalkFn = (value: unknown) => unknown;
type WalkerFactory = (nonce: TsonNonce) => WalkFn;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
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({
types: [tsonMap, tsonSet, tsonBigint],
});

{
// bigint
// bigint`
const expected = 1n;

const stringified = t.stringify(expected);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TsonType } from "../types.js";
import { TsonType } from "../syncTypes.js";

export const tsonBigint: TsonType<bigint, string> = {
deserialize: (v) => BigInt(v),
Expand Down
Original file line number Diff line number Diff line change
@@ -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({
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/tsonDate.ts → src/sync/handlers/tsonDate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TsonType } from "../types.js";
import { TsonType } from "../syncTypes.js";

export const tsonDate: TsonType<Date, string> = {
deserialize: (value) => new Date(value),
Expand Down
Original file line number Diff line number Diff line change
@@ -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({
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/tsonMap.ts → src/sync/handlers/tsonMap.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TsonType } from "../types.js";
import { TsonType } from "../syncTypes.js";

export const tsonMap: TsonType<Map<unknown, unknown>, [unknown, unknown][]> = {
deserialize: (v) => new Map(v),
Expand Down
Original file line number Diff line number Diff line change
@@ -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({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TsonType } from "../types.js";
import { TsonType } from "../syncTypes.js";

/**
* Prevents `NaN` and `Infinity` from being serialized
Expand Down
Original file line number Diff line number Diff line change
@@ -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({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TsonType } from "../types.js";
import { TsonType } from "../syncTypes.js";

export const tsonRegExp: TsonType<RegExp, string> = {
deserialize: (str) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -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({
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/tsonSet.ts → src/sync/handlers/tsonSet.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TsonType } from "../types.js";
import { TsonType } from "../syncTypes.js";

export const tsonSet: TsonType<Set<unknown>, unknown[]> = {
deserialize: (v) => new Set(v),
Expand Down
Original file line number Diff line number Diff line change
@@ -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");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TsonType } from "../types.js";
import { TsonType } from "../syncTypes.js";

export const tsonSymbol = <T extends symbol>(
symbol: T,
Expand Down
Original file line number Diff line number Diff line change
@@ -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({
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/tsonURL.ts → src/sync/handlers/tsonURL.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TsonType } from "../types.js";
import { TsonType } from "../syncTypes.js";

export const tsonURL: TsonType<URL, string> = {
deserialize: (value) => new URL(value),
Expand Down
Original file line number Diff line number Diff line change
@@ -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({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TsonType } from "../types.js";
import { TsonType } from "../syncTypes.js";

export const tsonUndefined: TsonType<undefined, 0> = {
deserialize: () => undefined,
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
/**
Expand Down
2 changes: 1 addition & 1 deletion src/sync/serialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
TsonTypeHandlerKey,
TsonTypeTesterCustom,
TsonTypeTesterPrimitive,
} from "../types.js";
} from "./syncTypes.js";

type WalkFn = (value: unknown) => unknown;
type WalkerFactory = (nonce: TsonNonce) => WalkFn;
Expand Down
Loading

0 comments on commit 0cbc767

Please sign in to comment.