Skip to content

Transaction

Transaction: object

Defined in: Core/Transaction.ts:52

make: <S>(…steps) => Transaction<CombinedInput<S>, StepOutputs<S>, ErrorOf<S[number]>, UndoErrorOf<S[number]>> = makeTransaction

Assembles step definitions in execution order and validates their dependencies.

Assembles steps in execution order and validates their dependencies.

S extends readonly AnyStepInternal[]

…S & (ValidSequence<S, never> extends true ? unknown : never)

Transaction<CombinedInput<S>, StepOutputs<S>, ErrorOf<S[number]>, UndoErrorOf<S[number]>>

Transaction.step for defining reusable steps.

const checkout = Transaction.make(reservation, payment);

run: {(): <Acc, E, EUndo>(transaction) => Deferred<Result<Failure<Aborted | E, EUndo>, Acc>>; <In>(input, options?): <Acc, E, EUndo>(transaction) => Deferred<Result<Failure<Aborted | E, EUndo>, Acc>>; } = runTransaction

Starts a Transaction and returns a deferred result.

Steps run sequentially. If all steps succeed, returns Ok(Acc) containing all step outputs. If a step returns an error or cancellation is observed before a step starts, completed steps with undo actions are undone in reverse order and the result is Err(Transaction.Failure). Active tasks receive the signal and must handle cancellation themselves.

(): <Acc, E, EUndo>(transaction) => Deferred<Result<Failure<Aborted | E, EUndo>, Acc>>

Starts a Transaction and returns a deferred result.

Steps run sequentially. If all steps succeed, returns Ok(Acc) containing all step outputs. If a step returns an error or cancellation is observed before a step starts, completed steps with undo actions are undone in reverse order and the result is Err(Transaction.Failure). Active tasks receive the signal and must handle cancellation themselves.

<Acc, E, EUndo>(transaction) => Deferred<Result<Failure<Aborted | E, EUndo>, Acc>>

Transaction.step for configuring transactional steps with compensating undo actions.

A transaction with no input is run as Transaction.run()(transaction). Pass undefined as the input when such a transaction also needs run options: Transaction.run(undefined, { signal })(transaction).

const outcome = await Transaction.run(orderInput)(checkoutTransaction);

<In>(input, options?): <Acc, E, EUndo>(transaction) => Deferred<Result<Failure<Aborted | E, EUndo>, Acc>>

Starts a Transaction and returns a deferred result.

Steps run sequentially. If all steps succeed, returns Ok(Acc) containing all step outputs. If a step returns an error or cancellation is observed before a step starts, completed steps with undo actions are undone in reverse order and the result is Err(Transaction.Failure). Active tasks receive the signal and must handle cancellation themselves.

In

In

RunOptions<unknown, unknown>

<Acc, E, EUndo>(transaction) => Deferred<Result<Failure<Aborted | E, EUndo>, Acc>>

Transaction.step for configuring transactional steps with compensating undo actions.

A transaction with no input is run as Transaction.run()(transaction). Pass undefined as the input when such a transaction also needs run options: Transaction.run(undefined, { signal })(transaction).

const outcome = await Transaction.run(orderInput)(checkoutTransaction);

Transaction.step for configuring transactional steps with compensating undo actions.

const outcome = await Transaction.run(orderInput, { signal })(checkout);

step: {<Id, Input, E, Out, EUndo>(id, run, undo?): Step<Id, Input, E, Out, EUndo, Record<never, never>>; <Id, D, Input, E, Out, EUndo>(id, deps, run, undo?): Step<Id, Input, E, Out, EUndo, D>; }

Defines a reusable step with optional named dependencies and compensation.

The step receives its run input in ctx and declared dependency outputs in deps. An optional undo action can reverse external mutations if a later step fails.

<Id, Input, E, Out, EUndo>(id, run, undo?): Step<Id, Input, E, Out, EUndo, Record<never, never>>

Creates a reusable step with optional dependencies and optional compensation.

Id extends string

Input = void

E = never

Out = never

EUndo = never

Id extends "initial" ? never : Id

StepRun<Record<never, never>, Input, E, Out>

StepUndo<Record<never, never>, Input, Out, EUndo>

Step<Id, Input, E, Out, EUndo, Record<never, never>>

<Id, D, Input, E, Out, EUndo>(id, deps, run, undo?): Step<Id, Input, E, Out, EUndo, D>

Creates a reusable step with optional dependencies and optional compensation.

Id extends string

D extends Record<string, AnyStepInternal | undefined> = Record<never, never>

Input = void

E = never

Out = never

EUndo = never

Id extends "initial" ? never : Id

D

StepRun<D, Input, E, Out>

StepUndo<D, Input, Out, EUndo>

Step<Id, Input, E, Out, EUndo, D>

Transaction.run for executing the compiled transaction.

const step = Transaction.stepFactory<OrderInput>();
const reserve = step(
  "inventory",
  ({ ctx }) => reserveInventory(ctx.input.sku),
  ({ ctx }) => releaseInventory(ctx.output.id),
);

stepFactory: <Input>() => StepFactory<Input>

Creates a step constructor with a shared input type.

Input

StepFactory<Input>

const step = Transaction.stepFactory<Order>();
const reserve = step("reserve", ({ ctx }) => reserveStock(ctx.input.sku));