Class AttemptRecord
Methods
input
-
Reads, as the type
typechecks, the value underkeythat the step was built with: an input, or, for a rescue step, a contribution it requested from the failed attempt. It reads as the data bag'sreaddoes: present, absent or of another type.import assert from "node:assert/strict";
import { type Contributor, contributor } from "itinera/journey";
import {
input,
type Outcome,
Step,
step,
stepReporter,
type StepReporter,
} from "itinera/step";
import { Level, RecordingReporter, scripted } from "itinera/testing";
import { integer } from "itinera/value";
import { withStep, Workflow, workflow } from "itinera/workflow";
@step()
class Charge extends Step {
override run(
@contributor() contributor: Contributor,
@stepReporter() reporter: StepReporter,
): Promise<Outcome> {
contributor.contribute("charged", 40);
return reporter.info("charged").then(() => this.succeed());
}
}
@step()
class Ship extends Step {
constructor(@input("charged", integer) readonly charged: number) {
super();
}
override run(): Outcome {
return this.succeed();
}
}
@workflow({ name: "orders" })
@withStep(Charge, { name: "charge", retryBudget: 2 })
@withStep(Ship, { name: "ship" })
class Orders extends Workflow {}
export default (async () => {
const recorder = new RecordingReporter();
const instance = Orders.build().instance({}, { reporters: [recorder] });
const run = await scripted(instance)
.step("charge")
.willFail("declined")
.onRemainingAttempts()
.willContribute("charged", 35)
.willEmit(Level.Warning, "charged less")
.willSucceed()
.andStep("ship")
.willRunForReal()
.ensureAllScripted()
.run();
assert.ok(run.result.isSucceeded());
assert.deepEqual(recorder.path, [
"charge attempt 1 failed: declined",
"charge retrying",
"charge attempt 2 succeeded",
"ship attempt 1 succeeded",
"journey succeeded",
]);
assert.equal(run.step("charge").attempts.length, 2);
const shipped = run.step("ship").attempt(1).unwrap();
assert.equal(shipped.input("charged", integer).option().unwrap(), 35);
})();Type Parameters
- S extends StandardSchemaV1<unknown, unknown>
Parameters
- key: string
- type: S
Returns Read<InferInput<S>>
-
input<S extends StandardSchemaV1<unknown, unknown>>(
key: string,
type: Optional<S>,
): Read<Option<InferInput<S>>>Reads, as the type
typechecks, the value underkeythat the step was built with: an input, or, for a rescue step, a contribution it requested from the failed attempt. It reads as the data bag'sreaddoes: present, absent or of another type.import assert from "node:assert/strict";
import { type Contributor, contributor } from "itinera/journey";
import {
input,
type Outcome,
Step,
step,
stepReporter,
type StepReporter,
} from "itinera/step";
import { Level, RecordingReporter, scripted } from "itinera/testing";
import { integer } from "itinera/value";
import { withStep, Workflow, workflow } from "itinera/workflow";
@step()
class Charge extends Step {
override run(
@contributor() contributor: Contributor,
@stepReporter() reporter: StepReporter,
): Promise<Outcome> {
contributor.contribute("charged", 40);
return reporter.info("charged").then(() => this.succeed());
}
}
@step()
class Ship extends Step {
constructor(@input("charged", integer) readonly charged: number) {
super();
}
override run(): Outcome {
return this.succeed();
}
}
@workflow({ name: "orders" })
@withStep(Charge, { name: "charge", retryBudget: 2 })
@withStep(Ship, { name: "ship" })
class Orders extends Workflow {}
export default (async () => {
const recorder = new RecordingReporter();
const instance = Orders.build().instance({}, { reporters: [recorder] });
const run = await scripted(instance)
.step("charge")
.willFail("declined")
.onRemainingAttempts()
.willContribute("charged", 35)
.willEmit(Level.Warning, "charged less")
.willSucceed()
.andStep("ship")
.willRunForReal()
.ensureAllScripted()
.run();
assert.ok(run.result.isSucceeded());
assert.deepEqual(recorder.path, [
"charge attempt 1 failed: declined",
"charge retrying",
"charge attempt 2 succeeded",
"ship attempt 1 succeeded",
"journey succeeded",
]);
assert.equal(run.step("charge").attempts.length, 2);
const shipped = run.step("ship").attempt(1).unwrap();
assert.equal(shipped.input("charged", integer).option().unwrap(), 35);
})();Type Parameters
- S extends StandardSchemaV1<unknown, unknown>
Returns Read<Option<InferInput<S>>>
What a scripted run records of one attempt: its number, and the values its step was built with. Only itinera makes one.