UNPKG

vite-plugin-react-server

Version:
61 lines 2.38 kB
import type { Logger } from "vite"; import type { ServerResponse } from "node:http"; import type { IncomingMessage } from "node:http"; export type ServerActionHandlerOptions = { projectRoot: string; verbose?: boolean; logger?: Logger; ssrLoadModule?: (path: string) => Promise<any>; }; export type ServerActionRequest = { id: string; args: unknown[]; }; /** * Parses a server action request from the request body. * Supports two formats: * 1. Direct args array: [arg1, arg2, ...] * 2. Object with id and args: { id: string, args: unknown[] } */ export declare function parseServerActionRequestBody(body: string, url?: string): ServerActionRequest; export type ServerActionResponse = { type: "server-action-response"; returnValue: unknown; }; /** * Creates a server action response with the given result or error. */ export declare function createServerActionResponse(result?: unknown, error?: string): ServerActionResponse; /** * Sets up common response headers for server actions. */ export declare function setupServerActionHeaders(res: ServerResponse): void; /** * Parses a server action request from the request body and URL */ export declare function parseServerActionRequest(req: IncomingMessage, verbose?: boolean, logger?: Logger): Promise<ServerActionRequest>; /** * Resolves a server action ID to file path and export name */ export declare function resolveServerAction(id: string, projectRoot: string, verbose?: boolean, logger?: Logger): { filePath: string; exportName: string; fullPath: string; }; /** * Loads and validates a server action from a module */ export declare function loadServerAction(fullPath: string, exportName: string, ssrLoadModule: (path: string) => Promise<any>, verbose?: boolean, logger?: Logger): Promise<Function>; /** * Executes a server action with the given arguments */ export declare function executeServerAction(action: Function, args: unknown[], verbose?: boolean, logger?: Logger): Promise<unknown>; /** * Sends a server action response */ export declare function sendServerActionResponse(res: ServerResponse, result: unknown, verbose?: boolean, logger?: Logger): void; /** * Handles server action errors */ export declare function handleServerActionError(error: unknown, res: ServerResponse, logger?: Logger): void; //# sourceMappingURL=handleServerActionHelper.d.ts.map