import { JSXElementType, JSXElement, Props } from '../elements.js'; import '../jsx-globals.js'; import { InferSchema, ObjectSchema } from '../peer-types.js'; import { StateTuple, state } from './state.js'; import { RenderableChild } from './context.js'; import { on } from './lifecycle.js'; import { invalidate } from './data.js'; /** A declared server action, built by {@link defineAction}, bound to a form via {@link ActionForm}. */ interface ActionDescriptor< TInput extends Record = Record, > { readonly id: string; readonly input: ObjectSchema; readonly invalidates: readonly string[]; } /** Declare a server action with a stable id, input schema, and query prefixes to invalidate on success. */ declare function defineAction>(options: { readonly id: string; readonly input: ObjectSchema; readonly invalidates?: readonly string[]; }): ActionDescriptor; /** A native form bound to a declared action; it is not a synthetic event API. */ declare function ActionForm>({ action, children, ...props }: { readonly action: ActionDescriptor; readonly children?: RenderableChild; readonly [key: string]: unknown; }): JSXElement; /** Server-replayed validation failure for an {@link ActionForm} submission. */ interface ActionValidationError { readonly kind: 'invalid'; readonly action: string; readonly values: Readonly>; readonly issues: readonly unknown[]; readonly fieldErrors: Readonly>; } /** Pending/result/error status for an action, as reported by the `action()` hook. */ interface ActionStatus { readonly pending: boolean; readonly result?: TResult; readonly error?: unknown; } /** * Bind an action descriptor to the calling component and return its * `{ state, submit }` handle. `action()` allocates its status with `state()`, * so it follows the same rule: call it during component render, at the top * level and in the same order on every render. `submit()` itself may be * called from event handlers or other async work. An explicit csrfToken * resolver runs fresh for every submission under the component/data lifetime. * Its undefined result omits the token instead of falling back to SSR data. */ declare function action< TInput extends Record, TResult = unknown, >( descriptor: ActionDescriptor, options?: { readonly csrfToken: (signal: AbortSignal) => Promise; } ): { state: StateTuple>; submit(input: TInput): Promise; }; export { ActionDescriptor, defineAction, ActionForm, ActionValidationError, ActionStatus, action, };