@chainflip/sdk 0.2.9 → 0.2.10

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