Interface IdGeneratorDecorator

The decorator idGenerator makes, which TypeScript calls once, with the method it marks, when the class is defined.

import assert from "node:assert/strict";
import { type DataBag, dataBag } from "itinera/journey";
import { type Outcome, Step, step } from "itinera/step";
import { idGenerator, withStep, Workflow, workflow } from "itinera/workflow";
import { integer } from "itinera/value";

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

@workflow({ name: "orders" })
@withStep(Ship, { name: "ship" })
class Orders extends Workflow {
constructor(readonly shop: string) {
super();
}

@idGenerator()
orderId(@dataBag() data: DataBag): string {
const number = data.read("number", integer).option();
return `${this.shop}-${number.map(String).unwrapOr("unnumbered")}`;
}
}

const orders = Orders.build("corner");

assert.equal(orders.instance({ number: 7 }).journeyId, "corner-7");
assert.equal(orders.instance().journeyId, "corner-unnumbered");
  • Marks the method key of a workflow class, given its prototype.

    Type Parameters

    • M extends (dataBag: DataBag) => string

      The type of the method, which takes nothing or the data bag and returns the journey ID.

    Parameters

    • prototype: Workflow
    • key: string | symbol
    • method: TypedPropertyDescriptor<M>

    Returns void