hono 2.0.3 → 2.0.6
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/context.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="@cloudflare/workers-types" />
|
|
2
|
-
import type { NotFoundHandler } from './hono';
|
|
2
|
+
import type { ContextVariableMap, NotFoundHandler } from './hono';
|
|
3
3
|
import type { CookieOptions } from './utils/cookie';
|
|
4
4
|
import type { StatusCode } from './utils/http-status';
|
|
5
5
|
declare type Headers = Record<string, string>;
|
|
@@ -15,8 +15,14 @@ export interface Context<RequestParamKeyType extends string = string, E = Env> {
|
|
|
15
15
|
set res(_res: Response);
|
|
16
16
|
header: (name: string, value: string) => void;
|
|
17
17
|
status: (status: StatusCode) => void;
|
|
18
|
-
set:
|
|
19
|
-
|
|
18
|
+
set: {
|
|
19
|
+
<Key extends keyof ContextVariableMap>(key: Key, value: ContextVariableMap[Key]): void;
|
|
20
|
+
(key: string, value: any): void;
|
|
21
|
+
};
|
|
22
|
+
get: {
|
|
23
|
+
<Key extends keyof ContextVariableMap>(key: Key): ContextVariableMap[Key];
|
|
24
|
+
<T = any>(key: string): T;
|
|
25
|
+
};
|
|
20
26
|
pretty: (prettyJSON: boolean, space?: number) => void;
|
|
21
27
|
newResponse: (data: Data | null, status: StatusCode, headers: Headers) => Response;
|
|
22
28
|
body: (data: Data | null, status?: StatusCode, headers?: Headers) => Response;
|
package/dist/hono.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/// <reference types="@cloudflare/workers-types" />
|
|
2
2
|
import type { Context } from './context';
|
|
3
3
|
import type { Router } from './router';
|
|
4
|
+
export interface ContextVariableMap {
|
|
5
|
+
}
|
|
4
6
|
declare type Env = Record<string, any>;
|
|
5
7
|
export declare type Handler<RequestParamKeyType extends string = string, E = Env> = (c: Context<RequestParamKeyType, E>, next: Next) => Response | Promise<Response> | Promise<void> | Promise<Response | undefined>;
|
|
6
8
|
export declare type NotFoundHandler<E = Env> = (c: Context<string, E>) => Response | Promise<Response>;
|
|
@@ -19,6 +19,12 @@ const emptyTags = [
|
|
|
19
19
|
'track',
|
|
20
20
|
'wbr',
|
|
21
21
|
];
|
|
22
|
+
const booleanAttributes = ['checked', 'selected', 'disabled', 'readonly', 'multiple'];
|
|
23
|
+
const newHtmlEscapedString = (str) => {
|
|
24
|
+
const escapedString = new String(str);
|
|
25
|
+
escapedString.isEscaped = true;
|
|
26
|
+
return escapedString;
|
|
27
|
+
};
|
|
22
28
|
const jsxFn = (tag, props, ...children) => {
|
|
23
29
|
if (typeof tag === 'function') {
|
|
24
30
|
return tag.call(null, { ...props, children: children.length <= 1 ? children[0] : children });
|
|
@@ -27,24 +33,35 @@ const jsxFn = (tag, props, ...children) => {
|
|
|
27
33
|
const propsKeys = Object.keys(props || {});
|
|
28
34
|
for (let i = 0, len = propsKeys.length; i < len; i++) {
|
|
29
35
|
const v = props[propsKeys[i]];
|
|
30
|
-
if (
|
|
36
|
+
if (typeof v === 'string') {
|
|
37
|
+
result += ` ${propsKeys[i]}="${(0, html_1.escape)(v)}"`;
|
|
38
|
+
}
|
|
39
|
+
else if (typeof v === 'number') {
|
|
40
|
+
result += ` ${propsKeys[i]}="${v}"`;
|
|
41
|
+
}
|
|
42
|
+
else if (v === null || v === undefined) {
|
|
43
|
+
// Do nothing
|
|
44
|
+
}
|
|
45
|
+
else if (typeof v === 'boolean' && booleanAttributes.includes(propsKeys[i])) {
|
|
46
|
+
if (v) {
|
|
47
|
+
result += ` ${propsKeys[i]}=""`;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
else if (propsKeys[i] === 'dangerouslySetInnerHTML') {
|
|
31
51
|
if (children.length > 0) {
|
|
32
52
|
throw 'Can only set one of `children` or `props.dangerouslySetInnerHTML`.';
|
|
33
53
|
}
|
|
34
|
-
|
|
35
|
-
escapedString.isEscaped = true;
|
|
36
|
-
children = [escapedString];
|
|
37
|
-
continue;
|
|
54
|
+
children = [newHtmlEscapedString(v.__html)];
|
|
38
55
|
}
|
|
39
|
-
else
|
|
40
|
-
|
|
56
|
+
else {
|
|
57
|
+
result += ` ${propsKeys[i]}="${(0, html_1.escape)(v.toString())}"`;
|
|
41
58
|
}
|
|
42
|
-
|
|
59
|
+
}
|
|
60
|
+
if (emptyTags.includes(tag)) {
|
|
61
|
+
result += '/>';
|
|
62
|
+
return newHtmlEscapedString(result);
|
|
43
63
|
}
|
|
44
64
|
if (tag !== '') {
|
|
45
|
-
if (emptyTags.includes(tag)) {
|
|
46
|
-
result += '/';
|
|
47
|
-
}
|
|
48
65
|
result += '>';
|
|
49
66
|
}
|
|
50
67
|
const flattenChildren = children.flat(Infinity);
|
|
@@ -60,12 +77,10 @@ const jsxFn = (tag, props, ...children) => {
|
|
|
60
77
|
result += (0, html_1.escape)(child.toString());
|
|
61
78
|
}
|
|
62
79
|
}
|
|
63
|
-
if (tag !== ''
|
|
80
|
+
if (tag !== '') {
|
|
64
81
|
result += `</${tag}>`;
|
|
65
82
|
}
|
|
66
|
-
|
|
67
|
-
escapedString.isEscaped = true;
|
|
68
|
-
return escapedString;
|
|
83
|
+
return newHtmlEscapedString(result);
|
|
69
84
|
};
|
|
70
85
|
exports.jsx = jsxFn;
|
|
71
86
|
const shallowEqual = (a, b) => {
|
package/dist/utils/body.js
CHANGED
|
@@ -4,7 +4,12 @@ exports.parseBody = void 0;
|
|
|
4
4
|
const parseBody = async (r) => {
|
|
5
5
|
const contentType = r.headers.get('Content-Type') || '';
|
|
6
6
|
if (contentType.includes('application/json')) {
|
|
7
|
-
|
|
7
|
+
let body = {};
|
|
8
|
+
try {
|
|
9
|
+
body = await r.json();
|
|
10
|
+
}
|
|
11
|
+
catch { } // Do nothing
|
|
12
|
+
return body;
|
|
8
13
|
}
|
|
9
14
|
else if (contentType.includes('application/text')) {
|
|
10
15
|
return await r.text();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hono",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.6",
|
|
4
4
|
"description": "Ultrafast web framework for Cloudflare Workers.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -70,10 +70,10 @@
|
|
|
70
70
|
"jsx": [
|
|
71
71
|
"./dist/middleware/jsx"
|
|
72
72
|
],
|
|
73
|
-
"jsx-runtime": [
|
|
73
|
+
"jsx/jsx-runtime": [
|
|
74
74
|
"./dist/middleware/jsx/jsx-runtime.d.ts"
|
|
75
75
|
],
|
|
76
|
-
"jsx-dev-runtime": [
|
|
76
|
+
"jsx/jsx-dev-runtime": [
|
|
77
77
|
"./dist/middleware/jsx/jsx-dev-runtime.d.ts"
|
|
78
78
|
],
|
|
79
79
|
"jwt": [
|