API reference / @node-ts/bus-core / Workflow
Abstract Class: Workflow<WorkflowStateType>
Defined in: packages/bus-core/src/workflow/workflow.ts:274
A workflow declared as a class. Its handlers are methods, which configureWorkflow maps messages to by name. What each handler takes and returns is checked against the message it's mapped to and the workflow state, so a handler that would fail at runtime doesn't compile.
Example
ts
export class OrderWorkflow extends Workflow<OrderState> {
configureWorkflow(mapper: WorkflowMapper<OrderState, OrderWorkflow>) {
mapper.withState(OrderState).startedBy(OrderPlaced, 'start')
}
start(message: OrderPlaced) {
return { orderId: message.orderId }
}
}Type Parameters
| Type Parameter |
|---|
WorkflowStateType extends WorkflowState |
Constructors
Constructor
ts
new Workflow<WorkflowStateType>(): Workflow<WorkflowStateType>;Returns
Workflow<WorkflowStateType>
Methods
configureWorkflow()
ts
abstract configureWorkflow(mapper): void;Defined in: packages/bus-core/src/workflow/workflow.ts:281
Maps the messages the workflow handles to its handler methods
Parameters
| Parameter | Type | Description |
|---|---|---|
mapper | WorkflowMapper<WorkflowStateType, Workflow<WorkflowStateType>> | Declares the workflow state, and which methods start the workflow or handle messages. Type it with the workflow class, such as WorkflowMapper<OrderState, OrderWorkflow>, so handler names are checked. With any no handler name compiles. |
Returns
void