@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
@@ -1,34 +1,53 @@
1
1
  import { Type } from '@sinclair/typebox';
2
2
  import { BaseType } from "./base.js";
3
+ const decode = (value)=>new Date(value);
4
+ const encode = (value)=>value.toISOString();
3
5
  export class DateType extends BaseType {
4
- constructor(schema = Type.Transform(Type.String({
5
- format: 'date'
6
- })).Decode((value)=>new Date(value)).Encode((value)=>value.toJSON()), nullable = false, optional = false){
7
- super(schema, nullable, optional);
6
+ constructor(options = {}, isNullable = false, isOptional = false, hasDefault = false){
7
+ super(options, isNullable, isOptional, hasDefault);
8
8
  }
9
- nullable() {
10
- return new DateType(...this._nullable());
11
- }
12
- optional() {
13
- return new DateType(...this._optional());
14
- }
15
- nullish() {
16
- return new DateType(...this._nullish());
17
- }
18
- }
19
- export class DateTimeType extends BaseType {
20
- constructor(schema = Type.Transform(Type.String({
21
- format: 'date-time'
22
- })).Decode((value)=>new Date(value)).Encode((value)=>value.toJSON()), nullable = false, optional = false){
23
- super(schema, nullable, optional);
9
+ _constructSchema(options) {
10
+ return Type.Transform(Type.String({
11
+ ...options,
12
+ format: 'date-time'
13
+ })).Decode(decode).Encode(encode);
24
14
  }
25
15
  nullable() {
26
- return new DateTimeType(...this._nullable());
16
+ return new DateType(...this._with({
17
+ isNullable: true
18
+ }));
27
19
  }
28
20
  optional() {
29
- return new DateTimeType(...this._optional());
21
+ return new DateType(...this._with({
22
+ isOptional: true
23
+ }));
30
24
  }
31
25
  nullish() {
32
- return new DateTimeType(...this._nullish());
26
+ return new DateType(...this._with({
27
+ isNullable: true,
28
+ isOptional: true
29
+ }));
30
+ }
31
+ default(value) {
32
+ return new DateType(...this._with({
33
+ options: {
34
+ default: encode(value)
35
+ },
36
+ hasDefault: true
37
+ }));
38
+ }
39
+ description(value) {
40
+ return new DateType(...this._with({
41
+ options: {
42
+ description: value
43
+ }
44
+ }));
45
+ }
46
+ examples(...values) {
47
+ return new DateType(...this._with({
48
+ options: {
49
+ examples: values.map(encode)
50
+ }
51
+ }));
33
52
  }
34
53
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/types/datetime.ts"],"sourcesContent":["import { type TString, type TTransform, Type } from '@sinclair/typebox'\nimport { BaseType } from './base.ts'\n\nexport class DateType<\n N extends boolean = false,\n O extends boolean = false,\n> extends BaseType<TTransform<TString, Date>, N, O> {\n constructor(\n schema: TTransform<TString, Date> = Type.Transform(\n Type.String({ format: 'date' }),\n )\n .Decode((value) => new Date(value))\n .Encode((value) => value.toJSON()),\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 DateType(...this._nullable())\n }\n\n optional() {\n return new DateType(...this._optional())\n }\n\n nullish() {\n return new DateType(...this._nullish())\n }\n}\n\nexport class DateTimeType<\n N extends boolean = false,\n O extends boolean = false,\n> extends BaseType<TTransform<TString, Date>, N, O> {\n constructor(\n schema: TTransform<TString, Date> = Type.Transform(\n Type.String({ format: 'date-time' }),\n )\n .Decode((value) => new Date(value))\n .Encode((value) => value.toJSON()),\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 DateTimeType(...this._nullable())\n }\n\n optional() {\n return new DateTimeType(...this._optional())\n }\n\n nullish() {\n return new DateTimeType(...this._nullish())\n }\n}\n"],"names":["Type","BaseType","DateType","constructor","schema","Transform","String","format","Decode","value","Date","Encode","toJSON","nullable","optional","_nullable","_optional","nullish","_nullish","DateTimeType"],"mappings":"AAAA,SAAwCA,IAAI,QAAQ,oBAAmB;AACvE,SAASC,QAAQ,QAAQ,YAAW;AAEpC,OAAO,MAAMC,iBAGHD;IACRE,YACEC,SAAoCJ,KAAKK,SAAS,CAChDL,KAAKM,MAAM,CAAC;QAAEC,QAAQ;IAAO,IAE5BC,MAAM,CAAC,CAACC,QAAU,IAAIC,KAAKD,QAC3BE,MAAM,CAAC,CAACF,QAAUA,MAAMG,MAAM,GAAG,EACpCC,WAAc,KAAU,EACxBC,WAAc,KAAU,CACxB;QACA,KAAK,CAACV,QAAQS,UAAUC;IAC1B;IAEAD,WAAW;QACT,OAAO,IAAIX,YAAY,IAAI,CAACa,SAAS;IACvC;IAEAD,WAAW;QACT,OAAO,IAAIZ,YAAY,IAAI,CAACc,SAAS;IACvC;IAEAC,UAAU;QACR,OAAO,IAAIf,YAAY,IAAI,CAACgB,QAAQ;IACtC;AACF;AAEA,OAAO,MAAMC,qBAGHlB;IACRE,YACEC,SAAoCJ,KAAKK,SAAS,CAChDL,KAAKM,MAAM,CAAC;QAAEC,QAAQ;IAAY,IAEjCC,MAAM,CAAC,CAACC,QAAU,IAAIC,KAAKD,QAC3BE,MAAM,CAAC,CAACF,QAAUA,MAAMG,MAAM,GAAG,EACpCC,WAAc,KAAU,EACxBC,WAAc,KAAU,CACxB;QACA,KAAK,CAACV,QAAQS,UAAUC;IAC1B;IAEAD,WAAW;QACT,OAAO,IAAIM,gBAAgB,IAAI,CAACJ,SAAS;IAC3C;IAEAD,WAAW;QACT,OAAO,IAAIK,gBAAgB,IAAI,CAACH,SAAS;IAC3C;IAEAC,UAAU;QACR,OAAO,IAAIE,gBAAgB,IAAI,CAACD,QAAQ;IAC1C;AACF"}
1
+ {"version":3,"sources":["../../../src/types/datetime.ts"],"sourcesContent":["import {\n type SchemaOptions,\n type StringOptions,\n type TString,\n type TTransform,\n Type,\n} from '@sinclair/typebox'\nimport { BaseType } from './base.ts'\n\nconst decode = (value: any): Date => new Date(value)\nconst encode = (value: Date): any => value.toISOString()\n\nexport class DateType<\n N extends boolean = false,\n O extends boolean = false,\n D extends boolean = false,\n> extends BaseType<TTransform<TString, Date>, N, O, D, StringOptions> {\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(\n options: StringOptions,\n ): TTransform<TString, Date> {\n return Type.Transform(Type.String({ ...options, format: 'date-time' }))\n .Decode(decode)\n .Encode(encode)\n }\n\n nullable() {\n return new DateType(...this._with({ isNullable: true }))\n }\n\n optional() {\n return new DateType(...this._with({ isOptional: true }))\n }\n\n nullish() {\n return new DateType(...this._with({ isNullable: true, isOptional: true }))\n }\n\n default(value: Date) {\n return new DateType(\n ...this._with({\n options: { default: encode(value) },\n hasDefault: true,\n }),\n )\n }\n\n description(value: string) {\n return new DateType(...this._with({ options: { description: value } }))\n }\n\n examples(...values: [Date, ...Date[]]) {\n return new DateType(\n ...this._with({ options: { examples: values.map(encode) } }),\n )\n }\n}\n"],"names":["Type","BaseType","decode","value","Date","encode","toISOString","DateType","constructor","options","isNullable","isOptional","hasDefault","_constructSchema","Transform","String","format","Decode","Encode","nullable","_with","optional","nullish","default","description","examples","values","map"],"mappings":"AAAA,SAKEA,IAAI,QACC,oBAAmB;AAC1B,SAASC,QAAQ,QAAQ,YAAW;AAEpC,MAAMC,SAAS,CAACC,QAAqB,IAAIC,KAAKD;AAC9C,MAAME,SAAS,CAACF,QAAqBA,MAAMG,WAAW;AAEtD,OAAO,MAAMC,iBAIHN;IACRO,YACEC,UAAyB,CAAC,CAAC,EAC3BC,aAAgB,KAAU,EAC1BC,aAAgB,KAAU,EAC1BC,aAAgB,KAAU,CAC1B;QACA,KAAK,CAACH,SAASC,YAAYC,YAAYC;IACzC;IAEUC,iBACRJ,OAAsB,EACK;QAC3B,OAAOT,KAAKc,SAAS,CAACd,KAAKe,MAAM,CAAC;YAAE,GAAGN,OAAO;YAAEO,QAAQ;QAAY,IACjEC,MAAM,CAACf,QACPgB,MAAM,CAACb;IACZ;IAEAc,WAAW;QACT,OAAO,IAAIZ,YAAY,IAAI,CAACa,KAAK,CAAC;YAAEV,YAAY;QAAK;IACvD;IAEAW,WAAW;QACT,OAAO,IAAId,YAAY,IAAI,CAACa,KAAK,CAAC;YAAET,YAAY;QAAK;IACvD;IAEAW,UAAU;QACR,OAAO,IAAIf,YAAY,IAAI,CAACa,KAAK,CAAC;YAAEV,YAAY;YAAMC,YAAY;QAAK;IACzE;IAEAY,QAAQpB,KAAW,EAAE;QACnB,OAAO,IAAII,YACN,IAAI,CAACa,KAAK,CAAC;YACZX,SAAS;gBAAEc,SAASlB,OAAOF;YAAO;YAClCS,YAAY;QACd;IAEJ;IAEAY,YAAYrB,KAAa,EAAE;QACzB,OAAO,IAAII,YAAY,IAAI,CAACa,KAAK,CAAC;YAAEX,SAAS;gBAAEe,aAAarB;YAAM;QAAE;IACtE;IAEAsB,SAAS,GAAGC,MAAyB,EAAE;QACrC,OAAO,IAAInB,YACN,IAAI,CAACa,KAAK,CAAC;YAAEX,SAAS;gBAAEgB,UAAUC,OAAOC,GAAG,CAACtB;YAAQ;QAAE;IAE9D;AACF"}
@@ -3,39 +3,97 @@ import { UnionEnum } from "../schemas/union-enum.js";
3
3
  import { BaseType } from "./base.js";
4
4
  export class NativeEnumType extends BaseType {
5
5
  values;
6
- constructor(values, nullable = false, optional = false){
7
- super(NativeEnum(values), nullable, optional);
6
+ constructor(values, options = {}, isNullable = false, isOptional = false, hasDefault = false){
7
+ super(options, isNullable, isOptional, hasDefault);
8
8
  this.values = values;
9
9
  }
10
+ _constructSchema(options) {
11
+ return NativeEnum(this.values, options);
12
+ }
10
13
  nullable() {
11
- const [_, ...args] = this._nullable();
12
- return new NativeEnumType(this.values, ...args);
14
+ return new NativeEnumType(this.values, ...this._with({
15
+ isNullable: true
16
+ }));
13
17
  }
14
18
  optional() {
15
- const [_, ...args] = this._optional();
16
- return new NativeEnumType(this.values, ...args);
19
+ return new NativeEnumType(this.values, ...this._with({
20
+ isOptional: true
21
+ }));
17
22
  }
18
23
  nullish() {
19
- const [_, ...args] = this._nullish();
20
- return new NativeEnumType(this.values, ...args);
24
+ return new NativeEnumType(this.values, ...this._with({
25
+ isNullable: true,
26
+ isOptional: true
27
+ }));
28
+ }
29
+ default(value) {
30
+ return new NativeEnumType(this.values, ...this._with({
31
+ options: {
32
+ default: value
33
+ },
34
+ hasDefault: true
35
+ }));
36
+ }
37
+ description(description) {
38
+ return new NativeEnumType(this.values, ...this._with({
39
+ options: {
40
+ description
41
+ }
42
+ }));
43
+ }
44
+ examples(...examples) {
45
+ return new NativeEnumType(this.values, ...this._with({
46
+ options: {
47
+ examples
48
+ }
49
+ }));
21
50
  }
22
51
  }
23
52
  export class EnumType extends BaseType {
24
53
  values;
25
- constructor(values, nullable = false, optional = false){
26
- super(UnionEnum(values), nullable, optional);
54
+ constructor(values, options = {}, isNullable = false, isOptional = false, hasDefault = false){
55
+ super(options, isNullable, isOptional, hasDefault, values);
27
56
  this.values = values;
28
57
  }
58
+ _constructSchema(options, values) {
59
+ return UnionEnum(values, options);
60
+ }
29
61
  nullable() {
30
- const [_, ...args] = this._nullable();
31
- return new EnumType(this.values, ...args);
62
+ return new EnumType(this.values, ...this._with({
63
+ isNullable: true
64
+ }));
32
65
  }
33
66
  optional() {
34
- const [_, ...args] = this._optional();
35
- return new EnumType(this.values, ...args);
67
+ return new EnumType(this.values, ...this._with({
68
+ isOptional: true
69
+ }));
36
70
  }
37
71
  nullish() {
38
- const [_, ...args] = this._nullish();
39
- return new EnumType(this.values, ...args);
72
+ return new EnumType(this.values, ...this._with({
73
+ isNullable: true,
74
+ isOptional: true
75
+ }));
76
+ }
77
+ default(value) {
78
+ return new EnumType(this.values, ...this._with({
79
+ options: {
80
+ default: value
81
+ },
82
+ hasDefault: true
83
+ }));
84
+ }
85
+ description(description) {
86
+ return new EnumType(this.values, ...this._with({
87
+ options: {
88
+ description
89
+ }
90
+ }));
91
+ }
92
+ examples(...examples) {
93
+ return new EnumType(this.values, ...this._with({
94
+ options: {
95
+ examples
96
+ }
97
+ }));
40
98
  }
41
99
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/types/enum.ts"],"sourcesContent":["import type { TNativeEnum } from '../schemas/native-enum.ts'\nimport { NativeEnum } from '../schemas/native-enum.ts'\nimport { type TUnionEnum, UnionEnum } from '../schemas/union-enum.ts'\nimport { BaseType } from './base.ts'\n\nexport class NativeEnumType<\n T extends { [K in string]: K } = { [K in string]: K },\n N extends boolean = false,\n O extends boolean = false,\n> extends BaseType<TNativeEnum<T>, N, O> {\n constructor(\n readonly values: T,\n nullable: N = false as N,\n optional: O = false as O,\n ) {\n super(NativeEnum(values), nullable, optional)\n }\n\n nullable() {\n const [_, ...args] = this._nullable()\n return new NativeEnumType(this.values, ...args)\n }\n\n optional() {\n const [_, ...args] = this._optional()\n return new NativeEnumType(this.values, ...args)\n }\n\n nullish() {\n const [_, ...args] = this._nullish()\n return new NativeEnumType(this.values, ...args)\n }\n}\n\nexport class EnumType<\n T extends (string | number)[],\n N extends boolean = false,\n O extends boolean = false,\n> extends BaseType<TUnionEnum<T>, N, O> {\n constructor(\n readonly values: [...T],\n nullable: N = false as N,\n optional: O = false as O,\n ) {\n super(UnionEnum(values), nullable, optional)\n }\n\n nullable() {\n const [_, ...args] = this._nullable()\n return new EnumType(this.values, ...args)\n }\n\n optional() {\n const [_, ...args] = this._optional()\n return new EnumType(this.values, ...args)\n }\n\n nullish() {\n const [_, ...args] = this._nullish()\n return new EnumType(this.values, ...args)\n }\n}\n"],"names":["NativeEnum","UnionEnum","BaseType","NativeEnumType","constructor","values","nullable","optional","_","args","_nullable","_optional","nullish","_nullish","EnumType"],"mappings":"AACA,SAASA,UAAU,QAAQ,4BAA2B;AACtD,SAA0BC,SAAS,QAAQ,2BAA0B;AACrE,SAASC,QAAQ,QAAQ,YAAW;AAEpC,OAAO,MAAMC,uBAIHD;;IACRE,YACE,AAASC,MAAS,EAClBC,WAAc,KAAU,EACxBC,WAAc,KAAU,CACxB;QACA,KAAK,CAACP,WAAWK,SAASC,UAAUC;aAJ3BF,SAAAA;IAKX;IAEAC,WAAW;QACT,MAAM,CAACE,GAAG,GAAGC,KAAK,GAAG,IAAI,CAACC,SAAS;QACnC,OAAO,IAAIP,eAAe,IAAI,CAACE,MAAM,KAAKI;IAC5C;IAEAF,WAAW;QACT,MAAM,CAACC,GAAG,GAAGC,KAAK,GAAG,IAAI,CAACE,SAAS;QACnC,OAAO,IAAIR,eAAe,IAAI,CAACE,MAAM,KAAKI;IAC5C;IAEAG,UAAU;QACR,MAAM,CAACJ,GAAG,GAAGC,KAAK,GAAG,IAAI,CAACI,QAAQ;QAClC,OAAO,IAAIV,eAAe,IAAI,CAACE,MAAM,KAAKI;IAC5C;AACF;AAEA,OAAO,MAAMK,iBAIHZ;;IACRE,YACE,AAASC,MAAc,EACvBC,WAAc,KAAU,EACxBC,WAAc,KAAU,CACxB;QACA,KAAK,CAACN,UAAUI,SAASC,UAAUC;aAJ1BF,SAAAA;IAKX;IAEAC,WAAW;QACT,MAAM,CAACE,GAAG,GAAGC,KAAK,GAAG,IAAI,CAACC,SAAS;QACnC,OAAO,IAAII,SAAS,IAAI,CAACT,MAAM,KAAKI;IACtC;IAEAF,WAAW;QACT,MAAM,CAACC,GAAG,GAAGC,KAAK,GAAG,IAAI,CAACE,SAAS;QACnC,OAAO,IAAIG,SAAS,IAAI,CAACT,MAAM,KAAKI;IACtC;IAEAG,UAAU;QACR,MAAM,CAACJ,GAAG,GAAGC,KAAK,GAAG,IAAI,CAACI,QAAQ;QAClC,OAAO,IAAIC,SAAS,IAAI,CAACT,MAAM,KAAKI;IACtC;AACF"}
1
+ {"version":3,"sources":["../../../src/types/enum.ts"],"sourcesContent":["import type { SchemaOptions } from '@sinclair/typebox'\nimport type { TNativeEnum } from '../schemas/native-enum.ts'\nimport { NativeEnum } from '../schemas/native-enum.ts'\nimport { type TUnionEnum, UnionEnum } from '../schemas/union-enum.ts'\nimport { BaseType } from './base.ts'\n\nexport class NativeEnumType<\n T extends { [K in string]: K } = { [K in string]: K },\n N extends boolean = false,\n O extends boolean = false,\n D extends boolean = false,\n> extends BaseType<TNativeEnum<T>, N, O, D> {\n constructor(\n readonly values: 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)\n }\n\n protected _constructSchema(options: SchemaOptions): TNativeEnum<T> {\n return NativeEnum(this.values, options)\n }\n\n nullable() {\n return new NativeEnumType(this.values, ...this._with({ isNullable: true }))\n }\n\n optional() {\n return new NativeEnumType(this.values, ...this._with({ isOptional: true }))\n }\n\n nullish() {\n return new NativeEnumType(\n this.values,\n ...this._with({ isNullable: true, isOptional: true }),\n )\n }\n\n default(value: keyof T) {\n return new NativeEnumType(\n this.values,\n ...this._with({ options: { default: value }, hasDefault: true }),\n )\n }\n\n description(description: string) {\n return new NativeEnumType(\n this.values,\n ...this._with({ options: { description } }),\n )\n }\n\n examples(...examples: (keyof T)[]) {\n return new NativeEnumType(\n this.values,\n ...this._with({ options: { examples } }),\n )\n }\n}\n\nexport class EnumType<\n T extends (string | number)[],\n N extends boolean = false,\n O extends boolean = false,\n D extends boolean = false,\n> extends BaseType<TUnionEnum<T>, N, O, D> {\n constructor(\n protected readonly values: [...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, values)\n }\n\n protected _constructSchema(\n options: SchemaOptions,\n values: [...T],\n ): TUnionEnum<T> {\n return UnionEnum(values, options)\n }\n\n nullable() {\n return new EnumType(this.values, ...this._with({ isNullable: true }))\n }\n\n optional() {\n return new EnumType(this.values, ...this._with({ isOptional: true }))\n }\n\n nullish() {\n return new EnumType(\n this.values,\n ...this._with({ isNullable: true, isOptional: true }),\n )\n }\n\n default(value: T[number]) {\n return new EnumType(\n this.values,\n ...this._with({ options: { default: value }, hasDefault: true }),\n )\n }\n\n description(description: string) {\n return new EnumType(\n this.values,\n ...this._with({ options: { description } }),\n )\n }\n\n examples(...examples: [T[number], ...T[number][]]) {\n return new EnumType(this.values, ...this._with({ options: { examples } }))\n }\n}\n"],"names":["NativeEnum","UnionEnum","BaseType","NativeEnumType","constructor","values","options","isNullable","isOptional","hasDefault","_constructSchema","nullable","_with","optional","nullish","default","value","description","examples","EnumType"],"mappings":"AAEA,SAASA,UAAU,QAAQ,4BAA2B;AACtD,SAA0BC,SAAS,QAAQ,2BAA0B;AACrE,SAASC,QAAQ,QAAQ,YAAW;AAEpC,OAAO,MAAMC,uBAKHD;;IACRE,YACE,AAASC,MAAS,EAClBC,UAAyB,CAAC,CAAC,EAC3BC,aAAgB,KAAU,EAC1BC,aAAgB,KAAU,EAC1BC,aAAgB,KAAU,CAC1B;QACA,KAAK,CAACH,SAASC,YAAYC,YAAYC;aAN9BJ,SAAAA;IAOX;IAEUK,iBAAiBJ,OAAsB,EAAkB;QACjE,OAAON,WAAW,IAAI,CAACK,MAAM,EAAEC;IACjC;IAEAK,WAAW;QACT,OAAO,IAAIR,eAAe,IAAI,CAACE,MAAM,KAAK,IAAI,CAACO,KAAK,CAAC;YAAEL,YAAY;QAAK;IAC1E;IAEAM,WAAW;QACT,OAAO,IAAIV,eAAe,IAAI,CAACE,MAAM,KAAK,IAAI,CAACO,KAAK,CAAC;YAAEJ,YAAY;QAAK;IAC1E;IAEAM,UAAU;QACR,OAAO,IAAIX,eACT,IAAI,CAACE,MAAM,KACR,IAAI,CAACO,KAAK,CAAC;YAAEL,YAAY;YAAMC,YAAY;QAAK;IAEvD;IAEAO,QAAQC,KAAc,EAAE;QACtB,OAAO,IAAIb,eACT,IAAI,CAACE,MAAM,KACR,IAAI,CAACO,KAAK,CAAC;YAAEN,SAAS;gBAAES,SAASC;YAAM;YAAGP,YAAY;QAAK;IAElE;IAEAQ,YAAYA,WAAmB,EAAE;QAC/B,OAAO,IAAId,eACT,IAAI,CAACE,MAAM,KACR,IAAI,CAACO,KAAK,CAAC;YAAEN,SAAS;gBAAEW;YAAY;QAAE;IAE7C;IAEAC,SAAS,GAAGA,QAAqB,EAAE;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import { Type } from '@sinclair/typebox';
2
2
  import { BaseType } from "./base.js";
3
3
  export class LiteralType extends BaseType {
4
4
  value;
5
- constructor(value, nullable = false, optional = false){
6
- super(Type.Literal(value), nullable, optional);
5
+ constructor(value, options = {}, isNullable = false, isOptional = false, hasDefault = false){
6
+ super(options, isNullable, isOptional, hasDefault, value);
7
7
  this.value = value;
8
8
  }
9
+ _constructSchema(options, value) {
10
+ return Type.Literal(value, options);
11
+ }
9
12
  nullable() {
10
- const [_, ...args] = this._nullable();
11
- return new LiteralType(this.value, ...args);
13
+ return new LiteralType(this.value, this.options, true, this.isOptional);
12
14
  }
13
15
  optional() {
14
- const [_, ...args] = this._optional();
15
- return new LiteralType(this.value, ...args);
16
+ return new LiteralType(this.value, ...this._with({
17
+ isOptional: true
18
+ }));
16
19
  }
17
20
  nullish() {
18
- const [_, ...args] = this._nullish();
19
- return new LiteralType(this.value, ...args);
21
+ return new LiteralType(this.value, ...this._with({
22
+ isNullable: true,
23
+ isOptional: true
24
+ }));
25
+ }
26
+ default(value = this.value) {
27
+ return new LiteralType(this.value, ...this._with({
28
+ options: {
29
+ default: value
30
+ },
31
+ hasDefault: true
32
+ }));
33
+ }
34
+ description(description) {
35
+ return new LiteralType(this.value, ...this._with({
36
+ options: {
37
+ description
38
+ }
39
+ }));
40
+ }
41
+ examples(...examples) {
42
+ return new LiteralType(this.value, ...this._with({
43
+ options: {
44
+ examples
45
+ }
46
+ }));
20
47
  }
21
48
  }
@@ -1 +1 @@
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 N extends boolean = false,\n O extends boolean = false,\n> extends BaseType<TLiteral<T>, N, O> {\n constructor(\n readonly value: T,\n nullable: N = false as N,\n optional: O = false as O,\n ) {\n super(Type.Literal(value), nullable, optional)\n }\n\n nullable() {\n const [_, ...args] = this._nullable()\n return new LiteralType(this.value, ...args)\n }\n\n optional() {\n const [_, ...args] = this._optional()\n return new LiteralType(this.value, ...args)\n }\n\n nullish() {\n const [_, ...args] = this._nullish()\n return new LiteralType(this.value, ...args)\n }\n}\n"],"names":["Type","BaseType","LiteralType","constructor","value","nullable","optional","Literal","_","args","_nullable","_optional","nullish","_nullish"],"mappings":"AAAA,SAA4CA,IAAI,QAAQ,oBAAmB;AAC3E,SAASC,QAAQ,QAAQ,YAAW;AAEpC,OAAO,MAAMC,oBAIHD;;IACRE,YACE,AAASC,KAAQ,EACjBC,WAAc,KAAU,EACxBC,WAAc,KAAU,CACxB;QACA,KAAK,CAACN,KAAKO,OAAO,CAACH,QAAQC,UAAUC;aAJ5BF,QAAAA;IAKX;IAEAC,WAAW;QACT,MAAM,CAACG,GAAG,GAAGC,KAAK,GAAG,IAAI,CAACC,SAAS;QACnC,OAAO,IAAIR,YAAY,IAAI,CAACE,KAAK,KAAKK;IACxC;IAEAH,WAAW;QACT,MAAM,CAACE,GAAG,GAAGC,KAAK,GAAG,IAAI,CAACE,SAAS;QACnC,OAAO,IAAIT,YAAY,IAAI,CAACE,KAAK,KAAKK;IACxC;IAEAG,UAAU;QACR,MAAM,CAACJ,GAAG,GAAGC,KAAK,GAAG,IAAI,CAACI,QAAQ;QAClC,OAAO,IAAIX,YAAY,IAAI,CAACE,KAAK,KAAKK;IACxC;AACF"}
1
+ {"version":3,"sources":["../../../src/types/literal.ts"],"sourcesContent":["import {\n type SchemaOptions,\n type TLiteral,\n type TLiteralValue,\n Type,\n} from '@sinclair/typebox'\nimport { BaseType } from './base.ts'\n\nexport class LiteralType<\n T extends TLiteralValue = TLiteralValue,\n N extends boolean = false,\n O extends boolean = false,\n D extends boolean = false,\n> extends BaseType<TLiteral<T>, N, O, D> {\n constructor(\n protected readonly value: 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, value)\n }\n\n protected _constructSchema(options: SchemaOptions, value: T): TLiteral<T> {\n return Type.Literal(value, options)\n }\n\n nullable() {\n return new LiteralType(this.value, this.options, true, this.isOptional)\n }\n\n optional() {\n return new LiteralType(this.value, ...this._with({ isOptional: true }))\n }\n\n nullish() {\n return new LiteralType(\n this.value,\n ...this._with({ isNullable: true, isOptional: true }),\n )\n }\n\n default(value: T = this.value) {\n return new LiteralType(\n this.value,\n ...this._with({ options: { default: value }, hasDefault: true }),\n )\n }\n\n description(description: string) {\n return new LiteralType(\n this.value,\n ...this._with({ options: { description } }),\n )\n }\n\n examples(...examples: [T, ...T[]]) {\n return new LiteralType(this.value, ...this._with({ options: { examples } }))\n }\n}\n"],"names":["Type","BaseType","LiteralType","constructor","value","options","isNullable","isOptional","hasDefault","_constructSchema","Literal","nullable","optional","_with","nullish","default","description","examples"],"mappings":"AAAA,SAIEA,IAAI,QACC,oBAAmB;AAC1B,SAASC,QAAQ,QAAQ,YAAW;AAEpC,OAAO,MAAMC,oBAKHD;;IACRE,YACE,AAAmBC,KAAQ,EAC3BC,UAAyB,CAAC,CAAC,EAC3BC,aAAgB,KAAU,EAC1BC,aAAgB,KAAU,EAC1BC,aAAgB,KAAU,CAC1B;QACA,KAAK,CAACH,SAASC,YAAYC,YAAYC,YAAYJ;aANhCA,QAAAA;IAOrB;IAEUK,iBAAiBJ,OAAsB,EAAED,KAAQ,EAAe;QACxE,OAAOJ,KAAKU,OAAO,CAACN,OAAOC;IAC7B;IAEAM,WAAW;QACT,OAAO,IAAIT,YAAY,IAAI,CAACE,KAAK,EAAE,IAAI,CAACC,OAAO,EAAE,MAAM,IAAI,CAACE,UAAU;IACxE;IAEAK,WAAW;QACT,OAAO,IAAIV,YAAY,IAAI,CAACE,KAAK,KAAK,IAAI,CAACS,KAAK,CAAC;YAAEN,YAAY;QAAK;IACtE;IAEAO,UAAU;QACR,OAAO,IAAIZ,YACT,IAAI,CAACE,KAAK,KACP,IAAI,CAACS,KAAK,CAAC;YAAEP,YAAY;YAAMC,YAAY;QAAK;IAEvD;IAEAQ,QAAQX,QAAW,IAAI,CAACA,KAAK,EAAE;QAC7B,OAAO,IAAIF,YACT,IAAI,CAACE,KAAK,KACP,IAAI,CAACS,KAAK,CAAC;YAAER,SAAS;gBAAEU,SAASX;YAAM;YAAGI,YAAY;QAAK;IAElE;IAEAQ,YAAYA,WAAmB,EAAE;QAC/B,OAAO,IAAId,YACT,IAAI,CAACE,KAAK,KACP,IAAI,CAACS,KAAK,CAAC;YAAER,SAAS;gBAAEW;YAAY;QAAE;IAE7C;IAEAC,SAAS,GAAGA,QAAqB,EAAE;QACjC,OAAO,IAAIf,YAAY,IAAI,CAACE,KAAK,KAAK,IAAI,CAACS,KAAK,CAAC;YAAER,SAAS;gBAAEY;YAAS;QAAE;IAC3E;AACF"}
@@ -1,8 +1,11 @@
1
1
  import { Type } from '@sinclair/typebox';
2
2
  import { BaseType } from "./base.js";
3
3
  export class NeverType extends BaseType {
4
- constructor(schema = Type.Never(), nullable = false, optional = false){
5
- super(schema, nullable, optional);
4
+ constructor(options = {}){
5
+ super(options, false, false, false);
6
+ }
7
+ _constructSchema(options) {
8
+ return Type.Never(options);
6
9
  }
7
10
  nullable() {
8
11
  throw new Error('NeverType cannot be nullable');
@@ -13,4 +16,16 @@ export class NeverType extends BaseType {
13
16
  nullish() {
14
17
  throw new Error('NeverType cannot be nullish');
15
18
  }
19
+ default() {
20
+ throw new Error('NeverType cannot have a default value');
21
+ }
22
+ description(description) {
23
+ return new NeverType({
24
+ ...this.options,
25
+ description
26
+ });
27
+ }
28
+ examples() {
29
+ throw new Error('NeverType cannot have examples');
30
+ }
16
31
  }
@@ -1 +1 @@
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<\n N extends boolean = false,\n O extends boolean = false,\n> extends BaseType<TNever, N, O> {\n constructor(\n schema = Type.Never(),\n nullable: N = false as N,\n optional: O = false as O,\n ) {\n super(schema, nullable, optional)\n }\n\n nullable(): NeverType<true, O> {\n throw new Error('NeverType cannot be nullable')\n }\n\n optional(): NeverType<N, true> {\n throw new Error('NeverType cannot be optional')\n }\n\n nullish(): NeverType<true, true> {\n throw new Error('NeverType cannot be nullish')\n }\n}\n"],"names":["Type","BaseType","NeverType","constructor","schema","Never","nullable","optional","Error","nullish"],"mappings":"AAAA,SAAsBA,IAAI,QAAQ,oBAAmB;AACrD,SAASC,QAAQ,QAAQ,YAAW;AAEpC,OAAO,MAAMC,kBAGHD;IACRE,YACEC,SAASJ,KAAKK,KAAK,EAAE,EACrBC,WAAc,KAAU,EACxBC,WAAc,KAAU,CACxB;QACA,KAAK,CAACH,QAAQE,UAAUC;IAC1B;IAEAD,WAA+B;QAC7B,MAAM,IAAIE,MAAM;IAClB;IAEAD,WAA+B;QAC7B,MAAM,IAAIC,MAAM;IAClB;IAEAC,UAAiC;QAC/B,MAAM,IAAID,MAAM;IAClB;AACF"}
1
+ {"version":3,"sources":["../../../src/types/never.ts"],"sourcesContent":["import { type SchemaOptions, type TNever, Type } from '@sinclair/typebox'\nimport { BaseType } from './base.ts'\n\nexport class NeverType<\n N extends boolean = false,\n O extends boolean = false,\n D extends boolean = false,\n> extends BaseType<TNever, N, O, D> {\n constructor(options: SchemaOptions = {}) {\n super(options, false as N, false as O, false as D)\n }\n\n protected _constructSchema(options: SchemaOptions): TNever {\n return Type.Never(options)\n }\n\n nullable(): NeverType<true, O, D> {\n throw new Error('NeverType cannot be nullable')\n }\n\n optional(): NeverType<N, true, D> {\n throw new Error('NeverType cannot be optional')\n }\n\n nullish(): NeverType<true, true, D> {\n throw new Error('NeverType cannot be nullish')\n }\n\n default(): NeverType<N, O, true> {\n throw new Error('NeverType cannot have a default value')\n }\n\n description(description: string): NeverType<N, O, D> {\n return new NeverType({ ...this.options, description })\n }\n\n examples(): NeverType<N, O, D> {\n throw new Error('NeverType cannot have examples')\n }\n}\n"],"names":["Type","BaseType","NeverType","constructor","options","_constructSchema","Never","nullable","Error","optional","nullish","default","description","examples"],"mappings":"AAAA,SAA0CA,IAAI,QAAQ,oBAAmB;AACzE,SAASC,QAAQ,QAAQ,YAAW;AAEpC,OAAO,MAAMC,kBAIHD;IACRE,YAAYC,UAAyB,CAAC,CAAC,CAAE;QACvC,KAAK,CAACA,SAAS,OAAY,OAAY;IACzC;IAEUC,iBAAiBD,OAAsB,EAAU;QACzD,OAAOJ,KAAKM,KAAK,CAACF;IACpB;IAEAG,WAAkC;QAChC,MAAM,IAAIC,MAAM;IAClB;IAEAC,WAAkC;QAChC,MAAM,IAAID,MAAM;IAClB;IAEAE,UAAoC;QAClC,MAAM,IAAIF,MAAM;IAClB;IAEAG,UAAiC;QAC/B,MAAM,IAAIH,MAAM;IAClB;IAEAI,YAAYA,WAAmB,EAAsB;QACnD,OAAO,IAAIV,UAAU;YAAE,GAAG,IAAI,CAACE,OAAO;YAAEQ;QAAY;IACtD;IAEAC,WAA+B;QAC7B,MAAM,IAAIL,MAAM;IAClB;AACF"}
@@ -1,94 +1,148 @@
1
1
  import { Type } from '@sinclair/typebox';
2
2
  import { BaseType } from "./base.js";
3
3
  export class NumberType extends BaseType {
4
- constructor(schema = Type.Number(), nullable = false, optional = false){
5
- super(schema, nullable, optional);
4
+ options;
5
+ constructor(options = {}, isNullable = false, isOptional = false, hasDefault = false){
6
+ super(options, isNullable, isOptional, hasDefault);
7
+ this.options = options;
8
+ }
9
+ _constructSchema(options) {
10
+ return Type.Number(options);
11
+ }
12
+ nullable() {
13
+ return new NumberType(...this._with({
14
+ isNullable: true
15
+ }));
16
+ }
17
+ optional() {
18
+ return new NumberType(...this._with({
19
+ isOptional: true
20
+ }));
21
+ }
22
+ nullish() {
23
+ return new NumberType(...this._with({
24
+ isNullable: true,
25
+ isOptional: true
26
+ }));
27
+ }
28
+ default(value) {
29
+ return new NumberType(...this._with({
30
+ options: {
31
+ default: value
32
+ },
33
+ hasDefault: true
34
+ }));
35
+ }
36
+ description(description) {
37
+ return new NumberType(...this._with({
38
+ options: {
39
+ description
40
+ }
41
+ }));
42
+ }
43
+ examples(...examples) {
44
+ return new NumberType(...this._with({
45
+ options: {
46
+ examples
47
+ }
48
+ }));
6
49
  }
7
50
  positive() {
8
- return new NumberType(Type.Number({
9
- ...this._schema,
10
- minimum: 0,
11
- exclusiveMinimum: 0
12
- }), ...this._isNullableOptional);
51
+ return this.min(0, true);
13
52
  }
14
53
  negative() {
15
- return new NumberType(Type.Number({
16
- ...this._schema,
17
- maximum: 0,
18
- exclusiveMaximum: 0
19
- }), ...this._isNullableOptional);
54
+ return this.max(0, true);
20
55
  }
21
56
  max(value, exclusive) {
22
- return new NumberType(Type.Number({
23
- ...this._schema,
24
- maximum: value,
25
- ...exclusive ? {} : {
26
- exclusiveMaximum: value
57
+ return new NumberType(...this._with({
58
+ options: {
59
+ maximum: value,
60
+ ...exclusive ? {} : {
61
+ exclusiveMaximum: value
62
+ }
27
63
  }
28
- }), ...this._isNullableOptional);
64
+ }));
29
65
  }
30
66
  min(value, exclusive) {
31
- return new NumberType(Type.Number({
32
- ...this._schema,
33
- minimum: value,
34
- ...exclusive ? {} : {
35
- exclusiveMinimum: value
67
+ return new NumberType(...this._with({
68
+ options: {
69
+ minimum: value,
70
+ ...exclusive ? {} : {
71
+ exclusiveMinimum: value
72
+ }
36
73
  }
37
- }), ...this._isNullableOptional);
74
+ }));
75
+ }
76
+ }
77
+ export class IntegerType extends BaseType {
78
+ constructor(options = {}, isNullable = false, isOptional = false, hasDefault = false){
79
+ super(options, isNullable, isOptional, hasDefault);
80
+ }
81
+ _constructSchema(options) {
82
+ return Type.Integer(options);
38
83
  }
39
84
  nullable() {
40
- return new NumberType(...this._nullable());
85
+ return new IntegerType(...this._with({
86
+ isNullable: true
87
+ }));
41
88
  }
42
89
  optional() {
43
- return new NumberType(...this._optional());
90
+ return new IntegerType(...this._with({
91
+ isOptional: true
92
+ }));
44
93
  }
45
94
  nullish() {
46
- return new NumberType(...this._nullish());
95
+ return new IntegerType(...this._with({
96
+ isNullable: true,
97
+ isOptional: true
98
+ }));
99
+ }
100
+ default(value) {
101
+ return new IntegerType(...this._with({
102
+ options: {
103
+ default: value
104
+ },
105
+ hasDefault: true
106
+ }));
107
+ }
108
+ description(description) {
109
+ return new IntegerType(...this._with({
110
+ options: {
111
+ description
112
+ }
113
+ }));
47
114
  }
48
- }
49
- export class IntegerType extends BaseType {
50
- constructor(schema = Type.Integer(), nullable = false, optional = false){
51
- super(schema, nullable, optional);
115
+ examples(...examples) {
116
+ return new IntegerType(...this._with({
117
+ options: {
118
+ examples
119
+ }
120
+ }));
52
121
  }
53
122
  positive() {
54
- return new IntegerType(Type.Integer({
55
- ...this._schema,
56
- minimum: 0,
57
- exclusiveMinimum: 0
58
- }), ...this._isNullableOptional);
123
+ return this.min(0, true);
59
124
  }
60
125
  negative() {
61
- return new IntegerType(Type.Integer({
62
- ...this._schema,
63
- maximum: 0,
64
- exclusiveMaximum: 0
65
- }), ...this._isNullableOptional);
126
+ return this.max(0, true);
66
127
  }
67
128
  max(value, exclusive) {
68
- return new IntegerType(Type.Integer({
69
- ...this._schema,
70
- maximum: value,
71
- ...exclusive ? {} : {
72
- exclusiveMaximum: value
129
+ return new IntegerType(...this._with({
130
+ options: {
131
+ maximum: value,
132
+ ...exclusive ? {} : {
133
+ exclusiveMaximum: value
134
+ }
73
135
  }
74
- }), ...this._isNullableOptional);
136
+ }));
75
137
  }
76
138
  min(value, exclusive) {
77
- return new IntegerType(Type.Integer({
78
- ...this._schema,
79
- minimum: value,
80
- ...exclusive ? {} : {
81
- exclusiveMinimum: value
139
+ return new IntegerType(...this._with({
140
+ options: {
141
+ minimum: value,
142
+ ...exclusive ? {} : {
143
+ exclusiveMinimum: value
144
+ }
82
145
  }
83
- }), ...this._isNullableOptional);
84
- }
85
- nullable() {
86
- return new IntegerType(...this._nullable());
87
- }
88
- optional() {
89
- return new IntegerType(...this._optional());
90
- }
91
- nullish() {
92
- return new IntegerType(...this._nullish());
146
+ }));
93
147
  }
94
148
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/types/number.ts"],"sourcesContent":["import { type TInteger, type TNumber, Type } from '@sinclair/typebox'\nimport { BaseType } from './base.ts'\n\nexport class NumberType<\n N extends boolean = false,\n O extends boolean = false,\n> extends BaseType<TNumber, N, O> {\n constructor(\n schema: TNumber = Type.Number(),\n nullable: N = false as N,\n optional: O = false as O,\n ) {\n super(schema, nullable, optional)\n }\n\n positive() {\n return new NumberType(\n Type.Number({ ...this._schema, minimum: 0, exclusiveMinimum: 0 }),\n ...this._isNullableOptional,\n )\n }\n\n negative() {\n return new NumberType(\n Type.Number({ ...this._schema, maximum: 0, exclusiveMaximum: 0 }),\n ...this._isNullableOptional,\n )\n }\n\n max(value: number, exclusive?: true) {\n return new NumberType(\n Type.Number({\n ...this._schema,\n maximum: value,\n ...(exclusive ? {} : { exclusiveMaximum: value }),\n }),\n ...this._isNullableOptional,\n )\n }\n\n min(value: number, exclusive?: true) {\n return new NumberType(\n Type.Number({\n ...this._schema,\n minimum: value,\n ...(exclusive ? {} : { exclusiveMinimum: value }),\n }),\n ...this._isNullableOptional,\n )\n }\n\n nullable() {\n return new NumberType(...this._nullable())\n }\n\n optional() {\n return new NumberType(...this._optional())\n }\n\n nullish() {\n return new NumberType(...this._nullish())\n }\n}\n\nexport class IntegerType<\n N extends boolean = false,\n O extends boolean = false,\n> extends BaseType<TInteger, N, O> {\n constructor(\n schema: TInteger = Type.Integer(),\n nullable: N = false as N,\n optional: O = false as O,\n ) {\n super(schema, nullable, optional)\n }\n\n positive() {\n return new IntegerType(\n Type.Integer({ ...this._schema, minimum: 0, exclusiveMinimum: 0 }),\n ...this._isNullableOptional,\n )\n }\n\n negative() {\n return new IntegerType(\n Type.Integer({ ...this._schema, maximum: 0, exclusiveMaximum: 0 }),\n ...this._isNullableOptional,\n )\n }\n\n max(value: number, exclusive?: true) {\n return new IntegerType(\n Type.Integer({\n ...this._schema,\n maximum: value,\n ...(exclusive ? {} : { exclusiveMaximum: value }),\n }),\n ...this._isNullableOptional,\n )\n }\n\n min(value: number, exclusive?: true) {\n return new IntegerType(\n Type.Integer({\n ...this._schema,\n minimum: value,\n ...(exclusive ? {} : { exclusiveMinimum: value }),\n }),\n ...this._isNullableOptional,\n )\n }\n\n nullable() {\n return new IntegerType(...this._nullable())\n }\n\n optional() {\n return new IntegerType(...this._optional())\n }\n\n nullish() {\n return new IntegerType(...this._nullish())\n }\n}\n"],"names":["Type","BaseType","NumberType","constructor","schema","Number","nullable","optional","positive","_schema","minimum","exclusiveMinimum","_isNullableOptional","negative","maximum","exclusiveMaximum","max","value","exclusive","min","_nullable","_optional","nullish","_nullish","IntegerType","Integer"],"mappings":"AAAA,SAAsCA,IAAI,QAAQ,oBAAmB;AACrE,SAASC,QAAQ,QAAQ,YAAW;AAEpC,OAAO,MAAMC,mBAGHD;IACRE,YACEC,SAAkBJ,KAAKK,MAAM,EAAE,EAC/BC,WAAc,KAAU,EACxBC,WAAc,KAAU,CACxB;QACA,KAAK,CAACH,QAAQE,UAAUC;IAC1B;IAEAC,WAAW;QACT,OAAO,IAAIN,WACTF,KAAKK,MAAM,CAAC;YAAE,GAAG,IAAI,CAACI,OAAO;YAAEC,SAAS;YAAGC,kBAAkB;QAAE,OAC5D,IAAI,CAACC,mBAAmB;IAE/B;IAEAC,WAAW;QACT,OAAO,IAAIX,WACTF,KAAKK,MAAM,CAAC;YAAE,GAAG,IAAI,CAACI,OAAO;YAAEK,SAAS;YAAGC,kBAAkB;QAAE,OAC5D,IAAI,CAACH,mBAAmB;IAE/B;IAEAI,IAAIC,KAAa,EAAEC,SAAgB,EAAE;QACnC,OAAO,IAAIhB,WACTF,KAAKK,MAAM,CAAC;YACV,GAAG,IAAI,CAACI,OAAO;YACfK,SAASG;YACT,GAAIC,YAAY,CAAC,IAAI;gBAAEH,kBAAkBE;YAAM,CAAC;QAClD,OACG,IAAI,CAACL,mBAAmB;IAE/B;IAEAO,IAAIF,KAAa,EAAEC,SAA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AAIC,YAAY,CAAC,IAAI;gBAAEP,kBAAkBM;YAAM,CAAC;QAClD,OACG,IAAI,CAACL,mBAAmB;IAE/B;IAEAN,WAAW;QACT,OAAO,IAAIkB,eAAe,IAAI,CAACJ,SAAS;IAC1C;IAEAb,WAAW;QACT,OAAO,IAAIiB,eAAe,IAAI,CAACH,SAAS;IAC1C;IAEAC,UAAU;QACR,OAAO,IAAIE,eAAe,IAAI,CAACD,QAAQ;IACzC;AACF"}
1
+ {"version":3,"sources":["../../../src/types/number.ts"],"sourcesContent":["import {\n type IntegerOptions,\n type NumberOptions,\n type TInteger,\n type TNumber,\n Type,\n} from '@sinclair/typebox'\nimport { BaseType } from './base.ts'\n\nexport class NumberType<\n N extends boolean = false,\n O extends boolean = false,\n D extends boolean = false,\n> extends BaseType<TNumber, N, O, D, NumberOptions> {\n constructor(\n protected readonly options: NumberOptions = {},\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: NumberOptions): TNumber {\n return Type.Number(options)\n }\n\n nullable() {\n return new NumberType(...this._with({ isNullable: true }))\n }\n\n optional() {\n return new NumberType(...this._with({ isOptional: true }))\n }\n\n nullish() {\n return new NumberType(...this._with({ isNullable: true, isOptional: true }))\n }\n\n default(value: number) {\n return new NumberType(\n ...this._with({ options: { default: value }, hasDefault: true }),\n )\n }\n\n description(description: string) {\n return new NumberType(...this._with({ options: { description } }))\n }\n\n examples(...examples: [number, ...number[]]) {\n return new NumberType(...this._with({ options: { examples } }))\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 new NumberType(\n ...this._with({\n options: {\n maximum: value,\n ...(exclusive ? {} : { exclusiveMaximum: value }),\n },\n }),\n )\n }\n\n min(value: number, exclusive?: true) {\n return new NumberType(\n ...this._with({\n options: {\n minimum: value,\n ...(exclusive ? {} : { exclusiveMinimum: value }),\n },\n }),\n )\n }\n}\n\nexport class IntegerType<\n N extends boolean = false,\n O extends boolean = false,\n D extends boolean = false,\n> extends BaseType<TInteger, N, O, D, IntegerOptions> {\n constructor(\n options: IntegerOptions = {},\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: IntegerOptions): TInteger {\n return Type.Integer(options)\n }\n\n nullable() {\n return new IntegerType(...this._with({ isNullable: true }))\n }\n\n optional() {\n return new IntegerType(...this._with({ isOptional: true }))\n }\n\n nullish() {\n return new IntegerType(\n ...this._with({ isNullable: true, isOptional: true }),\n )\n }\n\n default(value: number) {\n return new IntegerType(\n ...this._with({ options: { default: value }, hasDefault: true }),\n )\n }\n\n description(description: string) {\n return new IntegerType(...this._with({ options: { description } }))\n }\n\n examples(...examples: [number, ...number[]]) {\n return new IntegerType(...this._with({ options: { examples } }))\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 new IntegerType(\n ...this._with({\n options: {\n maximum: value,\n ...(exclusive ? {} : { exclusiveMaximum: value }),\n },\n }),\n )\n }\n\n min(value: number, exclusive?: true) {\n return new IntegerType(\n ...this._with({\n options: {\n minimum: value,\n ...(exclusive ? {} : { exclusiveMinimum: value }),\n },\n }),\n )\n }\n}\n"],"names":["Type","BaseType","NumberType","constructor","options","isNullable","isOptional","hasDefault","_constructSchema","Number","nullable","_with","optional","nullish","default","value","description","examples","positive","min","negative","max","exclusive","maximum","exclusiveMaximum","minimum","exclusiveMinimum","IntegerType","Integer"],"mappings":"AAAA,SAKEA,IAAI,QACC,oBAAmB;AAC1B,SAASC,QAAQ,QAAQ,YAAW;AAEpC,OAAO,MAAMC,mBAIHD;;IACRE,YACE,AAAmBC,UAAyB,CAAC,CAAC,EAC9CC,aAAgB,KAAU,EAC1BC,aAAgB,KAAU,EAC1BC,aAAgB,KAAU,CAC1B;QACA,K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