hono 4.2.8 → 4.3.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 +0 -13
- package/dist/adapter/deno/serve-static.js +1 -1
- package/dist/cjs/adapter/deno/serve-static.js +1 -1
- package/dist/cjs/client/client.js +2 -1
- package/dist/cjs/context.js +4 -7
- package/dist/cjs/helper/cookie/index.js +2 -0
- package/dist/cjs/helper/factory/index.js +13 -1
- package/dist/cjs/jsx/base.js +26 -14
- package/dist/cjs/jsx/children.js +45 -0
- package/dist/cjs/jsx/constants.js +3 -0
- package/dist/cjs/jsx/dom/context.js +22 -11
- package/dist/cjs/jsx/dom/css.js +6 -4
- package/dist/cjs/jsx/dom/index.js +35 -4
- package/dist/cjs/jsx/dom/jsx-dev-runtime.js +20 -13
- package/dist/cjs/jsx/dom/render.js +110 -48
- package/dist/cjs/jsx/dom/utils.js +33 -0
- package/dist/cjs/jsx/hooks/index.js +41 -1
- package/dist/cjs/jsx/index.js +17 -1
- package/dist/cjs/jsx/jsx-dev-runtime.js +0 -1
- package/dist/cjs/jsx/utils.js +12 -2
- package/dist/cjs/middleware/bearer-auth/index.js +2 -1
- package/dist/cjs/middleware/secure-headers/index.js +58 -8
- package/dist/cjs/middleware/serve-static/index.js +5 -2
- package/dist/cjs/middleware/timing/index.js +3 -2
- package/dist/cjs/utils/mime.js +4 -2
- package/dist/client/client.js +2 -1
- package/dist/context.js +4 -7
- package/dist/helper/cookie/index.js +2 -0
- package/dist/helper/factory/index.js +13 -1
- package/dist/jsx/base.js +27 -15
- package/dist/jsx/children.js +21 -0
- package/dist/jsx/constants.js +2 -0
- package/dist/jsx/dom/context.js +22 -11
- package/dist/jsx/dom/css.js +6 -4
- package/dist/jsx/dom/index.js +31 -5
- package/dist/jsx/dom/jsx-dev-runtime.js +20 -13
- package/dist/jsx/dom/render.js +109 -49
- package/dist/jsx/dom/utils.js +10 -0
- package/dist/jsx/hooks/index.js +37 -1
- package/dist/jsx/index.js +17 -2
- package/dist/jsx/jsx-dev-runtime.js +0 -1
- package/dist/jsx/utils.js +10 -1
- package/dist/middleware/bearer-auth/index.js +2 -1
- package/dist/middleware/secure-headers/index.js +57 -8
- package/dist/middleware/serve-static/index.js +5 -2
- package/dist/middleware/timing/index.js +3 -2
- package/dist/types/adapter/cloudflare-workers/serve-static.d.ts +6 -0
- package/dist/types/client/types.d.ts +44 -20
- package/dist/types/context.d.ts +6 -6
- package/dist/types/helper/cookie/index.d.ts +1 -1
- package/dist/types/helper/factory/index.d.ts +15 -1
- package/dist/types/helper/websocket/index.d.ts +1 -4
- package/dist/types/jsx/base.d.ts +10 -3
- package/dist/types/jsx/children.d.ts +9 -0
- package/dist/types/jsx/constants.d.ts +1 -0
- package/dist/types/jsx/dom/context.d.ts +1 -10
- package/dist/types/jsx/dom/index.d.ts +31 -11
- package/dist/types/jsx/dom/jsx-dev-runtime.d.ts +3 -13
- package/dist/types/jsx/dom/render.d.ts +6 -4
- package/dist/types/jsx/dom/utils.d.ts +1 -0
- package/dist/types/jsx/hooks/index.d.ts +6 -0
- package/dist/types/jsx/index.d.ts +18 -3
- package/dist/types/jsx/types.d.ts +24 -1
- package/dist/types/jsx/utils.d.ts +1 -0
- package/dist/types/middleware/bearer-auth/index.d.ts +2 -0
- package/dist/types/middleware/secure-headers/index.d.ts +30 -21
- package/dist/types/middleware/serve-static/index.d.ts +2 -2
- package/dist/types/middleware/timing/index.d.ts +1 -1
- package/dist/types/request.d.ts +3 -2
- package/dist/types/types.d.ts +76 -63
- package/dist/types/utils/mime.d.ts +2 -0
- package/dist/types/utils/types.d.ts +3 -0
- package/dist/utils/mime.js +2 -1
- package/package.json +9 -1
|
@@ -1,20 +1,26 @@
|
|
|
1
|
-
import type { UpgradedWebSocketResponseInputJSONType } from '../helper/websocket';
|
|
2
1
|
import type { Hono } from '../hono';
|
|
3
|
-
import type { Schema } from '../types';
|
|
2
|
+
import type { Endpoint, ResponseFormat, Schema } from '../types';
|
|
3
|
+
import type { StatusCode, SuccessStatusCode } from '../utils/http-status';
|
|
4
4
|
import type { HasRequiredKeys } from '../utils/types';
|
|
5
5
|
type HonoRequest = (typeof Hono.prototype)['request'];
|
|
6
|
-
export type ClientRequestOptions<T = unknown> =
|
|
7
|
-
headers?: Record<string, string> | (() => Record<string, string> | Promise<Record<string, string>>);
|
|
6
|
+
export type ClientRequestOptions<T = unknown> = {
|
|
8
7
|
fetch?: typeof fetch | HonoRequest;
|
|
8
|
+
/**
|
|
9
|
+
* Standard `RequestInit`, caution that this take highest priority
|
|
10
|
+
* and could be used to overwrite things that Hono sets for you, like `body | method | headers`.
|
|
11
|
+
*
|
|
12
|
+
* If you want to add some headers, use in `headers` instead of `init`
|
|
13
|
+
*/
|
|
14
|
+
init?: RequestInit;
|
|
15
|
+
} & (keyof T extends never ? {
|
|
16
|
+
headers?: Record<string, string> | (() => Record<string, string> | Promise<Record<string, string>>);
|
|
9
17
|
} : {
|
|
10
18
|
headers: T | (() => T | Promise<T>);
|
|
11
|
-
|
|
12
|
-
};
|
|
19
|
+
});
|
|
13
20
|
export type ClientRequest<S extends Schema> = {
|
|
14
|
-
[M in keyof S]: S[M] extends {
|
|
21
|
+
[M in keyof S]: S[M] extends Endpoint & {
|
|
15
22
|
input: infer R;
|
|
16
|
-
|
|
17
|
-
} ? R extends object ? HasRequiredKeys<R> extends true ? (args: R, options?: ClientRequestOptions) => Promise<ClientResponse<O>> : (args?: R, options?: ClientRequestOptions) => Promise<ClientResponse<O>> : never : never;
|
|
23
|
+
} ? R extends object ? HasRequiredKeys<R> extends true ? (args: R, options?: ClientRequestOptions) => Promise<ClientResponseOfEndpoint<S[M]>> : (args?: R, options?: ClientRequestOptions) => Promise<ClientResponseOfEndpoint<S[M]>> : never : never;
|
|
18
24
|
} & {
|
|
19
25
|
$url: (arg?: S[keyof S] extends {
|
|
20
26
|
input: infer R;
|
|
@@ -24,35 +30,53 @@ export type ClientRequest<S extends Schema> = {
|
|
|
24
30
|
param: P;
|
|
25
31
|
} : {} : {}) => URL;
|
|
26
32
|
} & (S['$get'] extends {
|
|
27
|
-
|
|
28
|
-
json: UpgradedWebSocketResponseInputJSONType;
|
|
29
|
-
};
|
|
33
|
+
outputFormat: 'ws';
|
|
30
34
|
} ? S['$get'] extends {
|
|
31
35
|
input: infer I;
|
|
32
36
|
} ? {
|
|
33
|
-
$ws: (args?:
|
|
37
|
+
$ws: (args?: I) => WebSocket;
|
|
34
38
|
} : {} : {});
|
|
35
39
|
type BlankRecordToNever<T> = T extends any ? T extends null ? null : keyof T extends never ? never : T : never;
|
|
36
|
-
|
|
40
|
+
type ClientResponseOfEndpoint<T extends Endpoint = Endpoint> = T extends {
|
|
41
|
+
output: infer O;
|
|
42
|
+
outputFormat: infer F;
|
|
43
|
+
status: infer S;
|
|
44
|
+
} ? ClientResponse<O, S extends number ? S : never, F extends ResponseFormat ? F : never> : never;
|
|
45
|
+
export interface ClientResponse<T, U extends number = StatusCode, F extends ResponseFormat = ResponseFormat> extends globalThis.Response {
|
|
37
46
|
readonly body: ReadableStream | null;
|
|
38
47
|
readonly bodyUsed: boolean;
|
|
39
|
-
ok: boolean;
|
|
40
|
-
status:
|
|
48
|
+
ok: U extends SuccessStatusCode ? true : U extends Exclude<StatusCode, SuccessStatusCode> ? false : boolean;
|
|
49
|
+
status: U;
|
|
41
50
|
statusText: string;
|
|
42
51
|
headers: Headers;
|
|
43
52
|
url: string;
|
|
44
53
|
redirect(url: string, status: number): Response;
|
|
45
54
|
clone(): Response;
|
|
46
|
-
json(): Promise<BlankRecordToNever<T
|
|
47
|
-
text(): Promise<string>;
|
|
55
|
+
json(): F extends 'text' ? Promise<never> : F extends 'json' ? Promise<BlankRecordToNever<T>> : Promise<unknown>;
|
|
56
|
+
text(): F extends 'text' ? (T extends string ? Promise<T> : Promise<never>) : Promise<string>;
|
|
48
57
|
blob(): Promise<Blob>;
|
|
49
58
|
formData(): Promise<FormData>;
|
|
50
59
|
arrayBuffer(): Promise<ArrayBuffer>;
|
|
51
60
|
}
|
|
52
61
|
export interface Response extends ClientResponse<unknown> {
|
|
53
62
|
}
|
|
54
|
-
export type Fetch<T> = (args?: InferRequestType<T>, opt?: ClientRequestOptions) => Promise<
|
|
55
|
-
|
|
63
|
+
export type Fetch<T> = (args?: InferRequestType<T>, opt?: ClientRequestOptions) => Promise<ClientResponseOfEndpoint<InferEndpointType<T>>>;
|
|
64
|
+
type InferEndpointType<T> = T extends (args: infer R, options: any | undefined) => Promise<infer U> ? U extends ClientResponse<infer O, infer S, infer F> ? {
|
|
65
|
+
input: NonNullable<R>;
|
|
66
|
+
output: O;
|
|
67
|
+
outputFormat: F;
|
|
68
|
+
status: S;
|
|
69
|
+
} extends Endpoint ? {
|
|
70
|
+
input: NonNullable<R>;
|
|
71
|
+
output: O;
|
|
72
|
+
outputFormat: F;
|
|
73
|
+
status: S;
|
|
74
|
+
} : never : never : never;
|
|
75
|
+
export type InferResponseType<T, U extends StatusCode = StatusCode> = InferResponseTypeFromEndpoint<InferEndpointType<T>, U>;
|
|
76
|
+
type InferResponseTypeFromEndpoint<T extends Endpoint, U extends StatusCode> = T extends {
|
|
77
|
+
output: infer O;
|
|
78
|
+
status: infer S;
|
|
79
|
+
} ? S extends U ? O : never : never;
|
|
56
80
|
export type InferRequestType<T> = T extends (args: infer R, options: any | undefined) => Promise<ClientResponse<unknown>> ? NonNullable<R> : never;
|
|
57
81
|
export type InferRequestOptionsType<T> = T extends (args: any, options: infer R) => Promise<ClientResponse<unknown>> ? NonNullable<R> : never;
|
|
58
82
|
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}` ? {
|
package/dist/types/context.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { HonoRequest } from './request';
|
|
2
2
|
import type { Env, FetchEventLike, NotFoundHandler, Input, TypedResponse } from './types';
|
|
3
3
|
import type { RedirectStatusCode, StatusCode } from './utils/http-status';
|
|
4
|
-
import type { JSONValue,
|
|
4
|
+
import type { JSONValue, JSONParsed, IsAny, Simplify } from './utils/types';
|
|
5
5
|
type HeaderRecord = Record<string, string | string[]>;
|
|
6
|
-
type Data = string | ArrayBuffer | ReadableStream;
|
|
6
|
+
export type Data = string | ArrayBuffer | ReadableStream;
|
|
7
7
|
export interface ExecutionContext {
|
|
8
8
|
waitUntil(promise: Promise<unknown>): void;
|
|
9
9
|
passThroughOnException(): void;
|
|
@@ -33,12 +33,12 @@ interface NewResponse {
|
|
|
33
33
|
interface BodyRespond extends NewResponse {
|
|
34
34
|
}
|
|
35
35
|
interface TextRespond {
|
|
36
|
-
(text:
|
|
37
|
-
(text:
|
|
36
|
+
<T extends string, U extends StatusCode>(text: T, status?: U, headers?: HeaderRecord): Response & TypedResponse<T, U, 'text'>;
|
|
37
|
+
<T extends string, U extends StatusCode>(text: T, init?: ResponseInit): Response & TypedResponse<T, U, 'text'>;
|
|
38
38
|
}
|
|
39
39
|
interface JSONRespond {
|
|
40
|
-
<T
|
|
41
|
-
<T>(object:
|
|
40
|
+
<T extends JSONValue | Simplify<any>, U extends StatusCode>(object: T, status?: U, headers?: HeaderRecord): Response & TypedResponse<Simplify<T> extends JSONValue ? JSONValue extends Simplify<T> ? never : JSONParsed<T> : never, U, 'json'>;
|
|
41
|
+
<T extends JSONValue | Simplify<any>, U extends StatusCode>(object: Simplify<T> extends JSONValue ? T : Simplify<T>, init?: ResponseInit): Response & TypedResponse<Simplify<T> extends JSONValue ? JSONValue extends Simplify<T> ? never : JSONParsed<T> : never, U, 'json'>;
|
|
42
42
|
}
|
|
43
43
|
interface HTMLRespond {
|
|
44
44
|
(html: string | Promise<string>, status?: StatusCode, headers?: HeaderRecord): Response | Promise<Response>;
|
|
@@ -14,5 +14,5 @@ export declare const getCookie: GetCookie;
|
|
|
14
14
|
export declare const getSignedCookie: GetSignedCookie;
|
|
15
15
|
export declare const setCookie: (c: Context, name: string, value: string, opt?: CookieOptions) => void;
|
|
16
16
|
export declare const setSignedCookie: (c: Context, name: string, value: string, secret: string | BufferSource, opt?: CookieOptions) => Promise<void>;
|
|
17
|
-
export declare const deleteCookie: (c: Context, name: string, opt?: CookieOptions) =>
|
|
17
|
+
export declare const deleteCookie: (c: Context, name: string, opt?: CookieOptions) => string | undefined;
|
|
18
18
|
export {};
|
|
@@ -1,5 +1,16 @@
|
|
|
1
|
+
import { Hono } from '../../hono';
|
|
1
2
|
import type { Env, H, HandlerResponse, Input, MiddlewareHandler } from '../../types';
|
|
3
|
+
type InitApp<E extends Env = Env> = (app: Hono<E>) => void;
|
|
2
4
|
export declare class Factory<E extends Env = any, P extends string = any> {
|
|
5
|
+
private initApp?;
|
|
6
|
+
constructor(init?: {
|
|
7
|
+
initApp?: InitApp<E>;
|
|
8
|
+
});
|
|
9
|
+
/**
|
|
10
|
+
* @experimental
|
|
11
|
+
* `createApp` is an experimental feature.
|
|
12
|
+
*/
|
|
13
|
+
createApp: () => Hono<E, import("../../types").BlankSchema, "/">;
|
|
3
14
|
createMiddleware: <I extends Input = {}>(middleware: MiddlewareHandler<E, P, I>) => MiddlewareHandler<E, P, I>;
|
|
4
15
|
createHandlers<I extends Input = {}, R extends HandlerResponse<any> = any>(handler1: H<E, P, I, R>): [H<E, P, I, R>];
|
|
5
16
|
createHandlers<I extends Input = {}, I2 extends Input = I, R extends HandlerResponse<any> = any>(handler1: H<E, P, I, R>, handler2: H<E, P, I2, R>): [H<E, P, I, R>, H<E, P, I2, R>];
|
|
@@ -50,5 +61,8 @@ export declare class Factory<E extends Env = any, P extends string = any> {
|
|
|
50
61
|
H<E, P, I10, R>
|
|
51
62
|
];
|
|
52
63
|
}
|
|
53
|
-
export declare const createFactory: <E extends Env = any, P extends string = any>(
|
|
64
|
+
export declare const createFactory: <E extends Env = any, P extends string = any>(init?: {
|
|
65
|
+
initApp?: InitApp<E> | undefined;
|
|
66
|
+
} | undefined) => Factory<E, P>;
|
|
54
67
|
export declare const createMiddleware: <E extends Env = any, P extends string = any, I extends Input = {}>(middleware: MiddlewareHandler<E, P, I>) => MiddlewareHandler<E, P, I>;
|
|
68
|
+
export {};
|
|
@@ -9,14 +9,11 @@ export interface WSEvents {
|
|
|
9
9
|
onClose?: (evt: CloseEvent, ws: WSContext) => void;
|
|
10
10
|
onError?: (evt: Event, ws: WSContext) => void;
|
|
11
11
|
}
|
|
12
|
-
export type UpgradedWebSocketResponseInputJSONType = '__websocket';
|
|
13
12
|
/**
|
|
14
13
|
* Upgrade WebSocket Type
|
|
15
14
|
*/
|
|
16
15
|
export type UpgradeWebSocket = (createEvents: (c: Context) => WSEvents | Promise<WSEvents>) => MiddlewareHandler<any, string, {
|
|
17
|
-
|
|
18
|
-
json: UpgradedWebSocketResponseInputJSONType;
|
|
19
|
-
};
|
|
16
|
+
outputFormat: 'ws';
|
|
20
17
|
}>;
|
|
21
18
|
export type WSReadyState = 0 | 1 | 2 | 3;
|
|
22
19
|
export type WSContext = {
|
package/dist/types/jsx/base.d.ts
CHANGED
|
@@ -2,7 +2,12 @@ import type { StringBuffer, HtmlEscaped, HtmlEscapedString } from '../utils/html
|
|
|
2
2
|
import type { Context } from './context';
|
|
3
3
|
import type { IntrinsicElements as IntrinsicElementsDefined } from './intrinsic-elements';
|
|
4
4
|
export type Props = Record<string, any>;
|
|
5
|
-
export type FC<
|
|
5
|
+
export type FC<P = Props> = {
|
|
6
|
+
(props: P): HtmlEscapedString | Promise<HtmlEscapedString>;
|
|
7
|
+
defaultProps?: Partial<P> | undefined;
|
|
8
|
+
displayName?: string | undefined;
|
|
9
|
+
};
|
|
10
|
+
export type DOMAttributes = Hono.HTMLAttributes;
|
|
6
11
|
declare global {
|
|
7
12
|
namespace JSX {
|
|
8
13
|
type Element = HtmlEscapedString | Promise<HtmlEscapedString>;
|
|
@@ -24,14 +29,16 @@ export declare class JSXNode implements HtmlEscaped {
|
|
|
24
29
|
isEscaped: true;
|
|
25
30
|
localContexts?: LocalContexts;
|
|
26
31
|
constructor(tag: string | Function, props: Props, children: Child[]);
|
|
32
|
+
get type(): string | Function;
|
|
33
|
+
get ref(): any;
|
|
27
34
|
toString(): string | Promise<string>;
|
|
28
35
|
toStringToBuffer(buffer: StringBuffer): void;
|
|
29
36
|
}
|
|
30
37
|
export declare class JSXFragmentNode extends JSXNode {
|
|
31
38
|
toStringToBuffer(buffer: StringBuffer): void;
|
|
32
39
|
}
|
|
33
|
-
export declare const jsx: (tag: string | Function, props: Props, ...children: (string | HtmlEscapedString)[]) => JSXNode;
|
|
34
|
-
export declare const jsxFn: (tag: string | Function, props: Props, children: (string | HtmlEscapedString)[]) => JSXNode;
|
|
40
|
+
export declare const jsx: (tag: string | Function, props: Props | null, ...children: (string | number | HtmlEscapedString)[]) => JSXNode;
|
|
41
|
+
export declare const jsxFn: (tag: string | Function, props: Props, children: (string | number | HtmlEscapedString)[]) => JSXNode;
|
|
35
42
|
export declare const memo: <T>(component: FC<T>, propsAreEqual?: (prevProps: Readonly<T>, nextProps: Readonly<T>) => boolean) => FC<T>;
|
|
36
43
|
export declare const Fragment: ({ children, }: {
|
|
37
44
|
key?: string | undefined;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Child } from './base';
|
|
2
|
+
export declare const toArray: (children: Child) => Child[];
|
|
3
|
+
export declare const Children: {
|
|
4
|
+
map: (children: Child[], fn: (child: Child, index: number) => Child) => Child[];
|
|
5
|
+
forEach: (children: Child[], fn: (child: Child, index: number) => void) => void;
|
|
6
|
+
count: (children: Child[]) => number;
|
|
7
|
+
only: (_children: Child[]) => Child;
|
|
8
|
+
toArray: (children: Child) => Child[];
|
|
9
|
+
};
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
import type { Child } from '../base';
|
|
2
1
|
import type { Context } from '../context';
|
|
3
|
-
export declare const createContextProviderFunction: <T>(values: T[]) =>
|
|
4
|
-
value: T;
|
|
5
|
-
children: Child[];
|
|
6
|
-
}) => {
|
|
7
|
-
tag: string | Function;
|
|
8
|
-
props: import("../base").Props;
|
|
9
|
-
key: string | undefined;
|
|
10
|
-
children: any[];
|
|
11
|
-
};
|
|
2
|
+
export declare const createContextProviderFunction: <T>(values: T[]) => Function;
|
|
12
3
|
export declare const createContext: <T>(defaultValue: T) => Context<T>;
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import type { Props, Child, JSXNode } from '../base';
|
|
1
|
+
import type { Props, Child, DOMAttributes, JSXNode } from '../base';
|
|
2
2
|
import { memo, isValidElement } from '../base';
|
|
3
|
+
import { Children } from '../children';
|
|
3
4
|
import { useContext } from '../context';
|
|
4
|
-
import { useState, useEffect, useRef, useCallback, use, startTransition, useTransition, useDeferredValue, startViewTransition, useViewTransition, useMemo, useLayoutEffect, useReducer, useId, useDebugValue } from '../hooks';
|
|
5
|
+
import { useState, useEffect, useRef, useCallback, use, startTransition, useTransition, useDeferredValue, startViewTransition, useViewTransition, useMemo, useLayoutEffect, useReducer, useId, useDebugValue, createRef, forwardRef, useImperativeHandle, useSyncExternalStore } from '../hooks';
|
|
5
6
|
import { Suspense, ErrorBoundary } from './components';
|
|
6
7
|
import { createContext } from './context';
|
|
8
|
+
import { Fragment } from './jsx-runtime';
|
|
9
|
+
import { flushSync, createPortal } from './render';
|
|
7
10
|
export { render } from './render';
|
|
8
|
-
declare const createElement: (tag: string | ((props: Props) => JSXNode), props: Props, ...children: Child[]) => JSXNode;
|
|
11
|
+
declare const createElement: (tag: string | ((props: Props) => JSXNode), props: Props | null, ...children: Child[]) => JSXNode;
|
|
9
12
|
declare const cloneElement: <T extends JSXNode | JSX.Element>(element: T, props: Props, ...children: Child[]) => T;
|
|
10
|
-
export { createElement as jsx, useState, useEffect, useRef, useCallback, use, startTransition, useTransition, useDeferredValue, startViewTransition, useViewTransition, useMemo, useLayoutEffect, useReducer, useId, useDebugValue, Suspense, ErrorBoundary, createContext, useContext, memo, isValidElement, createElement, cloneElement, };
|
|
13
|
+
export { createElement as jsx, useState, useEffect, useRef, useCallback, use, startTransition, useTransition, useDeferredValue, startViewTransition, useViewTransition, useMemo, useLayoutEffect, useReducer, useId, useDebugValue, createRef, forwardRef, useImperativeHandle, useSyncExternalStore, Suspense, ErrorBoundary, createContext, useContext, memo, isValidElement, createElement, cloneElement, Children, Fragment, DOMAttributes, flushSync, createPortal, };
|
|
11
14
|
declare const _default: {
|
|
12
15
|
useState: {
|
|
13
16
|
<T>(initialState: T | (() => T)): [T, (newState: T | ((currentState: T) => T)) => void];
|
|
@@ -27,20 +30,37 @@ declare const _default: {
|
|
|
27
30
|
useReducer: <T_7, A>(reducer: (state: T_7, action: A) => T_7, initialArg: T_7, init?: ((initialState: T_7) => T_7) | undefined) => [T_7, (action: A) => void];
|
|
28
31
|
useId: () => string;
|
|
29
32
|
useDebugValue: (_value: unknown, _formatter?: ((value: unknown) => string) | undefined) => void;
|
|
30
|
-
|
|
33
|
+
createRef: <T_8>() => import("../hooks").RefObject<T_8>;
|
|
34
|
+
forwardRef: <T_9, P = {}>(Component: (props: P, ref: import("../hooks").RefObject<T_9>) => JSX.Element) => (props: P & {
|
|
35
|
+
ref: import("../hooks").RefObject<T_9>;
|
|
36
|
+
}) => JSX.Element;
|
|
37
|
+
useImperativeHandle: <T_10>(ref: import("../hooks").RefObject<T_10>, createHandle: () => T_10, deps: readonly unknown[]) => void;
|
|
38
|
+
useSyncExternalStore: <T_11>(subscribe: (callback: (value: T_11) => void) => () => void, getSnapshot: () => T_11, getServerSnapshot?: (() => T_11) | undefined) => T_11;
|
|
39
|
+
Suspense: import("../base").FC<import("../types").PropsWithChildren<{
|
|
31
40
|
fallback: any;
|
|
32
41
|
}>>;
|
|
33
|
-
ErrorBoundary: import("../base").FC<import("
|
|
42
|
+
ErrorBoundary: import("../base").FC<import("../types").PropsWithChildren<{
|
|
34
43
|
fallback?: Child;
|
|
35
44
|
fallbackRender?: import("../components").FallbackRender | undefined;
|
|
36
45
|
onError?: import("../components").ErrorHandler | undefined;
|
|
37
46
|
}>>;
|
|
38
|
-
createContext: <
|
|
39
|
-
useContext: <
|
|
40
|
-
memo: <
|
|
47
|
+
createContext: <T_12>(defaultValue: T_12) => import("../context").Context<T_12>;
|
|
48
|
+
useContext: <T_13>(context: import("../context").Context<T_13>) => T_13;
|
|
49
|
+
memo: <T_14>(component: import("../base").FC<T_14>, propsAreEqual?: (prevProps: Readonly<T_14>, nextProps: Readonly<T_14>) => boolean) => import("../base").FC<T_14>;
|
|
41
50
|
isValidElement: (element: unknown) => element is JSXNode;
|
|
42
|
-
createElement: (tag: string | ((props: Props) => JSXNode), props: Props, ...children: Child[]) => JSXNode;
|
|
43
|
-
cloneElement: <
|
|
51
|
+
createElement: (tag: string | ((props: Props) => JSXNode), props: Props | null, ...children: Child[]) => JSXNode;
|
|
52
|
+
cloneElement: <T_15 extends JSXNode | JSX.Element>(element: T_15, props: Props, ...children: Child[]) => T_15;
|
|
53
|
+
Children: {
|
|
54
|
+
map: (children: Child[], fn: (child: Child, index: number) => Child) => Child[];
|
|
55
|
+
forEach: (children: Child[], fn: (child: Child, index: number) => void) => void;
|
|
56
|
+
count: (children: Child[]) => number;
|
|
57
|
+
only: (_children: Child[]) => Child;
|
|
58
|
+
toArray: (children: Child) => Child[];
|
|
59
|
+
};
|
|
60
|
+
Fragment: (props: Record<string, unknown>) => JSXNode;
|
|
61
|
+
flushSync: (callback: () => void) => void;
|
|
62
|
+
createPortal: (children: Child, container: HTMLElement, key?: string | undefined) => Child;
|
|
44
63
|
};
|
|
45
64
|
export default _default;
|
|
46
65
|
export type { Context } from '../context';
|
|
66
|
+
export * from '../types';
|
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
import type { Props } from '../base';
|
|
2
|
-
export declare const jsxDEV: (tag: string | Function, props: Props, key?: string) =>
|
|
3
|
-
|
|
4
|
-
props: Props;
|
|
5
|
-
key: string | undefined;
|
|
6
|
-
children: any[];
|
|
7
|
-
};
|
|
8
|
-
export declare const Fragment: (props: Record<string, unknown>) => {
|
|
9
|
-
tag: string | Function;
|
|
10
|
-
props: Props;
|
|
11
|
-
key: string | undefined;
|
|
12
|
-
children: any[];
|
|
13
|
-
};
|
|
1
|
+
import type { Props, JSXNode } from '../base';
|
|
2
|
+
export declare const jsxDEV: (tag: string | Function, props: Props, key?: string) => JSXNode;
|
|
3
|
+
export declare const Fragment: (props: Record<string, unknown>) => JSXNode;
|
|
@@ -27,10 +27,10 @@ export type NodeObject = {
|
|
|
27
27
|
any[][]
|
|
28
28
|
];
|
|
29
29
|
} & JSXNode;
|
|
30
|
-
type NodeString =
|
|
31
|
-
string
|
|
32
|
-
boolean
|
|
33
|
-
|
|
30
|
+
type NodeString = {
|
|
31
|
+
t: string;
|
|
32
|
+
d: boolean;
|
|
33
|
+
} & {
|
|
34
34
|
e?: Text;
|
|
35
35
|
vC: undefined;
|
|
36
36
|
nN: undefined;
|
|
@@ -50,4 +50,6 @@ export declare const buildDataStack: [Context, Node][];
|
|
|
50
50
|
export declare const build: (context: Context, node: NodeObject, topLevelErrorHandlerNode: NodeObject | undefined, children?: Child[]) => void;
|
|
51
51
|
export declare const update: (context: Context, node: NodeObject) => Promise<NodeObject | undefined>;
|
|
52
52
|
export declare const render: (jsxNode: unknown, container: Container) => void;
|
|
53
|
+
export declare const flushSync: (callback: () => void) => void;
|
|
54
|
+
export declare const createPortal: (children: Child, container: HTMLElement, key?: string) => Child;
|
|
53
55
|
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const setInternalTagFlag: (fn: Function) => Function;
|
|
@@ -31,4 +31,10 @@ export declare const use: <T>(promise: Promise<T>) => T;
|
|
|
31
31
|
export declare const useMemo: <T>(factory: () => T, deps: readonly unknown[]) => T;
|
|
32
32
|
export declare const useId: () => string;
|
|
33
33
|
export declare const useDebugValue: (_value: unknown, _formatter?: ((value: unknown) => string) | undefined) => void;
|
|
34
|
+
export declare const createRef: <T>() => RefObject<T>;
|
|
35
|
+
export declare const forwardRef: <T, P = {}>(Component: (props: P, ref: RefObject<T>) => JSX.Element) => (props: P & {
|
|
36
|
+
ref: RefObject<T>;
|
|
37
|
+
}) => JSX.Element;
|
|
38
|
+
export declare const useImperativeHandle: <T>(ref: RefObject<T>, createHandle: () => T, deps: readonly unknown[]) => void;
|
|
39
|
+
export declare const useSyncExternalStore: <T>(subscribe: (callback: (value: T) => void) => () => void, getSnapshot: () => T, getServerSnapshot?: (() => T) | undefined) => T;
|
|
34
40
|
export {};
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { jsx, memo, Fragment, isValidElement, cloneElement } from './base';
|
|
2
|
+
import type { DOMAttributes } from './base';
|
|
3
|
+
import { Children } from './children';
|
|
2
4
|
import { ErrorBoundary } from './components';
|
|
3
5
|
import { createContext, useContext } from './context';
|
|
4
|
-
import { useState, useEffect, useRef, useCallback, use, startTransition, useTransition, useDeferredValue, startViewTransition, useViewTransition, useMemo, useLayoutEffect, useReducer, useId, useDebugValue } from './hooks';
|
|
6
|
+
import { useState, useEffect, useRef, useCallback, use, startTransition, useTransition, useDeferredValue, startViewTransition, useViewTransition, useMemo, useLayoutEffect, useReducer, useId, useDebugValue, createRef, forwardRef, useImperativeHandle, useSyncExternalStore } from './hooks';
|
|
5
7
|
import { Suspense } from './streaming';
|
|
6
|
-
export { jsx, memo, Fragment, isValidElement, jsx as createElement, cloneElement, ErrorBoundary, createContext, useContext, useState, useEffect, useRef, useCallback, useReducer, useId, useDebugValue, use, startTransition, useTransition, useDeferredValue, startViewTransition, useViewTransition, useMemo, useLayoutEffect, Suspense, };
|
|
8
|
+
export { jsx, memo, Fragment, isValidElement, jsx as createElement, cloneElement, ErrorBoundary, createContext, useContext, useState, useEffect, useRef, useCallback, useReducer, useId, useDebugValue, use, startTransition, useTransition, useDeferredValue, startViewTransition, useViewTransition, useMemo, useLayoutEffect, createRef, forwardRef, useImperativeHandle, useSyncExternalStore, Suspense, Children, DOMAttributes, };
|
|
7
9
|
declare const _default: {
|
|
8
10
|
memo: <T>(component: import("./base").FC<T>, propsAreEqual?: (prevProps: Readonly<T>, nextProps: Readonly<T>) => boolean) => import("./base").FC<T>;
|
|
9
11
|
Fragment: ({ children, }: {
|
|
@@ -11,7 +13,7 @@ declare const _default: {
|
|
|
11
13
|
children?: import("../utils/html").HtmlEscapedString | import("./base").Child;
|
|
12
14
|
}) => import("../utils/html").HtmlEscapedString;
|
|
13
15
|
isValidElement: (element: unknown) => element is import("./base").JSXNode;
|
|
14
|
-
createElement: (tag: string | Function, props: import("./base").Props, ...children: (string | import("../utils/html").HtmlEscapedString)[]) => import("./base").JSXNode;
|
|
16
|
+
createElement: (tag: string | Function, props: import("./base").Props | null, ...children: (string | number | import("../utils/html").HtmlEscapedString)[]) => import("./base").JSXNode;
|
|
15
17
|
cloneElement: <T_1 extends import("./base").JSXNode | JSX.Element>(element: T_1, props: Partial<import("./base").Props>, ...children: import("./base").Child[]) => T_1;
|
|
16
18
|
ErrorBoundary: import("./base").FC<import("./types").PropsWithChildren<{
|
|
17
19
|
fallback?: import("./base").Child;
|
|
@@ -38,9 +40,22 @@ declare const _default: {
|
|
|
38
40
|
useViewTransition: () => [boolean, (callback: () => void) => void];
|
|
39
41
|
useMemo: <T_11>(factory: () => T_11, deps: readonly unknown[]) => T_11;
|
|
40
42
|
useLayoutEffect: (effect: () => void | (() => void), deps?: readonly unknown[] | undefined) => void;
|
|
43
|
+
createRef: <T_12>() => import("./hooks").RefObject<T_12>;
|
|
44
|
+
forwardRef: <T_13, P = {}>(Component: (props: P, ref: import("./hooks").RefObject<T_13>) => JSX.Element) => (props: P & {
|
|
45
|
+
ref: import("./hooks").RefObject<T_13>;
|
|
46
|
+
}) => JSX.Element;
|
|
47
|
+
useImperativeHandle: <T_14>(ref: import("./hooks").RefObject<T_14>, createHandle: () => T_14, deps: readonly unknown[]) => void;
|
|
48
|
+
useSyncExternalStore: <T_15>(subscribe: (callback: (value: T_15) => void) => () => void, getSnapshot: () => T_15, getServerSnapshot?: (() => T_15) | undefined) => T_15;
|
|
41
49
|
Suspense: import("./base").FC<import("./types").PropsWithChildren<{
|
|
42
50
|
fallback: any;
|
|
43
51
|
}>>;
|
|
52
|
+
Children: {
|
|
53
|
+
map: (children: import("./base").Child[], fn: (child: import("./base").Child, index: number) => import("./base").Child) => import("./base").Child[];
|
|
54
|
+
forEach: (children: import("./base").Child[], fn: (child: import("./base").Child, index: number) => void) => void;
|
|
55
|
+
count: (children: import("./base").Child[]) => number;
|
|
56
|
+
only: (_children: import("./base").Child[]) => import("./base").Child;
|
|
57
|
+
toArray: (children: import("./base").Child) => import("./base").Child[];
|
|
58
|
+
};
|
|
44
59
|
};
|
|
45
60
|
export default _default;
|
|
46
61
|
export * from './types';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* All types exported from "hono/jsx" are in this file.
|
|
3
3
|
*/
|
|
4
|
-
import type { Child } from './base';
|
|
4
|
+
import type { Child, JSXNode } from './base';
|
|
5
5
|
export type { Child, JSXNode, FC } from './base';
|
|
6
6
|
export type { RefObject } from './hooks';
|
|
7
7
|
export type { Context } from './context';
|
|
@@ -9,3 +9,26 @@ export type PropsWithChildren<P = unknown> = P & {
|
|
|
9
9
|
children?: Child | undefined;
|
|
10
10
|
};
|
|
11
11
|
export type CSSProperties = Hono.CSSProperties;
|
|
12
|
+
/**
|
|
13
|
+
* React types
|
|
14
|
+
*/
|
|
15
|
+
type ReactElement<P = any, T = string | Function> = JSXNode & {
|
|
16
|
+
type: T;
|
|
17
|
+
props: P;
|
|
18
|
+
key: string | null;
|
|
19
|
+
};
|
|
20
|
+
type ReactNode = ReactElement | string | number | boolean | null | undefined;
|
|
21
|
+
type ComponentClass<P = {}, S = {}> = unknown;
|
|
22
|
+
export type { ReactElement, ReactNode, ComponentClass };
|
|
23
|
+
export type Event = globalThis.Event;
|
|
24
|
+
export type MouseEvent = globalThis.MouseEvent;
|
|
25
|
+
export type KeyboardEvent = globalThis.KeyboardEvent;
|
|
26
|
+
export type FocusEvent = globalThis.FocusEvent;
|
|
27
|
+
export type ClipboardEvent = globalThis.ClipboardEvent;
|
|
28
|
+
export type InputEvent = globalThis.InputEvent;
|
|
29
|
+
export type PointerEvent = globalThis.PointerEvent;
|
|
30
|
+
export type TouchEvent = globalThis.TouchEvent;
|
|
31
|
+
export type WheelEvent = globalThis.WheelEvent;
|
|
32
|
+
export type AnimationEvent = globalThis.AnimationEvent;
|
|
33
|
+
export type TransitionEvent = globalThis.TransitionEvent;
|
|
34
|
+
export type DragEvent = globalThis.DragEvent;
|
|
@@ -4,10 +4,12 @@ type BearerAuthOptions = {
|
|
|
4
4
|
token: string | string[];
|
|
5
5
|
realm?: string;
|
|
6
6
|
prefix?: string;
|
|
7
|
+
headerName?: string;
|
|
7
8
|
hashFunction?: Function;
|
|
8
9
|
} | {
|
|
9
10
|
realm?: string;
|
|
10
11
|
prefix?: string;
|
|
12
|
+
headerName?: string;
|
|
11
13
|
verifyToken: (token: string, c: Context) => boolean | Promise<boolean>;
|
|
12
14
|
hashFunction?: Function;
|
|
13
15
|
};
|
|
@@ -1,27 +1,35 @@
|
|
|
1
|
+
import type { Context } from '../../context';
|
|
1
2
|
import type { MiddlewareHandler } from '../../types';
|
|
3
|
+
declare module '../../context' {
|
|
4
|
+
interface ContextVariableMap {
|
|
5
|
+
secureHeadersNonce?: string;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export type ContentSecurityPolicyOptionHandler = (ctx: Context, directive: string) => string;
|
|
9
|
+
type ContentSecurityPolicyOptionValue = (string | ContentSecurityPolicyOptionHandler)[];
|
|
2
10
|
interface ContentSecurityPolicyOptions {
|
|
3
|
-
defaultSrc?:
|
|
4
|
-
baseUri?:
|
|
5
|
-
childSrc?:
|
|
6
|
-
connectSrc?:
|
|
7
|
-
fontSrc?:
|
|
8
|
-
formAction?:
|
|
9
|
-
frameAncestors?:
|
|
10
|
-
frameSrc?:
|
|
11
|
-
imgSrc?:
|
|
12
|
-
manifestSrc?:
|
|
13
|
-
mediaSrc?:
|
|
14
|
-
objectSrc?:
|
|
11
|
+
defaultSrc?: ContentSecurityPolicyOptionValue;
|
|
12
|
+
baseUri?: ContentSecurityPolicyOptionValue;
|
|
13
|
+
childSrc?: ContentSecurityPolicyOptionValue;
|
|
14
|
+
connectSrc?: ContentSecurityPolicyOptionValue;
|
|
15
|
+
fontSrc?: ContentSecurityPolicyOptionValue;
|
|
16
|
+
formAction?: ContentSecurityPolicyOptionValue;
|
|
17
|
+
frameAncestors?: ContentSecurityPolicyOptionValue;
|
|
18
|
+
frameSrc?: ContentSecurityPolicyOptionValue;
|
|
19
|
+
imgSrc?: ContentSecurityPolicyOptionValue;
|
|
20
|
+
manifestSrc?: ContentSecurityPolicyOptionValue;
|
|
21
|
+
mediaSrc?: ContentSecurityPolicyOptionValue;
|
|
22
|
+
objectSrc?: ContentSecurityPolicyOptionValue;
|
|
15
23
|
reportTo?: string;
|
|
16
|
-
sandbox?:
|
|
17
|
-
scriptSrc?:
|
|
18
|
-
scriptSrcAttr?:
|
|
19
|
-
scriptSrcElem?:
|
|
20
|
-
styleSrc?:
|
|
21
|
-
styleSrcAttr?:
|
|
22
|
-
styleSrcElem?:
|
|
23
|
-
upgradeInsecureRequests?:
|
|
24
|
-
workerSrc?:
|
|
24
|
+
sandbox?: ContentSecurityPolicyOptionValue;
|
|
25
|
+
scriptSrc?: ContentSecurityPolicyOptionValue;
|
|
26
|
+
scriptSrcAttr?: ContentSecurityPolicyOptionValue;
|
|
27
|
+
scriptSrcElem?: ContentSecurityPolicyOptionValue;
|
|
28
|
+
styleSrc?: ContentSecurityPolicyOptionValue;
|
|
29
|
+
styleSrcAttr?: ContentSecurityPolicyOptionValue;
|
|
30
|
+
styleSrcElem?: ContentSecurityPolicyOptionValue;
|
|
31
|
+
upgradeInsecureRequests?: ContentSecurityPolicyOptionValue;
|
|
32
|
+
workerSrc?: ContentSecurityPolicyOptionValue;
|
|
25
33
|
}
|
|
26
34
|
interface ReportToOptions {
|
|
27
35
|
group: string;
|
|
@@ -53,5 +61,6 @@ interface SecureHeadersOptions {
|
|
|
53
61
|
xPermittedCrossDomainPolicies?: overridableHeader;
|
|
54
62
|
xXssProtection?: overridableHeader;
|
|
55
63
|
}
|
|
64
|
+
export declare const NONCE: ContentSecurityPolicyOptionHandler;
|
|
56
65
|
export declare const secureHeaders: (customOptions?: Partial<SecureHeadersOptions>) => MiddlewareHandler;
|
|
57
66
|
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Context } from '../../context';
|
|
1
|
+
import type { Context, Data } from '../../context';
|
|
2
2
|
import type { Env, MiddlewareHandler } from '../../types';
|
|
3
3
|
export type ServeStaticOptions<E extends Env = Env> = {
|
|
4
4
|
root?: string;
|
|
@@ -11,6 +11,6 @@ export type ServeStaticOptions<E extends Env = Env> = {
|
|
|
11
11
|
* This middleware is not directly used by the user. Create a wrapper specifying `getContent()` by the environment such as Deno or Bun.
|
|
12
12
|
*/
|
|
13
13
|
export declare const serveStatic: <E extends Env = Env>(options: ServeStaticOptions<E> & {
|
|
14
|
-
getContent: (path: string) =>
|
|
14
|
+
getContent: (path: string, c: Context<E, any, {}>) => Promise<Data | Response | null>;
|
|
15
15
|
pathResolve?: ((path: string) => string) | undefined;
|
|
16
16
|
}) => MiddlewareHandler;
|
|
@@ -18,7 +18,7 @@ interface TimingOptions {
|
|
|
18
18
|
enabled: boolean | ((c: Context) => boolean);
|
|
19
19
|
totalDescription: string;
|
|
20
20
|
autoEnd: boolean;
|
|
21
|
-
crossOrigin: boolean | string;
|
|
21
|
+
crossOrigin: boolean | string | ((c: Context) => boolean | string);
|
|
22
22
|
}
|
|
23
23
|
export declare const timing: (config?: Partial<TimingOptions>) => MiddlewareHandler;
|
|
24
24
|
interface SetMetric {
|
package/dist/types/request.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Result } from './router';
|
|
2
|
-
import type { Input, InputToDataByTarget, ParamKeys, ParamKeyToRecord, RemoveQuestion,
|
|
2
|
+
import type { Input, InputToDataByTarget, ParamKeys, ParamKeyToRecord, RemoveQuestion, ValidationTargets, RouterRoute } from './types';
|
|
3
3
|
import type { BodyData, ParseBodyOptions } from './utils/body';
|
|
4
4
|
import type { UnionToIntersection } from './utils/types';
|
|
5
5
|
type Body = {
|
|
@@ -51,7 +51,8 @@ export declare class HonoRequest<P extends string = '/', I extends Input['out']
|
|
|
51
51
|
* ```
|
|
52
52
|
* @see https://hono.dev/api/routing#path-parameter
|
|
53
53
|
*/
|
|
54
|
-
param<P2 extends
|
|
54
|
+
param<P2 extends ParamKeys<P> = ParamKeys<P>>(key: P2 extends `${infer _}?` ? never : P2): string;
|
|
55
|
+
param<P2 extends RemoveQuestion<ParamKeys<P>> = RemoveQuestion<ParamKeys<P>>>(key: P2): string | undefined;
|
|
55
56
|
param<P2 extends string = P>(): UnionToIntersection<ParamKeyToRecord<ParamKeys<P2>>>;
|
|
56
57
|
private getDecodedParam;
|
|
57
58
|
private getAllDecodedParams;
|