hono 4.4.3 → 4.4.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/cloudflare-workers/index.js +2 -0
- package/dist/cjs/adapter/cloudflare-workers/index.js +3 -0
- package/dist/cjs/context.js +3 -3
- package/dist/cjs/helper/conninfo/types.js +16 -0
- package/dist/cjs/hono-base.js +3 -10
- package/dist/cjs/jsx/base.js +2 -5
- package/dist/cjs/jsx/dom/jsx-dev-runtime.js +2 -6
- package/dist/cjs/jsx/dom/render.js +7 -7
- package/dist/cjs/jsx/utils.js +7 -8
- package/dist/cjs/middleware/cors/index.js +6 -1
- package/dist/cjs/middleware/serve-static/index.js +5 -3
- package/dist/cjs/request.js +8 -18
- package/dist/cjs/utils/filepath.js +1 -1
- package/dist/context.js +3 -3
- package/dist/helper/conninfo/types.js +0 -0
- package/dist/hono-base.js +3 -10
- package/dist/jsx/base.js +3 -6
- package/dist/jsx/dom/jsx-dev-runtime.js +0 -4
- package/dist/jsx/dom/render.js +8 -8
- package/dist/jsx/utils.js +6 -7
- package/dist/middleware/cors/index.js +6 -1
- package/dist/middleware/serve-static/index.js +5 -3
- package/dist/request.js +8 -18
- package/dist/types/adapter/cloudflare-workers/index.d.ts +1 -0
- package/dist/types/context.d.ts +14 -7
- package/dist/types/helper/conninfo/index.d.ts +1 -36
- package/dist/types/helper/conninfo/types.d.ts +36 -0
- package/dist/types/hono-base.d.ts +1 -1
- package/dist/types/jsx/base.d.ts +2 -2
- package/dist/types/jsx/index.d.ts +1 -0
- package/dist/types/jsx/intrinsic-elements.d.ts +2 -2
- package/dist/types/jsx/types.d.ts +2 -2
- package/dist/types/jsx/utils.d.ts +1 -1
- package/dist/types/types.d.ts +11 -8
- package/dist/types/utils/types.d.ts +10 -3
- package/dist/utils/filepath.js +1 -1
- package/package.json +1 -1
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// src/adapter/cloudflare-workers/index.ts
|
|
2
2
|
import { serveStatic } from "./serve-static-module.js";
|
|
3
3
|
import { upgradeWebSocket } from "./websocket.js";
|
|
4
|
+
import { getConnInfo } from "./conninfo.js";
|
|
4
5
|
export {
|
|
6
|
+
getConnInfo,
|
|
5
7
|
serveStatic,
|
|
6
8
|
upgradeWebSocket
|
|
7
9
|
};
|
|
@@ -18,14 +18,17 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var cloudflare_workers_exports = {};
|
|
20
20
|
__export(cloudflare_workers_exports, {
|
|
21
|
+
getConnInfo: () => import_conninfo.getConnInfo,
|
|
21
22
|
serveStatic: () => import_serve_static_module.serveStatic,
|
|
22
23
|
upgradeWebSocket: () => import_websocket.upgradeWebSocket
|
|
23
24
|
});
|
|
24
25
|
module.exports = __toCommonJS(cloudflare_workers_exports);
|
|
25
26
|
var import_serve_static_module = require("./serve-static-module");
|
|
26
27
|
var import_websocket = require("./websocket");
|
|
28
|
+
var import_conninfo = require("./conninfo");
|
|
27
29
|
// Annotate the CommonJS export names for ESM import in node:
|
|
28
30
|
0 && (module.exports = {
|
|
31
|
+
getConnInfo,
|
|
29
32
|
serveStatic,
|
|
30
33
|
upgradeWebSocket
|
|
31
34
|
});
|
package/dist/cjs/context.js
CHANGED
|
@@ -31,7 +31,7 @@ const setHeaders = (headers, map = {}) => {
|
|
|
31
31
|
class Context {
|
|
32
32
|
req;
|
|
33
33
|
env = {};
|
|
34
|
-
_var
|
|
34
|
+
_var;
|
|
35
35
|
finalized = false;
|
|
36
36
|
error = void 0;
|
|
37
37
|
#status = 200;
|
|
@@ -232,10 +232,10 @@ class Context {
|
|
|
232
232
|
}
|
|
233
233
|
return typeof arg === "number" ? this.newResponse(html, arg, headers) : this.newResponse(html, arg);
|
|
234
234
|
};
|
|
235
|
-
redirect = (location, status
|
|
235
|
+
redirect = (location, status) => {
|
|
236
236
|
this.#headers ??= new Headers();
|
|
237
237
|
this.#headers.set("Location", location);
|
|
238
|
-
return this.newResponse(null, status);
|
|
238
|
+
return this.newResponse(null, status ?? 302);
|
|
239
239
|
};
|
|
240
240
|
notFound = () => {
|
|
241
241
|
return this.notFoundHandler(this);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var types_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(types_exports);
|
package/dist/cjs/hono-base.js
CHANGED
|
@@ -24,7 +24,6 @@ __export(hono_base_exports, {
|
|
|
24
24
|
module.exports = __toCommonJS(hono_base_exports);
|
|
25
25
|
var import_compose = require("./compose");
|
|
26
26
|
var import_context = require("./context");
|
|
27
|
-
var import_http_exception = require("./http-exception");
|
|
28
27
|
var import_request = require("./request");
|
|
29
28
|
var import_router = require("./router");
|
|
30
29
|
var import_url = require("./utils/url");
|
|
@@ -33,7 +32,7 @@ const notFoundHandler = (c) => {
|
|
|
33
32
|
return c.text("404 Not Found", 404);
|
|
34
33
|
};
|
|
35
34
|
const errorHandler = (err, c) => {
|
|
36
|
-
if (
|
|
35
|
+
if ("getResponse" in err) {
|
|
37
36
|
return err.getResponse();
|
|
38
37
|
}
|
|
39
38
|
console.error(err);
|
|
@@ -72,9 +71,6 @@ class Hono {
|
|
|
72
71
|
};
|
|
73
72
|
});
|
|
74
73
|
this.on = (method, path, ...handlers) => {
|
|
75
|
-
if (!method) {
|
|
76
|
-
return this;
|
|
77
|
-
}
|
|
78
74
|
for (const p of [path].flat()) {
|
|
79
75
|
this.#path = p;
|
|
80
76
|
for (const m of [method].flat()) {
|
|
@@ -114,9 +110,6 @@ class Hono {
|
|
|
114
110
|
errorHandler = errorHandler;
|
|
115
111
|
route(path, app) {
|
|
116
112
|
const subApp = this.basePath(path);
|
|
117
|
-
if (!app) {
|
|
118
|
-
return subApp;
|
|
119
|
-
}
|
|
120
113
|
app.routes.map((r) => {
|
|
121
114
|
let handler;
|
|
122
115
|
if (app.errorHandler === errorHandler) {
|
|
@@ -221,7 +214,7 @@ class Hono {
|
|
|
221
214
|
}
|
|
222
215
|
return res instanceof Promise ? res.then(
|
|
223
216
|
(resolved) => resolved || (c.finalized ? c.res : this.notFoundHandler(c))
|
|
224
|
-
).catch((err) => this.handleError(err, c)) : res;
|
|
217
|
+
).catch((err) => this.handleError(err, c)) : res ?? this.notFoundHandler(c);
|
|
225
218
|
}
|
|
226
219
|
const composed = (0, import_compose.compose)(matchResult[0], this.errorHandler, this.notFoundHandler);
|
|
227
220
|
return (async () => {
|
|
@@ -229,7 +222,7 @@ class Hono {
|
|
|
229
222
|
const context = await composed(c);
|
|
230
223
|
if (!context.finalized) {
|
|
231
224
|
throw new Error(
|
|
232
|
-
"Context is not finalized.
|
|
225
|
+
"Context is not finalized. Did you forget to return a Response object or `await next()`?"
|
|
233
226
|
);
|
|
234
227
|
}
|
|
235
228
|
return context.res;
|
package/dist/cjs/jsx/base.js
CHANGED
|
@@ -133,10 +133,8 @@ class JSXNode {
|
|
|
133
133
|
const props = this.props;
|
|
134
134
|
let { children } = this;
|
|
135
135
|
buffer[0] += `<${tag}`;
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
const key = propsKeys[i];
|
|
139
|
-
const v = props[key];
|
|
136
|
+
for (let [key, v] of Object.entries(props)) {
|
|
137
|
+
key = (0, import_utils.normalizeIntrinsicElementKey)(key);
|
|
140
138
|
if (key === "children") {
|
|
141
139
|
} else if (key === "style" && typeof v === "object") {
|
|
142
140
|
let styleStr = "";
|
|
@@ -237,7 +235,6 @@ const jsxFn = (tag, props, children) => {
|
|
|
237
235
|
if (typeof tag === "function") {
|
|
238
236
|
return new JSXFunctionNode(tag, props, children);
|
|
239
237
|
} else {
|
|
240
|
-
(0, import_utils.normalizeIntrinsicElementProps)(props);
|
|
241
238
|
return new JSXNode(tag, props, children);
|
|
242
239
|
}
|
|
243
240
|
};
|
|
@@ -22,13 +22,9 @@ __export(jsx_dev_runtime_exports, {
|
|
|
22
22
|
jsxDEV: () => jsxDEV
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(jsx_dev_runtime_exports);
|
|
25
|
-
var import_utils = require("
|
|
26
|
-
var import_utils2 = require("./utils");
|
|
25
|
+
var import_utils = require("./utils");
|
|
27
26
|
const jsxDEV = (tag, props, key) => {
|
|
28
|
-
|
|
29
|
-
(0, import_utils.normalizeIntrinsicElementProps)(props);
|
|
30
|
-
}
|
|
31
|
-
return (0, import_utils2.newJSXNode)({
|
|
27
|
+
return (0, import_utils.newJSXNode)({
|
|
32
28
|
tag,
|
|
33
29
|
props,
|
|
34
30
|
key
|
|
@@ -41,8 +41,8 @@ const eventAliasMap = {
|
|
|
41
41
|
DoubleClick: "DblClick"
|
|
42
42
|
};
|
|
43
43
|
const nameSpaceMap = {
|
|
44
|
-
svg: "
|
|
45
|
-
math: "
|
|
44
|
+
svg: "2000/svg",
|
|
45
|
+
math: "1998/Math/MathML"
|
|
46
46
|
};
|
|
47
47
|
const skipProps = /* @__PURE__ */ new Set(["children"]);
|
|
48
48
|
const buildDataStack = [];
|
|
@@ -59,8 +59,9 @@ const getEventSpec = (key) => {
|
|
|
59
59
|
const toAttributeName = (element, key) => element instanceof SVGElement && /[A-Z]/.test(key) && (key in element.style || key.match(/^(?:o|pai|str|u|ve)/)) ? key.replace(/([A-Z])/g, "-$1").toLowerCase() : key;
|
|
60
60
|
const applyProps = (container, attributes, oldAttributes) => {
|
|
61
61
|
attributes ||= {};
|
|
62
|
-
for (
|
|
62
|
+
for (let [key, value] of Object.entries(attributes)) {
|
|
63
63
|
if (!skipProps.has(key) && (!oldAttributes || oldAttributes[key] !== value)) {
|
|
64
|
+
key = (0, import_utils.normalizeIntrinsicElementKey)(key);
|
|
64
65
|
const eventSpec = getEventSpec(key);
|
|
65
66
|
if (eventSpec) {
|
|
66
67
|
if (oldAttributes) {
|
|
@@ -125,8 +126,9 @@ const applyProps = (container, attributes, oldAttributes) => {
|
|
|
125
126
|
}
|
|
126
127
|
}
|
|
127
128
|
if (oldAttributes) {
|
|
128
|
-
for (
|
|
129
|
+
for (let [key, value] of Object.entries(oldAttributes)) {
|
|
129
130
|
if (!skipProps.has(key) && !(key in attributes)) {
|
|
131
|
+
key = (0, import_utils.normalizeIntrinsicElementKey)(key);
|
|
130
132
|
const eventSpec = getEventSpec(key);
|
|
131
133
|
if (eventSpec) {
|
|
132
134
|
container.removeEventListener(eventSpec[0], value, eventSpec[1]);
|
|
@@ -386,14 +388,12 @@ const buildNode = (node) => {
|
|
|
386
388
|
} else {
|
|
387
389
|
const ns = nameSpaceMap[node.tag];
|
|
388
390
|
if (ns) {
|
|
389
|
-
;
|
|
390
|
-
node.n = ns;
|
|
391
391
|
nameSpaceContext ||= (0, import_context2.createContext)("");
|
|
392
392
|
node.props.children = [
|
|
393
393
|
{
|
|
394
394
|
tag: nameSpaceContext.Provider,
|
|
395
395
|
props: {
|
|
396
|
-
value: ns
|
|
396
|
+
value: node.n = `http://www.w3.org/${ns}`,
|
|
397
397
|
children: node.props.children
|
|
398
398
|
}
|
|
399
399
|
}
|
package/dist/cjs/jsx/utils.js
CHANGED
|
@@ -18,16 +18,15 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var utils_exports = {};
|
|
20
20
|
__export(utils_exports, {
|
|
21
|
-
|
|
21
|
+
normalizeIntrinsicElementKey: () => normalizeIntrinsicElementKey,
|
|
22
22
|
styleObjectForEach: () => styleObjectForEach
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(utils_exports);
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
};
|
|
25
|
+
const normalizeElementKeyMap = /* @__PURE__ */ new Map([
|
|
26
|
+
["className", "class"],
|
|
27
|
+
["htmlFor", "for"]
|
|
28
|
+
]);
|
|
29
|
+
const normalizeIntrinsicElementKey = (key) => normalizeElementKeyMap.get(key) || key;
|
|
31
30
|
const styleObjectForEach = (style, fn) => {
|
|
32
31
|
for (const [k, v] of Object.entries(style)) {
|
|
33
32
|
const key = k[0] === "-" || !/[A-Z]/.test(k) ? k : k.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`);
|
|
@@ -41,6 +40,6 @@ const styleObjectForEach = (style, fn) => {
|
|
|
41
40
|
};
|
|
42
41
|
// Annotate the CommonJS export names for ESM import in node:
|
|
43
42
|
0 && (module.exports = {
|
|
44
|
-
|
|
43
|
+
normalizeIntrinsicElementKey,
|
|
45
44
|
styleObjectForEach
|
|
46
45
|
});
|
|
@@ -50,7 +50,12 @@ const cors = (options) => {
|
|
|
50
50
|
set("Access-Control-Allow-Origin", allowOrigin);
|
|
51
51
|
}
|
|
52
52
|
if (opts.origin !== "*") {
|
|
53
|
-
|
|
53
|
+
const existingVary = c.req.header("Vary");
|
|
54
|
+
if (existingVary) {
|
|
55
|
+
set("Vary", existingVary);
|
|
56
|
+
} else {
|
|
57
|
+
set("Vary", "Origin");
|
|
58
|
+
}
|
|
54
59
|
}
|
|
55
60
|
if (opts.credentials) {
|
|
56
61
|
set("Access-Control-Allow-Credentials", "true");
|
|
@@ -55,9 +55,11 @@ const serveStatic = (options) => {
|
|
|
55
55
|
return await next();
|
|
56
56
|
}
|
|
57
57
|
pathWithOutDefaultDocument = pathResolve(pathWithOutDefaultDocument);
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
58
|
+
if (pathWithOutDefaultDocument !== path) {
|
|
59
|
+
content = await getContent(pathWithOutDefaultDocument, c);
|
|
60
|
+
if (content) {
|
|
61
|
+
path = pathWithOutDefaultDocument;
|
|
62
|
+
}
|
|
61
63
|
}
|
|
62
64
|
}
|
|
63
65
|
if (content instanceof Response) {
|
package/dist/cjs/request.js
CHANGED
|
@@ -75,12 +75,7 @@ class HonoRequest {
|
|
|
75
75
|
return headerData;
|
|
76
76
|
}
|
|
77
77
|
async parseBody(options) {
|
|
78
|
-
|
|
79
|
-
return this.bodyCache.parsedBody;
|
|
80
|
-
}
|
|
81
|
-
const parsedBody = await (0, import_body.parseBody)(this, options);
|
|
82
|
-
this.bodyCache.parsedBody = parsedBody;
|
|
83
|
-
return parsedBody;
|
|
78
|
+
return this.bodyCache.parsedBody ??= await (0, import_body.parseBody)(this, options);
|
|
84
79
|
}
|
|
85
80
|
cachedBody = (key) => {
|
|
86
81
|
const { bodyCache, raw } = this;
|
|
@@ -88,19 +83,14 @@ class HonoRequest {
|
|
|
88
83
|
if (cachedBody) {
|
|
89
84
|
return cachedBody;
|
|
90
85
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
86
|
+
const anyCachedKey = Object.keys(bodyCache)[0];
|
|
87
|
+
if (anyCachedKey) {
|
|
88
|
+
return bodyCache[anyCachedKey].then((body) => {
|
|
89
|
+
if (anyCachedKey === "json") {
|
|
90
|
+
body = JSON.stringify(body);
|
|
95
91
|
}
|
|
96
|
-
return
|
|
97
|
-
|
|
98
|
-
if (keyOfBodyCache === "json") {
|
|
99
|
-
body = JSON.stringify(body);
|
|
100
|
-
}
|
|
101
|
-
return await new Response(body)[key]();
|
|
102
|
-
})();
|
|
103
|
-
}
|
|
92
|
+
return new Response(body)[key]();
|
|
93
|
+
});
|
|
104
94
|
}
|
|
105
95
|
return bodyCache[key] = raw[key]();
|
|
106
96
|
};
|
|
@@ -27,7 +27,7 @@ const getFilePath = (options) => {
|
|
|
27
27
|
const defaultDocument = options.defaultDocument || "index.html";
|
|
28
28
|
if (filename.endsWith("/")) {
|
|
29
29
|
filename = filename.concat(defaultDocument);
|
|
30
|
-
} else if (!filename.match(/\.[a-zA-Z0-
|
|
30
|
+
} else if (!filename.match(/\.[a-zA-Z0-9_-]+$/)) {
|
|
31
31
|
filename = filename.concat("/" + defaultDocument);
|
|
32
32
|
}
|
|
33
33
|
const path = getFilePathWithoutDefaultDocument({
|
package/dist/context.js
CHANGED
|
@@ -8,7 +8,7 @@ var setHeaders = (headers, map = {}) => {
|
|
|
8
8
|
var Context = class {
|
|
9
9
|
req;
|
|
10
10
|
env = {};
|
|
11
|
-
_var
|
|
11
|
+
_var;
|
|
12
12
|
finalized = false;
|
|
13
13
|
error = void 0;
|
|
14
14
|
#status = 200;
|
|
@@ -209,10 +209,10 @@ var Context = class {
|
|
|
209
209
|
}
|
|
210
210
|
return typeof arg === "number" ? this.newResponse(html, arg, headers) : this.newResponse(html, arg);
|
|
211
211
|
};
|
|
212
|
-
redirect = (location, status
|
|
212
|
+
redirect = (location, status) => {
|
|
213
213
|
this.#headers ??= new Headers();
|
|
214
214
|
this.#headers.set("Location", location);
|
|
215
|
-
return this.newResponse(null, status);
|
|
215
|
+
return this.newResponse(null, status ?? 302);
|
|
216
216
|
};
|
|
217
217
|
notFound = () => {
|
|
218
218
|
return this.notFoundHandler(this);
|
|
File without changes
|
package/dist/hono-base.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// src/hono-base.ts
|
|
2
2
|
import { compose } from "./compose.js";
|
|
3
3
|
import { Context } from "./context.js";
|
|
4
|
-
import { HTTPException } from "./http-exception.js";
|
|
5
4
|
import { HonoRequest } from "./request.js";
|
|
6
5
|
import { METHODS, METHOD_NAME_ALL, METHOD_NAME_ALL_LOWERCASE } from "./router.js";
|
|
7
6
|
import { getPath, getPathNoStrict, mergePath } from "./utils/url.js";
|
|
@@ -10,7 +9,7 @@ var notFoundHandler = (c) => {
|
|
|
10
9
|
return c.text("404 Not Found", 404);
|
|
11
10
|
};
|
|
12
11
|
var errorHandler = (err, c) => {
|
|
13
|
-
if (
|
|
12
|
+
if ("getResponse" in err) {
|
|
14
13
|
return err.getResponse();
|
|
15
14
|
}
|
|
16
15
|
console.error(err);
|
|
@@ -49,9 +48,6 @@ var Hono = class {
|
|
|
49
48
|
};
|
|
50
49
|
});
|
|
51
50
|
this.on = (method, path, ...handlers) => {
|
|
52
|
-
if (!method) {
|
|
53
|
-
return this;
|
|
54
|
-
}
|
|
55
51
|
for (const p of [path].flat()) {
|
|
56
52
|
this.#path = p;
|
|
57
53
|
for (const m of [method].flat()) {
|
|
@@ -91,9 +87,6 @@ var Hono = class {
|
|
|
91
87
|
errorHandler = errorHandler;
|
|
92
88
|
route(path, app) {
|
|
93
89
|
const subApp = this.basePath(path);
|
|
94
|
-
if (!app) {
|
|
95
|
-
return subApp;
|
|
96
|
-
}
|
|
97
90
|
app.routes.map((r) => {
|
|
98
91
|
let handler;
|
|
99
92
|
if (app.errorHandler === errorHandler) {
|
|
@@ -198,7 +191,7 @@ var Hono = class {
|
|
|
198
191
|
}
|
|
199
192
|
return res instanceof Promise ? res.then(
|
|
200
193
|
(resolved) => resolved || (c.finalized ? c.res : this.notFoundHandler(c))
|
|
201
|
-
).catch((err) => this.handleError(err, c)) : res;
|
|
194
|
+
).catch((err) => this.handleError(err, c)) : res ?? this.notFoundHandler(c);
|
|
202
195
|
}
|
|
203
196
|
const composed = compose(matchResult[0], this.errorHandler, this.notFoundHandler);
|
|
204
197
|
return (async () => {
|
|
@@ -206,7 +199,7 @@ var Hono = class {
|
|
|
206
199
|
const context = await composed(c);
|
|
207
200
|
if (!context.finalized) {
|
|
208
201
|
throw new Error(
|
|
209
|
-
"Context is not finalized.
|
|
202
|
+
"Context is not finalized. Did you forget to return a Response object or `await next()`?"
|
|
210
203
|
);
|
|
211
204
|
}
|
|
212
205
|
return context.res;
|
package/dist/jsx/base.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { raw } from "../helper/html/index.js";
|
|
3
3
|
import { escapeToBuffer, stringBufferToString } from "../utils/html.js";
|
|
4
4
|
import { globalContexts } from "./context.js";
|
|
5
|
-
import {
|
|
5
|
+
import { normalizeIntrinsicElementKey, styleObjectForEach } from "./utils.js";
|
|
6
6
|
var emptyTags = [
|
|
7
7
|
"area",
|
|
8
8
|
"base",
|
|
@@ -103,10 +103,8 @@ var JSXNode = class {
|
|
|
103
103
|
const props = this.props;
|
|
104
104
|
let { children } = this;
|
|
105
105
|
buffer[0] += `<${tag}`;
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
const key = propsKeys[i];
|
|
109
|
-
const v = props[key];
|
|
106
|
+
for (let [key, v] of Object.entries(props)) {
|
|
107
|
+
key = normalizeIntrinsicElementKey(key);
|
|
110
108
|
if (key === "children") {
|
|
111
109
|
} else if (key === "style" && typeof v === "object") {
|
|
112
110
|
let styleStr = "";
|
|
@@ -207,7 +205,6 @@ var jsxFn = (tag, props, children) => {
|
|
|
207
205
|
if (typeof tag === "function") {
|
|
208
206
|
return new JSXFunctionNode(tag, props, children);
|
|
209
207
|
} else {
|
|
210
|
-
normalizeIntrinsicElementProps(props);
|
|
211
208
|
return new JSXNode(tag, props, children);
|
|
212
209
|
}
|
|
213
210
|
};
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
// src/jsx/dom/jsx-dev-runtime.ts
|
|
2
|
-
import { normalizeIntrinsicElementProps } from "../utils.js";
|
|
3
2
|
import { newJSXNode } from "./utils.js";
|
|
4
3
|
var jsxDEV = (tag, props, key) => {
|
|
5
|
-
if (typeof tag === "string") {
|
|
6
|
-
normalizeIntrinsicElementProps(props);
|
|
7
|
-
}
|
|
8
4
|
return newJSXNode({
|
|
9
5
|
tag,
|
|
10
6
|
props,
|
package/dist/jsx/dom/render.js
CHANGED
|
@@ -3,7 +3,7 @@ import { toArray } from "../children.js";
|
|
|
3
3
|
import { DOM_ERROR_HANDLER, DOM_INTERNAL_TAG, DOM_RENDERER, DOM_STASH } from "../constants.js";
|
|
4
4
|
import { globalContexts as globalJSXContexts, useContext } from "../context.js";
|
|
5
5
|
import { STASH_EFFECT } from "../hooks/index.js";
|
|
6
|
-
import { styleObjectForEach } from "../utils.js";
|
|
6
|
+
import { normalizeIntrinsicElementKey, styleObjectForEach } from "../utils.js";
|
|
7
7
|
import { createContext } from "./context.js";
|
|
8
8
|
import { newJSXNode } from "./utils.js";
|
|
9
9
|
var HONO_PORTAL_ELEMENT = "_hp";
|
|
@@ -12,8 +12,8 @@ var eventAliasMap = {
|
|
|
12
12
|
DoubleClick: "DblClick"
|
|
13
13
|
};
|
|
14
14
|
var nameSpaceMap = {
|
|
15
|
-
svg: "
|
|
16
|
-
math: "
|
|
15
|
+
svg: "2000/svg",
|
|
16
|
+
math: "1998/Math/MathML"
|
|
17
17
|
};
|
|
18
18
|
var skipProps = /* @__PURE__ */ new Set(["children"]);
|
|
19
19
|
var buildDataStack = [];
|
|
@@ -30,8 +30,9 @@ var getEventSpec = (key) => {
|
|
|
30
30
|
var toAttributeName = (element, key) => element instanceof SVGElement && /[A-Z]/.test(key) && (key in element.style || key.match(/^(?:o|pai|str|u|ve)/)) ? key.replace(/([A-Z])/g, "-$1").toLowerCase() : key;
|
|
31
31
|
var applyProps = (container, attributes, oldAttributes) => {
|
|
32
32
|
attributes ||= {};
|
|
33
|
-
for (
|
|
33
|
+
for (let [key, value] of Object.entries(attributes)) {
|
|
34
34
|
if (!skipProps.has(key) && (!oldAttributes || oldAttributes[key] !== value)) {
|
|
35
|
+
key = normalizeIntrinsicElementKey(key);
|
|
35
36
|
const eventSpec = getEventSpec(key);
|
|
36
37
|
if (eventSpec) {
|
|
37
38
|
if (oldAttributes) {
|
|
@@ -96,8 +97,9 @@ var applyProps = (container, attributes, oldAttributes) => {
|
|
|
96
97
|
}
|
|
97
98
|
}
|
|
98
99
|
if (oldAttributes) {
|
|
99
|
-
for (
|
|
100
|
+
for (let [key, value] of Object.entries(oldAttributes)) {
|
|
100
101
|
if (!skipProps.has(key) && !(key in attributes)) {
|
|
102
|
+
key = normalizeIntrinsicElementKey(key);
|
|
101
103
|
const eventSpec = getEventSpec(key);
|
|
102
104
|
if (eventSpec) {
|
|
103
105
|
container.removeEventListener(eventSpec[0], value, eventSpec[1]);
|
|
@@ -357,14 +359,12 @@ var buildNode = (node) => {
|
|
|
357
359
|
} else {
|
|
358
360
|
const ns = nameSpaceMap[node.tag];
|
|
359
361
|
if (ns) {
|
|
360
|
-
;
|
|
361
|
-
node.n = ns;
|
|
362
362
|
nameSpaceContext ||= createContext("");
|
|
363
363
|
node.props.children = [
|
|
364
364
|
{
|
|
365
365
|
tag: nameSpaceContext.Provider,
|
|
366
366
|
props: {
|
|
367
|
-
value: ns
|
|
367
|
+
value: node.n = `http://www.w3.org/${ns}`,
|
|
368
368
|
children: node.props.children
|
|
369
369
|
}
|
|
370
370
|
}
|
package/dist/jsx/utils.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
// src/jsx/utils.ts
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
};
|
|
2
|
+
var normalizeElementKeyMap = /* @__PURE__ */ new Map([
|
|
3
|
+
["className", "class"],
|
|
4
|
+
["htmlFor", "for"]
|
|
5
|
+
]);
|
|
6
|
+
var normalizeIntrinsicElementKey = (key) => normalizeElementKeyMap.get(key) || key;
|
|
8
7
|
var styleObjectForEach = (style, fn) => {
|
|
9
8
|
for (const [k, v] of Object.entries(style)) {
|
|
10
9
|
const key = k[0] === "-" || !/[A-Z]/.test(k) ? k : k.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`);
|
|
@@ -17,6 +16,6 @@ var styleObjectForEach = (style, fn) => {
|
|
|
17
16
|
}
|
|
18
17
|
};
|
|
19
18
|
export {
|
|
20
|
-
|
|
19
|
+
normalizeIntrinsicElementKey,
|
|
21
20
|
styleObjectForEach
|
|
22
21
|
};
|
|
@@ -28,7 +28,12 @@ var cors = (options) => {
|
|
|
28
28
|
set("Access-Control-Allow-Origin", allowOrigin);
|
|
29
29
|
}
|
|
30
30
|
if (opts.origin !== "*") {
|
|
31
|
-
|
|
31
|
+
const existingVary = c.req.header("Vary");
|
|
32
|
+
if (existingVary) {
|
|
33
|
+
set("Vary", existingVary);
|
|
34
|
+
} else {
|
|
35
|
+
set("Vary", "Origin");
|
|
36
|
+
}
|
|
32
37
|
}
|
|
33
38
|
if (opts.credentials) {
|
|
34
39
|
set("Access-Control-Allow-Credentials", "true");
|
|
@@ -33,9 +33,11 @@ var serveStatic = (options) => {
|
|
|
33
33
|
return await next();
|
|
34
34
|
}
|
|
35
35
|
pathWithOutDefaultDocument = pathResolve(pathWithOutDefaultDocument);
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
if (pathWithOutDefaultDocument !== path) {
|
|
37
|
+
content = await getContent(pathWithOutDefaultDocument, c);
|
|
38
|
+
if (content) {
|
|
39
|
+
path = pathWithOutDefaultDocument;
|
|
40
|
+
}
|
|
39
41
|
}
|
|
40
42
|
}
|
|
41
43
|
if (content instanceof Response) {
|
package/dist/request.js
CHANGED
|
@@ -53,12 +53,7 @@ var HonoRequest = class {
|
|
|
53
53
|
return headerData;
|
|
54
54
|
}
|
|
55
55
|
async parseBody(options) {
|
|
56
|
-
|
|
57
|
-
return this.bodyCache.parsedBody;
|
|
58
|
-
}
|
|
59
|
-
const parsedBody = await parseBody(this, options);
|
|
60
|
-
this.bodyCache.parsedBody = parsedBody;
|
|
61
|
-
return parsedBody;
|
|
56
|
+
return this.bodyCache.parsedBody ??= await parseBody(this, options);
|
|
62
57
|
}
|
|
63
58
|
cachedBody = (key) => {
|
|
64
59
|
const { bodyCache, raw } = this;
|
|
@@ -66,19 +61,14 @@ var HonoRequest = class {
|
|
|
66
61
|
if (cachedBody) {
|
|
67
62
|
return cachedBody;
|
|
68
63
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
64
|
+
const anyCachedKey = Object.keys(bodyCache)[0];
|
|
65
|
+
if (anyCachedKey) {
|
|
66
|
+
return bodyCache[anyCachedKey].then((body) => {
|
|
67
|
+
if (anyCachedKey === "json") {
|
|
68
|
+
body = JSON.stringify(body);
|
|
73
69
|
}
|
|
74
|
-
return
|
|
75
|
-
|
|
76
|
-
if (keyOfBodyCache === "json") {
|
|
77
|
-
body = JSON.stringify(body);
|
|
78
|
-
}
|
|
79
|
-
return await new Response(body)[key]();
|
|
80
|
-
})();
|
|
81
|
-
}
|
|
70
|
+
return new Response(body)[key]();
|
|
71
|
+
});
|
|
82
72
|
}
|
|
83
73
|
return bodyCache[key] = raw[key]();
|
|
84
74
|
};
|
package/dist/types/context.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { HonoRequest } from './request';
|
|
2
2
|
import type { Env, FetchEventLike, Input, NotFoundHandler, TypedResponse } from './types';
|
|
3
3
|
import type { RedirectStatusCode, StatusCode } from './utils/http-status';
|
|
4
|
-
import type { IsAny, JSONParsed, JSONValue,
|
|
4
|
+
import type { IsAny, JSONParsed, JSONValue, SimplifyDeepArray } from './utils/types';
|
|
5
5
|
type HeaderRecord = Record<string, string | string[]>;
|
|
6
6
|
/**
|
|
7
7
|
* Data type can be a string, ArrayBuffer, or ReadableStream.
|
|
@@ -95,8 +95,8 @@ interface BodyRespond extends NewResponse {
|
|
|
95
95
|
* @returns {Response & TypedResponse<T, U, 'text'>} - The response after rendering the text content, typed with the provided text and status code types.
|
|
96
96
|
*/
|
|
97
97
|
interface TextRespond {
|
|
98
|
-
<T extends string, U extends StatusCode>(text: T, status?: U, headers?: HeaderRecord): Response & TypedResponse<T, U, 'text'>;
|
|
99
|
-
<T extends string, U extends StatusCode>(text: T, init?: ResponseInit): Response & TypedResponse<T, U, 'text'>;
|
|
98
|
+
<T extends string, U extends StatusCode = StatusCode>(text: T, status?: U, headers?: HeaderRecord): Response & TypedResponse<T, U, 'text'>;
|
|
99
|
+
<T extends string, U extends StatusCode = StatusCode>(text: T, init?: ResponseInit): Response & TypedResponse<T, U, 'text'>;
|
|
100
100
|
}
|
|
101
101
|
/**
|
|
102
102
|
* Interface for responding with JSON.
|
|
@@ -109,12 +109,19 @@ interface TextRespond {
|
|
|
109
109
|
* @param {U} [status] - An optional status code for the response.
|
|
110
110
|
* @param {HeaderRecord} [headers] - An optional record of headers to include in the response.
|
|
111
111
|
*
|
|
112
|
-
* @returns {
|
|
112
|
+
* @returns {JSONRespondReturn<T, U>} - The response after rendering the JSON object, typed with the provided object and status code types.
|
|
113
113
|
*/
|
|
114
114
|
interface JSONRespond {
|
|
115
|
-
<T extends JSONValue |
|
|
116
|
-
<T extends JSONValue |
|
|
115
|
+
<T extends JSONValue | SimplifyDeepArray<unknown>, U extends StatusCode = StatusCode>(object: T, status?: U, headers?: HeaderRecord): JSONRespondReturn<T, U>;
|
|
116
|
+
<T extends JSONValue | SimplifyDeepArray<unknown>, U extends StatusCode = StatusCode>(object: T, init?: ResponseInit): JSONRespondReturn<T, U>;
|
|
117
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* @template T - The type of the JSON value or simplified unknown type.
|
|
120
|
+
* @template U - The type of the status code.
|
|
121
|
+
*
|
|
122
|
+
* @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.
|
|
123
|
+
*/
|
|
124
|
+
type JSONRespondReturn<T extends JSONValue | SimplifyDeepArray<unknown>, U extends StatusCode> = Response & TypedResponse<SimplifyDeepArray<T> extends JSONValue ? JSONValue extends SimplifyDeepArray<T> ? never : JSONParsed<T> : never, U, 'json'>;
|
|
118
125
|
/**
|
|
119
126
|
* Interface representing a function that responds with HTML content.
|
|
120
127
|
*
|
|
@@ -401,7 +408,7 @@ export declare class Context<E extends Env = any, P extends string = any, I exte
|
|
|
401
408
|
* })
|
|
402
409
|
* ```
|
|
403
410
|
*/
|
|
404
|
-
redirect: (location: string, status?:
|
|
411
|
+
redirect: <T extends RedirectStatusCode = 302>(location: string, status?: T | undefined) => Response & TypedResponse<undefined, T, "redirect">;
|
|
405
412
|
/**
|
|
406
413
|
* `.notFound()` can return the Not Found Response.
|
|
407
414
|
*
|
|
@@ -2,39 +2,4 @@
|
|
|
2
2
|
* @module
|
|
3
3
|
* ConnInfo Helper for Hono.
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
|
-
export type AddressType = 'IPv6' | 'IPv4' | 'unknown';
|
|
7
|
-
export type NetAddrInfo = {
|
|
8
|
-
/**
|
|
9
|
-
* Transport protocol type
|
|
10
|
-
*/
|
|
11
|
-
transport?: 'tcp' | 'udp';
|
|
12
|
-
/**
|
|
13
|
-
* Transport port number
|
|
14
|
-
*/
|
|
15
|
-
port?: number;
|
|
16
|
-
address?: string;
|
|
17
|
-
addressType?: AddressType;
|
|
18
|
-
} & ({
|
|
19
|
-
/**
|
|
20
|
-
* Host name such as IP Addr
|
|
21
|
-
*/
|
|
22
|
-
address: string;
|
|
23
|
-
/**
|
|
24
|
-
* Host name type
|
|
25
|
-
*/
|
|
26
|
-
addressType: AddressType;
|
|
27
|
-
} | {});
|
|
28
|
-
/**
|
|
29
|
-
* HTTP Connection infomation
|
|
30
|
-
*/
|
|
31
|
-
export interface ConnInfo {
|
|
32
|
-
/**
|
|
33
|
-
* Remote infomation
|
|
34
|
-
*/
|
|
35
|
-
remote: NetAddrInfo;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Helper type
|
|
39
|
-
*/
|
|
40
|
-
export type GetConnInfo = (c: Context) => ConnInfo;
|
|
5
|
+
export type { AddressType, NetAddrInfo, ConnInfo, GetConnInfo } from './types';
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Context } from '../../context';
|
|
2
|
+
export type AddressType = 'IPv6' | 'IPv4' | 'unknown';
|
|
3
|
+
export type NetAddrInfo = {
|
|
4
|
+
/**
|
|
5
|
+
* Transport protocol type
|
|
6
|
+
*/
|
|
7
|
+
transport?: 'tcp' | 'udp';
|
|
8
|
+
/**
|
|
9
|
+
* Transport port number
|
|
10
|
+
*/
|
|
11
|
+
port?: number;
|
|
12
|
+
address?: string;
|
|
13
|
+
addressType?: AddressType;
|
|
14
|
+
} & ({
|
|
15
|
+
/**
|
|
16
|
+
* Host name such as IP Addr
|
|
17
|
+
*/
|
|
18
|
+
address: string;
|
|
19
|
+
/**
|
|
20
|
+
* Host name type
|
|
21
|
+
*/
|
|
22
|
+
addressType: AddressType;
|
|
23
|
+
} | {});
|
|
24
|
+
/**
|
|
25
|
+
* HTTP Connection infomation
|
|
26
|
+
*/
|
|
27
|
+
export interface ConnInfo {
|
|
28
|
+
/**
|
|
29
|
+
* Remote infomation
|
|
30
|
+
*/
|
|
31
|
+
remote: NetAddrInfo;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Helper type
|
|
35
|
+
*/
|
|
36
|
+
export type GetConnInfo = (c: Context) => ConnInfo;
|
|
@@ -98,7 +98,7 @@ declare class Hono<E extends Env = Env, S extends Schema = {}, BasePath extends
|
|
|
98
98
|
* app.route("/api", app2) // GET /api/user
|
|
99
99
|
* ```
|
|
100
100
|
*/
|
|
101
|
-
route<SubPath extends string, SubEnv extends Env, SubSchema extends Schema, SubBasePath extends string>(path: SubPath, app
|
|
101
|
+
route<SubPath extends string, SubEnv extends Env, SubSchema extends Schema, SubBasePath extends string>(path: SubPath, app: Hono<SubEnv, SubSchema, SubBasePath>): Hono<E, MergeSchemaPath<SubSchema, MergePath<BasePath, SubPath>> & S, BasePath>;
|
|
102
102
|
/**
|
|
103
103
|
* `.basePath()` allows base paths to be specified.
|
|
104
104
|
*
|
package/dist/types/jsx/base.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { HtmlEscaped, HtmlEscapedString, StringBuffer } from '../utils/html';
|
|
2
2
|
import type { Context } from './context';
|
|
3
|
-
import type {
|
|
3
|
+
import type { JSX as HonoJSX, IntrinsicElements as IntrinsicElementsDefined } from './intrinsic-elements';
|
|
4
4
|
export type Props = Record<string, any>;
|
|
5
5
|
export type FC<P = Props> = {
|
|
6
6
|
(props: P): HtmlEscapedString | Promise<HtmlEscapedString>;
|
|
7
7
|
defaultProps?: Partial<P> | undefined;
|
|
8
8
|
displayName?: string | undefined;
|
|
9
9
|
};
|
|
10
|
-
export type DOMAttributes =
|
|
10
|
+
export type DOMAttributes = HonoJSX.HTMLAttributes;
|
|
11
11
|
export declare namespace JSX {
|
|
12
12
|
type Element = HtmlEscapedString | Promise<HtmlEscapedString>;
|
|
13
13
|
interface ElementChildrenAttribute {
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* MIT License
|
|
5
5
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
6
6
|
*/
|
|
7
|
-
export declare namespace
|
|
7
|
+
export declare namespace JSX {
|
|
8
8
|
export type CrossOrigin = 'anonymous' | 'use-credentials' | '' | undefined;
|
|
9
9
|
export type CSSProperties = {};
|
|
10
10
|
type AnyAttributes = {
|
|
@@ -636,5 +636,5 @@ export declare namespace Hono {
|
|
|
636
636
|
}
|
|
637
637
|
export {};
|
|
638
638
|
}
|
|
639
|
-
export interface IntrinsicElements extends
|
|
639
|
+
export interface IntrinsicElements extends JSX.IntrinsicElements {
|
|
640
640
|
}
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
* All types exported from "hono/jsx" are in this file.
|
|
3
3
|
*/
|
|
4
4
|
import type { Child, JSXNode } from './base';
|
|
5
|
-
import type {
|
|
5
|
+
import type { JSX } from './intrinsic-elements';
|
|
6
6
|
export type { Child, JSXNode, FC } from './base';
|
|
7
7
|
export type { RefObject } from './hooks';
|
|
8
8
|
export type { Context } from './context';
|
|
9
9
|
export type PropsWithChildren<P = unknown> = P & {
|
|
10
10
|
children?: Child | undefined;
|
|
11
11
|
};
|
|
12
|
-
export type CSSProperties =
|
|
12
|
+
export type CSSProperties = JSX.CSSProperties;
|
|
13
13
|
/**
|
|
14
14
|
* React types
|
|
15
15
|
*/
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const
|
|
1
|
+
export declare const normalizeIntrinsicElementKey: (key: string) => string;
|
|
2
2
|
export declare const styleObjectForEach: (style: Record<string, string | number>, fn: (key: string, value: string | null) => void) => void;
|
package/dist/types/types.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import type { Context } from './context';
|
|
6
6
|
import type { Hono } from './hono';
|
|
7
7
|
import type { StatusCode } from './utils/http-status';
|
|
8
|
-
import type { IfAnyThenEmptyObject, IsAny, JSONValue,
|
|
8
|
+
import type { IfAnyThenEmptyObject, IsAny, JSONValue, RemoveBlankRecord, Simplify, UnionToIntersection } from './utils/types';
|
|
9
9
|
export type Bindings = Record<string, unknown>;
|
|
10
10
|
export type Variables = Record<string, unknown>;
|
|
11
11
|
export type BlankEnv = {};
|
|
@@ -32,7 +32,10 @@ export type Handler<E extends Env = any, P extends string = any, I extends Input
|
|
|
32
32
|
export type MiddlewareHandler<E extends Env = any, P extends string = string, I extends Input = {}> = (c: Context<E, P, I>, next: Next) => Promise<Response | void>;
|
|
33
33
|
export type H<E extends Env = any, P extends string = any, I extends Input = BlankInput, R extends HandlerResponse<any> = any> = Handler<E, P, I, R> | MiddlewareHandler<E, P, I>;
|
|
34
34
|
export type NotFoundHandler<E extends Env = any> = (c: Context<E>) => Response | Promise<Response>;
|
|
35
|
-
export
|
|
35
|
+
export interface HTTPResponseError extends Error {
|
|
36
|
+
getResponse: () => Response;
|
|
37
|
+
}
|
|
38
|
+
export type ErrorHandler<E extends Env = any> = (err: Error | HTTPResponseError, c: Context<E>) => Response | Promise<Response>;
|
|
36
39
|
export interface HandlerInterface<E extends Env = Env, M extends string = string, S extends Schema = BlankSchema, BasePath extends string = '/'> {
|
|
37
40
|
<P extends string = ExtractKey<S> extends never ? BasePath : ExtractKey<S>, I extends Input = BlankInput, R extends HandlerResponse<any> = any, E2 extends Env = E>(handler: H<E2, P, I, R>): Hono<IntersectNonAnyTypes<[E, E2]>, S & ToSchema<M, P, I, MergeTypedResponse<R>>, BasePath>;
|
|
38
41
|
<P extends string, MergedPath extends MergePath<BasePath, P> = MergePath<BasePath, P>, R extends HandlerResponse<any> = any, I extends Input = BlankInput, E2 extends Env = E>(path: P, handler: H<E2, MergedPath, I, R>): Hono<IntersectNonAnyTypes<[E, E2]>, S & ToSchema<M, MergePath<BasePath, P>, I, MergeTypedResponse<R>>, BasePath>;
|
|
@@ -367,7 +370,7 @@ export interface OnHandlerInterface<E extends Env = Env, S extends Schema = Blan
|
|
|
367
370
|
<I extends Input = BlankInput, R extends HandlerResponse<any> = any>(methods: string | string[], paths: string[], ...handlers: H<E, any, I, R>[]): Hono<E, S & ToSchema<string, string, I, MergeTypedResponse<R>>, BasePath>;
|
|
368
371
|
}
|
|
369
372
|
type ExtractKey<S> = S extends Record<infer Key, unknown> ? Key extends string ? Key : never : string;
|
|
370
|
-
export type ToSchema<M extends string, P extends string, I extends Input | Input['in'], RorO> =
|
|
373
|
+
export type ToSchema<M extends string, P extends string, I extends Input | Input['in'], RorO> = Simplify<{
|
|
371
374
|
[K in P]: {
|
|
372
375
|
[K2 in M as AddDollar<K2>]: Simplify<{
|
|
373
376
|
input: AddParam<ExtractInput<I>, P>;
|
|
@@ -409,7 +412,7 @@ type ExtractParams<Path extends string> = string extends Path ? Record<string, s
|
|
|
409
412
|
type FlattenIfIntersect<T> = T extends infer O ? {
|
|
410
413
|
[K in keyof O]: O[K];
|
|
411
414
|
} : never;
|
|
412
|
-
export type MergeSchemaPath<OrigSchema extends Schema, SubPath extends string> =
|
|
415
|
+
export type MergeSchemaPath<OrigSchema extends Schema, SubPath extends string> = Simplify<{
|
|
413
416
|
[P in keyof OrigSchema as MergePath<SubPath, P & string>]: {
|
|
414
417
|
[M in keyof OrigSchema[P]]: MergeEndpointParamsWithPath<OrigSchema[P][M], SubPath>;
|
|
415
418
|
};
|
|
@@ -442,12 +445,12 @@ export type AddParam<I, P extends string> = ParamKeys<P> extends never ? I : I e
|
|
|
442
445
|
};
|
|
443
446
|
type AddDollar<T extends string> = `$${Lowercase<T>}`;
|
|
444
447
|
export type MergePath<A extends string, B extends string> = B extends '' ? MergePath<A, '/'> : A extends '' ? B : A extends '/' ? B : A extends `${infer P}/` ? B extends `/${infer Q}` ? `${P}/${Q}` : `${P}/${B}` : B extends `/${infer Q}` ? Q extends '' ? A : `${A}/${Q}` : `${A}/${B}`;
|
|
445
|
-
export type KnownResponseFormat = 'json' | 'text';
|
|
448
|
+
export type KnownResponseFormat = 'json' | 'text' | 'redirect';
|
|
446
449
|
export type ResponseFormat = KnownResponseFormat | string;
|
|
447
450
|
export type TypedResponse<T = unknown, U extends StatusCode = StatusCode, F extends ResponseFormat = T extends string ? 'text' : T extends JSONValue ? 'json' : ResponseFormat> = {
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
+
_data: T;
|
|
452
|
+
_status: U;
|
|
453
|
+
_format: F;
|
|
451
454
|
};
|
|
452
455
|
type MergeTypedResponse<T> = T extends Promise<infer T2> ? T2 extends TypedResponse ? T2 : TypedResponse : T extends TypedResponse ? T : TypedResponse;
|
|
453
456
|
export type ValidationTargets = {
|
|
@@ -19,9 +19,19 @@ export type JSONParsed<T> = T extends {
|
|
|
19
19
|
} ? (() => J) extends () => JSONObject ? J : JSONParsed<J> : T extends JSONPrimitive ? T : T extends Array<infer U> ? Array<JSONParsed<U>> : T extends object ? {
|
|
20
20
|
[K in keyof T]: JSONParsed<T[K]>;
|
|
21
21
|
} : never;
|
|
22
|
+
/**
|
|
23
|
+
* Useful to flatten the type output to improve type hints shown in editors. And also to transform an interface into a type to aide with assignability.
|
|
24
|
+
* @copyright from sindresorhus/type-fest
|
|
25
|
+
*/
|
|
22
26
|
export type Simplify<T> = {
|
|
23
27
|
[KeyType in keyof T]: T[KeyType];
|
|
24
28
|
} & {};
|
|
29
|
+
/**
|
|
30
|
+
* A simple extension of Simplify that will deeply traverse array elements.
|
|
31
|
+
*/
|
|
32
|
+
export type SimplifyDeepArray<T> = T extends any[] ? {
|
|
33
|
+
[E in keyof T]: SimplifyDeepArray<T[E]>;
|
|
34
|
+
} : Simplify<T>;
|
|
25
35
|
export type InterfaceToType<T> = T extends Function ? T : {
|
|
26
36
|
[K in keyof T]: InterfaceToType<T[K]>;
|
|
27
37
|
};
|
|
@@ -30,6 +40,3 @@ export type RequiredKeysOf<BaseType extends object> = Exclude<{
|
|
|
30
40
|
}[keyof BaseType], undefined>;
|
|
31
41
|
export type HasRequiredKeys<BaseType extends object> = RequiredKeysOf<BaseType> extends never ? false : true;
|
|
32
42
|
export type IsAny<T> = boolean extends (T extends never ? true : false) ? true : false;
|
|
33
|
-
export type Prettify<T> = {
|
|
34
|
-
[K in keyof T]: T[K];
|
|
35
|
-
} & {};
|
package/dist/utils/filepath.js
CHANGED
|
@@ -4,7 +4,7 @@ var getFilePath = (options) => {
|
|
|
4
4
|
const defaultDocument = options.defaultDocument || "index.html";
|
|
5
5
|
if (filename.endsWith("/")) {
|
|
6
6
|
filename = filename.concat(defaultDocument);
|
|
7
|
-
} else if (!filename.match(/\.[a-zA-Z0-
|
|
7
|
+
} else if (!filename.match(/\.[a-zA-Z0-9_-]+$/)) {
|
|
8
8
|
filename = filename.concat("/" + defaultDocument);
|
|
9
9
|
}
|
|
10
10
|
const path = getFilePathWithoutDefaultDocument({
|