import type { FastifyRequest } from "fastify"; import type { VextRequest } from "../../types/request.js"; import type { VextApp } from "../../types/app.js"; /** * Fastify Request → VextRequest 转换 * * 将 Fastify 的 Request 对象转换为 vext 框架的统一请求接口。 * 所有底层框架特有的 API 在此处适配,后续代码只与 VextRequest 交互。 * * 转换要点: * - query: Fastify 已解析好 query 对象,直接使用 * - body: 由 body-parser 中间件后续填充(初始 undefined) * - params: Fastify 已解析好 params 对象,直接使用 * - headers: Fastify 的 request.headers 是 Node.js 原生 headers 对象(key 全小写) * - requestId: 由 requestId 中间件后续填充(初始空字符串) * - ip: 根据 trustProxy 配置决定从 X-Forwarded-For 或 socket 读取 * - protocol: 根据 trustProxy 配置决定从 X-Forwarded-Proto 或默认值读取 * - onClose: 注册请求关闭钩子,连接断开时触发(通过 request.raw.on('close')) * - valid: 获取 validate 中间件校验后的数据 * - _getRawBody: 从 Fastify request.body(Buffer,由通用 content-type parser 提供) * 转为字符串,供 vext body-parser 中间件使用 * * 与 Hono Adapter 的差异: * - Hono 通过 c.req.text() 读取 Web Request body(ReadableStream) * - Fastify 通过 removeAllContentTypeParsers + addContentTypeParser('*', parseAs: 'buffer') * 将原始 body 作为 Buffer 传入 request.body * - 两者最终都通过 req._getRawBody() 返回 string 供 body-parser 使用 * * @param request Fastify Request 对象 * @param app VextApp 实例 * @returns VextRequest 实例(含 _getRawBody 内部方法供 body-parser 使用) * * @see 08a-fastify-adapter.md §4(请求转换) * @see adapters/hono/request.ts(Hono Adapter 对应实现) */ export declare function createVextRequest(request: FastifyRequest, app: VextApp): VextRequest;