hono 3.0.0-rc.9 → 3.0.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 +23 -19
- package/dist/adapter/bun/serve-static.js +1 -1
- package/dist/adapter/cloudflare-pages/handler.js +3 -7
- package/dist/adapter/cloudflare-workers/serve-static.js +1 -1
- package/dist/adapter/deno/index.js +5 -0
- package/dist/adapter/deno/serve-static.js +1 -1
- package/dist/adapter/nextjs/handler.js +2 -5
- package/dist/cjs/adapter/bun/serve-static.js +1 -1
- package/dist/cjs/adapter/cloudflare-pages/handler.js +3 -7
- package/dist/cjs/adapter/cloudflare-workers/serve-static.js +1 -1
- package/dist/cjs/{router/static-router → adapter/deno}/index.js +6 -6
- package/dist/cjs/adapter/deno/serve-static.js +1 -1
- package/dist/cjs/adapter/nextjs/handler.js +2 -5
- package/dist/cjs/client/client.js +124 -0
- package/dist/cjs/client/index.js +28 -0
- package/dist/cjs/client/types.js +16 -0
- package/dist/cjs/client/utils.js +72 -0
- package/dist/cjs/compose.js +1 -1
- package/dist/cjs/context.js +1 -2
- package/dist/cjs/hono.js +25 -22
- package/dist/cjs/{utils/http-exception.js → http-exception.js} +1 -1
- package/dist/cjs/middleware/basic-auth/index.js +1 -1
- package/dist/cjs/middleware/bearer-auth/index.js +1 -1
- package/dist/cjs/middleware/jwt/index.js +1 -1
- package/dist/cjs/middleware/logger/index.js +1 -1
- package/dist/cjs/request.js +30 -52
- package/dist/cjs/router/reg-exp-router/router.js +4 -4
- package/dist/cjs/utils/url.js +4 -3
- package/dist/cjs/validator/index.js +28 -0
- package/dist/cjs/{middleware/validator/index.js → validator/validator.js} +3 -3
- package/dist/client/client.js +101 -0
- package/dist/client/index.js +5 -0
- package/dist/client/types.js +0 -0
- package/dist/client/utils.js +46 -0
- package/dist/compose.js +1 -1
- package/dist/context.js +1 -2
- package/dist/hono.js +25 -22
- package/dist/{utils/http-exception.js → http-exception.js} +2 -2
- package/dist/middleware/basic-auth/index.js +1 -1
- package/dist/middleware/bearer-auth/index.js +1 -1
- package/dist/middleware/jwt/index.js +1 -1
- package/dist/middleware/logger/index.js +1 -1
- package/dist/request.js +30 -52
- package/dist/router/reg-exp-router/router.js +4 -4
- package/dist/types/adapter/cloudflare-pages/handler.d.ts +5 -2
- package/dist/types/adapter/deno/index.d.ts +1 -0
- package/dist/types/adapter/nextjs/handler.d.ts +6 -2
- package/dist/types/client/client.d.ts +4 -0
- package/dist/types/client/index.d.ts +2 -0
- package/dist/types/client/types.d.ts +40 -0
- package/dist/types/client/utils.d.ts +4 -0
- package/dist/types/compose.d.ts +1 -1
- package/dist/types/context.d.ts +3 -5
- package/dist/types/hono.d.ts +5 -5
- package/dist/types/{utils/http-exception.d.ts → http-exception.d.ts} +1 -1
- package/dist/types/index.d.ts +1 -3
- package/dist/types/middleware/jsx/index.d.ts +2 -1
- package/dist/types/request.d.ts +9 -13
- package/dist/types/types.d.ts +33 -60
- package/dist/types/utils/url.d.ts +2 -2
- package/dist/types/validator/index.d.ts +1 -0
- package/dist/types/validator/validator.d.ts +6 -0
- package/dist/utils/url.js +4 -3
- package/dist/validator/index.js +5 -0
- package/dist/{middleware/validator/index.js → validator/validator.js} +4 -4
- package/package.json +34 -24
- package/dist/cjs/router/static-router/router.js +0 -98
- package/dist/cjs/utils/object.js +0 -58
- package/dist/router/static-router/index.js +0 -5
- package/dist/router/static-router/router.js +0 -75
- package/dist/types/middleware/validator/index.d.ts +0 -6
- package/dist/types/router/static-router/index.d.ts +0 -1
- package/dist/types/router/static-router/router.d.ts +0 -9
- package/dist/types/utils/object.d.ts +0 -2
- package/dist/utils/object.js +0 -34
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<div align="center">
|
|
2
|
-
<a href="https://
|
|
2
|
+
<a href="https://hono.dev">
|
|
3
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>
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
<hr />
|
|
8
8
|
|
|
9
9
|
<p align="center">
|
|
10
|
-
<a href="https://
|
|
11
|
-
<i>
|
|
10
|
+
<a href="https://hono.dev"><b>Documentation :point_right: hono.dev</b></a><br />
|
|
11
|
+
<i>v3 has been released!</i> <a href="docs/MIGRATION.md">Migration guide</b>
|
|
12
12
|
</p>
|
|
13
13
|
|
|
14
14
|
<hr />
|
|
@@ -17,51 +17,55 @@
|
|
|
17
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
|
+
[](https://bundlephobia.com/result?p=hono)
|
|
21
|
+
[](https://bundlephobia.com/result?p=hono)
|
|
20
22
|
[](https://www.npmjs.com/package/hono)
|
|
21
23
|
[](https://github.com/honojs/hono/pulse)
|
|
22
24
|
[](https://github.com/honojs/hono/commits/main)
|
|
23
25
|
[](https://doc.deno.land/https/deno.land/x/hono/mod.ts)
|
|
24
26
|
[](https://discord.gg/KMh2eNSdxV)
|
|
25
27
|
|
|
26
|
-
Hono - _
|
|
28
|
+
Hono - _**\[炎\] means flame🔥 in Japanese**_ - is a small, simple, and ultrafast web framework for the Edge.
|
|
29
|
+
It works on Cloudflare Workers, Fastly Compute@Edge, Deno, Bun, Vercel, Lagon, Node.js, and others.
|
|
30
|
+
Fast, but not only fast.
|
|
27
31
|
|
|
28
32
|
```ts
|
|
29
33
|
import { Hono } from 'hono'
|
|
30
34
|
const app = new Hono()
|
|
31
35
|
|
|
32
|
-
app.get('/', (c) => c.text('Hono
|
|
36
|
+
app.get('/', (c) => c.text('Hono!'))
|
|
33
37
|
|
|
34
38
|
export default app
|
|
35
39
|
```
|
|
36
40
|
|
|
37
41
|
## Features
|
|
38
42
|
|
|
39
|
-
- **Ultrafast** - The routers are really smart. Not using linear loops.
|
|
40
|
-
- **
|
|
41
|
-
- **
|
|
42
|
-
- **
|
|
43
|
-
- **
|
|
43
|
+
- **Ultrafast** - The routers are really fast and smart. Not using linear loops. Fast.
|
|
44
|
+
- **Multi-runtime** - Works on Cloudflare Workers, Fastly Compute@Edge, Deno, Bun, Lagon, or Node.js. The same code runs on all platforms.
|
|
45
|
+
- **Batteries Included** - Hono has built-in middleware, custom middleware, and third-party middleware. Batteries included.
|
|
46
|
+
- **Fine DX** - First-class TypeScript support. Now, we've got "Types".
|
|
47
|
+
- **Small** - About 20kB. Zero-dependencies. Using only Web Standard API.
|
|
44
48
|
|
|
45
49
|
## Benchmarks
|
|
46
50
|
|
|
47
|
-
**Hono is fastest**, compared to other routers for Cloudflare Workers.
|
|
51
|
+
**Hono is the fastest**, compared to other routers for Cloudflare Workers.
|
|
48
52
|
|
|
49
|
-
```
|
|
50
|
-
Hono x
|
|
51
|
-
itty-router x
|
|
52
|
-
sunder x
|
|
53
|
-
worktop x
|
|
53
|
+
```
|
|
54
|
+
Hono x 385,807 ops/sec ±5.02% (76 runs sampled)
|
|
55
|
+
itty-router x 205,318 ops/sec ±3.63% (84 runs sampled)
|
|
56
|
+
sunder x 287,198 ops/sec ±4.90% (74 runs sampled)
|
|
57
|
+
worktop x 191,134 ops/sec ±3.06% (85 runs sampled)
|
|
54
58
|
Fastest is Hono
|
|
55
|
-
✨ Done in
|
|
59
|
+
✨ Done in 27.51s.
|
|
56
60
|
```
|
|
57
61
|
|
|
58
62
|
## Documentation
|
|
59
63
|
|
|
60
|
-
The documentation is available on [
|
|
64
|
+
The documentation is available on [hono.dev](https://hono.dev).
|
|
61
65
|
|
|
62
66
|
## Migration
|
|
63
67
|
|
|
64
|
-
|
|
68
|
+
The migration guide is available on [docs/MIGRATION.md](docs/MIGRATION.md).
|
|
65
69
|
|
|
66
70
|
## Communication
|
|
67
71
|
|
|
@@ -12,7 +12,7 @@ var serveStatic = (options = { root: "" }) => {
|
|
|
12
12
|
}
|
|
13
13
|
const url = new URL(c.req.url);
|
|
14
14
|
let path = getFilePath({
|
|
15
|
-
filename: options.path ?? url.pathname,
|
|
15
|
+
filename: options.path ?? decodeURI(url.pathname),
|
|
16
16
|
root: options.root,
|
|
17
17
|
defaultDocument: DEFAULT_DOCUMENT
|
|
18
18
|
});
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
// src/adapter/cloudflare-pages/handler.ts
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
return app.fetch(request, env, { waitUntil, passThroughOnException: () => {
|
|
6
|
-
} });
|
|
7
|
-
};
|
|
8
|
-
};
|
|
2
|
+
import { Hono } from "../../hono.js";
|
|
3
|
+
var handle = (subApp, path = "/") => ({ request, env, waitUntil }) => new Hono().route(path, subApp).fetch(request, env, { waitUntil, passThroughOnException: () => {
|
|
4
|
+
} });
|
|
9
5
|
export {
|
|
10
6
|
handle
|
|
11
7
|
};
|
|
@@ -11,7 +11,7 @@ var serveStatic = (options = { root: "" }) => {
|
|
|
11
11
|
}
|
|
12
12
|
const url = new URL(c.req.url);
|
|
13
13
|
const path = getFilePath({
|
|
14
|
-
filename: options.path ?? url.pathname,
|
|
14
|
+
filename: options.path ?? decodeURI(url.pathname),
|
|
15
15
|
root: options.root,
|
|
16
16
|
defaultDocument: DEFAULT_DOCUMENT
|
|
17
17
|
});
|
|
@@ -10,7 +10,7 @@ var serveStatic = (options = { root: "" }) => {
|
|
|
10
10
|
}
|
|
11
11
|
const url = new URL(c.req.url);
|
|
12
12
|
let path = getFilePath({
|
|
13
|
-
filename: options.path ?? url.pathname,
|
|
13
|
+
filename: options.path ?? decodeURI(url.pathname),
|
|
14
14
|
root: options.root,
|
|
15
15
|
defaultDocument: DEFAULT_DOCUMENT
|
|
16
16
|
});
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
// src/adapter/nextjs/handler.ts
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
return app.fetch(req);
|
|
5
|
-
};
|
|
6
|
-
};
|
|
2
|
+
import { Hono } from "../../hono.js";
|
|
3
|
+
var handle = (subApp, path = "/") => async (req) => new Hono().route(path, subApp).fetch(req);
|
|
7
4
|
export {
|
|
8
5
|
handle
|
|
9
6
|
};
|
|
@@ -34,7 +34,7 @@ const serveStatic = (options = { root: "" }) => {
|
|
|
34
34
|
}
|
|
35
35
|
const url = new URL(c.req.url);
|
|
36
36
|
let path = (0, import_filepath.getFilePath)({
|
|
37
|
-
filename: options.path ?? url.pathname,
|
|
37
|
+
filename: options.path ?? decodeURI(url.pathname),
|
|
38
38
|
root: options.root,
|
|
39
39
|
defaultDocument: DEFAULT_DOCUMENT
|
|
40
40
|
});
|
|
@@ -21,13 +21,9 @@ __export(handler_exports, {
|
|
|
21
21
|
handle: () => handle
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(handler_exports);
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return app.fetch(request, env, { waitUntil, passThroughOnException: () => {
|
|
28
|
-
} });
|
|
29
|
-
};
|
|
30
|
-
};
|
|
24
|
+
var import_hono = require("../../hono");
|
|
25
|
+
const handle = (subApp, path = "/") => ({ request, env, waitUntil }) => new import_hono.Hono().route(path, subApp).fetch(request, env, { waitUntil, passThroughOnException: () => {
|
|
26
|
+
} });
|
|
31
27
|
// Annotate the CommonJS export names for ESM import in node:
|
|
32
28
|
0 && (module.exports = {
|
|
33
29
|
handle
|
|
@@ -33,7 +33,7 @@ const serveStatic = (options = { root: "" }) => {
|
|
|
33
33
|
}
|
|
34
34
|
const url = new URL(c.req.url);
|
|
35
35
|
const path = (0, import_filepath.getFilePath)({
|
|
36
|
-
filename: options.path ?? url.pathname,
|
|
36
|
+
filename: options.path ?? decodeURI(url.pathname),
|
|
37
37
|
root: options.root,
|
|
38
38
|
defaultDocument: DEFAULT_DOCUMENT
|
|
39
39
|
});
|
|
@@ -16,13 +16,13 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var
|
|
20
|
-
__export(
|
|
21
|
-
|
|
19
|
+
var deno_exports = {};
|
|
20
|
+
__export(deno_exports, {
|
|
21
|
+
serveStatic: () => import_serve_static.serveStatic
|
|
22
22
|
});
|
|
23
|
-
module.exports = __toCommonJS(
|
|
24
|
-
var
|
|
23
|
+
module.exports = __toCommonJS(deno_exports);
|
|
24
|
+
var import_serve_static = require("./serve-static");
|
|
25
25
|
// Annotate the CommonJS export names for ESM import in node:
|
|
26
26
|
0 && (module.exports = {
|
|
27
|
-
|
|
27
|
+
serveStatic
|
|
28
28
|
});
|
|
@@ -32,7 +32,7 @@ const serveStatic = (options = { root: "" }) => {
|
|
|
32
32
|
}
|
|
33
33
|
const url = new URL(c.req.url);
|
|
34
34
|
let path = (0, import_filepath.getFilePath)({
|
|
35
|
-
filename: options.path ?? url.pathname,
|
|
35
|
+
filename: options.path ?? decodeURI(url.pathname),
|
|
36
36
|
root: options.root,
|
|
37
37
|
defaultDocument: DEFAULT_DOCUMENT
|
|
38
38
|
});
|
|
@@ -21,11 +21,8 @@ __export(handler_exports, {
|
|
|
21
21
|
handle: () => handle
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(handler_exports);
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return app.fetch(req);
|
|
27
|
-
};
|
|
28
|
-
};
|
|
24
|
+
var import_hono = require("../../hono");
|
|
25
|
+
const handle = (subApp, path = "/") => async (req) => new import_hono.Hono().route(path, subApp).fetch(req);
|
|
29
26
|
// Annotate the CommonJS export names for ESM import in node:
|
|
30
27
|
0 && (module.exports = {
|
|
31
28
|
handle
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var client_exports = {};
|
|
20
|
+
__export(client_exports, {
|
|
21
|
+
hc: () => hc
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(client_exports);
|
|
24
|
+
var import_utils = require("./utils");
|
|
25
|
+
const createProxy = (callback, path) => {
|
|
26
|
+
const proxy = new Proxy(() => {
|
|
27
|
+
}, {
|
|
28
|
+
get(_obj, key) {
|
|
29
|
+
if (typeof key !== "string")
|
|
30
|
+
return void 0;
|
|
31
|
+
return createProxy(callback, [...path, key]);
|
|
32
|
+
},
|
|
33
|
+
apply(_1, _2, args) {
|
|
34
|
+
return callback({
|
|
35
|
+
path,
|
|
36
|
+
args
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
return proxy;
|
|
41
|
+
};
|
|
42
|
+
class ClientRequestImpl {
|
|
43
|
+
constructor(url, method) {
|
|
44
|
+
this.queryParams = void 0;
|
|
45
|
+
this.pathParams = {};
|
|
46
|
+
this.cType = void 0;
|
|
47
|
+
this.fetch = (args, opt) => {
|
|
48
|
+
if (args) {
|
|
49
|
+
if (args.query) {
|
|
50
|
+
for (const [k, v] of Object.entries(args.query)) {
|
|
51
|
+
this.queryParams || (this.queryParams = new URLSearchParams());
|
|
52
|
+
this.queryParams.set(k, v);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (args.queries) {
|
|
56
|
+
for (const [k, v] of Object.entries(args.queries)) {
|
|
57
|
+
for (const v2 of v) {
|
|
58
|
+
this.queryParams || (this.queryParams = new URLSearchParams());
|
|
59
|
+
this.queryParams.append(k, v2);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (args.form) {
|
|
64
|
+
const form = new FormData();
|
|
65
|
+
for (const [k, v] of Object.entries(args.form)) {
|
|
66
|
+
form.append(k, v);
|
|
67
|
+
}
|
|
68
|
+
this.rBody = form;
|
|
69
|
+
}
|
|
70
|
+
if (args.json) {
|
|
71
|
+
this.rBody = JSON.stringify(args.json);
|
|
72
|
+
this.cType = "application/json";
|
|
73
|
+
}
|
|
74
|
+
if (args.param) {
|
|
75
|
+
this.pathParams = args.param;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
let methodUpperCase = this.method.toUpperCase();
|
|
79
|
+
let setBody = !(methodUpperCase === "GET" || methodUpperCase === "HEAD");
|
|
80
|
+
const headerValues = opt?.headers ? opt.headers : {};
|
|
81
|
+
if (this.cType)
|
|
82
|
+
headerValues["Content-Type"] = this.cType;
|
|
83
|
+
const headers = new Headers(headerValues ?? void 0);
|
|
84
|
+
let url = this.url;
|
|
85
|
+
url = (0, import_utils.removeIndexString)(url);
|
|
86
|
+
url = (0, import_utils.replaceUrlParam)(url, this.pathParams);
|
|
87
|
+
if (this.queryParams) {
|
|
88
|
+
url = url + "?" + this.queryParams.toString();
|
|
89
|
+
}
|
|
90
|
+
methodUpperCase = this.method.toUpperCase();
|
|
91
|
+
setBody = !(methodUpperCase === "GET" || methodUpperCase === "HEAD");
|
|
92
|
+
return fetch(url, {
|
|
93
|
+
body: setBody ? this.rBody : void 0,
|
|
94
|
+
method: methodUpperCase,
|
|
95
|
+
headers
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
this.url = url;
|
|
99
|
+
this.method = method;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const hc = (baseUrl, options) => createProxy(async (opts) => {
|
|
103
|
+
const parts = [...opts.path];
|
|
104
|
+
let method = "";
|
|
105
|
+
if (/^\$/.test(parts[parts.length - 1])) {
|
|
106
|
+
const last = parts.pop();
|
|
107
|
+
if (last) {
|
|
108
|
+
method = last.replace(/^\$/, "");
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
const path = parts.join("/");
|
|
112
|
+
const url = (0, import_utils.mergePath)(baseUrl, path);
|
|
113
|
+
const req = new ClientRequestImpl(url, method);
|
|
114
|
+
if (method) {
|
|
115
|
+
options ?? (options = {});
|
|
116
|
+
const args = (0, import_utils.deepMerge)(options, { ...opts.args[1] ?? {} });
|
|
117
|
+
return req.fetch(opts.args[0], args);
|
|
118
|
+
}
|
|
119
|
+
return req;
|
|
120
|
+
}, []);
|
|
121
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
122
|
+
0 && (module.exports = {
|
|
123
|
+
hc
|
|
124
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var client_exports = {};
|
|
20
|
+
__export(client_exports, {
|
|
21
|
+
hc: () => import_client.hc
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(client_exports);
|
|
24
|
+
var import_client = require("./client");
|
|
25
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
26
|
+
0 && (module.exports = {
|
|
27
|
+
hc
|
|
28
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var types_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(types_exports);
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var utils_exports = {};
|
|
20
|
+
__export(utils_exports, {
|
|
21
|
+
deepMerge: () => deepMerge,
|
|
22
|
+
mergePath: () => mergePath,
|
|
23
|
+
removeIndexString: () => removeIndexString,
|
|
24
|
+
replaceUrlParam: () => replaceUrlParam
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(utils_exports);
|
|
27
|
+
var import_url = require("../utils/url");
|
|
28
|
+
const mergePath = (base, path) => {
|
|
29
|
+
base = base.replace(/\/+$/, "");
|
|
30
|
+
base = base + "/";
|
|
31
|
+
path = path.replace(/^\/+/, "");
|
|
32
|
+
return base + path;
|
|
33
|
+
};
|
|
34
|
+
const replaceUrlParam = (urlString, params) => {
|
|
35
|
+
for (const [k, v] of Object.entries(params)) {
|
|
36
|
+
const reg = new RegExp("/:" + k);
|
|
37
|
+
urlString = urlString.replace(reg, `/${v}`);
|
|
38
|
+
}
|
|
39
|
+
return urlString;
|
|
40
|
+
};
|
|
41
|
+
const removeIndexString = (urlSting) => {
|
|
42
|
+
const path = (0, import_url.getPathFromURL)(urlSting);
|
|
43
|
+
if (path === "/index") {
|
|
44
|
+
return urlSting.replace(/index$/, "");
|
|
45
|
+
}
|
|
46
|
+
return urlSting;
|
|
47
|
+
};
|
|
48
|
+
function isObject(item) {
|
|
49
|
+
return typeof item === "object" && item !== null && !Array.isArray(item);
|
|
50
|
+
}
|
|
51
|
+
function deepMerge(target, source) {
|
|
52
|
+
if (!isObject(target) && !isObject(source)) {
|
|
53
|
+
return source;
|
|
54
|
+
}
|
|
55
|
+
const merged = { ...target };
|
|
56
|
+
for (const key in source) {
|
|
57
|
+
const value = source[key];
|
|
58
|
+
if (isObject(merged[key]) && isObject(value)) {
|
|
59
|
+
merged[key] = deepMerge(merged[key], value);
|
|
60
|
+
} else {
|
|
61
|
+
merged[key] = value;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return merged;
|
|
65
|
+
}
|
|
66
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
67
|
+
0 && (module.exports = {
|
|
68
|
+
deepMerge,
|
|
69
|
+
mergePath,
|
|
70
|
+
removeIndexString,
|
|
71
|
+
replaceUrlParam
|
|
72
|
+
});
|
package/dist/cjs/compose.js
CHANGED
|
@@ -22,7 +22,7 @@ __export(compose_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(compose_exports);
|
|
24
24
|
var import_context = require("./context");
|
|
25
|
-
const compose = (middleware,
|
|
25
|
+
const compose = (middleware, onError, onNotFound) => {
|
|
26
26
|
const middlewareLength = middleware.length;
|
|
27
27
|
return (context, next) => {
|
|
28
28
|
let index = -1;
|
package/dist/cjs/context.js
CHANGED
|
@@ -160,14 +160,13 @@ class Context {
|
|
|
160
160
|
if (options.notFoundHandler) {
|
|
161
161
|
this.notFoundHandler = options.notFoundHandler;
|
|
162
162
|
}
|
|
163
|
-
this._queryIndex = options.queryIndex;
|
|
164
163
|
}
|
|
165
164
|
}
|
|
166
165
|
get req() {
|
|
167
166
|
if (this._req) {
|
|
168
167
|
return this._req;
|
|
169
168
|
} else {
|
|
170
|
-
this._req = new import_request.HonoRequest(this.rawRequest, this._paramData
|
|
169
|
+
this._req = new import_request.HonoRequest(this.rawRequest, this._paramData);
|
|
171
170
|
this.rawRequest = void 0;
|
|
172
171
|
this._paramData = void 0;
|
|
173
172
|
return this._req;
|
package/dist/cjs/hono.js
CHANGED
|
@@ -23,38 +23,39 @@ __export(hono_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(hono_exports);
|
|
24
24
|
var import_compose = require("./compose");
|
|
25
25
|
var import_context = require("./context");
|
|
26
|
+
var import_http_exception = require("./http-exception");
|
|
26
27
|
var import_router = require("./router");
|
|
27
28
|
var import_reg_exp_router = require("./router/reg-exp-router");
|
|
28
29
|
var import_smart_router = require("./router/smart-router");
|
|
29
|
-
var import_static_router = require("./router/static-router");
|
|
30
30
|
var import_trie_router = require("./router/trie-router");
|
|
31
|
-
var import_http_exception = require("./utils/http-exception");
|
|
32
31
|
var import_url = require("./utils/url");
|
|
33
32
|
function defineDynamicClass() {
|
|
34
33
|
return class {
|
|
35
34
|
};
|
|
36
35
|
}
|
|
36
|
+
const notFoundHandler = (c) => {
|
|
37
|
+
return c.text("404 Not Found", 404);
|
|
38
|
+
};
|
|
39
|
+
const errorHandler = (err, c) => {
|
|
40
|
+
if (err instanceof import_http_exception.HTTPException) {
|
|
41
|
+
return err.getResponse();
|
|
42
|
+
}
|
|
43
|
+
console.trace(err);
|
|
44
|
+
const message = "Internal Server Error";
|
|
45
|
+
return c.text(message, 500);
|
|
46
|
+
};
|
|
37
47
|
class Hono extends defineDynamicClass() {
|
|
38
48
|
constructor(init = {}) {
|
|
39
49
|
super();
|
|
40
50
|
this.router = new import_smart_router.SmartRouter({
|
|
41
|
-
routers: [new
|
|
51
|
+
routers: [new import_reg_exp_router.RegExpRouter(), new import_trie_router.TrieRouter()]
|
|
42
52
|
});
|
|
43
53
|
this.strict = true;
|
|
44
54
|
this._tempPath = "";
|
|
45
55
|
this.path = "*";
|
|
46
56
|
this.routes = [];
|
|
47
|
-
this.notFoundHandler =
|
|
48
|
-
|
|
49
|
-
};
|
|
50
|
-
this.errorHandler = (err, c) => {
|
|
51
|
-
if (err instanceof import_http_exception.HTTPException) {
|
|
52
|
-
return err.getResponse();
|
|
53
|
-
}
|
|
54
|
-
console.trace(err);
|
|
55
|
-
const message = "Internal Server Error";
|
|
56
|
-
return c.text(message, 500);
|
|
57
|
-
};
|
|
57
|
+
this.notFoundHandler = notFoundHandler;
|
|
58
|
+
this.errorHandler = errorHandler;
|
|
58
59
|
this.handleEvent = (event) => {
|
|
59
60
|
return this.dispatch(event.request, event);
|
|
60
61
|
};
|
|
@@ -85,9 +86,11 @@ class Hono extends defineDynamicClass() {
|
|
|
85
86
|
if (!method)
|
|
86
87
|
return this;
|
|
87
88
|
this.path = path;
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
89
|
+
for (const m of [method].flat()) {
|
|
90
|
+
handlers.map((handler) => {
|
|
91
|
+
this.addRoute(m.toUpperCase(), this.path, handler);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
91
94
|
return this;
|
|
92
95
|
};
|
|
93
96
|
this.use = (arg1, ...handlers) => {
|
|
@@ -107,7 +110,8 @@ class Hono extends defineDynamicClass() {
|
|
|
107
110
|
this._tempPath = path;
|
|
108
111
|
if (app) {
|
|
109
112
|
app.routes.map((r) => {
|
|
110
|
-
|
|
113
|
+
const handler = app.errorHandler === errorHandler ? r.handler : async (c, next) => (await (0, import_compose.compose)([r.handler], app.errorHandler)(c, next)).res;
|
|
114
|
+
this.addRoute(r.method, r.path, handler);
|
|
111
115
|
});
|
|
112
116
|
this._tempPath = "";
|
|
113
117
|
}
|
|
@@ -148,7 +152,7 @@ class Hono extends defineDynamicClass() {
|
|
|
148
152
|
throw err;
|
|
149
153
|
}
|
|
150
154
|
dispatch(request, eventOrExecutionCtx, env) {
|
|
151
|
-
const
|
|
155
|
+
const path = (0, import_url.getPathFromURL)(request.url, this.strict);
|
|
152
156
|
const method = request.method;
|
|
153
157
|
const result = this.matchRoute(method, path);
|
|
154
158
|
const paramData = result?.params;
|
|
@@ -156,8 +160,7 @@ class Hono extends defineDynamicClass() {
|
|
|
156
160
|
env,
|
|
157
161
|
executionCtx: eventOrExecutionCtx,
|
|
158
162
|
notFoundHandler: this.notFoundHandler,
|
|
159
|
-
paramData
|
|
160
|
-
queryIndex
|
|
163
|
+
paramData
|
|
161
164
|
});
|
|
162
165
|
if (result?.handlers.length === 1) {
|
|
163
166
|
const handler = result.handlers[0];
|
|
@@ -195,7 +198,7 @@ class Hono extends defineDynamicClass() {
|
|
|
195
198
|
})();
|
|
196
199
|
}
|
|
197
200
|
const handlers = result ? result.handlers : [this.notFoundHandler];
|
|
198
|
-
const composed = (0, import_compose.compose)(handlers, this.
|
|
201
|
+
const composed = (0, import_compose.compose)(handlers, this.errorHandler, this.notFoundHandler);
|
|
199
202
|
return (async () => {
|
|
200
203
|
try {
|
|
201
204
|
const tmp = composed(c);
|
|
@@ -21,7 +21,7 @@ __export(http_exception_exports, {
|
|
|
21
21
|
HTTPException: () => HTTPException
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(http_exception_exports);
|
|
24
|
-
var import_http_status = require("./http-status");
|
|
24
|
+
var import_http_status = require("./utils/http-status");
|
|
25
25
|
class HTTPException extends Error {
|
|
26
26
|
constructor(status = 500, options) {
|
|
27
27
|
super(options?.message || (0, import_http_status.getStatusText)(status));
|
|
@@ -21,9 +21,9 @@ __export(basic_auth_exports, {
|
|
|
21
21
|
basicAuth: () => basicAuth
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(basic_auth_exports);
|
|
24
|
+
var import_http_exception = require("../../http-exception");
|
|
24
25
|
var import_buffer = require("../../utils/buffer");
|
|
25
26
|
var import_encode = require("../../utils/encode");
|
|
26
|
-
var import_http_exception = require("../../utils/http-exception");
|
|
27
27
|
const CREDENTIALS_REGEXP = /^ *(?:[Bb][Aa][Ss][Ii][Cc]) +([A-Za-z0-9._~+/-]+=*) *$/;
|
|
28
28
|
const USER_PASS_REGEXP = /^([^:]*):(.*)$/;
|
|
29
29
|
const auth = (req) => {
|
|
@@ -21,8 +21,8 @@ __export(bearer_auth_exports, {
|
|
|
21
21
|
bearerAuth: () => bearerAuth
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(bearer_auth_exports);
|
|
24
|
+
var import_http_exception = require("../../http-exception");
|
|
24
25
|
var import_buffer = require("../../utils/buffer");
|
|
25
|
-
var import_http_exception = require("../../utils/http-exception");
|
|
26
26
|
const TOKEN_STRINGS = "[A-Za-z0-9._~+/-]+=*";
|
|
27
27
|
const PREFIX = "Bearer";
|
|
28
28
|
const bearerAuth = (options) => {
|