evoq_hope behaviour (evoq v1.14.1)

View Source

Hope behavior for evoq.

Hopes are integration artifacts for outbound RPC requests between agents or bounded contexts. Unlike facts (fire-and-forget), hopes expect a response.

Key characteristics: - Binary keys (JSON-safe), serializable for transport - Represent a request/intention directed at another agent - Cross boundary via mesh RPC or similar transport - Named "hope" because the caller hopes for a response but cannot guarantee one (distributed systems reality)

Required Callbacks

- hope_type() -> binary() - new(Params) -> {ok, Hope} | {error, Reason} - to_payload(Hope) -> map() - from_payload(Payload) -> {ok, Hope} | {error, Reason}

Optional Callbacks

- validate(Hope) -> ok | {error, Reason} - 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()}.

from_payload/1

-callback from_payload(Payload :: map()) -> {ok, Hope :: term()} | {error, Reason :: term()}.

hope_type/0

-callback hope_type() -> binary().

new/1

-callback new(Params :: map()) -> {ok, Hope :: term()} | {error, Reason :: term()}.

schema/0

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

serialize/1

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

to_payload/1

-callback to_payload(Hope :: term()) -> map().

validate/1

(optional)
-callback validate(Hope :: term()) -> ok | {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.