hono 4.6.3 → 4.6.5
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/adapter/service-worker/handler.js +1 -1
- package/dist/cjs/adapter/service-worker/handler.js +1 -1
- package/dist/cjs/middleware/cors/index.js +6 -2
- package/dist/cjs/middleware/csrf/index.js +1 -1
- package/dist/cjs/middleware/powered-by/index.js +2 -2
- package/dist/middleware/cors/index.js +6 -2
- package/dist/middleware/csrf/index.js +1 -1
- package/dist/middleware/powered-by/index.js +2 -2
- package/dist/types/adapter/aws-lambda/handler.d.ts +1 -1
- package/dist/types/adapter/cloudflare-pages/handler.d.ts +2 -2
- package/dist/types/adapter/lambda-edge/handler.d.ts +4 -4
- package/dist/types/adapter/netlify/handler.d.ts +1 -1
- package/dist/types/client/types.d.ts +9 -8
- package/dist/types/client/utils.d.ts +1 -1
- package/dist/types/compose.d.ts +7 -1
- package/dist/types/context.d.ts +27 -17
- package/dist/types/helper/accepts/accepts.d.ts +1 -1
- package/dist/types/helper/adapter/index.d.ts +2 -2
- package/dist/types/helper/conninfo/types.d.ts +2 -2
- package/dist/types/helper/css/common.d.ts +6 -1
- package/dist/types/helper/dev/index.d.ts +3 -3
- package/dist/types/helper/factory/index.d.ts +32 -8
- package/dist/types/helper/ssg/ssg.d.ts +1 -1
- package/dist/types/helper/ssg/utils.d.ts +1 -1
- package/dist/types/helper/streaming/sse.d.ts +1 -1
- package/dist/types/helper/streaming/stream.d.ts +1 -1
- package/dist/types/helper/streaming/text.d.ts +1 -1
- package/dist/types/helper/testing/index.d.ts +1 -1
- package/dist/types/helper/websocket/index.d.ts +1 -1
- package/dist/types/hono-base.d.ts +20 -23
- package/dist/types/hono.d.ts +1 -1
- package/dist/types/jsx/base.d.ts +8 -2
- package/dist/types/jsx/dom/hooks/index.d.ts +9 -3
- package/dist/types/jsx/dom/index.d.ts +52 -31
- package/dist/types/jsx/dom/intrinsic-element/components.d.ts +7 -7
- package/dist/types/jsx/dom/render.d.ts +28 -4
- package/dist/types/jsx/dom/server.d.ts +56 -35
- package/dist/types/jsx/hooks/index.d.ts +25 -10
- package/dist/types/jsx/index.d.ts +52 -31
- package/dist/types/jsx/intrinsic-element/components.d.ts +4 -4
- package/dist/types/jsx/intrinsic-elements.d.ts +46 -46
- package/dist/types/middleware/cache/index.d.ts +4 -4
- package/dist/types/middleware/compress/index.d.ts +4 -1
- package/dist/types/middleware/context-storage/index.d.ts +1 -1
- package/dist/types/middleware/ip-restriction/index.d.ts +2 -2
- package/dist/types/middleware/jwt/jwt.d.ts +2 -2
- package/dist/types/middleware/powered-by/index.d.ts +5 -1
- package/dist/types/middleware/secure-headers/permissions-policy.d.ts +3 -3
- package/dist/types/middleware/secure-headers/secure-headers.d.ts +1 -1
- package/dist/types/middleware/serve-static/index.d.ts +3 -3
- package/dist/types/preset/quick.d.ts +1 -1
- package/dist/types/preset/tiny.d.ts +1 -1
- package/dist/types/request.d.ts +5 -7
- package/dist/types/router/linear-router/router.d.ts +5 -1
- package/dist/types/router/pattern-router/router.d.ts +0 -1
- package/dist/types/router/reg-exp-router/node.d.ts +4 -1
- package/dist/types/router/reg-exp-router/router.d.ts +4 -3
- package/dist/types/router/reg-exp-router/trie.d.ts +5 -1
- package/dist/types/router/smart-router/router.d.ts +6 -2
- package/dist/types/router/trie-router/node.d.ts +6 -2
- package/dist/types/router.d.ts +20 -2
- package/dist/types/types.d.ts +908 -120
- package/dist/types/utils/concurrent.d.ts +2 -2
- package/dist/types/utils/cookie.d.ts +4 -4
- package/dist/types/utils/filepath.d.ts +1 -1
- package/dist/types/utils/html.d.ts +6 -2
- package/dist/types/utils/jwt/index.d.ts +2 -2
- package/dist/types/utils/jwt/jwt.d.ts +1 -1
- package/dist/types/utils/mime.d.ts +1 -1
- package/dist/types/utils/stream.d.ts +0 -4
- package/dist/types/utils/url.d.ts +5 -1
- package/dist/types/validator/validator.d.ts +18 -6
- package/package.json +10 -11
|
@@ -22,7 +22,7 @@ __export(handler_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(handler_exports);
|
|
24
24
|
const handle = (app, opts = {
|
|
25
|
-
fetch: globalThis.
|
|
25
|
+
fetch: globalThis.fetch.bind(globalThis)
|
|
26
26
|
}) => {
|
|
27
27
|
return (evt) => {
|
|
28
28
|
evt.respondWith(
|
|
@@ -34,11 +34,15 @@ const cors = (options) => {
|
|
|
34
34
|
};
|
|
35
35
|
const findAllowOrigin = ((optsOrigin) => {
|
|
36
36
|
if (typeof optsOrigin === "string") {
|
|
37
|
-
|
|
37
|
+
if (optsOrigin === "*") {
|
|
38
|
+
return () => optsOrigin;
|
|
39
|
+
} else {
|
|
40
|
+
return (origin) => optsOrigin === origin ? origin : null;
|
|
41
|
+
}
|
|
38
42
|
} else if (typeof optsOrigin === "function") {
|
|
39
43
|
return optsOrigin;
|
|
40
44
|
} else {
|
|
41
|
-
return (origin) => optsOrigin.includes(origin) ? origin :
|
|
45
|
+
return (origin) => optsOrigin.includes(origin) ? origin : null;
|
|
42
46
|
}
|
|
43
47
|
})(opts.origin);
|
|
44
48
|
return async function cors2(c, next) {
|
|
@@ -43,7 +43,7 @@ const csrf = (options) => {
|
|
|
43
43
|
return handler(origin, c);
|
|
44
44
|
};
|
|
45
45
|
return async function csrf2(c, next) {
|
|
46
|
-
if (!isSafeMethodRe.test(c.req.method) && isRequestedByFormElementRe.test(c.req.header("content-type") || "") && !isAllowedOrigin(c.req.header("origin"), c)) {
|
|
46
|
+
if (!isSafeMethodRe.test(c.req.method) && isRequestedByFormElementRe.test(c.req.header("content-type") || "text/plain") && !isAllowedOrigin(c.req.header("origin"), c)) {
|
|
47
47
|
const res = new Response("Forbidden", {
|
|
48
48
|
status: 403
|
|
49
49
|
});
|
|
@@ -21,10 +21,10 @@ __export(powered_by_exports, {
|
|
|
21
21
|
poweredBy: () => poweredBy
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(powered_by_exports);
|
|
24
|
-
const poweredBy = () => {
|
|
24
|
+
const poweredBy = (options) => {
|
|
25
25
|
return async function poweredBy2(c, next) {
|
|
26
26
|
await next();
|
|
27
|
-
c.res.headers.set("X-Powered-By", "Hono");
|
|
27
|
+
c.res.headers.set("X-Powered-By", options?.serverName ?? "Hono");
|
|
28
28
|
};
|
|
29
29
|
};
|
|
30
30
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -12,11 +12,15 @@ var cors = (options) => {
|
|
|
12
12
|
};
|
|
13
13
|
const findAllowOrigin = ((optsOrigin) => {
|
|
14
14
|
if (typeof optsOrigin === "string") {
|
|
15
|
-
|
|
15
|
+
if (optsOrigin === "*") {
|
|
16
|
+
return () => optsOrigin;
|
|
17
|
+
} else {
|
|
18
|
+
return (origin) => optsOrigin === origin ? origin : null;
|
|
19
|
+
}
|
|
16
20
|
} else if (typeof optsOrigin === "function") {
|
|
17
21
|
return optsOrigin;
|
|
18
22
|
} else {
|
|
19
|
-
return (origin) => optsOrigin.includes(origin) ? origin :
|
|
23
|
+
return (origin) => optsOrigin.includes(origin) ? origin : null;
|
|
20
24
|
}
|
|
21
25
|
})(opts.origin);
|
|
22
26
|
return async function cors2(c, next) {
|
|
@@ -21,7 +21,7 @@ var csrf = (options) => {
|
|
|
21
21
|
return handler(origin, c);
|
|
22
22
|
};
|
|
23
23
|
return async function csrf2(c, next) {
|
|
24
|
-
if (!isSafeMethodRe.test(c.req.method) && isRequestedByFormElementRe.test(c.req.header("content-type") || "") && !isAllowedOrigin(c.req.header("origin"), c)) {
|
|
24
|
+
if (!isSafeMethodRe.test(c.req.method) && isRequestedByFormElementRe.test(c.req.header("content-type") || "text/plain") && !isAllowedOrigin(c.req.header("origin"), c)) {
|
|
25
25
|
const res = new Response("Forbidden", {
|
|
26
26
|
status: 403
|
|
27
27
|
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// src/middleware/powered-by/index.ts
|
|
2
|
-
var poweredBy = () => {
|
|
2
|
+
var poweredBy = (options) => {
|
|
3
3
|
return async function poweredBy2(c, next) {
|
|
4
4
|
await next();
|
|
5
|
-
c.res.headers.set("X-Powered-By", "Hono");
|
|
5
|
+
c.res.headers.set("X-Powered-By", options?.serverName ?? "Hono");
|
|
6
6
|
};
|
|
7
7
|
};
|
|
8
8
|
export {
|
|
@@ -70,7 +70,7 @@ export declare const streamHandle: <E extends Env = Env, S extends Schema = {},
|
|
|
70
70
|
/**
|
|
71
71
|
* Accepts events from API Gateway/ELB(`APIGatewayProxyEvent`) and directly through Function Url(`APIGatewayProxyEventV2`)
|
|
72
72
|
*/
|
|
73
|
-
export declare const handle: <E extends Env = Env, S extends Schema = {}, BasePath extends string = "/">(app: Hono<E, S, BasePath>) => (event: LambdaEvent, lambdaContext?: LambdaContext) => Promise<APIGatewayProxyResult
|
|
73
|
+
export declare const handle: <E extends Env = Env, S extends Schema = {}, BasePath extends string = "/">(app: Hono<E, S, BasePath>) => ((event: LambdaEvent, lambdaContext?: LambdaContext) => Promise<APIGatewayProxyResult>);
|
|
74
74
|
declare abstract class EventProcessor<E extends LambdaEvent> {
|
|
75
75
|
protected abstract getPath(event: E): string;
|
|
76
76
|
protected abstract getMethod(event: E): string;
|
|
@@ -16,12 +16,12 @@ export type EventContext<Env = {}, P extends string = any, Data = Record<string,
|
|
|
16
16
|
data: Data;
|
|
17
17
|
};
|
|
18
18
|
declare type PagesFunction<Env = unknown, Params extends string = any, Data extends Record<string, unknown> = Record<string, unknown>> = (context: EventContext<Env, Params, Data>) => Response | Promise<Response>;
|
|
19
|
-
export declare const handle: <E extends Env = Env, S extends Schema = BlankSchema, BasePath extends string = "/">(app: Hono<E, S, BasePath>) => PagesFunction<E["Bindings"]
|
|
19
|
+
export declare const handle: <E extends Env = Env, S extends Schema = BlankSchema, BasePath extends string = "/">(app: Hono<E, S, BasePath>) => PagesFunction<E["Bindings"]>;
|
|
20
20
|
export declare function handleMiddleware<E extends Env = {}, P extends string = any, I extends Input = {}>(middleware: MiddlewareHandler<E & {
|
|
21
21
|
Bindings: {
|
|
22
22
|
eventContext: EventContext;
|
|
23
23
|
};
|
|
24
|
-
}, P, I>): PagesFunction<E[
|
|
24
|
+
}, P, I>): PagesFunction<E["Bindings"]>;
|
|
25
25
|
/**
|
|
26
26
|
*
|
|
27
27
|
* @description `serveStatic()` is for advanced mode:
|
|
@@ -17,7 +17,7 @@ interface CloudFrontCustomOrigin {
|
|
|
17
17
|
sslProtocols: string[];
|
|
18
18
|
}
|
|
19
19
|
interface CloudFrontS3Origin {
|
|
20
|
-
authMethod:
|
|
20
|
+
authMethod: "origin-access-identity" | "none";
|
|
21
21
|
customHeaders: CloudFrontHeaders;
|
|
22
22
|
domainName: string;
|
|
23
23
|
path: string;
|
|
@@ -79,9 +79,9 @@ interface CloudFrontResult {
|
|
|
79
79
|
}[];
|
|
80
80
|
};
|
|
81
81
|
body?: string;
|
|
82
|
-
bodyEncoding?:
|
|
82
|
+
bodyEncoding?: "text" | "base64";
|
|
83
83
|
}
|
|
84
|
-
export declare const handle: (app: Hono<any>) => (event: CloudFrontEdgeEvent, context?: CloudFrontContext, callback?: Callback) => Promise<CloudFrontResult
|
|
85
|
-
export declare const createBody: (method: string, requestBody: CloudFrontRequest[
|
|
84
|
+
export declare const handle: (app: Hono<any>) => ((event: CloudFrontEdgeEvent, context?: CloudFrontContext, callback?: Callback) => Promise<CloudFrontResult>);
|
|
85
|
+
export declare const createBody: (method: string, requestBody: CloudFrontRequest["body"]) => string | Uint8Array | undefined;
|
|
86
86
|
export declare const isContentTypeBinary: (contentType: string) => boolean;
|
|
87
87
|
export {};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { Hono } from '../../hono';
|
|
2
|
-
export declare const handle: (app: Hono<any, any>) => (req: Request, context: any) => Response | Promise<Response
|
|
2
|
+
export declare const handle: (app: Hono<any, any>) => ((req: Request, context: any) => Response | Promise<Response>);
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { Hono } from '../hono';
|
|
2
|
+
import type { HonoBase } from '../hono-base';
|
|
2
3
|
import type { Endpoint, ResponseFormat, Schema } from '../types';
|
|
3
4
|
import type { StatusCode, SuccessStatusCode } from '../utils/http-status';
|
|
4
5
|
import type { HasRequiredKeys } from '../utils/types';
|
|
5
|
-
type HonoRequest = (typeof Hono.prototype)[
|
|
6
|
+
type HonoRequest = (typeof Hono.prototype)["request"];
|
|
6
7
|
export type ClientRequestOptions<T = unknown> = {
|
|
7
8
|
fetch?: typeof fetch | HonoRequest;
|
|
8
9
|
webSocket?: (...args: ConstructorParameters<typeof WebSocket>) => WebSocket;
|
|
@@ -30,9 +31,9 @@ export type ClientRequest<S extends Schema> = {
|
|
|
30
31
|
} ? {
|
|
31
32
|
param: P;
|
|
32
33
|
} : {} : {}) => URL;
|
|
33
|
-
} & (S[
|
|
34
|
-
outputFormat:
|
|
35
|
-
} ? S[
|
|
34
|
+
} & (S["$get"] extends {
|
|
35
|
+
outputFormat: "ws";
|
|
36
|
+
} ? S["$get"] extends {
|
|
36
37
|
input: infer I;
|
|
37
38
|
} ? {
|
|
38
39
|
$ws: (args?: I) => WebSocket;
|
|
@@ -53,8 +54,8 @@ export interface ClientResponse<T, U extends number = StatusCode, F extends Resp
|
|
|
53
54
|
url: string;
|
|
54
55
|
redirect(url: string, status: number): Response;
|
|
55
56
|
clone(): Response;
|
|
56
|
-
json(): F extends
|
|
57
|
-
text(): F extends
|
|
57
|
+
json(): F extends "text" ? Promise<never> : F extends "json" ? Promise<BlankRecordToNever<T>> : Promise<unknown>;
|
|
58
|
+
text(): F extends "text" ? (T extends string ? Promise<T> : Promise<never>) : Promise<string>;
|
|
58
59
|
blob(): Promise<Blob>;
|
|
59
60
|
formData(): Promise<FormData>;
|
|
60
61
|
arrayBuffer(): Promise<ArrayBuffer>;
|
|
@@ -83,9 +84,9 @@ export type InferRequestOptionsType<T> = T extends (args: any, options: infer R)
|
|
|
83
84
|
type PathToChain<Path extends string, E extends Schema, Original extends string = Path> = Path extends `/${infer P}` ? PathToChain<P, E, Path> : Path extends `${infer P}/${infer R}` ? {
|
|
84
85
|
[K in P]: PathToChain<R, E, Original>;
|
|
85
86
|
} : {
|
|
86
|
-
[K in Path extends
|
|
87
|
+
[K in Path extends "" ? "index" : Path]: ClientRequest<E extends Record<string, unknown> ? E[Original] : never>;
|
|
87
88
|
};
|
|
88
|
-
export type Client<T> = T extends
|
|
89
|
+
export type Client<T> = T extends HonoBase<any, infer S, any> ? S extends Record<infer K, Schema> ? K extends string ? PathToChain<K, S> : never : never : never;
|
|
89
90
|
export type Callback = (opts: CallbackOptions) => unknown;
|
|
90
91
|
interface CallbackOptions {
|
|
91
92
|
path: string[];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare const mergePath: (base: string, path: string) => string;
|
|
2
2
|
export declare const replaceUrlParam: (urlString: string, params: Record<string, string | undefined>) => string;
|
|
3
|
-
export declare const replaceUrlProtocol: (urlString: string, protocol:
|
|
3
|
+
export declare const replaceUrlProtocol: (urlString: string, protocol: "ws" | "http") => string;
|
|
4
4
|
export declare const removeIndexString: (urlSting: string) => string;
|
|
5
5
|
export declare function deepMerge<T>(target: T, source: Record<string, unknown>): T;
|
package/dist/types/compose.d.ts
CHANGED
|
@@ -26,5 +26,11 @@ interface ComposeContext {
|
|
|
26
26
|
*
|
|
27
27
|
* @returns {(context: C, next?: Function) => Promise<C>} - A composed middleware function.
|
|
28
28
|
*/
|
|
29
|
-
export declare const compose: <C extends ComposeContext, E extends Env = Env>(middleware: [
|
|
29
|
+
export declare const compose: <C extends ComposeContext, E extends Env = Env>(middleware: [
|
|
30
|
+
[
|
|
31
|
+
Function,
|
|
32
|
+
unknown
|
|
33
|
+
],
|
|
34
|
+
ParamIndexMap | Params
|
|
35
|
+
][], onError?: ErrorHandler<E>, onNotFound?: NotFoundHandler<E>) => ((context: C, next?: Function) => Promise<C>);
|
|
30
36
|
export {};
|
package/dist/types/context.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { Env, FetchEventLike, H, Input, NotFoundHandler, RouterRoute, Typed
|
|
|
4
4
|
import type { RedirectStatusCode, StatusCode } from './utils/http-status';
|
|
5
5
|
import type { BaseMime } from './utils/mime';
|
|
6
6
|
import type { InvalidJSONValue, IsAny, JSONParsed, JSONValue, SimplifyDeepArray } from './utils/types';
|
|
7
|
-
type HeaderRecord = Record<
|
|
7
|
+
type HeaderRecord = Record<"Content-Type", BaseMime> | Record<ResponseHeader, string | string[]> | Record<string, string | string[]>;
|
|
8
8
|
/**
|
|
9
9
|
* Data type can be a string, ArrayBuffer, or ReadableStream.
|
|
10
10
|
*/
|
|
@@ -51,7 +51,12 @@ export type Renderer = ContextRenderer extends Function ? ContextRenderer : Defa
|
|
|
51
51
|
/**
|
|
52
52
|
* Extracts the props for the renderer.
|
|
53
53
|
*/
|
|
54
|
-
export type PropsForRenderer = [
|
|
54
|
+
export type PropsForRenderer = [
|
|
55
|
+
...Required<Parameters<Renderer>>
|
|
56
|
+
] extends [
|
|
57
|
+
unknown,
|
|
58
|
+
infer Props
|
|
59
|
+
] ? Props : unknown;
|
|
55
60
|
export type Layout<T = Record<string, any>> = (props: T) => any;
|
|
56
61
|
/**
|
|
57
62
|
* Interface for getting context variables.
|
|
@@ -59,7 +64,7 @@ export type Layout<T = Record<string, any>> = (props: T) => any;
|
|
|
59
64
|
* @template E - Environment type.
|
|
60
65
|
*/
|
|
61
66
|
interface Get<E extends Env> {
|
|
62
|
-
<Key extends keyof E[
|
|
67
|
+
<Key extends keyof E["Variables"]>(key: Key): E["Variables"][Key];
|
|
63
68
|
<Key extends keyof ContextVariableMap>(key: Key): ContextVariableMap[Key];
|
|
64
69
|
}
|
|
65
70
|
/**
|
|
@@ -68,7 +73,7 @@ interface Get<E extends Env> {
|
|
|
68
73
|
* @template E - Environment type.
|
|
69
74
|
*/
|
|
70
75
|
interface Set<E extends Env> {
|
|
71
|
-
<Key extends keyof E[
|
|
76
|
+
<Key extends keyof E["Variables"]>(key: Key, value: E["Variables"][Key]): void;
|
|
72
77
|
<Key extends keyof ContextVariableMap>(key: Key, value: ContextVariableMap[Key]): void;
|
|
73
78
|
}
|
|
74
79
|
/**
|
|
@@ -97,8 +102,8 @@ interface BodyRespond extends NewResponse {
|
|
|
97
102
|
* @returns {Response & TypedResponse<T, U, 'text'>} - The response after rendering the text content, typed with the provided text and status code types.
|
|
98
103
|
*/
|
|
99
104
|
interface TextRespond {
|
|
100
|
-
<T extends string, U extends StatusCode = StatusCode>(text: T, status?: U, headers?: HeaderRecord): Response & TypedResponse<T, U,
|
|
101
|
-
<T extends string, U extends StatusCode = StatusCode>(text: T, init?: ResponseInit): Response & TypedResponse<T, U,
|
|
105
|
+
<T extends string, U extends StatusCode = StatusCode>(text: T, status?: U, headers?: HeaderRecord): Response & TypedResponse<T, U, "text">;
|
|
106
|
+
<T extends string, U extends StatusCode = StatusCode>(text: T, init?: ResponseInit): Response & TypedResponse<T, U, "text">;
|
|
102
107
|
}
|
|
103
108
|
/**
|
|
104
109
|
* Interface for responding with JSON.
|
|
@@ -123,7 +128,7 @@ interface JSONRespond {
|
|
|
123
128
|
*
|
|
124
129
|
* @returns {Response & TypedResponse<SimplifyDeepArray<T> extends JSONValue ? (JSONValue extends SimplifyDeepArray<T> ? never : JSONParsed<T>) : never, U, 'json'>} - The response after rendering the JSON object, typed with the provided object and status code types.
|
|
125
130
|
*/
|
|
126
|
-
type JSONRespondReturn<T extends JSONValue | SimplifyDeepArray<unknown> | InvalidJSONValue, U extends StatusCode> = Response & TypedResponse<SimplifyDeepArray<T> extends JSONValue ? JSONValue extends SimplifyDeepArray<T> ? never : JSONParsed<T> : never, U,
|
|
131
|
+
type JSONRespondReturn<T extends JSONValue | SimplifyDeepArray<unknown> | InvalidJSONValue, U extends StatusCode> = Response & TypedResponse<SimplifyDeepArray<T> extends JSONValue ? JSONValue extends SimplifyDeepArray<T> ? never : JSONParsed<T> : never, U, "json">;
|
|
127
132
|
/**
|
|
128
133
|
* Interface representing a function that responds with HTML content.
|
|
129
134
|
*
|
|
@@ -147,7 +152,7 @@ type ContextOptions<E extends Env> = {
|
|
|
147
152
|
/**
|
|
148
153
|
* Bindings for the environment.
|
|
149
154
|
*/
|
|
150
|
-
env: E[
|
|
155
|
+
env: E["Bindings"];
|
|
151
156
|
/**
|
|
152
157
|
* Execution context for the request.
|
|
153
158
|
*/
|
|
@@ -156,19 +161,25 @@ type ContextOptions<E extends Env> = {
|
|
|
156
161
|
* Handler for not found responses.
|
|
157
162
|
*/
|
|
158
163
|
notFoundHandler?: NotFoundHandler<E>;
|
|
159
|
-
matchResult?: Result<[
|
|
164
|
+
matchResult?: Result<[
|
|
165
|
+
H,
|
|
166
|
+
RouterRoute
|
|
167
|
+
]>;
|
|
160
168
|
path?: string;
|
|
161
169
|
};
|
|
162
170
|
interface SetHeadersOptions {
|
|
163
171
|
append?: boolean;
|
|
164
172
|
}
|
|
165
|
-
type ResponseHeader =
|
|
173
|
+
type ResponseHeader = "Access-Control-Allow-Credentials" | "Access-Control-Allow-Headers" | "Access-Control-Allow-Methods" | "Access-Control-Allow-Origin" | "Access-Control-Expose-Headers" | "Access-Control-Max-Age" | "Age" | "Allow" | "Cache-Control" | "Clear-Site-Data" | "Content-Disposition" | "Content-Encoding" | "Content-Language" | "Content-Length" | "Content-Location" | "Content-Range" | "Content-Security-Policy" | "Content-Security-Policy-Report-Only" | "Content-Type" | "Cookie" | "Cross-Origin-Embedder-Policy" | "Cross-Origin-Opener-Policy" | "Cross-Origin-Resource-Policy" | "Date" | "ETag" | "Expires" | "Last-Modified" | "Location" | "Permissions-Policy" | "Pragma" | "Retry-After" | "Save-Data" | "Sec-CH-Prefers-Color-Scheme" | "Sec-CH-Prefers-Reduced-Motion" | "Sec-CH-UA" | "Sec-CH-UA-Arch" | "Sec-CH-UA-Bitness" | "Sec-CH-UA-Form-Factor" | "Sec-CH-UA-Full-Version" | "Sec-CH-UA-Full-Version-List" | "Sec-CH-UA-Mobile" | "Sec-CH-UA-Model" | "Sec-CH-UA-Platform" | "Sec-CH-UA-Platform-Version" | "Sec-CH-UA-WoW64" | "Sec-Fetch-Dest" | "Sec-Fetch-Mode" | "Sec-Fetch-Site" | "Sec-Fetch-User" | "Sec-GPC" | "Server" | "Server-Timing" | "Service-Worker-Navigation-Preload" | "Set-Cookie" | "Strict-Transport-Security" | "Timing-Allow-Origin" | "Trailer" | "Transfer-Encoding" | "Upgrade" | "Vary" | "WWW-Authenticate" | "Warning" | "X-Content-Type-Options" | "X-DNS-Prefetch-Control" | "X-Frame-Options" | "X-Permitted-Cross-Domain-Policies" | "X-Powered-By" | "X-Robots-Tag" | "X-XSS-Protection";
|
|
166
174
|
interface SetHeaders {
|
|
167
|
-
(name:
|
|
175
|
+
(name: "Content-Type", value?: BaseMime, options?: SetHeadersOptions): void;
|
|
168
176
|
(name: ResponseHeader, value?: string, options?: SetHeadersOptions): void;
|
|
169
177
|
(name: string, value?: string, options?: SetHeadersOptions): void;
|
|
170
178
|
}
|
|
171
|
-
type ResponseHeadersInit = [
|
|
179
|
+
type ResponseHeadersInit = [
|
|
180
|
+
string,
|
|
181
|
+
string
|
|
182
|
+
][] | Record<"Content-Type", BaseMime> | Record<ResponseHeader, string> | Record<string, string> | Headers;
|
|
172
183
|
interface ResponseInit {
|
|
173
184
|
headers?: ResponseHeadersInit;
|
|
174
185
|
status?: number;
|
|
@@ -176,7 +187,6 @@ interface ResponseInit {
|
|
|
176
187
|
}
|
|
177
188
|
export declare const TEXT_PLAIN = "text/plain; charset=UTF-8";
|
|
178
189
|
export declare class Context<E extends Env = any, P extends string = any, I extends Input = {}> {
|
|
179
|
-
#private;
|
|
180
190
|
/**
|
|
181
191
|
* `.env` can get bindings (environment variables, secrets, KV namespaces, D1 database, R2 bucket etc.) in Cloudflare Workers.
|
|
182
192
|
*
|
|
@@ -190,7 +200,7 @@ export declare class Context<E extends Env = any, P extends string = any, I exte
|
|
|
190
200
|
* })
|
|
191
201
|
* ```
|
|
192
202
|
*/
|
|
193
|
-
env: E[
|
|
203
|
+
env: E["Bindings"];
|
|
194
204
|
finalized: boolean;
|
|
195
205
|
/**
|
|
196
206
|
* `.error` can get the error object from the middleware if the Handler throws an error.
|
|
@@ -218,7 +228,7 @@ export declare class Context<E extends Env = any, P extends string = any, I exte
|
|
|
218
228
|
/**
|
|
219
229
|
* `.req` is the instance of {@link HonoRequest}.
|
|
220
230
|
*/
|
|
221
|
-
get req(): HonoRequest<P, I[
|
|
231
|
+
get req(): HonoRequest<P, I["out"]>;
|
|
222
232
|
/**
|
|
223
233
|
* @see {@link https://hono.dev/docs/api/context#event}
|
|
224
234
|
* The FetchEvent associated with the current request.
|
|
@@ -358,7 +368,7 @@ export declare class Context<E extends Env = any, P extends string = any, I exte
|
|
|
358
368
|
* const result = c.var.client.oneMethod()
|
|
359
369
|
* ```
|
|
360
370
|
*/
|
|
361
|
-
get var(): Readonly<ContextVariableMap & (IsAny<E[
|
|
371
|
+
get var(): Readonly<ContextVariableMap & (IsAny<E["Variables"]> extends true ? Record<string, any> : E["Variables"])>;
|
|
362
372
|
newResponse: NewResponse;
|
|
363
373
|
/**
|
|
364
374
|
* `.body()` can return the HTTP response.
|
|
@@ -424,7 +434,7 @@ export declare class Context<E extends Env = any, P extends string = any, I exte
|
|
|
424
434
|
* })
|
|
425
435
|
* ```
|
|
426
436
|
*/
|
|
427
|
-
redirect: <T extends RedirectStatusCode = 302>(location: string, status?: T
|
|
437
|
+
redirect: <T extends RedirectStatusCode = 302>(location: string, status?: T) => Response & TypedResponse<undefined, T, "redirect">;
|
|
428
438
|
/**
|
|
429
439
|
* `.notFound()` can return the Not Found Response.
|
|
430
440
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Context } from '../../context';
|
|
2
|
-
export type AcceptHeader =
|
|
2
|
+
export type AcceptHeader = "Accept" | "Accept-Charset" | "Accept-Encoding" | "Accept-Language" | "Accept-Patch" | "Accept-Post" | "Accept-Ranges";
|
|
3
3
|
export interface Accept {
|
|
4
4
|
type: string;
|
|
5
5
|
params: Record<string, string>;
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* Adapter Helper for Hono.
|
|
4
4
|
*/
|
|
5
5
|
import type { Context } from '../../context';
|
|
6
|
-
export type Runtime =
|
|
7
|
-
export declare const env: <T extends Record<string, unknown>, C extends Context
|
|
6
|
+
export type Runtime = "node" | "deno" | "bun" | "workerd" | "fastly" | "edge-light" | "other";
|
|
7
|
+
export declare const env: <T extends Record<string, unknown>, C extends Context = Context<{}, any, {}>>(c: C, runtime?: Runtime) => T & C["env"];
|
|
8
8
|
export declare const knownUserAgents: Partial<Record<Runtime, string>>;
|
|
9
9
|
export declare const getRuntimeKey: () => Runtime;
|
|
10
10
|
export declare const checkUserAgentEquals: (platform: string) => boolean;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { Context } from '../../context';
|
|
2
|
-
export type AddressType =
|
|
2
|
+
export type AddressType = "IPv6" | "IPv4" | undefined;
|
|
3
3
|
export type NetAddrInfo = {
|
|
4
4
|
/**
|
|
5
5
|
* Transport protocol type
|
|
6
6
|
*/
|
|
7
|
-
transport?:
|
|
7
|
+
transport?: "tcp" | "udp";
|
|
8
8
|
/**
|
|
9
9
|
* Transport port number
|
|
10
10
|
*/
|
|
@@ -29,7 +29,12 @@ type CssVariableBasicType = CssClassName | CssEscapedString | string | number |
|
|
|
29
29
|
type CssVariableAsyncType = Promise<CssVariableBasicType>;
|
|
30
30
|
type CssVariableArrayType = (CssVariableBasicType | CssVariableAsyncType)[];
|
|
31
31
|
export type CssVariableType = CssVariableBasicType | CssVariableAsyncType | CssVariableArrayType;
|
|
32
|
-
export declare const buildStyleString: (strings: TemplateStringsArray, values: CssVariableType[]) => [
|
|
32
|
+
export declare const buildStyleString: (strings: TemplateStringsArray, values: CssVariableType[]) => [
|
|
33
|
+
string,
|
|
34
|
+
string,
|
|
35
|
+
CssClassName[],
|
|
36
|
+
string[]
|
|
37
|
+
];
|
|
33
38
|
export declare const cssCommon: (strings: TemplateStringsArray, values: CssVariableType[]) => CssClassName;
|
|
34
39
|
export declare const cxCommon: (args: (string | boolean | null | undefined | CssClassName)[]) => (string | boolean | null | undefined | CssClassName)[];
|
|
35
40
|
export declare const keyframesCommon: (strings: TemplateStringsArray, ...values: CssVariableType[]) => CssClassName;
|
|
@@ -14,7 +14,7 @@ interface RouteData {
|
|
|
14
14
|
name: string;
|
|
15
15
|
isMiddleware: boolean;
|
|
16
16
|
}
|
|
17
|
-
export declare const inspectRoutes: <E extends Env>(hono: Hono<E
|
|
18
|
-
export declare const showRoutes: <E extends Env>(hono: Hono<E
|
|
19
|
-
export declare const getRouterName: <E extends Env>(app: Hono<E
|
|
17
|
+
export declare const inspectRoutes: <E extends Env>(hono: Hono<E>) => RouteData[];
|
|
18
|
+
export declare const showRoutes: <E extends Env>(hono: Hono<E>, opts?: ShowRoutesOptions) => void;
|
|
19
|
+
export declare const getRouterName: <E extends Env>(app: Hono<E>) => string;
|
|
20
20
|
export {};
|
|
@@ -9,11 +9,36 @@ export interface CreateHandlersInterface<E extends Env, P extends string> {
|
|
|
9
9
|
<I extends Input = {}, R extends HandlerResponse<any> = any>(handler1: H<E, P, I, R>): [
|
|
10
10
|
H<E, P, I, R>
|
|
11
11
|
];
|
|
12
|
-
<I extends Input = {}, I2 extends Input = I, R extends HandlerResponse<any> = any>(handler1: H<E, P, I, R>, handler2: H<E, P, I2, R>): [
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
<I extends Input = {}, I2 extends Input = I, I3 extends Input = I & I2,
|
|
12
|
+
<I extends Input = {}, I2 extends Input = I, R extends HandlerResponse<any> = any>(handler1: H<E, P, I, R>, handler2: H<E, P, I2, R>): [
|
|
13
|
+
H<E, P, I, R>,
|
|
14
|
+
H<E, P, I2, R>
|
|
15
|
+
];
|
|
16
|
+
<I extends Input = {}, I2 extends Input = I, I3 extends Input = I & I2, R extends HandlerResponse<any> = any>(handler1: H<E, P, I, R>, handler2: H<E, P, I2, R>, handler3: H<E, P, I3, R>): [
|
|
17
|
+
H<E, P, I, R>,
|
|
18
|
+
H<E, P, I2, R>,
|
|
19
|
+
H<E, P, I3, R>
|
|
20
|
+
];
|
|
21
|
+
<I extends Input = {}, I2 extends Input = I, I3 extends Input = I & I2, I4 extends Input = I & I2 & I3, R extends HandlerResponse<any> = any>(handler1: H<E, P, I, R>, handler2: H<E, P, I2, R>, handler3: H<E, P, I3, R>, handler4: H<E, P, I4, R>): [
|
|
22
|
+
H<E, P, I, R>,
|
|
23
|
+
H<E, P, I2, R>,
|
|
24
|
+
H<E, P, I3, R>,
|
|
25
|
+
H<E, P, I4, R>
|
|
26
|
+
];
|
|
27
|
+
<I extends Input = {}, I2 extends Input = I, I3 extends Input = I & I2, I4 extends Input = I & I2 & I3, I5 extends Input = I & I2 & I3 & I4, R extends HandlerResponse<any> = any>(handler1: H<E, P, I, R>, handler2: H<E, P, I2, R>, handler3: H<E, P, I3, R>, handler4: H<E, P, I4, R>, handler5: H<E, P, I5, R>): [
|
|
28
|
+
H<E, P, I, R>,
|
|
29
|
+
H<E, P, I2, R>,
|
|
30
|
+
H<E, P, I3, R>,
|
|
31
|
+
H<E, P, I4, R>,
|
|
32
|
+
H<E, P, I5, R>
|
|
33
|
+
];
|
|
34
|
+
<I extends Input = {}, I2 extends Input = I, I3 extends Input = I & I2, I4 extends Input = I & I2 & I3, I5 extends Input = I & I2 & I3 & I4, I6 extends Input = I & I2 & I3 & I4 & I5, R extends HandlerResponse<any> = any>(handler1: H<E, P, I, R>, handler2: H<E, P, I2, R>, handler3: H<E, P, I3, R>, handler4: H<E, P, I4, R>, handler5: H<E, P, I5, R>, handler6: H<E, P, I6, R>): [
|
|
35
|
+
H<E, P, I, R>,
|
|
36
|
+
H<E, P, I2, R>,
|
|
37
|
+
H<E, P, I3, R>,
|
|
38
|
+
H<E, P, I4, R>,
|
|
39
|
+
H<E, P, I5, R>,
|
|
40
|
+
H<E, P, I6, R>
|
|
41
|
+
];
|
|
17
42
|
<I extends Input = {}, I2 extends Input = I, I3 extends Input = I & I2, I4 extends Input = I & I2 & I3, I5 extends Input = I & I2 & I3 & I4, I6 extends Input = I & I2 & I3 & I4 & I5, I7 extends Input = I & I2 & I3 & I4 & I5 & I6, R extends HandlerResponse<any> = any>(handler1: H<E, P, I, R>, handler2: H<E, P, I2, R>, handler3: H<E, P, I3, R>, handler4: H<E, P, I4, R>, handler5: H<E, P, I5, R>, handler6: H<E, P, I6, R>, handler7: H<E, P, I7, R>): [
|
|
18
43
|
H<E, P, I, R>,
|
|
19
44
|
H<E, P, I2, R>,
|
|
@@ -58,7 +83,6 @@ export interface CreateHandlersInterface<E extends Env, P extends string> {
|
|
|
58
83
|
];
|
|
59
84
|
}
|
|
60
85
|
export declare class Factory<E extends Env = any, P extends string = any> {
|
|
61
|
-
private initApp?;
|
|
62
86
|
constructor(init?: {
|
|
63
87
|
initApp?: InitApp<E>;
|
|
64
88
|
});
|
|
@@ -67,7 +91,7 @@ export declare class Factory<E extends Env = any, P extends string = any> {
|
|
|
67
91
|
createHandlers: CreateHandlersInterface<E, P>;
|
|
68
92
|
}
|
|
69
93
|
export declare const createFactory: <E extends Env = any, P extends string = any>(init?: {
|
|
70
|
-
initApp?: InitApp<E
|
|
71
|
-
}
|
|
94
|
+
initApp?: InitApp<E>;
|
|
95
|
+
}) => Factory<E, P>;
|
|
72
96
|
export declare const createMiddleware: <E extends Env = any, P extends string = string, I extends Input = {}>(middleware: MiddlewareHandler<E, P, I>) => MiddlewareHandler<E, P, I>;
|
|
73
97
|
export {};
|
|
@@ -64,7 +64,7 @@ export interface ToSSGInterface {
|
|
|
64
64
|
* `ToSSGAdaptorInterface` is an experimental feature.
|
|
65
65
|
* The API might be changed.
|
|
66
66
|
*/
|
|
67
|
-
export interface ToSSGAdaptorInterface<E extends Env = Env, S extends Schema = {}, BasePath extends string =
|
|
67
|
+
export interface ToSSGAdaptorInterface<E extends Env = Env, S extends Schema = {}, BasePath extends string = "/"> {
|
|
68
68
|
(app: Hono<E, S, BasePath>, options?: ToSSGOptions): Promise<ToSSGResult>;
|
|
69
69
|
}
|
|
70
70
|
/**
|
|
@@ -10,5 +10,5 @@ export declare const joinPaths: (...paths: string[]) => string;
|
|
|
10
10
|
interface FilterStaticGenerateRouteData {
|
|
11
11
|
path: string;
|
|
12
12
|
}
|
|
13
|
-
export declare const filterStaticGenerateRoutes: <E extends Env>(hono: Hono<E
|
|
13
|
+
export declare const filterStaticGenerateRoutes: <E extends Env>(hono: Hono<E>) => FilterStaticGenerateRouteData[];
|
|
14
14
|
export {};
|
|
@@ -10,4 +10,4 @@ export declare class SSEStreamingApi extends StreamingApi {
|
|
|
10
10
|
constructor(writable: WritableStream, readable: ReadableStream);
|
|
11
11
|
writeSSE(message: SSEMessage): Promise<void>;
|
|
12
12
|
}
|
|
13
|
-
export declare const streamSSE: (c: Context, cb: (stream: SSEStreamingApi) => Promise<void>, onError?: (
|
|
13
|
+
export declare const streamSSE: (c: Context, cb: (stream: SSEStreamingApi) => Promise<void>, onError?: (e: Error, stream: SSEStreamingApi) => Promise<void>) => Response;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { Context } from '../../context';
|
|
2
2
|
import { StreamingApi } from '../../utils/stream';
|
|
3
|
-
export declare const stream: (c: Context, cb: (stream: StreamingApi) => Promise<void>, onError?: (
|
|
3
|
+
export declare const stream: (c: Context, cb: (stream: StreamingApi) => Promise<void>, onError?: (e: Error, stream: StreamingApi) => Promise<void>) => Response;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { Context } from '../../context';
|
|
2
2
|
import type { StreamingApi } from '../../utils/stream';
|
|
3
|
-
export declare const streamText: (c: Context, cb: (stream: StreamingApi) => Promise<void>, onError?: (
|
|
3
|
+
export declare const streamText: (c: Context, cb: (stream: StreamingApi) => Promise<void>, onError?: (e: Error, stream: StreamingApi) => Promise<void>) => Response;
|
|
@@ -8,5 +8,5 @@ import type { Hono } from '../../hono';
|
|
|
8
8
|
import type { Schema } from '../../types';
|
|
9
9
|
import type { UnionToIntersection } from '../../utils/types';
|
|
10
10
|
type ExtractEnv<T> = T extends Hono<infer E, Schema, string> ? E : never;
|
|
11
|
-
export declare const testClient: <T extends Hono<any, Schema, string>>(app: T, Env?:
|
|
11
|
+
export declare const testClient: <T extends Hono<any, Schema, string>>(app: T, Env?: ExtractEnv<T>["Bindings"] | {}, executionCtx?: ExecutionContext) => UnionToIntersection<Client<T>>;
|
|
12
12
|
export {};
|
|
@@ -17,7 +17,7 @@ export interface WSEvents<T = unknown> {
|
|
|
17
17
|
* Upgrade WebSocket Type
|
|
18
18
|
*/
|
|
19
19
|
export type UpgradeWebSocket<T = unknown, U = any> = (createEvents: (c: Context) => WSEvents<T> | Promise<WSEvents<T>>, options?: U) => MiddlewareHandler<any, string, {
|
|
20
|
-
outputFormat:
|
|
20
|
+
outputFormat: "ws";
|
|
21
21
|
}>;
|
|
22
22
|
export type WSReadyState = 0 | 1 | 2 | 3;
|
|
23
23
|
export type WSContext<T = unknown> = {
|