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.d.ts CHANGED
@@ -6,13 +6,32 @@ import { MaybePromise } from "./types.js";
6
6
  declare class ElysiaError<Status extends number = number, Response extends string = string> extends Error {
7
7
  status?: Status;
8
8
  response?: Response;
9
- /** RFC 9457 problem `type` slug (overridden per subclass) */
10
- problemType: string;
11
- /** RFC 9457 problem `title` (overridden per subclass) */
12
- problemTitle?: string;
9
+ /**
10
+ * Stable machine-readable token served in the `code` member, the same
11
+ * contract a {@link HTTPError.id} class speaks (set per subclass)
12
+ */
13
+ readonly code?: string;
14
+ /**
15
+ * RFC 9457 problem type served in the `type` member. Mirrors `code`, or
16
+ * resolves to `<typeBase>/<code>` once {@link HTTPError.typeBase} is set.
17
+ * Defined on the prototype below
18
+ */
19
+ type?: string;
13
20
  constructor(message: string, cause?: Error);
14
21
  toResponse(headers?: Record<string, any>): globalThis.Response;
15
22
  }
23
+ /**
24
+ * `type` an error slug resolves to: the slug verbatim, or `<typeBase>/<slug>`
25
+ * once {@link HTTPError.typeBase} is set. Shared by `ElysiaError` and every
26
+ * class {@link HTTPError.id} makes, so both lanes derive `type` identically
27
+ */
28
+ declare function problemTypeOf(code: string | undefined): string | undefined;
29
+ /**
30
+ * Problem members an `ElysiaError` serves. `title` is left to `problemBody`,
31
+ * which derives it from the status — so `response` is only worth serving as
32
+ * `detail` when it says something the title doesn't
33
+ */
34
+ declare function elysiaErrorProblem(error: ElysiaError): Problem;
16
35
  /**
17
36
  * Wrap a string into a TypeBox `error` callback that overrides the default
18
37
  * validation message. Use as `t.Number({ error: validationDetail('x must be a number') })`.
@@ -21,31 +40,31 @@ declare const validationDetail: <T>(message: T) => (error: any) => any;
21
40
  declare class InternalServerError extends ElysiaError {
22
41
  response: string;
23
42
  status: 500;
24
- problemType: string;
25
- problemTitle: string;
43
+ readonly code = "internal-server-error";
26
44
  constructor(response?: string, cause?: Error);
27
45
  }
28
46
  declare class NotFound extends ElysiaError {
29
47
  response: string;
30
48
  status: 404;
31
- problemType: string;
32
- problemTitle: string;
49
+ readonly code = "not-found";
33
50
  constructor(response?: string);
34
51
  }
35
52
  declare class ParseError extends ElysiaError {
36
53
  status: 400;
37
54
  response: string;
38
- problemType: string;
39
- problemTitle: string;
55
+ readonly code = "parse";
40
56
  constructor(cause?: Error);
41
57
  toResponse(headers?: Record<string, any>): Response;
42
58
  }
59
+ declare const MAX_ERRORS = 64;
43
60
  declare function subValueAt(value: unknown, path: unknown): any;
44
61
  declare class ValidationError extends ElysiaError {
45
62
  #private;
46
63
  type: string | undefined;
47
64
  value: unknown;
48
- status: 422;
65
+ /** Response validation is a server error; other validation is a client error. */
66
+ status: 422 | 500;
67
+ readonly code = "validation";
49
68
  schema?: unknown;
50
69
  message: string;
51
70
  allowUnsafeValidationDetails: boolean;
@@ -57,7 +76,7 @@ declare class ValidationError extends ElysiaError {
57
76
  '~resolve'(): {
58
77
  errors: any[];
59
78
  custom: unknown;
60
- message: string;
79
+ message: any;
61
80
  };
62
81
  errors: any[];
63
82
  get customError(): unknown;
@@ -67,116 +86,56 @@ declare class ValidationError extends ElysiaError {
67
86
  type: string;
68
87
  on: string | undefined;
69
88
  message: unknown;
70
- errors?: undefined;
89
+ errors: any[];
71
90
  } | {
72
91
  type: string;
73
92
  on: string | undefined;
74
93
  message: unknown;
75
- errors: any[];
94
+ errors?: undefined;
76
95
  };
77
96
  get payload(): {
78
- type: string;
97
+ type: string | undefined;
98
+ code: string;
79
99
  title: string;
80
100
  status: number;
81
- on?: undefined;
82
- property?: undefined;
83
- detail?: undefined;
84
- found?: undefined;
85
- expected?: undefined;
86
- errors?: undefined;
87
101
  } | {
88
102
  type: string;
103
+ code: string;
89
104
  title: string;
90
105
  status: number;
91
106
  on: string | undefined;
92
107
  property: string;
93
- detail?: undefined;
94
- found?: undefined;
95
- expected?: undefined;
96
- errors?: undefined;
97
108
  } | {
98
- type: string;
99
- title: string;
100
- status: number;
101
109
  detail: any;
102
110
  on: string | undefined;
103
111
  property: string;
104
- found: any;
112
+ found: unknown;
105
113
  expected: unknown;
106
114
  errors: any[];
115
+ type: string | undefined;
116
+ code: string;
117
+ title: string;
118
+ status: number;
107
119
  };
108
120
  toResponse(headers?: Record<string, any>): Response;
109
121
  }
110
- declare class ElysiaStatus<const in out Code extends number | keyof StatusMap, T = (Code extends keyof StatusMapBack ? StatusMapBack[Code] : Code), const in out Status extends (Code extends keyof StatusMap ? StatusMap[Code] : Code) = (Code extends keyof StatusMap ? StatusMap[Code] : Code)> {
111
- code: Status;
122
+ /** Default body for a status with no response. Named to keep emitted types small. */
123
+ type StatusResponse<Code extends number | keyof StatusMap> = Code extends keyof StatusMapBack ? StatusMapBack[Code] : Code;
124
+ declare class ElysiaStatus<const in out Code extends number | keyof StatusMap, T = StatusResponse<Code>, const in out Status extends NumericStatus<Code> = NumericStatus<Code>> {
125
+ /**
126
+ * Type-only brand, erased at runtime.
127
+ *
128
+ * `status` + `response` is a shape a handler may write by hand, so without
129
+ * a nominal marker a plain `{ status, response }` literal would be
130
+ * absorbed as a status box by response inference
131
+ */
132
+ readonly ['~status']: true;
133
+ status: Status;
112
134
  response: T;
113
135
  headers?: Record<string, string>;
114
136
  constructor(code: Code, res: T, headers?: Record<string, string>);
115
- get status(): number;
116
137
  }
117
- declare const status: <const Code extends number | keyof StatusMap, const T = (Code extends keyof StatusMapBack ? StatusMapBack[Code] : Code)>(code: Code, response?: T) => ElysiaStatus<Code, T, Code extends "Continue" | "Switching Protocols" | "Processing" | "Early Hints" | "OK" | "Created" | "Accepted" | "Non-Authoritative Information" | "No Content" | "Reset Content" | "Partial Content" | "Multi-Status" | "Already Reported" | "Multiple Choices" | "Moved Permanently" | "Found" | "See Other" | "Not Modified" | "Temporary Redirect" | "Permanent Redirect" | "Bad Request" | "Unauthorized" | "Payment Required" | "Forbidden" | "Not Found" | "Method Not Allowed" | "Not Acceptable" | "Proxy Authentication Required" | "Request Timeout" | "Conflict" | "Gone" | "Length Required" | "Precondition Failed" | "Payload Too Large" | "URI Too Long" | "Unsupported Media Type" | "Range Not Satisfiable" | "Expectation Failed" | "I'm a teapot" | "Enhance Your Calm" | "Misdirected Request" | "Unprocessable Content" | "Locked" | "Failed Dependency" | "Too Early" | "Upgrade Required" | "Precondition Required" | "Too Many Requests" | "Request Header Fields Too Large" | "Unavailable For Legal Reasons" | "Internal Server Error" | "Not Implemented" | "Bad Gateway" | "Service Unavailable" | "Gateway Timeout" | "HTTP Version Not Supported" | "Variant Also Negotiates" | "Insufficient Storage" | "Loop Detected" | "Not Extended" | "Network Authentication Required" ? {
118
- readonly Continue: 100;
119
- readonly 'Switching Protocols': 101;
120
- readonly Processing: 102;
121
- readonly 'Early Hints': 103;
122
- readonly OK: 200;
123
- readonly Created: 201;
124
- readonly Accepted: 202;
125
- readonly 'Non-Authoritative Information': 203;
126
- readonly 'No Content': 204;
127
- readonly 'Reset Content': 205;
128
- readonly 'Partial Content': 206;
129
- readonly 'Multi-Status': 207;
130
- readonly 'Already Reported': 208;
131
- readonly 'Multiple Choices': 300;
132
- readonly 'Moved Permanently': 301;
133
- readonly Found: 302;
134
- readonly 'See Other': 303;
135
- readonly 'Not Modified': 304;
136
- readonly 'Temporary Redirect': 307;
137
- readonly 'Permanent Redirect': 308;
138
- readonly 'Bad Request': 400;
139
- readonly Unauthorized: 401;
140
- readonly 'Payment Required': 402;
141
- readonly Forbidden: 403;
142
- readonly 'Not Found': 404;
143
- readonly 'Method Not Allowed': 405;
144
- readonly 'Not Acceptable': 406;
145
- readonly 'Proxy Authentication Required': 407;
146
- readonly 'Request Timeout': 408;
147
- readonly Conflict: 409;
148
- readonly Gone: 410;
149
- readonly 'Length Required': 411;
150
- readonly 'Precondition Failed': 412;
151
- readonly 'Payload Too Large': 413;
152
- readonly 'URI Too Long': 414;
153
- readonly 'Unsupported Media Type': 415;
154
- readonly 'Range Not Satisfiable': 416;
155
- readonly 'Expectation Failed': 417;
156
- readonly "I'm a teapot": 418;
157
- readonly 'Enhance Your Calm': 420;
158
- readonly 'Misdirected Request': 421;
159
- readonly 'Unprocessable Content': 422;
160
- readonly Locked: 423;
161
- readonly 'Failed Dependency': 424;
162
- readonly 'Too Early': 425;
163
- readonly 'Upgrade Required': 426;
164
- readonly 'Precondition Required': 428;
165
- readonly 'Too Many Requests': 429;
166
- readonly 'Request Header Fields Too Large': 431;
167
- readonly 'Unavailable For Legal Reasons': 451;
168
- readonly 'Internal Server Error': 500;
169
- readonly 'Not Implemented': 501;
170
- readonly 'Bad Gateway': 502;
171
- readonly 'Service Unavailable': 503;
172
- readonly 'Gateway Timeout': 504;
173
- readonly 'HTTP Version Not Supported': 505;
174
- readonly 'Variant Also Negotiates': 506;
175
- readonly 'Insufficient Storage': 507;
176
- readonly 'Loop Detected': 508;
177
- readonly 'Not Extended': 510;
178
- readonly 'Network Authentication Required': 511;
179
- }[Code] : Code>;
138
+ declare const status: <const Code extends number | keyof StatusMap, const T = StatusResponse<Code>>(code: Code, response?: T) => ElysiaStatus<Code, T, NumericStatus<Code>>;
180
139
  declare const PROBLEM_JSON = "application/problem+json";
181
140
  /**
182
141
  * RFC 9457 Problem Details shape.
@@ -184,16 +143,36 @@ declare const PROBLEM_JSON = "application/problem+json";
184
143
  * @see https://www.rfc-editor.org/info/rfc9457/
185
144
  */
186
145
  type Problem<Code extends number | keyof StatusMap = number | keyof StatusMap, Extension extends Record<string, unknown> = {}> = {
187
- /** URI (or slug) identifying the problem type. @default 'about:blank' */type?: string; /** Short, human-readable summary of the problem type */
146
+ /** URI (or slug) identifying the problem type. @default 'about:blank' */type?: string;
147
+ /**
148
+ * Extension member carrying a stable machine-readable token.
149
+ *
150
+ * `type` may be widened to a URI by {@link HTTPError.typeBase}, `code`
151
+ * never is
152
+ */
153
+ code?: string; /** Short, human-readable summary of the problem type */
188
154
  title?: string; /** HTTP status. A number or a `StatusMap` name (e.g. `'Conflict'`) */
189
155
  status?: Code; /** Human-readable explanation specific to this occurrence */
190
156
  detail?: string; /** URI identifying the specific occurrence of the problem */
191
157
  instance?: string;
192
158
  } & Extension;
159
+ /** Numeric form of a status name or code. */
193
160
  type NumericStatus<Code extends number | keyof StatusMap> = Code extends keyof StatusMap ? StatusMap[Code] : Code;
194
161
  type ProblemStatus<P> = P extends {
195
162
  status: infer S extends number | keyof StatusMap;
196
163
  } ? NumericStatus<S> : 500;
164
+ /** Request validation problem. Diagnostic fields are development-only. */
165
+ type ValidationErrorResponse = {
166
+ type: 'validation';
167
+ code: 'validation';
168
+ title: 'Validation Error';
169
+ status: 422;
170
+ detail?: string;
171
+ on: string;
172
+ found?: unknown;
173
+ property?: string;
174
+ expected?: string;
175
+ };
197
176
  type ProblemResponseBody<Status extends number, P> = Omit<{
198
177
  type: string;
199
178
  title: string;
@@ -235,12 +214,16 @@ declare function problem<const Code extends number | keyof StatusMap, const P ex
235
214
  declare function problem<const P extends Problem>(detail: P): ElysiaStatus<ProblemStatus<P>, ProblemResponseBody<ProblemStatus<P>, P>>;
236
215
  type CheckExcessProps<T, U> = 0 extends 1 & T ? T : U extends U ? Exclude<keyof T, keyof U> extends never ? T : { [K in keyof U]: U[K] } & { [K in Exclude<keyof T, keyof U>]: never } : never;
237
216
  type SelectiveStatus<in out Res> = <const Code extends keyof Res | StatusMapBack[Extract<keyof StatusMapBack, keyof Res>], T extends (Code extends keyof Res ? Res[Code] : Code extends keyof StatusMap ? Res[StatusMap[Code]] : never)>(code: Code, response: CheckExcessProps<T, Code extends keyof Res ? Res[Code] : Code extends keyof StatusMap ? Res[StatusMap[Code]] : never>) => ElysiaStatus<Code, T>;
217
+ type ProblemInput<T> = T extends object ? Omit<T, 'type' | 'title' | 'status'> & { [K in keyof T as K extends 'type' | 'title' ? K : never]?: T[K] } : never;
218
+ type ResponseOf<Res, Code> = Code extends keyof Res ? Res[Code] : Code extends keyof StatusMap ? Res[StatusMap[Code]] : never;
219
+ type SelectiveProblem<in out Res> = <const Code extends keyof Res | StatusMapBack[Extract<keyof StatusMapBack, keyof Res>], T extends ProblemInput<ResponseOf<Res, Code>> = ProblemInput<ResponseOf<Res, Code>>>(code: Code, ...detail: {} extends ProblemInput<ResponseOf<Res, Code>> ? [detail?: CheckExcessProps<T, ProblemInput<ResponseOf<Res, Code>>>] : [detail: CheckExcessProps<T, ProblemInput<ResponseOf<Res, Code>>>]) => ElysiaStatus<NumericStatus<Code>, ResponseOf<Res, Code>>;
238
220
  /**
239
221
  * Class returned by {@link HTTPError.id}
240
222
  */
241
223
  type TaggedHTTPError<Type extends string, Annotation = {}> = {
242
224
  new (message?: string, options?: ErrorOptions): HTTPError<Type> & {
243
225
  type: Type;
226
+ readonly code: Type;
244
227
  } & Annotation;
245
228
  prototype: HTTPError<Type>;
246
229
  };
@@ -305,8 +288,34 @@ declare abstract class HTTPError<const in out T extends string = string> extends
305
288
  /**
306
289
  * RFC 9457 problem type served in the `type` member, a URI or a slug.
307
290
  * Doubles as the tag that discriminates one error class from another
291
+ *
292
+ * On a {@link HTTPError.id} class this mirrors `code`, or resolves to
293
+ * `<typeBase>/<code>` once {@link HTTPError.typeBase} is set
308
294
  */
309
295
  abstract type: T;
296
+ /**
297
+ * Stable machine-readable token served in the `code` member, set by
298
+ * {@link HTTPError.id} to its first argument
299
+ *
300
+ * Unlike `type` it is never widened to a URI, so it stays the value to
301
+ * dispatch on
302
+ */
303
+ readonly code?: string;
304
+ /**
305
+ * Absolute base for the RFC 9457 `type` URI, applied to every class made
306
+ * by {@link HTTPError.id} and to every built-in `ElysiaError`
307
+ * (`NotFound`, `ParseError`, …) both derive `type` from the same slug
308
+ *
309
+ * @example
310
+ * ```ts
311
+ * HTTPError.typeBase = 'https://example.com/errors'
312
+ *
313
+ * class OutOfCredit extends HTTPError.id('OUT_OF_CREDIT', 402) {}
314
+ * // → { type: 'https://example.com/errors/OUT_OF_CREDIT',
315
+ * // code: 'OUT_OF_CREDIT', … }
316
+ * ```
317
+ */
318
+ static typeBase?: string;
310
319
  /**
311
320
  * HTTP status served when the error reaches the error pipeline,
312
321
  * as a number or a status name (`'Payment Required'`)
@@ -328,9 +337,10 @@ declare abstract class HTTPError<const in out T extends string = string> extends
328
337
  */
329
338
  detail?(): MaybePromise<unknown>;
330
339
  /**
331
- * Create a concrete `HTTPError` subclass carrying `type`
340
+ * Create a concrete `HTTPError` subclass carrying `code`, mirrored into
341
+ * `type` unless {@link HTTPError.typeBase} is set
332
342
  *
333
- * `type` carries no status annotation, annotate `status` in the subclass
343
+ * `code` carries no status annotation, annotate `status` in the subclass
334
344
  * body as a number or a status name
335
345
  *
336
346
  * @example
@@ -342,9 +352,9 @@ declare abstract class HTTPError<const in out T extends string = string> extends
342
352
  * }
343
353
  * ```
344
354
  */
345
- static id<const Type extends string>(type: Type): TaggedHTTPError<Type>;
355
+ static id<const Type extends string>(code: Type): TaggedHTTPError<Type>;
346
356
  /**
347
- * Create a concrete `HTTPError` subclass carrying `type`, annotated with
357
+ * Create a concrete `HTTPError` subclass carrying `code`, annotated with
348
358
  * `status` as a number or a status name
349
359
  *
350
360
  * Annotate what is served with `detail()` (problem `detail` member) or
@@ -353,16 +363,16 @@ declare abstract class HTTPError<const in out T extends string = string> extends
353
363
  * @example
354
364
  * ```ts
355
365
  * class OutOfCredit extends HTTPError.id('OUT_OF_CREDIT', 402) {}
356
- * class Denied extends HTTPError.id('https://example.com/denied', 'Payment Required') {
366
+ * class Denied extends HTTPError.id('DENIED', 'Payment Required') {
357
367
  * async detail() {
358
368
  * return await describeBalance()
359
369
  * }
360
370
  * }
361
371
  * ```
362
372
  */
363
- static id<const Type extends string, const S extends number | keyof StatusMap>(type: Type, status: S): TaggedHTTPError<Type, {
373
+ static id<const Type extends string, const S extends number | keyof StatusMap>(code: Type, status: S): TaggedHTTPError<Type, {
364
374
  readonly status: S extends keyof StatusMap ? StatusMap[S] : S;
365
375
  }>;
366
376
  }
367
377
  //#endregion
368
- export { ElysiaError, ElysiaStatus, HTTPError, InternalServerError, NotFound, PROBLEM_JSON, ParseError, Problem, ProblemResponseBody, SelectiveStatus, TaggedHTTPError, ValidationError, internalServerErrorBody, internalServerErrorBodyString, internalServerErrorResponse, isProduction, problem, problemBody, problemResponse, status, subValueAt, validationDetail };
378
+ export { ElysiaError, ElysiaStatus, HTTPError, InternalServerError, MAX_ERRORS, NotFound, NumericStatus, PROBLEM_JSON, ParseError, Problem, ProblemResponseBody, SelectiveProblem, SelectiveStatus, StatusResponse, TaggedHTTPError, ValidationError, ValidationErrorResponse, elysiaErrorProblem, internalServerErrorBody, internalServerErrorBodyString, internalServerErrorResponse, isProduction, problem, problemBody, problemResponse, problemTypeOf, status, subValueAt, validationDetail };