States, snapshots and events carry the evoq contracts (PR 2 of #4) #11
Loading…
Reference in a new issue
No description provided.
Delete branch "mercurius/4-pr2-state-events"
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): phoenix's states, aggregates and events carry the same contracts as mcl-bookclub's:
evoq_state, snapshots, and typed events withfrom_map/1. This is PR 2 of #4 (gap table H.2).Refs #4
What changes
@behaviour :evoq_stateto_map/1/from_map/1(the stream id is required)@type t,@specs, and@moduledoctext instead of@moduledoc falsesnapshot/1/from_snapshot/1, so evoq now snapshots them (evoq_aggregate.erl:757). Until now every load replayed the whole stream. They also get@specs on every callback.from_map/1with E's required keys, a typedt, and@spec/@docon every callback.test/snapshot_test.exs(32): a round trip per state, a snapshot per aggregate, and a load resumed from a snapshot that ends where a full replay endstest/event_map_test.exs(37): a round trip and a missing-key refusal per eventWhere it differs from mcl-bookclub, and why
""and0, E's record andmaps:getdefaults, sofrom_map(%{id => x}) == new(x), as in E. Nothing in phoenix read a nil field.new/1is unchanged.@type t, not@opaque: the handlers read state fields directly. Getters are out of scope.stream_id/1is kept on the aggregates, with@docand@specadded.event_data/1is unchanged: changing it would change behaviour.from_maptests, so those are new.Checks (msi00, ci image)
--warnings-as-errors, credo--strict(633 mods/funs): clean10 mutants, all killed (to_map drops, from_map accepting a missing id, snapshot omissions, from_snapshot not restoring a field, event from_map gaps).
The 4 state modules declare @behaviour :evoq_state and gain to_map/1 and from_map/1 (id required, every other field defaults to the struct), typed @type t and @specs. Their struct defaults move to the Erlang record defaults ("" and 0), so from_map/1 of a bare id is new/1. The 4 aggregates export snapshot/1 and from_snapshot/1 over that map: evoq saves a snapshot only when snapshot/1 is exported, so until now every load replayed the whole stream. The `#` comment headers become @moduledoc text. test/snapshot_test.exs round-trips every state the stream passes through, resumes a load from a snapshot at every point of the history, and pins from_map's refusal. Mirrors mcl-bookclub (0ce055a) apps/host_bookclub/src/: bookclub_state.erl, book_state.erl, member_state.erl, reading_state.erl (to_map/from_map), bookclub_aggregate.erl, book_aggregate.erl, member_aggregate.erl, reading_aggregate.erl (snapshot/from_snapshot). Refs macula-services/mcl-bookclub-phoenix#4Landed by fast-forward: phoenix main is
0a964e9ac2, this PR's head (PASS r=1 Uranus, CI 6116 + 6117). Closed rather than merged: this repository does not allow the manually-merged style.Pull request closed