A reason as a step or a test gives it: its code alone, or a code with a message and details. The details may be any value, an object that serialises itself included, and are captured when the reason is given.
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 }, },});
The type of the details.
Readonly
A short code a program can compare, such as "declined".
"declined"
Optional
Anything else the reason says, as a value.
A message for people.
A reason as a step or a test gives it: its code alone, or a code with a message and details. The details may be any value, an object that serialises itself included, and are captured when the reason is given.