hono 2.0.1 → 2.0.4
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 +11 -11
- package/dist/compose.d.ts +5 -1
- package/dist/context.d.ts +1 -1
- package/dist/hono.d.ts +1 -1
- package/dist/middleware/cache/index.d.ts +7 -0
- package/dist/middleware/cache/index.js +32 -0
- package/dist/middleware/compress/index.d.ts +1 -1
- package/dist/middleware/cors/index.d.ts +1 -1
- package/dist/middleware/jsx/index.d.ts +2 -2
- package/dist/middleware/jsx/index.js +3 -3
- package/dist/middleware/jsx/jsx-dev-runtime.d.ts +2 -0
- package/dist/middleware/jsx/jsx-dev-runtime.js +10 -0
- package/dist/middleware/jsx/jsx-runtime.d.ts +2 -0
- package/dist/middleware/jsx/jsx-runtime.js +7 -0
- package/dist/middleware/logger/index.d.ts +1 -1
- package/dist/middleware/logger/index.js +1 -1
- package/dist/middleware/serve-static/module.mjs +1 -0
- package/dist/router/trie-router/node.js +18 -12
- package/dist/utils/buffer.d.ts +1 -1
- package/dist/utils/cloudflare.d.ts +1 -1
- package/package.json +18 -6
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<div align="center">
|
|
2
2
|
<a href="https://honojs.dev">
|
|
3
|
-
<img src="https://raw.githubusercontent.com/honojs/hono/
|
|
3
|
+
<img src="https://raw.githubusercontent.com/honojs/hono/main/docs/images/hono-title.png" width="500" height="auto" alt="Hono"/>
|
|
4
4
|
</a>
|
|
5
5
|
</div>
|
|
6
6
|
|
|
@@ -14,12 +14,12 @@
|
|
|
14
14
|
<hr />
|
|
15
15
|
|
|
16
16
|
[](https://github.com/honojs/hono/actions)
|
|
17
|
-
[](https://github.com/honojs/hono/blob/
|
|
17
|
+
[](https://github.com/honojs/hono/blob/main/LICENSE)
|
|
18
18
|
[](https://www.npmjs.com/package/hono)
|
|
19
19
|
[](https://www.npmjs.com/package/hono)
|
|
20
20
|
[](https://www.npmjs.com/package/hono)
|
|
21
21
|
[](https://github.com/honojs/hono/pulse)
|
|
22
|
-
[](https://github.com/honojs/hono/commits/
|
|
22
|
+
[](https://github.com/honojs/hono/commits/main)
|
|
23
23
|
[](https://doc.deno.land/https/deno.land/x/hono/mod.ts)
|
|
24
24
|
|
|
25
25
|
Hono - _**[炎] means flame🔥 in Japanese**_ - is a small, simple, and ultrafast web framework for Cloudflare Workers, Deno, Bun, and others.
|
|
@@ -61,19 +61,19 @@ The documentation is available on [honojs.dev](https://honojs.dev).
|
|
|
61
61
|
|
|
62
62
|
## Migration
|
|
63
63
|
|
|
64
|
-
Migration guide is available on [docs/MIGRATION.md](docs/MIGRATION.md)
|
|
64
|
+
Migration guide is available on [docs/MIGRATION.md](docs/MIGRATION.md).
|
|
65
65
|
|
|
66
66
|
## Contributing
|
|
67
67
|
|
|
68
68
|
Contributions Welcome! You can contribute in the following ways.
|
|
69
69
|
|
|
70
|
-
-
|
|
71
|
-
-
|
|
72
|
-
-
|
|
73
|
-
-
|
|
74
|
-
-
|
|
75
|
-
|
|
76
|
-
|
|
70
|
+
- Create an Issue - Propose a new feature. Report a bug.
|
|
71
|
+
- Pull Request - Fix a bug and typo. Refactor the code.
|
|
72
|
+
- Create third-party middleware - Instruct below.
|
|
73
|
+
- Share - Share your thoughts on the Blog, Twitter, and others.
|
|
74
|
+
- Make your application - Please try to use Hono.
|
|
75
|
+
|
|
76
|
+
For more details, see [docs/CONTRIBUTING.md](docs/CONTRIBUTING.md).
|
|
77
77
|
|
|
78
78
|
## Contributors
|
|
79
79
|
|
package/dist/compose.d.ts
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
1
|
import type { ErrorHandler, NotFoundHandler } from './hono';
|
|
2
|
-
export declare const compose: <C>(middleware: Function[], onError?: ErrorHandler
|
|
2
|
+
export declare const compose: <C>(middleware: Function[], onError?: ErrorHandler<{
|
|
3
|
+
[x: string]: any;
|
|
4
|
+
}> | undefined, onNotFound?: NotFoundHandler<{
|
|
5
|
+
[x: string]: any;
|
|
6
|
+
}> | undefined) => (context: C, next?: Function | undefined) => Promise<C>;
|
package/dist/context.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export interface Context<RequestParamKeyType extends string = string, E = Env> {
|
|
|
16
16
|
header: (name: string, value: string) => void;
|
|
17
17
|
status: (status: StatusCode) => void;
|
|
18
18
|
set: (key: string, value: any) => void;
|
|
19
|
-
get: (key: string) =>
|
|
19
|
+
get: <T = any>(key: string) => T;
|
|
20
20
|
pretty: (prettyJSON: boolean, space?: number) => void;
|
|
21
21
|
newResponse: (data: Data | null, status: StatusCode, headers: Headers) => Response;
|
|
22
22
|
body: (data: Data | null, status?: StatusCode, headers?: Headers) => Response;
|
package/dist/hono.d.ts
CHANGED
|
@@ -48,7 +48,7 @@ export declare class Hono<E extends Env = Env, P extends string = '/'> extends H
|
|
|
48
48
|
private matchRoute;
|
|
49
49
|
private dispatch;
|
|
50
50
|
handleEvent(event: FetchEvent): Promise<Response>;
|
|
51
|
-
fetch: (request: Request, env?: E, executionCtx?: ExecutionContext) => Promise<Response>;
|
|
51
|
+
fetch: (request: Request, env?: E | undefined, executionCtx?: ExecutionContext | undefined) => Promise<Response>;
|
|
52
52
|
request(input: RequestInfo, requestInit?: RequestInit): Promise<Response>;
|
|
53
53
|
}
|
|
54
54
|
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cache = void 0;
|
|
4
|
+
const cache = (options) => {
|
|
5
|
+
if (options.wait === undefined) {
|
|
6
|
+
options.wait = false;
|
|
7
|
+
}
|
|
8
|
+
const addHeader = (response) => {
|
|
9
|
+
if (options.cacheControl)
|
|
10
|
+
response.headers.append('Cache-Control', options.cacheControl);
|
|
11
|
+
};
|
|
12
|
+
return async (c, next) => {
|
|
13
|
+
const key = c.req;
|
|
14
|
+
const cache = await caches.open(options.cacheName);
|
|
15
|
+
const response = await cache.match(key);
|
|
16
|
+
if (!response) {
|
|
17
|
+
await next();
|
|
18
|
+
addHeader(c.res);
|
|
19
|
+
const response = c.res.clone();
|
|
20
|
+
if (options.wait) {
|
|
21
|
+
await cache.put(key, response);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
c.executionCtx.waitUntil(cache.put(key, response));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
return response;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
exports.cache = cache;
|
|
@@ -4,5 +4,5 @@ declare type EncodingType = 'gzip' | 'deflate';
|
|
|
4
4
|
interface CompressionOptions {
|
|
5
5
|
encoding?: EncodingType;
|
|
6
6
|
}
|
|
7
|
-
export declare const compress: (options?: CompressionOptions) => (ctx: Context, next: Next) => Promise<void>;
|
|
7
|
+
export declare const compress: (options?: CompressionOptions | undefined) => (ctx: Context, next: Next) => Promise<void>;
|
|
8
8
|
export {};
|
|
@@ -8,5 +8,5 @@ declare type CORSOptions = {
|
|
|
8
8
|
credentials?: boolean;
|
|
9
9
|
exposeHeaders?: string[];
|
|
10
10
|
};
|
|
11
|
-
export declare const cors: (options?: CORSOptions) => (c: Context, next: Next) => Promise<void>;
|
|
11
|
+
export declare const cors: (options?: CORSOptions | undefined) => (c: Context, next: Next) => Promise<void>;
|
|
12
12
|
export {};
|
|
@@ -6,11 +6,11 @@ declare global {
|
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
|
-
export
|
|
9
|
+
export { jsxFn as jsx };
|
|
10
|
+
declare const jsxFn: (tag: string | Function, props: Record<string, any>, ...children: (string | HtmlEscapedString)[]) => HtmlEscapedString;
|
|
10
11
|
declare type FC<T = Record<string, any>> = (props: T) => HtmlEscapedString;
|
|
11
12
|
export declare const memo: <T>(component: FC<T>, propsAreEqual?: (prevProps: Readonly<T>, nextProps: Readonly<T>) => boolean) => FC<T>;
|
|
12
13
|
export declare const Fragment: (props: {
|
|
13
14
|
key?: string;
|
|
14
15
|
children?: any;
|
|
15
16
|
}) => HtmlEscapedString;
|
|
16
|
-
export {};
|
|
@@ -19,7 +19,7 @@ const emptyTags = [
|
|
|
19
19
|
'track',
|
|
20
20
|
'wbr',
|
|
21
21
|
];
|
|
22
|
-
const
|
|
22
|
+
const jsxFn = (tag, props, ...children) => {
|
|
23
23
|
if (typeof tag === 'function') {
|
|
24
24
|
return tag.call(null, { ...props, children: children.length <= 1 ? children[0] : children });
|
|
25
25
|
}
|
|
@@ -67,7 +67,7 @@ const jsx = (tag, props, ...children) => {
|
|
|
67
67
|
escapedString.isEscaped = true;
|
|
68
68
|
return escapedString;
|
|
69
69
|
};
|
|
70
|
-
exports.jsx =
|
|
70
|
+
exports.jsx = jsxFn;
|
|
71
71
|
const shallowEqual = (a, b) => {
|
|
72
72
|
if (a === b) {
|
|
73
73
|
return true;
|
|
@@ -97,6 +97,6 @@ const memo = (component, propsAreEqual = shallowEqual) => {
|
|
|
97
97
|
};
|
|
98
98
|
exports.memo = memo;
|
|
99
99
|
const Fragment = (props) => {
|
|
100
|
-
return (
|
|
100
|
+
return jsxFn('', {}, ...(props.children || []));
|
|
101
101
|
};
|
|
102
102
|
exports.Fragment = Fragment;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.jsxDEV = void 0;
|
|
4
|
+
const _1 = require(".");
|
|
5
|
+
function jsxDEV(tag, props) {
|
|
6
|
+
const children = props.children ?? [];
|
|
7
|
+
delete props['children'];
|
|
8
|
+
return (0, _1.jsx)(tag, props, ...children);
|
|
9
|
+
}
|
|
10
|
+
exports.jsxDEV = jsxDEV;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.jsxs = exports.jsx = void 0;
|
|
4
|
+
var jsx_dev_runtime_1 = require("./jsx-dev-runtime");
|
|
5
|
+
Object.defineProperty(exports, "jsx", { enumerable: true, get: function () { return jsx_dev_runtime_1.jsxDEV; } });
|
|
6
|
+
var jsx_dev_runtime_2 = require("./jsx-dev-runtime");
|
|
7
|
+
Object.defineProperty(exports, "jsxs", { enumerable: true, get: function () { return jsx_dev_runtime_2.jsxDEV; } });
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Context } from '../../context';
|
|
2
2
|
import type { Next } from '../../hono';
|
|
3
3
|
declare type PrintFunc = (str: string, ...rest: string[]) => void;
|
|
4
|
-
export declare const logger: (fn
|
|
4
|
+
export declare const logger: (fn?: PrintFunc) => (c: Context, next: Next) => Promise<void>;
|
|
5
5
|
export {};
|
|
@@ -36,7 +36,7 @@ function log(fn, prefix, method, path, status = 0, elapsed) {
|
|
|
36
36
|
: ` ${prefix} ${method} ${path} ${colorStatus(status)} ${elapsed}`;
|
|
37
37
|
fn(out);
|
|
38
38
|
}
|
|
39
|
-
const logger = (fn) => {
|
|
39
|
+
const logger = (fn = console.log) => {
|
|
40
40
|
return async (c, next) => {
|
|
41
41
|
const { method } = c.req;
|
|
42
42
|
const path = (0, url_1.getPathFromURL)(c.req.url);
|
|
@@ -102,8 +102,21 @@ class Node {
|
|
|
102
102
|
const part = parts[i];
|
|
103
103
|
const isLast = i === len - 1;
|
|
104
104
|
const tempNodes = [];
|
|
105
|
+
let matched = false;
|
|
105
106
|
for (let j = 0, len2 = curNodes.length; j < len2; j++) {
|
|
106
107
|
const node = curNodes[j];
|
|
108
|
+
const nextNode = node.children[part];
|
|
109
|
+
if (nextNode) {
|
|
110
|
+
if (isLast === true) {
|
|
111
|
+
// '/hello/*' => match '/hello'
|
|
112
|
+
if (nextNode.children['*']) {
|
|
113
|
+
handlerSets.push(...this.getHandlerSets(nextNode.children['*'], method, true));
|
|
114
|
+
}
|
|
115
|
+
handlerSets.push(...this.getHandlerSets(nextNode, method));
|
|
116
|
+
matched = true;
|
|
117
|
+
}
|
|
118
|
+
tempNodes.push(nextNode);
|
|
119
|
+
}
|
|
107
120
|
for (let k = 0, len3 = node.patterns.length; k < len3; k++) {
|
|
108
121
|
const pattern = node.patterns[k];
|
|
109
122
|
// Wildcard
|
|
@@ -128,22 +141,15 @@ class Node {
|
|
|
128
141
|
}
|
|
129
142
|
tempNodes.push(node.children[key]);
|
|
130
143
|
}
|
|
131
|
-
|
|
144
|
+
// '/book/a' => not-slug
|
|
145
|
+
// '/book/:slug' => slug
|
|
146
|
+
// GET /book/a ~> no-slug, param['slug'] => undefined
|
|
147
|
+
// GET /book/foo ~> slug, param['slug'] => foo
|
|
148
|
+
if (typeof name === 'string' && !matched) {
|
|
132
149
|
params[name] = part;
|
|
133
150
|
}
|
|
134
151
|
}
|
|
135
152
|
}
|
|
136
|
-
const nextNode = node.children[part];
|
|
137
|
-
if (nextNode) {
|
|
138
|
-
if (isLast === true) {
|
|
139
|
-
// '/hello/*' => match '/hello'
|
|
140
|
-
if (nextNode.children['*']) {
|
|
141
|
-
handlerSets.push(...this.getHandlerSets(nextNode.children['*'], method, true));
|
|
142
|
-
}
|
|
143
|
-
handlerSets.push(...this.getHandlerSets(nextNode, method));
|
|
144
|
-
}
|
|
145
|
-
tempNodes.push(nextNode);
|
|
146
|
-
}
|
|
147
153
|
}
|
|
148
154
|
curNodes = tempNodes;
|
|
149
155
|
}
|
package/dist/utils/buffer.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export declare const equal: (a: ArrayBuffer, b: ArrayBuffer) => boolean;
|
|
2
|
-
export declare const timingSafeEqual: (a: string | object | boolean, b: string | object | boolean, hashFunction?: Function) => Promise<boolean>;
|
|
2
|
+
export declare const timingSafeEqual: (a: string | object | boolean, b: string | object | boolean, hashFunction?: Function | undefined) => Promise<boolean>;
|
|
3
3
|
export declare const bufferToString: (buffer: ArrayBuffer) => string;
|
|
@@ -3,4 +3,4 @@ export declare type KVAssetOptions = {
|
|
|
3
3
|
manifest?: object | string;
|
|
4
4
|
namespace?: KVNamespace;
|
|
5
5
|
};
|
|
6
|
-
export declare const getContentFromKVAsset: (path: string, options?: KVAssetOptions) => Promise<ArrayBuffer | null>;
|
|
6
|
+
export declare const getContentFromKVAsset: (path: string, options?: KVAssetOptions | undefined) => Promise<ArrayBuffer | null>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hono",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.4",
|
|
4
4
|
"description": "Ultrafast web framework for Cloudflare Workers.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
"scripts": {
|
|
11
11
|
"test": "jest",
|
|
12
12
|
"test:deno": "deno test --allow-read deno_test",
|
|
13
|
-
"test:bun": "bun wiptest bun_test/index.test.
|
|
13
|
+
"test:bun": "bun wiptest --jsx-import-source ../src/middleware/jsx/jsx-dev-runtime bun_test/index.test.tsx",
|
|
14
|
+
"test:all": "yarn test && yarn test:deno && yarn test:bun",
|
|
14
15
|
"lint": "eslint --ext js,ts src .eslintrc.js",
|
|
15
16
|
"lint:fix": "eslint --ext js,ts src .eslintrc.js --fix",
|
|
16
17
|
"denoify": "rimraf deno_dist && denoify && rimraf 'deno_dist/**/*.test.ts'",
|
|
@@ -23,10 +24,14 @@
|
|
|
23
24
|
".": "./dist/index.js",
|
|
24
25
|
"./basic-auth": "./dist/middleware/basic-auth/index.js",
|
|
25
26
|
"./bearer-auth": "./dist/middleware/bearer-auth/index.js",
|
|
27
|
+
"./cache": "./dist/middleware/cache/index.js",
|
|
28
|
+
"./compress": "./dist/middleware/compress/index.js",
|
|
26
29
|
"./cors": "./dist/middleware/cors/index.js",
|
|
27
30
|
"./etag": "./dist/middleware/etag/index.js",
|
|
28
31
|
"./html": "./dist/middleware/html/index.js",
|
|
29
32
|
"./jsx": "./dist/middleware/jsx/index.js",
|
|
33
|
+
"./jsx/jsx-dev-runtime": "./dist/middleware/jsx/jsx-dev-runtime.js",
|
|
34
|
+
"./jsx/jsx-runtime": "./dist/middleware/jsx/jsx-runtime.js",
|
|
30
35
|
"./jwt": "./dist/middleware/jwt/index.js",
|
|
31
36
|
"./logger": "./dist/middleware/logger/index.js",
|
|
32
37
|
"./powered-by": "./dist/middleware/powered-by/index.js",
|
|
@@ -47,8 +52,11 @@
|
|
|
47
52
|
"bearer-auth": [
|
|
48
53
|
"./dist/middleware/bearer-auth"
|
|
49
54
|
],
|
|
50
|
-
"
|
|
51
|
-
"./dist/middleware/
|
|
55
|
+
"cache": [
|
|
56
|
+
"./dist/middleware/cache"
|
|
57
|
+
],
|
|
58
|
+
"compress": [
|
|
59
|
+
"./dist/middleware/compress"
|
|
52
60
|
],
|
|
53
61
|
"cors": [
|
|
54
62
|
"./dist/middleware/cors"
|
|
@@ -62,6 +70,12 @@
|
|
|
62
70
|
"jsx": [
|
|
63
71
|
"./dist/middleware/jsx"
|
|
64
72
|
],
|
|
73
|
+
"jsx/jsx-runtime": [
|
|
74
|
+
"./dist/middleware/jsx/jsx-runtime.d.ts"
|
|
75
|
+
],
|
|
76
|
+
"jsx/jsx-dev-runtime": [
|
|
77
|
+
"./dist/middleware/jsx/jsx-dev-runtime.d.ts"
|
|
78
|
+
],
|
|
65
79
|
"jwt": [
|
|
66
80
|
"./dist/middleware/jwt"
|
|
67
81
|
],
|
|
@@ -126,7 +140,6 @@
|
|
|
126
140
|
"@cloudflare/workers-types": "^3.7.1",
|
|
127
141
|
"@types/crypto-js": "^4.1.1",
|
|
128
142
|
"@types/jest": "^27.4.1",
|
|
129
|
-
"@types/mustache": "^4.1.2",
|
|
130
143
|
"@types/node": "^17.0.29",
|
|
131
144
|
"@typescript-eslint/eslint-plugin": "^5.21.0",
|
|
132
145
|
"@typescript-eslint/parser": "^5.21.0",
|
|
@@ -143,7 +156,6 @@
|
|
|
143
156
|
"form-data": "^4.0.0",
|
|
144
157
|
"jest": "27.5.1",
|
|
145
158
|
"jest-environment-miniflare": "^2.6.0",
|
|
146
|
-
"mustache": "^4.2.0",
|
|
147
159
|
"np": "^7.6.2",
|
|
148
160
|
"prettier": "^2.6.2",
|
|
149
161
|
"rimraf": "^3.0.2",
|