ccusage 0.4.2 → 0.6.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/README.md +106 -1
- package/dist/arktype-C-GObzDh-Dj1DVoqC.js +5 -0
- package/dist/calculate-cost.d.ts +5 -5
- package/dist/calculate-cost.js +1 -1
- package/dist/core-BgFXUe_h.js +693 -0
- package/dist/{data-loader-B8mdiY5r.js → data-loader-CDv0IYZx.js} +59 -22
- package/dist/{data-loader-DtCt7sNl.d.ts → data-loader-aUOjeZ06.d.ts} +17 -6
- package/dist/data-loader.d.ts +5 -5
- package/dist/data-loader.js +5 -5
- package/dist/{debug-Oce2b5bO.js → debug-Dk36WQTw.js} +4 -4
- package/dist/debug.js +5 -5
- package/dist/dist-C_i5I27w.js +469 -0
- package/dist/{dist-D6rk8Ra5.js → dist-FwNhpFrW.js} +30 -1
- package/dist/effect-WSjEuzC9-BsxP11fz.js +10 -0
- package/dist/esm-vjyZjnpZ.js +1090 -0
- package/dist/index-CISmcbXk-BotItq1T.js +23 -0
- package/dist/index.js +171 -23
- package/dist/{logger-nCODI08N.js → logger-DhDyJEC5.js} +2 -2
- package/dist/logger.js +1 -1
- package/dist/mcp-G-TIOcuj.js +37580 -0
- package/dist/mcp.d.ts +15 -0
- package/dist/mcp.js +10 -0
- package/dist/{pricing-fetcher-bvi4lbXl.js → pricing-fetcher-BCv1Vods.js} +2 -2
- package/dist/{pricing-fetcher-BqlslEH3.d.ts → pricing-fetcher-DygIroMj.d.ts} +1 -1
- package/dist/pricing-fetcher.d.ts +2 -2
- package/dist/pricing-fetcher.js +3 -3
- package/dist/{shared-args-DWaGio0e.js → shared-args-BtMSktLn.js} +10 -3
- package/dist/shared-args.d.ts +14 -0
- package/dist/shared-args.js +6 -6
- package/dist/sury-DmrZ3_Oj-DhGOjCNc.js +10 -0
- package/dist/{types-DjlBTM5P.js → types-BcXIBMQk.js} +3 -2
- package/dist/types-CFnCBr2I.js +3586 -0
- package/dist/{types-BfZ5dOy7.d.ts → types-y1JQzaKZ.d.ts} +4 -2
- package/dist/types.d.ts +3 -3
- package/dist/types.js +3 -3
- package/dist/utils.js +1 -1
- package/dist/valibot-CQk-M5rL-Cq5E7F3g.js +10 -0
- package/dist/zod-Db63SLXj-BWdcigdx.js +30 -0
- package/package.json +2 -1
- /package/dist/{calculate-cost-BnufbprY.js → calculate-cost-2IwHSzmi.js} +0 -0
- /package/dist/{index-Bazt8Nfd.d.ts → index-BurjgCfW.d.ts} +0 -0
- /package/dist/{prompt-BwcIpzWm.js → prompt-IToGuko2.js} +0 -0
- /package/dist/{utils-BeihwpHn.js → utils-C7kg8MXN.js} +0 -0
|
@@ -0,0 +1,3586 @@
|
|
|
1
|
+
//#region node_modules/zod/dist/esm/v3/helpers/util.js
|
|
2
|
+
var util;
|
|
3
|
+
(function(util$1) {
|
|
4
|
+
util$1.assertEqual = (_) => {};
|
|
5
|
+
function assertIs(_arg) {}
|
|
6
|
+
util$1.assertIs = assertIs;
|
|
7
|
+
function assertNever(_x) {
|
|
8
|
+
throw new Error();
|
|
9
|
+
}
|
|
10
|
+
util$1.assertNever = assertNever;
|
|
11
|
+
util$1.arrayToEnum = (items) => {
|
|
12
|
+
const obj = {};
|
|
13
|
+
for (const item of items) obj[item] = item;
|
|
14
|
+
return obj;
|
|
15
|
+
};
|
|
16
|
+
util$1.getValidEnumValues = (obj) => {
|
|
17
|
+
const validKeys = util$1.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
|
|
18
|
+
const filtered = {};
|
|
19
|
+
for (const k of validKeys) filtered[k] = obj[k];
|
|
20
|
+
return util$1.objectValues(filtered);
|
|
21
|
+
};
|
|
22
|
+
util$1.objectValues = (obj) => {
|
|
23
|
+
return util$1.objectKeys(obj).map(function(e) {
|
|
24
|
+
return obj[e];
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
util$1.objectKeys = typeof Object.keys === "function" ? (obj) => Object.keys(obj) : (object) => {
|
|
28
|
+
const keys = [];
|
|
29
|
+
for (const key in object) if (Object.prototype.hasOwnProperty.call(object, key)) keys.push(key);
|
|
30
|
+
return keys;
|
|
31
|
+
};
|
|
32
|
+
util$1.find = (arr, checker) => {
|
|
33
|
+
for (const item of arr) if (checker(item)) return item;
|
|
34
|
+
return void 0;
|
|
35
|
+
};
|
|
36
|
+
util$1.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && Number.isFinite(val) && Math.floor(val) === val;
|
|
37
|
+
function joinValues(array, separator = " | ") {
|
|
38
|
+
return array.map((val) => typeof val === "string" ? `'${val}'` : val).join(separator);
|
|
39
|
+
}
|
|
40
|
+
util$1.joinValues = joinValues;
|
|
41
|
+
util$1.jsonStringifyReplacer = (_, value) => {
|
|
42
|
+
if (typeof value === "bigint") return value.toString();
|
|
43
|
+
return value;
|
|
44
|
+
};
|
|
45
|
+
})(util || (util = {}));
|
|
46
|
+
var objectUtil;
|
|
47
|
+
(function(objectUtil$1) {
|
|
48
|
+
objectUtil$1.mergeShapes = (first, second) => {
|
|
49
|
+
return {
|
|
50
|
+
...first,
|
|
51
|
+
...second
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
})(objectUtil || (objectUtil = {}));
|
|
55
|
+
const ZodParsedType = util.arrayToEnum([
|
|
56
|
+
"string",
|
|
57
|
+
"nan",
|
|
58
|
+
"number",
|
|
59
|
+
"integer",
|
|
60
|
+
"float",
|
|
61
|
+
"boolean",
|
|
62
|
+
"date",
|
|
63
|
+
"bigint",
|
|
64
|
+
"symbol",
|
|
65
|
+
"function",
|
|
66
|
+
"undefined",
|
|
67
|
+
"null",
|
|
68
|
+
"array",
|
|
69
|
+
"object",
|
|
70
|
+
"unknown",
|
|
71
|
+
"promise",
|
|
72
|
+
"void",
|
|
73
|
+
"never",
|
|
74
|
+
"map",
|
|
75
|
+
"set"
|
|
76
|
+
]);
|
|
77
|
+
const getParsedType = (data) => {
|
|
78
|
+
const t = typeof data;
|
|
79
|
+
switch (t) {
|
|
80
|
+
case "undefined": return ZodParsedType.undefined;
|
|
81
|
+
case "string": return ZodParsedType.string;
|
|
82
|
+
case "number": return Number.isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
|
|
83
|
+
case "boolean": return ZodParsedType.boolean;
|
|
84
|
+
case "function": return ZodParsedType.function;
|
|
85
|
+
case "bigint": return ZodParsedType.bigint;
|
|
86
|
+
case "symbol": return ZodParsedType.symbol;
|
|
87
|
+
case "object":
|
|
88
|
+
if (Array.isArray(data)) return ZodParsedType.array;
|
|
89
|
+
if (data === null) return ZodParsedType.null;
|
|
90
|
+
if (data.then && typeof data.then === "function" && data.catch && typeof data.catch === "function") return ZodParsedType.promise;
|
|
91
|
+
if (typeof Map !== "undefined" && data instanceof Map) return ZodParsedType.map;
|
|
92
|
+
if (typeof Set !== "undefined" && data instanceof Set) return ZodParsedType.set;
|
|
93
|
+
if (typeof Date !== "undefined" && data instanceof Date) return ZodParsedType.date;
|
|
94
|
+
return ZodParsedType.object;
|
|
95
|
+
default: return ZodParsedType.unknown;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
//#endregion
|
|
100
|
+
//#region node_modules/zod/dist/esm/v3/ZodError.js
|
|
101
|
+
const ZodIssueCode = util.arrayToEnum([
|
|
102
|
+
"invalid_type",
|
|
103
|
+
"invalid_literal",
|
|
104
|
+
"custom",
|
|
105
|
+
"invalid_union",
|
|
106
|
+
"invalid_union_discriminator",
|
|
107
|
+
"invalid_enum_value",
|
|
108
|
+
"unrecognized_keys",
|
|
109
|
+
"invalid_arguments",
|
|
110
|
+
"invalid_return_type",
|
|
111
|
+
"invalid_date",
|
|
112
|
+
"invalid_string",
|
|
113
|
+
"too_small",
|
|
114
|
+
"too_big",
|
|
115
|
+
"invalid_intersection_types",
|
|
116
|
+
"not_multiple_of",
|
|
117
|
+
"not_finite"
|
|
118
|
+
]);
|
|
119
|
+
var ZodError = class ZodError extends Error {
|
|
120
|
+
get errors() {
|
|
121
|
+
return this.issues;
|
|
122
|
+
}
|
|
123
|
+
constructor(issues) {
|
|
124
|
+
super();
|
|
125
|
+
this.issues = [];
|
|
126
|
+
this.addIssue = (sub) => {
|
|
127
|
+
this.issues = [...this.issues, sub];
|
|
128
|
+
};
|
|
129
|
+
this.addIssues = (subs = []) => {
|
|
130
|
+
this.issues = [...this.issues, ...subs];
|
|
131
|
+
};
|
|
132
|
+
const actualProto = new.target.prototype;
|
|
133
|
+
if (Object.setPrototypeOf) Object.setPrototypeOf(this, actualProto);
|
|
134
|
+
else this.__proto__ = actualProto;
|
|
135
|
+
this.name = "ZodError";
|
|
136
|
+
this.issues = issues;
|
|
137
|
+
}
|
|
138
|
+
format(_mapper) {
|
|
139
|
+
const mapper = _mapper || function(issue) {
|
|
140
|
+
return issue.message;
|
|
141
|
+
};
|
|
142
|
+
const fieldErrors = { _errors: [] };
|
|
143
|
+
const processError = (error) => {
|
|
144
|
+
for (const issue of error.issues) if (issue.code === "invalid_union") issue.unionErrors.map(processError);
|
|
145
|
+
else if (issue.code === "invalid_return_type") processError(issue.returnTypeError);
|
|
146
|
+
else if (issue.code === "invalid_arguments") processError(issue.argumentsError);
|
|
147
|
+
else if (issue.path.length === 0) fieldErrors._errors.push(mapper(issue));
|
|
148
|
+
else {
|
|
149
|
+
let curr = fieldErrors;
|
|
150
|
+
let i = 0;
|
|
151
|
+
while (i < issue.path.length) {
|
|
152
|
+
const el = issue.path[i];
|
|
153
|
+
const terminal = i === issue.path.length - 1;
|
|
154
|
+
if (!terminal) curr[el] = curr[el] || { _errors: [] };
|
|
155
|
+
else {
|
|
156
|
+
curr[el] = curr[el] || { _errors: [] };
|
|
157
|
+
curr[el]._errors.push(mapper(issue));
|
|
158
|
+
}
|
|
159
|
+
curr = curr[el];
|
|
160
|
+
i++;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
processError(this);
|
|
165
|
+
return fieldErrors;
|
|
166
|
+
}
|
|
167
|
+
static assert(value) {
|
|
168
|
+
if (!(value instanceof ZodError)) throw new Error(`Not a ZodError: ${value}`);
|
|
169
|
+
}
|
|
170
|
+
toString() {
|
|
171
|
+
return this.message;
|
|
172
|
+
}
|
|
173
|
+
get message() {
|
|
174
|
+
return JSON.stringify(this.issues, util.jsonStringifyReplacer, 2);
|
|
175
|
+
}
|
|
176
|
+
get isEmpty() {
|
|
177
|
+
return this.issues.length === 0;
|
|
178
|
+
}
|
|
179
|
+
flatten(mapper = (issue) => issue.message) {
|
|
180
|
+
const fieldErrors = {};
|
|
181
|
+
const formErrors = [];
|
|
182
|
+
for (const sub of this.issues) if (sub.path.length > 0) {
|
|
183
|
+
fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
|
|
184
|
+
fieldErrors[sub.path[0]].push(mapper(sub));
|
|
185
|
+
} else formErrors.push(mapper(sub));
|
|
186
|
+
return {
|
|
187
|
+
formErrors,
|
|
188
|
+
fieldErrors
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
get formErrors() {
|
|
192
|
+
return this.flatten();
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
ZodError.create = (issues) => {
|
|
196
|
+
const error = new ZodError(issues);
|
|
197
|
+
return error;
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
//#endregion
|
|
201
|
+
//#region node_modules/zod/dist/esm/v3/locales/en.js
|
|
202
|
+
const errorMap = (issue, _ctx) => {
|
|
203
|
+
let message;
|
|
204
|
+
switch (issue.code) {
|
|
205
|
+
case ZodIssueCode.invalid_type:
|
|
206
|
+
if (issue.received === ZodParsedType.undefined) message = "Required";
|
|
207
|
+
else message = `Expected ${issue.expected}, received ${issue.received}`;
|
|
208
|
+
break;
|
|
209
|
+
case ZodIssueCode.invalid_literal:
|
|
210
|
+
message = `Invalid literal value, expected ${JSON.stringify(issue.expected, util.jsonStringifyReplacer)}`;
|
|
211
|
+
break;
|
|
212
|
+
case ZodIssueCode.unrecognized_keys:
|
|
213
|
+
message = `Unrecognized key(s) in object: ${util.joinValues(issue.keys, ", ")}`;
|
|
214
|
+
break;
|
|
215
|
+
case ZodIssueCode.invalid_union:
|
|
216
|
+
message = `Invalid input`;
|
|
217
|
+
break;
|
|
218
|
+
case ZodIssueCode.invalid_union_discriminator:
|
|
219
|
+
message = `Invalid discriminator value. Expected ${util.joinValues(issue.options)}`;
|
|
220
|
+
break;
|
|
221
|
+
case ZodIssueCode.invalid_enum_value:
|
|
222
|
+
message = `Invalid enum value. Expected ${util.joinValues(issue.options)}, received '${issue.received}'`;
|
|
223
|
+
break;
|
|
224
|
+
case ZodIssueCode.invalid_arguments:
|
|
225
|
+
message = `Invalid function arguments`;
|
|
226
|
+
break;
|
|
227
|
+
case ZodIssueCode.invalid_return_type:
|
|
228
|
+
message = `Invalid function return type`;
|
|
229
|
+
break;
|
|
230
|
+
case ZodIssueCode.invalid_date:
|
|
231
|
+
message = `Invalid date`;
|
|
232
|
+
break;
|
|
233
|
+
case ZodIssueCode.invalid_string:
|
|
234
|
+
if (typeof issue.validation === "object") if ("includes" in issue.validation) {
|
|
235
|
+
message = `Invalid input: must include "${issue.validation.includes}"`;
|
|
236
|
+
if (typeof issue.validation.position === "number") message = `${message} at one or more positions greater than or equal to ${issue.validation.position}`;
|
|
237
|
+
} else if ("startsWith" in issue.validation) message = `Invalid input: must start with "${issue.validation.startsWith}"`;
|
|
238
|
+
else if ("endsWith" in issue.validation) message = `Invalid input: must end with "${issue.validation.endsWith}"`;
|
|
239
|
+
else util.assertNever(issue.validation);
|
|
240
|
+
else if (issue.validation !== "regex") message = `Invalid ${issue.validation}`;
|
|
241
|
+
else message = "Invalid";
|
|
242
|
+
break;
|
|
243
|
+
case ZodIssueCode.too_small:
|
|
244
|
+
if (issue.type === "array") message = `Array must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `more than`} ${issue.minimum} element(s)`;
|
|
245
|
+
else if (issue.type === "string") message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
|
|
246
|
+
else if (issue.type === "number") message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
|
|
247
|
+
else if (issue.type === "date") message = `Date must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${new Date(Number(issue.minimum))}`;
|
|
248
|
+
else message = "Invalid input";
|
|
249
|
+
break;
|
|
250
|
+
case ZodIssueCode.too_big:
|
|
251
|
+
if (issue.type === "array") message = `Array must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `less than`} ${issue.maximum} element(s)`;
|
|
252
|
+
else if (issue.type === "string") message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
|
|
253
|
+
else if (issue.type === "number") message = `Number must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
|
|
254
|
+
else if (issue.type === "bigint") message = `BigInt must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
|
|
255
|
+
else if (issue.type === "date") message = `Date must be ${issue.exact ? `exactly` : issue.inclusive ? `smaller than or equal to` : `smaller than`} ${new Date(Number(issue.maximum))}`;
|
|
256
|
+
else message = "Invalid input";
|
|
257
|
+
break;
|
|
258
|
+
case ZodIssueCode.custom:
|
|
259
|
+
message = `Invalid input`;
|
|
260
|
+
break;
|
|
261
|
+
case ZodIssueCode.invalid_intersection_types:
|
|
262
|
+
message = `Intersection results could not be merged`;
|
|
263
|
+
break;
|
|
264
|
+
case ZodIssueCode.not_multiple_of:
|
|
265
|
+
message = `Number must be a multiple of ${issue.multipleOf}`;
|
|
266
|
+
break;
|
|
267
|
+
case ZodIssueCode.not_finite:
|
|
268
|
+
message = "Number must be finite";
|
|
269
|
+
break;
|
|
270
|
+
default:
|
|
271
|
+
message = _ctx.defaultError;
|
|
272
|
+
util.assertNever(issue);
|
|
273
|
+
}
|
|
274
|
+
return { message };
|
|
275
|
+
};
|
|
276
|
+
var en_default = errorMap;
|
|
277
|
+
|
|
278
|
+
//#endregion
|
|
279
|
+
//#region node_modules/zod/dist/esm/v3/errors.js
|
|
280
|
+
let overrideErrorMap = en_default;
|
|
281
|
+
function getErrorMap() {
|
|
282
|
+
return overrideErrorMap;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
//#endregion
|
|
286
|
+
//#region node_modules/zod/dist/esm/v3/helpers/parseUtil.js
|
|
287
|
+
const makeIssue = (params) => {
|
|
288
|
+
const { data, path, errorMaps, issueData } = params;
|
|
289
|
+
const fullPath = [...path, ...issueData.path || []];
|
|
290
|
+
const fullIssue = {
|
|
291
|
+
...issueData,
|
|
292
|
+
path: fullPath
|
|
293
|
+
};
|
|
294
|
+
if (issueData.message !== void 0) return {
|
|
295
|
+
...issueData,
|
|
296
|
+
path: fullPath,
|
|
297
|
+
message: issueData.message
|
|
298
|
+
};
|
|
299
|
+
let errorMessage = "";
|
|
300
|
+
const maps = errorMaps.filter((m) => !!m).slice().reverse();
|
|
301
|
+
for (const map of maps) errorMessage = map(fullIssue, {
|
|
302
|
+
data,
|
|
303
|
+
defaultError: errorMessage
|
|
304
|
+
}).message;
|
|
305
|
+
return {
|
|
306
|
+
...issueData,
|
|
307
|
+
path: fullPath,
|
|
308
|
+
message: errorMessage
|
|
309
|
+
};
|
|
310
|
+
};
|
|
311
|
+
function addIssueToContext(ctx, issueData) {
|
|
312
|
+
const overrideMap = getErrorMap();
|
|
313
|
+
const issue = makeIssue({
|
|
314
|
+
issueData,
|
|
315
|
+
data: ctx.data,
|
|
316
|
+
path: ctx.path,
|
|
317
|
+
errorMaps: [
|
|
318
|
+
ctx.common.contextualErrorMap,
|
|
319
|
+
ctx.schemaErrorMap,
|
|
320
|
+
overrideMap,
|
|
321
|
+
overrideMap === en_default ? void 0 : en_default
|
|
322
|
+
].filter((x) => !!x)
|
|
323
|
+
});
|
|
324
|
+
ctx.common.issues.push(issue);
|
|
325
|
+
}
|
|
326
|
+
var ParseStatus = class ParseStatus {
|
|
327
|
+
constructor() {
|
|
328
|
+
this.value = "valid";
|
|
329
|
+
}
|
|
330
|
+
dirty() {
|
|
331
|
+
if (this.value === "valid") this.value = "dirty";
|
|
332
|
+
}
|
|
333
|
+
abort() {
|
|
334
|
+
if (this.value !== "aborted") this.value = "aborted";
|
|
335
|
+
}
|
|
336
|
+
static mergeArray(status, results) {
|
|
337
|
+
const arrayValue = [];
|
|
338
|
+
for (const s of results) {
|
|
339
|
+
if (s.status === "aborted") return INVALID;
|
|
340
|
+
if (s.status === "dirty") status.dirty();
|
|
341
|
+
arrayValue.push(s.value);
|
|
342
|
+
}
|
|
343
|
+
return {
|
|
344
|
+
status: status.value,
|
|
345
|
+
value: arrayValue
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
static async mergeObjectAsync(status, pairs) {
|
|
349
|
+
const syncPairs = [];
|
|
350
|
+
for (const pair of pairs) {
|
|
351
|
+
const key = await pair.key;
|
|
352
|
+
const value = await pair.value;
|
|
353
|
+
syncPairs.push({
|
|
354
|
+
key,
|
|
355
|
+
value
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
return ParseStatus.mergeObjectSync(status, syncPairs);
|
|
359
|
+
}
|
|
360
|
+
static mergeObjectSync(status, pairs) {
|
|
361
|
+
const finalObject = {};
|
|
362
|
+
for (const pair of pairs) {
|
|
363
|
+
const { key, value } = pair;
|
|
364
|
+
if (key.status === "aborted") return INVALID;
|
|
365
|
+
if (value.status === "aborted") return INVALID;
|
|
366
|
+
if (key.status === "dirty") status.dirty();
|
|
367
|
+
if (value.status === "dirty") status.dirty();
|
|
368
|
+
if (key.value !== "__proto__" && (typeof value.value !== "undefined" || pair.alwaysSet)) finalObject[key.value] = value.value;
|
|
369
|
+
}
|
|
370
|
+
return {
|
|
371
|
+
status: status.value,
|
|
372
|
+
value: finalObject
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
};
|
|
376
|
+
const INVALID = Object.freeze({ status: "aborted" });
|
|
377
|
+
const DIRTY = (value) => ({
|
|
378
|
+
status: "dirty",
|
|
379
|
+
value
|
|
380
|
+
});
|
|
381
|
+
const OK = (value) => ({
|
|
382
|
+
status: "valid",
|
|
383
|
+
value
|
|
384
|
+
});
|
|
385
|
+
const isAborted = (x) => x.status === "aborted";
|
|
386
|
+
const isDirty = (x) => x.status === "dirty";
|
|
387
|
+
const isValid = (x) => x.status === "valid";
|
|
388
|
+
const isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
|
|
389
|
+
|
|
390
|
+
//#endregion
|
|
391
|
+
//#region node_modules/zod/dist/esm/v3/helpers/errorUtil.js
|
|
392
|
+
var errorUtil;
|
|
393
|
+
(function(errorUtil$1) {
|
|
394
|
+
errorUtil$1.errToObj = (message) => typeof message === "string" ? { message } : message || {};
|
|
395
|
+
errorUtil$1.toString = (message) => typeof message === "string" ? message : message?.message;
|
|
396
|
+
})(errorUtil || (errorUtil = {}));
|
|
397
|
+
|
|
398
|
+
//#endregion
|
|
399
|
+
//#region node_modules/zod/dist/esm/v3/types.js
|
|
400
|
+
var ParseInputLazyPath = class {
|
|
401
|
+
constructor(parent, value, path, key) {
|
|
402
|
+
this._cachedPath = [];
|
|
403
|
+
this.parent = parent;
|
|
404
|
+
this.data = value;
|
|
405
|
+
this._path = path;
|
|
406
|
+
this._key = key;
|
|
407
|
+
}
|
|
408
|
+
get path() {
|
|
409
|
+
if (!this._cachedPath.length) if (Array.isArray(this._key)) this._cachedPath.push(...this._path, ...this._key);
|
|
410
|
+
else this._cachedPath.push(...this._path, this._key);
|
|
411
|
+
return this._cachedPath;
|
|
412
|
+
}
|
|
413
|
+
};
|
|
414
|
+
const handleResult = (ctx, result) => {
|
|
415
|
+
if (isValid(result)) return {
|
|
416
|
+
success: true,
|
|
417
|
+
data: result.value
|
|
418
|
+
};
|
|
419
|
+
else {
|
|
420
|
+
if (!ctx.common.issues.length) throw new Error("Validation failed but no issues detected.");
|
|
421
|
+
return {
|
|
422
|
+
success: false,
|
|
423
|
+
get error() {
|
|
424
|
+
if (this._error) return this._error;
|
|
425
|
+
const error = new ZodError(ctx.common.issues);
|
|
426
|
+
this._error = error;
|
|
427
|
+
return this._error;
|
|
428
|
+
}
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
};
|
|
432
|
+
function processCreateParams(params) {
|
|
433
|
+
if (!params) return {};
|
|
434
|
+
const { errorMap: errorMap$1, invalid_type_error, required_error, description } = params;
|
|
435
|
+
if (errorMap$1 && (invalid_type_error || required_error)) throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
|
|
436
|
+
if (errorMap$1) return {
|
|
437
|
+
errorMap: errorMap$1,
|
|
438
|
+
description
|
|
439
|
+
};
|
|
440
|
+
const customMap = (iss, ctx) => {
|
|
441
|
+
const { message } = params;
|
|
442
|
+
if (iss.code === "invalid_enum_value") return { message: message ?? ctx.defaultError };
|
|
443
|
+
if (typeof ctx.data === "undefined") return { message: message ?? required_error ?? ctx.defaultError };
|
|
444
|
+
if (iss.code !== "invalid_type") return { message: ctx.defaultError };
|
|
445
|
+
return { message: message ?? invalid_type_error ?? ctx.defaultError };
|
|
446
|
+
};
|
|
447
|
+
return {
|
|
448
|
+
errorMap: customMap,
|
|
449
|
+
description
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
var ZodType = class {
|
|
453
|
+
get description() {
|
|
454
|
+
return this._def.description;
|
|
455
|
+
}
|
|
456
|
+
_getType(input) {
|
|
457
|
+
return getParsedType(input.data);
|
|
458
|
+
}
|
|
459
|
+
_getOrReturnCtx(input, ctx) {
|
|
460
|
+
return ctx || {
|
|
461
|
+
common: input.parent.common,
|
|
462
|
+
data: input.data,
|
|
463
|
+
parsedType: getParsedType(input.data),
|
|
464
|
+
schemaErrorMap: this._def.errorMap,
|
|
465
|
+
path: input.path,
|
|
466
|
+
parent: input.parent
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
_processInputParams(input) {
|
|
470
|
+
return {
|
|
471
|
+
status: new ParseStatus(),
|
|
472
|
+
ctx: {
|
|
473
|
+
common: input.parent.common,
|
|
474
|
+
data: input.data,
|
|
475
|
+
parsedType: getParsedType(input.data),
|
|
476
|
+
schemaErrorMap: this._def.errorMap,
|
|
477
|
+
path: input.path,
|
|
478
|
+
parent: input.parent
|
|
479
|
+
}
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
_parseSync(input) {
|
|
483
|
+
const result = this._parse(input);
|
|
484
|
+
if (isAsync(result)) throw new Error("Synchronous parse encountered promise.");
|
|
485
|
+
return result;
|
|
486
|
+
}
|
|
487
|
+
_parseAsync(input) {
|
|
488
|
+
const result = this._parse(input);
|
|
489
|
+
return Promise.resolve(result);
|
|
490
|
+
}
|
|
491
|
+
parse(data, params) {
|
|
492
|
+
const result = this.safeParse(data, params);
|
|
493
|
+
if (result.success) return result.data;
|
|
494
|
+
throw result.error;
|
|
495
|
+
}
|
|
496
|
+
safeParse(data, params) {
|
|
497
|
+
const ctx = {
|
|
498
|
+
common: {
|
|
499
|
+
issues: [],
|
|
500
|
+
async: params?.async ?? false,
|
|
501
|
+
contextualErrorMap: params?.errorMap
|
|
502
|
+
},
|
|
503
|
+
path: params?.path || [],
|
|
504
|
+
schemaErrorMap: this._def.errorMap,
|
|
505
|
+
parent: null,
|
|
506
|
+
data,
|
|
507
|
+
parsedType: getParsedType(data)
|
|
508
|
+
};
|
|
509
|
+
const result = this._parseSync({
|
|
510
|
+
data,
|
|
511
|
+
path: ctx.path,
|
|
512
|
+
parent: ctx
|
|
513
|
+
});
|
|
514
|
+
return handleResult(ctx, result);
|
|
515
|
+
}
|
|
516
|
+
"~validate"(data) {
|
|
517
|
+
const ctx = {
|
|
518
|
+
common: {
|
|
519
|
+
issues: [],
|
|
520
|
+
async: !!this["~standard"].async
|
|
521
|
+
},
|
|
522
|
+
path: [],
|
|
523
|
+
schemaErrorMap: this._def.errorMap,
|
|
524
|
+
parent: null,
|
|
525
|
+
data,
|
|
526
|
+
parsedType: getParsedType(data)
|
|
527
|
+
};
|
|
528
|
+
if (!this["~standard"].async) try {
|
|
529
|
+
const result = this._parseSync({
|
|
530
|
+
data,
|
|
531
|
+
path: [],
|
|
532
|
+
parent: ctx
|
|
533
|
+
});
|
|
534
|
+
return isValid(result) ? { value: result.value } : { issues: ctx.common.issues };
|
|
535
|
+
} catch (err) {
|
|
536
|
+
if (err?.message?.toLowerCase()?.includes("encountered")) this["~standard"].async = true;
|
|
537
|
+
ctx.common = {
|
|
538
|
+
issues: [],
|
|
539
|
+
async: true
|
|
540
|
+
};
|
|
541
|
+
}
|
|
542
|
+
return this._parseAsync({
|
|
543
|
+
data,
|
|
544
|
+
path: [],
|
|
545
|
+
parent: ctx
|
|
546
|
+
}).then((result) => isValid(result) ? { value: result.value } : { issues: ctx.common.issues });
|
|
547
|
+
}
|
|
548
|
+
async parseAsync(data, params) {
|
|
549
|
+
const result = await this.safeParseAsync(data, params);
|
|
550
|
+
if (result.success) return result.data;
|
|
551
|
+
throw result.error;
|
|
552
|
+
}
|
|
553
|
+
async safeParseAsync(data, params) {
|
|
554
|
+
const ctx = {
|
|
555
|
+
common: {
|
|
556
|
+
issues: [],
|
|
557
|
+
contextualErrorMap: params?.errorMap,
|
|
558
|
+
async: true
|
|
559
|
+
},
|
|
560
|
+
path: params?.path || [],
|
|
561
|
+
schemaErrorMap: this._def.errorMap,
|
|
562
|
+
parent: null,
|
|
563
|
+
data,
|
|
564
|
+
parsedType: getParsedType(data)
|
|
565
|
+
};
|
|
566
|
+
const maybeAsyncResult = this._parse({
|
|
567
|
+
data,
|
|
568
|
+
path: ctx.path,
|
|
569
|
+
parent: ctx
|
|
570
|
+
});
|
|
571
|
+
const result = await (isAsync(maybeAsyncResult) ? maybeAsyncResult : Promise.resolve(maybeAsyncResult));
|
|
572
|
+
return handleResult(ctx, result);
|
|
573
|
+
}
|
|
574
|
+
refine(check, message) {
|
|
575
|
+
const getIssueProperties = (val) => {
|
|
576
|
+
if (typeof message === "string" || typeof message === "undefined") return { message };
|
|
577
|
+
else if (typeof message === "function") return message(val);
|
|
578
|
+
else return message;
|
|
579
|
+
};
|
|
580
|
+
return this._refinement((val, ctx) => {
|
|
581
|
+
const result = check(val);
|
|
582
|
+
const setError = () => ctx.addIssue({
|
|
583
|
+
code: ZodIssueCode.custom,
|
|
584
|
+
...getIssueProperties(val)
|
|
585
|
+
});
|
|
586
|
+
if (typeof Promise !== "undefined" && result instanceof Promise) return result.then((data) => {
|
|
587
|
+
if (!data) {
|
|
588
|
+
setError();
|
|
589
|
+
return false;
|
|
590
|
+
} else return true;
|
|
591
|
+
});
|
|
592
|
+
if (!result) {
|
|
593
|
+
setError();
|
|
594
|
+
return false;
|
|
595
|
+
} else return true;
|
|
596
|
+
});
|
|
597
|
+
}
|
|
598
|
+
refinement(check, refinementData) {
|
|
599
|
+
return this._refinement((val, ctx) => {
|
|
600
|
+
if (!check(val)) {
|
|
601
|
+
ctx.addIssue(typeof refinementData === "function" ? refinementData(val, ctx) : refinementData);
|
|
602
|
+
return false;
|
|
603
|
+
} else return true;
|
|
604
|
+
});
|
|
605
|
+
}
|
|
606
|
+
_refinement(refinement) {
|
|
607
|
+
return new ZodEffects({
|
|
608
|
+
schema: this,
|
|
609
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
610
|
+
effect: {
|
|
611
|
+
type: "refinement",
|
|
612
|
+
refinement
|
|
613
|
+
}
|
|
614
|
+
});
|
|
615
|
+
}
|
|
616
|
+
superRefine(refinement) {
|
|
617
|
+
return this._refinement(refinement);
|
|
618
|
+
}
|
|
619
|
+
constructor(def) {
|
|
620
|
+
/** Alias of safeParseAsync */
|
|
621
|
+
this.spa = this.safeParseAsync;
|
|
622
|
+
this._def = def;
|
|
623
|
+
this.parse = this.parse.bind(this);
|
|
624
|
+
this.safeParse = this.safeParse.bind(this);
|
|
625
|
+
this.parseAsync = this.parseAsync.bind(this);
|
|
626
|
+
this.safeParseAsync = this.safeParseAsync.bind(this);
|
|
627
|
+
this.spa = this.spa.bind(this);
|
|
628
|
+
this.refine = this.refine.bind(this);
|
|
629
|
+
this.refinement = this.refinement.bind(this);
|
|
630
|
+
this.superRefine = this.superRefine.bind(this);
|
|
631
|
+
this.optional = this.optional.bind(this);
|
|
632
|
+
this.nullable = this.nullable.bind(this);
|
|
633
|
+
this.nullish = this.nullish.bind(this);
|
|
634
|
+
this.array = this.array.bind(this);
|
|
635
|
+
this.promise = this.promise.bind(this);
|
|
636
|
+
this.or = this.or.bind(this);
|
|
637
|
+
this.and = this.and.bind(this);
|
|
638
|
+
this.transform = this.transform.bind(this);
|
|
639
|
+
this.brand = this.brand.bind(this);
|
|
640
|
+
this.default = this.default.bind(this);
|
|
641
|
+
this.catch = this.catch.bind(this);
|
|
642
|
+
this.describe = this.describe.bind(this);
|
|
643
|
+
this.pipe = this.pipe.bind(this);
|
|
644
|
+
this.readonly = this.readonly.bind(this);
|
|
645
|
+
this.isNullable = this.isNullable.bind(this);
|
|
646
|
+
this.isOptional = this.isOptional.bind(this);
|
|
647
|
+
this["~standard"] = {
|
|
648
|
+
version: 1,
|
|
649
|
+
vendor: "zod",
|
|
650
|
+
validate: (data) => this["~validate"](data)
|
|
651
|
+
};
|
|
652
|
+
}
|
|
653
|
+
optional() {
|
|
654
|
+
return ZodOptional.create(this, this._def);
|
|
655
|
+
}
|
|
656
|
+
nullable() {
|
|
657
|
+
return ZodNullable.create(this, this._def);
|
|
658
|
+
}
|
|
659
|
+
nullish() {
|
|
660
|
+
return this.nullable().optional();
|
|
661
|
+
}
|
|
662
|
+
array() {
|
|
663
|
+
return ZodArray.create(this);
|
|
664
|
+
}
|
|
665
|
+
promise() {
|
|
666
|
+
return ZodPromise.create(this, this._def);
|
|
667
|
+
}
|
|
668
|
+
or(option) {
|
|
669
|
+
return ZodUnion.create([this, option], this._def);
|
|
670
|
+
}
|
|
671
|
+
and(incoming) {
|
|
672
|
+
return ZodIntersection.create(this, incoming, this._def);
|
|
673
|
+
}
|
|
674
|
+
transform(transform) {
|
|
675
|
+
return new ZodEffects({
|
|
676
|
+
...processCreateParams(this._def),
|
|
677
|
+
schema: this,
|
|
678
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
679
|
+
effect: {
|
|
680
|
+
type: "transform",
|
|
681
|
+
transform
|
|
682
|
+
}
|
|
683
|
+
});
|
|
684
|
+
}
|
|
685
|
+
default(def) {
|
|
686
|
+
const defaultValueFunc = typeof def === "function" ? def : () => def;
|
|
687
|
+
return new ZodDefault({
|
|
688
|
+
...processCreateParams(this._def),
|
|
689
|
+
innerType: this,
|
|
690
|
+
defaultValue: defaultValueFunc,
|
|
691
|
+
typeName: ZodFirstPartyTypeKind.ZodDefault
|
|
692
|
+
});
|
|
693
|
+
}
|
|
694
|
+
brand() {
|
|
695
|
+
return new ZodBranded({
|
|
696
|
+
typeName: ZodFirstPartyTypeKind.ZodBranded,
|
|
697
|
+
type: this,
|
|
698
|
+
...processCreateParams(this._def)
|
|
699
|
+
});
|
|
700
|
+
}
|
|
701
|
+
catch(def) {
|
|
702
|
+
const catchValueFunc = typeof def === "function" ? def : () => def;
|
|
703
|
+
return new ZodCatch({
|
|
704
|
+
...processCreateParams(this._def),
|
|
705
|
+
innerType: this,
|
|
706
|
+
catchValue: catchValueFunc,
|
|
707
|
+
typeName: ZodFirstPartyTypeKind.ZodCatch
|
|
708
|
+
});
|
|
709
|
+
}
|
|
710
|
+
describe(description) {
|
|
711
|
+
const This = this.constructor;
|
|
712
|
+
return new This({
|
|
713
|
+
...this._def,
|
|
714
|
+
description
|
|
715
|
+
});
|
|
716
|
+
}
|
|
717
|
+
pipe(target) {
|
|
718
|
+
return ZodPipeline.create(this, target);
|
|
719
|
+
}
|
|
720
|
+
readonly() {
|
|
721
|
+
return ZodReadonly.create(this);
|
|
722
|
+
}
|
|
723
|
+
isOptional() {
|
|
724
|
+
return this.safeParse(void 0).success;
|
|
725
|
+
}
|
|
726
|
+
isNullable() {
|
|
727
|
+
return this.safeParse(null).success;
|
|
728
|
+
}
|
|
729
|
+
};
|
|
730
|
+
const cuidRegex = /^c[^\s-]{8,}$/i;
|
|
731
|
+
const cuid2Regex = /^[0-9a-z]+$/;
|
|
732
|
+
const ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
|
|
733
|
+
const uuidRegex = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i;
|
|
734
|
+
const nanoidRegex = /^[a-z0-9_-]{21}$/i;
|
|
735
|
+
const jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;
|
|
736
|
+
const durationRegex = /^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/;
|
|
737
|
+
const emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
|
|
738
|
+
const _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
|
|
739
|
+
let emojiRegex;
|
|
740
|
+
const ipv4Regex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
|
|
741
|
+
const ipv4CidrRegex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/;
|
|
742
|
+
const ipv6Regex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/;
|
|
743
|
+
const ipv6CidrRegex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
|
|
744
|
+
const base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
|
|
745
|
+
const base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/;
|
|
746
|
+
const dateRegexSource = `((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))`;
|
|
747
|
+
const dateRegex = new RegExp(`^${dateRegexSource}$`);
|
|
748
|
+
function timeRegexSource(args) {
|
|
749
|
+
let secondsRegexSource = `[0-5]\\d`;
|
|
750
|
+
if (args.precision) secondsRegexSource = `${secondsRegexSource}\\.\\d{${args.precision}}`;
|
|
751
|
+
else if (args.precision == null) secondsRegexSource = `${secondsRegexSource}(\\.\\d+)?`;
|
|
752
|
+
const secondsQuantifier = args.precision ? "+" : "?";
|
|
753
|
+
return `([01]\\d|2[0-3]):[0-5]\\d(:${secondsRegexSource})${secondsQuantifier}`;
|
|
754
|
+
}
|
|
755
|
+
function timeRegex(args) {
|
|
756
|
+
return new RegExp(`^${timeRegexSource(args)}$`);
|
|
757
|
+
}
|
|
758
|
+
function datetimeRegex(args) {
|
|
759
|
+
let regex = `${dateRegexSource}T${timeRegexSource(args)}`;
|
|
760
|
+
const opts = [];
|
|
761
|
+
opts.push(args.local ? `Z?` : `Z`);
|
|
762
|
+
if (args.offset) opts.push(`([+-]\\d{2}:?\\d{2})`);
|
|
763
|
+
regex = `${regex}(${opts.join("|")})`;
|
|
764
|
+
return new RegExp(`^${regex}$`);
|
|
765
|
+
}
|
|
766
|
+
function isValidIP(ip, version) {
|
|
767
|
+
if ((version === "v4" || !version) && ipv4Regex.test(ip)) return true;
|
|
768
|
+
if ((version === "v6" || !version) && ipv6Regex.test(ip)) return true;
|
|
769
|
+
return false;
|
|
770
|
+
}
|
|
771
|
+
function isValidJWT(jwt, alg) {
|
|
772
|
+
if (!jwtRegex.test(jwt)) return false;
|
|
773
|
+
try {
|
|
774
|
+
const [header] = jwt.split(".");
|
|
775
|
+
const base64 = header.replace(/-/g, "+").replace(/_/g, "/").padEnd(header.length + (4 - header.length % 4) % 4, "=");
|
|
776
|
+
const decoded = JSON.parse(atob(base64));
|
|
777
|
+
if (typeof decoded !== "object" || decoded === null) return false;
|
|
778
|
+
if ("typ" in decoded && decoded?.typ !== "JWT") return false;
|
|
779
|
+
if (!decoded.alg) return false;
|
|
780
|
+
if (alg && decoded.alg !== alg) return false;
|
|
781
|
+
return true;
|
|
782
|
+
} catch {
|
|
783
|
+
return false;
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
function isValidCidr(ip, version) {
|
|
787
|
+
if ((version === "v4" || !version) && ipv4CidrRegex.test(ip)) return true;
|
|
788
|
+
if ((version === "v6" || !version) && ipv6CidrRegex.test(ip)) return true;
|
|
789
|
+
return false;
|
|
790
|
+
}
|
|
791
|
+
var ZodString = class ZodString extends ZodType {
|
|
792
|
+
_parse(input) {
|
|
793
|
+
if (this._def.coerce) input.data = String(input.data);
|
|
794
|
+
const parsedType = this._getType(input);
|
|
795
|
+
if (parsedType !== ZodParsedType.string) {
|
|
796
|
+
const ctx$1 = this._getOrReturnCtx(input);
|
|
797
|
+
addIssueToContext(ctx$1, {
|
|
798
|
+
code: ZodIssueCode.invalid_type,
|
|
799
|
+
expected: ZodParsedType.string,
|
|
800
|
+
received: ctx$1.parsedType
|
|
801
|
+
});
|
|
802
|
+
return INVALID;
|
|
803
|
+
}
|
|
804
|
+
const status = new ParseStatus();
|
|
805
|
+
let ctx = void 0;
|
|
806
|
+
for (const check of this._def.checks) if (check.kind === "min") {
|
|
807
|
+
if (input.data.length < check.value) {
|
|
808
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
809
|
+
addIssueToContext(ctx, {
|
|
810
|
+
code: ZodIssueCode.too_small,
|
|
811
|
+
minimum: check.value,
|
|
812
|
+
type: "string",
|
|
813
|
+
inclusive: true,
|
|
814
|
+
exact: false,
|
|
815
|
+
message: check.message
|
|
816
|
+
});
|
|
817
|
+
status.dirty();
|
|
818
|
+
}
|
|
819
|
+
} else if (check.kind === "max") {
|
|
820
|
+
if (input.data.length > check.value) {
|
|
821
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
822
|
+
addIssueToContext(ctx, {
|
|
823
|
+
code: ZodIssueCode.too_big,
|
|
824
|
+
maximum: check.value,
|
|
825
|
+
type: "string",
|
|
826
|
+
inclusive: true,
|
|
827
|
+
exact: false,
|
|
828
|
+
message: check.message
|
|
829
|
+
});
|
|
830
|
+
status.dirty();
|
|
831
|
+
}
|
|
832
|
+
} else if (check.kind === "length") {
|
|
833
|
+
const tooBig = input.data.length > check.value;
|
|
834
|
+
const tooSmall = input.data.length < check.value;
|
|
835
|
+
if (tooBig || tooSmall) {
|
|
836
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
837
|
+
if (tooBig) addIssueToContext(ctx, {
|
|
838
|
+
code: ZodIssueCode.too_big,
|
|
839
|
+
maximum: check.value,
|
|
840
|
+
type: "string",
|
|
841
|
+
inclusive: true,
|
|
842
|
+
exact: true,
|
|
843
|
+
message: check.message
|
|
844
|
+
});
|
|
845
|
+
else if (tooSmall) addIssueToContext(ctx, {
|
|
846
|
+
code: ZodIssueCode.too_small,
|
|
847
|
+
minimum: check.value,
|
|
848
|
+
type: "string",
|
|
849
|
+
inclusive: true,
|
|
850
|
+
exact: true,
|
|
851
|
+
message: check.message
|
|
852
|
+
});
|
|
853
|
+
status.dirty();
|
|
854
|
+
}
|
|
855
|
+
} else if (check.kind === "email") {
|
|
856
|
+
if (!emailRegex.test(input.data)) {
|
|
857
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
858
|
+
addIssueToContext(ctx, {
|
|
859
|
+
validation: "email",
|
|
860
|
+
code: ZodIssueCode.invalid_string,
|
|
861
|
+
message: check.message
|
|
862
|
+
});
|
|
863
|
+
status.dirty();
|
|
864
|
+
}
|
|
865
|
+
} else if (check.kind === "emoji") {
|
|
866
|
+
if (!emojiRegex) emojiRegex = new RegExp(_emojiRegex, "u");
|
|
867
|
+
if (!emojiRegex.test(input.data)) {
|
|
868
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
869
|
+
addIssueToContext(ctx, {
|
|
870
|
+
validation: "emoji",
|
|
871
|
+
code: ZodIssueCode.invalid_string,
|
|
872
|
+
message: check.message
|
|
873
|
+
});
|
|
874
|
+
status.dirty();
|
|
875
|
+
}
|
|
876
|
+
} else if (check.kind === "uuid") {
|
|
877
|
+
if (!uuidRegex.test(input.data)) {
|
|
878
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
879
|
+
addIssueToContext(ctx, {
|
|
880
|
+
validation: "uuid",
|
|
881
|
+
code: ZodIssueCode.invalid_string,
|
|
882
|
+
message: check.message
|
|
883
|
+
});
|
|
884
|
+
status.dirty();
|
|
885
|
+
}
|
|
886
|
+
} else if (check.kind === "nanoid") {
|
|
887
|
+
if (!nanoidRegex.test(input.data)) {
|
|
888
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
889
|
+
addIssueToContext(ctx, {
|
|
890
|
+
validation: "nanoid",
|
|
891
|
+
code: ZodIssueCode.invalid_string,
|
|
892
|
+
message: check.message
|
|
893
|
+
});
|
|
894
|
+
status.dirty();
|
|
895
|
+
}
|
|
896
|
+
} else if (check.kind === "cuid") {
|
|
897
|
+
if (!cuidRegex.test(input.data)) {
|
|
898
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
899
|
+
addIssueToContext(ctx, {
|
|
900
|
+
validation: "cuid",
|
|
901
|
+
code: ZodIssueCode.invalid_string,
|
|
902
|
+
message: check.message
|
|
903
|
+
});
|
|
904
|
+
status.dirty();
|
|
905
|
+
}
|
|
906
|
+
} else if (check.kind === "cuid2") {
|
|
907
|
+
if (!cuid2Regex.test(input.data)) {
|
|
908
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
909
|
+
addIssueToContext(ctx, {
|
|
910
|
+
validation: "cuid2",
|
|
911
|
+
code: ZodIssueCode.invalid_string,
|
|
912
|
+
message: check.message
|
|
913
|
+
});
|
|
914
|
+
status.dirty();
|
|
915
|
+
}
|
|
916
|
+
} else if (check.kind === "ulid") {
|
|
917
|
+
if (!ulidRegex.test(input.data)) {
|
|
918
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
919
|
+
addIssueToContext(ctx, {
|
|
920
|
+
validation: "ulid",
|
|
921
|
+
code: ZodIssueCode.invalid_string,
|
|
922
|
+
message: check.message
|
|
923
|
+
});
|
|
924
|
+
status.dirty();
|
|
925
|
+
}
|
|
926
|
+
} else if (check.kind === "url") try {
|
|
927
|
+
new URL(input.data);
|
|
928
|
+
} catch {
|
|
929
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
930
|
+
addIssueToContext(ctx, {
|
|
931
|
+
validation: "url",
|
|
932
|
+
code: ZodIssueCode.invalid_string,
|
|
933
|
+
message: check.message
|
|
934
|
+
});
|
|
935
|
+
status.dirty();
|
|
936
|
+
}
|
|
937
|
+
else if (check.kind === "regex") {
|
|
938
|
+
check.regex.lastIndex = 0;
|
|
939
|
+
const testResult = check.regex.test(input.data);
|
|
940
|
+
if (!testResult) {
|
|
941
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
942
|
+
addIssueToContext(ctx, {
|
|
943
|
+
validation: "regex",
|
|
944
|
+
code: ZodIssueCode.invalid_string,
|
|
945
|
+
message: check.message
|
|
946
|
+
});
|
|
947
|
+
status.dirty();
|
|
948
|
+
}
|
|
949
|
+
} else if (check.kind === "trim") input.data = input.data.trim();
|
|
950
|
+
else if (check.kind === "includes") {
|
|
951
|
+
if (!input.data.includes(check.value, check.position)) {
|
|
952
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
953
|
+
addIssueToContext(ctx, {
|
|
954
|
+
code: ZodIssueCode.invalid_string,
|
|
955
|
+
validation: {
|
|
956
|
+
includes: check.value,
|
|
957
|
+
position: check.position
|
|
958
|
+
},
|
|
959
|
+
message: check.message
|
|
960
|
+
});
|
|
961
|
+
status.dirty();
|
|
962
|
+
}
|
|
963
|
+
} else if (check.kind === "toLowerCase") input.data = input.data.toLowerCase();
|
|
964
|
+
else if (check.kind === "toUpperCase") input.data = input.data.toUpperCase();
|
|
965
|
+
else if (check.kind === "startsWith") {
|
|
966
|
+
if (!input.data.startsWith(check.value)) {
|
|
967
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
968
|
+
addIssueToContext(ctx, {
|
|
969
|
+
code: ZodIssueCode.invalid_string,
|
|
970
|
+
validation: { startsWith: check.value },
|
|
971
|
+
message: check.message
|
|
972
|
+
});
|
|
973
|
+
status.dirty();
|
|
974
|
+
}
|
|
975
|
+
} else if (check.kind === "endsWith") {
|
|
976
|
+
if (!input.data.endsWith(check.value)) {
|
|
977
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
978
|
+
addIssueToContext(ctx, {
|
|
979
|
+
code: ZodIssueCode.invalid_string,
|
|
980
|
+
validation: { endsWith: check.value },
|
|
981
|
+
message: check.message
|
|
982
|
+
});
|
|
983
|
+
status.dirty();
|
|
984
|
+
}
|
|
985
|
+
} else if (check.kind === "datetime") {
|
|
986
|
+
const regex = datetimeRegex(check);
|
|
987
|
+
if (!regex.test(input.data)) {
|
|
988
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
989
|
+
addIssueToContext(ctx, {
|
|
990
|
+
code: ZodIssueCode.invalid_string,
|
|
991
|
+
validation: "datetime",
|
|
992
|
+
message: check.message
|
|
993
|
+
});
|
|
994
|
+
status.dirty();
|
|
995
|
+
}
|
|
996
|
+
} else if (check.kind === "date") {
|
|
997
|
+
const regex = dateRegex;
|
|
998
|
+
if (!regex.test(input.data)) {
|
|
999
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1000
|
+
addIssueToContext(ctx, {
|
|
1001
|
+
code: ZodIssueCode.invalid_string,
|
|
1002
|
+
validation: "date",
|
|
1003
|
+
message: check.message
|
|
1004
|
+
});
|
|
1005
|
+
status.dirty();
|
|
1006
|
+
}
|
|
1007
|
+
} else if (check.kind === "time") {
|
|
1008
|
+
const regex = timeRegex(check);
|
|
1009
|
+
if (!regex.test(input.data)) {
|
|
1010
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1011
|
+
addIssueToContext(ctx, {
|
|
1012
|
+
code: ZodIssueCode.invalid_string,
|
|
1013
|
+
validation: "time",
|
|
1014
|
+
message: check.message
|
|
1015
|
+
});
|
|
1016
|
+
status.dirty();
|
|
1017
|
+
}
|
|
1018
|
+
} else if (check.kind === "duration") {
|
|
1019
|
+
if (!durationRegex.test(input.data)) {
|
|
1020
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1021
|
+
addIssueToContext(ctx, {
|
|
1022
|
+
validation: "duration",
|
|
1023
|
+
code: ZodIssueCode.invalid_string,
|
|
1024
|
+
message: check.message
|
|
1025
|
+
});
|
|
1026
|
+
status.dirty();
|
|
1027
|
+
}
|
|
1028
|
+
} else if (check.kind === "ip") {
|
|
1029
|
+
if (!isValidIP(input.data, check.version)) {
|
|
1030
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1031
|
+
addIssueToContext(ctx, {
|
|
1032
|
+
validation: "ip",
|
|
1033
|
+
code: ZodIssueCode.invalid_string,
|
|
1034
|
+
message: check.message
|
|
1035
|
+
});
|
|
1036
|
+
status.dirty();
|
|
1037
|
+
}
|
|
1038
|
+
} else if (check.kind === "jwt") {
|
|
1039
|
+
if (!isValidJWT(input.data, check.alg)) {
|
|
1040
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1041
|
+
addIssueToContext(ctx, {
|
|
1042
|
+
validation: "jwt",
|
|
1043
|
+
code: ZodIssueCode.invalid_string,
|
|
1044
|
+
message: check.message
|
|
1045
|
+
});
|
|
1046
|
+
status.dirty();
|
|
1047
|
+
}
|
|
1048
|
+
} else if (check.kind === "cidr") {
|
|
1049
|
+
if (!isValidCidr(input.data, check.version)) {
|
|
1050
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1051
|
+
addIssueToContext(ctx, {
|
|
1052
|
+
validation: "cidr",
|
|
1053
|
+
code: ZodIssueCode.invalid_string,
|
|
1054
|
+
message: check.message
|
|
1055
|
+
});
|
|
1056
|
+
status.dirty();
|
|
1057
|
+
}
|
|
1058
|
+
} else if (check.kind === "base64") {
|
|
1059
|
+
if (!base64Regex.test(input.data)) {
|
|
1060
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1061
|
+
addIssueToContext(ctx, {
|
|
1062
|
+
validation: "base64",
|
|
1063
|
+
code: ZodIssueCode.invalid_string,
|
|
1064
|
+
message: check.message
|
|
1065
|
+
});
|
|
1066
|
+
status.dirty();
|
|
1067
|
+
}
|
|
1068
|
+
} else if (check.kind === "base64url") {
|
|
1069
|
+
if (!base64urlRegex.test(input.data)) {
|
|
1070
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1071
|
+
addIssueToContext(ctx, {
|
|
1072
|
+
validation: "base64url",
|
|
1073
|
+
code: ZodIssueCode.invalid_string,
|
|
1074
|
+
message: check.message
|
|
1075
|
+
});
|
|
1076
|
+
status.dirty();
|
|
1077
|
+
}
|
|
1078
|
+
} else util.assertNever(check);
|
|
1079
|
+
return {
|
|
1080
|
+
status: status.value,
|
|
1081
|
+
value: input.data
|
|
1082
|
+
};
|
|
1083
|
+
}
|
|
1084
|
+
_regex(regex, validation, message) {
|
|
1085
|
+
return this.refinement((data) => regex.test(data), {
|
|
1086
|
+
validation,
|
|
1087
|
+
code: ZodIssueCode.invalid_string,
|
|
1088
|
+
...errorUtil.errToObj(message)
|
|
1089
|
+
});
|
|
1090
|
+
}
|
|
1091
|
+
_addCheck(check) {
|
|
1092
|
+
return new ZodString({
|
|
1093
|
+
...this._def,
|
|
1094
|
+
checks: [...this._def.checks, check]
|
|
1095
|
+
});
|
|
1096
|
+
}
|
|
1097
|
+
email(message) {
|
|
1098
|
+
return this._addCheck({
|
|
1099
|
+
kind: "email",
|
|
1100
|
+
...errorUtil.errToObj(message)
|
|
1101
|
+
});
|
|
1102
|
+
}
|
|
1103
|
+
url(message) {
|
|
1104
|
+
return this._addCheck({
|
|
1105
|
+
kind: "url",
|
|
1106
|
+
...errorUtil.errToObj(message)
|
|
1107
|
+
});
|
|
1108
|
+
}
|
|
1109
|
+
emoji(message) {
|
|
1110
|
+
return this._addCheck({
|
|
1111
|
+
kind: "emoji",
|
|
1112
|
+
...errorUtil.errToObj(message)
|
|
1113
|
+
});
|
|
1114
|
+
}
|
|
1115
|
+
uuid(message) {
|
|
1116
|
+
return this._addCheck({
|
|
1117
|
+
kind: "uuid",
|
|
1118
|
+
...errorUtil.errToObj(message)
|
|
1119
|
+
});
|
|
1120
|
+
}
|
|
1121
|
+
nanoid(message) {
|
|
1122
|
+
return this._addCheck({
|
|
1123
|
+
kind: "nanoid",
|
|
1124
|
+
...errorUtil.errToObj(message)
|
|
1125
|
+
});
|
|
1126
|
+
}
|
|
1127
|
+
cuid(message) {
|
|
1128
|
+
return this._addCheck({
|
|
1129
|
+
kind: "cuid",
|
|
1130
|
+
...errorUtil.errToObj(message)
|
|
1131
|
+
});
|
|
1132
|
+
}
|
|
1133
|
+
cuid2(message) {
|
|
1134
|
+
return this._addCheck({
|
|
1135
|
+
kind: "cuid2",
|
|
1136
|
+
...errorUtil.errToObj(message)
|
|
1137
|
+
});
|
|
1138
|
+
}
|
|
1139
|
+
ulid(message) {
|
|
1140
|
+
return this._addCheck({
|
|
1141
|
+
kind: "ulid",
|
|
1142
|
+
...errorUtil.errToObj(message)
|
|
1143
|
+
});
|
|
1144
|
+
}
|
|
1145
|
+
base64(message) {
|
|
1146
|
+
return this._addCheck({
|
|
1147
|
+
kind: "base64",
|
|
1148
|
+
...errorUtil.errToObj(message)
|
|
1149
|
+
});
|
|
1150
|
+
}
|
|
1151
|
+
base64url(message) {
|
|
1152
|
+
return this._addCheck({
|
|
1153
|
+
kind: "base64url",
|
|
1154
|
+
...errorUtil.errToObj(message)
|
|
1155
|
+
});
|
|
1156
|
+
}
|
|
1157
|
+
jwt(options) {
|
|
1158
|
+
return this._addCheck({
|
|
1159
|
+
kind: "jwt",
|
|
1160
|
+
...errorUtil.errToObj(options)
|
|
1161
|
+
});
|
|
1162
|
+
}
|
|
1163
|
+
ip(options) {
|
|
1164
|
+
return this._addCheck({
|
|
1165
|
+
kind: "ip",
|
|
1166
|
+
...errorUtil.errToObj(options)
|
|
1167
|
+
});
|
|
1168
|
+
}
|
|
1169
|
+
cidr(options) {
|
|
1170
|
+
return this._addCheck({
|
|
1171
|
+
kind: "cidr",
|
|
1172
|
+
...errorUtil.errToObj(options)
|
|
1173
|
+
});
|
|
1174
|
+
}
|
|
1175
|
+
datetime(options) {
|
|
1176
|
+
if (typeof options === "string") return this._addCheck({
|
|
1177
|
+
kind: "datetime",
|
|
1178
|
+
precision: null,
|
|
1179
|
+
offset: false,
|
|
1180
|
+
local: false,
|
|
1181
|
+
message: options
|
|
1182
|
+
});
|
|
1183
|
+
return this._addCheck({
|
|
1184
|
+
kind: "datetime",
|
|
1185
|
+
precision: typeof options?.precision === "undefined" ? null : options?.precision,
|
|
1186
|
+
offset: options?.offset ?? false,
|
|
1187
|
+
local: options?.local ?? false,
|
|
1188
|
+
...errorUtil.errToObj(options?.message)
|
|
1189
|
+
});
|
|
1190
|
+
}
|
|
1191
|
+
date(message) {
|
|
1192
|
+
return this._addCheck({
|
|
1193
|
+
kind: "date",
|
|
1194
|
+
message
|
|
1195
|
+
});
|
|
1196
|
+
}
|
|
1197
|
+
time(options) {
|
|
1198
|
+
if (typeof options === "string") return this._addCheck({
|
|
1199
|
+
kind: "time",
|
|
1200
|
+
precision: null,
|
|
1201
|
+
message: options
|
|
1202
|
+
});
|
|
1203
|
+
return this._addCheck({
|
|
1204
|
+
kind: "time",
|
|
1205
|
+
precision: typeof options?.precision === "undefined" ? null : options?.precision,
|
|
1206
|
+
...errorUtil.errToObj(options?.message)
|
|
1207
|
+
});
|
|
1208
|
+
}
|
|
1209
|
+
duration(message) {
|
|
1210
|
+
return this._addCheck({
|
|
1211
|
+
kind: "duration",
|
|
1212
|
+
...errorUtil.errToObj(message)
|
|
1213
|
+
});
|
|
1214
|
+
}
|
|
1215
|
+
regex(regex, message) {
|
|
1216
|
+
return this._addCheck({
|
|
1217
|
+
kind: "regex",
|
|
1218
|
+
regex,
|
|
1219
|
+
...errorUtil.errToObj(message)
|
|
1220
|
+
});
|
|
1221
|
+
}
|
|
1222
|
+
includes(value, options) {
|
|
1223
|
+
return this._addCheck({
|
|
1224
|
+
kind: "includes",
|
|
1225
|
+
value,
|
|
1226
|
+
position: options?.position,
|
|
1227
|
+
...errorUtil.errToObj(options?.message)
|
|
1228
|
+
});
|
|
1229
|
+
}
|
|
1230
|
+
startsWith(value, message) {
|
|
1231
|
+
return this._addCheck({
|
|
1232
|
+
kind: "startsWith",
|
|
1233
|
+
value,
|
|
1234
|
+
...errorUtil.errToObj(message)
|
|
1235
|
+
});
|
|
1236
|
+
}
|
|
1237
|
+
endsWith(value, message) {
|
|
1238
|
+
return this._addCheck({
|
|
1239
|
+
kind: "endsWith",
|
|
1240
|
+
value,
|
|
1241
|
+
...errorUtil.errToObj(message)
|
|
1242
|
+
});
|
|
1243
|
+
}
|
|
1244
|
+
min(minLength, message) {
|
|
1245
|
+
return this._addCheck({
|
|
1246
|
+
kind: "min",
|
|
1247
|
+
value: minLength,
|
|
1248
|
+
...errorUtil.errToObj(message)
|
|
1249
|
+
});
|
|
1250
|
+
}
|
|
1251
|
+
max(maxLength, message) {
|
|
1252
|
+
return this._addCheck({
|
|
1253
|
+
kind: "max",
|
|
1254
|
+
value: maxLength,
|
|
1255
|
+
...errorUtil.errToObj(message)
|
|
1256
|
+
});
|
|
1257
|
+
}
|
|
1258
|
+
length(len, message) {
|
|
1259
|
+
return this._addCheck({
|
|
1260
|
+
kind: "length",
|
|
1261
|
+
value: len,
|
|
1262
|
+
...errorUtil.errToObj(message)
|
|
1263
|
+
});
|
|
1264
|
+
}
|
|
1265
|
+
/**
|
|
1266
|
+
* Equivalent to `.min(1)`
|
|
1267
|
+
*/
|
|
1268
|
+
nonempty(message) {
|
|
1269
|
+
return this.min(1, errorUtil.errToObj(message));
|
|
1270
|
+
}
|
|
1271
|
+
trim() {
|
|
1272
|
+
return new ZodString({
|
|
1273
|
+
...this._def,
|
|
1274
|
+
checks: [...this._def.checks, { kind: "trim" }]
|
|
1275
|
+
});
|
|
1276
|
+
}
|
|
1277
|
+
toLowerCase() {
|
|
1278
|
+
return new ZodString({
|
|
1279
|
+
...this._def,
|
|
1280
|
+
checks: [...this._def.checks, { kind: "toLowerCase" }]
|
|
1281
|
+
});
|
|
1282
|
+
}
|
|
1283
|
+
toUpperCase() {
|
|
1284
|
+
return new ZodString({
|
|
1285
|
+
...this._def,
|
|
1286
|
+
checks: [...this._def.checks, { kind: "toUpperCase" }]
|
|
1287
|
+
});
|
|
1288
|
+
}
|
|
1289
|
+
get isDatetime() {
|
|
1290
|
+
return !!this._def.checks.find((ch) => ch.kind === "datetime");
|
|
1291
|
+
}
|
|
1292
|
+
get isDate() {
|
|
1293
|
+
return !!this._def.checks.find((ch) => ch.kind === "date");
|
|
1294
|
+
}
|
|
1295
|
+
get isTime() {
|
|
1296
|
+
return !!this._def.checks.find((ch) => ch.kind === "time");
|
|
1297
|
+
}
|
|
1298
|
+
get isDuration() {
|
|
1299
|
+
return !!this._def.checks.find((ch) => ch.kind === "duration");
|
|
1300
|
+
}
|
|
1301
|
+
get isEmail() {
|
|
1302
|
+
return !!this._def.checks.find((ch) => ch.kind === "email");
|
|
1303
|
+
}
|
|
1304
|
+
get isURL() {
|
|
1305
|
+
return !!this._def.checks.find((ch) => ch.kind === "url");
|
|
1306
|
+
}
|
|
1307
|
+
get isEmoji() {
|
|
1308
|
+
return !!this._def.checks.find((ch) => ch.kind === "emoji");
|
|
1309
|
+
}
|
|
1310
|
+
get isUUID() {
|
|
1311
|
+
return !!this._def.checks.find((ch) => ch.kind === "uuid");
|
|
1312
|
+
}
|
|
1313
|
+
get isNANOID() {
|
|
1314
|
+
return !!this._def.checks.find((ch) => ch.kind === "nanoid");
|
|
1315
|
+
}
|
|
1316
|
+
get isCUID() {
|
|
1317
|
+
return !!this._def.checks.find((ch) => ch.kind === "cuid");
|
|
1318
|
+
}
|
|
1319
|
+
get isCUID2() {
|
|
1320
|
+
return !!this._def.checks.find((ch) => ch.kind === "cuid2");
|
|
1321
|
+
}
|
|
1322
|
+
get isULID() {
|
|
1323
|
+
return !!this._def.checks.find((ch) => ch.kind === "ulid");
|
|
1324
|
+
}
|
|
1325
|
+
get isIP() {
|
|
1326
|
+
return !!this._def.checks.find((ch) => ch.kind === "ip");
|
|
1327
|
+
}
|
|
1328
|
+
get isCIDR() {
|
|
1329
|
+
return !!this._def.checks.find((ch) => ch.kind === "cidr");
|
|
1330
|
+
}
|
|
1331
|
+
get isBase64() {
|
|
1332
|
+
return !!this._def.checks.find((ch) => ch.kind === "base64");
|
|
1333
|
+
}
|
|
1334
|
+
get isBase64url() {
|
|
1335
|
+
return !!this._def.checks.find((ch) => ch.kind === "base64url");
|
|
1336
|
+
}
|
|
1337
|
+
get minLength() {
|
|
1338
|
+
let min = null;
|
|
1339
|
+
for (const ch of this._def.checks) if (ch.kind === "min") {
|
|
1340
|
+
if (min === null || ch.value > min) min = ch.value;
|
|
1341
|
+
}
|
|
1342
|
+
return min;
|
|
1343
|
+
}
|
|
1344
|
+
get maxLength() {
|
|
1345
|
+
let max = null;
|
|
1346
|
+
for (const ch of this._def.checks) if (ch.kind === "max") {
|
|
1347
|
+
if (max === null || ch.value < max) max = ch.value;
|
|
1348
|
+
}
|
|
1349
|
+
return max;
|
|
1350
|
+
}
|
|
1351
|
+
};
|
|
1352
|
+
ZodString.create = (params) => {
|
|
1353
|
+
return new ZodString({
|
|
1354
|
+
checks: [],
|
|
1355
|
+
typeName: ZodFirstPartyTypeKind.ZodString,
|
|
1356
|
+
coerce: params?.coerce ?? false,
|
|
1357
|
+
...processCreateParams(params)
|
|
1358
|
+
});
|
|
1359
|
+
};
|
|
1360
|
+
function floatSafeRemainder(val, step) {
|
|
1361
|
+
const valDecCount = (val.toString().split(".")[1] || "").length;
|
|
1362
|
+
const stepDecCount = (step.toString().split(".")[1] || "").length;
|
|
1363
|
+
const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
|
|
1364
|
+
const valInt = Number.parseInt(val.toFixed(decCount).replace(".", ""));
|
|
1365
|
+
const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
|
|
1366
|
+
return valInt % stepInt / 10 ** decCount;
|
|
1367
|
+
}
|
|
1368
|
+
var ZodNumber = class ZodNumber extends ZodType {
|
|
1369
|
+
constructor() {
|
|
1370
|
+
super(...arguments);
|
|
1371
|
+
this.min = this.gte;
|
|
1372
|
+
this.max = this.lte;
|
|
1373
|
+
this.step = this.multipleOf;
|
|
1374
|
+
}
|
|
1375
|
+
_parse(input) {
|
|
1376
|
+
if (this._def.coerce) input.data = Number(input.data);
|
|
1377
|
+
const parsedType = this._getType(input);
|
|
1378
|
+
if (parsedType !== ZodParsedType.number) {
|
|
1379
|
+
const ctx$1 = this._getOrReturnCtx(input);
|
|
1380
|
+
addIssueToContext(ctx$1, {
|
|
1381
|
+
code: ZodIssueCode.invalid_type,
|
|
1382
|
+
expected: ZodParsedType.number,
|
|
1383
|
+
received: ctx$1.parsedType
|
|
1384
|
+
});
|
|
1385
|
+
return INVALID;
|
|
1386
|
+
}
|
|
1387
|
+
let ctx = void 0;
|
|
1388
|
+
const status = new ParseStatus();
|
|
1389
|
+
for (const check of this._def.checks) if (check.kind === "int") {
|
|
1390
|
+
if (!util.isInteger(input.data)) {
|
|
1391
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1392
|
+
addIssueToContext(ctx, {
|
|
1393
|
+
code: ZodIssueCode.invalid_type,
|
|
1394
|
+
expected: "integer",
|
|
1395
|
+
received: "float",
|
|
1396
|
+
message: check.message
|
|
1397
|
+
});
|
|
1398
|
+
status.dirty();
|
|
1399
|
+
}
|
|
1400
|
+
} else if (check.kind === "min") {
|
|
1401
|
+
const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
|
|
1402
|
+
if (tooSmall) {
|
|
1403
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1404
|
+
addIssueToContext(ctx, {
|
|
1405
|
+
code: ZodIssueCode.too_small,
|
|
1406
|
+
minimum: check.value,
|
|
1407
|
+
type: "number",
|
|
1408
|
+
inclusive: check.inclusive,
|
|
1409
|
+
exact: false,
|
|
1410
|
+
message: check.message
|
|
1411
|
+
});
|
|
1412
|
+
status.dirty();
|
|
1413
|
+
}
|
|
1414
|
+
} else if (check.kind === "max") {
|
|
1415
|
+
const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
|
|
1416
|
+
if (tooBig) {
|
|
1417
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1418
|
+
addIssueToContext(ctx, {
|
|
1419
|
+
code: ZodIssueCode.too_big,
|
|
1420
|
+
maximum: check.value,
|
|
1421
|
+
type: "number",
|
|
1422
|
+
inclusive: check.inclusive,
|
|
1423
|
+
exact: false,
|
|
1424
|
+
message: check.message
|
|
1425
|
+
});
|
|
1426
|
+
status.dirty();
|
|
1427
|
+
}
|
|
1428
|
+
} else if (check.kind === "multipleOf") {
|
|
1429
|
+
if (floatSafeRemainder(input.data, check.value) !== 0) {
|
|
1430
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1431
|
+
addIssueToContext(ctx, {
|
|
1432
|
+
code: ZodIssueCode.not_multiple_of,
|
|
1433
|
+
multipleOf: check.value,
|
|
1434
|
+
message: check.message
|
|
1435
|
+
});
|
|
1436
|
+
status.dirty();
|
|
1437
|
+
}
|
|
1438
|
+
} else if (check.kind === "finite") {
|
|
1439
|
+
if (!Number.isFinite(input.data)) {
|
|
1440
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1441
|
+
addIssueToContext(ctx, {
|
|
1442
|
+
code: ZodIssueCode.not_finite,
|
|
1443
|
+
message: check.message
|
|
1444
|
+
});
|
|
1445
|
+
status.dirty();
|
|
1446
|
+
}
|
|
1447
|
+
} else util.assertNever(check);
|
|
1448
|
+
return {
|
|
1449
|
+
status: status.value,
|
|
1450
|
+
value: input.data
|
|
1451
|
+
};
|
|
1452
|
+
}
|
|
1453
|
+
gte(value, message) {
|
|
1454
|
+
return this.setLimit("min", value, true, errorUtil.toString(message));
|
|
1455
|
+
}
|
|
1456
|
+
gt(value, message) {
|
|
1457
|
+
return this.setLimit("min", value, false, errorUtil.toString(message));
|
|
1458
|
+
}
|
|
1459
|
+
lte(value, message) {
|
|
1460
|
+
return this.setLimit("max", value, true, errorUtil.toString(message));
|
|
1461
|
+
}
|
|
1462
|
+
lt(value, message) {
|
|
1463
|
+
return this.setLimit("max", value, false, errorUtil.toString(message));
|
|
1464
|
+
}
|
|
1465
|
+
setLimit(kind, value, inclusive, message) {
|
|
1466
|
+
return new ZodNumber({
|
|
1467
|
+
...this._def,
|
|
1468
|
+
checks: [...this._def.checks, {
|
|
1469
|
+
kind,
|
|
1470
|
+
value,
|
|
1471
|
+
inclusive,
|
|
1472
|
+
message: errorUtil.toString(message)
|
|
1473
|
+
}]
|
|
1474
|
+
});
|
|
1475
|
+
}
|
|
1476
|
+
_addCheck(check) {
|
|
1477
|
+
return new ZodNumber({
|
|
1478
|
+
...this._def,
|
|
1479
|
+
checks: [...this._def.checks, check]
|
|
1480
|
+
});
|
|
1481
|
+
}
|
|
1482
|
+
int(message) {
|
|
1483
|
+
return this._addCheck({
|
|
1484
|
+
kind: "int",
|
|
1485
|
+
message: errorUtil.toString(message)
|
|
1486
|
+
});
|
|
1487
|
+
}
|
|
1488
|
+
positive(message) {
|
|
1489
|
+
return this._addCheck({
|
|
1490
|
+
kind: "min",
|
|
1491
|
+
value: 0,
|
|
1492
|
+
inclusive: false,
|
|
1493
|
+
message: errorUtil.toString(message)
|
|
1494
|
+
});
|
|
1495
|
+
}
|
|
1496
|
+
negative(message) {
|
|
1497
|
+
return this._addCheck({
|
|
1498
|
+
kind: "max",
|
|
1499
|
+
value: 0,
|
|
1500
|
+
inclusive: false,
|
|
1501
|
+
message: errorUtil.toString(message)
|
|
1502
|
+
});
|
|
1503
|
+
}
|
|
1504
|
+
nonpositive(message) {
|
|
1505
|
+
return this._addCheck({
|
|
1506
|
+
kind: "max",
|
|
1507
|
+
value: 0,
|
|
1508
|
+
inclusive: true,
|
|
1509
|
+
message: errorUtil.toString(message)
|
|
1510
|
+
});
|
|
1511
|
+
}
|
|
1512
|
+
nonnegative(message) {
|
|
1513
|
+
return this._addCheck({
|
|
1514
|
+
kind: "min",
|
|
1515
|
+
value: 0,
|
|
1516
|
+
inclusive: true,
|
|
1517
|
+
message: errorUtil.toString(message)
|
|
1518
|
+
});
|
|
1519
|
+
}
|
|
1520
|
+
multipleOf(value, message) {
|
|
1521
|
+
return this._addCheck({
|
|
1522
|
+
kind: "multipleOf",
|
|
1523
|
+
value,
|
|
1524
|
+
message: errorUtil.toString(message)
|
|
1525
|
+
});
|
|
1526
|
+
}
|
|
1527
|
+
finite(message) {
|
|
1528
|
+
return this._addCheck({
|
|
1529
|
+
kind: "finite",
|
|
1530
|
+
message: errorUtil.toString(message)
|
|
1531
|
+
});
|
|
1532
|
+
}
|
|
1533
|
+
safe(message) {
|
|
1534
|
+
return this._addCheck({
|
|
1535
|
+
kind: "min",
|
|
1536
|
+
inclusive: true,
|
|
1537
|
+
value: Number.MIN_SAFE_INTEGER,
|
|
1538
|
+
message: errorUtil.toString(message)
|
|
1539
|
+
})._addCheck({
|
|
1540
|
+
kind: "max",
|
|
1541
|
+
inclusive: true,
|
|
1542
|
+
value: Number.MAX_SAFE_INTEGER,
|
|
1543
|
+
message: errorUtil.toString(message)
|
|
1544
|
+
});
|
|
1545
|
+
}
|
|
1546
|
+
get minValue() {
|
|
1547
|
+
let min = null;
|
|
1548
|
+
for (const ch of this._def.checks) if (ch.kind === "min") {
|
|
1549
|
+
if (min === null || ch.value > min) min = ch.value;
|
|
1550
|
+
}
|
|
1551
|
+
return min;
|
|
1552
|
+
}
|
|
1553
|
+
get maxValue() {
|
|
1554
|
+
let max = null;
|
|
1555
|
+
for (const ch of this._def.checks) if (ch.kind === "max") {
|
|
1556
|
+
if (max === null || ch.value < max) max = ch.value;
|
|
1557
|
+
}
|
|
1558
|
+
return max;
|
|
1559
|
+
}
|
|
1560
|
+
get isInt() {
|
|
1561
|
+
return !!this._def.checks.find((ch) => ch.kind === "int" || ch.kind === "multipleOf" && util.isInteger(ch.value));
|
|
1562
|
+
}
|
|
1563
|
+
get isFinite() {
|
|
1564
|
+
let max = null;
|
|
1565
|
+
let min = null;
|
|
1566
|
+
for (const ch of this._def.checks) if (ch.kind === "finite" || ch.kind === "int" || ch.kind === "multipleOf") return true;
|
|
1567
|
+
else if (ch.kind === "min") {
|
|
1568
|
+
if (min === null || ch.value > min) min = ch.value;
|
|
1569
|
+
} else if (ch.kind === "max") {
|
|
1570
|
+
if (max === null || ch.value < max) max = ch.value;
|
|
1571
|
+
}
|
|
1572
|
+
return Number.isFinite(min) && Number.isFinite(max);
|
|
1573
|
+
}
|
|
1574
|
+
};
|
|
1575
|
+
ZodNumber.create = (params) => {
|
|
1576
|
+
return new ZodNumber({
|
|
1577
|
+
checks: [],
|
|
1578
|
+
typeName: ZodFirstPartyTypeKind.ZodNumber,
|
|
1579
|
+
coerce: params?.coerce || false,
|
|
1580
|
+
...processCreateParams(params)
|
|
1581
|
+
});
|
|
1582
|
+
};
|
|
1583
|
+
var ZodBigInt = class ZodBigInt extends ZodType {
|
|
1584
|
+
constructor() {
|
|
1585
|
+
super(...arguments);
|
|
1586
|
+
this.min = this.gte;
|
|
1587
|
+
this.max = this.lte;
|
|
1588
|
+
}
|
|
1589
|
+
_parse(input) {
|
|
1590
|
+
if (this._def.coerce) try {
|
|
1591
|
+
input.data = BigInt(input.data);
|
|
1592
|
+
} catch {
|
|
1593
|
+
return this._getInvalidInput(input);
|
|
1594
|
+
}
|
|
1595
|
+
const parsedType = this._getType(input);
|
|
1596
|
+
if (parsedType !== ZodParsedType.bigint) return this._getInvalidInput(input);
|
|
1597
|
+
let ctx = void 0;
|
|
1598
|
+
const status = new ParseStatus();
|
|
1599
|
+
for (const check of this._def.checks) if (check.kind === "min") {
|
|
1600
|
+
const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
|
|
1601
|
+
if (tooSmall) {
|
|
1602
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1603
|
+
addIssueToContext(ctx, {
|
|
1604
|
+
code: ZodIssueCode.too_small,
|
|
1605
|
+
type: "bigint",
|
|
1606
|
+
minimum: check.value,
|
|
1607
|
+
inclusive: check.inclusive,
|
|
1608
|
+
message: check.message
|
|
1609
|
+
});
|
|
1610
|
+
status.dirty();
|
|
1611
|
+
}
|
|
1612
|
+
} else if (check.kind === "max") {
|
|
1613
|
+
const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
|
|
1614
|
+
if (tooBig) {
|
|
1615
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1616
|
+
addIssueToContext(ctx, {
|
|
1617
|
+
code: ZodIssueCode.too_big,
|
|
1618
|
+
type: "bigint",
|
|
1619
|
+
maximum: check.value,
|
|
1620
|
+
inclusive: check.inclusive,
|
|
1621
|
+
message: check.message
|
|
1622
|
+
});
|
|
1623
|
+
status.dirty();
|
|
1624
|
+
}
|
|
1625
|
+
} else if (check.kind === "multipleOf") {
|
|
1626
|
+
if (input.data % check.value !== BigInt(0)) {
|
|
1627
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1628
|
+
addIssueToContext(ctx, {
|
|
1629
|
+
code: ZodIssueCode.not_multiple_of,
|
|
1630
|
+
multipleOf: check.value,
|
|
1631
|
+
message: check.message
|
|
1632
|
+
});
|
|
1633
|
+
status.dirty();
|
|
1634
|
+
}
|
|
1635
|
+
} else util.assertNever(check);
|
|
1636
|
+
return {
|
|
1637
|
+
status: status.value,
|
|
1638
|
+
value: input.data
|
|
1639
|
+
};
|
|
1640
|
+
}
|
|
1641
|
+
_getInvalidInput(input) {
|
|
1642
|
+
const ctx = this._getOrReturnCtx(input);
|
|
1643
|
+
addIssueToContext(ctx, {
|
|
1644
|
+
code: ZodIssueCode.invalid_type,
|
|
1645
|
+
expected: ZodParsedType.bigint,
|
|
1646
|
+
received: ctx.parsedType
|
|
1647
|
+
});
|
|
1648
|
+
return INVALID;
|
|
1649
|
+
}
|
|
1650
|
+
gte(value, message) {
|
|
1651
|
+
return this.setLimit("min", value, true, errorUtil.toString(message));
|
|
1652
|
+
}
|
|
1653
|
+
gt(value, message) {
|
|
1654
|
+
return this.setLimit("min", value, false, errorUtil.toString(message));
|
|
1655
|
+
}
|
|
1656
|
+
lte(value, message) {
|
|
1657
|
+
return this.setLimit("max", value, true, errorUtil.toString(message));
|
|
1658
|
+
}
|
|
1659
|
+
lt(value, message) {
|
|
1660
|
+
return this.setLimit("max", value, false, errorUtil.toString(message));
|
|
1661
|
+
}
|
|
1662
|
+
setLimit(kind, value, inclusive, message) {
|
|
1663
|
+
return new ZodBigInt({
|
|
1664
|
+
...this._def,
|
|
1665
|
+
checks: [...this._def.checks, {
|
|
1666
|
+
kind,
|
|
1667
|
+
value,
|
|
1668
|
+
inclusive,
|
|
1669
|
+
message: errorUtil.toString(message)
|
|
1670
|
+
}]
|
|
1671
|
+
});
|
|
1672
|
+
}
|
|
1673
|
+
_addCheck(check) {
|
|
1674
|
+
return new ZodBigInt({
|
|
1675
|
+
...this._def,
|
|
1676
|
+
checks: [...this._def.checks, check]
|
|
1677
|
+
});
|
|
1678
|
+
}
|
|
1679
|
+
positive(message) {
|
|
1680
|
+
return this._addCheck({
|
|
1681
|
+
kind: "min",
|
|
1682
|
+
value: BigInt(0),
|
|
1683
|
+
inclusive: false,
|
|
1684
|
+
message: errorUtil.toString(message)
|
|
1685
|
+
});
|
|
1686
|
+
}
|
|
1687
|
+
negative(message) {
|
|
1688
|
+
return this._addCheck({
|
|
1689
|
+
kind: "max",
|
|
1690
|
+
value: BigInt(0),
|
|
1691
|
+
inclusive: false,
|
|
1692
|
+
message: errorUtil.toString(message)
|
|
1693
|
+
});
|
|
1694
|
+
}
|
|
1695
|
+
nonpositive(message) {
|
|
1696
|
+
return this._addCheck({
|
|
1697
|
+
kind: "max",
|
|
1698
|
+
value: BigInt(0),
|
|
1699
|
+
inclusive: true,
|
|
1700
|
+
message: errorUtil.toString(message)
|
|
1701
|
+
});
|
|
1702
|
+
}
|
|
1703
|
+
nonnegative(message) {
|
|
1704
|
+
return this._addCheck({
|
|
1705
|
+
kind: "min",
|
|
1706
|
+
value: BigInt(0),
|
|
1707
|
+
inclusive: true,
|
|
1708
|
+
message: errorUtil.toString(message)
|
|
1709
|
+
});
|
|
1710
|
+
}
|
|
1711
|
+
multipleOf(value, message) {
|
|
1712
|
+
return this._addCheck({
|
|
1713
|
+
kind: "multipleOf",
|
|
1714
|
+
value,
|
|
1715
|
+
message: errorUtil.toString(message)
|
|
1716
|
+
});
|
|
1717
|
+
}
|
|
1718
|
+
get minValue() {
|
|
1719
|
+
let min = null;
|
|
1720
|
+
for (const ch of this._def.checks) if (ch.kind === "min") {
|
|
1721
|
+
if (min === null || ch.value > min) min = ch.value;
|
|
1722
|
+
}
|
|
1723
|
+
return min;
|
|
1724
|
+
}
|
|
1725
|
+
get maxValue() {
|
|
1726
|
+
let max = null;
|
|
1727
|
+
for (const ch of this._def.checks) if (ch.kind === "max") {
|
|
1728
|
+
if (max === null || ch.value < max) max = ch.value;
|
|
1729
|
+
}
|
|
1730
|
+
return max;
|
|
1731
|
+
}
|
|
1732
|
+
};
|
|
1733
|
+
ZodBigInt.create = (params) => {
|
|
1734
|
+
return new ZodBigInt({
|
|
1735
|
+
checks: [],
|
|
1736
|
+
typeName: ZodFirstPartyTypeKind.ZodBigInt,
|
|
1737
|
+
coerce: params?.coerce ?? false,
|
|
1738
|
+
...processCreateParams(params)
|
|
1739
|
+
});
|
|
1740
|
+
};
|
|
1741
|
+
var ZodBoolean = class extends ZodType {
|
|
1742
|
+
_parse(input) {
|
|
1743
|
+
if (this._def.coerce) input.data = Boolean(input.data);
|
|
1744
|
+
const parsedType = this._getType(input);
|
|
1745
|
+
if (parsedType !== ZodParsedType.boolean) {
|
|
1746
|
+
const ctx = this._getOrReturnCtx(input);
|
|
1747
|
+
addIssueToContext(ctx, {
|
|
1748
|
+
code: ZodIssueCode.invalid_type,
|
|
1749
|
+
expected: ZodParsedType.boolean,
|
|
1750
|
+
received: ctx.parsedType
|
|
1751
|
+
});
|
|
1752
|
+
return INVALID;
|
|
1753
|
+
}
|
|
1754
|
+
return OK(input.data);
|
|
1755
|
+
}
|
|
1756
|
+
};
|
|
1757
|
+
ZodBoolean.create = (params) => {
|
|
1758
|
+
return new ZodBoolean({
|
|
1759
|
+
typeName: ZodFirstPartyTypeKind.ZodBoolean,
|
|
1760
|
+
coerce: params?.coerce || false,
|
|
1761
|
+
...processCreateParams(params)
|
|
1762
|
+
});
|
|
1763
|
+
};
|
|
1764
|
+
var ZodDate = class ZodDate extends ZodType {
|
|
1765
|
+
_parse(input) {
|
|
1766
|
+
if (this._def.coerce) input.data = new Date(input.data);
|
|
1767
|
+
const parsedType = this._getType(input);
|
|
1768
|
+
if (parsedType !== ZodParsedType.date) {
|
|
1769
|
+
const ctx$1 = this._getOrReturnCtx(input);
|
|
1770
|
+
addIssueToContext(ctx$1, {
|
|
1771
|
+
code: ZodIssueCode.invalid_type,
|
|
1772
|
+
expected: ZodParsedType.date,
|
|
1773
|
+
received: ctx$1.parsedType
|
|
1774
|
+
});
|
|
1775
|
+
return INVALID;
|
|
1776
|
+
}
|
|
1777
|
+
if (Number.isNaN(input.data.getTime())) {
|
|
1778
|
+
const ctx$1 = this._getOrReturnCtx(input);
|
|
1779
|
+
addIssueToContext(ctx$1, { code: ZodIssueCode.invalid_date });
|
|
1780
|
+
return INVALID;
|
|
1781
|
+
}
|
|
1782
|
+
const status = new ParseStatus();
|
|
1783
|
+
let ctx = void 0;
|
|
1784
|
+
for (const check of this._def.checks) if (check.kind === "min") {
|
|
1785
|
+
if (input.data.getTime() < check.value) {
|
|
1786
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1787
|
+
addIssueToContext(ctx, {
|
|
1788
|
+
code: ZodIssueCode.too_small,
|
|
1789
|
+
message: check.message,
|
|
1790
|
+
inclusive: true,
|
|
1791
|
+
exact: false,
|
|
1792
|
+
minimum: check.value,
|
|
1793
|
+
type: "date"
|
|
1794
|
+
});
|
|
1795
|
+
status.dirty();
|
|
1796
|
+
}
|
|
1797
|
+
} else if (check.kind === "max") {
|
|
1798
|
+
if (input.data.getTime() > check.value) {
|
|
1799
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1800
|
+
addIssueToContext(ctx, {
|
|
1801
|
+
code: ZodIssueCode.too_big,
|
|
1802
|
+
message: check.message,
|
|
1803
|
+
inclusive: true,
|
|
1804
|
+
exact: false,
|
|
1805
|
+
maximum: check.value,
|
|
1806
|
+
type: "date"
|
|
1807
|
+
});
|
|
1808
|
+
status.dirty();
|
|
1809
|
+
}
|
|
1810
|
+
} else util.assertNever(check);
|
|
1811
|
+
return {
|
|
1812
|
+
status: status.value,
|
|
1813
|
+
value: new Date(input.data.getTime())
|
|
1814
|
+
};
|
|
1815
|
+
}
|
|
1816
|
+
_addCheck(check) {
|
|
1817
|
+
return new ZodDate({
|
|
1818
|
+
...this._def,
|
|
1819
|
+
checks: [...this._def.checks, check]
|
|
1820
|
+
});
|
|
1821
|
+
}
|
|
1822
|
+
min(minDate, message) {
|
|
1823
|
+
return this._addCheck({
|
|
1824
|
+
kind: "min",
|
|
1825
|
+
value: minDate.getTime(),
|
|
1826
|
+
message: errorUtil.toString(message)
|
|
1827
|
+
});
|
|
1828
|
+
}
|
|
1829
|
+
max(maxDate, message) {
|
|
1830
|
+
return this._addCheck({
|
|
1831
|
+
kind: "max",
|
|
1832
|
+
value: maxDate.getTime(),
|
|
1833
|
+
message: errorUtil.toString(message)
|
|
1834
|
+
});
|
|
1835
|
+
}
|
|
1836
|
+
get minDate() {
|
|
1837
|
+
let min = null;
|
|
1838
|
+
for (const ch of this._def.checks) if (ch.kind === "min") {
|
|
1839
|
+
if (min === null || ch.value > min) min = ch.value;
|
|
1840
|
+
}
|
|
1841
|
+
return min != null ? new Date(min) : null;
|
|
1842
|
+
}
|
|
1843
|
+
get maxDate() {
|
|
1844
|
+
let max = null;
|
|
1845
|
+
for (const ch of this._def.checks) if (ch.kind === "max") {
|
|
1846
|
+
if (max === null || ch.value < max) max = ch.value;
|
|
1847
|
+
}
|
|
1848
|
+
return max != null ? new Date(max) : null;
|
|
1849
|
+
}
|
|
1850
|
+
};
|
|
1851
|
+
ZodDate.create = (params) => {
|
|
1852
|
+
return new ZodDate({
|
|
1853
|
+
checks: [],
|
|
1854
|
+
coerce: params?.coerce || false,
|
|
1855
|
+
typeName: ZodFirstPartyTypeKind.ZodDate,
|
|
1856
|
+
...processCreateParams(params)
|
|
1857
|
+
});
|
|
1858
|
+
};
|
|
1859
|
+
var ZodSymbol = class extends ZodType {
|
|
1860
|
+
_parse(input) {
|
|
1861
|
+
const parsedType = this._getType(input);
|
|
1862
|
+
if (parsedType !== ZodParsedType.symbol) {
|
|
1863
|
+
const ctx = this._getOrReturnCtx(input);
|
|
1864
|
+
addIssueToContext(ctx, {
|
|
1865
|
+
code: ZodIssueCode.invalid_type,
|
|
1866
|
+
expected: ZodParsedType.symbol,
|
|
1867
|
+
received: ctx.parsedType
|
|
1868
|
+
});
|
|
1869
|
+
return INVALID;
|
|
1870
|
+
}
|
|
1871
|
+
return OK(input.data);
|
|
1872
|
+
}
|
|
1873
|
+
};
|
|
1874
|
+
ZodSymbol.create = (params) => {
|
|
1875
|
+
return new ZodSymbol({
|
|
1876
|
+
typeName: ZodFirstPartyTypeKind.ZodSymbol,
|
|
1877
|
+
...processCreateParams(params)
|
|
1878
|
+
});
|
|
1879
|
+
};
|
|
1880
|
+
var ZodUndefined = class extends ZodType {
|
|
1881
|
+
_parse(input) {
|
|
1882
|
+
const parsedType = this._getType(input);
|
|
1883
|
+
if (parsedType !== ZodParsedType.undefined) {
|
|
1884
|
+
const ctx = this._getOrReturnCtx(input);
|
|
1885
|
+
addIssueToContext(ctx, {
|
|
1886
|
+
code: ZodIssueCode.invalid_type,
|
|
1887
|
+
expected: ZodParsedType.undefined,
|
|
1888
|
+
received: ctx.parsedType
|
|
1889
|
+
});
|
|
1890
|
+
return INVALID;
|
|
1891
|
+
}
|
|
1892
|
+
return OK(input.data);
|
|
1893
|
+
}
|
|
1894
|
+
};
|
|
1895
|
+
ZodUndefined.create = (params) => {
|
|
1896
|
+
return new ZodUndefined({
|
|
1897
|
+
typeName: ZodFirstPartyTypeKind.ZodUndefined,
|
|
1898
|
+
...processCreateParams(params)
|
|
1899
|
+
});
|
|
1900
|
+
};
|
|
1901
|
+
var ZodNull = class extends ZodType {
|
|
1902
|
+
_parse(input) {
|
|
1903
|
+
const parsedType = this._getType(input);
|
|
1904
|
+
if (parsedType !== ZodParsedType.null) {
|
|
1905
|
+
const ctx = this._getOrReturnCtx(input);
|
|
1906
|
+
addIssueToContext(ctx, {
|
|
1907
|
+
code: ZodIssueCode.invalid_type,
|
|
1908
|
+
expected: ZodParsedType.null,
|
|
1909
|
+
received: ctx.parsedType
|
|
1910
|
+
});
|
|
1911
|
+
return INVALID;
|
|
1912
|
+
}
|
|
1913
|
+
return OK(input.data);
|
|
1914
|
+
}
|
|
1915
|
+
};
|
|
1916
|
+
ZodNull.create = (params) => {
|
|
1917
|
+
return new ZodNull({
|
|
1918
|
+
typeName: ZodFirstPartyTypeKind.ZodNull,
|
|
1919
|
+
...processCreateParams(params)
|
|
1920
|
+
});
|
|
1921
|
+
};
|
|
1922
|
+
var ZodAny = class extends ZodType {
|
|
1923
|
+
constructor() {
|
|
1924
|
+
super(...arguments);
|
|
1925
|
+
this._any = true;
|
|
1926
|
+
}
|
|
1927
|
+
_parse(input) {
|
|
1928
|
+
return OK(input.data);
|
|
1929
|
+
}
|
|
1930
|
+
};
|
|
1931
|
+
ZodAny.create = (params) => {
|
|
1932
|
+
return new ZodAny({
|
|
1933
|
+
typeName: ZodFirstPartyTypeKind.ZodAny,
|
|
1934
|
+
...processCreateParams(params)
|
|
1935
|
+
});
|
|
1936
|
+
};
|
|
1937
|
+
var ZodUnknown = class extends ZodType {
|
|
1938
|
+
constructor() {
|
|
1939
|
+
super(...arguments);
|
|
1940
|
+
this._unknown = true;
|
|
1941
|
+
}
|
|
1942
|
+
_parse(input) {
|
|
1943
|
+
return OK(input.data);
|
|
1944
|
+
}
|
|
1945
|
+
};
|
|
1946
|
+
ZodUnknown.create = (params) => {
|
|
1947
|
+
return new ZodUnknown({
|
|
1948
|
+
typeName: ZodFirstPartyTypeKind.ZodUnknown,
|
|
1949
|
+
...processCreateParams(params)
|
|
1950
|
+
});
|
|
1951
|
+
};
|
|
1952
|
+
var ZodNever = class extends ZodType {
|
|
1953
|
+
_parse(input) {
|
|
1954
|
+
const ctx = this._getOrReturnCtx(input);
|
|
1955
|
+
addIssueToContext(ctx, {
|
|
1956
|
+
code: ZodIssueCode.invalid_type,
|
|
1957
|
+
expected: ZodParsedType.never,
|
|
1958
|
+
received: ctx.parsedType
|
|
1959
|
+
});
|
|
1960
|
+
return INVALID;
|
|
1961
|
+
}
|
|
1962
|
+
};
|
|
1963
|
+
ZodNever.create = (params) => {
|
|
1964
|
+
return new ZodNever({
|
|
1965
|
+
typeName: ZodFirstPartyTypeKind.ZodNever,
|
|
1966
|
+
...processCreateParams(params)
|
|
1967
|
+
});
|
|
1968
|
+
};
|
|
1969
|
+
var ZodVoid = class extends ZodType {
|
|
1970
|
+
_parse(input) {
|
|
1971
|
+
const parsedType = this._getType(input);
|
|
1972
|
+
if (parsedType !== ZodParsedType.undefined) {
|
|
1973
|
+
const ctx = this._getOrReturnCtx(input);
|
|
1974
|
+
addIssueToContext(ctx, {
|
|
1975
|
+
code: ZodIssueCode.invalid_type,
|
|
1976
|
+
expected: ZodParsedType.void,
|
|
1977
|
+
received: ctx.parsedType
|
|
1978
|
+
});
|
|
1979
|
+
return INVALID;
|
|
1980
|
+
}
|
|
1981
|
+
return OK(input.data);
|
|
1982
|
+
}
|
|
1983
|
+
};
|
|
1984
|
+
ZodVoid.create = (params) => {
|
|
1985
|
+
return new ZodVoid({
|
|
1986
|
+
typeName: ZodFirstPartyTypeKind.ZodVoid,
|
|
1987
|
+
...processCreateParams(params)
|
|
1988
|
+
});
|
|
1989
|
+
};
|
|
1990
|
+
var ZodArray = class ZodArray extends ZodType {
|
|
1991
|
+
_parse(input) {
|
|
1992
|
+
const { ctx, status } = this._processInputParams(input);
|
|
1993
|
+
const def = this._def;
|
|
1994
|
+
if (ctx.parsedType !== ZodParsedType.array) {
|
|
1995
|
+
addIssueToContext(ctx, {
|
|
1996
|
+
code: ZodIssueCode.invalid_type,
|
|
1997
|
+
expected: ZodParsedType.array,
|
|
1998
|
+
received: ctx.parsedType
|
|
1999
|
+
});
|
|
2000
|
+
return INVALID;
|
|
2001
|
+
}
|
|
2002
|
+
if (def.exactLength !== null) {
|
|
2003
|
+
const tooBig = ctx.data.length > def.exactLength.value;
|
|
2004
|
+
const tooSmall = ctx.data.length < def.exactLength.value;
|
|
2005
|
+
if (tooBig || tooSmall) {
|
|
2006
|
+
addIssueToContext(ctx, {
|
|
2007
|
+
code: tooBig ? ZodIssueCode.too_big : ZodIssueCode.too_small,
|
|
2008
|
+
minimum: tooSmall ? def.exactLength.value : void 0,
|
|
2009
|
+
maximum: tooBig ? def.exactLength.value : void 0,
|
|
2010
|
+
type: "array",
|
|
2011
|
+
inclusive: true,
|
|
2012
|
+
exact: true,
|
|
2013
|
+
message: def.exactLength.message
|
|
2014
|
+
});
|
|
2015
|
+
status.dirty();
|
|
2016
|
+
}
|
|
2017
|
+
}
|
|
2018
|
+
if (def.minLength !== null) {
|
|
2019
|
+
if (ctx.data.length < def.minLength.value) {
|
|
2020
|
+
addIssueToContext(ctx, {
|
|
2021
|
+
code: ZodIssueCode.too_small,
|
|
2022
|
+
minimum: def.minLength.value,
|
|
2023
|
+
type: "array",
|
|
2024
|
+
inclusive: true,
|
|
2025
|
+
exact: false,
|
|
2026
|
+
message: def.minLength.message
|
|
2027
|
+
});
|
|
2028
|
+
status.dirty();
|
|
2029
|
+
}
|
|
2030
|
+
}
|
|
2031
|
+
if (def.maxLength !== null) {
|
|
2032
|
+
if (ctx.data.length > def.maxLength.value) {
|
|
2033
|
+
addIssueToContext(ctx, {
|
|
2034
|
+
code: ZodIssueCode.too_big,
|
|
2035
|
+
maximum: def.maxLength.value,
|
|
2036
|
+
type: "array",
|
|
2037
|
+
inclusive: true,
|
|
2038
|
+
exact: false,
|
|
2039
|
+
message: def.maxLength.message
|
|
2040
|
+
});
|
|
2041
|
+
status.dirty();
|
|
2042
|
+
}
|
|
2043
|
+
}
|
|
2044
|
+
if (ctx.common.async) return Promise.all([...ctx.data].map((item, i) => {
|
|
2045
|
+
return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i));
|
|
2046
|
+
})).then((result$1) => {
|
|
2047
|
+
return ParseStatus.mergeArray(status, result$1);
|
|
2048
|
+
});
|
|
2049
|
+
const result = [...ctx.data].map((item, i) => {
|
|
2050
|
+
return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i));
|
|
2051
|
+
});
|
|
2052
|
+
return ParseStatus.mergeArray(status, result);
|
|
2053
|
+
}
|
|
2054
|
+
get element() {
|
|
2055
|
+
return this._def.type;
|
|
2056
|
+
}
|
|
2057
|
+
min(minLength, message) {
|
|
2058
|
+
return new ZodArray({
|
|
2059
|
+
...this._def,
|
|
2060
|
+
minLength: {
|
|
2061
|
+
value: minLength,
|
|
2062
|
+
message: errorUtil.toString(message)
|
|
2063
|
+
}
|
|
2064
|
+
});
|
|
2065
|
+
}
|
|
2066
|
+
max(maxLength, message) {
|
|
2067
|
+
return new ZodArray({
|
|
2068
|
+
...this._def,
|
|
2069
|
+
maxLength: {
|
|
2070
|
+
value: maxLength,
|
|
2071
|
+
message: errorUtil.toString(message)
|
|
2072
|
+
}
|
|
2073
|
+
});
|
|
2074
|
+
}
|
|
2075
|
+
length(len, message) {
|
|
2076
|
+
return new ZodArray({
|
|
2077
|
+
...this._def,
|
|
2078
|
+
exactLength: {
|
|
2079
|
+
value: len,
|
|
2080
|
+
message: errorUtil.toString(message)
|
|
2081
|
+
}
|
|
2082
|
+
});
|
|
2083
|
+
}
|
|
2084
|
+
nonempty(message) {
|
|
2085
|
+
return this.min(1, message);
|
|
2086
|
+
}
|
|
2087
|
+
};
|
|
2088
|
+
ZodArray.create = (schema, params) => {
|
|
2089
|
+
return new ZodArray({
|
|
2090
|
+
type: schema,
|
|
2091
|
+
minLength: null,
|
|
2092
|
+
maxLength: null,
|
|
2093
|
+
exactLength: null,
|
|
2094
|
+
typeName: ZodFirstPartyTypeKind.ZodArray,
|
|
2095
|
+
...processCreateParams(params)
|
|
2096
|
+
});
|
|
2097
|
+
};
|
|
2098
|
+
function deepPartialify(schema) {
|
|
2099
|
+
if (schema instanceof ZodObject) {
|
|
2100
|
+
const newShape = {};
|
|
2101
|
+
for (const key in schema.shape) {
|
|
2102
|
+
const fieldSchema = schema.shape[key];
|
|
2103
|
+
newShape[key] = ZodOptional.create(deepPartialify(fieldSchema));
|
|
2104
|
+
}
|
|
2105
|
+
return new ZodObject({
|
|
2106
|
+
...schema._def,
|
|
2107
|
+
shape: () => newShape
|
|
2108
|
+
});
|
|
2109
|
+
} else if (schema instanceof ZodArray) return new ZodArray({
|
|
2110
|
+
...schema._def,
|
|
2111
|
+
type: deepPartialify(schema.element)
|
|
2112
|
+
});
|
|
2113
|
+
else if (schema instanceof ZodOptional) return ZodOptional.create(deepPartialify(schema.unwrap()));
|
|
2114
|
+
else if (schema instanceof ZodNullable) return ZodNullable.create(deepPartialify(schema.unwrap()));
|
|
2115
|
+
else if (schema instanceof ZodTuple) return ZodTuple.create(schema.items.map((item) => deepPartialify(item)));
|
|
2116
|
+
else return schema;
|
|
2117
|
+
}
|
|
2118
|
+
var ZodObject = class ZodObject extends ZodType {
|
|
2119
|
+
constructor() {
|
|
2120
|
+
super(...arguments);
|
|
2121
|
+
this._cached = null;
|
|
2122
|
+
/**
|
|
2123
|
+
* @deprecated In most cases, this is no longer needed - unknown properties are now silently stripped.
|
|
2124
|
+
* If you want to pass through unknown properties, use `.passthrough()` instead.
|
|
2125
|
+
*/
|
|
2126
|
+
this.nonstrict = this.passthrough;
|
|
2127
|
+
/**
|
|
2128
|
+
* @deprecated Use `.extend` instead
|
|
2129
|
+
* */
|
|
2130
|
+
this.augment = this.extend;
|
|
2131
|
+
}
|
|
2132
|
+
_getCached() {
|
|
2133
|
+
if (this._cached !== null) return this._cached;
|
|
2134
|
+
const shape = this._def.shape();
|
|
2135
|
+
const keys = util.objectKeys(shape);
|
|
2136
|
+
this._cached = {
|
|
2137
|
+
shape,
|
|
2138
|
+
keys
|
|
2139
|
+
};
|
|
2140
|
+
return this._cached;
|
|
2141
|
+
}
|
|
2142
|
+
_parse(input) {
|
|
2143
|
+
const parsedType = this._getType(input);
|
|
2144
|
+
if (parsedType !== ZodParsedType.object) {
|
|
2145
|
+
const ctx$1 = this._getOrReturnCtx(input);
|
|
2146
|
+
addIssueToContext(ctx$1, {
|
|
2147
|
+
code: ZodIssueCode.invalid_type,
|
|
2148
|
+
expected: ZodParsedType.object,
|
|
2149
|
+
received: ctx$1.parsedType
|
|
2150
|
+
});
|
|
2151
|
+
return INVALID;
|
|
2152
|
+
}
|
|
2153
|
+
const { status, ctx } = this._processInputParams(input);
|
|
2154
|
+
const { shape, keys: shapeKeys } = this._getCached();
|
|
2155
|
+
const extraKeys = [];
|
|
2156
|
+
if (!(this._def.catchall instanceof ZodNever && this._def.unknownKeys === "strip")) {
|
|
2157
|
+
for (const key in ctx.data) if (!shapeKeys.includes(key)) extraKeys.push(key);
|
|
2158
|
+
}
|
|
2159
|
+
const pairs = [];
|
|
2160
|
+
for (const key of shapeKeys) {
|
|
2161
|
+
const keyValidator = shape[key];
|
|
2162
|
+
const value = ctx.data[key];
|
|
2163
|
+
pairs.push({
|
|
2164
|
+
key: {
|
|
2165
|
+
status: "valid",
|
|
2166
|
+
value: key
|
|
2167
|
+
},
|
|
2168
|
+
value: keyValidator._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
|
|
2169
|
+
alwaysSet: key in ctx.data
|
|
2170
|
+
});
|
|
2171
|
+
}
|
|
2172
|
+
if (this._def.catchall instanceof ZodNever) {
|
|
2173
|
+
const unknownKeys = this._def.unknownKeys;
|
|
2174
|
+
if (unknownKeys === "passthrough") for (const key of extraKeys) pairs.push({
|
|
2175
|
+
key: {
|
|
2176
|
+
status: "valid",
|
|
2177
|
+
value: key
|
|
2178
|
+
},
|
|
2179
|
+
value: {
|
|
2180
|
+
status: "valid",
|
|
2181
|
+
value: ctx.data[key]
|
|
2182
|
+
}
|
|
2183
|
+
});
|
|
2184
|
+
else if (unknownKeys === "strict") {
|
|
2185
|
+
if (extraKeys.length > 0) {
|
|
2186
|
+
addIssueToContext(ctx, {
|
|
2187
|
+
code: ZodIssueCode.unrecognized_keys,
|
|
2188
|
+
keys: extraKeys
|
|
2189
|
+
});
|
|
2190
|
+
status.dirty();
|
|
2191
|
+
}
|
|
2192
|
+
} else if (unknownKeys === "strip") {} else throw new Error(`Internal ZodObject error: invalid unknownKeys value.`);
|
|
2193
|
+
} else {
|
|
2194
|
+
const catchall = this._def.catchall;
|
|
2195
|
+
for (const key of extraKeys) {
|
|
2196
|
+
const value = ctx.data[key];
|
|
2197
|
+
pairs.push({
|
|
2198
|
+
key: {
|
|
2199
|
+
status: "valid",
|
|
2200
|
+
value: key
|
|
2201
|
+
},
|
|
2202
|
+
value: catchall._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
|
|
2203
|
+
alwaysSet: key in ctx.data
|
|
2204
|
+
});
|
|
2205
|
+
}
|
|
2206
|
+
}
|
|
2207
|
+
if (ctx.common.async) return Promise.resolve().then(async () => {
|
|
2208
|
+
const syncPairs = [];
|
|
2209
|
+
for (const pair of pairs) {
|
|
2210
|
+
const key = await pair.key;
|
|
2211
|
+
const value = await pair.value;
|
|
2212
|
+
syncPairs.push({
|
|
2213
|
+
key,
|
|
2214
|
+
value,
|
|
2215
|
+
alwaysSet: pair.alwaysSet
|
|
2216
|
+
});
|
|
2217
|
+
}
|
|
2218
|
+
return syncPairs;
|
|
2219
|
+
}).then((syncPairs) => {
|
|
2220
|
+
return ParseStatus.mergeObjectSync(status, syncPairs);
|
|
2221
|
+
});
|
|
2222
|
+
else return ParseStatus.mergeObjectSync(status, pairs);
|
|
2223
|
+
}
|
|
2224
|
+
get shape() {
|
|
2225
|
+
return this._def.shape();
|
|
2226
|
+
}
|
|
2227
|
+
strict(message) {
|
|
2228
|
+
errorUtil.errToObj;
|
|
2229
|
+
return new ZodObject({
|
|
2230
|
+
...this._def,
|
|
2231
|
+
unknownKeys: "strict",
|
|
2232
|
+
...message !== void 0 ? { errorMap: (issue, ctx) => {
|
|
2233
|
+
const defaultError = this._def.errorMap?.(issue, ctx).message ?? ctx.defaultError;
|
|
2234
|
+
if (issue.code === "unrecognized_keys") return { message: errorUtil.errToObj(message).message ?? defaultError };
|
|
2235
|
+
return { message: defaultError };
|
|
2236
|
+
} } : {}
|
|
2237
|
+
});
|
|
2238
|
+
}
|
|
2239
|
+
strip() {
|
|
2240
|
+
return new ZodObject({
|
|
2241
|
+
...this._def,
|
|
2242
|
+
unknownKeys: "strip"
|
|
2243
|
+
});
|
|
2244
|
+
}
|
|
2245
|
+
passthrough() {
|
|
2246
|
+
return new ZodObject({
|
|
2247
|
+
...this._def,
|
|
2248
|
+
unknownKeys: "passthrough"
|
|
2249
|
+
});
|
|
2250
|
+
}
|
|
2251
|
+
extend(augmentation) {
|
|
2252
|
+
return new ZodObject({
|
|
2253
|
+
...this._def,
|
|
2254
|
+
shape: () => ({
|
|
2255
|
+
...this._def.shape(),
|
|
2256
|
+
...augmentation
|
|
2257
|
+
})
|
|
2258
|
+
});
|
|
2259
|
+
}
|
|
2260
|
+
/**
|
|
2261
|
+
* Prior to zod@1.0.12 there was a bug in the
|
|
2262
|
+
* inferred type of merged objects. Please
|
|
2263
|
+
* upgrade if you are experiencing issues.
|
|
2264
|
+
*/
|
|
2265
|
+
merge(merging) {
|
|
2266
|
+
const merged = new ZodObject({
|
|
2267
|
+
unknownKeys: merging._def.unknownKeys,
|
|
2268
|
+
catchall: merging._def.catchall,
|
|
2269
|
+
shape: () => ({
|
|
2270
|
+
...this._def.shape(),
|
|
2271
|
+
...merging._def.shape()
|
|
2272
|
+
}),
|
|
2273
|
+
typeName: ZodFirstPartyTypeKind.ZodObject
|
|
2274
|
+
});
|
|
2275
|
+
return merged;
|
|
2276
|
+
}
|
|
2277
|
+
setKey(key, schema) {
|
|
2278
|
+
return this.augment({ [key]: schema });
|
|
2279
|
+
}
|
|
2280
|
+
catchall(index) {
|
|
2281
|
+
return new ZodObject({
|
|
2282
|
+
...this._def,
|
|
2283
|
+
catchall: index
|
|
2284
|
+
});
|
|
2285
|
+
}
|
|
2286
|
+
pick(mask) {
|
|
2287
|
+
const shape = {};
|
|
2288
|
+
for (const key of util.objectKeys(mask)) if (mask[key] && this.shape[key]) shape[key] = this.shape[key];
|
|
2289
|
+
return new ZodObject({
|
|
2290
|
+
...this._def,
|
|
2291
|
+
shape: () => shape
|
|
2292
|
+
});
|
|
2293
|
+
}
|
|
2294
|
+
omit(mask) {
|
|
2295
|
+
const shape = {};
|
|
2296
|
+
for (const key of util.objectKeys(this.shape)) if (!mask[key]) shape[key] = this.shape[key];
|
|
2297
|
+
return new ZodObject({
|
|
2298
|
+
...this._def,
|
|
2299
|
+
shape: () => shape
|
|
2300
|
+
});
|
|
2301
|
+
}
|
|
2302
|
+
/**
|
|
2303
|
+
* @deprecated
|
|
2304
|
+
*/
|
|
2305
|
+
deepPartial() {
|
|
2306
|
+
return deepPartialify(this);
|
|
2307
|
+
}
|
|
2308
|
+
partial(mask) {
|
|
2309
|
+
const newShape = {};
|
|
2310
|
+
for (const key of util.objectKeys(this.shape)) {
|
|
2311
|
+
const fieldSchema = this.shape[key];
|
|
2312
|
+
if (mask && !mask[key]) newShape[key] = fieldSchema;
|
|
2313
|
+
else newShape[key] = fieldSchema.optional();
|
|
2314
|
+
}
|
|
2315
|
+
return new ZodObject({
|
|
2316
|
+
...this._def,
|
|
2317
|
+
shape: () => newShape
|
|
2318
|
+
});
|
|
2319
|
+
}
|
|
2320
|
+
required(mask) {
|
|
2321
|
+
const newShape = {};
|
|
2322
|
+
for (const key of util.objectKeys(this.shape)) if (mask && !mask[key]) newShape[key] = this.shape[key];
|
|
2323
|
+
else {
|
|
2324
|
+
const fieldSchema = this.shape[key];
|
|
2325
|
+
let newField = fieldSchema;
|
|
2326
|
+
while (newField instanceof ZodOptional) newField = newField._def.innerType;
|
|
2327
|
+
newShape[key] = newField;
|
|
2328
|
+
}
|
|
2329
|
+
return new ZodObject({
|
|
2330
|
+
...this._def,
|
|
2331
|
+
shape: () => newShape
|
|
2332
|
+
});
|
|
2333
|
+
}
|
|
2334
|
+
keyof() {
|
|
2335
|
+
return createZodEnum(util.objectKeys(this.shape));
|
|
2336
|
+
}
|
|
2337
|
+
};
|
|
2338
|
+
ZodObject.create = (shape, params) => {
|
|
2339
|
+
return new ZodObject({
|
|
2340
|
+
shape: () => shape,
|
|
2341
|
+
unknownKeys: "strip",
|
|
2342
|
+
catchall: ZodNever.create(),
|
|
2343
|
+
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
2344
|
+
...processCreateParams(params)
|
|
2345
|
+
});
|
|
2346
|
+
};
|
|
2347
|
+
ZodObject.strictCreate = (shape, params) => {
|
|
2348
|
+
return new ZodObject({
|
|
2349
|
+
shape: () => shape,
|
|
2350
|
+
unknownKeys: "strict",
|
|
2351
|
+
catchall: ZodNever.create(),
|
|
2352
|
+
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
2353
|
+
...processCreateParams(params)
|
|
2354
|
+
});
|
|
2355
|
+
};
|
|
2356
|
+
ZodObject.lazycreate = (shape, params) => {
|
|
2357
|
+
return new ZodObject({
|
|
2358
|
+
shape,
|
|
2359
|
+
unknownKeys: "strip",
|
|
2360
|
+
catchall: ZodNever.create(),
|
|
2361
|
+
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
2362
|
+
...processCreateParams(params)
|
|
2363
|
+
});
|
|
2364
|
+
};
|
|
2365
|
+
var ZodUnion = class extends ZodType {
|
|
2366
|
+
_parse(input) {
|
|
2367
|
+
const { ctx } = this._processInputParams(input);
|
|
2368
|
+
const options = this._def.options;
|
|
2369
|
+
function handleResults(results) {
|
|
2370
|
+
for (const result of results) if (result.result.status === "valid") return result.result;
|
|
2371
|
+
for (const result of results) if (result.result.status === "dirty") {
|
|
2372
|
+
ctx.common.issues.push(...result.ctx.common.issues);
|
|
2373
|
+
return result.result;
|
|
2374
|
+
}
|
|
2375
|
+
const unionErrors = results.map((result) => new ZodError(result.ctx.common.issues));
|
|
2376
|
+
addIssueToContext(ctx, {
|
|
2377
|
+
code: ZodIssueCode.invalid_union,
|
|
2378
|
+
unionErrors
|
|
2379
|
+
});
|
|
2380
|
+
return INVALID;
|
|
2381
|
+
}
|
|
2382
|
+
if (ctx.common.async) return Promise.all(options.map(async (option) => {
|
|
2383
|
+
const childCtx = {
|
|
2384
|
+
...ctx,
|
|
2385
|
+
common: {
|
|
2386
|
+
...ctx.common,
|
|
2387
|
+
issues: []
|
|
2388
|
+
},
|
|
2389
|
+
parent: null
|
|
2390
|
+
};
|
|
2391
|
+
return {
|
|
2392
|
+
result: await option._parseAsync({
|
|
2393
|
+
data: ctx.data,
|
|
2394
|
+
path: ctx.path,
|
|
2395
|
+
parent: childCtx
|
|
2396
|
+
}),
|
|
2397
|
+
ctx: childCtx
|
|
2398
|
+
};
|
|
2399
|
+
})).then(handleResults);
|
|
2400
|
+
else {
|
|
2401
|
+
let dirty = void 0;
|
|
2402
|
+
const issues = [];
|
|
2403
|
+
for (const option of options) {
|
|
2404
|
+
const childCtx = {
|
|
2405
|
+
...ctx,
|
|
2406
|
+
common: {
|
|
2407
|
+
...ctx.common,
|
|
2408
|
+
issues: []
|
|
2409
|
+
},
|
|
2410
|
+
parent: null
|
|
2411
|
+
};
|
|
2412
|
+
const result = option._parseSync({
|
|
2413
|
+
data: ctx.data,
|
|
2414
|
+
path: ctx.path,
|
|
2415
|
+
parent: childCtx
|
|
2416
|
+
});
|
|
2417
|
+
if (result.status === "valid") return result;
|
|
2418
|
+
else if (result.status === "dirty" && !dirty) dirty = {
|
|
2419
|
+
result,
|
|
2420
|
+
ctx: childCtx
|
|
2421
|
+
};
|
|
2422
|
+
if (childCtx.common.issues.length) issues.push(childCtx.common.issues);
|
|
2423
|
+
}
|
|
2424
|
+
if (dirty) {
|
|
2425
|
+
ctx.common.issues.push(...dirty.ctx.common.issues);
|
|
2426
|
+
return dirty.result;
|
|
2427
|
+
}
|
|
2428
|
+
const unionErrors = issues.map((issues$1) => new ZodError(issues$1));
|
|
2429
|
+
addIssueToContext(ctx, {
|
|
2430
|
+
code: ZodIssueCode.invalid_union,
|
|
2431
|
+
unionErrors
|
|
2432
|
+
});
|
|
2433
|
+
return INVALID;
|
|
2434
|
+
}
|
|
2435
|
+
}
|
|
2436
|
+
get options() {
|
|
2437
|
+
return this._def.options;
|
|
2438
|
+
}
|
|
2439
|
+
};
|
|
2440
|
+
ZodUnion.create = (types, params) => {
|
|
2441
|
+
return new ZodUnion({
|
|
2442
|
+
options: types,
|
|
2443
|
+
typeName: ZodFirstPartyTypeKind.ZodUnion,
|
|
2444
|
+
...processCreateParams(params)
|
|
2445
|
+
});
|
|
2446
|
+
};
|
|
2447
|
+
const getDiscriminator = (type) => {
|
|
2448
|
+
if (type instanceof ZodLazy) return getDiscriminator(type.schema);
|
|
2449
|
+
else if (type instanceof ZodEffects) return getDiscriminator(type.innerType());
|
|
2450
|
+
else if (type instanceof ZodLiteral) return [type.value];
|
|
2451
|
+
else if (type instanceof ZodEnum) return type.options;
|
|
2452
|
+
else if (type instanceof ZodNativeEnum) return util.objectValues(type.enum);
|
|
2453
|
+
else if (type instanceof ZodDefault) return getDiscriminator(type._def.innerType);
|
|
2454
|
+
else if (type instanceof ZodUndefined) return [void 0];
|
|
2455
|
+
else if (type instanceof ZodNull) return [null];
|
|
2456
|
+
else if (type instanceof ZodOptional) return [void 0, ...getDiscriminator(type.unwrap())];
|
|
2457
|
+
else if (type instanceof ZodNullable) return [null, ...getDiscriminator(type.unwrap())];
|
|
2458
|
+
else if (type instanceof ZodBranded) return getDiscriminator(type.unwrap());
|
|
2459
|
+
else if (type instanceof ZodReadonly) return getDiscriminator(type.unwrap());
|
|
2460
|
+
else if (type instanceof ZodCatch) return getDiscriminator(type._def.innerType);
|
|
2461
|
+
else return [];
|
|
2462
|
+
};
|
|
2463
|
+
var ZodDiscriminatedUnion = class ZodDiscriminatedUnion extends ZodType {
|
|
2464
|
+
_parse(input) {
|
|
2465
|
+
const { ctx } = this._processInputParams(input);
|
|
2466
|
+
if (ctx.parsedType !== ZodParsedType.object) {
|
|
2467
|
+
addIssueToContext(ctx, {
|
|
2468
|
+
code: ZodIssueCode.invalid_type,
|
|
2469
|
+
expected: ZodParsedType.object,
|
|
2470
|
+
received: ctx.parsedType
|
|
2471
|
+
});
|
|
2472
|
+
return INVALID;
|
|
2473
|
+
}
|
|
2474
|
+
const discriminator = this.discriminator;
|
|
2475
|
+
const discriminatorValue = ctx.data[discriminator];
|
|
2476
|
+
const option = this.optionsMap.get(discriminatorValue);
|
|
2477
|
+
if (!option) {
|
|
2478
|
+
addIssueToContext(ctx, {
|
|
2479
|
+
code: ZodIssueCode.invalid_union_discriminator,
|
|
2480
|
+
options: Array.from(this.optionsMap.keys()),
|
|
2481
|
+
path: [discriminator]
|
|
2482
|
+
});
|
|
2483
|
+
return INVALID;
|
|
2484
|
+
}
|
|
2485
|
+
if (ctx.common.async) return option._parseAsync({
|
|
2486
|
+
data: ctx.data,
|
|
2487
|
+
path: ctx.path,
|
|
2488
|
+
parent: ctx
|
|
2489
|
+
});
|
|
2490
|
+
else return option._parseSync({
|
|
2491
|
+
data: ctx.data,
|
|
2492
|
+
path: ctx.path,
|
|
2493
|
+
parent: ctx
|
|
2494
|
+
});
|
|
2495
|
+
}
|
|
2496
|
+
get discriminator() {
|
|
2497
|
+
return this._def.discriminator;
|
|
2498
|
+
}
|
|
2499
|
+
get options() {
|
|
2500
|
+
return this._def.options;
|
|
2501
|
+
}
|
|
2502
|
+
get optionsMap() {
|
|
2503
|
+
return this._def.optionsMap;
|
|
2504
|
+
}
|
|
2505
|
+
/**
|
|
2506
|
+
* The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
|
|
2507
|
+
* However, it only allows a union of objects, all of which need to share a discriminator property. This property must
|
|
2508
|
+
* have a different value for each object in the union.
|
|
2509
|
+
* @param discriminator the name of the discriminator property
|
|
2510
|
+
* @param types an array of object schemas
|
|
2511
|
+
* @param params
|
|
2512
|
+
*/
|
|
2513
|
+
static create(discriminator, options, params) {
|
|
2514
|
+
const optionsMap = new Map();
|
|
2515
|
+
for (const type of options) {
|
|
2516
|
+
const discriminatorValues = getDiscriminator(type.shape[discriminator]);
|
|
2517
|
+
if (!discriminatorValues.length) throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
|
|
2518
|
+
for (const value of discriminatorValues) {
|
|
2519
|
+
if (optionsMap.has(value)) throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
|
|
2520
|
+
optionsMap.set(value, type);
|
|
2521
|
+
}
|
|
2522
|
+
}
|
|
2523
|
+
return new ZodDiscriminatedUnion({
|
|
2524
|
+
typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
|
|
2525
|
+
discriminator,
|
|
2526
|
+
options,
|
|
2527
|
+
optionsMap,
|
|
2528
|
+
...processCreateParams(params)
|
|
2529
|
+
});
|
|
2530
|
+
}
|
|
2531
|
+
};
|
|
2532
|
+
function mergeValues(a, b) {
|
|
2533
|
+
const aType = getParsedType(a);
|
|
2534
|
+
const bType = getParsedType(b);
|
|
2535
|
+
if (a === b) return {
|
|
2536
|
+
valid: true,
|
|
2537
|
+
data: a
|
|
2538
|
+
};
|
|
2539
|
+
else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
|
|
2540
|
+
const bKeys = util.objectKeys(b);
|
|
2541
|
+
const sharedKeys = util.objectKeys(a).filter((key) => bKeys.indexOf(key) !== -1);
|
|
2542
|
+
const newObj = {
|
|
2543
|
+
...a,
|
|
2544
|
+
...b
|
|
2545
|
+
};
|
|
2546
|
+
for (const key of sharedKeys) {
|
|
2547
|
+
const sharedValue = mergeValues(a[key], b[key]);
|
|
2548
|
+
if (!sharedValue.valid) return { valid: false };
|
|
2549
|
+
newObj[key] = sharedValue.data;
|
|
2550
|
+
}
|
|
2551
|
+
return {
|
|
2552
|
+
valid: true,
|
|
2553
|
+
data: newObj
|
|
2554
|
+
};
|
|
2555
|
+
} else if (aType === ZodParsedType.array && bType === ZodParsedType.array) {
|
|
2556
|
+
if (a.length !== b.length) return { valid: false };
|
|
2557
|
+
const newArray = [];
|
|
2558
|
+
for (let index = 0; index < a.length; index++) {
|
|
2559
|
+
const itemA = a[index];
|
|
2560
|
+
const itemB = b[index];
|
|
2561
|
+
const sharedValue = mergeValues(itemA, itemB);
|
|
2562
|
+
if (!sharedValue.valid) return { valid: false };
|
|
2563
|
+
newArray.push(sharedValue.data);
|
|
2564
|
+
}
|
|
2565
|
+
return {
|
|
2566
|
+
valid: true,
|
|
2567
|
+
data: newArray
|
|
2568
|
+
};
|
|
2569
|
+
} else if (aType === ZodParsedType.date && bType === ZodParsedType.date && +a === +b) return {
|
|
2570
|
+
valid: true,
|
|
2571
|
+
data: a
|
|
2572
|
+
};
|
|
2573
|
+
else return { valid: false };
|
|
2574
|
+
}
|
|
2575
|
+
var ZodIntersection = class extends ZodType {
|
|
2576
|
+
_parse(input) {
|
|
2577
|
+
const { status, ctx } = this._processInputParams(input);
|
|
2578
|
+
const handleParsed = (parsedLeft, parsedRight) => {
|
|
2579
|
+
if (isAborted(parsedLeft) || isAborted(parsedRight)) return INVALID;
|
|
2580
|
+
const merged = mergeValues(parsedLeft.value, parsedRight.value);
|
|
2581
|
+
if (!merged.valid) {
|
|
2582
|
+
addIssueToContext(ctx, { code: ZodIssueCode.invalid_intersection_types });
|
|
2583
|
+
return INVALID;
|
|
2584
|
+
}
|
|
2585
|
+
if (isDirty(parsedLeft) || isDirty(parsedRight)) status.dirty();
|
|
2586
|
+
return {
|
|
2587
|
+
status: status.value,
|
|
2588
|
+
value: merged.data
|
|
2589
|
+
};
|
|
2590
|
+
};
|
|
2591
|
+
if (ctx.common.async) return Promise.all([this._def.left._parseAsync({
|
|
2592
|
+
data: ctx.data,
|
|
2593
|
+
path: ctx.path,
|
|
2594
|
+
parent: ctx
|
|
2595
|
+
}), this._def.right._parseAsync({
|
|
2596
|
+
data: ctx.data,
|
|
2597
|
+
path: ctx.path,
|
|
2598
|
+
parent: ctx
|
|
2599
|
+
})]).then(([left, right]) => handleParsed(left, right));
|
|
2600
|
+
else return handleParsed(this._def.left._parseSync({
|
|
2601
|
+
data: ctx.data,
|
|
2602
|
+
path: ctx.path,
|
|
2603
|
+
parent: ctx
|
|
2604
|
+
}), this._def.right._parseSync({
|
|
2605
|
+
data: ctx.data,
|
|
2606
|
+
path: ctx.path,
|
|
2607
|
+
parent: ctx
|
|
2608
|
+
}));
|
|
2609
|
+
}
|
|
2610
|
+
};
|
|
2611
|
+
ZodIntersection.create = (left, right, params) => {
|
|
2612
|
+
return new ZodIntersection({
|
|
2613
|
+
left,
|
|
2614
|
+
right,
|
|
2615
|
+
typeName: ZodFirstPartyTypeKind.ZodIntersection,
|
|
2616
|
+
...processCreateParams(params)
|
|
2617
|
+
});
|
|
2618
|
+
};
|
|
2619
|
+
var ZodTuple = class ZodTuple extends ZodType {
|
|
2620
|
+
_parse(input) {
|
|
2621
|
+
const { status, ctx } = this._processInputParams(input);
|
|
2622
|
+
if (ctx.parsedType !== ZodParsedType.array) {
|
|
2623
|
+
addIssueToContext(ctx, {
|
|
2624
|
+
code: ZodIssueCode.invalid_type,
|
|
2625
|
+
expected: ZodParsedType.array,
|
|
2626
|
+
received: ctx.parsedType
|
|
2627
|
+
});
|
|
2628
|
+
return INVALID;
|
|
2629
|
+
}
|
|
2630
|
+
if (ctx.data.length < this._def.items.length) {
|
|
2631
|
+
addIssueToContext(ctx, {
|
|
2632
|
+
code: ZodIssueCode.too_small,
|
|
2633
|
+
minimum: this._def.items.length,
|
|
2634
|
+
inclusive: true,
|
|
2635
|
+
exact: false,
|
|
2636
|
+
type: "array"
|
|
2637
|
+
});
|
|
2638
|
+
return INVALID;
|
|
2639
|
+
}
|
|
2640
|
+
const rest = this._def.rest;
|
|
2641
|
+
if (!rest && ctx.data.length > this._def.items.length) {
|
|
2642
|
+
addIssueToContext(ctx, {
|
|
2643
|
+
code: ZodIssueCode.too_big,
|
|
2644
|
+
maximum: this._def.items.length,
|
|
2645
|
+
inclusive: true,
|
|
2646
|
+
exact: false,
|
|
2647
|
+
type: "array"
|
|
2648
|
+
});
|
|
2649
|
+
status.dirty();
|
|
2650
|
+
}
|
|
2651
|
+
const items = [...ctx.data].map((item, itemIndex) => {
|
|
2652
|
+
const schema = this._def.items[itemIndex] || this._def.rest;
|
|
2653
|
+
if (!schema) return null;
|
|
2654
|
+
return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
|
|
2655
|
+
}).filter((x) => !!x);
|
|
2656
|
+
if (ctx.common.async) return Promise.all(items).then((results) => {
|
|
2657
|
+
return ParseStatus.mergeArray(status, results);
|
|
2658
|
+
});
|
|
2659
|
+
else return ParseStatus.mergeArray(status, items);
|
|
2660
|
+
}
|
|
2661
|
+
get items() {
|
|
2662
|
+
return this._def.items;
|
|
2663
|
+
}
|
|
2664
|
+
rest(rest) {
|
|
2665
|
+
return new ZodTuple({
|
|
2666
|
+
...this._def,
|
|
2667
|
+
rest
|
|
2668
|
+
});
|
|
2669
|
+
}
|
|
2670
|
+
};
|
|
2671
|
+
ZodTuple.create = (schemas, params) => {
|
|
2672
|
+
if (!Array.isArray(schemas)) throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
|
|
2673
|
+
return new ZodTuple({
|
|
2674
|
+
items: schemas,
|
|
2675
|
+
typeName: ZodFirstPartyTypeKind.ZodTuple,
|
|
2676
|
+
rest: null,
|
|
2677
|
+
...processCreateParams(params)
|
|
2678
|
+
});
|
|
2679
|
+
};
|
|
2680
|
+
var ZodRecord = class ZodRecord extends ZodType {
|
|
2681
|
+
get keySchema() {
|
|
2682
|
+
return this._def.keyType;
|
|
2683
|
+
}
|
|
2684
|
+
get valueSchema() {
|
|
2685
|
+
return this._def.valueType;
|
|
2686
|
+
}
|
|
2687
|
+
_parse(input) {
|
|
2688
|
+
const { status, ctx } = this._processInputParams(input);
|
|
2689
|
+
if (ctx.parsedType !== ZodParsedType.object) {
|
|
2690
|
+
addIssueToContext(ctx, {
|
|
2691
|
+
code: ZodIssueCode.invalid_type,
|
|
2692
|
+
expected: ZodParsedType.object,
|
|
2693
|
+
received: ctx.parsedType
|
|
2694
|
+
});
|
|
2695
|
+
return INVALID;
|
|
2696
|
+
}
|
|
2697
|
+
const pairs = [];
|
|
2698
|
+
const keyType = this._def.keyType;
|
|
2699
|
+
const valueType = this._def.valueType;
|
|
2700
|
+
for (const key in ctx.data) pairs.push({
|
|
2701
|
+
key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
|
|
2702
|
+
value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
|
|
2703
|
+
alwaysSet: key in ctx.data
|
|
2704
|
+
});
|
|
2705
|
+
if (ctx.common.async) return ParseStatus.mergeObjectAsync(status, pairs);
|
|
2706
|
+
else return ParseStatus.mergeObjectSync(status, pairs);
|
|
2707
|
+
}
|
|
2708
|
+
get element() {
|
|
2709
|
+
return this._def.valueType;
|
|
2710
|
+
}
|
|
2711
|
+
static create(first, second, third) {
|
|
2712
|
+
if (second instanceof ZodType) return new ZodRecord({
|
|
2713
|
+
keyType: first,
|
|
2714
|
+
valueType: second,
|
|
2715
|
+
typeName: ZodFirstPartyTypeKind.ZodRecord,
|
|
2716
|
+
...processCreateParams(third)
|
|
2717
|
+
});
|
|
2718
|
+
return new ZodRecord({
|
|
2719
|
+
keyType: ZodString.create(),
|
|
2720
|
+
valueType: first,
|
|
2721
|
+
typeName: ZodFirstPartyTypeKind.ZodRecord,
|
|
2722
|
+
...processCreateParams(second)
|
|
2723
|
+
});
|
|
2724
|
+
}
|
|
2725
|
+
};
|
|
2726
|
+
var ZodMap = class extends ZodType {
|
|
2727
|
+
get keySchema() {
|
|
2728
|
+
return this._def.keyType;
|
|
2729
|
+
}
|
|
2730
|
+
get valueSchema() {
|
|
2731
|
+
return this._def.valueType;
|
|
2732
|
+
}
|
|
2733
|
+
_parse(input) {
|
|
2734
|
+
const { status, ctx } = this._processInputParams(input);
|
|
2735
|
+
if (ctx.parsedType !== ZodParsedType.map) {
|
|
2736
|
+
addIssueToContext(ctx, {
|
|
2737
|
+
code: ZodIssueCode.invalid_type,
|
|
2738
|
+
expected: ZodParsedType.map,
|
|
2739
|
+
received: ctx.parsedType
|
|
2740
|
+
});
|
|
2741
|
+
return INVALID;
|
|
2742
|
+
}
|
|
2743
|
+
const keyType = this._def.keyType;
|
|
2744
|
+
const valueType = this._def.valueType;
|
|
2745
|
+
const pairs = [...ctx.data.entries()].map(([key, value], index) => {
|
|
2746
|
+
return {
|
|
2747
|
+
key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index, "key"])),
|
|
2748
|
+
value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [index, "value"]))
|
|
2749
|
+
};
|
|
2750
|
+
});
|
|
2751
|
+
if (ctx.common.async) {
|
|
2752
|
+
const finalMap = new Map();
|
|
2753
|
+
return Promise.resolve().then(async () => {
|
|
2754
|
+
for (const pair of pairs) {
|
|
2755
|
+
const key = await pair.key;
|
|
2756
|
+
const value = await pair.value;
|
|
2757
|
+
if (key.status === "aborted" || value.status === "aborted") return INVALID;
|
|
2758
|
+
if (key.status === "dirty" || value.status === "dirty") status.dirty();
|
|
2759
|
+
finalMap.set(key.value, value.value);
|
|
2760
|
+
}
|
|
2761
|
+
return {
|
|
2762
|
+
status: status.value,
|
|
2763
|
+
value: finalMap
|
|
2764
|
+
};
|
|
2765
|
+
});
|
|
2766
|
+
} else {
|
|
2767
|
+
const finalMap = new Map();
|
|
2768
|
+
for (const pair of pairs) {
|
|
2769
|
+
const key = pair.key;
|
|
2770
|
+
const value = pair.value;
|
|
2771
|
+
if (key.status === "aborted" || value.status === "aborted") return INVALID;
|
|
2772
|
+
if (key.status === "dirty" || value.status === "dirty") status.dirty();
|
|
2773
|
+
finalMap.set(key.value, value.value);
|
|
2774
|
+
}
|
|
2775
|
+
return {
|
|
2776
|
+
status: status.value,
|
|
2777
|
+
value: finalMap
|
|
2778
|
+
};
|
|
2779
|
+
}
|
|
2780
|
+
}
|
|
2781
|
+
};
|
|
2782
|
+
ZodMap.create = (keyType, valueType, params) => {
|
|
2783
|
+
return new ZodMap({
|
|
2784
|
+
valueType,
|
|
2785
|
+
keyType,
|
|
2786
|
+
typeName: ZodFirstPartyTypeKind.ZodMap,
|
|
2787
|
+
...processCreateParams(params)
|
|
2788
|
+
});
|
|
2789
|
+
};
|
|
2790
|
+
var ZodSet = class ZodSet extends ZodType {
|
|
2791
|
+
_parse(input) {
|
|
2792
|
+
const { status, ctx } = this._processInputParams(input);
|
|
2793
|
+
if (ctx.parsedType !== ZodParsedType.set) {
|
|
2794
|
+
addIssueToContext(ctx, {
|
|
2795
|
+
code: ZodIssueCode.invalid_type,
|
|
2796
|
+
expected: ZodParsedType.set,
|
|
2797
|
+
received: ctx.parsedType
|
|
2798
|
+
});
|
|
2799
|
+
return INVALID;
|
|
2800
|
+
}
|
|
2801
|
+
const def = this._def;
|
|
2802
|
+
if (def.minSize !== null) {
|
|
2803
|
+
if (ctx.data.size < def.minSize.value) {
|
|
2804
|
+
addIssueToContext(ctx, {
|
|
2805
|
+
code: ZodIssueCode.too_small,
|
|
2806
|
+
minimum: def.minSize.value,
|
|
2807
|
+
type: "set",
|
|
2808
|
+
inclusive: true,
|
|
2809
|
+
exact: false,
|
|
2810
|
+
message: def.minSize.message
|
|
2811
|
+
});
|
|
2812
|
+
status.dirty();
|
|
2813
|
+
}
|
|
2814
|
+
}
|
|
2815
|
+
if (def.maxSize !== null) {
|
|
2816
|
+
if (ctx.data.size > def.maxSize.value) {
|
|
2817
|
+
addIssueToContext(ctx, {
|
|
2818
|
+
code: ZodIssueCode.too_big,
|
|
2819
|
+
maximum: def.maxSize.value,
|
|
2820
|
+
type: "set",
|
|
2821
|
+
inclusive: true,
|
|
2822
|
+
exact: false,
|
|
2823
|
+
message: def.maxSize.message
|
|
2824
|
+
});
|
|
2825
|
+
status.dirty();
|
|
2826
|
+
}
|
|
2827
|
+
}
|
|
2828
|
+
const valueType = this._def.valueType;
|
|
2829
|
+
function finalizeSet(elements$1) {
|
|
2830
|
+
const parsedSet = new Set();
|
|
2831
|
+
for (const element of elements$1) {
|
|
2832
|
+
if (element.status === "aborted") return INVALID;
|
|
2833
|
+
if (element.status === "dirty") status.dirty();
|
|
2834
|
+
parsedSet.add(element.value);
|
|
2835
|
+
}
|
|
2836
|
+
return {
|
|
2837
|
+
status: status.value,
|
|
2838
|
+
value: parsedSet
|
|
2839
|
+
};
|
|
2840
|
+
}
|
|
2841
|
+
const elements = [...ctx.data.values()].map((item, i) => valueType._parse(new ParseInputLazyPath(ctx, item, ctx.path, i)));
|
|
2842
|
+
if (ctx.common.async) return Promise.all(elements).then((elements$1) => finalizeSet(elements$1));
|
|
2843
|
+
else return finalizeSet(elements);
|
|
2844
|
+
}
|
|
2845
|
+
min(minSize, message) {
|
|
2846
|
+
return new ZodSet({
|
|
2847
|
+
...this._def,
|
|
2848
|
+
minSize: {
|
|
2849
|
+
value: minSize,
|
|
2850
|
+
message: errorUtil.toString(message)
|
|
2851
|
+
}
|
|
2852
|
+
});
|
|
2853
|
+
}
|
|
2854
|
+
max(maxSize, message) {
|
|
2855
|
+
return new ZodSet({
|
|
2856
|
+
...this._def,
|
|
2857
|
+
maxSize: {
|
|
2858
|
+
value: maxSize,
|
|
2859
|
+
message: errorUtil.toString(message)
|
|
2860
|
+
}
|
|
2861
|
+
});
|
|
2862
|
+
}
|
|
2863
|
+
size(size, message) {
|
|
2864
|
+
return this.min(size, message).max(size, message);
|
|
2865
|
+
}
|
|
2866
|
+
nonempty(message) {
|
|
2867
|
+
return this.min(1, message);
|
|
2868
|
+
}
|
|
2869
|
+
};
|
|
2870
|
+
ZodSet.create = (valueType, params) => {
|
|
2871
|
+
return new ZodSet({
|
|
2872
|
+
valueType,
|
|
2873
|
+
minSize: null,
|
|
2874
|
+
maxSize: null,
|
|
2875
|
+
typeName: ZodFirstPartyTypeKind.ZodSet,
|
|
2876
|
+
...processCreateParams(params)
|
|
2877
|
+
});
|
|
2878
|
+
};
|
|
2879
|
+
var ZodFunction = class ZodFunction extends ZodType {
|
|
2880
|
+
constructor() {
|
|
2881
|
+
super(...arguments);
|
|
2882
|
+
this.validate = this.implement;
|
|
2883
|
+
}
|
|
2884
|
+
_parse(input) {
|
|
2885
|
+
const { ctx } = this._processInputParams(input);
|
|
2886
|
+
if (ctx.parsedType !== ZodParsedType.function) {
|
|
2887
|
+
addIssueToContext(ctx, {
|
|
2888
|
+
code: ZodIssueCode.invalid_type,
|
|
2889
|
+
expected: ZodParsedType.function,
|
|
2890
|
+
received: ctx.parsedType
|
|
2891
|
+
});
|
|
2892
|
+
return INVALID;
|
|
2893
|
+
}
|
|
2894
|
+
function makeArgsIssue(args, error) {
|
|
2895
|
+
return makeIssue({
|
|
2896
|
+
data: args,
|
|
2897
|
+
path: ctx.path,
|
|
2898
|
+
errorMaps: [
|
|
2899
|
+
ctx.common.contextualErrorMap,
|
|
2900
|
+
ctx.schemaErrorMap,
|
|
2901
|
+
getErrorMap(),
|
|
2902
|
+
en_default
|
|
2903
|
+
].filter((x) => !!x),
|
|
2904
|
+
issueData: {
|
|
2905
|
+
code: ZodIssueCode.invalid_arguments,
|
|
2906
|
+
argumentsError: error
|
|
2907
|
+
}
|
|
2908
|
+
});
|
|
2909
|
+
}
|
|
2910
|
+
function makeReturnsIssue(returns, error) {
|
|
2911
|
+
return makeIssue({
|
|
2912
|
+
data: returns,
|
|
2913
|
+
path: ctx.path,
|
|
2914
|
+
errorMaps: [
|
|
2915
|
+
ctx.common.contextualErrorMap,
|
|
2916
|
+
ctx.schemaErrorMap,
|
|
2917
|
+
getErrorMap(),
|
|
2918
|
+
en_default
|
|
2919
|
+
].filter((x) => !!x),
|
|
2920
|
+
issueData: {
|
|
2921
|
+
code: ZodIssueCode.invalid_return_type,
|
|
2922
|
+
returnTypeError: error
|
|
2923
|
+
}
|
|
2924
|
+
});
|
|
2925
|
+
}
|
|
2926
|
+
const params = { errorMap: ctx.common.contextualErrorMap };
|
|
2927
|
+
const fn = ctx.data;
|
|
2928
|
+
if (this._def.returns instanceof ZodPromise) {
|
|
2929
|
+
const me = this;
|
|
2930
|
+
return OK(async function(...args) {
|
|
2931
|
+
const error = new ZodError([]);
|
|
2932
|
+
const parsedArgs = await me._def.args.parseAsync(args, params).catch((e) => {
|
|
2933
|
+
error.addIssue(makeArgsIssue(args, e));
|
|
2934
|
+
throw error;
|
|
2935
|
+
});
|
|
2936
|
+
const result = await Reflect.apply(fn, this, parsedArgs);
|
|
2937
|
+
const parsedReturns = await me._def.returns._def.type.parseAsync(result, params).catch((e) => {
|
|
2938
|
+
error.addIssue(makeReturnsIssue(result, e));
|
|
2939
|
+
throw error;
|
|
2940
|
+
});
|
|
2941
|
+
return parsedReturns;
|
|
2942
|
+
});
|
|
2943
|
+
} else {
|
|
2944
|
+
const me = this;
|
|
2945
|
+
return OK(function(...args) {
|
|
2946
|
+
const parsedArgs = me._def.args.safeParse(args, params);
|
|
2947
|
+
if (!parsedArgs.success) throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
|
|
2948
|
+
const result = Reflect.apply(fn, this, parsedArgs.data);
|
|
2949
|
+
const parsedReturns = me._def.returns.safeParse(result, params);
|
|
2950
|
+
if (!parsedReturns.success) throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
|
|
2951
|
+
return parsedReturns.data;
|
|
2952
|
+
});
|
|
2953
|
+
}
|
|
2954
|
+
}
|
|
2955
|
+
parameters() {
|
|
2956
|
+
return this._def.args;
|
|
2957
|
+
}
|
|
2958
|
+
returnType() {
|
|
2959
|
+
return this._def.returns;
|
|
2960
|
+
}
|
|
2961
|
+
args(...items) {
|
|
2962
|
+
return new ZodFunction({
|
|
2963
|
+
...this._def,
|
|
2964
|
+
args: ZodTuple.create(items).rest(ZodUnknown.create())
|
|
2965
|
+
});
|
|
2966
|
+
}
|
|
2967
|
+
returns(returnType) {
|
|
2968
|
+
return new ZodFunction({
|
|
2969
|
+
...this._def,
|
|
2970
|
+
returns: returnType
|
|
2971
|
+
});
|
|
2972
|
+
}
|
|
2973
|
+
implement(func) {
|
|
2974
|
+
const validatedFunc = this.parse(func);
|
|
2975
|
+
return validatedFunc;
|
|
2976
|
+
}
|
|
2977
|
+
strictImplement(func) {
|
|
2978
|
+
const validatedFunc = this.parse(func);
|
|
2979
|
+
return validatedFunc;
|
|
2980
|
+
}
|
|
2981
|
+
static create(args, returns, params) {
|
|
2982
|
+
return new ZodFunction({
|
|
2983
|
+
args: args ? args : ZodTuple.create([]).rest(ZodUnknown.create()),
|
|
2984
|
+
returns: returns || ZodUnknown.create(),
|
|
2985
|
+
typeName: ZodFirstPartyTypeKind.ZodFunction,
|
|
2986
|
+
...processCreateParams(params)
|
|
2987
|
+
});
|
|
2988
|
+
}
|
|
2989
|
+
};
|
|
2990
|
+
var ZodLazy = class extends ZodType {
|
|
2991
|
+
get schema() {
|
|
2992
|
+
return this._def.getter();
|
|
2993
|
+
}
|
|
2994
|
+
_parse(input) {
|
|
2995
|
+
const { ctx } = this._processInputParams(input);
|
|
2996
|
+
const lazySchema = this._def.getter();
|
|
2997
|
+
return lazySchema._parse({
|
|
2998
|
+
data: ctx.data,
|
|
2999
|
+
path: ctx.path,
|
|
3000
|
+
parent: ctx
|
|
3001
|
+
});
|
|
3002
|
+
}
|
|
3003
|
+
};
|
|
3004
|
+
ZodLazy.create = (getter, params) => {
|
|
3005
|
+
return new ZodLazy({
|
|
3006
|
+
getter,
|
|
3007
|
+
typeName: ZodFirstPartyTypeKind.ZodLazy,
|
|
3008
|
+
...processCreateParams(params)
|
|
3009
|
+
});
|
|
3010
|
+
};
|
|
3011
|
+
var ZodLiteral = class extends ZodType {
|
|
3012
|
+
_parse(input) {
|
|
3013
|
+
if (input.data !== this._def.value) {
|
|
3014
|
+
const ctx = this._getOrReturnCtx(input);
|
|
3015
|
+
addIssueToContext(ctx, {
|
|
3016
|
+
received: ctx.data,
|
|
3017
|
+
code: ZodIssueCode.invalid_literal,
|
|
3018
|
+
expected: this._def.value
|
|
3019
|
+
});
|
|
3020
|
+
return INVALID;
|
|
3021
|
+
}
|
|
3022
|
+
return {
|
|
3023
|
+
status: "valid",
|
|
3024
|
+
value: input.data
|
|
3025
|
+
};
|
|
3026
|
+
}
|
|
3027
|
+
get value() {
|
|
3028
|
+
return this._def.value;
|
|
3029
|
+
}
|
|
3030
|
+
};
|
|
3031
|
+
ZodLiteral.create = (value, params) => {
|
|
3032
|
+
return new ZodLiteral({
|
|
3033
|
+
value,
|
|
3034
|
+
typeName: ZodFirstPartyTypeKind.ZodLiteral,
|
|
3035
|
+
...processCreateParams(params)
|
|
3036
|
+
});
|
|
3037
|
+
};
|
|
3038
|
+
function createZodEnum(values, params) {
|
|
3039
|
+
return new ZodEnum({
|
|
3040
|
+
values,
|
|
3041
|
+
typeName: ZodFirstPartyTypeKind.ZodEnum,
|
|
3042
|
+
...processCreateParams(params)
|
|
3043
|
+
});
|
|
3044
|
+
}
|
|
3045
|
+
var ZodEnum = class ZodEnum extends ZodType {
|
|
3046
|
+
_parse(input) {
|
|
3047
|
+
if (typeof input.data !== "string") {
|
|
3048
|
+
const ctx = this._getOrReturnCtx(input);
|
|
3049
|
+
const expectedValues = this._def.values;
|
|
3050
|
+
addIssueToContext(ctx, {
|
|
3051
|
+
expected: util.joinValues(expectedValues),
|
|
3052
|
+
received: ctx.parsedType,
|
|
3053
|
+
code: ZodIssueCode.invalid_type
|
|
3054
|
+
});
|
|
3055
|
+
return INVALID;
|
|
3056
|
+
}
|
|
3057
|
+
if (!this._cache) this._cache = new Set(this._def.values);
|
|
3058
|
+
if (!this._cache.has(input.data)) {
|
|
3059
|
+
const ctx = this._getOrReturnCtx(input);
|
|
3060
|
+
const expectedValues = this._def.values;
|
|
3061
|
+
addIssueToContext(ctx, {
|
|
3062
|
+
received: ctx.data,
|
|
3063
|
+
code: ZodIssueCode.invalid_enum_value,
|
|
3064
|
+
options: expectedValues
|
|
3065
|
+
});
|
|
3066
|
+
return INVALID;
|
|
3067
|
+
}
|
|
3068
|
+
return OK(input.data);
|
|
3069
|
+
}
|
|
3070
|
+
get options() {
|
|
3071
|
+
return this._def.values;
|
|
3072
|
+
}
|
|
3073
|
+
get enum() {
|
|
3074
|
+
const enumValues = {};
|
|
3075
|
+
for (const val of this._def.values) enumValues[val] = val;
|
|
3076
|
+
return enumValues;
|
|
3077
|
+
}
|
|
3078
|
+
get Values() {
|
|
3079
|
+
const enumValues = {};
|
|
3080
|
+
for (const val of this._def.values) enumValues[val] = val;
|
|
3081
|
+
return enumValues;
|
|
3082
|
+
}
|
|
3083
|
+
get Enum() {
|
|
3084
|
+
const enumValues = {};
|
|
3085
|
+
for (const val of this._def.values) enumValues[val] = val;
|
|
3086
|
+
return enumValues;
|
|
3087
|
+
}
|
|
3088
|
+
extract(values, newDef = this._def) {
|
|
3089
|
+
return ZodEnum.create(values, {
|
|
3090
|
+
...this._def,
|
|
3091
|
+
...newDef
|
|
3092
|
+
});
|
|
3093
|
+
}
|
|
3094
|
+
exclude(values, newDef = this._def) {
|
|
3095
|
+
return ZodEnum.create(this.options.filter((opt) => !values.includes(opt)), {
|
|
3096
|
+
...this._def,
|
|
3097
|
+
...newDef
|
|
3098
|
+
});
|
|
3099
|
+
}
|
|
3100
|
+
};
|
|
3101
|
+
ZodEnum.create = createZodEnum;
|
|
3102
|
+
var ZodNativeEnum = class extends ZodType {
|
|
3103
|
+
_parse(input) {
|
|
3104
|
+
const nativeEnumValues = util.getValidEnumValues(this._def.values);
|
|
3105
|
+
const ctx = this._getOrReturnCtx(input);
|
|
3106
|
+
if (ctx.parsedType !== ZodParsedType.string && ctx.parsedType !== ZodParsedType.number) {
|
|
3107
|
+
const expectedValues = util.objectValues(nativeEnumValues);
|
|
3108
|
+
addIssueToContext(ctx, {
|
|
3109
|
+
expected: util.joinValues(expectedValues),
|
|
3110
|
+
received: ctx.parsedType,
|
|
3111
|
+
code: ZodIssueCode.invalid_type
|
|
3112
|
+
});
|
|
3113
|
+
return INVALID;
|
|
3114
|
+
}
|
|
3115
|
+
if (!this._cache) this._cache = new Set(util.getValidEnumValues(this._def.values));
|
|
3116
|
+
if (!this._cache.has(input.data)) {
|
|
3117
|
+
const expectedValues = util.objectValues(nativeEnumValues);
|
|
3118
|
+
addIssueToContext(ctx, {
|
|
3119
|
+
received: ctx.data,
|
|
3120
|
+
code: ZodIssueCode.invalid_enum_value,
|
|
3121
|
+
options: expectedValues
|
|
3122
|
+
});
|
|
3123
|
+
return INVALID;
|
|
3124
|
+
}
|
|
3125
|
+
return OK(input.data);
|
|
3126
|
+
}
|
|
3127
|
+
get enum() {
|
|
3128
|
+
return this._def.values;
|
|
3129
|
+
}
|
|
3130
|
+
};
|
|
3131
|
+
ZodNativeEnum.create = (values, params) => {
|
|
3132
|
+
return new ZodNativeEnum({
|
|
3133
|
+
values,
|
|
3134
|
+
typeName: ZodFirstPartyTypeKind.ZodNativeEnum,
|
|
3135
|
+
...processCreateParams(params)
|
|
3136
|
+
});
|
|
3137
|
+
};
|
|
3138
|
+
var ZodPromise = class extends ZodType {
|
|
3139
|
+
unwrap() {
|
|
3140
|
+
return this._def.type;
|
|
3141
|
+
}
|
|
3142
|
+
_parse(input) {
|
|
3143
|
+
const { ctx } = this._processInputParams(input);
|
|
3144
|
+
if (ctx.parsedType !== ZodParsedType.promise && ctx.common.async === false) {
|
|
3145
|
+
addIssueToContext(ctx, {
|
|
3146
|
+
code: ZodIssueCode.invalid_type,
|
|
3147
|
+
expected: ZodParsedType.promise,
|
|
3148
|
+
received: ctx.parsedType
|
|
3149
|
+
});
|
|
3150
|
+
return INVALID;
|
|
3151
|
+
}
|
|
3152
|
+
const promisified = ctx.parsedType === ZodParsedType.promise ? ctx.data : Promise.resolve(ctx.data);
|
|
3153
|
+
return OK(promisified.then((data) => {
|
|
3154
|
+
return this._def.type.parseAsync(data, {
|
|
3155
|
+
path: ctx.path,
|
|
3156
|
+
errorMap: ctx.common.contextualErrorMap
|
|
3157
|
+
});
|
|
3158
|
+
}));
|
|
3159
|
+
}
|
|
3160
|
+
};
|
|
3161
|
+
ZodPromise.create = (schema, params) => {
|
|
3162
|
+
return new ZodPromise({
|
|
3163
|
+
type: schema,
|
|
3164
|
+
typeName: ZodFirstPartyTypeKind.ZodPromise,
|
|
3165
|
+
...processCreateParams(params)
|
|
3166
|
+
});
|
|
3167
|
+
};
|
|
3168
|
+
var ZodEffects = class extends ZodType {
|
|
3169
|
+
innerType() {
|
|
3170
|
+
return this._def.schema;
|
|
3171
|
+
}
|
|
3172
|
+
sourceType() {
|
|
3173
|
+
return this._def.schema._def.typeName === ZodFirstPartyTypeKind.ZodEffects ? this._def.schema.sourceType() : this._def.schema;
|
|
3174
|
+
}
|
|
3175
|
+
_parse(input) {
|
|
3176
|
+
const { status, ctx } = this._processInputParams(input);
|
|
3177
|
+
const effect = this._def.effect || null;
|
|
3178
|
+
const checkCtx = {
|
|
3179
|
+
addIssue: (arg) => {
|
|
3180
|
+
addIssueToContext(ctx, arg);
|
|
3181
|
+
if (arg.fatal) status.abort();
|
|
3182
|
+
else status.dirty();
|
|
3183
|
+
},
|
|
3184
|
+
get path() {
|
|
3185
|
+
return ctx.path;
|
|
3186
|
+
}
|
|
3187
|
+
};
|
|
3188
|
+
checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
|
|
3189
|
+
if (effect.type === "preprocess") {
|
|
3190
|
+
const processed = effect.transform(ctx.data, checkCtx);
|
|
3191
|
+
if (ctx.common.async) return Promise.resolve(processed).then(async (processed$1) => {
|
|
3192
|
+
if (status.value === "aborted") return INVALID;
|
|
3193
|
+
const result = await this._def.schema._parseAsync({
|
|
3194
|
+
data: processed$1,
|
|
3195
|
+
path: ctx.path,
|
|
3196
|
+
parent: ctx
|
|
3197
|
+
});
|
|
3198
|
+
if (result.status === "aborted") return INVALID;
|
|
3199
|
+
if (result.status === "dirty") return DIRTY(result.value);
|
|
3200
|
+
if (status.value === "dirty") return DIRTY(result.value);
|
|
3201
|
+
return result;
|
|
3202
|
+
});
|
|
3203
|
+
else {
|
|
3204
|
+
if (status.value === "aborted") return INVALID;
|
|
3205
|
+
const result = this._def.schema._parseSync({
|
|
3206
|
+
data: processed,
|
|
3207
|
+
path: ctx.path,
|
|
3208
|
+
parent: ctx
|
|
3209
|
+
});
|
|
3210
|
+
if (result.status === "aborted") return INVALID;
|
|
3211
|
+
if (result.status === "dirty") return DIRTY(result.value);
|
|
3212
|
+
if (status.value === "dirty") return DIRTY(result.value);
|
|
3213
|
+
return result;
|
|
3214
|
+
}
|
|
3215
|
+
}
|
|
3216
|
+
if (effect.type === "refinement") {
|
|
3217
|
+
const executeRefinement = (acc) => {
|
|
3218
|
+
const result = effect.refinement(acc, checkCtx);
|
|
3219
|
+
if (ctx.common.async) return Promise.resolve(result);
|
|
3220
|
+
if (result instanceof Promise) throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
|
|
3221
|
+
return acc;
|
|
3222
|
+
};
|
|
3223
|
+
if (ctx.common.async === false) {
|
|
3224
|
+
const inner = this._def.schema._parseSync({
|
|
3225
|
+
data: ctx.data,
|
|
3226
|
+
path: ctx.path,
|
|
3227
|
+
parent: ctx
|
|
3228
|
+
});
|
|
3229
|
+
if (inner.status === "aborted") return INVALID;
|
|
3230
|
+
if (inner.status === "dirty") status.dirty();
|
|
3231
|
+
executeRefinement(inner.value);
|
|
3232
|
+
return {
|
|
3233
|
+
status: status.value,
|
|
3234
|
+
value: inner.value
|
|
3235
|
+
};
|
|
3236
|
+
} else return this._def.schema._parseAsync({
|
|
3237
|
+
data: ctx.data,
|
|
3238
|
+
path: ctx.path,
|
|
3239
|
+
parent: ctx
|
|
3240
|
+
}).then((inner) => {
|
|
3241
|
+
if (inner.status === "aborted") return INVALID;
|
|
3242
|
+
if (inner.status === "dirty") status.dirty();
|
|
3243
|
+
return executeRefinement(inner.value).then(() => {
|
|
3244
|
+
return {
|
|
3245
|
+
status: status.value,
|
|
3246
|
+
value: inner.value
|
|
3247
|
+
};
|
|
3248
|
+
});
|
|
3249
|
+
});
|
|
3250
|
+
}
|
|
3251
|
+
if (effect.type === "transform") if (ctx.common.async === false) {
|
|
3252
|
+
const base = this._def.schema._parseSync({
|
|
3253
|
+
data: ctx.data,
|
|
3254
|
+
path: ctx.path,
|
|
3255
|
+
parent: ctx
|
|
3256
|
+
});
|
|
3257
|
+
if (!isValid(base)) return INVALID;
|
|
3258
|
+
const result = effect.transform(base.value, checkCtx);
|
|
3259
|
+
if (result instanceof Promise) throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
|
|
3260
|
+
return {
|
|
3261
|
+
status: status.value,
|
|
3262
|
+
value: result
|
|
3263
|
+
};
|
|
3264
|
+
} else return this._def.schema._parseAsync({
|
|
3265
|
+
data: ctx.data,
|
|
3266
|
+
path: ctx.path,
|
|
3267
|
+
parent: ctx
|
|
3268
|
+
}).then((base) => {
|
|
3269
|
+
if (!isValid(base)) return INVALID;
|
|
3270
|
+
return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({
|
|
3271
|
+
status: status.value,
|
|
3272
|
+
value: result
|
|
3273
|
+
}));
|
|
3274
|
+
});
|
|
3275
|
+
util.assertNever(effect);
|
|
3276
|
+
}
|
|
3277
|
+
};
|
|
3278
|
+
ZodEffects.create = (schema, effect, params) => {
|
|
3279
|
+
return new ZodEffects({
|
|
3280
|
+
schema,
|
|
3281
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
3282
|
+
effect,
|
|
3283
|
+
...processCreateParams(params)
|
|
3284
|
+
});
|
|
3285
|
+
};
|
|
3286
|
+
ZodEffects.createWithPreprocess = (preprocess, schema, params) => {
|
|
3287
|
+
return new ZodEffects({
|
|
3288
|
+
schema,
|
|
3289
|
+
effect: {
|
|
3290
|
+
type: "preprocess",
|
|
3291
|
+
transform: preprocess
|
|
3292
|
+
},
|
|
3293
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
3294
|
+
...processCreateParams(params)
|
|
3295
|
+
});
|
|
3296
|
+
};
|
|
3297
|
+
var ZodOptional = class extends ZodType {
|
|
3298
|
+
_parse(input) {
|
|
3299
|
+
const parsedType = this._getType(input);
|
|
3300
|
+
if (parsedType === ZodParsedType.undefined) return OK(void 0);
|
|
3301
|
+
return this._def.innerType._parse(input);
|
|
3302
|
+
}
|
|
3303
|
+
unwrap() {
|
|
3304
|
+
return this._def.innerType;
|
|
3305
|
+
}
|
|
3306
|
+
};
|
|
3307
|
+
ZodOptional.create = (type, params) => {
|
|
3308
|
+
return new ZodOptional({
|
|
3309
|
+
innerType: type,
|
|
3310
|
+
typeName: ZodFirstPartyTypeKind.ZodOptional,
|
|
3311
|
+
...processCreateParams(params)
|
|
3312
|
+
});
|
|
3313
|
+
};
|
|
3314
|
+
var ZodNullable = class extends ZodType {
|
|
3315
|
+
_parse(input) {
|
|
3316
|
+
const parsedType = this._getType(input);
|
|
3317
|
+
if (parsedType === ZodParsedType.null) return OK(null);
|
|
3318
|
+
return this._def.innerType._parse(input);
|
|
3319
|
+
}
|
|
3320
|
+
unwrap() {
|
|
3321
|
+
return this._def.innerType;
|
|
3322
|
+
}
|
|
3323
|
+
};
|
|
3324
|
+
ZodNullable.create = (type, params) => {
|
|
3325
|
+
return new ZodNullable({
|
|
3326
|
+
innerType: type,
|
|
3327
|
+
typeName: ZodFirstPartyTypeKind.ZodNullable,
|
|
3328
|
+
...processCreateParams(params)
|
|
3329
|
+
});
|
|
3330
|
+
};
|
|
3331
|
+
var ZodDefault = class extends ZodType {
|
|
3332
|
+
_parse(input) {
|
|
3333
|
+
const { ctx } = this._processInputParams(input);
|
|
3334
|
+
let data = ctx.data;
|
|
3335
|
+
if (ctx.parsedType === ZodParsedType.undefined) data = this._def.defaultValue();
|
|
3336
|
+
return this._def.innerType._parse({
|
|
3337
|
+
data,
|
|
3338
|
+
path: ctx.path,
|
|
3339
|
+
parent: ctx
|
|
3340
|
+
});
|
|
3341
|
+
}
|
|
3342
|
+
removeDefault() {
|
|
3343
|
+
return this._def.innerType;
|
|
3344
|
+
}
|
|
3345
|
+
};
|
|
3346
|
+
ZodDefault.create = (type, params) => {
|
|
3347
|
+
return new ZodDefault({
|
|
3348
|
+
innerType: type,
|
|
3349
|
+
typeName: ZodFirstPartyTypeKind.ZodDefault,
|
|
3350
|
+
defaultValue: typeof params.default === "function" ? params.default : () => params.default,
|
|
3351
|
+
...processCreateParams(params)
|
|
3352
|
+
});
|
|
3353
|
+
};
|
|
3354
|
+
var ZodCatch = class extends ZodType {
|
|
3355
|
+
_parse(input) {
|
|
3356
|
+
const { ctx } = this._processInputParams(input);
|
|
3357
|
+
const newCtx = {
|
|
3358
|
+
...ctx,
|
|
3359
|
+
common: {
|
|
3360
|
+
...ctx.common,
|
|
3361
|
+
issues: []
|
|
3362
|
+
}
|
|
3363
|
+
};
|
|
3364
|
+
const result = this._def.innerType._parse({
|
|
3365
|
+
data: newCtx.data,
|
|
3366
|
+
path: newCtx.path,
|
|
3367
|
+
parent: { ...newCtx }
|
|
3368
|
+
});
|
|
3369
|
+
if (isAsync(result)) return result.then((result$1) => {
|
|
3370
|
+
return {
|
|
3371
|
+
status: "valid",
|
|
3372
|
+
value: result$1.status === "valid" ? result$1.value : this._def.catchValue({
|
|
3373
|
+
get error() {
|
|
3374
|
+
return new ZodError(newCtx.common.issues);
|
|
3375
|
+
},
|
|
3376
|
+
input: newCtx.data
|
|
3377
|
+
})
|
|
3378
|
+
};
|
|
3379
|
+
});
|
|
3380
|
+
else return {
|
|
3381
|
+
status: "valid",
|
|
3382
|
+
value: result.status === "valid" ? result.value : this._def.catchValue({
|
|
3383
|
+
get error() {
|
|
3384
|
+
return new ZodError(newCtx.common.issues);
|
|
3385
|
+
},
|
|
3386
|
+
input: newCtx.data
|
|
3387
|
+
})
|
|
3388
|
+
};
|
|
3389
|
+
}
|
|
3390
|
+
removeCatch() {
|
|
3391
|
+
return this._def.innerType;
|
|
3392
|
+
}
|
|
3393
|
+
};
|
|
3394
|
+
ZodCatch.create = (type, params) => {
|
|
3395
|
+
return new ZodCatch({
|
|
3396
|
+
innerType: type,
|
|
3397
|
+
typeName: ZodFirstPartyTypeKind.ZodCatch,
|
|
3398
|
+
catchValue: typeof params.catch === "function" ? params.catch : () => params.catch,
|
|
3399
|
+
...processCreateParams(params)
|
|
3400
|
+
});
|
|
3401
|
+
};
|
|
3402
|
+
var ZodNaN = class extends ZodType {
|
|
3403
|
+
_parse(input) {
|
|
3404
|
+
const parsedType = this._getType(input);
|
|
3405
|
+
if (parsedType !== ZodParsedType.nan) {
|
|
3406
|
+
const ctx = this._getOrReturnCtx(input);
|
|
3407
|
+
addIssueToContext(ctx, {
|
|
3408
|
+
code: ZodIssueCode.invalid_type,
|
|
3409
|
+
expected: ZodParsedType.nan,
|
|
3410
|
+
received: ctx.parsedType
|
|
3411
|
+
});
|
|
3412
|
+
return INVALID;
|
|
3413
|
+
}
|
|
3414
|
+
return {
|
|
3415
|
+
status: "valid",
|
|
3416
|
+
value: input.data
|
|
3417
|
+
};
|
|
3418
|
+
}
|
|
3419
|
+
};
|
|
3420
|
+
ZodNaN.create = (params) => {
|
|
3421
|
+
return new ZodNaN({
|
|
3422
|
+
typeName: ZodFirstPartyTypeKind.ZodNaN,
|
|
3423
|
+
...processCreateParams(params)
|
|
3424
|
+
});
|
|
3425
|
+
};
|
|
3426
|
+
const BRAND = Symbol("zod_brand");
|
|
3427
|
+
var ZodBranded = class extends ZodType {
|
|
3428
|
+
_parse(input) {
|
|
3429
|
+
const { ctx } = this._processInputParams(input);
|
|
3430
|
+
const data = ctx.data;
|
|
3431
|
+
return this._def.type._parse({
|
|
3432
|
+
data,
|
|
3433
|
+
path: ctx.path,
|
|
3434
|
+
parent: ctx
|
|
3435
|
+
});
|
|
3436
|
+
}
|
|
3437
|
+
unwrap() {
|
|
3438
|
+
return this._def.type;
|
|
3439
|
+
}
|
|
3440
|
+
};
|
|
3441
|
+
var ZodPipeline = class ZodPipeline extends ZodType {
|
|
3442
|
+
_parse(input) {
|
|
3443
|
+
const { status, ctx } = this._processInputParams(input);
|
|
3444
|
+
if (ctx.common.async) {
|
|
3445
|
+
const handleAsync = async () => {
|
|
3446
|
+
const inResult = await this._def.in._parseAsync({
|
|
3447
|
+
data: ctx.data,
|
|
3448
|
+
path: ctx.path,
|
|
3449
|
+
parent: ctx
|
|
3450
|
+
});
|
|
3451
|
+
if (inResult.status === "aborted") return INVALID;
|
|
3452
|
+
if (inResult.status === "dirty") {
|
|
3453
|
+
status.dirty();
|
|
3454
|
+
return DIRTY(inResult.value);
|
|
3455
|
+
} else return this._def.out._parseAsync({
|
|
3456
|
+
data: inResult.value,
|
|
3457
|
+
path: ctx.path,
|
|
3458
|
+
parent: ctx
|
|
3459
|
+
});
|
|
3460
|
+
};
|
|
3461
|
+
return handleAsync();
|
|
3462
|
+
} else {
|
|
3463
|
+
const inResult = this._def.in._parseSync({
|
|
3464
|
+
data: ctx.data,
|
|
3465
|
+
path: ctx.path,
|
|
3466
|
+
parent: ctx
|
|
3467
|
+
});
|
|
3468
|
+
if (inResult.status === "aborted") return INVALID;
|
|
3469
|
+
if (inResult.status === "dirty") {
|
|
3470
|
+
status.dirty();
|
|
3471
|
+
return {
|
|
3472
|
+
status: "dirty",
|
|
3473
|
+
value: inResult.value
|
|
3474
|
+
};
|
|
3475
|
+
} else return this._def.out._parseSync({
|
|
3476
|
+
data: inResult.value,
|
|
3477
|
+
path: ctx.path,
|
|
3478
|
+
parent: ctx
|
|
3479
|
+
});
|
|
3480
|
+
}
|
|
3481
|
+
}
|
|
3482
|
+
static create(a, b) {
|
|
3483
|
+
return new ZodPipeline({
|
|
3484
|
+
in: a,
|
|
3485
|
+
out: b,
|
|
3486
|
+
typeName: ZodFirstPartyTypeKind.ZodPipeline
|
|
3487
|
+
});
|
|
3488
|
+
}
|
|
3489
|
+
};
|
|
3490
|
+
var ZodReadonly = class extends ZodType {
|
|
3491
|
+
_parse(input) {
|
|
3492
|
+
const result = this._def.innerType._parse(input);
|
|
3493
|
+
const freeze = (data) => {
|
|
3494
|
+
if (isValid(data)) data.value = Object.freeze(data.value);
|
|
3495
|
+
return data;
|
|
3496
|
+
};
|
|
3497
|
+
return isAsync(result) ? result.then((data) => freeze(data)) : freeze(result);
|
|
3498
|
+
}
|
|
3499
|
+
unwrap() {
|
|
3500
|
+
return this._def.innerType;
|
|
3501
|
+
}
|
|
3502
|
+
};
|
|
3503
|
+
ZodReadonly.create = (type, params) => {
|
|
3504
|
+
return new ZodReadonly({
|
|
3505
|
+
innerType: type,
|
|
3506
|
+
typeName: ZodFirstPartyTypeKind.ZodReadonly,
|
|
3507
|
+
...processCreateParams(params)
|
|
3508
|
+
});
|
|
3509
|
+
};
|
|
3510
|
+
const late = { object: ZodObject.lazycreate };
|
|
3511
|
+
var ZodFirstPartyTypeKind;
|
|
3512
|
+
(function(ZodFirstPartyTypeKind$1) {
|
|
3513
|
+
ZodFirstPartyTypeKind$1["ZodString"] = "ZodString";
|
|
3514
|
+
ZodFirstPartyTypeKind$1["ZodNumber"] = "ZodNumber";
|
|
3515
|
+
ZodFirstPartyTypeKind$1["ZodNaN"] = "ZodNaN";
|
|
3516
|
+
ZodFirstPartyTypeKind$1["ZodBigInt"] = "ZodBigInt";
|
|
3517
|
+
ZodFirstPartyTypeKind$1["ZodBoolean"] = "ZodBoolean";
|
|
3518
|
+
ZodFirstPartyTypeKind$1["ZodDate"] = "ZodDate";
|
|
3519
|
+
ZodFirstPartyTypeKind$1["ZodSymbol"] = "ZodSymbol";
|
|
3520
|
+
ZodFirstPartyTypeKind$1["ZodUndefined"] = "ZodUndefined";
|
|
3521
|
+
ZodFirstPartyTypeKind$1["ZodNull"] = "ZodNull";
|
|
3522
|
+
ZodFirstPartyTypeKind$1["ZodAny"] = "ZodAny";
|
|
3523
|
+
ZodFirstPartyTypeKind$1["ZodUnknown"] = "ZodUnknown";
|
|
3524
|
+
ZodFirstPartyTypeKind$1["ZodNever"] = "ZodNever";
|
|
3525
|
+
ZodFirstPartyTypeKind$1["ZodVoid"] = "ZodVoid";
|
|
3526
|
+
ZodFirstPartyTypeKind$1["ZodArray"] = "ZodArray";
|
|
3527
|
+
ZodFirstPartyTypeKind$1["ZodObject"] = "ZodObject";
|
|
3528
|
+
ZodFirstPartyTypeKind$1["ZodUnion"] = "ZodUnion";
|
|
3529
|
+
ZodFirstPartyTypeKind$1["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion";
|
|
3530
|
+
ZodFirstPartyTypeKind$1["ZodIntersection"] = "ZodIntersection";
|
|
3531
|
+
ZodFirstPartyTypeKind$1["ZodTuple"] = "ZodTuple";
|
|
3532
|
+
ZodFirstPartyTypeKind$1["ZodRecord"] = "ZodRecord";
|
|
3533
|
+
ZodFirstPartyTypeKind$1["ZodMap"] = "ZodMap";
|
|
3534
|
+
ZodFirstPartyTypeKind$1["ZodSet"] = "ZodSet";
|
|
3535
|
+
ZodFirstPartyTypeKind$1["ZodFunction"] = "ZodFunction";
|
|
3536
|
+
ZodFirstPartyTypeKind$1["ZodLazy"] = "ZodLazy";
|
|
3537
|
+
ZodFirstPartyTypeKind$1["ZodLiteral"] = "ZodLiteral";
|
|
3538
|
+
ZodFirstPartyTypeKind$1["ZodEnum"] = "ZodEnum";
|
|
3539
|
+
ZodFirstPartyTypeKind$1["ZodEffects"] = "ZodEffects";
|
|
3540
|
+
ZodFirstPartyTypeKind$1["ZodNativeEnum"] = "ZodNativeEnum";
|
|
3541
|
+
ZodFirstPartyTypeKind$1["ZodOptional"] = "ZodOptional";
|
|
3542
|
+
ZodFirstPartyTypeKind$1["ZodNullable"] = "ZodNullable";
|
|
3543
|
+
ZodFirstPartyTypeKind$1["ZodDefault"] = "ZodDefault";
|
|
3544
|
+
ZodFirstPartyTypeKind$1["ZodCatch"] = "ZodCatch";
|
|
3545
|
+
ZodFirstPartyTypeKind$1["ZodPromise"] = "ZodPromise";
|
|
3546
|
+
ZodFirstPartyTypeKind$1["ZodBranded"] = "ZodBranded";
|
|
3547
|
+
ZodFirstPartyTypeKind$1["ZodPipeline"] = "ZodPipeline";
|
|
3548
|
+
ZodFirstPartyTypeKind$1["ZodReadonly"] = "ZodReadonly";
|
|
3549
|
+
})(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
|
|
3550
|
+
const stringType = ZodString.create;
|
|
3551
|
+
const numberType = ZodNumber.create;
|
|
3552
|
+
const nanType = ZodNaN.create;
|
|
3553
|
+
const bigIntType = ZodBigInt.create;
|
|
3554
|
+
const booleanType = ZodBoolean.create;
|
|
3555
|
+
const dateType = ZodDate.create;
|
|
3556
|
+
const symbolType = ZodSymbol.create;
|
|
3557
|
+
const undefinedType = ZodUndefined.create;
|
|
3558
|
+
const nullType = ZodNull.create;
|
|
3559
|
+
const anyType = ZodAny.create;
|
|
3560
|
+
const unknownType = ZodUnknown.create;
|
|
3561
|
+
const neverType = ZodNever.create;
|
|
3562
|
+
const voidType = ZodVoid.create;
|
|
3563
|
+
const arrayType = ZodArray.create;
|
|
3564
|
+
const objectType = ZodObject.create;
|
|
3565
|
+
const strictObjectType = ZodObject.strictCreate;
|
|
3566
|
+
const unionType = ZodUnion.create;
|
|
3567
|
+
const discriminatedUnionType = ZodDiscriminatedUnion.create;
|
|
3568
|
+
const intersectionType = ZodIntersection.create;
|
|
3569
|
+
const tupleType = ZodTuple.create;
|
|
3570
|
+
const recordType = ZodRecord.create;
|
|
3571
|
+
const mapType = ZodMap.create;
|
|
3572
|
+
const setType = ZodSet.create;
|
|
3573
|
+
const functionType = ZodFunction.create;
|
|
3574
|
+
const lazyType = ZodLazy.create;
|
|
3575
|
+
const literalType = ZodLiteral.create;
|
|
3576
|
+
const enumType = ZodEnum.create;
|
|
3577
|
+
const nativeEnumType = ZodNativeEnum.create;
|
|
3578
|
+
const promiseType = ZodPromise.create;
|
|
3579
|
+
const effectsType = ZodEffects.create;
|
|
3580
|
+
const optionalType = ZodOptional.create;
|
|
3581
|
+
const nullableType = ZodNullable.create;
|
|
3582
|
+
const preprocessType = ZodEffects.createWithPreprocess;
|
|
3583
|
+
const pipelineType = ZodPipeline.create;
|
|
3584
|
+
|
|
3585
|
+
//#endregion
|
|
3586
|
+
export { ZodFirstPartyTypeKind, ZodOptional, anyType, arrayType, booleanType, discriminatedUnionType, enumType, literalType, numberType, objectType, optionalType, recordType, stringType, unionType, unknownType };
|