@temporary-name/zod 1.9.3-alpha.a252b3ff8cb6bf7deaa6d41dc9ac8a8d50edd80e → 1.9.3-alpha.afa9ee885873ed8fa674c071639909426419e6f0
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.d.mts +717 -76
- package/dist/index.d.ts +717 -76
- package/dist/index.mjs +1555 -892
- package/package.json +6 -17
- package/dist/zod4/index.d.mts +0 -314
- package/dist/zod4/index.d.ts +0 -314
- package/dist/zod4/index.mjs +0 -743
package/dist/index.mjs
CHANGED
|
@@ -1,955 +1,1618 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
import escapeStringRegexp from 'escape-string-regexp';
|
|
1
|
+
import * as core from 'zod/v4/core';
|
|
2
|
+
import { $ZodError, util, _overwrite, _regex, _includes, _startsWith, _endsWith, _minLength, _maxLength, _length, _lowercase, _uppercase, _trim, _normalize, _toLowerCase, _toUpperCase, _gt, _gte, _lt, _lte, _multipleOf } from 'zod/v4/core';
|
|
3
|
+
export { core };
|
|
4
|
+
export { _endsWith as endsWith, _gt as gt, _gte as gte, _includes as includes, _length as length, _lowercase as lowercase, _lt as lt, _lte as lte, _maxLength as maxLength, _maxSize as maxSize, _mime as mime, _minLength as minLength, _minSize as minSize, _multipleOf as multipleOf, _negative as negative, _nonnegative as nonnegative, _nonpositive as nonpositive, _normalize as normalize, _overwrite as overwrite, _positive as positive, _property as property, _regex as regex, _size as size, _startsWith as startsWith, _toLowerCase as toLowerCase, _toUpperCase as toUpperCase, _trim as trim, _uppercase as uppercase } from 'zod/v4/core';
|
|
5
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
7
6
|
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
const initializer = (inst, issues) => {
|
|
8
|
+
$ZodError.init(inst, issues);
|
|
9
|
+
inst.name = "ZodError";
|
|
10
|
+
Object.defineProperties(inst, {
|
|
11
|
+
format: {
|
|
12
|
+
value: (mapper) => core.formatError(inst, mapper)
|
|
13
|
+
// enumerable: false,
|
|
14
|
+
},
|
|
15
|
+
flatten: {
|
|
16
|
+
value: (mapper) => core.flattenError(inst, mapper)
|
|
17
|
+
// enumerable: false,
|
|
18
|
+
},
|
|
19
|
+
addIssue: {
|
|
20
|
+
value: (issue) => {
|
|
21
|
+
inst.issues.push(issue);
|
|
22
|
+
inst.message = JSON.stringify(inst.issues, core.util.jsonStringifyReplacer, 2);
|
|
23
|
+
}
|
|
24
|
+
// enumerable: false,
|
|
25
|
+
},
|
|
26
|
+
addIssues: {
|
|
27
|
+
value: (issues2) => {
|
|
28
|
+
inst.issues.push(...issues2);
|
|
29
|
+
inst.message = JSON.stringify(inst.issues, core.util.jsonStringifyReplacer, 2);
|
|
30
|
+
}
|
|
31
|
+
// enumerable: false,
|
|
32
|
+
},
|
|
33
|
+
isEmpty: {
|
|
34
|
+
get() {
|
|
35
|
+
return inst.issues.length === 0;
|
|
36
|
+
}
|
|
37
|
+
// enumerable: false,
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
const ZodError = core.$constructor("ZodError", initializer);
|
|
42
|
+
const ZodRealError = core.$constructor("ZodError", initializer, {
|
|
43
|
+
Parent: Error
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const parse = /* @__PURE__ */ core._parse(ZodRealError);
|
|
47
|
+
const parseAsync = /* @__PURE__ */ core._parseAsync(ZodRealError);
|
|
48
|
+
const safeParse = /* @__PURE__ */ core._safeParse(ZodRealError);
|
|
49
|
+
const safeParseAsync = /* @__PURE__ */ core._safeParseAsync(ZodRealError);
|
|
50
|
+
const encode = /* @__PURE__ */ core._encode(ZodRealError);
|
|
51
|
+
const decode = /* @__PURE__ */ core._decode(ZodRealError);
|
|
52
|
+
const encodeAsync = /* @__PURE__ */ core._encodeAsync(ZodRealError);
|
|
53
|
+
const decodeAsync = /* @__PURE__ */ core._decodeAsync(ZodRealError);
|
|
54
|
+
const safeEncode = /* @__PURE__ */ core._safeEncode(ZodRealError);
|
|
55
|
+
const safeDecode = /* @__PURE__ */ core._safeDecode(ZodRealError);
|
|
56
|
+
const safeEncodeAsync = /* @__PURE__ */ core._safeEncodeAsync(ZodRealError);
|
|
57
|
+
const safeDecodeAsync = /* @__PURE__ */ core._safeDecodeAsync(ZodRealError);
|
|
58
|
+
|
|
59
|
+
const KrustyISODateTime = /* @__PURE__ */ core.$constructor(
|
|
60
|
+
"KrustyISODateTime",
|
|
61
|
+
(inst, def) => {
|
|
62
|
+
const coreInit = core.$ZodISODateTime.init;
|
|
63
|
+
coreInit(inst, def);
|
|
64
|
+
KrustyStringFormat.init(inst, def);
|
|
14
65
|
}
|
|
15
|
-
|
|
16
|
-
|
|
66
|
+
);
|
|
67
|
+
function datetime(params) {
|
|
68
|
+
return core._isoDateTime(KrustyISODateTime, params);
|
|
69
|
+
}
|
|
70
|
+
const KrustyISODate = /* @__PURE__ */ core.$constructor(
|
|
71
|
+
"KrustyISODate",
|
|
72
|
+
(inst, def) => {
|
|
73
|
+
const coreInit = core.$ZodISODate.init;
|
|
74
|
+
coreInit(inst, def);
|
|
75
|
+
KrustyStringFormat.init(inst, def);
|
|
17
76
|
}
|
|
18
|
-
|
|
19
|
-
|
|
77
|
+
);
|
|
78
|
+
function date$1(params) {
|
|
79
|
+
return core._isoDate(KrustyISODate, params);
|
|
80
|
+
}
|
|
81
|
+
const KrustyISOTime = /* @__PURE__ */ core.$constructor(
|
|
82
|
+
"KrustyISOTime",
|
|
83
|
+
(inst, def) => {
|
|
84
|
+
const coreInit = core.$ZodISOTime.init;
|
|
85
|
+
coreInit(inst, def);
|
|
86
|
+
KrustyStringFormat.init(inst, def);
|
|
20
87
|
}
|
|
21
|
-
|
|
88
|
+
);
|
|
89
|
+
function time(params) {
|
|
90
|
+
return core._isoTime(KrustyISOTime, params);
|
|
22
91
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
92
|
+
const KrustyISODuration = /* @__PURE__ */ core.$constructor(
|
|
93
|
+
"KrustyISODuration",
|
|
94
|
+
(inst, def) => {
|
|
95
|
+
const coreInit = core.$ZodISODuration.init;
|
|
96
|
+
coreInit(inst, def);
|
|
97
|
+
KrustyStringFormat.init(inst, def);
|
|
98
|
+
}
|
|
99
|
+
);
|
|
100
|
+
function duration(params) {
|
|
101
|
+
return core._isoDuration(KrustyISODuration, params);
|
|
31
102
|
}
|
|
32
103
|
|
|
33
|
-
const
|
|
34
|
-
function
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
function getCustomZodDef(def) {
|
|
38
|
-
return def[CUSTOM_ZOD_DEF_SYMBOL];
|
|
39
|
-
}
|
|
40
|
-
function composeParams(defaultMessage, params) {
|
|
41
|
-
return (val) => {
|
|
42
|
-
const message = defaultMessage(val);
|
|
43
|
-
if (!params) {
|
|
44
|
-
return {
|
|
45
|
-
message
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
if (typeof params === "function") {
|
|
49
|
-
return {
|
|
50
|
-
message,
|
|
51
|
-
...params(val)
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
if (typeof params === "object") {
|
|
55
|
-
return {
|
|
56
|
-
message,
|
|
57
|
-
...params
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
return {
|
|
61
|
-
message: params
|
|
62
|
-
};
|
|
63
|
-
};
|
|
104
|
+
const gatingContext = new AsyncLocalStorage();
|
|
105
|
+
function isGateIssueRaw(issue) {
|
|
106
|
+
return issue.code === "invalid_type" && issue.expected === "never" && issue.inst instanceof KrustyGate;
|
|
64
107
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const schema = custom(
|
|
68
|
-
(val) => val instanceof Blob,
|
|
69
|
-
composeParams(
|
|
70
|
-
() => "Input is not a blob",
|
|
71
|
-
params
|
|
72
|
-
)
|
|
73
|
-
);
|
|
74
|
-
setCustomZodDef(schema._def, { type: "blob" });
|
|
75
|
-
return schema;
|
|
108
|
+
function isGateIssue(issue) {
|
|
109
|
+
return issue.code === "invalid_type" && issue.expected === "never" && issue.path?.length === 0;
|
|
76
110
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
111
|
+
const KrustyGate = /* @__PURE__ */ core.$constructor(
|
|
112
|
+
"KrustyGate",
|
|
113
|
+
(inst, def) => {
|
|
114
|
+
const coreInit = core.$ZodOptional.init;
|
|
115
|
+
coreInit(inst, def);
|
|
116
|
+
KrustyType.init(inst, def);
|
|
117
|
+
inst._zod.parse = (payload, ctx) => {
|
|
118
|
+
const gateEnabled = gatingContext.getStore()?.(def.gateName);
|
|
119
|
+
if (gateEnabled) {
|
|
120
|
+
return def.innerType._zod.run(payload, ctx);
|
|
121
|
+
} else if (payload.value !== void 0) {
|
|
122
|
+
payload.issues.push({
|
|
123
|
+
expected: "never",
|
|
124
|
+
code: "invalid_type",
|
|
125
|
+
input: payload.value,
|
|
126
|
+
inst
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
return payload;
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
);
|
|
133
|
+
function gate(innerType, gateName) {
|
|
134
|
+
return new KrustyGate({
|
|
135
|
+
type: "optional",
|
|
136
|
+
innerType,
|
|
137
|
+
gateName
|
|
100
138
|
});
|
|
101
139
|
}
|
|
102
140
|
|
|
103
|
-
function
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
() =>
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
return schema;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function url(params) {
|
|
116
|
-
const schema = custom(
|
|
117
|
-
(val) => val instanceof URL,
|
|
118
|
-
composeParams(
|
|
119
|
-
() => "Input is not a URL",
|
|
120
|
-
params
|
|
121
|
-
)
|
|
122
|
-
);
|
|
123
|
-
setCustomZodDef(schema._def, { type: "url" });
|
|
124
|
-
return schema;
|
|
141
|
+
function handleGating(payload) {
|
|
142
|
+
for (let i = 0; i < payload.issues.length; i++) {
|
|
143
|
+
const issue = payload.issues[i];
|
|
144
|
+
if (issue?.code === "invalid_union") {
|
|
145
|
+
const newErrors = issue.errors.filter((innerIssues) => !innerIssues.some(isGateIssue));
|
|
146
|
+
issue.errors.splice(0, Infinity, ...newErrors);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return payload;
|
|
125
150
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
151
|
+
const KrustyUnion = /* @__PURE__ */ core.$constructor(
|
|
152
|
+
"KrustyUnion",
|
|
153
|
+
(inst, def) => {
|
|
154
|
+
const coreInit = core.$ZodUnion.init;
|
|
155
|
+
coreInit(inst, def);
|
|
156
|
+
KrustyType.init(inst, def);
|
|
157
|
+
inst.options = def.options;
|
|
158
|
+
const origParse = inst._zod.parse;
|
|
159
|
+
inst._zod.parse = (payload, ctx) => {
|
|
160
|
+
const res = origParse(payload, ctx);
|
|
161
|
+
if (res instanceof Promise) {
|
|
162
|
+
return res.then((r) => handleGating(r));
|
|
163
|
+
} else {
|
|
164
|
+
return handleGating(res);
|
|
134
165
|
}
|
|
135
|
-
|
|
136
|
-
return options2.next({ ...options2, input: coercedInput });
|
|
137
|
-
});
|
|
166
|
+
};
|
|
138
167
|
}
|
|
168
|
+
);
|
|
169
|
+
function union(options, params) {
|
|
170
|
+
return new KrustyUnion({
|
|
171
|
+
type: "union",
|
|
172
|
+
options,
|
|
173
|
+
...util.normalizeParams(params)
|
|
174
|
+
});
|
|
139
175
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
176
|
+
const KrustyDiscriminatedUnion = /* @__PURE__ */ core.$constructor("KrustyDiscriminatedUnion", (inst, def) => {
|
|
177
|
+
KrustyUnion.init(inst, def);
|
|
178
|
+
const coreInit = core.$ZodDiscriminatedUnion.init;
|
|
179
|
+
coreInit(inst, def);
|
|
180
|
+
});
|
|
181
|
+
function discriminatedUnion(discriminator, options, params) {
|
|
182
|
+
return new KrustyDiscriminatedUnion({
|
|
183
|
+
type: "union",
|
|
184
|
+
options,
|
|
185
|
+
discriminator,
|
|
186
|
+
...util.normalizeParams(params)
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function handlePropertyResult(result, final, key, input) {
|
|
191
|
+
if (result.issues.length) {
|
|
192
|
+
final.issues.push(...util.prefixIssues(key, result.issues));
|
|
155
193
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
if (typeof value === "string") {
|
|
160
|
-
return safeToNumber(value);
|
|
161
|
-
}
|
|
162
|
-
return value;
|
|
194
|
+
if (result.value === void 0) {
|
|
195
|
+
if (key in input) {
|
|
196
|
+
final.value[key] = void 0;
|
|
163
197
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
198
|
+
} else {
|
|
199
|
+
final.value[key] = result.value;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
const KrustyObject = /* @__PURE__ */ core.$constructor(
|
|
203
|
+
"KrustyObject",
|
|
204
|
+
(inst, def) => {
|
|
205
|
+
const coreInit = core.$ZodObjectJIT.init;
|
|
206
|
+
coreInit(inst, def);
|
|
207
|
+
KrustyType.init(inst, def);
|
|
208
|
+
util.defineLazy(inst, "shape", () => {
|
|
209
|
+
return def.shape;
|
|
210
|
+
});
|
|
211
|
+
inst.keyof = () => _enum(Object.keys(inst._zod.def.shape));
|
|
212
|
+
inst.catchall = (catchall) => inst.clone({ ...inst._zod.def, catchall });
|
|
213
|
+
inst.passthrough = () => inst.clone({ ...inst._zod.def, catchall: unknown() });
|
|
214
|
+
inst.loose = () => inst.clone({ ...inst._zod.def, catchall: unknown() });
|
|
215
|
+
inst.strict = () => inst.clone({ ...inst._zod.def, catchall: never() });
|
|
216
|
+
inst.strip = () => inst.clone({ ...inst._zod.def, catchall: void 0 });
|
|
217
|
+
inst.extend = (incoming) => {
|
|
218
|
+
return util.extend(inst, incoming);
|
|
219
|
+
};
|
|
220
|
+
inst.safeExtend = (incoming) => {
|
|
221
|
+
return util.safeExtend(inst, incoming);
|
|
222
|
+
};
|
|
223
|
+
inst.merge = (other) => util.merge(inst, other);
|
|
224
|
+
inst.pick = (mask) => util.pick(inst, mask);
|
|
225
|
+
inst.omit = (mask) => util.omit(inst, mask);
|
|
226
|
+
inst.partial = (...args) => util.partial(KrustyOptional, inst, args[0]);
|
|
227
|
+
inst.required = (...args) => util.required(KrustyNonOptional, inst, args[0]);
|
|
228
|
+
function handleGating(input, payload, ctx) {
|
|
229
|
+
const _catchall = def.catchall?._zod;
|
|
230
|
+
const t = _catchall?.def.type;
|
|
231
|
+
let newIssues = null;
|
|
232
|
+
const proms = [];
|
|
233
|
+
const newUnrecognizedKeys = [];
|
|
234
|
+
for (let i = 0; i < payload.issues.length; i++) {
|
|
235
|
+
const issue = payload.issues[i];
|
|
236
|
+
if (!isGateIssueRaw(issue)) {
|
|
237
|
+
continue;
|
|
192
238
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
239
|
+
newIssues ??= [...payload.issues];
|
|
240
|
+
newIssues[i] = null;
|
|
241
|
+
const key = issue.path[0];
|
|
242
|
+
if (!_catchall) {
|
|
243
|
+
delete payload.value[key];
|
|
244
|
+
} else if (t === "never") {
|
|
245
|
+
newUnrecognizedKeys.push(key);
|
|
246
|
+
} else {
|
|
247
|
+
const r = _catchall.run({ value: input[key], issues: [] }, ctx);
|
|
248
|
+
if (r instanceof Promise) {
|
|
249
|
+
proms.push(r.then((r2) => handlePropertyResult(r2, payload, key, input)));
|
|
250
|
+
} else {
|
|
251
|
+
handlePropertyResult(r, payload, key, input);
|
|
205
252
|
}
|
|
206
253
|
}
|
|
207
254
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
case ZodFirstPartyTypeKind.ZodObject: {
|
|
211
|
-
const schema_ = schema;
|
|
212
|
-
if (isObject(value)) {
|
|
213
|
-
const newObj = {};
|
|
214
|
-
const keys = /* @__PURE__ */ new Set([...Object.keys(value), ...Object.keys(schema_.shape)]);
|
|
215
|
-
for (const k of keys) {
|
|
216
|
-
newObj[k] = zodCoerceInternal(schema_.shape[k] ?? schema_._def.catchall, value[k]);
|
|
217
|
-
}
|
|
218
|
-
return newObj;
|
|
219
|
-
}
|
|
220
|
-
return value;
|
|
221
|
-
}
|
|
222
|
-
case ZodFirstPartyTypeKind.ZodRecord: {
|
|
223
|
-
const schema_ = schema;
|
|
224
|
-
if (isObject(value)) {
|
|
225
|
-
const newObj = {};
|
|
226
|
-
for (const [k, v] of Object.entries(value)) {
|
|
227
|
-
const key = zodCoerceInternal(schema_._def.keyType, k);
|
|
228
|
-
const val = zodCoerceInternal(schema_._def.valueType, v);
|
|
229
|
-
newObj[key] = val;
|
|
230
|
-
}
|
|
231
|
-
return newObj;
|
|
232
|
-
}
|
|
233
|
-
return value;
|
|
234
|
-
}
|
|
235
|
-
case ZodFirstPartyTypeKind.ZodArray: {
|
|
236
|
-
const schema_ = schema;
|
|
237
|
-
if (Array.isArray(value)) {
|
|
238
|
-
return value.map((v) => zodCoerceInternal(schema_._def.type, v));
|
|
239
|
-
}
|
|
240
|
-
return value;
|
|
241
|
-
}
|
|
242
|
-
case ZodFirstPartyTypeKind.ZodTuple: {
|
|
243
|
-
const schema_ = schema;
|
|
244
|
-
if (Array.isArray(value)) {
|
|
245
|
-
return value.map((v, i) => {
|
|
246
|
-
const s = schema_._def.items[i] ?? schema_._def.rest;
|
|
247
|
-
return s ? zodCoerceInternal(s, v) : v;
|
|
248
|
-
});
|
|
249
|
-
}
|
|
250
|
-
return value;
|
|
251
|
-
}
|
|
252
|
-
case ZodFirstPartyTypeKind.ZodSet: {
|
|
253
|
-
const schema_ = schema;
|
|
254
|
-
if (Array.isArray(value)) {
|
|
255
|
-
return new Set(value.map((v) => zodCoerceInternal(schema_._def.valueType, v)));
|
|
255
|
+
if (newIssues) {
|
|
256
|
+
payload.issues = newIssues.filter(Boolean);
|
|
256
257
|
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
const schema_ = schema;
|
|
261
|
-
if (Array.isArray(value) && value.every((i) => Array.isArray(i) && i.length === 2)) {
|
|
262
|
-
return new Map(
|
|
263
|
-
value.map(([k, v]) => [
|
|
264
|
-
zodCoerceInternal(schema_._def.keyType, k),
|
|
265
|
-
zodCoerceInternal(schema_._def.valueType, v)
|
|
266
|
-
])
|
|
258
|
+
if (newUnrecognizedKeys.length > 0) {
|
|
259
|
+
const missingKeyIssue = payload.issues.find(
|
|
260
|
+
(issue) => issue.code === "unrecognized_keys" && !issue.path
|
|
267
261
|
);
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
const results = [];
|
|
278
|
-
for (const s of schema_._def.options) {
|
|
279
|
-
const newValue = zodCoerceInternal(s, value);
|
|
280
|
-
const result = schema_.safeParse(newValue);
|
|
281
|
-
if (result.success) {
|
|
282
|
-
return newValue;
|
|
262
|
+
if (missingKeyIssue) {
|
|
263
|
+
missingKeyIssue.keys.push(...newUnrecognizedKeys);
|
|
264
|
+
} else {
|
|
265
|
+
payload.issues.push({
|
|
266
|
+
code: "unrecognized_keys",
|
|
267
|
+
keys: newUnrecognizedKeys,
|
|
268
|
+
input,
|
|
269
|
+
inst
|
|
270
|
+
});
|
|
283
271
|
}
|
|
284
|
-
results.push([newValue, result.error.issues.length]);
|
|
285
272
|
}
|
|
286
|
-
if (
|
|
287
|
-
return
|
|
273
|
+
if (proms.length > 0) {
|
|
274
|
+
return Promise.all(proms).then(() => payload);
|
|
275
|
+
} else {
|
|
276
|
+
return payload;
|
|
288
277
|
}
|
|
289
|
-
return results.sort((a, b) => a[1] - b[1])[0][0];
|
|
290
|
-
}
|
|
291
|
-
case ZodFirstPartyTypeKind.ZodIntersection: {
|
|
292
|
-
const schema_ = schema;
|
|
293
|
-
return zodCoerceInternal(schema_._def.right, zodCoerceInternal(schema_._def.left, value));
|
|
294
|
-
}
|
|
295
|
-
case ZodFirstPartyTypeKind.ZodReadonly: {
|
|
296
|
-
const schema_ = schema;
|
|
297
|
-
return zodCoerceInternal(schema_._def.innerType, value);
|
|
298
278
|
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
279
|
+
const origParse = inst._zod.parse;
|
|
280
|
+
inst._zod.parse = (payload, ctx) => {
|
|
281
|
+
const input = payload.value;
|
|
282
|
+
const res = origParse(payload, ctx);
|
|
283
|
+
if (!def.catchall) {
|
|
284
|
+
const { parseType } = ctx;
|
|
285
|
+
if (parseType && parseType !== "output") {
|
|
286
|
+
const unrecognized = [];
|
|
287
|
+
const keySet = new Set(Object.keys(def.shape));
|
|
288
|
+
for (const key in input) {
|
|
289
|
+
if (!keySet.has(key)) {
|
|
290
|
+
unrecognized.push(key);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
if (unrecognized.length) {
|
|
294
|
+
payload.issues.push({
|
|
295
|
+
code: "unrecognized_keys",
|
|
296
|
+
keys: unrecognized,
|
|
297
|
+
input,
|
|
298
|
+
inst
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
}
|
|
322
302
|
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
if (value === void 0) {
|
|
328
|
-
return void 0;
|
|
303
|
+
if (res instanceof Promise) {
|
|
304
|
+
return res.then((r) => handleGating(input, r, ctx));
|
|
305
|
+
} else {
|
|
306
|
+
return handleGating(input, res, ctx);
|
|
329
307
|
}
|
|
330
|
-
|
|
331
|
-
return zodCoerceInternal(schema_._def.innerType, value);
|
|
332
|
-
}
|
|
333
|
-
case ZodFirstPartyTypeKind.ZodLazy: {
|
|
334
|
-
const schema_ = schema;
|
|
335
|
-
if (value !== void 0) {
|
|
336
|
-
return zodCoerceInternal(schema_._def.getter(), value);
|
|
337
|
-
}
|
|
338
|
-
return value;
|
|
339
|
-
}
|
|
308
|
+
};
|
|
340
309
|
}
|
|
341
|
-
|
|
310
|
+
);
|
|
311
|
+
function object(shape, params) {
|
|
312
|
+
const def = {
|
|
313
|
+
type: "object",
|
|
314
|
+
shape: shape ?? {},
|
|
315
|
+
...util.normalizeParams(params)
|
|
316
|
+
};
|
|
317
|
+
return new KrustyObject(def);
|
|
342
318
|
}
|
|
343
|
-
function
|
|
344
|
-
return
|
|
319
|
+
function strictObject(shape, params) {
|
|
320
|
+
return new KrustyObject({
|
|
321
|
+
type: "object",
|
|
322
|
+
shape,
|
|
323
|
+
catchall: never(),
|
|
324
|
+
...util.normalizeParams(params)
|
|
325
|
+
});
|
|
345
326
|
}
|
|
346
|
-
function
|
|
347
|
-
|
|
348
|
-
|
|
327
|
+
function looseObject(shape, params) {
|
|
328
|
+
return new KrustyObject({
|
|
329
|
+
type: "object",
|
|
330
|
+
shape,
|
|
331
|
+
catchall: unknown(),
|
|
332
|
+
...util.normalizeParams(params)
|
|
333
|
+
});
|
|
349
334
|
}
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
335
|
+
|
|
336
|
+
const KrustyType = /* @__PURE__ */ core.$constructor(
|
|
337
|
+
"KrustyType",
|
|
338
|
+
(inst, def) => {
|
|
339
|
+
const coreInit = core.$ZodType.init;
|
|
340
|
+
coreInit(inst, def);
|
|
341
|
+
inst.def = def;
|
|
342
|
+
inst.type = def.type;
|
|
343
|
+
Object.defineProperty(inst, "_def", { value: def });
|
|
344
|
+
inst.check = (...checks2) => {
|
|
345
|
+
return inst.clone(
|
|
346
|
+
util.mergeDefs(def, {
|
|
347
|
+
checks: [
|
|
348
|
+
...def.checks ?? [],
|
|
349
|
+
...checks2.map(
|
|
350
|
+
(ch) => typeof ch === "function" ? { _zod: { check: ch, def: { check: "custom" }, onattach: [] } } : ch
|
|
351
|
+
)
|
|
352
|
+
]
|
|
353
|
+
})
|
|
354
|
+
);
|
|
355
|
+
};
|
|
356
|
+
inst.clone = (def2, params) => core.clone(inst, def2, params);
|
|
357
|
+
inst.brand = () => inst;
|
|
358
|
+
inst.register = ((reg, meta) => {
|
|
359
|
+
reg.add(inst, meta);
|
|
360
|
+
return inst;
|
|
361
|
+
});
|
|
362
|
+
inst.refine = (check2, params) => inst.check(refine(check2, params));
|
|
363
|
+
inst.superRefine = (refinement) => inst.check(superRefine(refinement));
|
|
364
|
+
inst.overwrite = (fn) => inst.check(_overwrite(fn));
|
|
365
|
+
inst.gate = (gateName) => gate(inst, gateName);
|
|
366
|
+
inst.optional = () => optional(inst);
|
|
367
|
+
inst.nullable = () => nullable(inst);
|
|
368
|
+
inst.nullish = () => optional(nullable(inst));
|
|
369
|
+
inst.nonoptional = (params) => nonoptional(inst, params);
|
|
370
|
+
inst.array = () => array(inst);
|
|
371
|
+
inst.or = (arg) => union([inst, arg]);
|
|
372
|
+
inst.and = (arg) => intersection(inst, arg);
|
|
373
|
+
inst.transform = (tx) => pipe(inst, transform(tx));
|
|
374
|
+
inst.default = (def2) => _default(inst, def2);
|
|
375
|
+
inst.prefault = (def2) => prefault(inst, def2);
|
|
376
|
+
return inst;
|
|
377
|
+
}
|
|
378
|
+
);
|
|
379
|
+
const _KrustyString = /* @__PURE__ */ core.$constructor(
|
|
380
|
+
"_KrustyString",
|
|
381
|
+
(inst, def) => {
|
|
382
|
+
const coreInit = core.$ZodString.init;
|
|
383
|
+
coreInit(inst, def);
|
|
384
|
+
KrustyType.init(inst, def);
|
|
385
|
+
const bag = inst._zod.bag;
|
|
386
|
+
inst.format = bag.format ?? null;
|
|
387
|
+
inst.minLength = bag.minimum ?? null;
|
|
388
|
+
inst.maxLength = bag.maximum ?? null;
|
|
389
|
+
inst.regex = (...args) => inst.check(_regex(...args));
|
|
390
|
+
inst.includes = (...args) => inst.check(_includes(...args));
|
|
391
|
+
inst.startsWith = (...args) => inst.check(_startsWith(...args));
|
|
392
|
+
inst.endsWith = (...args) => inst.check(_endsWith(...args));
|
|
393
|
+
inst.min = (...args) => inst.check(_minLength(...args));
|
|
394
|
+
inst.max = (...args) => inst.check(_maxLength(...args));
|
|
395
|
+
inst.length = (...args) => inst.check(_length(...args));
|
|
396
|
+
inst.nonempty = (...args) => inst.check(_minLength(1, ...args));
|
|
397
|
+
inst.lowercase = (params) => inst.check(_lowercase(params));
|
|
398
|
+
inst.uppercase = (params) => inst.check(_uppercase(params));
|
|
399
|
+
inst.trim = () => inst.check(_trim());
|
|
400
|
+
inst.normalize = (...args) => inst.check(_normalize(...args));
|
|
401
|
+
inst.toLowerCase = () => inst.check(_toLowerCase());
|
|
402
|
+
inst.toUpperCase = () => inst.check(_toUpperCase());
|
|
354
403
|
}
|
|
355
|
-
|
|
356
|
-
|
|
404
|
+
);
|
|
405
|
+
const KrustyString = /* @__PURE__ */ core.$constructor(
|
|
406
|
+
"KrustyString",
|
|
407
|
+
(inst, def) => {
|
|
408
|
+
const coreInit = core.$ZodString.init;
|
|
409
|
+
coreInit(inst, def);
|
|
410
|
+
_KrustyString.init(inst, def);
|
|
411
|
+
inst.email = (params) => inst.check(core._email(KrustyEmail, params));
|
|
412
|
+
inst.url = (params) => inst.check(core._url(KrustyURL, params));
|
|
413
|
+
inst.jwt = (params) => inst.check(core._jwt(KrustyJWT, params));
|
|
414
|
+
inst.emoji = (params) => inst.check(core._emoji(KrustyEmoji, params));
|
|
415
|
+
inst.guid = (params) => inst.check(core._guid(KrustyGUID, params));
|
|
416
|
+
inst.uuid = (params) => inst.check(core._uuid(KrustyUUID, params));
|
|
417
|
+
inst.uuidv4 = (params) => inst.check(core._uuidv4(KrustyUUID, params));
|
|
418
|
+
inst.uuidv6 = (params) => inst.check(core._uuidv6(KrustyUUID, params));
|
|
419
|
+
inst.uuidv7 = (params) => inst.check(core._uuidv7(KrustyUUID, params));
|
|
420
|
+
inst.nanoid = (params) => inst.check(core._nanoid(KrustyNanoID, params));
|
|
421
|
+
inst.guid = (params) => inst.check(core._guid(KrustyGUID, params));
|
|
422
|
+
inst.cuid = (params) => inst.check(core._cuid(KrustyCUID, params));
|
|
423
|
+
inst.cuid2 = (params) => inst.check(core._cuid2(KrustyCUID2, params));
|
|
424
|
+
inst.ulid = (params) => inst.check(core._ulid(KrustyULID, params));
|
|
425
|
+
inst.base64 = (params) => inst.check(core._base64(KrustyBase64, params));
|
|
426
|
+
inst.base64url = (params) => inst.check(core._base64url(KrustyBase64URL, params));
|
|
427
|
+
inst.xid = (params) => inst.check(core._xid(KrustyXID, params));
|
|
428
|
+
inst.ksuid = (params) => inst.check(core._ksuid(KrustyKSUID, params));
|
|
429
|
+
inst.ipv4 = (params) => inst.check(core._ipv4(KrustyIPv4, params));
|
|
430
|
+
inst.ipv6 = (params) => inst.check(core._ipv6(KrustyIPv6, params));
|
|
431
|
+
inst.cidrv4 = (params) => inst.check(core._cidrv4(KrustyCIDRv4, params));
|
|
432
|
+
inst.cidrv6 = (params) => inst.check(core._cidrv6(KrustyCIDRv6, params));
|
|
433
|
+
inst.e164 = (params) => inst.check(core._e164(KrustyE164, params));
|
|
434
|
+
inst.datetime = (params) => inst.check(datetime(params));
|
|
435
|
+
inst.date = (params) => inst.check(date$1(params));
|
|
436
|
+
inst.time = (params) => inst.check(time(params));
|
|
437
|
+
inst.duration = (params) => inst.check(duration(params));
|
|
357
438
|
}
|
|
358
|
-
|
|
439
|
+
);
|
|
440
|
+
function string(params) {
|
|
441
|
+
return core._string(KrustyString, params);
|
|
359
442
|
}
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
}
|
|
443
|
+
const KrustyStringFormat = /* @__PURE__ */ core.$constructor(
|
|
444
|
+
"KrustyStringFormat",
|
|
445
|
+
(inst, def) => {
|
|
446
|
+
const coreInit = core.$ZodStringFormat.init;
|
|
447
|
+
coreInit(inst, def);
|
|
448
|
+
_KrustyString.init(inst, def);
|
|
367
449
|
}
|
|
368
|
-
|
|
450
|
+
);
|
|
451
|
+
const KrustyEmail = /* @__PURE__ */ core.$constructor(
|
|
452
|
+
"KrustyEmail",
|
|
453
|
+
(inst, def) => {
|
|
454
|
+
const coreInit = core.$ZodEmail.init;
|
|
455
|
+
coreInit(inst, def);
|
|
456
|
+
KrustyStringFormat.init(inst, def);
|
|
457
|
+
}
|
|
458
|
+
);
|
|
459
|
+
function email(params) {
|
|
460
|
+
return core._email(KrustyEmail, params);
|
|
369
461
|
}
|
|
370
|
-
|
|
371
|
-
|
|
462
|
+
const KrustyGUID = /* @__PURE__ */ core.$constructor(
|
|
463
|
+
"KrustyGUID",
|
|
464
|
+
(inst, def) => {
|
|
465
|
+
const coreInit = core.$ZodGUID.init;
|
|
466
|
+
coreInit(inst, def);
|
|
467
|
+
KrustyStringFormat.init(inst, def);
|
|
468
|
+
}
|
|
469
|
+
);
|
|
470
|
+
function guid(params) {
|
|
471
|
+
return core._guid(KrustyGUID, params);
|
|
372
472
|
}
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
473
|
+
const KrustyUUID = /* @__PURE__ */ core.$constructor(
|
|
474
|
+
"KrustyUUID",
|
|
475
|
+
(inst, def) => {
|
|
476
|
+
const coreInit = core.$ZodUUID.init;
|
|
477
|
+
coreInit(inst, def);
|
|
478
|
+
KrustyStringFormat.init(inst, def);
|
|
377
479
|
}
|
|
378
|
-
|
|
480
|
+
);
|
|
481
|
+
function uuid(params) {
|
|
482
|
+
return core._uuid(KrustyUUID, params);
|
|
379
483
|
}
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
const prefixItems = [];
|
|
628
|
-
const json = { type: "array" };
|
|
629
|
-
for (const item of schema_._def.items) {
|
|
630
|
-
const [itemRequired, itemJson] = this.convert(
|
|
631
|
-
item,
|
|
632
|
-
options,
|
|
633
|
-
lazyDepth,
|
|
634
|
-
false,
|
|
635
|
-
false,
|
|
636
|
-
structureDepth + 1
|
|
637
|
-
);
|
|
638
|
-
prefixItems.push(this.#toArrayItemJsonSchema(itemRequired, itemJson, options.strategy));
|
|
639
|
-
}
|
|
640
|
-
if (prefixItems?.length) {
|
|
641
|
-
json.prefixItems = prefixItems;
|
|
642
|
-
}
|
|
643
|
-
if (schema_._def.rest) {
|
|
644
|
-
const [itemRequired, itemJson] = this.convert(
|
|
645
|
-
schema_._def.rest,
|
|
646
|
-
options,
|
|
647
|
-
lazyDepth,
|
|
648
|
-
false,
|
|
649
|
-
false,
|
|
650
|
-
structureDepth + 1
|
|
651
|
-
);
|
|
652
|
-
json.items = this.#toArrayItemJsonSchema(itemRequired, itemJson, options.strategy);
|
|
484
|
+
function uuidv4(params) {
|
|
485
|
+
return core._uuidv4(KrustyUUID, params);
|
|
486
|
+
}
|
|
487
|
+
function uuidv6(params) {
|
|
488
|
+
return core._uuidv6(KrustyUUID, params);
|
|
489
|
+
}
|
|
490
|
+
function uuidv7(params) {
|
|
491
|
+
return core._uuidv7(KrustyUUID, params);
|
|
492
|
+
}
|
|
493
|
+
const KrustyURL = /* @__PURE__ */ core.$constructor(
|
|
494
|
+
"KrustyURL",
|
|
495
|
+
(inst, def) => {
|
|
496
|
+
const coreInit = core.$ZodURL.init;
|
|
497
|
+
coreInit(inst, def);
|
|
498
|
+
KrustyStringFormat.init(inst, def);
|
|
499
|
+
}
|
|
500
|
+
);
|
|
501
|
+
function url(params) {
|
|
502
|
+
return core._url(KrustyURL, params);
|
|
503
|
+
}
|
|
504
|
+
function httpUrl(params) {
|
|
505
|
+
return core._url(KrustyURL, {
|
|
506
|
+
protocol: /^https?$/,
|
|
507
|
+
hostname: core.regexes.domain,
|
|
508
|
+
...util.normalizeParams(params)
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
const KrustyEmoji = /* @__PURE__ */ core.$constructor(
|
|
512
|
+
"KrustyEmoji",
|
|
513
|
+
(inst, def) => {
|
|
514
|
+
const coreInit = core.$ZodEmoji.init;
|
|
515
|
+
coreInit(inst, def);
|
|
516
|
+
KrustyStringFormat.init(inst, def);
|
|
517
|
+
}
|
|
518
|
+
);
|
|
519
|
+
function emoji(params) {
|
|
520
|
+
return core._emoji(KrustyEmoji, params);
|
|
521
|
+
}
|
|
522
|
+
const KrustyNanoID = /* @__PURE__ */ core.$constructor(
|
|
523
|
+
"KrustyNanoID",
|
|
524
|
+
(inst, def) => {
|
|
525
|
+
const coreInit = core.$ZodNanoID.init;
|
|
526
|
+
coreInit(inst, def);
|
|
527
|
+
KrustyStringFormat.init(inst, def);
|
|
528
|
+
}
|
|
529
|
+
);
|
|
530
|
+
function nanoid(params) {
|
|
531
|
+
return core._nanoid(KrustyNanoID, params);
|
|
532
|
+
}
|
|
533
|
+
const KrustyCUID = /* @__PURE__ */ core.$constructor(
|
|
534
|
+
"KrustyCUID",
|
|
535
|
+
(inst, def) => {
|
|
536
|
+
const coreInit = core.$ZodCUID.init;
|
|
537
|
+
coreInit(inst, def);
|
|
538
|
+
KrustyStringFormat.init(inst, def);
|
|
539
|
+
}
|
|
540
|
+
);
|
|
541
|
+
function cuid(params) {
|
|
542
|
+
return core._cuid(KrustyCUID, params);
|
|
543
|
+
}
|
|
544
|
+
const KrustyCUID2 = /* @__PURE__ */ core.$constructor(
|
|
545
|
+
"KrustyCUID2",
|
|
546
|
+
(inst, def) => {
|
|
547
|
+
const coreInit = core.$ZodCUID2.init;
|
|
548
|
+
coreInit(inst, def);
|
|
549
|
+
KrustyStringFormat.init(inst, def);
|
|
550
|
+
}
|
|
551
|
+
);
|
|
552
|
+
function cuid2(params) {
|
|
553
|
+
return core._cuid2(KrustyCUID2, params);
|
|
554
|
+
}
|
|
555
|
+
const KrustyULID = /* @__PURE__ */ core.$constructor(
|
|
556
|
+
"KrustyULID",
|
|
557
|
+
(inst, def) => {
|
|
558
|
+
const coreInit = core.$ZodULID.init;
|
|
559
|
+
coreInit(inst, def);
|
|
560
|
+
KrustyStringFormat.init(inst, def);
|
|
561
|
+
}
|
|
562
|
+
);
|
|
563
|
+
function ulid(params) {
|
|
564
|
+
return core._ulid(KrustyULID, params);
|
|
565
|
+
}
|
|
566
|
+
const KrustyXID = /* @__PURE__ */ core.$constructor(
|
|
567
|
+
"KrustyXID",
|
|
568
|
+
(inst, def) => {
|
|
569
|
+
const coreInit = core.$ZodXID.init;
|
|
570
|
+
coreInit(inst, def);
|
|
571
|
+
KrustyStringFormat.init(inst, def);
|
|
572
|
+
}
|
|
573
|
+
);
|
|
574
|
+
function xid(params) {
|
|
575
|
+
return core._xid(KrustyXID, params);
|
|
576
|
+
}
|
|
577
|
+
const KrustyKSUID = /* @__PURE__ */ core.$constructor(
|
|
578
|
+
"KrustyKSUID",
|
|
579
|
+
(inst, def) => {
|
|
580
|
+
const coreInit = core.$ZodKSUID.init;
|
|
581
|
+
coreInit(inst, def);
|
|
582
|
+
KrustyStringFormat.init(inst, def);
|
|
583
|
+
}
|
|
584
|
+
);
|
|
585
|
+
function ksuid(params) {
|
|
586
|
+
return core._ksuid(KrustyKSUID, params);
|
|
587
|
+
}
|
|
588
|
+
const KrustyIPv4 = /* @__PURE__ */ core.$constructor(
|
|
589
|
+
"KrustyIPv4",
|
|
590
|
+
(inst, def) => {
|
|
591
|
+
const coreInit = core.$ZodIPv4.init;
|
|
592
|
+
coreInit(inst, def);
|
|
593
|
+
KrustyStringFormat.init(inst, def);
|
|
594
|
+
}
|
|
595
|
+
);
|
|
596
|
+
function ipv4(params) {
|
|
597
|
+
return core._ipv4(KrustyIPv4, params);
|
|
598
|
+
}
|
|
599
|
+
const KrustyIPv6 = /* @__PURE__ */ core.$constructor(
|
|
600
|
+
"KrustyIPv6",
|
|
601
|
+
(inst, def) => {
|
|
602
|
+
const coreInit = core.$ZodIPv6.init;
|
|
603
|
+
coreInit(inst, def);
|
|
604
|
+
KrustyStringFormat.init(inst, def);
|
|
605
|
+
}
|
|
606
|
+
);
|
|
607
|
+
function ipv6(params) {
|
|
608
|
+
return core._ipv6(KrustyIPv6, params);
|
|
609
|
+
}
|
|
610
|
+
const KrustyCIDRv4 = /* @__PURE__ */ core.$constructor(
|
|
611
|
+
"KrustyCIDRv4",
|
|
612
|
+
(inst, def) => {
|
|
613
|
+
const coreInit = core.$ZodCIDRv4.init;
|
|
614
|
+
coreInit(inst, def);
|
|
615
|
+
KrustyStringFormat.init(inst, def);
|
|
616
|
+
}
|
|
617
|
+
);
|
|
618
|
+
function cidrv4(params) {
|
|
619
|
+
return core._cidrv4(KrustyCIDRv4, params);
|
|
620
|
+
}
|
|
621
|
+
const KrustyCIDRv6 = /* @__PURE__ */ core.$constructor(
|
|
622
|
+
"KrustyCIDRv6",
|
|
623
|
+
(inst, def) => {
|
|
624
|
+
const coreInit = core.$ZodCIDRv6.init;
|
|
625
|
+
coreInit(inst, def);
|
|
626
|
+
KrustyStringFormat.init(inst, def);
|
|
627
|
+
}
|
|
628
|
+
);
|
|
629
|
+
function cidrv6(params) {
|
|
630
|
+
return core._cidrv6(KrustyCIDRv6, params);
|
|
631
|
+
}
|
|
632
|
+
const KrustyBase64 = /* @__PURE__ */ core.$constructor(
|
|
633
|
+
"KrustyBase64",
|
|
634
|
+
(inst, def) => {
|
|
635
|
+
const coreInit = core.$ZodBase64.init;
|
|
636
|
+
coreInit(inst, def);
|
|
637
|
+
KrustyStringFormat.init(inst, def);
|
|
638
|
+
}
|
|
639
|
+
);
|
|
640
|
+
function base64(params) {
|
|
641
|
+
return core._base64(KrustyBase64, params);
|
|
642
|
+
}
|
|
643
|
+
const KrustyBase64URL = /* @__PURE__ */ core.$constructor(
|
|
644
|
+
"KrustyBase64URL",
|
|
645
|
+
(inst, def) => {
|
|
646
|
+
const coreInit = core.$ZodBase64URL.init;
|
|
647
|
+
coreInit(inst, def);
|
|
648
|
+
KrustyStringFormat.init(inst, def);
|
|
649
|
+
}
|
|
650
|
+
);
|
|
651
|
+
function base64url(params) {
|
|
652
|
+
return core._base64url(KrustyBase64URL, params);
|
|
653
|
+
}
|
|
654
|
+
const KrustyE164 = /* @__PURE__ */ core.$constructor(
|
|
655
|
+
"KrustyE164",
|
|
656
|
+
(inst, def) => {
|
|
657
|
+
const coreInit = core.$ZodE164.init;
|
|
658
|
+
coreInit(inst, def);
|
|
659
|
+
KrustyStringFormat.init(inst, def);
|
|
660
|
+
}
|
|
661
|
+
);
|
|
662
|
+
function e164(params) {
|
|
663
|
+
return core._e164(KrustyE164, params);
|
|
664
|
+
}
|
|
665
|
+
const KrustyJWT = /* @__PURE__ */ core.$constructor(
|
|
666
|
+
"KrustyJWT",
|
|
667
|
+
(inst, def) => {
|
|
668
|
+
const coreInit = core.$ZodJWT.init;
|
|
669
|
+
coreInit(inst, def);
|
|
670
|
+
KrustyStringFormat.init(inst, def);
|
|
671
|
+
}
|
|
672
|
+
);
|
|
673
|
+
function jwt(params) {
|
|
674
|
+
return core._jwt(KrustyJWT, params);
|
|
675
|
+
}
|
|
676
|
+
const KrustyCustomStringFormat = /* @__PURE__ */ core.$constructor("KrustyCustomStringFormat", (inst, def) => {
|
|
677
|
+
const coreInit = core.$ZodCustomStringFormat.init;
|
|
678
|
+
coreInit(inst, def);
|
|
679
|
+
KrustyStringFormat.init(inst, def);
|
|
680
|
+
});
|
|
681
|
+
function stringFormat(format, fnOrRegex, _params = {}) {
|
|
682
|
+
return core._stringFormat(KrustyCustomStringFormat, format, fnOrRegex, _params);
|
|
683
|
+
}
|
|
684
|
+
function hostname(_params) {
|
|
685
|
+
return core._stringFormat(KrustyCustomStringFormat, "hostname", core.regexes.hostname, _params);
|
|
686
|
+
}
|
|
687
|
+
function hex(_params) {
|
|
688
|
+
return core._stringFormat(KrustyCustomStringFormat, "hex", core.regexes.hex, _params);
|
|
689
|
+
}
|
|
690
|
+
function hash(alg, params) {
|
|
691
|
+
const enc = params?.enc ?? "hex";
|
|
692
|
+
const format = `${alg}_${enc}`;
|
|
693
|
+
const regex = core.regexes[format];
|
|
694
|
+
if (!regex) throw new Error(`Unrecognized hash format: ${format}`);
|
|
695
|
+
return core._stringFormat(KrustyCustomStringFormat, format, regex, params);
|
|
696
|
+
}
|
|
697
|
+
const KrustyNumber = /* @__PURE__ */ core.$constructor(
|
|
698
|
+
"KrustyNumber",
|
|
699
|
+
(inst, def) => {
|
|
700
|
+
const coreInit = core.$ZodNumber.init;
|
|
701
|
+
coreInit(inst, def);
|
|
702
|
+
KrustyType.init(inst, def);
|
|
703
|
+
inst.gt = (value, params) => inst.check(_gt(value, params));
|
|
704
|
+
inst.gte = (value, params) => inst.check(_gte(value, params));
|
|
705
|
+
inst.min = (value, params) => inst.check(_gte(value, params));
|
|
706
|
+
inst.lt = (value, params) => inst.check(_lt(value, params));
|
|
707
|
+
inst.lte = (value, params) => inst.check(_lte(value, params));
|
|
708
|
+
inst.max = (value, params) => inst.check(_lte(value, params));
|
|
709
|
+
inst.int = (params) => inst.check(int(params));
|
|
710
|
+
inst.safe = (params) => inst.check(int(params));
|
|
711
|
+
inst.positive = (params) => inst.check(_gt(0, params));
|
|
712
|
+
inst.nonnegative = (params) => inst.check(_gte(0, params));
|
|
713
|
+
inst.negative = (params) => inst.check(_lt(0, params));
|
|
714
|
+
inst.nonpositive = (params) => inst.check(_lte(0, params));
|
|
715
|
+
inst.multipleOf = (value, params) => inst.check(_multipleOf(value, params));
|
|
716
|
+
inst.step = (value, params) => inst.check(_multipleOf(value, params));
|
|
717
|
+
inst.finite = () => inst;
|
|
718
|
+
const bag = inst._zod.bag;
|
|
719
|
+
inst.minValue = Math.max(bag.minimum ?? Number.NEGATIVE_INFINITY, bag.exclusiveMinimum ?? Number.NEGATIVE_INFINITY) ?? null;
|
|
720
|
+
inst.maxValue = Math.min(bag.maximum ?? Number.POSITIVE_INFINITY, bag.exclusiveMaximum ?? Number.POSITIVE_INFINITY) ?? null;
|
|
721
|
+
inst.isInt = (bag.format ?? "").includes("int") || Number.isSafeInteger(bag.multipleOf ?? 0.5);
|
|
722
|
+
inst.isFinite = true;
|
|
723
|
+
inst.format = bag.format ?? null;
|
|
724
|
+
const origParse = inst._zod.parse;
|
|
725
|
+
inst._zod.parse = (payload, ctx) => {
|
|
726
|
+
const { parseType } = ctx;
|
|
727
|
+
if (parseType === "query" && typeof payload.value === "string") {
|
|
728
|
+
const value = Number(payload.value);
|
|
729
|
+
if (!Number.isNaN(value)) {
|
|
730
|
+
payload.value = value;
|
|
653
731
|
}
|
|
654
|
-
return [true, json];
|
|
655
732
|
}
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
733
|
+
return origParse(payload, ctx);
|
|
734
|
+
};
|
|
735
|
+
}
|
|
736
|
+
);
|
|
737
|
+
function number(params) {
|
|
738
|
+
return core._number(KrustyNumber, params);
|
|
739
|
+
}
|
|
740
|
+
const KrustyNumberFormat = /* @__PURE__ */ core.$constructor(
|
|
741
|
+
"KrustyNumberFormat",
|
|
742
|
+
(inst, def) => {
|
|
743
|
+
const coreInit = core.$ZodNumberFormat.init;
|
|
744
|
+
coreInit(inst, def);
|
|
745
|
+
KrustyNumber.init(inst, def);
|
|
746
|
+
}
|
|
747
|
+
);
|
|
748
|
+
function int(params) {
|
|
749
|
+
return core._int(KrustyNumberFormat, params);
|
|
750
|
+
}
|
|
751
|
+
function float32(params) {
|
|
752
|
+
return core._float32(KrustyNumberFormat, params);
|
|
753
|
+
}
|
|
754
|
+
function float64(params) {
|
|
755
|
+
return core._float64(KrustyNumberFormat, params);
|
|
756
|
+
}
|
|
757
|
+
function int32(params) {
|
|
758
|
+
return core._int32(KrustyNumberFormat, params);
|
|
759
|
+
}
|
|
760
|
+
function uint32(params) {
|
|
761
|
+
return core._uint32(KrustyNumberFormat, params);
|
|
762
|
+
}
|
|
763
|
+
const KrustyBoolean = /* @__PURE__ */ core.$constructor(
|
|
764
|
+
"KrustyBoolean",
|
|
765
|
+
(inst, def) => {
|
|
766
|
+
const coreInit = core.$ZodBoolean.init;
|
|
767
|
+
coreInit(inst, def);
|
|
768
|
+
KrustyType.init(inst, def);
|
|
769
|
+
const origParse = inst._zod.parse;
|
|
770
|
+
inst._zod.parse = (payload, ctx) => {
|
|
771
|
+
const { parseType } = ctx;
|
|
772
|
+
if (parseType === "query") {
|
|
773
|
+
if (payload.value === "true") {
|
|
774
|
+
payload.value = true;
|
|
775
|
+
} else if (payload.value === "false") {
|
|
776
|
+
payload.value = false;
|
|
686
777
|
} else {
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
);
|
|
695
|
-
|
|
778
|
+
payload.issues.push({
|
|
779
|
+
code: "invalid_type",
|
|
780
|
+
expected: "boolean",
|
|
781
|
+
values: ["true", "false"],
|
|
782
|
+
input: payload.value,
|
|
783
|
+
inst,
|
|
784
|
+
continue: false
|
|
785
|
+
});
|
|
786
|
+
return payload;
|
|
696
787
|
}
|
|
697
|
-
return [true, json];
|
|
698
|
-
}
|
|
699
|
-
case ZodFirstPartyTypeKind.ZodRecord: {
|
|
700
|
-
const schema_ = schema;
|
|
701
|
-
const json = { type: "object" };
|
|
702
|
-
const [__, keyJson] = this.convert(
|
|
703
|
-
schema_._def.keyType,
|
|
704
|
-
options,
|
|
705
|
-
lazyDepth,
|
|
706
|
-
false,
|
|
707
|
-
false,
|
|
708
|
-
structureDepth + 1
|
|
709
|
-
);
|
|
710
|
-
if (Object.entries(keyJson).some(([k, v]) => k !== "type" || v !== "string")) {
|
|
711
|
-
json.propertyNames = keyJson;
|
|
712
|
-
}
|
|
713
|
-
const [_, itemJson] = this.convert(
|
|
714
|
-
schema_._def.valueType,
|
|
715
|
-
options,
|
|
716
|
-
lazyDepth,
|
|
717
|
-
false,
|
|
718
|
-
false,
|
|
719
|
-
structureDepth + 1
|
|
720
|
-
);
|
|
721
|
-
json.additionalProperties = itemJson;
|
|
722
|
-
return [true, json];
|
|
723
|
-
}
|
|
724
|
-
case ZodFirstPartyTypeKind.ZodSet: {
|
|
725
|
-
const schema_ = schema;
|
|
726
|
-
const json = {
|
|
727
|
-
type: "array",
|
|
728
|
-
uniqueItems: true,
|
|
729
|
-
"x-native-type": JsonSchemaXNativeType.Set
|
|
730
|
-
};
|
|
731
|
-
const [itemRequired, itemJson] = this.convert(
|
|
732
|
-
schema_._def.valueType,
|
|
733
|
-
options,
|
|
734
|
-
lazyDepth,
|
|
735
|
-
false,
|
|
736
|
-
false,
|
|
737
|
-
structureDepth + 1
|
|
738
|
-
);
|
|
739
|
-
json.items = this.#toArrayItemJsonSchema(itemRequired, itemJson, options.strategy);
|
|
740
|
-
return [true, json];
|
|
741
788
|
}
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
789
|
+
return origParse(payload, ctx);
|
|
790
|
+
};
|
|
791
|
+
}
|
|
792
|
+
);
|
|
793
|
+
function boolean(params) {
|
|
794
|
+
return core._boolean(KrustyBoolean, params);
|
|
795
|
+
}
|
|
796
|
+
const KrustyBigInt = /* @__PURE__ */ core.$constructor(
|
|
797
|
+
"KrustyBigInt",
|
|
798
|
+
(inst, def) => {
|
|
799
|
+
const coreInit = core.$ZodBigInt.init;
|
|
800
|
+
coreInit(inst, def);
|
|
801
|
+
KrustyType.init(inst, def);
|
|
802
|
+
inst.gte = (value, params) => inst.check(_gte(value, params));
|
|
803
|
+
inst.min = (value, params) => inst.check(_gte(value, params));
|
|
804
|
+
inst.gt = (value, params) => inst.check(_gt(value, params));
|
|
805
|
+
inst.gte = (value, params) => inst.check(_gte(value, params));
|
|
806
|
+
inst.min = (value, params) => inst.check(_gte(value, params));
|
|
807
|
+
inst.lt = (value, params) => inst.check(_lt(value, params));
|
|
808
|
+
inst.lte = (value, params) => inst.check(_lte(value, params));
|
|
809
|
+
inst.max = (value, params) => inst.check(_lte(value, params));
|
|
810
|
+
inst.positive = (params) => inst.check(_gt(BigInt(0), params));
|
|
811
|
+
inst.negative = (params) => inst.check(_lt(BigInt(0), params));
|
|
812
|
+
inst.nonpositive = (params) => inst.check(_lte(BigInt(0), params));
|
|
813
|
+
inst.nonnegative = (params) => inst.check(_gte(BigInt(0), params));
|
|
814
|
+
inst.multipleOf = (value, params) => inst.check(_multipleOf(value, params));
|
|
815
|
+
const bag = inst._zod.bag;
|
|
816
|
+
inst.minValue = bag.minimum ?? null;
|
|
817
|
+
inst.maxValue = bag.maximum ?? null;
|
|
818
|
+
inst.format = bag.format ?? null;
|
|
819
|
+
}
|
|
820
|
+
);
|
|
821
|
+
function bigint(params) {
|
|
822
|
+
return core._bigint(KrustyBigInt, params);
|
|
823
|
+
}
|
|
824
|
+
const KrustyBigIntFormat = /* @__PURE__ */ core.$constructor(
|
|
825
|
+
"KrustyBigIntFormat",
|
|
826
|
+
(inst, def) => {
|
|
827
|
+
const coreInit = core.$ZodBigIntFormat.init;
|
|
828
|
+
coreInit(inst, def);
|
|
829
|
+
KrustyBigInt.init(inst, def);
|
|
830
|
+
}
|
|
831
|
+
);
|
|
832
|
+
function int64(params) {
|
|
833
|
+
return core._int64(KrustyBigIntFormat, params);
|
|
834
|
+
}
|
|
835
|
+
function uint64(params) {
|
|
836
|
+
return core._uint64(KrustyBigIntFormat, params);
|
|
837
|
+
}
|
|
838
|
+
const KrustySymbol = /* @__PURE__ */ core.$constructor(
|
|
839
|
+
"KrustySymbol",
|
|
840
|
+
(inst, def) => {
|
|
841
|
+
const coreInit = core.$ZodSymbol.init;
|
|
842
|
+
coreInit(inst, def);
|
|
843
|
+
KrustyType.init(inst, def);
|
|
844
|
+
}
|
|
845
|
+
);
|
|
846
|
+
function symbol(params) {
|
|
847
|
+
return core._symbol(KrustySymbol, params);
|
|
848
|
+
}
|
|
849
|
+
const KrustyUndefined = /* @__PURE__ */ core.$constructor(
|
|
850
|
+
"KrustyUndefined",
|
|
851
|
+
(inst, def) => {
|
|
852
|
+
const coreInit = core.$ZodUndefined.init;
|
|
853
|
+
coreInit(inst, def);
|
|
854
|
+
KrustyType.init(inst, def);
|
|
855
|
+
}
|
|
856
|
+
);
|
|
857
|
+
function _undefined(params) {
|
|
858
|
+
return core._undefined(KrustyUndefined, params);
|
|
859
|
+
}
|
|
860
|
+
const KrustyNull = /* @__PURE__ */ core.$constructor(
|
|
861
|
+
"KrustyNull",
|
|
862
|
+
(inst, def) => {
|
|
863
|
+
const coreInit = core.$ZodNull.init;
|
|
864
|
+
coreInit(inst, def);
|
|
865
|
+
KrustyType.init(inst, def);
|
|
866
|
+
}
|
|
867
|
+
);
|
|
868
|
+
function _null(params) {
|
|
869
|
+
return core._null(KrustyNull, params);
|
|
870
|
+
}
|
|
871
|
+
const KrustyAny = /* @__PURE__ */ core.$constructor(
|
|
872
|
+
"KrustyAny",
|
|
873
|
+
(inst, def) => {
|
|
874
|
+
const coreInit = core.$ZodAny.init;
|
|
875
|
+
coreInit(inst, def);
|
|
876
|
+
KrustyType.init(inst, def);
|
|
877
|
+
}
|
|
878
|
+
);
|
|
879
|
+
function any() {
|
|
880
|
+
return core._any(KrustyAny);
|
|
881
|
+
}
|
|
882
|
+
const KrustyUnknown = /* @__PURE__ */ core.$constructor(
|
|
883
|
+
"KrustyUnknown",
|
|
884
|
+
(inst, def) => {
|
|
885
|
+
const coreInit = core.$ZodUnknown.init;
|
|
886
|
+
coreInit(inst, def);
|
|
887
|
+
KrustyType.init(inst, def);
|
|
888
|
+
}
|
|
889
|
+
);
|
|
890
|
+
function unknown() {
|
|
891
|
+
return core._unknown(KrustyUnknown);
|
|
892
|
+
}
|
|
893
|
+
const KrustyNever = /* @__PURE__ */ core.$constructor(
|
|
894
|
+
"KrustyNever",
|
|
895
|
+
(inst, def) => {
|
|
896
|
+
const coreInit = core.$ZodNever.init;
|
|
897
|
+
coreInit(inst, def);
|
|
898
|
+
KrustyType.init(inst, def);
|
|
899
|
+
}
|
|
900
|
+
);
|
|
901
|
+
function never(params) {
|
|
902
|
+
return core._never(KrustyNever, params);
|
|
903
|
+
}
|
|
904
|
+
const KrustyVoid = /* @__PURE__ */ core.$constructor(
|
|
905
|
+
"KrustyVoid",
|
|
906
|
+
(inst, def) => {
|
|
907
|
+
const coreInit = core.$ZodVoid.init;
|
|
908
|
+
coreInit(inst, def);
|
|
909
|
+
KrustyType.init(inst, def);
|
|
910
|
+
}
|
|
911
|
+
);
|
|
912
|
+
function _void(params) {
|
|
913
|
+
return core._void(KrustyVoid, params);
|
|
914
|
+
}
|
|
915
|
+
const KrustyDate = /* @__PURE__ */ core.$constructor(
|
|
916
|
+
"KrustyDate",
|
|
917
|
+
(inst, def) => {
|
|
918
|
+
const coreInit = core.$ZodDate.init;
|
|
919
|
+
coreInit(inst, def);
|
|
920
|
+
KrustyType.init(inst, def);
|
|
921
|
+
inst.min = (value, params) => inst.check(_gte(value, params));
|
|
922
|
+
inst.max = (value, params) => inst.check(_lte(value, params));
|
|
923
|
+
const c = inst._zod.bag;
|
|
924
|
+
inst.minDate = c.minimum ? new Date(c.minimum) : null;
|
|
925
|
+
inst.maxDate = c.maximum ? new Date(c.maximum) : null;
|
|
926
|
+
}
|
|
927
|
+
);
|
|
928
|
+
function date(params) {
|
|
929
|
+
return core._date(KrustyDate, params);
|
|
930
|
+
}
|
|
931
|
+
const KrustyArray = /* @__PURE__ */ core.$constructor(
|
|
932
|
+
"KrustyArray",
|
|
933
|
+
(inst, def) => {
|
|
934
|
+
const coreInit = core.$ZodArray.init;
|
|
935
|
+
coreInit(inst, def);
|
|
936
|
+
KrustyType.init(inst, def);
|
|
937
|
+
inst.element = def.element;
|
|
938
|
+
inst.min = (minLength, params) => inst.check(_minLength(minLength, params));
|
|
939
|
+
inst.nonempty = (params) => inst.check(_minLength(1, params));
|
|
940
|
+
inst.max = (maxLength, params) => inst.check(_maxLength(maxLength, params));
|
|
941
|
+
inst.length = (len, params) => inst.check(_length(len, params));
|
|
942
|
+
inst.unwrap = () => inst.element;
|
|
943
|
+
}
|
|
944
|
+
);
|
|
945
|
+
function array(element, params) {
|
|
946
|
+
return core._array(KrustyArray, element, params);
|
|
947
|
+
}
|
|
948
|
+
function keyof(schema) {
|
|
949
|
+
const shape = schema._zod.def.shape;
|
|
950
|
+
return _enum(Object.keys(shape));
|
|
951
|
+
}
|
|
952
|
+
const KrustyIntersection = /* @__PURE__ */ core.$constructor(
|
|
953
|
+
"KrustyIntersection",
|
|
954
|
+
(inst, def) => {
|
|
955
|
+
const coreInit = core.$ZodIntersection.init;
|
|
956
|
+
coreInit(inst, def);
|
|
957
|
+
KrustyType.init(inst, def);
|
|
958
|
+
}
|
|
959
|
+
);
|
|
960
|
+
function intersection(left, right) {
|
|
961
|
+
return new KrustyIntersection({
|
|
962
|
+
type: "intersection",
|
|
963
|
+
left,
|
|
964
|
+
right
|
|
965
|
+
});
|
|
966
|
+
}
|
|
967
|
+
const KrustyTuple = /* @__PURE__ */ core.$constructor(
|
|
968
|
+
"KrustyTuple",
|
|
969
|
+
(inst, def) => {
|
|
970
|
+
const coreInit = core.$ZodTuple.init;
|
|
971
|
+
coreInit(inst, def);
|
|
972
|
+
KrustyType.init(inst, def);
|
|
973
|
+
inst.rest = (rest) => inst.clone({
|
|
974
|
+
...inst._zod.def,
|
|
975
|
+
rest
|
|
976
|
+
});
|
|
977
|
+
}
|
|
978
|
+
);
|
|
979
|
+
function tuple(items, _paramsOrRest, _params) {
|
|
980
|
+
const hasRest = _paramsOrRest instanceof core.$ZodType;
|
|
981
|
+
const params = hasRest ? _params : _paramsOrRest;
|
|
982
|
+
const rest = hasRest ? _paramsOrRest : null;
|
|
983
|
+
return new KrustyTuple({
|
|
984
|
+
type: "tuple",
|
|
985
|
+
items,
|
|
986
|
+
rest,
|
|
987
|
+
...util.normalizeParams(params)
|
|
988
|
+
});
|
|
989
|
+
}
|
|
990
|
+
const KrustyRecord = /* @__PURE__ */ core.$constructor(
|
|
991
|
+
"KrustyRecord",
|
|
992
|
+
(inst, def) => {
|
|
993
|
+
const coreInit = core.$ZodRecord.init;
|
|
994
|
+
coreInit(inst, def);
|
|
995
|
+
KrustyType.init(inst, def);
|
|
996
|
+
inst.keyType = def.keyType;
|
|
997
|
+
inst.valueType = def.valueType;
|
|
998
|
+
}
|
|
999
|
+
);
|
|
1000
|
+
function record(keyType, valueType, params) {
|
|
1001
|
+
return new KrustyRecord({
|
|
1002
|
+
type: "record",
|
|
1003
|
+
keyType,
|
|
1004
|
+
valueType,
|
|
1005
|
+
...util.normalizeParams(params)
|
|
1006
|
+
});
|
|
1007
|
+
}
|
|
1008
|
+
function partialRecord(keyType, valueType, params) {
|
|
1009
|
+
const k = core.clone(keyType);
|
|
1010
|
+
k._zod.values = void 0;
|
|
1011
|
+
return new KrustyRecord({
|
|
1012
|
+
type: "record",
|
|
1013
|
+
keyType: k,
|
|
1014
|
+
valueType,
|
|
1015
|
+
...util.normalizeParams(params)
|
|
1016
|
+
});
|
|
1017
|
+
}
|
|
1018
|
+
const KrustyMap = /* @__PURE__ */ core.$constructor(
|
|
1019
|
+
"KrustyMap",
|
|
1020
|
+
(inst, def) => {
|
|
1021
|
+
const coreInit = core.$ZodMap.init;
|
|
1022
|
+
coreInit(inst, def);
|
|
1023
|
+
KrustyType.init(inst, def);
|
|
1024
|
+
inst.keyType = def.keyType;
|
|
1025
|
+
inst.valueType = def.valueType;
|
|
1026
|
+
}
|
|
1027
|
+
);
|
|
1028
|
+
function map(keyType, valueType, params) {
|
|
1029
|
+
return new KrustyMap({
|
|
1030
|
+
type: "map",
|
|
1031
|
+
keyType,
|
|
1032
|
+
valueType,
|
|
1033
|
+
...util.normalizeParams(params)
|
|
1034
|
+
});
|
|
1035
|
+
}
|
|
1036
|
+
const KrustySet = /* @__PURE__ */ core.$constructor(
|
|
1037
|
+
"KrustySet",
|
|
1038
|
+
(inst, def) => {
|
|
1039
|
+
const coreInit = core.$ZodSet.init;
|
|
1040
|
+
coreInit(inst, def);
|
|
1041
|
+
KrustyType.init(inst, def);
|
|
1042
|
+
inst.min = (...args) => inst.check(core._minSize(...args));
|
|
1043
|
+
inst.nonempty = (params) => inst.check(core._minSize(1, params));
|
|
1044
|
+
inst.max = (...args) => inst.check(core._maxSize(...args));
|
|
1045
|
+
inst.size = (...args) => inst.check(core._size(...args));
|
|
1046
|
+
}
|
|
1047
|
+
);
|
|
1048
|
+
function set(valueType, params) {
|
|
1049
|
+
return new KrustySet({
|
|
1050
|
+
type: "set",
|
|
1051
|
+
valueType,
|
|
1052
|
+
...util.normalizeParams(params)
|
|
1053
|
+
});
|
|
1054
|
+
}
|
|
1055
|
+
const KrustyEnum = /* @__PURE__ */ core.$constructor(
|
|
1056
|
+
"KrustyEnum",
|
|
1057
|
+
(inst, def) => {
|
|
1058
|
+
const coreInit = core.$ZodEnum.init;
|
|
1059
|
+
coreInit(inst, def);
|
|
1060
|
+
KrustyType.init(inst, def);
|
|
1061
|
+
inst.enum = def.entries;
|
|
1062
|
+
inst.options = Object.values(def.entries);
|
|
1063
|
+
const keys = new Set(Object.keys(def.entries));
|
|
1064
|
+
inst.extract = (values, params) => {
|
|
1065
|
+
const newEntries = {};
|
|
1066
|
+
for (const value of values) {
|
|
1067
|
+
if (keys.has(value)) {
|
|
1068
|
+
newEntries[value] = def.entries[value];
|
|
1069
|
+
} else throw new Error(`Key ${value} not found in enum`);
|
|
802
1070
|
}
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
allOf.push(itemJson);
|
|
817
|
-
if (itemRequired) {
|
|
818
|
-
required = true;
|
|
819
|
-
}
|
|
820
|
-
}
|
|
821
|
-
return [required, { allOf }];
|
|
1071
|
+
return new KrustyEnum({
|
|
1072
|
+
...def,
|
|
1073
|
+
checks: [],
|
|
1074
|
+
...util.normalizeParams(params),
|
|
1075
|
+
entries: newEntries
|
|
1076
|
+
});
|
|
1077
|
+
};
|
|
1078
|
+
inst.exclude = (values, params) => {
|
|
1079
|
+
const newEntries = { ...def.entries };
|
|
1080
|
+
for (const value of values) {
|
|
1081
|
+
if (keys.has(value)) {
|
|
1082
|
+
delete newEntries[value];
|
|
1083
|
+
} else throw new Error(`Key ${value} not found in enum`);
|
|
822
1084
|
}
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
1085
|
+
return new KrustyEnum({
|
|
1086
|
+
...def,
|
|
1087
|
+
checks: [],
|
|
1088
|
+
...util.normalizeParams(params),
|
|
1089
|
+
entries: newEntries
|
|
1090
|
+
});
|
|
1091
|
+
};
|
|
1092
|
+
}
|
|
1093
|
+
);
|
|
1094
|
+
function _enum(values, params) {
|
|
1095
|
+
const entries = Array.isArray(values) ? Object.fromEntries(values.map((v) => [v, v])) : values;
|
|
1096
|
+
return new KrustyEnum({
|
|
1097
|
+
type: "enum",
|
|
1098
|
+
entries,
|
|
1099
|
+
...util.normalizeParams(params)
|
|
1100
|
+
});
|
|
1101
|
+
}
|
|
1102
|
+
function nativeEnum(entries, params) {
|
|
1103
|
+
return new KrustyEnum({
|
|
1104
|
+
type: "enum",
|
|
1105
|
+
entries,
|
|
1106
|
+
...util.normalizeParams(params)
|
|
1107
|
+
});
|
|
1108
|
+
}
|
|
1109
|
+
const KrustyLiteral = /* @__PURE__ */ core.$constructor(
|
|
1110
|
+
"KrustyLiteral",
|
|
1111
|
+
(inst, def) => {
|
|
1112
|
+
const coreInit = core.$ZodLiteral.init;
|
|
1113
|
+
coreInit(inst, def);
|
|
1114
|
+
KrustyType.init(inst, def);
|
|
1115
|
+
inst.values = new Set(def.values);
|
|
1116
|
+
Object.defineProperty(inst, "value", {
|
|
1117
|
+
get() {
|
|
1118
|
+
if (def.values.length > 1) {
|
|
1119
|
+
throw new Error("This schema contains multiple valid literal values. Use `.values` instead.");
|
|
827
1120
|
}
|
|
828
|
-
|
|
829
|
-
return this.convert(schema_._def.getter(), options, currentLazyDepth, false, false, structureDepth);
|
|
830
|
-
}
|
|
831
|
-
case ZodFirstPartyTypeKind.ZodOptional: {
|
|
832
|
-
const schema_ = schema;
|
|
833
|
-
const [_, inner] = this.convert(
|
|
834
|
-
schema_._def.innerType,
|
|
835
|
-
options,
|
|
836
|
-
lazyDepth,
|
|
837
|
-
false,
|
|
838
|
-
false,
|
|
839
|
-
structureDepth
|
|
840
|
-
);
|
|
841
|
-
return [false, inner];
|
|
1121
|
+
return def.values[0];
|
|
842
1122
|
}
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
1123
|
+
});
|
|
1124
|
+
}
|
|
1125
|
+
);
|
|
1126
|
+
function literal(value, params) {
|
|
1127
|
+
return new KrustyLiteral({
|
|
1128
|
+
type: "literal",
|
|
1129
|
+
values: Array.isArray(value) ? value : [value],
|
|
1130
|
+
...util.normalizeParams(params)
|
|
1131
|
+
});
|
|
1132
|
+
}
|
|
1133
|
+
const KrustyFile = /* @__PURE__ */ core.$constructor(
|
|
1134
|
+
"KrustyFile",
|
|
1135
|
+
(inst, def) => {
|
|
1136
|
+
const coreInit = core.$ZodFile.init;
|
|
1137
|
+
coreInit(inst, def);
|
|
1138
|
+
KrustyType.init(inst, def);
|
|
1139
|
+
inst.min = (size, params) => inst.check(core._minSize(size, params));
|
|
1140
|
+
inst.max = (size, params) => inst.check(core._maxSize(size, params));
|
|
1141
|
+
inst.mime = (types, params) => inst.check(core._mime(Array.isArray(types) ? types : [types], params));
|
|
1142
|
+
}
|
|
1143
|
+
);
|
|
1144
|
+
function file(params) {
|
|
1145
|
+
return core._file(KrustyFile, params);
|
|
1146
|
+
}
|
|
1147
|
+
const KrustyTransform = /* @__PURE__ */ core.$constructor(
|
|
1148
|
+
"KrustyTransform",
|
|
1149
|
+
(inst, def) => {
|
|
1150
|
+
const coreInit = core.$ZodTransform.init;
|
|
1151
|
+
coreInit(inst, def);
|
|
1152
|
+
KrustyType.init(inst, def);
|
|
1153
|
+
inst._zod.parse = (payload, _ctx) => {
|
|
1154
|
+
if (_ctx.direction === "backward") {
|
|
1155
|
+
throw new core.$ZodEncodeError(inst.constructor.name);
|
|
866
1156
|
}
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
1157
|
+
payload.addIssue = (issue) => {
|
|
1158
|
+
if (typeof issue === "string") {
|
|
1159
|
+
payload.issues.push(util.issue(issue, payload.value, def));
|
|
1160
|
+
} else {
|
|
1161
|
+
const _issue = issue;
|
|
1162
|
+
if (_issue.fatal) _issue.continue = false;
|
|
1163
|
+
_issue.code ??= "custom";
|
|
1164
|
+
_issue.input ??= payload.value;
|
|
1165
|
+
_issue.inst ??= inst;
|
|
1166
|
+
payload.issues.push(util.issue(_issue));
|
|
871
1167
|
}
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
const schema_ = schema;
|
|
880
|
-
return this.convert(schema_._def.type, options, lazyDepth, false, false, structureDepth);
|
|
881
|
-
}
|
|
882
|
-
case ZodFirstPartyTypeKind.ZodPipeline: {
|
|
883
|
-
const schema_ = schema;
|
|
884
|
-
return this.convert(
|
|
885
|
-
options.strategy === "input" ? schema_._def.in : schema_._def.out,
|
|
886
|
-
options,
|
|
887
|
-
lazyDepth,
|
|
888
|
-
false,
|
|
889
|
-
false,
|
|
890
|
-
structureDepth
|
|
891
|
-
);
|
|
892
|
-
}
|
|
893
|
-
case ZodFirstPartyTypeKind.ZodNullable: {
|
|
894
|
-
const schema_ = schema;
|
|
895
|
-
const [required, json] = this.convert(
|
|
896
|
-
schema_._def.innerType,
|
|
897
|
-
options,
|
|
898
|
-
lazyDepth,
|
|
899
|
-
false,
|
|
900
|
-
false,
|
|
901
|
-
structureDepth
|
|
902
|
-
);
|
|
903
|
-
return [required, { anyOf: [json, { type: "null" }] }];
|
|
1168
|
+
};
|
|
1169
|
+
const output = def.transform(payload.value, payload);
|
|
1170
|
+
if (output instanceof Promise) {
|
|
1171
|
+
return output.then((output2) => {
|
|
1172
|
+
payload.value = output2;
|
|
1173
|
+
return payload;
|
|
1174
|
+
});
|
|
904
1175
|
}
|
|
905
|
-
|
|
906
|
-
|
|
1176
|
+
payload.value = output;
|
|
1177
|
+
return payload;
|
|
1178
|
+
};
|
|
1179
|
+
}
|
|
1180
|
+
);
|
|
1181
|
+
function transform(fn) {
|
|
1182
|
+
return new KrustyTransform({
|
|
1183
|
+
type: "transform",
|
|
1184
|
+
transform: fn
|
|
1185
|
+
});
|
|
1186
|
+
}
|
|
1187
|
+
const KrustyOptional = /* @__PURE__ */ core.$constructor(
|
|
1188
|
+
"KrustyOptional",
|
|
1189
|
+
(inst, def) => {
|
|
1190
|
+
const coreInit = core.$ZodOptional.init;
|
|
1191
|
+
coreInit(inst, def);
|
|
1192
|
+
KrustyType.init(inst, def);
|
|
1193
|
+
inst.unwrap = () => inst._zod.def.innerType;
|
|
1194
|
+
}
|
|
1195
|
+
);
|
|
1196
|
+
function optional(innerType) {
|
|
1197
|
+
return new KrustyOptional({
|
|
1198
|
+
type: "optional",
|
|
1199
|
+
innerType
|
|
1200
|
+
});
|
|
1201
|
+
}
|
|
1202
|
+
const KrustyNullable = /* @__PURE__ */ core.$constructor(
|
|
1203
|
+
"KrustyNullable",
|
|
1204
|
+
(inst, def) => {
|
|
1205
|
+
const coreInit = core.$ZodNullable.init;
|
|
1206
|
+
coreInit(inst, def);
|
|
1207
|
+
KrustyType.init(inst, def);
|
|
1208
|
+
inst.unwrap = () => inst._zod.def.innerType;
|
|
1209
|
+
}
|
|
1210
|
+
);
|
|
1211
|
+
function nullable(innerType) {
|
|
1212
|
+
return new KrustyNullable({
|
|
1213
|
+
type: "nullable",
|
|
1214
|
+
innerType
|
|
1215
|
+
});
|
|
1216
|
+
}
|
|
1217
|
+
function nullish(innerType) {
|
|
1218
|
+
return optional(nullable(innerType));
|
|
1219
|
+
}
|
|
1220
|
+
const KrustyDefault = /* @__PURE__ */ core.$constructor(
|
|
1221
|
+
"KrustyDefault",
|
|
1222
|
+
(inst, def) => {
|
|
1223
|
+
const coreInit = core.$ZodDefault.init;
|
|
1224
|
+
coreInit(inst, def);
|
|
1225
|
+
KrustyType.init(inst, def);
|
|
1226
|
+
inst.unwrap = () => inst._zod.def.innerType;
|
|
1227
|
+
inst.removeDefault = inst.unwrap;
|
|
907
1228
|
}
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
1229
|
+
);
|
|
1230
|
+
function _default(innerType, defaultValue) {
|
|
1231
|
+
return new KrustyDefault({
|
|
1232
|
+
type: "default",
|
|
1233
|
+
innerType,
|
|
1234
|
+
get defaultValue() {
|
|
1235
|
+
return typeof defaultValue === "function" ? defaultValue() : util.shallowClone(defaultValue);
|
|
912
1236
|
}
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
format: JSONSchemaFormat.URI,
|
|
931
|
-
"x-native-type": JsonSchemaXNativeType.Url
|
|
932
|
-
};
|
|
933
|
-
}
|
|
1237
|
+
});
|
|
1238
|
+
}
|
|
1239
|
+
const KrustyPrefault = /* @__PURE__ */ core.$constructor(
|
|
1240
|
+
"KrustyPrefault",
|
|
1241
|
+
(inst, def) => {
|
|
1242
|
+
const coreInit = core.$ZodPrefault.init;
|
|
1243
|
+
coreInit(inst, def);
|
|
1244
|
+
KrustyType.init(inst, def);
|
|
1245
|
+
inst.unwrap = () => inst._zod.def.innerType;
|
|
1246
|
+
}
|
|
1247
|
+
);
|
|
1248
|
+
function prefault(innerType, defaultValue) {
|
|
1249
|
+
return new KrustyPrefault({
|
|
1250
|
+
type: "prefault",
|
|
1251
|
+
innerType,
|
|
1252
|
+
get defaultValue() {
|
|
1253
|
+
return typeof defaultValue === "function" ? defaultValue() : util.shallowClone(defaultValue);
|
|
934
1254
|
}
|
|
1255
|
+
});
|
|
1256
|
+
}
|
|
1257
|
+
const KrustyNonOptional = /* @__PURE__ */ core.$constructor(
|
|
1258
|
+
"KrustyNonOptional",
|
|
1259
|
+
(inst, def) => {
|
|
1260
|
+
const coreInit = core.$ZodNonOptional.init;
|
|
1261
|
+
coreInit(inst, def);
|
|
1262
|
+
KrustyType.init(inst, def);
|
|
1263
|
+
inst.unwrap = () => inst._zod.def.innerType;
|
|
935
1264
|
}
|
|
936
|
-
|
|
937
|
-
|
|
1265
|
+
);
|
|
1266
|
+
function nonoptional(innerType, params) {
|
|
1267
|
+
return new KrustyNonOptional({
|
|
1268
|
+
type: "nonoptional",
|
|
1269
|
+
innerType,
|
|
1270
|
+
...util.normalizeParams(params)
|
|
1271
|
+
});
|
|
1272
|
+
}
|
|
1273
|
+
const KrustySuccess = /* @__PURE__ */ core.$constructor(
|
|
1274
|
+
"KrustySuccess",
|
|
1275
|
+
(inst, def) => {
|
|
1276
|
+
const coreInit = core.$ZodSuccess.init;
|
|
1277
|
+
coreInit(inst, def);
|
|
1278
|
+
KrustyType.init(inst, def);
|
|
1279
|
+
inst.unwrap = () => inst._zod.def.innerType;
|
|
938
1280
|
}
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
1281
|
+
);
|
|
1282
|
+
function success(innerType) {
|
|
1283
|
+
return new KrustySuccess({
|
|
1284
|
+
type: "success",
|
|
1285
|
+
innerType
|
|
1286
|
+
});
|
|
1287
|
+
}
|
|
1288
|
+
const KrustyCatch = /* @__PURE__ */ core.$constructor(
|
|
1289
|
+
"KrustyCatch",
|
|
1290
|
+
(inst, def) => {
|
|
1291
|
+
const coreInit = core.$ZodCatch.init;
|
|
1292
|
+
coreInit(inst, def);
|
|
1293
|
+
KrustyType.init(inst, def);
|
|
1294
|
+
inst.unwrap = () => inst._zod.def.innerType;
|
|
1295
|
+
inst.removeCatch = inst.unwrap;
|
|
944
1296
|
}
|
|
1297
|
+
);
|
|
1298
|
+
function _catch(innerType, catchValue) {
|
|
1299
|
+
return new KrustyCatch({
|
|
1300
|
+
type: "catch",
|
|
1301
|
+
innerType,
|
|
1302
|
+
catchValue: typeof catchValue === "function" ? catchValue : () => catchValue
|
|
1303
|
+
});
|
|
1304
|
+
}
|
|
1305
|
+
const KrustyNaN = /* @__PURE__ */ core.$constructor(
|
|
1306
|
+
"KrustyNaN",
|
|
1307
|
+
(inst, def) => {
|
|
1308
|
+
const coreInit = core.$ZodNaN.init;
|
|
1309
|
+
coreInit(inst, def);
|
|
1310
|
+
KrustyType.init(inst, def);
|
|
1311
|
+
}
|
|
1312
|
+
);
|
|
1313
|
+
function nan(params) {
|
|
1314
|
+
return core._nan(KrustyNaN, params);
|
|
1315
|
+
}
|
|
1316
|
+
const KrustyPipe = /* @__PURE__ */ core.$constructor(
|
|
1317
|
+
"KrustyPipe",
|
|
1318
|
+
(inst, def) => {
|
|
1319
|
+
const coreInit = core.$ZodPipe.init;
|
|
1320
|
+
coreInit(inst, def);
|
|
1321
|
+
KrustyType.init(inst, def);
|
|
1322
|
+
inst.in = def.in;
|
|
1323
|
+
inst.out = def.out;
|
|
1324
|
+
}
|
|
1325
|
+
);
|
|
1326
|
+
function pipe(in_, out) {
|
|
1327
|
+
return new KrustyPipe({
|
|
1328
|
+
type: "pipe",
|
|
1329
|
+
in: in_,
|
|
1330
|
+
out
|
|
1331
|
+
// ...util.normalizeParams(params),
|
|
1332
|
+
});
|
|
1333
|
+
}
|
|
1334
|
+
const KrustyCodec = /* @__PURE__ */ core.$constructor(
|
|
1335
|
+
"KrustyCodec",
|
|
1336
|
+
(inst, def) => {
|
|
1337
|
+
KrustyPipe.init(inst, def);
|
|
1338
|
+
const coreInit = core.$ZodCodec.init;
|
|
1339
|
+
coreInit(inst, def);
|
|
1340
|
+
}
|
|
1341
|
+
);
|
|
1342
|
+
function codec(in_, out, params) {
|
|
1343
|
+
return new KrustyCodec({
|
|
1344
|
+
type: "pipe",
|
|
1345
|
+
in: in_,
|
|
1346
|
+
out,
|
|
1347
|
+
transform: params.decode,
|
|
1348
|
+
reverseTransform: params.encode
|
|
1349
|
+
});
|
|
1350
|
+
}
|
|
1351
|
+
const KrustyReadonly = /* @__PURE__ */ core.$constructor(
|
|
1352
|
+
"KrustyReadonly",
|
|
1353
|
+
(inst, def) => {
|
|
1354
|
+
const coreInit = core.$ZodReadonly.init;
|
|
1355
|
+
coreInit(inst, def);
|
|
1356
|
+
KrustyType.init(inst, def);
|
|
1357
|
+
inst.unwrap = () => inst._zod.def.innerType;
|
|
1358
|
+
}
|
|
1359
|
+
);
|
|
1360
|
+
function readonly(innerType) {
|
|
1361
|
+
return new KrustyReadonly({
|
|
1362
|
+
type: "readonly",
|
|
1363
|
+
innerType
|
|
1364
|
+
});
|
|
1365
|
+
}
|
|
1366
|
+
const KrustyTemplateLiteral = /* @__PURE__ */ core.$constructor("KrustyTemplateLiteral", (inst, def) => {
|
|
1367
|
+
const coreInit = core.$ZodTemplateLiteral.init;
|
|
1368
|
+
coreInit(inst, def);
|
|
1369
|
+
KrustyType.init(inst, def);
|
|
1370
|
+
});
|
|
1371
|
+
function templateLiteral(parts, params) {
|
|
1372
|
+
return new KrustyTemplateLiteral({
|
|
1373
|
+
type: "template_literal",
|
|
1374
|
+
parts,
|
|
1375
|
+
...util.normalizeParams(params)
|
|
1376
|
+
});
|
|
1377
|
+
}
|
|
1378
|
+
const KrustyLazy = /* @__PURE__ */ core.$constructor(
|
|
1379
|
+
"KrustyLazy",
|
|
1380
|
+
(inst, def) => {
|
|
1381
|
+
const coreInit = core.$ZodLazy.init;
|
|
1382
|
+
coreInit(inst, def);
|
|
1383
|
+
KrustyType.init(inst, def);
|
|
1384
|
+
inst.unwrap = () => inst._zod.def.getter();
|
|
1385
|
+
}
|
|
1386
|
+
);
|
|
1387
|
+
function lazy(getter) {
|
|
1388
|
+
return new KrustyLazy({
|
|
1389
|
+
type: "lazy",
|
|
1390
|
+
getter
|
|
1391
|
+
});
|
|
1392
|
+
}
|
|
1393
|
+
const KrustyPromise = /* @__PURE__ */ core.$constructor(
|
|
1394
|
+
"KrustyPromise",
|
|
1395
|
+
(inst, def) => {
|
|
1396
|
+
const coreInit = core.$ZodPromise.init;
|
|
1397
|
+
coreInit(inst, def);
|
|
1398
|
+
KrustyType.init(inst, def);
|
|
1399
|
+
inst.unwrap = () => inst._zod.def.innerType;
|
|
1400
|
+
}
|
|
1401
|
+
);
|
|
1402
|
+
function promise(innerType) {
|
|
1403
|
+
return new KrustyPromise({
|
|
1404
|
+
type: "promise",
|
|
1405
|
+
innerType
|
|
1406
|
+
});
|
|
1407
|
+
}
|
|
1408
|
+
const KrustyFunction = /* @__PURE__ */ core.$constructor(
|
|
1409
|
+
"KrustyFunction",
|
|
1410
|
+
(inst, def) => {
|
|
1411
|
+
const coreInit = core.$ZodFunction.init;
|
|
1412
|
+
coreInit(inst, def);
|
|
1413
|
+
KrustyType.init(inst, def);
|
|
1414
|
+
}
|
|
1415
|
+
);
|
|
1416
|
+
function _function(params) {
|
|
1417
|
+
return new KrustyFunction({
|
|
1418
|
+
type: "function",
|
|
1419
|
+
input: Array.isArray(params?.input) ? tuple(params?.input) : params?.input ?? array(unknown()),
|
|
1420
|
+
output: params?.output ?? unknown()
|
|
1421
|
+
});
|
|
1422
|
+
}
|
|
1423
|
+
const KrustyCustom = /* @__PURE__ */ core.$constructor(
|
|
1424
|
+
"KrustyCustom",
|
|
1425
|
+
(inst, def) => {
|
|
1426
|
+
const coreInit = core.$ZodCustom.init;
|
|
1427
|
+
coreInit(inst, def);
|
|
1428
|
+
KrustyType.init(inst, def);
|
|
1429
|
+
}
|
|
1430
|
+
);
|
|
1431
|
+
function check(fn) {
|
|
1432
|
+
const ch = new core.$ZodCheck({
|
|
1433
|
+
check: "custom"
|
|
1434
|
+
// ...util.normalizeParams(params),
|
|
1435
|
+
});
|
|
1436
|
+
ch._zod.check = fn;
|
|
1437
|
+
return ch;
|
|
1438
|
+
}
|
|
1439
|
+
function custom(fn, _params) {
|
|
1440
|
+
return core._custom(KrustyCustom, fn ?? (() => true), _params);
|
|
1441
|
+
}
|
|
1442
|
+
function refine(fn, _params = {}) {
|
|
1443
|
+
return core._refine(KrustyCustom, fn, _params);
|
|
1444
|
+
}
|
|
1445
|
+
function superRefine(fn) {
|
|
1446
|
+
return core._superRefine(fn);
|
|
1447
|
+
}
|
|
1448
|
+
function _instanceof(cls, params = {
|
|
1449
|
+
error: `Input not instance of ${cls.name}`
|
|
1450
|
+
}) {
|
|
1451
|
+
const inst = new KrustyCustom({
|
|
1452
|
+
type: "custom",
|
|
1453
|
+
check: "custom",
|
|
1454
|
+
fn: (data) => data instanceof cls,
|
|
1455
|
+
abort: true,
|
|
1456
|
+
...util.normalizeParams(params)
|
|
1457
|
+
});
|
|
1458
|
+
inst._zod.bag.Class = cls;
|
|
1459
|
+
return inst;
|
|
1460
|
+
}
|
|
1461
|
+
const stringbool = (...args) => core._stringbool(
|
|
1462
|
+
{
|
|
1463
|
+
Codec: KrustyCodec,
|
|
1464
|
+
Boolean: KrustyBoolean,
|
|
1465
|
+
String: KrustyString
|
|
1466
|
+
},
|
|
1467
|
+
...args
|
|
1468
|
+
);
|
|
1469
|
+
function json(params) {
|
|
1470
|
+
const jsonSchema = lazy(() => {
|
|
1471
|
+
return union([
|
|
1472
|
+
string(params),
|
|
1473
|
+
number(),
|
|
1474
|
+
boolean(),
|
|
1475
|
+
_null(),
|
|
1476
|
+
array(jsonSchema),
|
|
1477
|
+
record(string(), jsonSchema)
|
|
1478
|
+
]);
|
|
1479
|
+
});
|
|
1480
|
+
return jsonSchema;
|
|
945
1481
|
}
|
|
946
1482
|
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
}
|
|
1483
|
+
class SchemaClass {
|
|
1484
|
+
string(params) {
|
|
1485
|
+
return string(params);
|
|
1486
|
+
}
|
|
1487
|
+
number(params) {
|
|
1488
|
+
return number(params);
|
|
1489
|
+
}
|
|
1490
|
+
int(params) {
|
|
1491
|
+
return this.number().int(params);
|
|
1492
|
+
}
|
|
1493
|
+
boolean(params) {
|
|
1494
|
+
return boolean(params);
|
|
1495
|
+
}
|
|
1496
|
+
null(params) {
|
|
1497
|
+
return _null(params);
|
|
1498
|
+
}
|
|
1499
|
+
array(element, params) {
|
|
1500
|
+
return array(element, params);
|
|
1501
|
+
}
|
|
1502
|
+
record(keyType, valueType, params) {
|
|
1503
|
+
return record(keyType, valueType, params);
|
|
1504
|
+
}
|
|
1505
|
+
union(options, params) {
|
|
1506
|
+
return union(options, params);
|
|
1507
|
+
}
|
|
1508
|
+
discriminatedUnion(discriminator, options, params) {
|
|
1509
|
+
return discriminatedUnion(discriminator, options, params);
|
|
1510
|
+
}
|
|
1511
|
+
object(shape, params) {
|
|
1512
|
+
return object(shape, params);
|
|
1513
|
+
}
|
|
1514
|
+
// TODO: make this a codec?
|
|
1515
|
+
date(params) {
|
|
1516
|
+
return date(params);
|
|
1517
|
+
}
|
|
1518
|
+
any() {
|
|
1519
|
+
return any();
|
|
1520
|
+
}
|
|
1521
|
+
unknown() {
|
|
1522
|
+
return unknown();
|
|
1523
|
+
}
|
|
1524
|
+
never(params) {
|
|
1525
|
+
return never(params);
|
|
1526
|
+
}
|
|
1527
|
+
lazy(getter) {
|
|
1528
|
+
return lazy(getter);
|
|
1529
|
+
}
|
|
1530
|
+
json(params) {
|
|
1531
|
+
return json(params);
|
|
1532
|
+
}
|
|
1533
|
+
/**
|
|
1534
|
+
* TODO: def need to expose
|
|
1535
|
+
* file
|
|
1536
|
+
* literal
|
|
1537
|
+
* nativeEnum
|
|
1538
|
+
*/
|
|
1539
|
+
/**
|
|
1540
|
+
* TODO: decide how to handle non-serializeable values
|
|
1541
|
+
* TODO: decide what types to expose
|
|
1542
|
+
* function
|
|
1543
|
+
* promise
|
|
1544
|
+
* readonly
|
|
1545
|
+
* nan
|
|
1546
|
+
* success
|
|
1547
|
+
* set
|
|
1548
|
+
* map
|
|
1549
|
+
* partialRecord
|
|
1550
|
+
* tuple
|
|
1551
|
+
* intersection
|
|
1552
|
+
* keyof
|
|
1553
|
+
* symbol
|
|
1554
|
+
* bigint
|
|
1555
|
+
* blob
|
|
1556
|
+
*/
|
|
1557
|
+
/**
|
|
1558
|
+
* TODO: decide what non-chained format helpers to expose
|
|
1559
|
+
* -- OBJECT
|
|
1560
|
+
* strictObject
|
|
1561
|
+
* looseObject
|
|
1562
|
+
* -- STRING
|
|
1563
|
+
* url
|
|
1564
|
+
* regexp
|
|
1565
|
+
* email
|
|
1566
|
+
* guid
|
|
1567
|
+
* uuid
|
|
1568
|
+
* uuidv4
|
|
1569
|
+
* uuidv6
|
|
1570
|
+
* uuidv7
|
|
1571
|
+
* url
|
|
1572
|
+
* httpUrl
|
|
1573
|
+
* emoji
|
|
1574
|
+
* nanoid
|
|
1575
|
+
* cuid
|
|
1576
|
+
* cuid2
|
|
1577
|
+
* ulid
|
|
1578
|
+
* xid
|
|
1579
|
+
* ksuid
|
|
1580
|
+
* jwt
|
|
1581
|
+
* hostname
|
|
1582
|
+
* hex
|
|
1583
|
+
* hash
|
|
1584
|
+
* ipv4
|
|
1585
|
+
* ipv6
|
|
1586
|
+
* cidrv4
|
|
1587
|
+
* cidrv6
|
|
1588
|
+
* base64
|
|
1589
|
+
* base64url
|
|
1590
|
+
* e164
|
|
1591
|
+
* -- NUMBER
|
|
1592
|
+
* float32
|
|
1593
|
+
* float64
|
|
1594
|
+
* int32
|
|
1595
|
+
* uint32
|
|
1596
|
+
* int64
|
|
1597
|
+
* uint64
|
|
1598
|
+
*/
|
|
1599
|
+
/**
|
|
1600
|
+
* TODO: decide what other helper methods to expose
|
|
1601
|
+
* refine
|
|
1602
|
+
* superRefine
|
|
1603
|
+
* custom
|
|
1604
|
+
* check
|
|
1605
|
+
* codec
|
|
1606
|
+
* pipe
|
|
1607
|
+
* nonoptional
|
|
1608
|
+
* prefault
|
|
1609
|
+
* default
|
|
1610
|
+
* nullish
|
|
1611
|
+
* nullable
|
|
1612
|
+
* optional
|
|
1613
|
+
* transform
|
|
1614
|
+
* stringFormat
|
|
1615
|
+
*/
|
|
1616
|
+
}
|
|
954
1617
|
|
|
955
|
-
export {
|
|
1618
|
+
export { KrustyAny, KrustyArray, KrustyBase64, KrustyBase64URL, KrustyBigInt, KrustyBigIntFormat, KrustyBoolean, KrustyCIDRv4, KrustyCIDRv6, KrustyCUID, KrustyCUID2, KrustyCatch, KrustyCodec, KrustyCustom, KrustyCustomStringFormat, KrustyDate, KrustyDefault, KrustyDiscriminatedUnion, KrustyE164, KrustyEmail, KrustyEmoji, KrustyEnum, KrustyFile, KrustyFunction, KrustyGUID, KrustyGate, KrustyIPv4, KrustyIPv6, KrustyIntersection, KrustyJWT, KrustyKSUID, KrustyLazy, KrustyLiteral, KrustyMap, KrustyNaN, KrustyNanoID, KrustyNever, KrustyNonOptional, KrustyNull, KrustyNullable, KrustyNumber, KrustyNumberFormat, KrustyObject, KrustyOptional, KrustyPipe, KrustyPrefault, KrustyPromise, KrustyReadonly, KrustyRecord, KrustySet, KrustyString, KrustyStringFormat, KrustySuccess, KrustySymbol, KrustyTemplateLiteral, KrustyTransform, KrustyTuple, KrustyType, KrustyULID, KrustyURL, KrustyUUID, KrustyUndefined, KrustyUnion, KrustyUnknown, KrustyVoid, KrustyXID, SchemaClass, ZodError, ZodRealError, _KrustyString, _default, _function, any, array, base64, base64url, bigint, boolean, _catch as catch, check, cidrv4, cidrv6, codec, cuid, cuid2, custom, date, decode, decodeAsync, discriminatedUnion, e164, email, emoji, encode, encodeAsync, _enum as enum, file, float32, float64, _function as function, gate, gatingContext, guid, hash, hex, hostname, httpUrl, _instanceof as instanceof, int, int32, int64, intersection, ipv4, ipv6, isGateIssue, isGateIssueRaw, json, jwt, keyof, ksuid, lazy, literal, looseObject, map, nan, nanoid, nativeEnum, never, nonoptional, _null as null, nullable, nullish, number, object, optional, parse, parseAsync, partialRecord, pipe, prefault, promise, readonly, record, refine, safeDecode, safeDecodeAsync, safeEncode, safeEncodeAsync, safeParse, safeParseAsync, set, strictObject, string, stringFormat, stringbool, success, superRefine, symbol, templateLiteral, transform, tuple, uint32, uint64, ulid, _undefined as undefined, union, unknown, url, uuid, uuidv4, uuidv6, uuidv7, _void as void, xid };
|