@nmtjs/type 0.3.4 → 0.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/schemas/native-enum.js.map +1 -1
- package/dist/types/enum.js +7 -7
- package/dist/types/enum.js.map +1 -1
- package/dist/types/object.js.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +5 -5
- package/src/schemas/native-enum.ts +1 -1
- package/src/types/enum.ts +9 -9
- package/src/types/object.ts +2 -2
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { ArrayType } from "./types/array.js";
|
|
|
2
2
|
import { BooleanType } from "./types/boolean.js";
|
|
3
3
|
import { CustomType } from "./types/custom.js";
|
|
4
4
|
import { DateType } from "./types/datetime.js";
|
|
5
|
-
import { EnumType,
|
|
5
|
+
import { EnumType, ObjectEnumType } from "./types/enum.js";
|
|
6
6
|
import { LiteralType } from "./types/literal.js";
|
|
7
7
|
import { BigIntType, IntegerType, NumberType } from "./types/number.js";
|
|
8
8
|
import { ObjectType, RecordType } from "./types/object.js";
|
|
@@ -26,7 +26,7 @@ export var t;
|
|
|
26
26
|
t.integer = ()=>new IntegerType();
|
|
27
27
|
t.bitint = ()=>new BigIntType();
|
|
28
28
|
t.literal = (value)=>new LiteralType(value);
|
|
29
|
-
t.
|
|
29
|
+
t.objectEnum = (enumLike)=>new ObjectEnumType(enumLike);
|
|
30
30
|
t.arrayEnum = (enumLike)=>new EnumType(enumLike);
|
|
31
31
|
t.date = ()=>new DateType();
|
|
32
32
|
t.array = (element)=>new ArrayType(element);
|
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 } from './types/base.ts'\nimport { BooleanType } from './types/boolean.ts'\nimport { CustomType } from './types/custom.ts'\nimport { DateType } from './types/datetime.ts'\nimport {\n type AnyEnumType,\n type
|
|
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 {\n type AnyEnumType,\n type AnyObjectEnumType,\n EnumType,\n ObjectEnumType,\n} from './types/enum.ts'\nimport { type AnyLiteralType, LiteralType } from './types/literal.ts'\nimport { BigIntType, IntegerType, NumberType } from './types/number.ts'\nimport { ObjectType, RecordType } from './types/object.ts'\nimport { type AnyStringType, StringType } from './types/string.ts'\nimport {\n type AnyUnionType,\n IntersactionType,\n UnionType,\n} from './types/union.ts'\n\nimport type { typeStatic } from './constants.ts'\nimport { AnyType } from './types/any.ts'\nimport { NeverType } from './types/never.ts'\n\n// register ajv formats\nimport { register } from './formats.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 bitint = () => new BigIntType()\n export const literal = <T extends TLiteralValue>(value: T) =>\n new LiteralType(value)\n export const objectEnum = <T extends { [K in string]: K }>(enumLike: T) =>\n new ObjectEnumType(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 record = <\n K extends\n | AnyLiteralType\n | AnyEnumType\n | AnyObjectEnumType\n | AnyStringType\n | AnyUnionType,\n E extends BaseType,\n >(\n key: K,\n value: E,\n ) => new RecordType(key, value)\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","ObjectEnumType","LiteralType","BigIntType","IntegerType","NumberType","ObjectType","RecordType","StringType","IntersactionType","UnionType","AnyType","NeverType","register","BaseType","getTypeSchema","t","never","boolean","string","number","integer","bitint","literal","value","objectEnum","enumLike","arrayEnum","date","array","element","object","properties","record","key","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,SAGEC,QAAQ,EACRC,cAAc,QACT,kBAAiB;AACxB,SAA8BC,WAAW,QAAQ,qBAAoB;AACrE,SAASC,UAAU,EAAEC,WAAW,EAAEC,UAAU,QAAQ,oBAAmB;AACvE,SAASC,UAAU,EAAEC,UAAU,QAAQ,oBAAmB;AAC1D,SAA6BC,UAAU,QAAQ,oBAAmB;AAClE,SAEEC,gBAAgB,EAChBC,SAAS,QACJ,mBAAkB;AAGzB,SAASC,OAAO,QAAQ,iBAAgB;AACxC,SAASC,SAAS,QAAQ,mBAAkB;AAG5C,SAASC,QAAQ,QAAQ,eAAc;AACvCA;AAEA,cAAc,2BAA0B;AACxC,cAAc,0BAAyB;AACvC,cAAc,wBAAuB;AACrC,SACEC,QAAQ,EACRC,aAAa,QACR,kBAAiB;AAExB,SACEnB,SAAS,EACTC,WAAW,EACXC,UAAU,EACVC,QAAQ,EACRC,QAAQ,EACRE,WAAW,EACXE,WAAW,EACXC,UAAU,EACVC,UAAU,EACVE,UAAU,EACVC,gBAAgB,EAChBC,SAAS,EACTC,OAAO,EACPC,SAAS,KACV;;UAEgBI;MAKFC,QAAQ,IAAM,IAAIL;MAClBM,UAAU,IAAM,IAAIrB;MACpBsB,SAAS,IAAM,IAAIX;MACnBY,SAAS,IAAM,IAAIf;MACnBgB,UAAU,IAAM,IAAIjB;MACpBkB,SAAS,IAAM,IAAInB;MACnBoB,UAAU,CAA0BC,QAC/C,IAAItB,YAAYsB;MACLC,aAAa,CAAiCC,WACzD,IAAIzB,eAAeyB;MACRC,YAAY,CAAgCD,WACvD,IAAI1B,SAAS0B;MACFE,OAAO,IAAM,IAAI7B;MACjB8B,QAAQ,CAAqBC,UACxC,IAAIlC,UAAUkC;MACHC,SAAS,CAAqCC,aACzD,IAAI1B,WAAW0B;MACJC,SAAS,CASpBC,KACAV,QACG,IAAIjB,WAAW2B,KAAKV;MACZW,MAAM,IAAM,IAAIxB;MAChByB,KAAK,CAChB,GAAGC,QACA,IAAI3B,UAAU2B;MACNC,MAAM,CACjB,GAAGD,QACA,IAAI5B,iBAAiB4B;MACbE,SAAS,CACpBC,QACAC,SACG,IAAI3C,WAAc0C,QAAQC;AACjC,GA7CiBzB,MAAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/schemas/native-enum.ts"],"sourcesContent":["import {\n Kind,\n type SchemaOptions,\n type TSchema,\n TypeRegistry,\n} from '@sinclair/typebox/type'\n\nexport const NativeEnumKind = 'NativeEnum'\nexport interface TNativeEnum<T extends Record<string, string>> extends TSchema {\n [Kind]: typeof NativeEnumKind\n static: T[keyof T]
|
|
1
|
+
{"version":3,"sources":["../../../src/schemas/native-enum.ts"],"sourcesContent":["import {\n Kind,\n type SchemaOptions,\n type TSchema,\n TypeRegistry,\n} from '@sinclair/typebox/type'\n\nexport const NativeEnumKind = 'NativeEnum'\nexport interface TNativeEnum<T extends Record<string, string>> extends TSchema {\n [Kind]: typeof NativeEnumKind\n static: T[keyof T]\n enum: T[keyof T][]\n}\n\nexport function NativeEnum<T extends Record<string, string>>(\n value: T,\n options: SchemaOptions = {},\n) {\n const values = Object.values(value)\n\n function NativeEnumCheck(schema: TNativeEnum<T>, value: unknown) {\n return typeof value === 'string' && schema.enum.includes(value as any)\n }\n\n if (!TypeRegistry.Has(NativeEnumKind))\n TypeRegistry.Set(NativeEnumKind, NativeEnumCheck)\n\n return { ...options, [Kind]: NativeEnumKind, enum: values } as TNativeEnum<T>\n}\n"],"names":["Kind","TypeRegistry","NativeEnumKind","NativeEnum","value","options","values","Object","NativeEnumCheck","schema","enum","includes","Has","Set"],"mappings":"AAAA,SACEA,IAAI,EAGJC,YAAY,QACP,yBAAwB;AAE/B,OAAO,MAAMC,iBAAiB,aAAY;AAO1C,OAAO,SAASC,WACdC,KAAQ,EACRC,UAAyB,CAAC,CAAC;IAE3B,MAAMC,SAASC,OAAOD,MAAM,CAACF;IAE7B,SAASI,gBAAgBC,MAAsB,EAAEL,KAAc;QAC7D,OAAO,OAAOA,UAAU,YAAYK,OAAOC,IAAI,CAACC,QAAQ,CAACP;IAC3D;IAEA,IAAI,CAACH,aAAaW,GAAG,CAACV,iBACpBD,aAAaY,GAAG,CAACX,gBAAgBM;IAEnC,OAAO;QAAE,GAAGH,OAAO;QAAE,CAACL,KAAK,EAAEE;QAAgBQ,MAAMJ;IAAO;AAC5D"}
|
package/dist/types/enum.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { NativeEnum } from "../schemas/native-enum.js";
|
|
2
2
|
import { UnionEnum } from "../schemas/union-enum.js";
|
|
3
3
|
import { BaseType } from "./base.js";
|
|
4
|
-
export class
|
|
4
|
+
export class ObjectEnumType extends BaseType {
|
|
5
5
|
values;
|
|
6
6
|
constructor(values, options = {}, isNullable = false, isOptional = false, hasDefault = false){
|
|
7
7
|
super(options, isNullable, isOptional, hasDefault);
|
|
@@ -11,23 +11,23 @@ export class NativeEnumType extends BaseType {
|
|
|
11
11
|
return NativeEnum(this.values, options);
|
|
12
12
|
}
|
|
13
13
|
nullable() {
|
|
14
|
-
return new
|
|
14
|
+
return new ObjectEnumType(this.values, ...this._with({
|
|
15
15
|
isNullable: true
|
|
16
16
|
}));
|
|
17
17
|
}
|
|
18
18
|
optional() {
|
|
19
|
-
return new
|
|
19
|
+
return new ObjectEnumType(this.values, ...this._with({
|
|
20
20
|
isOptional: true
|
|
21
21
|
}));
|
|
22
22
|
}
|
|
23
23
|
nullish() {
|
|
24
|
-
return new
|
|
24
|
+
return new ObjectEnumType(this.values, ...this._with({
|
|
25
25
|
isNullable: true,
|
|
26
26
|
isOptional: true
|
|
27
27
|
}));
|
|
28
28
|
}
|
|
29
29
|
default(value) {
|
|
30
|
-
return new
|
|
30
|
+
return new ObjectEnumType(this.values, ...this._with({
|
|
31
31
|
options: {
|
|
32
32
|
default: value
|
|
33
33
|
},
|
|
@@ -35,14 +35,14 @@ export class NativeEnumType extends BaseType {
|
|
|
35
35
|
}));
|
|
36
36
|
}
|
|
37
37
|
description(description) {
|
|
38
|
-
return new
|
|
38
|
+
return new ObjectEnumType(this.values, ...this._with({
|
|
39
39
|
options: {
|
|
40
40
|
description
|
|
41
41
|
}
|
|
42
42
|
}));
|
|
43
43
|
}
|
|
44
44
|
examples(...examples) {
|
|
45
|
-
return new
|
|
45
|
+
return new ObjectEnumType(this.values, ...this._with({
|
|
46
46
|
options: {
|
|
47
47
|
examples
|
|
48
48
|
}
|
package/dist/types/enum.js.map
CHANGED
|
@@ -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
|
|
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,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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AO,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"}
|
package/dist/types/object.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/types/object.ts"],"sourcesContent":["import {\n type ObjectOptions,\n type TObject,\n type TRecord,\n Type,\n} from '@sinclair/typebox'\nimport type { typeStatic } from '../constants.ts'\nimport type { UnionToTupleString } from '../utils.ts'\nimport { BaseType, getTypeSchema } from './base.ts'\nimport { type AnyEnumType, type AnyNativeEnumType, EnumType } from './enum.ts'\nimport type { AnyLiteralType } from './literal.ts'\nimport type { AnyStringType } from './string.ts'\nimport type { AnyUnionType } from './union.ts'\n\nexport class ObjectType<\n T extends Record<string, BaseType>,\n N extends boolean = false,\n O extends boolean = false,\n D extends boolean = false,\n> extends BaseType<\n TObject<{ [K in keyof T]: T[K][typeStatic]['schema'] }>,\n N,\n O,\n D\n> {\n constructor(\n protected readonly properties: T = {} as T,\n options: ObjectOptions = {},\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, properties)\n }\n\n protected _constructSchema(\n options: ObjectOptions,\n properties: T,\n ): TObject<{ [K in keyof T]: T[K][typeStatic]['schema'] }> {\n const schemaProperties = {} as {\n [K in keyof T]: T[K][typeStatic]['schema']\n }\n\n for (const [key, value] of Object.entries(properties)) {\n // @ts-expect-error\n schemaProperties[key] = getTypeSchema(value)\n }\n return Type.Object(schemaProperties, options)\n }\n\n nullable() {\n return new ObjectType(this.properties, ...this._with({ isNullable: true }))\n }\n\n optional() {\n return new ObjectType(this.properties, ...this._with({ isOptional: true }))\n }\n\n nullish() {\n return new ObjectType(\n this.properties,\n ...this._with({ isNullable: true, isOptional: true }),\n )\n }\n\n default(value: this[typeStatic]['encoded']) {\n return new ObjectType(\n this.properties,\n ...this._with({ options: { default: value }, hasDefault: true }),\n )\n }\n\n description(description: string) {\n return new ObjectType(\n this.properties,\n ...this._with({ options: { description } }),\n )\n }\n\n examples(\n ...examples: [this[typeStatic]['encoded'], ...this[typeStatic]['encoded'][]]\n ) {\n return new ObjectType(\n this.properties,\n ...this._with({ options: { examples } }),\n )\n }\n\n pick<P extends { [K in keyof T]?: true }>(pick: P) {\n const properties = Object.fromEntries(\n Object.entries(this.properties).filter(([key]) => pick[key]),\n )\n const [_, ...args] = this._with()\n return new ObjectType(\n properties as Pick<T, Extract<keyof P, keyof T>>,\n {},\n ...args,\n )\n }\n\n omit<P extends { [K in keyof T]?: true }>(omit: P) {\n const properties = Object.fromEntries(\n Object.entries(this.properties).filter(([key]) => !omit[key]),\n )\n const [_, ...args] = this._with()\n return new ObjectType(\n properties as Omit<T, Extract<keyof P, keyof T>>,\n {},\n ...args,\n )\n }\n\n extend<P extends Record<string, BaseType>>(properties: P) {\n const [_, ...args] = this._with()\n return new ObjectType({ ...this.properties, ...properties }, {}, ...args)\n }\n\n merge<T extends ObjectType<Record<string, BaseType>>>(object: T) {\n const [_, ...args] = this._with()\n return new ObjectType(\n { ...this.properties, ...object.properties },\n {},\n ...args,\n )\n }\n\n partial() {\n const properties: { [K in keyof T]: ReturnType<T[K]['optional']> } =\n {} as any\n for (const [key, value] of Object.entries(this.properties)) {\n // @ts-expect-error\n properties[key] = value.optional()\n }\n const [_, ...args] = this._with()\n return new ObjectType(properties, {}, ...args)\n }\n\n keyof(): EnumType<UnionToTupleString<keyof T>> {\n return new EnumType(Object.keys(this.properties) as any)\n }\n}\n\nexport class RecordType<\n K extends\n | AnyLiteralType\n | AnyEnumType\n | AnyNativeEnumType\n | AnyStringType\n | AnyUnionType,\n E extends BaseType,\n N extends boolean = false,\n O extends boolean = false,\n D extends boolean = false,\n> extends BaseType<\n TRecord<K[typeStatic]['schema'], E[typeStatic]['schema']>,\n N,\n O,\n D,\n ObjectOptions\n> {\n constructor(\n protected readonly key: K,\n protected readonly element: E,\n options: ObjectOptions = {},\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, key, element)\n }\n\n protected _constructSchema(options: ObjectOptions, key: K, element: E) {\n return Type.Record(\n getTypeSchema(key),\n getTypeSchema(element),\n options,\n ) as TRecord<K[typeStatic]['schema'], E[typeStatic]['schema']>\n }\n\n nullable() {\n return new RecordType(\n this.key,\n this.element,\n ...this._with({ isNullable: true }),\n )\n }\n\n optional() {\n return new RecordType(\n this.key,\n this.element,\n ...this._with({ isOptional: true }),\n )\n }\n\n nullish() {\n return new RecordType(\n this.key,\n this.element,\n ...this._with({ isNullable: true, isOptional: true }),\n )\n }\n\n default(value: this[typeStatic]['encoded']) {\n return new RecordType(\n this.key,\n this.element,\n ...this._with({ options: { default: value }, hasDefault: true }),\n )\n }\n\n description(description: string) {\n return new RecordType(\n this.key,\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 RecordType(\n this.key,\n this.element,\n ...this._with({ options: { examples } }),\n )\n }\n}\n"],"names":["Type","BaseType","getTypeSchema","EnumType","ObjectType","constructor","properties","options","isNullable","isOptional","hasDefault","_constructSchema","schemaProperties","key","value","Object","entries","nullable","_with","optional","nullish","default","description","examples","pick","fromEntries","filter","_","args","omit","extend","merge","object","partial","keyof","keys","RecordType","element","Record"],"mappings":"AAAA,SAIEA,IAAI,QACC,oBAAmB;AAG1B,SAASC,QAAQ,EAAEC,aAAa,QAAQ,YAAW;AACnD,SAAmDC,QAAQ,QAAQ,YAAW;AAK9E,OAAO,MAAMC,mBAKHH;;IAMRI,YACE,AAAmBC,aAAgB,CAAC,CAAM,EAC1CC,UAAyB,CAAC,CAAC,EAC3BC,aAAgB,KAAU,EAC1BC,aAAgB,KAAU,EAC1BC,aAAgB,KAAU,CAC1B;QACA,KAAK,CAACH,SAASC,YAAYC,YAAYC,YAAYJ;aANhCA,aAAAA;IAOrB;IAEUK,iBACRJ,OAAsB,EACtBD,UAAa,EAC4C;QACzD,MAAMM,mBAAmB,CAAC;QAI1B,KAAK,MAAM,CAACC,KAAKC,MAAM,IAAIC,OAAOC,OAAO,CAACV,YAAa;YAErDM,gBAAgB,CAACC,IAAI,GAAGX,cAAcY;QACxC;QACA,OAAOd,KAAKe,MAAM,CAACH,kBAAkBL;IACvC;IAEAU,WAAW;QACT,OAAO,IAAIb,WAAW,IAAI,CAACE,UAAU,KAAK,IAAI,CAACY,KAAK,CAAC;YAAEV,YAAY;QAAK;IAC1E;IAEAW,WAAW;QACT,OAAO,IAAIf,WAAW,IAAI,CAACE,UAAU,KAAK,IAAI,CAACY,KAAK,CAAC;YAAET,YAAY;QAAK;IAC1E;IAEAW,UAAU;QACR,OAAO,IAAIhB,WACT,IAAI,CAACE,UAAU,KACZ,IAAI,CAACY,KAAK,CAAC;YAAEV,YAAY;YAAMC,YAAY;QAAK;IAEvD;IAEAY,QAAQP,KAAkC,EAAE;QAC1C,OAAO,IAAIV,WACT,IAAI,CAACE,UAAU,KACZ,IAAI,CAACY,KAAK,CAAC;YAAEX,SAAS;gBAAEc,SAASP;YAAM;YAAGJ,YAAY;QAAK;IAElE;IAEAY,YAAYA,WAAmB,EAAE;QAC/B,OAA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,EAAE;QAC1C,OAAO,IAAIsB,WACT,IAAI,CAACvB,GAAG,EACR,IAAI,CAACwB,OAAO,KACT,IAAI,CAACnB,KAAK,CAAC;YAAEX,SAAS;gBAAEc,SAASP;YAAM;YAAGJ,YAAY;QAAK;IAElE;IAEAY,YAAYA,WAAmB,EAAE;QAC/B,OAAO,IAAIc,WACT,IAAI,CAACvB,GAAG,EACR,IAAI,CAACwB,OAAO,KACT,IAAI,CAACnB,KAAK,CAAC;YAAEX,SAAS;gBAAEe;YAAY;QAAE;IAE7C;IAEAC,SACE,GAAGA,QAAyE,EAC5E;QACA,OAAO,IAAIa,WACT,IAAI,CAACvB,GAAG,EACR,IAAI,CAACwB,OAAO,KACT,IAAI,CAACnB,KAAK,CAAC;YAAEX,SAAS;gBAAEgB;YAAS;QAAE;IAE1C;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../src/types/object.ts"],"sourcesContent":["import {\n type ObjectOptions,\n type TObject,\n type TRecord,\n Type,\n} from '@sinclair/typebox'\nimport type { typeStatic } from '../constants.ts'\nimport type { UnionToTupleString } from '../utils.ts'\nimport { BaseType, getTypeSchema } from './base.ts'\nimport { type AnyEnumType, type AnyObjectEnumType, EnumType } from './enum.ts'\nimport type { AnyLiteralType } from './literal.ts'\nimport type { AnyStringType } from './string.ts'\nimport type { AnyUnionType } from './union.ts'\n\nexport class ObjectType<\n T extends Record<string, BaseType>,\n N extends boolean = false,\n O extends boolean = false,\n D extends boolean = false,\n> extends BaseType<\n TObject<{ [K in keyof T]: T[K][typeStatic]['schema'] }>,\n N,\n O,\n D\n> {\n constructor(\n protected readonly properties: T = {} as T,\n options: ObjectOptions = {},\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, properties)\n }\n\n protected _constructSchema(\n options: ObjectOptions,\n properties: T,\n ): TObject<{ [K in keyof T]: T[K][typeStatic]['schema'] }> {\n const schemaProperties = {} as {\n [K in keyof T]: T[K][typeStatic]['schema']\n }\n\n for (const [key, value] of Object.entries(properties)) {\n // @ts-expect-error\n schemaProperties[key] = getTypeSchema(value)\n }\n return Type.Object(schemaProperties, options)\n }\n\n nullable() {\n return new ObjectType(this.properties, ...this._with({ isNullable: true }))\n }\n\n optional() {\n return new ObjectType(this.properties, ...this._with({ isOptional: true }))\n }\n\n nullish() {\n return new ObjectType(\n this.properties,\n ...this._with({ isNullable: true, isOptional: true }),\n )\n }\n\n default(value: this[typeStatic]['encoded']) {\n return new ObjectType(\n this.properties,\n ...this._with({ options: { default: value }, hasDefault: true }),\n )\n }\n\n description(description: string) {\n return new ObjectType(\n this.properties,\n ...this._with({ options: { description } }),\n )\n }\n\n examples(\n ...examples: [this[typeStatic]['encoded'], ...this[typeStatic]['encoded'][]]\n ) {\n return new ObjectType(\n this.properties,\n ...this._with({ options: { examples } }),\n )\n }\n\n pick<P extends { [K in keyof T]?: true }>(pick: P) {\n const properties = Object.fromEntries(\n Object.entries(this.properties).filter(([key]) => pick[key]),\n )\n const [_, ...args] = this._with()\n return new ObjectType(\n properties as Pick<T, Extract<keyof P, keyof T>>,\n {},\n ...args,\n )\n }\n\n omit<P extends { [K in keyof T]?: true }>(omit: P) {\n const properties = Object.fromEntries(\n Object.entries(this.properties).filter(([key]) => !omit[key]),\n )\n const [_, ...args] = this._with()\n return new ObjectType(\n properties as Omit<T, Extract<keyof P, keyof T>>,\n {},\n ...args,\n )\n }\n\n extend<P extends Record<string, BaseType>>(properties: P) {\n const [_, ...args] = this._with()\n return new ObjectType({ ...this.properties, ...properties }, {}, ...args)\n }\n\n merge<T extends ObjectType<Record<string, BaseType>>>(object: T) {\n const [_, ...args] = this._with()\n return new ObjectType(\n { ...this.properties, ...object.properties },\n {},\n ...args,\n )\n }\n\n partial() {\n const properties: { [K in keyof T]: ReturnType<T[K]['optional']> } =\n {} as any\n for (const [key, value] of Object.entries(this.properties)) {\n // @ts-expect-error\n properties[key] = value.optional()\n }\n const [_, ...args] = this._with()\n return new ObjectType(properties, {}, ...args)\n }\n\n keyof(): EnumType<UnionToTupleString<keyof T>> {\n return new EnumType(Object.keys(this.properties) as any)\n }\n}\n\nexport class RecordType<\n K extends\n | AnyLiteralType\n | AnyEnumType\n | AnyObjectEnumType\n | AnyStringType\n | AnyUnionType,\n E extends BaseType,\n N extends boolean = false,\n O extends boolean = false,\n D extends boolean = false,\n> extends BaseType<\n TRecord<K[typeStatic]['schema'], E[typeStatic]['schema']>,\n N,\n O,\n D,\n ObjectOptions\n> {\n constructor(\n protected readonly key: K,\n protected readonly element: E,\n options: ObjectOptions = {},\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, key, element)\n }\n\n protected _constructSchema(options: ObjectOptions, key: K, element: E) {\n return Type.Record(\n getTypeSchema(key),\n getTypeSchema(element),\n options,\n ) as TRecord<K[typeStatic]['schema'], E[typeStatic]['schema']>\n }\n\n nullable() {\n return new RecordType(\n this.key,\n this.element,\n ...this._with({ isNullable: true }),\n )\n }\n\n optional() {\n return new RecordType(\n this.key,\n this.element,\n ...this._with({ isOptional: true }),\n )\n }\n\n nullish() {\n return new RecordType(\n this.key,\n this.element,\n ...this._with({ isNullable: true, isOptional: true }),\n )\n }\n\n default(value: this[typeStatic]['encoded']) {\n return new RecordType(\n this.key,\n this.element,\n ...this._with({ options: { default: value }, hasDefault: true }),\n )\n }\n\n description(description: string) {\n return new RecordType(\n this.key,\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 RecordType(\n this.key,\n this.element,\n ...this._with({ options: { examples } }),\n )\n }\n}\n"],"names":["Type","BaseType","getTypeSchema","EnumType","ObjectType","constructor","properties","options","isNullable","isOptional","hasDefault","_constructSchema","schemaProperties","key","value","Object","entries","nullable","_with","optional","nullish","default","description","examples","pick","fromEntries","filter","_","args","omit","extend","merge","object","partial","keyof","keys","RecordType","element","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I,CAACnB,KAAK,CAAC;YAAEX,SAAS;gBAAEc,SAASP;YAAM;YAAGJ,YAAY;QAAK;IAElE;IAEAY,YAAYA,WAAmB,EAAE;QAC/B,OAAO,IAAIc,WACT,IAAI,CAACvB,GAAG,EACR,IAAI,CAACwB,OAAO,KACT,IAAI,CAACnB,KAAK,CAAC;YAAEX,SAAS;gBAAEe;YAAY;QAAE;IAE7C;IAEAC,SACE,GAAGA,QAAyE,EAC5E;QACA,OAAO,IAAIa,WACT,IAAI,CAACvB,GAAG,EACR,IAAI,CAACwB,OAAO,KACT,IAAI,CAACnB,KAAK,CAAC;YAAEX,SAAS;gBAAEgB;YAAS;QAAE;IAE1C;AACF"}
|
package/package.json
CHANGED
|
@@ -21,12 +21,12 @@
|
|
|
21
21
|
"peerDependencies": {
|
|
22
22
|
"@sinclair/typebox": "^0.33.7",
|
|
23
23
|
"temporal-polyfill": "^0.2.5",
|
|
24
|
-
"@nmtjs/common": "0.3.
|
|
24
|
+
"@nmtjs/common": "0.3.6"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@sinclair/typebox": "^0.33.7",
|
|
28
28
|
"temporal-polyfill": "^0.2.5",
|
|
29
|
-
"@nmtjs/common": "0.3.
|
|
29
|
+
"@nmtjs/common": "0.3.6"
|
|
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.
|
|
38
|
+
"version": "0.3.6",
|
|
39
39
|
"scripts": {
|
|
40
40
|
"build": "neemata-build -p neutral --root=./src './**/*.ts'",
|
|
41
41
|
"type-check": "tsc --noEmit"
|
package/src/index.ts
CHANGED
|
@@ -6,9 +6,9 @@ import { CustomType } from './types/custom.ts'
|
|
|
6
6
|
import { DateType } from './types/datetime.ts'
|
|
7
7
|
import {
|
|
8
8
|
type AnyEnumType,
|
|
9
|
-
type
|
|
9
|
+
type AnyObjectEnumType,
|
|
10
10
|
EnumType,
|
|
11
|
-
|
|
11
|
+
ObjectEnumType,
|
|
12
12
|
} from './types/enum.ts'
|
|
13
13
|
import { type AnyLiteralType, LiteralType } from './types/literal.ts'
|
|
14
14
|
import { BigIntType, IntegerType, NumberType } from './types/number.ts'
|
|
@@ -66,8 +66,8 @@ export namespace t {
|
|
|
66
66
|
export const bitint = () => new BigIntType()
|
|
67
67
|
export const literal = <T extends TLiteralValue>(value: T) =>
|
|
68
68
|
new LiteralType(value)
|
|
69
|
-
export const
|
|
70
|
-
new
|
|
69
|
+
export const objectEnum = <T extends { [K in string]: K }>(enumLike: T) =>
|
|
70
|
+
new ObjectEnumType(enumLike)
|
|
71
71
|
export const arrayEnum = <T extends (string | number)[]>(enumLike: [...T]) =>
|
|
72
72
|
new EnumType(enumLike)
|
|
73
73
|
export const date = () => new DateType()
|
|
@@ -79,7 +79,7 @@ export namespace t {
|
|
|
79
79
|
K extends
|
|
80
80
|
| AnyLiteralType
|
|
81
81
|
| AnyEnumType
|
|
82
|
-
|
|
|
82
|
+
| AnyObjectEnumType
|
|
83
83
|
| AnyStringType
|
|
84
84
|
| AnyUnionType,
|
|
85
85
|
E extends BaseType,
|
package/src/types/enum.ts
CHANGED
|
@@ -4,9 +4,9 @@ import { NativeEnum } from '../schemas/native-enum.ts'
|
|
|
4
4
|
import { type TUnionEnum, UnionEnum } from '../schemas/union-enum.ts'
|
|
5
5
|
import { BaseType } from './base.ts'
|
|
6
6
|
|
|
7
|
-
export type
|
|
8
|
-
|
|
9
|
-
export class
|
|
7
|
+
export type AnyObjectEnumType<T extends { [K in string]: K } = any> =
|
|
8
|
+
ObjectEnumType<T, boolean, boolean, boolean>
|
|
9
|
+
export class ObjectEnumType<
|
|
10
10
|
T extends { [K in string]: K },
|
|
11
11
|
N extends boolean = false,
|
|
12
12
|
O extends boolean = false,
|
|
@@ -27,36 +27,36 @@ export class NativeEnumType<
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
nullable() {
|
|
30
|
-
return new
|
|
30
|
+
return new ObjectEnumType(this.values, ...this._with({ isNullable: true }))
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
optional() {
|
|
34
|
-
return new
|
|
34
|
+
return new ObjectEnumType(this.values, ...this._with({ isOptional: true }))
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
nullish() {
|
|
38
|
-
return new
|
|
38
|
+
return new ObjectEnumType(
|
|
39
39
|
this.values,
|
|
40
40
|
...this._with({ isNullable: true, isOptional: true }),
|
|
41
41
|
)
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
default(value: keyof T) {
|
|
45
|
-
return new
|
|
45
|
+
return new ObjectEnumType(
|
|
46
46
|
this.values,
|
|
47
47
|
...this._with({ options: { default: value }, hasDefault: true }),
|
|
48
48
|
)
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
description(description: string) {
|
|
52
|
-
return new
|
|
52
|
+
return new ObjectEnumType(
|
|
53
53
|
this.values,
|
|
54
54
|
...this._with({ options: { description } }),
|
|
55
55
|
)
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
examples(...examples: (keyof T)[]) {
|
|
59
|
-
return new
|
|
59
|
+
return new ObjectEnumType(
|
|
60
60
|
this.values,
|
|
61
61
|
...this._with({ options: { examples } }),
|
|
62
62
|
)
|
package/src/types/object.ts
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
import type { typeStatic } from '../constants.ts'
|
|
8
8
|
import type { UnionToTupleString } from '../utils.ts'
|
|
9
9
|
import { BaseType, getTypeSchema } from './base.ts'
|
|
10
|
-
import { type AnyEnumType, type
|
|
10
|
+
import { type AnyEnumType, type AnyObjectEnumType, EnumType } from './enum.ts'
|
|
11
11
|
import type { AnyLiteralType } from './literal.ts'
|
|
12
12
|
import type { AnyStringType } from './string.ts'
|
|
13
13
|
import type { AnyUnionType } from './union.ts'
|
|
@@ -144,7 +144,7 @@ export class RecordType<
|
|
|
144
144
|
K extends
|
|
145
145
|
| AnyLiteralType
|
|
146
146
|
| AnyEnumType
|
|
147
|
-
|
|
|
147
|
+
| AnyObjectEnumType
|
|
148
148
|
| AnyStringType
|
|
149
149
|
| AnyUnionType,
|
|
150
150
|
E extends BaseType,
|