Interface JourneyResult

What running a journey gives: its journey ID and how it ended, its business outcome. Each step's status and the name of the step that failed are not in it, but in the journey's events.

import assert from "node:assert/strict";
import { LocalExecutor } from "itinera/executor";
import { Step } from "itinera/step";
import { Workflow } from "itinera/workflow";

class Charge extends Step {
override run(): never {
throw new Error("gateway down");
}
}

class Orders extends Workflow {}

export default (async () => {
const orders = Orders.builder()
.name("orders")
.step(Charge.builder("charge"))
.build();
const instance = orders.instance(new Map([["order", "A-1"]]));

const result = await new LocalExecutor().run(instance);

assert.equal(result.journeyId, instance.journeyId);
assert.ok(result.isFailed());
assert.deepEqual(result.status.dataBag.keys(), ["order"]);
assert.equal(result.failure?.cause, "abnormal termination");
assert.equal(result.failure.errorMessage, "gateway down");
assert.equal(result.abort, undefined);
})();
interface JourneyResult {
    abort:
        | NotAValue
        | UnexpectedResult
        | RequiredDataMissing
        | WrongType
        | InvalidLifecycle
        | RescueSkipped
        | ReservedMetadataKey
        | (
            StepCouldNotBeBuilt & ({ readonly errorMessage: string; readonly error: unknown; } | { readonly errorMessage?: never; readonly error?: never; })
        )
        | PolicyCouldNotBeBuilt & { error: unknown }
        | HookFailed & { error: unknown }
        | ReporterFailed & { error: unknown }
        | undefined;
    failure: Failure | undefined;
    journeyId: JourneyId;
    status: JourneyStatus;
    isAborted(): this is { status: Aborted };
    isFailed(): this is { status: Failed };
    isSucceeded(): this is { status: Succeeded };
    output<S extends Readonly<Record<string, RequestType>>>(
        shape: S,
    ): Output<S>;
}

Index

abort:
    | NotAValue
    | UnexpectedResult
    | RequiredDataMissing
    | WrongType
    | InvalidLifecycle
    | RescueSkipped
    | ReservedMetadataKey
    | (
        StepCouldNotBeBuilt & ({ readonly errorMessage: string; readonly error: unknown; } | { readonly errorMessage?: never; readonly error?: never; })
    )
    | PolicyCouldNotBeBuilt & { error: unknown }
    | HookFailed & { error: unknown }
    | ReporterFailed & { error: unknown }
    | undefined

Why the journey was aborted, when it was.

Type Declaration

failure: Failure | undefined

Why the journey failed, when it failed.

journeyId: JourneyId

The journey's ID.

How the journey ended.

  • Reads the journey's output from its data bag: under each key of shape, the value its type reads, as DataBag.read reads it, so an Option for a type wrapped in optional, and an instance made by fromValue for a class named with classOf.

    import assert from "node:assert/strict";
    import { LocalExecutor } from "itinera/executor";
    import { OutputError } from "itinera/journey";
    import { None, type Option } from "itinera/option";
    import { Step } from "itinera/step";
    import { Workflow } from "itinera/workflow";
    import { integer, optional, string } from "itinera/value";

    class Charge extends Step {
    override run() {
    return this.succeed();
    }
    }

    class Orders extends Workflow {}

    export default (async () => {
    const orders = Orders.builder()
    .name("orders")
    .step(Charge.builder("charge"))
    .build();
    const instance = orders.instance({ order: "A-1", amount: 1250 });

    const result = await new LocalExecutor().run(instance);

    const receipt: { readonly amount: number; readonly note: Option<string> } =
    result.output({ amount: integer, note: optional(string) });
    assert.equal(receipt.amount, 1250);
    assert.equal(receipt.note, None);

    assert.throws(
    () => result.output({ order: integer }),
    (thrown: unknown) =>
    thrown instanceof OutputError &&
    thrown.problem.kind === "other type" &&
    thrown.problem.key === "order",
    );
    })();

    Type Parameters

    Parameters

    • shape: S

    Returns Output<S>

    OutputError when the journey was aborted, since it has no data bag, or on the first key of shape that holds no value, or a value its type refuses.