Skip to content

WriteTransitionInstance

Executes one transition out of an Item’s current state.

TWriteItem extends WriteItem = WriteItem

The Item type returned by execute.

execute(payload): Promise<TWriteItem>

Moves the Item to the transition’s target state, provided it is still in the source state.

Record<string, unknown>

Data accompanying the transition, matching the payload the transition declares.

Promise<TWriteItem>

The Item in its new state; the instance the transition was taken from is unchanged.

The source-state check and the state change are one atomic operation. A conflict is treated as transient, so the enclosing execution is retried within its retry budget with fresh Item lookups. The transition changes the state; publish the Event that announces the change from the same execution.

StateTransitionConflictError when the Item is no longer in the transition’s source state, for example because another execution moved it first.

Transition when in the expected state

const state = item.state;
if (state?.value === 'active') return await state.transitions.deactivate.execute({});
return item;

Add states and transitions