hono 2.1.0 → 2.1.3
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/dist/compose.d.ts +2 -2
- package/dist/compose.js +4 -19
- package/dist/context.d.ts +4 -4
- package/dist/context.js +1 -1
- package/dist/hono.d.ts +7 -10
- package/dist/hono.js +1 -1
- package/dist/middleware/serve-static/module.d.mts +1 -1
- package/dist/middleware/serve-static/serve-static.d.ts +3 -2
- package/package.json +1 -1
package/dist/compose.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare const compose: <C>(middleware: Function[],
|
|
1
|
+
import type { NotFoundHandler } from './hono';
|
|
2
|
+
export declare const compose: <C>(middleware: Function[], onNotFound?: NotFoundHandler<import("./hono").Environment> | undefined) => (context: C, next?: Function | undefined) => Promise<C>;
|
package/dist/compose.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.compose = void 0;
|
|
4
4
|
const context_1 = require("./context");
|
|
5
5
|
// Based on the code in the MIT licensed `koa-compose` package.
|
|
6
|
-
const compose = (middleware,
|
|
6
|
+
const compose = (middleware, onNotFound) => {
|
|
7
7
|
const middlewareLength = middleware.length;
|
|
8
8
|
return (context, next) => {
|
|
9
9
|
let index = -1;
|
|
@@ -22,24 +22,9 @@ const compose = (middleware, onError, onNotFound) => {
|
|
|
22
22
|
}
|
|
23
23
|
return context;
|
|
24
24
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const tmp = handler(context, () => dispatch(i + 1));
|
|
29
|
-
res = tmp instanceof Promise ? await tmp : tmp;
|
|
30
|
-
}
|
|
31
|
-
catch (err) {
|
|
32
|
-
if (context instanceof context_1.HonoContext && onError) {
|
|
33
|
-
if (err instanceof Error) {
|
|
34
|
-
isError = true;
|
|
35
|
-
res = onError(err, context);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
if (!res) {
|
|
39
|
-
throw err;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
if (res && context instanceof context_1.HonoContext && (!context.finalized || isError)) {
|
|
25
|
+
const tmp = handler(context, () => dispatch(i + 1));
|
|
26
|
+
const res = tmp instanceof Promise ? await tmp : tmp;
|
|
27
|
+
if (res && context instanceof context_1.HonoContext && context.finalized === false) {
|
|
43
28
|
context.res = res;
|
|
44
29
|
}
|
|
45
30
|
return context;
|
package/dist/context.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/// <reference types="@cloudflare/workers-types" />
|
|
2
|
-
import type { Environment, NotFoundHandler, ContextVariableMap
|
|
2
|
+
import type { Environment, NotFoundHandler, ContextVariableMap } from './hono';
|
|
3
3
|
import type { CookieOptions } from './utils/cookie';
|
|
4
4
|
import type { StatusCode } from './utils/http-status';
|
|
5
5
|
declare type Headers = Record<string, string>;
|
|
6
6
|
export declare type Data = string | ArrayBuffer | ReadableStream;
|
|
7
|
-
export interface Context<RequestParamKeyType extends string = string, E extends Partial<Environment> =
|
|
7
|
+
export interface Context<RequestParamKeyType extends string = string, E extends Partial<Environment> = any> {
|
|
8
8
|
req: Request<RequestParamKeyType>;
|
|
9
|
-
env: E['Bindings']
|
|
9
|
+
env: E['Bindings'];
|
|
10
10
|
event: FetchEvent;
|
|
11
11
|
executionCtx: ExecutionContext;
|
|
12
12
|
finalized: boolean;
|
|
@@ -36,7 +36,7 @@ export interface Context<RequestParamKeyType extends string = string, E extends
|
|
|
36
36
|
}
|
|
37
37
|
export declare class HonoContext<RequestParamKeyType extends string = string, E extends Partial<Environment> = Environment> implements Context<RequestParamKeyType, E> {
|
|
38
38
|
req: Request<RequestParamKeyType>;
|
|
39
|
-
env:
|
|
39
|
+
env: E['Bindings'];
|
|
40
40
|
finalized: boolean;
|
|
41
41
|
_status: StatusCode;
|
|
42
42
|
private _executionCtx;
|
package/dist/context.js
CHANGED
package/dist/hono.d.ts
CHANGED
|
@@ -16,11 +16,11 @@ export declare type Next = () => Promise<void>;
|
|
|
16
16
|
declare type ParamKeyName<NameWithPattern> = NameWithPattern extends `${infer Name}{${infer _Pattern}` ? Name : NameWithPattern;
|
|
17
17
|
declare type ParamKey<Component> = Component extends `:${infer NameWithPattern}` ? ParamKeyName<NameWithPattern> : never;
|
|
18
18
|
declare type ParamKeys<Path> = Path extends `${infer Component}/${infer Rest}` ? ParamKey<Component> | ParamKeys<Rest> : ParamKey<Path>;
|
|
19
|
-
interface HandlerInterface<T extends string, E extends Partial<Environment> = Environment, U = Hono<E, T>> {
|
|
20
|
-
<Path extends string>
|
|
21
|
-
(path: string, ...handlers: Handler<string, E>[]): U;
|
|
22
|
-
<Path extends string>(...handlers: Handler<ParamKeys<Path> extends never ? string : ParamKeys<Path>, E>[]): U;
|
|
19
|
+
interface HandlerInterface<T extends string = string, E extends Partial<Environment> = Environment, U = Hono<E, T>> {
|
|
20
|
+
<Path extends string, Env extends Partial<Environment> = E>(...handlers: Handler<ParamKeys<Path> extends never ? string : ParamKeys<Path>, Env>[]): U;
|
|
23
21
|
(...handlers: Handler<string, E>[]): U;
|
|
22
|
+
<Path extends string, Env extends Partial<Environment> = E>(path: Path, ...handlers: Handler<ParamKeys<Path> extends never ? string : ParamKeys<Path>, Env>[]): U;
|
|
23
|
+
(path: string, ...handlers: Handler<string, E>[]): U;
|
|
24
24
|
}
|
|
25
25
|
interface Route<E extends Partial<Environment> = Environment> {
|
|
26
26
|
path: string;
|
|
@@ -37,10 +37,7 @@ declare const Hono_base: new <E_1 extends Partial<Environment> = Environment, T
|
|
|
37
37
|
options: HandlerInterface<T, E_1, U>;
|
|
38
38
|
patch: HandlerInterface<T, E_1, U>;
|
|
39
39
|
};
|
|
40
|
-
export declare class Hono<E extends {
|
|
41
|
-
Bindings?: Bindings;
|
|
42
|
-
Variables?: Variables;
|
|
43
|
-
} = Environment, P extends string = '/'> extends Hono_base<E, P, Hono<E, P>> {
|
|
40
|
+
export declare class Hono<E extends Partial<Environment> = Environment, P extends string = '/'> extends Hono_base<E, P, Hono<E, P>> {
|
|
44
41
|
readonly router: Router<Handler<string, E>>;
|
|
45
42
|
readonly strict: boolean;
|
|
46
43
|
private _tempPath;
|
|
@@ -50,8 +47,8 @@ export declare class Hono<E extends {
|
|
|
50
47
|
private notFoundHandler;
|
|
51
48
|
private errorHandler;
|
|
52
49
|
route(path: string, app?: Hono<any>): Hono<E, P>;
|
|
53
|
-
use
|
|
54
|
-
use(...middleware: Handler<
|
|
50
|
+
use<Path extends string = string, Env extends Partial<Environment> = E>(...middleware: Handler<Path, Env>[]): Hono<Env, Path>;
|
|
51
|
+
use<Path extends string = string, Env extends Partial<Environment> = E>(arg1: string, ...middleware: Handler<Path, Env>[]): Hono<Env, Path>;
|
|
55
52
|
onError(handler: ErrorHandler): Hono<E, P>;
|
|
56
53
|
notFound(handler: NotFoundHandler): Hono<E, P>;
|
|
57
54
|
private addRoute;
|
package/dist/hono.js
CHANGED
|
@@ -101,7 +101,7 @@ class Hono extends defineDynamicClass() {
|
|
|
101
101
|
request.paramData = result?.params;
|
|
102
102
|
const handlers = result ? result.handlers : [this.notFoundHandler];
|
|
103
103
|
const c = new context_1.HonoContext(request, env, eventOrExecutionCtx, this.notFoundHandler);
|
|
104
|
-
const composed = (0, compose_1.compose)(handlers, this.
|
|
104
|
+
const composed = (0, compose_1.compose)(handlers, this.notFoundHandler);
|
|
105
105
|
let context;
|
|
106
106
|
try {
|
|
107
107
|
context = await composed(c);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { ServeStaticOptions } from './serve-static';
|
|
2
|
-
declare const module: (options?: ServeStaticOptions) => import("../../
|
|
2
|
+
declare const module: (options?: ServeStaticOptions) => (c: import("../../context").Context<string, any>, next: import("../../hono").Next) => Promise<Response | undefined>;
|
|
3
3
|
export { module as serveStatic };
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/// <reference types="@cloudflare/workers-types" />
|
|
2
|
-
import type {
|
|
2
|
+
import type { Context } from '../../context';
|
|
3
|
+
import type { Next } from '../../hono';
|
|
3
4
|
export declare type ServeStaticOptions = {
|
|
4
5
|
root?: string;
|
|
5
6
|
path?: string;
|
|
6
7
|
manifest?: object | string;
|
|
7
8
|
namespace?: KVNamespace;
|
|
8
9
|
};
|
|
9
|
-
export declare const serveStatic: (options?: ServeStaticOptions) =>
|
|
10
|
+
export declare const serveStatic: (options?: ServeStaticOptions) => (c: Context, next: Next) => Promise<Response | undefined>;
|