|
2 | 2 |
|
3 | 3 | -export([ |
4 | 4 | new/6, |
5 | | - key/1, |
| 5 | + target/1, |
6 | 6 | with_metadata/2, |
7 | 7 | put_metadata/3, |
8 | 8 | with_tags/2, |
|
12 | 12 |
|
13 | 13 | -export_type([ |
14 | 14 | domain/0, |
15 | | - stream_id/0, |
| 15 | + aggregate_id/0, |
16 | 16 | sequence/0, |
17 | 17 | type/0, |
18 | 18 | metadata_key/0, |
|
22 | 22 | tags/0, |
23 | 23 | payload/0, |
24 | 24 | t/0, |
25 | | - key/0 |
| 25 | + target/0 |
26 | 26 | ]). |
27 | 27 |
|
28 | 28 | %%-------------------------------------------------------------------- |
|
32 | 32 | -doc "Domain identifier, representing a bounded context.". |
33 | 33 | -type domain() :: atom(). |
34 | 34 |
|
35 | | --doc "Stream identifier, uniquely identifying the target aggregate stream.". |
36 | | --type stream_id() :: binary(). |
| 35 | +-doc """ |
| 36 | +Aggregate identifier, uniquely identifying an aggregate instance. |
| 37 | + |
| 38 | +Can be any term (UUID, binary, integer, etc.). |
| 39 | +""". |
| 40 | +-type aggregate_id() :: term(). |
37 | 41 |
|
38 | 42 | -doc "Sequence of the command when batching operations (optional semantic).". |
39 | 43 | -type sequence() :: non_neg_integer(). |
@@ -67,43 +71,49 @@ A command represents an intent to change the state of an aggregate in a specific |
67 | 71 | It consists of: |
68 | 72 | - `domain`: The domain this command belongs to |
69 | 73 | - `type`: The type of command to execute |
70 | | -- `stream_id`: Identifier of the target aggregate stream |
| 74 | +- `aggregate_id`: Identifier of the target aggregate instance |
71 | 75 | - `sequence`: Optional sequencing information for idempotency/correlation |
72 | 76 | - `metadata`: Additional contextual information (user, timestamp, correlation ID, etc.) |
73 | 77 | - `tags`: Labels for categorization or routing |
74 | | -- `payload`: The actual command data (self-sufficient, includes aggregate ID(s)) |
| 78 | +- `payload`: The actual command data |
75 | 79 | """. |
76 | 80 | -type t() :: #{ |
77 | 81 | domain := domain(), |
78 | 82 | type := type(), |
79 | | - stream_id := stream_id(), |
| 83 | + aggregate_id := aggregate_id(), |
80 | 84 | sequence := sequence(), |
81 | 85 | metadata := metadata(), |
82 | 86 | tags := tags(), |
83 | 87 | payload := payload() |
84 | 88 | }. |
85 | 89 |
|
86 | | --type key() :: {domain(), stream_id(), sequence()}. |
| 90 | +-doc """ |
| 91 | +Command target identifier. |
| 92 | + |
| 93 | +The target is a tuple of the Domain and the AggregateId that identifies |
| 94 | +which aggregate this command is addressed to. |
| 95 | +""". |
| 96 | +-type target() :: {domain(), aggregate_id()}. |
87 | 97 |
|
88 | 98 | %%-------------------------------------------------------------------- |
89 | 99 | %% Functions |
90 | 100 | %%-------------------------------------------------------------------- |
91 | 101 |
|
92 | | --spec new(domain(), type(), stream_id(), sequence(), metadata(), payload()) -> t(). |
93 | | -new(Domain, Type, StreamId, Sequence, Metadata, Payload) -> |
| 102 | +-spec new(domain(), type(), aggregate_id(), sequence(), metadata(), payload()) -> t(). |
| 103 | +new(Domain, Type, AggregateId, Sequence, Metadata, Payload) -> |
94 | 104 | #{ |
95 | 105 | domain => Domain, |
96 | 106 | type => Type, |
97 | | - stream_id => StreamId, |
| 107 | + aggregate_id => AggregateId, |
98 | 108 | sequence => Sequence, |
99 | 109 | metadata => Metadata, |
100 | 110 | tags => [], |
101 | 111 | payload => Payload |
102 | 112 | }. |
103 | 113 |
|
104 | | --spec key(t()) -> key(). |
105 | | -key(#{domain := D, stream_id := S, sequence := Seq}) -> |
106 | | - {D, S, Seq}. |
| 114 | +-spec target(t()) -> target(). |
| 115 | +target(#{domain := D, aggregate_id := AggId}) -> |
| 116 | + {D, AggId}. |
107 | 117 |
|
108 | 118 | -spec with_metadata(metadata(), t()) -> t(). |
109 | 119 | with_metadata(Meta, Command) when is_map(Command) -> |
|
0 commit comments