View Source Domainex.Aggregate (domainex v0.1.0)
Aggregate is a module provide base Aggregate module functions. It provide base structure for the aggregate. An aggregate itself means, a cluster of objects that treat as a single unit of domain business logic, although it's possible too to contain only a single object.
This module should not provide any functions that possible to limiting scope of some domain business, or it should be designed to be generic, and only provide some helpers
Summary
Functions
add_event/2
used to adding an event to current available events in some aggregate
aggregate/1
used to extract a main aggregate data structure from the tuple of
emit_events/1
used to emit all current available events from an aggregate. All of available
event will send to all registered processors, and after emitting events, we need to reset current
events to empty list.
entities/1
used to load multiple entities. It just using entity/1
under the hood.
If your current aggregate contains multiple entities, then it will all of that entities
in map()
format.
entity/1
used to load current aggregate's :contains
property, which expected result
is a single entity.
is_aggregate?/1
used to check if given tuple is an :aggregate
or not. For any types
which not a tuple, it will return false
A new/2
has two possibilities depends on given parameter.
If it give a single entity which is a struct()
it will generate a
BaseType.aggregate()
that contains a main aggregate object with single entity,
or people common said as aggregate root.
update_entity/2
used to update internal aggregate's entity. This function used
only for an aggregate with a single entity.
update_entity/3
used to update one of available entities. This function used for an aggregate
with multiple entities.
Functions
@spec add_event(data :: Domainex.aggregate(), event :: Domainex.event()) :: Domainex.result()
add_event/2
used to adding an event to current available events in some aggregate
@spec aggregate(data :: Domainex.aggregate()) :: Domainex.result()
aggregate/1
used to extract a main aggregate data structure from the tuple of:
# used to extract structure
{:aggregate, {name, structure}}
It will return an error of :aggregate
if given parameter is not tuple
@spec emit_events(data :: Domainex.aggregate()) :: Domainex.result()
emit_events/1
used to emit all current available events from an aggregate. All of available
event will send to all registered processors, and after emitting events, we need to reset current
events to empty list.
@spec entities(data :: Domainex.aggregate()) :: Domainex.result()
entities/1
used to load multiple entities. It just using entity/1
under the hood.
If your current aggregate contains multiple entities, then it will all of that entities
in map()
format.
@spec entity(data :: Domainex.aggregate()) :: Domainex.result()
entity/1
used to load current aggregate's :contains
property, which expected result
is a single entity.
@spec error_invalid_aggregate_type() :: binary()
@spec error_invalid_data_type() :: binary()
@spec is_aggregate?(given :: Domainex.aggregate()) :: boolean()
is_aggregate?/1
used to check if given tuple is an :aggregate
or not. For any types
which not a tuple, it will return false
@spec new( name :: Domainex.aggregate_name(), entity :: Domainex.aggregate_payload(), processors :: [module()] ) :: Domainex.aggregate()
@spec new( name :: Domainex.aggregate_name(), entities :: %{required(atom()) => Domainex.aggregate_payload()}, processors :: [module()] ) :: Domainex.aggregate()
A new/2
has two possibilities depends on given parameter.
If it give a single entity which is a struct()
it will generate a
BaseType.aggregate()
that contains a main aggregate object with single entity,
or people common said as aggregate root.
If it give a list of entities, it will generate a BaseType.aggregate()
that
contains a list of entities.
All generated structure will always generated with an empty :events
@spec update_entity(data :: Domainex.aggregate(), entity :: struct()) :: Domainex.result()
update_entity/2
used to update internal aggregate's entity. This function used
only for an aggregate with a single entity.
Usage:
aggregate2 = aggregate |> Aggregate.update_entity(fake_entity_updated)
@spec update_entity(data :: Domainex.aggregate(), key :: atom(), entity :: struct()) :: Domainex.result()
update_entity/3
used to update one of available entities. This function used for an aggregate
with multiple entities.
Usage:
{:ok, aggregate2} = aggregate |> Aggregate.update_entity(:fake1, fake_entity_1_updated)
The update_entity/3
need a key
to update some entity, since an aggregate that contains multiple
entities will be mapped based on some unique key