evoq_fact behaviour (evoq v1.14.1)

View Source

Fact behavior for evoq.

Facts are integration artifacts that cross bounded context boundaries. They translate domain events into serializable payloads for external consumption via pg (local) or mesh (WAN).

Key differences from domain events: - Binary keys (JSON-safe), not atom keys - Explicit public contract, not internal implementation detail - May have different structure/name than the source event - Versioned independently from the domain event

Required Callbacks

- fact_type() -> binary() - from_event(EventType, EventData, Metadata) -> {ok, Payload} | skip

Optional Callbacks

- serialize(Payload) -> {ok, binary()} | {error, Reason} - deserialize(Binary) -> {ok, map()} | {error, Reason} - schema() -> map()

Summary

Functions

Default deserialization using OTP 27 json module.

Default serialization using OTP 27 json module.

Callbacks

deserialize/1

(optional)
-callback deserialize(Binary :: binary()) -> {ok, map()} | {error, Reason :: term()}.

fact_type/0

-callback fact_type() -> binary().

from_event/3

-callback from_event(EventType :: atom(), EventData :: map(), Metadata :: map()) ->
                        {ok, Payload :: map()} | skip.

schema/0

(optional)
-callback schema() -> map().

serialize/1

(optional)
-callback serialize(Payload :: map()) -> {ok, binary()} | {error, Reason :: term()}.

Functions

default_deserialize(Binary)

-spec default_deserialize(binary()) -> {ok, map()} | {error, term()}.

Default deserialization using OTP 27 json module.

default_serialize(Payload)

-spec default_serialize(map()) -> {ok, binary()} | {error, term()}.

Default serialization using OTP 27 json module.