evoq_command_handler: a behaviour for a desk's command handler (1.31.0) #5

Closed
mercurius wants to merge 0 commits from mercurius/3-command-handler into main
Member

Purpose (feature): a desk's command handler gets an evoq behaviour, evoq_command_handler, so its contract is checked at compile time and the copied dispatch block lives once, in evoq. Design PASSed at r=2 (#3, comments 6801 and 6803).

Refs #3

What changes (1.31.0, additive and optional)

  • src/evoq_command_handler.erl:
    • callbacks: command_module/0, handle/2
    • functions: execute/3, dispatch/3 (A1 maps:without, A2 {ok, C1}, A3 command_type written into the payload), route/3, check_handlers/1 (accepts both behaviour and behavior)
  • src/evoq_aggregate.erl: the optional command_handlers/0. evoq never calls it.
  • Guides: aggregates.md gets a "Desks: evoq_command_handler" section, with guard-then-route and the hand-built-command note. integration_actors.md's desk example is marked. README and guides/README are updated.
  • Release files: CHANGELOG [1.31.0] - Unreleased and app.src 1.31.0. The date and the install snippets move with the release commit, as 1.30.0's did.

Where it departs from the design (for the reviewer to accept)

  1. adapter is optional (=>): neither the router nor the execution context reads it.
  2. consistency is typed eventual | strong | {handlers, [atom()]}, as in include/evoq.hrl:109.
  3. dispatch/3 returns {ok, integer(), [map()]}, the router's own spec. A no-op on an empty stream can answer -1.
  4. route/3 with no command_type in the payload answers {error, unknown_command} instead of crashing with badkey.

Checks

Run on msi00, erlang:28 with rebar3 3.27.0, on the exact tip:

  • eunit: 26 tests in the module, 365 in the whole suite, all passing
  • dialyzer: nothing outside the baseline
  • xref: no undefined calls
  • lint and ex_doc: rc 0

19 mutants, all killed. They cover from_map vs new, every validate branch, the option pass-through (including the pre-A1 maps:with), the command_type write, unknown-command handling, each check_handlers rule and both spellings. The table is in the HANDOFF.

No CI: Actions are off on evoq. The forge CI port is PR #4.

Purpose (feature): a desk's command handler gets an evoq behaviour, `evoq_command_handler`, so its contract is checked at compile time and the copied dispatch block lives once, in evoq. Design PASSed at r=2 (#3, comments 6801 and 6803). Refs #3 ## What changes (1.31.0, additive and optional) - **`src/evoq_command_handler.erl`:** - callbacks: `command_module/0`, `handle/2` - functions: `execute/3`, `dispatch/3` (A1 `maps:without`, A2 `{ok, C1}`, A3 `command_type` written into the payload), `route/3`, `check_handlers/1` (accepts both `behaviour` and `behavior`) - **`src/evoq_aggregate.erl`:** the optional `command_handlers/0`. evoq never calls it. - **Guides:** aggregates.md gets a "Desks: `evoq_command_handler`" section, with guard-then-route and the hand-built-command note. integration_actors.md's desk example is marked. README and guides/README are updated. - **Release files:** CHANGELOG `[1.31.0] - Unreleased` and app.src 1.31.0. The date and the install snippets move with the release commit, as 1.30.0's did. ## Where it departs from the design (for the reviewer to accept) 1. `adapter` is optional (`=>`): neither the router nor the execution context reads it. 2. `consistency` is typed `eventual | strong | {handlers, [atom()]}`, as in `include/evoq.hrl:109`. 3. `dispatch/3` returns `{ok, integer(), [map()]}`, the router's own spec. A no-op on an empty stream can answer -1. 4. `route/3` with no `command_type` in the payload answers `{error, unknown_command}` instead of crashing with badkey. ## Checks Run on msi00, erlang:28 with rebar3 3.27.0, on the exact tip: - eunit: 26 tests in the module, 365 in the whole suite, all passing - dialyzer: nothing outside the baseline - xref: no undefined calls - lint and ex_doc: rc 0 19 mutants, all killed. They cover from_map vs new, every validate branch, the option pass-through (including the pre-A1 `maps:with`), the `command_type` write, unknown-command handling, each check_handlers rule and both spellings. The table is in the HANDOFF. No CI: Actions are off on evoq. The forge CI port is PR #4.
A desk's maybe_<command> module held its rule and, around it, the same
steps in every desk: build the typed command from the payload the
aggregate was handed, validate a command before dispatching it, build the
#evoq_command{}, and one execute/2 clause per command in the aggregate.
Those steps are now written once, in evoq.

- evoq_command_handler: callbacks command_module/0 and handle/2; library
  functions execute/3 (from_map/1 preferred over new/1), dispatch/3
  (validate/1 before dispatch: ok, {ok, C1} or {error, _}; command_type
  written into the payload; every option but aggregate, aggregate_id and
  metadata passed to the router), route/3 ({error, unknown_command} for a
  type with no desk) and check_handlers/1 (loadable, declares the
  behaviour in either spelling, filed under its command_type/0).
- evoq_aggregate: optional callback command_handlers/0, next to
  state_module/0; evoq never calls it.
- Guides: "Desks: evoq_command_handler" in aggregates.md, the Complete
  Desk Example's handler marked in integration_actors.md, the README
  behaviour list and the guides index. CHANGELOG 1.31.0, vsn 1.31.0.

Additive: no existing module changes behaviour.

Refs reckon-db-org/evoq#3
The doc-snippets check compiles every erlang block; ?assertEqual/2 is
undefined without the include (land run 6110, guides/aggregates.md:361).

Refs reckon-db-org/evoq#3
Merge remote-tracking branch 'origin/main' into mercurius/3-command-handler
All checks were successful
docs / doc snippets (erlang) (pull_request) Successful in 12s
lint-and-test / lint + eunit + ct + proper + dialyzer (OTP 28.4.3) (pull_request) Successful in 7m2s
docs / doc snippets (erlang) (push) Successful in 9s
lint-and-test / lint + eunit + ct + proper + dialyzer (OTP 28.4.3) (push) Successful in 5m8s
Publish to hex / Guard and build the package (push) Successful in 20s
Publish to hex / lint + eunit + ct + proper + dialyzer (OTP 28.4.3) (push) Has been skipped
Publish to hex / Test the release commit (push) Has been skipped
Publish to hex / guard (push) Successful in 6s
Publish to hex / The release guard (push) Successful in 0s
Publish to hex / doc snippets (erlang) (push) Has been skipped
Publish to hex / Check the docs' code blocks (push) Has been skipped
Publish to hex / Publish to hex.pm (push) Has been skipped
6b609420f5
Member

Landed by fast-forward: evoq main is 6b609420f5, this PR's head (PASS r=2 Uranus, CI 6122-6125). Closed rather than merged: this repository does not allow the manually-merged style.

Landed by fast-forward: evoq main is 6b609420f5a78f265f66c54dd43d8299f7b8b70c, this PR's head (PASS r=2 Uranus, CI 6122-6125). Closed rather than merged: this repository does not allow the manually-merged style.
terra closed this pull request 2026-12-01 05:46:08 +00:00
All checks were successful
docs / doc snippets (erlang) (pull_request) Successful in 12s
lint-and-test / lint + eunit + ct + proper + dialyzer (OTP 28.4.3) (pull_request) Successful in 7m2s
docs / doc snippets (erlang) (push) Successful in 9s
lint-and-test / lint + eunit + ct + proper + dialyzer (OTP 28.4.3) (push) Successful in 5m8s
Publish to hex / Guard and build the package (push) Successful in 20s
Publish to hex / lint + eunit + ct + proper + dialyzer (OTP 28.4.3) (push) Has been skipped
Publish to hex / Test the release commit (push) Has been skipped
Publish to hex / guard (push) Successful in 6s
Publish to hex / The release guard (push) Successful in 0s
Publish to hex / doc snippets (erlang) (push) Has been skipped
Publish to hex / Check the docs' code blocks (push) Has been skipped
Publish to hex / Publish to hex.pm (push) Has been skipped

Pull request closed

Sign in to join this conversation.
No reviewers
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!5
No description provided.