zod-compiler 1.23.0 → 1.23.2

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 (494) hide show
  1. package/README.md +9 -6
  2. package/dist/cli/commands/check.d.ts +10 -7
  3. package/dist/cli/commands/check.d.ts.map +1 -1
  4. package/dist/cli/commands/check.js +125 -148
  5. package/dist/cli/commands/check.js.map +1 -1
  6. package/dist/cli/commands/generate.d.ts +22 -19
  7. package/dist/cli/commands/generate.d.ts.map +1 -1
  8. package/dist/cli/commands/generate.js +102 -133
  9. package/dist/cli/commands/generate.js.map +1 -1
  10. package/dist/cli/commands/watch.d.ts +17 -15
  11. package/dist/cli/commands/watch.d.ts.map +1 -1
  12. package/dist/cli/commands/watch.js +126 -154
  13. package/dist/cli/commands/watch.js.map +1 -1
  14. package/dist/cli/emitter.d.ts +19 -16
  15. package/dist/cli/emitter.d.ts.map +1 -1
  16. package/dist/cli/emitter.js +55 -71
  17. package/dist/cli/emitter.js.map +1 -1
  18. package/dist/cli/errors.d.ts +4 -1
  19. package/dist/cli/errors.d.ts.map +1 -1
  20. package/dist/cli/errors.js +6 -2
  21. package/dist/cli/errors.js.map +1 -1
  22. package/dist/cli/index.d.ts +1 -3
  23. package/dist/cli/index.js +147 -160
  24. package/dist/cli/index.js.map +1 -1
  25. package/dist/cli/logger.d.ts +18 -15
  26. package/dist/cli/logger.d.ts.map +1 -1
  27. package/dist/cli/logger.js +38 -37
  28. package/dist/cli/logger.js.map +1 -1
  29. package/dist/core/codegen/build-path.d.ts +7 -41
  30. package/dist/core/codegen/build-path.d.ts.map +1 -1
  31. package/dist/core/codegen/build-path.js +481 -570
  32. package/dist/core/codegen/build-path.js.map +1 -1
  33. package/dist/core/codegen/context.d.ts +256 -253
  34. package/dist/core/codegen/context.d.ts.map +1 -1
  35. package/dist/core/codegen/context.js +363 -437
  36. package/dist/core/codegen/context.js.map +1 -1
  37. package/dist/core/codegen/dedupe.d.ts +22 -56
  38. package/dist/core/codegen/dedupe.d.ts.map +1 -1
  39. package/dist/core/codegen/dedupe.js +150 -242
  40. package/dist/core/codegen/dedupe.js.map +1 -1
  41. package/dist/core/codegen/emit-issue.d.ts +44 -68
  42. package/dist/core/codegen/emit-issue.d.ts.map +1 -1
  43. package/dist/core/codegen/emit-issue.js +76 -108
  44. package/dist/core/codegen/emit-issue.js.map +1 -1
  45. package/dist/core/codegen/emit.d.ts +4 -1
  46. package/dist/core/codegen/emit.d.ts.map +1 -1
  47. package/dist/core/codegen/emit.js +16 -13
  48. package/dist/core/codegen/emit.js.map +1 -1
  49. package/dist/core/codegen/fast-path.d.ts +7 -12
  50. package/dist/core/codegen/fast-path.d.ts.map +1 -1
  51. package/dist/core/codegen/fast-path.js +116 -145
  52. package/dist/core/codegen/fast-path.js.map +1 -1
  53. package/dist/core/codegen/fast-size.d.ts +12 -26
  54. package/dist/core/codegen/fast-size.d.ts.map +1 -1
  55. package/dist/core/codegen/fast-size.js +169 -244
  56. package/dist/core/codegen/fast-size.js.map +1 -1
  57. package/dist/core/codegen/index.d.ts +25 -23
  58. package/dist/core/codegen/index.d.ts.map +1 -1
  59. package/dist/core/codegen/index.js +239 -405
  60. package/dist/core/codegen/index.js.map +1 -1
  61. package/dist/core/codegen/issue-decls.d.ts +15 -12
  62. package/dist/core/codegen/issue-decls.d.ts.map +1 -1
  63. package/dist/core/codegen/issue-decls.js +131 -162
  64. package/dist/core/codegen/issue-decls.js.map +1 -1
  65. package/dist/core/codegen/regex-unroll.d.ts +4 -1
  66. package/dist/core/codegen/regex-unroll.d.ts.map +1 -1
  67. package/dist/core/codegen/regex-unroll.js +173 -197
  68. package/dist/core/codegen/regex-unroll.js.map +1 -1
  69. package/dist/core/codegen/schemas/any.d.ts +7 -4
  70. package/dist/core/codegen/schemas/any.d.ts.map +1 -1
  71. package/dist/core/codegen/schemas/any.js +8 -4
  72. package/dist/core/codegen/schemas/any.js.map +1 -1
  73. package/dist/core/codegen/schemas/array.d.ts +8 -5
  74. package/dist/core/codegen/schemas/array.d.ts.map +1 -1
  75. package/dist/core/codegen/schemas/array.js +77 -95
  76. package/dist/core/codegen/schemas/array.js.map +1 -1
  77. package/dist/core/codegen/schemas/bigint.d.ts +7 -4
  78. package/dist/core/codegen/schemas/bigint.d.ts.map +1 -1
  79. package/dist/core/codegen/schemas/bigint.js +44 -56
  80. package/dist/core/codegen/schemas/bigint.js.map +1 -1
  81. package/dist/core/codegen/schemas/boolean.d.ts +7 -4
  82. package/dist/core/codegen/schemas/boolean.d.ts.map +1 -1
  83. package/dist/core/codegen/schemas/boolean.js +12 -11
  84. package/dist/core/codegen/schemas/boolean.js.map +1 -1
  85. package/dist/core/codegen/schemas/catch.d.ts +8 -5
  86. package/dist/core/codegen/schemas/catch.d.ts.map +1 -1
  87. package/dist/core/codegen/schemas/catch.js +23 -23
  88. package/dist/core/codegen/schemas/catch.js.map +1 -1
  89. package/dist/core/codegen/schemas/date.d.ts +7 -4
  90. package/dist/core/codegen/schemas/date.d.ts.map +1 -1
  91. package/dist/core/codegen/schemas/date.js +49 -68
  92. package/dist/core/codegen/schemas/date.js.map +1 -1
  93. package/dist/core/codegen/schemas/default.d.ts +9 -6
  94. package/dist/core/codegen/schemas/default.d.ts.map +1 -1
  95. package/dist/core/codegen/schemas/default.js +29 -27
  96. package/dist/core/codegen/schemas/default.js.map +1 -1
  97. package/dist/core/codegen/schemas/discriminated-union.d.ts +12 -10
  98. package/dist/core/codegen/schemas/discriminated-union.d.ts.map +1 -1
  99. package/dist/core/codegen/schemas/discriminated-union.js +153 -178
  100. package/dist/core/codegen/schemas/discriminated-union.js.map +1 -1
  101. package/dist/core/codegen/schemas/effect.d.ts +9 -6
  102. package/dist/core/codegen/schemas/effect.d.ts.map +1 -1
  103. package/dist/core/codegen/schemas/effect.js +54 -67
  104. package/dist/core/codegen/schemas/effect.js.map +1 -1
  105. package/dist/core/codegen/schemas/enum.d.ts +7 -4
  106. package/dist/core/codegen/schemas/enum.d.ts.map +1 -1
  107. package/dist/core/codegen/schemas/enum.js +15 -21
  108. package/dist/core/codegen/schemas/enum.js.map +1 -1
  109. package/dist/core/codegen/schemas/fallback.d.ts +6 -3
  110. package/dist/core/codegen/schemas/fallback.d.ts.map +1 -1
  111. package/dist/core/codegen/schemas/fallback.js +14 -13
  112. package/dist/core/codegen/schemas/fallback.js.map +1 -1
  113. package/dist/core/codegen/schemas/file.d.ts +7 -4
  114. package/dist/core/codegen/schemas/file.d.ts.map +1 -1
  115. package/dist/core/codegen/schemas/file.js +51 -57
  116. package/dist/core/codegen/schemas/file.js.map +1 -1
  117. package/dist/core/codegen/schemas/intersection.d.ts +8 -5
  118. package/dist/core/codegen/schemas/intersection.d.ts.map +1 -1
  119. package/dist/core/codegen/schemas/intersection.js +16 -13
  120. package/dist/core/codegen/schemas/intersection.js.map +1 -1
  121. package/dist/core/codegen/schemas/literal.d.ts +7 -4
  122. package/dist/core/codegen/schemas/literal.d.ts.map +1 -1
  123. package/dist/core/codegen/schemas/literal.js +20 -23
  124. package/dist/core/codegen/schemas/literal.js.map +1 -1
  125. package/dist/core/codegen/schemas/map.d.ts +8 -5
  126. package/dist/core/codegen/schemas/map.d.ts.map +1 -1
  127. package/dist/core/codegen/schemas/map.js +61 -67
  128. package/dist/core/codegen/schemas/map.js.map +1 -1
  129. package/dist/core/codegen/schemas/nan.d.ts +7 -4
  130. package/dist/core/codegen/schemas/nan.d.ts.map +1 -1
  131. package/dist/core/codegen/schemas/nan.js +8 -4
  132. package/dist/core/codegen/schemas/nan.js.map +1 -1
  133. package/dist/core/codegen/schemas/never.d.ts +7 -4
  134. package/dist/core/codegen/schemas/never.d.ts.map +1 -1
  135. package/dist/core/codegen/schemas/never.js +8 -4
  136. package/dist/core/codegen/schemas/never.js.map +1 -1
  137. package/dist/core/codegen/schemas/null.d.ts +7 -4
  138. package/dist/core/codegen/schemas/null.d.ts.map +1 -1
  139. package/dist/core/codegen/schemas/null.js +8 -4
  140. package/dist/core/codegen/schemas/null.js.map +1 -1
  141. package/dist/core/codegen/schemas/nullable.d.ts +8 -5
  142. package/dist/core/codegen/schemas/nullable.d.ts.map +1 -1
  143. package/dist/core/codegen/schemas/nullable.js +8 -5
  144. package/dist/core/codegen/schemas/nullable.js.map +1 -1
  145. package/dist/core/codegen/schemas/number.d.ts +7 -4
  146. package/dist/core/codegen/schemas/number.d.ts.map +1 -1
  147. package/dist/core/codegen/schemas/number.js +120 -176
  148. package/dist/core/codegen/schemas/number.js.map +1 -1
  149. package/dist/core/codegen/schemas/object.d.ts +8 -5
  150. package/dist/core/codegen/schemas/object.d.ts.map +1 -1
  151. package/dist/core/codegen/schemas/object.js +144 -231
  152. package/dist/core/codegen/schemas/object.js.map +1 -1
  153. package/dist/core/codegen/schemas/optional.d.ts +9 -6
  154. package/dist/core/codegen/schemas/optional.d.ts.map +1 -1
  155. package/dist/core/codegen/schemas/optional.js +23 -31
  156. package/dist/core/codegen/schemas/optional.js.map +1 -1
  157. package/dist/core/codegen/schemas/pipe.d.ts +8 -5
  158. package/dist/core/codegen/schemas/pipe.d.ts.map +1 -1
  159. package/dist/core/codegen/schemas/pipe.js +20 -27
  160. package/dist/core/codegen/schemas/pipe.js.map +1 -1
  161. package/dist/core/codegen/schemas/readonly.d.ts +8 -5
  162. package/dist/core/codegen/schemas/readonly.d.ts.map +1 -1
  163. package/dist/core/codegen/schemas/readonly.js +8 -5
  164. package/dist/core/codegen/schemas/readonly.js.map +1 -1
  165. package/dist/core/codegen/schemas/record.d.ts +8 -5
  166. package/dist/core/codegen/schemas/record.d.ts.map +1 -1
  167. package/dist/core/codegen/schemas/record.js +52 -65
  168. package/dist/core/codegen/schemas/record.js.map +1 -1
  169. package/dist/core/codegen/schemas/recursive-ref.d.ts +9 -6
  170. package/dist/core/codegen/schemas/recursive-ref.d.ts.map +1 -1
  171. package/dist/core/codegen/schemas/recursive-ref.js +44 -44
  172. package/dist/core/codegen/schemas/recursive-ref.js.map +1 -1
  173. package/dist/core/codegen/schemas/set.d.ts +8 -5
  174. package/dist/core/codegen/schemas/set.d.ts.map +1 -1
  175. package/dist/core/codegen/schemas/set.js +61 -73
  176. package/dist/core/codegen/schemas/set.js.map +1 -1
  177. package/dist/core/codegen/schemas/string-bool.d.ts +6 -3
  178. package/dist/core/codegen/schemas/string-bool.d.ts.map +1 -1
  179. package/dist/core/codegen/schemas/string-bool.js +22 -23
  180. package/dist/core/codegen/schemas/string-bool.js.map +1 -1
  181. package/dist/core/codegen/schemas/string.d.ts +8 -5
  182. package/dist/core/codegen/schemas/string.d.ts.map +1 -1
  183. package/dist/core/codegen/schemas/string.js +168 -207
  184. package/dist/core/codegen/schemas/string.js.map +1 -1
  185. package/dist/core/codegen/schemas/symbol.d.ts +7 -4
  186. package/dist/core/codegen/schemas/symbol.d.ts.map +1 -1
  187. package/dist/core/codegen/schemas/symbol.js +8 -4
  188. package/dist/core/codegen/schemas/symbol.js.map +1 -1
  189. package/dist/core/codegen/schemas/template-literal.d.ts +7 -4
  190. package/dist/core/codegen/schemas/template-literal.d.ts.map +1 -1
  191. package/dist/core/codegen/schemas/template-literal.js +12 -13
  192. package/dist/core/codegen/schemas/template-literal.js.map +1 -1
  193. package/dist/core/codegen/schemas/tuple.d.ts +8 -5
  194. package/dist/core/codegen/schemas/tuple.d.ts.map +1 -1
  195. package/dist/core/codegen/schemas/tuple.js +84 -94
  196. package/dist/core/codegen/schemas/tuple.js.map +1 -1
  197. package/dist/core/codegen/schemas/undefined.d.ts +7 -4
  198. package/dist/core/codegen/schemas/undefined.d.ts.map +1 -1
  199. package/dist/core/codegen/schemas/undefined.js +8 -4
  200. package/dist/core/codegen/schemas/undefined.js.map +1 -1
  201. package/dist/core/codegen/schemas/union.d.ts +8 -5
  202. package/dist/core/codegen/schemas/union.d.ts.map +1 -1
  203. package/dist/core/codegen/schemas/union.js +49 -69
  204. package/dist/core/codegen/schemas/union.js.map +1 -1
  205. package/dist/core/codegen/schemas/unknown.d.ts +7 -4
  206. package/dist/core/codegen/schemas/unknown.d.ts.map +1 -1
  207. package/dist/core/codegen/schemas/unknown.js +8 -4
  208. package/dist/core/codegen/schemas/unknown.js.map +1 -1
  209. package/dist/core/codegen/schemas/void.d.ts +7 -4
  210. package/dist/core/codegen/schemas/void.d.ts.map +1 -1
  211. package/dist/core/codegen/schemas/void.js +8 -4
  212. package/dist/core/codegen/schemas/void.js.map +1 -1
  213. package/dist/core/codegen/slow-path.d.ts +7 -4
  214. package/dist/core/codegen/slow-path.d.ts.map +1 -1
  215. package/dist/core/codegen/slow-path.js +71 -96
  216. package/dist/core/codegen/slow-path.js.map +1 -1
  217. package/dist/core/codegen/well-known-regex.d.ts +22 -19
  218. package/dist/core/codegen/well-known-regex.d.ts.map +1 -1
  219. package/dist/core/codegen/well-known-regex.js +127 -96
  220. package/dist/core/codegen/well-known-regex.js.map +1 -1
  221. package/dist/core/compile.d.ts +7 -4
  222. package/dist/core/compile.d.ts.map +1 -1
  223. package/dist/core/compile.js +48 -48
  224. package/dist/core/compile.js.map +1 -1
  225. package/dist/core/diagnostic.d.ts +38 -39
  226. package/dist/core/diagnostic.d.ts.map +1 -1
  227. package/dist/core/diagnostic.js +140 -164
  228. package/dist/core/diagnostic.js.map +1 -1
  229. package/dist/core/extract/checks.d.ts +18 -15
  230. package/dist/core/extract/checks.d.ts.map +1 -1
  231. package/dist/core/extract/checks.js +318 -311
  232. package/dist/core/extract/checks.js.map +1 -1
  233. package/dist/core/extract/effects.d.ts +13 -10
  234. package/dist/core/extract/effects.d.ts.map +1 -1
  235. package/dist/core/extract/effects.js +153 -222
  236. package/dist/core/extract/effects.js.map +1 -1
  237. package/dist/core/extract/extractors/any.d.ts +5 -2
  238. package/dist/core/extract/extractors/any.d.ts.map +1 -1
  239. package/dist/core/extract/extractors/any.js +5 -1
  240. package/dist/core/extract/extractors/any.js.map +1 -1
  241. package/dist/core/extract/extractors/array.d.ts +6 -3
  242. package/dist/core/extract/extractors/array.d.ts.map +1 -1
  243. package/dist/core/extract/extractors/array.js +25 -20
  244. package/dist/core/extract/extractors/array.js.map +1 -1
  245. package/dist/core/extract/extractors/bigint.d.ts +6 -3
  246. package/dist/core/extract/extractors/bigint.d.ts.map +1 -1
  247. package/dist/core/extract/extractors/bigint.js +66 -64
  248. package/dist/core/extract/extractors/bigint.js.map +1 -1
  249. package/dist/core/extract/extractors/boolean.d.ts +5 -2
  250. package/dist/core/extract/extractors/boolean.d.ts.map +1 -1
  251. package/dist/core/extract/extractors/boolean.js +7 -3
  252. package/dist/core/extract/extractors/boolean.js.map +1 -1
  253. package/dist/core/extract/extractors/catch.d.ts +6 -3
  254. package/dist/core/extract/extractors/catch.d.ts.map +1 -1
  255. package/dist/core/extract/extractors/catch.js +26 -17
  256. package/dist/core/extract/extractors/catch.js.map +1 -1
  257. package/dist/core/extract/extractors/date.d.ts +6 -3
  258. package/dist/core/extract/extractors/date.d.ts.map +1 -1
  259. package/dist/core/extract/extractors/date.js +42 -46
  260. package/dist/core/extract/extractors/date.js.map +1 -1
  261. package/dist/core/extract/extractors/default.d.ts +6 -3
  262. package/dist/core/extract/extractors/default.d.ts.map +1 -1
  263. package/dist/core/extract/extractors/default.js +20 -14
  264. package/dist/core/extract/extractors/default.js.map +1 -1
  265. package/dist/core/extract/extractors/enum.d.ts +5 -2
  266. package/dist/core/extract/extractors/enum.d.ts.map +1 -1
  267. package/dist/core/extract/extractors/enum.js +12 -13
  268. package/dist/core/extract/extractors/enum.js.map +1 -1
  269. package/dist/core/extract/extractors/file.d.ts +6 -3
  270. package/dist/core/extract/extractors/file.d.ts.map +1 -1
  271. package/dist/core/extract/extractors/file.js +34 -28
  272. package/dist/core/extract/extractors/file.js.map +1 -1
  273. package/dist/core/extract/extractors/intersection.d.ts +5 -2
  274. package/dist/core/extract/extractors/intersection.d.ts.map +1 -1
  275. package/dist/core/extract/extractors/intersection.js +13 -11
  276. package/dist/core/extract/extractors/intersection.js.map +1 -1
  277. package/dist/core/extract/extractors/lazy.d.ts +6 -3
  278. package/dist/core/extract/extractors/lazy.d.ts.map +1 -1
  279. package/dist/core/extract/extractors/lazy.js +21 -30
  280. package/dist/core/extract/extractors/lazy.js.map +1 -1
  281. package/dist/core/extract/extractors/literal.d.ts +5 -2
  282. package/dist/core/extract/extractors/literal.d.ts.map +1 -1
  283. package/dist/core/extract/extractors/literal.js +8 -1
  284. package/dist/core/extract/extractors/literal.js.map +1 -1
  285. package/dist/core/extract/extractors/map.d.ts +6 -3
  286. package/dist/core/extract/extractors/map.d.ts.map +1 -1
  287. package/dist/core/extract/extractors/map.js +10 -4
  288. package/dist/core/extract/extractors/map.js.map +1 -1
  289. package/dist/core/extract/extractors/nan.d.ts +5 -2
  290. package/dist/core/extract/extractors/nan.d.ts.map +1 -1
  291. package/dist/core/extract/extractors/nan.js +5 -1
  292. package/dist/core/extract/extractors/nan.js.map +1 -1
  293. package/dist/core/extract/extractors/never.d.ts +5 -2
  294. package/dist/core/extract/extractors/never.d.ts.map +1 -1
  295. package/dist/core/extract/extractors/never.js +5 -1
  296. package/dist/core/extract/extractors/never.js.map +1 -1
  297. package/dist/core/extract/extractors/null.d.ts +5 -2
  298. package/dist/core/extract/extractors/null.d.ts.map +1 -1
  299. package/dist/core/extract/extractors/null.js +5 -1
  300. package/dist/core/extract/extractors/null.js.map +1 -1
  301. package/dist/core/extract/extractors/nullable.d.ts +5 -2
  302. package/dist/core/extract/extractors/nullable.d.ts.map +1 -1
  303. package/dist/core/extract/extractors/nullable.js +7 -3
  304. package/dist/core/extract/extractors/nullable.js.map +1 -1
  305. package/dist/core/extract/extractors/number.d.ts +6 -3
  306. package/dist/core/extract/extractors/number.d.ts.map +1 -1
  307. package/dist/core/extract/extractors/number.js +35 -35
  308. package/dist/core/extract/extractors/number.js.map +1 -1
  309. package/dist/core/extract/extractors/object.d.ts +6 -3
  310. package/dist/core/extract/extractors/object.d.ts.map +1 -1
  311. package/dist/core/extract/extractors/object.js +49 -76
  312. package/dist/core/extract/extractors/object.js.map +1 -1
  313. package/dist/core/extract/extractors/optional.d.ts +5 -2
  314. package/dist/core/extract/extractors/optional.d.ts.map +1 -1
  315. package/dist/core/extract/extractors/optional.js +10 -12
  316. package/dist/core/extract/extractors/optional.js.map +1 -1
  317. package/dist/core/extract/extractors/pipe.d.ts +6 -3
  318. package/dist/core/extract/extractors/pipe.d.ts.map +1 -1
  319. package/dist/core/extract/extractors/pipe.js +40 -41
  320. package/dist/core/extract/extractors/pipe.js.map +1 -1
  321. package/dist/core/extract/extractors/readonly.d.ts +5 -2
  322. package/dist/core/extract/extractors/readonly.d.ts.map +1 -1
  323. package/dist/core/extract/extractors/readonly.js +10 -6
  324. package/dist/core/extract/extractors/readonly.js.map +1 -1
  325. package/dist/core/extract/extractors/record.d.ts +6 -3
  326. package/dist/core/extract/extractors/record.d.ts.map +1 -1
  327. package/dist/core/extract/extractors/record.js +24 -35
  328. package/dist/core/extract/extractors/record.js.map +1 -1
  329. package/dist/core/extract/extractors/set.d.ts +6 -3
  330. package/dist/core/extract/extractors/set.d.ts.map +1 -1
  331. package/dist/core/extract/extractors/set.js +36 -30
  332. package/dist/core/extract/extractors/set.js.map +1 -1
  333. package/dist/core/extract/extractors/string-bool.d.ts +7 -4
  334. package/dist/core/extract/extractors/string-bool.d.ts.map +1 -1
  335. package/dist/core/extract/extractors/string-bool.js +66 -84
  336. package/dist/core/extract/extractors/string-bool.js.map +1 -1
  337. package/dist/core/extract/extractors/string.d.ts +6 -3
  338. package/dist/core/extract/extractors/string.d.ts.map +1 -1
  339. package/dist/core/extract/extractors/string.js +34 -37
  340. package/dist/core/extract/extractors/string.js.map +1 -1
  341. package/dist/core/extract/extractors/symbol.d.ts +5 -2
  342. package/dist/core/extract/extractors/symbol.d.ts.map +1 -1
  343. package/dist/core/extract/extractors/symbol.js +5 -1
  344. package/dist/core/extract/extractors/symbol.js.map +1 -1
  345. package/dist/core/extract/extractors/template-literal.d.ts +6 -3
  346. package/dist/core/extract/extractors/template-literal.d.ts.map +1 -1
  347. package/dist/core/extract/extractors/template-literal.js +11 -6
  348. package/dist/core/extract/extractors/template-literal.js.map +1 -1
  349. package/dist/core/extract/extractors/tuple.d.ts +6 -3
  350. package/dist/core/extract/extractors/tuple.d.ts.map +1 -1
  351. package/dist/core/extract/extractors/tuple.js +10 -4
  352. package/dist/core/extract/extractors/tuple.js.map +1 -1
  353. package/dist/core/extract/extractors/undefined.d.ts +5 -2
  354. package/dist/core/extract/extractors/undefined.d.ts.map +1 -1
  355. package/dist/core/extract/extractors/undefined.js +5 -1
  356. package/dist/core/extract/extractors/undefined.js.map +1 -1
  357. package/dist/core/extract/extractors/union.d.ts +6 -3
  358. package/dist/core/extract/extractors/union.d.ts.map +1 -1
  359. package/dist/core/extract/extractors/union.js +38 -64
  360. package/dist/core/extract/extractors/union.js.map +1 -1
  361. package/dist/core/extract/extractors/unknown.d.ts +5 -2
  362. package/dist/core/extract/extractors/unknown.d.ts.map +1 -1
  363. package/dist/core/extract/extractors/unknown.js +5 -1
  364. package/dist/core/extract/extractors/unknown.js.map +1 -1
  365. package/dist/core/extract/extractors/void.d.ts +5 -2
  366. package/dist/core/extract/extractors/void.d.ts.map +1 -1
  367. package/dist/core/extract/extractors/void.js +5 -1
  368. package/dist/core/extract/extractors/void.js.map +1 -1
  369. package/dist/core/extract/fallback.d.ts +6 -3
  370. package/dist/core/extract/fallback.d.ts.map +1 -1
  371. package/dist/core/extract/fallback.js +21 -7
  372. package/dist/core/extract/fallback.js.map +1 -1
  373. package/dist/core/extract/index.d.ts +6 -4
  374. package/dist/core/extract/index.d.ts.map +1 -1
  375. package/dist/core/extract/index.js +15 -15
  376. package/dist/core/extract/index.js.map +1 -1
  377. package/dist/core/extract/registry.d.ts +39 -36
  378. package/dist/core/extract/registry.d.ts.map +1 -1
  379. package/dist/core/extract/registry.js +96 -123
  380. package/dist/core/extract/registry.js.map +1 -1
  381. package/dist/core/extract/types.d.ts +124 -120
  382. package/dist/core/extract/types.d.ts.map +1 -1
  383. package/dist/core/extract/types.js +0 -1
  384. package/dist/core/iife.d.ts +14 -15
  385. package/dist/core/iife.d.ts.map +1 -1
  386. package/dist/core/iife.js +182 -206
  387. package/dist/core/iife.js.map +1 -1
  388. package/dist/core/pipeline.d.ts +33 -30
  389. package/dist/core/pipeline.d.ts.map +1 -1
  390. package/dist/core/pipeline.js +67 -74
  391. package/dist/core/pipeline.js.map +1 -1
  392. package/dist/core/types.d.ts +430 -427
  393. package/dist/core/types.d.ts.map +1 -1
  394. package/dist/core/types.js +0 -5
  395. package/dist/discovery.d.ts +8 -5
  396. package/dist/discovery.d.ts.map +1 -1
  397. package/dist/discovery.js +31 -32
  398. package/dist/discovery.js.map +1 -1
  399. package/dist/index.d.ts +4 -4
  400. package/dist/index.js +2 -2
  401. package/dist/jit.d.ts +15 -42
  402. package/dist/jit.d.ts.map +1 -1
  403. package/dist/jit.js +187 -216
  404. package/dist/jit.js.map +1 -1
  405. package/dist/loader.d.ts +14 -11
  406. package/dist/loader.d.ts.map +1 -1
  407. package/dist/loader.js +226 -258
  408. package/dist/loader.js.map +1 -1
  409. package/dist/static-filter.d.ts +4 -1
  410. package/dist/static-filter.d.ts.map +1 -1
  411. package/dist/static-filter.js +240 -367
  412. package/dist/static-filter.js.map +1 -1
  413. package/dist/swc.d.ts +38 -35
  414. package/dist/swc.d.ts.map +1 -1
  415. package/dist/swc.js +83 -76
  416. package/dist/swc.js.map +1 -1
  417. package/dist/unplugin/bun.d.ts +5 -2
  418. package/dist/unplugin/bun.d.ts.map +1 -1
  419. package/dist/unplugin/bun.js +5 -1
  420. package/dist/unplugin/bun.js.map +1 -1
  421. package/dist/unplugin/dep-graph.d.ts +10 -7
  422. package/dist/unplugin/dep-graph.d.ts.map +1 -1
  423. package/dist/unplugin/dep-graph.js +216 -252
  424. package/dist/unplugin/dep-graph.js.map +1 -1
  425. package/dist/unplugin/disk-cache.d.ts +121 -92
  426. package/dist/unplugin/disk-cache.d.ts.map +1 -1
  427. package/dist/unplugin/disk-cache.js +425 -444
  428. package/dist/unplugin/disk-cache.js.map +1 -1
  429. package/dist/unplugin/edits.d.ts +15 -12
  430. package/dist/unplugin/edits.d.ts.map +1 -1
  431. package/dist/unplugin/edits.js +24 -37
  432. package/dist/unplugin/edits.js.map +1 -1
  433. package/dist/unplugin/esbuild.d.ts +5 -2
  434. package/dist/unplugin/esbuild.d.ts.map +1 -1
  435. package/dist/unplugin/esbuild.js +5 -1
  436. package/dist/unplugin/esbuild.js.map +1 -1
  437. package/dist/unplugin/farm.d.ts +5 -2
  438. package/dist/unplugin/farm.d.ts.map +1 -1
  439. package/dist/unplugin/farm.js +5 -1
  440. package/dist/unplugin/farm.js.map +1 -1
  441. package/dist/unplugin/hoist-compile.d.ts +14 -42
  442. package/dist/unplugin/hoist-compile.d.ts.map +1 -1
  443. package/dist/unplugin/hoist-compile.js +67 -112
  444. package/dist/unplugin/hoist-compile.js.map +1 -1
  445. package/dist/unplugin/hoist.d.ts +56 -54
  446. package/dist/unplugin/hoist.d.ts.map +1 -1
  447. package/dist/unplugin/hoist.js +945 -1170
  448. package/dist/unplugin/hoist.js.map +1 -1
  449. package/dist/unplugin/index.d.ts +5 -3
  450. package/dist/unplugin/index.d.ts.map +1 -1
  451. package/dist/unplugin/index.js +175 -250
  452. package/dist/unplugin/index.js.map +1 -1
  453. package/dist/unplugin/rolldown.d.ts +5 -2
  454. package/dist/unplugin/rolldown.d.ts.map +1 -1
  455. package/dist/unplugin/rolldown.js +5 -1
  456. package/dist/unplugin/rolldown.js.map +1 -1
  457. package/dist/unplugin/rollup.d.ts +5 -2
  458. package/dist/unplugin/rollup.d.ts.map +1 -1
  459. package/dist/unplugin/rollup.js +5 -1
  460. package/dist/unplugin/rollup.js.map +1 -1
  461. package/dist/unplugin/rsbuild.d.ts +6 -3
  462. package/dist/unplugin/rsbuild.d.ts.map +1 -1
  463. package/dist/unplugin/rsbuild.js +15 -11
  464. package/dist/unplugin/rsbuild.js.map +1 -1
  465. package/dist/unplugin/rspack.d.ts +5 -2
  466. package/dist/unplugin/rspack.d.ts.map +1 -1
  467. package/dist/unplugin/rspack.js +5 -1
  468. package/dist/unplugin/rspack.js.map +1 -1
  469. package/dist/unplugin/transform.d.ts +30 -27
  470. package/dist/unplugin/transform.d.ts.map +1 -1
  471. package/dist/unplugin/transform.js +433 -620
  472. package/dist/unplugin/transform.js.map +1 -1
  473. package/dist/unplugin/types.d.ts +189 -184
  474. package/dist/unplugin/types.d.ts.map +1 -1
  475. package/dist/unplugin/types.js +22 -18
  476. package/dist/unplugin/types.js.map +1 -1
  477. package/dist/unplugin/virtual.d.ts +11 -8
  478. package/dist/unplugin/virtual.d.ts.map +1 -1
  479. package/dist/unplugin/virtual.js +65 -83
  480. package/dist/unplugin/virtual.js.map +1 -1
  481. package/dist/unplugin/vite.d.ts +5 -2
  482. package/dist/unplugin/vite.d.ts.map +1 -1
  483. package/dist/unplugin/vite.js +5 -1
  484. package/dist/unplugin/vite.js.map +1 -1
  485. package/dist/unplugin/webpack.d.ts +5 -2
  486. package/dist/unplugin/webpack.d.ts.map +1 -1
  487. package/dist/unplugin/webpack.js +5 -1
  488. package/dist/unplugin/webpack.js.map +1 -1
  489. package/package.json +23 -14
  490. package/dist/cli/index.d.ts.map +0 -1
  491. package/dist/core/extract/types.js.map +0 -1
  492. package/dist/core/types.js.map +0 -1
  493. package/dist/index.d.ts.map +0 -1
  494. package/dist/index.js.map +0 -1
@@ -1,8 +1,5 @@
1
- /**
2
- * Shared CompiledSchema<T> IIFE generation.
3
- * Used by both CLI emitter and unplugin transform.
4
- */
5
- import type { CompiledSchemaInfo } from "./pipeline.js";
1
+ import { CompiledSchemaInfo } from "./pipeline.js";
2
+ //#region src/core/iife.d.ts
6
3
  /**
7
4
  * Import statement required by generateIIFE output (references
8
5
  * __zodCompilerConfig). `core` is bound for $ZodAsyncError: a superRefine
@@ -10,7 +7,7 @@ import type { CompiledSchemaInfo } from "./pipeline.js";
10
7
  * detectable by the promise it returns, at which point zod's own synchronous
11
8
  * parse raises (see ZC_SR_DECL).
12
9
  */
13
- export declare const ZOD_CONFIG_IMPORT = "import { config as __zodCompilerConfig, core as __zcCore, ZodRealError as __zcZodError } from \"zod\";";
10
+ declare const ZOD_CONFIG_IMPORT = "import { config as __zodCompilerConfig, core as __zcCore, ZodRealError as __zcZodError } from \"zod\";";
14
11
  /**
15
12
  * File-level `__zcMsg` declaration (must appear once after ZOD_CONFIG_IMPORT):
16
13
  * the message an issue gets when nothing was baked into it at build time.
@@ -30,7 +27,7 @@ export declare const ZOD_CONFIG_IMPORT = "import { config as __zodCompilerConfig
30
27
  *
31
28
  * Only ever called while building an error, never on a successful parse.
32
29
  */
33
- export declare const ZOD_MSG_DECLARATION: string;
30
+ declare const ZOD_MSG_DECLARATION: string;
34
31
  /**
35
32
  * Shared failure-result for __zcFin / __zcFinD. Inline mode (CLI emitter)
36
33
  * declares it once per compiled file; lean mode (all unplugin bundlers) declares
@@ -57,10 +54,10 @@ export declare const ZOD_MSG_DECLARATION: string;
57
54
  * trace) — stays deferred inside the cached accessor exactly as before, since
58
55
  * the issues array is observable solely through `.error`.
59
56
  */
60
- export declare const FAIL_CLASS_DECL: string;
57
+ declare const FAIL_CLASS_DECL: string;
61
58
  /** Eager finalizer (mutation / partial-fast-path schemas): issues already
62
59
  * collected in `e`; success short-circuits to a plain result literal. */
63
- export declare const FIN_DECL = "function __zcFin(e,d){if(!e.length)return{success:true,data:d};return new __ZcFail(e,null,null);}";
60
+ declare const FIN_DECL = "function __zcFin(e,d){if(!e.length)return{success:true,data:d};return new __ZcFail(e,null,null);}";
64
61
  /**
65
62
  * Deferred-collection finalizer for Fast-Path-eligible schemas. When the
66
63
  * fast check fails, the ENTIRE slow path (the issue-collecting re-walk) is
@@ -83,7 +80,7 @@ export declare const FIN_DECL = "function __zcFin(e,d){if(!e.length)return{succe
83
80
  * mutated value (zod materializes at parse time). Same caveat class as the
84
81
  * documented __zcFin deferral.
85
82
  */
86
- export declare const FIN_DEFERRED_DECL = "function __zcFinD(f,inp){return new __ZcFail(null,f,inp);}";
83
+ declare const FIN_DEFERRED_DECL = "function __zcFinD(f,inp){return new __ZcFail(null,f,inp);}";
87
84
  /**
88
85
  * Compact-mode failure class — a lazy failure that delegates error reporting to
89
86
  * the ORIGINAL Zod schema's `safeParse`. Used by `output: "compact"`, where the
@@ -106,9 +103,9 @@ export declare const FIN_DEFERRED_DECL = "function __zcFinD(f,inp){return new __
106
103
  * re-wrap — zod already finalized it), so a delegated failure is exactly what
107
104
  * the unaltered schema would have produced.
108
105
  */
109
- export declare const FAILZ_CLASS_DECL: string;
106
+ declare const FAILZ_CLASS_DECL: string;
110
107
  /** Compact-mode finalizer: wrap a pristine bound safeParse + input into a lazy delegated failure. */
111
- export declare const FINZ_DECL = "function __zcFinZ(z,i){return new __ZcFailZ(z,i);}";
108
+ declare const FINZ_DECL = "function __zcFinZ(z,i){return new __ZcFailZ(z,i);}";
112
109
  /**
113
110
  * Validator factory. Inline mode (CLI emitter) declares it once per compiled
114
111
  * file; lean mode (all unplugin bundlers) exports it once per bundle from the
@@ -164,7 +161,7 @@ export declare const FINZ_DECL = "function __zcFinZ(z,i){return new __ZcFailZ(z,
164
161
  * redefines the slot as non-writable, so a second `__zcMkv` on the same schema
165
162
  * object — two exports aliasing one schema — would throw under ESM strict mode.
166
163
  */
167
- export declare const MK_VALIDATOR_DECL: string;
164
+ declare const MK_VALIDATOR_DECL: string;
168
165
  /**
169
166
  * Generate a `/* @__PURE__ * /` IIFE wrapping a compiled validator.
170
167
  *
@@ -173,7 +170,9 @@ export declare const MK_VALIDATOR_DECL: string;
173
170
  * @param schema
174
171
  * @param options
175
172
  */
176
- export declare function generateIIFE(schemaExpr: string, schema: CompiledSchemaInfo, options?: {
177
- zodCompat?: boolean | undefined;
173
+ declare function generateIIFE(schemaExpr: string, schema: CompiledSchemaInfo, options?: {
174
+ zodCompat?: boolean | undefined;
178
175
  }): string;
176
+ //#endregion
177
+ export { FAILZ_CLASS_DECL, FAIL_CLASS_DECL, FINZ_DECL, FIN_DECL, FIN_DEFERRED_DECL, MK_VALIDATOR_DECL, ZOD_CONFIG_IMPORT, ZOD_MSG_DECLARATION, generateIIFE };
179
178
  //# sourceMappingURL=iife.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"iife.d.ts","sourceRoot":"","sources":["../../src/core/iife.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAExD;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,2GAC0E,CAAC;AAEzG;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,mBAAmB,QAKH,CAAC;AAE9B;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,eAAe,QAMe,CAAC;AAE5C;yEACyE;AACzE,eAAO,MAAM,QAAQ,sGACgF,CAAC;AAEtG;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,iBAAiB,+DAA+D,CAAC;AAE9F;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,gBAAgB,QAG4B,CAAC;AAE1D,qGAAqG;AACrG,eAAO,MAAM,SAAS,uDAAuD,CAAC;AAE9E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AACH,eAAO,MAAM,iBAAiB,QAIhB,CAAC;AAUf;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAC1B,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,kBAAkB,EAC1B,OAAO,CAAC,EAAE;IAAE,SAAS,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;CAAE,GAC5C,MAAM,CAuBR"}
1
+ {"version":3,"file":"iife.d.ts","names":[],"sources":["../../src/core/iife.ts"],"mappings":";;;;;;;;;cAca;;;;;;;;;;;;;;;;;;;;cAsBA;;;;;;;;;;;;;;;;;;;;;;;;;;;cAiCA;;;cAUA;;;;;;;;;;;;;;;;;;;;;;;cAyBA;;;;;;;;;;;;;;;;;;;;;;;cAwBA;;cAMA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAyDA;;;;;;;;;iBAsBG,aACd,oBACA,QAAQ,oBACR;EAAY"}
package/dist/core/iife.js CHANGED
@@ -1,219 +1,195 @@
1
+ //#region src/core/iife.ts
1
2
  /**
2
- * Shared CompiledSchema<T> IIFE generation.
3
- * Used by both CLI emitter and unplugin transform.
4
- */
3
+ * Import statement required by generateIIFE output (references
4
+ * __zodCompilerConfig). `core` is bound for $ZodAsyncError: a superRefine
5
+ * callback is reached through zod's wrapper, so an async one is only
6
+ * detectable by the promise it returns, at which point zod's own synchronous
7
+ * parse raises (see ZC_SR_DECL).
8
+ */
9
+ const ZOD_CONFIG_IMPORT = "import { config as __zodCompilerConfig, core as __zcCore, ZodRealError as __zcZodError } from \"zod\";";
5
10
  /**
6
- * Import statement required by generateIIFE output (references
7
- * __zodCompilerConfig). `core` is bound for $ZodAsyncError: a superRefine
8
- * callback is reached through zod's wrapper, so an async one is only
9
- * detectable by the promise it returns, at which point zod's own synchronous
10
- * parse raises (see ZC_SR_DECL).
11
- */
12
- export const ZOD_CONFIG_IMPORT = 'import { config as __zodCompilerConfig, core as __zcCore, ZodRealError as __zcZodError } from "zod";';
11
+ * File-level `__zcMsg` declaration (must appear once after ZOD_CONFIG_IMPORT):
12
+ * the message an issue gets when nothing was baked into it at build time.
13
+ *
14
+ * Resolves zod's tail of `finalizeIssue` — `config.customError` then
15
+ * `config.localeError` then "Invalid input" — and does it PER CALL, because the
16
+ * config is mutable: `z.config({ localeError })` in an entry point runs after
17
+ * the schema modules it imports, so a value snapshotted at module init misses
18
+ * it. Reading a captured `localeError` alone also dropped `customError`
19
+ * outright, silently ignoring the global map most i18n setups install.
20
+ *
21
+ * The head of zod's chain — the schema's own `error` option — is baked into the
22
+ * issue at build time and short-circuits this. The one link that cannot be
23
+ * reproduced is a per-CALL `ctx.error`, which would have to travel through
24
+ * `safeParse`; that entry point sits at V8's inlining budget, where even an
25
+ * unused extra parameter measured ~12% on every parse.
26
+ *
27
+ * Only ever called while building an error, never on a successful parse.
28
+ */
29
+ const ZOD_MSG_DECLARATION = "function __zcUw(m){return typeof m===\"string\"?m:(m===undefined||m===null?undefined:m.message);}var __zcMsg=function(iss){var c=__zodCompilerConfig(),m;if(c.customError){m=__zcUw(c.customError(iss));if(m!==undefined&&m!==null)return m;}if(c.localeError){m=__zcUw(c.localeError(iss));if(m!==undefined&&m!==null)return m;}return \"Invalid input\";};";
13
30
  /**
14
- * File-level `__zcMsg` declaration (must appear once after ZOD_CONFIG_IMPORT):
15
- * the message an issue gets when nothing was baked into it at build time.
16
- *
17
- * Resolves zod's tail of `finalizeIssue` — `config.customError` then
18
- * `config.localeError` then "Invalid input" — and does it PER CALL, because the
19
- * config is mutable: `z.config({ localeError })` in an entry point runs after
20
- * the schema modules it imports, so a value snapshotted at module init misses
21
- * it. Reading a captured `localeError` alone also dropped `customError`
22
- * outright, silently ignoring the global map most i18n setups install.
23
- *
24
- * The head of zod's chain — the schema's own `error` option — is baked into the
25
- * issue at build time and short-circuits this. The one link that cannot be
26
- * reproduced is a per-CALL `ctx.error`, which would have to travel through
27
- * `safeParse`; that entry point sits at V8's inlining budget, where even an
28
- * unused extra parameter measured ~12% on every parse.
29
- *
30
- * Only ever called while building an error, never on a successful parse.
31
- */
32
- export const ZOD_MSG_DECLARATION = 'function __zcUw(m){return typeof m==="string"?m:(m===undefined||m===null?undefined:m.message);}' +
33
- "var __zcMsg=function(iss){var c=__zodCompilerConfig(),m;" +
34
- "if(c.customError){m=__zcUw(c.customError(iss));if(m!==undefined&&m!==null)return m;}" +
35
- "if(c.localeError){m=__zcUw(c.localeError(iss));if(m!==undefined&&m!==null)return m;}" +
36
- 'return "Invalid input";};';
37
- /**
38
- * Shared failure-result for __zcFin / __zcFinD. Inline mode (CLI emitter)
39
- * declares it once per compiled file; lean mode (all unplugin bundlers) declares
40
- * it once per bundle in the plugin-materialized runtime module (module-local —
41
- * generated code only ever references __zcFin/__zcFinD, never __ZcFail).
42
- *
43
- * Why a prototype getter and not `{success:false, get error(){...}}`: an object
44
- * literal with an inline accessor forces V8 down its slow accessor-defining
45
- * allocation path — ~110ns per failure, measured — which dominates the entire
46
- * invalid-input cost whenever callers never read `.error`. Hosting `error` on
47
- * the prototype turns each failure into a plain field-only instantiation (~2ns,
48
- * ~13x), with the lazy-cache semantics intact. (Trade-off: `error` is a
49
- * prototype accessor, so it no longer shows up in `Object.keys(result)` / spread
50
- * / JSON.stringify of the result wrapper — `.success`/`.error`/`.data` access,
51
- * destructuring, and `in` are unaffected.)
52
- *
53
- * One class serves both finalizers, so the instances share one hidden class:
54
- * __zcFin passes pre-collected issues in `_e` (with `_f===null`); __zcFinD
55
- * passes the hosted slow-walk in `_f` plus the input in `_i`, and the getter
56
- * runs the walk on first `.error` read. The whole finalization — locale fill
57
- * (__zcMsg applied ONLY when an issue carries no message, never overwriting a
58
- * baked-in custom/fallback message), input strip, and ZodError construction
59
- * (zod v4 JSON.stringifies every issue into `message` and captures a stack
60
- * trace) — stays deferred inside the cached accessor exactly as before, since
61
- * the issues array is observable solely through `.error`.
62
- */
63
- export const FAIL_CLASS_DECL = "function __ZcFail(e,f,i){this.success=false;this._e=e;this._f=f;this._i=i;this._c=undefined;}" +
64
- 'Object.defineProperty(__ZcFail.prototype,"error",{configurable:true,get:function(){' +
65
- "if(this._c)return this._c;" +
66
- "var e=this._f!==null?this._f(this._i):this._e;" +
67
- 'for(var i=0;i<e.length;i++){if(e[i].message===undefined&&typeof __zcMsg==="function")e[i].message=__zcMsg(e[i]);e[i].input=undefined;}' +
68
- "return this._c=new __zcZodError(e);}});";
31
+ * Shared failure-result for __zcFin / __zcFinD. Inline mode (CLI emitter)
32
+ * declares it once per compiled file; lean mode (all unplugin bundlers) declares
33
+ * it once per bundle in the plugin-materialized runtime module (module-local —
34
+ * generated code only ever references __zcFin/__zcFinD, never __ZcFail).
35
+ *
36
+ * Why a prototype getter and not `{success:false, get error(){...}}`: an object
37
+ * literal with an inline accessor forces V8 down its slow accessor-defining
38
+ * allocation path — ~110ns per failure, measured — which dominates the entire
39
+ * invalid-input cost whenever callers never read `.error`. Hosting `error` on
40
+ * the prototype turns each failure into a plain field-only instantiation (~2ns,
41
+ * ~13x), with the lazy-cache semantics intact. (Trade-off: `error` is a
42
+ * prototype accessor, so it no longer shows up in `Object.keys(result)` / spread
43
+ * / JSON.stringify of the result wrapper — `.success`/`.error`/`.data` access,
44
+ * destructuring, and `in` are unaffected.)
45
+ *
46
+ * One class serves both finalizers, so the instances share one hidden class:
47
+ * __zcFin passes pre-collected issues in `_e` (with `_f===null`); __zcFinD
48
+ * passes the hosted slow-walk in `_f` plus the input in `_i`, and the getter
49
+ * runs the walk on first `.error` read. The whole finalization — locale fill
50
+ * (__zcMsg applied ONLY when an issue carries no message, never overwriting a
51
+ * baked-in custom/fallback message), input strip, and ZodError construction
52
+ * (zod v4 JSON.stringifies every issue into `message` and captures a stack
53
+ * trace) — stays deferred inside the cached accessor exactly as before, since
54
+ * the issues array is observable solely through `.error`.
55
+ */
56
+ const FAIL_CLASS_DECL = "function __ZcFail(e,f,i){this.success=false;this._e=e;this._f=f;this._i=i;this._c=undefined;}Object.defineProperty(__ZcFail.prototype,\"error\",{configurable:true,get:function(){if(this._c)return this._c;var e=this._f!==null?this._f(this._i):this._e;for(var i=0;i<e.length;i++){if(e[i].message===undefined&&typeof __zcMsg===\"function\")e[i].message=__zcMsg(e[i]);e[i].input=undefined;}return this._c=new __zcZodError(e);}});";
69
57
  /** Eager finalizer (mutation / partial-fast-path schemas): issues already
70
- * collected in `e`; success short-circuits to a plain result literal. */
71
- export const FIN_DECL = "function __zcFin(e,d){if(!e.length)return{success:true,data:d};return new __ZcFail(e,null,null);}";
58
+ * collected in `e`; success short-circuits to a plain result literal. */
59
+ const FIN_DECL = "function __zcFin(e,d){if(!e.length)return{success:true,data:d};return new __ZcFail(e,null,null);}";
72
60
  /**
73
- * Deferred-collection finalizer for Fast-Path-eligible schemas. When the
74
- * fast check fails, the ENTIRE slow path (the issue-collecting re-walk) is
75
- * pushed into the cached `.error` accessor instead of running eagerly:
76
- * fast-eligible schemas never mutate, so the walk's only output is the
77
- * issues array, which is observable solely through `.error` — one step
78
- * further along the same lazy boundary `__zcFin` already established (locale
79
- * fill, input strip, ZodError construction). A failed safeParse whose
80
- * `.error` is never read costs the fast check alone.
81
- *
82
- * Takes the schema's HOSTED slow-walk function plus the input — NOT a
83
- * per-call closure: `__zcFinD(__sw_N, input)` allocates only the result
84
- * object, where `__zcFinD(function(){...})` paid a closure environment and
85
- * function object per failure. Hosting the walk also shrinks safeParse to
86
- * two statements, within V8's inlining budget (the success-path result
87
- * literal becomes escape-analyzable at monomorphic call sites).
88
- *
89
- * The walk re-reads `input` at `.error`-read time; a caller that mutates
90
- * the input between safeParse and reading `.error` sees issues for the
91
- * mutated value (zod materializes at parse time). Same caveat class as the
92
- * documented __zcFin deferral.
93
- */
94
- export const FIN_DEFERRED_DECL = "function __zcFinD(f,inp){return new __ZcFail(null,f,inp);}";
61
+ * Deferred-collection finalizer for Fast-Path-eligible schemas. When the
62
+ * fast check fails, the ENTIRE slow path (the issue-collecting re-walk) is
63
+ * pushed into the cached `.error` accessor instead of running eagerly:
64
+ * fast-eligible schemas never mutate, so the walk's only output is the
65
+ * issues array, which is observable solely through `.error` — one step
66
+ * further along the same lazy boundary `__zcFin` already established (locale
67
+ * fill, input strip, ZodError construction). A failed safeParse whose
68
+ * `.error` is never read costs the fast check alone.
69
+ *
70
+ * Takes the schema's HOSTED slow-walk function plus the input — NOT a
71
+ * per-call closure: `__zcFinD(__sw_N, input)` allocates only the result
72
+ * object, where `__zcFinD(function(){...})` paid a closure environment and
73
+ * function object per failure. Hosting the walk also shrinks safeParse to
74
+ * two statements, within V8's inlining budget (the success-path result
75
+ * literal becomes escape-analyzable at monomorphic call sites).
76
+ *
77
+ * The walk re-reads `input` at `.error`-read time; a caller that mutates
78
+ * the input between safeParse and reading `.error` sees issues for the
79
+ * mutated value (zod materializes at parse time). Same caveat class as the
80
+ * documented __zcFin deferral.
81
+ */
82
+ const FIN_DEFERRED_DECL = "function __zcFinD(f,inp){return new __ZcFail(null,f,inp);}";
95
83
  /**
96
- * Compact-mode failure class — a lazy failure that delegates error reporting to
97
- * the ORIGINAL Zod schema's `safeParse`. Used by `output: "compact"`, where the
98
- * compiled slow walk is dropped entirely: a mutation-free schema's fast check
99
- * is the only generated validation, and on a fast-check failure the cold error
100
- * path is produced by the retained Zod schema itself (`zod` is the source of
101
- * truth, so the issues are byte-identical — no second validation engine).
102
- *
103
- * `_z` is the schema's PRISTINE bound safeParse (`__rf[N].safeParse.bind(...)`,
104
- * captured pre-`__zcMkv` by emitRfDelegate — see context.ts — so it is zod's
105
- * own implementation, never the compiled delegate, avoiding infinite
106
- * recursion). The zod parse is deferred until `.error` is read and cached, so
107
- * the common `safeParse(x).success`/`.is(x)` checks on invalid input cost only
108
- * the fast check (zod never runs) — the same deferral boundary `__zcFinD`
109
- * establishes for the compiled slow walk. Sound because compact mode is gated
110
- * on a TOTAL fast path: `fc(input) === false` ⟹ zod rejects, so `success:false`
111
- * holds without consulting zod.
112
- *
113
- * The getter returns zod's OWN ZodError verbatim (no locale fill / input strip /
114
- * re-wrap — zod already finalized it), so a delegated failure is exactly what
115
- * the unaltered schema would have produced.
116
- */
117
- export const FAILZ_CLASS_DECL = "function __ZcFailZ(z,i){this.success=false;this._z=z;this._i=i;this._c=undefined;}" +
118
- 'Object.defineProperty(__ZcFailZ.prototype,"error",{configurable:true,get:function(){' +
119
- "return this._c||(this._c=this._z(this._i).error);}});";
84
+ * Compact-mode failure class — a lazy failure that delegates error reporting to
85
+ * the ORIGINAL Zod schema's `safeParse`. Used by `output: "compact"`, where the
86
+ * compiled slow walk is dropped entirely: a mutation-free schema's fast check
87
+ * is the only generated validation, and on a fast-check failure the cold error
88
+ * path is produced by the retained Zod schema itself (`zod` is the source of
89
+ * truth, so the issues are byte-identical — no second validation engine).
90
+ *
91
+ * `_z` is the schema's PRISTINE bound safeParse (`__rf[N].safeParse.bind(...)`,
92
+ * captured pre-`__zcMkv` by emitRfDelegate — see context.ts — so it is zod's
93
+ * own implementation, never the compiled delegate, avoiding infinite
94
+ * recursion). The zod parse is deferred until `.error` is read and cached, so
95
+ * the common `safeParse(x).success`/`.is(x)` checks on invalid input cost only
96
+ * the fast check (zod never runs) — the same deferral boundary `__zcFinD`
97
+ * establishes for the compiled slow walk. Sound because compact mode is gated
98
+ * on a TOTAL fast path: `fc(input) === false` ⟹ zod rejects, so `success:false`
99
+ * holds without consulting zod.
100
+ *
101
+ * The getter returns zod's OWN ZodError verbatim (no locale fill / input strip /
102
+ * re-wrap — zod already finalized it), so a delegated failure is exactly what
103
+ * the unaltered schema would have produced.
104
+ */
105
+ const FAILZ_CLASS_DECL = "function __ZcFailZ(z,i){this.success=false;this._z=z;this._i=i;this._c=undefined;}Object.defineProperty(__ZcFailZ.prototype,\"error\",{configurable:true,get:function(){return this._c||(this._c=this._z(this._i).error);}});";
120
106
  /** Compact-mode finalizer: wrap a pristine bound safeParse + input into a lazy delegated failure. */
121
- export const FINZ_DECL = "function __zcFinZ(z,i){return new __ZcFailZ(z,i);}";
107
+ const FINZ_DECL = "function __zcFinZ(z,i){return new __ZcFailZ(z,i);}";
122
108
  /**
123
- * Validator factory. Inline mode (CLI emitter) declares it once per compiled
124
- * file; lean mode (all unplugin bundlers) exports it once per bundle from the
125
- * plugin-materialized runtime module — generated code never imports it from
126
- * the zod-compiler package itself, so zod-compiler stays a devDependency and
127
- * the helper set is always version-locked to the codegen that calls it.
128
- * Wraps a safeParse function into the CompiledSchema interface.
129
- *
130
- * IDENTITY-PRESERVING: with zodCompat (schema != null) the compiled
131
- * parse/safeParse/parseAsync/safeParseAsync are installed as OWN properties
132
- * on the original schema object, which is returned as-is. zod v4 keys
133
- * several APIs on object identity — toJSONSchema's ctx.seen registers the
134
- * object it is handed while each processor closure captures the original
135
- * inst (a wrapper crashes `optionalProcessor` with "Cannot set properties
136
- * of undefined (setting 'ref')" the moment a compiled schema is composed
137
- * into another schema), and globalRegistry/.meta() is a WeakMap keyed by
138
- * the schema instance (a wrapper silently loses OpenAPI titles/ids). An
139
- * Object.create wrapper breaks both; mutating the original breaks neither
140
- * (zod's internal parsing flows through _zod.run, never the public
141
- * methods, and derived schemas — .optional(), .extend() — are fresh
142
- * instances that fall back to plain zod). schema=null (zodCompat: false)
143
- * still produces a plain method-bag object.
144
- *
145
- * fc is the schema's hosted fast-check boolean function (null when no Fast
146
- * Path exists). parse()/parseAsync() try it first and return the input
147
- * directly on success: fc is small enough for V8 to inline, so the hot parse
148
- * path runs with zero allocations — calling fn would allocate an intermediate
149
- * SafeParseResult that escape analysis cannot remove (fn never inlines).
150
- * Fast-path-eligible schemas never mutate, so fc(input) ⟹ data === input.
151
- *
152
- * is is the TOTAL fast-check predicate (fc when the fast path is total, else
153
- * null). Installed as `.is()` — a zero-allocation boolean type guard. When
154
- * null (partial fast path or none) `.is()` derives from fn(input).success: a
155
- * partial fc can pass-through valid input but its `false` does not imply
156
- * rejection (a default/catch may still succeed), so it would be unsound as a
157
- * standalone guard.
158
- *
159
- * `~standard` is REPLACED, not merely preserved. Zod builds it lazily as
160
- * `validate: (v) => safeParse(inst, v)` — the core FUNCTION, which goes straight
161
- * to `inst._zod.run`. It never reads the schema's own `safeParse` property, so
162
- * installing the compiled one leaves this route entirely uncompiled: measured
163
- * 271.7 ns against the compiled 26.6 ns on the same schema, i.e. Standard Schema
164
- * consumers (tRPC, Hono, TanStack) were getting plain Zod.
165
- *
166
- * Zod's own validate is captured first and kept as the throw path: it catches a
167
- * synchronous throw and retries through `safeParseAsync`, which is how an async
168
- * refinement resolves and how a throwing check surfaces as a rejected promise
169
- * rather than a synchronous throw. The compiled validator cannot reproduce that
170
- * (async schemas delegate to Zod anyway), so deferring to the original is both
171
- * simpler and exact.
172
- *
173
- * Installed with defineProperty rather than assignment: Zod's lazy setter
174
- * redefines the slot as non-writable, so a second `__zcMkv` on the same schema
175
- * object — two exports aliasing one schema — would throw under ESM strict mode.
176
- */
177
- export const MK_VALIDATOR_DECL = "function __zcMkv(fn,schema,fc,is){var w=schema||{};w.parse=fc?function(input){if(fc(input))return input;var r=fn(input);if(r.success)return r.data;throw r.error;}:function(input){var r=fn(input);if(r.success)return r.data;throw r.error;};w.safeParse=fn;w.safeParseAsync=function(input){return Promise.resolve(fn(input));};w.parseAsync=fc?function(input){if(fc(input))return Promise.resolve(input);var r=fn(input);if(r.success)return Promise.resolve(r.data);return Promise.reject(r.error);}:function(input){var r=fn(input);if(r.success)return Promise.resolve(r.data);return Promise.reject(r.error);};w.is=is||function(input){return fn(input).success;};" +
178
- 'var s=w["~standard"],zv=s&&s.validate;' +
179
- 'Object.defineProperty(w,"~standard",{configurable:true,value:{version:1,vendor:(s&&s.vendor)||"zod",validate:function(input){var r;try{if(fc&&fc(input))return{value:input};r=fn(input);}catch(e){if(zv)return zv(input);throw e;}return r.success?{value:r.data}:{issues:r.error.issues};}}});' +
180
- "return w;}";
109
+ * Validator factory. Inline mode (CLI emitter) declares it once per compiled
110
+ * file; lean mode (all unplugin bundlers) exports it once per bundle from the
111
+ * plugin-materialized runtime module — generated code never imports it from
112
+ * the zod-compiler package itself, so zod-compiler stays a devDependency and
113
+ * the helper set is always version-locked to the codegen that calls it.
114
+ * Wraps a safeParse function into the CompiledSchema interface.
115
+ *
116
+ * IDENTITY-PRESERVING: with zodCompat (schema != null) the compiled
117
+ * parse/safeParse/parseAsync/safeParseAsync are installed as OWN properties
118
+ * on the original schema object, which is returned as-is. zod v4 keys
119
+ * several APIs on object identity — toJSONSchema's ctx.seen registers the
120
+ * object it is handed while each processor closure captures the original
121
+ * inst (a wrapper crashes `optionalProcessor` with "Cannot set properties
122
+ * of undefined (setting 'ref')" the moment a compiled schema is composed
123
+ * into another schema), and globalRegistry/.meta() is a WeakMap keyed by
124
+ * the schema instance (a wrapper silently loses OpenAPI titles/ids). An
125
+ * Object.create wrapper breaks both; mutating the original breaks neither
126
+ * (zod's internal parsing flows through _zod.run, never the public
127
+ * methods, and derived schemas — .optional(), .extend() — are fresh
128
+ * instances that fall back to plain zod). schema=null (zodCompat: false)
129
+ * still produces a plain method-bag object.
130
+ *
131
+ * fc is the schema's hosted fast-check boolean function (null when no Fast
132
+ * Path exists). parse()/parseAsync() try it first and return the input
133
+ * directly on success: fc is small enough for V8 to inline, so the hot parse
134
+ * path runs with zero allocations — calling fn would allocate an intermediate
135
+ * SafeParseResult that escape analysis cannot remove (fn never inlines).
136
+ * Fast-path-eligible schemas never mutate, so fc(input) ⟹ data === input.
137
+ *
138
+ * is is the TOTAL fast-check predicate (fc when the fast path is total, else
139
+ * null). Installed as `.is()` — a zero-allocation boolean type guard. When
140
+ * null (partial fast path or none) `.is()` derives from fn(input).success: a
141
+ * partial fc can pass-through valid input but its `false` does not imply
142
+ * rejection (a default/catch may still succeed), so it would be unsound as a
143
+ * standalone guard.
144
+ *
145
+ * `~standard` is REPLACED, not merely preserved. Zod builds it lazily as
146
+ * `validate: (v) => safeParse(inst, v)` — the core FUNCTION, which goes straight
147
+ * to `inst._zod.run`. It never reads the schema's own `safeParse` property, so
148
+ * installing the compiled one leaves this route entirely uncompiled: measured
149
+ * 271.7 ns against the compiled 26.6 ns on the same schema, i.e. Standard Schema
150
+ * consumers (tRPC, Hono, TanStack) were getting plain Zod.
151
+ *
152
+ * Zod's own validate is captured first and kept as the throw path: it catches a
153
+ * synchronous throw and retries through `safeParseAsync`, which is how an async
154
+ * refinement resolves and how a throwing check surfaces as a rejected promise
155
+ * rather than a synchronous throw. The compiled validator cannot reproduce that
156
+ * (async schemas delegate to Zod anyway), so deferring to the original is both
157
+ * simpler and exact.
158
+ *
159
+ * Installed with defineProperty rather than assignment: Zod's lazy setter
160
+ * redefines the slot as non-writable, so a second `__zcMkv` on the same schema
161
+ * object — two exports aliasing one schema — would throw under ESM strict mode.
162
+ */
163
+ const MK_VALIDATOR_DECL = "function __zcMkv(fn,schema,fc,is){var w=schema||{};w.parse=fc?function(input){if(fc(input))return input;var r=fn(input);if(r.success)return r.data;throw r.error;}:function(input){var r=fn(input);if(r.success)return r.data;throw r.error;};w.safeParse=fn;w.safeParseAsync=function(input){return Promise.resolve(fn(input));};w.parseAsync=fc?function(input){if(fc(input))return Promise.resolve(input);var r=fn(input);if(r.success)return Promise.resolve(r.data);return Promise.reject(r.error);}:function(input){var r=fn(input);if(r.success)return Promise.resolve(r.data);return Promise.reject(r.error);};w.is=is||function(input){return fn(input).success;};var s=w[\"~standard\"],zv=s&&s.validate;Object.defineProperty(w,\"~standard\",{configurable:true,value:{version:1,vendor:(s&&s.vendor)||\"zod\",validate:function(input){var r;try{if(fc&&fc(input))return{value:input};r=fn(input);}catch(e){if(zv)return zv(input);throw e;}return r.success?{value:r.data}:{issues:r.error.issues};}}});return w;}";
181
164
  function extractFunctionName(functionDef) {
182
- const match = /^function\s+(\w+)\s*\(/.exec(functionDef);
183
- if (!match?.[1]) {
184
- throw new Error("Cannot extract function name from generated code");
185
- }
186
- return match[1];
165
+ const match = /^function\s+(\w+)\s*\(/.exec(functionDef);
166
+ if (!match?.[1]) throw new Error("Cannot extract function name from generated code");
167
+ return match[1];
187
168
  }
188
169
  /**
189
- * Generate a `/* @__PURE__ * /` IIFE wrapping a compiled validator.
190
- *
191
- * @param schemaExpr - Expression resolving to the original Zod schema
192
- * (e.g. `"UserSchema"` in unplugin, `"(__src_X as any).schema"` in CLI)
193
- * @param schema
194
- * @param options
195
- */
196
- export function generateIIFE(schemaExpr, schema, options) {
197
- const { codegenResult, refEntries } = schema;
198
- const fnName = extractFunctionName(codegenResult.functionDef);
199
- const zodCompat = options?.zodCompat !== false;
200
- const schemaArg = zodCompat ? schemaExpr : "null";
201
- const fcArg = codegenResult.fastFnName ?? "null";
202
- // `.is()` gets the fast-check directly only when it is a total predicate;
203
- // partial/none falls back to safeParse().success inside __zcMkv. A rebuilding
204
- // schema has no by-reference `fc` but still names its predicate separately.
205
- const isArg = codegenResult.isFnName ?? (codegenResult.fastTotal ? fcArg : "null");
206
- return [
207
- "/* @__PURE__ */ (() => {",
208
- ...(refEntries.length > 0
209
- ? [`var __rf=[${refEntries.map((fb) => `${schemaExpr}${fb.accessPath}`).join(",")}];`]
210
- : []),
211
- ...codegenResult.code
212
- .split("\n")
213
- .filter((l) => l.trim() !== "" && l.trim() !== "/* zod-compiler */"),
214
- codegenResult.functionDef,
215
- `return __zcMkv(${fnName},${schemaArg},${fcArg},${isArg});`,
216
- "})()",
217
- ].join("\n");
170
+ * Generate a `/* @__PURE__ * /` IIFE wrapping a compiled validator.
171
+ *
172
+ * @param schemaExpr - Expression resolving to the original Zod schema
173
+ * (e.g. `"UserSchema"` in unplugin, `"(__src_X as any).schema"` in CLI)
174
+ * @param schema
175
+ * @param options
176
+ */
177
+ function generateIIFE(schemaExpr, schema, options) {
178
+ const { codegenResult, refEntries } = schema;
179
+ const fnName = extractFunctionName(codegenResult.functionDef);
180
+ const schemaArg = options?.zodCompat !== false ? schemaExpr : "null";
181
+ const fcArg = codegenResult.fastFnName ?? "null";
182
+ const isArg = codegenResult.isFnName ?? (codegenResult.fastTotal ? fcArg : "null");
183
+ return [
184
+ "/* @__PURE__ */ (() => {",
185
+ ...refEntries.length > 0 ? [`var __rf=[${refEntries.map((fb) => `${schemaExpr}${fb.accessPath}`).join(",")}];`] : [],
186
+ ...codegenResult.code.split("\n").filter((l) => l.trim() !== "" && l.trim() !== "/* zod-compiler */"),
187
+ codegenResult.functionDef,
188
+ `return __zcMkv(${fnName},${schemaArg},${fcArg},${isArg});`,
189
+ "})()"
190
+ ].join("\n");
218
191
  }
192
+ //#endregion
193
+ export { FAILZ_CLASS_DECL, FAIL_CLASS_DECL, FINZ_DECL, FIN_DECL, FIN_DEFERRED_DECL, MK_VALIDATOR_DECL, ZOD_CONFIG_IMPORT, ZOD_MSG_DECLARATION, generateIIFE };
194
+
219
195
  //# sourceMappingURL=iife.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"iife.js","sourceRoot":"","sources":["../../src/core/iife.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAC5B,sGAAsG,CAAC;AAEzG;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAC9B,iGAAiG;IACjG,0DAA0D;IAC1D,sFAAsF;IACtF,sFAAsF;IACtF,2BAA2B,CAAC;AAE9B;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,CAAC,MAAM,eAAe,GAC1B,+FAA+F;IAC/F,qFAAqF;IACrF,4BAA4B;IAC5B,gDAAgD;IAChD,wIAAwI;IACxI,yCAAyC,CAAC;AAE5C;yEACyE;AACzE,MAAM,CAAC,MAAM,QAAQ,GACnB,mGAAmG,CAAC;AAEtG;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,4DAA4D,CAAC;AAE9F;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAC3B,oFAAoF;IACpF,sFAAsF;IACtF,uDAAuD,CAAC;AAE1D,qGAAqG;AACrG,MAAM,CAAC,MAAM,SAAS,GAAG,oDAAoD,CAAC;AAE9E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAC5B,6oBAA6oB;IAC7oB,wCAAwC;IACxC,iSAAiS;IACjS,YAAY,CAAC;AAEf,SAAS,mBAAmB,CAAC,WAAmB;IAC9C,MAAM,KAAK,GAAG,wBAAwB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACzD,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;IACtE,CAAC;IACD,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAC1B,UAAkB,EAClB,MAA0B,EAC1B,OAA6C;IAE7C,MAAM,EAAE,aAAa,EAAE,UAAU,EAAE,GAAG,MAAM,CAAC;IAC7C,MAAM,MAAM,GAAG,mBAAmB,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC;IAC9D,MAAM,SAAS,GAAG,OAAO,EAAE,SAAS,KAAK,KAAK,CAAC;IAC/C,MAAM,SAAS,GAAG,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC;IAClD,MAAM,KAAK,GAAG,aAAa,CAAC,UAAU,IAAI,MAAM,CAAC;IACjD,0EAA0E;IAC1E,8EAA8E;IAC9E,4EAA4E;IAC5E,MAAM,KAAK,GAAG,aAAa,CAAC,QAAQ,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IAEnF,OAAO;QACL,0BAA0B;QAC1B,GAAG,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC;YACvB,CAAC,CAAC,CAAC,aAAa,UAAU,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,UAAU,GAAG,EAAE,CAAC,UAAU,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC;YACtF,CAAC,CAAC,EAAE,CAAC;QACP,GAAG,aAAa,CAAC,IAAI;aAClB,KAAK,CAAC,IAAI,CAAC;aACX,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC,IAAI,EAAE,KAAK,oBAAoB,CAAC;QACtE,aAAa,CAAC,WAAW;QACzB,kBAAkB,MAAM,IAAI,SAAS,IAAI,KAAK,IAAI,KAAK,IAAI;QAC3D,MAAM;KACP,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC"}
1
+ {"version":3,"file":"iife.js","names":[],"sources":["../../src/core/iife.ts"],"sourcesContent":["/**\n * Shared CompiledSchema<T> IIFE generation.\n * Used by both CLI emitter and unplugin transform.\n */\n\nimport type { CompiledSchemaInfo } from \"./pipeline.js\";\n\n/**\n * Import statement required by generateIIFE output (references\n * __zodCompilerConfig). `core` is bound for $ZodAsyncError: a superRefine\n * callback is reached through zod's wrapper, so an async one is only\n * detectable by the promise it returns, at which point zod's own synchronous\n * parse raises (see ZC_SR_DECL).\n */\nexport const ZOD_CONFIG_IMPORT =\n 'import { config as __zodCompilerConfig, core as __zcCore, ZodRealError as __zcZodError } from \"zod\";';\n\n/**\n * File-level `__zcMsg` declaration (must appear once after ZOD_CONFIG_IMPORT):\n * the message an issue gets when nothing was baked into it at build time.\n *\n * Resolves zod's tail of `finalizeIssue` — `config.customError` then\n * `config.localeError` then \"Invalid input\" — and does it PER CALL, because the\n * config is mutable: `z.config({ localeError })` in an entry point runs after\n * the schema modules it imports, so a value snapshotted at module init misses\n * it. Reading a captured `localeError` alone also dropped `customError`\n * outright, silently ignoring the global map most i18n setups install.\n *\n * The head of zod's chain — the schema's own `error` option — is baked into the\n * issue at build time and short-circuits this. The one link that cannot be\n * reproduced is a per-CALL `ctx.error`, which would have to travel through\n * `safeParse`; that entry point sits at V8's inlining budget, where even an\n * unused extra parameter measured ~12% on every parse.\n *\n * Only ever called while building an error, never on a successful parse.\n */\nexport const ZOD_MSG_DECLARATION =\n 'function __zcUw(m){return typeof m===\"string\"?m:(m===undefined||m===null?undefined:m.message);}' +\n \"var __zcMsg=function(iss){var c=__zodCompilerConfig(),m;\" +\n \"if(c.customError){m=__zcUw(c.customError(iss));if(m!==undefined&&m!==null)return m;}\" +\n \"if(c.localeError){m=__zcUw(c.localeError(iss));if(m!==undefined&&m!==null)return m;}\" +\n 'return \"Invalid input\";};';\n\n/**\n * Shared failure-result for __zcFin / __zcFinD. Inline mode (CLI emitter)\n * declares it once per compiled file; lean mode (all unplugin bundlers) declares\n * it once per bundle in the plugin-materialized runtime module (module-local —\n * generated code only ever references __zcFin/__zcFinD, never __ZcFail).\n *\n * Why a prototype getter and not `{success:false, get error(){...}}`: an object\n * literal with an inline accessor forces V8 down its slow accessor-defining\n * allocation path — ~110ns per failure, measured — which dominates the entire\n * invalid-input cost whenever callers never read `.error`. Hosting `error` on\n * the prototype turns each failure into a plain field-only instantiation (~2ns,\n * ~13x), with the lazy-cache semantics intact. (Trade-off: `error` is a\n * prototype accessor, so it no longer shows up in `Object.keys(result)` / spread\n * / JSON.stringify of the result wrapper — `.success`/`.error`/`.data` access,\n * destructuring, and `in` are unaffected.)\n *\n * One class serves both finalizers, so the instances share one hidden class:\n * __zcFin passes pre-collected issues in `_e` (with `_f===null`); __zcFinD\n * passes the hosted slow-walk in `_f` plus the input in `_i`, and the getter\n * runs the walk on first `.error` read. The whole finalization — locale fill\n * (__zcMsg applied ONLY when an issue carries no message, never overwriting a\n * baked-in custom/fallback message), input strip, and ZodError construction\n * (zod v4 JSON.stringifies every issue into `message` and captures a stack\n * trace) — stays deferred inside the cached accessor exactly as before, since\n * the issues array is observable solely through `.error`.\n */\nexport const FAIL_CLASS_DECL =\n \"function __ZcFail(e,f,i){this.success=false;this._e=e;this._f=f;this._i=i;this._c=undefined;}\" +\n 'Object.defineProperty(__ZcFail.prototype,\"error\",{configurable:true,get:function(){' +\n \"if(this._c)return this._c;\" +\n \"var e=this._f!==null?this._f(this._i):this._e;\" +\n 'for(var i=0;i<e.length;i++){if(e[i].message===undefined&&typeof __zcMsg===\"function\")e[i].message=__zcMsg(e[i]);e[i].input=undefined;}' +\n \"return this._c=new __zcZodError(e);}});\";\n\n/** Eager finalizer (mutation / partial-fast-path schemas): issues already\n * collected in `e`; success short-circuits to a plain result literal. */\nexport const FIN_DECL =\n \"function __zcFin(e,d){if(!e.length)return{success:true,data:d};return new __ZcFail(e,null,null);}\";\n\n/**\n * Deferred-collection finalizer for Fast-Path-eligible schemas. When the\n * fast check fails, the ENTIRE slow path (the issue-collecting re-walk) is\n * pushed into the cached `.error` accessor instead of running eagerly:\n * fast-eligible schemas never mutate, so the walk's only output is the\n * issues array, which is observable solely through `.error` — one step\n * further along the same lazy boundary `__zcFin` already established (locale\n * fill, input strip, ZodError construction). A failed safeParse whose\n * `.error` is never read costs the fast check alone.\n *\n * Takes the schema's HOSTED slow-walk function plus the input — NOT a\n * per-call closure: `__zcFinD(__sw_N, input)` allocates only the result\n * object, where `__zcFinD(function(){...})` paid a closure environment and\n * function object per failure. Hosting the walk also shrinks safeParse to\n * two statements, within V8's inlining budget (the success-path result\n * literal becomes escape-analyzable at monomorphic call sites).\n *\n * The walk re-reads `input` at `.error`-read time; a caller that mutates\n * the input between safeParse and reading `.error` sees issues for the\n * mutated value (zod materializes at parse time). Same caveat class as the\n * documented __zcFin deferral.\n */\nexport const FIN_DEFERRED_DECL = \"function __zcFinD(f,inp){return new __ZcFail(null,f,inp);}\";\n\n/**\n * Compact-mode failure class — a lazy failure that delegates error reporting to\n * the ORIGINAL Zod schema's `safeParse`. Used by `output: \"compact\"`, where the\n * compiled slow walk is dropped entirely: a mutation-free schema's fast check\n * is the only generated validation, and on a fast-check failure the cold error\n * path is produced by the retained Zod schema itself (`zod` is the source of\n * truth, so the issues are byte-identical — no second validation engine).\n *\n * `_z` is the schema's PRISTINE bound safeParse (`__rf[N].safeParse.bind(...)`,\n * captured pre-`__zcMkv` by emitRfDelegate — see context.ts — so it is zod's\n * own implementation, never the compiled delegate, avoiding infinite\n * recursion). The zod parse is deferred until `.error` is read and cached, so\n * the common `safeParse(x).success`/`.is(x)` checks on invalid input cost only\n * the fast check (zod never runs) — the same deferral boundary `__zcFinD`\n * establishes for the compiled slow walk. Sound because compact mode is gated\n * on a TOTAL fast path: `fc(input) === false` ⟹ zod rejects, so `success:false`\n * holds without consulting zod.\n *\n * The getter returns zod's OWN ZodError verbatim (no locale fill / input strip /\n * re-wrap — zod already finalized it), so a delegated failure is exactly what\n * the unaltered schema would have produced.\n */\nexport const FAILZ_CLASS_DECL =\n \"function __ZcFailZ(z,i){this.success=false;this._z=z;this._i=i;this._c=undefined;}\" +\n 'Object.defineProperty(__ZcFailZ.prototype,\"error\",{configurable:true,get:function(){' +\n \"return this._c||(this._c=this._z(this._i).error);}});\";\n\n/** Compact-mode finalizer: wrap a pristine bound safeParse + input into a lazy delegated failure. */\nexport const FINZ_DECL = \"function __zcFinZ(z,i){return new __ZcFailZ(z,i);}\";\n\n/**\n * Validator factory. Inline mode (CLI emitter) declares it once per compiled\n * file; lean mode (all unplugin bundlers) exports it once per bundle from the\n * plugin-materialized runtime module — generated code never imports it from\n * the zod-compiler package itself, so zod-compiler stays a devDependency and\n * the helper set is always version-locked to the codegen that calls it.\n * Wraps a safeParse function into the CompiledSchema interface.\n *\n * IDENTITY-PRESERVING: with zodCompat (schema != null) the compiled\n * parse/safeParse/parseAsync/safeParseAsync are installed as OWN properties\n * on the original schema object, which is returned as-is. zod v4 keys\n * several APIs on object identity — toJSONSchema's ctx.seen registers the\n * object it is handed while each processor closure captures the original\n * inst (a wrapper crashes `optionalProcessor` with \"Cannot set properties\n * of undefined (setting 'ref')\" the moment a compiled schema is composed\n * into another schema), and globalRegistry/.meta() is a WeakMap keyed by\n * the schema instance (a wrapper silently loses OpenAPI titles/ids). An\n * Object.create wrapper breaks both; mutating the original breaks neither\n * (zod's internal parsing flows through _zod.run, never the public\n * methods, and derived schemas — .optional(), .extend() — are fresh\n * instances that fall back to plain zod). schema=null (zodCompat: false)\n * still produces a plain method-bag object.\n *\n * fc is the schema's hosted fast-check boolean function (null when no Fast\n * Path exists). parse()/parseAsync() try it first and return the input\n * directly on success: fc is small enough for V8 to inline, so the hot parse\n * path runs with zero allocations — calling fn would allocate an intermediate\n * SafeParseResult that escape analysis cannot remove (fn never inlines).\n * Fast-path-eligible schemas never mutate, so fc(input) ⟹ data === input.\n *\n * is is the TOTAL fast-check predicate (fc when the fast path is total, else\n * null). Installed as `.is()` — a zero-allocation boolean type guard. When\n * null (partial fast path or none) `.is()` derives from fn(input).success: a\n * partial fc can pass-through valid input but its `false` does not imply\n * rejection (a default/catch may still succeed), so it would be unsound as a\n * standalone guard.\n *\n * `~standard` is REPLACED, not merely preserved. Zod builds it lazily as\n * `validate: (v) => safeParse(inst, v)` — the core FUNCTION, which goes straight\n * to `inst._zod.run`. It never reads the schema's own `safeParse` property, so\n * installing the compiled one leaves this route entirely uncompiled: measured\n * 271.7 ns against the compiled 26.6 ns on the same schema, i.e. Standard Schema\n * consumers (tRPC, Hono, TanStack) were getting plain Zod.\n *\n * Zod's own validate is captured first and kept as the throw path: it catches a\n * synchronous throw and retries through `safeParseAsync`, which is how an async\n * refinement resolves and how a throwing check surfaces as a rejected promise\n * rather than a synchronous throw. The compiled validator cannot reproduce that\n * (async schemas delegate to Zod anyway), so deferring to the original is both\n * simpler and exact.\n *\n * Installed with defineProperty rather than assignment: Zod's lazy setter\n * redefines the slot as non-writable, so a second `__zcMkv` on the same schema\n * object — two exports aliasing one schema — would throw under ESM strict mode.\n */\nexport const MK_VALIDATOR_DECL =\n \"function __zcMkv(fn,schema,fc,is){var w=schema||{};w.parse=fc?function(input){if(fc(input))return input;var r=fn(input);if(r.success)return r.data;throw r.error;}:function(input){var r=fn(input);if(r.success)return r.data;throw r.error;};w.safeParse=fn;w.safeParseAsync=function(input){return Promise.resolve(fn(input));};w.parseAsync=fc?function(input){if(fc(input))return Promise.resolve(input);var r=fn(input);if(r.success)return Promise.resolve(r.data);return Promise.reject(r.error);}:function(input){var r=fn(input);if(r.success)return Promise.resolve(r.data);return Promise.reject(r.error);};w.is=is||function(input){return fn(input).success;};\" +\n 'var s=w[\"~standard\"],zv=s&&s.validate;' +\n 'Object.defineProperty(w,\"~standard\",{configurable:true,value:{version:1,vendor:(s&&s.vendor)||\"zod\",validate:function(input){var r;try{if(fc&&fc(input))return{value:input};r=fn(input);}catch(e){if(zv)return zv(input);throw e;}return r.success?{value:r.data}:{issues:r.error.issues};}}});' +\n \"return w;}\";\n\nfunction extractFunctionName(functionDef: string): string {\n const match = /^function\\s+(\\w+)\\s*\\(/.exec(functionDef);\n if (!match?.[1]) {\n throw new Error(\"Cannot extract function name from generated code\");\n }\n return match[1];\n}\n\n/**\n * Generate a `/* @__PURE__ * /` IIFE wrapping a compiled validator.\n *\n * @param schemaExpr - Expression resolving to the original Zod schema\n * (e.g. `\"UserSchema\"` in unplugin, `\"(__src_X as any).schema\"` in CLI)\n * @param schema\n * @param options\n */\nexport function generateIIFE(\n schemaExpr: string,\n schema: CompiledSchemaInfo,\n options?: { zodCompat?: boolean | undefined },\n): string {\n const { codegenResult, refEntries } = schema;\n const fnName = extractFunctionName(codegenResult.functionDef);\n const zodCompat = options?.zodCompat !== false;\n const schemaArg = zodCompat ? schemaExpr : \"null\";\n const fcArg = codegenResult.fastFnName ?? \"null\";\n // `.is()` gets the fast-check directly only when it is a total predicate;\n // partial/none falls back to safeParse().success inside __zcMkv. A rebuilding\n // schema has no by-reference `fc` but still names its predicate separately.\n const isArg = codegenResult.isFnName ?? (codegenResult.fastTotal ? fcArg : \"null\");\n\n return [\n \"/* @__PURE__ */ (() => {\",\n ...(refEntries.length > 0\n ? [`var __rf=[${refEntries.map((fb) => `${schemaExpr}${fb.accessPath}`).join(\",\")}];`]\n : []),\n ...codegenResult.code\n .split(\"\\n\")\n .filter((l) => l.trim() !== \"\" && l.trim() !== \"/* zod-compiler */\"),\n codegenResult.functionDef,\n `return __zcMkv(${fnName},${schemaArg},${fcArg},${isArg});`,\n \"})()\",\n ].join(\"\\n\");\n}\n"],"mappings":";;;;;;;;AAcA,MAAa,oBACX;;;;;;;;;;;;;;;;;;;;AAqBF,MAAa,sBACX;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCF,MAAa,kBACX;;;AASF,MAAa,WACX;;;;;;;;;;;;;;;;;;;;;;;AAwBF,MAAa,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;AAwBjC,MAAa,mBACX;;AAKF,MAAa,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyDzB,MAAa,oBACX;AAKF,SAAS,oBAAoB,aAA6B;CACxD,MAAM,QAAQ,yBAAyB,KAAK,WAAW;CACvD,IAAI,CAAC,QAAQ,IACX,MAAM,IAAI,MAAM,kDAAkD;CAEpE,OAAO,MAAM;AACf;;;;;;;;;AAUA,SAAgB,aACd,YACA,QACA,SACQ;CACR,MAAM,EAAE,eAAe,eAAe;CACtC,MAAM,SAAS,oBAAoB,cAAc,WAAW;CAE5D,MAAM,YADY,SAAS,cAAc,QACX,aAAa;CAC3C,MAAM,QAAQ,cAAc,cAAc;CAI1C,MAAM,QAAQ,cAAc,aAAa,cAAc,YAAY,QAAQ;CAE3E,OAAO;EACL;EACA,GAAI,WAAW,SAAS,IACpB,CAAC,aAAa,WAAW,KAAK,OAAO,GAAG,aAAa,GAAG,YAAY,CAAC,CAAC,KAAK,GAAG,EAAE,GAAG,IACnF,CAAC;EACL,GAAG,cAAc,KACd,MAAM,IAAI,CAAC,CACX,QAAQ,MAAM,EAAE,KAAK,MAAM,MAAM,EAAE,KAAK,MAAM,oBAAoB;EACrE,cAAc;EACd,kBAAkB,OAAO,GAAG,UAAU,GAAG,MAAM,GAAG,MAAM;EACxD;CACF,CAAC,CAAC,KAAK,IAAI;AACb"}