@kellanjs/actioncraft
Version:
Fluent, type-safe builder for Next.js server actions.
65 lines (64 loc) • 2.25 kB
TypeScript
import type { CraftedAction } from "../types/actions.js";
import type { CrafterConfig, CrafterSchemas, CrafterErrors, CrafterCallbacks } from "../types/crafter.js";
import type { Crafter } from "./crafter.js";
export declare class Executor<TConfig extends CrafterConfig, TSchemas extends CrafterSchemas, TErrors extends CrafterErrors, TCallbacks extends CrafterCallbacks<TConfig, TSchemas, TErrors, TData>, TData> {
private readonly _config;
private readonly _schemas;
private readonly _errors;
private readonly _callbacks;
private readonly _handler?;
private _actionId?;
constructor(crafter: Crafter<TConfig, TSchemas, TErrors, TCallbacks, TData>);
/**
* Builds and returns the final executable server action.
*/
craft(): CraftedAction<TConfig, TSchemas, TErrors, TData>;
/**
* Generates a unique identifier for this action instance.
*/
private _generateActionId;
/**
* Orchestrates action execution (validation, business logic, callbacks, and result formatting.)
*/
private _runAction;
/**
* Extracts bind arguments, previous state, and input from raw action arguments.
*/
private _extractActionArgs;
/**
* Transforms internal Result objects to client-facing action result format.
*/
private _toActionResult;
/**
* Handles uncaught exceptions during action execution.
*/
private _handleThrownError;
/**
* Validates input using the shared helper.
*/
private _validateInput;
/**
* Validates bound arguments using the configured bind schemas.
*/
private _validateBindArgs;
/**
* Validates output data using the configured output schema.
*/
private _validateOutput;
/**
* Executes the onStart callback if defined.
*/
private _executeOnStartCallback;
/**
* Executes result-based lifecycle callbacks (onSuccess, onError, onSettled).
*/
private _executeResultCallbacks;
/**
* Ensures a Result object has the correct action ID.
*/
private _ensureResultActionId;
/**
* Creates error functions that return a Result object when called by the action handler.
*/
private _buildErrorFunctions;
}