A service provider is attached to a step or a rescue step the workflow does not have.
import assert from "node:assert/strict";import { service, serviceType } from "itinera/service";import { type Outcome, Step, step } from "itinera/step";import { key, type Supplied, type Violation, ViolationKind, Violations, withStep, Workflow, workflow,} from "itinera/workflow";@step()class Ship extends Step { override run(): Outcome { return this.succeed(); }}const COURIER = serviceType<{ book(): void }>("Courier");class Deliver extends Step { override run(courier: { book(): void }): Outcome { courier.book(); return this.succeed(); }}class Shipping extends Workflow { pricing(inputKey: string): Supplied { return this.supply(inputKey.length); }}function declareTwoShips(): typeof Workflow { @workflow({ name: "orders" }) @withStep(Ship, { name: "ship" }) @withStep(Ship, { name: "ship" }) class Orders extends Workflow {} return Orders;}assert.throws(declareTwoShips, (error: unknown) => { assert.ok(error instanceof Violations); assert.deepEqual(error.violations, [ { kind: ViolationKind.DuplicateStepName, step: "ship" }, ]); assert.equal(error.message, "duplicate step name: ship"); return true;});assert.throws( () => Shipping.builder() .name("shipping") .step(Deliver.builder("deliver").run(service("courier", COURIER))) .inputAdapter("pricing", { steps: ["pack"] }, key()) .build(), (error: unknown) => { assert.ok(error instanceof Violations); const found: readonly Violation[] = error.violations; assert.deepEqual(found, [ { kind: ViolationKind.InputAdapterForUnknownStep, adapter: "pricing", step: "pack", }, { kind: ViolationKind.ServiceNotProvided, step: "deliver", key: "courier", }, ]); assert.equal( error.message, "input adapter for unknown step: pricing on pack\nservice not provided: courier for deliver", ); return true; },); Copy
import assert from "node:assert/strict";import { service, serviceType } from "itinera/service";import { type Outcome, Step, step } from "itinera/step";import { key, type Supplied, type Violation, ViolationKind, Violations, withStep, Workflow, workflow,} from "itinera/workflow";@step()class Ship extends Step { override run(): Outcome { return this.succeed(); }}const COURIER = serviceType<{ book(): void }>("Courier");class Deliver extends Step { override run(courier: { book(): void }): Outcome { courier.book(); return this.succeed(); }}class Shipping extends Workflow { pricing(inputKey: string): Supplied { return this.supply(inputKey.length); }}function declareTwoShips(): typeof Workflow { @workflow({ name: "orders" }) @withStep(Ship, { name: "ship" }) @withStep(Ship, { name: "ship" }) class Orders extends Workflow {} return Orders;}assert.throws(declareTwoShips, (error: unknown) => { assert.ok(error instanceof Violations); assert.deepEqual(error.violations, [ { kind: ViolationKind.DuplicateStepName, step: "ship" }, ]); assert.equal(error.message, "duplicate step name: ship"); return true;});assert.throws( () => Shipping.builder() .name("shipping") .step(Deliver.builder("deliver").run(service("courier", COURIER))) .inputAdapter("pricing", { steps: ["pack"] }, key()) .build(), (error: unknown) => { assert.ok(error instanceof Violations); const found: readonly Violation[] = error.violations; assert.deepEqual(found, [ { kind: ViolationKind.InputAdapterForUnknownStep, adapter: "pricing", step: "pack", }, { kind: ViolationKind.ServiceNotProvided, step: "deliver", key: "courier", }, ]); assert.equal( error.message, "input adapter for unknown step: pricing on pack\nservice not provided: courier for deliver", ); return true; },);
Readonly
Tells this violation from the others.
The provider.
The name it is attached to, which no step or rescue step has.
A service provider is attached to a step or a rescue step the workflow does not have.