@kerebron/extension-server-hono 0.4.4 → 0.4.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/esm/HonoYjsMemAdapter.d.ts +2 -1
  2. package/esm/HonoYjsMemAdapter.d.ts.map +1 -1
  3. package/esm/HonoYjsMemAdapter.js +1 -0
  4. package/esm/_dnt.polyfills.d.ts +7 -0
  5. package/esm/_dnt.polyfills.d.ts.map +1 -0
  6. package/esm/_dnt.polyfills.js +1 -0
  7. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/compose.d.ts +15 -0
  8. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/compose.d.ts.map +1 -0
  9. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/compose.js +64 -0
  10. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/context.d.ts +452 -0
  11. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/context.d.ts.map +1 -0
  12. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/context.js +513 -0
  13. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/helper/websocket/index.d.ts +70 -0
  14. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/helper/websocket/index.d.ts.map +1 -0
  15. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/helper/websocket/index.js +95 -0
  16. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/hono-base.d.ts +221 -0
  17. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/hono-base.d.ts.map +1 -0
  18. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/hono-base.js +498 -0
  19. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/http-exception.d.ts +60 -0
  20. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/http-exception.d.ts.map +1 -0
  21. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/http-exception.js +71 -0
  22. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/request/constants.d.ts +2 -0
  23. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/request/constants.d.ts.map +1 -0
  24. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/request/constants.js +1 -0
  25. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/request.d.ts +314 -0
  26. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/request.d.ts.map +1 -0
  27. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/request.js +370 -0
  28. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/router.d.ts +98 -0
  29. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/router.d.ts.map +1 -0
  30. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/router.js +25 -0
  31. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/types.d.ts +563 -0
  32. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/types.d.ts.map +1 -0
  33. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/types.js +11 -0
  34. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/body.d.ts +80 -0
  35. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/body.d.ts.map +1 -0
  36. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/body.js +111 -0
  37. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/constants.d.ts +5 -0
  38. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/constants.d.ts.map +1 -0
  39. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/constants.js +4 -0
  40. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/headers.d.ts +9 -0
  41. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/headers.d.ts.map +1 -0
  42. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/headers.js +5 -0
  43. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/html.d.ts +45 -0
  44. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/html.d.ts.map +1 -0
  45. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/html.js +122 -0
  46. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/http-status.d.ts +33 -0
  47. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/http-status.d.ts.map +1 -0
  48. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/http-status.js +5 -0
  49. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/mime.d.ts +71 -0
  50. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/mime.d.ts.map +1 -0
  51. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/mime.js +83 -0
  52. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/types.d.ts +75 -0
  53. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/types.d.ts.map +1 -0
  54. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/types.js +5 -0
  55. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/url.d.ts +30 -0
  56. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/url.d.ts.map +1 -0
  57. package/esm/deps/jsr.io/@hono/hono/4.10.7/src/utils/url.js +255 -0
  58. package/esm/mod.d.ts +2 -1
  59. package/esm/mod.d.ts.map +1 -1
  60. package/esm/mod.js +1 -1
  61. package/package.json +3 -1
@@ -0,0 +1,314 @@
1
+ import { GET_MATCH_RESULT } from './request/constants.js';
2
+ import type { Result } from './router.js';
3
+ import type { Input, InputToDataByTarget, ParamKeyToRecord, ParamKeys, RemoveQuestion, RouterRoute, ValidationTargets } from './types.js';
4
+ import type { BodyData, ParseBodyOptions } from './utils/body.js';
5
+ import type { CustomHeader, RequestHeader } from './utils/headers.js';
6
+ import type { Simplify, UnionToIntersection } from './utils/types.js';
7
+ type Body = {
8
+ json: any;
9
+ text: string;
10
+ arrayBuffer: ArrayBuffer;
11
+ blob: Blob;
12
+ formData: FormData;
13
+ };
14
+ type BodyCache = Partial<Body & {
15
+ parsedBody: BodyData;
16
+ }>;
17
+ export declare class HonoRequest<P extends string = '/', I extends Input['out'] = {}> {
18
+ #private;
19
+ [GET_MATCH_RESULT]: Result<[unknown, RouterRoute]>;
20
+ /**
21
+ * `.raw` can get the raw Request object.
22
+ *
23
+ * @see {@link https://hono.dev/docs/api/request#raw}
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * // For Cloudflare Workers
28
+ * app.post('/', async (c) => {
29
+ * const metadata = c.req.raw.cf?.hostMetadata?
30
+ * ...
31
+ * })
32
+ * ```
33
+ */
34
+ raw: Request;
35
+ routeIndex: number;
36
+ /**
37
+ * `.path` can get the pathname of the request.
38
+ *
39
+ * @see {@link https://hono.dev/docs/api/request#path}
40
+ *
41
+ * @example
42
+ * ```ts
43
+ * app.get('/about/me', (c) => {
44
+ * const pathname = c.req.path // `/about/me`
45
+ * })
46
+ * ```
47
+ */
48
+ path: string;
49
+ bodyCache: BodyCache;
50
+ constructor(request: Request, path?: string, matchResult?: Result<[unknown, RouterRoute]>);
51
+ /**
52
+ * `.req.param()` gets the path parameters.
53
+ *
54
+ * @see {@link https://hono.dev/docs/api/routing#path-parameter}
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * const name = c.req.param('name')
59
+ * // or all parameters at once
60
+ * const { id, comment_id } = c.req.param()
61
+ * ```
62
+ */
63
+ param<P2 extends ParamKeys<P> = ParamKeys<P>>(key: P2 extends `${infer _}?` ? never : P2): string;
64
+ param<P2 extends RemoveQuestion<ParamKeys<P>> = RemoveQuestion<ParamKeys<P>>>(key: P2): string | undefined;
65
+ param(key: string): string | undefined;
66
+ param<P2 extends string = P>(): Simplify<UnionToIntersection<ParamKeyToRecord<ParamKeys<P2>>>>;
67
+ /**
68
+ * `.query()` can get querystring parameters.
69
+ *
70
+ * @see {@link https://hono.dev/docs/api/request#query}
71
+ *
72
+ * @example
73
+ * ```ts
74
+ * // Query params
75
+ * app.get('/search', (c) => {
76
+ * const query = c.req.query('q')
77
+ * })
78
+ *
79
+ * // Get all params at once
80
+ * app.get('/search', (c) => {
81
+ * const { q, limit, offset } = c.req.query()
82
+ * })
83
+ * ```
84
+ */
85
+ query(key: string): string | undefined;
86
+ query(): Record<string, string>;
87
+ /**
88
+ * `.queries()` can get multiple querystring parameter values, e.g. /search?tags=A&tags=B
89
+ *
90
+ * @see {@link https://hono.dev/docs/api/request#queries}
91
+ *
92
+ * @example
93
+ * ```ts
94
+ * app.get('/search', (c) => {
95
+ * // tags will be string[]
96
+ * const tags = c.req.queries('tags')
97
+ * })
98
+ * ```
99
+ */
100
+ queries(key: string): string[] | undefined;
101
+ queries(): Record<string, string[]>;
102
+ /**
103
+ * `.header()` can get the request header value.
104
+ *
105
+ * @see {@link https://hono.dev/docs/api/request#header}
106
+ *
107
+ * @example
108
+ * ```ts
109
+ * app.get('/', (c) => {
110
+ * const userAgent = c.req.header('User-Agent')
111
+ * })
112
+ * ```
113
+ */
114
+ header(name: RequestHeader): string | undefined;
115
+ header(name: string): string | undefined;
116
+ header(): Record<RequestHeader | (string & CustomHeader), string>;
117
+ /**
118
+ * `.parseBody()` can parse Request body of type `multipart/form-data` or `application/x-www-form-urlencoded`
119
+ *
120
+ * @see {@link https://hono.dev/docs/api/request#parsebody}
121
+ *
122
+ * @example
123
+ * ```ts
124
+ * app.post('/entry', async (c) => {
125
+ * const body = await c.req.parseBody()
126
+ * })
127
+ * ```
128
+ */
129
+ parseBody<Options extends Partial<ParseBodyOptions>, T extends BodyData<Options>>(options?: Options): Promise<T>;
130
+ parseBody<T extends BodyData>(options?: Partial<ParseBodyOptions>): Promise<T>;
131
+ /**
132
+ * `.json()` can parse Request body of type `application/json`
133
+ *
134
+ * @see {@link https://hono.dev/docs/api/request#json}
135
+ *
136
+ * @example
137
+ * ```ts
138
+ * app.post('/entry', async (c) => {
139
+ * const body = await c.req.json()
140
+ * })
141
+ * ```
142
+ */
143
+ json<T = any>(): Promise<T>;
144
+ /**
145
+ * `.text()` can parse Request body of type `text/plain`
146
+ *
147
+ * @see {@link https://hono.dev/docs/api/request#text}
148
+ *
149
+ * @example
150
+ * ```ts
151
+ * app.post('/entry', async (c) => {
152
+ * const body = await c.req.text()
153
+ * })
154
+ * ```
155
+ */
156
+ text(): Promise<string>;
157
+ /**
158
+ * `.arrayBuffer()` parse Request body as an `ArrayBuffer`
159
+ *
160
+ * @see {@link https://hono.dev/docs/api/request#arraybuffer}
161
+ *
162
+ * @example
163
+ * ```ts
164
+ * app.post('/entry', async (c) => {
165
+ * const body = await c.req.arrayBuffer()
166
+ * })
167
+ * ```
168
+ */
169
+ arrayBuffer(): Promise<ArrayBuffer>;
170
+ /**
171
+ * Parses the request body as a `Blob`.
172
+ * @example
173
+ * ```ts
174
+ * app.post('/entry', async (c) => {
175
+ * const body = await c.req.blob();
176
+ * });
177
+ * ```
178
+ * @see https://hono.dev/docs/api/request#blob
179
+ */
180
+ blob(): Promise<Blob>;
181
+ /**
182
+ * Parses the request body as `FormData`.
183
+ * @example
184
+ * ```ts
185
+ * app.post('/entry', async (c) => {
186
+ * const body = await c.req.formData();
187
+ * });
188
+ * ```
189
+ * @see https://hono.dev/docs/api/request#formdata
190
+ */
191
+ formData(): Promise<FormData>;
192
+ /**
193
+ * Adds validated data to the request.
194
+ *
195
+ * @param target - The target of the validation.
196
+ * @param data - The validated data to add.
197
+ */
198
+ addValidatedData(target: keyof ValidationTargets, data: {}): void;
199
+ /**
200
+ * Gets validated data from the request.
201
+ *
202
+ * @param target - The target of the validation.
203
+ * @returns The validated data.
204
+ *
205
+ * @see https://hono.dev/docs/api/request#valid
206
+ */
207
+ valid<T extends keyof I & keyof ValidationTargets>(target: T): InputToDataByTarget<I, T>;
208
+ /**
209
+ * `.url()` can get the request url strings.
210
+ *
211
+ * @see {@link https://hono.dev/docs/api/request#url}
212
+ *
213
+ * @example
214
+ * ```ts
215
+ * app.get('/about/me', (c) => {
216
+ * const url = c.req.url // `http://localhost:8787/about/me`
217
+ * ...
218
+ * })
219
+ * ```
220
+ */
221
+ get url(): string;
222
+ /**
223
+ * `.method()` can get the method name of the request.
224
+ *
225
+ * @see {@link https://hono.dev/docs/api/request#method}
226
+ *
227
+ * @example
228
+ * ```ts
229
+ * app.get('/about/me', (c) => {
230
+ * const method = c.req.method // `GET`
231
+ * })
232
+ * ```
233
+ */
234
+ get method(): string;
235
+ /**
236
+ * `.matchedRoutes()` can return a matched route in the handler
237
+ *
238
+ * @deprecated
239
+ *
240
+ * Use matchedRoutes helper defined in "hono/route" instead.
241
+ *
242
+ * @see {@link https://hono.dev/docs/api/request#matchedroutes}
243
+ *
244
+ * @example
245
+ * ```ts
246
+ * app.use('*', async function logger(c, next) {
247
+ * await next()
248
+ * c.req.matchedRoutes.forEach(({ handler, method, path }, i) => {
249
+ * const name = handler.name || (handler.length < 2 ? '[handler]' : '[middleware]')
250
+ * console.log(
251
+ * method,
252
+ * ' ',
253
+ * path,
254
+ * ' '.repeat(Math.max(10 - path.length, 0)),
255
+ * name,
256
+ * i === c.req.routeIndex ? '<- respond from here' : ''
257
+ * )
258
+ * })
259
+ * })
260
+ * ```
261
+ */
262
+ get matchedRoutes(): RouterRoute[];
263
+ /**
264
+ * `routePath()` can retrieve the path registered within the handler
265
+ *
266
+ * @deprecated
267
+ *
268
+ * Use routePath helper defined in "hono/route" instead.
269
+ *
270
+ * @see {@link https://hono.dev/docs/api/request#routepath}
271
+ *
272
+ * @example
273
+ * ```ts
274
+ * app.get('/posts/:id', (c) => {
275
+ * return c.json({ path: c.req.routePath })
276
+ * })
277
+ * ```
278
+ */
279
+ get routePath(): string;
280
+ }
281
+ /**
282
+ * Clones a HonoRequest's underlying raw Request object.
283
+ *
284
+ * This utility handles both consumed and unconsumed request bodies:
285
+ * - If the request body hasn't been consumed, it uses the native `clone()` method
286
+ * - If the request body has been consumed, it reconstructs a new Request using cached body data
287
+ *
288
+ * This is particularly useful when you need to:
289
+ * - Process the same request body multiple times
290
+ * - Pass requests to external services after validation
291
+ *
292
+ * @param req - The HonoRequest object to clone
293
+ * @returns A Promise that resolves to a new Request object with the same properties
294
+ * @throws {HTTPException} If the request body was consumed directly via `req.raw`
295
+ * without using HonoRequest methods (e.g., `req.json()`, `req.text()`), making it
296
+ * impossible to reconstruct the body from cache
297
+ *
298
+ * @example
299
+ * ```ts
300
+ * // Clone after consuming the body (e.g., after validation)
301
+ * app.post('/forward',
302
+ * validator('json', (data) => data),
303
+ * async (c) => {
304
+ * const validated = c.req.valid('json')
305
+ * // Body has been consumed, but cloneRawRequest still works
306
+ * const clonedReq = await cloneRawRequest(c.req)
307
+ * return fetch('http://backend-service.com', clonedReq)
308
+ * }
309
+ * )
310
+ * ```
311
+ */
312
+ export declare const cloneRawRequest: (req: HonoRequest) => Promise<Request>;
313
+ export {};
314
+ //# sourceMappingURL=request.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../../../../../../src/deps/jsr.io/@hono/hono/4.10.7/src/request.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AACzD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,KAAK,EACV,KAAK,EACL,mBAAmB,EACnB,gBAAgB,EAChB,SAAS,EACT,cAAc,EACd,WAAW,EACX,iBAAiB,EAClB,MAAM,YAAY,CAAA;AAEnB,OAAO,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AACjE,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AACrE,OAAO,KAAK,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAA;AAGrE,KAAK,IAAI,GAAG;IACV,IAAI,EAAE,GAAG,CAAA;IACT,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,WAAW,CAAA;IACxB,IAAI,EAAE,IAAI,CAAA;IACV,QAAQ,EAAE,QAAQ,CAAA;CACnB,CAAA;AACD,KAAK,SAAS,GAAG,OAAO,CAAC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EAAE,CAAC,CAAC;IAKxF;;;;;;;;;;;;OAYG;IACH,IAAI,GAAG,IAAI,MAAM,CAEhB;IAED;;;;;;;;;;;OAWG;IACH,IAAI,MAAM,IAAI,MAAM,CAEnB;IAMD;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACH,IAAI,aAAa,IAAI,WAAW,EAAE,CAEjC;IAED;;;;;;;;;;;;;;;OAeG;IACH,IAAI,SAAS,IAAI,MAAM,CAEtB;CACF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,eAAO,MAAM,eAAe,GAAU,KAAK,WAAW,KAAG,OAAO,CAAC,OAAO,CA6BvE,CAAA"}
@@ -0,0 +1,370 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _HonoRequest_instances, _HonoRequest_validatedData, _HonoRequest_matchResult, _HonoRequest_getDecodedParam, _HonoRequest_getAllDecodedParams, _HonoRequest_getParamValue, _HonoRequest_cachedBody;
13
+ /* eslint-disable @typescript-eslint/no-explicit-any */
14
+ import { HTTPException } from './http-exception.js';
15
+ import { GET_MATCH_RESULT } from './request/constants.js';
16
+ import { parseBody } from './utils/body.js';
17
+ import { decodeURIComponent_, getQueryParam, getQueryParams, tryDecode } from './utils/url.js';
18
+ const tryDecodeURIComponent = (str) => tryDecode(str, decodeURIComponent_);
19
+ export class HonoRequest {
20
+ constructor(request, path = '/', matchResult = [[]]) {
21
+ _HonoRequest_instances.add(this);
22
+ /**
23
+ * `.raw` can get the raw Request object.
24
+ *
25
+ * @see {@link https://hono.dev/docs/api/request#raw}
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * // For Cloudflare Workers
30
+ * app.post('/', async (c) => {
31
+ * const metadata = c.req.raw.cf?.hostMetadata?
32
+ * ...
33
+ * })
34
+ * ```
35
+ */
36
+ Object.defineProperty(this, "raw", {
37
+ enumerable: true,
38
+ configurable: true,
39
+ writable: true,
40
+ value: void 0
41
+ });
42
+ _HonoRequest_validatedData.set(this, void 0); // Short name of validatedData
43
+ _HonoRequest_matchResult.set(this, void 0);
44
+ Object.defineProperty(this, "routeIndex", {
45
+ enumerable: true,
46
+ configurable: true,
47
+ writable: true,
48
+ value: 0
49
+ });
50
+ /**
51
+ * `.path` can get the pathname of the request.
52
+ *
53
+ * @see {@link https://hono.dev/docs/api/request#path}
54
+ *
55
+ * @example
56
+ * ```ts
57
+ * app.get('/about/me', (c) => {
58
+ * const pathname = c.req.path // `/about/me`
59
+ * })
60
+ * ```
61
+ */
62
+ Object.defineProperty(this, "path", {
63
+ enumerable: true,
64
+ configurable: true,
65
+ writable: true,
66
+ value: void 0
67
+ });
68
+ Object.defineProperty(this, "bodyCache", {
69
+ enumerable: true,
70
+ configurable: true,
71
+ writable: true,
72
+ value: {}
73
+ });
74
+ _HonoRequest_cachedBody.set(this, (key) => {
75
+ const { bodyCache, raw } = this;
76
+ const cachedBody = bodyCache[key];
77
+ if (cachedBody) {
78
+ return cachedBody;
79
+ }
80
+ const anyCachedKey = Object.keys(bodyCache)[0];
81
+ if (anyCachedKey) {
82
+ return bodyCache[anyCachedKey].then((body) => {
83
+ if (anyCachedKey === 'json') {
84
+ body = JSON.stringify(body);
85
+ }
86
+ return new Response(body)[key]();
87
+ });
88
+ }
89
+ return (bodyCache[key] = raw[key]());
90
+ }
91
+ /**
92
+ * `.json()` can parse Request body of type `application/json`
93
+ *
94
+ * @see {@link https://hono.dev/docs/api/request#json}
95
+ *
96
+ * @example
97
+ * ```ts
98
+ * app.post('/entry', async (c) => {
99
+ * const body = await c.req.json()
100
+ * })
101
+ * ```
102
+ */
103
+ );
104
+ this.raw = request;
105
+ this.path = path;
106
+ __classPrivateFieldSet(this, _HonoRequest_matchResult, matchResult, "f");
107
+ __classPrivateFieldSet(this, _HonoRequest_validatedData, {}, "f");
108
+ }
109
+ param(key) {
110
+ return key ? __classPrivateFieldGet(this, _HonoRequest_instances, "m", _HonoRequest_getDecodedParam).call(this, key) : __classPrivateFieldGet(this, _HonoRequest_instances, "m", _HonoRequest_getAllDecodedParams).call(this);
111
+ }
112
+ query(key) {
113
+ return getQueryParam(this.url, key);
114
+ }
115
+ queries(key) {
116
+ return getQueryParams(this.url, key);
117
+ }
118
+ header(name) {
119
+ if (name) {
120
+ return this.raw.headers.get(name) ?? undefined;
121
+ }
122
+ const headerData = {};
123
+ this.raw.headers.forEach((value, key) => {
124
+ headerData[key] = value;
125
+ });
126
+ return headerData;
127
+ }
128
+ async parseBody(options) {
129
+ return (this.bodyCache.parsedBody ??= await parseBody(this, options));
130
+ }
131
+ /**
132
+ * `.json()` can parse Request body of type `application/json`
133
+ *
134
+ * @see {@link https://hono.dev/docs/api/request#json}
135
+ *
136
+ * @example
137
+ * ```ts
138
+ * app.post('/entry', async (c) => {
139
+ * const body = await c.req.json()
140
+ * })
141
+ * ```
142
+ */
143
+ json() {
144
+ return __classPrivateFieldGet(this, _HonoRequest_cachedBody, "f").call(this, 'text').then((text) => JSON.parse(text));
145
+ }
146
+ /**
147
+ * `.text()` can parse Request body of type `text/plain`
148
+ *
149
+ * @see {@link https://hono.dev/docs/api/request#text}
150
+ *
151
+ * @example
152
+ * ```ts
153
+ * app.post('/entry', async (c) => {
154
+ * const body = await c.req.text()
155
+ * })
156
+ * ```
157
+ */
158
+ text() {
159
+ return __classPrivateFieldGet(this, _HonoRequest_cachedBody, "f").call(this, 'text');
160
+ }
161
+ /**
162
+ * `.arrayBuffer()` parse Request body as an `ArrayBuffer`
163
+ *
164
+ * @see {@link https://hono.dev/docs/api/request#arraybuffer}
165
+ *
166
+ * @example
167
+ * ```ts
168
+ * app.post('/entry', async (c) => {
169
+ * const body = await c.req.arrayBuffer()
170
+ * })
171
+ * ```
172
+ */
173
+ arrayBuffer() {
174
+ return __classPrivateFieldGet(this, _HonoRequest_cachedBody, "f").call(this, 'arrayBuffer');
175
+ }
176
+ /**
177
+ * Parses the request body as a `Blob`.
178
+ * @example
179
+ * ```ts
180
+ * app.post('/entry', async (c) => {
181
+ * const body = await c.req.blob();
182
+ * });
183
+ * ```
184
+ * @see https://hono.dev/docs/api/request#blob
185
+ */
186
+ blob() {
187
+ return __classPrivateFieldGet(this, _HonoRequest_cachedBody, "f").call(this, 'blob');
188
+ }
189
+ /**
190
+ * Parses the request body as `FormData`.
191
+ * @example
192
+ * ```ts
193
+ * app.post('/entry', async (c) => {
194
+ * const body = await c.req.formData();
195
+ * });
196
+ * ```
197
+ * @see https://hono.dev/docs/api/request#formdata
198
+ */
199
+ formData() {
200
+ return __classPrivateFieldGet(this, _HonoRequest_cachedBody, "f").call(this, 'formData');
201
+ }
202
+ /**
203
+ * Adds validated data to the request.
204
+ *
205
+ * @param target - The target of the validation.
206
+ * @param data - The validated data to add.
207
+ */
208
+ addValidatedData(target, data) {
209
+ __classPrivateFieldGet(this, _HonoRequest_validatedData, "f")[target] = data;
210
+ }
211
+ valid(target) {
212
+ return __classPrivateFieldGet(this, _HonoRequest_validatedData, "f")[target];
213
+ }
214
+ /**
215
+ * `.url()` can get the request url strings.
216
+ *
217
+ * @see {@link https://hono.dev/docs/api/request#url}
218
+ *
219
+ * @example
220
+ * ```ts
221
+ * app.get('/about/me', (c) => {
222
+ * const url = c.req.url // `http://localhost:8787/about/me`
223
+ * ...
224
+ * })
225
+ * ```
226
+ */
227
+ get url() {
228
+ return this.raw.url;
229
+ }
230
+ /**
231
+ * `.method()` can get the method name of the request.
232
+ *
233
+ * @see {@link https://hono.dev/docs/api/request#method}
234
+ *
235
+ * @example
236
+ * ```ts
237
+ * app.get('/about/me', (c) => {
238
+ * const method = c.req.method // `GET`
239
+ * })
240
+ * ```
241
+ */
242
+ get method() {
243
+ return this.raw.method;
244
+ }
245
+ get [(_HonoRequest_validatedData = new WeakMap(), _HonoRequest_matchResult = new WeakMap(), _HonoRequest_cachedBody = new WeakMap(), _HonoRequest_instances = new WeakSet(), _HonoRequest_getDecodedParam = function _HonoRequest_getDecodedParam(key) {
246
+ const paramKey = __classPrivateFieldGet(this, _HonoRequest_matchResult, "f")[0][this.routeIndex][1][key];
247
+ const param = __classPrivateFieldGet(this, _HonoRequest_instances, "m", _HonoRequest_getParamValue).call(this, paramKey);
248
+ return param && /\%/.test(param) ? tryDecodeURIComponent(param) : param;
249
+ }, _HonoRequest_getAllDecodedParams = function _HonoRequest_getAllDecodedParams() {
250
+ const decoded = {};
251
+ const keys = Object.keys(__classPrivateFieldGet(this, _HonoRequest_matchResult, "f")[0][this.routeIndex][1]);
252
+ for (const key of keys) {
253
+ const value = __classPrivateFieldGet(this, _HonoRequest_instances, "m", _HonoRequest_getParamValue).call(this, __classPrivateFieldGet(this, _HonoRequest_matchResult, "f")[0][this.routeIndex][1][key]);
254
+ if (value !== undefined) {
255
+ decoded[key] = /\%/.test(value) ? tryDecodeURIComponent(value) : value;
256
+ }
257
+ }
258
+ return decoded;
259
+ }, _HonoRequest_getParamValue = function _HonoRequest_getParamValue(paramKey) {
260
+ return __classPrivateFieldGet(this, _HonoRequest_matchResult, "f")[1] ? __classPrivateFieldGet(this, _HonoRequest_matchResult, "f")[1][paramKey] : paramKey;
261
+ }, GET_MATCH_RESULT)]() {
262
+ return __classPrivateFieldGet(this, _HonoRequest_matchResult, "f");
263
+ }
264
+ /**
265
+ * `.matchedRoutes()` can return a matched route in the handler
266
+ *
267
+ * @deprecated
268
+ *
269
+ * Use matchedRoutes helper defined in "hono/route" instead.
270
+ *
271
+ * @see {@link https://hono.dev/docs/api/request#matchedroutes}
272
+ *
273
+ * @example
274
+ * ```ts
275
+ * app.use('*', async function logger(c, next) {
276
+ * await next()
277
+ * c.req.matchedRoutes.forEach(({ handler, method, path }, i) => {
278
+ * const name = handler.name || (handler.length < 2 ? '[handler]' : '[middleware]')
279
+ * console.log(
280
+ * method,
281
+ * ' ',
282
+ * path,
283
+ * ' '.repeat(Math.max(10 - path.length, 0)),
284
+ * name,
285
+ * i === c.req.routeIndex ? '<- respond from here' : ''
286
+ * )
287
+ * })
288
+ * })
289
+ * ```
290
+ */
291
+ get matchedRoutes() {
292
+ return __classPrivateFieldGet(this, _HonoRequest_matchResult, "f")[0].map(([[, route]]) => route);
293
+ }
294
+ /**
295
+ * `routePath()` can retrieve the path registered within the handler
296
+ *
297
+ * @deprecated
298
+ *
299
+ * Use routePath helper defined in "hono/route" instead.
300
+ *
301
+ * @see {@link https://hono.dev/docs/api/request#routepath}
302
+ *
303
+ * @example
304
+ * ```ts
305
+ * app.get('/posts/:id', (c) => {
306
+ * return c.json({ path: c.req.routePath })
307
+ * })
308
+ * ```
309
+ */
310
+ get routePath() {
311
+ return __classPrivateFieldGet(this, _HonoRequest_matchResult, "f")[0].map(([[, route]]) => route)[this.routeIndex].path;
312
+ }
313
+ }
314
+ /**
315
+ * Clones a HonoRequest's underlying raw Request object.
316
+ *
317
+ * This utility handles both consumed and unconsumed request bodies:
318
+ * - If the request body hasn't been consumed, it uses the native `clone()` method
319
+ * - If the request body has been consumed, it reconstructs a new Request using cached body data
320
+ *
321
+ * This is particularly useful when you need to:
322
+ * - Process the same request body multiple times
323
+ * - Pass requests to external services after validation
324
+ *
325
+ * @param req - The HonoRequest object to clone
326
+ * @returns A Promise that resolves to a new Request object with the same properties
327
+ * @throws {HTTPException} If the request body was consumed directly via `req.raw`
328
+ * without using HonoRequest methods (e.g., `req.json()`, `req.text()`), making it
329
+ * impossible to reconstruct the body from cache
330
+ *
331
+ * @example
332
+ * ```ts
333
+ * // Clone after consuming the body (e.g., after validation)
334
+ * app.post('/forward',
335
+ * validator('json', (data) => data),
336
+ * async (c) => {
337
+ * const validated = c.req.valid('json')
338
+ * // Body has been consumed, but cloneRawRequest still works
339
+ * const clonedReq = await cloneRawRequest(c.req)
340
+ * return fetch('http://backend-service.com', clonedReq)
341
+ * }
342
+ * )
343
+ * ```
344
+ */
345
+ export const cloneRawRequest = async (req) => {
346
+ if (!req.raw.bodyUsed) {
347
+ return req.raw.clone();
348
+ }
349
+ const cacheKey = Object.keys(req.bodyCache)[0];
350
+ if (!cacheKey) {
351
+ throw new HTTPException(500, {
352
+ message: 'Cannot clone request: body was already consumed and not cached. Please use HonoRequest methods (e.g., req.json(), req.text()) instead of consuming req.raw directly.',
353
+ });
354
+ }
355
+ const requestInit = {
356
+ body: await req[cacheKey](),
357
+ cache: req.raw.cache,
358
+ credentials: req.raw.credentials,
359
+ headers: req.header(),
360
+ integrity: req.raw.integrity,
361
+ keepalive: req.raw.keepalive,
362
+ method: req.method,
363
+ mode: req.raw.mode,
364
+ redirect: req.raw.redirect,
365
+ referrer: req.raw.referrer,
366
+ referrerPolicy: req.raw.referrerPolicy,
367
+ signal: req.raw.signal,
368
+ };
369
+ return new Request(req.url, requestInit);
370
+ };