Skip to content

Latest commit

 

History

History
85 lines (60 loc) · 3.14 KB

saga.md

File metadata and controls

85 lines (60 loc) · 3.14 KB
id title description
saga
Saga
This document describes API used by sagas.

:::info TypeScript Support

A saga object has an associated TypeScript type:

  • Type Name - Saga
  • Package - @resolve-js/core

:::

A saga's event handler receives an object that provides access to the saga-related API. This API includes the following objects:

Object Name Description
store Provides access to the saga's persistent store (similar to the Read Model store).
sideEffects Provides access to the saga's side effect functions.

In addition to user-defined side effect functions, the SideEffects object contains the following default side effects:

Function Name Description
executeCommand Sends a command with the specified payload to an aggregate.
scheduleCommand Similar to executeCommand, but delays command execution until a specified moment in time.

The sideEffects object's isEnabled field indicates whether or not side effects are enabled for the saga.

executeCommand

Sends a command with the specified payload to an aggregate.

Arguments

Argument Name Description
command Specifies a command object. Refer to the Write Side article for more information.

Example

await sideEffects.executeCommand({
  aggregateName: 'User',
  aggregateId: event.aggregateId,
  type: 'requestConfirmUser',
  payload: event.payload,
})

scheduleCommand

Similar to executeCommand but delays the command's execution until a specified moment in time.

Arguments

Argument Name Description
command Specifies a command object. Refer to the Write Side article for more information.

Example

await sideEffects.scheduleCommand(
  event.timestamp + 1000 * 60 * 60 * 24 * 7,
  {
    aggregateName: 'User',
    aggregateId: event.aggregateId,
    type: 'forgetUser',
    payload: {},
  }
)