Skip to main content

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 NameDescription
stateThe state object built by the aggregate projection.
commandAn object that contains the incoming command's data.
contextAn object that contains data and functions related to the current operation.

Contextā€‹

The context argument is an object with the following fields:

Field NameDescription
jwtThe JSON Web Token attached to the request.
aggregateVersionThe aggregate version that is a number incremented for each subsequent event with the current aggregateId.
encryptThe user-defined encrypt function.
decryptThe user-defined decrypt function.

This object can also contain additional fields added by middleware.