Interface Endings

Makes each Ending, and gives the outcome it stands for.

import assert from "node:assert/strict";
import { Ending } from "itinera/testing";

assert.deepEqual(Ending.outcome(Ending.success), { kind: "success" });
assert.deepEqual(Ending.outcome(Ending.failure("declined")), {
kind: "failure",
reason: { code: "declined" },
});
assert.deepEqual(Ending.outcome(Ending.skipBecause("nothing to ship")), {
kind: "skipped",
reason: { code: "nothing to ship" },
});

const crashed = Ending.abnormalTermination("gateway down");
assert.equal(crashed.kind, "abnormal termination");
assert.throws(() => Ending.outcome(crashed), { message: "gateway down" });
interface Endings {
    abnormalTermination: (errorMessage: string) => EndsAbnormally;
    failure: (reason: string | Reason) => EndsInFailure;
    outcome: (ending: Ending) => Outcome;
    skip: EndsInSkip;
    skipBecause: (reason: string | Reason) => EndsInSkip;
    success: EndsInSuccess;
}

Index

abnormalTermination: (errorMessage: string) => EndsAbnormally

The attempt terminates abnormally, with an error carrying the message.

failure: (reason: string | Reason) => EndsInFailure

The attempt fails, for a reason, or only its code.

outcome: (ending: Ending) => Outcome

The outcome a step's run returns to end this way, its reason's details captured now, as a step's helpers capture them.

Error carrying the message, for an abnormal termination, as a step's run throws it.

The step skips itself, giving no reason.

skipBecause: (reason: string | Reason) => EndsInSkip

The step skips itself, for a reason, or only its code.

success: EndsInSuccess

The attempt succeeds.