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,22 +1,20 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_runtime = require('../../_virtual/_rolldown/runtime.js');
3
2
  const require_utils = require('../../utils.js');
4
3
  const require_type_constants = require('../constants.js');
5
4
  const require_error = require('../../error.js');
6
5
  const require_compile_aot = require('../../compile/aot.js');
7
6
  const require_type_shared = require('../shared.js');
8
- const require_type_elysia_file_type = require('../elysia/file-type.js');
9
7
  const require_type_validator_clean_safe = require('./clean-safe.js');
10
8
  const require_type_utils = require('../utils.js');
11
9
  const require_validator_index = require('../../validator/index.js');
10
+ const require_type_typebox_type = require('../typebox-type.js');
11
+ const require_type_typebox_value = require('../typebox-value.js');
12
12
  const require_type_coerce = require('../coerce.js');
13
+ const require_type_elysia_file_type = require('../elysia/file-type.js');
13
14
  const require_type_validator_default_precompute = require('./default-precompute.js');
14
15
  const require_type_validator_custom_error = require('./custom-error.js');
15
16
  const require_type_validator_exact_mirror = require('./exact-mirror.js');
16
17
  const require_type_validator_validator_cache = require('./validator-cache.js');
17
- let typebox_type = require("typebox/type");
18
- let typebox_value = require("typebox/value");
19
- let typebox_schema = require("typebox/schema");
20
18
 
21
19
  //#region src/type/validator/index.ts
22
20
  const moduleCache = /* @__PURE__ */ new WeakMap();
@@ -40,6 +38,19 @@ const freshRefineValidation = (groups) => {
40
38
  checking: false
41
39
  };
42
40
  };
41
+ const UNAWAITED_REFINE = "[Elysia] t.Refine check must be synchronous";
42
+ const guardedChecks = /* @__PURE__ */ new WeakSet();
43
+ function guardRefinement(refinement) {
44
+ const check = refinement.check;
45
+ if (guardedChecks.has(check) || check["~elyAsyncRefine"] === true || require_type_shared.isPureRefinement(refinement)) return;
46
+ const guarded = function(value) {
47
+ const result = check.call(this, value);
48
+ if (typeof result?.then === "function") throw new Error(UNAWAITED_REFINE);
49
+ return result;
50
+ };
51
+ guardedChecks.add(guarded);
52
+ refinement.check = guarded;
53
+ }
43
54
  function collectRefinements(schema, out = /* @__PURE__ */ new Set(), seen = /* @__PURE__ */ new WeakSet()) {
44
55
  if (!schema || typeof schema !== "object" || seen.has(schema)) return out;
45
56
  seen.add(schema);
@@ -48,7 +59,8 @@ function collectRefinements(schema, out = /* @__PURE__ */ new Set(), seen = /* @
48
59
  let group = refinementGroups.get(refinements);
49
60
  if (!group) {
50
61
  const members = refinements.filter((refinement) => refinement && typeof refinement === "object" && typeof refinement.check === "function");
51
- if (members.length) {
62
+ for (const refinement of members) guardRefinement(refinement);
63
+ if (members.length && !require_type_elysia_file_type.isAsyncPredicate(members)) {
52
64
  group = {
53
65
  checks: members.map((refinement) => refinement.check),
54
66
  pure: members.every(require_type_shared.isPureRefinement)
@@ -84,6 +96,7 @@ function collectRefinements(schema, out = /* @__PURE__ */ new Set(), seen = /* @
84
96
  if (slot.occurrences > slot.recorded) return true;
85
97
  return slot.verdicts[slot.occurrences - 1][index];
86
98
  };
99
+ guardedChecks.add(refinement.check);
87
100
  }
88
101
  }
89
102
  }
@@ -120,20 +133,6 @@ function collectRefinements(schema, out = /* @__PURE__ */ new Set(), seen = /* @
120
133
  ]) if (Array.isArray(schema[key])) for (const child of schema[key]) collectRefinements(child, out, seen);
121
134
  return out;
122
135
  }
123
- const materializeModels = (models) => {
124
- const out = {};
125
- for (const name in models) {
126
- const schema = models[name];
127
- const value = {};
128
- let source = schema;
129
- while (source && source !== Object.prototype) {
130
- for (const key of Object.getOwnPropertyNames(source)) if (key !== "$id" && !Object.hasOwn(value, key)) Object.defineProperty(value, key, Object.getOwnPropertyDescriptor(source, key));
131
- source = Object.getPrototypeOf(source);
132
- }
133
- out[name] = value;
134
- }
135
- return out;
136
- };
137
136
  function divergesFromEvaluate(node, seen) {
138
137
  if (!node || typeof node !== "object" || seen.has(node)) return false;
139
138
  seen.add(node);
@@ -183,7 +182,6 @@ function schemaMayHaveAsyncRefine(node, seen = /* @__PURE__ */ new WeakSet()) {
183
182
  }
184
183
  return false;
185
184
  }
186
- const schemaHasCustomError = (schema) => require_type_validator_clean_safe.schemaSome(schema, (node) => node.error !== void 0);
187
185
  async function enforceFileTypeChecks(pending, type, value, schema) {
188
186
  const results = await Promise.all(pending.map((x) => x.check));
189
187
  for (let i = 0; i < results.length; i++) if (results[i] !== true) throw new require_error.ValidationError(type, value, [{
@@ -206,7 +204,24 @@ function findInstancePath(value, target, path = "") {
206
204
  if (found !== void 0) return found;
207
205
  }
208
206
  }
207
+ function warnMirrorFailure(schema, error) {
208
+ console.warn("Failed to create exactMirror. Please report the following to https://github.com/elysiajs/elysia/issues");
209
+ let report;
210
+ try {
211
+ report = JSON.stringify(schema, (key, value) => key === "secrets" ? "[redacted]" : value);
212
+ } catch {
213
+ report = "[unserializable schema]";
214
+ }
215
+ console.warn(report);
216
+ console.warn(error);
217
+ }
218
+ let warnedMissingMirror = false;
209
219
  var TypeBoxValidator = class extends require_validator_index.Validator {
220
+ static member(schema, compiled) {
221
+ const isAsync = (compiled.buildResult ?? require_type_typebox_value.Build(schema)).external.variables.some(require_type_elysia_file_type.isAsyncPredicate);
222
+ collectRefinements(schema);
223
+ return isAsync;
224
+ }
210
225
  #decodeMirror;
211
226
  #encodeMirror;
212
227
  #refinements;
@@ -229,41 +244,66 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
229
244
  this.#hits = 0;
230
245
  if (isIntersectable) {
231
246
  const members = [schema, ...options.schemas];
232
- schema = shallowMergeObjects(members) ?? (0, typebox_type.Evaluate)((0, typebox_type.Intersect)(members));
247
+ schema = shallowMergeObjects(members) ?? require_type_typebox_type.Evaluate(require_type_typebox_type.Intersect(members));
233
248
  }
234
249
  const originalElyTyp = schema?.["~elyTyp"];
235
250
  const rawSchema = schema;
236
251
  const frozen = options?.aot && options.slot ? require_compile_aot.Compiled.getValidator(options.aot.method, options.aot.path, options.slot, options.app?.["~programId"]) : void 0;
237
252
  let schemaHasRef = false;
238
253
  if (name && options?.models) {
239
- schema = moduleCache.getOrInsertComputed(options.models, () => (0, typebox_type.Module)(materializeModels(options.models)))[name];
254
+ let modelModule = moduleCache.get(options.models);
255
+ if (modelModule === void 0) {
256
+ const models = options.models;
257
+ const out = {};
258
+ for (const modelName in models) {
259
+ const modelSchema = models[modelName];
260
+ const value = {};
261
+ let source = modelSchema;
262
+ while (source && source !== Object.prototype) {
263
+ for (const key of Object.getOwnPropertyNames(source)) if (key !== "$id" && !Object.hasOwn(value, key)) Object.defineProperty(value, key, Object.getOwnPropertyDescriptor(source, key));
264
+ source = Object.getPrototypeOf(source);
265
+ }
266
+ out[modelName] = value;
267
+ }
268
+ moduleCache.set(options.models, modelModule = require_type_typebox_type.Module(out));
269
+ }
270
+ schema = modelModule[name];
240
271
  if (isIntersectable) {
241
272
  const members = [schema, ...options.schemas];
242
- schema = shallowMergeObjects(members) ?? (0, typebox_type.Evaluate)((0, typebox_type.Intersect)(members));
273
+ schema = shallowMergeObjects(members) ?? require_type_typebox_type.Evaluate(require_type_typebox_type.Intersect(members));
243
274
  }
244
275
  } else if (options?.models && typeof name !== "string") {
245
- schemaHasRef = frozen ? frozen.r === 1 : require_type_validator_clean_safe.schemaContainsRef(schema);
276
+ schemaHasRef = frozen ? frozen.r === 1 : require_type_validator_clean_safe.schemaSome(schema, (n) => !!n.$ref);
246
277
  if (schemaHasRef) {
247
278
  const id = `inline@${++inlineRefId}`;
248
- schema = (0, typebox_type.Module)({
279
+ schema = require_type_typebox_type.Module({
249
280
  ...options.models,
250
281
  [id]: schema
251
282
  })[id];
252
283
  }
253
284
  }
254
- const isFrozen = this.#reconstruct(options, frozen);
285
+ let isFrozen;
286
+ if (!options?.aot || !options.slot || options.normalize === "typebox") isFrozen = false;
287
+ else if (!frozen?.c && !frozen?.cm) isFrozen = false;
288
+ else {
289
+ this.isAsync = frozen.a === 1;
290
+ this.hasDefault = frozen.d === 1;
291
+ this.hasCodec = frozen.k === 1;
292
+ isFrozen = true;
293
+ }
255
294
  this.schema = isFrozen && frozen.cp ? require_type_coerce.buildCoercedFromPlan(schema, frozen.cp) : isFrozen && !this.hasCodec ? schema : require_type_coerce.applyCoercions(schema, options?.coerces);
256
295
  if (options?.normalize === false && options.slot !== "headers" && options.slot !== "cookie") this.schema = require_type_shared.nonAdditionalProperties(this.schema);
257
296
  if (!isFrozen) {
258
297
  const capturing = require_compile_aot.Capture.isCapturing();
259
- this.hasCodec = (0, typebox_value.HasCodec)(this.schema);
298
+ this.hasCodec = require_type_typebox_value.HasCodec(this.schema);
260
299
  this.hasDefault = require_type_utils.hasProperty("default", this.schema);
261
- if (!capturing && !options?.eager && !schemaMayHaveAsyncRefine(this.schema) && !schemaHasCustomError(this.schema)) {
300
+ if (!capturing && !options?.eager && !schemaMayHaveAsyncRefine(this.schema) && !require_type_validator_clean_safe.schemaSome(this.schema, (node) => node.error !== void 0)) {
262
301
  this.#deferred = true;
263
302
  this.isAsync = false;
264
303
  } else {
265
- this.tb = capturing && require_compile_aot.captureImpl ? require_compile_aot.captureImpl.sourceOnlyValidator(this.schema) : (0, typebox_schema.Compile)(this.schema);
266
- this.isAsync = this.tb.buildResult.external.variables.some(require_type_elysia_file_type.isAsyncPredicate) ?? false;
304
+ this.tb = capturing && require_compile_aot.captureImpl ? require_compile_aot.captureImpl.sourceOnlyValidator(this.schema) : require_type_typebox_value.SchemaCompile(this.schema);
305
+ const build = this.tb.buildResult ?? require_type_typebox_value.Build(this.schema);
306
+ this.isAsync = build.external.variables.some(require_type_elysia_file_type.isAsyncPredicate);
267
307
  if (capturing && require_compile_aot.captureImpl && options?.aot && options.slot) require_compile_aot.captureImpl.maybeCapture({
268
308
  aot: options.aot,
269
309
  slot: options.slot,
@@ -275,15 +315,13 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
275
315
  coerces: options.coerces,
276
316
  normalize: options.normalize,
277
317
  sanitize: options.sanitize,
278
- buildResult: this.tb.buildResult
318
+ buildResult: build
279
319
  });
280
- else if (!capturing) this.#dropCompiledSource();
320
+ else if (!capturing) require_type_shared.dropCompiledSource(this.tb);
281
321
  }
282
322
  }
283
- if (!this.isAsync) {
284
- const refinements = collectRefinements(this.schema);
285
- if (refinements.size) this.#refinements = refinements;
286
- }
323
+ const refinements = collectRefinements(this.schema);
324
+ if (!this.isAsync && refinements.size) this.#refinements = refinements;
287
325
  if (frozen?.ps === 1) {
288
326
  const objectTemplate = frozen.pod !== void 0 ? Object.freeze(frozen.pod) : void 0;
289
327
  this.precomputeSafe = true;
@@ -299,6 +337,7 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
299
337
  if (defaults) {
300
338
  this.precomputeSafe = true;
301
339
  const objectTemplate = defaults.pod !== void 0 ? Object.freeze(defaults.pod) : void 0;
340
+ const failures = require_type_validator_default_precompute.precomputeCompileFailures();
302
341
  this.#defaultFastPath = {
303
342
  value: defaults.pd,
304
343
  appliesToNull: defaults.pn,
@@ -306,6 +345,7 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
306
345
  clone: defaults.pd !== void 0 ? require_type_validator_default_precompute.createDefaultCloner(defaults.pd) : void 0,
307
346
  merge: defaults.ms ? require_type_validator_default_precompute.createMergerFromSource(defaults.ms) : objectTemplate !== void 0 ? require_type_validator_default_precompute.createObjectDefaultMerger(objectTemplate) : void 0
308
347
  };
348
+ if (require_type_validator_default_precompute.precomputeCompileFailures() !== failures) this.precomputeSafe = false;
309
349
  } else {
310
350
  this.precomputeSafe = false;
311
351
  this.#defaultFastPath = void 0;
@@ -318,30 +358,60 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
318
358
  if (isFrozen && frozen.cm) {
319
359
  const both = require_compile_aot.reconstruct().instantiateFrozenBoth(frozen, this.schema, schema);
320
360
  this.reconstructedCheck = both.check;
321
- this.Clean = options?.normalize === false ? void 0 : require_type_validator_clean_safe.schemaHasDangerousProperties(this.schema) ? (value) => (0, typebox_value.Clean)(this.schema, value) : both.clean;
361
+ this.Clean = options?.normalize === false ? void 0 : require_type_validator_clean_safe.schemaHasDangerousProperties(this.schema) ? (value) => require_type_typebox_value.Clean(this.schema, value) : both.clean;
322
362
  } else {
323
363
  if (isFrozen) this.reconstructedCheck = frozen.c(frozen.e ? require_compile_aot.reconstruct().collectExternals(this.schema) : require_compile_aot.EMPTY_EXTERNALS);
324
- if (!require_type_validator_exact_mirror.getExactMirror() && !frozen?.m && !require_type_validator_clean_safe.schemaHasDangerousProperties(this.schema) && options?.normalize !== false && options?.normalize !== "typebox" && (options?.normalize === true || options?.normalize === "exactMirror" || !!options?.sanitize)) throw require_type_validator_exact_mirror.exactMirrorRequired();
364
+ if (!require_type_validator_exact_mirror.getExactMirror() && !frozen?.m && !require_type_validator_clean_safe.schemaHasDangerousProperties(this.schema) && options?.normalize !== false && options?.normalize !== "typebox") {
365
+ if (options?.normalize === "exactMirror" || options?.sanitize) throw require_type_validator_exact_mirror.exactMirrorRequired();
366
+ if (options?.normalize === true && !warnedMissingMirror) {
367
+ warnedMissingMirror = true;
368
+ console.warn("exact-mirror is unavailable, normalization degraded to TypeBox. Install exact-mirror, or bundle it statically with the AOT build plugin ('elysia/plugin/aot') to restore the fast path. Use normalize: 'typebox' to silence this.");
369
+ }
370
+ }
325
371
  try {
326
- this.Clean = options?.normalize === false ? void 0 : options?.normalize === "typebox" ? (value) => (0, typebox_value.Clean)(this.schema, value) : this.#setupMirror(schema, options, frozen);
372
+ if (options?.normalize === false) this.Clean = void 0;
373
+ else if (options?.normalize === "typebox") this.Clean = (value) => require_type_typebox_value.Clean(this.schema, value);
374
+ else if (require_type_validator_clean_safe.schemaHasDangerousProperties(this.schema)) this.Clean = (value) => require_type_typebox_value.Clean(this.schema, value);
375
+ else {
376
+ const aot = options?.aot;
377
+ const slot = options?.slot;
378
+ if (aot && slot && frozen?.m) {
379
+ const m = frozen.m;
380
+ let clean;
381
+ this.Clean = (value) => {
382
+ if (clean === void 0) try {
383
+ clean = require_compile_aot.reconstruct().instantiateFrozenMirror(m, schema);
384
+ } catch (error) {
385
+ warnMirrorFailure(schema, error);
386
+ clean = (v) => v;
387
+ }
388
+ return clean(value);
389
+ };
390
+ } else {
391
+ if (aot && slot && require_compile_aot.Capture.isCapturing() && require_compile_aot.captureImpl) require_compile_aot.captureImpl.captureMirror(schema, aot, slot, options?.sanitize);
392
+ const createMirror = require_type_validator_exact_mirror.getExactMirror();
393
+ this.Clean = !createMirror ? (value) => require_type_typebox_value.Clean(this.schema, value) : createMirror(schema, {
394
+ Compile: require_type_typebox_value.SchemaCompile,
395
+ sanitize: options?.sanitize
396
+ });
397
+ }
398
+ }
327
399
  } catch (error) {
328
- console.warn("Failed to create exactMirror. Please report the following code to https://github.com/elysiajs/elysia/issues");
329
- console.warn(schema);
330
- console.warn(error);
331
- if (options?.normalize !== false) this.Clean = (value) => (0, typebox_value.Clean)(this.schema, value);
400
+ warnMirrorFailure(schema, error);
401
+ if (options?.normalize !== false) this.Clean = (value) => require_type_typebox_value.Clean(this.schema, value);
332
402
  }
333
403
  }
334
404
  this.#cleanRedundant = !!this.Clean && !options?.sanitize && options?.normalize !== "typebox" && require_type_validator_clean_safe.isFullyClosedObject(this.schema);
335
- if (this.hasCodec && !this.#isForm && !this.#noValidate && !options?.slot?.startsWith("r") && options?.normalize !== false && options?.normalize !== "typebox") this.#decodeMirror = this.#setupCodecMirror(this.schema, options, frozen, "decode");
336
- if (this.hasCodec && !this.#isForm && !this.#noValidate && options?.slot?.startsWith("r") && options?.normalize !== false && options?.normalize !== "typebox") this.#encodeMirror = this.#setupCodecMirror(this.schema, options, frozen, "encode");
405
+ if (this.hasCodec && !this.#isForm && !this.#noValidate && options?.normalize !== false && options?.normalize !== "typebox") if (options?.slot?.startsWith("r")) this.#encodeMirror = this.#setupCodecMirror(this.schema, options, frozen, "encode");
406
+ else this.#decodeMirror = this.#setupCodecMirror(this.schema, options, frozen, "decode");
337
407
  if (!this.#noValidate) this.#findCustomError = require_type_validator_custom_error.buildFindCustomError(this.schema, frozen);
338
408
  if (options?.aot && options.slot && require_compile_aot.Capture.isCapturing() && require_compile_aot.captureImpl) require_compile_aot.captureImpl.captureBridgeFree(options.aot, options.slot, rawSchema);
339
409
  }
340
410
  #error(value, type, errors) {
341
411
  return new require_error.ValidationError(type, value, errors ?? (() => this.Errors(value)), this.schema, this.#findCustomError);
342
412
  }
343
- #validate(value) {
344
- if (!this.#refinements) return this.Check(value) ? void 0 : [];
413
+ #validate(value, countHit = true) {
414
+ if (!this.#refinements) return (countHit ? this.Check(value) : this.#check(value, false)) ? void 0 : [];
345
415
  const pool = this.#refineScratch ??= freshRefineValidation(this.#refinements);
346
416
  const usingPool = !pool.active;
347
417
  const validation = usingPool ? pool : freshRefineValidation(this.#refinements);
@@ -351,7 +421,7 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
351
421
  validation.replay = false;
352
422
  activeRefineValidation = validation;
353
423
  try {
354
- if (this.Check(value)) return;
424
+ if (countHit ? this.Check(value) : this.#check(value, false)) return;
355
425
  validation.replay = true;
356
426
  validation.replayEpoch++;
357
427
  return this.Errors(value);
@@ -360,33 +430,6 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
360
430
  if (usingPool) pool.active = false;
361
431
  }
362
432
  }
363
- #setupMirror(schema, options, frozen) {
364
- if (require_type_validator_clean_safe.schemaHasDangerousProperties(this.schema)) return (value) => (0, typebox_value.Clean)(this.schema, value);
365
- const aot = options?.aot;
366
- const slot = options?.slot;
367
- if (aot && slot && frozen?.m) {
368
- const m = frozen.m;
369
- let clean;
370
- return (value) => {
371
- if (clean === void 0) try {
372
- clean = require_compile_aot.reconstruct().instantiateFrozenMirror(m, schema);
373
- } catch (error) {
374
- console.warn("Failed to create exactMirror. Please report the following code to https://github.com/elysiajs/elysia/issues");
375
- console.warn(schema);
376
- console.warn(error);
377
- clean = (v) => v;
378
- }
379
- return clean(value);
380
- };
381
- }
382
- if (aot && slot && require_compile_aot.Capture.isCapturing() && require_compile_aot.captureImpl) require_compile_aot.captureImpl.captureMirror(schema, aot, slot, options?.sanitize);
383
- const createMirror = require_type_validator_exact_mirror.getExactMirror();
384
- if (!createMirror) return (value) => (0, typebox_value.Clean)(this.schema, value);
385
- return createMirror(schema, {
386
- Compile: typebox_schema.Compile,
387
- sanitize: options?.sanitize
388
- });
389
- }
390
433
  #setupCodecMirror(schema, options, frozen, dir) {
391
434
  if (require_type_validator_clean_safe.schemaHasDangerousProperties(this.schema)) return;
392
435
  const aot = options?.aot;
@@ -400,10 +443,10 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
400
443
  run = require_compile_aot.reconstruct().instantiateFrozenDecodeMirror(m, schema, dir);
401
444
  } catch {
402
445
  run = dir === "decode" ? (v) => {
403
- const decoded = (0, typebox_value.DecodeUnsafe)(require_utils.nullObject(), schema, v);
446
+ const decoded = require_type_typebox_value.DecodeUnsafe(require_utils.nullObject(), schema, v);
404
447
  return this.Clean ? this.Clean(decoded) : decoded;
405
448
  } : (v) => {
406
- const out = (0, typebox_value.Encode)(schema, v);
449
+ const out = require_type_typebox_value.Encode(schema, v);
407
450
  return this.Clean ? this.Clean(out) : out;
408
451
  };
409
452
  }
@@ -417,14 +460,17 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
417
460
  if (!createMirror) return;
418
461
  try {
419
462
  return createMirror(schema, {
420
- Compile: typebox_schema.Compile,
463
+ Compile: require_type_typebox_value.SchemaCompile,
421
464
  sanitize: options?.sanitize,
422
465
  ...dirOpt
423
466
  });
424
467
  } catch {}
425
468
  }
426
469
  Check(value) {
427
- this.#tick();
470
+ return this.#check(value, true);
471
+ }
472
+ #check(value, countHit) {
473
+ if (countHit) this.#tick();
428
474
  const pool = this.#refineScratch;
429
475
  if (pool?.active && this.#refinements) {
430
476
  if (pool.checking) {
@@ -447,7 +493,7 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
447
493
  }
448
494
  #rawCheck(value) {
449
495
  if (this.reconstructedCheck) return this.reconstructedCheck(value);
450
- if (this.#deferred) return (0, typebox_value.Check)(this.schema, value);
496
+ if (this.#deferred) return require_type_typebox_value.Check(this.schema, value);
451
497
  return this.tb.Check(value);
452
498
  }
453
499
  #tick() {
@@ -457,64 +503,48 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
457
503
  * Promote a deferred validator to the compiled `Check` fast path
458
504
  */
459
505
  #materialize() {
460
- const tb = (0, typebox_schema.Compile)(this.schema);
506
+ const tb = require_type_typebox_value.SchemaCompile(this.schema);
461
507
  this.tb = tb;
462
- this.#dropCompiledSource();
508
+ require_type_shared.dropCompiledSource(tb);
463
509
  this.#deferred = false;
464
510
  }
465
- #reconstruct(options, frozen) {
466
- if (!options?.aot || !options.slot || options.normalize === "typebox") return false;
467
- if (!frozen?.c && !frozen?.cm) return false;
468
- this.isAsync = frozen.a === 1;
469
- this.hasDefault = frozen.d === 1;
470
- this.hasCodec = frozen.k === 1;
471
- return true;
472
- }
473
- #dropCompiledSource() {
474
- const tb = this.tb;
475
- if (!tb) return;
476
- if (tb.evaluateResult) tb.evaluateResult.code = void 0;
477
- if (tb.buildResult) tb.buildResult.functions = void 0;
478
- }
479
511
  Errors(value) {
480
- return (0, typebox_value.Errors)(this.schema, value);
512
+ return require_type_typebox_value.Errors(this.schema, value);
481
513
  }
482
514
  Decode(value) {
483
- return (0, typebox_value.Decode)(this.schema, value);
515
+ return require_type_typebox_value.Decode(this.schema, value);
484
516
  }
485
517
  Encode(value) {
486
- return this.hasCodec ? (0, typebox_value.Encode)(this.schema, value) : value;
518
+ return this.hasCodec ? require_type_typebox_value.Encode(this.schema, value) : value;
487
519
  }
488
520
  EncodeFrom(value, type) {
489
521
  this.#tick();
490
- if (this.#isForm) {
491
- const errors = this.#noValidate ? void 0 : this.#validate(value);
492
- if (errors) throw this.#error(value, type, errors.length ? errors : void 0);
493
- return value;
494
- }
495
- if (!this.hasCodec) {
496
- const errors = this.#noValidate ? void 0 : this.#validate(value);
522
+ if (this.#isForm || !this.hasCodec) {
523
+ const errors = this.#noValidate ? void 0 : this.#validate(value, false);
497
524
  if (errors) throw this.#error(value, type, errors.length ? errors : void 0);
498
- if (this.Clean) value = this.Clean(value);
525
+ if (this.Clean && !this.#isForm) value = this.Clean(value);
499
526
  return value;
500
527
  }
501
528
  try {
502
529
  if (this.#encodeMirror) {
503
530
  const out = this.#encodeMirror(value);
504
- const errors = this.#noValidate ? void 0 : this.#validate(out);
531
+ const errors = this.#noValidate ? void 0 : this.#validate(out, false);
505
532
  if (errors) throw new require_error.ValidationError(type, out, errors.length ? errors : () => this.Errors(out), this.schema);
506
533
  return out;
507
534
  }
508
- const out = this.#noValidate ? (0, typebox_value.EncodeUnsafe)(require_utils.nullObject(), this.schema, value) : (0, typebox_value.Encode)(this.schema, value);
535
+ const out = this.#noValidate ? require_type_typebox_value.EncodeUnsafe(require_utils.nullObject(), this.schema, value) : require_type_typebox_value.Encode(this.schema, value);
509
536
  return this.Clean ? this.Clean(out) : out;
510
537
  } catch (e) {
511
538
  if (this.#noValidate) return this.Clean ? this.Clean(value) : value;
512
- if (e instanceof require_error.ValidationError) throw e;
513
- if (e?.error) throw e.error;
514
- if (e?.status) throw e;
515
- throw new require_error.ValidationError(type, value, () => this.Errors(value), this.schema);
539
+ this.#rethrow(e, value, type);
516
540
  }
517
541
  }
542
+ #rethrow(e, value, type) {
543
+ if (e instanceof require_error.ValidationError) throw e;
544
+ if (e?.error) throw e.error;
545
+ if (e?.status) throw e;
546
+ throw new require_error.ValidationError(type, value, () => this.Errors(value), this.schema);
547
+ }
518
548
  #markForm(value) {
519
549
  if (this.#isForm && value !== null && typeof value === "object") {
520
550
  const previous = Object.getPrototypeOf(value);
@@ -541,6 +571,15 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
541
571
  if (Array.isArray(value)) return value;
542
572
  return require_type_validator_default_precompute.applyPrecomputed(defaults.objectTemplate, value);
543
573
  }
574
+ #applyDefault(value) {
575
+ const defaults = this.#defaultFastPath;
576
+ if (defaults) {
577
+ if (value === void 0 || value === null && defaults.appliesToNull) return this.#cloneSharedDefault();
578
+ if (value !== null && typeof value === "object" && (defaults.merge !== void 0 || defaults.objectTemplate !== void 0)) return this.#applyPrecomputedObjectDefault(value);
579
+ return value;
580
+ }
581
+ return require_type_typebox_value.Default(this.schema, value);
582
+ }
544
583
  optionalBypass(value) {
545
584
  const schema = this.schema;
546
585
  if (!schema?.["~optional"]) return;
@@ -554,13 +593,7 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
554
593
  };
555
594
  }
556
595
  async FromAsync(value, type) {
557
- if (this.hasDefault) {
558
- const defaults = this.#defaultFastPath;
559
- if (defaults) {
560
- if (value === void 0 || value === null && defaults.appliesToNull) value = this.#cloneSharedDefault();
561
- else if (value !== null && typeof value === "object" && (defaults.merge !== void 0 || defaults.objectTemplate !== void 0)) value = this.#applyPrecomputedObjectDefault(value);
562
- } else value = (0, typebox_value.Default)(this.schema, value);
563
- }
596
+ if (this.hasDefault) value = this.#applyDefault(value);
564
597
  if (this.#hasOptional) {
565
598
  const bypass = this.optionalBypass(value);
566
599
  if (bypass) return bypass.value;
@@ -568,29 +601,7 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
568
601
  const markedValue = value;
569
602
  const marked = this.#isForm ? this.#markForm(value) : void 0;
570
603
  try {
571
- if (this.hasCodec) {
572
- if (!this.#noValidate) {
573
- require_type_elysia_file_type.collectFileTypeChecks();
574
- let errors;
575
- let pendingFile;
576
- try {
577
- errors = this.#validate(value);
578
- } finally {
579
- pendingFile = require_type_elysia_file_type.takeFileTypeChecks();
580
- }
581
- if (errors) throw this.#error(value, type, errors.length ? errors : void 0);
582
- if (pendingFile) await enforceFileTypeChecks(pendingFile, type, value, this.schema);
583
- }
584
- if (this.#decodeMirror) value = this.#decodeMirror(value);
585
- else try {
586
- value = (0, typebox_value.DecodeUnsafe)(require_utils.nullObject(), this.schema, value);
587
- } catch (e) {
588
- if (e instanceof require_error.ValidationError) throw e;
589
- if (e?.error) throw e.error;
590
- if (e?.status) throw e;
591
- throw new require_error.ValidationError(type, value, () => this.Errors(value), this.schema);
592
- }
593
- } else if (!this.#noValidate) {
604
+ if (!this.#noValidate) {
594
605
  require_type_elysia_file_type.collectFileTypeChecks();
595
606
  let errors;
596
607
  let pendingFile;
@@ -602,6 +613,12 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
602
613
  if (errors) throw this.#error(value, type, errors.length ? errors : void 0);
603
614
  if (pendingFile) await enforceFileTypeChecks(pendingFile, type, value, this.schema);
604
615
  }
616
+ if (this.hasCodec) if (this.#decodeMirror) value = this.#decodeMirror(value);
617
+ else try {
618
+ value = require_type_typebox_value.DecodeUnsafe(require_utils.nullObject(), this.schema, value);
619
+ } catch (e) {
620
+ this.#rethrow(e, value, type);
621
+ }
605
622
  if (this.Clean && !this.#decodeMirror && !this.#cleanRedundant) value = this.Clean(value);
606
623
  return value;
607
624
  } finally {
@@ -609,13 +626,7 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
609
626
  }
610
627
  }
611
628
  FromSync(value, type) {
612
- if (this.hasDefault) {
613
- const defaults = this.#defaultFastPath;
614
- if (defaults) {
615
- if (value === void 0 || value === null && defaults.appliesToNull) value = this.#cloneSharedDefault();
616
- else if (value !== null && typeof value === "object" && (defaults.merge !== void 0 || defaults.objectTemplate !== void 0)) value = this.#applyPrecomputedObjectDefault(value);
617
- } else value = (0, typebox_value.Default)(this.schema, value);
618
- }
629
+ if (this.hasDefault) value = this.#applyDefault(value);
619
630
  if (this.#hasOptional) {
620
631
  const bypass = this.optionalBypass(value);
621
632
  if (bypass) return bypass.value;
@@ -623,21 +634,13 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
623
634
  const markedValue = value;
624
635
  const marked = this.#isForm ? this.#markForm(value) : void 0;
625
636
  try {
626
- if (this.hasCodec) {
627
- const errors = this.#noValidate ? void 0 : this.#validate(value);
628
- if (errors) throw this.#error(value, type, errors.length ? errors : void 0);
629
- if (this.#decodeMirror) value = this.#decodeMirror(value);
630
- else try {
631
- value = (0, typebox_value.DecodeUnsafe)(require_utils.nullObject(), this.schema, value);
632
- } catch (e) {
633
- if (e instanceof require_error.ValidationError) throw e;
634
- if (e?.error) throw e.error;
635
- if (e?.status) throw e;
636
- throw new require_error.ValidationError(type, value, () => this.Errors(value), this.schema);
637
- }
638
- } else {
639
- const errors = this.#noValidate ? void 0 : this.#validate(value);
640
- if (errors) throw this.#error(value, type, errors.length ? errors : void 0);
637
+ const errors = this.#noValidate ? void 0 : this.#validate(value);
638
+ if (errors) throw this.#error(value, type, errors.length ? errors : void 0);
639
+ if (this.hasCodec) if (this.#decodeMirror) value = this.#decodeMirror(value);
640
+ else try {
641
+ value = require_type_typebox_value.DecodeUnsafe(require_utils.nullObject(), this.schema, value);
642
+ } catch (e) {
643
+ this.#rethrow(e, value, type);
641
644
  }
642
645
  if (this.Clean && !this.#decodeMirror && !this.#cleanRedundant) value = this.Clean(value);
643
646
  return value;