@nmtjs/type 0.7.4 → 0.7.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 +30 -30
- package/dist/index.js.map +1 -1
- package/dist/types/enum.js.map +1 -1
- package/dist/types/object.js.map +1 -1
- package/dist/types/tuple.js +16 -0
- package/dist/types/tuple.js.map +1 -0
- package/dist/types/union.js.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +32 -28
- package/src/types/enum.ts +4 -4
- package/src/types/object.ts +1 -3
- package/src/types/tuple.ts +54 -0
- package/src/types/union.ts +14 -8
package/dist/index.js
CHANGED
|
@@ -10,38 +10,38 @@ import { NeverType } from "./types/never.js";
|
|
|
10
10
|
import { BigIntType, IntegerType, NumberType } from "./types/number.js";
|
|
11
11
|
import { extend, keyof, merge, ObjectType, omit, partial, pick, RecordType } from "./types/object.js";
|
|
12
12
|
import { StringType } from "./types/string.js";
|
|
13
|
+
import { TupleType } from "./types/tuple.js";
|
|
13
14
|
import { DiscriminatedUnionType, IntersactionType, UnionType } from "./types/union.js";
|
|
14
15
|
zod.config(zod.core.locales.en());
|
|
15
16
|
export { NeemataTypeError } from "./types/base.js";
|
|
16
17
|
export { BaseType } from "./types/base.js";
|
|
17
|
-
export { ArrayType, BooleanType, CustomType, DateType, EnumType, LiteralType, IntegerType, NumberType, ObjectType, StringType, IntersactionType, UnionType,
|
|
18
|
-
export let type;
|
|
19
|
-
(function(_type) {
|
|
20
|
-
const never = _type.never = NeverType.factory;
|
|
21
|
-
const boolean = _type.boolean = BooleanType.factory;
|
|
22
|
-
const string = _type.string = StringType.factory;
|
|
23
|
-
const number = _type.number = NumberType.factory;
|
|
24
|
-
const integer = _type.integer = IntegerType.factory;
|
|
25
|
-
const bitint = _type.bitint = BigIntType.factory;
|
|
26
|
-
const literal = _type.literal = LiteralType.factory;
|
|
27
|
-
const enumeration = _type.enumeration = EnumType.factory;
|
|
28
|
-
const date = _type.date = DateType.factory;
|
|
29
|
-
const array = _type.array = ArrayType.factory;
|
|
30
|
-
const record = _type.record = RecordType.factory;
|
|
31
|
-
const any = _type.any = AnyType.factory;
|
|
32
|
-
const or = _type.or = UnionType.factory;
|
|
33
|
-
const and = _type.and = IntersactionType.factory;
|
|
34
|
-
const union = _type.union = UnionType.factory;
|
|
35
|
-
const intersaction = _type.intersaction = IntersactionType.factory;
|
|
36
|
-
const discriminatedUnion = _type.discriminatedUnion = DiscriminatedUnionType.factory;
|
|
37
|
-
const custom = _type.custom = CustomType.factory;
|
|
38
|
-
const object = _type.object = Object.assign(ObjectType.factory.bind(ObjectType), {
|
|
39
|
-
keyof,
|
|
40
|
-
partial,
|
|
41
|
-
merge,
|
|
42
|
-
omit,
|
|
43
|
-
extend,
|
|
44
|
-
pick
|
|
45
|
-
});
|
|
46
|
-
})(type || (type = {}));
|
|
18
|
+
export { AnyType, ArrayType, BooleanType, CustomType, DateType, EnumType, LiteralType, IntegerType, NumberType, ObjectType, StringType, IntersactionType, UnionType, TupleType, NeverType, DiscriminatedUnionType, RecordType };
|
|
47
19
|
export { type as t, zod };
|
|
20
|
+
export const type = {
|
|
21
|
+
never: NeverType.factory,
|
|
22
|
+
boolean: BooleanType.factory,
|
|
23
|
+
string: StringType.factory,
|
|
24
|
+
number: NumberType.factory,
|
|
25
|
+
integer: IntegerType.factory,
|
|
26
|
+
bigint: BigIntType.factory,
|
|
27
|
+
literal: LiteralType.factory,
|
|
28
|
+
enum: EnumType.factory,
|
|
29
|
+
tuple: TupleType.factory,
|
|
30
|
+
date: DateType.factory,
|
|
31
|
+
array: ArrayType.factory,
|
|
32
|
+
record: RecordType.factory,
|
|
33
|
+
any: AnyType.factory,
|
|
34
|
+
or: UnionType.factory,
|
|
35
|
+
and: IntersactionType.factory,
|
|
36
|
+
union: UnionType.factory,
|
|
37
|
+
intersaction: IntersactionType.factory,
|
|
38
|
+
discriminatedUnion: DiscriminatedUnionType.factory,
|
|
39
|
+
custom: CustomType.factory,
|
|
40
|
+
object: ObjectType.factory,
|
|
41
|
+
keyof,
|
|
42
|
+
partial,
|
|
43
|
+
merge,
|
|
44
|
+
omit,
|
|
45
|
+
extend,
|
|
46
|
+
pick
|
|
47
|
+
};
|
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,
|
|
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,SAAS,iBAAiB,kBAAkB;AAC5C,SACE,wBACA,kBACA,iBACK,kBAAkB;AAEzB,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC;AAEjC,SAAS,wBAAwB;AACjC,SAAS,gBAAkC;AAC3C,SACE,SACA,WACA,aACA,YACA,UACA,UACA,aACA,aACA,YACA,YACA,YACA,kBACA,WACA,WACA,WACA,wBACA;AAqBF,SAAS,QAAQ,GAAG;AAEpB,OAAO,MAAM,OAAO;CAClB,OAAO,UAAU;CACjB,SAAS,YAAY;CACrB,QAAQ,WAAW;CACnB,QAAQ,WAAW;CACnB,SAAS,YAAY;CACrB,QAAQ,WAAW;CACnB,SAAS,YAAY;CACrB,MAAM,SAAS;CACf,OAAO,UAAU;CACjB,MAAM,SAAS;CACf,OAAO,UAAU;CACjB,QAAQ,WAAW;CACnB,KAAK,QAAQ;CACb,IAAI,UAAU;CACd,KAAK,iBAAiB;CACtB,OAAO,UAAU;CACjB,cAAc,iBAAiB;CAC/B,oBAAoB,uBAAuB;CAC3C,QAAQ,WAAW;CACnB,QAAQ,WAAW;CACnB;CACA;CACA;CACA;CACA;CACA;AACD","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 { TupleType } from './types/tuple.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 AnyType,\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 TupleType,\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\nexport { type as t, zod }\n\nexport const type = {\n never: NeverType.factory,\n boolean: BooleanType.factory,\n string: StringType.factory,\n number: NumberType.factory,\n integer: IntegerType.factory,\n bigint: BigIntType.factory,\n literal: LiteralType.factory,\n enum: EnumType.factory,\n tuple: TupleType.factory,\n date: DateType.factory,\n array: ArrayType.factory,\n record: RecordType.factory,\n any: AnyType.factory,\n or: UnionType.factory,\n and: IntersactionType.factory,\n union: UnionType.factory,\n intersaction: IntersactionType.factory,\n discriminatedUnion: DiscriminatedUnionType.factory,\n custom: CustomType.factory,\n object: ObjectType.factory,\n keyof,\n partial,\n merge,\n omit,\n extend,\n pick,\n}\n"],"version":3}
|
package/dist/types/enum.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAAA,SAAoB,QAAQ,aAA+B,WAAW;AACtE,SAAS,gBAAgB,WAAW;AAEpC,OAAO,MAAM,iBAEH,SAAwD;CAKhE,OAAO,
|
|
1
|
+
{"mappings":"AAAA,SAAoB,QAAQ,aAA+B,WAAW;AACtE,SAAS,gBAAgB,WAAW;AAEpC,OAAO,MAAM,iBAEH,SAAwD;CAKhE,OAAO,QAAiDA,QAAW;AACjE,SAAO,IAAI,SAAS;GAClB,gBAAgB,MAAM,OAAc;GACpC,OAAO,EAAE,OAAQ;EAClB;CACF;AACF","names":["values: T"],"sources":["src/types/enum.ts"],"sourcesContent":["import { type core, enum as enum_, type ZodMiniEnum } from '@zod/mini'\nimport { BaseType } from './base.ts'\n\nexport class EnumType<\n T extends core.util.EnumLike = core.util.EnumLike,\n> extends BaseType<ZodMiniEnum<T>, ZodMiniEnum<T>, { values: T }> {\n static factory<T extends core.util.EnumLike>(values: T): EnumType<T>\n static factory<T extends string[]>(\n values: T,\n ): EnumType<core.util.ToEnum<T[number]>>\n static factory<T extends core.util.EnumLike | string[]>(values: T) {\n return new EnumType({\n encodedZodType: enum_(values as any),\n props: { values },\n })\n }\n}\n"],"version":3}
|
package/dist/types/object.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAAA,SAEE,QACA,QACA,oBAGK,WAAW;AAElB,SAAS,gBAAqD,WAAW;AACzE,SAAS,gBAAgB,WAAW;AAMpC,OAAO,MAAM,mBAAmD,SAI9D;CACA,OAAO,QAAwCA,YAAe;EAC5D,MAAM,mBAAmB,CAAE;EAG3B,MAAM,mBAAmB,CAAE;AAI3B,OAAK,MAAM,OAAO,YAAY;AAC5B,oBAAiB,OAAO,WAAW,KAAK;AACxC,oBAAiB,OAAO,WAAW,KAAK;EACzC;AAED,SAAO,IAAI,WAAc;GACvB,gBAAgB,OAAO,iBAAiB;GACxC,gBAAgB,OAAO,iBAAiB;GACxC,OAAO,EAAE,WAAY;EACtB;CACF;AACF;AAED,OAAO,MAAM,mBAGH,SAGR;CACA,OAAO,QAGLC,KAAQC,SAAY;AACpB,SAAO,IAAI,WAAiB;GAC1B,gBAAgB,OACb,IAAY,gBACb,QAAQ,eACT;GACD,gBAAgB,OACb,IAAY,gBACb,QAAQ,eACT;GACD,OAAO;IAAE;IAAK;GAAS;EACxB;CACF;AACF;AAED,OAAO,SAAS,MACdC,
|
|
1
|
+
{"mappings":"AAAA,SAEE,QACA,QACA,oBAGK,WAAW;AAElB,SAAS,gBAAqD,WAAW;AACzE,SAAS,gBAAgB,WAAW;AAMpC,OAAO,MAAM,mBAAmD,SAI9D;CACA,OAAO,QAAwCA,YAAe;EAC5D,MAAM,mBAAmB,CAAE;EAG3B,MAAM,mBAAmB,CAAE;AAI3B,OAAK,MAAM,OAAO,YAAY;AAC5B,oBAAiB,OAAO,WAAW,KAAK;AACxC,oBAAiB,OAAO,WAAW,KAAK;EACzC;AAED,SAAO,IAAI,WAAc;GACvB,gBAAgB,OAAO,iBAAiB;GACxC,gBAAgB,OAAO,iBAAiB;GACxC,OAAO,EAAE,WAAY;EACtB;CACF;AACF;AAED,OAAO,MAAM,mBAGH,SAGR;CACA,OAAO,QAGLC,KAAQC,SAAY;AACpB,SAAO,IAAI,WAAiB;GAC1B,gBAAgB,OACb,IAAY,gBACb,QAAQ,eACT;GACD,gBAAgB,OACb,IAAY,gBACb,QAAQ,eACT;GACD,OAAO;IAAE;IAAK;GAAS;EACxB;CACF;AACF;AAED,OAAO,SAAS,MACdC,MAC6E;AAC7E,QAAO,SAAS,QAAQ,OAAO,KAAK,KAAK,MAAM,WAAW,CAAQ;AACnE;AAED,OAAO,SAAS,KAIdC,QACAC,MAOC;CACD,MAAM,aAAa,OAAO,YACxB,OAAO,QAAQ,OAAO,MAAM,WAAW,CAAC,OAAO,CAAC,CAAC,IAAI,KAAK,KAAK,KAAK,CACrE;AACD,QAAO,WAAW,QAAQ,WAAW;AACtC;AAED,OAAO,SAAS,KAIdD,QACAE,MAKC;CACD,MAAM,aAAa,OAAO,YACxB,OAAO,QAAQ,OAAO,MAAM,WAAW,CAAC,OAAO,CAAC,CAAC,IAAI,MAAM,KAAK,KAAK,CACtE;AACD,QAAO,WAAW,QAAQ,WAAW;AACtC;AAED,OAAO,SAAS,OACdC,SACAC,YAOC;AACD,QAAO,WAAW,QAAQ;EACxB,GAAG,QAAQ,MAAM;EACjB,GAAG;CACJ,EAAC;AACH;AAED,OAAO,SAAS,MACdC,SACAC,SASC;AACD,QAAO,WAAW,QAAQ;EACxB,GAAG,QAAQ,MAAM;EACjB,GAAG,QAAQ,MAAM;CAClB,EAAC;AACH;AAED,OAAO,SAAS,QAIdC,QAGC;CACD,MAAM,aAAa,CAAE;AAErB,MAAK,MAAM,CAAC,KAAK,MAAM,IAAI,OAAO,QAAQ,OAAO,MAAM,WAAW,EAAE;AAClE,aAAW,OAAO,MAAM,UAAU;CACnC;AAED,QAAO,WAAW,QAAQ,WAAW;AACtC","names":["properties: T","key: K","element: E","type: T","source: T","pick: P","omit: P","object1: T","properties: P","object1: T1","object2: T2","object: T"],"sources":["src/types/object.ts"],"sourcesContent":["import {\n type core,\n object,\n record,\n strictObject,\n type ZodMiniObject,\n type ZodMiniRecord,\n} from '@zod/mini'\n\nimport { BaseType, type BaseTypeAny, type OptionalType } from './base.ts'\nimport { EnumType } from './enum.ts'\nimport type { LiteralType } from './literal.ts'\nimport type { StringType } from './string.ts'\n\nexport type ObjectTypeProps = { [k: string]: BaseTypeAny }\nexport type AnyObjectType = ObjectType<ObjectTypeProps>\nexport class ObjectType<T extends ObjectTypeProps = {}> extends BaseType<\n ZodMiniObject<{ [K in keyof T]: T[K]['encodedZodType'] }, {}>,\n ZodMiniObject<{ [K in keyof T]: T[K]['decodedZodType'] }, {}>,\n { properties: T }\n> {\n static factory<T extends ObjectTypeProps = {}>(properties: T) {\n const encodeProperties = {} as {\n [K in keyof T]: T[K]['encodedZodType']\n }\n const decodeProperties = {} as {\n [K in keyof T]: T[K]['decodedZodType']\n }\n\n for (const key in properties) {\n encodeProperties[key] = properties[key].encodedZodType\n decodeProperties[key] = properties[key].decodedZodType\n }\n\n return new ObjectType<T>({\n encodedZodType: object(encodeProperties),\n decodedZodType: object(decodeProperties),\n props: { properties },\n })\n }\n}\n\nexport class RecordType<\n K extends LiteralType<string | number> | EnumType | StringType,\n E extends BaseType,\n> extends BaseType<\n ZodMiniRecord<K['encodedZodType'], E['encodedZodType']>,\n ZodMiniRecord<K['decodedZodType'], E['decodedZodType']>\n> {\n static factory<\n K extends LiteralType<string | number> | EnumType | StringType,\n E extends BaseType,\n >(key: K, element: E) {\n return new RecordType<K, E>({\n encodedZodType: record(\n (key as any).encodedZodType,\n element.encodedZodType,\n ),\n decodedZodType: record(\n (key as any).decodedZodType,\n element.decodedZodType,\n ),\n props: { key, element },\n })\n }\n}\n\nexport function keyof<T extends ObjectType>(\n type: T,\n): EnumType<core.util.ToEnum<Extract<keyof T['props']['properties'], string>>> {\n return EnumType.factory(Object.keys(type.props.properties) as any)\n}\n\nexport function pick<\n T extends AnyObjectType,\n P extends { [K in keyof T['props']['properties']]?: true },\n>(\n source: T,\n pick: P,\n): ObjectType<{\n [K in keyof P]: P[K] extends true\n ? K extends keyof T['props']['properties']\n ? T['props']['properties'][K]\n : never\n : never\n}> {\n const properties = Object.fromEntries(\n Object.entries(source.props.properties).filter(([key]) => pick[key]),\n )\n return ObjectType.factory(properties) as any\n}\n\nexport function omit<\n T extends AnyObjectType,\n P extends { [K in keyof T['props']['properties']]?: true },\n>(\n source: T,\n omit: P,\n): ObjectType<{\n [K in keyof T['props']['properties'] as K extends keyof P\n ? never\n : K]: T['props']['properties'][K]\n}> {\n const properties = Object.fromEntries(\n Object.entries(source.props.properties).filter(([key]) => !omit[key]),\n )\n return ObjectType.factory(properties) as any\n}\n\nexport function extend<T extends AnyObjectType, P extends ObjectTypeProps>(\n object1: T,\n properties: P,\n): ObjectType<{\n [K in keyof T['props']['properties'] | keyof P]: K extends keyof P\n ? P[K]\n : K extends keyof T['props']['properties']\n ? T['props']['properties'][K]\n : never\n}> {\n return ObjectType.factory({\n ...object1.props.properties,\n ...properties,\n }) as any\n}\n\nexport function merge<T1 extends AnyObjectType, T2 extends AnyObjectType>(\n object1: T1,\n object2: T2,\n): ObjectType<{\n [K in\n | keyof T1['props']['properties']\n | keyof T2['props']['properties']]: K extends keyof T2['props']['properties']\n ? T2['props']['properties'][K]\n : K extends keyof T1['props']['properties']\n ? T1['props']['properties'][K]\n : never\n}> {\n return ObjectType.factory({\n ...object1.props.properties,\n ...object2.props.properties,\n }) as any\n}\n\nexport function partial<\n T extends AnyObjectType,\n P extends T extends ObjectType<infer Props> ? Props : never,\n>(\n object: T,\n): ObjectType<{\n [K in keyof P]: OptionalType<P[K]>\n}> {\n const properties = {} as any\n\n for (const [key, value] of Object.entries(object.props.properties)) {\n properties[key] = value.optional()\n }\n\n return ObjectType.factory(properties)\n}\n"],"version":3}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { tuple } from "@zod/mini";
|
|
2
|
+
import { BaseType } from "./base.js";
|
|
3
|
+
export class TupleType extends BaseType {
|
|
4
|
+
static factory(elements, rest = null) {
|
|
5
|
+
const encoded = elements.map((el) => el.encodedZodType);
|
|
6
|
+
const decoded = elements.map((el) => el.decodedZodType);
|
|
7
|
+
return new TupleType({
|
|
8
|
+
encodedZodType: tuple(encoded, rest?.encodedZodType),
|
|
9
|
+
decodedZodType: tuple(decoded, rest?.decodedZodType),
|
|
10
|
+
props: {
|
|
11
|
+
elements,
|
|
12
|
+
rest
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAAA,SAAS,aAAgC,WAAW;AACpD,SAAS,gBAAgB,WAAW;AAEpC,OAAO,MAAM,kBAMH,SA4BR;CACA,OAAO,QAGLA,UAAaC,OAAU,MAAW;EAClC,MAAM,UAAU,SAAS,IAAI,CAAC,OAAO,GAAG,eAAe;EACvD,MAAM,UAAU,SAAS,IAAI,CAAC,OAAO,GAAG,eAAe;AAEvD,SAAO,IAAI,UAAgB;GAEzB,gBAAgB,MAAM,SAAS,MAAM,eAAe;GAEpD,gBAAgB,MAAM,SAAS,MAAM,eAAe;GACpD,OAAO;IAAE;IAAU;GAAM;EAC1B;CACF;AACF","names":["elements: T","rest: R"],"sources":["src/types/tuple.ts"],"sourcesContent":["import { tuple, type ZodMiniTuple } from '@zod/mini'\nimport { BaseType } from './base.ts'\n\nexport class TupleType<\n T extends readonly [BaseType, ...BaseType[]] = readonly [\n BaseType,\n ...BaseType[],\n ],\n R extends BaseType | null = BaseType | null,\n> extends BaseType<\n R extends BaseType\n ? ZodMiniTuple<\n {\n [K in keyof T]: T[K]['encodedZodType']\n },\n R['encodedZodType']\n >\n : ZodMiniTuple<\n {\n [K in keyof T]: T[K]['encodedZodType']\n },\n null\n >,\n R extends BaseType\n ? ZodMiniTuple<\n {\n [K in keyof T]: T[K]['decodedZodType']\n },\n R['decodedZodType']\n >\n : ZodMiniTuple<\n {\n [K in keyof T]: T[K]['decodedZodType']\n },\n null\n >,\n { elements: T; rest?: R }\n> {\n static factory<\n T extends readonly [BaseType, ...BaseType[]],\n R extends BaseType | null = null,\n >(elements: T, rest: R = null as R) {\n const encoded = elements.map((el) => el.encodedZodType)\n const decoded = elements.map((el) => el.decodedZodType)\n\n return new TupleType<T, R>({\n // @ts-expect-error\n encodedZodType: tuple(encoded, rest?.encodedZodType),\n // @ts-expect-error\n decodedZodType: tuple(decoded, rest?.decodedZodType),\n props: { elements, rest },\n })\n }\n}\n"],"version":3}
|
package/dist/types/union.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAAA,SAEE,oBACA,cACA,aAIK,WAAW;AAClB,SAAS,gBAAkC,WAAW;AAItD,OAAO,MAAM,
|
|
1
|
+
{"mappings":"AAAA,SAEE,oBACA,cACA,aAIK,WAAW;AAClB,SAAS,gBAAkC,WAAW;AAItD,OAAO,MAAM,kBAKH,SAIR;CACA,OAAO,QAKL,GAAG,SAAY;AACf,SAAO,IAAI,UAAa;GACtB,gBAAgB,MAAM,QAAQ,IAAI,CAAC,MAAM,EAAE,eAAe,CAAC;GAC3D,gBAAgB,MAAM,QAAQ,IAAI,CAAC,MAAM,EAAE,eAAe,CAAC;GAC3D,OAAO,EAAE,QAAS;EACnB;CACF;AACF;AAED,OAAO,MAAM,yBAEH,SAIR;CACA,OAAO,QAEL,GAAG,SAAY;EACf,MAAM,CAAC,OAAO,OAAO,GAAG;AACxB,SAAO,IAAI,iBAAoB;GAC7B,gBAAgB,aAAa,MAAM,gBAAgB,OAAO,eAAe;GACzE,gBAAgB,aAAa,MAAM,gBAAgB,OAAO,eAAe;GACzE,OAAO,EAAE,QAAS;EACnB;CACF;AACF;AAYD,OAAO,MAAM,+BAIH,SAOR;CACA,OAAO,QAILA,KAAQ,GAAG,SAAY;AACvB,SAAO,IAAI,uBAA6B;GACtC,gBAAgB,mBACd,QAAQ,IAAI,CAAC,MAAM,EAAE,eAAe,CACrC;GACD,gBAAgB,mBACd,QAAQ,IAAI,CAAC,MAAM,EAAE,eAAe,CACrC;GACD,OAAO;IAAE;IAAK;GAAS;EACxB;CACF;AACF","names":["key: K"],"sources":["src/types/union.ts"],"sourcesContent":["import {\n type core,\n discriminatedUnion,\n intersection,\n union,\n type ZodMiniDiscriminatedUnion,\n type ZodMiniIntersection,\n type ZodMiniUnion,\n} from '@zod/mini'\nimport { BaseType, type BaseTypeAny } from './base.ts'\nimport type { LiteralType } from './literal.ts'\nimport type { ObjectType, ObjectTypeProps } from './object.ts'\n\nexport class UnionType<\n T extends readonly [BaseType, ...BaseType[]] = readonly [\n BaseType,\n ...BaseType[],\n ],\n> extends BaseType<\n ZodMiniUnion<core.util.Flatten<T[number]['encodedZodType'][]>>,\n ZodMiniUnion<core.util.Flatten<T[number]['decodedZodType'][]>>,\n { options: T }\n> {\n static factory<\n T extends readonly [BaseType, ...BaseType[]] = readonly [\n BaseType,\n ...BaseType[],\n ],\n >(...options: T) {\n return new UnionType<T>({\n encodedZodType: union(options.map((t) => t.encodedZodType)),\n decodedZodType: union(options.map((t) => t.decodedZodType)),\n props: { options },\n })\n }\n}\n\nexport class IntersactionType<\n T extends readonly [BaseType, BaseType] = readonly [BaseType, BaseType],\n> extends BaseType<\n ZodMiniIntersection<T[0]['encodedZodType'], T[1]['encodedZodType']>,\n ZodMiniIntersection<T[0]['decodedZodType'], T[1]['decodedZodType']>,\n { options: T }\n> {\n static factory<\n T extends readonly [BaseType, BaseType] = readonly [BaseType, BaseType],\n >(...options: T) {\n const [first, second] = options\n return new IntersactionType<T>({\n encodedZodType: intersection(first.encodedZodType, second.encodedZodType),\n decodedZodType: intersection(first.decodedZodType, second.decodedZodType),\n props: { options },\n })\n }\n}\n\nexport type DiscriminatedUnionProperties<K extends string = string> = {\n [OK in K]: LiteralType<string>\n} & {\n [OK in string]: any\n}\n\nexport type DiscriminatedUnionOptionType<K extends string> = ObjectType<\n ObjectTypeProps & { [_ in K]: BaseTypeAny }\n>\n\nexport class DiscriminatedUnionType<\n K extends string = string,\n T extends\n readonly DiscriminatedUnionOptionType<K>[] = DiscriminatedUnionOptionType<K>[],\n> extends BaseType<\n ZodMiniDiscriminatedUnion<T[number]['encodedZodType'][]>,\n ZodMiniDiscriminatedUnion<T[number]['decodedZodType'][]>,\n {\n key: K\n options: T\n }\n> {\n static factory<\n K extends string = string,\n T extends\n readonly DiscriminatedUnionOptionType<K>[] = DiscriminatedUnionOptionType<K>[],\n >(key: K, ...options: T) {\n return new DiscriminatedUnionType<K, T>({\n encodedZodType: discriminatedUnion(\n options.map((t) => t.encodedZodType) as any,\n ),\n decodedZodType: discriminatedUnion(\n options.map((t) => t.decodedZodType) as any,\n ),\n props: { key, options },\n })\n }\n}\n"],"version":3}
|
package/package.json
CHANGED
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@zod/mini": "4.0.0-beta.
|
|
15
|
+
"@zod/mini": "4.0.0-beta.20250503T014749",
|
|
16
16
|
"temporal-polyfill": "^0.3.0",
|
|
17
|
-
"@nmtjs/common": "0.7.
|
|
17
|
+
"@nmtjs/common": "0.7.6"
|
|
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.
|
|
25
|
+
"version": "0.7.6",
|
|
26
26
|
"scripts": {
|
|
27
27
|
"build": "neemata-build --root=./src './**/*.ts'",
|
|
28
28
|
"type-check": "tsc --noEmit"
|
package/src/index.ts
CHANGED
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
RecordType,
|
|
21
21
|
} from './types/object.ts'
|
|
22
22
|
import { StringType } from './types/string.ts'
|
|
23
|
+
import { TupleType } from './types/tuple.ts'
|
|
23
24
|
import {
|
|
24
25
|
DiscriminatedUnionType,
|
|
25
26
|
IntersactionType,
|
|
@@ -31,6 +32,7 @@ zod.config(zod.core.locales.en())
|
|
|
31
32
|
export { NeemataTypeError } from './types/base.ts'
|
|
32
33
|
export { BaseType, type BaseTypeAny } from './types/base.ts'
|
|
33
34
|
export {
|
|
35
|
+
AnyType,
|
|
34
36
|
ArrayType,
|
|
35
37
|
BooleanType,
|
|
36
38
|
CustomType,
|
|
@@ -43,7 +45,7 @@ export {
|
|
|
43
45
|
StringType,
|
|
44
46
|
IntersactionType,
|
|
45
47
|
UnionType,
|
|
46
|
-
|
|
48
|
+
TupleType,
|
|
47
49
|
NeverType,
|
|
48
50
|
DiscriminatedUnionType,
|
|
49
51
|
RecordType,
|
|
@@ -65,33 +67,35 @@ export namespace type {
|
|
|
65
67
|
T['encodedZodType']['_zod']['output']
|
|
66
68
|
}
|
|
67
69
|
}
|
|
68
|
-
|
|
69
|
-
export const never = NeverType.factory
|
|
70
|
-
export const boolean = BooleanType.factory
|
|
71
|
-
export const string = StringType.factory
|
|
72
|
-
export const number = NumberType.factory
|
|
73
|
-
export const integer = IntegerType.factory
|
|
74
|
-
export const bitint = BigIntType.factory
|
|
75
|
-
export const literal = LiteralType.factory
|
|
76
|
-
export const enumeration = EnumType.factory
|
|
77
|
-
export const date = DateType.factory
|
|
78
|
-
export const array = ArrayType.factory
|
|
79
|
-
export const record = RecordType.factory
|
|
80
|
-
export const any = AnyType.factory
|
|
81
|
-
export const or = UnionType.factory
|
|
82
|
-
export const and = IntersactionType.factory
|
|
83
|
-
export const union = UnionType.factory
|
|
84
|
-
export const intersaction = IntersactionType.factory
|
|
85
|
-
export const discriminatedUnion = DiscriminatedUnionType.factory
|
|
86
|
-
export const custom = CustomType.factory
|
|
87
|
-
export const object = Object.assign(ObjectType.factory.bind(ObjectType), {
|
|
88
|
-
keyof,
|
|
89
|
-
partial,
|
|
90
|
-
merge,
|
|
91
|
-
omit,
|
|
92
|
-
extend,
|
|
93
|
-
pick,
|
|
94
|
-
})
|
|
95
70
|
}
|
|
96
71
|
|
|
97
72
|
export { type as t, zod }
|
|
73
|
+
|
|
74
|
+
export const type = {
|
|
75
|
+
never: NeverType.factory,
|
|
76
|
+
boolean: BooleanType.factory,
|
|
77
|
+
string: StringType.factory,
|
|
78
|
+
number: NumberType.factory,
|
|
79
|
+
integer: IntegerType.factory,
|
|
80
|
+
bigint: BigIntType.factory,
|
|
81
|
+
literal: LiteralType.factory,
|
|
82
|
+
enum: EnumType.factory,
|
|
83
|
+
tuple: TupleType.factory,
|
|
84
|
+
date: DateType.factory,
|
|
85
|
+
array: ArrayType.factory,
|
|
86
|
+
record: RecordType.factory,
|
|
87
|
+
any: AnyType.factory,
|
|
88
|
+
or: UnionType.factory,
|
|
89
|
+
and: IntersactionType.factory,
|
|
90
|
+
union: UnionType.factory,
|
|
91
|
+
intersaction: IntersactionType.factory,
|
|
92
|
+
discriminatedUnion: DiscriminatedUnionType.factory,
|
|
93
|
+
custom: CustomType.factory,
|
|
94
|
+
object: ObjectType.factory,
|
|
95
|
+
keyof,
|
|
96
|
+
partial,
|
|
97
|
+
merge,
|
|
98
|
+
omit,
|
|
99
|
+
extend,
|
|
100
|
+
pick,
|
|
101
|
+
}
|
package/src/types/enum.ts
CHANGED
|
@@ -2,13 +2,13 @@ import { type core, enum as enum_, type ZodMiniEnum } from '@zod/mini'
|
|
|
2
2
|
import { BaseType } from './base.ts'
|
|
3
3
|
|
|
4
4
|
export class EnumType<
|
|
5
|
-
T extends core.
|
|
5
|
+
T extends core.util.EnumLike = core.util.EnumLike,
|
|
6
6
|
> extends BaseType<ZodMiniEnum<T>, ZodMiniEnum<T>, { values: T }> {
|
|
7
|
-
static factory<T extends core.
|
|
7
|
+
static factory<T extends core.util.EnumLike>(values: T): EnumType<T>
|
|
8
8
|
static factory<T extends string[]>(
|
|
9
9
|
values: T,
|
|
10
|
-
): EnumType<core.
|
|
11
|
-
static factory<T extends core.
|
|
10
|
+
): EnumType<core.util.ToEnum<T[number]>>
|
|
11
|
+
static factory<T extends core.util.EnumLike | string[]>(values: T) {
|
|
12
12
|
return new EnumType({
|
|
13
13
|
encodedZodType: enum_(values as any),
|
|
14
14
|
props: { values },
|
package/src/types/object.ts
CHANGED
|
@@ -67,9 +67,7 @@ export class RecordType<
|
|
|
67
67
|
|
|
68
68
|
export function keyof<T extends ObjectType>(
|
|
69
69
|
type: T,
|
|
70
|
-
): EnumType<
|
|
71
|
-
core.utils.ToEnum<Extract<keyof T['props']['properties'], string>>
|
|
72
|
-
> {
|
|
70
|
+
): EnumType<core.util.ToEnum<Extract<keyof T['props']['properties'], string>>> {
|
|
73
71
|
return EnumType.factory(Object.keys(type.props.properties) as any)
|
|
74
72
|
}
|
|
75
73
|
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { tuple, type ZodMiniTuple } from '@zod/mini'
|
|
2
|
+
import { BaseType } from './base.ts'
|
|
3
|
+
|
|
4
|
+
export class TupleType<
|
|
5
|
+
T extends readonly [BaseType, ...BaseType[]] = readonly [
|
|
6
|
+
BaseType,
|
|
7
|
+
...BaseType[],
|
|
8
|
+
],
|
|
9
|
+
R extends BaseType | null = BaseType | null,
|
|
10
|
+
> extends BaseType<
|
|
11
|
+
R extends BaseType
|
|
12
|
+
? ZodMiniTuple<
|
|
13
|
+
{
|
|
14
|
+
[K in keyof T]: T[K]['encodedZodType']
|
|
15
|
+
},
|
|
16
|
+
R['encodedZodType']
|
|
17
|
+
>
|
|
18
|
+
: ZodMiniTuple<
|
|
19
|
+
{
|
|
20
|
+
[K in keyof T]: T[K]['encodedZodType']
|
|
21
|
+
},
|
|
22
|
+
null
|
|
23
|
+
>,
|
|
24
|
+
R extends BaseType
|
|
25
|
+
? ZodMiniTuple<
|
|
26
|
+
{
|
|
27
|
+
[K in keyof T]: T[K]['decodedZodType']
|
|
28
|
+
},
|
|
29
|
+
R['decodedZodType']
|
|
30
|
+
>
|
|
31
|
+
: ZodMiniTuple<
|
|
32
|
+
{
|
|
33
|
+
[K in keyof T]: T[K]['decodedZodType']
|
|
34
|
+
},
|
|
35
|
+
null
|
|
36
|
+
>,
|
|
37
|
+
{ elements: T; rest?: R }
|
|
38
|
+
> {
|
|
39
|
+
static factory<
|
|
40
|
+
T extends readonly [BaseType, ...BaseType[]],
|
|
41
|
+
R extends BaseType | null = null,
|
|
42
|
+
>(elements: T, rest: R = null as R) {
|
|
43
|
+
const encoded = elements.map((el) => el.encodedZodType)
|
|
44
|
+
const decoded = elements.map((el) => el.decodedZodType)
|
|
45
|
+
|
|
46
|
+
return new TupleType<T, R>({
|
|
47
|
+
// @ts-expect-error
|
|
48
|
+
encodedZodType: tuple(encoded, rest?.encodedZodType),
|
|
49
|
+
// @ts-expect-error
|
|
50
|
+
decodedZodType: tuple(decoded, rest?.decodedZodType),
|
|
51
|
+
props: { elements, rest },
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
}
|
package/src/types/union.ts
CHANGED
|
@@ -12,15 +12,21 @@ import type { LiteralType } from './literal.ts'
|
|
|
12
12
|
import type { ObjectType, ObjectTypeProps } from './object.ts'
|
|
13
13
|
|
|
14
14
|
export class UnionType<
|
|
15
|
-
T extends readonly BaseType[] = readonly
|
|
15
|
+
T extends readonly [BaseType, ...BaseType[]] = readonly [
|
|
16
|
+
BaseType,
|
|
17
|
+
...BaseType[],
|
|
18
|
+
],
|
|
16
19
|
> extends BaseType<
|
|
17
|
-
ZodMiniUnion<core.
|
|
18
|
-
ZodMiniUnion<core.
|
|
20
|
+
ZodMiniUnion<core.util.Flatten<T[number]['encodedZodType'][]>>,
|
|
21
|
+
ZodMiniUnion<core.util.Flatten<T[number]['decodedZodType'][]>>,
|
|
19
22
|
{ options: T }
|
|
20
23
|
> {
|
|
21
|
-
static factory<
|
|
22
|
-
...
|
|
23
|
-
|
|
24
|
+
static factory<
|
|
25
|
+
T extends readonly [BaseType, ...BaseType[]] = readonly [
|
|
26
|
+
BaseType,
|
|
27
|
+
...BaseType[],
|
|
28
|
+
],
|
|
29
|
+
>(...options: T) {
|
|
24
30
|
return new UnionType<T>({
|
|
25
31
|
encodedZodType: union(options.map((t) => t.encodedZodType)),
|
|
26
32
|
decodedZodType: union(options.map((t) => t.decodedZodType)),
|
|
@@ -63,8 +69,8 @@ export class DiscriminatedUnionType<
|
|
|
63
69
|
T extends
|
|
64
70
|
readonly DiscriminatedUnionOptionType<K>[] = DiscriminatedUnionOptionType<K>[],
|
|
65
71
|
> extends BaseType<
|
|
66
|
-
ZodMiniDiscriminatedUnion<
|
|
67
|
-
ZodMiniDiscriminatedUnion<
|
|
72
|
+
ZodMiniDiscriminatedUnion<T[number]['encodedZodType'][]>,
|
|
73
|
+
ZodMiniDiscriminatedUnion<T[number]['decodedZodType'][]>,
|
|
68
74
|
{
|
|
69
75
|
key: K
|
|
70
76
|
options: T
|