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