File tree Expand file tree Collapse file tree
eventsourcingdb/request_options Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -212,7 +212,7 @@ EventSourcingDB.read_events(
212212 " /books/42" ,
213213 %EventSourcingDB .ReadEventsOptions {
214214 recursive: false ,
215- from_latest_event: %EventSourcingDB .FromLatestEventOptions {
215+ from_latest_event: %EventSourcingDB .ReadFromLatestEventOptions {
216216 subject: " /books/42" ,
217217 type: " io.eventsourcingdb.library.book-borrowed" ,
218218 if_event_is_missing: :read_everything
@@ -297,7 +297,7 @@ EventSourcingDB.observe_events(
297297 " /books/42" ,
298298 %EventSourcingDB .ObserveEventsOptions {
299299 recursive: false ,
300- from_latest_event: %EventSourcingDB .FromLatestEventOptions {
300+ from_latest_event: %EventSourcingDB .ObserveFromLatestEventOptions {
301301 subject: " /books/42" ,
302302 type: " io.eventsourcingdb.library.book-borrowed" ,
303303 if_event_is_missing: :read_everything
Original file line number Diff line number Diff line change @@ -292,7 +292,7 @@ defmodule EventSourcingDB do
292292 "/books/42",
293293 %EventSourcingDB.ReadEventsOptions{
294294 recursive: false,
295- from_latest_event: %EventSourcingDB.FromLatestEventOptions {
295+ from_latest_event: %EventSourcingDB.ReadFromLatestEventOptions {
296296 subject: "/books/42",
297297 type: "io.eventsourcingdb.library.book-borrowed",
298298 if_event_is_missing: :read_everything
@@ -378,7 +378,7 @@ defmodule EventSourcingDB do
378378 "/books/42",
379379 %EventSourcingDB.ObserveEventsOptions{
380380 recursive: false,
381- from_latest_event: %EventSourcingDB.FromLatestEventOptions {
381+ from_latest_event: %EventSourcingDB.ObserveFromLatestEventOptions {
382382 subject: "/books/42",
383383 type: "io.eventsourcingdb.library.book-borrowed",
384384 if_event_is_missing: :read_everything
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ defmodule EventSourcingDB.ObserveEventsOptions do
66
77 typedstruct do
88 field :recursive , boolean ( ) , enforce: true
9- field :from_latest_event , EventSourcingDB.FromLatestEventOptions . t ( )
9+ field :from_latest_event , EventSourcingDB.ObserveFromLatestEventOptions . t ( )
1010 field :lower_bound , EventSourcingDB.BoundOptions . t ( )
1111 end
1212
Original file line number Diff line number Diff line change 1+ defmodule EventSourcingDB.ObserveFromLatestEventOptions do
2+ @ moduledoc """
3+ Options for observing events starting from the latest event of a given type.
4+ """
5+ use TypedStruct
6+
7+ typedstruct enforce: true do
8+ field :if_event_is_missing , :read_everything | :wait_for_event
9+ field :subject , String . t ( )
10+ field :type , String . t ( )
11+ end
12+
13+ @ spec new ( keyword ( ) ) :: t ( )
14+ def new ( options ) do
15+ options =
16+ options
17+ |> Keyword . validate! ( [ :if_event_is_missing , :subject , :type ] )
18+
19+ struct! ( __MODULE__ , options )
20+ end
21+
22+ defimpl Jason.Encoder do
23+ @ spec encode ( EventSourcingDB.ObserveFromLatestEventOptions . t ( ) , Jason.Encode . opts ( ) ) ::
24+ iodata ( )
25+ def encode ( value , opts ) do
26+ Jason.Encode . map (
27+ % {
28+ "ifEventIsMissing" =>
29+ case value . if_event_is_missing do
30+ :read_everything -> "read-everything"
31+ :wait_for_event -> "wait-for-event"
32+ end ,
33+ "subject" => value . subject ,
34+ "type" => value . type
35+ } ,
36+ opts
37+ )
38+ end
39+ end
40+ end
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ defmodule EventSourcingDB.ReadEventsOptions do
77 typedstruct do
88 field :recursive , boolean ( ) , enforce: true
99 field :order , :chronological | :antichronological
10- field :from_latest_event , EventSourcingDB.FromLatestEventOptions . t ( )
10+ field :from_latest_event , EventSourcingDB.ReadFromLatestEventOptions . t ( )
1111 field :lower_bound , EventSourcingDB.BoundOptions . t ( )
1212 field :upper_bound , EventSourcingDB.BoundOptions . t ( )
1313 end
Original file line number Diff line number Diff line change 1- defmodule EventSourcingDB.FromLatestEventOptions do
1+ defmodule EventSourcingDB.ReadFromLatestEventOptions do
22 @ moduledoc """
3- Reading events from when a certain event occured .
3+ Options for reading events starting from the latest event of a given type .
44 """
55 use TypedStruct
66
77 typedstruct enforce: true do
8- field :if_event_is_missing , :read_everything | :read_nothing | :wait_for_event
8+ field :if_event_is_missing , :read_everything | :read_nothing
99 field :subject , String . t ( )
1010 field :type , String . t ( )
1111 end
@@ -20,7 +20,7 @@ defmodule EventSourcingDB.FromLatestEventOptions do
2020 end
2121
2222 defimpl Jason.Encoder do
23- @ spec encode ( EventSourcingDB.FromLatestEventOptions . t ( ) , Jason.Encode . opts ( ) ) ::
23+ @ spec encode ( EventSourcingDB.ReadFromLatestEventOptions . t ( ) , Jason.Encode . opts ( ) ) ::
2424 iodata ( )
2525 def encode ( value , opts ) do
2626 Jason.Encode . map (
@@ -29,7 +29,6 @@ defmodule EventSourcingDB.FromLatestEventOptions do
2929 case value . if_event_is_missing do
3030 :read_everything -> "read-everything"
3131 :read_nothing -> "read-nothing"
32- :wait_for_event -> "wait-for-event"
3332 end ,
3433 "subject" => value . subject ,
3534 "type" => value . type
Original file line number Diff line number Diff line change @@ -70,9 +70,10 @@ defmodule EventSourcingDB.MixProject do
7070 ] ,
7171 "Request Options": [
7272 EventSourcingDB.BoundOptions ,
73- EventSourcingDB.FromLatestEventOptions ,
7473 EventSourcingDB.ObserveEventsOptions ,
75- EventSourcingDB.ReadEventsOptions
74+ EventSourcingDB.ObserveFromLatestEventOptions ,
75+ EventSourcingDB.ReadEventsOptions ,
76+ EventSourcingDB.ReadFromLatestEventOptions
7677 ] ,
7778 Testing: [
7879 EventSourcingDB.TestContainer
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ defmodule EventSourcingDBTest.ObserveEvents do
22 alias EventSourcingDB.TestContainer
33 alias EventSourcingDB.ObserveEventsOptions
44 alias EventSourcingDB.BoundOptions
5- alias EventSourcingDB.FromLatestEventOptions
5+ alias EventSourcingDB.ObserveFromLatestEventOptions
66 import EventSourcingDBTest.Utils
77 use ExUnit.Case , async: true
88
@@ -70,7 +70,7 @@ defmodule EventSourcingDBTest.ObserveEvents do
7070 events =
7171 EventSourcingDB . observe_events! ( client , "/" , % ObserveEventsOptions {
7272 recursive: true ,
73- from_latest_event: % FromLatestEventOptions {
73+ from_latest_event: % ObserveFromLatestEventOptions {
7474 subject: "/test" ,
7575 type: "io.eventsourcingdb.test.bar" ,
7676 if_event_is_missing: :read_everything
Original file line number Diff line number Diff line change 11defmodule EventSourcingDBTest.ReadEvents do
22 alias EventSourcingDB.Errors.TransmissionError
33 alias EventSourcingDB.Client
4- alias EventSourcingDB.FromLatestEventOptions
4+ alias EventSourcingDB.ReadFromLatestEventOptions
55 alias EventSourcingDB.BoundOptions
66 alias EventSourcingDB.ReadEventsOptions
77 alias EventSourcingDB.TestContainer
@@ -181,7 +181,7 @@ defmodule EventSourcingDBTest.ReadEvents do
181181
182182 events =
183183 EventSourcingDB . read_events! ( client , "/test" , % ReadEventsOptions {
184- from_latest_event: % FromLatestEventOptions {
184+ from_latest_event: % ReadFromLatestEventOptions {
185185 subject: "/" ,
186186 type: "io.eventsourcingdb.test.does-not-exist" ,
187187 if_event_is_missing: :read_nothing
@@ -204,7 +204,7 @@ defmodule EventSourcingDBTest.ReadEvents do
204204
205205 events =
206206 EventSourcingDB . read_events! ( client , "/test" , % ReadEventsOptions {
207- from_latest_event: % FromLatestEventOptions {
207+ from_latest_event: % ReadFromLatestEventOptions {
208208 subject: "/marker" ,
209209 type: "io.eventsourcingdb.test" ,
210210 if_event_is_missing: :read_nothing
You can’t perform that action at this time.
0 commit comments