What one attempt of a step reports when it ends normally: it succeeded, failed or skipped itself. A step makes it with the helpers of its base class, such as this.succeed(), and reports anything abnormal by throwing instead.
this.succeed()
import assert from "node:assert/strict";import { input, type Outcome, Step, step } from "itinera/step";@step()class Charge extends Step { constructor(@input("amount") private readonly amount: number) { super(); } override run(): Outcome { if (this.amount === 0) { return this.skip(); } if (this.amount < 0) { return this.skipBecause("refunds are not charged"); } if (this.amount > 100) { return this.fail({ code: "declined", message: "over the limit", details: { limit: 100 }, }); } return this.succeed(); }}assert.deepEqual(new Charge(40).run(), { kind: "success" });assert.deepEqual(new Charge(0).run(), { kind: "skipped" });assert.deepEqual(new Charge(-5).run(), { kind: "skipped", reason: { code: "refunds are not charged" },});assert.deepEqual(new Charge(140).run(), { kind: "failure", reason: { code: "declined", message: "over the limit", details: { limit: 100 }, },}); Copy
import assert from "node:assert/strict";import { input, type Outcome, Step, step } from "itinera/step";@step()class Charge extends Step { constructor(@input("amount") private readonly amount: number) { super(); } override run(): Outcome { if (this.amount === 0) { return this.skip(); } if (this.amount < 0) { return this.skipBecause("refunds are not charged"); } if (this.amount > 100) { return this.fail({ code: "declined", message: "over the limit", details: { limit: 100 }, }); } return this.succeed(); }}assert.deepEqual(new Charge(40).run(), { kind: "success" });assert.deepEqual(new Charge(0).run(), { kind: "skipped" });assert.deepEqual(new Charge(-5).run(), { kind: "skipped", reason: { code: "refunds are not charged" },});assert.deepEqual(new Charge(140).run(), { kind: "failure", reason: { code: "declined", message: "over the limit", details: { limit: 100 }, },});
What one attempt of a step reports when it ends normally: it succeeded, failed or skipped itself. A step makes it with the helpers of its base class, such as
this.succeed(), and reports anything abnormal by throwing instead.