Skip to content

Commit 9d03039

Browse files
committed
fix!: remove upcast (#26)
Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
1 parent 3ad1e98 commit 9d03039

14 files changed

Lines changed: 25 additions & 439 deletions

File tree

‎guides/explanations/events.md‎

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -223,38 +223,6 @@ You request the consistency guarantee, either `:strong` or `:eventual`, when dis
223223

224224
An event handler is a `GenServer` process that subscribes to the configured event store. For each event persisted to the store the `handle/2` callback is called, passing the domain event and its metadata.
225225

226-
## Upcasting events
227-
228-
Commanded supports upcasting of events at runtime using the `Commanded.Event.Upcaster` protocol.
229-
230-
By implementing the upcaster protocol you can transform an event before it is used by a consumer. This might be an aggregate or an event handler. Because the upcaster changes the event at runtime, handlers only need to support the latest version. You can also use upcasting to change the type of event.
231-
232-
### Examples
233-
234-
Change the shape of an event by renaming a field:
235-
236-
```elixir
237-
defimpl Commanded.Event.Upcaster, for: AnEvent do
238-
def upcast(%AnEvent{} = event, _metadata) do
239-
%AnEvent{name: name} = event
240-
241-
%AnEvent{event | first_name: name}
242-
end
243-
end
244-
```
245-
246-
Change the type of event by replacing a historical event with a new event:
247-
248-
```elixir
249-
defimpl Commanded.Event.Upcaster, for: HistoricalEvent do
250-
def upcast(%HistoricalEvent{} = event, _metadata) do
251-
%HistoricalEvent{id: id, name: name} = event
252-
253-
%NewEvent{id: id, name: name}
254-
end
255-
end
256-
```
257-
258226
## Reset an EventHandler
259227

260228
An event handler can be reset (using a mix task), it will restart the event store subscription from the configured

‎guides/explanations/fork-differences.md‎

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ This fork maintains an independent release cycle to introduce new features and i
1111

1212
---
1313

14-
## Breaking Changes
14+
## Breaking Changes ❌
1515

16-
### **Removed ProcessManager Support** ❌
16+
### **Removed ProcessManager Support**
1717
[PR #24](https://github.com/straw-hat-team/commanded/pull/24)
1818

1919
**Changes:**
@@ -26,7 +26,19 @@ This fork maintains an independent release cycle to introduce new features and i
2626

2727
---
2828

29-
### **EnrichedMetadata Struct** 🔄
29+
### **Removed Upcasting Support**
30+
[PR #26](https://github.com/straw-hat-team/commanded/pull/26)
31+
32+
**Changes:**
33+
- Removed `Commanded.Event.Upcast` and `Commanded.Event.Upcaster` modules
34+
- Removed upcasting from event handlers and aggregates
35+
- Removed upcasting documentation
36+
37+
**Reason:** Event schema transformations can be handled explicitly in event handlers and aggregates using pattern matching, eliminating the need for a global upcasting component.
38+
39+
---
40+
41+
### **EnrichedMetadata Struct**
3042
[PR #11](https://github.com/straw-hat-team/commanded/pull/11)
3143

3244
**Changes:**
@@ -37,9 +49,9 @@ This fork maintains an independent release cycle to introduce new features and i
3749

3850
---
3951

40-
## Features Added
52+
## Features Added ✨
4153

42-
### **UUIDv7 Support** ✨
54+
### **UUIDv7 Support**
4355
[PR #22](https://github.com/straw-hat-team/commanded/pull/22)
4456

4557
**Changes:**
@@ -48,7 +60,7 @@ This fork maintains an independent release cycle to introduce new features and i
4860

4961
---
5062

51-
### **Configurable UUID Provider** ✨
63+
### **Configurable UUID Provider**
5264

5365
**Changes:**
5466
- Integrated `Uniq.UUID` library for UUID generation
@@ -57,7 +69,7 @@ This fork maintains an independent release cycle to introduce new features and i
5769

5870
---
5971

60-
### **Aggregate Telemetry for Version Conflicts** ✨
72+
### **Aggregate Telemetry for Version Conflicts**
6173
[PR #8](https://github.com/straw-hat-team/commanded/pull/8)
6274

6375
**Changes:**
@@ -66,7 +78,7 @@ This fork maintains an independent release cycle to introduce new features and i
6678

6779
---
6880

69-
### **Custom Event ID Support** ✨
81+
### **Custom Event ID Support**
7082
[PR #2](https://github.com/straw-hat-team/commanded/pull/2)
7183

7284
**Changes:**
@@ -76,7 +88,7 @@ This fork maintains an independent release cycle to introduce new features and i
7688

7789
---
7890

79-
### **EventStore Adapter** ✨
91+
### **EventStore Adapter**
8092
[PR #1](https://github.com/straw-hat-team/commanded/pull/1)
8193

8294
**Changes:**

‎guides/howtos/migrating-from-v1-to-v2.md‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,6 @@ end
9494
end
9595
```
9696

97-
4. **Update Upcaster implementations:**
98-
99-
```elixir
100-
defimpl Commanded.Event.Upcaster, for: MyEvent do
101-
alias Commanded.EventStore.EnrichedMetadata
102-
103-
def upcast(event, %EnrichedMetadata{} = metadata) do
104-
# Implementation
105-
end
106-
end
107-
```
108-
10997
## System Metadata Fields
11098

11199
The following fields are now directly accessible on the `EnrichedMetadata` struct:

‎lib/commanded/aggregates/aggregate.ex‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ defmodule Commanded.Aggregates.Aggregate do
119119
alias Commanded.Aggregates.ExecutionContext
120120
alias Commanded.Application.Config
121121
alias Commanded.Event.Mapper
122-
alias Commanded.Event.Upcast
123122
alias Commanded.EventStore
124123
alias Commanded.EventStore.RecordedEvent
125124
alias Commanded.Registration
@@ -392,15 +391,12 @@ defmodule Commanded.Aggregates.Aggregate do
392391
@doc false
393392
@impl GenServer
394393
def handle_info({:events, events}, %Aggregate{} = state) do
395-
%Aggregate{application: application} = state
396-
397394
Logger.debug(describe(state) <> " received events: " <> inspect(events))
398395

399396
try do
400397
state =
401398
events
402399
|> Enum.reject(&event_already_seen?(&1, state))
403-
|> Upcast.upcast_event_stream(additional_metadata: %{application: application})
404400
|> Enum.reduce(state, &handle_event/2)
405401

406402
noreply_with_lifespan(state)

‎lib/commanded/event/handler.ex‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,6 @@ defmodule Commanded.Event.Handler do
407407
alias Commanded.Event.ErrorHandler
408408
alias Commanded.Event.FailureContext
409409
alias Commanded.Event.Handler
410-
alias Commanded.Event.Upcast
411410
alias Commanded.EventStore.RecordedEvent
412411
alias Commanded.EventStore.Subscription
413412
alias Commanded.Subscriptions
@@ -952,7 +951,7 @@ defmodule Commanded.Event.Handler do
952951
@doc false
953952
@impl GenServer
954953
def handle_info({:events, events}, state) do
955-
%Handler{application: application, handler_callback: callback} = state
954+
%Handler{handler_callback: callback} = state
956955

957956
processor =
958957
case callback do
@@ -963,10 +962,7 @@ defmodule Commanded.Event.Handler do
963962
Logger.debug(describe(state) <> " received events: #{inspect(events)}")
964963

965964
try do
966-
state =
967-
events
968-
|> Upcast.upcast_event_stream(additional_metadata: %{application: application})
969-
|> processor.(state)
965+
state = processor.(events, state)
970966

971967
{:noreply, state}
972968
catch
@@ -1417,8 +1413,7 @@ defmodule Commanded.Event.Handler do
14171413
handler_name,
14181414
handler_module
14191415
) do
1420-
%RecordedEvent{data: data} =
1421-
event = Upcast.upcast_event(event, additional_metadata: %{application: application})
1416+
%RecordedEvent{data: data} = event
14221417

14231418
metadata =
14241419
RecordedEvent.enrich_metadata(event,

‎lib/commanded/event/upcast.ex‎

Lines changed: 0 additions & 22 deletions
This file was deleted.

‎lib/commanded/event/upcaster.ex‎

Lines changed: 0 additions & 67 deletions
This file was deleted.

‎lib/commanded/event_store.ex‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ defmodule Commanded.EventStore do
2525
2626
"""
2727
alias Commanded.Application
28-
alias Commanded.Event.Upcast
2928

3029
@type application :: Application.t()
3130
@type config :: Keyword.t()
@@ -80,7 +79,7 @@ defmodule Commanded.EventStore do
8079
error
8180

8281
stream ->
83-
Upcast.upcast_event_stream(stream, additional_metadata: %{application: application})
82+
stream
8483
end
8584
end)
8685
end

‎mix.exs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ defmodule Commanded.Mixfile do
131131
Commanded.Event.FailureContext,
132132
Commanded.Event.Handler,
133133
Commanded.Event.Mapper,
134-
Commanded.Event.Upcaster,
135134
Commanded.Event.EventId
136135
],
137136
"Event Store": [

‎test/event/support/upcast/batch_event_handler.ex‎

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)