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/http-exception.js
CHANGED
|
@@ -1,48 +1,12 @@
|
|
|
1
1
|
//#region src/http-exception.ts
|
|
2
|
-
/**
|
|
3
|
-
* `HTTPException` must be used when a fatal error such as authentication failure occurs.
|
|
4
|
-
*
|
|
5
|
-
* @see {@link https://hono.dev/docs/api/exception}
|
|
6
|
-
*
|
|
7
|
-
* @param {StatusCode} status - status code of HTTPException
|
|
8
|
-
* @param {HTTPExceptionOptions} options - options of HTTPException
|
|
9
|
-
* @param {HTTPExceptionOptions["res"]} options.res - response of options of HTTPException
|
|
10
|
-
* @param {HTTPExceptionOptions["message"]} options.message - message of options of HTTPException
|
|
11
|
-
* @param {HTTPExceptionOptions["cause"]} options.cause - cause of options of HTTPException
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```ts
|
|
15
|
-
* import { HTTPException } from 'hono/http-exception'
|
|
16
|
-
*
|
|
17
|
-
* // ...
|
|
18
|
-
*
|
|
19
|
-
* app.post('/auth', async (c, next) => {
|
|
20
|
-
* // authentication
|
|
21
|
-
* if (authorized === false) {
|
|
22
|
-
* throw new HTTPException(401, { message: 'Custom error message' })
|
|
23
|
-
* }
|
|
24
|
-
* await next()
|
|
25
|
-
* })
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
2
|
var HTTPException = class extends Error {
|
|
29
3
|
res;
|
|
30
4
|
status;
|
|
31
|
-
/**
|
|
32
|
-
* Creates an instance of `HTTPException`.
|
|
33
|
-
* @param status - HTTP status code for the exception. Defaults to 500.
|
|
34
|
-
* @param options - Additional options for the exception.
|
|
35
|
-
*/
|
|
36
5
|
constructor(status = 500, options) {
|
|
37
6
|
super(options?.message, { cause: options?.cause });
|
|
38
7
|
this.res = options?.res;
|
|
39
8
|
this.status = status;
|
|
40
9
|
}
|
|
41
|
-
/**
|
|
42
|
-
* Returns the response object associated with the exception.
|
|
43
|
-
* If a response object is not provided, a new response is created with the error message and status code.
|
|
44
|
-
* @returns The response object.
|
|
45
|
-
*/
|
|
46
10
|
getResponse() {
|
|
47
11
|
if (this.res) return new Response(this.res.body, {
|
|
48
12
|
status: this.status,
|
package/dist/index.js
CHANGED
|
@@ -1,20 +1,5 @@
|
|
|
1
1
|
import { Context } from "./context.js";
|
|
2
2
|
import { Hono } from "./hono.js";
|
|
3
3
|
//#region src/index.ts
|
|
4
|
-
/**
|
|
5
|
-
* @module
|
|
6
|
-
*
|
|
7
|
-
* Hono - Web Framework built on Web Standards
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```ts
|
|
11
|
-
* import { Hono } from 'hono'
|
|
12
|
-
* const app = new Hono()
|
|
13
|
-
*
|
|
14
|
-
* app.get('/', (c) => c.text('Hono!'))
|
|
15
|
-
*
|
|
16
|
-
* export default app
|
|
17
|
-
* ```
|
|
18
|
-
*/
|
|
19
4
|
//#endregion
|
|
20
5
|
export { Context, Hono };
|
package/dist/jsx/components.js
CHANGED
|
@@ -26,11 +26,6 @@ const resolveChildEarly = (child) => {
|
|
|
26
26
|
return str instanceof Promise ? str : raw(str);
|
|
27
27
|
}
|
|
28
28
|
};
|
|
29
|
-
/**
|
|
30
|
-
* @experimental
|
|
31
|
-
* `ErrorBoundary` is an experimental feature.
|
|
32
|
-
* The API might be changed.
|
|
33
|
-
*/
|
|
34
29
|
const ErrorBoundary = async ({ children, fallback, fallbackRender, onError }) => {
|
|
35
30
|
if (!children) return raw("");
|
|
36
31
|
if (!Array.isArray(children)) children = [children];
|
package/dist/jsx/context.js
CHANGED
|
@@ -75,18 +75,6 @@ const resumeWithContextValues = (callback, store, contexts) => runWithRenderCont
|
|
|
75
75
|
throw e;
|
|
76
76
|
}
|
|
77
77
|
}, store);
|
|
78
|
-
/**
|
|
79
|
-
* Establish the request-scoped context store for a render.
|
|
80
|
-
*
|
|
81
|
-
* `resumeStore` continues a suspended subtree in the same store on the fallback
|
|
82
|
-
* path (ignored when `AsyncLocalStorage` is available, where isolation is
|
|
83
|
-
* automatic).
|
|
84
|
-
*
|
|
85
|
-
* Without `AsyncLocalStorage` a render can't be followed across `await`, so the
|
|
86
|
-
* store lives in `fallbackStore` only during synchronous work (mirroring
|
|
87
|
-
* React's request storage). Reading context after `await` then finds no store
|
|
88
|
-
* and falls back to the default value — never another request's value.
|
|
89
|
-
*/
|
|
90
78
|
const runWithRenderContext = (callback, resumeStore) => {
|
|
91
79
|
if (getCurrentStore()) return callback();
|
|
92
80
|
const store = resumeStore ?? /* @__PURE__ */ new WeakMap();
|
|
@@ -107,27 +95,11 @@ const runWithRenderContext = (callback, resumeStore) => {
|
|
|
107
95
|
}
|
|
108
96
|
return result;
|
|
109
97
|
};
|
|
110
|
-
/**
|
|
111
|
-
* Capture the current render store and return a resumer that re-establishes it
|
|
112
|
-
* around a deferred continuation (e.g. a re-render after a suspended promise
|
|
113
|
-
* settles). Shared by every suspension point so none reimplements it.
|
|
114
|
-
*/
|
|
115
98
|
const captureRenderContext = () => {
|
|
116
99
|
const store = getCurrentStore();
|
|
117
100
|
const contexts = captureContextValues(store);
|
|
118
101
|
return (callback) => resumeWithContextValues(callback, store, contexts);
|
|
119
102
|
};
|
|
120
|
-
/**
|
|
121
|
-
* Create a context whose value can be provided with `<Context.Provider>` and
|
|
122
|
-
* read with {@link useContext}.
|
|
123
|
-
*
|
|
124
|
-
* Server-side renders are isolated per request, so a provided value never leaks
|
|
125
|
-
* into a concurrent request — even across `await` in an async component, when
|
|
126
|
-
* `AsyncLocalStorage` is available (Node.js >= 20.16, Deno, Bun, Cloudflare
|
|
127
|
-
* Workers with `nodejs_compat`). Without it, reading context after `await`
|
|
128
|
-
* returns the default value; synchronous components and `use()`-based
|
|
129
|
-
* suspension are unaffected.
|
|
130
|
-
*/
|
|
131
103
|
const createContext = (defaultValue) => {
|
|
132
104
|
const values = [defaultValue];
|
|
133
105
|
const context = ((props) => {
|
|
@@ -152,12 +124,6 @@ const createContext = (defaultValue) => {
|
|
|
152
124
|
globalContexts.push(context);
|
|
153
125
|
return context;
|
|
154
126
|
};
|
|
155
|
-
/**
|
|
156
|
-
* Read the current value of a context created with {@link createContext}.
|
|
157
|
-
*
|
|
158
|
-
* Safe to call from async components after `await`. See {@link createContext}
|
|
159
|
-
* for the per-runtime isolation guarantees.
|
|
160
|
-
*/
|
|
161
127
|
const useContext = (context) => {
|
|
162
128
|
return readContextValueIn(getCurrentStore(), context);
|
|
163
129
|
};
|
package/dist/jsx/dom/client.js
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import { buildNode, renderNode } from "./render.js";
|
|
2
2
|
import { useState } from "../hooks/index.js";
|
|
3
3
|
//#region src/jsx/dom/client.ts
|
|
4
|
-
/**
|
|
5
|
-
* Create a root object for rendering
|
|
6
|
-
* @param element Render target
|
|
7
|
-
* @param options Options for createRoot (not supported yet)
|
|
8
|
-
* @returns Root object has `render` and `unmount` methods
|
|
9
|
-
*/
|
|
10
4
|
const createRoot = (element, options = {}) => {
|
|
11
5
|
let setJsxNode = void 0;
|
|
12
6
|
if (Object.keys(options).length > 0) console.warn("createRoot options are not supported yet");
|
|
@@ -29,14 +23,6 @@ const createRoot = (element, options = {}) => {
|
|
|
29
23
|
}
|
|
30
24
|
};
|
|
31
25
|
};
|
|
32
|
-
/**
|
|
33
|
-
* Create a root object and hydrate app to the target element.
|
|
34
|
-
* In hono/jsx/dom, hydrate is equivalent to render.
|
|
35
|
-
* @param element Render target
|
|
36
|
-
* @param reactNode A JSXNode to render
|
|
37
|
-
* @param options Options for createRoot (not supported yet)
|
|
38
|
-
* @returns Root object has `render` and `unmount` methods
|
|
39
|
-
*/
|
|
40
26
|
const hydrateRoot = (element, reactNode, options = {}) => {
|
|
41
27
|
const root = createRoot(element, options);
|
|
42
28
|
root.render(reactNode);
|
package/dist/jsx/dom/css.js
CHANGED
|
@@ -76,15 +76,6 @@ const createCssJsxDomObjects = ({ id }) => {
|
|
|
76
76
|
});
|
|
77
77
|
return [cssObject, Style];
|
|
78
78
|
};
|
|
79
|
-
/**
|
|
80
|
-
* @experimental
|
|
81
|
-
* `createCssContext` is an experimental feature.
|
|
82
|
-
* The API might be changed.
|
|
83
|
-
*
|
|
84
|
-
* @param options.id - The ID for the style element
|
|
85
|
-
* @param options.classNameSlug - Optional function to customize generated CSS class names
|
|
86
|
-
* @param options.onInvalidSlug - Optional callback function called when an invalid slug is returned from ClassNameSlug
|
|
87
|
-
*/
|
|
88
79
|
const createCssContext = ({ id, classNameSlug, onInvalidSlug }) => {
|
|
89
80
|
const [cssObject, Style] = createCssJsxDomObjects({ id });
|
|
90
81
|
const newCssClassNameObject = (cssClassName) => {
|
|
@@ -111,35 +102,10 @@ const createCssContext = ({ id, classNameSlug, onInvalidSlug }) => {
|
|
|
111
102
|
};
|
|
112
103
|
};
|
|
113
104
|
const defaultContext = createCssContext({ id: DEFAULT_STYLE_ID });
|
|
114
|
-
/**
|
|
115
|
-
* @experimental
|
|
116
|
-
* `css` is an experimental feature.
|
|
117
|
-
* The API might be changed.
|
|
118
|
-
*/
|
|
119
105
|
const css = defaultContext.css;
|
|
120
|
-
/**
|
|
121
|
-
* @experimental
|
|
122
|
-
* `cx` is an experimental feature.
|
|
123
|
-
* The API might be changed.
|
|
124
|
-
*/
|
|
125
106
|
const cx = defaultContext.cx;
|
|
126
|
-
/**
|
|
127
|
-
* @experimental
|
|
128
|
-
* `keyframes` is an experimental feature.
|
|
129
|
-
* The API might be changed.
|
|
130
|
-
*/
|
|
131
107
|
const keyframes = defaultContext.keyframes;
|
|
132
|
-
/**
|
|
133
|
-
* @experimental
|
|
134
|
-
* `viewTransition` is an experimental feature.
|
|
135
|
-
* The API might be changed.
|
|
136
|
-
*/
|
|
137
108
|
const viewTransition = defaultContext.viewTransition;
|
|
138
|
-
/**
|
|
139
|
-
* @experimental
|
|
140
|
-
* `Style` is an experimental feature.
|
|
141
|
-
* The API might be changed.
|
|
142
|
-
*/
|
|
143
109
|
const Style = defaultContext.Style;
|
|
144
110
|
//#endregion
|
|
145
111
|
export { Style, createCssContext, createCssJsxDomObjects, css, cx, keyframes, rawCssString, viewTransition };
|
|
@@ -3,9 +3,6 @@ import { createContext } from "../context.js";
|
|
|
3
3
|
import { useContext } from "../../context.js";
|
|
4
4
|
import { useCallback, useState } from "../../hooks/index.js";
|
|
5
5
|
//#region src/jsx/dom/hooks/index.ts
|
|
6
|
-
/**
|
|
7
|
-
* Provide hooks used only in jsx/dom
|
|
8
|
-
*/
|
|
9
6
|
const FormContext = createContext({
|
|
10
7
|
pending: false,
|
|
11
8
|
data: null,
|
|
@@ -17,20 +14,9 @@ const registerAction = (action) => {
|
|
|
17
14
|
actions.add(action);
|
|
18
15
|
action.finally(() => actions.delete(action));
|
|
19
16
|
};
|
|
20
|
-
/**
|
|
21
|
-
* This hook returns the current form status
|
|
22
|
-
* @returns FormStatus
|
|
23
|
-
*/
|
|
24
17
|
const useFormStatus = () => {
|
|
25
18
|
return useContext(FormContext);
|
|
26
19
|
};
|
|
27
|
-
/**
|
|
28
|
-
* This hook returns the current state and a function to update the state optimistically
|
|
29
|
-
* The current state is updated optimistically and then reverted to the original state when all actions are resolved
|
|
30
|
-
* @param state
|
|
31
|
-
* @param updateState
|
|
32
|
-
* @returns [T, (action: N) => void]
|
|
33
|
-
*/
|
|
34
20
|
const useOptimistic = (state, updateState) => {
|
|
35
21
|
const [optimisticState, setOptimisticState] = useState(state);
|
|
36
22
|
if (actions.size > 0) Promise.all(actions).finally(() => {
|
|
@@ -41,13 +27,6 @@ const useOptimistic = (state, updateState) => {
|
|
|
41
27
|
setOptimisticState((currentState) => updateState(currentState, newData));
|
|
42
28
|
}, [])];
|
|
43
29
|
};
|
|
44
|
-
/**
|
|
45
|
-
* This hook returns the current state and a function to update the state by form action
|
|
46
|
-
* @param fn
|
|
47
|
-
* @param initialState
|
|
48
|
-
* @param permalink
|
|
49
|
-
* @returns [T, (data: FormData) => void]
|
|
50
|
-
*/
|
|
51
30
|
const useActionState = (fn, initialState, permalink) => {
|
|
52
31
|
const [state, setState] = useState(initialState);
|
|
53
32
|
const actionState = async (data) => {
|
package/dist/jsx/dom/index.js
CHANGED
|
@@ -10,10 +10,6 @@ import { Fragment, jsxDEV } from "./jsx-dev-runtime.js";
|
|
|
10
10
|
import "./jsx-runtime.js";
|
|
11
11
|
import { ErrorBoundary, Suspense } from "./components.js";
|
|
12
12
|
//#region src/jsx/dom/index.ts
|
|
13
|
-
/**
|
|
14
|
-
* @module
|
|
15
|
-
* This module provides APIs for `hono/jsx/dom`.
|
|
16
|
-
*/
|
|
17
13
|
const createElement = (tag, props, ...children) => {
|
|
18
14
|
const jsxProps = props ? { ...props } : {};
|
|
19
15
|
if (children.length) jsxProps.children = children.length === 1 ? children[0] : children;
|
package/dist/jsx/dom/server.js
CHANGED
|
@@ -3,12 +3,6 @@ import { renderToReadableStream as renderToReadableStream$1 } from "../streaming
|
|
|
3
3
|
import dom_default from "./index.js";
|
|
4
4
|
//#region src/jsx/dom/server.ts
|
|
5
5
|
const prepareRoot = (element) => typeof element === "string" || Array.isArray(element) ? renderChildren([element]) : element;
|
|
6
|
-
/**
|
|
7
|
-
* Render JSX element to string.
|
|
8
|
-
* @param element JSX element to render.
|
|
9
|
-
* @param options Options for rendering.
|
|
10
|
-
* @returns Rendered string.
|
|
11
|
-
*/
|
|
12
6
|
const renderToString = (element, options = {}) => {
|
|
13
7
|
if (Object.keys(options).length > 0) console.warn("options are not supported yet");
|
|
14
8
|
element = prepareRoot(element);
|
|
@@ -16,12 +10,6 @@ const renderToString = (element, options = {}) => {
|
|
|
16
10
|
if (typeof res !== "string") throw new Error("Async component is not supported in renderToString");
|
|
17
11
|
return res;
|
|
18
12
|
};
|
|
19
|
-
/**
|
|
20
|
-
* Render JSX element to readable stream.
|
|
21
|
-
* @param element JSX element to render.
|
|
22
|
-
* @param options Options for rendering.
|
|
23
|
-
* @returns Rendered readable stream.
|
|
24
|
-
*/
|
|
25
13
|
const renderToReadableStream = async (element, options = {}) => {
|
|
26
14
|
if (Object.keys(options).some((key) => key !== "onError")) console.warn("options are not supported yet, except onError");
|
|
27
15
|
element = prepareRoot(element);
|
package/dist/jsx/index.js
CHANGED
|
@@ -6,10 +6,6 @@ import { useActionState, useOptimistic } from "./dom/hooks/index.js";
|
|
|
6
6
|
import { Suspense } from "./streaming.js";
|
|
7
7
|
import { ErrorBoundary } from "./components.js";
|
|
8
8
|
//#region src/jsx/index.ts
|
|
9
|
-
/**
|
|
10
|
-
* @module
|
|
11
|
-
* JSX for Hono.
|
|
12
|
-
*/
|
|
13
9
|
var jsx_default = {
|
|
14
10
|
version: reactAPICompatVersion,
|
|
15
11
|
memo,
|
package/dist/jsx/streaming.js
CHANGED
|
@@ -6,30 +6,9 @@ import { buildDataStack } from "./dom/render.js";
|
|
|
6
6
|
import { Suspense as Suspense$1 } from "./dom/components.js";
|
|
7
7
|
import { childrenToString } from "./components.js";
|
|
8
8
|
//#region src/jsx/streaming.ts
|
|
9
|
-
/**
|
|
10
|
-
* @module
|
|
11
|
-
* This module enables JSX to supports streaming Response.
|
|
12
|
-
*/
|
|
13
|
-
/**
|
|
14
|
-
* Used to specify nonce for scripts generated by `Suspense` and `ErrorBoundary`.
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```tsx
|
|
18
|
-
* <StreamingContext.Provider value={{ scriptNonce: 'test-nonce' }}>
|
|
19
|
-
* <Suspense fallback={<p>Loading...</p>}>
|
|
20
|
-
* <Content />
|
|
21
|
-
* </Suspense>
|
|
22
|
-
* </StreamingContext.Provider>
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
9
|
const StreamingContext = createContext(null);
|
|
26
10
|
let suspenseCounter = 0;
|
|
27
11
|
const serializeBoundaryChild = (child) => typeof child === "string" || Array.isArray(child) ? renderChildren([child]) : child == null || typeof child === "boolean" ? "" : isUntrustedObject(child) ? renderUntrustedObject(child) : child.toString();
|
|
28
|
-
/**
|
|
29
|
-
* @experimental
|
|
30
|
-
* `Suspense` is an experimental feature.
|
|
31
|
-
* The API might be changed.
|
|
32
|
-
*/
|
|
33
12
|
const Suspense = async ({ children, fallback }) => {
|
|
34
13
|
if (!Array.isArray(children)) children = [children];
|
|
35
14
|
const nonce = useContext(StreamingContext)?.scriptNonce;
|
|
@@ -82,11 +61,6 @@ d.replaceWith(c.content)
|
|
|
82
61
|
};
|
|
83
62
|
Suspense[DOM_RENDERER] = Suspense$1;
|
|
84
63
|
const textEncoder = new TextEncoder();
|
|
85
|
-
/**
|
|
86
|
-
* @experimental
|
|
87
|
-
* `renderToReadableStream()` is an experimental feature.
|
|
88
|
-
* The API might be changed.
|
|
89
|
-
*/
|
|
90
64
|
const renderToReadableStream = (content, onError = console.trace) => {
|
|
91
65
|
let cancelled = false;
|
|
92
66
|
return new ReadableStream({
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import { MiddlewareHandler } from "../../types.js";
|
|
2
2
|
import { Context } from "../../context.js";
|
|
3
|
+
import { StringHashFunction } from "../../utils/buffer.js";
|
|
3
4
|
//#region src/middleware/basic-auth/index.d.ts
|
|
4
5
|
type MessageFunction = (c: Context) => string | object | Promise<string | object>;
|
|
5
6
|
type BasicAuthOptions = {
|
|
6
7
|
username: string;
|
|
7
8
|
password: string;
|
|
8
9
|
realm?: string;
|
|
9
|
-
hashFunction?:
|
|
10
|
+
hashFunction?: StringHashFunction;
|
|
10
11
|
invalidUserMessage?: string | object | MessageFunction;
|
|
11
12
|
onAuthSuccess?: (c: Context, username: string) => void | Promise<void>;
|
|
12
13
|
} | {
|
|
13
14
|
verifyUser: (username: string, password: string, c: Context) => boolean | Promise<boolean>;
|
|
14
15
|
realm?: string;
|
|
15
|
-
hashFunction?:
|
|
16
|
+
hashFunction?: StringHashFunction;
|
|
16
17
|
invalidUserMessage?: string | object | MessageFunction;
|
|
17
18
|
onAuthSuccess?: (c: Context, username: string) => void | Promise<void>;
|
|
18
19
|
};
|
|
@@ -25,7 +26,7 @@ type BasicAuthOptions = {
|
|
|
25
26
|
* @param {string} options.username - The username for authentication.
|
|
26
27
|
* @param {string} options.password - The password for authentication.
|
|
27
28
|
* @param {string} [options.realm="Secure Area"] - The realm attribute for the WWW-Authenticate header.
|
|
28
|
-
* @param {
|
|
29
|
+
* @param {StringHashFunction} [options.hashFunction] - The hash function used for secure comparison.
|
|
29
30
|
* @param {Function} [options.verifyUser] - The function to verify user credentials.
|
|
30
31
|
* @param {string | object | MessageFunction} [options.invalidUserMessage="Unauthorized"] - The invalid user message.
|
|
31
32
|
* @param {Function} [options.onAuthSuccess] - Callback function called on successful authentication.
|
|
@@ -2,55 +2,6 @@ import { HTTPException } from "../../http-exception.js";
|
|
|
2
2
|
import { timingSafeEqual } from "../../utils/buffer.js";
|
|
3
3
|
import { auth } from "../../utils/basic-auth.js";
|
|
4
4
|
//#region src/middleware/basic-auth/index.ts
|
|
5
|
-
/**
|
|
6
|
-
* Basic Auth Middleware for Hono.
|
|
7
|
-
*
|
|
8
|
-
* @see {@link https://hono.dev/docs/middleware/builtin/basic-auth}
|
|
9
|
-
*
|
|
10
|
-
* @param {BasicAuthOptions} options - The options for the basic authentication middleware.
|
|
11
|
-
* @param {string} options.username - The username for authentication.
|
|
12
|
-
* @param {string} options.password - The password for authentication.
|
|
13
|
-
* @param {string} [options.realm="Secure Area"] - The realm attribute for the WWW-Authenticate header.
|
|
14
|
-
* @param {Function} [options.hashFunction] - The hash function used for secure comparison.
|
|
15
|
-
* @param {Function} [options.verifyUser] - The function to verify user credentials.
|
|
16
|
-
* @param {string | object | MessageFunction} [options.invalidUserMessage="Unauthorized"] - The invalid user message.
|
|
17
|
-
* @param {Function} [options.onAuthSuccess] - Callback function called on successful authentication.
|
|
18
|
-
* @returns {MiddlewareHandler} The middleware handler function.
|
|
19
|
-
* @throws {HTTPException} If neither "username and password" nor "verifyUser" options are provided.
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```ts
|
|
23
|
-
* const app = new Hono()
|
|
24
|
-
*
|
|
25
|
-
* app.use(
|
|
26
|
-
* '/auth/*',
|
|
27
|
-
* basicAuth({
|
|
28
|
-
* username: 'hono',
|
|
29
|
-
* password: 'ahotproject',
|
|
30
|
-
* })
|
|
31
|
-
* )
|
|
32
|
-
*
|
|
33
|
-
* app.get('/auth/page', (c) => {
|
|
34
|
-
* return c.text('You are authorized')
|
|
35
|
-
* })
|
|
36
|
-
* ```
|
|
37
|
-
*
|
|
38
|
-
* @example
|
|
39
|
-
* ```ts
|
|
40
|
-
* // With onAuthSuccess callback
|
|
41
|
-
* app.use(
|
|
42
|
-
* '/auth/*',
|
|
43
|
-
* basicAuth({
|
|
44
|
-
* username: 'hono',
|
|
45
|
-
* password: 'ahotproject',
|
|
46
|
-
* onAuthSuccess: (c, username) => {
|
|
47
|
-
* c.set('user', { name: username, role: 'admin' })
|
|
48
|
-
* console.log(`User ${username} authenticated`)
|
|
49
|
-
* },
|
|
50
|
-
* })
|
|
51
|
-
* )
|
|
52
|
-
* ```
|
|
53
|
-
*/
|
|
54
5
|
const basicAuth = (options, ...users) => {
|
|
55
6
|
const usernamePasswordInOptions = "username" in options && "password" in options;
|
|
56
7
|
const verifyUserInOptions = "verifyUser" in options;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Env, MiddlewareHandler } from "../../types.js";
|
|
2
2
|
import { Context } from "../../context.js";
|
|
3
|
+
import { StringHashFunction } from "../../utils/buffer.js";
|
|
3
4
|
//#region src/middleware/bearer-auth/index.d.ts
|
|
4
5
|
type MessageFunction = (c: Context) => string | object | Promise<string | object>;
|
|
5
6
|
type CustomizedErrorResponseOptions = {
|
|
@@ -11,42 +12,18 @@ type BearerAuthOptions<E extends Env = Env> = {
|
|
|
11
12
|
realm?: string;
|
|
12
13
|
prefix?: string;
|
|
13
14
|
headerName?: string;
|
|
14
|
-
hashFunction?:
|
|
15
|
-
/**
|
|
16
|
-
* @deprecated Use noAuthenticationHeader.message instead
|
|
17
|
-
*/
|
|
18
|
-
noAuthenticationHeaderMessage?: string | object | MessageFunction;
|
|
15
|
+
hashFunction?: StringHashFunction;
|
|
19
16
|
noAuthenticationHeader?: CustomizedErrorResponseOptions;
|
|
20
|
-
/**
|
|
21
|
-
* @deprecated Use invalidAuthenticationHeader.message instead
|
|
22
|
-
*/
|
|
23
|
-
invalidAuthenticationHeaderMessage?: string | object | MessageFunction;
|
|
24
17
|
invalidAuthenticationHeader?: CustomizedErrorResponseOptions;
|
|
25
|
-
/**
|
|
26
|
-
* @deprecated Use invalidToken.message instead
|
|
27
|
-
*/
|
|
28
|
-
invalidTokenMessage?: string | object | MessageFunction;
|
|
29
18
|
invalidToken?: CustomizedErrorResponseOptions;
|
|
30
19
|
} | {
|
|
31
20
|
realm?: string;
|
|
32
21
|
prefix?: string;
|
|
33
22
|
headerName?: string;
|
|
34
23
|
verifyToken: (token: string, c: Context<E>) => boolean | Promise<boolean>;
|
|
35
|
-
hashFunction?:
|
|
36
|
-
/**
|
|
37
|
-
* @deprecated Use noAuthenticationHeader.message instead
|
|
38
|
-
*/
|
|
39
|
-
noAuthenticationHeaderMessage?: string | object | MessageFunction;
|
|
24
|
+
hashFunction?: StringHashFunction;
|
|
40
25
|
noAuthenticationHeader?: CustomizedErrorResponseOptions;
|
|
41
|
-
/**
|
|
42
|
-
* @deprecated Use invalidAuthenticationHeader.message instead
|
|
43
|
-
*/
|
|
44
|
-
invalidAuthenticationHeaderMessage?: string | object | MessageFunction;
|
|
45
26
|
invalidAuthenticationHeader?: CustomizedErrorResponseOptions;
|
|
46
|
-
/**
|
|
47
|
-
* @deprecated Use invalidToken.message instead
|
|
48
|
-
*/
|
|
49
|
-
invalidTokenMessage?: string | object | MessageFunction;
|
|
50
27
|
invalidToken?: CustomizedErrorResponseOptions;
|
|
51
28
|
};
|
|
52
29
|
/**
|
|
@@ -61,7 +38,7 @@ type BearerAuthOptions<E extends Env = Env> = {
|
|
|
61
38
|
* @param {string} [options.realm=""] - The domain name of the realm, as part of the returned WWW-Authenticate challenge header.
|
|
62
39
|
* @param {string} [options.prefix="Bearer"] - The prefix (or known as `schema`) for the Authorization header value. If set to the empty string, no prefix is expected.
|
|
63
40
|
* @param {string} [options.headerName=Authorization] - The header name.
|
|
64
|
-
* @param {
|
|
41
|
+
* @param {StringHashFunction} [options.hashFunction] - A function to handle hashing for safe comparison of authentication tokens.
|
|
65
42
|
* @param {string | object | MessageFunction} [options.noAuthenticationHeader.message="Unauthorized"] - The no authentication header message.
|
|
66
43
|
* @param {string | object | MessageFunction} [options.noAuthenticationHeader.wwwAuthenticateHeader="Bearer realm=\"\""] - The response header value for the WWW-Authenticate header when no authentication header is provided.
|
|
67
44
|
* @param {string | object | MessageFunction} [options.invalidAuthenticationHeader.message="Bad Request"] - The invalid authentication header message.
|
|
@@ -4,42 +4,6 @@ import { timingSafeEqual } from "../../utils/buffer.js";
|
|
|
4
4
|
const TOKEN_STRINGS = "[A-Za-z0-9._~+/-]+=*";
|
|
5
5
|
const PREFIX = "Bearer";
|
|
6
6
|
const HEADER = "Authorization";
|
|
7
|
-
/**
|
|
8
|
-
* Bearer Auth Middleware for Hono.
|
|
9
|
-
*
|
|
10
|
-
* @see {@link https://hono.dev/docs/middleware/builtin/bearer-auth}
|
|
11
|
-
*
|
|
12
|
-
* @template E - The environment type.
|
|
13
|
-
* @param {BearerAuthOptions} options - The options for the bearer authentication middleware.
|
|
14
|
-
* @param {string | string[]} [options.token] - The string or array of strings to validate the incoming bearer token against.
|
|
15
|
-
* @param {Function} [options.verifyToken] - The function to verify the token.
|
|
16
|
-
* @param {string} [options.realm=""] - The domain name of the realm, as part of the returned WWW-Authenticate challenge header.
|
|
17
|
-
* @param {string} [options.prefix="Bearer"] - The prefix (or known as `schema`) for the Authorization header value. If set to the empty string, no prefix is expected.
|
|
18
|
-
* @param {string} [options.headerName=Authorization] - The header name.
|
|
19
|
-
* @param {Function} [options.hashFunction] - A function to handle hashing for safe comparison of authentication tokens.
|
|
20
|
-
* @param {string | object | MessageFunction} [options.noAuthenticationHeader.message="Unauthorized"] - The no authentication header message.
|
|
21
|
-
* @param {string | object | MessageFunction} [options.noAuthenticationHeader.wwwAuthenticateHeader="Bearer realm=\"\""] - The response header value for the WWW-Authenticate header when no authentication header is provided.
|
|
22
|
-
* @param {string | object | MessageFunction} [options.invalidAuthenticationHeader.message="Bad Request"] - The invalid authentication header message.
|
|
23
|
-
* @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.
|
|
24
|
-
* @param {string | object | MessageFunction} [options.invalidToken.message="Unauthorized"] - The invalid token message.
|
|
25
|
-
* @param {string | object | MessageFunction} [options.invalidToken.wwwAuthenticateHeader="Bearer error=\"invalid_token\""] - The response header value for the WWW-Authenticate header when token is invalid.
|
|
26
|
-
* @returns {MiddlewareHandler<E>} The middleware handler function.
|
|
27
|
-
* @throws {Error} If neither "token" nor "verifyToken" options are provided.
|
|
28
|
-
* @throws {HTTPException} If authentication fails, with 401 status code for missing or invalid token, or 400 status code for invalid request.
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
* ```ts
|
|
32
|
-
* const app = new Hono()
|
|
33
|
-
*
|
|
34
|
-
* const token = 'honoishot'
|
|
35
|
-
*
|
|
36
|
-
* app.use('/api/*', bearerAuth({ token }))
|
|
37
|
-
*
|
|
38
|
-
* app.get('/api/page', (c) => {
|
|
39
|
-
* return c.json({ message: 'You are authorized' })
|
|
40
|
-
* })
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
7
|
const bearerAuth = (options) => {
|
|
44
8
|
if (!("token" in options || "verifyToken" in options)) throw new Error("bearer auth middleware requires options for \"token\" or \"verifyToken\"");
|
|
45
9
|
if (!options.realm) options.realm = "";
|
|
@@ -66,7 +30,7 @@ const bearerAuth = (options) => {
|
|
|
66
30
|
};
|
|
67
31
|
return async function bearerAuth(c, next) {
|
|
68
32
|
const headerToken = c.req.header(options.headerName || HEADER);
|
|
69
|
-
if (!headerToken) await throwHTTPException(c, 401, options.noAuthenticationHeader?.wwwAuthenticateHeader || `${wwwAuthenticatePrefix}realm="${realm}"`, options.noAuthenticationHeader?.message ||
|
|
33
|
+
if (!headerToken) await throwHTTPException(c, 401, options.noAuthenticationHeader?.wwwAuthenticateHeader || `${wwwAuthenticatePrefix}realm="${realm}"`, options.noAuthenticationHeader?.message || "Unauthorized");
|
|
70
34
|
else {
|
|
71
35
|
let tokenValue;
|
|
72
36
|
if (prefix === "") tokenValue = headerToken;
|
|
@@ -75,7 +39,7 @@ const bearerAuth = (options) => {
|
|
|
75
39
|
const prefixLower = prefix.toLowerCase();
|
|
76
40
|
if (headerLower.startsWith(prefixLower) && headerToken[prefix.length] === " ") tokenValue = headerToken.slice(prefix.length).trimStart();
|
|
77
41
|
}
|
|
78
|
-
if (!tokenValue || !tokenRegexp.test(tokenValue)) await throwHTTPException(c, 400, options.invalidAuthenticationHeader?.wwwAuthenticateHeader || `${wwwAuthenticatePrefix}error="invalid_request"`, options.invalidAuthenticationHeader?.message ||
|
|
42
|
+
if (!tokenValue || !tokenRegexp.test(tokenValue)) await throwHTTPException(c, 400, options.invalidAuthenticationHeader?.wwwAuthenticateHeader || `${wwwAuthenticatePrefix}error="invalid_request"`, options.invalidAuthenticationHeader?.message || "Bad Request");
|
|
79
43
|
else {
|
|
80
44
|
let equal = false;
|
|
81
45
|
if ("verifyToken" in options) equal = await options.verifyToken(tokenValue, c);
|
|
@@ -86,7 +50,7 @@ const bearerAuth = (options) => {
|
|
|
86
50
|
break;
|
|
87
51
|
}
|
|
88
52
|
}
|
|
89
|
-
if (!equal) await throwHTTPException(c, 401, options.invalidToken?.wwwAuthenticateHeader || `${wwwAuthenticatePrefix}error="invalid_token"`, options.invalidToken?.message ||
|
|
53
|
+
if (!equal) await throwHTTPException(c, 401, options.invalidToken?.wwwAuthenticateHeader || `${wwwAuthenticatePrefix}error="invalid_token"`, options.invalidToken?.message || "Unauthorized");
|
|
90
54
|
}
|
|
91
55
|
}
|
|
92
56
|
await next();
|
|
@@ -1,38 +1,6 @@
|
|
|
1
1
|
import { HTTPException } from "../../http-exception.js";
|
|
2
2
|
//#region src/middleware/body-limit/index.ts
|
|
3
3
|
const ERROR_MESSAGE = "Payload Too Large";
|
|
4
|
-
/**
|
|
5
|
-
* Body Limit Middleware for Hono.
|
|
6
|
-
*
|
|
7
|
-
* @see {@link https://hono.dev/docs/middleware/builtin/body-limit}
|
|
8
|
-
*
|
|
9
|
-
* @param {BodyLimitOptions} options - The options for the body limit middleware.
|
|
10
|
-
* @param {number} options.maxSize - The maximum body size allowed.
|
|
11
|
-
* @param {OnError} [options.onError] - The error handler to be invoked if the specified body size is exceeded.
|
|
12
|
-
* @returns {MiddlewareHandler} The middleware handler function.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```ts
|
|
16
|
-
* const app = new Hono()
|
|
17
|
-
*
|
|
18
|
-
* app.post(
|
|
19
|
-
* '/upload',
|
|
20
|
-
* bodyLimit({
|
|
21
|
-
* maxSize: 50 * 1024, // 50kb
|
|
22
|
-
* onError: (c) => {
|
|
23
|
-
* return c.text('overflow :(', 413)
|
|
24
|
-
* },
|
|
25
|
-
* }),
|
|
26
|
-
* async (c) => {
|
|
27
|
-
* const body = await c.req.parseBody()
|
|
28
|
-
* if (body['file'] instanceof File) {
|
|
29
|
-
* console.log(`Got file sized: ${body['file'].size}`)
|
|
30
|
-
* }
|
|
31
|
-
* return c.text('pass :)')
|
|
32
|
-
* }
|
|
33
|
-
* )
|
|
34
|
-
* ```
|
|
35
|
-
*/
|
|
36
4
|
const bodyLimit = (options) => {
|
|
37
5
|
const onError = options.onError || (() => {
|
|
38
6
|
const res = new Response(ERROR_MESSAGE, { status: 413 });
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { sha256 } from "../../utils/crypto.js";
|
|
2
2
|
import { cloneRawRequest } from "../../request.js";
|
|
3
3
|
//#region src/middleware/cache/index.ts
|
|
4
|
-
/**
|
|
5
|
-
* status codes that can be cached by default.
|
|
6
|
-
*/
|
|
7
4
|
const defaultCacheableStatusCodes = [200];
|
|
8
5
|
const defaultMaxQueryBodySize = 65536;
|
|
9
6
|
const cacheKeyPath = "/.hono/cache";
|
|
@@ -69,34 +66,6 @@ const createQueryDigest = async (c, maxQueryBodySize) => {
|
|
|
69
66
|
return;
|
|
70
67
|
}
|
|
71
68
|
};
|
|
72
|
-
/**
|
|
73
|
-
* Cache Middleware for Hono.
|
|
74
|
-
*
|
|
75
|
-
* @see {@link https://hono.dev/docs/middleware/builtin/cache}
|
|
76
|
-
*
|
|
77
|
-
* @param {Object} options - The options for the cache middleware.
|
|
78
|
-
* @param {string | Function} options.cacheName - The name of the cache. Can be used to store multiple caches with different identifiers.
|
|
79
|
-
* @param {boolean} [options.wait=false] - A boolean indicating if Hono should wait for the Promise of the `cache.put` function to resolve before continuing with the request. Required to be true for the Deno environment.
|
|
80
|
-
* @param {string} [options.cacheControl] - A string of directives for the `Cache-Control` header.
|
|
81
|
-
* @param {string | string[]} [options.vary] - Adds the configured request headers to the cache key variants and sets the `Vary` header in the response. If the original response header already contains a `Vary` header, the values are merged, removing any duplicates.
|
|
82
|
-
* @param {Function} [options.keyGenerator] - Generates keys for every request in the `cacheName` store. This can be used to cache data based on request parameters or context parameters. QUERY keys additionally include a digest of the request content and its representation metadata.
|
|
83
|
-
* @param {number} [options.maxQueryBodySize=65536] - The maximum QUERY request body size in bytes that can be cached. Larger QUERY requests bypass the cache.
|
|
84
|
-
* @param {number[]} [options.cacheableStatusCodes=[200]] - An array of status codes that can be cached.
|
|
85
|
-
* @param {Function | false} [options.onCacheNotAvailable] - A callback invoked with the reason when `globalThis.caches` is not available or QUERY caching cannot use Web Crypto. By default, the reason is logged to the console. Set to `false` to suppress the log, or provide a custom function.
|
|
86
|
-
* @returns {MiddlewareHandler} The middleware handler function.
|
|
87
|
-
* @throws {Error} If the `vary` option includes "*".
|
|
88
|
-
*
|
|
89
|
-
* @example
|
|
90
|
-
* ```ts
|
|
91
|
-
* app.use(
|
|
92
|
-
* '*',
|
|
93
|
-
* cache({
|
|
94
|
-
* cacheName: 'my-app',
|
|
95
|
-
* cacheControl: 'max-age=3600',
|
|
96
|
-
* })
|
|
97
|
-
* )
|
|
98
|
-
* ```
|
|
99
|
-
*/
|
|
100
69
|
const cache = (options) => {
|
|
101
70
|
if (!globalThis.caches) {
|
|
102
71
|
reportCacheNotAvailable(options.onCacheNotAvailable, "Cache Middleware is not enabled because caches is not defined.");
|