elysia 2.0.0-beta.2 → 2.0.0-beta.21

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 (339) hide show
  1. package/dist/adapter/bun/index.d.ts +18 -2
  2. package/dist/adapter/bun/index.js +467 -110
  3. package/dist/adapter/bun/index.mjs +467 -112
  4. package/dist/adapter/types.d.ts +2 -21
  5. package/dist/adapter/utils.d.ts +14 -3
  6. package/dist/adapter/utils.js +146 -87
  7. package/dist/adapter/utils.mjs +148 -90
  8. package/dist/adapter/web-standard/handler.d.ts +1 -1
  9. package/dist/adapter/web-standard/handler.js +47 -36
  10. package/dist/adapter/web-standard/handler.mjs +48 -37
  11. package/dist/adapter/web-standard/index.js +2 -30
  12. package/dist/adapter/web-standard/index.mjs +2 -30
  13. package/dist/adapter/web-standard/utils.js +5 -18
  14. package/dist/adapter/web-standard/utils.mjs +5 -18
  15. package/dist/base.d.ts +99 -67
  16. package/dist/base.js +678 -510
  17. package/dist/base.mjs +682 -514
  18. package/dist/compile/aot-capture.d.ts +2 -13
  19. package/dist/compile/aot-capture.js +26 -69
  20. package/dist/compile/aot-capture.mjs +28 -67
  21. package/dist/compile/aot-emit.d.ts +9 -7
  22. package/dist/compile/aot-emit.js +42 -19
  23. package/dist/compile/aot-emit.mjs +42 -20
  24. package/dist/compile/aot.d.ts +17 -19
  25. package/dist/compile/aot.js +41 -51
  26. package/dist/compile/aot.mjs +39 -49
  27. package/dist/compile/handler/descriptor.d.ts +9 -12
  28. package/dist/compile/handler/descriptor.js +19 -44
  29. package/dist/compile/handler/descriptor.mjs +20 -42
  30. package/dist/compile/handler/frozen-validator.d.ts +5 -10
  31. package/dist/compile/handler/frozen-validator.js +55 -105
  32. package/dist/compile/handler/frozen-validator.mjs +53 -105
  33. package/dist/compile/handler/index.d.ts +7 -5
  34. package/dist/compile/handler/index.js +270 -111
  35. package/dist/compile/handler/index.mjs +270 -113
  36. package/dist/compile/handler/jit.d.ts +19 -17
  37. package/dist/compile/handler/jit.js +222 -149
  38. package/dist/compile/handler/jit.mjs +224 -152
  39. package/dist/compile/handler/params.d.ts +1 -4
  40. package/dist/compile/handler/params.js +10 -5
  41. package/dist/compile/handler/params.mjs +14 -8
  42. package/dist/compile/handler/reconstruct.d.ts +2 -2
  43. package/dist/compile/handler/reconstruct.js +6 -4
  44. package/dist/compile/handler/reconstruct.mjs +6 -4
  45. package/dist/compile/handler/static-clone-resolver.d.ts +6 -0
  46. package/dist/compile/handler/static-clone-resolver.js +8 -0
  47. package/dist/compile/handler/static-clone-resolver.mjs +7 -0
  48. package/dist/compile/handler/utils.d.ts +22 -11
  49. package/dist/compile/handler/utils.js +159 -253
  50. package/dist/compile/handler/utils.mjs +155 -252
  51. package/dist/compile/jit-probe.d.ts +2 -2
  52. package/dist/compile/jit-probe.js +2 -3
  53. package/dist/compile/jit-probe.mjs +2 -3
  54. package/dist/compile/lexer.d.ts +7 -4
  55. package/dist/compile/lexer.js +268 -6
  56. package/dist/compile/lexer.mjs +268 -4
  57. package/dist/compile/utils.js +7 -4
  58. package/dist/compile/utils.mjs +7 -4
  59. package/dist/compiled.d.ts +0 -1
  60. package/dist/compiled.js +0 -1
  61. package/dist/compiled.mjs +0 -1
  62. package/dist/context.d.ts +14 -4
  63. package/dist/context.js +17 -32
  64. package/dist/context.mjs +19 -34
  65. package/dist/cookie/config.d.ts +7 -2
  66. package/dist/cookie/config.js +76 -16
  67. package/dist/cookie/config.mjs +77 -18
  68. package/dist/cookie/cookie.d.ts +1 -1
  69. package/dist/cookie/cookie.js +8 -10
  70. package/dist/cookie/cookie.mjs +8 -10
  71. package/dist/cookie/crypto.d.ts +8 -7
  72. package/dist/cookie/crypto.js +51 -40
  73. package/dist/cookie/crypto.mjs +51 -41
  74. package/dist/cookie/error.d.ts +1 -2
  75. package/dist/cookie/error.js +6 -4
  76. package/dist/cookie/error.mjs +6 -4
  77. package/dist/cookie/lib.js +7 -2
  78. package/dist/cookie/lib.mjs +7 -2
  79. package/dist/cookie/serialize.js +1 -1
  80. package/dist/cookie/serialize.mjs +1 -1
  81. package/dist/cookie/types.d.ts +10 -0
  82. package/dist/cookie/utils.d.ts +4 -8
  83. package/dist/cookie/utils.js +86 -52
  84. package/dist/cookie/utils.mjs +89 -54
  85. package/dist/error.d.ts +113 -103
  86. package/dist/error.js +181 -117
  87. package/dist/error.mjs +179 -118
  88. package/dist/generation.d.ts +2 -2
  89. package/dist/handler/error.d.ts +26 -15
  90. package/dist/handler/error.js +77 -96
  91. package/dist/handler/error.mjs +74 -97
  92. package/dist/handler/fetch.js +87 -108
  93. package/dist/handler/fetch.mjs +89 -110
  94. package/dist/handler/utils.d.ts +12 -6
  95. package/dist/handler/utils.js +84 -28
  96. package/dist/handler/utils.mjs +80 -28
  97. package/dist/index.d.ts +12 -12
  98. package/dist/index.js +2 -9
  99. package/dist/index.mjs +1 -1
  100. package/dist/memory.js +1 -1
  101. package/dist/memory.mjs +1 -1
  102. package/dist/package.js +1 -1
  103. package/dist/package.mjs +1 -1
  104. package/dist/plugin/aot/bun.d.ts +8 -1
  105. package/dist/plugin/aot/bun.js +16 -9
  106. package/dist/plugin/aot/bun.mjs +17 -10
  107. package/dist/plugin/aot/core.d.ts +52 -60
  108. package/dist/plugin/aot/core.js +208 -109
  109. package/dist/plugin/aot/core.mjs +205 -111
  110. package/dist/plugin/aot/esbuild.js +8 -5
  111. package/dist/plugin/aot/esbuild.mjs +9 -6
  112. package/dist/plugin/aot/hooks.d.ts +6 -17
  113. package/dist/plugin/aot/hooks.js +36 -14
  114. package/dist/plugin/aot/hooks.mjs +37 -16
  115. package/dist/plugin/aot/rspack-loader.d.ts +1 -5
  116. package/dist/plugin/aot/rspack-loader.js +1 -10
  117. package/dist/plugin/aot/rspack-loader.mjs +1 -10
  118. package/dist/plugin/aot/rspack.js +2 -5
  119. package/dist/plugin/aot/rspack.mjs +3 -6
  120. package/dist/plugin/aot/source.d.ts +6 -42
  121. package/dist/plugin/aot/source.js +71 -71
  122. package/dist/plugin/aot/source.mjs +72 -72
  123. package/dist/plugin/aot/treeshake.js +2 -6
  124. package/dist/plugin/aot/treeshake.mjs +2 -6
  125. package/dist/plugin/aot/unplugin.d.ts +1 -4
  126. package/dist/plugin/aot/unplugin.js +4 -13
  127. package/dist/plugin/aot/unplugin.mjs +4 -13
  128. package/dist/plugin/aot/vite.d.ts +2 -6
  129. package/dist/plugin/aot/worker.js +2 -2
  130. package/dist/plugin/aot/worker.mjs +2 -2
  131. package/dist/plugin/auto-head.js +1 -10
  132. package/dist/plugin/auto-head.mjs +1 -10
  133. package/dist/plugin/trace.d.ts +2 -1
  134. package/dist/route-table.d.ts +3 -0
  135. package/dist/route-table.js +16 -11
  136. package/dist/route-table.mjs +16 -11
  137. package/dist/schema-snapshot.d.ts +0 -4
  138. package/dist/schema-snapshot.js +32 -49
  139. package/dist/schema-snapshot.mjs +32 -49
  140. package/dist/sucrose.d.ts +6 -55
  141. package/dist/sucrose.js +103 -731
  142. package/dist/sucrose.mjs +102 -724
  143. package/dist/trace.d.ts +5 -8
  144. package/dist/trace.js +23 -134
  145. package/dist/trace.mjs +24 -135
  146. package/dist/type/bridge-live.d.ts +4 -2
  147. package/dist/type/bridge-live.js +6 -3
  148. package/dist/type/bridge-live.mjs +4 -2
  149. package/dist/type/bridge.d.ts +6 -4
  150. package/dist/type/bridge.js +17 -9
  151. package/dist/type/bridge.mjs +5 -3
  152. package/dist/type/coerce-plan.d.ts +5 -5
  153. package/dist/type/coerce-plan.js +41 -39
  154. package/dist/type/coerce-plan.mjs +43 -39
  155. package/dist/type/coerce.d.ts +3 -7
  156. package/dist/type/coerce.js +18 -75
  157. package/dist/type/coerce.mjs +19 -76
  158. package/dist/type/compat.d.ts +3 -0
  159. package/dist/type/compat.js +23 -14
  160. package/dist/type/compat.mjs +20 -10
  161. package/dist/type/elysia/array-buffer.d.ts +4 -1
  162. package/dist/type/elysia/array-buffer.js +17 -17
  163. package/dist/type/elysia/array-buffer.mjs +17 -17
  164. package/dist/type/elysia/array-string.js +2 -40
  165. package/dist/type/elysia/array-string.mjs +2 -39
  166. package/dist/type/elysia/array.js +5 -9
  167. package/dist/type/elysia/array.mjs +5 -9
  168. package/dist/type/elysia/boolean-string.js +2 -3
  169. package/dist/type/elysia/boolean-string.mjs +1 -1
  170. package/dist/type/elysia/boolean.js +3 -12
  171. package/dist/type/elysia/boolean.mjs +3 -11
  172. package/dist/type/elysia/cookie.d.ts +3 -4
  173. package/dist/type/elysia/cookie.js +5 -15
  174. package/dist/type/elysia/cookie.mjs +5 -15
  175. package/dist/type/elysia/date.js +13 -20
  176. package/dist/type/elysia/date.mjs +10 -16
  177. package/dist/type/elysia/file-type.d.ts +11 -4
  178. package/dist/type/elysia/file-type.js +17 -2
  179. package/dist/type/elysia/file-type.mjs +17 -3
  180. package/dist/type/elysia/file.d.ts +1 -3
  181. package/dist/type/elysia/file.js +11 -27
  182. package/dist/type/elysia/file.mjs +11 -12
  183. package/dist/type/elysia/files.js +7 -11
  184. package/dist/type/elysia/files.mjs +7 -10
  185. package/dist/type/elysia/form.js +2 -3
  186. package/dist/type/elysia/form.mjs +3 -3
  187. package/dist/type/elysia/integer-string.d.ts +1 -1
  188. package/dist/type/elysia/integer-string.js +4 -30
  189. package/dist/type/elysia/integer-string.mjs +5 -30
  190. package/dist/type/elysia/integer.js +3 -12
  191. package/dist/type/elysia/integer.mjs +3 -11
  192. package/dist/type/elysia/intersect.js +0 -5
  193. package/dist/type/elysia/intersect.mjs +0 -5
  194. package/dist/type/elysia/json-string.d.ts +7 -0
  195. package/dist/type/elysia/json-string.js +47 -0
  196. package/dist/type/elysia/json-string.mjs +46 -0
  197. package/dist/type/elysia/keep-config.d.ts +14 -0
  198. package/dist/type/elysia/keep-config.js +62 -0
  199. package/dist/type/elysia/keep-config.mjs +53 -0
  200. package/dist/type/elysia/maybe-empty.js +3 -4
  201. package/dist/type/elysia/maybe-empty.mjs +1 -1
  202. package/dist/type/elysia/nullable.js +2 -3
  203. package/dist/type/elysia/nullable.mjs +1 -1
  204. package/dist/type/elysia/number.d.ts +2 -1
  205. package/dist/type/elysia/number.js +19 -11
  206. package/dist/type/elysia/number.mjs +18 -10
  207. package/dist/type/elysia/numeric-enum.d.ts +1 -1
  208. package/dist/type/elysia/numeric-enum.js +4 -5
  209. package/dist/type/elysia/numeric-enum.mjs +3 -3
  210. package/dist/type/elysia/numeric.d.ts +4 -2
  211. package/dist/type/elysia/numeric.js +20 -17
  212. package/dist/type/elysia/numeric.mjs +19 -16
  213. package/dist/type/elysia/object-string.js +2 -37
  214. package/dist/type/elysia/object-string.mjs +2 -36
  215. package/dist/type/elysia/object.js +5 -9
  216. package/dist/type/elysia/object.mjs +5 -9
  217. package/dist/type/elysia/optional.js +8 -8
  218. package/dist/type/elysia/optional.mjs +7 -7
  219. package/dist/type/elysia/problem.d.ts +20 -0
  220. package/dist/type/elysia/problem.js +25 -0
  221. package/dist/type/elysia/problem.mjs +24 -0
  222. package/dist/type/elysia/string.js +4 -3
  223. package/dist/type/elysia/string.mjs +4 -2
  224. package/dist/type/elysia/uint8-array.d.ts +1 -1
  225. package/dist/type/elysia/uint8-array.js +5 -20
  226. package/dist/type/elysia/uint8-array.mjs +5 -19
  227. package/dist/type/elysia/union-enum.js +7 -8
  228. package/dist/type/elysia/union-enum.mjs +6 -6
  229. package/dist/type/elysia/union.js +0 -5
  230. package/dist/type/elysia/union.mjs +0 -5
  231. package/dist/type/elysia/utils.d.ts +2 -4
  232. package/dist/type/elysia/utils.js +10 -21
  233. package/dist/type/elysia/utils.mjs +7 -15
  234. package/dist/type/exports.d.ts +4 -2
  235. package/dist/type/exports.js +23 -2
  236. package/dist/type/exports.mjs +11 -2
  237. package/dist/type/index.d.ts +10 -2
  238. package/dist/type/index.js +62 -15
  239. package/dist/type/index.mjs +65 -11
  240. package/dist/type/shared.d.ts +3 -9
  241. package/dist/type/shared.js +44 -97
  242. package/dist/type/shared.mjs +43 -97
  243. package/dist/type/sync-require.d.ts +11 -0
  244. package/dist/type/sync-require.js +14 -0
  245. package/dist/type/sync-require.mjs +12 -0
  246. package/dist/type/typebox-system-lite.d.ts +2 -0
  247. package/dist/type/typebox-system-lite.js +34 -0
  248. package/dist/type/typebox-system-lite.mjs +3 -0
  249. package/dist/type/typebox-system-require.d.ts +7 -0
  250. package/dist/type/typebox-system-require.js +24 -0
  251. package/dist/type/typebox-system-require.mjs +23 -0
  252. package/dist/type/typebox-type-live.d.ts +11 -0
  253. package/dist/type/typebox-type-live.js +45 -0
  254. package/dist/type/typebox-type-live.mjs +20 -0
  255. package/dist/type/typebox-type.d.ts +34 -0
  256. package/dist/type/typebox-type.js +199 -0
  257. package/dist/type/typebox-type.mjs +86 -0
  258. package/dist/type/typebox-value-live.d.ts +11 -0
  259. package/dist/type/typebox-value-live.js +31 -0
  260. package/dist/type/typebox-value-live.mjs +13 -0
  261. package/dist/type/typebox-value-ops.d.ts +4 -0
  262. package/dist/type/typebox-value-ops.js +90 -0
  263. package/dist/type/typebox-value-ops.mjs +5 -0
  264. package/dist/type/typebox-value-require.d.ts +8 -0
  265. package/dist/type/typebox-value-require.js +28 -0
  266. package/dist/type/typebox-value-require.mjs +25 -0
  267. package/dist/type/typebox-value.d.ts +35 -0
  268. package/dist/type/typebox-value.js +161 -0
  269. package/dist/type/typebox-value.mjs +74 -0
  270. package/dist/type/utils.js +1 -10
  271. package/dist/type/utils.mjs +1 -10
  272. package/dist/type/validator/clean-safe.d.ts +2 -4
  273. package/dist/type/validator/clean-safe.js +15 -11
  274. package/dist/type/validator/clean-safe.mjs +16 -10
  275. package/dist/type/validator/custom-error.js +12 -16
  276. package/dist/type/validator/custom-error.mjs +11 -14
  277. package/dist/type/validator/default-precompute.d.ts +9 -1
  278. package/dist/type/validator/default-precompute.js +40 -77
  279. package/dist/type/validator/default-precompute.mjs +37 -74
  280. package/dist/type/validator/exact-mirror-live.d.ts +8 -0
  281. package/dist/type/validator/exact-mirror-live.js +22 -0
  282. package/dist/type/validator/exact-mirror-live.mjs +17 -0
  283. package/dist/type/validator/exact-mirror-require.d.ts +4 -0
  284. package/dist/type/validator/exact-mirror-require.js +11 -0
  285. package/dist/type/validator/exact-mirror-require.mjs +9 -0
  286. package/dist/type/validator/exact-mirror.js +8 -8
  287. package/dist/type/validator/exact-mirror.mjs +9 -8
  288. package/dist/type/validator/frozen-check.js +5 -6
  289. package/dist/type/validator/frozen-check.mjs +6 -7
  290. package/dist/type/validator/index.d.ts +1 -0
  291. package/dist/type/validator/index.js +169 -166
  292. package/dist/type/validator/index.mjs +162 -158
  293. package/dist/type/validator/string-codec-aot.d.ts +2 -1
  294. package/dist/type/validator/string-codec-aot.js +8 -2
  295. package/dist/type/validator/string-codec-aot.mjs +7 -2
  296. package/dist/type/validator/validator-cache.d.ts +5 -4
  297. package/dist/type/validator/validator-cache.js +41 -24
  298. package/dist/type/validator/validator-cache.mjs +40 -22
  299. package/dist/types.d.ts +263 -95
  300. package/dist/universal/constants.d.ts +2 -1
  301. package/dist/universal/constants.js +3 -1
  302. package/dist/universal/constants.mjs +2 -1
  303. package/dist/universal/env.js +2 -3
  304. package/dist/universal/env.mjs +2 -3
  305. package/dist/universal/file.d.ts +6 -4
  306. package/dist/universal/file.js +11 -16
  307. package/dist/universal/file.mjs +12 -16
  308. package/dist/universal/index.d.ts +2 -2
  309. package/dist/universal/is-production.d.ts +1 -2
  310. package/dist/universal/is-production.js +1 -3
  311. package/dist/universal/is-production.mjs +2 -3
  312. package/dist/universal/server.d.ts +0 -272
  313. package/dist/utils.d.ts +43 -7
  314. package/dist/utils.js +181 -126
  315. package/dist/utils.mjs +168 -126
  316. package/dist/validator/index.d.ts +1 -1
  317. package/dist/validator/index.js +17 -30
  318. package/dist/validator/index.mjs +18 -31
  319. package/dist/validator/route.js +2 -1
  320. package/dist/validator/route.mjs +2 -1
  321. package/dist/ws/context.d.ts +8 -1
  322. package/dist/ws/context.js +68 -44
  323. package/dist/ws/context.mjs +67 -44
  324. package/dist/ws/parser.js +10 -20
  325. package/dist/ws/parser.mjs +10 -20
  326. package/dist/ws/route.d.ts +2 -2
  327. package/dist/ws/route.js +249 -141
  328. package/dist/ws/route.mjs +254 -146
  329. package/dist/ws/types.d.ts +2 -2
  330. package/package.json +23 -49
  331. package/dist/compile/analysis-cache.d.ts +0 -6
  332. package/dist/compile/analysis-cache.js +0 -12
  333. package/dist/compile/analysis-cache.mjs +0 -11
  334. package/dist/cookie/index.d.ts +0 -7
  335. package/dist/cookie/index.js +0 -13
  336. package/dist/cookie/index.mjs +0 -7
  337. package/dist/handler/index.d.ts +0 -2
  338. package/dist/handler/index.js +0 -5
  339. package/dist/handler/index.mjs +0 -3
@@ -1,24 +1,13 @@
1
- import { CaptureImpl, CapturedHandler, CapturedValidator, CompiledSnapshot } from "./aot.js";
1
+ import { CapturedHandler, CapturedValidator, CompiledSnapshot } from "./aot.js";
2
2
 
3
3
  //#region src/compile/aot-capture.d.ts
4
- declare function resetCompactErrorWarnings(): void;
5
4
  declare function beginValidatorCapture(): void;
6
5
  declare function abortCapture(): void;
7
6
  declare function endValidatorCapture(): CapturedValidator[];
8
7
  declare function endHandlerCapture(): CapturedHandler[];
9
- /** @internal deterministic session/capture assertions. */
10
- declare const getCompilerSessionDiagnostics: () => {
11
- active: boolean;
12
- appAttached: boolean;
13
- validators: number;
14
- handlers: number;
15
- sucrose: number;
16
- };
17
8
  /** @internal preserve registry around in-process AOT analysis */
18
9
  declare const snapshotCompiled: () => CompiledSnapshot;
19
10
  /** @internal restore registry after in-process AOT analysis */
20
11
  declare function restoreCompiled(snapshot: CompiledSnapshot): void;
21
- declare const impl: CaptureImpl;
22
- declare function installCaptureImpl(): void;
23
12
  //#endregion
24
- export { abortCapture, beginValidatorCapture, impl as captureImplementation, endHandlerCapture, endValidatorCapture, getCompilerSessionDiagnostics, installCaptureImpl, resetCompactErrorWarnings, restoreCompiled, snapshotCompiled };
13
+ export { abortCapture, beginValidatorCapture, endHandlerCapture, endValidatorCapture, restoreCompiled, snapshotCompiled };
@@ -3,9 +3,9 @@ const require_runtime = require('../_virtual/_rolldown/runtime.js');
3
3
  const require_utils = require('../utils.js');
4
4
  const require_universal_env = require('../universal/env.js');
5
5
  const require_compile_aot = require('./aot.js');
6
- const require_type_elysia_file_type = require('../type/elysia/file-type.js');
7
6
  const require_compile_handler_frozen_validator = require('./handler/frozen-validator.js');
8
7
  const require_type_coerce = require('../type/coerce.js');
8
+ const require_type_elysia_file_type = require('../type/elysia/file-type.js');
9
9
  const require_type_validator_default_precompute = require('../type/validator/default-precompute.js');
10
10
  const require_compile_aot_reconstruct = require('./aot-reconstruct.js');
11
11
  const require_compile_aot_emit = require('./aot-emit.js');
@@ -13,8 +13,8 @@ const require_type_validator_frozen_check = require('../type/validator/frozen-ch
13
13
  const require_type_validator_custom_error = require('../type/validator/custom-error.js');
14
14
  const require_type_validator_exact_mirror = require('../type/validator/exact-mirror.js');
15
15
  const require_type_validator_string_codec_aot = require('../type/validator/string-codec-aot.js');
16
- let typebox_value = require("typebox/value");
17
16
  let typebox_schema = require("typebox/schema");
17
+ let typebox_value = require("typebox/value");
18
18
 
19
19
  //#region src/compile/aot-capture.ts
20
20
  function emptyContainers(node, depth) {
@@ -124,13 +124,14 @@ function sourceOnlyValidator(schema) {
124
124
  }
125
125
  function maybeCapture(args) {
126
126
  const { aot, slot, hasRef, originalSchema, schema, hasCodec, hasDefault, coerces, normalize, buildResult } = args;
127
+ const loc = {
128
+ method: aot.method,
129
+ path: aot.path,
130
+ slot
131
+ };
127
132
  if (hasCodec && !hasRef && coerces && normalize !== false && normalize !== "typebox") {
128
133
  const plan = require_type_coerce.captureCoercePlan(originalSchema, schema);
129
- if (plan && externalsShape(require_type_coerce.buildCoercedFromPlan(originalSchema, plan)) === externalsShape(schema)) require_compile_aot.Capture.set({
130
- method: aot.method,
131
- path: aot.path,
132
- slot
133
- }, { coercePlan: plan });
134
+ if (plan && externalsShape(require_type_coerce.buildCoercedFromPlan(originalSchema, plan)) === externalsShape(schema)) require_compile_aot.Capture.set(loc, { coercePlan: plan });
134
135
  }
135
136
  const defaultFastPathCapture = {
136
137
  precomputeSafe: void 0,
@@ -151,30 +152,14 @@ function maybeCapture(args) {
151
152
  defaultFastPathCapture.objectDefaultMerger = defaults.ms ?? (defaults.pod !== void 0 ? require_type_validator_default_precompute.buildObjectDefaultMergeSource(defaults.pod) : void 0);
152
153
  }
153
154
  }
154
- require_compile_aot.Capture.set({
155
- method: aot.method,
156
- path: aot.path,
157
- slot
158
- }, defaultFastPathCapture);
155
+ require_compile_aot.Capture.set(loc, defaultFastPathCapture);
159
156
  const customErrors = require_type_validator_custom_error.captureCustomErrors(schema);
160
- if (customErrors) require_compile_aot.Capture.set({
161
- method: aot.method,
162
- path: aot.path,
163
- slot
164
- }, { customErrors });
157
+ if (customErrors) require_compile_aot.Capture.set(loc, { customErrors });
165
158
  const innerCodecs = require_type_validator_string_codec_aot.captureStringCodecEntries(schema, args.sanitize);
166
- if (innerCodecs) require_compile_aot.Capture.set({
167
- method: aot.method,
168
- path: aot.path,
169
- slot
170
- }, { innerCodecs });
159
+ if (innerCodecs) require_compile_aot.Capture.set(loc, { innerCodecs });
171
160
  const cf = require_type_validator_frozen_check.buildFrozenCheck(buildResult, schema);
172
161
  if (!cf) return;
173
- require_compile_aot.Capture.set({
174
- method: aot.method,
175
- path: aot.path,
176
- slot
177
- }, {
162
+ require_compile_aot.Capture.set(loc, {
178
163
  ...cf,
179
164
  async: buildResult.external.variables.some(require_type_elysia_file_type.isAsyncPredicate),
180
165
  hasDefault,
@@ -187,27 +172,24 @@ function captureMirror(schema, aot, slot, sanitize) {
187
172
  if (!createMirror) return;
188
173
  try {
189
174
  const emitted = createMirror(schema, {
190
- Compile: typebox_schema.Compile,
175
+ Compile: require_type_validator_string_codec_aot.compileWithBuild,
191
176
  sanitize,
192
177
  emit: true
193
178
  });
194
179
  if (typeof emitted?.source === "string") {
195
180
  const ext = emitted.externals;
196
- if (!ext) require_compile_aot.Capture.set({
181
+ const loc = {
197
182
  method: aot.method,
198
183
  path: aot.path,
199
184
  slot
200
- }, { mirror: {
185
+ };
186
+ if (!ext) require_compile_aot.Capture.set(loc, { mirror: {
201
187
  source: emitted.source,
202
188
  hasExternals: false
203
189
  } });
204
190
  else if (ext.unions && !ext.hof) {
205
191
  const u = require_compile_aot_emit.captureMirrorUnions(schema, ext.unions);
206
- if (u) require_compile_aot.Capture.set({
207
- method: aot.method,
208
- path: aot.path,
209
- slot
210
- }, { mirror: {
192
+ if (u) require_compile_aot.Capture.set(loc, { mirror: {
211
193
  source: emitted.source,
212
194
  hasExternals: true,
213
195
  u
@@ -222,7 +204,7 @@ function captureCodecMirror(schema, aot, slot, sanitize, dir) {
222
204
  const dirOpt = dir === "decode" ? { decode: true } : { encode: true };
223
205
  try {
224
206
  const emitted = createMirror(schema, {
225
- Compile: typebox_schema.Compile,
207
+ Compile: require_type_validator_string_codec_aot.compileWithBuild,
226
208
  sanitize,
227
209
  ...dirOpt,
228
210
  emit: true
@@ -254,9 +236,6 @@ function captureCodecMirror(schema, aot, slot, sanitize, dir) {
254
236
  }
255
237
  const compactErrorWarned = /* @__PURE__ */ new Set();
256
238
  const isVerboseAotWarnings = () => !!require_universal_env.env.ELYSIA_AOT_VERBOSE;
257
- function resetCompactErrorWarnings() {
258
- compactErrorWarned.clear();
259
- }
260
239
  function warnCompactErrorLoss(aot, slot) {
261
240
  const key = `${aot.method}\0${aot.path}\0${slot}`;
262
241
  if (compactErrorWarned.has(key)) return;
@@ -266,22 +245,19 @@ function warnCompactErrorLoss(aot, slot) {
266
245
  function flushCompactErrorWarnings() {
267
246
  const total = compactErrorWarned.size;
268
247
  if (total > 0 && !isVerboseAotWarnings()) console.warn(`[elysia-aot]: ${total} sealed validator slot${total === 1 ? "" : "s"} ${total === 1 ? "carries" : "carry"} a coercion/codec schema; 422 error details will be coarse (best-effort). Set ELYSIA_AOT_VERBOSE=1 for per-route detail.`);
269
- resetCompactErrorWarnings();
248
+ compactErrorWarned.clear();
270
249
  }
271
250
  function captureBridgeFree(aot, slot, rawSchema) {
272
- const captured = require_compile_aot.Capture.get({
251
+ const loc = {
273
252
  method: aot.method,
274
253
  path: aot.path,
275
254
  slot
276
- });
255
+ };
256
+ const captured = require_compile_aot.Capture.get(loc);
277
257
  if (captured) {
278
258
  const coerced = captured.coercePlan && typeof rawSchema !== "string" ? require_type_coerce.buildCoercedFromPlan(rawSchema, captured.coercePlan) : rawSchema;
279
259
  const bridgeFree = require_compile_handler_frozen_validator.isCapturedBridgeFree(captured, rawSchema, coerced);
280
- require_compile_aot.Capture.set({
281
- method: aot.method,
282
- path: aot.path,
283
- slot
284
- }, { bridgeFree });
260
+ require_compile_aot.Capture.set(loc, { bridgeFree });
285
261
  if (bridgeFree && !require_compile_handler_frozen_validator.isCompactWalkable(coerced)) warnCompactErrorLoss(aot, slot);
286
262
  }
287
263
  }
@@ -333,44 +309,25 @@ function endHandlerCapture() {
333
309
  }
334
310
  return captured;
335
311
  }
336
- /** @internal deterministic session/capture assertions. */
337
- const getCompilerSessionDiagnostics = () => {
338
- const session = require_compile_aot.CompilerState.session;
339
- return {
340
- active: session !== void 0,
341
- appAttached: session?.app !== void 0,
342
- validators: session?.capture?.size ?? 0,
343
- handlers: session?.handlerCapture?.size ?? 0,
344
- sucrose: session?.sucroseCache.size ?? 0
345
- };
346
- };
347
312
  /** @internal preserve registry around in-process AOT analysis */
348
313
  const snapshotCompiled = () => require_compile_aot.CompilerState.registry;
349
314
  /** @internal restore registry after in-process AOT analysis */
350
315
  function restoreCompiled(snapshot) {
351
316
  require_compile_aot.CompilerState.registry = snapshot;
352
317
  }
353
- const impl = {
318
+ require_compile_aot.setCaptureImpl({
354
319
  sourceOnlyValidator,
355
320
  maybeCapture,
356
321
  captureMirror,
357
322
  captureCodecMirror,
358
323
  captureBridgeFree
359
- };
360
- function installCaptureImpl() {
361
- require_compile_aot.setCaptureImpl(impl);
362
- require_compile_aot_emit.installReconstructImpl();
363
- }
364
- installCaptureImpl();
324
+ });
325
+ require_compile_aot_emit.installReconstructImpl();
365
326
 
366
327
  //#endregion
367
328
  exports.abortCapture = abortCapture;
368
329
  exports.beginValidatorCapture = beginValidatorCapture;
369
- exports.captureImplementation = impl;
370
330
  exports.endHandlerCapture = endHandlerCapture;
371
331
  exports.endValidatorCapture = endValidatorCapture;
372
- exports.getCompilerSessionDiagnostics = getCompilerSessionDiagnostics;
373
- exports.installCaptureImpl = installCaptureImpl;
374
- exports.resetCompactErrorWarnings = resetCompactErrorWarnings;
375
332
  exports.restoreCompiled = restoreCompiled;
376
333
  exports.snapshotCompiled = snapshotCompiled;
@@ -1,18 +1,18 @@
1
1
  import { nullObject } from "../utils.mjs";
2
2
  import { env } from "../universal/env.mjs";
3
3
  import { Capture, CompilerState, aotActivationError, captureImpl, setCaptureImpl } from "./aot.mjs";
4
- import { isAsyncPredicate } from "../type/elysia/file-type.mjs";
5
4
  import { isCapturedBridgeFree, isCompactWalkable } from "./handler/frozen-validator.mjs";
6
5
  import { buildCoercedFromPlan, captureCoercePlan } from "../type/coerce.mjs";
6
+ import { isAsyncPredicate } from "../type/elysia/file-type.mjs";
7
7
  import { applyPrecomputed, buildDefaultClonerSource, buildObjectDefaultMergeSource, canonical, createMergerFromSource, setDefaultProbeImpl, verifyPreallocatableDefault } from "../type/validator/default-precompute.mjs";
8
8
  import { collectExternals } from "./aot-reconstruct.mjs";
9
9
  import { captureMirrorCodecs, captureMirrorUnions, installReconstructImpl } from "./aot-emit.mjs";
10
10
  import { buildFrozenCheck } from "../type/validator/frozen-check.mjs";
11
11
  import { captureCustomErrors } from "../type/validator/custom-error.mjs";
12
12
  import { getExactMirror } from "../type/validator/exact-mirror.mjs";
13
- import { captureStringCodecEntries } from "../type/validator/string-codec-aot.mjs";
14
- import { Default } from "typebox/value";
13
+ import { captureStringCodecEntries, compileWithBuild } from "../type/validator/string-codec-aot.mjs";
15
14
  import { Build, Compile } from "typebox/schema";
15
+ import { Default } from "typebox/value";
16
16
 
17
17
  //#region src/compile/aot-capture.ts
18
18
  function emptyContainers(node, depth) {
@@ -122,13 +122,14 @@ function sourceOnlyValidator(schema) {
122
122
  }
123
123
  function maybeCapture(args) {
124
124
  const { aot, slot, hasRef, originalSchema, schema, hasCodec, hasDefault, coerces, normalize, buildResult } = args;
125
+ const loc = {
126
+ method: aot.method,
127
+ path: aot.path,
128
+ slot
129
+ };
125
130
  if (hasCodec && !hasRef && coerces && normalize !== false && normalize !== "typebox") {
126
131
  const plan = captureCoercePlan(originalSchema, schema);
127
- if (plan && externalsShape(buildCoercedFromPlan(originalSchema, plan)) === externalsShape(schema)) Capture.set({
128
- method: aot.method,
129
- path: aot.path,
130
- slot
131
- }, { coercePlan: plan });
132
+ if (plan && externalsShape(buildCoercedFromPlan(originalSchema, plan)) === externalsShape(schema)) Capture.set(loc, { coercePlan: plan });
132
133
  }
133
134
  const defaultFastPathCapture = {
134
135
  precomputeSafe: void 0,
@@ -149,30 +150,14 @@ function maybeCapture(args) {
149
150
  defaultFastPathCapture.objectDefaultMerger = defaults.ms ?? (defaults.pod !== void 0 ? buildObjectDefaultMergeSource(defaults.pod) : void 0);
150
151
  }
151
152
  }
152
- Capture.set({
153
- method: aot.method,
154
- path: aot.path,
155
- slot
156
- }, defaultFastPathCapture);
153
+ Capture.set(loc, defaultFastPathCapture);
157
154
  const customErrors = captureCustomErrors(schema);
158
- if (customErrors) Capture.set({
159
- method: aot.method,
160
- path: aot.path,
161
- slot
162
- }, { customErrors });
155
+ if (customErrors) Capture.set(loc, { customErrors });
163
156
  const innerCodecs = captureStringCodecEntries(schema, args.sanitize);
164
- if (innerCodecs) Capture.set({
165
- method: aot.method,
166
- path: aot.path,
167
- slot
168
- }, { innerCodecs });
157
+ if (innerCodecs) Capture.set(loc, { innerCodecs });
169
158
  const cf = buildFrozenCheck(buildResult, schema);
170
159
  if (!cf) return;
171
- Capture.set({
172
- method: aot.method,
173
- path: aot.path,
174
- slot
175
- }, {
160
+ Capture.set(loc, {
176
161
  ...cf,
177
162
  async: buildResult.external.variables.some(isAsyncPredicate),
178
163
  hasDefault,
@@ -185,27 +170,24 @@ function captureMirror(schema, aot, slot, sanitize) {
185
170
  if (!createMirror) return;
186
171
  try {
187
172
  const emitted = createMirror(schema, {
188
- Compile,
173
+ Compile: compileWithBuild,
189
174
  sanitize,
190
175
  emit: true
191
176
  });
192
177
  if (typeof emitted?.source === "string") {
193
178
  const ext = emitted.externals;
194
- if (!ext) Capture.set({
179
+ const loc = {
195
180
  method: aot.method,
196
181
  path: aot.path,
197
182
  slot
198
- }, { mirror: {
183
+ };
184
+ if (!ext) Capture.set(loc, { mirror: {
199
185
  source: emitted.source,
200
186
  hasExternals: false
201
187
  } });
202
188
  else if (ext.unions && !ext.hof) {
203
189
  const u = captureMirrorUnions(schema, ext.unions);
204
- if (u) Capture.set({
205
- method: aot.method,
206
- path: aot.path,
207
- slot
208
- }, { mirror: {
190
+ if (u) Capture.set(loc, { mirror: {
209
191
  source: emitted.source,
210
192
  hasExternals: true,
211
193
  u
@@ -220,7 +202,7 @@ function captureCodecMirror(schema, aot, slot, sanitize, dir) {
220
202
  const dirOpt = dir === "decode" ? { decode: true } : { encode: true };
221
203
  try {
222
204
  const emitted = createMirror(schema, {
223
- Compile,
205
+ Compile: compileWithBuild,
224
206
  sanitize,
225
207
  ...dirOpt,
226
208
  emit: true
@@ -252,9 +234,6 @@ function captureCodecMirror(schema, aot, slot, sanitize, dir) {
252
234
  }
253
235
  const compactErrorWarned = /* @__PURE__ */ new Set();
254
236
  const isVerboseAotWarnings = () => !!env.ELYSIA_AOT_VERBOSE;
255
- function resetCompactErrorWarnings() {
256
- compactErrorWarned.clear();
257
- }
258
237
  function warnCompactErrorLoss(aot, slot) {
259
238
  const key = `${aot.method}\0${aot.path}\0${slot}`;
260
239
  if (compactErrorWarned.has(key)) return;
@@ -264,22 +243,19 @@ function warnCompactErrorLoss(aot, slot) {
264
243
  function flushCompactErrorWarnings() {
265
244
  const total = compactErrorWarned.size;
266
245
  if (total > 0 && !isVerboseAotWarnings()) console.warn(`[elysia-aot]: ${total} sealed validator slot${total === 1 ? "" : "s"} ${total === 1 ? "carries" : "carry"} a coercion/codec schema; 422 error details will be coarse (best-effort). Set ELYSIA_AOT_VERBOSE=1 for per-route detail.`);
267
- resetCompactErrorWarnings();
246
+ compactErrorWarned.clear();
268
247
  }
269
248
  function captureBridgeFree(aot, slot, rawSchema) {
270
- const captured = Capture.get({
249
+ const loc = {
271
250
  method: aot.method,
272
251
  path: aot.path,
273
252
  slot
274
- });
253
+ };
254
+ const captured = Capture.get(loc);
275
255
  if (captured) {
276
256
  const coerced = captured.coercePlan && typeof rawSchema !== "string" ? buildCoercedFromPlan(rawSchema, captured.coercePlan) : rawSchema;
277
257
  const bridgeFree = isCapturedBridgeFree(captured, rawSchema, coerced);
278
- Capture.set({
279
- method: aot.method,
280
- path: aot.path,
281
- slot
282
- }, { bridgeFree });
258
+ Capture.set(loc, { bridgeFree });
283
259
  if (bridgeFree && !isCompactWalkable(coerced)) warnCompactErrorLoss(aot, slot);
284
260
  }
285
261
  }
@@ -331,35 +307,20 @@ function endHandlerCapture() {
331
307
  }
332
308
  return captured;
333
309
  }
334
- /** @internal deterministic session/capture assertions. */
335
- const getCompilerSessionDiagnostics = () => {
336
- const session = CompilerState.session;
337
- return {
338
- active: session !== void 0,
339
- appAttached: session?.app !== void 0,
340
- validators: session?.capture?.size ?? 0,
341
- handlers: session?.handlerCapture?.size ?? 0,
342
- sucrose: session?.sucroseCache.size ?? 0
343
- };
344
- };
345
310
  /** @internal preserve registry around in-process AOT analysis */
346
311
  const snapshotCompiled = () => CompilerState.registry;
347
312
  /** @internal restore registry after in-process AOT analysis */
348
313
  function restoreCompiled(snapshot) {
349
314
  CompilerState.registry = snapshot;
350
315
  }
351
- const impl = {
316
+ setCaptureImpl({
352
317
  sourceOnlyValidator,
353
318
  maybeCapture,
354
319
  captureMirror,
355
320
  captureCodecMirror,
356
321
  captureBridgeFree
357
- };
358
- function installCaptureImpl() {
359
- setCaptureImpl(impl);
360
- installReconstructImpl();
361
- }
362
- installCaptureImpl();
322
+ });
323
+ installReconstructImpl();
363
324
 
364
325
  //#endregion
365
- export { abortCapture, beginValidatorCapture, impl as captureImplementation, endHandlerCapture, endValidatorCapture, getCompilerSessionDiagnostics, installCaptureImpl, resetCompactErrorWarnings, restoreCompiled, snapshotCompiled };
326
+ export { abortCapture, beginValidatorCapture, endHandlerCapture, endValidatorCapture, restoreCompiled, snapshotCompiled };
@@ -6,6 +6,14 @@ declare function reconstructCheck(build: CheckBuildResult): {
6
6
  value: string;
7
7
  };
8
8
  declare function externalsMatch(a: unknown[], b: unknown[]): boolean;
9
+ /**
10
+ * Align a TypeBox build's externals with the layout the runtime rebuilds from
11
+ * the schema (`collectExternals`). Returns the build as is when they already
12
+ * match, a copy with a prepended remap when TypeBox >= 1.3.31 passed a lone
13
+ * refinement instead of its `~refine` array, or undefined (don't freeze) when
14
+ * a slot can't be proven equal, e.g. a 1.3.31+ format function
15
+ */
16
+ declare function alignBuildExternals(build: CheckBuildResult, schema: unknown): CheckBuildResult | undefined;
9
17
  declare const Source: {
10
18
  readonly checkFactory: (identifier: string, code: string) => string;
11
19
  readonly checkCode: (defs: string, value: string) => string;
@@ -13,12 +21,6 @@ declare const Source: {
13
21
  readonly mirrorFactory: (source: string, hasExternals: boolean) => string;
14
22
  readonly bothFactory: (identifier: string, checkDefs: string, checkValue: string, mirrorSource: string, mirrorHasExternals: boolean) => string;
15
23
  };
16
- /**
17
- * verify that mirror unions can be reconstructed in build time
18
- *
19
- * return undefined if not reconstructable
20
- * `truthUnions` is `mir.externals.unions` (compiled branches).
21
- */
22
24
  declare function captureMirrorUnions(schema: unknown, truthUnions: any[][]): {
23
25
  identifier: string;
24
26
  code: string;
@@ -26,4 +28,4 @@ declare function captureMirrorUnions(schema: unknown, truthUnions: any[][]): {
26
28
  declare function captureMirrorCodecs(schema: unknown, truthCodecs: Function[], dir?: 'decode' | 'encode'): boolean;
27
29
  declare function installReconstructImpl(): void;
28
30
  //#endregion
29
- export { Source, captureMirrorCodecs, captureMirrorUnions, externalsMatch, installReconstructImpl, reconstructCheck };
31
+ export { Source, alignBuildExternals, captureMirrorCodecs, captureMirrorUnions, externalsMatch, installReconstructImpl, reconstructCheck };
@@ -28,7 +28,7 @@ function reconstructCheckCode(build) {
28
28
  const { defs, value } = reconstructCheck(build);
29
29
  return checkCode(defs, value);
30
30
  }
31
- const checkFactorySource = (identifier, code) => `function(${identifier}){${code}}`;
31
+ const checkFactorySource = (identifier, code) => `(${identifier})=>{${code}}`;
32
32
  const handlerFactorySource = (alias, code) => `function(h${alias ? "," + alias : ""}){return ${code}}`;
33
33
  function externalsMatch(a, b) {
34
34
  if (a.length !== b.length) return false;
@@ -40,19 +40,46 @@ function externalsMatch(a, b) {
40
40
  if (x.source !== y.source || x.flags !== y.flags) return false;
41
41
  continue;
42
42
  }
43
- if (Array.isArray(x) && Array.isArray(y)) {
44
- if (x.length !== y.length) return false;
45
- let ok = true;
46
- for (let j = 0; j < x.length; j++) if (x[j] !== y[j]) {
47
- ok = false;
48
- break;
49
- }
50
- if (ok) continue;
51
- }
43
+ if (Array.isArray(x) && Array.isArray(y) && x.length === y.length && x.findIndex((v, j) => v !== y[j]) === -1) continue;
52
44
  return false;
53
45
  }
54
46
  return true;
55
47
  }
48
+ /**
49
+ * Align a TypeBox build's externals with the layout the runtime rebuilds from
50
+ * the schema (`collectExternals`). Returns the build as is when they already
51
+ * match, a copy with a prepended remap when TypeBox >= 1.3.31 passed a lone
52
+ * refinement instead of its `~refine` array, or undefined (don't freeze) when
53
+ * a slot can't be proven equal, e.g. a 1.3.31+ format function
54
+ */
55
+ function alignBuildExternals(build, schema) {
56
+ const variables = build.external.variables;
57
+ const canonical = require_compile_aot_reconstruct.collectExternals(schema);
58
+ const id = build.external.identifier;
59
+ if (!/^[A-Za-z_$][\w$]*$/.test(id)) return;
60
+ const slots = [];
61
+ let j = 0;
62
+ let same = variables.length === canonical.length;
63
+ for (let i = 0; i < variables.length; i++) {
64
+ const v = variables[i];
65
+ const c = canonical[j];
66
+ if (j < canonical.length && externalsMatch([c], [v])) slots.push(`${id}[${j++}]`);
67
+ else if (Array.isArray(c) && c.length === 1 && c[0] === v) {
68
+ slots.push(`${id}[${j++}][0]`);
69
+ same = false;
70
+ } else return;
71
+ }
72
+ if (j !== canonical.length) return;
73
+ if (same) return build;
74
+ return {
75
+ ...build,
76
+ functions: [`${id}=[${slots.join(",")}]`, ...build.functions],
77
+ external: {
78
+ identifier: id,
79
+ variables: canonical
80
+ }
81
+ };
82
+ }
56
83
  const mirrorFactorySource = (source, hasExternals) => hasExternals ? `function(d){${source}}` : `function(v){${source}}`;
57
84
  const bothFactorySource = (identifier, checkDefs, checkValue, mirrorSource, mirrorHasExternals) => `function(${identifier},d){${checkDefs}; return{check:${checkValue},clean:${mirrorHasExternals ? `(function(d){${mirrorSource}})(d)` : `function(v){${mirrorSource}}`}}}`;
58
85
  const Source = {
@@ -62,12 +89,6 @@ const Source = {
62
89
  mirrorFactory: mirrorFactorySource,
63
90
  bothFactory: bothFactorySource
64
91
  };
65
- /**
66
- * verify that mirror unions can be reconstructed in build time
67
- *
68
- * return undefined if not reconstructable
69
- * `truthUnions` is `mir.externals.unions` (compiled branches).
70
- */
71
92
  function captureMirrorUnions(schema, truthUnions) {
72
93
  const branchSchemas = require_compile_aot_reconstruct.collectMirrorUnions(schema);
73
94
  if (branchSchemas.length !== truthUnions.length) return;
@@ -76,9 +97,10 @@ function captureMirrorUnions(schema, truthUnions) {
76
97
  if (!branchSchemas[ui] || branchSchemas[ui].length !== truthUnions[ui].length) return;
77
98
  const branch = [];
78
99
  for (let i = 0; i < truthUnions[ui].length; i++) {
79
- const build = truthUnions[ui][i]?.buildResult;
80
- if (!build?.functions?.length || !build.entry) return;
81
- if (!externalsMatch(require_compile_aot_reconstruct.collectExternals(branchSchemas[ui][i]), build.external.variables)) return;
100
+ const raw = truthUnions[ui][i]?.buildResult;
101
+ if (!raw?.functions?.length || !raw.entry) return;
102
+ const build = alignBuildExternals(raw, branchSchemas[ui][i]);
103
+ if (!build) return;
82
104
  branch.push({
83
105
  identifier: build.external.identifier,
84
106
  code: reconstructCheckCode(build)
@@ -100,6 +122,7 @@ function installReconstructImpl() {
100
122
 
101
123
  //#endregion
102
124
  exports.Source = Source;
125
+ exports.alignBuildExternals = alignBuildExternals;
103
126
  exports.captureMirrorCodecs = captureMirrorCodecs;
104
127
  exports.captureMirrorUnions = captureMirrorUnions;
105
128
  exports.externalsMatch = externalsMatch;
@@ -27,7 +27,7 @@ function reconstructCheckCode(build) {
27
27
  const { defs, value } = reconstructCheck(build);
28
28
  return checkCode(defs, value);
29
29
  }
30
- const checkFactorySource = (identifier, code) => `function(${identifier}){${code}}`;
30
+ const checkFactorySource = (identifier, code) => `(${identifier})=>{${code}}`;
31
31
  const handlerFactorySource = (alias, code) => `function(h${alias ? "," + alias : ""}){return ${code}}`;
32
32
  function externalsMatch(a, b) {
33
33
  if (a.length !== b.length) return false;
@@ -39,19 +39,46 @@ function externalsMatch(a, b) {
39
39
  if (x.source !== y.source || x.flags !== y.flags) return false;
40
40
  continue;
41
41
  }
42
- if (Array.isArray(x) && Array.isArray(y)) {
43
- if (x.length !== y.length) return false;
44
- let ok = true;
45
- for (let j = 0; j < x.length; j++) if (x[j] !== y[j]) {
46
- ok = false;
47
- break;
48
- }
49
- if (ok) continue;
50
- }
42
+ if (Array.isArray(x) && Array.isArray(y) && x.length === y.length && x.findIndex((v, j) => v !== y[j]) === -1) continue;
51
43
  return false;
52
44
  }
53
45
  return true;
54
46
  }
47
+ /**
48
+ * Align a TypeBox build's externals with the layout the runtime rebuilds from
49
+ * the schema (`collectExternals`). Returns the build as is when they already
50
+ * match, a copy with a prepended remap when TypeBox >= 1.3.31 passed a lone
51
+ * refinement instead of its `~refine` array, or undefined (don't freeze) when
52
+ * a slot can't be proven equal, e.g. a 1.3.31+ format function
53
+ */
54
+ function alignBuildExternals(build, schema) {
55
+ const variables = build.external.variables;
56
+ const canonical = collectExternals(schema);
57
+ const id = build.external.identifier;
58
+ if (!/^[A-Za-z_$][\w$]*$/.test(id)) return;
59
+ const slots = [];
60
+ let j = 0;
61
+ let same = variables.length === canonical.length;
62
+ for (let i = 0; i < variables.length; i++) {
63
+ const v = variables[i];
64
+ const c = canonical[j];
65
+ if (j < canonical.length && externalsMatch([c], [v])) slots.push(`${id}[${j++}]`);
66
+ else if (Array.isArray(c) && c.length === 1 && c[0] === v) {
67
+ slots.push(`${id}[${j++}][0]`);
68
+ same = false;
69
+ } else return;
70
+ }
71
+ if (j !== canonical.length) return;
72
+ if (same) return build;
73
+ return {
74
+ ...build,
75
+ functions: [`${id}=[${slots.join(",")}]`, ...build.functions],
76
+ external: {
77
+ identifier: id,
78
+ variables: canonical
79
+ }
80
+ };
81
+ }
55
82
  const mirrorFactorySource = (source, hasExternals) => hasExternals ? `function(d){${source}}` : `function(v){${source}}`;
56
83
  const bothFactorySource = (identifier, checkDefs, checkValue, mirrorSource, mirrorHasExternals) => `function(${identifier},d){${checkDefs}; return{check:${checkValue},clean:${mirrorHasExternals ? `(function(d){${mirrorSource}})(d)` : `function(v){${mirrorSource}}`}}}`;
57
84
  const Source = {
@@ -61,12 +88,6 @@ const Source = {
61
88
  mirrorFactory: mirrorFactorySource,
62
89
  bothFactory: bothFactorySource
63
90
  };
64
- /**
65
- * verify that mirror unions can be reconstructed in build time
66
- *
67
- * return undefined if not reconstructable
68
- * `truthUnions` is `mir.externals.unions` (compiled branches).
69
- */
70
91
  function captureMirrorUnions(schema, truthUnions) {
71
92
  const branchSchemas = collectMirrorUnions(schema);
72
93
  if (branchSchemas.length !== truthUnions.length) return;
@@ -75,9 +96,10 @@ function captureMirrorUnions(schema, truthUnions) {
75
96
  if (!branchSchemas[ui] || branchSchemas[ui].length !== truthUnions[ui].length) return;
76
97
  const branch = [];
77
98
  for (let i = 0; i < truthUnions[ui].length; i++) {
78
- const build = truthUnions[ui][i]?.buildResult;
79
- if (!build?.functions?.length || !build.entry) return;
80
- if (!externalsMatch(collectExternals(branchSchemas[ui][i]), build.external.variables)) return;
99
+ const raw = truthUnions[ui][i]?.buildResult;
100
+ if (!raw?.functions?.length || !raw.entry) return;
101
+ const build = alignBuildExternals(raw, branchSchemas[ui][i]);
102
+ if (!build) return;
81
103
  branch.push({
82
104
  identifier: build.external.identifier,
83
105
  code: reconstructCheckCode(build)
@@ -98,4 +120,4 @@ function installReconstructImpl() {
98
120
  }
99
121
 
100
122
  //#endregion
101
- export { Source, captureMirrorCodecs, captureMirrorUnions, externalsMatch, installReconstructImpl, reconstructCheck };
123
+ export { Source, alignBuildExternals, captureMirrorCodecs, captureMirrorUnions, externalsMatch, installReconstructImpl, reconstructCheck };