---
url: https://node-ts.github.io/bus/api/bus-core/classes/Workflow.md
---
[API reference](../../index.md) / [@node-ts/bus-core](../index.md) / Workflow

# Abstract Class: Workflow\<WorkflowStateType>

Defined in: [packages/bus-core/src/workflow/workflow.ts:274](https://github.com/node-ts/bus/blob/2e6cf65c27833b707ae31ee623cfb6343770f434/packages/bus-core/src/workflow/workflow.ts#L274)

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`](WorkflowState.md) |

## 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](https://github.com/node-ts/bus/blob/2e6cf65c27833b707ae31ee623cfb6343770f434/packages/bus-core/src/workflow/workflow.ts#L281)

Maps the messages the workflow handles to its handler methods

#### Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `mapper` | [`WorkflowMapper`](WorkflowMapper.md)<`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`
