UNPKG

@kellanjs/actioncraft

Version:

Fluent, type-safe builder for Next.js server actions.

32 lines (31 loc) 1.5 kB
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>>; /** * Utility to extract the action ID from a crafted action. * Useful for debugging and logging purposes. * * @param action - The crafted action * @returns The action ID if available, undefined otherwise */ export declare function getActionId<TAction extends CraftedAction<any, any, any, any>>(action: TAction): string | undefined;