/** * @nexus_js/server - Legacy Action Wrapper * * Wrap Express/Connect middleware and route handlers as Nexus Server Actions. * Use this to migrate existing business logic incrementally. */ import type { NexusContext } from './context.js'; import { IncomingMessage, ServerResponse } from 'node:http'; export type ExpressMiddleware = (req: IncomingMessage & { body?: unknown; params?: Record; }, res: ServerResponse & { json?: (data: unknown) => void; status?: (code: number) => ServerResponse; }, next: (err?: unknown) => void) => void; /** * Wrap an Express/Connect middleware as a Nexus Server Action. * * The middleware's `req.body` is populated from the FormData/JSON action payload. * The middleware's `res.json(data)` returns `{ data }` to the client. * Calling `next(err)` returns `{ error: err.message, status: 500 }`. * * @example * ```ts * // Old Express route: * app.post('/api/legacy-payment', legacyPaymentMiddleware); * * // Wrap as Nexus action: * export const legacyPayment = wrapExpressMiddleware(legacyPaymentMiddleware); * * // Now callable from Nexus: *
* * *
* ``` */ export declare function wrapExpressMiddleware(middleware: ExpressMiddleware): (formData: FormData, ctx: NexusContext) => Promise<{ error: string; status: number; data?: never; } | { data: {}; error?: never; status?: never; } | { error?: never; status?: never; data?: never; }>; /** * Wrap a callback-style Express route handler as a Nexus Server Action. * * @example * ```ts * // Old Express route: * app.get('/api/users/:id', (req, res) => { * const user = db.users.find(req.params.id); * res.json({ user }); * }); * * // Wrap as Nexus action: * export const getUser = wrapExpressHandler((req, res) => { * const user = db.users.find(req.params.id); * res.json({ user }); * }); * ``` */ export declare function wrapExpressHandler(handler: (req: IncomingMessage & { body?: unknown; params?: Record; }, res: ServerResponse & { json?: (data: unknown) => void; status?: (code: number) => ServerResponse; }) => void | Promise): (formData: FormData, ctx: NexusContext) => Promise<{ error: string; status: number; data?: never; } | { data: {}; error?: never; status?: never; } | { error?: never; status?: never; data?: never; }>; //# sourceMappingURL=legacy-wrapper.d.ts.map