hono 3.11.6 → 3.11.7
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/cjs/router/trie-router/node.js +5 -7
- package/dist/router/trie-router/node.js +5 -7
- package/dist/types/adapter/aws-lambda/custom-context.d.ts +1 -1
- package/dist/types/adapter/aws-lambda/handler.d.ts +2 -2
- package/dist/types/adapter/aws-lambda/types.d.ts +2 -2
- package/dist/types/adapter/bun/serve-static.d.ts +1 -1
- package/dist/types/adapter/cloudflare-pages/handler.d.ts +2 -2
- package/dist/types/adapter/cloudflare-workers/serve-static.d.ts +1 -1
- package/dist/types/adapter/cloudflare-workers/server-static-module.d.ts +1 -1
- package/dist/types/adapter/deno/serve-static.d.ts +1 -1
- package/dist/types/adapter/lambda-edge/handler.d.ts +1 -1
- package/dist/types/adapter/netlify/handler.d.ts +1 -1
- package/dist/types/client/types.d.ts +12 -12
- package/dist/types/context.d.ts +4 -4
- package/dist/types/helper/adapter/index.d.ts +1 -1
- package/dist/types/helper/testing/index.d.ts +1 -1
- package/dist/types/hono-base.d.ts +2 -2
- package/dist/types/http-exception.d.ts +1 -1
- package/dist/types/jsx/components.d.ts +2 -2
- package/dist/types/jsx/index.d.ts +3 -3
- package/dist/types/middleware/cors/index.d.ts +1 -1
- package/dist/types/middleware/etag/index.d.ts +1 -1
- package/dist/types/middleware/jsx-renderer/index.d.ts +2 -2
- package/dist/types/middleware/logger/index.d.ts +1 -1
- package/dist/types/middleware/pretty-json/index.d.ts +1 -1
- package/dist/types/middleware/secure-headers/index.d.ts +1 -1
- package/dist/types/request.d.ts +2 -2
- package/dist/types/router/reg-exp-router/node.d.ts +1 -1
- package/dist/types/router/reg-exp-router/router.d.ts +1 -1
- package/dist/types/router/reg-exp-router/trie.d.ts +1 -1
- package/dist/types/router/trie-router/node.d.ts +1 -2
- package/dist/types/router.d.ts +4 -4
- package/dist/types/types.d.ts +30 -30
- package/dist/types/utils/body.d.ts +2 -2
- package/dist/types/utils/cloudflare.d.ts +1 -1
- package/dist/types/utils/cookie.d.ts +3 -3
- package/dist/types/utils/crypto.d.ts +2 -2
- package/dist/types/utils/filepath.d.ts +1 -1
- package/dist/types/utils/html.d.ts +5 -5
- package/dist/types/utils/http-status.d.ts +1 -1
- package/dist/types/utils/jwt/jwt.d.ts +1 -1
- package/dist/types/utils/types.d.ts +15 -15
- package/dist/types/utils/url.d.ts +1 -1
- package/dist/types/validator/validator.d.ts +3 -3
- package/package.json +7 -16
|
@@ -32,7 +32,7 @@ class Node {
|
|
|
32
32
|
this.name = "";
|
|
33
33
|
if (method && handler) {
|
|
34
34
|
const m = {};
|
|
35
|
-
m[method] = { handler,
|
|
35
|
+
m[method] = { handler, possibleKeys: [], score: 0, name: this.name };
|
|
36
36
|
this.methods = [m];
|
|
37
37
|
}
|
|
38
38
|
this.patterns = [];
|
|
@@ -70,7 +70,6 @@ class Node {
|
|
|
70
70
|
const m = {};
|
|
71
71
|
const handlerSet = {
|
|
72
72
|
handler,
|
|
73
|
-
params: {},
|
|
74
73
|
possibleKeys,
|
|
75
74
|
name: this.name,
|
|
76
75
|
score: this.order
|
|
@@ -85,6 +84,7 @@ class Node {
|
|
|
85
84
|
const m = node.methods[i];
|
|
86
85
|
const handlerSet = m[method] || m[import_router.METHOD_NAME_ALL];
|
|
87
86
|
if (handlerSet !== void 0) {
|
|
87
|
+
handlerSet.params = {};
|
|
88
88
|
handlerSet.possibleKeys.map((key) => {
|
|
89
89
|
handlerSet.params[key] = params[key];
|
|
90
90
|
});
|
|
@@ -110,11 +110,9 @@ class Node {
|
|
|
110
110
|
if (nextNode) {
|
|
111
111
|
if (isLast === true) {
|
|
112
112
|
if (nextNode.children["*"]) {
|
|
113
|
-
handlerSets.push(
|
|
114
|
-
...this.gHSets(nextNode.children["*"], method, { ...params, ...node.params })
|
|
115
|
-
);
|
|
113
|
+
handlerSets.push(...this.gHSets(nextNode.children["*"], method, node.params));
|
|
116
114
|
}
|
|
117
|
-
handlerSets.push(...this.gHSets(nextNode, method,
|
|
115
|
+
handlerSets.push(...this.gHSets(nextNode, method, node.params));
|
|
118
116
|
} else {
|
|
119
117
|
tempNodes.push(nextNode);
|
|
120
118
|
}
|
|
@@ -124,7 +122,7 @@ class Node {
|
|
|
124
122
|
if (pattern === "*") {
|
|
125
123
|
const astNode = node.children["*"];
|
|
126
124
|
if (astNode) {
|
|
127
|
-
handlerSets.push(...this.gHSets(astNode, method,
|
|
125
|
+
handlerSets.push(...this.gHSets(astNode, method, node.params));
|
|
128
126
|
tempNodes.push(astNode);
|
|
129
127
|
}
|
|
130
128
|
continue;
|
|
@@ -10,7 +10,7 @@ var Node = class {
|
|
|
10
10
|
this.name = "";
|
|
11
11
|
if (method && handler) {
|
|
12
12
|
const m = {};
|
|
13
|
-
m[method] = { handler,
|
|
13
|
+
m[method] = { handler, possibleKeys: [], score: 0, name: this.name };
|
|
14
14
|
this.methods = [m];
|
|
15
15
|
}
|
|
16
16
|
this.patterns = [];
|
|
@@ -48,7 +48,6 @@ var Node = class {
|
|
|
48
48
|
const m = {};
|
|
49
49
|
const handlerSet = {
|
|
50
50
|
handler,
|
|
51
|
-
params: {},
|
|
52
51
|
possibleKeys,
|
|
53
52
|
name: this.name,
|
|
54
53
|
score: this.order
|
|
@@ -63,6 +62,7 @@ var Node = class {
|
|
|
63
62
|
const m = node.methods[i];
|
|
64
63
|
const handlerSet = m[method] || m[METHOD_NAME_ALL];
|
|
65
64
|
if (handlerSet !== void 0) {
|
|
65
|
+
handlerSet.params = {};
|
|
66
66
|
handlerSet.possibleKeys.map((key) => {
|
|
67
67
|
handlerSet.params[key] = params[key];
|
|
68
68
|
});
|
|
@@ -88,11 +88,9 @@ var Node = class {
|
|
|
88
88
|
if (nextNode) {
|
|
89
89
|
if (isLast === true) {
|
|
90
90
|
if (nextNode.children["*"]) {
|
|
91
|
-
handlerSets.push(
|
|
92
|
-
...this.gHSets(nextNode.children["*"], method, { ...params, ...node.params })
|
|
93
|
-
);
|
|
91
|
+
handlerSets.push(...this.gHSets(nextNode.children["*"], method, node.params));
|
|
94
92
|
}
|
|
95
|
-
handlerSets.push(...this.gHSets(nextNode, method,
|
|
93
|
+
handlerSets.push(...this.gHSets(nextNode, method, node.params));
|
|
96
94
|
} else {
|
|
97
95
|
tempNodes.push(nextNode);
|
|
98
96
|
}
|
|
@@ -102,7 +100,7 @@ var Node = class {
|
|
|
102
100
|
if (pattern === "*") {
|
|
103
101
|
const astNode = node.children["*"];
|
|
104
102
|
if (astNode) {
|
|
105
|
-
handlerSets.push(...this.gHSets(astNode, method,
|
|
103
|
+
handlerSets.push(...this.gHSets(astNode, method, node.params));
|
|
106
104
|
tempNodes.push(astNode);
|
|
107
105
|
}
|
|
108
106
|
continue;
|
|
@@ -83,5 +83,5 @@ export interface ALBRequestContext {
|
|
|
83
83
|
/**
|
|
84
84
|
* @deprecated Use ApiGatewayRequestContextV2 instead.
|
|
85
85
|
*/
|
|
86
|
-
export
|
|
86
|
+
export type LambdaFunctionUrlRequestContext = ApiGatewayRequestContextV2;
|
|
87
87
|
export {};
|
|
@@ -2,7 +2,7 @@ import type { Hono } from '../../hono';
|
|
|
2
2
|
import type { Env, Schema } from '../../types';
|
|
3
3
|
import type { ApiGatewayRequestContext, ApiGatewayRequestContextV2, ALBRequestContext } from './custom-context';
|
|
4
4
|
import type { LambdaContext } from './types';
|
|
5
|
-
export
|
|
5
|
+
export type LambdaEvent = APIGatewayProxyEvent | APIGatewayProxyEventV2 | ALBProxyEvent;
|
|
6
6
|
export interface APIGatewayProxyEventV2 {
|
|
7
7
|
version: string;
|
|
8
8
|
routeKey: string;
|
|
@@ -62,7 +62,7 @@ export interface APIGatewayProxyResult {
|
|
|
62
62
|
};
|
|
63
63
|
isBase64Encoded: boolean;
|
|
64
64
|
}
|
|
65
|
-
export declare const streamHandle: <E extends Env = Env, S extends Schema = {}, BasePath extends string = "/">(app: Hono<E, S, BasePath>) => import("./types").Handler
|
|
65
|
+
export declare const streamHandle: <E extends Env = Env, S extends Schema = {}, BasePath extends string = "/">(app: Hono<E, S, BasePath>) => import("./types").Handler;
|
|
66
66
|
/**
|
|
67
67
|
* Accepts events from API Gateway/ELB(`APIGatewayProxyEvent`) and directly through Function Url(`APIGatewayProxyEventV2`)
|
|
68
68
|
*/
|
|
@@ -38,6 +38,6 @@ export interface LambdaContext {
|
|
|
38
38
|
clientContext?: ClientContext | undefined;
|
|
39
39
|
getRemainingTimeInMillis(): number;
|
|
40
40
|
}
|
|
41
|
-
|
|
42
|
-
export
|
|
41
|
+
type Callback<TResult = any> = (error?: Error | string | null, result?: TResult) => void;
|
|
42
|
+
export type Handler<TEvent = any, TResult = any> = (event: TEvent, context: LambdaContext, callback: Callback<TResult>) => void | Promise<TResult>;
|
|
43
43
|
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Hono } from '../../hono';
|
|
2
2
|
import type { Env, MiddlewareHandler } from '../../types';
|
|
3
|
-
|
|
4
|
-
export
|
|
3
|
+
type Params<P extends string = any> = Record<P, string | string[]>;
|
|
4
|
+
export type EventContext<Env = {}, P extends string = any, Data = {}> = {
|
|
5
5
|
request: Request;
|
|
6
6
|
functionPath: string;
|
|
7
7
|
waitUntil: (promise: Promise<unknown>) => void;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { ServeStaticOptions } from './serve-static';
|
|
2
|
-
declare const module: (options?: ServeStaticOptions) => import("../..").MiddlewareHandler
|
|
2
|
+
declare const module: (options?: ServeStaticOptions) => import("../..").MiddlewareHandler;
|
|
3
3
|
export { module as serveStatic };
|
|
@@ -53,7 +53,7 @@ interface CloudFrontEvent {
|
|
|
53
53
|
export interface CloudFrontEdgeEvent {
|
|
54
54
|
Records: CloudFrontEvent[];
|
|
55
55
|
}
|
|
56
|
-
|
|
56
|
+
type CloudFrontContext = {};
|
|
57
57
|
export interface Callback {
|
|
58
58
|
(err: Error | null, result?: CloudFrontRequest | CloudFrontResult): void;
|
|
59
59
|
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import type { Hono } from '../hono';
|
|
2
2
|
import type { Schema } from '../types';
|
|
3
3
|
import type { HasRequiredKeys } from '../utils/types';
|
|
4
|
-
|
|
5
|
-
export
|
|
4
|
+
type HonoRequest = typeof Hono.prototype['request'];
|
|
5
|
+
export type ClientRequestOptions<T = unknown> = keyof T extends never ? {
|
|
6
6
|
headers?: Record<string, string>;
|
|
7
7
|
fetch?: typeof fetch | HonoRequest;
|
|
8
8
|
} : {
|
|
9
9
|
headers: T;
|
|
10
10
|
fetch?: typeof fetch | HonoRequest;
|
|
11
11
|
};
|
|
12
|
-
|
|
12
|
+
type ClientRequest<S extends Schema> = {
|
|
13
13
|
[M in keyof S]: S[M] extends {
|
|
14
14
|
input: infer R;
|
|
15
15
|
output: infer O;
|
|
@@ -17,7 +17,7 @@ declare type ClientRequest<S extends Schema> = {
|
|
|
17
17
|
} & {
|
|
18
18
|
$url: () => URL;
|
|
19
19
|
};
|
|
20
|
-
|
|
20
|
+
type BlankRecordToNever<T> = T extends any ? (keyof T extends never ? never : T) : never;
|
|
21
21
|
export interface ClientResponse<T> {
|
|
22
22
|
ok: boolean;
|
|
23
23
|
status: number;
|
|
@@ -34,22 +34,22 @@ export interface ClientResponse<T> {
|
|
|
34
34
|
}
|
|
35
35
|
export interface Response extends ClientResponse<unknown> {
|
|
36
36
|
}
|
|
37
|
-
export
|
|
38
|
-
export
|
|
39
|
-
export
|
|
40
|
-
export
|
|
41
|
-
|
|
37
|
+
export type Fetch<T> = (args?: InferRequestType<T>, opt?: ClientRequestOptions) => Promise<ClientResponse<InferResponseType<T>>>;
|
|
38
|
+
export type InferResponseType<T> = T extends (args: any | undefined, options: any | undefined) => Promise<ClientResponse<infer O>> ? O : never;
|
|
39
|
+
export type InferRequestType<T> = T extends (args: infer R, options: any | undefined) => Promise<ClientResponse<unknown>> ? NonNullable<R> : never;
|
|
40
|
+
export type InferRequestOptionsType<T> = T extends (args: any, options: infer R) => Promise<ClientResponse<unknown>> ? NonNullable<R> : never;
|
|
41
|
+
type PathToChain<Path extends string, E extends Schema, Original extends string = ''> = Path extends `/${infer P}` ? PathToChain<P, E, Path> : Path extends `${infer P}/${infer R}` ? {
|
|
42
42
|
[K in P]: PathToChain<R, E, Original>;
|
|
43
43
|
} : {
|
|
44
44
|
[K in Path extends '' ? 'index' : Path]: ClientRequest<E extends Record<string, unknown> ? E[Original] : never>;
|
|
45
45
|
};
|
|
46
|
-
export
|
|
47
|
-
export
|
|
46
|
+
export type Client<T> = T extends Hono<any, infer S, any> ? S extends Record<infer K, Schema> ? K extends string ? PathToChain<K, S> : never : never : never;
|
|
47
|
+
export type Callback = (opts: CallbackOptions) => unknown;
|
|
48
48
|
interface CallbackOptions {
|
|
49
49
|
path: string[];
|
|
50
50
|
args: any[];
|
|
51
51
|
}
|
|
52
|
-
export
|
|
52
|
+
export type ObjectType<T = unknown> = {
|
|
53
53
|
[key: string]: T;
|
|
54
54
|
};
|
|
55
55
|
export {};
|
package/dist/types/context.d.ts
CHANGED
|
@@ -5,8 +5,8 @@ import type { CookieOptions } from './utils/cookie';
|
|
|
5
5
|
import type { StatusCode } from './utils/http-status';
|
|
6
6
|
import { StreamingApi } from './utils/stream';
|
|
7
7
|
import type { JSONValue, InterfaceToType, JSONParsed } from './utils/types';
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
type HeaderRecord = Record<string, string | string[]>;
|
|
9
|
+
type Data = string | ArrayBuffer | ReadableStream;
|
|
10
10
|
export interface ExecutionContext {
|
|
11
11
|
waitUntil(promise: Promise<unknown>): void;
|
|
12
12
|
passThroughOnException(): void;
|
|
@@ -18,7 +18,7 @@ export interface ContextRenderer {
|
|
|
18
18
|
interface DefaultRenderer {
|
|
19
19
|
(content: string | Promise<string>): Response | Promise<Response>;
|
|
20
20
|
}
|
|
21
|
-
export
|
|
21
|
+
export type Renderer = ContextRenderer extends Function ? ContextRenderer : DefaultRenderer;
|
|
22
22
|
interface Get<E extends Env> {
|
|
23
23
|
<Key extends keyof ContextVariableMap>(key: Key): ContextVariableMap[Key];
|
|
24
24
|
<Key extends keyof E['Variables']>(key: Key): E['Variables'][Key];
|
|
@@ -45,7 +45,7 @@ interface HTMLRespond {
|
|
|
45
45
|
(html: string | Promise<string>, status?: StatusCode, headers?: HeaderRecord): Response | Promise<Response>;
|
|
46
46
|
(html: string | Promise<string>, init?: ResponseInit): Response | Promise<Response>;
|
|
47
47
|
}
|
|
48
|
-
|
|
48
|
+
type ContextOptions<E extends Env> = {
|
|
49
49
|
env: E['Bindings'];
|
|
50
50
|
executionCtx?: FetchEventLike | ExecutionContext | undefined;
|
|
51
51
|
notFoundHandler?: NotFoundHandler<E>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { Context } from '../../context';
|
|
2
|
-
export
|
|
2
|
+
export type Runtime = 'node' | 'deno' | 'bun' | 'workerd' | 'fastly' | 'edge-light' | 'lagon' | 'other';
|
|
3
3
|
export declare const env: <T extends Record<string, unknown>, C extends Context<any, any, {}> = Context<{}, any, {}>>(c: C, runtime?: Runtime) => T & C["env"];
|
|
4
4
|
export declare const getRuntimeKey: () => "other" | "node" | "deno" | "bun" | "workerd" | "fastly" | "edge-light" | "lagon";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { Hono } from '../../hono';
|
|
2
|
-
|
|
2
|
+
type ExtractEnv<T> = T extends Hono<infer E, any, any> ? E : never;
|
|
3
3
|
export declare const testClient: <T extends Hono<any, any, any>>(app: T, Env?: {} | ExtractEnv<T>["Bindings"] | undefined, executionCtx?: any) => import("../../utils/types").UnionToIntersection<import("../../client/types").Client<T>>;
|
|
4
4
|
export {};
|
|
@@ -2,10 +2,10 @@ import { Context } from './context';
|
|
|
2
2
|
import type { ExecutionContext } from './context';
|
|
3
3
|
import type { Router } from './router';
|
|
4
4
|
import type { Env, ErrorHandler, H, HandlerInterface, MiddlewareHandlerInterface, NotFoundHandler, OnHandlerInterface, MergePath, MergeSchemaPath, FetchEventLike, Schema, RouterRoute } from './types';
|
|
5
|
-
|
|
5
|
+
type GetPath<E extends Env> = (request: Request, options?: {
|
|
6
6
|
env?: E['Bindings'];
|
|
7
7
|
}) => string;
|
|
8
|
-
export
|
|
8
|
+
export type HonoOptions<E extends Env> = {
|
|
9
9
|
strict?: boolean;
|
|
10
10
|
router?: Router<[H, RouterRoute]>;
|
|
11
11
|
getPath?: GetPath<E>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { HtmlEscapedString } from '../utils/html';
|
|
2
2
|
import type { FC, Child } from './index';
|
|
3
3
|
export declare const childrenToString: (children: Child[]) => Promise<HtmlEscapedString[]>;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
type ErrorHandler = (error: Error) => void;
|
|
5
|
+
type FallbackRender = (error: Error) => Child;
|
|
6
6
|
/**
|
|
7
7
|
* @experimental
|
|
8
8
|
* `ErrorBoundary` is an experimental feature.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { StringBuffer, HtmlEscaped, HtmlEscapedString } from '../utils/html';
|
|
2
2
|
import type { IntrinsicElements as IntrinsicElementsDefined } from './intrinsic-elements';
|
|
3
3
|
export { ErrorBoundary } from './components';
|
|
4
|
-
|
|
4
|
+
type Props = Record<string, any>;
|
|
5
5
|
declare global {
|
|
6
6
|
namespace JSX {
|
|
7
7
|
type Element = HtmlEscapedString | Promise<HtmlEscapedString>;
|
|
@@ -13,7 +13,7 @@ declare global {
|
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
|
-
export
|
|
16
|
+
export type Child = string | Promise<string> | number | JSXNode | Child[];
|
|
17
17
|
export declare class JSXNode implements HtmlEscaped {
|
|
18
18
|
tag: string | Function;
|
|
19
19
|
props: Props;
|
|
@@ -25,7 +25,7 @@ export declare class JSXNode implements HtmlEscaped {
|
|
|
25
25
|
}
|
|
26
26
|
export { jsxFn as jsx };
|
|
27
27
|
declare const jsxFn: (tag: string | Function, props: Props, ...children: (string | HtmlEscapedString)[]) => JSXNode;
|
|
28
|
-
export
|
|
28
|
+
export type FC<T = Props> = (props: T & {
|
|
29
29
|
children?: Child;
|
|
30
30
|
}) => HtmlEscapedString | Promise<HtmlEscapedString>;
|
|
31
31
|
export declare const memo: <T>(component: FC<T>, propsAreEqual?: (prevProps: Readonly<T>, nextProps: Readonly<T>) => boolean) => FC<T>;
|
|
@@ -2,8 +2,8 @@ import type { Context, Renderer } from '../../context';
|
|
|
2
2
|
import type { FC } from '../../jsx';
|
|
3
3
|
import type { Env, Input, MiddlewareHandler } from '../../types';
|
|
4
4
|
export declare const RequestContext: import("../../jsx").Context<Context<any, any, {}> | null>;
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
type PropsForRenderer = [...Required<Parameters<Renderer>>] extends [unknown, infer Props] ? Props : unknown;
|
|
6
|
+
type RendererOptions = {
|
|
7
7
|
docType?: boolean | string;
|
|
8
8
|
stream?: boolean | Record<string, string>;
|
|
9
9
|
};
|
|
@@ -35,7 +35,7 @@ interface ReportingEndpointOptions {
|
|
|
35
35
|
name: string;
|
|
36
36
|
url: string;
|
|
37
37
|
}
|
|
38
|
-
|
|
38
|
+
type overridableHeader = boolean | string;
|
|
39
39
|
interface SecureHeadersOptions {
|
|
40
40
|
contentSecurityPolicy?: ContentSecurityPolicyOptions;
|
|
41
41
|
crossOriginEmbedderPolicy?: overridableHeader;
|
package/dist/types/request.d.ts
CHANGED
|
@@ -3,14 +3,14 @@ import type { Input, InputToDataByTarget, ParamKeys, ParamKeyToRecord, RemoveQue
|
|
|
3
3
|
import type { BodyData, ParseBodyOptions } from './utils/body';
|
|
4
4
|
import type { Cookie } from './utils/cookie';
|
|
5
5
|
import type { UnionToIntersection } from './utils/types';
|
|
6
|
-
|
|
6
|
+
type Body = {
|
|
7
7
|
json: any;
|
|
8
8
|
text: string;
|
|
9
9
|
arrayBuffer: ArrayBuffer;
|
|
10
10
|
blob: Blob;
|
|
11
11
|
formData: FormData;
|
|
12
12
|
};
|
|
13
|
-
|
|
13
|
+
type BodyCache = Partial<Body & {
|
|
14
14
|
parsedBody: BodyData;
|
|
15
15
|
}>;
|
|
16
16
|
export declare class HonoRequest<P extends string = '/', I extends Input['out'] = {}> {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Router, Result } from '../../router';
|
|
2
|
-
|
|
2
|
+
type HandlerWithMetadata<T> = [T, number];
|
|
3
3
|
export declare class RegExpRouter<T> implements Router<T> {
|
|
4
4
|
name: string;
|
|
5
5
|
middleware?: Record<string, Record<string, HandlerWithMetadata<T>[]>>;
|
package/dist/types/router.d.ts
CHANGED
|
@@ -7,9 +7,9 @@ export interface Router<T> {
|
|
|
7
7
|
add(method: string, path: string, handler: T): void;
|
|
8
8
|
match(method: string, path: string): Result<T>;
|
|
9
9
|
}
|
|
10
|
-
export
|
|
11
|
-
export
|
|
12
|
-
export
|
|
13
|
-
export
|
|
10
|
+
export type ParamIndexMap = Record<string, number>;
|
|
11
|
+
export type ParamStash = string[];
|
|
12
|
+
export type Params = Record<string, string>;
|
|
13
|
+
export type Result<T> = [[T, ParamIndexMap][], ParamStash] | [[T, Params][]];
|
|
14
14
|
export declare class UnsupportedPathError extends Error {
|
|
15
15
|
}
|
package/dist/types/types.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import type { Context } from './context';
|
|
2
2
|
import type { Hono } from './hono';
|
|
3
3
|
import type { IntersectNonAnyTypes, UnionToIntersection } from './utils/types';
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
4
|
+
export type Bindings = Record<string, unknown>;
|
|
5
|
+
export type Variables = Record<string, unknown>;
|
|
6
|
+
export type Env = {
|
|
7
7
|
Bindings?: Bindings;
|
|
8
8
|
Variables?: Variables;
|
|
9
9
|
};
|
|
10
|
-
export
|
|
11
|
-
export
|
|
10
|
+
export type Next = () => Promise<void>;
|
|
11
|
+
export type Input = {
|
|
12
12
|
in?: Partial<ValidationTargets>;
|
|
13
13
|
out?: Partial<{
|
|
14
14
|
[K in keyof ValidationTargets]: unknown;
|
|
@@ -19,12 +19,12 @@ export interface RouterRoute {
|
|
|
19
19
|
method: string;
|
|
20
20
|
handler: H;
|
|
21
21
|
}
|
|
22
|
-
export
|
|
23
|
-
export
|
|
24
|
-
export
|
|
25
|
-
export
|
|
26
|
-
export
|
|
27
|
-
export
|
|
22
|
+
export type HandlerResponse<O> = Response | TypedResponse<O> | Promise<Response | TypedResponse<O>>;
|
|
23
|
+
export type Handler<E extends Env = any, P extends string = any, I extends Input = Input, R extends HandlerResponse<any> = any> = (c: Context<E, P, I>, next: Next) => R;
|
|
24
|
+
export type MiddlewareHandler<E extends Env = any, P extends string = string, I extends Input = {}> = (c: Context<E, P, I>, next: Next) => Promise<Response | void>;
|
|
25
|
+
export type H<E extends Env = any, P extends string = any, I extends Input = {}, R extends HandlerResponse<any> = any> = Handler<E, P, I, R> | MiddlewareHandler<E, P, I>;
|
|
26
|
+
export type NotFoundHandler<E extends Env = any> = (c: Context<E>) => Response | Promise<Response>;
|
|
27
|
+
export type ErrorHandler<E extends Env = any> = (err: Error, c: Context<E>) => Response | Promise<Response>;
|
|
28
28
|
export interface HandlerInterface<E extends Env = Env, M extends string = string, S extends Schema = {}, BasePath extends string = '/'> {
|
|
29
29
|
<P extends string = ExtractKey<S> extends never ? BasePath : ExtractKey<S>, I extends Input = {}, R extends HandlerResponse<any> = any, E2 extends Env = E>(handler: H<E2, P, I, R>): Hono<IntersectNonAnyTypes<[E, E2]>, S & ToSchema<M, P, I['in'], MergeTypedResponseData<R>>, BasePath>;
|
|
30
30
|
<P extends string = ExtractKey<S> extends never ? BasePath : ExtractKey<S>, I extends Input = {}, I2 extends Input = I, R extends HandlerResponse<any> = any, E2 extends Env = E, E3 extends Env = IntersectNonAnyTypes<[E, E2]>>(...handlers: [H<E2, P, I>, H<E3, P, I2, R>]): Hono<IntersectNonAnyTypes<[E, E2, E3]>, S & ToSchema<M, P, I2['in'], MergeTypedResponseData<R>>, BasePath>;
|
|
@@ -291,8 +291,8 @@ export interface OnHandlerInterface<E extends Env = Env, S extends Schema = {},
|
|
|
291
291
|
]): Hono<IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9, E10, E11]>, S & ToSchema<Ms[number], MergedPath, I10['in'], MergeTypedResponseData<HandlerResponse<any>>>, BasePath>;
|
|
292
292
|
<P extends string, R extends HandlerResponse<any> = any, I extends Input = {}>(methods: string[], path: P, ...handlers: H<E, MergePath<BasePath, P>, I, R>[]): Hono<E, S & ToSchema<string, MergePath<BasePath, P>, I['in'], MergeTypedResponseData<R>>, BasePath>;
|
|
293
293
|
}
|
|
294
|
-
|
|
295
|
-
export
|
|
294
|
+
type ExtractKey<S> = S extends Record<infer Key, unknown> ? Key extends string ? Key : never : string;
|
|
295
|
+
export type ToSchema<M extends string, P extends string, I extends Input['in'], O> = {
|
|
296
296
|
[K in P]: {
|
|
297
297
|
[K2 in M as AddDollar<K2>]: {
|
|
298
298
|
input: unknown extends I ? AddParam<{}, P> : AddParam<I, P>;
|
|
@@ -300,7 +300,7 @@ export declare type ToSchema<M extends string, P extends string, I extends Input
|
|
|
300
300
|
};
|
|
301
301
|
};
|
|
302
302
|
};
|
|
303
|
-
export
|
|
303
|
+
export type Schema = {
|
|
304
304
|
[Path: string]: {
|
|
305
305
|
[Method: `$${Lowercase<string>}`]: {
|
|
306
306
|
input: Partial<ValidationTargets> & {
|
|
@@ -310,21 +310,21 @@ export declare type Schema = {
|
|
|
310
310
|
};
|
|
311
311
|
};
|
|
312
312
|
};
|
|
313
|
-
export
|
|
313
|
+
export type MergeSchemaPath<OrigSchema, SubPath extends string> = {
|
|
314
314
|
[K in keyof OrigSchema as `${MergePath<SubPath, K & string>}`]: OrigSchema[K];
|
|
315
315
|
};
|
|
316
|
-
export
|
|
316
|
+
export type AddParam<I, P extends string> = ParamKeys<P> extends never ? I : I & {
|
|
317
317
|
param: UnionToIntersection<ParamKeyToRecord<ParamKeys<P>>>;
|
|
318
318
|
};
|
|
319
|
-
|
|
320
|
-
export
|
|
321
|
-
export
|
|
319
|
+
type AddDollar<T extends string> = `$${Lowercase<T>}`;
|
|
320
|
+
export type MergePath<A extends string, B extends string> = A extends '' ? B : A extends '/' ? B : A extends `${infer P}/` ? B extends `/${infer Q}` ? `${P}/${Q}` : `${P}/${B}` : B extends `/${infer Q}` ? Q extends '' ? A : `${A}/${Q}` : `${A}/${B}`;
|
|
321
|
+
export type TypedResponse<T = unknown> = {
|
|
322
322
|
data: T;
|
|
323
323
|
format: 'json';
|
|
324
324
|
};
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
export
|
|
325
|
+
type ExtractResponseData<T> = T extends Promise<infer T2> ? T2 extends TypedResponse<infer U> ? U : {} : T extends TypedResponse<infer U> ? U : {};
|
|
326
|
+
type MergeTypedResponseData<T> = ExtractResponseData<T>;
|
|
327
|
+
export type ValidationTargets = {
|
|
328
328
|
json: any;
|
|
329
329
|
form: Record<string, string | File>;
|
|
330
330
|
query: Record<string, string | string[]>;
|
|
@@ -333,18 +333,18 @@ export declare type ValidationTargets = {
|
|
|
333
333
|
header: Record<string, string>;
|
|
334
334
|
cookie: Record<string, string>;
|
|
335
335
|
};
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
export
|
|
339
|
-
export
|
|
336
|
+
type ParamKeyName<NameWithPattern> = NameWithPattern extends `${infer Name}{${infer Rest}` ? Rest extends `${infer _Pattern}?` ? `${Name}?` : Name : NameWithPattern;
|
|
337
|
+
type ParamKey<Component> = Component extends `:${infer NameWithPattern}` ? ParamKeyName<NameWithPattern> : never;
|
|
338
|
+
export type ParamKeys<Path> = Path extends `${infer Component}/${infer Rest}` ? ParamKey<Component> | ParamKeys<Rest> : ParamKey<Path>;
|
|
339
|
+
export type ParamKeyToRecord<T extends string> = T extends `${infer R}?` ? Record<R, string | undefined> : {
|
|
340
340
|
[K in T]: string;
|
|
341
341
|
};
|
|
342
|
-
export
|
|
342
|
+
export type InputToDataByTarget<T extends Input['out'], Target extends keyof ValidationTargets> = T extends {
|
|
343
343
|
[K in Target]: infer R;
|
|
344
344
|
} ? R : never;
|
|
345
|
-
export
|
|
346
|
-
export
|
|
347
|
-
export
|
|
345
|
+
export type RemoveQuestion<T> = T extends `${infer R}?` ? R : T;
|
|
346
|
+
export type UndefinedIfHavingQuestion<T> = T extends `${infer _}?` ? string | undefined : string;
|
|
347
|
+
export type ExtractSchema<T> = UnionToIntersection<T extends Hono<infer _, infer S, any> ? S : never>;
|
|
348
348
|
export declare abstract class FetchEventLike {
|
|
349
349
|
abstract readonly request: Request;
|
|
350
350
|
abstract respondWith(promise: Response | Promise<Response>): void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { HonoRequest } from '../request';
|
|
2
|
-
export
|
|
3
|
-
export
|
|
2
|
+
export type BodyData = Record<string, string | File | (string | File)[]>;
|
|
3
|
+
export type ParseBodyOptions = {
|
|
4
4
|
/**
|
|
5
5
|
* Parse all fields with multiple values should be parsed as an array.
|
|
6
6
|
* @default false
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
1
|
+
export type Cookie = Record<string, string>;
|
|
2
|
+
export type SignedCookie = Record<string, string | false>;
|
|
3
|
+
export type CookieOptions = {
|
|
4
4
|
domain?: string;
|
|
5
5
|
expires?: Date;
|
|
6
6
|
httpOnly?: boolean;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
type Algorithm = {
|
|
2
2
|
name: string;
|
|
3
3
|
alias: string;
|
|
4
4
|
};
|
|
5
|
-
|
|
5
|
+
type Data = string | boolean | number | object | ArrayBufferView | ArrayBuffer | ReadableStream;
|
|
6
6
|
export declare const sha256: (data: Data) => Promise<string | null>;
|
|
7
7
|
export declare const sha1: (data: Data) => Promise<string | null>;
|
|
8
8
|
export declare const md5: (data: Data) => Promise<string | null>;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
type HtmlEscapedCallbackOpts = {
|
|
2
2
|
error?: Error;
|
|
3
3
|
buffer?: [string];
|
|
4
4
|
};
|
|
5
|
-
export
|
|
6
|
-
export
|
|
5
|
+
export type HtmlEscapedCallback = (opts: HtmlEscapedCallbackOpts) => Promise<string>;
|
|
6
|
+
export type HtmlEscaped = {
|
|
7
7
|
isEscaped: true;
|
|
8
8
|
callbacks?: HtmlEscapedCallback[];
|
|
9
9
|
};
|
|
10
|
-
export
|
|
11
|
-
export
|
|
10
|
+
export type HtmlEscapedString = string & HtmlEscaped;
|
|
11
|
+
export type StringBuffer = (string | Promise<string>)[];
|
|
12
12
|
export declare const stringBufferToString: (buffer: StringBuffer) => Promise<HtmlEscapedString>;
|
|
13
13
|
export declare const escapeToBuffer: (str: string, buffer: StringBuffer) => void;
|
|
14
14
|
export declare const resolveStream: (str: string | HtmlEscapedString, buffer?: [string]) => Promise<string>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type StatusCode = number;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AlgorithmTypes } from './types';
|
|
2
|
-
|
|
2
|
+
type AlgorithmTypeName = keyof typeof AlgorithmTypes;
|
|
3
3
|
export declare const sign: (payload: unknown, secret: string, alg?: AlgorithmTypeName) => Promise<string>;
|
|
4
4
|
export declare const verify: (token: string, secret: string, alg?: AlgorithmTypeName) => Promise<any>;
|
|
5
5
|
export declare const decode: (token: string) => {
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export
|
|
9
|
-
export
|
|
10
|
-
export
|
|
1
|
+
export type Expect<T extends true> = T;
|
|
2
|
+
export type Equal<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? true : false;
|
|
3
|
+
export type NotEqual<X, Y> = true extends Equal<X, Y> ? false : true;
|
|
4
|
+
export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
5
|
+
export type RemoveBlankRecord<T> = T extends Record<infer K, unknown> ? K extends string ? T : never : never;
|
|
6
|
+
export type IfAnyThenEmptyObject<T> = 0 extends 1 & T ? {} : T;
|
|
7
|
+
export type IntersectNonAnyTypes<T extends any[]> = T extends [infer Head, ...infer Rest] ? IfAnyThenEmptyObject<Head> & IntersectNonAnyTypes<Rest> : {};
|
|
8
|
+
export type JSONPrimitive = string | boolean | number | null | undefined;
|
|
9
|
+
export type JSONArray = (JSONPrimitive | JSONObject | JSONArray)[];
|
|
10
|
+
export type JSONObject = {
|
|
11
11
|
[key: string]: JSONPrimitive | JSONArray | JSONObject | object;
|
|
12
12
|
};
|
|
13
|
-
export
|
|
14
|
-
export
|
|
13
|
+
export type JSONValue = JSONObject | JSONArray | JSONPrimitive;
|
|
14
|
+
export type JSONParsed<T> = {
|
|
15
15
|
[k in keyof T]: T[k] extends JSONValue ? T[k] : string;
|
|
16
16
|
};
|
|
17
|
-
export
|
|
17
|
+
export type InterfaceToType<T> = T extends Function ? T : {
|
|
18
18
|
[K in keyof T]: InterfaceToType<T[K]>;
|
|
19
19
|
};
|
|
20
|
-
export
|
|
20
|
+
export type RequiredKeysOf<BaseType extends object> = Exclude<{
|
|
21
21
|
[Key in keyof BaseType]: BaseType extends Record<Key, BaseType[Key]> ? Key : never;
|
|
22
22
|
}[keyof BaseType], undefined>;
|
|
23
|
-
export
|
|
23
|
+
export type HasRequiredKeys<BaseType extends object> = RequiredKeysOf<BaseType> extends never ? false : true;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type Pattern = readonly [string, string, RegExp | true] | '*';
|
|
2
2
|
export declare const splitPath: (path: string) => string[];
|
|
3
3
|
export declare const splitRoutingPath: (path: string) => string[];
|
|
4
4
|
export declare const getPattern: (label: string) => Pattern | null;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Context } from '../context';
|
|
2
2
|
import type { Env, ValidationTargets, MiddlewareHandler } from '../types';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export
|
|
3
|
+
type ValidationTargetKeysWithBody = 'form' | 'json';
|
|
4
|
+
type ValidationTargetByMethod<M> = M extends 'get' | 'head' ? Exclude<keyof ValidationTargets, ValidationTargetKeysWithBody> : keyof ValidationTargets;
|
|
5
|
+
export type ValidationFunction<InputType, OutputType, E extends Env = {}, P extends string = string> = (value: InputType, c: Context<E, P>) => OutputType | Response | Promise<OutputType> | Promise<Response>;
|
|
6
6
|
export declare const validator: <InputType, P extends string, M extends string, U extends ValidationTargetByMethod<M>, OutputType = ValidationTargets[U], P2 extends string = P, V extends {
|
|
7
7
|
in: { [K in U]: unknown extends InputType ? OutputType : InputType; };
|
|
8
8
|
out: { [K_1 in U]: OutputType; };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hono",
|
|
3
|
-
"version": "3.11.
|
|
3
|
+
"version": "3.11.7",
|
|
4
4
|
"description": "Ultrafast web framework for the Edges",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"test:lambda": "env NAME=Node vitest --run --config ./runtime_tests/lambda/vitest.config.ts",
|
|
21
21
|
"test:lambda-edge": "env NAME=Node vitest --run --config ./runtime_tests/lambda-edge/vitest.config.ts",
|
|
22
22
|
"test:all": "yarn test && yarn test:deno && yarn test:bun && yarn test:fastly && yarn test:lagon && yarn test:node && yarn test:wrangler && yarn test:lambda && yarn test:lambda-edge",
|
|
23
|
-
"lint": "eslint --ext js,ts src runtime_tests
|
|
24
|
-
"lint:fix": "eslint --ext js,ts src runtime_tests
|
|
23
|
+
"lint": "eslint --ext js,ts src runtime_tests",
|
|
24
|
+
"lint:fix": "eslint --ext js,ts src runtime_tests --fix",
|
|
25
25
|
"format": "prettier --check 'src/**/*.{js,ts}' 'runtime_tests/**/*.{js,ts}'",
|
|
26
26
|
"format:fix": "prettier --write 'src/**/*.{js,ts}' 'runtime_tests/**/*.{js,ts}'",
|
|
27
27
|
"denoify": "rimraf deno_dist && denoify && rimraf 'deno_dist/**/*.test.{ts,tsx}'",
|
|
@@ -442,6 +442,7 @@
|
|
|
442
442
|
],
|
|
443
443
|
"devDependencies": {
|
|
444
444
|
"@cloudflare/workers-types": "^4.20221111.1",
|
|
445
|
+
"@hono/eslint-config": "^0.0.2",
|
|
445
446
|
"@hono/node-server": "^1.0.2",
|
|
446
447
|
"@types/crypto-js": "^4.1.1",
|
|
447
448
|
"@types/glob": "^8.0.0",
|
|
@@ -450,21 +451,12 @@
|
|
|
450
451
|
"@types/node": "^20.8.2",
|
|
451
452
|
"@types/node-fetch": "^2.6.2",
|
|
452
453
|
"@types/supertest": "^2.0.12",
|
|
453
|
-
"@typescript-eslint/eslint-plugin": "^5.59.2",
|
|
454
|
-
"@typescript-eslint/parser": "^5.59.2",
|
|
455
454
|
"@vitest/coverage-v8": "^0.34.3",
|
|
456
455
|
"arg": "^5.0.2",
|
|
457
456
|
"crypto-js": "^4.1.1",
|
|
458
457
|
"denoify": "^1.6.6",
|
|
459
458
|
"esbuild": "^0.15.12",
|
|
460
|
-
"eslint": "^8.
|
|
461
|
-
"eslint-config-prettier": "^8.8.0",
|
|
462
|
-
"eslint-define-config": "^1.20.0",
|
|
463
|
-
"eslint-import-resolver-typescript": "^3.5.5",
|
|
464
|
-
"eslint-plugin-eslint-comments": "^3.2.0",
|
|
465
|
-
"eslint-plugin-flowtype": "^8.0.3",
|
|
466
|
-
"eslint-plugin-import": "^2.27.5",
|
|
467
|
-
"eslint-plugin-node": "^11.1.0",
|
|
459
|
+
"eslint": "^8.55.0",
|
|
468
460
|
"form-data": "^4.0.0",
|
|
469
461
|
"jest": "^29.6.4",
|
|
470
462
|
"jest-preset-fastly-js-compute": "^1.3.0",
|
|
@@ -479,13 +471,12 @@
|
|
|
479
471
|
"supertest": "^6.3.3",
|
|
480
472
|
"ts-jest": "^29.1.1",
|
|
481
473
|
"tsx": "^3.11.0",
|
|
482
|
-
"typescript": "^
|
|
474
|
+
"typescript": "^5.3.3",
|
|
483
475
|
"vitest": "^0.34.3",
|
|
484
476
|
"wrangler": "^2.12.0",
|
|
485
477
|
"zod": "^3.20.2"
|
|
486
478
|
},
|
|
487
479
|
"engines": {
|
|
488
480
|
"node": ">=16.0.0"
|
|
489
|
-
}
|
|
490
|
-
"dependencies": {}
|
|
481
|
+
}
|
|
491
482
|
}
|