@nmtjs/type 0.2.1 → 0.3.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.
Files changed (55) hide show
  1. package/dist/compiler.js +2 -2
  2. package/dist/compiler.js.map +1 -1
  3. package/dist/constants.js +2 -0
  4. package/dist/constants.js.map +1 -0
  5. package/dist/index.js +2 -3
  6. package/dist/index.js.map +1 -1
  7. package/dist/temporal.js +3 -1
  8. package/dist/temporal.js.map +1 -1
  9. package/dist/types/any.js +37 -5
  10. package/dist/types/any.js.map +1 -1
  11. package/dist/types/array.js +55 -24
  12. package/dist/types/array.js.map +1 -1
  13. package/dist/types/base.js +31 -62
  14. package/dist/types/base.js.map +1 -1
  15. package/dist/types/boolean.js +37 -5
  16. package/dist/types/boolean.js.map +1 -1
  17. package/dist/types/custom.js +37 -8
  18. package/dist/types/custom.js.map +1 -1
  19. package/dist/types/datetime.js +41 -22
  20. package/dist/types/datetime.js.map +1 -1
  21. package/dist/types/enum.js +74 -16
  22. package/dist/types/enum.js.map +1 -1
  23. package/dist/types/literal.js +35 -8
  24. package/dist/types/literal.js.map +1 -1
  25. package/dist/types/never.js +17 -2
  26. package/dist/types/never.js.map +1 -1
  27. package/dist/types/number.js +116 -62
  28. package/dist/types/number.js.map +1 -1
  29. package/dist/types/object.js +58 -17
  30. package/dist/types/object.js.map +1 -1
  31. package/dist/types/string.js +57 -21
  32. package/dist/types/string.js.map +1 -1
  33. package/dist/types/temporal.js +292 -74
  34. package/dist/types/temporal.js.map +1 -1
  35. package/dist/types/union.js +75 -17
  36. package/dist/types/union.js.map +1 -1
  37. package/package.json +3 -3
  38. package/src/compiler.ts +2 -2
  39. package/src/constants.ts +5 -0
  40. package/src/index.ts +5 -6
  41. package/src/temporal.ts +4 -2
  42. package/src/types/any.ts +32 -9
  43. package/src/types/array.ts +59 -28
  44. package/src/types/base.ts +59 -112
  45. package/src/types/boolean.ts +31 -9
  46. package/src/types/custom.ts +61 -24
  47. package/src/types/datetime.ts +40 -35
  48. package/src/types/enum.ts +78 -21
  49. package/src/types/literal.ts +42 -12
  50. package/src/types/never.ts +24 -11
  51. package/src/types/number.ts +103 -67
  52. package/src/types/object.ts +87 -32
  53. package/src/types/string.ts +38 -30
  54. package/src/types/temporal.ts +378 -118
  55. package/src/types/union.ts +103 -31
package/dist/compiler.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { TypeCompiler } from '@sinclair/typebox/compiler';
2
2
  import { Value } from '@sinclair/typebox/value';
3
- import { typeFinalSchema } from "./types/base.js";
3
+ import { getTypeSchema } from "./types/base.js";
4
4
  const compileType = (type)=>{
5
- const schema = type[typeFinalSchema];
5
+ const schema = getTypeSchema(type);
6
6
  const compiled = TypeCompiler.Compile(schema);
7
7
  const prepare = (value)=>{
8
8
  for (const fn of [
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/compiler.ts"],"sourcesContent":["import {\n TypeCompiler,\n type ValueErrorIterator,\n} from '@sinclair/typebox/compiler'\nimport { Value } from '@sinclair/typebox/value'\nimport { type BaseType, typeFinalSchema } from './types/base.ts'\n\nexport type Compiled = {\n check: (val: unknown) => boolean\n errors: (val: unknown) => ValueErrorIterator\n prepare: (val: unknown) => unknown\n convert: (val: unknown) => unknown\n decode: (\n val: unknown,\n ) => { success: true; value: unknown } | { success: false; error: any }\n encode: (\n val: unknown,\n ) => { success: true; value: unknown } | { success: false; error: any }\n}\n\nconst compileType = (type: BaseType) => {\n const schema = type[typeFinalSchema]\n const compiled = TypeCompiler.Compile(schema)\n const prepare = (value: any) => {\n for (const fn of [Value.Clean, Value.Default]) {\n value = fn(schema, value)\n }\n return value\n }\n const convert = (value: any) => Value.Convert(schema, value)\n return {\n check: compiled.Check.bind(compiled),\n errors: compiled.Errors.bind(compiled),\n decode: compiled.Decode.bind(compiled),\n encode: compiled.Encode.bind(compiled),\n prepare,\n convert,\n }\n}\n\nexport const compile = (schema: BaseType): Compiled => {\n const compiled = compileType(schema)\n\n // TODO: custom error handling/shaping\n return {\n ...compiled,\n decode: (val) => {\n try {\n return {\n success: true as const,\n value: compiled.decode(compiled.prepare(val)),\n }\n } catch (error) {\n return { success: false as const, error }\n }\n },\n encode: (val) => {\n try {\n return {\n success: true as const,\n value: compiled.encode(compiled.prepare(val)),\n }\n } catch (error) {\n return { success: false as const, error }\n }\n },\n }\n}\n"],"names":["TypeCompiler","Value","typeFinalSchema","compileType","type","schema","compiled","Compile","prepare","value","fn","Clean","Default","convert","Convert","check","Check","bind","errors","Errors","decode","Decode","encode","Encode","compile","val","success","error"],"mappings":"AAAA,SACEA,YAAY,QAEP,6BAA4B;AACnC,SAASC,KAAK,QAAQ,0BAAyB;AAC/C,SAAwBC,eAAe,QAAQ,kBAAiB;AAehE,MAAMC,cAAc,CAACC;IACnB,MAAMC,SAASD,IAAI,CAACF,gBAAgB;IACpC,MAAMI,WAAWN,aAAaO,OAAO,CAACF;IACtC,MAAMG,UAAU,CAACC;QACf,KAAK,MAAMC,MAAM;YAACT,MAAMU,KAAK;YAAEV,MAAMW,OAAO;SAAC,CAAE;YAC7CH,QAAQC,GAAGL,QAAQI;QACrB;QACA,OAAOA;IACT;IACA,MAAMI,UAAU,CAACJ,QAAeR,MAAMa,OAAO,CAACT,QAAQI;IACtD,OAAO;QACLM,OAAOT,SAASU,KAAK,CAACC,IAAI,CAACX;QAC3BY,QAAQZ,SAASa,MAAM,CAACF,IAAI,CAACX;QAC7Bc,QAAQd,SAASe,MAAM,CAACJ,IAAI,CAACX;QAC7BgB,QAAQhB,SAASiB,MAAM,CAACN,IAAI,CAACX;QAC7BE;QACAK;IACF;AACF;AAEA,OAAO,MAAMW,UAAU,CAACnB;IACtB,MAAMC,WAAWH,YAAYE;IAG7B,OAAO;QACL,GAAGC,QAAQ;QACXc,QAAQ,CAACK;YACP,IAAI;gBACF,OAAO;oBACLC,SAAS;oBACTjB,OAAOH,SAASc,MAAM,CAACd,SAASE,OAAO,CAACiB;gBAC1C;YACF,EAAE,OAAOE,OAAO;gBACd,OAAO;oBAAED,SAAS;oBAAgBC;gBAAM;YAC1C;QACF;QACAL,QAAQ,CAACG;YACP,IAAI;gBACF,OAAO;oBACLC,SAAS;oBACTjB,OAAOH,SAASgB,MAAM,CAAChB,SAASE,OAAO,CAACiB;gBAC1C;YACF,EAAE,OAAOE,OAAO;gBACd,OAAO;oBAAED,SAAS;oBAAgBC;gBAAM;YAC1C;QACF;IACF;AACF,EAAC"}
1
+ {"version":3,"sources":["../../src/compiler.ts"],"sourcesContent":["import {\n TypeCompiler,\n type ValueErrorIterator,\n} from '@sinclair/typebox/compiler'\nimport { Value } from '@sinclair/typebox/value'\nimport { type BaseType, getTypeSchema } from './types/base.ts'\n\nexport type Compiled = {\n check: (val: unknown) => boolean\n errors: (val: unknown) => ValueErrorIterator\n prepare: (val: unknown) => unknown\n convert: (val: unknown) => unknown\n decode: (\n val: unknown,\n ) => { success: true; value: unknown } | { success: false; error: any }\n encode: (\n val: unknown,\n ) => { success: true; value: unknown } | { success: false; error: any }\n}\n\nconst compileType = (type: BaseType) => {\n const schema = getTypeSchema(type)\n const compiled = TypeCompiler.Compile(schema)\n const prepare = (value: any) => {\n for (const fn of [Value.Clean, Value.Default]) {\n value = fn(schema, value)\n }\n return value\n }\n const convert = (value: any) => Value.Convert(schema, value)\n return {\n check: compiled.Check.bind(compiled),\n errors: compiled.Errors.bind(compiled),\n decode: compiled.Decode.bind(compiled),\n encode: compiled.Encode.bind(compiled),\n prepare,\n convert,\n }\n}\n\nexport const compile = (schema: BaseType): Compiled => {\n const compiled = compileType(schema)\n\n // TODO: custom error handling/shaping\n return {\n ...compiled,\n decode: (val) => {\n try {\n return {\n success: true as const,\n value: compiled.decode(compiled.prepare(val)),\n }\n } catch (error) {\n return { success: false as const, error }\n }\n },\n encode: (val) => {\n try {\n return {\n success: true as const,\n value: compiled.encode(compiled.prepare(val)),\n }\n } catch (error) {\n return { success: false as const, error }\n }\n },\n }\n}\n"],"names":["TypeCompiler","Value","getTypeSchema","compileType","type","schema","compiled","Compile","prepare","value","fn","Clean","Default","convert","Convert","check","Check","bind","errors","Errors","decode","Decode","encode","Encode","compile","val","success","error"],"mappings":"AAAA,SACEA,YAAY,QAEP,6BAA4B;AACnC,SAASC,KAAK,QAAQ,0BAAyB;AAC/C,SAAwBC,aAAa,QAAQ,kBAAiB;AAe9D,MAAMC,cAAc,CAACC;IACnB,MAAMC,SAASH,cAAcE;IAC7B,MAAME,WAAWN,aAAaO,OAAO,CAACF;IACtC,MAAMG,UAAU,CAACC;QACf,KAAK,MAAMC,MAAM;YAACT,MAAMU,KAAK;YAAEV,MAAMW,OAAO;SAAC,CAAE;YAC7CH,QAAQC,GAAGL,QAAQI;QACrB;QACA,OAAOA;IACT;IACA,MAAMI,UAAU,CAACJ,QAAeR,MAAMa,OAAO,CAACT,QAAQI;IACtD,OAAO;QACLM,OAAOT,SAASU,KAAK,CAACC,IAAI,CAACX;QAC3BY,QAAQZ,SAASa,MAAM,CAACF,IAAI,CAACX;QAC7Bc,QAAQd,SAASe,MAAM,CAACJ,IAAI,CAACX;QAC7BgB,QAAQhB,SAASiB,MAAM,CAACN,IAAI,CAACX;QAC7BE;QACAK;IACF;AACF;AAEA,OAAO,MAAMW,UAAU,CAACnB;IACtB,MAAMC,WAAWH,YAAYE;IAG7B,OAAO;QACL,GAAGC,QAAQ;QACXc,QAAQ,CAACK;YACP,IAAI;gBACF,OAAO;oBACLC,SAAS;oBACTjB,OAAOH,SAASc,MAAM,CAACd,SAASE,OAAO,CAACiB;gBAC1C;YACF,EAAE,OAAOE,OAAO;gBACd,OAAO;oBAAED,SAAS;oBAAgBC;gBAAM;YAC1C;QACF;QACAL,QAAQ,CAACG;YACP,IAAI;gBACF,OAAO;oBACLC,SAAS;oBACTjB,OAAOH,SAASgB,MAAM,CAAChB,SAASE,OAAO,CAACiB;gBAC1C;YACF,EAAE,OAAOE,OAAO;gBACd,OAAO;oBAAED,SAAS;oBAAgBC;gBAAM;YAC1C;QACF;IACF;AACF,EAAC"}
@@ -0,0 +1,2 @@
1
+ export const typeStatic = Symbol();
2
+ export const typeSchema = Symbol();
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/constants.ts"],"sourcesContent":["export const typeStatic: unique symbol = Symbol()\nexport type typeStatic = typeof typeStatic\n\nexport const typeSchema: unique symbol = Symbol()\nexport type typeSchema = typeof typeSchema\n"],"names":["typeStatic","Symbol","typeSchema"],"mappings":"AAAA,OAAO,MAAMA,aAA4BC,SAAQ;AAGjD,OAAO,MAAMC,aAA4BD,SAAQ"}
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { ArrayType } from "./types/array.js";
2
2
  import { BooleanType } from "./types/boolean.js";
3
3
  import { CustomType } from "./types/custom.js";
4
- import { DateTimeType, DateType } from "./types/datetime.js";
4
+ import { DateType } from "./types/datetime.js";
5
5
  import { EnumType, NativeEnumType } from "./types/enum.js";
6
6
  import { LiteralType } from "./types/literal.js";
7
7
  import { IntegerType, NumberType } from "./types/number.js";
@@ -16,7 +16,7 @@ export * from "./schemas/native-enum.js";
16
16
  export * from "./schemas/union-enum.js";
17
17
  export * from "./schemas/nullable.js";
18
18
  export { BaseType, getTypeSchema } from "./types/base.js";
19
- export { ArrayType, BooleanType, CustomType, DateTimeType, DateType, EnumType, LiteralType, IntegerType, NumberType, ObjectType, StringType, IntersactionType, UnionType, AnyType, NeverType, };
19
+ export { ArrayType, BooleanType, CustomType, DateType, EnumType, LiteralType, IntegerType, NumberType, ObjectType, StringType, IntersactionType, UnionType, AnyType, NeverType, };
20
20
  export var t;
21
21
  (function(t) {
22
22
  t.never = ()=>new NeverType();
@@ -28,7 +28,6 @@ export var t;
28
28
  t.nativeEnum = (enumLike)=>new NativeEnumType(enumLike);
29
29
  t.arrayEnum = (enumLike)=>new EnumType(enumLike);
30
30
  t.date = ()=>new DateType();
31
- t.datetime = ()=>new DateTimeType();
32
31
  t.array = (element)=>new ArrayType(element);
33
32
  t.object = (properties)=>new ObjectType(properties);
34
33
  t.any = ()=>new AnyType();
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["import type { TLiteralValue } from '@sinclair/typebox'\nimport { ArrayType } from './types/array.ts'\nimport type { BaseType, staticType } from './types/base.ts'\nimport { BooleanType } from './types/boolean.ts'\nimport { CustomType } from './types/custom.ts'\nimport { DateTimeType, DateType } from './types/datetime.ts'\nimport { EnumType, NativeEnumType } from './types/enum.ts'\nimport { LiteralType } from './types/literal.ts'\nimport { IntegerType, NumberType } from './types/number.ts'\nimport { ObjectType } from './types/object.ts'\nimport { StringType } from './types/string.ts'\nimport { IntersactionType, UnionType } from './types/union.ts'\n\n// register ajv formats\nimport { register } from './formats.ts'\nimport { AnyType } from './types/any.ts'\nimport { NeverType } from './types/never.ts'\nregister()\n\nexport * from './schemas/native-enum.ts'\nexport * from './schemas/union-enum.ts'\nexport * from './schemas/nullable.ts'\nexport {\n BaseType,\n getTypeSchema,\n} from './types/base.ts'\nexport { type TSchema } from '@sinclair/typebox'\nexport {\n ArrayType,\n BooleanType,\n CustomType,\n DateTimeType,\n DateType,\n EnumType,\n LiteralType,\n IntegerType,\n NumberType,\n ObjectType,\n StringType,\n IntersactionType,\n UnionType,\n AnyType,\n NeverType,\n}\n\nexport namespace t {\n export namespace infer {\n export type decoded<T extends BaseType> = T[staticType]['decoded']\n export type encoded<T extends BaseType> = T[staticType]['encoded']\n }\n export const never = () => new NeverType()\n export const boolean = () => new BooleanType()\n export const string = () => new StringType()\n export const number = () => new NumberType()\n export const integer = () => new IntegerType()\n export const literal = <T extends TLiteralValue>(value: T) =>\n new LiteralType(value)\n export const nativeEnum = <T extends { [K in string]: K }>(enumLike: T) =>\n new NativeEnumType(enumLike)\n export const arrayEnum = <T extends (string | number)[]>(enumLike: [...T]) =>\n new EnumType(enumLike)\n export const date = () => new DateType()\n export const datetime = () => new DateTimeType()\n export const array = <T extends BaseType>(element: T) =>\n new ArrayType(element)\n export const object = <T extends Record<string, BaseType>>(properties: T) =>\n new ObjectType(properties)\n export const any = () => new AnyType()\n export const or = <T extends [BaseType, BaseType, ...BaseType[]]>(\n ...types: T\n ) => new UnionType(types)\n export const and = <T extends [BaseType, BaseType, ...BaseType[]]>(\n ...types: T\n ) => new IntersactionType(types)\n export const custom = <T>(\n decode: (value: any) => T,\n encode: (value: T) => any,\n ) => new CustomType<T>(decode, encode)\n}\n"],"names":["ArrayType","BooleanType","CustomType","DateTimeType","DateType","EnumType","NativeEnumType","LiteralType","IntegerType","NumberType","ObjectType","StringType","IntersactionType","UnionType","register","AnyType","NeverType","BaseType","getTypeSchema","t","never","boolean","string","number","integer","literal","value","nativeEnum","enumLike","arrayEnum","date","datetime","array","element","object","properties","any","or","types","and","custom","decode","encode"],"mappings":"AACA,SAASA,SAAS,QAAQ,mBAAkB;AAE5C,SAASC,WAAW,QAAQ,qBAAoB;AAChD,SAASC,UAAU,QAAQ,oBAAmB;AAC9C,SAASC,YAAY,EAAEC,QAAQ,QAAQ,sBAAqB;AAC5D,SAASC,QAAQ,EAAEC,cAAc,QAAQ,kBAAiB;AAC1D,SAASC,WAAW,QAAQ,qBAAoB;AAChD,SAASC,WAAW,EAAEC,UAAU,QAAQ,oBAAmB;AAC3D,SAASC,UAAU,QAAQ,oBAAmB;AAC9C,SAASC,UAAU,QAAQ,oBAAmB;AAC9C,SAASC,gBAAgB,EAAEC,SAAS,QAAQ,mBAAkB;AAG9D,SAASC,QAAQ,QAAQ,eAAc;AACvC,SAASC,OAAO,QAAQ,iBAAgB;AACxC,SAASC,SAAS,QAAQ,mBAAkB;AAC5CF;AAEA,cAAc,2BAA0B;AACxC,cAAc,0BAAyB;AACvC,cAAc,wBAAuB;AACrC,SACEG,QAAQ,EACRC,aAAa,QACR,kBAAiB;AAExB,SACElB,SAAS,EACTC,WAAW,EACXC,UAAU,EACVC,YAAY,EACZC,QAAQ,EACRC,QAAQ,EACRE,WAAW,EACXC,WAAW,EACXC,UAAU,EACVC,UAAU,EACVC,UAAU,EACVC,gBAAgB,EAChBC,SAAS,EACTE,OAAO,EACPC,SAAS,KACV;;UAEgBG;MAKFC,QAAQ,IAAM,IAAIJ;MAClBK,UAAU,IAAM,IAAIpB;MACpBqB,SAAS,IAAM,IAAIX;MACnBY,SAAS,IAAM,IAAId;MACnBe,UAAU,IAAM,IAAIhB;MACpBiB,UAAU,CAA0BC,QAC/C,IAAInB,YAAYmB;MACLC,aAAa,CAAiCC,WACzD,IAAItB,eAAesB;MACRC,YAAY,CAAgCD,WACvD,IAAIvB,SAASuB;MACFE,OAAO,IAAM,IAAI1B;MACjB2B,WAAW,IAAM,IAAI5B;MACrB6B,QAAQ,CAAqBC,UACxC,IAAIjC,UAAUiC;MACHC,SAAS,CAAqCC,aACzD,IAAIzB,WAAWyB;MACJC,MAAM,IAAM,IAAIrB;MAChBsB,KAAK,CAChB,GAAGC,QACA,IAAIzB,UAAUyB;MACNC,MAAM,CACjB,GAAGD,QACA,IAAI1B,iBAAiB0B;MACbE,SAAS,CACpBC,QACAC,SACG,IAAIxC,WAAcuC,QAAQC;AACjC,GAjCiBvB,MAAAA"}
1
+ {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["import type { TLiteralValue } from '@sinclair/typebox'\nimport { ArrayType } from './types/array.ts'\nimport type { BaseType } from './types/base.ts'\nimport { BooleanType } from './types/boolean.ts'\nimport { CustomType } from './types/custom.ts'\nimport { DateType } from './types/datetime.ts'\nimport { EnumType, NativeEnumType } from './types/enum.ts'\nimport { LiteralType } from './types/literal.ts'\nimport { IntegerType, NumberType } from './types/number.ts'\nimport { ObjectType } from './types/object.ts'\nimport { StringType } from './types/string.ts'\nimport { IntersactionType, UnionType } from './types/union.ts'\n\nimport type { typeStatic } from './constants.ts'\n// register ajv formats\nimport { register } from './formats.ts'\nimport { AnyType } from './types/any.ts'\nimport { NeverType } from './types/never.ts'\nregister()\n\nexport * from './schemas/native-enum.ts'\nexport * from './schemas/union-enum.ts'\nexport * from './schemas/nullable.ts'\nexport {\n BaseType,\n getTypeSchema,\n} from './types/base.ts'\nexport { type TSchema } from '@sinclair/typebox'\nexport {\n ArrayType,\n BooleanType,\n CustomType,\n DateType,\n EnumType,\n LiteralType,\n IntegerType,\n NumberType,\n ObjectType,\n StringType,\n IntersactionType,\n UnionType,\n AnyType,\n NeverType,\n}\n\nexport namespace t {\n export namespace infer {\n export type decoded<T extends BaseType> = T[typeStatic]['decoded']\n export type encoded<T extends BaseType> = T[typeStatic]['encoded']\n }\n export const never = () => new NeverType()\n export const boolean = () => new BooleanType()\n export const string = () => new StringType()\n export const number = () => new NumberType()\n export const integer = () => new IntegerType()\n export const literal = <T extends TLiteralValue>(value: T) =>\n new LiteralType(value)\n export const nativeEnum = <T extends { [K in string]: K }>(enumLike: T) =>\n new NativeEnumType(enumLike)\n export const arrayEnum = <T extends (string | number)[]>(enumLike: [...T]) =>\n new EnumType(enumLike)\n export const date = () => new DateType()\n export const array = <T extends BaseType>(element: T) =>\n new ArrayType(element)\n export const object = <T extends Record<string, BaseType>>(properties: T) =>\n new ObjectType(properties)\n export const any = () => new AnyType()\n export const or = <T extends [BaseType, BaseType, ...BaseType[]]>(\n ...types: T\n ) => new UnionType(types)\n export const and = <T extends [BaseType, BaseType, ...BaseType[]]>(\n ...types: T\n ) => new IntersactionType(types)\n export const custom = <T>(\n decode: (value: any) => T,\n encode: (value: T) => any,\n ) => new CustomType<T>(decode, encode)\n}\n"],"names":["ArrayType","BooleanType","CustomType","DateType","EnumType","NativeEnumType","LiteralType","IntegerType","NumberType","ObjectType","StringType","IntersactionType","UnionType","register","AnyType","NeverType","BaseType","getTypeSchema","t","never","boolean","string","number","integer","literal","value","nativeEnum","enumLike","arrayEnum","date","array","element","object","properties","any","or","types","and","custom","decode","encode"],"mappings":"AACA,SAASA,SAAS,QAAQ,mBAAkB;AAE5C,SAASC,WAAW,QAAQ,qBAAoB;AAChD,SAASC,UAAU,QAAQ,oBAAmB;AAC9C,SAASC,QAAQ,QAAQ,sBAAqB;AAC9C,SAASC,QAAQ,EAAEC,cAAc,QAAQ,kBAAiB;AAC1D,SAASC,WAAW,QAAQ,qBAAoB;AAChD,SAASC,WAAW,EAAEC,UAAU,QAAQ,oBAAmB;AAC3D,SAASC,UAAU,QAAQ,oBAAmB;AAC9C,SAASC,UAAU,QAAQ,oBAAmB;AAC9C,SAASC,gBAAgB,EAAEC,SAAS,QAAQ,mBAAkB;AAI9D,SAASC,QAAQ,QAAQ,eAAc;AACvC,SAASC,OAAO,QAAQ,iBAAgB;AACxC,SAASC,SAAS,QAAQ,mBAAkB;AAC5CF;AAEA,cAAc,2BAA0B;AACxC,cAAc,0BAAyB;AACvC,cAAc,wBAAuB;AACrC,SACEG,QAAQ,EACRC,aAAa,QACR,kBAAiB;AAExB,SACEjB,SAAS,EACTC,WAAW,EACXC,UAAU,EACVC,QAAQ,EACRC,QAAQ,EACRE,WAAW,EACXC,WAAW,EACXC,UAAU,EACVC,UAAU,EACVC,UAAU,EACVC,gBAAgB,EAChBC,SAAS,EACTE,OAAO,EACPC,SAAS,KACV;;UAEgBG;MAKFC,QAAQ,IAAM,IAAIJ;MAClBK,UAAU,IAAM,IAAInB;MACpBoB,SAAS,IAAM,IAAIX;MACnBY,SAAS,IAAM,IAAId;MACnBe,UAAU,IAAM,IAAIhB;MACpBiB,UAAU,CAA0BC,QAC/C,IAAInB,YAAYmB;MACLC,aAAa,CAAiCC,WACzD,IAAItB,eAAesB;MACRC,YAAY,CAAgCD,WACvD,IAAIvB,SAASuB;MACFE,OAAO,IAAM,IAAI1B;MACjB2B,QAAQ,CAAqBC,UACxC,IAAI/B,UAAU+B;MACHC,SAAS,CAAqCC,aACzD,IAAIxB,WAAWwB;MACJC,MAAM,IAAM,IAAIpB;MAChBqB,KAAK,CAChB,GAAGC,QACA,IAAIxB,UAAUwB;MACNC,MAAM,CACjB,GAAGD,QACA,IAAIzB,iBAAiByB;MACbE,SAAS,CACpBC,QACAC,SACG,IAAItC,WAAcqC,QAAQC;AACjC,GAhCiBtB,MAAAA"}
package/dist/temporal.js CHANGED
@@ -1,5 +1,6 @@
1
+ import { t as baseT } from "./index.js";
1
2
  import { DurationType, PlainDateTimeType, PlainDateType, PlainMonthDayType, PlainTimeType, PlainYearMonthType, ZonedDateTimeType } from "./types/temporal.js";
2
- export function extend(value) {
3
+ function extend(value) {
3
4
  return Object.assign({}, value, {
4
5
  temporal: {
5
6
  plainDate: ()=>new PlainDateType(),
@@ -12,4 +13,5 @@ export function extend(value) {
12
13
  }
13
14
  });
14
15
  }
16
+ export const t = extend(baseT);
15
17
  export { DurationType, PlainDateTimeType, PlainDateType, PlainMonthDayType, PlainTimeType, PlainYearMonthType, ZonedDateTimeType, };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/temporal.ts"],"sourcesContent":["import type { t } from './index.ts'\nimport {\n DurationType,\n PlainDateTimeType,\n PlainDateType,\n PlainMonthDayType,\n PlainTimeType,\n PlainYearMonthType,\n ZonedDateTimeType,\n} from './types/temporal.ts'\n\nexport function extend<T extends typeof t>(value: T) {\n return Object.assign({}, value, {\n temporal: {\n plainDate: () => new PlainDateType(),\n plainDatetime: () => new PlainDateTimeType(),\n plainTime: () => new PlainTimeType(),\n zonedDatetime: () => new ZonedDateTimeType(),\n duration: () => new DurationType(),\n plainYearMonth: () => new PlainYearMonthType(),\n plainMonthDay: () => new PlainMonthDayType(),\n },\n })\n}\n\nexport {\n DurationType,\n PlainDateTimeType,\n PlainDateType,\n PlainMonthDayType,\n PlainTimeType,\n PlainYearMonthType,\n ZonedDateTimeType,\n}\n"],"names":["DurationType","PlainDateTimeType","PlainDateType","PlainMonthDayType","PlainTimeType","PlainYearMonthType","ZonedDateTimeType","extend","value","Object","assign","temporal","plainDate","plainDatetime","plainTime","zonedDatetime","duration","plainYearMonth","plainMonthDay"],"mappings":"AACA,SACEA,YAAY,EACZC,iBAAiB,EACjBC,aAAa,EACbC,iBAAiB,EACjBC,aAAa,EACbC,kBAAkB,EAClBC,iBAAiB,QACZ,sBAAqB;AAE5B,OAAO,SAASC,OAA2BC,KAAQ;IACjD,OAAOC,OAAOC,MAAM,CAAC,CAAC,GAAGF,OAAO;QAC9BG,UAAU;YACRC,WAAW,IAAM,IAAIV;YACrBW,eAAe,IAAM,IAAIZ;YACzBa,WAAW,IAAM,IAAIV;YACrBW,eAAe,IAAM,IAAIT;YACzBU,UAAU,IAAM,IAAIhB;YACpBiB,gBAAgB,IAAM,IAAIZ;YAC1Ba,eAAe,IAAM,IAAIf;QAC3B;IACF;AACF;AAEA,SACEH,YAAY,EACZC,iBAAiB,EACjBC,aAAa,EACbC,iBAAiB,EACjBC,aAAa,EACbC,kBAAkB,EAClBC,iBAAiB,KAClB"}
1
+ {"version":3,"sources":["../../src/temporal.ts"],"sourcesContent":["import { t as baseT } from './index.ts'\nimport {\n DurationType,\n PlainDateTimeType,\n PlainDateType,\n PlainMonthDayType,\n PlainTimeType,\n PlainYearMonthType,\n ZonedDateTimeType,\n} from './types/temporal.ts'\n\nfunction extend<T extends typeof baseT>(value: T) {\n return Object.assign({}, value, {\n temporal: {\n plainDate: () => new PlainDateType(),\n plainDatetime: () => new PlainDateTimeType(),\n plainTime: () => new PlainTimeType(),\n zonedDatetime: () => new ZonedDateTimeType(),\n duration: () => new DurationType(),\n plainYearMonth: () => new PlainYearMonthType(),\n plainMonthDay: () => new PlainMonthDayType(),\n },\n })\n}\n\nexport const t = extend(baseT)\n\nexport {\n DurationType,\n PlainDateTimeType,\n PlainDateType,\n PlainMonthDayType,\n PlainTimeType,\n PlainYearMonthType,\n ZonedDateTimeType,\n}\n"],"names":["t","baseT","DurationType","PlainDateTimeType","PlainDateType","PlainMonthDayType","PlainTimeType","PlainYearMonthType","ZonedDateTimeType","extend","value","Object","assign","temporal","plainDate","plainDatetime","plainTime","zonedDatetime","duration","plainYearMonth","plainMonthDay"],"mappings":"AAAA,SAASA,KAAKC,KAAK,QAAQ,aAAY;AACvC,SACEC,YAAY,EACZC,iBAAiB,EACjBC,aAAa,EACbC,iBAAiB,EACjBC,aAAa,EACbC,kBAAkB,EAClBC,iBAAiB,QACZ,sBAAqB;AAE5B,SAASC,OAA+BC,KAAQ;IAC9C,OAAOC,OAAOC,MAAM,CAAC,CAAC,GAAGF,OAAO;QAC9BG,UAAU;YACRC,WAAW,IAAM,IAAIV;YACrBW,eAAe,IAAM,IAAIZ;YACzBa,WAAW,IAAM,IAAIV;YACrBW,eAAe,IAAM,IAAIT;YACzBU,UAAU,IAAM,IAAIhB;YACpBiB,gBAAgB,IAAM,IAAIZ;YAC1Ba,eAAe,IAAM,IAAIf;QAC3B;IACF;AACF;AAEA,OAAO,MAAML,IAAIS,OAAOR,OAAM;AAE9B,SACEC,YAAY,EACZC,iBAAiB,EACjBC,aAAa,EACbC,iBAAiB,EACjBC,aAAa,EACbC,kBAAkB,EAClBC,iBAAiB,KAClB"}
package/dist/types/any.js CHANGED
@@ -1,16 +1,48 @@
1
1
  import { Type } from '@sinclair/typebox';
2
2
  import { BaseType } from "./base.js";
3
3
  export class AnyType extends BaseType {
4
- constructor(schema = Type.Any(), nullable = false, optional = false){
5
- super(schema, nullable, optional);
4
+ constructor(options = {}, isNullable = false, isOptional = false, hasDefault = false){
5
+ super(options, isNullable, isOptional, hasDefault);
6
+ }
7
+ _constructSchema(options) {
8
+ return Type.Any(options);
6
9
  }
7
10
  nullable() {
8
- return new AnyType(...this._nullable());
11
+ return new AnyType(...this._with({
12
+ isNullable: true
13
+ }));
9
14
  }
10
15
  optional() {
11
- return new AnyType(...this._optional());
16
+ return new AnyType(...this._with({
17
+ isOptional: true
18
+ }));
12
19
  }
13
20
  nullish() {
14
- return new AnyType(...this._nullish());
21
+ return new AnyType(...this._with({
22
+ isNullable: true,
23
+ isOptional: true
24
+ }));
25
+ }
26
+ default(value) {
27
+ return new AnyType(...this._with({
28
+ options: {
29
+ default: value
30
+ },
31
+ hasDefault: true
32
+ }));
33
+ }
34
+ description(description) {
35
+ return new AnyType(...this._with({
36
+ options: {
37
+ description
38
+ }
39
+ }));
40
+ }
41
+ examples(...examples) {
42
+ return new AnyType(...this._with({
43
+ options: {
44
+ examples
45
+ }
46
+ }));
15
47
  }
16
48
  }
@@ -1 +1 @@
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<\n N extends boolean = false,\n O extends boolean = false,\n> extends BaseType<TAny, N, O> {\n constructor(\n schema = Type.Any(),\n nullable: N = false as N,\n optional: O = false as O,\n ) {\n super(schema, nullable, optional)\n }\n\n nullable() {\n return new AnyType(...this._nullable())\n }\n\n optional() {\n return new AnyType(...this._optional())\n }\n\n nullish() {\n return new AnyType(...this._nullish())\n }\n}\n"],"names":["Type","BaseType","AnyType","constructor","schema","Any","nullable","optional","_nullable","_optional","nullish","_nullish"],"mappings":"AAAA,SAAoBA,IAAI,QAAQ,oBAAmB;AACnD,SAASC,QAAQ,QAAQ,YAAW;AAEpC,OAAO,MAAMC,gBAGHD;IACRE,YACEC,SAASJ,KAAKK,GAAG,EAAE,EACnBC,WAAc,KAAU,EACxBC,WAAc,KAAU,CACxB;QACA,KAAK,CAACH,QAAQE,UAAUC;IAC1B;IAEAD,WAAW;QACT,OAAO,IAAIJ,WAAW,IAAI,CAACM,SAAS;IACtC;IAEAD,WAAW;QACT,OAAO,IAAIL,WAAW,IAAI,CAACO,SAAS;IACtC;IAEAC,UAAU;QACR,OAAO,IAAIR,WAAW,IAAI,CAACS,QAAQ;IACrC;AACF"}
1
+ {"version":3,"sources":["../../../src/types/any.ts"],"sourcesContent":["import { type SchemaOptions, type TAny, Type } from '@sinclair/typebox'\nimport { BaseType } from './base.ts'\n\nexport class AnyType<\n N extends boolean = false,\n O extends boolean = false,\n D extends boolean = false,\n> extends BaseType<TAny, N, O, D, SchemaOptions> {\n constructor(\n options: SchemaOptions = {},\n isNullable: N = false as N,\n isOptional: O = false as O,\n hasDefault: D = false as D,\n ) {\n super(options, isNullable, isOptional, hasDefault)\n }\n\n protected _constructSchema(options: SchemaOptions): TAny {\n return Type.Any(options)\n }\n\n nullable() {\n return new AnyType(...this._with({ isNullable: true }))\n }\n\n optional() {\n return new AnyType(...this._with({ isOptional: true }))\n }\n\n nullish() {\n return new AnyType(...this._with({ isNullable: true, isOptional: true }))\n }\n\n default(value: any) {\n return new AnyType(\n ...this._with({\n options: { default: value },\n hasDefault: true,\n }),\n )\n }\n\n description(description: string) {\n return new AnyType(...this._with({ options: { description } }))\n }\n\n examples(...examples: [any, ...any[]]) {\n return new AnyType(...this._with({ options: { examples } }))\n }\n}\n"],"names":["Type","BaseType","AnyType","constructor","options","isNullable","isOptional","hasDefault","_constructSchema","Any","nullable","_with","optional","nullish","default","value","description","examples"],"mappings":"AAAA,SAAwCA,IAAI,QAAQ,oBAAmB;AACvE,SAASC,QAAQ,QAAQ,YAAW;AAEpC,OAAO,MAAMC,gBAIHD;IACRE,YACEC,UAAyB,CAAC,CAAC,EAC3BC,aAAgB,KAAU,EAC1BC,aAAgB,KAAU,EAC1BC,aAAgB,KAAU,CAC1B;QACA,KAAK,CAACH,SAASC,YAAYC,YAAYC;IACzC;IAEUC,iBAAiBJ,OAAsB,EAAQ;QACvD,OAAOJ,KAAKS,GAAG,CAACL;IAClB;IAEAM,WAAW;QACT,OAAO,IAAIR,WAAW,IAAI,CAACS,KAAK,CAAC;YAAEN,YAAY;QAAK;IACtD;IAEAO,WAAW;QACT,OAAO,IAAIV,WAAW,IAAI,CAACS,KAAK,CAAC;YAAEL,YAAY;QAAK;IACtD;IAEAO,UAAU;QACR,OAAO,IAAIX,WAAW,IAAI,CAACS,KAAK,CAAC;YAAEN,YAAY;YAAMC,YAAY;QAAK;IACxE;IAEAQ,QAAQC,KAAU,EAAE;QAClB,OAAO,IAAIb,WACN,IAAI,CAACS,KAAK,CAAC;YACZP,SAAS;gBAAEU,SAASC;YAAM;YAC1BR,YAAY;QACd;IAEJ;IAEAS,YAAYA,WAAmB,EAAE;QAC/B,OAAO,IAAId,WAAW,IAAI,CAACS,KAAK,CAAC;YAAEP,SAAS;gBAAEY;YAAY;QAAE;IAC9D;IAEAC,SAAS,GAAGA,QAAyB,EAAE;QACrC,OAAO,IAAIf,WAAW,IAAI,CAACS,KAAK,CAAC;YAAEP,SAAS;gBAAEa;YAAS;QAAE;IAC3D;AACF"}
@@ -1,42 +1,73 @@
1
1
  import { Type } from '@sinclair/typebox';
2
- import { BaseType, typeFinalSchema } from "./base.js";
2
+ import { BaseType, getTypeSchema } from "./base.js";
3
3
  export class ArrayType extends BaseType {
4
4
  element;
5
- options;
6
- constructor(element, options = {}, nullable = false, optional = false){
7
- super(Type.Array(element[typeFinalSchema]), nullable, optional);
5
+ constructor(element, options = {}, isNullable = false, isOptional = false, hasDefault = false){
6
+ super(options, isNullable, isOptional, hasDefault, element);
8
7
  this.element = element;
9
- this.options = options;
8
+ }
9
+ _constructSchema(options, element) {
10
+ return Type.Array(getTypeSchema(element), options);
10
11
  }
11
12
  nullable() {
12
- const [_, ...args] = this._nullable();
13
- return new ArrayType(this.element, this.options, ...args);
13
+ return new ArrayType(this.element, ...this._with({
14
+ isNullable: true
15
+ }));
14
16
  }
15
17
  optional() {
16
- const [_, ...args] = this._optional();
17
- return new ArrayType(this.element, this.options, ...args);
18
+ return new ArrayType(this.element, ...this._with({
19
+ isOptional: true
20
+ }));
18
21
  }
19
22
  nullish() {
20
- const [_, ...args] = this._nullish();
21
- return new ArrayType(this.element, this.options, ...args);
23
+ return new ArrayType(this.element, ...this._with({
24
+ isNullable: true,
25
+ isOptional: true
26
+ }));
27
+ }
28
+ default(value) {
29
+ return new ArrayType(this.element, ...this._with({
30
+ options: {
31
+ default: value
32
+ },
33
+ hasDefault: true
34
+ }));
35
+ }
36
+ description(description) {
37
+ return new ArrayType(this.element, ...this._with({
38
+ options: {
39
+ description
40
+ }
41
+ }));
42
+ }
43
+ examples(...examples) {
44
+ return new ArrayType(this.element, ...this._with({
45
+ options: {
46
+ example: examples[0],
47
+ examples
48
+ }
49
+ }));
22
50
  }
23
51
  min(value) {
24
- return new ArrayType(this.element, {
25
- ...this.options,
26
- minItems: value
27
- }, ...this._isNullableOptional);
52
+ return new ArrayType(this.element, ...this._with({
53
+ options: {
54
+ minItems: value
55
+ }
56
+ }));
28
57
  }
29
58
  max(value) {
30
- return new ArrayType(this.element, {
31
- ...this.options,
32
- maxItems: value
33
- }, ...this._isNullableOptional);
59
+ return new ArrayType(this.element, ...this._with({
60
+ options: {
61
+ maxItems: value
62
+ }
63
+ }));
34
64
  }
35
65
  length(value) {
36
- return new ArrayType(this.element, {
37
- ...this.options,
38
- minItems: value,
39
- maxItems: value
40
- }, ...this._isNullableOptional);
66
+ return new ArrayType(this.element, ...this._with({
67
+ options: {
68
+ minItems: value,
69
+ maxItems: value
70
+ }
71
+ }));
41
72
  }
42
73
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/types/array.ts"],"sourcesContent":["import { type ArrayOptions, type TArray, Type } from '@sinclair/typebox'\nimport { BaseType, typeFinalSchema } from './base.ts'\n\nexport class ArrayType<\n T extends BaseType = BaseType,\n N extends boolean = false,\n O extends boolean = false,\n> extends BaseType<TArray<T[typeFinalSchema]>, N, O> {\n constructor(\n readonly element: T,\n readonly options: ArrayOptions = {},\n nullable: N = false as N,\n optional: O = false as O,\n ) {\n super(Type.Array(element[typeFinalSchema]), nullable, optional)\n }\n\n nullable() {\n const [_, ...args] = this._nullable()\n return new ArrayType(this.element, this.options, ...args)\n }\n\n optional() {\n const [_, ...args] = this._optional()\n return new ArrayType(this.element, this.options, ...args)\n }\n\n nullish() {\n const [_, ...args] = this._nullish()\n return new ArrayType(this.element, this.options, ...args)\n }\n\n min(value: number) {\n return new ArrayType(\n this.element,\n {\n ...this.options,\n minItems: value,\n },\n ...this._isNullableOptional,\n )\n }\n\n max(value: number) {\n return new ArrayType(\n this.element,\n {\n ...this.options,\n maxItems: value,\n },\n ...this._isNullableOptional,\n )\n }\n\n length(value: number) {\n return new ArrayType(\n this.element,\n {\n ...this.options,\n minItems: value,\n maxItems: value,\n },\n ...this._isNullableOptional,\n )\n }\n}\n"],"names":["Type","BaseType","typeFinalSchema","ArrayType","constructor","element","options","nullable","optional","Array","_","args","_nullable","_optional","nullish","_nullish","min","value","minItems","_isNullableOptional","max","maxItems","length"],"mappings":"AAAA,SAAyCA,IAAI,QAAQ,oBAAmB;AACxE,SAASC,QAAQ,EAAEC,eAAe,QAAQ,YAAW;AAErD,OAAO,MAAMC,kBAIHF;;;IACRG,YACE,AAASC,OAAU,EACnB,AAASC,UAAwB,CAAC,CAAC,EACnCC,WAAc,KAAU,EACxBC,WAAc,KAAU,CACxB;QACA,KAAK,CAACR,KAAKS,KAAK,CAACJ,OAAO,CAACH,gBAAgB,GAAGK,UAAUC;aAL7CH,UAAAA;aACAC,UAAAA;IAKX;IAEAC,WAAW;QACT,MAAM,CAACG,GAAG,GAAGC,KAAK,GAAG,IAAI,CAACC,SAAS;QACnC,OAAO,IAAIT,UAAU,IAAI,CAACE,OAAO,EAAE,IAAI,CAACC,OAAO,KAAKK;IACtD;IAEAH,WAAW;QACT,MAAM,CAACE,GAAG,GAAGC,KAAK,GAAG,IAAI,CAACE,SAAS;QACnC,OAAO,IAAIV,UAAU,IAAI,CAACE,OAAO,EAAE,IAAI,CAACC,OAAO,KAAKK;IACtD;IAEAG,UAAU;QACR,MAAM,CAACJ,GAAG,GAAGC,KAAK,GAAG,IAAI,CAACI,QAAQ;QAClC,OAAO,IAAIZ,UAAU,IAAI,CAACE,OAAO,EAAE,IAAI,CAACC,OAAO,KAAKK;IACtD;IAEAK,IAAIC,KAAa,EAAE;QACjB,OAAO,IAAId,UACT,IAAI,CAACE,OAAO,EACZ;YACE,GAAG,IAAI,CAACC,OAAO;YACfY,UAAUD;QACZ,MACG,IAAI,CAACE,mBAAmB;IAE/B;IAEAC,IAAIH,KAAa,EAAE;QACjB,OAAO,IAAId,UACT,IAAI,CAACE,OAAO,EACZ;YACE,GAAG,IAAI,CAACC,OAAO;YACfe,UAAUJ;QACZ,MACG,IAAI,CAACE,mBAAmB;IAE/B;IAEAG,OAAOL,KAAa,EAAE;QACpB,OAAO,IAAId,UACT,IAAI,CAACE,OAAO,EACZ;YACE,GAAG,IAAI,CAACC,OAAO;YACfY,UAAUD;YACVI,UAAUJ;QACZ,MACG,IAAI,CAACE,mBAAmB;IAE/B;AACF"}
1
+ {"version":3,"sources":["../../../src/types/array.ts"],"sourcesContent":["import { type ArrayOptions, type TArray, Type } from '@sinclair/typebox'\nimport type { typeStatic } from '../constants.ts'\nimport { BaseType, getTypeSchema } from './base.ts'\n\nexport class ArrayType<\n T extends BaseType = BaseType,\n N extends boolean = false,\n O extends boolean = false,\n D extends boolean = false,\n> extends BaseType<TArray<T[typeStatic]['schema']>, N, O, D, ArrayOptions> {\n constructor(\n readonly element: T,\n options: ArrayOptions = {},\n isNullable: N = false as N,\n isOptional: O = false as O,\n hasDefault: D = false as D,\n ) {\n super(options, isNullable, isOptional, hasDefault, element)\n }\n\n protected _constructSchema(\n options: ArrayOptions,\n element: T,\n ): TArray<T[typeStatic]['schema']> {\n return Type.Array(getTypeSchema(element), options)\n }\n\n nullable() {\n return new ArrayType(this.element, ...this._with({ isNullable: true }))\n }\n\n optional() {\n return new ArrayType(this.element, ...this._with({ isOptional: true }))\n }\n\n nullish() {\n return new ArrayType(\n this.element,\n ...this._with({ isNullable: true, isOptional: true }),\n )\n }\n\n default(value: this[typeStatic]['encoded']) {\n return new ArrayType(\n this.element,\n ...this._with({\n options: { default: value },\n hasDefault: true,\n }),\n )\n }\n\n description(description: string) {\n return new ArrayType(\n this.element,\n ...this._with({ options: { description } }),\n )\n }\n\n examples(\n ...examples: [this[typeStatic]['encoded'], ...this[typeStatic]['encoded'][]]\n ) {\n return new ArrayType(\n this.element,\n ...this._with({\n options: { example: examples[0], examples },\n }),\n )\n }\n\n min(value: number) {\n return new ArrayType(\n this.element,\n ...this._with({\n options: { minItems: value },\n }),\n )\n }\n\n max(value: number) {\n return new ArrayType(\n this.element,\n ...this._with({\n options: { maxItems: value },\n }),\n )\n }\n\n length(value: number) {\n return new ArrayType(\n this.element,\n ...this._with({\n options: { minItems: value, maxItems: value },\n }),\n )\n }\n}\n"],"names":["Type","BaseType","getTypeSchema","ArrayType","constructor","element","options","isNullable","isOptional","hasDefault","_constructSchema","Array","nullable","_with","optional","nullish","default","value","description","examples","example","min","minItems","max","maxItems","length"],"mappings":"AAAA,SAAyCA,IAAI,QAAQ,oBAAmB;AAExE,SAASC,QAAQ,EAAEC,aAAa,QAAQ,YAAW;AAEnD,OAAO,MAAMC,kBAKHF;;IACRG,YACE,AAASC,OAAU,EACnBC,UAAwB,CAAC,CAAC,EAC1BC,aAAgB,KAAU,EAC1BC,aAAgB,KAAU,EAC1BC,aAAgB,KAAU,CAC1B;QACA,KAAK,CAACH,SAASC,YAAYC,YAAYC,YAAYJ;aAN1CA,UAAAA;IAOX;IAEUK,iBACRJ,OAAqB,EACrBD,OAAU,EACuB;QACjC,OAAOL,KAAKW,KAAK,CAACT,cAAcG,UAAUC;IAC5C;IAEAM,WAAW;QACT,OAAO,IAAIT,UAAU,IAAI,CAACE,OAAO,KAAK,IAAI,CAACQ,KAAK,CAAC;YAAEN,YAAY;QAAK;IACtE;IAEAO,WAAW;QACT,OAAO,IAAIX,UAAU,IAAI,CAACE,OAAO,KAAK,IAAI,CAACQ,KAAK,CAAC;YAAEL,YAAY;QAAK;IACtE;IAEAO,UAAU;QACR,OAAO,IAAIZ,UACT,IAAI,CAACE,OAAO,KACT,IAAI,CAACQ,KAAK,CAAC;YAAEN,YAAY;YAAMC,YAAY;QAAK;IAEvD;IAEAQ,QAAQC,KAAkC,EAAE;QAC1C,OAAO,IAAId,UACT,IAAI,CAACE,OAAO,KACT,IAAI,CAACQ,KAAK,CAAC;YACZP,SAAS;gBAAEU,SAASC;YAAM;YAC1BR,YAAY;QACd;IAEJ;IAEAS,YAAYA,WAAmB,EAAE;QAC/B,OAAO,IAAIf,UACT,IAAI,CAACE,OAAO,KACT,IAAI,CAACQ,KAAK,CAAC;YAAEP,SAAS;gBAAEY;YAAY;QAAE;IAE7C;IAEAC,SACE,GAAGA,QAAyE,EAC5E;QACA,OAAO,IAAIhB,UACT,IAAI,CAACE,OAAO,KACT,IAAI,CAACQ,KAAK,CAAC;YACZP,SAAS;gBAAEc,SAASD,QAAQ,CAAC,EAAE;gBAAEA;YAAS;QAC5C;IAEJ;IAEAE,IAAIJ,KAAa,EAAE;QACjB,OAAO,IAAId,UACT,IAAI,CAACE,OAAO,KACT,IAAI,CAACQ,KAAK,CAAC;YACZP,SAAS;gBAAEgB,UAAUL;YAAM;QAC7B;IAEJ;IAEAM,IAAIN,KAAa,EAAE;QACjB,OAAO,IAAId,UACT,IAAI,CAACE,OAAO,KACT,IAAI,CAACQ,KAAK,CAAC;YACZP,SAAS;gBAAEkB,UAAUP;YAAM;QAC7B;IAEJ;IAEAQ,OAAOR,KAAa,EAAE;QACpB,OAAO,IAAId,UACT,IAAI,CAACE,OAAO,KACT,IAAI,CAACQ,KAAK,CAAC;YACZP,SAAS;gBAAEgB,UAAUL;gBAAOO,UAAUP;YAAM;QAC9C;IAEJ;AACF"}
@@ -1,77 +1,46 @@
1
1
  import { Type } from '@sinclair/typebox';
2
+ import { typeSchema, typeStatic } from "../constants.js";
2
3
  import { Nullable } from "../schemas/nullable.js";
3
- export const typeSchema = Symbol();
4
- export const typeOptions = Symbol();
5
- export const typeOptional = Symbol();
6
- export const typeNullable = Symbol();
7
- export const staticType = Symbol();
8
- export const typeFinalSchema = Symbol();
9
4
  export class BaseType {
10
- [typeSchema];
11
- [typeNullable];
12
- [typeOptional];
13
- [staticType];
14
- constructor(schema, nullable = false, optional = false){
15
- this[typeSchema] = schema;
16
- this[typeNullable] = nullable;
17
- this[typeOptional] = optional;
18
- }
19
- get [typeFinalSchema]() {
20
- let schema = this._schema;
21
- if (this._isNullable) {
5
+ options;
6
+ isNullable;
7
+ isOptional;
8
+ hasDefault;
9
+ [typeStatic];
10
+ constructor(options = {}, isNullable = false, isOptional = false, hasDefault = false, ...contstructArgs){
11
+ this.options = options;
12
+ this.isNullable = isNullable;
13
+ this.isOptional = isOptional;
14
+ this.hasDefault = hasDefault;
15
+ let schema = this._constructSchema(options, ...contstructArgs);
16
+ if (this.isNullable) {
22
17
  schema = Nullable(schema);
23
18
  }
24
- if (this._isOptional) {
19
+ if (this.isOptional) {
25
20
  schema = Type.Optional(schema);
26
21
  }
27
- return schema;
28
- }
29
- get _schema() {
30
- return this[typeSchema];
31
- }
32
- get _isNullable() {
33
- return this[typeNullable];
34
- }
35
- get _isOptional() {
36
- return this[typeOptional];
22
+ this[typeSchema] = schema;
37
23
  }
38
- get _isNullableOptional() {
24
+ [typeSchema];
25
+ get _args() {
39
26
  return [
40
- this._isNullable,
41
- this._isOptional
27
+ this.isNullable,
28
+ this.isOptional,
29
+ this.hasDefault
42
30
  ];
43
31
  }
44
- _contructSelf(...args) {
45
- return args;
46
- }
47
- _nullable() {
48
- return this._contructSelf(this._schema, true, this[typeOptional]);
49
- }
50
- _optional() {
51
- return this._contructSelf(this._schema, this[typeNullable], true);
52
- }
53
- _nullish() {
54
- return this._contructSelf(this._schema, true, true);
55
- }
56
- default(value) {
57
- return this._contructSelf({
58
- ...this._schema,
59
- default: value
60
- }, this[typeNullable], this[typeOptional]);
61
- }
62
- description(description) {
63
- return this._contructSelf({
64
- ...this._schema,
65
- description
66
- }, this[typeNullable], this[typeOptional]);
67
- }
68
- examples(...examples) {
69
- return this._contructSelf({
70
- ...this._schema,
71
- examples
72
- }, this[typeNullable], this[typeOptional]);
32
+ _with({ options = this.options, isNullable = this.isNullable, isOptional = this.isOptional, hasDefault = this.hasDefault } = {}) {
33
+ return [
34
+ {
35
+ ...this.options,
36
+ ...options
37
+ },
38
+ isNullable,
39
+ isOptional,
40
+ hasDefault
41
+ ];
73
42
  }
74
43
  }
75
44
  export function getTypeSchema(type) {
76
- return type[typeFinalSchema];
45
+ return type[typeSchema];
77
46
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/types/base.ts"],"sourcesContent":["import {\n type StaticDecode,\n type StaticEncode,\n type TAny,\n type TOptional,\n type TSchema,\n Type,\n} from '@sinclair/typebox'\nimport { Nullable, type TNullable } from '../schemas/nullable.ts'\n\nexport const typeSchema: unique symbol = Symbol()\nexport type typeSchema = typeof typeSchema\n\nexport const typeOptions: unique symbol = Symbol()\nexport type typeOptions = typeof typeOptions\n\nexport const typeOptional: unique symbol = Symbol()\nexport type typeOptional = typeof typeOptional\n\nexport const typeNullable: unique symbol = Symbol()\nexport type typeNullable = typeof typeNullable\n\nexport const staticType: unique symbol = Symbol()\nexport type staticType = typeof staticType\n\nexport const typeFinalSchema: unique symbol = Symbol()\nexport type typeFinalSchema = typeof typeFinalSchema\n\ntype ResolveNullable<T extends TSchema, Is extends boolean> = Is extends true\n ? T | TNullable<T>\n : T\n\ntype ResolveOptional<T extends TSchema, Is extends boolean> = Is extends true\n ? T | TOptional<T>\n : T\n\ntype Resolve<\n Schema extends TSchema,\n IsNullable extends boolean,\n IsOptional extends boolean,\n> = ResolveOptional<ResolveNullable<Schema, IsNullable>, IsOptional>\n\nexport abstract class BaseType<\n Schema extends TSchema = any,\n IsNullable extends boolean = boolean,\n IsOptional extends boolean = boolean,\n Final extends Resolve<Schema, IsNullable, IsOptional> = Resolve<\n Schema,\n IsNullable,\n IsOptional\n >,\n> {\n [typeSchema]: Schema;\n [typeNullable]: IsNullable;\n [typeOptional]: IsOptional;\n\n [staticType]!: {\n final: Final\n isOptional: IsOptional\n isNullable: IsNullable\n encoded: StaticEncode<Final>\n decoded: StaticDecode<Final>\n }\n\n constructor(\n schema: Schema,\n nullable: IsNullable = false as IsNullable,\n optional: IsOptional = false as IsOptional,\n ) {\n this[typeSchema] = schema\n this[typeNullable] = nullable\n this[typeOptional] = optional\n }\n\n get [typeFinalSchema](): Final {\n let schema: TSchema = this._schema\n if (this._isNullable) {\n schema = Nullable(schema)\n }\n if (this._isOptional) {\n schema = Type.Optional(schema)\n }\n return schema as Final\n }\n\n protected get _schema() {\n return this[typeSchema]\n }\n\n protected get _isNullable(): IsNullable {\n return this[typeNullable]\n }\n\n protected get _isOptional(): IsOptional {\n return this[typeOptional]\n }\n\n protected get _isNullableOptional(): [IsNullable, IsOptional] {\n return [this._isNullable, this._isOptional]\n }\n\n protected _contructSelf<T extends any[]>(...args: T) {\n return args\n }\n\n protected _nullable() {\n return this._contructSelf(this._schema, true as const, this[typeOptional])\n }\n\n protected _optional() {\n return this._contructSelf(this._schema, this[typeNullable], true as const)\n }\n\n protected _nullish() {\n return this._contructSelf(this._schema, true as const, true as const)\n }\n\n abstract nullable(): BaseType<Schema, true, IsOptional>\n abstract optional(): BaseType<Schema, IsNullable, true>\n abstract nullish(): BaseType<Schema, true, true>\n\n default(value: StaticDecode<Schema>): this {\n return this._contructSelf(\n {\n ...this._schema,\n default: value,\n },\n this[typeNullable],\n this[typeOptional],\n ) as unknown as this\n }\n\n description(description: string): this {\n return this._contructSelf(\n {\n ...this._schema,\n description,\n },\n this[typeNullable],\n this[typeOptional],\n ) as unknown as this\n }\n\n examples(...examples: StaticDecode<Schema>[]): this {\n return this._contructSelf(\n {\n ...this._schema,\n examples,\n },\n this[typeNullable],\n this[typeOptional],\n ) as unknown as this\n }\n}\n\nexport function getTypeSchema<T extends BaseType>(type: T): T[typeFinalSchema] {\n return type[typeFinalSchema]\n}\n"],"names":["Type","Nullable","typeSchema","Symbol","typeOptions","typeOptional","typeNullable","staticType","typeFinalSchema","BaseType","constructor","schema","nullable","optional","_schema","_isNullable","_isOptional","Optional","_isNullableOptional","_contructSelf","args","_nullable","_optional","_nullish","default","value","description","examples","getTypeSchema","type"],"mappings":"AAAA,SAMEA,IAAI,QACC,oBAAmB;AAC1B,SAASC,QAAQ,QAAwB,yBAAwB;AAEjE,OAAO,MAAMC,aAA4BC,SAAQ;AAGjD,OAAO,MAAMC,cAA6BD,SAAQ;AAGlD,OAAO,MAAME,eAA8BF,SAAQ;AAGnD,OAAO,MAAMG,eAA8BH,SAAQ;AAGnD,OAAO,MAAMI,aAA4BJ,SAAQ;AAGjD,OAAO,MAAMK,kBAAiCL,SAAQ;AAiBtD,OAAO,MAAeM;IAUpB,CAACP,WAAW,CAAS;IACrB,CAACI,aAAa,CAAa;IAC3B,CAACD,aAAa,CAAa;IAE3B,CAACE,WAAW,CAMX;IAEDG,YACEC,MAAc,EACdC,WAAuB,KAAmB,EAC1CC,WAAuB,KAAmB,CAC1C;QACA,IAAI,CAACX,WAAW,GAAGS;QACnB,IAAI,CAACL,aAAa,GAAGM;QACrB,IAAI,CAACP,aAAa,GAAGQ;IACvB;IAEA,IAAI,CAACL,gBAAgB,GAAU;QAC7B,IAAIG,SAAkB,IAAI,CAACG,OAAO;QAClC,IAAI,IAAI,CAACC,WAAW,EAAE;YACpBJ,SAASV,SAASU;QACpB;QACA,IAAI,IAAI,CAACK,WAAW,EAAE;YACpBL,SAASX,KAAKiB,QAAQ,CAACN;QACzB;QACA,OAAOA;IACT;IAEA,IAAcG,UAAU;QACtB,OAAO,IAAI,CAACZ,WAAW;IACzB;IAEA,IAAca,cAA0B;QACtC,OAAO,IAAI,CAACT,aAAa;IAC3B;IAEA,IAAcU,cAA0B;QACtC,OAAO,IAAI,CAACX,aAAa;IAC3B;IAEA,IAAca,sBAAgD;QAC5D,OAAO;YAAC,IAAI,CAACH,WAAW;YAAE,IAAI,CAACC,WAAW;SAAC;IAC7C;IAEUG,cAA+B,GAAGC,IAAO,EAAE;QACnD,OAAOA;IACT;IAEUC,YAAY;QACpB,OAAO,IAAI,CAACF,aAAa,CAAC,IAAI,CAACL,OAAO,EAAE,MAAe,IAAI,CAACT,aAAa;IAC3E;IAEUiB,YAAY;QACpB,OAAO,IAAI,CAACH,aAAa,CAAC,IAAI,CAACL,OAAO,EAAE,IAAI,CAACR,aAAa,EAAE;IAC9D;IAEUiB,WAAW;QACnB,OAAO,IAAI,CAACJ,aAAa,CAAC,IAAI,CAACL,OAAO,EAAE,MAAe;IACzD;IAMAU,QAAQC,KAA2B,EAAQ;QACzC,OAAO,IAAI,CAACN,aAAa,CACvB;YACE,GAAG,IAAI,CAACL,OAAO;YACfU,SAASC;QACX,GACA,IAAI,CAACnB,aAAa,EAClB,IAAI,CAACD,aAAa;IAEtB;IAEAqB,YAAYA,WAAmB,EAAQ;QACrC,OAAO,IAAI,CAACP,aAAa,CACvB;YACE,GAAG,IAAI,CAACL,OAAO;YACfY;QACF,GACA,IAAI,CAACpB,aAAa,EAClB,IAAI,CAACD,aAAa;IAEtB;IAEAsB,SAAS,GAAGA,QAAgC,EAAQ;QAClD,OAAO,IAAI,CAACR,aAAa,CACvB;YACE,GAAG,IAAI,CAACL,OAAO;YACfa;QACF,GACA,IAAI,CAACrB,aAAa,EAClB,IAAI,CAACD,aAAa;IAEtB;AACF;AAEA,OAAO,SAASuB,cAAkCC,IAAO;IACvD,OAAOA,IAAI,CAACrB,gBAAgB;AAC9B"}
1
+ {"version":3,"sources":["../../../src/types/base.ts"],"sourcesContent":["import {\n type SchemaOptions,\n type StaticDecode,\n type StaticEncode,\n type TAny,\n type TOptional,\n type TSchema,\n Type,\n} from '@sinclair/typebox'\nimport { typeSchema, typeStatic } from '../constants.ts'\nimport { Nullable, type TNullable } from '../schemas/nullable.ts'\n\ntype ResolveNullable<T extends TSchema, Is extends boolean> = Is extends true\n ? TNullable<T>\n : T\n\ntype ResolveOptional<T extends TSchema, Is extends boolean> = Is extends true\n ? TOptional<T>\n : T\n\ntype Resolve<\n Schema extends TSchema,\n IsNullable extends boolean,\n IsOptional extends boolean,\n> = ResolveOptional<ResolveNullable<Schema, IsNullable>, IsOptional>\n\nexport abstract class BaseType<\n Schema extends TSchema = TSchema,\n IsNullable extends boolean = boolean,\n IsOptional extends boolean = boolean,\n HasDefault extends boolean = boolean,\n Options extends SchemaOptions = SchemaOptions,\n> {\n protected abstract _constructSchema(\n options: Options,\n ...constructArgs: any[]\n ): Schema\n\n [typeStatic]!: {\n schema: Resolve<Schema, IsNullable, IsOptional>\n isOptional: IsOptional\n isNullable: IsNullable\n hasDefault: HasDefault\n encoded: StaticEncode<Resolve<Schema, IsNullable, IsOptional>>\n decoded: StaticDecode<\n Resolve<Schema, IsNullable, HasDefault extends false ? false : IsOptional>\n >\n }\n\n constructor(\n protected options: Options = {} as Options,\n protected isNullable: IsNullable = false as IsNullable,\n protected isOptional: IsOptional = false as IsOptional,\n protected hasDefault: HasDefault = false as HasDefault,\n ...contstructArgs: any[]\n ) {\n let schema: TSchema = this._constructSchema(options, ...contstructArgs)\n if (this.isNullable) {\n schema = Nullable(schema)\n }\n if (this.isOptional) {\n schema = Type.Optional(schema)\n }\n this[typeSchema] = schema as Schema\n }\n protected [typeSchema]: Schema\n\n protected get _args(): [IsNullable, IsOptional, HasDefault] {\n return [this.isNullable, this.isOptional, this.hasDefault]\n }\n\n protected _with<\n _IsNullable extends boolean = IsNullable,\n _IsOptional extends boolean = IsOptional,\n _HasDefault extends boolean = HasDefault,\n >({\n options = this.options as Options,\n isNullable = this.isNullable as unknown as _IsNullable,\n isOptional = this.isOptional as unknown as _IsOptional,\n hasDefault = this.hasDefault as unknown as _HasDefault,\n }: {\n options?: Options\n isNullable?: _IsNullable\n isOptional?: _IsOptional\n hasDefault?: _HasDefault\n } = {}): [Options, _IsNullable, _IsOptional, _HasDefault] {\n return [{ ...this.options, ...options }, isNullable, isOptional, hasDefault]\n }\n\n abstract optional(): BaseType<Schema, IsNullable, true, HasDefault>\n abstract nullish(): BaseType<Schema, true, true, HasDefault>\n abstract default(value: any): BaseType<Schema, IsNullable, IsOptional, true>\n abstract description(\n value: string,\n ): BaseType<Schema, IsNullable, IsOptional, HasDefault>\n abstract examples(\n ...values: any[]\n ): BaseType<Schema, IsNullable, IsOptional, HasDefault>\n}\n\nexport function getTypeSchema<T extends BaseType>(\n type: T,\n): T[typeStatic]['schema'] {\n return type[typeSchema]\n}\n"],"names":["Type","typeSchema","typeStatic","Nullable","BaseType","constructor","options","isNullable","isOptional","hasDefault","contstructArgs","schema","_constructSchema","Optional","_args","_with","getTypeSchema","type"],"mappings":"AAAA,SAOEA,IAAI,QACC,oBAAmB;AAC1B,SAASC,UAAU,EAAEC,UAAU,QAAQ,kBAAiB;AACxD,SAASC,QAAQ,QAAwB,yBAAwB;AAgBjE,OAAO,MAAeC;;;;;IAYpB,CAACF,WAAW,CASX;IAEDG,YACE,AAAUC,UAAmB,CAAC,CAAY,EAC1C,AAAUC,aAAyB,KAAmB,EACtD,AAAUC,aAAyB,KAAmB,EACtD,AAAUC,aAAyB,KAAmB,EACtD,GAAGC,cAAqB,CACxB;aALUJ,UAAAA;aACAC,aAAAA;aACAC,aAAAA;aACAC,aAAAA;QAGV,IAAIE,SAAkB,IAAI,CAACC,gBAAgB,CAACN,YAAYI;QACxD,IAAI,IAAI,CAACH,UAAU,EAAE;YACnBI,SAASR,SAASQ;QACpB;QACA,IAAI,IAAI,CAACH,UAAU,EAAE;YACnBG,SAASX,KAAKa,QAAQ,CAACF;QACzB;QACA,IAAI,CAACV,WAAW,GAAGU;IACrB;IACU,CAACV,WAAW,CAAQ;IAE9B,IAAca,QAA8C;QAC1D,OAAO;YAAC,IAAI,CAACP,UAAU;YAAE,IAAI,CAACC,UAAU;YAAE,IAAI,CAACC,UAAU;SAAC;IAC5D;IAEUM,MAIR,EACAT,UAAU,IAAI,CAACA,OAAO,AAAW,EACjCC,aAAa,IAAI,CAACA,UAAU,AAA0B,EACtDC,aAAa,IAAI,CAACA,UAAU,AAA0B,EACtDC,aAAa,IAAI,CAACA,UAAU,AAA0B,EAMvD,GAAG,CAAC,CAAC,EAAoD;QACxD,OAAO;YAAC;gBAAE,GAAG,IAAI,CAACH,OAAO;gBAAE,GAAGA,OAAO;YAAC;YAAGC;YAAYC;YAAYC;SAAW;IAC9E;AAWF;AAEA,OAAO,SAASO,cACdC,IAAO;IAEP,OAAOA,IAAI,CAAChB,WAAW;AACzB"}
@@ -1,16 +1,48 @@
1
1
  import { Type } from '@sinclair/typebox';
2
2
  import { BaseType } from "./base.js";
3
3
  export class BooleanType extends BaseType {
4
- constructor(schema = Type.Boolean(), nullable = false, optional = false){
5
- super(schema, nullable, optional);
4
+ constructor(options = {}, isNullable = false, isOptional = false, hasDefault = false){
5
+ super(options, isNullable, isOptional, hasDefault);
6
+ }
7
+ _constructSchema(options) {
8
+ return Type.Boolean(options);
6
9
  }
7
10
  nullable() {
8
- return new BooleanType(...this._nullable());
11
+ return new BooleanType(...this._with({
12
+ isNullable: true
13
+ }));
9
14
  }
10
15
  optional() {
11
- return new BooleanType(...this._optional());
16
+ return new BooleanType(...this._with({
17
+ isOptional: true
18
+ }));
12
19
  }
13
20
  nullish() {
14
- return new BooleanType(...this._nullish());
21
+ return new BooleanType(...this._with({
22
+ isNullable: true,
23
+ isOptional: true
24
+ }));
25
+ }
26
+ default(value) {
27
+ return new BooleanType(...this._with({
28
+ options: {
29
+ default: value
30
+ },
31
+ hasDefault: true
32
+ }));
33
+ }
34
+ description(description) {
35
+ return new BooleanType(...this._with({
36
+ options: {
37
+ description
38
+ }
39
+ }));
40
+ }
41
+ examples(...examples) {
42
+ return new BooleanType(...this._with({
43
+ options: {
44
+ examples
45
+ }
46
+ }));
15
47
  }
16
48
  }
@@ -1 +1 @@
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<\n N extends boolean = false,\n O extends boolean = false,\n> extends BaseType<TBoolean, N, O> {\n constructor(\n schema: TBoolean = Type.Boolean(),\n nullable: N = false as N,\n optional: O = false as O,\n ) {\n super(schema, nullable, optional)\n }\n\n nullable() {\n return new BooleanType(...this._nullable())\n }\n\n optional() {\n return new BooleanType(...this._optional())\n }\n\n nullish() {\n return new BooleanType(...this._nullish())\n }\n}\n"],"names":["Type","BaseType","BooleanType","constructor","schema","Boolean","nullable","optional","_nullable","_optional","nullish","_nullish"],"mappings":"AAAA,SAAwBA,IAAI,QAAQ,oBAAmB;AACvD,SAASC,QAAQ,QAAQ,YAAW;AAEpC,OAAO,MAAMC,oBAGHD;IACRE,YACEC,SAAmBJ,KAAKK,OAAO,EAAE,EACjCC,WAAc,KAAU,EACxBC,WAAc,KAAU,CACxB;QACA,KAAK,CAACH,QAAQE,UAAUC;IAC1B;IAEAD,WAAW;QACT,OAAO,IAAIJ,eAAe,IAAI,CAACM,SAAS;IAC1C;IAEAD,WAAW;QACT,OAAO,IAAIL,eAAe,IAAI,CAACO,SAAS;IAC1C;IAEAC,UAAU;QACR,OAAO,IAAIR,eAAe,IAAI,CAACS,QAAQ;IACzC;AACF"}
1
+ {"version":3,"sources":["../../../src/types/boolean.ts"],"sourcesContent":["import { type SchemaOptions, type TBoolean, Type } from '@sinclair/typebox'\nimport { BaseType } from './base.ts'\n\nexport class BooleanType<\n N extends boolean = false,\n O extends boolean = false,\n D extends boolean = false,\n> extends BaseType<TBoolean, N, O, D> {\n constructor(\n options: SchemaOptions = {},\n isNullable: N = false as N,\n isOptional: O = false as O,\n hasDefault: D = false as D,\n ) {\n super(options, isNullable, isOptional, hasDefault)\n }\n\n protected _constructSchema(options: SchemaOptions): TBoolean {\n return Type.Boolean(options)\n }\n\n nullable() {\n return new BooleanType(...this._with({ isNullable: true }))\n }\n\n optional() {\n return new BooleanType(...this._with({ isOptional: true }))\n }\n\n nullish() {\n return new BooleanType(\n ...this._with({ isNullable: true, isOptional: true }),\n )\n }\n\n default(value: boolean) {\n return new BooleanType(\n ...this._with({ options: { default: value }, hasDefault: true }),\n )\n }\n\n description(description: string) {\n return new BooleanType(...this._with({ options: { description } }))\n }\n\n examples(...examples: [boolean, ...boolean[]]) {\n return new BooleanType(...this._with({ options: { examples } }))\n }\n}\n"],"names":["Type","BaseType","BooleanType","constructor","options","isNullable","isOptional","hasDefault","_constructSchema","Boolean","nullable","_with","optional","nullish","default","value","description","examples"],"mappings":"AAAA,SAA4CA,IAAI,QAAQ,oBAAmB;AAC3E,SAASC,QAAQ,QAAQ,YAAW;AAEpC,OAAO,MAAMC,oBAIHD;IACRE,YACEC,UAAyB,CAAC,CAAC,EAC3BC,aAAgB,KAAU,EAC1BC,aAAgB,KAAU,EAC1BC,aAAgB,KAAU,CAC1B;QACA,KAAK,CAACH,SAASC,YAAYC,YAAYC;IACzC;IAEUC,iBAAiBJ,OAAsB,EAAY;QAC3D,OAAOJ,KAAKS,OAAO,CAACL;IACtB;IAEAM,WAAW;QACT,OAAO,IAAIR,eAAe,IAAI,CAACS,KAAK,CAAC;YAAEN,YAAY;QAAK;IAC1D;IAEAO,WAAW;QACT,OAAO,IAAIV,eAAe,IAAI,CAACS,KAAK,CAAC;YAAEL,YAAY;QAAK;IAC1D;IAEAO,UAAU;QACR,OAAO,IAAIX,eACN,IAAI,CAACS,KAAK,CAAC;YAAEN,YAAY;YAAMC,YAAY;QAAK;IAEvD;IAEAQ,QAAQC,KAAc,EAAE;QACtB,OAAO,IAAIb,eACN,IAAI,CAACS,KAAK,CAAC;YAAEP,SAAS;gBAAEU,SAASC;YAAM;YAAGR,YAAY;QAAK;IAElE;IAEAS,YAAYA,WAAmB,EAAE;QAC/B,OAAO,IAAId,eAAe,IAAI,CAACS,KAAK,CAAC;YAAEP,SAAS;gBAAEY;YAAY;QAAE;IAClE;IAEAC,SAAS,GAAGA,QAAiC,EAAE;QAC7C,OAAO,IAAIf,eAAe,IAAI,CAACS,KAAK,CAAC;YAAEP,SAAS;gBAAEa;YAAS;QAAE;IAC/D;AACF"}
@@ -3,21 +3,50 @@ import { BaseType } from "./base.js";
3
3
  export class CustomType extends BaseType {
4
4
  decode;
5
5
  encode;
6
- constructor(decode, encode, nullable = false, optional = false){
7
- super(Type.Optional(Type.Transform(Type.Any()).Decode(decode).Encode(encode)), nullable, optional);
6
+ constructor(decode, encode, options = {}, isNullable = false, isOptional = false, hasDefault = false){
7
+ super(options, isNullable, isOptional, hasDefault, decode, encode);
8
8
  this.decode = decode;
9
9
  this.encode = encode;
10
10
  }
11
+ _constructSchema(options, decode, encode) {
12
+ return Type.Transform(Type.Any(options)).Decode(decode).Encode(encode);
13
+ }
11
14
  nullable() {
12
- const [_, ...args] = this._nullable();
13
- return new CustomType(this.decode, this.encode, ...args);
15
+ return new CustomType(this.decode, this.encode, ...this._with({
16
+ isNullable: true
17
+ }));
14
18
  }
15
19
  optional() {
16
- const [_, ...args] = this._optional();
17
- return new CustomType(this.decode, this.encode, ...args);
20
+ return new CustomType(this.decode, this.encode, ...this._with({
21
+ isOptional: true
22
+ }));
18
23
  }
19
24
  nullish() {
20
- const [_, ...args] = this._nullish();
21
- return new CustomType(this.decode, this.encode, ...args);
25
+ return new CustomType(this.decode, this.encode, ...this._with({
26
+ isNullable: true,
27
+ isOptional: true
28
+ }));
29
+ }
30
+ default(value) {
31
+ return new CustomType(this.decode, this.encode, ...this._with({
32
+ options: {
33
+ default: this.encode(value)
34
+ },
35
+ hasDefault: true
36
+ }));
37
+ }
38
+ description(description) {
39
+ return new CustomType(this.decode, this.encode, ...this._with({
40
+ options: {
41
+ description
42
+ }
43
+ }));
44
+ }
45
+ examples(...examples) {
46
+ return new CustomType(this.decode, this.encode, ...this._with({
47
+ options: {
48
+ examples: examples.map(this.encode)
49
+ }
50
+ }));
22
51
  }
23
52
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/types/custom.ts"],"sourcesContent":["import { type TTransform, type TUnsafe, Type } from '@sinclair/typebox'\nimport { BaseType } from './base.ts'\n\nexport class CustomType<\n T,\n S = T,\n N extends boolean = false,\n O extends boolean = false,\n> extends BaseType<TTransform<TUnsafe<S>, T>, N, O> {\n constructor(\n protected readonly decode: (value: any) => T,\n protected readonly encode: (value: T) => any,\n nullable: N = false as N,\n optional: O = false as O,\n ) {\n super(\n Type.Optional(\n Type.Transform(Type.Any() as unknown as TUnsafe<S>)\n .Decode(decode)\n .Encode(encode),\n ),\n nullable,\n optional,\n )\n }\n\n nullable() {\n const [_, ...args] = this._nullable()\n return new CustomType<T, S, (typeof args)[0], (typeof args)[1]>(\n this.decode,\n this.encode,\n ...args,\n )\n }\n\n optional() {\n const [_, ...args] = this._optional()\n return new CustomType<T, S, (typeof args)[0], (typeof args)[1]>(\n this.decode,\n this.encode,\n ...args,\n )\n }\n\n nullish() {\n const [_, ...args] = this._nullish()\n return new CustomType<T, S, (typeof args)[0], (typeof args)[1]>(\n this.decode,\n this.encode,\n ...args,\n )\n }\n}\n"],"names":["Type","BaseType","CustomType","constructor","decode","encode","nullable","optional","Optional","Transform","Any","Decode","Encode","_","args","_nullable","_optional","nullish","_nullish"],"mappings":"AAAA,SAAwCA,IAAI,QAAQ,oBAAmB;AACvE,SAASC,QAAQ,QAAQ,YAAW;AAEpC,OAAO,MAAMC,mBAKHD;;;IACRE,YACE,AAAmBC,MAAyB,EAC5C,AAAmBC,MAAyB,EAC5CC,WAAc,KAAU,EACxBC,WAAc,KAAU,CACxB;QACA,KAAK,CACHP,KAAKQ,QAAQ,CACXR,KAAKS,SAAS,CAACT,KAAKU,GAAG,IACpBC,MAAM,CAACP,QACPQ,MAAM,CAACP,UAEZC,UACAC;aAZiBH,SAAAA;aACAC,SAAAA;IAarB;IAEAC,WAAW;QACT,MAAM,CAACO,GAAG,GAAGC,KAAK,GAAG,IAAI,CAACC,SAAS;QACnC,OAAO,IAAIb,WACT,IAAI,CAACE,MAAM,EACX,IAAI,CAACC,MAAM,KACRS;IAEP;IAEAP,WAAW;QACT,MAAM,CAACM,GAAG,GAAGC,KAAK,GAAG,IAAI,CAACE,SAAS;QACnC,OAAO,IAAId,WACT,IAAI,CAACE,MAAM,EACX,IAAI,CAACC,MAAM,KACRS;IAEP;IAEAG,UAAU;QACR,MAAM,CAACJ,GAAG,GAAGC,KAAK,GAAG,IAAI,CAACI,QAAQ;QAClC,OAAO,IAAIhB,WACT,IAAI,CAACE,MAAM,EACX,IAAI,CAACC,MAAM,KACRS;IAEP;AACF"}
1
+ {"version":3,"sources":["../../../src/types/custom.ts"],"sourcesContent":["import {\n type SchemaOptions,\n type TTransform,\n type TUnsafe,\n Type,\n} from '@sinclair/typebox'\nimport { BaseType } from './base.ts'\n\ntype CustomDecode<T> = (value: any) => T\ntype CustomEncode<T> = (value: T) => any\n\nexport class CustomType<\n T,\n S = T,\n N extends boolean = false,\n O extends boolean = false,\n D extends boolean = false,\n> extends BaseType<TTransform<TUnsafe<S>, T>, N, O, D> {\n constructor(\n protected readonly decode: CustomDecode<T>,\n protected readonly encode: CustomEncode<T>,\n options: SchemaOptions = {},\n isNullable: N = false as N,\n isOptional: O = false as O,\n hasDefault: D = false as D,\n ) {\n super(options, isNullable, isOptional, hasDefault, decode, encode)\n }\n\n protected _constructSchema(\n options: SchemaOptions,\n decode: CustomDecode<T>,\n encode: CustomEncode<T>,\n ): TTransform<TUnsafe<S>, T> {\n return Type.Transform(Type.Any(options) as unknown as TUnsafe<S>)\n .Decode(decode)\n .Encode(encode)\n }\n\n nullable() {\n return new CustomType<T, S, true, O, D>(\n this.decode,\n this.encode,\n ...this._with({ isNullable: true }),\n )\n }\n\n optional() {\n return new CustomType<T, S, N, true, D>(\n this.decode,\n this.encode,\n ...this._with({ isOptional: true }),\n )\n }\n\n nullish() {\n return new CustomType<T, S, true, true, D>(\n this.decode,\n this.encode,\n ...this._with({ isNullable: true, isOptional: true }),\n )\n }\n\n default(value: T) {\n return new CustomType<T, S, N, O, true>(\n this.decode,\n this.encode,\n ...this._with({\n options: { default: this.encode(value) },\n hasDefault: true,\n }),\n )\n }\n\n description(description: string) {\n return new CustomType<T, S, N, O, D>(\n this.decode,\n this.encode,\n ...this._with({ options: { description } }),\n )\n }\n\n examples(...examples: [T, ...T[]]) {\n return new CustomType<T, S, N, O, D>(\n this.decode,\n this.encode,\n ...this._with({ options: { examples: examples.map(this.encode) } }),\n )\n }\n}\n"],"names":["Type","BaseType","CustomType","constructor","decode","encode","options","isNullable","isOptional","hasDefault","_constructSchema","Transform","Any","Decode","Encode","nullable","_with","optional","nullish","default","value","description","examples","map"],"mappings":"AAAA,SAIEA,IAAI,QACC,oBAAmB;AAC1B,SAASC,QAAQ,QAAQ,YAAW;AAKpC,OAAO,MAAMC,mBAMHD;;;IACRE,YACE,AAAmBC,MAAuB,EAC1C,AAAmBC,MAAuB,EAC1CC,UAAyB,CAAC,CAAC,EAC3BC,aAAgB,KAAU,EAC1BC,aAAgB,KAAU,EAC1BC,aAAgB,KAAU,CAC1B;QACA,KAAK,CAACH,SAASC,YAAYC,YAAYC,YAAYL,QAAQC;aAPxCD,SAAAA;aACAC,SAAAA;IAOrB;IAEUK,iBACRJ,OAAsB,EACtBF,MAAuB,EACvBC,MAAuB,EACI;QAC3B,OAAOL,KAAKW,SAAS,CAACX,KAAKY,GAAG,CAACN,UAC5BO,MAAM,CAACT,QACPU,MAAM,CAACT;IACZ;IAEAU,WAAW;QACT,OAAO,IAAIb,WACT,IAAI,CAACE,MAAM,EACX,IAAI,CAACC,MAAM,KACR,IAAI,CAACW,KAAK,CAAC;YAAET,YAAY;QAAK;IAErC;IAEAU,WAAW;QACT,OAAO,IAAIf,WACT,IAAI,CAACE,MAAM,EACX,IAAI,CAACC,MAAM,KACR,IAAI,CAACW,KAAK,CAAC;YAAER,YAAY;QAAK;IAErC;IAEAU,UAAU;QACR,OAAO,IAAIhB,WACT,IAAI,CAACE,MAAM,EACX,IAAI,CAACC,MAAM,KACR,IAAI,CAACW,KAAK,CAAC;YAAET,YAAY;YAAMC,YAAY;QAAK;IAEvD;IAEAW,QAAQC,KAAQ,EAAE;QAChB,OAAO,IAAIlB,WACT,IAAI,CAACE,MAAM,EACX,IAAI,CAACC,MAAM,KACR,IAAI,CAACW,KAAK,CAAC;YACZV,SAAS;gBAAEa,SAAS,IAAI,CAACd,MAAM,CAACe;YAAO;YACvCX,YAAY;QACd;IAEJ;IAEAY,YAAYA,WAAmB,EAAE;QAC/B,OAAO,IAAInB,WACT,IAAI,CAACE,MAAM,EACX,IAAI,CAACC,MAAM,KACR,IAAI,CAACW,KAAK,CAAC;YAAEV,SAAS;gBAAEe;YAAY;QAAE;IAE7C;IAEAC,SAAS,GAAGA,QAAqB,EAAE;QACjC,OAAO,IAAIpB,WACT,IAAI,CAACE,MAAM,EACX,IAAI,CAACC,MAAM,KACR,IAAI,CAACW,KAAK,CAAC;YAAEV,SAAS;gBAAEgB,UAAUA,SAASC,GAAG,CAAC,IAAI,CAAClB,MAAM;YAAE;QAAE;IAErE;AACF"}