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
package/dist/utils.mjs CHANGED
@@ -36,6 +36,27 @@ function fnv1a(str) {
36
36
  }
37
37
  return hash >>> 0;
38
38
  }
39
+ const compositionKeys = Object.freeze([
40
+ "allOf",
41
+ "anyOf",
42
+ "oneOf",
43
+ "~cookieFrom"
44
+ ]);
45
+ function refTargets(roots, models = {}) {
46
+ const targets = nullObject();
47
+ const add = (name, schema) => (targets[name] ??= /* @__PURE__ */ new Set()).add(schema);
48
+ const seen = /* @__PURE__ */ new Set();
49
+ const index = (node) => {
50
+ if (!node || typeof node !== "object" || seen.has(node)) return;
51
+ seen.add(node);
52
+ if (typeof node.$id === "string") add(node.$id.slice(node.$id.lastIndexOf("/") + 1), node);
53
+ for (const key in node) index(node[key]);
54
+ index(node["~cookieFrom"]);
55
+ };
56
+ for (const name in models) add(name, models[name]);
57
+ roots.concat(Object.values(models)).forEach(index);
58
+ return (name) => targets[name] ?? [];
59
+ }
39
60
  /**
40
61
  * Maps each lifecycle/derive function to the hash of the named plugin it was
41
62
  * first registered on. Used by `.use()` to dedup absorbed hooks: if a fn's
@@ -48,6 +69,12 @@ function fnv1a(str) {
48
69
  const fnOrigin = /* @__PURE__ */ new WeakMap();
49
70
  const macroOrigin = /* @__PURE__ */ new WeakMap();
50
71
  const isLocalScope = (s) => s === "local" || s === void 0;
72
+ /**
73
+ * The absorbing instance's chain as it stood at `.use()`: the `over` of a
74
+ * combine node, or the node itself. A combine node is never on an instance's
75
+ * own chain, so it can't serve as a `stopAt` directly
76
+ */
77
+ const rootSnapshot = (node) => node && "combine" in node ? node.over : node;
51
78
  const COMPACT_CHUNK_SIZE = 32;
52
79
  const emptyCompactBeforeHandlePrefix = {
53
80
  length: 0,
@@ -72,30 +99,6 @@ function compactBeforeHandleConflicts(hook) {
72
99
  for (let i = 0; i < values.length; i++) if (compactBeforeHandleFunctions.has(values[i])) return true;
73
100
  return false;
74
101
  }
75
- function appendCompactBeforeHandle(previous, added) {
76
- if (!added.length) return previous;
77
- let tail = previous.tail;
78
- let length = previous.length;
79
- for (let i = 0; i < added.length; i++) {
80
- const fn = added[i];
81
- compactBeforeHandleFunctions.add(fn);
82
- if (tail && tail.values.length < COMPACT_CHUNK_SIZE) tail = {
83
- parent: tail.parent,
84
- values: [...tail.values, fn]
85
- };
86
- else tail = {
87
- parent: tail,
88
- values: [fn]
89
- };
90
- length++;
91
- }
92
- return {
93
- tail,
94
- length,
95
- previous: previous.length ? previous : void 0,
96
- added
97
- };
98
- }
99
102
  function compactBeforeHandlePrefix(start) {
100
103
  if (!start) return;
101
104
  const pending = [];
@@ -103,34 +106,51 @@ function compactBeforeHandlePrefix(start) {
103
106
  let prefix = emptyCompactBeforeHandlePrefix;
104
107
  while (node) {
105
108
  const cached = compactBeforeHandleMemos.get(node);
106
- if (cached !== void 0) {
107
- if (cached === false) {
108
- for (let i = 0; i < pending.length; i++) compactBeforeHandleMemos.set(pending[i].node, false);
109
- return;
110
- }
109
+ if (cached) {
111
110
  prefix = cached;
112
111
  break;
113
112
  }
114
- if ("combine" in node) {
115
- compactBeforeHandleMemos.set(node, false);
116
- for (let i = 0; i < pending.length; i++) compactBeforeHandleMemos.set(pending[i].node, false);
117
- return;
118
- }
119
- const values = compactBeforeHandleValues(node.added);
120
- if (values === false) {
121
- compactBeforeHandleMemos.set(node, false);
122
- for (let i = 0; i < pending.length; i++) compactBeforeHandleMemos.set(pending[i].node, false);
123
- return;
113
+ if (cached === void 0 && !("combine" in node)) {
114
+ const values = compactBeforeHandleValues(node.added);
115
+ if (values !== false) {
116
+ pending.push({
117
+ node,
118
+ values
119
+ });
120
+ node = node.parent;
121
+ continue;
122
+ }
124
123
  }
125
- pending.push({
126
- node,
127
- values
128
- });
129
- node = node.parent;
124
+ compactBeforeHandleMemos.set(node, false);
125
+ for (let i = 0; i < pending.length; i++) compactBeforeHandleMemos.set(pending[i].node, false);
126
+ return;
130
127
  }
131
128
  for (let i = pending.length - 1; i >= 0; i--) {
132
129
  const item = pending[i];
133
- prefix = appendCompactBeforeHandle(prefix, item.values);
130
+ const added = item.values;
131
+ if (added.length) {
132
+ let tail = prefix.tail;
133
+ let length = prefix.length;
134
+ for (let j = 0; j < added.length; j++) {
135
+ const fn = added[j];
136
+ compactBeforeHandleFunctions.add(fn);
137
+ if (tail && tail.values.length < COMPACT_CHUNK_SIZE) tail = {
138
+ parent: tail.parent,
139
+ values: [...tail.values, fn]
140
+ };
141
+ else tail = {
142
+ parent: tail,
143
+ values: [fn]
144
+ };
145
+ length++;
146
+ }
147
+ prefix = {
148
+ tail,
149
+ length,
150
+ previous: prefix.length ? prefix : void 0,
151
+ added
152
+ };
153
+ }
134
154
  compactBeforeHandleMemos.set(item.node, prefix);
135
155
  }
136
156
  return prefix.length ? prefix : void 0;
@@ -156,13 +176,30 @@ function flattenChain(start, keep, stopAt, resolveAdded) {
156
176
  const node = nodes.pop();
157
177
  if (phases.pop() === 1) {
158
178
  const added = resolveAdded ? resolveAdded(node) : node.added;
159
- if (added) appendInto(result, added, keep, node.scope);
179
+ if (added) {
180
+ const nodeScope = node.scope;
181
+ if (!(keep && !keep(nodeScope))) for (const key in added) {
182
+ const v = added[key];
183
+ if (v === void 0 || v === null) continue;
184
+ if (eventProperties.has(key) || key === "schemas" || key === "~deriveEntries") {
185
+ const existing = result[key];
186
+ if (Array.isArray(v)) if (existing) {
187
+ const arr = existing;
188
+ for (let i = 0; i < v.length; i++) arr.push(v[i]);
189
+ } else result[key] = v.slice();
190
+ else if (existing) existing.push(v);
191
+ else result[key] = [v];
192
+ } else result[key] = v;
193
+ }
194
+ }
160
195
  continue;
161
196
  }
162
197
  if (stopAt && node === stopAt) continue;
163
198
  if ("combine" in node) {
164
- nodes.push(node.combine);
165
- phases.push(0);
199
+ if (node.combine) {
200
+ nodes.push(node.combine);
201
+ phases.push(0);
202
+ }
166
203
  if (node.over) {
167
204
  nodes.push(node.over);
168
205
  phases.push(0);
@@ -196,7 +233,8 @@ function clearFlattenChainMemo(root) {
196
233
  flattenChainMemos.delete(root);
197
234
  }
198
235
  const emptyFlatten = Object.freeze(nullObject());
199
- function flattenChainCached(root, start, resolveAdded) {
236
+ function flattenChainMemoReadonly(root, start, resolveAdded) {
237
+ if (!start) return;
200
238
  let bucket = flattenChainMemos.get(root);
201
239
  if (!bucket || bucket.e !== macroTableEpoch) {
202
240
  bucket = {
@@ -215,30 +253,8 @@ function flattenChainCached(root, start, resolveAdded) {
215
253
  return cached;
216
254
  }
217
255
  function flattenChainMemo(root, start, resolveAdded) {
218
- if (!start) return;
219
- const cached = flattenChainCached(root, start, resolveAdded);
220
- if (cached === void 0) return;
221
- return cloneHook(cached);
222
- }
223
- function flattenChainMemoReadonly(root, start, resolveAdded) {
224
- if (!start) return;
225
- return flattenChainCached(root, start, resolveAdded);
226
- }
227
- function appendInto(target, src, keep, nodeScope) {
228
- if (keep && !keep(nodeScope)) return;
229
- for (const key in src) {
230
- const v = src[key];
231
- if (v === void 0 || v === null) continue;
232
- if (eventProperties.has(key) || key === "schemas" || key === "~deriveEntries") {
233
- const existing = target[key];
234
- if (Array.isArray(v)) if (existing) {
235
- const arr = existing;
236
- for (let i = 0; i < v.length; i++) arr.push(v[i]);
237
- } else target[key] = v.slice();
238
- else if (existing) existing.push(v);
239
- else target[key] = [v];
240
- } else target[key] = v;
241
- }
256
+ const cached = flattenChainMemoReadonly(root, start, resolveAdded);
257
+ if (cached) return cloneHook(cached);
242
258
  }
243
259
  const notLatin = /[^\x00-\xFF]/;
244
260
  /**
@@ -286,6 +302,7 @@ function formToFormData(value) {
286
302
  * ```
287
303
  */
288
304
  const form = (value) => Object.setPrototypeOf({ ...value }, ELYSIA_FORM_PROTOTYPE);
305
+ const assignOwn = (target, source) => source != null && Object.hasOwn(source, "__proto__") ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : Object.assign(target, source);
289
306
  const getLoosePath = (path) => path.charCodeAt(path.length - 1) === 47 ? path.slice(0, -1) : path + "/";
290
307
  const byteStreams = /* @__PURE__ */ new WeakSet();
291
308
  /**
@@ -321,6 +338,7 @@ const sse = (_payload) => {
321
338
  if (payload.data === null) s += "data: null\n";
322
339
  else if (typeof payload.data === "string") s += sseData(payload.data);
323
340
  else if (typeof payload.data === "object") s += `data: ${JSON.stringify(payload.data)}\n`;
341
+ else if (payload.data !== void 0) s += sseData(String(payload.data));
324
342
  if (s) s += "\n";
325
343
  return s;
326
344
  };
@@ -330,11 +348,11 @@ const _enc = new TextEncoder();
330
348
  let _constantTimeEqual;
331
349
  const _resolveConstantTimeEqual = () => {
332
350
  let native;
333
- try {
351
+ if (isBun && typeof crypto?.timingSafeEqual === "function") native = (a, b) => crypto.timingSafeEqual(a, b);
352
+ else try {
334
353
  const _crypto = globalThis.process?.getBuiltinModule?.("node:crypto");
335
354
  if (typeof _crypto?.timingSafeEqual === "function") native = _crypto.timingSafeEqual;
336
355
  } catch {}
337
- if (!native && typeof crypto?.timingSafeEqual === "function") native = (a, b) => crypto.timingSafeEqual(a, b);
338
356
  if (!native) return (a, b) => {
339
357
  if (a.length !== b.length) return false;
340
358
  let mismatch = 0;
@@ -428,14 +446,26 @@ function dedupedMergeArray(a, b, reverse = false) {
428
446
  for (let i = 0; i < aArr.length; i++) if (!seen.has(aArr[i])) filtered.push(aArr[i]);
429
447
  return reverse ? bArr.concat(filtered) : filtered.concat(bArr);
430
448
  }
431
- const schemaProperties = new Set([
449
+ const hookSchemaKeys = [
432
450
  "body",
433
451
  "headers",
434
452
  "params",
435
453
  "query",
436
454
  "cookie",
437
455
  "response"
438
- ]);
456
+ ];
457
+ const schemaProperties = new Set(hookSchemaKeys);
458
+ const hookEventKeys = [
459
+ "parse",
460
+ "transform",
461
+ "derive",
462
+ "beforeHandle",
463
+ "afterHandle",
464
+ "mapResponse",
465
+ "afterResponse",
466
+ "error",
467
+ "trace"
468
+ ];
439
469
  const eventProperties = new Set([
440
470
  "start",
441
471
  "stop",
@@ -450,33 +480,16 @@ const eventProperties = new Set([
450
480
  "error"
451
481
  ]);
452
482
  function hookToGuard(a) {
453
- if (a.schema !== "merge") return a;
483
+ if (a.schema !== "merge") {
484
+ if (a.schema !== void 0 && a.schema !== "override") throw new Error(`[Elysia] Invalid guard schema ${JSON.stringify(a.schema)}, expected 'merge' or 'override' (1.x 'standalone' is 'merge')`);
485
+ return a;
486
+ }
454
487
  if (a.body || a.headers || a.params || a.query || a.cookie || a.response) {
455
488
  a.schemas ??= [];
456
489
  const schema = Object.create(null);
457
- if (a.body) {
458
- schema.body = a.body;
459
- a.body = void 0;
460
- }
461
- if (a.headers) {
462
- schema.headers = a.headers;
463
- a.headers = void 0;
464
- }
465
- if (a.params) {
466
- schema.params = a.params;
467
- a.params = void 0;
468
- }
469
- if (a.query) {
470
- schema.query = a.query;
471
- a.query = void 0;
472
- }
473
- if (a.cookie) {
474
- schema.cookie = a.cookie;
475
- a.cookie = void 0;
476
- }
477
- if (a.response) {
478
- schema.response = a.response;
479
- a.response = void 0;
490
+ for (const key of hookSchemaKeys) if (a[key]) {
491
+ schema[key] = a[key];
492
+ a[key] = void 0;
480
493
  }
481
494
  a.schemas.push(schema);
482
495
  }
@@ -506,30 +519,22 @@ function mergeHook(a, b, reverse = false, dedup = false) {
506
519
  if (!b) return a;
507
520
  if (!a) return b;
508
521
  const merge = dedup ? dedupedMergeArray : mergeArray;
509
- if (!a.body && b.body) a.body = b.body;
510
- if (!a.headers && b.headers) a.headers = b.headers;
511
- if (!a.params && b.params) a.params = b.params;
512
- if (!a.query && b.query) a.query = b.query;
513
- if (!a.cookie && b.cookie) a.cookie = b.cookie;
514
- if (!a.response && b.response) a.response = b.response;
515
- else if (a.response && b.response) a.response = mergeResponse(b.response, a.response);
516
- if (a.parse || b.parse) a.parse = merge(a.parse, b.parse, reverse);
517
- if (a.transform || b.transform) a.transform = merge(a.transform, b.transform, reverse);
518
- if (a.derive || b.derive) a.derive = merge(a.derive, b.derive, reverse);
519
- if (a.beforeHandle || b.beforeHandle) a.beforeHandle = merge(a.beforeHandle, b.beforeHandle, reverse);
520
- if (a.afterHandle || b.afterHandle) a.afterHandle = merge(a.afterHandle, b.afterHandle, reverse);
521
- if (a.mapResponse || b.mapResponse) a.mapResponse = merge(a.mapResponse, b.mapResponse, reverse);
522
- if (a.afterResponse || b.afterResponse) a.afterResponse = merge(a.afterResponse, b.afterResponse, reverse);
523
- if (a.error || b.error) a.error = merge(a.error, b.error, reverse);
524
- if (a.trace || b.trace) a.trace = merge(a.trace, b.trace, reverse);
522
+ for (const key of hookSchemaKeys) if (!a[key] && b[key]) a[key] = b[key];
523
+ else if (key === "response" && a.response && b.response) a.response = mergeResponse(b.response, a.response);
524
+ for (const key of hookEventKeys) if (a[key] || b[key]) a[key] = merge(a[key], b[key], reverse);
525
525
  if (a.schemas || b.schemas) a.schemas = mergeArray(a.schemas, b.schemas, reverse);
526
526
  const aDerive = a["~deriveEntries"];
527
527
  const bDerive = b["~deriveEntries"];
528
528
  if (aDerive || bDerive) a["~deriveEntries"] = mergeArray(aDerive, bDerive, reverse);
529
529
  return a;
530
530
  }
531
- const createErrorEventHandler = (fn, error) => (context) => {
532
- if (context.error instanceof error) return fn(context);
531
+ const createErrorEventHandler = (fn, error) => {
532
+ const handler = (context) => {
533
+ if (context.error instanceof error) return fn(context);
534
+ };
535
+ const p = error?.prototype;
536
+ if (typeof p === "object" && p !== null && p !== Error.prototype && !(p instanceof Error)) handler["~errorClass"] = error;
537
+ return handler;
533
538
  };
534
539
  const isObject = (item) => item && typeof item === "object" && !Array.isArray(item);
535
540
  const isClassRegex = /^\s*class\s+/;
@@ -618,15 +623,21 @@ function joinPath(base, path) {
618
623
  if (!baseEndsWithSlash && !pathStartsWithSlash) return base + "/" + path;
619
624
  return base + path;
620
625
  }
621
- function pushField(target, key, item, defaultArray = false) {
626
+ function pushField(target, key, item) {
622
627
  const v = target[key];
623
628
  if (v) if (Array.isArray(v)) target[key].push(item);
624
629
  else target[key] = [v, item];
625
- else target[key] = defaultArray ? [item] : item;
630
+ else target[key] = item;
626
631
  }
627
- const requestId = isBun ? Bun.randomUUIDv7 : crypto.randomUUIDv7?.bind(crypto) ?? crypto.randomUUID?.bind(crypto);
632
+ const requestId = isBun ? Bun.randomUUIDv7 : crypto.randomUUID.bind(crypto);
633
+ /**
634
+ * Offset of the first byte after `://`, so the authority is never scanned as
635
+ * path. A fixed offset would let the client-supplied `Host` decide how many
636
+ * leading path bytes are dropped
637
+ */
638
+ const authorityEnd = (url) => url.charCodeAt(4) === 58 ? 7 : url.charCodeAt(5) === 58 ? 8 : url.indexOf("://") + 3;
628
639
  function replaceUrlPath(url, path) {
629
- const i = url.indexOf("/", 11);
640
+ const i = url.indexOf("/", authorityEnd(url));
630
641
  const qs = url.indexOf("?", i);
631
642
  return `${url.slice(0, i)}${path.charCodeAt(0) === 47 ? "" : "/"}${path}${qs === -1 ? "" : url.slice(qs)}`;
632
643
  }
@@ -651,7 +662,6 @@ function clonePlainDecorators(source, seen) {
651
662
  }
652
663
  return out;
653
664
  }
654
- const capitalize = (s) => s.charAt(0).toUpperCase() + s.slice(1);
655
665
  function prefix(prefix, models) {
656
666
  const prefixed = nullObject();
657
667
  for (const key in models) prefixed[`${prefix}.${key}`] = models[key];
@@ -659,7 +669,7 @@ function prefix(prefix, models) {
659
669
  }
660
670
  prefix.capitalize = function prefixModelsCapitalize(prefix, models) {
661
671
  const prefixed = nullObject();
662
- for (const key in models) prefixed[`${prefix}.${capitalize(key)}`] = models[key];
672
+ for (const key in models) prefixed[`${prefix}.${key.charAt(0).toUpperCase() + key.slice(1)}`] = models[key];
663
673
  return prefixed;
664
674
  };
665
675
  const macroSeedRefIds = /* @__PURE__ */ new WeakMap();
@@ -678,6 +688,38 @@ function serializeMacroSeed(_key, value) {
678
688
  default: return value;
679
689
  }
680
690
  }
691
+ const throwLifecycleErrors = (errors) => {
692
+ if (errors.length === 1) throw errors[0];
693
+ if (errors.length) throw new AggregateError(errors, "Multiple lifecycle failures");
694
+ };
695
+ const isDisposable = (value) => {
696
+ if (value == null) return false;
697
+ const kind = typeof value;
698
+ if (kind !== "object" && kind !== "function") return false;
699
+ try {
700
+ return typeof value[Symbol.asyncDispose] === "function" || typeof value[Symbol.dispose] === "function";
701
+ } catch {
702
+ return false;
703
+ }
704
+ };
705
+ const singletons = /* @__PURE__ */ new WeakSet();
706
+ const isSingleton = (value) => singletons.has(value);
707
+ const markSingletons = (value, depth = 4, seen = /* @__PURE__ */ new Set()) => {
708
+ if (value == null) return;
709
+ const kind = typeof value;
710
+ if (kind !== "object" && kind !== "function") return;
711
+ const object = value;
712
+ if (seen.has(object)) return;
713
+ seen.add(object);
714
+ singletons.add(object);
715
+ if (depth <= 0) return;
716
+ for (const key of Object.keys(object)) {
717
+ const descriptor = Object.getOwnPropertyDescriptor(object, key);
718
+ if (descriptor && "value" in descriptor) markSingletons(descriptor.value, depth - 1, seen);
719
+ }
720
+ };
721
+ const isSocketQuiet = (socket) => socket.readyState === 3 && !socket.data.inflight && !socket.data.opening && !socket.data.settling;
722
+ const isHTMLBundle = (value) => Object.prototype.toString.call(value) === "[object HTMLBundle]" || typeof value?.index === "string" && Array.isArray(value.files);
681
723
 
682
724
  //#endregion
683
- export { ELYSIA_FORM_PROTOTYPE, bytes, clearFlattenChainMemo, cloneHook, clonePlainDecorators, clonePlainDeep, coalesceSchemas, compactBeforeHandleConflicts, compactBeforeHandlePrefix, constantTimeEqual, createErrorEventHandler, deriveEntryFn, eventProperties, evictOldestHalf, flattenChain, flattenChainMemo, flattenChainMemoReadonly, fnOrigin, fnv1a, form, formToFormData, getLoosePath, guardNonPlainLeaves, hookToGuard, invalidateMacroEpoch, isBlob, isByteStream, isCompactBeforeHandleOnly, isElysiaForm, isEmpty, isLocalScope, isMapDeriveEntry, isNotEmpty, isRecordNumber, joinPath, macroEpoch, macroOrigin, mapDeriveEntry, mergeArray, mergeDeep, mergeHook, mergeResponse, nullObject, prefix, pushField, redirect, replaceUrlPath, requestId, schemaProperties, serializeMacroSeed, sse };
725
+ export { ELYSIA_FORM_PROTOTYPE, assignOwn, authorityEnd, bytes, clearFlattenChainMemo, cloneHook, clonePlainDecorators, clonePlainDeep, coalesceSchemas, compactBeforeHandleConflicts, compactBeforeHandlePrefix, compositionKeys, constantTimeEqual, createErrorEventHandler, deriveEntryFn, eventProperties, evictOldestHalf, flattenChain, flattenChainMemo, flattenChainMemoReadonly, fnOrigin, fnv1a, form, formToFormData, getLoosePath, guardNonPlainLeaves, hookToGuard, invalidateMacroEpoch, isBlob, isByteStream, isCompactBeforeHandleOnly, isDisposable, isElysiaForm, isEmpty, isHTMLBundle, isLocalScope, isMapDeriveEntry, isNotEmpty, isPlainObject, isRecordNumber, isSingleton, isSocketQuiet, joinPath, macroEpoch, macroOrigin, mapDeriveEntry, markSingletons, mergeArray, mergeDeep, mergeHook, mergeResponse, nullObject, prefix, pushField, redirect, refTargets, replaceUrlPath, requestId, rootSnapshot, schemaProperties, serializeMacroSeed, sse, sseData, throwLifecycleErrors };
@@ -1,5 +1,5 @@
1
- import { ElysiaConfig, MaybePromise } from "../types.js";
2
1
  import { AnySchema, StandardSchemaV1Like } from "../type/types.js";
2
+ import { ElysiaConfig, MaybePromise } from "../types.js";
3
3
  import { TypeBoxValidator } from "../type/bridge.js";
4
4
  import { CoerceOption } from "../type/coerce.js";
5
5
  import { ProgramId, ValidatorSlot } from "../compile/aot.js";
@@ -1,10 +1,10 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_utils = require('../utils.js');
2
3
  const require_type_bridge = require('../type/bridge.js');
3
4
  const require_error = require('../error.js');
4
5
  const require_compile_aot = require('../compile/aot.js');
5
6
  const require_compile_utils = require('../compile/utils.js');
6
7
  const require_type_shared = require('../type/shared.js');
7
- const require_type_elysia_file_type = require('../type/elysia/file-type.js');
8
8
  const require_type_utils = require('../type/utils.js');
9
9
 
10
10
  //#region src/validator/index.ts
@@ -35,11 +35,7 @@ var Validator = class Validator {
35
35
  schemas: options.schemas.map((v) => Validator.reference(v, models))
36
36
  };
37
37
  }
38
- if (isCompiledSchema(schema)) {
39
- const message = "[Elysia] Compiled schema detected. Please pass t.Schema instead.";
40
- if (require_compile_aot.Capture.isCapturing()) throw new Error(`${message} build plugin cannot serialize a pre-compiled schema.`);
41
- console.warn(message);
42
- }
38
+ if (schema != null && typeof schema.Check === "function" && "evaluateResult" in schema && !("~standard" in schema)) throw new Error("[Elysia] Compiled schema detected. Please pass t.Schema instead.");
43
39
  let isIntersectable = false;
44
40
  if (options?.schemas?.length) if ("~kind" in schema && options.schemas.every((v) => "~kind" in v || "~elyAcl" in v)) isIntersectable = true;
45
41
  else return new MultiValidator(schema, options);
@@ -99,7 +95,6 @@ var Validator = class Validator {
99
95
  require_type_shared.clearSharedReferenceCaches();
100
96
  }
101
97
  };
102
- const isCompiledSchema = (schema) => schema != null && typeof schema.Check === "function" && "buildResult" in schema;
103
98
  const isSingleSchema = (schema) => "~kind" in schema || "~elyAcl" in schema || "~standard" in schema;
104
99
  const toStatusBased = (schema) => isSingleSchema(schema) ? { 200: schema } : schema;
105
100
  const isAsyncStandardSchema = (schema) => require_compile_utils.isAsyncFunction(schema["~standard"].validate);
@@ -143,7 +138,6 @@ var MultiValidator = class MultiValidator extends Validator {
143
138
  #schemas;
144
139
  #codecs;
145
140
  #hasDefaults;
146
- #tbSchemas;
147
141
  #asyncMembers;
148
142
  constructor(schema, options) {
149
143
  super();
@@ -152,7 +146,6 @@ var MultiValidator = class MultiValidator extends Validator {
152
146
  const schemas = [schema].concat(options.schemas);
153
147
  const codecs = [];
154
148
  const hasDefaults = [];
155
- const tbSchemas = [];
156
149
  const asyncMembers = [];
157
150
  const shouldClose = options?.normalize === false;
158
151
  const compileMember = (rawSchema, hd) => {
@@ -161,8 +154,7 @@ var MultiValidator = class MultiValidator extends Validator {
161
154
  const compiled = require_type_bridge.Compile(coercedSchema);
162
155
  codecs.push(require_type_bridge.HasCodec(coercedSchema));
163
156
  hasDefaults.push(hd);
164
- tbSchemas.push(hd ? coercedSchema : null);
165
- if (compiled.buildResult?.external?.variables?.some(require_type_elysia_file_type.isAsyncPredicate) ?? false) {
157
+ if (require_type_bridge.TypeBoxValidator.member(coercedSchema, compiled)) {
166
158
  this.isAsync = true;
167
159
  asyncMembers.push(Validator.create(rawSchema, {
168
160
  coerces: options?.coerces,
@@ -188,7 +180,6 @@ var MultiValidator = class MultiValidator extends Validator {
188
180
  if (isAsyncStandardSchema(schema)) this.isAsync = true;
189
181
  codecs.push(false);
190
182
  hasDefaults.push(false);
191
- tbSchemas.push(null);
192
183
  asyncMembers.push(null);
193
184
  }
194
185
  }
@@ -196,7 +187,6 @@ var MultiValidator = class MultiValidator extends Validator {
196
187
  this.#schemas = schemas;
197
188
  this.#codecs = codecs;
198
189
  this.#hasDefaults = hasDefaults;
199
- this.#tbSchemas = tbSchemas;
200
190
  this.#asyncMembers = asyncMembers;
201
191
  }
202
192
  static #merge(snapshot, result) {
@@ -205,7 +195,7 @@ var MultiValidator = class MultiValidator extends Validator {
205
195
  snapshot.push(...result);
206
196
  return snapshot;
207
197
  }
208
- if (typeof snapshot === "object" && typeof result === "object") return Object.assign(snapshot, result);
198
+ if (typeof snapshot === "object" && typeof result === "object") return require_utils.assignOwn(snapshot, result);
209
199
  throw new Error("Unable to merged value with different type");
210
200
  }
211
201
  static #syncStandard(schema, value) {
@@ -247,20 +237,6 @@ var MultiValidator = class MultiValidator extends Validator {
247
237
  EncodeFrom(value) {
248
238
  return this.From(value);
249
239
  }
250
- #fromTypeBox(compiled, index, value, type) {
251
- let v = this.#cloneForMember(value);
252
- if (this.#hasDefaults[index]) v = compiled.Default ? compiled.Default(v) : require_type_bridge.Default(this.#tbSchemas[index], v);
253
- if (this.#codecs[index]) try {
254
- return compiled.Clean(compiled.Decode(v));
255
- } catch {
256
- throw new require_error.ValidationError(type, value, () => compiled.Errors(value));
257
- }
258
- if (!compiled.Check(v)) throw new require_error.ValidationError(type, value, () => compiled.Errors(v));
259
- return compiled.Clean(v);
260
- }
261
- #fromTypeBoxAsync(tbv, value, type) {
262
- return tbv.FromAsync(this.#cloneForMember(value), type);
263
- }
264
240
  From(value, type, allowAsync = this.isAsync) {
265
241
  return this.#fromLoop(value, 0, void 0, type, allowAsync);
266
242
  }
@@ -283,9 +259,20 @@ var MultiValidator = class MultiValidator extends Validator {
283
259
  const asyncTbv = this.#asyncMembers[i];
284
260
  if (asyncTbv) {
285
261
  if (!allowAsync) throw asyncStandardSchemaError();
286
- return this.#fromTypeBoxAsync(asyncTbv, value, type).then((result) => this.#fromLoop(value, i + 1, MultiValidator.#merge(snapshot, result), type, allowAsync));
262
+ return asyncTbv.FromAsync(this.#cloneForMember(value), type).then((result) => this.#fromLoop(value, i + 1, MultiValidator.#merge(snapshot, result), type, allowAsync));
263
+ }
264
+ const compiled = validator;
265
+ let v = this.#cloneForMember(value);
266
+ if (this.#hasDefaults[i]) v = compiled.Default(v);
267
+ let memberValue;
268
+ if (this.#codecs[i]) try {
269
+ memberValue = compiled.Clean(compiled.Decode(v));
270
+ } catch {
271
+ throw new require_error.ValidationError(type, value, () => compiled.Errors(value));
287
272
  }
288
- snapshot = MultiValidator.#merge(snapshot, this.#fromTypeBox(validator, i, value, type));
273
+ else if (!compiled.Check(v)) throw new require_error.ValidationError(type, value, () => compiled.Errors(v));
274
+ else memberValue = compiled.Clean(v);
275
+ snapshot = MultiValidator.#merge(snapshot, memberValue);
289
276
  }
290
277
  return snapshot;
291
278
  }