@nmtjs/type 0.3.7 → 0.3.8

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.
@@ -4,11 +4,11 @@ import { BaseType } from "./base.js";
4
4
  export class ObjectEnumType extends BaseType {
5
5
  values;
6
6
  constructor(values, options = {}, isNullable = false, isOptional = false, hasDefault = false){
7
- super(options, isNullable, isOptional, hasDefault);
7
+ super(options, isNullable, isOptional, hasDefault, values);
8
8
  this.values = values;
9
9
  }
10
- _constructSchema(options) {
11
- return NativeEnum(this.values, options);
10
+ _constructSchema(options, values) {
11
+ return NativeEnum(values, options);
12
12
  }
13
13
  nullable() {
14
14
  return new ObjectEnumType(this.values, ...this._with({
@@ -1 +1 @@
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 type AnyObjectEnumType<T extends { [K in string]: K } = any> =\n ObjectEnumType<T, boolean, boolean, boolean>\nexport class ObjectEnumType<\n T extends { [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 ObjectEnumType(this.values, ...this._with({ isNullable: true }))\n }\n\n optional() {\n return new ObjectEnumType(this.values, ...this._with({ isOptional: true }))\n }\n\n nullish() {\n return new ObjectEnumType(\n this.values,\n ...this._with({ isNullable: true, isOptional: true }),\n )\n }\n\n default(value: keyof T) {\n return new ObjectEnumType(\n this.values,\n ...this._with({ options: { default: value }, hasDefault: true }),\n )\n }\n\n description(description: string) {\n return new ObjectEnumType(\n this.values,\n ...this._with({ options: { description } }),\n )\n }\n\n examples(...examples: (keyof T)[]) {\n return new ObjectEnumType(\n this.values,\n ...this._with({ options: { examples } }),\n )\n }\n}\n\nexport type AnyEnumType = EnumType<any[], boolean, boolean, boolean>\nexport class EnumType<\n T extends (string | number)[] = (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","ObjectEnumType","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;AAIpC,OAAO,MAAMC,uBAKHD;;IACRE,YACE,AAASC,MAAS,EAClBC,UAAyB,CAAC,CAAC,EAC3BC,aAAgB,K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sB,EACtBD,MAAc,EACC;QACf,OAAOJ,UAAUI,QAAQC;IAC3B;IAEAK,WAAW;QACT,OAAO,IAAIQ,SAAS,IAAI,CAACd,MAAM,KAAK,IAAI,CAACO,KAAK,CAAC;YAAEL,YAAY;QAAK;IACpE;IAEAM,WAAW;QACT,OAAO,IAAIM,SAAS,IAAI,CAACd,MAAM,KAAK,IAAI,CAACO,KAAK,CAAC;YAAEJ,YAAY;QAAK;IACpE;IAEAM,UAAU;QACR,OAAO,IAAIK,SACT,IAAI,CAACd,MAAM,KACR,IAAI,CAACO,KAAK,CAAC;YAAEL,YAAY;YAAMC,YAAY;QAAK;IAEvD;IAEAO,QAAQC,KAAgB,EAAE;QACxB,OAAO,IAAIG,SACT,IAAI,CAACd,MAAM,KACR,IAAI,CAACO,KAAK,CAAC;YAAEN,SAAS;gBAAES,SAASC;YAAM;YAAGP,YAAY;QAAK;IAElE;IAEAQ,YAAYA,WAAmB,EAAE;QAC/B,OAAO,IAAIE,SACT,IAAI,CAACd,MAAM,KACR,IAAI,CAACO,KAAK,CAAC;YAAEN,SAAS;gBAAEW;YAAY;QAAE;IAE7C;IAEAC,SAAS,GAAGA,QAAqC,EAAE;QACjD,OAAO,IAAIC,SAAS,IAAI,CAACd,MAAM,KAAK,IAAI,CAACO,KAAK,CAAC;YAAEN,SAAS;gBAAEY;YAAS;QAAE;IACzE;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 type AnyObjectEnumType<T extends { [K in string]: K } = any> =\n ObjectEnumType<T, boolean, boolean, boolean>\nexport class ObjectEnumType<\n T extends { [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 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 ): TNativeEnum<T> {\n return NativeEnum(values, options)\n }\n\n nullable() {\n return new ObjectEnumType(this.values, ...this._with({ isNullable: true }))\n }\n\n optional() {\n return new ObjectEnumType(this.values, ...this._with({ isOptional: true }))\n }\n\n nullish() {\n return new ObjectEnumType(\n this.values,\n ...this._with({ isNullable: true, isOptional: true }),\n )\n }\n\n default(value: keyof T) {\n return new ObjectEnumType(\n this.values,\n ...this._with({ options: { default: value }, hasDefault: true }),\n )\n }\n\n description(description: string) {\n return new ObjectEnumType(\n this.values,\n ...this._with({ options: { description } }),\n )\n }\n\n examples(...examples: (keyof T)[]) {\n return new ObjectEnumType(\n this.values,\n ...this._with({ options: { examples } }),\n )\n }\n}\n\nexport type AnyEnumType = EnumType<any[], boolean, boolean, boolean>\nexport class EnumType<\n T extends (string | number)[] = (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","ObjectEnumType","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;AAIpC,OAAO,MAAMC,uBAKHD;;IACRE,YACE,AAAmBC,MAAS,EAC5BC,UAAyB,CAAC,CAAC,EAC3BC,aAAgB,KAAU,EAC1BC,aAAgB,KAAU,EAC1BC,aAAgB,KAAU,CAC1B;QACA,KAAK,CAACH,SAASC,YAAYC,YAAYC,YAAYJ;aANhCA,SAAAA;IAOrB;IAEUK,iBACRJ,OAAsB,EACtBD,MAAS,EACO;QAChB,OAAOL,WAAWK,QAAQC;IAC5B;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;gBAA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AS;gBAAEY;YAAS;QAAE;IACzE;AACF"}
@@ -3,11 +3,11 @@ import { BaseType, getTypeSchema } from "./base.js";
3
3
  export class UnionType extends BaseType {
4
4
  types;
5
5
  constructor(types, options = {}, isNullable = false, isOptional = false, hasDefault = false){
6
- super(options, isNullable, isOptional, hasDefault);
6
+ super(options, isNullable, isOptional, hasDefault, types);
7
7
  this.types = types;
8
8
  }
9
- _constructSchema(options) {
10
- return Type.Union(this.types.map(getTypeSchema), options);
9
+ _constructSchema(options, types) {
10
+ return Type.Union(types.map(getTypeSchema), options);
11
11
  }
12
12
  nullable() {
13
13
  return new UnionType(this.types, ...this._with({
@@ -51,11 +51,11 @@ export class UnionType extends BaseType {
51
51
  export class IntersactionType extends BaseType {
52
52
  types;
53
53
  constructor(types, options = {}, isNullable = false, isOptional = false, hasDefault = false){
54
- super(options, isNullable, isOptional, hasDefault);
54
+ super(options, isNullable, isOptional, hasDefault, types);
55
55
  this.types = types;
56
56
  }
57
- _constructSchema(options) {
58
- return Type.Intersect(this.types.map(getTypeSchema), options);
57
+ _constructSchema(options, types) {
58
+ return Type.Intersect(types.map(getTypeSchema), options);
59
59
  }
60
60
  nullable() {
61
61
  return new IntersactionType(this.types, ...this._with({
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/types/union.ts"],"sourcesContent":["import {\n type SchemaOptions,\n type TIntersect,\n type TUnion,\n Type,\n} from '@sinclair/typebox'\nimport type { typeStatic } from '../constants.ts'\nimport type { UnionToTuple } from '../utils.ts'\nimport { BaseType, getTypeSchema } from './base.ts'\n\nexport type AnyUnionType<\n T extends [BaseType, BaseType, ...BaseType[]] = [\n BaseType,\n BaseType,\n ...BaseType[],\n ],\n> = UnionType<T, boolean, boolean, boolean>\nexport class UnionType<\n T extends [BaseType, BaseType, ...BaseType[]] = [\n BaseType,\n BaseType,\n ...BaseType[],\n ],\n N extends boolean = false,\n O extends boolean = false,\n D extends boolean = false,\n> extends BaseType<\n //@ts-expect-error\n TUnion<UnionToTuple<T[number][typeStatic]['schema']>>,\n N,\n O,\n D\n> {\n constructor(\n readonly types: 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(\n options: SchemaOptions,\n //@ts-expect-error\n ): TUnion<UnionToTuple<T[number][typeStatic]['schema']>> {\n return Type.Union(this.types.map(getTypeSchema), options) as any\n }\n\n nullable() {\n return new UnionType(this.types, ...this._with({ isNullable: true }))\n }\n\n optional() {\n return new UnionType(this.types, ...this._with({ isOptional: true }))\n }\n\n nullish() {\n return new UnionType(\n this.types,\n ...this._with({ isNullable: true, isOptional: true }),\n )\n }\n\n default(value: this[typeStatic]['encoded']) {\n return new UnionType(\n this.types,\n ...this._with({ options: { default: value }, hasDefault: true }),\n )\n }\n\n description(description: string) {\n return new UnionType(\n this.types,\n ...this._with({ options: { description } }),\n )\n }\n\n examples(\n ...examples: [this[typeStatic]['encoded'], ...this[typeStatic]['encoded'][]]\n ) {\n return new UnionType(this.types, ...this._with({ options: { examples } }))\n }\n}\n\nexport class IntersactionType<\n T extends [BaseType, BaseType, ...BaseType[]] = [\n BaseType,\n BaseType,\n ...BaseType[],\n ],\n N extends boolean = false,\n O extends boolean = false,\n D extends boolean = false,\n> extends BaseType<\n // @ts-expect-error\n TIntersect<UnionToTuple<T[number][typeStatic]['schema']>>,\n N,\n O,\n D\n> {\n constructor(\n readonly types: 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(\n options: SchemaOptions,\n // @ts-expect-error\n ): TIntersect<UnionToTuple<T[number][typeStatic]['schema']>> {\n return Type.Intersect(this.types.map(getTypeSchema), options) as any\n }\n\n nullable() {\n return new IntersactionType(this.types, ...this._with({ isNullable: true }))\n }\n\n optional() {\n return new IntersactionType(this.types, ...this._with({ isOptional: true }))\n }\n\n nullish() {\n return new IntersactionType(\n this.types,\n ...this._with({ isNullable: true, isOptional: true }),\n )\n }\n\n default(value: this[typeStatic]['encoded']) {\n return new IntersactionType(\n this.types,\n ...this._with({ options: { default: value }, hasDefault: true }),\n )\n }\n\n description(description: string) {\n return new IntersactionType(\n this.types,\n ...this._with({ options: { description } }),\n )\n }\n\n examples(\n ...values: [this[typeStatic]['encoded'], ...this[typeStatic]['encoded'][]]\n ) {\n return new IntersactionType(\n this.types,\n ...this._with({ options: { examples: values } }),\n )\n }\n}\n"],"names":["Type","BaseType","getTypeSchema","UnionType","constructor","types","options","isNullable","isOptional","hasDefault","_constructSchema","Union","map","nullable","_with","optional","nullish","default","value","description","examples","IntersactionType","Intersect","values"],"mappings":"AAAA,SAIEA,IAAI,QACC,oBAAmB;AAG1B,SAASC,QAAQ,EAAEC,aAAa,QAAQ,YAAW;AASnD,OAAO,MAAMC,kBASHF;;IAORG,YACE,AAASC,KAAQ,EACjBC,UAAyB,CAAC,CAAC,EAC3BC,aAAgB,KAAU,EAC1BC,aAAgB,KAAU,EAC1BC,aAAgB,KAAU,CAC1B;QACA,KAAK,CAACH,SAASC,YAAYC,YAAYC;aAN9BJ,QAAAA;IAOX;IAEUK,iBACRJ,OAAsB,EAEiC;QACvD,OAAON,KAAKW,KAAK,CAAC,IAAI,CAACN,KAAK,CAACO,GAAG,CAACV,gBAAgBI;IACnD;IAEAO,WAAW;QACT,OAAO,IAAIV,UAAU,IAAI,CAACE,KAAK,KAAK,IAAI,CAACS,KAAK,CAAC;YAAEP,YAAY;QAAK;IACpE;IAEAQ,WAAW;QACT,OAAO,IAAIZ,UAAU,IAAI,CAACE,KAAK,KAAK,IAAI,CAACS,KAAK,CAAC;YAAEN,YAAY;QAAK;IACpE;IAEAQ,UAAU;QACR,OAAO,IAAIb,UACT,IAAI,CAACE,KAAK,KACP,IAAI,CAACS,KAAK,CAAC;YAAEP,YAAY;YAAMC,YAAY;QAAK;IAEvD;IAEAS,QAAQC,KAAkC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BAAEW,SAASC;YAAM;YAAGT,YAAY;QAAK;IAElE;IAEAU,YAAYA,WAAmB,EAAE;QAC/B,OAAO,IAAIE,iBACT,IAAI,CAAChB,KAAK,KACP,IAAI,CAACS,KAAK,CAAC;YAAER,SAAS;gBAAEa;YAAY;QAAE;IAE7C;IAEAC,SACE,GAAGG,MAAuE,EAC1E;QACA,OAAO,IAAIF,iBACT,IAAI,CAAChB,KAAK,KACP,IAAI,CAACS,KAAK,CAAC;YAAER,SAAS;gBAAEc,UAAUG;YAAO;QAAE;IAElD;AACF"}
1
+ {"version":3,"sources":["../../../src/types/union.ts"],"sourcesContent":["import {\n type SchemaOptions,\n type TIntersect,\n type TUnion,\n Type,\n} from '@sinclair/typebox'\nimport type { typeStatic } from '../constants.ts'\nimport type { UnionToTuple } from '../utils.ts'\nimport { BaseType, getTypeSchema } from './base.ts'\n\nexport type AnyUnionType<\n T extends [BaseType, BaseType, ...BaseType[]] = [\n BaseType,\n BaseType,\n ...BaseType[],\n ],\n> = UnionType<T, boolean, boolean, boolean>\nexport class UnionType<\n T extends [BaseType, BaseType, ...BaseType[]] = [\n BaseType,\n BaseType,\n ...BaseType[],\n ],\n N extends boolean = false,\n O extends boolean = false,\n D extends boolean = false,\n> extends BaseType<\n //@ts-expect-error\n TUnion<UnionToTuple<T[number][typeStatic]['schema']>>,\n N,\n O,\n D\n> {\n constructor(\n protected readonly types: 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, types)\n }\n\n protected _constructSchema(\n options: SchemaOptions,\n types: T,\n //@ts-expect-error\n ): TUnion<UnionToTuple<T[number][typeStatic]['schema']>> {\n return Type.Union(types.map(getTypeSchema), options) as any\n }\n\n nullable() {\n return new UnionType(this.types, ...this._with({ isNullable: true }))\n }\n\n optional() {\n return new UnionType(this.types, ...this._with({ isOptional: true }))\n }\n\n nullish() {\n return new UnionType(\n this.types,\n ...this._with({ isNullable: true, isOptional: true }),\n )\n }\n\n default(value: this[typeStatic]['encoded']) {\n return new UnionType(\n this.types,\n ...this._with({ options: { default: value }, hasDefault: true }),\n )\n }\n\n description(description: string) {\n return new UnionType(\n this.types,\n ...this._with({ options: { description } }),\n )\n }\n\n examples(\n ...examples: [this[typeStatic]['encoded'], ...this[typeStatic]['encoded'][]]\n ) {\n return new UnionType(this.types, ...this._with({ options: { examples } }))\n }\n}\n\nexport class IntersactionType<\n T extends [BaseType, BaseType, ...BaseType[]] = [\n BaseType,\n BaseType,\n ...BaseType[],\n ],\n N extends boolean = false,\n O extends boolean = false,\n D extends boolean = false,\n> extends BaseType<\n // @ts-expect-error\n TIntersect<UnionToTuple<T[number][typeStatic]['schema']>>,\n N,\n O,\n D\n> {\n constructor(\n protected readonly types: 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, types)\n }\n\n protected _constructSchema(\n options: SchemaOptions,\n types: T,\n // @ts-expect-error\n ): TIntersect<UnionToTuple<T[number][typeStatic]['schema']>> {\n return Type.Intersect(types.map(getTypeSchema), options) as any\n }\n\n nullable() {\n return new IntersactionType(this.types, ...this._with({ isNullable: true }))\n }\n\n optional() {\n return new IntersactionType(this.types, ...this._with({ isOptional: true }))\n }\n\n nullish() {\n return new IntersactionType(\n this.types,\n ...this._with({ isNullable: true, isOptional: true }),\n )\n }\n\n default(value: this[typeStatic]['encoded']) {\n return new IntersactionType(\n this.types,\n ...this._with({ options: { default: value }, hasDefault: true }),\n )\n }\n\n description(description: string) {\n return new IntersactionType(\n this.types,\n ...this._with({ options: { description } }),\n )\n }\n\n examples(\n ...values: [this[typeStatic]['encoded'], ...this[typeStatic]['encoded'][]]\n ) {\n return new IntersactionType(\n this.types,\n ...this._with({ options: { examples: values } }),\n )\n }\n}\n"],"names":["Type","BaseType","getTypeSchema","UnionType","constructor","types","options","isNullable","isOptional","hasDefault","_constructSchema","Union","map","nullable","_with","optional","nullish","default","value","description","examples","IntersactionType","Intersect","values"],"mappings":"AAAA,SAIEA,IAAI,QACC,oBAAmB;AAG1B,SAASC,QAAQ,EAAEC,aAAa,QAAQ,YAAW;AASnD,OAAO,MAAMC,kBASHF;;IAORG,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,iBACRJ,OAAsB,EACtBD,KAAQ,EAE+C;QACvD,OAAOL,KAAKW,KAAK,CAACN,MAAMO,GAAG,CAACV,gBAAgBI;IAC9C;IAEAO,WAAW;QACT,OAAO,IAAIV,UAAU,IAAI,CAACE,KAAK,KAAK,IAAI,CAACS,KAAK,CAAC;YAAEP,YAAY;QAAK;IACpE;IAEAQ,WAAW;QACT,OAAO,IAAIZ,UAAU,IAAI,CAACE,KAAK,KAAK,IAAI,CAACS,KAAK,CAAC;YAAEN,YAAY;QAAK;IACpE;IAEAQ,UAAU;QACR,OAAO,IAAIb,UACT,IAAI,CAACE,KAAK,KACP,IAAI,CAACS,KAAK,CAAC;YAAEP,YAAY;YAAMC,YAAY;QAAK;IAEvD;IAEAS,QAAQC,KAAkC,EAAE;QAC1C,OAAO,IAAIf,UACT,IAAI,CAACE,KAAK,KACP,IAAI,CAACS,KAAK,CAAC;YAAER,SAAS;gBAAEW,SAASC;YAAM;YAAGT,YAAY;QAAK;IAElE;IAEAU,YAAYA,WAAmB,EAAE;QAC/B,OAAO,IAAIhB,UACT,IAAI,CAACE,KAAK,KACP,IAAI,CAACS,KAAK,CAAC;YAAER,SAAS;gBAAEa;YAAY;QAAE;IAE7C;IAEAC,SACE,GAAGA,QAAyE,EAC5E;QACA,OAAO,IAAIjB,UAAU,IAAI,CAACE,KAAK,KAAK,IAAI,CAACS,KAAK,CAAC;YAAER,SAAS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erDependencies": {
22
22
  "@sinclair/typebox": "^0.33.7",
23
23
  "temporal-polyfill": "^0.2.5",
24
- "@nmtjs/common": "0.3.7"
24
+ "@nmtjs/common": "0.3.8"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@sinclair/typebox": "^0.33.7",
28
28
  "temporal-polyfill": "^0.2.5",
29
- "@nmtjs/common": "0.3.7"
29
+ "@nmtjs/common": "0.3.8"
30
30
  },
31
31
  "files": [
32
32
  "src",
@@ -35,7 +35,7 @@
35
35
  "LICENSE.md",
36
36
  "README.md"
37
37
  ],
38
- "version": "0.3.7",
38
+ "version": "0.3.8",
39
39
  "scripts": {
40
40
  "build": "neemata-build -p neutral --root=./src './**/*.ts'",
41
41
  "type-check": "tsc --noEmit"
package/src/types/enum.ts CHANGED
@@ -13,17 +13,20 @@ export class ObjectEnumType<
13
13
  D extends boolean = false,
14
14
  > extends BaseType<TNativeEnum<T>, N, O, D> {
15
15
  constructor(
16
- readonly values: T,
16
+ protected readonly values: T,
17
17
  options: SchemaOptions = {},
18
18
  isNullable: N = false as N,
19
19
  isOptional: O = false as O,
20
20
  hasDefault: D = false as D,
21
21
  ) {
22
- super(options, isNullable, isOptional, hasDefault)
22
+ super(options, isNullable, isOptional, hasDefault, values)
23
23
  }
24
24
 
25
- protected _constructSchema(options: SchemaOptions): TNativeEnum<T> {
26
- return NativeEnum(this.values, options)
25
+ protected _constructSchema(
26
+ options: SchemaOptions,
27
+ values: T,
28
+ ): TNativeEnum<T> {
29
+ return NativeEnum(values, options)
27
30
  }
28
31
 
29
32
  nullable() {
@@ -32,20 +32,21 @@ export class UnionType<
32
32
  D
33
33
  > {
34
34
  constructor(
35
- readonly types: T,
35
+ protected readonly types: T,
36
36
  options: SchemaOptions = {},
37
37
  isNullable: N = false as N,
38
38
  isOptional: O = false as O,
39
39
  hasDefault: D = false as D,
40
40
  ) {
41
- super(options, isNullable, isOptional, hasDefault)
41
+ super(options, isNullable, isOptional, hasDefault, types)
42
42
  }
43
43
 
44
44
  protected _constructSchema(
45
45
  options: SchemaOptions,
46
+ types: T,
46
47
  //@ts-expect-error
47
48
  ): TUnion<UnionToTuple<T[number][typeStatic]['schema']>> {
48
- return Type.Union(this.types.map(getTypeSchema), options) as any
49
+ return Type.Union(types.map(getTypeSchema), options) as any
49
50
  }
50
51
 
51
52
  nullable() {
@@ -101,20 +102,21 @@ export class IntersactionType<
101
102
  D
102
103
  > {
103
104
  constructor(
104
- readonly types: T,
105
+ protected readonly types: T,
105
106
  options: SchemaOptions = {},
106
107
  isNullable: N = false as N,
107
108
  isOptional: O = false as O,
108
109
  hasDefault: D = false as D,
109
110
  ) {
110
- super(options, isNullable, isOptional, hasDefault)
111
+ super(options, isNullable, isOptional, hasDefault, types)
111
112
  }
112
113
 
113
114
  protected _constructSchema(
114
115
  options: SchemaOptions,
116
+ types: T,
115
117
  // @ts-expect-error
116
118
  ): TIntersect<UnionToTuple<T[number][typeStatic]['schema']>> {
117
- return Type.Intersect(this.types.map(getTypeSchema), options) as any
119
+ return Type.Intersect(types.map(getTypeSchema), options) as any
118
120
  }
119
121
 
120
122
  nullable() {