@es-joy/jsoe 0.24.3 → 0.25.1

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 (524) hide show
  1. package/.claude/settings.local.json +9 -0
  2. package/.ncurc.cjs +2 -2
  3. package/CHANGES.md +51 -0
  4. package/README.md +23 -13
  5. package/badges/coverage-badge.svg +1 -1
  6. package/dist/eslint.config.d.ts +3 -0
  7. package/dist/eslint.config.d.ts.map +1 -0
  8. package/dist/formatAndTypeChoices.d.ts +28 -30
  9. package/dist/formatAndTypeChoices.d.ts.map +1 -1
  10. package/dist/formats/indexedDBKey.d.ts.map +1 -1
  11. package/dist/formats/schema.d.ts +46 -3
  12. package/dist/formats/schema.d.ts.map +1 -1
  13. package/dist/formats/structuredCloning.d.ts +3 -0
  14. package/dist/formats/structuredCloning.d.ts.map +1 -1
  15. package/dist/formats.d.ts +24 -6
  16. package/dist/formats.d.ts.map +1 -1
  17. package/dist/fundamentalTypes/BooleanObjectType.d.ts.map +1 -1
  18. package/dist/fundamentalTypes/NumberObjectType.d.ts.map +1 -1
  19. package/dist/fundamentalTypes/StringObjectType.d.ts.map +1 -1
  20. package/dist/fundamentalTypes/arrayReferenceType.d.ts.map +1 -1
  21. package/dist/fundamentalTypes/arrayType.d.ts +7 -0
  22. package/dist/fundamentalTypes/arrayType.d.ts.map +1 -1
  23. package/dist/fundamentalTypes/bigintObjectType.d.ts.map +1 -1
  24. package/dist/fundamentalTypes/bigintType.d.ts +10 -0
  25. package/dist/fundamentalTypes/bigintType.d.ts.map +1 -1
  26. package/dist/fundamentalTypes/blobType.d.ts.map +1 -1
  27. package/dist/fundamentalTypes/booleanType.d.ts.map +1 -1
  28. package/dist/fundamentalTypes/catchType.d.ts +2 -2
  29. package/dist/fundamentalTypes/catchType.d.ts.map +1 -1
  30. package/dist/fundamentalTypes/dateType.d.ts.map +1 -1
  31. package/dist/fundamentalTypes/domexceptionType.d.ts.map +1 -1
  32. package/dist/fundamentalTypes/enumType.d.ts +2 -2
  33. package/dist/fundamentalTypes/enumType.d.ts.map +1 -1
  34. package/dist/fundamentalTypes/errorType.d.ts.map +1 -1
  35. package/dist/fundamentalTypes/fileType.d.ts +6 -0
  36. package/dist/fundamentalTypes/fileType.d.ts.map +1 -1
  37. package/dist/fundamentalTypes/functionType.d.ts.map +1 -1
  38. package/dist/fundamentalTypes/literalType.d.ts +3 -2
  39. package/dist/fundamentalTypes/literalType.d.ts.map +1 -1
  40. package/dist/fundamentalTypes/looseRecordType.d.ts +6 -0
  41. package/dist/fundamentalTypes/looseRecordType.d.ts.map +1 -0
  42. package/dist/fundamentalTypes/nanType.d.ts.map +1 -1
  43. package/dist/fundamentalTypes/neverType.d.ts +2 -2
  44. package/dist/fundamentalTypes/neverType.d.ts.map +1 -1
  45. package/dist/fundamentalTypes/noneditableType.d.ts.map +1 -1
  46. package/dist/fundamentalTypes/nullType.d.ts.map +1 -1
  47. package/dist/fundamentalTypes/numberType.d.ts.map +1 -1
  48. package/dist/fundamentalTypes/promiseType.d.ts.map +1 -1
  49. package/dist/fundamentalTypes/regexpType.d.ts.map +1 -1
  50. package/dist/fundamentalTypes/stringType.d.ts.map +1 -1
  51. package/dist/fundamentalTypes/symbolType.d.ts.map +1 -1
  52. package/dist/fundamentalTypes/undefinedType.d.ts.map +1 -1
  53. package/dist/fundamentalTypes/voidType.d.ts +2 -2
  54. package/dist/fundamentalTypes/voidType.d.ts.map +1 -1
  55. package/dist/index.d.ts.map +1 -1
  56. package/dist/index.js +6 -1
  57. package/dist/index.js.map +1 -1
  58. package/dist/rollup.config.d.ts +30 -0
  59. package/dist/rollup.config.d.ts.map +1 -0
  60. package/dist/server.d.ts +2 -0
  61. package/dist/server.d.ts.map +1 -0
  62. package/dist/src/formatAndTypeChoices.d.ts +108 -0
  63. package/dist/src/formatAndTypeChoices.d.ts.map +1 -0
  64. package/dist/src/formats/arbitraryJS.d.ts +4 -0
  65. package/dist/src/formats/arbitraryJS.d.ts.map +1 -0
  66. package/dist/src/formats/indexedDBKey.d.ts +4 -0
  67. package/dist/src/formats/indexedDBKey.d.ts.map +1 -0
  68. package/dist/src/formats/json.d.ts +4 -0
  69. package/dist/src/formats/json.d.ts.map +1 -0
  70. package/dist/src/formats/schema.d.ts +17 -0
  71. package/dist/src/formats/schema.d.ts.map +1 -0
  72. package/dist/src/formats/structuredCloning.d.ts +19 -0
  73. package/dist/src/formats/structuredCloning.d.ts.map +1 -0
  74. package/dist/src/formats.d.ts +135 -0
  75. package/dist/src/formats.d.ts.map +1 -0
  76. package/dist/src/fundamentalTypes/BooleanObjectType.d.ts +8 -0
  77. package/dist/src/fundamentalTypes/BooleanObjectType.d.ts.map +1 -0
  78. package/dist/src/fundamentalTypes/NumberObjectType.d.ts +6 -0
  79. package/dist/src/fundamentalTypes/NumberObjectType.d.ts.map +1 -0
  80. package/dist/src/fundamentalTypes/StringObjectType.d.ts +6 -0
  81. package/dist/src/fundamentalTypes/StringObjectType.d.ts.map +1 -0
  82. package/dist/src/fundamentalTypes/arrayReferenceType.d.ts +8 -0
  83. package/dist/src/fundamentalTypes/arrayReferenceType.d.ts.map +1 -0
  84. package/dist/src/fundamentalTypes/arrayType.d.ts +29 -0
  85. package/dist/src/fundamentalTypes/arrayType.d.ts.map +1 -0
  86. package/dist/src/fundamentalTypes/bigintObjectType.d.ts +6 -0
  87. package/dist/src/fundamentalTypes/bigintObjectType.d.ts.map +1 -0
  88. package/dist/src/fundamentalTypes/bigintType.d.ts +6 -0
  89. package/dist/src/fundamentalTypes/bigintType.d.ts.map +1 -0
  90. package/dist/src/fundamentalTypes/blobType.d.ts +11 -0
  91. package/dist/src/fundamentalTypes/blobType.d.ts.map +1 -0
  92. package/dist/src/fundamentalTypes/booleanType.d.ts +8 -0
  93. package/dist/src/fundamentalTypes/booleanType.d.ts.map +1 -0
  94. package/dist/src/fundamentalTypes/catchType.d.ts +6 -0
  95. package/dist/src/fundamentalTypes/catchType.d.ts.map +1 -0
  96. package/dist/src/fundamentalTypes/dateType.d.ts +26 -0
  97. package/dist/src/fundamentalTypes/dateType.d.ts.map +1 -0
  98. package/dist/src/fundamentalTypes/domexceptionType.d.ts +6 -0
  99. package/dist/src/fundamentalTypes/domexceptionType.d.ts.map +1 -0
  100. package/dist/src/fundamentalTypes/enumType.d.ts +6 -0
  101. package/dist/src/fundamentalTypes/enumType.d.ts.map +1 -0
  102. package/dist/src/fundamentalTypes/errorType.d.ts +6 -0
  103. package/dist/src/fundamentalTypes/errorType.d.ts.map +1 -0
  104. package/dist/src/fundamentalTypes/fileType.d.ts +13 -0
  105. package/dist/src/fundamentalTypes/fileType.d.ts.map +1 -0
  106. package/dist/src/fundamentalTypes/filelistType.d.ts +6 -0
  107. package/dist/src/fundamentalTypes/filelistType.d.ts.map +1 -0
  108. package/dist/src/fundamentalTypes/functionType.d.ts +7 -0
  109. package/dist/src/fundamentalTypes/functionType.d.ts.map +1 -0
  110. package/dist/src/fundamentalTypes/literalType.d.ts +6 -0
  111. package/dist/src/fundamentalTypes/literalType.d.ts.map +1 -0
  112. package/dist/src/fundamentalTypes/mapType.d.ts +6 -0
  113. package/dist/src/fundamentalTypes/mapType.d.ts.map +1 -0
  114. package/dist/src/fundamentalTypes/nanType.d.ts +6 -0
  115. package/dist/src/fundamentalTypes/nanType.d.ts.map +1 -0
  116. package/dist/src/fundamentalTypes/neverType.d.ts +6 -0
  117. package/dist/src/fundamentalTypes/neverType.d.ts.map +1 -0
  118. package/dist/src/fundamentalTypes/noneditableType.d.ts +6 -0
  119. package/dist/src/fundamentalTypes/noneditableType.d.ts.map +1 -0
  120. package/dist/src/fundamentalTypes/nullType.d.ts +6 -0
  121. package/dist/src/fundamentalTypes/nullType.d.ts.map +1 -0
  122. package/dist/src/fundamentalTypes/numberType.d.ts +6 -0
  123. package/dist/src/fundamentalTypes/numberType.d.ts.map +1 -0
  124. package/dist/src/fundamentalTypes/objectReferenceType.d.ts +8 -0
  125. package/dist/src/fundamentalTypes/objectReferenceType.d.ts.map +1 -0
  126. package/dist/src/fundamentalTypes/objectType.d.ts +6 -0
  127. package/dist/src/fundamentalTypes/objectType.d.ts.map +1 -0
  128. package/dist/src/fundamentalTypes/promiseType.d.ts +6 -0
  129. package/dist/src/fundamentalTypes/promiseType.d.ts.map +1 -0
  130. package/dist/src/fundamentalTypes/recordType.d.ts +6 -0
  131. package/dist/src/fundamentalTypes/recordType.d.ts.map +1 -0
  132. package/dist/src/fundamentalTypes/regexpType.d.ts +8 -0
  133. package/dist/src/fundamentalTypes/regexpType.d.ts.map +1 -0
  134. package/dist/src/fundamentalTypes/setType.d.ts +6 -0
  135. package/dist/src/fundamentalTypes/setType.d.ts.map +1 -0
  136. package/dist/src/fundamentalTypes/sparseUndefinedType.d.ts +6 -0
  137. package/dist/src/fundamentalTypes/sparseUndefinedType.d.ts.map +1 -0
  138. package/dist/src/fundamentalTypes/stringType.d.ts +6 -0
  139. package/dist/src/fundamentalTypes/stringType.d.ts.map +1 -0
  140. package/dist/src/fundamentalTypes/symbolType.d.ts +8 -0
  141. package/dist/src/fundamentalTypes/symbolType.d.ts.map +1 -0
  142. package/dist/src/fundamentalTypes/tupleType.d.ts +6 -0
  143. package/dist/src/fundamentalTypes/tupleType.d.ts.map +1 -0
  144. package/dist/src/fundamentalTypes/undefinedType.d.ts +6 -0
  145. package/dist/src/fundamentalTypes/undefinedType.d.ts.map +1 -0
  146. package/dist/src/fundamentalTypes/voidType.d.ts +6 -0
  147. package/dist/src/fundamentalTypes/voidType.d.ts.map +1 -0
  148. package/dist/src/index.d.ts +12 -0
  149. package/dist/src/index.d.ts.map +1 -0
  150. package/dist/src/subTypes/blobHTMLType.d.ts +20 -0
  151. package/dist/src/subTypes/blobHTMLType.d.ts.map +1 -0
  152. package/dist/src/subTypes/falseType.d.ts +8 -0
  153. package/dist/src/subTypes/falseType.d.ts.map +1 -0
  154. package/dist/src/subTypes/trueType.d.ts +8 -0
  155. package/dist/src/subTypes/trueType.d.ts.map +1 -0
  156. package/dist/src/superTypes/SpecialNumberType.d.ts +6 -0
  157. package/dist/src/superTypes/SpecialNumberType.d.ts.map +1 -0
  158. package/dist/src/superTypes/SpecialRealNumberType.d.ts +6 -0
  159. package/dist/src/superTypes/SpecialRealNumberType.d.ts.map +1 -0
  160. package/dist/src/superTypes/buffersourceType.d.ts +8 -0
  161. package/dist/src/superTypes/buffersourceType.d.ts.map +1 -0
  162. package/dist/src/superTypes/dommatrixType.d.ts +6 -0
  163. package/dist/src/superTypes/dommatrixType.d.ts.map +1 -0
  164. package/dist/src/superTypes/dompointType.d.ts +6 -0
  165. package/dist/src/superTypes/dompointType.d.ts.map +1 -0
  166. package/dist/src/superTypes/domrectType.d.ts +6 -0
  167. package/dist/src/superTypes/domrectType.d.ts.map +1 -0
  168. package/dist/src/superTypes/errorsSpecialType.d.ts +8 -0
  169. package/dist/src/superTypes/errorsSpecialType.d.ts.map +1 -0
  170. package/dist/src/typeChoices.d.ts +140 -0
  171. package/dist/src/typeChoices.d.ts.map +1 -0
  172. package/dist/src/types.d.ts +758 -0
  173. package/dist/src/types.d.ts.map +1 -0
  174. package/dist/src/utils/FileList.d.ts +26 -0
  175. package/dist/src/utils/FileList.d.ts.map +1 -0
  176. package/dist/src/utils/dialogs.d.ts +111 -0
  177. package/dist/src/utils/dialogs.d.ts.map +1 -0
  178. package/dist/src/utils/jsonPointer.d.ts +46 -0
  179. package/dist/src/utils/jsonPointer.d.ts.map +1 -0
  180. package/dist/src/utils/media.d.ts +18 -0
  181. package/dist/src/utils/media.d.ts.map +1 -0
  182. package/dist/src/utils/objects.d.ts +16 -0
  183. package/dist/src/utils/objects.d.ts.map +1 -0
  184. package/dist/src/utils/templateUtils.d.ts +59 -0
  185. package/dist/src/utils/templateUtils.d.ts.map +1 -0
  186. package/dist/src/utils/types.d.ts +2 -0
  187. package/dist/src/utils/types.d.ts.map +1 -0
  188. package/dist/src/vendor-imports.d.ts +4 -0
  189. package/dist/src/vendor-imports.d.ts.map +1 -0
  190. package/dist/subTypes/blobHTMLType.d.ts.map +1 -1
  191. package/dist/superTypes/SpecialRealNumberType.d.ts.map +1 -1
  192. package/dist/superTypes/buffersourceType.d.ts.map +1 -1
  193. package/dist/superTypes/dommatrixType.d.ts.map +1 -1
  194. package/dist/superTypes/dompointType.d.ts.map +1 -1
  195. package/dist/superTypes/domrectType.d.ts.map +1 -1
  196. package/dist/superTypes/errorsSpecialType.d.ts.map +1 -1
  197. package/dist/typeChoices.d.ts +21 -87
  198. package/dist/typeChoices.d.ts.map +1 -1
  199. package/dist/types.d.ts +90 -64
  200. package/dist/types.d.ts.map +1 -1
  201. package/dist/utils/FileList.d.ts +4 -3
  202. package/dist/utils/FileList.d.ts.map +1 -1
  203. package/dist/utils/dialogs.d.ts +4 -4
  204. package/dist/utils/dialogs.d.ts.map +1 -1
  205. package/dist/utils/media.d.ts.map +1 -1
  206. package/dist/utils/schemaMeta.d.ts +92 -0
  207. package/dist/utils/schemaMeta.d.ts.map +1 -0
  208. package/dist/utils/templateUtils.d.ts +3 -3
  209. package/dist/utils/templateUtils.d.ts.map +1 -1
  210. package/dist/utils/timing.d.ts +2 -0
  211. package/dist/utils/timing.d.ts.map +1 -0
  212. package/dist/utils/types.d.ts +1 -0
  213. package/dist/utils/types.d.ts.map +1 -1
  214. package/dist/vendor-imports.d.ts +3 -1
  215. package/docs/proposals/schema-meta.md +233 -0
  216. package/eslint.config.js +51 -4
  217. package/licenseInfo.json +1 -1
  218. package/package.json +52 -42
  219. package/pnpm-workspace.yaml +57 -0
  220. package/rollup.config.js +20 -18
  221. package/server.js +3 -3
  222. package/src/deepEqual.js.map +1 -1
  223. package/src/formatAndTypeChoices.js +62 -58
  224. package/src/formats/indexedDBKey.js +3 -4
  225. package/src/formats/schema.js +824 -475
  226. package/src/formats/structuredCloning.js +189 -79
  227. package/src/formats.js +17 -5
  228. package/src/fundamentalTypes/BooleanObjectType.js +4 -5
  229. package/src/fundamentalTypes/NumberObjectType.js +4 -4
  230. package/src/fundamentalTypes/StringObjectType.js +3 -4
  231. package/src/fundamentalTypes/arrayReferenceType.js +0 -2
  232. package/src/fundamentalTypes/arrayType.js +624 -389
  233. package/src/fundamentalTypes/bigintObjectType.js +3 -2
  234. package/src/fundamentalTypes/bigintType.js +79 -17
  235. package/src/fundamentalTypes/blobType.js +35 -35
  236. package/src/fundamentalTypes/booleanType.js +16 -8
  237. package/src/fundamentalTypes/dateType.js +6 -8
  238. package/src/fundamentalTypes/domexceptionType.js +5 -4
  239. package/src/fundamentalTypes/errorType.js +39 -32
  240. package/src/fundamentalTypes/fileType.js +238 -52
  241. package/src/fundamentalTypes/functionType.js +61 -41
  242. package/src/fundamentalTypes/nanType.js +5 -4
  243. package/src/fundamentalTypes/noneditableType.js +4 -3
  244. package/src/fundamentalTypes/nullType.js +3 -2
  245. package/src/fundamentalTypes/numberType.js +72 -20
  246. package/src/fundamentalTypes/promiseType.js +16 -40
  247. package/src/fundamentalTypes/regexpType.js +7 -13
  248. package/src/fundamentalTypes/stringType.js +176 -110
  249. package/src/fundamentalTypes/symbolType.js +3 -2
  250. package/src/fundamentalTypes/undefinedType.js +3 -2
  251. package/src/index.js +6 -5
  252. package/src/jsoe.css +107 -8
  253. package/src/subTypes/blobHTMLType.js +23 -10
  254. package/src/superTypes/SpecialNumberType.js +6 -6
  255. package/src/superTypes/SpecialRealNumberType.js +10 -9
  256. package/src/superTypes/buffersourceType.js +86 -75
  257. package/src/superTypes/dommatrixType.js +6 -5
  258. package/src/superTypes/dompointType.js +6 -5
  259. package/src/superTypes/domrectType.js +6 -5
  260. package/src/superTypes/errorsSpecialType.js +54 -35
  261. package/src/typeChoices.js +399 -54
  262. package/src/types.js +157 -97
  263. package/src/utils/FileList.js +3 -3
  264. package/src/utils/dialogs.js +5 -7
  265. package/src/utils/jsonPointer.js +1 -1
  266. package/src/utils/media.js +1 -0
  267. package/src/utils/schemaMeta.js +257 -0
  268. package/src/utils/templateUtils.js +3 -3
  269. package/src/utils/timing.js +12 -0
  270. package/src/utils/types.js +19 -0
  271. package/src/vendor-imports.js +10 -2
  272. package/tsconfig.json +2 -0
  273. package/vendor/acorn/dist/acorn.d.mts +46 -5
  274. package/vendor/acorn/dist/acorn.d.ts +46 -5
  275. package/vendor/acorn/dist/acorn.js +394 -117
  276. package/vendor/acorn/dist/acorn.mjs +394 -117
  277. package/vendor/acorn/dist/bin.js +1 -1
  278. package/vendor/jamilih/dist/{jml-es.js → jml.mjs} +590 -312
  279. package/vendor/jamilih/package.json +1 -1
  280. package/vendor/mime/dist/types/other.js +719 -0
  281. package/vendor/mime/dist/types/standard.js +366 -0
  282. package/vendor/typeson-registry/dist/index.js +519 -99
  283. package/vendor/zod/classic/checks.d.ts +1 -0
  284. package/vendor/zod/classic/checks.js +1 -0
  285. package/vendor/zod/classic/coerce.d.ts +17 -0
  286. package/vendor/zod/classic/coerce.js +17 -0
  287. package/vendor/zod/classic/compat.d.ts +48 -0
  288. package/vendor/zod/classic/compat.js +31 -0
  289. package/vendor/zod/classic/deep-partial.d.ts +14 -0
  290. package/vendor/zod/classic/deep-partial.js +13 -0
  291. package/vendor/zod/classic/errors.d.ts +29 -0
  292. package/vendor/zod/classic/errors.js +57 -0
  293. package/vendor/zod/classic/external.d.ts +19 -0
  294. package/vendor/zod/classic/external.js +17 -0
  295. package/vendor/zod/classic/from-json-schema.d.ts +12 -0
  296. package/vendor/zod/classic/from-json-schema.js +660 -0
  297. package/vendor/zod/classic/in-out.d.ts +8 -0
  298. package/vendor/zod/classic/in-out.js +36 -0
  299. package/vendor/zod/classic/index.d.ts +3 -0
  300. package/vendor/zod/classic/index.js +4 -0
  301. package/vendor/zod/classic/iso.d.ts +7 -0
  302. package/vendor/zod/classic/iso.js +15 -0
  303. package/vendor/zod/classic/package.json +7 -0
  304. package/vendor/zod/classic/parse.d.ts +44 -0
  305. package/vendor/zod/classic/parse.js +16 -0
  306. package/vendor/zod/classic/schemas.d.ts +802 -0
  307. package/vendor/zod/classic/schemas.js +1491 -0
  308. package/vendor/zod/core/api.d.ts +329 -0
  309. package/vendor/zod/core/api.js +1104 -0
  310. package/vendor/zod/core/checks.d.ts +278 -0
  311. package/vendor/zod/core/checks.js +581 -0
  312. package/vendor/zod/core/compile.d.ts +51 -0
  313. package/vendor/zod/core/compile.js +1783 -0
  314. package/vendor/zod/core/core.d.ts +82 -0
  315. package/vendor/zod/core/core.js +141 -0
  316. package/vendor/zod/core/doc.d.ts +16 -0
  317. package/vendor/zod/core/doc.js +33 -0
  318. package/vendor/zod/core/errors.d.ts +225 -0
  319. package/vendor/zod/core/errors.js +270 -0
  320. package/vendor/zod/core/index.d.ts +19 -0
  321. package/vendor/zod/core/index.js +19 -0
  322. package/vendor/zod/core/json-schema-generator.d.ts +65 -0
  323. package/vendor/zod/core/json-schema-generator.js +99 -0
  324. package/vendor/zod/core/json-schema-processors.d.ts +49 -0
  325. package/vendor/zod/core/json-schema-processors.js +747 -0
  326. package/vendor/zod/core/json-schema.d.ts +89 -0
  327. package/vendor/zod/core/memoizer.d.ts +15 -0
  328. package/vendor/zod/core/memoizer.js +265 -0
  329. package/vendor/zod/core/package.json +7 -0
  330. package/vendor/zod/core/parse.d.ts +52 -0
  331. package/vendor/zod/core/parse.js +154 -0
  332. package/vendor/zod/core/regexes.d.ts +87 -0
  333. package/vendor/zod/core/regexes.js +150 -0
  334. package/vendor/zod/core/registries.d.ts +35 -0
  335. package/vendor/zod/core/registries.js +51 -0
  336. package/vendor/zod/core/schemas.d.ts +1253 -0
  337. package/vendor/zod/core/schemas.js +2440 -0
  338. package/vendor/zod/core/standard-schema.d.ts +126 -0
  339. package/vendor/zod/core/to-json-schema.d.ts +153 -0
  340. package/vendor/zod/core/to-json-schema.js +650 -0
  341. package/vendor/zod/core/util.d.ts +257 -0
  342. package/vendor/zod/core/util.js +846 -0
  343. package/vendor/zod/core/versions.d.ts +5 -0
  344. package/vendor/zod/core/versions.js +5 -0
  345. package/vendor/zod/core/visit.d.ts +30 -0
  346. package/vendor/zod/core/visit.js +169 -0
  347. package/vendor/zod/index.d.ts +3 -0
  348. package/vendor/zod/index.js +4 -0
  349. package/vendor/zod/locales/ar.d.ts +4 -0
  350. package/vendor/zod/locales/ar.js +109 -0
  351. package/vendor/zod/locales/az.d.ts +4 -0
  352. package/vendor/zod/locales/az.js +108 -0
  353. package/vendor/zod/locales/be.d.ts +4 -0
  354. package/vendor/zod/locales/be.js +166 -0
  355. package/vendor/zod/locales/bg.d.ts +4 -0
  356. package/vendor/zod/locales/bg.js +123 -0
  357. package/vendor/zod/locales/bn.d.ts +4 -0
  358. package/vendor/zod/locales/bn.js +111 -0
  359. package/vendor/zod/locales/ca.d.ts +4 -0
  360. package/vendor/zod/locales/ca.js +110 -0
  361. package/vendor/zod/locales/ckb.d.ts +4 -0
  362. package/vendor/zod/locales/ckb.js +131 -0
  363. package/vendor/zod/locales/cs.d.ts +4 -0
  364. package/vendor/zod/locales/cs.js +114 -0
  365. package/vendor/zod/locales/da.d.ts +4 -0
  366. package/vendor/zod/locales/da.js +118 -0
  367. package/vendor/zod/locales/de.d.ts +4 -0
  368. package/vendor/zod/locales/de.js +111 -0
  369. package/vendor/zod/locales/el.d.ts +4 -0
  370. package/vendor/zod/locales/el.js +110 -0
  371. package/vendor/zod/locales/en.d.ts +4 -0
  372. package/vendor/zod/locales/en.js +123 -0
  373. package/vendor/zod/locales/eo.d.ts +4 -0
  374. package/vendor/zod/locales/eo.js +112 -0
  375. package/vendor/zod/locales/es.d.ts +4 -0
  376. package/vendor/zod/locales/es.js +134 -0
  377. package/vendor/zod/locales/fa.d.ts +4 -0
  378. package/vendor/zod/locales/fa.js +117 -0
  379. package/vendor/zod/locales/fi.d.ts +4 -0
  380. package/vendor/zod/locales/fi.js +115 -0
  381. package/vendor/zod/locales/fr-CA.d.ts +4 -0
  382. package/vendor/zod/locales/fr-CA.js +110 -0
  383. package/vendor/zod/locales/fr.d.ts +4 -0
  384. package/vendor/zod/locales/fr.js +127 -0
  385. package/vendor/zod/locales/gu.d.ts +4 -0
  386. package/vendor/zod/locales/gu.js +111 -0
  387. package/vendor/zod/locales/he.d.ts +4 -0
  388. package/vendor/zod/locales/he.js +219 -0
  389. package/vendor/zod/locales/hi.d.ts +4 -0
  390. package/vendor/zod/locales/hi.js +109 -0
  391. package/vendor/zod/locales/hr.d.ts +4 -0
  392. package/vendor/zod/locales/hr.js +124 -0
  393. package/vendor/zod/locales/hu.d.ts +4 -0
  394. package/vendor/zod/locales/hu.js +111 -0
  395. package/vendor/zod/locales/hy.d.ts +4 -0
  396. package/vendor/zod/locales/hy.js +156 -0
  397. package/vendor/zod/locales/id.d.ts +4 -0
  398. package/vendor/zod/locales/id.js +109 -0
  399. package/vendor/zod/locales/index.d.ts +62 -0
  400. package/vendor/zod/locales/index.js +62 -0
  401. package/vendor/zod/locales/is.d.ts +4 -0
  402. package/vendor/zod/locales/is.js +112 -0
  403. package/vendor/zod/locales/it.d.ts +4 -0
  404. package/vendor/zod/locales/it.js +111 -0
  405. package/vendor/zod/locales/ja.d.ts +4 -0
  406. package/vendor/zod/locales/ja.js +110 -0
  407. package/vendor/zod/locales/ka.d.ts +4 -0
  408. package/vendor/zod/locales/ka.js +115 -0
  409. package/vendor/zod/locales/kh.d.ts +5 -0
  410. package/vendor/zod/locales/kh.js +5 -0
  411. package/vendor/zod/locales/km.d.ts +4 -0
  412. package/vendor/zod/locales/km.js +113 -0
  413. package/vendor/zod/locales/kn.d.ts +4 -0
  414. package/vendor/zod/locales/kn.js +114 -0
  415. package/vendor/zod/locales/ko.d.ts +4 -0
  416. package/vendor/zod/locales/ko.js +114 -0
  417. package/vendor/zod/locales/lt.d.ts +4 -0
  418. package/vendor/zod/locales/lt.js +205 -0
  419. package/vendor/zod/locales/mk.d.ts +4 -0
  420. package/vendor/zod/locales/mk.js +112 -0
  421. package/vendor/zod/locales/ms.d.ts +4 -0
  422. package/vendor/zod/locales/ms.js +110 -0
  423. package/vendor/zod/locales/ne.d.ts +4 -0
  424. package/vendor/zod/locales/ne.js +109 -0
  425. package/vendor/zod/locales/nl.d.ts +4 -0
  426. package/vendor/zod/locales/nl.js +113 -0
  427. package/vendor/zod/locales/nn.d.ts +4 -0
  428. package/vendor/zod/locales/nn.js +111 -0
  429. package/vendor/zod/locales/no.d.ts +4 -0
  430. package/vendor/zod/locales/no.js +111 -0
  431. package/vendor/zod/locales/ota.d.ts +4 -0
  432. package/vendor/zod/locales/ota.js +112 -0
  433. package/vendor/zod/locales/package.json +7 -0
  434. package/vendor/zod/locales/pl.d.ts +4 -0
  435. package/vendor/zod/locales/pl.js +112 -0
  436. package/vendor/zod/locales/ps.d.ts +4 -0
  437. package/vendor/zod/locales/ps.js +117 -0
  438. package/vendor/zod/locales/pt-BR.d.ts +4 -0
  439. package/vendor/zod/locales/pt-BR.js +141 -0
  440. package/vendor/zod/locales/pt.d.ts +4 -0
  441. package/vendor/zod/locales/pt.js +140 -0
  442. package/vendor/zod/locales/ro.d.ts +4 -0
  443. package/vendor/zod/locales/ro.js +120 -0
  444. package/vendor/zod/locales/ru.d.ts +4 -0
  445. package/vendor/zod/locales/ru.js +166 -0
  446. package/vendor/zod/locales/sk.d.ts +4 -0
  447. package/vendor/zod/locales/sk.js +114 -0
  448. package/vendor/zod/locales/sl.d.ts +4 -0
  449. package/vendor/zod/locales/sl.js +112 -0
  450. package/vendor/zod/locales/sv.d.ts +4 -0
  451. package/vendor/zod/locales/sv.js +113 -0
  452. package/vendor/zod/locales/ta.d.ts +4 -0
  453. package/vendor/zod/locales/ta.js +113 -0
  454. package/vendor/zod/locales/th.d.ts +4 -0
  455. package/vendor/zod/locales/th.js +113 -0
  456. package/vendor/zod/locales/tk.d.ts +4 -0
  457. package/vendor/zod/locales/tk.js +105 -0
  458. package/vendor/zod/locales/tr.d.ts +4 -0
  459. package/vendor/zod/locales/tr.js +108 -0
  460. package/vendor/zod/locales/ua.d.ts +5 -0
  461. package/vendor/zod/locales/ua.js +5 -0
  462. package/vendor/zod/locales/uk.d.ts +4 -0
  463. package/vendor/zod/locales/uk.js +111 -0
  464. package/vendor/zod/locales/ur.d.ts +4 -0
  465. package/vendor/zod/locales/ur.js +113 -0
  466. package/vendor/zod/locales/uz.d.ts +4 -0
  467. package/vendor/zod/locales/uz.js +111 -0
  468. package/vendor/zod/locales/vi.d.ts +4 -0
  469. package/vendor/zod/locales/vi.js +111 -0
  470. package/vendor/zod/locales/yo.d.ts +4 -0
  471. package/vendor/zod/locales/yo.js +110 -0
  472. package/vendor/zod/locales/zh-CN.d.ts +4 -0
  473. package/vendor/zod/locales/zh-CN.js +112 -0
  474. package/vendor/zod/locales/zh-TW.d.ts +4 -0
  475. package/vendor/zod/locales/zh-TW.js +110 -0
  476. package/vendor/zod/mini/checks.d.ts +1 -0
  477. package/vendor/zod/mini/checks.js +1 -0
  478. package/vendor/zod/mini/coerce.d.ts +7 -0
  479. package/vendor/zod/mini/coerce.js +22 -0
  480. package/vendor/zod/mini/deep-partial.d.ts +14 -0
  481. package/vendor/zod/mini/deep-partial.js +13 -0
  482. package/vendor/zod/mini/external.d.ts +16 -0
  483. package/vendor/zod/mini/external.js +16 -0
  484. package/vendor/zod/mini/in-out.d.ts +8 -0
  485. package/vendor/zod/mini/in-out.js +36 -0
  486. package/vendor/zod/mini/index.d.ts +3 -0
  487. package/vendor/zod/mini/index.js +3 -0
  488. package/vendor/zod/mini/iso.d.ts +22 -0
  489. package/vendor/zod/mini/iso.js +34 -0
  490. package/vendor/zod/mini/package.json +7 -0
  491. package/vendor/zod/mini/parse.d.ts +1 -0
  492. package/vendor/zod/mini/parse.js +1 -0
  493. package/vendor/zod/mini/schemas.d.ts +475 -0
  494. package/vendor/zod/mini/schemas.js +987 -0
  495. package/vendor/zod/package.json +7 -0
  496. package/vendor/zodexy/dist/esm/index.js +1274 -0
  497. package/vendor/zodexy/dist/index.js +1088 -0
  498. package/vendor/zodexy/dist/schema.zodexy.json +1036 -0
  499. package/dist/fundamentalTypes/nativeEnumType.d.ts +0 -6
  500. package/dist/fundamentalTypes/nativeEnumType.d.ts.map +0 -1
  501. package/src/fundamentalTypes/catchType.js +0 -140
  502. package/src/fundamentalTypes/enumType.js +0 -52
  503. package/src/fundamentalTypes/literalType.js +0 -81
  504. package/src/fundamentalTypes/nativeEnumType.js +0 -157
  505. package/src/fundamentalTypes/neverType.js +0 -49
  506. package/src/fundamentalTypes/recordType.js +0 -42
  507. package/src/fundamentalTypes/tupleType.js +0 -39
  508. package/src/fundamentalTypes/voidType.js +0 -48
  509. package/vendor/zod/lib/index.mjs +0 -4236
  510. package/vendor/zodex/dist/esm/dezerialize.d.ts +0 -26
  511. package/vendor/zodex/dist/esm/dezerialize.js +0 -393
  512. package/vendor/zodex/dist/esm/index.d.ts +0 -9
  513. package/vendor/zodex/dist/esm/index.js +0 -4
  514. package/vendor/zodex/dist/esm/infer.d.ts +0 -29
  515. package/vendor/zodex/dist/esm/package.json +0 -1
  516. package/vendor/zodex/dist/esm/types.d.ts +0 -201
  517. package/vendor/zodex/dist/esm/types.js +0 -13
  518. package/vendor/zodex/dist/esm/ui.d.ts +0 -23
  519. package/vendor/zodex/dist/esm/ui.js +0 -10
  520. package/vendor/zodex/dist/esm/zerialize.d.ts +0 -50
  521. package/vendor/zodex/dist/esm/zerialize.js +0 -417
  522. package/vendor/zodex/dist/esm/zod-types.d.ts +0 -11
  523. /package/vendor/{zodex/dist/esm/infer.js → zod/core/json-schema.js} +0 -0
  524. /package/vendor/{zodex/dist/esm/zod-types.js → zod/core/standard-schema.js} +0 -0
@@ -0,0 +1,2440 @@
1
+ import * as checks from "./checks.js";
2
+ import * as core from "./core.js";
3
+ import { Doc } from "./doc.js";
4
+ import { parse, parseAsync, safeParse, safeParseAsync } from "./parse.js";
5
+ import * as regexes from "./regexes.js";
6
+ import * as util from "./util.js";
7
+ import { version } from "./versions.js";
8
+ export const $ZodType = /*@__PURE__*/ core.$constructor("$ZodType", (inst, def) => {
9
+ var _a;
10
+ inst ?? (inst = {});
11
+ inst._zod.def = def; // set _def property
12
+ inst._zod.bag = inst._zod.bag || {}; // initialize _bag object
13
+ inst._zod.version = version;
14
+ const defChecks = inst._zod.def.checks;
15
+ // if inst is itself a checks.$ZodCheck, run it as a check
16
+ const checks = inst._zod.traits.has("$ZodCheck")
17
+ ? [inst, ...(defChecks ?? [])]
18
+ : defChecks?.length
19
+ ? [...defChecks]
20
+ : [];
21
+ for (const ch of checks) {
22
+ for (const fn of ch._zod.onattach) {
23
+ fn(inst);
24
+ }
25
+ }
26
+ if (checks.length === 0) {
27
+ // deferred initializer inst._zod.parse is not yet defined
28
+ (_a = inst._zod).deferred ?? (_a.deferred = []);
29
+ inst._zod.deferred?.push(() => {
30
+ inst._zod.run = inst._zod.parse;
31
+ });
32
+ }
33
+ else {
34
+ const runChecks = (payload, checks, ctx) => {
35
+ if (payload.memo)
36
+ return payload;
37
+ let isAborted = util.aborted(payload);
38
+ let asyncResult;
39
+ for (const ch of checks) {
40
+ if (ch._zod.def.when) {
41
+ if (util.explicitlyAborted(payload))
42
+ continue;
43
+ const shouldRun = ch._zod.def.when(payload);
44
+ if (!shouldRun)
45
+ continue;
46
+ }
47
+ else if (isAborted) {
48
+ continue;
49
+ }
50
+ const currLen = payload.issues.length;
51
+ const _ = ch._zod.check(payload);
52
+ if (_ instanceof Promise && ctx?.async === false) {
53
+ throw new core.$ZodAsyncError();
54
+ }
55
+ if (asyncResult || _ instanceof Promise) {
56
+ asyncResult = (asyncResult ?? Promise.resolve()).then(async () => {
57
+ await _;
58
+ const nextLen = payload.issues.length;
59
+ if (nextLen === currLen)
60
+ return;
61
+ util.attachSchema(payload.issues, currLen, inst);
62
+ if (!isAborted)
63
+ isAborted = util.aborted(payload, currLen);
64
+ });
65
+ }
66
+ else {
67
+ const nextLen = payload.issues.length;
68
+ if (nextLen === currLen)
69
+ continue;
70
+ util.attachSchema(payload.issues, currLen, inst);
71
+ if (!isAborted)
72
+ isAborted = util.aborted(payload, currLen);
73
+ }
74
+ }
75
+ if (asyncResult) {
76
+ return asyncResult.then(() => {
77
+ return payload;
78
+ });
79
+ }
80
+ return payload;
81
+ };
82
+ const handleCanaryResult = (canary, payload, ctx) => {
83
+ // abort if the canary is aborted
84
+ if (util.aborted(canary)) {
85
+ canary.aborted = true;
86
+ return canary;
87
+ }
88
+ // run checks first, then
89
+ const checkResult = runChecks(payload, checks, ctx);
90
+ if (checkResult instanceof Promise) {
91
+ if (ctx.async === false)
92
+ throw new core.$ZodAsyncError();
93
+ return checkResult.then((checkResult) => inst._zod.parse(checkResult, ctx));
94
+ }
95
+ return inst._zod.parse(checkResult, ctx);
96
+ };
97
+ inst._zod.run = (payload, ctx) => {
98
+ if (ctx.skipChecks) {
99
+ return inst._zod.parse(payload, ctx);
100
+ }
101
+ if (ctx.direction === "backward") {
102
+ // run canary initial pass (no checks)
103
+ const canary = inst._zod.parse({ value: payload.value, issues: [] }, { ...ctx, skipChecks: true });
104
+ if (canary instanceof Promise) {
105
+ return canary.then((canary) => {
106
+ return handleCanaryResult(canary, payload, ctx);
107
+ });
108
+ }
109
+ return handleCanaryResult(canary, payload, ctx);
110
+ }
111
+ // forward
112
+ const result = inst._zod.parse(payload, ctx);
113
+ if (result instanceof Promise) {
114
+ if (ctx.async === false)
115
+ throw new core.$ZodAsyncError();
116
+ return result.then((result) => runChecks(result, checks, ctx));
117
+ }
118
+ return runChecks(result, checks, ctx);
119
+ };
120
+ }
121
+ }, {
122
+ // Wrappers extend this by installing a richer factory over it; reading it eagerly would defeat the laziness.
123
+ get "~standard"() {
124
+ return util.hide(this, "~standard", standardProps(this));
125
+ },
126
+ set "~standard"(value) {
127
+ util.own(this, "~standard", value);
128
+ },
129
+ });
130
+ /** The Standard Schema surface for `inst`. Shared so wrappers can extend it without forcing it. */
131
+ const toStandardResult = (r) => r.success ? { value: r.data } : { issues: r.error?.issues };
132
+ export function standardProps(inst) {
133
+ return {
134
+ validate: (value) => {
135
+ try {
136
+ return toStandardResult(safeParse(inst, value));
137
+ }
138
+ catch (_) {
139
+ return safeParseAsync(inst, value).then(toStandardResult);
140
+ }
141
+ },
142
+ vendor: "zod",
143
+ version: 1,
144
+ };
145
+ }
146
+ export { clone } from "./util.js";
147
+ export const $ZodString = /*@__PURE__*/ core.$constructor("$ZodString", (inst, def) => {
148
+ $ZodType.init(inst, def);
149
+ inst._zod.pattern = [...(inst?._zod.bag?.patterns ?? [])].pop() ?? regexes.string(inst._zod.bag);
150
+ inst._zod.parse = (payload, _) => {
151
+ if (def.coerce)
152
+ try {
153
+ payload.value = String(payload.value);
154
+ }
155
+ catch (_) { }
156
+ if (typeof payload.value === "string")
157
+ return payload;
158
+ payload.issues.push({
159
+ expected: "string",
160
+ code: "invalid_type",
161
+ input: payload.value,
162
+ inst,
163
+ });
164
+ return payload;
165
+ };
166
+ });
167
+ export const $ZodStringFormat = /*@__PURE__*/ core.$constructor("$ZodStringFormat", (inst, def) => {
168
+ // check initialization must come first
169
+ checks.$ZodCheckStringFormat.init(inst, def);
170
+ $ZodString.init(inst, def);
171
+ });
172
+ export const $ZodGUID = /*@__PURE__*/ core.$constructor("$ZodGUID", (inst, def) => {
173
+ def.pattern ?? (def.pattern = regexes.guid);
174
+ $ZodStringFormat.init(inst, def);
175
+ });
176
+ export const $ZodUUID = /*@__PURE__*/ core.$constructor("$ZodUUID", (inst, def) => {
177
+ if (def.version) {
178
+ const versionMap = {
179
+ v1: 1,
180
+ v2: 2,
181
+ v3: 3,
182
+ v4: 4,
183
+ v5: 5,
184
+ v6: 6,
185
+ v7: 7,
186
+ v8: 8,
187
+ };
188
+ const v = versionMap[def.version];
189
+ if (v === undefined)
190
+ throw new Error(`Invalid UUID version: "${def.version}"`);
191
+ def.pattern ?? (def.pattern = regexes.uuid(v));
192
+ }
193
+ else
194
+ def.pattern ?? (def.pattern = regexes.uuid());
195
+ $ZodStringFormat.init(inst, def);
196
+ });
197
+ export const $ZodEmail = /*@__PURE__*/ core.$constructor("$ZodEmail", (inst, def) => {
198
+ def.pattern ?? (def.pattern = regexes.email);
199
+ $ZodStringFormat.init(inst, def);
200
+ });
201
+ /** The `://` guard rejected the input before the URL constructor saw it. */
202
+ export const URL_BAD_FORMAT = 1;
203
+ /** The URL constructor rejected the input. */
204
+ export const URL_UNPARSEABLE = 2;
205
+ /** Parses a URL for `$ZodURL`, applying the one guard the URL constructor cannot express. Returns the parsed URL, or a code naming the stage that rejected it — the runtime needs that distinction to pick an issue note, and compiled code only needs to know it is not a URL. */
206
+ export function parseURLObject(trimmed, def) {
207
+ // When normalize is off, require :// for http/https URLs. This prevents strings like "http:example.com" or "https:/path" from being silently accepted
208
+ if (!def.normalize && def.protocol?.source === regexes.httpProtocol.source && !/^https?:\/\//i.test(trimmed)) {
209
+ return URL_BAD_FORMAT;
210
+ }
211
+ try {
212
+ // @ts-ignore
213
+ return new URL(trimmed);
214
+ }
215
+ catch {
216
+ return URL_UNPARSEABLE;
217
+ }
218
+ }
219
+ const asciiTabOrNewline = /[\t\n\r]/g;
220
+ /** The URL parser deletes every ASCII tab, LF and CR from its input before it parses, so `new URL("https://exa\nmple.com")` reports on `example.com`. Applying the same deletion to the returned value closes the half of that divergence which can move the host; the parser's other rewrite, stripping C0 controls at the edges, cannot. */
221
+ export function stripTabAndNewline(value) {
222
+ return value.replace(asciiTabOrNewline, "");
223
+ }
224
+ export function urlHostnameOk(url, hostname) {
225
+ hostname.lastIndex = 0;
226
+ return hostname.test(url.hostname);
227
+ }
228
+ export function urlProtocolOk(url, protocol) {
229
+ protocol.lastIndex = 0;
230
+ return protocol.test(url.protocol.endsWith(":") ? url.protocol.slice(0, -1) : url.protocol);
231
+ }
232
+ export const $ZodURL = /*@__PURE__*/ core.$constructor("$ZodURL", (inst, def) => {
233
+ $ZodStringFormat.init(inst, def);
234
+ inst._zod.check = (payload) => {
235
+ try {
236
+ // Trim whitespace from input
237
+ const trimmed = payload.value.trim();
238
+ const url = parseURLObject(trimmed, def);
239
+ if (url === URL_BAD_FORMAT) {
240
+ payload.issues.push({
241
+ code: "invalid_format",
242
+ format: "url",
243
+ note: "Invalid URL format",
244
+ input: payload.value,
245
+ inst,
246
+ continue: !def.abort,
247
+ });
248
+ return;
249
+ }
250
+ if (url === URL_UNPARSEABLE) {
251
+ payload.issues.push({
252
+ code: "invalid_format",
253
+ format: "url",
254
+ input: payload.value,
255
+ inst,
256
+ continue: !def.abort,
257
+ });
258
+ return;
259
+ }
260
+ if (def.hostname && !urlHostnameOk(url, def.hostname)) {
261
+ payload.issues.push({
262
+ code: "invalid_format",
263
+ format: "url",
264
+ note: "Invalid hostname",
265
+ pattern: def.hostname.source,
266
+ input: payload.value,
267
+ inst,
268
+ continue: !def.abort,
269
+ });
270
+ }
271
+ if (def.protocol && !urlProtocolOk(url, def.protocol)) {
272
+ payload.issues.push({
273
+ code: "invalid_format",
274
+ format: "url",
275
+ note: "Invalid protocol",
276
+ pattern: def.protocol.source,
277
+ input: payload.value,
278
+ inst,
279
+ continue: !def.abort,
280
+ });
281
+ }
282
+ // Set the output value based on normalize flag
283
+ payload.value = def.normalize ? url.href : stripTabAndNewline(trimmed);
284
+ return;
285
+ }
286
+ catch (_) {
287
+ payload.issues.push({
288
+ code: "invalid_format",
289
+ format: "url",
290
+ input: payload.value,
291
+ inst,
292
+ continue: !def.abort,
293
+ });
294
+ }
295
+ };
296
+ });
297
+ export const $ZodEmoji = /*@__PURE__*/ core.$constructor("$ZodEmoji", (inst, def) => {
298
+ def.pattern ?? (def.pattern = regexes.emoji());
299
+ $ZodStringFormat.init(inst, def);
300
+ });
301
+ export const $ZodNanoID = /*@__PURE__*/ core.$constructor("$ZodNanoID", (inst, def) => {
302
+ if (def.length !== undefined && (!Number.isInteger(def.length) || def.length < 1))
303
+ throw new Error(`Invalid nanoid length: ${def.length}`);
304
+ def.pattern ?? (def.pattern = def.length === undefined ? regexes.nanoid : regexes.nanoidOfLength(def.length));
305
+ $ZodStringFormat.init(inst, def);
306
+ });
307
+ /**
308
+ * @deprecated CUID v1 is deprecated by its authors due to information leakage
309
+ * (timestamps embedded in the id). Use {@link $ZodCUID2} instead.
310
+ * See https://github.com/paralleldrive/cuid.
311
+ */
312
+ export const $ZodCUID = /*@__PURE__*/ core.$constructor("$ZodCUID", (inst, def) => {
313
+ def.pattern ?? (def.pattern = regexes.cuid);
314
+ $ZodStringFormat.init(inst, def);
315
+ });
316
+ export const $ZodCUID2 = /*@__PURE__*/ core.$constructor("$ZodCUID2", (inst, def) => {
317
+ def.pattern ?? (def.pattern = regexes.cuid2);
318
+ $ZodStringFormat.init(inst, def);
319
+ });
320
+ export const $ZodULID = /*@__PURE__*/ core.$constructor("$ZodULID", (inst, def) => {
321
+ def.pattern ?? (def.pattern = regexes.ulid);
322
+ $ZodStringFormat.init(inst, def);
323
+ });
324
+ export const $ZodXID = /*@__PURE__*/ core.$constructor("$ZodXID", (inst, def) => {
325
+ def.pattern ?? (def.pattern = regexes.xid);
326
+ $ZodStringFormat.init(inst, def);
327
+ });
328
+ export const $ZodKSUID = /*@__PURE__*/ core.$constructor("$ZodKSUID", (inst, def) => {
329
+ def.pattern ?? (def.pattern = regexes.ksuid);
330
+ $ZodStringFormat.init(inst, def);
331
+ });
332
+ export const $ZodISODateTime = /*@__PURE__*/ core.$constructor("$ZodISODateTime", (inst, def) => {
333
+ def.pattern ?? (def.pattern = regexes.datetime(def));
334
+ $ZodStringFormat.init(inst, def);
335
+ // these two drop the offset or seconds `date-time` requires — on the bag not the def, since `z.string().check(...)` lands the format on a different schema
336
+ if (def.local || def.precision === -1) {
337
+ inst._zod.bag.laxFormat = true;
338
+ inst._zod.onattach.push((s) => {
339
+ s._zod.bag.laxFormat = true;
340
+ });
341
+ }
342
+ });
343
+ export const $ZodISODate = /*@__PURE__*/ core.$constructor("$ZodISODate", (inst, def) => {
344
+ def.pattern ?? (def.pattern = regexes.date);
345
+ $ZodStringFormat.init(inst, def);
346
+ });
347
+ export const $ZodISOTime = /*@__PURE__*/ core.$constructor("$ZodISOTime", (inst, def) => {
348
+ def.pattern ?? (def.pattern = regexes.time(def));
349
+ $ZodStringFormat.init(inst, def);
350
+ });
351
+ export const $ZodISODuration = /*@__PURE__*/ core.$constructor("$ZodISODuration", (inst, def) => {
352
+ def.pattern ?? (def.pattern = regexes.duration);
353
+ $ZodStringFormat.init(inst, def);
354
+ });
355
+ export const $ZodIPv4 = /*@__PURE__*/ core.$constructor("$ZodIPv4", (inst, def) => {
356
+ def.pattern ?? (def.pattern = regexes.ipv4);
357
+ $ZodStringFormat.init(inst, def);
358
+ inst._zod.bag.format = `ipv4`;
359
+ });
360
+ /** An IPv6 address is written with hex digits, colons and dots, and nothing else. The guard is what makes the check below an IPv6 check: `new URL("http://[...]")` parses an authority, not an address, so `@` and `\` re-delimit it and `"::@1\\"` validates against the host `0.0.0.1`. The URL parser also deletes ASCII tab, LF and CR rather than failing, which is how `"::1\n"` validated as `::1`. */
361
+ const ipv6Alphabet = /^[0-9a-fA-F:.]+$/;
362
+ export function isValidIPv6(value) {
363
+ if (!ipv6Alphabet.test(value))
364
+ return false;
365
+ try {
366
+ // @ts-ignore
367
+ new URL(`http://[${value}]`);
368
+ return true;
369
+ }
370
+ catch {
371
+ return false;
372
+ }
373
+ }
374
+ export const $ZodIPv6 = /*@__PURE__*/ core.$constructor("$ZodIPv6", (inst, def) => {
375
+ def.pattern ?? (def.pattern = regexes.ipv6);
376
+ $ZodStringFormat.init(inst, def);
377
+ inst._zod.bag.format = `ipv6`;
378
+ inst._zod.check = (payload) => {
379
+ if (!isValidIPv6(payload.value)) {
380
+ payload.issues.push({
381
+ code: "invalid_format",
382
+ format: "ipv6",
383
+ input: payload.value,
384
+ inst,
385
+ continue: !def.abort,
386
+ });
387
+ }
388
+ };
389
+ });
390
+ export const $ZodMAC = /*@__PURE__*/ core.$constructor("$ZodMAC", (inst, def) => {
391
+ def.pattern ?? (def.pattern = regexes.mac(def.delimiter));
392
+ $ZodStringFormat.init(inst, def);
393
+ inst._zod.bag.format = `mac`;
394
+ });
395
+ export const $ZodCIDRv4 = /*@__PURE__*/ core.$constructor("$ZodCIDRv4", (inst, def) => {
396
+ def.pattern ?? (def.pattern = regexes.cidrv4);
397
+ $ZodStringFormat.init(inst, def);
398
+ });
399
+ export function isValidCIDRv6(value) {
400
+ const parts = value.split("/");
401
+ if (parts.length !== 2)
402
+ return false;
403
+ const [address, prefix] = parts;
404
+ if (!prefix)
405
+ return false;
406
+ const prefixNum = Number(prefix);
407
+ if (`${prefixNum}` !== prefix)
408
+ return false;
409
+ if (prefixNum < 0 || prefixNum > 128)
410
+ return false;
411
+ return isValidIPv6(address);
412
+ }
413
+ export const $ZodCIDRv6 = /*@__PURE__*/ core.$constructor("$ZodCIDRv6", (inst, def) => {
414
+ def.pattern ?? (def.pattern = regexes.cidrv6); // not used for validation
415
+ $ZodStringFormat.init(inst, def);
416
+ inst._zod.check = (payload) => {
417
+ if (!isValidCIDRv6(payload.value)) {
418
+ payload.issues.push({
419
+ code: "invalid_format",
420
+ format: "cidrv6",
421
+ input: payload.value,
422
+ inst,
423
+ continue: !def.abort,
424
+ });
425
+ }
426
+ };
427
+ });
428
+ ////////////////////////////// ZodBase64 //////////////////////////////
429
+ export function isValidBase64(data) {
430
+ if (data === "")
431
+ return true;
432
+ // atob ignores whitespace, so reject it up front.
433
+ if (/\s/.test(data))
434
+ return false;
435
+ if (data.length % 4 !== 0)
436
+ return false;
437
+ try {
438
+ // @ts-ignore
439
+ atob(data);
440
+ return true;
441
+ }
442
+ catch {
443
+ return false;
444
+ }
445
+ }
446
+ export const $ZodBase64 = /*@__PURE__*/ core.$constructor("$ZodBase64", (inst, def) => {
447
+ def.pattern ?? (def.pattern = regexes.base64);
448
+ $ZodStringFormat.init(inst, def);
449
+ inst._zod.bag.contentEncoding = "base64";
450
+ inst._zod.check = (payload) => {
451
+ if (isValidBase64(payload.value))
452
+ return;
453
+ payload.issues.push({
454
+ code: "invalid_format",
455
+ format: "base64",
456
+ input: payload.value,
457
+ inst,
458
+ continue: !def.abort,
459
+ });
460
+ };
461
+ });
462
+ ////////////////////////////// ZodBase64 //////////////////////////////
463
+ export function isValidBase64URL(data) {
464
+ if (!regexes.base64url.test(data))
465
+ return false;
466
+ const base64 = data.replace(/[-_]/g, (c) => (c === "-" ? "+" : "/"));
467
+ const padded = base64.padEnd(Math.ceil(base64.length / 4) * 4, "=");
468
+ return isValidBase64(padded);
469
+ }
470
+ export const $ZodBase64URL = /*@__PURE__*/ core.$constructor("$ZodBase64URL", (inst, def) => {
471
+ def.pattern ?? (def.pattern = regexes.base64url);
472
+ $ZodStringFormat.init(inst, def);
473
+ inst._zod.bag.contentEncoding = "base64url";
474
+ inst._zod.check = (payload) => {
475
+ if (isValidBase64URL(payload.value))
476
+ return;
477
+ payload.issues.push({
478
+ code: "invalid_format",
479
+ format: "base64url",
480
+ input: payload.value,
481
+ inst,
482
+ continue: !def.abort,
483
+ });
484
+ };
485
+ });
486
+ export const $ZodE164 = /*@__PURE__*/ core.$constructor("$ZodE164", (inst, def) => {
487
+ def.pattern ?? (def.pattern = regexes.e164);
488
+ $ZodStringFormat.init(inst, def);
489
+ });
490
+ ////////////////////////////// ZodCreditCard //////////////////////////////
491
+ const CC_SANITIZE = /[- ]/g;
492
+ /** Luhn checksum on a digit-only string. Adapted from valibot (MIT). */
493
+ function isLuhnAlgo(digits) {
494
+ let length = digits.length;
495
+ let bit = 1;
496
+ let sum = 0;
497
+ while (length) {
498
+ const value = +digits[--length];
499
+ bit ^= 1;
500
+ sum += bit ? [0, 2, 4, 6, 8, 1, 3, 5, 7, 9][value] : value;
501
+ }
502
+ return sum % 10 === 0;
503
+ }
504
+ export function isValidCreditCard(input) {
505
+ if (!regexes.creditCard.test(input))
506
+ return false;
507
+ return isLuhnAlgo(input.replace(CC_SANITIZE, ""));
508
+ }
509
+ export const $ZodCreditCard = /*@__PURE__*/ core.$constructor("$ZodCreditCard", (inst, def) => {
510
+ // Shape only — the Luhn check below is not expressible as a pattern, so consumers of `pattern` (JSON Schema, template literals) get the length and separator rules alone.
511
+ def.pattern ?? (def.pattern = regexes.creditCard);
512
+ $ZodStringFormat.init(inst, def);
513
+ inst._zod.check = (payload) => {
514
+ if (isValidCreditCard(payload.value))
515
+ return;
516
+ payload.issues.push({
517
+ code: "invalid_format",
518
+ format: "credit_card",
519
+ input: payload.value,
520
+ inst,
521
+ continue: !def.abort,
522
+ });
523
+ };
524
+ });
525
+ ////////////////////////////// ZodJWT //////////////////////////////
526
+ export function isValidJWT(token, algorithm = null) {
527
+ try {
528
+ const tokensParts = token.split(".");
529
+ if (tokensParts.length !== 3)
530
+ return false;
531
+ const [header] = tokensParts;
532
+ if (!header)
533
+ return false;
534
+ // @ts-ignore
535
+ const parsedHeader = JSON.parse(atob(header));
536
+ if ("typ" in parsedHeader && parsedHeader?.typ !== "JWT")
537
+ return false;
538
+ if (!parsedHeader.alg)
539
+ return false;
540
+ if (algorithm && (!("alg" in parsedHeader) || parsedHeader.alg !== algorithm))
541
+ return false;
542
+ return true;
543
+ }
544
+ catch {
545
+ return false;
546
+ }
547
+ }
548
+ export const $ZodJWT = /*@__PURE__*/ core.$constructor("$ZodJWT", (inst, def) => {
549
+ $ZodStringFormat.init(inst, def);
550
+ inst._zod.check = (payload) => {
551
+ if (isValidJWT(payload.value, def.alg))
552
+ return;
553
+ payload.issues.push({
554
+ code: "invalid_format",
555
+ format: "jwt",
556
+ input: payload.value,
557
+ inst,
558
+ continue: !def.abort,
559
+ });
560
+ };
561
+ });
562
+ export const $ZodCustomStringFormat = /*@__PURE__*/ core.$constructor("$ZodCustomStringFormat", (inst, def) => {
563
+ $ZodStringFormat.init(inst, def);
564
+ inst._zod.check = (payload) => {
565
+ if (def.fn(payload.value))
566
+ return;
567
+ payload.issues.push({
568
+ code: "invalid_format",
569
+ format: def.format,
570
+ input: payload.value,
571
+ inst,
572
+ continue: !def.abort,
573
+ });
574
+ };
575
+ });
576
+ export const $ZodNumber = /*@__PURE__*/ core.$constructor("$ZodNumber", (inst, def) => {
577
+ $ZodType.init(inst, def);
578
+ inst._zod.pattern = inst._zod.bag.pattern ?? regexes.number;
579
+ inst._zod.parse = (payload, _ctx) => {
580
+ if (def.coerce)
581
+ try {
582
+ payload.value = Number(payload.value);
583
+ }
584
+ catch (_) { }
585
+ const input = payload.value;
586
+ if (typeof input === "number" && !Number.isNaN(input) && Number.isFinite(input)) {
587
+ return payload;
588
+ }
589
+ const received = typeof input === "number"
590
+ ? Number.isNaN(input)
591
+ ? "NaN"
592
+ : !Number.isFinite(input)
593
+ ? String(input)
594
+ : undefined
595
+ : undefined;
596
+ payload.issues.push({
597
+ expected: "number",
598
+ code: "invalid_type",
599
+ input,
600
+ inst,
601
+ ...(received ? { received } : {}),
602
+ });
603
+ return payload;
604
+ };
605
+ });
606
+ export const $ZodNumberFormat = /*@__PURE__*/ core.$constructor("$ZodNumberFormat", (inst, def) => {
607
+ checks.$ZodCheckNumberFormat.init(inst, def);
608
+ $ZodNumber.init(inst, def); // no format checks
609
+ });
610
+ export const $ZodBoolean = /*@__PURE__*/ core.$constructor("$ZodBoolean", (inst, def) => {
611
+ $ZodType.init(inst, def);
612
+ inst._zod.pattern = regexes.boolean;
613
+ inst._zod.parse = (payload, _ctx) => {
614
+ if (def.coerce)
615
+ try {
616
+ payload.value = Boolean(payload.value);
617
+ }
618
+ catch (_) { }
619
+ const input = payload.value;
620
+ if (typeof input === "boolean")
621
+ return payload;
622
+ payload.issues.push({
623
+ expected: "boolean",
624
+ code: "invalid_type",
625
+ input,
626
+ inst,
627
+ });
628
+ return payload;
629
+ };
630
+ });
631
+ export const $ZodBigInt = /*@__PURE__*/ core.$constructor("$ZodBigInt", (inst, def) => {
632
+ $ZodType.init(inst, def);
633
+ inst._zod.pattern = regexes.bigint;
634
+ inst._zod.parse = (payload, _ctx) => {
635
+ if (def.coerce)
636
+ try {
637
+ payload.value = BigInt(payload.value);
638
+ }
639
+ catch (_) { }
640
+ if (typeof payload.value === "bigint")
641
+ return payload;
642
+ payload.issues.push({
643
+ expected: "bigint",
644
+ code: "invalid_type",
645
+ input: payload.value,
646
+ inst,
647
+ });
648
+ return payload;
649
+ };
650
+ });
651
+ export const $ZodBigIntFormat = /*@__PURE__*/ core.$constructor("$ZodBigIntFormat", (inst, def) => {
652
+ checks.$ZodCheckBigIntFormat.init(inst, def);
653
+ $ZodBigInt.init(inst, def); // no format checks
654
+ });
655
+ export const $ZodSymbol = /*@__PURE__*/ core.$constructor("$ZodSymbol", (inst, def) => {
656
+ $ZodType.init(inst, def);
657
+ inst._zod.parse = (payload, _ctx) => {
658
+ const input = payload.value;
659
+ if (typeof input === "symbol")
660
+ return payload;
661
+ payload.issues.push({
662
+ expected: "symbol",
663
+ code: "invalid_type",
664
+ input,
665
+ inst,
666
+ });
667
+ return payload;
668
+ };
669
+ });
670
+ export const $ZodUndefined = /*@__PURE__*/ core.$constructor("$ZodUndefined", (inst, def) => {
671
+ $ZodType.init(inst, def);
672
+ inst._zod.pattern = regexes.undefined;
673
+ inst._zod.values = new Set([undefined]);
674
+ inst._zod.parse = (payload, _ctx) => {
675
+ const input = payload.value;
676
+ if (typeof input === "undefined")
677
+ return payload;
678
+ payload.issues.push({
679
+ expected: "undefined",
680
+ code: "invalid_type",
681
+ input,
682
+ inst,
683
+ });
684
+ return payload;
685
+ };
686
+ });
687
+ export const $ZodNull = /*@__PURE__*/ core.$constructor("$ZodNull", (inst, def) => {
688
+ $ZodType.init(inst, def);
689
+ inst._zod.pattern = regexes.null;
690
+ inst._zod.values = new Set([null]);
691
+ inst._zod.parse = (payload, _ctx) => {
692
+ const input = payload.value;
693
+ if (input === null)
694
+ return payload;
695
+ payload.issues.push({
696
+ expected: "null",
697
+ code: "invalid_type",
698
+ input,
699
+ inst,
700
+ });
701
+ return payload;
702
+ };
703
+ });
704
+ export const $ZodAny = /*@__PURE__*/ core.$constructor("$ZodAny", (inst, def) => {
705
+ $ZodType.init(inst, def);
706
+ inst._zod.parse = (payload) => payload;
707
+ });
708
+ export const $ZodUnknown = /*@__PURE__*/ core.$constructor("$ZodUnknown", (inst, def) => {
709
+ $ZodType.init(inst, def);
710
+ inst._zod.parse = (payload) => payload;
711
+ });
712
+ export const $ZodNever = /*@__PURE__*/ core.$constructor("$ZodNever", (inst, def) => {
713
+ $ZodType.init(inst, def);
714
+ inst._zod.parse = (payload, _ctx) => {
715
+ payload.issues.push({
716
+ expected: "never",
717
+ code: "invalid_type",
718
+ input: payload.value,
719
+ inst,
720
+ });
721
+ return payload;
722
+ };
723
+ });
724
+ export const $ZodVoid = /*@__PURE__*/ core.$constructor("$ZodVoid", (inst, def) => {
725
+ $ZodType.init(inst, def);
726
+ inst._zod.parse = (payload, _ctx) => {
727
+ const input = payload.value;
728
+ if (typeof input === "undefined")
729
+ return payload;
730
+ payload.issues.push({
731
+ expected: "void",
732
+ code: "invalid_type",
733
+ input,
734
+ inst,
735
+ });
736
+ return payload;
737
+ };
738
+ });
739
+ export const $ZodDate = /*@__PURE__*/ core.$constructor("$ZodDate", (inst, def) => {
740
+ $ZodType.init(inst, def);
741
+ inst._zod.parse = (payload, _ctx) => {
742
+ if (def.coerce) {
743
+ try {
744
+ payload.value = new Date(payload.value);
745
+ }
746
+ catch (_err) { }
747
+ }
748
+ const input = payload.value;
749
+ const isDate = input instanceof Date;
750
+ const isValidDate = isDate && !Number.isNaN(input.getTime());
751
+ if (isValidDate)
752
+ return payload;
753
+ payload.issues.push({
754
+ expected: "date",
755
+ code: "invalid_type",
756
+ input,
757
+ ...(isDate ? { received: "Invalid Date" } : {}),
758
+ inst,
759
+ });
760
+ return payload;
761
+ };
762
+ });
763
+ function handleArrayResult(result, final, index) {
764
+ if (result.issues.length) {
765
+ final.issues.push(...util.prefixIssues(index, result.issues));
766
+ }
767
+ final.value[index] = result.value;
768
+ }
769
+ export const $ZodArray = /*@__PURE__*/ core.$constructor("$ZodArray", (inst, def) => {
770
+ $ZodType.init(inst, def);
771
+ const memo = core.globalConfig.memoizer;
772
+ memo?.attach(inst);
773
+ inst._zod.parse = (payload, ctx) => {
774
+ const input = payload.value;
775
+ if (!Array.isArray(input)) {
776
+ payload.issues.push({
777
+ expected: "array",
778
+ code: "invalid_type",
779
+ input,
780
+ inst,
781
+ });
782
+ return payload;
783
+ }
784
+ payload.value = memo ? memo.alloc(inst, payload, Array(input.length), ctx) : Array(input.length);
785
+ const proms = [];
786
+ for (let i = 0; i < input.length; i++) {
787
+ const item = input[i];
788
+ const result = def.element._zod.run({
789
+ value: item,
790
+ issues: [],
791
+ }, ctx);
792
+ if (result instanceof Promise) {
793
+ proms.push(result.then((result) => handleArrayResult(result, payload, i)));
794
+ }
795
+ else {
796
+ handleArrayResult(result, payload, i);
797
+ }
798
+ }
799
+ if (proms.length) {
800
+ return Promise.all(proms).then(() => payload);
801
+ }
802
+ return payload; //handleArrayResultsAsync(parseResults, final);
803
+ };
804
+ });
805
+ function handlePropertyResult(result, final, key, input, optin, optout) {
806
+ const isPresent = key in input;
807
+ const isOptionalOut = optout === "optional";
808
+ // The middle rung means "absence permitted, nothing supplied in its place", so an absent key contributes nothing — whatever the schema made of `undefined` is invented, not substituted. Only `optional` reaches this with a value: `defaulted` substitutes, and a schema that isn't optional-out has to keep the key.
809
+ if (!isPresent && isOptionalOut && optin === "optional") {
810
+ return;
811
+ }
812
+ if (result.issues.length) {
813
+ // For optional-in/out schemas, ignore errors on absent keys.
814
+ if (optin !== undefined && isOptionalOut && !isPresent) {
815
+ return;
816
+ }
817
+ final.issues.push(...util.prefixIssues(key, result.issues));
818
+ }
819
+ if (!isPresent && optin === undefined) {
820
+ if (!result.issues.length) {
821
+ final.issues.push({
822
+ code: "invalid_type",
823
+ expected: "nonoptional",
824
+ input: undefined,
825
+ path: [key],
826
+ });
827
+ }
828
+ return;
829
+ }
830
+ if (result.value === undefined) {
831
+ if (isPresent) {
832
+ final.value[key] = undefined;
833
+ }
834
+ }
835
+ else {
836
+ final.value[key] = result.value;
837
+ }
838
+ }
839
+ // one shared instance; a fresh [] per schema cost 56 bytes retained
840
+ const NO_SYMBOL_KEYS = [];
841
+ function normalizeDef(def) {
842
+ const keys = Object.keys(def.shape);
843
+ const ownSymbols = Object.getOwnPropertySymbols(def.shape);
844
+ const symbolKeys = ownSymbols.length ? ownSymbols : NO_SYMBOL_KEYS;
845
+ // aliases `keys` when there are no symbols, so a string-only shape keeps one array
846
+ const allKeys = symbolKeys.length ? [...keys, ...symbolKeys] : keys;
847
+ for (const k of allKeys) {
848
+ if (!def.shape?.[k]?._zod?.traits?.has("$ZodType")) {
849
+ throw new Error(`Invalid element at key "${String(k)}": expected a Zod schema`);
850
+ }
851
+ }
852
+ const okeys = util.optionalKeys(def.shape);
853
+ return {
854
+ ...def,
855
+ allKeys,
856
+ symbolKeys,
857
+ // string-only: handleCatchall matches it against `for...in`, which never yields a symbol
858
+ keySet: new Set(keys),
859
+ numKeys: keys.length,
860
+ optionalKeys: new Set(okeys),
861
+ };
862
+ }
863
+ function handleCatchall(proms, input, payload, ctx, def, inst) {
864
+ const unrecognized = [];
865
+ const keySet = def.keySet;
866
+ const _catchall = def.catchall._zod;
867
+ const t = _catchall.def.type;
868
+ const optin = _catchall.optin;
869
+ const optout = _catchall.optout;
870
+ for (const key in input) {
871
+ // Must precede the __proto__ branch: a declared key is not unrecognized, even though the shape loop deliberately strips __proto__ from the parsed output.
872
+ if (keySet.has(key))
873
+ continue;
874
+ // Don't copy an undeclared __proto__ into the result; assignment to a plain {} would replace the result prototype. But in strict mode it is still an unknown key, so report it before skipping.
875
+ if (key === "__proto__") {
876
+ if (t === "never")
877
+ unrecognized.push(key);
878
+ continue;
879
+ }
880
+ if (t === "never") {
881
+ unrecognized.push(key);
882
+ continue;
883
+ }
884
+ const r = _catchall.run({ value: input[key], issues: [] }, ctx);
885
+ if (r instanceof Promise) {
886
+ proms.push(r.then((r) => handlePropertyResult(r, payload, key, input, optin, optout)));
887
+ }
888
+ else {
889
+ handlePropertyResult(r, payload, key, input, optin, optout);
890
+ }
891
+ }
892
+ if (unrecognized.length) {
893
+ payload.issues.push({
894
+ code: "unrecognized_keys",
895
+ keys: unrecognized,
896
+ input,
897
+ inst,
898
+ // Describes the shape of the input, not the validity of the parsed value, so it never aborts. The parse still fails; the schema's own checks just get to run first, and an enclosing intersection can reconcile the key against a sibling operand.
899
+ continue: true,
900
+ });
901
+ }
902
+ if (!proms.length)
903
+ return payload;
904
+ return Promise.all(proms).then(() => {
905
+ return payload;
906
+ });
907
+ }
908
+ // Whichever object a def's `shape` currently answers from: the one the caller passed until the first read, the frozen copy after it. Keyed by def, so a def rebuilt by a builder is simply absent rather than inheriting the source's. Read its keys with `Object.keys`, which does not invoke them — that is what lets a discriminated union check its discriminator without resolving an option whose getters reference the union being constructed.
909
+ const propShapes = new WeakMap();
910
+ export const $ZodObject = /*@__PURE__*/ core.$constructor("$ZodObject", (inst, def) => {
911
+ // requires cast because technically $ZodObject doesn't extend
912
+ $ZodType.init(inst, def);
913
+ // const sh = def.shape;
914
+ const desc = Object.getOwnPropertyDescriptor(def, "shape");
915
+ if (!desc?.get) {
916
+ const sh = def.shape;
917
+ propShapes.set(def, sh);
918
+ Object.defineProperty(def, "shape", {
919
+ get: () => {
920
+ const newSh = { ...sh };
921
+ Object.defineProperty(def, "shape", {
922
+ value: newSh,
923
+ });
924
+ propShapes.set(def, newSh);
925
+ return newSh;
926
+ },
927
+ });
928
+ }
929
+ const _normalized = util.cached(() => normalizeDef(def));
930
+ util.defineLazyInternal(inst, "propValues", (zod) => {
931
+ const shape = zod.def.shape;
932
+ const propValues = {};
933
+ for (const key in shape) {
934
+ const field = shape[key]._zod;
935
+ if (field.values) {
936
+ if (!Object.prototype.hasOwnProperty.call(propValues, key)) {
937
+ util.assignProp(propValues, key, new Set());
938
+ }
939
+ for (const v of field.values)
940
+ propValues[key].add(v);
941
+ // An omittable slot reads back as undefined at a discriminator lookup, so it has to claim undefined: two options that can both omit the key are not discriminable on it.
942
+ if (field.optin !== undefined)
943
+ propValues[key].add(undefined);
944
+ }
945
+ }
946
+ return propValues;
947
+ });
948
+ const isObject = util.isObject;
949
+ const catchall = def.catchall;
950
+ let value;
951
+ const memo = core.globalConfig.memoizer;
952
+ memo?.attach(inst);
953
+ inst._zod.parse = (payload, ctx) => {
954
+ value ?? (value = _normalized.value);
955
+ const input = payload.value;
956
+ if (!isObject(input)) {
957
+ payload.issues.push({
958
+ expected: "object",
959
+ code: "invalid_type",
960
+ input,
961
+ inst,
962
+ });
963
+ return payload;
964
+ }
965
+ payload.value = memo ? memo.alloc(inst, payload, {}, ctx) : {};
966
+ const proms = [];
967
+ const shape = value.shape;
968
+ for (const key of value.allKeys) {
969
+ if (key === "__proto__")
970
+ continue;
971
+ const el = shape[key];
972
+ const optin = el._zod.optin;
973
+ const optout = el._zod.optout;
974
+ const r = el._zod.run({ value: input[key], issues: [] }, ctx);
975
+ if (r instanceof Promise) {
976
+ proms.push(r.then((r) => handlePropertyResult(r, payload, key, input, optin, optout)));
977
+ }
978
+ else {
979
+ handlePropertyResult(r, payload, key, input, optin, optout);
980
+ }
981
+ }
982
+ if (!catchall) {
983
+ return proms.length ? Promise.all(proms).then(() => payload) : payload;
984
+ }
985
+ return handleCatchall(proms, input, payload, ctx, _normalized.value, inst);
986
+ };
987
+ });
988
+ export const $ZodObjectJIT = /*@__PURE__*/ core.$constructor("$ZodObjectJIT", (inst, def) => {
989
+ // requires cast because technically $ZodObject doesn't extend
990
+ $ZodObject.init(inst, def);
991
+ const superParse = inst._zod.parse;
992
+ const _normalized = util.cached(() => normalizeDef(def));
993
+ const memo = core.globalConfig.memoizer;
994
+ const generateFastpass = (shape) => {
995
+ const normalized = _normalized.value;
996
+ const syms = normalized.symbolKeys;
997
+ // a symbol has no source literal, so it is read as `syms[i]` off the closed-over scope
998
+ const doc = new Doc(["payload", "ctx"], { shape, inst, memo, syms });
999
+ const parseStr = (k) => `shape[${k}]._zod.run({ value: input[${k}], issues: [] }, ctx)`;
1000
+ // Prefixes in place, like util.prefixIssues does for every interpreted path.
1001
+ const prefixStr = (id, k) => `
1002
+ for (let i = 0; i < ${id}.issues.length; i++) {
1003
+ const iss = ${id}.issues[i];
1004
+ iss.path = iss.path ? [${k}, ...iss.path] : [${k}];
1005
+ payload.issues.push(iss);
1006
+ }`;
1007
+ doc.write(`const input = payload.value;`);
1008
+ const ids = Object.create(null);
1009
+ let counter = 0;
1010
+ for (const key of normalized.allKeys) {
1011
+ ids[key] = `key_${counter++}`;
1012
+ }
1013
+ // A: preserve key order {
1014
+ doc.write(memo ? `const newResult = memo.alloc(inst, payload, {}, ctx);` : `const newResult = {};`);
1015
+ for (const key of normalized.allKeys) {
1016
+ if (key === "__proto__")
1017
+ continue;
1018
+ const id = ids[key];
1019
+ const k = typeof key === "symbol" ? `syms[${syms.indexOf(key)}]` : util.esc(key);
1020
+ const isPresent = `${k} in input`;
1021
+ const schema = shape[key];
1022
+ const optin = schema?._zod?.optin;
1023
+ const isOptionalIn = optin !== undefined;
1024
+ const isOptionalOut = schema?._zod?.optout === "optional";
1025
+ doc.write(`const ${id} = ${parseStr(k)};`);
1026
+ if (isOptionalIn && isOptionalOut) {
1027
+ // For optional-in/out schemas, ignore errors on absent keys — and, like the interpreted path, drop the value produced alongside them. The middle rung goes further: it permits absence without supplying anything in its place, so an absent key contributes nothing at all.
1028
+ const assign = optin === "optional" ? `${id}_present` : `${id}.value !== undefined || ${id}_present`;
1029
+ doc.write(`
1030
+ const ${id}_present = ${isPresent};
1031
+ if (!${id}.issues.length || ${id}_present) {
1032
+ if (${id}.issues.length) {${prefixStr(id, k)}
1033
+ }
1034
+
1035
+ if (${assign}) {
1036
+ newResult[${k}] = ${id}.value;
1037
+ }
1038
+ }
1039
+
1040
+ `);
1041
+ }
1042
+ else if (!isOptionalIn) {
1043
+ doc.write(`
1044
+ const ${id}_present = ${isPresent};
1045
+ if (${id}.issues.length) {${prefixStr(id, k)}
1046
+ }
1047
+ if (!${id}_present && !${id}.issues.length) {
1048
+ payload.issues.push({
1049
+ code: "invalid_type",
1050
+ expected: "nonoptional",
1051
+ input: undefined,
1052
+ path: [${k}]
1053
+ });
1054
+ }
1055
+
1056
+ if (${id}_present) {
1057
+ newResult[${k}] = ${id}.value;
1058
+ }
1059
+
1060
+ `);
1061
+ }
1062
+ else {
1063
+ doc.write(`
1064
+ if (${id}.issues.length) {${prefixStr(id, k)}
1065
+ }
1066
+
1067
+ if (${id}.value === undefined) {
1068
+ if (${isPresent}) {
1069
+ newResult[${k}] = undefined;
1070
+ }
1071
+ } else {
1072
+ newResult[${k}] = ${id}.value;
1073
+ }
1074
+
1075
+ `);
1076
+ }
1077
+ }
1078
+ doc.write(`payload.value = newResult;`);
1079
+ doc.write(`return payload;`);
1080
+ // closing `shape` in is what pays: turbofan specializes the parser against that one shape object, so every `shape[k]._zod.run` folds to a known callee. as a parameter it stays a generic load and measures 13% slower even with the forwarding frame gone
1081
+ return doc.compile();
1082
+ };
1083
+ let fastpass;
1084
+ const isObject = util.isObject;
1085
+ const jit = !core.globalConfig.jitless;
1086
+ const allowsEval = util.allowsEval;
1087
+ const fastEnabled = jit && allowsEval.value; // && !def.catchall;
1088
+ const catchall = def.catchall;
1089
+ let value;
1090
+ inst._zod.parse = (payload, ctx) => {
1091
+ value ?? (value = _normalized.value);
1092
+ const input = payload.value;
1093
+ if (!isObject(input)) {
1094
+ payload.issues.push({
1095
+ expected: "object",
1096
+ code: "invalid_type",
1097
+ input,
1098
+ inst,
1099
+ });
1100
+ return payload;
1101
+ }
1102
+ if (jit && fastEnabled && ctx?.async === false && ctx.jitless !== true) {
1103
+ // always synchronous
1104
+ if (!fastpass)
1105
+ fastpass = generateFastpass(def.shape);
1106
+ payload = fastpass(payload, ctx);
1107
+ if (!catchall)
1108
+ return payload;
1109
+ return handleCatchall([], input, payload, ctx, value, inst);
1110
+ }
1111
+ return superParse(payload, ctx);
1112
+ };
1113
+ });
1114
+ function handleUnionResults(results, final, inst, ctx) {
1115
+ for (const result of results) {
1116
+ if (result.issues.length === 0) {
1117
+ final.value = result.value;
1118
+ return final;
1119
+ }
1120
+ }
1121
+ const nonaborted = results.filter((r) => !util.aborted(r));
1122
+ if (nonaborted.length === 1) {
1123
+ final.value = nonaborted[0].value;
1124
+ return nonaborted[0];
1125
+ }
1126
+ final.issues.push({
1127
+ code: "invalid_union",
1128
+ input: final.value,
1129
+ inst,
1130
+ errors: results.map((result) => result.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config()))),
1131
+ });
1132
+ return final;
1133
+ }
1134
+ export const $ZodUnion = /*@__PURE__*/ core.$constructor("$ZodUnion", (inst, def) => {
1135
+ $ZodType.init(inst, def);
1136
+ util.defineLazyInternal(inst, "optin", (zod) => zod.def.options.some((o) => o._zod.optin === "defaulted")
1137
+ ? "defaulted"
1138
+ : zod.def.options.some((o) => o._zod.optin !== undefined)
1139
+ ? "optional"
1140
+ : undefined);
1141
+ util.defineLazyInternal(inst, "optout", (zod) => zod.def.options.some((o) => o._zod.optout === "optional") ? "optional" : undefined);
1142
+ util.defineLazyInternal(inst, "values", (zod) => {
1143
+ if (zod.def.options.every((o) => o._zod.values)) {
1144
+ return new Set(zod.def.options.flatMap((option) => Array.from(option._zod.values)));
1145
+ }
1146
+ return undefined;
1147
+ });
1148
+ util.defineLazyInternal(inst, "pattern", (zod) => {
1149
+ if (zod.def.options.every((o) => o._zod.pattern)) {
1150
+ const patterns = zod.def.options.map((o) => o._zod.pattern);
1151
+ return new RegExp(`^(${patterns.map((p) => util.cleanRegex(p.source)).join("|")})$`);
1152
+ }
1153
+ return undefined;
1154
+ });
1155
+ const first = def.options.length === 1 ? def.options[0]._zod.run : null;
1156
+ inst._zod.parse = (payload, ctx) => {
1157
+ if (first) {
1158
+ return first(payload, ctx);
1159
+ }
1160
+ let async = false;
1161
+ const results = [];
1162
+ for (const option of def.options) {
1163
+ const result = option._zod.run({
1164
+ value: payload.value,
1165
+ issues: [],
1166
+ }, ctx);
1167
+ if (result instanceof Promise) {
1168
+ results.push(result);
1169
+ async = true;
1170
+ }
1171
+ else {
1172
+ if (result.issues.length === 0)
1173
+ return result;
1174
+ results.push(result);
1175
+ }
1176
+ }
1177
+ if (!async)
1178
+ return handleUnionResults(results, payload, inst, ctx);
1179
+ return Promise.all(results).then((results) => {
1180
+ return handleUnionResults(results, payload, inst, ctx);
1181
+ });
1182
+ };
1183
+ });
1184
+ function handleExclusiveUnionResults(results, final, inst, ctx) {
1185
+ const matches = [];
1186
+ for (let i = 0; i < results.length; i++) {
1187
+ if (results[i].issues.length === 0)
1188
+ matches.push(i);
1189
+ }
1190
+ if (matches.length === 1) {
1191
+ final.value = results[matches[0]].value;
1192
+ return final;
1193
+ }
1194
+ if (matches.length === 0) {
1195
+ // No matches - same as regular union
1196
+ final.issues.push({
1197
+ code: "invalid_union",
1198
+ input: final.value,
1199
+ inst,
1200
+ errors: results.map((result) => result.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config()))),
1201
+ });
1202
+ }
1203
+ else {
1204
+ // Multiple matches - exclusive union failure
1205
+ final.issues.push({
1206
+ code: "invalid_union",
1207
+ input: final.value,
1208
+ inst,
1209
+ errors: [],
1210
+ inclusive: false,
1211
+ matches,
1212
+ });
1213
+ }
1214
+ return final;
1215
+ }
1216
+ export const $ZodXor = /*@__PURE__*/ core.$constructor("$ZodXor", (inst, def) => {
1217
+ $ZodUnion.init(inst, def);
1218
+ def.inclusive = false;
1219
+ const first = def.options.length === 1 ? def.options[0]._zod.run : null;
1220
+ inst._zod.parse = (payload, ctx) => {
1221
+ if (first) {
1222
+ return first(payload, ctx);
1223
+ }
1224
+ let async = false;
1225
+ const results = [];
1226
+ for (const option of def.options) {
1227
+ const result = option._zod.run({
1228
+ value: payload.value,
1229
+ issues: [],
1230
+ }, ctx);
1231
+ if (result instanceof Promise) {
1232
+ results.push(result);
1233
+ async = true;
1234
+ }
1235
+ else {
1236
+ results.push(result);
1237
+ }
1238
+ }
1239
+ if (!async)
1240
+ return handleExclusiveUnionResults(results, payload, inst, ctx);
1241
+ return Promise.all(results).then((results) => {
1242
+ return handleExclusiveUnionResults(results, payload, inst, ctx);
1243
+ });
1244
+ };
1245
+ });
1246
+ /** Returns the option of `union` whose discriminator claims `value`. */
1247
+ export function getDiscriminatedOption(union, value) {
1248
+ const internals = union._zod;
1249
+ let map = internals.bag.optionsMap;
1250
+ if (!map) {
1251
+ map = new Map();
1252
+ const { options, discriminator } = internals.def;
1253
+ for (const option of options) {
1254
+ // First declaration wins, matching the order the parse path resolves a duplicate in.
1255
+ for (const v of option._zod.propValues?.[discriminator] ?? [])
1256
+ if (!map.has(v))
1257
+ map.set(v, option);
1258
+ }
1259
+ internals.bag.optionsMap = map;
1260
+ }
1261
+ return map.get(value);
1262
+ }
1263
+ export const $ZodDiscriminatedUnion =
1264
+ /*@__PURE__*/
1265
+ core.$constructor("$ZodDiscriminatedUnion", (inst, def) => {
1266
+ def.inclusive = false;
1267
+ $ZodUnion.init(inst, def);
1268
+ const _super = inst._zod.parse;
1269
+ util.defineLazyInternal(inst, "propValues", (zod) => {
1270
+ const propValues = {};
1271
+ for (const option of zod.def.options) {
1272
+ const pv = option._zod.propValues;
1273
+ if (!pv || Object.keys(pv).length === 0)
1274
+ throw new Error(`Invalid discriminated union option at index "${zod.def.options.indexOf(option)}"`);
1275
+ for (const [k, v] of Object.entries(pv)) {
1276
+ if (!Object.prototype.hasOwnProperty.call(propValues, k)) {
1277
+ util.assignProp(propValues, k, new Set());
1278
+ }
1279
+ for (const val of v) {
1280
+ propValues[k].add(val);
1281
+ }
1282
+ }
1283
+ }
1284
+ return propValues;
1285
+ });
1286
+ // Checked now rather than in the lookup map below, so an option that lacks the discriminator fails at the `discriminatedUnion` call instead of on the first object parsed. Options whose shape cannot be enumerated without resolving it — pipes, lazies, and objects rebuilt by a builder such as `.extend()` — are left to the map.
1287
+ def.options.forEach((option, i) => {
1288
+ const propShape = propShapes.get(option._zod.def);
1289
+ if (propShape && !Object.prototype.hasOwnProperty.call(propShape, def.discriminator)) {
1290
+ throw new Error(`Invalid discriminated union option at index "${i}"`);
1291
+ }
1292
+ });
1293
+ const disc = util.cached(() => {
1294
+ const opts = def.options;
1295
+ const map = new Map();
1296
+ for (const o of opts) {
1297
+ const values = o._zod.propValues?.[def.discriminator];
1298
+ if (!values || values.size === 0)
1299
+ throw new Error(`Invalid discriminated union option at index "${def.options.indexOf(o)}"`);
1300
+ for (const v of values) {
1301
+ if (map.has(v)) {
1302
+ throw new Error(`Duplicate discriminator value "${String(v)}"`);
1303
+ }
1304
+ map.set(v, o);
1305
+ }
1306
+ }
1307
+ return map;
1308
+ });
1309
+ inst._zod.parse = (payload, ctx) => {
1310
+ const input = payload.value;
1311
+ if (!util.isObject(input)) {
1312
+ payload.issues.push({
1313
+ code: "invalid_type",
1314
+ expected: "object",
1315
+ input,
1316
+ inst,
1317
+ });
1318
+ return payload;
1319
+ }
1320
+ const opt = disc.value.get(input?.[def.discriminator]);
1321
+ if (opt) {
1322
+ return opt._zod.run(payload, ctx);
1323
+ }
1324
+ // Fall back to union matching when the fast discriminator path fails:
1325
+ // - explicitly enabled via unionFallback, or
1326
+ // - during backward direction (encode), since codec-based discriminators have different values in forward vs backward directions
1327
+ if (def.unionFallback || ctx.direction === "backward") {
1328
+ return _super(payload, ctx);
1329
+ }
1330
+ // no matching discriminator
1331
+ payload.issues.push({
1332
+ code: "invalid_union",
1333
+ errors: [],
1334
+ note: "No matching discriminator",
1335
+ discriminator: def.discriminator,
1336
+ options: Array.from(disc.value.keys()),
1337
+ input,
1338
+ path: [def.discriminator],
1339
+ inst,
1340
+ });
1341
+ return payload;
1342
+ };
1343
+ });
1344
+ export const $ZodIntersection = /*@__PURE__*/ core.$constructor("$ZodIntersection", (inst, def) => {
1345
+ $ZodType.init(inst, def);
1346
+ inst._zod.parse = (payload, ctx) => {
1347
+ const input = payload.value;
1348
+ const left = def.left._zod.run({ value: input, issues: [] }, ctx);
1349
+ const right = def.right._zod.run({ value: input, issues: [] }, ctx);
1350
+ const async = left instanceof Promise || right instanceof Promise;
1351
+ if (async) {
1352
+ return Promise.all([left, right]).then(([left, right]) => {
1353
+ return handleIntersectionResults(payload, left, right);
1354
+ });
1355
+ }
1356
+ return handleIntersectionResults(payload, left, right);
1357
+ };
1358
+ });
1359
+ export function mergeValues(a, b) {
1360
+ // const aType = parse.t(a);
1361
+ // const bType = parse.t(b);
1362
+ if (a === b) {
1363
+ return { valid: true, data: a };
1364
+ }
1365
+ if (a instanceof Date && b instanceof Date && +a === +b) {
1366
+ return { valid: true, data: a };
1367
+ }
1368
+ if (util.isPlainObject(a) && util.isPlainObject(b)) {
1369
+ const bKeys = Object.keys(b);
1370
+ const sharedKeys = Object.keys(a).filter((key) => bKeys.indexOf(key) !== -1);
1371
+ const newObj = { ...a, ...b };
1372
+ if (Object.prototype.hasOwnProperty.call(newObj, "__proto__"))
1373
+ delete newObj.__proto__;
1374
+ for (const key of sharedKeys) {
1375
+ if (key === "__proto__")
1376
+ continue;
1377
+ const sharedValue = mergeValues(a[key], b[key]);
1378
+ if (!sharedValue.valid) {
1379
+ return {
1380
+ valid: false,
1381
+ mergeErrorPath: [key, ...sharedValue.mergeErrorPath],
1382
+ };
1383
+ }
1384
+ newObj[key] = sharedValue.data;
1385
+ }
1386
+ return { valid: true, data: newObj };
1387
+ }
1388
+ if (Array.isArray(a) && Array.isArray(b)) {
1389
+ if (a.length !== b.length) {
1390
+ return { valid: false, mergeErrorPath: [] };
1391
+ }
1392
+ const newArray = [];
1393
+ for (let index = 0; index < a.length; index++) {
1394
+ const itemA = a[index];
1395
+ const itemB = b[index];
1396
+ const sharedValue = mergeValues(itemA, itemB);
1397
+ if (!sharedValue.valid) {
1398
+ return {
1399
+ valid: false,
1400
+ mergeErrorPath: [index, ...sharedValue.mergeErrorPath],
1401
+ };
1402
+ }
1403
+ newArray.push(sharedValue.data);
1404
+ }
1405
+ return { valid: true, data: newArray };
1406
+ }
1407
+ return { valid: false, mergeErrorPath: [] };
1408
+ }
1409
+ function handleIntersectionResults(result, left, right) {
1410
+ // Track which side(s) reject each key. A key rejection is reported only when BOTH sides reject it, so a key owned by one branch survives the other's key schema. strictObject reports these as unrecognized_keys; a record with an open key schema reports one invalid_key per key.
1411
+ const unrecKeys = new Map();
1412
+ let unrecIssue;
1413
+ const keyIssues = new Map();
1414
+ const collect = (iss, side) => {
1415
+ let keys;
1416
+ if (iss.code === "unrecognized_keys" && !iss.path?.length) {
1417
+ unrecIssue ?? (unrecIssue = iss);
1418
+ keys = iss.keys;
1419
+ }
1420
+ else if (iss.code === "invalid_key" && iss.origin === "record" && iss.path?.length === 1) {
1421
+ const k = String(iss.path[0]);
1422
+ if (!keyIssues.has(k))
1423
+ keyIssues.set(k, iss);
1424
+ keys = [k];
1425
+ }
1426
+ else {
1427
+ return false;
1428
+ }
1429
+ for (const k of keys) {
1430
+ if (!unrecKeys.has(k))
1431
+ unrecKeys.set(k, {});
1432
+ unrecKeys.get(k)[side] = true;
1433
+ }
1434
+ return true;
1435
+ };
1436
+ for (const iss of left.issues) {
1437
+ if (!collect(iss, "l"))
1438
+ result.issues.push(iss);
1439
+ }
1440
+ for (const iss of right.issues) {
1441
+ if (!collect(iss, "r"))
1442
+ result.issues.push(iss);
1443
+ }
1444
+ // Report only keys rejected by BOTH sides
1445
+ const bothKeys = [...unrecKeys].filter(([, f]) => f.l && f.r).map(([k]) => k);
1446
+ if (bothKeys.length) {
1447
+ const aggregated = unrecIssue ? bothKeys.filter((k) => unrecIssue.keys.includes(k)) : [];
1448
+ if (aggregated.length)
1449
+ result.issues.push({ ...unrecIssue, keys: aggregated });
1450
+ for (const k of bothKeys) {
1451
+ if (!aggregated.includes(k) && keyIssues.has(k))
1452
+ result.issues.push(keyIssues.get(k));
1453
+ }
1454
+ }
1455
+ const merged = mergeValues(left.value, right.value);
1456
+ if (!merged.valid) {
1457
+ if (util.aborted(result))
1458
+ return result;
1459
+ throw new Error(`Unmergable intersection. Error path: ` + `${JSON.stringify(merged.mergeErrorPath)}`);
1460
+ }
1461
+ result.value = merged.data;
1462
+ return result;
1463
+ }
1464
+ export const $ZodTuple = /*@__PURE__*/ core.$constructor("$ZodTuple", (inst, def) => {
1465
+ $ZodType.init(inst, def);
1466
+ const items = def.items;
1467
+ const memo = core.globalConfig.memoizer;
1468
+ memo?.attach(inst);
1469
+ inst._zod.parse = (payload, ctx) => {
1470
+ const input = payload.value;
1471
+ if (!Array.isArray(input)) {
1472
+ payload.issues.push({
1473
+ input,
1474
+ inst,
1475
+ expected: "tuple",
1476
+ code: "invalid_type",
1477
+ });
1478
+ return payload;
1479
+ }
1480
+ payload.value = memo ? memo.alloc(inst, payload, [], ctx) : [];
1481
+ const proms = [];
1482
+ const optinStart = getTupleOptStart(items, "optin");
1483
+ const optoutStart = getTupleOptStart(items, "optout");
1484
+ if (!def.rest) {
1485
+ if (input.length < optinStart) {
1486
+ payload.issues.push({
1487
+ code: "too_small",
1488
+ minimum: optinStart,
1489
+ inclusive: true,
1490
+ input,
1491
+ inst,
1492
+ origin: "array",
1493
+ });
1494
+ return payload;
1495
+ }
1496
+ if (input.length > items.length) {
1497
+ payload.issues.push({
1498
+ code: "too_big",
1499
+ maximum: items.length,
1500
+ inclusive: true,
1501
+ input,
1502
+ inst,
1503
+ origin: "array",
1504
+ });
1505
+ }
1506
+ }
1507
+ // Run every item in parallel, collecting results into an indexed array. The post-processing in `handleTupleResults` walks them in order so it can decide whether an absent optional-output error can truncate the tail or must be reported to preserve required output.
1508
+ const itemResults = new Array(items.length);
1509
+ for (let i = 0; i < items.length; i++) {
1510
+ const r = items[i]._zod.run({ value: input[i], issues: [] }, ctx);
1511
+ if (r instanceof Promise) {
1512
+ proms.push(r.then((rr) => {
1513
+ itemResults[i] = rr;
1514
+ }));
1515
+ }
1516
+ else {
1517
+ itemResults[i] = r;
1518
+ }
1519
+ }
1520
+ if (def.rest) {
1521
+ let i = items.length - 1;
1522
+ const rest = input.slice(items.length);
1523
+ for (const el of rest) {
1524
+ i++;
1525
+ const result = def.rest._zod.run({ value: el, issues: [] }, ctx);
1526
+ if (result instanceof Promise) {
1527
+ proms.push(result.then((r) => handleTupleResult(r, payload, i)));
1528
+ }
1529
+ else {
1530
+ handleTupleResult(result, payload, i);
1531
+ }
1532
+ }
1533
+ }
1534
+ if (proms.length) {
1535
+ return Promise.all(proms).then(() => handleTupleResults(itemResults, payload, items, input, optoutStart));
1536
+ }
1537
+ return handleTupleResults(itemResults, payload, items, input, optoutStart);
1538
+ };
1539
+ });
1540
+ function getTupleOptStart(items, key) {
1541
+ for (let i = items.length - 1; i >= 0; i--) {
1542
+ // optin is a three-rung ladder so any rung above `undefined` permits an absent slot; optout stays two-valued.
1543
+ const omittable = key === "optin" ? items[i]._zod.optin !== undefined : items[i]._zod.optout === "optional";
1544
+ if (!omittable)
1545
+ return i + 1;
1546
+ }
1547
+ return 0;
1548
+ }
1549
+ function handleTupleResult(result, final, index) {
1550
+ if (result.issues.length) {
1551
+ final.issues.push(...util.prefixIssues(index, result.issues));
1552
+ }
1553
+ final.value[index] = result.value;
1554
+ }
1555
+ function handleTupleResults(itemResults, final, items, input, optoutStart) {
1556
+ // Walk results in order. Mirror $ZodObject's swallow-on-absent-optional rule, but only after `optoutStart`: the first index where the output tuple tail can be absent.
1557
+ for (let i = 0; i < items.length; i++) {
1558
+ const r = itemResults[i];
1559
+ const isPresent = i < input.length;
1560
+ // The array analog of `handlePropertyResult`'s absent-key early return: the middle rung permits absence without supplying anything in its place, so the tail truncates here instead of materializing whatever the item made of `undefined`.
1561
+ if (!isPresent && i >= optoutStart && items[i]._zod.optin === "optional") {
1562
+ final.value.length = i;
1563
+ break;
1564
+ }
1565
+ if (r.issues.length) {
1566
+ if (!isPresent && i >= optoutStart) {
1567
+ final.value.length = i;
1568
+ break;
1569
+ }
1570
+ final.issues.push(...util.prefixIssues(i, r.issues));
1571
+ }
1572
+ final.value[i] = r.value;
1573
+ }
1574
+ // Drop trailing slots that produced `undefined` for absent input
1575
+ // (the array analog of an absent optional key on an object). The
1576
+ // `i >= input.length` floor is critical: an explicit `undefined`
1577
+ // *inside* the input must be preserved even when the schema is
1578
+ // optional-out (e.g. `z.string().or(z.undefined())` accepting an
1579
+ // explicit undefined value).
1580
+ for (let i = final.value.length - 1; i >= input.length; i--) {
1581
+ if (items[i]._zod.optout === "optional" && final.value[i] === undefined) {
1582
+ final.value.length = i;
1583
+ }
1584
+ else {
1585
+ break;
1586
+ }
1587
+ }
1588
+ return final;
1589
+ }
1590
+ export const $ZodRecord = /*@__PURE__*/ core.$constructor("$ZodRecord", (inst, def) => {
1591
+ $ZodType.init(inst, def);
1592
+ const memo = core.globalConfig.memoizer;
1593
+ memo?.attach(inst);
1594
+ inst._zod.parse = (payload, ctx) => {
1595
+ const input = payload.value;
1596
+ if (!util.isPlainObject(input)) {
1597
+ payload.issues.push({
1598
+ expected: "record",
1599
+ code: "invalid_type",
1600
+ input,
1601
+ inst,
1602
+ });
1603
+ return payload;
1604
+ }
1605
+ const proms = [];
1606
+ const values = def.keyType._zod.values;
1607
+ if (values && !def.partial) {
1608
+ payload.value = memo ? memo.alloc(inst, payload, {}, ctx) : {};
1609
+ const recordKeys = new Set();
1610
+ for (const key of values) {
1611
+ if (typeof key === "string" || typeof key === "number" || typeof key === "symbol") {
1612
+ recordKeys.add(typeof key === "number" ? key.toString() : key);
1613
+ // A declared __proto__ is stripped but is not an unrecognized key.
1614
+ if (key === "__proto__")
1615
+ continue;
1616
+ const keyResult = def.keyType._zod.run({ value: key, issues: [] }, ctx);
1617
+ if (keyResult instanceof Promise) {
1618
+ throw new Error("Async schemas not supported in object keys currently");
1619
+ }
1620
+ if (keyResult.issues.length) {
1621
+ payload.issues.push({
1622
+ code: "invalid_key",
1623
+ origin: "record",
1624
+ issues: keyResult.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
1625
+ input: key,
1626
+ path: [key],
1627
+ inst,
1628
+ });
1629
+ continue;
1630
+ }
1631
+ const outKey = keyResult.value;
1632
+ if (outKey === "__proto__")
1633
+ continue;
1634
+ const result = def.valueType._zod.run({ value: input[key], issues: [] }, ctx);
1635
+ if (result instanceof Promise) {
1636
+ proms.push(result.then((result) => {
1637
+ if (result.issues.length) {
1638
+ payload.issues.push(...util.prefixIssues(key, result.issues));
1639
+ }
1640
+ payload.value[outKey] = result.value;
1641
+ }));
1642
+ }
1643
+ else {
1644
+ if (result.issues.length) {
1645
+ payload.issues.push(...util.prefixIssues(key, result.issues));
1646
+ }
1647
+ payload.value[outKey] = result.value;
1648
+ }
1649
+ }
1650
+ }
1651
+ let unrecognized;
1652
+ for (const key in input) {
1653
+ if (!recordKeys.has(key)) {
1654
+ if (def.mode === "loose") {
1655
+ // skip __proto__ so it can't replace the result prototype via the assignment setter on the plain {} we build into
1656
+ if (key === "__proto__")
1657
+ continue;
1658
+ payload.value[key] = input[key];
1659
+ }
1660
+ else {
1661
+ unrecognized = unrecognized ?? [];
1662
+ unrecognized.push(key);
1663
+ }
1664
+ }
1665
+ }
1666
+ if (unrecognized && unrecognized.length > 0) {
1667
+ payload.issues.push({
1668
+ code: "unrecognized_keys",
1669
+ input,
1670
+ inst,
1671
+ keys: unrecognized,
1672
+ continue: true,
1673
+ });
1674
+ }
1675
+ }
1676
+ else {
1677
+ payload.value = memo ? memo.alloc(inst, payload, {}, ctx) : {};
1678
+ // An enumerable key schema declares which keys the record owns, so a key outside the set is unrecognized. A non-enumerable one (regex, refine) is a constraint every key must satisfy, so a failing key is invalid. Only the former is reconcilable against the other side of an intersection.
1679
+ let unrecognized;
1680
+ // Reflect.ownKeys for Symbol-key support; filter non-enumerable to match z.object()
1681
+ for (const key of Reflect.ownKeys(input)) {
1682
+ if (key === "__proto__")
1683
+ continue;
1684
+ if (!Object.prototype.propertyIsEnumerable.call(input, key))
1685
+ continue;
1686
+ let keyResult = def.keyType._zod.run({ value: key, issues: [] }, ctx);
1687
+ if (keyResult instanceof Promise) {
1688
+ throw new Error("Async schemas not supported in object keys currently");
1689
+ }
1690
+ // Numeric string fallback: if key is a numeric string and failed, retry with Number(key). This handles z.number(), z.literal([1, 2, 3]), and unions containing numeric literals
1691
+ const checkNumericKey = typeof key === "string" && regexes.number.test(key) && keyResult.issues.length;
1692
+ if (checkNumericKey) {
1693
+ const retryResult = def.keyType._zod.run({ value: Number(key), issues: [] }, ctx);
1694
+ if (retryResult instanceof Promise) {
1695
+ throw new Error("Async schemas not supported in object keys currently");
1696
+ }
1697
+ if (retryResult.issues.length === 0) {
1698
+ keyResult = retryResult;
1699
+ }
1700
+ }
1701
+ if (keyResult.issues.length) {
1702
+ if (def.mode === "loose") {
1703
+ // Pass through unchanged
1704
+ payload.value[key] = input[key];
1705
+ }
1706
+ else if (values) {
1707
+ unrecognized = unrecognized ?? [];
1708
+ unrecognized.push(key);
1709
+ }
1710
+ else {
1711
+ // Default "strict" behavior: error on invalid key
1712
+ payload.issues.push({
1713
+ code: "invalid_key",
1714
+ origin: "record",
1715
+ issues: keyResult.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
1716
+ input: key,
1717
+ path: [key],
1718
+ inst,
1719
+ });
1720
+ }
1721
+ continue;
1722
+ }
1723
+ // the guard above tests the raw input key, but the key schema can normalize an ordinary key into __proto__; re-check the key we actually write under
1724
+ const outKey = keyResult.value;
1725
+ if (outKey === "__proto__")
1726
+ continue;
1727
+ const result = def.valueType._zod.run({ value: input[key], issues: [] }, ctx);
1728
+ if (result instanceof Promise) {
1729
+ proms.push(result.then((result) => {
1730
+ if (result.issues.length) {
1731
+ payload.issues.push(...util.prefixIssues(key, result.issues));
1732
+ }
1733
+ payload.value[outKey] = result.value;
1734
+ }));
1735
+ }
1736
+ else {
1737
+ if (result.issues.length) {
1738
+ payload.issues.push(...util.prefixIssues(key, result.issues));
1739
+ }
1740
+ payload.value[outKey] = result.value;
1741
+ }
1742
+ }
1743
+ if (unrecognized && unrecognized.length > 0) {
1744
+ payload.issues.push({
1745
+ code: "unrecognized_keys",
1746
+ input,
1747
+ inst,
1748
+ keys: unrecognized,
1749
+ continue: true,
1750
+ });
1751
+ }
1752
+ }
1753
+ if (proms.length) {
1754
+ return Promise.all(proms).then(() => payload);
1755
+ }
1756
+ return payload;
1757
+ };
1758
+ });
1759
+ export const $ZodMap = /*@__PURE__*/ core.$constructor("$ZodMap", (inst, def) => {
1760
+ $ZodType.init(inst, def);
1761
+ const memo = core.globalConfig.memoizer;
1762
+ memo?.attach(inst);
1763
+ inst._zod.parse = (payload, ctx) => {
1764
+ const input = payload.value;
1765
+ if (!(input instanceof Map)) {
1766
+ payload.issues.push({
1767
+ expected: "map",
1768
+ code: "invalid_type",
1769
+ input,
1770
+ inst,
1771
+ });
1772
+ return payload;
1773
+ }
1774
+ const proms = [];
1775
+ payload.value = memo ? memo.alloc(inst, payload, new Map(), ctx) : new Map();
1776
+ for (const [key, value] of input) {
1777
+ const keyResult = def.keyType._zod.run({ value: key, issues: [] }, ctx);
1778
+ const valueResult = def.valueType._zod.run({ value: value, issues: [] }, ctx);
1779
+ if (keyResult instanceof Promise || valueResult instanceof Promise) {
1780
+ proms.push(Promise.all([keyResult, valueResult]).then(([keyResult, valueResult]) => {
1781
+ handleMapResult(keyResult, valueResult, payload, key, input, inst, ctx);
1782
+ }));
1783
+ }
1784
+ else {
1785
+ handleMapResult(keyResult, valueResult, payload, key, input, inst, ctx);
1786
+ }
1787
+ }
1788
+ if (proms.length)
1789
+ return Promise.all(proms).then(() => payload);
1790
+ return payload;
1791
+ };
1792
+ });
1793
+ function handleMapResult(keyResult, valueResult, final, key, input, inst, ctx) {
1794
+ if (keyResult.issues.length) {
1795
+ if (util.propertyKeyTypes.has(typeof key)) {
1796
+ final.issues.push(...util.prefixIssues(key, keyResult.issues));
1797
+ }
1798
+ else {
1799
+ final.issues.push({
1800
+ code: "invalid_key",
1801
+ origin: "map",
1802
+ input,
1803
+ inst,
1804
+ issues: keyResult.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
1805
+ });
1806
+ }
1807
+ }
1808
+ if (valueResult.issues.length) {
1809
+ if (util.propertyKeyTypes.has(typeof key)) {
1810
+ final.issues.push(...util.prefixIssues(key, valueResult.issues));
1811
+ }
1812
+ else {
1813
+ final.issues.push({
1814
+ origin: "map",
1815
+ code: "invalid_element",
1816
+ input,
1817
+ inst,
1818
+ key: key,
1819
+ issues: valueResult.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
1820
+ });
1821
+ }
1822
+ }
1823
+ final.value.set(keyResult.value, valueResult.value);
1824
+ }
1825
+ export const $ZodSet = /*@__PURE__*/ core.$constructor("$ZodSet", (inst, def) => {
1826
+ $ZodType.init(inst, def);
1827
+ const memo = core.globalConfig.memoizer;
1828
+ memo?.attach(inst);
1829
+ inst._zod.parse = (payload, ctx) => {
1830
+ const input = payload.value;
1831
+ if (!(input instanceof Set)) {
1832
+ payload.issues.push({
1833
+ input,
1834
+ inst,
1835
+ expected: "set",
1836
+ code: "invalid_type",
1837
+ });
1838
+ return payload;
1839
+ }
1840
+ const proms = [];
1841
+ payload.value = memo ? memo.alloc(inst, payload, new Set(), ctx) : new Set();
1842
+ for (const item of input) {
1843
+ const result = def.valueType._zod.run({ value: item, issues: [] }, ctx);
1844
+ if (result instanceof Promise) {
1845
+ proms.push(result.then((result) => handleSetResult(result, payload)));
1846
+ }
1847
+ else
1848
+ handleSetResult(result, payload);
1849
+ }
1850
+ if (proms.length)
1851
+ return Promise.all(proms).then(() => payload);
1852
+ return payload;
1853
+ };
1854
+ });
1855
+ function handleSetResult(result, final) {
1856
+ if (result.issues.length) {
1857
+ final.issues.push(...result.issues);
1858
+ }
1859
+ final.value.add(result.value);
1860
+ }
1861
+ export const $ZodEnum = /*@__PURE__*/ core.$constructor("$ZodEnum", (inst, def) => {
1862
+ $ZodType.init(inst, def);
1863
+ const values = util.getEnumValues(def.entries);
1864
+ const valuesSet = new Set(values);
1865
+ inst._zod.values = valuesSet;
1866
+ const patternValues = values.filter((k) => util.propertyKeyTypes.has(typeof k));
1867
+ // unmatchable fallback, RE2-safe: an empty alternation would compile to /^()$/, which matches ""
1868
+ inst._zod.pattern = new RegExp(patternValues.length ? `^(${patternValues.map((o) => util.escapeRegex(o.toString())).join("|")})$` : "^[^\\s\\S]$");
1869
+ inst._zod.parse = (payload, _ctx) => {
1870
+ const input = payload.value;
1871
+ if (valuesSet.has(input)) {
1872
+ return payload;
1873
+ }
1874
+ payload.issues.push({
1875
+ code: "invalid_value",
1876
+ values,
1877
+ input,
1878
+ inst,
1879
+ });
1880
+ return payload;
1881
+ };
1882
+ });
1883
+ export const $ZodLiteral = /*@__PURE__*/ core.$constructor("$ZodLiteral", (inst, def) => {
1884
+ $ZodType.init(inst, def);
1885
+ const values = new Set(def.values);
1886
+ inst._zod.values = values;
1887
+ // unmatchable fallback, RE2-safe: an empty alternation would compile to /^()$/, which matches ""
1888
+ inst._zod.pattern = new RegExp(def.values.length
1889
+ ? `^(${def.values
1890
+ .map((o) => (typeof o === "string" ? util.escapeRegex(o) : o ? util.escapeRegex(o.toString()) : String(o)))
1891
+ .join("|")})$`
1892
+ : "^[^\\s\\S]$");
1893
+ inst._zod.parse = (payload, _ctx) => {
1894
+ const input = payload.value;
1895
+ if (values.has(input)) {
1896
+ return payload;
1897
+ }
1898
+ payload.issues.push({
1899
+ code: "invalid_value",
1900
+ values: def.values,
1901
+ input,
1902
+ inst,
1903
+ });
1904
+ return payload;
1905
+ };
1906
+ });
1907
+ export const $ZodFile = /*@__PURE__*/ core.$constructor("$ZodFile", (inst, def) => {
1908
+ $ZodType.init(inst, def);
1909
+ inst._zod.parse = (payload, _ctx) => {
1910
+ const input = payload.value;
1911
+ // @ts-ignore
1912
+ if (input instanceof File)
1913
+ return payload;
1914
+ payload.issues.push({
1915
+ expected: "file",
1916
+ code: "invalid_type",
1917
+ input,
1918
+ inst,
1919
+ });
1920
+ return payload;
1921
+ };
1922
+ });
1923
+ export const $ZodTransform = /*@__PURE__*/ core.$constructor("$ZodTransform", (inst, def) => {
1924
+ $ZodType.init(inst, def);
1925
+ inst._zod.optin = "optional";
1926
+ core.globalConfig.memoizer?.guard(inst);
1927
+ inst._zod.parse = (payload, ctx) => {
1928
+ if (ctx.direction === "backward") {
1929
+ throw new core.$ZodEncodeError(inst.constructor.name);
1930
+ }
1931
+ const _out = def.transform(payload.value, payload);
1932
+ if (ctx.async) {
1933
+ const output = _out instanceof Promise ? _out : Promise.resolve(_out);
1934
+ return output.then((output) => {
1935
+ payload.value = output;
1936
+ return payload;
1937
+ });
1938
+ }
1939
+ if (_out instanceof Promise) {
1940
+ throw new core.$ZodAsyncError();
1941
+ }
1942
+ payload.value = _out;
1943
+ return payload;
1944
+ };
1945
+ });
1946
+ function handleOptionalResult(payload, result) {
1947
+ // A substituting schema that still failed has no usable answer; yield undefined. Its issues are simply dropped: it ran on a payload of its own, so there is no shared array to truncate and nothing of the caller's to lose with it.
1948
+ payload.value = result.issues.length ? undefined : result.value;
1949
+ return payload;
1950
+ }
1951
+ export const $ZodOptional = /*@__PURE__*/ core.$constructor("$ZodOptional", (inst, def) => {
1952
+ $ZodType.init(inst, def);
1953
+ // .optional() propagates absence rather than substituting for it, so a defaulted inner keeps its rung.
1954
+ util.defineLazyInternal(inst, "optin", (zod) => zod.def.innerType._zod.optin === "defaulted" ? "defaulted" : "optional");
1955
+ inst._zod.optout = "optional";
1956
+ util.defineLazyInternal(inst, "values", (zod) => {
1957
+ const values = zod.def.innerType._zod.values;
1958
+ return values ? new Set([...values, undefined]) : undefined;
1959
+ });
1960
+ util.defineLazyInternal(inst, "pattern", (zod) => {
1961
+ const pattern = zod.def.innerType._zod.pattern;
1962
+ return pattern ? new RegExp(`^(${util.cleanRegex(pattern.source)})?$`) : undefined;
1963
+ });
1964
+ inst._zod.parse = (payload, ctx) => {
1965
+ if (payload.value === undefined) {
1966
+ // Only the top rung substitutes a value for absence; everything else leaves it intact, which is what .optional() means.
1967
+ if (def.innerType._zod.optin !== "defaulted")
1968
+ return payload;
1969
+ // Its own payload, for the same reason $ZodCatch gets one: a pipe forwards an unrecognized key through the caller's issues array, and this must not read that as the substituting schema failing and drop it.
1970
+ const result = def.innerType._zod.run({ value: payload.value, issues: [] }, ctx);
1971
+ if (result instanceof Promise)
1972
+ return result.then((result) => handleOptionalResult(payload, result));
1973
+ return handleOptionalResult(payload, result);
1974
+ }
1975
+ return def.innerType._zod.run(payload, ctx);
1976
+ };
1977
+ });
1978
+ export const $ZodExactOptional = /*@__PURE__*/ core.$constructor("$ZodExactOptional", (inst, def) => {
1979
+ // Call parent init - inherits optin/optout = "optional"
1980
+ $ZodOptional.init(inst, def);
1981
+ // Override values/pattern to NOT add undefined
1982
+ util.defineLazyInternal(inst, "values", (zod) => zod.def.innerType._zod.values);
1983
+ util.defineLazyInternal(inst, "pattern", (zod) => zod.def.innerType._zod.pattern);
1984
+ // Override parse to just delegate (no undefined handling)
1985
+ inst._zod.parse = (payload, ctx) => {
1986
+ return def.innerType._zod.run(payload, ctx);
1987
+ };
1988
+ });
1989
+ export const $ZodNullable = /*@__PURE__*/ core.$constructor("$ZodNullable", (inst, def) => {
1990
+ $ZodType.init(inst, def);
1991
+ util.defineLazyInternal(inst, "optin", (zod) => zod.def.innerType._zod.optin);
1992
+ util.defineLazyInternal(inst, "optout", (zod) => zod.def.innerType._zod.optout);
1993
+ util.defineLazyInternal(inst, "pattern", (zod) => {
1994
+ const pattern = zod.def.innerType._zod.pattern;
1995
+ return pattern ? new RegExp(`^(${util.cleanRegex(pattern.source)}|null)$`) : undefined;
1996
+ });
1997
+ util.defineLazyInternal(inst, "values", (zod) => {
1998
+ return zod.def.innerType._zod.values ? new Set([...zod.def.innerType._zod.values, null]) : undefined;
1999
+ });
2000
+ inst._zod.parse = (payload, ctx) => {
2001
+ // Forward direction (decode): allow null to pass through
2002
+ if (payload.value === null)
2003
+ return payload;
2004
+ return def.innerType._zod.run(payload, ctx);
2005
+ };
2006
+ });
2007
+ export const $ZodDefault = /*@__PURE__*/ core.$constructor("$ZodDefault", (inst, def) => {
2008
+ $ZodType.init(inst, def);
2009
+ // inst._zod.qin = "true";
2010
+ inst._zod.optin = "defaulted";
2011
+ util.defineLazyInternal(inst, "values", (zod) => zod.def.innerType._zod.values);
2012
+ inst._zod.parse = (payload, ctx) => {
2013
+ if (ctx.direction === "backward") {
2014
+ return def.innerType._zod.run(payload, ctx);
2015
+ }
2016
+ // Forward direction (decode): apply defaults for undefined input
2017
+ if (payload.value === undefined) {
2018
+ payload.value = def.defaultValue;
2019
+ /**
2020
+ * $ZodDefault returns the default value immediately in forward direction.
2021
+ * It doesn't pass the default value into the validator ("prefault"). There's no reason to pass the default value through validation. The validity of the default is enforced by TypeScript statically. Otherwise, it's the responsibility of the user to ensure the default is valid. In the case of pipes with divergent in/out types, you can specify the default on the `in` schema of your ZodPipe to set a "prefault" for the pipe. */
2022
+ return payload;
2023
+ }
2024
+ // Forward direction: continue with default handling
2025
+ const result = def.innerType._zod.run(payload, ctx);
2026
+ if (result instanceof Promise) {
2027
+ return result.then((result) => handleDefaultResult(result, def));
2028
+ }
2029
+ return handleDefaultResult(result, def);
2030
+ };
2031
+ });
2032
+ function handleDefaultResult(payload, def) {
2033
+ if (payload.value === undefined) {
2034
+ payload.value = def.defaultValue;
2035
+ }
2036
+ return payload;
2037
+ }
2038
+ export const $ZodPrefault = /*@__PURE__*/ core.$constructor("$ZodPrefault", (inst, def) => {
2039
+ $ZodType.init(inst, def);
2040
+ inst._zod.optin = "defaulted";
2041
+ util.defineLazyInternal(inst, "values", (zod) => zod.def.innerType._zod.values);
2042
+ inst._zod.parse = (payload, ctx) => {
2043
+ if (ctx.direction === "backward") {
2044
+ return def.innerType._zod.run(payload, ctx);
2045
+ }
2046
+ // Forward direction (decode): apply prefault for undefined input
2047
+ if (payload.value === undefined) {
2048
+ payload.value = def.defaultValue;
2049
+ }
2050
+ return def.innerType._zod.run(payload, ctx);
2051
+ };
2052
+ });
2053
+ export const $ZodNonOptional = /*@__PURE__*/ core.$constructor("$ZodNonOptional", (inst, def) => {
2054
+ $ZodType.init(inst, def);
2055
+ util.defineLazyInternal(inst, "values", (zod) => {
2056
+ const v = zod.def.innerType._zod.values;
2057
+ return v ? new Set([...v].filter((x) => x !== undefined)) : undefined;
2058
+ });
2059
+ inst._zod.parse = (payload, ctx) => {
2060
+ const result = def.innerType._zod.run(payload, ctx);
2061
+ if (result instanceof Promise) {
2062
+ return result.then((result) => handleNonOptionalResult(result, inst));
2063
+ }
2064
+ return handleNonOptionalResult(result, inst);
2065
+ };
2066
+ });
2067
+ function handleNonOptionalResult(payload, inst) {
2068
+ if (!payload.issues.length && payload.value === undefined) {
2069
+ payload.issues.push({
2070
+ code: "invalid_type",
2071
+ expected: "nonoptional",
2072
+ input: payload.value,
2073
+ inst,
2074
+ });
2075
+ }
2076
+ return payload;
2077
+ }
2078
+ export const $ZodSuccess = /*@__PURE__*/ core.$constructor("$ZodSuccess", (inst, def) => {
2079
+ $ZodType.init(inst, def);
2080
+ inst._zod.parse = (payload, ctx) => {
2081
+ if (ctx.direction === "backward") {
2082
+ throw new core.$ZodEncodeError("ZodSuccess");
2083
+ }
2084
+ const result = def.innerType._zod.run(payload, ctx);
2085
+ if (result instanceof Promise) {
2086
+ return result.then((result) => {
2087
+ payload.value = result.issues.length === 0;
2088
+ return payload;
2089
+ });
2090
+ }
2091
+ payload.value = result.issues.length === 0;
2092
+ return payload;
2093
+ };
2094
+ });
2095
+ function handleCatchResult(payload, result, def, ctx) {
2096
+ if (!result.issues.length) {
2097
+ payload.value = result.value;
2098
+ // The value carries up, so the flag describing it has to carry with it: a back-edge into a node still being parsed must not be frozen by an enclosing readonly, and its checks belong to the node itself. Guarded so the ordinary case adds no own property.
2099
+ if (result.memo)
2100
+ payload.memo = true;
2101
+ return payload;
2102
+ }
2103
+ // Spread the inner's own payload, not ours: `value` has to stay the input the catch was handed, and the inner ran on a payload of its own so its issues are already private to this call.
2104
+ payload.value = def.catchValue({
2105
+ ...result,
2106
+ value: payload.value,
2107
+ error: {
2108
+ issues: result.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
2109
+ },
2110
+ input: payload.value,
2111
+ });
2112
+ return payload;
2113
+ }
2114
+ export const $ZodCatch = /*@__PURE__*/ core.$constructor("$ZodCatch", (inst, def) => {
2115
+ $ZodType.init(inst, def);
2116
+ util.defineLazyInternal(inst, "optin", (zod) => zod.def.innerType._zod.optin === "defaulted" ? "defaulted" : "optional");
2117
+ util.defineLazyInternal(inst, "optout", (zod) => zod.def.innerType._zod.optout);
2118
+ util.defineLazyInternal(inst, "values", (zod) => zod.def.innerType._zod.values);
2119
+ inst._zod.parse = (payload, ctx) => {
2120
+ if (ctx.direction === "backward") {
2121
+ return def.innerType._zod.run(payload, ctx);
2122
+ }
2123
+ // Forward direction (decode): apply catch logic
2124
+ const result = def.innerType._zod.run({ value: payload.value, issues: [] }, ctx);
2125
+ if (result instanceof Promise) {
2126
+ return result.then((result) => handleCatchResult(payload, result, def, ctx));
2127
+ }
2128
+ return handleCatchResult(payload, result, def, ctx);
2129
+ };
2130
+ });
2131
+ export const $ZodNaN = /*@__PURE__*/ core.$constructor("$ZodNaN", (inst, def) => {
2132
+ $ZodType.init(inst, def);
2133
+ inst._zod.parse = (payload, _ctx) => {
2134
+ if (typeof payload.value !== "number" || !Number.isNaN(payload.value)) {
2135
+ payload.issues.push({
2136
+ input: payload.value,
2137
+ inst,
2138
+ expected: "nan",
2139
+ code: "invalid_type",
2140
+ });
2141
+ return payload;
2142
+ }
2143
+ return payload;
2144
+ };
2145
+ });
2146
+ export const $ZodPipe = /*@__PURE__*/ core.$constructor("$ZodPipe", (inst, def) => {
2147
+ $ZodType.init(inst, def);
2148
+ util.defineLazyInternal(inst, "values", (zod) => zod.def.in._zod.values);
2149
+ util.defineLazyInternal(inst, "optin", (zod) => zod.def.in._zod.optin);
2150
+ util.defineLazyInternal(inst, "optout", (zod) => zod.def.out._zod.optout);
2151
+ util.defineLazyInternal(inst, "propValues", (zod) => zod.def.in._zod.propValues);
2152
+ inst._zod.parse = (payload, ctx) => {
2153
+ if (ctx.direction === "backward") {
2154
+ const right = def.out._zod.run(payload, ctx);
2155
+ if (right instanceof Promise) {
2156
+ return right.then((right) => handlePipeResult(right, def.in, ctx));
2157
+ }
2158
+ return handlePipeResult(right, def.in, ctx);
2159
+ }
2160
+ const left = def.in._zod.run(payload, ctx);
2161
+ if (left instanceof Promise) {
2162
+ return left.then((left) => handlePipeResult(left, def.out, ctx));
2163
+ }
2164
+ return handlePipeResult(left, def.out, ctx);
2165
+ };
2166
+ });
2167
+ function handlePipeResult(left, next, ctx) {
2168
+ // Any issue stops the pipe, so a failing refinement never feeds its transform. An unrecognized key is the exception: it describes the input's extra properties, not the value being piped, and an enclosing intersection may yet reconcile it.
2169
+ if (left.issues.some((iss) => iss.code !== "unrecognized_keys")) {
2170
+ // prevent further checks
2171
+ left.aborted = true;
2172
+ return left;
2173
+ }
2174
+ return next._zod.run({ value: left.value, issues: left.issues }, ctx);
2175
+ }
2176
+ export const $ZodCodec = /*@__PURE__*/ core.$constructor("$ZodCodec", (inst, def) => {
2177
+ $ZodType.init(inst, def);
2178
+ util.defineLazyInternal(inst, "values", (zod) => zod.def.in._zod.values);
2179
+ util.defineLazyInternal(inst, "optin", (zod) => zod.def.in._zod.optin);
2180
+ util.defineLazyInternal(inst, "optout", (zod) => zod.def.out._zod.optout);
2181
+ util.defineLazyInternal(inst, "propValues", (zod) => zod.def.in._zod.propValues);
2182
+ inst._zod.parse = (payload, ctx) => {
2183
+ const direction = ctx.direction || "forward";
2184
+ if (direction === "forward") {
2185
+ const left = def.in._zod.run(payload, ctx);
2186
+ if (left instanceof Promise) {
2187
+ return left.then((left) => handleCodecAResult(left, def, ctx));
2188
+ }
2189
+ return handleCodecAResult(left, def, ctx);
2190
+ }
2191
+ else {
2192
+ const right = def.out._zod.run(payload, ctx);
2193
+ if (right instanceof Promise) {
2194
+ return right.then((right) => handleCodecAResult(right, def, ctx));
2195
+ }
2196
+ return handleCodecAResult(right, def, ctx);
2197
+ }
2198
+ };
2199
+ });
2200
+ function handleCodecAResult(result, def, ctx) {
2201
+ if (result.issues.length) {
2202
+ // prevent further checks
2203
+ result.aborted = true;
2204
+ return result;
2205
+ }
2206
+ const direction = ctx.direction || "forward";
2207
+ if (direction === "forward") {
2208
+ const transformed = def.transform(result.value, result);
2209
+ if (transformed instanceof Promise) {
2210
+ return transformed.then((value) => handleCodecTxResult(result, value, def.out, ctx));
2211
+ }
2212
+ return handleCodecTxResult(result, transformed, def.out, ctx);
2213
+ }
2214
+ else {
2215
+ const transformed = def.reverseTransform(result.value, result);
2216
+ if (transformed instanceof Promise) {
2217
+ return transformed.then((value) => handleCodecTxResult(result, value, def.in, ctx));
2218
+ }
2219
+ return handleCodecTxResult(result, transformed, def.in, ctx);
2220
+ }
2221
+ }
2222
+ function handleCodecTxResult(left, value, nextSchema, ctx) {
2223
+ // Check if transform added any issues
2224
+ if (left.issues.length) {
2225
+ left.aborted = true;
2226
+ return left;
2227
+ }
2228
+ return nextSchema._zod.run({ value, issues: left.issues }, ctx);
2229
+ }
2230
+ export const $ZodPreprocess = /*@__PURE__*/ core.$constructor("$ZodPreprocess", (inst, def) => {
2231
+ $ZodPipe.init(inst, def);
2232
+ });
2233
+ export const $ZodReadonly = /*@__PURE__*/ core.$constructor("$ZodReadonly", (inst, def) => {
2234
+ $ZodType.init(inst, def);
2235
+ util.defineLazyInternal(inst, "propValues", (zod) => zod.def.innerType._zod.propValues);
2236
+ util.defineLazyInternal(inst, "values", (zod) => zod.def.innerType._zod.values);
2237
+ util.defineLazyInternal(inst, "optin", (zod) => zod.def.innerType?._zod?.optin);
2238
+ util.defineLazyInternal(inst, "optout", (zod) => zod.def.innerType?._zod?.optout);
2239
+ inst._zod.parse = (payload, ctx) => {
2240
+ if (ctx.direction === "backward") {
2241
+ return def.innerType._zod.run(payload, ctx);
2242
+ }
2243
+ const result = def.innerType._zod.run(payload, ctx);
2244
+ if (result instanceof Promise) {
2245
+ return result.then(handleReadonlyResult);
2246
+ }
2247
+ return handleReadonlyResult(result);
2248
+ };
2249
+ });
2250
+ function handleReadonlyResult(payload) {
2251
+ // A repeat visit hands back a node that is still being built; freezing it here would make the rest of its keys fail to assign.
2252
+ if (!payload.memo)
2253
+ payload.value = Object.freeze(payload.value);
2254
+ return payload;
2255
+ }
2256
+ export const $ZodTemplateLiteral = /*@__PURE__*/ core.$constructor("$ZodTemplateLiteral", (inst, def) => {
2257
+ $ZodType.init(inst, def);
2258
+ const regexParts = [];
2259
+ for (const part of def.parts) {
2260
+ if (typeof part === "object" && part !== null) {
2261
+ // is Zod schema
2262
+ if (!part._zod.pattern) {
2263
+ // if (!source)
2264
+ throw new Error(`Invalid template literal part, no pattern found: ${[...part._zod.traits].shift()}`);
2265
+ }
2266
+ const source = part._zod.pattern instanceof RegExp ? part._zod.pattern.source : part._zod.pattern;
2267
+ if (!source)
2268
+ throw new Error(`Invalid template literal part: ${part._zod.traits}`);
2269
+ const start = source.startsWith("^") ? 1 : 0;
2270
+ const end = source.endsWith("$") ? source.length - 1 : source.length;
2271
+ regexParts.push(source.slice(start, end));
2272
+ }
2273
+ else if (part === null || util.primitiveTypes.has(typeof part)) {
2274
+ regexParts.push(util.escapeRegex(`${part}`));
2275
+ }
2276
+ else {
2277
+ throw new Error(`Invalid template literal part: ${part}`);
2278
+ }
2279
+ }
2280
+ inst._zod.pattern = new RegExp(`^${regexParts.join("")}$`);
2281
+ inst._zod.parse = (payload, _ctx) => {
2282
+ if (typeof payload.value !== "string") {
2283
+ payload.issues.push({
2284
+ input: payload.value,
2285
+ inst,
2286
+ expected: "string",
2287
+ code: "invalid_type",
2288
+ });
2289
+ return payload;
2290
+ }
2291
+ inst._zod.pattern.lastIndex = 0;
2292
+ if (!inst._zod.pattern.test(payload.value)) {
2293
+ payload.issues.push({
2294
+ input: payload.value,
2295
+ inst,
2296
+ code: "invalid_format",
2297
+ format: def.format ?? "template_literal",
2298
+ pattern: inst._zod.pattern.source,
2299
+ });
2300
+ return payload;
2301
+ }
2302
+ return payload;
2303
+ };
2304
+ });
2305
+ export const $ZodFunction = /*@__PURE__*/ core.$constructor("$ZodFunction", (inst, def) => {
2306
+ $ZodType.init(inst, def);
2307
+ // Defined, not assigned: the classic prototype exposes `_def` as a getter with no setter.
2308
+ Object.defineProperty(inst, "_def", { value: def });
2309
+ inst._zod.def = def;
2310
+ inst.implement = (func) => {
2311
+ if (typeof func !== "function") {
2312
+ throw new Error("implement() must be called with a function");
2313
+ }
2314
+ // Defined inline so the closure stays anonymous: binding it to a `const` first names it, which costs 256 bytes per implemented function.
2315
+ return Object.defineProperty(function (...args) {
2316
+ const parsedArgs = inst._def.input ? parse(inst._def.input, args) : args;
2317
+ const result = Reflect.apply(func, this, parsedArgs);
2318
+ if (inst._def.output) {
2319
+ return parse(inst._def.output, result);
2320
+ }
2321
+ return result;
2322
+ }, "_zod", { value: inst._zod, enumerable: false });
2323
+ };
2324
+ inst.implementAsync = (func) => {
2325
+ if (typeof func !== "function") {
2326
+ throw new Error("implementAsync() must be called with a function");
2327
+ }
2328
+ return Object.defineProperty(async function (...args) {
2329
+ const parsedArgs = inst._def.input ? await parseAsync(inst._def.input, args) : args;
2330
+ const result = await Reflect.apply(func, this, parsedArgs);
2331
+ if (inst._def.output) {
2332
+ return await parseAsync(inst._def.output, result);
2333
+ }
2334
+ return result;
2335
+ }, "_zod", { value: inst._zod, enumerable: false });
2336
+ };
2337
+ inst._zod.parse = (payload, _ctx) => {
2338
+ if (typeof payload.value !== "function") {
2339
+ payload.issues.push({
2340
+ code: "invalid_type",
2341
+ expected: "function",
2342
+ input: payload.value,
2343
+ inst,
2344
+ });
2345
+ return payload;
2346
+ }
2347
+ // Check if output is a promise type to determine if we should use async implementation
2348
+ const hasPromiseOutput = inst._def.output && inst._def.output._zod.def.type === "promise";
2349
+ if (hasPromiseOutput) {
2350
+ payload.value = inst.implementAsync(payload.value);
2351
+ }
2352
+ else {
2353
+ payload.value = inst.implement(payload.value);
2354
+ }
2355
+ return payload;
2356
+ };
2357
+ inst.input = (...args) => {
2358
+ const F = inst.constructor;
2359
+ if (Array.isArray(args[0])) {
2360
+ return new F({
2361
+ type: "function",
2362
+ input: new $ZodTuple({
2363
+ type: "tuple",
2364
+ items: args[0],
2365
+ rest: args[1],
2366
+ }),
2367
+ output: inst._def.output,
2368
+ });
2369
+ }
2370
+ return new F({
2371
+ type: "function",
2372
+ input: args[0],
2373
+ output: inst._def.output,
2374
+ });
2375
+ };
2376
+ inst.output = (output) => {
2377
+ const F = inst.constructor;
2378
+ return new F({
2379
+ type: "function",
2380
+ input: inst._def.input,
2381
+ output,
2382
+ });
2383
+ };
2384
+ return inst;
2385
+ });
2386
+ export const $ZodPromise = /*@__PURE__*/ core.$constructor("$ZodPromise", (inst, def) => {
2387
+ $ZodType.init(inst, def);
2388
+ inst._zod.parse = (payload, ctx) => {
2389
+ return Promise.resolve(payload.value).then((inner) => def.innerType._zod.run({ value: inner, issues: [] }, ctx));
2390
+ };
2391
+ });
2392
+ export const $ZodLazy = /*@__PURE__*/ core.$constructor("$ZodLazy", (inst, def) => {
2393
+ $ZodType.init(inst, def);
2394
+ // Cache the resolved inner type on the shared `def` so all clones of this lazy (e.g. via `.describe()`/`.meta()`) share the same inner instance, preserving identity for cycle detection on recursive schemas.
2395
+ util.defineLazy(inst._zod, "innerType", () => {
2396
+ const d = def;
2397
+ if (!d._cachedInner)
2398
+ d._cachedInner = def.getter();
2399
+ return d._cachedInner;
2400
+ });
2401
+ util.defineLazyInternal(inst, "pattern", (zod) => zod.innerType?._zod?.pattern);
2402
+ util.defineLazyInternal(inst, "propValues", (zod) => zod.innerType?._zod?.propValues);
2403
+ util.defineLazyInternal(inst, "optin", (zod) => zod.innerType?._zod?.optin ?? undefined);
2404
+ util.defineLazyInternal(inst, "optout", (zod) => zod.innerType?._zod?.optout ?? undefined);
2405
+ inst._zod.parse = (payload, ctx) => {
2406
+ const inner = inst._zod.innerType;
2407
+ return inner._zod.run(payload, ctx);
2408
+ };
2409
+ });
2410
+ export const $ZodCustom = /*@__PURE__*/ core.$constructor("$ZodCustom", (inst, def) => {
2411
+ checks.$ZodCheck.init(inst, def);
2412
+ $ZodType.init(inst, def);
2413
+ inst._zod.parse = (payload, _) => {
2414
+ return payload;
2415
+ };
2416
+ inst._zod.check = (payload) => {
2417
+ const input = payload.value;
2418
+ const r = def.fn(input);
2419
+ if (r instanceof Promise) {
2420
+ return r.then((r) => handleRefineResult(r, payload, input, inst));
2421
+ }
2422
+ handleRefineResult(r, payload, input, inst);
2423
+ return;
2424
+ };
2425
+ });
2426
+ function handleRefineResult(result, payload, input, inst) {
2427
+ if (!result) {
2428
+ const _iss = {
2429
+ code: "custom",
2430
+ input,
2431
+ inst, // incorporates params.error into issue reporting
2432
+ path: [...(inst._zod.def.path ?? [])], // incorporates params.error into issue reporting
2433
+ continue: !inst._zod.def.abort,
2434
+ // params: inst._zod.def.params,
2435
+ };
2436
+ if (inst._zod.def.params)
2437
+ _iss.params = inst._zod.def.params;
2438
+ payload.issues.push(util.issue(_iss));
2439
+ }
2440
+ }