tenjin-cli 0.1.0-alpha.14 → 0.1.0-alpha.15

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 (176) hide show
  1. package/README.md +18 -3
  2. package/dist/{buy-2JBYPHAI.js → buy-VIRNSYGN.js} +24 -23
  3. package/dist/{chunk-QWBUKIP2.js → chunk-2MYQN7HM.js} +66 -27
  4. package/dist/chunk-2MYQN7HM.js.map +1 -0
  5. package/dist/{chunk-DAZAXFSF.js → chunk-2RF2GIJQ.js} +57 -226
  6. package/dist/chunk-2RF2GIJQ.js.map +1 -0
  7. package/dist/{chunk-VEAERJVJ.js → chunk-3GL2Z5QK.js} +23 -9
  8. package/dist/chunk-3GL2Z5QK.js.map +1 -0
  9. package/dist/{chunk-IUQZ4Z7M.js → chunk-4CQIDQOT.js} +6 -1
  10. package/dist/chunk-4CQIDQOT.js.map +1 -0
  11. package/dist/{chunk-IXZJ3JOO.js → chunk-4KG27W2S.js} +10 -10
  12. package/dist/chunk-4KG27W2S.js.map +1 -0
  13. package/dist/{chunk-54AJIO3E.js → chunk-5QQTYWEU.js} +4 -3
  14. package/dist/chunk-5QQTYWEU.js.map +1 -0
  15. package/dist/chunk-65DTCCJ7.js +21 -0
  16. package/dist/chunk-65DTCCJ7.js.map +1 -0
  17. package/dist/{chunk-7NADDA2V.js → chunk-A5DKHMUN.js} +20 -8
  18. package/dist/chunk-A5DKHMUN.js.map +1 -0
  19. package/dist/{chunk-WYLMJQVH.js → chunk-B63XPWQ4.js} +24 -18
  20. package/dist/chunk-B63XPWQ4.js.map +1 -0
  21. package/dist/{chunk-L6G35FU5.js → chunk-CAR6FHK6.js} +5 -5
  22. package/dist/{chunk-7GJQ5RGA.js → chunk-CPCX67TI.js} +20 -22
  23. package/dist/{chunk-7GJQ5RGA.js.map → chunk-CPCX67TI.js.map} +1 -1
  24. package/dist/{chunk-XVPQGCH4.js → chunk-CQBVCYI2.js} +36 -50
  25. package/dist/chunk-CQBVCYI2.js.map +1 -0
  26. package/dist/chunk-DBU5CXBV.js +4731 -0
  27. package/dist/chunk-DBU5CXBV.js.map +1 -0
  28. package/dist/chunk-DHJD77OW.js +81 -0
  29. package/dist/chunk-DHJD77OW.js.map +1 -0
  30. package/dist/{chunk-XGZ5EVMB.js → chunk-EDZSNPE5.js} +2 -2
  31. package/dist/{chunk-736DW4V3.js → chunk-EFWZPUTC.js} +2 -2
  32. package/dist/chunk-EPFL6CTE.js +448 -0
  33. package/dist/chunk-EPFL6CTE.js.map +1 -0
  34. package/dist/{chunk-3P3ES4XU.js → chunk-GHLVXVZD.js} +3 -5
  35. package/dist/{chunk-3P3ES4XU.js.map → chunk-GHLVXVZD.js.map} +1 -1
  36. package/dist/{chunk-4UHNXY6B.js → chunk-H3SOOJ2I.js} +88 -294
  37. package/dist/chunk-H3SOOJ2I.js.map +1 -0
  38. package/dist/{chunk-MJSXP4LW.js → chunk-HPJGOLTN.js} +6 -8
  39. package/dist/{chunk-MJSXP4LW.js.map → chunk-HPJGOLTN.js.map} +1 -1
  40. package/dist/{chunk-J6FUAIRR.js → chunk-HRGBS2PA.js} +4 -6
  41. package/dist/{chunk-J6FUAIRR.js.map → chunk-HRGBS2PA.js.map} +1 -1
  42. package/dist/{chunk-FDUD3W5V.js → chunk-ITUXPJIS.js} +55 -58
  43. package/dist/chunk-ITUXPJIS.js.map +1 -0
  44. package/dist/{chunk-ETKZWJ4B.js → chunk-JBIKAAT3.js} +2 -2
  45. package/dist/{chunk-ETKZWJ4B.js.map → chunk-JBIKAAT3.js.map} +1 -1
  46. package/dist/{chunk-3ZW7HPY5.js → chunk-KAJZHIQ4.js} +13 -10
  47. package/dist/chunk-KAJZHIQ4.js.map +1 -0
  48. package/dist/{chunk-OWVVI4VQ.js → chunk-KINZ23CV.js} +107 -4535
  49. package/dist/chunk-KINZ23CV.js.map +1 -0
  50. package/dist/{chunk-PCX2JQ2J.js → chunk-LRYV3SK7.js} +9 -7
  51. package/dist/{chunk-PCX2JQ2J.js.map → chunk-LRYV3SK7.js.map} +1 -1
  52. package/dist/{chunk-ACBEHJAH.js → chunk-NIKXHWOL.js} +11 -13
  53. package/dist/{chunk-ACBEHJAH.js.map → chunk-NIKXHWOL.js.map} +1 -1
  54. package/dist/chunk-OKDRDT74.js +209 -0
  55. package/dist/chunk-OKDRDT74.js.map +1 -0
  56. package/dist/chunk-OKYSNAS3.js +2144 -0
  57. package/dist/chunk-OKYSNAS3.js.map +1 -0
  58. package/dist/{chunk-B676GPS2.js → chunk-OLWTRUTS.js} +7 -3
  59. package/dist/{chunk-B676GPS2.js.map → chunk-OLWTRUTS.js.map} +1 -1
  60. package/dist/{chunk-WU5CZPLD.js → chunk-QQ6ELLSA.js} +6 -8
  61. package/dist/{chunk-WU5CZPLD.js.map → chunk-QQ6ELLSA.js.map} +1 -1
  62. package/dist/{chunk-NAAMHWSI.js → chunk-QZ6ROAJU.js} +5 -4
  63. package/dist/chunk-QZ6ROAJU.js.map +1 -0
  64. package/dist/{chunk-GEHL43VE.js → chunk-R7RSCBI7.js} +130 -47
  65. package/dist/chunk-R7RSCBI7.js.map +1 -0
  66. package/dist/{chunk-LSWP7MU2.js → chunk-U6VPKMGC.js} +127 -27
  67. package/dist/chunk-U6VPKMGC.js.map +1 -0
  68. package/dist/{chunk-W4VW5XYB.js → chunk-US456VUI.js} +6 -6
  69. package/dist/{chunk-O75FOHXS.js → chunk-V44J2MXV.js} +64 -36
  70. package/dist/chunk-V44J2MXV.js.map +1 -0
  71. package/dist/{chunk-4Y53PDH6.js → chunk-VJQKL3YH.js} +10 -7
  72. package/dist/{chunk-4Y53PDH6.js.map → chunk-VJQKL3YH.js.map} +1 -1
  73. package/dist/{chunk-VRPLZERE.js → chunk-VJSQSLBM.js} +47 -26
  74. package/dist/chunk-VJSQSLBM.js.map +1 -0
  75. package/dist/{chunk-PKW3H26Z.js → chunk-VYOJOX4Z.js} +9 -7
  76. package/dist/chunk-VYOJOX4Z.js.map +1 -0
  77. package/dist/chunk-WY2K35OL.js +269 -0
  78. package/dist/chunk-WY2K35OL.js.map +1 -0
  79. package/dist/{chunk-PAOVPSP6.js → chunk-ZFJJ3EXC.js} +53 -5
  80. package/dist/chunk-ZFJJ3EXC.js.map +1 -0
  81. package/dist/{cli-U2BEUA55.js → cli-KKRKBU5T.js} +71 -40
  82. package/dist/{cli-U2BEUA55.js.map → cli-KKRKBU5T.js.map} +1 -1
  83. package/dist/config-JMRUNYE6.js +37 -0
  84. package/dist/discover-B5HF6SHM.js +102 -0
  85. package/dist/discover-B5HF6SHM.js.map +1 -0
  86. package/dist/doctor-ZBG7X66D.js +32 -0
  87. package/dist/edit-PZJIILQE.js +40 -0
  88. package/dist/{fund-Y5IAHZ5D.js → fund-EUDH5KPA.js} +19 -19
  89. package/dist/index.js +1 -1
  90. package/dist/{inspect-NFQ6SQQQ.js → inspect-QC6WEQPN.js} +20 -20
  91. package/dist/{install-DXX7PVUP.js → install-GNK2W3PI.js} +196 -78
  92. package/dist/install-GNK2W3PI.js.map +1 -0
  93. package/dist/outcome-KSGWZHUS.js +24 -0
  94. package/dist/pay-BC4UICPA.js +361 -0
  95. package/dist/pay-BC4UICPA.js.map +1 -0
  96. package/dist/publish-LXWFDIKF.js +42 -0
  97. package/dist/{read-W7QVRBVD.js → read-JMNUQ56P.js} +21 -21
  98. package/dist/{run-CJWPGMIQ.js → run-XYTQ5TWQ.js} +52 -45
  99. package/dist/{run-CJWPGMIQ.js.map → run-XYTQ5TWQ.js.map} +1 -1
  100. package/dist/search-TSQAB45E.js +25 -0
  101. package/dist/{send-C5EOKXOU.js → send-G746D7PQ.js} +14 -15
  102. package/dist/{send-C5EOKXOU.js.map → send-G746D7PQ.js.map} +1 -1
  103. package/dist/{session-OBCUUIFX.js → session-JBKWMJ24.js} +17 -17
  104. package/dist/{skill-heal-D6EPLPS6.js → skill-heal-WKD67SLJ.js} +17 -9
  105. package/dist/skill-heal-WKD67SLJ.js.map +1 -0
  106. package/dist/skill-placement-RIU4AMC2.js +20 -0
  107. package/dist/{uninstall-OWJNJ5LI.js → uninstall-5E263VTS.js} +12 -12
  108. package/dist/uninstall-5E263VTS.js.map +1 -0
  109. package/dist/{update-24Y2CQTT.js → update-R76LHOZW.js} +7 -8
  110. package/dist/{update-24Y2CQTT.js.map → update-R76LHOZW.js.map} +1 -1
  111. package/dist/{wallet-SLRIYJ2U.js → wallet-TQ7D5EQ7.js} +7 -8
  112. package/dist/{wallet-OFXDIIGP.js → wallet-ZAVXWLWP.js} +11 -12
  113. package/dist/wallet-ZAVXWLWP.js.map +1 -0
  114. package/docs/agent-permissions.md +17 -2
  115. package/docs/command-reference.md +84 -42
  116. package/docs/safety-model.md +9 -0
  117. package/package.json +1 -1
  118. package/skills/tenjin/SKILL.md +38 -29
  119. package/skills/tenjin-pay/SKILL.md +76 -0
  120. package/skills/tenjin-publish/SKILL.md +10 -7
  121. package/skills/tenjin-search/SKILL.md +18 -13
  122. package/skills/tenjin-search/references/permissions.md +9 -3
  123. package/dist/chunk-3ZW7HPY5.js.map +0 -1
  124. package/dist/chunk-4UHNXY6B.js.map +0 -1
  125. package/dist/chunk-54AJIO3E.js.map +0 -1
  126. package/dist/chunk-7NADDA2V.js.map +0 -1
  127. package/dist/chunk-DAZAXFSF.js.map +0 -1
  128. package/dist/chunk-DTCXO7HS.js +0 -791
  129. package/dist/chunk-DTCXO7HS.js.map +0 -1
  130. package/dist/chunk-FDUD3W5V.js.map +0 -1
  131. package/dist/chunk-GEHL43VE.js.map +0 -1
  132. package/dist/chunk-IU2HVT3Y.js +0 -313
  133. package/dist/chunk-IU2HVT3Y.js.map +0 -1
  134. package/dist/chunk-IUQZ4Z7M.js.map +0 -1
  135. package/dist/chunk-IXZJ3JOO.js.map +0 -1
  136. package/dist/chunk-LSWP7MU2.js.map +0 -1
  137. package/dist/chunk-NAAMHWSI.js.map +0 -1
  138. package/dist/chunk-O75FOHXS.js.map +0 -1
  139. package/dist/chunk-OWVVI4VQ.js.map +0 -1
  140. package/dist/chunk-PAOVPSP6.js.map +0 -1
  141. package/dist/chunk-PKW3H26Z.js.map +0 -1
  142. package/dist/chunk-PQZVDCCA.js +0 -125
  143. package/dist/chunk-PQZVDCCA.js.map +0 -1
  144. package/dist/chunk-QWBUKIP2.js.map +0 -1
  145. package/dist/chunk-VEAERJVJ.js.map +0 -1
  146. package/dist/chunk-VRPLZERE.js.map +0 -1
  147. package/dist/chunk-WYLMJQVH.js.map +0 -1
  148. package/dist/chunk-XVPQGCH4.js.map +0 -1
  149. package/dist/chunk-ZQIQ55KK.js +0 -51
  150. package/dist/chunk-ZQIQ55KK.js.map +0 -1
  151. package/dist/config-CNUIX23Q.js +0 -32
  152. package/dist/doctor-QJJXRWTO.js +0 -31
  153. package/dist/edit-HJ44P44P.js +0 -40
  154. package/dist/install-DXX7PVUP.js.map +0 -1
  155. package/dist/outcome-ANV4QIED.js +0 -24
  156. package/dist/publish-PCBTCXCZ.js +0 -42
  157. package/dist/search-JGAVKTYJ.js +0 -25
  158. package/dist/skill-heal-D6EPLPS6.js.map +0 -1
  159. package/dist/uninstall-OWJNJ5LI.js.map +0 -1
  160. /package/dist/{buy-2JBYPHAI.js.map → buy-VIRNSYGN.js.map} +0 -0
  161. /package/dist/{chunk-L6G35FU5.js.map → chunk-CAR6FHK6.js.map} +0 -0
  162. /package/dist/{chunk-XGZ5EVMB.js.map → chunk-EDZSNPE5.js.map} +0 -0
  163. /package/dist/{chunk-736DW4V3.js.map → chunk-EFWZPUTC.js.map} +0 -0
  164. /package/dist/{chunk-W4VW5XYB.js.map → chunk-US456VUI.js.map} +0 -0
  165. /package/dist/{config-CNUIX23Q.js.map → config-JMRUNYE6.js.map} +0 -0
  166. /package/dist/{doctor-QJJXRWTO.js.map → doctor-ZBG7X66D.js.map} +0 -0
  167. /package/dist/{edit-HJ44P44P.js.map → edit-PZJIILQE.js.map} +0 -0
  168. /package/dist/{fund-Y5IAHZ5D.js.map → fund-EUDH5KPA.js.map} +0 -0
  169. /package/dist/{inspect-NFQ6SQQQ.js.map → inspect-QC6WEQPN.js.map} +0 -0
  170. /package/dist/{outcome-ANV4QIED.js.map → outcome-KSGWZHUS.js.map} +0 -0
  171. /package/dist/{publish-PCBTCXCZ.js.map → publish-LXWFDIKF.js.map} +0 -0
  172. /package/dist/{read-W7QVRBVD.js.map → read-JMNUQ56P.js.map} +0 -0
  173. /package/dist/{search-JGAVKTYJ.js.map → search-TSQAB45E.js.map} +0 -0
  174. /package/dist/{session-OBCUUIFX.js.map → session-JBKWMJ24.js.map} +0 -0
  175. /package/dist/{wallet-OFXDIIGP.js.map → skill-placement-RIU4AMC2.js.map} +0 -0
  176. /package/dist/{wallet-SLRIYJ2U.js.map → wallet-TQ7D5EQ7.js.map} +0 -0
@@ -1,4 +1,8 @@
1
1
  import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
2
+ import {
3
+ external_exports,
4
+ safeBase64Encode
5
+ } from "./chunk-DBU5CXBV.js";
2
6
  import {
3
7
  AbiDecodingDataSizeTooSmallError,
4
8
  AbiDecodingZeroDataError,
@@ -2310,4195 +2314,105 @@ var require_nacl_fast = __commonJS({
2310
2314
  if (publicKey.length !== crypto_sign_PUBLICKEYBYTES)
2311
2315
  throw new Error("bad public key size");
2312
2316
  var tmp = new Uint8Array(signedMsg.length);
2313
- var mlen = crypto_sign_open(tmp, signedMsg, signedMsg.length, publicKey);
2314
- if (mlen < 0) return null;
2315
- var m3 = new Uint8Array(mlen);
2316
- for (var i3 = 0; i3 < m3.length; i3++) m3[i3] = tmp[i3];
2317
- return m3;
2318
- };
2319
- nacl2.sign.detached = function(msg, secretKey) {
2320
- var signedMsg = nacl2.sign(msg, secretKey);
2321
- var sig = new Uint8Array(crypto_sign_BYTES);
2322
- for (var i3 = 0; i3 < sig.length; i3++) sig[i3] = signedMsg[i3];
2323
- return sig;
2324
- };
2325
- nacl2.sign.detached.verify = function(msg, sig, publicKey) {
2326
- checkArrayTypes(msg, sig, publicKey);
2327
- if (sig.length !== crypto_sign_BYTES)
2328
- throw new Error("bad signature size");
2329
- if (publicKey.length !== crypto_sign_PUBLICKEYBYTES)
2330
- throw new Error("bad public key size");
2331
- var sm = new Uint8Array(crypto_sign_BYTES + msg.length);
2332
- var m3 = new Uint8Array(crypto_sign_BYTES + msg.length);
2333
- var i3;
2334
- for (i3 = 0; i3 < crypto_sign_BYTES; i3++) sm[i3] = sig[i3];
2335
- for (i3 = 0; i3 < msg.length; i3++) sm[i3 + crypto_sign_BYTES] = msg[i3];
2336
- return crypto_sign_open(m3, sm, sm.length, publicKey) >= 0;
2337
- };
2338
- nacl2.sign.keyPair = function() {
2339
- var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
2340
- var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES);
2341
- crypto_sign_keypair(pk, sk);
2342
- return { publicKey: pk, secretKey: sk };
2343
- };
2344
- nacl2.sign.keyPair.fromSecretKey = function(secretKey) {
2345
- checkArrayTypes(secretKey);
2346
- if (secretKey.length !== crypto_sign_SECRETKEYBYTES)
2347
- throw new Error("bad secret key size");
2348
- var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
2349
- for (var i3 = 0; i3 < pk.length; i3++) pk[i3] = secretKey[32 + i3];
2350
- return { publicKey: pk, secretKey: new Uint8Array(secretKey) };
2351
- };
2352
- nacl2.sign.keyPair.fromSeed = function(seed) {
2353
- checkArrayTypes(seed);
2354
- if (seed.length !== crypto_sign_SEEDBYTES)
2355
- throw new Error("bad seed size");
2356
- var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
2357
- var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES);
2358
- for (var i3 = 0; i3 < 32; i3++) sk[i3] = seed[i3];
2359
- crypto_sign_keypair(pk, sk, true);
2360
- return { publicKey: pk, secretKey: sk };
2361
- };
2362
- nacl2.sign.publicKeyLength = crypto_sign_PUBLICKEYBYTES;
2363
- nacl2.sign.secretKeyLength = crypto_sign_SECRETKEYBYTES;
2364
- nacl2.sign.seedLength = crypto_sign_SEEDBYTES;
2365
- nacl2.sign.signatureLength = crypto_sign_BYTES;
2366
- nacl2.hash = function(msg) {
2367
- checkArrayTypes(msg);
2368
- var h2 = new Uint8Array(crypto_hash_BYTES);
2369
- crypto_hash(h2, msg, msg.length);
2370
- return h2;
2371
- };
2372
- nacl2.hash.hashLength = crypto_hash_BYTES;
2373
- nacl2.verify = function(x, y) {
2374
- checkArrayTypes(x, y);
2375
- if (x.length === 0 || y.length === 0) return false;
2376
- if (x.length !== y.length) return false;
2377
- return vn(x, 0, y, 0, x.length) === 0 ? true : false;
2378
- };
2379
- nacl2.setPRNG = function(fn) {
2380
- randombytes = fn;
2381
- };
2382
- (function() {
2383
- var crypto = typeof self !== "undefined" ? self.crypto || self.msCrypto : null;
2384
- if (crypto && crypto.getRandomValues) {
2385
- var QUOTA = 65536;
2386
- nacl2.setPRNG(function(x, n2) {
2387
- var i3, v = new Uint8Array(n2);
2388
- for (i3 = 0; i3 < n2; i3 += QUOTA) {
2389
- crypto.getRandomValues(v.subarray(i3, i3 + Math.min(n2 - i3, QUOTA)));
2390
- }
2391
- for (i3 = 0; i3 < n2; i3++) x[i3] = v[i3];
2392
- cleanup(v);
2393
- });
2394
- } else if (typeof __require !== "undefined") {
2395
- crypto = __require("crypto");
2396
- if (crypto && crypto.randomBytes) {
2397
- nacl2.setPRNG(function(x, n2) {
2398
- var i3, v = crypto.randomBytes(n2);
2399
- for (i3 = 0; i3 < n2; i3++) x[i3] = v[i3];
2400
- cleanup(v);
2401
- });
2402
- }
2403
- }
2404
- })();
2405
- })(typeof module !== "undefined" && module.exports ? module.exports : self.nacl = self.nacl || {});
2406
- }
2407
- });
2408
-
2409
- // src/lib/siwx.ts
2410
- import { randomUUID } from "crypto";
2411
-
2412
- // node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/external.js
2413
- var external_exports = {};
2414
- __export(external_exports, {
2415
- BRAND: () => BRAND,
2416
- DIRTY: () => DIRTY,
2417
- EMPTY_PATH: () => EMPTY_PATH,
2418
- INVALID: () => INVALID,
2419
- NEVER: () => NEVER,
2420
- OK: () => OK,
2421
- ParseStatus: () => ParseStatus,
2422
- Schema: () => ZodType,
2423
- ZodAny: () => ZodAny,
2424
- ZodArray: () => ZodArray,
2425
- ZodBigInt: () => ZodBigInt,
2426
- ZodBoolean: () => ZodBoolean,
2427
- ZodBranded: () => ZodBranded,
2428
- ZodCatch: () => ZodCatch,
2429
- ZodDate: () => ZodDate,
2430
- ZodDefault: () => ZodDefault,
2431
- ZodDiscriminatedUnion: () => ZodDiscriminatedUnion,
2432
- ZodEffects: () => ZodEffects,
2433
- ZodEnum: () => ZodEnum,
2434
- ZodError: () => ZodError,
2435
- ZodFirstPartyTypeKind: () => ZodFirstPartyTypeKind,
2436
- ZodFunction: () => ZodFunction,
2437
- ZodIntersection: () => ZodIntersection,
2438
- ZodIssueCode: () => ZodIssueCode,
2439
- ZodLazy: () => ZodLazy,
2440
- ZodLiteral: () => ZodLiteral,
2441
- ZodMap: () => ZodMap,
2442
- ZodNaN: () => ZodNaN,
2443
- ZodNativeEnum: () => ZodNativeEnum,
2444
- ZodNever: () => ZodNever,
2445
- ZodNull: () => ZodNull,
2446
- ZodNullable: () => ZodNullable,
2447
- ZodNumber: () => ZodNumber,
2448
- ZodObject: () => ZodObject,
2449
- ZodOptional: () => ZodOptional,
2450
- ZodParsedType: () => ZodParsedType,
2451
- ZodPipeline: () => ZodPipeline,
2452
- ZodPromise: () => ZodPromise,
2453
- ZodReadonly: () => ZodReadonly,
2454
- ZodRecord: () => ZodRecord,
2455
- ZodSchema: () => ZodType,
2456
- ZodSet: () => ZodSet,
2457
- ZodString: () => ZodString,
2458
- ZodSymbol: () => ZodSymbol,
2459
- ZodTransformer: () => ZodEffects,
2460
- ZodTuple: () => ZodTuple,
2461
- ZodType: () => ZodType,
2462
- ZodUndefined: () => ZodUndefined,
2463
- ZodUnion: () => ZodUnion,
2464
- ZodUnknown: () => ZodUnknown,
2465
- ZodVoid: () => ZodVoid,
2466
- addIssueToContext: () => addIssueToContext,
2467
- any: () => anyType,
2468
- array: () => arrayType,
2469
- bigint: () => bigIntType,
2470
- boolean: () => booleanType,
2471
- coerce: () => coerce,
2472
- custom: () => custom,
2473
- date: () => dateType,
2474
- datetimeRegex: () => datetimeRegex,
2475
- defaultErrorMap: () => en_default,
2476
- discriminatedUnion: () => discriminatedUnionType,
2477
- effect: () => effectsType,
2478
- enum: () => enumType,
2479
- function: () => functionType,
2480
- getErrorMap: () => getErrorMap,
2481
- getParsedType: () => getParsedType,
2482
- instanceof: () => instanceOfType,
2483
- intersection: () => intersectionType,
2484
- isAborted: () => isAborted,
2485
- isAsync: () => isAsync,
2486
- isDirty: () => isDirty,
2487
- isValid: () => isValid,
2488
- late: () => late,
2489
- lazy: () => lazyType,
2490
- literal: () => literalType,
2491
- makeIssue: () => makeIssue,
2492
- map: () => mapType,
2493
- nan: () => nanType,
2494
- nativeEnum: () => nativeEnumType,
2495
- never: () => neverType,
2496
- null: () => nullType,
2497
- nullable: () => nullableType,
2498
- number: () => numberType,
2499
- object: () => objectType,
2500
- objectUtil: () => objectUtil,
2501
- oboolean: () => oboolean,
2502
- onumber: () => onumber,
2503
- optional: () => optionalType,
2504
- ostring: () => ostring,
2505
- pipeline: () => pipelineType,
2506
- preprocess: () => preprocessType,
2507
- promise: () => promiseType,
2508
- quotelessJson: () => quotelessJson,
2509
- record: () => recordType,
2510
- set: () => setType,
2511
- setErrorMap: () => setErrorMap,
2512
- strictObject: () => strictObjectType,
2513
- string: () => stringType,
2514
- symbol: () => symbolType,
2515
- transformer: () => effectsType,
2516
- tuple: () => tupleType,
2517
- undefined: () => undefinedType,
2518
- union: () => unionType,
2519
- unknown: () => unknownType,
2520
- util: () => util,
2521
- void: () => voidType
2522
- });
2523
-
2524
- // node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/util.js
2525
- var util;
2526
- (function(util2) {
2527
- util2.assertEqual = (_) => {
2528
- };
2529
- function assertIs(_arg) {
2530
- }
2531
- util2.assertIs = assertIs;
2532
- function assertNever(_x) {
2533
- throw new Error();
2534
- }
2535
- util2.assertNever = assertNever;
2536
- util2.arrayToEnum = (items) => {
2537
- const obj = {};
2538
- for (const item of items) {
2539
- obj[item] = item;
2540
- }
2541
- return obj;
2542
- };
2543
- util2.getValidEnumValues = (obj) => {
2544
- const validKeys = util2.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
2545
- const filtered = {};
2546
- for (const k of validKeys) {
2547
- filtered[k] = obj[k];
2548
- }
2549
- return util2.objectValues(filtered);
2550
- };
2551
- util2.objectValues = (obj) => {
2552
- return util2.objectKeys(obj).map(function(e) {
2553
- return obj[e];
2554
- });
2555
- };
2556
- util2.objectKeys = typeof Object.keys === "function" ? (obj) => Object.keys(obj) : (object) => {
2557
- const keys = [];
2558
- for (const key in object) {
2559
- if (Object.prototype.hasOwnProperty.call(object, key)) {
2560
- keys.push(key);
2561
- }
2562
- }
2563
- return keys;
2564
- };
2565
- util2.find = (arr, checker) => {
2566
- for (const item of arr) {
2567
- if (checker(item))
2568
- return item;
2569
- }
2570
- return void 0;
2571
- };
2572
- util2.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && Number.isFinite(val) && Math.floor(val) === val;
2573
- function joinValues(array, separator = " | ") {
2574
- return array.map((val) => typeof val === "string" ? `'${val}'` : val).join(separator);
2575
- }
2576
- util2.joinValues = joinValues;
2577
- util2.jsonStringifyReplacer = (_, value) => {
2578
- if (typeof value === "bigint") {
2579
- return value.toString();
2580
- }
2581
- return value;
2582
- };
2583
- })(util || (util = {}));
2584
- var objectUtil;
2585
- (function(objectUtil2) {
2586
- objectUtil2.mergeShapes = (first, second) => {
2587
- return {
2588
- ...first,
2589
- ...second
2590
- // second overwrites first
2591
- };
2592
- };
2593
- })(objectUtil || (objectUtil = {}));
2594
- var ZodParsedType = util.arrayToEnum([
2595
- "string",
2596
- "nan",
2597
- "number",
2598
- "integer",
2599
- "float",
2600
- "boolean",
2601
- "date",
2602
- "bigint",
2603
- "symbol",
2604
- "function",
2605
- "undefined",
2606
- "null",
2607
- "array",
2608
- "object",
2609
- "unknown",
2610
- "promise",
2611
- "void",
2612
- "never",
2613
- "map",
2614
- "set"
2615
- ]);
2616
- var getParsedType = (data) => {
2617
- const t2 = typeof data;
2618
- switch (t2) {
2619
- case "undefined":
2620
- return ZodParsedType.undefined;
2621
- case "string":
2622
- return ZodParsedType.string;
2623
- case "number":
2624
- return Number.isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
2625
- case "boolean":
2626
- return ZodParsedType.boolean;
2627
- case "function":
2628
- return ZodParsedType.function;
2629
- case "bigint":
2630
- return ZodParsedType.bigint;
2631
- case "symbol":
2632
- return ZodParsedType.symbol;
2633
- case "object":
2634
- if (Array.isArray(data)) {
2635
- return ZodParsedType.array;
2636
- }
2637
- if (data === null) {
2638
- return ZodParsedType.null;
2639
- }
2640
- if (data.then && typeof data.then === "function" && data.catch && typeof data.catch === "function") {
2641
- return ZodParsedType.promise;
2642
- }
2643
- if (typeof Map !== "undefined" && data instanceof Map) {
2644
- return ZodParsedType.map;
2645
- }
2646
- if (typeof Set !== "undefined" && data instanceof Set) {
2647
- return ZodParsedType.set;
2648
- }
2649
- if (typeof Date !== "undefined" && data instanceof Date) {
2650
- return ZodParsedType.date;
2651
- }
2652
- return ZodParsedType.object;
2653
- default:
2654
- return ZodParsedType.unknown;
2655
- }
2656
- };
2657
-
2658
- // node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/ZodError.js
2659
- var ZodIssueCode = util.arrayToEnum([
2660
- "invalid_type",
2661
- "invalid_literal",
2662
- "custom",
2663
- "invalid_union",
2664
- "invalid_union_discriminator",
2665
- "invalid_enum_value",
2666
- "unrecognized_keys",
2667
- "invalid_arguments",
2668
- "invalid_return_type",
2669
- "invalid_date",
2670
- "invalid_string",
2671
- "too_small",
2672
- "too_big",
2673
- "invalid_intersection_types",
2674
- "not_multiple_of",
2675
- "not_finite"
2676
- ]);
2677
- var quotelessJson = (obj) => {
2678
- const json = JSON.stringify(obj, null, 2);
2679
- return json.replace(/"([^"]+)":/g, "$1:");
2680
- };
2681
- var ZodError = class _ZodError extends Error {
2682
- get errors() {
2683
- return this.issues;
2684
- }
2685
- constructor(issues) {
2686
- super();
2687
- this.issues = [];
2688
- this.addIssue = (sub) => {
2689
- this.issues = [...this.issues, sub];
2690
- };
2691
- this.addIssues = (subs = []) => {
2692
- this.issues = [...this.issues, ...subs];
2693
- };
2694
- const actualProto = new.target.prototype;
2695
- if (Object.setPrototypeOf) {
2696
- Object.setPrototypeOf(this, actualProto);
2697
- } else {
2698
- this.__proto__ = actualProto;
2699
- }
2700
- this.name = "ZodError";
2701
- this.issues = issues;
2702
- }
2703
- format(_mapper) {
2704
- const mapper = _mapper || function(issue) {
2705
- return issue.message;
2706
- };
2707
- const fieldErrors = { _errors: [] };
2708
- const processError = (error) => {
2709
- for (const issue of error.issues) {
2710
- if (issue.code === "invalid_union") {
2711
- issue.unionErrors.map(processError);
2712
- } else if (issue.code === "invalid_return_type") {
2713
- processError(issue.returnTypeError);
2714
- } else if (issue.code === "invalid_arguments") {
2715
- processError(issue.argumentsError);
2716
- } else if (issue.path.length === 0) {
2717
- fieldErrors._errors.push(mapper(issue));
2718
- } else {
2719
- let curr = fieldErrors;
2720
- let i3 = 0;
2721
- while (i3 < issue.path.length) {
2722
- const el = issue.path[i3];
2723
- const terminal = i3 === issue.path.length - 1;
2724
- if (!terminal) {
2725
- curr[el] = curr[el] || { _errors: [] };
2726
- } else {
2727
- curr[el] = curr[el] || { _errors: [] };
2728
- curr[el]._errors.push(mapper(issue));
2729
- }
2730
- curr = curr[el];
2731
- i3++;
2732
- }
2733
- }
2734
- }
2735
- };
2736
- processError(this);
2737
- return fieldErrors;
2738
- }
2739
- static assert(value) {
2740
- if (!(value instanceof _ZodError)) {
2741
- throw new Error(`Not a ZodError: ${value}`);
2742
- }
2743
- }
2744
- toString() {
2745
- return this.message;
2746
- }
2747
- get message() {
2748
- return JSON.stringify(this.issues, util.jsonStringifyReplacer, 2);
2749
- }
2750
- get isEmpty() {
2751
- return this.issues.length === 0;
2752
- }
2753
- flatten(mapper = (issue) => issue.message) {
2754
- const fieldErrors = {};
2755
- const formErrors = [];
2756
- for (const sub of this.issues) {
2757
- if (sub.path.length > 0) {
2758
- const firstEl = sub.path[0];
2759
- fieldErrors[firstEl] = fieldErrors[firstEl] || [];
2760
- fieldErrors[firstEl].push(mapper(sub));
2761
- } else {
2762
- formErrors.push(mapper(sub));
2763
- }
2764
- }
2765
- return { formErrors, fieldErrors };
2766
- }
2767
- get formErrors() {
2768
- return this.flatten();
2769
- }
2770
- };
2771
- ZodError.create = (issues) => {
2772
- const error = new ZodError(issues);
2773
- return error;
2774
- };
2775
-
2776
- // node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/locales/en.js
2777
- var errorMap = (issue, _ctx) => {
2778
- let message;
2779
- switch (issue.code) {
2780
- case ZodIssueCode.invalid_type:
2781
- if (issue.received === ZodParsedType.undefined) {
2782
- message = "Required";
2783
- } else {
2784
- message = `Expected ${issue.expected}, received ${issue.received}`;
2785
- }
2786
- break;
2787
- case ZodIssueCode.invalid_literal:
2788
- message = `Invalid literal value, expected ${JSON.stringify(issue.expected, util.jsonStringifyReplacer)}`;
2789
- break;
2790
- case ZodIssueCode.unrecognized_keys:
2791
- message = `Unrecognized key(s) in object: ${util.joinValues(issue.keys, ", ")}`;
2792
- break;
2793
- case ZodIssueCode.invalid_union:
2794
- message = `Invalid input`;
2795
- break;
2796
- case ZodIssueCode.invalid_union_discriminator:
2797
- message = `Invalid discriminator value. Expected ${util.joinValues(issue.options)}`;
2798
- break;
2799
- case ZodIssueCode.invalid_enum_value:
2800
- message = `Invalid enum value. Expected ${util.joinValues(issue.options)}, received '${issue.received}'`;
2801
- break;
2802
- case ZodIssueCode.invalid_arguments:
2803
- message = `Invalid function arguments`;
2804
- break;
2805
- case ZodIssueCode.invalid_return_type:
2806
- message = `Invalid function return type`;
2807
- break;
2808
- case ZodIssueCode.invalid_date:
2809
- message = `Invalid date`;
2810
- break;
2811
- case ZodIssueCode.invalid_string:
2812
- if (typeof issue.validation === "object") {
2813
- if ("includes" in issue.validation) {
2814
- message = `Invalid input: must include "${issue.validation.includes}"`;
2815
- if (typeof issue.validation.position === "number") {
2816
- message = `${message} at one or more positions greater than or equal to ${issue.validation.position}`;
2817
- }
2818
- } else if ("startsWith" in issue.validation) {
2819
- message = `Invalid input: must start with "${issue.validation.startsWith}"`;
2820
- } else if ("endsWith" in issue.validation) {
2821
- message = `Invalid input: must end with "${issue.validation.endsWith}"`;
2822
- } else {
2823
- util.assertNever(issue.validation);
2824
- }
2825
- } else if (issue.validation !== "regex") {
2826
- message = `Invalid ${issue.validation}`;
2827
- } else {
2828
- message = "Invalid";
2829
- }
2830
- break;
2831
- case ZodIssueCode.too_small:
2832
- if (issue.type === "array")
2833
- message = `Array must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `more than`} ${issue.minimum} element(s)`;
2834
- else if (issue.type === "string")
2835
- message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
2836
- else if (issue.type === "number")
2837
- message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
2838
- else if (issue.type === "bigint")
2839
- message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
2840
- else if (issue.type === "date")
2841
- message = `Date must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${new Date(Number(issue.minimum))}`;
2842
- else
2843
- message = "Invalid input";
2844
- break;
2845
- case ZodIssueCode.too_big:
2846
- if (issue.type === "array")
2847
- message = `Array must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `less than`} ${issue.maximum} element(s)`;
2848
- else if (issue.type === "string")
2849
- message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
2850
- else if (issue.type === "number")
2851
- message = `Number must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
2852
- else if (issue.type === "bigint")
2853
- message = `BigInt must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
2854
- else if (issue.type === "date")
2855
- message = `Date must be ${issue.exact ? `exactly` : issue.inclusive ? `smaller than or equal to` : `smaller than`} ${new Date(Number(issue.maximum))}`;
2856
- else
2857
- message = "Invalid input";
2858
- break;
2859
- case ZodIssueCode.custom:
2860
- message = `Invalid input`;
2861
- break;
2862
- case ZodIssueCode.invalid_intersection_types:
2863
- message = `Intersection results could not be merged`;
2864
- break;
2865
- case ZodIssueCode.not_multiple_of:
2866
- message = `Number must be a multiple of ${issue.multipleOf}`;
2867
- break;
2868
- case ZodIssueCode.not_finite:
2869
- message = "Number must be finite";
2870
- break;
2871
- default:
2872
- message = _ctx.defaultError;
2873
- util.assertNever(issue);
2874
- }
2875
- return { message };
2876
- };
2877
- var en_default = errorMap;
2878
-
2879
- // node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/errors.js
2880
- var overrideErrorMap = en_default;
2881
- function setErrorMap(map) {
2882
- overrideErrorMap = map;
2883
- }
2884
- function getErrorMap() {
2885
- return overrideErrorMap;
2886
- }
2887
-
2888
- // node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/parseUtil.js
2889
- var makeIssue = (params) => {
2890
- const { data, path, errorMaps, issueData } = params;
2891
- const fullPath = [...path, ...issueData.path || []];
2892
- const fullIssue = {
2893
- ...issueData,
2894
- path: fullPath
2895
- };
2896
- if (issueData.message !== void 0) {
2897
- return {
2898
- ...issueData,
2899
- path: fullPath,
2900
- message: issueData.message
2901
- };
2902
- }
2903
- let errorMessage = "";
2904
- const maps = errorMaps.filter((m3) => !!m3).slice().reverse();
2905
- for (const map of maps) {
2906
- errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message;
2907
- }
2908
- return {
2909
- ...issueData,
2910
- path: fullPath,
2911
- message: errorMessage
2912
- };
2913
- };
2914
- var EMPTY_PATH = [];
2915
- function addIssueToContext(ctx, issueData) {
2916
- const overrideMap = getErrorMap();
2917
- const issue = makeIssue({
2918
- issueData,
2919
- data: ctx.data,
2920
- path: ctx.path,
2921
- errorMaps: [
2922
- ctx.common.contextualErrorMap,
2923
- // contextual error map is first priority
2924
- ctx.schemaErrorMap,
2925
- // then schema-bound map if available
2926
- overrideMap,
2927
- // then global override map
2928
- overrideMap === en_default ? void 0 : en_default
2929
- // then global default map
2930
- ].filter((x) => !!x)
2931
- });
2932
- ctx.common.issues.push(issue);
2933
- }
2934
- var ParseStatus = class _ParseStatus {
2935
- constructor() {
2936
- this.value = "valid";
2937
- }
2938
- dirty() {
2939
- if (this.value === "valid")
2940
- this.value = "dirty";
2941
- }
2942
- abort() {
2943
- if (this.value !== "aborted")
2944
- this.value = "aborted";
2945
- }
2946
- static mergeArray(status, results) {
2947
- const arrayValue = [];
2948
- for (const s5 of results) {
2949
- if (s5.status === "aborted")
2950
- return INVALID;
2951
- if (s5.status === "dirty")
2952
- status.dirty();
2953
- arrayValue.push(s5.value);
2954
- }
2955
- return { status: status.value, value: arrayValue };
2956
- }
2957
- static async mergeObjectAsync(status, pairs) {
2958
- const syncPairs = [];
2959
- for (const pair of pairs) {
2960
- const key = await pair.key;
2961
- const value = await pair.value;
2962
- syncPairs.push({
2963
- key,
2964
- value
2965
- });
2966
- }
2967
- return _ParseStatus.mergeObjectSync(status, syncPairs);
2968
- }
2969
- static mergeObjectSync(status, pairs) {
2970
- const finalObject = {};
2971
- for (const pair of pairs) {
2972
- const { key, value } = pair;
2973
- if (key.status === "aborted")
2974
- return INVALID;
2975
- if (value.status === "aborted")
2976
- return INVALID;
2977
- if (key.status === "dirty")
2978
- status.dirty();
2979
- if (value.status === "dirty")
2980
- status.dirty();
2981
- if (key.value !== "__proto__" && (typeof value.value !== "undefined" || pair.alwaysSet)) {
2982
- finalObject[key.value] = value.value;
2983
- }
2984
- }
2985
- return { status: status.value, value: finalObject };
2986
- }
2987
- };
2988
- var INVALID = Object.freeze({
2989
- status: "aborted"
2990
- });
2991
- var DIRTY = (value) => ({ status: "dirty", value });
2992
- var OK = (value) => ({ status: "valid", value });
2993
- var isAborted = (x) => x.status === "aborted";
2994
- var isDirty = (x) => x.status === "dirty";
2995
- var isValid = (x) => x.status === "valid";
2996
- var isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
2997
-
2998
- // node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/errorUtil.js
2999
- var errorUtil;
3000
- (function(errorUtil2) {
3001
- errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
3002
- errorUtil2.toString = (message) => typeof message === "string" ? message : message?.message;
3003
- })(errorUtil || (errorUtil = {}));
3004
-
3005
- // node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/types.js
3006
- var ParseInputLazyPath = class {
3007
- constructor(parent, value, path, key) {
3008
- this._cachedPath = [];
3009
- this.parent = parent;
3010
- this.data = value;
3011
- this._path = path;
3012
- this._key = key;
3013
- }
3014
- get path() {
3015
- if (!this._cachedPath.length) {
3016
- if (Array.isArray(this._key)) {
3017
- this._cachedPath.push(...this._path, ...this._key);
3018
- } else {
3019
- this._cachedPath.push(...this._path, this._key);
3020
- }
3021
- }
3022
- return this._cachedPath;
3023
- }
3024
- };
3025
- var handleResult = (ctx, result) => {
3026
- if (isValid(result)) {
3027
- return { success: true, data: result.value };
3028
- } else {
3029
- if (!ctx.common.issues.length) {
3030
- throw new Error("Validation failed but no issues detected.");
3031
- }
3032
- return {
3033
- success: false,
3034
- get error() {
3035
- if (this._error)
3036
- return this._error;
3037
- const error = new ZodError(ctx.common.issues);
3038
- this._error = error;
3039
- return this._error;
3040
- }
3041
- };
3042
- }
3043
- };
3044
- function processCreateParams(params) {
3045
- if (!params)
3046
- return {};
3047
- const { errorMap: errorMap2, invalid_type_error, required_error, description } = params;
3048
- if (errorMap2 && (invalid_type_error || required_error)) {
3049
- throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
3050
- }
3051
- if (errorMap2)
3052
- return { errorMap: errorMap2, description };
3053
- const customMap = (iss, ctx) => {
3054
- const { message } = params;
3055
- if (iss.code === "invalid_enum_value") {
3056
- return { message: message ?? ctx.defaultError };
3057
- }
3058
- if (typeof ctx.data === "undefined") {
3059
- return { message: message ?? required_error ?? ctx.defaultError };
3060
- }
3061
- if (iss.code !== "invalid_type")
3062
- return { message: ctx.defaultError };
3063
- return { message: message ?? invalid_type_error ?? ctx.defaultError };
3064
- };
3065
- return { errorMap: customMap, description };
3066
- }
3067
- var ZodType = class {
3068
- get description() {
3069
- return this._def.description;
3070
- }
3071
- _getType(input) {
3072
- return getParsedType(input.data);
3073
- }
3074
- _getOrReturnCtx(input, ctx) {
3075
- return ctx || {
3076
- common: input.parent.common,
3077
- data: input.data,
3078
- parsedType: getParsedType(input.data),
3079
- schemaErrorMap: this._def.errorMap,
3080
- path: input.path,
3081
- parent: input.parent
3082
- };
3083
- }
3084
- _processInputParams(input) {
3085
- return {
3086
- status: new ParseStatus(),
3087
- ctx: {
3088
- common: input.parent.common,
3089
- data: input.data,
3090
- parsedType: getParsedType(input.data),
3091
- schemaErrorMap: this._def.errorMap,
3092
- path: input.path,
3093
- parent: input.parent
3094
- }
3095
- };
3096
- }
3097
- _parseSync(input) {
3098
- const result = this._parse(input);
3099
- if (isAsync(result)) {
3100
- throw new Error("Synchronous parse encountered promise.");
3101
- }
3102
- return result;
3103
- }
3104
- _parseAsync(input) {
3105
- const result = this._parse(input);
3106
- return Promise.resolve(result);
3107
- }
3108
- parse(data, params) {
3109
- const result = this.safeParse(data, params);
3110
- if (result.success)
3111
- return result.data;
3112
- throw result.error;
3113
- }
3114
- safeParse(data, params) {
3115
- const ctx = {
3116
- common: {
3117
- issues: [],
3118
- async: params?.async ?? false,
3119
- contextualErrorMap: params?.errorMap
3120
- },
3121
- path: params?.path || [],
3122
- schemaErrorMap: this._def.errorMap,
3123
- parent: null,
3124
- data,
3125
- parsedType: getParsedType(data)
3126
- };
3127
- const result = this._parseSync({ data, path: ctx.path, parent: ctx });
3128
- return handleResult(ctx, result);
3129
- }
3130
- "~validate"(data) {
3131
- const ctx = {
3132
- common: {
3133
- issues: [],
3134
- async: !!this["~standard"].async
3135
- },
3136
- path: [],
3137
- schemaErrorMap: this._def.errorMap,
3138
- parent: null,
3139
- data,
3140
- parsedType: getParsedType(data)
3141
- };
3142
- if (!this["~standard"].async) {
3143
- try {
3144
- const result = this._parseSync({ data, path: [], parent: ctx });
3145
- return isValid(result) ? {
3146
- value: result.value
3147
- } : {
3148
- issues: ctx.common.issues
3149
- };
3150
- } catch (err) {
3151
- if (err?.message?.toLowerCase()?.includes("encountered")) {
3152
- this["~standard"].async = true;
3153
- }
3154
- ctx.common = {
3155
- issues: [],
3156
- async: true
3157
- };
3158
- }
3159
- }
3160
- return this._parseAsync({ data, path: [], parent: ctx }).then((result) => isValid(result) ? {
3161
- value: result.value
3162
- } : {
3163
- issues: ctx.common.issues
3164
- });
3165
- }
3166
- async parseAsync(data, params) {
3167
- const result = await this.safeParseAsync(data, params);
3168
- if (result.success)
3169
- return result.data;
3170
- throw result.error;
3171
- }
3172
- async safeParseAsync(data, params) {
3173
- const ctx = {
3174
- common: {
3175
- issues: [],
3176
- contextualErrorMap: params?.errorMap,
3177
- async: true
3178
- },
3179
- path: params?.path || [],
3180
- schemaErrorMap: this._def.errorMap,
3181
- parent: null,
3182
- data,
3183
- parsedType: getParsedType(data)
3184
- };
3185
- const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx });
3186
- const result = await (isAsync(maybeAsyncResult) ? maybeAsyncResult : Promise.resolve(maybeAsyncResult));
3187
- return handleResult(ctx, result);
3188
- }
3189
- refine(check, message) {
3190
- const getIssueProperties = (val) => {
3191
- if (typeof message === "string" || typeof message === "undefined") {
3192
- return { message };
3193
- } else if (typeof message === "function") {
3194
- return message(val);
3195
- } else {
3196
- return message;
3197
- }
3198
- };
3199
- return this._refinement((val, ctx) => {
3200
- const result = check(val);
3201
- const setError = () => ctx.addIssue({
3202
- code: ZodIssueCode.custom,
3203
- ...getIssueProperties(val)
3204
- });
3205
- if (typeof Promise !== "undefined" && result instanceof Promise) {
3206
- return result.then((data) => {
3207
- if (!data) {
3208
- setError();
3209
- return false;
3210
- } else {
3211
- return true;
3212
- }
3213
- });
3214
- }
3215
- if (!result) {
3216
- setError();
3217
- return false;
3218
- } else {
3219
- return true;
3220
- }
3221
- });
3222
- }
3223
- refinement(check, refinementData) {
3224
- return this._refinement((val, ctx) => {
3225
- if (!check(val)) {
3226
- ctx.addIssue(typeof refinementData === "function" ? refinementData(val, ctx) : refinementData);
3227
- return false;
3228
- } else {
3229
- return true;
3230
- }
3231
- });
3232
- }
3233
- _refinement(refinement) {
3234
- return new ZodEffects({
3235
- schema: this,
3236
- typeName: ZodFirstPartyTypeKind.ZodEffects,
3237
- effect: { type: "refinement", refinement }
3238
- });
3239
- }
3240
- superRefine(refinement) {
3241
- return this._refinement(refinement);
3242
- }
3243
- constructor(def) {
3244
- this.spa = this.safeParseAsync;
3245
- this._def = def;
3246
- this.parse = this.parse.bind(this);
3247
- this.safeParse = this.safeParse.bind(this);
3248
- this.parseAsync = this.parseAsync.bind(this);
3249
- this.safeParseAsync = this.safeParseAsync.bind(this);
3250
- this.spa = this.spa.bind(this);
3251
- this.refine = this.refine.bind(this);
3252
- this.refinement = this.refinement.bind(this);
3253
- this.superRefine = this.superRefine.bind(this);
3254
- this.optional = this.optional.bind(this);
3255
- this.nullable = this.nullable.bind(this);
3256
- this.nullish = this.nullish.bind(this);
3257
- this.array = this.array.bind(this);
3258
- this.promise = this.promise.bind(this);
3259
- this.or = this.or.bind(this);
3260
- this.and = this.and.bind(this);
3261
- this.transform = this.transform.bind(this);
3262
- this.brand = this.brand.bind(this);
3263
- this.default = this.default.bind(this);
3264
- this.catch = this.catch.bind(this);
3265
- this.describe = this.describe.bind(this);
3266
- this.pipe = this.pipe.bind(this);
3267
- this.readonly = this.readonly.bind(this);
3268
- this.isNullable = this.isNullable.bind(this);
3269
- this.isOptional = this.isOptional.bind(this);
3270
- this["~standard"] = {
3271
- version: 1,
3272
- vendor: "zod",
3273
- validate: (data) => this["~validate"](data)
3274
- };
3275
- }
3276
- optional() {
3277
- return ZodOptional.create(this, this._def);
3278
- }
3279
- nullable() {
3280
- return ZodNullable.create(this, this._def);
3281
- }
3282
- nullish() {
3283
- return this.nullable().optional();
3284
- }
3285
- array() {
3286
- return ZodArray.create(this);
3287
- }
3288
- promise() {
3289
- return ZodPromise.create(this, this._def);
3290
- }
3291
- or(option) {
3292
- return ZodUnion.create([this, option], this._def);
3293
- }
3294
- and(incoming) {
3295
- return ZodIntersection.create(this, incoming, this._def);
3296
- }
3297
- transform(transform) {
3298
- return new ZodEffects({
3299
- ...processCreateParams(this._def),
3300
- schema: this,
3301
- typeName: ZodFirstPartyTypeKind.ZodEffects,
3302
- effect: { type: "transform", transform }
3303
- });
3304
- }
3305
- default(def) {
3306
- const defaultValueFunc = typeof def === "function" ? def : () => def;
3307
- return new ZodDefault({
3308
- ...processCreateParams(this._def),
3309
- innerType: this,
3310
- defaultValue: defaultValueFunc,
3311
- typeName: ZodFirstPartyTypeKind.ZodDefault
3312
- });
3313
- }
3314
- brand() {
3315
- return new ZodBranded({
3316
- typeName: ZodFirstPartyTypeKind.ZodBranded,
3317
- type: this,
3318
- ...processCreateParams(this._def)
3319
- });
3320
- }
3321
- catch(def) {
3322
- const catchValueFunc = typeof def === "function" ? def : () => def;
3323
- return new ZodCatch({
3324
- ...processCreateParams(this._def),
3325
- innerType: this,
3326
- catchValue: catchValueFunc,
3327
- typeName: ZodFirstPartyTypeKind.ZodCatch
3328
- });
3329
- }
3330
- describe(description) {
3331
- const This = this.constructor;
3332
- return new This({
3333
- ...this._def,
3334
- description
3335
- });
3336
- }
3337
- pipe(target) {
3338
- return ZodPipeline.create(this, target);
3339
- }
3340
- readonly() {
3341
- return ZodReadonly.create(this);
3342
- }
3343
- isOptional() {
3344
- return this.safeParse(void 0).success;
3345
- }
3346
- isNullable() {
3347
- return this.safeParse(null).success;
3348
- }
3349
- };
3350
- var cuidRegex = /^c[^\s-]{8,}$/i;
3351
- var cuid2Regex = /^[0-9a-z]+$/;
3352
- var ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
3353
- 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;
3354
- var nanoidRegex = /^[a-z0-9_-]{21}$/i;
3355
- var jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;
3356
- 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)?)??$/;
3357
- var emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
3358
- var _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
3359
- var emojiRegex;
3360
- 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])$/;
3361
- 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])$/;
3362
- 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]))$/;
3363
- 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])$/;
3364
- var base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
3365
- var base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/;
3366
- 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])))`;
3367
- var dateRegex = new RegExp(`^${dateRegexSource}$`);
3368
- function timeRegexSource(args) {
3369
- let secondsRegexSource = `[0-5]\\d`;
3370
- if (args.precision) {
3371
- secondsRegexSource = `${secondsRegexSource}\\.\\d{${args.precision}}`;
3372
- } else if (args.precision == null) {
3373
- secondsRegexSource = `${secondsRegexSource}(\\.\\d+)?`;
3374
- }
3375
- const secondsQuantifier = args.precision ? "+" : "?";
3376
- return `([01]\\d|2[0-3]):[0-5]\\d(:${secondsRegexSource})${secondsQuantifier}`;
3377
- }
3378
- function timeRegex(args) {
3379
- return new RegExp(`^${timeRegexSource(args)}$`);
3380
- }
3381
- function datetimeRegex(args) {
3382
- let regex = `${dateRegexSource}T${timeRegexSource(args)}`;
3383
- const opts = [];
3384
- opts.push(args.local ? `Z?` : `Z`);
3385
- if (args.offset)
3386
- opts.push(`([+-]\\d{2}:?\\d{2})`);
3387
- regex = `${regex}(${opts.join("|")})`;
3388
- return new RegExp(`^${regex}$`);
3389
- }
3390
- function isValidIP(ip, version) {
3391
- if ((version === "v4" || !version) && ipv4Regex.test(ip)) {
3392
- return true;
3393
- }
3394
- if ((version === "v6" || !version) && ipv6Regex.test(ip)) {
3395
- return true;
3396
- }
3397
- return false;
3398
- }
3399
- function isValidJWT(jwt, alg) {
3400
- if (!jwtRegex.test(jwt))
3401
- return false;
3402
- try {
3403
- const [header] = jwt.split(".");
3404
- if (!header)
3405
- return false;
3406
- const base64 = header.replace(/-/g, "+").replace(/_/g, "/").padEnd(header.length + (4 - header.length % 4) % 4, "=");
3407
- const decoded = JSON.parse(atob(base64));
3408
- if (typeof decoded !== "object" || decoded === null)
3409
- return false;
3410
- if ("typ" in decoded && decoded?.typ !== "JWT")
3411
- return false;
3412
- if (!decoded.alg)
3413
- return false;
3414
- if (alg && decoded.alg !== alg)
3415
- return false;
3416
- return true;
3417
- } catch {
3418
- return false;
3419
- }
3420
- }
3421
- function isValidCidr(ip, version) {
3422
- if ((version === "v4" || !version) && ipv4CidrRegex.test(ip)) {
3423
- return true;
3424
- }
3425
- if ((version === "v6" || !version) && ipv6CidrRegex.test(ip)) {
3426
- return true;
3427
- }
3428
- return false;
3429
- }
3430
- var ZodString = class _ZodString extends ZodType {
3431
- _parse(input) {
3432
- if (this._def.coerce) {
3433
- input.data = String(input.data);
3434
- }
3435
- const parsedType = this._getType(input);
3436
- if (parsedType !== ZodParsedType.string) {
3437
- const ctx2 = this._getOrReturnCtx(input);
3438
- addIssueToContext(ctx2, {
3439
- code: ZodIssueCode.invalid_type,
3440
- expected: ZodParsedType.string,
3441
- received: ctx2.parsedType
3442
- });
3443
- return INVALID;
3444
- }
3445
- const status = new ParseStatus();
3446
- let ctx = void 0;
3447
- for (const check of this._def.checks) {
3448
- if (check.kind === "min") {
3449
- if (input.data.length < check.value) {
3450
- ctx = this._getOrReturnCtx(input, ctx);
3451
- addIssueToContext(ctx, {
3452
- code: ZodIssueCode.too_small,
3453
- minimum: check.value,
3454
- type: "string",
3455
- inclusive: true,
3456
- exact: false,
3457
- message: check.message
3458
- });
3459
- status.dirty();
3460
- }
3461
- } else if (check.kind === "max") {
3462
- if (input.data.length > check.value) {
3463
- ctx = this._getOrReturnCtx(input, ctx);
3464
- addIssueToContext(ctx, {
3465
- code: ZodIssueCode.too_big,
3466
- maximum: check.value,
3467
- type: "string",
3468
- inclusive: true,
3469
- exact: false,
3470
- message: check.message
3471
- });
3472
- status.dirty();
3473
- }
3474
- } else if (check.kind === "length") {
3475
- const tooBig = input.data.length > check.value;
3476
- const tooSmall = input.data.length < check.value;
3477
- if (tooBig || tooSmall) {
3478
- ctx = this._getOrReturnCtx(input, ctx);
3479
- if (tooBig) {
3480
- addIssueToContext(ctx, {
3481
- code: ZodIssueCode.too_big,
3482
- maximum: check.value,
3483
- type: "string",
3484
- inclusive: true,
3485
- exact: true,
3486
- message: check.message
3487
- });
3488
- } else if (tooSmall) {
3489
- addIssueToContext(ctx, {
3490
- code: ZodIssueCode.too_small,
3491
- minimum: check.value,
3492
- type: "string",
3493
- inclusive: true,
3494
- exact: true,
3495
- message: check.message
3496
- });
3497
- }
3498
- status.dirty();
3499
- }
3500
- } else if (check.kind === "email") {
3501
- if (!emailRegex.test(input.data)) {
3502
- ctx = this._getOrReturnCtx(input, ctx);
3503
- addIssueToContext(ctx, {
3504
- validation: "email",
3505
- code: ZodIssueCode.invalid_string,
3506
- message: check.message
3507
- });
3508
- status.dirty();
3509
- }
3510
- } else if (check.kind === "emoji") {
3511
- if (!emojiRegex) {
3512
- emojiRegex = new RegExp(_emojiRegex, "u");
3513
- }
3514
- if (!emojiRegex.test(input.data)) {
3515
- ctx = this._getOrReturnCtx(input, ctx);
3516
- addIssueToContext(ctx, {
3517
- validation: "emoji",
3518
- code: ZodIssueCode.invalid_string,
3519
- message: check.message
3520
- });
3521
- status.dirty();
3522
- }
3523
- } else if (check.kind === "uuid") {
3524
- if (!uuidRegex.test(input.data)) {
3525
- ctx = this._getOrReturnCtx(input, ctx);
3526
- addIssueToContext(ctx, {
3527
- validation: "uuid",
3528
- code: ZodIssueCode.invalid_string,
3529
- message: check.message
3530
- });
3531
- status.dirty();
3532
- }
3533
- } else if (check.kind === "nanoid") {
3534
- if (!nanoidRegex.test(input.data)) {
3535
- ctx = this._getOrReturnCtx(input, ctx);
3536
- addIssueToContext(ctx, {
3537
- validation: "nanoid",
3538
- code: ZodIssueCode.invalid_string,
3539
- message: check.message
3540
- });
3541
- status.dirty();
3542
- }
3543
- } else if (check.kind === "cuid") {
3544
- if (!cuidRegex.test(input.data)) {
3545
- ctx = this._getOrReturnCtx(input, ctx);
3546
- addIssueToContext(ctx, {
3547
- validation: "cuid",
3548
- code: ZodIssueCode.invalid_string,
3549
- message: check.message
3550
- });
3551
- status.dirty();
3552
- }
3553
- } else if (check.kind === "cuid2") {
3554
- if (!cuid2Regex.test(input.data)) {
3555
- ctx = this._getOrReturnCtx(input, ctx);
3556
- addIssueToContext(ctx, {
3557
- validation: "cuid2",
3558
- code: ZodIssueCode.invalid_string,
3559
- message: check.message
3560
- });
3561
- status.dirty();
3562
- }
3563
- } else if (check.kind === "ulid") {
3564
- if (!ulidRegex.test(input.data)) {
3565
- ctx = this._getOrReturnCtx(input, ctx);
3566
- addIssueToContext(ctx, {
3567
- validation: "ulid",
3568
- code: ZodIssueCode.invalid_string,
3569
- message: check.message
3570
- });
3571
- status.dirty();
3572
- }
3573
- } else if (check.kind === "url") {
3574
- try {
3575
- new URL(input.data);
3576
- } catch {
3577
- ctx = this._getOrReturnCtx(input, ctx);
3578
- addIssueToContext(ctx, {
3579
- validation: "url",
3580
- code: ZodIssueCode.invalid_string,
3581
- message: check.message
3582
- });
3583
- status.dirty();
3584
- }
3585
- } else if (check.kind === "regex") {
3586
- check.regex.lastIndex = 0;
3587
- const testResult = check.regex.test(input.data);
3588
- if (!testResult) {
3589
- ctx = this._getOrReturnCtx(input, ctx);
3590
- addIssueToContext(ctx, {
3591
- validation: "regex",
3592
- code: ZodIssueCode.invalid_string,
3593
- message: check.message
3594
- });
3595
- status.dirty();
3596
- }
3597
- } else if (check.kind === "trim") {
3598
- input.data = input.data.trim();
3599
- } else if (check.kind === "includes") {
3600
- if (!input.data.includes(check.value, check.position)) {
3601
- ctx = this._getOrReturnCtx(input, ctx);
3602
- addIssueToContext(ctx, {
3603
- code: ZodIssueCode.invalid_string,
3604
- validation: { includes: check.value, position: check.position },
3605
- message: check.message
3606
- });
3607
- status.dirty();
3608
- }
3609
- } else if (check.kind === "toLowerCase") {
3610
- input.data = input.data.toLowerCase();
3611
- } else if (check.kind === "toUpperCase") {
3612
- input.data = input.data.toUpperCase();
3613
- } else if (check.kind === "startsWith") {
3614
- if (!input.data.startsWith(check.value)) {
3615
- ctx = this._getOrReturnCtx(input, ctx);
3616
- addIssueToContext(ctx, {
3617
- code: ZodIssueCode.invalid_string,
3618
- validation: { startsWith: check.value },
3619
- message: check.message
3620
- });
3621
- status.dirty();
3622
- }
3623
- } else if (check.kind === "endsWith") {
3624
- if (!input.data.endsWith(check.value)) {
3625
- ctx = this._getOrReturnCtx(input, ctx);
3626
- addIssueToContext(ctx, {
3627
- code: ZodIssueCode.invalid_string,
3628
- validation: { endsWith: check.value },
3629
- message: check.message
3630
- });
3631
- status.dirty();
3632
- }
3633
- } else if (check.kind === "datetime") {
3634
- const regex = datetimeRegex(check);
3635
- if (!regex.test(input.data)) {
3636
- ctx = this._getOrReturnCtx(input, ctx);
3637
- addIssueToContext(ctx, {
3638
- code: ZodIssueCode.invalid_string,
3639
- validation: "datetime",
3640
- message: check.message
3641
- });
3642
- status.dirty();
3643
- }
3644
- } else if (check.kind === "date") {
3645
- const regex = dateRegex;
3646
- if (!regex.test(input.data)) {
3647
- ctx = this._getOrReturnCtx(input, ctx);
3648
- addIssueToContext(ctx, {
3649
- code: ZodIssueCode.invalid_string,
3650
- validation: "date",
3651
- message: check.message
3652
- });
3653
- status.dirty();
3654
- }
3655
- } else if (check.kind === "time") {
3656
- const regex = timeRegex(check);
3657
- if (!regex.test(input.data)) {
3658
- ctx = this._getOrReturnCtx(input, ctx);
3659
- addIssueToContext(ctx, {
3660
- code: ZodIssueCode.invalid_string,
3661
- validation: "time",
3662
- message: check.message
3663
- });
3664
- status.dirty();
3665
- }
3666
- } else if (check.kind === "duration") {
3667
- if (!durationRegex.test(input.data)) {
3668
- ctx = this._getOrReturnCtx(input, ctx);
3669
- addIssueToContext(ctx, {
3670
- validation: "duration",
3671
- code: ZodIssueCode.invalid_string,
3672
- message: check.message
3673
- });
3674
- status.dirty();
3675
- }
3676
- } else if (check.kind === "ip") {
3677
- if (!isValidIP(input.data, check.version)) {
3678
- ctx = this._getOrReturnCtx(input, ctx);
3679
- addIssueToContext(ctx, {
3680
- validation: "ip",
3681
- code: ZodIssueCode.invalid_string,
3682
- message: check.message
3683
- });
3684
- status.dirty();
3685
- }
3686
- } else if (check.kind === "jwt") {
3687
- if (!isValidJWT(input.data, check.alg)) {
3688
- ctx = this._getOrReturnCtx(input, ctx);
3689
- addIssueToContext(ctx, {
3690
- validation: "jwt",
3691
- code: ZodIssueCode.invalid_string,
3692
- message: check.message
3693
- });
3694
- status.dirty();
3695
- }
3696
- } else if (check.kind === "cidr") {
3697
- if (!isValidCidr(input.data, check.version)) {
3698
- ctx = this._getOrReturnCtx(input, ctx);
3699
- addIssueToContext(ctx, {
3700
- validation: "cidr",
3701
- code: ZodIssueCode.invalid_string,
3702
- message: check.message
3703
- });
3704
- status.dirty();
3705
- }
3706
- } else if (check.kind === "base64") {
3707
- if (!base64Regex.test(input.data)) {
3708
- ctx = this._getOrReturnCtx(input, ctx);
3709
- addIssueToContext(ctx, {
3710
- validation: "base64",
3711
- code: ZodIssueCode.invalid_string,
3712
- message: check.message
3713
- });
3714
- status.dirty();
3715
- }
3716
- } else if (check.kind === "base64url") {
3717
- if (!base64urlRegex.test(input.data)) {
3718
- ctx = this._getOrReturnCtx(input, ctx);
3719
- addIssueToContext(ctx, {
3720
- validation: "base64url",
3721
- code: ZodIssueCode.invalid_string,
3722
- message: check.message
3723
- });
3724
- status.dirty();
3725
- }
3726
- } else {
3727
- util.assertNever(check);
3728
- }
3729
- }
3730
- return { status: status.value, value: input.data };
3731
- }
3732
- _regex(regex, validation, message) {
3733
- return this.refinement((data) => regex.test(data), {
3734
- validation,
3735
- code: ZodIssueCode.invalid_string,
3736
- ...errorUtil.errToObj(message)
3737
- });
3738
- }
3739
- _addCheck(check) {
3740
- return new _ZodString({
3741
- ...this._def,
3742
- checks: [...this._def.checks, check]
3743
- });
3744
- }
3745
- email(message) {
3746
- return this._addCheck({ kind: "email", ...errorUtil.errToObj(message) });
3747
- }
3748
- url(message) {
3749
- return this._addCheck({ kind: "url", ...errorUtil.errToObj(message) });
3750
- }
3751
- emoji(message) {
3752
- return this._addCheck({ kind: "emoji", ...errorUtil.errToObj(message) });
3753
- }
3754
- uuid(message) {
3755
- return this._addCheck({ kind: "uuid", ...errorUtil.errToObj(message) });
3756
- }
3757
- nanoid(message) {
3758
- return this._addCheck({ kind: "nanoid", ...errorUtil.errToObj(message) });
3759
- }
3760
- cuid(message) {
3761
- return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) });
3762
- }
3763
- cuid2(message) {
3764
- return this._addCheck({ kind: "cuid2", ...errorUtil.errToObj(message) });
3765
- }
3766
- ulid(message) {
3767
- return this._addCheck({ kind: "ulid", ...errorUtil.errToObj(message) });
3768
- }
3769
- base64(message) {
3770
- return this._addCheck({ kind: "base64", ...errorUtil.errToObj(message) });
3771
- }
3772
- base64url(message) {
3773
- return this._addCheck({
3774
- kind: "base64url",
3775
- ...errorUtil.errToObj(message)
3776
- });
3777
- }
3778
- jwt(options) {
3779
- return this._addCheck({ kind: "jwt", ...errorUtil.errToObj(options) });
3780
- }
3781
- ip(options) {
3782
- return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
3783
- }
3784
- cidr(options) {
3785
- return this._addCheck({ kind: "cidr", ...errorUtil.errToObj(options) });
3786
- }
3787
- datetime(options) {
3788
- if (typeof options === "string") {
3789
- return this._addCheck({
3790
- kind: "datetime",
3791
- precision: null,
3792
- offset: false,
3793
- local: false,
3794
- message: options
3795
- });
3796
- }
3797
- return this._addCheck({
3798
- kind: "datetime",
3799
- precision: typeof options?.precision === "undefined" ? null : options?.precision,
3800
- offset: options?.offset ?? false,
3801
- local: options?.local ?? false,
3802
- ...errorUtil.errToObj(options?.message)
3803
- });
3804
- }
3805
- date(message) {
3806
- return this._addCheck({ kind: "date", message });
3807
- }
3808
- time(options) {
3809
- if (typeof options === "string") {
3810
- return this._addCheck({
3811
- kind: "time",
3812
- precision: null,
3813
- message: options
3814
- });
3815
- }
3816
- return this._addCheck({
3817
- kind: "time",
3818
- precision: typeof options?.precision === "undefined" ? null : options?.precision,
3819
- ...errorUtil.errToObj(options?.message)
3820
- });
3821
- }
3822
- duration(message) {
3823
- return this._addCheck({ kind: "duration", ...errorUtil.errToObj(message) });
3824
- }
3825
- regex(regex, message) {
3826
- return this._addCheck({
3827
- kind: "regex",
3828
- regex,
3829
- ...errorUtil.errToObj(message)
3830
- });
3831
- }
3832
- includes(value, options) {
3833
- return this._addCheck({
3834
- kind: "includes",
3835
- value,
3836
- position: options?.position,
3837
- ...errorUtil.errToObj(options?.message)
3838
- });
3839
- }
3840
- startsWith(value, message) {
3841
- return this._addCheck({
3842
- kind: "startsWith",
3843
- value,
3844
- ...errorUtil.errToObj(message)
3845
- });
3846
- }
3847
- endsWith(value, message) {
3848
- return this._addCheck({
3849
- kind: "endsWith",
3850
- value,
3851
- ...errorUtil.errToObj(message)
3852
- });
3853
- }
3854
- min(minLength, message) {
3855
- return this._addCheck({
3856
- kind: "min",
3857
- value: minLength,
3858
- ...errorUtil.errToObj(message)
3859
- });
3860
- }
3861
- max(maxLength, message) {
3862
- return this._addCheck({
3863
- kind: "max",
3864
- value: maxLength,
3865
- ...errorUtil.errToObj(message)
3866
- });
3867
- }
3868
- length(len, message) {
3869
- return this._addCheck({
3870
- kind: "length",
3871
- value: len,
3872
- ...errorUtil.errToObj(message)
3873
- });
3874
- }
3875
- /**
3876
- * Equivalent to `.min(1)`
3877
- */
3878
- nonempty(message) {
3879
- return this.min(1, errorUtil.errToObj(message));
3880
- }
3881
- trim() {
3882
- return new _ZodString({
3883
- ...this._def,
3884
- checks: [...this._def.checks, { kind: "trim" }]
3885
- });
3886
- }
3887
- toLowerCase() {
3888
- return new _ZodString({
3889
- ...this._def,
3890
- checks: [...this._def.checks, { kind: "toLowerCase" }]
3891
- });
3892
- }
3893
- toUpperCase() {
3894
- return new _ZodString({
3895
- ...this._def,
3896
- checks: [...this._def.checks, { kind: "toUpperCase" }]
3897
- });
3898
- }
3899
- get isDatetime() {
3900
- return !!this._def.checks.find((ch) => ch.kind === "datetime");
3901
- }
3902
- get isDate() {
3903
- return !!this._def.checks.find((ch) => ch.kind === "date");
3904
- }
3905
- get isTime() {
3906
- return !!this._def.checks.find((ch) => ch.kind === "time");
3907
- }
3908
- get isDuration() {
3909
- return !!this._def.checks.find((ch) => ch.kind === "duration");
3910
- }
3911
- get isEmail() {
3912
- return !!this._def.checks.find((ch) => ch.kind === "email");
3913
- }
3914
- get isURL() {
3915
- return !!this._def.checks.find((ch) => ch.kind === "url");
3916
- }
3917
- get isEmoji() {
3918
- return !!this._def.checks.find((ch) => ch.kind === "emoji");
3919
- }
3920
- get isUUID() {
3921
- return !!this._def.checks.find((ch) => ch.kind === "uuid");
3922
- }
3923
- get isNANOID() {
3924
- return !!this._def.checks.find((ch) => ch.kind === "nanoid");
3925
- }
3926
- get isCUID() {
3927
- return !!this._def.checks.find((ch) => ch.kind === "cuid");
3928
- }
3929
- get isCUID2() {
3930
- return !!this._def.checks.find((ch) => ch.kind === "cuid2");
3931
- }
3932
- get isULID() {
3933
- return !!this._def.checks.find((ch) => ch.kind === "ulid");
3934
- }
3935
- get isIP() {
3936
- return !!this._def.checks.find((ch) => ch.kind === "ip");
3937
- }
3938
- get isCIDR() {
3939
- return !!this._def.checks.find((ch) => ch.kind === "cidr");
3940
- }
3941
- get isBase64() {
3942
- return !!this._def.checks.find((ch) => ch.kind === "base64");
3943
- }
3944
- get isBase64url() {
3945
- return !!this._def.checks.find((ch) => ch.kind === "base64url");
3946
- }
3947
- get minLength() {
3948
- let min = null;
3949
- for (const ch of this._def.checks) {
3950
- if (ch.kind === "min") {
3951
- if (min === null || ch.value > min)
3952
- min = ch.value;
3953
- }
3954
- }
3955
- return min;
3956
- }
3957
- get maxLength() {
3958
- let max = null;
3959
- for (const ch of this._def.checks) {
3960
- if (ch.kind === "max") {
3961
- if (max === null || ch.value < max)
3962
- max = ch.value;
3963
- }
3964
- }
3965
- return max;
3966
- }
3967
- };
3968
- ZodString.create = (params) => {
3969
- return new ZodString({
3970
- checks: [],
3971
- typeName: ZodFirstPartyTypeKind.ZodString,
3972
- coerce: params?.coerce ?? false,
3973
- ...processCreateParams(params)
3974
- });
3975
- };
3976
- function floatSafeRemainder(val, step) {
3977
- const valDecCount = (val.toString().split(".")[1] || "").length;
3978
- const stepDecCount = (step.toString().split(".")[1] || "").length;
3979
- const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
3980
- const valInt = Number.parseInt(val.toFixed(decCount).replace(".", ""));
3981
- const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
3982
- return valInt % stepInt / 10 ** decCount;
3983
- }
3984
- var ZodNumber = class _ZodNumber extends ZodType {
3985
- constructor() {
3986
- super(...arguments);
3987
- this.min = this.gte;
3988
- this.max = this.lte;
3989
- this.step = this.multipleOf;
3990
- }
3991
- _parse(input) {
3992
- if (this._def.coerce) {
3993
- input.data = Number(input.data);
3994
- }
3995
- const parsedType = this._getType(input);
3996
- if (parsedType !== ZodParsedType.number) {
3997
- const ctx2 = this._getOrReturnCtx(input);
3998
- addIssueToContext(ctx2, {
3999
- code: ZodIssueCode.invalid_type,
4000
- expected: ZodParsedType.number,
4001
- received: ctx2.parsedType
4002
- });
4003
- return INVALID;
4004
- }
4005
- let ctx = void 0;
4006
- const status = new ParseStatus();
4007
- for (const check of this._def.checks) {
4008
- if (check.kind === "int") {
4009
- if (!util.isInteger(input.data)) {
4010
- ctx = this._getOrReturnCtx(input, ctx);
4011
- addIssueToContext(ctx, {
4012
- code: ZodIssueCode.invalid_type,
4013
- expected: "integer",
4014
- received: "float",
4015
- message: check.message
4016
- });
4017
- status.dirty();
4018
- }
4019
- } else if (check.kind === "min") {
4020
- const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
4021
- if (tooSmall) {
4022
- ctx = this._getOrReturnCtx(input, ctx);
4023
- addIssueToContext(ctx, {
4024
- code: ZodIssueCode.too_small,
4025
- minimum: check.value,
4026
- type: "number",
4027
- inclusive: check.inclusive,
4028
- exact: false,
4029
- message: check.message
4030
- });
4031
- status.dirty();
4032
- }
4033
- } else if (check.kind === "max") {
4034
- const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
4035
- if (tooBig) {
4036
- ctx = this._getOrReturnCtx(input, ctx);
4037
- addIssueToContext(ctx, {
4038
- code: ZodIssueCode.too_big,
4039
- maximum: check.value,
4040
- type: "number",
4041
- inclusive: check.inclusive,
4042
- exact: false,
4043
- message: check.message
4044
- });
4045
- status.dirty();
4046
- }
4047
- } else if (check.kind === "multipleOf") {
4048
- if (floatSafeRemainder(input.data, check.value) !== 0) {
4049
- ctx = this._getOrReturnCtx(input, ctx);
4050
- addIssueToContext(ctx, {
4051
- code: ZodIssueCode.not_multiple_of,
4052
- multipleOf: check.value,
4053
- message: check.message
4054
- });
4055
- status.dirty();
4056
- }
4057
- } else if (check.kind === "finite") {
4058
- if (!Number.isFinite(input.data)) {
4059
- ctx = this._getOrReturnCtx(input, ctx);
4060
- addIssueToContext(ctx, {
4061
- code: ZodIssueCode.not_finite,
4062
- message: check.message
4063
- });
4064
- status.dirty();
4065
- }
4066
- } else {
4067
- util.assertNever(check);
4068
- }
4069
- }
4070
- return { status: status.value, value: input.data };
4071
- }
4072
- gte(value, message) {
4073
- return this.setLimit("min", value, true, errorUtil.toString(message));
4074
- }
4075
- gt(value, message) {
4076
- return this.setLimit("min", value, false, errorUtil.toString(message));
4077
- }
4078
- lte(value, message) {
4079
- return this.setLimit("max", value, true, errorUtil.toString(message));
4080
- }
4081
- lt(value, message) {
4082
- return this.setLimit("max", value, false, errorUtil.toString(message));
4083
- }
4084
- setLimit(kind, value, inclusive, message) {
4085
- return new _ZodNumber({
4086
- ...this._def,
4087
- checks: [
4088
- ...this._def.checks,
4089
- {
4090
- kind,
4091
- value,
4092
- inclusive,
4093
- message: errorUtil.toString(message)
4094
- }
4095
- ]
4096
- });
4097
- }
4098
- _addCheck(check) {
4099
- return new _ZodNumber({
4100
- ...this._def,
4101
- checks: [...this._def.checks, check]
4102
- });
4103
- }
4104
- int(message) {
4105
- return this._addCheck({
4106
- kind: "int",
4107
- message: errorUtil.toString(message)
4108
- });
4109
- }
4110
- positive(message) {
4111
- return this._addCheck({
4112
- kind: "min",
4113
- value: 0,
4114
- inclusive: false,
4115
- message: errorUtil.toString(message)
4116
- });
4117
- }
4118
- negative(message) {
4119
- return this._addCheck({
4120
- kind: "max",
4121
- value: 0,
4122
- inclusive: false,
4123
- message: errorUtil.toString(message)
4124
- });
4125
- }
4126
- nonpositive(message) {
4127
- return this._addCheck({
4128
- kind: "max",
4129
- value: 0,
4130
- inclusive: true,
4131
- message: errorUtil.toString(message)
4132
- });
4133
- }
4134
- nonnegative(message) {
4135
- return this._addCheck({
4136
- kind: "min",
4137
- value: 0,
4138
- inclusive: true,
4139
- message: errorUtil.toString(message)
4140
- });
4141
- }
4142
- multipleOf(value, message) {
4143
- return this._addCheck({
4144
- kind: "multipleOf",
4145
- value,
4146
- message: errorUtil.toString(message)
4147
- });
4148
- }
4149
- finite(message) {
4150
- return this._addCheck({
4151
- kind: "finite",
4152
- message: errorUtil.toString(message)
4153
- });
4154
- }
4155
- safe(message) {
4156
- return this._addCheck({
4157
- kind: "min",
4158
- inclusive: true,
4159
- value: Number.MIN_SAFE_INTEGER,
4160
- message: errorUtil.toString(message)
4161
- })._addCheck({
4162
- kind: "max",
4163
- inclusive: true,
4164
- value: Number.MAX_SAFE_INTEGER,
4165
- message: errorUtil.toString(message)
4166
- });
4167
- }
4168
- get minValue() {
4169
- let min = null;
4170
- for (const ch of this._def.checks) {
4171
- if (ch.kind === "min") {
4172
- if (min === null || ch.value > min)
4173
- min = ch.value;
4174
- }
4175
- }
4176
- return min;
4177
- }
4178
- get maxValue() {
4179
- let max = null;
4180
- for (const ch of this._def.checks) {
4181
- if (ch.kind === "max") {
4182
- if (max === null || ch.value < max)
4183
- max = ch.value;
4184
- }
4185
- }
4186
- return max;
4187
- }
4188
- get isInt() {
4189
- return !!this._def.checks.find((ch) => ch.kind === "int" || ch.kind === "multipleOf" && util.isInteger(ch.value));
4190
- }
4191
- get isFinite() {
4192
- let max = null;
4193
- let min = null;
4194
- for (const ch of this._def.checks) {
4195
- if (ch.kind === "finite" || ch.kind === "int" || ch.kind === "multipleOf") {
4196
- return true;
4197
- } else if (ch.kind === "min") {
4198
- if (min === null || ch.value > min)
4199
- min = ch.value;
4200
- } else if (ch.kind === "max") {
4201
- if (max === null || ch.value < max)
4202
- max = ch.value;
4203
- }
4204
- }
4205
- return Number.isFinite(min) && Number.isFinite(max);
4206
- }
4207
- };
4208
- ZodNumber.create = (params) => {
4209
- return new ZodNumber({
4210
- checks: [],
4211
- typeName: ZodFirstPartyTypeKind.ZodNumber,
4212
- coerce: params?.coerce || false,
4213
- ...processCreateParams(params)
4214
- });
4215
- };
4216
- var ZodBigInt = class _ZodBigInt extends ZodType {
4217
- constructor() {
4218
- super(...arguments);
4219
- this.min = this.gte;
4220
- this.max = this.lte;
4221
- }
4222
- _parse(input) {
4223
- if (this._def.coerce) {
4224
- try {
4225
- input.data = BigInt(input.data);
4226
- } catch {
4227
- return this._getInvalidInput(input);
4228
- }
4229
- }
4230
- const parsedType = this._getType(input);
4231
- if (parsedType !== ZodParsedType.bigint) {
4232
- return this._getInvalidInput(input);
4233
- }
4234
- let ctx = void 0;
4235
- const status = new ParseStatus();
4236
- for (const check of this._def.checks) {
4237
- if (check.kind === "min") {
4238
- const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
4239
- if (tooSmall) {
4240
- ctx = this._getOrReturnCtx(input, ctx);
4241
- addIssueToContext(ctx, {
4242
- code: ZodIssueCode.too_small,
4243
- type: "bigint",
4244
- minimum: check.value,
4245
- inclusive: check.inclusive,
4246
- message: check.message
4247
- });
4248
- status.dirty();
4249
- }
4250
- } else if (check.kind === "max") {
4251
- const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
4252
- if (tooBig) {
4253
- ctx = this._getOrReturnCtx(input, ctx);
4254
- addIssueToContext(ctx, {
4255
- code: ZodIssueCode.too_big,
4256
- type: "bigint",
4257
- maximum: check.value,
4258
- inclusive: check.inclusive,
4259
- message: check.message
4260
- });
4261
- status.dirty();
4262
- }
4263
- } else if (check.kind === "multipleOf") {
4264
- if (input.data % check.value !== BigInt(0)) {
4265
- ctx = this._getOrReturnCtx(input, ctx);
4266
- addIssueToContext(ctx, {
4267
- code: ZodIssueCode.not_multiple_of,
4268
- multipleOf: check.value,
4269
- message: check.message
4270
- });
4271
- status.dirty();
4272
- }
4273
- } else {
4274
- util.assertNever(check);
4275
- }
4276
- }
4277
- return { status: status.value, value: input.data };
4278
- }
4279
- _getInvalidInput(input) {
4280
- const ctx = this._getOrReturnCtx(input);
4281
- addIssueToContext(ctx, {
4282
- code: ZodIssueCode.invalid_type,
4283
- expected: ZodParsedType.bigint,
4284
- received: ctx.parsedType
4285
- });
4286
- return INVALID;
4287
- }
4288
- gte(value, message) {
4289
- return this.setLimit("min", value, true, errorUtil.toString(message));
4290
- }
4291
- gt(value, message) {
4292
- return this.setLimit("min", value, false, errorUtil.toString(message));
4293
- }
4294
- lte(value, message) {
4295
- return this.setLimit("max", value, true, errorUtil.toString(message));
4296
- }
4297
- lt(value, message) {
4298
- return this.setLimit("max", value, false, errorUtil.toString(message));
4299
- }
4300
- setLimit(kind, value, inclusive, message) {
4301
- return new _ZodBigInt({
4302
- ...this._def,
4303
- checks: [
4304
- ...this._def.checks,
4305
- {
4306
- kind,
4307
- value,
4308
- inclusive,
4309
- message: errorUtil.toString(message)
4310
- }
4311
- ]
4312
- });
4313
- }
4314
- _addCheck(check) {
4315
- return new _ZodBigInt({
4316
- ...this._def,
4317
- checks: [...this._def.checks, check]
4318
- });
4319
- }
4320
- positive(message) {
4321
- return this._addCheck({
4322
- kind: "min",
4323
- value: BigInt(0),
4324
- inclusive: false,
4325
- message: errorUtil.toString(message)
4326
- });
4327
- }
4328
- negative(message) {
4329
- return this._addCheck({
4330
- kind: "max",
4331
- value: BigInt(0),
4332
- inclusive: false,
4333
- message: errorUtil.toString(message)
4334
- });
4335
- }
4336
- nonpositive(message) {
4337
- return this._addCheck({
4338
- kind: "max",
4339
- value: BigInt(0),
4340
- inclusive: true,
4341
- message: errorUtil.toString(message)
4342
- });
4343
- }
4344
- nonnegative(message) {
4345
- return this._addCheck({
4346
- kind: "min",
4347
- value: BigInt(0),
4348
- inclusive: true,
4349
- message: errorUtil.toString(message)
4350
- });
4351
- }
4352
- multipleOf(value, message) {
4353
- return this._addCheck({
4354
- kind: "multipleOf",
4355
- value,
4356
- message: errorUtil.toString(message)
4357
- });
4358
- }
4359
- get minValue() {
4360
- let min = null;
4361
- for (const ch of this._def.checks) {
4362
- if (ch.kind === "min") {
4363
- if (min === null || ch.value > min)
4364
- min = ch.value;
4365
- }
4366
- }
4367
- return min;
4368
- }
4369
- get maxValue() {
4370
- let max = null;
4371
- for (const ch of this._def.checks) {
4372
- if (ch.kind === "max") {
4373
- if (max === null || ch.value < max)
4374
- max = ch.value;
4375
- }
4376
- }
4377
- return max;
4378
- }
4379
- };
4380
- ZodBigInt.create = (params) => {
4381
- return new ZodBigInt({
4382
- checks: [],
4383
- typeName: ZodFirstPartyTypeKind.ZodBigInt,
4384
- coerce: params?.coerce ?? false,
4385
- ...processCreateParams(params)
4386
- });
4387
- };
4388
- var ZodBoolean = class extends ZodType {
4389
- _parse(input) {
4390
- if (this._def.coerce) {
4391
- input.data = Boolean(input.data);
4392
- }
4393
- const parsedType = this._getType(input);
4394
- if (parsedType !== ZodParsedType.boolean) {
4395
- const ctx = this._getOrReturnCtx(input);
4396
- addIssueToContext(ctx, {
4397
- code: ZodIssueCode.invalid_type,
4398
- expected: ZodParsedType.boolean,
4399
- received: ctx.parsedType
4400
- });
4401
- return INVALID;
4402
- }
4403
- return OK(input.data);
4404
- }
4405
- };
4406
- ZodBoolean.create = (params) => {
4407
- return new ZodBoolean({
4408
- typeName: ZodFirstPartyTypeKind.ZodBoolean,
4409
- coerce: params?.coerce || false,
4410
- ...processCreateParams(params)
4411
- });
4412
- };
4413
- var ZodDate = class _ZodDate extends ZodType {
4414
- _parse(input) {
4415
- if (this._def.coerce) {
4416
- input.data = new Date(input.data);
4417
- }
4418
- const parsedType = this._getType(input);
4419
- if (parsedType !== ZodParsedType.date) {
4420
- const ctx2 = this._getOrReturnCtx(input);
4421
- addIssueToContext(ctx2, {
4422
- code: ZodIssueCode.invalid_type,
4423
- expected: ZodParsedType.date,
4424
- received: ctx2.parsedType
4425
- });
4426
- return INVALID;
4427
- }
4428
- if (Number.isNaN(input.data.getTime())) {
4429
- const ctx2 = this._getOrReturnCtx(input);
4430
- addIssueToContext(ctx2, {
4431
- code: ZodIssueCode.invalid_date
4432
- });
4433
- return INVALID;
4434
- }
4435
- const status = new ParseStatus();
4436
- let ctx = void 0;
4437
- for (const check of this._def.checks) {
4438
- if (check.kind === "min") {
4439
- if (input.data.getTime() < check.value) {
4440
- ctx = this._getOrReturnCtx(input, ctx);
4441
- addIssueToContext(ctx, {
4442
- code: ZodIssueCode.too_small,
4443
- message: check.message,
4444
- inclusive: true,
4445
- exact: false,
4446
- minimum: check.value,
4447
- type: "date"
4448
- });
4449
- status.dirty();
4450
- }
4451
- } else if (check.kind === "max") {
4452
- if (input.data.getTime() > check.value) {
4453
- ctx = this._getOrReturnCtx(input, ctx);
4454
- addIssueToContext(ctx, {
4455
- code: ZodIssueCode.too_big,
4456
- message: check.message,
4457
- inclusive: true,
4458
- exact: false,
4459
- maximum: check.value,
4460
- type: "date"
4461
- });
4462
- status.dirty();
4463
- }
4464
- } else {
4465
- util.assertNever(check);
4466
- }
4467
- }
4468
- return {
4469
- status: status.value,
4470
- value: new Date(input.data.getTime())
4471
- };
4472
- }
4473
- _addCheck(check) {
4474
- return new _ZodDate({
4475
- ...this._def,
4476
- checks: [...this._def.checks, check]
4477
- });
4478
- }
4479
- min(minDate, message) {
4480
- return this._addCheck({
4481
- kind: "min",
4482
- value: minDate.getTime(),
4483
- message: errorUtil.toString(message)
4484
- });
4485
- }
4486
- max(maxDate, message) {
4487
- return this._addCheck({
4488
- kind: "max",
4489
- value: maxDate.getTime(),
4490
- message: errorUtil.toString(message)
4491
- });
4492
- }
4493
- get minDate() {
4494
- let min = null;
4495
- for (const ch of this._def.checks) {
4496
- if (ch.kind === "min") {
4497
- if (min === null || ch.value > min)
4498
- min = ch.value;
4499
- }
4500
- }
4501
- return min != null ? new Date(min) : null;
4502
- }
4503
- get maxDate() {
4504
- let max = null;
4505
- for (const ch of this._def.checks) {
4506
- if (ch.kind === "max") {
4507
- if (max === null || ch.value < max)
4508
- max = ch.value;
4509
- }
4510
- }
4511
- return max != null ? new Date(max) : null;
4512
- }
4513
- };
4514
- ZodDate.create = (params) => {
4515
- return new ZodDate({
4516
- checks: [],
4517
- coerce: params?.coerce || false,
4518
- typeName: ZodFirstPartyTypeKind.ZodDate,
4519
- ...processCreateParams(params)
4520
- });
4521
- };
4522
- var ZodSymbol = class extends ZodType {
4523
- _parse(input) {
4524
- const parsedType = this._getType(input);
4525
- if (parsedType !== ZodParsedType.symbol) {
4526
- const ctx = this._getOrReturnCtx(input);
4527
- addIssueToContext(ctx, {
4528
- code: ZodIssueCode.invalid_type,
4529
- expected: ZodParsedType.symbol,
4530
- received: ctx.parsedType
4531
- });
4532
- return INVALID;
4533
- }
4534
- return OK(input.data);
4535
- }
4536
- };
4537
- ZodSymbol.create = (params) => {
4538
- return new ZodSymbol({
4539
- typeName: ZodFirstPartyTypeKind.ZodSymbol,
4540
- ...processCreateParams(params)
4541
- });
4542
- };
4543
- var ZodUndefined = class extends ZodType {
4544
- _parse(input) {
4545
- const parsedType = this._getType(input);
4546
- if (parsedType !== ZodParsedType.undefined) {
4547
- const ctx = this._getOrReturnCtx(input);
4548
- addIssueToContext(ctx, {
4549
- code: ZodIssueCode.invalid_type,
4550
- expected: ZodParsedType.undefined,
4551
- received: ctx.parsedType
4552
- });
4553
- return INVALID;
4554
- }
4555
- return OK(input.data);
4556
- }
4557
- };
4558
- ZodUndefined.create = (params) => {
4559
- return new ZodUndefined({
4560
- typeName: ZodFirstPartyTypeKind.ZodUndefined,
4561
- ...processCreateParams(params)
4562
- });
4563
- };
4564
- var ZodNull = class extends ZodType {
4565
- _parse(input) {
4566
- const parsedType = this._getType(input);
4567
- if (parsedType !== ZodParsedType.null) {
4568
- const ctx = this._getOrReturnCtx(input);
4569
- addIssueToContext(ctx, {
4570
- code: ZodIssueCode.invalid_type,
4571
- expected: ZodParsedType.null,
4572
- received: ctx.parsedType
4573
- });
4574
- return INVALID;
4575
- }
4576
- return OK(input.data);
4577
- }
4578
- };
4579
- ZodNull.create = (params) => {
4580
- return new ZodNull({
4581
- typeName: ZodFirstPartyTypeKind.ZodNull,
4582
- ...processCreateParams(params)
4583
- });
4584
- };
4585
- var ZodAny = class extends ZodType {
4586
- constructor() {
4587
- super(...arguments);
4588
- this._any = true;
4589
- }
4590
- _parse(input) {
4591
- return OK(input.data);
4592
- }
4593
- };
4594
- ZodAny.create = (params) => {
4595
- return new ZodAny({
4596
- typeName: ZodFirstPartyTypeKind.ZodAny,
4597
- ...processCreateParams(params)
4598
- });
4599
- };
4600
- var ZodUnknown = class extends ZodType {
4601
- constructor() {
4602
- super(...arguments);
4603
- this._unknown = true;
4604
- }
4605
- _parse(input) {
4606
- return OK(input.data);
4607
- }
4608
- };
4609
- ZodUnknown.create = (params) => {
4610
- return new ZodUnknown({
4611
- typeName: ZodFirstPartyTypeKind.ZodUnknown,
4612
- ...processCreateParams(params)
4613
- });
4614
- };
4615
- var ZodNever = class extends ZodType {
4616
- _parse(input) {
4617
- const ctx = this._getOrReturnCtx(input);
4618
- addIssueToContext(ctx, {
4619
- code: ZodIssueCode.invalid_type,
4620
- expected: ZodParsedType.never,
4621
- received: ctx.parsedType
4622
- });
4623
- return INVALID;
4624
- }
4625
- };
4626
- ZodNever.create = (params) => {
4627
- return new ZodNever({
4628
- typeName: ZodFirstPartyTypeKind.ZodNever,
4629
- ...processCreateParams(params)
4630
- });
4631
- };
4632
- var ZodVoid = class extends ZodType {
4633
- _parse(input) {
4634
- const parsedType = this._getType(input);
4635
- if (parsedType !== ZodParsedType.undefined) {
4636
- const ctx = this._getOrReturnCtx(input);
4637
- addIssueToContext(ctx, {
4638
- code: ZodIssueCode.invalid_type,
4639
- expected: ZodParsedType.void,
4640
- received: ctx.parsedType
4641
- });
4642
- return INVALID;
4643
- }
4644
- return OK(input.data);
4645
- }
4646
- };
4647
- ZodVoid.create = (params) => {
4648
- return new ZodVoid({
4649
- typeName: ZodFirstPartyTypeKind.ZodVoid,
4650
- ...processCreateParams(params)
4651
- });
4652
- };
4653
- var ZodArray = class _ZodArray extends ZodType {
4654
- _parse(input) {
4655
- const { ctx, status } = this._processInputParams(input);
4656
- const def = this._def;
4657
- if (ctx.parsedType !== ZodParsedType.array) {
4658
- addIssueToContext(ctx, {
4659
- code: ZodIssueCode.invalid_type,
4660
- expected: ZodParsedType.array,
4661
- received: ctx.parsedType
4662
- });
4663
- return INVALID;
4664
- }
4665
- if (def.exactLength !== null) {
4666
- const tooBig = ctx.data.length > def.exactLength.value;
4667
- const tooSmall = ctx.data.length < def.exactLength.value;
4668
- if (tooBig || tooSmall) {
4669
- addIssueToContext(ctx, {
4670
- code: tooBig ? ZodIssueCode.too_big : ZodIssueCode.too_small,
4671
- minimum: tooSmall ? def.exactLength.value : void 0,
4672
- maximum: tooBig ? def.exactLength.value : void 0,
4673
- type: "array",
4674
- inclusive: true,
4675
- exact: true,
4676
- message: def.exactLength.message
4677
- });
4678
- status.dirty();
4679
- }
4680
- }
4681
- if (def.minLength !== null) {
4682
- if (ctx.data.length < def.minLength.value) {
4683
- addIssueToContext(ctx, {
4684
- code: ZodIssueCode.too_small,
4685
- minimum: def.minLength.value,
4686
- type: "array",
4687
- inclusive: true,
4688
- exact: false,
4689
- message: def.minLength.message
4690
- });
4691
- status.dirty();
4692
- }
4693
- }
4694
- if (def.maxLength !== null) {
4695
- if (ctx.data.length > def.maxLength.value) {
4696
- addIssueToContext(ctx, {
4697
- code: ZodIssueCode.too_big,
4698
- maximum: def.maxLength.value,
4699
- type: "array",
4700
- inclusive: true,
4701
- exact: false,
4702
- message: def.maxLength.message
4703
- });
4704
- status.dirty();
4705
- }
4706
- }
4707
- if (ctx.common.async) {
4708
- return Promise.all([...ctx.data].map((item, i3) => {
4709
- return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i3));
4710
- })).then((result2) => {
4711
- return ParseStatus.mergeArray(status, result2);
4712
- });
4713
- }
4714
- const result = [...ctx.data].map((item, i3) => {
4715
- return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i3));
4716
- });
4717
- return ParseStatus.mergeArray(status, result);
4718
- }
4719
- get element() {
4720
- return this._def.type;
4721
- }
4722
- min(minLength, message) {
4723
- return new _ZodArray({
4724
- ...this._def,
4725
- minLength: { value: minLength, message: errorUtil.toString(message) }
4726
- });
4727
- }
4728
- max(maxLength, message) {
4729
- return new _ZodArray({
4730
- ...this._def,
4731
- maxLength: { value: maxLength, message: errorUtil.toString(message) }
4732
- });
4733
- }
4734
- length(len, message) {
4735
- return new _ZodArray({
4736
- ...this._def,
4737
- exactLength: { value: len, message: errorUtil.toString(message) }
4738
- });
4739
- }
4740
- nonempty(message) {
4741
- return this.min(1, message);
4742
- }
4743
- };
4744
- ZodArray.create = (schema, params) => {
4745
- return new ZodArray({
4746
- type: schema,
4747
- minLength: null,
4748
- maxLength: null,
4749
- exactLength: null,
4750
- typeName: ZodFirstPartyTypeKind.ZodArray,
4751
- ...processCreateParams(params)
4752
- });
4753
- };
4754
- function deepPartialify(schema) {
4755
- if (schema instanceof ZodObject) {
4756
- const newShape = {};
4757
- for (const key in schema.shape) {
4758
- const fieldSchema = schema.shape[key];
4759
- newShape[key] = ZodOptional.create(deepPartialify(fieldSchema));
4760
- }
4761
- return new ZodObject({
4762
- ...schema._def,
4763
- shape: () => newShape
4764
- });
4765
- } else if (schema instanceof ZodArray) {
4766
- return new ZodArray({
4767
- ...schema._def,
4768
- type: deepPartialify(schema.element)
4769
- });
4770
- } else if (schema instanceof ZodOptional) {
4771
- return ZodOptional.create(deepPartialify(schema.unwrap()));
4772
- } else if (schema instanceof ZodNullable) {
4773
- return ZodNullable.create(deepPartialify(schema.unwrap()));
4774
- } else if (schema instanceof ZodTuple) {
4775
- return ZodTuple.create(schema.items.map((item) => deepPartialify(item)));
4776
- } else {
4777
- return schema;
4778
- }
4779
- }
4780
- var ZodObject = class _ZodObject extends ZodType {
4781
- constructor() {
4782
- super(...arguments);
4783
- this._cached = null;
4784
- this.nonstrict = this.passthrough;
4785
- this.augment = this.extend;
4786
- }
4787
- _getCached() {
4788
- if (this._cached !== null)
4789
- return this._cached;
4790
- const shape = this._def.shape();
4791
- const keys = util.objectKeys(shape);
4792
- this._cached = { shape, keys };
4793
- return this._cached;
4794
- }
4795
- _parse(input) {
4796
- const parsedType = this._getType(input);
4797
- if (parsedType !== ZodParsedType.object) {
4798
- const ctx2 = this._getOrReturnCtx(input);
4799
- addIssueToContext(ctx2, {
4800
- code: ZodIssueCode.invalid_type,
4801
- expected: ZodParsedType.object,
4802
- received: ctx2.parsedType
4803
- });
4804
- return INVALID;
4805
- }
4806
- const { status, ctx } = this._processInputParams(input);
4807
- const { shape, keys: shapeKeys } = this._getCached();
4808
- const extraKeys = [];
4809
- if (!(this._def.catchall instanceof ZodNever && this._def.unknownKeys === "strip")) {
4810
- for (const key in ctx.data) {
4811
- if (!shapeKeys.includes(key)) {
4812
- extraKeys.push(key);
4813
- }
4814
- }
4815
- }
4816
- const pairs = [];
4817
- for (const key of shapeKeys) {
4818
- const keyValidator = shape[key];
4819
- const value = ctx.data[key];
4820
- pairs.push({
4821
- key: { status: "valid", value: key },
4822
- value: keyValidator._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
4823
- alwaysSet: key in ctx.data
4824
- });
4825
- }
4826
- if (this._def.catchall instanceof ZodNever) {
4827
- const unknownKeys = this._def.unknownKeys;
4828
- if (unknownKeys === "passthrough") {
4829
- for (const key of extraKeys) {
4830
- pairs.push({
4831
- key: { status: "valid", value: key },
4832
- value: { status: "valid", value: ctx.data[key] }
4833
- });
4834
- }
4835
- } else if (unknownKeys === "strict") {
4836
- if (extraKeys.length > 0) {
4837
- addIssueToContext(ctx, {
4838
- code: ZodIssueCode.unrecognized_keys,
4839
- keys: extraKeys
4840
- });
4841
- status.dirty();
4842
- }
4843
- } else if (unknownKeys === "strip") {
4844
- } else {
4845
- throw new Error(`Internal ZodObject error: invalid unknownKeys value.`);
4846
- }
4847
- } else {
4848
- const catchall = this._def.catchall;
4849
- for (const key of extraKeys) {
4850
- const value = ctx.data[key];
4851
- pairs.push({
4852
- key: { status: "valid", value: key },
4853
- value: catchall._parse(
4854
- new ParseInputLazyPath(ctx, value, ctx.path, key)
4855
- //, ctx.child(key), value, getParsedType(value)
4856
- ),
4857
- alwaysSet: key in ctx.data
4858
- });
4859
- }
4860
- }
4861
- if (ctx.common.async) {
4862
- return Promise.resolve().then(async () => {
4863
- const syncPairs = [];
4864
- for (const pair of pairs) {
4865
- const key = await pair.key;
4866
- const value = await pair.value;
4867
- syncPairs.push({
4868
- key,
4869
- value,
4870
- alwaysSet: pair.alwaysSet
4871
- });
4872
- }
4873
- return syncPairs;
4874
- }).then((syncPairs) => {
4875
- return ParseStatus.mergeObjectSync(status, syncPairs);
4876
- });
4877
- } else {
4878
- return ParseStatus.mergeObjectSync(status, pairs);
4879
- }
4880
- }
4881
- get shape() {
4882
- return this._def.shape();
4883
- }
4884
- strict(message) {
4885
- errorUtil.errToObj;
4886
- return new _ZodObject({
4887
- ...this._def,
4888
- unknownKeys: "strict",
4889
- ...message !== void 0 ? {
4890
- errorMap: (issue, ctx) => {
4891
- const defaultError = this._def.errorMap?.(issue, ctx).message ?? ctx.defaultError;
4892
- if (issue.code === "unrecognized_keys")
4893
- return {
4894
- message: errorUtil.errToObj(message).message ?? defaultError
4895
- };
4896
- return {
4897
- message: defaultError
4898
- };
4899
- }
4900
- } : {}
4901
- });
4902
- }
4903
- strip() {
4904
- return new _ZodObject({
4905
- ...this._def,
4906
- unknownKeys: "strip"
4907
- });
4908
- }
4909
- passthrough() {
4910
- return new _ZodObject({
4911
- ...this._def,
4912
- unknownKeys: "passthrough"
4913
- });
4914
- }
4915
- // const AugmentFactory =
4916
- // <Def extends ZodObjectDef>(def: Def) =>
4917
- // <Augmentation extends ZodRawShape>(
4918
- // augmentation: Augmentation
4919
- // ): ZodObject<
4920
- // extendShape<ReturnType<Def["shape"]>, Augmentation>,
4921
- // Def["unknownKeys"],
4922
- // Def["catchall"]
4923
- // > => {
4924
- // return new ZodObject({
4925
- // ...def,
4926
- // shape: () => ({
4927
- // ...def.shape(),
4928
- // ...augmentation,
4929
- // }),
4930
- // }) as any;
4931
- // };
4932
- extend(augmentation) {
4933
- return new _ZodObject({
4934
- ...this._def,
4935
- shape: () => ({
4936
- ...this._def.shape(),
4937
- ...augmentation
4938
- })
4939
- });
4940
- }
4941
- /**
4942
- * Prior to zod@1.0.12 there was a bug in the
4943
- * inferred type of merged objects. Please
4944
- * upgrade if you are experiencing issues.
4945
- */
4946
- merge(merging) {
4947
- const merged = new _ZodObject({
4948
- unknownKeys: merging._def.unknownKeys,
4949
- catchall: merging._def.catchall,
4950
- shape: () => ({
4951
- ...this._def.shape(),
4952
- ...merging._def.shape()
4953
- }),
4954
- typeName: ZodFirstPartyTypeKind.ZodObject
4955
- });
4956
- return merged;
4957
- }
4958
- // merge<
4959
- // Incoming extends AnyZodObject,
4960
- // Augmentation extends Incoming["shape"],
4961
- // NewOutput extends {
4962
- // [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
4963
- // ? Augmentation[k]["_output"]
4964
- // : k extends keyof Output
4965
- // ? Output[k]
4966
- // : never;
4967
- // },
4968
- // NewInput extends {
4969
- // [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
4970
- // ? Augmentation[k]["_input"]
4971
- // : k extends keyof Input
4972
- // ? Input[k]
4973
- // : never;
4974
- // }
4975
- // >(
4976
- // merging: Incoming
4977
- // ): ZodObject<
4978
- // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
4979
- // Incoming["_def"]["unknownKeys"],
4980
- // Incoming["_def"]["catchall"],
4981
- // NewOutput,
4982
- // NewInput
4983
- // > {
4984
- // const merged: any = new ZodObject({
4985
- // unknownKeys: merging._def.unknownKeys,
4986
- // catchall: merging._def.catchall,
4987
- // shape: () =>
4988
- // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
4989
- // typeName: ZodFirstPartyTypeKind.ZodObject,
4990
- // }) as any;
4991
- // return merged;
4992
- // }
4993
- setKey(key, schema) {
4994
- return this.augment({ [key]: schema });
4995
- }
4996
- // merge<Incoming extends AnyZodObject>(
4997
- // merging: Incoming
4998
- // ): //ZodObject<T & Incoming["_shape"], UnknownKeys, Catchall> = (merging) => {
4999
- // ZodObject<
5000
- // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
5001
- // Incoming["_def"]["unknownKeys"],
5002
- // Incoming["_def"]["catchall"]
5003
- // > {
5004
- // // const mergedShape = objectUtil.mergeShapes(
5005
- // // this._def.shape(),
5006
- // // merging._def.shape()
5007
- // // );
5008
- // const merged: any = new ZodObject({
5009
- // unknownKeys: merging._def.unknownKeys,
5010
- // catchall: merging._def.catchall,
5011
- // shape: () =>
5012
- // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
5013
- // typeName: ZodFirstPartyTypeKind.ZodObject,
5014
- // }) as any;
5015
- // return merged;
5016
- // }
5017
- catchall(index2) {
5018
- return new _ZodObject({
5019
- ...this._def,
5020
- catchall: index2
5021
- });
5022
- }
5023
- pick(mask) {
5024
- const shape = {};
5025
- for (const key of util.objectKeys(mask)) {
5026
- if (mask[key] && this.shape[key]) {
5027
- shape[key] = this.shape[key];
5028
- }
5029
- }
5030
- return new _ZodObject({
5031
- ...this._def,
5032
- shape: () => shape
5033
- });
5034
- }
5035
- omit(mask) {
5036
- const shape = {};
5037
- for (const key of util.objectKeys(this.shape)) {
5038
- if (!mask[key]) {
5039
- shape[key] = this.shape[key];
5040
- }
5041
- }
5042
- return new _ZodObject({
5043
- ...this._def,
5044
- shape: () => shape
5045
- });
5046
- }
5047
- /**
5048
- * @deprecated
5049
- */
5050
- deepPartial() {
5051
- return deepPartialify(this);
5052
- }
5053
- partial(mask) {
5054
- const newShape = {};
5055
- for (const key of util.objectKeys(this.shape)) {
5056
- const fieldSchema = this.shape[key];
5057
- if (mask && !mask[key]) {
5058
- newShape[key] = fieldSchema;
5059
- } else {
5060
- newShape[key] = fieldSchema.optional();
5061
- }
5062
- }
5063
- return new _ZodObject({
5064
- ...this._def,
5065
- shape: () => newShape
5066
- });
5067
- }
5068
- required(mask) {
5069
- const newShape = {};
5070
- for (const key of util.objectKeys(this.shape)) {
5071
- if (mask && !mask[key]) {
5072
- newShape[key] = this.shape[key];
5073
- } else {
5074
- const fieldSchema = this.shape[key];
5075
- let newField = fieldSchema;
5076
- while (newField instanceof ZodOptional) {
5077
- newField = newField._def.innerType;
5078
- }
5079
- newShape[key] = newField;
5080
- }
5081
- }
5082
- return new _ZodObject({
5083
- ...this._def,
5084
- shape: () => newShape
5085
- });
5086
- }
5087
- keyof() {
5088
- return createZodEnum(util.objectKeys(this.shape));
5089
- }
5090
- };
5091
- ZodObject.create = (shape, params) => {
5092
- return new ZodObject({
5093
- shape: () => shape,
5094
- unknownKeys: "strip",
5095
- catchall: ZodNever.create(),
5096
- typeName: ZodFirstPartyTypeKind.ZodObject,
5097
- ...processCreateParams(params)
5098
- });
5099
- };
5100
- ZodObject.strictCreate = (shape, params) => {
5101
- return new ZodObject({
5102
- shape: () => shape,
5103
- unknownKeys: "strict",
5104
- catchall: ZodNever.create(),
5105
- typeName: ZodFirstPartyTypeKind.ZodObject,
5106
- ...processCreateParams(params)
5107
- });
5108
- };
5109
- ZodObject.lazycreate = (shape, params) => {
5110
- return new ZodObject({
5111
- shape,
5112
- unknownKeys: "strip",
5113
- catchall: ZodNever.create(),
5114
- typeName: ZodFirstPartyTypeKind.ZodObject,
5115
- ...processCreateParams(params)
5116
- });
5117
- };
5118
- var ZodUnion = class extends ZodType {
5119
- _parse(input) {
5120
- const { ctx } = this._processInputParams(input);
5121
- const options = this._def.options;
5122
- function handleResults(results) {
5123
- for (const result of results) {
5124
- if (result.result.status === "valid") {
5125
- return result.result;
5126
- }
5127
- }
5128
- for (const result of results) {
5129
- if (result.result.status === "dirty") {
5130
- ctx.common.issues.push(...result.ctx.common.issues);
5131
- return result.result;
5132
- }
5133
- }
5134
- const unionErrors = results.map((result) => new ZodError(result.ctx.common.issues));
5135
- addIssueToContext(ctx, {
5136
- code: ZodIssueCode.invalid_union,
5137
- unionErrors
5138
- });
5139
- return INVALID;
5140
- }
5141
- if (ctx.common.async) {
5142
- return Promise.all(options.map(async (option) => {
5143
- const childCtx = {
5144
- ...ctx,
5145
- common: {
5146
- ...ctx.common,
5147
- issues: []
5148
- },
5149
- parent: null
5150
- };
5151
- return {
5152
- result: await option._parseAsync({
5153
- data: ctx.data,
5154
- path: ctx.path,
5155
- parent: childCtx
5156
- }),
5157
- ctx: childCtx
5158
- };
5159
- })).then(handleResults);
5160
- } else {
5161
- let dirty = void 0;
5162
- const issues = [];
5163
- for (const option of options) {
5164
- const childCtx = {
5165
- ...ctx,
5166
- common: {
5167
- ...ctx.common,
5168
- issues: []
5169
- },
5170
- parent: null
5171
- };
5172
- const result = option._parseSync({
5173
- data: ctx.data,
5174
- path: ctx.path,
5175
- parent: childCtx
5176
- });
5177
- if (result.status === "valid") {
5178
- return result;
5179
- } else if (result.status === "dirty" && !dirty) {
5180
- dirty = { result, ctx: childCtx };
5181
- }
5182
- if (childCtx.common.issues.length) {
5183
- issues.push(childCtx.common.issues);
5184
- }
5185
- }
5186
- if (dirty) {
5187
- ctx.common.issues.push(...dirty.ctx.common.issues);
5188
- return dirty.result;
5189
- }
5190
- const unionErrors = issues.map((issues2) => new ZodError(issues2));
5191
- addIssueToContext(ctx, {
5192
- code: ZodIssueCode.invalid_union,
5193
- unionErrors
5194
- });
5195
- return INVALID;
5196
- }
5197
- }
5198
- get options() {
5199
- return this._def.options;
5200
- }
5201
- };
5202
- ZodUnion.create = (types, params) => {
5203
- return new ZodUnion({
5204
- options: types,
5205
- typeName: ZodFirstPartyTypeKind.ZodUnion,
5206
- ...processCreateParams(params)
5207
- });
5208
- };
5209
- var getDiscriminator = (type) => {
5210
- if (type instanceof ZodLazy) {
5211
- return getDiscriminator(type.schema);
5212
- } else if (type instanceof ZodEffects) {
5213
- return getDiscriminator(type.innerType());
5214
- } else if (type instanceof ZodLiteral) {
5215
- return [type.value];
5216
- } else if (type instanceof ZodEnum) {
5217
- return type.options;
5218
- } else if (type instanceof ZodNativeEnum) {
5219
- return util.objectValues(type.enum);
5220
- } else if (type instanceof ZodDefault) {
5221
- return getDiscriminator(type._def.innerType);
5222
- } else if (type instanceof ZodUndefined) {
5223
- return [void 0];
5224
- } else if (type instanceof ZodNull) {
5225
- return [null];
5226
- } else if (type instanceof ZodOptional) {
5227
- return [void 0, ...getDiscriminator(type.unwrap())];
5228
- } else if (type instanceof ZodNullable) {
5229
- return [null, ...getDiscriminator(type.unwrap())];
5230
- } else if (type instanceof ZodBranded) {
5231
- return getDiscriminator(type.unwrap());
5232
- } else if (type instanceof ZodReadonly) {
5233
- return getDiscriminator(type.unwrap());
5234
- } else if (type instanceof ZodCatch) {
5235
- return getDiscriminator(type._def.innerType);
5236
- } else {
5237
- return [];
5238
- }
5239
- };
5240
- var ZodDiscriminatedUnion = class _ZodDiscriminatedUnion extends ZodType {
5241
- _parse(input) {
5242
- const { ctx } = this._processInputParams(input);
5243
- if (ctx.parsedType !== ZodParsedType.object) {
5244
- addIssueToContext(ctx, {
5245
- code: ZodIssueCode.invalid_type,
5246
- expected: ZodParsedType.object,
5247
- received: ctx.parsedType
5248
- });
5249
- return INVALID;
5250
- }
5251
- const discriminator = this.discriminator;
5252
- const discriminatorValue = ctx.data[discriminator];
5253
- const option = this.optionsMap.get(discriminatorValue);
5254
- if (!option) {
5255
- addIssueToContext(ctx, {
5256
- code: ZodIssueCode.invalid_union_discriminator,
5257
- options: Array.from(this.optionsMap.keys()),
5258
- path: [discriminator]
5259
- });
5260
- return INVALID;
5261
- }
5262
- if (ctx.common.async) {
5263
- return option._parseAsync({
5264
- data: ctx.data,
5265
- path: ctx.path,
5266
- parent: ctx
5267
- });
5268
- } else {
5269
- return option._parseSync({
5270
- data: ctx.data,
5271
- path: ctx.path,
5272
- parent: ctx
5273
- });
5274
- }
5275
- }
5276
- get discriminator() {
5277
- return this._def.discriminator;
5278
- }
5279
- get options() {
5280
- return this._def.options;
5281
- }
5282
- get optionsMap() {
5283
- return this._def.optionsMap;
5284
- }
5285
- /**
5286
- * The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
5287
- * However, it only allows a union of objects, all of which need to share a discriminator property. This property must
5288
- * have a different value for each object in the union.
5289
- * @param discriminator the name of the discriminator property
5290
- * @param types an array of object schemas
5291
- * @param params
5292
- */
5293
- static create(discriminator, options, params) {
5294
- const optionsMap = /* @__PURE__ */ new Map();
5295
- for (const type of options) {
5296
- const discriminatorValues = getDiscriminator(type.shape[discriminator]);
5297
- if (!discriminatorValues.length) {
5298
- throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
5299
- }
5300
- for (const value of discriminatorValues) {
5301
- if (optionsMap.has(value)) {
5302
- throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
5303
- }
5304
- optionsMap.set(value, type);
5305
- }
5306
- }
5307
- return new _ZodDiscriminatedUnion({
5308
- typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
5309
- discriminator,
5310
- options,
5311
- optionsMap,
5312
- ...processCreateParams(params)
5313
- });
5314
- }
5315
- };
5316
- function mergeValues(a4, b) {
5317
- const aType = getParsedType(a4);
5318
- const bType = getParsedType(b);
5319
- if (a4 === b) {
5320
- return { valid: true, data: a4 };
5321
- } else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
5322
- const bKeys = util.objectKeys(b);
5323
- const sharedKeys = util.objectKeys(a4).filter((key) => bKeys.indexOf(key) !== -1);
5324
- const newObj = { ...a4, ...b };
5325
- for (const key of sharedKeys) {
5326
- const sharedValue = mergeValues(a4[key], b[key]);
5327
- if (!sharedValue.valid) {
5328
- return { valid: false };
5329
- }
5330
- newObj[key] = sharedValue.data;
5331
- }
5332
- return { valid: true, data: newObj };
5333
- } else if (aType === ZodParsedType.array && bType === ZodParsedType.array) {
5334
- if (a4.length !== b.length) {
5335
- return { valid: false };
5336
- }
5337
- const newArray = [];
5338
- for (let index2 = 0; index2 < a4.length; index2++) {
5339
- const itemA = a4[index2];
5340
- const itemB = b[index2];
5341
- const sharedValue = mergeValues(itemA, itemB);
5342
- if (!sharedValue.valid) {
5343
- return { valid: false };
5344
- }
5345
- newArray.push(sharedValue.data);
5346
- }
5347
- return { valid: true, data: newArray };
5348
- } else if (aType === ZodParsedType.date && bType === ZodParsedType.date && +a4 === +b) {
5349
- return { valid: true, data: a4 };
5350
- } else {
5351
- return { valid: false };
5352
- }
5353
- }
5354
- var ZodIntersection = class extends ZodType {
5355
- _parse(input) {
5356
- const { status, ctx } = this._processInputParams(input);
5357
- const handleParsed = (parsedLeft, parsedRight) => {
5358
- if (isAborted(parsedLeft) || isAborted(parsedRight)) {
5359
- return INVALID;
5360
- }
5361
- const merged = mergeValues(parsedLeft.value, parsedRight.value);
5362
- if (!merged.valid) {
5363
- addIssueToContext(ctx, {
5364
- code: ZodIssueCode.invalid_intersection_types
5365
- });
5366
- return INVALID;
5367
- }
5368
- if (isDirty(parsedLeft) || isDirty(parsedRight)) {
5369
- status.dirty();
5370
- }
5371
- return { status: status.value, value: merged.data };
5372
- };
5373
- if (ctx.common.async) {
5374
- return Promise.all([
5375
- this._def.left._parseAsync({
5376
- data: ctx.data,
5377
- path: ctx.path,
5378
- parent: ctx
5379
- }),
5380
- this._def.right._parseAsync({
5381
- data: ctx.data,
5382
- path: ctx.path,
5383
- parent: ctx
5384
- })
5385
- ]).then(([left, right]) => handleParsed(left, right));
5386
- } else {
5387
- return handleParsed(this._def.left._parseSync({
5388
- data: ctx.data,
5389
- path: ctx.path,
5390
- parent: ctx
5391
- }), this._def.right._parseSync({
5392
- data: ctx.data,
5393
- path: ctx.path,
5394
- parent: ctx
5395
- }));
5396
- }
5397
- }
5398
- };
5399
- ZodIntersection.create = (left, right, params) => {
5400
- return new ZodIntersection({
5401
- left,
5402
- right,
5403
- typeName: ZodFirstPartyTypeKind.ZodIntersection,
5404
- ...processCreateParams(params)
5405
- });
5406
- };
5407
- var ZodTuple = class _ZodTuple extends ZodType {
5408
- _parse(input) {
5409
- const { status, ctx } = this._processInputParams(input);
5410
- if (ctx.parsedType !== ZodParsedType.array) {
5411
- addIssueToContext(ctx, {
5412
- code: ZodIssueCode.invalid_type,
5413
- expected: ZodParsedType.array,
5414
- received: ctx.parsedType
5415
- });
5416
- return INVALID;
5417
- }
5418
- if (ctx.data.length < this._def.items.length) {
5419
- addIssueToContext(ctx, {
5420
- code: ZodIssueCode.too_small,
5421
- minimum: this._def.items.length,
5422
- inclusive: true,
5423
- exact: false,
5424
- type: "array"
5425
- });
5426
- return INVALID;
5427
- }
5428
- const rest = this._def.rest;
5429
- if (!rest && ctx.data.length > this._def.items.length) {
5430
- addIssueToContext(ctx, {
5431
- code: ZodIssueCode.too_big,
5432
- maximum: this._def.items.length,
5433
- inclusive: true,
5434
- exact: false,
5435
- type: "array"
5436
- });
5437
- status.dirty();
5438
- }
5439
- const items = [...ctx.data].map((item, itemIndex) => {
5440
- const schema = this._def.items[itemIndex] || this._def.rest;
5441
- if (!schema)
5442
- return null;
5443
- return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
5444
- }).filter((x) => !!x);
5445
- if (ctx.common.async) {
5446
- return Promise.all(items).then((results) => {
5447
- return ParseStatus.mergeArray(status, results);
5448
- });
5449
- } else {
5450
- return ParseStatus.mergeArray(status, items);
5451
- }
5452
- }
5453
- get items() {
5454
- return this._def.items;
5455
- }
5456
- rest(rest) {
5457
- return new _ZodTuple({
5458
- ...this._def,
5459
- rest
5460
- });
5461
- }
5462
- };
5463
- ZodTuple.create = (schemas, params) => {
5464
- if (!Array.isArray(schemas)) {
5465
- throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
5466
- }
5467
- return new ZodTuple({
5468
- items: schemas,
5469
- typeName: ZodFirstPartyTypeKind.ZodTuple,
5470
- rest: null,
5471
- ...processCreateParams(params)
5472
- });
5473
- };
5474
- var ZodRecord = class _ZodRecord extends ZodType {
5475
- get keySchema() {
5476
- return this._def.keyType;
5477
- }
5478
- get valueSchema() {
5479
- return this._def.valueType;
5480
- }
5481
- _parse(input) {
5482
- const { status, ctx } = this._processInputParams(input);
5483
- if (ctx.parsedType !== ZodParsedType.object) {
5484
- addIssueToContext(ctx, {
5485
- code: ZodIssueCode.invalid_type,
5486
- expected: ZodParsedType.object,
5487
- received: ctx.parsedType
5488
- });
5489
- return INVALID;
5490
- }
5491
- const pairs = [];
5492
- const keyType = this._def.keyType;
5493
- const valueType = this._def.valueType;
5494
- for (const key in ctx.data) {
5495
- pairs.push({
5496
- key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
5497
- value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
5498
- alwaysSet: key in ctx.data
5499
- });
5500
- }
5501
- if (ctx.common.async) {
5502
- return ParseStatus.mergeObjectAsync(status, pairs);
5503
- } else {
5504
- return ParseStatus.mergeObjectSync(status, pairs);
5505
- }
5506
- }
5507
- get element() {
5508
- return this._def.valueType;
5509
- }
5510
- static create(first, second, third) {
5511
- if (second instanceof ZodType) {
5512
- return new _ZodRecord({
5513
- keyType: first,
5514
- valueType: second,
5515
- typeName: ZodFirstPartyTypeKind.ZodRecord,
5516
- ...processCreateParams(third)
5517
- });
5518
- }
5519
- return new _ZodRecord({
5520
- keyType: ZodString.create(),
5521
- valueType: first,
5522
- typeName: ZodFirstPartyTypeKind.ZodRecord,
5523
- ...processCreateParams(second)
5524
- });
5525
- }
5526
- };
5527
- var ZodMap = class extends ZodType {
5528
- get keySchema() {
5529
- return this._def.keyType;
5530
- }
5531
- get valueSchema() {
5532
- return this._def.valueType;
5533
- }
5534
- _parse(input) {
5535
- const { status, ctx } = this._processInputParams(input);
5536
- if (ctx.parsedType !== ZodParsedType.map) {
5537
- addIssueToContext(ctx, {
5538
- code: ZodIssueCode.invalid_type,
5539
- expected: ZodParsedType.map,
5540
- received: ctx.parsedType
5541
- });
5542
- return INVALID;
5543
- }
5544
- const keyType = this._def.keyType;
5545
- const valueType = this._def.valueType;
5546
- const pairs = [...ctx.data.entries()].map(([key, value], index2) => {
5547
- return {
5548
- key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index2, "key"])),
5549
- value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [index2, "value"]))
5550
- };
5551
- });
5552
- if (ctx.common.async) {
5553
- const finalMap = /* @__PURE__ */ new Map();
5554
- return Promise.resolve().then(async () => {
5555
- for (const pair of pairs) {
5556
- const key = await pair.key;
5557
- const value = await pair.value;
5558
- if (key.status === "aborted" || value.status === "aborted") {
5559
- return INVALID;
5560
- }
5561
- if (key.status === "dirty" || value.status === "dirty") {
5562
- status.dirty();
5563
- }
5564
- finalMap.set(key.value, value.value);
5565
- }
5566
- return { status: status.value, value: finalMap };
5567
- });
5568
- } else {
5569
- const finalMap = /* @__PURE__ */ new Map();
5570
- for (const pair of pairs) {
5571
- const key = pair.key;
5572
- const value = pair.value;
5573
- if (key.status === "aborted" || value.status === "aborted") {
5574
- return INVALID;
5575
- }
5576
- if (key.status === "dirty" || value.status === "dirty") {
5577
- status.dirty();
5578
- }
5579
- finalMap.set(key.value, value.value);
5580
- }
5581
- return { status: status.value, value: finalMap };
5582
- }
5583
- }
5584
- };
5585
- ZodMap.create = (keyType, valueType, params) => {
5586
- return new ZodMap({
5587
- valueType,
5588
- keyType,
5589
- typeName: ZodFirstPartyTypeKind.ZodMap,
5590
- ...processCreateParams(params)
5591
- });
5592
- };
5593
- var ZodSet = class _ZodSet extends ZodType {
5594
- _parse(input) {
5595
- const { status, ctx } = this._processInputParams(input);
5596
- if (ctx.parsedType !== ZodParsedType.set) {
5597
- addIssueToContext(ctx, {
5598
- code: ZodIssueCode.invalid_type,
5599
- expected: ZodParsedType.set,
5600
- received: ctx.parsedType
5601
- });
5602
- return INVALID;
5603
- }
5604
- const def = this._def;
5605
- if (def.minSize !== null) {
5606
- if (ctx.data.size < def.minSize.value) {
5607
- addIssueToContext(ctx, {
5608
- code: ZodIssueCode.too_small,
5609
- minimum: def.minSize.value,
5610
- type: "set",
5611
- inclusive: true,
5612
- exact: false,
5613
- message: def.minSize.message
5614
- });
5615
- status.dirty();
5616
- }
5617
- }
5618
- if (def.maxSize !== null) {
5619
- if (ctx.data.size > def.maxSize.value) {
5620
- addIssueToContext(ctx, {
5621
- code: ZodIssueCode.too_big,
5622
- maximum: def.maxSize.value,
5623
- type: "set",
5624
- inclusive: true,
5625
- exact: false,
5626
- message: def.maxSize.message
5627
- });
5628
- status.dirty();
5629
- }
5630
- }
5631
- const valueType = this._def.valueType;
5632
- function finalizeSet(elements2) {
5633
- const parsedSet = /* @__PURE__ */ new Set();
5634
- for (const element of elements2) {
5635
- if (element.status === "aborted")
5636
- return INVALID;
5637
- if (element.status === "dirty")
5638
- status.dirty();
5639
- parsedSet.add(element.value);
5640
- }
5641
- return { status: status.value, value: parsedSet };
5642
- }
5643
- const elements = [...ctx.data.values()].map((item, i3) => valueType._parse(new ParseInputLazyPath(ctx, item, ctx.path, i3)));
5644
- if (ctx.common.async) {
5645
- return Promise.all(elements).then((elements2) => finalizeSet(elements2));
5646
- } else {
5647
- return finalizeSet(elements);
5648
- }
5649
- }
5650
- min(minSize, message) {
5651
- return new _ZodSet({
5652
- ...this._def,
5653
- minSize: { value: minSize, message: errorUtil.toString(message) }
5654
- });
5655
- }
5656
- max(maxSize, message) {
5657
- return new _ZodSet({
5658
- ...this._def,
5659
- maxSize: { value: maxSize, message: errorUtil.toString(message) }
5660
- });
5661
- }
5662
- size(size5, message) {
5663
- return this.min(size5, message).max(size5, message);
5664
- }
5665
- nonempty(message) {
5666
- return this.min(1, message);
5667
- }
5668
- };
5669
- ZodSet.create = (valueType, params) => {
5670
- return new ZodSet({
5671
- valueType,
5672
- minSize: null,
5673
- maxSize: null,
5674
- typeName: ZodFirstPartyTypeKind.ZodSet,
5675
- ...processCreateParams(params)
5676
- });
5677
- };
5678
- var ZodFunction = class _ZodFunction extends ZodType {
5679
- constructor() {
5680
- super(...arguments);
5681
- this.validate = this.implement;
5682
- }
5683
- _parse(input) {
5684
- const { ctx } = this._processInputParams(input);
5685
- if (ctx.parsedType !== ZodParsedType.function) {
5686
- addIssueToContext(ctx, {
5687
- code: ZodIssueCode.invalid_type,
5688
- expected: ZodParsedType.function,
5689
- received: ctx.parsedType
5690
- });
5691
- return INVALID;
5692
- }
5693
- function makeArgsIssue(args, error) {
5694
- return makeIssue({
5695
- data: args,
5696
- path: ctx.path,
5697
- errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), en_default].filter((x) => !!x),
5698
- issueData: {
5699
- code: ZodIssueCode.invalid_arguments,
5700
- argumentsError: error
5701
- }
5702
- });
5703
- }
5704
- function makeReturnsIssue(returns, error) {
5705
- return makeIssue({
5706
- data: returns,
5707
- path: ctx.path,
5708
- errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), en_default].filter((x) => !!x),
5709
- issueData: {
5710
- code: ZodIssueCode.invalid_return_type,
5711
- returnTypeError: error
5712
- }
5713
- });
5714
- }
5715
- const params = { errorMap: ctx.common.contextualErrorMap };
5716
- const fn = ctx.data;
5717
- if (this._def.returns instanceof ZodPromise) {
5718
- const me = this;
5719
- return OK(async function(...args) {
5720
- const error = new ZodError([]);
5721
- const parsedArgs = await me._def.args.parseAsync(args, params).catch((e) => {
5722
- error.addIssue(makeArgsIssue(args, e));
5723
- throw error;
5724
- });
5725
- const result = await Reflect.apply(fn, this, parsedArgs);
5726
- const parsedReturns = await me._def.returns._def.type.parseAsync(result, params).catch((e) => {
5727
- error.addIssue(makeReturnsIssue(result, e));
5728
- throw error;
5729
- });
5730
- return parsedReturns;
5731
- });
5732
- } else {
5733
- const me = this;
5734
- return OK(function(...args) {
5735
- const parsedArgs = me._def.args.safeParse(args, params);
5736
- if (!parsedArgs.success) {
5737
- throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
5738
- }
5739
- const result = Reflect.apply(fn, this, parsedArgs.data);
5740
- const parsedReturns = me._def.returns.safeParse(result, params);
5741
- if (!parsedReturns.success) {
5742
- throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
5743
- }
5744
- return parsedReturns.data;
5745
- });
5746
- }
5747
- }
5748
- parameters() {
5749
- return this._def.args;
5750
- }
5751
- returnType() {
5752
- return this._def.returns;
5753
- }
5754
- args(...items) {
5755
- return new _ZodFunction({
5756
- ...this._def,
5757
- args: ZodTuple.create(items).rest(ZodUnknown.create())
5758
- });
5759
- }
5760
- returns(returnType) {
5761
- return new _ZodFunction({
5762
- ...this._def,
5763
- returns: returnType
5764
- });
5765
- }
5766
- implement(func) {
5767
- const validatedFunc = this.parse(func);
5768
- return validatedFunc;
5769
- }
5770
- strictImplement(func) {
5771
- const validatedFunc = this.parse(func);
5772
- return validatedFunc;
5773
- }
5774
- static create(args, returns, params) {
5775
- return new _ZodFunction({
5776
- args: args ? args : ZodTuple.create([]).rest(ZodUnknown.create()),
5777
- returns: returns || ZodUnknown.create(),
5778
- typeName: ZodFirstPartyTypeKind.ZodFunction,
5779
- ...processCreateParams(params)
5780
- });
5781
- }
5782
- };
5783
- var ZodLazy = class extends ZodType {
5784
- get schema() {
5785
- return this._def.getter();
5786
- }
5787
- _parse(input) {
5788
- const { ctx } = this._processInputParams(input);
5789
- const lazySchema = this._def.getter();
5790
- return lazySchema._parse({ data: ctx.data, path: ctx.path, parent: ctx });
5791
- }
5792
- };
5793
- ZodLazy.create = (getter, params) => {
5794
- return new ZodLazy({
5795
- getter,
5796
- typeName: ZodFirstPartyTypeKind.ZodLazy,
5797
- ...processCreateParams(params)
5798
- });
5799
- };
5800
- var ZodLiteral = class extends ZodType {
5801
- _parse(input) {
5802
- if (input.data !== this._def.value) {
5803
- const ctx = this._getOrReturnCtx(input);
5804
- addIssueToContext(ctx, {
5805
- received: ctx.data,
5806
- code: ZodIssueCode.invalid_literal,
5807
- expected: this._def.value
5808
- });
5809
- return INVALID;
5810
- }
5811
- return { status: "valid", value: input.data };
5812
- }
5813
- get value() {
5814
- return this._def.value;
5815
- }
5816
- };
5817
- ZodLiteral.create = (value, params) => {
5818
- return new ZodLiteral({
5819
- value,
5820
- typeName: ZodFirstPartyTypeKind.ZodLiteral,
5821
- ...processCreateParams(params)
5822
- });
5823
- };
5824
- function createZodEnum(values, params) {
5825
- return new ZodEnum({
5826
- values,
5827
- typeName: ZodFirstPartyTypeKind.ZodEnum,
5828
- ...processCreateParams(params)
5829
- });
5830
- }
5831
- var ZodEnum = class _ZodEnum extends ZodType {
5832
- _parse(input) {
5833
- if (typeof input.data !== "string") {
5834
- const ctx = this._getOrReturnCtx(input);
5835
- const expectedValues = this._def.values;
5836
- addIssueToContext(ctx, {
5837
- expected: util.joinValues(expectedValues),
5838
- received: ctx.parsedType,
5839
- code: ZodIssueCode.invalid_type
5840
- });
5841
- return INVALID;
5842
- }
5843
- if (!this._cache) {
5844
- this._cache = new Set(this._def.values);
5845
- }
5846
- if (!this._cache.has(input.data)) {
5847
- const ctx = this._getOrReturnCtx(input);
5848
- const expectedValues = this._def.values;
5849
- addIssueToContext(ctx, {
5850
- received: ctx.data,
5851
- code: ZodIssueCode.invalid_enum_value,
5852
- options: expectedValues
5853
- });
5854
- return INVALID;
5855
- }
5856
- return OK(input.data);
5857
- }
5858
- get options() {
5859
- return this._def.values;
5860
- }
5861
- get enum() {
5862
- const enumValues = {};
5863
- for (const val of this._def.values) {
5864
- enumValues[val] = val;
5865
- }
5866
- return enumValues;
5867
- }
5868
- get Values() {
5869
- const enumValues = {};
5870
- for (const val of this._def.values) {
5871
- enumValues[val] = val;
5872
- }
5873
- return enumValues;
5874
- }
5875
- get Enum() {
5876
- const enumValues = {};
5877
- for (const val of this._def.values) {
5878
- enumValues[val] = val;
5879
- }
5880
- return enumValues;
5881
- }
5882
- extract(values, newDef = this._def) {
5883
- return _ZodEnum.create(values, {
5884
- ...this._def,
5885
- ...newDef
5886
- });
5887
- }
5888
- exclude(values, newDef = this._def) {
5889
- return _ZodEnum.create(this.options.filter((opt) => !values.includes(opt)), {
5890
- ...this._def,
5891
- ...newDef
5892
- });
5893
- }
5894
- };
5895
- ZodEnum.create = createZodEnum;
5896
- var ZodNativeEnum = class extends ZodType {
5897
- _parse(input) {
5898
- const nativeEnumValues = util.getValidEnumValues(this._def.values);
5899
- const ctx = this._getOrReturnCtx(input);
5900
- if (ctx.parsedType !== ZodParsedType.string && ctx.parsedType !== ZodParsedType.number) {
5901
- const expectedValues = util.objectValues(nativeEnumValues);
5902
- addIssueToContext(ctx, {
5903
- expected: util.joinValues(expectedValues),
5904
- received: ctx.parsedType,
5905
- code: ZodIssueCode.invalid_type
5906
- });
5907
- return INVALID;
5908
- }
5909
- if (!this._cache) {
5910
- this._cache = new Set(util.getValidEnumValues(this._def.values));
5911
- }
5912
- if (!this._cache.has(input.data)) {
5913
- const expectedValues = util.objectValues(nativeEnumValues);
5914
- addIssueToContext(ctx, {
5915
- received: ctx.data,
5916
- code: ZodIssueCode.invalid_enum_value,
5917
- options: expectedValues
5918
- });
5919
- return INVALID;
5920
- }
5921
- return OK(input.data);
5922
- }
5923
- get enum() {
5924
- return this._def.values;
5925
- }
5926
- };
5927
- ZodNativeEnum.create = (values, params) => {
5928
- return new ZodNativeEnum({
5929
- values,
5930
- typeName: ZodFirstPartyTypeKind.ZodNativeEnum,
5931
- ...processCreateParams(params)
5932
- });
5933
- };
5934
- var ZodPromise = class extends ZodType {
5935
- unwrap() {
5936
- return this._def.type;
5937
- }
5938
- _parse(input) {
5939
- const { ctx } = this._processInputParams(input);
5940
- if (ctx.parsedType !== ZodParsedType.promise && ctx.common.async === false) {
5941
- addIssueToContext(ctx, {
5942
- code: ZodIssueCode.invalid_type,
5943
- expected: ZodParsedType.promise,
5944
- received: ctx.parsedType
5945
- });
5946
- return INVALID;
5947
- }
5948
- const promisified = ctx.parsedType === ZodParsedType.promise ? ctx.data : Promise.resolve(ctx.data);
5949
- return OK(promisified.then((data) => {
5950
- return this._def.type.parseAsync(data, {
5951
- path: ctx.path,
5952
- errorMap: ctx.common.contextualErrorMap
5953
- });
5954
- }));
5955
- }
5956
- };
5957
- ZodPromise.create = (schema, params) => {
5958
- return new ZodPromise({
5959
- type: schema,
5960
- typeName: ZodFirstPartyTypeKind.ZodPromise,
5961
- ...processCreateParams(params)
5962
- });
5963
- };
5964
- var ZodEffects = class extends ZodType {
5965
- innerType() {
5966
- return this._def.schema;
5967
- }
5968
- sourceType() {
5969
- return this._def.schema._def.typeName === ZodFirstPartyTypeKind.ZodEffects ? this._def.schema.sourceType() : this._def.schema;
5970
- }
5971
- _parse(input) {
5972
- const { status, ctx } = this._processInputParams(input);
5973
- const effect = this._def.effect || null;
5974
- const checkCtx = {
5975
- addIssue: (arg) => {
5976
- addIssueToContext(ctx, arg);
5977
- if (arg.fatal) {
5978
- status.abort();
5979
- } else {
5980
- status.dirty();
5981
- }
5982
- },
5983
- get path() {
5984
- return ctx.path;
5985
- }
5986
- };
5987
- checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
5988
- if (effect.type === "preprocess") {
5989
- const processed = effect.transform(ctx.data, checkCtx);
5990
- if (ctx.common.async) {
5991
- return Promise.resolve(processed).then(async (processed2) => {
5992
- if (status.value === "aborted")
5993
- return INVALID;
5994
- const result = await this._def.schema._parseAsync({
5995
- data: processed2,
5996
- path: ctx.path,
5997
- parent: ctx
5998
- });
5999
- if (result.status === "aborted")
6000
- return INVALID;
6001
- if (result.status === "dirty")
6002
- return DIRTY(result.value);
6003
- if (status.value === "dirty")
6004
- return DIRTY(result.value);
6005
- return result;
6006
- });
6007
- } else {
6008
- if (status.value === "aborted")
6009
- return INVALID;
6010
- const result = this._def.schema._parseSync({
6011
- data: processed,
6012
- path: ctx.path,
6013
- parent: ctx
6014
- });
6015
- if (result.status === "aborted")
6016
- return INVALID;
6017
- if (result.status === "dirty")
6018
- return DIRTY(result.value);
6019
- if (status.value === "dirty")
6020
- return DIRTY(result.value);
6021
- return result;
6022
- }
6023
- }
6024
- if (effect.type === "refinement") {
6025
- const executeRefinement = (acc) => {
6026
- const result = effect.refinement(acc, checkCtx);
6027
- if (ctx.common.async) {
6028
- return Promise.resolve(result);
6029
- }
6030
- if (result instanceof Promise) {
6031
- throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
6032
- }
6033
- return acc;
2317
+ var mlen = crypto_sign_open(tmp, signedMsg, signedMsg.length, publicKey);
2318
+ if (mlen < 0) return null;
2319
+ var m3 = new Uint8Array(mlen);
2320
+ for (var i3 = 0; i3 < m3.length; i3++) m3[i3] = tmp[i3];
2321
+ return m3;
6034
2322
  };
6035
- if (ctx.common.async === false) {
6036
- const inner = this._def.schema._parseSync({
6037
- data: ctx.data,
6038
- path: ctx.path,
6039
- parent: ctx
6040
- });
6041
- if (inner.status === "aborted")
6042
- return INVALID;
6043
- if (inner.status === "dirty")
6044
- status.dirty();
6045
- executeRefinement(inner.value);
6046
- return { status: status.value, value: inner.value };
6047
- } else {
6048
- return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((inner) => {
6049
- if (inner.status === "aborted")
6050
- return INVALID;
6051
- if (inner.status === "dirty")
6052
- status.dirty();
6053
- return executeRefinement(inner.value).then(() => {
6054
- return { status: status.value, value: inner.value };
6055
- });
6056
- });
6057
- }
6058
- }
6059
- if (effect.type === "transform") {
6060
- if (ctx.common.async === false) {
6061
- const base = this._def.schema._parseSync({
6062
- data: ctx.data,
6063
- path: ctx.path,
6064
- parent: ctx
6065
- });
6066
- if (!isValid(base))
6067
- return INVALID;
6068
- const result = effect.transform(base.value, checkCtx);
6069
- if (result instanceof Promise) {
6070
- throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
6071
- }
6072
- return { status: status.value, value: result };
6073
- } else {
6074
- return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((base) => {
6075
- if (!isValid(base))
6076
- return INVALID;
6077
- return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({
6078
- status: status.value,
6079
- value: result
6080
- }));
6081
- });
6082
- }
6083
- }
6084
- util.assertNever(effect);
6085
- }
6086
- };
6087
- ZodEffects.create = (schema, effect, params) => {
6088
- return new ZodEffects({
6089
- schema,
6090
- typeName: ZodFirstPartyTypeKind.ZodEffects,
6091
- effect,
6092
- ...processCreateParams(params)
6093
- });
6094
- };
6095
- ZodEffects.createWithPreprocess = (preprocess, schema, params) => {
6096
- return new ZodEffects({
6097
- schema,
6098
- effect: { type: "preprocess", transform: preprocess },
6099
- typeName: ZodFirstPartyTypeKind.ZodEffects,
6100
- ...processCreateParams(params)
6101
- });
6102
- };
6103
- var ZodOptional = class extends ZodType {
6104
- _parse(input) {
6105
- const parsedType = this._getType(input);
6106
- if (parsedType === ZodParsedType.undefined) {
6107
- return OK(void 0);
6108
- }
6109
- return this._def.innerType._parse(input);
6110
- }
6111
- unwrap() {
6112
- return this._def.innerType;
6113
- }
6114
- };
6115
- ZodOptional.create = (type, params) => {
6116
- return new ZodOptional({
6117
- innerType: type,
6118
- typeName: ZodFirstPartyTypeKind.ZodOptional,
6119
- ...processCreateParams(params)
6120
- });
6121
- };
6122
- var ZodNullable = class extends ZodType {
6123
- _parse(input) {
6124
- const parsedType = this._getType(input);
6125
- if (parsedType === ZodParsedType.null) {
6126
- return OK(null);
6127
- }
6128
- return this._def.innerType._parse(input);
6129
- }
6130
- unwrap() {
6131
- return this._def.innerType;
6132
- }
6133
- };
6134
- ZodNullable.create = (type, params) => {
6135
- return new ZodNullable({
6136
- innerType: type,
6137
- typeName: ZodFirstPartyTypeKind.ZodNullable,
6138
- ...processCreateParams(params)
6139
- });
6140
- };
6141
- var ZodDefault = class extends ZodType {
6142
- _parse(input) {
6143
- const { ctx } = this._processInputParams(input);
6144
- let data = ctx.data;
6145
- if (ctx.parsedType === ZodParsedType.undefined) {
6146
- data = this._def.defaultValue();
6147
- }
6148
- return this._def.innerType._parse({
6149
- data,
6150
- path: ctx.path,
6151
- parent: ctx
6152
- });
6153
- }
6154
- removeDefault() {
6155
- return this._def.innerType;
6156
- }
6157
- };
6158
- ZodDefault.create = (type, params) => {
6159
- return new ZodDefault({
6160
- innerType: type,
6161
- typeName: ZodFirstPartyTypeKind.ZodDefault,
6162
- defaultValue: typeof params.default === "function" ? params.default : () => params.default,
6163
- ...processCreateParams(params)
6164
- });
6165
- };
6166
- var ZodCatch = class extends ZodType {
6167
- _parse(input) {
6168
- const { ctx } = this._processInputParams(input);
6169
- const newCtx = {
6170
- ...ctx,
6171
- common: {
6172
- ...ctx.common,
6173
- issues: []
6174
- }
6175
- };
6176
- const result = this._def.innerType._parse({
6177
- data: newCtx.data,
6178
- path: newCtx.path,
6179
- parent: {
6180
- ...newCtx
6181
- }
6182
- });
6183
- if (isAsync(result)) {
6184
- return result.then((result2) => {
6185
- return {
6186
- status: "valid",
6187
- value: result2.status === "valid" ? result2.value : this._def.catchValue({
6188
- get error() {
6189
- return new ZodError(newCtx.common.issues);
6190
- },
6191
- input: newCtx.data
6192
- })
6193
- };
6194
- });
6195
- } else {
6196
- return {
6197
- status: "valid",
6198
- value: result.status === "valid" ? result.value : this._def.catchValue({
6199
- get error() {
6200
- return new ZodError(newCtx.common.issues);
6201
- },
6202
- input: newCtx.data
6203
- })
2323
+ nacl2.sign.detached = function(msg, secretKey) {
2324
+ var signedMsg = nacl2.sign(msg, secretKey);
2325
+ var sig = new Uint8Array(crypto_sign_BYTES);
2326
+ for (var i3 = 0; i3 < sig.length; i3++) sig[i3] = signedMsg[i3];
2327
+ return sig;
6204
2328
  };
6205
- }
6206
- }
6207
- removeCatch() {
6208
- return this._def.innerType;
6209
- }
6210
- };
6211
- ZodCatch.create = (type, params) => {
6212
- return new ZodCatch({
6213
- innerType: type,
6214
- typeName: ZodFirstPartyTypeKind.ZodCatch,
6215
- catchValue: typeof params.catch === "function" ? params.catch : () => params.catch,
6216
- ...processCreateParams(params)
6217
- });
6218
- };
6219
- var ZodNaN = class extends ZodType {
6220
- _parse(input) {
6221
- const parsedType = this._getType(input);
6222
- if (parsedType !== ZodParsedType.nan) {
6223
- const ctx = this._getOrReturnCtx(input);
6224
- addIssueToContext(ctx, {
6225
- code: ZodIssueCode.invalid_type,
6226
- expected: ZodParsedType.nan,
6227
- received: ctx.parsedType
6228
- });
6229
- return INVALID;
6230
- }
6231
- return { status: "valid", value: input.data };
6232
- }
6233
- };
6234
- ZodNaN.create = (params) => {
6235
- return new ZodNaN({
6236
- typeName: ZodFirstPartyTypeKind.ZodNaN,
6237
- ...processCreateParams(params)
6238
- });
6239
- };
6240
- var BRAND = /* @__PURE__ */ Symbol("zod_brand");
6241
- var ZodBranded = class extends ZodType {
6242
- _parse(input) {
6243
- const { ctx } = this._processInputParams(input);
6244
- const data = ctx.data;
6245
- return this._def.type._parse({
6246
- data,
6247
- path: ctx.path,
6248
- parent: ctx
6249
- });
6250
- }
6251
- unwrap() {
6252
- return this._def.type;
6253
- }
6254
- };
6255
- var ZodPipeline = class _ZodPipeline extends ZodType {
6256
- _parse(input) {
6257
- const { status, ctx } = this._processInputParams(input);
6258
- if (ctx.common.async) {
6259
- const handleAsync = async () => {
6260
- const inResult = await this._def.in._parseAsync({
6261
- data: ctx.data,
6262
- path: ctx.path,
6263
- parent: ctx
6264
- });
6265
- if (inResult.status === "aborted")
6266
- return INVALID;
6267
- if (inResult.status === "dirty") {
6268
- status.dirty();
6269
- return DIRTY(inResult.value);
6270
- } else {
6271
- return this._def.out._parseAsync({
6272
- data: inResult.value,
6273
- path: ctx.path,
6274
- parent: ctx
2329
+ nacl2.sign.detached.verify = function(msg, sig, publicKey) {
2330
+ checkArrayTypes(msg, sig, publicKey);
2331
+ if (sig.length !== crypto_sign_BYTES)
2332
+ throw new Error("bad signature size");
2333
+ if (publicKey.length !== crypto_sign_PUBLICKEYBYTES)
2334
+ throw new Error("bad public key size");
2335
+ var sm = new Uint8Array(crypto_sign_BYTES + msg.length);
2336
+ var m3 = new Uint8Array(crypto_sign_BYTES + msg.length);
2337
+ var i3;
2338
+ for (i3 = 0; i3 < crypto_sign_BYTES; i3++) sm[i3] = sig[i3];
2339
+ for (i3 = 0; i3 < msg.length; i3++) sm[i3 + crypto_sign_BYTES] = msg[i3];
2340
+ return crypto_sign_open(m3, sm, sm.length, publicKey) >= 0;
2341
+ };
2342
+ nacl2.sign.keyPair = function() {
2343
+ var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
2344
+ var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES);
2345
+ crypto_sign_keypair(pk, sk);
2346
+ return { publicKey: pk, secretKey: sk };
2347
+ };
2348
+ nacl2.sign.keyPair.fromSecretKey = function(secretKey) {
2349
+ checkArrayTypes(secretKey);
2350
+ if (secretKey.length !== crypto_sign_SECRETKEYBYTES)
2351
+ throw new Error("bad secret key size");
2352
+ var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
2353
+ for (var i3 = 0; i3 < pk.length; i3++) pk[i3] = secretKey[32 + i3];
2354
+ return { publicKey: pk, secretKey: new Uint8Array(secretKey) };
2355
+ };
2356
+ nacl2.sign.keyPair.fromSeed = function(seed) {
2357
+ checkArrayTypes(seed);
2358
+ if (seed.length !== crypto_sign_SEEDBYTES)
2359
+ throw new Error("bad seed size");
2360
+ var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
2361
+ var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES);
2362
+ for (var i3 = 0; i3 < 32; i3++) sk[i3] = seed[i3];
2363
+ crypto_sign_keypair(pk, sk, true);
2364
+ return { publicKey: pk, secretKey: sk };
2365
+ };
2366
+ nacl2.sign.publicKeyLength = crypto_sign_PUBLICKEYBYTES;
2367
+ nacl2.sign.secretKeyLength = crypto_sign_SECRETKEYBYTES;
2368
+ nacl2.sign.seedLength = crypto_sign_SEEDBYTES;
2369
+ nacl2.sign.signatureLength = crypto_sign_BYTES;
2370
+ nacl2.hash = function(msg) {
2371
+ checkArrayTypes(msg);
2372
+ var h2 = new Uint8Array(crypto_hash_BYTES);
2373
+ crypto_hash(h2, msg, msg.length);
2374
+ return h2;
2375
+ };
2376
+ nacl2.hash.hashLength = crypto_hash_BYTES;
2377
+ nacl2.verify = function(x, y) {
2378
+ checkArrayTypes(x, y);
2379
+ if (x.length === 0 || y.length === 0) return false;
2380
+ if (x.length !== y.length) return false;
2381
+ return vn(x, 0, y, 0, x.length) === 0 ? true : false;
2382
+ };
2383
+ nacl2.setPRNG = function(fn) {
2384
+ randombytes = fn;
2385
+ };
2386
+ (function() {
2387
+ var crypto = typeof self !== "undefined" ? self.crypto || self.msCrypto : null;
2388
+ if (crypto && crypto.getRandomValues) {
2389
+ var QUOTA = 65536;
2390
+ nacl2.setPRNG(function(x, n2) {
2391
+ var i3, v = new Uint8Array(n2);
2392
+ for (i3 = 0; i3 < n2; i3 += QUOTA) {
2393
+ crypto.getRandomValues(v.subarray(i3, i3 + Math.min(n2 - i3, QUOTA)));
2394
+ }
2395
+ for (i3 = 0; i3 < n2; i3++) x[i3] = v[i3];
2396
+ cleanup(v);
6275
2397
  });
2398
+ } else if (typeof __require !== "undefined") {
2399
+ crypto = __require("crypto");
2400
+ if (crypto && crypto.randomBytes) {
2401
+ nacl2.setPRNG(function(x, n2) {
2402
+ var i3, v = crypto.randomBytes(n2);
2403
+ for (i3 = 0; i3 < n2; i3++) x[i3] = v[i3];
2404
+ cleanup(v);
2405
+ });
2406
+ }
6276
2407
  }
6277
- };
6278
- return handleAsync();
6279
- } else {
6280
- const inResult = this._def.in._parseSync({
6281
- data: ctx.data,
6282
- path: ctx.path,
6283
- parent: ctx
6284
- });
6285
- if (inResult.status === "aborted")
6286
- return INVALID;
6287
- if (inResult.status === "dirty") {
6288
- status.dirty();
6289
- return {
6290
- status: "dirty",
6291
- value: inResult.value
6292
- };
6293
- } else {
6294
- return this._def.out._parseSync({
6295
- data: inResult.value,
6296
- path: ctx.path,
6297
- parent: ctx
6298
- });
6299
- }
6300
- }
6301
- }
6302
- static create(a4, b) {
6303
- return new _ZodPipeline({
6304
- in: a4,
6305
- out: b,
6306
- typeName: ZodFirstPartyTypeKind.ZodPipeline
6307
- });
6308
- }
6309
- };
6310
- var ZodReadonly = class extends ZodType {
6311
- _parse(input) {
6312
- const result = this._def.innerType._parse(input);
6313
- const freeze = (data) => {
6314
- if (isValid(data)) {
6315
- data.value = Object.freeze(data.value);
6316
- }
6317
- return data;
6318
- };
6319
- return isAsync(result) ? result.then((data) => freeze(data)) : freeze(result);
6320
- }
6321
- unwrap() {
6322
- return this._def.innerType;
2408
+ })();
2409
+ })(typeof module !== "undefined" && module.exports ? module.exports : self.nacl = self.nacl || {});
6323
2410
  }
6324
- };
6325
- ZodReadonly.create = (type, params) => {
6326
- return new ZodReadonly({
6327
- innerType: type,
6328
- typeName: ZodFirstPartyTypeKind.ZodReadonly,
6329
- ...processCreateParams(params)
6330
- });
6331
- };
6332
- function cleanParams(params, data) {
6333
- const p2 = typeof params === "function" ? params(data) : typeof params === "string" ? { message: params } : params;
6334
- const p22 = typeof p2 === "string" ? { message: p2 } : p2;
6335
- return p22;
6336
- }
6337
- function custom(check, _params = {}, fatal) {
6338
- if (check)
6339
- return ZodAny.create().superRefine((data, ctx) => {
6340
- const r2 = check(data);
6341
- if (r2 instanceof Promise) {
6342
- return r2.then((r3) => {
6343
- if (!r3) {
6344
- const params = cleanParams(_params, data);
6345
- const _fatal = params.fatal ?? fatal ?? true;
6346
- ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
6347
- }
6348
- });
6349
- }
6350
- if (!r2) {
6351
- const params = cleanParams(_params, data);
6352
- const _fatal = params.fatal ?? fatal ?? true;
6353
- ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
6354
- }
6355
- return;
6356
- });
6357
- return ZodAny.create();
6358
- }
6359
- var late = {
6360
- object: ZodObject.lazycreate
6361
- };
6362
- var ZodFirstPartyTypeKind;
6363
- (function(ZodFirstPartyTypeKind2) {
6364
- ZodFirstPartyTypeKind2["ZodString"] = "ZodString";
6365
- ZodFirstPartyTypeKind2["ZodNumber"] = "ZodNumber";
6366
- ZodFirstPartyTypeKind2["ZodNaN"] = "ZodNaN";
6367
- ZodFirstPartyTypeKind2["ZodBigInt"] = "ZodBigInt";
6368
- ZodFirstPartyTypeKind2["ZodBoolean"] = "ZodBoolean";
6369
- ZodFirstPartyTypeKind2["ZodDate"] = "ZodDate";
6370
- ZodFirstPartyTypeKind2["ZodSymbol"] = "ZodSymbol";
6371
- ZodFirstPartyTypeKind2["ZodUndefined"] = "ZodUndefined";
6372
- ZodFirstPartyTypeKind2["ZodNull"] = "ZodNull";
6373
- ZodFirstPartyTypeKind2["ZodAny"] = "ZodAny";
6374
- ZodFirstPartyTypeKind2["ZodUnknown"] = "ZodUnknown";
6375
- ZodFirstPartyTypeKind2["ZodNever"] = "ZodNever";
6376
- ZodFirstPartyTypeKind2["ZodVoid"] = "ZodVoid";
6377
- ZodFirstPartyTypeKind2["ZodArray"] = "ZodArray";
6378
- ZodFirstPartyTypeKind2["ZodObject"] = "ZodObject";
6379
- ZodFirstPartyTypeKind2["ZodUnion"] = "ZodUnion";
6380
- ZodFirstPartyTypeKind2["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion";
6381
- ZodFirstPartyTypeKind2["ZodIntersection"] = "ZodIntersection";
6382
- ZodFirstPartyTypeKind2["ZodTuple"] = "ZodTuple";
6383
- ZodFirstPartyTypeKind2["ZodRecord"] = "ZodRecord";
6384
- ZodFirstPartyTypeKind2["ZodMap"] = "ZodMap";
6385
- ZodFirstPartyTypeKind2["ZodSet"] = "ZodSet";
6386
- ZodFirstPartyTypeKind2["ZodFunction"] = "ZodFunction";
6387
- ZodFirstPartyTypeKind2["ZodLazy"] = "ZodLazy";
6388
- ZodFirstPartyTypeKind2["ZodLiteral"] = "ZodLiteral";
6389
- ZodFirstPartyTypeKind2["ZodEnum"] = "ZodEnum";
6390
- ZodFirstPartyTypeKind2["ZodEffects"] = "ZodEffects";
6391
- ZodFirstPartyTypeKind2["ZodNativeEnum"] = "ZodNativeEnum";
6392
- ZodFirstPartyTypeKind2["ZodOptional"] = "ZodOptional";
6393
- ZodFirstPartyTypeKind2["ZodNullable"] = "ZodNullable";
6394
- ZodFirstPartyTypeKind2["ZodDefault"] = "ZodDefault";
6395
- ZodFirstPartyTypeKind2["ZodCatch"] = "ZodCatch";
6396
- ZodFirstPartyTypeKind2["ZodPromise"] = "ZodPromise";
6397
- ZodFirstPartyTypeKind2["ZodBranded"] = "ZodBranded";
6398
- ZodFirstPartyTypeKind2["ZodPipeline"] = "ZodPipeline";
6399
- ZodFirstPartyTypeKind2["ZodReadonly"] = "ZodReadonly";
6400
- })(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
6401
- var instanceOfType = (cls, params = {
6402
- message: `Input not instance of ${cls.name}`
6403
- }) => custom((data) => data instanceof cls, params);
6404
- var stringType = ZodString.create;
6405
- var numberType = ZodNumber.create;
6406
- var nanType = ZodNaN.create;
6407
- var bigIntType = ZodBigInt.create;
6408
- var booleanType = ZodBoolean.create;
6409
- var dateType = ZodDate.create;
6410
- var symbolType = ZodSymbol.create;
6411
- var undefinedType = ZodUndefined.create;
6412
- var nullType = ZodNull.create;
6413
- var anyType = ZodAny.create;
6414
- var unknownType = ZodUnknown.create;
6415
- var neverType = ZodNever.create;
6416
- var voidType = ZodVoid.create;
6417
- var arrayType = ZodArray.create;
6418
- var objectType = ZodObject.create;
6419
- var strictObjectType = ZodObject.strictCreate;
6420
- var unionType = ZodUnion.create;
6421
- var discriminatedUnionType = ZodDiscriminatedUnion.create;
6422
- var intersectionType = ZodIntersection.create;
6423
- var tupleType = ZodTuple.create;
6424
- var recordType = ZodRecord.create;
6425
- var mapType = ZodMap.create;
6426
- var setType = ZodSet.create;
6427
- var functionType = ZodFunction.create;
6428
- var lazyType = ZodLazy.create;
6429
- var literalType = ZodLiteral.create;
6430
- var enumType = ZodEnum.create;
6431
- var nativeEnumType = ZodNativeEnum.create;
6432
- var promiseType = ZodPromise.create;
6433
- var effectsType = ZodEffects.create;
6434
- var optionalType = ZodOptional.create;
6435
- var nullableType = ZodNullable.create;
6436
- var preprocessType = ZodEffects.createWithPreprocess;
6437
- var pipelineType = ZodPipeline.create;
6438
- var ostring = () => stringType().optional();
6439
- var onumber = () => numberType().optional();
6440
- var oboolean = () => booleanType().optional();
6441
- var coerce = {
6442
- string: ((arg) => ZodString.create({ ...arg, coerce: true })),
6443
- number: ((arg) => ZodNumber.create({ ...arg, coerce: true })),
6444
- boolean: ((arg) => ZodBoolean.create({
6445
- ...arg,
6446
- coerce: true
6447
- })),
6448
- bigint: ((arg) => ZodBigInt.create({ ...arg, coerce: true })),
6449
- date: ((arg) => ZodDate.create({ ...arg, coerce: true }))
6450
- };
6451
- var NEVER = INVALID;
2411
+ });
6452
2412
 
6453
2413
  // node_modules/.pnpm/@x402+extensions@2.17.0_typescript@6.0.3/node_modules/@x402/extensions/dist/esm/chunk-LMLJI6VE.mjs
6454
2414
  var import_tweetnacl = __toESM(require_nacl_fast(), 1);
6455
2415
 
6456
- // node_modules/.pnpm/@x402+core@2.17.0/node_modules/@x402/core/dist/esm/chunk-ABS7D6VX.mjs
6457
- var escapeRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
6458
- var networkPatternToRegExp = (pattern) => {
6459
- const source = escapeRegExp(pattern).replace(/\\\*/g, ".*");
6460
- return new RegExp(`^${source}$`);
6461
- };
6462
- var networkMatchesPattern = (pattern, network) => {
6463
- return networkPatternToRegExp(pattern).test(network);
6464
- };
6465
- var findSchemesByNetwork = (map, network) => {
6466
- let implementationsByScheme = map.get(network);
6467
- if (!implementationsByScheme) {
6468
- for (const [registeredNetworkPattern, implementations] of map.entries()) {
6469
- if (networkMatchesPattern(registeredNetworkPattern, network)) {
6470
- implementationsByScheme = implementations;
6471
- break;
6472
- }
6473
- }
6474
- }
6475
- return implementationsByScheme;
6476
- };
6477
- var findByNetworkAndScheme = (map, scheme, network) => {
6478
- return findSchemesByNetwork(map, network)?.get(scheme);
6479
- };
6480
- var Base64EncodedRegex = /^[A-Za-z0-9+/]*={0,2}$/;
6481
- function safeBase64Encode(data) {
6482
- if (typeof globalThis !== "undefined" && typeof globalThis.btoa === "function") {
6483
- const bytes = new TextEncoder().encode(data);
6484
- const binaryString = Array.from(bytes, (byte) => String.fromCharCode(byte)).join("");
6485
- return globalThis.btoa(binaryString);
6486
- }
6487
- return Buffer.from(data, "utf8").toString("base64");
6488
- }
6489
- function safeBase64Decode(data) {
6490
- if (typeof globalThis !== "undefined" && typeof globalThis.atob === "function") {
6491
- const binaryString = globalThis.atob(data);
6492
- const bytes = new Uint8Array(binaryString.length);
6493
- for (let i3 = 0; i3 < binaryString.length; i3++) {
6494
- bytes[i3] = binaryString.charCodeAt(i3);
6495
- }
6496
- const decoder = new TextDecoder("utf-8");
6497
- return decoder.decode(bytes);
6498
- }
6499
- return Buffer.from(data, "base64").toString("utf-8");
6500
- }
6501
-
6502
2416
  // node_modules/.pnpm/viem@2.55.2_typescript@6.0.3_zod@3.25.76/node_modules/viem/_esm/utils/getAction.js
6503
2417
  function getAction(client, actionFn, name) {
6504
2418
  const action_implicit = client[actionFn.name];
@@ -8781,7 +4695,7 @@ var EnsAvatarUnsupportedNamespaceError = class extends BaseError {
8781
4695
  // node_modules/.pnpm/viem@2.55.2_typescript@6.0.3_zod@3.25.76/node_modules/viem/_esm/utils/ens/avatar/utils.js
8782
4696
  var networkRegex = /(?<protocol>https?:\/\/[^/]*|ipfs:\/|ipns:\/|ar:\/)?(?<root>\/)?(?<subpath>ipfs\/|ipns\/)?(?<target>[\w\-.]+)(?<subtarget>\/.*)?/;
8783
4697
  var ipfsHashRegex = /^(Qm[1-9A-HJ-NP-Za-km-z]{44,}|b[A-Za-z2-7]{58,}|B[A-Z2-7]{58,}|z[1-9A-HJ-NP-Za-km-z]{48,}|F[0-9A-F]{50,})(\/(?<target>[\w\-.]+))?(?<subtarget>\/.*)?$/;
8784
- var base64Regex2 = /^data:([a-zA-Z\-/+]*);base64,([^"].*)/;
4698
+ var base64Regex = /^data:([a-zA-Z\-/+]*);base64,([^"].*)/;
8785
4699
  var dataURIRegex = /^data:([a-zA-Z\-/+]*)?(;[a-zA-Z0-9].*?)?(,)/;
8786
4700
  async function isImageUri(uri) {
8787
4701
  try {
@@ -8809,15 +4723,15 @@ async function isImageUri(uri) {
8809
4723
  });
8810
4724
  }
8811
4725
  }
8812
- function getGateway(custom2, defaultGateway) {
8813
- if (!custom2)
4726
+ function getGateway(custom, defaultGateway) {
4727
+ if (!custom)
8814
4728
  return defaultGateway;
8815
- if (custom2.endsWith("/"))
8816
- return custom2.slice(0, -1);
8817
- return custom2;
4729
+ if (custom.endsWith("/"))
4730
+ return custom.slice(0, -1);
4731
+ return custom;
8818
4732
  }
8819
4733
  function resolveAvatarUri({ uri, gatewayUrls }) {
8820
- const isEncoded = base64Regex2.test(uri);
4734
+ const isEncoded = base64Regex.test(uri);
8821
4735
  if (isEncoded)
8822
4736
  return { uri, isOnChain: true, isEncoded };
8823
4737
  const ipfsGateway = getGateway(gatewayUrls?.ipfs, "https://ipfs.io");
@@ -13490,7 +9404,7 @@ async function verifySiweMessage(client, parameters) {
13490
9404
  const parsed = parseSiweMessage(message);
13491
9405
  if (!parsed.address)
13492
9406
  return false;
13493
- const isValid2 = validateSiweMessage({
9407
+ const isValid = validateSiweMessage({
13494
9408
  address,
13495
9409
  domain,
13496
9410
  message: parsed,
@@ -13498,7 +9412,7 @@ async function verifySiweMessage(client, parameters) {
13498
9412
  scheme,
13499
9413
  time
13500
9414
  });
13501
- if (!isValid2)
9415
+ if (!isValid)
13502
9416
  return false;
13503
9417
  const hash2 = hashMessage(message);
13504
9418
  return verifyHash(client, {
@@ -14142,346 +10056,8 @@ var w = class {
14142
10056
  }
14143
10057
  };
14144
10058
 
14145
- // node_modules/.pnpm/@x402+core@2.17.0/node_modules/@x402/core/dist/esm/chunk-FPXAE3OS.mjs
14146
- var NonEmptyString = external_exports.string().min(1);
14147
- var Any = external_exports.record(external_exports.unknown());
14148
- var OptionalAny = external_exports.record(external_exports.unknown()).optional().nullable();
14149
- var NetworkSchemaV1 = NonEmptyString;
14150
- var NetworkSchemaV2 = external_exports.string().min(3).refine((val) => val.includes(":"), {
14151
- message: "Network must be in CAIP-2 format (e.g., 'eip155:84532')"
14152
- });
14153
- var NetworkSchema = external_exports.union([NetworkSchemaV1, NetworkSchemaV2]);
14154
- var PRINTABLE_ASCII_REGEX = /^[\x20-\x7e]+$/;
14155
- var ResourceInfoSchema = external_exports.object({
14156
- url: NonEmptyString,
14157
- description: external_exports.string().optional(),
14158
- mimeType: external_exports.string().optional(),
14159
- serviceName: external_exports.string().min(1).max(32).regex(PRINTABLE_ASCII_REGEX).optional(),
14160
- tags: external_exports.array(external_exports.string().min(1).max(32).regex(PRINTABLE_ASCII_REGEX)).max(5).optional(),
14161
- iconUrl: external_exports.string().max(2048).optional()
14162
- });
14163
- var PaymentRequirementsV1Schema = external_exports.object({
14164
- scheme: NonEmptyString,
14165
- network: NetworkSchemaV1,
14166
- maxAmountRequired: NonEmptyString,
14167
- resource: NonEmptyString,
14168
- // URL string in V1
14169
- description: external_exports.string(),
14170
- mimeType: external_exports.string().optional(),
14171
- outputSchema: Any.optional().nullable(),
14172
- payTo: NonEmptyString,
14173
- maxTimeoutSeconds: external_exports.number().positive(),
14174
- asset: NonEmptyString,
14175
- extra: OptionalAny
14176
- });
14177
- var PaymentRequiredV1Schema = external_exports.object({
14178
- x402Version: external_exports.literal(1),
14179
- error: external_exports.string().optional(),
14180
- accepts: external_exports.array(PaymentRequirementsV1Schema).min(1)
14181
- });
14182
- var PaymentPayloadV1Schema = external_exports.object({
14183
- x402Version: external_exports.literal(1),
14184
- scheme: NonEmptyString,
14185
- network: NetworkSchemaV1,
14186
- payload: Any
14187
- });
14188
- var PaymentRequirementsV2Schema = external_exports.object({
14189
- scheme: NonEmptyString,
14190
- network: NetworkSchemaV2,
14191
- amount: NonEmptyString,
14192
- asset: NonEmptyString,
14193
- payTo: NonEmptyString,
14194
- maxTimeoutSeconds: external_exports.number().positive(),
14195
- extra: OptionalAny
14196
- });
14197
- var PaymentRequiredV2Schema = external_exports.object({
14198
- x402Version: external_exports.literal(2),
14199
- error: external_exports.string().optional(),
14200
- resource: ResourceInfoSchema,
14201
- accepts: external_exports.array(PaymentRequirementsV2Schema).min(1),
14202
- extensions: OptionalAny
14203
- });
14204
- var PaymentPayloadV2Schema = external_exports.object({
14205
- x402Version: external_exports.literal(2),
14206
- resource: ResourceInfoSchema.optional(),
14207
- accepted: PaymentRequirementsV2Schema,
14208
- payload: Any,
14209
- extensions: OptionalAny
14210
- });
14211
- var PaymentRequirementsSchema = external_exports.union([
14212
- PaymentRequirementsV1Schema,
14213
- PaymentRequirementsV2Schema
14214
- ]);
14215
- var PaymentRequiredSchema = external_exports.discriminatedUnion("x402Version", [
14216
- PaymentRequiredV1Schema,
14217
- PaymentRequiredV2Schema
14218
- ]);
14219
- var PaymentPayloadSchema = external_exports.discriminatedUnion("x402Version", [
14220
- PaymentPayloadV1Schema,
14221
- PaymentPayloadV2Schema
14222
- ]);
14223
-
14224
- // node_modules/.pnpm/@x402+core@2.17.0/node_modules/@x402/core/dist/esm/chunk-VE37GDG2.mjs
14225
- var x402Version = 2;
14226
-
14227
- // node_modules/.pnpm/@x402+core@2.17.0/node_modules/@x402/core/dist/esm/chunk-YEYZQZNL.mjs
14228
- var verifyResponseSchema = external_exports.object({
14229
- isValid: external_exports.boolean(),
14230
- invalidReason: external_exports.string().nullish().transform((v) => v ?? void 0),
14231
- invalidMessage: external_exports.string().nullish().transform((v) => v ?? void 0),
14232
- payer: external_exports.string().nullish().transform((v) => v ?? void 0),
14233
- extensions: external_exports.record(external_exports.string(), external_exports.unknown()).nullish().transform((v) => v ?? void 0),
14234
- extra: external_exports.record(external_exports.string(), external_exports.unknown()).nullish().transform((v) => v ?? void 0)
14235
- });
14236
- var settleResponseSchema = external_exports.object({
14237
- success: external_exports.boolean(),
14238
- errorReason: external_exports.string().nullish().transform((v) => v ?? void 0),
14239
- errorMessage: external_exports.string().nullish().transform((v) => v ?? void 0),
14240
- payer: external_exports.string().nullish().transform((v) => v ?? void 0),
14241
- transaction: external_exports.string(),
14242
- network: external_exports.custom((value) => typeof value === "string"),
14243
- amount: external_exports.string().nullish().transform((v) => v ?? void 0),
14244
- extensions: external_exports.record(external_exports.string(), external_exports.unknown()).nullish().transform((v) => v ?? void 0),
14245
- extra: external_exports.record(external_exports.string(), external_exports.unknown()).nullish().transform((v) => v ?? void 0)
14246
- });
14247
- var supportedKindSchema = external_exports.object({
14248
- x402Version: external_exports.number(),
14249
- scheme: external_exports.string(),
14250
- network: external_exports.custom(
14251
- (value) => typeof value === "string"
14252
- ),
14253
- extra: external_exports.record(external_exports.string(), external_exports.unknown()).nullish().transform((v) => v ?? void 0)
14254
- });
14255
- var supportedResponseSchema = external_exports.object({
14256
- kinds: external_exports.array(supportedKindSchema),
14257
- extensions: external_exports.array(external_exports.string()).default([]),
14258
- signers: external_exports.record(external_exports.string(), external_exports.array(external_exports.string())).default({})
14259
- });
14260
- var x402HTTPClient = class {
14261
- /**
14262
- * Creates a new x402HTTPClient instance.
14263
- *
14264
- * @param client - The underlying x402Client for payment logic
14265
- */
14266
- constructor(client) {
14267
- this.client = client;
14268
- this.paymentRequiredHooks = [];
14269
- }
14270
- /**
14271
- * Register a hook to handle 402 responses before payment.
14272
- * Hooks run in order; first to return headers wins.
14273
- *
14274
- * @param hook - The hook function to register
14275
- * @returns This instance for chaining
14276
- */
14277
- onPaymentRequired(hook) {
14278
- this.paymentRequiredHooks.push(hook);
14279
- return this;
14280
- }
14281
- /**
14282
- * Run hooks and return headers if any hook provides them.
14283
- *
14284
- * @param paymentRequired - The payment required response from the server
14285
- * @returns Headers to use for retry, or null to proceed to payment
14286
- */
14287
- async handlePaymentRequired(paymentRequired) {
14288
- for (const hook of this.getPaymentRequiredHooks(paymentRequired)) {
14289
- const result = await hook({ paymentRequired });
14290
- if (result?.headers) {
14291
- return result.headers;
14292
- }
14293
- }
14294
- return null;
14295
- }
14296
- /**
14297
- * Encodes a payment payload into appropriate HTTP headers based on version.
14298
- *
14299
- * @param paymentPayload - The payment payload to encode
14300
- * @returns HTTP headers containing the encoded payment signature
14301
- */
14302
- encodePaymentSignatureHeader(paymentPayload) {
14303
- switch (paymentPayload.x402Version) {
14304
- case 2:
14305
- return {
14306
- "PAYMENT-SIGNATURE": encodePaymentSignatureHeader(paymentPayload)
14307
- };
14308
- case 1:
14309
- return {
14310
- "X-PAYMENT": encodePaymentSignatureHeader(paymentPayload)
14311
- };
14312
- default:
14313
- throw new Error(
14314
- `Unsupported x402 version: ${paymentPayload.x402Version}`
14315
- );
14316
- }
14317
- }
14318
- /**
14319
- * Extracts payment required information from HTTP response.
14320
- *
14321
- * @param getHeader - Function to retrieve header value by name (case-insensitive)
14322
- * @param body - Optional response body for v1 compatibility
14323
- * @returns The payment required object
14324
- */
14325
- getPaymentRequiredResponse(getHeader, body) {
14326
- const paymentRequired = getHeader("PAYMENT-REQUIRED");
14327
- if (paymentRequired) {
14328
- return decodePaymentRequiredHeader(paymentRequired);
14329
- }
14330
- if (body && body instanceof Object && "x402Version" in body && body.x402Version === 1) {
14331
- return body;
14332
- }
14333
- throw new Error("Invalid payment required response");
14334
- }
14335
- /**
14336
- * Extracts payment settlement response from HTTP headers.
14337
- *
14338
- * @param getHeader - Function to retrieve header value by name (case-insensitive)
14339
- * @returns The settlement response object
14340
- */
14341
- getPaymentSettleResponse(getHeader) {
14342
- const paymentResponse = getHeader("PAYMENT-RESPONSE");
14343
- if (paymentResponse) {
14344
- return decodePaymentResponseHeader(paymentResponse);
14345
- }
14346
- const xPaymentResponse = getHeader("X-PAYMENT-RESPONSE");
14347
- if (xPaymentResponse) {
14348
- return decodePaymentResponseHeader(xPaymentResponse);
14349
- }
14350
- throw new Error("Payment response header not found");
14351
- }
14352
- /**
14353
- * Creates a payment payload for the given payment requirements.
14354
- * Delegates to the underlying x402Client.
14355
- *
14356
- * @param paymentRequired - The payment required response from the server
14357
- * @returns Promise resolving to the payment payload
14358
- */
14359
- async createPaymentPayload(paymentRequired) {
14360
- return this.client.createPaymentPayload(paymentRequired);
14361
- }
14362
- /**
14363
- * Parses response headers into protocol types, fires payment response hooks (v2 only),
14364
- * and returns whether a hook signaled recovery.
14365
- *
14366
- * Called by transport wrappers (fetch, axios) after the paid request completes.
14367
- *
14368
- * @param paymentPayload - The payload that was sent with the request
14369
- * @param getHeader - Function to retrieve a response header by name
14370
- * @param status - The HTTP status code of the response
14371
- * @returns Whether a hook recovered and the parsed settle response (if any)
14372
- */
14373
- async processPaymentResult(paymentPayload, getHeader, status) {
14374
- let settleResponse;
14375
- try {
14376
- settleResponse = this.getPaymentSettleResponse(getHeader);
14377
- } catch {
14378
- }
14379
- if (paymentPayload.x402Version === 1) {
14380
- return { recovered: false, settleResponse };
14381
- }
14382
- let paymentRequired;
14383
- if (!settleResponse && status === 402) {
14384
- try {
14385
- paymentRequired = this.getPaymentRequiredResponse(getHeader);
14386
- } catch {
14387
- }
14388
- }
14389
- const requirements = paymentPayload.accepted;
14390
- if (!requirements) {
14391
- throw new Error("Invalid x402 v2 payment payload: missing `accepted`");
14392
- }
14393
- const ctx = {
14394
- paymentPayload,
14395
- requirements,
14396
- ...settleResponse ? { settleResponse } : {},
14397
- ...paymentRequired ? { paymentRequired } : {}
14398
- };
14399
- const result = await this.client.handlePaymentResponse(ctx);
14400
- return { recovered: result?.recovered === true, settleResponse };
14401
- }
14402
- /**
14403
- * Parses HTTP status, headers, and body into an `HTTPResourceResponse`.
14404
- *
14405
- * Decodes the x402 payment header into `header`: the `PAYMENT-RESPONSE`
14406
- * settlement if present, otherwise the `PAYMENT-REQUIRED` declaration on
14407
- * 402 responses (whose `error` field carries the server's failure reason).
14408
- *
14409
- * @param args - Normalized response inputs from any HTTP transport
14410
- * @param args.status - HTTP response status code
14411
- * @param args.getHeader - Callback to read response headers by name
14412
- * @param args.body - Response body payload
14413
- * @returns The parsed status, body, and decoded payment header
14414
- */
14415
- parsePaymentResult(args) {
14416
- const { status, getHeader, body } = args;
14417
- let header;
14418
- try {
14419
- header = this.getPaymentSettleResponse(getHeader);
14420
- } catch {
14421
- if (status === 402) {
14422
- try {
14423
- header = this.getPaymentRequiredResponse(getHeader, body);
14424
- } catch {
14425
- }
14426
- }
14427
- }
14428
- let paymentStatus = "none";
14429
- if (header && !("success" in header)) {
14430
- paymentStatus = "payment_required";
14431
- }
14432
- if (header && "success" in header) {
14433
- paymentStatus = header.success ? "settled" : "settle_failed";
14434
- }
14435
- return { status, paymentStatus, body, header };
14436
- }
14437
- /**
14438
- * Parses a fetch Response into an `HTTPResourceResponse` for app-level convenience.
14439
- *
14440
- * @param response - The fetch Response to process
14441
- * @returns The parsed status, body, and decoded payment header
14442
- */
14443
- async processResponse(response) {
14444
- const getHeader = (name) => response.headers.get(name);
14445
- const contentType = response.headers.get("content-type") ?? "";
14446
- const body = contentType.includes("application/json") ? await response.json() : await response.text();
14447
- return this.parsePaymentResult({ status: response.status, getHeader, body });
14448
- }
14449
- /**
14450
- * Manual HTTP hooks run before extension hooks scoped to the 402 response.
14451
- *
14452
- * @param paymentRequired - The payment required response from the server
14453
- * @returns Hooks in invocation order
14454
- */
14455
- getPaymentRequiredHooks(paymentRequired) {
14456
- const hooks = [...this.paymentRequiredHooks];
14457
- const declaredExtensions = paymentRequired.extensions;
14458
- if (!declaredExtensions) return hooks;
14459
- for (const extension of this.client.getExtensions()) {
14460
- const httpExtension = extension;
14461
- const hook = httpExtension.transportHooks?.http?.onPaymentRequired;
14462
- if (!hook || !(extension.key in declaredExtensions)) continue;
14463
- hooks.push((context) => hook(declaredExtensions[extension.key], context));
14464
- }
14465
- return hooks;
14466
- }
14467
- };
14468
- function encodePaymentSignatureHeader(paymentPayload) {
14469
- return safeBase64Encode(JSON.stringify(paymentPayload));
14470
- }
14471
- function decodePaymentRequiredHeader(paymentRequiredHeader) {
14472
- if (!Base64EncodedRegex.test(paymentRequiredHeader)) {
14473
- throw new Error("Invalid payment required header");
14474
- }
14475
- return JSON.parse(safeBase64Decode(paymentRequiredHeader));
14476
- }
14477
- function decodePaymentResponseHeader(paymentResponseHeader) {
14478
- if (!Base64EncodedRegex.test(paymentResponseHeader)) {
14479
- throw new Error("Invalid payment response header");
14480
- }
14481
- return JSON.parse(safeBase64Decode(paymentResponseHeader));
14482
- }
14483
-
14484
10059
  // node_modules/.pnpm/@x402+extensions@2.17.0_typescript@6.0.3/node_modules/@x402/extensions/dist/esm/chunk-LMLJI6VE.mjs
10060
+ var SIGN_IN_WITH_X = "sign-in-with-x";
14485
10061
  var SIWxPayloadSchema = external_exports.object({
14486
10062
  domain: external_exports.string(),
14487
10063
  address: external_exports.string(),
@@ -14578,6 +10154,7 @@ function encodeSIWxHeader(payload) {
14578
10154
  }
14579
10155
 
14580
10156
  // src/lib/siwx.ts
10157
+ import { randomUUID } from "crypto";
14581
10158
  var SIWX_HEADER = "SIGN-IN-WITH-X";
14582
10159
  async function buildSiwxHeader(signer, opts) {
14583
10160
  const url = new URL(opts.baseUrl);
@@ -14606,15 +10183,10 @@ async function buildSiwxHeader(signer, opts) {
14606
10183
  }
14607
10184
 
14608
10185
  export {
14609
- findSchemesByNetwork,
14610
- findByNetworkAndScheme,
14611
10186
  createPublicClient,
14612
10187
  http,
14613
- x402Version,
14614
- x402HTTPClient,
14615
- decodePaymentRequiredHeader,
14616
- decodePaymentResponseHeader,
10188
+ SIGN_IN_WITH_X,
14617
10189
  SIWX_HEADER,
14618
10190
  buildSiwxHeader
14619
10191
  };
14620
- //# sourceMappingURL=chunk-OWVVI4VQ.js.map
10192
+ //# sourceMappingURL=chunk-KINZ23CV.js.map