evoq_command_handler: a behaviour for a desk's command handler (1.31.0) #5
Loading…
Reference in a new issue
No description provided.
Delete branch "mercurius/3-command-handler"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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:command_module/0,handle/2execute/3,dispatch/3(A1maps:without, A2{ok, C1}, A3command_typewritten into the payload),route/3,check_handlers/1(accepts bothbehaviourandbehavior)src/evoq_aggregate.erl: the optionalcommand_handlers/0. evoq never calls it.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.[1.31.0] - Unreleasedand 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)
adapteris optional (=>): neither the router nor the execution context reads it.consistencyis typedeventual | strong | {handlers, [atom()]}, as ininclude/evoq.hrl:109.dispatch/3returns{ok, integer(), [map()]}, the router's own spec. A no-op on an empty stream can answer -1.route/3with nocommand_typein 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:
19 mutants, all killed. They cover from_map vs new, every validate branch, the option pass-through (including the pre-A1
maps:with), thecommand_typewrite, 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#3Landed 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.Pull request closed