@nmtjs/type 0.10.1 → 0.10.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 +4 -46
- package/dist/index.js.map +1 -1
- package/dist/temporal.js +1 -8
- package/dist/temporal.js.map +1 -1
- package/dist/types/any.js +3 -2
- package/dist/types/any.js.map +1 -1
- package/dist/types/array.js +7 -6
- package/dist/types/array.js.map +1 -1
- package/dist/types/base.js +7 -7
- package/dist/types/base.js.map +1 -1
- package/dist/types/boolean.js +3 -2
- package/dist/types/boolean.js.map +1 -1
- package/dist/types/custom.js +13 -8
- package/dist/types/custom.js.map +1 -1
- package/dist/types/date.js +3 -2
- package/dist/types/date.js.map +1 -1
- package/dist/types/enum.js +4 -2
- package/dist/types/enum.js.map +1 -1
- package/dist/types/literal.js +3 -2
- package/dist/types/literal.js.map +1 -1
- package/dist/types/never.js +3 -2
- package/dist/types/never.js.map +1 -1
- package/dist/types/number.js +13 -10
- package/dist/types/number.js.map +1 -1
- package/dist/types/object.js +7 -5
- package/dist/types/object.js.map +1 -1
- package/dist/types/string.js +17 -16
- package/dist/types/string.js.map +1 -1
- package/dist/types/temporal.js +8 -1
- package/dist/types/temporal.js.map +1 -1
- package/dist/types/tuple.js +4 -3
- package/dist/types/tuple.js.map +1 -1
- package/dist/types/type.js +15 -0
- package/dist/types/type.js.map +1 -0
- package/dist/types/union.js +12 -7
- package/dist/types/union.js.map +1 -1
- package/package.json +7 -7
- package/src/index.ts +4 -97
- package/src/temporal.ts +1 -27
- package/src/types/any.ts +5 -3
- package/src/types/array.ts +11 -16
- package/src/types/base.ts +35 -61
- package/src/types/boolean.ts +5 -3
- package/src/types/custom.ts +37 -31
- package/src/types/date.ts +8 -4
- package/src/types/enum.ts +11 -7
- package/src/types/literal.ts +5 -3
- package/src/types/never.ts +5 -3
- package/src/types/number.ts +22 -27
- package/src/types/object.ts +21 -17
- package/src/types/string.ts +32 -48
- package/src/types/temporal.ts +9 -1
- package/src/types/tuple.ts +9 -7
- package/src/types/type.ts +31 -0
- package/src/types/union.ts +25 -21
package/dist/index.js
CHANGED
|
@@ -1,50 +1,8 @@
|
|
|
1
|
-
import * as zod from "
|
|
2
|
-
import
|
|
3
|
-
import { ArrayType } from "./types/array.js";
|
|
4
|
-
import { BooleanType } from "./types/boolean.js";
|
|
5
|
-
import { CustomType } from "./types/custom.js";
|
|
6
|
-
import { DateType } from "./types/date.js";
|
|
7
|
-
import { EnumType } from "./types/enum.js";
|
|
8
|
-
import { LiteralType } from "./types/literal.js";
|
|
9
|
-
import { NeverType } from "./types/never.js";
|
|
10
|
-
import { BigIntType, IntegerType, NumberType } from "./types/number.js";
|
|
11
|
-
import { extend, keyof, merge, ObjectType, omit, partial, pick, RecordType } from "./types/object.js";
|
|
12
|
-
import { StringType } from "./types/string.js";
|
|
13
|
-
import { TupleType } from "./types/tuple.js";
|
|
14
|
-
import { DiscriminatedUnionType, IntersactionType, UnionType } from "./types/union.js";
|
|
1
|
+
import * as zod from "zod/v4-mini";
|
|
2
|
+
import * as type from "./types/type.js";
|
|
15
3
|
zod.config(zod.core.locales.en());
|
|
16
|
-
export
|
|
17
|
-
export {
|
|
18
|
-
export { AnyType, ArrayType, BooleanType, CustomType, DateType, EnumType, LiteralType, IntegerType, NumberType, ObjectType, StringType, IntersactionType, UnionType, TupleType, NeverType, DiscriminatedUnionType, RecordType };
|
|
19
|
-
export const type = {
|
|
20
|
-
never: NeverType.factory,
|
|
21
|
-
boolean: BooleanType.factory,
|
|
22
|
-
string: StringType.factory,
|
|
23
|
-
number: NumberType.factory,
|
|
24
|
-
integer: IntegerType.factory,
|
|
25
|
-
bigint: BigIntType.factory,
|
|
26
|
-
literal: LiteralType.factory,
|
|
27
|
-
enum: EnumType.factory,
|
|
28
|
-
tuple: TupleType.factory,
|
|
29
|
-
date: DateType.factory,
|
|
30
|
-
array: ArrayType.factory,
|
|
31
|
-
record: RecordType.factory,
|
|
32
|
-
any: AnyType.factory,
|
|
33
|
-
or: UnionType.factory,
|
|
34
|
-
and: IntersactionType.factory,
|
|
35
|
-
union: UnionType.factory,
|
|
36
|
-
intersaction: IntersactionType.factory,
|
|
37
|
-
discriminatedUnion: DiscriminatedUnionType.factory,
|
|
38
|
-
custom: CustomType.factory,
|
|
39
|
-
object: ObjectType.factory,
|
|
40
|
-
keyof,
|
|
41
|
-
partial,
|
|
42
|
-
merge,
|
|
43
|
-
omit,
|
|
44
|
-
extend,
|
|
45
|
-
pick
|
|
46
|
-
};
|
|
47
|
-
export { type as t, zod };
|
|
4
|
+
export * from "./types/base.js";
|
|
5
|
+
export { type, type as t };
|
|
48
6
|
export default type;
|
|
49
7
|
|
|
50
8
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAAA,YAAY,SAAS,
|
|
1
|
+
{"mappings":"AAAA,YAAY,SAAS,aAAa;AAClC,YAAY,UAAU,iBAAiB;AAEvC,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC;AAEjC,cAAc;AACd,SAAS,MAAM,QAAQ;AACvB,eAAe","names":[],"sources":["../src/index.ts"],"sourcesContent":["import * as zod from 'zod/v4-mini'\nimport * as type from './types/type.ts'\n\nzod.config(zod.core.locales.en())\n\nexport * from './types/base.ts'\nexport { type, type as t }\nexport default type\n"],"version":3,"file":"index.js"}
|
package/dist/temporal.js
CHANGED
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
export const plainDate = PlainDateType.factory;
|
|
3
|
-
export const plainDatetime = PlainDateTimeType.factory;
|
|
4
|
-
export const plainTime = PlainTimeType.factory;
|
|
5
|
-
export const zonedDatetime = ZonedDateTimeType.factory;
|
|
6
|
-
export const duration = DurationType.factory;
|
|
7
|
-
export const plainYearMonth = PlainYearMonthType.factory;
|
|
8
|
-
export const plainMonthDay = PlainMonthDayType.factory;
|
|
1
|
+
export * from "./types/temporal.js";
|
|
9
2
|
|
|
10
3
|
//# sourceMappingURL=temporal.js.map
|
package/dist/temporal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAAA,
|
|
1
|
+
{"mappings":"AAAA,cAAc","names":[],"sources":["../src/temporal.ts"],"sourcesContent":["export * from './types/temporal.ts'\n"],"version":3,"file":"temporal.js"}
|
package/dist/types/any.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as zod from "zod/v4-mini";
|
|
2
2
|
import { BaseType } from "./base.js";
|
|
3
3
|
export class AnyType extends BaseType {
|
|
4
4
|
static factory() {
|
|
5
|
-
return new AnyType({ encodedZodType: any() });
|
|
5
|
+
return new AnyType({ encodedZodType: zod.any() });
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
|
+
export const any = AnyType.factory;
|
|
8
9
|
|
|
9
10
|
//# sourceMappingURL=any.js.map
|
package/dist/types/any.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAAA,SAAS,
|
|
1
|
+
{"mappings":"AAAA,YAAY,SAAS,aAAa;AAClC,SAAS,gBAAgB,WAAW;AAEpC,OAAO,MAAM,gBAAgB,SAAyB;CACpD,OAAO,UAAU;AACf,SAAO,IAAI,QAAQ,EACjB,gBAAgB,IAAI,KAAK,CAC1B;CACF;AACF;AAED,OAAO,MAAM,MAAM,QAAQ","names":[],"sources":["../../src/types/any.ts"],"sourcesContent":["import * as zod from 'zod/v4-mini'\nimport { BaseType } from './base.ts'\n\nexport class AnyType extends BaseType<zod.ZodMiniAny> {\n static factory() {\n return new AnyType({\n encodedZodType: zod.any(),\n })\n }\n}\n\nexport const any = AnyType.factory\n"],"version":3,"file":"any.js"}
|
package/dist/types/array.js
CHANGED
|
@@ -1,26 +1,27 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as zod from "zod/v4-mini";
|
|
2
2
|
import { BaseType } from "./base.js";
|
|
3
3
|
export class ArrayType extends BaseType {
|
|
4
4
|
static factory(element, ...checks) {
|
|
5
5
|
return new ArrayType({
|
|
6
|
-
encodedZodType: array(element.encodedZodType).check(...checks),
|
|
7
|
-
decodedZodType: array(element.decodedZodType).check(...checks),
|
|
6
|
+
encodedZodType: zod.array(element.encodedZodType).check(...checks),
|
|
7
|
+
decodedZodType: zod.array(element.decodedZodType).check(...checks),
|
|
8
8
|
params: { checks },
|
|
9
9
|
props: { element }
|
|
10
10
|
});
|
|
11
11
|
}
|
|
12
12
|
min(value) {
|
|
13
|
-
const check = minLength(value);
|
|
13
|
+
const check = zod.minLength(value);
|
|
14
14
|
return ArrayType.factory(this.props.element, ...this.params.checks, check);
|
|
15
15
|
}
|
|
16
16
|
max(value) {
|
|
17
|
-
const check = maxLength(value);
|
|
17
|
+
const check = zod.maxLength(value);
|
|
18
18
|
return ArrayType.factory(this.props.element, ...this.params.checks, check);
|
|
19
19
|
}
|
|
20
20
|
length(value) {
|
|
21
|
-
const check = length(value);
|
|
21
|
+
const check = zod.length(value);
|
|
22
22
|
return ArrayType.factory(this.props.element, ...this.params.checks, check);
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
+
export const array = ArrayType.factory;
|
|
25
26
|
|
|
26
27
|
//# sourceMappingURL=array.js.map
|
package/dist/types/array.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAAA,
|
|
1
|
+
{"mappings":"AAAA,YAAY,SAAS,aAAa;AAClC,SAAS,gBAAgB,WAAW;AAIpC,OAAO,MAAM,kBAAiD,SAI5D;CACA,OAAO,QAA4BA,SAAY,GAAG,QAAiB;AACjE,SAAO,IAAI,UAAa;GACtB,gBAAgB,IAAI,MAAM,QAAQ,eAAe,CAAC,MAAM,GAAG,OAAO;GAClE,gBAAgB,IAAI,MAAM,QAAQ,eAAe,CAAC,MAAM,GAAG,OAAO;GAClE,QAAQ,EAAE,OAAQ;GAClB,OAAO,EAAE,QAAS;EACnB;CACF;CAED,IAAIC,OAAe;EACjB,MAAM,QAAQ,IAAI,UAAU,MAAM;AAClC,SAAO,UAAU,QACf,KAAK,MAAM,SACX,GAAG,KAAK,OAAO,QACf,MACD;CACF;CAED,IAAIA,OAAe;EACjB,MAAM,QAAQ,IAAI,UAAU,MAAM;AAClC,SAAO,UAAU,QACf,KAAK,MAAM,SACX,GAAG,KAAK,OAAO,QACf,MACD;CACF;CAED,OAAOA,OAAe;EACpB,MAAM,QAAQ,IAAI,OAAO,MAAM;AAC/B,SAAO,UAAU,QACf,KAAK,MAAM,SACX,GAAG,KAAK,OAAO,QACf,MACD;CACF;AACF;AAED,OAAO,MAAM,QAAQ,UAAU","names":["element: T","value: number"],"sources":["../../src/types/array.ts"],"sourcesContent":["import * as zod from 'zod/v4-mini'\nimport { BaseType } from './base.ts'\n\ntype Check = zod.core.CheckFn<any[]> | zod.core.$ZodCheck<any[]>\n\nexport class ArrayType<T extends BaseType = BaseType> extends BaseType<\n zod.ZodMiniArray<T['encodedZodType']>,\n zod.ZodMiniArray<T['decodedZodType']>,\n { element: T }\n> {\n static factory<T extends BaseType>(element: T, ...checks: Check[]) {\n return new ArrayType<T>({\n encodedZodType: zod.array(element.encodedZodType).check(...checks),\n decodedZodType: zod.array(element.decodedZodType).check(...checks),\n params: { checks },\n props: { element },\n })\n }\n\n min(value: number) {\n const check = zod.minLength(value)\n return ArrayType.factory<T>(\n this.props.element,\n ...this.params.checks,\n check,\n )\n }\n\n max(value: number) {\n const check = zod.maxLength(value)\n return ArrayType.factory<T>(\n this.props.element,\n ...this.params.checks,\n check,\n )\n }\n\n length(value: number) {\n const check = zod.length(value)\n return ArrayType.factory<T>(\n this.props.element,\n ...this.params.checks,\n check,\n )\n }\n}\n\nexport const array = ArrayType.factory\n"],"version":3,"file":"array.js"}
|
package/dist/types/base.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
export const typesRegistry = registry();
|
|
3
|
-
export const NeemataTypeError = core.$ZodError;
|
|
1
|
+
import * as zod from "zod/v4-mini";
|
|
2
|
+
export const typesRegistry = zod.registry();
|
|
3
|
+
export const NeemataTypeError = zod.core.$ZodError;
|
|
4
4
|
export class BaseType {
|
|
5
5
|
encodedZodType;
|
|
6
6
|
decodedZodType;
|
|
@@ -49,7 +49,7 @@ export class BaseType {
|
|
|
49
49
|
export class OptionalType extends BaseType {
|
|
50
50
|
static factory(type) {
|
|
51
51
|
return new OptionalType({
|
|
52
|
-
encodedZodType: optional(type.encodedZodType),
|
|
52
|
+
encodedZodType: zod.optional(type.encodedZodType),
|
|
53
53
|
props: { inner: type }
|
|
54
54
|
});
|
|
55
55
|
}
|
|
@@ -57,7 +57,7 @@ export class OptionalType extends BaseType {
|
|
|
57
57
|
export class NullableType extends BaseType {
|
|
58
58
|
static factory(type) {
|
|
59
59
|
return new NullableType({
|
|
60
|
-
encodedZodType: nullable(type.encodedZodType),
|
|
60
|
+
encodedZodType: zod.nullable(type.encodedZodType),
|
|
61
61
|
props: { inner: type }
|
|
62
62
|
});
|
|
63
63
|
}
|
|
@@ -65,8 +65,8 @@ export class NullableType extends BaseType {
|
|
|
65
65
|
export class DefaultType extends BaseType {
|
|
66
66
|
static factory(type, defaultValue) {
|
|
67
67
|
return new DefaultType({
|
|
68
|
-
encodedZodType: _default(type.encodedZodType, type.params.encode?.(defaultValue) ?? defaultValue),
|
|
69
|
-
decodedZodType: _default(type.decodedZodType, defaultValue),
|
|
68
|
+
encodedZodType: zod._default(type.encodedZodType, type.params.encode?.(defaultValue) ?? defaultValue),
|
|
69
|
+
decodedZodType: zod._default(type.decodedZodType, defaultValue),
|
|
70
70
|
props: { inner: type }
|
|
71
71
|
});
|
|
72
72
|
}
|
package/dist/types/base.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAAA,
|
|
1
|
+
{"mappings":"AAAA,YAAY,SAAS,aAAa;AAkDlC,OAAO,MAAM,gBAAgB,IAAI,UAAwB;AAEzD,OAAO,MAAM,mBAAmB,IAAI,KAAK;AAGzC,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,IAAI,SAAS,KAAK,eAAe;GACjD,OAAO,EAAE,OAAO,KAAM;EACvB;CACF;AACF;AAED,OAAO,MAAM,qBAEH,SAIR;CACA,OAAO,QAAoCA,MAAS;AAClD,SAAO,IAAI,aAAgB;GACzB,gBAAgB,IAAI,SAAS,KAAK,eAAe;GACjD,OAAO,EAAE,OAAO,KAAM;EACvB;CACF;AACF;AAED,OAAO,MAAM,oBAEH,SAIR;CACA,OAAO,QAAoCA,MAASC,cAAmB;AACrE,SAAO,IAAI,YAAe;GACxB,gBAAgB,IAAI,SAClB,KAAK,gBACL,KAAK,OAAO,SAAS,aAAa,IAAI,aACvC;GACD,gBAAgB,IAAI,SAAS,KAAK,gBAAgB,aAAa;GAC/D,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 * as zod from 'zod/v4-mini'\n\nexport type PrimitiveValueType = string | number | boolean | null\n\nexport type PrimitiveZodType =\n | zod.ZodMiniNever\n | zod.ZodMiniDefault\n | zod.ZodMiniNullable\n | zod.ZodMiniOptional\n | zod.ZodMiniString\n | zod.ZodMiniObject\n | zod.ZodMiniAny\n | zod.ZodMiniArray\n | zod.ZodMiniBoolean\n | zod.ZodMiniNumber\n | zod.ZodMiniEnum<any>\n | zod.ZodMiniLiteral<PrimitiveValueType>\n | zod.ZodMiniUnion\n | zod.ZodMiniIntersection\n | zod.ZodMiniRecord\n\nexport type SimpleZodType = zod.ZodMiniType\n\nexport type ZodType = SimpleZodType | zod.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<zod.core.CheckFn<any> | zod.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 = zod.ZodMiniType,\n> = BaseType<EncodedZodType, DecodedZodType, TypeProps>\n\nexport const typesRegistry = zod.registry<TypeMetadata>()\n\nexport const NeemataTypeError = zod.core.$ZodError\nexport type NeemataTypeError = zod.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 zod.ZodMiniOptional<Type['encodedZodType']>,\n zod.ZodMiniOptional<Type['decodedZodType']>,\n { inner: Type }\n> {\n static factory<T extends BaseTypeAny>(type: T) {\n return new OptionalType<T>({\n encodedZodType: zod.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 zod.ZodMiniNullable<Type['encodedZodType']>,\n zod.ZodMiniNullable<Type['decodedZodType']>,\n { inner: Type }\n> {\n static factory<T extends BaseTypeAny<any>>(type: T) {\n return new NullableType<T>({\n encodedZodType: zod.nullable(type.encodedZodType),\n props: { inner: type },\n })\n }\n}\n\nexport class DefaultType<\n Type extends BaseTypeAny = BaseTypeAny,\n> extends BaseType<\n zod.ZodMiniDefault<Type['encodedZodType']>,\n zod.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: zod._default(\n type.encodedZodType,\n type.params.encode?.(defaultValue) ?? defaultValue,\n ) as any,\n decodedZodType: zod._default(type.decodedZodType, defaultValue) as any,\n props: { inner: type },\n })\n }\n}\n"],"version":3,"file":"base.js"}
|
package/dist/types/boolean.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as zod from "zod/v4-mini";
|
|
2
2
|
import { BaseType } from "./base.js";
|
|
3
3
|
export class BooleanType extends BaseType {
|
|
4
4
|
static factory() {
|
|
5
|
-
return new BooleanType({ encodedZodType: boolean() });
|
|
5
|
+
return new BooleanType({ encodedZodType: zod.boolean() });
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
|
+
export const boolean = BooleanType.factory;
|
|
8
9
|
|
|
9
10
|
//# sourceMappingURL=boolean.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAAA,SAAS,
|
|
1
|
+
{"mappings":"AAAA,YAAY,SAAS,aAAa;AAClC,SAAS,gBAAgB,WAAW;AAEpC,OAAO,MAAM,oBAAoB,SAAsC;CACrE,OAAO,UAAU;AACf,SAAO,IAAI,YAAY,EACrB,gBAAgB,IAAI,SAAS,CAC9B;CACF;AACF;AAED,OAAO,MAAM,UAAU,YAAY","names":[],"sources":["../../src/types/boolean.ts"],"sourcesContent":["import * as zod from 'zod/v4-mini'\nimport { BaseType } from './base.ts'\n\nexport class BooleanType extends BaseType<zod.ZodMiniBoolean<boolean>> {\n static factory() {\n return new BooleanType({\n encodedZodType: zod.boolean(),\n })\n }\n}\n\nexport const boolean = BooleanType.factory\n"],"version":3,"file":"boolean.js"}
|
package/dist/types/custom.js
CHANGED
|
@@ -1,20 +1,25 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as zod from "zod/v4-mini";
|
|
2
2
|
import { BaseType } from "./base.js";
|
|
3
3
|
export class TransformType extends BaseType {}
|
|
4
4
|
export class CustomType extends TransformType {
|
|
5
|
-
static factory({ decode, encode, error, type = any() }) {
|
|
5
|
+
static factory({ decode, encode, error, type = zod.any() }) {
|
|
6
6
|
return new CustomType({
|
|
7
|
-
encodedZodType: pipe(custom().check(refine((val) => typeof val !== "undefined", {
|
|
7
|
+
encodedZodType: zod.pipe(zod.custom().check(zod.refine((val) => typeof val !== "undefined", {
|
|
8
8
|
error,
|
|
9
9
|
abort: true
|
|
10
|
-
}), overwrite(encode)), type),
|
|
11
|
-
decodedZodType: pipe(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
}), zod.overwrite(encode)), type),
|
|
11
|
+
decodedZodType: zod.pipe(
|
|
12
|
+
type,
|
|
13
|
+
// @ts-expect-error
|
|
14
|
+
zod.custom().check(zod.refine((val) => typeof val !== "undefined", {
|
|
15
|
+
error,
|
|
16
|
+
abort: true
|
|
17
|
+
}), zod.overwrite(decode))
|
|
18
|
+
),
|
|
15
19
|
params: { encode }
|
|
16
20
|
});
|
|
17
21
|
}
|
|
18
22
|
}
|
|
23
|
+
export const custom = CustomType.factory;
|
|
19
24
|
|
|
20
25
|
//# sourceMappingURL=custom.js.map
|
package/dist/types/custom.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAAA,
|
|
1
|
+
{"mappings":"AAAA,YAAY,SAAS,aAAa;AAClC,SAAS,gBAAkD,WAAW;AAGtE,OAAO,MAAe,sBAIZ,SAYR,CAAE;AAEJ,OAAO,MAAM,mBAIH,cAA8C;CACtD,OAAO,QAIL,EACA,QACA,QACA,OACA,OAAO,IAAI,KAAK,EAYjB,EAAE;AACD,SAAO,IAAI,WAA2C;GACpD,gBAAgB,IAAI,KAClB,IAAI,QAAQ,CAAC,MACX,IAAI,OAAO,CAAC,eAAe,QAAQ,aAAa;IAC9C;IACA,OAAO;GACR,EAAC,EACF,IAAI,UAAU,OAAO,CACtB,EACD,KACD;GAED,gBAAgB,IAAI;IAClB;;IAEA,IACG,QAAQ,CACR,MACC,IAAI,OAAO,CAAC,eAAe,QAAQ,aAAa;KAC9C;KACA,OAAO;IACR,EAAC,EACF,IAAI,UAAU,OAAO,CACtB;CACJ;GACD,QAAQ,EAAE,OAAQ;EACnB;CACF;AACF;AAED,OAAO,MAAM,SAAS,WAAW","names":[],"sources":["../../src/types/custom.ts"],"sourcesContent":["import * as zod from 'zod/v4-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 = zod.ZodMiniType<Type, Type>,\n DecodedType extends ZodType = zod.ZodMiniType<Type, Type>,\n> extends BaseType<\n zod.ZodMiniPipe<\n zod.ZodMiniType<\n DecodedType['_zod']['output'],\n DecodedType['_zod']['input']\n >,\n EncodedType\n >,\n zod.ZodMiniPipe<\n EncodedType,\n zod.ZodMiniType<EncodedType['_zod']['output'], EncodedType['_zod']['input']>\n >\n> {}\n\nexport class CustomType<\n Type,\n EncodedType extends SimpleZodType = zod.ZodMiniType<Type, Type>,\n DecodedType extends ZodType = zod.ZodMiniType<Type, Type>,\n> extends TransformType<Type, EncodedType, DecodedType> {\n static factory<\n Type,\n EncodedType extends SimpleZodType = zod.ZodMiniType<Type, Type>,\n DecodedType extends ZodType = zod.ZodMiniType<Type, Type>,\n >({\n decode,\n encode,\n error,\n type = zod.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 | zod.core.$ZodErrorMap<zod.core.$ZodIssueBase>\n type?: EncodedType\n }) {\n return new CustomType<Type, EncodedType, DecodedType>({\n encodedZodType: zod.pipe(\n zod.custom().check(\n zod.refine((val) => typeof val !== 'undefined', {\n error,\n abort: true,\n }),\n zod.overwrite(encode),\n ),\n type,\n ),\n // @ts-expect-error\n decodedZodType: zod.pipe(\n type,\n // @ts-expect-error\n zod\n .custom()\n .check(\n zod.refine((val) => typeof val !== 'undefined', {\n error,\n abort: true,\n }),\n zod.overwrite(decode),\n ),\n ),\n params: { encode },\n })\n }\n}\n\nexport const custom = CustomType.factory\n"],"version":3,"file":"custom.js"}
|
package/dist/types/date.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as zod from "zod/v4-mini";
|
|
2
2
|
import { CustomType, TransformType } from "./custom.js";
|
|
3
3
|
export class DateType extends TransformType {
|
|
4
4
|
static factory() {
|
|
5
5
|
return CustomType.factory({
|
|
6
6
|
decode: (value) => new Date(value),
|
|
7
7
|
encode: (value) => value.toISOString(),
|
|
8
|
-
type: union([iso.datetime(), iso.date()])
|
|
8
|
+
type: zod.union([zod.iso.datetime(), zod.iso.date()])
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
|
+
export const date = DateType.factory;
|
|
12
13
|
|
|
13
14
|
//# sourceMappingURL=date.js.map
|
package/dist/types/date.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAAA,SAAS,
|
|
1
|
+
{"mappings":"AAAA,YAAY,SAAS,aAAa;AAClC,SAAS,YAAY,qBAAqB,aAAa;AAEvD,OAAO,MAAM,iBAAiB,cAG5B;CACA,OAAO,UAAU;AACf,SAAO,WAAW,QAKhB;GACA,QAAQ,CAACA,UAAwB,IAAI,KAAK;GAC1C,QAAQ,CAACC,UAAwB,MAAM,aAAa;GACpD,MAAM,IAAI,MAAM,CAAC,IAAI,IAAI,UAAU,EAAE,IAAI,IAAI,MAAM,AAAC,EAAC;EACtD,EAAC;CACH;AACF;AAED,OAAO,MAAM,OAAO,SAAS","names":["value: string","value: Date"],"sources":["../../src/types/date.ts"],"sourcesContent":["import * as zod from 'zod/v4-mini'\nimport { CustomType, TransformType } from './custom.ts'\n\nexport class DateType extends TransformType<\n Date,\n zod.ZodMiniUnion<[zod.iso.ZodMiniISODate, zod.iso.ZodMiniISODateTime]>\n> {\n static factory() {\n return CustomType.factory<\n Date,\n zod.ZodMiniUnion<\n Array<zod.iso.ZodMiniISODate | zod.iso.ZodMiniISODateTime>\n >\n >({\n decode: (value: string): Date => new Date(value),\n encode: (value: Date): string => value.toISOString(),\n type: zod.union([zod.iso.datetime(), zod.iso.date()]),\n })\n }\n}\n\nexport const date = DateType.factory\n"],"version":3,"file":"date.js"}
|
package/dist/types/enum.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as zod from "zod/v4-mini";
|
|
2
2
|
import { BaseType } from "./base.js";
|
|
3
3
|
export class EnumType extends BaseType {
|
|
4
4
|
static factory(values) {
|
|
5
5
|
return new EnumType({
|
|
6
|
-
encodedZodType:
|
|
6
|
+
encodedZodType: zod.enum(values),
|
|
7
7
|
props: { values }
|
|
8
8
|
});
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
+
const _enum = EnumType.factory;
|
|
12
|
+
export { _enum as enum };
|
|
11
13
|
|
|
12
14
|
//# sourceMappingURL=enum.js.map
|
package/dist/types/enum.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAAA,
|
|
1
|
+
{"mappings":"AAAA,YAAY,SAAS,aAAa;AAClC,SAAS,gBAAgB,WAAW;AAEpC,OAAO,MAAM,iBAEH,SAAgE;CAKxE,OAAO,QAAqDA,QAAW;AACrE,SAAO,IAAI,SAAS;GAClB,gBAAgB,IAAI,KAAK,OAAc;GACvC,OAAO,EAAE,OAAQ;EAClB;CACF;AACF;AAED,MAAM,QAAQ,SAAS;AAEvB,SAAS,SAAS","names":["values: T"],"sources":["../../src/types/enum.ts"],"sourcesContent":["import * as zod from 'zod/v4-mini'\nimport { BaseType } from './base.ts'\n\nexport class EnumType<\n T extends zod.core.util.EnumLike = zod.core.util.EnumLike,\n> extends BaseType<zod.ZodMiniEnum<T>, zod.ZodMiniEnum<T>, { values: T }> {\n static factory<T extends zod.core.util.EnumLike>(values: T): EnumType<T>\n static factory<T extends string[]>(\n values: T,\n ): EnumType<zod.core.util.ToEnum<T[number]>>\n static factory<T extends zod.core.util.EnumLike | string[]>(values: T) {\n return new EnumType({\n encodedZodType: zod.enum(values as any),\n props: { values },\n })\n }\n}\n\nconst _enum = EnumType.factory\n\nexport { _enum as enum }\n"],"version":3,"file":"enum.js"}
|
package/dist/types/literal.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as zod from "zod/v4-mini";
|
|
2
2
|
import { BaseType } from "./base.js";
|
|
3
3
|
export class LiteralType extends BaseType {
|
|
4
4
|
static factory(value) {
|
|
5
5
|
return new LiteralType({
|
|
6
|
-
encodedZodType: literal(value),
|
|
6
|
+
encodedZodType: zod.literal(value),
|
|
7
7
|
props: { value }
|
|
8
8
|
});
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
+
export const literal = LiteralType.factory;
|
|
11
12
|
|
|
12
13
|
//# sourceMappingURL=literal.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAAA,SAAS,
|
|
1
|
+
{"mappings":"AAAA,YAAY,SAAS,aAAa;AAClC,SAAS,gBAAyC,WAAW;AAE7D,OAAO,MAAM,oBAEH,SAAqE;CAC7E,OAAO,QAAsCA,OAAU;AACrD,SAAO,IAAI,YAAe;GACxB,gBAAgB,IAAI,QAAQ,MAAM;GAClC,OAAO,EAAE,MAAO;EACjB;CACF;AACF;AAED,OAAO,MAAM,UAAU,YAAY","names":["value: T"],"sources":["../../src/types/literal.ts"],"sourcesContent":["import * as zod from 'zod/v4-mini'\nimport { BaseType, type PrimitiveValueType } from './base.ts'\n\nexport class LiteralType<\n T extends PrimitiveValueType = PrimitiveValueType,\n> extends BaseType<zod.ZodMiniLiteral<T>, zod.ZodMiniLiteral<T>, { value: T }> {\n static factory<T extends PrimitiveValueType>(value: T) {\n return new LiteralType<T>({\n encodedZodType: zod.literal(value),\n props: { value },\n })\n }\n}\n\nexport const literal = LiteralType.factory\n"],"version":3,"file":"literal.js"}
|
package/dist/types/never.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as zod from "zod/v4-mini";
|
|
2
2
|
import { BaseType } from "./base.js";
|
|
3
3
|
export class NeverType extends BaseType {
|
|
4
4
|
static factory() {
|
|
5
|
-
return new NeverType({ encodedZodType: never() });
|
|
5
|
+
return new NeverType({ encodedZodType: zod.never() });
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
|
+
export const never = NeverType.factory;
|
|
8
9
|
|
|
9
10
|
//# sourceMappingURL=never.js.map
|
package/dist/types/never.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAAA,SAAS,
|
|
1
|
+
{"mappings":"AAAA,YAAY,SAAS,aAAa;AAClC,SAAS,gBAAgB,WAAW;AAEpC,OAAO,MAAM,kBAAkB,SAA2B;CACxD,OAAO,UAAU;AACf,SAAO,IAAI,UAAU,EACnB,gBAAgB,IAAI,OAAO,CAC5B;CACF;AACF;AAED,OAAO,MAAM,QAAQ,UAAU","names":[],"sources":["../../src/types/never.ts"],"sourcesContent":["import * as zod from 'zod/v4-mini'\nimport { BaseType } from './base.ts'\n\nexport class NeverType extends BaseType<zod.ZodMiniNever> {\n static factory() {\n return new NeverType({\n encodedZodType: zod.never(),\n })\n }\n}\n\nexport const never = NeverType.factory\n"],"version":3,"file":"never.js"}
|
package/dist/types/number.js
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as zod from "zod/v4-mini";
|
|
2
2
|
import { BaseType } from "./base.js";
|
|
3
3
|
import { CustomType, TransformType } from "./custom.js";
|
|
4
4
|
export class NumberType extends BaseType {
|
|
5
5
|
static factory(...checks) {
|
|
6
6
|
return new NumberType({
|
|
7
|
-
encodedZodType: number().check(...checks),
|
|
7
|
+
encodedZodType: zod.number().check(...checks),
|
|
8
8
|
params: { checks }
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
11
|
positive() {
|
|
12
|
-
return NumberType.factory(...this.params.checks, gte(0));
|
|
12
|
+
return NumberType.factory(...this.params.checks, zod.gte(0));
|
|
13
13
|
}
|
|
14
14
|
negative() {
|
|
15
|
-
return NumberType.factory(...this.params.checks, lte(0));
|
|
15
|
+
return NumberType.factory(...this.params.checks, zod.lte(0));
|
|
16
16
|
}
|
|
17
17
|
lt(value) {
|
|
18
|
-
return NumberType.factory(...this.params.checks, lt(value));
|
|
18
|
+
return NumberType.factory(...this.params.checks, zod.lt(value));
|
|
19
19
|
}
|
|
20
20
|
lte(value) {
|
|
21
|
-
return NumberType.factory(...this.params.checks, lte(value));
|
|
21
|
+
return NumberType.factory(...this.params.checks, zod.lte(value));
|
|
22
22
|
}
|
|
23
23
|
gte(value) {
|
|
24
|
-
return NumberType.factory(...this.params.checks, gte(value));
|
|
24
|
+
return NumberType.factory(...this.params.checks, zod.gte(value));
|
|
25
25
|
}
|
|
26
26
|
gt(value) {
|
|
27
|
-
return NumberType.factory(...this.params.checks, gt(value));
|
|
27
|
+
return NumberType.factory(...this.params.checks, zod.gt(value));
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
export class IntegerType extends NumberType {
|
|
31
31
|
static factory(...checks) {
|
|
32
|
-
return NumberType.factory(...checks, int());
|
|
32
|
+
return NumberType.factory(...checks, zod.int());
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
export class BigIntType extends TransformType {
|
|
@@ -37,10 +37,13 @@ export class BigIntType extends TransformType {
|
|
|
37
37
|
return CustomType.factory({
|
|
38
38
|
decode: (value) => BigInt(value),
|
|
39
39
|
encode: (value) => value.toString(),
|
|
40
|
-
type: string().check(regex(/^-?\d+$/)),
|
|
40
|
+
type: zod.string().check(zod.regex(/^-?\d+$/)),
|
|
41
41
|
error: "Invalid bigint format"
|
|
42
42
|
});
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
|
+
export const number = NumberType.factory;
|
|
46
|
+
export const integer = IntegerType.factory;
|
|
47
|
+
export const bigInt = BigIntType.factory;
|
|
45
48
|
|
|
46
49
|
//# sourceMappingURL=number.js.map
|
package/dist/types/number.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAAA,
|
|
1
|
+
{"mappings":"AAAA,YAAY,SAAS,aAAa;AAClC,SAAS,gBAAgB,WAAW;AACpC,SAAS,YAAY,qBAAqB,aAAa;AAIvD,OAAO,MAAM,mBAAmB,SAG9B;CACA,OAAO,QAAQ,GAAG,QAAiB;AACjC,SAAO,IAAI,WAAW;GACpB,gBAAgB,IAAI,QAAQ,CAAC,MAAM,GAAG,OAAO;GAC7C,QAAQ,EAAE,OAAQ;EACnB;CACF;CAED,WAAW;AACT,SAAO,WAAW,QAAQ,GAAG,KAAK,OAAO,QAAQ,IAAI,IAAI,EAAE,CAAC;CAC7D;CAED,WAAW;AACT,SAAO,WAAW,QAAQ,GAAG,KAAK,OAAO,QAAQ,IAAI,IAAI,EAAE,CAAC;CAC7D;CAED,GAAGA,OAAe;AAChB,SAAO,WAAW,QAAQ,GAAG,KAAK,OAAO,QAAQ,IAAI,GAAG,MAAM,CAAC;CAChE;CAED,IAAIA,OAAe;AACjB,SAAO,WAAW,QAAQ,GAAG,KAAK,OAAO,QAAQ,IAAI,IAAI,MAAM,CAAC;CACjE;CAED,IAAIA,OAAe;AACjB,SAAO,WAAW,QAAQ,GAAG,KAAK,OAAO,QAAQ,IAAI,IAAI,MAAM,CAAC;CACjE;CAED,GAAGA,OAAe;AAChB,SAAO,WAAW,QAAQ,GAAG,KAAK,OAAO,QAAQ,IAAI,GAAG,MAAM,CAAC;CAChE;AACF;AAED,OAAO,MAAM,oBAAoB,WAAW;CAC1C,OAAO,QAAQ,GAAG,QAAiB;AACjC,SAAO,WAAW,QAAQ,GAAG,QAAQ,IAAI,KAAK,CAAC;CAChD;AACF;AAED,OAAO,MAAM,mBAAmB,cAG9B;CACA,OAAO,UAAU;AACf,SAAO,WAAW,QAA2C;GAC3D,QAAQ,CAAC,UAAU,OAAO,MAAM;GAChC,QAAQ,CAAC,UAAU,MAAM,UAAU;GACnC,MAAM,IAAI,QAAQ,CAAC,MAAM,IAAI,MAAM,UAAU,CAAC;GAC9C,OAAO;EACR,EAAC;CACH;AACF;AAED,OAAO,MAAM,SAAS,WAAW;AACjC,OAAO,MAAM,UAAU,YAAY;AACnC,OAAO,MAAM,SAAS,WAAW","names":["value: number"],"sources":["../../src/types/number.ts"],"sourcesContent":["import * as zod from 'zod/v4-mini'\nimport { BaseType } from './base.ts'\nimport { CustomType, TransformType } from './custom.ts'\n\ntype Check = zod.core.CheckFn<number> | zod.core.$ZodCheck<number>\n\nexport class NumberType extends BaseType<\n zod.ZodMiniNumber<number>,\n zod.ZodMiniNumber<number>\n> {\n static factory(...checks: Check[]) {\n return new NumberType({\n encodedZodType: zod.number().check(...checks),\n params: { checks },\n })\n }\n\n positive() {\n return NumberType.factory(...this.params.checks, zod.gte(0))\n }\n\n negative() {\n return NumberType.factory(...this.params.checks, zod.lte(0))\n }\n\n lt(value: number) {\n return NumberType.factory(...this.params.checks, zod.lt(value))\n }\n\n lte(value: number) {\n return NumberType.factory(...this.params.checks, zod.lte(value))\n }\n\n gte(value: number) {\n return NumberType.factory(...this.params.checks, zod.gte(value))\n }\n\n gt(value: number) {\n return NumberType.factory(...this.params.checks, zod.gt(value))\n }\n}\n\nexport class IntegerType extends NumberType {\n static factory(...checks: Check[]) {\n return NumberType.factory(...checks, zod.int())\n }\n}\n\nexport class BigIntType extends TransformType<\n bigint,\n zod.ZodMiniString<string>\n> {\n static factory() {\n return CustomType.factory<bigint, zod.ZodMiniString<string>>({\n decode: (value) => BigInt(value),\n encode: (value) => value.toString(),\n type: zod.string().check(zod.regex(/^-?\\d+$/)),\n error: 'Invalid bigint format',\n })\n }\n}\n\nexport const number = NumberType.factory\nexport const integer = IntegerType.factory\nexport const bigInt = BigIntType.factory\n"],"version":3,"file":"number.js"}
|
package/dist/types/object.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as zod from "zod/v4-mini";
|
|
2
2
|
import { BaseType } from "./base.js";
|
|
3
3
|
import { EnumType } from "./enum.js";
|
|
4
4
|
export class ObjectType extends BaseType {
|
|
@@ -10,8 +10,8 @@ export class ObjectType extends BaseType {
|
|
|
10
10
|
decodeProperties[key] = properties[key].decodedZodType;
|
|
11
11
|
}
|
|
12
12
|
return new ObjectType({
|
|
13
|
-
encodedZodType: object(encodeProperties),
|
|
14
|
-
decodedZodType: object(decodeProperties),
|
|
13
|
+
encodedZodType: zod.object(encodeProperties),
|
|
14
|
+
decodedZodType: zod.object(decodeProperties),
|
|
15
15
|
props: { properties }
|
|
16
16
|
});
|
|
17
17
|
}
|
|
@@ -19,8 +19,8 @@ export class ObjectType extends BaseType {
|
|
|
19
19
|
export class RecordType extends BaseType {
|
|
20
20
|
static factory(key, element) {
|
|
21
21
|
return new RecordType({
|
|
22
|
-
encodedZodType: record(key.encodedZodType, element.encodedZodType),
|
|
23
|
-
decodedZodType: record(key.decodedZodType, element.decodedZodType),
|
|
22
|
+
encodedZodType: zod.record(key.encodedZodType, element.encodedZodType),
|
|
23
|
+
decodedZodType: zod.record(key.decodedZodType, element.decodedZodType),
|
|
24
24
|
props: {
|
|
25
25
|
key,
|
|
26
26
|
element
|
|
@@ -58,5 +58,7 @@ export function partial(object) {
|
|
|
58
58
|
}
|
|
59
59
|
return ObjectType.factory(properties);
|
|
60
60
|
}
|
|
61
|
+
export const object = ObjectType.factory;
|
|
62
|
+
export const record = RecordType.factory;
|
|
61
63
|
|
|
62
64
|
//# sourceMappingURL=object.js.map
|
package/dist/types/object.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAAA,
|
|
1
|
+
{"mappings":"AAAA,YAAY,SAAS,aAAa;AAElC,SAAS,gBAAqD,WAAW;AACzE,SAAS,gBAAgB,WAAW;AAMpC,OAAO,MAAM,mBAAmD,SAU9D;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,IAAI,OAAO,iBAAiB;GAC5C,gBAAgB,IAAI,OAAO,iBAAiB;GAC5C,OAAO,EAAE,WAAY;EACtB;CACF;AACF;AAED,OAAO,MAAM,mBAGH,SAGR;CACA,OAAO,QAGLC,KAAQC,SAAY;AACpB,SAAO,IAAI,WAAiB;GAC1B,gBAAgB,IAAI,OACjB,IAAY,gBACb,QAAQ,eACT;GACD,gBAAgB,IAAI,OACjB,IAAY,gBACb,QAAQ,eACT;GACD,OAAO;IAAE;IAAK;GAAS;EACxB;CACF;AACF;AAED,OAAO,SAAS,MACdC,MAGA;AACA,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;AAED,OAAO,MAAM,SAAS,WAAW;AACjC,OAAO,MAAM,SAAS,WAAW","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 * as zod from 'zod/v4-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 zod.ZodMiniObject<\n { [K in keyof T]: T[K]['encodedZodType'] },\n zod.core.$strict\n >,\n zod.ZodMiniObject<\n { [K in keyof T]: T[K]['decodedZodType'] },\n zod.core.$strict\n >,\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: zod.object(encodeProperties),\n decodedZodType: zod.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 zod.ZodMiniRecord<K['encodedZodType'], E['encodedZodType']>,\n zod.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: zod.record(\n (key as any).encodedZodType,\n element.encodedZodType,\n ),\n decodedZodType: zod.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<\n zod.core.util.ToEnum<Extract<keyof T['props']['properties'], string>>\n> {\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\nexport const object = ObjectType.factory\nexport const record = RecordType.factory\n"],"version":3,"file":"object.js"}
|