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