Command Handler
TypeScript Support
Command handlers are grouped into an Aggregate container object that has an associated TypeScript type:
- Type Name -
Aggregate - Package -
@resolve-js/core
A command handler function has the following structure:
(state, command, context) => {
...
return {
type: 'CommandTypeName',
payload: { ... },
}
}
A command handler implementation receives the following arguments:
| Argument Name | Description |
|---|---|
| state | The state object built by the aggregate projection. |
| command | An object that contains the incoming command's data. |
| context | An object that contains data and functions related to the current operation. |
Contextā
The context argument is an object with the following fields:
| Field Name | Description |
|---|---|
| jwt | The JSON Web Token attached to the request. |
| aggregateVersion | The aggregate version that is a number incremented for each subsequent event with the current aggregateId. |
| encrypt | The user-defined encrypt function. |
| decrypt | The user-defined decrypt function. |
This object can also contain additional fields added by middleware.