@nmtjs/type 0.7.1 → 0.7.3

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.map CHANGED
@@ -1 +1 @@
1
- {"mappings":"AAAA,YAAY,SAAS,WAAW;AAChC,SAAS,eAAe,gBAAgB;AACxC,SAAS,iBAAiB,kBAAkB;AAE5C,SAAS,mBAAmB,oBAAoB;AAChD,SAAS,kBAAkB,mBAAmB;AAC9C,SAAS,gBAAgB,iBAAiB;AAC1C,SAAS,gBAAgB,iBAAiB;AAC1C,SAAS,mBAAmB,oBAAoB;AAChD,SAAS,iBAAiB,kBAAkB;AAC5C,SAAS,YAAY,aAAa,kBAAkB,mBAAmB;AACvE,SACE,QACA,OACA,OACA,YACA,MACA,SACA,MACA,kBACK,mBAAmB;AAC1B,SAAS,kBAAkB,mBAAmB;AAC9C,SACE,wBACA,kBACA,iBACK,kBAAkB;AAEzB,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC;AAEjC,SAAS,wBAAwB;AACjC,SAAS,gBAAkC;AAC3C,SACE,WACA,aACA,YACA,UACA,UACA,aACA,aACA,YACA,YACA,YACA,kBACA,WACA,SACA,WACA,wBACA;;AAGK;CAiBE,MAAM,sBAAQ,UAAU;CACxB,MAAM,0BAAU,YAAY;CAC5B,MAAM,wBAAS,WAAW;CAC1B,MAAM,wBAAS,WAAW;CAC1B,MAAM,0BAAU,YAAY;CAC5B,MAAM,wBAAS,WAAW;CAC1B,MAAM,0BAAU,YAAY;CAC5B,MAAM,kCAAc,SAAS;CAC7B,MAAM,oBAAO,SAAS;CACtB,MAAM,sBAAQ,UAAU;CACxB,MAAM,wBAAS,WAAW;CAC1B,MAAM,kBAAM,QAAQ;CACpB,MAAM,gBAAK,UAAU;CACrB,MAAM,kBAAM,iBAAiB;CAC7B,MAAM,sBAAQ,UAAU;CACxB,MAAM,oCAAe,iBAAiB;CACtC,MAAM,gDAAqB,uBAAuB;CAClD,MAAM,wBAAS,WAAW;CAC1B,MAAM,wBAAS,OAAO,OAAO,WAAW,QAAQ,KAAK,WAAW,EAAE;EACvE;EACA;EACA;EACA;EACA;EACA;CACD,EAAC;;AAGJ,SAAS,QAAQ,GAAG","names":[],"sources":["src/index.ts"],"sourcesContent":["import * as zod from '@zod/mini'\nimport { AnyType } from './types/any.ts'\nimport { ArrayType } from './types/array.ts'\nimport type { BaseTypeAny } from './types/base.ts'\nimport { BooleanType } from './types/boolean.ts'\nimport { CustomType } from './types/custom.ts'\nimport { DateType } from './types/date.ts'\nimport { EnumType } from './types/enum.ts'\nimport { LiteralType } from './types/literal.ts'\nimport { NeverType } from './types/never.ts'\nimport { BigIntType, IntegerType, NumberType } from './types/number.ts'\nimport {\n extend,\n keyof,\n merge,\n ObjectType,\n omit,\n partial,\n pick,\n RecordType,\n} from './types/object.ts'\nimport { StringType } from './types/string.ts'\nimport {\n DiscriminatedUnionType,\n IntersactionType,\n UnionType,\n} from './types/union.ts'\n\nzod.config(zod.core.locales.en())\n\nexport { NeemataTypeError } from './types/base.ts'\nexport { BaseType, type BaseTypeAny } from './types/base.ts'\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 DiscriminatedUnionType,\n RecordType,\n}\n\nexport namespace type {\n export namespace infer {\n export type decoded<T extends BaseTypeAny> =\n T['decodedZodType']['_zod']['output']\n\n export type encoded<T extends BaseTypeAny> =\n T['encodedZodType']['_zod']['output']\n\n export namespace input {\n export type decoded<T extends BaseTypeAny> =\n T['decodedZodType']['_zod']['input']\n\n export type encoded<T extends BaseTypeAny> =\n T['encodedZodType']['_zod']['input']\n }\n }\n\n export const never = NeverType.factory\n export const boolean = BooleanType.factory\n export const string = StringType.factory\n export const number = NumberType.factory\n export const integer = IntegerType.factory\n export const bitint = BigIntType.factory\n export const literal = LiteralType.factory\n export const enumeration = EnumType.factory\n export const date = DateType.factory\n export const array = ArrayType.factory\n export const record = RecordType.factory\n export const any = AnyType.factory\n export const or = UnionType.factory\n export const and = IntersactionType.factory\n export const union = UnionType.factory\n export const intersaction = IntersactionType.factory\n export const discriminatedUnion = DiscriminatedUnionType.factory\n export const custom = CustomType.factory\n export const object = Object.assign(ObjectType.factory.bind(ObjectType), {\n keyof,\n partial,\n merge,\n omit,\n extend,\n pick,\n })\n}\n\nexport { type as t, zod }\n"],"version":3}
1
+ {"mappings":"AAAA,YAAY,SAAS,WAAW;AAChC,SAAS,eAAe,gBAAgB;AACxC,SAAS,iBAAiB,kBAAkB;AAE5C,SAAS,mBAAmB,oBAAoB;AAChD,SAAS,kBAAkB,mBAAmB;AAC9C,SAAS,gBAAgB,iBAAiB;AAC1C,SAAS,gBAAgB,iBAAiB;AAC1C,SAAS,mBAAmB,oBAAoB;AAChD,SAAS,iBAAiB,kBAAkB;AAC5C,SAAS,YAAY,aAAa,kBAAkB,mBAAmB;AACvE,SACE,QACA,OACA,OACA,YACA,MACA,SACA,MACA,kBACK,mBAAmB;AAC1B,SAAS,kBAAkB,mBAAmB;AAC9C,SACE,wBACA,kBACA,iBACK,kBAAkB;AAEzB,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC;AAEjC,SAAS,wBAAwB;AACjC,SAAS,gBAAkC;AAC3C,SACE,WACA,aACA,YACA,UACA,UACA,aACA,aACA,YACA,YACA,YACA,kBACA,WACA,SACA,WACA,wBACA;;AAGK;CAiBE,MAAM,sBAAQ,UAAU;CACxB,MAAM,0BAAU,YAAY;CAC5B,MAAM,wBAAS,WAAW;CAC1B,MAAM,wBAAS,WAAW;CAC1B,MAAM,0BAAU,YAAY;CAC5B,MAAM,wBAAS,WAAW;CAC1B,MAAM,0BAAU,YAAY;CAC5B,MAAM,kCAAc,SAAS;CAC7B,MAAM,oBAAO,SAAS;CACtB,MAAM,sBAAQ,UAAU;CACxB,MAAM,wBAAS,WAAW;CAC1B,MAAM,kBAAM,QAAQ;CACpB,MAAM,gBAAK,UAAU;CACrB,MAAM,kBAAM,iBAAiB;CAC7B,MAAM,sBAAQ,UAAU;CACxB,MAAM,oCAAe,iBAAiB;CACtC,MAAM,gDAAqB,uBAAuB;CAClD,MAAM,wBAAS,WAAW;CAC1B,MAAM,wBAAS,OAAO,OAAO,WAAW,QAAQ,KAAK,WAAW,EAAE;EACvE;EACA;EACA;EACA;EACA;EACA;CACD,EAAC;;AAGJ,SAAS,QAAQ,GAAG","names":[],"sources":["src/index.ts"],"sourcesContent":["import * as zod from '@zod/mini'\nimport { AnyType } from './types/any.ts'\nimport { ArrayType } from './types/array.ts'\nimport type { BaseTypeAny } from './types/base.ts'\nimport { BooleanType } from './types/boolean.ts'\nimport { CustomType } from './types/custom.ts'\nimport { DateType } from './types/date.ts'\nimport { EnumType } from './types/enum.ts'\nimport { LiteralType } from './types/literal.ts'\nimport { NeverType } from './types/never.ts'\nimport { BigIntType, IntegerType, NumberType } from './types/number.ts'\nimport {\n extend,\n keyof,\n merge,\n ObjectType,\n omit,\n partial,\n pick,\n RecordType,\n} from './types/object.ts'\nimport { StringType } from './types/string.ts'\nimport {\n DiscriminatedUnionType,\n IntersactionType,\n UnionType,\n} from './types/union.ts'\n\nzod.config(zod.core.locales.en())\n\nexport { NeemataTypeError } from './types/base.ts'\nexport { BaseType, type BaseTypeAny } from './types/base.ts'\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 DiscriminatedUnionType,\n RecordType,\n}\n\nexport namespace type {\n export namespace infer {\n export namespace decoded {\n export type input<T extends BaseTypeAny> =\n T['decodedZodType']['_zod']['input']\n export type output<T extends BaseTypeAny> =\n T['decodedZodType']['_zod']['output']\n }\n\n export namespace encoded {\n export type input<T extends BaseTypeAny> =\n T['encodedZodType']['_zod']['input']\n export type output<T extends BaseTypeAny> =\n T['encodedZodType']['_zod']['output']\n }\n }\n\n export const never = NeverType.factory\n export const boolean = BooleanType.factory\n export const string = StringType.factory\n export const number = NumberType.factory\n export const integer = IntegerType.factory\n export const bitint = BigIntType.factory\n export const literal = LiteralType.factory\n export const enumeration = EnumType.factory\n export const date = DateType.factory\n export const array = ArrayType.factory\n export const record = RecordType.factory\n export const any = AnyType.factory\n export const or = UnionType.factory\n export const and = IntersactionType.factory\n export const union = UnionType.factory\n export const intersaction = IntersactionType.factory\n export const discriminatedUnion = DiscriminatedUnionType.factory\n export const custom = CustomType.factory\n export const object = Object.assign(ObjectType.factory.bind(ObjectType), {\n keyof,\n partial,\n merge,\n omit,\n extend,\n pick,\n })\n}\n\nexport { type as t, zod }\n"],"version":3}
@@ -1 +1 @@
1
- {"mappings":"AAAA,SACE,UACA,MACA,UACA,UACA,gBAmBK,WAAW;AAkDlB,OAAO,MAAM,gBAAgB,UAAwB;AAErD,OAAO,MAAM,mBAAmB,KAAK;AAGrC,OAAO,MAAe,SAIpB;CACA,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS;CAET,YAAY,EACV,gBACA,iBAAiB,gBACjB,QAAQ,CAAE,GACV,SAAS,CAAE,GAMZ,EAAE;AACD,OAAK,iBAAiB;AACtB,OAAK,iBAAiB;AAEtB,OAAK,QAAQ;AACb,OAAK,SAAS,OAAO,OAAO,EAAE,QAAQ,CAAE,EAAE,GAAE,OAAO;CACpD;CAED,WAA+B;AAC7B,SAAO,aAAa,QAAQ,KAAK;CAClC;CAED,WAA+B;AAC7B,SAAO,aAAa,QAAQ,KAAK;CAClC;CAED,UAAU;AACR,SAAO,KAAK,UAAU,CAAC,UAAU;CAClC;CAED,QAAQA,OAAmE;AACzE,SAAO,YAAY,QAAQ,MAAM,MAAM;CACxC;CAED,MAAMC,OAAqB;AACzB,SAAO,KAAK,KAAK,EAAE,MAAO,EAAC;CAC5B;CAED,YAAYC,aAA2B;AACrC,SAAO,KAAK,KAAK,EAAE,YAAa,EAAC;CAClC;CAED,SAAS,GAAG,UAA2D;AACrE,SAAO,KAAK,KAAK,EACf,UAAU,KAAK,OAAO,SAClB,SAAS,IAAI,KAAK,OAAO,OAAO,GAChC,SACL,EAAC;CACH;CAED,KAAKC,aAAiC;EACpC,MAAM,WAAW,cAAc,IAAI,KAAK,eAAe,IAAI,CAAE;AAC7D,SAAO,OAAO,UAAU,YAAY;AACpC,gBAAc,IAAI,KAAK,gBAAgB,SAAS;AAChD,SAAO;CACR;CAED,OACEC,MAC0C;AAC1C,SAAO,KAAK,eAAe,MAAM,MAAM,EAAE,aAAa,KAAM,EAAC;CAC9D;CAED,OACEC,MAC0C;AAC1C,SAAO,KAAK,eAAe,MAAM,MAAM,EAAE,aAAa,KAAM,EAAC;CAC9D;AACF;AAED,OAAO,MAAM,qBAEH,SAIR;CACA,OAAO,QAA+BC,MAAS;AAC7C,SAAO,IAAI,aAAgB;GACzB,gBAAgB,SAAS,KAAK,eAAe;GAC7C,OAAO,EAAE,OAAO,KAAM;EACvB;CACF;AACF;AAED,OAAO,MAAM,qBAEH,SAIR;CACA,OAAO,QAAoCA,MAAS;AAClD,SAAO,IAAI,aAAgB;GACzB,gBAAgB,SAAS,KAAK,eAAe;GAC7C,OAAO,EAAE,OAAO,KAAM;EACvB;CACF;AACF;AAED,OAAO,MAAM,oBAEH,SAIR;CACA,OAAO,QAAoCA,MAASC,cAAmB;AACrE,SAAO,IAAI,YAAe;GACxB,gBAAgB,SACd,KAAK,gBACL,KAAK,OAAO,SAAS,aAAa,IAAI,aACvC;GACD,gBAAgB,SAAS,KAAK,gBAAgB,aAAa;GAC3D,OAAO,EAAE,OAAO,KAAM;EACvB;CACF;AACF","names":["value: this['encodedZodType']['_zod']['input']","title: string","description: string","newMetadata: TypeMetadata","data: this['encodedZodType']['_zod']['input']","data: this['decodedZodType']['_zod']['input']","type: T","defaultValue: any"],"sources":["src/types/base.ts"],"sourcesContent":["import {\n _default,\n core,\n nullable,\n optional,\n registry,\n type ZodMiniAny,\n type ZodMiniArray,\n type ZodMiniBoolean,\n type ZodMiniDefault,\n type ZodMiniEnum,\n type ZodMiniInterface,\n type ZodMiniIntersection,\n type ZodMiniLiteral,\n type ZodMiniNever,\n type ZodMiniNullable,\n type ZodMiniNumber,\n type ZodMiniObject,\n type ZodMiniOptional,\n type ZodMiniPipe,\n type ZodMiniRecord,\n type ZodMiniString,\n type ZodMiniType,\n type ZodMiniUnion,\n} from '@zod/mini'\n\nexport type PrimitiveValueType = string | number | boolean | null\n\nexport type SimpleZodType =\n | ZodMiniNever\n | ZodMiniDefault\n | ZodMiniNullable\n | ZodMiniOptional\n | ZodMiniString\n | ZodMiniObject\n | ZodMiniAny\n | ZodMiniArray\n | ZodMiniBoolean\n | ZodMiniNumber\n | ZodMiniEnum<any>\n | ZodMiniLiteral<PrimitiveValueType>\n | ZodMiniUnion\n | ZodMiniIntersection\n | ZodMiniInterface\n | ZodMiniRecord\n | ZodMiniPipe\n\nexport type ZodType = SimpleZodType | ZodMiniType\n\nexport type TypeProps = Record<string, any>\n\nexport type TypeMetadata<T = any> = {\n id?: string\n description?: string\n examples?: T[]\n title?: string\n}\n\nexport type TypeParams = {\n encode?: (value: any) => any\n metadata?: TypeMetadata\n checks: Array<core.CheckFn<any> | core.$ZodCheck<any>>\n}\n\nexport type DefaultTypeParams = {\n encode?: TypeParams['encode']\n metadata?: TypeMetadata\n}\n\nexport type BaseTypeAny<\n EncodedZodType extends SimpleZodType = SimpleZodType,\n DecodedZodType extends ZodType = ZodMiniType,\n> = BaseType<EncodedZodType, DecodedZodType, TypeProps>\n\nexport const typesRegistry = registry<TypeMetadata>()\n\nexport const NeemataTypeError = core.$ZodError\nexport type NeemataTypeError = core.$ZodError\n\nexport abstract class BaseType<\n EncodedZodType extends SimpleZodType = SimpleZodType,\n DecodedZodType extends ZodType = EncodedZodType,\n Props extends TypeProps = TypeProps,\n> {\n readonly encodedZodType: EncodedZodType\n readonly decodedZodType: DecodedZodType\n readonly props: Props\n readonly params: TypeParams\n\n constructor({\n encodedZodType,\n decodedZodType = encodedZodType as unknown as DecodedZodType,\n props = {} as Props,\n params = {} as Partial<TypeParams>,\n }: {\n encodedZodType: EncodedZodType\n decodedZodType?: DecodedZodType\n props?: Props\n params?: Partial<TypeParams>\n }) {\n this.encodedZodType = encodedZodType\n this.decodedZodType = decodedZodType\n\n this.props = props\n this.params = Object.assign({ checks: [] }, params)\n }\n\n optional(): OptionalType<this> {\n return OptionalType.factory(this)\n }\n\n nullable(): NullableType<this> {\n return NullableType.factory(this)\n }\n\n nullish() {\n return this.nullable().optional()\n }\n\n default(value: this['encodedZodType']['_zod']['input']): DefaultType<this> {\n return DefaultType.factory(this, value)\n }\n\n title(title: string): this {\n return this.meta({ title })\n }\n\n description(description: string): this {\n return this.meta({ description })\n }\n\n examples(...examples: this['decodedZodType']['_zod']['input'][]): this {\n return this.meta({\n examples: this.params.encode\n ? examples.map(this.params.encode)\n : examples,\n })\n }\n\n meta(newMetadata: TypeMetadata): this {\n const metadata = typesRegistry.get(this.encodedZodType) ?? {}\n Object.assign(metadata, newMetadata)\n typesRegistry.add(this.encodedZodType, metadata)\n return this\n }\n\n encode(\n data: this['encodedZodType']['_zod']['input'],\n ): this['encodedZodType']['_zod']['output'] {\n return this.encodedZodType.parse(data, { reportInput: true })\n }\n\n decode(\n data: this['decodedZodType']['_zod']['input'],\n ): this['decodedZodType']['_zod']['output'] {\n return this.decodedZodType.parse(data, { reportInput: true })\n }\n}\n\nexport class OptionalType<\n Type extends BaseTypeAny = BaseTypeAny,\n> extends BaseType<\n ZodMiniOptional<Type['encodedZodType']>,\n ZodMiniOptional<Type['decodedZodType']>,\n { inner: Type }\n> {\n static factory<T extends BaseTypeAny>(type: T) {\n return new OptionalType<T>({\n encodedZodType: optional(type.encodedZodType) as any,\n props: { inner: type },\n })\n }\n}\n\nexport class NullableType<\n Type extends BaseTypeAny<any> = BaseTypeAny<any>,\n> extends BaseType<\n ZodMiniNullable<Type['encodedZodType']>,\n ZodMiniNullable<Type['decodedZodType']>,\n { inner: Type }\n> {\n static factory<T extends BaseTypeAny<any>>(type: T) {\n return new NullableType<T>({\n encodedZodType: nullable(type.encodedZodType),\n props: { inner: type },\n })\n }\n}\n\nexport class DefaultType<\n Type extends BaseTypeAny = BaseTypeAny,\n> extends BaseType<\n ZodMiniDefault<Type['encodedZodType']>,\n ZodMiniDefault<Type['decodedZodType']>,\n { inner: Type }\n> {\n static factory<T extends BaseTypeAny<any>>(type: T, defaultValue: any) {\n return new DefaultType<T>({\n encodedZodType: _default(\n type.encodedZodType,\n type.params.encode?.(defaultValue) ?? defaultValue,\n ) as any,\n decodedZodType: _default(type.decodedZodType, defaultValue) as any,\n props: { inner: type },\n })\n }\n}\n"],"version":3}
1
+ {"mappings":"AAAA,SACE,UACA,MACA,UACA,UACA,gBAoBK,WAAW;AAmDlB,OAAO,MAAM,gBAAgB,UAAwB;AAErD,OAAO,MAAM,mBAAmB,KAAK;AAGrC,OAAO,MAAe,SAIpB;CACA,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS;CAET,YAAY,EACV,gBACA,iBAAiB,gBACjB,QAAQ,CAAE,GACV,SAAS,CAAE,GAMZ,EAAE;AACD,OAAK,iBAAiB;AACtB,OAAK,iBAAiB;AAEtB,OAAK,QAAQ;AACb,OAAK,SAAS,OAAO,OAAO,EAAE,QAAQ,CAAE,EAAE,GAAE,OAAO;CACpD;CAED,WAA+B;AAC7B,SAAO,aAAa,QAAQ,KAAK;CAClC;CAED,WAA+B;AAC7B,SAAO,aAAa,QAAQ,KAAK;CAClC;CAED,UAAU;AACR,SAAO,KAAK,UAAU,CAAC,UAAU;CAClC;CAED,QAAQA,OAAmE;AACzE,SAAO,YAAY,QAAQ,MAAM,MAAM;CACxC;CAED,MAAMC,OAAqB;AACzB,SAAO,KAAK,KAAK,EAAE,MAAO,EAAC;CAC5B;CAED,YAAYC,aAA2B;AACrC,SAAO,KAAK,KAAK,EAAE,YAAa,EAAC;CAClC;CAED,SAAS,GAAG,UAA2D;AACrE,SAAO,KAAK,KAAK,EACf,UAAU,KAAK,OAAO,SAClB,SAAS,IAAI,KAAK,OAAO,OAAO,GAChC,SACL,EAAC;CACH;CAED,KAAKC,aAAiC;EACpC,MAAM,WAAW,cAAc,IAAI,KAAK,eAAe,IAAI,CAAE;AAC7D,SAAO,OAAO,UAAU,YAAY;AACpC,gBAAc,IAAI,KAAK,gBAAgB,SAAS;AAChD,SAAO;CACR;CAED,OACEC,MAC0C;AAC1C,SAAO,KAAK,eAAe,MAAM,MAAM,EAAE,aAAa,KAAM,EAAC;CAC9D;CAED,OACEC,MAC0C;AAC1C,SAAO,KAAK,eAAe,MAAM,MAAM,EAAE,aAAa,KAAM,EAAC;CAC9D;AACF;AAED,OAAO,MAAM,qBAEH,SAIR;CACA,OAAO,QAA+BC,MAAS;AAC7C,SAAO,IAAI,aAAgB;GACzB,gBAAgB,SAAS,KAAK,eAAe;GAC7C,OAAO,EAAE,OAAO,KAAM;EACvB;CACF;AACF;AAED,OAAO,MAAM,qBAEH,SAIR;CACA,OAAO,QAAoCA,MAAS;AAClD,SAAO,IAAI,aAAgB;GACzB,gBAAgB,SAAS,KAAK,eAAe;GAC7C,OAAO,EAAE,OAAO,KAAM;EACvB;CACF;AACF;AAED,OAAO,MAAM,oBAEH,SAIR;CACA,OAAO,QAAoCA,MAASC,cAAmB;AACrE,SAAO,IAAI,YAAe;GACxB,gBAAgB,SACd,KAAK,gBACL,KAAK,OAAO,SAAS,aAAa,IAAI,aACvC;GACD,gBAAgB,SAAS,KAAK,gBAAgB,aAAa;GAC3D,OAAO,EAAE,OAAO,KAAM;EACvB;CACF;AACF","names":["value: this['encodedZodType']['_zod']['input']","title: string","description: string","newMetadata: TypeMetadata","data: this['encodedZodType']['_zod']['input']","data: this['decodedZodType']['_zod']['input']","type: T","defaultValue: any"],"sources":["src/types/base.ts"],"sourcesContent":["import {\n _default,\n core,\n nullable,\n optional,\n registry,\n type ZodMiniAny,\n type ZodMiniArray,\n type ZodMiniBoolean,\n type ZodMiniCustom,\n type ZodMiniDefault,\n type ZodMiniEnum,\n type ZodMiniInterface,\n type ZodMiniIntersection,\n type ZodMiniLiteral,\n type ZodMiniNever,\n type ZodMiniNullable,\n type ZodMiniNumber,\n type ZodMiniObject,\n type ZodMiniOptional,\n type ZodMiniPipe,\n type ZodMiniRecord,\n type ZodMiniString,\n type ZodMiniType,\n type ZodMiniUnion,\n} from '@zod/mini'\n\nexport type PrimitiveValueType = string | number | boolean | null\n\nexport type PrimitiveZodType =\n | ZodMiniNever\n | ZodMiniDefault\n | ZodMiniNullable\n | ZodMiniOptional\n | ZodMiniString\n | ZodMiniObject\n | ZodMiniAny\n | ZodMiniArray\n | ZodMiniBoolean\n | ZodMiniNumber\n | ZodMiniEnum<any>\n | ZodMiniLiteral<PrimitiveValueType>\n | ZodMiniUnion\n | ZodMiniIntersection\n | ZodMiniInterface\n | ZodMiniRecord\n\nexport type SimpleZodType = ZodMiniType\n\nexport type ZodType = SimpleZodType | ZodMiniType\n\nexport type TypeProps = Record<string, any>\n\nexport type TypeMetadata<T = any> = {\n id?: string\n description?: string\n examples?: T[]\n title?: string\n}\n\nexport type TypeParams = {\n encode?: (value: any) => any\n metadata?: TypeMetadata\n checks: Array<core.CheckFn<any> | core.$ZodCheck<any>>\n}\n\nexport type DefaultTypeParams = {\n encode?: TypeParams['encode']\n metadata?: TypeMetadata\n}\n\nexport type BaseTypeAny<\n EncodedZodType extends SimpleZodType = SimpleZodType,\n DecodedZodType extends ZodType = ZodMiniType,\n> = BaseType<EncodedZodType, DecodedZodType, TypeProps>\n\nexport const typesRegistry = registry<TypeMetadata>()\n\nexport const NeemataTypeError = core.$ZodError\nexport type NeemataTypeError = core.$ZodError\n\nexport abstract class BaseType<\n EncodedZodType extends SimpleZodType = SimpleZodType,\n DecodedZodType extends ZodType = EncodedZodType,\n Props extends TypeProps = TypeProps,\n> {\n readonly encodedZodType: EncodedZodType\n readonly decodedZodType: DecodedZodType\n readonly props: Props\n readonly params: TypeParams\n\n constructor({\n encodedZodType,\n decodedZodType = encodedZodType as unknown as DecodedZodType,\n props = {} as Props,\n params = {} as Partial<TypeParams>,\n }: {\n encodedZodType: EncodedZodType\n decodedZodType?: DecodedZodType\n props?: Props\n params?: Partial<TypeParams>\n }) {\n this.encodedZodType = encodedZodType\n this.decodedZodType = decodedZodType\n\n this.props = props\n this.params = Object.assign({ checks: [] }, params)\n }\n\n optional(): OptionalType<this> {\n return OptionalType.factory(this)\n }\n\n nullable(): NullableType<this> {\n return NullableType.factory(this)\n }\n\n nullish() {\n return this.nullable().optional()\n }\n\n default(value: this['encodedZodType']['_zod']['input']): DefaultType<this> {\n return DefaultType.factory(this, value)\n }\n\n title(title: string): this {\n return this.meta({ title })\n }\n\n description(description: string): this {\n return this.meta({ description })\n }\n\n examples(...examples: this['decodedZodType']['_zod']['input'][]): this {\n return this.meta({\n examples: this.params.encode\n ? examples.map(this.params.encode)\n : examples,\n })\n }\n\n meta(newMetadata: TypeMetadata): this {\n const metadata = typesRegistry.get(this.encodedZodType) ?? {}\n Object.assign(metadata, newMetadata)\n typesRegistry.add(this.encodedZodType, metadata)\n return this\n }\n\n encode(\n data: this['encodedZodType']['_zod']['input'],\n ): this['encodedZodType']['_zod']['output'] {\n return this.encodedZodType.parse(data, { reportInput: true })\n }\n\n decode(\n data: this['decodedZodType']['_zod']['input'],\n ): this['decodedZodType']['_zod']['output'] {\n return this.decodedZodType.parse(data, { reportInput: true })\n }\n}\n\nexport class OptionalType<\n Type extends BaseTypeAny = BaseTypeAny,\n> extends BaseType<\n ZodMiniOptional<Type['encodedZodType']>,\n ZodMiniOptional<Type['decodedZodType']>,\n { inner: Type }\n> {\n static factory<T extends BaseTypeAny>(type: T) {\n return new OptionalType<T>({\n encodedZodType: optional(type.encodedZodType) as any,\n props: { inner: type },\n })\n }\n}\n\nexport class NullableType<\n Type extends BaseTypeAny<any> = BaseTypeAny<any>,\n> extends BaseType<\n ZodMiniNullable<Type['encodedZodType']>,\n ZodMiniNullable<Type['decodedZodType']>,\n { inner: Type }\n> {\n static factory<T extends BaseTypeAny<any>>(type: T) {\n return new NullableType<T>({\n encodedZodType: nullable(type.encodedZodType),\n props: { inner: type },\n })\n }\n}\n\nexport class DefaultType<\n Type extends BaseTypeAny = BaseTypeAny,\n> extends BaseType<\n ZodMiniDefault<Type['encodedZodType']>,\n ZodMiniDefault<Type['decodedZodType']>,\n { inner: Type }\n> {\n static factory<T extends BaseTypeAny<any>>(type: T, defaultValue: any) {\n return new DefaultType<T>({\n encodedZodType: _default(\n type.encodedZodType,\n type.params.encode?.(defaultValue) ?? defaultValue,\n ) as any,\n decodedZodType: _default(type.decodedZodType, defaultValue) as any,\n props: { inner: type },\n })\n }\n}\n"],"version":3}
@@ -1 +1 @@
1
- {"mappings":"AAAA,SACE,KAEA,QACA,WACA,YAIK,WAAW;AAClB,SAAS,gBAAkD,WAAW;AAKtE,OAAO,MAAe,sBAIZ,SASR,CAAE;AAEJ,OAAO,MAAM,mBAIH,cAA8C;CACtD,OAAO,QAIL,EACA,QACA,QACA,OACA,OAAO,KAAK,EAYb,EAAE;AACD,SAAO,IAAI,WAA2C;GACpD,gBAAgB,KAAK,QAAQ,CAAC,MAAM,UAAU,OAAO,CAAC,EAAE,KAAK;GAC7D,gBAAgB,KACd,MACA,OAAO,WAAW,EAAE,MAAO,EAAC,CAAC,MAAM,UAAU,OAAO,CAAC,CACtD;GACD,QAAQ,EAAE,OAAQ;EACnB;CACF;AACF","names":[],"sources":["src/types/custom.ts"],"sourcesContent":["import {\n any,\n type core,\n custom,\n overwrite,\n pipe,\n type ZodMiniAny,\n type ZodMiniCustom,\n type ZodMiniPipe,\n} from '@zod/mini'\nimport { BaseType, type SimpleZodType, type ZodType } from './base.ts'\n\nexport type CustomTypeDecode<I, O> = (value: I) => O\nexport type CustomTypeEncode<I, O> = (value: I) => O\n\nexport abstract class TransformType<\n Type,\n EncodedType extends SimpleZodType = ZodMiniAny,\n DecodedType extends ZodType = ZodMiniCustom<Type, Type>,\n> extends BaseType<\n ZodMiniPipe<\n ZodMiniCustom<DecodedType['_zod']['output'], DecodedType['_zod']['input']>,\n EncodedType\n >,\n ZodMiniPipe<\n EncodedType,\n ZodMiniCustom<EncodedType['_zod']['output'], EncodedType['_zod']['input']>\n >\n> {}\n\nexport class CustomType<\n Type,\n EncodedType extends SimpleZodType = ZodMiniAny,\n DecodedType extends ZodType = ZodMiniCustom<Type, Type>,\n> extends TransformType<Type, EncodedType, DecodedType> {\n static factory<\n Type,\n EncodedType extends SimpleZodType = ZodMiniAny,\n DecodedType extends ZodType = ZodMiniCustom<Type, Type>,\n >({\n decode,\n encode,\n error,\n type = any() as unknown as EncodedType,\n }: {\n decode: CustomTypeDecode<\n EncodedType['_zod']['input'],\n DecodedType['_zod']['output']\n >\n encode: CustomTypeEncode<\n DecodedType['_zod']['input'],\n EncodedType['_zod']['output']\n >\n error?: string | core.$ZodErrorMap<core.$ZodIssueBase>\n type?: EncodedType\n }) {\n return new CustomType<Type, EncodedType, DecodedType>({\n encodedZodType: pipe(custom().check(overwrite(encode)), type),\n decodedZodType: pipe(\n type,\n custom(undefined, { error }).check(overwrite(decode)),\n ),\n params: { encode },\n })\n }\n}\n"],"version":3}
1
+ {"mappings":"AAAA,SACE,KAEA,QACA,WACA,YAGK,WAAW;AAClB,SAAS,gBAAkD,WAAW;AAGtE,OAAO,MAAe,sBAIZ,SASR,CAAE;AAEJ,OAAO,MAAM,mBAIH,cAA8C;CACtD,OAAO,QAIL,EACA,QACA,QACA,OACA,OAAO,KAAK,EAYb,EAAE;AACD,SAAO,IAAI,WAA2C;GACpD,gBAAgB,KAAK,QAAQ,CAAC,MAAM,UAAU,OAAO,CAAC,EAAE,KAAK;GAC7D,gBAAgB,KACd,MACA,OAAO,WAAW,EAAE,MAAO,EAAC,CAAC,MAAM,UAAU,OAAO,CAAC,CACtD;GACD,QAAQ,EAAE,OAAQ;EACnB;CACF;AACF","names":[],"sources":["src/types/custom.ts"],"sourcesContent":["import {\n any,\n type core,\n custom,\n overwrite,\n pipe,\n type ZodMiniPipe,\n type ZodMiniType,\n} from '@zod/mini'\nimport { BaseType, type SimpleZodType, type ZodType } from './base.ts'\n\nexport type CustomTransformFn<I, O> = (value: I) => O\nexport abstract class TransformType<\n Type,\n EncodedType extends SimpleZodType = ZodMiniType<Type, Type>,\n DecodedType extends ZodType = ZodMiniType<Type, Type>,\n> extends BaseType<\n ZodMiniPipe<\n ZodMiniType<DecodedType['_zod']['output'], DecodedType['_zod']['input']>,\n EncodedType\n >,\n ZodMiniPipe<\n EncodedType,\n ZodMiniType<EncodedType['_zod']['output'], EncodedType['_zod']['input']>\n >\n> {}\n\nexport class CustomType<\n Type,\n EncodedType extends SimpleZodType = ZodMiniType<Type, Type>,\n DecodedType extends ZodType = ZodMiniType<Type, Type>,\n> extends TransformType<Type, EncodedType, DecodedType> {\n static factory<\n Type,\n EncodedType extends SimpleZodType = ZodMiniType<Type, Type>,\n DecodedType extends ZodType = ZodMiniType<Type, Type>,\n >({\n decode,\n encode,\n error,\n type = any() as unknown as EncodedType,\n }: {\n decode: CustomTransformFn<\n EncodedType['_zod']['input'],\n DecodedType['_zod']['output']\n >\n encode: CustomTransformFn<\n DecodedType['_zod']['input'],\n EncodedType['_zod']['output']\n >\n error?: string | core.$ZodErrorMap<core.$ZodIssueBase>\n type?: EncodedType\n }) {\n return new CustomType<Type, EncodedType, DecodedType>({\n encodedZodType: pipe(custom().check(overwrite(encode)), type),\n decodedZodType: pipe(\n type,\n custom(undefined, { error }).check(overwrite(decode)),\n ),\n params: { encode },\n })\n }\n}\n"],"version":3}
package/package.json CHANGED
@@ -14,7 +14,7 @@
14
14
  "dependencies": {
15
15
  "@zod/mini": "4.0.0-beta.0",
16
16
  "temporal-polyfill": "^0.3.0",
17
- "@nmtjs/common": "0.7.1"
17
+ "@nmtjs/common": "0.7.3"
18
18
  },
19
19
  "files": [
20
20
  "src",
@@ -22,7 +22,7 @@
22
22
  "LICENSE.md",
23
23
  "README.md"
24
24
  ],
25
- "version": "0.7.1",
25
+ "version": "0.7.3",
26
26
  "scripts": {
27
27
  "build": "neemata-build --root=./src './**/*.ts'",
28
28
  "type-check": "tsc --noEmit"
package/src/index.ts CHANGED
@@ -51,18 +51,18 @@ export {
51
51
 
52
52
  export namespace type {
53
53
  export namespace infer {
54
- export type decoded<T extends BaseTypeAny> =
55
- T['decodedZodType']['_zod']['output']
56
-
57
- export type encoded<T extends BaseTypeAny> =
58
- T['encodedZodType']['_zod']['output']
59
-
60
- export namespace input {
61
- export type decoded<T extends BaseTypeAny> =
54
+ export namespace decoded {
55
+ export type input<T extends BaseTypeAny> =
62
56
  T['decodedZodType']['_zod']['input']
57
+ export type output<T extends BaseTypeAny> =
58
+ T['decodedZodType']['_zod']['output']
59
+ }
63
60
 
64
- export type encoded<T extends BaseTypeAny> =
61
+ export namespace encoded {
62
+ export type input<T extends BaseTypeAny> =
65
63
  T['encodedZodType']['_zod']['input']
64
+ export type output<T extends BaseTypeAny> =
65
+ T['encodedZodType']['_zod']['output']
66
66
  }
67
67
  }
68
68
 
package/src/types/base.ts CHANGED
@@ -7,6 +7,7 @@ import {
7
7
  type ZodMiniAny,
8
8
  type ZodMiniArray,
9
9
  type ZodMiniBoolean,
10
+ type ZodMiniCustom,
10
11
  type ZodMiniDefault,
11
12
  type ZodMiniEnum,
12
13
  type ZodMiniInterface,
@@ -26,7 +27,7 @@ import {
26
27
 
27
28
  export type PrimitiveValueType = string | number | boolean | null
28
29
 
29
- export type SimpleZodType =
30
+ export type PrimitiveZodType =
30
31
  | ZodMiniNever
31
32
  | ZodMiniDefault
32
33
  | ZodMiniNullable
@@ -43,7 +44,8 @@ export type SimpleZodType =
43
44
  | ZodMiniIntersection
44
45
  | ZodMiniInterface
45
46
  | ZodMiniRecord
46
- | ZodMiniPipe
47
+
48
+ export type SimpleZodType = ZodMiniType
47
49
 
48
50
  export type ZodType = SimpleZodType | ZodMiniType
49
51
 
@@ -4,50 +4,47 @@ import {
4
4
  custom,
5
5
  overwrite,
6
6
  pipe,
7
- type ZodMiniAny,
8
- type ZodMiniCustom,
9
7
  type ZodMiniPipe,
8
+ type ZodMiniType,
10
9
  } from '@zod/mini'
11
10
  import { BaseType, type SimpleZodType, type ZodType } from './base.ts'
12
11
 
13
- export type CustomTypeDecode<I, O> = (value: I) => O
14
- export type CustomTypeEncode<I, O> = (value: I) => O
15
-
12
+ export type CustomTransformFn<I, O> = (value: I) => O
16
13
  export abstract class TransformType<
17
14
  Type,
18
- EncodedType extends SimpleZodType = ZodMiniAny,
19
- DecodedType extends ZodType = ZodMiniCustom<Type, Type>,
15
+ EncodedType extends SimpleZodType = ZodMiniType<Type, Type>,
16
+ DecodedType extends ZodType = ZodMiniType<Type, Type>,
20
17
  > extends BaseType<
21
18
  ZodMiniPipe<
22
- ZodMiniCustom<DecodedType['_zod']['output'], DecodedType['_zod']['input']>,
19
+ ZodMiniType<DecodedType['_zod']['output'], DecodedType['_zod']['input']>,
23
20
  EncodedType
24
21
  >,
25
22
  ZodMiniPipe<
26
23
  EncodedType,
27
- ZodMiniCustom<EncodedType['_zod']['output'], EncodedType['_zod']['input']>
24
+ ZodMiniType<EncodedType['_zod']['output'], EncodedType['_zod']['input']>
28
25
  >
29
26
  > {}
30
27
 
31
28
  export class CustomType<
32
29
  Type,
33
- EncodedType extends SimpleZodType = ZodMiniAny,
34
- DecodedType extends ZodType = ZodMiniCustom<Type, Type>,
30
+ EncodedType extends SimpleZodType = ZodMiniType<Type, Type>,
31
+ DecodedType extends ZodType = ZodMiniType<Type, Type>,
35
32
  > extends TransformType<Type, EncodedType, DecodedType> {
36
33
  static factory<
37
34
  Type,
38
- EncodedType extends SimpleZodType = ZodMiniAny,
39
- DecodedType extends ZodType = ZodMiniCustom<Type, Type>,
35
+ EncodedType extends SimpleZodType = ZodMiniType<Type, Type>,
36
+ DecodedType extends ZodType = ZodMiniType<Type, Type>,
40
37
  >({
41
38
  decode,
42
39
  encode,
43
40
  error,
44
41
  type = any() as unknown as EncodedType,
45
42
  }: {
46
- decode: CustomTypeDecode<
43
+ decode: CustomTransformFn<
47
44
  EncodedType['_zod']['input'],
48
45
  DecodedType['_zod']['output']
49
46
  >
50
- encode: CustomTypeEncode<
47
+ encode: CustomTransformFn<
51
48
  DecodedType['_zod']['input'],
52
49
  EncodedType['_zod']['output']
53
50
  >