Repository: commanded/commanded
Pull request #528 (2023-02-21 09:04:42)

Support opts in append_to_stream


Patch:
diff --git a/lib/commanded/event_store.ex b/lib/commanded/event_store.ex
index 3e3e22c..a6f0cff 100644
--- a/lib/commanded/event_store.ex
+++ b/lib/commanded/event_store.ex
@@ -33,7 +33,7 @@ defmodule Commanded.EventStore do
   @doc """
   Append one or more events to a stream atomically.
   """
-  def append_to_stream(application, stream_uuid, expected_version, events) do
+  def append_to_stream(application, stream_uuid, expected_version, events, options \\ []) do
     meta = %{
       application: application,
       stream_uuid: stream_uuid,
@@ -43,12 +43,22 @@ defmodule Commanded.EventStore do
     span(:append_to_stream, meta, fn ->
       {adapter, adapter_meta} = Application.event_store_adapter(application)
 
-      adapter.append_to_stream(
-        adapter_meta,
-        stream_uuid,
-        expected_version,
-        events
-      )
+      if function_exported?(adapter, :append_to_stream, 5) do
+        adapter.append_to_stream(
+          adapter_meta,
+          stream_uuid,
+          expected_version,
+          events,
+          options
+        )
+      else
+        adapter.append_to_stream(
+          adapter_meta,
+          stream_uuid,
+          expected_version,
+          events
+        )
+      end
     end)
   end
 
diff --git a/lib/commanded/event_store/adapter.ex b/lib/commanded/event_store/adapter.ex
index 8e618e6..3bfffbe 100644
--- a/lib/commanded/event_store/adapter.ex
+++ b/lib/commanded/event_store/adapter.ex
@@ -31,7 +31,8 @@ defmodule Commanded.EventStore.Adapter do
               adapter_meta,
               stream_uuid,
               expected_version,
-              events :: list(EventData.t())
+              events :: list(EventData.t()),
+              options
             ) ::
               :ok
               | {:error, :wrong_expected_version}
diff --git a/lib/commanded/event_store/adapters/in_memory.ex b/lib/commanded/event_store/adapters/in_memory.ex
index 97254cd..28b25e4 100644
--- a/lib/commanded/event_store/adapters/in_memory.ex
+++ b/lib/commanded/event_store/adapters/in_memory.ex
@@ -64,7 +64,7 @@ defmodule Commanded.EventStore.Adapters.InMemory do
   end
 
   @impl Commanded.EventStore.Adapter
-  def append_to_stream(adapter_meta, stream_uuid, expected_version, events) do
+  def append_to_stream(adapter_meta, stream_uuid, expected_version, events, _opts \\ []) do
     event_store = event_store_name(adapter_meta)
 
     GenServer.call(event_store, {:append, stream_uuid, expected_version, events})


Test patch:
diff --git a/test/aggregates/aggregate_concurrency_test.exs b/test/aggregates/aggregate_concurrency_test.exs
index 446524a..22e308b 100644
--- a/test/aggregates/aggregate_concurrency_test.exs
+++ b/test/aggregates/aggregate_concurrency_test.exs
@@ -50,7 +50,8 @@ defmodule Commanded.Aggregates.AggregateConcurrencyTest do
       expect(MockEventStore, :append_to_stream, fn _event_store_meta,
                                                    ^account_number,
                                                    1,
-                                                   _event_data ->
+                                                   _event_data,
+                                                   _opts ->
         {:error, :wrong_expected_version}
       end)
 
@@ -81,7 +82,8 @@ defmodule Commanded.Aggregates.AggregateConcurrencyTest do
       expect(MockEventStore, :append_to_stream, fn _event_store_meta,
                                                    ^account_number,
                                                    2,
-                                                   _event_data ->
+                                                   _event_data,
+                                                   _opts ->
         :ok
       end)
 
@@ -102,7 +104,8 @@ defmodule Commanded.Aggregates.AggregateConcurrencyTest do
       expect(MockEventStore, :append_to_stream, 6, fn _event_store_meta,
                                                       ^account_number,
                                                       1,
-                                                      _event_data ->
+                                                      _event_data,
+                                                      _opts ->
         {:error, :wrong_expected_version}
       end)
 
@@ -143,7 +146,8 @@ defmodule Commanded.Aggregates.AggregateConcurrencyTest do
       expect(MockEventStore, :append_to_stream, fn _event_store_meta,
                                                    ^account_number,
                                                    0,
-                                                   _event_data ->
+                                                   _event_data,
+                                                   _opts ->
         :ok
       end)