Skip to content

Action<TPayload, TResult, TUndoState>

@blobs/sdk v0.1.0


@blobs/sdk / actions/types / Action

Defined in: actions/types.ts:76

Command-pattern contract every action must implement.

Action instances carry their own payload, capture undo state on execution, and can replay or roll back via Action.redo and Action.undo. Actions are normally executed through ActionManager.execute so the manager can track them in history.

Type Parameters

TPayload

TPayload = unknown

The shape of the action’s input parameters.

TResult

TResult = unknown

The shape of the result data on success.

TUndoState

TUndoState = unknown

The shape of the snapshot captured for undo.

Properties

id

readonly id: string

Defined in: actions/types.ts:78

Unique action ID


type

readonly type: string

Defined in: actions/types.ts:80

Action type identifier


description

readonly description: string

Defined in: actions/types.ts:82

Human-readable description


payload

readonly payload: TPayload

Defined in: actions/types.ts:84

Action payload/parameters


status

status: ActionStatus

Defined in: actions/types.ts:86

Current status


createdAt

readonly createdAt: number

Defined in: actions/types.ts:88

Timestamp of creation


executedAt?

optional executedAt?: number

Defined in: actions/types.ts:90

Timestamp of execution


previousState?

optional previousState?: ActionState<TUndoState>

Defined in: actions/types.ts:92

State captured before execution (for undo)


result?

optional result?: ActionResult<TResult>

Defined in: actions/types.ts:94

Result of execution


canUndo

readonly canUndo: boolean

Defined in: actions/types.ts:96

Whether this action can be undone


canRedo

readonly canRedo: boolean

Defined in: actions/types.ts:98

Whether this action can be redone after undo

Methods

execute()

execute(context): Promise<ActionResult<TResult>>

Defined in: actions/types.ts:106

Executes the action, capturing undo state first if canUndo is true.

Parameters

context

ActionContext

Per-execution context.

Returns

Promise<ActionResult<TResult>>

The execution result.


undo()

undo(context): Promise<ActionResult<TResult>>

Defined in: actions/types.ts:114

Reverses the action by restoring the captured undo state.

Parameters

context

ActionContext

Per-execution context.

Returns

Promise<ActionResult<TResult>>

The undo result.


redo()

redo(context): Promise<ActionResult<TResult>>

Defined in: actions/types.ts:122

Re-applies a previously undone action.

Parameters

context

ActionContext

Per-execution context.

Returns

Promise<ActionResult<TResult>>

The redo result.


captureState()

captureState(context): Promise<TUndoState>

Defined in: actions/types.ts:131

Captures the state needed to reverse this action. Called automatically by BaseAction.execute before the operation runs.

Parameters

context

ActionContext

Per-execution context.

Returns

Promise<TUndoState>

The undo-state snapshot.


validate()

validate(context): Promise<ActionResult<void>>

Defined in: actions/types.ts:139

Validates whether the action can run in the given context.

Parameters

context

ActionContext

Per-execution context.

Returns

Promise<ActionResult<void>>

A success result, or a failure result with an error reason.