vinojs 0.1.0 → 0.1.2
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/client.mjs +1 -1
- package/dist/{compile-Lxl_tdxL.mjs → compile-glNMkyyx.mjs} +3 -47
- package/dist/compile-glNMkyyx.mjs.map +1 -0
- package/dist/{definePage-Ba4r-TFh.mjs → definePage--9Pz7rHs.mjs} +29 -7
- package/dist/definePage--9Pz7rHs.mjs.map +1 -0
- package/dist/defineServerFn-H-bz7xBX.mjs +47 -0
- package/dist/defineServerFn-H-bz7xBX.mjs.map +1 -0
- package/dist/factory-CVT0-OZw.d.mts +187 -0
- package/dist/factory-CVT0-OZw.d.mts.map +1 -0
- package/dist/factory.d.mts +2 -0
- package/dist/factory.mjs +153 -0
- package/dist/factory.mjs.map +1 -0
- package/dist/vino.d.mts +4 -103
- package/dist/vino.d.mts.map +1 -1
- package/dist/vino.mjs +8 -3
- package/dist/vino.mjs.map +1 -1
- package/dist/vite.mjs +3 -2
- package/dist/vite.mjs.map +1 -1
- package/package.json +5 -1
- package/dist/compile-Lxl_tdxL.mjs.map +0 -1
- package/dist/definePage-Ba4r-TFh.mjs.map +0 -1
- package/examples/basic/dist/client/.assetsignore +0 -2
- package/examples/basic/dist/client/about.html +0 -1
- package/examples/basic/dist/client/admin.html +0 -1
- package/examples/basic/dist/client/assets/Counter-BvqMZKON.js +0 -1
- package/examples/basic/dist/client/assets/_slug_-CYpOSbrn.js +0 -1
- package/examples/basic/dist/client/assets/about-BZXRzUyv.js +0 -1
- package/examples/basic/dist/client/assets/admin-DRE7uh2s.js +0 -1
- package/examples/basic/dist/client/assets/client-B6nFkut5.js +0 -1
- package/examples/basic/dist/client/assets/client-pages-Bc6cNZAm.js +0 -2
- package/examples/basic/dist/client/assets/components-DX9r6vHn.js +0 -1
- package/examples/basic/dist/client/assets/components-DsWJ6F73.js +0 -2
- package/examples/basic/dist/client/assets/counter-DBpvln_F.js +0 -1
- package/examples/basic/dist/client/assets/dom-B5sHIJ1E.js +0 -1
- package/examples/basic/dist/client/assets/honoto-9UtdLp4J.js +0 -33
- package/examples/basic/dist/client/assets/honoto-client-DEh86_WZ.css +0 -1
- package/examples/basic/dist/client/assets/honoto-client.js +0 -2
- package/examples/basic/dist/client/assets/hooks-Cz6AT21d.js +0 -1
- package/examples/basic/dist/client/assets/jsx-dev-runtime-92VDsVyo.js +0 -1
- package/examples/basic/dist/client/counter.html +0 -1
- package/examples/basic/dist/client/index.html +0 -1
- package/examples/basic/dist/client/jobs.html +0 -1
- package/examples/basic/dist/ssr/.vite/manifest.json +0 -140
- package/examples/basic/dist/ssr/assets/_slug_-CY3-kffX.js +0 -46
- package/examples/basic/dist/ssr/assets/about-CTDjNhkO.js +0 -15
- package/examples/basic/dist/ssr/assets/admin-DvS-UGJx.js +0 -26
- package/examples/basic/dist/ssr/assets/constants-UoriGYcX-CUecBFMT.js +0 -6
- package/examples/basic/dist/ssr/assets/counter-DfIbc9Sp.js +0 -30
- package/examples/basic/dist/ssr/assets/honoto-CA313cVy.js +0 -2129
- package/examples/basic/dist/ssr/assets/jobs-D9hh-UO9.js +0 -42
- package/examples/basic/dist/ssr/assets/jsx-CgYLQazd.js +0 -1080
- package/examples/basic/dist/ssr/assets/jsx-dev-runtime-BlUda7H8.js +0 -742
- package/examples/basic/dist/ssr/assets/jsx-renderer-CzZcZPnS.js +0 -65
- package/examples/basic/dist/ssr/assets/layout-DYvLwr2u.js +0 -53
- package/examples/basic/dist/ssr/assets/pages-DB6jeyrt.js +0 -53
- package/examples/basic/dist/ssr/assets/rolldown-runtime-D7D4PA-g.js +0 -13
- package/examples/basic/dist/ssr/assets/ssr-hooks-CBQr0cdH.js +0 -7
- package/examples/basic/dist/ssr/index.js +0 -22
- package/examples/basic/dist/ssr/wrangler.json +0 -1
- package/examples/full/dist/client/.assetsignore +0 -2
- package/examples/full/dist/client/assets/BookmarkButton-py0xGxgl.js +0 -1
- package/examples/full/dist/client/assets/_slug_-DZUFsE9O.js +0 -1
- package/examples/full/dist/client/assets/auth-client-D2Wtuobe.js +0 -1
- package/examples/full/dist/client/assets/bun-sqlite-dialect-C7ftEUSI-CsHdUKBY.js +0 -1
- package/examples/full/dist/client/assets/client-B6nFkut5.js +0 -1
- package/examples/full/dist/client/assets/client-pages-fshKs747.js +0 -2
- package/examples/full/dist/client/assets/components-DX9r6vHn.js +0 -1
- package/examples/full/dist/client/assets/components-S_-rWrKi.js +0 -2
- package/examples/full/dist/client/assets/d1-sqlite-dialect-BZmaVTp8-FPCaMZqX.js +0 -1
- package/examples/full/dist/client/assets/default-query-compiler-CUdqIu1h.js +0 -1
- package/examples/full/dist/client/assets/dist-BoGTNvkC.js +0 -1
- package/examples/full/dist/client/assets/dom-DCd3wYW7.js +0 -1
- package/examples/full/dist/client/assets/factory-Bgf4EtLx.js +0 -8
- package/examples/full/dist/client/assets/honoto-client-BSvNAnxN.css +0 -1
- package/examples/full/dist/client/assets/honoto-client.js +0 -2
- package/examples/full/dist/client/assets/hooks-Cz6AT21d.js +0 -1
- package/examples/full/dist/client/assets/jsx-dev-runtime-92VDsVyo.js +0 -1
- package/examples/full/dist/client/assets/kysely-adapter-BHhasAnc.js +0 -1
- package/examples/full/dist/client/assets/kysely-migration-tables-DFfmKhq--U5ujlMwE.js +0 -1
- package/examples/full/dist/client/assets/node-sqlite-dialect-DJDXH5Ot.js +0 -1
- package/examples/full/dist/client/assets/pages-CUQx6Eus.js +0 -1
- package/examples/full/dist/client/assets/saved-jIi74ncJ.js +0 -1
- package/examples/full/dist/client/assets/session-B-accyM3.js +0 -611
- package/examples/full/dist/client/assets/sign-in-BelI3gSs.js +0 -1
- package/examples/full/dist/client/assets/sign-up-pR94lfdu.js +0 -1
- package/examples/full/dist/client/index.html +0 -1
- package/examples/full/dist/client/saved.html +0 -1
- package/examples/full/dist/client/sign-in.html +0 -1
- package/examples/full/dist/client/sign-up.html +0 -1
- package/examples/full/dist/ssr/.dev.vars +0 -1
- package/examples/full/dist/ssr/.vite/manifest.json +0 -219
- package/examples/full/dist/ssr/assets/BookmarkButton-KS7z5_vi.js +0 -298
- package/examples/full/dist/ssr/assets/_slug_-rRStRaAN.js +0 -89
- package/examples/full/dist/ssr/assets/auth-DSFZ4iak.js +0 -31434
- package/examples/full/dist/ssr/assets/auth-client-BFSBVoML.js +0 -894
- package/examples/full/dist/ssr/assets/bun-sqlite-dialect-C7ftEUSI-BeXpIqKl.js +0 -162
- package/examples/full/dist/ssr/assets/compiled-query-DmoyCh28.js +0 -8410
- package/examples/full/dist/ssr/assets/d1-sqlite-dialect-BZmaVTp8-CjJdvL94.js +0 -114
- package/examples/full/dist/ssr/assets/default-query-compiler-D7xOzCCJ.js +0 -1727
- package/examples/full/dist/ssr/assets/dist-LmmDoNdk.js +0 -6832
- package/examples/full/dist/ssr/assets/dist-kFDN1l4Z.js +0 -342
- package/examples/full/dist/ssr/assets/factory-AD6s9SIW.js +0 -2079
- package/examples/full/dist/ssr/assets/jsx-renderer-mMLf5XLN.js +0 -1926
- package/examples/full/dist/ssr/assets/kysely-adapter-BCLenpM8.js +0 -2
- package/examples/full/dist/ssr/assets/kysely-migration-tables-DFfmKhq--BtVr6hRe.js +0 -17
- package/examples/full/dist/ssr/assets/layout-mVA7qP4j.js +0 -44
- package/examples/full/dist/ssr/assets/node-sqlite-dialect-D-wtYAD7.js +0 -162
- package/examples/full/dist/ssr/assets/pages-Do5kR_Ia.js +0 -147
- package/examples/full/dist/ssr/assets/saved-Dr4pP6B5.js +0 -111
- package/examples/full/dist/ssr/assets/session-BvIpX7tr.js +0 -13
- package/examples/full/dist/ssr/assets/sign-in-22pzTnJE.js +0 -115
- package/examples/full/dist/ssr/assets/sign-up-CN4j8Qg1.js +0 -117
- package/examples/full/dist/ssr/assets/sqlite-adapter-DVlms5wO.js +0 -79
- package/examples/full/dist/ssr/index.js +0 -97
- package/examples/full/dist/ssr/wrangler.json +0 -1
|
@@ -1,2129 +0,0 @@
|
|
|
1
|
-
import { C as HtmlEscapedCallbackPhase, E as resolveCallback, t as jsxDEV } from "./jsx-dev-runtime-BlUda7H8.js";
|
|
2
|
-
import { n as PAGE_SLOT_ID, r as PAYLOAD_SCRIPT_ID } from "./constants-UoriGYcX-CUecBFMT.js";
|
|
3
|
-
import { t as jsxRenderer } from "./jsx-renderer-CzZcZPnS.js";
|
|
4
|
-
//#region ../../node_modules/.pnpm/hono@4.13.3/node_modules/hono/dist/compose.js
|
|
5
|
-
var compose = (middleware, onError, onNotFound) => {
|
|
6
|
-
return (context, next) => {
|
|
7
|
-
let index = -1;
|
|
8
|
-
return dispatch(0);
|
|
9
|
-
async function dispatch(i) {
|
|
10
|
-
if (i <= index) throw new Error("next() called multiple times");
|
|
11
|
-
index = i;
|
|
12
|
-
let res;
|
|
13
|
-
let isError = false;
|
|
14
|
-
let handler;
|
|
15
|
-
if (middleware[i]) {
|
|
16
|
-
handler = middleware[i][0][0];
|
|
17
|
-
context.req.routeIndex = i;
|
|
18
|
-
} else handler = i === middleware.length && next || void 0;
|
|
19
|
-
if (handler) try {
|
|
20
|
-
res = await handler(context, () => dispatch(i + 1));
|
|
21
|
-
} catch (err) {
|
|
22
|
-
if (err instanceof Error && onError) {
|
|
23
|
-
context.error = err;
|
|
24
|
-
res = await onError(err, context);
|
|
25
|
-
isError = true;
|
|
26
|
-
} else throw err;
|
|
27
|
-
}
|
|
28
|
-
else if (context.finalized === false && onNotFound) res = await onNotFound(context);
|
|
29
|
-
if (res && (context.finalized === false || isError)) context.res = res;
|
|
30
|
-
return context;
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
};
|
|
34
|
-
//#endregion
|
|
35
|
-
//#region ../../node_modules/.pnpm/hono@4.13.3/node_modules/hono/dist/request/constants.js
|
|
36
|
-
var GET_MATCH_RESULT = /* @__PURE__ */ Symbol();
|
|
37
|
-
//#endregion
|
|
38
|
-
//#region ../../node_modules/.pnpm/hono@4.13.3/node_modules/hono/dist/utils/buffer.js
|
|
39
|
-
var bufferToFormData = (arrayBuffer, contentType) => {
|
|
40
|
-
return new Response(arrayBuffer, { headers: { "Content-Type": contentType.replace(/^[^;]+/, (mediaType) => mediaType.toLowerCase()) } }).formData();
|
|
41
|
-
};
|
|
42
|
-
//#endregion
|
|
43
|
-
//#region ../../node_modules/.pnpm/hono@4.13.3/node_modules/hono/dist/utils/body.js
|
|
44
|
-
var isRawRequest = (request) => "headers" in request;
|
|
45
|
-
var parseBody = async (request, options = /* @__PURE__ */ Object.create(null)) => {
|
|
46
|
-
const { all = false, dot = false } = options;
|
|
47
|
-
const mediaType = (isRawRequest(request) ? request.headers : request.raw.headers).get("Content-Type")?.split(";")[0].trim().toLowerCase();
|
|
48
|
-
if (mediaType === "multipart/form-data" || mediaType === "application/x-www-form-urlencoded") return parseFormData(request, {
|
|
49
|
-
all,
|
|
50
|
-
dot
|
|
51
|
-
});
|
|
52
|
-
return {};
|
|
53
|
-
};
|
|
54
|
-
async function parseFormData(request, options) {
|
|
55
|
-
if (!isRawRequest(request) && request.bodyCache.formData) return convertFormDataToBodyData(await request.bodyCache.formData, options);
|
|
56
|
-
const headers = isRawRequest(request) ? request.headers : request.raw.headers;
|
|
57
|
-
const formDataPromise = bufferToFormData(await request.arrayBuffer(), headers.get("Content-Type") || "");
|
|
58
|
-
if (!isRawRequest(request)) request.bodyCache.formData = formDataPromise;
|
|
59
|
-
const formData = await formDataPromise;
|
|
60
|
-
if (formData) return convertFormDataToBodyData(formData, options);
|
|
61
|
-
return {};
|
|
62
|
-
}
|
|
63
|
-
function convertFormDataToBodyData(formData, options) {
|
|
64
|
-
const form = /* @__PURE__ */ Object.create(null);
|
|
65
|
-
formData.forEach((value, key) => {
|
|
66
|
-
if (!(options.all || key.endsWith("[]"))) form[key] = value;
|
|
67
|
-
else handleParsingAllValues(form, key, value);
|
|
68
|
-
});
|
|
69
|
-
if (options.dot) Object.entries(form).forEach(([key, value]) => {
|
|
70
|
-
if (key.includes(".")) {
|
|
71
|
-
handleParsingNestedValues(form, key, value);
|
|
72
|
-
delete form[key];
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
return form;
|
|
76
|
-
}
|
|
77
|
-
var handleParsingAllValues = (form, key, value) => {
|
|
78
|
-
if (form[key] !== void 0) {
|
|
79
|
-
if (Array.isArray(form[key])) form[key].push(value);
|
|
80
|
-
else form[key] = [form[key], value];
|
|
81
|
-
} else if (!key.endsWith("[]")) form[key] = value;
|
|
82
|
-
else form[key] = [value];
|
|
83
|
-
};
|
|
84
|
-
var handleParsingNestedValues = (form, key, value) => {
|
|
85
|
-
if (/(?:^|\.)__proto__\./.test(key)) return;
|
|
86
|
-
let nestedForm = form;
|
|
87
|
-
const keys = key.split(".");
|
|
88
|
-
keys.forEach((key2, index) => {
|
|
89
|
-
if (index === keys.length - 1) nestedForm[key2] = value;
|
|
90
|
-
else {
|
|
91
|
-
if (!nestedForm[key2] || typeof nestedForm[key2] !== "object" || Array.isArray(nestedForm[key2]) || nestedForm[key2] instanceof File) nestedForm[key2] = /* @__PURE__ */ Object.create(null);
|
|
92
|
-
nestedForm = nestedForm[key2];
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
};
|
|
96
|
-
//#endregion
|
|
97
|
-
//#region ../../node_modules/.pnpm/hono@4.13.3/node_modules/hono/dist/utils/url.js
|
|
98
|
-
var splitPath = (path) => {
|
|
99
|
-
const paths = path.split("/");
|
|
100
|
-
if (paths[0] === "") paths.shift();
|
|
101
|
-
return paths;
|
|
102
|
-
};
|
|
103
|
-
var splitRoutingPath = (routePath) => {
|
|
104
|
-
const { groups, path } = extractGroupsFromPath(routePath);
|
|
105
|
-
return replaceGroupMarks(splitPath(path), groups);
|
|
106
|
-
};
|
|
107
|
-
var extractGroupsFromPath = (path) => {
|
|
108
|
-
const groups = [];
|
|
109
|
-
path = path.replace(/\{[^}]+\}/g, (match, index) => {
|
|
110
|
-
const mark = `@${index}`;
|
|
111
|
-
groups.push([mark, match]);
|
|
112
|
-
return mark;
|
|
113
|
-
});
|
|
114
|
-
return {
|
|
115
|
-
groups,
|
|
116
|
-
path
|
|
117
|
-
};
|
|
118
|
-
};
|
|
119
|
-
var replaceGroupMarks = (paths, groups) => {
|
|
120
|
-
for (let i = groups.length - 1; i >= 0; i--) {
|
|
121
|
-
const [mark] = groups[i];
|
|
122
|
-
for (let j = paths.length - 1; j >= 0; j--) if (paths[j].includes(mark)) {
|
|
123
|
-
paths[j] = paths[j].replace(mark, groups[i][1]);
|
|
124
|
-
break;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
return paths;
|
|
128
|
-
};
|
|
129
|
-
var patternCache = {};
|
|
130
|
-
var getPattern = (label, next) => {
|
|
131
|
-
if (label === "*") return "*";
|
|
132
|
-
const match = label.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
|
|
133
|
-
if (match) {
|
|
134
|
-
const cacheKey = `${label}#${next}`;
|
|
135
|
-
if (!patternCache[cacheKey]) {
|
|
136
|
-
if (match[2]) patternCache[cacheKey] = next && next[0] !== ":" && next[0] !== "*" ? [
|
|
137
|
-
cacheKey,
|
|
138
|
-
match[1],
|
|
139
|
-
new RegExp(`^${match[2]}(?=/${next})`)
|
|
140
|
-
] : [
|
|
141
|
-
label,
|
|
142
|
-
match[1],
|
|
143
|
-
new RegExp(`^${match[2]}$`)
|
|
144
|
-
];
|
|
145
|
-
else patternCache[cacheKey] = [
|
|
146
|
-
label,
|
|
147
|
-
match[1],
|
|
148
|
-
true
|
|
149
|
-
];
|
|
150
|
-
}
|
|
151
|
-
return patternCache[cacheKey];
|
|
152
|
-
}
|
|
153
|
-
return null;
|
|
154
|
-
};
|
|
155
|
-
var tryDecode = (str, decoder) => {
|
|
156
|
-
try {
|
|
157
|
-
return decoder(str);
|
|
158
|
-
} catch {
|
|
159
|
-
return str.replace(/(?:%[0-9A-Fa-f]{2})+/g, (match) => {
|
|
160
|
-
try {
|
|
161
|
-
return decoder(match);
|
|
162
|
-
} catch {
|
|
163
|
-
return match;
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
};
|
|
168
|
-
var tryDecodeURI = (str) => tryDecode(str, decodeURI);
|
|
169
|
-
var getPath = (request) => {
|
|
170
|
-
const url = request.url;
|
|
171
|
-
const start = url.indexOf("/", url.indexOf(":") + 4);
|
|
172
|
-
let i = start;
|
|
173
|
-
for (; i < url.length; i++) {
|
|
174
|
-
const charCode = url.charCodeAt(i);
|
|
175
|
-
if (charCode === 37) {
|
|
176
|
-
const queryIndex = url.indexOf("?", i);
|
|
177
|
-
const hashIndex = url.indexOf("#", i);
|
|
178
|
-
const end = queryIndex === -1 ? hashIndex === -1 ? void 0 : hashIndex : hashIndex === -1 ? queryIndex : Math.min(queryIndex, hashIndex);
|
|
179
|
-
const path = url.slice(start, end);
|
|
180
|
-
return tryDecodeURI(path.includes("%25") ? path.replace(/%25/g, "%2525") : path);
|
|
181
|
-
} else if (charCode === 63 || charCode === 35) break;
|
|
182
|
-
}
|
|
183
|
-
return url.slice(start, i);
|
|
184
|
-
};
|
|
185
|
-
var getPathNoStrict = (request) => {
|
|
186
|
-
const result = getPath(request);
|
|
187
|
-
return result.length > 1 && result.at(-1) === "/" ? result.slice(0, -1) : result;
|
|
188
|
-
};
|
|
189
|
-
var mergePath = (base, sub, ...rest) => {
|
|
190
|
-
if (rest.length) sub = mergePath(sub, ...rest);
|
|
191
|
-
return `${base?.[0] === "/" ? "" : "/"}${base}${sub === "/" ? "" : `${base?.at(-1) === "/" ? "" : "/"}${sub?.[0] === "/" ? sub.slice(1) : sub}`}`;
|
|
192
|
-
};
|
|
193
|
-
var checkOptionalParameter = (path) => {
|
|
194
|
-
if (path.charCodeAt(path.length - 1) !== 63 || !path.includes(":")) return null;
|
|
195
|
-
const segments = path.split("/");
|
|
196
|
-
const results = [];
|
|
197
|
-
let basePath = "";
|
|
198
|
-
segments.forEach((segment) => {
|
|
199
|
-
if (segment !== "" && !/\:/.test(segment)) basePath += "/" + segment;
|
|
200
|
-
else if (/\:/.test(segment)) {
|
|
201
|
-
if (segment.charCodeAt(segment.length - 1) === 63) {
|
|
202
|
-
if (results.length === 0 && basePath === "") results.push("/");
|
|
203
|
-
else results.push(basePath);
|
|
204
|
-
const optionalSegment = segment.slice(0, -1);
|
|
205
|
-
basePath += "/" + optionalSegment;
|
|
206
|
-
results.push(basePath);
|
|
207
|
-
} else basePath += "/" + segment;
|
|
208
|
-
}
|
|
209
|
-
});
|
|
210
|
-
return results.filter((v, i, a) => a.indexOf(v) === i);
|
|
211
|
-
};
|
|
212
|
-
var tryDecodeURIComponent = (str) => str.indexOf("%") !== -1 ? tryDecode(str, decodeURIComponent_) : str;
|
|
213
|
-
var _decodeURI = (value) => {
|
|
214
|
-
if (value.indexOf("+") !== -1) value = value.replace(/\+/g, " ");
|
|
215
|
-
return tryDecodeURIComponent(value);
|
|
216
|
-
};
|
|
217
|
-
var _getQueryParam = (url, key, multiple) => {
|
|
218
|
-
let encoded;
|
|
219
|
-
if (!multiple && key && key.indexOf("%") === -1 && key.indexOf("+") === -1) {
|
|
220
|
-
let keyIndex2 = url.indexOf("?", 8);
|
|
221
|
-
if (keyIndex2 === -1) return;
|
|
222
|
-
if (!url.startsWith(key, keyIndex2 + 1)) keyIndex2 = url.indexOf(`&${key}`, keyIndex2 + 1);
|
|
223
|
-
while (keyIndex2 !== -1) {
|
|
224
|
-
const trailingKeyCode = url.charCodeAt(keyIndex2 + key.length + 1);
|
|
225
|
-
if (trailingKeyCode === 61) {
|
|
226
|
-
const valueIndex = keyIndex2 + key.length + 2;
|
|
227
|
-
const endIndex = url.indexOf("&", valueIndex);
|
|
228
|
-
return _decodeURI(url.slice(valueIndex, endIndex === -1 ? void 0 : endIndex));
|
|
229
|
-
} else if (trailingKeyCode == 38 || isNaN(trailingKeyCode)) return "";
|
|
230
|
-
keyIndex2 = url.indexOf(`&${key}`, keyIndex2 + 1);
|
|
231
|
-
}
|
|
232
|
-
encoded = /[%+]/.test(url);
|
|
233
|
-
if (!encoded) return;
|
|
234
|
-
}
|
|
235
|
-
const results = /* @__PURE__ */ Object.create(null);
|
|
236
|
-
encoded ??= /[%+]/.test(url);
|
|
237
|
-
let keyIndex = url.indexOf("?", 8);
|
|
238
|
-
while (keyIndex !== -1) {
|
|
239
|
-
const nextKeyIndex = url.indexOf("&", keyIndex + 1);
|
|
240
|
-
let valueIndex = url.indexOf("=", keyIndex);
|
|
241
|
-
if (valueIndex > nextKeyIndex && nextKeyIndex !== -1) valueIndex = -1;
|
|
242
|
-
let name = url.slice(keyIndex + 1, valueIndex === -1 ? nextKeyIndex === -1 ? void 0 : nextKeyIndex : valueIndex);
|
|
243
|
-
if (encoded) name = _decodeURI(name);
|
|
244
|
-
keyIndex = nextKeyIndex;
|
|
245
|
-
if (name === "") continue;
|
|
246
|
-
let value;
|
|
247
|
-
if (valueIndex === -1) value = "";
|
|
248
|
-
else {
|
|
249
|
-
value = url.slice(valueIndex + 1, nextKeyIndex === -1 ? void 0 : nextKeyIndex);
|
|
250
|
-
if (encoded) value = _decodeURI(value);
|
|
251
|
-
}
|
|
252
|
-
if (multiple) {
|
|
253
|
-
if (!(results[name] && Array.isArray(results[name]))) results[name] = [];
|
|
254
|
-
results[name].push(value);
|
|
255
|
-
} else results[name] ??= value;
|
|
256
|
-
}
|
|
257
|
-
return key ? results[key] : results;
|
|
258
|
-
};
|
|
259
|
-
var getQueryParam = _getQueryParam;
|
|
260
|
-
var getQueryParams = (url, key) => {
|
|
261
|
-
return _getQueryParam(url, key, true);
|
|
262
|
-
};
|
|
263
|
-
var decodeURIComponent_ = decodeURIComponent;
|
|
264
|
-
//#endregion
|
|
265
|
-
//#region ../../node_modules/.pnpm/hono@4.13.3/node_modules/hono/dist/request.js
|
|
266
|
-
var HonoRequest = class {
|
|
267
|
-
/**
|
|
268
|
-
* `.raw` can get the raw Request object.
|
|
269
|
-
*
|
|
270
|
-
* @see {@link https://hono.dev/docs/api/request#raw}
|
|
271
|
-
*
|
|
272
|
-
* @example
|
|
273
|
-
* ```ts
|
|
274
|
-
* // For Cloudflare Workers
|
|
275
|
-
* app.post('/', async (c) => {
|
|
276
|
-
* const metadata = c.req.raw.cf?.hostMetadata?
|
|
277
|
-
* ...
|
|
278
|
-
* })
|
|
279
|
-
* ```
|
|
280
|
-
*/
|
|
281
|
-
raw;
|
|
282
|
-
#validatedData;
|
|
283
|
-
#matchResult;
|
|
284
|
-
routeIndex = 0;
|
|
285
|
-
/**
|
|
286
|
-
* `.path` can get the pathname of the request.
|
|
287
|
-
*
|
|
288
|
-
* @see {@link https://hono.dev/docs/api/request#path}
|
|
289
|
-
*
|
|
290
|
-
* @example
|
|
291
|
-
* ```ts
|
|
292
|
-
* app.get('/about/me', (c) => {
|
|
293
|
-
* const pathname = c.req.path // `/about/me`
|
|
294
|
-
* })
|
|
295
|
-
* ```
|
|
296
|
-
*/
|
|
297
|
-
path;
|
|
298
|
-
bodyCache = {};
|
|
299
|
-
constructor(request, path = "/", matchResult = [[]]) {
|
|
300
|
-
this.raw = request;
|
|
301
|
-
this.path = path;
|
|
302
|
-
this.#matchResult = matchResult;
|
|
303
|
-
}
|
|
304
|
-
param(key) {
|
|
305
|
-
return key ? this.#getDecodedParam(key) : this.#getAllDecodedParams();
|
|
306
|
-
}
|
|
307
|
-
#getDecodedParam(key) {
|
|
308
|
-
const paramKey = this.#matchResult[0][this.routeIndex][1][key];
|
|
309
|
-
const param = this.#getParamValue(paramKey);
|
|
310
|
-
return param && tryDecodeURIComponent(param);
|
|
311
|
-
}
|
|
312
|
-
#getAllDecodedParams() {
|
|
313
|
-
const decoded = {};
|
|
314
|
-
const keys = Object.keys(this.#matchResult[0][this.routeIndex][1]);
|
|
315
|
-
for (const key of keys) {
|
|
316
|
-
const value = this.#getParamValue(this.#matchResult[0][this.routeIndex][1][key]);
|
|
317
|
-
if (value !== void 0) decoded[key] = tryDecodeURIComponent(value);
|
|
318
|
-
}
|
|
319
|
-
return decoded;
|
|
320
|
-
}
|
|
321
|
-
#getParamValue(paramKey) {
|
|
322
|
-
return this.#matchResult[1] ? this.#matchResult[1][paramKey] : paramKey;
|
|
323
|
-
}
|
|
324
|
-
query(key) {
|
|
325
|
-
return getQueryParam(this.url, key);
|
|
326
|
-
}
|
|
327
|
-
queries(key) {
|
|
328
|
-
return getQueryParams(this.url, key);
|
|
329
|
-
}
|
|
330
|
-
header(name) {
|
|
331
|
-
if (name) return this.raw.headers.get(name) ?? void 0;
|
|
332
|
-
const headerData = /* @__PURE__ */ Object.create(null);
|
|
333
|
-
this.raw.headers.forEach((value, key) => {
|
|
334
|
-
headerData[key] = value;
|
|
335
|
-
});
|
|
336
|
-
return headerData;
|
|
337
|
-
}
|
|
338
|
-
async parseBody(options) {
|
|
339
|
-
return parseBody(this, options);
|
|
340
|
-
}
|
|
341
|
-
#cachedBody = (key) => {
|
|
342
|
-
const { bodyCache, raw } = this;
|
|
343
|
-
const cachedBody = bodyCache[key];
|
|
344
|
-
if (cachedBody) return cachedBody;
|
|
345
|
-
for (const anyCachedKey in bodyCache) return bodyCache[anyCachedKey].then((body) => {
|
|
346
|
-
if (anyCachedKey === "json") body = JSON.stringify(body);
|
|
347
|
-
return new Response(body)[key]();
|
|
348
|
-
});
|
|
349
|
-
return bodyCache[key] = raw[key]();
|
|
350
|
-
};
|
|
351
|
-
/**
|
|
352
|
-
* `.json()` can parse Request body of type `application/json`
|
|
353
|
-
*
|
|
354
|
-
* @see {@link https://hono.dev/docs/api/request#json}
|
|
355
|
-
*
|
|
356
|
-
* @example
|
|
357
|
-
* ```ts
|
|
358
|
-
* app.post('/entry', async (c) => {
|
|
359
|
-
* const body = await c.req.json()
|
|
360
|
-
* })
|
|
361
|
-
* ```
|
|
362
|
-
*/
|
|
363
|
-
json() {
|
|
364
|
-
return this.#cachedBody("text").then((text) => JSON.parse(text));
|
|
365
|
-
}
|
|
366
|
-
/**
|
|
367
|
-
* `.text()` can parse Request body of type `text/plain`
|
|
368
|
-
*
|
|
369
|
-
* @see {@link https://hono.dev/docs/api/request#text}
|
|
370
|
-
*
|
|
371
|
-
* @example
|
|
372
|
-
* ```ts
|
|
373
|
-
* app.post('/entry', async (c) => {
|
|
374
|
-
* const body = await c.req.text()
|
|
375
|
-
* })
|
|
376
|
-
* ```
|
|
377
|
-
*/
|
|
378
|
-
text() {
|
|
379
|
-
return this.#cachedBody("text");
|
|
380
|
-
}
|
|
381
|
-
/**
|
|
382
|
-
* `.arrayBuffer()` parse Request body as an `ArrayBuffer`
|
|
383
|
-
*
|
|
384
|
-
* @see {@link https://hono.dev/docs/api/request#arraybuffer}
|
|
385
|
-
*
|
|
386
|
-
* @example
|
|
387
|
-
* ```ts
|
|
388
|
-
* app.post('/entry', async (c) => {
|
|
389
|
-
* const body = await c.req.arrayBuffer()
|
|
390
|
-
* })
|
|
391
|
-
* ```
|
|
392
|
-
*/
|
|
393
|
-
arrayBuffer() {
|
|
394
|
-
return this.#cachedBody("arrayBuffer");
|
|
395
|
-
}
|
|
396
|
-
/**
|
|
397
|
-
* `.bytes()` parses the request body as a `Uint8Array`.
|
|
398
|
-
*
|
|
399
|
-
* @see {@link https://hono.dev/docs/api/request#bytes}
|
|
400
|
-
*
|
|
401
|
-
* @example
|
|
402
|
-
* ```ts
|
|
403
|
-
* app.post('/entry', async (c) => {
|
|
404
|
-
* const body = await c.req.bytes()
|
|
405
|
-
* })
|
|
406
|
-
* ```
|
|
407
|
-
*/
|
|
408
|
-
bytes() {
|
|
409
|
-
return this.#cachedBody("arrayBuffer").then((buffer) => new Uint8Array(buffer));
|
|
410
|
-
}
|
|
411
|
-
/**
|
|
412
|
-
* Parses the request body as a `Blob`.
|
|
413
|
-
* @example
|
|
414
|
-
* ```ts
|
|
415
|
-
* app.post('/entry', async (c) => {
|
|
416
|
-
* const body = await c.req.blob();
|
|
417
|
-
* });
|
|
418
|
-
* ```
|
|
419
|
-
* @see https://hono.dev/docs/api/request#blob
|
|
420
|
-
*/
|
|
421
|
-
blob() {
|
|
422
|
-
return this.#cachedBody("blob");
|
|
423
|
-
}
|
|
424
|
-
/**
|
|
425
|
-
* Parses the request body as `FormData`.
|
|
426
|
-
* @example
|
|
427
|
-
* ```ts
|
|
428
|
-
* app.post('/entry', async (c) => {
|
|
429
|
-
* const body = await c.req.formData();
|
|
430
|
-
* });
|
|
431
|
-
* ```
|
|
432
|
-
* @see https://hono.dev/docs/api/request#formdata
|
|
433
|
-
*/
|
|
434
|
-
formData() {
|
|
435
|
-
return this.#cachedBody("formData");
|
|
436
|
-
}
|
|
437
|
-
/**
|
|
438
|
-
* Adds validated data to the request.
|
|
439
|
-
*
|
|
440
|
-
* @param target - The target of the validation.
|
|
441
|
-
* @param data - The validated data to add.
|
|
442
|
-
*/
|
|
443
|
-
addValidatedData(target, data) {
|
|
444
|
-
(this.#validatedData ??= {})[target] = data;
|
|
445
|
-
}
|
|
446
|
-
valid(target) {
|
|
447
|
-
return this.#validatedData?.[target];
|
|
448
|
-
}
|
|
449
|
-
/**
|
|
450
|
-
* `.url()` can get the request url strings.
|
|
451
|
-
*
|
|
452
|
-
* @see {@link https://hono.dev/docs/api/request#url}
|
|
453
|
-
*
|
|
454
|
-
* @example
|
|
455
|
-
* ```ts
|
|
456
|
-
* app.get('/about/me', (c) => {
|
|
457
|
-
* const url = c.req.url // `http://localhost:8787/about/me`
|
|
458
|
-
* ...
|
|
459
|
-
* })
|
|
460
|
-
* ```
|
|
461
|
-
*/
|
|
462
|
-
get url() {
|
|
463
|
-
return this.raw.url;
|
|
464
|
-
}
|
|
465
|
-
/**
|
|
466
|
-
* `.method()` can get the method name of the request.
|
|
467
|
-
*
|
|
468
|
-
* @see {@link https://hono.dev/docs/api/request#method}
|
|
469
|
-
*
|
|
470
|
-
* @example
|
|
471
|
-
* ```ts
|
|
472
|
-
* app.get('/about/me', (c) => {
|
|
473
|
-
* const method = c.req.method // `GET`
|
|
474
|
-
* })
|
|
475
|
-
* ```
|
|
476
|
-
*/
|
|
477
|
-
get method() {
|
|
478
|
-
return this.raw.method;
|
|
479
|
-
}
|
|
480
|
-
get [GET_MATCH_RESULT]() {
|
|
481
|
-
return this.#matchResult;
|
|
482
|
-
}
|
|
483
|
-
/**
|
|
484
|
-
* `.matchedRoutes()` can return a matched route in the handler
|
|
485
|
-
*
|
|
486
|
-
* @deprecated
|
|
487
|
-
*
|
|
488
|
-
* Use matchedRoutes helper defined in "hono/route" instead.
|
|
489
|
-
*
|
|
490
|
-
* @see {@link https://hono.dev/docs/api/request#matchedroutes}
|
|
491
|
-
*
|
|
492
|
-
* @example
|
|
493
|
-
* ```ts
|
|
494
|
-
* app.use('*', async function logger(c, next) {
|
|
495
|
-
* await next()
|
|
496
|
-
* c.req.matchedRoutes.forEach(({ handler, method, path }, i) => {
|
|
497
|
-
* const name = handler.name || (handler.length < 2 ? '[handler]' : '[middleware]')
|
|
498
|
-
* console.log(
|
|
499
|
-
* method,
|
|
500
|
-
* ' ',
|
|
501
|
-
* path,
|
|
502
|
-
* ' '.repeat(Math.max(10 - path.length, 0)),
|
|
503
|
-
* name,
|
|
504
|
-
* i === c.req.routeIndex ? '<- respond from here' : ''
|
|
505
|
-
* )
|
|
506
|
-
* })
|
|
507
|
-
* })
|
|
508
|
-
* ```
|
|
509
|
-
*/
|
|
510
|
-
get matchedRoutes() {
|
|
511
|
-
return this.#matchResult[0].map(([[, route]]) => route);
|
|
512
|
-
}
|
|
513
|
-
/**
|
|
514
|
-
* `routePath()` can retrieve the path registered within the handler
|
|
515
|
-
*
|
|
516
|
-
* @deprecated
|
|
517
|
-
*
|
|
518
|
-
* Use routePath helper defined in "hono/route" instead.
|
|
519
|
-
*
|
|
520
|
-
* @see {@link https://hono.dev/docs/api/request#routepath}
|
|
521
|
-
*
|
|
522
|
-
* @example
|
|
523
|
-
* ```ts
|
|
524
|
-
* app.get('/posts/:id', (c) => {
|
|
525
|
-
* return c.json({ path: c.req.routePath })
|
|
526
|
-
* })
|
|
527
|
-
* ```
|
|
528
|
-
*/
|
|
529
|
-
get routePath() {
|
|
530
|
-
return this.#matchResult[0].map(([[, route]]) => route)[this.routeIndex].path;
|
|
531
|
-
}
|
|
532
|
-
};
|
|
533
|
-
//#endregion
|
|
534
|
-
//#region ../../node_modules/.pnpm/hono@4.13.3/node_modules/hono/dist/context.js
|
|
535
|
-
var TEXT_PLAIN = "text/plain; charset=UTF-8";
|
|
536
|
-
var setDefaultContentType = (contentType, headers) => {
|
|
537
|
-
return {
|
|
538
|
-
"Content-Type": contentType,
|
|
539
|
-
...headers
|
|
540
|
-
};
|
|
541
|
-
};
|
|
542
|
-
var createResponseInstance = (body, init) => new Response(body, init);
|
|
543
|
-
var Context = class {
|
|
544
|
-
#rawRequest;
|
|
545
|
-
#req;
|
|
546
|
-
/**
|
|
547
|
-
* `.env` can get bindings (environment variables, secrets, KV namespaces, D1 database, R2 bucket etc.) in Cloudflare Workers.
|
|
548
|
-
*
|
|
549
|
-
* @see {@link https://hono.dev/docs/api/context#env}
|
|
550
|
-
*
|
|
551
|
-
* @example
|
|
552
|
-
* ```ts
|
|
553
|
-
* // Environment object for Cloudflare Workers
|
|
554
|
-
* app.get('*', async c => {
|
|
555
|
-
* const counter = c.env.COUNTER
|
|
556
|
-
* })
|
|
557
|
-
* ```
|
|
558
|
-
*/
|
|
559
|
-
env = {};
|
|
560
|
-
#var;
|
|
561
|
-
finalized = false;
|
|
562
|
-
/**
|
|
563
|
-
* `.error` can get the error object from the middleware if the Handler throws an error.
|
|
564
|
-
*
|
|
565
|
-
* @see {@link https://hono.dev/docs/api/context#error}
|
|
566
|
-
*
|
|
567
|
-
* @example
|
|
568
|
-
* ```ts
|
|
569
|
-
* app.use('*', async (c, next) => {
|
|
570
|
-
* await next()
|
|
571
|
-
* if (c.error) {
|
|
572
|
-
* // do something...
|
|
573
|
-
* }
|
|
574
|
-
* })
|
|
575
|
-
* ```
|
|
576
|
-
*/
|
|
577
|
-
error;
|
|
578
|
-
#status;
|
|
579
|
-
#executionCtx;
|
|
580
|
-
#res;
|
|
581
|
-
#layout;
|
|
582
|
-
#renderer;
|
|
583
|
-
#notFoundHandler;
|
|
584
|
-
#preparedHeaders;
|
|
585
|
-
#matchResult;
|
|
586
|
-
#path;
|
|
587
|
-
/**
|
|
588
|
-
* Creates an instance of the Context class.
|
|
589
|
-
*
|
|
590
|
-
* @param req - The Request object.
|
|
591
|
-
* @param options - Optional configuration options for the context.
|
|
592
|
-
*/
|
|
593
|
-
constructor(req, options) {
|
|
594
|
-
this.#rawRequest = req;
|
|
595
|
-
if (options) {
|
|
596
|
-
this.#executionCtx = options.executionCtx;
|
|
597
|
-
this.env = options.env;
|
|
598
|
-
this.#notFoundHandler = options.notFoundHandler;
|
|
599
|
-
this.#path = options.path;
|
|
600
|
-
this.#matchResult = options.matchResult;
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
/**
|
|
604
|
-
* `.req` is the instance of {@link HonoRequest}.
|
|
605
|
-
*/
|
|
606
|
-
get req() {
|
|
607
|
-
this.#req ??= new HonoRequest(this.#rawRequest, this.#path, this.#matchResult);
|
|
608
|
-
return this.#req;
|
|
609
|
-
}
|
|
610
|
-
/**
|
|
611
|
-
* @see {@link https://hono.dev/docs/api/context#event}
|
|
612
|
-
* The FetchEvent associated with the current request.
|
|
613
|
-
*
|
|
614
|
-
* @throws Will throw an error if the context does not have a FetchEvent.
|
|
615
|
-
*/
|
|
616
|
-
get event() {
|
|
617
|
-
if (this.#executionCtx && "respondWith" in this.#executionCtx) return this.#executionCtx;
|
|
618
|
-
else throw Error("This context has no FetchEvent");
|
|
619
|
-
}
|
|
620
|
-
/**
|
|
621
|
-
* @see {@link https://hono.dev/docs/api/context#executionctx}
|
|
622
|
-
* The ExecutionContext associated with the current request.
|
|
623
|
-
*
|
|
624
|
-
* @throws Will throw an error if the context does not have an ExecutionContext.
|
|
625
|
-
*/
|
|
626
|
-
get executionCtx() {
|
|
627
|
-
if (this.#executionCtx) return this.#executionCtx;
|
|
628
|
-
else throw Error("This context has no ExecutionContext");
|
|
629
|
-
}
|
|
630
|
-
/**
|
|
631
|
-
* @see {@link https://hono.dev/docs/api/context#res}
|
|
632
|
-
* The Response object for the current request.
|
|
633
|
-
*/
|
|
634
|
-
get res() {
|
|
635
|
-
return this.#res ||= createResponseInstance(null, { headers: this.#preparedHeaders ??= new Headers() });
|
|
636
|
-
}
|
|
637
|
-
/**
|
|
638
|
-
* Sets the Response object for the current request.
|
|
639
|
-
*
|
|
640
|
-
* @param _res - The Response object to set.
|
|
641
|
-
*/
|
|
642
|
-
set res(_res) {
|
|
643
|
-
if (this.#res && _res) {
|
|
644
|
-
_res = createResponseInstance(_res.body, _res);
|
|
645
|
-
for (const [k, v] of this.#res.headers.entries()) {
|
|
646
|
-
if (k === "content-type") continue;
|
|
647
|
-
if (k === "set-cookie") {
|
|
648
|
-
const cookies = this.#res.headers.getSetCookie();
|
|
649
|
-
_res.headers.delete("set-cookie");
|
|
650
|
-
for (const cookie of cookies) _res.headers.append("set-cookie", cookie);
|
|
651
|
-
} else _res.headers.set(k, v);
|
|
652
|
-
}
|
|
653
|
-
}
|
|
654
|
-
this.#res = _res;
|
|
655
|
-
this.finalized = true;
|
|
656
|
-
}
|
|
657
|
-
/**
|
|
658
|
-
* `.render()` can create a response within a layout.
|
|
659
|
-
*
|
|
660
|
-
* @see {@link https://hono.dev/docs/api/context#render-setrenderer}
|
|
661
|
-
*
|
|
662
|
-
* @example
|
|
663
|
-
* ```ts
|
|
664
|
-
* app.get('/', (c) => {
|
|
665
|
-
* return c.render('Hello!')
|
|
666
|
-
* })
|
|
667
|
-
* ```
|
|
668
|
-
*/
|
|
669
|
-
render = (...args) => {
|
|
670
|
-
this.#renderer ??= (content) => this.html(content);
|
|
671
|
-
return this.#renderer(...args);
|
|
672
|
-
};
|
|
673
|
-
/**
|
|
674
|
-
* Sets the layout for the response.
|
|
675
|
-
*
|
|
676
|
-
* @param layout - The layout to set.
|
|
677
|
-
* @returns The layout function.
|
|
678
|
-
*/
|
|
679
|
-
setLayout = (layout) => this.#layout = layout;
|
|
680
|
-
/**
|
|
681
|
-
* Gets the current layout for the response.
|
|
682
|
-
*
|
|
683
|
-
* @returns The current layout function.
|
|
684
|
-
*/
|
|
685
|
-
getLayout = () => this.#layout;
|
|
686
|
-
/**
|
|
687
|
-
* `.setRenderer()` can set the layout in the custom middleware.
|
|
688
|
-
*
|
|
689
|
-
* @see {@link https://hono.dev/docs/api/context#render-setrenderer}
|
|
690
|
-
*
|
|
691
|
-
* @example
|
|
692
|
-
* ```tsx
|
|
693
|
-
* app.use('*', async (c, next) => {
|
|
694
|
-
* c.setRenderer((content) => {
|
|
695
|
-
* return c.html(
|
|
696
|
-
* <html>
|
|
697
|
-
* <body>
|
|
698
|
-
* <p>{content}</p>
|
|
699
|
-
* </body>
|
|
700
|
-
* </html>
|
|
701
|
-
* )
|
|
702
|
-
* })
|
|
703
|
-
* await next()
|
|
704
|
-
* })
|
|
705
|
-
* ```
|
|
706
|
-
*/
|
|
707
|
-
setRenderer = (renderer) => {
|
|
708
|
-
this.#renderer = renderer;
|
|
709
|
-
};
|
|
710
|
-
/**
|
|
711
|
-
* `.header()` can set headers.
|
|
712
|
-
*
|
|
713
|
-
* @see {@link https://hono.dev/docs/api/context#header}
|
|
714
|
-
*
|
|
715
|
-
* @example
|
|
716
|
-
* ```ts
|
|
717
|
-
* app.get('/welcome', (c) => {
|
|
718
|
-
* // Set headers
|
|
719
|
-
* c.header('X-Message', 'Hello!')
|
|
720
|
-
* c.header('Content-Type', 'text/plain')
|
|
721
|
-
*
|
|
722
|
-
* // Append multiple headers using the append option (e.g. Vary)
|
|
723
|
-
* c.header('Vary', 'Accept-Encoding', { append: true })
|
|
724
|
-
* c.header('Vary', 'User-Agent', { append: true })
|
|
725
|
-
*
|
|
726
|
-
* return c.body('Thank you for coming')
|
|
727
|
-
* })
|
|
728
|
-
* ```
|
|
729
|
-
*/
|
|
730
|
-
header = (name, value, options) => {
|
|
731
|
-
if (this.finalized) this.#res = createResponseInstance(this.#res.body, this.#res);
|
|
732
|
-
const headers = this.#res ? this.#res.headers : this.#preparedHeaders ??= new Headers();
|
|
733
|
-
if (value === void 0) headers.delete(name);
|
|
734
|
-
else if (options?.append) headers.append(name, value);
|
|
735
|
-
else headers.set(name, value);
|
|
736
|
-
};
|
|
737
|
-
status = (status) => {
|
|
738
|
-
this.#status = status;
|
|
739
|
-
};
|
|
740
|
-
/**
|
|
741
|
-
* `.set()` can set the value specified by the key.
|
|
742
|
-
*
|
|
743
|
-
* @see {@link https://hono.dev/docs/api/context#set-get}
|
|
744
|
-
*
|
|
745
|
-
* @example
|
|
746
|
-
* ```ts
|
|
747
|
-
* app.use('*', async (c, next) => {
|
|
748
|
-
* c.set('message', 'Hono is hot!!')
|
|
749
|
-
* await next()
|
|
750
|
-
* })
|
|
751
|
-
* ```
|
|
752
|
-
*/
|
|
753
|
-
set = (key, value) => {
|
|
754
|
-
this.#var ??= /* @__PURE__ */ new Map();
|
|
755
|
-
this.#var.set(key, value);
|
|
756
|
-
};
|
|
757
|
-
/**
|
|
758
|
-
* `.get()` can use the value specified by the key.
|
|
759
|
-
*
|
|
760
|
-
* @see {@link https://hono.dev/docs/api/context#set-get}
|
|
761
|
-
*
|
|
762
|
-
* @example
|
|
763
|
-
* ```ts
|
|
764
|
-
* app.get('/', (c) => {
|
|
765
|
-
* const message = c.get('message')
|
|
766
|
-
* return c.text(`The message is "${message}"`)
|
|
767
|
-
* })
|
|
768
|
-
* ```
|
|
769
|
-
*/
|
|
770
|
-
get = (key) => {
|
|
771
|
-
return this.#var ? this.#var.get(key) : void 0;
|
|
772
|
-
};
|
|
773
|
-
/**
|
|
774
|
-
* `.var` can access the value of a variable.
|
|
775
|
-
*
|
|
776
|
-
* @see {@link https://hono.dev/docs/api/context#var}
|
|
777
|
-
*
|
|
778
|
-
* @example
|
|
779
|
-
* ```ts
|
|
780
|
-
* const result = c.var.client.oneMethod()
|
|
781
|
-
* ```
|
|
782
|
-
*/
|
|
783
|
-
get var() {
|
|
784
|
-
if (!this.#var) return {};
|
|
785
|
-
return Object.fromEntries(this.#var);
|
|
786
|
-
}
|
|
787
|
-
#newResponse(data, arg, headers) {
|
|
788
|
-
let responseHeaders = this.#res ? new Headers(this.#res.headers) : this.#preparedHeaders;
|
|
789
|
-
if (typeof arg === "object" && arg.headers) {
|
|
790
|
-
responseHeaders ??= new Headers();
|
|
791
|
-
for (const [key, value] of new Headers(arg.headers)) if (key === "set-cookie") responseHeaders.append(key, value);
|
|
792
|
-
else responseHeaders.set(key, value);
|
|
793
|
-
}
|
|
794
|
-
if (headers) {
|
|
795
|
-
if (!responseHeaders) {
|
|
796
|
-
let count = 0;
|
|
797
|
-
for (const k in headers) if (++count > 1 || typeof headers[k] !== "string") {
|
|
798
|
-
responseHeaders = new Headers();
|
|
799
|
-
break;
|
|
800
|
-
}
|
|
801
|
-
}
|
|
802
|
-
if (responseHeaders) for (const k in headers) {
|
|
803
|
-
const v = headers[k];
|
|
804
|
-
if (typeof v === "string") responseHeaders.set(k, v);
|
|
805
|
-
else {
|
|
806
|
-
responseHeaders.delete(k);
|
|
807
|
-
for (const v2 of v) responseHeaders.append(k, v2);
|
|
808
|
-
}
|
|
809
|
-
}
|
|
810
|
-
}
|
|
811
|
-
return createResponseInstance(data, {
|
|
812
|
-
status: typeof arg === "number" ? arg : arg?.status ?? this.#status,
|
|
813
|
-
headers: responseHeaders ?? headers
|
|
814
|
-
});
|
|
815
|
-
}
|
|
816
|
-
newResponse = (...args) => this.#newResponse(...args);
|
|
817
|
-
/**
|
|
818
|
-
* `.body()` can return the HTTP response.
|
|
819
|
-
* You can set headers with `.header()` and set HTTP status code with `.status`.
|
|
820
|
-
* This can also be set in `.text()`, `.json()` and so on.
|
|
821
|
-
*
|
|
822
|
-
* @see {@link https://hono.dev/docs/api/context#body}
|
|
823
|
-
*
|
|
824
|
-
* @example
|
|
825
|
-
* ```ts
|
|
826
|
-
* app.get('/welcome', (c) => {
|
|
827
|
-
* // Set headers
|
|
828
|
-
* c.header('X-Message', 'Hello!')
|
|
829
|
-
* c.header('Content-Type', 'text/plain')
|
|
830
|
-
* // Set HTTP status code
|
|
831
|
-
* c.status(201)
|
|
832
|
-
*
|
|
833
|
-
* // Return the response body
|
|
834
|
-
* return c.body('Thank you for coming')
|
|
835
|
-
* })
|
|
836
|
-
* ```
|
|
837
|
-
*/
|
|
838
|
-
body = (data, arg, headers) => this.#newResponse(data, arg, headers);
|
|
839
|
-
/**
|
|
840
|
-
* `.text()` can render text as `Content-Type:text/plain`.
|
|
841
|
-
*
|
|
842
|
-
* @see {@link https://hono.dev/docs/api/context#text}
|
|
843
|
-
*
|
|
844
|
-
* @example
|
|
845
|
-
* ```ts
|
|
846
|
-
* app.get('/say', (c) => {
|
|
847
|
-
* return c.text('Hello!')
|
|
848
|
-
* })
|
|
849
|
-
* ```
|
|
850
|
-
*/
|
|
851
|
-
text = (text, arg, headers) => {
|
|
852
|
-
return !this.#preparedHeaders && !this.#status && !arg && !headers && !this.finalized ? new Response(text) : this.#newResponse(text, arg, setDefaultContentType(TEXT_PLAIN, headers));
|
|
853
|
-
};
|
|
854
|
-
/**
|
|
855
|
-
* `.json()` can render JSON as `Content-Type:application/json`.
|
|
856
|
-
*
|
|
857
|
-
* @see {@link https://hono.dev/docs/api/context#json}
|
|
858
|
-
*
|
|
859
|
-
* @example
|
|
860
|
-
* ```ts
|
|
861
|
-
* app.get('/api', (c) => {
|
|
862
|
-
* return c.json({ message: 'Hello!' })
|
|
863
|
-
* })
|
|
864
|
-
* ```
|
|
865
|
-
*/
|
|
866
|
-
json = (object, arg, headers) => {
|
|
867
|
-
return this.#newResponse(JSON.stringify(object), arg, setDefaultContentType("application/json", headers));
|
|
868
|
-
};
|
|
869
|
-
html = (html, arg, headers) => {
|
|
870
|
-
const res = (html2) => this.#newResponse(html2, arg, setDefaultContentType("text/html; charset=UTF-8", headers));
|
|
871
|
-
return typeof html === "object" ? resolveCallback(html, HtmlEscapedCallbackPhase.Stringify, false, {}).then(res) : res(html);
|
|
872
|
-
};
|
|
873
|
-
/**
|
|
874
|
-
* `.redirect()` can Redirect, default status code is 302.
|
|
875
|
-
*
|
|
876
|
-
* @see {@link https://hono.dev/docs/api/context#redirect}
|
|
877
|
-
*
|
|
878
|
-
* @example
|
|
879
|
-
* ```ts
|
|
880
|
-
* app.get('/redirect', (c) => {
|
|
881
|
-
* return c.redirect('/')
|
|
882
|
-
* })
|
|
883
|
-
* app.get('/redirect-permanently', (c) => {
|
|
884
|
-
* return c.redirect('/', 301)
|
|
885
|
-
* })
|
|
886
|
-
* ```
|
|
887
|
-
*/
|
|
888
|
-
redirect = (location, status) => {
|
|
889
|
-
const locationString = String(location);
|
|
890
|
-
this.header("Location", !/[^\x00-\xFF]/.test(locationString) ? locationString : encodeURI(locationString));
|
|
891
|
-
return this.newResponse(null, status ?? 302);
|
|
892
|
-
};
|
|
893
|
-
/**
|
|
894
|
-
* `.notFound()` can return the Not Found Response.
|
|
895
|
-
*
|
|
896
|
-
* @see {@link https://hono.dev/docs/api/context#notfound}
|
|
897
|
-
*
|
|
898
|
-
* @example
|
|
899
|
-
* ```ts
|
|
900
|
-
* app.get('/notfound', (c) => {
|
|
901
|
-
* return c.notFound()
|
|
902
|
-
* })
|
|
903
|
-
* ```
|
|
904
|
-
*/
|
|
905
|
-
notFound = () => {
|
|
906
|
-
this.#notFoundHandler ??= () => createResponseInstance();
|
|
907
|
-
return this.#notFoundHandler(this);
|
|
908
|
-
};
|
|
909
|
-
};
|
|
910
|
-
//#endregion
|
|
911
|
-
//#region ../../node_modules/.pnpm/hono@4.13.3/node_modules/hono/dist/router.js
|
|
912
|
-
var METHODS = [
|
|
913
|
-
"get",
|
|
914
|
-
"post",
|
|
915
|
-
"put",
|
|
916
|
-
"delete",
|
|
917
|
-
"options",
|
|
918
|
-
"patch",
|
|
919
|
-
"query"
|
|
920
|
-
];
|
|
921
|
-
var MESSAGE_MATCHER_IS_ALREADY_BUILT = "Can not add a route since the matcher is already built.";
|
|
922
|
-
var UnsupportedPathError = class extends Error {};
|
|
923
|
-
//#endregion
|
|
924
|
-
//#region ../../node_modules/.pnpm/hono@4.13.3/node_modules/hono/dist/utils/constants.js
|
|
925
|
-
var COMPOSED_HANDLER = "__COMPOSED_HANDLER";
|
|
926
|
-
//#endregion
|
|
927
|
-
//#region ../../node_modules/.pnpm/hono@4.13.3/node_modules/hono/dist/hono-base.js
|
|
928
|
-
var notFoundHandler = (c) => {
|
|
929
|
-
return c.text("404 Not Found", 404);
|
|
930
|
-
};
|
|
931
|
-
var errorHandler = (err, c) => {
|
|
932
|
-
if ("getResponse" in err) {
|
|
933
|
-
const res = err.getResponse();
|
|
934
|
-
return c.newResponse(res.body, res);
|
|
935
|
-
}
|
|
936
|
-
console.error(err);
|
|
937
|
-
return c.text("Internal Server Error", 500);
|
|
938
|
-
};
|
|
939
|
-
var Hono$1 = class _Hono {
|
|
940
|
-
get;
|
|
941
|
-
post;
|
|
942
|
-
put;
|
|
943
|
-
delete;
|
|
944
|
-
options;
|
|
945
|
-
patch;
|
|
946
|
-
query;
|
|
947
|
-
all;
|
|
948
|
-
on;
|
|
949
|
-
use;
|
|
950
|
-
router;
|
|
951
|
-
getPath;
|
|
952
|
-
_basePath = "/";
|
|
953
|
-
#path = "/";
|
|
954
|
-
routes = [];
|
|
955
|
-
constructor(options = {}) {
|
|
956
|
-
[...METHODS, "all"].forEach((method) => {
|
|
957
|
-
this[method] = (args1, ...args) => {
|
|
958
|
-
if (typeof args1 === "string") this.#path = args1;
|
|
959
|
-
else this.#addRoute(method, this.#path, args1);
|
|
960
|
-
args.forEach((handler) => {
|
|
961
|
-
this.#addRoute(method, this.#path, handler);
|
|
962
|
-
});
|
|
963
|
-
return this;
|
|
964
|
-
};
|
|
965
|
-
});
|
|
966
|
-
this.on = (method, path, ...handlers) => {
|
|
967
|
-
for (const p of [path].flat()) {
|
|
968
|
-
this.#path = p;
|
|
969
|
-
for (const m of [method].flat()) handlers.map((handler) => {
|
|
970
|
-
this.#addRoute(m.toUpperCase(), this.#path, handler);
|
|
971
|
-
});
|
|
972
|
-
}
|
|
973
|
-
return this;
|
|
974
|
-
};
|
|
975
|
-
this.use = (arg1, ...handlers) => {
|
|
976
|
-
if (typeof arg1 === "string") this.#path = arg1;
|
|
977
|
-
else {
|
|
978
|
-
this.#path = "*";
|
|
979
|
-
handlers.unshift(arg1);
|
|
980
|
-
}
|
|
981
|
-
handlers.forEach((handler) => {
|
|
982
|
-
this.#addRoute("ALL", this.#path, handler);
|
|
983
|
-
});
|
|
984
|
-
return this;
|
|
985
|
-
};
|
|
986
|
-
const { strict, ...optionsWithoutStrict } = options;
|
|
987
|
-
Object.assign(this, optionsWithoutStrict);
|
|
988
|
-
this.getPath = strict ?? true ? options.getPath ?? getPath : getPathNoStrict;
|
|
989
|
-
}
|
|
990
|
-
#clone() {
|
|
991
|
-
const clone = new _Hono({
|
|
992
|
-
router: this.router,
|
|
993
|
-
getPath: this.getPath
|
|
994
|
-
});
|
|
995
|
-
clone.errorHandler = this.errorHandler;
|
|
996
|
-
clone.#notFoundHandler = this.#notFoundHandler;
|
|
997
|
-
clone.routes = this.routes;
|
|
998
|
-
return clone;
|
|
999
|
-
}
|
|
1000
|
-
#notFoundHandler = notFoundHandler;
|
|
1001
|
-
errorHandler = errorHandler;
|
|
1002
|
-
/**
|
|
1003
|
-
* `.route()` allows grouping other Hono instance in routes.
|
|
1004
|
-
*
|
|
1005
|
-
* @see {@link https://hono.dev/docs/api/routing#grouping}
|
|
1006
|
-
*
|
|
1007
|
-
* @param {string} path - base Path
|
|
1008
|
-
* @param {Hono} app - other Hono instance
|
|
1009
|
-
* @returns {Hono} routed Hono instance
|
|
1010
|
-
*
|
|
1011
|
-
* @example
|
|
1012
|
-
* ```ts
|
|
1013
|
-
* const app = new Hono()
|
|
1014
|
-
* const app2 = new Hono()
|
|
1015
|
-
*
|
|
1016
|
-
* app2.get("/user", (c) => c.text("user"))
|
|
1017
|
-
* app.route("/api", app2) // GET /api/user
|
|
1018
|
-
* ```
|
|
1019
|
-
*/
|
|
1020
|
-
route(path, app) {
|
|
1021
|
-
const subApp = this.basePath(path);
|
|
1022
|
-
app.routes.map((r) => {
|
|
1023
|
-
let handler;
|
|
1024
|
-
if (app.errorHandler === errorHandler) handler = r.handler;
|
|
1025
|
-
else {
|
|
1026
|
-
handler = async (c, next) => (await compose([], app.errorHandler)(c, () => r.handler(c, next))).res;
|
|
1027
|
-
handler[COMPOSED_HANDLER] = r.handler;
|
|
1028
|
-
}
|
|
1029
|
-
subApp.#addRoute(r.method, r.path, handler, r.basePath);
|
|
1030
|
-
});
|
|
1031
|
-
return this;
|
|
1032
|
-
}
|
|
1033
|
-
/**
|
|
1034
|
-
* `.basePath()` allows base paths to be specified.
|
|
1035
|
-
*
|
|
1036
|
-
* @see {@link https://hono.dev/docs/api/routing#base-path}
|
|
1037
|
-
*
|
|
1038
|
-
* @param {string} path - base Path
|
|
1039
|
-
* @returns {Hono} changed Hono instance
|
|
1040
|
-
*
|
|
1041
|
-
* @example
|
|
1042
|
-
* ```ts
|
|
1043
|
-
* const api = new Hono().basePath('/api')
|
|
1044
|
-
* ```
|
|
1045
|
-
*/
|
|
1046
|
-
basePath(path) {
|
|
1047
|
-
const subApp = this.#clone();
|
|
1048
|
-
subApp._basePath = mergePath(this._basePath, path);
|
|
1049
|
-
return subApp;
|
|
1050
|
-
}
|
|
1051
|
-
/**
|
|
1052
|
-
* `.onError()` handles an error and returns a customized Response.
|
|
1053
|
-
*
|
|
1054
|
-
* @see {@link https://hono.dev/docs/api/hono#error-handling}
|
|
1055
|
-
*
|
|
1056
|
-
* @param {ErrorHandler} handler - request Handler for error
|
|
1057
|
-
* @returns {Hono} changed Hono instance
|
|
1058
|
-
*
|
|
1059
|
-
* @example
|
|
1060
|
-
* ```ts
|
|
1061
|
-
* app.onError((err, c) => {
|
|
1062
|
-
* console.error(`${err}`)
|
|
1063
|
-
* return c.text('Custom Error Message', 500)
|
|
1064
|
-
* })
|
|
1065
|
-
* ```
|
|
1066
|
-
*/
|
|
1067
|
-
onError = (handler) => {
|
|
1068
|
-
this.errorHandler = handler;
|
|
1069
|
-
return this;
|
|
1070
|
-
};
|
|
1071
|
-
/**
|
|
1072
|
-
* `.notFound()` allows you to customize a Not Found Response.
|
|
1073
|
-
*
|
|
1074
|
-
* @see {@link https://hono.dev/docs/api/hono#not-found}
|
|
1075
|
-
*
|
|
1076
|
-
* @param {NotFoundHandler} handler - request handler for not-found
|
|
1077
|
-
* @returns {Hono} changed Hono instance
|
|
1078
|
-
*
|
|
1079
|
-
* @example
|
|
1080
|
-
* ```ts
|
|
1081
|
-
* app.notFound((c) => {
|
|
1082
|
-
* return c.text('Custom 404 Message', 404)
|
|
1083
|
-
* })
|
|
1084
|
-
* ```
|
|
1085
|
-
*/
|
|
1086
|
-
notFound = (handler) => {
|
|
1087
|
-
this.#notFoundHandler = handler;
|
|
1088
|
-
return this;
|
|
1089
|
-
};
|
|
1090
|
-
/**
|
|
1091
|
-
* `.mount()` allows you to mount applications built with other frameworks into your Hono application.
|
|
1092
|
-
*
|
|
1093
|
-
* @see {@link https://hono.dev/docs/api/hono#mount}
|
|
1094
|
-
*
|
|
1095
|
-
* @param {string} path - base Path
|
|
1096
|
-
* @param {Function} applicationHandler - other Request Handler
|
|
1097
|
-
* @param {MountOptions} [options] - options of `.mount()`
|
|
1098
|
-
* @returns {Hono} mounted Hono instance
|
|
1099
|
-
*
|
|
1100
|
-
* @example
|
|
1101
|
-
* ```ts
|
|
1102
|
-
* import { Router as IttyRouter } from 'itty-router'
|
|
1103
|
-
* import { Hono } from 'hono'
|
|
1104
|
-
* // Create itty-router application
|
|
1105
|
-
* const ittyRouter = IttyRouter()
|
|
1106
|
-
* // GET /itty-router/hello
|
|
1107
|
-
* ittyRouter.get('/hello', () => new Response('Hello from itty-router'))
|
|
1108
|
-
*
|
|
1109
|
-
* const app = new Hono()
|
|
1110
|
-
* app.mount('/itty-router', ittyRouter.handle)
|
|
1111
|
-
* ```
|
|
1112
|
-
*
|
|
1113
|
-
* @example
|
|
1114
|
-
* ```ts
|
|
1115
|
-
* const app = new Hono()
|
|
1116
|
-
* // Send the request to another application without modification.
|
|
1117
|
-
* app.mount('/app', anotherApp, {
|
|
1118
|
-
* replaceRequest: (req) => req,
|
|
1119
|
-
* })
|
|
1120
|
-
* ```
|
|
1121
|
-
*/
|
|
1122
|
-
mount(path, applicationHandler, options) {
|
|
1123
|
-
let replaceRequest;
|
|
1124
|
-
let optionHandler;
|
|
1125
|
-
if (options) {
|
|
1126
|
-
if (typeof options === "function") optionHandler = options;
|
|
1127
|
-
else {
|
|
1128
|
-
optionHandler = options.optionHandler;
|
|
1129
|
-
if (options.replaceRequest === false) replaceRequest = (request) => request;
|
|
1130
|
-
else replaceRequest = options.replaceRequest;
|
|
1131
|
-
}
|
|
1132
|
-
}
|
|
1133
|
-
const getOptions = optionHandler ? (c) => {
|
|
1134
|
-
const options2 = optionHandler(c);
|
|
1135
|
-
return Array.isArray(options2) ? options2 : [options2];
|
|
1136
|
-
} : (c) => {
|
|
1137
|
-
let executionContext = void 0;
|
|
1138
|
-
try {
|
|
1139
|
-
executionContext = c.executionCtx;
|
|
1140
|
-
} catch {}
|
|
1141
|
-
return [c.env, executionContext];
|
|
1142
|
-
};
|
|
1143
|
-
replaceRequest ||= (() => {
|
|
1144
|
-
const mergedPath = mergePath(this._basePath, path);
|
|
1145
|
-
const pathPrefixLength = mergedPath === "/" ? 0 : mergedPath.length;
|
|
1146
|
-
return (request) => {
|
|
1147
|
-
const url = new URL(request.url);
|
|
1148
|
-
url.pathname = this.getPath(request).slice(pathPrefixLength) || "/";
|
|
1149
|
-
return new Request(url, request);
|
|
1150
|
-
};
|
|
1151
|
-
})();
|
|
1152
|
-
const handler = async (c, next) => {
|
|
1153
|
-
const res = await applicationHandler(replaceRequest(c.req.raw), ...getOptions(c));
|
|
1154
|
-
if (res) return res;
|
|
1155
|
-
await next();
|
|
1156
|
-
};
|
|
1157
|
-
this.#addRoute("ALL", mergePath(path, "*"), handler);
|
|
1158
|
-
return this;
|
|
1159
|
-
}
|
|
1160
|
-
#addRoute(method, path, handler, baseRoutePath) {
|
|
1161
|
-
method = method.toUpperCase();
|
|
1162
|
-
path = mergePath(this._basePath, path);
|
|
1163
|
-
const r = {
|
|
1164
|
-
basePath: baseRoutePath !== void 0 ? mergePath(this._basePath, baseRoutePath) : this._basePath,
|
|
1165
|
-
path,
|
|
1166
|
-
method,
|
|
1167
|
-
handler
|
|
1168
|
-
};
|
|
1169
|
-
this.router.add(method, path, [handler, r]);
|
|
1170
|
-
this.routes.push(r);
|
|
1171
|
-
}
|
|
1172
|
-
#handleError(err, c) {
|
|
1173
|
-
if (err instanceof Error) return this.errorHandler(err, c);
|
|
1174
|
-
throw err;
|
|
1175
|
-
}
|
|
1176
|
-
#dispatch(request, executionCtx, env, method) {
|
|
1177
|
-
if (method === "HEAD") return (async () => new Response(null, await this.#dispatch(request, executionCtx, env, "GET")))();
|
|
1178
|
-
const path = this.getPath(request, { env });
|
|
1179
|
-
const matchResult = this.router.match(method, path);
|
|
1180
|
-
const c = new Context(request, {
|
|
1181
|
-
path,
|
|
1182
|
-
matchResult,
|
|
1183
|
-
env,
|
|
1184
|
-
executionCtx,
|
|
1185
|
-
notFoundHandler: this.#notFoundHandler
|
|
1186
|
-
});
|
|
1187
|
-
if (matchResult[0].length === 1) {
|
|
1188
|
-
let res;
|
|
1189
|
-
try {
|
|
1190
|
-
res = matchResult[0][0][0][0](c, async () => {
|
|
1191
|
-
c.res = await this.#notFoundHandler(c);
|
|
1192
|
-
});
|
|
1193
|
-
} catch (err) {
|
|
1194
|
-
return this.#handleError(err, c);
|
|
1195
|
-
}
|
|
1196
|
-
return res instanceof Promise ? res.then((resolved) => resolved || (c.finalized ? c.res : this.#notFoundHandler(c))).catch((err) => this.#handleError(err, c)) : res ?? this.#notFoundHandler(c);
|
|
1197
|
-
}
|
|
1198
|
-
const composed = compose(matchResult[0], this.errorHandler, this.#notFoundHandler);
|
|
1199
|
-
return (async () => {
|
|
1200
|
-
try {
|
|
1201
|
-
const context = await composed(c);
|
|
1202
|
-
if (!context.finalized) throw new Error("Context is not finalized. Did you forget to return a Response object or `await next()`?");
|
|
1203
|
-
return context.res;
|
|
1204
|
-
} catch (err) {
|
|
1205
|
-
return this.#handleError(err, c);
|
|
1206
|
-
}
|
|
1207
|
-
})();
|
|
1208
|
-
}
|
|
1209
|
-
/**
|
|
1210
|
-
* `.fetch()` will be entry point of your app.
|
|
1211
|
-
*
|
|
1212
|
-
* @see {@link https://hono.dev/docs/api/hono#fetch}
|
|
1213
|
-
*
|
|
1214
|
-
* @param {Request} request - request Object of request
|
|
1215
|
-
* @param {Env} env - env Object
|
|
1216
|
-
* @param {ExecutionContext} executionCtx - context of execution
|
|
1217
|
-
* @returns {Response | Promise<Response>} response of request
|
|
1218
|
-
*
|
|
1219
|
-
*/
|
|
1220
|
-
fetch = (request, ...rest) => {
|
|
1221
|
-
return this.#dispatch(request, rest[1], rest[0], request.method);
|
|
1222
|
-
};
|
|
1223
|
-
/**
|
|
1224
|
-
* `.request()` is a useful method for testing.
|
|
1225
|
-
* You can pass a URL or pathname to send a GET request.
|
|
1226
|
-
* app will return a Response object.
|
|
1227
|
-
* ```ts
|
|
1228
|
-
* test('GET /hello is ok', async () => {
|
|
1229
|
-
* const res = await app.request('/hello')
|
|
1230
|
-
* expect(res.status).toBe(200)
|
|
1231
|
-
* })
|
|
1232
|
-
* ```
|
|
1233
|
-
* @see https://hono.dev/docs/api/hono#request
|
|
1234
|
-
*/
|
|
1235
|
-
request = (input, requestInit, Env, executionCtx) => {
|
|
1236
|
-
if (input instanceof Request) return this.fetch(requestInit ? new Request(input, requestInit) : input, Env, executionCtx);
|
|
1237
|
-
input = input.toString();
|
|
1238
|
-
return this.fetch(new Request(/^https?:\/\//.test(input) ? input : `http://localhost${mergePath("/", input)}`, requestInit), Env, executionCtx);
|
|
1239
|
-
};
|
|
1240
|
-
/**
|
|
1241
|
-
* `.fire()` automatically adds a global fetch event listener.
|
|
1242
|
-
* This can be useful for environments that adhere to the Service Worker API, such as non-ES module Cloudflare Workers.
|
|
1243
|
-
* @deprecated
|
|
1244
|
-
* Use `fire` from `hono/service-worker` instead.
|
|
1245
|
-
* ```ts
|
|
1246
|
-
* import { Hono } from 'hono'
|
|
1247
|
-
* import { fire } from 'hono/service-worker'
|
|
1248
|
-
*
|
|
1249
|
-
* const app = new Hono()
|
|
1250
|
-
* // ...
|
|
1251
|
-
* fire(app)
|
|
1252
|
-
* ```
|
|
1253
|
-
* @see https://hono.dev/docs/api/hono#fire
|
|
1254
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API
|
|
1255
|
-
* @see https://developers.cloudflare.com/workers/reference/migrate-to-module-workers/
|
|
1256
|
-
*/
|
|
1257
|
-
fire = () => {
|
|
1258
|
-
addEventListener("fetch", (event) => {
|
|
1259
|
-
event.respondWith(this.#dispatch(event.request, event, void 0, event.request.method));
|
|
1260
|
-
});
|
|
1261
|
-
};
|
|
1262
|
-
};
|
|
1263
|
-
//#endregion
|
|
1264
|
-
//#region ../../node_modules/.pnpm/hono@4.13.3/node_modules/hono/dist/router/reg-exp-router/matcher.js
|
|
1265
|
-
var emptyParam = [];
|
|
1266
|
-
function match(method, path) {
|
|
1267
|
-
const matchers = this.buildAllMatchers();
|
|
1268
|
-
const match2 = ((method2, path2) => {
|
|
1269
|
-
const matcher = matchers[method2] || matchers["ALL"];
|
|
1270
|
-
const staticMatch = matcher[2][path2];
|
|
1271
|
-
if (staticMatch) return staticMatch;
|
|
1272
|
-
const match3 = path2.match(matcher[0]);
|
|
1273
|
-
if (!match3) return [[], emptyParam];
|
|
1274
|
-
const index = match3.indexOf("", 1);
|
|
1275
|
-
return [matcher[1][index], match3];
|
|
1276
|
-
});
|
|
1277
|
-
this.match = match2;
|
|
1278
|
-
return match2(method, path);
|
|
1279
|
-
}
|
|
1280
|
-
//#endregion
|
|
1281
|
-
//#region ../../node_modules/.pnpm/hono@4.13.3/node_modules/hono/dist/router/reg-exp-router/node.js
|
|
1282
|
-
var LABEL_REG_EXP_STR = "[^/]+";
|
|
1283
|
-
var ONLY_WILDCARD_REG_EXP_STR = ".*";
|
|
1284
|
-
var TAIL_WILDCARD_REG_EXP_STR = "(?:|/.*)";
|
|
1285
|
-
var PATH_ERROR = /* @__PURE__ */ Symbol();
|
|
1286
|
-
var regExpMetaChars = /* @__PURE__ */ new Set(".\\+*[^]$()");
|
|
1287
|
-
function compareKey(a, b) {
|
|
1288
|
-
if (a.length === 1) return b.length === 1 ? a < b ? -1 : 1 : -1;
|
|
1289
|
-
if (b.length === 1) return 1;
|
|
1290
|
-
if (a === ONLY_WILDCARD_REG_EXP_STR || a === TAIL_WILDCARD_REG_EXP_STR) return b === TAIL_WILDCARD_REG_EXP_STR ? -1 : 1;
|
|
1291
|
-
else if (b === ONLY_WILDCARD_REG_EXP_STR || b === TAIL_WILDCARD_REG_EXP_STR) return -1;
|
|
1292
|
-
if (a === LABEL_REG_EXP_STR) return 1;
|
|
1293
|
-
else if (b === LABEL_REG_EXP_STR) return -1;
|
|
1294
|
-
return a.length === b.length ? a < b ? -1 : 1 : b.length - a.length;
|
|
1295
|
-
}
|
|
1296
|
-
var Node$1 = class _Node {
|
|
1297
|
-
#index;
|
|
1298
|
-
#varIndex;
|
|
1299
|
-
#children = /* @__PURE__ */ Object.create(null);
|
|
1300
|
-
insert(tokens, index, paramMap, context, isStatic) {
|
|
1301
|
-
let node = this;
|
|
1302
|
-
for (let i = 0, len = tokens.length; i < len; i++) {
|
|
1303
|
-
const token = tokens[i];
|
|
1304
|
-
const pattern = token.length === 1 ? token === "*" ? i === len - 1 ? [
|
|
1305
|
-
"",
|
|
1306
|
-
"",
|
|
1307
|
-
ONLY_WILDCARD_REG_EXP_STR
|
|
1308
|
-
] : [
|
|
1309
|
-
"",
|
|
1310
|
-
"",
|
|
1311
|
-
LABEL_REG_EXP_STR
|
|
1312
|
-
] : null : token === "/*" ? [
|
|
1313
|
-
"",
|
|
1314
|
-
"",
|
|
1315
|
-
TAIL_WILDCARD_REG_EXP_STR
|
|
1316
|
-
] : token.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
|
|
1317
|
-
let nextNode;
|
|
1318
|
-
if (pattern) {
|
|
1319
|
-
const name = pattern[1];
|
|
1320
|
-
let regexpStr = pattern[2] || LABEL_REG_EXP_STR;
|
|
1321
|
-
if (name && pattern[2]) {
|
|
1322
|
-
if (regexpStr === ".*") throw PATH_ERROR;
|
|
1323
|
-
regexpStr = regexpStr.replace(/^\((?!\?:)(?=[^)]+\)$)/, "(?:");
|
|
1324
|
-
if (/\((?!\?:)/.test(regexpStr)) throw PATH_ERROR;
|
|
1325
|
-
if (regexpStr.length === 1 && regExpMetaChars.has(regexpStr)) throw PATH_ERROR;
|
|
1326
|
-
}
|
|
1327
|
-
nextNode = node.#children[regexpStr];
|
|
1328
|
-
if (!nextNode) {
|
|
1329
|
-
if (regexpStr !== ONLY_WILDCARD_REG_EXP_STR && regexpStr !== TAIL_WILDCARD_REG_EXP_STR) {
|
|
1330
|
-
for (const k in node.#children) if ((regexpStr.length > 1 || k.length > 1) && k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR) throw PATH_ERROR;
|
|
1331
|
-
}
|
|
1332
|
-
nextNode = node.#children[regexpStr] = new _Node();
|
|
1333
|
-
}
|
|
1334
|
-
if (name !== "") {
|
|
1335
|
-
nextNode.#varIndex ??= context.varIndex++;
|
|
1336
|
-
paramMap.push([name, nextNode.#varIndex]);
|
|
1337
|
-
}
|
|
1338
|
-
} else {
|
|
1339
|
-
nextNode = node.#children[token];
|
|
1340
|
-
if (!nextNode) {
|
|
1341
|
-
for (const k in node.#children) if (k.length > 1 && k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR) throw PATH_ERROR;
|
|
1342
|
-
nextNode = node.#children[token] = new _Node();
|
|
1343
|
-
}
|
|
1344
|
-
}
|
|
1345
|
-
node = nextNode;
|
|
1346
|
-
}
|
|
1347
|
-
if (node.#index !== void 0) throw PATH_ERROR;
|
|
1348
|
-
node.#index = isStatic ? -1 : index;
|
|
1349
|
-
}
|
|
1350
|
-
buildRegExpStr() {
|
|
1351
|
-
const strList = Object.keys(this.#children).sort(compareKey).map((k) => {
|
|
1352
|
-
const c = this.#children[k];
|
|
1353
|
-
const childStr = c.buildRegExpStr();
|
|
1354
|
-
return childStr === "" ? "" : (typeof c.#varIndex === "number" ? `(${k})@${c.#varIndex}` : regExpMetaChars.has(k) ? `\\${k}` : k) + childStr;
|
|
1355
|
-
}).filter(Boolean);
|
|
1356
|
-
if (typeof this.#index === "number" && this.#index !== -1) strList.unshift(`#${this.#index}`);
|
|
1357
|
-
if (strList.length === 0) return "";
|
|
1358
|
-
if (strList.length === 1) return strList[0];
|
|
1359
|
-
return "(?:" + strList.join("|") + ")";
|
|
1360
|
-
}
|
|
1361
|
-
};
|
|
1362
|
-
//#endregion
|
|
1363
|
-
//#region ../../node_modules/.pnpm/hono@4.13.3/node_modules/hono/dist/router/reg-exp-router/trie.js
|
|
1364
|
-
var Trie = class {
|
|
1365
|
-
#context = { varIndex: 0 };
|
|
1366
|
-
#root = new Node$1();
|
|
1367
|
-
#index = 0;
|
|
1368
|
-
paths = /* @__PURE__ */ Object.create(null);
|
|
1369
|
-
insert(path, isStatic) {
|
|
1370
|
-
if (isStatic) {
|
|
1371
|
-
this.#root.insert(path.split(""), 0, [], this.#context, true);
|
|
1372
|
-
return;
|
|
1373
|
-
}
|
|
1374
|
-
const paramAssoc = [];
|
|
1375
|
-
const groups = [];
|
|
1376
|
-
let markedPath = path;
|
|
1377
|
-
for (let i = 0;;) {
|
|
1378
|
-
let replaced = false;
|
|
1379
|
-
markedPath = markedPath.replace(/\{[^}]+\}/g, (m) => {
|
|
1380
|
-
const mark = `@\\${i}`;
|
|
1381
|
-
groups[i] = [mark, m];
|
|
1382
|
-
i++;
|
|
1383
|
-
replaced = true;
|
|
1384
|
-
return mark;
|
|
1385
|
-
});
|
|
1386
|
-
if (!replaced) break;
|
|
1387
|
-
}
|
|
1388
|
-
const tokens = markedPath.match(/(?::[^\/]+)|(?:\/\*$)|./g) || [];
|
|
1389
|
-
for (let i = groups.length - 1; i >= 0; i--) {
|
|
1390
|
-
const [mark] = groups[i];
|
|
1391
|
-
for (let j = tokens.length - 1; j >= 0; j--) if (tokens[j].indexOf(mark) !== -1) {
|
|
1392
|
-
tokens[j] = tokens[j].replace(mark, groups[i][1]);
|
|
1393
|
-
break;
|
|
1394
|
-
}
|
|
1395
|
-
}
|
|
1396
|
-
this.#root.insert(tokens, this.#index, paramAssoc, this.#context, false);
|
|
1397
|
-
this.paths[path] = [this.#index++, paramAssoc];
|
|
1398
|
-
}
|
|
1399
|
-
buildRegExp() {
|
|
1400
|
-
let regexp = this.#root.buildRegExpStr();
|
|
1401
|
-
if (regexp === "") return [
|
|
1402
|
-
/^$/,
|
|
1403
|
-
[],
|
|
1404
|
-
[]
|
|
1405
|
-
];
|
|
1406
|
-
let captureIndex = 0;
|
|
1407
|
-
const indexReplacementMap = [];
|
|
1408
|
-
const paramReplacementMap = [];
|
|
1409
|
-
regexp = regexp.replace(/#(\d+)|@(\d+)|\.\*\$/g, (_, handlerIndex, paramIndex) => {
|
|
1410
|
-
if (handlerIndex !== void 0) {
|
|
1411
|
-
indexReplacementMap[++captureIndex] = Number(handlerIndex);
|
|
1412
|
-
return "$()";
|
|
1413
|
-
}
|
|
1414
|
-
if (paramIndex !== void 0) {
|
|
1415
|
-
paramReplacementMap[Number(paramIndex)] = ++captureIndex;
|
|
1416
|
-
return "";
|
|
1417
|
-
}
|
|
1418
|
-
return "";
|
|
1419
|
-
});
|
|
1420
|
-
return [
|
|
1421
|
-
new RegExp(`^${regexp}`),
|
|
1422
|
-
indexReplacementMap,
|
|
1423
|
-
paramReplacementMap
|
|
1424
|
-
];
|
|
1425
|
-
}
|
|
1426
|
-
};
|
|
1427
|
-
//#endregion
|
|
1428
|
-
//#region ../../node_modules/.pnpm/hono@4.13.3/node_modules/hono/dist/router/reg-exp-router/router.js
|
|
1429
|
-
var wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
|
|
1430
|
-
function buildWildcardRegExp(path) {
|
|
1431
|
-
return wildcardRegExpCache[path] ??= new RegExp(path === "*" ? "" : `^${path.replace(/\/\*$|([.\\+*[^\]$()])/g, (_, metaChar) => metaChar ? `\\${metaChar}` : "(?:|/.*)")}$`);
|
|
1432
|
-
}
|
|
1433
|
-
function clearWildcardRegExpCache() {
|
|
1434
|
-
wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
|
|
1435
|
-
}
|
|
1436
|
-
function findMiddleware(middleware, path) {
|
|
1437
|
-
if (!middleware) return;
|
|
1438
|
-
for (const k of Object.keys(middleware).sort((a, b) => b.length - a.length)) if (buildWildcardRegExp(k).test(path)) return [...middleware[k]];
|
|
1439
|
-
}
|
|
1440
|
-
var RegExpRouter = class {
|
|
1441
|
-
name = "RegExpRouter";
|
|
1442
|
-
#middleware;
|
|
1443
|
-
#routes;
|
|
1444
|
-
#tries;
|
|
1445
|
-
constructor() {
|
|
1446
|
-
this.#middleware = { ["ALL"]: /* @__PURE__ */ Object.create(null) };
|
|
1447
|
-
this.#routes = { ["ALL"]: /* @__PURE__ */ Object.create(null) };
|
|
1448
|
-
this.#tries = { ["ALL"]: new Trie() };
|
|
1449
|
-
}
|
|
1450
|
-
#insertPath(method, path) {
|
|
1451
|
-
try {
|
|
1452
|
-
this.#tries[method].insert(path, !/\*|\/:/.test(path));
|
|
1453
|
-
} catch (e) {
|
|
1454
|
-
throw e === PATH_ERROR ? new UnsupportedPathError(path) : e;
|
|
1455
|
-
}
|
|
1456
|
-
}
|
|
1457
|
-
add(method, path, handler) {
|
|
1458
|
-
const middleware = this.#middleware;
|
|
1459
|
-
const routes = this.#routes;
|
|
1460
|
-
if (!middleware || !routes) throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
|
|
1461
|
-
if (!middleware[method]) {
|
|
1462
|
-
this.#tries[method] = new Trie();
|
|
1463
|
-
[middleware, routes].forEach((handlerMap) => {
|
|
1464
|
-
handlerMap[method] = /* @__PURE__ */ Object.create(null);
|
|
1465
|
-
Object.keys(handlerMap["ALL"]).forEach((p) => {
|
|
1466
|
-
handlerMap[method][p] = [...handlerMap["ALL"][p]];
|
|
1467
|
-
this.#insertPath(method, p);
|
|
1468
|
-
});
|
|
1469
|
-
});
|
|
1470
|
-
}
|
|
1471
|
-
if (path === "/*") path = "*";
|
|
1472
|
-
const paramCount = (path.match(/\/:/g) || []).length;
|
|
1473
|
-
if (/\*$/.test(path)) {
|
|
1474
|
-
const re = buildWildcardRegExp(path);
|
|
1475
|
-
Object.keys(middleware).forEach((m) => {
|
|
1476
|
-
if ((method === "ALL" || method === m) && !middleware[m][path]) {
|
|
1477
|
-
this.#insertPath(m, path);
|
|
1478
|
-
middleware[m][path] = findMiddleware(middleware[m], path) || findMiddleware(middleware["ALL"], path) || [];
|
|
1479
|
-
}
|
|
1480
|
-
});
|
|
1481
|
-
Object.keys(middleware).forEach((m) => {
|
|
1482
|
-
if (method === "ALL" || method === m) Object.keys(middleware[m]).forEach((p) => {
|
|
1483
|
-
re.test(p) && middleware[m][p].push([handler, paramCount]);
|
|
1484
|
-
});
|
|
1485
|
-
});
|
|
1486
|
-
Object.keys(routes).forEach((m) => {
|
|
1487
|
-
if (method === "ALL" || method === m) Object.keys(routes[m]).forEach((p) => re.test(p) && routes[m][p].push([handler, paramCount]));
|
|
1488
|
-
});
|
|
1489
|
-
return;
|
|
1490
|
-
}
|
|
1491
|
-
const paths = checkOptionalParameter(path) || [path];
|
|
1492
|
-
for (let i = 0, len = paths.length; i < len; i++) {
|
|
1493
|
-
const path2 = paths[i];
|
|
1494
|
-
Object.keys(routes).forEach((m) => {
|
|
1495
|
-
if (method === "ALL" || method === m) {
|
|
1496
|
-
if (!routes[m][path2]) {
|
|
1497
|
-
this.#insertPath(m, path2);
|
|
1498
|
-
routes[m][path2] = [...findMiddleware(middleware[m], path2) || findMiddleware(middleware["ALL"], path2) || []];
|
|
1499
|
-
}
|
|
1500
|
-
routes[m][path2].push([handler, paramCount - len + i + 1]);
|
|
1501
|
-
}
|
|
1502
|
-
});
|
|
1503
|
-
}
|
|
1504
|
-
}
|
|
1505
|
-
match = match;
|
|
1506
|
-
buildAllMatchers() {
|
|
1507
|
-
const matchers = /* @__PURE__ */ Object.create(null);
|
|
1508
|
-
Object.keys(this.#routes).concat(Object.keys(this.#middleware)).forEach((method) => {
|
|
1509
|
-
matchers[method] ||= this.#buildMatcher(method);
|
|
1510
|
-
});
|
|
1511
|
-
this.#middleware = this.#routes = this.#tries = void 0;
|
|
1512
|
-
clearWildcardRegExpCache();
|
|
1513
|
-
return matchers;
|
|
1514
|
-
}
|
|
1515
|
-
#buildMatcher(method) {
|
|
1516
|
-
const middleware = this.#middleware[method];
|
|
1517
|
-
const routes = this.#routes[method];
|
|
1518
|
-
const trie = this.#tries[method];
|
|
1519
|
-
const staticMap = /* @__PURE__ */ Object.create(null);
|
|
1520
|
-
const handlerData = [];
|
|
1521
|
-
[middleware, routes].forEach((r) => {
|
|
1522
|
-
for (const path in r) {
|
|
1523
|
-
const handlers = r[path];
|
|
1524
|
-
const pathData = trie.paths[path];
|
|
1525
|
-
if (!pathData) {
|
|
1526
|
-
staticMap[path] = [handlers.map(([h]) => [h, /* @__PURE__ */ Object.create(null)]), emptyParam];
|
|
1527
|
-
continue;
|
|
1528
|
-
}
|
|
1529
|
-
const paramAssoc = pathData[1];
|
|
1530
|
-
handlerData[pathData[0]] = handlers.map(([h, paramCount]) => {
|
|
1531
|
-
const paramIndexMap = /* @__PURE__ */ Object.create(null);
|
|
1532
|
-
paramCount -= 1;
|
|
1533
|
-
for (; paramCount >= 0; paramCount--) {
|
|
1534
|
-
const [key, value] = paramAssoc[paramCount];
|
|
1535
|
-
paramIndexMap[key] = value;
|
|
1536
|
-
}
|
|
1537
|
-
return [h, paramIndexMap];
|
|
1538
|
-
});
|
|
1539
|
-
}
|
|
1540
|
-
});
|
|
1541
|
-
const [regexp, indexReplacementMap, paramReplacementMap] = trie.buildRegExp();
|
|
1542
|
-
for (let i = 0, len = handlerData.length; i < len; i++) for (let j = 0, len2 = handlerData[i].length; j < len2; j++) {
|
|
1543
|
-
const map = handlerData[i][j]?.[1];
|
|
1544
|
-
if (!map) continue;
|
|
1545
|
-
const keys = Object.keys(map);
|
|
1546
|
-
for (let k = 0, len3 = keys.length; k < len3; k++) map[keys[k]] = paramReplacementMap[map[keys[k]]];
|
|
1547
|
-
}
|
|
1548
|
-
const handlerMap = [];
|
|
1549
|
-
for (const i in indexReplacementMap) handlerMap[i] = handlerData[indexReplacementMap[i]];
|
|
1550
|
-
return [
|
|
1551
|
-
regexp,
|
|
1552
|
-
handlerMap,
|
|
1553
|
-
staticMap
|
|
1554
|
-
];
|
|
1555
|
-
}
|
|
1556
|
-
};
|
|
1557
|
-
//#endregion
|
|
1558
|
-
//#region ../../node_modules/.pnpm/hono@4.13.3/node_modules/hono/dist/router/smart-router/router.js
|
|
1559
|
-
var SmartRouter = class {
|
|
1560
|
-
name = "SmartRouter";
|
|
1561
|
-
#routers = [];
|
|
1562
|
-
#routes = [];
|
|
1563
|
-
constructor(init) {
|
|
1564
|
-
this.#routers = init.routers;
|
|
1565
|
-
}
|
|
1566
|
-
add(method, path, handler) {
|
|
1567
|
-
if (!this.#routes) throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
|
|
1568
|
-
this.#routes.push([
|
|
1569
|
-
method,
|
|
1570
|
-
path,
|
|
1571
|
-
handler
|
|
1572
|
-
]);
|
|
1573
|
-
}
|
|
1574
|
-
match(method, path) {
|
|
1575
|
-
if (!this.#routes) throw new Error("Fatal error");
|
|
1576
|
-
const routers = this.#routers;
|
|
1577
|
-
const routes = this.#routes;
|
|
1578
|
-
const len = routers.length;
|
|
1579
|
-
let i = 0;
|
|
1580
|
-
let res;
|
|
1581
|
-
for (; i < len; i++) {
|
|
1582
|
-
const router = routers[i];
|
|
1583
|
-
try {
|
|
1584
|
-
for (let i2 = 0, len2 = routes.length; i2 < len2; i2++) router.add(...routes[i2]);
|
|
1585
|
-
res = router.match(method, path);
|
|
1586
|
-
} catch (e) {
|
|
1587
|
-
if (e instanceof UnsupportedPathError) continue;
|
|
1588
|
-
throw e;
|
|
1589
|
-
}
|
|
1590
|
-
this.match = router.match.bind(router);
|
|
1591
|
-
this.#routers = [router];
|
|
1592
|
-
this.#routes = void 0;
|
|
1593
|
-
break;
|
|
1594
|
-
}
|
|
1595
|
-
if (i === len) throw new Error("Fatal error");
|
|
1596
|
-
this.name = `SmartRouter + ${this.activeRouter.name}`;
|
|
1597
|
-
return res;
|
|
1598
|
-
}
|
|
1599
|
-
get activeRouter() {
|
|
1600
|
-
if (this.#routes || this.#routers.length !== 1) throw new Error("No active router has been determined yet.");
|
|
1601
|
-
return this.#routers[0];
|
|
1602
|
-
}
|
|
1603
|
-
};
|
|
1604
|
-
//#endregion
|
|
1605
|
-
//#region ../../node_modules/.pnpm/hono@4.13.3/node_modules/hono/dist/router/trie-router/node.js
|
|
1606
|
-
var emptyParams = /* @__PURE__ */ Object.create(null);
|
|
1607
|
-
var order = 0;
|
|
1608
|
-
var Node = class _Node {
|
|
1609
|
-
#methods = [];
|
|
1610
|
-
#children = /* @__PURE__ */ Object.create(null);
|
|
1611
|
-
#patterns = [];
|
|
1612
|
-
#pattern;
|
|
1613
|
-
#params = emptyParams;
|
|
1614
|
-
insert(method, path, handler) {
|
|
1615
|
-
let curNode = this;
|
|
1616
|
-
const parts = splitRoutingPath(path);
|
|
1617
|
-
const possibleKeys = /* @__PURE__ */ new Set();
|
|
1618
|
-
let i = 0;
|
|
1619
|
-
for (const p of parts) {
|
|
1620
|
-
const nextP = parts[++i];
|
|
1621
|
-
const pattern = getPattern(p, nextP) || (nextP === void 0 && p && p.indexOf("*") === p.length - 1 ? p : null);
|
|
1622
|
-
const isParam = Array.isArray(pattern);
|
|
1623
|
-
const key = isParam ? pattern[0] : pattern || p;
|
|
1624
|
-
const child = curNode.#children[key] ||= new _Node();
|
|
1625
|
-
if (pattern && !child.#pattern) {
|
|
1626
|
-
child.#pattern = pattern;
|
|
1627
|
-
curNode.#patterns.push(child);
|
|
1628
|
-
}
|
|
1629
|
-
curNode = child;
|
|
1630
|
-
if (isParam) possibleKeys.add(pattern[1]);
|
|
1631
|
-
}
|
|
1632
|
-
curNode.#methods.push({ [method]: {
|
|
1633
|
-
handler,
|
|
1634
|
-
possibleKeys: [...possibleKeys],
|
|
1635
|
-
score: ++order
|
|
1636
|
-
} });
|
|
1637
|
-
}
|
|
1638
|
-
#pushHandlerSets(handlerSets, node, method, nodeParams, params) {
|
|
1639
|
-
for (let i = 0, len = node.#methods.length; i < len; i++) {
|
|
1640
|
-
const m = node.#methods[i];
|
|
1641
|
-
const handlerSet = m[method] || m["ALL"];
|
|
1642
|
-
if (handlerSet) {
|
|
1643
|
-
handlerSet.params = /* @__PURE__ */ Object.create(null);
|
|
1644
|
-
handlerSets.push(handlerSet);
|
|
1645
|
-
for (let i2 = 0, len2 = handlerSet.possibleKeys.length; i2 < len2; i2++) {
|
|
1646
|
-
const key = handlerSet.possibleKeys[i2];
|
|
1647
|
-
handlerSet.params[key] = params?.[key] && !i2 ? params[key] : nodeParams[key] ?? params?.[key];
|
|
1648
|
-
}
|
|
1649
|
-
}
|
|
1650
|
-
}
|
|
1651
|
-
}
|
|
1652
|
-
search(method, path) {
|
|
1653
|
-
const handlerSets = [];
|
|
1654
|
-
this.#params = emptyParams;
|
|
1655
|
-
let curNodes = [this];
|
|
1656
|
-
const parts = splitPath(path);
|
|
1657
|
-
const curNodesQueue = [];
|
|
1658
|
-
const len = parts.length;
|
|
1659
|
-
let partOffsets = null;
|
|
1660
|
-
for (let i = 0; i < len; i++) {
|
|
1661
|
-
const part = parts[i];
|
|
1662
|
-
const isLast = i === len - 1;
|
|
1663
|
-
const tempNodes = [];
|
|
1664
|
-
for (let j = 0, len2 = curNodes.length; j < len2; j++) {
|
|
1665
|
-
const node = curNodes[j];
|
|
1666
|
-
const nextNode = node.#children[part];
|
|
1667
|
-
if (nextNode) {
|
|
1668
|
-
nextNode.#params = node.#params;
|
|
1669
|
-
if (isLast) {
|
|
1670
|
-
if (nextNode.#children["*"]) this.#pushHandlerSets(handlerSets, nextNode.#children["*"], method, node.#params);
|
|
1671
|
-
this.#pushHandlerSets(handlerSets, nextNode, method, node.#params);
|
|
1672
|
-
} else tempNodes.push(nextNode);
|
|
1673
|
-
}
|
|
1674
|
-
for (const child of node.#patterns) {
|
|
1675
|
-
const pattern = child.#pattern;
|
|
1676
|
-
const params = node.#params === emptyParams ? {} : { ...node.#params };
|
|
1677
|
-
if (typeof pattern === "string") {
|
|
1678
|
-
if (pattern === "*" || part.startsWith(pattern.slice(0, -1))) {
|
|
1679
|
-
this.#pushHandlerSets(handlerSets, child, method, node.#params);
|
|
1680
|
-
if (pattern === "*") {
|
|
1681
|
-
child.#params = params;
|
|
1682
|
-
tempNodes.push(child);
|
|
1683
|
-
}
|
|
1684
|
-
}
|
|
1685
|
-
continue;
|
|
1686
|
-
}
|
|
1687
|
-
const [, name, matcher] = pattern;
|
|
1688
|
-
if (!part && matcher === true) continue;
|
|
1689
|
-
if (matcher !== true) {
|
|
1690
|
-
if (!partOffsets) {
|
|
1691
|
-
partOffsets = [];
|
|
1692
|
-
let offset = path[0] === "/" ? 1 : 0;
|
|
1693
|
-
for (let p = 0; p < len; p++) {
|
|
1694
|
-
partOffsets[p] = offset;
|
|
1695
|
-
offset += parts[p].length + 1;
|
|
1696
|
-
}
|
|
1697
|
-
}
|
|
1698
|
-
const restPathString = path.slice(partOffsets[i]);
|
|
1699
|
-
const m = matcher.exec(restPathString);
|
|
1700
|
-
if (m) {
|
|
1701
|
-
params[name] = m[0];
|
|
1702
|
-
this.#pushHandlerSets(handlerSets, child, method, node.#params, params);
|
|
1703
|
-
if (m[0].length === restPathString.length && child.#children["*"]) this.#pushHandlerSets(handlerSets, child.#children["*"], method, node.#params, params);
|
|
1704
|
-
for (const _ in child.#children) {
|
|
1705
|
-
child.#params = params;
|
|
1706
|
-
const componentCount = m[0].match(/\//g)?.length ?? 0;
|
|
1707
|
-
(curNodesQueue[componentCount] ||= []).push(child);
|
|
1708
|
-
break;
|
|
1709
|
-
}
|
|
1710
|
-
continue;
|
|
1711
|
-
}
|
|
1712
|
-
}
|
|
1713
|
-
if (matcher === true || matcher.test(part)) {
|
|
1714
|
-
params[name] = part;
|
|
1715
|
-
if (isLast) {
|
|
1716
|
-
this.#pushHandlerSets(handlerSets, child, method, params, node.#params);
|
|
1717
|
-
if (child.#children["*"]) this.#pushHandlerSets(handlerSets, child.#children["*"], method, params, node.#params);
|
|
1718
|
-
} else {
|
|
1719
|
-
child.#params = params;
|
|
1720
|
-
tempNodes.push(child);
|
|
1721
|
-
}
|
|
1722
|
-
}
|
|
1723
|
-
}
|
|
1724
|
-
}
|
|
1725
|
-
const shifted = curNodesQueue.shift();
|
|
1726
|
-
curNodes = shifted ? tempNodes.concat(shifted) : tempNodes;
|
|
1727
|
-
}
|
|
1728
|
-
if (handlerSets[1]) handlerSets.sort((a, b) => {
|
|
1729
|
-
return a.score - b.score;
|
|
1730
|
-
});
|
|
1731
|
-
return [handlerSets.map(({ handler, params }) => [handler, params])];
|
|
1732
|
-
}
|
|
1733
|
-
};
|
|
1734
|
-
//#endregion
|
|
1735
|
-
//#region ../../node_modules/.pnpm/hono@4.13.3/node_modules/hono/dist/router/trie-router/router.js
|
|
1736
|
-
var TrieRouter = class {
|
|
1737
|
-
name = "TrieRouter";
|
|
1738
|
-
#node = new Node();
|
|
1739
|
-
add(method, path, handler) {
|
|
1740
|
-
for (const result of checkOptionalParameter(path) || [path]) this.#node.insert(method, result, handler);
|
|
1741
|
-
}
|
|
1742
|
-
match(method, path) {
|
|
1743
|
-
return this.#node.search(method, path);
|
|
1744
|
-
}
|
|
1745
|
-
};
|
|
1746
|
-
//#endregion
|
|
1747
|
-
//#region ../../node_modules/.pnpm/hono@4.13.3/node_modules/hono/dist/hono.js
|
|
1748
|
-
var Hono = class extends Hono$1 {
|
|
1749
|
-
/**
|
|
1750
|
-
* Creates an instance of the Hono class.
|
|
1751
|
-
*
|
|
1752
|
-
* @param options - Optional configuration options for the Hono instance.
|
|
1753
|
-
*/
|
|
1754
|
-
constructor(options = {}) {
|
|
1755
|
-
super(options);
|
|
1756
|
-
this.router = options.router ?? new SmartRouter({ routers: [new RegExpRouter(), new TrieRouter()] });
|
|
1757
|
-
}
|
|
1758
|
-
};
|
|
1759
|
-
//#endregion
|
|
1760
|
-
//#region ../../dist/definePage-CaSxfTRr.mjs
|
|
1761
|
-
var PAGE_KIND = "honoto:page";
|
|
1762
|
-
var SERVER_PAGE_KIND = "honoto:server-page";
|
|
1763
|
-
function isPageDefinition(value) {
|
|
1764
|
-
if (value === null || typeof value !== "object" && typeof value !== "function") return false;
|
|
1765
|
-
const candidate = value;
|
|
1766
|
-
return (candidate.kind === "honoto:page" || candidate.kind === "honoto:server-page") && typeof candidate.render === "function";
|
|
1767
|
-
}
|
|
1768
|
-
function readPageDefinition(value) {
|
|
1769
|
-
return isPageDefinition(value) ? value : void 0;
|
|
1770
|
-
}
|
|
1771
|
-
function resolvePageRender(value) {
|
|
1772
|
-
if (isPageDefinition(value)) return value.render;
|
|
1773
|
-
if (typeof value === "function") return value;
|
|
1774
|
-
}
|
|
1775
|
-
function pageDefinition(page, kind, fnName) {
|
|
1776
|
-
if (typeof page === "function") return {
|
|
1777
|
-
kind,
|
|
1778
|
-
client: kind === PAGE_KIND,
|
|
1779
|
-
render: page
|
|
1780
|
-
};
|
|
1781
|
-
const render = page.render ?? page.page;
|
|
1782
|
-
if (typeof render !== "function") throw new TypeError(`[honoto] ${fnName}() requires a JSX function or { render }`);
|
|
1783
|
-
return {
|
|
1784
|
-
kind,
|
|
1785
|
-
client: kind === PAGE_KIND,
|
|
1786
|
-
render,
|
|
1787
|
-
data: page.data,
|
|
1788
|
-
config: page.config
|
|
1789
|
-
};
|
|
1790
|
-
}
|
|
1791
|
-
function definePage(page) {
|
|
1792
|
-
return pageDefinition(page, PAGE_KIND, "definePage");
|
|
1793
|
-
}
|
|
1794
|
-
function defineServerPage(page) {
|
|
1795
|
-
return pageDefinition(page, SERVER_PAGE_KIND, "defineServerPage");
|
|
1796
|
-
}
|
|
1797
|
-
//#endregion
|
|
1798
|
-
//#region ../../dist/compile--TCrnBT5.mjs
|
|
1799
|
-
function loadMergedConfig(page, pageMod) {
|
|
1800
|
-
const merged = { ...page.config };
|
|
1801
|
-
const inline = readPageDefinition(pageMod?.default)?.config;
|
|
1802
|
-
if (inline) Object.assign(merged, inline);
|
|
1803
|
-
return merged;
|
|
1804
|
-
}
|
|
1805
|
-
async function loadMergedData(_page, c, pageMod) {
|
|
1806
|
-
const fn = readPageDefinition(pageMod?.default)?.data;
|
|
1807
|
-
if (!fn) return void 0;
|
|
1808
|
-
return await fn(c);
|
|
1809
|
-
}
|
|
1810
|
-
var SERVER_FN_KIND = "honoto:server-fn";
|
|
1811
|
-
/**
|
|
1812
|
-
* Mark a function as server-only.
|
|
1813
|
-
*
|
|
1814
|
-
* Pass the result to `definePage({ data })` (or `defineServerPage`) as a
|
|
1815
|
-
* loader. The same function can later be imported and invoked
|
|
1816
|
-
*
|
|
1817
|
-
* @example
|
|
1818
|
-
* // [slug].server.ts
|
|
1819
|
-
* export default defineServerFn(c => {
|
|
1820
|
-
* const slug = c.req.param("slug") ?? ""
|
|
1821
|
-
* return { slug }
|
|
1822
|
-
* })
|
|
1823
|
-
*
|
|
1824
|
-
* @example
|
|
1825
|
-
* // [slug].tsx
|
|
1826
|
-
* import data from "./[slug].server"
|
|
1827
|
-
* export default definePage({ data, render: ({ data }) => <h1>{data.slug}</h1> })
|
|
1828
|
-
*/
|
|
1829
|
-
function defineServerFn(fn) {
|
|
1830
|
-
function serverFn(c) {
|
|
1831
|
-
return fn(c);
|
|
1832
|
-
}
|
|
1833
|
-
Object.defineProperty(serverFn, "kind", {
|
|
1834
|
-
value: SERVER_FN_KIND,
|
|
1835
|
-
enumerable: true
|
|
1836
|
-
});
|
|
1837
|
-
return serverFn;
|
|
1838
|
-
}
|
|
1839
|
-
//#endregion
|
|
1840
|
-
//#region \0virtual:honoto/manifest
|
|
1841
|
-
var manifest = {
|
|
1842
|
-
defaults: {
|
|
1843
|
-
"clientRouting": true,
|
|
1844
|
-
"prerender": "full"
|
|
1845
|
-
},
|
|
1846
|
-
pages: [
|
|
1847
|
-
{
|
|
1848
|
-
id: "/counter",
|
|
1849
|
-
path: "/counter",
|
|
1850
|
-
pattern: "/counter",
|
|
1851
|
-
isClientPage: true,
|
|
1852
|
-
isStatic: true,
|
|
1853
|
-
isCatchAll: false,
|
|
1854
|
-
paramNames: [],
|
|
1855
|
-
config: {
|
|
1856
|
-
"clientRouting": true,
|
|
1857
|
-
"prerender": "full"
|
|
1858
|
-
},
|
|
1859
|
-
loadPage: () => import("./counter-DfIbc9Sp.js"),
|
|
1860
|
-
loadClientPage: () => import("./counter-DfIbc9Sp.js"),
|
|
1861
|
-
loadLayouts: [() => import("./layout-DYvLwr2u.js")]
|
|
1862
|
-
},
|
|
1863
|
-
{
|
|
1864
|
-
id: "/about",
|
|
1865
|
-
path: "/about",
|
|
1866
|
-
pattern: "/about",
|
|
1867
|
-
isClientPage: false,
|
|
1868
|
-
isStatic: true,
|
|
1869
|
-
isCatchAll: false,
|
|
1870
|
-
paramNames: [],
|
|
1871
|
-
config: {
|
|
1872
|
-
"clientRouting": true,
|
|
1873
|
-
"prerender": "full"
|
|
1874
|
-
},
|
|
1875
|
-
loadPage: () => import("./about-CTDjNhkO.js"),
|
|
1876
|
-
loadLayouts: [() => import("./layout-DYvLwr2u.js")]
|
|
1877
|
-
},
|
|
1878
|
-
{
|
|
1879
|
-
id: "/admin",
|
|
1880
|
-
path: "/admin",
|
|
1881
|
-
pattern: "/admin",
|
|
1882
|
-
isClientPage: true,
|
|
1883
|
-
isStatic: true,
|
|
1884
|
-
isCatchAll: false,
|
|
1885
|
-
paramNames: [],
|
|
1886
|
-
config: {
|
|
1887
|
-
"clientRouting": true,
|
|
1888
|
-
"prerender": "full"
|
|
1889
|
-
},
|
|
1890
|
-
loadPage: () => import("./admin-DvS-UGJx.js"),
|
|
1891
|
-
loadClientPage: () => import("./admin-DvS-UGJx.js"),
|
|
1892
|
-
loadLayouts: [() => import("./layout-DYvLwr2u.js")]
|
|
1893
|
-
},
|
|
1894
|
-
{
|
|
1895
|
-
id: "/jobs",
|
|
1896
|
-
path: "/jobs",
|
|
1897
|
-
pattern: "/jobs",
|
|
1898
|
-
isClientPage: false,
|
|
1899
|
-
isStatic: true,
|
|
1900
|
-
isCatchAll: false,
|
|
1901
|
-
paramNames: [],
|
|
1902
|
-
config: {
|
|
1903
|
-
"clientRouting": true,
|
|
1904
|
-
"prerender": "full"
|
|
1905
|
-
},
|
|
1906
|
-
loadPage: () => import("./jobs-D9hh-UO9.js"),
|
|
1907
|
-
loadLayouts: [() => import("./layout-DYvLwr2u.js")]
|
|
1908
|
-
},
|
|
1909
|
-
{
|
|
1910
|
-
id: "/",
|
|
1911
|
-
path: "/",
|
|
1912
|
-
pattern: "/",
|
|
1913
|
-
isClientPage: false,
|
|
1914
|
-
isStatic: true,
|
|
1915
|
-
isCatchAll: false,
|
|
1916
|
-
paramNames: [],
|
|
1917
|
-
config: {
|
|
1918
|
-
"clientRouting": true,
|
|
1919
|
-
"prerender": "full"
|
|
1920
|
-
},
|
|
1921
|
-
loadPage: () => import("./pages-DB6jeyrt.js"),
|
|
1922
|
-
loadLayouts: [() => import("./layout-DYvLwr2u.js")]
|
|
1923
|
-
},
|
|
1924
|
-
{
|
|
1925
|
-
id: "/blog/:slug",
|
|
1926
|
-
path: "/blog/:slug",
|
|
1927
|
-
pattern: "/blog/:slug",
|
|
1928
|
-
isClientPage: true,
|
|
1929
|
-
isStatic: false,
|
|
1930
|
-
isCatchAll: false,
|
|
1931
|
-
paramNames: ["slug"],
|
|
1932
|
-
config: {
|
|
1933
|
-
"clientRouting": true,
|
|
1934
|
-
"prerender": "full"
|
|
1935
|
-
},
|
|
1936
|
-
loadPage: () => import("./_slug_-CY3-kffX.js"),
|
|
1937
|
-
loadClientPage: () => import("./_slug_-CY3-kffX.js"),
|
|
1938
|
-
loadLayouts: [() => import("./layout-DYvLwr2u.js")]
|
|
1939
|
-
}
|
|
1940
|
-
]
|
|
1941
|
-
};
|
|
1942
|
-
//#endregion
|
|
1943
|
-
//#region \0virtual:honoto/assets
|
|
1944
|
-
var clientScriptSrc = "/assets/honoto-client.js";
|
|
1945
|
-
//#endregion
|
|
1946
|
-
//#region ../../dist/honoto.mjs
|
|
1947
|
-
function DefaultLayout(props) {
|
|
1948
|
-
return jsxDEV("html", { children: [jsxDEV("head", { children: [jsxDEV("meta", { charset: "utf-8" }), jsxDEV("meta", {
|
|
1949
|
-
name: "viewport",
|
|
1950
|
-
content: "width=device-width, initial-scale=1"
|
|
1951
|
-
})] }), jsxDEV("body", { children: props.children })] });
|
|
1952
|
-
}
|
|
1953
|
-
function isHonoApp(value) {
|
|
1954
|
-
return value instanceof Hono;
|
|
1955
|
-
}
|
|
1956
|
-
function payloadScript(payload) {
|
|
1957
|
-
const json = JSON.stringify(payload).replaceAll("<", "\\u003c");
|
|
1958
|
-
return `<script id="${PAYLOAD_SCRIPT_ID}" type="application/json">${json}<\/script>`;
|
|
1959
|
-
}
|
|
1960
|
-
function injectDocument(html, payload, isDev, scriptSrc) {
|
|
1961
|
-
const vite = isDev ? `<script type="module" src="/@vite/client"><\/script>` : "";
|
|
1962
|
-
const client = `<script type="module" src="${scriptSrc}"><\/script>`;
|
|
1963
|
-
const inject = `${vite}${payloadScript(payload)}${client}`;
|
|
1964
|
-
if (html.includes("</body>")) return html.replace("</body>", `${inject}</body>`);
|
|
1965
|
-
if (html.includes("</html>")) return html.replace("</html>", `${inject}</html>`);
|
|
1966
|
-
return `<!DOCTYPE html>${html}${inject}`;
|
|
1967
|
-
}
|
|
1968
|
-
async function ensureJsxRenderer(c) {
|
|
1969
|
-
await jsxRenderer(void 0, { docType: true })(c, async () => {});
|
|
1970
|
-
}
|
|
1971
|
-
function needsPageSlot(page, config, mode) {
|
|
1972
|
-
if (mode === "shell" || mode === "content") return true;
|
|
1973
|
-
if (page.isClientPage) return true;
|
|
1974
|
-
if (config.clientRouting === true) return true;
|
|
1975
|
-
if (config.prerender === "partial") return true;
|
|
1976
|
-
return false;
|
|
1977
|
-
}
|
|
1978
|
-
function emptySlot() {
|
|
1979
|
-
return jsxDEV("div", { id: PAGE_SLOT_ID });
|
|
1980
|
-
}
|
|
1981
|
-
function wrapSlot(children) {
|
|
1982
|
-
return jsxDEV("div", {
|
|
1983
|
-
id: PAGE_SLOT_ID,
|
|
1984
|
-
children
|
|
1985
|
-
});
|
|
1986
|
-
}
|
|
1987
|
-
function buildPayload(options) {
|
|
1988
|
-
const { page, params, data, config, mode, requestPath, title } = options;
|
|
1989
|
-
return {
|
|
1990
|
-
path: requestPath ?? (page.path === "" ? "/" : page.path),
|
|
1991
|
-
params,
|
|
1992
|
-
data,
|
|
1993
|
-
clientRouting: config.clientRouting === true,
|
|
1994
|
-
clientPage: page.isClientPage ? page.path : null,
|
|
1995
|
-
partial: mode === "shell",
|
|
1996
|
-
title
|
|
1997
|
-
};
|
|
1998
|
-
}
|
|
1999
|
-
async function renderPageHtml(options) {
|
|
2000
|
-
const { c, page, pageNode = null, data, params, config, isDev, clientScriptSrc, mode = "full", title } = options;
|
|
2001
|
-
const payload = buildPayload({
|
|
2002
|
-
page,
|
|
2003
|
-
params,
|
|
2004
|
-
data,
|
|
2005
|
-
config,
|
|
2006
|
-
mode,
|
|
2007
|
-
requestPath: c.req.path,
|
|
2008
|
-
title
|
|
2009
|
-
});
|
|
2010
|
-
if (mode === "content") {
|
|
2011
|
-
if (pageNode == null) throw new Error("content render requires pageNode");
|
|
2012
|
-
const node = wrapSlot(pageNode);
|
|
2013
|
-
await ensureJsxRenderer(c);
|
|
2014
|
-
let html = await (await c.render(node)).text();
|
|
2015
|
-
html = html.replace(/^<!DOCTYPE html>/i, "");
|
|
2016
|
-
html = `${html}${payloadScript(payload)}`;
|
|
2017
|
-
return {
|
|
2018
|
-
html,
|
|
2019
|
-
payload
|
|
2020
|
-
};
|
|
2021
|
-
}
|
|
2022
|
-
let node = mode === "shell" ? emptySlot() : pageNode;
|
|
2023
|
-
if (mode !== "shell" && needsPageSlot(page, config, mode)) node = wrapSlot(node);
|
|
2024
|
-
const layouts = await Promise.all(page.loadLayouts.map((load) => load()));
|
|
2025
|
-
for (const layout of [...layouts].reverse()) {
|
|
2026
|
-
const Layout = layout.default;
|
|
2027
|
-
node = jsxDEV(Layout, {
|
|
2028
|
-
data,
|
|
2029
|
-
params,
|
|
2030
|
-
children: node
|
|
2031
|
-
});
|
|
2032
|
-
}
|
|
2033
|
-
if (layouts.length === 0) node = jsxDEV(DefaultLayout, { children: node });
|
|
2034
|
-
await ensureJsxRenderer(c);
|
|
2035
|
-
let html = await (await c.render(node)).text();
|
|
2036
|
-
html = injectDocument(html, payload, isDev, clientScriptSrc);
|
|
2037
|
-
if (!html.startsWith("<!")) html = `<!DOCTYPE html>${html}`;
|
|
2038
|
-
return {
|
|
2039
|
-
html,
|
|
2040
|
-
payload
|
|
2041
|
-
};
|
|
2042
|
-
}
|
|
2043
|
-
function requestParams(c) {
|
|
2044
|
-
try {
|
|
2045
|
-
return c.req.param();
|
|
2046
|
-
} catch {
|
|
2047
|
-
return {};
|
|
2048
|
-
}
|
|
2049
|
-
}
|
|
2050
|
-
function pageFromModule(pageMod, data, params) {
|
|
2051
|
-
const Page = resolvePageRender(pageMod.default);
|
|
2052
|
-
if (Page) return jsxDEV(Page, {
|
|
2053
|
-
data,
|
|
2054
|
-
params
|
|
2055
|
-
});
|
|
2056
|
-
return pageMod.default;
|
|
2057
|
-
}
|
|
2058
|
-
function resolveRenderMode(c) {
|
|
2059
|
-
if (c.req.header("X-Honoto-Shell")) return "shell";
|
|
2060
|
-
if (c.req.header("X-Honoto-Nav")) return "content";
|
|
2061
|
-
return "full";
|
|
2062
|
-
}
|
|
2063
|
-
async function handlePage(c, page) {
|
|
2064
|
-
const pageMod = await page.loadPage();
|
|
2065
|
-
if (isHonoApp(pageMod.default)) return pageMod.default.fetch(c.req.raw, c.env, c.executionCtx);
|
|
2066
|
-
const method = c.req.method;
|
|
2067
|
-
const named = pageMod[method];
|
|
2068
|
-
const hasPage = Boolean(resolvePageRender(pageMod.default));
|
|
2069
|
-
const mode = resolveRenderMode(c);
|
|
2070
|
-
if (typeof named === "function" && (method !== "GET" || !hasPage)) {
|
|
2071
|
-
const result = await named(c);
|
|
2072
|
-
if (result instanceof Response) return result;
|
|
2073
|
-
if (method === "GET" || method === "HEAD") {
|
|
2074
|
-
const config = loadMergedConfig(page, pageMod);
|
|
2075
|
-
const params = requestParams(c);
|
|
2076
|
-
const data = mode === "shell" ? void 0 : await loadMergedData(page, c, pageMod);
|
|
2077
|
-
const { html } = await renderPageHtml({
|
|
2078
|
-
c,
|
|
2079
|
-
page,
|
|
2080
|
-
pageMod,
|
|
2081
|
-
pageNode: mode === "shell" ? null : result,
|
|
2082
|
-
data,
|
|
2083
|
-
params,
|
|
2084
|
-
config,
|
|
2085
|
-
isDev: false,
|
|
2086
|
-
clientScriptSrc,
|
|
2087
|
-
mode
|
|
2088
|
-
});
|
|
2089
|
-
return c.html(html);
|
|
2090
|
-
}
|
|
2091
|
-
return c.json(result);
|
|
2092
|
-
}
|
|
2093
|
-
if (method !== "GET" && method !== "HEAD") return c.text("Method Not Allowed", 405);
|
|
2094
|
-
const config = loadMergedConfig(page, pageMod);
|
|
2095
|
-
const params = requestParams(c);
|
|
2096
|
-
const data = mode === "shell" ? void 0 : await loadMergedData(page, c, pageMod);
|
|
2097
|
-
const { html } = await renderPageHtml({
|
|
2098
|
-
c,
|
|
2099
|
-
page,
|
|
2100
|
-
pageMod,
|
|
2101
|
-
pageNode: mode === "shell" ? null : pageFromModule(pageMod, data, params),
|
|
2102
|
-
data,
|
|
2103
|
-
params,
|
|
2104
|
-
config,
|
|
2105
|
-
isDev: false,
|
|
2106
|
-
clientScriptSrc,
|
|
2107
|
-
mode
|
|
2108
|
-
});
|
|
2109
|
-
return c.html(html);
|
|
2110
|
-
}
|
|
2111
|
-
/**
|
|
2112
|
-
* Mount filesystem pages from the Vite-generated manifest onto a user-owned Hono app.
|
|
2113
|
-
* Extra API routes should be registered on `app` before calling this.
|
|
2114
|
-
*/
|
|
2115
|
-
function mountHonoto(app, options = {}) {
|
|
2116
|
-
const manifest$1 = options.manifest ?? manifest;
|
|
2117
|
-
for (const page of manifest$1.pages) app.get(page.pattern, (c) => handlePage(c, page));
|
|
2118
|
-
return app;
|
|
2119
|
-
}
|
|
2120
|
-
/**
|
|
2121
|
-
* Create a new Honoto app. Returns a Hono app with the Honoto pages mounted.
|
|
2122
|
-
* @param options - The options for the Honoto app.
|
|
2123
|
-
* @returns A Hono app with the Honoto pages mounted.
|
|
2124
|
-
*/
|
|
2125
|
-
function createHonoto(options = {}) {
|
|
2126
|
-
return mountHonoto(new Hono(), options);
|
|
2127
|
-
}
|
|
2128
|
-
//#endregion
|
|
2129
|
-
export { Hono as a, defineServerPage as i, defineServerFn as n, definePage as r, createHonoto as t };
|