hono 4.13.13 → 5.0.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/{types/compose.d.ts → compose.d.ts} +1 -0
- package/dist/compose.js +10 -5
- package/dist/{types/context.d.ts → context.d.ts} +15 -15
- package/dist/context.js +79 -47
- package/dist/helper/factory/define-handler.d.ts +150 -0
- package/dist/helper/factory/define-handler.js +165 -0
- package/dist/{types/helper → helper}/factory/index.d.ts +30 -1
- package/dist/helper/factory/index.js +31 -3
- package/dist/{types/helper → helper}/ssg/middleware.d.ts +0 -6
- package/dist/helper/ssg/middleware.js +1 -16
- package/dist/{types/helper → helper}/ssg/ssg.d.ts +0 -12
- package/dist/helper/ssg/ssg.js +0 -3
- package/dist/{types/hono-base.d.ts → hono-base.d.ts} +3 -60
- package/dist/hono-base.js +6 -97
- package/dist/{types/hono.d.ts → hono.d.ts} +1 -1
- package/dist/{types/middleware → middleware}/basic-auth/index.d.ts +4 -3
- package/dist/middleware/basic-auth/index.js +1 -1
- package/dist/{types/middleware → middleware}/bearer-auth/index.d.ts +4 -27
- package/dist/middleware/bearer-auth/index.js +4 -4
- package/dist/middleware/language/language.js +1 -1
- package/dist/middleware/logger/index.js +6 -8
- package/dist/{types/middleware → middleware}/serve-static/index.d.ts +0 -4
- package/dist/{types/preset → preset}/quick.d.ts +1 -1
- package/dist/{types/preset → preset}/tiny.d.ts +1 -1
- package/dist/{types/request.d.ts → request.d.ts} +3 -48
- package/dist/request.js +0 -49
- package/dist/router/linear-router/router.js +4 -6
- package/dist/router/pattern-router/router.js +2 -2
- package/dist/router/reg-exp-router/node.js +1 -1
- package/dist/router/trie-router/node.js +3 -3
- package/dist/utils/buffer.d.ts +11 -0
- package/dist/utils/buffer.js +1 -8
- package/dist/utils/color.d.ts +16 -0
- package/dist/utils/color.js +7 -23
- package/dist/{types/utils → utils}/http-status.d.ts +1 -9
- package/dist/{types/utils → utils}/url.d.ts +0 -5
- package/dist/utils/url.js +1 -11
- package/dist/{types/validator → validator}/validator.d.ts +5 -0
- package/dist/validator/validator.js +46 -49
- package/package.json +209 -350
- 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}/dev/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/types.d.ts → types.d.ts} +1 -1
- /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
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_utils_html = require("../utils/html.js");
|
|
3
|
-
const require_jsx_constants = require("./constants.js");
|
|
4
|
-
const require_jsx_context = require("./context.js");
|
|
5
|
-
const require_jsx_base = require("./base.js");
|
|
6
|
-
const require_jsx_dom_render = require("./dom/render.js");
|
|
7
|
-
const require_jsx_dom_components = require("./dom/components.js");
|
|
8
|
-
const require_jsx_components = require("./components.js");
|
|
9
|
-
//#region src/jsx/streaming.ts
|
|
10
|
-
/**
|
|
11
|
-
* @module
|
|
12
|
-
* This module enables JSX to supports streaming Response.
|
|
13
|
-
*/
|
|
14
|
-
/**
|
|
15
|
-
* Used to specify nonce for scripts generated by `Suspense` and `ErrorBoundary`.
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```tsx
|
|
19
|
-
* <StreamingContext.Provider value={{ scriptNonce: 'test-nonce' }}>
|
|
20
|
-
* <Suspense fallback={<p>Loading...</p>}>
|
|
21
|
-
* <Content />
|
|
22
|
-
* </Suspense>
|
|
23
|
-
* </StreamingContext.Provider>
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
|
-
const StreamingContext = require_jsx_context.createContext(null);
|
|
27
|
-
let suspenseCounter = 0;
|
|
28
|
-
const serializeBoundaryChild = (child) => typeof child === "string" || Array.isArray(child) ? require_jsx_base.renderChildren([child]) : child == null || typeof child === "boolean" ? "" : require_jsx_base.isUntrustedObject(child) ? require_jsx_base.renderUntrustedObject(child) : child.toString();
|
|
29
|
-
/**
|
|
30
|
-
* @experimental
|
|
31
|
-
* `Suspense` is an experimental feature.
|
|
32
|
-
* The API might be changed.
|
|
33
|
-
*/
|
|
34
|
-
const Suspense = async ({ children, fallback }) => {
|
|
35
|
-
if (!Array.isArray(children)) children = [children];
|
|
36
|
-
const nonce = require_jsx_context.useContext(StreamingContext)?.scriptNonce;
|
|
37
|
-
let resArray = [];
|
|
38
|
-
const stackNode = { [require_jsx_constants.DOM_STASH]: [0, []] };
|
|
39
|
-
const popNodeStack = () => {
|
|
40
|
-
require_jsx_dom_render.buildDataStack.pop();
|
|
41
|
-
};
|
|
42
|
-
try {
|
|
43
|
-
stackNode[require_jsx_constants.DOM_STASH][0] = 0;
|
|
44
|
-
require_jsx_dom_render.buildDataStack.push([[], stackNode]);
|
|
45
|
-
resArray = children.map(serializeBoundaryChild);
|
|
46
|
-
} catch (e) {
|
|
47
|
-
if (e instanceof Promise) {
|
|
48
|
-
const resume = require_jsx_context.captureRenderContext();
|
|
49
|
-
resArray = [e.then(() => resume(() => {
|
|
50
|
-
stackNode[require_jsx_constants.DOM_STASH][0] = 0;
|
|
51
|
-
require_jsx_dom_render.buildDataStack.push([[], stackNode]);
|
|
52
|
-
return require_jsx_components.childrenToString(children).finally(popNodeStack);
|
|
53
|
-
}))];
|
|
54
|
-
} else throw e;
|
|
55
|
-
} finally {
|
|
56
|
-
popNodeStack();
|
|
57
|
-
}
|
|
58
|
-
if (resArray.some((res) => res instanceof Promise)) {
|
|
59
|
-
const index = suspenseCounter++;
|
|
60
|
-
const fallbackStr = await (typeof fallback === "string" || Array.isArray(fallback) ? require_jsx_base.renderChildren([fallback]) : require_jsx_base.isUntrustedObject(fallback) ? require_jsx_base.renderUntrustedObject(fallback) : fallback.toString());
|
|
61
|
-
return require_utils_html.raw(`<template id="H:${index}"></template>${fallbackStr}<!--/$-->`, [...fallbackStr.callbacks || [], ({ phase, buffer, context }) => {
|
|
62
|
-
if (phase === require_utils_html.HtmlEscapedCallbackPhase.BeforeStream) return;
|
|
63
|
-
return Promise.all(resArray).then(async (htmlArray) => {
|
|
64
|
-
htmlArray = htmlArray.flat();
|
|
65
|
-
const content = htmlArray.join("");
|
|
66
|
-
if (buffer) buffer[0] = buffer[0].replace(new RegExp(`<template id="H:${index}"></template>.*?<!--/\\$-->`, "s"), () => content);
|
|
67
|
-
let html = buffer ? "" : `<template data-hono-target="H:${index}">${content}</template><script${nonce ? ` nonce="${nonce}"` : ""}>
|
|
68
|
-
((d,c,n) => {
|
|
69
|
-
c=d.currentScript.previousSibling
|
|
70
|
-
d=d.getElementById('H:${index}')
|
|
71
|
-
if(!d)return
|
|
72
|
-
do{n=d.nextSibling;n.remove()}while(n.nodeType!=8||n.nodeValue!='/$')
|
|
73
|
-
d.replaceWith(c.content)
|
|
74
|
-
})(document)
|
|
75
|
-
<\/script>`;
|
|
76
|
-
const callbacks = htmlArray.map((html) => html.callbacks || []).flat();
|
|
77
|
-
if (!callbacks.length) return html;
|
|
78
|
-
if (phase === require_utils_html.HtmlEscapedCallbackPhase.Stream) html = await require_utils_html.resolveCallback(html, require_utils_html.HtmlEscapedCallbackPhase.BeforeStream, true, context);
|
|
79
|
-
return require_utils_html.raw(html, callbacks);
|
|
80
|
-
});
|
|
81
|
-
}]);
|
|
82
|
-
} else return require_utils_html.raw(resArray.join(""));
|
|
83
|
-
};
|
|
84
|
-
Suspense[require_jsx_constants.DOM_RENDERER] = require_jsx_dom_components.Suspense;
|
|
85
|
-
const textEncoder = new TextEncoder();
|
|
86
|
-
/**
|
|
87
|
-
* @experimental
|
|
88
|
-
* `renderToReadableStream()` is an experimental feature.
|
|
89
|
-
* The API might be changed.
|
|
90
|
-
*/
|
|
91
|
-
const renderToReadableStream = (content, onError = console.trace) => {
|
|
92
|
-
let cancelled = false;
|
|
93
|
-
return new ReadableStream({
|
|
94
|
-
async start(controller) {
|
|
95
|
-
try {
|
|
96
|
-
if (content instanceof require_jsx_base.JSXNode) content = content.toString();
|
|
97
|
-
const context = typeof content === "object" ? content : {};
|
|
98
|
-
const resolved = await require_utils_html.resolveCallback(content, require_utils_html.HtmlEscapedCallbackPhase.BeforeStream, true, context);
|
|
99
|
-
if (!cancelled) controller.enqueue(textEncoder.encode(resolved));
|
|
100
|
-
let resolvedCount = 0;
|
|
101
|
-
const callbacks = [];
|
|
102
|
-
const then = (promise) => {
|
|
103
|
-
callbacks.push(promise.catch((err) => {
|
|
104
|
-
console.log(err);
|
|
105
|
-
onError(err);
|
|
106
|
-
return "";
|
|
107
|
-
}).then(async (res) => {
|
|
108
|
-
res = await require_utils_html.resolveCallback(res, require_utils_html.HtmlEscapedCallbackPhase.BeforeStream, true, context);
|
|
109
|
-
res.callbacks?.map((c) => c({
|
|
110
|
-
phase: require_utils_html.HtmlEscapedCallbackPhase.Stream,
|
|
111
|
-
context
|
|
112
|
-
})).filter(Boolean).forEach(then);
|
|
113
|
-
resolvedCount++;
|
|
114
|
-
if (!cancelled) controller.enqueue(textEncoder.encode(res));
|
|
115
|
-
}));
|
|
116
|
-
};
|
|
117
|
-
resolved.callbacks?.map((c) => c({
|
|
118
|
-
phase: require_utils_html.HtmlEscapedCallbackPhase.Stream,
|
|
119
|
-
context
|
|
120
|
-
})).filter(Boolean).forEach(then);
|
|
121
|
-
while (resolvedCount !== callbacks.length) await Promise.all(callbacks);
|
|
122
|
-
} catch (e) {
|
|
123
|
-
onError(e);
|
|
124
|
-
}
|
|
125
|
-
if (!cancelled) controller.close();
|
|
126
|
-
},
|
|
127
|
-
cancel() {
|
|
128
|
-
cancelled = true;
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
};
|
|
132
|
-
//#endregion
|
|
133
|
-
exports.StreamingContext = StreamingContext;
|
|
134
|
-
exports.Suspense = Suspense;
|
|
135
|
-
exports.renderToReadableStream = renderToReadableStream;
|
package/dist/cjs/jsx/types.js
DELETED
|
File without changes
|
package/dist/cjs/jsx/utils.js
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
//#region src/jsx/utils.ts
|
|
3
|
-
const normalizeElementKeyMap = /* @__PURE__ */ new Map([
|
|
4
|
-
["className", "class"],
|
|
5
|
-
["htmlFor", "for"],
|
|
6
|
-
["crossOrigin", "crossorigin"],
|
|
7
|
-
["httpEquiv", "http-equiv"],
|
|
8
|
-
["itemProp", "itemprop"],
|
|
9
|
-
["fetchPriority", "fetchpriority"],
|
|
10
|
-
["noModule", "nomodule"],
|
|
11
|
-
["formAction", "formaction"]
|
|
12
|
-
]);
|
|
13
|
-
const normalizeIntrinsicElementKey = (key) => normalizeElementKeyMap.get(key) || key;
|
|
14
|
-
const invalidAttributeNameCharRe = /[\s"'<>/=`\\\x00-\x1f\x7f-\x9f]/;
|
|
15
|
-
const validAttributeNameCache = /* @__PURE__ */ new Set();
|
|
16
|
-
const validAttributeNameCacheMax = 1024;
|
|
17
|
-
const invalidTagNameCharRe = /^[!?]|[\s"'<>/=`\\\x00-\x1f\x7f-\x9f]/;
|
|
18
|
-
const validTagNameCache = /* @__PURE__ */ new Set();
|
|
19
|
-
const validTagNameCacheMax = 256;
|
|
20
|
-
const cacheValidName = (cache, max, name) => {
|
|
21
|
-
if (cache.size >= max) cache.clear();
|
|
22
|
-
cache.add(name);
|
|
23
|
-
};
|
|
24
|
-
const isValidTagName = (name) => {
|
|
25
|
-
if (validTagNameCache.has(name)) return true;
|
|
26
|
-
if (typeof name !== "string") return false;
|
|
27
|
-
if (name.length === 0) return true;
|
|
28
|
-
if (invalidTagNameCharRe.test(name)) return false;
|
|
29
|
-
cacheValidName(validTagNameCache, validTagNameCacheMax, name);
|
|
30
|
-
return true;
|
|
31
|
-
};
|
|
32
|
-
const isValidAttributeName = (name) => {
|
|
33
|
-
if (validAttributeNameCache.has(name)) return true;
|
|
34
|
-
const len = name.length;
|
|
35
|
-
if (len === 0) return false;
|
|
36
|
-
for (let i = 0; i < len; i++) {
|
|
37
|
-
const c = name.charCodeAt(i);
|
|
38
|
-
if (!(c >= 97 && c <= 122 || c >= 65 && c <= 90 || c >= 48 && c <= 57 || c === 45 || c === 95 || c === 46 || c === 58)) {
|
|
39
|
-
if (!invalidAttributeNameCharRe.test(name)) {
|
|
40
|
-
cacheValidName(validAttributeNameCache, validAttributeNameCacheMax, name);
|
|
41
|
-
return true;
|
|
42
|
-
} else return false;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
cacheValidName(validAttributeNameCache, validAttributeNameCacheMax, name);
|
|
46
|
-
return true;
|
|
47
|
-
};
|
|
48
|
-
const invalidStylePropertyNameCharRe = /[\s"'():;\\/\[\]{}\x00-\x1f\x7f-\x9f]/;
|
|
49
|
-
const validStylePropertyNameCache = /* @__PURE__ */ new Set();
|
|
50
|
-
const validStylePropertyNameCacheMax = 1024;
|
|
51
|
-
const isValidStylePropertyName = (name) => {
|
|
52
|
-
if (validStylePropertyNameCache.has(name)) return true;
|
|
53
|
-
const len = name.length;
|
|
54
|
-
if (len === 0) return false;
|
|
55
|
-
for (let i = 0; i < len; i++) {
|
|
56
|
-
const c = name.charCodeAt(i);
|
|
57
|
-
if (!(c >= 97 && c <= 122 || c >= 65 && c <= 90 || c >= 48 && c <= 57 || c === 45 || c === 95)) {
|
|
58
|
-
if (!invalidStylePropertyNameCharRe.test(name)) {
|
|
59
|
-
cacheValidName(validStylePropertyNameCache, validStylePropertyNameCacheMax, name);
|
|
60
|
-
return true;
|
|
61
|
-
} else return false;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
cacheValidName(validStylePropertyNameCache, validStylePropertyNameCacheMax, name);
|
|
65
|
-
return true;
|
|
66
|
-
};
|
|
67
|
-
const unsafeStyleValueCharRe = /[;"'\\/\[\](){}]/;
|
|
68
|
-
const hasUnsafeStyleValue = (value) => {
|
|
69
|
-
if (!unsafeStyleValueCharRe.test(value)) return false;
|
|
70
|
-
let quote = 0;
|
|
71
|
-
const blockStack = [];
|
|
72
|
-
for (let i = 0, len = value.length; i < len; i++) {
|
|
73
|
-
const c = value.charCodeAt(i);
|
|
74
|
-
if (c === 92) {
|
|
75
|
-
if (i === len - 1) return true;
|
|
76
|
-
i++;
|
|
77
|
-
} else if (quote !== 0) {
|
|
78
|
-
if (c === 10 || c === 12 || c === 13) return true;
|
|
79
|
-
if (c === quote) quote = 0;
|
|
80
|
-
} else if (c === 47 && value.charCodeAt(i + 1) === 42) {
|
|
81
|
-
const end = value.indexOf("*/", i + 2);
|
|
82
|
-
if (end === -1) return true;
|
|
83
|
-
i = end + 1;
|
|
84
|
-
} else if (c === 34 || c === 39) quote = c;
|
|
85
|
-
else if (c === 40) blockStack.push(41);
|
|
86
|
-
else if (c === 91) blockStack.push(93);
|
|
87
|
-
else if (c === 123 || c === 125) return true;
|
|
88
|
-
else if (c === 41 || c === 93) {
|
|
89
|
-
if (blockStack[blockStack.length - 1] !== c) return true;
|
|
90
|
-
blockStack.pop();
|
|
91
|
-
} else if (c === 59 && blockStack.length === 0) return true;
|
|
92
|
-
}
|
|
93
|
-
return quote !== 0 || blockStack.length !== 0;
|
|
94
|
-
};
|
|
95
|
-
const styleObjectForEach = (style, fn) => {
|
|
96
|
-
for (const [k, v] of Object.entries(style)) {
|
|
97
|
-
const key = k[0] === "-" || !/[A-Z]/.test(k) ? k : k.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`);
|
|
98
|
-
if (!isValidStylePropertyName(key)) continue;
|
|
99
|
-
if (v == null) {
|
|
100
|
-
fn(key, null);
|
|
101
|
-
continue;
|
|
102
|
-
}
|
|
103
|
-
let value;
|
|
104
|
-
if (typeof v === "number") value = !key.match(/^(?:a|border-im|column(?:-c|s)|flex(?:$|-[^b])|grid-(?!.*gap)(?:ar|[^a])|font-w|li|or|sca|st|ta|wido|z)|ty$/) ? `${v}px` : `${v}`;
|
|
105
|
-
else if (typeof v === "string") {
|
|
106
|
-
if (hasUnsafeStyleValue(v)) continue;
|
|
107
|
-
value = v;
|
|
108
|
-
} else continue;
|
|
109
|
-
fn(key, value);
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
//#endregion
|
|
113
|
-
exports.isValidAttributeName = isValidAttributeName;
|
|
114
|
-
exports.isValidTagName = isValidTagName;
|
|
115
|
-
exports.normalizeIntrinsicElementKey = normalizeIntrinsicElementKey;
|
|
116
|
-
exports.styleObjectForEach = styleObjectForEach;
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_http_exception = require("../../http-exception.js");
|
|
3
|
-
const require_utils_buffer = require("../../utils/buffer.js");
|
|
4
|
-
const require_utils_basic_auth = require("../../utils/basic-auth.js");
|
|
5
|
-
//#region src/middleware/basic-auth/index.ts
|
|
6
|
-
/**
|
|
7
|
-
* Basic Auth Middleware for Hono.
|
|
8
|
-
*
|
|
9
|
-
* @see {@link https://hono.dev/docs/middleware/builtin/basic-auth}
|
|
10
|
-
*
|
|
11
|
-
* @param {BasicAuthOptions} options - The options for the basic authentication middleware.
|
|
12
|
-
* @param {string} options.username - The username for authentication.
|
|
13
|
-
* @param {string} options.password - The password for authentication.
|
|
14
|
-
* @param {string} [options.realm="Secure Area"] - The realm attribute for the WWW-Authenticate header.
|
|
15
|
-
* @param {Function} [options.hashFunction] - The hash function used for secure comparison.
|
|
16
|
-
* @param {Function} [options.verifyUser] - The function to verify user credentials.
|
|
17
|
-
* @param {string | object | MessageFunction} [options.invalidUserMessage="Unauthorized"] - The invalid user message.
|
|
18
|
-
* @param {Function} [options.onAuthSuccess] - Callback function called on successful authentication.
|
|
19
|
-
* @returns {MiddlewareHandler} The middleware handler function.
|
|
20
|
-
* @throws {HTTPException} If neither "username and password" nor "verifyUser" options are provided.
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* ```ts
|
|
24
|
-
* const app = new Hono()
|
|
25
|
-
*
|
|
26
|
-
* app.use(
|
|
27
|
-
* '/auth/*',
|
|
28
|
-
* basicAuth({
|
|
29
|
-
* username: 'hono',
|
|
30
|
-
* password: 'ahotproject',
|
|
31
|
-
* })
|
|
32
|
-
* )
|
|
33
|
-
*
|
|
34
|
-
* app.get('/auth/page', (c) => {
|
|
35
|
-
* return c.text('You are authorized')
|
|
36
|
-
* })
|
|
37
|
-
* ```
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
* ```ts
|
|
41
|
-
* // With onAuthSuccess callback
|
|
42
|
-
* app.use(
|
|
43
|
-
* '/auth/*',
|
|
44
|
-
* basicAuth({
|
|
45
|
-
* username: 'hono',
|
|
46
|
-
* password: 'ahotproject',
|
|
47
|
-
* onAuthSuccess: (c, username) => {
|
|
48
|
-
* c.set('user', { name: username, role: 'admin' })
|
|
49
|
-
* console.log(`User ${username} authenticated`)
|
|
50
|
-
* },
|
|
51
|
-
* })
|
|
52
|
-
* )
|
|
53
|
-
* ```
|
|
54
|
-
*/
|
|
55
|
-
const basicAuth = (options, ...users) => {
|
|
56
|
-
const usernamePasswordInOptions = "username" in options && "password" in options;
|
|
57
|
-
const verifyUserInOptions = "verifyUser" in options;
|
|
58
|
-
if (!(usernamePasswordInOptions || verifyUserInOptions)) throw new Error("basic auth middleware requires options for \"username and password\" or \"verifyUser\"");
|
|
59
|
-
if (!options.realm) options.realm = "Secure Area";
|
|
60
|
-
if (!options.invalidUserMessage) options.invalidUserMessage = "Unauthorized";
|
|
61
|
-
if (usernamePasswordInOptions) users.unshift({
|
|
62
|
-
username: options.username,
|
|
63
|
-
password: options.password
|
|
64
|
-
});
|
|
65
|
-
return async function basicAuth(ctx, next) {
|
|
66
|
-
const requestUser = require_utils_basic_auth.auth(ctx.req.raw);
|
|
67
|
-
if (requestUser) {
|
|
68
|
-
if (verifyUserInOptions) {
|
|
69
|
-
if (await options.verifyUser(requestUser.username, requestUser.password, ctx)) {
|
|
70
|
-
if (options.onAuthSuccess) await options.onAuthSuccess(ctx, requestUser.username);
|
|
71
|
-
await next();
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
} else for (const user of users) {
|
|
75
|
-
const [usernameEqual, passwordEqual] = await Promise.all([require_utils_buffer.timingSafeEqual(user.username, requestUser.username, options.hashFunction), require_utils_buffer.timingSafeEqual(user.password, requestUser.password, options.hashFunction)]);
|
|
76
|
-
if (usernameEqual && passwordEqual) {
|
|
77
|
-
if (options.onAuthSuccess) await options.onAuthSuccess(ctx, requestUser.username);
|
|
78
|
-
await next();
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
const status = 401;
|
|
84
|
-
const headers = { "WWW-Authenticate": "Basic realm=\"" + options.realm?.replace(/"/g, "\\\"") + "\"" };
|
|
85
|
-
const responseMessage = typeof options.invalidUserMessage === "function" ? await options.invalidUserMessage(ctx) : options.invalidUserMessage;
|
|
86
|
-
const res = typeof responseMessage === "string" ? new Response(responseMessage, {
|
|
87
|
-
status,
|
|
88
|
-
headers
|
|
89
|
-
}) : new Response(JSON.stringify(responseMessage), {
|
|
90
|
-
status,
|
|
91
|
-
headers: {
|
|
92
|
-
...headers,
|
|
93
|
-
"content-type": "application/json"
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
throw new require_http_exception.HTTPException(status, { res });
|
|
97
|
-
};
|
|
98
|
-
};
|
|
99
|
-
//#endregion
|
|
100
|
-
exports.basicAuth = basicAuth;
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_http_exception = require("../../http-exception.js");
|
|
3
|
-
const require_utils_buffer = require("../../utils/buffer.js");
|
|
4
|
-
//#region src/middleware/bearer-auth/index.ts
|
|
5
|
-
const TOKEN_STRINGS = "[A-Za-z0-9._~+/-]+=*";
|
|
6
|
-
const PREFIX = "Bearer";
|
|
7
|
-
const HEADER = "Authorization";
|
|
8
|
-
/**
|
|
9
|
-
* Bearer Auth Middleware for Hono.
|
|
10
|
-
*
|
|
11
|
-
* @see {@link https://hono.dev/docs/middleware/builtin/bearer-auth}
|
|
12
|
-
*
|
|
13
|
-
* @template E - The environment type.
|
|
14
|
-
* @param {BearerAuthOptions} options - The options for the bearer authentication middleware.
|
|
15
|
-
* @param {string | string[]} [options.token] - The string or array of strings to validate the incoming bearer token against.
|
|
16
|
-
* @param {Function} [options.verifyToken] - The function to verify the token.
|
|
17
|
-
* @param {string} [options.realm=""] - The domain name of the realm, as part of the returned WWW-Authenticate challenge header.
|
|
18
|
-
* @param {string} [options.prefix="Bearer"] - The prefix (or known as `schema`) for the Authorization header value. If set to the empty string, no prefix is expected.
|
|
19
|
-
* @param {string} [options.headerName=Authorization] - The header name.
|
|
20
|
-
* @param {Function} [options.hashFunction] - A function to handle hashing for safe comparison of authentication tokens.
|
|
21
|
-
* @param {string | object | MessageFunction} [options.noAuthenticationHeader.message="Unauthorized"] - The no authentication header message.
|
|
22
|
-
* @param {string | object | MessageFunction} [options.noAuthenticationHeader.wwwAuthenticateHeader="Bearer realm=\"\""] - The response header value for the WWW-Authenticate header when no authentication header is provided.
|
|
23
|
-
* @param {string | object | MessageFunction} [options.invalidAuthenticationHeader.message="Bad Request"] - The invalid authentication header message.
|
|
24
|
-
* @param {string | object | MessageFunction} [options.invalidAuthenticationHeader.wwwAuthenticateHeader="Bearer error=\"invalid_request\""] - The response header value for the WWW-Authenticate header when authentication header is invalid.
|
|
25
|
-
* @param {string | object | MessageFunction} [options.invalidToken.message="Unauthorized"] - The invalid token message.
|
|
26
|
-
* @param {string | object | MessageFunction} [options.invalidToken.wwwAuthenticateHeader="Bearer error=\"invalid_token\""] - The response header value for the WWW-Authenticate header when token is invalid.
|
|
27
|
-
* @returns {MiddlewareHandler<E>} The middleware handler function.
|
|
28
|
-
* @throws {Error} If neither "token" nor "verifyToken" options are provided.
|
|
29
|
-
* @throws {HTTPException} If authentication fails, with 401 status code for missing or invalid token, or 400 status code for invalid request.
|
|
30
|
-
*
|
|
31
|
-
* @example
|
|
32
|
-
* ```ts
|
|
33
|
-
* const app = new Hono()
|
|
34
|
-
*
|
|
35
|
-
* const token = 'honoishot'
|
|
36
|
-
*
|
|
37
|
-
* app.use('/api/*', bearerAuth({ token }))
|
|
38
|
-
*
|
|
39
|
-
* app.get('/api/page', (c) => {
|
|
40
|
-
* return c.json({ message: 'You are authorized' })
|
|
41
|
-
* })
|
|
42
|
-
* ```
|
|
43
|
-
*/
|
|
44
|
-
const bearerAuth = (options) => {
|
|
45
|
-
if (!("token" in options || "verifyToken" in options)) throw new Error("bearer auth middleware requires options for \"token\" or \"verifyToken\"");
|
|
46
|
-
if (!options.realm) options.realm = "";
|
|
47
|
-
if (options.prefix === void 0) options.prefix = PREFIX;
|
|
48
|
-
const realm = options.realm?.replace(/"/g, "\\\"");
|
|
49
|
-
const prefix = options.prefix;
|
|
50
|
-
const tokenRegexp = new RegExp(`^${TOKEN_STRINGS}$`);
|
|
51
|
-
const wwwAuthenticatePrefix = prefix === "" ? "" : `${prefix} `;
|
|
52
|
-
const throwHTTPException = async (c, status, wwwAuthenticateHeader, messageOption) => {
|
|
53
|
-
const wwwAuthenticateHeaderValue = typeof wwwAuthenticateHeader === "function" ? await wwwAuthenticateHeader(c) : wwwAuthenticateHeader;
|
|
54
|
-
const headers = { "WWW-Authenticate": typeof wwwAuthenticateHeaderValue === "string" ? wwwAuthenticateHeaderValue : `${wwwAuthenticatePrefix}${Object.entries(wwwAuthenticateHeaderValue).map(([key, value]) => `${key}="${value}"`).join(",")}` };
|
|
55
|
-
const responseMessage = typeof messageOption === "function" ? await messageOption(c) : messageOption;
|
|
56
|
-
const res = typeof responseMessage === "string" ? new Response(responseMessage, {
|
|
57
|
-
status,
|
|
58
|
-
headers
|
|
59
|
-
}) : new Response(JSON.stringify(responseMessage), {
|
|
60
|
-
status,
|
|
61
|
-
headers: {
|
|
62
|
-
...headers,
|
|
63
|
-
"content-type": "application/json"
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
throw new require_http_exception.HTTPException(status, { res });
|
|
67
|
-
};
|
|
68
|
-
return async function bearerAuth(c, next) {
|
|
69
|
-
const headerToken = c.req.header(options.headerName || HEADER);
|
|
70
|
-
if (!headerToken) await throwHTTPException(c, 401, options.noAuthenticationHeader?.wwwAuthenticateHeader || `${wwwAuthenticatePrefix}realm="${realm}"`, options.noAuthenticationHeader?.message || options.noAuthenticationHeaderMessage || "Unauthorized");
|
|
71
|
-
else {
|
|
72
|
-
let tokenValue;
|
|
73
|
-
if (prefix === "") tokenValue = headerToken;
|
|
74
|
-
else {
|
|
75
|
-
const headerLower = headerToken.toLowerCase();
|
|
76
|
-
const prefixLower = prefix.toLowerCase();
|
|
77
|
-
if (headerLower.startsWith(prefixLower) && headerToken[prefix.length] === " ") tokenValue = headerToken.slice(prefix.length).trimStart();
|
|
78
|
-
}
|
|
79
|
-
if (!tokenValue || !tokenRegexp.test(tokenValue)) await throwHTTPException(c, 400, options.invalidAuthenticationHeader?.wwwAuthenticateHeader || `${wwwAuthenticatePrefix}error="invalid_request"`, options.invalidAuthenticationHeader?.message || options.invalidAuthenticationHeaderMessage || "Bad Request");
|
|
80
|
-
else {
|
|
81
|
-
let equal = false;
|
|
82
|
-
if ("verifyToken" in options) equal = await options.verifyToken(tokenValue, c);
|
|
83
|
-
else if (typeof options.token === "string") equal = await require_utils_buffer.timingSafeEqual(options.token, tokenValue, options.hashFunction);
|
|
84
|
-
else if (Array.isArray(options.token) && options.token.length > 0) {
|
|
85
|
-
for (const token of options.token) if (await require_utils_buffer.timingSafeEqual(token, tokenValue, options.hashFunction)) {
|
|
86
|
-
equal = true;
|
|
87
|
-
break;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
if (!equal) await throwHTTPException(c, 401, options.invalidToken?.wwwAuthenticateHeader || `${wwwAuthenticatePrefix}error="invalid_token"`, options.invalidToken?.message || options.invalidTokenMessage || "Unauthorized");
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
await next();
|
|
94
|
-
};
|
|
95
|
-
};
|
|
96
|
-
//#endregion
|
|
97
|
-
exports.bearerAuth = bearerAuth;
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_http_exception = require("../../http-exception.js");
|
|
3
|
-
//#region src/middleware/body-limit/index.ts
|
|
4
|
-
const ERROR_MESSAGE = "Payload Too Large";
|
|
5
|
-
/**
|
|
6
|
-
* Body Limit Middleware for Hono.
|
|
7
|
-
*
|
|
8
|
-
* @see {@link https://hono.dev/docs/middleware/builtin/body-limit}
|
|
9
|
-
*
|
|
10
|
-
* @param {BodyLimitOptions} options - The options for the body limit middleware.
|
|
11
|
-
* @param {number} options.maxSize - The maximum body size allowed.
|
|
12
|
-
* @param {OnError} [options.onError] - The error handler to be invoked if the specified body size is exceeded.
|
|
13
|
-
* @returns {MiddlewareHandler} The middleware handler function.
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* ```ts
|
|
17
|
-
* const app = new Hono()
|
|
18
|
-
*
|
|
19
|
-
* app.post(
|
|
20
|
-
* '/upload',
|
|
21
|
-
* bodyLimit({
|
|
22
|
-
* maxSize: 50 * 1024, // 50kb
|
|
23
|
-
* onError: (c) => {
|
|
24
|
-
* return c.text('overflow :(', 413)
|
|
25
|
-
* },
|
|
26
|
-
* }),
|
|
27
|
-
* async (c) => {
|
|
28
|
-
* const body = await c.req.parseBody()
|
|
29
|
-
* if (body['file'] instanceof File) {
|
|
30
|
-
* console.log(`Got file sized: ${body['file'].size}`)
|
|
31
|
-
* }
|
|
32
|
-
* return c.text('pass :)')
|
|
33
|
-
* }
|
|
34
|
-
* )
|
|
35
|
-
* ```
|
|
36
|
-
*/
|
|
37
|
-
const bodyLimit = (options) => {
|
|
38
|
-
const onError = options.onError || (() => {
|
|
39
|
-
const res = new Response(ERROR_MESSAGE, { status: 413 });
|
|
40
|
-
throw new require_http_exception.HTTPException(413, { res });
|
|
41
|
-
});
|
|
42
|
-
const maxSize = options.maxSize;
|
|
43
|
-
return async function bodyLimit(c, next) {
|
|
44
|
-
if (!c.req.raw.body) return next();
|
|
45
|
-
const hasTransferEncoding = c.req.raw.headers.has("transfer-encoding");
|
|
46
|
-
if (c.req.raw.headers.has("content-length") && !hasTransferEncoding) return parseInt(c.req.raw.headers.get("content-length") || "0", 10) > maxSize ? onError(c) : next();
|
|
47
|
-
let size = 0;
|
|
48
|
-
const chunks = [];
|
|
49
|
-
const rawReader = c.req.raw.body.getReader();
|
|
50
|
-
for (;;) {
|
|
51
|
-
const { done, value } = await rawReader.read();
|
|
52
|
-
if (done) break;
|
|
53
|
-
size += value.length;
|
|
54
|
-
if (size > maxSize) return onError(c);
|
|
55
|
-
chunks.push(value);
|
|
56
|
-
}
|
|
57
|
-
const requestInit = {
|
|
58
|
-
body: new ReadableStream({ start(controller) {
|
|
59
|
-
for (const chunk of chunks) controller.enqueue(chunk);
|
|
60
|
-
controller.close();
|
|
61
|
-
} }),
|
|
62
|
-
duplex: "half"
|
|
63
|
-
};
|
|
64
|
-
c.req.raw = new Request(c.req.raw, requestInit);
|
|
65
|
-
return next();
|
|
66
|
-
};
|
|
67
|
-
};
|
|
68
|
-
//#endregion
|
|
69
|
-
exports.bodyLimit = bodyLimit;
|