Function input

  • Requests one of the inputs of a step or a rescue step, on a parameter of its constructor: the value under key, from the step's input adapter or the data bag, checked by type. With no type written, the parameter's own type is checked, as the compiler records it, which it can say only for number, string, boolean and a class that serialises itself.

    An input is required unless type is wrapped in optional.

    import assert from "node:assert/strict";
    import { None, type Option, Some } from "itinera/option";
    import {
    input,
    type Outcome,
    Step,
    step,
    type StepClass,
    stepReporter,
    type StepReporter,
    } from "itinera/step";
    import type {
    Answer,
    KeyIn,
    ParameterOf,
    Place,
    ReadFromMetadata,
    RequestDecorator,
    ValueRequestDecorator,
    } from "itinera/workflow";
    import { integer, optional, string } from "itinera/value";

    @step()
    class Charge extends Step {
    constructor(
    @input("amount", integer) readonly amount: number,
    @input("coupon", optional(string)) readonly coupon: Option<string>,
    @input("note") readonly note: string,
    ) {
    super();
    }

    override run(): Outcome {
    return this.succeed();
    }
    }

    type InConstructor = Place<StepClass, undefined>;
    const amount: ParameterOf<typeof Charge, undefined, 0> = 40;
    const given: Answer<typeof integer> = amount;
    const coupon: Answer<ReturnType<typeof optional<typeof string>>> =
    Some("WELCOME");
    const noted: ReadFromMetadata<string> = true;
    const key: KeyIn<InConstructor, typeof Charge> = undefined;
    const amountDecorator: ValueRequestDecorator<typeof integer, InConstructor> =
    input("amount", integer);
    const reporterDecorator: RequestDecorator<
    StepReporter,
    Place<Step, "run">
    > = stepReporter();

    const charge = new Charge(given, None, "first order");
    assert.equal(charge.coupon.unwrapOr("none"), "none");
    assert.equal(coupon.unwrapOr("none"), "WELCOME");
    assert.ok(noted);
    assert.equal(key, undefined);
    assert.equal(typeof amountDecorator, "function");
    assert.equal(typeof reporterDecorator, "function");

    Type Parameters

    Parameters

    • key: string
    • Optionaltype: T

    Returns ValueRequestDecorator<T, Place<StepClass | RescueStepClass, undefined>>

    Error, when the class is defined, if no type is written and the compiler recorded none it can say.