@nmtjs/type 0.6.5 → 0.7.1
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 +34 -31
- package/dist/index.js.map +1 -1
- package/dist/temporal.js +0 -1
- package/dist/temporal.js.map +1 -1
- package/dist/types/any.js +4 -4
- package/dist/types/any.js.map +1 -1
- package/dist/types/array.js +21 -23
- package/dist/types/array.js.map +1 -1
- package/dist/types/base.js +65 -66
- package/dist/types/base.js.map +1 -1
- package/dist/types/boolean.js +4 -4
- package/dist/types/boolean.js.map +1 -1
- package/dist/types/custom.js +9 -8
- package/dist/types/custom.js.map +1 -1
- package/dist/types/date.js +8 -13
- package/dist/types/date.js.map +1 -1
- package/dist/types/enum.js +7 -16
- package/dist/types/enum.js.map +1 -1
- package/dist/types/literal.js +7 -6
- package/dist/types/literal.js.map +1 -1
- package/dist/types/never.js +4 -4
- package/dist/types/never.js.map +1 -1
- package/dist/types/number.js +39 -92
- package/dist/types/number.js.map +1 -1
- package/dist/types/object.js +42 -31
- package/dist/types/object.js.map +1 -1
- package/dist/types/string.js +49 -47
- package/dist/types/string.js.map +1 -1
- package/dist/types/temporal.js +75 -41
- package/dist/types/temporal.js.map +1 -1
- package/dist/types/union.js +26 -18
- package/dist/types/union.js.map +1 -1
- package/package.json +7 -19
- package/src/index.ts +22 -24
- package/src/temporal.ts +1 -1
- package/src/types/any.ts +5 -3
- package/src/types/array.ts +37 -22
- package/src/types/base.ts +149 -81
- package/src/types/boolean.ts +5 -3
- package/src/types/custom.ts +59 -26
- package/src/types/date.ts +13 -17
- package/src/types/enum.ts +12 -22
- package/src/types/literal.ts +9 -6
- package/src/types/never.ts +5 -3
- package/src/types/number.ts +43 -90
- package/src/types/object.ts +45 -37
- package/src/types/string.ts +68 -37
- package/src/types/temporal.ts +69 -53
- package/src/types/union.ts +54 -50
- package/dist/compiler.js +0 -55
- package/dist/compiler.js.map +0 -1
- package/dist/formats.js +0 -127
- package/dist/formats.js.map +0 -1
- package/dist/inference.js +0 -1
- package/dist/inference.js.map +0 -1
- package/dist/parse.js +0 -145
- package/dist/parse.js.map +0 -1
- package/dist/runtime.js +0 -73
- package/dist/runtime.js.map +0 -1
- package/dist/schemas/default.js +0 -6
- package/dist/schemas/default.js.map +0 -1
- package/dist/schemas/discriminated-union.js +0 -9
- package/dist/schemas/discriminated-union.js.map +0 -1
- package/dist/schemas/nullable.js +0 -11
- package/dist/schemas/nullable.js.map +0 -1
- package/dist/utils.js +0 -1
- package/dist/utils.js.map +0 -1
- package/src/compiler.ts +0 -100
- package/src/formats.ts +0 -182
- package/src/inference.ts +0 -128
- package/src/parse.ts +0 -217
- package/src/runtime.ts +0 -137
- package/src/schemas/default.ts +0 -12
- package/src/schemas/discriminated-union.ts +0 -49
- package/src/schemas/nullable.ts +0 -20
- package/src/utils.ts +0 -24
package/dist/types/number.js
CHANGED
|
@@ -1,97 +1,44 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { gt, gte, int, lt, lte, number, regex, string } from "@zod/mini";
|
|
2
2
|
import { BaseType } from "./base.js";
|
|
3
|
+
import { CustomType, TransformType } from "./custom.js";
|
|
3
4
|
export class NumberType extends BaseType {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
...!exclusive ? {} : {
|
|
29
|
-
exclusiveMinimum: value
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
}
|
|
5
|
+
static factory(...checks) {
|
|
6
|
+
return new NumberType({
|
|
7
|
+
encodedZodType: number().check(...checks),
|
|
8
|
+
params: { checks }
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
positive() {
|
|
12
|
+
return NumberType.factory(...this.params.checks, gte(0));
|
|
13
|
+
}
|
|
14
|
+
negative() {
|
|
15
|
+
return NumberType.factory(...this.params.checks, lte(0));
|
|
16
|
+
}
|
|
17
|
+
lt(value) {
|
|
18
|
+
return NumberType.factory(...this.params.checks, lt(value));
|
|
19
|
+
}
|
|
20
|
+
lte(value) {
|
|
21
|
+
return NumberType.factory(...this.params.checks, lte(value));
|
|
22
|
+
}
|
|
23
|
+
gte(value) {
|
|
24
|
+
return NumberType.factory(...this.params.checks, gte(value));
|
|
25
|
+
}
|
|
26
|
+
gt(value) {
|
|
27
|
+
return NumberType.factory(...this.params.checks, gt(value));
|
|
28
|
+
}
|
|
33
29
|
}
|
|
34
|
-
export class IntegerType extends
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
positive() {
|
|
41
|
-
return this.min(0, true);
|
|
42
|
-
}
|
|
43
|
-
negative() {
|
|
44
|
-
return this.max(0, true);
|
|
45
|
-
}
|
|
46
|
-
max(value, exclusive) {
|
|
47
|
-
return IntegerType.factory({
|
|
48
|
-
...this.props.options,
|
|
49
|
-
maximum: value,
|
|
50
|
-
...!exclusive ? {} : {
|
|
51
|
-
exclusiveMaximum: value
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
min(value, exclusive) {
|
|
56
|
-
return IntegerType.factory({
|
|
57
|
-
...this.props.options,
|
|
58
|
-
minimum: value,
|
|
59
|
-
...!exclusive ? {} : {
|
|
60
|
-
exclusiveMinimum: value
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
}
|
|
30
|
+
export class IntegerType extends NumberType {
|
|
31
|
+
static factory(...checks) {
|
|
32
|
+
return NumberType.factory(...checks, int());
|
|
33
|
+
}
|
|
64
34
|
}
|
|
65
|
-
export class BigIntType extends
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
return this.min(0n, true);
|
|
75
|
-
}
|
|
76
|
-
negative() {
|
|
77
|
-
return this.max(0n, true);
|
|
78
|
-
}
|
|
79
|
-
max(value, exclusive) {
|
|
80
|
-
return BigIntType.factory({
|
|
81
|
-
...this.props.options,
|
|
82
|
-
maximum: value,
|
|
83
|
-
...!exclusive ? {} : {
|
|
84
|
-
exclusiveMaximum: value
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
min(value, exclusive) {
|
|
89
|
-
return BigIntType.factory({
|
|
90
|
-
...this.props.options,
|
|
91
|
-
minimum: value,
|
|
92
|
-
...!exclusive ? {} : {
|
|
93
|
-
exclusiveMinimum: value
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
}
|
|
35
|
+
export class BigIntType extends TransformType {
|
|
36
|
+
static factory() {
|
|
37
|
+
return CustomType.factory({
|
|
38
|
+
decode: (value) => BigInt(value),
|
|
39
|
+
encode: (value) => value.toString(),
|
|
40
|
+
type: string().check(regex(/^-?\d+$/)),
|
|
41
|
+
error: "Invalid bigint format"
|
|
42
|
+
});
|
|
43
|
+
}
|
|
97
44
|
}
|
package/dist/types/number.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"
|
|
1
|
+
{"mappings":"AAAA,SAEE,IACA,KACA,KACA,IACA,KACA,QACA,OACA,cAGK,WAAW;AAClB,SAAS,gBAAgB,WAAW;AACpC,SAAS,YAAY,qBAAqB,aAAa;AAIvD,OAAO,MAAM,mBAAmB,SAG9B;CACA,OAAO,QAAQ,GAAG,QAAiB;AACjC,SAAO,IAAI,WAAW;GACpB,gBAAgB,QAAQ,CAAC,MAAM,GAAG,OAAO;GACzC,QAAQ,EAAE,OAAQ;EACnB;CACF;CAED,WAAW;AACT,SAAO,WAAW,QAAQ,GAAG,KAAK,OAAO,QAAQ,IAAI,EAAE,CAAC;CACzD;CAED,WAAW;AACT,SAAO,WAAW,QAAQ,GAAG,KAAK,OAAO,QAAQ,IAAI,EAAE,CAAC;CACzD;CAED,GAAGA,OAAe;AAChB,SAAO,WAAW,QAAQ,GAAG,KAAK,OAAO,QAAQ,GAAG,MAAM,CAAC;CAC5D;CAED,IAAIA,OAAe;AACjB,SAAO,WAAW,QAAQ,GAAG,KAAK,OAAO,QAAQ,IAAI,MAAM,CAAC;CAC7D;CAED,IAAIA,OAAe;AACjB,SAAO,WAAW,QAAQ,GAAG,KAAK,OAAO,QAAQ,IAAI,MAAM,CAAC;CAC7D;CAED,GAAGA,OAAe;AAChB,SAAO,WAAW,QAAQ,GAAG,KAAK,OAAO,QAAQ,GAAG,MAAM,CAAC;CAC5D;AACF;AAED,OAAO,MAAM,oBAAoB,WAAW;CAC1C,OAAO,QAAQ,GAAG,QAAiB;AACjC,SAAO,WAAW,QAAQ,GAAG,QAAQ,KAAK,CAAC;CAC5C;AACF;AAED,OAAO,MAAM,mBAAmB,cAA6C;CAC3E,OAAO,UAAU;AACf,SAAO,WAAW,QAAuC;GACvD,QAAQ,CAAC,UAAU,OAAO,MAAM;GAChC,QAAQ,CAAC,UAAU,MAAM,UAAU;GACnC,MAAM,QAAQ,CAAC,MAAM,MAAM,UAAU,CAAC;GACtC,OAAO;EACR,EAAC;CACH;AACF","names":["value: number"],"sources":["src/types/number.ts"],"sourcesContent":["import {\n type core,\n gt,\n gte,\n int,\n lt,\n lte,\n number,\n regex,\n string,\n type ZodMiniNumber,\n type ZodMiniString,\n} from '@zod/mini'\nimport { BaseType } from './base.ts'\nimport { CustomType, TransformType } from './custom.ts'\n\ntype Check = core.CheckFn<number> | core.$ZodCheck<number>\n\nexport class NumberType extends BaseType<\n ZodMiniNumber<number>,\n ZodMiniNumber<number>\n> {\n static factory(...checks: Check[]) {\n return new NumberType({\n encodedZodType: number().check(...checks),\n params: { checks },\n })\n }\n\n positive() {\n return NumberType.factory(...this.params.checks, gte(0))\n }\n\n negative() {\n return NumberType.factory(...this.params.checks, lte(0))\n }\n\n lt(value: number) {\n return NumberType.factory(...this.params.checks, lt(value))\n }\n\n lte(value: number) {\n return NumberType.factory(...this.params.checks, lte(value))\n }\n\n gte(value: number) {\n return NumberType.factory(...this.params.checks, gte(value))\n }\n\n gt(value: number) {\n return NumberType.factory(...this.params.checks, gt(value))\n }\n}\n\nexport class IntegerType extends NumberType {\n static factory(...checks: Check[]) {\n return NumberType.factory(...checks, int())\n }\n}\n\nexport class BigIntType extends TransformType<bigint, ZodMiniString<string>> {\n static factory() {\n return CustomType.factory<bigint, ZodMiniString<string>>({\n decode: (value) => BigInt(value),\n encode: (value) => value.toString(),\n type: string().check(regex(/^-?\\d+$/)),\n error: 'Invalid bigint format',\n })\n }\n}\n"],"version":3}
|
package/dist/types/object.js
CHANGED
|
@@ -1,49 +1,60 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { object, record, strictObject } from "@zod/mini";
|
|
2
2
|
import { BaseType } from "./base.js";
|
|
3
3
|
import { EnumType } from "./enum.js";
|
|
4
4
|
export class ObjectType extends BaseType {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
5
|
+
static factory(properties) {
|
|
6
|
+
const encodeProperties = {};
|
|
7
|
+
const decodeProperties = {};
|
|
8
|
+
for (const key in properties) {
|
|
9
|
+
encodeProperties[key] = properties[key].encodedZodType;
|
|
10
|
+
decodeProperties[key] = properties[key].decodedZodType;
|
|
11
|
+
}
|
|
12
|
+
return new ObjectType({
|
|
13
|
+
encodedZodType: object(encodeProperties),
|
|
14
|
+
decodedZodType: object(decodeProperties),
|
|
15
|
+
props: { properties }
|
|
16
|
+
});
|
|
17
|
+
}
|
|
14
18
|
}
|
|
15
19
|
export class RecordType extends BaseType {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
20
|
+
static factory(key, element) {
|
|
21
|
+
return new RecordType({
|
|
22
|
+
encodedZodType: record(key.encodedZodType, element.encodedZodType),
|
|
23
|
+
decodedZodType: record(key.decodedZodType, element.decodedZodType),
|
|
24
|
+
props: {
|
|
25
|
+
key,
|
|
26
|
+
element
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
19
30
|
}
|
|
20
31
|
export function keyof(type) {
|
|
21
|
-
|
|
32
|
+
return EnumType.factory(Object.keys(type.props.properties));
|
|
22
33
|
}
|
|
23
34
|
export function pick(source, pick) {
|
|
24
|
-
|
|
25
|
-
|
|
35
|
+
const properties = Object.fromEntries(Object.entries(source.props.properties).filter(([key]) => pick[key]));
|
|
36
|
+
return ObjectType.factory(properties);
|
|
26
37
|
}
|
|
27
38
|
export function omit(source, omit) {
|
|
28
|
-
|
|
29
|
-
|
|
39
|
+
const properties = Object.fromEntries(Object.entries(source.props.properties).filter(([key]) => !omit[key]));
|
|
40
|
+
return ObjectType.factory(properties);
|
|
30
41
|
}
|
|
31
42
|
export function extend(object1, properties) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
43
|
+
return ObjectType.factory({
|
|
44
|
+
...object1.props.properties,
|
|
45
|
+
...properties
|
|
46
|
+
});
|
|
36
47
|
}
|
|
37
48
|
export function merge(object1, object2) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
49
|
+
return ObjectType.factory({
|
|
50
|
+
...object1.props.properties,
|
|
51
|
+
...object2.props.properties
|
|
52
|
+
});
|
|
42
53
|
}
|
|
43
54
|
export function partial(object) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
55
|
+
const properties = {};
|
|
56
|
+
for (const [key, value] of Object.entries(object.props.properties)) {
|
|
57
|
+
properties[key] = value.optional();
|
|
58
|
+
}
|
|
59
|
+
return ObjectType.factory(properties);
|
|
49
60
|
}
|
package/dist/types/object.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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jB,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<\n core.utils.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"],"version":3}
|
package/dist/types/string.js
CHANGED
|
@@ -1,50 +1,52 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { cuid, cuid2, e164, email, emoji, ipv4, ipv6, jwt, maxLength, minLength, nanoid, regex, string, url, uuid } from "@zod/mini";
|
|
2
2
|
import { BaseType } from "./base.js";
|
|
3
3
|
export class StringType extends BaseType {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
4
|
+
static factory(...checks) {
|
|
5
|
+
return new StringType({
|
|
6
|
+
encodedZodType: string().check(...checks),
|
|
7
|
+
params: { checks }
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
max(value) {
|
|
11
|
+
return StringType.factory(...this.params.checks, maxLength(value));
|
|
12
|
+
}
|
|
13
|
+
min(value) {
|
|
14
|
+
return StringType.factory(...this.params.checks, minLength(value));
|
|
15
|
+
}
|
|
16
|
+
pattern(pattern) {
|
|
17
|
+
return StringType.factory(...this.params.checks, regex(typeof pattern === "string" ? new RegExp(pattern) : pattern));
|
|
18
|
+
}
|
|
19
|
+
email(options) {
|
|
20
|
+
return StringType.factory(...this.params.checks, email(options));
|
|
21
|
+
}
|
|
22
|
+
url(options) {
|
|
23
|
+
return StringType.factory(...this.params.checks, url(options));
|
|
24
|
+
}
|
|
25
|
+
ipv4(options) {
|
|
26
|
+
return StringType.factory(...this.params.checks, ipv4(options));
|
|
27
|
+
}
|
|
28
|
+
ipv6(options) {
|
|
29
|
+
return StringType.factory(...this.params.checks, ipv6(options));
|
|
30
|
+
}
|
|
31
|
+
uuid(options) {
|
|
32
|
+
return StringType.factory(...this.params.checks, uuid(options));
|
|
33
|
+
}
|
|
34
|
+
emoji(options) {
|
|
35
|
+
return StringType.factory(...this.params.checks, emoji(options));
|
|
36
|
+
}
|
|
37
|
+
nanoid(options) {
|
|
38
|
+
return StringType.factory(...this.params.checks, nanoid(options));
|
|
39
|
+
}
|
|
40
|
+
cuid(options) {
|
|
41
|
+
return StringType.factory(...this.params.checks, cuid(options));
|
|
42
|
+
}
|
|
43
|
+
cuid2(options) {
|
|
44
|
+
return StringType.factory(...this.params.checks, cuid2(options));
|
|
45
|
+
}
|
|
46
|
+
e164(options) {
|
|
47
|
+
return StringType.factory(...this.params.checks, e164(options));
|
|
48
|
+
}
|
|
49
|
+
jwt(options) {
|
|
50
|
+
return StringType.factory(...this.params.checks, jwt(options));
|
|
51
|
+
}
|
|
50
52
|
}
|
package/dist/types/string.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"
|
|
1
|
+
{"mappings":"AAAA,SAEE,MACA,OACA,MACA,OACA,OACA,MACA,MACA,K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+B;AAClC,SAAO,WAAW,QAAQ,GAAG,KAAK,OAAO,QAAQ,KAAK,QAAQ,CAAC;CAChE;CAED,MAAMC,SAAgC;AACpC,SAAO,WAAW,QAAQ,GAAG,KAAK,OAAO,QAAQ,MAAM,QAAQ,CAAC;CACjE;CAED,KAAKC,SAA+B;AAClC,SAAO,WAAW,QAAQ,GAAG,KAAK,OAAO,QAAQ,KAAK,QAAQ,CAAC;CAChE;CAED,IAAIC,SAA8B;AAChC,SAAO,WAAW,QAAQ,GAAG,KAAK,OAAO,QAAQ,IAAI,QAAQ,CAAC;CAC/D;AACF","names":["value: number","pattern: string | RegExp","options?: core.$ZodEmailParams","options?: core.$ZodURLParams","options?: core.$ZodIPv4Params","options?: core.$ZodIPv6Params","options?: core.$ZodUUIDParams","options?: core.$ZodEmojiParams","options?: core.$ZodNanoIDParams","options?: core.$ZodCUIDParams","options?: core.$ZodCUID2Params","options?: core.$ZodE164Params","options?: core.$ZodJWTParams"],"sources":["src/types/string.ts"],"sourcesContent":["import {\n type core,\n cuid,\n cuid2,\n e164,\n email,\n emoji,\n ipv4,\n ipv6,\n jwt,\n maxLength,\n minLength,\n nanoid,\n regex,\n string,\n url,\n uuid,\n type ZodMiniString,\n} from '@zod/mini'\n\nimport { BaseType } from './base.ts'\n\ntype Check = core.CheckFn<string> | core.$ZodCheck<string>\n\nexport class StringType extends BaseType<\n ZodMiniString<string>,\n ZodMiniString<string>\n> {\n static factory(...checks: Check[]) {\n return new StringType({\n encodedZodType: string().check(...checks),\n params: { checks },\n })\n }\n\n max(value: number) {\n return StringType.factory(...this.params.checks, maxLength(value))\n }\n\n min(value: number) {\n return StringType.factory(...this.params.checks, minLength(value))\n }\n\n pattern(pattern: string | RegExp) {\n return StringType.factory(\n ...this.params.checks,\n regex(typeof pattern === 'string' ? new RegExp(pattern) : pattern),\n )\n }\n\n email(options?: core.$ZodEmailParams) {\n return StringType.factory(...this.params.checks, email(options))\n }\n\n url(options?: core.$ZodURLParams) {\n return StringType.factory(...this.params.checks, url(options))\n }\n\n ipv4(options?: core.$ZodIPv4Params) {\n return StringType.factory(...this.params.checks, ipv4(options))\n }\n\n ipv6(options?: core.$ZodIPv6Params) {\n return StringType.factory(...this.params.checks, ipv6(options))\n }\n\n uuid(options?: core.$ZodUUIDParams) {\n return StringType.factory(...this.params.checks, uuid(options))\n }\n\n emoji(options?: core.$ZodEmojiParams) {\n return StringType.factory(...this.params.checks, emoji(options))\n }\n\n nanoid(options?: core.$ZodNanoIDParams) {\n return StringType.factory(...this.params.checks, nanoid(options))\n }\n\n cuid(options?: core.$ZodCUIDParams) {\n return StringType.factory(...this.params.checks, cuid(options))\n }\n\n cuid2(options?: core.$ZodCUID2Params) {\n return StringType.factory(...this.params.checks, cuid2(options))\n }\n\n e164(options?: core.$ZodE164Params) {\n return StringType.factory(...this.params.checks, e164(options))\n }\n\n jwt(options?: core.$ZodJWTParams) {\n return StringType.factory(...this.params.checks, jwt(options))\n }\n}\n"],"version":3}
|
package/dist/types/temporal.js
CHANGED
|
@@ -1,57 +1,91 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Temporal } from
|
|
1
|
+
import { iso, regex, string } from "@zod/mini";
|
|
2
|
+
import { Temporal } from "temporal-polyfill";
|
|
3
3
|
import { CustomType, TransformType } from "./custom.js";
|
|
4
|
-
const createTemporalTransformer = (type, decode = (value)=>Temporal[type].from(value))=>{
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
4
|
+
const createTemporalTransformer = (type, decode = (value) => Temporal[type].from(value)) => {
|
|
5
|
+
const encode = (value) => value.toString({
|
|
6
|
+
calendarName: "never",
|
|
7
|
+
smallestUnit: "microsecond",
|
|
8
|
+
timeZoneName: "never"
|
|
9
|
+
});
|
|
10
|
+
return {
|
|
11
|
+
decode,
|
|
12
|
+
encode
|
|
13
|
+
};
|
|
14
14
|
};
|
|
15
15
|
export class PlainDateType extends TransformType {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
static transformer = createTemporalTransformer("PlainDate");
|
|
17
|
+
static factory() {
|
|
18
|
+
return CustomType.factory({
|
|
19
|
+
decode: PlainDateType.transformer.decode,
|
|
20
|
+
encode: PlainDateType.transformer.encode,
|
|
21
|
+
type: iso.date(),
|
|
22
|
+
error: "Invalid date format"
|
|
23
|
+
});
|
|
24
|
+
}
|
|
20
25
|
}
|
|
21
26
|
export class PlainDateTimeType extends TransformType {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
static transformer = createTemporalTransformer("PlainDateTime");
|
|
28
|
+
static factory() {
|
|
29
|
+
return CustomType.factory({
|
|
30
|
+
decode: PlainDateTimeType.transformer.decode,
|
|
31
|
+
encode: PlainDateTimeType.transformer.encode,
|
|
32
|
+
type: iso.datetime({ local: true }),
|
|
33
|
+
error: "Invalid datetime format"
|
|
34
|
+
});
|
|
35
|
+
}
|
|
27
36
|
}
|
|
28
37
|
export class ZonedDateTimeType extends TransformType {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
38
|
+
static transformer = createTemporalTransformer("ZonedDateTime", (value) => Temporal.Instant.from(value).toZonedDateTimeISO("UTC"));
|
|
39
|
+
static factory() {
|
|
40
|
+
return CustomType.factory({
|
|
41
|
+
decode: ZonedDateTimeType.transformer.decode,
|
|
42
|
+
encode: ZonedDateTimeType.transformer.encode,
|
|
43
|
+
type: iso.datetime({ local: true }),
|
|
44
|
+
error: "Invalid datetime format"
|
|
45
|
+
});
|
|
46
|
+
}
|
|
33
47
|
}
|
|
34
48
|
export class PlainTimeType extends TransformType {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
49
|
+
static transformer = createTemporalTransformer("PlainTime");
|
|
50
|
+
static factory() {
|
|
51
|
+
return CustomType.factory({
|
|
52
|
+
decode: PlainTimeType.transformer.decode,
|
|
53
|
+
encode: PlainTimeType.transformer.encode,
|
|
54
|
+
type: iso.time(),
|
|
55
|
+
error: "Invalid time format"
|
|
56
|
+
});
|
|
57
|
+
}
|
|
39
58
|
}
|
|
40
59
|
export class DurationType extends TransformType {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
60
|
+
static transformer = createTemporalTransformer("Duration");
|
|
61
|
+
static factory() {
|
|
62
|
+
return CustomType.factory({
|
|
63
|
+
decode: DurationType.transformer.decode,
|
|
64
|
+
encode: DurationType.transformer.encode,
|
|
65
|
+
type: iso.duration(),
|
|
66
|
+
error: "Invalid duration format"
|
|
67
|
+
});
|
|
68
|
+
}
|
|
45
69
|
}
|
|
46
70
|
export class PlainYearMonthType extends TransformType {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
71
|
+
static transformer = createTemporalTransformer("PlainYearMonth");
|
|
72
|
+
static factory() {
|
|
73
|
+
return CustomType.factory({
|
|
74
|
+
decode: PlainYearMonthType.transformer.decode,
|
|
75
|
+
encode: PlainYearMonthType.transformer.encode,
|
|
76
|
+
type: string().check(regex(/^\d{4}-\d{2}$/)),
|
|
77
|
+
error: "Invalid year-month format"
|
|
78
|
+
});
|
|
79
|
+
}
|
|
51
80
|
}
|
|
52
81
|
export class PlainMonthDayType extends TransformType {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
82
|
+
static transformer = createTemporalTransformer("PlainMonthDay");
|
|
83
|
+
static factory() {
|
|
84
|
+
return CustomType.factory({
|
|
85
|
+
decode: PlainMonthDayType.transformer.decode,
|
|
86
|
+
encode: PlainMonthDayType.transformer.encode,
|
|
87
|
+
type: string().check(regex(/^\d{2}-\d{2}$/)),
|
|
88
|
+
error: "Invalid month-day format"
|
|
89
|
+
});
|
|
90
|
+
}
|
|
57
91
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"
|
|
1
|
+
{"mappings":"A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AAM,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","names":["type: T","value: string","value: ReturnType<(typeof Temporal)[T]['from']>"],"sources":["src/types/temporal.ts"],"sourcesContent":["import { iso, regex, string, type ZodMiniString } from '@zod/mini'\nimport { Temporal } from 'temporal-polyfill'\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"],"version":3}
|
package/dist/types/union.js
CHANGED
|
@@ -1,25 +1,33 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { DiscriminatedUnion } from "../schemas/discriminated-union.js";
|
|
1
|
+
import { discriminatedUnion, intersection, union } from "@zod/mini";
|
|
3
2
|
import { BaseType } from "./base.js";
|
|
4
3
|
export class UnionType extends BaseType {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
static factory(...options) {
|
|
5
|
+
return new UnionType({
|
|
6
|
+
encodedZodType: union(options.map((t) => t.encodedZodType)),
|
|
7
|
+
decodedZodType: union(options.map((t) => t.decodedZodType)),
|
|
8
|
+
props: { options }
|
|
9
|
+
});
|
|
10
|
+
}
|
|
10
11
|
}
|
|
11
12
|
export class IntersactionType extends BaseType {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
static factory(...options) {
|
|
14
|
+
const [first, second] = options;
|
|
15
|
+
return new IntersactionType({
|
|
16
|
+
encodedZodType: intersection(first.encodedZodType, second.encodedZodType),
|
|
17
|
+
decodedZodType: intersection(first.decodedZodType, second.decodedZodType),
|
|
18
|
+
props: { options }
|
|
19
|
+
});
|
|
20
|
+
}
|
|
17
21
|
}
|
|
18
22
|
export class DiscriminatedUnionType extends BaseType {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
static factory(key, ...options) {
|
|
24
|
+
return new DiscriminatedUnionType({
|
|
25
|
+
encodedZodType: discriminatedUnion(options.map((t) => t.encodedZodType)),
|
|
26
|
+
decodedZodType: discriminatedUnion(options.map((t) => t.decodedZodType)),
|
|
27
|
+
props: {
|
|
28
|
+
key,
|
|
29
|
+
options
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
25
33
|
}
|