@mastra/mcp 1.8.0 → 1.8.1

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 (35) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/_types/hono/dist/types/client/client.d.ts +4 -0
  3. package/dist/_types/hono/dist/types/client/fetch-result-please.d.ts +35 -0
  4. package/dist/_types/hono/dist/types/client/index.d.ts +7 -0
  5. package/dist/_types/hono/dist/types/client/types.d.ts +229 -0
  6. package/dist/_types/hono/dist/types/client/utils.d.ts +18 -0
  7. package/dist/_types/hono/dist/types/context.d.ts +455 -0
  8. package/dist/_types/hono/dist/types/helper/streaming/index.d.ts +8 -0
  9. package/dist/_types/hono/dist/types/helper/streaming/sse.d.ts +13 -0
  10. package/dist/_types/hono/dist/types/helper/streaming/stream.d.ts +3 -0
  11. package/dist/_types/hono/dist/types/helper/streaming/text.d.ts +3 -0
  12. package/dist/_types/hono/dist/types/hono-base.d.ts +220 -0
  13. package/dist/_types/hono/dist/types/hono.d.ts +19 -0
  14. package/dist/_types/hono/dist/types/index.d.ts +36 -0
  15. package/dist/_types/hono/dist/types/request/constants.d.ts +1 -0
  16. package/dist/_types/hono/dist/types/request.d.ts +311 -0
  17. package/dist/_types/hono/dist/types/router.d.ts +97 -0
  18. package/dist/_types/hono/dist/types/types.d.ts +573 -0
  19. package/dist/_types/hono/dist/types/utils/body.d.ts +79 -0
  20. package/dist/_types/hono/dist/types/utils/headers.d.ts +8 -0
  21. package/dist/_types/hono/dist/types/utils/http-status.d.ts +32 -0
  22. package/dist/_types/hono/dist/types/utils/mime.d.ts +70 -0
  23. package/dist/_types/hono/dist/types/utils/stream.d.ts +31 -0
  24. package/dist/_types/hono/dist/types/utils/types.d.ts +74 -0
  25. package/dist/_types/hono-mcp-server-sse-transport/build/index.d.ts +1 -0
  26. package/dist/_types/hono-mcp-server-sse-transport/build/sse.d.ts +25 -0
  27. package/dist/docs/SKILL.md +1 -1
  28. package/dist/docs/assets/SOURCE_MAP.json +1 -1
  29. package/dist/docs/references/docs-mcp-mcp-apps.md +3 -3
  30. package/dist/index.cjs +2 -2
  31. package/dist/index.cjs.map +1 -1
  32. package/dist/index.js +2 -2
  33. package/dist/index.js.map +1 -1
  34. package/dist/server/server.d.ts +2 -2
  35. package/package.json +8 -9
@@ -0,0 +1,220 @@
1
+ /**
2
+ * @module
3
+ * This module is the base module for the Hono object.
4
+ */
5
+ import { Context } from './context';
6
+ import type { ExecutionContext } from './context';
7
+ import type { Router } from './router';
8
+ import type { Env, ErrorHandler, H, HandlerInterface, MergePath, MergeSchemaPath, MiddlewareHandlerInterface, NotFoundHandler, OnHandlerInterface, RouterRoute, Schema } from './types';
9
+ type GetPath<E extends Env> = (request: Request, options?: {
10
+ env?: E['Bindings'];
11
+ }) => string;
12
+ export type HonoOptions<E extends Env> = {
13
+ /**
14
+ * `strict` option specifies whether to distinguish whether the last path is a directory or not.
15
+ *
16
+ * @see {@link https://hono.dev/docs/api/hono#strict-mode}
17
+ *
18
+ * @default true
19
+ */
20
+ strict?: boolean;
21
+ /**
22
+ * `router` option specifies which router to use.
23
+ *
24
+ * @see {@link https://hono.dev/docs/api/hono#router-option}
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * const app = new Hono({ router: new RegExpRouter() })
29
+ * ```
30
+ */
31
+ router?: Router<[H, RouterRoute]>;
32
+ /**
33
+ * `getPath` can handle the host header value.
34
+ *
35
+ * @see {@link https://hono.dev/docs/api/routing#routing-with-host-header-value}
36
+ *
37
+ * @example
38
+ * ```ts
39
+ * const app = new Hono({
40
+ * getPath: (req) =>
41
+ * '/' + req.headers.get('host') + req.url.replace(/^https?:\/\/[^/]+(\/[^?]*)/, '$1'),
42
+ * })
43
+ *
44
+ * app.get('/www1.example.com/hello', () => c.text('hello www1'))
45
+ *
46
+ * // A following request will match the route:
47
+ * // new Request('http://www1.example.com/hello', {
48
+ * // headers: { host: 'www1.example.com' },
49
+ * // })
50
+ * ```
51
+ */
52
+ getPath?: GetPath<E>;
53
+ };
54
+ type MountOptionHandler = (c: Context) => unknown;
55
+ type MountReplaceRequest = (originalRequest: Request) => Request;
56
+ type MountOptions = MountOptionHandler | {
57
+ optionHandler?: MountOptionHandler;
58
+ replaceRequest?: MountReplaceRequest | false;
59
+ };
60
+ declare class Hono<E extends Env = Env, S extends Schema = {}, BasePath extends string = '/', CurrentPath extends string = BasePath> {
61
+
62
+ get: HandlerInterface<E, 'get', S, BasePath, CurrentPath>;
63
+ post: HandlerInterface<E, 'post', S, BasePath, CurrentPath>;
64
+ put: HandlerInterface<E, 'put', S, BasePath, CurrentPath>;
65
+ delete: HandlerInterface<E, 'delete', S, BasePath, CurrentPath>;
66
+ options: HandlerInterface<E, 'options', S, BasePath, CurrentPath>;
67
+ patch: HandlerInterface<E, 'patch', S, BasePath, CurrentPath>;
68
+ all: HandlerInterface<E, 'all', S, BasePath, CurrentPath>;
69
+ on: OnHandlerInterface<E, S, BasePath>;
70
+ use: MiddlewareHandlerInterface<E, S, BasePath>;
71
+ router: Router<[H, RouterRoute]>;
72
+ readonly getPath: GetPath<E>;
73
+ private _basePath;
74
+ routes: RouterRoute[];
75
+ constructor(options?: HonoOptions<E>);
76
+ private errorHandler;
77
+ /**
78
+ * `.route()` allows grouping other Hono instance in routes.
79
+ *
80
+ * @see {@link https://hono.dev/docs/api/routing#grouping}
81
+ *
82
+ * @param {string} path - base Path
83
+ * @param {Hono} app - other Hono instance
84
+ * @returns {Hono} routed Hono instance
85
+ *
86
+ * @example
87
+ * ```ts
88
+ * const app = new Hono()
89
+ * const app2 = new Hono()
90
+ *
91
+ * app2.get("/user", (c) => c.text("user"))
92
+ * app.route("/api", app2) // GET /api/user
93
+ * ```
94
+ */
95
+ route<SubPath extends string, SubEnv extends Env, SubSchema extends Schema, SubBasePath extends string, SubCurrentPath extends string>(path: SubPath, app: Hono<SubEnv, SubSchema, SubBasePath, SubCurrentPath>): Hono<E, MergeSchemaPath<SubSchema, MergePath<BasePath, SubPath>> | S, BasePath, CurrentPath>;
96
+ /**
97
+ * `.basePath()` allows base paths to be specified.
98
+ *
99
+ * @see {@link https://hono.dev/docs/api/routing#base-path}
100
+ *
101
+ * @param {string} path - base Path
102
+ * @returns {Hono} changed Hono instance
103
+ *
104
+ * @example
105
+ * ```ts
106
+ * const api = new Hono().basePath('/api')
107
+ * ```
108
+ */
109
+ basePath<SubPath extends string>(path: SubPath): Hono<E, S, MergePath<BasePath, SubPath>, MergePath<BasePath, SubPath>>;
110
+ /**
111
+ * `.onError()` handles an error and returns a customized Response.
112
+ *
113
+ * @see {@link https://hono.dev/docs/api/hono#error-handling}
114
+ *
115
+ * @param {ErrorHandler} handler - request Handler for error
116
+ * @returns {Hono} changed Hono instance
117
+ *
118
+ * @example
119
+ * ```ts
120
+ * app.onError((err, c) => {
121
+ * console.error(`${err}`)
122
+ * return c.text('Custom Error Message', 500)
123
+ * })
124
+ * ```
125
+ */
126
+ onError: (handler: ErrorHandler<E>) => Hono<E, S, BasePath, CurrentPath>;
127
+ /**
128
+ * `.notFound()` allows you to customize a Not Found Response.
129
+ *
130
+ * @see {@link https://hono.dev/docs/api/hono#not-found}
131
+ *
132
+ * @param {NotFoundHandler} handler - request handler for not-found
133
+ * @returns {Hono} changed Hono instance
134
+ *
135
+ * @example
136
+ * ```ts
137
+ * app.notFound((c) => {
138
+ * return c.text('Custom 404 Message', 404)
139
+ * })
140
+ * ```
141
+ */
142
+ notFound: (handler: NotFoundHandler<E>) => Hono<E, S, BasePath, CurrentPath>;
143
+ /**
144
+ * `.mount()` allows you to mount applications built with other frameworks into your Hono application.
145
+ *
146
+ * @see {@link https://hono.dev/docs/api/hono#mount}
147
+ *
148
+ * @param {string} path - base Path
149
+ * @param {Function} applicationHandler - other Request Handler
150
+ * @param {MountOptions} [options] - options of `.mount()`
151
+ * @returns {Hono} mounted Hono instance
152
+ *
153
+ * @example
154
+ * ```ts
155
+ * import { Router as IttyRouter } from 'itty-router'
156
+ * import { Hono } from 'hono'
157
+ * // Create itty-router application
158
+ * const ittyRouter = IttyRouter()
159
+ * // GET /itty-router/hello
160
+ * ittyRouter.get('/hello', () => new Response('Hello from itty-router'))
161
+ *
162
+ * const app = new Hono()
163
+ * app.mount('/itty-router', ittyRouter.handle)
164
+ * ```
165
+ *
166
+ * @example
167
+ * ```ts
168
+ * const app = new Hono()
169
+ * // Send the request to another application without modification.
170
+ * app.mount('/app', anotherApp, {
171
+ * replaceRequest: (req) => req,
172
+ * })
173
+ * ```
174
+ */
175
+ mount(path: string, applicationHandler: (request: Request, ...args: any) => Response | Promise<Response>, options?: MountOptions): Hono<E, S, BasePath, CurrentPath>;
176
+ /**
177
+ * `.fetch()` will be entry point of your app.
178
+ *
179
+ * @see {@link https://hono.dev/docs/api/hono#fetch}
180
+ *
181
+ * @param {Request} request - request Object of request
182
+ * @param {Env} Env - env Object
183
+ * @param {ExecutionContext} - context of execution
184
+ * @returns {Response | Promise<Response>} response of request
185
+ *
186
+ */
187
+ fetch: (request: Request, Env?: E['Bindings'] | {}, executionCtx?: ExecutionContext) => Response | Promise<Response>;
188
+ /**
189
+ * `.request()` is a useful method for testing.
190
+ * You can pass a URL or pathname to send a GET request.
191
+ * app will return a Response object.
192
+ * ```ts
193
+ * test('GET /hello is ok', async () => {
194
+ * const res = await app.request('/hello')
195
+ * expect(res.status).toBe(200)
196
+ * })
197
+ * ```
198
+ * @see https://hono.dev/docs/api/hono#request
199
+ */
200
+ request: (input: Request | string | URL, requestInit?: RequestInit, Env?: E["Bindings"] | {}, executionCtx?: ExecutionContext) => Response | Promise<Response>;
201
+ /**
202
+ * `.fire()` automatically adds a global fetch event listener.
203
+ * This can be useful for environments that adhere to the Service Worker API, such as non-ES module Cloudflare Workers.
204
+ * @deprecated
205
+ * Use `fire` from `hono/service-worker` instead.
206
+ * ```ts
207
+ * import { Hono } from 'hono'
208
+ * import { fire } from 'hono/service-worker'
209
+ *
210
+ * const app = new Hono()
211
+ * // ...
212
+ * fire(app)
213
+ * ```
214
+ * @see https://hono.dev/docs/api/hono#fire
215
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API
216
+ * @see https://developers.cloudflare.com/workers/reference/migrate-to-module-workers/
217
+ */
218
+ fire: () => void;
219
+ }
220
+ export { Hono as HonoBase };
@@ -0,0 +1,19 @@
1
+ import { HonoBase } from './hono-base';
2
+ import type { HonoOptions } from './hono-base';
3
+ import type { BlankEnv, BlankSchema, Env, Schema } from './types';
4
+ /**
5
+ * The Hono class extends the functionality of the HonoBase class.
6
+ * It sets up routing and allows for custom options to be passed.
7
+ *
8
+ * @template E - The environment type.
9
+ * @template S - The schema type.
10
+ * @template BasePath - The base path type.
11
+ */
12
+ export declare class Hono<E extends Env = BlankEnv, S extends Schema = BlankSchema, BasePath extends string = '/'> extends HonoBase<E, S, BasePath> {
13
+ /**
14
+ * Creates an instance of the Hono class.
15
+ *
16
+ * @param options - Optional configuration options for the Hono instance.
17
+ */
18
+ constructor(options?: HonoOptions<E>);
19
+ }
@@ -0,0 +1,36 @@
1
+ /**
2
+ * @module
3
+ *
4
+ * Hono - Web Framework built on Web Standards
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * import { Hono } from 'hono'
9
+ * const app = new Hono()
10
+ *
11
+ * app.get('/', (c) => c.text('Hono!'))
12
+ *
13
+ * export default app
14
+ * ```
15
+ */
16
+ import { Hono } from './hono';
17
+ /**
18
+ * Types for environment variables, error handlers, handlers, middleware handlers, and more.
19
+ */
20
+ export type { Env, ErrorHandler, Handler, MiddlewareHandler, Next, NotFoundResponse, NotFoundHandler, ValidationTargets, Input, Schema, ToSchema, TypedResponse, } from './types';
21
+ /**
22
+ * Types for context, context variable map, context renderer, and execution context.
23
+ */
24
+ export type { Context, ContextVariableMap, ContextRenderer, ExecutionContext } from './context';
25
+ /**
26
+ * Type for HonoRequest.
27
+ */
28
+ export type { HonoRequest } from './request';
29
+ /**
30
+ * Types for inferring request and response types and client request options.
31
+ */
32
+ export type { InferRequestType, InferResponseType, ClientRequestOptions } from './client';
33
+ /**
34
+ * Hono framework for building web applications.
35
+ */
36
+ export { Hono };
@@ -0,0 +1 @@
1
+ export declare const GET_MATCH_RESULT: unique symbol;
@@ -0,0 +1,311 @@
1
+ import { GET_MATCH_RESULT } from './request/constants';
2
+ import type { Result } from './router';
3
+ import type { Input, InputToDataByTarget, ParamKeyToRecord, ParamKeys, RemoveQuestion, RouterRoute, ValidationTargets } from './types';
4
+ import type { BodyData, ParseBodyOptions } from './utils/body';
5
+ import type { CustomHeader, RequestHeader } from './utils/headers';
6
+ import type { Simplify, UnionToIntersection } from './utils/types';
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
+ export declare class HonoRequest<P extends string = '/', I extends Input['out'] = {}> {
16
+
17
+ /**
18
+ * `.raw` can get the raw Request object.
19
+ *
20
+ * @see {@link https://hono.dev/docs/api/request#raw}
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * // For Cloudflare Workers
25
+ * app.post('/', async (c) => {
26
+ * const metadata = c.req.raw.cf?.hostMetadata?
27
+ * ...
28
+ * })
29
+ * ```
30
+ */
31
+ raw: Request;
32
+ routeIndex: number;
33
+ /**
34
+ * `.path` can get the pathname of the request.
35
+ *
36
+ * @see {@link https://hono.dev/docs/api/request#path}
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * app.get('/about/me', (c) => {
41
+ * const pathname = c.req.path // `/about/me`
42
+ * })
43
+ * ```
44
+ */
45
+ path: string;
46
+ bodyCache: BodyCache;
47
+ constructor(request: Request, path?: string, matchResult?: Result<[unknown, RouterRoute]>);
48
+ /**
49
+ * `.req.param()` gets the path parameters.
50
+ *
51
+ * @see {@link https://hono.dev/docs/api/routing#path-parameter}
52
+ *
53
+ * @example
54
+ * ```ts
55
+ * const name = c.req.param('name')
56
+ * // or all parameters at once
57
+ * const { id, comment_id } = c.req.param()
58
+ * ```
59
+ */
60
+ param<P2 extends ParamKeys<P> = ParamKeys<P>>(key: string extends P ? never : P2 extends `${infer _}?` ? never : P2): string;
61
+ param<P2 extends RemoveQuestion<ParamKeys<P>> = RemoveQuestion<ParamKeys<P>>>(key: P2): string | undefined;
62
+ param(key: string): string | undefined;
63
+ param<P2 extends string = P>(): Simplify<UnionToIntersection<ParamKeyToRecord<ParamKeys<P2>>>>;
64
+ /**
65
+ * `.query()` can get querystring parameters.
66
+ *
67
+ * @see {@link https://hono.dev/docs/api/request#query}
68
+ *
69
+ * @example
70
+ * ```ts
71
+ * // Query params
72
+ * app.get('/search', (c) => {
73
+ * const query = c.req.query('q')
74
+ * })
75
+ *
76
+ * // Get all params at once
77
+ * app.get('/search', (c) => {
78
+ * const { q, limit, offset } = c.req.query()
79
+ * })
80
+ * ```
81
+ */
82
+ query(key: string): string | undefined;
83
+ query(): Record<string, string>;
84
+ /**
85
+ * `.queries()` can get multiple querystring parameter values, e.g. /search?tags=A&tags=B
86
+ *
87
+ * @see {@link https://hono.dev/docs/api/request#queries}
88
+ *
89
+ * @example
90
+ * ```ts
91
+ * app.get('/search', (c) => {
92
+ * // tags will be string[]
93
+ * const tags = c.req.queries('tags')
94
+ * })
95
+ * ```
96
+ */
97
+ queries(key: string): string[] | undefined;
98
+ queries(): Record<string, string[]>;
99
+ /**
100
+ * `.header()` can get the request header value.
101
+ *
102
+ * @see {@link https://hono.dev/docs/api/request#header}
103
+ *
104
+ * @example
105
+ * ```ts
106
+ * app.get('/', (c) => {
107
+ * const userAgent = c.req.header('User-Agent')
108
+ * })
109
+ * ```
110
+ */
111
+ header(name: RequestHeader): string | undefined;
112
+ header(name: string): string | undefined;
113
+ header(): Record<RequestHeader | (string & CustomHeader), string>;
114
+ /**
115
+ * `.parseBody()` can parse Request body of type `multipart/form-data` or `application/x-www-form-urlencoded`
116
+ *
117
+ * @see {@link https://hono.dev/docs/api/request#parsebody}
118
+ *
119
+ * @example
120
+ * ```ts
121
+ * app.post('/entry', async (c) => {
122
+ * const body = await c.req.parseBody()
123
+ * })
124
+ * ```
125
+ */
126
+ parseBody<Options extends Partial<ParseBodyOptions>, T extends BodyData<Options>>(options?: Options): Promise<T>;
127
+ parseBody<T extends BodyData>(options?: Partial<ParseBodyOptions>): Promise<T>;
128
+ /**
129
+ * `.json()` can parse Request body of type `application/json`
130
+ *
131
+ * @see {@link https://hono.dev/docs/api/request#json}
132
+ *
133
+ * @example
134
+ * ```ts
135
+ * app.post('/entry', async (c) => {
136
+ * const body = await c.req.json()
137
+ * })
138
+ * ```
139
+ */
140
+ json<T = any>(): Promise<T>;
141
+ /**
142
+ * `.text()` can parse Request body of type `text/plain`
143
+ *
144
+ * @see {@link https://hono.dev/docs/api/request#text}
145
+ *
146
+ * @example
147
+ * ```ts
148
+ * app.post('/entry', async (c) => {
149
+ * const body = await c.req.text()
150
+ * })
151
+ * ```
152
+ */
153
+ text(): Promise<string>;
154
+ /**
155
+ * `.arrayBuffer()` parse Request body as an `ArrayBuffer`
156
+ *
157
+ * @see {@link https://hono.dev/docs/api/request#arraybuffer}
158
+ *
159
+ * @example
160
+ * ```ts
161
+ * app.post('/entry', async (c) => {
162
+ * const body = await c.req.arrayBuffer()
163
+ * })
164
+ * ```
165
+ */
166
+ arrayBuffer(): Promise<ArrayBuffer>;
167
+ /**
168
+ * Parses the request body as a `Blob`.
169
+ * @example
170
+ * ```ts
171
+ * app.post('/entry', async (c) => {
172
+ * const body = await c.req.blob();
173
+ * });
174
+ * ```
175
+ * @see https://hono.dev/docs/api/request#blob
176
+ */
177
+ blob(): Promise<Blob>;
178
+ /**
179
+ * Parses the request body as `FormData`.
180
+ * @example
181
+ * ```ts
182
+ * app.post('/entry', async (c) => {
183
+ * const body = await c.req.formData();
184
+ * });
185
+ * ```
186
+ * @see https://hono.dev/docs/api/request#formdata
187
+ */
188
+ formData(): Promise<FormData>;
189
+ /**
190
+ * Adds validated data to the request.
191
+ *
192
+ * @param target - The target of the validation.
193
+ * @param data - The validated data to add.
194
+ */
195
+ addValidatedData(target: keyof ValidationTargets, data: {}): void;
196
+ /**
197
+ * Gets validated data from the request.
198
+ *
199
+ * @param target - The target of the validation.
200
+ * @returns The validated data.
201
+ *
202
+ * @see https://hono.dev/docs/api/request#valid
203
+ */
204
+ valid<T extends keyof I & keyof ValidationTargets>(target: T): InputToDataByTarget<I, T>;
205
+ /**
206
+ * `.url()` can get the request url strings.
207
+ *
208
+ * @see {@link https://hono.dev/docs/api/request#url}
209
+ *
210
+ * @example
211
+ * ```ts
212
+ * app.get('/about/me', (c) => {
213
+ * const url = c.req.url // `http://localhost:8787/about/me`
214
+ * ...
215
+ * })
216
+ * ```
217
+ */
218
+ get url(): string;
219
+ /**
220
+ * `.method()` can get the method name of the request.
221
+ *
222
+ * @see {@link https://hono.dev/docs/api/request#method}
223
+ *
224
+ * @example
225
+ * ```ts
226
+ * app.get('/about/me', (c) => {
227
+ * const method = c.req.method // `GET`
228
+ * })
229
+ * ```
230
+ */
231
+ get method(): string;
232
+ get [GET_MATCH_RESULT](): Result<[unknown, RouterRoute]>;
233
+ /**
234
+ * `.matchedRoutes()` can return a matched route in the handler
235
+ *
236
+ * @deprecated
237
+ *
238
+ * Use matchedRoutes helper defined in "hono/route" instead.
239
+ *
240
+ * @see {@link https://hono.dev/docs/api/request#matchedroutes}
241
+ *
242
+ * @example
243
+ * ```ts
244
+ * app.use('*', async function logger(c, next) {
245
+ * await next()
246
+ * c.req.matchedRoutes.forEach(({ handler, method, path }, i) => {
247
+ * const name = handler.name || (handler.length < 2 ? '[handler]' : '[middleware]')
248
+ * console.log(
249
+ * method,
250
+ * ' ',
251
+ * path,
252
+ * ' '.repeat(Math.max(10 - path.length, 0)),
253
+ * name,
254
+ * i === c.req.routeIndex ? '<- respond from here' : ''
255
+ * )
256
+ * })
257
+ * })
258
+ * ```
259
+ */
260
+ get matchedRoutes(): RouterRoute[];
261
+ /**
262
+ * `routePath()` can retrieve the path registered within the handler
263
+ *
264
+ * @deprecated
265
+ *
266
+ * Use routePath helper defined in "hono/route" instead.
267
+ *
268
+ * @see {@link https://hono.dev/docs/api/request#routepath}
269
+ *
270
+ * @example
271
+ * ```ts
272
+ * app.get('/posts/:id', (c) => {
273
+ * return c.json({ path: c.req.routePath })
274
+ * })
275
+ * ```
276
+ */
277
+ get routePath(): string;
278
+ }
279
+ /**
280
+ * Clones a HonoRequest's underlying raw Request object.
281
+ *
282
+ * This utility handles both consumed and unconsumed request bodies:
283
+ * - If the request body hasn't been consumed, it uses the native `clone()` method
284
+ * - If the request body has been consumed, it reconstructs a new Request using cached body data
285
+ *
286
+ * This is particularly useful when you need to:
287
+ * - Process the same request body multiple times
288
+ * - Pass requests to external services after validation
289
+ *
290
+ * @param req - The HonoRequest object to clone
291
+ * @returns A Promise that resolves to a new Request object with the same properties
292
+ * @throws {HTTPException} If the request body was consumed directly via `req.raw`
293
+ * without using HonoRequest methods (e.g., `req.json()`, `req.text()`), making it
294
+ * impossible to reconstruct the body from cache
295
+ *
296
+ * @example
297
+ * ```ts
298
+ * // Clone after consuming the body (e.g., after validation)
299
+ * app.post('/forward',
300
+ * validator('json', (data) => data),
301
+ * async (c) => {
302
+ * const validated = c.req.valid('json')
303
+ * // Body has been consumed, but cloneRawRequest still works
304
+ * const clonedReq = await cloneRawRequest(c.req)
305
+ * return fetch('http://backend-service.com', clonedReq)
306
+ * }
307
+ * )
308
+ * ```
309
+ */
310
+ export declare const cloneRawRequest: (req: HonoRequest) => Promise<Request>;
311
+ export {};
@@ -0,0 +1,97 @@
1
+ /**
2
+ * @module
3
+ * This module provides types definitions and variables for the routers.
4
+ */
5
+ /**
6
+ * Constant representing all HTTP methods in uppercase.
7
+ */
8
+ export declare const METHOD_NAME_ALL: "ALL";
9
+ /**
10
+ * Constant representing all HTTP methods in lowercase.
11
+ */
12
+ export declare const METHOD_NAME_ALL_LOWERCASE: "all";
13
+ /**
14
+ * Array of supported HTTP methods.
15
+ */
16
+ export declare const METHODS: readonly ["get", "post", "put", "delete", "options", "patch"];
17
+ /**
18
+ * Error message indicating that a route cannot be added because the matcher is already built.
19
+ */
20
+ export declare const MESSAGE_MATCHER_IS_ALREADY_BUILT = "Can not add a route since the matcher is already built.";
21
+ /**
22
+ * Interface representing a router.
23
+ *
24
+ * @template T - The type of the handler.
25
+ */
26
+ export interface Router<T> {
27
+ /**
28
+ * The name of the router.
29
+ */
30
+ name: string;
31
+ /**
32
+ * Adds a route to the router.
33
+ *
34
+ * @param method - The HTTP method (e.g., 'get', 'post').
35
+ * @param path - The path for the route.
36
+ * @param handler - The handler for the route.
37
+ */
38
+ add(method: string, path: string, handler: T): void;
39
+ /**
40
+ * Matches a route based on the given method and path.
41
+ *
42
+ * @param method - The HTTP method (e.g., 'get', 'post').
43
+ * @param path - The path to match.
44
+ * @returns The result of the match.
45
+ */
46
+ match(method: string, path: string): Result<T>;
47
+ }
48
+ /**
49
+ * Type representing a map of parameter indices.
50
+ */
51
+ export type ParamIndexMap = Record<string, number>;
52
+ /**
53
+ * Type representing a stash of parameters.
54
+ */
55
+ export type ParamStash = string[];
56
+ /**
57
+ * Type representing a map of parameters.
58
+ */
59
+ export type Params = Record<string, string>;
60
+ /**
61
+ * Type representing the result of a route match.
62
+ *
63
+ * The result can be in one of two formats:
64
+ * 1. An array of handlers with their corresponding parameter index maps, followed by a parameter stash.
65
+ * 2. An array of handlers with their corresponding parameter maps.
66
+ *
67
+ * Example:
68
+ *
69
+ * [[handler, paramIndexMap][], paramArray]
70
+ * ```typescript
71
+ * [
72
+ * [
73
+ * [middlewareA, {}], // '*'
74
+ * [funcA, {'id': 0}], // '/user/:id/*'
75
+ * [funcB, {'id': 0, 'action': 1}], // '/user/:id/:action'
76
+ * ],
77
+ * ['123', 'abc']
78
+ * ]
79
+ * ```
80
+ *
81
+ * [[handler, params][]]
82
+ * ```typescript
83
+ * [
84
+ * [
85
+ * [middlewareA, {}], // '*'
86
+ * [funcA, {'id': '123'}], // '/user/:id/*'
87
+ * [funcB, {'id': '123', 'action': 'abc'}], // '/user/:id/:action'
88
+ * ]
89
+ * ]
90
+ * ```
91
+ */
92
+ export type Result<T> = [[T, ParamIndexMap][], ParamStash] | [[T, Params][]];
93
+ /**
94
+ * Error class representing an unsupported path error.
95
+ */
96
+ export declare class UnsupportedPathError extends Error {
97
+ }