@statelyai/agent 0.0.6 → 0.0.8

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