@chainflip/sdk 0.2.17 → 0.2.18

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