Function workflow

  • Declares a workflow: a class extending Workflow directly, whose steps the @withStep decorators written below this one list, in the order they run. It goes on the top line, above every @withStep.

    It checks the whole declaration when the class is defined, and makes the workflow's descriptor, which build() hands to every workflow object. It compiles only on a class that implements every role its policies request.

    import assert from "node:assert/strict";
    import type { Event } from "itinera/event";
    import type { Reporter } from "itinera/report";
    import { type Outcome, Step, step } from "itinera/step";
    import { withStep, Workflow, workflow } from "itinera/workflow";

    @step()
    class Charge extends Step {
    override run(): Outcome {
    return this.succeed();
    }
    }

    @step()
    class Ship extends Step {
    override run(): Outcome {
    return this.succeed();
    }
    }

    class Audit implements Reporter {
    readonly kinds: string[] = [];

    report(event: Event): void {
    this.kinds.push(event.kind);
    }
    }

    @workflow({ name: "orders", reporters: [Audit] })
    @withStep(Charge, { name: "charge", retryBudget: 1 })
    @withStep(Ship, { name: "ship" })
    class Orders extends Workflow {
    constructor(readonly shop: string) {
    super();
    }
    }

    const orders = Orders.build("corner");
    const instance = orders.instance({
    order: "1",
    price: 40,
    discount: undefined,
    });

    assert.equal(instance.workflow.shop, "corner");
    assert.equal(instance.descriptor.name, "orders");
    assert.deepEqual(
    instance.descriptor.steps().map((described) => described.name),
    ["charge", "ship"],
    );
    assert.deepEqual(
    [...instance.initialData],
    [
    ["order", "1"],
    ["price", 40],
    ],
    );

    Type Parameters

    Parameters

    Returns (target: WorkflowClass<RolesOf<P>>) => void

    Violations, when the class is defined, listing every violation in how the workflow is put together.

    Error, when the class is defined, if the name is empty, if the class does not extend Workflow itself, if it is declared twice, if a policy is not declared with @workflowPolicy, or if a method carries requests but is marked with none of @inputAdapter, @provider and @idGenerator.