hono 3.0.0-rc.8 → 3.0.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 +23 -19
- package/dist/adapter/bun/serve-static.js +1 -1
- package/dist/adapter/cloudflare-pages/handler.js +3 -6
- 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 -6
- 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 +122 -0
- package/dist/cjs/client/index.js +28 -0
- package/dist/cjs/client/types.js +16 -0
- package/dist/cjs/client/utils.js +52 -0
- package/dist/cjs/compose.js +1 -1
- package/dist/cjs/context.js +11 -8
- package/dist/cjs/hono.js +45 -45
- package/dist/cjs/{utils/http-exception.js → http-exception.js} +2 -3
- 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 +34 -47
- package/dist/cjs/router/reg-exp-router/node.js +12 -3
- package/dist/cjs/router/reg-exp-router/router.js +23 -7
- package/dist/cjs/router/reg-exp-router/trie.js +5 -2
- package/dist/cjs/utils/mime.js +25 -5
- package/dist/cjs/utils/url.js +13 -12
- package/dist/cjs/validator/index.js +28 -0
- package/dist/cjs/{middleware/validator/index.js → validator/validator.js} +3 -6
- package/dist/client/client.js +99 -0
- package/dist/client/index.js +5 -0
- package/dist/client/types.js +0 -0
- package/dist/client/utils.js +27 -0
- package/dist/compose.js +1 -1
- package/dist/context.js +11 -8
- package/dist/hono.js +45 -45
- package/dist/{utils/http-exception.js → http-exception.js} +3 -4
- 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 +34 -47
- package/dist/router/reg-exp-router/node.js +12 -3
- package/dist/router/reg-exp-router/router.js +23 -7
- package/dist/router/reg-exp-router/trie.js +5 -2
- package/dist/types/adapter/cloudflare-pages/handler.d.ts +15 -3
- 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 +37 -0
- package/dist/types/client/utils.d.ts +3 -0
- package/dist/types/compose.d.ts +1 -1
- package/dist/types/context.d.ts +7 -9
- package/dist/types/hono.d.ts +18 -27
- 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 +14 -15
- package/dist/types/router/reg-exp-router/node.d.ts +1 -1
- package/dist/types/router/reg-exp-router/trie.d.ts +1 -1
- package/dist/types/types.d.ts +70 -67
- package/dist/types/utils/types.d.ts +1 -0
- 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/mime.js +25 -5
- package/dist/utils/url.js +13 -12
- package/dist/validator/index.js +5 -0
- package/dist/{middleware/validator/index.js → validator/validator.js} +4 -7
- 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 -9
- 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,10 +1,7 @@
|
|
|
1
1
|
// src/adapter/cloudflare-pages/handler.ts
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
return app.fetch(request, env, { waitUntil, passThroughOnException });
|
|
6
|
-
};
|
|
7
|
-
};
|
|
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
|
+
} });
|
|
8
5
|
export {
|
|
9
6
|
handle
|
|
10
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,12 +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
|
-
};
|
|
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
|
+
} });
|
|
30
27
|
// Annotate the CommonJS export names for ESM import in node:
|
|
31
28
|
0 && (module.exports = {
|
|
32
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,122 @@
|
|
|
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) => 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
|
+
return req.fetch(opts.args[0], opts.args[1]);
|
|
116
|
+
}
|
|
117
|
+
return req;
|
|
118
|
+
}, []);
|
|
119
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
120
|
+
0 && (module.exports = {
|
|
121
|
+
hc
|
|
122
|
+
});
|
|
@@ -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,52 @@
|
|
|
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
|
+
mergePath: () => mergePath,
|
|
22
|
+
removeIndexString: () => removeIndexString,
|
|
23
|
+
replaceUrlParam: () => replaceUrlParam
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(utils_exports);
|
|
26
|
+
var import_url = require("../utils/url");
|
|
27
|
+
const mergePath = (base, path) => {
|
|
28
|
+
base = base.replace(/\/+$/, "");
|
|
29
|
+
base = base + "/";
|
|
30
|
+
path = path.replace(/^\/+/, "");
|
|
31
|
+
return base + path;
|
|
32
|
+
};
|
|
33
|
+
const replaceUrlParam = (urlString, params) => {
|
|
34
|
+
for (const [k, v] of Object.entries(params)) {
|
|
35
|
+
const reg = new RegExp("/:" + k);
|
|
36
|
+
urlString = urlString.replace(reg, `/${v}`);
|
|
37
|
+
}
|
|
38
|
+
return urlString;
|
|
39
|
+
};
|
|
40
|
+
const removeIndexString = (urlSting) => {
|
|
41
|
+
const path = (0, import_url.getPathFromURL)(urlSting);
|
|
42
|
+
if (path === "/index") {
|
|
43
|
+
return urlSting.replace(/index$/, "");
|
|
44
|
+
}
|
|
45
|
+
return urlSting;
|
|
46
|
+
};
|
|
47
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
48
|
+
0 && (module.exports = {
|
|
49
|
+
mergePath,
|
|
50
|
+
removeIndexString,
|
|
51
|
+
replaceUrlParam
|
|
52
|
+
});
|
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,18 +160,15 @@ 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
|
|
171
|
-
this.rawRequest =
|
|
172
|
-
|
|
173
|
-
this._paramData = null;
|
|
174
|
-
delete this._paramData;
|
|
169
|
+
this._req = new import_request.HonoRequest(this.rawRequest, this._paramData);
|
|
170
|
+
this.rawRequest = void 0;
|
|
171
|
+
this._paramData = void 0;
|
|
175
172
|
return this._req;
|
|
176
173
|
}
|
|
177
174
|
}
|
|
@@ -193,6 +190,12 @@ class Context {
|
|
|
193
190
|
return this._res || (this._res = new Response("404 Not Found", { status: 404 }));
|
|
194
191
|
}
|
|
195
192
|
set res(_res) {
|
|
193
|
+
if (this._res) {
|
|
194
|
+
this._res.headers.delete("content-type");
|
|
195
|
+
this._res.headers.forEach((v, k) => {
|
|
196
|
+
_res.headers.set(k, v);
|
|
197
|
+
});
|
|
198
|
+
}
|
|
196
199
|
this._res = _res;
|
|
197
200
|
this.finalized = true;
|
|
198
201
|
}
|
|
@@ -205,10 +208,10 @@ class Context {
|
|
|
205
208
|
return "bun";
|
|
206
209
|
}
|
|
207
210
|
if (typeof global?.WebSocketPair === "function") {
|
|
208
|
-
return "
|
|
211
|
+
return "workerd";
|
|
209
212
|
}
|
|
210
213
|
if (typeof global?.EdgeRuntime === "string") {
|
|
211
|
-
return "
|
|
214
|
+
return "edge-light";
|
|
212
215
|
}
|
|
213
216
|
let onFastly = false;
|
|
214
217
|
try {
|