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
@@ -16,7 +16,7 @@ const HEADER = "Authorization";
16
16
  * @param {string} [options.realm=""] - The domain name of the realm, as part of the returned WWW-Authenticate challenge header.
17
17
  * @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.
18
18
  * @param {string} [options.headerName=Authorization] - The header name.
19
- * @param {Function} [options.hashFunction] - A function to handle hashing for safe comparison of authentication tokens.
19
+ * @param {StringHashFunction} [options.hashFunction] - A function to handle hashing for safe comparison of authentication tokens.
20
20
  * @param {string | object | MessageFunction} [options.noAuthenticationHeader.message="Unauthorized"] - The no authentication header message.
21
21
  * @param {string | object | MessageFunction} [options.noAuthenticationHeader.wwwAuthenticateHeader="Bearer realm=\"\""] - The response header value for the WWW-Authenticate header when no authentication header is provided.
22
22
  * @param {string | object | MessageFunction} [options.invalidAuthenticationHeader.message="Bad Request"] - The invalid authentication header message.
@@ -66,7 +66,7 @@ const bearerAuth = (options) => {
66
66
  };
67
67
  return async function bearerAuth(c, next) {
68
68
  const headerToken = c.req.header(options.headerName || HEADER);
69
- if (!headerToken) await throwHTTPException(c, 401, options.noAuthenticationHeader?.wwwAuthenticateHeader || `${wwwAuthenticatePrefix}realm="${realm}"`, options.noAuthenticationHeader?.message || options.noAuthenticationHeaderMessage || "Unauthorized");
69
+ if (!headerToken) await throwHTTPException(c, 401, options.noAuthenticationHeader?.wwwAuthenticateHeader || `${wwwAuthenticatePrefix}realm="${realm}"`, options.noAuthenticationHeader?.message || "Unauthorized");
70
70
  else {
71
71
  let tokenValue;
72
72
  if (prefix === "") tokenValue = headerToken;
@@ -75,7 +75,7 @@ const bearerAuth = (options) => {
75
75
  const prefixLower = prefix.toLowerCase();
76
76
  if (headerLower.startsWith(prefixLower) && headerToken[prefix.length] === " ") tokenValue = headerToken.slice(prefix.length).trimStart();
77
77
  }
78
- if (!tokenValue || !tokenRegexp.test(tokenValue)) await throwHTTPException(c, 400, options.invalidAuthenticationHeader?.wwwAuthenticateHeader || `${wwwAuthenticatePrefix}error="invalid_request"`, options.invalidAuthenticationHeader?.message || options.invalidAuthenticationHeaderMessage || "Bad Request");
78
+ if (!tokenValue || !tokenRegexp.test(tokenValue)) await throwHTTPException(c, 400, options.invalidAuthenticationHeader?.wwwAuthenticateHeader || `${wwwAuthenticatePrefix}error="invalid_request"`, options.invalidAuthenticationHeader?.message || "Bad Request");
79
79
  else {
80
80
  let equal = false;
81
81
  if ("verifyToken" in options) equal = await options.verifyToken(tokenValue, c);
@@ -86,7 +86,7 @@ const bearerAuth = (options) => {
86
86
  break;
87
87
  }
88
88
  }
89
- if (!equal) await throwHTTPException(c, 401, options.invalidToken?.wwwAuthenticateHeader || `${wwwAuthenticatePrefix}error="invalid_token"`, options.invalidToken?.message || options.invalidTokenMessage || "Unauthorized");
89
+ if (!equal) await throwHTTPException(c, 401, options.invalidToken?.wwwAuthenticateHeader || `${wwwAuthenticatePrefix}error="invalid_token"`, options.invalidToken?.message || "Unauthorized");
90
90
  }
91
91
  }
92
92
  await next();
@@ -1,5 +1,5 @@
1
- import { getCookie, setCookie } from "../../helper/cookie/index.js";
2
1
  import { parseAccept } from "../../utils/accept.js";
2
+ import { getCookie, setCookie } from "../../helper/cookie/index.js";
3
3
  //#region src/middleware/language/language.ts
4
4
  const DEFAULT_OPTIONS = {
5
5
  order: [
@@ -1,4 +1,4 @@
1
- import { getColorEnabledAsync } from "../../utils/color.js";
1
+ import { getColorEnabled } from "../../utils/color.js";
2
2
  //#region src/middleware/logger/index.ts
3
3
  const humanize = (times) => {
4
4
  const [delimiter, separator] = [",", "."];
@@ -8,8 +8,8 @@ const time = (start) => {
8
8
  const delta = Date.now() - start;
9
9
  return humanize([delta < 1e3 ? delta + "ms" : Math.round(delta / 1e3) + "s"]);
10
10
  };
11
- const colorStatus = async (status) => {
12
- if (await getColorEnabledAsync()) switch (status / 100 | 0) {
11
+ const colorStatus = (status, colorEnabled) => {
12
+ if (colorEnabled) switch (status / 100 | 0) {
13
13
  case 5: return `\x1b[31m${status}\x1b[0m`;
14
14
  case 4: return `\x1b[33m${status}\x1b[0m`;
15
15
  case 3: return `\x1b[36m${status}\x1b[0m`;
@@ -17,9 +17,6 @@ const colorStatus = async (status) => {
17
17
  }
18
18
  return `${status}`;
19
19
  };
20
- async function log(fn, prefix, method, path, status = 0, elapsed) {
21
- fn(prefix === "<--" ? `${prefix} ${method} ${path}` : `${prefix} ${method} ${path} ${await colorStatus(status)} ${elapsed}`);
22
- }
23
20
  /**
24
21
  * Logger Middleware for Hono.
25
22
  *
@@ -40,10 +37,11 @@ const logger = (fn = console.log) => {
40
37
  return async function logger(c, next) {
41
38
  const { method, url } = c.req;
42
39
  const path = url.slice(url.indexOf("/", 8));
43
- await log(fn, "<--", method, path);
40
+ fn(`<-- ${method} ${path}`);
44
41
  const start = Date.now();
45
42
  await next();
46
- await log(fn, "-->", method, path, c.res.status, time(start));
43
+ const elapsed = time(start);
44
+ fn(`--> ${method} ${path} ${colorStatus(c.res.status, getColorEnabled(c.env))} ${elapsed}`);
47
45
  };
48
46
  };
49
47
  //#endregion
@@ -22,10 +22,6 @@ export declare const serveStatic: <E extends Env = Env>(options: ServeStaticOpti
22
22
  * `join` option according to the runtime. Example `import { join } from 'node:path`. If not specified, it will fall back to the default join function.`
23
23
  */
24
24
  join?: (...paths: string[]) => string;
25
- /**
26
- * @deprecated Currently, `pathResolve` is no longer used.
27
- */
28
- pathResolve?: (path: string) => string;
29
25
  isDir?: (path: string) => boolean | undefined | Promise<boolean | undefined>;
30
26
  }) => MiddlewareHandler;
31
27
  //#endregion
@@ -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/preset/quick.d.ts
4
4
  export declare class Hono<E extends Env = BlankEnv, S extends Schema = BlankSchema, BasePath extends string = '/'> extends Hono$1<E, S, BasePath> {
5
5
  constructor(options?: HonoOptions<E>);
@@ -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/preset/tiny.d.ts
4
4
  export declare class Hono<E extends Env = BlankEnv, S extends Schema = BlankSchema, BasePath extends string = '/'> extends Hono$1<E, S, BasePath> {
5
5
  constructor(options?: HonoOptions<E>);
@@ -81,7 +81,7 @@ export declare class HonoRequest<P extends string = '/', I extends Input['out']
81
81
  * ```
82
82
  */
83
83
  query(key: string): string | undefined;
84
- query(): Record<string, string>;
84
+ query(): Record<string, string | undefined>;
85
85
  /**
86
86
  * `.queries()` can get multiple querystring parameter values, e.g. /search?tags=A&tags=B
87
87
  *
@@ -96,7 +96,7 @@ export declare class HonoRequest<P extends string = '/', I extends Input['out']
96
96
  * ```
97
97
  */
98
98
  queries(key: string): string[] | undefined;
99
- queries(): Record<string, string[]>;
99
+ queries(): Record<string, string[] | undefined>;
100
100
  /**
101
101
  * `.header()` can get the request header value.
102
102
  *
@@ -138,7 +138,7 @@ export declare class HonoRequest<P extends string = '/', I extends Input['out']
138
138
  * })
139
139
  * ```
140
140
  */
141
- json<T = any>(): Promise<T>;
141
+ json<T = unknown>(): Promise<T>;
142
142
  /**
143
143
  * `.text()` can parse Request body of type `text/plain`
144
144
  *
@@ -244,51 +244,6 @@ export declare class HonoRequest<P extends string = '/', I extends Input['out']
244
244
  */
245
245
  get method(): string;
246
246
  get [GET_MATCH_RESULT](): Result<[unknown, RouterRoute]>;
247
- /**
248
- * `.matchedRoutes` can return a matched route in the handler
249
- *
250
- * @deprecated
251
- *
252
- * Use matchedRoutes helper defined in "hono/route" instead.
253
- *
254
- * @see {@link https://hono.dev/docs/api/request#matchedroutes}
255
- *
256
- * @example
257
- * ```ts
258
- * app.use('*', async function logger(c, next) {
259
- * await next()
260
- * c.req.matchedRoutes.forEach(({ handler, method, path }, i) => {
261
- * const name = handler.name || (handler.length < 2 ? '[handler]' : '[middleware]')
262
- * console.log(
263
- * method,
264
- * ' ',
265
- * path,
266
- * ' '.repeat(Math.max(10 - path.length, 0)),
267
- * name,
268
- * i === c.req.routeIndex ? '<- respond from here' : ''
269
- * )
270
- * })
271
- * })
272
- * ```
273
- */
274
- get matchedRoutes(): RouterRoute[];
275
- /**
276
- * `.routePath` can retrieve the path registered within the handler
277
- *
278
- * @deprecated
279
- *
280
- * Use routePath helper defined in "hono/route" instead.
281
- *
282
- * @see {@link https://hono.dev/docs/api/request#routepath}
283
- *
284
- * @example
285
- * ```ts
286
- * app.get('/posts/:id', (c) => {
287
- * return c.json({ path: c.req.routePath })
288
- * })
289
- * ```
290
- */
291
- get routePath(): string;
292
247
  }
293
248
  /**
294
249
  * Clones a HonoRequest's underlying raw Request object.
package/dist/request.js CHANGED
@@ -221,55 +221,6 @@ var HonoRequest = class {
221
221
  get [GET_MATCH_RESULT]() {
222
222
  return this.#matchResult;
223
223
  }
224
- /**
225
- * `.matchedRoutes` can return a matched route in the handler
226
- *
227
- * @deprecated
228
- *
229
- * Use matchedRoutes helper defined in "hono/route" instead.
230
- *
231
- * @see {@link https://hono.dev/docs/api/request#matchedroutes}
232
- *
233
- * @example
234
- * ```ts
235
- * app.use('*', async function logger(c, next) {
236
- * await next()
237
- * c.req.matchedRoutes.forEach(({ handler, method, path }, i) => {
238
- * const name = handler.name || (handler.length < 2 ? '[handler]' : '[middleware]')
239
- * console.log(
240
- * method,
241
- * ' ',
242
- * path,
243
- * ' '.repeat(Math.max(10 - path.length, 0)),
244
- * name,
245
- * i === c.req.routeIndex ? '<- respond from here' : ''
246
- * )
247
- * })
248
- * })
249
- * ```
250
- */
251
- get matchedRoutes() {
252
- return this.#matchResult[0].map(([[, route]]) => route);
253
- }
254
- /**
255
- * `.routePath` can retrieve the path registered within the handler
256
- *
257
- * @deprecated
258
- *
259
- * Use routePath helper defined in "hono/route" instead.
260
- *
261
- * @see {@link https://hono.dev/docs/api/request#routepath}
262
- *
263
- * @example
264
- * ```ts
265
- * app.get('/posts/:id', (c) => {
266
- * return c.json({ path: c.req.routePath })
267
- * })
268
- * ```
269
- */
270
- get routePath() {
271
- return this.#matchResult[0].map(([[, route]]) => route)[this.routeIndex].path;
272
- }
273
224
  };
274
225
  /**
275
226
  * Clones a HonoRequest's underlying raw Request object.
@@ -2,7 +2,7 @@ import { checkOptionalParameter } from "../../utils/url.js";
2
2
  import { UnsupportedPathError } from "../../router.js";
3
3
  //#region src/router/linear-router/router.ts
4
4
  const emptyParams = Object.create(null);
5
- const splitPathRe = /\/(:\w+(?:{(?:(?:{[\d,]+})|[^}])+})?)|\/[^\/\?]+|(\?)/g;
5
+ const splitPathRe = /\/(:\w+(?:{(?:(?:{[\d,]+})|[^}])+})?)|\/[^\/\?]+|\/$|(\?)/g;
6
6
  const splitByStarRe = /\*/;
7
7
  var LinearRouter = class {
8
8
  name = "LinearRouter";
@@ -26,7 +26,7 @@ var LinearRouter = class {
26
26
  const hasStar = routePath.indexOf("*") !== -1;
27
27
  const hasLabel = routePath.indexOf(":") !== -1;
28
28
  if (!hasStar && !hasLabel) {
29
- if (routePath === path || routePath + "/" === path) handlers.push([handler, emptyParams]);
29
+ if (routePath === path) handlers.push([handler, emptyParams]);
30
30
  } else if (hasStar && !hasLabel) {
31
31
  const endsWithStar = routePath.charCodeAt(routePath.length - 1) === 42;
32
32
  const endsWithSlashStar = routePath.endsWith("/*");
@@ -39,7 +39,7 @@ var LinearRouter = class {
39
39
  if (j === lastIndex) {
40
40
  if (endsWithSlashStar) {
41
41
  if (pos !== path.length && path.charCodeAt(pos) !== 47) continue ROUTES_LOOP;
42
- } else if (!endsWithStar && pos !== path.length && !(pos === path.length - 1 && path.charCodeAt(pos) === 47)) continue ROUTES_LOOP;
42
+ } else if (!endsWithStar && pos !== path.length) continue ROUTES_LOOP;
43
43
  } else {
44
44
  const index = path.indexOf("/", pos);
45
45
  if (index === -1) continue ROUTES_LOOP;
@@ -81,9 +81,7 @@ var LinearRouter = class {
81
81
  if (path.indexOf(part, pos) !== pos) continue ROUTES_LOOP;
82
82
  pos += part.length;
83
83
  }
84
- if (j === lastIndex) {
85
- if (pos !== path.length && !(pos === path.length - 1 && path.charCodeAt(pos) === 47)) continue ROUTES_LOOP;
86
- }
84
+ if (j === lastIndex && pos !== path.length) continue ROUTES_LOOP;
87
85
  }
88
86
  handlers.push([handler, params]);
89
87
  } else if (hasLabel && hasStar) throw new UnsupportedPathError();
@@ -5,11 +5,11 @@ var PatternRouter = class {
5
5
  name = "PatternRouter";
6
6
  #routes = [];
7
7
  add(method, path, handler) {
8
- const suffix = path.endsWith("/*") ? "(?:$|/)" : path.endsWith("*") ? "" : "/?$";
8
+ const suffix = path.endsWith("/*") ? "(?:$|/)" : path.endsWith("*") ? "" : path.endsWith("/") ? "/$" : "$";
9
9
  path = path.replace(/\*$/, "");
10
10
  if (path.at(-1) === "?") {
11
11
  path = path.slice(0, -1);
12
- this.add(method, path.replace(/\/[^/]+$/, ""), handler);
12
+ this.add(method, path.replace(/\/[^/]+$/, "") || "/", handler);
13
13
  }
14
14
  const parts = (path.match(/\/?(:\w+(?:{(?:(?:{[\d,]+})|[^}])+})?)|\/?[^\/\?]+/g) || []).map((part) => {
15
15
  const match = part.match(/^\/:([^{]+)(?:{(.*)})?/);
@@ -47,7 +47,7 @@ var Node = class Node {
47
47
  const name = pattern[1];
48
48
  let regexpStr = pattern[2] || "[^/]+";
49
49
  if (name && pattern[2]) {
50
- if (regexpStr === ".*") throw PATH_ERROR;
50
+ if (new RegExp(regexpStr).test("")) throw PATH_ERROR;
51
51
  regexpStr = regexpStr.replace(/^\((?!\?:)(?=[^)]+\)$)/, "(?:");
52
52
  if (/\((?!\?:)/.test(regexpStr)) throw PATH_ERROR;
53
53
  if (regexpStr.length === 1 && regExpMetaChars.has(regexpStr)) throw PATH_ERROR;
@@ -66,9 +66,9 @@ var Node = class Node {
66
66
  if (nextNode) {
67
67
  nextNode.#params = node.#params;
68
68
  if (isLast) {
69
- if (nextNode.#children["*"]) this.#pushHandlerSets(handlerSets, nextNode.#children["*"], method, node.#params);
70
- this.#pushHandlerSets(handlerSets, nextNode, method, node.#params);
71
- } else tempNodes.push(nextNode);
69
+ if (nextNode.#children["*"] && !Array.isArray(nextNode.#pattern)) this.#pushHandlerSets(handlerSets, nextNode.#children["*"], method, node.#params);
70
+ if (nextNode.#pattern === void 0) this.#pushHandlerSets(handlerSets, nextNode, method, node.#params);
71
+ } else if (nextNode.#pattern !== "*" && !Array.isArray(nextNode.#pattern)) tempNodes.push(nextNode);
72
72
  }
73
73
  for (const child of node.#patterns) {
74
74
  const pattern = child.#pattern;
@@ -0,0 +1,11 @@
1
+ //#region src/utils/buffer.d.ts
2
+ /**
3
+ * @module
4
+ * Buffer utility.
5
+ */
6
+ export declare const equal: (a: ArrayBuffer, b: ArrayBuffer) => boolean;
7
+ export type StringHashFunction = (input: string) => string | null | Promise<string | null>;
8
+ export declare const timingSafeEqual: (a: string, b: string, hashFunction?: StringHashFunction) => Promise<boolean>;
9
+ export declare const bufferToString: (buffer: ArrayBuffer) => string;
10
+ export declare const bufferToFormData: (arrayBuffer: ArrayBuffer, contentType: string) => Promise<FormData>;
11
+ //#endregion
@@ -25,7 +25,7 @@ const constantTimeEqualString = (a, b) => {
25
25
  }
26
26
  return out === 0;
27
27
  };
28
- const timingSafeEqualString = async (a, b, hashFunction) => {
28
+ const timingSafeEqual = async (a, b, hashFunction) => {
29
29
  if (!hashFunction) hashFunction = sha256;
30
30
  const [sa, sb] = await Promise.all([hashFunction(a), hashFunction(b)]);
31
31
  if (sa == null || sb == null || typeof sa !== "string" || typeof sb !== "string") return false;
@@ -33,13 +33,6 @@ const timingSafeEqualString = async (a, b, hashFunction) => {
33
33
  const originalEqual = constantTimeEqualString(a, b);
34
34
  return hashEqual && originalEqual;
35
35
  };
36
- const timingSafeEqual = async (a, b, hashFunction) => {
37
- if (typeof a === "string" && typeof b === "string") return timingSafeEqualString(a, b, hashFunction);
38
- if (!hashFunction) hashFunction = sha256;
39
- const [sa, sb] = await Promise.all([hashFunction(a), hashFunction(b)]);
40
- if (!sa || !sb || typeof sa !== "string" || typeof sb !== "string") return false;
41
- return timingSafeEqualString(sa, sb);
42
- };
43
36
  const bufferToString = (buffer) => {
44
37
  if (buffer instanceof ArrayBuffer) return new TextDecoder("utf-8").decode(buffer);
45
38
  return buffer;
@@ -0,0 +1,16 @@
1
+ //#region src/utils/color.d.ts
2
+ /**
3
+ * @module
4
+ * Color utility.
5
+ */
6
+ /**
7
+ * Get whether color change on terminal is enabled or disabled.
8
+ * If `NO_COLOR` is set in the provided bindings or runtime environment, this function returns `false`.
9
+ * Pass Cloudflare Workers bindings explicitly, for example `getColorEnabled(c.env)`.
10
+ * @see {@link https://no-color.org/}
11
+ *
12
+ * @param {object} [env] - Optional environment bindings to check in addition to the runtime environment.
13
+ * @returns {boolean}
14
+ */
15
+ export declare function getColorEnabled(env?: object): boolean;
16
+ //#endregion
@@ -5,33 +5,17 @@
5
5
  */
6
6
  /**
7
7
  * Get whether color change on terminal is enabled or disabled.
8
- * If `NO_COLOR` environment variable is set, this function returns `false`.
9
- * Unlike getColorEnabledAsync(), this cannot check Cloudflare environment variables.
8
+ * If `NO_COLOR` is set in the provided bindings or runtime environment, this function returns `false`.
9
+ * Pass Cloudflare Workers bindings explicitly, for example `getColorEnabled(c.env)`.
10
10
  * @see {@link https://no-color.org/}
11
11
  *
12
+ * @param {object} [env] - Optional environment bindings to check in addition to the runtime environment.
12
13
  * @returns {boolean}
13
14
  */
14
- function getColorEnabled() {
15
+ function getColorEnabled(env) {
16
+ if (env && "NO_COLOR" in env) return false;
15
17
  const { process, Deno } = globalThis;
16
- return !(typeof Deno?.noColor === "boolean" ? Deno.noColor : process !== void 0 ? "NO_COLOR" in process?.env : false);
17
- }
18
- /**
19
- * Get whether color change on terminal is enabled or disabled.
20
- * If `NO_COLOR` environment variable is set, this function returns `false`.
21
- * @see {@link https://no-color.org/}
22
- *
23
- * @returns {boolean}
24
- */
25
- async function getColorEnabledAsync() {
26
- const { navigator } = globalThis;
27
- const cfWorkers = "cloudflare:workers";
28
- return !(navigator !== void 0 && navigator.userAgent === "Cloudflare-Workers" ? await (async () => {
29
- try {
30
- return "NO_COLOR" in ((await import(cfWorkers)).env ?? {});
31
- } catch {
32
- return false;
33
- }
34
- })() : !getColorEnabled());
18
+ return !(typeof Deno?.noColor === "boolean" ? Deno.noColor : "NO_COLOR" in (process?.env ?? {}));
35
19
  }
36
20
  //#endregion
37
- export { getColorEnabled, getColorEnabledAsync };
21
+ export { getColorEnabled };
@@ -11,8 +11,8 @@ export type ClientErrorStatusCode = 400 | 401 | 402 | 403 | 404 | 405 | 406 | 40
11
11
  export type ServerErrorStatusCode = 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511;
12
12
  /**
13
13
  * `UnofficialStatusCode` can be used to specify an unofficial status code.
14
- * @example
15
14
  *
15
+ * @example
16
16
  * ```ts
17
17
  * app.get('/unknown', (c) => {
18
18
  * return c.text("Unknown Error", 520 as UnofficialStatusCode)
@@ -20,14 +20,6 @@ export type ServerErrorStatusCode = 500 | 501 | 502 | 503 | 504 | 505 | 506 | 50
20
20
  * ```
21
21
  */
22
22
  export type UnofficialStatusCode = -1;
23
- /**
24
- * @deprecated
25
- * Use `UnofficialStatusCode` instead.
26
- */
27
- export type UnOfficalStatusCode = UnofficialStatusCode;
28
- /**
29
- * If you want to use an unofficial status, use `UnofficialStatusCode`.
30
- */
31
23
  export type StatusCode = InfoStatusCode | SuccessStatusCode | RedirectStatusCode | ClientErrorStatusCode | ServerErrorStatusCode | UnofficialStatusCode;
32
24
  export type ContentlessStatusCode = 101 | 204 | 205 | 304;
33
25
  export type ContentfulStatusCode = Exclude<StatusCode, ContentlessStatusCode>;
@@ -20,11 +20,6 @@ export declare const tryDecode: (str: string, decoder: Decoder) => string;
20
20
  */
21
21
  export declare const tryDecodeURI: (str: string) => string;
22
22
  export declare const getPath: (request: Request) => string;
23
- /**
24
- * @deprecated
25
- * Use the `URL` API instead.
26
- */
27
- export declare const getQueryStrings: (url: string) => string;
28
23
  export declare const getPathNoStrict: (request: Request) => string;
29
24
  /**
30
25
  * Merge paths.
package/dist/utils/url.js CHANGED
@@ -96,16 +96,6 @@ const getPath = (request) => {
96
96
  }
97
97
  return url.slice(start, i);
98
98
  };
99
- /**
100
- * @deprecated
101
- * Use the `URL` API instead.
102
- */
103
- const getQueryStrings = (url) => {
104
- const queryIndex = url.indexOf("?", 8);
105
- if (queryIndex === -1) return "";
106
- const hashIndex = url.indexOf("#", 8);
107
- return hashIndex === -1 ? url.slice(queryIndex) : queryIndex < hashIndex ? url.slice(queryIndex, hashIndex) : "";
108
- };
109
99
  const getPathNoStrict = (request) => {
110
100
  const result = getPath(request);
111
101
  return result.length > 1 && result.at(-1) === "/" ? result.slice(0, -1) : result;
@@ -198,4 +188,4 @@ const getQueryParams = (url, key) => {
198
188
  };
199
189
  const decodeURIComponent_ = decodeURIComponent;
200
190
  //#endregion
201
- export { checkOptionalParameter, decodeURIComponent_, getPath, getPathNoStrict, getPattern, getQueryParam, getQueryParams, getQueryStrings, mergePath, splitPath, splitRoutingPath, tryDecode, tryDecodeURI, tryDecodeURIComponent };
191
+ export { checkOptionalParameter, decodeURIComponent_, getPath, getPathNoStrict, getPattern, getQueryParam, getQueryParams, mergePath, splitPath, splitRoutingPath, tryDecode, tryDecodeURI, tryDecodeURIComponent };
@@ -6,6 +6,11 @@ type ValidationTargetKeysWithBody = 'form' | 'json';
6
6
  type ValidationTargetByMethod<M> = M extends 'get' | 'head' ? Exclude<keyof ValidationTargets, ValidationTargetKeysWithBody> : keyof ValidationTargets;
7
7
  export type ValidationFunction<InputType, OutputType, E extends Env = {}, P extends string = string> = (value: InputType, c: Context<E, P>) => OutputType | TypedResponse | Promise<OutputType> | Promise<TypedResponse>;
8
8
  export type ExtractValidationResponse<VF> = VF extends ((value: any, c: any) => infer R) ? R extends Promise<infer PR> ? PR extends TypedResponse<infer T, infer S, infer F> ? TypedResponse<T, S, F> : PR extends Response ? PR : PR extends undefined ? never : never : R extends TypedResponse<infer T, infer S, infer F> ? TypedResponse<T, S, F> : R extends Response ? R : R extends undefined ? never : never : never;
9
+ /**
10
+ * Get the value of the validation target from the request.
11
+ * Returns a Promise only for `json` and `form`.
12
+ */
13
+ export declare const getValidationTarget: (c: Context, target: keyof ValidationTargets) => unknown | Promise<unknown>;
9
14
  export declare const validator: <InputType, P extends string, M extends string, U extends ValidationTargetByMethod<M>, P2 extends string = P, VF extends (value: unknown extends InputType ? ValidationTargets[U] : InputType, c: Context<any, P2>) => any = (value: unknown extends InputType ? ValidationTargets[U] : InputType, c: Context<any, P2>) => any, V extends {
10
15
  in: { [K in U]: K extends "json" ? unknown extends InputType ? ExtractValidatorOutput<VF> : InputType : InferInput<ExtractValidatorOutput<VF>, K, FormValue>; };
11
16
  out: { [K in U]: ExtractValidatorOutput<VF>; };
@@ -5,60 +5,57 @@ import { getCookie } from "../helper/cookie/index.js";
5
5
  const jsonRegex = /^application\/([a-z-\.]+\+)?json(;\s*[a-zA-Z0-9\-]+\=([^;]+))*$/i;
6
6
  const multipartRegex = /^multipart\/form-data(;\s?boundary=[a-zA-Z0-9'"()+_,\-./:=?]+)?$/i;
7
7
  const urlencodedRegex = /^application\/x-www-form-urlencoded(;\s*[a-zA-Z0-9\-]+\=([^;]+))*$/i;
8
+ /**
9
+ * Get the value of the validation target from the request.
10
+ * Returns a Promise only for `json` and `form`.
11
+ */
12
+ const getValidationTarget = (c, target) => {
13
+ const contentType = c.req.header("Content-Type");
14
+ switch (target) {
15
+ case "json":
16
+ if (!contentType || !jsonRegex.test(contentType)) return {};
17
+ return c.req.json().catch(() => {
18
+ throw new HTTPException(400, { message: "Malformed JSON in request body" });
19
+ });
20
+ case "form":
21
+ if (!contentType || !(multipartRegex.test(contentType) || urlencodedRegex.test(contentType))) return {};
22
+ return getForm(c, contentType);
23
+ case "query": return Object.fromEntries(Object.entries(c.req.queries()).map(([k, v]) => {
24
+ return v?.length === 1 ? [k, v[0]] : [k, v];
25
+ }));
26
+ case "param": return c.req.param();
27
+ case "header": return c.req.header();
28
+ case "cookie": return getCookie(c);
29
+ }
30
+ };
31
+ const getForm = async (c, contentType) => {
32
+ let formData;
33
+ if (c.req.bodyCache.formData) formData = await c.req.bodyCache.formData;
34
+ else try {
35
+ const arrayBuffer = await c.req.arrayBuffer();
36
+ formData = await bufferToFormData(arrayBuffer, contentType);
37
+ c.req.bodyCache.formData = formData;
38
+ } catch (e) {
39
+ let message = "Malformed FormData request.";
40
+ message += e instanceof Error ? ` ${e.message}` : ` ${String(e)}`;
41
+ throw new HTTPException(400, { message });
42
+ }
43
+ const form = Object.create(null);
44
+ formData.forEach((value, key) => {
45
+ if (key.endsWith("[]")) (form[key] ??= []).push(value);
46
+ else if (Array.isArray(form[key])) form[key].push(value);
47
+ else if (Object.hasOwn(form, key)) form[key] = [form[key], value];
48
+ else form[key] = value;
49
+ });
50
+ return form;
51
+ };
8
52
  const validator = (target, validationFunc) => {
9
53
  return async (c, next) => {
10
- let value = {};
11
- const contentType = c.req.header("Content-Type");
12
- switch (target) {
13
- case "json":
14
- if (!contentType || !jsonRegex.test(contentType)) break;
15
- try {
16
- value = await c.req.json();
17
- } catch {
18
- throw new HTTPException(400, { message: "Malformed JSON in request body" });
19
- }
20
- break;
21
- case "form": {
22
- if (!contentType || !(multipartRegex.test(contentType) || urlencodedRegex.test(contentType))) break;
23
- let formData;
24
- if (c.req.bodyCache.formData) formData = await c.req.bodyCache.formData;
25
- else try {
26
- const arrayBuffer = await c.req.arrayBuffer();
27
- formData = await bufferToFormData(arrayBuffer, contentType);
28
- c.req.bodyCache.formData = formData;
29
- } catch (e) {
30
- let message = "Malformed FormData request.";
31
- message += e instanceof Error ? ` ${e.message}` : ` ${String(e)}`;
32
- throw new HTTPException(400, { message });
33
- }
34
- const form = Object.create(null);
35
- formData.forEach((value, key) => {
36
- if (key.endsWith("[]")) (form[key] ??= []).push(value);
37
- else if (Array.isArray(form[key])) form[key].push(value);
38
- else if (Object.hasOwn(form, key)) form[key] = [form[key], value];
39
- else form[key] = value;
40
- });
41
- value = form;
42
- break;
43
- }
44
- case "query":
45
- value = Object.fromEntries(Object.entries(c.req.queries()).map(([k, v]) => {
46
- return v.length === 1 ? [k, v[0]] : [k, v];
47
- }));
48
- break;
49
- case "param":
50
- value = c.req.param();
51
- break;
52
- case "header":
53
- value = c.req.header();
54
- break;
55
- case "cookie": value = getCookie(c);
56
- }
57
- const res = await validationFunc(value, c);
54
+ const res = await validationFunc(await getValidationTarget(c, target), c);
58
55
  if (res instanceof Response) return res;
59
56
  c.req.addValidatedData(target, res);
60
57
  return await next();
61
58
  };
62
59
  };
63
60
  //#endregion
64
- export { validator };
61
+ export { getValidationTarget, validator };