@nmtjs/type 0.6.4 → 0.7.0
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 +31 -31
- package/dist/index.js.map +1 -1
- package/dist/temporal.js +7 -8
- 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 +23 -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 +10 -9
- package/dist/types/custom.js.map +1 -1
- package/dist/types/date.js +6 -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 +26 -93
- 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 +31 -47
- package/dist/types/string.js.map +1 -1
- package/dist/types/temporal.js +40 -41
- package/dist/types/temporal.js.map +1 -1
- package/dist/types/union.js +25 -18
- package/dist/types/union.js.map +1 -1
- package/dist/utils.js +0 -1
- package/dist/utils.js.map +1 -1
- package/package.json +7 -19
- package/src/index.ts +24 -25
- package/src/temporal.ts +8 -8
- package/src/types/any.ts +5 -3
- package/src/types/array.ts +24 -22
- package/src/types/base.ts +148 -81
- package/src/types/boolean.ts +5 -3
- package/src/types/custom.ts +43 -24
- package/src/types/date.ts +17 -16
- 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 +31 -93
- package/src/types/object.ts +44 -37
- package/src/types/string.ts +41 -39
- package/src/types/temporal.ts +72 -32
- package/src/types/union.ts +59 -50
- package/src/utils.ts +22 -22
- 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/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/dist/types/number.js
CHANGED
|
@@ -1,97 +1,30 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { gt, gte, int, lt, lte, number } from "@zod/mini";
|
|
2
2
|
import { BaseType } from "./base.js";
|
|
3
3
|
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
|
-
return NumberType.factory({
|
|
26
|
-
...this.props.options,
|
|
27
|
-
minimum: value,
|
|
28
|
-
...!exclusive ? {} : {
|
|
29
|
-
exclusiveMinimum: value
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
}
|
|
4
|
+
static factory(...checks) {
|
|
5
|
+
return new NumberType({ encodedZodType: number().check(...checks) });
|
|
6
|
+
}
|
|
7
|
+
positive() {
|
|
8
|
+
return NumberType.factory(...this.props.checks, gte(0));
|
|
9
|
+
}
|
|
10
|
+
negative() {
|
|
11
|
+
return NumberType.factory(...this.props.checks, lte(0));
|
|
12
|
+
}
|
|
13
|
+
lt(value) {
|
|
14
|
+
return NumberType.factory(...this.props.checks, lt(value));
|
|
15
|
+
}
|
|
16
|
+
lte(value) {
|
|
17
|
+
return NumberType.factory(...this.props.checks, lte(value));
|
|
18
|
+
}
|
|
19
|
+
gte(value) {
|
|
20
|
+
return NumberType.factory(...this.props.checks, gte(value));
|
|
21
|
+
}
|
|
22
|
+
gt(value) {
|
|
23
|
+
return NumberType.factory(...this.props.checks, gt(value));
|
|
24
|
+
}
|
|
33
25
|
}
|
|
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
|
-
}
|
|
64
|
-
}
|
|
65
|
-
export class BigIntType extends BaseType {
|
|
66
|
-
static factory(options = {}) {
|
|
67
|
-
return new BigIntType(Type.BigInt(options), {
|
|
68
|
-
options
|
|
69
|
-
}, {
|
|
70
|
-
encode: (value)=>`${value}`
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
positive() {
|
|
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
|
-
}
|
|
26
|
+
export class IntegerType extends NumberType {
|
|
27
|
+
static factory(...checks) {
|
|
28
|
+
return NumberType.factory(...checks, int());
|
|
29
|
+
}
|
|
97
30
|
}
|
package/dist/types/number.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"
|
|
1
|
+
{"mappings":"AAAA,SAEE,IACA,KACA,KACA,IACA,KACA,cAEK,WAAW;AAClB,SAAS,gBAAgB,WAAW;AAIpC,OAAO,MAAM,mBAAmB,SAI9B;CACA,OAAO,QAAQ,GAAG,QAAiB;AACjC,SAAO,IAAI,WAAW,EACpB,gBAAgB,QAAQ,CAAC,MAAM,GAAG,OAAO,CAC1C;CACF;CAED,WAAW;AACT,SAAO,WAAW,QAAQ,GAAG,KAAK,MAAM,QAAQ,IAAI,EAAE,CAAC;CACxD;CAED,WAAW;AACT,SAAO,WAAW,QAAQ,GAAG,KAAK,MAAM,QAAQ,IAAI,EAAE,CAAC;CACxD;CAED,GAAGA,OAAe;AAChB,SAAO,WAAW,QAAQ,GAAG,KAAK,MAAM,QAAQ,GAAG,MAAM,CAAC;CAC3D;CAED,IAAIA,OAAe;AACjB,SAAO,WAAW,QAAQ,GAAG,KAAK,MAAM,QAAQ,IAAI,MAAM,CAAC;CAC5D;CAED,IAAIA,OAAe;AACjB,SAAO,WAAW,QAAQ,GAAG,KAAK,MAAM,QAAQ,IAAI,MAAM,CAAC;CAC5D;CAED,GAAGA,OAAe;AAChB,SAAO,WAAW,QAAQ,GAAG,KAAK,MAAM,QAAQ,GAAG,MAAM,CAAC;CAC3D;AACF;AAED,OAAO,MAAM,oBAAoB,WAAW;CAC1C,OAAO,QAAQ,GAAG,QAAiB;AACjC,SAAO,WAAW,QAAQ,GAAG,QAAQ,KAAK,CAAC;CAC5C;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 type ZodMiniNumber,\n} from '@zod/mini'\nimport { BaseType } from './base.ts'\n\ntype Check = core.CheckFn<number> | core.$ZodCheck<number>\n\nexport class NumberType extends BaseType<\n ZodMiniNumber<number>,\n ZodMiniNumber<number>,\n { checks: Check[] }\n> {\n static factory(...checks: Check[]) {\n return new NumberType({\n encodedZodType: number().check(...checks),\n })\n }\n\n positive() {\n return NumberType.factory(...this.props.checks, gte(0))\n }\n\n negative() {\n return NumberType.factory(...this.props.checks, lte(0))\n }\n\n lt(value: number) {\n return NumberType.factory(...this.props.checks, lt(value))\n }\n\n lte(value: number) {\n return NumberType.factory(...this.props.checks, lte(value))\n }\n\n gte(value: number) {\n return NumberType.factory(...this.props.checks, gte(value))\n }\n\n gt(value: number) {\n return NumberType.factory(...this.props.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"],"version":3}
|
package/dist/types/object.js
CHANGED
|
@@ -1,49 +1,60 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { object, record } 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 @@
|
|
|
1
|
-
{"
|
|
1
|
+
{"mappings":"AAAA,SAEE,QACA,cAGK,WAAW;AAElB,SAAS,gBAAqD,WAAW;AACzE,SAAS,gBAAgB,WAAW;AAMpC,OAAO,MAAM,mBAAmD,SAI9D;CACA,OAAO,QAAwCA,YAAe;EAC5D,MAAM,mBAAmB,CAAE;EAG3B,MAAM,mBAAmB,CAAE;AAI3B,OAAK,MAAM,OAAO,YAAY;AAC5B,oBAAiB,OAAO,WAAW,KAAK;AACxC,oBAAiB,OAAO,WAAW,KAAK;EACzC;AAED,SAAO,IAAI,WAAc;GACvB,gBAAgB,OAAO,iBAAiB;GACxC,gBAAgB,OAAO,iBAAiB;GACxC,OAAO,EAAE,WAAY;EACtB;CACF;AACF;AAED,OAAO,MAAM,mBAGH,SAGR;CACA,OAAO,QAGLC,KAAQC,SAAY;AACpB,SAAO,IAAI,WAAiB;GAC1B,gBAAgB,OACb,IAAY,gBACb,QAAQ,eACT;GACD,gBAAgB,OACb,IAAY,gBACb,QAAQ,eACT;GACD,OAAO;IAAE;IAAK;GAAS;EACxB;CACF;AACF;AAED,OAAO,SAAS,MACdC,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","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 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,34 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { email, ipv4, ipv6, maxLength, minLength, 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
|
-
email() {
|
|
36
|
-
return this.format('email');
|
|
37
|
-
}
|
|
38
|
-
url() {
|
|
39
|
-
return this.format('uri');
|
|
40
|
-
}
|
|
41
|
-
ipv4() {
|
|
42
|
-
return this.format('ipv4');
|
|
43
|
-
}
|
|
44
|
-
ipv6() {
|
|
45
|
-
return this.format('ipv6');
|
|
46
|
-
}
|
|
47
|
-
uuid() {
|
|
48
|
-
return this.format('uuid');
|
|
49
|
-
}
|
|
4
|
+
static factory(...checks) {
|
|
5
|
+
return new StringType({
|
|
6
|
+
encodedZodType: string().check(...checks),
|
|
7
|
+
props: { checks }
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
max(value) {
|
|
11
|
+
return StringType.factory(...this.props.checks, maxLength(value));
|
|
12
|
+
}
|
|
13
|
+
min(value) {
|
|
14
|
+
return StringType.factory(...this.props.checks, minLength(value));
|
|
15
|
+
}
|
|
16
|
+
pattern(pattern) {
|
|
17
|
+
return StringType.factory(...this.props.checks, regex(typeof pattern === "string" ? new RegExp(pattern) : pattern));
|
|
18
|
+
}
|
|
19
|
+
email(options) {
|
|
20
|
+
return StringType.factory(...this.props.checks, email(options));
|
|
21
|
+
}
|
|
22
|
+
url(options) {
|
|
23
|
+
return StringType.factory(...this.props.checks, url(options));
|
|
24
|
+
}
|
|
25
|
+
ipv4(options) {
|
|
26
|
+
return StringType.factory(...this.props.checks, ipv4(options));
|
|
27
|
+
}
|
|
28
|
+
ipv6(options) {
|
|
29
|
+
return StringType.factory(...this.props.checks, ipv6(options));
|
|
30
|
+
}
|
|
31
|
+
uuid(options) {
|
|
32
|
+
return StringType.factory(...this.props.checks, uuid(options));
|
|
33
|
+
}
|
|
50
34
|
}
|
package/dist/types/string.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"
|
|
1
|
+
{"mappings":"AAAA,SAEE,OACA,MACA,MACA,WACA,WACA,OACA,QACA,KACA,YAEK,WAAW;AAElB,SAAS,gBAAgB,WAAW;AAIpC,OAAO,MAAM,mBAAmB,SAI9B;CACA,OAAO,QAAQ,GAAG,QAAiB;AACjC,SAAO,IAAI,WAAW;GACpB,gBAAgB,QAAQ,CAAC,MAAM,GAAG,OAAO;GACzC,OAAO,EAAE,OAAQ;EAClB;CACF;CAED,IAAIA,OAAe;AACjB,SAAO,WAAW,QAAQ,GAAG,KAAK,MAAM,QAAQ,UAAU,MAAM,CAAC;CAClE;CAED,IAAIA,OAAe;AACjB,SAAO,WAAW,QAAQ,GAAG,KAAK,MAAM,QAAQ,UAAU,MAAM,CAAC;CAClE;CAED,QAAQC,SAA0B;AAChC,SAAO,WAAW,QAChB,GAAG,KAAK,MAAM,QACd,aAAa,YAAY,WAAW,IAAI,OAAO,WAAW,QAAQ,CACnE;CACF;CAED,MAAMC,SAAgC;AACpC,SAAO,WAAW,QAAQ,GAAG,KAAK,MAAM,QAAQ,MAAM,QAAQ,CAAC;CAChE;CAED,IAAIC,SAA8B;AAChC,SAAO,WAAW,QAAQ,GAAG,KAAK,MAAM,QAAQ,IAAI,QAAQ,CAAC;CAC9D;CAED,KAAKC,SAA+B;AAClC,SAAO,WAAW,QAAQ,GAAG,KAAK,MAAM,QAAQ,KAAK,QAAQ,CAAC;CAC/D;CAED,KAAKC,SAA+B;AAClC,SAAO,WAAW,QAAQ,GAAG,KAAK,MAAM,QAAQ,KAAK,QAAQ,CAAC;CAC/D;CAED,KAAKC,SAA+B;AAClC,SAAO,WAAW,QAAQ,GAAG,KAAK,MAAM,QAAQ,KAAK,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"],"sources":["src/types/string.ts"],"sourcesContent":["import {\n type core,\n email,\n ipv4,\n ipv6,\n maxLength,\n minLength,\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 { checks: Check[] }\n> {\n static factory(...checks: Check[]) {\n return new StringType({\n encodedZodType: string().check(...checks),\n props: { checks },\n })\n }\n\n max(value: number) {\n return StringType.factory(...this.props.checks, maxLength(value))\n }\n\n min(value: number) {\n return StringType.factory(...this.props.checks, minLength(value))\n }\n\n pattern(pattern: string | RegExp) {\n return StringType.factory(\n ...this.props.checks,\n regex(typeof pattern === 'string' ? new RegExp(pattern) : pattern),\n )\n }\n\n email(options?: core.$ZodEmailParams) {\n return StringType.factory(...this.props.checks, email(options))\n }\n\n url(options?: core.$ZodURLParams) {\n return StringType.factory(...this.props.checks, url(options))\n }\n\n ipv4(options?: core.$ZodIPv4Params) {\n return StringType.factory(...this.props.checks, ipv4(options))\n }\n\n ipv6(options?: core.$ZodIPv6Params) {\n return StringType.factory(...this.props.checks, ipv6(options))\n }\n\n uuid(options?: core.$ZodUUIDParams) {\n return StringType.factory(...this.props.checks, uuid(options))\n }\n}\n"],"version":3}
|
package/dist/types/temporal.js
CHANGED
|
@@ -1,57 +1,56 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Temporal } from
|
|
1
|
+
import { custom, 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(PlainDateType.transformer.decode, PlainDateType.transformer.encode, string());
|
|
19
|
+
}
|
|
20
20
|
}
|
|
21
21
|
export class PlainDateTimeType extends TransformType {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
22
|
+
static transformer = createTemporalTransformer("PlainDateTime");
|
|
23
|
+
static factory() {
|
|
24
|
+
return CustomType.factory(PlainDateTimeType.transformer.decode, PlainDateTimeType.transformer.encode, string());
|
|
25
|
+
}
|
|
27
26
|
}
|
|
28
27
|
export class ZonedDateTimeType extends TransformType {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
static transformer = createTemporalTransformer("ZonedDateTime", (value) => Temporal.Instant.from(value).toZonedDateTimeISO("UTC"));
|
|
29
|
+
static factory() {
|
|
30
|
+
return CustomType.factory(ZonedDateTimeType.transformer.decode, ZonedDateTimeType.transformer.encode, string());
|
|
31
|
+
}
|
|
33
32
|
}
|
|
34
33
|
export class PlainTimeType extends TransformType {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
static transformer = createTemporalTransformer("PlainTime");
|
|
35
|
+
static factory() {
|
|
36
|
+
return CustomType.factory(PlainTimeType.transformer.decode, PlainTimeType.transformer.encode, string());
|
|
37
|
+
}
|
|
39
38
|
}
|
|
40
39
|
export class DurationType extends TransformType {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
static transformer = createTemporalTransformer("Duration");
|
|
41
|
+
static factory() {
|
|
42
|
+
return CustomType.factory(DurationType.transformer.decode, DurationType.transformer.encode, string());
|
|
43
|
+
}
|
|
45
44
|
}
|
|
46
45
|
export class PlainYearMonthType extends TransformType {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
static transformer = createTemporalTransformer("PlainYearMonth");
|
|
47
|
+
static factory() {
|
|
48
|
+
return CustomType.factory(PlainYearMonthType.transformer.decode, PlainYearMonthType.transformer.encode, string());
|
|
49
|
+
}
|
|
51
50
|
}
|
|
52
51
|
export class PlainMonthDayType extends TransformType {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
52
|
+
static transformer = createTemporalTransformer("PlainMonthDay");
|
|
53
|
+
static factory() {
|
|
54
|
+
return CustomType.factory(PlainMonthDayType.transformer.decode, PlainMonthDayType.transformer.encode, string());
|
|
55
|
+
}
|
|
57
56
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"
|
|
1
|
+
{"mappings":"AAAA,SACE,QACA,cAGK,WAAW;AAClB,SAAS,gBAAgB,mBAAmB;AAC5C,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;AAED,OAAO,MAAM,sBAAsB,cAGjC;CACA,OAAO,cAAc,0BAA0B,YAAY;CAE3D,OAAO,UAAU;AACf,SAAO,WAAW,QAKhB,cAAc,YAAY,QAC1B,cAAc,YAAY,QAC1B,QAAQ,CACT;CACF;AACF;AAED,OAAO,MAAM,0BAA0B,cAGrC;CACA,OAAO,cAAc,0BAA0B,gBAAgB;CAE/D,OAAO,UAAU;AACf,SAAO,WAAW,QAKhB,kBAAkB,YAAY,QAC9B,kBAAkB,YAAY,QAC9B,QAAQ,CACT;CACF;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,QAKhB,kBAAkB,YAAY,QAC9B,kBAAkB,YAAY,QAC9B,QAAQ,CACT;CACF;AACF;AAED,OAAO,MAAM,sBAAsB,cAGjC;CACA,OAAO,cAAc,0BAA0B,YAAY;CAE3D,OAAO,UAAU;AACf,SAAO,WAAW,QAKhB,cAAc,YAAY,QAC1B,cAAc,YAAY,QAC1B,QAAQ,CACT;CACF;AACF;AAED,OAAO,MAAM,qBAAqB,cAGhC;CACA,OAAO,cAAc,0BAA0B,WAAW;CAE1D,OAAO,UAAU;AACf,SAAO,WAAW,QAKhB,aAAa,YAAY,QACzB,aAAa,YAAY,QACzB,QAAQ,CACT;CACF;AACF;AAED,OAAO,MAAM,2BAA2B,cAGtC;CACA,OAAO,cAAc,0BAA0B,iBAAiB;CAEhE,OAAO,UAAU;AACf,SAAO,WAAW,QAKhB,mBAAmB,YAAY,QAC/B,mBAAmB,YAAY,QAC/B,QAAQ,CACT;CACF;AACF;AAED,OAAO,MAAM,0BAA0B,cAGrC;CACA,OAAO,cAAc,0BAA0B,gBAAgB;CAE/D,OAAO,UAAU;AACf,SAAO,WAAW,QAKhB,kBAAkB,YAAY,QAC9B,kBAAkB,YAAY,QAC9B,QAAQ,CACT;CACF;AACF","names":["type: T","value: string","value: ReturnType<(typeof Temporal)[T]['from']>"],"sources":["src/types/temporal.ts"],"sourcesContent":["import {\n custom,\n string,\n type ZodMiniCustom,\n type ZodMiniString,\n} 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\nexport class PlainDateType extends TransformType<\n Temporal.PlainDate,\n ZodMiniString\n> {\n static transformer = createTemporalTransformer('PlainDate')\n\n static factory() {\n return CustomType.factory<\n Temporal.PlainDate,\n ZodMiniString,\n ZodMiniCustom<Temporal.PlainDate, Temporal.PlainDate>\n >(\n PlainDateType.transformer.decode,\n PlainDateType.transformer.encode,\n string(),\n )\n }\n}\n\nexport class PlainDateTimeType extends TransformType<\n Temporal.PlainDateTime,\n ZodMiniString\n> {\n static transformer = createTemporalTransformer('PlainDateTime')\n\n static factory() {\n return CustomType.factory<\n Temporal.PlainDateTime,\n ZodMiniString,\n ZodMiniCustom<Temporal.PlainDateTime, Temporal.PlainDateTime>\n >(\n PlainDateTimeType.transformer.decode,\n PlainDateTimeType.transformer.encode,\n string(),\n )\n }\n}\n\nexport class ZonedDateTimeType extends TransformType<\n Temporal.ZonedDateTime,\n ZodMiniString\n> {\n static transformer = createTemporalTransformer('ZonedDateTime', (value) =>\n Temporal.Instant.from(value).toZonedDateTimeISO('UTC'),\n )\n\n static factory() {\n return CustomType.factory<\n Temporal.ZonedDateTime,\n ZodMiniString,\n ZodMiniCustom<Temporal.ZonedDateTime, Temporal.ZonedDateTime>\n >(\n ZonedDateTimeType.transformer.decode,\n ZonedDateTimeType.transformer.encode,\n string(),\n )\n }\n}\n\nexport class PlainTimeType extends TransformType<\n Temporal.PlainTime,\n ZodMiniString\n> {\n static transformer = createTemporalTransformer('PlainTime')\n\n static factory() {\n return CustomType.factory<\n Temporal.PlainTime,\n ZodMiniString,\n ZodMiniCustom<Temporal.PlainTime, Temporal.PlainTime>\n >(\n PlainTimeType.transformer.decode,\n PlainTimeType.transformer.encode,\n string(),\n )\n }\n}\n\nexport class DurationType extends TransformType<\n Temporal.Duration,\n ZodMiniString\n> {\n static transformer = createTemporalTransformer('Duration')\n\n static factory() {\n return CustomType.factory<\n Temporal.Duration,\n ZodMiniString,\n ZodMiniCustom<Temporal.Duration, Temporal.Duration>\n >(\n DurationType.transformer.decode,\n DurationType.transformer.encode,\n string(),\n )\n }\n}\n\nexport class PlainYearMonthType extends TransformType<\n Temporal.PlainYearMonth,\n ZodMiniString\n> {\n static transformer = createTemporalTransformer('PlainYearMonth')\n\n static factory() {\n return CustomType.factory<\n Temporal.PlainYearMonth,\n ZodMiniString,\n ZodMiniCustom<Temporal.PlainYearMonth, Temporal.PlainYearMonth>\n >(\n PlainYearMonthType.transformer.decode,\n PlainYearMonthType.transformer.encode,\n string(),\n )\n }\n}\n\nexport class PlainMonthDayType extends TransformType<\n Temporal.PlainMonthDay,\n ZodMiniString\n> {\n static transformer = createTemporalTransformer('PlainMonthDay')\n\n static factory() {\n return CustomType.factory<\n Temporal.PlainMonthDay,\n ZodMiniString,\n ZodMiniCustom<Temporal.PlainMonthDay, Temporal.PlainMonthDay>\n >(\n PlainMonthDayType.transformer.decode,\n PlainMonthDayType.transformer.encode,\n string(),\n )\n }\n}\n"],"version":3}
|
package/dist/types/union.js
CHANGED
|
@@ -1,25 +1,32 @@
|
|
|
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
|
+
return new IntersactionType({
|
|
15
|
+
encodedZodType: intersection(options[0].encodedZodType, options[1].encodedZodType),
|
|
16
|
+
decodedZodType: intersection(options[0].decodedZodType, options[1].decodedZodType),
|
|
17
|
+
props: { options }
|
|
18
|
+
});
|
|
19
|
+
}
|
|
17
20
|
}
|
|
18
21
|
export class DiscriminatedUnionType extends BaseType {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
static factory(key, ...options) {
|
|
23
|
+
return new DiscriminatedUnionType({
|
|
24
|
+
encodedZodType: discriminatedUnion(options.map((t) => t.encodedZodType)),
|
|
25
|
+
decodedZodType: discriminatedUnion(options.map((t) => t.decodedZodType)),
|
|
26
|
+
props: {
|
|
27
|
+
key,
|
|
28
|
+
options
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
25
32
|
}
|
package/dist/types/union.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"
|
|
1
|
+
{"mappings":"AAAA,SAEE,oBACA,cACA,aAIK,WAAW;AAClB,SAAS,gBAAkC,WAAW;AAItD,OAAO,MAAM,kBAEH,SAIR;CACA,OAAO,QACL,GAAG,SACH;AACA,SAAO,IAAI,UAAa;GACtB,gBAAgB,MAAM,QAAQ,IAAI,CAAC,MAAM,EAAE,eAAe,CAAC;GAC3D,gBAAgB,MAAM,QAAQ,IAAI,CAAC,MAAM,EAAE,eAAe,CAAC;GAC3D,OAAO,EAAE,QAAS;EACnB;CACF;AACF;AAED,OAAO,MAAM,yBAEH,SAIR;CACA,OAAO,QAEL,GAAG,SAAY;AACf,SAAO,IAAI,iBAAoB;GAC7B,gBAAgB,aACd,QAAQ,GAAG,gBACX,QAAQ,GAAG,eACZ;GACD,gBAAgB,aACd,QAAQ,GAAG,gBACX,QAAQ,GAAG,eACZ;GACD,OAAO,EAAE,QAAS;EACnB;CACF;AACF;AAYD,OAAO,MAAM,+BAIH,SAOR;CACA,OAAO,QAILA,KAAQ,GAAG,SAAY;AACvB,SAAO,IAAI,uBAA6B;GACtC,gBAAgB,mBACd,QAAQ,IAAI,CAAC,MAAM,EAAE,eAAe,CACrC;GACD,gBAAgB,mBACd,QAAQ,IAAI,CAAC,MAAM,EAAE,eAAe,CACrC;GACD,OAAO;IAAE;IAAK;GAAS;EACxB;CACF;AACF","names":["key: K"],"sources":["src/types/union.ts"],"sourcesContent":["import {\n type core,\n discriminatedUnion,\n intersection,\n union,\n type ZodMiniDiscriminatedUnion,\n type ZodMiniIntersection,\n type ZodMiniUnion,\n} from '@zod/mini'\nimport { BaseType, type BaseTypeAny } from './base.ts'\nimport type { LiteralType } from './literal.ts'\nimport type { ObjectType, ObjectTypeProps } from './object.ts'\n\nexport class UnionType<\n T extends readonly BaseType[] = readonly BaseType[],\n> extends BaseType<\n ZodMiniUnion<core.utils.Flatten<T[number]['encodedZodType'][]>>,\n ZodMiniUnion<core.utils.Flatten<T[number]['decodedZodType'][]>>,\n { options: T }\n> {\n static factory<T extends readonly BaseType[] = readonly BaseType[]>(\n ...options: T\n ) {\n return new UnionType<T>({\n encodedZodType: union(options.map((t) => t.encodedZodType)),\n decodedZodType: union(options.map((t) => t.decodedZodType)),\n props: { options },\n })\n }\n}\n\nexport class IntersactionType<\n T extends readonly [BaseType, BaseType] = readonly [BaseType, BaseType],\n> extends BaseType<\n ZodMiniIntersection<T[0]['encodedZodType'], T[1]['encodedZodType']>,\n ZodMiniIntersection<T[0]['decodedZodType'], T[1]['decodedZodType']>,\n { options: T }\n> {\n static factory<\n T extends readonly [BaseType, BaseType] = readonly [BaseType, BaseType],\n >(...options: T) {\n return new IntersactionType<T>({\n encodedZodType: intersection(\n options[0].encodedZodType,\n options[1].encodedZodType,\n ),\n decodedZodType: intersection(\n options[0].decodedZodType,\n options[1].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 ZodMiniDiscriminatedUnion<core.utils.Flatten<T[number]['encodedZodType'][]>>,\n ZodMiniDiscriminatedUnion<core.utils.Flatten<T[number]['decodedZodType'][]>>,\n {\n key: K\n options: T\n }\n> {\n static factory<\n K extends string = string,\n T extends\n readonly DiscriminatedUnionOptionType<K>[] = DiscriminatedUnionOptionType<K>[],\n >(key: K, ...options: T) {\n return new DiscriminatedUnionType<K, T>({\n encodedZodType: discriminatedUnion(\n options.map((t) => t.encodedZodType) as any,\n ),\n decodedZodType: discriminatedUnion(\n options.map((t) => t.decodedZodType) as any,\n ),\n props: { key, options },\n })\n }\n}\n"],"version":3}
|
package/dist/utils.js
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"
|
|
1
|
+
{"mappings":"","names":[],"sources":["src/utils.ts"],"sourcesContent":["// export type UnionToIntersectionFn<T> = (\n// T extends unknown\n// ? (k: () => T) => void\n// : never\n// ) extends (k: infer Intersection) => void\n// ? Intersection\n// : never\n// export type GetUnionLast<T> = UnionToIntersectionFn<T> extends () => infer Last\n// ? Last\n// : never\n// export type UnionToTuple<T, Tuple extends unknown[] = []> = [T] extends [never]\n// ? Tuple\n// : UnionToTuple<Exclude<T, GetUnionLast<T>>, [GetUnionLast<T>, ...Tuple]>\n// export type CastToStringTuple<T> = T extends [string, ...string[]] ? T : never\n\n// export type UnionToTupleString<T> = CastToStringTuple<UnionToTuple<T>>\n\n// export type Merge<T, U> = {\n// [K in keyof T | keyof U]: K extends keyof U\n// ? U[K]\n// : K extends keyof T\n// ? T[K]\n// : never\n// }\n"],"version":3}
|