Comparing version 2.0.8 to 2.0.9
import type { ErrorHandler, NotFoundHandler } from './hono'; | ||
export declare const compose: <C>(middleware: Function[], onError?: ErrorHandler<{ | ||
[x: string]: any; | ||
}> | undefined, onNotFound?: NotFoundHandler<{ | ||
[x: string]: any; | ||
}> | undefined) => (context: C, next?: Function | undefined) => Promise<C>; | ||
export declare const compose: <C>(middleware: Function[], onError?: ErrorHandler, onNotFound?: NotFoundHandler) => (context: C, next?: Function) => Promise<C>; |
@@ -13,3 +13,3 @@ "use strict"; | ||
if (i <= index) { | ||
return Promise.reject(new Error('next() called multiple times')); | ||
throw new Error('next() called multiple times'); | ||
} | ||
@@ -24,23 +24,25 @@ let handler = middleware[i]; | ||
} | ||
return Promise.resolve(context); | ||
return context; | ||
} | ||
return Promise.resolve(handler(context, () => dispatch(i + 1))) | ||
.then((res) => { | ||
// If handler return Response like `return c.text('foo')` | ||
if (res && context instanceof context_1.HonoContext) { | ||
context.res = res; | ||
} | ||
return context; | ||
}) | ||
.catch((err) => { | ||
let res; | ||
let isError = false; | ||
try { | ||
const tmp = handler(context, () => dispatch(i + 1)); | ||
res = tmp instanceof Promise ? await tmp : tmp; | ||
} | ||
catch (err) { | ||
if (context instanceof context_1.HonoContext && onError) { | ||
if (err instanceof Error) { | ||
context.res = onError(err, context); | ||
isError = true; | ||
res = onError(err, context); | ||
} | ||
return context; | ||
} | ||
else { | ||
if (!res) { | ||
throw err; | ||
} | ||
}); | ||
} | ||
if (res && context instanceof context_1.HonoContext && (!context.finalized || isError)) { | ||
context.res = res; | ||
} | ||
return context; | ||
} | ||
@@ -47,0 +49,0 @@ }; |
@@ -55,4 +55,6 @@ /// <reference types="@cloudflare/workers-types" /> | ||
status(status: StatusCode): void; | ||
set<Key extends keyof ContextVariableMap>(key: Key, value: ContextVariableMap[Key]): void; | ||
set(key: string, value: any): void; | ||
get(key: string): any; | ||
get<Key extends keyof ContextVariableMap>(key: Key): ContextVariableMap[Key]; | ||
get<T = any>(key: string): T; | ||
pretty(prettyJSON: boolean, space?: number): void; | ||
@@ -59,0 +61,0 @@ newResponse(data: Data | null, status: StatusCode, headers?: Headers): Response; |
@@ -53,5 +53,5 @@ /// <reference types="@cloudflare/workers-types" /> | ||
handleEvent(event: FetchEvent): Promise<Response>; | ||
fetch: (request: Request, env?: E | undefined, executionCtx?: ExecutionContext | undefined) => Promise<Response>; | ||
fetch: (request: Request, env?: E, executionCtx?: ExecutionContext) => Promise<Response>; | ||
request(input: RequestInfo, requestInit?: RequestInit): Promise<Response>; | ||
} | ||
export {}; |
@@ -7,3 +7,3 @@ import type { Context } from '../../context'; | ||
} | ||
export declare const compress: (options?: CompressionOptions | undefined) => (ctx: Context, next: Next) => Promise<void>; | ||
export declare const compress: (options?: CompressionOptions) => (ctx: Context, next: Next) => Promise<void>; | ||
export {}; |
@@ -11,3 +11,3 @@ import type { Context } from '../../context'; | ||
}; | ||
export declare const cors: (options?: CORSOptions | undefined) => (c: Context, next: Next) => Promise<void>; | ||
export declare const cors: (options?: CORSOptions) => (c: Context, next: Next) => Promise<void>; | ||
export {}; |
export declare const equal: (a: ArrayBuffer, b: ArrayBuffer) => boolean; | ||
export declare const timingSafeEqual: (a: string | object | boolean, b: string | object | boolean, hashFunction?: Function | undefined) => Promise<boolean>; | ||
export declare const timingSafeEqual: (a: string | object | boolean, b: string | object | boolean, hashFunction?: Function) => Promise<boolean>; | ||
export declare const bufferToString: (buffer: ArrayBuffer) => string; |
@@ -6,2 +6,2 @@ /// <reference types="@cloudflare/workers-types" /> | ||
}; | ||
export declare const getContentFromKVAsset: (path: string, options?: KVAssetOptions | undefined) => Promise<ArrayBuffer | null>; | ||
export declare const getContentFromKVAsset: (path: string, options?: KVAssetOptions) => Promise<ArrayBuffer | null>; |
{ | ||
"name": "hono", | ||
"version": "2.0.8", | ||
"version": "2.0.9", | ||
"description": "Ultrafast web framework for Cloudflare Workers.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -49,9 +49,9 @@ <div align="center"> | ||
```plain | ||
hono - trie-router(default) x 389,510 ops/sec ±3.16% (85 runs sampled) | ||
hono - regexp-router x 452,290 ops/sec ±2.64% (84 runs sampled) | ||
itty-router x 206,013 ops/sec ±3.39% (90 runs sampled) | ||
sunder x 323,131 ops/sec ±0.75% (97 runs sampled) | ||
worktop x 191,218 ops/sec ±2.70% (91 runs sampled) | ||
hono - trie-router(default) x 424,449 ops/sec ±4.98% (77 runs sampled) | ||
hono - regexp-router x 516,228 ops/sec ±4.79% (81 runs sampled) | ||
itty-router x 206,641 ops/sec ±3.59% (87 runs sampled) | ||
sunder x 319,500 ops/sec ±1.33% (93 runs sampled) | ||
worktop x 187,280 ops/sec ±3.09% (87 runs sampled) | ||
Fastest is hono - regexp-router | ||
✨ Done in 43.56s. | ||
✨ Done in 38.32s. | ||
``` | ||
@@ -58,0 +58,0 @@ |
118457