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
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// src/middleware/secure-headers/secure-headers.ts
|
|
2
|
+
import { encodeBase64 } from "../../utils/encode.js";
|
|
3
|
+
var HEADERS_MAP = {
|
|
4
|
+
crossOriginEmbedderPolicy: ["Cross-Origin-Embedder-Policy", "require-corp"],
|
|
5
|
+
crossOriginResourcePolicy: ["Cross-Origin-Resource-Policy", "same-origin"],
|
|
6
|
+
crossOriginOpenerPolicy: ["Cross-Origin-Opener-Policy", "same-origin"],
|
|
7
|
+
originAgentCluster: ["Origin-Agent-Cluster", "?1"],
|
|
8
|
+
referrerPolicy: ["Referrer-Policy", "no-referrer"],
|
|
9
|
+
strictTransportSecurity: ["Strict-Transport-Security", "max-age=15552000; includeSubDomains"],
|
|
10
|
+
xContentTypeOptions: ["X-Content-Type-Options", "nosniff"],
|
|
11
|
+
xDnsPrefetchControl: ["X-DNS-Prefetch-Control", "off"],
|
|
12
|
+
xDownloadOptions: ["X-Download-Options", "noopen"],
|
|
13
|
+
xFrameOptions: ["X-Frame-Options", "SAMEORIGIN"],
|
|
14
|
+
xPermittedCrossDomainPolicies: ["X-Permitted-Cross-Domain-Policies", "none"],
|
|
15
|
+
xXssProtection: ["X-XSS-Protection", "0"]
|
|
16
|
+
};
|
|
17
|
+
var DEFAULT_OPTIONS = {
|
|
18
|
+
crossOriginEmbedderPolicy: false,
|
|
19
|
+
crossOriginResourcePolicy: true,
|
|
20
|
+
crossOriginOpenerPolicy: true,
|
|
21
|
+
originAgentCluster: true,
|
|
22
|
+
referrerPolicy: true,
|
|
23
|
+
strictTransportSecurity: true,
|
|
24
|
+
xContentTypeOptions: true,
|
|
25
|
+
xDnsPrefetchControl: true,
|
|
26
|
+
xDownloadOptions: true,
|
|
27
|
+
xFrameOptions: true,
|
|
28
|
+
xPermittedCrossDomainPolicies: true,
|
|
29
|
+
xXssProtection: true
|
|
30
|
+
};
|
|
31
|
+
var generateNonce = () => {
|
|
32
|
+
const buffer = new Uint8Array(16);
|
|
33
|
+
crypto.getRandomValues(buffer);
|
|
34
|
+
return encodeBase64(buffer);
|
|
35
|
+
};
|
|
36
|
+
var NONCE = (ctx) => {
|
|
37
|
+
const nonce = ctx.get("secureHeadersNonce") || (() => {
|
|
38
|
+
const newNonce = generateNonce();
|
|
39
|
+
ctx.set("secureHeadersNonce", newNonce);
|
|
40
|
+
return newNonce;
|
|
41
|
+
})();
|
|
42
|
+
return `'nonce-${nonce}'`;
|
|
43
|
+
};
|
|
44
|
+
var secureHeaders = (customOptions) => {
|
|
45
|
+
const options = { ...DEFAULT_OPTIONS, ...customOptions };
|
|
46
|
+
const headersToSet = getFilteredHeaders(options);
|
|
47
|
+
const callbacks = [];
|
|
48
|
+
if (options.contentSecurityPolicy) {
|
|
49
|
+
const [callback, value] = getCSPDirectives(options.contentSecurityPolicy);
|
|
50
|
+
if (callback) {
|
|
51
|
+
callbacks.push(callback);
|
|
52
|
+
}
|
|
53
|
+
headersToSet.push(["Content-Security-Policy", value]);
|
|
54
|
+
}
|
|
55
|
+
if (options.reportingEndpoints) {
|
|
56
|
+
headersToSet.push(["Reporting-Endpoints", getReportingEndpoints(options.reportingEndpoints)]);
|
|
57
|
+
}
|
|
58
|
+
if (options.reportTo) {
|
|
59
|
+
headersToSet.push(["Report-To", getReportToOptions(options.reportTo)]);
|
|
60
|
+
}
|
|
61
|
+
return async function secureHeaders2(ctx, next) {
|
|
62
|
+
const headersToSetForReq = callbacks.length === 0 ? headersToSet : callbacks.reduce((acc, cb) => cb(ctx, acc), headersToSet);
|
|
63
|
+
await next();
|
|
64
|
+
setHeaders(ctx, headersToSetForReq);
|
|
65
|
+
ctx.res.headers.delete("X-Powered-By");
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
function getFilteredHeaders(options) {
|
|
69
|
+
return Object.entries(HEADERS_MAP).filter(([key]) => options[key]).map(([key, defaultValue]) => {
|
|
70
|
+
const overrideValue = options[key];
|
|
71
|
+
return typeof overrideValue === "string" ? [defaultValue[0], overrideValue] : defaultValue;
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
function getCSPDirectives(contentSecurityPolicy) {
|
|
75
|
+
const callbacks = [];
|
|
76
|
+
const resultValues = [];
|
|
77
|
+
for (const [directive, value] of Object.entries(contentSecurityPolicy)) {
|
|
78
|
+
const valueArray = Array.isArray(value) ? value : [value];
|
|
79
|
+
valueArray.forEach((value2, i) => {
|
|
80
|
+
if (typeof value2 === "function") {
|
|
81
|
+
const index = i * 2 + 2 + resultValues.length;
|
|
82
|
+
callbacks.push((ctx, values) => {
|
|
83
|
+
values[index] = value2(ctx, directive);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
resultValues.push(
|
|
88
|
+
directive.replace(
|
|
89
|
+
/[A-Z]+(?![a-z])|[A-Z]/g,
|
|
90
|
+
(match, offset) => offset ? "-" + match.toLowerCase() : match.toLowerCase()
|
|
91
|
+
),
|
|
92
|
+
...valueArray.flatMap((value2) => [" ", value2]),
|
|
93
|
+
"; "
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
resultValues.pop();
|
|
97
|
+
return callbacks.length === 0 ? [void 0, resultValues.join("")] : [
|
|
98
|
+
(ctx, headersToSet) => headersToSet.map((values) => {
|
|
99
|
+
if (values[0] === "Content-Security-Policy") {
|
|
100
|
+
const clone = values[1].slice();
|
|
101
|
+
callbacks.forEach((cb) => {
|
|
102
|
+
cb(ctx, clone);
|
|
103
|
+
});
|
|
104
|
+
return [values[0], clone.join("")];
|
|
105
|
+
} else {
|
|
106
|
+
return values;
|
|
107
|
+
}
|
|
108
|
+
}),
|
|
109
|
+
resultValues
|
|
110
|
+
];
|
|
111
|
+
}
|
|
112
|
+
function getReportingEndpoints(reportingEndpoints = []) {
|
|
113
|
+
return reportingEndpoints.map((endpoint) => `${endpoint.name}="${endpoint.url}"`).join(", ");
|
|
114
|
+
}
|
|
115
|
+
function getReportToOptions(reportTo = []) {
|
|
116
|
+
return reportTo.map((option) => JSON.stringify(option)).join(", ");
|
|
117
|
+
}
|
|
118
|
+
function setHeaders(ctx, headersToSet) {
|
|
119
|
+
headersToSet.forEach(([header, value]) => {
|
|
120
|
+
ctx.res.headers.set(header, value);
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
export {
|
|
124
|
+
NONCE,
|
|
125
|
+
secureHeaders
|
|
126
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// src/middleware/timeout/index.ts
|
|
2
|
+
import { HTTPException } from "../../http-exception.js";
|
|
3
|
+
var defaultTimeoutException = new HTTPException(504, {
|
|
4
|
+
message: "Gateway Timeout"
|
|
5
|
+
});
|
|
6
|
+
var timeout = (duration, exception = defaultTimeoutException) => {
|
|
7
|
+
return async function timeout2(context, next) {
|
|
8
|
+
let timer;
|
|
9
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
10
|
+
timer = setTimeout(() => {
|
|
11
|
+
reject(typeof exception === "function" ? exception(context) : exception);
|
|
12
|
+
}, duration);
|
|
13
|
+
});
|
|
14
|
+
try {
|
|
15
|
+
await Promise.race([next(), timeoutPromise]);
|
|
16
|
+
} finally {
|
|
17
|
+
if (timer !== void 0) {
|
|
18
|
+
clearTimeout(timer);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
export {
|
|
24
|
+
timeout
|
|
25
|
+
};
|
|
@@ -1,89 +1,5 @@
|
|
|
1
1
|
// src/middleware/timing/index.ts
|
|
2
|
-
import "
|
|
3
|
-
var getTime = () => {
|
|
4
|
-
try {
|
|
5
|
-
return performance.now();
|
|
6
|
-
} catch {
|
|
7
|
-
}
|
|
8
|
-
return Date.now();
|
|
9
|
-
};
|
|
10
|
-
var timing = (config) => {
|
|
11
|
-
const options = {
|
|
12
|
-
...{
|
|
13
|
-
total: true,
|
|
14
|
-
enabled: true,
|
|
15
|
-
totalDescription: "Total Response Time",
|
|
16
|
-
autoEnd: true,
|
|
17
|
-
crossOrigin: false
|
|
18
|
-
},
|
|
19
|
-
...config
|
|
20
|
-
};
|
|
21
|
-
return async function timing2(c, next) {
|
|
22
|
-
const headers = [];
|
|
23
|
-
const timers = /* @__PURE__ */ new Map();
|
|
24
|
-
c.set("metric", { headers, timers });
|
|
25
|
-
if (options.total) {
|
|
26
|
-
startTime(c, "total", options.totalDescription);
|
|
27
|
-
}
|
|
28
|
-
await next();
|
|
29
|
-
if (options.total) {
|
|
30
|
-
endTime(c, "total");
|
|
31
|
-
}
|
|
32
|
-
if (options.autoEnd) {
|
|
33
|
-
timers.forEach((_, key) => endTime(c, key));
|
|
34
|
-
}
|
|
35
|
-
const enabled = typeof options.enabled === "function" ? options.enabled(c) : options.enabled;
|
|
36
|
-
if (enabled) {
|
|
37
|
-
c.res.headers.append("Server-Timing", headers.join(","));
|
|
38
|
-
const crossOrigin = typeof options.crossOrigin === "function" ? options.crossOrigin(c) : options.crossOrigin;
|
|
39
|
-
if (crossOrigin) {
|
|
40
|
-
c.res.headers.append(
|
|
41
|
-
"Timing-Allow-Origin",
|
|
42
|
-
typeof crossOrigin === "string" ? crossOrigin : "*"
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
};
|
|
48
|
-
var setMetric = (c, name, valueDescription, description, precision) => {
|
|
49
|
-
const metrics = c.get("metric");
|
|
50
|
-
if (!metrics) {
|
|
51
|
-
console.warn("Metrics not initialized! Please add the `timing()` middleware to this route!");
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
if (typeof valueDescription === "number") {
|
|
55
|
-
const dur = valueDescription.toFixed(precision || 1);
|
|
56
|
-
const metric = description ? `${name};dur=${dur};desc="${description}"` : `${name};dur=${dur}`;
|
|
57
|
-
metrics.headers.push(metric);
|
|
58
|
-
} else {
|
|
59
|
-
const metric = valueDescription ? `${name};desc="${valueDescription}"` : `${name}`;
|
|
60
|
-
metrics.headers.push(metric);
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
var startTime = (c, name, description) => {
|
|
64
|
-
const metrics = c.get("metric");
|
|
65
|
-
if (!metrics) {
|
|
66
|
-
console.warn("Metrics not initialized! Please add the `timing()` middleware to this route!");
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
metrics.timers.set(name, { description, start: getTime() });
|
|
70
|
-
};
|
|
71
|
-
var endTime = (c, name, precision) => {
|
|
72
|
-
const metrics = c.get("metric");
|
|
73
|
-
if (!metrics) {
|
|
74
|
-
console.warn("Metrics not initialized! Please add the `timing()` middleware to this route!");
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
const timer = metrics.timers.get(name);
|
|
78
|
-
if (!timer) {
|
|
79
|
-
console.warn(`Timer "${name}" does not exist!`);
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
const { description, start } = timer;
|
|
83
|
-
const duration = getTime() - start;
|
|
84
|
-
setMetric(c, name, duration, description, precision);
|
|
85
|
-
metrics.timers.delete(name);
|
|
86
|
-
};
|
|
2
|
+
import { timing, setMetric, startTime, endTime } from "./timing.js";
|
|
87
3
|
export {
|
|
88
4
|
endTime,
|
|
89
5
|
setMetric,
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// src/middleware/timing/timing.ts
|
|
2
|
+
import "../../context.js";
|
|
3
|
+
var getTime = () => {
|
|
4
|
+
try {
|
|
5
|
+
return performance.now();
|
|
6
|
+
} catch {
|
|
7
|
+
}
|
|
8
|
+
return Date.now();
|
|
9
|
+
};
|
|
10
|
+
var timing = (config) => {
|
|
11
|
+
const options = {
|
|
12
|
+
...{
|
|
13
|
+
total: true,
|
|
14
|
+
enabled: true,
|
|
15
|
+
totalDescription: "Total Response Time",
|
|
16
|
+
autoEnd: true,
|
|
17
|
+
crossOrigin: false
|
|
18
|
+
},
|
|
19
|
+
...config
|
|
20
|
+
};
|
|
21
|
+
return async function timing2(c, next) {
|
|
22
|
+
const headers = [];
|
|
23
|
+
const timers = /* @__PURE__ */ new Map();
|
|
24
|
+
c.set("metric", { headers, timers });
|
|
25
|
+
if (options.total) {
|
|
26
|
+
startTime(c, "total", options.totalDescription);
|
|
27
|
+
}
|
|
28
|
+
await next();
|
|
29
|
+
if (options.total) {
|
|
30
|
+
endTime(c, "total");
|
|
31
|
+
}
|
|
32
|
+
if (options.autoEnd) {
|
|
33
|
+
timers.forEach((_, key) => endTime(c, key));
|
|
34
|
+
}
|
|
35
|
+
const enabled = typeof options.enabled === "function" ? options.enabled(c) : options.enabled;
|
|
36
|
+
if (enabled) {
|
|
37
|
+
c.res.headers.append("Server-Timing", headers.join(","));
|
|
38
|
+
const crossOrigin = typeof options.crossOrigin === "function" ? options.crossOrigin(c) : options.crossOrigin;
|
|
39
|
+
if (crossOrigin) {
|
|
40
|
+
c.res.headers.append(
|
|
41
|
+
"Timing-Allow-Origin",
|
|
42
|
+
typeof crossOrigin === "string" ? crossOrigin : "*"
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
var setMetric = (c, name, valueDescription, description, precision) => {
|
|
49
|
+
const metrics = c.get("metric");
|
|
50
|
+
if (!metrics) {
|
|
51
|
+
console.warn("Metrics not initialized! Please add the `timing()` middleware to this route!");
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (typeof valueDescription === "number") {
|
|
55
|
+
const dur = valueDescription.toFixed(precision || 1);
|
|
56
|
+
const metric = description ? `${name};dur=${dur};desc="${description}"` : `${name};dur=${dur}`;
|
|
57
|
+
metrics.headers.push(metric);
|
|
58
|
+
} else {
|
|
59
|
+
const metric = valueDescription ? `${name};desc="${valueDescription}"` : `${name}`;
|
|
60
|
+
metrics.headers.push(metric);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
var startTime = (c, name, description) => {
|
|
64
|
+
const metrics = c.get("metric");
|
|
65
|
+
if (!metrics) {
|
|
66
|
+
console.warn("Metrics not initialized! Please add the `timing()` middleware to this route!");
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
metrics.timers.set(name, { description, start: getTime() });
|
|
70
|
+
};
|
|
71
|
+
var endTime = (c, name, precision) => {
|
|
72
|
+
const metrics = c.get("metric");
|
|
73
|
+
if (!metrics) {
|
|
74
|
+
console.warn("Metrics not initialized! Please add the `timing()` middleware to this route!");
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const timer = metrics.timers.get(name);
|
|
78
|
+
if (!timer) {
|
|
79
|
+
console.warn(`Timer "${name}" does not exist!`);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const { description, start } = timer;
|
|
83
|
+
const duration = getTime() - start;
|
|
84
|
+
setMetric(c, name, duration, description, precision);
|
|
85
|
+
metrics.timers.delete(name);
|
|
86
|
+
};
|
|
87
|
+
export {
|
|
88
|
+
endTime,
|
|
89
|
+
setMetric,
|
|
90
|
+
startTime,
|
|
91
|
+
timing
|
|
92
|
+
};
|
package/dist/request.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/request.ts
|
|
2
2
|
import { parseBody } from "./utils/body.js";
|
|
3
|
-
import { getQueryParam, getQueryParams
|
|
3
|
+
import { decodeURIComponent_, getQueryParam, getQueryParams } from "./utils/url.js";
|
|
4
4
|
var HonoRequest = class {
|
|
5
5
|
raw;
|
|
6
6
|
#validatedData;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// src/router/reg-exp-router/router.ts
|
|
2
2
|
import {
|
|
3
|
+
MESSAGE_MATCHER_IS_ALREADY_BUILT,
|
|
3
4
|
METHOD_NAME_ALL,
|
|
4
|
-
UnsupportedPathError
|
|
5
|
-
MESSAGE_MATCHER_IS_ALREADY_BUILT
|
|
5
|
+
UnsupportedPathError
|
|
6
6
|
} from "../../router.js";
|
|
7
7
|
import { checkOptionalParameter } from "../../utils/url.js";
|
|
8
8
|
import { PATH_ERROR } from "./node.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/router/smart-router/router.ts
|
|
2
|
-
import {
|
|
2
|
+
import { MESSAGE_MATCHER_IS_ALREADY_BUILT, UnsupportedPathError } from "../../router.js";
|
|
3
3
|
var SmartRouter = class {
|
|
4
4
|
name = "SmartRouter";
|
|
5
5
|
routers = [];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/router/trie-router/node.ts
|
|
2
2
|
import { METHOD_NAME_ALL } from "../../router.js";
|
|
3
|
-
import { splitPath, splitRoutingPath
|
|
3
|
+
import { getPattern, splitPath, splitRoutingPath } from "../../utils/url.js";
|
|
4
4
|
var Node = class {
|
|
5
5
|
methods;
|
|
6
6
|
children;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Hono } from '../../hono';
|
|
2
2
|
import type { Env, Schema } from '../../types';
|
|
3
|
-
import type { ApiGatewayRequestContext, ApiGatewayRequestContextV2
|
|
4
|
-
import type { LambdaContext } from './types';
|
|
3
|
+
import type { ALBRequestContext, ApiGatewayRequestContext, ApiGatewayRequestContextV2 } from './custom-context';
|
|
4
|
+
import type { Handler, LambdaContext } from './types';
|
|
5
5
|
export type LambdaEvent = APIGatewayProxyEvent | APIGatewayProxyEventV2 | ALBProxyEvent;
|
|
6
6
|
export interface APIGatewayProxyEventV2 {
|
|
7
7
|
version: string;
|
|
@@ -67,7 +67,7 @@ export interface APIGatewayProxyResult {
|
|
|
67
67
|
};
|
|
68
68
|
isBase64Encoded: boolean;
|
|
69
69
|
}
|
|
70
|
-
export declare const streamHandle: <E extends Env = Env, S extends Schema = {}, BasePath extends string = "/">(app: Hono<E, S, BasePath>) =>
|
|
70
|
+
export declare const streamHandle: <E extends Env = Env, S extends Schema = {}, BasePath extends string = "/">(app: Hono<E, S, BasePath>) => Handler;
|
|
71
71
|
/**
|
|
72
72
|
* Accepts events from API Gateway/ELB(`APIGatewayProxyEvent`) and directly through Function Url(`APIGatewayProxyEventV2`)
|
|
73
73
|
*/
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* AWS Lambda Adapter for Hono.
|
|
4
|
+
*/
|
|
1
5
|
export { handle, streamHandle } from './handler';
|
|
2
6
|
export type { APIGatewayProxyResult, LambdaEvent } from './handler';
|
|
3
7
|
export type { ApiGatewayRequestContext, ApiGatewayRequestContextV2, ALBRequestContext, } from './custom-context';
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import { type UpgradeWebSocket } from '../../helper/websocket';
|
|
1
|
+
import type { UpgradeWebSocket } from '../../helper/websocket';
|
|
3
2
|
interface BunServerWebSocket<T> {
|
|
4
3
|
send(data: string | ArrayBufferLike, compress?: boolean): void;
|
|
5
4
|
close(code?: number, reason?: string): void;
|
|
@@ -9,7 +8,7 @@ interface BunServerWebSocket<T> {
|
|
|
9
8
|
interface BunWebSocketHandler<T> {
|
|
10
9
|
open(ws: BunServerWebSocket<T>): void;
|
|
11
10
|
close(ws: BunServerWebSocket<T>, code?: number, reason?: string): void;
|
|
12
|
-
message(ws: BunServerWebSocket<T>, message: string |
|
|
11
|
+
message(ws: BunServerWebSocket<T>, message: string | Uint8Array): void;
|
|
13
12
|
}
|
|
14
13
|
interface CreateWebSocket {
|
|
15
14
|
(): {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Env } from '../../types';
|
|
1
|
+
import type { Env, MiddlewareHandler } from '../../types';
|
|
2
2
|
import type { ServeStaticOptions } from './serve-static';
|
|
3
|
-
declare const module: <E extends Env = Env>(options: Omit<ServeStaticOptions<E>, "namespace">) =>
|
|
3
|
+
declare const module: <E extends Env = Env>(options: Omit<ServeStaticOptions<E>, "namespace">) => MiddlewareHandler;
|
|
4
4
|
export { module as serveStatic };
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import type { KVNamespace } from '@cloudflare/workers-types';
|
|
2
1
|
import type { ServeStaticOptions as BaseServeStaticOptions } from '../../middleware/serve-static';
|
|
3
2
|
import type { Env, MiddlewareHandler } from '../../types';
|
|
4
3
|
export type ServeStaticOptions<E extends Env = Env> = BaseServeStaticOptions<E> & {
|
|
5
|
-
namespace?:
|
|
4
|
+
namespace?: unknown;
|
|
6
5
|
manifest: object | string;
|
|
7
6
|
};
|
|
8
7
|
/**
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type { KVNamespace } from '@cloudflare/workers-types';
|
|
2
1
|
export type KVAssetOptions = {
|
|
3
2
|
manifest?: object | string;
|
|
4
|
-
namespace?:
|
|
3
|
+
namespace?: unknown;
|
|
5
4
|
};
|
|
6
5
|
export declare const getContentFromKVAsset: (path: string, options?: KVAssetOptions) => Promise<ReadableStream | null>;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import type { Hono } from '../../hono';
|
|
3
2
|
interface CloudFrontHeader {
|
|
4
3
|
key: string;
|
|
@@ -83,6 +82,6 @@ interface CloudFrontResult {
|
|
|
83
82
|
bodyEncoding?: 'text' | 'base64';
|
|
84
83
|
}
|
|
85
84
|
export declare const handle: (app: Hono<any>) => (event: CloudFrontEdgeEvent, context?: CloudFrontContext, callback?: Callback) => Promise<CloudFrontResult>;
|
|
86
|
-
export declare const createBody: (method: string, requestBody: CloudFrontRequest['body']) => string |
|
|
85
|
+
export declare const createBody: (method: string, requestBody: CloudFrontRequest['body']) => string | Uint8Array | undefined;
|
|
87
86
|
export declare const isContentTypeBinary: (contentType: string) => boolean;
|
|
88
87
|
export {};
|
|
@@ -1,8 +1,2 @@
|
|
|
1
|
-
import type { Context } from 'https://edge.netlify.com/';
|
|
2
1
|
import type { Hono } from '../../hono';
|
|
3
|
-
export
|
|
4
|
-
Bindings: {
|
|
5
|
-
context: Context;
|
|
6
|
-
};
|
|
7
|
-
};
|
|
8
|
-
export declare const handle: (app: Hono<any, any>) => (req: Request, context: Context) => Response | Promise<Response>;
|
|
2
|
+
export declare const handle: (app: Hono<any, any>) => (req: Request, context: any) => Response | Promise<Response>;
|
package/dist/types/compose.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* Adapter Helper for Hono.
|
|
4
|
+
*/
|
|
1
5
|
import type { Context } from '../../context';
|
|
2
6
|
export type Runtime = 'node' | 'deno' | 'bun' | 'workerd' | 'fastly' | 'edge-light' | 'other';
|
|
3
7
|
export declare const env: <T extends Record<string, unknown>, C extends Context<any, any, {}> = Context<{}, any, {}>>(c: C, runtime?: Runtime) => T & C["env"];
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* ConnInfo Helper for Hono.
|
|
4
|
+
*/
|
|
5
|
+
import type { Context } from '../../context';
|
|
6
|
+
export type AddressType = 'IPv6' | 'IPv4' | 'unknown';
|
|
7
|
+
export type NetAddrInfo = {
|
|
8
|
+
/**
|
|
9
|
+
* Transport protocol type
|
|
10
|
+
*/
|
|
11
|
+
transport?: 'tcp' | 'udp';
|
|
12
|
+
/**
|
|
13
|
+
* Transport port number
|
|
14
|
+
*/
|
|
15
|
+
port?: number;
|
|
16
|
+
address?: string;
|
|
17
|
+
addressType?: AddressType;
|
|
18
|
+
} & ({
|
|
19
|
+
/**
|
|
20
|
+
* Host name such as IP Addr
|
|
21
|
+
*/
|
|
22
|
+
address: string;
|
|
23
|
+
/**
|
|
24
|
+
* Host name type
|
|
25
|
+
*/
|
|
26
|
+
addressType: AddressType;
|
|
27
|
+
} | {});
|
|
28
|
+
/**
|
|
29
|
+
* HTTP Connection infomation
|
|
30
|
+
*/
|
|
31
|
+
export interface ConnInfo {
|
|
32
|
+
/**
|
|
33
|
+
* Remote infomation
|
|
34
|
+
*/
|
|
35
|
+
remote: NetAddrInfo;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Helper type
|
|
39
|
+
*/
|
|
40
|
+
export type GetConnInfo = (c: Context) => ConnInfo;
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* Cookie Helper for Hono.
|
|
4
|
+
*/
|
|
1
5
|
import type { Context } from '../../context';
|
|
2
|
-
import type { CookieOptions,
|
|
6
|
+
import type { Cookie, CookieOptions, CookiePrefixOptions, SignedCookie } from '../../utils/cookie';
|
|
3
7
|
interface GetCookie {
|
|
4
8
|
(c: Context, key: string): string | undefined;
|
|
5
9
|
(c: Context): Cookie;
|