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
20 changes: 10 additions & 10 deletions Source/chronicle/lib/chronicle/constraints.ex
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ defmodule Chronicle.Constraints do
definitions =
Enum.map(constraints, &build_constraint/1)

request = %RegisterConstraintsRequest{
request = struct(RegisterConstraintsRequest,
EventStore: event_store,
Constraints: definitions
}
)

case Constraints.Stub.register(channel, request) do
{:ok, _} -> :ok
Expand All @@ -67,21 +67,21 @@ defmodule Chronicle.Constraints do
end

defp build_constraint(%{type: :unique, name: name, event_type_id: event_type_id, on: properties}) do
%Constraint{
struct(Constraint,
Name: name,
Type: :Unique,
Definition: %OneOf_UniqueConstraintDefinition_UniqueEventTypeConstraintDefinition{
Value0: %UniqueConstraintDefinition{
Definition: struct(OneOf_UniqueConstraintDefinition_UniqueEventTypeConstraintDefinition,
Value0: struct(UniqueConstraintDefinition,
EventDefinitions: [
%UniqueConstraintEventDefinition{
struct(UniqueConstraintEventDefinition,
EventTypeId: event_type_id,
Properties: List.wrap(properties)
}
)
],
IgnoreCasing: false
}
}
}
)
)
)
end

defp build_constraint(%{type: :unique, name: name, event_type: event_module} = constraint) do
Expand Down
40 changes: 20 additions & 20 deletions Source/chronicle/lib/chronicle/event_log.ex
Original file line number Diff line number Diff line change
Expand Up @@ -70,27 +70,27 @@ defmodule Chronicle.EventLog do
namespace = Keyword.get(opts, :namespace, config.namespace)
event_module = event.__struct__

request = %AppendRequest{
CorrelationId: %BclGuid{},
request = struct(AppendRequest,
CorrelationId: struct(BclGuid),
EventStore: config.event_store,
Namespace: namespace,
EventSequenceId: @event_log_id,
EventSourceType: Keyword.get(opts, :event_source_type, "Default"),
EventSourceId: event_source_id,
EventStreamType: Keyword.get(opts, :event_stream_type, "All"),
EventStreamId: Keyword.get(opts, :event_stream_id, "Default"),
EventType: %EventType{
EventType: struct(EventType,
Id: event_module.__chronicle_event_type__(:id),
Generation: event_module.__chronicle_event_type__(:generation)
},
),
Content: encode_event(event),
Causation: [client_causation()],
CausedBy: %Identity{Subject: "elixir-client", Name: "Chronicle Elixir Client", UserName: "chronicle"},
ConcurrencyScope: %ConcurrencyScope{SequenceNumber: 18_446_744_073_709_551_615},
CausedBy: struct(Identity, Subject: "elixir-client", Name: "Chronicle Elixir Client", UserName: "chronicle"),
ConcurrencyScope: struct(ConcurrencyScope, SequenceNumber: 18_446_744_073_709_551_615),
Occurred: current_datetime_offset(),
Tags: Keyword.get(opts, :tags, []),
Subject: Keyword.get(opts, :subject, "")
}
)

case EventSequences.Stub.append(channel, request) do
{:ok, response} ->
Expand Down Expand Up @@ -128,26 +128,26 @@ defmodule Chronicle.EventLog do
Enum.map(events, fn event ->
module = event.__struct__

%EventToAppend{
struct(EventToAppend,
EventSourceType: Keyword.get(opts, :event_source_type, "Default"),
EventSourceId: event_source_id,
EventStreamType: Keyword.get(opts, :event_stream_type, "All"),
EventStreamId: Keyword.get(opts, :event_stream_id, "Default"),
EventType: %EventType{
EventType: struct(EventType,
Id: module.__chronicle_event_type__(:id),
Generation: module.__chronicle_event_type__(:generation)
},
),
Content: encode_event(event),
Tags: Keyword.get(opts, :tags, [])
}
)
end)

request = %AppendManyRequest{
request = struct(AppendManyRequest,
EventStore: config.event_store,
Namespace: namespace,
EventSequenceId: @event_log_id,
Events: event_entries
}
)

case EventSequences.Stub.append_many(channel, request) do
{:ok, response} ->
Expand Down Expand Up @@ -185,19 +185,19 @@ defmodule Chronicle.EventLog do

event_types =
Enum.map(event_type_modules, fn module ->
%EventType{
struct(EventType,
Id: module.__chronicle_event_type__(:id),
Generation: module.__chronicle_event_type__(:generation)
}
)
end)

request = %GetForEventSourceIdAndEventTypesRequest{
request = struct(GetForEventSourceIdAndEventTypesRequest,
EventStore: config.event_store,
Namespace: namespace,
EventSequenceId: @event_log_id,
EventSourceId: event_source_id,
EventTypes: event_types
}
)

case EventSequences.Stub.get_for_event_source_id_and_event_types(channel, request) do
{:ok, response} -> {:ok, Map.get(response, :Events, [])}
Expand Down Expand Up @@ -235,13 +235,13 @@ defmodule Chronicle.EventLog do
end

defp client_causation do
%Causation{
struct(Causation,
Type: "Elixir.Chronicle.Client",
Occurred: current_datetime_offset()
}
)
end

defp current_datetime_offset do
%SerializableDateTimeOffset{Value: DateTime.utc_now() |> DateTime.to_iso8601()}
struct(SerializableDateTimeOffset, Value: DateTime.utc_now() |> DateTime.to_iso8601())
end
end
12 changes: 6 additions & 6 deletions Source/chronicle/lib/chronicle/event_types.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,21 @@ defmodule Chronicle.EventTypes do
def register(channel, event_store, event_type_modules) when is_list(event_type_modules) do
registrations =
Enum.map(event_type_modules, fn module ->
%EventTypeRegistration{
Type: %EventType{
struct(EventTypeRegistration,
Type: struct(EventType,
Id: module.__chronicle_event_type__(:id),
Generation: module.__chronicle_event_type__(:generation)
},
),
Schema: generate_schema(module),
EventStore: event_store
}
)
end)

request = %RegisterEventTypesRequest{
request = struct(RegisterEventTypesRequest,
EventStore: event_store,
Types: registrations,
DisableValidation: false
}
)

case EventTypes.Stub.register(channel, request) do
{:ok, _} -> :ok
Expand Down
64 changes: 32 additions & 32 deletions Source/chronicle/lib/chronicle/projections/registrar.ex
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ defmodule Chronicle.Projections.Registrar do

# MongoDB sink type ID: "22202c41-2be1-4547-9c00-f0b1f797fd75"
# Computed from .NET Guid.ToByteArray() split into lo/hi fixed64 little-endian
@mongodb_sink_type_id %BclGuid{lo: 0x45472BE122202C41, hi: 0x75FD97F7B1F0009C}
defp mongodb_sink_type_id, do: struct(BclGuid, lo: 0x45472BE122202C41, hi: 0x75FD97F7B1F0009C)

@retry_delay 5_000

Expand Down Expand Up @@ -116,14 +116,14 @@ defmodule Chronicle.Projections.Registrar do
end

defp ensure_event_store(channel, event_store) do
case EventStores.Stub.ensure(channel, %EnsureEventStore{Name: event_store}) do
case EventStores.Stub.ensure(channel, struct(EnsureEventStore, Name: event_store)) do
{:ok, _} -> :ok
{:error, reason} -> {:error, {:ensure_event_store, reason}}
end
end

defp ensure_namespace(channel, event_store, namespace) do
case Namespaces.Stub.ensure(channel, %EnsureNamespace{EventStore: event_store, Name: namespace}) do
case Namespaces.Stub.ensure(channel, struct(EnsureNamespace, EventStore: event_store, Name: namespace)) do
{:ok, _} -> :ok
{:error, reason} -> {:error, {:ensure_namespace, reason}}
end
Expand All @@ -136,17 +136,17 @@ defmodule Chronicle.Projections.Registrar do
|> Enum.map(fn rm ->
model_id = rm.__chronicle_read_model__(:id)

%ReadModelDefinition{
Type: %ReadModelType{Identifier: model_id, Generation: 1},
struct(ReadModelDefinition,
Type: struct(ReadModelType, Identifier: model_id, Generation: 1),
ContainerName: model_id,
DisplayName: model_id,
Sink: %SinkDefinition{ConfigurationId: %BclGuid{}, TypeId: @mongodb_sink_type_id},
Sink: struct(SinkDefinition, ConfigurationId: struct(BclGuid), TypeId: mongodb_sink_type_id()),
Schema: generate_read_model_schema(rm),
ObserverType: 2,
ObserverIdentifier: model_id,
Owner: 2,
Source: 1
}
)
end)

reducer_definitions =
Expand All @@ -156,30 +156,30 @@ defmodule Chronicle.Projections.Registrar do
model_id = model_module.__chronicle_read_model__(:id)
reducer_id = reducer_module.__chronicle_reducer__(:id)

%ReadModelDefinition{
Type: %ReadModelType{Identifier: model_id, Generation: 1},
struct(ReadModelDefinition,
Type: struct(ReadModelType, Identifier: model_id, Generation: 1),
ContainerName: model_id,
DisplayName: model_id,
Sink: %SinkDefinition{ConfigurationId: %BclGuid{}, TypeId: @mongodb_sink_type_id},
Sink: struct(SinkDefinition, ConfigurationId: struct(BclGuid), TypeId: mongodb_sink_type_id()),
Schema: generate_read_model_schema(model_module),
ObserverType: 1,
ObserverIdentifier: reducer_id,
Owner: 2,
Source: 1
}
)
end)

all_definitions = projection_definitions ++ reducer_definitions

if Enum.empty?(all_definitions) do
:ok
else
request = %RegisterManyRequest{
request = struct(RegisterManyRequest,
EventStore: state.event_store,
Owner: 2,
ReadModels: all_definitions,
Source: 1
}
)

case ReadModels.Stub.register_many(channel, request) do
{:ok, _} -> :ok
Expand Down Expand Up @@ -238,11 +238,11 @@ defmodule Chronicle.Projections.Registrar do
else
definitions = Enum.map(projection_read_models, &build_projection_definition(&1))

request = %RegisterRequest{
request = struct(RegisterRequest,
EventStore: state.event_store,
Owner: 1,
Projections: definitions
}
)

case Projections.Stub.register(channel, request) do
{:ok, _} ->
Expand All @@ -266,14 +266,14 @@ defmodule Chronicle.Projections.Registrar do
key = Keyword.get(opts, :key, "$eventSourceId")
parent_key = Keyword.get(opts, :parent_key, "")

%KeyValuePair_EventType_FromDefinition{
struct(KeyValuePair_EventType_FromDefinition,
Key: proto_event_type(event_module),
Value: %FromDefinition{
Value: struct(FromDefinition,
Key: key,
Properties: properties,
ParentKey: parent_key
}
}
)
)
end)

join_entries =
Expand All @@ -283,14 +283,14 @@ defmodule Chronicle.Projections.Registrar do
key = Keyword.get(opts, :key, "$eventSourceId")
on = Keyword.fetch!(opts, :on)

%KeyValuePair_EventType_JoinDefinition{
struct(KeyValuePair_EventType_JoinDefinition,
Key: proto_event_type(event_module),
Value: %JoinDefinition{
Value: struct(JoinDefinition,
On: on,
Key: key,
Properties: properties
}
}
)
)
end)

removed_with_entries =
Expand All @@ -299,10 +299,10 @@ defmodule Chronicle.Projections.Registrar do
key = Keyword.get(opts, :key, "$eventSourceId")
parent_key = Keyword.get(opts, :parent_key, "")

%KeyValuePair_EventType_RemovedWithDefinition{
struct(KeyValuePair_EventType_RemovedWithDefinition,
Key: proto_event_type(event_module),
Value: %RemovedWithDefinition{Key: key, ParentKey: parent_key}
}
Value: struct(RemovedWithDefinition, Key: key, ParentKey: parent_key)
)
end)

from_every =
Expand All @@ -311,13 +311,13 @@ defmodule Chronicle.Projections.Registrar do
nil

[opts | _] ->
%FromEveryDefinition{
struct(FromEveryDefinition,
Properties: build_properties(opts),
IncludeChildren: Keyword.get(opts, :include_children, false)
}
)
end

%ProjectionDefinition{
struct(ProjectionDefinition,
Identifier: identifier,
ReadModel: model_name,
EventSequenceId: "event-log",
Expand All @@ -328,7 +328,7 @@ defmodule Chronicle.Projections.Registrar do
RemovedWith: removed_with_entries,
All: from_every,
InitialModelState: initial_model_state(read_model_module)
}
)
end

# Converts set/add/subtract/count opts into a Chronicle properties map.
Expand Down Expand Up @@ -378,9 +378,9 @@ defmodule Chronicle.Projections.Registrar do
defp resolve_expression(str) when is_binary(str), do: str

defp proto_event_type(event_module) do
%ProtoEventType{
struct(ProtoEventType,
Id: event_module.__chronicle_event_type__(:id),
Generation: event_module.__chronicle_event_type__(:generation)
}
)
end
end
Loading
Loading