evoq_command behaviour (evoq v1.1.0)

View Source

Command behavior for evoq.

Commands represent intentions to change state. They are: - Imperative (present tense): open_account, deposit_money - Targeted at a specific aggregate - Validated before dispatch

Callbacks

Optional: - validate(Command) -> ok | {error, Reason}

Summary

Functions

Get the aggregate ID.

Get the aggregate type.

Get the command ID.

Get the command metadata.

Get the command payload.

Get the command type.

Validate a command using its module's validate/1 callback.

Callbacks

validate/1

(optional)
-callback validate(Command :: map()) -> ok | {error, Reason :: term()}.

Functions

get_aggregate_id(Evoq_command)

-spec get_aggregate_id(#evoq_command{command_id :: binary() | undefined,
                                     command_type :: atom() | undefined,
                                     aggregate_type :: atom() | undefined,
                                     aggregate_id :: binary() | undefined,
                                     payload :: map(),
                                     metadata :: map(),
                                     causation_id :: binary() | undefined,
                                     correlation_id :: binary() | undefined}) ->
                          binary().

Get the aggregate ID.

get_aggregate_type(Evoq_command)

-spec get_aggregate_type(#evoq_command{command_id :: binary() | undefined,
                                       command_type :: atom() | undefined,
                                       aggregate_type :: atom() | undefined,
                                       aggregate_id :: binary() | undefined,
                                       payload :: map(),
                                       metadata :: map(),
                                       causation_id :: binary() | undefined,
                                       correlation_id :: binary() | undefined}) ->
                            atom().

Get the aggregate type.

get_id(Evoq_command)

-spec get_id(#evoq_command{command_id :: binary() | undefined,
                           command_type :: atom() | undefined,
                           aggregate_type :: atom() | undefined,
                           aggregate_id :: binary() | undefined,
                           payload :: map(),
                           metadata :: map(),
                           causation_id :: binary() | undefined,
                           correlation_id :: binary() | undefined}) ->
                binary().

Get the command ID.

get_metadata(Evoq_command)

-spec get_metadata(#evoq_command{command_id :: binary() | undefined,
                                 command_type :: atom() | undefined,
                                 aggregate_type :: atom() | undefined,
                                 aggregate_id :: binary() | undefined,
                                 payload :: map(),
                                 metadata :: map(),
                                 causation_id :: binary() | undefined,
                                 correlation_id :: binary() | undefined}) ->
                      map().

Get the command metadata.

get_payload(Evoq_command)

-spec get_payload(#evoq_command{command_id :: binary() | undefined,
                                command_type :: atom() | undefined,
                                aggregate_type :: atom() | undefined,
                                aggregate_id :: binary() | undefined,
                                payload :: map(),
                                metadata :: map(),
                                causation_id :: binary() | undefined,
                                correlation_id :: binary() | undefined}) ->
                     map().

Get the command payload.

get_type(Evoq_command)

-spec get_type(#evoq_command{command_id :: binary() | undefined,
                             command_type :: atom() | undefined,
                             aggregate_type :: atom() | undefined,
                             aggregate_id :: binary() | undefined,
                             payload :: map(),
                             metadata :: map(),
                             causation_id :: binary() | undefined,
                             correlation_id :: binary() | undefined}) ->
                  atom().

Get the command type.

new(CommandType, AggregateType, AggregateId, Payload)

-spec new(atom(), atom(), binary(), map()) ->
             #evoq_command{command_id :: binary() | undefined,
                           command_type :: atom() | undefined,
                           aggregate_type :: atom() | undefined,
                           aggregate_id :: binary() | undefined,
                           payload :: map(),
                           metadata :: map(),
                           causation_id :: binary() | undefined,
                           correlation_id :: binary() | undefined}.

Create a new command.

new(CommandType, AggregateType, AggregateId, Payload, Metadata)

-spec new(atom(), atom(), binary(), map(), map()) ->
             #evoq_command{command_id :: binary() | undefined,
                           command_type :: atom() | undefined,
                           aggregate_type :: atom() | undefined,
                           aggregate_id :: binary() | undefined,
                           payload :: map(),
                           metadata :: map(),
                           causation_id :: binary() | undefined,
                           correlation_id :: binary() | undefined}.

Create a new command with metadata.

set_causation_id(CausationId, Evoq_command)

-spec set_causation_id(binary(),
                       #evoq_command{command_id :: binary() | undefined,
                                     command_type :: atom() | undefined,
                                     aggregate_type :: atom() | undefined,
                                     aggregate_id :: binary() | undefined,
                                     payload :: map(),
                                     metadata :: map(),
                                     causation_id :: binary() | undefined,
                                     correlation_id :: binary() | undefined}) ->
                          #evoq_command{command_id :: binary() | undefined,
                                        command_type :: atom() | undefined,
                                        aggregate_type :: atom() | undefined,
                                        aggregate_id :: binary() | undefined,
                                        payload :: map(),
                                        metadata :: map(),
                                        causation_id :: binary() | undefined,
                                        correlation_id :: binary() | undefined}.

Set the causation ID.

set_correlation_id(CorrelationId, Evoq_command)

-spec set_correlation_id(binary(),
                         #evoq_command{command_id :: binary() | undefined,
                                       command_type :: atom() | undefined,
                                       aggregate_type :: atom() | undefined,
                                       aggregate_id :: binary() | undefined,
                                       payload :: map(),
                                       metadata :: map(),
                                       causation_id :: binary() | undefined,
                                       correlation_id :: binary() | undefined}) ->
                            #evoq_command{command_id :: binary() | undefined,
                                          command_type :: atom() | undefined,
                                          aggregate_type :: atom() | undefined,
                                          aggregate_id :: binary() | undefined,
                                          payload :: map(),
                                          metadata :: map(),
                                          causation_id :: binary() | undefined,
                                          correlation_id :: binary() | undefined}.

Set the correlation ID.

validate(Evoq_command)

-spec validate(#evoq_command{command_id :: binary() | undefined,
                             command_type :: atom() | undefined,
                             aggregate_type :: atom() | undefined,
                             aggregate_id :: binary() | undefined,
                             payload :: map(),
                             metadata :: map(),
                             causation_id :: binary() | undefined,
                             correlation_id :: binary() | undefined}) ->
                  ok | {error, term()}.

Validate a command using its module's validate/1 callback.