hono 4.13.13 → 5.0.0-rc.1
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.
- package/README.md +2 -2
- package/dist/client/fetch-result-please.js +0 -22
- package/dist/client/utils.js +0 -7
- package/dist/{types/compose.d.ts → compose.d.ts} +5 -3
- package/dist/compose.js +18 -31
- package/dist/context/constants.d.ts +3 -0
- package/dist/context/constants.js +4 -0
- package/dist/{types/context.d.ts → context.d.ts} +56 -15
- package/dist/context.js +83 -277
- package/dist/helper/accepts/accepts.js +0 -13
- package/dist/helper/css/common.js +0 -10
- package/dist/helper/css/index.js +0 -38
- package/dist/{types/helper → helper}/dev/index.d.ts +5 -2
- package/dist/helper/dev/index.js +3 -3
- package/dist/helper/factory/define-handler.d.ts +150 -0
- package/dist/helper/factory/define-handler.js +117 -0
- package/dist/{types/helper → helper}/factory/index.d.ts +30 -1
- package/dist/helper/factory/index.js +7 -7
- package/dist/helper/html/index.js +0 -4
- package/dist/helper/proxy/index.js +0 -49
- package/dist/helper/route/index.js +0 -90
- package/dist/{types/helper → helper}/ssg/middleware.d.ts +0 -6
- package/dist/helper/ssg/middleware.js +1 -34
- package/dist/helper/ssg/plugins.js +0 -24
- package/dist/{types/helper → helper}/ssg/ssg.d.ts +0 -12
- package/dist/helper/ssg/ssg.js +0 -18
- package/dist/helper/ssg/utils.js +0 -5
- package/dist/helper/testing/index.js +0 -4
- package/dist/helper/websocket/index.js +0 -6
- package/dist/{types/hono-base.d.ts → hono-base.d.ts} +47 -95
- package/dist/hono-base.js +63 -228
- package/dist/{types/hono.d.ts → hono.d.ts} +1 -1
- package/dist/hono.js +0 -13
- package/dist/http-exception.js +0 -36
- package/dist/index.js +0 -15
- package/dist/jsx/components.js +0 -5
- package/dist/jsx/context.js +0 -34
- package/dist/jsx/dom/client.js +0 -14
- package/dist/jsx/dom/css.js +0 -34
- package/dist/jsx/dom/hooks/index.js +0 -21
- package/dist/jsx/dom/index.js +0 -4
- package/dist/jsx/dom/server.js +0 -12
- package/dist/jsx/index.js +0 -4
- package/dist/jsx/streaming.js +0 -26
- package/dist/{types/middleware → middleware}/basic-auth/index.d.ts +4 -3
- package/dist/middleware/basic-auth/index.js +0 -49
- package/dist/{types/middleware → middleware}/bearer-auth/index.d.ts +4 -27
- package/dist/middleware/bearer-auth/index.js +3 -39
- package/dist/middleware/body-limit/index.js +0 -32
- package/dist/middleware/cache/index.js +0 -31
- package/dist/middleware/combine/index.js +0 -80
- package/dist/middleware/compress/index.js +0 -24
- package/dist/middleware/context-storage/index.js +0 -35
- package/dist/middleware/cors/index.js +0 -39
- package/dist/middleware/csrf/index.js +0 -62
- package/dist/middleware/etag/index.js +0 -29
- package/dist/middleware/ip-restriction/index.js +0 -41
- package/dist/middleware/jsx-renderer/index.js +0 -58
- package/dist/middleware/jwk/jwk.js +0 -31
- package/dist/middleware/jwt/jwt.js +0 -32
- package/dist/middleware/language/language.js +0 -60
- package/dist/middleware/logger/index.js +6 -24
- package/dist/middleware/method-not-allowed/index.js +1 -36
- package/dist/middleware/method-override/index.js +0 -25
- package/dist/middleware/mount/index.js +0 -32
- package/dist/middleware/powered-by/index.js +0 -15
- package/dist/middleware/pretty-json/index.js +0 -18
- package/dist/middleware/request-id/request-id.js +0 -22
- package/dist/middleware/secure-headers/secure-headers.js +0 -32
- package/dist/{types/middleware → middleware}/serve-static/index.d.ts +0 -4
- package/dist/middleware/serve-static/index.js +0 -3
- package/dist/middleware/serve-static/path.js +0 -4
- package/dist/middleware/timeout/index.js +0 -22
- package/dist/middleware/timing/timing.js +0 -95
- package/dist/middleware/trailing-slash/index.js +0 -50
- package/dist/{types/preset → preset}/quick.d.ts +1 -1
- package/dist/preset/quick.js +0 -4
- package/dist/{types/preset → preset}/tiny.d.ts +1 -1
- package/dist/preset/tiny.js +0 -4
- package/dist/{types/request.d.ts → request.d.ts} +3 -48
- package/dist/request.js +0 -205
- package/dist/router/linear-router/router.js +19 -13
- package/dist/router/pattern-router/router.js +3 -3
- package/dist/router/reg-exp-router/node.js +9 -11
- package/dist/router/reg-exp-router/trie.js +0 -5
- package/dist/router/trie-router/node.js +5 -5
- package/dist/router.js +0 -19
- package/dist/{types/types.d.ts → types.d.ts} +33 -2
- package/dist/utils/body.js +0 -30
- package/dist/utils/buffer.d.ts +11 -0
- package/dist/utils/buffer.js +1 -12
- package/dist/utils/color.d.ts +16 -0
- package/dist/utils/color.js +4 -33
- package/dist/utils/compress.js +0 -7
- package/dist/utils/concurrent.js +0 -4
- package/dist/utils/constants.js +0 -3
- package/dist/utils/cookie.js +0 -4
- package/dist/utils/encode.js +0 -4
- package/dist/utils/handler.js +0 -4
- package/dist/utils/html.js +0 -4
- package/dist/{types/utils → utils}/http-status.d.ts +1 -9
- package/dist/utils/ipaddr.js +0 -39
- package/dist/utils/jwt/index.js +0 -4
- package/dist/utils/jwt/jwa.js +0 -5
- package/dist/utils/jwt/jws.js +0 -5
- package/dist/utils/jwt/jwt.js +0 -5
- package/dist/utils/jwt/types.js +0 -4
- package/dist/utils/jwt/utf8.js +0 -4
- package/dist/utils/mime.js +0 -4
- package/dist/utils/stream.js +0 -14
- package/dist/{types/utils → utils}/url.d.ts +0 -5
- package/dist/utils/url.js +1 -30
- package/dist/{types/validator → validator}/validator.d.ts +5 -0
- package/dist/validator/validator.js +42 -49
- package/package.json +142 -488
- package/dist/adapter/aws-lambda/conninfo.js +0 -43
- package/dist/adapter/aws-lambda/handler.js +0 -342
- package/dist/adapter/aws-lambda/index.js +0 -3
- package/dist/adapter/aws-lambda/types.js +0 -1
- package/dist/adapter/bun/conninfo.js +0 -22
- package/dist/adapter/bun/index.js +0 -6
- package/dist/adapter/bun/serve-static.js +0 -30
- package/dist/adapter/bun/server.js +0 -11
- package/dist/adapter/bun/ssg.js +0 -27
- package/dist/adapter/bun/websocket.js +0 -66
- package/dist/adapter/cloudflare-pages/conninfo.js +0 -24
- package/dist/adapter/cloudflare-pages/handler.js +0 -64
- package/dist/adapter/cloudflare-pages/index.js +0 -3
- package/dist/adapter/cloudflare-workers/conninfo.js +0 -7
- package/dist/adapter/cloudflare-workers/index.js +0 -4
- package/dist/adapter/cloudflare-workers/serve-static-module.js +0 -7
- package/dist/adapter/cloudflare-workers/serve-static.js +0 -28
- package/dist/adapter/cloudflare-workers/utils.js +0 -22
- package/dist/adapter/cloudflare-workers/websocket.js +0 -33
- package/dist/adapter/deno/conninfo.js +0 -17
- package/dist/adapter/deno/deno.d.js +0 -1
- package/dist/adapter/deno/index.js +0 -5
- package/dist/adapter/deno/serve-static.js +0 -35
- package/dist/adapter/deno/ssg.js +0 -29
- package/dist/adapter/deno/websocket.js +0 -32
- package/dist/adapter/lambda-edge/conninfo.js +0 -7
- package/dist/adapter/lambda-edge/handler.js +0 -111
- package/dist/adapter/lambda-edge/index.js +0 -3
- package/dist/adapter/netlify/conninfo.js +0 -24
- package/dist/adapter/netlify/handler.js +0 -11
- package/dist/adapter/netlify/index.js +0 -3
- package/dist/adapter/netlify/mod.js +0 -3
- package/dist/adapter/service-worker/handler.js +0 -16
- package/dist/adapter/service-worker/index.js +0 -25
- package/dist/adapter/service-worker/types.js +0 -1
- package/dist/adapter/vercel/conninfo.js +0 -7
- package/dist/adapter/vercel/handler.js +0 -9
- package/dist/adapter/vercel/index.js +0 -3
- package/dist/cjs/_virtual/_rolldown/runtime.js +0 -33
- package/dist/cjs/adapter/aws-lambda/conninfo.js +0 -44
- package/dist/cjs/adapter/aws-lambda/handler.js +0 -352
- package/dist/cjs/adapter/aws-lambda/index.js +0 -7
- package/dist/cjs/adapter/aws-lambda/types.js +0 -0
- package/dist/cjs/adapter/bun/conninfo.js +0 -23
- package/dist/cjs/adapter/bun/index.js +0 -14
- package/dist/cjs/adapter/bun/serve-static.js +0 -31
- package/dist/cjs/adapter/bun/server.js +0 -12
- package/dist/cjs/adapter/bun/ssg.js +0 -29
- package/dist/cjs/adapter/bun/websocket.js +0 -70
- package/dist/cjs/adapter/cloudflare-pages/conninfo.js +0 -25
- package/dist/cjs/adapter/cloudflare-pages/handler.js +0 -67
- package/dist/cjs/adapter/cloudflare-pages/index.js +0 -7
- package/dist/cjs/adapter/cloudflare-workers/conninfo.js +0 -8
- package/dist/cjs/adapter/cloudflare-workers/index.js +0 -7
- package/dist/cjs/adapter/cloudflare-workers/serve-static-module.js +0 -8
- package/dist/cjs/adapter/cloudflare-workers/serve-static.js +0 -29
- package/dist/cjs/adapter/cloudflare-workers/utils.js +0 -23
- package/dist/cjs/adapter/cloudflare-workers/websocket.js +0 -34
- package/dist/cjs/adapter/deno/conninfo.js +0 -18
- package/dist/cjs/adapter/deno/deno.d.js +0 -0
- package/dist/cjs/adapter/deno/index.js +0 -10
- package/dist/cjs/adapter/deno/serve-static.js +0 -36
- package/dist/cjs/adapter/deno/ssg.js +0 -31
- package/dist/cjs/adapter/deno/websocket.js +0 -33
- package/dist/cjs/adapter/lambda-edge/conninfo.js +0 -8
- package/dist/cjs/adapter/lambda-edge/handler.js +0 -116
- package/dist/cjs/adapter/lambda-edge/index.js +0 -5
- package/dist/cjs/adapter/netlify/conninfo.js +0 -25
- package/dist/cjs/adapter/netlify/handler.js +0 -12
- package/dist/cjs/adapter/netlify/index.js +0 -5
- package/dist/cjs/adapter/netlify/mod.js +0 -5
- package/dist/cjs/adapter/service-worker/handler.js +0 -17
- package/dist/cjs/adapter/service-worker/index.js +0 -27
- package/dist/cjs/adapter/service-worker/types.js +0 -0
- package/dist/cjs/adapter/vercel/conninfo.js +0 -8
- package/dist/cjs/adapter/vercel/handler.js +0 -10
- package/dist/cjs/adapter/vercel/index.js +0 -5
- package/dist/cjs/client/client.js +0 -145
- package/dist/cjs/client/fetch-result-please.js +0 -67
- package/dist/cjs/client/index.js +0 -7
- package/dist/cjs/client/types.js +0 -0
- package/dist/cjs/client/utils.js +0 -70
- package/dist/cjs/compose.js +0 -51
- package/dist/cjs/context.js +0 -383
- package/dist/cjs/helper/accepts/accepts.js +0 -54
- package/dist/cjs/helper/accepts/index.js +0 -3
- package/dist/cjs/helper/adapter/index.js +0 -41
- package/dist/cjs/helper/conninfo/index.js +0 -0
- package/dist/cjs/helper/conninfo/types.js +0 -0
- package/dist/cjs/helper/cookie/index.js +0 -89
- package/dist/cjs/helper/css/common.js +0 -194
- package/dist/cjs/helper/css/index.js +0 -142
- package/dist/cjs/helper/dev/index.js +0 -53
- package/dist/cjs/helper/factory/index.js +0 -33
- package/dist/cjs/helper/html/index.js +0 -34
- package/dist/cjs/helper/proxy/index.js +0 -122
- package/dist/cjs/helper/route/index.js +0 -128
- package/dist/cjs/helper/ssg/index.js +0 -19
- package/dist/cjs/helper/ssg/middleware.js +0 -65
- package/dist/cjs/helper/ssg/plugins.js +0 -68
- package/dist/cjs/helper/ssg/ssg.js +0 -220
- package/dist/cjs/helper/ssg/utils.js +0 -70
- package/dist/cjs/helper/streaming/index.js +0 -8
- package/dist/cjs/helper/streaming/sse.js +0 -59
- package/dist/cjs/helper/streaming/stream.js +0 -26
- package/dist/cjs/helper/streaming/text.js +0 -12
- package/dist/cjs/helper/streaming/utils.js +0 -16
- package/dist/cjs/helper/testing/index.js +0 -18
- package/dist/cjs/helper/websocket/index.js +0 -56
- package/dist/cjs/hono-base.js +0 -351
- package/dist/cjs/hono.js +0 -29
- package/dist/cjs/http-exception.js +0 -56
- package/dist/cjs/index.js +0 -22
- package/dist/cjs/jsx/base.js +0 -266
- package/dist/cjs/jsx/children.js +0 -19
- package/dist/cjs/jsx/components.js +0 -147
- package/dist/cjs/jsx/constants.js +0 -15
- package/dist/cjs/jsx/context.js +0 -170
- package/dist/cjs/jsx/dom/client.js +0 -56
- package/dist/cjs/jsx/dom/components.js +0 -26
- package/dist/cjs/jsx/dom/context.js +0 -43
- package/dist/cjs/jsx/dom/css.js +0 -153
- package/dist/cjs/jsx/dom/hooks/index.js +0 -65
- package/dist/cjs/jsx/dom/index.js +0 -122
- package/dist/cjs/jsx/dom/intrinsic-element/components.js +0 -306
- package/dist/cjs/jsx/dom/jsx-dev-runtime.js +0 -17
- package/dist/cjs/jsx/dom/jsx-runtime.js +0 -5
- package/dist/cjs/jsx/dom/render.js +0 -525
- package/dist/cjs/jsx/dom/server.js +0 -44
- package/dist/cjs/jsx/dom/utils.js +0 -9
- package/dist/cjs/jsx/hooks/index.js +0 -280
- package/dist/cjs/jsx/index.js +0 -89
- package/dist/cjs/jsx/intrinsic-element/common.js +0 -27
- package/dist/cjs/jsx/intrinsic-element/components.js +0 -138
- package/dist/cjs/jsx/intrinsic-elements.js +0 -0
- package/dist/cjs/jsx/jsx-dev-runtime.js +0 -16
- package/dist/cjs/jsx/jsx-runtime.js +0 -37
- package/dist/cjs/jsx/streaming.js +0 -135
- package/dist/cjs/jsx/types.js +0 -0
- package/dist/cjs/jsx/utils.js +0 -116
- package/dist/cjs/middleware/basic-auth/index.js +0 -100
- package/dist/cjs/middleware/bearer-auth/index.js +0 -97
- package/dist/cjs/middleware/body-limit/index.js +0 -69
- package/dist/cjs/middleware/cache/index.js +0 -173
- package/dist/cjs/middleware/combine/index.js +0 -141
- package/dist/cjs/middleware/compress/index.js +0 -82
- package/dist/cjs/middleware/context-storage/index.js +0 -55
- package/dist/cjs/middleware/cors/index.js +0 -109
- package/dist/cjs/middleware/csrf/index.js +0 -106
- package/dist/cjs/middleware/etag/digest.js +0 -62
- package/dist/cjs/middleware/etag/index.js +0 -79
- package/dist/cjs/middleware/ip-restriction/index.js +0 -168
- package/dist/cjs/middleware/jsx-renderer/index.js +0 -104
- package/dist/cjs/middleware/jwk/index.js +0 -3
- package/dist/cjs/middleware/jwk/jwk.js +0 -122
- package/dist/cjs/middleware/jwt/index.js +0 -9
- package/dist/cjs/middleware/jwt/jwt.js +0 -124
- package/dist/cjs/middleware/language/index.js +0 -7
- package/dist/cjs/middleware/language/language.js +0 -208
- package/dist/cjs/middleware/logger/index.js +0 -51
- package/dist/cjs/middleware/method-not-allowed/index.js +0 -84
- package/dist/cjs/middleware/method-override/index.js +0 -105
- package/dist/cjs/middleware/mount/index.js +0 -71
- package/dist/cjs/middleware/powered-by/index.js +0 -25
- package/dist/cjs/middleware/pretty-json/index.js +0 -41
- package/dist/cjs/middleware/request-id/index.js +0 -3
- package/dist/cjs/middleware/request-id/request-id.js +0 -35
- package/dist/cjs/middleware/secure-headers/index.js +0 -4
- package/dist/cjs/middleware/secure-headers/permissions-policy.js +0 -0
- package/dist/cjs/middleware/secure-headers/secure-headers.js +0 -166
- package/dist/cjs/middleware/serve-static/index.js +0 -62
- package/dist/cjs/middleware/serve-static/path.js +0 -17
- package/dist/cjs/middleware/timeout/index.js +0 -42
- package/dist/cjs/middleware/timing/index.js +0 -7
- package/dist/cjs/middleware/timing/timing.js +0 -189
- package/dist/cjs/middleware/trailing-slash/index.js +0 -89
- package/dist/cjs/package.json +0 -3
- package/dist/cjs/preset/quick.js +0 -19
- package/dist/cjs/preset/tiny.js +0 -16
- package/dist/cjs/request/constants.js +0 -5
- package/dist/cjs/request.js +0 -337
- package/dist/cjs/router/linear-router/index.js +0 -3
- package/dist/cjs/router/linear-router/router.js +0 -97
- package/dist/cjs/router/pattern-router/index.js +0 -3
- package/dist/cjs/router/pattern-router/router.js +0 -42
- package/dist/cjs/router/reg-exp-router/index.js +0 -7
- package/dist/cjs/router/reg-exp-router/matcher.js +0 -21
- package/dist/cjs/router/reg-exp-router/node.js +0 -96
- package/dist/cjs/router/reg-exp-router/prepared-router.js +0 -97
- package/dist/cjs/router/reg-exp-router/router.js +0 -102
- package/dist/cjs/router/reg-exp-router/trie.js +0 -74
- package/dist/cjs/router/smart-router/index.js +0 -3
- package/dist/cjs/router/smart-router/router.js +0 -50
- package/dist/cjs/router/trie-router/index.js +0 -3
- package/dist/cjs/router/trie-router/node.js +0 -135
- package/dist/cjs/router/trie-router/router.js +0 -16
- package/dist/cjs/router/utils.js +0 -5
- package/dist/cjs/router.js +0 -40
- package/dist/cjs/types.js +0 -5
- package/dist/cjs/utils/accept.js +0 -194
- package/dist/cjs/utils/basic-auth.js +0 -21
- package/dist/cjs/utils/body.js +0 -97
- package/dist/cjs/utils/buffer.js +0 -55
- package/dist/cjs/utils/color.js +0 -39
- package/dist/cjs/utils/compress.js +0 -12
- package/dist/cjs/utils/concurrent.js +0 -31
- package/dist/cjs/utils/constants.js +0 -8
- package/dist/cjs/utils/cookie.js +0 -129
- package/dist/cjs/utils/crypto.js +0 -38
- package/dist/cjs/utils/encode.js +0 -37
- package/dist/cjs/utils/filepath.js +0 -27
- package/dist/cjs/utils/handler.js +0 -14
- package/dist/cjs/utils/headers.js +0 -0
- package/dist/cjs/utils/html.js +0 -109
- package/dist/cjs/utils/http-status.js +0 -0
- package/dist/cjs/utils/ipaddr.js +0 -247
- package/dist/cjs/utils/jwt/index.js +0 -15
- package/dist/cjs/utils/jwt/jwa.js +0 -25
- package/dist/cjs/utils/jwt/jws.js +0 -135
- package/dist/cjs/utils/jwt/jwt.js +0 -136
- package/dist/cjs/utils/jwt/types.js +0 -124
- package/dist/cjs/utils/jwt/utf8.js +0 -11
- package/dist/cjs/utils/mime.js +0 -80
- package/dist/cjs/utils/stream.js +0 -89
- package/dist/cjs/utils/types.js +0 -0
- package/dist/cjs/utils/url.js +0 -215
- package/dist/cjs/validator/index.js +0 -3
- package/dist/cjs/validator/utils.js +0 -0
- package/dist/cjs/validator/validator.js +0 -65
- package/dist/types/adapter/aws-lambda/conninfo.d.ts +0 -30
- package/dist/types/adapter/aws-lambda/handler.d.ts +0 -230
- package/dist/types/adapter/aws-lambda/index.d.ts +0 -4
- package/dist/types/adapter/aws-lambda/types.d.ts +0 -183
- package/dist/types/adapter/bun/conninfo.d.ts +0 -10
- package/dist/types/adapter/bun/index.d.ts +0 -6
- package/dist/types/adapter/bun/serve-static.d.ts +0 -8
- package/dist/types/adapter/bun/server.d.ts +0 -11
- package/dist/types/adapter/bun/ssg.d.ts +0 -17
- package/dist/types/adapter/bun/websocket.d.ts +0 -54
- package/dist/types/adapter/cloudflare-pages/conninfo.d.ts +0 -24
- package/dist/types/adapter/cloudflare-pages/handler.d.ts +0 -45
- package/dist/types/adapter/cloudflare-pages/index.d.ts +0 -3
- package/dist/types/adapter/cloudflare-workers/conninfo.d.ts +0 -7
- package/dist/types/adapter/cloudflare-workers/index.d.ts +0 -4
- package/dist/types/adapter/cloudflare-workers/serve-static-module.d.ts +0 -7
- package/dist/types/adapter/cloudflare-workers/serve-static.d.ts +0 -21
- package/dist/types/adapter/cloudflare-workers/utils.d.ts +0 -13
- package/dist/types/adapter/cloudflare-workers/websocket.d.ts +0 -7
- package/dist/types/adapter/deno/conninfo.d.ts +0 -10
- package/dist/types/adapter/deno/deno.d.ts +0 -1
- package/dist/types/adapter/deno/index.d.ts +0 -5
- package/dist/types/adapter/deno/serve-static.d.ts +0 -8
- package/dist/types/adapter/deno/ssg.d.ts +0 -17
- package/dist/types/adapter/deno/websocket.d.ts +0 -7
- package/dist/types/adapter/lambda-edge/conninfo.d.ts +0 -7
- package/dist/types/adapter/lambda-edge/handler.d.ts +0 -113
- package/dist/types/adapter/lambda-edge/index.d.ts +0 -3
- package/dist/types/adapter/netlify/conninfo.d.ts +0 -24
- package/dist/types/adapter/netlify/handler.d.ts +0 -7
- package/dist/types/adapter/netlify/index.d.ts +0 -3
- package/dist/types/adapter/netlify/mod.d.ts +0 -3
- package/dist/types/adapter/service-worker/handler.d.ts +0 -18
- package/dist/types/adapter/service-worker/index.d.ts +0 -26
- package/dist/types/adapter/service-worker/types.d.ts +0 -17
- package/dist/types/adapter/vercel/conninfo.d.ts +0 -7
- package/dist/types/adapter/vercel/handler.d.ts +0 -7
- package/dist/types/adapter/vercel/index.d.ts +0 -3
- package/dist/types/package.json +0 -3
- package/dist/types/utils/buffer.d.ts +0 -19
- package/dist/types/utils/color.d.ts +0 -23
- package/dist/{types/client → client}/client.d.ts +0 -0
- package/dist/{types/client → client}/fetch-result-please.d.ts +0 -0
- package/dist/{types/client → client}/index.d.ts +0 -0
- package/dist/{types/client → client}/types.d.ts +1 -1
- /package/dist/{types/client → client}/utils.d.ts +0 -0
- /package/dist/{types/helper → helper}/accepts/accepts.d.ts +0 -0
- /package/dist/{types/helper → helper}/accepts/index.d.ts +0 -0
- /package/dist/{types/helper → helper}/adapter/index.d.ts +0 -0
- /package/dist/{types/helper → helper}/conninfo/index.d.ts +0 -0
- /package/dist/{types/helper → helper}/conninfo/types.d.ts +0 -0
- /package/dist/{types/helper → helper}/cookie/index.d.ts +0 -0
- /package/dist/{types/helper → helper}/css/common.d.ts +0 -0
- /package/dist/{types/helper → helper}/css/index.d.ts +0 -0
- /package/dist/{types/helper → helper}/html/index.d.ts +0 -0
- /package/dist/{types/helper → helper}/proxy/index.d.ts +0 -0
- /package/dist/{types/helper → helper}/route/index.d.ts +0 -0
- /package/dist/{types/helper → helper}/ssg/index.d.ts +0 -0
- /package/dist/{types/helper → helper}/ssg/plugins.d.ts +0 -0
- /package/dist/{types/helper → helper}/ssg/utils.d.ts +0 -0
- /package/dist/{types/helper → helper}/streaming/index.d.ts +0 -0
- /package/dist/{types/helper → helper}/streaming/sse.d.ts +0 -0
- /package/dist/{types/helper → helper}/streaming/stream.d.ts +0 -0
- /package/dist/{types/helper → helper}/streaming/text.d.ts +0 -0
- /package/dist/{types/helper → helper}/streaming/utils.d.ts +0 -0
- /package/dist/{types/helper → helper}/testing/index.d.ts +0 -0
- /package/dist/{types/helper → helper}/websocket/index.d.ts +0 -0
- /package/dist/{types/http-exception.d.ts → http-exception.d.ts} +0 -0
- /package/dist/{types/index.d.ts → index.d.ts} +0 -0
- /package/dist/{types/jsx → jsx}/base.d.ts +0 -0
- /package/dist/{types/jsx → jsx}/children.d.ts +0 -0
- /package/dist/{types/jsx → jsx}/components.d.ts +0 -0
- /package/dist/{types/jsx → jsx}/constants.d.ts +0 -0
- /package/dist/{types/jsx → jsx}/context.d.ts +0 -0
- /package/dist/{types/jsx → jsx}/dom/client.d.ts +0 -0
- /package/dist/{types/jsx → jsx}/dom/components.d.ts +0 -0
- /package/dist/{types/jsx → jsx}/dom/context.d.ts +0 -0
- /package/dist/{types/jsx → jsx}/dom/css.d.ts +0 -0
- /package/dist/{types/jsx → jsx}/dom/hooks/index.d.ts +0 -0
- /package/dist/{types/jsx → jsx}/dom/index.d.ts +0 -0
- /package/dist/{types/jsx → jsx}/dom/intrinsic-element/components.d.ts +0 -0
- /package/dist/{types/jsx → jsx}/dom/jsx-dev-runtime.d.ts +0 -0
- /package/dist/{types/jsx → jsx}/dom/jsx-runtime.d.ts +0 -0
- /package/dist/{types/jsx → jsx}/dom/render.d.ts +0 -0
- /package/dist/{types/jsx → jsx}/dom/server.d.ts +0 -0
- /package/dist/{types/jsx → jsx}/dom/utils.d.ts +0 -0
- /package/dist/{types/jsx → jsx}/hooks/index.d.ts +0 -0
- /package/dist/{types/jsx → jsx}/index.d.ts +0 -0
- /package/dist/{types/jsx → jsx}/intrinsic-element/common.d.ts +0 -0
- /package/dist/{types/jsx → jsx}/intrinsic-element/components.d.ts +0 -0
- /package/dist/{types/jsx → jsx}/intrinsic-elements.d.ts +0 -0
- /package/dist/{types/jsx → jsx}/jsx-dev-runtime.d.ts +0 -0
- /package/dist/{types/jsx → jsx}/jsx-runtime.d.ts +0 -0
- /package/dist/{types/jsx → jsx}/streaming.d.ts +0 -0
- /package/dist/{types/jsx → jsx}/types.d.ts +0 -0
- /package/dist/{types/jsx → jsx}/utils.d.ts +0 -0
- /package/dist/{types/middleware → middleware}/body-limit/index.d.ts +0 -0
- /package/dist/{types/middleware → middleware}/cache/index.d.ts +0 -0
- /package/dist/{types/middleware → middleware}/combine/index.d.ts +0 -0
- /package/dist/{types/middleware → middleware}/compress/index.d.ts +0 -0
- /package/dist/{types/middleware → middleware}/context-storage/index.d.ts +0 -0
- /package/dist/{types/middleware → middleware}/cors/index.d.ts +0 -0
- /package/dist/{types/middleware → middleware}/csrf/index.d.ts +0 -0
- /package/dist/{types/middleware → middleware}/etag/digest.d.ts +0 -0
- /package/dist/{types/middleware → middleware}/etag/index.d.ts +0 -0
- /package/dist/{types/middleware → middleware}/ip-restriction/index.d.ts +0 -0
- /package/dist/{types/middleware → middleware}/jsx-renderer/index.d.ts +0 -0
- /package/dist/{types/middleware → middleware}/jwk/index.d.ts +0 -0
- /package/dist/{types/middleware → middleware}/jwk/jwk.d.ts +0 -0
- /package/dist/{types/middleware → middleware}/jwt/index.d.ts +0 -0
- /package/dist/{types/middleware → middleware}/jwt/jwt.d.ts +0 -0
- /package/dist/{types/middleware → middleware}/language/index.d.ts +0 -0
- /package/dist/{types/middleware → middleware}/language/language.d.ts +0 -0
- /package/dist/{types/middleware → middleware}/logger/index.d.ts +0 -0
- /package/dist/{types/middleware → middleware}/method-not-allowed/index.d.ts +0 -0
- /package/dist/{types/middleware → middleware}/method-override/index.d.ts +0 -0
- /package/dist/{types/middleware → middleware}/mount/index.d.ts +0 -0
- /package/dist/{types/middleware → middleware}/powered-by/index.d.ts +0 -0
- /package/dist/{types/middleware → middleware}/pretty-json/index.d.ts +0 -0
- /package/dist/{types/middleware → middleware}/request-id/index.d.ts +0 -0
- /package/dist/{types/middleware → middleware}/request-id/request-id.d.ts +0 -0
- /package/dist/{types/middleware → middleware}/secure-headers/index.d.ts +0 -0
- /package/dist/{types/middleware → middleware}/secure-headers/permissions-policy.d.ts +0 -0
- /package/dist/{types/middleware → middleware}/secure-headers/secure-headers.d.ts +0 -0
- /package/dist/{types/middleware → middleware}/serve-static/path.d.ts +0 -0
- /package/dist/{types/middleware → middleware}/timeout/index.d.ts +0 -0
- /package/dist/{types/middleware → middleware}/timing/index.d.ts +0 -0
- /package/dist/{types/middleware → middleware}/timing/timing.d.ts +0 -0
- /package/dist/{types/middleware → middleware}/trailing-slash/index.d.ts +0 -0
- /package/dist/{types/request → request}/constants.d.ts +0 -0
- /package/dist/{types/router → router}/linear-router/index.d.ts +0 -0
- /package/dist/{types/router → router}/linear-router/router.d.ts +0 -0
- /package/dist/{types/router → router}/pattern-router/index.d.ts +0 -0
- /package/dist/{types/router → router}/pattern-router/router.d.ts +0 -0
- /package/dist/{types/router → router}/reg-exp-router/index.d.ts +0 -0
- /package/dist/{types/router → router}/reg-exp-router/matcher.d.ts +0 -0
- /package/dist/{types/router → router}/reg-exp-router/node.d.ts +0 -0
- /package/dist/{types/router → router}/reg-exp-router/prepared-router.d.ts +0 -0
- /package/dist/{types/router → router}/reg-exp-router/router.d.ts +0 -0
- /package/dist/{types/router → router}/reg-exp-router/trie.d.ts +0 -0
- /package/dist/{types/router → router}/smart-router/index.d.ts +0 -0
- /package/dist/{types/router → router}/smart-router/router.d.ts +0 -0
- /package/dist/{types/router → router}/trie-router/index.d.ts +0 -0
- /package/dist/{types/router → router}/trie-router/node.d.ts +0 -0
- /package/dist/{types/router → router}/trie-router/router.d.ts +0 -0
- /package/dist/{types/router → router}/utils.d.ts +0 -0
- /package/dist/{types/router.d.ts → router.d.ts} +0 -0
- /package/dist/{types/utils → utils}/accept.d.ts +0 -0
- /package/dist/{types/utils → utils}/basic-auth.d.ts +0 -0
- /package/dist/{types/utils → utils}/body.d.ts +0 -0
- /package/dist/{types/utils → utils}/compress.d.ts +0 -0
- /package/dist/{types/utils → utils}/concurrent.d.ts +0 -0
- /package/dist/{types/utils → utils}/constants.d.ts +0 -0
- /package/dist/{types/utils → utils}/cookie.d.ts +0 -0
- /package/dist/{types/utils → utils}/crypto.d.ts +0 -0
- /package/dist/{types/utils → utils}/encode.d.ts +0 -0
- /package/dist/{types/utils → utils}/filepath.d.ts +0 -0
- /package/dist/{types/utils → utils}/handler.d.ts +0 -0
- /package/dist/{types/utils → utils}/headers.d.ts +0 -0
- /package/dist/{types/utils → utils}/html.d.ts +0 -0
- /package/dist/{types/utils → utils}/ipaddr.d.ts +0 -0
- /package/dist/{types/utils → utils}/jwt/index.d.ts +0 -0
- /package/dist/{types/utils → utils}/jwt/jwa.d.ts +0 -0
- /package/dist/{types/utils → utils}/jwt/jws.d.ts +0 -0
- /package/dist/{types/utils → utils}/jwt/jwt.d.ts +0 -0
- /package/dist/{types/utils → utils}/jwt/types.d.ts +0 -0
- /package/dist/{types/utils → utils}/jwt/utf8.d.ts +0 -0
- /package/dist/{types/utils → utils}/mime.d.ts +0 -0
- /package/dist/{types/utils → utils}/stream.d.ts +0 -0
- /package/dist/{types/utils → utils}/types.d.ts +0 -0
- /package/dist/{types/validator → validator}/index.d.ts +0 -0
- /package/dist/{types/validator → validator}/utils.d.ts +0 -0
package/dist/helper/ssg/ssg.js
CHANGED
|
@@ -70,11 +70,6 @@ const combineAfterGenerateHooks = (hooks, fsModule, options) => {
|
|
|
70
70
|
for (const hook of hooks) await hook(result, fsModule, options);
|
|
71
71
|
};
|
|
72
72
|
};
|
|
73
|
-
/**
|
|
74
|
-
* @experimental
|
|
75
|
-
* `fetchRoutesContent` is an experimental feature.
|
|
76
|
-
* The API might be changed.
|
|
77
|
-
*/
|
|
78
73
|
const fetchRoutesContent = function* (app, beforeRequestHook, afterResponseHook, concurrency) {
|
|
79
74
|
const baseURL = "http://localhost";
|
|
80
75
|
const pool = createPool({ concurrency });
|
|
@@ -136,11 +131,6 @@ const fetchRoutesContent = function* (app, beforeRequestHook, afterResponseHook,
|
|
|
136
131
|
});
|
|
137
132
|
}
|
|
138
133
|
};
|
|
139
|
-
/**
|
|
140
|
-
* @experimental
|
|
141
|
-
* `saveContentToFile` is an experimental feature.
|
|
142
|
-
* The API might be changed.
|
|
143
|
-
*/
|
|
144
134
|
const createdDirs = /* @__PURE__ */ new Set();
|
|
145
135
|
const saveContentToFile = async (data, fsModule, outDir, extensionMap) => {
|
|
146
136
|
const awaitedData = await data;
|
|
@@ -156,11 +146,6 @@ const saveContentToFile = async (data, fsModule, outDir, extensionMap) => {
|
|
|
156
146
|
else if (content instanceof ArrayBuffer) await fsModule.writeFile(filePath, new Uint8Array(content));
|
|
157
147
|
return filePath;
|
|
158
148
|
};
|
|
159
|
-
/**
|
|
160
|
-
* @experimental
|
|
161
|
-
* `toSSG` is an experimental feature.
|
|
162
|
-
* The API might be changed.
|
|
163
|
-
*/
|
|
164
149
|
const toSSG = async (app, fs, options) => {
|
|
165
150
|
let result;
|
|
166
151
|
const getInfoPromises = [];
|
|
@@ -169,9 +154,6 @@ const toSSG = async (app, fs, options) => {
|
|
|
169
154
|
const beforeRequestHooks = [];
|
|
170
155
|
const afterResponseHooks = [];
|
|
171
156
|
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
157
|
for (const plugin of plugins) {
|
|
176
158
|
if (plugin.beforeRequestHook) beforeRequestHooks.push(...Array.isArray(plugin.beforeRequestHook) ? plugin.beforeRequestHook : [plugin.beforeRequestHook]);
|
|
177
159
|
if (plugin.afterResponseHook) afterResponseHooks.push(...Array.isArray(plugin.afterResponseHook) ? plugin.afterResponseHook : [plugin.afterResponseHook]);
|
package/dist/helper/ssg/utils.js
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import "../../router.js";
|
|
2
2
|
import { findTargetHandler, isMiddleware } from "../../utils/handler.js";
|
|
3
3
|
//#region src/helper/ssg/utils.ts
|
|
4
|
-
/**
|
|
5
|
-
* Get dirname
|
|
6
|
-
* @param path File Path
|
|
7
|
-
* @returns Parent dir path
|
|
8
|
-
*/
|
|
9
4
|
const dirname = (path) => {
|
|
10
5
|
return path.split(/[\/\\]/).slice(0, -1).join("/");
|
|
11
6
|
};
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import { hc } from "../../client/client.js";
|
|
2
2
|
//#region src/helper/testing/index.ts
|
|
3
|
-
/**
|
|
4
|
-
* @module
|
|
5
|
-
* Testing Helper for Hono.
|
|
6
|
-
*/
|
|
7
3
|
const testClient = (app, Env, executionCtx, options) => {
|
|
8
4
|
const customFetch = (input, init) => {
|
|
9
5
|
return app.request(input, init, Env, executionCtx);
|
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
//#region src/helper/websocket/index.ts
|
|
2
|
-
/**
|
|
3
|
-
* A context for controlling WebSockets
|
|
4
|
-
*/
|
|
5
2
|
var WSContext = class {
|
|
6
3
|
#init;
|
|
7
4
|
constructor(init) {
|
|
@@ -27,9 +24,6 @@ var WSContext = class {
|
|
|
27
24
|
const createWSMessageEvent = (source) => {
|
|
28
25
|
return new MessageEvent("message", { data: source });
|
|
29
26
|
};
|
|
30
|
-
/**
|
|
31
|
-
* Create a WebSocket adapter/helper
|
|
32
|
-
*/
|
|
33
27
|
const defineWebSocketHelper = (handler) => {
|
|
34
28
|
return ((...args) => {
|
|
35
29
|
if (typeof args[0] === "function") {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Router } from "./router.js";
|
|
2
|
-
import { Env,
|
|
3
|
-
import {
|
|
2
|
+
import { Env, FallbackHandlerInterface, H, HandlerInterface, MergePath, MergeSchemaPath, MiddlewareHandlerInterface, OnHandlerInterface, RouterRoute, Schema } from "./types.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>;
|
|
@@ -65,12 +59,56 @@ declare class Hono<E extends Env = Env, S extends Schema = {}, BasePath extends
|
|
|
65
59
|
all: HandlerInterface<E, 'all', S, BasePath, CurrentPath>;
|
|
66
60
|
on: OnHandlerInterface<E, S, BasePath>;
|
|
67
61
|
use: MiddlewareHandlerInterface<E, S, BasePath>;
|
|
62
|
+
/**
|
|
63
|
+
* `.onError()` adds middleware that runs when an error is caught.
|
|
64
|
+
* Paths are relative to the current base path and default to `*`, for any HTTP method.
|
|
65
|
+
* The error is available as `c.error`. Matching middleware runs in registration order,
|
|
66
|
+
* with nested applications taking priority. If every middleware calls `next()`,
|
|
67
|
+
* the built-in error handler returns the response.
|
|
68
|
+
* Errors thrown by this middleware are handled by the built-in error handler.
|
|
69
|
+
* Non-Error values thrown by handlers are wrapped in an Error with the original value as its cause.
|
|
70
|
+
* If the thrown value is a string, it is also used as the error message.
|
|
71
|
+
* Request parameters come from the original route, not this scope, and may be absent.
|
|
72
|
+
*
|
|
73
|
+
* @param {string} [path] - path to scope the error middleware
|
|
74
|
+
* @param {...MiddlewareHandler[]} handlers - middleware to run when handling an error
|
|
75
|
+
* @returns {Hono} changed Hono instance
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* app.onError('/api/*', async (c, next) => {
|
|
80
|
+
* console.error(c.error)
|
|
81
|
+
* await next()
|
|
82
|
+
* })
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
onError: FallbackHandlerInterface<E, S, BasePath, CurrentPath>;
|
|
86
|
+
/**
|
|
87
|
+
* `.notFound()` adds middleware that runs when a not-found response is requested.
|
|
88
|
+
* It uses the same path scoping and ordering as `.onError()`, including for `c.notFound()`.
|
|
89
|
+
* If every matching middleware calls `next()`, the built-in not-found handler returns the response.
|
|
90
|
+
* Request parameters come from the original route, not this scope, and may be absent.
|
|
91
|
+
*
|
|
92
|
+
* @see {@link https://hono.dev/docs/api/hono#not-found}
|
|
93
|
+
*
|
|
94
|
+
* @param {string} [path] - path to scope the not-found middleware
|
|
95
|
+
* @param {...MiddlewareHandler[]} handlers - middleware to run when handling not found
|
|
96
|
+
* @returns {Hono} changed Hono instance
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```ts
|
|
100
|
+
* app.notFound('/api/*', async (c, next) => {
|
|
101
|
+
* c.header('x-not-found', 'true')
|
|
102
|
+
* await next()
|
|
103
|
+
* })
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
notFound: FallbackHandlerInterface<E, S, BasePath, CurrentPath>;
|
|
68
107
|
router: Router<[H, RouterRoute]>;
|
|
69
108
|
readonly getPath: GetPath<E>;
|
|
70
109
|
private _basePath;
|
|
71
110
|
routes: RouterRoute[];
|
|
72
111
|
constructor(options?: HonoOptions<E>);
|
|
73
|
-
private errorHandler;
|
|
74
112
|
/**
|
|
75
113
|
* `.route()` allows grouping other Hono instance in routes.
|
|
76
114
|
*
|
|
@@ -104,74 +142,6 @@ declare class Hono<E extends Env = Env, S extends Schema = {}, BasePath extends
|
|
|
104
142
|
* ```
|
|
105
143
|
*/
|
|
106
144
|
basePath<SubPath extends string>(path: SubPath): Hono<E, S, MergePath<BasePath, SubPath>, MergePath<BasePath, SubPath>>;
|
|
107
|
-
/**
|
|
108
|
-
* `.onError()` handles an error and returns a customized Response.
|
|
109
|
-
*
|
|
110
|
-
* @see {@link https://hono.dev/docs/api/hono#error-handling}
|
|
111
|
-
*
|
|
112
|
-
* @param {ErrorHandler} handler - request Handler for error
|
|
113
|
-
* @returns {Hono} changed Hono instance
|
|
114
|
-
*
|
|
115
|
-
* @example
|
|
116
|
-
* ```ts
|
|
117
|
-
* app.onError((err, c) => {
|
|
118
|
-
* console.error(`${err}`)
|
|
119
|
-
* return c.text('Custom Error Message', 500)
|
|
120
|
-
* })
|
|
121
|
-
* ```
|
|
122
|
-
*/
|
|
123
|
-
onError: (handler: ErrorHandler<E>) => Hono<E, S, BasePath, CurrentPath>;
|
|
124
|
-
/**
|
|
125
|
-
* `.notFound()` allows you to customize a Not Found Response.
|
|
126
|
-
*
|
|
127
|
-
* @see {@link https://hono.dev/docs/api/hono#not-found}
|
|
128
|
-
*
|
|
129
|
-
* @param {NotFoundHandler} handler - request handler for not-found
|
|
130
|
-
* @returns {Hono} changed Hono instance
|
|
131
|
-
*
|
|
132
|
-
* @example
|
|
133
|
-
* ```ts
|
|
134
|
-
* app.notFound((c) => {
|
|
135
|
-
* return c.text('Custom 404 Message', 404)
|
|
136
|
-
* })
|
|
137
|
-
* ```
|
|
138
|
-
*/
|
|
139
|
-
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
145
|
/**
|
|
176
146
|
* `.fetch()` will be entry point of your app.
|
|
177
147
|
*
|
|
@@ -197,24 +167,6 @@ declare class Hono<E extends Env = Env, S extends Schema = {}, BasePath extends
|
|
|
197
167
|
* @see https://hono.dev/docs/api/hono#request
|
|
198
168
|
*/
|
|
199
169
|
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
170
|
}
|
|
219
171
|
//#endregion
|
|
220
172
|
export { Hono as HonoBase };
|
package/dist/hono-base.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import { compose } from "./compose.js";
|
|
1
|
+
import { compose, toError } from "./compose.js";
|
|
2
|
+
import { GET_RESPONSE } from "./context/constants.js";
|
|
2
3
|
import { getPath, getPathNoStrict, mergePath } from "./utils/url.js";
|
|
3
4
|
import { Context } from "./context.js";
|
|
4
5
|
import { METHODS } from "./router.js";
|
|
5
|
-
import { COMPOSED_HANDLER } from "./utils/constants.js";
|
|
6
6
|
//#region src/hono-base.ts
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
* This module is the base module for the Hono object.
|
|
10
|
-
*/
|
|
7
|
+
const METHOD_NAME_NOT_FOUND = "@NOT_FOUND";
|
|
8
|
+
const METHOD_NAME_ERROR = "@ERROR";
|
|
11
9
|
const notFoundHandler = (c) => {
|
|
12
10
|
return c.text("404 Not Found", 404);
|
|
13
11
|
};
|
|
@@ -19,6 +17,15 @@ const errorHandler = (err, c) => {
|
|
|
19
17
|
console.error(err);
|
|
20
18
|
return c.text("Internal Server Error", 500);
|
|
21
19
|
};
|
|
20
|
+
const errorFallback = (c) => errorHandler(c.error, c);
|
|
21
|
+
const rethrow = (err) => {
|
|
22
|
+
throw err;
|
|
23
|
+
};
|
|
24
|
+
const byDepthDesc = (a, b) => b[0][1].depth - a[0][1].depth;
|
|
25
|
+
const getResponse = (context) => {
|
|
26
|
+
if (!context.finalized) throw new Error("Context is not finalized. Did you forget to return a Response object or `await next()`?");
|
|
27
|
+
return context.res;
|
|
28
|
+
};
|
|
22
29
|
var Hono = class Hono {
|
|
23
30
|
get;
|
|
24
31
|
post;
|
|
@@ -30,6 +37,8 @@ var Hono = class Hono {
|
|
|
30
37
|
all;
|
|
31
38
|
on;
|
|
32
39
|
use;
|
|
40
|
+
onError;
|
|
41
|
+
notFound;
|
|
33
42
|
router;
|
|
34
43
|
getPath;
|
|
35
44
|
_basePath = "/";
|
|
@@ -63,11 +72,11 @@ var Hono = class Hono {
|
|
|
63
72
|
this.#path = "*";
|
|
64
73
|
handlers.unshift(arg1);
|
|
65
74
|
}
|
|
66
|
-
handlers.forEach((handler) =>
|
|
67
|
-
this.#addRoute("ALL", this.#path, handler);
|
|
68
|
-
});
|
|
75
|
+
handlers.forEach((handler) => this.#addRoute("ALL", this.#path, handler));
|
|
69
76
|
return this;
|
|
70
77
|
};
|
|
78
|
+
this.onError = (...handlers) => this.#addRoutes(METHOD_NAME_ERROR, handlers);
|
|
79
|
+
this.notFound = (...handlers) => this.#addRoutes(METHOD_NAME_NOT_FOUND, handlers);
|
|
71
80
|
const { strict, ...optionsWithoutStrict } = options;
|
|
72
81
|
Object.assign(this, optionsWithoutStrict);
|
|
73
82
|
this.getPath = strict ?? true ? options.getPath ?? getPath : getPathNoStrict;
|
|
@@ -77,187 +86,67 @@ var Hono = class Hono {
|
|
|
77
86
|
router: this.router,
|
|
78
87
|
getPath: this.getPath
|
|
79
88
|
});
|
|
80
|
-
clone.errorHandler = this.errorHandler;
|
|
81
|
-
clone.#notFoundHandler = this.#notFoundHandler;
|
|
82
89
|
clone.routes = this.routes;
|
|
83
90
|
return clone;
|
|
84
91
|
}
|
|
85
|
-
#notFoundHandler = notFoundHandler;
|
|
86
|
-
errorHandler = errorHandler;
|
|
87
|
-
/**
|
|
88
|
-
* `.route()` allows grouping other Hono instance in routes.
|
|
89
|
-
*
|
|
90
|
-
* @see {@link https://hono.dev/docs/api/routing#grouping}
|
|
91
|
-
*
|
|
92
|
-
* @param {string} path - base Path
|
|
93
|
-
* @param {Hono} app - other Hono instance
|
|
94
|
-
* @returns {Hono} routed Hono instance
|
|
95
|
-
*
|
|
96
|
-
* @example
|
|
97
|
-
* ```ts
|
|
98
|
-
* const app = new Hono()
|
|
99
|
-
* const app2 = new Hono()
|
|
100
|
-
*
|
|
101
|
-
* app2.get("/user", (c) => c.text("user"))
|
|
102
|
-
* app.route("/api", app2) // GET /api/user
|
|
103
|
-
* ```
|
|
104
|
-
*/
|
|
105
92
|
route(path, app) {
|
|
106
93
|
const subApp = this.basePath(path);
|
|
107
|
-
app.routes.
|
|
108
|
-
let handler;
|
|
109
|
-
if (app.errorHandler === errorHandler) handler = r.handler;
|
|
110
|
-
else {
|
|
111
|
-
handler = async (c, next) => (await compose([], app.errorHandler)(c, () => r.handler(c, next))).res;
|
|
112
|
-
handler[COMPOSED_HANDLER] = r.handler;
|
|
113
|
-
}
|
|
114
|
-
subApp.#addRoute(r.method, r.path, handler, r.basePath);
|
|
115
|
-
});
|
|
94
|
+
app.routes.forEach((r) => subApp.#addRoute(r.method, r.path, r.handler, r));
|
|
116
95
|
return this;
|
|
117
96
|
}
|
|
118
|
-
/**
|
|
119
|
-
* `.basePath()` allows base paths to be specified.
|
|
120
|
-
*
|
|
121
|
-
* @see {@link https://hono.dev/docs/api/routing#base-path}
|
|
122
|
-
*
|
|
123
|
-
* @param {string} path - base Path
|
|
124
|
-
* @returns {Hono} changed Hono instance
|
|
125
|
-
*
|
|
126
|
-
* @example
|
|
127
|
-
* ```ts
|
|
128
|
-
* const api = new Hono().basePath('/api')
|
|
129
|
-
* ```
|
|
130
|
-
*/
|
|
131
97
|
basePath(path) {
|
|
132
98
|
const subApp = this.#clone();
|
|
133
99
|
subApp._basePath = mergePath(this._basePath, path);
|
|
134
100
|
return subApp;
|
|
135
101
|
}
|
|
136
|
-
|
|
137
|
-
* `.onError()` handles an error and returns a customized Response.
|
|
138
|
-
*
|
|
139
|
-
* @see {@link https://hono.dev/docs/api/hono#error-handling}
|
|
140
|
-
*
|
|
141
|
-
* @param {ErrorHandler} handler - request Handler for error
|
|
142
|
-
* @returns {Hono} changed Hono instance
|
|
143
|
-
*
|
|
144
|
-
* @example
|
|
145
|
-
* ```ts
|
|
146
|
-
* app.onError((err, c) => {
|
|
147
|
-
* console.error(`${err}`)
|
|
148
|
-
* return c.text('Custom Error Message', 500)
|
|
149
|
-
* })
|
|
150
|
-
* ```
|
|
151
|
-
*/
|
|
152
|
-
onError = (handler) => {
|
|
153
|
-
this.errorHandler = handler;
|
|
154
|
-
return this;
|
|
155
|
-
};
|
|
156
|
-
/**
|
|
157
|
-
* `.notFound()` allows you to customize a Not Found Response.
|
|
158
|
-
*
|
|
159
|
-
* @see {@link https://hono.dev/docs/api/hono#not-found}
|
|
160
|
-
*
|
|
161
|
-
* @param {NotFoundHandler} handler - request handler for not-found
|
|
162
|
-
* @returns {Hono} changed Hono instance
|
|
163
|
-
*
|
|
164
|
-
* @example
|
|
165
|
-
* ```ts
|
|
166
|
-
* app.notFound((c) => {
|
|
167
|
-
* return c.text('Custom 404 Message', 404)
|
|
168
|
-
* })
|
|
169
|
-
* ```
|
|
170
|
-
*/
|
|
171
|
-
notFound = (handler) => {
|
|
172
|
-
this.#notFoundHandler = handler;
|
|
173
|
-
return this;
|
|
174
|
-
};
|
|
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
|
-
#addRoute(method, path, handler, baseRoutePath) {
|
|
102
|
+
#addRoute(method, path, handler, baseRoute) {
|
|
248
103
|
path = mergePath(this._basePath, path);
|
|
249
104
|
const r = {
|
|
250
|
-
basePath:
|
|
105
|
+
basePath: mergePath(this._basePath, baseRoute?.basePath ?? "/"),
|
|
251
106
|
path,
|
|
252
107
|
method,
|
|
253
|
-
handler
|
|
108
|
+
handler,
|
|
109
|
+
depth: (baseRoute?.depth ?? -1) + 1
|
|
254
110
|
};
|
|
255
111
|
this.router.add(method, path, [handler, r]);
|
|
256
112
|
this.routes.push(r);
|
|
257
113
|
}
|
|
258
|
-
#
|
|
259
|
-
|
|
260
|
-
|
|
114
|
+
#addRoutes(method, handlers) {
|
|
115
|
+
const path = typeof handlers[0] === "string" ? handlers.shift() : "*";
|
|
116
|
+
handlers.forEach((handler) => this.#addRoute(method, path, handler));
|
|
117
|
+
return this;
|
|
118
|
+
}
|
|
119
|
+
#dispatchInternal(method, c) {
|
|
120
|
+
const handlers = this.router.match(method, c.req.path)[0].filter(([[, route]]) => route.method === method);
|
|
121
|
+
const fallback = method === METHOD_NAME_ERROR ? errorFallback : notFoundHandler;
|
|
122
|
+
if (!handlers.length) return fallback(c);
|
|
123
|
+
handlers.sort(byDepthDesc);
|
|
124
|
+
const res = c[GET_RESPONSE];
|
|
125
|
+
const finalized = c.finalized;
|
|
126
|
+
if (res?.status && !res.bodyUsed && !res.body?.locked) {
|
|
127
|
+
const mutableRes = new Response(res.body, res);
|
|
128
|
+
c.res = void 0;
|
|
129
|
+
c.res = mutableRes;
|
|
130
|
+
}
|
|
131
|
+
c.finalized = false;
|
|
132
|
+
const handleError = c.error ? rethrow : (err) => this.#handleError(err, c);
|
|
133
|
+
return compose(handlers, method === METHOD_NAME_ERROR ? errorHandler : handleError, fallback, false)(c).then(getResponse).catch(handleError).finally(() => {
|
|
134
|
+
c.res = void 0;
|
|
135
|
+
if (method !== METHOD_NAME_ERROR) c.res = res;
|
|
136
|
+
c.finalized = finalized;
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
#handleError = (err, c) => {
|
|
140
|
+
c.error = toError(err);
|
|
141
|
+
return this.#dispatchInternal(METHOD_NAME_ERROR, c);
|
|
142
|
+
};
|
|
143
|
+
#notFound = (c) => this.#dispatchInternal(METHOD_NAME_NOT_FOUND, c);
|
|
144
|
+
async #dispatchComposed(c, matchResult) {
|
|
145
|
+
try {
|
|
146
|
+
return getResponse(await compose(matchResult[0], this.#handleError, this.#notFound)(c));
|
|
147
|
+
} catch (err) {
|
|
148
|
+
return this.#handleError(err, c);
|
|
149
|
+
}
|
|
261
150
|
}
|
|
262
151
|
#dispatch(request, executionCtx, env, method) {
|
|
263
152
|
if (method === "HEAD") return (async () => new Response(null, await this.#dispatch(request, executionCtx, env, "GET")))();
|
|
@@ -268,83 +157,29 @@ var Hono = class Hono {
|
|
|
268
157
|
matchResult,
|
|
269
158
|
env,
|
|
270
159
|
executionCtx,
|
|
271
|
-
notFoundHandler: this.#
|
|
160
|
+
notFoundHandler: this.#notFound
|
|
272
161
|
});
|
|
273
162
|
if (matchResult[0].length === 1) {
|
|
274
163
|
let res;
|
|
275
164
|
try {
|
|
276
165
|
res = matchResult[0][0][0][0](c, async () => {
|
|
277
|
-
c.res = await this.#
|
|
166
|
+
c.res = await this.#notFound(c);
|
|
278
167
|
});
|
|
279
168
|
} catch (err) {
|
|
280
169
|
return this.#handleError(err, c);
|
|
281
170
|
}
|
|
282
|
-
return res instanceof Promise ? res.then((resolved) => resolved || (c.finalized ? c.res : this.#
|
|
171
|
+
return res instanceof Promise ? res.then((resolved) => resolved || (c.finalized ? c.res : this.#notFound(c))).catch((err) => this.#handleError(err, c)) : res ?? this.#notFound(c);
|
|
283
172
|
}
|
|
284
|
-
|
|
285
|
-
return (async () => {
|
|
286
|
-
try {
|
|
287
|
-
const context = await composed(c);
|
|
288
|
-
if (!context.finalized) throw new Error("Context is not finalized. Did you forget to return a Response object or `await next()`?");
|
|
289
|
-
return context.res;
|
|
290
|
-
} catch (err) {
|
|
291
|
-
return this.#handleError(err, c);
|
|
292
|
-
}
|
|
293
|
-
})();
|
|
173
|
+
return this.#dispatchComposed(c, matchResult);
|
|
294
174
|
}
|
|
295
|
-
/**
|
|
296
|
-
* `.fetch()` will be entry point of your app.
|
|
297
|
-
*
|
|
298
|
-
* @see {@link https://hono.dev/docs/api/hono#fetch}
|
|
299
|
-
*
|
|
300
|
-
* @param {Request} request - request Object of request
|
|
301
|
-
* @param {Env} env - env Object
|
|
302
|
-
* @param {ExecutionContext} executionCtx - context of execution
|
|
303
|
-
* @returns {Response | Promise<Response>} response of request
|
|
304
|
-
*
|
|
305
|
-
*/
|
|
306
175
|
fetch = (request, ...rest) => {
|
|
307
176
|
return this.#dispatch(request, rest[1], rest[0], request.method);
|
|
308
177
|
};
|
|
309
|
-
/**
|
|
310
|
-
* `.request()` is a useful method for testing.
|
|
311
|
-
* You can pass a URL or pathname to send a GET request.
|
|
312
|
-
* app will return a Response object.
|
|
313
|
-
* ```ts
|
|
314
|
-
* test('GET /hello is ok', async () => {
|
|
315
|
-
* const res = await app.request('/hello')
|
|
316
|
-
* expect(res.status).toBe(200)
|
|
317
|
-
* })
|
|
318
|
-
* ```
|
|
319
|
-
* @see https://hono.dev/docs/api/hono#request
|
|
320
|
-
*/
|
|
321
178
|
request = (input, requestInit, Env, executionCtx) => {
|
|
322
179
|
if (input instanceof Request) return this.fetch(requestInit ? new Request(input, requestInit) : input, Env, executionCtx);
|
|
323
180
|
input = input.toString();
|
|
324
181
|
return this.fetch(new Request(/^https?:\/\//.test(input) ? input : `http://localhost${mergePath("/", input)}`, requestInit), Env, executionCtx);
|
|
325
182
|
};
|
|
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
183
|
};
|
|
349
184
|
//#endregion
|
|
350
185
|
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.
|
package/dist/hono.js
CHANGED
|
@@ -5,20 +5,7 @@ import { SmartRouter } from "./router/smart-router/router.js";
|
|
|
5
5
|
import { TrieRouter } from "./router/trie-router/router.js";
|
|
6
6
|
import "./router/trie-router/index.js";
|
|
7
7
|
//#region src/hono.ts
|
|
8
|
-
/**
|
|
9
|
-
* The Hono class extends the functionality of the HonoBase class.
|
|
10
|
-
* It sets up routing and allows for custom options to be passed.
|
|
11
|
-
*
|
|
12
|
-
* @template E - The environment type.
|
|
13
|
-
* @template S - The schema type.
|
|
14
|
-
* @template BasePath - The base path type.
|
|
15
|
-
*/
|
|
16
8
|
var Hono = class extends Hono$1 {
|
|
17
|
-
/**
|
|
18
|
-
* Creates an instance of the Hono class.
|
|
19
|
-
*
|
|
20
|
-
* @param options - Optional configuration options for the Hono instance.
|
|
21
|
-
*/
|
|
22
9
|
constructor(options = {}) {
|
|
23
10
|
super(options);
|
|
24
11
|
this.router = options.router ?? new SmartRouter({ routers: [new RegExpRouter(), new TrieRouter()] });
|