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