hono 4.3.11 → 4.4.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 -3
- package/dist/adapter/aws-lambda/handler.js +12 -9
- package/dist/adapter/bun/conninfo.js +21 -0
- package/dist/adapter/bun/index.js +2 -0
- package/dist/adapter/bun/websocket.js +1 -3
- package/dist/adapter/cloudflare-workers/conninfo.js +10 -0
- package/dist/adapter/cloudflare-workers/websocket.js +2 -6
- package/dist/adapter/deno/conninfo.js +15 -0
- package/dist/adapter/deno/index.js +2 -0
- package/dist/adapter/lambda-edge/handler.js +3 -3
- package/dist/cjs/adapter/aws-lambda/handler.js +12 -9
- package/dist/cjs/adapter/bun/conninfo.js +44 -0
- package/dist/cjs/adapter/bun/index.js +3 -0
- package/dist/cjs/adapter/cloudflare-workers/conninfo.js +33 -0
- package/dist/cjs/adapter/cloudflare-workers/websocket.js +2 -6
- package/dist/cjs/adapter/deno/conninfo.js +38 -0
- package/dist/cjs/adapter/deno/index.js +3 -0
- package/dist/cjs/adapter/lambda-edge/handler.js +3 -3
- package/dist/cjs/helper/conninfo/index.js +16 -0
- package/dist/cjs/helper/ssg/ssg.js +64 -3
- package/dist/cjs/helper/streaming/text.js +1 -1
- package/dist/cjs/hono-base.js +10 -6
- package/dist/cjs/jsx/base.js +5 -2
- package/dist/cjs/jsx/dom/client.js +68 -0
- package/dist/cjs/jsx/dom/index.js +8 -4
- package/dist/cjs/jsx/dom/jsx-dev-runtime.js +6 -20
- package/dist/cjs/jsx/dom/render.js +41 -25
- package/dist/cjs/jsx/dom/utils.js +15 -0
- package/dist/cjs/jsx/hooks/index.js +4 -1
- package/dist/cjs/jsx/index.js +8 -4
- package/dist/cjs/middleware/jwt/index.js +5 -82
- package/dist/cjs/middleware/jwt/jwt.js +111 -0
- package/dist/cjs/middleware/secure-headers/index.js +3 -123
- package/dist/cjs/middleware/secure-headers/secure-headers.js +150 -0
- package/dist/cjs/middleware/timeout/index.js +48 -0
- package/dist/cjs/middleware/timing/index.js +5 -89
- package/dist/cjs/middleware/timing/timing.js +118 -0
- package/dist/cjs/utils/body.js +34 -9
- package/dist/cjs/utils/jwt/jws.js +4 -5
- package/dist/cjs/utils/jwt/jwt.js +6 -7
- package/dist/cjs/utils/url.js +26 -2
- package/dist/helper/css/index.js +4 -4
- package/dist/helper/html/index.js +1 -1
- package/dist/helper/ssg/ssg.js +63 -5
- package/dist/helper/streaming/text.js +1 -1
- package/dist/hono-base.js +11 -7
- package/dist/jsx/base.js +3 -1
- package/dist/jsx/dom/client.js +44 -0
- package/dist/jsx/dom/css.js +4 -4
- package/dist/jsx/dom/index.js +25 -21
- package/dist/jsx/dom/jsx-dev-runtime.js +6 -20
- package/dist/jsx/dom/render.js +40 -26
- package/dist/jsx/dom/utils.js +14 -0
- package/dist/jsx/hooks/index.js +4 -2
- package/dist/jsx/index.js +22 -18
- package/dist/jsx/jsx-runtime.js +1 -1
- package/dist/middleware/jsx-renderer/index.js +1 -1
- package/dist/middleware/jwt/index.js +1 -78
- package/dist/middleware/jwt/jwt.js +85 -0
- package/dist/middleware/secure-headers/index.js +1 -121
- package/dist/middleware/secure-headers/secure-headers.js +126 -0
- package/dist/middleware/timeout/index.js +25 -0
- package/dist/middleware/timing/index.js +1 -85
- package/dist/middleware/timing/timing.js +92 -0
- package/dist/request.js +1 -1
- package/dist/router/reg-exp-router/router.js +2 -2
- package/dist/router/smart-router/router.js +1 -1
- package/dist/router/trie-router/node.js +1 -1
- package/dist/types/adapter/aws-lambda/handler.d.ts +3 -3
- package/dist/types/adapter/aws-lambda/index.d.ts +4 -0
- package/dist/types/adapter/bun/conninfo.d.ts +7 -0
- package/dist/types/adapter/bun/index.d.ts +5 -0
- package/dist/types/adapter/bun/websocket.d.ts +2 -3
- package/dist/types/adapter/cloudflare-pages/index.d.ts +4 -0
- package/dist/types/adapter/cloudflare-workers/conninfo.d.ts +2 -0
- package/dist/types/adapter/cloudflare-workers/index.d.ts +4 -0
- package/dist/types/adapter/cloudflare-workers/serve-static-module.d.ts +2 -2
- package/dist/types/adapter/cloudflare-workers/serve-static.d.ts +1 -2
- package/dist/types/adapter/cloudflare-workers/utils.d.ts +1 -2
- package/dist/types/adapter/deno/conninfo.d.ts +7 -0
- package/dist/types/adapter/deno/index.d.ts +5 -0
- package/dist/types/adapter/lambda-edge/handler.d.ts +1 -2
- package/dist/types/adapter/lambda-edge/index.d.ts +4 -0
- package/dist/types/adapter/netlify/handler.d.ts +1 -7
- package/dist/types/adapter/netlify/index.d.ts +4 -0
- package/dist/types/adapter/netlify/mod.d.ts +0 -1
- package/dist/types/adapter/vercel/index.d.ts +4 -0
- package/dist/types/client/index.d.ts +4 -0
- package/dist/types/compose.d.ts +1 -1
- package/dist/types/helper/accepts/index.d.ts +4 -0
- package/dist/types/helper/adapter/index.d.ts +4 -0
- package/dist/types/helper/conninfo/index.d.ts +40 -0
- package/dist/types/helper/cookie/index.d.ts +5 -1
- package/dist/types/helper/css/index.d.ts +4 -0
- package/dist/types/helper/dev/index.d.ts +4 -0
- package/dist/types/helper/factory/index.d.ts +4 -0
- package/dist/types/helper/html/index.d.ts +4 -0
- package/dist/types/helper/ssg/index.d.ts +4 -0
- package/dist/types/helper/ssg/ssg.d.ts +6 -3
- package/dist/types/helper/streaming/index.d.ts +4 -0
- package/dist/types/helper/testing/index.d.ts +4 -0
- package/dist/types/helper/websocket/index.d.ts +4 -0
- package/dist/types/hono-base.d.ts +15 -15
- package/dist/types/http-exception.d.ts +4 -0
- package/dist/types/index.d.ts +15 -0
- package/dist/types/jsx/base.d.ts +10 -11
- package/dist/types/jsx/components.d.ts +1 -1
- package/dist/types/jsx/context.d.ts +1 -1
- package/dist/types/jsx/dom/client.d.ts +26 -0
- package/dist/types/jsx/dom/components.d.ts +2 -2
- package/dist/types/jsx/dom/css.d.ts +31 -20
- package/dist/types/jsx/dom/index.d.ts +13 -7
- package/dist/types/jsx/dom/jsx-dev-runtime.d.ts +5 -1
- package/dist/types/jsx/dom/jsx-runtime.d.ts +4 -0
- package/dist/types/jsx/dom/render.d.ts +4 -3
- package/dist/types/jsx/dom/utils.d.ts +6 -0
- package/dist/types/jsx/hooks/index.d.ts +4 -0
- package/dist/types/jsx/index.d.ts +13 -7
- package/dist/types/jsx/intrinsic-elements.d.ts +629 -630
- package/dist/types/jsx/jsx-dev-runtime.d.ts +5 -0
- package/dist/types/jsx/jsx-runtime.d.ts +5 -0
- package/dist/types/jsx/streaming.d.ts +5 -1
- package/dist/types/jsx/types.d.ts +1 -0
- package/dist/types/middleware/basic-auth/index.d.ts +35 -0
- package/dist/types/middleware/bearer-auth/index.d.ts +33 -0
- package/dist/types/middleware/body-limit/index.d.ts +28 -11
- package/dist/types/middleware/cache/index.d.ts +29 -0
- package/dist/types/middleware/compress/index.d.ts +20 -0
- package/dist/types/middleware/cors/index.d.ts +43 -0
- package/dist/types/middleware/csrf/index.d.ts +41 -0
- package/dist/types/middleware/etag/index.d.ts +24 -0
- package/dist/types/middleware/jsx-renderer/index.d.ts +63 -2
- package/dist/types/middleware/jwt/index.d.ts +5 -17
- package/dist/types/middleware/jwt/jwt.d.ts +48 -0
- package/dist/types/middleware/logger/index.d.ts +20 -0
- package/dist/types/middleware/method-override/index.d.ts +22 -10
- package/dist/types/middleware/powered-by/index.d.ts +4 -0
- package/dist/types/middleware/pretty-json/index.d.ts +23 -0
- package/dist/types/middleware/secure-headers/index.d.ts +6 -64
- package/dist/types/middleware/secure-headers/secure-headers.d.ts +97 -0
- package/dist/types/middleware/serve-static/index.d.ts +4 -0
- package/dist/types/middleware/timeout/index.d.ts +31 -0
- package/dist/types/middleware/timing/index.d.ts +5 -29
- package/dist/types/middleware/timing/timing.d.ts +111 -0
- package/dist/types/middleware/trailing-slash/index.d.ts +29 -5
- package/dist/types/preset/quick.d.ts +4 -0
- package/dist/types/preset/tiny.d.ts +4 -0
- package/dist/types/request.d.ts +5 -4
- package/dist/types/router/linear-router/index.d.ts +4 -0
- package/dist/types/router/linear-router/router.d.ts +1 -1
- package/dist/types/router/pattern-router/index.d.ts +4 -0
- package/dist/types/router/reg-exp-router/index.d.ts +4 -0
- package/dist/types/router/reg-exp-router/router.d.ts +1 -1
- package/dist/types/router/reg-exp-router/trie.d.ts +1 -1
- package/dist/types/router/smart-router/index.d.ts +4 -0
- package/dist/types/router/smart-router/router.d.ts +1 -1
- package/dist/types/router/trie-router/index.d.ts +4 -0
- package/dist/types/router.d.ts +4 -0
- package/dist/types/types.d.ts +4 -0
- package/dist/types/utils/body.d.ts +61 -3
- package/dist/types/utils/buffer.d.ts +4 -0
- package/dist/types/utils/color.d.ts +4 -0
- package/dist/types/utils/concurrent.d.ts +4 -0
- package/dist/types/utils/cookie.d.ts +4 -0
- package/dist/types/utils/crypto.d.ts +4 -0
- package/dist/types/utils/encode.d.ts +4 -0
- package/dist/types/utils/filepath.d.ts +4 -0
- package/dist/types/utils/handler.d.ts +4 -0
- package/dist/types/utils/html.d.ts +4 -0
- package/dist/types/utils/http-status.d.ts +4 -0
- package/dist/types/utils/jwt/index.d.ts +4 -0
- package/dist/types/utils/jwt/jwt.d.ts +3 -3
- package/dist/types/utils/mime.d.ts +4 -0
- package/dist/types/utils/stream.d.ts +4 -0
- package/dist/types/utils/types.d.ts +4 -0
- package/dist/types/utils/url.d.ts +4 -0
- package/dist/types/validator/index.d.ts +4 -0
- package/dist/types/validator/validator.d.ts +1 -1
- package/dist/utils/body.js +34 -9
- package/dist/utils/jwt/index.js +1 -1
- package/dist/utils/jwt/jws.js +1 -2
- package/dist/utils/jwt/jwt.js +5 -5
- package/dist/utils/url.js +26 -2
- package/package.json +27 -6
- package/dist/cjs/adapter/aws-lambda/awslambda.d.js +0 -1
- package/dist/cjs/helper.js +0 -44
- package/dist/helper.js +0 -18
- /package/dist/{adapter/aws-lambda/awslambda.d.js → helper/conninfo/index.js} +0 -0
|
@@ -1,66 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
export type { ContentSecurityPolicyOptionHandler } from './secure-headers';
|
|
2
|
+
export { NONCE, secureHeaders } from './secure-headers';
|
|
3
|
+
import type { SecureHeadersVariables } from './secure-headers';
|
|
4
|
+
export type { SecureHeadersVariables };
|
|
5
|
+
declare module '../..' {
|
|
6
|
+
interface ContextVariableMap extends SecureHeadersVariables {
|
|
6
7
|
}
|
|
7
8
|
}
|
|
8
|
-
export type ContentSecurityPolicyOptionHandler = (ctx: Context, directive: string) => string;
|
|
9
|
-
type ContentSecurityPolicyOptionValue = (string | ContentSecurityPolicyOptionHandler)[];
|
|
10
|
-
interface ContentSecurityPolicyOptions {
|
|
11
|
-
defaultSrc?: ContentSecurityPolicyOptionValue;
|
|
12
|
-
baseUri?: ContentSecurityPolicyOptionValue;
|
|
13
|
-
childSrc?: ContentSecurityPolicyOptionValue;
|
|
14
|
-
connectSrc?: ContentSecurityPolicyOptionValue;
|
|
15
|
-
fontSrc?: ContentSecurityPolicyOptionValue;
|
|
16
|
-
formAction?: ContentSecurityPolicyOptionValue;
|
|
17
|
-
frameAncestors?: ContentSecurityPolicyOptionValue;
|
|
18
|
-
frameSrc?: ContentSecurityPolicyOptionValue;
|
|
19
|
-
imgSrc?: ContentSecurityPolicyOptionValue;
|
|
20
|
-
manifestSrc?: ContentSecurityPolicyOptionValue;
|
|
21
|
-
mediaSrc?: ContentSecurityPolicyOptionValue;
|
|
22
|
-
objectSrc?: ContentSecurityPolicyOptionValue;
|
|
23
|
-
reportTo?: string;
|
|
24
|
-
sandbox?: ContentSecurityPolicyOptionValue;
|
|
25
|
-
scriptSrc?: ContentSecurityPolicyOptionValue;
|
|
26
|
-
scriptSrcAttr?: ContentSecurityPolicyOptionValue;
|
|
27
|
-
scriptSrcElem?: ContentSecurityPolicyOptionValue;
|
|
28
|
-
styleSrc?: ContentSecurityPolicyOptionValue;
|
|
29
|
-
styleSrcAttr?: ContentSecurityPolicyOptionValue;
|
|
30
|
-
styleSrcElem?: ContentSecurityPolicyOptionValue;
|
|
31
|
-
upgradeInsecureRequests?: ContentSecurityPolicyOptionValue;
|
|
32
|
-
workerSrc?: ContentSecurityPolicyOptionValue;
|
|
33
|
-
}
|
|
34
|
-
interface ReportToOptions {
|
|
35
|
-
group: string;
|
|
36
|
-
max_age: number;
|
|
37
|
-
endpoints: ReportToEndpoint[];
|
|
38
|
-
}
|
|
39
|
-
interface ReportToEndpoint {
|
|
40
|
-
url: string;
|
|
41
|
-
}
|
|
42
|
-
interface ReportingEndpointOptions {
|
|
43
|
-
name: string;
|
|
44
|
-
url: string;
|
|
45
|
-
}
|
|
46
|
-
type overridableHeader = boolean | string;
|
|
47
|
-
interface SecureHeadersOptions {
|
|
48
|
-
contentSecurityPolicy?: ContentSecurityPolicyOptions;
|
|
49
|
-
crossOriginEmbedderPolicy?: overridableHeader;
|
|
50
|
-
crossOriginResourcePolicy?: overridableHeader;
|
|
51
|
-
crossOriginOpenerPolicy?: overridableHeader;
|
|
52
|
-
originAgentCluster?: overridableHeader;
|
|
53
|
-
referrerPolicy?: overridableHeader;
|
|
54
|
-
reportingEndpoints?: ReportingEndpointOptions[];
|
|
55
|
-
reportTo?: ReportToOptions[];
|
|
56
|
-
strictTransportSecurity?: overridableHeader;
|
|
57
|
-
xContentTypeOptions?: overridableHeader;
|
|
58
|
-
xDnsPrefetchControl?: overridableHeader;
|
|
59
|
-
xDownloadOptions?: overridableHeader;
|
|
60
|
-
xFrameOptions?: overridableHeader;
|
|
61
|
-
xPermittedCrossDomainPolicies?: overridableHeader;
|
|
62
|
-
xXssProtection?: overridableHeader;
|
|
63
|
-
}
|
|
64
|
-
export declare const NONCE: ContentSecurityPolicyOptionHandler;
|
|
65
|
-
export declare const secureHeaders: (customOptions?: SecureHeadersOptions) => MiddlewareHandler;
|
|
66
|
-
export {};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* Secure Headers Middleware for Hono.
|
|
4
|
+
*/
|
|
5
|
+
import type { Context } from '../../context';
|
|
6
|
+
import type { MiddlewareHandler } from '../../types';
|
|
7
|
+
export type SecureHeadersVariables = {
|
|
8
|
+
secureHeadersNonce?: string;
|
|
9
|
+
};
|
|
10
|
+
export type ContentSecurityPolicyOptionHandler = (ctx: Context, directive: string) => string;
|
|
11
|
+
type ContentSecurityPolicyOptionValue = (string | ContentSecurityPolicyOptionHandler)[];
|
|
12
|
+
interface ContentSecurityPolicyOptions {
|
|
13
|
+
defaultSrc?: ContentSecurityPolicyOptionValue;
|
|
14
|
+
baseUri?: ContentSecurityPolicyOptionValue;
|
|
15
|
+
childSrc?: ContentSecurityPolicyOptionValue;
|
|
16
|
+
connectSrc?: ContentSecurityPolicyOptionValue;
|
|
17
|
+
fontSrc?: ContentSecurityPolicyOptionValue;
|
|
18
|
+
formAction?: ContentSecurityPolicyOptionValue;
|
|
19
|
+
frameAncestors?: ContentSecurityPolicyOptionValue;
|
|
20
|
+
frameSrc?: ContentSecurityPolicyOptionValue;
|
|
21
|
+
imgSrc?: ContentSecurityPolicyOptionValue;
|
|
22
|
+
manifestSrc?: ContentSecurityPolicyOptionValue;
|
|
23
|
+
mediaSrc?: ContentSecurityPolicyOptionValue;
|
|
24
|
+
objectSrc?: ContentSecurityPolicyOptionValue;
|
|
25
|
+
reportTo?: string;
|
|
26
|
+
sandbox?: ContentSecurityPolicyOptionValue;
|
|
27
|
+
scriptSrc?: ContentSecurityPolicyOptionValue;
|
|
28
|
+
scriptSrcAttr?: ContentSecurityPolicyOptionValue;
|
|
29
|
+
scriptSrcElem?: ContentSecurityPolicyOptionValue;
|
|
30
|
+
styleSrc?: ContentSecurityPolicyOptionValue;
|
|
31
|
+
styleSrcAttr?: ContentSecurityPolicyOptionValue;
|
|
32
|
+
styleSrcElem?: ContentSecurityPolicyOptionValue;
|
|
33
|
+
upgradeInsecureRequests?: ContentSecurityPolicyOptionValue;
|
|
34
|
+
workerSrc?: ContentSecurityPolicyOptionValue;
|
|
35
|
+
}
|
|
36
|
+
interface ReportToOptions {
|
|
37
|
+
group: string;
|
|
38
|
+
max_age: number;
|
|
39
|
+
endpoints: ReportToEndpoint[];
|
|
40
|
+
}
|
|
41
|
+
interface ReportToEndpoint {
|
|
42
|
+
url: string;
|
|
43
|
+
}
|
|
44
|
+
interface ReportingEndpointOptions {
|
|
45
|
+
name: string;
|
|
46
|
+
url: string;
|
|
47
|
+
}
|
|
48
|
+
type overridableHeader = boolean | string;
|
|
49
|
+
interface SecureHeadersOptions {
|
|
50
|
+
contentSecurityPolicy?: ContentSecurityPolicyOptions;
|
|
51
|
+
crossOriginEmbedderPolicy?: overridableHeader;
|
|
52
|
+
crossOriginResourcePolicy?: overridableHeader;
|
|
53
|
+
crossOriginOpenerPolicy?: overridableHeader;
|
|
54
|
+
originAgentCluster?: overridableHeader;
|
|
55
|
+
referrerPolicy?: overridableHeader;
|
|
56
|
+
reportingEndpoints?: ReportingEndpointOptions[];
|
|
57
|
+
reportTo?: ReportToOptions[];
|
|
58
|
+
strictTransportSecurity?: overridableHeader;
|
|
59
|
+
xContentTypeOptions?: overridableHeader;
|
|
60
|
+
xDnsPrefetchControl?: overridableHeader;
|
|
61
|
+
xDownloadOptions?: overridableHeader;
|
|
62
|
+
xFrameOptions?: overridableHeader;
|
|
63
|
+
xPermittedCrossDomainPolicies?: overridableHeader;
|
|
64
|
+
xXssProtection?: overridableHeader;
|
|
65
|
+
}
|
|
66
|
+
export declare const NONCE: ContentSecurityPolicyOptionHandler;
|
|
67
|
+
/**
|
|
68
|
+
* Secure Headers Middleware for Hono.
|
|
69
|
+
*
|
|
70
|
+
* @see {@link https://hono.dev/middleware/builtin/secure-headers}
|
|
71
|
+
*
|
|
72
|
+
* @param {Partial<SecureHeadersOptions>} [customOptions] - The options for the secure headers middleware.
|
|
73
|
+
* @param {ContentSecurityPolicyOptions} [customOptions.contentSecurityPolicy] - Settings for the Content-Security-Policy header.
|
|
74
|
+
* @param {overridableHeader} [customOptions.crossOriginEmbedderPolicy=false] - Settings for the Cross-Origin-Embedder-Policy header.
|
|
75
|
+
* @param {overridableHeader} [customOptions.crossOriginResourcePolicy=true] - Settings for the Cross-Origin-Resource-Policy header.
|
|
76
|
+
* @param {overridableHeader} [customOptions.crossOriginOpenerPolicy=true] - Settings for the Cross-Origin-Opener-Policy header.
|
|
77
|
+
* @param {overridableHeader} [customOptions.originAgentCluster=true] - Settings for the Origin-Agent-Cluster header.
|
|
78
|
+
* @param {overridableHeader} [customOptions.referrerPolicy=true] - Settings for the Referrer-Policy header.
|
|
79
|
+
* @param {ReportingEndpointOptions[]} [customOptions.reportingEndpoints] - Settings for the Reporting-Endpoints header.
|
|
80
|
+
* @param {ReportToOptions[]} [customOptions.reportTo] - Settings for the Report-To header.
|
|
81
|
+
* @param {overridableHeader} [customOptions.strictTransportSecurity=true] - Settings for the Strict-Transport-Security header.
|
|
82
|
+
* @param {overridableHeader} [customOptions.xContentTypeOptions=true] - Settings for the X-Content-Type-Options header.
|
|
83
|
+
* @param {overridableHeader} [customOptions.xDnsPrefetchControl=true] - Settings for the X-DNS-Prefetch-Control header.
|
|
84
|
+
* @param {overridableHeader} [customOptions.xDownloadOptions=true] - Settings for the X-Download-Options header.
|
|
85
|
+
* @param {overridableHeader} [customOptions.xFrameOptions=true] - Settings for the X-Frame-Options header.
|
|
86
|
+
* @param {overridableHeader} [customOptions.xPermittedCrossDomainPolicies=true] - Settings for the X-Permitted-Cross-Domain-Policies header.
|
|
87
|
+
* @param {overridableHeader} [customOptions.xXssProtection=true] - Settings for the X-XSS-Protection header.
|
|
88
|
+
* @returns {MiddlewareHandler} The middleware handler function.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```ts
|
|
92
|
+
* const app = new Hono()
|
|
93
|
+
* app.use(secureHeaders())
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
export declare const secureHeaders: (customOptions?: SecureHeadersOptions) => MiddlewareHandler;
|
|
97
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* Timeout Middleware for Hono.
|
|
4
|
+
*/
|
|
5
|
+
import type { Context } from '../../context';
|
|
6
|
+
import { HTTPException } from '../../http-exception';
|
|
7
|
+
import type { MiddlewareHandler } from '../../types';
|
|
8
|
+
export type HTTPExceptionFunction = (context: Context) => HTTPException;
|
|
9
|
+
/**
|
|
10
|
+
* Timeout Middleware for Hono.
|
|
11
|
+
*
|
|
12
|
+
* @param {number} duration - The timeout duration in milliseconds.
|
|
13
|
+
* @param {HTTPExceptionFunction | HTTPException} [exception=defaultTimeoutException] - The exception to throw when the timeout occurs. Can be a function that returns an HTTPException or an HTTPException object.
|
|
14
|
+
* @returns {MiddlewareHandler} The middleware handler function.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* const app = new Hono()
|
|
19
|
+
*
|
|
20
|
+
* app.use(
|
|
21
|
+
* '/long-request',
|
|
22
|
+
* timeout(5000) // Set timeout to 5 seconds
|
|
23
|
+
* )
|
|
24
|
+
*
|
|
25
|
+
* app.get('/long-request', async (c) => {
|
|
26
|
+
* await someLongRunningFunction()
|
|
27
|
+
* return c.text('Completed within time limit')
|
|
28
|
+
* })
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare const timeout: (duration: number, exception?: HTTPExceptionFunction | HTTPException) => MiddlewareHandler;
|
|
@@ -1,31 +1,7 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
declare module '
|
|
5
|
-
interface ContextVariableMap {
|
|
6
|
-
metric?: {
|
|
7
|
-
headers: string[];
|
|
8
|
-
timers: Map<string, Timer>;
|
|
9
|
-
};
|
|
1
|
+
import type { TimingVariables } from './timing';
|
|
2
|
+
export { TimingVariables };
|
|
3
|
+
export { timing, setMetric, startTime, endTime } from './timing';
|
|
4
|
+
declare module '../..' {
|
|
5
|
+
interface ContextVariableMap extends TimingVariables {
|
|
10
6
|
}
|
|
11
7
|
}
|
|
12
|
-
interface Timer {
|
|
13
|
-
description?: string;
|
|
14
|
-
start: number;
|
|
15
|
-
}
|
|
16
|
-
interface TimingOptions {
|
|
17
|
-
total?: boolean;
|
|
18
|
-
enabled?: boolean | ((c: Context) => boolean);
|
|
19
|
-
totalDescription?: string;
|
|
20
|
-
autoEnd?: boolean;
|
|
21
|
-
crossOrigin?: boolean | string | ((c: Context) => boolean | string);
|
|
22
|
-
}
|
|
23
|
-
export declare const timing: (config?: TimingOptions) => MiddlewareHandler;
|
|
24
|
-
interface SetMetric {
|
|
25
|
-
(c: Context, name: string, value: number, description?: string, precision?: number): void;
|
|
26
|
-
(c: Context, name: string, description?: string): void;
|
|
27
|
-
}
|
|
28
|
-
export declare const setMetric: SetMetric;
|
|
29
|
-
export declare const startTime: (c: Context, name: string, description?: string) => void;
|
|
30
|
-
export declare const endTime: (c: Context, name: string, precision?: number) => void;
|
|
31
|
-
export {};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* Server-Timing Middleware for Hono.
|
|
4
|
+
*/
|
|
5
|
+
import type { Context } from '../../context';
|
|
6
|
+
import type { MiddlewareHandler } from '../../types';
|
|
7
|
+
import '../../context';
|
|
8
|
+
export type TimingVariables = {
|
|
9
|
+
metric?: {
|
|
10
|
+
headers: string[];
|
|
11
|
+
timers: Map<string, Timer>;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
interface Timer {
|
|
15
|
+
description?: string;
|
|
16
|
+
start: number;
|
|
17
|
+
}
|
|
18
|
+
interface TimingOptions {
|
|
19
|
+
total?: boolean;
|
|
20
|
+
enabled?: boolean | ((c: Context) => boolean);
|
|
21
|
+
totalDescription?: string;
|
|
22
|
+
autoEnd?: boolean;
|
|
23
|
+
crossOrigin?: boolean | string | ((c: Context) => boolean | string);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Server-Timing Middleware for Hono.
|
|
27
|
+
*
|
|
28
|
+
* @see {@link https://hono.dev/middleware/builtin/timing}
|
|
29
|
+
*
|
|
30
|
+
* @param {TimingOptions} [config] - The options for the timing middleware.
|
|
31
|
+
* @param {boolean} [config.total=true] - Show the total response time.
|
|
32
|
+
* @param {boolean | ((c: Context) => boolean)} [config.enabled=true] - Whether timings should be added to the headers or not.
|
|
33
|
+
* @param {string} [config.totalDescription=Total Response Time] - Description for the total response time.
|
|
34
|
+
* @param {boolean} [config.autoEnd=true] - If `startTime()` should end automatically at the end of the request.
|
|
35
|
+
* @param {boolean | string | ((c: Context) => boolean | string)} [config.crossOrigin=false] - The origin this timings header should be readable.
|
|
36
|
+
* @returns {MiddlewareHandler} The middleware handler function.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* const app = new Hono()
|
|
41
|
+
*
|
|
42
|
+
* // add the middleware to your router
|
|
43
|
+
* app.use(timing());
|
|
44
|
+
*
|
|
45
|
+
* app.get('/', async (c) => {
|
|
46
|
+
* // add custom metrics
|
|
47
|
+
* setMetric(c, 'region', 'europe-west3')
|
|
48
|
+
*
|
|
49
|
+
* // add custom metrics with timing, must be in milliseconds
|
|
50
|
+
* setMetric(c, 'custom', 23.8, 'My custom Metric')
|
|
51
|
+
*
|
|
52
|
+
* // start a new timer
|
|
53
|
+
* startTime(c, 'db');
|
|
54
|
+
*
|
|
55
|
+
* const data = await db.findMany(...);
|
|
56
|
+
*
|
|
57
|
+
* // end the timer
|
|
58
|
+
* endTime(c, 'db');
|
|
59
|
+
*
|
|
60
|
+
* return c.json({ response: data });
|
|
61
|
+
* });
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export declare const timing: (config?: TimingOptions) => MiddlewareHandler;
|
|
65
|
+
interface SetMetric {
|
|
66
|
+
(c: Context, name: string, value: number, description?: string, precision?: number): void;
|
|
67
|
+
(c: Context, name: string, description?: string): void;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Set a metric for the timing middleware.
|
|
71
|
+
*
|
|
72
|
+
* @param {Context} c - The context of the request.
|
|
73
|
+
* @param {string} name - The name of the metric.
|
|
74
|
+
* @param {number | string} [valueDescription] - The value or description of the metric.
|
|
75
|
+
* @param {string} [description] - The description of the metric.
|
|
76
|
+
* @param {number} [precision] - The precision of the metric value.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```ts
|
|
80
|
+
* setMetric(c, 'region', 'europe-west3')
|
|
81
|
+
* setMetric(c, 'custom', 23.8, 'My custom Metric')
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
export declare const setMetric: SetMetric;
|
|
85
|
+
/**
|
|
86
|
+
* Start a timer for the timing middleware.
|
|
87
|
+
*
|
|
88
|
+
* @param {Context} c - The context of the request.
|
|
89
|
+
* @param {string} name - The name of the timer.
|
|
90
|
+
* @param {string} [description] - The description of the timer.
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```ts
|
|
94
|
+
* startTime(c, 'db')
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
export declare const startTime: (c: Context, name: string, description?: string) => void;
|
|
98
|
+
/**
|
|
99
|
+
* End a timer for the timing middleware.
|
|
100
|
+
*
|
|
101
|
+
* @param {Context} c - The context of the request.
|
|
102
|
+
* @param {string} name - The name of the timer.
|
|
103
|
+
* @param {number} [precision] - The precision of the timer value.
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```ts
|
|
107
|
+
* endTime(c, 'db')
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
export declare const endTime: (c: Context, name: string, precision?: number) => void;
|
|
111
|
+
export {};
|
|
@@ -1,13 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* Trailing Slash Middleware for Hono.
|
|
4
|
+
*/
|
|
1
5
|
import type { MiddlewareHandler } from '../../types';
|
|
2
6
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* @
|
|
7
|
+
* Trailing Slash Middleware for Hono.
|
|
8
|
+
*
|
|
9
|
+
* @see {@link https://hono.dev/middleware/builtin/trailing-slash}
|
|
10
|
+
*
|
|
11
|
+
* @returns {MiddlewareHandler} The middleware handler function.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* const app = new Hono()
|
|
16
|
+
*
|
|
17
|
+
* app.use(trimTrailingSlash())
|
|
18
|
+
* app.get('/about/me/', (c) => c.text('With Trailing Slash'))
|
|
19
|
+
* ```
|
|
6
20
|
*/
|
|
7
21
|
export declare const trimTrailingSlash: () => MiddlewareHandler;
|
|
8
22
|
/**
|
|
23
|
+
* Append trailing slash middleware for Hono.
|
|
9
24
|
* Append a trailing slash to the URL if it doesn't have one. For example, `/path/to/page` will be redirected to `/path/to/page/`.
|
|
10
|
-
*
|
|
11
|
-
* @
|
|
25
|
+
*
|
|
26
|
+
* @see {@link https://hono.dev/middleware/builtin/trailing-slash}
|
|
27
|
+
*
|
|
28
|
+
* @returns {MiddlewareHandler} The middleware handler function.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* const app = new Hono()
|
|
33
|
+
*
|
|
34
|
+
* app.use(appendTrailingSlash())
|
|
35
|
+
* ```
|
|
12
36
|
*/
|
|
13
37
|
export declare const appendTrailingSlash: () => MiddlewareHandler;
|
package/dist/types/request.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Result } from './router';
|
|
2
|
-
import type { Input, InputToDataByTarget,
|
|
2
|
+
import type { Input, InputToDataByTarget, ParamKeyToRecord, ParamKeys, RemoveQuestion, RouterRoute, ValidationTargets } from './types';
|
|
3
3
|
import type { BodyData, ParseBodyOptions } from './utils/body';
|
|
4
|
-
import type { UnionToIntersection } from './utils/types';
|
|
4
|
+
import type { Simplify, UnionToIntersection } from './utils/types';
|
|
5
5
|
type Body = {
|
|
6
6
|
json: any;
|
|
7
7
|
text: string;
|
|
@@ -54,7 +54,7 @@ export declare class HonoRequest<P extends string = '/', I extends Input['out']
|
|
|
54
54
|
param<P2 extends ParamKeys<P> = ParamKeys<P>>(key: P2 extends `${infer _}?` ? never : P2): string;
|
|
55
55
|
param<P2 extends RemoveQuestion<ParamKeys<P>> = RemoveQuestion<ParamKeys<P>>>(key: P2): string | undefined;
|
|
56
56
|
param(key: string): string | undefined;
|
|
57
|
-
param<P2 extends string = P>(): UnionToIntersection<ParamKeyToRecord<ParamKeys<P2
|
|
57
|
+
param<P2 extends string = P>(): Simplify<UnionToIntersection<ParamKeyToRecord<ParamKeys<P2>>>>;
|
|
58
58
|
private getDecodedParam;
|
|
59
59
|
private getAllDecodedParams;
|
|
60
60
|
private getParamValue;
|
|
@@ -111,7 +111,8 @@ export declare class HonoRequest<P extends string = '/', I extends Input['out']
|
|
|
111
111
|
* ```
|
|
112
112
|
* @see https://hono.dev/api/request#parsebody
|
|
113
113
|
*/
|
|
114
|
-
parseBody<
|
|
114
|
+
parseBody<Options extends Partial<ParseBodyOptions>, T extends BodyData<Options>>(options?: Options): Promise<T>;
|
|
115
|
+
parseBody<T extends BodyData>(options?: Partial<ParseBodyOptions>): Promise<T>;
|
|
115
116
|
private cachedBody;
|
|
116
117
|
/**
|
|
117
118
|
* `.json()` can parse Request body of type `application/json`
|
package/dist/types/router.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* This module provides types definitions and variables for the routers.
|
|
4
|
+
*/
|
|
1
5
|
export declare const METHOD_NAME_ALL: "ALL";
|
|
2
6
|
export declare const METHOD_NAME_ALL_LOWERCASE: "all";
|
|
3
7
|
export declare const METHODS: readonly ["get", "post", "put", "delete", "options", "patch"];
|
package/dist/types/types.d.ts
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* Body utility.
|
|
4
|
+
*/
|
|
1
5
|
import { HonoRequest } from '../request';
|
|
2
|
-
|
|
6
|
+
type BodyDataValueDot = {
|
|
7
|
+
[x: string]: string | File | BodyDataValueDot;
|
|
8
|
+
} & {};
|
|
9
|
+
type BodyDataValueDotAll = {
|
|
10
|
+
[x: string]: string | File | (string | File)[] | BodyDataValueDotAll;
|
|
11
|
+
} & {};
|
|
12
|
+
type SimplifyBodyData<T> = {
|
|
13
|
+
[K in keyof T]: string | File | (string | File)[] | BodyDataValueDotAll extends T[K] ? string | File | (string | File)[] | BodyDataValueDotAll : string | File | BodyDataValueDot extends T[K] ? string | File | BodyDataValueDot : string | File | (string | File)[] extends T[K] ? string | File | (string | File)[] : string | File;
|
|
14
|
+
} & {};
|
|
15
|
+
type BodyDataValueComponent<T> = string | File | (T extends {
|
|
16
|
+
all: false;
|
|
17
|
+
} ? never : T extends {
|
|
18
|
+
all: true;
|
|
19
|
+
} | {
|
|
20
|
+
all: boolean;
|
|
21
|
+
} ? (string | File)[] : never);
|
|
22
|
+
type BodyDataValueObject<T> = {
|
|
23
|
+
[key: string]: BodyDataValueComponent<T> | BodyDataValueObject<T>;
|
|
24
|
+
};
|
|
25
|
+
type BodyDataValue<T> = BodyDataValueComponent<T> | (T extends {
|
|
26
|
+
dot: false;
|
|
27
|
+
} ? never : T extends {
|
|
28
|
+
dot: true;
|
|
29
|
+
} | {
|
|
30
|
+
dot: boolean;
|
|
31
|
+
} ? BodyDataValueObject<T> : never);
|
|
32
|
+
export type BodyData<T extends Partial<ParseBodyOptions> = {}> = SimplifyBodyData<Record<string, BodyDataValue<T>>>;
|
|
3
33
|
export type ParseBodyOptions = {
|
|
4
34
|
/**
|
|
5
35
|
* Determines whether all fields with multiple values should be parsed as arrays.
|
|
@@ -16,6 +46,34 @@ export type ParseBodyOptions = {
|
|
|
16
46
|
* If all is true:
|
|
17
47
|
* parseBody should return { file: ['aaa', 'bbb'], message: 'hello' }
|
|
18
48
|
*/
|
|
19
|
-
all
|
|
49
|
+
all: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Determines whether all fields with dot notation should be parsed as nested objects.
|
|
52
|
+
* @default false
|
|
53
|
+
* @example
|
|
54
|
+
* const data = new FormData()
|
|
55
|
+
* data.append('obj.key1', 'value1')
|
|
56
|
+
* data.append('obj.key2', 'value2')
|
|
57
|
+
*
|
|
58
|
+
* If dot is false:
|
|
59
|
+
* parseBody should return { 'obj.key1': 'value1', 'obj.key2': 'value2' }
|
|
60
|
+
*
|
|
61
|
+
* If dot is true:
|
|
62
|
+
* parseBody should return { obj: { key1: 'value1', key2: 'value2' } }
|
|
63
|
+
*/
|
|
64
|
+
dot: boolean;
|
|
20
65
|
};
|
|
21
|
-
|
|
66
|
+
/**
|
|
67
|
+
* Parses the body of a request based on the provided options.
|
|
68
|
+
*
|
|
69
|
+
* @template T - The type of the parsed body data.
|
|
70
|
+
* @param {HonoRequest | Request} request - The request object to parse.
|
|
71
|
+
* @param {Partial<ParseBodyOptions>} [options] - Options for parsing the body.
|
|
72
|
+
* @returns {Promise<T>} The parsed body data.
|
|
73
|
+
*/
|
|
74
|
+
interface ParseBody {
|
|
75
|
+
<Options extends Partial<ParseBodyOptions>, T extends BodyData<Options>>(request: HonoRequest | Request, options?: Options): Promise<T>;
|
|
76
|
+
<T extends BodyData>(request: HonoRequest | Request, options?: Partial<ParseBodyOptions>): Promise<T>;
|
|
77
|
+
}
|
|
78
|
+
export declare const parseBody: ParseBody;
|
|
79
|
+
export {};
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* Buffer utility.
|
|
4
|
+
*/
|
|
1
5
|
export declare const equal: (a: ArrayBuffer, b: ArrayBuffer) => boolean;
|
|
2
6
|
export declare const timingSafeEqual: (a: string | object | boolean, b: string | object | boolean, hashFunction?: Function) => Promise<boolean>;
|
|
3
7
|
export declare const bufferToString: (buffer: ArrayBuffer) => string;
|