/** * Client-side helpers for invoking server actions. * * Server actions are defined in `page.action.ts` files next to `page.ts`. * They export async functions that run on the server. On the client, call them * by name using `callAction` or the higher-level `nixJsAction` helper: * * ```ts * import { callAction } from "@deijose/nix-js-kit/action"; * * const result = await callAction("submitContact", { name: "Ada" }, { page: "/contact" }); * ``` * * ```ts * import { nixJsAction } from "@deijose/nix-js-kit/action"; * * const contact = nixJsAction("submitContact", { page: "/contact" }); * await contact.submit({ name: "Ada" }); * console.log(contact.data.value, contact.error.value, contact.pending.value); * ``` */ import { ActionFailure, RedirectResponse } from "../errors.js"; export interface ActionRequest { name: string; page?: string; args: unknown[]; } export interface CallActionOptions { /** Page URL path that scopes the action, e.g. `/contact`. */ page?: string; } /** * Call a server action by name. * * The request is sent as a POST to `/__nix-js/actions` with the action name, * optional page scope, and serialized arguments. The server executes the * matching exported function from the scanned `page.action.ts` modules and * returns its JSON result. */ export declare function callAction(name: string, args?: unknown, options?: CallActionOptions): Promise | RedirectResponse>; export interface NixJsAction { /** Submit the action with the given input. */ submit(input: TInput): Promise | RedirectResponse>; /** Signal that is true while the action is running. */ pending: { value: boolean; }; /** Signal with the last successful result, action failure, redirect, or null. */ data: { value: TOutput | ActionFailure | RedirectResponse | null; }; /** Signal with the last error, or null. */ error: { value: Error | null; }; } /** * Create a reactive handle for a server action. * * Returns a `submit` function and signals for `pending`, `data`, and `error`. * Useful for wiring actions to forms and islands without manual signal boilerplate. */ export declare function nixJsAction(name: string, options?: CallActionOptions): NixJsAction; export { defineAction, type DefineActionOptions, type DefinedAction, type DefinedActionFn, type ActionContext, type ActionInputValidator, type ActionConcurrencyMode, } from "./define.js";