hono 4.6.5 → 4.6.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/adapter/bun/websocket.js +23 -26
- package/dist/adapter/cloudflare-workers/websocket.js +40 -39
- package/dist/adapter/deno/serve-static.js +4 -2
- package/dist/adapter/deno/websocket.js +7 -8
- package/dist/adapter/vercel/handler.js +2 -2
- package/dist/cjs/adapter/bun/websocket.js +24 -26
- package/dist/cjs/adapter/cloudflare-workers/websocket.js +40 -39
- package/dist/cjs/adapter/deno/serve-static.js +4 -2
- package/dist/cjs/adapter/deno/websocket.js +7 -8
- package/dist/cjs/adapter/vercel/handler.js +2 -2
- package/dist/cjs/client/client.js +10 -16
- package/dist/cjs/client/utils.js +18 -0
- package/dist/cjs/helper/websocket/index.js +43 -2
- package/dist/cjs/middleware/secure-headers/secure-headers.js +6 -5
- package/dist/cjs/router/linear-router/router.js +75 -77
- package/dist/cjs/router/pattern-router/router.js +3 -2
- package/dist/cjs/router/smart-router/router.js +3 -3
- package/dist/cjs/router/trie-router/node.js +9 -12
- package/dist/cjs/router/trie-router/router.js +2 -2
- package/dist/cjs/utils/jwt/jws.js +4 -2
- package/dist/client/client.js +11 -16
- package/dist/client/utils.js +17 -0
- package/dist/helper/websocket/index.js +40 -1
- package/dist/middleware/secure-headers/secure-headers.js +6 -5
- package/dist/router/linear-router/router.js +75 -77
- package/dist/router/pattern-router/router.js +3 -2
- package/dist/router/smart-router/router.js +3 -3
- package/dist/router/trie-router/node.js +9 -12
- package/dist/router/trie-router/router.js +2 -2
- package/dist/types/adapter/bun/websocket.d.ts +9 -1
- package/dist/types/adapter/vercel/handler.d.ts +1 -2
- package/dist/types/client/types.d.ts +9 -0
- package/dist/types/client/utils.d.ts +1 -0
- package/dist/types/helper/websocket/index.d.ts +35 -6
- package/dist/types/middleware/powered-by/index.d.ts +19 -0
- package/dist/types/router/trie-router/node.d.ts +0 -2
- package/dist/utils/jwt/jws.js +4 -2
- package/package.json +1 -1
|
@@ -6,21 +6,18 @@ var Node = class {
|
|
|
6
6
|
children;
|
|
7
7
|
patterns;
|
|
8
8
|
order = 0;
|
|
9
|
-
name;
|
|
10
9
|
params = /* @__PURE__ */ Object.create(null);
|
|
11
10
|
constructor(method, handler, children) {
|
|
12
11
|
this.children = children || /* @__PURE__ */ Object.create(null);
|
|
13
12
|
this.methods = [];
|
|
14
|
-
this.name = "";
|
|
15
13
|
if (method && handler) {
|
|
16
14
|
const m = /* @__PURE__ */ Object.create(null);
|
|
17
|
-
m[method] = { handler, possibleKeys: [], score: 0
|
|
15
|
+
m[method] = { handler, possibleKeys: [], score: 0 };
|
|
18
16
|
this.methods = [m];
|
|
19
17
|
}
|
|
20
18
|
this.patterns = [];
|
|
21
19
|
}
|
|
22
20
|
insert(method, path, handler) {
|
|
23
|
-
this.name = `${method} ${path}`;
|
|
24
21
|
this.order = ++this.order;
|
|
25
22
|
let curNode = this;
|
|
26
23
|
const parts = splitRoutingPath(path);
|
|
@@ -50,7 +47,6 @@ var Node = class {
|
|
|
50
47
|
const handlerSet = {
|
|
51
48
|
handler,
|
|
52
49
|
possibleKeys: possibleKeys.filter((v, i, a) => a.indexOf(v) === i),
|
|
53
|
-
name: this.name,
|
|
54
50
|
score: this.order
|
|
55
51
|
};
|
|
56
52
|
m[method] = handlerSet;
|
|
@@ -65,11 +61,12 @@ var Node = class {
|
|
|
65
61
|
const processedSet = /* @__PURE__ */ Object.create(null);
|
|
66
62
|
if (handlerSet !== void 0) {
|
|
67
63
|
handlerSet.params = /* @__PURE__ */ Object.create(null);
|
|
68
|
-
handlerSet.possibleKeys.
|
|
69
|
-
const
|
|
64
|
+
for (let i2 = 0, len2 = handlerSet.possibleKeys.length; i2 < len2; i2++) {
|
|
65
|
+
const key = handlerSet.possibleKeys[i2];
|
|
66
|
+
const processed = processedSet[handlerSet.score];
|
|
70
67
|
handlerSet.params[key] = params[key] && !processed ? params[key] : nodeParams[key] ?? params[key];
|
|
71
|
-
processedSet[handlerSet.
|
|
72
|
-
}
|
|
68
|
+
processedSet[handlerSet.score] = true;
|
|
69
|
+
}
|
|
73
70
|
handlerSets.push(handlerSet);
|
|
74
71
|
}
|
|
75
72
|
}
|
|
@@ -90,7 +87,7 @@ var Node = class {
|
|
|
90
87
|
const nextNode = node.children[part];
|
|
91
88
|
if (nextNode) {
|
|
92
89
|
nextNode.params = node.params;
|
|
93
|
-
if (isLast
|
|
90
|
+
if (isLast) {
|
|
94
91
|
if (nextNode.children["*"]) {
|
|
95
92
|
handlerSets.push(
|
|
96
93
|
...this.gHSets(nextNode.children["*"], method, node.params, /* @__PURE__ */ Object.create(null))
|
|
@@ -123,10 +120,10 @@ var Node = class {
|
|
|
123
120
|
handlerSets.push(...this.gHSets(child, method, node.params, params));
|
|
124
121
|
continue;
|
|
125
122
|
}
|
|
126
|
-
if (matcher === true || matcher
|
|
123
|
+
if (matcher === true || matcher.test(part)) {
|
|
127
124
|
if (typeof key === "string") {
|
|
128
125
|
params[name] = part;
|
|
129
|
-
if (isLast
|
|
126
|
+
if (isLast) {
|
|
130
127
|
handlerSets.push(...this.gHSets(child, method, params, node.params));
|
|
131
128
|
if (child.children["*"]) {
|
|
132
129
|
handlerSets.push(...this.gHSets(child.children["*"], method, params, node.params));
|
|
@@ -10,8 +10,8 @@ var TrieRouter = class {
|
|
|
10
10
|
add(method, path, handler) {
|
|
11
11
|
const results = checkOptionalParameter(path);
|
|
12
12
|
if (results) {
|
|
13
|
-
for (
|
|
14
|
-
this.node.insert(method,
|
|
13
|
+
for (let i = 0, len = results.length; i < len; i++) {
|
|
14
|
+
this.node.insert(method, results[i], handler);
|
|
15
15
|
}
|
|
16
16
|
return;
|
|
17
17
|
}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import type { UpgradeWebSocket } from '../../helper/websocket';
|
|
2
|
-
|
|
2
|
+
import { WSContext } from '../../helper/websocket';
|
|
3
|
+
/**
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
6
|
+
export interface BunServerWebSocket<T> {
|
|
3
7
|
send(data: string | ArrayBufferLike, compress?: boolean): void;
|
|
4
8
|
close(code?: number, reason?: string): void;
|
|
5
9
|
data: T;
|
|
@@ -19,5 +23,9 @@ export interface BunWebSocketData {
|
|
|
19
23
|
url: URL;
|
|
20
24
|
protocol: string;
|
|
21
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
export declare const createWSContext: (ws: BunServerWebSocket<BunWebSocketData>) => WSContext;
|
|
22
30
|
export declare const createBunWebSocket: <T>() => CreateWebSocket<T>;
|
|
23
31
|
export {};
|
|
@@ -1,3 +1,2 @@
|
|
|
1
1
|
import type { Hono } from '../../hono';
|
|
2
|
-
|
|
3
|
-
export declare const handle: (app: Hono<any, any, any>) => (req: Request, requestContext: FetchEventLike) => Response | Promise<Response>;
|
|
2
|
+
export declare const handle: (app: Hono<any, any, any>) => (req: Request) => Response | Promise<Response>;
|
|
@@ -28,8 +28,17 @@ export type ClientRequest<S extends Schema> = {
|
|
|
28
28
|
input: infer R;
|
|
29
29
|
} ? R extends {
|
|
30
30
|
param: infer P;
|
|
31
|
+
} ? R extends {
|
|
32
|
+
query: infer Q;
|
|
31
33
|
} ? {
|
|
32
34
|
param: P;
|
|
35
|
+
query: Q;
|
|
36
|
+
} : {
|
|
37
|
+
param: P;
|
|
38
|
+
} : R extends {
|
|
39
|
+
query: infer Q;
|
|
40
|
+
} ? {
|
|
41
|
+
query: Q;
|
|
33
42
|
} : {} : {}) => URL;
|
|
34
43
|
} & (S["$get"] extends {
|
|
35
44
|
outputFormat: "ws";
|
|
@@ -1,5 +1,6 @@
|
|
|
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 buildSearchParams: (query: Record<string, string | string[]>) => URLSearchParams;
|
|
3
4
|
export declare const replaceUrlProtocol: (urlString: string, protocol: "ws" | "http") => string;
|
|
4
5
|
export declare const removeIndexString: (urlSting: string) => string;
|
|
5
6
|
export declare function deepMerge<T>(target: T, source: Record<string, unknown>): T;
|
|
@@ -19,17 +19,46 @@ export interface WSEvents<T = unknown> {
|
|
|
19
19
|
export type UpgradeWebSocket<T = unknown, U = any> = (createEvents: (c: Context) => WSEvents<T> | Promise<WSEvents<T>>, options?: U) => MiddlewareHandler<any, string, {
|
|
20
20
|
outputFormat: "ws";
|
|
21
21
|
}>;
|
|
22
|
+
/**
|
|
23
|
+
* ReadyState for WebSocket
|
|
24
|
+
*/
|
|
22
25
|
export type WSReadyState = 0 | 1 | 2 | 3;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
/**
|
|
27
|
+
* An argument for WSContext class
|
|
28
|
+
*/
|
|
29
|
+
export interface WSContestInit<T = unknown> {
|
|
30
|
+
send(data: string | ArrayBuffer, options: SendOptions): void;
|
|
31
|
+
close(code?: number, reason?: string): void;
|
|
27
32
|
raw?: T;
|
|
28
|
-
binaryType: BinaryType;
|
|
29
33
|
readyState: WSReadyState;
|
|
34
|
+
url?: string | URL | null;
|
|
35
|
+
protocol?: string | null;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Options for sending message
|
|
39
|
+
*/
|
|
40
|
+
export interface SendOptions {
|
|
41
|
+
compress?: boolean;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* A context for controlling WebSockets
|
|
45
|
+
*/
|
|
46
|
+
export declare class WSContext<T = unknown> {
|
|
47
|
+
constructor(init: WSContestInit<T>);
|
|
48
|
+
send(source: string | ArrayBuffer | Uint8Array, options?: SendOptions): void;
|
|
49
|
+
raw?: T;
|
|
50
|
+
binaryType: BinaryType;
|
|
51
|
+
get readyState(): WSReadyState;
|
|
30
52
|
url: URL | null;
|
|
31
53
|
protocol: string | null;
|
|
32
54
|
close(code?: number, reason?: string): void;
|
|
33
|
-
}
|
|
55
|
+
}
|
|
34
56
|
export type WSMessageReceive = string | Blob | ArrayBufferLike;
|
|
35
57
|
export declare const createWSMessageEvent: (source: WSMessageReceive) => MessageEvent<WSMessageReceive>;
|
|
58
|
+
export interface WebSocketHelperDefineContext {
|
|
59
|
+
}
|
|
60
|
+
export type WebSocketHelperDefineHandler<T, U> = (c: Context, events: WSEvents<T>, options?: U) => Promise<Response | void> | Response | void;
|
|
61
|
+
/**
|
|
62
|
+
* Create a WebSocket adapter/helper
|
|
63
|
+
*/
|
|
64
|
+
export declare const defineWebSocketHelper: <T = unknown, U = any>(handler: WebSocketHelperDefineHandler<T, U>) => UpgradeWebSocket<T, U>;
|
|
@@ -4,7 +4,26 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import type { MiddlewareHandler } from '../../types';
|
|
6
6
|
type PoweredByOptions = {
|
|
7
|
+
/**
|
|
8
|
+
* The value for X-Powered-By header.
|
|
9
|
+
* @default Hono
|
|
10
|
+
*/
|
|
7
11
|
serverName?: string;
|
|
8
12
|
};
|
|
13
|
+
/**
|
|
14
|
+
* Powered By Middleware for Hono.
|
|
15
|
+
*
|
|
16
|
+
* @param options - The options for the Powered By Middleware.
|
|
17
|
+
* @returns {MiddlewareHandler} The middleware handler function.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* import { poweredBy } from 'hono/powered-by'
|
|
22
|
+
*
|
|
23
|
+
* const app = new Hono()
|
|
24
|
+
*
|
|
25
|
+
* app.use(poweredBy()) // With options: poweredBy({ serverName: "My Server" })
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
9
28
|
export declare const poweredBy: (options?: PoweredByOptions) => MiddlewareHandler;
|
|
10
29
|
export {};
|
|
@@ -4,14 +4,12 @@ type HandlerSet<T> = {
|
|
|
4
4
|
handler: T;
|
|
5
5
|
possibleKeys: string[];
|
|
6
6
|
score: number;
|
|
7
|
-
name: string;
|
|
8
7
|
};
|
|
9
8
|
export declare class Node<T> {
|
|
10
9
|
methods: Record<string, HandlerSet<T>>[];
|
|
11
10
|
children: Record<string, Node<T>>;
|
|
12
11
|
patterns: Pattern[];
|
|
13
12
|
order: number;
|
|
14
|
-
name: string;
|
|
15
13
|
params: Record<string, string>;
|
|
16
14
|
constructor(method?: string, handler?: T, children?: Record<string, Node<T>>);
|
|
17
15
|
insert(method: string, path: string, handler: T): Node<T>;
|
package/dist/utils/jwt/jws.js
CHANGED
|
@@ -21,8 +21,10 @@ async function importPrivateKey(key, alg) {
|
|
|
21
21
|
throw new Error("`crypto.subtle.importKey` is undefined. JWT auth middleware requires it.");
|
|
22
22
|
}
|
|
23
23
|
if (isCryptoKey(key)) {
|
|
24
|
-
if (key.type !== "private") {
|
|
25
|
-
throw new Error(
|
|
24
|
+
if (key.type !== "private" && key.type !== "secret") {
|
|
25
|
+
throw new Error(
|
|
26
|
+
`unexpected key type: CryptoKey.type is ${key.type}, expected private or secret`
|
|
27
|
+
);
|
|
26
28
|
}
|
|
27
29
|
return key;
|
|
28
30
|
}
|