@nmtjs/type 0.10.2 → 0.10.4
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/types/string.js
CHANGED
|
@@ -1,54 +1,55 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as zod from "zod/v4-mini";
|
|
2
2
|
import { BaseType } from "./base.js";
|
|
3
3
|
export class StringType extends BaseType {
|
|
4
4
|
static factory(...checks) {
|
|
5
5
|
return new StringType({
|
|
6
|
-
encodedZodType: string().check(...checks),
|
|
6
|
+
encodedZodType: zod.string().check(...checks),
|
|
7
7
|
params: { checks }
|
|
8
8
|
});
|
|
9
9
|
}
|
|
10
10
|
max(value) {
|
|
11
|
-
return StringType.factory(...this.params.checks, maxLength(value));
|
|
11
|
+
return StringType.factory(...this.params.checks, zod.maxLength(value));
|
|
12
12
|
}
|
|
13
13
|
min(value) {
|
|
14
|
-
return StringType.factory(...this.params.checks, minLength(value));
|
|
14
|
+
return StringType.factory(...this.params.checks, zod.minLength(value));
|
|
15
15
|
}
|
|
16
16
|
pattern(pattern) {
|
|
17
|
-
return StringType.factory(...this.params.checks, regex(typeof pattern === "string" ? new RegExp(pattern) : pattern));
|
|
17
|
+
return StringType.factory(...this.params.checks, zod.regex(typeof pattern === "string" ? new RegExp(pattern) : pattern));
|
|
18
18
|
}
|
|
19
19
|
email(options) {
|
|
20
|
-
return StringType.factory(...this.params.checks, email(options));
|
|
20
|
+
return StringType.factory(...this.params.checks, zod.email(options));
|
|
21
21
|
}
|
|
22
22
|
url(options) {
|
|
23
|
-
return StringType.factory(...this.params.checks, url(options));
|
|
23
|
+
return StringType.factory(...this.params.checks, zod.url(options));
|
|
24
24
|
}
|
|
25
25
|
ipv4(options) {
|
|
26
|
-
return StringType.factory(...this.params.checks, ipv4(options));
|
|
26
|
+
return StringType.factory(...this.params.checks, zod.ipv4(options));
|
|
27
27
|
}
|
|
28
28
|
ipv6(options) {
|
|
29
|
-
return StringType.factory(...this.params.checks, ipv6(options));
|
|
29
|
+
return StringType.factory(...this.params.checks, zod.ipv6(options));
|
|
30
30
|
}
|
|
31
31
|
uuid(options) {
|
|
32
|
-
return StringType.factory(...this.params.checks, uuid(options));
|
|
32
|
+
return StringType.factory(...this.params.checks, zod.uuid(options));
|
|
33
33
|
}
|
|
34
34
|
emoji(options) {
|
|
35
|
-
return StringType.factory(...this.params.checks, emoji(options));
|
|
35
|
+
return StringType.factory(...this.params.checks, zod.emoji(options));
|
|
36
36
|
}
|
|
37
37
|
nanoid(options) {
|
|
38
|
-
return StringType.factory(...this.params.checks, nanoid(options));
|
|
38
|
+
return StringType.factory(...this.params.checks, zod.nanoid(options));
|
|
39
39
|
}
|
|
40
40
|
cuid(options) {
|
|
41
|
-
return StringType.factory(...this.params.checks, cuid(options));
|
|
41
|
+
return StringType.factory(...this.params.checks, zod.cuid(options));
|
|
42
42
|
}
|
|
43
43
|
cuid2(options) {
|
|
44
|
-
return StringType.factory(...this.params.checks, cuid2(options));
|
|
44
|
+
return StringType.factory(...this.params.checks, zod.cuid2(options));
|
|
45
45
|
}
|
|
46
46
|
e164(options) {
|
|
47
|
-
return StringType.factory(...this.params.checks, e164(options));
|
|
47
|
+
return StringType.factory(...this.params.checks, zod.e164(options));
|
|
48
48
|
}
|
|
49
49
|
jwt(options) {
|
|
50
|
-
return StringType.factory(...this.params.checks, jwt(options));
|
|
50
|
+
return StringType.factory(...this.params.checks, zod.jwt(options));
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
+
export const string = StringType.factory;
|
|
53
54
|
|
|
54
55
|
//# sourceMappingURL=string.js.map
|
package/dist/types/string.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAAA,
|
|
1
|
+
{"mappings":"AAAA,YAAY,SAAS,aAAa;AAElC,SAAS,gBAAgB,WAAW;AAIpC,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,IAAIA,OAAe;AACjB,SAAO,WAAW,QAAQ,GAAG,KAAK,OAAO,QAAQ,IAAI,UAAU,MAAM,CAAC;CACvE;CAED,IAAIA,OAAe;AACjB,SAAO,WAAW,QAAQ,GAAG,KAAK,OAAO,QAAQ,IAAI,UAAU,MAAM,CAAC;CACvE;CAED,QAAQC,SAA0B;AAChC,SAAO,WAAW,QAChB,GAAG,KAAK,OAAO,QACf,IAAI,aAAa,YAAY,WAAW,IAAI,OAAO,WAAW,QAAQ,CACvE;CACF;CAED,MAAMC,SAAoC;AACxC,SAAO,WAAW,QAAQ,GAAG,KAAK,OAAO,QAAQ,IAAI,MAAM,QAAQ,CAAC;CACrE;CAED,IAAIC,SAAkC;AACpC,SAAO,WAAW,QAAQ,GAAG,KAAK,OAAO,QAAQ,IAAI,IAAI,QAAQ,CAAC;CACnE;CAED,KAAKC,SAAmC;AACtC,SAAO,WAAW,QAAQ,GAAG,KAAK,OAAO,QAAQ,IAAI,KAAK,QAAQ,CAAC;CACpE;CAED,KAAKC,SAAmC;AACtC,SAAO,WAAW,QAAQ,GAAG,KAAK,OAAO,QAAQ,IAAI,KAAK,QAAQ,CAAC;CACpE;CAED,KAAKC,SAAmC;AACtC,SAAO,WAAW,QAAQ,GAAG,KAAK,OAAO,QAAQ,IAAI,KAAK,QAAQ,CAAC;CACpE;CAED,MAAMC,SAAoC;AACxC,SAAO,WAAW,QAAQ,GAAG,KAAK,OAAO,QAAQ,IAAI,MAAM,QAAQ,CAAC;CACrE;CAED,OAAOC,SAAqC;AAC1C,SAAO,WAAW,QAAQ,GAAG,KAAK,OAAO,QAAQ,IAAI,OAAO,QAAQ,CAAC;CACtE;CAED,KAAKC,SAAmC;AACtC,SAAO,WAAW,QAAQ,GAAG,KAAK,OAAO,QAAQ,IAAI,KAAK,QAAQ,CAAC;CACpE;CAED,MAAMC,SAAoC;AACxC,SAAO,WAAW,QAAQ,GAAG,KAAK,OAAO,QAAQ,IAAI,MAAM,QAAQ,CAAC;CACrE;CAED,KAAKC,SAAmC;AACtC,SAAO,WAAW,QAAQ,GAAG,KAAK,OAAO,QAAQ,IAAI,KAAK,QAAQ,CAAC;CACpE;CAED,IAAIC,SAAkC;AACpC,SAAO,WAAW,QAAQ,GAAG,KAAK,OAAO,QAAQ,IAAI,IAAI,QAAQ,CAAC;CACnE;AACF;AAED,OAAO,MAAM,SAAS,WAAW","names":["value: number","pattern: string | RegExp","options?: zod.core.$ZodEmailParams","options?: zod.core.$ZodURLParams","options?: zod.core.$ZodIPv4Params","options?: zod.core.$ZodIPv6Params","options?: zod.core.$ZodUUIDParams","options?: zod.core.$ZodEmojiParams","options?: zod.core.$ZodNanoIDParams","options?: zod.core.$ZodCUIDParams","options?: zod.core.$ZodCUID2Params","options?: zod.core.$ZodE164Params","options?: zod.core.$ZodJWTParams"],"sources":["../../src/types/string.ts"],"sourcesContent":["import * as zod from 'zod/v4-mini'\n\nimport { BaseType } from './base.ts'\n\ntype Check = zod.core.CheckFn<string> | zod.core.$ZodCheck<string>\n\nexport class StringType extends BaseType<\n zod.ZodMiniString<string>,\n zod.ZodMiniString<string>\n> {\n static factory(...checks: Check[]) {\n return new StringType({\n encodedZodType: zod.string().check(...checks),\n params: { checks },\n })\n }\n\n max(value: number) {\n return StringType.factory(...this.params.checks, zod.maxLength(value))\n }\n\n min(value: number) {\n return StringType.factory(...this.params.checks, zod.minLength(value))\n }\n\n pattern(pattern: string | RegExp) {\n return StringType.factory(\n ...this.params.checks,\n zod.regex(typeof pattern === 'string' ? new RegExp(pattern) : pattern),\n )\n }\n\n email(options?: zod.core.$ZodEmailParams) {\n return StringType.factory(...this.params.checks, zod.email(options))\n }\n\n url(options?: zod.core.$ZodURLParams) {\n return StringType.factory(...this.params.checks, zod.url(options))\n }\n\n ipv4(options?: zod.core.$ZodIPv4Params) {\n return StringType.factory(...this.params.checks, zod.ipv4(options))\n }\n\n ipv6(options?: zod.core.$ZodIPv6Params) {\n return StringType.factory(...this.params.checks, zod.ipv6(options))\n }\n\n uuid(options?: zod.core.$ZodUUIDParams) {\n return StringType.factory(...this.params.checks, zod.uuid(options))\n }\n\n emoji(options?: zod.core.$ZodEmojiParams) {\n return StringType.factory(...this.params.checks, zod.emoji(options))\n }\n\n nanoid(options?: zod.core.$ZodNanoIDParams) {\n return StringType.factory(...this.params.checks, zod.nanoid(options))\n }\n\n cuid(options?: zod.core.$ZodCUIDParams) {\n return StringType.factory(...this.params.checks, zod.cuid(options))\n }\n\n cuid2(options?: zod.core.$ZodCUID2Params) {\n return StringType.factory(...this.params.checks, zod.cuid2(options))\n }\n\n e164(options?: zod.core.$ZodE164Params) {\n return StringType.factory(...this.params.checks, zod.e164(options))\n }\n\n jwt(options?: zod.core.$ZodJWTParams) {\n return StringType.factory(...this.params.checks, zod.jwt(options))\n }\n}\n\nexport const string = StringType.factory\n"],"version":3,"file":"string.js"}
|
package/dist/types/temporal.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { iso, regex, string } from "@zod/mini";
|
|
2
1
|
import { Temporal } from "temporal-polyfill";
|
|
2
|
+
import { iso, regex, string } from "zod/v4-mini";
|
|
3
3
|
import { CustomType, TransformType } from "./custom.js";
|
|
4
4
|
const createTemporalTransformer = (type, decode = (value) => Temporal[type].from(value)) => {
|
|
5
5
|
const encode = (value) => value.toString({
|
|
@@ -89,5 +89,12 @@ export class PlainMonthDayType extends TransformType {
|
|
|
89
89
|
});
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
|
+
export const plainDate = PlainDateType.factory;
|
|
93
|
+
export const plainDatetime = PlainDateTimeType.factory;
|
|
94
|
+
export const plainTime = PlainTimeType.factory;
|
|
95
|
+
export const zonedDatetime = ZonedDateTimeType.factory;
|
|
96
|
+
export const duration = DurationType.factory;
|
|
97
|
+
export const plainYearMonth = PlainYearMonthType.factory;
|
|
98
|
+
export const plainMonthDay = PlainMonthDayType.factory;
|
|
92
99
|
|
|
93
100
|
//# sourceMappingURL=temporal.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAAA,SAAS,KAAK,OAAO,cAAkC,
|
|
1
|
+
{"mappings":"AAAA,SAAS,gBAAgB,mBAAmB;AAC5C,SAAS,KAAK,OAAO,cAAkC,aAAa;AACpE,SAAS,YAAY,qBAAqB,aAAa;AAYvD,MAAM,4BAA4B,CAChCA,MACA,SAAS,CAACC,UAAkB,SAAS,MAAM,KAAK,MAAM,KACnD;CACH,MAAM,SAAS,CAACC,UACd,MAAM,SAAS;EACb,cAAc;EACd,cAAc;EACd,cAAc;CACf,EAAC;AAEJ,QAAO;EACL;EACA;CACD;AACF;AAID,OAAO,MAAM,sBAAsB,cAGjC;CACA,OAAO,cAAc,0BAA0B,YAAY;CAE3D,OAAO,UAAU;AACf,SAAO,WAAW,QAAyC;GACzD,QAAQ,cAAc,YAAY;GAClC,QAAQ,cAAc,YAAY;GAClC,MAAM,IAAI,MAAM;GAChB,OAAO;EACR,EAAC;CACH;AACF;AAED,OAAO,MAAM,0BAA0B,cAGrC;CACA,OAAO,cAAc,0BAA0B,gBAAgB;CAE/D,OAAO,UAAU;AACf,SAAO,WAAW,QAA6C;GAC7D,QAAQ,kBAAkB,YAAY;GACtC,QAAQ,kBAAkB,YAAY;GACtC,MAAM,IAAI,SAAS,EAAE,OAAO,KAAM,EAAC;GACnC,OAAO;EACR,EAAC;CACH;AACF;AAED,OAAO,MAAM,0BAA0B,cAGrC;CACA,OAAO,cAAc,0BAA0B,iBAAiB,CAAC,UAC/D,SAAS,QAAQ,KAAK,MAAM,CAAC,mBAAmB,MAAM,CACvD;CAED,OAAO,UAAU;AACf,SAAO,WAAW,QAA6C;GAC7D,QAAQ,kBAAkB,YAAY;GACtC,QAAQ,kBAAkB,YAAY;GACtC,MAAM,IAAI,SAAS,EAAE,OAAO,KAAM,EAAC;GACnC,OAAO;EACR,EAAC;CACH;AACF;AAED,OAAO,MAAM,sBAAsB,cAGjC;CACA,OAAO,cAAc,0BAA0B,YAAY;CAE3D,OAAO,UAAU;AACf,SAAO,WAAW,QAAyC;GACzD,QAAQ,cAAc,YAAY;GAClC,QAAQ,cAAc,YAAY;GAClC,MAAM,IAAI,MAAM;GAChB,OAAO;EACR,EAAC;CACH;AACF;AAED,OAAO,MAAM,qBAAqB,cAGhC;CACA,OAAO,cAAc,0BAA0B,WAAW;CAE1D,OAAO,UAAU;AACf,SAAO,WAAW,QAAwC;GACxD,QAAQ,aAAa,YAAY;GACjC,QAAQ,aAAa,YAAY;GACjC,MAAM,IAAI,UAAU;GACpB,OAAO;EACR,EAAC;CACH;AACF;AAED,OAAO,MAAM,2BAA2B,cAGtC;CACA,OAAO,cAAc,0BAA0B,iBAAiB;CAEhE,OAAO,UAAU;AACf,SAAO,WAAW,QAA8C;GAC9D,QAAQ,mBAAmB,YAAY;GACvC,QAAQ,mBAAmB,YAAY;GACvC,MAAM,QAAQ,CAAC,MAAM,MAAM,gBAAgB,CAAC;GAC5C,OAAO;EACR,EAAC;CACH;AACF;AAED,OAAO,MAAM,0BAA0B,cAGrC;CACA,OAAO,cAAc,0BAA0B,gBAAgB;CAE/D,OAAO,UAAU;AACf,SAAO,WAAW,QAA6C;GAC7D,QAAQ,kBAAkB,YAAY;GACtC,QAAQ,kBAAkB,YAAY;GACtC,MAAM,QAAQ,CAAC,MAAM,MAAM,gBAAgB,CAAC;GAC5C,OAAO;EACR,EAAC;CACH;AACF;AAED,OAAO,MAAM,YAAY,cAAc;AACvC,OAAO,MAAM,gBAAgB,kBAAkB;AAC/C,OAAO,MAAM,YAAY,cAAc;AACvC,OAAO,MAAM,gBAAgB,kBAAkB;AAC/C,OAAO,MAAM,WAAW,aAAa;AACrC,OAAO,MAAM,iBAAiB,mBAAmB;AACjD,OAAO,MAAM,gBAAgB,kBAAkB","names":["type: T","value: string","value: ReturnType<(typeof Temporal)[T]['from']>"],"sources":["../../src/types/temporal.ts"],"sourcesContent":["import { Temporal } from 'temporal-polyfill'\nimport { iso, regex, string, type ZodMiniString } from 'zod/v4-mini'\nimport { CustomType, TransformType } from './custom.ts'\n\ntype Types = Exclude<\n keyof typeof Temporal,\n 'Now' | 'Instant' | 'Calendar' | 'TimeZone'\n>\n\ntype TemporalTransformer<T extends Types> = {\n decode: (value: string) => ReturnType<(typeof Temporal)[T]['from']>\n encode: (value: ReturnType<(typeof Temporal)[T]['from']>) => string\n}\n\nconst createTemporalTransformer = <T extends Types>(\n type: T,\n decode = (value: string) => Temporal[type].from(value),\n) => {\n const encode = (value: ReturnType<(typeof Temporal)[T]['from']>) =>\n value.toString({\n calendarName: 'never',\n smallestUnit: 'microsecond',\n timeZoneName: 'never',\n })\n\n return {\n decode,\n encode,\n } as TemporalTransformer<T>\n}\n\ntype EncodedType = ZodMiniString<string>\n\nexport class PlainDateType extends TransformType<\n Temporal.PlainDate,\n EncodedType\n> {\n static transformer = createTemporalTransformer('PlainDate')\n\n static factory() {\n return CustomType.factory<Temporal.PlainDate, EncodedType>({\n decode: PlainDateType.transformer.decode,\n encode: PlainDateType.transformer.encode,\n type: iso.date(),\n error: 'Invalid date format',\n })\n }\n}\n\nexport class PlainDateTimeType extends TransformType<\n Temporal.PlainDateTime,\n EncodedType\n> {\n static transformer = createTemporalTransformer('PlainDateTime')\n\n static factory() {\n return CustomType.factory<Temporal.PlainDateTime, EncodedType>({\n decode: PlainDateTimeType.transformer.decode,\n encode: PlainDateTimeType.transformer.encode,\n type: iso.datetime({ local: true }),\n error: 'Invalid datetime format',\n })\n }\n}\n\nexport class ZonedDateTimeType extends TransformType<\n Temporal.ZonedDateTime,\n EncodedType\n> {\n static transformer = createTemporalTransformer('ZonedDateTime', (value) =>\n Temporal.Instant.from(value).toZonedDateTimeISO('UTC'),\n )\n\n static factory() {\n return CustomType.factory<Temporal.ZonedDateTime, EncodedType>({\n decode: ZonedDateTimeType.transformer.decode,\n encode: ZonedDateTimeType.transformer.encode,\n type: iso.datetime({ local: true }),\n error: 'Invalid datetime format',\n })\n }\n}\n\nexport class PlainTimeType extends TransformType<\n Temporal.PlainTime,\n EncodedType\n> {\n static transformer = createTemporalTransformer('PlainTime')\n\n static factory() {\n return CustomType.factory<Temporal.PlainTime, EncodedType>({\n decode: PlainTimeType.transformer.decode,\n encode: PlainTimeType.transformer.encode,\n type: iso.time(),\n error: 'Invalid time format',\n })\n }\n}\n\nexport class DurationType extends TransformType<\n Temporal.Duration,\n EncodedType\n> {\n static transformer = createTemporalTransformer('Duration')\n\n static factory() {\n return CustomType.factory<Temporal.Duration, EncodedType>({\n decode: DurationType.transformer.decode,\n encode: DurationType.transformer.encode,\n type: iso.duration(),\n error: 'Invalid duration format',\n })\n }\n}\n\nexport class PlainYearMonthType extends TransformType<\n Temporal.PlainYearMonth,\n EncodedType\n> {\n static transformer = createTemporalTransformer('PlainYearMonth')\n\n static factory() {\n return CustomType.factory<Temporal.PlainYearMonth, EncodedType>({\n decode: PlainYearMonthType.transformer.decode,\n encode: PlainYearMonthType.transformer.encode,\n type: string().check(regex(/^\\d{4}-\\d{2}$/)),\n error: 'Invalid year-month format',\n })\n }\n}\n\nexport class PlainMonthDayType extends TransformType<\n Temporal.PlainMonthDay,\n EncodedType\n> {\n static transformer = createTemporalTransformer('PlainMonthDay')\n\n static factory() {\n return CustomType.factory<Temporal.PlainMonthDay, EncodedType>({\n decode: PlainMonthDayType.transformer.decode,\n encode: PlainMonthDayType.transformer.encode,\n type: string().check(regex(/^\\d{2}-\\d{2}$/)),\n error: 'Invalid month-day format',\n })\n }\n}\n\nexport const plainDate = PlainDateType.factory\nexport const plainDatetime = PlainDateTimeType.factory\nexport const plainTime = PlainTimeType.factory\nexport const zonedDatetime = ZonedDateTimeType.factory\nexport const duration = DurationType.factory\nexport const plainYearMonth = PlainYearMonthType.factory\nexport const plainMonthDay = PlainMonthDayType.factory\n"],"version":3,"file":"temporal.js"}
|
package/dist/types/tuple.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as zod from "zod/v4-mini";
|
|
2
2
|
import { BaseType } from "./base.js";
|
|
3
3
|
export class TupleType extends BaseType {
|
|
4
4
|
static factory(elements, rest = null) {
|
|
5
5
|
const encoded = elements.map((el) => el.encodedZodType);
|
|
6
6
|
const decoded = elements.map((el) => el.decodedZodType);
|
|
7
7
|
return new TupleType({
|
|
8
|
-
encodedZodType: tuple(encoded, rest?.encodedZodType),
|
|
9
|
-
decodedZodType: tuple(decoded, rest?.decodedZodType),
|
|
8
|
+
encodedZodType: zod.tuple(encoded, rest?.encodedZodType),
|
|
9
|
+
decodedZodType: zod.tuple(decoded, rest?.decodedZodType),
|
|
10
10
|
props: {
|
|
11
11
|
elements,
|
|
12
12
|
rest
|
|
@@ -14,5 +14,6 @@ export class TupleType extends BaseType {
|
|
|
14
14
|
});
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
|
+
export const tuple = TupleType.factory;
|
|
17
18
|
|
|
18
19
|
//# sourceMappingURL=tuple.js.map
|
package/dist/types/tuple.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AACA,SAAS,
|
|
1
|
+
{"mappings":"AACA,YAAY,SAAS,aAAa;AAClC,SAAS,gBAAgB,WAAW;AAEpC,OAAO,MAAM,kBAMH,SAQR;CACA,OAAO,QAGLA,UAAaC,OAAU,MAAW;EAClC,MAAM,UAAU,SAAS,IAAI,CAAC,OAAO,GAAG,eAAe;EACvD,MAAM,UAAU,SAAS,IAAI,CAAC,OAAO,GAAG,eAAe;AACvD,SAAO,IAAI,UAAgB;GAEzB,gBAAgB,IAAI,MAAM,SAAS,MAAM,eAAe;GAExD,gBAAgB,IAAI,MAAM,SAAS,MAAM,eAAe;GACxD,OAAO;IAAE;IAAU;GAAM;EAC1B;CACF;AACF;AAED,OAAO,MAAM,QAAQ,UAAU","names":["elements: T","rest: R"],"sources":["../../src/types/tuple.ts"],"sourcesContent":["import type { ArrayMap } from '@nmtjs/common'\nimport * as zod from 'zod/v4-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 ? zod.ZodMiniTuple<ArrayMap<T, 'encodedZodType'>, R['encodedZodType']>\n : zod.ZodMiniTuple<ArrayMap<T, 'encodedZodType'>, null>,\n R extends BaseType\n ? zod.ZodMiniTuple<ArrayMap<T, 'decodedZodType'>, R['decodedZodType']>\n : zod.ZodMiniTuple<ArrayMap<T, 'decodedZodType'>, null>,\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 return new TupleType<T, R>({\n // @ts-expect-error\n encodedZodType: zod.tuple(encoded, rest?.encodedZodType),\n // @ts-expect-error\n decodedZodType: zod.tuple(decoded, rest?.decodedZodType),\n props: { elements, rest },\n })\n }\n}\n\nexport const tuple = TupleType.factory\n"],"version":3,"file":"tuple.js"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export * from "./any.js";
|
|
2
|
+
export * from "./array.js";
|
|
3
|
+
export * from "./boolean.js";
|
|
4
|
+
export * from "./custom.js";
|
|
5
|
+
export * from "./date.js";
|
|
6
|
+
export * from "./enum.js";
|
|
7
|
+
export * from "./literal.js";
|
|
8
|
+
export * from "./never.js";
|
|
9
|
+
export * from "./number.js";
|
|
10
|
+
export * from "./object.js";
|
|
11
|
+
export * from "./string.js";
|
|
12
|
+
export * from "./tuple.js";
|
|
13
|
+
export * from "./union.js";
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=type.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAEA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc","names":[],"sources":["../../src/types/type.ts"],"sourcesContent":["import type { BaseTypeAny } from './base.ts'\n\nexport * from './any.ts'\nexport * from './array.ts'\nexport * from './boolean.ts'\nexport * from './custom.ts'\nexport * from './date.ts'\nexport * from './enum.ts'\nexport * from './literal.ts'\nexport * from './never.ts'\nexport * from './number.ts'\nexport * from './object.ts'\nexport * from './string.ts'\nexport * from './tuple.ts'\nexport * from './union.ts'\n\nexport 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"],"version":3,"file":"type.js"}
|
package/dist/types/union.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as zod from "zod/v4-mini";
|
|
2
2
|
import { BaseType } from "./base.js";
|
|
3
3
|
export class UnionType extends BaseType {
|
|
4
4
|
static factory(...options) {
|
|
5
5
|
const encoded = options.map((t) => t.encodedZodType);
|
|
6
6
|
const decoded = options.map((t) => t.decodedZodType);
|
|
7
7
|
return new UnionType({
|
|
8
|
-
encodedZodType: union(encoded),
|
|
9
|
-
decodedZodType: union(decoded),
|
|
8
|
+
encodedZodType: zod.union(encoded),
|
|
9
|
+
decodedZodType: zod.union(decoded),
|
|
10
10
|
props: { options }
|
|
11
11
|
});
|
|
12
12
|
}
|
|
@@ -15,8 +15,8 @@ export class IntersactionType extends BaseType {
|
|
|
15
15
|
static factory(...options) {
|
|
16
16
|
const [first, second] = options;
|
|
17
17
|
return new IntersactionType({
|
|
18
|
-
encodedZodType: intersection(first.encodedZodType, second.encodedZodType),
|
|
19
|
-
decodedZodType: intersection(first.decodedZodType, second.decodedZodType),
|
|
18
|
+
encodedZodType: zod.intersection(first.encodedZodType, second.encodedZodType),
|
|
19
|
+
decodedZodType: zod.intersection(first.decodedZodType, second.decodedZodType),
|
|
20
20
|
props: { options }
|
|
21
21
|
});
|
|
22
22
|
}
|
|
@@ -26,8 +26,8 @@ export class DiscriminatedUnionType extends BaseType {
|
|
|
26
26
|
const encoded = options.map((t) => t.encodedZodType);
|
|
27
27
|
const decoded = options.map((t) => t.decodedZodType);
|
|
28
28
|
return new DiscriminatedUnionType({
|
|
29
|
-
encodedZodType: discriminatedUnion(encoded),
|
|
30
|
-
decodedZodType: discriminatedUnion(decoded),
|
|
29
|
+
encodedZodType: zod.discriminatedUnion(key, encoded),
|
|
30
|
+
decodedZodType: zod.discriminatedUnion(key, decoded),
|
|
31
31
|
props: {
|
|
32
32
|
key,
|
|
33
33
|
options
|
|
@@ -35,5 +35,10 @@ export class DiscriminatedUnionType extends BaseType {
|
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
+
export const union = UnionType.factory;
|
|
39
|
+
export const or = UnionType.factory;
|
|
40
|
+
export const intersection = IntersactionType.factory;
|
|
41
|
+
export const and = IntersactionType.factory;
|
|
42
|
+
export const discriminatedUnion = DiscriminatedUnionType.factory;
|
|
38
43
|
|
|
39
44
|
//# sourceMappingURL=union.js.map
|
package/dist/types/union.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AACA,
|
|
1
|
+
{"mappings":"AACA,YAAY,SAAS,aAAa;AAClC,SAAS,gBAAkC,WAAW;AAItD,OAAO,MAAM,kBAKH,SAIR;CACA,OAAO,QAKL,GAAG,SAAY;EACf,MAAM,UAAU,QAAQ,IAAI,CAAC,MAAM,EAAE,eAAe;EAIpD,MAAM,UAAU,QAAQ,IAAI,CAAC,MAAM,EAAE,eAAe;AAIpD,SAAO,IAAI,UAAa;GACtB,gBAAgB,IAAI,MAAM,QAAQ;GAClC,gBAAgB,IAAI,MAAM,QAAQ;GAClC,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,IAAI,aAClB,MAAM,gBACN,OAAO,eACR;GACD,gBAAgB,IAAI,aAClB,MAAM,gBACN,OAAO,eACR;GACD,OAAO,EAAE,QAAS;EACnB;CACF;AACF;AAYD,OAAO,MAAM,+BAIH,SAOR;CACA,OAAO,QAILA,KAAQ,GAAG,SAAY;EACvB,MAAM,UAAU,QAAQ,IAAI,CAAC,MAAM,EAAE,eAAe;EAIpD,MAAM,UAAU,QAAQ,IAAI,CAAC,MAAM,EAAE,eAAe;AAIpD,SAAO,IAAI,uBAA6B;GAEtC,gBAAgB,IAAI,mBAAmB,KAAK,QAAQ;GAEpD,gBAAgB,IAAI,mBAAmB,KAAK,QAAQ;GACpD,OAAO;IAAE;IAAK;GAAS;EACxB;CACF;AACF;AAED,OAAO,MAAM,QAAQ,UAAU;AAC/B,OAAO,MAAM,KAAK,UAAU;AAC5B,OAAO,MAAM,eAAe,iBAAiB;AAC7C,OAAO,MAAM,MAAM,iBAAiB;AACpC,OAAO,MAAM,qBAAqB,uBAAuB","names":["key: K"],"sources":["../../src/types/union.ts"],"sourcesContent":["import type { ArrayMap } from '@nmtjs/common'\nimport * as zod from 'zod/v4-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 zod.ZodMiniUnion<ArrayMap<T, 'encodedZodType'>>,\n zod.ZodMiniUnion<ArrayMap<T, 'decodedZodType'>>,\n { options: T }\n> {\n static factory<\n T extends readonly [BaseType, ...BaseType[]] = readonly [\n BaseType,\n ...BaseType[],\n ],\n >(...options: T) {\n const encoded = options.map((t) => t.encodedZodType) as ArrayMap<\n T,\n 'encodedZodType'\n >\n const decoded = options.map((t) => t.decodedZodType) as ArrayMap<\n T,\n 'decodedZodType'\n >\n return new UnionType<T>({\n encodedZodType: zod.union(encoded),\n decodedZodType: zod.union(decoded),\n props: { options },\n })\n }\n}\n\nexport class IntersactionType<\n T extends readonly [BaseType, BaseType] = readonly [BaseType, BaseType],\n> extends BaseType<\n zod.ZodMiniIntersection<T[0]['encodedZodType'], T[1]['encodedZodType']>,\n zod.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: zod.intersection(\n first.encodedZodType,\n second.encodedZodType,\n ),\n decodedZodType: zod.intersection(\n first.decodedZodType,\n second.decodedZodType,\n ),\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 zod.ZodMiniDiscriminatedUnion<ArrayMap<T, 'encodedZodType'>>,\n zod.ZodMiniDiscriminatedUnion<ArrayMap<T, '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 const encoded = options.map((t) => t.encodedZodType) as ArrayMap<\n T,\n 'encodedZodType'\n >\n const decoded = options.map((t) => t.decodedZodType) as ArrayMap<\n T,\n 'decodedZodType'\n >\n return new DiscriminatedUnionType<K, T>({\n // @ts-expect-error\n encodedZodType: zod.discriminatedUnion(key, encoded),\n // @ts-expect-error\n decodedZodType: zod.discriminatedUnion(key, decoded),\n props: { key, options },\n })\n }\n}\n\nexport const union = UnionType.factory\nexport const or = UnionType.factory\nexport const intersection = IntersactionType.factory\nexport const and = IntersactionType.factory\nexport const discriminatedUnion = DiscriminatedUnionType.factory\n"],"version":3,"file":"union.js"}
|
package/package.json
CHANGED
|
@@ -11,15 +11,15 @@
|
|
|
11
11
|
"types": "./src/temporal.ts"
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
|
-
"dependencies": {
|
|
15
|
-
"@zod/mini": "4.0.0-beta.20250503T014749",
|
|
16
|
-
"temporal-polyfill": "^0.3.0"
|
|
17
|
-
},
|
|
18
14
|
"peerDependencies": {
|
|
19
|
-
"
|
|
15
|
+
"temporal-polyfill": "^0.3.0",
|
|
16
|
+
"zod": "^3.25.0",
|
|
17
|
+
"@nmtjs/common": "0.10.4"
|
|
20
18
|
},
|
|
21
19
|
"devDependencies": {
|
|
22
|
-
"
|
|
20
|
+
"temporal-polyfill": "^0.3.0",
|
|
21
|
+
"zod": "^3.25.0",
|
|
22
|
+
"@nmtjs/common": "0.10.4"
|
|
23
23
|
},
|
|
24
24
|
"files": [
|
|
25
25
|
"src",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"LICENSE.md",
|
|
28
28
|
"README.md"
|
|
29
29
|
],
|
|
30
|
-
"version": "0.10.
|
|
30
|
+
"version": "0.10.4",
|
|
31
31
|
"scripts": {
|
|
32
32
|
"build": "neemata-build --root=./src './**/*.ts'",
|
|
33
33
|
"type-check": "tsc --noEmit"
|
package/src/index.ts
CHANGED
|
@@ -1,101 +1,8 @@
|
|
|
1
|
-
import * as zod from '
|
|
2
|
-
import
|
|
3
|
-
import { ArrayType } from './types/array.ts'
|
|
4
|
-
import type { BaseTypeAny } from './types/base.ts'
|
|
5
|
-
import { BooleanType } from './types/boolean.ts'
|
|
6
|
-
import { CustomType } from './types/custom.ts'
|
|
7
|
-
import { DateType } from './types/date.ts'
|
|
8
|
-
import { EnumType } from './types/enum.ts'
|
|
9
|
-
import { LiteralType } from './types/literal.ts'
|
|
10
|
-
import { NeverType } from './types/never.ts'
|
|
11
|
-
import { BigIntType, IntegerType, NumberType } from './types/number.ts'
|
|
12
|
-
import {
|
|
13
|
-
extend,
|
|
14
|
-
keyof,
|
|
15
|
-
merge,
|
|
16
|
-
ObjectType,
|
|
17
|
-
omit,
|
|
18
|
-
partial,
|
|
19
|
-
pick,
|
|
20
|
-
RecordType,
|
|
21
|
-
} from './types/object.ts'
|
|
22
|
-
import { StringType } from './types/string.ts'
|
|
23
|
-
import { TupleType } from './types/tuple.ts'
|
|
24
|
-
import {
|
|
25
|
-
DiscriminatedUnionType,
|
|
26
|
-
IntersactionType,
|
|
27
|
-
UnionType,
|
|
28
|
-
} from './types/union.ts'
|
|
1
|
+
import * as zod from 'zod/v4-mini'
|
|
2
|
+
import * as type from './types/type.ts'
|
|
29
3
|
|
|
30
4
|
zod.config(zod.core.locales.en())
|
|
31
5
|
|
|
32
|
-
export
|
|
33
|
-
export {
|
|
34
|
-
export {
|
|
35
|
-
AnyType,
|
|
36
|
-
ArrayType,
|
|
37
|
-
BooleanType,
|
|
38
|
-
CustomType,
|
|
39
|
-
DateType,
|
|
40
|
-
EnumType,
|
|
41
|
-
LiteralType,
|
|
42
|
-
IntegerType,
|
|
43
|
-
NumberType,
|
|
44
|
-
ObjectType,
|
|
45
|
-
StringType,
|
|
46
|
-
IntersactionType,
|
|
47
|
-
UnionType,
|
|
48
|
-
TupleType,
|
|
49
|
-
NeverType,
|
|
50
|
-
DiscriminatedUnionType,
|
|
51
|
-
RecordType,
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export namespace type {
|
|
55
|
-
export namespace infer {
|
|
56
|
-
export namespace decoded {
|
|
57
|
-
export type input<T extends BaseTypeAny> =
|
|
58
|
-
T['decodedZodType']['_zod']['input']
|
|
59
|
-
export type output<T extends BaseTypeAny> =
|
|
60
|
-
T['decodedZodType']['_zod']['output']
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export namespace encoded {
|
|
64
|
-
export type input<T extends BaseTypeAny> =
|
|
65
|
-
T['encodedZodType']['_zod']['input']
|
|
66
|
-
export type output<T extends BaseTypeAny> =
|
|
67
|
-
T['encodedZodType']['_zod']['output']
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export const type = {
|
|
73
|
-
never: NeverType.factory,
|
|
74
|
-
boolean: BooleanType.factory,
|
|
75
|
-
string: StringType.factory,
|
|
76
|
-
number: NumberType.factory,
|
|
77
|
-
integer: IntegerType.factory,
|
|
78
|
-
bigint: BigIntType.factory,
|
|
79
|
-
literal: LiteralType.factory,
|
|
80
|
-
enum: EnumType.factory,
|
|
81
|
-
tuple: TupleType.factory,
|
|
82
|
-
date: DateType.factory,
|
|
83
|
-
array: ArrayType.factory,
|
|
84
|
-
record: RecordType.factory,
|
|
85
|
-
any: AnyType.factory,
|
|
86
|
-
or: UnionType.factory,
|
|
87
|
-
and: IntersactionType.factory,
|
|
88
|
-
union: UnionType.factory,
|
|
89
|
-
intersaction: IntersactionType.factory,
|
|
90
|
-
discriminatedUnion: DiscriminatedUnionType.factory,
|
|
91
|
-
custom: CustomType.factory,
|
|
92
|
-
object: ObjectType.factory,
|
|
93
|
-
keyof,
|
|
94
|
-
partial,
|
|
95
|
-
merge,
|
|
96
|
-
omit,
|
|
97
|
-
extend,
|
|
98
|
-
pick,
|
|
99
|
-
}
|
|
100
|
-
export { type as t, zod }
|
|
6
|
+
export * from './types/base.ts'
|
|
7
|
+
export { type, type as t }
|
|
101
8
|
export default type
|
package/src/temporal.ts
CHANGED
|
@@ -1,27 +1 @@
|
|
|
1
|
-
|
|
2
|
-
DurationType,
|
|
3
|
-
PlainDateTimeType,
|
|
4
|
-
PlainDateType,
|
|
5
|
-
PlainMonthDayType,
|
|
6
|
-
PlainTimeType,
|
|
7
|
-
PlainYearMonthType,
|
|
8
|
-
ZonedDateTimeType,
|
|
9
|
-
} from './types/temporal.ts'
|
|
10
|
-
|
|
11
|
-
export const plainDate = PlainDateType.factory
|
|
12
|
-
export const plainDatetime = PlainDateTimeType.factory
|
|
13
|
-
export const plainTime = PlainTimeType.factory
|
|
14
|
-
export const zonedDatetime = ZonedDateTimeType.factory
|
|
15
|
-
export const duration = DurationType.factory
|
|
16
|
-
export const plainYearMonth = PlainYearMonthType.factory
|
|
17
|
-
export const plainMonthDay = PlainMonthDayType.factory
|
|
18
|
-
|
|
19
|
-
export type {
|
|
20
|
-
DurationType,
|
|
21
|
-
PlainDateTimeType,
|
|
22
|
-
PlainDateType,
|
|
23
|
-
PlainMonthDayType,
|
|
24
|
-
PlainTimeType,
|
|
25
|
-
PlainYearMonthType,
|
|
26
|
-
ZonedDateTimeType,
|
|
27
|
-
}
|
|
1
|
+
export * from './types/temporal.ts'
|
package/src/types/any.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as zod from 'zod/v4-mini'
|
|
2
2
|
import { BaseType } from './base.ts'
|
|
3
3
|
|
|
4
|
-
export class AnyType extends BaseType<ZodMiniAny> {
|
|
4
|
+
export class AnyType extends BaseType<zod.ZodMiniAny> {
|
|
5
5
|
static factory() {
|
|
6
6
|
return new AnyType({
|
|
7
|
-
encodedZodType: any(),
|
|
7
|
+
encodedZodType: zod.any(),
|
|
8
8
|
})
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
+
|
|
12
|
+
export const any = AnyType.factory
|
package/src/types/array.ts
CHANGED
|
@@ -1,31 +1,24 @@
|
|
|
1
|
-
import
|
|
2
|
-
array,
|
|
3
|
-
type core,
|
|
4
|
-
length,
|
|
5
|
-
maxLength,
|
|
6
|
-
minLength,
|
|
7
|
-
type ZodMiniArray,
|
|
8
|
-
} from '@zod/mini'
|
|
1
|
+
import * as zod from 'zod/v4-mini'
|
|
9
2
|
import { BaseType } from './base.ts'
|
|
10
3
|
|
|
11
|
-
type Check = core.CheckFn<any[]> | core.$ZodCheck<any[]>
|
|
4
|
+
type Check = zod.core.CheckFn<any[]> | zod.core.$ZodCheck<any[]>
|
|
12
5
|
|
|
13
6
|
export class ArrayType<T extends BaseType = BaseType> extends BaseType<
|
|
14
|
-
ZodMiniArray<T['encodedZodType']>,
|
|
15
|
-
ZodMiniArray<T['decodedZodType']>,
|
|
7
|
+
zod.ZodMiniArray<T['encodedZodType']>,
|
|
8
|
+
zod.ZodMiniArray<T['decodedZodType']>,
|
|
16
9
|
{ element: T }
|
|
17
10
|
> {
|
|
18
11
|
static factory<T extends BaseType>(element: T, ...checks: Check[]) {
|
|
19
12
|
return new ArrayType<T>({
|
|
20
|
-
encodedZodType: array(element.encodedZodType).check(...checks),
|
|
21
|
-
decodedZodType: array(element.decodedZodType).check(...checks),
|
|
13
|
+
encodedZodType: zod.array(element.encodedZodType).check(...checks),
|
|
14
|
+
decodedZodType: zod.array(element.decodedZodType).check(...checks),
|
|
22
15
|
params: { checks },
|
|
23
16
|
props: { element },
|
|
24
17
|
})
|
|
25
18
|
}
|
|
26
19
|
|
|
27
20
|
min(value: number) {
|
|
28
|
-
const check = minLength(value)
|
|
21
|
+
const check = zod.minLength(value)
|
|
29
22
|
return ArrayType.factory<T>(
|
|
30
23
|
this.props.element,
|
|
31
24
|
...this.params.checks,
|
|
@@ -34,7 +27,7 @@ export class ArrayType<T extends BaseType = BaseType> extends BaseType<
|
|
|
34
27
|
}
|
|
35
28
|
|
|
36
29
|
max(value: number) {
|
|
37
|
-
const check = maxLength(value)
|
|
30
|
+
const check = zod.maxLength(value)
|
|
38
31
|
return ArrayType.factory<T>(
|
|
39
32
|
this.props.element,
|
|
40
33
|
...this.params.checks,
|
|
@@ -43,7 +36,7 @@ export class ArrayType<T extends BaseType = BaseType> extends BaseType<
|
|
|
43
36
|
}
|
|
44
37
|
|
|
45
38
|
length(value: number) {
|
|
46
|
-
const check = length(value)
|
|
39
|
+
const check = zod.length(value)
|
|
47
40
|
return ArrayType.factory<T>(
|
|
48
41
|
this.props.element,
|
|
49
42
|
...this.params.checks,
|
|
@@ -51,3 +44,5 @@ export class ArrayType<T extends BaseType = BaseType> extends BaseType<
|
|
|
51
44
|
)
|
|
52
45
|
}
|
|
53
46
|
}
|
|
47
|
+
|
|
48
|
+
export const array = ArrayType.factory
|