@alint-js/plugin-simplicity 0.0.27 → 0.0.29

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.
@@ -0,0 +1,4632 @@
1
+ //#region ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@4.4.3/node_modules/zod-to-json-schema/dist/esm/Options.js
2
+ const ignoreOverride = Symbol("Let zodToJsonSchema decide on which parser to use");
3
+ const defaultOptions = {
4
+ name: void 0,
5
+ $refStrategy: "root",
6
+ basePath: ["#"],
7
+ effectStrategy: "input",
8
+ pipeStrategy: "all",
9
+ dateStrategy: "format:date-time",
10
+ mapStrategy: "entries",
11
+ removeAdditionalStrategy: "passthrough",
12
+ allowedAdditionalProperties: true,
13
+ rejectedAdditionalProperties: false,
14
+ definitionPath: "definitions",
15
+ target: "jsonSchema7",
16
+ strictUnions: false,
17
+ definitions: {},
18
+ errorMessages: false,
19
+ markdownDescription: false,
20
+ patternStrategy: "escape",
21
+ applyRegexFlags: false,
22
+ emailStrategy: "format:email",
23
+ base64Strategy: "contentEncoding:base64",
24
+ nameStrategy: "ref",
25
+ openAiAnyTypeName: "OpenAiAnyType"
26
+ };
27
+ const getDefaultOptions = (options) => typeof options === "string" ? {
28
+ ...defaultOptions,
29
+ name: options
30
+ } : {
31
+ ...defaultOptions,
32
+ ...options
33
+ };
34
+ //#endregion
35
+ //#region ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@4.4.3/node_modules/zod-to-json-schema/dist/esm/Refs.js
36
+ const getRefs = (options) => {
37
+ const _options = getDefaultOptions(options);
38
+ const currentPath = _options.name !== void 0 ? [
39
+ ..._options.basePath,
40
+ _options.definitionPath,
41
+ _options.name
42
+ ] : _options.basePath;
43
+ return {
44
+ ..._options,
45
+ flags: { hasReferencedOpenAiAnyType: false },
46
+ currentPath,
47
+ propertyPath: void 0,
48
+ seen: new Map(Object.entries(_options.definitions).map(([name, def]) => [def._def, {
49
+ def: def._def,
50
+ path: [
51
+ ..._options.basePath,
52
+ _options.definitionPath,
53
+ name
54
+ ],
55
+ jsonSchema: void 0
56
+ }]))
57
+ };
58
+ };
59
+ //#endregion
60
+ //#region ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@4.4.3/node_modules/zod-to-json-schema/dist/esm/errorMessages.js
61
+ function addErrorMessage(res, key, errorMessage, refs) {
62
+ if (!refs?.errorMessages) return;
63
+ if (errorMessage) res.errorMessage = {
64
+ ...res.errorMessage,
65
+ [key]: errorMessage
66
+ };
67
+ }
68
+ function setResponseValueAndErrors(res, key, value, errorMessage, refs) {
69
+ res[key] = value;
70
+ addErrorMessage(res, key, errorMessage, refs);
71
+ }
72
+ //#endregion
73
+ //#region ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@4.4.3/node_modules/zod-to-json-schema/dist/esm/getRelativePath.js
74
+ const getRelativePath = (pathA, pathB) => {
75
+ let i = 0;
76
+ for (; i < pathA.length && i < pathB.length; i++) if (pathA[i] !== pathB[i]) break;
77
+ return [(pathA.length - i).toString(), ...pathB.slice(i)].join("/");
78
+ };
79
+ //#endregion
80
+ //#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v3/helpers/util.js
81
+ var util;
82
+ (function(util) {
83
+ util.assertEqual = (_) => {};
84
+ function assertIs(_arg) {}
85
+ util.assertIs = assertIs;
86
+ function assertNever(_x) {
87
+ throw new Error();
88
+ }
89
+ util.assertNever = assertNever;
90
+ util.arrayToEnum = (items) => {
91
+ const obj = {};
92
+ for (const item of items) obj[item] = item;
93
+ return obj;
94
+ };
95
+ util.getValidEnumValues = (obj) => {
96
+ const validKeys = util.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
97
+ const filtered = {};
98
+ for (const k of validKeys) filtered[k] = obj[k];
99
+ return util.objectValues(filtered);
100
+ };
101
+ util.objectValues = (obj) => {
102
+ return util.objectKeys(obj).map(function(e) {
103
+ return obj[e];
104
+ });
105
+ };
106
+ util.objectKeys = typeof Object.keys === "function" ? (obj) => Object.keys(obj) : (object) => {
107
+ const keys = [];
108
+ for (const key in object) if (Object.prototype.hasOwnProperty.call(object, key)) keys.push(key);
109
+ return keys;
110
+ };
111
+ util.find = (arr, checker) => {
112
+ for (const item of arr) if (checker(item)) return item;
113
+ };
114
+ util.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && Number.isFinite(val) && Math.floor(val) === val;
115
+ function joinValues(array, separator = " | ") {
116
+ return array.map((val) => typeof val === "string" ? `'${val}'` : val).join(separator);
117
+ }
118
+ util.joinValues = joinValues;
119
+ util.jsonStringifyReplacer = (_, value) => {
120
+ if (typeof value === "bigint") return value.toString();
121
+ return value;
122
+ };
123
+ })(util || (util = {}));
124
+ var objectUtil;
125
+ (function(objectUtil) {
126
+ objectUtil.mergeShapes = (first, second) => {
127
+ return {
128
+ ...first,
129
+ ...second
130
+ };
131
+ };
132
+ })(objectUtil || (objectUtil = {}));
133
+ const ZodParsedType = util.arrayToEnum([
134
+ "string",
135
+ "nan",
136
+ "number",
137
+ "integer",
138
+ "float",
139
+ "boolean",
140
+ "date",
141
+ "bigint",
142
+ "symbol",
143
+ "function",
144
+ "undefined",
145
+ "null",
146
+ "array",
147
+ "object",
148
+ "unknown",
149
+ "promise",
150
+ "void",
151
+ "never",
152
+ "map",
153
+ "set"
154
+ ]);
155
+ const getParsedType = (data) => {
156
+ switch (typeof data) {
157
+ case "undefined": return ZodParsedType.undefined;
158
+ case "string": return ZodParsedType.string;
159
+ case "number": return Number.isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
160
+ case "boolean": return ZodParsedType.boolean;
161
+ case "function": return ZodParsedType.function;
162
+ case "bigint": return ZodParsedType.bigint;
163
+ case "symbol": return ZodParsedType.symbol;
164
+ case "object":
165
+ if (Array.isArray(data)) return ZodParsedType.array;
166
+ if (data === null) return ZodParsedType.null;
167
+ if (data.then && typeof data.then === "function" && data.catch && typeof data.catch === "function") return ZodParsedType.promise;
168
+ if (typeof Map !== "undefined" && data instanceof Map) return ZodParsedType.map;
169
+ if (typeof Set !== "undefined" && data instanceof Set) return ZodParsedType.set;
170
+ if (typeof Date !== "undefined" && data instanceof Date) return ZodParsedType.date;
171
+ return ZodParsedType.object;
172
+ default: return ZodParsedType.unknown;
173
+ }
174
+ };
175
+ //#endregion
176
+ //#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v3/ZodError.js
177
+ const ZodIssueCode = util.arrayToEnum([
178
+ "invalid_type",
179
+ "invalid_literal",
180
+ "custom",
181
+ "invalid_union",
182
+ "invalid_union_discriminator",
183
+ "invalid_enum_value",
184
+ "unrecognized_keys",
185
+ "invalid_arguments",
186
+ "invalid_return_type",
187
+ "invalid_date",
188
+ "invalid_string",
189
+ "too_small",
190
+ "too_big",
191
+ "invalid_intersection_types",
192
+ "not_multiple_of",
193
+ "not_finite"
194
+ ]);
195
+ var ZodError = class ZodError extends Error {
196
+ get errors() {
197
+ return this.issues;
198
+ }
199
+ constructor(issues) {
200
+ super();
201
+ this.issues = [];
202
+ this.addIssue = (sub) => {
203
+ this.issues = [...this.issues, sub];
204
+ };
205
+ this.addIssues = (subs = []) => {
206
+ this.issues = [...this.issues, ...subs];
207
+ };
208
+ const actualProto = new.target.prototype;
209
+ if (Object.setPrototypeOf) Object.setPrototypeOf(this, actualProto);
210
+ else this.__proto__ = actualProto;
211
+ this.name = "ZodError";
212
+ this.issues = issues;
213
+ }
214
+ format(_mapper) {
215
+ const mapper = _mapper || function(issue) {
216
+ return issue.message;
217
+ };
218
+ const fieldErrors = { _errors: [] };
219
+ const processError = (error) => {
220
+ for (const issue of error.issues) if (issue.code === "invalid_union") issue.unionErrors.map(processError);
221
+ else if (issue.code === "invalid_return_type") processError(issue.returnTypeError);
222
+ else if (issue.code === "invalid_arguments") processError(issue.argumentsError);
223
+ else if (issue.path.length === 0) fieldErrors._errors.push(mapper(issue));
224
+ else {
225
+ let curr = fieldErrors;
226
+ let i = 0;
227
+ while (i < issue.path.length) {
228
+ const el = issue.path[i];
229
+ if (!(i === issue.path.length - 1)) curr[el] = curr[el] || { _errors: [] };
230
+ else {
231
+ curr[el] = curr[el] || { _errors: [] };
232
+ curr[el]._errors.push(mapper(issue));
233
+ }
234
+ curr = curr[el];
235
+ i++;
236
+ }
237
+ }
238
+ };
239
+ processError(this);
240
+ return fieldErrors;
241
+ }
242
+ static assert(value) {
243
+ if (!(value instanceof ZodError)) throw new Error(`Not a ZodError: ${value}`);
244
+ }
245
+ toString() {
246
+ return this.message;
247
+ }
248
+ get message() {
249
+ return JSON.stringify(this.issues, util.jsonStringifyReplacer, 2);
250
+ }
251
+ get isEmpty() {
252
+ return this.issues.length === 0;
253
+ }
254
+ flatten(mapper = (issue) => issue.message) {
255
+ const fieldErrors = Object.create(null);
256
+ const formErrors = [];
257
+ for (const sub of this.issues) if (sub.path.length > 0) {
258
+ const firstEl = sub.path[0];
259
+ fieldErrors[firstEl] = fieldErrors[firstEl] || [];
260
+ fieldErrors[firstEl].push(mapper(sub));
261
+ } else formErrors.push(mapper(sub));
262
+ return {
263
+ formErrors,
264
+ fieldErrors
265
+ };
266
+ }
267
+ get formErrors() {
268
+ return this.flatten();
269
+ }
270
+ };
271
+ ZodError.create = (issues) => {
272
+ return new ZodError(issues);
273
+ };
274
+ //#endregion
275
+ //#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v3/locales/en.js
276
+ const errorMap = (issue, _ctx) => {
277
+ let message;
278
+ switch (issue.code) {
279
+ case ZodIssueCode.invalid_type:
280
+ if (issue.received === ZodParsedType.undefined) message = "Required";
281
+ else message = `Expected ${issue.expected}, received ${issue.received}`;
282
+ break;
283
+ case ZodIssueCode.invalid_literal:
284
+ message = `Invalid literal value, expected ${JSON.stringify(issue.expected, util.jsonStringifyReplacer)}`;
285
+ break;
286
+ case ZodIssueCode.unrecognized_keys:
287
+ message = `Unrecognized key(s) in object: ${util.joinValues(issue.keys, ", ")}`;
288
+ break;
289
+ case ZodIssueCode.invalid_union:
290
+ message = `Invalid input`;
291
+ break;
292
+ case ZodIssueCode.invalid_union_discriminator:
293
+ message = `Invalid discriminator value. Expected ${util.joinValues(issue.options)}`;
294
+ break;
295
+ case ZodIssueCode.invalid_enum_value:
296
+ message = `Invalid enum value. Expected ${util.joinValues(issue.options)}, received '${issue.received}'`;
297
+ break;
298
+ case ZodIssueCode.invalid_arguments:
299
+ message = `Invalid function arguments`;
300
+ break;
301
+ case ZodIssueCode.invalid_return_type:
302
+ message = `Invalid function return type`;
303
+ break;
304
+ case ZodIssueCode.invalid_date:
305
+ message = `Invalid date`;
306
+ break;
307
+ case ZodIssueCode.invalid_string:
308
+ if (typeof issue.validation === "object") if ("includes" in issue.validation) {
309
+ message = `Invalid input: must include "${issue.validation.includes}"`;
310
+ if (typeof issue.validation.position === "number") message = `${message} at one or more positions greater than or equal to ${issue.validation.position}`;
311
+ } else if ("startsWith" in issue.validation) message = `Invalid input: must start with "${issue.validation.startsWith}"`;
312
+ else if ("endsWith" in issue.validation) message = `Invalid input: must end with "${issue.validation.endsWith}"`;
313
+ else util.assertNever(issue.validation);
314
+ else if (issue.validation !== "regex") message = `Invalid ${issue.validation}`;
315
+ else message = "Invalid";
316
+ break;
317
+ case ZodIssueCode.too_small:
318
+ if (issue.type === "array") message = `Array must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `more than`} ${issue.minimum} element(s)`;
319
+ else if (issue.type === "string") message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
320
+ 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}`;
321
+ 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}`;
322
+ 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))}`;
323
+ else message = "Invalid input";
324
+ break;
325
+ case ZodIssueCode.too_big:
326
+ if (issue.type === "array") message = `Array must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `less than`} ${issue.maximum} element(s)`;
327
+ else if (issue.type === "string") message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
328
+ else if (issue.type === "number") message = `Number must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
329
+ else if (issue.type === "bigint") message = `BigInt must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
330
+ 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))}`;
331
+ else message = "Invalid input";
332
+ break;
333
+ case ZodIssueCode.custom:
334
+ message = `Invalid input`;
335
+ break;
336
+ case ZodIssueCode.invalid_intersection_types:
337
+ message = `Intersection results could not be merged`;
338
+ break;
339
+ case ZodIssueCode.not_multiple_of:
340
+ message = `Number must be a multiple of ${issue.multipleOf}`;
341
+ break;
342
+ case ZodIssueCode.not_finite:
343
+ message = "Number must be finite";
344
+ break;
345
+ default:
346
+ message = _ctx.defaultError;
347
+ util.assertNever(issue);
348
+ }
349
+ return { message };
350
+ };
351
+ //#endregion
352
+ //#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v3/errors.js
353
+ let overrideErrorMap = errorMap;
354
+ function getErrorMap() {
355
+ return overrideErrorMap;
356
+ }
357
+ //#endregion
358
+ //#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v3/helpers/parseUtil.js
359
+ const makeIssue = (params) => {
360
+ const { data, path, errorMaps, issueData } = params;
361
+ const fullPath = [...path, ...issueData.path || []];
362
+ const fullIssue = {
363
+ ...issueData,
364
+ path: fullPath
365
+ };
366
+ if (issueData.message !== void 0) return {
367
+ ...issueData,
368
+ path: fullPath,
369
+ message: issueData.message
370
+ };
371
+ let errorMessage = "";
372
+ const maps = errorMaps.filter((m) => !!m).slice().reverse();
373
+ for (const map of maps) errorMessage = map(fullIssue, {
374
+ data,
375
+ defaultError: errorMessage
376
+ }).message;
377
+ return {
378
+ ...issueData,
379
+ path: fullPath,
380
+ message: errorMessage
381
+ };
382
+ };
383
+ function addIssueToContext(ctx, issueData) {
384
+ const overrideMap = getErrorMap();
385
+ const issue = makeIssue({
386
+ issueData,
387
+ data: ctx.data,
388
+ path: ctx.path,
389
+ errorMaps: [
390
+ ctx.common.contextualErrorMap,
391
+ ctx.schemaErrorMap,
392
+ overrideMap,
393
+ overrideMap === errorMap ? void 0 : errorMap
394
+ ].filter((x) => !!x)
395
+ });
396
+ ctx.common.issues.push(issue);
397
+ }
398
+ var ParseStatus = class ParseStatus {
399
+ constructor() {
400
+ this.value = "valid";
401
+ }
402
+ dirty() {
403
+ if (this.value === "valid") this.value = "dirty";
404
+ }
405
+ abort() {
406
+ if (this.value !== "aborted") this.value = "aborted";
407
+ }
408
+ static mergeArray(status, results) {
409
+ const arrayValue = [];
410
+ for (const s of results) {
411
+ if (s.status === "aborted") return INVALID;
412
+ if (s.status === "dirty") status.dirty();
413
+ arrayValue.push(s.value);
414
+ }
415
+ return {
416
+ status: status.value,
417
+ value: arrayValue
418
+ };
419
+ }
420
+ static async mergeObjectAsync(status, pairs) {
421
+ const syncPairs = [];
422
+ for (const pair of pairs) {
423
+ const key = await pair.key;
424
+ const value = await pair.value;
425
+ syncPairs.push({
426
+ key,
427
+ value
428
+ });
429
+ }
430
+ return ParseStatus.mergeObjectSync(status, syncPairs);
431
+ }
432
+ static mergeObjectSync(status, pairs) {
433
+ const finalObject = {};
434
+ for (const pair of pairs) {
435
+ const { key, value } = pair;
436
+ if (key.status === "aborted") return INVALID;
437
+ if (value.status === "aborted") return INVALID;
438
+ if (key.status === "dirty") status.dirty();
439
+ if (value.status === "dirty") status.dirty();
440
+ if (key.value !== "__proto__" && (typeof value.value !== "undefined" || pair.alwaysSet)) finalObject[key.value] = value.value;
441
+ }
442
+ return {
443
+ status: status.value,
444
+ value: finalObject
445
+ };
446
+ }
447
+ };
448
+ const INVALID = Object.freeze({ status: "aborted" });
449
+ const DIRTY = (value) => ({
450
+ status: "dirty",
451
+ value
452
+ });
453
+ const OK = (value) => ({
454
+ status: "valid",
455
+ value
456
+ });
457
+ const isAborted = (x) => x.status === "aborted";
458
+ const isDirty = (x) => x.status === "dirty";
459
+ const isValid = (x) => x.status === "valid";
460
+ const isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
461
+ //#endregion
462
+ //#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v3/helpers/errorUtil.js
463
+ var errorUtil;
464
+ (function(errorUtil) {
465
+ errorUtil.errToObj = (message) => typeof message === "string" ? { message } : message || {};
466
+ errorUtil.toString = (message) => typeof message === "string" ? message : message?.message;
467
+ })(errorUtil || (errorUtil = {}));
468
+ //#endregion
469
+ //#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v3/types.js
470
+ var ParseInputLazyPath = class {
471
+ constructor(parent, value, path, key) {
472
+ this._cachedPath = [];
473
+ this.parent = parent;
474
+ this.data = value;
475
+ this._path = path;
476
+ this._key = key;
477
+ }
478
+ get path() {
479
+ if (!this._cachedPath.length) if (Array.isArray(this._key)) this._cachedPath.push(...this._path, ...this._key);
480
+ else this._cachedPath.push(...this._path, this._key);
481
+ return this._cachedPath;
482
+ }
483
+ };
484
+ const handleResult = (ctx, result) => {
485
+ if (isValid(result)) return {
486
+ success: true,
487
+ data: result.value
488
+ };
489
+ else {
490
+ if (!ctx.common.issues.length) throw new Error("Validation failed but no issues detected.");
491
+ return {
492
+ success: false,
493
+ get error() {
494
+ if (this._error) return this._error;
495
+ const error = new ZodError(ctx.common.issues);
496
+ this._error = error;
497
+ return this._error;
498
+ }
499
+ };
500
+ }
501
+ };
502
+ function processCreateParams(params) {
503
+ if (!params) return {};
504
+ const { errorMap, invalid_type_error, required_error, description } = params;
505
+ 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.`);
506
+ if (errorMap) return {
507
+ errorMap,
508
+ description
509
+ };
510
+ const customMap = (iss, ctx) => {
511
+ const { message } = params;
512
+ if (iss.code === "invalid_enum_value") return { message: message ?? ctx.defaultError };
513
+ if (typeof ctx.data === "undefined") return { message: message ?? required_error ?? ctx.defaultError };
514
+ if (iss.code !== "invalid_type") return { message: ctx.defaultError };
515
+ return { message: message ?? invalid_type_error ?? ctx.defaultError };
516
+ };
517
+ return {
518
+ errorMap: customMap,
519
+ description
520
+ };
521
+ }
522
+ var ZodType = class {
523
+ get description() {
524
+ return this._def.description;
525
+ }
526
+ _getType(input) {
527
+ return getParsedType(input.data);
528
+ }
529
+ _getOrReturnCtx(input, ctx) {
530
+ return ctx || {
531
+ common: input.parent.common,
532
+ data: input.data,
533
+ parsedType: getParsedType(input.data),
534
+ schemaErrorMap: this._def.errorMap,
535
+ path: input.path,
536
+ parent: input.parent
537
+ };
538
+ }
539
+ _processInputParams(input) {
540
+ return {
541
+ status: new ParseStatus(),
542
+ ctx: {
543
+ common: input.parent.common,
544
+ data: input.data,
545
+ parsedType: getParsedType(input.data),
546
+ schemaErrorMap: this._def.errorMap,
547
+ path: input.path,
548
+ parent: input.parent
549
+ }
550
+ };
551
+ }
552
+ _parseSync(input) {
553
+ const result = this._parse(input);
554
+ if (isAsync(result)) throw new Error("Synchronous parse encountered promise.");
555
+ return result;
556
+ }
557
+ _parseAsync(input) {
558
+ const result = this._parse(input);
559
+ return Promise.resolve(result);
560
+ }
561
+ parse(data, params) {
562
+ const result = this.safeParse(data, params);
563
+ if (result.success) return result.data;
564
+ throw result.error;
565
+ }
566
+ safeParse(data, params) {
567
+ const ctx = {
568
+ common: {
569
+ issues: [],
570
+ async: params?.async ?? false,
571
+ contextualErrorMap: params?.errorMap
572
+ },
573
+ path: params?.path || [],
574
+ schemaErrorMap: this._def.errorMap,
575
+ parent: null,
576
+ data,
577
+ parsedType: getParsedType(data)
578
+ };
579
+ const result = this._parseSync({
580
+ data,
581
+ path: ctx.path,
582
+ parent: ctx
583
+ });
584
+ return handleResult(ctx, result);
585
+ }
586
+ "~validate"(data) {
587
+ const ctx = {
588
+ common: {
589
+ issues: [],
590
+ async: !!this["~standard"].async
591
+ },
592
+ path: [],
593
+ schemaErrorMap: this._def.errorMap,
594
+ parent: null,
595
+ data,
596
+ parsedType: getParsedType(data)
597
+ };
598
+ if (!this["~standard"].async) try {
599
+ const result = this._parseSync({
600
+ data,
601
+ path: [],
602
+ parent: ctx
603
+ });
604
+ return isValid(result) ? { value: result.value } : { issues: ctx.common.issues };
605
+ } catch (err) {
606
+ if (err?.message?.toLowerCase()?.includes("encountered")) this["~standard"].async = true;
607
+ ctx.common = {
608
+ issues: [],
609
+ async: true
610
+ };
611
+ }
612
+ return this._parseAsync({
613
+ data,
614
+ path: [],
615
+ parent: ctx
616
+ }).then((result) => isValid(result) ? { value: result.value } : { issues: ctx.common.issues });
617
+ }
618
+ async parseAsync(data, params) {
619
+ const result = await this.safeParseAsync(data, params);
620
+ if (result.success) return result.data;
621
+ throw result.error;
622
+ }
623
+ async safeParseAsync(data, params) {
624
+ const ctx = {
625
+ common: {
626
+ issues: [],
627
+ contextualErrorMap: params?.errorMap,
628
+ async: true
629
+ },
630
+ path: params?.path || [],
631
+ schemaErrorMap: this._def.errorMap,
632
+ parent: null,
633
+ data,
634
+ parsedType: getParsedType(data)
635
+ };
636
+ const maybeAsyncResult = this._parse({
637
+ data,
638
+ path: ctx.path,
639
+ parent: ctx
640
+ });
641
+ const result = await (isAsync(maybeAsyncResult) ? maybeAsyncResult : Promise.resolve(maybeAsyncResult));
642
+ return handleResult(ctx, result);
643
+ }
644
+ refine(check, message) {
645
+ const getIssueProperties = (val) => {
646
+ if (typeof message === "string" || typeof message === "undefined") return { message };
647
+ else if (typeof message === "function") return message(val);
648
+ else return message;
649
+ };
650
+ return this._refinement((val, ctx) => {
651
+ const result = check(val);
652
+ const setError = () => ctx.addIssue({
653
+ code: ZodIssueCode.custom,
654
+ ...getIssueProperties(val)
655
+ });
656
+ if (typeof Promise !== "undefined" && result instanceof Promise) return result.then((data) => {
657
+ if (!data) {
658
+ setError();
659
+ return false;
660
+ } else return true;
661
+ });
662
+ if (!result) {
663
+ setError();
664
+ return false;
665
+ } else return true;
666
+ });
667
+ }
668
+ refinement(check, refinementData) {
669
+ return this._refinement((val, ctx) => {
670
+ if (!check(val)) {
671
+ ctx.addIssue(typeof refinementData === "function" ? refinementData(val, ctx) : refinementData);
672
+ return false;
673
+ } else return true;
674
+ });
675
+ }
676
+ _refinement(refinement) {
677
+ return new ZodEffects({
678
+ schema: this,
679
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
680
+ effect: {
681
+ type: "refinement",
682
+ refinement
683
+ }
684
+ });
685
+ }
686
+ superRefine(refinement) {
687
+ return this._refinement(refinement);
688
+ }
689
+ constructor(def) {
690
+ /** Alias of safeParseAsync */
691
+ this.spa = this.safeParseAsync;
692
+ this._def = def;
693
+ this.parse = this.parse.bind(this);
694
+ this.safeParse = this.safeParse.bind(this);
695
+ this.parseAsync = this.parseAsync.bind(this);
696
+ this.safeParseAsync = this.safeParseAsync.bind(this);
697
+ this.spa = this.spa.bind(this);
698
+ this.refine = this.refine.bind(this);
699
+ this.refinement = this.refinement.bind(this);
700
+ this.superRefine = this.superRefine.bind(this);
701
+ this.optional = this.optional.bind(this);
702
+ this.nullable = this.nullable.bind(this);
703
+ this.nullish = this.nullish.bind(this);
704
+ this.array = this.array.bind(this);
705
+ this.promise = this.promise.bind(this);
706
+ this.or = this.or.bind(this);
707
+ this.and = this.and.bind(this);
708
+ this.transform = this.transform.bind(this);
709
+ this.brand = this.brand.bind(this);
710
+ this.default = this.default.bind(this);
711
+ this.catch = this.catch.bind(this);
712
+ this.describe = this.describe.bind(this);
713
+ this.pipe = this.pipe.bind(this);
714
+ this.readonly = this.readonly.bind(this);
715
+ this.isNullable = this.isNullable.bind(this);
716
+ this.isOptional = this.isOptional.bind(this);
717
+ this["~standard"] = {
718
+ version: 1,
719
+ vendor: "zod",
720
+ validate: (data) => this["~validate"](data)
721
+ };
722
+ }
723
+ optional() {
724
+ return ZodOptional.create(this, this._def);
725
+ }
726
+ nullable() {
727
+ return ZodNullable.create(this, this._def);
728
+ }
729
+ nullish() {
730
+ return this.nullable().optional();
731
+ }
732
+ array() {
733
+ return ZodArray.create(this);
734
+ }
735
+ promise() {
736
+ return ZodPromise.create(this, this._def);
737
+ }
738
+ or(option) {
739
+ return ZodUnion.create([this, option], this._def);
740
+ }
741
+ and(incoming) {
742
+ return ZodIntersection.create(this, incoming, this._def);
743
+ }
744
+ transform(transform) {
745
+ return new ZodEffects({
746
+ ...processCreateParams(this._def),
747
+ schema: this,
748
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
749
+ effect: {
750
+ type: "transform",
751
+ transform
752
+ }
753
+ });
754
+ }
755
+ default(def) {
756
+ const defaultValueFunc = typeof def === "function" ? def : () => def;
757
+ return new ZodDefault({
758
+ ...processCreateParams(this._def),
759
+ innerType: this,
760
+ defaultValue: defaultValueFunc,
761
+ typeName: ZodFirstPartyTypeKind.ZodDefault
762
+ });
763
+ }
764
+ brand() {
765
+ return new ZodBranded({
766
+ typeName: ZodFirstPartyTypeKind.ZodBranded,
767
+ type: this,
768
+ ...processCreateParams(this._def)
769
+ });
770
+ }
771
+ catch(def) {
772
+ const catchValueFunc = typeof def === "function" ? def : () => def;
773
+ return new ZodCatch({
774
+ ...processCreateParams(this._def),
775
+ innerType: this,
776
+ catchValue: catchValueFunc,
777
+ typeName: ZodFirstPartyTypeKind.ZodCatch
778
+ });
779
+ }
780
+ describe(description) {
781
+ const This = this.constructor;
782
+ return new This({
783
+ ...this._def,
784
+ description
785
+ });
786
+ }
787
+ pipe(target) {
788
+ return ZodPipeline.create(this, target);
789
+ }
790
+ readonly() {
791
+ return ZodReadonly.create(this);
792
+ }
793
+ isOptional() {
794
+ return this.safeParse(void 0).success;
795
+ }
796
+ isNullable() {
797
+ return this.safeParse(null).success;
798
+ }
799
+ };
800
+ const cuidRegex = /^c[^\s-]{8,}$/i;
801
+ const cuid2Regex = /^[0-9a-z]+$/;
802
+ const ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
803
+ 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;
804
+ const nanoidRegex = /^[a-z0-9_-]{21}$/i;
805
+ const jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;
806
+ 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)?)??$/;
807
+ const emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
808
+ const _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
809
+ let emojiRegex$1;
810
+ 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])$/;
811
+ 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])$/;
812
+ 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]))$/;
813
+ 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])$/;
814
+ const base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
815
+ const base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/;
816
+ 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])))`;
817
+ const dateRegex = new RegExp(`^${dateRegexSource}$`);
818
+ function timeRegexSource(args) {
819
+ let secondsRegexSource = `[0-5]\\d`;
820
+ if (args.precision) secondsRegexSource = `${secondsRegexSource}\\.\\d{${args.precision}}`;
821
+ else if (args.precision == null) secondsRegexSource = `${secondsRegexSource}(\\.\\d+)?`;
822
+ const secondsQuantifier = args.precision ? "+" : "?";
823
+ return `([01]\\d|2[0-3]):[0-5]\\d(:${secondsRegexSource})${secondsQuantifier}`;
824
+ }
825
+ function timeRegex(args) {
826
+ return new RegExp(`^${timeRegexSource(args)}$`);
827
+ }
828
+ function datetimeRegex(args) {
829
+ let regex = `${dateRegexSource}T${timeRegexSource(args)}`;
830
+ const opts = [];
831
+ opts.push(args.local ? `Z?` : `Z`);
832
+ if (args.offset) opts.push(`([+-]\\d{2}:?\\d{2})`);
833
+ regex = `${regex}(${opts.join("|")})`;
834
+ return new RegExp(`^${regex}$`);
835
+ }
836
+ function isValidIP(ip, version) {
837
+ if ((version === "v4" || !version) && ipv4Regex.test(ip)) return true;
838
+ if ((version === "v6" || !version) && ipv6Regex.test(ip)) return true;
839
+ return false;
840
+ }
841
+ function isValidJWT(jwt, alg) {
842
+ if (!jwtRegex.test(jwt)) return false;
843
+ try {
844
+ const [header] = jwt.split(".");
845
+ if (!header) return false;
846
+ const base64 = header.replace(/-/g, "+").replace(/_/g, "/").padEnd(header.length + (4 - header.length % 4) % 4, "=");
847
+ const decoded = JSON.parse(atob(base64));
848
+ if (typeof decoded !== "object" || decoded === null) return false;
849
+ if ("typ" in decoded && decoded?.typ !== "JWT") return false;
850
+ if (!decoded.alg) return false;
851
+ if (alg && decoded.alg !== alg) return false;
852
+ return true;
853
+ } catch {
854
+ return false;
855
+ }
856
+ }
857
+ function isValidCidr(ip, version) {
858
+ if ((version === "v4" || !version) && ipv4CidrRegex.test(ip)) return true;
859
+ if ((version === "v6" || !version) && ipv6CidrRegex.test(ip)) return true;
860
+ return false;
861
+ }
862
+ var ZodString = class ZodString extends ZodType {
863
+ _parse(input) {
864
+ if (this._def.coerce) input.data = String(input.data);
865
+ if (this._getType(input) !== ZodParsedType.string) {
866
+ const ctx = this._getOrReturnCtx(input);
867
+ addIssueToContext(ctx, {
868
+ code: ZodIssueCode.invalid_type,
869
+ expected: ZodParsedType.string,
870
+ received: ctx.parsedType
871
+ });
872
+ return INVALID;
873
+ }
874
+ const status = new ParseStatus();
875
+ let ctx = void 0;
876
+ for (const check of this._def.checks) if (check.kind === "min") {
877
+ if (input.data.length < check.value) {
878
+ ctx = this._getOrReturnCtx(input, ctx);
879
+ addIssueToContext(ctx, {
880
+ code: ZodIssueCode.too_small,
881
+ minimum: check.value,
882
+ type: "string",
883
+ inclusive: true,
884
+ exact: false,
885
+ message: check.message
886
+ });
887
+ status.dirty();
888
+ }
889
+ } else if (check.kind === "max") {
890
+ if (input.data.length > check.value) {
891
+ ctx = this._getOrReturnCtx(input, ctx);
892
+ addIssueToContext(ctx, {
893
+ code: ZodIssueCode.too_big,
894
+ maximum: check.value,
895
+ type: "string",
896
+ inclusive: true,
897
+ exact: false,
898
+ message: check.message
899
+ });
900
+ status.dirty();
901
+ }
902
+ } else if (check.kind === "length") {
903
+ const tooBig = input.data.length > check.value;
904
+ const tooSmall = input.data.length < check.value;
905
+ if (tooBig || tooSmall) {
906
+ ctx = this._getOrReturnCtx(input, ctx);
907
+ if (tooBig) addIssueToContext(ctx, {
908
+ code: ZodIssueCode.too_big,
909
+ maximum: check.value,
910
+ type: "string",
911
+ inclusive: true,
912
+ exact: true,
913
+ message: check.message
914
+ });
915
+ else if (tooSmall) addIssueToContext(ctx, {
916
+ code: ZodIssueCode.too_small,
917
+ minimum: check.value,
918
+ type: "string",
919
+ inclusive: true,
920
+ exact: true,
921
+ message: check.message
922
+ });
923
+ status.dirty();
924
+ }
925
+ } else if (check.kind === "email") {
926
+ if (!emailRegex.test(input.data)) {
927
+ ctx = this._getOrReturnCtx(input, ctx);
928
+ addIssueToContext(ctx, {
929
+ validation: "email",
930
+ code: ZodIssueCode.invalid_string,
931
+ message: check.message
932
+ });
933
+ status.dirty();
934
+ }
935
+ } else if (check.kind === "emoji") {
936
+ if (!emojiRegex$1) emojiRegex$1 = new RegExp(_emojiRegex, "u");
937
+ if (!emojiRegex$1.test(input.data)) {
938
+ ctx = this._getOrReturnCtx(input, ctx);
939
+ addIssueToContext(ctx, {
940
+ validation: "emoji",
941
+ code: ZodIssueCode.invalid_string,
942
+ message: check.message
943
+ });
944
+ status.dirty();
945
+ }
946
+ } else if (check.kind === "uuid") {
947
+ if (!uuidRegex.test(input.data)) {
948
+ ctx = this._getOrReturnCtx(input, ctx);
949
+ addIssueToContext(ctx, {
950
+ validation: "uuid",
951
+ code: ZodIssueCode.invalid_string,
952
+ message: check.message
953
+ });
954
+ status.dirty();
955
+ }
956
+ } else if (check.kind === "nanoid") {
957
+ if (!nanoidRegex.test(input.data)) {
958
+ ctx = this._getOrReturnCtx(input, ctx);
959
+ addIssueToContext(ctx, {
960
+ validation: "nanoid",
961
+ code: ZodIssueCode.invalid_string,
962
+ message: check.message
963
+ });
964
+ status.dirty();
965
+ }
966
+ } else if (check.kind === "cuid") {
967
+ if (!cuidRegex.test(input.data)) {
968
+ ctx = this._getOrReturnCtx(input, ctx);
969
+ addIssueToContext(ctx, {
970
+ validation: "cuid",
971
+ code: ZodIssueCode.invalid_string,
972
+ message: check.message
973
+ });
974
+ status.dirty();
975
+ }
976
+ } else if (check.kind === "cuid2") {
977
+ if (!cuid2Regex.test(input.data)) {
978
+ ctx = this._getOrReturnCtx(input, ctx);
979
+ addIssueToContext(ctx, {
980
+ validation: "cuid2",
981
+ code: ZodIssueCode.invalid_string,
982
+ message: check.message
983
+ });
984
+ status.dirty();
985
+ }
986
+ } else if (check.kind === "ulid") {
987
+ if (!ulidRegex.test(input.data)) {
988
+ ctx = this._getOrReturnCtx(input, ctx);
989
+ addIssueToContext(ctx, {
990
+ validation: "ulid",
991
+ code: ZodIssueCode.invalid_string,
992
+ message: check.message
993
+ });
994
+ status.dirty();
995
+ }
996
+ } else if (check.kind === "url") try {
997
+ new URL(input.data);
998
+ } catch {
999
+ ctx = this._getOrReturnCtx(input, ctx);
1000
+ addIssueToContext(ctx, {
1001
+ validation: "url",
1002
+ code: ZodIssueCode.invalid_string,
1003
+ message: check.message
1004
+ });
1005
+ status.dirty();
1006
+ }
1007
+ else if (check.kind === "regex") {
1008
+ check.regex.lastIndex = 0;
1009
+ if (!check.regex.test(input.data)) {
1010
+ ctx = this._getOrReturnCtx(input, ctx);
1011
+ addIssueToContext(ctx, {
1012
+ validation: "regex",
1013
+ code: ZodIssueCode.invalid_string,
1014
+ message: check.message
1015
+ });
1016
+ status.dirty();
1017
+ }
1018
+ } else if (check.kind === "trim") input.data = input.data.trim();
1019
+ else if (check.kind === "includes") {
1020
+ if (!input.data.includes(check.value, check.position)) {
1021
+ ctx = this._getOrReturnCtx(input, ctx);
1022
+ addIssueToContext(ctx, {
1023
+ code: ZodIssueCode.invalid_string,
1024
+ validation: {
1025
+ includes: check.value,
1026
+ position: check.position
1027
+ },
1028
+ message: check.message
1029
+ });
1030
+ status.dirty();
1031
+ }
1032
+ } else if (check.kind === "toLowerCase") input.data = input.data.toLowerCase();
1033
+ else if (check.kind === "toUpperCase") input.data = input.data.toUpperCase();
1034
+ else if (check.kind === "startsWith") {
1035
+ if (!input.data.startsWith(check.value)) {
1036
+ ctx = this._getOrReturnCtx(input, ctx);
1037
+ addIssueToContext(ctx, {
1038
+ code: ZodIssueCode.invalid_string,
1039
+ validation: { startsWith: check.value },
1040
+ message: check.message
1041
+ });
1042
+ status.dirty();
1043
+ }
1044
+ } else if (check.kind === "endsWith") {
1045
+ if (!input.data.endsWith(check.value)) {
1046
+ ctx = this._getOrReturnCtx(input, ctx);
1047
+ addIssueToContext(ctx, {
1048
+ code: ZodIssueCode.invalid_string,
1049
+ validation: { endsWith: check.value },
1050
+ message: check.message
1051
+ });
1052
+ status.dirty();
1053
+ }
1054
+ } else if (check.kind === "datetime") {
1055
+ if (!datetimeRegex(check).test(input.data)) {
1056
+ ctx = this._getOrReturnCtx(input, ctx);
1057
+ addIssueToContext(ctx, {
1058
+ code: ZodIssueCode.invalid_string,
1059
+ validation: "datetime",
1060
+ message: check.message
1061
+ });
1062
+ status.dirty();
1063
+ }
1064
+ } else if (check.kind === "date") {
1065
+ if (!dateRegex.test(input.data)) {
1066
+ ctx = this._getOrReturnCtx(input, ctx);
1067
+ addIssueToContext(ctx, {
1068
+ code: ZodIssueCode.invalid_string,
1069
+ validation: "date",
1070
+ message: check.message
1071
+ });
1072
+ status.dirty();
1073
+ }
1074
+ } else if (check.kind === "time") {
1075
+ if (!timeRegex(check).test(input.data)) {
1076
+ ctx = this._getOrReturnCtx(input, ctx);
1077
+ addIssueToContext(ctx, {
1078
+ code: ZodIssueCode.invalid_string,
1079
+ validation: "time",
1080
+ message: check.message
1081
+ });
1082
+ status.dirty();
1083
+ }
1084
+ } else if (check.kind === "duration") {
1085
+ if (!durationRegex.test(input.data)) {
1086
+ ctx = this._getOrReturnCtx(input, ctx);
1087
+ addIssueToContext(ctx, {
1088
+ validation: "duration",
1089
+ code: ZodIssueCode.invalid_string,
1090
+ message: check.message
1091
+ });
1092
+ status.dirty();
1093
+ }
1094
+ } else if (check.kind === "ip") {
1095
+ if (!isValidIP(input.data, check.version)) {
1096
+ ctx = this._getOrReturnCtx(input, ctx);
1097
+ addIssueToContext(ctx, {
1098
+ validation: "ip",
1099
+ code: ZodIssueCode.invalid_string,
1100
+ message: check.message
1101
+ });
1102
+ status.dirty();
1103
+ }
1104
+ } else if (check.kind === "jwt") {
1105
+ if (!isValidJWT(input.data, check.alg)) {
1106
+ ctx = this._getOrReturnCtx(input, ctx);
1107
+ addIssueToContext(ctx, {
1108
+ validation: "jwt",
1109
+ code: ZodIssueCode.invalid_string,
1110
+ message: check.message
1111
+ });
1112
+ status.dirty();
1113
+ }
1114
+ } else if (check.kind === "cidr") {
1115
+ if (!isValidCidr(input.data, check.version)) {
1116
+ ctx = this._getOrReturnCtx(input, ctx);
1117
+ addIssueToContext(ctx, {
1118
+ validation: "cidr",
1119
+ code: ZodIssueCode.invalid_string,
1120
+ message: check.message
1121
+ });
1122
+ status.dirty();
1123
+ }
1124
+ } else if (check.kind === "base64") {
1125
+ if (!base64Regex.test(input.data)) {
1126
+ ctx = this._getOrReturnCtx(input, ctx);
1127
+ addIssueToContext(ctx, {
1128
+ validation: "base64",
1129
+ code: ZodIssueCode.invalid_string,
1130
+ message: check.message
1131
+ });
1132
+ status.dirty();
1133
+ }
1134
+ } else if (check.kind === "base64url") {
1135
+ if (!base64urlRegex.test(input.data)) {
1136
+ ctx = this._getOrReturnCtx(input, ctx);
1137
+ addIssueToContext(ctx, {
1138
+ validation: "base64url",
1139
+ code: ZodIssueCode.invalid_string,
1140
+ message: check.message
1141
+ });
1142
+ status.dirty();
1143
+ }
1144
+ } else util.assertNever(check);
1145
+ return {
1146
+ status: status.value,
1147
+ value: input.data
1148
+ };
1149
+ }
1150
+ _regex(regex, validation, message) {
1151
+ return this.refinement((data) => regex.test(data), {
1152
+ validation,
1153
+ code: ZodIssueCode.invalid_string,
1154
+ ...errorUtil.errToObj(message)
1155
+ });
1156
+ }
1157
+ _addCheck(check) {
1158
+ return new ZodString({
1159
+ ...this._def,
1160
+ checks: [...this._def.checks, check]
1161
+ });
1162
+ }
1163
+ email(message) {
1164
+ return this._addCheck({
1165
+ kind: "email",
1166
+ ...errorUtil.errToObj(message)
1167
+ });
1168
+ }
1169
+ url(message) {
1170
+ return this._addCheck({
1171
+ kind: "url",
1172
+ ...errorUtil.errToObj(message)
1173
+ });
1174
+ }
1175
+ emoji(message) {
1176
+ return this._addCheck({
1177
+ kind: "emoji",
1178
+ ...errorUtil.errToObj(message)
1179
+ });
1180
+ }
1181
+ uuid(message) {
1182
+ return this._addCheck({
1183
+ kind: "uuid",
1184
+ ...errorUtil.errToObj(message)
1185
+ });
1186
+ }
1187
+ nanoid(message) {
1188
+ return this._addCheck({
1189
+ kind: "nanoid",
1190
+ ...errorUtil.errToObj(message)
1191
+ });
1192
+ }
1193
+ cuid(message) {
1194
+ return this._addCheck({
1195
+ kind: "cuid",
1196
+ ...errorUtil.errToObj(message)
1197
+ });
1198
+ }
1199
+ cuid2(message) {
1200
+ return this._addCheck({
1201
+ kind: "cuid2",
1202
+ ...errorUtil.errToObj(message)
1203
+ });
1204
+ }
1205
+ ulid(message) {
1206
+ return this._addCheck({
1207
+ kind: "ulid",
1208
+ ...errorUtil.errToObj(message)
1209
+ });
1210
+ }
1211
+ base64(message) {
1212
+ return this._addCheck({
1213
+ kind: "base64",
1214
+ ...errorUtil.errToObj(message)
1215
+ });
1216
+ }
1217
+ base64url(message) {
1218
+ return this._addCheck({
1219
+ kind: "base64url",
1220
+ ...errorUtil.errToObj(message)
1221
+ });
1222
+ }
1223
+ jwt(options) {
1224
+ return this._addCheck({
1225
+ kind: "jwt",
1226
+ ...errorUtil.errToObj(options)
1227
+ });
1228
+ }
1229
+ ip(options) {
1230
+ return this._addCheck({
1231
+ kind: "ip",
1232
+ ...errorUtil.errToObj(options)
1233
+ });
1234
+ }
1235
+ cidr(options) {
1236
+ return this._addCheck({
1237
+ kind: "cidr",
1238
+ ...errorUtil.errToObj(options)
1239
+ });
1240
+ }
1241
+ datetime(options) {
1242
+ if (typeof options === "string") return this._addCheck({
1243
+ kind: "datetime",
1244
+ precision: null,
1245
+ offset: false,
1246
+ local: false,
1247
+ message: options
1248
+ });
1249
+ return this._addCheck({
1250
+ kind: "datetime",
1251
+ precision: typeof options?.precision === "undefined" ? null : options?.precision,
1252
+ offset: options?.offset ?? false,
1253
+ local: options?.local ?? false,
1254
+ ...errorUtil.errToObj(options?.message)
1255
+ });
1256
+ }
1257
+ date(message) {
1258
+ return this._addCheck({
1259
+ kind: "date",
1260
+ message
1261
+ });
1262
+ }
1263
+ time(options) {
1264
+ if (typeof options === "string") return this._addCheck({
1265
+ kind: "time",
1266
+ precision: null,
1267
+ message: options
1268
+ });
1269
+ return this._addCheck({
1270
+ kind: "time",
1271
+ precision: typeof options?.precision === "undefined" ? null : options?.precision,
1272
+ ...errorUtil.errToObj(options?.message)
1273
+ });
1274
+ }
1275
+ duration(message) {
1276
+ return this._addCheck({
1277
+ kind: "duration",
1278
+ ...errorUtil.errToObj(message)
1279
+ });
1280
+ }
1281
+ regex(regex, message) {
1282
+ return this._addCheck({
1283
+ kind: "regex",
1284
+ regex,
1285
+ ...errorUtil.errToObj(message)
1286
+ });
1287
+ }
1288
+ includes(value, options) {
1289
+ return this._addCheck({
1290
+ kind: "includes",
1291
+ value,
1292
+ position: options?.position,
1293
+ ...errorUtil.errToObj(options?.message)
1294
+ });
1295
+ }
1296
+ startsWith(value, message) {
1297
+ return this._addCheck({
1298
+ kind: "startsWith",
1299
+ value,
1300
+ ...errorUtil.errToObj(message)
1301
+ });
1302
+ }
1303
+ endsWith(value, message) {
1304
+ return this._addCheck({
1305
+ kind: "endsWith",
1306
+ value,
1307
+ ...errorUtil.errToObj(message)
1308
+ });
1309
+ }
1310
+ min(minLength, message) {
1311
+ return this._addCheck({
1312
+ kind: "min",
1313
+ value: minLength,
1314
+ ...errorUtil.errToObj(message)
1315
+ });
1316
+ }
1317
+ max(maxLength, message) {
1318
+ return this._addCheck({
1319
+ kind: "max",
1320
+ value: maxLength,
1321
+ ...errorUtil.errToObj(message)
1322
+ });
1323
+ }
1324
+ length(len, message) {
1325
+ return this._addCheck({
1326
+ kind: "length",
1327
+ value: len,
1328
+ ...errorUtil.errToObj(message)
1329
+ });
1330
+ }
1331
+ /**
1332
+ * Equivalent to `.min(1)`
1333
+ */
1334
+ nonempty(message) {
1335
+ return this.min(1, errorUtil.errToObj(message));
1336
+ }
1337
+ trim() {
1338
+ return new ZodString({
1339
+ ...this._def,
1340
+ checks: [...this._def.checks, { kind: "trim" }]
1341
+ });
1342
+ }
1343
+ toLowerCase() {
1344
+ return new ZodString({
1345
+ ...this._def,
1346
+ checks: [...this._def.checks, { kind: "toLowerCase" }]
1347
+ });
1348
+ }
1349
+ toUpperCase() {
1350
+ return new ZodString({
1351
+ ...this._def,
1352
+ checks: [...this._def.checks, { kind: "toUpperCase" }]
1353
+ });
1354
+ }
1355
+ get isDatetime() {
1356
+ return !!this._def.checks.find((ch) => ch.kind === "datetime");
1357
+ }
1358
+ get isDate() {
1359
+ return !!this._def.checks.find((ch) => ch.kind === "date");
1360
+ }
1361
+ get isTime() {
1362
+ return !!this._def.checks.find((ch) => ch.kind === "time");
1363
+ }
1364
+ get isDuration() {
1365
+ return !!this._def.checks.find((ch) => ch.kind === "duration");
1366
+ }
1367
+ get isEmail() {
1368
+ return !!this._def.checks.find((ch) => ch.kind === "email");
1369
+ }
1370
+ get isURL() {
1371
+ return !!this._def.checks.find((ch) => ch.kind === "url");
1372
+ }
1373
+ get isEmoji() {
1374
+ return !!this._def.checks.find((ch) => ch.kind === "emoji");
1375
+ }
1376
+ get isUUID() {
1377
+ return !!this._def.checks.find((ch) => ch.kind === "uuid");
1378
+ }
1379
+ get isNANOID() {
1380
+ return !!this._def.checks.find((ch) => ch.kind === "nanoid");
1381
+ }
1382
+ get isCUID() {
1383
+ return !!this._def.checks.find((ch) => ch.kind === "cuid");
1384
+ }
1385
+ get isCUID2() {
1386
+ return !!this._def.checks.find((ch) => ch.kind === "cuid2");
1387
+ }
1388
+ get isULID() {
1389
+ return !!this._def.checks.find((ch) => ch.kind === "ulid");
1390
+ }
1391
+ get isIP() {
1392
+ return !!this._def.checks.find((ch) => ch.kind === "ip");
1393
+ }
1394
+ get isCIDR() {
1395
+ return !!this._def.checks.find((ch) => ch.kind === "cidr");
1396
+ }
1397
+ get isBase64() {
1398
+ return !!this._def.checks.find((ch) => ch.kind === "base64");
1399
+ }
1400
+ get isBase64url() {
1401
+ return !!this._def.checks.find((ch) => ch.kind === "base64url");
1402
+ }
1403
+ get minLength() {
1404
+ let min = null;
1405
+ for (const ch of this._def.checks) if (ch.kind === "min") {
1406
+ if (min === null || ch.value > min) min = ch.value;
1407
+ }
1408
+ return min;
1409
+ }
1410
+ get maxLength() {
1411
+ let max = null;
1412
+ for (const ch of this._def.checks) if (ch.kind === "max") {
1413
+ if (max === null || ch.value < max) max = ch.value;
1414
+ }
1415
+ return max;
1416
+ }
1417
+ };
1418
+ ZodString.create = (params) => {
1419
+ return new ZodString({
1420
+ checks: [],
1421
+ typeName: ZodFirstPartyTypeKind.ZodString,
1422
+ coerce: params?.coerce ?? false,
1423
+ ...processCreateParams(params)
1424
+ });
1425
+ };
1426
+ function floatSafeRemainder(val, step) {
1427
+ const valDecCount = (val.toString().split(".")[1] || "").length;
1428
+ const stepDecCount = (step.toString().split(".")[1] || "").length;
1429
+ const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
1430
+ return Number.parseInt(val.toFixed(decCount).replace(".", "")) % Number.parseInt(step.toFixed(decCount).replace(".", "")) / 10 ** decCount;
1431
+ }
1432
+ var ZodNumber = class ZodNumber extends ZodType {
1433
+ constructor() {
1434
+ super(...arguments);
1435
+ this.min = this.gte;
1436
+ this.max = this.lte;
1437
+ this.step = this.multipleOf;
1438
+ }
1439
+ _parse(input) {
1440
+ if (this._def.coerce) input.data = Number(input.data);
1441
+ if (this._getType(input) !== ZodParsedType.number) {
1442
+ const ctx = this._getOrReturnCtx(input);
1443
+ addIssueToContext(ctx, {
1444
+ code: ZodIssueCode.invalid_type,
1445
+ expected: ZodParsedType.number,
1446
+ received: ctx.parsedType
1447
+ });
1448
+ return INVALID;
1449
+ }
1450
+ let ctx = void 0;
1451
+ const status = new ParseStatus();
1452
+ for (const check of this._def.checks) if (check.kind === "int") {
1453
+ if (!util.isInteger(input.data)) {
1454
+ ctx = this._getOrReturnCtx(input, ctx);
1455
+ addIssueToContext(ctx, {
1456
+ code: ZodIssueCode.invalid_type,
1457
+ expected: "integer",
1458
+ received: "float",
1459
+ message: check.message
1460
+ });
1461
+ status.dirty();
1462
+ }
1463
+ } else if (check.kind === "min") {
1464
+ if (check.inclusive ? input.data < check.value : input.data <= check.value) {
1465
+ ctx = this._getOrReturnCtx(input, ctx);
1466
+ addIssueToContext(ctx, {
1467
+ code: ZodIssueCode.too_small,
1468
+ minimum: check.value,
1469
+ type: "number",
1470
+ inclusive: check.inclusive,
1471
+ exact: false,
1472
+ message: check.message
1473
+ });
1474
+ status.dirty();
1475
+ }
1476
+ } else if (check.kind === "max") {
1477
+ if (check.inclusive ? input.data > check.value : input.data >= check.value) {
1478
+ ctx = this._getOrReturnCtx(input, ctx);
1479
+ addIssueToContext(ctx, {
1480
+ code: ZodIssueCode.too_big,
1481
+ maximum: check.value,
1482
+ type: "number",
1483
+ inclusive: check.inclusive,
1484
+ exact: false,
1485
+ message: check.message
1486
+ });
1487
+ status.dirty();
1488
+ }
1489
+ } else if (check.kind === "multipleOf") {
1490
+ if (floatSafeRemainder(input.data, check.value) !== 0) {
1491
+ ctx = this._getOrReturnCtx(input, ctx);
1492
+ addIssueToContext(ctx, {
1493
+ code: ZodIssueCode.not_multiple_of,
1494
+ multipleOf: check.value,
1495
+ message: check.message
1496
+ });
1497
+ status.dirty();
1498
+ }
1499
+ } else if (check.kind === "finite") {
1500
+ if (!Number.isFinite(input.data)) {
1501
+ ctx = this._getOrReturnCtx(input, ctx);
1502
+ addIssueToContext(ctx, {
1503
+ code: ZodIssueCode.not_finite,
1504
+ message: check.message
1505
+ });
1506
+ status.dirty();
1507
+ }
1508
+ } else util.assertNever(check);
1509
+ return {
1510
+ status: status.value,
1511
+ value: input.data
1512
+ };
1513
+ }
1514
+ gte(value, message) {
1515
+ return this.setLimit("min", value, true, errorUtil.toString(message));
1516
+ }
1517
+ gt(value, message) {
1518
+ return this.setLimit("min", value, false, errorUtil.toString(message));
1519
+ }
1520
+ lte(value, message) {
1521
+ return this.setLimit("max", value, true, errorUtil.toString(message));
1522
+ }
1523
+ lt(value, message) {
1524
+ return this.setLimit("max", value, false, errorUtil.toString(message));
1525
+ }
1526
+ setLimit(kind, value, inclusive, message) {
1527
+ return new ZodNumber({
1528
+ ...this._def,
1529
+ checks: [...this._def.checks, {
1530
+ kind,
1531
+ value,
1532
+ inclusive,
1533
+ message: errorUtil.toString(message)
1534
+ }]
1535
+ });
1536
+ }
1537
+ _addCheck(check) {
1538
+ return new ZodNumber({
1539
+ ...this._def,
1540
+ checks: [...this._def.checks, check]
1541
+ });
1542
+ }
1543
+ int(message) {
1544
+ return this._addCheck({
1545
+ kind: "int",
1546
+ message: errorUtil.toString(message)
1547
+ });
1548
+ }
1549
+ positive(message) {
1550
+ return this._addCheck({
1551
+ kind: "min",
1552
+ value: 0,
1553
+ inclusive: false,
1554
+ message: errorUtil.toString(message)
1555
+ });
1556
+ }
1557
+ negative(message) {
1558
+ return this._addCheck({
1559
+ kind: "max",
1560
+ value: 0,
1561
+ inclusive: false,
1562
+ message: errorUtil.toString(message)
1563
+ });
1564
+ }
1565
+ nonpositive(message) {
1566
+ return this._addCheck({
1567
+ kind: "max",
1568
+ value: 0,
1569
+ inclusive: true,
1570
+ message: errorUtil.toString(message)
1571
+ });
1572
+ }
1573
+ nonnegative(message) {
1574
+ return this._addCheck({
1575
+ kind: "min",
1576
+ value: 0,
1577
+ inclusive: true,
1578
+ message: errorUtil.toString(message)
1579
+ });
1580
+ }
1581
+ multipleOf(value, message) {
1582
+ return this._addCheck({
1583
+ kind: "multipleOf",
1584
+ value,
1585
+ message: errorUtil.toString(message)
1586
+ });
1587
+ }
1588
+ finite(message) {
1589
+ return this._addCheck({
1590
+ kind: "finite",
1591
+ message: errorUtil.toString(message)
1592
+ });
1593
+ }
1594
+ safe(message) {
1595
+ return this._addCheck({
1596
+ kind: "min",
1597
+ inclusive: true,
1598
+ value: Number.MIN_SAFE_INTEGER,
1599
+ message: errorUtil.toString(message)
1600
+ })._addCheck({
1601
+ kind: "max",
1602
+ inclusive: true,
1603
+ value: Number.MAX_SAFE_INTEGER,
1604
+ message: errorUtil.toString(message)
1605
+ });
1606
+ }
1607
+ get minValue() {
1608
+ let min = null;
1609
+ for (const ch of this._def.checks) if (ch.kind === "min") {
1610
+ if (min === null || ch.value > min) min = ch.value;
1611
+ }
1612
+ return min;
1613
+ }
1614
+ get maxValue() {
1615
+ let max = null;
1616
+ for (const ch of this._def.checks) if (ch.kind === "max") {
1617
+ if (max === null || ch.value < max) max = ch.value;
1618
+ }
1619
+ return max;
1620
+ }
1621
+ get isInt() {
1622
+ return !!this._def.checks.find((ch) => ch.kind === "int" || ch.kind === "multipleOf" && util.isInteger(ch.value));
1623
+ }
1624
+ get isFinite() {
1625
+ let max = null;
1626
+ let min = null;
1627
+ for (const ch of this._def.checks) if (ch.kind === "finite" || ch.kind === "int" || ch.kind === "multipleOf") return true;
1628
+ else if (ch.kind === "min") {
1629
+ if (min === null || ch.value > min) min = ch.value;
1630
+ } else if (ch.kind === "max") {
1631
+ if (max === null || ch.value < max) max = ch.value;
1632
+ }
1633
+ return Number.isFinite(min) && Number.isFinite(max);
1634
+ }
1635
+ };
1636
+ ZodNumber.create = (params) => {
1637
+ return new ZodNumber({
1638
+ checks: [],
1639
+ typeName: ZodFirstPartyTypeKind.ZodNumber,
1640
+ coerce: params?.coerce || false,
1641
+ ...processCreateParams(params)
1642
+ });
1643
+ };
1644
+ var ZodBigInt = class ZodBigInt extends ZodType {
1645
+ constructor() {
1646
+ super(...arguments);
1647
+ this.min = this.gte;
1648
+ this.max = this.lte;
1649
+ }
1650
+ _parse(input) {
1651
+ if (this._def.coerce) try {
1652
+ input.data = BigInt(input.data);
1653
+ } catch {
1654
+ return this._getInvalidInput(input);
1655
+ }
1656
+ if (this._getType(input) !== ZodParsedType.bigint) return this._getInvalidInput(input);
1657
+ let ctx = void 0;
1658
+ const status = new ParseStatus();
1659
+ for (const check of this._def.checks) if (check.kind === "min") {
1660
+ if (check.inclusive ? input.data < check.value : input.data <= check.value) {
1661
+ ctx = this._getOrReturnCtx(input, ctx);
1662
+ addIssueToContext(ctx, {
1663
+ code: ZodIssueCode.too_small,
1664
+ type: "bigint",
1665
+ minimum: check.value,
1666
+ inclusive: check.inclusive,
1667
+ message: check.message
1668
+ });
1669
+ status.dirty();
1670
+ }
1671
+ } else if (check.kind === "max") {
1672
+ if (check.inclusive ? input.data > check.value : input.data >= check.value) {
1673
+ ctx = this._getOrReturnCtx(input, ctx);
1674
+ addIssueToContext(ctx, {
1675
+ code: ZodIssueCode.too_big,
1676
+ type: "bigint",
1677
+ maximum: check.value,
1678
+ inclusive: check.inclusive,
1679
+ message: check.message
1680
+ });
1681
+ status.dirty();
1682
+ }
1683
+ } else if (check.kind === "multipleOf") {
1684
+ if (input.data % check.value !== BigInt(0)) {
1685
+ ctx = this._getOrReturnCtx(input, ctx);
1686
+ addIssueToContext(ctx, {
1687
+ code: ZodIssueCode.not_multiple_of,
1688
+ multipleOf: check.value,
1689
+ message: check.message
1690
+ });
1691
+ status.dirty();
1692
+ }
1693
+ } else util.assertNever(check);
1694
+ return {
1695
+ status: status.value,
1696
+ value: input.data
1697
+ };
1698
+ }
1699
+ _getInvalidInput(input) {
1700
+ const ctx = this._getOrReturnCtx(input);
1701
+ addIssueToContext(ctx, {
1702
+ code: ZodIssueCode.invalid_type,
1703
+ expected: ZodParsedType.bigint,
1704
+ received: ctx.parsedType
1705
+ });
1706
+ return INVALID;
1707
+ }
1708
+ gte(value, message) {
1709
+ return this.setLimit("min", value, true, errorUtil.toString(message));
1710
+ }
1711
+ gt(value, message) {
1712
+ return this.setLimit("min", value, false, errorUtil.toString(message));
1713
+ }
1714
+ lte(value, message) {
1715
+ return this.setLimit("max", value, true, errorUtil.toString(message));
1716
+ }
1717
+ lt(value, message) {
1718
+ return this.setLimit("max", value, false, errorUtil.toString(message));
1719
+ }
1720
+ setLimit(kind, value, inclusive, message) {
1721
+ return new ZodBigInt({
1722
+ ...this._def,
1723
+ checks: [...this._def.checks, {
1724
+ kind,
1725
+ value,
1726
+ inclusive,
1727
+ message: errorUtil.toString(message)
1728
+ }]
1729
+ });
1730
+ }
1731
+ _addCheck(check) {
1732
+ return new ZodBigInt({
1733
+ ...this._def,
1734
+ checks: [...this._def.checks, check]
1735
+ });
1736
+ }
1737
+ positive(message) {
1738
+ return this._addCheck({
1739
+ kind: "min",
1740
+ value: BigInt(0),
1741
+ inclusive: false,
1742
+ message: errorUtil.toString(message)
1743
+ });
1744
+ }
1745
+ negative(message) {
1746
+ return this._addCheck({
1747
+ kind: "max",
1748
+ value: BigInt(0),
1749
+ inclusive: false,
1750
+ message: errorUtil.toString(message)
1751
+ });
1752
+ }
1753
+ nonpositive(message) {
1754
+ return this._addCheck({
1755
+ kind: "max",
1756
+ value: BigInt(0),
1757
+ inclusive: true,
1758
+ message: errorUtil.toString(message)
1759
+ });
1760
+ }
1761
+ nonnegative(message) {
1762
+ return this._addCheck({
1763
+ kind: "min",
1764
+ value: BigInt(0),
1765
+ inclusive: true,
1766
+ message: errorUtil.toString(message)
1767
+ });
1768
+ }
1769
+ multipleOf(value, message) {
1770
+ return this._addCheck({
1771
+ kind: "multipleOf",
1772
+ value,
1773
+ message: errorUtil.toString(message)
1774
+ });
1775
+ }
1776
+ get minValue() {
1777
+ let min = null;
1778
+ for (const ch of this._def.checks) if (ch.kind === "min") {
1779
+ if (min === null || ch.value > min) min = ch.value;
1780
+ }
1781
+ return min;
1782
+ }
1783
+ get maxValue() {
1784
+ let max = null;
1785
+ for (const ch of this._def.checks) if (ch.kind === "max") {
1786
+ if (max === null || ch.value < max) max = ch.value;
1787
+ }
1788
+ return max;
1789
+ }
1790
+ };
1791
+ ZodBigInt.create = (params) => {
1792
+ return new ZodBigInt({
1793
+ checks: [],
1794
+ typeName: ZodFirstPartyTypeKind.ZodBigInt,
1795
+ coerce: params?.coerce ?? false,
1796
+ ...processCreateParams(params)
1797
+ });
1798
+ };
1799
+ var ZodBoolean = class extends ZodType {
1800
+ _parse(input) {
1801
+ if (this._def.coerce) input.data = Boolean(input.data);
1802
+ if (this._getType(input) !== ZodParsedType.boolean) {
1803
+ const ctx = this._getOrReturnCtx(input);
1804
+ addIssueToContext(ctx, {
1805
+ code: ZodIssueCode.invalid_type,
1806
+ expected: ZodParsedType.boolean,
1807
+ received: ctx.parsedType
1808
+ });
1809
+ return INVALID;
1810
+ }
1811
+ return OK(input.data);
1812
+ }
1813
+ };
1814
+ ZodBoolean.create = (params) => {
1815
+ return new ZodBoolean({
1816
+ typeName: ZodFirstPartyTypeKind.ZodBoolean,
1817
+ coerce: params?.coerce || false,
1818
+ ...processCreateParams(params)
1819
+ });
1820
+ };
1821
+ var ZodDate = class ZodDate extends ZodType {
1822
+ _parse(input) {
1823
+ if (this._def.coerce) input.data = new Date(input.data);
1824
+ if (this._getType(input) !== ZodParsedType.date) {
1825
+ const ctx = this._getOrReturnCtx(input);
1826
+ addIssueToContext(ctx, {
1827
+ code: ZodIssueCode.invalid_type,
1828
+ expected: ZodParsedType.date,
1829
+ received: ctx.parsedType
1830
+ });
1831
+ return INVALID;
1832
+ }
1833
+ if (Number.isNaN(input.data.getTime())) {
1834
+ addIssueToContext(this._getOrReturnCtx(input), { code: ZodIssueCode.invalid_date });
1835
+ return INVALID;
1836
+ }
1837
+ const status = new ParseStatus();
1838
+ let ctx = void 0;
1839
+ for (const check of this._def.checks) if (check.kind === "min") {
1840
+ if (input.data.getTime() < check.value) {
1841
+ ctx = this._getOrReturnCtx(input, ctx);
1842
+ addIssueToContext(ctx, {
1843
+ code: ZodIssueCode.too_small,
1844
+ message: check.message,
1845
+ inclusive: true,
1846
+ exact: false,
1847
+ minimum: check.value,
1848
+ type: "date"
1849
+ });
1850
+ status.dirty();
1851
+ }
1852
+ } else if (check.kind === "max") {
1853
+ if (input.data.getTime() > check.value) {
1854
+ ctx = this._getOrReturnCtx(input, ctx);
1855
+ addIssueToContext(ctx, {
1856
+ code: ZodIssueCode.too_big,
1857
+ message: check.message,
1858
+ inclusive: true,
1859
+ exact: false,
1860
+ maximum: check.value,
1861
+ type: "date"
1862
+ });
1863
+ status.dirty();
1864
+ }
1865
+ } else util.assertNever(check);
1866
+ return {
1867
+ status: status.value,
1868
+ value: new Date(input.data.getTime())
1869
+ };
1870
+ }
1871
+ _addCheck(check) {
1872
+ return new ZodDate({
1873
+ ...this._def,
1874
+ checks: [...this._def.checks, check]
1875
+ });
1876
+ }
1877
+ min(minDate, message) {
1878
+ return this._addCheck({
1879
+ kind: "min",
1880
+ value: minDate.getTime(),
1881
+ message: errorUtil.toString(message)
1882
+ });
1883
+ }
1884
+ max(maxDate, message) {
1885
+ return this._addCheck({
1886
+ kind: "max",
1887
+ value: maxDate.getTime(),
1888
+ message: errorUtil.toString(message)
1889
+ });
1890
+ }
1891
+ get minDate() {
1892
+ let min = null;
1893
+ for (const ch of this._def.checks) if (ch.kind === "min") {
1894
+ if (min === null || ch.value > min) min = ch.value;
1895
+ }
1896
+ return min != null ? new Date(min) : null;
1897
+ }
1898
+ get maxDate() {
1899
+ let max = null;
1900
+ for (const ch of this._def.checks) if (ch.kind === "max") {
1901
+ if (max === null || ch.value < max) max = ch.value;
1902
+ }
1903
+ return max != null ? new Date(max) : null;
1904
+ }
1905
+ };
1906
+ ZodDate.create = (params) => {
1907
+ return new ZodDate({
1908
+ checks: [],
1909
+ coerce: params?.coerce || false,
1910
+ typeName: ZodFirstPartyTypeKind.ZodDate,
1911
+ ...processCreateParams(params)
1912
+ });
1913
+ };
1914
+ var ZodSymbol = class extends ZodType {
1915
+ _parse(input) {
1916
+ if (this._getType(input) !== ZodParsedType.symbol) {
1917
+ const ctx = this._getOrReturnCtx(input);
1918
+ addIssueToContext(ctx, {
1919
+ code: ZodIssueCode.invalid_type,
1920
+ expected: ZodParsedType.symbol,
1921
+ received: ctx.parsedType
1922
+ });
1923
+ return INVALID;
1924
+ }
1925
+ return OK(input.data);
1926
+ }
1927
+ };
1928
+ ZodSymbol.create = (params) => {
1929
+ return new ZodSymbol({
1930
+ typeName: ZodFirstPartyTypeKind.ZodSymbol,
1931
+ ...processCreateParams(params)
1932
+ });
1933
+ };
1934
+ var ZodUndefined = class extends ZodType {
1935
+ _parse(input) {
1936
+ if (this._getType(input) !== ZodParsedType.undefined) {
1937
+ const ctx = this._getOrReturnCtx(input);
1938
+ addIssueToContext(ctx, {
1939
+ code: ZodIssueCode.invalid_type,
1940
+ expected: ZodParsedType.undefined,
1941
+ received: ctx.parsedType
1942
+ });
1943
+ return INVALID;
1944
+ }
1945
+ return OK(input.data);
1946
+ }
1947
+ };
1948
+ ZodUndefined.create = (params) => {
1949
+ return new ZodUndefined({
1950
+ typeName: ZodFirstPartyTypeKind.ZodUndefined,
1951
+ ...processCreateParams(params)
1952
+ });
1953
+ };
1954
+ var ZodNull = class extends ZodType {
1955
+ _parse(input) {
1956
+ if (this._getType(input) !== ZodParsedType.null) {
1957
+ const ctx = this._getOrReturnCtx(input);
1958
+ addIssueToContext(ctx, {
1959
+ code: ZodIssueCode.invalid_type,
1960
+ expected: ZodParsedType.null,
1961
+ received: ctx.parsedType
1962
+ });
1963
+ return INVALID;
1964
+ }
1965
+ return OK(input.data);
1966
+ }
1967
+ };
1968
+ ZodNull.create = (params) => {
1969
+ return new ZodNull({
1970
+ typeName: ZodFirstPartyTypeKind.ZodNull,
1971
+ ...processCreateParams(params)
1972
+ });
1973
+ };
1974
+ var ZodAny = class extends ZodType {
1975
+ constructor() {
1976
+ super(...arguments);
1977
+ this._any = true;
1978
+ }
1979
+ _parse(input) {
1980
+ return OK(input.data);
1981
+ }
1982
+ };
1983
+ ZodAny.create = (params) => {
1984
+ return new ZodAny({
1985
+ typeName: ZodFirstPartyTypeKind.ZodAny,
1986
+ ...processCreateParams(params)
1987
+ });
1988
+ };
1989
+ var ZodUnknown = class extends ZodType {
1990
+ constructor() {
1991
+ super(...arguments);
1992
+ this._unknown = true;
1993
+ }
1994
+ _parse(input) {
1995
+ return OK(input.data);
1996
+ }
1997
+ };
1998
+ ZodUnknown.create = (params) => {
1999
+ return new ZodUnknown({
2000
+ typeName: ZodFirstPartyTypeKind.ZodUnknown,
2001
+ ...processCreateParams(params)
2002
+ });
2003
+ };
2004
+ var ZodNever = class extends ZodType {
2005
+ _parse(input) {
2006
+ const ctx = this._getOrReturnCtx(input);
2007
+ addIssueToContext(ctx, {
2008
+ code: ZodIssueCode.invalid_type,
2009
+ expected: ZodParsedType.never,
2010
+ received: ctx.parsedType
2011
+ });
2012
+ return INVALID;
2013
+ }
2014
+ };
2015
+ ZodNever.create = (params) => {
2016
+ return new ZodNever({
2017
+ typeName: ZodFirstPartyTypeKind.ZodNever,
2018
+ ...processCreateParams(params)
2019
+ });
2020
+ };
2021
+ var ZodVoid = class extends ZodType {
2022
+ _parse(input) {
2023
+ if (this._getType(input) !== ZodParsedType.undefined) {
2024
+ const ctx = this._getOrReturnCtx(input);
2025
+ addIssueToContext(ctx, {
2026
+ code: ZodIssueCode.invalid_type,
2027
+ expected: ZodParsedType.void,
2028
+ received: ctx.parsedType
2029
+ });
2030
+ return INVALID;
2031
+ }
2032
+ return OK(input.data);
2033
+ }
2034
+ };
2035
+ ZodVoid.create = (params) => {
2036
+ return new ZodVoid({
2037
+ typeName: ZodFirstPartyTypeKind.ZodVoid,
2038
+ ...processCreateParams(params)
2039
+ });
2040
+ };
2041
+ var ZodArray = class ZodArray extends ZodType {
2042
+ _parse(input) {
2043
+ const { ctx, status } = this._processInputParams(input);
2044
+ const def = this._def;
2045
+ if (ctx.parsedType !== ZodParsedType.array) {
2046
+ addIssueToContext(ctx, {
2047
+ code: ZodIssueCode.invalid_type,
2048
+ expected: ZodParsedType.array,
2049
+ received: ctx.parsedType
2050
+ });
2051
+ return INVALID;
2052
+ }
2053
+ if (def.exactLength !== null) {
2054
+ const tooBig = ctx.data.length > def.exactLength.value;
2055
+ const tooSmall = ctx.data.length < def.exactLength.value;
2056
+ if (tooBig || tooSmall) {
2057
+ addIssueToContext(ctx, {
2058
+ code: tooBig ? ZodIssueCode.too_big : ZodIssueCode.too_small,
2059
+ minimum: tooSmall ? def.exactLength.value : void 0,
2060
+ maximum: tooBig ? def.exactLength.value : void 0,
2061
+ type: "array",
2062
+ inclusive: true,
2063
+ exact: true,
2064
+ message: def.exactLength.message
2065
+ });
2066
+ status.dirty();
2067
+ }
2068
+ }
2069
+ if (def.minLength !== null) {
2070
+ if (ctx.data.length < def.minLength.value) {
2071
+ addIssueToContext(ctx, {
2072
+ code: ZodIssueCode.too_small,
2073
+ minimum: def.minLength.value,
2074
+ type: "array",
2075
+ inclusive: true,
2076
+ exact: false,
2077
+ message: def.minLength.message
2078
+ });
2079
+ status.dirty();
2080
+ }
2081
+ }
2082
+ if (def.maxLength !== null) {
2083
+ if (ctx.data.length > def.maxLength.value) {
2084
+ addIssueToContext(ctx, {
2085
+ code: ZodIssueCode.too_big,
2086
+ maximum: def.maxLength.value,
2087
+ type: "array",
2088
+ inclusive: true,
2089
+ exact: false,
2090
+ message: def.maxLength.message
2091
+ });
2092
+ status.dirty();
2093
+ }
2094
+ }
2095
+ if (ctx.common.async) return Promise.all([...ctx.data].map((item, i) => {
2096
+ return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i));
2097
+ })).then((result) => {
2098
+ return ParseStatus.mergeArray(status, result);
2099
+ });
2100
+ const result = [...ctx.data].map((item, i) => {
2101
+ return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i));
2102
+ });
2103
+ return ParseStatus.mergeArray(status, result);
2104
+ }
2105
+ get element() {
2106
+ return this._def.type;
2107
+ }
2108
+ min(minLength, message) {
2109
+ return new ZodArray({
2110
+ ...this._def,
2111
+ minLength: {
2112
+ value: minLength,
2113
+ message: errorUtil.toString(message)
2114
+ }
2115
+ });
2116
+ }
2117
+ max(maxLength, message) {
2118
+ return new ZodArray({
2119
+ ...this._def,
2120
+ maxLength: {
2121
+ value: maxLength,
2122
+ message: errorUtil.toString(message)
2123
+ }
2124
+ });
2125
+ }
2126
+ length(len, message) {
2127
+ return new ZodArray({
2128
+ ...this._def,
2129
+ exactLength: {
2130
+ value: len,
2131
+ message: errorUtil.toString(message)
2132
+ }
2133
+ });
2134
+ }
2135
+ nonempty(message) {
2136
+ return this.min(1, message);
2137
+ }
2138
+ };
2139
+ ZodArray.create = (schema, params) => {
2140
+ return new ZodArray({
2141
+ type: schema,
2142
+ minLength: null,
2143
+ maxLength: null,
2144
+ exactLength: null,
2145
+ typeName: ZodFirstPartyTypeKind.ZodArray,
2146
+ ...processCreateParams(params)
2147
+ });
2148
+ };
2149
+ function deepPartialify(schema) {
2150
+ if (schema instanceof ZodObject) {
2151
+ const newShape = {};
2152
+ for (const key in schema.shape) {
2153
+ const fieldSchema = schema.shape[key];
2154
+ newShape[key] = ZodOptional.create(deepPartialify(fieldSchema));
2155
+ }
2156
+ return new ZodObject({
2157
+ ...schema._def,
2158
+ shape: () => newShape
2159
+ });
2160
+ } else if (schema instanceof ZodArray) return new ZodArray({
2161
+ ...schema._def,
2162
+ type: deepPartialify(schema.element)
2163
+ });
2164
+ else if (schema instanceof ZodOptional) return ZodOptional.create(deepPartialify(schema.unwrap()));
2165
+ else if (schema instanceof ZodNullable) return ZodNullable.create(deepPartialify(schema.unwrap()));
2166
+ else if (schema instanceof ZodTuple) return ZodTuple.create(schema.items.map((item) => deepPartialify(item)));
2167
+ else return schema;
2168
+ }
2169
+ var ZodObject = class ZodObject extends ZodType {
2170
+ constructor() {
2171
+ super(...arguments);
2172
+ this._cached = null;
2173
+ /**
2174
+ * @deprecated In most cases, this is no longer needed - unknown properties are now silently stripped.
2175
+ * If you want to pass through unknown properties, use `.passthrough()` instead.
2176
+ */
2177
+ this.nonstrict = this.passthrough;
2178
+ /**
2179
+ * @deprecated Use `.extend` instead
2180
+ * */
2181
+ this.augment = this.extend;
2182
+ }
2183
+ _getCached() {
2184
+ if (this._cached !== null) return this._cached;
2185
+ const shape = this._def.shape();
2186
+ const keys = util.objectKeys(shape);
2187
+ this._cached = {
2188
+ shape,
2189
+ keys
2190
+ };
2191
+ return this._cached;
2192
+ }
2193
+ _parse(input) {
2194
+ if (this._getType(input) !== ZodParsedType.object) {
2195
+ const ctx = this._getOrReturnCtx(input);
2196
+ addIssueToContext(ctx, {
2197
+ code: ZodIssueCode.invalid_type,
2198
+ expected: ZodParsedType.object,
2199
+ received: ctx.parsedType
2200
+ });
2201
+ return INVALID;
2202
+ }
2203
+ const { status, ctx } = this._processInputParams(input);
2204
+ const { shape, keys: shapeKeys } = this._getCached();
2205
+ const extraKeys = [];
2206
+ if (!(this._def.catchall instanceof ZodNever && this._def.unknownKeys === "strip")) {
2207
+ for (const key in ctx.data) if (!shapeKeys.includes(key)) extraKeys.push(key);
2208
+ }
2209
+ const pairs = [];
2210
+ for (const key of shapeKeys) {
2211
+ const keyValidator = shape[key];
2212
+ const value = ctx.data[key];
2213
+ pairs.push({
2214
+ key: {
2215
+ status: "valid",
2216
+ value: key
2217
+ },
2218
+ value: keyValidator._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
2219
+ alwaysSet: key in ctx.data
2220
+ });
2221
+ }
2222
+ if (this._def.catchall instanceof ZodNever) {
2223
+ const unknownKeys = this._def.unknownKeys;
2224
+ if (unknownKeys === "passthrough") for (const key of extraKeys) pairs.push({
2225
+ key: {
2226
+ status: "valid",
2227
+ value: key
2228
+ },
2229
+ value: {
2230
+ status: "valid",
2231
+ value: ctx.data[key]
2232
+ }
2233
+ });
2234
+ else if (unknownKeys === "strict") {
2235
+ if (extraKeys.length > 0) {
2236
+ addIssueToContext(ctx, {
2237
+ code: ZodIssueCode.unrecognized_keys,
2238
+ keys: extraKeys
2239
+ });
2240
+ status.dirty();
2241
+ }
2242
+ } else if (unknownKeys === "strip") {} else throw new Error(`Internal ZodObject error: invalid unknownKeys value.`);
2243
+ } else {
2244
+ const catchall = this._def.catchall;
2245
+ for (const key of extraKeys) {
2246
+ const value = ctx.data[key];
2247
+ pairs.push({
2248
+ key: {
2249
+ status: "valid",
2250
+ value: key
2251
+ },
2252
+ value: catchall._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
2253
+ alwaysSet: key in ctx.data
2254
+ });
2255
+ }
2256
+ }
2257
+ if (ctx.common.async) return Promise.resolve().then(async () => {
2258
+ const syncPairs = [];
2259
+ for (const pair of pairs) {
2260
+ const key = await pair.key;
2261
+ const value = await pair.value;
2262
+ syncPairs.push({
2263
+ key,
2264
+ value,
2265
+ alwaysSet: pair.alwaysSet
2266
+ });
2267
+ }
2268
+ return syncPairs;
2269
+ }).then((syncPairs) => {
2270
+ return ParseStatus.mergeObjectSync(status, syncPairs);
2271
+ });
2272
+ else return ParseStatus.mergeObjectSync(status, pairs);
2273
+ }
2274
+ get shape() {
2275
+ return this._def.shape();
2276
+ }
2277
+ strict(message) {
2278
+ errorUtil.errToObj;
2279
+ return new ZodObject({
2280
+ ...this._def,
2281
+ unknownKeys: "strict",
2282
+ ...message !== void 0 ? { errorMap: (issue, ctx) => {
2283
+ const defaultError = this._def.errorMap?.(issue, ctx).message ?? ctx.defaultError;
2284
+ if (issue.code === "unrecognized_keys") return { message: errorUtil.errToObj(message).message ?? defaultError };
2285
+ return { message: defaultError };
2286
+ } } : {}
2287
+ });
2288
+ }
2289
+ strip() {
2290
+ return new ZodObject({
2291
+ ...this._def,
2292
+ unknownKeys: "strip"
2293
+ });
2294
+ }
2295
+ passthrough() {
2296
+ return new ZodObject({
2297
+ ...this._def,
2298
+ unknownKeys: "passthrough"
2299
+ });
2300
+ }
2301
+ extend(augmentation) {
2302
+ return new ZodObject({
2303
+ ...this._def,
2304
+ shape: () => ({
2305
+ ...this._def.shape(),
2306
+ ...augmentation
2307
+ })
2308
+ });
2309
+ }
2310
+ /**
2311
+ * Prior to zod@1.0.12 there was a bug in the
2312
+ * inferred type of merged objects. Please
2313
+ * upgrade if you are experiencing issues.
2314
+ */
2315
+ merge(merging) {
2316
+ return new ZodObject({
2317
+ unknownKeys: merging._def.unknownKeys,
2318
+ catchall: merging._def.catchall,
2319
+ shape: () => ({
2320
+ ...this._def.shape(),
2321
+ ...merging._def.shape()
2322
+ }),
2323
+ typeName: ZodFirstPartyTypeKind.ZodObject
2324
+ });
2325
+ }
2326
+ setKey(key, schema) {
2327
+ return this.augment({ [key]: schema });
2328
+ }
2329
+ catchall(index) {
2330
+ return new ZodObject({
2331
+ ...this._def,
2332
+ catchall: index
2333
+ });
2334
+ }
2335
+ pick(mask) {
2336
+ const shape = {};
2337
+ for (const key of util.objectKeys(mask)) if (mask[key] && this.shape[key]) shape[key] = this.shape[key];
2338
+ return new ZodObject({
2339
+ ...this._def,
2340
+ shape: () => shape
2341
+ });
2342
+ }
2343
+ omit(mask) {
2344
+ const shape = {};
2345
+ for (const key of util.objectKeys(this.shape)) if (!mask[key]) shape[key] = this.shape[key];
2346
+ return new ZodObject({
2347
+ ...this._def,
2348
+ shape: () => shape
2349
+ });
2350
+ }
2351
+ /**
2352
+ * @deprecated
2353
+ */
2354
+ deepPartial() {
2355
+ return deepPartialify(this);
2356
+ }
2357
+ partial(mask) {
2358
+ const newShape = {};
2359
+ for (const key of util.objectKeys(this.shape)) {
2360
+ const fieldSchema = this.shape[key];
2361
+ if (mask && !mask[key]) newShape[key] = fieldSchema;
2362
+ else newShape[key] = fieldSchema.optional();
2363
+ }
2364
+ return new ZodObject({
2365
+ ...this._def,
2366
+ shape: () => newShape
2367
+ });
2368
+ }
2369
+ required(mask) {
2370
+ const newShape = {};
2371
+ for (const key of util.objectKeys(this.shape)) if (mask && !mask[key]) newShape[key] = this.shape[key];
2372
+ else {
2373
+ let newField = this.shape[key];
2374
+ while (newField instanceof ZodOptional) newField = newField._def.innerType;
2375
+ newShape[key] = newField;
2376
+ }
2377
+ return new ZodObject({
2378
+ ...this._def,
2379
+ shape: () => newShape
2380
+ });
2381
+ }
2382
+ keyof() {
2383
+ return createZodEnum(util.objectKeys(this.shape));
2384
+ }
2385
+ };
2386
+ ZodObject.create = (shape, params) => {
2387
+ return new ZodObject({
2388
+ shape: () => shape,
2389
+ unknownKeys: "strip",
2390
+ catchall: ZodNever.create(),
2391
+ typeName: ZodFirstPartyTypeKind.ZodObject,
2392
+ ...processCreateParams(params)
2393
+ });
2394
+ };
2395
+ ZodObject.strictCreate = (shape, params) => {
2396
+ return new ZodObject({
2397
+ shape: () => shape,
2398
+ unknownKeys: "strict",
2399
+ catchall: ZodNever.create(),
2400
+ typeName: ZodFirstPartyTypeKind.ZodObject,
2401
+ ...processCreateParams(params)
2402
+ });
2403
+ };
2404
+ ZodObject.lazycreate = (shape, params) => {
2405
+ return new ZodObject({
2406
+ shape,
2407
+ unknownKeys: "strip",
2408
+ catchall: ZodNever.create(),
2409
+ typeName: ZodFirstPartyTypeKind.ZodObject,
2410
+ ...processCreateParams(params)
2411
+ });
2412
+ };
2413
+ var ZodUnion = class extends ZodType {
2414
+ _parse(input) {
2415
+ const { ctx } = this._processInputParams(input);
2416
+ const options = this._def.options;
2417
+ function handleResults(results) {
2418
+ for (const result of results) if (result.result.status === "valid") return result.result;
2419
+ for (const result of results) if (result.result.status === "dirty") {
2420
+ ctx.common.issues.push(...result.ctx.common.issues);
2421
+ return result.result;
2422
+ }
2423
+ const unionErrors = results.map((result) => new ZodError(result.ctx.common.issues));
2424
+ addIssueToContext(ctx, {
2425
+ code: ZodIssueCode.invalid_union,
2426
+ unionErrors
2427
+ });
2428
+ return INVALID;
2429
+ }
2430
+ if (ctx.common.async) return Promise.all(options.map(async (option) => {
2431
+ const childCtx = {
2432
+ ...ctx,
2433
+ common: {
2434
+ ...ctx.common,
2435
+ issues: []
2436
+ },
2437
+ parent: null
2438
+ };
2439
+ return {
2440
+ result: await option._parseAsync({
2441
+ data: ctx.data,
2442
+ path: ctx.path,
2443
+ parent: childCtx
2444
+ }),
2445
+ ctx: childCtx
2446
+ };
2447
+ })).then(handleResults);
2448
+ else {
2449
+ let dirty = void 0;
2450
+ const issues = [];
2451
+ for (const option of options) {
2452
+ const childCtx = {
2453
+ ...ctx,
2454
+ common: {
2455
+ ...ctx.common,
2456
+ issues: []
2457
+ },
2458
+ parent: null
2459
+ };
2460
+ const result = option._parseSync({
2461
+ data: ctx.data,
2462
+ path: ctx.path,
2463
+ parent: childCtx
2464
+ });
2465
+ if (result.status === "valid") return result;
2466
+ else if (result.status === "dirty" && !dirty) dirty = {
2467
+ result,
2468
+ ctx: childCtx
2469
+ };
2470
+ if (childCtx.common.issues.length) issues.push(childCtx.common.issues);
2471
+ }
2472
+ if (dirty) {
2473
+ ctx.common.issues.push(...dirty.ctx.common.issues);
2474
+ return dirty.result;
2475
+ }
2476
+ const unionErrors = issues.map((issues) => new ZodError(issues));
2477
+ addIssueToContext(ctx, {
2478
+ code: ZodIssueCode.invalid_union,
2479
+ unionErrors
2480
+ });
2481
+ return INVALID;
2482
+ }
2483
+ }
2484
+ get options() {
2485
+ return this._def.options;
2486
+ }
2487
+ };
2488
+ ZodUnion.create = (types, params) => {
2489
+ return new ZodUnion({
2490
+ options: types,
2491
+ typeName: ZodFirstPartyTypeKind.ZodUnion,
2492
+ ...processCreateParams(params)
2493
+ });
2494
+ };
2495
+ const getDiscriminator = (type) => {
2496
+ if (type instanceof ZodLazy) return getDiscriminator(type.schema);
2497
+ else if (type instanceof ZodEffects) return getDiscriminator(type.innerType());
2498
+ else if (type instanceof ZodLiteral) return [type.value];
2499
+ else if (type instanceof ZodEnum) return type.options;
2500
+ else if (type instanceof ZodNativeEnum) return util.objectValues(type.enum);
2501
+ else if (type instanceof ZodDefault) return getDiscriminator(type._def.innerType);
2502
+ else if (type instanceof ZodUndefined) return [void 0];
2503
+ else if (type instanceof ZodNull) return [null];
2504
+ else if (type instanceof ZodOptional) return [void 0, ...getDiscriminator(type.unwrap())];
2505
+ else if (type instanceof ZodNullable) return [null, ...getDiscriminator(type.unwrap())];
2506
+ else if (type instanceof ZodBranded) return getDiscriminator(type.unwrap());
2507
+ else if (type instanceof ZodReadonly) return getDiscriminator(type.unwrap());
2508
+ else if (type instanceof ZodCatch) return getDiscriminator(type._def.innerType);
2509
+ else return [];
2510
+ };
2511
+ var ZodDiscriminatedUnion = class ZodDiscriminatedUnion extends ZodType {
2512
+ _parse(input) {
2513
+ const { ctx } = this._processInputParams(input);
2514
+ if (ctx.parsedType !== ZodParsedType.object) {
2515
+ addIssueToContext(ctx, {
2516
+ code: ZodIssueCode.invalid_type,
2517
+ expected: ZodParsedType.object,
2518
+ received: ctx.parsedType
2519
+ });
2520
+ return INVALID;
2521
+ }
2522
+ const discriminator = this.discriminator;
2523
+ const discriminatorValue = ctx.data[discriminator];
2524
+ const option = this.optionsMap.get(discriminatorValue);
2525
+ if (!option) {
2526
+ addIssueToContext(ctx, {
2527
+ code: ZodIssueCode.invalid_union_discriminator,
2528
+ options: Array.from(this.optionsMap.keys()),
2529
+ path: [discriminator]
2530
+ });
2531
+ return INVALID;
2532
+ }
2533
+ if (ctx.common.async) return option._parseAsync({
2534
+ data: ctx.data,
2535
+ path: ctx.path,
2536
+ parent: ctx
2537
+ });
2538
+ else return option._parseSync({
2539
+ data: ctx.data,
2540
+ path: ctx.path,
2541
+ parent: ctx
2542
+ });
2543
+ }
2544
+ get discriminator() {
2545
+ return this._def.discriminator;
2546
+ }
2547
+ get options() {
2548
+ return this._def.options;
2549
+ }
2550
+ get optionsMap() {
2551
+ return this._def.optionsMap;
2552
+ }
2553
+ /**
2554
+ * The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
2555
+ * However, it only allows a union of objects, all of which need to share a discriminator property. This property must
2556
+ * have a different value for each object in the union.
2557
+ * @param discriminator the name of the discriminator property
2558
+ * @param types an array of object schemas
2559
+ * @param params
2560
+ */
2561
+ static create(discriminator, options, params) {
2562
+ const optionsMap = /* @__PURE__ */ new Map();
2563
+ for (const type of options) {
2564
+ const discriminatorValues = getDiscriminator(type.shape[discriminator]);
2565
+ if (!discriminatorValues.length) throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
2566
+ for (const value of discriminatorValues) {
2567
+ if (optionsMap.has(value)) throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
2568
+ optionsMap.set(value, type);
2569
+ }
2570
+ }
2571
+ return new ZodDiscriminatedUnion({
2572
+ typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
2573
+ discriminator,
2574
+ options,
2575
+ optionsMap,
2576
+ ...processCreateParams(params)
2577
+ });
2578
+ }
2579
+ };
2580
+ function mergeValues(a, b) {
2581
+ const aType = getParsedType(a);
2582
+ const bType = getParsedType(b);
2583
+ if (a === b) return {
2584
+ valid: true,
2585
+ data: a
2586
+ };
2587
+ else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
2588
+ const bKeys = util.objectKeys(b);
2589
+ const sharedKeys = util.objectKeys(a).filter((key) => bKeys.indexOf(key) !== -1);
2590
+ const newObj = {
2591
+ ...a,
2592
+ ...b
2593
+ };
2594
+ for (const key of sharedKeys) {
2595
+ const sharedValue = mergeValues(a[key], b[key]);
2596
+ if (!sharedValue.valid) return { valid: false };
2597
+ newObj[key] = sharedValue.data;
2598
+ }
2599
+ return {
2600
+ valid: true,
2601
+ data: newObj
2602
+ };
2603
+ } else if (aType === ZodParsedType.array && bType === ZodParsedType.array) {
2604
+ if (a.length !== b.length) return { valid: false };
2605
+ const newArray = [];
2606
+ for (let index = 0; index < a.length; index++) {
2607
+ const itemA = a[index];
2608
+ const itemB = b[index];
2609
+ const sharedValue = mergeValues(itemA, itemB);
2610
+ if (!sharedValue.valid) return { valid: false };
2611
+ newArray.push(sharedValue.data);
2612
+ }
2613
+ return {
2614
+ valid: true,
2615
+ data: newArray
2616
+ };
2617
+ } else if (aType === ZodParsedType.date && bType === ZodParsedType.date && +a === +b) return {
2618
+ valid: true,
2619
+ data: a
2620
+ };
2621
+ else return { valid: false };
2622
+ }
2623
+ var ZodIntersection = class extends ZodType {
2624
+ _parse(input) {
2625
+ const { status, ctx } = this._processInputParams(input);
2626
+ const handleParsed = (parsedLeft, parsedRight) => {
2627
+ if (isAborted(parsedLeft) || isAborted(parsedRight)) return INVALID;
2628
+ const merged = mergeValues(parsedLeft.value, parsedRight.value);
2629
+ if (!merged.valid) {
2630
+ addIssueToContext(ctx, { code: ZodIssueCode.invalid_intersection_types });
2631
+ return INVALID;
2632
+ }
2633
+ if (isDirty(parsedLeft) || isDirty(parsedRight)) status.dirty();
2634
+ return {
2635
+ status: status.value,
2636
+ value: merged.data
2637
+ };
2638
+ };
2639
+ if (ctx.common.async) return Promise.all([this._def.left._parseAsync({
2640
+ data: ctx.data,
2641
+ path: ctx.path,
2642
+ parent: ctx
2643
+ }), this._def.right._parseAsync({
2644
+ data: ctx.data,
2645
+ path: ctx.path,
2646
+ parent: ctx
2647
+ })]).then(([left, right]) => handleParsed(left, right));
2648
+ else return handleParsed(this._def.left._parseSync({
2649
+ data: ctx.data,
2650
+ path: ctx.path,
2651
+ parent: ctx
2652
+ }), this._def.right._parseSync({
2653
+ data: ctx.data,
2654
+ path: ctx.path,
2655
+ parent: ctx
2656
+ }));
2657
+ }
2658
+ };
2659
+ ZodIntersection.create = (left, right, params) => {
2660
+ return new ZodIntersection({
2661
+ left,
2662
+ right,
2663
+ typeName: ZodFirstPartyTypeKind.ZodIntersection,
2664
+ ...processCreateParams(params)
2665
+ });
2666
+ };
2667
+ var ZodTuple = class ZodTuple extends ZodType {
2668
+ _parse(input) {
2669
+ const { status, ctx } = this._processInputParams(input);
2670
+ if (ctx.parsedType !== ZodParsedType.array) {
2671
+ addIssueToContext(ctx, {
2672
+ code: ZodIssueCode.invalid_type,
2673
+ expected: ZodParsedType.array,
2674
+ received: ctx.parsedType
2675
+ });
2676
+ return INVALID;
2677
+ }
2678
+ if (ctx.data.length < this._def.items.length) {
2679
+ addIssueToContext(ctx, {
2680
+ code: ZodIssueCode.too_small,
2681
+ minimum: this._def.items.length,
2682
+ inclusive: true,
2683
+ exact: false,
2684
+ type: "array"
2685
+ });
2686
+ return INVALID;
2687
+ }
2688
+ if (!this._def.rest && ctx.data.length > this._def.items.length) {
2689
+ addIssueToContext(ctx, {
2690
+ code: ZodIssueCode.too_big,
2691
+ maximum: this._def.items.length,
2692
+ inclusive: true,
2693
+ exact: false,
2694
+ type: "array"
2695
+ });
2696
+ status.dirty();
2697
+ }
2698
+ const items = [...ctx.data].map((item, itemIndex) => {
2699
+ const schema = this._def.items[itemIndex] || this._def.rest;
2700
+ if (!schema) return null;
2701
+ return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
2702
+ }).filter((x) => !!x);
2703
+ if (ctx.common.async) return Promise.all(items).then((results) => {
2704
+ return ParseStatus.mergeArray(status, results);
2705
+ });
2706
+ else return ParseStatus.mergeArray(status, items);
2707
+ }
2708
+ get items() {
2709
+ return this._def.items;
2710
+ }
2711
+ rest(rest) {
2712
+ return new ZodTuple({
2713
+ ...this._def,
2714
+ rest
2715
+ });
2716
+ }
2717
+ };
2718
+ ZodTuple.create = (schemas, params) => {
2719
+ if (!Array.isArray(schemas)) throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
2720
+ return new ZodTuple({
2721
+ items: schemas,
2722
+ typeName: ZodFirstPartyTypeKind.ZodTuple,
2723
+ rest: null,
2724
+ ...processCreateParams(params)
2725
+ });
2726
+ };
2727
+ var ZodRecord = class ZodRecord extends ZodType {
2728
+ get keySchema() {
2729
+ return this._def.keyType;
2730
+ }
2731
+ get valueSchema() {
2732
+ return this._def.valueType;
2733
+ }
2734
+ _parse(input) {
2735
+ const { status, ctx } = this._processInputParams(input);
2736
+ if (ctx.parsedType !== ZodParsedType.object) {
2737
+ addIssueToContext(ctx, {
2738
+ code: ZodIssueCode.invalid_type,
2739
+ expected: ZodParsedType.object,
2740
+ received: ctx.parsedType
2741
+ });
2742
+ return INVALID;
2743
+ }
2744
+ const pairs = [];
2745
+ const keyType = this._def.keyType;
2746
+ const valueType = this._def.valueType;
2747
+ for (const key in ctx.data) pairs.push({
2748
+ key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
2749
+ value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
2750
+ alwaysSet: key in ctx.data
2751
+ });
2752
+ if (ctx.common.async) return ParseStatus.mergeObjectAsync(status, pairs);
2753
+ else return ParseStatus.mergeObjectSync(status, pairs);
2754
+ }
2755
+ get element() {
2756
+ return this._def.valueType;
2757
+ }
2758
+ static create(first, second, third) {
2759
+ if (second instanceof ZodType) return new ZodRecord({
2760
+ keyType: first,
2761
+ valueType: second,
2762
+ typeName: ZodFirstPartyTypeKind.ZodRecord,
2763
+ ...processCreateParams(third)
2764
+ });
2765
+ return new ZodRecord({
2766
+ keyType: ZodString.create(),
2767
+ valueType: first,
2768
+ typeName: ZodFirstPartyTypeKind.ZodRecord,
2769
+ ...processCreateParams(second)
2770
+ });
2771
+ }
2772
+ };
2773
+ var ZodMap = class extends ZodType {
2774
+ get keySchema() {
2775
+ return this._def.keyType;
2776
+ }
2777
+ get valueSchema() {
2778
+ return this._def.valueType;
2779
+ }
2780
+ _parse(input) {
2781
+ const { status, ctx } = this._processInputParams(input);
2782
+ if (ctx.parsedType !== ZodParsedType.map) {
2783
+ addIssueToContext(ctx, {
2784
+ code: ZodIssueCode.invalid_type,
2785
+ expected: ZodParsedType.map,
2786
+ received: ctx.parsedType
2787
+ });
2788
+ return INVALID;
2789
+ }
2790
+ const keyType = this._def.keyType;
2791
+ const valueType = this._def.valueType;
2792
+ const pairs = [...ctx.data.entries()].map(([key, value], index) => {
2793
+ return {
2794
+ key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index, "key"])),
2795
+ value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [index, "value"]))
2796
+ };
2797
+ });
2798
+ if (ctx.common.async) {
2799
+ const finalMap = /* @__PURE__ */ new Map();
2800
+ return Promise.resolve().then(async () => {
2801
+ for (const pair of pairs) {
2802
+ const key = await pair.key;
2803
+ const value = await pair.value;
2804
+ if (key.status === "aborted" || value.status === "aborted") return INVALID;
2805
+ if (key.status === "dirty" || value.status === "dirty") status.dirty();
2806
+ finalMap.set(key.value, value.value);
2807
+ }
2808
+ return {
2809
+ status: status.value,
2810
+ value: finalMap
2811
+ };
2812
+ });
2813
+ } else {
2814
+ const finalMap = /* @__PURE__ */ new Map();
2815
+ for (const pair of pairs) {
2816
+ const key = pair.key;
2817
+ const value = pair.value;
2818
+ if (key.status === "aborted" || value.status === "aborted") return INVALID;
2819
+ if (key.status === "dirty" || value.status === "dirty") status.dirty();
2820
+ finalMap.set(key.value, value.value);
2821
+ }
2822
+ return {
2823
+ status: status.value,
2824
+ value: finalMap
2825
+ };
2826
+ }
2827
+ }
2828
+ };
2829
+ ZodMap.create = (keyType, valueType, params) => {
2830
+ return new ZodMap({
2831
+ valueType,
2832
+ keyType,
2833
+ typeName: ZodFirstPartyTypeKind.ZodMap,
2834
+ ...processCreateParams(params)
2835
+ });
2836
+ };
2837
+ var ZodSet = class ZodSet extends ZodType {
2838
+ _parse(input) {
2839
+ const { status, ctx } = this._processInputParams(input);
2840
+ if (ctx.parsedType !== ZodParsedType.set) {
2841
+ addIssueToContext(ctx, {
2842
+ code: ZodIssueCode.invalid_type,
2843
+ expected: ZodParsedType.set,
2844
+ received: ctx.parsedType
2845
+ });
2846
+ return INVALID;
2847
+ }
2848
+ const def = this._def;
2849
+ if (def.minSize !== null) {
2850
+ if (ctx.data.size < def.minSize.value) {
2851
+ addIssueToContext(ctx, {
2852
+ code: ZodIssueCode.too_small,
2853
+ minimum: def.minSize.value,
2854
+ type: "set",
2855
+ inclusive: true,
2856
+ exact: false,
2857
+ message: def.minSize.message
2858
+ });
2859
+ status.dirty();
2860
+ }
2861
+ }
2862
+ if (def.maxSize !== null) {
2863
+ if (ctx.data.size > def.maxSize.value) {
2864
+ addIssueToContext(ctx, {
2865
+ code: ZodIssueCode.too_big,
2866
+ maximum: def.maxSize.value,
2867
+ type: "set",
2868
+ inclusive: true,
2869
+ exact: false,
2870
+ message: def.maxSize.message
2871
+ });
2872
+ status.dirty();
2873
+ }
2874
+ }
2875
+ const valueType = this._def.valueType;
2876
+ function finalizeSet(elements) {
2877
+ const parsedSet = /* @__PURE__ */ new Set();
2878
+ for (const element of elements) {
2879
+ if (element.status === "aborted") return INVALID;
2880
+ if (element.status === "dirty") status.dirty();
2881
+ parsedSet.add(element.value);
2882
+ }
2883
+ return {
2884
+ status: status.value,
2885
+ value: parsedSet
2886
+ };
2887
+ }
2888
+ const elements = [...ctx.data.values()].map((item, i) => valueType._parse(new ParseInputLazyPath(ctx, item, ctx.path, i)));
2889
+ if (ctx.common.async) return Promise.all(elements).then((elements) => finalizeSet(elements));
2890
+ else return finalizeSet(elements);
2891
+ }
2892
+ min(minSize, message) {
2893
+ return new ZodSet({
2894
+ ...this._def,
2895
+ minSize: {
2896
+ value: minSize,
2897
+ message: errorUtil.toString(message)
2898
+ }
2899
+ });
2900
+ }
2901
+ max(maxSize, message) {
2902
+ return new ZodSet({
2903
+ ...this._def,
2904
+ maxSize: {
2905
+ value: maxSize,
2906
+ message: errorUtil.toString(message)
2907
+ }
2908
+ });
2909
+ }
2910
+ size(size, message) {
2911
+ return this.min(size, message).max(size, message);
2912
+ }
2913
+ nonempty(message) {
2914
+ return this.min(1, message);
2915
+ }
2916
+ };
2917
+ ZodSet.create = (valueType, params) => {
2918
+ return new ZodSet({
2919
+ valueType,
2920
+ minSize: null,
2921
+ maxSize: null,
2922
+ typeName: ZodFirstPartyTypeKind.ZodSet,
2923
+ ...processCreateParams(params)
2924
+ });
2925
+ };
2926
+ var ZodFunction = class ZodFunction extends ZodType {
2927
+ constructor() {
2928
+ super(...arguments);
2929
+ this.validate = this.implement;
2930
+ }
2931
+ _parse(input) {
2932
+ const { ctx } = this._processInputParams(input);
2933
+ if (ctx.parsedType !== ZodParsedType.function) {
2934
+ addIssueToContext(ctx, {
2935
+ code: ZodIssueCode.invalid_type,
2936
+ expected: ZodParsedType.function,
2937
+ received: ctx.parsedType
2938
+ });
2939
+ return INVALID;
2940
+ }
2941
+ function makeArgsIssue(args, error) {
2942
+ return makeIssue({
2943
+ data: args,
2944
+ path: ctx.path,
2945
+ errorMaps: [
2946
+ ctx.common.contextualErrorMap,
2947
+ ctx.schemaErrorMap,
2948
+ getErrorMap(),
2949
+ errorMap
2950
+ ].filter((x) => !!x),
2951
+ issueData: {
2952
+ code: ZodIssueCode.invalid_arguments,
2953
+ argumentsError: error
2954
+ }
2955
+ });
2956
+ }
2957
+ function makeReturnsIssue(returns, error) {
2958
+ return makeIssue({
2959
+ data: returns,
2960
+ path: ctx.path,
2961
+ errorMaps: [
2962
+ ctx.common.contextualErrorMap,
2963
+ ctx.schemaErrorMap,
2964
+ getErrorMap(),
2965
+ errorMap
2966
+ ].filter((x) => !!x),
2967
+ issueData: {
2968
+ code: ZodIssueCode.invalid_return_type,
2969
+ returnTypeError: error
2970
+ }
2971
+ });
2972
+ }
2973
+ const params = { errorMap: ctx.common.contextualErrorMap };
2974
+ const fn = ctx.data;
2975
+ if (this._def.returns instanceof ZodPromise) {
2976
+ const me = this;
2977
+ return OK(async function(...args) {
2978
+ const error = new ZodError([]);
2979
+ const parsedArgs = await me._def.args.parseAsync(args, params).catch((e) => {
2980
+ error.addIssue(makeArgsIssue(args, e));
2981
+ throw error;
2982
+ });
2983
+ const result = await Reflect.apply(fn, this, parsedArgs);
2984
+ return await me._def.returns._def.type.parseAsync(result, params).catch((e) => {
2985
+ error.addIssue(makeReturnsIssue(result, e));
2986
+ throw error;
2987
+ });
2988
+ });
2989
+ } else {
2990
+ const me = this;
2991
+ return OK(function(...args) {
2992
+ const parsedArgs = me._def.args.safeParse(args, params);
2993
+ if (!parsedArgs.success) throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
2994
+ const result = Reflect.apply(fn, this, parsedArgs.data);
2995
+ const parsedReturns = me._def.returns.safeParse(result, params);
2996
+ if (!parsedReturns.success) throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
2997
+ return parsedReturns.data;
2998
+ });
2999
+ }
3000
+ }
3001
+ parameters() {
3002
+ return this._def.args;
3003
+ }
3004
+ returnType() {
3005
+ return this._def.returns;
3006
+ }
3007
+ args(...items) {
3008
+ return new ZodFunction({
3009
+ ...this._def,
3010
+ args: ZodTuple.create(items).rest(ZodUnknown.create())
3011
+ });
3012
+ }
3013
+ returns(returnType) {
3014
+ return new ZodFunction({
3015
+ ...this._def,
3016
+ returns: returnType
3017
+ });
3018
+ }
3019
+ implement(func) {
3020
+ return this.parse(func);
3021
+ }
3022
+ strictImplement(func) {
3023
+ return this.parse(func);
3024
+ }
3025
+ static create(args, returns, params) {
3026
+ return new ZodFunction({
3027
+ args: args ? args : ZodTuple.create([]).rest(ZodUnknown.create()),
3028
+ returns: returns || ZodUnknown.create(),
3029
+ typeName: ZodFirstPartyTypeKind.ZodFunction,
3030
+ ...processCreateParams(params)
3031
+ });
3032
+ }
3033
+ };
3034
+ var ZodLazy = class extends ZodType {
3035
+ get schema() {
3036
+ return this._def.getter();
3037
+ }
3038
+ _parse(input) {
3039
+ const { ctx } = this._processInputParams(input);
3040
+ return this._def.getter()._parse({
3041
+ data: ctx.data,
3042
+ path: ctx.path,
3043
+ parent: ctx
3044
+ });
3045
+ }
3046
+ };
3047
+ ZodLazy.create = (getter, params) => {
3048
+ return new ZodLazy({
3049
+ getter,
3050
+ typeName: ZodFirstPartyTypeKind.ZodLazy,
3051
+ ...processCreateParams(params)
3052
+ });
3053
+ };
3054
+ var ZodLiteral = class extends ZodType {
3055
+ _parse(input) {
3056
+ if (input.data !== this._def.value) {
3057
+ const ctx = this._getOrReturnCtx(input);
3058
+ addIssueToContext(ctx, {
3059
+ received: ctx.data,
3060
+ code: ZodIssueCode.invalid_literal,
3061
+ expected: this._def.value
3062
+ });
3063
+ return INVALID;
3064
+ }
3065
+ return {
3066
+ status: "valid",
3067
+ value: input.data
3068
+ };
3069
+ }
3070
+ get value() {
3071
+ return this._def.value;
3072
+ }
3073
+ };
3074
+ ZodLiteral.create = (value, params) => {
3075
+ return new ZodLiteral({
3076
+ value,
3077
+ typeName: ZodFirstPartyTypeKind.ZodLiteral,
3078
+ ...processCreateParams(params)
3079
+ });
3080
+ };
3081
+ function createZodEnum(values, params) {
3082
+ return new ZodEnum({
3083
+ values,
3084
+ typeName: ZodFirstPartyTypeKind.ZodEnum,
3085
+ ...processCreateParams(params)
3086
+ });
3087
+ }
3088
+ var ZodEnum = class ZodEnum extends ZodType {
3089
+ _parse(input) {
3090
+ if (typeof input.data !== "string") {
3091
+ const ctx = this._getOrReturnCtx(input);
3092
+ const expectedValues = this._def.values;
3093
+ addIssueToContext(ctx, {
3094
+ expected: util.joinValues(expectedValues),
3095
+ received: ctx.parsedType,
3096
+ code: ZodIssueCode.invalid_type
3097
+ });
3098
+ return INVALID;
3099
+ }
3100
+ if (!this._cache) this._cache = new Set(this._def.values);
3101
+ if (!this._cache.has(input.data)) {
3102
+ const ctx = this._getOrReturnCtx(input);
3103
+ const expectedValues = this._def.values;
3104
+ addIssueToContext(ctx, {
3105
+ received: ctx.data,
3106
+ code: ZodIssueCode.invalid_enum_value,
3107
+ options: expectedValues
3108
+ });
3109
+ return INVALID;
3110
+ }
3111
+ return OK(input.data);
3112
+ }
3113
+ get options() {
3114
+ return this._def.values;
3115
+ }
3116
+ get enum() {
3117
+ const enumValues = {};
3118
+ for (const val of this._def.values) enumValues[val] = val;
3119
+ return enumValues;
3120
+ }
3121
+ get Values() {
3122
+ const enumValues = {};
3123
+ for (const val of this._def.values) enumValues[val] = val;
3124
+ return enumValues;
3125
+ }
3126
+ get Enum() {
3127
+ const enumValues = {};
3128
+ for (const val of this._def.values) enumValues[val] = val;
3129
+ return enumValues;
3130
+ }
3131
+ extract(values, newDef = this._def) {
3132
+ return ZodEnum.create(values, {
3133
+ ...this._def,
3134
+ ...newDef
3135
+ });
3136
+ }
3137
+ exclude(values, newDef = this._def) {
3138
+ return ZodEnum.create(this.options.filter((opt) => !values.includes(opt)), {
3139
+ ...this._def,
3140
+ ...newDef
3141
+ });
3142
+ }
3143
+ };
3144
+ ZodEnum.create = createZodEnum;
3145
+ var ZodNativeEnum = class extends ZodType {
3146
+ _parse(input) {
3147
+ const nativeEnumValues = util.getValidEnumValues(this._def.values);
3148
+ const ctx = this._getOrReturnCtx(input);
3149
+ if (ctx.parsedType !== ZodParsedType.string && ctx.parsedType !== ZodParsedType.number) {
3150
+ const expectedValues = util.objectValues(nativeEnumValues);
3151
+ addIssueToContext(ctx, {
3152
+ expected: util.joinValues(expectedValues),
3153
+ received: ctx.parsedType,
3154
+ code: ZodIssueCode.invalid_type
3155
+ });
3156
+ return INVALID;
3157
+ }
3158
+ if (!this._cache) this._cache = new Set(util.getValidEnumValues(this._def.values));
3159
+ if (!this._cache.has(input.data)) {
3160
+ const expectedValues = util.objectValues(nativeEnumValues);
3161
+ addIssueToContext(ctx, {
3162
+ received: ctx.data,
3163
+ code: ZodIssueCode.invalid_enum_value,
3164
+ options: expectedValues
3165
+ });
3166
+ return INVALID;
3167
+ }
3168
+ return OK(input.data);
3169
+ }
3170
+ get enum() {
3171
+ return this._def.values;
3172
+ }
3173
+ };
3174
+ ZodNativeEnum.create = (values, params) => {
3175
+ return new ZodNativeEnum({
3176
+ values,
3177
+ typeName: ZodFirstPartyTypeKind.ZodNativeEnum,
3178
+ ...processCreateParams(params)
3179
+ });
3180
+ };
3181
+ var ZodPromise = class extends ZodType {
3182
+ unwrap() {
3183
+ return this._def.type;
3184
+ }
3185
+ _parse(input) {
3186
+ const { ctx } = this._processInputParams(input);
3187
+ if (ctx.parsedType !== ZodParsedType.promise && ctx.common.async === false) {
3188
+ addIssueToContext(ctx, {
3189
+ code: ZodIssueCode.invalid_type,
3190
+ expected: ZodParsedType.promise,
3191
+ received: ctx.parsedType
3192
+ });
3193
+ return INVALID;
3194
+ }
3195
+ return OK((ctx.parsedType === ZodParsedType.promise ? ctx.data : Promise.resolve(ctx.data)).then((data) => {
3196
+ return this._def.type.parseAsync(data, {
3197
+ path: ctx.path,
3198
+ errorMap: ctx.common.contextualErrorMap
3199
+ });
3200
+ }));
3201
+ }
3202
+ };
3203
+ ZodPromise.create = (schema, params) => {
3204
+ return new ZodPromise({
3205
+ type: schema,
3206
+ typeName: ZodFirstPartyTypeKind.ZodPromise,
3207
+ ...processCreateParams(params)
3208
+ });
3209
+ };
3210
+ var ZodEffects = class extends ZodType {
3211
+ innerType() {
3212
+ return this._def.schema;
3213
+ }
3214
+ sourceType() {
3215
+ return this._def.schema._def.typeName === ZodFirstPartyTypeKind.ZodEffects ? this._def.schema.sourceType() : this._def.schema;
3216
+ }
3217
+ _parse(input) {
3218
+ const { status, ctx } = this._processInputParams(input);
3219
+ const effect = this._def.effect || null;
3220
+ const checkCtx = {
3221
+ addIssue: (arg) => {
3222
+ addIssueToContext(ctx, arg);
3223
+ if (arg.fatal) status.abort();
3224
+ else status.dirty();
3225
+ },
3226
+ get path() {
3227
+ return ctx.path;
3228
+ }
3229
+ };
3230
+ checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
3231
+ if (effect.type === "preprocess") {
3232
+ const processed = effect.transform(ctx.data, checkCtx);
3233
+ if (ctx.common.async) return Promise.resolve(processed).then(async (processed) => {
3234
+ if (status.value === "aborted") return INVALID;
3235
+ const result = await this._def.schema._parseAsync({
3236
+ data: processed,
3237
+ path: ctx.path,
3238
+ parent: ctx
3239
+ });
3240
+ if (result.status === "aborted") return INVALID;
3241
+ if (result.status === "dirty") return DIRTY(result.value);
3242
+ if (status.value === "dirty") return DIRTY(result.value);
3243
+ return result;
3244
+ });
3245
+ else {
3246
+ if (status.value === "aborted") return INVALID;
3247
+ const result = this._def.schema._parseSync({
3248
+ data: processed,
3249
+ path: ctx.path,
3250
+ parent: ctx
3251
+ });
3252
+ if (result.status === "aborted") return INVALID;
3253
+ if (result.status === "dirty") return DIRTY(result.value);
3254
+ if (status.value === "dirty") return DIRTY(result.value);
3255
+ return result;
3256
+ }
3257
+ }
3258
+ if (effect.type === "refinement") {
3259
+ const executeRefinement = (acc) => {
3260
+ const result = effect.refinement(acc, checkCtx);
3261
+ if (ctx.common.async) return Promise.resolve(result);
3262
+ if (result instanceof Promise) throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
3263
+ return acc;
3264
+ };
3265
+ if (ctx.common.async === false) {
3266
+ const inner = this._def.schema._parseSync({
3267
+ data: ctx.data,
3268
+ path: ctx.path,
3269
+ parent: ctx
3270
+ });
3271
+ if (inner.status === "aborted") return INVALID;
3272
+ if (inner.status === "dirty") status.dirty();
3273
+ executeRefinement(inner.value);
3274
+ return {
3275
+ status: status.value,
3276
+ value: inner.value
3277
+ };
3278
+ } else return this._def.schema._parseAsync({
3279
+ data: ctx.data,
3280
+ path: ctx.path,
3281
+ parent: ctx
3282
+ }).then((inner) => {
3283
+ if (inner.status === "aborted") return INVALID;
3284
+ if (inner.status === "dirty") status.dirty();
3285
+ return executeRefinement(inner.value).then(() => {
3286
+ return {
3287
+ status: status.value,
3288
+ value: inner.value
3289
+ };
3290
+ });
3291
+ });
3292
+ }
3293
+ if (effect.type === "transform") if (ctx.common.async === false) {
3294
+ const base = this._def.schema._parseSync({
3295
+ data: ctx.data,
3296
+ path: ctx.path,
3297
+ parent: ctx
3298
+ });
3299
+ if (!isValid(base)) return INVALID;
3300
+ const result = effect.transform(base.value, checkCtx);
3301
+ if (result instanceof Promise) throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
3302
+ return {
3303
+ status: status.value,
3304
+ value: result
3305
+ };
3306
+ } else return this._def.schema._parseAsync({
3307
+ data: ctx.data,
3308
+ path: ctx.path,
3309
+ parent: ctx
3310
+ }).then((base) => {
3311
+ if (!isValid(base)) return INVALID;
3312
+ return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({
3313
+ status: status.value,
3314
+ value: result
3315
+ }));
3316
+ });
3317
+ util.assertNever(effect);
3318
+ }
3319
+ };
3320
+ ZodEffects.create = (schema, effect, params) => {
3321
+ return new ZodEffects({
3322
+ schema,
3323
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
3324
+ effect,
3325
+ ...processCreateParams(params)
3326
+ });
3327
+ };
3328
+ ZodEffects.createWithPreprocess = (preprocess, schema, params) => {
3329
+ return new ZodEffects({
3330
+ schema,
3331
+ effect: {
3332
+ type: "preprocess",
3333
+ transform: preprocess
3334
+ },
3335
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
3336
+ ...processCreateParams(params)
3337
+ });
3338
+ };
3339
+ var ZodOptional = class extends ZodType {
3340
+ _parse(input) {
3341
+ if (this._getType(input) === ZodParsedType.undefined) return OK(void 0);
3342
+ return this._def.innerType._parse(input);
3343
+ }
3344
+ unwrap() {
3345
+ return this._def.innerType;
3346
+ }
3347
+ };
3348
+ ZodOptional.create = (type, params) => {
3349
+ return new ZodOptional({
3350
+ innerType: type,
3351
+ typeName: ZodFirstPartyTypeKind.ZodOptional,
3352
+ ...processCreateParams(params)
3353
+ });
3354
+ };
3355
+ var ZodNullable = class extends ZodType {
3356
+ _parse(input) {
3357
+ if (this._getType(input) === ZodParsedType.null) return OK(null);
3358
+ return this._def.innerType._parse(input);
3359
+ }
3360
+ unwrap() {
3361
+ return this._def.innerType;
3362
+ }
3363
+ };
3364
+ ZodNullable.create = (type, params) => {
3365
+ return new ZodNullable({
3366
+ innerType: type,
3367
+ typeName: ZodFirstPartyTypeKind.ZodNullable,
3368
+ ...processCreateParams(params)
3369
+ });
3370
+ };
3371
+ var ZodDefault = class extends ZodType {
3372
+ _parse(input) {
3373
+ const { ctx } = this._processInputParams(input);
3374
+ let data = ctx.data;
3375
+ if (ctx.parsedType === ZodParsedType.undefined) data = this._def.defaultValue();
3376
+ return this._def.innerType._parse({
3377
+ data,
3378
+ path: ctx.path,
3379
+ parent: ctx
3380
+ });
3381
+ }
3382
+ removeDefault() {
3383
+ return this._def.innerType;
3384
+ }
3385
+ };
3386
+ ZodDefault.create = (type, params) => {
3387
+ return new ZodDefault({
3388
+ innerType: type,
3389
+ typeName: ZodFirstPartyTypeKind.ZodDefault,
3390
+ defaultValue: typeof params.default === "function" ? params.default : () => params.default,
3391
+ ...processCreateParams(params)
3392
+ });
3393
+ };
3394
+ var ZodCatch = class extends ZodType {
3395
+ _parse(input) {
3396
+ const { ctx } = this._processInputParams(input);
3397
+ const newCtx = {
3398
+ ...ctx,
3399
+ common: {
3400
+ ...ctx.common,
3401
+ issues: []
3402
+ }
3403
+ };
3404
+ const result = this._def.innerType._parse({
3405
+ data: newCtx.data,
3406
+ path: newCtx.path,
3407
+ parent: { ...newCtx }
3408
+ });
3409
+ if (isAsync(result)) return result.then((result) => {
3410
+ return {
3411
+ status: "valid",
3412
+ value: result.status === "valid" ? result.value : this._def.catchValue({
3413
+ get error() {
3414
+ return new ZodError(newCtx.common.issues);
3415
+ },
3416
+ input: newCtx.data
3417
+ })
3418
+ };
3419
+ });
3420
+ else return {
3421
+ status: "valid",
3422
+ value: result.status === "valid" ? result.value : this._def.catchValue({
3423
+ get error() {
3424
+ return new ZodError(newCtx.common.issues);
3425
+ },
3426
+ input: newCtx.data
3427
+ })
3428
+ };
3429
+ }
3430
+ removeCatch() {
3431
+ return this._def.innerType;
3432
+ }
3433
+ };
3434
+ ZodCatch.create = (type, params) => {
3435
+ return new ZodCatch({
3436
+ innerType: type,
3437
+ typeName: ZodFirstPartyTypeKind.ZodCatch,
3438
+ catchValue: typeof params.catch === "function" ? params.catch : () => params.catch,
3439
+ ...processCreateParams(params)
3440
+ });
3441
+ };
3442
+ var ZodNaN = class extends ZodType {
3443
+ _parse(input) {
3444
+ if (this._getType(input) !== ZodParsedType.nan) {
3445
+ const ctx = this._getOrReturnCtx(input);
3446
+ addIssueToContext(ctx, {
3447
+ code: ZodIssueCode.invalid_type,
3448
+ expected: ZodParsedType.nan,
3449
+ received: ctx.parsedType
3450
+ });
3451
+ return INVALID;
3452
+ }
3453
+ return {
3454
+ status: "valid",
3455
+ value: input.data
3456
+ };
3457
+ }
3458
+ };
3459
+ ZodNaN.create = (params) => {
3460
+ return new ZodNaN({
3461
+ typeName: ZodFirstPartyTypeKind.ZodNaN,
3462
+ ...processCreateParams(params)
3463
+ });
3464
+ };
3465
+ var ZodBranded = class extends ZodType {
3466
+ _parse(input) {
3467
+ const { ctx } = this._processInputParams(input);
3468
+ const data = ctx.data;
3469
+ return this._def.type._parse({
3470
+ data,
3471
+ path: ctx.path,
3472
+ parent: ctx
3473
+ });
3474
+ }
3475
+ unwrap() {
3476
+ return this._def.type;
3477
+ }
3478
+ };
3479
+ var ZodPipeline = class ZodPipeline extends ZodType {
3480
+ _parse(input) {
3481
+ const { status, ctx } = this._processInputParams(input);
3482
+ if (ctx.common.async) {
3483
+ const handleAsync = async () => {
3484
+ const inResult = await this._def.in._parseAsync({
3485
+ data: ctx.data,
3486
+ path: ctx.path,
3487
+ parent: ctx
3488
+ });
3489
+ if (inResult.status === "aborted") return INVALID;
3490
+ if (inResult.status === "dirty") {
3491
+ status.dirty();
3492
+ return DIRTY(inResult.value);
3493
+ } else return this._def.out._parseAsync({
3494
+ data: inResult.value,
3495
+ path: ctx.path,
3496
+ parent: ctx
3497
+ });
3498
+ };
3499
+ return handleAsync();
3500
+ } else {
3501
+ const inResult = this._def.in._parseSync({
3502
+ data: ctx.data,
3503
+ path: ctx.path,
3504
+ parent: ctx
3505
+ });
3506
+ if (inResult.status === "aborted") return INVALID;
3507
+ if (inResult.status === "dirty") {
3508
+ status.dirty();
3509
+ return {
3510
+ status: "dirty",
3511
+ value: inResult.value
3512
+ };
3513
+ } else return this._def.out._parseSync({
3514
+ data: inResult.value,
3515
+ path: ctx.path,
3516
+ parent: ctx
3517
+ });
3518
+ }
3519
+ }
3520
+ static create(a, b) {
3521
+ return new ZodPipeline({
3522
+ in: a,
3523
+ out: b,
3524
+ typeName: ZodFirstPartyTypeKind.ZodPipeline
3525
+ });
3526
+ }
3527
+ };
3528
+ var ZodReadonly = class extends ZodType {
3529
+ _parse(input) {
3530
+ const result = this._def.innerType._parse(input);
3531
+ const freeze = (data) => {
3532
+ if (isValid(data)) data.value = Object.freeze(data.value);
3533
+ return data;
3534
+ };
3535
+ return isAsync(result) ? result.then((data) => freeze(data)) : freeze(result);
3536
+ }
3537
+ unwrap() {
3538
+ return this._def.innerType;
3539
+ }
3540
+ };
3541
+ ZodReadonly.create = (type, params) => {
3542
+ return new ZodReadonly({
3543
+ innerType: type,
3544
+ typeName: ZodFirstPartyTypeKind.ZodReadonly,
3545
+ ...processCreateParams(params)
3546
+ });
3547
+ };
3548
+ ZodObject.lazycreate;
3549
+ var ZodFirstPartyTypeKind;
3550
+ (function(ZodFirstPartyTypeKind) {
3551
+ ZodFirstPartyTypeKind["ZodString"] = "ZodString";
3552
+ ZodFirstPartyTypeKind["ZodNumber"] = "ZodNumber";
3553
+ ZodFirstPartyTypeKind["ZodNaN"] = "ZodNaN";
3554
+ ZodFirstPartyTypeKind["ZodBigInt"] = "ZodBigInt";
3555
+ ZodFirstPartyTypeKind["ZodBoolean"] = "ZodBoolean";
3556
+ ZodFirstPartyTypeKind["ZodDate"] = "ZodDate";
3557
+ ZodFirstPartyTypeKind["ZodSymbol"] = "ZodSymbol";
3558
+ ZodFirstPartyTypeKind["ZodUndefined"] = "ZodUndefined";
3559
+ ZodFirstPartyTypeKind["ZodNull"] = "ZodNull";
3560
+ ZodFirstPartyTypeKind["ZodAny"] = "ZodAny";
3561
+ ZodFirstPartyTypeKind["ZodUnknown"] = "ZodUnknown";
3562
+ ZodFirstPartyTypeKind["ZodNever"] = "ZodNever";
3563
+ ZodFirstPartyTypeKind["ZodVoid"] = "ZodVoid";
3564
+ ZodFirstPartyTypeKind["ZodArray"] = "ZodArray";
3565
+ ZodFirstPartyTypeKind["ZodObject"] = "ZodObject";
3566
+ ZodFirstPartyTypeKind["ZodUnion"] = "ZodUnion";
3567
+ ZodFirstPartyTypeKind["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion";
3568
+ ZodFirstPartyTypeKind["ZodIntersection"] = "ZodIntersection";
3569
+ ZodFirstPartyTypeKind["ZodTuple"] = "ZodTuple";
3570
+ ZodFirstPartyTypeKind["ZodRecord"] = "ZodRecord";
3571
+ ZodFirstPartyTypeKind["ZodMap"] = "ZodMap";
3572
+ ZodFirstPartyTypeKind["ZodSet"] = "ZodSet";
3573
+ ZodFirstPartyTypeKind["ZodFunction"] = "ZodFunction";
3574
+ ZodFirstPartyTypeKind["ZodLazy"] = "ZodLazy";
3575
+ ZodFirstPartyTypeKind["ZodLiteral"] = "ZodLiteral";
3576
+ ZodFirstPartyTypeKind["ZodEnum"] = "ZodEnum";
3577
+ ZodFirstPartyTypeKind["ZodEffects"] = "ZodEffects";
3578
+ ZodFirstPartyTypeKind["ZodNativeEnum"] = "ZodNativeEnum";
3579
+ ZodFirstPartyTypeKind["ZodOptional"] = "ZodOptional";
3580
+ ZodFirstPartyTypeKind["ZodNullable"] = "ZodNullable";
3581
+ ZodFirstPartyTypeKind["ZodDefault"] = "ZodDefault";
3582
+ ZodFirstPartyTypeKind["ZodCatch"] = "ZodCatch";
3583
+ ZodFirstPartyTypeKind["ZodPromise"] = "ZodPromise";
3584
+ ZodFirstPartyTypeKind["ZodBranded"] = "ZodBranded";
3585
+ ZodFirstPartyTypeKind["ZodPipeline"] = "ZodPipeline";
3586
+ ZodFirstPartyTypeKind["ZodReadonly"] = "ZodReadonly";
3587
+ })(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
3588
+ ZodString.create;
3589
+ ZodNumber.create;
3590
+ ZodNaN.create;
3591
+ ZodBigInt.create;
3592
+ ZodBoolean.create;
3593
+ ZodDate.create;
3594
+ ZodSymbol.create;
3595
+ ZodUndefined.create;
3596
+ ZodNull.create;
3597
+ ZodAny.create;
3598
+ ZodUnknown.create;
3599
+ ZodNever.create;
3600
+ ZodVoid.create;
3601
+ ZodArray.create;
3602
+ ZodObject.create;
3603
+ ZodObject.strictCreate;
3604
+ ZodUnion.create;
3605
+ ZodDiscriminatedUnion.create;
3606
+ ZodIntersection.create;
3607
+ ZodTuple.create;
3608
+ ZodRecord.create;
3609
+ ZodMap.create;
3610
+ ZodSet.create;
3611
+ ZodFunction.create;
3612
+ ZodLazy.create;
3613
+ ZodLiteral.create;
3614
+ ZodEnum.create;
3615
+ ZodNativeEnum.create;
3616
+ ZodPromise.create;
3617
+ ZodEffects.create;
3618
+ ZodOptional.create;
3619
+ ZodNullable.create;
3620
+ ZodEffects.createWithPreprocess;
3621
+ ZodPipeline.create;
3622
+ //#endregion
3623
+ //#region ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@4.4.3/node_modules/zod-to-json-schema/dist/esm/parsers/any.js
3624
+ function parseAnyDef(refs) {
3625
+ if (refs.target !== "openAi") return {};
3626
+ const anyDefinitionPath = [
3627
+ ...refs.basePath,
3628
+ refs.definitionPath,
3629
+ refs.openAiAnyTypeName
3630
+ ];
3631
+ refs.flags.hasReferencedOpenAiAnyType = true;
3632
+ return { $ref: refs.$refStrategy === "relative" ? getRelativePath(anyDefinitionPath, refs.currentPath) : anyDefinitionPath.join("/") };
3633
+ }
3634
+ //#endregion
3635
+ //#region ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@4.4.3/node_modules/zod-to-json-schema/dist/esm/parsers/array.js
3636
+ function parseArrayDef(def, refs) {
3637
+ const res = { type: "array" };
3638
+ if (def.type?._def && def.type?._def?.typeName !== ZodFirstPartyTypeKind.ZodAny) res.items = parseDef(def.type._def, {
3639
+ ...refs,
3640
+ currentPath: [...refs.currentPath, "items"]
3641
+ });
3642
+ if (def.minLength) setResponseValueAndErrors(res, "minItems", def.minLength.value, def.minLength.message, refs);
3643
+ if (def.maxLength) setResponseValueAndErrors(res, "maxItems", def.maxLength.value, def.maxLength.message, refs);
3644
+ if (def.exactLength) {
3645
+ setResponseValueAndErrors(res, "minItems", def.exactLength.value, def.exactLength.message, refs);
3646
+ setResponseValueAndErrors(res, "maxItems", def.exactLength.value, def.exactLength.message, refs);
3647
+ }
3648
+ return res;
3649
+ }
3650
+ //#endregion
3651
+ //#region ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@4.4.3/node_modules/zod-to-json-schema/dist/esm/parsers/bigint.js
3652
+ function parseBigintDef(def, refs) {
3653
+ const res = {
3654
+ type: "integer",
3655
+ format: "int64"
3656
+ };
3657
+ if (!def.checks) return res;
3658
+ for (const check of def.checks) switch (check.kind) {
3659
+ case "min":
3660
+ if (refs.target === "jsonSchema7") if (check.inclusive) setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
3661
+ else setResponseValueAndErrors(res, "exclusiveMinimum", check.value, check.message, refs);
3662
+ else {
3663
+ if (!check.inclusive) res.exclusiveMinimum = true;
3664
+ setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
3665
+ }
3666
+ break;
3667
+ case "max":
3668
+ if (refs.target === "jsonSchema7") if (check.inclusive) setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
3669
+ else setResponseValueAndErrors(res, "exclusiveMaximum", check.value, check.message, refs);
3670
+ else {
3671
+ if (!check.inclusive) res.exclusiveMaximum = true;
3672
+ setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
3673
+ }
3674
+ break;
3675
+ case "multipleOf":
3676
+ setResponseValueAndErrors(res, "multipleOf", check.value, check.message, refs);
3677
+ break;
3678
+ }
3679
+ return res;
3680
+ }
3681
+ //#endregion
3682
+ //#region ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@4.4.3/node_modules/zod-to-json-schema/dist/esm/parsers/boolean.js
3683
+ function parseBooleanDef() {
3684
+ return { type: "boolean" };
3685
+ }
3686
+ //#endregion
3687
+ //#region ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@4.4.3/node_modules/zod-to-json-schema/dist/esm/parsers/branded.js
3688
+ function parseBrandedDef(_def, refs) {
3689
+ return parseDef(_def.type._def, refs);
3690
+ }
3691
+ //#endregion
3692
+ //#region ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@4.4.3/node_modules/zod-to-json-schema/dist/esm/parsers/catch.js
3693
+ const parseCatchDef = (def, refs) => {
3694
+ return parseDef(def.innerType._def, refs);
3695
+ };
3696
+ //#endregion
3697
+ //#region ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@4.4.3/node_modules/zod-to-json-schema/dist/esm/parsers/date.js
3698
+ function parseDateDef(def, refs, overrideDateStrategy) {
3699
+ const strategy = overrideDateStrategy ?? refs.dateStrategy;
3700
+ if (Array.isArray(strategy)) return { anyOf: strategy.map((item, i) => parseDateDef(def, refs, item)) };
3701
+ switch (strategy) {
3702
+ case "string":
3703
+ case "format:date-time": return {
3704
+ type: "string",
3705
+ format: "date-time"
3706
+ };
3707
+ case "format:date": return {
3708
+ type: "string",
3709
+ format: "date"
3710
+ };
3711
+ case "integer": return integerDateParser(def, refs);
3712
+ }
3713
+ }
3714
+ const integerDateParser = (def, refs) => {
3715
+ const res = {
3716
+ type: "integer",
3717
+ format: "unix-time"
3718
+ };
3719
+ if (refs.target === "openApi3") return res;
3720
+ for (const check of def.checks) switch (check.kind) {
3721
+ case "min":
3722
+ setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
3723
+ break;
3724
+ case "max":
3725
+ setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
3726
+ break;
3727
+ }
3728
+ return res;
3729
+ };
3730
+ //#endregion
3731
+ //#region ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@4.4.3/node_modules/zod-to-json-schema/dist/esm/parsers/default.js
3732
+ function parseDefaultDef(_def, refs) {
3733
+ return {
3734
+ ...parseDef(_def.innerType._def, refs),
3735
+ default: _def.defaultValue()
3736
+ };
3737
+ }
3738
+ //#endregion
3739
+ //#region ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@4.4.3/node_modules/zod-to-json-schema/dist/esm/parsers/effects.js
3740
+ function parseEffectsDef(_def, refs) {
3741
+ return refs.effectStrategy === "input" ? parseDef(_def.schema._def, refs) : parseAnyDef(refs);
3742
+ }
3743
+ //#endregion
3744
+ //#region ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@4.4.3/node_modules/zod-to-json-schema/dist/esm/parsers/enum.js
3745
+ function parseEnumDef(def) {
3746
+ return {
3747
+ type: "string",
3748
+ enum: Array.from(def.values)
3749
+ };
3750
+ }
3751
+ //#endregion
3752
+ //#region ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@4.4.3/node_modules/zod-to-json-schema/dist/esm/parsers/intersection.js
3753
+ const isJsonSchema7AllOfType = (type) => {
3754
+ if ("type" in type && type.type === "string") return false;
3755
+ return "allOf" in type;
3756
+ };
3757
+ function parseIntersectionDef(def, refs) {
3758
+ const allOf = [parseDef(def.left._def, {
3759
+ ...refs,
3760
+ currentPath: [
3761
+ ...refs.currentPath,
3762
+ "allOf",
3763
+ "0"
3764
+ ]
3765
+ }), parseDef(def.right._def, {
3766
+ ...refs,
3767
+ currentPath: [
3768
+ ...refs.currentPath,
3769
+ "allOf",
3770
+ "1"
3771
+ ]
3772
+ })].filter((x) => !!x);
3773
+ let unevaluatedProperties = refs.target === "jsonSchema2019-09" ? { unevaluatedProperties: false } : void 0;
3774
+ const mergedAllOf = [];
3775
+ allOf.forEach((schema) => {
3776
+ if (isJsonSchema7AllOfType(schema)) {
3777
+ mergedAllOf.push(...schema.allOf);
3778
+ if (schema.unevaluatedProperties === void 0) unevaluatedProperties = void 0;
3779
+ } else {
3780
+ let nestedSchema = schema;
3781
+ if ("additionalProperties" in schema && schema.additionalProperties === false) {
3782
+ const { additionalProperties, ...rest } = schema;
3783
+ nestedSchema = rest;
3784
+ } else unevaluatedProperties = void 0;
3785
+ mergedAllOf.push(nestedSchema);
3786
+ }
3787
+ });
3788
+ return mergedAllOf.length ? {
3789
+ allOf: mergedAllOf,
3790
+ ...unevaluatedProperties
3791
+ } : void 0;
3792
+ }
3793
+ //#endregion
3794
+ //#region ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@4.4.3/node_modules/zod-to-json-schema/dist/esm/parsers/literal.js
3795
+ function parseLiteralDef(def, refs) {
3796
+ const parsedType = typeof def.value;
3797
+ if (parsedType !== "bigint" && parsedType !== "number" && parsedType !== "boolean" && parsedType !== "string") return { type: Array.isArray(def.value) ? "array" : "object" };
3798
+ if (refs.target === "openApi3") return {
3799
+ type: parsedType === "bigint" ? "integer" : parsedType,
3800
+ enum: [def.value]
3801
+ };
3802
+ return {
3803
+ type: parsedType === "bigint" ? "integer" : parsedType,
3804
+ const: def.value
3805
+ };
3806
+ }
3807
+ //#endregion
3808
+ //#region ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@4.4.3/node_modules/zod-to-json-schema/dist/esm/parsers/string.js
3809
+ let emojiRegex = void 0;
3810
+ /**
3811
+ * Generated from the regular expressions found here as of 2024-05-22:
3812
+ * https://github.com/colinhacks/zod/blob/master/src/types.ts.
3813
+ *
3814
+ * Expressions with /i flag have been changed accordingly.
3815
+ */
3816
+ const zodPatterns = {
3817
+ /**
3818
+ * `c` was changed to `[cC]` to replicate /i flag
3819
+ */
3820
+ cuid: /^[cC][^\s-]{8,}$/,
3821
+ cuid2: /^[0-9a-z]+$/,
3822
+ ulid: /^[0-9A-HJKMNP-TV-Z]{26}$/,
3823
+ /**
3824
+ * `a-z` was added to replicate /i flag
3825
+ */
3826
+ email: /^(?!\.)(?!.*\.\.)([a-zA-Z0-9_'+\-\.]*)[a-zA-Z0-9_+-]@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,}$/,
3827
+ /**
3828
+ * Constructed a valid Unicode RegExp
3829
+ *
3830
+ * Lazily instantiate since this type of regex isn't supported
3831
+ * in all envs (e.g. React Native).
3832
+ *
3833
+ * See:
3834
+ * https://github.com/colinhacks/zod/issues/2433
3835
+ * Fix in Zod:
3836
+ * https://github.com/colinhacks/zod/commit/9340fd51e48576a75adc919bff65dbc4a5d4c99b
3837
+ */
3838
+ emoji: () => {
3839
+ if (emojiRegex === void 0) emojiRegex = RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$", "u");
3840
+ return emojiRegex;
3841
+ },
3842
+ /**
3843
+ * Unused
3844
+ */
3845
+ uuid: /^[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}$/,
3846
+ /**
3847
+ * Unused
3848
+ */
3849
+ ipv4: /^(?:(?: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])$/,
3850
+ ipv4Cidr: /^(?:(?: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])$/,
3851
+ /**
3852
+ * Unused
3853
+ */
3854
+ ipv6: /^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/,
3855
+ ipv6Cidr: /^(([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])$/,
3856
+ base64: /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,
3857
+ base64url: /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,
3858
+ nanoid: /^[a-zA-Z0-9_-]{21}$/,
3859
+ jwt: /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/
3860
+ };
3861
+ function parseStringDef(def, refs) {
3862
+ const res = { type: "string" };
3863
+ if (def.checks) for (const check of def.checks) switch (check.kind) {
3864
+ case "min":
3865
+ setResponseValueAndErrors(res, "minLength", typeof res.minLength === "number" ? Math.max(res.minLength, check.value) : check.value, check.message, refs);
3866
+ break;
3867
+ case "max":
3868
+ setResponseValueAndErrors(res, "maxLength", typeof res.maxLength === "number" ? Math.min(res.maxLength, check.value) : check.value, check.message, refs);
3869
+ break;
3870
+ case "email":
3871
+ switch (refs.emailStrategy) {
3872
+ case "format:email":
3873
+ addFormat(res, "email", check.message, refs);
3874
+ break;
3875
+ case "format:idn-email":
3876
+ addFormat(res, "idn-email", check.message, refs);
3877
+ break;
3878
+ case "pattern:zod":
3879
+ addPattern(res, zodPatterns.email, check.message, refs);
3880
+ break;
3881
+ }
3882
+ break;
3883
+ case "url":
3884
+ addFormat(res, "uri", check.message, refs);
3885
+ break;
3886
+ case "uuid":
3887
+ addFormat(res, "uuid", check.message, refs);
3888
+ break;
3889
+ case "regex":
3890
+ addPattern(res, check.regex, check.message, refs);
3891
+ break;
3892
+ case "cuid":
3893
+ addPattern(res, zodPatterns.cuid, check.message, refs);
3894
+ break;
3895
+ case "cuid2":
3896
+ addPattern(res, zodPatterns.cuid2, check.message, refs);
3897
+ break;
3898
+ case "startsWith":
3899
+ addPattern(res, RegExp(`^${escapeLiteralCheckValue(check.value, refs)}`), check.message, refs);
3900
+ break;
3901
+ case "endsWith":
3902
+ addPattern(res, RegExp(`${escapeLiteralCheckValue(check.value, refs)}$`), check.message, refs);
3903
+ break;
3904
+ case "datetime":
3905
+ addFormat(res, "date-time", check.message, refs);
3906
+ break;
3907
+ case "date":
3908
+ addFormat(res, "date", check.message, refs);
3909
+ break;
3910
+ case "time":
3911
+ addFormat(res, "time", check.message, refs);
3912
+ break;
3913
+ case "duration":
3914
+ addFormat(res, "duration", check.message, refs);
3915
+ break;
3916
+ case "length":
3917
+ setResponseValueAndErrors(res, "minLength", typeof res.minLength === "number" ? Math.max(res.minLength, check.value) : check.value, check.message, refs);
3918
+ setResponseValueAndErrors(res, "maxLength", typeof res.maxLength === "number" ? Math.min(res.maxLength, check.value) : check.value, check.message, refs);
3919
+ break;
3920
+ case "includes":
3921
+ addPattern(res, RegExp(escapeLiteralCheckValue(check.value, refs)), check.message, refs);
3922
+ break;
3923
+ case "ip":
3924
+ if (check.version !== "v6") addFormat(res, "ipv4", check.message, refs);
3925
+ if (check.version !== "v4") addFormat(res, "ipv6", check.message, refs);
3926
+ break;
3927
+ case "base64url":
3928
+ addPattern(res, zodPatterns.base64url, check.message, refs);
3929
+ break;
3930
+ case "jwt":
3931
+ addPattern(res, zodPatterns.jwt, check.message, refs);
3932
+ break;
3933
+ case "cidr":
3934
+ if (check.version !== "v6") addPattern(res, zodPatterns.ipv4Cidr, check.message, refs);
3935
+ if (check.version !== "v4") addPattern(res, zodPatterns.ipv6Cidr, check.message, refs);
3936
+ break;
3937
+ case "emoji":
3938
+ addPattern(res, zodPatterns.emoji(), check.message, refs);
3939
+ break;
3940
+ case "ulid":
3941
+ addPattern(res, zodPatterns.ulid, check.message, refs);
3942
+ break;
3943
+ case "base64":
3944
+ switch (refs.base64Strategy) {
3945
+ case "format:binary":
3946
+ addFormat(res, "binary", check.message, refs);
3947
+ break;
3948
+ case "contentEncoding:base64":
3949
+ setResponseValueAndErrors(res, "contentEncoding", "base64", check.message, refs);
3950
+ break;
3951
+ case "pattern:zod":
3952
+ addPattern(res, zodPatterns.base64, check.message, refs);
3953
+ break;
3954
+ }
3955
+ break;
3956
+ case "nanoid": addPattern(res, zodPatterns.nanoid, check.message, refs);
3957
+ case "toLowerCase":
3958
+ case "toUpperCase":
3959
+ case "trim": break;
3960
+ default:
3961
+ }
3962
+ return res;
3963
+ }
3964
+ function escapeLiteralCheckValue(literal, refs) {
3965
+ return refs.patternStrategy === "escape" ? escapeNonAlphaNumeric(literal) : literal;
3966
+ }
3967
+ const ALPHA_NUMERIC = /* @__PURE__ */ new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");
3968
+ function escapeNonAlphaNumeric(source) {
3969
+ let result = "";
3970
+ for (let i = 0; i < source.length; i++) {
3971
+ if (!ALPHA_NUMERIC.has(source[i])) result += "\\";
3972
+ result += source[i];
3973
+ }
3974
+ return result;
3975
+ }
3976
+ function addFormat(schema, value, message, refs) {
3977
+ if (schema.format || schema.anyOf?.some((x) => x.format)) {
3978
+ if (!schema.anyOf) schema.anyOf = [];
3979
+ if (schema.format) {
3980
+ schema.anyOf.push({
3981
+ format: schema.format,
3982
+ ...schema.errorMessage && refs.errorMessages && { errorMessage: { format: schema.errorMessage.format } }
3983
+ });
3984
+ delete schema.format;
3985
+ if (schema.errorMessage) {
3986
+ delete schema.errorMessage.format;
3987
+ if (Object.keys(schema.errorMessage).length === 0) delete schema.errorMessage;
3988
+ }
3989
+ }
3990
+ schema.anyOf.push({
3991
+ format: value,
3992
+ ...message && refs.errorMessages && { errorMessage: { format: message } }
3993
+ });
3994
+ } else setResponseValueAndErrors(schema, "format", value, message, refs);
3995
+ }
3996
+ function addPattern(schema, regex, message, refs) {
3997
+ if (schema.pattern || schema.allOf?.some((x) => x.pattern)) {
3998
+ if (!schema.allOf) schema.allOf = [];
3999
+ if (schema.pattern) {
4000
+ schema.allOf.push({
4001
+ pattern: schema.pattern,
4002
+ ...schema.errorMessage && refs.errorMessages && { errorMessage: { pattern: schema.errorMessage.pattern } }
4003
+ });
4004
+ delete schema.pattern;
4005
+ if (schema.errorMessage) {
4006
+ delete schema.errorMessage.pattern;
4007
+ if (Object.keys(schema.errorMessage).length === 0) delete schema.errorMessage;
4008
+ }
4009
+ }
4010
+ schema.allOf.push({
4011
+ pattern: stringifyRegExpWithFlags(regex, refs),
4012
+ ...message && refs.errorMessages && { errorMessage: { pattern: message } }
4013
+ });
4014
+ } else setResponseValueAndErrors(schema, "pattern", stringifyRegExpWithFlags(regex, refs), message, refs);
4015
+ }
4016
+ function stringifyRegExpWithFlags(regex, refs) {
4017
+ if (!refs.applyRegexFlags || !regex.flags) return regex.source;
4018
+ const flags = {
4019
+ i: regex.flags.includes("i"),
4020
+ m: regex.flags.includes("m"),
4021
+ s: regex.flags.includes("s")
4022
+ };
4023
+ const source = flags.i ? regex.source.toLowerCase() : regex.source;
4024
+ let pattern = "";
4025
+ let isEscaped = false;
4026
+ let inCharGroup = false;
4027
+ let inCharRange = false;
4028
+ for (let i = 0; i < source.length; i++) {
4029
+ if (isEscaped) {
4030
+ pattern += source[i];
4031
+ isEscaped = false;
4032
+ continue;
4033
+ }
4034
+ if (flags.i) {
4035
+ if (inCharGroup) {
4036
+ if (source[i].match(/[a-z]/)) {
4037
+ if (inCharRange) {
4038
+ pattern += source[i];
4039
+ pattern += `${source[i - 2]}-${source[i]}`.toUpperCase();
4040
+ inCharRange = false;
4041
+ } else if (source[i + 1] === "-" && source[i + 2]?.match(/[a-z]/)) {
4042
+ pattern += source[i];
4043
+ inCharRange = true;
4044
+ } else pattern += `${source[i]}${source[i].toUpperCase()}`;
4045
+ continue;
4046
+ }
4047
+ } else if (source[i].match(/[a-z]/)) {
4048
+ pattern += `[${source[i]}${source[i].toUpperCase()}]`;
4049
+ continue;
4050
+ }
4051
+ }
4052
+ if (flags.m) {
4053
+ if (source[i] === "^") {
4054
+ pattern += `(^|(?<=[\r\n]))`;
4055
+ continue;
4056
+ } else if (source[i] === "$") {
4057
+ pattern += `($|(?=[\r\n]))`;
4058
+ continue;
4059
+ }
4060
+ }
4061
+ if (flags.s && source[i] === ".") {
4062
+ pattern += inCharGroup ? `${source[i]}\r\n` : `[${source[i]}\r\n]`;
4063
+ continue;
4064
+ }
4065
+ pattern += source[i];
4066
+ if (source[i] === "\\") isEscaped = true;
4067
+ else if (inCharGroup && source[i] === "]") inCharGroup = false;
4068
+ else if (!inCharGroup && source[i] === "[") inCharGroup = true;
4069
+ }
4070
+ try {
4071
+ new RegExp(pattern);
4072
+ } catch {
4073
+ console.warn(`Could not convert regex pattern at ${refs.currentPath.join("/")} to a flag-independent form! Falling back to the flag-ignorant source`);
4074
+ return regex.source;
4075
+ }
4076
+ return pattern;
4077
+ }
4078
+ //#endregion
4079
+ //#region ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@4.4.3/node_modules/zod-to-json-schema/dist/esm/parsers/record.js
4080
+ function parseRecordDef(def, refs) {
4081
+ if (refs.target === "openAi") console.warn("Warning: OpenAI may not support records in schemas! Try an array of key-value pairs instead.");
4082
+ if (refs.target === "openApi3" && def.keyType?._def.typeName === ZodFirstPartyTypeKind.ZodEnum) return {
4083
+ type: "object",
4084
+ required: def.keyType._def.values,
4085
+ properties: def.keyType._def.values.reduce((acc, key) => ({
4086
+ ...acc,
4087
+ [key]: parseDef(def.valueType._def, {
4088
+ ...refs,
4089
+ currentPath: [
4090
+ ...refs.currentPath,
4091
+ "properties",
4092
+ key
4093
+ ]
4094
+ }) ?? parseAnyDef(refs)
4095
+ }), {}),
4096
+ additionalProperties: refs.rejectedAdditionalProperties
4097
+ };
4098
+ const schema = {
4099
+ type: "object",
4100
+ additionalProperties: parseDef(def.valueType._def, {
4101
+ ...refs,
4102
+ currentPath: [...refs.currentPath, "additionalProperties"]
4103
+ }) ?? refs.allowedAdditionalProperties
4104
+ };
4105
+ if (refs.target === "openApi3") return schema;
4106
+ if (def.keyType?._def.typeName === ZodFirstPartyTypeKind.ZodString && def.keyType._def.checks?.length) {
4107
+ const { type, ...keyType } = parseStringDef(def.keyType._def, refs);
4108
+ return {
4109
+ ...schema,
4110
+ propertyNames: keyType
4111
+ };
4112
+ } else if (def.keyType?._def.typeName === ZodFirstPartyTypeKind.ZodEnum) return {
4113
+ ...schema,
4114
+ propertyNames: { enum: def.keyType._def.values }
4115
+ };
4116
+ else if (def.keyType?._def.typeName === ZodFirstPartyTypeKind.ZodBranded && def.keyType._def.type._def.typeName === ZodFirstPartyTypeKind.ZodString && def.keyType._def.type._def.checks?.length) {
4117
+ const { type, ...keyType } = parseBrandedDef(def.keyType._def, refs);
4118
+ return {
4119
+ ...schema,
4120
+ propertyNames: keyType
4121
+ };
4122
+ }
4123
+ return schema;
4124
+ }
4125
+ //#endregion
4126
+ //#region ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@4.4.3/node_modules/zod-to-json-schema/dist/esm/parsers/map.js
4127
+ function parseMapDef(def, refs) {
4128
+ if (refs.mapStrategy === "record") return parseRecordDef(def, refs);
4129
+ return {
4130
+ type: "array",
4131
+ maxItems: 125,
4132
+ items: {
4133
+ type: "array",
4134
+ items: [parseDef(def.keyType._def, {
4135
+ ...refs,
4136
+ currentPath: [
4137
+ ...refs.currentPath,
4138
+ "items",
4139
+ "items",
4140
+ "0"
4141
+ ]
4142
+ }) || parseAnyDef(refs), parseDef(def.valueType._def, {
4143
+ ...refs,
4144
+ currentPath: [
4145
+ ...refs.currentPath,
4146
+ "items",
4147
+ "items",
4148
+ "1"
4149
+ ]
4150
+ }) || parseAnyDef(refs)],
4151
+ minItems: 2,
4152
+ maxItems: 2
4153
+ }
4154
+ };
4155
+ }
4156
+ //#endregion
4157
+ //#region ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@4.4.3/node_modules/zod-to-json-schema/dist/esm/parsers/nativeEnum.js
4158
+ function parseNativeEnumDef(def) {
4159
+ const object = def.values;
4160
+ const actualValues = Object.keys(def.values).filter((key) => {
4161
+ return typeof object[object[key]] !== "number";
4162
+ }).map((key) => object[key]);
4163
+ const parsedTypes = Array.from(new Set(actualValues.map((values) => typeof values)));
4164
+ return {
4165
+ type: parsedTypes.length === 1 ? parsedTypes[0] === "string" ? "string" : "number" : ["string", "number"],
4166
+ enum: actualValues
4167
+ };
4168
+ }
4169
+ //#endregion
4170
+ //#region ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@4.4.3/node_modules/zod-to-json-schema/dist/esm/parsers/never.js
4171
+ function parseNeverDef(refs) {
4172
+ return refs.target === "openAi" ? void 0 : { not: parseAnyDef({
4173
+ ...refs,
4174
+ currentPath: [...refs.currentPath, "not"]
4175
+ }) };
4176
+ }
4177
+ //#endregion
4178
+ //#region ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@4.4.3/node_modules/zod-to-json-schema/dist/esm/parsers/null.js
4179
+ function parseNullDef(refs) {
4180
+ return refs.target === "openApi3" ? {
4181
+ enum: ["null"],
4182
+ nullable: true
4183
+ } : { type: "null" };
4184
+ }
4185
+ //#endregion
4186
+ //#region ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@4.4.3/node_modules/zod-to-json-schema/dist/esm/parsers/union.js
4187
+ const primitiveMappings = {
4188
+ ZodString: "string",
4189
+ ZodNumber: "number",
4190
+ ZodBigInt: "integer",
4191
+ ZodBoolean: "boolean",
4192
+ ZodNull: "null"
4193
+ };
4194
+ function parseUnionDef(def, refs) {
4195
+ if (refs.target === "openApi3") return asAnyOf(def, refs);
4196
+ const options = def.options instanceof Map ? Array.from(def.options.values()) : def.options;
4197
+ if (options.every((x) => x._def.typeName in primitiveMappings && (!x._def.checks || !x._def.checks.length))) {
4198
+ const types = options.reduce((types, x) => {
4199
+ const type = primitiveMappings[x._def.typeName];
4200
+ return type && !types.includes(type) ? [...types, type] : types;
4201
+ }, []);
4202
+ return { type: types.length > 1 ? types : types[0] };
4203
+ } else if (options.every((x) => x._def.typeName === "ZodLiteral" && !x.description)) {
4204
+ const types = options.reduce((acc, x) => {
4205
+ const type = typeof x._def.value;
4206
+ switch (type) {
4207
+ case "string":
4208
+ case "number":
4209
+ case "boolean": return [...acc, type];
4210
+ case "bigint": return [...acc, "integer"];
4211
+ case "object": if (x._def.value === null) return [...acc, "null"];
4212
+ default: return acc;
4213
+ }
4214
+ }, []);
4215
+ if (types.length === options.length) {
4216
+ const uniqueTypes = types.filter((x, i, a) => a.indexOf(x) === i);
4217
+ return {
4218
+ type: uniqueTypes.length > 1 ? uniqueTypes : uniqueTypes[0],
4219
+ enum: options.reduce((acc, x) => {
4220
+ return acc.includes(x._def.value) ? acc : [...acc, x._def.value];
4221
+ }, [])
4222
+ };
4223
+ }
4224
+ } else if (options.every((x) => x._def.typeName === "ZodEnum")) return {
4225
+ type: "string",
4226
+ enum: options.reduce((acc, x) => [...acc, ...x._def.values.filter((x) => !acc.includes(x))], [])
4227
+ };
4228
+ return asAnyOf(def, refs);
4229
+ }
4230
+ const asAnyOf = (def, refs) => {
4231
+ const anyOf = (def.options instanceof Map ? Array.from(def.options.values()) : def.options).map((x, i) => parseDef(x._def, {
4232
+ ...refs,
4233
+ currentPath: [
4234
+ ...refs.currentPath,
4235
+ "anyOf",
4236
+ `${i}`
4237
+ ]
4238
+ })).filter((x) => !!x && (!refs.strictUnions || typeof x === "object" && Object.keys(x).length > 0));
4239
+ return anyOf.length ? { anyOf } : void 0;
4240
+ };
4241
+ //#endregion
4242
+ //#region ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@4.4.3/node_modules/zod-to-json-schema/dist/esm/parsers/nullable.js
4243
+ function parseNullableDef(def, refs) {
4244
+ if ([
4245
+ "ZodString",
4246
+ "ZodNumber",
4247
+ "ZodBigInt",
4248
+ "ZodBoolean",
4249
+ "ZodNull"
4250
+ ].includes(def.innerType._def.typeName) && (!def.innerType._def.checks || !def.innerType._def.checks.length)) {
4251
+ if (refs.target === "openApi3") return {
4252
+ type: primitiveMappings[def.innerType._def.typeName],
4253
+ nullable: true
4254
+ };
4255
+ return { type: [primitiveMappings[def.innerType._def.typeName], "null"] };
4256
+ }
4257
+ if (refs.target === "openApi3") {
4258
+ const base = parseDef(def.innerType._def, {
4259
+ ...refs,
4260
+ currentPath: [...refs.currentPath]
4261
+ });
4262
+ if (base && "$ref" in base) return {
4263
+ allOf: [base],
4264
+ nullable: true
4265
+ };
4266
+ return base && {
4267
+ ...base,
4268
+ nullable: true
4269
+ };
4270
+ }
4271
+ const base = parseDef(def.innerType._def, {
4272
+ ...refs,
4273
+ currentPath: [
4274
+ ...refs.currentPath,
4275
+ "anyOf",
4276
+ "0"
4277
+ ]
4278
+ });
4279
+ return base && { anyOf: [base, { type: "null" }] };
4280
+ }
4281
+ //#endregion
4282
+ //#region ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@4.4.3/node_modules/zod-to-json-schema/dist/esm/parsers/number.js
4283
+ function parseNumberDef(def, refs) {
4284
+ const res = { type: "number" };
4285
+ if (!def.checks) return res;
4286
+ for (const check of def.checks) switch (check.kind) {
4287
+ case "int":
4288
+ res.type = "integer";
4289
+ addErrorMessage(res, "type", check.message, refs);
4290
+ break;
4291
+ case "min":
4292
+ if (refs.target === "jsonSchema7") if (check.inclusive) setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
4293
+ else setResponseValueAndErrors(res, "exclusiveMinimum", check.value, check.message, refs);
4294
+ else {
4295
+ if (!check.inclusive) res.exclusiveMinimum = true;
4296
+ setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
4297
+ }
4298
+ break;
4299
+ case "max":
4300
+ if (refs.target === "jsonSchema7") if (check.inclusive) setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
4301
+ else setResponseValueAndErrors(res, "exclusiveMaximum", check.value, check.message, refs);
4302
+ else {
4303
+ if (!check.inclusive) res.exclusiveMaximum = true;
4304
+ setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
4305
+ }
4306
+ break;
4307
+ case "multipleOf":
4308
+ setResponseValueAndErrors(res, "multipleOf", check.value, check.message, refs);
4309
+ break;
4310
+ }
4311
+ return res;
4312
+ }
4313
+ //#endregion
4314
+ //#region ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@4.4.3/node_modules/zod-to-json-schema/dist/esm/parsers/object.js
4315
+ function parseObjectDef(def, refs) {
4316
+ const forceOptionalIntoNullable = refs.target === "openAi";
4317
+ const result = {
4318
+ type: "object",
4319
+ properties: {}
4320
+ };
4321
+ const required = [];
4322
+ const shape = def.shape();
4323
+ for (const propName in shape) {
4324
+ let propDef = shape[propName];
4325
+ if (propDef === void 0 || propDef._def === void 0) continue;
4326
+ let propOptional = safeIsOptional(propDef);
4327
+ if (propOptional && forceOptionalIntoNullable) {
4328
+ if (propDef._def.typeName === "ZodOptional") propDef = propDef._def.innerType;
4329
+ if (!propDef.isNullable()) propDef = propDef.nullable();
4330
+ propOptional = false;
4331
+ }
4332
+ const parsedDef = parseDef(propDef._def, {
4333
+ ...refs,
4334
+ currentPath: [
4335
+ ...refs.currentPath,
4336
+ "properties",
4337
+ propName
4338
+ ],
4339
+ propertyPath: [
4340
+ ...refs.currentPath,
4341
+ "properties",
4342
+ propName
4343
+ ]
4344
+ });
4345
+ if (parsedDef === void 0) continue;
4346
+ result.properties[propName] = parsedDef;
4347
+ if (!propOptional) required.push(propName);
4348
+ }
4349
+ if (required.length) result.required = required;
4350
+ const additionalProperties = decideAdditionalProperties(def, refs);
4351
+ if (additionalProperties !== void 0) result.additionalProperties = additionalProperties;
4352
+ return result;
4353
+ }
4354
+ function decideAdditionalProperties(def, refs) {
4355
+ if (def.catchall._def.typeName !== "ZodNever") return parseDef(def.catchall._def, {
4356
+ ...refs,
4357
+ currentPath: [...refs.currentPath, "additionalProperties"]
4358
+ });
4359
+ switch (def.unknownKeys) {
4360
+ case "passthrough": return refs.allowedAdditionalProperties;
4361
+ case "strict": return refs.rejectedAdditionalProperties;
4362
+ case "strip": return refs.removeAdditionalStrategy === "strict" ? refs.allowedAdditionalProperties : refs.rejectedAdditionalProperties;
4363
+ }
4364
+ }
4365
+ function safeIsOptional(schema) {
4366
+ try {
4367
+ return schema.isOptional();
4368
+ } catch {
4369
+ return true;
4370
+ }
4371
+ }
4372
+ //#endregion
4373
+ //#region ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@4.4.3/node_modules/zod-to-json-schema/dist/esm/parsers/optional.js
4374
+ const parseOptionalDef = (def, refs) => {
4375
+ if (refs.currentPath.toString() === refs.propertyPath?.toString()) return parseDef(def.innerType._def, refs);
4376
+ const innerSchema = parseDef(def.innerType._def, {
4377
+ ...refs,
4378
+ currentPath: [
4379
+ ...refs.currentPath,
4380
+ "anyOf",
4381
+ "1"
4382
+ ]
4383
+ });
4384
+ return innerSchema ? { anyOf: [{ not: parseAnyDef(refs) }, innerSchema] } : parseAnyDef(refs);
4385
+ };
4386
+ //#endregion
4387
+ //#region ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@4.4.3/node_modules/zod-to-json-schema/dist/esm/parsers/pipeline.js
4388
+ const parsePipelineDef = (def, refs) => {
4389
+ if (refs.pipeStrategy === "input") return parseDef(def.in._def, refs);
4390
+ else if (refs.pipeStrategy === "output") return parseDef(def.out._def, refs);
4391
+ const a = parseDef(def.in._def, {
4392
+ ...refs,
4393
+ currentPath: [
4394
+ ...refs.currentPath,
4395
+ "allOf",
4396
+ "0"
4397
+ ]
4398
+ });
4399
+ return { allOf: [a, parseDef(def.out._def, {
4400
+ ...refs,
4401
+ currentPath: [
4402
+ ...refs.currentPath,
4403
+ "allOf",
4404
+ a ? "1" : "0"
4405
+ ]
4406
+ })].filter((x) => x !== void 0) };
4407
+ };
4408
+ //#endregion
4409
+ //#region ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@4.4.3/node_modules/zod-to-json-schema/dist/esm/parsers/promise.js
4410
+ function parsePromiseDef(def, refs) {
4411
+ return parseDef(def.type._def, refs);
4412
+ }
4413
+ //#endregion
4414
+ //#region ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@4.4.3/node_modules/zod-to-json-schema/dist/esm/parsers/set.js
4415
+ function parseSetDef(def, refs) {
4416
+ const schema = {
4417
+ type: "array",
4418
+ uniqueItems: true,
4419
+ items: parseDef(def.valueType._def, {
4420
+ ...refs,
4421
+ currentPath: [...refs.currentPath, "items"]
4422
+ })
4423
+ };
4424
+ if (def.minSize) setResponseValueAndErrors(schema, "minItems", def.minSize.value, def.minSize.message, refs);
4425
+ if (def.maxSize) setResponseValueAndErrors(schema, "maxItems", def.maxSize.value, def.maxSize.message, refs);
4426
+ return schema;
4427
+ }
4428
+ //#endregion
4429
+ //#region ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@4.4.3/node_modules/zod-to-json-schema/dist/esm/parsers/tuple.js
4430
+ function parseTupleDef(def, refs) {
4431
+ if (def.rest) return {
4432
+ type: "array",
4433
+ minItems: def.items.length,
4434
+ items: def.items.map((x, i) => parseDef(x._def, {
4435
+ ...refs,
4436
+ currentPath: [
4437
+ ...refs.currentPath,
4438
+ "items",
4439
+ `${i}`
4440
+ ]
4441
+ })).reduce((acc, x) => x === void 0 ? acc : [...acc, x], []),
4442
+ additionalItems: parseDef(def.rest._def, {
4443
+ ...refs,
4444
+ currentPath: [...refs.currentPath, "additionalItems"]
4445
+ })
4446
+ };
4447
+ else return {
4448
+ type: "array",
4449
+ minItems: def.items.length,
4450
+ maxItems: def.items.length,
4451
+ items: def.items.map((x, i) => parseDef(x._def, {
4452
+ ...refs,
4453
+ currentPath: [
4454
+ ...refs.currentPath,
4455
+ "items",
4456
+ `${i}`
4457
+ ]
4458
+ })).reduce((acc, x) => x === void 0 ? acc : [...acc, x], [])
4459
+ };
4460
+ }
4461
+ //#endregion
4462
+ //#region ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@4.4.3/node_modules/zod-to-json-schema/dist/esm/parsers/undefined.js
4463
+ function parseUndefinedDef(refs) {
4464
+ return { not: parseAnyDef(refs) };
4465
+ }
4466
+ //#endregion
4467
+ //#region ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@4.4.3/node_modules/zod-to-json-schema/dist/esm/parsers/unknown.js
4468
+ function parseUnknownDef(refs) {
4469
+ return parseAnyDef(refs);
4470
+ }
4471
+ //#endregion
4472
+ //#region ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@4.4.3/node_modules/zod-to-json-schema/dist/esm/parsers/readonly.js
4473
+ const parseReadonlyDef = (def, refs) => {
4474
+ return parseDef(def.innerType._def, refs);
4475
+ };
4476
+ //#endregion
4477
+ //#region ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@4.4.3/node_modules/zod-to-json-schema/dist/esm/selectParser.js
4478
+ const selectParser = (def, typeName, refs) => {
4479
+ switch (typeName) {
4480
+ case ZodFirstPartyTypeKind.ZodString: return parseStringDef(def, refs);
4481
+ case ZodFirstPartyTypeKind.ZodNumber: return parseNumberDef(def, refs);
4482
+ case ZodFirstPartyTypeKind.ZodObject: return parseObjectDef(def, refs);
4483
+ case ZodFirstPartyTypeKind.ZodBigInt: return parseBigintDef(def, refs);
4484
+ case ZodFirstPartyTypeKind.ZodBoolean: return parseBooleanDef();
4485
+ case ZodFirstPartyTypeKind.ZodDate: return parseDateDef(def, refs);
4486
+ case ZodFirstPartyTypeKind.ZodUndefined: return parseUndefinedDef(refs);
4487
+ case ZodFirstPartyTypeKind.ZodNull: return parseNullDef(refs);
4488
+ case ZodFirstPartyTypeKind.ZodArray: return parseArrayDef(def, refs);
4489
+ case ZodFirstPartyTypeKind.ZodUnion:
4490
+ case ZodFirstPartyTypeKind.ZodDiscriminatedUnion: return parseUnionDef(def, refs);
4491
+ case ZodFirstPartyTypeKind.ZodIntersection: return parseIntersectionDef(def, refs);
4492
+ case ZodFirstPartyTypeKind.ZodTuple: return parseTupleDef(def, refs);
4493
+ case ZodFirstPartyTypeKind.ZodRecord: return parseRecordDef(def, refs);
4494
+ case ZodFirstPartyTypeKind.ZodLiteral: return parseLiteralDef(def, refs);
4495
+ case ZodFirstPartyTypeKind.ZodEnum: return parseEnumDef(def);
4496
+ case ZodFirstPartyTypeKind.ZodNativeEnum: return parseNativeEnumDef(def);
4497
+ case ZodFirstPartyTypeKind.ZodNullable: return parseNullableDef(def, refs);
4498
+ case ZodFirstPartyTypeKind.ZodOptional: return parseOptionalDef(def, refs);
4499
+ case ZodFirstPartyTypeKind.ZodMap: return parseMapDef(def, refs);
4500
+ case ZodFirstPartyTypeKind.ZodSet: return parseSetDef(def, refs);
4501
+ case ZodFirstPartyTypeKind.ZodLazy: return () => def.getter()._def;
4502
+ case ZodFirstPartyTypeKind.ZodPromise: return parsePromiseDef(def, refs);
4503
+ case ZodFirstPartyTypeKind.ZodNaN:
4504
+ case ZodFirstPartyTypeKind.ZodNever: return parseNeverDef(refs);
4505
+ case ZodFirstPartyTypeKind.ZodEffects: return parseEffectsDef(def, refs);
4506
+ case ZodFirstPartyTypeKind.ZodAny: return parseAnyDef(refs);
4507
+ case ZodFirstPartyTypeKind.ZodUnknown: return parseUnknownDef(refs);
4508
+ case ZodFirstPartyTypeKind.ZodDefault: return parseDefaultDef(def, refs);
4509
+ case ZodFirstPartyTypeKind.ZodBranded: return parseBrandedDef(def, refs);
4510
+ case ZodFirstPartyTypeKind.ZodReadonly: return parseReadonlyDef(def, refs);
4511
+ case ZodFirstPartyTypeKind.ZodCatch: return parseCatchDef(def, refs);
4512
+ case ZodFirstPartyTypeKind.ZodPipeline: return parsePipelineDef(def, refs);
4513
+ case ZodFirstPartyTypeKind.ZodFunction:
4514
+ case ZodFirstPartyTypeKind.ZodVoid:
4515
+ case ZodFirstPartyTypeKind.ZodSymbol: return;
4516
+ default: return ((_) => void 0)(typeName);
4517
+ }
4518
+ };
4519
+ //#endregion
4520
+ //#region ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@4.4.3/node_modules/zod-to-json-schema/dist/esm/parseDef.js
4521
+ function parseDef(def, refs, forceResolution = false) {
4522
+ const seenItem = refs.seen.get(def);
4523
+ if (refs.override) {
4524
+ const overrideResult = refs.override?.(def, refs, seenItem, forceResolution);
4525
+ if (overrideResult !== ignoreOverride) return overrideResult;
4526
+ }
4527
+ if (seenItem && !forceResolution) {
4528
+ const seenSchema = get$ref(seenItem, refs);
4529
+ if (seenSchema !== void 0) return seenSchema;
4530
+ }
4531
+ const newItem = {
4532
+ def,
4533
+ path: refs.currentPath,
4534
+ jsonSchema: void 0
4535
+ };
4536
+ refs.seen.set(def, newItem);
4537
+ const jsonSchemaOrGetter = selectParser(def, def.typeName, refs);
4538
+ const jsonSchema = typeof jsonSchemaOrGetter === "function" ? parseDef(jsonSchemaOrGetter(), refs) : jsonSchemaOrGetter;
4539
+ if (jsonSchema) addMeta(def, refs, jsonSchema);
4540
+ if (refs.postProcess) {
4541
+ const postProcessResult = refs.postProcess(jsonSchema, def, refs);
4542
+ newItem.jsonSchema = jsonSchema;
4543
+ return postProcessResult;
4544
+ }
4545
+ newItem.jsonSchema = jsonSchema;
4546
+ return jsonSchema;
4547
+ }
4548
+ const get$ref = (item, refs) => {
4549
+ switch (refs.$refStrategy) {
4550
+ case "root": return { $ref: item.path.join("/") };
4551
+ case "relative": return { $ref: getRelativePath(refs.currentPath, item.path) };
4552
+ case "none":
4553
+ case "seen":
4554
+ if (item.path.length < refs.currentPath.length && item.path.every((value, index) => refs.currentPath[index] === value)) {
4555
+ console.warn(`Recursive reference detected at ${refs.currentPath.join("/")}! Defaulting to any`);
4556
+ return parseAnyDef(refs);
4557
+ }
4558
+ return refs.$refStrategy === "seen" ? parseAnyDef(refs) : void 0;
4559
+ }
4560
+ };
4561
+ const addMeta = (def, refs, jsonSchema) => {
4562
+ if (def.description) {
4563
+ jsonSchema.description = def.description;
4564
+ if (refs.markdownDescription) jsonSchema.markdownDescription = def.description;
4565
+ }
4566
+ return jsonSchema;
4567
+ };
4568
+ //#endregion
4569
+ //#region ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@4.4.3/node_modules/zod-to-json-schema/dist/esm/zodToJsonSchema.js
4570
+ const zodToJsonSchema = (schema, options) => {
4571
+ const refs = getRefs(options);
4572
+ let definitions = typeof options === "object" && options.definitions ? Object.entries(options.definitions).reduce((acc, [name, schema]) => ({
4573
+ ...acc,
4574
+ [name]: parseDef(schema._def, {
4575
+ ...refs,
4576
+ currentPath: [
4577
+ ...refs.basePath,
4578
+ refs.definitionPath,
4579
+ name
4580
+ ]
4581
+ }, true) ?? parseAnyDef(refs)
4582
+ }), {}) : void 0;
4583
+ const name = typeof options === "string" ? options : options?.nameStrategy === "title" ? void 0 : options?.name;
4584
+ const main = parseDef(schema._def, name === void 0 ? refs : {
4585
+ ...refs,
4586
+ currentPath: [
4587
+ ...refs.basePath,
4588
+ refs.definitionPath,
4589
+ name
4590
+ ]
4591
+ }, false) ?? parseAnyDef(refs);
4592
+ const title = typeof options === "object" && options.name !== void 0 && options.nameStrategy === "title" ? options.name : void 0;
4593
+ if (title !== void 0) main.title = title;
4594
+ if (refs.flags.hasReferencedOpenAiAnyType) {
4595
+ if (!definitions) definitions = {};
4596
+ if (!definitions[refs.openAiAnyTypeName]) definitions[refs.openAiAnyTypeName] = {
4597
+ type: [
4598
+ "string",
4599
+ "number",
4600
+ "integer",
4601
+ "boolean",
4602
+ "array",
4603
+ "null"
4604
+ ],
4605
+ items: { $ref: refs.$refStrategy === "relative" ? "1" : [
4606
+ ...refs.basePath,
4607
+ refs.definitionPath,
4608
+ refs.openAiAnyTypeName
4609
+ ].join("/") }
4610
+ };
4611
+ }
4612
+ const combined = name === void 0 ? definitions ? {
4613
+ ...main,
4614
+ [refs.definitionPath]: definitions
4615
+ } : main : {
4616
+ $ref: [
4617
+ ...refs.$refStrategy === "relative" ? [] : refs.basePath,
4618
+ refs.definitionPath,
4619
+ name
4620
+ ].join("/"),
4621
+ [refs.definitionPath]: {
4622
+ ...definitions,
4623
+ [name]: main
4624
+ }
4625
+ };
4626
+ if (refs.target === "jsonSchema7") combined.$schema = "http://json-schema.org/draft-07/schema#";
4627
+ else if (refs.target === "jsonSchema2019-09" || refs.target === "openAi") combined.$schema = "https://json-schema.org/draft/2019-09/schema#";
4628
+ if (refs.target === "openAi" && ("anyOf" in combined || "oneOf" in combined || "allOf" in combined || "type" in combined && Array.isArray(combined.type))) console.warn("Warning: OpenAI may not support schemas with unions as roots! Try wrapping it in an object property.");
4629
+ return combined;
4630
+ };
4631
+ //#endregion
4632
+ export { zodToJsonSchema };