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/request.js
CHANGED
|
@@ -4,36 +4,10 @@ import { parseBody } from "./utils/body.js";
|
|
|
4
4
|
import { getQueryParam, getQueryParams, tryDecodeURIComponent } from "./utils/url.js";
|
|
5
5
|
//#region src/request.ts
|
|
6
6
|
var HonoRequest = class {
|
|
7
|
-
/**
|
|
8
|
-
* `.raw` can get the raw Request object.
|
|
9
|
-
*
|
|
10
|
-
* @see {@link https://hono.dev/docs/api/request#raw}
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```ts
|
|
14
|
-
* // For Cloudflare Workers
|
|
15
|
-
* app.post('/', async (c) => {
|
|
16
|
-
* const metadata = c.req.raw.cf?.hostMetadata?
|
|
17
|
-
* ...
|
|
18
|
-
* })
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
7
|
raw;
|
|
22
8
|
#validatedData;
|
|
23
9
|
#matchResult;
|
|
24
10
|
routeIndex = 0;
|
|
25
|
-
/**
|
|
26
|
-
* `.path` can get the pathname of the request.
|
|
27
|
-
*
|
|
28
|
-
* @see {@link https://hono.dev/docs/api/request#path}
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
* ```ts
|
|
32
|
-
* app.get('/about/me', (c) => {
|
|
33
|
-
* const pathname = c.req.path // `/about/me`
|
|
34
|
-
* })
|
|
35
|
-
* ```
|
|
36
|
-
*/
|
|
37
11
|
path;
|
|
38
12
|
bodyCache = {};
|
|
39
13
|
constructor(request, path = "/", matchResult = [[]]) {
|
|
@@ -89,219 +63,40 @@ var HonoRequest = class {
|
|
|
89
63
|
});
|
|
90
64
|
return bodyCache[key] = raw[key]();
|
|
91
65
|
};
|
|
92
|
-
/**
|
|
93
|
-
* `.json()` can parse Request body of type `application/json`
|
|
94
|
-
*
|
|
95
|
-
* @see {@link https://hono.dev/docs/api/request#json}
|
|
96
|
-
*
|
|
97
|
-
* @example
|
|
98
|
-
* ```ts
|
|
99
|
-
* app.post('/entry', async (c) => {
|
|
100
|
-
* const body = await c.req.json()
|
|
101
|
-
* })
|
|
102
|
-
* ```
|
|
103
|
-
*/
|
|
104
66
|
json() {
|
|
105
67
|
return this.#cachedBody("text").then((text) => JSON.parse(text));
|
|
106
68
|
}
|
|
107
|
-
/**
|
|
108
|
-
* `.text()` can parse Request body of type `text/plain`
|
|
109
|
-
*
|
|
110
|
-
* @see {@link https://hono.dev/docs/api/request#text}
|
|
111
|
-
*
|
|
112
|
-
* @example
|
|
113
|
-
* ```ts
|
|
114
|
-
* app.post('/entry', async (c) => {
|
|
115
|
-
* const body = await c.req.text()
|
|
116
|
-
* })
|
|
117
|
-
* ```
|
|
118
|
-
*/
|
|
119
69
|
text() {
|
|
120
70
|
return this.#cachedBody("text");
|
|
121
71
|
}
|
|
122
|
-
/**
|
|
123
|
-
* `.arrayBuffer()` parse Request body as an `ArrayBuffer`
|
|
124
|
-
*
|
|
125
|
-
* @see {@link https://hono.dev/docs/api/request#arraybuffer}
|
|
126
|
-
*
|
|
127
|
-
* @example
|
|
128
|
-
* ```ts
|
|
129
|
-
* app.post('/entry', async (c) => {
|
|
130
|
-
* const body = await c.req.arrayBuffer()
|
|
131
|
-
* })
|
|
132
|
-
* ```
|
|
133
|
-
*/
|
|
134
72
|
arrayBuffer() {
|
|
135
73
|
return this.#cachedBody("arrayBuffer");
|
|
136
74
|
}
|
|
137
|
-
/**
|
|
138
|
-
* `.bytes()` parses the request body as a `Uint8Array`.
|
|
139
|
-
*
|
|
140
|
-
* @see {@link https://hono.dev/docs/api/request#bytes}
|
|
141
|
-
*
|
|
142
|
-
* @example
|
|
143
|
-
* ```ts
|
|
144
|
-
* app.post('/entry', async (c) => {
|
|
145
|
-
* const body = await c.req.bytes()
|
|
146
|
-
* })
|
|
147
|
-
* ```
|
|
148
|
-
*/
|
|
149
75
|
bytes() {
|
|
150
76
|
return this.#cachedBody("arrayBuffer").then((buffer) => new Uint8Array(buffer));
|
|
151
77
|
}
|
|
152
|
-
/**
|
|
153
|
-
* Parses the request body as a `Blob`.
|
|
154
|
-
* @example
|
|
155
|
-
* ```ts
|
|
156
|
-
* app.post('/entry', async (c) => {
|
|
157
|
-
* const body = await c.req.blob();
|
|
158
|
-
* });
|
|
159
|
-
* ```
|
|
160
|
-
* @see https://hono.dev/docs/api/request#blob
|
|
161
|
-
*/
|
|
162
78
|
blob() {
|
|
163
79
|
return this.#cachedBody("blob");
|
|
164
80
|
}
|
|
165
|
-
/**
|
|
166
|
-
* Parses the request body as `FormData`.
|
|
167
|
-
* @example
|
|
168
|
-
* ```ts
|
|
169
|
-
* app.post('/entry', async (c) => {
|
|
170
|
-
* const body = await c.req.formData();
|
|
171
|
-
* });
|
|
172
|
-
* ```
|
|
173
|
-
* @see https://hono.dev/docs/api/request#formdata
|
|
174
|
-
*/
|
|
175
81
|
formData() {
|
|
176
82
|
return this.#cachedBody("formData");
|
|
177
83
|
}
|
|
178
|
-
/**
|
|
179
|
-
* Adds validated data to the request.
|
|
180
|
-
*
|
|
181
|
-
* @param target - The target of the validation.
|
|
182
|
-
* @param data - The validated data to add.
|
|
183
|
-
*/
|
|
184
84
|
addValidatedData(target, data) {
|
|
185
85
|
(this.#validatedData ??= {})[target] = data;
|
|
186
86
|
}
|
|
187
87
|
valid(target) {
|
|
188
88
|
return this.#validatedData?.[target];
|
|
189
89
|
}
|
|
190
|
-
/**
|
|
191
|
-
* `.url` can get the request url strings.
|
|
192
|
-
*
|
|
193
|
-
* @see {@link https://hono.dev/docs/api/request#url}
|
|
194
|
-
*
|
|
195
|
-
* @example
|
|
196
|
-
* ```ts
|
|
197
|
-
* app.get('/about/me', (c) => {
|
|
198
|
-
* const url = c.req.url // `http://localhost:8787/about/me`
|
|
199
|
-
* ...
|
|
200
|
-
* })
|
|
201
|
-
* ```
|
|
202
|
-
*/
|
|
203
90
|
get url() {
|
|
204
91
|
return this.raw.url;
|
|
205
92
|
}
|
|
206
|
-
/**
|
|
207
|
-
* `.method` can get the method name of the request.
|
|
208
|
-
*
|
|
209
|
-
* @see {@link https://hono.dev/docs/api/request#method}
|
|
210
|
-
*
|
|
211
|
-
* @example
|
|
212
|
-
* ```ts
|
|
213
|
-
* app.get('/about/me', (c) => {
|
|
214
|
-
* const method = c.req.method // `GET`
|
|
215
|
-
* })
|
|
216
|
-
* ```
|
|
217
|
-
*/
|
|
218
93
|
get method() {
|
|
219
94
|
return this.raw.method;
|
|
220
95
|
}
|
|
221
96
|
get [GET_MATCH_RESULT]() {
|
|
222
97
|
return this.#matchResult;
|
|
223
98
|
}
|
|
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
99
|
};
|
|
274
|
-
/**
|
|
275
|
-
* Clones a HonoRequest's underlying raw Request object.
|
|
276
|
-
*
|
|
277
|
-
* This utility handles both consumed and unconsumed request bodies:
|
|
278
|
-
* - If the request body hasn't been consumed, it uses the native `clone()` method
|
|
279
|
-
* - If the request body has been consumed, it reconstructs a new Request using cached body data
|
|
280
|
-
*
|
|
281
|
-
* This is particularly useful when you need to:
|
|
282
|
-
* - Process the same request body multiple times
|
|
283
|
-
* - Pass requests to external services after validation
|
|
284
|
-
*
|
|
285
|
-
* @param req - The HonoRequest object to clone
|
|
286
|
-
* @returns A Promise that resolves to a new Request object with the same properties
|
|
287
|
-
* @throws {HTTPException} If the request body was consumed directly via `req.raw`
|
|
288
|
-
* without using HonoRequest methods (e.g., `req.json()`, `req.text()`), making it
|
|
289
|
-
* impossible to reconstruct the body from cache
|
|
290
|
-
*
|
|
291
|
-
* @example
|
|
292
|
-
* ```ts
|
|
293
|
-
* // Clone after consuming the body (e.g., after validation)
|
|
294
|
-
* app.post('/forward',
|
|
295
|
-
* validator('json', (data) => data),
|
|
296
|
-
* async (c) => {
|
|
297
|
-
* const validated = c.req.valid('json')
|
|
298
|
-
* // Body has been consumed, but cloneRawRequest still works
|
|
299
|
-
* const clonedReq = await cloneRawRequest(c.req)
|
|
300
|
-
* return fetch('http://backend-service.com', clonedReq)
|
|
301
|
-
* }
|
|
302
|
-
* )
|
|
303
|
-
* ```
|
|
304
|
-
*/
|
|
305
100
|
const cloneRawRequest = async (req) => {
|
|
306
101
|
if (!req.raw.bodyUsed) return req.raw.clone();
|
|
307
102
|
const cacheKey = Object.keys(req.bodyCache)[0];
|
|
@@ -2,12 +2,14 @@ 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,]+})|[^}])+})?)|\/[^\/\?]
|
|
5
|
+
const splitPathRe = /\/(:\w+(?:{(?:(?:{[\d,]+})|[^}])+})?)|\/[^\/\?]+|\/$|(\?)/g;
|
|
6
6
|
const splitByStarRe = /\*/;
|
|
7
7
|
var LinearRouter = class {
|
|
8
8
|
name = "LinearRouter";
|
|
9
9
|
#routes = [];
|
|
10
10
|
add(method, path, handler) {
|
|
11
|
+
const starIndex = path.indexOf("*");
|
|
12
|
+
if (starIndex !== -1 && path.includes(":") && (!path.endsWith("/*") || starIndex !== path.length - 1)) throw new UnsupportedPathError();
|
|
11
13
|
for (let i = 0, paths = checkOptionalParameter(path) || [path], len = paths.length; i < len; i++) this.#routes.push([
|
|
12
14
|
method,
|
|
13
15
|
paths[i],
|
|
@@ -26,7 +28,7 @@ var LinearRouter = class {
|
|
|
26
28
|
const hasStar = routePath.indexOf("*") !== -1;
|
|
27
29
|
const hasLabel = routePath.indexOf(":") !== -1;
|
|
28
30
|
if (!hasStar && !hasLabel) {
|
|
29
|
-
if (routePath === path
|
|
31
|
+
if (routePath === path) handlers.push([handler, emptyParams]);
|
|
30
32
|
} else if (hasStar && !hasLabel) {
|
|
31
33
|
const endsWithStar = routePath.charCodeAt(routePath.length - 1) === 42;
|
|
32
34
|
const endsWithSlashStar = routePath.endsWith("/*");
|
|
@@ -39,17 +41,18 @@ var LinearRouter = class {
|
|
|
39
41
|
if (j === lastIndex) {
|
|
40
42
|
if (endsWithSlashStar) {
|
|
41
43
|
if (pos !== path.length && path.charCodeAt(pos) !== 47) continue ROUTES_LOOP;
|
|
42
|
-
} else if (!endsWithStar && pos !== path.length
|
|
44
|
+
} else if (!endsWithStar && pos !== path.length) continue ROUTES_LOOP;
|
|
43
45
|
} else {
|
|
44
|
-
const
|
|
46
|
+
const standalone = part.charCodeAt(part.length - 1) === 47;
|
|
47
|
+
const index = path.indexOf("/", standalone ? pos + 1 : pos);
|
|
45
48
|
if (index === -1) continue ROUTES_LOOP;
|
|
46
49
|
pos = index;
|
|
47
50
|
}
|
|
48
51
|
}
|
|
49
52
|
handlers.push([handler, emptyParams]);
|
|
50
|
-
} else
|
|
53
|
+
} else {
|
|
51
54
|
const params = Object.create(null);
|
|
52
|
-
const parts = routePath.match(splitPathRe);
|
|
55
|
+
const parts = (hasStar ? routePath.slice(0, -2) : routePath).match(splitPathRe);
|
|
53
56
|
const lastIndex = parts.length - 1;
|
|
54
57
|
for (let j = 0, pos = 0, len = parts.length; j < len; j++) {
|
|
55
58
|
if (pos === -1 || pos >= path.length) continue ROUTES_LOOP;
|
|
@@ -61,10 +64,15 @@ var LinearRouter = class {
|
|
|
61
64
|
if (name.charCodeAt(name.length - 1) === 125) {
|
|
62
65
|
const openBracePos = name.indexOf("{");
|
|
63
66
|
const next = parts[j + 1];
|
|
64
|
-
const lookahead = next && next[1] !== ":" && next[1] !== "*" ? `(?=${next})` : "";
|
|
65
|
-
const pattern = name.slice(openBracePos + 1, -1)
|
|
67
|
+
const lookahead = next && next[1] !== ":" && next[1] !== "*" ? `(?=${next})` : hasStar ? "(?=/|$)" : "";
|
|
68
|
+
const pattern = `(?:${name.slice(openBracePos + 1, -1)})${lookahead}`;
|
|
66
69
|
const restPath = path.slice(pos + 1);
|
|
67
|
-
const
|
|
70
|
+
const regexp = new RegExp(pattern, "d");
|
|
71
|
+
let match = regexp.exec(restPath);
|
|
72
|
+
if (hasStar && match?.index !== 0) {
|
|
73
|
+
const slashPos = restPath.indexOf("/");
|
|
74
|
+
if (slashPos !== -1) match = regexp.exec(restPath.slice(0, slashPos));
|
|
75
|
+
}
|
|
68
76
|
if (!match || match.indices[0][0] !== 0 || match.indices[0][1] === 0) continue ROUTES_LOOP;
|
|
69
77
|
name = name.slice(0, openBracePos);
|
|
70
78
|
value = restPath.slice(...match.indices[0]);
|
|
@@ -81,12 +89,10 @@ var LinearRouter = class {
|
|
|
81
89
|
if (path.indexOf(part, pos) !== pos) continue ROUTES_LOOP;
|
|
82
90
|
pos += part.length;
|
|
83
91
|
}
|
|
84
|
-
if (j === lastIndex)
|
|
85
|
-
if (pos !== path.length && !(pos === path.length - 1 && path.charCodeAt(pos) === 47)) continue ROUTES_LOOP;
|
|
86
|
-
}
|
|
92
|
+
if (j === lastIndex && pos !== path.length && !(hasStar && path.charCodeAt(pos) === 47)) continue ROUTES_LOOP;
|
|
87
93
|
}
|
|
88
94
|
handlers.push([handler, params]);
|
|
89
|
-
}
|
|
95
|
+
}
|
|
90
96
|
}
|
|
91
97
|
}
|
|
92
98
|
return [handlers];
|
|
@@ -5,15 +5,15 @@ 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(/^\/:([^{]+)(?:{(.*)})?/);
|
|
16
|
-
return match ? `/(?<${match[1]}>${match[2] || "[^/]+"})` : part === "/*" ? "/[^/]+" : part.replace(/[.\\+*[^\]$()]/g, "\\$&");
|
|
16
|
+
return match ? `/(?<${match[1]}>${match[2] || "[^/]+"})` : part === "/*" ? "/[^/]+" : part.endsWith("*") ? part.slice(0, -1).replace(/[.\\+*[^\]$()]/g, "\\$&") + "[^/]*" : part.replace(/[.\\+*[^\]$()]/g, "\\$&");
|
|
17
17
|
});
|
|
18
18
|
try {
|
|
19
19
|
this.#routes.push([
|
|
@@ -2,16 +2,10 @@ import { createNullObject } from "../utils.js";
|
|
|
2
2
|
//#region src/router/reg-exp-router/node.ts
|
|
3
3
|
const LABEL_REG_EXP_STR = "[^/]+";
|
|
4
4
|
const ONLY_WILDCARD_REG_EXP_STR = ".*";
|
|
5
|
+
const PREFIXED_WILDCARD_REG_EXP_STR = "[^/]*";
|
|
5
6
|
const TAIL_WILDCARD_REG_EXP_STR = "(?:|/.*)";
|
|
6
7
|
const PATH_ERROR = Symbol();
|
|
7
8
|
const regExpMetaChars = /* @__PURE__ */ new Set(".\\+*[^]$()");
|
|
8
|
-
/**
|
|
9
|
-
* Sort order:
|
|
10
|
-
* 1. literal
|
|
11
|
-
* 2. special pattern (e.g. :label{[0-9]+})
|
|
12
|
-
* 3. common label pattern (e.g. :label)
|
|
13
|
-
* 4. wildcard
|
|
14
|
-
*/
|
|
15
9
|
function compareKey(a, b) {
|
|
16
10
|
if (a.length === 1) return b.length === 1 ? a < b ? -1 : 1 : -1;
|
|
17
11
|
if (b.length === 1) return 1;
|
|
@@ -33,10 +27,14 @@ var Node = class Node {
|
|
|
33
27
|
"",
|
|
34
28
|
"",
|
|
35
29
|
".*"
|
|
36
|
-
] : [
|
|
30
|
+
] : tokens[i + 1][0] !== "/" ? null : tokens[i - 1] === "/" ? [
|
|
37
31
|
"",
|
|
38
32
|
"",
|
|
39
33
|
LABEL_REG_EXP_STR
|
|
34
|
+
] : [
|
|
35
|
+
"",
|
|
36
|
+
"",
|
|
37
|
+
PREFIXED_WILDCARD_REG_EXP_STR
|
|
40
38
|
] : null : token === "/*" ? [
|
|
41
39
|
"",
|
|
42
40
|
"",
|
|
@@ -47,15 +45,15 @@ var Node = class Node {
|
|
|
47
45
|
const name = pattern[1];
|
|
48
46
|
let regexpStr = pattern[2] || "[^/]+";
|
|
49
47
|
if (name && pattern[2]) {
|
|
50
|
-
if (regexpStr
|
|
48
|
+
if (new RegExp(regexpStr).test("")) throw PATH_ERROR;
|
|
51
49
|
regexpStr = regexpStr.replace(/^\((?!\?:)(?=[^)]+\)$)/, "(?:");
|
|
52
50
|
if (/\((?!\?:)/.test(regexpStr)) throw PATH_ERROR;
|
|
53
51
|
if (regexpStr.length === 1 && regExpMetaChars.has(regexpStr)) throw PATH_ERROR;
|
|
54
52
|
}
|
|
55
53
|
nextNode = node.#children[regexpStr];
|
|
56
54
|
if (!nextNode) {
|
|
57
|
-
if (regexpStr !== ".*" && regexpStr !== "(?:|/.*)") {
|
|
58
|
-
for (const k in node.#children) if ((regexpStr.length > 1 || k.length > 1) && k !== ".*" && k !== "(?:|/.*)") throw PATH_ERROR;
|
|
55
|
+
if (regexpStr !== ".*" && (regexpStr !== "(?:|/.*)" || node.#children[PREFIXED_WILDCARD_REG_EXP_STR])) {
|
|
56
|
+
for (const k in node.#children) if ((regexpStr.length > 1 || k.length > 1) && k !== ".*" && (k !== "(?:|/.*)" || regexpStr === PREFIXED_WILDCARD_REG_EXP_STR)) throw PATH_ERROR;
|
|
59
57
|
}
|
|
60
58
|
nextNode = node.#children[regexpStr] = new Node();
|
|
61
59
|
}
|
|
@@ -25,11 +25,6 @@ var Trie = class {
|
|
|
25
25
|
});
|
|
26
26
|
if (!replaced) break;
|
|
27
27
|
}
|
|
28
|
-
/**
|
|
29
|
-
* - pattern (:label, :label{0-9]+}, ...)
|
|
30
|
-
* - /* wildcard
|
|
31
|
-
* - character
|
|
32
|
-
*/
|
|
33
28
|
const tokens = markedPath.match(/(?::[^\/]+)|(?:\/\*$)|./g) || [];
|
|
34
29
|
for (let i = groups.length - 1; i >= 0; i--) {
|
|
35
30
|
const [mark] = groups[i];
|
|
@@ -17,7 +17,7 @@ var Node = class Node {
|
|
|
17
17
|
let i = 0;
|
|
18
18
|
for (const p of parts) {
|
|
19
19
|
const nextP = parts[++i];
|
|
20
|
-
const pattern = getPattern(p, nextP) || (
|
|
20
|
+
const pattern = getPattern(p, nextP) || (p && p.indexOf("*") === p.length - 1 ? p : null);
|
|
21
21
|
const isParam = Array.isArray(pattern);
|
|
22
22
|
const key = isParam ? pattern[0] : pattern || p;
|
|
23
23
|
const child = curNode.#children[key] ||= new Node();
|
|
@@ -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;
|
|
@@ -76,7 +76,7 @@ var Node = class Node {
|
|
|
76
76
|
if (typeof pattern === "string") {
|
|
77
77
|
if (pattern === "*" || part.startsWith(pattern.slice(0, -1))) {
|
|
78
78
|
this.#pushHandlerSets(handlerSets, child, method, node.#params);
|
|
79
|
-
if (pattern
|
|
79
|
+
if (pattern !== "*" || part !== "") {
|
|
80
80
|
child.#params = params;
|
|
81
81
|
tempNodes.push(child);
|
|
82
82
|
}
|
package/dist/router.js
CHANGED
|
@@ -1,19 +1,6 @@
|
|
|
1
1
|
//#region src/router.ts
|
|
2
|
-
/**
|
|
3
|
-
* @module
|
|
4
|
-
* This module provides types definitions and variables for the routers.
|
|
5
|
-
*/
|
|
6
|
-
/**
|
|
7
|
-
* Constant representing all HTTP methods in uppercase.
|
|
8
|
-
*/
|
|
9
2
|
const METHOD_NAME_ALL = "ALL";
|
|
10
|
-
/**
|
|
11
|
-
* Constant representing all HTTP methods in lowercase.
|
|
12
|
-
*/
|
|
13
3
|
const METHOD_NAME_ALL_LOWERCASE = "all";
|
|
14
|
-
/**
|
|
15
|
-
* Array of supported HTTP methods.
|
|
16
|
-
*/
|
|
17
4
|
const METHODS = [
|
|
18
5
|
"get",
|
|
19
6
|
"post",
|
|
@@ -23,13 +10,7 @@ const METHODS = [
|
|
|
23
10
|
"patch",
|
|
24
11
|
"query"
|
|
25
12
|
];
|
|
26
|
-
/**
|
|
27
|
-
* Error message indicating that a route cannot be added because the matcher is already built.
|
|
28
|
-
*/
|
|
29
13
|
const MESSAGE_MATCHER_IS_ALREADY_BUILT = "Can not add a route since the matcher is already built.";
|
|
30
|
-
/**
|
|
31
|
-
* Error class representing an unsupported path error.
|
|
32
|
-
*/
|
|
33
14
|
var UnsupportedPathError = class extends Error {};
|
|
34
15
|
//#endregion
|
|
35
16
|
export { MESSAGE_MATCHER_IS_ALREADY_BUILT, METHODS, METHOD_NAME_ALL, METHOD_NAME_ALL_LOWERCASE, UnsupportedPathError };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { HonoBase as Hono } from "./hono-base.js";
|
|
2
1
|
import { CustomHeader, RequestHeader } from "./utils/headers.js";
|
|
3
2
|
import { StatusCode } from "./utils/http-status.js";
|
|
4
3
|
import { IfAnyThenEmptyObject, IsAny, JSONValue, RemoveBlankRecord, Simplify, UnionToIntersection } from "./utils/types.js";
|
|
5
4
|
import { Context } from "./context.js";
|
|
5
|
+
import { HonoBase as Hono } from "./hono-base.js";
|
|
6
6
|
//#region src/types.d.ts
|
|
7
7
|
export type Bindings = object;
|
|
8
8
|
export type Variables = object;
|
|
@@ -25,6 +25,8 @@ export interface RouterRoute {
|
|
|
25
25
|
path: string;
|
|
26
26
|
method: string;
|
|
27
27
|
handler: H;
|
|
28
|
+
/** Number of application boundaries crossed by `route()`. */
|
|
29
|
+
depth?: number;
|
|
28
30
|
}
|
|
29
31
|
export type HandlerResponse<O> = Response | TypedResponse<O> | Promise<Response | TypedResponse<O>> | Promise<void>;
|
|
30
32
|
export type Handler<E extends Env = any, P extends string = any, I extends Input = BlankInput, R extends HandlerResponse<any> = any> = (c: Context<E, P, I>, next: Next) => R;
|
|
@@ -43,7 +45,8 @@ export type NotFoundHandler<E extends Env = any> = (c: Context<E>) => NotFoundRe
|
|
|
43
45
|
export interface HTTPResponseError extends Error {
|
|
44
46
|
getResponse: () => Response;
|
|
45
47
|
}
|
|
46
|
-
|
|
48
|
+
/** Error middleware registered with `onError()`. The error is available as `c.error`. */
|
|
49
|
+
export type ErrorHandler<E extends Env = any> = H<E>;
|
|
47
50
|
export interface HandlerInterface<E extends Env = Env, M extends string = string, S extends Schema = BlankSchema, BasePath extends string = '/', CurrentPath extends string = BasePath> {
|
|
48
51
|
<P extends string = CurrentPath, I extends Input = BlankInput, R extends HandlerResponse<any> = any, E2 extends Env = E>(handler: H<E2, P, I, R>): Hono<IntersectNonAnyTypes<[E, E2]>, S & ToSchema<M, P, I, MergeTypedResponse<R>>, BasePath, CurrentPath>;
|
|
49
52
|
<P extends string = CurrentPath, I extends Input = BlankInput, I2 extends Input = I, R extends HandlerResponse<any> = any, E2 extends Env = E, E3 extends Env = IntersectNonAnyTypes<[E, E2]>, M1 extends H<E2, P, I> = H<E2, P, I>>(...handlers: [H<E2, P, I> & M1, H<E3, P, I2, R>]): Hono<IntersectNonAnyTypes<[E, E2, E3]>, S & ToSchema<M, P, I2, MergeTypedResponse<R> | MergeMiddlewareResponse<M1>>, BasePath, CurrentPath>;
|
|
@@ -69,6 +72,34 @@ export interface HandlerInterface<E extends Env = Env, M extends string = string
|
|
|
69
72
|
<P extends string, I extends Input = BlankInput, R extends HandlerResponse<any> = any>(path: P, ...handlers: [H<E, MergePath<BasePath, P>, I, R>, ...H<E, MergePath<BasePath, P>, I, R>[]]): Hono<E, S & ToSchema<M, MergePath<BasePath, P>, I, MergeTypedResponse<R>>, BasePath, MergePath<BasePath, P>>;
|
|
70
73
|
<P extends string, R extends HandlerResponse<any> = any, I extends Input = BlankInput>(path: P): Hono<E, S & ToSchema<M, MergePath<BasePath, P>, I, MergeTypedResponse<R>>, BasePath, MergePath<BasePath, P>>;
|
|
71
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Fallback middleware composes environments without changing the route schema or current path.
|
|
77
|
+
* Its scope does not determine request parameters, which come from the original route.
|
|
78
|
+
*/
|
|
79
|
+
export interface FallbackHandlerInterface<E extends Env, S extends Schema, BasePath extends string, CurrentPath extends string> {
|
|
80
|
+
<E2 extends Env = E>(...handlers: [H<E2, string, any, any>]): Hono<IntersectNonAnyTypes<[E, E2]>, S, BasePath, CurrentPath>;
|
|
81
|
+
<Path extends string, E2 extends Env = E>(path: Path, ...handlers: [H<E2, string, any, any>]): Hono<IntersectNonAnyTypes<[E, E2]>, S, BasePath, CurrentPath>;
|
|
82
|
+
<E2 extends Env = E, E3 extends Env = IntersectNonAnyTypes<[E, E2]>>(...handlers: [H<E2, string, any, any>, H<E3, string, any, any>]): Hono<IntersectNonAnyTypes<[E, E2, E3]>, S, BasePath, CurrentPath>;
|
|
83
|
+
<Path extends string, E2 extends Env = E, E3 extends Env = IntersectNonAnyTypes<[E, E2]>>(path: Path, ...handlers: [H<E2, string, any, any>, H<E3, string, any, any>]): Hono<IntersectNonAnyTypes<[E, E2, E3]>, S, BasePath, CurrentPath>;
|
|
84
|
+
<E2 extends Env = E, E3 extends Env = IntersectNonAnyTypes<[E, E2]>, E4 extends Env = IntersectNonAnyTypes<[E, E2, E3]>>(...handlers: [H<E2, string, any, any>, H<E3, string, any, any>, H<E4, string, any, any>]): Hono<IntersectNonAnyTypes<[E, E2, E3, E4]>, S, BasePath, CurrentPath>;
|
|
85
|
+
<Path extends string, E2 extends Env = E, E3 extends Env = IntersectNonAnyTypes<[E, E2]>, E4 extends Env = IntersectNonAnyTypes<[E, E2, E3]>>(path: Path, ...handlers: [H<E2, string, any, any>, H<E3, string, any, any>, H<E4, string, any, any>]): Hono<IntersectNonAnyTypes<[E, E2, E3, E4]>, S, BasePath, CurrentPath>;
|
|
86
|
+
<E2 extends Env = E, E3 extends Env = IntersectNonAnyTypes<[E, E2]>, E4 extends Env = IntersectNonAnyTypes<[E, E2, E3]>, E5 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4]>>(...handlers: [H<E2, string, any, any>, H<E3, string, any, any>, H<E4, string, any, any>, H<E5, string, any, any>]): Hono<IntersectNonAnyTypes<[E, E2, E3, E4, E5]>, S, BasePath, CurrentPath>;
|
|
87
|
+
<Path extends string, E2 extends Env = E, E3 extends Env = IntersectNonAnyTypes<[E, E2]>, E4 extends Env = IntersectNonAnyTypes<[E, E2, E3]>, E5 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4]>>(path: Path, ...handlers: [H<E2, string, any, any>, H<E3, string, any, any>, H<E4, string, any, any>, H<E5, string, any, any>]): Hono<IntersectNonAnyTypes<[E, E2, E3, E4, E5]>, S, BasePath, CurrentPath>;
|
|
88
|
+
<E2 extends Env = E, E3 extends Env = IntersectNonAnyTypes<[E, E2]>, E4 extends Env = IntersectNonAnyTypes<[E, E2, E3]>, E5 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4]>, E6 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5]>>(...handlers: [H<E2, string, any, any>, H<E3, string, any, any>, H<E4, string, any, any>, H<E5, string, any, any>, H<E6, string, any, any>]): Hono<IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]>, S, BasePath, CurrentPath>;
|
|
89
|
+
<Path extends string, E2 extends Env = E, E3 extends Env = IntersectNonAnyTypes<[E, E2]>, E4 extends Env = IntersectNonAnyTypes<[E, E2, E3]>, E5 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4]>, E6 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5]>>(path: Path, ...handlers: [H<E2, string, any, any>, H<E3, string, any, any>, H<E4, string, any, any>, H<E5, string, any, any>, H<E6, string, any, any>]): Hono<IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]>, S, BasePath, CurrentPath>;
|
|
90
|
+
<E2 extends Env = E, E3 extends Env = IntersectNonAnyTypes<[E, E2]>, E4 extends Env = IntersectNonAnyTypes<[E, E2, E3]>, E5 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4]>, E6 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5]>, E7 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]>>(...handlers: [H<E2, string, any, any>, H<E3, string, any, any>, H<E4, string, any, any>, H<E5, string, any, any>, H<E6, string, any, any>, H<E7, string, any, any>]): Hono<IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7]>, S, BasePath, CurrentPath>;
|
|
91
|
+
<Path extends string, E2 extends Env = E, E3 extends Env = IntersectNonAnyTypes<[E, E2]>, E4 extends Env = IntersectNonAnyTypes<[E, E2, E3]>, E5 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4]>, E6 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5]>, E7 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]>>(path: Path, ...handlers: [H<E2, string, any, any>, H<E3, string, any, any>, H<E4, string, any, any>, H<E5, string, any, any>, H<E6, string, any, any>, H<E7, string, any, any>]): Hono<IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7]>, S, BasePath, CurrentPath>;
|
|
92
|
+
<E2 extends Env = E, E3 extends Env = IntersectNonAnyTypes<[E, E2]>, E4 extends Env = IntersectNonAnyTypes<[E, E2, E3]>, E5 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4]>, E6 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5]>, E7 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]>, E8 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7]>>(...handlers: [H<E2, string, any, any>, H<E3, string, any, any>, H<E4, string, any, any>, H<E5, string, any, any>, H<E6, string, any, any>, H<E7, string, any, any>, H<E8, string, any, any>]): Hono<IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8]>, S, BasePath, CurrentPath>;
|
|
93
|
+
<Path extends string, E2 extends Env = E, E3 extends Env = IntersectNonAnyTypes<[E, E2]>, E4 extends Env = IntersectNonAnyTypes<[E, E2, E3]>, E5 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4]>, E6 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5]>, E7 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]>, E8 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7]>>(path: Path, ...handlers: [H<E2, string, any, any>, H<E3, string, any, any>, H<E4, string, any, any>, H<E5, string, any, any>, H<E6, string, any, any>, H<E7, string, any, any>, H<E8, string, any, any>]): Hono<IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8]>, S, BasePath, CurrentPath>;
|
|
94
|
+
<E2 extends Env = E, E3 extends Env = IntersectNonAnyTypes<[E, E2]>, E4 extends Env = IntersectNonAnyTypes<[E, E2, E3]>, E5 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4]>, E6 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5]>, E7 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]>, E8 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7]>, E9 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8]>>(...handlers: [H<E2, string, any, any>, H<E3, string, any, any>, H<E4, string, any, any>, H<E5, string, any, any>, H<E6, string, any, any>, H<E7, string, any, any>, H<E8, string, any, any>, H<E9, string, any, any>]): Hono<IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9]>, S, BasePath, CurrentPath>;
|
|
95
|
+
<Path extends string, E2 extends Env = E, E3 extends Env = IntersectNonAnyTypes<[E, E2]>, E4 extends Env = IntersectNonAnyTypes<[E, E2, E3]>, E5 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4]>, E6 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5]>, E7 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]>, E8 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7]>, E9 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8]>>(path: Path, ...handlers: [H<E2, string, any, any>, H<E3, string, any, any>, H<E4, string, any, any>, H<E5, string, any, any>, H<E6, string, any, any>, H<E7, string, any, any>, H<E8, string, any, any>, H<E9, string, any, any>]): Hono<IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9]>, S, BasePath, CurrentPath>;
|
|
96
|
+
<E2 extends Env = E, E3 extends Env = IntersectNonAnyTypes<[E, E2]>, E4 extends Env = IntersectNonAnyTypes<[E, E2, E3]>, E5 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4]>, E6 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5]>, E7 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]>, E8 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7]>, E9 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8]>, E10 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9]>>(...handlers: [H<E2, string, any, any>, H<E3, string, any, any>, H<E4, string, any, any>, H<E5, string, any, any>, H<E6, string, any, any>, H<E7, string, any, any>, H<E8, string, any, any>, H<E9, string, any, any>, H<E10, string, any, any>]): Hono<IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9, E10]>, S, BasePath, CurrentPath>;
|
|
97
|
+
<Path extends string, E2 extends Env = E, E3 extends Env = IntersectNonAnyTypes<[E, E2]>, E4 extends Env = IntersectNonAnyTypes<[E, E2, E3]>, E5 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4]>, E6 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5]>, E7 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]>, E8 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7]>, E9 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8]>, E10 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9]>>(path: Path, ...handlers: [H<E2, string, any, any>, H<E3, string, any, any>, H<E4, string, any, any>, H<E5, string, any, any>, H<E6, string, any, any>, H<E7, string, any, any>, H<E8, string, any, any>, H<E9, string, any, any>, H<E10, string, any, any>]): Hono<IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9, E10]>, S, BasePath, CurrentPath>;
|
|
98
|
+
<E2 extends Env = E, E3 extends Env = IntersectNonAnyTypes<[E, E2]>, E4 extends Env = IntersectNonAnyTypes<[E, E2, E3]>, E5 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4]>, E6 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5]>, E7 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]>, E8 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7]>, E9 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8]>, E10 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9]>, E11 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9, E10]>>(...handlers: [H<E2, string, any, any>, H<E3, string, any, any>, H<E4, string, any, any>, H<E5, string, any, any>, H<E6, string, any, any>, H<E7, string, any, any>, H<E8, string, any, any>, H<E9, string, any, any>, H<E10, string, any, any>, H<E11, string, any, any>]): Hono<IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9, E10, E11]>, S, BasePath, CurrentPath>;
|
|
99
|
+
<Path extends string, E2 extends Env = E, E3 extends Env = IntersectNonAnyTypes<[E, E2]>, E4 extends Env = IntersectNonAnyTypes<[E, E2, E3]>, E5 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4]>, E6 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5]>, E7 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]>, E8 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7]>, E9 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8]>, E10 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9]>, E11 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9, E10]>>(path: Path, ...handlers: [H<E2, string, any, any>, H<E3, string, any, any>, H<E4, string, any, any>, H<E5, string, any, any>, H<E6, string, any, any>, H<E7, string, any, any>, H<E8, string, any, any>, H<E9, string, any, any>, H<E10, string, any, any>, H<E11, string, any, any>]): Hono<IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9, E10, E11]>, S, BasePath, CurrentPath>;
|
|
100
|
+
<E2 extends Env = E>(...handlers: H<E2, string, any, any>[]): Hono<IntersectNonAnyTypes<[E, E2]>, S, BasePath, CurrentPath>;
|
|
101
|
+
<Path extends string, E2 extends Env = E>(path: Path, ...handlers: H<E2, string, any, any>[]): Hono<IntersectNonAnyTypes<[E, E2]>, S, BasePath, CurrentPath>;
|
|
102
|
+
}
|
|
72
103
|
export interface MiddlewareHandlerInterface<E extends Env = Env, S extends Schema = BlankSchema, BasePath extends string = '/'> {
|
|
73
104
|
<E2 extends Env = E>(...handlers: MiddlewareHandler<E2, MergePath<BasePath, '*'>>[]): Hono<IntersectNonAnyTypes<[E, E2]>, S, BasePath, MergePath<BasePath, '*'>>;
|
|
74
105
|
<E2 extends Env = E>(handler: MiddlewareHandler<E2, MergePath<BasePath, '*'>>): Hono<IntersectNonAnyTypes<[E, E2]>, S, BasePath, MergePath<BasePath, '*'>>;
|
package/dist/utils/body.js
CHANGED
|
@@ -11,14 +11,6 @@ const parseBody = async (request, options = Object.create(null)) => {
|
|
|
11
11
|
});
|
|
12
12
|
return {};
|
|
13
13
|
};
|
|
14
|
-
/**
|
|
15
|
-
* Parses form data from a request.
|
|
16
|
-
*
|
|
17
|
-
* @template T - The type of the parsed body data.
|
|
18
|
-
* @param {HonoRequest | Request} request - The request object containing form data.
|
|
19
|
-
* @param {ParseBodyOptions} options - Options for parsing the form data.
|
|
20
|
-
* @returns {Promise<T>} The parsed body data.
|
|
21
|
-
*/
|
|
22
14
|
async function parseFormData(request, options) {
|
|
23
15
|
if (!isRawRequest(request) && request.bodyCache.formData) return convertFormDataToBodyData(await request.bodyCache.formData, options);
|
|
24
16
|
const headers = isRawRequest(request) ? request.headers : request.raw.headers;
|
|
@@ -29,14 +21,6 @@ async function parseFormData(request, options) {
|
|
|
29
21
|
if (formData) return convertFormDataToBodyData(formData, options);
|
|
30
22
|
return {};
|
|
31
23
|
}
|
|
32
|
-
/**
|
|
33
|
-
* Converts form data to body data based on the provided options.
|
|
34
|
-
*
|
|
35
|
-
* @template T - The type of the parsed body data.
|
|
36
|
-
* @param {FormData} formData - The form data to convert.
|
|
37
|
-
* @param {ParseBodyOptions} options - Options for parsing the form data.
|
|
38
|
-
* @returns {T} The converted body data.
|
|
39
|
-
*/
|
|
40
24
|
function convertFormDataToBodyData(formData, options) {
|
|
41
25
|
const form = Object.create(null);
|
|
42
26
|
const nestingState = { count: 0 };
|
|
@@ -52,13 +36,6 @@ function convertFormDataToBodyData(formData, options) {
|
|
|
52
36
|
});
|
|
53
37
|
return form;
|
|
54
38
|
}
|
|
55
|
-
/**
|
|
56
|
-
* Handles parsing all values for a given key, supporting multiple values as arrays.
|
|
57
|
-
*
|
|
58
|
-
* @param {BodyData} form - The form data object.
|
|
59
|
-
* @param {string} key - The key to parse.
|
|
60
|
-
* @param {FormDataEntryValue} value - The value to assign.
|
|
61
|
-
*/
|
|
62
39
|
const handleParsingAllValues = (form, key, value) => {
|
|
63
40
|
if (form[key] !== void 0) {
|
|
64
41
|
if (Array.isArray(form[key])) form[key].push(value);
|
|
@@ -66,13 +43,6 @@ const handleParsingAllValues = (form, key, value) => {
|
|
|
66
43
|
} else if (!key.endsWith("[]")) form[key] = value;
|
|
67
44
|
else form[key] = [value];
|
|
68
45
|
};
|
|
69
|
-
/**
|
|
70
|
-
* Handles parsing nested values using dot notation keys.
|
|
71
|
-
*
|
|
72
|
-
* @param {BodyData} form - The form data object.
|
|
73
|
-
* @param {string} key - The dot notation key.
|
|
74
|
-
* @param {BodyDataValue} value - The value to assign.
|
|
75
|
-
*/
|
|
76
46
|
const handleParsingNestedValues = (form, key, value, state) => {
|
|
77
47
|
if (/(?:^|\.)__proto__\./.test(key)) return;
|
|
78
48
|
let nestedForm = form;
|
|
@@ -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
|