Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 0 additions & 32 deletions guides/explanations/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,38 +223,6 @@ You request the consistency guarantee, either `:strong` or `:eventual`, when dis

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.

## Upcasting events

Commanded supports upcasting of events at runtime using the `Commanded.Event.Upcaster` protocol.

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.

### Examples

Change the shape of an event by renaming a field:

```elixir
defimpl Commanded.Event.Upcaster, for: AnEvent do
def upcast(%AnEvent{} = event, _metadata) do
%AnEvent{name: name} = event

%AnEvent{event | first_name: name}
end
end
```

Change the type of event by replacing a historical event with a new event:

```elixir
defimpl Commanded.Event.Upcaster, for: HistoricalEvent do
def upcast(%HistoricalEvent{} = event, _metadata) do
%HistoricalEvent{id: id, name: name} = event

%NewEvent{id: id, name: name}
end
end
```

## Reset an EventHandler

An event handler can be reset (using a mix task), it will restart the event store subscription from the configured
Expand Down
29 changes: 20 additions & 9 deletions guides/explanations/fork-differences.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ This fork maintains an independent release cycle to introduce new features and i

---

## Breaking Changes
## Breaking Changes ❌

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

**Changes:**
Expand All @@ -26,7 +26,18 @@ This fork maintains an independent release cycle to introduce new features and i

---

### **EnrichedMetadata Struct** 🔄
### **Removed Upcasting Support**

**Changes:**
- Removed `Commanded.Event.Upcast` and `Commanded.Event.Upcaster` modules
- Removed upcasting from event handlers and aggregates
- Removed upcasting documentation

**Reason:** Event schema transformations can be handled explicitly in event handlers and aggregates using pattern matching, eliminating the need for a global upcasting component.

---

### **EnrichedMetadata Struct**
[PR #11](https://github.com/straw-hat-team/commanded/pull/11)

**Changes:**
Expand All @@ -37,9 +48,9 @@ This fork maintains an independent release cycle to introduce new features and i

---

## Features Added
## Features Added ✨

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

**Changes:**
Expand All @@ -48,7 +59,7 @@ This fork maintains an independent release cycle to introduce new features and i

---

### **Configurable UUID Provider** ✨
### **Configurable UUID Provider**

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

---

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

**Changes:**
Expand All @@ -66,7 +77,7 @@ This fork maintains an independent release cycle to introduce new features and i

---

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

**Changes:**
Expand All @@ -76,7 +87,7 @@ This fork maintains an independent release cycle to introduce new features and i

---

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

**Changes:**
Expand Down
12 changes: 0 additions & 12 deletions guides/howtos/migrating-from-v1-to-v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,6 @@ end
end
```

4. **Update Upcaster implementations:**

```elixir
defimpl Commanded.Event.Upcaster, for: MyEvent do
alias Commanded.EventStore.EnrichedMetadata

def upcast(event, %EnrichedMetadata{} = metadata) do
# Implementation
end
end
```

## System Metadata Fields

The following fields are now directly accessible on the `EnrichedMetadata` struct:
Expand Down
4 changes: 0 additions & 4 deletions lib/commanded/aggregates/aggregate.ex
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ defmodule Commanded.Aggregates.Aggregate do
alias Commanded.Aggregates.ExecutionContext
alias Commanded.Application.Config
alias Commanded.Event.Mapper
alias Commanded.Event.Upcast
alias Commanded.EventStore
alias Commanded.EventStore.RecordedEvent
alias Commanded.Registration
Expand Down Expand Up @@ -392,15 +391,12 @@ defmodule Commanded.Aggregates.Aggregate do
@doc false
@impl GenServer
def handle_info({:events, events}, %Aggregate{} = state) do
%Aggregate{application: application} = state

Logger.debug(describe(state) <> " received events: " <> inspect(events))

try do
state =
events
|> Enum.reject(&event_already_seen?(&1, state))
|> Upcast.upcast_event_stream(additional_metadata: %{application: application})
|> Enum.reduce(state, &handle_event/2)

noreply_with_lifespan(state)
Expand Down
11 changes: 3 additions & 8 deletions lib/commanded/event/handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,6 @@ defmodule Commanded.Event.Handler do
alias Commanded.Event.ErrorHandler
alias Commanded.Event.FailureContext
alias Commanded.Event.Handler
alias Commanded.Event.Upcast
alias Commanded.EventStore.RecordedEvent
alias Commanded.EventStore.Subscription
alias Commanded.Subscriptions
Expand Down Expand Up @@ -952,7 +951,7 @@ defmodule Commanded.Event.Handler do
@doc false
@impl GenServer
def handle_info({:events, events}, state) do
%Handler{application: application, handler_callback: callback} = state
%Handler{handler_callback: callback} = state

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

try do
state =
events
|> Upcast.upcast_event_stream(additional_metadata: %{application: application})
|> processor.(state)
state = processor.(events, state)

{:noreply, state}
catch
Expand Down Expand Up @@ -1417,8 +1413,7 @@ defmodule Commanded.Event.Handler do
handler_name,
handler_module
) do
%RecordedEvent{data: data} =
event = Upcast.upcast_event(event, additional_metadata: %{application: application})
%RecordedEvent{data: data} = event

metadata =
RecordedEvent.enrich_metadata(event,
Expand Down
22 changes: 0 additions & 22 deletions lib/commanded/event/upcast.ex

This file was deleted.

67 changes: 0 additions & 67 deletions lib/commanded/event/upcaster.ex

This file was deleted.

3 changes: 1 addition & 2 deletions lib/commanded/event_store.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ defmodule Commanded.EventStore do

"""
alias Commanded.Application
alias Commanded.Event.Upcast

@type application :: Application.t()
@type config :: Keyword.t()
Expand Down Expand Up @@ -80,7 +79,7 @@ defmodule Commanded.EventStore do
error

stream ->
Upcast.upcast_event_stream(stream, additional_metadata: %{application: application})
stream
end
end)
end
Expand Down
1 change: 0 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ defmodule Commanded.Mixfile do
Commanded.Event.FailureContext,
Commanded.Event.Handler,
Commanded.Event.Mapper,
Commanded.Event.Upcaster,
Commanded.Event.EventId
],
"Event Store": [
Expand Down
13 changes: 0 additions & 13 deletions test/event/support/upcast/batch_event_handler.ex

This file was deleted.

18 changes: 0 additions & 18 deletions test/event/support/upcast/event_handler.ex

This file was deleted.

Loading