import type { Context } from "hono"; import type { ServerResponse } from "node:http"; import type { VextResponse } from "../../types/response.js"; import type { RouteOptions } from "../../types/app.js"; /** * 共享 Response 容器 * * Hono 的 route handler 必须返回 Response 对象。 * 但 vext 的中间件链通过 VextResponse 的方法(json/text/...)间接调用 Hono 的 API。 * 这些 API(c.json / c.body / c.text / c.redirect)都返回 Response 对象。 * * 通过 ResponseBox 容器,VextResponse 的每个发送方法将 Hono 返回的 Response * 存储到 box.value 中,adapter 的 route handler 随后通过 box.value 获取最终 Response * 返回给 Hono。 * * 如果中间件链执行完毕后 box.value 仍为 null,说明 handler 没有调用任何发送方法, * adapter 将返回一个空的 204 Response 作为兜底。 * * With deferred flush: terminal sends stage into `_pending` and only write into * the box during `_flush()` after the onion chain unwinds, so post-`await next()` * middleware can still setHeader/cookie. */ export interface ResponseBox { value: Response | null; } export interface HonoNodeResponseEnvironment { outgoing?: ServerResponse; vextStreamOwned?: boolean; } /** * 创建 ResponseBox 容器 * * 由 adapter 的 registerRoute / registerNotFound 中调用, * 传给 createVextResponse,并在 handler 返回后读取 box.value。 */ export declare function createResponseBox(): ResponseBox; /** * HonoContext → VextResponse 转换 * * Deferred terminal flush: json/rawJson/text/html/redirect stage until `_flush()` * so onion after-middleware can still mutate headers. * * @param c Hono Context 对象 * @param getRequestId 延迟获取 requestId 的 getter 函数 * @param box Response 捕获容器 * @returns VextResponse 实例(含内部方法 _enableWrap) */ export declare function createVextResponse(c: Context, getRequestId: () => string, box: ResponseBox, closeToken?: object, routeOptions?: RouteOptions, routeMethod?: string): VextResponse;