hono 3.2.0-rc.3 â 3.2.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 +5 -5
- package/dist/cjs/hono-base.js +30 -0
- package/dist/cjs/index.js +0 -5
- package/dist/cjs/preset/quick.js +2 -2
- package/dist/cjs/preset/tiny.js +2 -2
- package/dist/cjs/router/linear-router/router.js +1 -0
- package/dist/cjs/router/pattern-router/router.js +2 -1
- package/dist/cjs/router/reg-exp-router/router.js +1 -0
- package/dist/cjs/router/smart-router/router.js +2 -0
- package/dist/cjs/router/trie-router/router.js +1 -0
- package/dist/hono-base.js +30 -0
- package/dist/index.js +0 -5
- package/dist/preset/quick.js +2 -2
- package/dist/preset/tiny.js +2 -2
- package/dist/router/linear-router/router.js +1 -0
- package/dist/router/pattern-router/router.js +2 -1
- package/dist/router/reg-exp-router/router.js +1 -0
- package/dist/router/smart-router/router.js +2 -0
- package/dist/router/trie-router/router.js +1 -0
- package/dist/types/hono-base.d.ts +9 -0
- package/dist/types/index.d.ts +0 -5
- package/dist/types/preset/quick.d.ts +3 -1
- package/dist/types/preset/tiny.d.ts +3 -1
- package/dist/types/router/linear-router/router.d.ts +1 -0
- package/dist/types/router/pattern-router/router.d.ts +1 -0
- package/dist/types/router/reg-exp-router/router.d.ts +1 -0
- package/dist/types/router/smart-router/router.d.ts +1 -0
- package/dist/types/router/trie-router/router.d.ts +1 -0
- package/dist/types/router.d.ts +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -47,11 +47,11 @@ npm create hono@latest my-app
|
|
|
47
47
|
|
|
48
48
|
## Features
|
|
49
49
|
|
|
50
|
-
- **Ultrafast** - The router
|
|
51
|
-
- **
|
|
52
|
-
- **
|
|
53
|
-
- **
|
|
54
|
-
- **
|
|
50
|
+
- **Ultrafast** ð - The router `RegExpRouter` is really fast. Not using linear loops. Fast.
|
|
51
|
+
- **Lightweight** ðŠķ - The `hono/tiny` preset is under 12kB. Hono has zero dependencies and uses only the Web Standard API.
|
|
52
|
+
- **Multi-runtime** ð - Works on Cloudflare Workers, Fastly Compute@Edge, Deno, Bun, Lagon, AWS Lambda, or Node.js. The same code runs on all platforms.
|
|
53
|
+
- **Batteries Included** ð - Hono has built-in middleware, custom middleware, and third-party middleware. Batteries included.
|
|
54
|
+
- **Delightful DX** ð ïļ - Super clean APIs. First-class TypeScript support. Now, we've got "Types".
|
|
55
55
|
|
|
56
56
|
## Benchmarks
|
|
57
57
|
|
package/dist/cjs/hono-base.js
CHANGED
|
@@ -67,6 +67,11 @@ class Hono extends defineDynamicClass() {
|
|
|
67
67
|
const req = new Request(path, requestInit);
|
|
68
68
|
return await this.fetch(req);
|
|
69
69
|
};
|
|
70
|
+
this.fire = () => {
|
|
71
|
+
addEventListener("fetch", (event) => {
|
|
72
|
+
void event.respondWith(this.handleEvent(event));
|
|
73
|
+
});
|
|
74
|
+
};
|
|
70
75
|
const allMethods = [...import_router.METHODS, import_router.METHOD_NAME_ALL_LOWERCASE];
|
|
71
76
|
allMethods.map((method) => {
|
|
72
77
|
this[method] = (args1, ...args) => {
|
|
@@ -150,6 +155,31 @@ class Hono extends defineDynamicClass() {
|
|
|
150
155
|
);
|
|
151
156
|
});
|
|
152
157
|
}
|
|
158
|
+
mount(path, applicationHandler, optionHandler) {
|
|
159
|
+
const pathPrefixLength = (0, import_url.mergePath)(this._basePath, path).length;
|
|
160
|
+
const handler = async (c, next) => {
|
|
161
|
+
let executionContext = void 0;
|
|
162
|
+
try {
|
|
163
|
+
executionContext = c.executionCtx;
|
|
164
|
+
} catch {
|
|
165
|
+
}
|
|
166
|
+
const options = optionHandler ? optionHandler(c) : [c.env, executionContext];
|
|
167
|
+
const optionsArray = Array.isArray(options) ? options : [options];
|
|
168
|
+
const res = await applicationHandler(
|
|
169
|
+
new Request(new URL(c.req.path.slice(pathPrefixLength) || "/", c.req.url), c.req.raw),
|
|
170
|
+
...optionsArray
|
|
171
|
+
);
|
|
172
|
+
if (res)
|
|
173
|
+
return res;
|
|
174
|
+
await next();
|
|
175
|
+
};
|
|
176
|
+
this.addRoute(import_router.METHOD_NAME_ALL, (0, import_url.mergePath)(path, "*"), handler);
|
|
177
|
+
return this;
|
|
178
|
+
}
|
|
179
|
+
get routerName() {
|
|
180
|
+
this.matchRoute("GET", "/");
|
|
181
|
+
return this.router.name;
|
|
182
|
+
}
|
|
153
183
|
addRoute(method, path, handler) {
|
|
154
184
|
method = method.toUpperCase();
|
|
155
185
|
if (this._basePath) {
|
package/dist/cjs/index.js
CHANGED
|
@@ -22,11 +22,6 @@ __export(src_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(src_exports);
|
|
24
24
|
var import_hono = require("./hono");
|
|
25
|
-
import_hono.Hono.prototype.fire = function() {
|
|
26
|
-
addEventListener("fetch", (event) => {
|
|
27
|
-
void event.respondWith(this.handleEvent(event));
|
|
28
|
-
});
|
|
29
|
-
};
|
|
30
25
|
// Annotate the CommonJS export names for ESM import in node:
|
|
31
26
|
0 && (module.exports = {
|
|
32
27
|
Hono
|
package/dist/cjs/preset/quick.js
CHANGED
|
@@ -24,8 +24,8 @@ module.exports = __toCommonJS(quick_exports);
|
|
|
24
24
|
var import_hono_base = require("../hono-base");
|
|
25
25
|
var import_linear_router = require("../router/linear-router");
|
|
26
26
|
class Hono extends import_hono_base.HonoBase {
|
|
27
|
-
constructor() {
|
|
28
|
-
super();
|
|
27
|
+
constructor(init = {}) {
|
|
28
|
+
super(init);
|
|
29
29
|
this.router = new import_linear_router.LinearRouter();
|
|
30
30
|
}
|
|
31
31
|
}
|
package/dist/cjs/preset/tiny.js
CHANGED
|
@@ -24,8 +24,8 @@ module.exports = __toCommonJS(tiny_exports);
|
|
|
24
24
|
var import_hono_base = require("../hono-base");
|
|
25
25
|
var import_pattern_router = require("../router/pattern-router");
|
|
26
26
|
class Hono extends import_hono_base.HonoBase {
|
|
27
|
-
constructor() {
|
|
28
|
-
super();
|
|
27
|
+
constructor(init = {}) {
|
|
28
|
+
super(init);
|
|
29
29
|
this.router = new import_pattern_router.PatternRouter();
|
|
30
30
|
}
|
|
31
31
|
}
|
|
@@ -24,6 +24,7 @@ module.exports = __toCommonJS(router_exports);
|
|
|
24
24
|
var import_router = require("../../router");
|
|
25
25
|
class PatternRouter {
|
|
26
26
|
constructor() {
|
|
27
|
+
this.name = "PatternRouter";
|
|
27
28
|
this.routes = [];
|
|
28
29
|
this.dNames = {};
|
|
29
30
|
}
|
|
@@ -32,7 +33,7 @@ class PatternRouter {
|
|
|
32
33
|
if (endsWithWildcard) {
|
|
33
34
|
path = path.slice(0, -2);
|
|
34
35
|
}
|
|
35
|
-
const parts = path.match(
|
|
36
|
+
const parts = path.match(/\/?(:\w+(?:{[^}]+})?)|\/?[^\/\?]+|(\?)/g) || [];
|
|
36
37
|
if (parts[parts.length - 1] === "?") {
|
|
37
38
|
this.add(method, parts.slice(0, parts.length - 2).join(""), handler);
|
|
38
39
|
parts.pop();
|
|
@@ -24,6 +24,7 @@ module.exports = __toCommonJS(router_exports);
|
|
|
24
24
|
var import_router = require("../../router");
|
|
25
25
|
class SmartRouter {
|
|
26
26
|
constructor(init) {
|
|
27
|
+
this.name = "SmartRouter";
|
|
27
28
|
this.routers = [];
|
|
28
29
|
this.routes = [];
|
|
29
30
|
Object.assign(this, init);
|
|
@@ -63,6 +64,7 @@ class SmartRouter {
|
|
|
63
64
|
if (i === len) {
|
|
64
65
|
throw new Error("Fatal error");
|
|
65
66
|
}
|
|
67
|
+
this.name = `SmartRouter + ${this.activeRouter.name}`;
|
|
66
68
|
return res || null;
|
|
67
69
|
}
|
|
68
70
|
get activeRouter() {
|
package/dist/hono-base.js
CHANGED
|
@@ -45,6 +45,11 @@ var Hono = class extends defineDynamicClass() {
|
|
|
45
45
|
const req = new Request(path, requestInit);
|
|
46
46
|
return await this.fetch(req);
|
|
47
47
|
};
|
|
48
|
+
this.fire = () => {
|
|
49
|
+
addEventListener("fetch", (event) => {
|
|
50
|
+
void event.respondWith(this.handleEvent(event));
|
|
51
|
+
});
|
|
52
|
+
};
|
|
48
53
|
const allMethods = [...METHODS, METHOD_NAME_ALL_LOWERCASE];
|
|
49
54
|
allMethods.map((method) => {
|
|
50
55
|
this[method] = (args1, ...args) => {
|
|
@@ -128,6 +133,31 @@ var Hono = class extends defineDynamicClass() {
|
|
|
128
133
|
);
|
|
129
134
|
});
|
|
130
135
|
}
|
|
136
|
+
mount(path, applicationHandler, optionHandler) {
|
|
137
|
+
const pathPrefixLength = mergePath(this._basePath, path).length;
|
|
138
|
+
const handler = async (c, next) => {
|
|
139
|
+
let executionContext = void 0;
|
|
140
|
+
try {
|
|
141
|
+
executionContext = c.executionCtx;
|
|
142
|
+
} catch {
|
|
143
|
+
}
|
|
144
|
+
const options = optionHandler ? optionHandler(c) : [c.env, executionContext];
|
|
145
|
+
const optionsArray = Array.isArray(options) ? options : [options];
|
|
146
|
+
const res = await applicationHandler(
|
|
147
|
+
new Request(new URL(c.req.path.slice(pathPrefixLength) || "/", c.req.url), c.req.raw),
|
|
148
|
+
...optionsArray
|
|
149
|
+
);
|
|
150
|
+
if (res)
|
|
151
|
+
return res;
|
|
152
|
+
await next();
|
|
153
|
+
};
|
|
154
|
+
this.addRoute(METHOD_NAME_ALL, mergePath(path, "*"), handler);
|
|
155
|
+
return this;
|
|
156
|
+
}
|
|
157
|
+
get routerName() {
|
|
158
|
+
this.matchRoute("GET", "/");
|
|
159
|
+
return this.router.name;
|
|
160
|
+
}
|
|
131
161
|
addRoute(method, path, handler) {
|
|
132
162
|
method = method.toUpperCase();
|
|
133
163
|
if (this._basePath) {
|
package/dist/index.js
CHANGED
package/dist/preset/quick.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
import { HonoBase } from "../hono-base.js";
|
|
3
3
|
import { LinearRouter } from "../router/linear-router/index.js";
|
|
4
4
|
var Hono = class extends HonoBase {
|
|
5
|
-
constructor() {
|
|
6
|
-
super();
|
|
5
|
+
constructor(init = {}) {
|
|
6
|
+
super(init);
|
|
7
7
|
this.router = new LinearRouter();
|
|
8
8
|
}
|
|
9
9
|
};
|
package/dist/preset/tiny.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
import { HonoBase } from "../hono-base.js";
|
|
3
3
|
import { PatternRouter } from "../router/pattern-router/index.js";
|
|
4
4
|
var Hono = class extends HonoBase {
|
|
5
|
-
constructor() {
|
|
6
|
-
super();
|
|
5
|
+
constructor(init = {}) {
|
|
6
|
+
super(init);
|
|
7
7
|
this.router = new PatternRouter();
|
|
8
8
|
}
|
|
9
9
|
};
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { METHOD_NAME_ALL } from "../../router.js";
|
|
3
3
|
var PatternRouter = class {
|
|
4
4
|
constructor() {
|
|
5
|
+
this.name = "PatternRouter";
|
|
5
6
|
this.routes = [];
|
|
6
7
|
this.dNames = {};
|
|
7
8
|
}
|
|
@@ -10,7 +11,7 @@ var PatternRouter = class {
|
|
|
10
11
|
if (endsWithWildcard) {
|
|
11
12
|
path = path.slice(0, -2);
|
|
12
13
|
}
|
|
13
|
-
const parts = path.match(
|
|
14
|
+
const parts = path.match(/\/?(:\w+(?:{[^}]+})?)|\/?[^\/\?]+|(\?)/g) || [];
|
|
14
15
|
if (parts[parts.length - 1] === "?") {
|
|
15
16
|
this.add(method, parts.slice(0, parts.length - 2).join(""), handler);
|
|
16
17
|
parts.pop();
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { UnsupportedPathError } from "../../router.js";
|
|
3
3
|
var SmartRouter = class {
|
|
4
4
|
constructor(init) {
|
|
5
|
+
this.name = "SmartRouter";
|
|
5
6
|
this.routers = [];
|
|
6
7
|
this.routes = [];
|
|
7
8
|
Object.assign(this, init);
|
|
@@ -41,6 +42,7 @@ var SmartRouter = class {
|
|
|
41
42
|
if (i === len) {
|
|
42
43
|
throw new Error("Fatal error");
|
|
43
44
|
}
|
|
45
|
+
this.name = `SmartRouter + ${this.activeRouter.name}`;
|
|
44
46
|
return res || null;
|
|
45
47
|
}
|
|
46
48
|
get activeRouter() {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Context } from './context';
|
|
1
2
|
import type { ExecutionContext } from './context';
|
|
2
3
|
import type { Router } from './router';
|
|
3
4
|
import type { Env, ErrorHandler, H, HandlerInterface, MiddlewareHandlerInterface, NotFoundHandler, OnHandlerInterface, MergePath, MergeSchemaPath } from './types';
|
|
@@ -43,6 +44,13 @@ declare class Hono<E extends Env = Env, S = {}, BasePath extends string = '/'> e
|
|
|
43
44
|
onError(handler: ErrorHandler<E>): this;
|
|
44
45
|
notFound(handler: NotFoundHandler<E>): this;
|
|
45
46
|
showRoutes(): void;
|
|
47
|
+
/**
|
|
48
|
+
* @experimental
|
|
49
|
+
* `app.mount()` is an experimental feature.
|
|
50
|
+
* The API might be changed.
|
|
51
|
+
*/
|
|
52
|
+
mount(path: string, applicationHandler: (request: Request, ...args: any) => Response | Promise<Response>, optionHandler?: (c: Context) => unknown): Hono<E, S, BasePath>;
|
|
53
|
+
get routerName(): string;
|
|
46
54
|
private addRoute;
|
|
47
55
|
private matchRoute;
|
|
48
56
|
private handleError;
|
|
@@ -50,5 +58,6 @@ declare class Hono<E extends Env = Env, S = {}, BasePath extends string = '/'> e
|
|
|
50
58
|
handleEvent: (event: FetchEvent) => Response | Promise<Response>;
|
|
51
59
|
fetch: (request: Request, Env?: E['Bindings'] | {}, executionCtx?: ExecutionContext) => Response | Promise<Response>;
|
|
52
60
|
request: (input: Request | string | URL, requestInit?: RequestInit) => Promise<Response>;
|
|
61
|
+
fire: () => void;
|
|
53
62
|
}
|
|
54
63
|
export { Hono as HonoBase };
|
package/dist/types/index.d.ts
CHANGED
|
@@ -2,9 +2,4 @@ import { Hono } from './hono';
|
|
|
2
2
|
export type { Env, ErrorHandler, Handler, MiddlewareHandler, Next, NotFoundHandler, ValidationTargets, Input, } from './types';
|
|
3
3
|
export type { Context, ContextVariableMap } from './context';
|
|
4
4
|
export type { HonoRequest } from './request';
|
|
5
|
-
declare module './hono-base' {
|
|
6
|
-
interface HonoBase {
|
|
7
|
-
fire(): void;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
5
|
export { Hono };
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { HonoBase } from '../hono-base';
|
|
2
2
|
import type { Env } from '../types';
|
|
3
3
|
export declare class Hono<E extends Env = Env, S = {}, BasePath extends string = '/'> extends HonoBase<E, S, BasePath> {
|
|
4
|
-
constructor(
|
|
4
|
+
constructor(init?: Partial<Pick<Hono, 'getPath'> & {
|
|
5
|
+
strict: boolean;
|
|
6
|
+
}>);
|
|
5
7
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { HonoBase } from '../hono-base';
|
|
2
2
|
import type { Env } from '../types';
|
|
3
3
|
export declare class Hono<E extends Env = Env, S = {}, BasePath extends string = '/'> extends HonoBase<E, S, BasePath> {
|
|
4
|
-
constructor(
|
|
4
|
+
constructor(init?: Partial<Pick<Hono, 'getPath'> & {
|
|
5
|
+
strict: boolean;
|
|
6
|
+
}>);
|
|
5
7
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Router, Result } from '../../router';
|
|
2
2
|
export declare class LinearRouter<T> implements Router<T> {
|
|
3
|
+
name: string;
|
|
3
4
|
routes: [string, string, T][];
|
|
4
5
|
add(method: string, path: string, handler: T): void;
|
|
5
6
|
match(method: string, path: string): Result<T> | null;
|
package/dist/types/router.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export declare const METHOD_NAME_ALL: "ALL";
|
|
|
2
2
|
export declare const METHOD_NAME_ALL_LOWERCASE: "all";
|
|
3
3
|
export declare const METHODS: readonly ["get", "post", "put", "delete", "head", "options", "patch"];
|
|
4
4
|
export interface Router<T> {
|
|
5
|
+
name: string;
|
|
5
6
|
add(method: string, path: string, handler: T): void;
|
|
6
7
|
match(method: string, path: string): Result<T> | null;
|
|
7
8
|
}
|