Interface Contributor

What a step or a hook contributes data back through: values by key, which reach the data bag only if the step's attempt succeeds, or as soon as the hook returns without failing. itinera makes one for each attempt or call, and closes it when the attempt or the call ends.

import assert from "node:assert/strict";
import { type Contributor, contributor } from "itinera/journey";
import { type Outcome, Step, step } from "itinera/step";

@step()
class Charge extends Step {
override run(@contributor() contributor: Contributor): Outcome {
contributor.contribute("charged", 40);
return this.succeed();
}
}

const contributed = new Map<string, unknown>();
const recording: Contributor = {
contribute: (key, value) => {
contributed.set(key, value);
},
};

new Charge().run(recording);
assert.deepEqual([...contributed], [["charged", 40]]);
interface Contributor {
    contribute<T>(key: string, value: T & AsValue<T>): void;
}

Index

  • Contributes value under key, captured as it is now. The last value contributed under a key in an attempt or a call wins.

    Type Parameters

    • T

    Parameters

    Returns void