hono 3.2.4 → 3.2.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/aws-lambda/handler.js +8 -10
- package/dist/cjs/adapter/aws-lambda/handler.js +8 -10
- package/dist/cjs/http-exception.js +1 -2
- package/dist/cjs/middleware/jsx/index.js +12 -8
- package/dist/cjs/utils/encode.js +5 -1
- package/dist/http-exception.js +1 -2
- package/dist/middleware/jsx/index.js +12 -8
- package/dist/types/context.d.ts +5 -3
- package/dist/types/utils/types.d.ts +3 -0
- package/dist/utils/encode.js +5 -1
- package/package.json +1 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// src/adapter/aws-lambda/handler.ts
|
|
2
2
|
import crypto from "crypto";
|
|
3
|
+
import { encodeBase64 } from "../../utils/encode.js";
|
|
3
4
|
globalThis.crypto = crypto;
|
|
4
5
|
var handle = (app) => {
|
|
5
6
|
return async (event) => {
|
|
@@ -11,7 +12,13 @@ var handle = (app) => {
|
|
|
11
12
|
var createResult = async (res) => {
|
|
12
13
|
const contentType = res.headers.get("content-type");
|
|
13
14
|
const isBase64Encoded = contentType && isContentTypeBinary(contentType) ? true : false;
|
|
14
|
-
|
|
15
|
+
let body;
|
|
16
|
+
if (isBase64Encoded) {
|
|
17
|
+
const buffer = await res.arrayBuffer();
|
|
18
|
+
body = encodeBase64(buffer);
|
|
19
|
+
} else {
|
|
20
|
+
body = await res.text();
|
|
21
|
+
}
|
|
15
22
|
const result = {
|
|
16
23
|
body,
|
|
17
24
|
headers: {},
|
|
@@ -54,15 +61,6 @@ var isProxyEvent = (event) => {
|
|
|
54
61
|
var isProxyEventV2 = (event) => {
|
|
55
62
|
return Object.prototype.hasOwnProperty.call(event, "rawPath");
|
|
56
63
|
};
|
|
57
|
-
var fromReadableToString = async (res) => {
|
|
58
|
-
const stream = res.body || new ReadableStream();
|
|
59
|
-
const decoder = new TextDecoder();
|
|
60
|
-
let string = "";
|
|
61
|
-
for await (const chunk of stream) {
|
|
62
|
-
string += decoder.decode(chunk);
|
|
63
|
-
}
|
|
64
|
-
return btoa(string);
|
|
65
|
-
};
|
|
66
64
|
var isContentTypeBinary = (contentType) => {
|
|
67
65
|
return !/^(text\/(plain|html|css|javascript|csv).*|application\/(.*json|.*xml).*|image\/svg\+xml)$/.test(
|
|
68
66
|
contentType
|
|
@@ -29,6 +29,7 @@ __export(handler_exports, {
|
|
|
29
29
|
});
|
|
30
30
|
module.exports = __toCommonJS(handler_exports);
|
|
31
31
|
var import_crypto = __toESM(require("crypto"), 1);
|
|
32
|
+
var import_encode = require("../../utils/encode");
|
|
32
33
|
globalThis.crypto = import_crypto.default;
|
|
33
34
|
const handle = (app) => {
|
|
34
35
|
return async (event) => {
|
|
@@ -40,7 +41,13 @@ const handle = (app) => {
|
|
|
40
41
|
const createResult = async (res) => {
|
|
41
42
|
const contentType = res.headers.get("content-type");
|
|
42
43
|
const isBase64Encoded = contentType && isContentTypeBinary(contentType) ? true : false;
|
|
43
|
-
|
|
44
|
+
let body;
|
|
45
|
+
if (isBase64Encoded) {
|
|
46
|
+
const buffer = await res.arrayBuffer();
|
|
47
|
+
body = (0, import_encode.encodeBase64)(buffer);
|
|
48
|
+
} else {
|
|
49
|
+
body = await res.text();
|
|
50
|
+
}
|
|
44
51
|
const result = {
|
|
45
52
|
body,
|
|
46
53
|
headers: {},
|
|
@@ -83,15 +90,6 @@ const isProxyEvent = (event) => {
|
|
|
83
90
|
const isProxyEventV2 = (event) => {
|
|
84
91
|
return Object.prototype.hasOwnProperty.call(event, "rawPath");
|
|
85
92
|
};
|
|
86
|
-
const fromReadableToString = async (res) => {
|
|
87
|
-
const stream = res.body || new ReadableStream();
|
|
88
|
-
const decoder = new TextDecoder();
|
|
89
|
-
let string = "";
|
|
90
|
-
for await (const chunk of stream) {
|
|
91
|
-
string += decoder.decode(chunk);
|
|
92
|
-
}
|
|
93
|
-
return btoa(string);
|
|
94
|
-
};
|
|
95
93
|
const isContentTypeBinary = (contentType) => {
|
|
96
94
|
return !/^(text\/(plain|html|css|javascript|csv).*|application\/(.*json|.*xml).*|image\/svg\+xml)$/.test(
|
|
97
95
|
contentType
|
|
@@ -104,19 +104,23 @@ class JSXNode {
|
|
|
104
104
|
buffer[0] += `<${tag}`;
|
|
105
105
|
const propsKeys = Object.keys(props || {});
|
|
106
106
|
for (let i = 0, len = propsKeys.length; i < len; i++) {
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
|
|
107
|
+
const key = propsKeys[i];
|
|
108
|
+
const v = props[key];
|
|
109
|
+
if (key === "style" && typeof v === "object") {
|
|
110
|
+
const styles = Object.keys(v).map((k) => `${k}:${v[k]}`).join(";").replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
|
|
111
|
+
buffer[0] += ` style="${styles}"`;
|
|
112
|
+
} else if (typeof v === "string") {
|
|
113
|
+
buffer[0] += ` ${key}="`;
|
|
110
114
|
(0, import_html.escapeToBuffer)(v, buffer);
|
|
111
115
|
buffer[0] += '"';
|
|
112
116
|
} else if (typeof v === "number") {
|
|
113
|
-
buffer[0] += ` ${
|
|
117
|
+
buffer[0] += ` ${key}="${v}"`;
|
|
114
118
|
} else if (v === null || v === void 0) {
|
|
115
|
-
} else if (typeof v === "boolean" && booleanAttributes.includes(
|
|
119
|
+
} else if (typeof v === "boolean" && booleanAttributes.includes(key)) {
|
|
116
120
|
if (v) {
|
|
117
|
-
buffer[0] += ` ${
|
|
121
|
+
buffer[0] += ` ${key}=""`;
|
|
118
122
|
}
|
|
119
|
-
} else if (
|
|
123
|
+
} else if (key === "dangerouslySetInnerHTML") {
|
|
120
124
|
if (children.length > 0) {
|
|
121
125
|
throw "Can only set one of `children` or `props.dangerouslySetInnerHTML`.";
|
|
122
126
|
}
|
|
@@ -124,7 +128,7 @@ class JSXNode {
|
|
|
124
128
|
escapedString.isEscaped = true;
|
|
125
129
|
children = [escapedString];
|
|
126
130
|
} else {
|
|
127
|
-
buffer[0] += ` ${
|
|
131
|
+
buffer[0] += ` ${key}="`;
|
|
128
132
|
(0, import_html.escapeToBuffer)(v.toString(), buffer);
|
|
129
133
|
buffer[0] += '"';
|
|
130
134
|
}
|
package/dist/cjs/utils/encode.js
CHANGED
|
@@ -29,7 +29,11 @@ const decodeBase64Url = (str) => {
|
|
|
29
29
|
};
|
|
30
30
|
const encodeBase64Url = (buf) => encodeBase64(buf).replace(/\/|\+/g, (m) => ({ "/": "_", "+": "-" })[m] ?? m);
|
|
31
31
|
const encodeBase64 = (buf) => {
|
|
32
|
-
|
|
32
|
+
let binary = "";
|
|
33
|
+
const bytes = new Uint8Array(buf);
|
|
34
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
35
|
+
binary += String.fromCharCode(bytes[i]);
|
|
36
|
+
}
|
|
33
37
|
return btoa(binary);
|
|
34
38
|
};
|
|
35
39
|
const decodeBase64 = (str) => {
|
package/dist/http-exception.js
CHANGED
|
@@ -79,19 +79,23 @@ var JSXNode = class {
|
|
|
79
79
|
buffer[0] += `<${tag}`;
|
|
80
80
|
const propsKeys = Object.keys(props || {});
|
|
81
81
|
for (let i = 0, len = propsKeys.length; i < len; i++) {
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
82
|
+
const key = propsKeys[i];
|
|
83
|
+
const v = props[key];
|
|
84
|
+
if (key === "style" && typeof v === "object") {
|
|
85
|
+
const styles = Object.keys(v).map((k) => `${k}:${v[k]}`).join(";").replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
|
|
86
|
+
buffer[0] += ` style="${styles}"`;
|
|
87
|
+
} else if (typeof v === "string") {
|
|
88
|
+
buffer[0] += ` ${key}="`;
|
|
85
89
|
escapeToBuffer(v, buffer);
|
|
86
90
|
buffer[0] += '"';
|
|
87
91
|
} else if (typeof v === "number") {
|
|
88
|
-
buffer[0] += ` ${
|
|
92
|
+
buffer[0] += ` ${key}="${v}"`;
|
|
89
93
|
} else if (v === null || v === void 0) {
|
|
90
|
-
} else if (typeof v === "boolean" && booleanAttributes.includes(
|
|
94
|
+
} else if (typeof v === "boolean" && booleanAttributes.includes(key)) {
|
|
91
95
|
if (v) {
|
|
92
|
-
buffer[0] += ` ${
|
|
96
|
+
buffer[0] += ` ${key}=""`;
|
|
93
97
|
}
|
|
94
|
-
} else if (
|
|
98
|
+
} else if (key === "dangerouslySetInnerHTML") {
|
|
95
99
|
if (children.length > 0) {
|
|
96
100
|
throw "Can only set one of `children` or `props.dangerouslySetInnerHTML`.";
|
|
97
101
|
}
|
|
@@ -99,7 +103,7 @@ var JSXNode = class {
|
|
|
99
103
|
escapedString.isEscaped = true;
|
|
100
104
|
children = [escapedString];
|
|
101
105
|
} else {
|
|
102
|
-
buffer[0] += ` ${
|
|
106
|
+
buffer[0] += ` ${key}="`;
|
|
103
107
|
escapeToBuffer(v.toString(), buffer);
|
|
104
108
|
buffer[0] += '"';
|
|
105
109
|
}
|
package/dist/types/context.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { TypedResponse } from './types';
|
|
|
3
3
|
import type { Env, NotFoundHandler, Input } from './types';
|
|
4
4
|
import type { CookieOptions } from './utils/cookie';
|
|
5
5
|
import type { StatusCode } from './utils/http-status';
|
|
6
|
-
import type { JSONValue } from './utils/types';
|
|
6
|
+
import type { JSONValue, InterfaceToType } from './utils/types';
|
|
7
7
|
declare type Runtime = 'node' | 'deno' | 'bun' | 'workerd' | 'fastly' | 'edge-light' | 'lagon' | 'other';
|
|
8
8
|
declare type HeaderRecord = Record<string, string | string[]>;
|
|
9
9
|
declare type Data = string | ArrayBuffer | ReadableStream;
|
|
@@ -36,8 +36,10 @@ interface JSONRespond {
|
|
|
36
36
|
<T = JSONValue>(object: T, init?: ResponseInit): Response;
|
|
37
37
|
}
|
|
38
38
|
interface JSONTRespond {
|
|
39
|
-
<T>(object: T extends JSONValue ? T : JSONValue, status?: StatusCode, headers?: HeaderRecord): TypedResponse<T extends JSONValue ?
|
|
40
|
-
<T>(object: T extends JSONValue ? T : JSONValue,
|
|
39
|
+
<T>(object: T extends JSONValue ? T : JSONValue, status?: StatusCode, headers?: HeaderRecord): TypedResponse<InterfaceToType<T> extends JSONValue ? JSONValue extends InterfaceToType<T> ? never : T : never>;
|
|
40
|
+
<T>(object: InterfaceToType<T> extends JSONValue ? T : JSONValue, status?: StatusCode, headers?: HeaderRecord): TypedResponse<InterfaceToType<T> extends JSONValue ? JSONValue extends InterfaceToType<T> ? never : T : never>;
|
|
41
|
+
<T>(object: T extends JSONValue ? T : JSONValue, init?: ResponseInit): TypedResponse<InterfaceToType<T> extends JSONValue ? JSONValue extends InterfaceToType<T> ? never : T : never>;
|
|
42
|
+
<T>(object: InterfaceToType<T> extends JSONValue ? T : JSONValue, init?: ResponseInit): TypedResponse<InterfaceToType<T> extends JSONValue ? JSONValue extends InterfaceToType<T> ? never : T : never>;
|
|
41
43
|
}
|
|
42
44
|
interface HTMLRespond {
|
|
43
45
|
(html: string, status?: StatusCode, headers?: HeaderRecord): Response;
|
|
@@ -9,3 +9,6 @@ export declare type JSONObject = {
|
|
|
9
9
|
[key: string]: JSONPrimitive | JSONArray | JSONObject;
|
|
10
10
|
};
|
|
11
11
|
export declare type JSONValue = JSONObject | JSONArray | JSONPrimitive;
|
|
12
|
+
export declare type InterfaceToType<T> = T extends Function ? T : {
|
|
13
|
+
[K in keyof T]: InterfaceToType<T[K]>;
|
|
14
|
+
};
|
package/dist/utils/encode.js
CHANGED
|
@@ -4,7 +4,11 @@ var decodeBase64Url = (str) => {
|
|
|
4
4
|
};
|
|
5
5
|
var encodeBase64Url = (buf) => encodeBase64(buf).replace(/\/|\+/g, (m) => ({ "/": "_", "+": "-" })[m] ?? m);
|
|
6
6
|
var encodeBase64 = (buf) => {
|
|
7
|
-
|
|
7
|
+
let binary = "";
|
|
8
|
+
const bytes = new Uint8Array(buf);
|
|
9
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
10
|
+
binary += String.fromCharCode(bytes[i]);
|
|
11
|
+
}
|
|
8
12
|
return btoa(binary);
|
|
9
13
|
};
|
|
10
14
|
var decodeBase64 = (str) => {
|