@dvmkit/dvm-cli 0.0.0 → 0.1.4

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