vite-plus 0.3.0 → 0.3.2

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