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/error.js CHANGED
@@ -29,20 +29,60 @@ function isCacheableExpected(value, visited = /* @__PURE__ */ new Set()) {
29
29
  var ElysiaError = class extends Error {
30
30
  constructor(message, cause) {
31
31
  super(message);
32
- this.problemType = "about:blank";
33
32
  this.name = this.constructor.name;
34
33
  if (cause) this.cause = cause;
35
34
  }
36
35
  toResponse(headers) {
37
- return problemResponse({
38
- type: this.problemType,
39
- title: this.problemTitle,
40
- status: this.status ?? 500,
41
- detail: this.response !== void 0 && this.response !== this.problemTitle ? this.response : void 0
42
- }, headers);
36
+ return problemResponse(elysiaErrorProblem(this), headers);
43
37
  }
44
38
  };
45
39
  /**
40
+ * `type` an error slug resolves to: the slug verbatim, or `<typeBase>/<slug>`
41
+ * once {@link HTTPError.typeBase} is set. Shared by `ElysiaError` and every
42
+ * class {@link HTTPError.id} makes, so both lanes derive `type` identically
43
+ */
44
+ function problemTypeOf(code) {
45
+ if (code === void 0) return;
46
+ const base = HTTPError.typeBase;
47
+ if (!base) return code;
48
+ return (base.endsWith("/") ? base : base + "/") + code;
49
+ }
50
+ /**
51
+ * Problem members an `ElysiaError` serves. `title` is left to `problemBody`,
52
+ * which derives it from the status — so `response` is only worth serving as
53
+ * `detail` when it says something the title doesn't
54
+ */
55
+ function elysiaErrorProblem(error) {
56
+ const status = error.status ?? 500;
57
+ return {
58
+ type: error.type ?? "about:blank",
59
+ code: error.code,
60
+ status,
61
+ detail: error.response !== void 0 && error.response !== require_constants.StatusMapBack[status] ? error.response : void 0
62
+ };
63
+ }
64
+ function defineData(target, key, value, enumerable = true) {
65
+ Object.defineProperty(target, key, {
66
+ value,
67
+ writable: true,
68
+ enumerable,
69
+ configurable: true
70
+ });
71
+ }
72
+ function defineProblemType(prototype) {
73
+ Object.defineProperty(prototype, "type", {
74
+ get() {
75
+ return problemTypeOf(this.code);
76
+ },
77
+ set(value) {
78
+ defineData(this, "type", value);
79
+ },
80
+ enumerable: true,
81
+ configurable: true
82
+ });
83
+ }
84
+ defineProblemType(ElysiaError.prototype);
85
+ /**
46
86
  * Wrap a string into a TypeBox `error` callback that overrides the default
47
87
  * validation message. Use as `t.Number({ error: validationDetail('x must be a number') })`.
48
88
  */
@@ -55,8 +95,7 @@ var InternalServerError = class extends ElysiaError {
55
95
  super(response, cause);
56
96
  this.response = response;
57
97
  this.status = 500;
58
- this.problemType = "internal-server-error";
59
- this.problemTitle = "Internal Server Error";
98
+ this.code = "internal-server-error";
60
99
  }
61
100
  };
62
101
  var NotFound = class extends ElysiaError {
@@ -64,8 +103,7 @@ var NotFound = class extends ElysiaError {
64
103
  super(response);
65
104
  this.response = response;
66
105
  this.status = 404;
67
- this.problemType = "not-found";
68
- this.problemTitle = "Not Found";
106
+ this.code = "not-found";
69
107
  }
70
108
  };
71
109
  var ParseError = class extends ElysiaError {
@@ -73,15 +111,12 @@ var ParseError = class extends ElysiaError {
73
111
  super("Bad Request", cause);
74
112
  this.status = 400;
75
113
  this.response = "Bad Request";
76
- this.problemType = "parse";
77
- this.problemTitle = "Bad Request";
114
+ this.code = "parse";
78
115
  }
79
116
  toResponse(headers) {
80
117
  const cause = this.cause;
81
118
  return problemResponse({
82
- type: this.problemType,
83
- title: this.problemTitle,
84
- status: 400,
119
+ ...elysiaErrorProblem(this),
85
120
  detail: !require_universal_is_production.isProduction() && cause?.message != null ? String(cause.message) : void 0
86
121
  }, headers);
87
122
  }
@@ -113,6 +148,7 @@ function walkComposition(schema, parts, seen = /* @__PURE__ */ new WeakSet()) {
113
148
  const walkSubSchema = (schema, instancePath) => !schema || !instancePath ? schema : walkComposition(schema, instancePath.split("/").filter(Boolean));
114
149
  const FOUND_ECHO_LIMIT = 8192;
115
150
  const FOUND_ECHO_OMITTED = `[value exceeds ${FOUND_ECHO_LIMIT} byte echo limit]`;
151
+ const MAX_ERRORS = 64;
116
152
  function jsonStringLengthWithin(value, budget) {
117
153
  budget -= 2;
118
154
  for (let i = 0; i < value.length && budget >= 0; i++) {
@@ -174,11 +210,54 @@ function subValueAt(value, path) {
174
210
  }
175
211
  return current;
176
212
  }
177
- function scopeFound(value, first) {
178
- if (jsonLengthWithin(value, FOUND_ECHO_LIMIT) >= 0) return value;
179
- const sub = subValueAt(value, first?.instancePath ?? first?.path);
180
- if (sub !== void 0 && jsonLengthWithin(sub, FOUND_ECHO_LIMIT) >= 0) return sub;
181
- return FOUND_ECHO_OMITTED;
213
+ const issueLocator = new Set([
214
+ "keyword",
215
+ "schemaPath",
216
+ "instancePath",
217
+ "path"
218
+ ]);
219
+ function scopeIssues(errors) {
220
+ let budget = FOUND_ECHO_LIMIT;
221
+ let out;
222
+ for (let i = 0; i < errors.length; i++) {
223
+ const issue = errors[i];
224
+ if (!issue || typeof issue !== "object") {
225
+ out?.push(issue);
226
+ continue;
227
+ }
228
+ let scoped;
229
+ for (const key in issue) {
230
+ if (issueLocator.has(key)) continue;
231
+ const member = issue[key];
232
+ const remaining = jsonLengthWithin(member, budget);
233
+ if (remaining >= 0) {
234
+ budget = remaining;
235
+ continue;
236
+ }
237
+ scoped ??= { ...issue };
238
+ if (member === null || typeof member !== "object" || Array.isArray(member)) {
239
+ scoped[key] = FOUND_ECHO_OMITTED;
240
+ continue;
241
+ }
242
+ const narrowed = {};
243
+ for (const name in member) {
244
+ const value = member[name];
245
+ const rest = jsonLengthWithin(value, budget);
246
+ if (rest >= 0) {
247
+ narrowed[name] = value;
248
+ budget = rest;
249
+ } else narrowed[name] = FOUND_ECHO_OMITTED;
250
+ }
251
+ scoped[key] = narrowed;
252
+ }
253
+ if (!scoped) {
254
+ out?.push(issue);
255
+ continue;
256
+ }
257
+ out ??= errors.slice(0, i);
258
+ out.push(scoped);
259
+ }
260
+ return out ?? errors;
182
261
  }
183
262
  var ValidationError = class extends ElysiaError {
184
263
  #thunk;
@@ -189,19 +268,16 @@ var ValidationError = class extends ElysiaError {
189
268
  this.type = type;
190
269
  this.value = value;
191
270
  this.status = 422;
271
+ this.code = "validation";
192
272
  this.allowUnsafeValidationDetails = false;
273
+ if (type === "response") this.status = 500;
193
274
  this.schema = schema;
194
275
  this.#thunk = typeof errors === "function" ? errors : () => errors;
195
276
  this.#findCustomError = findCustomError;
196
277
  Object.defineProperty(this, "errors", {
197
278
  get: () => this["~resolve"]().errors,
198
279
  set(v) {
199
- Object.defineProperty(this, "errors", {
200
- value: v,
201
- writable: true,
202
- enumerable: true,
203
- configurable: true
204
- });
280
+ defineData(this, "errors", v);
205
281
  },
206
282
  enumerable: true,
207
283
  configurable: true
@@ -216,7 +292,6 @@ var ValidationError = class extends ElysiaError {
216
292
  const findCustomError = this.#findCustomError;
217
293
  let resolved;
218
294
  let custom;
219
- let message;
220
295
  if (production && !allowUnsafe && findCustomError) {
221
296
  const hit = findCustomError(value);
222
297
  resolved = hit ? [{ instancePath: hit.instancePath }] : [];
@@ -225,26 +300,23 @@ var ValidationError = class extends ElysiaError {
225
300
  on: type,
226
301
  found: void 0
227
302
  }) : hit.error;
228
- message = custom !== void 0 ? typeof custom === "string" ? custom : JSON.stringify(custom) : `Validation error on ${type ?? "unknown"}`;
229
- return this.#state = {
230
- errors: resolved,
231
- custom,
232
- message
233
- };
303
+ } else {
304
+ resolved = this.#thunk() ?? [];
305
+ if (resolved.length > 64) resolved = resolved.slice(0, 64);
306
+ resolved = scopeIssues(resolved);
307
+ const sub = walkSubSchema(this.schema, resolved[0]?.instancePath);
308
+ if (sub?.error !== void 0) custom = typeof sub.error === "function" ? sub.error(production && !allowUnsafe ? {
309
+ type: "validation",
310
+ on: type,
311
+ found: void 0
312
+ } : {
313
+ type: "validation",
314
+ on: type,
315
+ value,
316
+ errors: resolved
317
+ }) : sub.error;
234
318
  }
235
- resolved = this.#thunk() ?? [];
236
- const sub = walkSubSchema(this.schema, resolved[0]?.instancePath);
237
- if (sub?.error !== void 0) custom = typeof sub.error === "function" ? sub.error(production && !allowUnsafe ? {
238
- type: "validation",
239
- on: type,
240
- found: void 0
241
- } : {
242
- type: "validation",
243
- on: type,
244
- value,
245
- errors: resolved
246
- }) : sub.error;
247
- message = custom !== void 0 ? typeof custom === "string" ? custom : JSON.stringify(custom) : resolved[0]?.message ? resolved[0].message : `Validation error on ${type ?? "unknown"}`;
319
+ const message = custom !== void 0 ? typeof custom === "string" ? custom : JSON.stringify(custom) : resolved[0]?.message ? resolved[0].message : `Validation error on ${type ?? "unknown"}`;
248
320
  return this.#state = {
249
321
  errors: resolved,
250
322
  custom,
@@ -255,16 +327,21 @@ var ValidationError = class extends ElysiaError {
255
327
  return this["~resolve"]().custom;
256
328
  }
257
329
  set customError(v) {
258
- Object.defineProperty(this, "customError", {
259
- value: v,
260
- writable: true,
261
- enumerable: true,
262
- configurable: true
263
- });
330
+ defineData(this, "customError", v);
264
331
  }
265
332
  get all() {
266
333
  if (!this.errors) return [];
267
- return this.#collapseCoercionErrors(this.errors.filter(Boolean)).map((e) => this.#normalizeIssue(e));
334
+ return this.#collapseCoercionErrors(this.errors.filter(Boolean)).map((e) => {
335
+ if (!e) return e;
336
+ const issue = {
337
+ path: Array.isArray(e.path) ? e.path.length ? e.path.map(segmentString).join(".") : "root" : typeof e.path === "string" ? e.path.replace(/^\//, "").replace(/\//g, ".") || "root" : "root",
338
+ message: e.message ?? "",
339
+ schemaPath: e.schemaPath,
340
+ params: e.params
341
+ };
342
+ defineData(issue, "value", this.value, false);
343
+ return issue;
344
+ });
268
345
  }
269
346
  #collapseCoercionErrors(errors) {
270
347
  if (!this.schema || !errors.length) return errors;
@@ -304,52 +381,30 @@ var ValidationError = class extends ElysiaError {
304
381
  }
305
382
  return out ?? errors;
306
383
  }
307
- #normalizeIssue(e) {
308
- if (!e) return e;
309
- return {
310
- path: Array.isArray(e.path) ? e.path.length ? e.path.map(segmentString).join(".") : "root" : typeof e.path === "string" ? e.path.replace(/^\//, "").replace(/\//g, ".") || "root" : "root",
311
- message: e.message ?? "",
312
- schemaPath: e.schemaPath,
313
- params: e.params,
314
- value: this.value
315
- };
316
- }
317
384
  get #productionDetail() {
318
385
  return require_universal_is_production.isProduction() && !this.allowUnsafeValidationDetails;
319
386
  }
320
- get #maskResponseValue() {
321
- return this.type === "response" && this.#productionDetail;
322
- }
323
387
  detail(message) {
324
- if (this.#productionDetail) {
325
- if (this.type === "response") return {
326
- type: "internal-server-error",
327
- on: this.type,
328
- message
329
- };
330
- return {
331
- type: "validation",
332
- on: this.type,
333
- message
334
- };
335
- }
336
- return {
388
+ if (!this.#productionDetail) return {
337
389
  type: "validation",
338
390
  on: this.type,
339
391
  message,
340
392
  errors: this.all
341
393
  };
394
+ return {
395
+ type: this.type === "response" ? "internal-server-error" : "validation",
396
+ on: this.type,
397
+ message
398
+ };
342
399
  }
343
400
  get payload() {
401
+ const server = this.type === "response";
344
402
  if (this.#productionDetail) {
345
- if (this.type === "response") return {
346
- type: "internal-server-error",
347
- title: "Internal Server Error",
348
- status: 500
349
- };
403
+ if (server) return internalServerErrorProblem();
350
404
  const first = (this.errors ?? []).find(Boolean);
351
405
  return {
352
406
  type: "validation",
407
+ code: "validation",
353
408
  title: "Validation Error",
354
409
  status: 422,
355
410
  on: this.type,
@@ -374,24 +429,35 @@ var ValidationError = class extends ElysiaError {
374
429
  }
375
430
  else expected = created;
376
431
  } catch {}
432
+ const value = this.value;
433
+ let found;
434
+ if (jsonLengthWithin(value, FOUND_ECHO_LIMIT) >= 0) found = value;
435
+ else {
436
+ const sub = subValueAt(value, first?.instancePath ?? first?.path);
437
+ if (sub !== void 0 && jsonLengthWithin(sub, FOUND_ECHO_LIMIT) >= 0) found = sub;
438
+ else found = FOUND_ECHO_OMITTED;
439
+ }
377
440
  return {
378
- type: "validation",
379
- title: "Validation Error",
380
- status: 422,
441
+ ...server ? internalServerErrorProblem() : {
442
+ type: "validation",
443
+ code: "validation",
444
+ title: "Validation Error",
445
+ status: 422
446
+ },
381
447
  detail,
382
448
  on: this.type,
383
449
  property,
384
- found: scopeFound(this.value, first),
450
+ found,
385
451
  expected,
386
452
  errors
387
453
  };
388
454
  }
389
455
  toResponse(headers) {
390
- if (this.#maskResponseValue) return problemResponse(this.payload, headers);
456
+ if (this.type === "response" && this.#productionDetail) return problemResponse(this.payload, headers);
391
457
  if (this.customError !== void 0) {
392
458
  const isString = typeof this.customError === "string";
393
459
  const response = new Response(isString ? this.customError : JSON.stringify(this.customError), {
394
- status: this.status ?? 422,
460
+ status: this.type === "response" ? 500 : this.status ?? 422,
395
461
  headers: {
396
462
  ...headers,
397
463
  "content-type": isString ? "text/plain" : "application/json"
@@ -408,12 +474,7 @@ Object.defineProperty(ValidationError.prototype, "message", {
408
474
  return this["~resolve"]().message;
409
475
  },
410
476
  set(v) {
411
- Object.defineProperty(this, "message", {
412
- value: v,
413
- writable: true,
414
- enumerable: false,
415
- configurable: true
416
- });
477
+ defineData(this, "message", v, false);
417
478
  },
418
479
  enumerable: false,
419
480
  configurable: true
@@ -429,13 +490,10 @@ const emptyHttpStatus = new Set([
429
490
  var ElysiaStatus = class {
430
491
  constructor(code, res, headers) {
431
492
  const response = res ?? (code in require_constants.StatusMapBack ? require_constants.StatusMapBack[code] : code);
432
- this.code = require_constants.StatusMap[code] ?? code;
433
- if (!emptyHttpStatus.has(this.code)) this.response = response;
493
+ this.status = require_constants.StatusMap[code] ?? code;
494
+ if (!emptyHttpStatus.has(this.status)) this.response = response;
434
495
  this.headers = headers;
435
496
  }
436
- get status() {
437
- return this.code;
438
- }
439
497
  };
440
498
  Object.defineProperty(ElysiaStatus, "name", { value: "ElysiaStatus" });
441
499
  const status = (code, response) => new ElysiaStatus(code, response);
@@ -462,12 +520,14 @@ function problemResponse(p, headers) {
462
520
  require_adapter_skip_clone.skipClone.add(response);
463
521
  return response;
464
522
  }
523
+ const internalServerErrorProblem = () => ({
524
+ type: problemTypeOf("internal-server-error"),
525
+ code: "internal-server-error",
526
+ title: "Internal Server Error",
527
+ status: 500
528
+ });
465
529
  function internalServerErrorBody(error) {
466
- const body = {
467
- type: "internal-server-error",
468
- title: "Internal Server Error",
469
- status: 500
470
- };
530
+ const body = internalServerErrorProblem();
471
531
  if (!require_universal_is_production.isProduction()) {
472
532
  if (error?.message != null) body.detail = error.message;
473
533
  if (error?.name) body.name = error.name;
@@ -484,11 +544,7 @@ function internalServerErrorBodyString(error) {
484
544
  delete safe.cause;
485
545
  return JSON.stringify(safe);
486
546
  } catch {
487
- return JSON.stringify({
488
- type: "internal-server-error",
489
- title: "Internal Server Error",
490
- status: 500
491
- });
547
+ return JSON.stringify(internalServerErrorProblem());
492
548
  }
493
549
  }
494
550
  }
@@ -566,12 +622,17 @@ function problem(statusOrDetail, detail) {
566
622
  * @since 2.0.0
567
623
  */
568
624
  var HTTPError = class HTTPError extends Error {
569
- static id(type, status) {
570
- const Tagged = class extends HTTPError {};
571
- Tagged.prototype.type = type;
572
- Tagged.prototype.name = type;
625
+ static id(code, status) {
626
+ const Tagged = class extends HTTPError {
627
+ constructor(..._args) {
628
+ super(..._args);
629
+ this.code = code;
630
+ }
631
+ };
632
+ defineProblemType(Tagged.prototype);
633
+ Tagged.prototype.name = code;
573
634
  Object.defineProperty(Tagged, "name", {
574
- value: type,
635
+ value: code,
575
636
  configurable: true
576
637
  });
577
638
  const resolved = typeof status === "string" ? require_constants.StatusMap[status] : status;
@@ -585,10 +646,12 @@ exports.ElysiaError = ElysiaError;
585
646
  exports.ElysiaStatus = ElysiaStatus;
586
647
  exports.HTTPError = HTTPError;
587
648
  exports.InternalServerError = InternalServerError;
649
+ exports.MAX_ERRORS = MAX_ERRORS;
588
650
  exports.NotFound = NotFound;
589
651
  exports.PROBLEM_JSON = PROBLEM_JSON;
590
652
  exports.ParseError = ParseError;
591
653
  exports.ValidationError = ValidationError;
654
+ exports.elysiaErrorProblem = elysiaErrorProblem;
592
655
  exports.internalServerErrorBody = internalServerErrorBody;
593
656
  exports.internalServerErrorBodyString = internalServerErrorBodyString;
594
657
  exports.internalServerErrorResponse = internalServerErrorResponse;
@@ -596,6 +659,7 @@ exports.isProduction = require_universal_is_production.isProduction;
596
659
  exports.problem = problem;
597
660
  exports.problemBody = problemBody;
598
661
  exports.problemResponse = problemResponse;
662
+ exports.problemTypeOf = problemTypeOf;
599
663
  exports.status = status;
600
664
  exports.subValueAt = subValueAt;
601
665
  exports.validationDetail = validationDetail;