From 89cc98661ae5a3fa0559807f3d5b7c903c99f61a Mon Sep 17 00:00:00 2001 From: m1212e <14091540+m1212e@users.noreply.github.com> Date: Sun, 6 Jul 2025 19:38:04 +0200 Subject: [PATCH 1/6] =?UTF-8?q?=F0=9F=8F=97=EF=B8=8F=20build:=20add=20file?= =?UTF-8?q?=20specific=20exports=20to=20packagejson?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- task/build/package/create-package-json.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/task/build/package/create-package-json.ts b/task/build/package/create-package-json.ts index d042978..4a329a8 100644 --- a/task/build/package/create-package-json.ts +++ b/task/build/package/create-package-json.ts @@ -73,6 +73,24 @@ function resolveExports(submodules: string[]) { "types": "./build/esm/index.d.mts", "default": "./build/esm/index.mjs", } + }, + "./typebox/*": { + "require": "./build/cjs/typebox/*", + "import": "./build/esm/typebox/*", + "node": "./build/cjs/typebox/*", + "default": "./build/cjs/typebox/*" + }, + "./zod/*": { + "require": "./build/cjs/zod/*", + "import": "./build/esm/zod/*", + "node": "./build/cjs/zod/*", + "default": "./build/cjs/zod/*" + }, + "./valibot/*": { + "require": "./build/cjs/valibot/*", + "import": "./build/esm/valibot/*", + "node": "./build/cjs/valibot/*", + "default": "./build/cjs/valibot/*" } }) return { exports } From f61f2924d81f0b3793a85c2a16a45b3bb233c927 Mon Sep 17 00:00:00 2001 From: m1212e <14091540+m1212e@users.noreply.github.com> Date: Sun, 6 Jul 2025 20:23:28 +0200 Subject: [PATCH 2/6] =?UTF-8?q?=F0=9F=8F=97=EF=B8=8F=20build:=20add=20guar?= =?UTF-8?q?d=20to=20package=20exports?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- task/build/package/create-package-json.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/task/build/package/create-package-json.ts b/task/build/package/create-package-json.ts index 4a329a8..9c29266 100644 --- a/task/build/package/create-package-json.ts +++ b/task/build/package/create-package-json.ts @@ -74,6 +74,12 @@ function resolveExports(submodules: string[]) { "default": "./build/esm/index.mjs", } }, + "./guard": { + "require": "./build/cjs/guard.js", + "import": "./build/esm/guard.mjs", + "node": "./build/cjs/guard.js", + "default": "./build/cjs/guard.js" + }, "./typebox/*": { "require": "./build/cjs/typebox/*", "import": "./build/esm/typebox/*", From f55533fbb7bec59474610aaca5a3ae78cd4bcd29 Mon Sep 17 00:00:00 2001 From: m1212e <14091540+m1212e@users.noreply.github.com> Date: Sat, 19 Jul 2025 01:54:12 +0200 Subject: [PATCH 3/6] =?UTF-8?q?=F0=9F=9A=A7=20wip:=20use=20proper=20submod?= =?UTF-8?q?ules=20in=20build=20flow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/compile/compile.ts | 36 +- src/{guard.ts => guard/index.ts} | 0 src/index.ts | 46 +- src/syntax/syntax.ts | 38 +- src/typebox/{typebox.ts => index.ts} | 47 +- src/typebox/typebox-from-valibot.ts | 823 ++++++++++++++-------- src/valibot/{valibot.ts => index.ts} | 49 +- src/zod/{zod.ts => index.ts} | 36 +- task/build/package/build.ts | 2 +- task/build/package/create-package-json.ts | 24 - 10 files changed, 701 insertions(+), 400 deletions(-) rename src/{guard.ts => guard/index.ts} (100%) rename src/typebox/{typebox.ts => index.ts} (80%) rename src/valibot/{valibot.ts => index.ts} (73%) rename src/zod/{zod.ts => index.ts} (76%) diff --git a/src/compile/compile.ts b/src/compile/compile.ts index f6a1fc3..b8a0267 100644 --- a/src/compile/compile.ts +++ b/src/compile/compile.ts @@ -26,16 +26,16 @@ THE SOFTWARE. ---------------------------------------------------------------------------*/ -import { TypeCompiler, TypeCheck } from '@sinclair/typebox/compiler' -import { Value } from '@sinclair/typebox/value' -import { IsEvalSupported } from './environment' -import { Validator } from './validator' +import { TypeCompiler, TypeCheck } from "@sinclair/typebox/compiler"; +import { Value } from "@sinclair/typebox/value"; +import { IsEvalSupported } from "./environment"; +import { Validator } from "./validator"; -import { type TTypeBox, TypeBox } from '../typebox/typebox' -import { type TSyntaxOptions } from '../options' -import { type TParameter } from '../typebox/typebox' -import * as t from '@sinclair/typebox' -import * as g from '../guard' +import { type TTypeBox, TypeBox } from "../typebox"; +import { type TSyntaxOptions } from "../options"; +import { type TParameter } from "../typebox"; +import * as t from "@sinclair/typebox"; +import * as g from "../guard"; // ------------------------------------------------------------------ // CompileDynamic @@ -48,7 +48,7 @@ function CompileDynamic(type: Type, references: t.TSchem // ResolveTypeCheck // ------------------------------------------------------------------ function ResolveTypeCheck(type: Type): TypeCheck { - return IsEvalSupported() ? TypeCompiler.Compile(type) : CompileDynamic(type) + return IsEvalSupported() ? TypeCompiler.Compile(type) : CompileDynamic(type); } // ------------------------------------------------------------------ // Compile @@ -61,11 +61,21 @@ type TCompile = Result /** Compiles a type for high performance validation */ -export function Compile(parameter: Parameter, type: Type, options?: TSyntaxOptions): TCompile +export function Compile( + parameter: Parameter, + type: Type, + options?: TSyntaxOptions +): TCompile; /** Compiles a type for high performance validation */ -export function Compile(type: Type, options?: TSyntaxOptions): TCompile<{}, Type> +export function Compile( + type: Type, + options?: TSyntaxOptions +): TCompile<{}, Type>; /** Compiles a type for high performance validation */ -export function Compile(type: Type, options?: TSyntaxOptions): TCompile<{}, Type> +export function Compile( + type: Type, + options?: TSyntaxOptions +): TCompile<{}, Type>; /** Compiles a type for high performance validation */ // prettier-ignore export function Compile(...args: any[]): never { diff --git a/src/guard.ts b/src/guard/index.ts similarity index 100% rename from src/guard.ts rename to src/guard/index.ts diff --git a/src/index.ts b/src/index.ts index 333972c..fd63f27 100644 --- a/src/index.ts +++ b/src/index.ts @@ -26,50 +26,50 @@ THE SOFTWARE. ---------------------------------------------------------------------------*/ -export { type TSyntaxOptions } from './options' +export { type TSyntaxOptions } from "./options"; // ------------------------------------------------------------------ // Static // ------------------------------------------------------------------ -export { type Static } from './static' +export { type Static } from "./static"; // ------------------------------------------------------------------ // Compile // ------------------------------------------------------------------ -export * from './compile/compile' +export * from "./compile/compile"; // ------------------------------------------------------------------ // Syntax // ------------------------------------------------------------------ -export * from './syntax/syntax-from-syntax' -export * from './syntax/syntax-from-typebox' -export * from './syntax/syntax-from-valibot' -export * from './syntax/syntax-from-zod' -export { type TSyntax, Syntax } from './syntax/syntax' +export * from "./syntax/syntax-from-syntax"; +export * from "./syntax/syntax-from-typebox"; +export * from "./syntax/syntax-from-valibot"; +export * from "./syntax/syntax-from-zod"; +export { type TSyntax, Syntax } from "./syntax/syntax"; // ------------------------------------------------------------------ // TypeBox // ------------------------------------------------------------------ -export * from './typebox/typebox-from-syntax' -export * from './typebox/typebox-from-typebox' -export * from './typebox/typebox-from-valibot' -export * from './typebox/typebox-from-zod' -export { type TTypeBox, TypeBox } from './typebox/typebox' +export * from "./typebox/typebox-from-syntax"; +export * from "./typebox/typebox-from-typebox"; +export * from "./typebox/typebox-from-valibot"; +export * from "./typebox/typebox-from-zod"; +export { type TTypeBox, TypeBox } from "./typebox"; // ------------------------------------------------------------------ // Valibot // ------------------------------------------------------------------ -export * from './valibot/valibot-from-syntax' -export * from './valibot/valibot-from-typebox' -export * from './valibot/valibot-from-valibot' -export * from './valibot/valibot-from-zod' -export { type TValibot, Valibot } from './valibot/valibot' +export * from "./valibot/valibot-from-syntax"; +export * from "./valibot/valibot-from-typebox"; +export * from "./valibot/valibot-from-valibot"; +export * from "./valibot/valibot-from-zod"; +export { type TValibot, Valibot } from "./valibot"; // ------------------------------------------------------------------ // Zod // ------------------------------------------------------------------ -export * from './zod/zod-from-syntax' -export * from './zod/zod-from-typebox' -export * from './zod/zod-from-valibot' -export * from './zod/zod-from-zod' -export { type TZod, Zod } from './zod/zod' +export * from "./zod/zod-from-syntax"; +export * from "./zod/zod-from-typebox"; +export * from "./zod/zod-from-valibot"; +export * from "./zod/zod-from-zod"; +export { type TZod, Zod } from "./zod"; diff --git a/src/syntax/syntax.ts b/src/syntax/syntax.ts index 4d38501..10a7e1e 100644 --- a/src/syntax/syntax.ts +++ b/src/syntax/syntax.ts @@ -26,15 +26,21 @@ THE SOFTWARE. ---------------------------------------------------------------------------*/ -import { type TSyntaxFromSyntax, SyntaxFromSyntax } from './syntax-from-syntax' -import { type TSyntaxFromTypeBox, SyntaxFromTypeBox } from './syntax-from-typebox' -import { type TSyntaxFromValibot, SyntaxFromValibot } from './syntax-from-valibot' -import { type TSyntaxFromZod, SyntaxFromZod } from './syntax-from-zod' -import { type TSyntaxOptions } from '../options' -import { type TParameter } from '../typebox/typebox' +import { type TSyntaxFromSyntax, SyntaxFromSyntax } from "./syntax-from-syntax"; +import { + type TSyntaxFromTypeBox, + SyntaxFromTypeBox, +} from "./syntax-from-typebox"; +import { + type TSyntaxFromValibot, + SyntaxFromValibot, +} from "./syntax-from-valibot"; +import { type TSyntaxFromZod, SyntaxFromZod } from "./syntax-from-zod"; +import { type TSyntaxOptions } from "../options"; +import { type TParameter } from "../typebox"; -import * as g from '../guard' -import * as z from 'zod' +import * as g from "../guard"; +import * as z from "zod"; // ------------------------------------------------------------------ // Zod @@ -50,11 +56,21 @@ export type TSyntax<_Parameter extends TParameter, Type extends object | string, )> = Result /** Creates Syntax by mapping from a remote Type */ -export function Syntax(parameter: Parameter, type: Type, options?: TSyntaxOptions): TSyntax +export function Syntax( + parameter: Parameter, + type: Type, + options?: TSyntaxOptions +): TSyntax; /** Creates Syntax by mapping from a remote Type */ -export function Syntax(type: Type, options?: TSyntaxOptions): TSyntax<{}, Type> +export function Syntax( + type: Type, + options?: TSyntaxOptions +): TSyntax<{}, Type>; /** Creates Syntax by mapping from a remote Type */ -export function Syntax(type: Type, options?: TSyntaxOptions): TSyntax<{}, Type> +export function Syntax( + type: Type, + options?: TSyntaxOptions +): TSyntax<{}, Type>; /** Creates Syntax by mapping from a remote Type */ // prettier-ignore export function Syntax(...args: any[]): never { diff --git a/src/typebox/typebox.ts b/src/typebox/index.ts similarity index 80% rename from src/typebox/typebox.ts rename to src/typebox/index.ts index 9cbaaf4..ffaddf3 100644 --- a/src/typebox/typebox.ts +++ b/src/typebox/index.ts @@ -26,14 +26,23 @@ THE SOFTWARE. ---------------------------------------------------------------------------*/ -import { type TTypeBoxFromSyntax, TypeBoxFromSyntax } from './typebox-from-syntax' -import { type TTypeBoxFromTypeBox, TypeBoxFromTypeBox } from './typebox-from-typebox' -import { type TTypeBoxFromValibot, TypeBoxFromValibot } from './typebox-from-valibot' -import { type TTypeBoxFromZod, TypeBoxFromZod } from './typebox-from-zod' -import { type TSyntaxOptions } from '../options' +import { + type TTypeBoxFromSyntax, + TypeBoxFromSyntax, +} from "./typebox-from-syntax"; +import { + type TTypeBoxFromTypeBox, + TypeBoxFromTypeBox, +} from "./typebox-from-typebox"; +import { + type TTypeBoxFromValibot, + TypeBoxFromValibot, +} from "./typebox-from-valibot"; +import { type TTypeBoxFromZod, TypeBoxFromZod } from "./typebox-from-zod"; +import { type TSyntaxOptions } from "../options"; -import * as g from '../guard' -import * as t from '@sinclair/typebox' +import * as g from "../guard"; +import * as t from "@sinclair/typebox"; // ------------------------------------------------------------------------------ // @@ -44,7 +53,7 @@ import * as t from '@sinclair/typebox' // the remote types such that they can be mapped prior to syntax parsing. // // ------------------------------------------------------------------------------- -export type TParameter = Record +export type TParameter = Record; // ------------------------------------------------------------------ // ContextFromParameter @@ -75,9 +84,16 @@ export type TTypeBox = Result /** Creates a TypeBox type by mapping from a remote Type */ -export function TypeBox(parameter: Parameter, type: Type, options?: TSyntaxOptions): TTypeBox +export function TypeBox( + parameter: Parameter, + type: Type, + options?: TSyntaxOptions +): TTypeBox; /** Creates a TypeBox type by mapping from a remote Type */ -export function TypeBox(type: Type, options?: TSyntaxOptions): TTypeBox<{}, Type> +export function TypeBox( + type: Type, + options?: TSyntaxOptions +): TTypeBox<{}, Type>; /** Creates a TypeBox type by mapping from a remote Type */ // prettier-ignore export function TypeBox(...args: any[]): never { @@ -92,9 +108,16 @@ export function TypeBox(...args: any[]): never { } /** Creates a TypeBox type from Syntax or another Type */ -export function Type(parameter: Parameter, type: Type, options?: TSyntaxOptions): TTypeBox +export function Type( + parameter: Parameter, + type: Type, + options?: TSyntaxOptions +): TTypeBox; /** Creates a TypeBox type from Syntax or another Type */ -export function Type(type: Type, options?: TSyntaxOptions): TTypeBox<{}, Type> +export function Type( + type: Type, + options?: TSyntaxOptions +): TTypeBox<{}, Type>; /** Creates a TypeBox type from Syntax or another Type */ // prettier-ignore export function Type(...args: any[]): never { diff --git a/src/typebox/typebox-from-valibot.ts b/src/typebox/typebox-from-valibot.ts index 31a1da9..80383e8 100644 --- a/src/typebox/typebox-from-valibot.ts +++ b/src/typebox/typebox-from-valibot.ts @@ -26,15 +26,21 @@ THE SOFTWARE. ---------------------------------------------------------------------------*/ -import * as t from '@sinclair/typebox' -import * as v from 'valibot' -import * as Guard from '../guard' +import * as t from "@sinclair/typebox"; +import * as v from "valibot"; +import * as Guard from "../guard"; // ------------------------------------------------------------------ // Options // ------------------------------------------------------------------ -function IsSchemaWithPipe(type: BaseSchema): type is v.SchemaWithPipe<[BaseSchema, ...BaseValidation[]]> { - return t.ValueGuard.IsObject(type) && t.ValueGuard.HasPropertyKey(type, 'pipe') && t.ValueGuard.IsArray(type.pipe) +function IsSchemaWithPipe( + type: BaseSchema +): type is v.SchemaWithPipe<[BaseSchema, ...BaseValidation[]]> { + return ( + t.ValueGuard.IsObject(type) && + t.ValueGuard.HasPropertyKey(type, "pipe") && + t.ValueGuard.IsArray(type.pipe) + ); } // prettier-ignore function Options(type: BaseSchema) { @@ -157,181 +163,298 @@ function Options(type: BaseSchema) { // ------------------------------------------------------------------ // Formats // ------------------------------------------------------------------ -t.FormatRegistry.Set('base64', (value) => v.safeParse(v.pipe(v.string(), v.base64()), value).success) -t.FormatRegistry.Set('bic', (value) => v.safeParse(v.pipe(v.string(), v.bic()), value).success) -t.FormatRegistry.Set('credit_card', (value) => v.safeParse(v.pipe(v.string(), v.creditCard()), value).success) -t.FormatRegistry.Set('cuid2', (value) => v.safeParse(v.pipe(v.string(), v.cuid2()), value).success) -t.FormatRegistry.Set('decimal', (value) => v.safeParse(v.pipe(v.string(), v.decimal()), value).success) -t.FormatRegistry.Set('digits', (value) => v.safeParse(v.pipe(v.string(), v.digits()), value).success) -t.FormatRegistry.Set('email', (value) => v.safeParse(v.pipe(v.string(), v.email()), value).success) -t.FormatRegistry.Set('emoji', (value) => v.safeParse(v.pipe(v.string(), v.emoji()), value).success) -t.FormatRegistry.Set('ip', (value) => v.safeParse(v.pipe(v.string(), v.ip()), value).success) -t.FormatRegistry.Set('ipv4', (value) => v.safeParse(v.pipe(v.string(), v.ipv4()), value).success) -t.FormatRegistry.Set('ipv6', (value) => v.safeParse(v.pipe(v.string(), v.ipv6()), value).success) -t.FormatRegistry.Set('iso_date', (value) => v.safeParse(v.pipe(v.string(), v.isoDate()), value).success) -t.FormatRegistry.Set('iso_date_time', (value) => v.safeParse(v.pipe(v.string(), v.isoDateTime()), value).success) -t.FormatRegistry.Set('iso_time', (value) => v.safeParse(v.pipe(v.string(), v.isoTime()), value).success) -t.FormatRegistry.Set('iso_time_second', (value) => v.safeParse(v.pipe(v.string(), v.isoTimeSecond()), value).success) -t.FormatRegistry.Set('iso_timestamp', (value) => v.safeParse(v.pipe(v.string(), v.isoTimestamp()), value).success) -t.FormatRegistry.Set('iso_week', (value) => v.safeParse(v.pipe(v.string(), v.isoWeek()), value).success) -t.FormatRegistry.Set('mac', (value) => v.safeParse(v.pipe(v.string(), v.mac()), value).success) -t.FormatRegistry.Set('mac48', (value) => v.safeParse(v.pipe(v.string(), v.mac48()), value).success) -t.FormatRegistry.Set('mac64', (value) => v.safeParse(v.pipe(v.string(), v.mac64()), value).success) -t.FormatRegistry.Set('nanoid', (value) => v.safeParse(v.pipe(v.string(), v.nanoid()), value).success) -t.FormatRegistry.Set('octal', (value) => v.safeParse(v.pipe(v.string(), v.octal()), value).success) -t.FormatRegistry.Set('ulid', (value) => v.safeParse(v.pipe(v.string(), v.ulid()), value).success) -t.FormatRegistry.Set('url', (value) => v.safeParse(v.pipe(v.string(), v.url()), value).success) -t.FormatRegistry.Set('uuid', (value) => v.safeParse(v.pipe(v.string(), v.uuid()), value).success) +t.FormatRegistry.Set( + "base64", + (value) => v.safeParse(v.pipe(v.string(), v.base64()), value).success +); +t.FormatRegistry.Set( + "bic", + (value) => v.safeParse(v.pipe(v.string(), v.bic()), value).success +); +t.FormatRegistry.Set( + "credit_card", + (value) => v.safeParse(v.pipe(v.string(), v.creditCard()), value).success +); +t.FormatRegistry.Set( + "cuid2", + (value) => v.safeParse(v.pipe(v.string(), v.cuid2()), value).success +); +t.FormatRegistry.Set( + "decimal", + (value) => v.safeParse(v.pipe(v.string(), v.decimal()), value).success +); +t.FormatRegistry.Set( + "digits", + (value) => v.safeParse(v.pipe(v.string(), v.digits()), value).success +); +t.FormatRegistry.Set( + "email", + (value) => v.safeParse(v.pipe(v.string(), v.email()), value).success +); +t.FormatRegistry.Set( + "emoji", + (value) => v.safeParse(v.pipe(v.string(), v.emoji()), value).success +); +t.FormatRegistry.Set( + "ip", + (value) => v.safeParse(v.pipe(v.string(), v.ip()), value).success +); +t.FormatRegistry.Set( + "ipv4", + (value) => v.safeParse(v.pipe(v.string(), v.ipv4()), value).success +); +t.FormatRegistry.Set( + "ipv6", + (value) => v.safeParse(v.pipe(v.string(), v.ipv6()), value).success +); +t.FormatRegistry.Set( + "iso_date", + (value) => v.safeParse(v.pipe(v.string(), v.isoDate()), value).success +); +t.FormatRegistry.Set( + "iso_date_time", + (value) => v.safeParse(v.pipe(v.string(), v.isoDateTime()), value).success +); +t.FormatRegistry.Set( + "iso_time", + (value) => v.safeParse(v.pipe(v.string(), v.isoTime()), value).success +); +t.FormatRegistry.Set( + "iso_time_second", + (value) => v.safeParse(v.pipe(v.string(), v.isoTimeSecond()), value).success +); +t.FormatRegistry.Set( + "iso_timestamp", + (value) => v.safeParse(v.pipe(v.string(), v.isoTimestamp()), value).success +); +t.FormatRegistry.Set( + "iso_week", + (value) => v.safeParse(v.pipe(v.string(), v.isoWeek()), value).success +); +t.FormatRegistry.Set( + "mac", + (value) => v.safeParse(v.pipe(v.string(), v.mac()), value).success +); +t.FormatRegistry.Set( + "mac48", + (value) => v.safeParse(v.pipe(v.string(), v.mac48()), value).success +); +t.FormatRegistry.Set( + "mac64", + (value) => v.safeParse(v.pipe(v.string(), v.mac64()), value).success +); +t.FormatRegistry.Set( + "nanoid", + (value) => v.safeParse(v.pipe(v.string(), v.nanoid()), value).success +); +t.FormatRegistry.Set( + "octal", + (value) => v.safeParse(v.pipe(v.string(), v.octal()), value).success +); +t.FormatRegistry.Set( + "ulid", + (value) => v.safeParse(v.pipe(v.string(), v.ulid()), value).success +); +t.FormatRegistry.Set( + "url", + (value) => v.safeParse(v.pipe(v.string(), v.url()), value).success +); +t.FormatRegistry.Set( + "uuid", + (value) => v.safeParse(v.pipe(v.string(), v.uuid()), value).success +); // ------------------------------------------------------------------ // Schema // ------------------------------------------------------------------ -type BaseValidation = v.BaseValidation> -type BaseSchema = v.BaseSchema> -type BaseRecordKey = v.BaseSchema> +type BaseValidation = v.BaseValidation>; +type BaseSchema = v.BaseSchema>; +type BaseRecordKey = v.BaseSchema< + string, + string | number | symbol, + v.BaseIssue +>; // ------------------------------------------------------------------ // Any // ------------------------------------------------------------------ -type TFromAny<_Type extends v.AnySchema> = t.Ensure +type TFromAny<_Type extends v.AnySchema> = t.Ensure; function FromAny(type: BaseSchema): t.TSchema { - return t.Any(Options(type)) + return t.Any(Options(type)); } // ------------------------------------------------------------------ // Array // ------------------------------------------------------------------ -type TFromArray = t.Ensure>> +type TFromArray = t.Ensure>>; function FromArray(type: BaseSchema): t.TSchema { - return t.Array(FromType((type as v.ArraySchema).item), Options(type)) + return t.Array( + FromType((type as v.ArraySchema).item), + Options(type) + ); } // ------------------------------------------------------------------ // BigInt // ------------------------------------------------------------------ -type TFromBigInt<_Type extends v.BigintSchema> = t.Ensure +type TFromBigInt<_Type extends v.BigintSchema> = t.Ensure; function FromBigInt(type: BaseSchema): t.TSchema { - return t.BigInt(Options(type)) + return t.BigInt(Options(type)); } // ------------------------------------------------------------------ // Blob // ------------------------------------------------------------------ -t.TypeRegistry.Set('ValibotBlob', (schema, value) => { - return v.safeParse(schema.schema, value).success -}) -interface TBlob = v.BlobSchema> extends t.TSchema { - [t.Kind]: 'ValibotBlob' - static: v.InferOutput - type: Type +t.TypeRegistry.Set("ValibotBlob", (schema, value) => { + return v.safeParse(schema.schema, value).success; +}); +interface TBlob = v.BlobSchema> + extends t.TSchema { + [t.Kind]: "ValibotBlob"; + static: v.InferOutput; + type: Type; } function _Blob(type: v.BlobSchema, options?: t.SchemaOptions): TBlob { - return t.CreateType({ [t.Kind]: 'ValibotBlob', type }, options) as never + return t.CreateType({ [t.Kind]: "ValibotBlob", type }, options) as never; } -type TFromBlob> = t.Ensure> +type TFromBlob> = t.Ensure>; function FromBlob(type: BaseSchema): t.TSchema { - return _Blob(type as v.BlobSchema, Options(type)) + return _Blob(type as v.BlobSchema, Options(type)); } // ------------------------------------------------------------------ // Boolean // ------------------------------------------------------------------ -type TFromBoolean<_Type extends v.BooleanSchema> = t.TBoolean +type TFromBoolean<_Type extends v.BooleanSchema> = t.TBoolean; function FromBoolean(type: BaseSchema): t.TSchema { - return t.Boolean(Options(type)) + return t.Boolean(Options(type)); } // ------------------------------------------------------------------ // Custom // ------------------------------------------------------------------ -t.TypeRegistry.Set('ValibotCustom', (schema, value) => v.safeParse(schema.schema, value).success) -interface TCustom = v.CustomSchema> extends t.TSchema { - [t.Kind]: 'ValibotCustom' - static: v.InferOutput - type: Type -} -function Custom>(type: Type, options?: t.SchemaOptions): TCustom { - return t.CreateType({ [t.Kind]: 'ValibotCustom', type }, options) as never -} -type TFromCustom> = t.Ensure> +t.TypeRegistry.Set( + "ValibotCustom", + (schema, value) => v.safeParse(schema.schema, value).success +); +interface TCustom< + Type extends v.CustomSchema = v.CustomSchema, +> extends t.TSchema { + [t.Kind]: "ValibotCustom"; + static: v.InferOutput; + type: Type; +} +function Custom>( + type: Type, + options?: t.SchemaOptions +): TCustom { + return t.CreateType({ [t.Kind]: "ValibotCustom", type }, options) as never; +} +type TFromCustom> = t.Ensure< + TCustom +>; function FromCustom(type: BaseSchema): t.TSchema { - return Custom(type as v.CustomSchema, Options(type)) + return Custom(type as v.CustomSchema, Options(type)); } // ------------------------------------------------------------------ // Date // ------------------------------------------------------------------ -type TFromDate<_Type extends v.DateSchema> = t.TDate +type TFromDate<_Type extends v.DateSchema> = t.TDate; function FromDate(type: BaseSchema): t.TSchema { - return t.Date(Options(type)) + return t.Date(Options(type)); } // ------------------------------------------------------------------ // Enum // ------------------------------------------------------------------ -t.TypeRegistry.Set('ValibotEnum', (schema, value) => { - return v.safeParse(schema.type, value).success -}) -export interface TValibotEnum = v.EnumSchema> extends t.TSchema { - [t.Kind]: 'ValibotEnum' - static: v.InferOutput - type: Type -} -function ValibotEnum>(type: Type, options?: t.SchemaOptions): TValibotEnum { - return t.CreateType({ [t.Kind]: 'ValibotEnum', type }, options) as never +t.TypeRegistry.Set("ValibotEnum", (schema, value) => { + return v.safeParse(schema.type, value).success; +}); +export interface TValibotEnum< + Type extends v.EnumSchema = v.EnumSchema, +> extends t.TSchema { + [t.Kind]: "ValibotEnum"; + static: v.InferOutput; + type: Type; +} +function ValibotEnum>( + type: Type, + options?: t.SchemaOptions +): TValibotEnum { + return t.CreateType({ [t.Kind]: "ValibotEnum", type }, options) as never; } // prettier-ignore type TFromEnum, Result = TValibotEnum > = Result function FromEnum(type: Type): t.TSchema { - return ValibotEnum(type as never as v.EnumSchema, Options(type)) + return ValibotEnum(type as never as v.EnumSchema, Options(type)); } // ------------------------------------------------------------------ // File // ------------------------------------------------------------------ -t.TypeRegistry.Set('ValibotFile', (schema, value) => { - return v.safeParse(schema.schema, value).success -}) -export interface TValibotFile = v.FileSchema> extends t.TSchema { - [t.Kind]: 'ValibotFile' - static: v.InferOutput - type: Type -} -function _File(type: v.FileSchema, options?: t.SchemaOptions): TValibotFile { - return t.CreateType({ [t.Kind]: 'ValibotFile', type }, options) as never -} -type TFromFile> = t.Ensure> +t.TypeRegistry.Set("ValibotFile", (schema, value) => { + return v.safeParse(schema.schema, value).success; +}); +export interface TValibotFile< + Type extends v.FileSchema = v.FileSchema, +> extends t.TSchema { + [t.Kind]: "ValibotFile"; + static: v.InferOutput; + type: Type; +} +function _File( + type: v.FileSchema, + options?: t.SchemaOptions +): TValibotFile { + return t.CreateType({ [t.Kind]: "ValibotFile", type }, options) as never; +} +type TFromFile> = t.Ensure>; function FromFile(type: BaseSchema): t.TSchema { - return _File(type as v.FileSchema, Options(type)) + return _File(type as v.FileSchema, Options(type)); } // ------------------------------------------------------------------ // Function // ------------------------------------------------------------------ -t.TypeRegistry.Set('ValibotFunction', (schema, value) => { - return v.safeParse(schema.schema, value).success -}) -export interface TValibotFunction = v.FunctionSchema> extends t.TSchema { - [t.Kind]: 'ValibotFunction' - static: v.InferOutput - type: Type -} -function _Function>(type: Type, options?: t.SchemaOptions): TValibotFunction { - return t.CreateType({ [t.Kind]: 'ValibotFunction', type }, options) as never -} -type TFromFunction> = t.Ensure> +t.TypeRegistry.Set("ValibotFunction", (schema, value) => { + return v.safeParse(schema.schema, value).success; +}); +export interface TValibotFunction< + Type extends v.FunctionSchema = v.FunctionSchema, +> extends t.TSchema { + [t.Kind]: "ValibotFunction"; + static: v.InferOutput; + type: Type; +} +function _Function>( + type: Type, + options?: t.SchemaOptions +): TValibotFunction { + return t.CreateType({ [t.Kind]: "ValibotFunction", type }, options) as never; +} +type TFromFunction> = t.Ensure< + TValibotFunction +>; function FromFunction(type: BaseSchema): t.TSchema { - return _Function(type as v.FunctionSchema, Options(type)) + return _Function(type as v.FunctionSchema, Options(type)); } // ------------------------------------------------------------------ // Instance // ------------------------------------------------------------------ -t.TypeRegistry.Set('ValibotInstance', (schema, value) => { - return v.safeParse(schema.schema, value).success -}) -export interface TValibotInstance = v.InstanceSchema> extends t.TSchema { - [t.Kind]: 'ValibotInstance' - static: v.InferOutput - type: Type -} -function Instance>(type: Type, options?: t.SchemaOptions): TValibotInstance { - return t.CreateType({ [t.Kind]: 'ValibotInstance', type }, options) as never -} -type TFromInstance> = t.Ensure> +t.TypeRegistry.Set("ValibotInstance", (schema, value) => { + return v.safeParse(schema.schema, value).success; +}); +export interface TValibotInstance< + Type extends v.InstanceSchema = v.InstanceSchema, +> extends t.TSchema { + [t.Kind]: "ValibotInstance"; + static: v.InferOutput; + type: Type; +} +function Instance>( + type: Type, + options?: t.SchemaOptions +): TValibotInstance { + return t.CreateType({ [t.Kind]: "ValibotInstance", type }, options) as never; +} +type TFromInstance> = t.Ensure< + TValibotInstance +>; function FromInstance(type: BaseSchema): t.TSchema { - return Instance(type as v.InstanceSchema, Options(type)) + return Instance(type as v.InstanceSchema, Options(type)); } // ------------------------------------------------------------------ // Intersect @@ -343,201 +466,258 @@ type TFromIntersect : t.TIntersect ) function FromIntersect(type: BaseSchema): t.TSchema { - const intersect = type as v.IntersectSchema + const intersect = type as v.IntersectSchema; return t.Intersect( intersect.options.map((option) => FromType(option)), - Options(type), - ) + Options(type) + ); } // ------------------------------------------------------------------ // Literal // ------------------------------------------------------------------ -type TFromLiteral = t.Ensure> +type TFromLiteral = t.Ensure>; function FromLiteral(type: BaseSchema): t.TSchema { - const literal = type as v.LiteralSchema - return t.Literal(literal.literal, Options(type)) + const literal = type as v.LiteralSchema; + return t.Literal(literal.literal, Options(type)); } // ------------------------------------------------------------------ // LooseObject // ------------------------------------------------------------------ type TFromLooseObject = t.Ensure< t.TObject<{ - -readonly [Key in keyof Properties]: TFromType + -readonly [Key in keyof Properties]: TFromType; }> -> +>; function FromLooseObject(type: BaseSchema): t.TSchema { - const object = type as v.LooseObjectSchema - const keys = globalThis.Object.getOwnPropertyNames(object.entries) + const object = type as v.LooseObjectSchema; + const keys = globalThis.Object.getOwnPropertyNames(object.entries); return t.Object( keys.reduce((properties, key) => { - return { ...properties, [key]: FromType(object.entries[key]) } + return { ...properties, [key]: FromType(object.entries[key]) }; }, {} as t.TProperties), - Options(type), - ) + Options(type) + ); } // ------------------------------------------------------------------ // LooseTuple // ------------------------------------------------------------------ -t.TypeRegistry.Set('ValibotLooseTuple', (schema, value) => { - return v.safeParse(schema.schema, value).success -}) -export interface TValibotLooseTuple = v.LooseTupleSchema> extends t.TSchema { - [t.Kind]: 'ValibotLooseTuple' - static: v.InferOutput - type: Type -} -function LooseTuple>(type: Type, schema?: t.SchemaOptions): TValibotLooseTuple { - return t.CreateType({ [t.Kind]: 'ValibotLooseTuple', type }) as never -} -type TFromLooseTuple> = t.Ensure> +t.TypeRegistry.Set("ValibotLooseTuple", (schema, value) => { + return v.safeParse(schema.schema, value).success; +}); +export interface TValibotLooseTuple< + Type extends v.LooseTupleSchema = v.LooseTupleSchema< + BaseSchema[], + any + >, +> extends t.TSchema { + [t.Kind]: "ValibotLooseTuple"; + static: v.InferOutput; + type: Type; +} +function LooseTuple>( + type: Type, + schema?: t.SchemaOptions +): TValibotLooseTuple { + return t.CreateType({ [t.Kind]: "ValibotLooseTuple", type }) as never; +} +type TFromLooseTuple> = + t.Ensure>; function FromLooseTuple(type: BaseSchema): t.TSchema { - return LooseTuple(type as v.LooseTupleSchema, Options(type)) + return LooseTuple( + type as v.LooseTupleSchema, + Options(type) + ); } // ------------------------------------------------------------------ // Map // ------------------------------------------------------------------ -t.TypeRegistry.Set('ValibotMap', (schema, value) => { - return v.safeParse(schema.schema, value).success -}) -export interface TValibotMap = v.MapSchema> extends t.TSchema { - [t.Kind]: 'ValibotMap' - static: v.InferOutput - type: Type -} -function _Map>(type: Type, options?: t.SchemaOptions): TValibotMap { - return t.CreateType({ [t.Kind]: 'ValibotMap', type }) as never -} -type TFromMap> = t.Ensure> +t.TypeRegistry.Set("ValibotMap", (schema, value) => { + return v.safeParse(schema.schema, value).success; +}); +export interface TValibotMap< + Type extends v.MapSchema = v.MapSchema< + BaseSchema, + BaseSchema, + any + >, +> extends t.TSchema { + [t.Kind]: "ValibotMap"; + static: v.InferOutput; + type: Type; +} +function _Map>( + type: Type, + options?: t.SchemaOptions +): TValibotMap { + return t.CreateType({ [t.Kind]: "ValibotMap", type }) as never; +} +type TFromMap> = t.Ensure< + TValibotMap +>; function FromMap(type: BaseSchema): t.TSchema { - return _Map(type as v.MapSchema, Options(type)) + return _Map(type as v.MapSchema, Options(type)); } // ------------------------------------------------------------------ // NaN // ------------------------------------------------------------------ -t.TypeRegistry.Set('ValibotNaN', (schema, value) => { - return v.safeParse(schema.schema, value).success -}) -export interface TValibotNaN = v.NanSchema> extends t.TSchema { - [t.Kind]: 'ValibotNaN' - static: v.InferOutput - type: Type -} -function _NaN>(type: Type, options?: t.SchemaOptions): TValibotNaN { - return t.CreateType({ [t.Kind]: 'ValibotNaN', type }, options) as never -} -type TFromNaN> = t.Ensure> +t.TypeRegistry.Set("ValibotNaN", (schema, value) => { + return v.safeParse(schema.schema, value).success; +}); +export interface TValibotNaN = v.NanSchema> + extends t.TSchema { + [t.Kind]: "ValibotNaN"; + static: v.InferOutput; + type: Type; +} +function _NaN>( + type: Type, + options?: t.SchemaOptions +): TValibotNaN { + return t.CreateType({ [t.Kind]: "ValibotNaN", type }, options) as never; +} +type TFromNaN> = t.Ensure>; function FromNaN(type: BaseSchema): t.TSchema { - return _NaN(type as v.NanSchema, Options(type)) + return _NaN(type as v.NanSchema, Options(type)); } // ------------------------------------------------------------------ // Never // ------------------------------------------------------------------ -type TFromNever<_Type extends v.NeverSchema> = t.TNever +type TFromNever<_Type extends v.NeverSchema> = t.TNever; function FromNever(type: BaseSchema): t.TSchema { - return t.Never(Options(type)) + return t.Never(Options(type)); } // ------------------------------------------------------------------ // NonNullable // ------------------------------------------------------------------ -type TFromNonNullable = t.TExclude, t.TNull> +type TFromNonNullable = t.TExclude< + TFromType, + t.TNull +>; function FromNonNullable(type: BaseSchema): t.TSchema { - const non_nullable = type as v.NonNullableSchema - return t.Exclude(FromType(non_nullable.wrapped), t.Null(), Options(type)) + const non_nullable = type as v.NonNullableSchema; + return t.Exclude(FromType(non_nullable.wrapped), t.Null(), Options(type)); } // ------------------------------------------------------------------ // NonNullish // ------------------------------------------------------------------ -type TFromNonNullish = t.TExclude, t.TUnion<[t.TNull, t.TUndefined]>> +type TFromNonNullish = t.TExclude< + TFromType, + t.TUnion<[t.TNull, t.TUndefined]> +>; function FromNonNullish(type: BaseSchema): t.TSchema { - const non_nullish = type as v.NonNullishSchema - return t.Exclude(FromType(non_nullish.wrapped), t.Union([t.Null(), t.Undefined()]), Options(type)) + const non_nullish = type as v.NonNullishSchema; + return t.Exclude( + FromType(non_nullish.wrapped), + t.Union([t.Null(), t.Undefined()]), + Options(type) + ); } // ------------------------------------------------------------------ // NonOptional // ------------------------------------------------------------------ -type TFromNonOptional = TFromType> = t.TOptionalWithFlag +type TFromNonOptional< + Type extends BaseSchema, + Result extends TFromType = TFromType, +> = t.TOptionalWithFlag; function FromNonOptional(type: BaseSchema): t.TSchema { - const non_optional = type as v.NonOptionalSchema - return t.Optional(FromType(non_optional.wrapped), false) + const non_optional = type as v.NonOptionalSchema; + return t.Optional(FromType(non_optional.wrapped), false); } // ------------------------------------------------------------------ // Null // ------------------------------------------------------------------ -type TFromNull<_Type extends v.NullSchema> = t.TNull +type TFromNull<_Type extends v.NullSchema> = t.TNull; function FromNull(type: BaseSchema) { - return t.Null(Options(type)) + return t.Null(Options(type)); } // ------------------------------------------------------------------ // Nullable // ------------------------------------------------------------------ -type TFromNullable = t.TUnion<[TFromType, t.TNull]> +type TFromNullable = t.TUnion< + [TFromType, t.TNull] +>; function FromNullable(type: BaseSchema) { - const nullable = type as v.NullableSchema - return t.Union([t.Null(), FromType(nullable.wrapped)], Options(type)) + const nullable = type as v.NullableSchema; + return t.Union([t.Null(), FromType(nullable.wrapped)], Options(type)); } // ------------------------------------------------------------------ // Nullish // ------------------------------------------------------------------ -type TFromNullish = t.TUnion<[TFromType, t.TNull, t.TUndefined]> +type TFromNullish = t.TUnion< + [TFromType, t.TNull, t.TUndefined] +>; function FromNullish(type: BaseSchema) { - const nullish = type as v.NullishSchema - return t.Union([FromType(nullish.wrapped), t.Null(), t.Undefined()], Options(type)) + const nullish = type as v.NullishSchema; + return t.Union( + [FromType(nullish.wrapped), t.Null(), t.Undefined()], + Options(type) + ); } // ------------------------------------------------------------------ // Number // ------------------------------------------------------------------ -type TFromNumber<_Type extends v.NumberSchema> = t.TNumber +type TFromNumber<_Type extends v.NumberSchema> = t.TNumber; function FromNumber(type: BaseSchema): t.TSchema { - return t.Number(Options(type)) + return t.Number(Options(type)); } // ------------------------------------------------------------------ // Object // ------------------------------------------------------------------ type TFromObject = t.Ensure< t.TObject<{ - -readonly [Key in keyof Properties]: TFromType + -readonly [Key in keyof Properties]: TFromType; }> -> +>; function FromObject(type: BaseSchema): t.TSchema { - const object = type as v.ObjectSchema - const keys = globalThis.Object.getOwnPropertyNames(object.entries) + const object = type as v.ObjectSchema; + const keys = globalThis.Object.getOwnPropertyNames(object.entries); return t.Object( keys.reduce((properties, key) => { - return { ...properties, [key]: FromType(object.entries[key]) } + return { ...properties, [key]: FromType(object.entries[key]) }; }, {} as t.TProperties), - Options(type), - ) + Options(type) + ); } // ------------------------------------------------------------------ // ObjectWithRest // ------------------------------------------------------------------ -type TFromObjectWithRest = t.Ensure< +type TFromObjectWithRest< + Properties extends v.ObjectEntries, + _Rest extends BaseSchema, +> = t.Ensure< t.TObject<{ - -readonly [Key in keyof Properties]: TFromType + -readonly [Key in keyof Properties]: TFromType; }> -> +>; function FromObjectWithRest(type: BaseSchema): t.TSchema { - const object = type as v.ObjectWithRestSchema - const keys = globalThis.Object.getOwnPropertyNames(object.entries) + const object = type as v.ObjectWithRestSchema< + v.ObjectEntries, + BaseSchema, + any + >; + const keys = globalThis.Object.getOwnPropertyNames(object.entries); return t.Object( keys.reduce((properties, key) => { - return { ...properties, [key]: FromType(object.entries[key]) } + return { ...properties, [key]: FromType(object.entries[key]) }; }, {} as t.TProperties), - { ...Options(type), additionalProperties: FromType(object.rest) }, - ) + { ...Options(type), additionalProperties: FromType(object.rest) } + ); } // ------------------------------------------------------------------ // Optional // ------------------------------------------------------------------ -type TFromOptional = TFromType> = t.TOptionalWithFlag +type TFromOptional< + Type extends BaseSchema, + Result extends TFromType = TFromType, +> = t.TOptionalWithFlag; function FromOptional(type: BaseSchema): t.TSchema { - const optional = type as v.OptionalSchema - return t.Optional(FromType(optional.wrapped)) + const optional = type as v.OptionalSchema; + return t.Optional(FromType(optional.wrapped)); } // ------------------------------------------------------------------ // PickList // ------------------------------------------------------------------ -type PickListOption = string | number | bigint +type PickListOption = string | number | bigint; // prettier-ignore type TFromPickList = ( Options extends [infer Left extends PickListOption, ...infer Right extends PickListOption[]] @@ -549,73 +729,90 @@ type TFromPickList ) function FromPickList(type: BaseSchema): t.TSchema { - const picklist = type as v.PicklistSchema + const picklist = type as v.PicklistSchema; return t.Union( picklist.options.map((option) => t.Literal(option as t.TLiteralValue)), - Options(type), - ) + Options(type) + ); } // ------------------------------------------------------------------ // Promise // ------------------------------------------------------------------ -t.TypeRegistry.Set('ValibotPromise', (schema, value) => { - return v.safeParse(schema.schema, value).success -}) -export interface TValibotPromise = v.PromiseSchema> extends t.TSchema { - [t.Kind]: 'ValibotPromise' - static: v.InferOutput - type: Type -} -function _Promise>(type: Type, options?: t.SchemaOptions): TValibotPromise { - return t.CreateType({ [t.Kind]: 'ValibotPromise', type }, options) as never -} -type TFromPromise> = t.Ensure> +t.TypeRegistry.Set("ValibotPromise", (schema, value) => { + return v.safeParse(schema.schema, value).success; +}); +export interface TValibotPromise< + Type extends v.PromiseSchema = v.PromiseSchema, +> extends t.TSchema { + [t.Kind]: "ValibotPromise"; + static: v.InferOutput; + type: Type; +} +function _Promise>( + type: Type, + options?: t.SchemaOptions +): TValibotPromise { + return t.CreateType({ [t.Kind]: "ValibotPromise", type }, options) as never; +} +type TFromPromise> = t.Ensure< + TValibotPromise +>; function FromPromise(type: BaseSchema): t.TSchema { - return _Promise(type as v.PromiseSchema, Options(type)) + return _Promise(type as v.PromiseSchema, Options(type)); } // ------------------------------------------------------------------ // Record // ------------------------------------------------------------------ -type TFromRecord = t.Ensure, TFromType>> +type TFromRecord< + Key extends BaseRecordKey, + Value extends BaseSchema, +> = t.Ensure, TFromType>>; function FromRecord(type: BaseSchema) { - const record = type as v.RecordSchema - return t.Record(FromType(record.key), FromType(record.value), Options(type)) + const record = type as v.RecordSchema; + return t.Record(FromType(record.key), FromType(record.value), Options(type)); } // ------------------------------------------------------------------ // Set // ------------------------------------------------------------------ -t.TypeRegistry.Set('ValibotSet', (schema, value) => { - return v.safeParse(schema.schema, value).success -}) -export interface TValibotSet = v.SetSchema> extends t.TSchema { - [t.Kind]: 'ValibotSet' - static: v.InferOutput extends infer Result ? Result : never - type: Type -} -function Set>(type: Type, options?: t.SchemaOptions): TValibotSet { - return t.CreateType({ [t.Kind]: 'ValibotSet', type }, options) as never -} -type TFromSet> = t.Ensure> +t.TypeRegistry.Set("ValibotSet", (schema, value) => { + return v.safeParse(schema.schema, value).success; +}); +export interface TValibotSet< + Type extends v.SetSchema = v.SetSchema, +> extends t.TSchema { + [t.Kind]: "ValibotSet"; + static: v.InferOutput extends infer Result ? Result : never; + type: Type; +} +function Set>( + type: Type, + options?: t.SchemaOptions +): TValibotSet { + return t.CreateType({ [t.Kind]: "ValibotSet", type }, options) as never; +} +type TFromSet> = t.Ensure< + TValibotSet +>; function FromSet(type: BaseSchema): t.TSchema { - return Set(type as v.SetSchema) + return Set(type as v.SetSchema); } // ------------------------------------------------------------------ // StrictObject // ------------------------------------------------------------------ type TFromStrictObject = t.Ensure< t.TObject<{ - -readonly [Key in keyof Properties]: TFromType + -readonly [Key in keyof Properties]: TFromType; }> -> +>; function FromStrictObject(type: BaseSchema): t.TSchema { - const object = type as v.StrictObjectSchema - const keys = globalThis.Object.getOwnPropertyNames(object.entries) + const object = type as v.StrictObjectSchema; + const keys = globalThis.Object.getOwnPropertyNames(object.entries); return t.Object( keys.reduce((properties, key) => { - return { ...properties, [key]: FromType(object.entries[key]) } + return { ...properties, [key]: FromType(object.entries[key]) }; }, {} as t.TProperties), - { ...Options(type), additionalProperties: false }, - ) + { ...Options(type), additionalProperties: false } + ); } // ------------------------------------------------------------------ // StrictTuple @@ -627,23 +824,25 @@ type TFromStrictTuple ) function FromStrictTuple(type: BaseSchema): t.TSchema { - const tuple = type as v.StrictTupleSchema - const items = globalThis.Array.isArray(tuple.items) ? tuple.items.map((item) => FromType(item)) : [] - return t.Tuple(items, Options(type)) + const tuple = type as v.StrictTupleSchema; + const items = globalThis.Array.isArray(tuple.items) + ? tuple.items.map((item) => FromType(item)) + : []; + return t.Tuple(items, Options(type)); } // ------------------------------------------------------------------ // String // ------------------------------------------------------------------ -type TFromString<_Type extends v.StringSchema> = t.TString +type TFromString<_Type extends v.StringSchema> = t.TString; function FromString(type: BaseSchema): t.TSchema { - return t.String(Options(type)) + return t.String(Options(type)); } // ------------------------------------------------------------------ // Symbol // ------------------------------------------------------------------ -type TFromSymbol<_Type extends v.SymbolSchema> = t.TSymbol +type TFromSymbol<_Type extends v.SymbolSchema> = t.TSymbol; function FromSymbol(type: BaseSchema): t.TSchema { - return t.Symbol(Options(type)) + return t.Symbol(Options(type)); } // ------------------------------------------------------------------ // Tuple @@ -655,42 +854,65 @@ type TFromTuple = ( : t.TTuple ) function FromTuple(type: BaseSchema): t.TSchema { - const tuple = type as v.TupleSchema - const items = globalThis.Array.isArray(tuple.items) ? tuple.items.map((item) => FromType(item)) : [] - return t.Tuple(items, Options(type)) + const tuple = type as v.TupleSchema; + const items = globalThis.Array.isArray(tuple.items) + ? tuple.items.map((item) => FromType(item)) + : []; + return t.Tuple(items, Options(type)); } // ------------------------------------------------------------------ // TupleWithRest // ------------------------------------------------------------------ -t.TypeRegistry.Set('ValibotTupleWithRest', (schema, value) => { - return v.safeParse(schema.schema, value).success -}) -interface TTupleWithRest = v.TupleWithRestSchema> extends t.TSchema { - [t.Kind]: 'ValibotTupleWithRest' - static: v.InferOutput - type: Type -} -function TupleWithRest>(type: Type, options?: t.SchemaOptions): TTupleWithRest { - return t.CreateType({ [t.Kind]: 'ValibotTupleWithRest', type }, Options(type)) as never -} -type TFromTupleWithRest> = t.Ensure> +t.TypeRegistry.Set("ValibotTupleWithRest", (schema, value) => { + return v.safeParse(schema.schema, value).success; +}); +interface TTupleWithRest< + Type extends v.TupleWithRestSchema< + BaseSchema[], + BaseSchema, + any + > = v.TupleWithRestSchema, +> extends t.TSchema { + [t.Kind]: "ValibotTupleWithRest"; + static: v.InferOutput; + type: Type; +} +function TupleWithRest< + Type extends v.TupleWithRestSchema, +>(type: Type, options?: t.SchemaOptions): TTupleWithRest { + return t.CreateType( + { [t.Kind]: "ValibotTupleWithRest", type }, + Options(type) + ) as never; +} +type TFromTupleWithRest< + Type extends v.TupleWithRestSchema, +> = t.Ensure>; function FromTupleWithRest(type: BaseSchema): t.TSchema { - return TupleWithRest(type as v.TupleWithRestSchema, Options(type)) + return TupleWithRest( + type as v.TupleWithRestSchema, + Options(type) + ); } // ------------------------------------------------------------------ // Undefined // ------------------------------------------------------------------ -type TFromUndefined<_Type extends v.UndefinedSchema> = t.TUndefined +type TFromUndefined<_Type extends v.UndefinedSchema> = t.TUndefined; function FromUndefined(type: BaseSchema): t.TSchema { - return t.Undefined(Options(type)) + return t.Undefined(Options(type)); } // ------------------------------------------------------------------ // Undefinable // ------------------------------------------------------------------ -type TFromUndefinedable = t.TUnion<[TFromType, t.TUndefined]> +type TFromUndefinedable = t.TUnion< + [TFromType, t.TUndefined] +>; function FromUndefinedable(type: BaseSchema): t.TSchema { - const undefinedable = type as v.UndefinedableSchema - return t.Union([FromType(undefinedable.wrapped), t.Undefined()], Options(type)) + const undefinedable = type as v.UndefinedableSchema; + return t.Union( + [FromType(undefinedable.wrapped), t.Undefined()], + Options(type) + ); } // ------------------------------------------------------------------ // Union @@ -702,40 +924,57 @@ type TFromUnion = ( : t.TUnion ) function FromUnion(type: BaseSchema): t.TSchema { - const variants = (type as v.UnionSchema).options.map((option) => FromType(option)) - return t.Union(variants, Options(type)) + const variants = (type as v.UnionSchema).options.map( + (option) => FromType(option) + ); + return t.Union(variants, Options(type)); } // ------------------------------------------------------------------ // Unknown // ------------------------------------------------------------------ -type TFromUnknown<_Type extends v.UnknownSchema> = t.TUnknown +type TFromUnknown<_Type extends v.UnknownSchema> = t.TUnknown; function FromUnknown(type: BaseSchema): t.TSchema { - return t.Unknown(Options(type)) + return t.Unknown(Options(type)); } // ------------------------------------------------------------------ // Variant // ------------------------------------------------------------------ -t.TypeRegistry.Set('ValibotVariant', (schema, value) => { - return v.safeParse(schema.schema, value).success -}) -interface TVariant, any> = v.VariantSchema, any>> extends t.TSchema { - [t.Kind]: 'ValibotVariant' - static: v.InferOutput - type: Type -} -function Variant, any>>(type: Type): TVariant { - return t.CreateType({ [t.Kind]: 'ValibotVariant', type }, Options(type)) as never -} -type TFromVariant, any>> = t.Ensure> +t.TypeRegistry.Set("ValibotVariant", (schema, value) => { + return v.safeParse(schema.schema, value).success; +}); +interface TVariant< + Type extends v.VariantSchema< + string, + v.VariantOptions, + any + > = v.VariantSchema, any>, +> extends t.TSchema { + [t.Kind]: "ValibotVariant"; + static: v.InferOutput; + type: Type; +} +function Variant< + Type extends v.VariantSchema, any>, +>(type: Type): TVariant { + return t.CreateType( + { [t.Kind]: "ValibotVariant", type }, + Options(type) + ) as never; +} +type TFromVariant< + Type extends v.VariantSchema, any>, +> = t.Ensure>; function FromVariant(type: BaseSchema): t.TSchema { - return Variant(type as v.VariantSchema, any>) + return Variant( + type as v.VariantSchema, any> + ); } // ------------------------------------------------------------------ // Void // ------------------------------------------------------------------ -type TFromVoid<_Type extends v.VoidSchema> = t.TVoid +type TFromVoid<_Type extends v.VoidSchema> = t.TVoid; function FromVoid(type: BaseSchema): t.TSchema { - return t.Void(Options(type)) + return t.Void(Options(type)); } // ------------------------------------------------------------------ // Type diff --git a/src/valibot/valibot.ts b/src/valibot/index.ts similarity index 73% rename from src/valibot/valibot.ts rename to src/valibot/index.ts index 31f89b3..d1497a5 100644 --- a/src/valibot/valibot.ts +++ b/src/valibot/index.ts @@ -26,18 +26,31 @@ THE SOFTWARE. ---------------------------------------------------------------------------*/ -import { type TValibotFromSyntax, ValibotFromSyntax } from './valibot-from-syntax' -import { type TValibotFromTypeBox, ValibotFromTypeBox } from './valibot-from-typebox' -import { type TValibotFromValibot, ValibotFromValibot } from './valibot-from-valibot' -import { type TValibotFromZod, ValibotFromZod } from './valibot-from-zod' -import { type TSyntaxOptions } from '../options' +import { + type TValibotFromSyntax, + ValibotFromSyntax, +} from "./valibot-from-syntax"; +import { + type TValibotFromTypeBox, + ValibotFromTypeBox, +} from "./valibot-from-typebox"; +import { + type TValibotFromValibot, + ValibotFromValibot, +} from "./valibot-from-valibot"; +import { type TValibotFromZod, ValibotFromZod } from "./valibot-from-zod"; +import { type TSyntaxOptions } from "../options"; -import { type TParameter, type TContextFromParameter, ContextFromParameter } from '../typebox/typebox' +import { + type TParameter, + type TContextFromParameter, + ContextFromParameter, +} from "../typebox"; -import * as g from '../guard' -import * as t from '@sinclair/typebox' -import * as v from 'valibot' -import * as c from './common' +import * as g from "../guard"; +import * as t from "@sinclair/typebox"; +import * as v from "valibot"; +import * as c from "./common"; // ------------------------------------------------------------------ // Valibot @@ -53,11 +66,21 @@ export type TValibot = Result /** Creates a Valibot type by mapping from a remote Type */ -export function Valibot(parameter: Parameter, type: Type, options?: TSyntaxOptions): TValibot +export function Valibot( + parameter: Parameter, + type: Type, + options?: TSyntaxOptions +): TValibot; /** Creates a Valibot type by mapping from a remote Type */ -export function Valibot(type: Type, options?: TSyntaxOptions): TValibot<{}, Type> +export function Valibot( + type: Type, + options?: TSyntaxOptions +): TValibot<{}, Type>; /** Creates a Valibot type by mapping from a remote Type */ -export function Valibot(type: Type, options?: TSyntaxOptions): TValibot<{}, Type> +export function Valibot( + type: Type, + options?: TSyntaxOptions +): TValibot<{}, Type>; /** Creates a Valibot type by mapping from a remote Type */ // prettier-ignore export function Valibot(...args: any[]): never { diff --git a/src/zod/zod.ts b/src/zod/index.ts similarity index 76% rename from src/zod/zod.ts rename to src/zod/index.ts index 7bb96b3..517ae93 100644 --- a/src/zod/zod.ts +++ b/src/zod/index.ts @@ -26,16 +26,20 @@ THE SOFTWARE. ---------------------------------------------------------------------------*/ -import { type TZodFromSyntax, ZodFromSyntax } from './zod-from-syntax' -import { type TZodFromTypeBox, ZodFromTypeBox } from './zod-from-typebox' -import { type TZodFromValibot, ZodFromValibot } from './zod-from-valibot' -import { type TZodFromZod, ZodFromZod } from './zod-from-zod' -import { type TSyntaxOptions } from '../options' +import { type TZodFromSyntax, ZodFromSyntax } from "./zod-from-syntax"; +import { type TZodFromTypeBox, ZodFromTypeBox } from "./zod-from-typebox"; +import { type TZodFromValibot, ZodFromValibot } from "./zod-from-valibot"; +import { type TZodFromZod, ZodFromZod } from "./zod-from-zod"; +import { type TSyntaxOptions } from "../options"; -import { type TParameter, type TContextFromParameter, ContextFromParameter } from '../typebox/typebox' +import { + type TParameter, + type TContextFromParameter, + ContextFromParameter, +} from "../typebox"; -import * as g from '../guard' -import * as z from 'zod' +import * as g from "../guard"; +import * as z from "zod"; // ------------------------------------------------------------------ // Zod @@ -51,11 +55,21 @@ export type TZod = Result /** Creates a Zod type by mapping from a remote Type */ -export function Zod(parameter: Parameter, type: Type, options?: TSyntaxOptions): TZod +export function Zod( + parameter: Parameter, + type: Type, + options?: TSyntaxOptions +): TZod; /** Creates a Zod type by mapping from a remote Type */ -export function Zod(type: Type, options?: TSyntaxOptions): TZod<{}, Type> +export function Zod( + type: Type, + options?: TSyntaxOptions +): TZod<{}, Type>; /** Creates a Zod type by mapping from a remote Type */ -export function Zod(type: Type, options?: TSyntaxOptions): TZod<{}, Type> +export function Zod( + type: Type, + options?: TSyntaxOptions +): TZod<{}, Type>; /** Creates a Zod type by mapping from a remote Type */ // prettier-ignore export function Zod(...args: any[]): never { diff --git a/task/build/package/build.ts b/task/build/package/build.ts index 4f6e0e9..f5d35ed 100644 --- a/task/build/package/build.ts +++ b/task/build/package/build.ts @@ -32,7 +32,7 @@ import { createPackageJson } from './create-package-json' /** Builds package.json and redirect directories */ export async function build(target: string) { console.log('building...package.json') - const submodules = [] as string[] + const submodules = ['typebox', 'valibot', 'zod', 'guard'] as string[] await createPackageJsonRedirect(target, submodules) await createPackageJson(target, submodules) } diff --git a/task/build/package/create-package-json.ts b/task/build/package/create-package-json.ts index 9c29266..f410f38 100644 --- a/task/build/package/create-package-json.ts +++ b/task/build/package/create-package-json.ts @@ -74,30 +74,6 @@ function resolveExports(submodules: string[]) { "default": "./build/esm/index.mjs", } }, - "./guard": { - "require": "./build/cjs/guard.js", - "import": "./build/esm/guard.mjs", - "node": "./build/cjs/guard.js", - "default": "./build/cjs/guard.js" - }, - "./typebox/*": { - "require": "./build/cjs/typebox/*", - "import": "./build/esm/typebox/*", - "node": "./build/cjs/typebox/*", - "default": "./build/cjs/typebox/*" - }, - "./zod/*": { - "require": "./build/cjs/zod/*", - "import": "./build/esm/zod/*", - "node": "./build/cjs/zod/*", - "default": "./build/cjs/zod/*" - }, - "./valibot/*": { - "require": "./build/cjs/valibot/*", - "import": "./build/esm/valibot/*", - "node": "./build/cjs/valibot/*", - "default": "./build/cjs/valibot/*" - } }) return { exports } } From e4d585631471515ed4b3f3d7f070c767d6a7cf95 Mon Sep 17 00:00:00 2001 From: m1212e <14091540+m1212e@users.noreply.github.com> Date: Sat, 19 Jul 2025 02:00:39 +0200 Subject: [PATCH 4/6] =?UTF-8?q?=E2=AC=86=EF=B8=8F=20improvement:=20mark=20?= =?UTF-8?q?zod=20and=20valibot=20as=20optional=20dependencies?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 5e954f5..157fe79 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,14 @@ "valibot": "^1.0.0", "zod": "^3.24.1" }, + "peerDependenciesMeta": { + "zod": { + "optional": true + }, + "valibot": { + "optional": true + } + }, "devDependencies": { "@arethetypeswrong/cli": "^0.17.2", "@sinclair/hammer": "^0.18.0", @@ -30,5 +38,5 @@ "mocha": "^11.0.1", "prettier": "^3.4.2", "typescript": "^5.7.2" - } -} + }, +} \ No newline at end of file From 89cd1b006a6bdaa9ebbdfcda1b7f592ffaec7ce9 Mon Sep 17 00:00:00 2001 From: sinclair Date: Sun, 20 Jul 2025 14:04:31 +0900 Subject: [PATCH 5/6] fix build | index submodule | formatting --- .vscode/settings.json | 2 +- package-lock.json | 673 +++++++---------------- package.json | 10 +- src/compile/compile.ts | 35 +- src/compile/index.ts | 32 ++ src/guard/guard.ts | 113 ++++ src/guard/index.ts | 86 +-- src/index.ts | 51 +- src/static.ts | 2 +- src/syntax/index.ts | 33 ++ src/syntax/syntax.ts | 38 +- src/typebox/index.ts | 102 +--- src/typebox/typebox-from-valibot.ts | 822 ++++++++++------------------ src/typebox/typebox.ts | 102 ++++ src/valibot/index.ts | 72 +-- src/valibot/valibot.ts | 72 +++ src/zod/index.ts | 61 +-- src/zod/zod.ts | 70 +++ task/build/package/build.ts | 2 +- tsconfig.json | 8 +- 20 files changed, 985 insertions(+), 1401 deletions(-) create mode 100644 src/compile/index.ts create mode 100644 src/guard/guard.ts create mode 100644 src/syntax/index.ts create mode 100644 src/typebox/typebox.ts create mode 100644 src/valibot/valibot.ts create mode 100644 src/zod/zod.ts diff --git a/.vscode/settings.json b/.vscode/settings.json index 6fa52ea..53b508b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,6 @@ { "files.exclude": { "node_modules": true, - "package-lock.json": true + "package-lock.json": false } } \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 6d9eff0..a0dd2bd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,12 +15,20 @@ "@types/node": "^22.10.2", "mocha": "^11.0.1", "prettier": "^3.4.2", - "typescript": "^5.7.2" - }, - "peerDependencies": { - "@sinclair/typebox": "^0.34.30", + "typescript": "^5.7.2", "valibot": "^1.0.0", "zod": "^3.24.1" + }, + "peerDependencies": { + "@sinclair/typebox": "^0.34.30" + }, + "peerDependenciesMeta": { + "valibot": { + "optional": true + }, + "zod": { + "optional": true + } } }, "node_modules/@andrewbranch/untar.js": { @@ -30,12 +38,12 @@ "dev": true }, "node_modules/@arethetypeswrong/cli": { - "version": "0.17.3", - "resolved": "https://registry.npmjs.org/@arethetypeswrong/cli/-/cli-0.17.3.tgz", - "integrity": "sha512-wI9ZSTweunmzHboSyYtWRFpba9fM9mpX1g7EUoRr+86zHSd7NR7svb6EmJD2hv1V+SoisB2fERu6EQGGEfQ8oQ==", + "version": "0.17.4", + "resolved": "https://registry.npmjs.org/@arethetypeswrong/cli/-/cli-0.17.4.tgz", + "integrity": "sha512-AeiKxtf67XD/NdOqXgBOE5TZWH3EOCt+0GkbUpekOzngc+Q/cRZ5azjWyMxISxxfp0EItgm5NoSld9p7BAA5xQ==", "dev": true, "dependencies": { - "@arethetypeswrong/core": "0.17.3", + "@arethetypeswrong/core": "0.17.4", "chalk": "^4.1.2", "cli-table3": "^0.6.3", "commander": "^10.0.1", @@ -51,12 +59,13 @@ } }, "node_modules/@arethetypeswrong/core": { - "version": "0.17.3", - "resolved": "https://registry.npmjs.org/@arethetypeswrong/core/-/core-0.17.3.tgz", - "integrity": "sha512-2TB7O5JmC7UX7QHRGGftxRVQjV4Ce6oOIDGIDDERyT9dQ8lK/tRGfFubzO80rWeXm/gSrA8jirlXSWSE1i5ynQ==", + "version": "0.17.4", + "resolved": "https://registry.npmjs.org/@arethetypeswrong/core/-/core-0.17.4.tgz", + "integrity": "sha512-Izvir8iIoU+X4SKtDAa5kpb+9cpifclzsbA8x/AZY0k0gIfXYQ1fa1B6Epfe6vNA2YfDX8VtrZFgvnXB6aPEoQ==", "dev": true, "dependencies": { "@andrewbranch/untar.js": "^1.0.3", + "@loaderkit/resolve": "^1.0.2", "cjs-module-lexer": "^1.2.3", "fflate": "^0.8.2", "lru-cache": "^10.4.3", @@ -81,6 +90,12 @@ "node": ">=14.17" } }, + "node_modules/@braidai/lang": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@braidai/lang/-/lang-1.1.1.tgz", + "integrity": "sha512-5uM+no3i3DafVgkoW7ayPhEGHNNBZCSj5TrGDQt0ayEKQda5f3lAXlmQg0MR5E0gKgmTzUUEtSWHsEC3h9jUcg==", + "dev": true + }, "node_modules/@colors/colors": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/@colors/colors/-/colors-1.5.0.tgz", @@ -147,6 +162,15 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/@loaderkit/resolve": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@loaderkit/resolve/-/resolve-1.0.4.tgz", + "integrity": "sha512-rJzYKVcV4dxJv+vW6jlvagF8zvGxHJ2+HTr1e2qOejfmGhAApgJHl8Aog4mMszxceTRiKTTbnpgmTO1bEZHV/A==", + "dev": true, + "dependencies": { + "@braidai/lang": "^1.0.0" + } + }, "node_modules/@pkgjs/parseargs": { "version": "0.11.0", "resolved": "https://registry.npmjs.org/@pkgjs/parseargs/-/parseargs-0.11.0.tgz", @@ -170,9 +194,9 @@ } }, "node_modules/@sinclair/typebox": { - "version": "0.34.30", - "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.34.30.tgz", - "integrity": "sha512-gFB3BiqjDxEoadW0zn+xyMVb7cLxPCoblVn2C/BKpI41WPYi2d6fwHAlynPNZ5O/Q4WEiujdnJzVtvG/Jc2CBQ==", + "version": "0.34.38", + "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.34.38.tgz", + "integrity": "sha512-HpkxMmc2XmZKhvaKIZZThlHmx1L0I/V1hWK1NubtlFnr6ZqdiOpV72TKudZUNQjZNsyDBay72qFEhEvb+bcwcA==", "peer": true }, "node_modules/@sindresorhus/is": { @@ -194,21 +218,12 @@ "dev": true }, "node_modules/@types/node": { - "version": "22.12.0", - "resolved": "https://registry.npmjs.org/@types/node/-/node-22.12.0.tgz", - "integrity": "sha512-Fll2FZ1riMjNmlmJOdAyY5pUbkftXslB5DgEzlIuNaiWhXd00FhWxVC/r4yV/4wBb9JfImTu+jiSvXTkJ7F/gA==", + "version": "22.16.5", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.16.5.tgz", + "integrity": "sha512-bJFoMATwIGaxxx8VJPeM8TonI8t579oRvgAuT8zFugJsJZgzqv0Fu8Mhp68iecjzG7cnN3mO2dJQ5uUM2EFrgQ==", "dev": true, "dependencies": { - "undici-types": "~6.20.0" - } - }, - "node_modules/ansi-colors": { - "version": "4.1.3", - "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.3.tgz", - "integrity": "sha512-/6w/C21Pm1A7aZitlI5Ni/2J6FFQN8i1Cvz3kHABAAbw93v/NlvKdVOqz7CCWz/3iv/JplRSEEZ83XION15ovw==", - "dev": true, - "engines": { - "node": ">=6" + "undici-types": "~6.21.0" } }, "node_modules/ansi-escapes": { @@ -259,19 +274,6 @@ "integrity": "sha512-7UvmKalWRt1wgjL1RrGxoSJW/0QZFIegpeGvZG9kjp8vrRu55XTHbwnqq2GpXm9uLbcuhxm3IqX9OB4MZR1b2A==", "dev": true }, - "node_modules/anymatch": { - "version": "3.1.3", - "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.3.tgz", - "integrity": "sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==", - "dev": true, - "dependencies": { - "normalize-path": "^3.0.0", - "picomatch": "^2.0.4" - }, - "engines": { - "node": ">= 8" - } - }, "node_modules/argparse": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", @@ -284,39 +286,15 @@ "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", "dev": true }, - "node_modules/binary-extensions": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.3.0.tgz", - "integrity": "sha512-Ceh+7ox5qe7LJuLHoY0feh3pHuUDHAcRUeyL2VYghZwfpkNIy/+8Ocg0a3UuSoYzavmylwuLWQOf3hl0jjMMIw==", - "dev": true, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/brace-expansion": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", - "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.2.tgz", + "integrity": "sha512-Jt0vHyM+jmUBqojB7E1NIYadt0vI0Qxjxd2TErW94wDz+E2LAm5vKMXXwg6ZZBTHPuUlDgQHKXvjGBdfcF1ZDQ==", "dev": true, "dependencies": { "balanced-match": "^1.0.0" } }, - "node_modules/braces": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz", - "integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==", - "dev": true, - "dependencies": { - "fill-range": "^7.1.1" - }, - "engines": { - "node": ">=8" - } - }, "node_modules/browser-stdout": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/browser-stdout/-/browser-stdout-1.3.1.tgz", @@ -361,27 +339,18 @@ } }, "node_modules/chokidar": { - "version": "3.6.0", - "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.6.0.tgz", - "integrity": "sha512-7VT13fmjotKpGipCW9JEQAusEPE+Ei8nl6/g4FBAmIm0GOOLMua9NDDo/DWp0ZAxCr3cPq5ZpBqmPAQgDda2Pw==", + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-4.0.3.tgz", + "integrity": "sha512-Qgzu8kfBvo+cA4962jnP1KkS6Dop5NS6g7R5LFYJr4b8Ub94PPQXUksCw9PvXoeXPRRddRNC5C1JQUR2SMGtnA==", "dev": true, "dependencies": { - "anymatch": "~3.1.2", - "braces": "~3.0.2", - "glob-parent": "~5.1.2", - "is-binary-path": "~2.1.0", - "is-glob": "~4.0.1", - "normalize-path": "~3.0.0", - "readdirp": "~3.6.0" + "readdirp": "^4.0.1" }, "engines": { - "node": ">= 8.10.0" + "node": ">= 14.16.0" }, "funding": { "url": "https://paulmillr.com/funding/" - }, - "optionalDependencies": { - "fsevents": "~2.3.2" } }, "node_modules/cjs-module-lexer": { @@ -517,9 +486,9 @@ } }, "node_modules/debug": { - "version": "4.4.0", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.0.tgz", - "integrity": "sha512-6WTZ/IxCY/T6BALoZHaE4ctp9xm+Z5kY/pzYaCHRFeyVhojxlrm+46y68HA6hr0TcwEssoxNiDEUJQjfPZ/RYA==", + "version": "4.4.1", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.1.tgz", + "integrity": "sha512-KcKCqiftBJcZr++7ykoDIEwSa3XWowTfNPo92BYxjXiyYEVrUQh2aLyhxBCwww+heortUFxEJYcRzosstTEBYQ==", "dev": true, "dependencies": { "ms": "^2.1.3" @@ -546,9 +515,9 @@ } }, "node_modules/diff": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/diff/-/diff-5.2.0.tgz", - "integrity": "sha512-uIFDxqpRZGZ6ThOk84hEfqWoHx2devRFvpTZcTHur85vImfaxUbTW9Ryh4CpCuDnToOP1CEtXKIgytHBPVff5A==", + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/diff/-/diff-7.0.0.tgz", + "integrity": "sha512-PJWHUb1RFevKCwaFA9RlG5tCd+FO5iRh9A8HEtkmBH2Li03iJriB6m6JIN4rGz3K3JLawI7/veA1xzRKP6ISBw==", "dev": true, "engines": { "node": ">=0.3.1" @@ -967,18 +936,6 @@ "integrity": "sha512-cPJU47OaAoCbg0pBvzsgpTPhmhqI5eJjh/JIu8tPj5q+T7iLvW/JAYUqmE7KOB4R1ZyEhzBaIQpQpardBF5z8A==", "dev": true }, - "node_modules/fill-range": { - "version": "7.1.1", - "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", - "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==", - "dev": true, - "dependencies": { - "to-regex-range": "^5.0.1" - }, - "engines": { - "node": ">=8" - } - }, "node_modules/find-up": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/find-up/-/find-up-5.0.0.tgz", @@ -1005,12 +962,12 @@ } }, "node_modules/foreground-child": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-3.3.0.tgz", - "integrity": "sha512-Ld2g8rrAyMYFXBhEqMz8ZAHBi4J4uS1i/CxGMDnjyFWddMXLVcDp051DZfu+t7+ab7Wv6SMqpWmyFIj5UbfFvg==", + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-3.3.1.tgz", + "integrity": "sha512-gIXjKqtFuWEgzFRJA9WCQeSJLZDjgJUOMCMzxtvFq/37KojM1BFGufqsCy0r4qSQmYLsZYMeyRqzIWOMup03sw==", "dev": true, "dependencies": { - "cross-spawn": "^7.0.0", + "cross-spawn": "^7.0.6", "signal-exit": "^4.0.1" }, "engines": { @@ -1020,20 +977,6 @@ "url": "https://github.com/sponsors/isaacs" } }, - "node_modules/fsevents": { - "version": "2.3.3", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", - "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", - "dev": true, - "hasInstallScript": true, - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": "^8.16.0 || ^10.6.0 || >=11.0.0" - } - }, "node_modules/get-caller-file": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", @@ -1063,33 +1006,6 @@ "url": "https://github.com/sponsors/isaacs" } }, - "node_modules/glob-parent": { - "version": "5.1.2", - "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", - "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", - "dev": true, - "dependencies": { - "is-glob": "^4.0.1" - }, - "engines": { - "node": ">= 6" - } - }, - "node_modules/glob/node_modules/minimatch": { - "version": "9.0.5", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz", - "integrity": "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==", - "dev": true, - "dependencies": { - "brace-expansion": "^2.0.1" - }, - "engines": { - "node": ">=16 || 14 >=14.17" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, "node_modules/has-flag": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", @@ -1117,27 +1033,6 @@ "node": "*" } }, - "node_modules/is-binary-path": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", - "integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==", - "dev": true, - "dependencies": { - "binary-extensions": "^2.0.0" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/is-extglob": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", - "integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==", - "dev": true, - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/is-fullwidth-code-point": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", @@ -1147,27 +1042,6 @@ "node": ">=8" } }, - "node_modules/is-glob": { - "version": "4.0.3", - "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", - "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==", - "dev": true, - "dependencies": { - "is-extglob": "^2.1.1" - }, - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/is-number": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", - "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", - "dev": true, - "engines": { - "node": ">=0.12.0" - } - }, "node_modules/is-plain-obj": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-2.1.0.tgz", @@ -1305,15 +1179,18 @@ } }, "node_modules/minimatch": { - "version": "5.1.6", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.6.tgz", - "integrity": "sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==", + "version": "9.0.5", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz", + "integrity": "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==", "dev": true, "dependencies": { "brace-expansion": "^2.0.1" }, "engines": { - "node": ">=10" + "node": ">=16 || 14 >=14.17" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" } }, "node_modules/minipass": { @@ -1326,28 +1203,28 @@ } }, "node_modules/mocha": { - "version": "11.1.0", - "resolved": "https://registry.npmjs.org/mocha/-/mocha-11.1.0.tgz", - "integrity": "sha512-8uJR5RTC2NgpY3GrYcgpZrsEd9zKbPDpob1RezyR2upGHRQtHWofmzTMzTMSV6dru3tj5Ukt0+Vnq1qhFEEwAg==", + "version": "11.7.1", + "resolved": "https://registry.npmjs.org/mocha/-/mocha-11.7.1.tgz", + "integrity": "sha512-5EK+Cty6KheMS/YLPPMJC64g5V61gIR25KsRItHw6x4hEKT6Njp1n9LOlH4gpevuwMVS66SXaBBpg+RWZkza4A==", "dev": true, "dependencies": { - "ansi-colors": "^4.1.3", "browser-stdout": "^1.3.1", - "chokidar": "^3.5.3", + "chokidar": "^4.0.1", "debug": "^4.3.5", - "diff": "^5.2.0", + "diff": "^7.0.0", "escape-string-regexp": "^4.0.0", "find-up": "^5.0.0", "glob": "^10.4.5", "he": "^1.2.0", "js-yaml": "^4.1.0", "log-symbols": "^4.1.0", - "minimatch": "^5.1.6", + "minimatch": "^9.0.5", "ms": "^2.1.3", + "picocolors": "^1.1.1", "serialize-javascript": "^6.0.2", "strip-json-comments": "^3.1.1", "supports-color": "^8.1.1", - "workerpool": "^6.5.1", + "workerpool": "^9.2.0", "yargs": "^17.7.2", "yargs-parser": "^21.1.1", "yargs-unparser": "^2.0.0" @@ -1477,15 +1354,6 @@ "node": ">=18" } }, - "node_modules/normalize-path": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", - "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==", - "dev": true, - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/object-assign": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", @@ -1586,22 +1454,16 @@ "url": "https://github.com/sponsors/isaacs" } }, - "node_modules/picomatch": { - "version": "2.3.1", - "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", - "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", - "dev": true, - "engines": { - "node": ">=8.6" - }, - "funding": { - "url": "https://github.com/sponsors/jonschlinkert" - } + "node_modules/picocolors": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz", + "integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==", + "dev": true }, "node_modules/prettier": { - "version": "3.4.2", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.4.2.tgz", - "integrity": "sha512-e9MewbtFo+Fevyuxn/4rrcDAaq0IYxPGLvObpQjiZBMAzB9IGmzlnG9RZy3FFas+eBMu2vA0CszMeduow5dIuQ==", + "version": "3.6.2", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.6.2.tgz", + "integrity": "sha512-I7AIg5boAr5R0FFtJ6rCfD+LFsWHp81dolrFD8S79U9tb8Az2nGrJncnMSnys+bpQJfRUzqs9hnA81OAA3hCuQ==", "dev": true, "bin": { "prettier": "bin/prettier.cjs" @@ -1623,15 +1485,16 @@ } }, "node_modules/readdirp": { - "version": "3.6.0", - "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz", - "integrity": "sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==", + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-4.1.2.tgz", + "integrity": "sha512-GDhwkLfywWL2s6vEjyhri+eXmfH6j1L7JE27WhqLeYzoh/A3DBaYGEj2H/HFZCn/kMfim73FXxEJTw06WtxQwg==", "dev": true, - "dependencies": { - "picomatch": "^2.2.1" - }, "engines": { - "node": ">=8.10.0" + "node": ">= 14.18.0" + }, + "funding": { + "type": "individual", + "url": "https://paulmillr.com/funding/" } }, "node_modules/require-directory": { @@ -1664,9 +1527,9 @@ ] }, "node_modules/semver": { - "version": "7.7.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.0.tgz", - "integrity": "sha512-DrfFnPzblFmNrIZzg5RzHegbiRWg7KMR7btwi2yjHwx06zsUbO5g613sVwEV7FTwmzJu+Io0lJe2GJ3LxqpvBQ==", + "version": "7.7.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.2.tgz", + "integrity": "sha512-RF0Fw+rO5AMf9MAyaRXI4AV0Ulj5lMHqVxxdSgiVbixSCXoEmmX/jk0CuJw4+3SqroYO9VoUh+HcuJivvtJemA==", "dev": true, "bin": { "semver": "bin/semver.js" @@ -1862,9 +1725,9 @@ } }, "node_modules/supports-hyperlinks": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/supports-hyperlinks/-/supports-hyperlinks-3.1.0.tgz", - "integrity": "sha512-2rn0BZ+/f7puLOHZm1HOJfwBggfaHXUpPUSSG/SWM4TWp5KCfmNYwnC3hruy2rZlMnmWZ+QAGpZfchu3f3695A==", + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/supports-hyperlinks/-/supports-hyperlinks-3.2.0.tgz", + "integrity": "sha512-zFObLMyZeEwzAoKCyu1B91U79K2t7ApXuQfo8OuxwXLDgcKxuwM+YvcbIhm6QWqz7mHUH1TVytR1PwVVjEuMig==", "dev": true, "dependencies": { "has-flag": "^4.0.0", @@ -1874,7 +1737,7 @@ "node": ">=14.18" }, "funding": { - "url": "https://github.com/sponsors/sindresorhus" + "url": "https://github.com/chalk/supports-hyperlinks?sponsor=1" } }, "node_modules/thenify": { @@ -1898,23 +1761,11 @@ "node": ">=0.8" } }, - "node_modules/to-regex-range": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", - "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", - "dev": true, - "dependencies": { - "is-number": "^7.0.0" - }, - "engines": { - "node": ">=8.0" - } - }, "node_modules/typescript": { - "version": "5.7.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.7.3.tgz", - "integrity": "sha512-84MVSjMEHP+FQRPy3pX9sTVV/INIex71s9TL2Gm5FG/WG1SqXeKyZ0k7/blY/4FdOzI12CBy1vGc4og/eus0fw==", - "devOptional": true, + "version": "5.8.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.8.3.tgz", + "integrity": "sha512-p1diW6TqL9L07nNxvRMM7hMMw4c5XOo/1ibL4aAIGmSAt9slTE1Xgw5KWuof2uTOvCg9BY7ZRi+GaF+7sfgPeQ==", + "dev": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" @@ -1924,9 +1775,9 @@ } }, "node_modules/undici-types": { - "version": "6.20.0", - "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.20.0.tgz", - "integrity": "sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg==", + "version": "6.21.0", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz", + "integrity": "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==", "dev": true }, "node_modules/unicode-emoji-modifier-base": { @@ -1939,10 +1790,10 @@ } }, "node_modules/valibot": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/valibot/-/valibot-1.0.0.tgz", - "integrity": "sha512-1Hc0ihzWxBar6NGeZv7fPLY0QuxFMyxwYR2sF1Blu7Wq7EnremwY2W02tit2ij2VJT8HcSkHAQqmFfl77f73Yw==", - "peer": true, + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/valibot/-/valibot-1.1.0.tgz", + "integrity": "sha512-Nk8lX30Qhu+9txPYTwM0cFlWLdPFsFr6LblzqIySfbZph9+BFsAHsNvHOymEviUepeIW6KFHzpX8TKhbptBXXw==", + "dev": true, "peerDependencies": { "typescript": ">=5" }, @@ -1977,9 +1828,9 @@ } }, "node_modules/workerpool": { - "version": "6.5.1", - "resolved": "https://registry.npmjs.org/workerpool/-/workerpool-6.5.1.tgz", - "integrity": "sha512-Fs4dNYcsdpYSAfVxhnl1L5zTksjvOJxtC5hzMNl+1t9B8hTJTdKDyZ5ju7ztgPy+ft9tBFXoOlDNiOT9WUXZlA==", + "version": "9.3.3", + "resolved": "https://registry.npmjs.org/workerpool/-/workerpool-9.3.3.tgz", + "integrity": "sha512-slxCaKbYjEdFT/o2rH9xS1hf4uRDch1w7Uo+apxhZ+sf/1d9e0ZVkn42kPNGP2dgjIx6YFvSevj0zHvbWe2jdw==", "dev": true }, "node_modules/wrap-ansi": { @@ -2146,10 +1997,10 @@ } }, "node_modules/zod": { - "version": "3.24.1", - "resolved": "https://registry.npmjs.org/zod/-/zod-3.24.1.tgz", - "integrity": "sha512-muH7gBL9sI1nciMZV67X5fTKKBLtwpZ5VBp1vsOQzj1MhrBZ4wlVCm3gedKZWLp0Oyel8sIGfeiz54Su+OVT+A==", - "peer": true, + "version": "3.25.76", + "resolved": "https://registry.npmjs.org/zod/-/zod-3.25.76.tgz", + "integrity": "sha512-gzUt/qt81nXsFGKIFcC3YnfEAx5NkunCfnDlvuBSSFS02bcXu4Lmea0AFIUwbLWxWPx3d9p8S5QoaujKcNQxcQ==", + "dev": true, "funding": { "url": "https://github.com/sponsors/colinhacks" } @@ -2163,12 +2014,12 @@ "dev": true }, "@arethetypeswrong/cli": { - "version": "0.17.3", - "resolved": "https://registry.npmjs.org/@arethetypeswrong/cli/-/cli-0.17.3.tgz", - "integrity": "sha512-wI9ZSTweunmzHboSyYtWRFpba9fM9mpX1g7EUoRr+86zHSd7NR7svb6EmJD2hv1V+SoisB2fERu6EQGGEfQ8oQ==", + "version": "0.17.4", + "resolved": "https://registry.npmjs.org/@arethetypeswrong/cli/-/cli-0.17.4.tgz", + "integrity": "sha512-AeiKxtf67XD/NdOqXgBOE5TZWH3EOCt+0GkbUpekOzngc+Q/cRZ5azjWyMxISxxfp0EItgm5NoSld9p7BAA5xQ==", "dev": true, "requires": { - "@arethetypeswrong/core": "0.17.3", + "@arethetypeswrong/core": "0.17.4", "chalk": "^4.1.2", "cli-table3": "^0.6.3", "commander": "^10.0.1", @@ -2178,12 +2029,13 @@ } }, "@arethetypeswrong/core": { - "version": "0.17.3", - "resolved": "https://registry.npmjs.org/@arethetypeswrong/core/-/core-0.17.3.tgz", - "integrity": "sha512-2TB7O5JmC7UX7QHRGGftxRVQjV4Ce6oOIDGIDDERyT9dQ8lK/tRGfFubzO80rWeXm/gSrA8jirlXSWSE1i5ynQ==", + "version": "0.17.4", + "resolved": "https://registry.npmjs.org/@arethetypeswrong/core/-/core-0.17.4.tgz", + "integrity": "sha512-Izvir8iIoU+X4SKtDAa5kpb+9cpifclzsbA8x/AZY0k0gIfXYQ1fa1B6Epfe6vNA2YfDX8VtrZFgvnXB6aPEoQ==", "dev": true, "requires": { "@andrewbranch/untar.js": "^1.0.3", + "@loaderkit/resolve": "^1.0.2", "cjs-module-lexer": "^1.2.3", "fflate": "^0.8.2", "lru-cache": "^10.4.3", @@ -2200,6 +2052,12 @@ } } }, + "@braidai/lang": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@braidai/lang/-/lang-1.1.1.tgz", + "integrity": "sha512-5uM+no3i3DafVgkoW7ayPhEGHNNBZCSj5TrGDQt0ayEKQda5f3lAXlmQg0MR5E0gKgmTzUUEtSWHsEC3h9jUcg==", + "dev": true + }, "@colors/colors": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/@colors/colors/-/colors-1.5.0.tgz", @@ -2247,6 +2105,15 @@ } } }, + "@loaderkit/resolve": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@loaderkit/resolve/-/resolve-1.0.4.tgz", + "integrity": "sha512-rJzYKVcV4dxJv+vW6jlvagF8zvGxHJ2+HTr1e2qOejfmGhAApgJHl8Aog4mMszxceTRiKTTbnpgmTO1bEZHV/A==", + "dev": true, + "requires": { + "@braidai/lang": "^1.0.0" + } + }, "@pkgjs/parseargs": { "version": "0.11.0", "resolved": "https://registry.npmjs.org/@pkgjs/parseargs/-/parseargs-0.11.0.tgz", @@ -2264,9 +2131,9 @@ } }, "@sinclair/typebox": { - "version": "0.34.30", - "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.34.30.tgz", - "integrity": "sha512-gFB3BiqjDxEoadW0zn+xyMVb7cLxPCoblVn2C/BKpI41WPYi2d6fwHAlynPNZ5O/Q4WEiujdnJzVtvG/Jc2CBQ==", + "version": "0.34.38", + "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.34.38.tgz", + "integrity": "sha512-HpkxMmc2XmZKhvaKIZZThlHmx1L0I/V1hWK1NubtlFnr6ZqdiOpV72TKudZUNQjZNsyDBay72qFEhEvb+bcwcA==", "peer": true }, "@sindresorhus/is": { @@ -2282,20 +2149,14 @@ "dev": true }, "@types/node": { - "version": "22.12.0", - "resolved": "https://registry.npmjs.org/@types/node/-/node-22.12.0.tgz", - "integrity": "sha512-Fll2FZ1riMjNmlmJOdAyY5pUbkftXslB5DgEzlIuNaiWhXd00FhWxVC/r4yV/4wBb9JfImTu+jiSvXTkJ7F/gA==", + "version": "22.16.5", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.16.5.tgz", + "integrity": "sha512-bJFoMATwIGaxxx8VJPeM8TonI8t579oRvgAuT8zFugJsJZgzqv0Fu8Mhp68iecjzG7cnN3mO2dJQ5uUM2EFrgQ==", "dev": true, "requires": { - "undici-types": "~6.20.0" + "undici-types": "~6.21.0" } }, - "ansi-colors": { - "version": "4.1.3", - "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.3.tgz", - "integrity": "sha512-/6w/C21Pm1A7aZitlI5Ni/2J6FFQN8i1Cvz3kHABAAbw93v/NlvKdVOqz7CCWz/3iv/JplRSEEZ83XION15ovw==", - "dev": true - }, "ansi-escapes": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-7.0.0.tgz", @@ -2326,16 +2187,6 @@ "integrity": "sha512-7UvmKalWRt1wgjL1RrGxoSJW/0QZFIegpeGvZG9kjp8vrRu55XTHbwnqq2GpXm9uLbcuhxm3IqX9OB4MZR1b2A==", "dev": true }, - "anymatch": { - "version": "3.1.3", - "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.3.tgz", - "integrity": "sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==", - "dev": true, - "requires": { - "normalize-path": "^3.0.0", - "picomatch": "^2.0.4" - } - }, "argparse": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", @@ -2348,30 +2199,15 @@ "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", "dev": true }, - "binary-extensions": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.3.0.tgz", - "integrity": "sha512-Ceh+7ox5qe7LJuLHoY0feh3pHuUDHAcRUeyL2VYghZwfpkNIy/+8Ocg0a3UuSoYzavmylwuLWQOf3hl0jjMMIw==", - "dev": true - }, "brace-expansion": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", - "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.2.tgz", + "integrity": "sha512-Jt0vHyM+jmUBqojB7E1NIYadt0vI0Qxjxd2TErW94wDz+E2LAm5vKMXXwg6ZZBTHPuUlDgQHKXvjGBdfcF1ZDQ==", "dev": true, "requires": { "balanced-match": "^1.0.0" } }, - "braces": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz", - "integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==", - "dev": true, - "requires": { - "fill-range": "^7.1.1" - } - }, "browser-stdout": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/browser-stdout/-/browser-stdout-1.3.1.tgz", @@ -2401,19 +2237,12 @@ "dev": true }, "chokidar": { - "version": "3.6.0", - "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.6.0.tgz", - "integrity": "sha512-7VT13fmjotKpGipCW9JEQAusEPE+Ei8nl6/g4FBAmIm0GOOLMua9NDDo/DWp0ZAxCr3cPq5ZpBqmPAQgDda2Pw==", + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-4.0.3.tgz", + "integrity": "sha512-Qgzu8kfBvo+cA4962jnP1KkS6Dop5NS6g7R5LFYJr4b8Ub94PPQXUksCw9PvXoeXPRRddRNC5C1JQUR2SMGtnA==", "dev": true, "requires": { - "anymatch": "~3.1.2", - "braces": "~3.0.2", - "fsevents": "~2.3.2", - "glob-parent": "~5.1.2", - "is-binary-path": "~2.1.0", - "is-glob": "~4.0.1", - "normalize-path": "~3.0.0", - "readdirp": "~3.6.0" + "readdirp": "^4.0.1" } }, "cjs-module-lexer": { @@ -2518,9 +2347,9 @@ } }, "debug": { - "version": "4.4.0", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.0.tgz", - "integrity": "sha512-6WTZ/IxCY/T6BALoZHaE4ctp9xm+Z5kY/pzYaCHRFeyVhojxlrm+46y68HA6hr0TcwEssoxNiDEUJQjfPZ/RYA==", + "version": "4.4.1", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.1.tgz", + "integrity": "sha512-KcKCqiftBJcZr++7ykoDIEwSa3XWowTfNPo92BYxjXiyYEVrUQh2aLyhxBCwww+heortUFxEJYcRzosstTEBYQ==", "dev": true, "requires": { "ms": "^2.1.3" @@ -2533,9 +2362,9 @@ "dev": true }, "diff": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/diff/-/diff-5.2.0.tgz", - "integrity": "sha512-uIFDxqpRZGZ6ThOk84hEfqWoHx2devRFvpTZcTHur85vImfaxUbTW9Ryh4CpCuDnToOP1CEtXKIgytHBPVff5A==", + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/diff/-/diff-7.0.0.tgz", + "integrity": "sha512-PJWHUb1RFevKCwaFA9RlG5tCd+FO5iRh9A8HEtkmBH2Li03iJriB6m6JIN4rGz3K3JLawI7/veA1xzRKP6ISBw==", "dev": true }, "eastasianwidth": { @@ -2749,15 +2578,6 @@ "integrity": "sha512-cPJU47OaAoCbg0pBvzsgpTPhmhqI5eJjh/JIu8tPj5q+T7iLvW/JAYUqmE7KOB4R1ZyEhzBaIQpQpardBF5z8A==", "dev": true }, - "fill-range": { - "version": "7.1.1", - "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", - "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==", - "dev": true, - "requires": { - "to-regex-range": "^5.0.1" - } - }, "find-up": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/find-up/-/find-up-5.0.0.tgz", @@ -2775,22 +2595,15 @@ "dev": true }, "foreground-child": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-3.3.0.tgz", - "integrity": "sha512-Ld2g8rrAyMYFXBhEqMz8ZAHBi4J4uS1i/CxGMDnjyFWddMXLVcDp051DZfu+t7+ab7Wv6SMqpWmyFIj5UbfFvg==", + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-3.3.1.tgz", + "integrity": "sha512-gIXjKqtFuWEgzFRJA9WCQeSJLZDjgJUOMCMzxtvFq/37KojM1BFGufqsCy0r4qSQmYLsZYMeyRqzIWOMup03sw==", "dev": true, "requires": { - "cross-spawn": "^7.0.0", + "cross-spawn": "^7.0.6", "signal-exit": "^4.0.1" } }, - "fsevents": { - "version": "2.3.3", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", - "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", - "dev": true, - "optional": true - }, "get-caller-file": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", @@ -2809,26 +2622,6 @@ "minipass": "^7.1.2", "package-json-from-dist": "^1.0.0", "path-scurry": "^1.11.1" - }, - "dependencies": { - "minimatch": { - "version": "9.0.5", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz", - "integrity": "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==", - "dev": true, - "requires": { - "brace-expansion": "^2.0.1" - } - } - } - }, - "glob-parent": { - "version": "5.1.2", - "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", - "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", - "dev": true, - "requires": { - "is-glob": "^4.0.1" } }, "has-flag": { @@ -2849,42 +2642,12 @@ "integrity": "sha512-tzcUFauisWKNHaRkN4Wjl/ZA07gENAjFl3J/c480dprkGTg5EQstgaNFqBfUqCq54kZRIEcreTsAgF/m2quD7A==", "dev": true }, - "is-binary-path": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", - "integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==", - "dev": true, - "requires": { - "binary-extensions": "^2.0.0" - } - }, - "is-extglob": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", - "integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==", - "dev": true - }, "is-fullwidth-code-point": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", "dev": true }, - "is-glob": { - "version": "4.0.3", - "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", - "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==", - "dev": true, - "requires": { - "is-extglob": "^2.1.1" - } - }, - "is-number": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", - "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", - "dev": true - }, "is-plain-obj": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-2.1.0.tgz", @@ -2977,9 +2740,9 @@ } }, "minimatch": { - "version": "5.1.6", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.6.tgz", - "integrity": "sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==", + "version": "9.0.5", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz", + "integrity": "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==", "dev": true, "requires": { "brace-expansion": "^2.0.1" @@ -2992,28 +2755,28 @@ "dev": true }, "mocha": { - "version": "11.1.0", - "resolved": "https://registry.npmjs.org/mocha/-/mocha-11.1.0.tgz", - "integrity": "sha512-8uJR5RTC2NgpY3GrYcgpZrsEd9zKbPDpob1RezyR2upGHRQtHWofmzTMzTMSV6dru3tj5Ukt0+Vnq1qhFEEwAg==", + "version": "11.7.1", + "resolved": "https://registry.npmjs.org/mocha/-/mocha-11.7.1.tgz", + "integrity": "sha512-5EK+Cty6KheMS/YLPPMJC64g5V61gIR25KsRItHw6x4hEKT6Njp1n9LOlH4gpevuwMVS66SXaBBpg+RWZkza4A==", "dev": true, "requires": { - "ansi-colors": "^4.1.3", "browser-stdout": "^1.3.1", - "chokidar": "^3.5.3", + "chokidar": "^4.0.1", "debug": "^4.3.5", - "diff": "^5.2.0", + "diff": "^7.0.0", "escape-string-regexp": "^4.0.0", "find-up": "^5.0.0", "glob": "^10.4.5", "he": "^1.2.0", "js-yaml": "^4.1.0", "log-symbols": "^4.1.0", - "minimatch": "^5.1.6", + "minimatch": "^9.0.5", "ms": "^2.1.3", + "picocolors": "^1.1.1", "serialize-javascript": "^6.0.2", "strip-json-comments": "^3.1.1", "supports-color": "^8.1.1", - "workerpool": "^6.5.1", + "workerpool": "^9.2.0", "yargs": "^17.7.2", "yargs-parser": "^21.1.1", "yargs-unparser": "^2.0.0" @@ -3111,12 +2874,6 @@ "skin-tone": "^2.0.0" } }, - "normalize-path": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", - "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==", - "dev": true - }, "object-assign": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", @@ -3192,16 +2949,16 @@ "minipass": "^5.0.0 || ^6.0.2 || ^7.0.0" } }, - "picomatch": { - "version": "2.3.1", - "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", - "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", + "picocolors": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz", + "integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==", "dev": true }, "prettier": { - "version": "3.4.2", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.4.2.tgz", - "integrity": "sha512-e9MewbtFo+Fevyuxn/4rrcDAaq0IYxPGLvObpQjiZBMAzB9IGmzlnG9RZy3FFas+eBMu2vA0CszMeduow5dIuQ==", + "version": "3.6.2", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.6.2.tgz", + "integrity": "sha512-I7AIg5boAr5R0FFtJ6rCfD+LFsWHp81dolrFD8S79U9tb8Az2nGrJncnMSnys+bpQJfRUzqs9hnA81OAA3hCuQ==", "dev": true }, "randombytes": { @@ -3214,13 +2971,10 @@ } }, "readdirp": { - "version": "3.6.0", - "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz", - "integrity": "sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==", - "dev": true, - "requires": { - "picomatch": "^2.2.1" - } + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-4.1.2.tgz", + "integrity": "sha512-GDhwkLfywWL2s6vEjyhri+eXmfH6j1L7JE27WhqLeYzoh/A3DBaYGEj2H/HFZCn/kMfim73FXxEJTw06WtxQwg==", + "dev": true }, "require-directory": { "version": "2.1.1", @@ -3235,9 +2989,9 @@ "dev": true }, "semver": { - "version": "7.7.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.0.tgz", - "integrity": "sha512-DrfFnPzblFmNrIZzg5RzHegbiRWg7KMR7btwi2yjHwx06zsUbO5g613sVwEV7FTwmzJu+Io0lJe2GJ3LxqpvBQ==", + "version": "7.7.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.2.tgz", + "integrity": "sha512-RF0Fw+rO5AMf9MAyaRXI4AV0Ulj5lMHqVxxdSgiVbixSCXoEmmX/jk0CuJw4+3SqroYO9VoUh+HcuJivvtJemA==", "dev": true }, "serialize-javascript": { @@ -3377,9 +3131,9 @@ } }, "supports-hyperlinks": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/supports-hyperlinks/-/supports-hyperlinks-3.1.0.tgz", - "integrity": "sha512-2rn0BZ+/f7puLOHZm1HOJfwBggfaHXUpPUSSG/SWM4TWp5KCfmNYwnC3hruy2rZlMnmWZ+QAGpZfchu3f3695A==", + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/supports-hyperlinks/-/supports-hyperlinks-3.2.0.tgz", + "integrity": "sha512-zFObLMyZeEwzAoKCyu1B91U79K2t7ApXuQfo8OuxwXLDgcKxuwM+YvcbIhm6QWqz7mHUH1TVytR1PwVVjEuMig==", "dev": true, "requires": { "has-flag": "^4.0.0", @@ -3404,25 +3158,16 @@ "thenify": ">= 3.1.0 < 4" } }, - "to-regex-range": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", - "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", - "dev": true, - "requires": { - "is-number": "^7.0.0" - } - }, "typescript": { - "version": "5.7.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.7.3.tgz", - "integrity": "sha512-84MVSjMEHP+FQRPy3pX9sTVV/INIex71s9TL2Gm5FG/WG1SqXeKyZ0k7/blY/4FdOzI12CBy1vGc4og/eus0fw==", - "devOptional": true + "version": "5.8.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.8.3.tgz", + "integrity": "sha512-p1diW6TqL9L07nNxvRMM7hMMw4c5XOo/1ibL4aAIGmSAt9slTE1Xgw5KWuof2uTOvCg9BY7ZRi+GaF+7sfgPeQ==", + "dev": true }, "undici-types": { - "version": "6.20.0", - "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.20.0.tgz", - "integrity": "sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg==", + "version": "6.21.0", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz", + "integrity": "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==", "dev": true }, "unicode-emoji-modifier-base": { @@ -3432,10 +3177,10 @@ "dev": true }, "valibot": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/valibot/-/valibot-1.0.0.tgz", - "integrity": "sha512-1Hc0ihzWxBar6NGeZv7fPLY0QuxFMyxwYR2sF1Blu7Wq7EnremwY2W02tit2ij2VJT8HcSkHAQqmFfl77f73Yw==", - "peer": true, + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/valibot/-/valibot-1.1.0.tgz", + "integrity": "sha512-Nk8lX30Qhu+9txPYTwM0cFlWLdPFsFr6LblzqIySfbZph9+BFsAHsNvHOymEviUepeIW6KFHzpX8TKhbptBXXw==", + "dev": true, "requires": {} }, "validate-npm-package-name": { @@ -3454,9 +3199,9 @@ } }, "workerpool": { - "version": "6.5.1", - "resolved": "https://registry.npmjs.org/workerpool/-/workerpool-6.5.1.tgz", - "integrity": "sha512-Fs4dNYcsdpYSAfVxhnl1L5zTksjvOJxtC5hzMNl+1t9B8hTJTdKDyZ5ju7ztgPy+ft9tBFXoOlDNiOT9WUXZlA==", + "version": "9.3.3", + "resolved": "https://registry.npmjs.org/workerpool/-/workerpool-9.3.3.tgz", + "integrity": "sha512-slxCaKbYjEdFT/o2rH9xS1hf4uRDch1w7Uo+apxhZ+sf/1d9e0ZVkn42kPNGP2dgjIx6YFvSevj0zHvbWe2jdw==", "dev": true }, "wrap-ansi": { @@ -3577,10 +3322,10 @@ "dev": true }, "zod": { - "version": "3.24.1", - "resolved": "https://registry.npmjs.org/zod/-/zod-3.24.1.tgz", - "integrity": "sha512-muH7gBL9sI1nciMZV67X5fTKKBLtwpZ5VBp1vsOQzj1MhrBZ4wlVCm3gedKZWLp0Oyel8sIGfeiz54Su+OVT+A==", - "peer": true + "version": "3.25.76", + "resolved": "https://registry.npmjs.org/zod/-/zod-3.25.76.tgz", + "integrity": "sha512-gzUt/qt81nXsFGKIFcC3YnfEAx5NkunCfnDlvuBSSFS02bcXu4Lmea0AFIUwbLWxWPx3d9p8S5QoaujKcNQxcQ==", + "dev": true } } } diff --git a/package.json b/package.json index 157fe79..d792748 100644 --- a/package.json +++ b/package.json @@ -18,9 +18,7 @@ "publish": "hammer task publish" }, "peerDependencies": { - "@sinclair/typebox": "^0.34.30", - "valibot": "^1.0.0", - "zod": "^3.24.1" + "@sinclair/typebox": "^0.34.30" }, "peerDependenciesMeta": { "zod": { @@ -37,6 +35,8 @@ "@types/node": "^22.10.2", "mocha": "^11.0.1", "prettier": "^3.4.2", - "typescript": "^5.7.2" - }, + "typescript": "^5.7.2", + "valibot": "^1.0.0", + "zod": "^3.24.1" + } } \ No newline at end of file diff --git a/src/compile/compile.ts b/src/compile/compile.ts index b8a0267..96947af 100644 --- a/src/compile/compile.ts +++ b/src/compile/compile.ts @@ -26,16 +26,15 @@ THE SOFTWARE. ---------------------------------------------------------------------------*/ -import { TypeCompiler, TypeCheck } from "@sinclair/typebox/compiler"; -import { Value } from "@sinclair/typebox/value"; -import { IsEvalSupported } from "./environment"; -import { Validator } from "./validator"; +import { TypeCompiler, TypeCheck } from '@sinclair/typebox/compiler' +import { Value } from '@sinclair/typebox/value' +import { IsEvalSupported } from './environment' +import { Validator } from './validator' -import { type TTypeBox, TypeBox } from "../typebox"; -import { type TSyntaxOptions } from "../options"; -import { type TParameter } from "../typebox"; -import * as t from "@sinclair/typebox"; -import * as g from "../guard"; +import { type TTypeBox, type TParameter, TypeBox } from '../typebox/index' +import { type TSyntaxOptions } from '../options' +import * as t from '@sinclair/typebox' +import * as g from '../guard/index' // ------------------------------------------------------------------ // CompileDynamic @@ -48,7 +47,7 @@ function CompileDynamic(type: Type, references: t.TSchem // ResolveTypeCheck // ------------------------------------------------------------------ function ResolveTypeCheck(type: Type): TypeCheck { - return IsEvalSupported() ? TypeCompiler.Compile(type) : CompileDynamic(type); + return IsEvalSupported() ? TypeCompiler.Compile(type) : CompileDynamic(type) } // ------------------------------------------------------------------ // Compile @@ -61,21 +60,11 @@ type TCompile = Result /** Compiles a type for high performance validation */ -export function Compile( - parameter: Parameter, - type: Type, - options?: TSyntaxOptions -): TCompile; +export function Compile(parameter: Parameter, type: Type, options?: TSyntaxOptions): TCompile /** Compiles a type for high performance validation */ -export function Compile( - type: Type, - options?: TSyntaxOptions -): TCompile<{}, Type>; +export function Compile(type: Type, options?: TSyntaxOptions): TCompile<{}, Type> /** Compiles a type for high performance validation */ -export function Compile( - type: Type, - options?: TSyntaxOptions -): TCompile<{}, Type>; +export function Compile(type: Type, options?: TSyntaxOptions): TCompile<{}, Type> /** Compiles a type for high performance validation */ // prettier-ignore export function Compile(...args: any[]): never { diff --git a/src/compile/index.ts b/src/compile/index.ts new file mode 100644 index 0000000..45e4dfa --- /dev/null +++ b/src/compile/index.ts @@ -0,0 +1,32 @@ +/*-------------------------------------------------------------------------- + +@sinclair/typemap + +The MIT License (MIT) + +Copyright (c) 2024-2025 Haydn Paterson (sinclair) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + +---------------------------------------------------------------------------*/ + +export * from './compile' +export * from './environment' +export * from './standard' +export * from './validator' diff --git a/src/guard/guard.ts b/src/guard/guard.ts new file mode 100644 index 0000000..de72462 --- /dev/null +++ b/src/guard/guard.ts @@ -0,0 +1,113 @@ +/*-------------------------------------------------------------------------- + +@sinclair/typemap + +The MIT License (MIT) + +Copyright (c) 2024-2025 Haydn Paterson (sinclair) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + +---------------------------------------------------------------------------*/ + +import * as t from '@sinclair/typebox' +import * as v from 'valibot' +import * as z from 'zod' + +/** Structural Type for Syntax */ +export type SyntaxType = string +/** Structural Type for TypeBox */ +export type TypeBoxType = t.TSchema +/** Structural Type for Valibot */ +export type ValibotType = v.BaseSchema> +/** Structural Type for Zod */ +export type ZodType = z.ZodTypeAny | z.ZodEffects + +// ------------------------------------------------------------------ +// Syntax +// ------------------------------------------------------------------ +/** Returns true if the given value is a Syntax type */ +export function IsSyntax(value: unknown): value is string { + return t.ValueGuard.IsString(value) +} +// ------------------------------------------------------------------ +// TypeBox +// ------------------------------------------------------------------ +/** Returns true if the given value is a TypeBox type */ +export function IsTypeBox(type: unknown): type is t.TSchema { + return t.KindGuard.IsSchema(type) +} +// ------------------------------------------------------------------ +// Valibot +// ------------------------------------------------------------------ +/** Returns true if the given value is a Valibot type */ +// prettier-ignore +export function IsValibot(type: unknown): type is v.AnySchema { + return ( + t.ValueGuard.IsObject(type) && + t.ValueGuard.HasPropertyKey(type, '~standard') && + t.ValueGuard.IsObject(type['~standard']) && + t.ValueGuard.HasPropertyKey(type['~standard'], 'vendor') && + type['~standard'].vendor === 'valibot' + ) +} +// ------------------------------------------------------------------ +// Zod +// ------------------------------------------------------------------ +/** Returns true if the given value is a Zod type */ +// prettier-ignore +export function IsZod(type: unknown): type is z.ZodTypeAny { + return ( + t.ValueGuard.IsObject(type) && + t.ValueGuard.HasPropertyKey(type, '~standard') && + t.ValueGuard.IsObject(type['~standard']) && + t.ValueGuard.HasPropertyKey(type['~standard'], 'vendor') && + type['~standard'].vendor === 'zod' + ) +} +// ------------------------------------------------------------------ +// Signature +// ------------------------------------------------------------------ +// (parameter, syntax, options) +function Signature1(args: any[]) { + return args.length === 3 && t.ValueGuard.IsObject(args[0]) && t.ValueGuard.IsString(args[1]) && t.ValueGuard.IsObject(args[2]) +} +// (syntax, options) +function Signature2(args: any[]) { + return args.length === 2 && t.ValueGuard.IsString(args[0]) && t.ValueGuard.IsObject(args[1]) +} +// (parameter, options) +function Signature3(args: any[]) { + return args.length === 2 && t.ValueGuard.IsObject(args[0]) && t.ValueGuard.IsString(args[1]) +} +// (syntax | type) +function Signature4(args: any[]) { + return args.length === 1 && (t.ValueGuard.IsString(args[0]) || t.ValueGuard.IsObject(args[0])) +} +/** Resolve common mapping signature parameters */ +// prettier-ignore +export function Signature(args: any[]): [parameter: Record, type: string | object, options: object] { + return ( + Signature1(args) ? [args[0], args[1], args[2]] : + Signature2(args) ? [{}, args[0], args[1]] : + Signature3(args) ? [args[0], args[1], {}] : + Signature4(args) ? [{}, args[0], {}] : + [{}, 'never', {}] + ) +} diff --git a/src/guard/index.ts b/src/guard/index.ts index de72462..c80b0fa 100644 --- a/src/guard/index.ts +++ b/src/guard/index.ts @@ -26,88 +26,4 @@ THE SOFTWARE. ---------------------------------------------------------------------------*/ -import * as t from '@sinclair/typebox' -import * as v from 'valibot' -import * as z from 'zod' - -/** Structural Type for Syntax */ -export type SyntaxType = string -/** Structural Type for TypeBox */ -export type TypeBoxType = t.TSchema -/** Structural Type for Valibot */ -export type ValibotType = v.BaseSchema> -/** Structural Type for Zod */ -export type ZodType = z.ZodTypeAny | z.ZodEffects - -// ------------------------------------------------------------------ -// Syntax -// ------------------------------------------------------------------ -/** Returns true if the given value is a Syntax type */ -export function IsSyntax(value: unknown): value is string { - return t.ValueGuard.IsString(value) -} -// ------------------------------------------------------------------ -// TypeBox -// ------------------------------------------------------------------ -/** Returns true if the given value is a TypeBox type */ -export function IsTypeBox(type: unknown): type is t.TSchema { - return t.KindGuard.IsSchema(type) -} -// ------------------------------------------------------------------ -// Valibot -// ------------------------------------------------------------------ -/** Returns true if the given value is a Valibot type */ -// prettier-ignore -export function IsValibot(type: unknown): type is v.AnySchema { - return ( - t.ValueGuard.IsObject(type) && - t.ValueGuard.HasPropertyKey(type, '~standard') && - t.ValueGuard.IsObject(type['~standard']) && - t.ValueGuard.HasPropertyKey(type['~standard'], 'vendor') && - type['~standard'].vendor === 'valibot' - ) -} -// ------------------------------------------------------------------ -// Zod -// ------------------------------------------------------------------ -/** Returns true if the given value is a Zod type */ -// prettier-ignore -export function IsZod(type: unknown): type is z.ZodTypeAny { - return ( - t.ValueGuard.IsObject(type) && - t.ValueGuard.HasPropertyKey(type, '~standard') && - t.ValueGuard.IsObject(type['~standard']) && - t.ValueGuard.HasPropertyKey(type['~standard'], 'vendor') && - type['~standard'].vendor === 'zod' - ) -} -// ------------------------------------------------------------------ -// Signature -// ------------------------------------------------------------------ -// (parameter, syntax, options) -function Signature1(args: any[]) { - return args.length === 3 && t.ValueGuard.IsObject(args[0]) && t.ValueGuard.IsString(args[1]) && t.ValueGuard.IsObject(args[2]) -} -// (syntax, options) -function Signature2(args: any[]) { - return args.length === 2 && t.ValueGuard.IsString(args[0]) && t.ValueGuard.IsObject(args[1]) -} -// (parameter, options) -function Signature3(args: any[]) { - return args.length === 2 && t.ValueGuard.IsObject(args[0]) && t.ValueGuard.IsString(args[1]) -} -// (syntax | type) -function Signature4(args: any[]) { - return args.length === 1 && (t.ValueGuard.IsString(args[0]) || t.ValueGuard.IsObject(args[0])) -} -/** Resolve common mapping signature parameters */ -// prettier-ignore -export function Signature(args: any[]): [parameter: Record, type: string | object, options: object] { - return ( - Signature1(args) ? [args[0], args[1], args[2]] : - Signature2(args) ? [{}, args[0], args[1]] : - Signature3(args) ? [args[0], args[1], {}] : - Signature4(args) ? [{}, args[0], {}] : - [{}, 'never', {}] - ) -} +export * from './guard' diff --git a/src/index.ts b/src/index.ts index fd63f27..aff05fb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -26,50 +26,17 @@ THE SOFTWARE. ---------------------------------------------------------------------------*/ -export { type TSyntaxOptions } from "./options"; - -// ------------------------------------------------------------------ -// Static -// ------------------------------------------------------------------ -export { type Static } from "./static"; - -// ------------------------------------------------------------------ -// Compile -// ------------------------------------------------------------------ -export * from "./compile/compile"; - -// ------------------------------------------------------------------ -// Syntax -// ------------------------------------------------------------------ -export * from "./syntax/syntax-from-syntax"; -export * from "./syntax/syntax-from-typebox"; -export * from "./syntax/syntax-from-valibot"; -export * from "./syntax/syntax-from-zod"; -export { type TSyntax, Syntax } from "./syntax/syntax"; - -// ------------------------------------------------------------------ -// TypeBox -// ------------------------------------------------------------------ -export * from "./typebox/typebox-from-syntax"; -export * from "./typebox/typebox-from-typebox"; -export * from "./typebox/typebox-from-valibot"; -export * from "./typebox/typebox-from-zod"; -export { type TTypeBox, TypeBox } from "./typebox"; - // ------------------------------------------------------------------ -// Valibot +// Infrastructure // ------------------------------------------------------------------ -export * from "./valibot/valibot-from-syntax"; -export * from "./valibot/valibot-from-typebox"; -export * from "./valibot/valibot-from-valibot"; -export * from "./valibot/valibot-from-zod"; -export { type TValibot, Valibot } from "./valibot"; +export * from './compile/index' +export * from './syntax/index' +export * from './typebox/index' +export * from './valibot/index' +export * from './zod/index' // ------------------------------------------------------------------ -// Zod +// Common // ------------------------------------------------------------------ -export * from "./zod/zod-from-syntax"; -export * from "./zod/zod-from-typebox"; -export * from "./zod/zod-from-valibot"; -export * from "./zod/zod-from-zod"; -export { type TZod, Zod } from "./zod"; +export * from './options' +export * from './static' diff --git a/src/static.ts b/src/static.ts index 32db87e..1397765 100644 --- a/src/static.ts +++ b/src/static.ts @@ -26,7 +26,7 @@ THE SOFTWARE. ---------------------------------------------------------------------------*/ -import { Validator } from './compile/validator' +import { type Validator } from './compile/validator' import * as s from '@sinclair/typebox/syntax' import * as t from '@sinclair/typebox' import * as v from 'valibot' diff --git a/src/syntax/index.ts b/src/syntax/index.ts new file mode 100644 index 0000000..34bcfcd --- /dev/null +++ b/src/syntax/index.ts @@ -0,0 +1,33 @@ +/*-------------------------------------------------------------------------- + +@sinclair/typemap + +The MIT License (MIT) + +Copyright (c) 2024-2025 Haydn Paterson (sinclair) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + +---------------------------------------------------------------------------*/ + +export * from './syntax-from-syntax' +export * from './syntax-from-typebox' +export * from './syntax-from-valibot' +export * from './syntax-from-zod' +export * from './syntax' diff --git a/src/syntax/syntax.ts b/src/syntax/syntax.ts index 10a7e1e..33f4541 100644 --- a/src/syntax/syntax.ts +++ b/src/syntax/syntax.ts @@ -26,21 +26,15 @@ THE SOFTWARE. ---------------------------------------------------------------------------*/ -import { type TSyntaxFromSyntax, SyntaxFromSyntax } from "./syntax-from-syntax"; -import { - type TSyntaxFromTypeBox, - SyntaxFromTypeBox, -} from "./syntax-from-typebox"; -import { - type TSyntaxFromValibot, - SyntaxFromValibot, -} from "./syntax-from-valibot"; -import { type TSyntaxFromZod, SyntaxFromZod } from "./syntax-from-zod"; -import { type TSyntaxOptions } from "../options"; -import { type TParameter } from "../typebox"; +import { type TSyntaxFromSyntax, SyntaxFromSyntax } from './syntax-from-syntax' +import { type TSyntaxFromTypeBox, SyntaxFromTypeBox } from './syntax-from-typebox' +import { type TSyntaxFromValibot, SyntaxFromValibot } from './syntax-from-valibot' +import { type TSyntaxFromZod, SyntaxFromZod } from './syntax-from-zod' +import { type TSyntaxOptions } from '../options' +import { type TParameter } from '../typebox/index' -import * as g from "../guard"; -import * as z from "zod"; +import * as g from '../guard/index' +import * as z from 'zod' // ------------------------------------------------------------------ // Zod @@ -56,21 +50,11 @@ export type TSyntax<_Parameter extends TParameter, Type extends object | string, )> = Result /** Creates Syntax by mapping from a remote Type */ -export function Syntax( - parameter: Parameter, - type: Type, - options?: TSyntaxOptions -): TSyntax; +export function Syntax(parameter: Parameter, type: Type, options?: TSyntaxOptions): TSyntax /** Creates Syntax by mapping from a remote Type */ -export function Syntax( - type: Type, - options?: TSyntaxOptions -): TSyntax<{}, Type>; +export function Syntax(type: Type, options?: TSyntaxOptions): TSyntax<{}, Type> /** Creates Syntax by mapping from a remote Type */ -export function Syntax( - type: Type, - options?: TSyntaxOptions -): TSyntax<{}, Type>; +export function Syntax(type: Type, options?: TSyntaxOptions): TSyntax<{}, Type> /** Creates Syntax by mapping from a remote Type */ // prettier-ignore export function Syntax(...args: any[]): never { diff --git a/src/typebox/index.ts b/src/typebox/index.ts index ffaddf3..95e440d 100644 --- a/src/typebox/index.ts +++ b/src/typebox/index.ts @@ -26,100 +26,8 @@ THE SOFTWARE. ---------------------------------------------------------------------------*/ -import { - type TTypeBoxFromSyntax, - TypeBoxFromSyntax, -} from "./typebox-from-syntax"; -import { - type TTypeBoxFromTypeBox, - TypeBoxFromTypeBox, -} from "./typebox-from-typebox"; -import { - type TTypeBoxFromValibot, - TypeBoxFromValibot, -} from "./typebox-from-valibot"; -import { type TTypeBoxFromZod, TypeBoxFromZod } from "./typebox-from-zod"; -import { type TSyntaxOptions } from "../options"; - -import * as g from "../guard"; -import * as t from "@sinclair/typebox"; - -// ------------------------------------------------------------------------------ -// -// TParameter: Shared -// -// TypeBox supports Type injection via a Context parameter. Because the Context -// only accepts types of TSchema, we need to an intermediate structure to hold -// the remote types such that they can be mapped prior to syntax parsing. -// -// ------------------------------------------------------------------------------- -export type TParameter = Record; - -// ------------------------------------------------------------------ -// ContextFromParameter -// ------------------------------------------------------------------ -// prettier-ignore -export type TContextFromParameter - } -> = Result -// prettier-ignore -export function ContextFromParameter(parameter: Parameter): TContextFromParameter { - return globalThis.Object.getOwnPropertyNames(parameter).reduce((result, key) => { - return { ...result, [key]: TypeBox(parameter[key] as never) } - }, {} as t.TProperties) as never -} - -// ------------------------------------------------------------------ -// TypeBox -// ------------------------------------------------------------------ -/** Creates a TypeBox type by mapping from a remote Type */ -// prettier-ignore -export type TTypeBox, Type> : - Type extends g.TypeBoxType ? TTypeBoxFromTypeBox : - Type extends g.ValibotType ? TTypeBoxFromValibot : - Type extends g.ZodType ? TTypeBoxFromZod : - t.TNever -)> = Result -/** Creates a TypeBox type by mapping from a remote Type */ -export function TypeBox( - parameter: Parameter, - type: Type, - options?: TSyntaxOptions -): TTypeBox; -/** Creates a TypeBox type by mapping from a remote Type */ -export function TypeBox( - type: Type, - options?: TSyntaxOptions -): TTypeBox<{}, Type>; -/** Creates a TypeBox type by mapping from a remote Type */ -// prettier-ignore -export function TypeBox(...args: any[]): never { - const [parameter, type, options] = g.Signature(args) - return ( - g.IsSyntax(type) ? TypeBoxFromSyntax(ContextFromParameter(parameter), type, options) : - g.IsTypeBox(type) ? TypeBoxFromTypeBox(type) : - g.IsValibot(type) ? TypeBoxFromValibot(type) : - g.IsZod(type) ? TypeBoxFromZod(type) : - t.Never() - ) as never -} - -/** Creates a TypeBox type from Syntax or another Type */ -export function Type( - parameter: Parameter, - type: Type, - options?: TSyntaxOptions -): TTypeBox; -/** Creates a TypeBox type from Syntax or another Type */ -export function Type( - type: Type, - options?: TSyntaxOptions -): TTypeBox<{}, Type>; -/** Creates a TypeBox type from Syntax or another Type */ -// prettier-ignore -export function Type(...args: any[]): never { - return TypeBox.apply(null, args as never) as never -} +export * from './typebox-from-syntax' +export * from './typebox-from-typebox' +export * from './typebox-from-valibot' +export * from './typebox-from-zod' +export * from './typebox' diff --git a/src/typebox/typebox-from-valibot.ts b/src/typebox/typebox-from-valibot.ts index 80383e8..7b8c739 100644 --- a/src/typebox/typebox-from-valibot.ts +++ b/src/typebox/typebox-from-valibot.ts @@ -26,21 +26,14 @@ THE SOFTWARE. ---------------------------------------------------------------------------*/ -import * as t from "@sinclair/typebox"; -import * as v from "valibot"; -import * as Guard from "../guard"; +import * as t from '@sinclair/typebox' +import * as v from 'valibot' // ------------------------------------------------------------------ // Options // ------------------------------------------------------------------ -function IsSchemaWithPipe( - type: BaseSchema -): type is v.SchemaWithPipe<[BaseSchema, ...BaseValidation[]]> { - return ( - t.ValueGuard.IsObject(type) && - t.ValueGuard.HasPropertyKey(type, "pipe") && - t.ValueGuard.IsArray(type.pipe) - ); +function IsSchemaWithPipe(type: BaseSchema): type is v.SchemaWithPipe<[BaseSchema, ...BaseValidation[]]> { + return t.ValueGuard.IsObject(type) && t.ValueGuard.HasPropertyKey(type, 'pipe') && t.ValueGuard.IsArray(type.pipe) } // prettier-ignore function Options(type: BaseSchema) { @@ -163,298 +156,181 @@ function Options(type: BaseSchema) { // ------------------------------------------------------------------ // Formats // ------------------------------------------------------------------ -t.FormatRegistry.Set( - "base64", - (value) => v.safeParse(v.pipe(v.string(), v.base64()), value).success -); -t.FormatRegistry.Set( - "bic", - (value) => v.safeParse(v.pipe(v.string(), v.bic()), value).success -); -t.FormatRegistry.Set( - "credit_card", - (value) => v.safeParse(v.pipe(v.string(), v.creditCard()), value).success -); -t.FormatRegistry.Set( - "cuid2", - (value) => v.safeParse(v.pipe(v.string(), v.cuid2()), value).success -); -t.FormatRegistry.Set( - "decimal", - (value) => v.safeParse(v.pipe(v.string(), v.decimal()), value).success -); -t.FormatRegistry.Set( - "digits", - (value) => v.safeParse(v.pipe(v.string(), v.digits()), value).success -); -t.FormatRegistry.Set( - "email", - (value) => v.safeParse(v.pipe(v.string(), v.email()), value).success -); -t.FormatRegistry.Set( - "emoji", - (value) => v.safeParse(v.pipe(v.string(), v.emoji()), value).success -); -t.FormatRegistry.Set( - "ip", - (value) => v.safeParse(v.pipe(v.string(), v.ip()), value).success -); -t.FormatRegistry.Set( - "ipv4", - (value) => v.safeParse(v.pipe(v.string(), v.ipv4()), value).success -); -t.FormatRegistry.Set( - "ipv6", - (value) => v.safeParse(v.pipe(v.string(), v.ipv6()), value).success -); -t.FormatRegistry.Set( - "iso_date", - (value) => v.safeParse(v.pipe(v.string(), v.isoDate()), value).success -); -t.FormatRegistry.Set( - "iso_date_time", - (value) => v.safeParse(v.pipe(v.string(), v.isoDateTime()), value).success -); -t.FormatRegistry.Set( - "iso_time", - (value) => v.safeParse(v.pipe(v.string(), v.isoTime()), value).success -); -t.FormatRegistry.Set( - "iso_time_second", - (value) => v.safeParse(v.pipe(v.string(), v.isoTimeSecond()), value).success -); -t.FormatRegistry.Set( - "iso_timestamp", - (value) => v.safeParse(v.pipe(v.string(), v.isoTimestamp()), value).success -); -t.FormatRegistry.Set( - "iso_week", - (value) => v.safeParse(v.pipe(v.string(), v.isoWeek()), value).success -); -t.FormatRegistry.Set( - "mac", - (value) => v.safeParse(v.pipe(v.string(), v.mac()), value).success -); -t.FormatRegistry.Set( - "mac48", - (value) => v.safeParse(v.pipe(v.string(), v.mac48()), value).success -); -t.FormatRegistry.Set( - "mac64", - (value) => v.safeParse(v.pipe(v.string(), v.mac64()), value).success -); -t.FormatRegistry.Set( - "nanoid", - (value) => v.safeParse(v.pipe(v.string(), v.nanoid()), value).success -); -t.FormatRegistry.Set( - "octal", - (value) => v.safeParse(v.pipe(v.string(), v.octal()), value).success -); -t.FormatRegistry.Set( - "ulid", - (value) => v.safeParse(v.pipe(v.string(), v.ulid()), value).success -); -t.FormatRegistry.Set( - "url", - (value) => v.safeParse(v.pipe(v.string(), v.url()), value).success -); -t.FormatRegistry.Set( - "uuid", - (value) => v.safeParse(v.pipe(v.string(), v.uuid()), value).success -); +t.FormatRegistry.Set('base64', (value) => v.safeParse(v.pipe(v.string(), v.base64()), value).success) +t.FormatRegistry.Set('bic', (value) => v.safeParse(v.pipe(v.string(), v.bic()), value).success) +t.FormatRegistry.Set('credit_card', (value) => v.safeParse(v.pipe(v.string(), v.creditCard()), value).success) +t.FormatRegistry.Set('cuid2', (value) => v.safeParse(v.pipe(v.string(), v.cuid2()), value).success) +t.FormatRegistry.Set('decimal', (value) => v.safeParse(v.pipe(v.string(), v.decimal()), value).success) +t.FormatRegistry.Set('digits', (value) => v.safeParse(v.pipe(v.string(), v.digits()), value).success) +t.FormatRegistry.Set('email', (value) => v.safeParse(v.pipe(v.string(), v.email()), value).success) +t.FormatRegistry.Set('emoji', (value) => v.safeParse(v.pipe(v.string(), v.emoji()), value).success) +t.FormatRegistry.Set('ip', (value) => v.safeParse(v.pipe(v.string(), v.ip()), value).success) +t.FormatRegistry.Set('ipv4', (value) => v.safeParse(v.pipe(v.string(), v.ipv4()), value).success) +t.FormatRegistry.Set('ipv6', (value) => v.safeParse(v.pipe(v.string(), v.ipv6()), value).success) +t.FormatRegistry.Set('iso_date', (value) => v.safeParse(v.pipe(v.string(), v.isoDate()), value).success) +t.FormatRegistry.Set('iso_date_time', (value) => v.safeParse(v.pipe(v.string(), v.isoDateTime()), value).success) +t.FormatRegistry.Set('iso_time', (value) => v.safeParse(v.pipe(v.string(), v.isoTime()), value).success) +t.FormatRegistry.Set('iso_time_second', (value) => v.safeParse(v.pipe(v.string(), v.isoTimeSecond()), value).success) +t.FormatRegistry.Set('iso_timestamp', (value) => v.safeParse(v.pipe(v.string(), v.isoTimestamp()), value).success) +t.FormatRegistry.Set('iso_week', (value) => v.safeParse(v.pipe(v.string(), v.isoWeek()), value).success) +t.FormatRegistry.Set('mac', (value) => v.safeParse(v.pipe(v.string(), v.mac()), value).success) +t.FormatRegistry.Set('mac48', (value) => v.safeParse(v.pipe(v.string(), v.mac48()), value).success) +t.FormatRegistry.Set('mac64', (value) => v.safeParse(v.pipe(v.string(), v.mac64()), value).success) +t.FormatRegistry.Set('nanoid', (value) => v.safeParse(v.pipe(v.string(), v.nanoid()), value).success) +t.FormatRegistry.Set('octal', (value) => v.safeParse(v.pipe(v.string(), v.octal()), value).success) +t.FormatRegistry.Set('ulid', (value) => v.safeParse(v.pipe(v.string(), v.ulid()), value).success) +t.FormatRegistry.Set('url', (value) => v.safeParse(v.pipe(v.string(), v.url()), value).success) +t.FormatRegistry.Set('uuid', (value) => v.safeParse(v.pipe(v.string(), v.uuid()), value).success) // ------------------------------------------------------------------ // Schema // ------------------------------------------------------------------ -type BaseValidation = v.BaseValidation>; -type BaseSchema = v.BaseSchema>; -type BaseRecordKey = v.BaseSchema< - string, - string | number | symbol, - v.BaseIssue ->; +type BaseValidation = v.BaseValidation> +type BaseSchema = v.BaseSchema> +type BaseRecordKey = v.BaseSchema> // ------------------------------------------------------------------ // Any // ------------------------------------------------------------------ -type TFromAny<_Type extends v.AnySchema> = t.Ensure; +type TFromAny<_Type extends v.AnySchema> = t.Ensure function FromAny(type: BaseSchema): t.TSchema { - return t.Any(Options(type)); + return t.Any(Options(type)) } // ------------------------------------------------------------------ // Array // ------------------------------------------------------------------ -type TFromArray = t.Ensure>>; +type TFromArray = t.Ensure>> function FromArray(type: BaseSchema): t.TSchema { - return t.Array( - FromType((type as v.ArraySchema).item), - Options(type) - ); + return t.Array(FromType((type as v.ArraySchema).item), Options(type)) } // ------------------------------------------------------------------ // BigInt // ------------------------------------------------------------------ -type TFromBigInt<_Type extends v.BigintSchema> = t.Ensure; +type TFromBigInt<_Type extends v.BigintSchema> = t.Ensure function FromBigInt(type: BaseSchema): t.TSchema { - return t.BigInt(Options(type)); + return t.BigInt(Options(type)) } // ------------------------------------------------------------------ // Blob // ------------------------------------------------------------------ -t.TypeRegistry.Set("ValibotBlob", (schema, value) => { - return v.safeParse(schema.schema, value).success; -}); -interface TBlob = v.BlobSchema> - extends t.TSchema { - [t.Kind]: "ValibotBlob"; - static: v.InferOutput; - type: Type; +t.TypeRegistry.Set('ValibotBlob', (schema, value) => { + return v.safeParse(schema.schema, value).success +}) +interface TBlob = v.BlobSchema> extends t.TSchema { + [t.Kind]: 'ValibotBlob' + static: v.InferOutput + type: Type } function _Blob(type: v.BlobSchema, options?: t.SchemaOptions): TBlob { - return t.CreateType({ [t.Kind]: "ValibotBlob", type }, options) as never; + return t.CreateType({ [t.Kind]: 'ValibotBlob', type }, options) as never } -type TFromBlob> = t.Ensure>; +type TFromBlob> = t.Ensure> function FromBlob(type: BaseSchema): t.TSchema { - return _Blob(type as v.BlobSchema, Options(type)); + return _Blob(type as v.BlobSchema, Options(type)) } // ------------------------------------------------------------------ // Boolean // ------------------------------------------------------------------ -type TFromBoolean<_Type extends v.BooleanSchema> = t.TBoolean; +type TFromBoolean<_Type extends v.BooleanSchema> = t.TBoolean function FromBoolean(type: BaseSchema): t.TSchema { - return t.Boolean(Options(type)); + return t.Boolean(Options(type)) } // ------------------------------------------------------------------ // Custom // ------------------------------------------------------------------ -t.TypeRegistry.Set( - "ValibotCustom", - (schema, value) => v.safeParse(schema.schema, value).success -); -interface TCustom< - Type extends v.CustomSchema = v.CustomSchema, -> extends t.TSchema { - [t.Kind]: "ValibotCustom"; - static: v.InferOutput; - type: Type; -} -function Custom>( - type: Type, - options?: t.SchemaOptions -): TCustom { - return t.CreateType({ [t.Kind]: "ValibotCustom", type }, options) as never; -} -type TFromCustom> = t.Ensure< - TCustom ->; +t.TypeRegistry.Set('ValibotCustom', (schema, value) => v.safeParse(schema.schema, value).success) +interface TCustom = v.CustomSchema> extends t.TSchema { + [t.Kind]: 'ValibotCustom' + static: v.InferOutput + type: Type +} +function Custom>(type: Type, options?: t.SchemaOptions): TCustom { + return t.CreateType({ [t.Kind]: 'ValibotCustom', type }, options) as never +} +type TFromCustom> = t.Ensure> function FromCustom(type: BaseSchema): t.TSchema { - return Custom(type as v.CustomSchema, Options(type)); + return Custom(type as v.CustomSchema, Options(type)) } // ------------------------------------------------------------------ // Date // ------------------------------------------------------------------ -type TFromDate<_Type extends v.DateSchema> = t.TDate; +type TFromDate<_Type extends v.DateSchema> = t.TDate function FromDate(type: BaseSchema): t.TSchema { - return t.Date(Options(type)); + return t.Date(Options(type)) } // ------------------------------------------------------------------ // Enum // ------------------------------------------------------------------ -t.TypeRegistry.Set("ValibotEnum", (schema, value) => { - return v.safeParse(schema.type, value).success; -}); -export interface TValibotEnum< - Type extends v.EnumSchema = v.EnumSchema, -> extends t.TSchema { - [t.Kind]: "ValibotEnum"; - static: v.InferOutput; - type: Type; -} -function ValibotEnum>( - type: Type, - options?: t.SchemaOptions -): TValibotEnum { - return t.CreateType({ [t.Kind]: "ValibotEnum", type }, options) as never; +t.TypeRegistry.Set('ValibotEnum', (schema, value) => { + return v.safeParse(schema.type, value).success +}) +interface TValibotEnum = v.EnumSchema> extends t.TSchema { + [t.Kind]: 'ValibotEnum' + static: v.InferOutput + type: Type +} +function ValibotEnum>(type: Type, options?: t.SchemaOptions): TValibotEnum { + return t.CreateType({ [t.Kind]: 'ValibotEnum', type }, options) as never } // prettier-ignore type TFromEnum, Result = TValibotEnum > = Result function FromEnum(type: Type): t.TSchema { - return ValibotEnum(type as never as v.EnumSchema, Options(type)); + return ValibotEnum(type as never as v.EnumSchema, Options(type)) } // ------------------------------------------------------------------ // File // ------------------------------------------------------------------ -t.TypeRegistry.Set("ValibotFile", (schema, value) => { - return v.safeParse(schema.schema, value).success; -}); -export interface TValibotFile< - Type extends v.FileSchema = v.FileSchema, -> extends t.TSchema { - [t.Kind]: "ValibotFile"; - static: v.InferOutput; - type: Type; -} -function _File( - type: v.FileSchema, - options?: t.SchemaOptions -): TValibotFile { - return t.CreateType({ [t.Kind]: "ValibotFile", type }, options) as never; -} -type TFromFile> = t.Ensure>; +t.TypeRegistry.Set('ValibotFile', (schema, value) => { + return v.safeParse(schema.schema, value).success +}) +interface TValibotFile = v.FileSchema> extends t.TSchema { + [t.Kind]: 'ValibotFile' + static: v.InferOutput + type: Type +} +function _File(type: v.FileSchema, options?: t.SchemaOptions): TValibotFile { + return t.CreateType({ [t.Kind]: 'ValibotFile', type }, options) as never +} +type TFromFile> = t.Ensure> function FromFile(type: BaseSchema): t.TSchema { - return _File(type as v.FileSchema, Options(type)); + return _File(type as v.FileSchema, Options(type)) } // ------------------------------------------------------------------ // Function // ------------------------------------------------------------------ -t.TypeRegistry.Set("ValibotFunction", (schema, value) => { - return v.safeParse(schema.schema, value).success; -}); -export interface TValibotFunction< - Type extends v.FunctionSchema = v.FunctionSchema, -> extends t.TSchema { - [t.Kind]: "ValibotFunction"; - static: v.InferOutput; - type: Type; -} -function _Function>( - type: Type, - options?: t.SchemaOptions -): TValibotFunction { - return t.CreateType({ [t.Kind]: "ValibotFunction", type }, options) as never; -} -type TFromFunction> = t.Ensure< - TValibotFunction ->; +t.TypeRegistry.Set('ValibotFunction', (schema, value) => { + return v.safeParse(schema.schema, value).success +}) +interface TValibotFunction = v.FunctionSchema> extends t.TSchema { + [t.Kind]: 'ValibotFunction' + static: v.InferOutput + type: Type +} +function _Function>(type: Type, options?: t.SchemaOptions): TValibotFunction { + return t.CreateType({ [t.Kind]: 'ValibotFunction', type }, options) as never +} +type TFromFunction> = t.Ensure> function FromFunction(type: BaseSchema): t.TSchema { - return _Function(type as v.FunctionSchema, Options(type)); + return _Function(type as v.FunctionSchema, Options(type)) } // ------------------------------------------------------------------ // Instance // ------------------------------------------------------------------ -t.TypeRegistry.Set("ValibotInstance", (schema, value) => { - return v.safeParse(schema.schema, value).success; -}); -export interface TValibotInstance< - Type extends v.InstanceSchema = v.InstanceSchema, -> extends t.TSchema { - [t.Kind]: "ValibotInstance"; - static: v.InferOutput; - type: Type; -} -function Instance>( - type: Type, - options?: t.SchemaOptions -): TValibotInstance { - return t.CreateType({ [t.Kind]: "ValibotInstance", type }, options) as never; -} -type TFromInstance> = t.Ensure< - TValibotInstance ->; +t.TypeRegistry.Set('ValibotInstance', (schema, value) => { + return v.safeParse(schema.schema, value).success +}) +interface TValibotInstance = v.InstanceSchema> extends t.TSchema { + [t.Kind]: 'ValibotInstance' + static: v.InferOutput + type: Type +} +function Instance>(type: Type, options?: t.SchemaOptions): TValibotInstance { + return t.CreateType({ [t.Kind]: 'ValibotInstance', type }, options) as never +} +type TFromInstance> = t.Ensure> function FromInstance(type: BaseSchema): t.TSchema { - return Instance(type as v.InstanceSchema, Options(type)); + return Instance(type as v.InstanceSchema, Options(type)) } // ------------------------------------------------------------------ // Intersect @@ -466,258 +342,201 @@ type TFromIntersect : t.TIntersect ) function FromIntersect(type: BaseSchema): t.TSchema { - const intersect = type as v.IntersectSchema; + const intersect = type as v.IntersectSchema return t.Intersect( intersect.options.map((option) => FromType(option)), - Options(type) - ); + Options(type), + ) } // ------------------------------------------------------------------ // Literal // ------------------------------------------------------------------ -type TFromLiteral = t.Ensure>; +type TFromLiteral = t.Ensure> function FromLiteral(type: BaseSchema): t.TSchema { - const literal = type as v.LiteralSchema; - return t.Literal(literal.literal, Options(type)); + const literal = type as v.LiteralSchema + return t.Literal(literal.literal, Options(type)) } // ------------------------------------------------------------------ // LooseObject // ------------------------------------------------------------------ type TFromLooseObject = t.Ensure< t.TObject<{ - -readonly [Key in keyof Properties]: TFromType; + -readonly [Key in keyof Properties]: TFromType }> ->; +> function FromLooseObject(type: BaseSchema): t.TSchema { - const object = type as v.LooseObjectSchema; - const keys = globalThis.Object.getOwnPropertyNames(object.entries); + const object = type as v.LooseObjectSchema + const keys = globalThis.Object.getOwnPropertyNames(object.entries) return t.Object( keys.reduce((properties, key) => { - return { ...properties, [key]: FromType(object.entries[key]) }; + return { ...properties, [key]: FromType(object.entries[key]) } }, {} as t.TProperties), - Options(type) - ); + Options(type), + ) } // ------------------------------------------------------------------ // LooseTuple // ------------------------------------------------------------------ -t.TypeRegistry.Set("ValibotLooseTuple", (schema, value) => { - return v.safeParse(schema.schema, value).success; -}); -export interface TValibotLooseTuple< - Type extends v.LooseTupleSchema = v.LooseTupleSchema< - BaseSchema[], - any - >, -> extends t.TSchema { - [t.Kind]: "ValibotLooseTuple"; - static: v.InferOutput; - type: Type; -} -function LooseTuple>( - type: Type, - schema?: t.SchemaOptions -): TValibotLooseTuple { - return t.CreateType({ [t.Kind]: "ValibotLooseTuple", type }) as never; -} -type TFromLooseTuple> = - t.Ensure>; +t.TypeRegistry.Set('ValibotLooseTuple', (schema, value) => { + return v.safeParse(schema.schema, value).success +}) +interface TValibotLooseTuple = v.LooseTupleSchema> extends t.TSchema { + [t.Kind]: 'ValibotLooseTuple' + static: v.InferOutput + type: Type +} +function LooseTuple>(type: Type, schema?: t.SchemaOptions): TValibotLooseTuple { + return t.CreateType({ [t.Kind]: 'ValibotLooseTuple', type }) as never +} +type TFromLooseTuple> = t.Ensure> function FromLooseTuple(type: BaseSchema): t.TSchema { - return LooseTuple( - type as v.LooseTupleSchema, - Options(type) - ); + return LooseTuple(type as v.LooseTupleSchema, Options(type)) } // ------------------------------------------------------------------ // Map // ------------------------------------------------------------------ -t.TypeRegistry.Set("ValibotMap", (schema, value) => { - return v.safeParse(schema.schema, value).success; -}); -export interface TValibotMap< - Type extends v.MapSchema = v.MapSchema< - BaseSchema, - BaseSchema, - any - >, -> extends t.TSchema { - [t.Kind]: "ValibotMap"; - static: v.InferOutput; - type: Type; -} -function _Map>( - type: Type, - options?: t.SchemaOptions -): TValibotMap { - return t.CreateType({ [t.Kind]: "ValibotMap", type }) as never; -} -type TFromMap> = t.Ensure< - TValibotMap ->; +t.TypeRegistry.Set('ValibotMap', (schema, value) => { + return v.safeParse(schema.schema, value).success +}) +interface TValibotMap = v.MapSchema> extends t.TSchema { + [t.Kind]: 'ValibotMap' + static: v.InferOutput + type: Type +} +function _Map>(type: Type, options?: t.SchemaOptions): TValibotMap { + return t.CreateType({ [t.Kind]: 'ValibotMap', type }) as never +} +type TFromMap> = t.Ensure> function FromMap(type: BaseSchema): t.TSchema { - return _Map(type as v.MapSchema, Options(type)); + return _Map(type as v.MapSchema, Options(type)) } // ------------------------------------------------------------------ // NaN // ------------------------------------------------------------------ -t.TypeRegistry.Set("ValibotNaN", (schema, value) => { - return v.safeParse(schema.schema, value).success; -}); -export interface TValibotNaN = v.NanSchema> - extends t.TSchema { - [t.Kind]: "ValibotNaN"; - static: v.InferOutput; - type: Type; -} -function _NaN>( - type: Type, - options?: t.SchemaOptions -): TValibotNaN { - return t.CreateType({ [t.Kind]: "ValibotNaN", type }, options) as never; -} -type TFromNaN> = t.Ensure>; +t.TypeRegistry.Set('ValibotNaN', (schema, value) => { + return v.safeParse(schema.schema, value).success +}) +interface TValibotNaN = v.NanSchema> extends t.TSchema { + [t.Kind]: 'ValibotNaN' + static: v.InferOutput + type: Type +} +function _NaN>(type: Type, options?: t.SchemaOptions): TValibotNaN { + return t.CreateType({ [t.Kind]: 'ValibotNaN', type }, options) as never +} +type TFromNaN> = t.Ensure> function FromNaN(type: BaseSchema): t.TSchema { - return _NaN(type as v.NanSchema, Options(type)); + return _NaN(type as v.NanSchema, Options(type)) } // ------------------------------------------------------------------ // Never // ------------------------------------------------------------------ -type TFromNever<_Type extends v.NeverSchema> = t.TNever; +type TFromNever<_Type extends v.NeverSchema> = t.TNever function FromNever(type: BaseSchema): t.TSchema { - return t.Never(Options(type)); + return t.Never(Options(type)) } // ------------------------------------------------------------------ // NonNullable // ------------------------------------------------------------------ -type TFromNonNullable = t.TExclude< - TFromType, - t.TNull ->; +type TFromNonNullable = t.TExclude, t.TNull> function FromNonNullable(type: BaseSchema): t.TSchema { - const non_nullable = type as v.NonNullableSchema; - return t.Exclude(FromType(non_nullable.wrapped), t.Null(), Options(type)); + const non_nullable = type as v.NonNullableSchema + return t.Exclude(FromType(non_nullable.wrapped), t.Null(), Options(type)) } // ------------------------------------------------------------------ // NonNullish // ------------------------------------------------------------------ -type TFromNonNullish = t.TExclude< - TFromType, - t.TUnion<[t.TNull, t.TUndefined]> ->; +type TFromNonNullish = t.TExclude, t.TUnion<[t.TNull, t.TUndefined]>> function FromNonNullish(type: BaseSchema): t.TSchema { - const non_nullish = type as v.NonNullishSchema; - return t.Exclude( - FromType(non_nullish.wrapped), - t.Union([t.Null(), t.Undefined()]), - Options(type) - ); + const non_nullish = type as v.NonNullishSchema + return t.Exclude(FromType(non_nullish.wrapped), t.Union([t.Null(), t.Undefined()]), Options(type)) } // ------------------------------------------------------------------ // NonOptional // ------------------------------------------------------------------ -type TFromNonOptional< - Type extends BaseSchema, - Result extends TFromType = TFromType, -> = t.TOptionalWithFlag; +type TFromNonOptional = TFromType> = t.TOptionalWithFlag function FromNonOptional(type: BaseSchema): t.TSchema { - const non_optional = type as v.NonOptionalSchema; - return t.Optional(FromType(non_optional.wrapped), false); + const non_optional = type as v.NonOptionalSchema + return t.Optional(FromType(non_optional.wrapped), false) } // ------------------------------------------------------------------ // Null // ------------------------------------------------------------------ -type TFromNull<_Type extends v.NullSchema> = t.TNull; +type TFromNull<_Type extends v.NullSchema> = t.TNull function FromNull(type: BaseSchema) { - return t.Null(Options(type)); + return t.Null(Options(type)) } // ------------------------------------------------------------------ // Nullable // ------------------------------------------------------------------ -type TFromNullable = t.TUnion< - [TFromType, t.TNull] ->; +type TFromNullable = t.TUnion<[TFromType, t.TNull]> function FromNullable(type: BaseSchema) { - const nullable = type as v.NullableSchema; - return t.Union([t.Null(), FromType(nullable.wrapped)], Options(type)); + const nullable = type as v.NullableSchema + return t.Union([t.Null(), FromType(nullable.wrapped)], Options(type)) } // ------------------------------------------------------------------ // Nullish // ------------------------------------------------------------------ -type TFromNullish = t.TUnion< - [TFromType, t.TNull, t.TUndefined] ->; +type TFromNullish = t.TUnion<[TFromType, t.TNull, t.TUndefined]> function FromNullish(type: BaseSchema) { - const nullish = type as v.NullishSchema; - return t.Union( - [FromType(nullish.wrapped), t.Null(), t.Undefined()], - Options(type) - ); + const nullish = type as v.NullishSchema + return t.Union([FromType(nullish.wrapped), t.Null(), t.Undefined()], Options(type)) } // ------------------------------------------------------------------ // Number // ------------------------------------------------------------------ -type TFromNumber<_Type extends v.NumberSchema> = t.TNumber; +type TFromNumber<_Type extends v.NumberSchema> = t.TNumber function FromNumber(type: BaseSchema): t.TSchema { - return t.Number(Options(type)); + return t.Number(Options(type)) } // ------------------------------------------------------------------ // Object // ------------------------------------------------------------------ type TFromObject = t.Ensure< t.TObject<{ - -readonly [Key in keyof Properties]: TFromType; + -readonly [Key in keyof Properties]: TFromType }> ->; +> function FromObject(type: BaseSchema): t.TSchema { - const object = type as v.ObjectSchema; - const keys = globalThis.Object.getOwnPropertyNames(object.entries); + const object = type as v.ObjectSchema + const keys = globalThis.Object.getOwnPropertyNames(object.entries) return t.Object( keys.reduce((properties, key) => { - return { ...properties, [key]: FromType(object.entries[key]) }; + return { ...properties, [key]: FromType(object.entries[key]) } }, {} as t.TProperties), - Options(type) - ); + Options(type), + ) } // ------------------------------------------------------------------ // ObjectWithRest // ------------------------------------------------------------------ -type TFromObjectWithRest< - Properties extends v.ObjectEntries, - _Rest extends BaseSchema, -> = t.Ensure< +type TFromObjectWithRest = t.Ensure< t.TObject<{ - -readonly [Key in keyof Properties]: TFromType; + -readonly [Key in keyof Properties]: TFromType }> ->; +> function FromObjectWithRest(type: BaseSchema): t.TSchema { - const object = type as v.ObjectWithRestSchema< - v.ObjectEntries, - BaseSchema, - any - >; - const keys = globalThis.Object.getOwnPropertyNames(object.entries); + const object = type as v.ObjectWithRestSchema + const keys = globalThis.Object.getOwnPropertyNames(object.entries) return t.Object( keys.reduce((properties, key) => { - return { ...properties, [key]: FromType(object.entries[key]) }; + return { ...properties, [key]: FromType(object.entries[key]) } }, {} as t.TProperties), - { ...Options(type), additionalProperties: FromType(object.rest) } - ); + { ...Options(type), additionalProperties: FromType(object.rest) }, + ) } // ------------------------------------------------------------------ // Optional // ------------------------------------------------------------------ -type TFromOptional< - Type extends BaseSchema, - Result extends TFromType = TFromType, -> = t.TOptionalWithFlag; +type TFromOptional = TFromType> = t.TOptionalWithFlag function FromOptional(type: BaseSchema): t.TSchema { - const optional = type as v.OptionalSchema; - return t.Optional(FromType(optional.wrapped)); + const optional = type as v.OptionalSchema + return t.Optional(FromType(optional.wrapped)) } // ------------------------------------------------------------------ // PickList // ------------------------------------------------------------------ -type PickListOption = string | number | bigint; +type PickListOption = string | number | bigint // prettier-ignore type TFromPickList = ( Options extends [infer Left extends PickListOption, ...infer Right extends PickListOption[]] @@ -729,90 +548,73 @@ type TFromPickList ) function FromPickList(type: BaseSchema): t.TSchema { - const picklist = type as v.PicklistSchema; + const picklist = type as v.PicklistSchema return t.Union( picklist.options.map((option) => t.Literal(option as t.TLiteralValue)), - Options(type) - ); + Options(type), + ) } // ------------------------------------------------------------------ // Promise // ------------------------------------------------------------------ -t.TypeRegistry.Set("ValibotPromise", (schema, value) => { - return v.safeParse(schema.schema, value).success; -}); -export interface TValibotPromise< - Type extends v.PromiseSchema = v.PromiseSchema, -> extends t.TSchema { - [t.Kind]: "ValibotPromise"; - static: v.InferOutput; - type: Type; -} -function _Promise>( - type: Type, - options?: t.SchemaOptions -): TValibotPromise { - return t.CreateType({ [t.Kind]: "ValibotPromise", type }, options) as never; -} -type TFromPromise> = t.Ensure< - TValibotPromise ->; +t.TypeRegistry.Set('ValibotPromise', (schema, value) => { + return v.safeParse(schema.schema, value).success +}) +interface TValibotPromise = v.PromiseSchema> extends t.TSchema { + [t.Kind]: 'ValibotPromise' + static: v.InferOutput + type: Type +} +function _Promise>(type: Type, options?: t.SchemaOptions): TValibotPromise { + return t.CreateType({ [t.Kind]: 'ValibotPromise', type }, options) as never +} +type TFromPromise> = t.Ensure> function FromPromise(type: BaseSchema): t.TSchema { - return _Promise(type as v.PromiseSchema, Options(type)); + return _Promise(type as v.PromiseSchema, Options(type)) } // ------------------------------------------------------------------ // Record // ------------------------------------------------------------------ -type TFromRecord< - Key extends BaseRecordKey, - Value extends BaseSchema, -> = t.Ensure, TFromType>>; +type TFromRecord = t.Ensure, TFromType>> function FromRecord(type: BaseSchema) { - const record = type as v.RecordSchema; - return t.Record(FromType(record.key), FromType(record.value), Options(type)); + const record = type as v.RecordSchema + return t.Record(FromType(record.key), FromType(record.value), Options(type)) } // ------------------------------------------------------------------ // Set // ------------------------------------------------------------------ -t.TypeRegistry.Set("ValibotSet", (schema, value) => { - return v.safeParse(schema.schema, value).success; -}); -export interface TValibotSet< - Type extends v.SetSchema = v.SetSchema, -> extends t.TSchema { - [t.Kind]: "ValibotSet"; - static: v.InferOutput extends infer Result ? Result : never; - type: Type; -} -function Set>( - type: Type, - options?: t.SchemaOptions -): TValibotSet { - return t.CreateType({ [t.Kind]: "ValibotSet", type }, options) as never; -} -type TFromSet> = t.Ensure< - TValibotSet ->; +t.TypeRegistry.Set('ValibotSet', (schema, value) => { + return v.safeParse(schema.schema, value).success +}) +interface TValibotSet = v.SetSchema> extends t.TSchema { + [t.Kind]: 'ValibotSet' + static: v.InferOutput extends infer Result ? Result : never + type: Type +} +function Set>(type: Type, options?: t.SchemaOptions): TValibotSet { + return t.CreateType({ [t.Kind]: 'ValibotSet', type }, options) as never +} +type TFromSet> = t.Ensure> function FromSet(type: BaseSchema): t.TSchema { - return Set(type as v.SetSchema); + return Set(type as v.SetSchema) } // ------------------------------------------------------------------ // StrictObject // ------------------------------------------------------------------ type TFromStrictObject = t.Ensure< t.TObject<{ - -readonly [Key in keyof Properties]: TFromType; + -readonly [Key in keyof Properties]: TFromType }> ->; +> function FromStrictObject(type: BaseSchema): t.TSchema { - const object = type as v.StrictObjectSchema; - const keys = globalThis.Object.getOwnPropertyNames(object.entries); + const object = type as v.StrictObjectSchema + const keys = globalThis.Object.getOwnPropertyNames(object.entries) return t.Object( keys.reduce((properties, key) => { - return { ...properties, [key]: FromType(object.entries[key]) }; + return { ...properties, [key]: FromType(object.entries[key]) } }, {} as t.TProperties), - { ...Options(type), additionalProperties: false } - ); + { ...Options(type), additionalProperties: false }, + ) } // ------------------------------------------------------------------ // StrictTuple @@ -824,25 +626,23 @@ type TFromStrictTuple ) function FromStrictTuple(type: BaseSchema): t.TSchema { - const tuple = type as v.StrictTupleSchema; - const items = globalThis.Array.isArray(tuple.items) - ? tuple.items.map((item) => FromType(item)) - : []; - return t.Tuple(items, Options(type)); + const tuple = type as v.StrictTupleSchema + const items = globalThis.Array.isArray(tuple.items) ? tuple.items.map((item) => FromType(item)) : [] + return t.Tuple(items, Options(type)) } // ------------------------------------------------------------------ // String // ------------------------------------------------------------------ -type TFromString<_Type extends v.StringSchema> = t.TString; +type TFromString<_Type extends v.StringSchema> = t.TString function FromString(type: BaseSchema): t.TSchema { - return t.String(Options(type)); + return t.String(Options(type)) } // ------------------------------------------------------------------ // Symbol // ------------------------------------------------------------------ -type TFromSymbol<_Type extends v.SymbolSchema> = t.TSymbol; +type TFromSymbol<_Type extends v.SymbolSchema> = t.TSymbol function FromSymbol(type: BaseSchema): t.TSchema { - return t.Symbol(Options(type)); + return t.Symbol(Options(type)) } // ------------------------------------------------------------------ // Tuple @@ -854,65 +654,42 @@ type TFromTuple = ( : t.TTuple ) function FromTuple(type: BaseSchema): t.TSchema { - const tuple = type as v.TupleSchema; - const items = globalThis.Array.isArray(tuple.items) - ? tuple.items.map((item) => FromType(item)) - : []; - return t.Tuple(items, Options(type)); + const tuple = type as v.TupleSchema + const items = globalThis.Array.isArray(tuple.items) ? tuple.items.map((item) => FromType(item)) : [] + return t.Tuple(items, Options(type)) } // ------------------------------------------------------------------ // TupleWithRest // ------------------------------------------------------------------ -t.TypeRegistry.Set("ValibotTupleWithRest", (schema, value) => { - return v.safeParse(schema.schema, value).success; -}); -interface TTupleWithRest< - Type extends v.TupleWithRestSchema< - BaseSchema[], - BaseSchema, - any - > = v.TupleWithRestSchema, -> extends t.TSchema { - [t.Kind]: "ValibotTupleWithRest"; - static: v.InferOutput; - type: Type; -} -function TupleWithRest< - Type extends v.TupleWithRestSchema, ->(type: Type, options?: t.SchemaOptions): TTupleWithRest { - return t.CreateType( - { [t.Kind]: "ValibotTupleWithRest", type }, - Options(type) - ) as never; -} -type TFromTupleWithRest< - Type extends v.TupleWithRestSchema, -> = t.Ensure>; +t.TypeRegistry.Set('ValibotTupleWithRest', (schema, value) => { + return v.safeParse(schema.schema, value).success +}) +interface TTupleWithRest = v.TupleWithRestSchema> extends t.TSchema { + [t.Kind]: 'ValibotTupleWithRest' + static: v.InferOutput + type: Type +} +function TupleWithRest>(type: Type, options?: t.SchemaOptions): TTupleWithRest { + return t.CreateType({ [t.Kind]: 'ValibotTupleWithRest', type }, Options(type)) as never +} +type TFromTupleWithRest> = t.Ensure> function FromTupleWithRest(type: BaseSchema): t.TSchema { - return TupleWithRest( - type as v.TupleWithRestSchema, - Options(type) - ); + return TupleWithRest(type as v.TupleWithRestSchema, Options(type)) } // ------------------------------------------------------------------ // Undefined // ------------------------------------------------------------------ -type TFromUndefined<_Type extends v.UndefinedSchema> = t.TUndefined; +type TFromUndefined<_Type extends v.UndefinedSchema> = t.TUndefined function FromUndefined(type: BaseSchema): t.TSchema { - return t.Undefined(Options(type)); + return t.Undefined(Options(type)) } // ------------------------------------------------------------------ // Undefinable // ------------------------------------------------------------------ -type TFromUndefinedable = t.TUnion< - [TFromType, t.TUndefined] ->; +type TFromUndefinedable = t.TUnion<[TFromType, t.TUndefined]> function FromUndefinedable(type: BaseSchema): t.TSchema { - const undefinedable = type as v.UndefinedableSchema; - return t.Union( - [FromType(undefinedable.wrapped), t.Undefined()], - Options(type) - ); + const undefinedable = type as v.UndefinedableSchema + return t.Union([FromType(undefinedable.wrapped), t.Undefined()], Options(type)) } // ------------------------------------------------------------------ // Union @@ -924,57 +701,40 @@ type TFromUnion = ( : t.TUnion ) function FromUnion(type: BaseSchema): t.TSchema { - const variants = (type as v.UnionSchema).options.map( - (option) => FromType(option) - ); - return t.Union(variants, Options(type)); + const variants = (type as v.UnionSchema).options.map((option) => FromType(option)) + return t.Union(variants, Options(type)) } // ------------------------------------------------------------------ // Unknown // ------------------------------------------------------------------ -type TFromUnknown<_Type extends v.UnknownSchema> = t.TUnknown; +type TFromUnknown<_Type extends v.UnknownSchema> = t.TUnknown function FromUnknown(type: BaseSchema): t.TSchema { - return t.Unknown(Options(type)); + return t.Unknown(Options(type)) } // ------------------------------------------------------------------ // Variant // ------------------------------------------------------------------ -t.TypeRegistry.Set("ValibotVariant", (schema, value) => { - return v.safeParse(schema.schema, value).success; -}); -interface TVariant< - Type extends v.VariantSchema< - string, - v.VariantOptions, - any - > = v.VariantSchema, any>, -> extends t.TSchema { - [t.Kind]: "ValibotVariant"; - static: v.InferOutput; - type: Type; -} -function Variant< - Type extends v.VariantSchema, any>, ->(type: Type): TVariant { - return t.CreateType( - { [t.Kind]: "ValibotVariant", type }, - Options(type) - ) as never; -} -type TFromVariant< - Type extends v.VariantSchema, any>, -> = t.Ensure>; +t.TypeRegistry.Set('ValibotVariant', (schema, value) => { + return v.safeParse(schema.schema, value).success +}) +interface TVariant, any> = v.VariantSchema, any>> extends t.TSchema { + [t.Kind]: 'ValibotVariant' + static: v.InferOutput + type: Type +} +function Variant, any>>(type: Type): TVariant { + return t.CreateType({ [t.Kind]: 'ValibotVariant', type }, Options(type)) as never +} +type TFromVariant, any>> = t.Ensure> function FromVariant(type: BaseSchema): t.TSchema { - return Variant( - type as v.VariantSchema, any> - ); + return Variant(type as v.VariantSchema, any>) } // ------------------------------------------------------------------ // Void // ------------------------------------------------------------------ -type TFromVoid<_Type extends v.VoidSchema> = t.TVoid; +type TFromVoid<_Type extends v.VoidSchema> = t.TVoid function FromVoid(type: BaseSchema): t.TSchema { - return t.Void(Options(type)); + return t.Void(Options(type)) } // ------------------------------------------------------------------ // Type diff --git a/src/typebox/typebox.ts b/src/typebox/typebox.ts new file mode 100644 index 0000000..143224a --- /dev/null +++ b/src/typebox/typebox.ts @@ -0,0 +1,102 @@ +/*-------------------------------------------------------------------------- + +@sinclair/typemap + +The MIT License (MIT) + +Copyright (c) 2024-2025 Haydn Paterson (sinclair) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + +---------------------------------------------------------------------------*/ + +import { type TTypeBoxFromSyntax, TypeBoxFromSyntax } from './typebox-from-syntax' +import { type TTypeBoxFromTypeBox, TypeBoxFromTypeBox } from './typebox-from-typebox' +import { type TTypeBoxFromValibot, TypeBoxFromValibot } from './typebox-from-valibot' +import { type TTypeBoxFromZod, TypeBoxFromZod } from './typebox-from-zod' +import { type TSyntaxOptions } from '../options' + +import * as g from '../guard/index' +import * as t from '@sinclair/typebox' + +// ------------------------------------------------------------------------------ +// +// TParameter: Shared +// +// TypeBox supports Type injection via a Context parameter. Because the Context +// only accepts types of TSchema, we need to an intermediate structure to hold +// the remote types such that they can be mapped prior to syntax parsing. +// +// ------------------------------------------------------------------------------- +export type TParameter = Record + +// ------------------------------------------------------------------ +// ContextFromParameter +// ------------------------------------------------------------------ +// prettier-ignore +export type TContextFromParameter + } +> = Result +// prettier-ignore +export function ContextFromParameter(parameter: Parameter): TContextFromParameter { + return globalThis.Object.getOwnPropertyNames(parameter).reduce((result, key) => { + return { ...result, [key]: TypeBox(parameter[key] as never) } + }, {} as t.TProperties) as never +} + +// ------------------------------------------------------------------ +// TypeBox +// ------------------------------------------------------------------ +/** Creates a TypeBox type by mapping from a remote Type */ +// prettier-ignore +export type TTypeBox, Type> : + Type extends g.TypeBoxType ? TTypeBoxFromTypeBox : + Type extends g.ValibotType ? TTypeBoxFromValibot : + Type extends g.ZodType ? TTypeBoxFromZod : + t.TNever +)> = Result +/** Creates a TypeBox type by mapping from a remote Type */ +export function TypeBox(parameter: Parameter, type: Type, options?: TSyntaxOptions): TTypeBox +/** Creates a TypeBox type by mapping from a remote Type */ +export function TypeBox(type: Type, options?: TSyntaxOptions): TTypeBox<{}, Type> +/** Creates a TypeBox type by mapping from a remote Type */ +// prettier-ignore +export function TypeBox(...args: any[]): never { + const [parameter, type, options] = g.Signature(args) + return ( + g.IsSyntax(type) ? TypeBoxFromSyntax(ContextFromParameter(parameter), type, options) : + g.IsTypeBox(type) ? TypeBoxFromTypeBox(type) : + g.IsValibot(type) ? TypeBoxFromValibot(type) : + g.IsZod(type) ? TypeBoxFromZod(type) : + t.Never() + ) as never +} + +// /** Creates a TypeBox type from Syntax or another Type */ +// export function Type(parameter: Parameter, type: Type, options?: TSyntaxOptions): TTypeBox +// /** Creates a TypeBox type from Syntax or another Type */ +// export function Type(type: Type, options?: TSyntaxOptions): TTypeBox<{}, Type> +// /** Creates a TypeBox type from Syntax or another Type */ +// // prettier-ignore +// export function Type(...args: any[]): never { +// return TypeBox.apply(null, args as never) as never +// } diff --git a/src/valibot/index.ts b/src/valibot/index.ts index d1497a5..926f2bf 100644 --- a/src/valibot/index.ts +++ b/src/valibot/index.ts @@ -26,70 +26,8 @@ THE SOFTWARE. ---------------------------------------------------------------------------*/ -import { - type TValibotFromSyntax, - ValibotFromSyntax, -} from "./valibot-from-syntax"; -import { - type TValibotFromTypeBox, - ValibotFromTypeBox, -} from "./valibot-from-typebox"; -import { - type TValibotFromValibot, - ValibotFromValibot, -} from "./valibot-from-valibot"; -import { type TValibotFromZod, ValibotFromZod } from "./valibot-from-zod"; -import { type TSyntaxOptions } from "../options"; - -import { - type TParameter, - type TContextFromParameter, - ContextFromParameter, -} from "../typebox"; - -import * as g from "../guard"; -import * as t from "@sinclair/typebox"; -import * as v from "valibot"; -import * as c from "./common"; - -// ------------------------------------------------------------------ -// Valibot -// ------------------------------------------------------------------ -/** Creates a Valibot type by mapping from a remote Type */ -// prettier-ignore -export type TValibot, Type> : - Type extends t.TSchema ? TValibotFromTypeBox : - Type extends g.ValibotType ? TValibotFromValibot : - Type extends g.ZodType ? TValibotFromZod : - v.NeverSchema -)> = Result - -/** Creates a Valibot type by mapping from a remote Type */ -export function Valibot( - parameter: Parameter, - type: Type, - options?: TSyntaxOptions -): TValibot; -/** Creates a Valibot type by mapping from a remote Type */ -export function Valibot( - type: Type, - options?: TSyntaxOptions -): TValibot<{}, Type>; -/** Creates a Valibot type by mapping from a remote Type */ -export function Valibot( - type: Type, - options?: TSyntaxOptions -): TValibot<{}, Type>; -/** Creates a Valibot type by mapping from a remote Type */ -// prettier-ignore -export function Valibot(...args: any[]): never { - const [parameter, type, options] = g.Signature(args) - return ( - g.IsSyntax(type) ? ValibotFromSyntax(ContextFromParameter(parameter), type, options) : - g.IsTypeBox(type) ? ValibotFromTypeBox(type) : - g.IsValibot(type) ? ValibotFromValibot(type) : - g.IsZod(type) ? ValibotFromZod(type as any) : - v.never() - ) as never -} +export * from './valibot-from-syntax' +export * from './valibot-from-typebox' +export * from './valibot-from-valibot' +export * from './valibot-from-zod' +export * from './valibot' diff --git a/src/valibot/valibot.ts b/src/valibot/valibot.ts new file mode 100644 index 0000000..852539c --- /dev/null +++ b/src/valibot/valibot.ts @@ -0,0 +1,72 @@ +/*-------------------------------------------------------------------------- + +@sinclair/typemap + +The MIT License (MIT) + +Copyright (c) 2024-2025 Haydn Paterson (sinclair) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + +---------------------------------------------------------------------------*/ + +import { type TValibotFromSyntax, ValibotFromSyntax } from './valibot-from-syntax' +import { type TValibotFromTypeBox, ValibotFromTypeBox } from './valibot-from-typebox' +import { type TValibotFromValibot, ValibotFromValibot } from './valibot-from-valibot' +import { type TValibotFromZod, ValibotFromZod } from './valibot-from-zod' +import { type TSyntaxOptions } from '../options' + +import { type TParameter, type TContextFromParameter, ContextFromParameter } from '../typebox/index' + +import * as g from '../guard/index' +import * as t from '@sinclair/typebox' +import * as v from 'valibot' +import * as c from './common' + +// ------------------------------------------------------------------ +// Valibot +// ------------------------------------------------------------------ +/** Creates a Valibot type by mapping from a remote Type */ +// prettier-ignore +export type TValibot, Type> : + Type extends t.TSchema ? TValibotFromTypeBox : + Type extends g.ValibotType ? TValibotFromValibot : + Type extends g.ZodType ? TValibotFromZod : + v.NeverSchema +)> = Result + +/** Creates a Valibot type by mapping from a remote Type */ +export function Valibot(parameter: Parameter, type: Type, options?: TSyntaxOptions): TValibot +/** Creates a Valibot type by mapping from a remote Type */ +export function Valibot(type: Type, options?: TSyntaxOptions): TValibot<{}, Type> +/** Creates a Valibot type by mapping from a remote Type */ +export function Valibot(type: Type, options?: TSyntaxOptions): TValibot<{}, Type> +/** Creates a Valibot type by mapping from a remote Type */ +// prettier-ignore +export function Valibot(...args: any[]): never { + const [parameter, type, options] = g.Signature(args) + return ( + g.IsSyntax(type) ? ValibotFromSyntax(ContextFromParameter(parameter), type, options) : + g.IsTypeBox(type) ? ValibotFromTypeBox(type) : + g.IsValibot(type) ? ValibotFromValibot(type) : + g.IsZod(type) ? ValibotFromZod(type as any) : + v.never() + ) as never +} diff --git a/src/zod/index.ts b/src/zod/index.ts index 517ae93..170d038 100644 --- a/src/zod/index.ts +++ b/src/zod/index.ts @@ -26,59 +26,8 @@ THE SOFTWARE. ---------------------------------------------------------------------------*/ -import { type TZodFromSyntax, ZodFromSyntax } from "./zod-from-syntax"; -import { type TZodFromTypeBox, ZodFromTypeBox } from "./zod-from-typebox"; -import { type TZodFromValibot, ZodFromValibot } from "./zod-from-valibot"; -import { type TZodFromZod, ZodFromZod } from "./zod-from-zod"; -import { type TSyntaxOptions } from "../options"; - -import { - type TParameter, - type TContextFromParameter, - ContextFromParameter, -} from "../typebox"; - -import * as g from "../guard"; -import * as z from "zod"; - -// ------------------------------------------------------------------ -// Zod -// ------------------------------------------------------------------ -/** Creates a Zod type by mapping from a remote Type */ -// prettier-ignore -export type TZod = ( - Type extends g.SyntaxType ? TZodFromSyntax, Type> : - Type extends g.TypeBoxType ? TZodFromTypeBox : - Type extends g.ValibotType ? TZodFromValibot : - Type extends g.ZodType ? TZodFromZod : - z.ZodNever -)> = Result - -/** Creates a Zod type by mapping from a remote Type */ -export function Zod( - parameter: Parameter, - type: Type, - options?: TSyntaxOptions -): TZod; -/** Creates a Zod type by mapping from a remote Type */ -export function Zod( - type: Type, - options?: TSyntaxOptions -): TZod<{}, Type>; -/** Creates a Zod type by mapping from a remote Type */ -export function Zod( - type: Type, - options?: TSyntaxOptions -): TZod<{}, Type>; -/** Creates a Zod type by mapping from a remote Type */ -// prettier-ignore -export function Zod(...args: any[]): never { - const [parameter, type, options] = g.Signature(args) - return ( - g.IsSyntax(type) ? ZodFromSyntax(ContextFromParameter(parameter), type, options) : - g.IsTypeBox(type) ? ZodFromTypeBox(type) : - g.IsValibot(type) ? ZodFromValibot(type) : - g.IsZod(type) ? ZodFromZod(type) : - z.never() - ) as never -} +export * from './zod-from-syntax' +export * from './zod-from-typebox' +export * from './zod-from-valibot' +export * from './zod-from-zod' +export * from './zod' diff --git a/src/zod/zod.ts b/src/zod/zod.ts new file mode 100644 index 0000000..3b6298d --- /dev/null +++ b/src/zod/zod.ts @@ -0,0 +1,70 @@ +/*-------------------------------------------------------------------------- + +@sinclair/typemap + +The MIT License (MIT) + +Copyright (c) 2024-2025 Haydn Paterson (sinclair) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + +---------------------------------------------------------------------------*/ + +import { type TZodFromSyntax, ZodFromSyntax } from './zod-from-syntax' +import { type TZodFromTypeBox, ZodFromTypeBox } from './zod-from-typebox' +import { type TZodFromValibot, ZodFromValibot } from './zod-from-valibot' +import { type TZodFromZod, ZodFromZod } from './zod-from-zod' +import { type TSyntaxOptions } from '../options' + +import { type TParameter, type TContextFromParameter, ContextFromParameter } from '../typebox/index' + +import * as g from '../guard/index' +import * as z from 'zod' + +// ------------------------------------------------------------------ +// Zod +// ------------------------------------------------------------------ +/** Creates a Zod type by mapping from a remote Type */ +// prettier-ignore +export type TZod = ( + Type extends g.SyntaxType ? TZodFromSyntax, Type> : + Type extends g.TypeBoxType ? TZodFromTypeBox : + Type extends g.ValibotType ? TZodFromValibot : + Type extends g.ZodType ? TZodFromZod : + z.ZodNever +)> = Result + +/** Creates a Zod type by mapping from a remote Type */ +export function Zod(parameter: Parameter, type: Type, options?: TSyntaxOptions): TZod +/** Creates a Zod type by mapping from a remote Type */ +export function Zod(type: Type, options?: TSyntaxOptions): TZod<{}, Type> +/** Creates a Zod type by mapping from a remote Type */ +export function Zod(type: Type, options?: TSyntaxOptions): TZod<{}, Type> +/** Creates a Zod type by mapping from a remote Type */ +// prettier-ignore +export function Zod(...args: any[]): never { + const [parameter, type, options] = g.Signature(args) + return ( + g.IsSyntax(type) ? ZodFromSyntax(ContextFromParameter(parameter), type, options) : + g.IsTypeBox(type) ? ZodFromTypeBox(type) : + g.IsValibot(type) ? ZodFromValibot(type) : + g.IsZod(type) ? ZodFromZod(type) : + z.never() + ) as never +} diff --git a/task/build/package/build.ts b/task/build/package/build.ts index f5d35ed..06be894 100644 --- a/task/build/package/build.ts +++ b/task/build/package/build.ts @@ -32,7 +32,7 @@ import { createPackageJson } from './create-package-json' /** Builds package.json and redirect directories */ export async function build(target: string) { console.log('building...package.json') - const submodules = ['typebox', 'valibot', 'zod', 'guard'] as string[] + const submodules = ['compile', 'guard', 'typebox', 'valibot', 'zod'] as string[] await createPackageJsonRedirect(target, submodules) await createPackageJson(target, submodules) } diff --git a/tsconfig.json b/tsconfig.json index ac0dc92..744cda3 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,7 +5,13 @@ "moduleResolution": "Node", "baseUrl": ".", "paths": { - "@sinclair/typemap": ["src/index.ts"] + "@sinclair/typemap/compile": ["src/compile/index.ts"], + "@sinclair/typemap/guard": ["src/guard/index.ts"], + "@sinclair/typemap/typebox": ["src/typebox/index.ts"], + "@sinclair/typemap/valibot": ["src/valibot/index.ts"], + "@sinclair/typemap/zod": ["src/zod/index.ts"], + "@sinclair/typemap": ["src/index.ts"], + } } } \ No newline at end of file From bbd5524a480ffb3c1dbc9d3351fc800659e0bfa1 Mon Sep 17 00:00:00 2001 From: sinclair Date: Sun, 20 Jul 2025 14:06:55 +0900 Subject: [PATCH 6/6] typescript latest --- package-lock.json | 2 +- package.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index a0dd2bd..e3dfcf8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,7 +15,7 @@ "@types/node": "^22.10.2", "mocha": "^11.0.1", "prettier": "^3.4.2", - "typescript": "^5.7.2", + "typescript": "^5.8.3", "valibot": "^1.0.0", "zod": "^3.24.1" }, diff --git a/package.json b/package.json index d792748..6941057 100644 --- a/package.json +++ b/package.json @@ -35,8 +35,8 @@ "@types/node": "^22.10.2", "mocha": "^11.0.1", "prettier": "^3.4.2", - "typescript": "^5.7.2", + "typescript": "^5.8.3", "valibot": "^1.0.0", "zod": "^3.24.1" } -} \ No newline at end of file +}