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
package/dist/jit.js CHANGED
@@ -1,245 +1,216 @@
1
- /**
2
- * Runtime compilation — the same extract → codegen pipeline the build plugin
3
- * runs, executed in-process and evaluated through `new Function`.
4
- *
5
- * The AOT paths (unplugin, CLI) need a build step to fire. Plenty of everyday
6
- * code has none: `tsx server.ts`, `node --experimental-strip-types`, a Jest
7
- * suite, a serverless handler bundled by someone else's toolchain, a library
8
- * that ships schemas to consumers. There `compile()` is a no-op and every parse
9
- * runs plain Zod. `jit()` closes that gap — one call, no build integration,
10
- * measured 3-25x on everyday schemas at ~0.1-0.2 ms of one-time compilation.
11
- *
12
- * Nothing here re-implements validation: {@link compileSchemas} and
13
- * {@link generateIIFE} are the exact modules the plugin and CLI use, so the
14
- * generated validator, its Zod parity and its performance are identical to what
15
- * a build would have emitted. The only difference is *when* the code is
16
- * produced.
17
- *
18
- * Compilation is LAZY by default: `jit()` installs accessors that compile on
19
- * the first read of a parse method and replace themselves with the compiled
20
- * ones. Importing a module of 500 schemas therefore costs nothing, and a
21
- * serverless invocation touching three of them pays for three.
22
- *
23
- * Runtime code generation is not always permitted — a strict CSP without
24
- * `unsafe-eval`, some edge runtimes. Zod v4 has the same constraint (its object
25
- * fast-pass is itself a `new Function`) and already exposes the two switches
26
- * for it: the `core.util.allowsEval` probe and `z.config({ jitless: true })`.
27
- * `jit()` honours both and degrades to plain Zod, so one setting governs both
28
- * compilers. Those targets are where the build plugin belongs anyway — it emits
29
- * the same validator with no runtime evaluation at all.
30
- */
31
- import { config as zodConfig, core as zodCore, ZodRealError } from "zod";
32
- import { FAIL_CLASS_DECL, FAILZ_CLASS_DECL, FIN_DECL, FIN_DEFERRED_DECL, FINZ_DECL, generateIIFE, MK_VALIDATOR_DECL, ZOD_MSG_DECLARATION, } from "./core/iife.js";
1
+ import { FAILZ_CLASS_DECL, FAIL_CLASS_DECL, FINZ_DECL, FIN_DECL, FIN_DEFERRED_DECL, MK_VALIDATOR_DECL, ZOD_MSG_DECLARATION, generateIIFE } from "./core/iife.js";
33
2
  import { compileSchemas } from "./core/pipeline.js";
3
+ import { ZodRealError, config, core } from "zod";
4
+ //#region src/jit.ts
5
+ /**
6
+ * Runtime compilation — the same extract → codegen pipeline the build plugin
7
+ * runs, executed in-process and evaluated through `new Function`.
8
+ *
9
+ * The AOT paths (unplugin, CLI) need a build step to fire. Plenty of everyday
10
+ * code has none: `tsx server.ts`, `node --experimental-strip-types`, a Jest
11
+ * suite, a serverless handler bundled by someone else's toolchain, a library
12
+ * that ships schemas to consumers. There `compile()` is a no-op and every parse
13
+ * runs plain Zod. `jit()` closes that gap — one call, no build integration,
14
+ * measured 3-25x on everyday schemas at ~0.1-0.2 ms of one-time compilation.
15
+ *
16
+ * Nothing here re-implements validation: {@link compileSchemas} and
17
+ * {@link generateIIFE} are the exact modules the plugin and CLI use, so the
18
+ * generated validator, its Zod parity and its performance are identical to what
19
+ * a build would have emitted. The only difference is *when* the code is
20
+ * produced.
21
+ *
22
+ * Compilation is LAZY by default: `jit()` installs accessors that compile on
23
+ * the first read of a parse method and replace themselves with the compiled
24
+ * ones. Importing a module of 500 schemas therefore costs nothing, and a
25
+ * serverless invocation touching three of them pays for three.
26
+ *
27
+ * Runtime code generation is not always permitted — a strict CSP without
28
+ * `unsafe-eval`, some edge runtimes. Zod v4 has the same constraint (its object
29
+ * fast-pass is itself a `new Function`) and already exposes the two switches
30
+ * for it: the `core.util.allowsEval` probe and `z.config({ jitless: true })`.
31
+ * `jit()` honours both and degrades to plain Zod, so one setting governs both
32
+ * compilers. Those targets are where the build plugin belongs anyway — it emits
33
+ * the same validator with no runtime evaluation at all.
34
+ */
34
35
  /**
35
- * The declarations `ZOD_CONFIG_IMPORT` supplies to an emitted module, minus the
36
- * import itself — `zod`'s three bindings arrive as parameters instead, so the
37
- * evaluated code has no module scope to resolve. Byte-for-byte the same helper
38
- * source the CLI emitter writes into a `.compiled.ts`, so a JIT validator and
39
- * an AOT one share their entire runtime layer.
40
- */
36
+ * The declarations `ZOD_CONFIG_IMPORT` supplies to an emitted module, minus the
37
+ * import itself — `zod`'s three bindings arrive as parameters instead, so the
38
+ * evaluated code has no module scope to resolve. Byte-for-byte the same helper
39
+ * source the CLI emitter writes into a `.compiled.ts`, so a JIT validator and
40
+ * an AOT one share their entire runtime layer.
41
+ */
41
42
  const RUNTIME_PRELUDE = [
42
- ZOD_MSG_DECLARATION,
43
- FAIL_CLASS_DECL,
44
- MK_VALIDATOR_DECL,
45
- FIN_DECL,
46
- FIN_DEFERRED_DECL,
47
- FAILZ_CLASS_DECL,
48
- FINZ_DECL,
43
+ ZOD_MSG_DECLARATION,
44
+ FAIL_CLASS_DECL,
45
+ MK_VALIDATOR_DECL,
46
+ FIN_DECL,
47
+ FIN_DEFERRED_DECL,
48
+ FAILZ_CLASS_DECL,
49
+ FINZ_DECL
49
50
  ].join("\n");
50
51
  /**
51
- * Methods `__zcMkv` installs. Each is fronted by a compile-on-read accessor
52
- * until the schema materializes.
53
- *
54
- * `~standard` earns its place: Zod builds it as a closure over `_zod.run`, not
55
- * over the schema's `safeParse` property, so a Standard Schema consumer (tRPC,
56
- * Hono, TanStack Form) that never touches `safeParse` would otherwise keep
57
- * running plain Zod forever behind a "compiled" schema.
58
- */
59
- const SLOTS = ["parse", "safeParse", "parseAsync", "safeParseAsync", "is", "~standard"];
52
+ * Methods `__zcMkv` installs. Each is fronted by a compile-on-read accessor
53
+ * until the schema materializes.
54
+ *
55
+ * `~standard` earns its place: Zod builds it as a closure over `_zod.run`, not
56
+ * over the schema's `safeParse` property, so a Standard Schema consumer (tRPC,
57
+ * Hono, TanStack Form) that never touches `safeParse` would otherwise keep
58
+ * running plain Zod forever behind a "compiled" schema.
59
+ */
60
+ const SLOTS = [
61
+ "parse",
62
+ "safeParse",
63
+ "parseAsync",
64
+ "safeParseAsync",
65
+ "is",
66
+ "~standard"
67
+ ];
60
68
  /** Schemas already handed to `jit()`, so a second call is a no-op rather than a recompile. */
61
- const seen = new WeakSet();
69
+ const seen = /* @__PURE__ */ new WeakSet();
62
70
  /**
63
- * Compile `schema` in-process and install the compiled `parse` / `safeParse` /
64
- * `parseAsync` / `safeParseAsync` / `is` / `~standard` on it.
65
- *
66
- * Returns the SAME object — identity-preserving exactly as the build plugin is,
67
- * so `.shape`, `_zod`, `instanceof`, `z.toJSONSchema()`, `.meta()` and
68
- * composition into a larger schema all keep working, and every existing
69
- * reference to the schema picks the compiled methods up.
70
- *
71
- * ```ts
72
- * import { z } from "zod";
73
- * import { jit } from "zod-compiler/jit";
74
- *
75
- * export const UserSchema = jit(z.object({ name: z.string(), email: z.email() }));
76
- * UserSchema.safeParse(input); // compiled on this first call
77
- * ```
78
- *
79
- * Schemas the compiler cannot reproduce fall back to Zod per sub-schema, the
80
- * same way they do at build time; a schema that cannot be compiled at all is
81
- * left as plain Zod.
82
- */
83
- export function jit(schema, options) {
84
- const target = schema;
85
- if (seen.has(target))
86
- return schema;
87
- seen.add(target);
88
- if (options?.eager === true) {
89
- materialize(schema);
90
- return schema;
91
- }
92
- // Snapshot Zod's own descriptors first: materialize() restores them before
93
- // handing the object to `__zcMkv`, so the generated code sees a pristine
94
- // schema — it captures `~standard`'s original `validate` as its throw path,
95
- // and capturing a stub there would loop back into itself.
96
- const original = new Map();
97
- for (const slot of SLOTS) {
98
- original.set(slot, Object.getOwnPropertyDescriptor(target, slot));
99
- }
100
- // Installing the accessors is the one step that can throw rather than degrade:
101
- // a slot locked non-configurable (a future Zod, another wrapper) makes
102
- // defineProperty raise, and `jit()` is called at module scope — so an
103
- // unhandled throw here takes down the importing app at boot. Roll back to
104
- // whatever Zod had and leave the schema alone instead.
105
- let pending = true;
106
- try {
107
- installAccessors(target, original, () => {
108
- if (!pending)
109
- return;
110
- pending = false;
111
- restore(target, original);
112
- materialize(schema);
113
- }, () => {
114
- if (!pending)
115
- return;
116
- pending = false;
117
- // Restore EVERY slot, not just the one being written. A left-behind
118
- // accessor whose trigger has been cancelled would read `target[slot]`
119
- // and re-enter itself — unbounded recursion. This is the path the build
120
- // plugin takes when a file uses `jit()` too: `__zcMkv` assigns the parse
121
- // methods (cancelling here) and then reads `~standard`.
122
- restore(target, original);
123
- });
124
- }
125
- catch {
126
- pending = false;
127
- restore(target, original);
128
- }
129
- return schema;
71
+ * Compile `schema` in-process and install the compiled `parse` / `safeParse` /
72
+ * `parseAsync` / `safeParseAsync` / `is` / `~standard` on it.
73
+ *
74
+ * Returns the SAME object — identity-preserving exactly as the build plugin is,
75
+ * so `.shape`, `_zod`, `instanceof`, `z.toJSONSchema()`, `.meta()` and
76
+ * composition into a larger schema all keep working, and every existing
77
+ * reference to the schema picks the compiled methods up.
78
+ *
79
+ * ```ts
80
+ * import { z } from "zod";
81
+ * import { jit } from "zod-compiler/jit";
82
+ *
83
+ * export const UserSchema = jit(z.object({ name: z.string(), email: z.email() }));
84
+ * UserSchema.safeParse(input); // compiled on this first call
85
+ * ```
86
+ *
87
+ * Schemas the compiler cannot reproduce fall back to Zod per sub-schema, the
88
+ * same way they do at build time; a schema that cannot be compiled at all is
89
+ * left as plain Zod.
90
+ */
91
+ function jit(schema, options) {
92
+ const target = schema;
93
+ if (seen.has(target)) return schema;
94
+ seen.add(target);
95
+ if (options?.eager === true) {
96
+ materialize(schema);
97
+ return schema;
98
+ }
99
+ const original = /* @__PURE__ */ new Map();
100
+ for (const slot of SLOTS) original.set(slot, Object.getOwnPropertyDescriptor(target, slot));
101
+ let pending = true;
102
+ try {
103
+ installAccessors(target, original, () => {
104
+ if (!pending) return;
105
+ pending = false;
106
+ restore(target, original);
107
+ materialize(schema);
108
+ }, () => {
109
+ if (!pending) return;
110
+ pending = false;
111
+ restore(target, original);
112
+ });
113
+ } catch {
114
+ pending = false;
115
+ restore(target, original);
116
+ }
117
+ return schema;
130
118
  }
131
119
  /**
132
- * Front every installed method with a compile-on-read accessor. `trigger`
133
- * materializes the schema, which replaces these accessors with the compiled
134
- * methods (or restores Zod's own), so the read that follows never re-enters.
135
- */
120
+ * Front every installed method with a compile-on-read accessor. `trigger`
121
+ * materializes the schema, which replaces these accessors with the compiled
122
+ * methods (or restores Zod's own), so the read that follows never re-enters.
123
+ */
136
124
  function installAccessors(target, original, trigger, cancel) {
137
- for (const slot of SLOTS) {
138
- Object.defineProperty(target, slot, {
139
- configurable: true,
140
- // Preserve Zod's own visibility: parse/safeParse/... are enumerable own
141
- // properties, `~standard` is not. `is` does not exist on a Zod schema, so
142
- // it follows the non-enumerable convention `compile()` already uses.
143
- enumerable: original.get(slot)?.enumerable ?? false,
144
- get() {
145
- trigger();
146
- // Whatever now occupies the slot: the compiled method, or — if
147
- // compilation was impossible — Zod's own, put back by restore().
148
- return target[slot];
149
- },
150
- set(value) {
151
- // Someone overwrote a method before first use (a test double, another
152
- // wrapper). Their value wins, and compilation is cancelled outright —
153
- // materializing later would restore Zod's descriptors over it.
154
- cancel();
155
- Object.defineProperty(target, slot, {
156
- configurable: true,
157
- enumerable: original.get(slot)?.enumerable ?? false,
158
- value,
159
- writable: true,
160
- });
161
- },
162
- });
163
- }
125
+ for (const slot of SLOTS) Object.defineProperty(target, slot, {
126
+ configurable: true,
127
+ enumerable: original.get(slot)?.enumerable ?? false,
128
+ get() {
129
+ trigger();
130
+ return target[slot];
131
+ },
132
+ set(value) {
133
+ cancel();
134
+ Object.defineProperty(target, slot, {
135
+ configurable: true,
136
+ enumerable: original.get(slot)?.enumerable ?? false,
137
+ value,
138
+ writable: true
139
+ });
140
+ }
141
+ });
164
142
  }
165
143
  /**
166
- * Compile every Zod schema found among an object's own values — typically a
167
- * module namespace, so a whole schema file opts in with one call:
168
- *
169
- * ```ts
170
- * import * as schemas from "./schemas.js";
171
- * jitAll(schemas);
172
- * ```
173
- *
174
- * The namespace object itself is never written to (a module namespace is
175
- * read-only); `jit()` mutates the schema objects it holds, which is what every
176
- * importer of that module already references.
177
- */
178
- export function jitAll(schemas, options) {
179
- for (const value of Object.values(schemas)) {
180
- if (isZodSchema(value))
181
- jit(value, options);
182
- }
144
+ * Compile every Zod schema found among an object's own values — typically a
145
+ * module namespace, so a whole schema file opts in with one call:
146
+ *
147
+ * ```ts
148
+ * import * as schemas from "./schemas.js";
149
+ * jitAll(schemas);
150
+ * ```
151
+ *
152
+ * The namespace object itself is never written to (a module namespace is
153
+ * read-only); `jit()` mutates the schema objects it holds, which is what every
154
+ * importer of that module already references.
155
+ */
156
+ function jitAll(schemas, options) {
157
+ for (const value of Object.values(schemas)) if (isZodSchema(value)) jit(value, options);
183
158
  }
184
159
  /** Zod schemas carry `_zod.def`; the same probe auto-discovery uses at build time. */
185
160
  function isZodSchema(value) {
186
- if (typeof value !== "object" || value === null || !("_zod" in value))
187
- return false;
188
- const internal = value["_zod"];
189
- return typeof internal === "object" && internal !== null && "def" in internal;
161
+ if (typeof value !== "object" || value === null || !("_zod" in value)) return false;
162
+ const internal = value["_zod"];
163
+ return typeof internal === "object" && internal !== null && "def" in internal;
190
164
  }
191
165
  /** Put Zod's own descriptors back, dropping the compile-on-read accessors. */
192
166
  function restore(target, original) {
193
- for (const slot of SLOTS) {
194
- const descriptor = original.get(slot);
195
- if (descriptor === undefined)
196
- delete target[slot];
197
- else
198
- Object.defineProperty(target, slot, descriptor);
199
- }
167
+ for (const slot of SLOTS) {
168
+ const descriptor = original.get(slot);
169
+ if (descriptor === void 0) delete target[slot];
170
+ else Object.defineProperty(target, slot, descriptor);
171
+ }
200
172
  }
201
173
  /**
202
- * Whether runtime code generation is permitted here. Read per call, never
203
- * snapshotted: `z.config({ jitless: true })` runs in an entry point, after the
204
- * schema modules it imports have already been evaluated.
205
- */
174
+ * Whether runtime code generation is permitted here. Read per call, never
175
+ * snapshotted: `z.config({ jitless: true })` runs in an entry point, after the
176
+ * schema modules it imports have already been evaluated.
177
+ */
206
178
  function codegenAllowed() {
207
- return zodCore.globalConfig.jitless !== true && zodCore.util.allowsEval.value;
179
+ return core.globalConfig.jitless !== true && core.util.allowsEval.value;
208
180
  }
209
181
  /**
210
- * Run the pipeline and let the generated IIFE install its methods on `schema`.
211
- * Swallows failure: a schema that cannot be compiled keeps Zod's own methods,
212
- * which the caller already has, so there is nothing to report and nothing to
213
- * break.
214
- */
182
+ * Run the pipeline and let the generated IIFE install its methods on `schema`.
183
+ * Swallows failure: a schema that cannot be compiled keeps Zod's own methods,
184
+ * which the caller already has, so there is nothing to report and nothing to
185
+ * break.
186
+ */
215
187
  function materialize(schema) {
216
- if (!codegenAllowed())
217
- return;
218
- try {
219
- buildValidator(schema);
220
- }
221
- catch {
222
- // Left as plain Zod. Deliberately silent: `jit()` is an optimization, and a
223
- // schema using a construct the compiler declines is a supported outcome,
224
- // not an error.
225
- }
188
+ if (!codegenAllowed()) return;
189
+ try {
190
+ buildValidator(schema);
191
+ } catch {}
226
192
  }
227
193
  /**
228
- * Generate the validator and evaluate it, reproducing the module a
229
- * `.compiled.ts` would have been: helper preamble, the file-level shared block,
230
- * then the `__zcMkv` IIFE whose `__rf[]` bases and install target are the live
231
- * schema object passed in as `__schema`.
232
- */
194
+ * Generate the validator and evaluate it, reproducing the module a
195
+ * `.compiled.ts` would have been: helper preamble, the file-level shared block,
196
+ * then the `__zcMkv` IIFE whose `__rf[]` bases and install target are the live
197
+ * schema object passed in as `__schema`.
198
+ */
233
199
  function buildValidator(schema) {
234
- const { schemas, shared } = compileSchemas([{ exportName: "jit", schema }], { mode: "inline" });
235
- const compiled = schemas[0];
236
- if (compiled === undefined)
237
- throw new Error("zod-compiler: schema produced no validator");
238
- const body = [RUNTIME_PRELUDE, shared.code, `return ${generateIIFE("__schema", compiled)};`].join("\n");
239
- // The three bindings ZOD_CONFIG_IMPORT would have imported, passed in so the
240
- // evaluated code needs no module resolution of its own.
241
- // oxlint-disable-next-line no-new-func -- generating the validator IS the feature
242
- const factory = new Function("__zodCompilerConfig", "__zcCore", "__zcZodError", "__schema", body);
243
- factory(zodConfig, zodCore, ZodRealError, schema);
200
+ const { schemas, shared } = compileSchemas([{
201
+ exportName: "jit",
202
+ schema
203
+ }], { mode: "inline" });
204
+ const compiled = schemas[0];
205
+ if (compiled === void 0) throw new Error("zod-compiler: schema produced no validator");
206
+ const body = [
207
+ RUNTIME_PRELUDE,
208
+ shared.code,
209
+ `return ${generateIIFE("__schema", compiled)};`
210
+ ].join("\n");
211
+ new Function("__zodCompilerConfig", "__zcCore", "__zcZodError", "__schema", body)(config, core, ZodRealError, schema);
244
212
  }
213
+ //#endregion
214
+ export { jit, jitAll };
215
+
245
216
  //# sourceMappingURL=jit.js.map
package/dist/jit.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"jit.js","sourceRoot":"","sources":["../src/jit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EAAE,MAAM,IAAI,SAAS,EAAE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["zodCore","zodConfig"],"sources":["../src/jit.ts"],"sourcesContent":["/**\n * Runtime compilation — the same extract → codegen pipeline the build plugin\n * runs, executed in-process and evaluated through `new Function`.\n *\n * The AOT paths (unplugin, CLI) need a build step to fire. Plenty of everyday\n * code has none: `tsx server.ts`, `node --experimental-strip-types`, a Jest\n * suite, a serverless handler bundled by someone else's toolchain, a library\n * that ships schemas to consumers. There `compile()` is a no-op and every parse\n * runs plain Zod. `jit()` closes that gap — one call, no build integration,\n * measured 3-25x on everyday schemas at ~0.1-0.2 ms of one-time compilation.\n *\n * Nothing here re-implements validation: {@link compileSchemas} and\n * {@link generateIIFE} are the exact modules the plugin and CLI use, so the\n * generated validator, its Zod parity and its performance are identical to what\n * a build would have emitted. The only difference is *when* the code is\n * produced.\n *\n * Compilation is LAZY by default: `jit()` installs accessors that compile on\n * the first read of a parse method and replace themselves with the compiled\n * ones. Importing a module of 500 schemas therefore costs nothing, and a\n * serverless invocation touching three of them pays for three.\n *\n * Runtime code generation is not always permitted — a strict CSP without\n * `unsafe-eval`, some edge runtimes. Zod v4 has the same constraint (its object\n * fast-pass is itself a `new Function`) and already exposes the two switches\n * for it: the `core.util.allowsEval` probe and `z.config({ jitless: true })`.\n * `jit()` honours both and degrades to plain Zod, so one setting governs both\n * compilers. Those targets are where the build plugin belongs anyway — it emits\n * the same validator with no runtime evaluation at all.\n */\n\nimport { config as zodConfig, core as zodCore, ZodRealError, type output, type ZodType } from \"zod\";\nimport {\n FAIL_CLASS_DECL,\n FAILZ_CLASS_DECL,\n FIN_DECL,\n FIN_DEFERRED_DECL,\n FINZ_DECL,\n generateIIFE,\n MK_VALIDATOR_DECL,\n ZOD_MSG_DECLARATION,\n} from \"./core/iife.js\";\nimport { compileSchemas } from \"./core/pipeline.js\";\nimport type { CompiledSchema } from \"./core/types.js\";\n\n/**\n * The declarations `ZOD_CONFIG_IMPORT` supplies to an emitted module, minus the\n * import itself — `zod`'s three bindings arrive as parameters instead, so the\n * evaluated code has no module scope to resolve. Byte-for-byte the same helper\n * source the CLI emitter writes into a `.compiled.ts`, so a JIT validator and\n * an AOT one share their entire runtime layer.\n */\nconst RUNTIME_PRELUDE = [\n ZOD_MSG_DECLARATION,\n FAIL_CLASS_DECL,\n MK_VALIDATOR_DECL,\n FIN_DECL,\n FIN_DEFERRED_DECL,\n FAILZ_CLASS_DECL,\n FINZ_DECL,\n].join(\"\\n\");\n\n/**\n * Methods `__zcMkv` installs. Each is fronted by a compile-on-read accessor\n * until the schema materializes.\n *\n * `~standard` earns its place: Zod builds it as a closure over `_zod.run`, not\n * over the schema's `safeParse` property, so a Standard Schema consumer (tRPC,\n * Hono, TanStack Form) that never touches `safeParse` would otherwise keep\n * running plain Zod forever behind a \"compiled\" schema.\n */\nconst SLOTS = [\"parse\", \"safeParse\", \"parseAsync\", \"safeParseAsync\", \"is\", \"~standard\"] as const;\n\n/** Schemas already handed to `jit()`, so a second call is a no-op rather than a recompile. */\nconst seen = new WeakSet<object>();\n\nexport interface JitOptions {\n /**\n * Compile immediately instead of on first use. Costs ~0.1-0.2 ms per schema\n * at import time; useful for a long-lived server that would rather pay during\n * startup than on the first request, or to surface a compilation failure\n * eagerly. Default `false`.\n */\n eager?: boolean | undefined;\n}\n\n/**\n * Compile `schema` in-process and install the compiled `parse` / `safeParse` /\n * `parseAsync` / `safeParseAsync` / `is` / `~standard` on it.\n *\n * Returns the SAME object — identity-preserving exactly as the build plugin is,\n * so `.shape`, `_zod`, `instanceof`, `z.toJSONSchema()`, `.meta()` and\n * composition into a larger schema all keep working, and every existing\n * reference to the schema picks the compiled methods up.\n *\n * ```ts\n * import { z } from \"zod\";\n * import { jit } from \"zod-compiler/jit\";\n *\n * export const UserSchema = jit(z.object({ name: z.string(), email: z.email() }));\n * UserSchema.safeParse(input); // compiled on this first call\n * ```\n *\n * Schemas the compiler cannot reproduce fall back to Zod per sub-schema, the\n * same way they do at build time; a schema that cannot be compiled at all is\n * left as plain Zod.\n */\nexport function jit<T extends ZodType>(\n schema: T,\n options?: JitOptions,\n): T & CompiledSchema<output<T>> {\n const target = schema as unknown as Record<string, unknown>;\n if (seen.has(target)) return schema as T & CompiledSchema<output<T>>;\n seen.add(target);\n\n if (options?.eager === true) {\n materialize(schema);\n return schema as T & CompiledSchema<output<T>>;\n }\n\n // Snapshot Zod's own descriptors first: materialize() restores them before\n // handing the object to `__zcMkv`, so the generated code sees a pristine\n // schema — it captures `~standard`'s original `validate` as its throw path,\n // and capturing a stub there would loop back into itself.\n const original = new Map<string, PropertyDescriptor | undefined>();\n for (const slot of SLOTS) {\n original.set(slot, Object.getOwnPropertyDescriptor(target, slot));\n }\n\n // Installing the accessors is the one step that can throw rather than degrade:\n // a slot locked non-configurable (a future Zod, another wrapper) makes\n // defineProperty raise, and `jit()` is called at module scope — so an\n // unhandled throw here takes down the importing app at boot. Roll back to\n // whatever Zod had and leave the schema alone instead.\n let pending = true;\n try {\n installAccessors(\n target,\n original,\n () => {\n if (!pending) return;\n pending = false;\n restore(target, original);\n materialize(schema);\n },\n () => {\n if (!pending) return;\n pending = false;\n // Restore EVERY slot, not just the one being written. A left-behind\n // accessor whose trigger has been cancelled would read `target[slot]`\n // and re-enter itself — unbounded recursion. This is the path the build\n // plugin takes when a file uses `jit()` too: `__zcMkv` assigns the parse\n // methods (cancelling here) and then reads `~standard`.\n restore(target, original);\n },\n );\n } catch {\n pending = false;\n restore(target, original);\n }\n\n return schema as T & CompiledSchema<output<T>>;\n}\n\n/**\n * Front every installed method with a compile-on-read accessor. `trigger`\n * materializes the schema, which replaces these accessors with the compiled\n * methods (or restores Zod's own), so the read that follows never re-enters.\n */\nfunction installAccessors(\n target: Record<string, unknown>,\n original: ReadonlyMap<string, PropertyDescriptor | undefined>,\n trigger: () => void,\n cancel: () => void,\n): void {\n for (const slot of SLOTS) {\n Object.defineProperty(target, slot, {\n configurable: true,\n // Preserve Zod's own visibility: parse/safeParse/... are enumerable own\n // properties, `~standard` is not. `is` does not exist on a Zod schema, so\n // it follows the non-enumerable convention `compile()` already uses.\n enumerable: original.get(slot)?.enumerable ?? false,\n get() {\n trigger();\n // Whatever now occupies the slot: the compiled method, or — if\n // compilation was impossible — Zod's own, put back by restore().\n return target[slot];\n },\n set(value: unknown) {\n // Someone overwrote a method before first use (a test double, another\n // wrapper). Their value wins, and compilation is cancelled outright —\n // materializing later would restore Zod's descriptors over it.\n cancel();\n Object.defineProperty(target, slot, {\n configurable: true,\n enumerable: original.get(slot)?.enumerable ?? false,\n value,\n writable: true,\n });\n },\n });\n }\n}\n\n/**\n * Compile every Zod schema found among an object's own values — typically a\n * module namespace, so a whole schema file opts in with one call:\n *\n * ```ts\n * import * as schemas from \"./schemas.js\";\n * jitAll(schemas);\n * ```\n *\n * The namespace object itself is never written to (a module namespace is\n * read-only); `jit()` mutates the schema objects it holds, which is what every\n * importer of that module already references.\n */\nexport function jitAll(schemas: object, options?: JitOptions): void {\n for (const value of Object.values(schemas)) {\n if (isZodSchema(value)) jit(value, options);\n }\n}\n\n/** Zod schemas carry `_zod.def`; the same probe auto-discovery uses at build time. */\nfunction isZodSchema(value: unknown): value is ZodType {\n if (typeof value !== \"object\" || value === null || !(\"_zod\" in value)) return false;\n const internal = (value as Record<string, unknown>)[\"_zod\"];\n return typeof internal === \"object\" && internal !== null && \"def\" in internal;\n}\n\n/** Put Zod's own descriptors back, dropping the compile-on-read accessors. */\nfunction restore(\n target: Record<string, unknown>,\n original: ReadonlyMap<string, PropertyDescriptor | undefined>,\n): void {\n for (const slot of SLOTS) {\n const descriptor = original.get(slot);\n if (descriptor === undefined) delete target[slot];\n else Object.defineProperty(target, slot, descriptor);\n }\n}\n\n/**\n * Whether runtime code generation is permitted here. Read per call, never\n * snapshotted: `z.config({ jitless: true })` runs in an entry point, after the\n * schema modules it imports have already been evaluated.\n */\nfunction codegenAllowed(): boolean {\n return zodCore.globalConfig.jitless !== true && zodCore.util.allowsEval.value;\n}\n\n/**\n * Run the pipeline and let the generated IIFE install its methods on `schema`.\n * Swallows failure: a schema that cannot be compiled keeps Zod's own methods,\n * which the caller already has, so there is nothing to report and nothing to\n * break.\n */\nfunction materialize(schema: unknown): void {\n if (!codegenAllowed()) return;\n try {\n buildValidator(schema);\n } catch {\n // Left as plain Zod. Deliberately silent: `jit()` is an optimization, and a\n // schema using a construct the compiler declines is a supported outcome,\n // not an error.\n }\n}\n\n/**\n * Generate the validator and evaluate it, reproducing the module a\n * `.compiled.ts` would have been: helper preamble, the file-level shared block,\n * then the `__zcMkv` IIFE whose `__rf[]` bases and install target are the live\n * schema object passed in as `__schema`.\n */\nfunction buildValidator(schema: unknown): void {\n const { schemas, shared } = compileSchemas([{ exportName: \"jit\", schema }], { mode: \"inline\" });\n const compiled = schemas[0];\n if (compiled === undefined) throw new Error(\"zod-compiler: schema produced no validator\");\n\n const body = [RUNTIME_PRELUDE, shared.code, `return ${generateIIFE(\"__schema\", compiled)};`].join(\n \"\\n\",\n );\n\n // The three bindings ZOD_CONFIG_IMPORT would have imported, passed in so the\n // evaluated code needs no module resolution of its own.\n // oxlint-disable-next-line no-new-func -- generating the validator IS the feature\n const factory = new Function(\n \"__zodCompilerConfig\",\n \"__zcCore\",\n \"__zcZodError\",\n \"__schema\",\n body,\n ) as (\n zodConfigFn: typeof zodConfig,\n zodCoreNs: typeof zodCore,\n zodErrorCtor: typeof ZodRealError,\n target: unknown,\n ) => unknown;\n\n factory(zodConfig, zodCore, ZodRealError, schema);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoDA,MAAM,kBAAkB;CACtB;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC,CAAC,KAAK,IAAI;;;;;;;;;;AAWX,MAAM,QAAQ;CAAC;CAAS;CAAa;CAAc;CAAkB;CAAM;AAAW;;AAGtF,MAAM,uBAAO,IAAI,QAAgB;;;;;;;;;;;;;;;;;;;;;;AAiCjC,SAAgB,IACd,QACA,SAC+B;CAC/B,MAAM,SAAS;CACf,IAAI,KAAK,IAAI,MAAM,GAAG,OAA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ACN,KAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,aAAa,SAAS,IAAI,IAAI;EACpC,IAAI,eAAe,KAAA,GAAW,OAAO,OAAO;OACvC,OAAO,eAAe,QAAQ,MAAM,UAAU;CACrD;AACF;;;;;;AAOA,SAAS,iBAA0B;CACjC,OAAOA,KAAQ,aAAa,YAAY,QAAQA,KAAQ,KAAK,WAAW;AAC1E;;;;;;;AAQA,SAAS,YAAY,QAAuB;CAC1C,IAAI,CAAC,eAAe,GAAG;CACvB,IAAI;EACF,eAAe,MAAM;CACvB,QAAQ,CAIR;AACF;;;;;;;AAQA,SAAS,eAAe,QAAuB;CAC7C,MAAM,EAAE,SAAS,WAAW,eAAe,CAAC;EAAE,YAAY;EAAO;CAAO,CAAC,GAAG,EAAE,MAAM,SAAS,CAAC;CAC9F,MAAM,WAAW,QAAQ;CACzB,IAAI,aAAa,KAAA,GAAW,MAAM,IAAI,MAAM,4CAA4C;CAExF,MAAM,OAAO;EAAC;EAAiB,OAAO;EAAM,UAAU,aAAa,YAAY,QAAQ,EAAE;CAAE,CAAC,CAAC,KAC3F,IACF;CAkBA,IAboB,SAClB,uBACA,YACA,gBACA,YACA,IAQI,CAAC,CAACC,QAAWD,MAAS,cAAc,MAAM;AAClD"}
package/dist/loader.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ //#region src/loader.d.ts
1
2
  /**
2
3
  * Candidate files for a specifier using the tsconfig path mappings visible
3
4
  * from a directory. Used by the static dependency crawler so alias imports
@@ -15,9 +16,9 @@
15
16
  * and `#` subpath imports included) and expects the caller to fall back
16
17
  * to node resolution when the candidate does not exist.
17
18
  */
18
- export declare function resolveTsconfigPathCandidates(fromDir: string, specifier: string): {
19
- candidates: string[];
20
- authoritative: boolean;
19
+ declare function resolveTsconfigPathCandidates(fromDir: string, specifier: string): {
20
+ candidates: string[];
21
+ authoritative: boolean;
21
22
  };
22
23
  /**
23
24
  * Thrown in place of a `process.exit()` call made while a build-time module is
@@ -25,10 +26,10 @@ export declare function resolveTsconfigPathCandidates(fromDir: string, specifier
25
26
  * and skips the file (falling back to runtime Zod), so a non-cooperating
26
27
  * module's exit degrades gracefully instead of terminating the bundler.
27
28
  */
28
- export declare class ProcessExitDuringLoadError extends Error {
29
- /** The code passed to the intercepted `process.exit()`, if any. */
30
- readonly exitCode: number | string | undefined;
31
- constructor(code?: number | string);
29
+ declare class ProcessExitDuringLoadError extends Error {
30
+ /** The code passed to the intercepted `process.exit()`, if any. */
31
+ readonly exitCode: number | string | undefined;
32
+ constructor(code?: number | string);
32
33
  }
33
34
  /**
34
35
  * Drop every first-party (non-node_modules) module from the shared loader
@@ -42,7 +43,7 @@ export declare class ProcessExitDuringLoadError extends Error {
42
43
  * keeping node_modules (the expensive bulk — zod itself) warm is both correct
43
44
  * and fast.
44
45
  */
45
- export declare function invalidateModuleCache(): void;
46
+ declare function invalidateModuleCache(): void;
46
47
  /**
47
48
  * Absolute paths of every first-party (non-node_modules) module currently
48
49
  * executed by the shared loader. Used by the unplugin disk cache to record
@@ -52,7 +53,7 @@ export declare function invalidateModuleCache(): void;
52
53
  * Returns null when no jiti instance exists (Bun/Deno native import — no
53
54
  * evictable cache, so dependency tracking is unavailable).
54
55
  */
55
- export declare function getFirstPartyModulePaths(): string[] | null;
56
+ declare function getFirstPartyModulePaths(): string[] | null;
56
57
  /**
57
58
  * Dynamically import a source file (.ts or .js).
58
59
  * - Bun/Deno: native TypeScript support, direct import
@@ -62,7 +63,7 @@ export declare function getFirstPartyModulePaths(): string[] | null;
62
63
  * Module executions are cached across calls; use invalidateModuleCache()
63
64
  * when source files change (watch/HMR).
64
65
  */
65
- export declare function loadSourceFile(filePath: string): Promise<Record<string, unknown>>;
66
+ declare function loadSourceFile(filePath: string): Promise<Record<string, unknown>>;
66
67
  /**
67
68
  * Import a module by SPECIFIER as `fromFile` would: relative specifiers
68
69
  * resolve against the importing file's directory; bare specifiers (`zod`)
@@ -70,5 +71,7 @@ export declare function loadSourceFile(filePath: string): Promise<Record<string,
70
71
  * the same module instance discovery executions see. Used by the hoisted-
71
72
  * schema compile step to evaluate hoisted expressions at build time.
72
73
  */
73
- export declare function loadModule(specifier: string, fromFile: string): Promise<Record<string, unknown>>;
74
+ declare function loadModule(specifier: string, fromFile: string): Promise<Record<string, unknown>>;
75
+ //#endregion
76
+ export { ProcessExitDuringLoadError, getFirstPartyModulePaths, invalidateModuleCache, loadModule, loadSourceFile, resolveTsconfigPathCandidates };
74
77
  //# sourceMappingURL=loader.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAoFA;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,GAChB;IAAE,UAAU,EAAE,MAAM,EAAE,CAAC;IAAC,aAAa,EAAE,OAAO,CAAA;CAAE,CAoBlD;AAoCD;;;;;GAKG;AACH,qBAAa,0BAA2B,SAAQ,KAAK;IACnD,mEAAmE;IACnE,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;gBAEnC,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM;CAQnC;AA0DD;;;;;;;;;;;GAWG;AACH,wBAAgB,qBAAqB,IAAI,IAAI,CAS5C;AAED;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,IAAI,MAAM,EAAE,GAAG,IAAI,CAW1D;AAiBD;;;;;;;;GAQG;AACH,wBAAsB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAsBvF;AAED;;;;;;GAMG;AACH,wBAAsB,UAAU,CAC9B,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAkBlC"}
1
+ {"version":3,"file":"loader.d.ts","names":[],"sources":["../src/loader.ts"],"mappings":";;;;;;;;;;;;;;;;;;iBAqGgB,8BACd,iBACA;EACG;EAAsB;;;;;;;;cA8Dd,mCAAmC;;WAErC;EAEG,YAAA;;;;;;;;;;;;;;iBA8EE;;;;;;;;;;iBAoBA;;;;;;;;;;iBAqCM,eAAe,mBAAmB,QAAQ;;;;;;;;iBA+B1C,WACpB,mBACA,mBACC,QAAQ"}