hono 4.13.13 → 5.0.0-rc.0

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 (444) hide show
  1. package/README.md +2 -2
  2. package/dist/{types/compose.d.ts → compose.d.ts} +1 -0
  3. package/dist/compose.js +10 -5
  4. package/dist/{types/context.d.ts → context.d.ts} +15 -15
  5. package/dist/context.js +79 -47
  6. package/dist/helper/factory/define-handler.d.ts +150 -0
  7. package/dist/helper/factory/define-handler.js +165 -0
  8. package/dist/{types/helper → helper}/factory/index.d.ts +30 -1
  9. package/dist/helper/factory/index.js +31 -3
  10. package/dist/{types/helper → helper}/ssg/middleware.d.ts +0 -6
  11. package/dist/helper/ssg/middleware.js +1 -16
  12. package/dist/{types/helper → helper}/ssg/ssg.d.ts +0 -12
  13. package/dist/helper/ssg/ssg.js +0 -3
  14. package/dist/{types/hono-base.d.ts → hono-base.d.ts} +3 -60
  15. package/dist/hono-base.js +6 -97
  16. package/dist/{types/hono.d.ts → hono.d.ts} +1 -1
  17. package/dist/{types/middleware → middleware}/basic-auth/index.d.ts +4 -3
  18. package/dist/middleware/basic-auth/index.js +1 -1
  19. package/dist/{types/middleware → middleware}/bearer-auth/index.d.ts +4 -27
  20. package/dist/middleware/bearer-auth/index.js +4 -4
  21. package/dist/middleware/language/language.js +1 -1
  22. package/dist/middleware/logger/index.js +6 -8
  23. package/dist/{types/middleware → middleware}/serve-static/index.d.ts +0 -4
  24. package/dist/{types/preset → preset}/quick.d.ts +1 -1
  25. package/dist/{types/preset → preset}/tiny.d.ts +1 -1
  26. package/dist/{types/request.d.ts → request.d.ts} +3 -48
  27. package/dist/request.js +0 -49
  28. package/dist/router/linear-router/router.js +4 -6
  29. package/dist/router/pattern-router/router.js +2 -2
  30. package/dist/router/reg-exp-router/node.js +1 -1
  31. package/dist/router/trie-router/node.js +3 -3
  32. package/dist/utils/buffer.d.ts +11 -0
  33. package/dist/utils/buffer.js +1 -8
  34. package/dist/utils/color.d.ts +16 -0
  35. package/dist/utils/color.js +7 -23
  36. package/dist/{types/utils → utils}/http-status.d.ts +1 -9
  37. package/dist/{types/utils → utils}/url.d.ts +0 -5
  38. package/dist/utils/url.js +1 -11
  39. package/dist/{types/validator → validator}/validator.d.ts +5 -0
  40. package/dist/validator/validator.js +46 -49
  41. package/package.json +209 -350
  42. package/dist/adapter/aws-lambda/conninfo.js +0 -43
  43. package/dist/adapter/aws-lambda/handler.js +0 -342
  44. package/dist/adapter/aws-lambda/index.js +0 -3
  45. package/dist/adapter/aws-lambda/types.js +0 -1
  46. package/dist/adapter/bun/conninfo.js +0 -22
  47. package/dist/adapter/bun/index.js +0 -6
  48. package/dist/adapter/bun/serve-static.js +0 -30
  49. package/dist/adapter/bun/server.js +0 -11
  50. package/dist/adapter/bun/ssg.js +0 -27
  51. package/dist/adapter/bun/websocket.js +0 -66
  52. package/dist/adapter/cloudflare-pages/conninfo.js +0 -24
  53. package/dist/adapter/cloudflare-pages/handler.js +0 -64
  54. package/dist/adapter/cloudflare-pages/index.js +0 -3
  55. package/dist/adapter/cloudflare-workers/conninfo.js +0 -7
  56. package/dist/adapter/cloudflare-workers/index.js +0 -4
  57. package/dist/adapter/cloudflare-workers/serve-static-module.js +0 -7
  58. package/dist/adapter/cloudflare-workers/serve-static.js +0 -28
  59. package/dist/adapter/cloudflare-workers/utils.js +0 -22
  60. package/dist/adapter/cloudflare-workers/websocket.js +0 -33
  61. package/dist/adapter/deno/conninfo.js +0 -17
  62. package/dist/adapter/deno/deno.d.js +0 -1
  63. package/dist/adapter/deno/index.js +0 -5
  64. package/dist/adapter/deno/serve-static.js +0 -35
  65. package/dist/adapter/deno/ssg.js +0 -29
  66. package/dist/adapter/deno/websocket.js +0 -32
  67. package/dist/adapter/lambda-edge/conninfo.js +0 -7
  68. package/dist/adapter/lambda-edge/handler.js +0 -111
  69. package/dist/adapter/lambda-edge/index.js +0 -3
  70. package/dist/adapter/netlify/conninfo.js +0 -24
  71. package/dist/adapter/netlify/handler.js +0 -11
  72. package/dist/adapter/netlify/index.js +0 -3
  73. package/dist/adapter/netlify/mod.js +0 -3
  74. package/dist/adapter/service-worker/handler.js +0 -16
  75. package/dist/adapter/service-worker/index.js +0 -25
  76. package/dist/adapter/service-worker/types.js +0 -1
  77. package/dist/adapter/vercel/conninfo.js +0 -7
  78. package/dist/adapter/vercel/handler.js +0 -9
  79. package/dist/adapter/vercel/index.js +0 -3
  80. package/dist/cjs/_virtual/_rolldown/runtime.js +0 -33
  81. package/dist/cjs/adapter/aws-lambda/conninfo.js +0 -44
  82. package/dist/cjs/adapter/aws-lambda/handler.js +0 -352
  83. package/dist/cjs/adapter/aws-lambda/index.js +0 -7
  84. package/dist/cjs/adapter/aws-lambda/types.js +0 -0
  85. package/dist/cjs/adapter/bun/conninfo.js +0 -23
  86. package/dist/cjs/adapter/bun/index.js +0 -14
  87. package/dist/cjs/adapter/bun/serve-static.js +0 -31
  88. package/dist/cjs/adapter/bun/server.js +0 -12
  89. package/dist/cjs/adapter/bun/ssg.js +0 -29
  90. package/dist/cjs/adapter/bun/websocket.js +0 -70
  91. package/dist/cjs/adapter/cloudflare-pages/conninfo.js +0 -25
  92. package/dist/cjs/adapter/cloudflare-pages/handler.js +0 -67
  93. package/dist/cjs/adapter/cloudflare-pages/index.js +0 -7
  94. package/dist/cjs/adapter/cloudflare-workers/conninfo.js +0 -8
  95. package/dist/cjs/adapter/cloudflare-workers/index.js +0 -7
  96. package/dist/cjs/adapter/cloudflare-workers/serve-static-module.js +0 -8
  97. package/dist/cjs/adapter/cloudflare-workers/serve-static.js +0 -29
  98. package/dist/cjs/adapter/cloudflare-workers/utils.js +0 -23
  99. package/dist/cjs/adapter/cloudflare-workers/websocket.js +0 -34
  100. package/dist/cjs/adapter/deno/conninfo.js +0 -18
  101. package/dist/cjs/adapter/deno/deno.d.js +0 -0
  102. package/dist/cjs/adapter/deno/index.js +0 -10
  103. package/dist/cjs/adapter/deno/serve-static.js +0 -36
  104. package/dist/cjs/adapter/deno/ssg.js +0 -31
  105. package/dist/cjs/adapter/deno/websocket.js +0 -33
  106. package/dist/cjs/adapter/lambda-edge/conninfo.js +0 -8
  107. package/dist/cjs/adapter/lambda-edge/handler.js +0 -116
  108. package/dist/cjs/adapter/lambda-edge/index.js +0 -5
  109. package/dist/cjs/adapter/netlify/conninfo.js +0 -25
  110. package/dist/cjs/adapter/netlify/handler.js +0 -12
  111. package/dist/cjs/adapter/netlify/index.js +0 -5
  112. package/dist/cjs/adapter/netlify/mod.js +0 -5
  113. package/dist/cjs/adapter/service-worker/handler.js +0 -17
  114. package/dist/cjs/adapter/service-worker/index.js +0 -27
  115. package/dist/cjs/adapter/service-worker/types.js +0 -0
  116. package/dist/cjs/adapter/vercel/conninfo.js +0 -8
  117. package/dist/cjs/adapter/vercel/handler.js +0 -10
  118. package/dist/cjs/adapter/vercel/index.js +0 -5
  119. package/dist/cjs/client/client.js +0 -145
  120. package/dist/cjs/client/fetch-result-please.js +0 -67
  121. package/dist/cjs/client/index.js +0 -7
  122. package/dist/cjs/client/types.js +0 -0
  123. package/dist/cjs/client/utils.js +0 -70
  124. package/dist/cjs/compose.js +0 -51
  125. package/dist/cjs/context.js +0 -383
  126. package/dist/cjs/helper/accepts/accepts.js +0 -54
  127. package/dist/cjs/helper/accepts/index.js +0 -3
  128. package/dist/cjs/helper/adapter/index.js +0 -41
  129. package/dist/cjs/helper/conninfo/index.js +0 -0
  130. package/dist/cjs/helper/conninfo/types.js +0 -0
  131. package/dist/cjs/helper/cookie/index.js +0 -89
  132. package/dist/cjs/helper/css/common.js +0 -194
  133. package/dist/cjs/helper/css/index.js +0 -142
  134. package/dist/cjs/helper/dev/index.js +0 -53
  135. package/dist/cjs/helper/factory/index.js +0 -33
  136. package/dist/cjs/helper/html/index.js +0 -34
  137. package/dist/cjs/helper/proxy/index.js +0 -122
  138. package/dist/cjs/helper/route/index.js +0 -128
  139. package/dist/cjs/helper/ssg/index.js +0 -19
  140. package/dist/cjs/helper/ssg/middleware.js +0 -65
  141. package/dist/cjs/helper/ssg/plugins.js +0 -68
  142. package/dist/cjs/helper/ssg/ssg.js +0 -220
  143. package/dist/cjs/helper/ssg/utils.js +0 -70
  144. package/dist/cjs/helper/streaming/index.js +0 -8
  145. package/dist/cjs/helper/streaming/sse.js +0 -59
  146. package/dist/cjs/helper/streaming/stream.js +0 -26
  147. package/dist/cjs/helper/streaming/text.js +0 -12
  148. package/dist/cjs/helper/streaming/utils.js +0 -16
  149. package/dist/cjs/helper/testing/index.js +0 -18
  150. package/dist/cjs/helper/websocket/index.js +0 -56
  151. package/dist/cjs/hono-base.js +0 -351
  152. package/dist/cjs/hono.js +0 -29
  153. package/dist/cjs/http-exception.js +0 -56
  154. package/dist/cjs/index.js +0 -22
  155. package/dist/cjs/jsx/base.js +0 -266
  156. package/dist/cjs/jsx/children.js +0 -19
  157. package/dist/cjs/jsx/components.js +0 -147
  158. package/dist/cjs/jsx/constants.js +0 -15
  159. package/dist/cjs/jsx/context.js +0 -170
  160. package/dist/cjs/jsx/dom/client.js +0 -56
  161. package/dist/cjs/jsx/dom/components.js +0 -26
  162. package/dist/cjs/jsx/dom/context.js +0 -43
  163. package/dist/cjs/jsx/dom/css.js +0 -153
  164. package/dist/cjs/jsx/dom/hooks/index.js +0 -65
  165. package/dist/cjs/jsx/dom/index.js +0 -122
  166. package/dist/cjs/jsx/dom/intrinsic-element/components.js +0 -306
  167. package/dist/cjs/jsx/dom/jsx-dev-runtime.js +0 -17
  168. package/dist/cjs/jsx/dom/jsx-runtime.js +0 -5
  169. package/dist/cjs/jsx/dom/render.js +0 -525
  170. package/dist/cjs/jsx/dom/server.js +0 -44
  171. package/dist/cjs/jsx/dom/utils.js +0 -9
  172. package/dist/cjs/jsx/hooks/index.js +0 -280
  173. package/dist/cjs/jsx/index.js +0 -89
  174. package/dist/cjs/jsx/intrinsic-element/common.js +0 -27
  175. package/dist/cjs/jsx/intrinsic-element/components.js +0 -138
  176. package/dist/cjs/jsx/intrinsic-elements.js +0 -0
  177. package/dist/cjs/jsx/jsx-dev-runtime.js +0 -16
  178. package/dist/cjs/jsx/jsx-runtime.js +0 -37
  179. package/dist/cjs/jsx/streaming.js +0 -135
  180. package/dist/cjs/jsx/types.js +0 -0
  181. package/dist/cjs/jsx/utils.js +0 -116
  182. package/dist/cjs/middleware/basic-auth/index.js +0 -100
  183. package/dist/cjs/middleware/bearer-auth/index.js +0 -97
  184. package/dist/cjs/middleware/body-limit/index.js +0 -69
  185. package/dist/cjs/middleware/cache/index.js +0 -173
  186. package/dist/cjs/middleware/combine/index.js +0 -141
  187. package/dist/cjs/middleware/compress/index.js +0 -82
  188. package/dist/cjs/middleware/context-storage/index.js +0 -55
  189. package/dist/cjs/middleware/cors/index.js +0 -109
  190. package/dist/cjs/middleware/csrf/index.js +0 -106
  191. package/dist/cjs/middleware/etag/digest.js +0 -62
  192. package/dist/cjs/middleware/etag/index.js +0 -79
  193. package/dist/cjs/middleware/ip-restriction/index.js +0 -168
  194. package/dist/cjs/middleware/jsx-renderer/index.js +0 -104
  195. package/dist/cjs/middleware/jwk/index.js +0 -3
  196. package/dist/cjs/middleware/jwk/jwk.js +0 -122
  197. package/dist/cjs/middleware/jwt/index.js +0 -9
  198. package/dist/cjs/middleware/jwt/jwt.js +0 -124
  199. package/dist/cjs/middleware/language/index.js +0 -7
  200. package/dist/cjs/middleware/language/language.js +0 -208
  201. package/dist/cjs/middleware/logger/index.js +0 -51
  202. package/dist/cjs/middleware/method-not-allowed/index.js +0 -84
  203. package/dist/cjs/middleware/method-override/index.js +0 -105
  204. package/dist/cjs/middleware/mount/index.js +0 -71
  205. package/dist/cjs/middleware/powered-by/index.js +0 -25
  206. package/dist/cjs/middleware/pretty-json/index.js +0 -41
  207. package/dist/cjs/middleware/request-id/index.js +0 -3
  208. package/dist/cjs/middleware/request-id/request-id.js +0 -35
  209. package/dist/cjs/middleware/secure-headers/index.js +0 -4
  210. package/dist/cjs/middleware/secure-headers/permissions-policy.js +0 -0
  211. package/dist/cjs/middleware/secure-headers/secure-headers.js +0 -166
  212. package/dist/cjs/middleware/serve-static/index.js +0 -62
  213. package/dist/cjs/middleware/serve-static/path.js +0 -17
  214. package/dist/cjs/middleware/timeout/index.js +0 -42
  215. package/dist/cjs/middleware/timing/index.js +0 -7
  216. package/dist/cjs/middleware/timing/timing.js +0 -189
  217. package/dist/cjs/middleware/trailing-slash/index.js +0 -89
  218. package/dist/cjs/package.json +0 -3
  219. package/dist/cjs/preset/quick.js +0 -19
  220. package/dist/cjs/preset/tiny.js +0 -16
  221. package/dist/cjs/request/constants.js +0 -5
  222. package/dist/cjs/request.js +0 -337
  223. package/dist/cjs/router/linear-router/index.js +0 -3
  224. package/dist/cjs/router/linear-router/router.js +0 -97
  225. package/dist/cjs/router/pattern-router/index.js +0 -3
  226. package/dist/cjs/router/pattern-router/router.js +0 -42
  227. package/dist/cjs/router/reg-exp-router/index.js +0 -7
  228. package/dist/cjs/router/reg-exp-router/matcher.js +0 -21
  229. package/dist/cjs/router/reg-exp-router/node.js +0 -96
  230. package/dist/cjs/router/reg-exp-router/prepared-router.js +0 -97
  231. package/dist/cjs/router/reg-exp-router/router.js +0 -102
  232. package/dist/cjs/router/reg-exp-router/trie.js +0 -74
  233. package/dist/cjs/router/smart-router/index.js +0 -3
  234. package/dist/cjs/router/smart-router/router.js +0 -50
  235. package/dist/cjs/router/trie-router/index.js +0 -3
  236. package/dist/cjs/router/trie-router/node.js +0 -135
  237. package/dist/cjs/router/trie-router/router.js +0 -16
  238. package/dist/cjs/router/utils.js +0 -5
  239. package/dist/cjs/router.js +0 -40
  240. package/dist/cjs/types.js +0 -5
  241. package/dist/cjs/utils/accept.js +0 -194
  242. package/dist/cjs/utils/basic-auth.js +0 -21
  243. package/dist/cjs/utils/body.js +0 -97
  244. package/dist/cjs/utils/buffer.js +0 -55
  245. package/dist/cjs/utils/color.js +0 -39
  246. package/dist/cjs/utils/compress.js +0 -12
  247. package/dist/cjs/utils/concurrent.js +0 -31
  248. package/dist/cjs/utils/constants.js +0 -8
  249. package/dist/cjs/utils/cookie.js +0 -129
  250. package/dist/cjs/utils/crypto.js +0 -38
  251. package/dist/cjs/utils/encode.js +0 -37
  252. package/dist/cjs/utils/filepath.js +0 -27
  253. package/dist/cjs/utils/handler.js +0 -14
  254. package/dist/cjs/utils/headers.js +0 -0
  255. package/dist/cjs/utils/html.js +0 -109
  256. package/dist/cjs/utils/http-status.js +0 -0
  257. package/dist/cjs/utils/ipaddr.js +0 -247
  258. package/dist/cjs/utils/jwt/index.js +0 -15
  259. package/dist/cjs/utils/jwt/jwa.js +0 -25
  260. package/dist/cjs/utils/jwt/jws.js +0 -135
  261. package/dist/cjs/utils/jwt/jwt.js +0 -136
  262. package/dist/cjs/utils/jwt/types.js +0 -124
  263. package/dist/cjs/utils/jwt/utf8.js +0 -11
  264. package/dist/cjs/utils/mime.js +0 -80
  265. package/dist/cjs/utils/stream.js +0 -89
  266. package/dist/cjs/utils/types.js +0 -0
  267. package/dist/cjs/utils/url.js +0 -215
  268. package/dist/cjs/validator/index.js +0 -3
  269. package/dist/cjs/validator/utils.js +0 -0
  270. package/dist/cjs/validator/validator.js +0 -65
  271. package/dist/types/adapter/aws-lambda/conninfo.d.ts +0 -30
  272. package/dist/types/adapter/aws-lambda/handler.d.ts +0 -230
  273. package/dist/types/adapter/aws-lambda/index.d.ts +0 -4
  274. package/dist/types/adapter/aws-lambda/types.d.ts +0 -183
  275. package/dist/types/adapter/bun/conninfo.d.ts +0 -10
  276. package/dist/types/adapter/bun/index.d.ts +0 -6
  277. package/dist/types/adapter/bun/serve-static.d.ts +0 -8
  278. package/dist/types/adapter/bun/server.d.ts +0 -11
  279. package/dist/types/adapter/bun/ssg.d.ts +0 -17
  280. package/dist/types/adapter/bun/websocket.d.ts +0 -54
  281. package/dist/types/adapter/cloudflare-pages/conninfo.d.ts +0 -24
  282. package/dist/types/adapter/cloudflare-pages/handler.d.ts +0 -45
  283. package/dist/types/adapter/cloudflare-pages/index.d.ts +0 -3
  284. package/dist/types/adapter/cloudflare-workers/conninfo.d.ts +0 -7
  285. package/dist/types/adapter/cloudflare-workers/index.d.ts +0 -4
  286. package/dist/types/adapter/cloudflare-workers/serve-static-module.d.ts +0 -7
  287. package/dist/types/adapter/cloudflare-workers/serve-static.d.ts +0 -21
  288. package/dist/types/adapter/cloudflare-workers/utils.d.ts +0 -13
  289. package/dist/types/adapter/cloudflare-workers/websocket.d.ts +0 -7
  290. package/dist/types/adapter/deno/conninfo.d.ts +0 -10
  291. package/dist/types/adapter/deno/deno.d.ts +0 -1
  292. package/dist/types/adapter/deno/index.d.ts +0 -5
  293. package/dist/types/adapter/deno/serve-static.d.ts +0 -8
  294. package/dist/types/adapter/deno/ssg.d.ts +0 -17
  295. package/dist/types/adapter/deno/websocket.d.ts +0 -7
  296. package/dist/types/adapter/lambda-edge/conninfo.d.ts +0 -7
  297. package/dist/types/adapter/lambda-edge/handler.d.ts +0 -113
  298. package/dist/types/adapter/lambda-edge/index.d.ts +0 -3
  299. package/dist/types/adapter/netlify/conninfo.d.ts +0 -24
  300. package/dist/types/adapter/netlify/handler.d.ts +0 -7
  301. package/dist/types/adapter/netlify/index.d.ts +0 -3
  302. package/dist/types/adapter/netlify/mod.d.ts +0 -3
  303. package/dist/types/adapter/service-worker/handler.d.ts +0 -18
  304. package/dist/types/adapter/service-worker/index.d.ts +0 -26
  305. package/dist/types/adapter/service-worker/types.d.ts +0 -17
  306. package/dist/types/adapter/vercel/conninfo.d.ts +0 -7
  307. package/dist/types/adapter/vercel/handler.d.ts +0 -7
  308. package/dist/types/adapter/vercel/index.d.ts +0 -3
  309. package/dist/types/package.json +0 -3
  310. package/dist/types/utils/buffer.d.ts +0 -19
  311. package/dist/types/utils/color.d.ts +0 -23
  312. package/dist/{types/client → client}/client.d.ts +0 -0
  313. package/dist/{types/client → client}/fetch-result-please.d.ts +0 -0
  314. package/dist/{types/client → client}/index.d.ts +0 -0
  315. package/dist/{types/client → client}/types.d.ts +1 -1
  316. package/dist/{types/client → client}/utils.d.ts +0 -0
  317. package/dist/{types/helper → helper}/accepts/accepts.d.ts +0 -0
  318. package/dist/{types/helper → helper}/accepts/index.d.ts +0 -0
  319. package/dist/{types/helper → helper}/adapter/index.d.ts +0 -0
  320. package/dist/{types/helper → helper}/conninfo/index.d.ts +0 -0
  321. package/dist/{types/helper → helper}/conninfo/types.d.ts +0 -0
  322. package/dist/{types/helper → helper}/cookie/index.d.ts +0 -0
  323. package/dist/{types/helper → helper}/css/common.d.ts +0 -0
  324. package/dist/{types/helper → helper}/css/index.d.ts +0 -0
  325. package/dist/{types/helper → helper}/dev/index.d.ts +0 -0
  326. package/dist/{types/helper → helper}/html/index.d.ts +0 -0
  327. package/dist/{types/helper → helper}/proxy/index.d.ts +0 -0
  328. package/dist/{types/helper → helper}/route/index.d.ts +0 -0
  329. package/dist/{types/helper → helper}/ssg/index.d.ts +0 -0
  330. package/dist/{types/helper → helper}/ssg/plugins.d.ts +0 -0
  331. package/dist/{types/helper → helper}/ssg/utils.d.ts +0 -0
  332. package/dist/{types/helper → helper}/streaming/index.d.ts +0 -0
  333. package/dist/{types/helper → helper}/streaming/sse.d.ts +0 -0
  334. package/dist/{types/helper → helper}/streaming/stream.d.ts +0 -0
  335. package/dist/{types/helper → helper}/streaming/text.d.ts +0 -0
  336. package/dist/{types/helper → helper}/streaming/utils.d.ts +0 -0
  337. package/dist/{types/helper → helper}/testing/index.d.ts +0 -0
  338. package/dist/{types/helper → helper}/websocket/index.d.ts +0 -0
  339. package/dist/{types/http-exception.d.ts → http-exception.d.ts} +0 -0
  340. package/dist/{types/index.d.ts → index.d.ts} +0 -0
  341. package/dist/{types/jsx → jsx}/base.d.ts +0 -0
  342. package/dist/{types/jsx → jsx}/children.d.ts +0 -0
  343. package/dist/{types/jsx → jsx}/components.d.ts +0 -0
  344. package/dist/{types/jsx → jsx}/constants.d.ts +0 -0
  345. package/dist/{types/jsx → jsx}/context.d.ts +0 -0
  346. package/dist/{types/jsx → jsx}/dom/client.d.ts +0 -0
  347. package/dist/{types/jsx → jsx}/dom/components.d.ts +0 -0
  348. package/dist/{types/jsx → jsx}/dom/context.d.ts +0 -0
  349. package/dist/{types/jsx → jsx}/dom/css.d.ts +0 -0
  350. package/dist/{types/jsx → jsx}/dom/hooks/index.d.ts +0 -0
  351. package/dist/{types/jsx → jsx}/dom/index.d.ts +0 -0
  352. package/dist/{types/jsx → jsx}/dom/intrinsic-element/components.d.ts +0 -0
  353. package/dist/{types/jsx → jsx}/dom/jsx-dev-runtime.d.ts +0 -0
  354. package/dist/{types/jsx → jsx}/dom/jsx-runtime.d.ts +0 -0
  355. package/dist/{types/jsx → jsx}/dom/render.d.ts +0 -0
  356. package/dist/{types/jsx → jsx}/dom/server.d.ts +0 -0
  357. package/dist/{types/jsx → jsx}/dom/utils.d.ts +0 -0
  358. package/dist/{types/jsx → jsx}/hooks/index.d.ts +0 -0
  359. package/dist/{types/jsx → jsx}/index.d.ts +0 -0
  360. package/dist/{types/jsx → jsx}/intrinsic-element/common.d.ts +0 -0
  361. package/dist/{types/jsx → jsx}/intrinsic-element/components.d.ts +0 -0
  362. package/dist/{types/jsx → jsx}/intrinsic-elements.d.ts +0 -0
  363. package/dist/{types/jsx → jsx}/jsx-dev-runtime.d.ts +0 -0
  364. package/dist/{types/jsx → jsx}/jsx-runtime.d.ts +0 -0
  365. package/dist/{types/jsx → jsx}/streaming.d.ts +0 -0
  366. package/dist/{types/jsx → jsx}/types.d.ts +0 -0
  367. package/dist/{types/jsx → jsx}/utils.d.ts +0 -0
  368. package/dist/{types/middleware → middleware}/body-limit/index.d.ts +0 -0
  369. package/dist/{types/middleware → middleware}/cache/index.d.ts +0 -0
  370. package/dist/{types/middleware → middleware}/combine/index.d.ts +0 -0
  371. package/dist/{types/middleware → middleware}/compress/index.d.ts +0 -0
  372. package/dist/{types/middleware → middleware}/context-storage/index.d.ts +0 -0
  373. package/dist/{types/middleware → middleware}/cors/index.d.ts +0 -0
  374. package/dist/{types/middleware → middleware}/csrf/index.d.ts +0 -0
  375. package/dist/{types/middleware → middleware}/etag/digest.d.ts +0 -0
  376. package/dist/{types/middleware → middleware}/etag/index.d.ts +0 -0
  377. package/dist/{types/middleware → middleware}/ip-restriction/index.d.ts +0 -0
  378. package/dist/{types/middleware → middleware}/jsx-renderer/index.d.ts +0 -0
  379. package/dist/{types/middleware → middleware}/jwk/index.d.ts +0 -0
  380. package/dist/{types/middleware → middleware}/jwk/jwk.d.ts +0 -0
  381. package/dist/{types/middleware → middleware}/jwt/index.d.ts +0 -0
  382. package/dist/{types/middleware → middleware}/jwt/jwt.d.ts +0 -0
  383. package/dist/{types/middleware → middleware}/language/index.d.ts +0 -0
  384. package/dist/{types/middleware → middleware}/language/language.d.ts +0 -0
  385. package/dist/{types/middleware → middleware}/logger/index.d.ts +0 -0
  386. package/dist/{types/middleware → middleware}/method-not-allowed/index.d.ts +0 -0
  387. package/dist/{types/middleware → middleware}/method-override/index.d.ts +0 -0
  388. package/dist/{types/middleware → middleware}/mount/index.d.ts +0 -0
  389. package/dist/{types/middleware → middleware}/powered-by/index.d.ts +0 -0
  390. package/dist/{types/middleware → middleware}/pretty-json/index.d.ts +0 -0
  391. package/dist/{types/middleware → middleware}/request-id/index.d.ts +0 -0
  392. package/dist/{types/middleware → middleware}/request-id/request-id.d.ts +0 -0
  393. package/dist/{types/middleware → middleware}/secure-headers/index.d.ts +0 -0
  394. package/dist/{types/middleware → middleware}/secure-headers/permissions-policy.d.ts +0 -0
  395. package/dist/{types/middleware → middleware}/secure-headers/secure-headers.d.ts +0 -0
  396. package/dist/{types/middleware → middleware}/serve-static/path.d.ts +0 -0
  397. package/dist/{types/middleware → middleware}/timeout/index.d.ts +0 -0
  398. package/dist/{types/middleware → middleware}/timing/index.d.ts +0 -0
  399. package/dist/{types/middleware → middleware}/timing/timing.d.ts +0 -0
  400. package/dist/{types/middleware → middleware}/trailing-slash/index.d.ts +0 -0
  401. package/dist/{types/request → request}/constants.d.ts +0 -0
  402. package/dist/{types/router → router}/linear-router/index.d.ts +0 -0
  403. package/dist/{types/router → router}/linear-router/router.d.ts +0 -0
  404. package/dist/{types/router → router}/pattern-router/index.d.ts +0 -0
  405. package/dist/{types/router → router}/pattern-router/router.d.ts +0 -0
  406. package/dist/{types/router → router}/reg-exp-router/index.d.ts +0 -0
  407. package/dist/{types/router → router}/reg-exp-router/matcher.d.ts +0 -0
  408. package/dist/{types/router → router}/reg-exp-router/node.d.ts +0 -0
  409. package/dist/{types/router → router}/reg-exp-router/prepared-router.d.ts +0 -0
  410. package/dist/{types/router → router}/reg-exp-router/router.d.ts +0 -0
  411. package/dist/{types/router → router}/reg-exp-router/trie.d.ts +0 -0
  412. package/dist/{types/router → router}/smart-router/index.d.ts +0 -0
  413. package/dist/{types/router → router}/smart-router/router.d.ts +0 -0
  414. package/dist/{types/router → router}/trie-router/index.d.ts +0 -0
  415. package/dist/{types/router → router}/trie-router/node.d.ts +0 -0
  416. package/dist/{types/router → router}/trie-router/router.d.ts +0 -0
  417. package/dist/{types/router → router}/utils.d.ts +0 -0
  418. package/dist/{types/router.d.ts → router.d.ts} +0 -0
  419. package/dist/{types/types.d.ts → types.d.ts} +1 -1
  420. /package/dist/{types/utils → utils}/accept.d.ts +0 -0
  421. /package/dist/{types/utils → utils}/basic-auth.d.ts +0 -0
  422. /package/dist/{types/utils → utils}/body.d.ts +0 -0
  423. /package/dist/{types/utils → utils}/compress.d.ts +0 -0
  424. /package/dist/{types/utils → utils}/concurrent.d.ts +0 -0
  425. /package/dist/{types/utils → utils}/constants.d.ts +0 -0
  426. /package/dist/{types/utils → utils}/cookie.d.ts +0 -0
  427. /package/dist/{types/utils → utils}/crypto.d.ts +0 -0
  428. /package/dist/{types/utils → utils}/encode.d.ts +0 -0
  429. /package/dist/{types/utils → utils}/filepath.d.ts +0 -0
  430. /package/dist/{types/utils → utils}/handler.d.ts +0 -0
  431. /package/dist/{types/utils → utils}/headers.d.ts +0 -0
  432. /package/dist/{types/utils → utils}/html.d.ts +0 -0
  433. /package/dist/{types/utils → utils}/ipaddr.d.ts +0 -0
  434. /package/dist/{types/utils → utils}/jwt/index.d.ts +0 -0
  435. /package/dist/{types/utils → utils}/jwt/jwa.d.ts +0 -0
  436. /package/dist/{types/utils → utils}/jwt/jws.d.ts +0 -0
  437. /package/dist/{types/utils → utils}/jwt/jwt.d.ts +0 -0
  438. /package/dist/{types/utils → utils}/jwt/types.d.ts +0 -0
  439. /package/dist/{types/utils → utils}/jwt/utf8.d.ts +0 -0
  440. /package/dist/{types/utils → utils}/mime.d.ts +0 -0
  441. /package/dist/{types/utils → utils}/stream.d.ts +0 -0
  442. /package/dist/{types/utils → utils}/types.d.ts +0 -0
  443. /package/dist/{types/validator → validator}/index.d.ts +0 -0
  444. /package/dist/{types/validator → validator}/utils.d.ts +0 -0
@@ -0,0 +1,165 @@
1
+ import { HTTPException } from "../../http-exception.js";
2
+ import { getValidationTarget } from "../../validator/validator.js";
3
+ //#region src/helper/factory/define-handler.ts
4
+ const requestTargets = [
5
+ "param",
6
+ "query",
7
+ "header",
8
+ "cookie",
9
+ "form",
10
+ "json"
11
+ ];
12
+ const isStandardSchema = (v) => (typeof v === "object" || typeof v === "function") && v !== null && "~standard" in v;
13
+ const toValidationIssues = (issues) => issues.map(({ message, path }) => path ? {
14
+ message,
15
+ path: path.map((p) => String(typeof p === "object" ? p.key : p)).join(".")
16
+ } : { message });
17
+ const toValidator = (target, v) => isStandardSchema(v) ? {
18
+ target,
19
+ schema: v["~standard"].validate
20
+ } : {
21
+ target,
22
+ fn: v
23
+ };
24
+ const toResponse = (c, result) => {
25
+ if (result instanceof Response) return result;
26
+ if (result === null || result === void 0) return c.body(null, 204);
27
+ return typeof result === "string" || result.isEscaped ? c.html(result) : c.json(result);
28
+ };
29
+ /**
30
+ * `defineHandler()` defines a handler. A value returned from the handler is converted to a
31
+ * Response: an object is returned as JSON, a string or JSX as HTML, and `null` or `undefined`
32
+ * as `204 No Content`. A `Response` is returned as is. The status is set with `c.status()`, and
33
+ * it is not in the types. Return `c.json()` to have the status in the types.
34
+ *
35
+ * With options, each request target (`param`, `query`, `json`, `form`, `header`, `cookie`)
36
+ * is validated before the handler runs. The validated values are passed to the handler as
37
+ * the second argument, and are also available through `c.req.valid()`.
38
+ * A value returned from the handler is validated with `response` and returned as JSON.
39
+ *
40
+ * Each validation accepts a Standard Schema or a validation function.
41
+ * When a Standard Schema fails, an `HTTPException` is thrown with status 400 for the request
42
+ * and 500 for the response, so `onError` can handle it. Its `res` is a JSON response of
43
+ * `{ error, issues }`, and its `cause` is `{ issues }` with the raw Standard Schema issues.
44
+ *
45
+ * Middleware passed before the handler runs first, around the validation. Its Env flows into
46
+ * the handler, so `c.get()` is typed. Otherwise, use `createFactory<Env>().defineHandler`, or
47
+ * pass the Env and the path as type arguments.
48
+ *
49
+ * @see {@link https://hono.dev/docs/helpers/factory#definehandler}
50
+ *
51
+ * @experimental
52
+ * `defineHandler()` is an experimental feature.
53
+ * The API might be changed.
54
+ *
55
+ * @example
56
+ * ```ts
57
+ * app.get('/ping', defineHandler(() => ({ pong: true })))
58
+ * app.get('/me', defineHandler(auth, (c) => c.get('user')))
59
+ *
60
+ * app.post(
61
+ * '/users/:id',
62
+ * defineHandler({
63
+ * param: ParamSchema,
64
+ * json: BodySchema,
65
+ * response: UserSchema,
66
+ * })(async (c, { param, json }) => {
67
+ * c.status(201)
68
+ * return { id: param.id, ...json }
69
+ * })
70
+ * )
71
+ * ```
72
+ */
73
+ const defineHandler = ((...args) => {
74
+ if (typeof args[0] === "function") return compose(args, async (c) => toResponse(c, await args[args.length - 1](c)));
75
+ const options = args[0];
76
+ const validators = requestTargets.filter((target) => options[target]).map((target) => toValidator(target, options[target]));
77
+ const response = options.response && toValidator("json", options.response);
78
+ return (...args) => {
79
+ const handler = args[args.length - 1];
80
+ const run = async (c) => {
81
+ const input = {};
82
+ const failures = [];
83
+ const issues = [];
84
+ for (const { target, schema, fn } of validators) {
85
+ let value = getValidationTarget(c, target);
86
+ if (value instanceof Promise) value = await value;
87
+ if (schema) {
88
+ let result = schema(value);
89
+ if (result instanceof Promise) result = await result;
90
+ if (result.issues) {
91
+ failures.push({
92
+ slot: target,
93
+ issues: toValidationIssues(result.issues)
94
+ });
95
+ issues.push({
96
+ slot: target,
97
+ issues: result.issues
98
+ });
99
+ continue;
100
+ }
101
+ value = result.value;
102
+ } else {
103
+ value = fn(value, c);
104
+ if (value instanceof Promise) value = await value;
105
+ if (value instanceof Response) return value;
106
+ }
107
+ c.req.addValidatedData(target, value);
108
+ input[target] = value;
109
+ }
110
+ if (failures.length) throw new HTTPException(400, {
111
+ res: c.json({
112
+ error: "Validation failed",
113
+ issues: failures
114
+ }, 400),
115
+ cause: { issues }
116
+ });
117
+ let result = handler(c, input);
118
+ if (result instanceof Promise) result = await result;
119
+ if (result instanceof Response) return result;
120
+ if (response) {
121
+ if (response.schema) {
122
+ let validated = response.schema(result);
123
+ if (validated instanceof Promise) validated = await validated;
124
+ if (validated.issues) throw new HTTPException(500, {
125
+ res: c.json({ error: "Response validation failed" }, 500),
126
+ cause: { issues: [{
127
+ slot: "response",
128
+ issues: validated.issues
129
+ }] }
130
+ });
131
+ result = validated.value;
132
+ } else {
133
+ result = response.fn(result, c);
134
+ if (result instanceof Promise) result = await result;
135
+ if (result instanceof Response) return result;
136
+ }
137
+ return c.json(result);
138
+ }
139
+ return toResponse(c, result);
140
+ };
141
+ return Object.assign(compose(args, run), { validations: options });
142
+ };
143
+ });
144
+ /**
145
+ * Runs the middleware (all but the last argument) around `run`,
146
+ * so code after `await next()` runs after the handler.
147
+ */
148
+ const compose = (args, run) => {
149
+ const middleware = args.slice(0, -1);
150
+ if (!middleware.length) return run;
151
+ return async (c) => {
152
+ const dispatch = async (i) => {
153
+ if (i === middleware.length) {
154
+ c.res = await run(c);
155
+ return;
156
+ }
157
+ const res = await middleware[i](c, () => dispatch(i + 1));
158
+ if (res) c.res = res;
159
+ };
160
+ await dispatch(0);
161
+ return c.res;
162
+ };
163
+ };
164
+ //#endregion
165
+ export { defineHandler };
@@ -1,6 +1,7 @@
1
- import { HonoOptions } from "../../hono-base.js";
2
1
  import { Env, H, HandlerResponse, Input, IntersectNonAnyTypes, MiddlewareHandler } from "../../types.js";
2
+ import { HonoOptions } from "../../hono-base.js";
3
3
  import { Hono } from "../../hono.js";
4
+ import { DefineHandler, StandardSchema, ValidationFailure, ValidationIssue, defineHandler } from "./define-handler.js";
4
5
  //#region src/helper/factory/index.d.ts
5
6
  type InitApp<E extends Env = Env> = (app: Hono<E>) => void;
6
7
  export interface CreateHandlersInterface<E extends Env, P extends string> {
@@ -23,13 +24,41 @@ export declare class Factory<E extends Env = Env, P extends string = string> {
23
24
  defaultAppOptions?: HonoOptions<E>;
24
25
  });
25
26
  createApp: (options?: HonoOptions<E>) => Hono<E>;
27
+ defineMiddleware: <I extends Input = {}, R extends HandlerResponse<any> | void = void>(middleware: MiddlewareHandler<E, P, I, R extends void ? Response : R>) => MiddlewareHandler<E, P, I, R extends void ? Response : R>;
28
+ defineHandler: DefineHandler<E, P>;
29
+ /**
30
+ * @deprecated Use `defineMiddleware()` instead. It will be removed in the next major version.
31
+ */
26
32
  createMiddleware: <I extends Input = {}, R extends HandlerResponse<any> | void = void>(middleware: MiddlewareHandler<E, P, I, R extends void ? Response : R>) => MiddlewareHandler<E, P, I, R extends void ? Response : R>;
33
+ /**
34
+ * @deprecated Use `defineHandler()` instead. It will be removed in the next major version.
35
+ * Pass the middleware before the handler:
36
+ * `defineHandler(auth, (c) => ...)`.
37
+ */
27
38
  createHandlers: CreateHandlersInterface<E, P>;
28
39
  }
29
40
  export declare const createFactory: <E extends Env = Env, P extends string = string>(init?: {
30
41
  initApp?: InitApp<E>;
31
42
  defaultAppOptions?: HonoOptions<E>;
32
43
  }) => Factory<E, P>;
44
+ /**
45
+ * `defineMiddleware()` defines a middleware with the types.
46
+ *
47
+ * @see {@link https://hono.dev/docs/helpers/factory#definemiddleware}
48
+ *
49
+ * @example
50
+ * ```ts
51
+ * const auth = defineMiddleware<{ Variables: { user: User } }>(async (c, next) => {
52
+ * c.set('user', await getUser(c))
53
+ * await next()
54
+ * })
55
+ * ```
56
+ */
57
+ export declare const defineMiddleware: <E extends Env = any, P extends string = string, I extends Input = {}, R extends HandlerResponse<any> | void = void>(middleware: MiddlewareHandler<E, P, I, R extends void ? Response : R>) => MiddlewareHandler<E, P, I, R extends void ? Response : R>;
58
+ /**
59
+ * @deprecated Use `defineMiddleware()` instead. It will be removed in the next major version.
60
+ */
33
61
  export declare const createMiddleware: <E extends Env = any, P extends string = string, I extends Input = {}, R extends HandlerResponse<any> | void = void>(middleware: MiddlewareHandler<E, P, I, R extends void ? Response : R>) => MiddlewareHandler<E, P, I, R extends void ? Response : R>;
34
62
  //#endregion
63
+ export { type StandardSchema, type ValidationFailure, type ValidationIssue, defineHandler };
35
64
  export {};
@@ -1,4 +1,5 @@
1
1
  import { Hono } from "../../hono.js";
2
+ import { defineHandler } from "./define-handler.js";
2
3
  //#region src/helper/factory/index.ts
3
4
  /**
4
5
  * @module
@@ -19,12 +20,39 @@ var Factory = class {
19
20
  if (this.initApp) this.initApp(app);
20
21
  return app;
21
22
  };
22
- createMiddleware = (middleware) => middleware;
23
+ defineMiddleware = (middleware) => middleware;
24
+ defineHandler = defineHandler;
25
+ /**
26
+ * @deprecated Use `defineMiddleware()` instead. It will be removed in the next major version.
27
+ */
28
+ createMiddleware = this.defineMiddleware;
29
+ /**
30
+ * @deprecated Use `defineHandler()` instead. It will be removed in the next major version.
31
+ * Pass the middleware before the handler:
32
+ * `defineHandler(auth, (c) => ...)`.
33
+ */
23
34
  createHandlers = (...handlers) => {
24
35
  return handlers.filter((handler) => handler !== void 0);
25
36
  };
26
37
  };
27
38
  const createFactory = (init) => new Factory(init);
28
- const createMiddleware = (middleware) => middleware;
39
+ /**
40
+ * `defineMiddleware()` defines a middleware with the types.
41
+ *
42
+ * @see {@link https://hono.dev/docs/helpers/factory#definemiddleware}
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * const auth = defineMiddleware<{ Variables: { user: User } }>(async (c, next) => {
47
+ * c.set('user', await getUser(c))
48
+ * await next()
49
+ * })
50
+ * ```
51
+ */
52
+ const defineMiddleware = (middleware) => middleware;
53
+ /**
54
+ * @deprecated Use `defineMiddleware()` instead. It will be removed in the next major version.
55
+ */
56
+ const createMiddleware = defineMiddleware;
29
57
  //#endregion
30
- export { Factory, createFactory, createMiddleware };
58
+ export { Factory, createFactory, createMiddleware, defineHandler, defineMiddleware };
@@ -3,12 +3,6 @@ import { Context } from "../../context.js";
3
3
  //#region src/helper/ssg/middleware.d.ts
4
4
  export declare const SSG_CONTEXT = "HONO_SSG_CONTEXT";
5
5
  export declare const X_HONO_DISABLE_SSG_HEADER_KEY = "x-hono-disable-ssg";
6
- /**
7
- * @deprecated
8
- * Use `X_HONO_DISABLE_SSG_HEADER_KEY` instead.
9
- * This constant will be removed in the next minor version.
10
- */
11
- export declare const SSG_DISABLED_RESPONSE: Response;
12
6
  interface SSGParam {
13
7
  [key: string]: string;
14
8
  }
@@ -3,21 +3,6 @@ import { isDynamicRoute } from "./utils.js";
3
3
  const SSG_CONTEXT = "HONO_SSG_CONTEXT";
4
4
  const X_HONO_DISABLE_SSG_HEADER_KEY = "x-hono-disable-ssg";
5
5
  /**
6
- * @deprecated
7
- * Use `X_HONO_DISABLE_SSG_HEADER_KEY` instead.
8
- * This constant will be removed in the next minor version.
9
- */
10
- const SSG_DISABLED_RESPONSE = (() => {
11
- try {
12
- return new Response("SSG is disabled", {
13
- status: 404,
14
- headers: { [X_HONO_DISABLE_SSG_HEADER_KEY]: "true" }
15
- });
16
- } catch {
17
- return null;
18
- }
19
- })();
20
- /**
21
6
  * Define SSG Route
22
7
  */
23
8
  const ssgParams = (params) => async (c, next) => {
@@ -55,4 +40,4 @@ const onlySSG = () => async function onlySSG(c, next) {
55
40
  await next();
56
41
  };
57
42
  //#endregion
58
- export { SSG_CONTEXT, SSG_DISABLED_RESPONSE, X_HONO_DISABLE_SSG_HEADER_KEY, disableSSG, isSSGContext, onlySSG, ssgParams };
43
+ export { SSG_CONTEXT, X_HONO_DISABLE_SSG_HEADER_KEY, disableSSG, isSSGContext, onlySSG, ssgParams };
@@ -37,18 +37,6 @@ export interface SSGPlugin {
37
37
  }
38
38
  export interface ToSSGOptions {
39
39
  dir?: string;
40
- /**
41
- * @deprecated Use plugins[].beforeRequestHook instead.
42
- */
43
- beforeRequestHook?: BeforeRequestHook | BeforeRequestHook[];
44
- /**
45
- * @deprecated Use plugins[].afterResponseHook instead.
46
- */
47
- afterResponseHook?: AfterResponseHook | AfterResponseHook[];
48
- /**
49
- * @deprecated Use plugins[].afterGenerateHook instead.
50
- */
51
- afterGenerateHook?: AfterGenerateHook | AfterGenerateHook[];
52
40
  concurrency?: number;
53
41
  extensionMap?: Record<string, string>;
54
42
  plugins?: SSGPlugin[];
@@ -169,9 +169,6 @@ const toSSG = async (app, fs, options) => {
169
169
  const beforeRequestHooks = [];
170
170
  const afterResponseHooks = [];
171
171
  const afterGenerateHooks = [];
172
- if (options?.beforeRequestHook) beforeRequestHooks.push(...Array.isArray(options.beforeRequestHook) ? options.beforeRequestHook : [options.beforeRequestHook]);
173
- if (options?.afterResponseHook) afterResponseHooks.push(...Array.isArray(options.afterResponseHook) ? options.afterResponseHook : [options.afterResponseHook]);
174
- if (options?.afterGenerateHook) afterGenerateHooks.push(...Array.isArray(options.afterGenerateHook) ? options.afterGenerateHook : [options.afterGenerateHook]);
175
172
  for (const plugin of plugins) {
176
173
  if (plugin.beforeRequestHook) beforeRequestHooks.push(...Array.isArray(plugin.beforeRequestHook) ? plugin.beforeRequestHook : [plugin.beforeRequestHook]);
177
174
  if (plugin.afterResponseHook) afterResponseHooks.push(...Array.isArray(plugin.afterResponseHook) ? plugin.afterResponseHook : [plugin.afterResponseHook]);
@@ -1,6 +1,6 @@
1
1
  import { Router } from "./router.js";
2
2
  import { Env, ErrorHandler, H, HandlerInterface, MergePath, MergeSchemaPath, MiddlewareHandlerInterface, NotFoundHandler, OnHandlerInterface, RouterRoute, Schema } from "./types.js";
3
- import { Context, ExecutionContext } from "./context.js";
3
+ import { ExecutionContext } from "./context.js";
4
4
  //#region src/hono-base.d.ts
5
5
  type GetPath<E extends Env> = (request: Request, options?: {
6
6
  env?: E['Bindings'];
@@ -47,12 +47,6 @@ export type HonoOptions<E extends Env> = {
47
47
  */
48
48
  getPath?: GetPath<E>;
49
49
  };
50
- type MountOptionHandler = (c: Context) => unknown;
51
- type MountReplaceRequest = (originalRequest: Request) => Request;
52
- type MountOptions = MountOptionHandler | {
53
- optionHandler?: MountOptionHandler;
54
- replaceRequest?: MountReplaceRequest | false;
55
- };
56
50
  declare class Hono<E extends Env = Env, S extends Schema = {}, BasePath extends string = '/', CurrentPath extends string = BasePath> {
57
51
 
58
52
  get: HandlerInterface<E, 'get', S, BasePath, CurrentPath>;
@@ -106,6 +100,8 @@ declare class Hono<E extends Env = Env, S extends Schema = {}, BasePath extends
106
100
  basePath<SubPath extends string>(path: SubPath): Hono<E, S, MergePath<BasePath, SubPath>, MergePath<BasePath, SubPath>>;
107
101
  /**
108
102
  * `.onError()` handles an error and returns a customized Response.
103
+ * Non-Error values thrown by handlers are wrapped in an Error with the original value as its cause.
104
+ * If the thrown value is a string, it is also used as the error message.
109
105
  *
110
106
  * @see {@link https://hono.dev/docs/api/hono#error-handling}
111
107
  *
@@ -137,41 +133,6 @@ declare class Hono<E extends Env = Env, S extends Schema = {}, BasePath extends
137
133
  * ```
138
134
  */
139
135
  notFound: (handler: NotFoundHandler<E>) => Hono<E, S, BasePath, CurrentPath>;
140
- /**
141
- * `.mount()` allows you to mount applications built with other frameworks into your Hono application.
142
- *
143
- * @deprecated Use `mount()` from `hono/mount` instead. `.mount()` will be removed in v5.
144
- *
145
- * @see {@link https://hono.dev/docs/api/hono#mount}
146
- *
147
- * @param {string} path - base Path
148
- * @param {Function} applicationHandler - other Request Handler
149
- * @param {MountOptions} [options] - options of `.mount()`
150
- * @returns {Hono} mounted Hono instance
151
- *
152
- * @example
153
- * ```ts
154
- * import { Router as IttyRouter } from 'itty-router'
155
- * import { Hono } from 'hono'
156
- * // Create itty-router application
157
- * const ittyRouter = IttyRouter()
158
- * // GET /itty-router/hello
159
- * ittyRouter.get('/hello', () => new Response('Hello from itty-router'))
160
- *
161
- * const app = new Hono()
162
- * app.mount('/itty-router', ittyRouter.handle)
163
- * ```
164
- *
165
- * @example
166
- * ```ts
167
- * const app = new Hono()
168
- * // Send the request to another application without modification.
169
- * app.mount('/app', anotherApp, {
170
- * replaceRequest: (req) => req,
171
- * })
172
- * ```
173
- */
174
- mount(path: string, applicationHandler: (request: Request, ...args: any) => Response | Promise<Response>, options?: MountOptions): Hono<E, S, BasePath, CurrentPath>;
175
136
  /**
176
137
  * `.fetch()` will be entry point of your app.
177
138
  *
@@ -197,24 +158,6 @@ declare class Hono<E extends Env = Env, S extends Schema = {}, BasePath extends
197
158
  * @see https://hono.dev/docs/api/hono#request
198
159
  */
199
160
  request: (input: Request | string | URL, requestInit?: RequestInit, Env?: E["Bindings"] | {}, executionCtx?: ExecutionContext) => Response | Promise<Response>;
200
- /**
201
- * `.fire()` automatically adds a global fetch event listener.
202
- * This can be useful for environments that adhere to the Service Worker API, such as non-ES module Cloudflare Workers.
203
- * @deprecated
204
- * Use `fire` from `hono/service-worker` instead.
205
- * ```ts
206
- * import { Hono } from 'hono'
207
- * import { fire } from 'hono/service-worker'
208
- *
209
- * const app = new Hono()
210
- * // ...
211
- * fire(app)
212
- * ```
213
- * @see https://hono.dev/docs/api/hono#fire
214
- * @see https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API
215
- * @see https://developers.cloudflare.com/workers/reference/migrate-to-module-workers/
216
- */
217
- fire: () => void;
218
161
  }
219
162
  //#endregion
220
163
  export { Hono as HonoBase };
package/dist/hono-base.js CHANGED
@@ -1,4 +1,4 @@
1
- import { compose } from "./compose.js";
1
+ import { compose, toError } from "./compose.js";
2
2
  import { getPath, getPathNoStrict, mergePath } from "./utils/url.js";
3
3
  import { Context } from "./context.js";
4
4
  import { METHODS } from "./router.js";
@@ -135,6 +135,8 @@ var Hono = class Hono {
135
135
  }
136
136
  /**
137
137
  * `.onError()` handles an error and returns a customized Response.
138
+ * Non-Error values thrown by handlers are wrapped in an Error with the original value as its cause.
139
+ * If the thrown value is a string, it is also used as the error message.
138
140
  *
139
141
  * @see {@link https://hono.dev/docs/api/hono#error-handling}
140
142
  *
@@ -172,78 +174,6 @@ var Hono = class Hono {
172
174
  this.#notFoundHandler = handler;
173
175
  return this;
174
176
  };
175
- /**
176
- * `.mount()` allows you to mount applications built with other frameworks into your Hono application.
177
- *
178
- * @deprecated Use `mount()` from `hono/mount` instead. `.mount()` will be removed in v5.
179
- *
180
- * @see {@link https://hono.dev/docs/api/hono#mount}
181
- *
182
- * @param {string} path - base Path
183
- * @param {Function} applicationHandler - other Request Handler
184
- * @param {MountOptions} [options] - options of `.mount()`
185
- * @returns {Hono} mounted Hono instance
186
- *
187
- * @example
188
- * ```ts
189
- * import { Router as IttyRouter } from 'itty-router'
190
- * import { Hono } from 'hono'
191
- * // Create itty-router application
192
- * const ittyRouter = IttyRouter()
193
- * // GET /itty-router/hello
194
- * ittyRouter.get('/hello', () => new Response('Hello from itty-router'))
195
- *
196
- * const app = new Hono()
197
- * app.mount('/itty-router', ittyRouter.handle)
198
- * ```
199
- *
200
- * @example
201
- * ```ts
202
- * const app = new Hono()
203
- * // Send the request to another application without modification.
204
- * app.mount('/app', anotherApp, {
205
- * replaceRequest: (req) => req,
206
- * })
207
- * ```
208
- */
209
- mount(path, applicationHandler, options) {
210
- let replaceRequest;
211
- let optionHandler;
212
- if (options) {
213
- if (typeof options === "function") optionHandler = options;
214
- else {
215
- optionHandler = options.optionHandler;
216
- if (options.replaceRequest === false) replaceRequest = (request) => request;
217
- else replaceRequest = options.replaceRequest;
218
- }
219
- }
220
- const getOptions = optionHandler ? (c) => {
221
- const options = optionHandler(c);
222
- return Array.isArray(options) ? options : [options];
223
- } : (c) => {
224
- let executionContext = void 0;
225
- try {
226
- executionContext = c.executionCtx;
227
- } catch {}
228
- return [c.env, executionContext];
229
- };
230
- replaceRequest ||= (() => {
231
- const mergedPath = mergePath(this._basePath, path);
232
- const pathPrefixLength = mergedPath === "/" ? 0 : mergedPath.length;
233
- return (request) => {
234
- const url = new URL(request.url);
235
- url.pathname = this.getPath(request).slice(pathPrefixLength) || "/";
236
- return new Request(url, request);
237
- };
238
- })();
239
- const handler = async (c, next) => {
240
- const res = await applicationHandler(replaceRequest(c.req.raw), ...getOptions(c));
241
- if (res) return res;
242
- await next();
243
- };
244
- this.#addRoute("ALL", mergePath(path, "*"), handler);
245
- return this;
246
- }
247
177
  #addRoute(method, path, handler, baseRoutePath) {
248
178
  path = mergePath(this._basePath, path);
249
179
  const r = {
@@ -256,8 +186,9 @@ var Hono = class Hono {
256
186
  this.routes.push(r);
257
187
  }
258
188
  #handleError(err, c) {
259
- if (err instanceof Error) return this.errorHandler(err, c);
260
- throw err;
189
+ const error = toError(err);
190
+ c.error = error;
191
+ return this.errorHandler(error, c);
261
192
  }
262
193
  #dispatch(request, executionCtx, env, method) {
263
194
  if (method === "HEAD") return (async () => new Response(null, await this.#dispatch(request, executionCtx, env, "GET")))();
@@ -323,28 +254,6 @@ var Hono = class Hono {
323
254
  input = input.toString();
324
255
  return this.fetch(new Request(/^https?:\/\//.test(input) ? input : `http://localhost${mergePath("/", input)}`, requestInit), Env, executionCtx);
325
256
  };
326
- /**
327
- * `.fire()` automatically adds a global fetch event listener.
328
- * This can be useful for environments that adhere to the Service Worker API, such as non-ES module Cloudflare Workers.
329
- * @deprecated
330
- * Use `fire` from `hono/service-worker` instead.
331
- * ```ts
332
- * import { Hono } from 'hono'
333
- * import { fire } from 'hono/service-worker'
334
- *
335
- * const app = new Hono()
336
- * // ...
337
- * fire(app)
338
- * ```
339
- * @see https://hono.dev/docs/api/hono#fire
340
- * @see https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API
341
- * @see https://developers.cloudflare.com/workers/reference/migrate-to-module-workers/
342
- */
343
- fire = () => {
344
- addEventListener("fetch", (event) => {
345
- event.respondWith(this.#dispatch(event.request, event, void 0, event.request.method));
346
- });
347
- };
348
257
  };
349
258
  //#endregion
350
259
  export { Hono as HonoBase };
@@ -1,5 +1,5 @@
1
- import { HonoBase as Hono$1, HonoOptions } from "./hono-base.js";
2
1
  import { BlankEnv, BlankSchema, Env, Schema } from "./types.js";
2
+ import { HonoBase as Hono$1, HonoOptions } from "./hono-base.js";
3
3
  //#region src/hono.d.ts
4
4
  /**
5
5
  * The Hono class extends the functionality of the HonoBase class.
@@ -1,18 +1,19 @@
1
1
  import { MiddlewareHandler } from "../../types.js";
2
2
  import { Context } from "../../context.js";
3
+ import { StringHashFunction } from "../../utils/buffer.js";
3
4
  //#region src/middleware/basic-auth/index.d.ts
4
5
  type MessageFunction = (c: Context) => string | object | Promise<string | object>;
5
6
  type BasicAuthOptions = {
6
7
  username: string;
7
8
  password: string;
8
9
  realm?: string;
9
- hashFunction?: Function;
10
+ hashFunction?: StringHashFunction;
10
11
  invalidUserMessage?: string | object | MessageFunction;
11
12
  onAuthSuccess?: (c: Context, username: string) => void | Promise<void>;
12
13
  } | {
13
14
  verifyUser: (username: string, password: string, c: Context) => boolean | Promise<boolean>;
14
15
  realm?: string;
15
- hashFunction?: Function;
16
+ hashFunction?: StringHashFunction;
16
17
  invalidUserMessage?: string | object | MessageFunction;
17
18
  onAuthSuccess?: (c: Context, username: string) => void | Promise<void>;
18
19
  };
@@ -25,7 +26,7 @@ type BasicAuthOptions = {
25
26
  * @param {string} options.username - The username for authentication.
26
27
  * @param {string} options.password - The password for authentication.
27
28
  * @param {string} [options.realm="Secure Area"] - The realm attribute for the WWW-Authenticate header.
28
- * @param {Function} [options.hashFunction] - The hash function used for secure comparison.
29
+ * @param {StringHashFunction} [options.hashFunction] - The hash function used for secure comparison.
29
30
  * @param {Function} [options.verifyUser] - The function to verify user credentials.
30
31
  * @param {string | object | MessageFunction} [options.invalidUserMessage="Unauthorized"] - The invalid user message.
31
32
  * @param {Function} [options.onAuthSuccess] - Callback function called on successful authentication.
@@ -11,7 +11,7 @@ import { auth } from "../../utils/basic-auth.js";
11
11
  * @param {string} options.username - The username for authentication.
12
12
  * @param {string} options.password - The password for authentication.
13
13
  * @param {string} [options.realm="Secure Area"] - The realm attribute for the WWW-Authenticate header.
14
- * @param {Function} [options.hashFunction] - The hash function used for secure comparison.
14
+ * @param {StringHashFunction} [options.hashFunction] - The hash function used for secure comparison.
15
15
  * @param {Function} [options.verifyUser] - The function to verify user credentials.
16
16
  * @param {string | object | MessageFunction} [options.invalidUserMessage="Unauthorized"] - The invalid user message.
17
17
  * @param {Function} [options.onAuthSuccess] - Callback function called on successful authentication.
@@ -1,5 +1,6 @@
1
1
  import { Env, MiddlewareHandler } from "../../types.js";
2
2
  import { Context } from "../../context.js";
3
+ import { StringHashFunction } from "../../utils/buffer.js";
3
4
  //#region src/middleware/bearer-auth/index.d.ts
4
5
  type MessageFunction = (c: Context) => string | object | Promise<string | object>;
5
6
  type CustomizedErrorResponseOptions = {
@@ -11,42 +12,18 @@ type BearerAuthOptions<E extends Env = Env> = {
11
12
  realm?: string;
12
13
  prefix?: string;
13
14
  headerName?: string;
14
- hashFunction?: Function;
15
- /**
16
- * @deprecated Use noAuthenticationHeader.message instead
17
- */
18
- noAuthenticationHeaderMessage?: string | object | MessageFunction;
15
+ hashFunction?: StringHashFunction;
19
16
  noAuthenticationHeader?: CustomizedErrorResponseOptions;
20
- /**
21
- * @deprecated Use invalidAuthenticationHeader.message instead
22
- */
23
- invalidAuthenticationHeaderMessage?: string | object | MessageFunction;
24
17
  invalidAuthenticationHeader?: CustomizedErrorResponseOptions;
25
- /**
26
- * @deprecated Use invalidToken.message instead
27
- */
28
- invalidTokenMessage?: string | object | MessageFunction;
29
18
  invalidToken?: CustomizedErrorResponseOptions;
30
19
  } | {
31
20
  realm?: string;
32
21
  prefix?: string;
33
22
  headerName?: string;
34
23
  verifyToken: (token: string, c: Context<E>) => boolean | Promise<boolean>;
35
- hashFunction?: Function;
36
- /**
37
- * @deprecated Use noAuthenticationHeader.message instead
38
- */
39
- noAuthenticationHeaderMessage?: string | object | MessageFunction;
24
+ hashFunction?: StringHashFunction;
40
25
  noAuthenticationHeader?: CustomizedErrorResponseOptions;
41
- /**
42
- * @deprecated Use invalidAuthenticationHeader.message instead
43
- */
44
- invalidAuthenticationHeaderMessage?: string | object | MessageFunction;
45
26
  invalidAuthenticationHeader?: CustomizedErrorResponseOptions;
46
- /**
47
- * @deprecated Use invalidToken.message instead
48
- */
49
- invalidTokenMessage?: string | object | MessageFunction;
50
27
  invalidToken?: CustomizedErrorResponseOptions;
51
28
  };
52
29
  /**
@@ -61,7 +38,7 @@ type BearerAuthOptions<E extends Env = Env> = {
61
38
  * @param {string} [options.realm=""] - The domain name of the realm, as part of the returned WWW-Authenticate challenge header.
62
39
  * @param {string} [options.prefix="Bearer"] - The prefix (or known as `schema`) for the Authorization header value. If set to the empty string, no prefix is expected.
63
40
  * @param {string} [options.headerName=Authorization] - The header name.
64
- * @param {Function} [options.hashFunction] - A function to handle hashing for safe comparison of authentication tokens.
41
+ * @param {StringHashFunction} [options.hashFunction] - A function to handle hashing for safe comparison of authentication tokens.
65
42
  * @param {string | object | MessageFunction} [options.noAuthenticationHeader.message="Unauthorized"] - The no authentication header message.
66
43
  * @param {string | object | MessageFunction} [options.noAuthenticationHeader.wwwAuthenticateHeader="Bearer realm=\"\""] - The response header value for the WWW-Authenticate header when no authentication header is provided.
67
44
  * @param {string | object | MessageFunction} [options.invalidAuthenticationHeader.message="Bad Request"] - The invalid authentication header message.