@kellanjs/actioncraft
Version:
Fluent, type-safe builder for Next.js server actions.
24 lines (23 loc) • 1.16 kB
TypeScript
import type { CraftedAction } from "./types/actions.js";
import type { BaseError } from "./types/errors.js";
import type { InferErrors } from "./types/inference.js";
/**
* Error wrapper that provides standard Error semantics while preserving
* the original Actioncraft error data in the cause property.
*/
export declare class ActioncraftError<TErrorData extends BaseError = BaseError> extends Error {
readonly cause: TErrorData;
readonly actionId?: string;
constructor(errorData: TErrorData, actionId?: string);
}
/**
* Type guard to check if an error is an ActioncraftError.
*
* When called with just an error, performs basic structural validation.
* When called with an error and action, performs verified action ID checking.
*
* @param error - The unknown error to check
* @param action - Optional action for verified checking and type inference
* @returns Type predicate indicating if error is ActioncraftError
*/
export declare function isActioncraftError<TAction extends CraftedAction<any, any, any, any>>(error: unknown, action?: TAction): error is ActioncraftError<TAction extends undefined ? BaseError : InferErrors<TAction>>;