@prisma-next/sql-runtime 0.1.0-dev.14 → 0.1.0-dev.16
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/accelerate-EEKAFGN3-SHR4XFVV.js +137863 -0
- package/dist/accelerate-EEKAFGN3-SHR4XFVV.js.map +1 -0
- package/dist/amcheck-24VY6X5V.js +13 -0
- package/dist/amcheck-24VY6X5V.js.map +1 -0
- package/dist/bloom-VS74NLHT.js +13 -0
- package/dist/bloom-VS74NLHT.js.map +1 -0
- package/dist/btree_gin-WBC4EAAI.js +13 -0
- package/dist/btree_gin-WBC4EAAI.js.map +1 -0
- package/dist/btree_gist-UNC6QD3M.js +13 -0
- package/dist/btree_gist-UNC6QD3M.js.map +1 -0
- package/dist/chunk-3KTOEDFX.js +49 -0
- package/dist/chunk-3KTOEDFX.js.map +1 -0
- package/dist/chunk-47DZBRQC.js +1280 -0
- package/dist/chunk-47DZBRQC.js.map +1 -0
- package/dist/chunk-52N6AFZM.js +133 -0
- package/dist/chunk-52N6AFZM.js.map +1 -0
- package/dist/chunk-7D4SUZUM.js +38 -0
- package/dist/chunk-7D4SUZUM.js.map +1 -0
- package/dist/chunk-7UNP42HJ.js +455 -0
- package/dist/chunk-7UNP42HJ.js.map +1 -0
- package/dist/chunk-ECWIHLAT.js +37 -0
- package/dist/chunk-ECWIHLAT.js.map +1 -0
- package/dist/chunk-EI626SDC.js +105 -0
- package/dist/chunk-EI626SDC.js.map +1 -0
- package/dist/chunk-UKKOYUGL.js +578 -0
- package/dist/chunk-UKKOYUGL.js.map +1 -0
- package/dist/chunk-XPLNMXQV.js +1537 -0
- package/dist/chunk-XPLNMXQV.js.map +1 -0
- package/dist/citext-T7MXGUY7.js +13 -0
- package/dist/citext-T7MXGUY7.js.map +1 -0
- package/dist/client-5FENX6AW.js +299 -0
- package/dist/client-5FENX6AW.js.map +1 -0
- package/dist/cube-TFDQBZCI.js +13 -0
- package/dist/cube-TFDQBZCI.js.map +1 -0
- package/dist/dict_int-AEUOPGWP.js +13 -0
- package/dist/dict_int-AEUOPGWP.js.map +1 -0
- package/dist/dict_xsyn-DAAYX3FL.js +13 -0
- package/dist/dict_xsyn-DAAYX3FL.js.map +1 -0
- package/dist/dist-LBVX6BJW.js +189 -0
- package/dist/dist-LBVX6BJW.js.map +1 -0
- package/dist/dist-LCVVJCGI.js +570 -0
- package/dist/dist-LCVVJCGI.js.map +1 -0
- package/dist/dist-WLKUVDN2.js +5127 -0
- package/dist/dist-WLKUVDN2.js.map +1 -0
- package/dist/earthdistance-KIGTF4LE.js +13 -0
- package/dist/earthdistance-KIGTF4LE.js.map +1 -0
- package/dist/file_fdw-5N55UP6I.js +13 -0
- package/dist/file_fdw-5N55UP6I.js.map +1 -0
- package/dist/fuzzystrmatch-KN3YWBFP.js +13 -0
- package/dist/fuzzystrmatch-KN3YWBFP.js.map +1 -0
- package/dist/hstore-YX726NKN.js +13 -0
- package/dist/hstore-YX726NKN.js.map +1 -0
- package/dist/http-exception-FZY2H4OF.js +8 -0
- package/dist/http-exception-FZY2H4OF.js.map +1 -0
- package/dist/index.d.ts +7 -59
- package/dist/index.js +15 -439
- package/dist/index.js.map +1 -1
- package/dist/intarray-NKVXNO2D.js +13 -0
- package/dist/intarray-NKVXNO2D.js.map +1 -0
- package/dist/isn-FTEMJGEV.js +13 -0
- package/dist/isn-FTEMJGEV.js.map +1 -0
- package/dist/lo-DB7L4NGI.js +13 -0
- package/dist/lo-DB7L4NGI.js.map +1 -0
- package/dist/logger-WQ7SHNDD.js +68 -0
- package/dist/logger-WQ7SHNDD.js.map +1 -0
- package/dist/ltree-Z32TZT6W.js +13 -0
- package/dist/ltree-Z32TZT6W.js.map +1 -0
- package/dist/nodefs-NM46ACH7.js +31 -0
- package/dist/nodefs-NM46ACH7.js.map +1 -0
- package/dist/opfs-ahp-NJO33LVZ.js +332 -0
- package/dist/opfs-ahp-NJO33LVZ.js.map +1 -0
- package/dist/pageinspect-YP3IZR4X.js +13 -0
- package/dist/pageinspect-YP3IZR4X.js.map +1 -0
- package/dist/pg_buffercache-7TD5J2FB.js +13 -0
- package/dist/pg_buffercache-7TD5J2FB.js.map +1 -0
- package/dist/pg_dump-SG4KYBUB.js +2492 -0
- package/dist/pg_dump-SG4KYBUB.js.map +1 -0
- package/dist/pg_freespacemap-DZDNCPZK.js +13 -0
- package/dist/pg_freespacemap-DZDNCPZK.js.map +1 -0
- package/dist/pg_surgery-J2MUEWEP.js +13 -0
- package/dist/pg_surgery-J2MUEWEP.js.map +1 -0
- package/dist/pg_trgm-7VNQOYS6.js +13 -0
- package/dist/pg_trgm-7VNQOYS6.js.map +1 -0
- package/dist/pg_visibility-TTSIPHFL.js +13 -0
- package/dist/pg_visibility-TTSIPHFL.js.map +1 -0
- package/dist/pg_walinspect-KPFHSHRJ.js +13 -0
- package/dist/pg_walinspect-KPFHSHRJ.js.map +1 -0
- package/dist/proxy-signals-GUDAMDHV.js +39 -0
- package/dist/proxy-signals-GUDAMDHV.js.map +1 -0
- package/dist/seg-IYVDLE4O.js +13 -0
- package/dist/seg-IYVDLE4O.js.map +1 -0
- package/dist/sql-runtime-qPimiOqJ.d.ts +63 -0
- package/dist/tablefunc-EF4RCS7S.js +13 -0
- package/dist/tablefunc-EF4RCS7S.js.map +1 -0
- package/dist/tcn-3VT5BQYW.js +13 -0
- package/dist/tcn-3VT5BQYW.js.map +1 -0
- package/dist/test/utils.d.ts +60 -0
- package/dist/test/utils.js +24604 -0
- package/dist/test/utils.js.map +1 -0
- package/dist/tiny-CW6F4GX6.js +10 -0
- package/dist/tiny-CW6F4GX6.js.map +1 -0
- package/dist/tsm_system_rows-ES7KNUQH.js +13 -0
- package/dist/tsm_system_rows-ES7KNUQH.js.map +1 -0
- package/dist/tsm_system_time-76WEIMBG.js +13 -0
- package/dist/tsm_system_time-76WEIMBG.js.map +1 -0
- package/dist/unaccent-7RYF3R64.js +13 -0
- package/dist/unaccent-7RYF3R64.js.map +1 -0
- package/dist/utility-Q5A254LJ-J4HTKZPT.js +347 -0
- package/dist/utility-Q5A254LJ-J4HTKZPT.js.map +1 -0
- package/dist/uuid_ossp-4ETE4FPE.js +13 -0
- package/dist/uuid_ossp-4ETE4FPE.js.map +1 -0
- package/dist/vector-74GPNV7V.js +13 -0
- package/dist/vector-74GPNV7V.js.map +1 -0
- package/package.json +9 -9
|
@@ -0,0 +1,1280 @@
|
|
|
1
|
+
import {
|
|
2
|
+
decodeURIComponent_,
|
|
3
|
+
getPath,
|
|
4
|
+
getPathNoStrict,
|
|
5
|
+
getQueryParam,
|
|
6
|
+
getQueryParams,
|
|
7
|
+
mergePath,
|
|
8
|
+
tryDecode
|
|
9
|
+
} from "./chunk-52N6AFZM.js";
|
|
10
|
+
|
|
11
|
+
// ../../../node_modules/.pnpm/hono@4.11.1/node_modules/hono/dist/compose.js
|
|
12
|
+
var compose = (middleware, onError, onNotFound) => {
|
|
13
|
+
return (context, next) => {
|
|
14
|
+
let index = -1;
|
|
15
|
+
return dispatch(0);
|
|
16
|
+
async function dispatch(i) {
|
|
17
|
+
if (i <= index) {
|
|
18
|
+
throw new Error("next() called multiple times");
|
|
19
|
+
}
|
|
20
|
+
index = i;
|
|
21
|
+
let res;
|
|
22
|
+
let isError = false;
|
|
23
|
+
let handler;
|
|
24
|
+
if (middleware[i]) {
|
|
25
|
+
handler = middleware[i][0][0];
|
|
26
|
+
context.req.routeIndex = i;
|
|
27
|
+
} else {
|
|
28
|
+
handler = i === middleware.length && next || void 0;
|
|
29
|
+
}
|
|
30
|
+
if (handler) {
|
|
31
|
+
try {
|
|
32
|
+
res = await handler(context, () => dispatch(i + 1));
|
|
33
|
+
} catch (err) {
|
|
34
|
+
if (err instanceof Error && onError) {
|
|
35
|
+
context.error = err;
|
|
36
|
+
res = await onError(err, context);
|
|
37
|
+
isError = true;
|
|
38
|
+
} else {
|
|
39
|
+
throw err;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
} else {
|
|
43
|
+
if (context.finalized === false && onNotFound) {
|
|
44
|
+
res = await onNotFound(context);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (res && (context.finalized === false || isError)) {
|
|
48
|
+
context.res = res;
|
|
49
|
+
}
|
|
50
|
+
return context;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// ../../../node_modules/.pnpm/hono@4.11.1/node_modules/hono/dist/request/constants.js
|
|
56
|
+
var GET_MATCH_RESULT = /* @__PURE__ */ Symbol();
|
|
57
|
+
|
|
58
|
+
// ../../../node_modules/.pnpm/hono@4.11.1/node_modules/hono/dist/utils/body.js
|
|
59
|
+
var parseBody = async (request, options = /* @__PURE__ */ Object.create(null)) => {
|
|
60
|
+
const { all = false, dot = false } = options;
|
|
61
|
+
const headers = request instanceof HonoRequest ? request.raw.headers : request.headers;
|
|
62
|
+
const contentType = headers.get("Content-Type");
|
|
63
|
+
if (contentType?.startsWith("multipart/form-data") || contentType?.startsWith("application/x-www-form-urlencoded")) {
|
|
64
|
+
return parseFormData(request, { all, dot });
|
|
65
|
+
}
|
|
66
|
+
return {};
|
|
67
|
+
};
|
|
68
|
+
async function parseFormData(request, options) {
|
|
69
|
+
const formData = await request.formData();
|
|
70
|
+
if (formData) {
|
|
71
|
+
return convertFormDataToBodyData(formData, options);
|
|
72
|
+
}
|
|
73
|
+
return {};
|
|
74
|
+
}
|
|
75
|
+
function convertFormDataToBodyData(formData, options) {
|
|
76
|
+
const form = /* @__PURE__ */ Object.create(null);
|
|
77
|
+
formData.forEach((value, key) => {
|
|
78
|
+
const shouldParseAllValues = options.all || key.endsWith("[]");
|
|
79
|
+
if (!shouldParseAllValues) {
|
|
80
|
+
form[key] = value;
|
|
81
|
+
} else {
|
|
82
|
+
handleParsingAllValues(form, key, value);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
if (options.dot) {
|
|
86
|
+
Object.entries(form).forEach(([key, value]) => {
|
|
87
|
+
const shouldParseDotValues = key.includes(".");
|
|
88
|
+
if (shouldParseDotValues) {
|
|
89
|
+
handleParsingNestedValues(form, key, value);
|
|
90
|
+
delete form[key];
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
return form;
|
|
95
|
+
}
|
|
96
|
+
var handleParsingAllValues = (form, key, value) => {
|
|
97
|
+
if (form[key] !== void 0) {
|
|
98
|
+
if (Array.isArray(form[key])) {
|
|
99
|
+
;
|
|
100
|
+
form[key].push(value);
|
|
101
|
+
} else {
|
|
102
|
+
form[key] = [form[key], value];
|
|
103
|
+
}
|
|
104
|
+
} else {
|
|
105
|
+
if (!key.endsWith("[]")) {
|
|
106
|
+
form[key] = value;
|
|
107
|
+
} else {
|
|
108
|
+
form[key] = [value];
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
var handleParsingNestedValues = (form, key, value) => {
|
|
113
|
+
let nestedForm = form;
|
|
114
|
+
const keys = key.split(".");
|
|
115
|
+
keys.forEach((key2, index) => {
|
|
116
|
+
if (index === keys.length - 1) {
|
|
117
|
+
nestedForm[key2] = value;
|
|
118
|
+
} else {
|
|
119
|
+
if (!nestedForm[key2] || typeof nestedForm[key2] !== "object" || Array.isArray(nestedForm[key2]) || nestedForm[key2] instanceof File) {
|
|
120
|
+
nestedForm[key2] = /* @__PURE__ */ Object.create(null);
|
|
121
|
+
}
|
|
122
|
+
nestedForm = nestedForm[key2];
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
// ../../../node_modules/.pnpm/hono@4.11.1/node_modules/hono/dist/request.js
|
|
128
|
+
var tryDecodeURIComponent = (str) => tryDecode(str, decodeURIComponent_);
|
|
129
|
+
var HonoRequest = class {
|
|
130
|
+
/**
|
|
131
|
+
* `.raw` can get the raw Request object.
|
|
132
|
+
*
|
|
133
|
+
* @see {@link https://hono.dev/docs/api/request#raw}
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```ts
|
|
137
|
+
* // For Cloudflare Workers
|
|
138
|
+
* app.post('/', async (c) => {
|
|
139
|
+
* const metadata = c.req.raw.cf?.hostMetadata?
|
|
140
|
+
* ...
|
|
141
|
+
* })
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
raw;
|
|
145
|
+
#validatedData;
|
|
146
|
+
// Short name of validatedData
|
|
147
|
+
#matchResult;
|
|
148
|
+
routeIndex = 0;
|
|
149
|
+
/**
|
|
150
|
+
* `.path` can get the pathname of the request.
|
|
151
|
+
*
|
|
152
|
+
* @see {@link https://hono.dev/docs/api/request#path}
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* ```ts
|
|
156
|
+
* app.get('/about/me', (c) => {
|
|
157
|
+
* const pathname = c.req.path // `/about/me`
|
|
158
|
+
* })
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
path;
|
|
162
|
+
bodyCache = {};
|
|
163
|
+
constructor(request, path = "/", matchResult = [[]]) {
|
|
164
|
+
this.raw = request;
|
|
165
|
+
this.path = path;
|
|
166
|
+
this.#matchResult = matchResult;
|
|
167
|
+
this.#validatedData = {};
|
|
168
|
+
}
|
|
169
|
+
param(key) {
|
|
170
|
+
return key ? this.#getDecodedParam(key) : this.#getAllDecodedParams();
|
|
171
|
+
}
|
|
172
|
+
#getDecodedParam(key) {
|
|
173
|
+
const paramKey = this.#matchResult[0][this.routeIndex][1][key];
|
|
174
|
+
const param = this.#getParamValue(paramKey);
|
|
175
|
+
return param && /\%/.test(param) ? tryDecodeURIComponent(param) : param;
|
|
176
|
+
}
|
|
177
|
+
#getAllDecodedParams() {
|
|
178
|
+
const decoded = {};
|
|
179
|
+
const keys = Object.keys(this.#matchResult[0][this.routeIndex][1]);
|
|
180
|
+
for (const key of keys) {
|
|
181
|
+
const value = this.#getParamValue(this.#matchResult[0][this.routeIndex][1][key]);
|
|
182
|
+
if (value !== void 0) {
|
|
183
|
+
decoded[key] = /\%/.test(value) ? tryDecodeURIComponent(value) : value;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return decoded;
|
|
187
|
+
}
|
|
188
|
+
#getParamValue(paramKey) {
|
|
189
|
+
return this.#matchResult[1] ? this.#matchResult[1][paramKey] : paramKey;
|
|
190
|
+
}
|
|
191
|
+
query(key) {
|
|
192
|
+
return getQueryParam(this.url, key);
|
|
193
|
+
}
|
|
194
|
+
queries(key) {
|
|
195
|
+
return getQueryParams(this.url, key);
|
|
196
|
+
}
|
|
197
|
+
header(name) {
|
|
198
|
+
if (name) {
|
|
199
|
+
return this.raw.headers.get(name) ?? void 0;
|
|
200
|
+
}
|
|
201
|
+
const headerData = {};
|
|
202
|
+
this.raw.headers.forEach((value, key) => {
|
|
203
|
+
headerData[key] = value;
|
|
204
|
+
});
|
|
205
|
+
return headerData;
|
|
206
|
+
}
|
|
207
|
+
async parseBody(options) {
|
|
208
|
+
return this.bodyCache.parsedBody ??= await parseBody(this, options);
|
|
209
|
+
}
|
|
210
|
+
#cachedBody = (key) => {
|
|
211
|
+
const { bodyCache, raw: raw2 } = this;
|
|
212
|
+
const cachedBody = bodyCache[key];
|
|
213
|
+
if (cachedBody) {
|
|
214
|
+
return cachedBody;
|
|
215
|
+
}
|
|
216
|
+
const anyCachedKey = Object.keys(bodyCache)[0];
|
|
217
|
+
if (anyCachedKey) {
|
|
218
|
+
return bodyCache[anyCachedKey].then((body) => {
|
|
219
|
+
if (anyCachedKey === "json") {
|
|
220
|
+
body = JSON.stringify(body);
|
|
221
|
+
}
|
|
222
|
+
return new Response(body)[key]();
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
return bodyCache[key] = raw2[key]();
|
|
226
|
+
};
|
|
227
|
+
/**
|
|
228
|
+
* `.json()` can parse Request body of type `application/json`
|
|
229
|
+
*
|
|
230
|
+
* @see {@link https://hono.dev/docs/api/request#json}
|
|
231
|
+
*
|
|
232
|
+
* @example
|
|
233
|
+
* ```ts
|
|
234
|
+
* app.post('/entry', async (c) => {
|
|
235
|
+
* const body = await c.req.json()
|
|
236
|
+
* })
|
|
237
|
+
* ```
|
|
238
|
+
*/
|
|
239
|
+
json() {
|
|
240
|
+
return this.#cachedBody("text").then((text) => JSON.parse(text));
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* `.text()` can parse Request body of type `text/plain`
|
|
244
|
+
*
|
|
245
|
+
* @see {@link https://hono.dev/docs/api/request#text}
|
|
246
|
+
*
|
|
247
|
+
* @example
|
|
248
|
+
* ```ts
|
|
249
|
+
* app.post('/entry', async (c) => {
|
|
250
|
+
* const body = await c.req.text()
|
|
251
|
+
* })
|
|
252
|
+
* ```
|
|
253
|
+
*/
|
|
254
|
+
text() {
|
|
255
|
+
return this.#cachedBody("text");
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* `.arrayBuffer()` parse Request body as an `ArrayBuffer`
|
|
259
|
+
*
|
|
260
|
+
* @see {@link https://hono.dev/docs/api/request#arraybuffer}
|
|
261
|
+
*
|
|
262
|
+
* @example
|
|
263
|
+
* ```ts
|
|
264
|
+
* app.post('/entry', async (c) => {
|
|
265
|
+
* const body = await c.req.arrayBuffer()
|
|
266
|
+
* })
|
|
267
|
+
* ```
|
|
268
|
+
*/
|
|
269
|
+
arrayBuffer() {
|
|
270
|
+
return this.#cachedBody("arrayBuffer");
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Parses the request body as a `Blob`.
|
|
274
|
+
* @example
|
|
275
|
+
* ```ts
|
|
276
|
+
* app.post('/entry', async (c) => {
|
|
277
|
+
* const body = await c.req.blob();
|
|
278
|
+
* });
|
|
279
|
+
* ```
|
|
280
|
+
* @see https://hono.dev/docs/api/request#blob
|
|
281
|
+
*/
|
|
282
|
+
blob() {
|
|
283
|
+
return this.#cachedBody("blob");
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Parses the request body as `FormData`.
|
|
287
|
+
* @example
|
|
288
|
+
* ```ts
|
|
289
|
+
* app.post('/entry', async (c) => {
|
|
290
|
+
* const body = await c.req.formData();
|
|
291
|
+
* });
|
|
292
|
+
* ```
|
|
293
|
+
* @see https://hono.dev/docs/api/request#formdata
|
|
294
|
+
*/
|
|
295
|
+
formData() {
|
|
296
|
+
return this.#cachedBody("formData");
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Adds validated data to the request.
|
|
300
|
+
*
|
|
301
|
+
* @param target - The target of the validation.
|
|
302
|
+
* @param data - The validated data to add.
|
|
303
|
+
*/
|
|
304
|
+
addValidatedData(target, data) {
|
|
305
|
+
this.#validatedData[target] = data;
|
|
306
|
+
}
|
|
307
|
+
valid(target) {
|
|
308
|
+
return this.#validatedData[target];
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* `.url()` can get the request url strings.
|
|
312
|
+
*
|
|
313
|
+
* @see {@link https://hono.dev/docs/api/request#url}
|
|
314
|
+
*
|
|
315
|
+
* @example
|
|
316
|
+
* ```ts
|
|
317
|
+
* app.get('/about/me', (c) => {
|
|
318
|
+
* const url = c.req.url // `http://localhost:8787/about/me`
|
|
319
|
+
* ...
|
|
320
|
+
* })
|
|
321
|
+
* ```
|
|
322
|
+
*/
|
|
323
|
+
get url() {
|
|
324
|
+
return this.raw.url;
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* `.method()` can get the method name of the request.
|
|
328
|
+
*
|
|
329
|
+
* @see {@link https://hono.dev/docs/api/request#method}
|
|
330
|
+
*
|
|
331
|
+
* @example
|
|
332
|
+
* ```ts
|
|
333
|
+
* app.get('/about/me', (c) => {
|
|
334
|
+
* const method = c.req.method // `GET`
|
|
335
|
+
* })
|
|
336
|
+
* ```
|
|
337
|
+
*/
|
|
338
|
+
get method() {
|
|
339
|
+
return this.raw.method;
|
|
340
|
+
}
|
|
341
|
+
get [GET_MATCH_RESULT]() {
|
|
342
|
+
return this.#matchResult;
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* `.matchedRoutes()` can return a matched route in the handler
|
|
346
|
+
*
|
|
347
|
+
* @deprecated
|
|
348
|
+
*
|
|
349
|
+
* Use matchedRoutes helper defined in "hono/route" instead.
|
|
350
|
+
*
|
|
351
|
+
* @see {@link https://hono.dev/docs/api/request#matchedroutes}
|
|
352
|
+
*
|
|
353
|
+
* @example
|
|
354
|
+
* ```ts
|
|
355
|
+
* app.use('*', async function logger(c, next) {
|
|
356
|
+
* await next()
|
|
357
|
+
* c.req.matchedRoutes.forEach(({ handler, method, path }, i) => {
|
|
358
|
+
* const name = handler.name || (handler.length < 2 ? '[handler]' : '[middleware]')
|
|
359
|
+
* console.log(
|
|
360
|
+
* method,
|
|
361
|
+
* ' ',
|
|
362
|
+
* path,
|
|
363
|
+
* ' '.repeat(Math.max(10 - path.length, 0)),
|
|
364
|
+
* name,
|
|
365
|
+
* i === c.req.routeIndex ? '<- respond from here' : ''
|
|
366
|
+
* )
|
|
367
|
+
* })
|
|
368
|
+
* })
|
|
369
|
+
* ```
|
|
370
|
+
*/
|
|
371
|
+
get matchedRoutes() {
|
|
372
|
+
return this.#matchResult[0].map(([[, route]]) => route);
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* `routePath()` can retrieve the path registered within the handler
|
|
376
|
+
*
|
|
377
|
+
* @deprecated
|
|
378
|
+
*
|
|
379
|
+
* Use routePath helper defined in "hono/route" instead.
|
|
380
|
+
*
|
|
381
|
+
* @see {@link https://hono.dev/docs/api/request#routepath}
|
|
382
|
+
*
|
|
383
|
+
* @example
|
|
384
|
+
* ```ts
|
|
385
|
+
* app.get('/posts/:id', (c) => {
|
|
386
|
+
* return c.json({ path: c.req.routePath })
|
|
387
|
+
* })
|
|
388
|
+
* ```
|
|
389
|
+
*/
|
|
390
|
+
get routePath() {
|
|
391
|
+
return this.#matchResult[0].map(([[, route]]) => route)[this.routeIndex].path;
|
|
392
|
+
}
|
|
393
|
+
};
|
|
394
|
+
|
|
395
|
+
// ../../../node_modules/.pnpm/hono@4.11.1/node_modules/hono/dist/utils/html.js
|
|
396
|
+
var HtmlEscapedCallbackPhase = {
|
|
397
|
+
Stringify: 1,
|
|
398
|
+
BeforeStream: 2,
|
|
399
|
+
Stream: 3
|
|
400
|
+
};
|
|
401
|
+
var raw = (value, callbacks) => {
|
|
402
|
+
const escapedString = new String(value);
|
|
403
|
+
escapedString.isEscaped = true;
|
|
404
|
+
escapedString.callbacks = callbacks;
|
|
405
|
+
return escapedString;
|
|
406
|
+
};
|
|
407
|
+
var resolveCallback = async (str, phase, preserveCallbacks, context, buffer) => {
|
|
408
|
+
if (typeof str === "object" && !(str instanceof String)) {
|
|
409
|
+
if (!(str instanceof Promise)) {
|
|
410
|
+
str = str.toString();
|
|
411
|
+
}
|
|
412
|
+
if (str instanceof Promise) {
|
|
413
|
+
str = await str;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
const callbacks = str.callbacks;
|
|
417
|
+
if (!callbacks?.length) {
|
|
418
|
+
return Promise.resolve(str);
|
|
419
|
+
}
|
|
420
|
+
if (buffer) {
|
|
421
|
+
buffer[0] += str;
|
|
422
|
+
} else {
|
|
423
|
+
buffer = [str];
|
|
424
|
+
}
|
|
425
|
+
const resStr = Promise.all(callbacks.map((c) => c({ phase, buffer, context }))).then(
|
|
426
|
+
(res) => Promise.all(
|
|
427
|
+
res.filter(Boolean).map((str2) => resolveCallback(str2, phase, false, context, buffer))
|
|
428
|
+
).then(() => buffer[0])
|
|
429
|
+
);
|
|
430
|
+
if (preserveCallbacks) {
|
|
431
|
+
return raw(await resStr, callbacks);
|
|
432
|
+
} else {
|
|
433
|
+
return resStr;
|
|
434
|
+
}
|
|
435
|
+
};
|
|
436
|
+
|
|
437
|
+
// ../../../node_modules/.pnpm/hono@4.11.1/node_modules/hono/dist/context.js
|
|
438
|
+
var TEXT_PLAIN = "text/plain; charset=UTF-8";
|
|
439
|
+
var setDefaultContentType = (contentType, headers) => {
|
|
440
|
+
return {
|
|
441
|
+
"Content-Type": contentType,
|
|
442
|
+
...headers
|
|
443
|
+
};
|
|
444
|
+
};
|
|
445
|
+
var Context = class {
|
|
446
|
+
#rawRequest;
|
|
447
|
+
#req;
|
|
448
|
+
/**
|
|
449
|
+
* `.env` can get bindings (environment variables, secrets, KV namespaces, D1 database, R2 bucket etc.) in Cloudflare Workers.
|
|
450
|
+
*
|
|
451
|
+
* @see {@link https://hono.dev/docs/api/context#env}
|
|
452
|
+
*
|
|
453
|
+
* @example
|
|
454
|
+
* ```ts
|
|
455
|
+
* // Environment object for Cloudflare Workers
|
|
456
|
+
* app.get('*', async c => {
|
|
457
|
+
* const counter = c.env.COUNTER
|
|
458
|
+
* })
|
|
459
|
+
* ```
|
|
460
|
+
*/
|
|
461
|
+
env = {};
|
|
462
|
+
#var;
|
|
463
|
+
finalized = false;
|
|
464
|
+
/**
|
|
465
|
+
* `.error` can get the error object from the middleware if the Handler throws an error.
|
|
466
|
+
*
|
|
467
|
+
* @see {@link https://hono.dev/docs/api/context#error}
|
|
468
|
+
*
|
|
469
|
+
* @example
|
|
470
|
+
* ```ts
|
|
471
|
+
* app.use('*', async (c, next) => {
|
|
472
|
+
* await next()
|
|
473
|
+
* if (c.error) {
|
|
474
|
+
* // do something...
|
|
475
|
+
* }
|
|
476
|
+
* })
|
|
477
|
+
* ```
|
|
478
|
+
*/
|
|
479
|
+
error;
|
|
480
|
+
#status;
|
|
481
|
+
#executionCtx;
|
|
482
|
+
#res;
|
|
483
|
+
#layout;
|
|
484
|
+
#renderer;
|
|
485
|
+
#notFoundHandler;
|
|
486
|
+
#preparedHeaders;
|
|
487
|
+
#matchResult;
|
|
488
|
+
#path;
|
|
489
|
+
/**
|
|
490
|
+
* Creates an instance of the Context class.
|
|
491
|
+
*
|
|
492
|
+
* @param req - The Request object.
|
|
493
|
+
* @param options - Optional configuration options for the context.
|
|
494
|
+
*/
|
|
495
|
+
constructor(req, options) {
|
|
496
|
+
this.#rawRequest = req;
|
|
497
|
+
if (options) {
|
|
498
|
+
this.#executionCtx = options.executionCtx;
|
|
499
|
+
this.env = options.env;
|
|
500
|
+
this.#notFoundHandler = options.notFoundHandler;
|
|
501
|
+
this.#path = options.path;
|
|
502
|
+
this.#matchResult = options.matchResult;
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
/**
|
|
506
|
+
* `.req` is the instance of {@link HonoRequest}.
|
|
507
|
+
*/
|
|
508
|
+
get req() {
|
|
509
|
+
this.#req ??= new HonoRequest(this.#rawRequest, this.#path, this.#matchResult);
|
|
510
|
+
return this.#req;
|
|
511
|
+
}
|
|
512
|
+
/**
|
|
513
|
+
* @see {@link https://hono.dev/docs/api/context#event}
|
|
514
|
+
* The FetchEvent associated with the current request.
|
|
515
|
+
*
|
|
516
|
+
* @throws Will throw an error if the context does not have a FetchEvent.
|
|
517
|
+
*/
|
|
518
|
+
get event() {
|
|
519
|
+
if (this.#executionCtx && "respondWith" in this.#executionCtx) {
|
|
520
|
+
return this.#executionCtx;
|
|
521
|
+
} else {
|
|
522
|
+
throw Error("This context has no FetchEvent");
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
/**
|
|
526
|
+
* @see {@link https://hono.dev/docs/api/context#executionctx}
|
|
527
|
+
* The ExecutionContext associated with the current request.
|
|
528
|
+
*
|
|
529
|
+
* @throws Will throw an error if the context does not have an ExecutionContext.
|
|
530
|
+
*/
|
|
531
|
+
get executionCtx() {
|
|
532
|
+
if (this.#executionCtx) {
|
|
533
|
+
return this.#executionCtx;
|
|
534
|
+
} else {
|
|
535
|
+
throw Error("This context has no ExecutionContext");
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
/**
|
|
539
|
+
* @see {@link https://hono.dev/docs/api/context#res}
|
|
540
|
+
* The Response object for the current request.
|
|
541
|
+
*/
|
|
542
|
+
get res() {
|
|
543
|
+
return this.#res ||= new Response(null, {
|
|
544
|
+
headers: this.#preparedHeaders ??= new Headers()
|
|
545
|
+
});
|
|
546
|
+
}
|
|
547
|
+
/**
|
|
548
|
+
* Sets the Response object for the current request.
|
|
549
|
+
*
|
|
550
|
+
* @param _res - The Response object to set.
|
|
551
|
+
*/
|
|
552
|
+
set res(_res) {
|
|
553
|
+
if (this.#res && _res) {
|
|
554
|
+
_res = new Response(_res.body, _res);
|
|
555
|
+
for (const [k, v] of this.#res.headers.entries()) {
|
|
556
|
+
if (k === "content-type") {
|
|
557
|
+
continue;
|
|
558
|
+
}
|
|
559
|
+
if (k === "set-cookie") {
|
|
560
|
+
const cookies = this.#res.headers.getSetCookie();
|
|
561
|
+
_res.headers.delete("set-cookie");
|
|
562
|
+
for (const cookie of cookies) {
|
|
563
|
+
_res.headers.append("set-cookie", cookie);
|
|
564
|
+
}
|
|
565
|
+
} else {
|
|
566
|
+
_res.headers.set(k, v);
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
this.#res = _res;
|
|
571
|
+
this.finalized = true;
|
|
572
|
+
}
|
|
573
|
+
/**
|
|
574
|
+
* `.render()` can create a response within a layout.
|
|
575
|
+
*
|
|
576
|
+
* @see {@link https://hono.dev/docs/api/context#render-setrenderer}
|
|
577
|
+
*
|
|
578
|
+
* @example
|
|
579
|
+
* ```ts
|
|
580
|
+
* app.get('/', (c) => {
|
|
581
|
+
* return c.render('Hello!')
|
|
582
|
+
* })
|
|
583
|
+
* ```
|
|
584
|
+
*/
|
|
585
|
+
render = (...args) => {
|
|
586
|
+
this.#renderer ??= (content) => this.html(content);
|
|
587
|
+
return this.#renderer(...args);
|
|
588
|
+
};
|
|
589
|
+
/**
|
|
590
|
+
* Sets the layout for the response.
|
|
591
|
+
*
|
|
592
|
+
* @param layout - The layout to set.
|
|
593
|
+
* @returns The layout function.
|
|
594
|
+
*/
|
|
595
|
+
setLayout = (layout) => this.#layout = layout;
|
|
596
|
+
/**
|
|
597
|
+
* Gets the current layout for the response.
|
|
598
|
+
*
|
|
599
|
+
* @returns The current layout function.
|
|
600
|
+
*/
|
|
601
|
+
getLayout = () => this.#layout;
|
|
602
|
+
/**
|
|
603
|
+
* `.setRenderer()` can set the layout in the custom middleware.
|
|
604
|
+
*
|
|
605
|
+
* @see {@link https://hono.dev/docs/api/context#render-setrenderer}
|
|
606
|
+
*
|
|
607
|
+
* @example
|
|
608
|
+
* ```tsx
|
|
609
|
+
* app.use('*', async (c, next) => {
|
|
610
|
+
* c.setRenderer((content) => {
|
|
611
|
+
* return c.html(
|
|
612
|
+
* <html>
|
|
613
|
+
* <body>
|
|
614
|
+
* <p>{content}</p>
|
|
615
|
+
* </body>
|
|
616
|
+
* </html>
|
|
617
|
+
* )
|
|
618
|
+
* })
|
|
619
|
+
* await next()
|
|
620
|
+
* })
|
|
621
|
+
* ```
|
|
622
|
+
*/
|
|
623
|
+
setRenderer = (renderer) => {
|
|
624
|
+
this.#renderer = renderer;
|
|
625
|
+
};
|
|
626
|
+
/**
|
|
627
|
+
* `.header()` can set headers.
|
|
628
|
+
*
|
|
629
|
+
* @see {@link https://hono.dev/docs/api/context#header}
|
|
630
|
+
*
|
|
631
|
+
* @example
|
|
632
|
+
* ```ts
|
|
633
|
+
* app.get('/welcome', (c) => {
|
|
634
|
+
* // Set headers
|
|
635
|
+
* c.header('X-Message', 'Hello!')
|
|
636
|
+
* c.header('Content-Type', 'text/plain')
|
|
637
|
+
*
|
|
638
|
+
* return c.body('Thank you for coming')
|
|
639
|
+
* })
|
|
640
|
+
* ```
|
|
641
|
+
*/
|
|
642
|
+
header = (name, value, options) => {
|
|
643
|
+
if (this.finalized) {
|
|
644
|
+
this.#res = new Response(this.#res.body, this.#res);
|
|
645
|
+
}
|
|
646
|
+
const headers = this.#res ? this.#res.headers : this.#preparedHeaders ??= new Headers();
|
|
647
|
+
if (value === void 0) {
|
|
648
|
+
headers.delete(name);
|
|
649
|
+
} else if (options?.append) {
|
|
650
|
+
headers.append(name, value);
|
|
651
|
+
} else {
|
|
652
|
+
headers.set(name, value);
|
|
653
|
+
}
|
|
654
|
+
};
|
|
655
|
+
status = (status) => {
|
|
656
|
+
this.#status = status;
|
|
657
|
+
};
|
|
658
|
+
/**
|
|
659
|
+
* `.set()` can set the value specified by the key.
|
|
660
|
+
*
|
|
661
|
+
* @see {@link https://hono.dev/docs/api/context#set-get}
|
|
662
|
+
*
|
|
663
|
+
* @example
|
|
664
|
+
* ```ts
|
|
665
|
+
* app.use('*', async (c, next) => {
|
|
666
|
+
* c.set('message', 'Hono is hot!!')
|
|
667
|
+
* await next()
|
|
668
|
+
* })
|
|
669
|
+
* ```
|
|
670
|
+
*/
|
|
671
|
+
set = (key, value) => {
|
|
672
|
+
this.#var ??= /* @__PURE__ */ new Map();
|
|
673
|
+
this.#var.set(key, value);
|
|
674
|
+
};
|
|
675
|
+
/**
|
|
676
|
+
* `.get()` can use the value specified by the key.
|
|
677
|
+
*
|
|
678
|
+
* @see {@link https://hono.dev/docs/api/context#set-get}
|
|
679
|
+
*
|
|
680
|
+
* @example
|
|
681
|
+
* ```ts
|
|
682
|
+
* app.get('/', (c) => {
|
|
683
|
+
* const message = c.get('message')
|
|
684
|
+
* return c.text(`The message is "${message}"`)
|
|
685
|
+
* })
|
|
686
|
+
* ```
|
|
687
|
+
*/
|
|
688
|
+
get = (key) => {
|
|
689
|
+
return this.#var ? this.#var.get(key) : void 0;
|
|
690
|
+
};
|
|
691
|
+
/**
|
|
692
|
+
* `.var` can access the value of a variable.
|
|
693
|
+
*
|
|
694
|
+
* @see {@link https://hono.dev/docs/api/context#var}
|
|
695
|
+
*
|
|
696
|
+
* @example
|
|
697
|
+
* ```ts
|
|
698
|
+
* const result = c.var.client.oneMethod()
|
|
699
|
+
* ```
|
|
700
|
+
*/
|
|
701
|
+
// c.var.propName is a read-only
|
|
702
|
+
get var() {
|
|
703
|
+
if (!this.#var) {
|
|
704
|
+
return {};
|
|
705
|
+
}
|
|
706
|
+
return Object.fromEntries(this.#var);
|
|
707
|
+
}
|
|
708
|
+
#newResponse(data, arg, headers) {
|
|
709
|
+
const responseHeaders = this.#res ? new Headers(this.#res.headers) : this.#preparedHeaders ?? new Headers();
|
|
710
|
+
if (typeof arg === "object" && "headers" in arg) {
|
|
711
|
+
const argHeaders = arg.headers instanceof Headers ? arg.headers : new Headers(arg.headers);
|
|
712
|
+
for (const [key, value] of argHeaders) {
|
|
713
|
+
if (key.toLowerCase() === "set-cookie") {
|
|
714
|
+
responseHeaders.append(key, value);
|
|
715
|
+
} else {
|
|
716
|
+
responseHeaders.set(key, value);
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
if (headers) {
|
|
721
|
+
for (const [k, v] of Object.entries(headers)) {
|
|
722
|
+
if (typeof v === "string") {
|
|
723
|
+
responseHeaders.set(k, v);
|
|
724
|
+
} else {
|
|
725
|
+
responseHeaders.delete(k);
|
|
726
|
+
for (const v2 of v) {
|
|
727
|
+
responseHeaders.append(k, v2);
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
const status = typeof arg === "number" ? arg : arg?.status ?? this.#status;
|
|
733
|
+
return new Response(data, { status, headers: responseHeaders });
|
|
734
|
+
}
|
|
735
|
+
newResponse = (...args) => this.#newResponse(...args);
|
|
736
|
+
/**
|
|
737
|
+
* `.body()` can return the HTTP response.
|
|
738
|
+
* You can set headers with `.header()` and set HTTP status code with `.status`.
|
|
739
|
+
* This can also be set in `.text()`, `.json()` and so on.
|
|
740
|
+
*
|
|
741
|
+
* @see {@link https://hono.dev/docs/api/context#body}
|
|
742
|
+
*
|
|
743
|
+
* @example
|
|
744
|
+
* ```ts
|
|
745
|
+
* app.get('/welcome', (c) => {
|
|
746
|
+
* // Set headers
|
|
747
|
+
* c.header('X-Message', 'Hello!')
|
|
748
|
+
* c.header('Content-Type', 'text/plain')
|
|
749
|
+
* // Set HTTP status code
|
|
750
|
+
* c.status(201)
|
|
751
|
+
*
|
|
752
|
+
* // Return the response body
|
|
753
|
+
* return c.body('Thank you for coming')
|
|
754
|
+
* })
|
|
755
|
+
* ```
|
|
756
|
+
*/
|
|
757
|
+
body = (data, arg, headers) => this.#newResponse(data, arg, headers);
|
|
758
|
+
/**
|
|
759
|
+
* `.text()` can render text as `Content-Type:text/plain`.
|
|
760
|
+
*
|
|
761
|
+
* @see {@link https://hono.dev/docs/api/context#text}
|
|
762
|
+
*
|
|
763
|
+
* @example
|
|
764
|
+
* ```ts
|
|
765
|
+
* app.get('/say', (c) => {
|
|
766
|
+
* return c.text('Hello!')
|
|
767
|
+
* })
|
|
768
|
+
* ```
|
|
769
|
+
*/
|
|
770
|
+
text = (text, arg, headers) => {
|
|
771
|
+
return !this.#preparedHeaders && !this.#status && !arg && !headers && !this.finalized ? new Response(text) : this.#newResponse(
|
|
772
|
+
text,
|
|
773
|
+
arg,
|
|
774
|
+
setDefaultContentType(TEXT_PLAIN, headers)
|
|
775
|
+
);
|
|
776
|
+
};
|
|
777
|
+
/**
|
|
778
|
+
* `.json()` can render JSON as `Content-Type:application/json`.
|
|
779
|
+
*
|
|
780
|
+
* @see {@link https://hono.dev/docs/api/context#json}
|
|
781
|
+
*
|
|
782
|
+
* @example
|
|
783
|
+
* ```ts
|
|
784
|
+
* app.get('/api', (c) => {
|
|
785
|
+
* return c.json({ message: 'Hello!' })
|
|
786
|
+
* })
|
|
787
|
+
* ```
|
|
788
|
+
*/
|
|
789
|
+
json = (object, arg, headers) => {
|
|
790
|
+
return this.#newResponse(
|
|
791
|
+
JSON.stringify(object),
|
|
792
|
+
arg,
|
|
793
|
+
setDefaultContentType("application/json", headers)
|
|
794
|
+
);
|
|
795
|
+
};
|
|
796
|
+
html = (html, arg, headers) => {
|
|
797
|
+
const res = (html2) => this.#newResponse(html2, arg, setDefaultContentType("text/html; charset=UTF-8", headers));
|
|
798
|
+
return typeof html === "object" ? resolveCallback(html, HtmlEscapedCallbackPhase.Stringify, false, {}).then(res) : res(html);
|
|
799
|
+
};
|
|
800
|
+
/**
|
|
801
|
+
* `.redirect()` can Redirect, default status code is 302.
|
|
802
|
+
*
|
|
803
|
+
* @see {@link https://hono.dev/docs/api/context#redirect}
|
|
804
|
+
*
|
|
805
|
+
* @example
|
|
806
|
+
* ```ts
|
|
807
|
+
* app.get('/redirect', (c) => {
|
|
808
|
+
* return c.redirect('/')
|
|
809
|
+
* })
|
|
810
|
+
* app.get('/redirect-permanently', (c) => {
|
|
811
|
+
* return c.redirect('/', 301)
|
|
812
|
+
* })
|
|
813
|
+
* ```
|
|
814
|
+
*/
|
|
815
|
+
redirect = (location, status) => {
|
|
816
|
+
const locationString = String(location);
|
|
817
|
+
this.header(
|
|
818
|
+
"Location",
|
|
819
|
+
// Multibyes should be encoded
|
|
820
|
+
// eslint-disable-next-line no-control-regex
|
|
821
|
+
!/[^\x00-\xFF]/.test(locationString) ? locationString : encodeURI(locationString)
|
|
822
|
+
);
|
|
823
|
+
return this.newResponse(null, status ?? 302);
|
|
824
|
+
};
|
|
825
|
+
/**
|
|
826
|
+
* `.notFound()` can return the Not Found Response.
|
|
827
|
+
*
|
|
828
|
+
* @see {@link https://hono.dev/docs/api/context#notfound}
|
|
829
|
+
*
|
|
830
|
+
* @example
|
|
831
|
+
* ```ts
|
|
832
|
+
* app.get('/notfound', (c) => {
|
|
833
|
+
* return c.notFound()
|
|
834
|
+
* })
|
|
835
|
+
* ```
|
|
836
|
+
*/
|
|
837
|
+
notFound = () => {
|
|
838
|
+
this.#notFoundHandler ??= () => new Response();
|
|
839
|
+
return this.#notFoundHandler(this);
|
|
840
|
+
};
|
|
841
|
+
};
|
|
842
|
+
|
|
843
|
+
// ../../../node_modules/.pnpm/hono@4.11.1/node_modules/hono/dist/router.js
|
|
844
|
+
var METHOD_NAME_ALL = "ALL";
|
|
845
|
+
var METHOD_NAME_ALL_LOWERCASE = "all";
|
|
846
|
+
var METHODS = ["get", "post", "put", "delete", "options", "patch"];
|
|
847
|
+
var UnsupportedPathError = class extends Error {
|
|
848
|
+
};
|
|
849
|
+
|
|
850
|
+
// ../../../node_modules/.pnpm/hono@4.11.1/node_modules/hono/dist/utils/constants.js
|
|
851
|
+
var COMPOSED_HANDLER = "__COMPOSED_HANDLER";
|
|
852
|
+
|
|
853
|
+
// ../../../node_modules/.pnpm/hono@4.11.1/node_modules/hono/dist/hono-base.js
|
|
854
|
+
var notFoundHandler = (c) => {
|
|
855
|
+
return c.text("404 Not Found", 404);
|
|
856
|
+
};
|
|
857
|
+
var errorHandler = (err, c) => {
|
|
858
|
+
if ("getResponse" in err) {
|
|
859
|
+
const res = err.getResponse();
|
|
860
|
+
return c.newResponse(res.body, res);
|
|
861
|
+
}
|
|
862
|
+
console.error(err);
|
|
863
|
+
return c.text("Internal Server Error", 500);
|
|
864
|
+
};
|
|
865
|
+
var Hono = class _Hono {
|
|
866
|
+
get;
|
|
867
|
+
post;
|
|
868
|
+
put;
|
|
869
|
+
delete;
|
|
870
|
+
options;
|
|
871
|
+
patch;
|
|
872
|
+
all;
|
|
873
|
+
on;
|
|
874
|
+
use;
|
|
875
|
+
/*
|
|
876
|
+
This class is like an abstract class and does not have a router.
|
|
877
|
+
To use it, inherit the class and implement router in the constructor.
|
|
878
|
+
*/
|
|
879
|
+
router;
|
|
880
|
+
getPath;
|
|
881
|
+
// Cannot use `#` because it requires visibility at JavaScript runtime.
|
|
882
|
+
_basePath = "/";
|
|
883
|
+
#path = "/";
|
|
884
|
+
routes = [];
|
|
885
|
+
constructor(options = {}) {
|
|
886
|
+
const allMethods = [...METHODS, METHOD_NAME_ALL_LOWERCASE];
|
|
887
|
+
allMethods.forEach((method) => {
|
|
888
|
+
this[method] = (args1, ...args) => {
|
|
889
|
+
if (typeof args1 === "string") {
|
|
890
|
+
this.#path = args1;
|
|
891
|
+
} else {
|
|
892
|
+
this.#addRoute(method, this.#path, args1);
|
|
893
|
+
}
|
|
894
|
+
args.forEach((handler) => {
|
|
895
|
+
this.#addRoute(method, this.#path, handler);
|
|
896
|
+
});
|
|
897
|
+
return this;
|
|
898
|
+
};
|
|
899
|
+
});
|
|
900
|
+
this.on = (method, path, ...handlers) => {
|
|
901
|
+
for (const p of [path].flat()) {
|
|
902
|
+
this.#path = p;
|
|
903
|
+
for (const m of [method].flat()) {
|
|
904
|
+
handlers.map((handler) => {
|
|
905
|
+
this.#addRoute(m.toUpperCase(), this.#path, handler);
|
|
906
|
+
});
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
return this;
|
|
910
|
+
};
|
|
911
|
+
this.use = (arg1, ...handlers) => {
|
|
912
|
+
if (typeof arg1 === "string") {
|
|
913
|
+
this.#path = arg1;
|
|
914
|
+
} else {
|
|
915
|
+
this.#path = "*";
|
|
916
|
+
handlers.unshift(arg1);
|
|
917
|
+
}
|
|
918
|
+
handlers.forEach((handler) => {
|
|
919
|
+
this.#addRoute(METHOD_NAME_ALL, this.#path, handler);
|
|
920
|
+
});
|
|
921
|
+
return this;
|
|
922
|
+
};
|
|
923
|
+
const { strict, ...optionsWithoutStrict } = options;
|
|
924
|
+
Object.assign(this, optionsWithoutStrict);
|
|
925
|
+
this.getPath = strict ?? true ? options.getPath ?? getPath : getPathNoStrict;
|
|
926
|
+
}
|
|
927
|
+
#clone() {
|
|
928
|
+
const clone = new _Hono({
|
|
929
|
+
router: this.router,
|
|
930
|
+
getPath: this.getPath
|
|
931
|
+
});
|
|
932
|
+
clone.errorHandler = this.errorHandler;
|
|
933
|
+
clone.#notFoundHandler = this.#notFoundHandler;
|
|
934
|
+
clone.routes = this.routes;
|
|
935
|
+
return clone;
|
|
936
|
+
}
|
|
937
|
+
#notFoundHandler = notFoundHandler;
|
|
938
|
+
// Cannot use `#` because it requires visibility at JavaScript runtime.
|
|
939
|
+
errorHandler = errorHandler;
|
|
940
|
+
/**
|
|
941
|
+
* `.route()` allows grouping other Hono instance in routes.
|
|
942
|
+
*
|
|
943
|
+
* @see {@link https://hono.dev/docs/api/routing#grouping}
|
|
944
|
+
*
|
|
945
|
+
* @param {string} path - base Path
|
|
946
|
+
* @param {Hono} app - other Hono instance
|
|
947
|
+
* @returns {Hono} routed Hono instance
|
|
948
|
+
*
|
|
949
|
+
* @example
|
|
950
|
+
* ```ts
|
|
951
|
+
* const app = new Hono()
|
|
952
|
+
* const app2 = new Hono()
|
|
953
|
+
*
|
|
954
|
+
* app2.get("/user", (c) => c.text("user"))
|
|
955
|
+
* app.route("/api", app2) // GET /api/user
|
|
956
|
+
* ```
|
|
957
|
+
*/
|
|
958
|
+
route(path, app) {
|
|
959
|
+
const subApp = this.basePath(path);
|
|
960
|
+
app.routes.map((r) => {
|
|
961
|
+
let handler;
|
|
962
|
+
if (app.errorHandler === errorHandler) {
|
|
963
|
+
handler = r.handler;
|
|
964
|
+
} else {
|
|
965
|
+
handler = async (c, next) => (await compose([], app.errorHandler)(c, () => r.handler(c, next))).res;
|
|
966
|
+
handler[COMPOSED_HANDLER] = r.handler;
|
|
967
|
+
}
|
|
968
|
+
subApp.#addRoute(r.method, r.path, handler);
|
|
969
|
+
});
|
|
970
|
+
return this;
|
|
971
|
+
}
|
|
972
|
+
/**
|
|
973
|
+
* `.basePath()` allows base paths to be specified.
|
|
974
|
+
*
|
|
975
|
+
* @see {@link https://hono.dev/docs/api/routing#base-path}
|
|
976
|
+
*
|
|
977
|
+
* @param {string} path - base Path
|
|
978
|
+
* @returns {Hono} changed Hono instance
|
|
979
|
+
*
|
|
980
|
+
* @example
|
|
981
|
+
* ```ts
|
|
982
|
+
* const api = new Hono().basePath('/api')
|
|
983
|
+
* ```
|
|
984
|
+
*/
|
|
985
|
+
basePath(path) {
|
|
986
|
+
const subApp = this.#clone();
|
|
987
|
+
subApp._basePath = mergePath(this._basePath, path);
|
|
988
|
+
return subApp;
|
|
989
|
+
}
|
|
990
|
+
/**
|
|
991
|
+
* `.onError()` handles an error and returns a customized Response.
|
|
992
|
+
*
|
|
993
|
+
* @see {@link https://hono.dev/docs/api/hono#error-handling}
|
|
994
|
+
*
|
|
995
|
+
* @param {ErrorHandler} handler - request Handler for error
|
|
996
|
+
* @returns {Hono} changed Hono instance
|
|
997
|
+
*
|
|
998
|
+
* @example
|
|
999
|
+
* ```ts
|
|
1000
|
+
* app.onError((err, c) => {
|
|
1001
|
+
* console.error(`${err}`)
|
|
1002
|
+
* return c.text('Custom Error Message', 500)
|
|
1003
|
+
* })
|
|
1004
|
+
* ```
|
|
1005
|
+
*/
|
|
1006
|
+
onError = (handler) => {
|
|
1007
|
+
this.errorHandler = handler;
|
|
1008
|
+
return this;
|
|
1009
|
+
};
|
|
1010
|
+
/**
|
|
1011
|
+
* `.notFound()` allows you to customize a Not Found Response.
|
|
1012
|
+
*
|
|
1013
|
+
* @see {@link https://hono.dev/docs/api/hono#not-found}
|
|
1014
|
+
*
|
|
1015
|
+
* @param {NotFoundHandler} handler - request handler for not-found
|
|
1016
|
+
* @returns {Hono} changed Hono instance
|
|
1017
|
+
*
|
|
1018
|
+
* @example
|
|
1019
|
+
* ```ts
|
|
1020
|
+
* app.notFound((c) => {
|
|
1021
|
+
* return c.text('Custom 404 Message', 404)
|
|
1022
|
+
* })
|
|
1023
|
+
* ```
|
|
1024
|
+
*/
|
|
1025
|
+
notFound = (handler) => {
|
|
1026
|
+
this.#notFoundHandler = handler;
|
|
1027
|
+
return this;
|
|
1028
|
+
};
|
|
1029
|
+
/**
|
|
1030
|
+
* `.mount()` allows you to mount applications built with other frameworks into your Hono application.
|
|
1031
|
+
*
|
|
1032
|
+
* @see {@link https://hono.dev/docs/api/hono#mount}
|
|
1033
|
+
*
|
|
1034
|
+
* @param {string} path - base Path
|
|
1035
|
+
* @param {Function} applicationHandler - other Request Handler
|
|
1036
|
+
* @param {MountOptions} [options] - options of `.mount()`
|
|
1037
|
+
* @returns {Hono} mounted Hono instance
|
|
1038
|
+
*
|
|
1039
|
+
* @example
|
|
1040
|
+
* ```ts
|
|
1041
|
+
* import { Router as IttyRouter } from 'itty-router'
|
|
1042
|
+
* import { Hono } from 'hono'
|
|
1043
|
+
* // Create itty-router application
|
|
1044
|
+
* const ittyRouter = IttyRouter()
|
|
1045
|
+
* // GET /itty-router/hello
|
|
1046
|
+
* ittyRouter.get('/hello', () => new Response('Hello from itty-router'))
|
|
1047
|
+
*
|
|
1048
|
+
* const app = new Hono()
|
|
1049
|
+
* app.mount('/itty-router', ittyRouter.handle)
|
|
1050
|
+
* ```
|
|
1051
|
+
*
|
|
1052
|
+
* @example
|
|
1053
|
+
* ```ts
|
|
1054
|
+
* const app = new Hono()
|
|
1055
|
+
* // Send the request to another application without modification.
|
|
1056
|
+
* app.mount('/app', anotherApp, {
|
|
1057
|
+
* replaceRequest: (req) => req,
|
|
1058
|
+
* })
|
|
1059
|
+
* ```
|
|
1060
|
+
*/
|
|
1061
|
+
mount(path, applicationHandler, options) {
|
|
1062
|
+
let replaceRequest;
|
|
1063
|
+
let optionHandler;
|
|
1064
|
+
if (options) {
|
|
1065
|
+
if (typeof options === "function") {
|
|
1066
|
+
optionHandler = options;
|
|
1067
|
+
} else {
|
|
1068
|
+
optionHandler = options.optionHandler;
|
|
1069
|
+
if (options.replaceRequest === false) {
|
|
1070
|
+
replaceRequest = (request) => request;
|
|
1071
|
+
} else {
|
|
1072
|
+
replaceRequest = options.replaceRequest;
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
const getOptions = optionHandler ? (c) => {
|
|
1077
|
+
const options2 = optionHandler(c);
|
|
1078
|
+
return Array.isArray(options2) ? options2 : [options2];
|
|
1079
|
+
} : (c) => {
|
|
1080
|
+
let executionContext = void 0;
|
|
1081
|
+
try {
|
|
1082
|
+
executionContext = c.executionCtx;
|
|
1083
|
+
} catch {
|
|
1084
|
+
}
|
|
1085
|
+
return [c.env, executionContext];
|
|
1086
|
+
};
|
|
1087
|
+
replaceRequest ||= (() => {
|
|
1088
|
+
const mergedPath = mergePath(this._basePath, path);
|
|
1089
|
+
const pathPrefixLength = mergedPath === "/" ? 0 : mergedPath.length;
|
|
1090
|
+
return (request) => {
|
|
1091
|
+
const url = new URL(request.url);
|
|
1092
|
+
url.pathname = url.pathname.slice(pathPrefixLength) || "/";
|
|
1093
|
+
return new Request(url, request);
|
|
1094
|
+
};
|
|
1095
|
+
})();
|
|
1096
|
+
const handler = async (c, next) => {
|
|
1097
|
+
const res = await applicationHandler(replaceRequest(c.req.raw), ...getOptions(c));
|
|
1098
|
+
if (res) {
|
|
1099
|
+
return res;
|
|
1100
|
+
}
|
|
1101
|
+
await next();
|
|
1102
|
+
};
|
|
1103
|
+
this.#addRoute(METHOD_NAME_ALL, mergePath(path, "*"), handler);
|
|
1104
|
+
return this;
|
|
1105
|
+
}
|
|
1106
|
+
#addRoute(method, path, handler) {
|
|
1107
|
+
method = method.toUpperCase();
|
|
1108
|
+
path = mergePath(this._basePath, path);
|
|
1109
|
+
const r = { basePath: this._basePath, path, method, handler };
|
|
1110
|
+
this.router.add(method, path, [handler, r]);
|
|
1111
|
+
this.routes.push(r);
|
|
1112
|
+
}
|
|
1113
|
+
#handleError(err, c) {
|
|
1114
|
+
if (err instanceof Error) {
|
|
1115
|
+
return this.errorHandler(err, c);
|
|
1116
|
+
}
|
|
1117
|
+
throw err;
|
|
1118
|
+
}
|
|
1119
|
+
#dispatch(request, executionCtx, env, method) {
|
|
1120
|
+
if (method === "HEAD") {
|
|
1121
|
+
return (async () => new Response(null, await this.#dispatch(request, executionCtx, env, "GET")))();
|
|
1122
|
+
}
|
|
1123
|
+
const path = this.getPath(request, { env });
|
|
1124
|
+
const matchResult = this.router.match(method, path);
|
|
1125
|
+
const c = new Context(request, {
|
|
1126
|
+
path,
|
|
1127
|
+
matchResult,
|
|
1128
|
+
env,
|
|
1129
|
+
executionCtx,
|
|
1130
|
+
notFoundHandler: this.#notFoundHandler
|
|
1131
|
+
});
|
|
1132
|
+
if (matchResult[0].length === 1) {
|
|
1133
|
+
let res;
|
|
1134
|
+
try {
|
|
1135
|
+
res = matchResult[0][0][0][0](c, async () => {
|
|
1136
|
+
c.res = await this.#notFoundHandler(c);
|
|
1137
|
+
});
|
|
1138
|
+
} catch (err) {
|
|
1139
|
+
return this.#handleError(err, c);
|
|
1140
|
+
}
|
|
1141
|
+
return res instanceof Promise ? res.then(
|
|
1142
|
+
(resolved) => resolved || (c.finalized ? c.res : this.#notFoundHandler(c))
|
|
1143
|
+
).catch((err) => this.#handleError(err, c)) : res ?? this.#notFoundHandler(c);
|
|
1144
|
+
}
|
|
1145
|
+
const composed = compose(matchResult[0], this.errorHandler, this.#notFoundHandler);
|
|
1146
|
+
return (async () => {
|
|
1147
|
+
try {
|
|
1148
|
+
const context = await composed(c);
|
|
1149
|
+
if (!context.finalized) {
|
|
1150
|
+
throw new Error(
|
|
1151
|
+
"Context is not finalized. Did you forget to return a Response object or `await next()`?"
|
|
1152
|
+
);
|
|
1153
|
+
}
|
|
1154
|
+
return context.res;
|
|
1155
|
+
} catch (err) {
|
|
1156
|
+
return this.#handleError(err, c);
|
|
1157
|
+
}
|
|
1158
|
+
})();
|
|
1159
|
+
}
|
|
1160
|
+
/**
|
|
1161
|
+
* `.fetch()` will be entry point of your app.
|
|
1162
|
+
*
|
|
1163
|
+
* @see {@link https://hono.dev/docs/api/hono#fetch}
|
|
1164
|
+
*
|
|
1165
|
+
* @param {Request} request - request Object of request
|
|
1166
|
+
* @param {Env} Env - env Object
|
|
1167
|
+
* @param {ExecutionContext} - context of execution
|
|
1168
|
+
* @returns {Response | Promise<Response>} response of request
|
|
1169
|
+
*
|
|
1170
|
+
*/
|
|
1171
|
+
fetch = (request, ...rest) => {
|
|
1172
|
+
return this.#dispatch(request, rest[1], rest[0], request.method);
|
|
1173
|
+
};
|
|
1174
|
+
/**
|
|
1175
|
+
* `.request()` is a useful method for testing.
|
|
1176
|
+
* You can pass a URL or pathname to send a GET request.
|
|
1177
|
+
* app will return a Response object.
|
|
1178
|
+
* ```ts
|
|
1179
|
+
* test('GET /hello is ok', async () => {
|
|
1180
|
+
* const res = await app.request('/hello')
|
|
1181
|
+
* expect(res.status).toBe(200)
|
|
1182
|
+
* })
|
|
1183
|
+
* ```
|
|
1184
|
+
* @see https://hono.dev/docs/api/hono#request
|
|
1185
|
+
*/
|
|
1186
|
+
request = (input, requestInit, Env, executionCtx) => {
|
|
1187
|
+
if (input instanceof Request) {
|
|
1188
|
+
return this.fetch(requestInit ? new Request(input, requestInit) : input, Env, executionCtx);
|
|
1189
|
+
}
|
|
1190
|
+
input = input.toString();
|
|
1191
|
+
return this.fetch(
|
|
1192
|
+
new Request(
|
|
1193
|
+
/^https?:\/\//.test(input) ? input : `http://localhost${mergePath("/", input)}`,
|
|
1194
|
+
requestInit
|
|
1195
|
+
),
|
|
1196
|
+
Env,
|
|
1197
|
+
executionCtx
|
|
1198
|
+
);
|
|
1199
|
+
};
|
|
1200
|
+
/**
|
|
1201
|
+
* `.fire()` automatically adds a global fetch event listener.
|
|
1202
|
+
* This can be useful for environments that adhere to the Service Worker API, such as non-ES module Cloudflare Workers.
|
|
1203
|
+
* @deprecated
|
|
1204
|
+
* Use `fire` from `hono/service-worker` instead.
|
|
1205
|
+
* ```ts
|
|
1206
|
+
* import { Hono } from 'hono'
|
|
1207
|
+
* import { fire } from 'hono/service-worker'
|
|
1208
|
+
*
|
|
1209
|
+
* const app = new Hono()
|
|
1210
|
+
* // ...
|
|
1211
|
+
* fire(app)
|
|
1212
|
+
* ```
|
|
1213
|
+
* @see https://hono.dev/docs/api/hono#fire
|
|
1214
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API
|
|
1215
|
+
* @see https://developers.cloudflare.com/workers/reference/migrate-to-module-workers/
|
|
1216
|
+
*/
|
|
1217
|
+
fire = () => {
|
|
1218
|
+
addEventListener("fetch", (event) => {
|
|
1219
|
+
event.respondWith(this.#dispatch(event.request, event, void 0, event.request.method));
|
|
1220
|
+
});
|
|
1221
|
+
};
|
|
1222
|
+
};
|
|
1223
|
+
|
|
1224
|
+
// ../../../node_modules/.pnpm/hono@4.11.1/node_modules/hono/dist/router/pattern-router/router.js
|
|
1225
|
+
var emptyParams = /* @__PURE__ */ Object.create(null);
|
|
1226
|
+
var PatternRouter = class {
|
|
1227
|
+
name = "PatternRouter";
|
|
1228
|
+
#routes = [];
|
|
1229
|
+
add(method, path, handler) {
|
|
1230
|
+
const endsWithWildcard = path.at(-1) === "*";
|
|
1231
|
+
if (endsWithWildcard) {
|
|
1232
|
+
path = path.slice(0, -2);
|
|
1233
|
+
}
|
|
1234
|
+
if (path.at(-1) === "?") {
|
|
1235
|
+
path = path.slice(0, -1);
|
|
1236
|
+
this.add(method, path.replace(/\/[^/]+$/, ""), handler);
|
|
1237
|
+
}
|
|
1238
|
+
const parts = (path.match(/\/?(:\w+(?:{(?:(?:{[\d,]+})|[^}])+})?)|\/?[^\/\?]+/g) || []).map(
|
|
1239
|
+
(part) => {
|
|
1240
|
+
const match = part.match(/^\/:([^{]+)(?:{(.*)})?/);
|
|
1241
|
+
return match ? `/(?<${match[1]}>${match[2] || "[^/]+"})` : part === "/*" ? "/[^/]+" : part.replace(/[.\\+*[^\]$()]/g, "\\$&");
|
|
1242
|
+
}
|
|
1243
|
+
);
|
|
1244
|
+
try {
|
|
1245
|
+
this.#routes.push([
|
|
1246
|
+
new RegExp(`^${parts.join("")}${endsWithWildcard ? "" : "/?$"}`),
|
|
1247
|
+
method,
|
|
1248
|
+
handler
|
|
1249
|
+
]);
|
|
1250
|
+
} catch {
|
|
1251
|
+
throw new UnsupportedPathError();
|
|
1252
|
+
}
|
|
1253
|
+
}
|
|
1254
|
+
match(method, path) {
|
|
1255
|
+
const handlers = [];
|
|
1256
|
+
for (let i = 0, len = this.#routes.length; i < len; i++) {
|
|
1257
|
+
const [pattern, routeMethod, handler] = this.#routes[i];
|
|
1258
|
+
if (routeMethod === method || routeMethod === METHOD_NAME_ALL) {
|
|
1259
|
+
const match = pattern.exec(path);
|
|
1260
|
+
if (match) {
|
|
1261
|
+
handlers.push([handler, match.groups || emptyParams]);
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1265
|
+
return [handlers];
|
|
1266
|
+
}
|
|
1267
|
+
};
|
|
1268
|
+
|
|
1269
|
+
// ../../../node_modules/.pnpm/hono@4.11.1/node_modules/hono/dist/preset/tiny.js
|
|
1270
|
+
var Hono2 = class extends Hono {
|
|
1271
|
+
constructor(options = {}) {
|
|
1272
|
+
super(options);
|
|
1273
|
+
this.router = new PatternRouter();
|
|
1274
|
+
}
|
|
1275
|
+
};
|
|
1276
|
+
|
|
1277
|
+
export {
|
|
1278
|
+
Hono2 as Hono
|
|
1279
|
+
};
|
|
1280
|
+
//# sourceMappingURL=chunk-47DZBRQC.js.map
|