Interface StepOptions<P>

What a workflow says about one of its steps to @withStep; its builder takes a step builder instead.

import assert from "node:assert/strict";
import { type Provided, provider, service, serviceType } from "itinera/service";
import {
type Outcome,
Step,
step,
type StepName,
stepName,
} from "itinera/step";
import {
inputAdapter,
key,
type Supplied,
withStep,
Workflow,
workflow,
} from "itinera/workflow";

const RECEIPTS = serviceType<string[]>("Receipts");

@step()
class Charge extends Step {
override run(@service("receipts", RECEIPTS) receipts: string[]): Outcome {
receipts.push("charged");
return this.succeed();
}
}

@workflow({ name: "payments" })
@withStep(Charge, {
name: "charge",
retryBudget: 2,
noRetryOnAbnormalTermination: true,
})
class Payments extends Workflow {
@inputAdapter({ steps: ["charge"] })
price(@key() key: string): Supplied {
return this.supply(key.length);
}

@provider(RECEIPTS, { perAttempt: true })
receipts(@stepName() step: StepName): Provided<string[]> {
return this.provide([`receipts of ${step}`]);
}
}

const { descriptor, workflow: payments } = Payments.build().instance();
const [charge] = descriptor.steps();
assert.ok(charge);

assert.equal(descriptor.name, "payments");
assert.equal(charge.name, "charge");
assert.equal(charge.retryBudget, 2);
assert.equal(charge.retryOnAbnormalTermination, false);
assert.ok(charge.build() instanceof Charge);
assert.deepEqual(descriptor.reporters(), []);
assert.deepEqual(descriptor.adapt(payments, charge.name, ["amount"]), {
kind: "supplied",
value: 6,
});
assert.deepEqual(
descriptor.provide(payments, charge.name, "receipts", [charge.name]),
{ instance: ["receipts of charge"] },
);
interface StepOptions<P extends readonly StepPolicyClass[] = readonly []> {
    name: string;
    noRetryOnAbnormalTermination?: boolean;
    policies?: P;
    rescue?: RescueStepClass;
    retryBudget?: number;
}

Type Parameters

  • P extends readonly StepPolicyClass[] = readonly []

    The step policies attached to the step, as a list written in place.

Index

name: string

The step's name: not empty, and unique in its workflow.

noRetryOnAbnormalTermination?: boolean

true to never retry an attempt that ends in an abnormal termination, whatever the retry budget.

policies?: P

The step policies attached to the step, in the order their hooks are looked up, each declared with @stepPolicy. The workflow must implement the roles each of them requests.

The rescue step that runs, as <step name>_rescue, before the step runs again after an attempt that failed, declared with @rescueStep.

retryBudget?: number

How many times the step may be retried after its first attempt, a whole number from 0: 0 when not given.