@wise/dynamic-flow-types 2.11.0 → 2.12.0-experimental-6654c72

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