@nmtjs/type 0.5.2 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/compiler.js +16 -79
- package/dist/compiler.js.map +1 -1
- package/dist/index.js +30 -54
- package/dist/index.js.map +1 -1
- package/dist/inference.js +1 -0
- package/dist/inference.js.map +1 -0
- package/dist/parse.js +145 -0
- package/dist/parse.js.map +1 -0
- package/dist/runtime.js +73 -0
- package/dist/runtime.js.map +1 -0
- package/dist/schemas/default.js +6 -0
- package/dist/schemas/default.js.map +1 -0
- package/dist/schemas/discriminated-union.js.map +1 -1
- package/dist/schemas/nullable.js.map +1 -1
- package/dist/temporal.js.map +1 -1
- package/dist/types/any.js +0 -1
- package/dist/types/any.js.map +1 -1
- package/dist/types/array.js +0 -1
- package/dist/types/array.js.map +1 -1
- package/dist/types/base.js +4 -13
- package/dist/types/base.js.map +1 -1
- package/dist/types/boolean.js +0 -1
- package/dist/types/boolean.js.map +1 -1
- package/dist/types/custom.js +0 -1
- package/dist/types/custom.js.map +1 -1
- package/dist/types/date.js +9 -1
- package/dist/types/date.js.map +1 -1
- package/dist/types/enum.js +6 -4
- package/dist/types/enum.js.map +1 -1
- package/dist/types/literal.js +3 -2
- package/dist/types/literal.js.map +1 -1
- package/dist/types/never.js +0 -1
- package/dist/types/never.js.map +1 -1
- package/dist/types/number.js +2 -3
- package/dist/types/number.js.map +1 -1
- package/dist/types/object.js +31 -1
- package/dist/types/object.js.map +1 -1
- package/dist/types/string.js +0 -1
- package/dist/types/string.js.map +1 -1
- package/dist/types/union.js +8 -7
- package/dist/types/union.js.map +1 -1
- package/package.json +8 -8
- package/src/compiler.ts +36 -121
- package/src/index.ts +36 -119
- package/src/inference.ts +128 -0
- package/src/parse.ts +217 -0
- package/src/runtime.ts +137 -0
- package/src/schemas/default.ts +12 -0
- package/src/schemas/discriminated-union.ts +1 -1
- package/src/schemas/nullable.ts +0 -6
- package/src/temporal.ts +0 -1
- package/src/types/any.ts +2 -4
- package/src/types/array.ts +0 -11
- package/src/types/base.ts +45 -139
- package/src/types/boolean.ts +3 -10
- package/src/types/custom.ts +14 -13
- package/src/types/date.ts +13 -1
- package/src/types/enum.ts +12 -15
- package/src/types/literal.ts +3 -5
- package/src/types/never.ts +2 -4
- package/src/types/number.ts +18 -18
- package/src/types/object.ts +107 -42
- package/src/types/string.ts +8 -5
- package/src/types/union.ts +42 -77
package/dist/types/any.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/types/any.ts"],"sourcesContent":["import { type TAny, Type } from '@sinclair/typebox'\nimport { BaseType
|
|
1
|
+
{"version":3,"sources":["../../../src/types/any.ts"],"sourcesContent":["import { type TAny, Type } from '@sinclair/typebox'\nimport { BaseType } from './base.ts'\n\nexport class AnyType extends BaseType<TAny, {}, any> {\n static factory() {\n return new AnyType(Type.Any())\n }\n}\n"],"names":["Type","BaseType","AnyType","factory","Any"],"mappings":"AAAA,SAAoBA,IAAI,QAAQ,oBAAmB;AACnD,SAASC,QAAQ,QAAQ,YAAW;AAEpC,OAAO,MAAMC,gBAAgBD;IAC3B,OAAOE,UAAU;QACf,OAAO,IAAID,QAAQF,KAAKI,GAAG;IAC7B;AACF"}
|
package/dist/types/array.js
CHANGED
package/dist/types/array.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/types/array.ts"],"sourcesContent":["import {\n type ArrayOptions,\n type StaticDecode,\n type TArray,\n Type,\n} from '@sinclair/typebox'\nimport { BaseType } from './base.ts'\n\nexport class ArrayType<T extends BaseType = BaseType> extends BaseType<\n TArray<T['schema']>,\n { element: T; options: ArrayOptions }\n> {\n
|
|
1
|
+
{"version":3,"sources":["../../../src/types/array.ts"],"sourcesContent":["import {\n type ArrayOptions,\n type StaticDecode,\n type TArray,\n Type,\n} from '@sinclair/typebox'\nimport { BaseType } from './base.ts'\n\nexport class ArrayType<T extends BaseType = BaseType> extends BaseType<\n TArray<T['schema']>,\n { element: T; options: ArrayOptions }\n> {\n static factory<T extends BaseType>(element: T, options: ArrayOptions = {}) {\n return new ArrayType<T>(Type.Array(element.schema, options))\n }\n\n min(value: number) {\n return ArrayType.factory(this.props.element, {\n ...this.props.options,\n minItems: value,\n })\n }\n\n max(value: number) {\n return ArrayType.factory(this.props.element, {\n ...this.props.options,\n maxItems: value,\n })\n }\n\n length(value: number) {\n return ArrayType.factory(this.props.element, {\n ...this.props.options,\n minItems: value,\n maxItems: value,\n })\n }\n}\n"],"names":["Type","BaseType","ArrayType","factory","element","options","Array","schema","min","value","props","minItems","max","maxItems","length"],"mappings":"AAAA,SAIEA,IAAI,QACC,oBAAmB;AAC1B,SAASC,QAAQ,QAAQ,YAAW;AAEpC,OAAO,MAAMC,kBAAiDD;IAI5D,OAAOE,QAA4BC,OAAU,EAAEC,UAAwB,CAAC,CAAC,EAAE;QACzE,OAAO,IAAIH,UAAaF,KAAKM,KAAK,CAACF,QAAQG,MAAM,EAAEF;IACrD;IAEAG,IAAIC,KAAa,EAAE;QACjB,OAAOP,UAAUC,OAAO,CAAC,IAAI,CAACO,KAAK,CAACN,OAAO,EAAE;YAC3C,GAAG,IAAI,CAACM,KAAK,CAACL,OAAO;YACrBM,UAAUF;QACZ;IACF;IAEAG,IAAIH,KAAa,EAAE;QACjB,OAAOP,UAAUC,OAAO,CAAC,IAAI,CAACO,KAAK,CAACN,OAAO,EAAE;YAC3C,GAAG,IAAI,CAACM,KAAK,CAACL,OAAO;YACrBQ,UAAUJ;QACZ;IACF;IAEAK,OAAOL,KAAa,EAAE;QACpB,OAAOP,UAAUC,OAAO,CAAC,IAAI,CAACO,KAAK,CAACN,OAAO,EAAE;YAC3C,GAAG,IAAI,CAACM,KAAK,CAACL,OAAO;YACrBM,UAAUF;YACVI,UAAUJ;QACZ;IACF;AACF"}
|
package/dist/types/base.js
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
import { Optional } from '@sinclair/typebox';
|
|
2
|
+
import { Default } from "../schemas/default.js";
|
|
2
3
|
import { Nullable } from "../schemas/nullable.js";
|
|
3
4
|
export class BaseType {
|
|
4
5
|
schema;
|
|
5
|
-
final;
|
|
6
6
|
props;
|
|
7
7
|
params;
|
|
8
8
|
constructor(schema, props = {}, params = {}){
|
|
9
9
|
const { hasDefault = false, nullable = false, optional = false } = params;
|
|
10
10
|
this.schema = schema;
|
|
11
|
-
this.final = schema;
|
|
12
|
-
if (nullable) this.final = Nullable(this.final);
|
|
13
|
-
if (optional || hasDefault) this.final = Optional(this.final);
|
|
14
11
|
this.props = props;
|
|
15
12
|
this.params = {
|
|
16
13
|
hasDefault,
|
|
@@ -46,9 +43,8 @@ export class BaseType {
|
|
|
46
43
|
}
|
|
47
44
|
}
|
|
48
45
|
export class OptionalType extends BaseType {
|
|
49
|
-
_;
|
|
50
46
|
static factory(type) {
|
|
51
|
-
return new OptionalType(type.schema, {
|
|
47
|
+
return new OptionalType(Optional(type.schema), {
|
|
52
48
|
inner: type
|
|
53
49
|
}, {
|
|
54
50
|
...type.params,
|
|
@@ -57,9 +53,8 @@ export class OptionalType extends BaseType {
|
|
|
57
53
|
}
|
|
58
54
|
}
|
|
59
55
|
export class NullableType extends BaseType {
|
|
60
|
-
_;
|
|
61
56
|
static factory(type) {
|
|
62
|
-
return new NullableType(type.schema, {
|
|
57
|
+
return new NullableType(Nullable(type.schema), {
|
|
63
58
|
inner: type
|
|
64
59
|
}, {
|
|
65
60
|
...type.params,
|
|
@@ -68,12 +63,8 @@ export class NullableType extends BaseType {
|
|
|
68
63
|
}
|
|
69
64
|
}
|
|
70
65
|
export class DefaultType extends BaseType {
|
|
71
|
-
_;
|
|
72
66
|
static factory(type, defaultValue) {
|
|
73
|
-
return new DefaultType({
|
|
74
|
-
...type.schema,
|
|
75
|
-
default: defaultValue
|
|
76
|
-
}, {
|
|
67
|
+
return new DefaultType(Default(Optional(type.schema), defaultValue), {
|
|
77
68
|
inner: type
|
|
78
69
|
}, {
|
|
79
70
|
...type.params,
|
package/dist/types/base.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/types/base.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../../src/types/base.ts"],"sourcesContent":["import { Optional, type TOptional, type TSchema } from '@sinclair/typebox'\nimport { Default, type TDefault } from '../schemas/default.ts'\nimport { Nullable, type TNullable } from '../schemas/nullable.ts'\n\nexport type TypeProps = Record<string, any>\n\nexport type TypeParams = {\n optional?: boolean\n nullable?: boolean\n hasDefault?: boolean\n encode?: (value: any) => any\n}\n\nexport type DefaultTypeParams = {\n optional: false\n nullable: false\n hasDefault: false\n encode?: TypeParams['encode']\n}\n\nexport type BaseTypeAny<T extends TSchema = TSchema> = BaseType<\n T,\n TypeProps,\n any\n>\n\nexport abstract class BaseType<\n Schema extends TSchema = TSchema,\n Props extends TypeProps = TypeProps,\n ValueType = unknown,\n> {\n readonly schema: Schema\n readonly props: Props\n readonly params: TypeParams\n\n constructor(\n schema: Schema,\n props: Props = {} as Props,\n params: TypeParams = {} as TypeParams,\n ) {\n const { hasDefault = false, nullable = false, optional = false } = params\n this.schema = schema\n\n this.props = props\n this.params = {\n hasDefault,\n nullable,\n optional,\n } as TypeParams\n }\n\n optional(): OptionalType<BaseType<Schema, Props>, ValueType> {\n return OptionalType.factory(this) as any\n }\n\n nullable(): NullableType<BaseType<Schema, Props>, ValueType> {\n return NullableType.factory(this) as any\n }\n\n nullish() {\n return this.nullable().optional()\n }\n\n default(value: ValueType): DefaultType<BaseType<Schema, Props>, ValueType> {\n return DefaultType.factory(\n this,\n this.params.encode?.(value) ?? value,\n ) as any\n }\n\n description(description: string): BaseType<Schema, Props, ValueType> {\n const ThisConstructor = this.constructor as any\n return new ThisConstructor(\n {\n ...this.schema,\n description,\n },\n this.props,\n this.params,\n ) as any\n }\n\n examples(...examples: ValueType[]): BaseType<Schema, Props, ValueType> {\n const ThisConstructor = this.constructor as any\n return new ThisConstructor(\n {\n ...this.schema,\n examples,\n },\n this.props,\n this.params,\n ) as any\n }\n}\n\nexport class OptionalType<\n Type extends BaseTypeAny = BaseTypeAny,\n ValueType = unknown,\n> extends BaseType<TOptional<Type['schema']>, { inner: Type }, ValueType> {\n static factory<T extends BaseTypeAny>(type: T) {\n return new OptionalType<T>(Optional(type.schema) as any, { inner: type }, {\n ...type.params,\n optional: true,\n } as any)\n }\n}\n\nexport class NullableType<\n Type extends BaseTypeAny<any> = BaseTypeAny<any>,\n ValueType = unknown,\n> extends BaseType<\n TNullable<Type['schema']>,\n { inner: Type },\n ValueType | null\n> {\n static factory<T extends BaseTypeAny<any>>(type: T) {\n return new NullableType<T>(Nullable(type.schema), { inner: type }, {\n ...type.params,\n nullable: true,\n } as any)\n }\n}\n\nexport class DefaultType<\n Type extends BaseTypeAny = BaseTypeAny,\n ValueType = unknown,\n> extends BaseType<\n TDefault<TOptional<Type['schema']>>,\n { inner: Type },\n ValueType\n> {\n static factory<T extends BaseTypeAny<any>>(type: T, defaultValue: any) {\n return new DefaultType<T>(\n Default(Optional(type.schema), defaultValue) as any,\n { inner: type },\n { ...type.params, hasDefault: true } as any,\n )\n }\n}\n"],"names":["Optional","Default","Nullable","BaseType","schema","props","params","constructor","hasDefault","nullable","optional","OptionalType","factory","NullableType","nullish","default","value","DefaultType","encode","description","ThisConstructor","examples","type","inner","defaultValue"],"mappings":"AAAA,SAASA,QAAQ,QAAsC,oBAAmB;AAC1E,SAASC,OAAO,QAAuB,wBAAuB;AAC9D,SAASC,QAAQ,QAAwB,yBAAwB;AAwBjE,OAAO,MAAeC;IAKXC,OAAc;IACdC,MAAY;IACZC,OAAkB;IAE3BC,YACEH,MAAc,EACdC,QAAe,CAAC,CAAU,EAC1BC,SAAqB,CAAC,CAAe,CACrC;QACA,MAAM,EAAEE,aAAa,KAAK,EAAEC,WAAW,KAAK,EAAEC,WAAW,KAAK,EAAE,GAAGJ;QACnE,IAAI,CAACF,MAAM,GAAGA;QAEd,IAAI,CAACC,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B,EAAE;QACrE,OAAO,IAAIP,YACThB,QAAQD,SAASsB,KAAKlB,MAAM,GAAGoB,eAC/B;YAAED,OAAOD;QAAK,GACd;YAAE,GAAGA,KAAKhB,MAAM;YAAEE,YAAY;QAAK;IAEvC;AACF"}
|
package/dist/types/boolean.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/types/boolean.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../../src/types/boolean.ts"],"sourcesContent":["import { type TBoolean, Type } from '@sinclair/typebox'\nimport { BaseType } from './base.ts'\n\nexport class BooleanType extends BaseType<TBoolean, {}, boolean> {\n static factory() {\n return new BooleanType(Type.Boolean())\n }\n}\n"],"names":["Type","BaseType","BooleanType","factory","Boolean"],"mappings":"AAAA,SAAwBA,IAAI,QAAQ,oBAAmB;AACvD,SAASC,QAAQ,QAAQ,YAAW;AAEpC,OAAO,MAAMC,oBAAoBD;IAC/B,OAAOE,UAAU;QACf,OAAO,IAAID,YAAYF,KAAKI,OAAO;IACrC;AACF"}
|
package/dist/types/custom.js
CHANGED
package/dist/types/custom.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/types/custom.ts"],"sourcesContent":["import {\n type TAny,\n type
|
|
1
|
+
{"version":3,"sources":["../../../src/types/custom.ts"],"sourcesContent":["import {\n type TAny,\n type TSchema,\n type TTransform,\n Type,\n} from '@sinclair/typebox'\nimport type { StaticInputDecode, StaticOutputDecode } from '../inference.ts'\nimport { BaseType } from './base.ts'\n\nexport type CustomTypeDecode<T> = (value: any) => T\nexport type CustomTypeEncode<T> = (value: T) => any\n\nexport abstract class TransformType<\n T,\n S extends TSchema = TAny,\n> extends BaseType<TTransform<S, T>, {}, StaticInputDecode<TTransform<S, T>>> {}\n\nexport class CustomType<T, S extends TSchema = TAny> extends TransformType<\n T,\n S\n> {\n static factory<T, S extends TSchema = TAny>(\n decode: CustomTypeDecode<T>,\n encode: CustomTypeEncode<T>,\n schema: S = Type.Any() as S,\n ) {\n return new CustomType<T, S>(\n Type.Transform(schema).Decode(decode).Encode(encode),\n {},\n { encode } as any,\n )\n }\n}\n"],"names":["Type","BaseType","TransformType","CustomType","factory","decode","encode","schema","Any","Transform","Decode","Encode"],"mappings":"AAAA,SAIEA,IAAI,QACC,oBAAmB;AAE1B,SAASC,QAAQ,QAAQ,YAAW;AAKpC,OAAO,MAAeC,sBAGZD;AAAqE;AAE/E,OAAO,MAAME,mBAAgDD;IAI3D,OAAOE,QACLC,MAA2B,EAC3BC,MAA2B,EAC3BC,SAAYP,KAAKQ,GAAG,EAAO,EAC3B;QACA,OAAO,IAAIL,WACTH,KAAKS,SAAS,CAACF,QAAQG,MAAM,CAACL,QAAQM,MAAM,CAACL,SAC7C,CAAC,GACD;YAAEA;QAAO;IAEb;AACF"}
|
package/dist/types/date.js
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
|
+
import { Type } from '@sinclair/typebox';
|
|
1
2
|
import { CustomType, TransformType } from "./custom.js";
|
|
2
3
|
const decode = (value)=>new Date(value);
|
|
3
4
|
const encode = (value)=>value.toISOString();
|
|
4
5
|
export class DateType extends TransformType {
|
|
5
6
|
static factory() {
|
|
6
|
-
return CustomType.factory(decode, encode
|
|
7
|
+
return CustomType.factory(decode, encode, Type.Union([
|
|
8
|
+
Type.String({
|
|
9
|
+
format: 'date'
|
|
10
|
+
}),
|
|
11
|
+
Type.String({
|
|
12
|
+
format: 'date-time'
|
|
13
|
+
})
|
|
14
|
+
]));
|
|
7
15
|
}
|
|
8
16
|
}
|
package/dist/types/date.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/types/date.ts"],"sourcesContent":["import { CustomType, TransformType } from './custom.ts'\n\nconst decode = (value: any): Date => new Date(value)\nconst encode = (value: Date): any => value.toISOString()\n\nexport class DateType extends TransformType<Date> {\n static factory() {\n return CustomType.factory<Date>(decode
|
|
1
|
+
{"version":3,"sources":["../../../src/types/date.ts"],"sourcesContent":["import { type TString, Type } from '@sinclair/typebox'\nimport { CustomType, TransformType } from './custom.ts'\n\nconst decode = (value: any): Date => new Date(value)\nconst encode = (value: Date): any => value.toISOString()\n\nexport class DateType extends TransformType<Date> {\n static factory() {\n return CustomType.factory<Date, TString>(\n decode,\n encode,\n Type.Union([\n Type.String({\n format: 'date',\n }),\n Type.String({\n format: 'date-time',\n }),\n ]) as unknown as TString,\n )\n }\n}\n"],"names":["Type","CustomType","TransformType","decode","value","Date","encode","toISOString","DateType","factory","Union","String","format"],"mappings":"AAAA,SAAuBA,IAAI,QAAQ,oBAAmB;AACtD,SAASC,UAAU,EAAEC,aAAa,QAAQ,cAAa;AAEvD,MAAMC,SAAS,CAACC,QAAqB,IAAIC,KAAKD;AAC9C,MAAME,SAAS,CAACF,QAAqBA,MAAMG,WAAW;AAEtD,OAAO,MAAMC,iBAAiBN;IAC5B,OAAOO,UAAU;QACf,OAAOR,WAAWQ,OAAO,CACvBN,QACAG,QACAN,KAAKU,KAAK,CAAC;YACTV,KAAKW,MAAM,CAAC;gBACVC,QAAQ;YACV;YACAZ,KAAKW,MAAM,CAAC;gBACVC,QAAQ;YACV;SACD;IAEL;AACF"}
|
package/dist/types/enum.js
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import { Type } from '@sinclair/typebox';
|
|
2
2
|
import { BaseType } from "./base.js";
|
|
3
3
|
export class ObjectEnumType extends BaseType {
|
|
4
|
-
_;
|
|
5
4
|
static factory(values) {
|
|
6
|
-
return new ObjectEnumType(Type.Enum(values)
|
|
5
|
+
return new ObjectEnumType(Type.Enum(values), {
|
|
6
|
+
values: Object.values(values)
|
|
7
|
+
});
|
|
7
8
|
}
|
|
8
9
|
}
|
|
9
10
|
export class EnumType extends BaseType {
|
|
10
|
-
_;
|
|
11
11
|
static factory(values) {
|
|
12
12
|
return new EnumType(Type.Enum(Object.fromEntries(values.map((v)=>[
|
|
13
13
|
v,
|
|
14
14
|
v
|
|
15
|
-
])))
|
|
15
|
+
]))), {
|
|
16
|
+
values
|
|
17
|
+
});
|
|
16
18
|
}
|
|
17
19
|
}
|
package/dist/types/enum.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/types/enum.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../../src/types/enum.ts"],"sourcesContent":["import { type TEnum, Type } from '@sinclair/typebox'\nimport { BaseType } from './base.ts'\n\nexport class ObjectEnumType<\n T extends { [K in string]: K } = { [K in string]: K },\n> extends BaseType<TEnum<T>, { values: T[keyof T] }, T[keyof T]> {\n static factory<T extends { [K in string]: K }>(values: T) {\n return new ObjectEnumType<T>(Type.Enum(values as any), {\n values: Object.values(values) as unknown as T[keyof T],\n })\n }\n}\n\nexport class EnumType<\n T extends (string | number)[] = (string | number)[],\n> extends BaseType<\n TEnum<Record<string, T[number]>>,\n { values: [...T] },\n T[keyof T]\n> {\n static factory<T extends (string | number)[]>(values: [...T]) {\n return new EnumType<T>(\n Type.Enum(Object.fromEntries(values.map((v) => [v, v])) as any),\n { values },\n )\n }\n}\n"],"names":["Type","BaseType","ObjectEnumType","factory","values","Enum","Object","EnumType","fromEntries","map","v"],"mappings":"AAAA,SAAqBA,IAAI,QAAQ,oBAAmB;AACpD,SAASC,QAAQ,QAAQ,YAAW;AAEpC,OAAO,MAAMC,uBAEHD;IACR,OAAOE,QAAwCC,MAAS,EAAE;QACxD,OAAO,IAAIF,eAAkBF,KAAKK,IAAI,CAACD,SAAgB;YACrDA,QAAQE,OAAOF,MAAM,CAACA;QACxB;IACF;AACF;AAEA,OAAO,MAAMG,iBAEHN;IAKR,OAAOE,QAAuCC,MAAc,EAAE;QAC5D,OAAO,IAAIG,SACTP,KAAKK,IAAI,CAACC,OAAOE,WAAW,CAACJ,OAAOK,GAAG,CAAC,CAACC,IAAM;gBAACA;gBAAGA;aAAE,KACrD;YAAEN;QAAO;IAEb;AACF"}
|
package/dist/types/literal.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Type } from '@sinclair/typebox';
|
|
2
2
|
import { BaseType } from "./base.js";
|
|
3
3
|
export class LiteralType extends BaseType {
|
|
4
|
-
_;
|
|
5
4
|
static factory(value) {
|
|
6
|
-
return new LiteralType(Type.Literal(value)
|
|
5
|
+
return new LiteralType(Type.Literal(value), {
|
|
6
|
+
value
|
|
7
|
+
});
|
|
7
8
|
}
|
|
8
9
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/types/literal.ts"],"sourcesContent":["import { type TLiteral, type TLiteralValue, Type } from '@sinclair/typebox'\nimport { BaseType
|
|
1
|
+
{"version":3,"sources":["../../../src/types/literal.ts"],"sourcesContent":["import { type TLiteral, type TLiteralValue, Type } from '@sinclair/typebox'\nimport { BaseType } from './base.ts'\n\nexport class LiteralType<\n T extends TLiteralValue = TLiteralValue,\n> extends BaseType<TLiteral<T>, { value: TLiteralValue }, T> {\n static factory<T extends TLiteralValue>(value: T) {\n return new LiteralType<T>(Type.Literal(value), { value })\n }\n}\n"],"names":["Type","BaseType","LiteralType","factory","value","Literal"],"mappings":"AAAA,SAA4CA,IAAI,QAAQ,oBAAmB;AAC3E,SAASC,QAAQ,QAAQ,YAAW;AAEpC,OAAO,MAAMC,oBAEHD;IACR,OAAOE,QAAiCC,KAAQ,EAAE;QAChD,OAAO,IAAIF,YAAeF,KAAKK,OAAO,CAACD,QAAQ;YAAEA;QAAM;IACzD;AACF"}
|
package/dist/types/never.js
CHANGED
package/dist/types/never.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/types/never.ts"],"sourcesContent":["import { type TNever, Type } from '@sinclair/typebox'\nimport { BaseType
|
|
1
|
+
{"version":3,"sources":["../../../src/types/never.ts"],"sourcesContent":["import { type TNever, Type } from '@sinclair/typebox'\nimport { BaseType } from './base.ts'\n\nexport class NeverType extends BaseType<TNever, {}, never> {\n static factory() {\n return new NeverType(Type.Never())\n }\n}\n"],"names":["Type","BaseType","NeverType","factory","Never"],"mappings":"AAAA,SAAsBA,IAAI,QAAQ,oBAAmB;AACrD,SAASC,QAAQ,QAAQ,YAAW;AAEpC,OAAO,MAAMC,kBAAkBD;IAC7B,OAAOE,UAAU;QACf,OAAO,IAAID,UAAUF,KAAKI,KAAK;IACjC;AACF"}
|
package/dist/types/number.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Type } from '@sinclair/typebox';
|
|
2
2
|
import { BaseType } from "./base.js";
|
|
3
3
|
export class NumberType extends BaseType {
|
|
4
|
-
_;
|
|
5
4
|
static factory(options = {}) {
|
|
6
5
|
return new NumberType(Type.Number(options), {
|
|
7
6
|
options
|
|
@@ -33,7 +32,6 @@ export class NumberType extends BaseType {
|
|
|
33
32
|
}
|
|
34
33
|
}
|
|
35
34
|
export class IntegerType extends BaseType {
|
|
36
|
-
_;
|
|
37
35
|
static factory(options = {}) {
|
|
38
36
|
return new IntegerType(Type.Integer(options), {
|
|
39
37
|
options
|
|
@@ -65,10 +63,11 @@ export class IntegerType extends BaseType {
|
|
|
65
63
|
}
|
|
66
64
|
}
|
|
67
65
|
export class BigIntType extends BaseType {
|
|
68
|
-
_;
|
|
69
66
|
static factory(options = {}) {
|
|
70
67
|
return new BigIntType(Type.BigInt(options), {
|
|
71
68
|
options
|
|
69
|
+
}, {
|
|
70
|
+
encode: (value)=>`${value}`
|
|
72
71
|
});
|
|
73
72
|
}
|
|
74
73
|
positive() {
|
package/dist/types/number.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/types/number.ts"],"sourcesContent":["import {\n type BigIntOptions,\n type IntegerOptions,\n type NumberOptions,\n type
|
|
1
|
+
{"version":3,"sources":["../../../src/types/number.ts"],"sourcesContent":["import {\n type BigIntOptions,\n type IntegerOptions,\n type NumberOptions,\n type TBigInt,\n type TInteger,\n type TNumber,\n Type,\n} from '@sinclair/typebox'\nimport { BaseType } from './base.ts'\n\nexport class NumberType extends BaseType<\n TNumber,\n { options: NumberOptions },\n number\n> {\n static factory(options: NumberOptions = {}) {\n return new NumberType(Type.Number(options), { options })\n }\n\n positive() {\n return this.min(0, true)\n }\n\n negative() {\n return this.max(0, true)\n }\n\n max(value: number, exclusive?: true) {\n return NumberType.factory({\n ...this.props.options,\n maximum: value,\n ...(!exclusive ? {} : { exclusiveMaximum: value }),\n })\n }\n\n min(value: number, exclusive?: true) {\n return NumberType.factory({\n ...this.props.options,\n minimum: value,\n ...(!exclusive ? {} : { exclusiveMinimum: value }),\n })\n }\n}\n\nexport class IntegerType extends BaseType<\n TInteger,\n { options: IntegerOptions },\n number\n> {\n static factory(options: IntegerOptions = {}) {\n return new IntegerType(Type.Integer(options), { options })\n }\n\n positive() {\n return this.min(0, true)\n }\n\n negative() {\n return this.max(0, true)\n }\n\n max(value: number, exclusive?: true) {\n return IntegerType.factory({\n ...this.props.options,\n maximum: value,\n ...(!exclusive ? {} : { exclusiveMaximum: value }),\n })\n }\n\n min(value: number, exclusive?: true) {\n return IntegerType.factory({\n ...this.props.options,\n minimum: value,\n ...(!exclusive ? {} : { exclusiveMinimum: value }),\n })\n }\n}\n\n// TODO: this is not json schema compatible\nexport class BigIntType extends BaseType<\n TBigInt,\n { options: BigIntOptions },\n bigint\n> {\n static factory(options: BigIntOptions = {}) {\n return new BigIntType(\n Type.BigInt(options),\n { options },\n { encode: (value) => `${value}` },\n )\n }\n\n positive() {\n return this.min(0n, true)\n }\n\n negative() {\n return this.max(0n, true)\n }\n\n max(value: bigint, exclusive?: true) {\n return BigIntType.factory({\n ...this.props.options,\n maximum: value,\n ...(!exclusive ? {} : { exclusiveMaximum: value }),\n })\n }\n\n min(value: bigint, exclusive?: true) {\n return BigIntType.factory({\n ...this.props.options,\n minimum: value,\n ...(!exclusive ? {} : { exclusiveMinimum: value }),\n })\n }\n}\n"],"names":["Type","BaseType","NumberType","factory","options","Number","positive","min","negative","max","value","exclusive","props","maximum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,CAACC,YAAY,CAAC,IAAI;gBAAEG,kBAAkBJ;YAAM,CAAC;QACnD;IACF;IAEAH,IAAIG,KAAa,EAAEC,SAAgB,EAAE;QACnC,OAAOM,YAAYd,OAAO,CAAC;YACzB,GAAG,IAAI,CAACS,KAAK,CAACR,OAAO;YACrBW,SAASL;YACT,GAAI,CAACC,YAAY,CAAC,IAAI;gBAAEK,kBAAkBN;YAAM,CAAC;QACnD;IACF;AACF;AAGA,OAAO,MAAMS,mBAAmBlB;IAK9B,OAAOE,QAAQC,UAAyB,CAAC,CAAC,EAAE;QAC1C,OAAO,IAAIe,WACTnB,KAAKoB,MAAM,CAAChB,UACZ;YAAEA;QAAQ,GACV;YAAEiB,QAAQ,CAACX,QAAU,CAAC,EAAEA,MAAM,CAAC;QAAC;IAEpC;IAEAJ,WAAW;QACT,OAAO,IAAI,CAACC,GAAG,CAAC,EAAE,EAAE;IACtB;IAEAC,WAAW;QACT,OAAO,IAAI,CAACC,GAAG,CAAC,EAAE,EAAE;IACtB;IAEAA,IAAIC,KAAa,EAAEC,SAAgB,EAAE;QACnC,OAAOQ,WAAWhB,OAAO,CAAC;YACxB,GAAG,IAAI,CAACS,KAAK,CAACR,OAAO;YACrBS,SAASH;YACT,GAAI,CAACC,YAAY,CAAC,IAAI;gBAAEG,kBAAkBJ;YAAM,CAAC;QACnD;IACF;IAEAH,IAAIG,KAAa,EAAEC,SAAgB,EAAE;QACnC,OAAOQ,WAAWhB,OAAO,CAAC;YACxB,GAAG,IAAI,CAACS,KAAK,CAACR,OAAO;YACrBW,SAASL;YACT,GAAI,CAACC,YAAY,CAAC,IAAI;gBAAEK,kBAAkBN;YAAM,CAAC;QACnD;IACF;AACF"}
|
package/dist/types/object.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Type } from '@sinclair/typebox';
|
|
2
2
|
import { BaseType } from "./base.js";
|
|
3
|
+
import { EnumType } from "./enum.js";
|
|
3
4
|
export class ObjectType extends BaseType {
|
|
4
5
|
static factory(properties, options = {}) {
|
|
5
6
|
const schemaProperties = {};
|
|
@@ -12,8 +13,37 @@ export class ObjectType extends BaseType {
|
|
|
12
13
|
}
|
|
13
14
|
}
|
|
14
15
|
export class RecordType extends BaseType {
|
|
15
|
-
_;
|
|
16
16
|
static factory(key, element, options = {}) {
|
|
17
17
|
return new RecordType(Type.Record(key.schema, element.schema, options));
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
|
+
export function keyof(type) {
|
|
21
|
+
return EnumType.factory(Object.keys(type.props.properties));
|
|
22
|
+
}
|
|
23
|
+
export function pick(source, pick) {
|
|
24
|
+
const properties = Object.fromEntries(Object.entries(source.props.properties).filter(([key])=>pick[key]));
|
|
25
|
+
return ObjectType.factory(properties);
|
|
26
|
+
}
|
|
27
|
+
export function omit(source, omit) {
|
|
28
|
+
const properties = Object.fromEntries(Object.entries(source.props.properties).filter(([key])=>!omit[key]));
|
|
29
|
+
return ObjectType.factory(properties);
|
|
30
|
+
}
|
|
31
|
+
export function extend(object1, properties) {
|
|
32
|
+
return ObjectType.factory({
|
|
33
|
+
...object1.props.properties,
|
|
34
|
+
...properties
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
export function merge(object1, object2) {
|
|
38
|
+
return ObjectType.factory({
|
|
39
|
+
...object1.props.properties,
|
|
40
|
+
...object2.props.properties
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
export function partial(object) {
|
|
44
|
+
const properties = {};
|
|
45
|
+
for (const [key, value] of Object.entries(object.props.properties)){
|
|
46
|
+
properties[key] = value.optional();
|
|
47
|
+
}
|
|
48
|
+
return ObjectType.factory(properties, {});
|
|
49
|
+
}
|
package/dist/types/object.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/types/object.ts"],"sourcesContent":["import {\n type ObjectOptions,\n type TObject,\n type TRecordOrObject,\n type TSchema,\n Type,\n} from '@sinclair/typebox'\nimport { BaseType, type BaseTypeAny } from './base.ts'\nimport
|
|
1
|
+
{"version":3,"sources":["../../../src/types/object.ts"],"sourcesContent":["import {\n type ObjectOptions,\n type TObject,\n type TRecordOrObject,\n type TSchema,\n Type,\n} from '@sinclair/typebox'\nimport type { StaticInputDecode } from '../inference.ts'\nimport type { UnionToTupleString } from '../utils.ts'\nimport { BaseType, type BaseTypeAny, type OptionalType } from './base.ts'\nimport { EnumType, type ObjectEnumType } from './enum.ts'\nimport type { LiteralType } from './literal.ts'\nimport type { StringType } from './string.ts'\n\nexport type ObjectTypeProps = { [k: string]: BaseTypeAny }\nexport type AnyObjectType = ObjectType<ObjectTypeProps>\nexport class ObjectType<T extends ObjectTypeProps = {}> extends BaseType<\n TObject<{ [K in keyof T]: T[K]['schema'] }>,\n { properties: T },\n StaticInputDecode<TObject<{ [K in keyof T]: T[K]['schema'] }>>\n> {\n static factory<T extends ObjectTypeProps = {}>(\n properties: T,\n options: ObjectOptions = {},\n ) {\n const schemaProperties = {} as {\n [K in keyof T]: T[K]['schema']\n }\n\n for (const key in properties) {\n schemaProperties[key] = properties[key].schema\n }\n\n return new ObjectType<T>(Type.Object(schemaProperties, options) as any, {\n properties,\n })\n }\n}\n\nexport class RecordType<\n K extends LiteralType | EnumType | ObjectEnumType | StringType,\n E extends BaseType,\n> extends BaseType<TRecordOrObject<K['schema'], E['schema']>> {\n static factory<\n K extends\n | LiteralType<any>\n | EnumType<any>\n | ObjectEnumType<any>\n | StringType,\n E extends BaseType,\n >(key: K, element: E, options: ObjectOptions = {}) {\n return new RecordType<K, E>(\n Type.Record(key.schema, element.schema, options) as any,\n )\n }\n}\n\nexport function keyof<T extends ObjectType>(\n type: T,\n): EnumType<\n UnionToTupleString<T extends ObjectType<infer Props> ? keyof Props : never>\n> {\n return EnumType.factory(Object.keys(type.props.properties) as any)\n}\n\nexport function pick<\n T extends AnyObjectType,\n P extends { [K in keyof T['props']['properties']]?: true },\n>(\n source: T,\n pick: P,\n): ObjectType<{\n [K in keyof P]: P[K] extends true\n ? K extends keyof T['props']['properties']\n ? T['props']['properties'][K]\n : never\n : never\n}> {\n const properties = Object.fromEntries(\n Object.entries(source.props.properties).filter(([key]) => pick[key]),\n )\n return ObjectType.factory(properties) as any\n}\n\nexport function omit<\n T extends AnyObjectType,\n P extends { [K in keyof T['props']['properties']]?: true },\n>(\n source: T,\n omit: P,\n): ObjectType<{\n [K in keyof T['props']['properties'] as K extends keyof P\n ? never\n : K]: T['props']['properties'][K]\n}> {\n const properties = Object.fromEntries(\n Object.entries(source.props.properties).filter(([key]) => !omit[key]),\n )\n return ObjectType.factory(properties) as any\n}\n\nexport function extend<T extends AnyObjectType, P extends ObjectTypeProps>(\n object1: T,\n properties: P,\n): ObjectType<{\n [K in keyof T['props']['properties'] | keyof P]: K extends keyof P\n ? P[K]\n : K extends keyof T['props']['properties']\n ? T['props']['properties'][K]\n : never\n}> {\n return ObjectType.factory({\n ...object1.props.properties,\n ...properties,\n }) as any\n}\n\nexport function merge<T1 extends AnyObjectType, T2 extends AnyObjectType>(\n object1: T1,\n object2: T2,\n): ObjectType<{\n [K in\n | keyof T1['props']['properties']\n | keyof T2['props']['properties']]: K extends keyof T2['props']['properties']\n ? T2['props']['properties'][K]\n : K extends keyof T1['props']['properties']\n ? T1['props']['properties'][K]\n : never\n}> {\n return ObjectType.factory({\n ...object1.props.properties,\n ...object2.props.properties,\n }) as any\n}\n\nexport function partial<\n T extends AnyObjectType,\n P extends T extends ObjectType<infer Props> ? Props : never,\n>(\n object: T,\n): ObjectType<{\n [K in keyof P]: P[K] extends BaseType<any, any, infer T>\n ? OptionalType<P[K], T>\n : never\n}> {\n const properties = {} as any\n\n for (const [key, value] of Object.entries(object.props.properties)) {\n properties[key] = value.optional()\n }\n\n return ObjectType.factory(properties, {}) as any\n}\n"],"names":["Type","BaseType","EnumType","ObjectType","factory","properties","options","schemaProperties","key","schema","Object","RecordType","element","Record","keyof","type","keys","props","pick","source","fromEntries","entries","filter","omit","extend","object1","merge","object2","partial","object","value","optional"],"mappings":"AAAA,SA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,OAAOF,WAAWC,OAAO,CAAC;QACxB,GAAGqB,QAAQR,KAAK,CAACZ,UAAU;QAC3B,GAAGA,UAAU;IACf;AACF;AAEA,OAAO,SAASqB,MACdD,OAAW,EACXE,OAAW;IAUX,OAAOxB,WAAWC,OAAO,CAAC;QACxB,GAAGqB,QAAQR,KAAK,CAACZ,UAAU;QAC3B,GAAGsB,QAAQV,KAAK,CAACZ,UAAU;IAC7B;AACF;AAEA,OAAO,SAASuB,QAIdC,MAAS;IAMT,MAAMxB,aAAa,CAAC;IAEpB,KAAK,MAAM,CAACG,KAAKsB,MAAM,IAAIpB,OAAOW,OAAO,CAACQ,OAAOZ,KAAK,CAACZ,UAAU,EAAG;QAClEA,UAAU,CAACG,IAAI,GAAGsB,MAAMC,QAAQ;IAClC;IAEA,OAAO5B,WAAWC,OAAO,CAACC,YAAY,CAAC;AACzC"}
|
package/dist/types/string.js
CHANGED
package/dist/types/string.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/types/string.ts"],"sourcesContent":["import { type StringOptions, type TString, Type } from '@sinclair/typebox'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/types/string.ts"],"sourcesContent":["import { type StringOptions, type TString, Type } from '@sinclair/typebox'\nimport type { StaticOutputDecode } from '../inference.ts'\nimport { BaseType } from './base.ts'\n\nexport class StringType extends BaseType<\n TString,\n { options: StringOptions },\n string\n> {\n static factory(options: StringOptions = {}) {\n return new StringType(Type.String(options), { options })\n }\n\n max(value: number) {\n return StringType.factory({\n ...this.props.options,\n maxLength: value,\n })\n }\n\n min(value: number) {\n return StringType.factory({\n ...this.props.options,\n minLength: value,\n })\n }\n\n format(format: TString['format']) {\n return StringType.factory({\n ...this.props.options,\n pattern: undefined,\n format,\n })\n }\n\n pattern(pattern: string) {\n return StringType.factory({\n ...this.props.options,\n format: undefined,\n pattern,\n })\n }\n\n email() {\n return this.format('email')\n }\n\n url() {\n return this.format('uri')\n }\n\n ipv4() {\n return this.format('ipv4')\n }\n\n ipv6() {\n return this.format('ipv6')\n }\n\n uuid() {\n return this.format('uuid')\n }\n}\n"],"names":["Type","BaseType","StringType","factory","options","String","max","value","props","maxLength","min","minLength","format","pattern","undefined","email","url","ipv4","ipv6","uuid"],"mappings":"AAAA,SAA2CA,IAAI,QAAQ,oBAAmB;AAE1E,SAASC,QAAQ,QAAQ,YAAW;AAEpC,OAAO,MAAMC,mBAAmBD;IAK9B,OAAOE,QAAQC,UAAyB,CAAC,CAAC,EAAE;QAC1C,OAAO,IAAIF,WAAWF,KAAKK,MAAM,CAACD,UAAU;YAAEA;QAAQ;IACxD;IAEAE,IAAIC,KAAa,EAAE;QACjB,OAAOL,WAAWC,OAAO,CAAC;YACxB,GAAG,IAAI,CAACK,KAAK,CAACJ,OAAO;YACrBK,WAAWF;QACb;IACF;IAEAG,IAAIH,KAAa,EAAE;QACjB,OAAOL,WAAWC,OAAO,CAAC;YACxB,GAAG,IAAI,CAACK,KAAK,CAACJ,OAAO;YACrBO,WAAWJ;QACb;IACF;IAEAK,OAAOA,MAAyB,EAAE;QAChC,OAAOV,WAAWC,OAAO,CAAC;YACxB,GAAG,IAAI,CAACK,KAAK,CAACJ,OAAO;YACrBS,SAASC;YACTF;QACF;IACF;IAEAC,QAAQA,OAAe,EAAE;QACvB,OAAOX,WAAWC,OAAO,CAAC;YACxB,GAAG,IAAI,CAACK,KAAK,CAACJ,OAAO;YACrBQ,QAAQE;YACRD;QACF;IACF;IAEAE,QAAQ;QACN,OAAO,IAAI,CAACH,MAAM,CAAC;IACrB;IAEAI,MAAM;QACJ,OAAO,IAAI,CAACJ,MAAM,CAAC;IACrB;IAEAK,OAAO;QACL,OAAO,IAAI,CAACL,MAAM,CAAC;IACrB;IAEAM,OAAO;QACL,OAAO,IAAI,CAACN,MAAM,CAAC;IACrB;IAEAO,OAAO;QACL,OAAO,IAAI,CAACP,MAAM,CAAC;IACrB;AACF"}
|
package/dist/types/union.js
CHANGED
|
@@ -2,19 +2,20 @@ import { Type } from '@sinclair/typebox';
|
|
|
2
2
|
import { DiscriminatedUnion } from "../schemas/discriminated-union.js";
|
|
3
3
|
import { BaseType } from "./base.js";
|
|
4
4
|
export class UnionType extends BaseType {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
static factory(...options) {
|
|
6
|
+
return new UnionType(Type.Union(options.map((t)=>t.schema)), {
|
|
7
|
+
options
|
|
8
|
+
});
|
|
8
9
|
}
|
|
9
10
|
}
|
|
10
11
|
export class IntersactionType extends BaseType {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
static factory(...options) {
|
|
13
|
+
return new IntersactionType(Type.Intersect(options.map((t)=>t.schema)), {
|
|
14
|
+
options
|
|
15
|
+
});
|
|
14
16
|
}
|
|
15
17
|
}
|
|
16
18
|
export class DiscriminatedUnionType extends BaseType {
|
|
17
|
-
_;
|
|
18
19
|
static factory(key, ...options) {
|
|
19
20
|
return new DiscriminatedUnionType(DiscriminatedUnion(key, options.map((t)=>t.schema)), {
|
|
20
21
|
key,
|
package/dist/types/union.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/types/union.ts"],"sourcesContent":["import {\n type TIntersect,\n type TUnion,\n Type,\n type UnionToTuple,\n} from '@sinclair/typebox'\nimport {\n DiscriminatedUnion,\n type TDiscriminatedUnion,\n} from '../schemas/discriminated-union.ts'\nimport { BaseType, type BaseTypeAny } from './base.ts'\nimport type {
|
|
1
|
+
{"version":3,"sources":["../../../src/types/union.ts"],"sourcesContent":["import {\n type TIntersect,\n type TObject,\n type TSchema,\n type TUnion,\n Type,\n type UnionToTuple,\n} from '@sinclair/typebox'\nimport type { StaticInputDecode } from '../inference.ts'\nimport {\n DiscriminatedUnion,\n type DiscriminatedUnionProperties,\n type TDiscriminatedUnion,\n} from '../schemas/discriminated-union.ts'\nimport { BaseType, type BaseTypeAny } from './base.ts'\nimport type { ObjectType, ObjectTypeProps } from './object.ts'\n\nexport class UnionType<\n T extends readonly BaseType[] = readonly BaseType[],\n S extends TSchema[] = UnionToTuple<T[number]['schema']>,\n> extends BaseType<TUnion<S>, { options: T }, StaticInputDecode<TUnion<S>>> {\n static factory<\n T extends readonly BaseType[] = readonly BaseType[],\n S extends TSchema[] = UnionToTuple<T[number]['schema']>,\n >(...options: T) {\n return new UnionType<T, S>(\n Type.Union(options.map((t) => t.schema)) as any,\n {\n options,\n },\n )\n }\n}\n\nexport class IntersactionType<\n T extends readonly BaseType[] = readonly BaseType[],\n S extends TSchema[] = UnionToTuple<T[number]['schema']>,\n> extends BaseType<\n TIntersect<S>,\n { options: T },\n StaticInputDecode<TIntersect<S>>\n> {\n static factory<\n T extends readonly BaseType[] = readonly BaseType[],\n S extends TSchema[] = UnionToTuple<T[number]['schema']>,\n >(...options: T) {\n return new IntersactionType<T, S>(\n Type.Intersect(options.map((t) => t.schema)) as any,\n { options },\n )\n }\n}\n\nexport type DiscriminatedUnionOptionType<K extends string> = ObjectType<\n ObjectTypeProps & { [_ in K]: BaseTypeAny }\n>\n\nexport class DiscriminatedUnionType<\n K extends string = string,\n T extends\n readonly DiscriminatedUnionOptionType<K>[] = DiscriminatedUnionOptionType<K>[],\n S extends TObject<DiscriminatedUnionProperties<K>>[] = [],\n> extends BaseType<\n TDiscriminatedUnion<K, S>,\n {\n key: K\n options: T\n },\n StaticInputDecode<TDiscriminatedUnion<K, S>>\n> {\n static factory<\n K extends string,\n T extends readonly DiscriminatedUnionOptionType<K>[],\n //@ts-expect-error\n S extends TObject<DiscriminatedUnionProperties<K>>[] = UnionToTuple<\n T[number]['schema']\n >,\n >(key: K, ...options: T) {\n return new DiscriminatedUnionType<K, T, S>(\n DiscriminatedUnion(key, options.map((t) => t.schema) as any),\n { key, options },\n )\n }\n}\n"],"names":["Type","DiscriminatedUnion","BaseType","UnionType","factory","options","Union","map","t","schema","IntersactionType","Intersect","DiscriminatedUnionType","key"],"mappings":"AAAA,SAKEA,IAAI,QAEC,oBAAmB;AAE1B,SACEC,kBAAkB,QAGb,oCAAmC;AAC1C,SAASC,QAAQ,QAA0B,YAAW;AAGtD,OAAO,MAAMC,kBAGHD;IACR,OAAOE,QAGL,GAAGC,OAAU,EAAE;QACf,OAAO,IAAIF,UACTH,KAAKM,KAAK,CAACD,QAAQE,GAAG,CAAC,CAACC,IAAMA,EAAEC,MAAM,IACtC;YACEJ;QACF;IAEJ;AACF;AAEA,OAAO,MAAMK,yBAGHR;IAKR,OAAOE,QAGL,GAAGC,OAAU,EAAE;QACf,OAAO,IAAIK,iBACTV,KAAKW,SAAS,CAACN,QAAQE,GAAG,CAAC,CAACC,IAAMA,EAAEC,MAAM,IAC1C;YAAEJ;QAAQ;IAEd;AACF;AAMA,OAAO,MAAMO,+BAKHV;IAQR,OAAOE,QAOLS,GAAM,EAAE,GAAGR,OAAU,EAAE;QACvB,OAAO,IAAIO,uBACTX,mBAAmBY,KAAKR,QAAQE,GAAG,CAAC,CAACC,IAAMA,EAAEC,MAAM,IACnD;YAAEI;YAAKR;QAAQ;IAEnB;AACF"}
|
package/package.json
CHANGED
|
@@ -12,21 +12,21 @@
|
|
|
12
12
|
"default": "./dist/compiler.js",
|
|
13
13
|
"types": "./src/compiler.ts"
|
|
14
14
|
},
|
|
15
|
+
"./runtime": {
|
|
16
|
+
"bun": "./src/runtime.ts",
|
|
17
|
+
"default": "./dist/runtime.js",
|
|
18
|
+
"types": "./src/runtime.ts"
|
|
19
|
+
},
|
|
15
20
|
"./temporal": {
|
|
16
21
|
"bun": "./src/temporal.ts",
|
|
17
22
|
"default": "./dist/temporal.js",
|
|
18
23
|
"types": "./src/temporal.ts"
|
|
19
24
|
}
|
|
20
25
|
},
|
|
21
|
-
"
|
|
22
|
-
"@sinclair/typebox": "^0.34.13",
|
|
23
|
-
"temporal-polyfill": "^0.2.5",
|
|
24
|
-
"@nmtjs/common": "0.5.2"
|
|
25
|
-
},
|
|
26
|
-
"devDependencies": {
|
|
26
|
+
"dependencies": {
|
|
27
27
|
"@sinclair/typebox": "^0.34.13",
|
|
28
28
|
"temporal-polyfill": "^0.2.5",
|
|
29
|
-
"@nmtjs/common": "0.
|
|
29
|
+
"@nmtjs/common": "0.6.0"
|
|
30
30
|
},
|
|
31
31
|
"files": [
|
|
32
32
|
"src",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"LICENSE.md",
|
|
36
36
|
"README.md"
|
|
37
37
|
],
|
|
38
|
-
"version": "0.
|
|
38
|
+
"version": "0.6.0",
|
|
39
39
|
"scripts": {
|
|
40
40
|
"build": "neemata-build -p neutral --root=./src './**/*.ts'",
|
|
41
41
|
"type-check": "tsc --noEmit"
|