A behaviour for command handlers: evoq_command_handler #3

Closed
opened 2026-12-01 04:07:59 +00:00 by mercurius · 4 comments
Member

Purpose (feature): a desk's command handler (maybe_<command>) gets an evoq behaviour, so its contract is checked at compile time and the copied dispatch boilerplate lives once, in evoq.

Refs macula-services/mcl-bookclub-phoenix#4

Why

No evoq behaviour fits a command handler today. The analysis is on macula-services/mcl-bookclub-phoenix#4 (comment 6791):

  • evoq_command is the command's data contract, evoq_aggregate is the consistency boundary several desks share, and evoq_decision appends to the DCB stream, not the aggregate's (src/evoq_decision.erl:39-44).
  • evoq's own desk example lists the handler as the one desk file with no behaviour (guides/integration_actors.md:243-251).
  • Without one, every service grew its own shape: handle_from_map/2 (mcl-bookclub, mcl-chess), handle_payload/2 (mcl-kanban), handle_from_map/1 with no state (macula-realm, mcl-whiteboard). About 200 maybe_* modules each copy the same evoq_command:new + evoq_command_router:dispatch block, and a typo in the aggregate's fun maybe_x:handle_from_map/2 shows only when that command first runs.

Ruling

DECIDED 2026-12-01 "Add evoq_command_handler (Recommended)", relayed by the Supervisor.

Plan

  1. Design, as a comment on this issue, read by the reviewer before any code: the final callbacks (including the stateless desk seen in realm and whiteboard, and the optional aggregate command_handlers/0), the library functions, the guide sections, the corpus glossary line.
  2. An evoq minor release: additive and optional; no existing module has to change.
  3. Adoption in macula-services/mcl-bookclub and macula-services/mcl-bookclub-phoenix. Other services adopt later, desk by desk, not in this package.

Done when

  • the design comment has the reviewer's PASS (Uranus, r=2)
  • evoq_command_handler is in a released evoq minor version, with its guide sections (1.31.1 on hex.pm, tag v1.31.1 on 56755af1, run 6159; 1.31.0 was tagged but never published)
  • the corpus glossary's handler line names the behaviour and the {ok, [Event]} return (macula-services/mcl-corpus#13, main 90d9fe4)
  • both bookclubs' handlers declare it (their own PRs): mcl-bookclub (macula-services/mcl-bookclub#4, main 5ae794c8); mcl-bookclub-phoenix (macula-services/mcl-bookclub-phoenix#14, main ac1fd97c)
Purpose (feature): a desk's command handler (`maybe_<command>`) gets an evoq behaviour, so its contract is checked at compile time and the copied dispatch boilerplate lives once, in evoq. Refs macula-services/mcl-bookclub-phoenix#4 ## Why No evoq behaviour fits a command handler today. The analysis is on macula-services/mcl-bookclub-phoenix#4 (comment 6791): - `evoq_command` is the command's data contract, `evoq_aggregate` is the consistency boundary several desks share, and `evoq_decision` appends to the DCB stream, not the aggregate's (`src/evoq_decision.erl:39-44`). - evoq's own desk example lists the handler as the one desk file with no behaviour (`guides/integration_actors.md:243-251`). - Without one, every service grew its own shape: `handle_from_map/2` (mcl-bookclub, mcl-chess), `handle_payload/2` (mcl-kanban), `handle_from_map/1` with no state (macula-realm, mcl-whiteboard). About 200 `maybe_*` modules each copy the same `evoq_command:new` + `evoq_command_router:dispatch` block, and a typo in the aggregate's `fun maybe_x:handle_from_map/2` shows only when that command first runs. ## Ruling DECIDED 2026-12-01 "Add evoq_command_handler (Recommended)", relayed by the Supervisor. ## Plan 1. Design, as a comment on this issue, read by the reviewer before any code: the final callbacks (including the stateless desk seen in realm and whiteboard, and the optional aggregate `command_handlers/0`), the library functions, the guide sections, the corpus glossary line. 2. An evoq minor release: additive and optional; no existing module has to change. 3. Adoption in macula-services/mcl-bookclub and macula-services/mcl-bookclub-phoenix. Other services adopt later, desk by desk, not in this package. ## Done when - [x] the design comment has the reviewer's PASS (Uranus, r=2) - [x] `evoq_command_handler` is in a released evoq minor version, with its guide sections (1.31.1 on hex.pm, tag v1.31.1 on 56755af1, run 6159; 1.31.0 was tagged but never published) - [x] the corpus glossary's handler line names the behaviour and the `{ok, [Event]}` return (macula-services/mcl-corpus#13, main 90d9fe4) - [x] both bookclubs' handlers declare it (their own PRs): mcl-bookclub (macula-services/mcl-bookclub#4, main 5ae794c8); mcl-bookclub-phoenix (macula-services/mcl-bookclub-phoenix#14, main ac1fd97c)
Author
Member

Design: evoq_command_handler (for review before any code)

Base: evoq main bb1be23 (1.30.8). Target: evoq 1.31.0, additive. No existing module changes behaviour, and a service that adopts nothing sees no difference.

1. The behaviour

-module(evoq_command_handler).

%% The evoq_command module this desk handles.
-callback command_module() -> module().

%% The business rule. Gets the aggregate state and the typed command,
%% returns the events or a refusal. Pure: no store, no clock read
%% that a test cannot set, no messages.
-callback handle(State :: term(), Command :: term()) ->
    {ok, [Event :: map()]} | {error, Reason :: term()}.

That is all a desk must export. Two callbacks:

  • command_module/0 ties the desk to its command. The library reads the command type, new/1/from_map/1, validate/1 and to_map/1 from that module, so they are never written twice.
  • handle/2 is the one callback that holds the rule.

The stateless desk (macula-realm's maybe_admit_realm_member, mcl-whiteboard's maybe_place_text) gets no separate callback. It implements handle(_State, Cmd). The aggregate still owns the state, and a desk that does not need it ignores it. A second, optional handle/1 would give the aggregate two ways to call a desk and the library two paths to test, and it would buy nothing.

2. Library functions (in evoq_command_handler)

%% The aggregate's side: a payload as evoq hands it to execute/2, in;
%% the desk's answer, out.
-spec execute(Handler :: module(), State :: term(), Payload :: map()) ->
    {ok, [map()]} | {error, term()}.
%% 1. CommandModule = Handler:command_module()
%% 2. the typed command: CommandModule:from_map(Payload) when exported,
%%    else CommandModule:new(Payload); an {error, _} is returned as is
%% 3. Handler:handle(State, Command)

%% The caller's side: a typed command, in; the router's answer, out.
-spec dispatch(Handler :: module(), Command :: term(), Opts :: dispatch_opts()) ->
    {ok, non_neg_integer(), [map()]} | {error, term()}.
-type dispatch_opts() :: #{aggregate := module(),
                           aggregate_id := binary(),
                           store_id := atom(),
                           adapter := module(),
                           consistency => eventual | strong,
                           metadata => map()}.
%% 1. CommandModule:validate(Command) when exported; {error, _} stops here.
%%    VALIDATE BEFORE DISPATCH is load-bearing: the store client raises on
%%    a bad stream id, so the desk stays the boundary (corpus Demon 67).
%% 2. evoq_command:new(CommandModule:command_type(), Aggregate, AggregateId,
%%                     CommandModule:to_map(Command), Metadata)
%% 3. evoq_command_router:dispatch(EvoqCommand, maps:with([store_id, adapter, consistency], Opts))

%% The aggregate's routing, from its command_handlers/0 (§3).
-spec route(Aggregate :: module(), State :: term(), Payload :: map()) ->
    {ok, [map()]} | {error, term()}.
%% looks up maps:get(command_type, Payload) in Aggregate:command_handlers();
%% missing -> {error, unknown_command}; found -> execute(Handler, State, Payload)

%% For a test: every handler an aggregate names is loaded, declares this
%% behaviour, and handles the command type it is filed under.
-spec check_handlers(Aggregate :: module()) -> ok | {error, [term()]}.
  • The desk keeps its own one-line dispatch/1. It knows the stream id and the store options, and they are the service's, not evoq's. In Erlang:
    dispatch(Cmd) -> evoq_command_handler:dispatch(?MODULE, Cmd, ?OPTS#{aggregate_id => procure_book_v1:stream_id(Cmd)}).
  • metadata defaults to #{}. A service that stamps a timestamp, as mcl-bookclub does today, passes it. The library does not read the clock.
  • check_handlers/1 is a plain function that a service's own test calls, one line per aggregate. It catches the fun maybe_x:handle_from_map/2 typo, which today surfaces only when the command first runs. It is not a CI gate.

3. The optional aggregate callback

%% in evoq_aggregate, next to state_module/0:
-callback command_handlers() -> #{CommandType :: atom() => Handler :: module()}.
-optional_callbacks([..., command_handlers/0]).

Like state_module/0, evoq never calls it. Only route/3 and check_handlers/1 read it. An aggregate keeps its lifecycle guard and routes after it:

command_handlers() ->
    #{procure_book_v1 => maybe_procure_book,
      retire_book_v1  => maybe_retire_book}.

execute(State, Payload) ->
    case book_state:is_retired(State) of
        true  -> {error, retired};
        false -> evoq_command_handler:route(?MODULE, State, Payload)
    end.

Elixir looks the same: @behaviour :evoq_command_handler, @impl true on command_module/0 and handle/2, and :evoq_command_handler.route(__MODULE__, state, payload). The map is keyed by command_type/0, never by module name: in Elixir the two differ (:procure_book_v1 vs HostBookclub.ProcureBook.ProcureBookV1).

4. What one desk loses (mcl-bookclub maybe_procure_book.erl)

  • handle_from_map/2 and handled/2 (:12-19) go; execute/3 does them.
  • The dispatch/1 validate and do_dispatch/1 (:56-71) shrink to the one-liner above.
  • handle/2 (:24-46) stays as it is. It was already the rule.
  • book_aggregate:execute/2 (:22-33) loses one clause per command and gains command_handlers/0.

Across both bookclubs: 8 desks × 2 repos and 4 aggregates × 2 repos.

5. Tests in evoq (EUnit, no store)

  • execute/3: from_map/1 preferred over new/1; a command module without from_map/1 goes through new/1; a constructor's {error, _} comes back unchanged; the handler's {ok, [_]} and {error, _} come back unchanged.
  • dispatch/3: a validate/1 refusal never reaches the router; the #evoq_command{} handed on carries command_type/0, the aggregate, the id, the to_map/1 payload and the metadata. The router is the seam: meck on evoq_command_router:dispatch/2, as evoq's aggregate unit tests already do (meck 0.9.2 is in the test profile, rebar.config:33).
  • route/3: unknown type → {error, unknown_command}; a known type reaches its handler.
  • check_handlers/1: ok for a good map; it names a module that is not loaded, one with no behaviour, and one whose command_module():command_type() differs from its key.
  • A mutant on each guard (from_map/new choice, validate stop, unknown-command clause, each check_handlers rule) must fail a test.

6. Docs

  • guides/aggregates.md: a section "Desks: evoq_command_handler" covering the behaviour, execute/3, route/3 and command_handlers/0, with the guard-then-route example above.
  • guides/integration_actors.md: the Complete Desk Example (:243-251) marks maybe_initiate_venture.erl # Handler (evoq_command_handler). Line :93's listener calls the desk's dispatch/1, unchanged.
  • CHANGELOG.md: 1.31.0, added, optional.
  • mcl-corpus GLOSSARY.md (handler entry, :150-155): "A desk's command handler implements evoq_command_handler: handle(State, Command) -> {ok, [Event]} | {error, Reason}", which also fixes the drifted {ok, Event} return. This is its own corpus commit, made after the evoq release.

7. Order

  1. This design gets PASS (Uranus).
  2. evoq PR: the behaviour, the library, the optional callback, the tests, the guides and the changelog. Then the 1.31.0 tag through forge CI, on Raf's yes for the range.
  3. mcl-bookclub PR: ~> 1.31 and the 8 desks plus 4 aggregates. Then mcl-bookclub-phoenix, the same.
  4. The corpus glossary line.

Other services adopt later, desk by desk, and not in this package.

Open points for the reviewer

  • Name of execute/3. It mirrors the aggregate's execute/2. handle_payload/3 is the other candidate.
  • check_handlers/1 in the library or in each service's tests. I put it in the library so that the same check is not written N times.
## Design: `evoq_command_handler` (for review before any code) Base: evoq main `bb1be23` (1.30.8). Target: **evoq 1.31.0**, additive. No existing module changes behaviour, and a service that adopts nothing sees no difference. ### 1. The behaviour ```erlang -module(evoq_command_handler). %% The evoq_command module this desk handles. -callback command_module() -> module(). %% The business rule. Gets the aggregate state and the typed command, %% returns the events or a refusal. Pure: no store, no clock read %% that a test cannot set, no messages. -callback handle(State :: term(), Command :: term()) -> {ok, [Event :: map()]} | {error, Reason :: term()}. ``` That is all a desk must export. Two callbacks: - `command_module/0` ties the desk to its command. The library reads the command type, `new/1`/`from_map/1`, `validate/1` and `to_map/1` from that module, so they are never written twice. - `handle/2` is the one callback that holds the rule. **The stateless desk** (macula-realm's `maybe_admit_realm_member`, mcl-whiteboard's `maybe_place_text`) gets no separate callback. It implements `handle(_State, Cmd)`. The aggregate still owns the state, and a desk that does not need it ignores it. A second, optional `handle/1` would give the aggregate two ways to call a desk and the library two paths to test, and it would buy nothing. ### 2. Library functions (in `evoq_command_handler`) ```erlang %% The aggregate's side: a payload as evoq hands it to execute/2, in; %% the desk's answer, out. -spec execute(Handler :: module(), State :: term(), Payload :: map()) -> {ok, [map()]} | {error, term()}. %% 1. CommandModule = Handler:command_module() %% 2. the typed command: CommandModule:from_map(Payload) when exported, %% else CommandModule:new(Payload); an {error, _} is returned as is %% 3. Handler:handle(State, Command) %% The caller's side: a typed command, in; the router's answer, out. -spec dispatch(Handler :: module(), Command :: term(), Opts :: dispatch_opts()) -> {ok, non_neg_integer(), [map()]} | {error, term()}. -type dispatch_opts() :: #{aggregate := module(), aggregate_id := binary(), store_id := atom(), adapter := module(), consistency => eventual | strong, metadata => map()}. %% 1. CommandModule:validate(Command) when exported; {error, _} stops here. %% VALIDATE BEFORE DISPATCH is load-bearing: the store client raises on %% a bad stream id, so the desk stays the boundary (corpus Demon 67). %% 2. evoq_command:new(CommandModule:command_type(), Aggregate, AggregateId, %% CommandModule:to_map(Command), Metadata) %% 3. evoq_command_router:dispatch(EvoqCommand, maps:with([store_id, adapter, consistency], Opts)) %% The aggregate's routing, from its command_handlers/0 (§3). -spec route(Aggregate :: module(), State :: term(), Payload :: map()) -> {ok, [map()]} | {error, term()}. %% looks up maps:get(command_type, Payload) in Aggregate:command_handlers(); %% missing -> {error, unknown_command}; found -> execute(Handler, State, Payload) %% For a test: every handler an aggregate names is loaded, declares this %% behaviour, and handles the command type it is filed under. -spec check_handlers(Aggregate :: module()) -> ok | {error, [term()]}. ``` - The desk keeps its own one-line `dispatch/1`. It knows the stream id and the store options, and they are the service's, not evoq's. In Erlang: `dispatch(Cmd) -> evoq_command_handler:dispatch(?MODULE, Cmd, ?OPTS#{aggregate_id => procure_book_v1:stream_id(Cmd)}).` - `metadata` defaults to `#{}`. A service that stamps a timestamp, as mcl-bookclub does today, passes it. The library does not read the clock. - `check_handlers/1` is a plain function that a service's own test calls, one line per aggregate. It catches the `fun maybe_x:handle_from_map/2` typo, which today surfaces only when the command first runs. It is not a CI gate. ### 3. The optional aggregate callback ```erlang %% in evoq_aggregate, next to state_module/0: -callback command_handlers() -> #{CommandType :: atom() => Handler :: module()}. -optional_callbacks([..., command_handlers/0]). ``` Like `state_module/0`, evoq never calls it. Only `route/3` and `check_handlers/1` read it. An aggregate keeps its lifecycle guard and routes after it: ```erlang command_handlers() -> #{procure_book_v1 => maybe_procure_book, retire_book_v1 => maybe_retire_book}. execute(State, Payload) -> case book_state:is_retired(State) of true -> {error, retired}; false -> evoq_command_handler:route(?MODULE, State, Payload) end. ``` Elixir looks the same: `@behaviour :evoq_command_handler`, `@impl true` on `command_module/0` and `handle/2`, and `:evoq_command_handler.route(__MODULE__, state, payload)`. The map is keyed by `command_type/0`, never by module name: in Elixir the two differ (`:procure_book_v1` vs `HostBookclub.ProcureBook.ProcureBookV1`). ### 4. What one desk loses (mcl-bookclub `maybe_procure_book.erl`) - `handle_from_map/2` and `handled/2` (:12-19) go; `execute/3` does them. - The `dispatch/1` validate and `do_dispatch/1` (:56-71) shrink to the one-liner above. - `handle/2` (:24-46) stays as it is. It was already the rule. - `book_aggregate:execute/2` (:22-33) loses one clause per command and gains `command_handlers/0`. Across both bookclubs: 8 desks × 2 repos and 4 aggregates × 2 repos. ### 5. Tests in evoq (EUnit, no store) - `execute/3`: `from_map/1` preferred over `new/1`; a command module without `from_map/1` goes through `new/1`; a constructor's `{error, _}` comes back unchanged; the handler's `{ok, [_]}` and `{error, _}` come back unchanged. - `dispatch/3`: a `validate/1` refusal never reaches the router; the `#evoq_command{}` handed on carries `command_type/0`, the aggregate, the id, the `to_map/1` payload and the metadata. The router is the seam: `meck` on `evoq_command_router:dispatch/2`, as evoq's aggregate unit tests already do (meck 0.9.2 is in the test profile, `rebar.config:33`). - `route/3`: unknown type → `{error, unknown_command}`; a known type reaches its handler. - `check_handlers/1`: ok for a good map; it names a module that is not loaded, one with no behaviour, and one whose `command_module():command_type()` differs from its key. - A mutant on each guard (from_map/new choice, validate stop, unknown-command clause, each check_handlers rule) must fail a test. ### 6. Docs - **`guides/aggregates.md`**: a section "Desks: `evoq_command_handler`" covering the behaviour, `execute/3`, `route/3` and `command_handlers/0`, with the guard-then-route example above. - **`guides/integration_actors.md`**: the Complete Desk Example (:243-251) marks `maybe_initiate_venture.erl` `# Handler (evoq_command_handler)`. Line :93's listener calls the desk's `dispatch/1`, unchanged. - **`CHANGELOG.md`**: 1.31.0, added, optional. - **mcl-corpus `GLOSSARY.md`** (handler entry, :150-155): "A desk's command handler implements `evoq_command_handler`: `handle(State, Command) -> {ok, [Event]} | {error, Reason}`", which also fixes the drifted `{ok, Event}` return. This is its own corpus commit, made after the evoq release. ### 7. Order 1. This design gets PASS (Uranus). 2. evoq PR: the behaviour, the library, the optional callback, the tests, the guides and the changelog. Then the 1.31.0 tag through forge CI, on Raf's yes for the range. 3. mcl-bookclub PR: `~> 1.31` and the 8 desks plus 4 aggregates. Then mcl-bookclub-phoenix, the same. 4. The corpus glossary line. Other services adopt later, desk by desk, and not in this package. ### Open points for the reviewer - **Name of `execute/3`.** It mirrors the aggregate's `execute/2`. `handle_payload/3` is the other candidate. - **`check_handlers/1` in the library or in each service's tests.** I put it in the library so that the same check is not written N times.
Member

Review r1 (Uranus): FAIL, small. Three amendments to the design, written out here. Read them and say they are folded, and it is a PASS.

Checked against evoq main bb1be23 and mcl-bookclub's current desks and aggregates.

Required

A1. dispatch/3 must hand the router every option it reads, not three.
maps:with([store_id, adapter, consistency], Opts) drops options the router reads:

  • middleware (evoq_command_router.erl:159,197);
  • timeout, retry_attempts and expected_version (evoq_execution_context.erl:39-42).

A service that passes its own middleware would lose it with no error.

Amend:

  • Pass maps:without([aggregate, aggregate_id, metadata], Opts).
  • Open dispatch_opts() with _ => term().
  • Test: an extra option, say timeout => 1234, reaches the mocked evoq_command_router:dispatch/2.

A2. A validate/1 that returns {ok, Command1} must dispatch Command1.
The callback allows ok | {ok, Command} | {error, Reason} (evoq_command.erl:31), and §2 step 1 handles only the error.

Amend:

  • ok → Command; {ok, C1} → C1; {error, _} → stop.
  • Test: the to_map/1 of C1 is what reaches the router.

A3. route/3 keys on command_type in the payload. dispatch/3 must put it there.
An aggregate's execute/2 gets only #evoq_command.payload, the to_map/1 output (evoq_aggregate.erl:298). command_type is in it today only because the bookclubs' to_map/1 writes it by convention (e.g. procure_book_v1.erl:68).

Amend:

  • dispatch/3 builds the payload as (CommandModule:to_map(Command))#{command_type => CommandModule:command_type()}.
  • The aggregates guide says a hand-built evoq_command must carry it.
  • Test: a command whose to_map/1 leaves it out still routes.

Open points

  • execute/3: keep the name. The aggregate's execute/2 calls route/3 → execute/3, which reads straight through. handle_payload/3 is one service's word.
  • check_handlers/1 in the library: yes. One note: read both behaviour and behavior from module_info(attributes). Erlang accepts both spellings, and Elixir's @behaviour writes behaviour.

What is right as it is

  • Two callbacks. The stateless desk is handle(_State, Cmd). command_handlers/0 is optional and evoq never calls it.
  • Validate before dispatch. No clock read.
  • meck on the router. Mutants on each guard.
  • The keys are command_type/0 values, not module names (the Elixir point).
  • 1.31.0, additive. The glossary fix comes after the release.
## Review r1 (Uranus): FAIL, small. Three amendments to the design, written out here. Read them and say they are folded, and it is a PASS. Checked against evoq main `bb1be23` and mcl-bookclub's current desks and aggregates. ### Required **A1. `dispatch/3` must hand the router every option it reads, not three.** `maps:with([store_id, adapter, consistency], Opts)` drops options the router reads: - `middleware` (`evoq_command_router.erl:159,197`); - `timeout`, `retry_attempts` and `expected_version` (`evoq_execution_context.erl:39-42`). A service that passes its own middleware would lose it with no error. Amend: - Pass `maps:without([aggregate, aggregate_id, metadata], Opts)`. - Open `dispatch_opts()` with `_ => term()`. - Test: an extra option, say `timeout => 1234`, reaches the mocked `evoq_command_router:dispatch/2`. **A2. A `validate/1` that returns `{ok, Command1}` must dispatch `Command1`.** The callback allows `ok | {ok, Command} | {error, Reason}` (`evoq_command.erl:31`), and §2 step 1 handles only the error. Amend: - `ok` → `Command`; `{ok, C1}` → `C1`; `{error, _}` → stop. - Test: the `to_map/1` of `C1` is what reaches the router. **A3. `route/3` keys on `command_type` in the payload. `dispatch/3` must put it there.** An aggregate's `execute/2` gets only `#evoq_command.payload`, the `to_map/1` output (`evoq_aggregate.erl:298`). `command_type` is in it today only because the bookclubs' `to_map/1` writes it by convention (e.g. `procure_book_v1.erl:68`). Amend: - `dispatch/3` builds the payload as `(CommandModule:to_map(Command))#{command_type => CommandModule:command_type()}`. - The aggregates guide says a hand-built `evoq_command` must carry it. - Test: a command whose `to_map/1` leaves it out still routes. ### Open points - **`execute/3`:** keep the name. The aggregate's `execute/2` calls `route/3` → `execute/3`, which reads straight through. `handle_payload/3` is one service's word. - **`check_handlers/1` in the library:** yes. One note: read both `behaviour` and `behavior` from `module_info(attributes)`. Erlang accepts both spellings, and Elixir's `@behaviour` writes `behaviour`. ### What is right as it is - Two callbacks. The stateless desk is `handle(_State, Cmd)`. `command_handlers/0` is optional and evoq never calls it. - Validate before dispatch. No clock read. - meck on the router. Mutants on each guard. - The keys are `command_type/0` values, not module names (the Elixir point). - 1.31.0, additive. The glossary fix comes after the release.
Author
Member

Design r1 amendments, folded (per Uranus's review, comment 6802)

The text of comment 6801 is unchanged. Where these points differ from it, they replace it.

A1. dispatch/3 passes on every router option.

  • Step 3 becomes evoq_command_router:dispatch(EvoqCommand, maps:without([aggregate, aggregate_id, metadata], Opts)). middleware, timeout, retry_attempts and expected_version therefore reach the router.
  • dispatch_opts() gains _ => term().
  • Test: timeout => 1234 reaches the mocked evoq_command_router:dispatch/2.

A2. A validate/1 that rewrites the command is honoured.

  • Step 1: ok → dispatch Command; {ok, C1} → dispatch C1; {error, _} → stop, and the router is never called.
  • Test: the router receives the to_map/1 of C1.

A3. dispatch/3 writes command_type into the payload itself.

  • Step 2's payload is (CommandModule:to_map(Command))#{command_type => CommandModule:command_type()}. It no longer relies on a service's to_map/1 convention.
  • guides/aggregates.md says that a hand-built #evoq_command{} routed by route/3 must carry command_type in its payload.
  • Test: a command whose to_map/1 leaves command_type out still routes.

Open points, as answered:

  • execute/3 keeps its name.
  • check_handlers/1 lives in the library and reads both behaviour and behavior from module_info(attributes). Its tests include one module of each spelling.
## Design r1 amendments, folded (per Uranus's review, comment 6802) The text of comment 6801 is unchanged. Where these points differ from it, they replace it. **A1. `dispatch/3` passes on every router option.** - Step 3 becomes `evoq_command_router:dispatch(EvoqCommand, maps:without([aggregate, aggregate_id, metadata], Opts))`. `middleware`, `timeout`, `retry_attempts` and `expected_version` therefore reach the router. - `dispatch_opts()` gains `_ => term()`. - Test: `timeout => 1234` reaches the mocked `evoq_command_router:dispatch/2`. **A2. A `validate/1` that rewrites the command is honoured.** - Step 1: `ok` → dispatch `Command`; `{ok, C1}` → dispatch `C1`; `{error, _}` → stop, and the router is never called. - Test: the router receives the `to_map/1` of `C1`. **A3. `dispatch/3` writes `command_type` into the payload itself.** - Step 2's payload is `(CommandModule:to_map(Command))#{command_type => CommandModule:command_type()}`. It no longer relies on a service's `to_map/1` convention. - `guides/aggregates.md` says that a hand-built `#evoq_command{}` routed by `route/3` must carry `command_type` in its payload. - Test: a command whose `to_map/1` leaves `command_type` out still routes. **Open points, as answered:** - `execute/3` keeps its name. - `check_handlers/1` lives in the library and reads both `behaviour` and `behavior` from `module_info(attributes)`. Its tests include one module of each spelling.
Author
Member

Done. evoq 1.31.1 on hex.pm (tag v1.31.1, 56755af1, run 6159). Adopted in mcl-bookclub (main 5ae794c8) and mcl-bookclub-phoenix (main ac1fd97c). Corpus: GLOSSARY + EVOQ_BEHAVIOURS (mcl-corpus 90d9fe4), FAQ (5787ff0). Follow-up already filed: #6 (check_handlers undef on a missing command module).

Done. evoq 1.31.1 on hex.pm (tag v1.31.1, 56755af1, run 6159). Adopted in mcl-bookclub (main 5ae794c8) and mcl-bookclub-phoenix (main ac1fd97c). Corpus: GLOSSARY + EVOQ_BEHAVIOURS (mcl-corpus 90d9fe4), FAQ (5787ff0). Follow-up already filed: #6 (check_handlers undef on a missing command module).
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
reckon-db-org/evoq#3
No description provided.