From 46cb9e014e155f8b45d61f8864012090ae9f4061 Mon Sep 17 00:00:00 2001 From: Paul-Henri Froidmont Date: Tue, 4 Nov 2025 17:57:44 +0100 Subject: [PATCH 1/3] Move reducer --- core/src/lu/foyer/EventSourcing.scala | 10 ---------- core/src/lu/foyer/Reducer.scala | 11 +++++++++++ 2 files changed, 11 insertions(+), 10 deletions(-) create mode 100644 core/src/lu/foyer/Reducer.scala diff --git a/core/src/lu/foyer/EventSourcing.scala b/core/src/lu/foyer/EventSourcing.scala index bd157af..370a4bf 100644 --- a/core/src/lu/foyer/EventSourcing.scala +++ b/core/src/lu/foyer/EventSourcing.scala @@ -12,13 +12,3 @@ trait StateRepository[Data] extends Repository[Entity[Data], String] trait EventRepository[Data] extends Repository[Event[Data], String]: def fetchOne(entityId: String, eventId: String): Task[Option[Event[Data]]] def fetchMany(entityId: String, page: Page): Task[Paged[Event[Data]]] - -trait Reducer[Event, State]: - def fromEmpty: PartialFunction[Event, State] - def fromState: PartialFunction[(State, Event), State] - - def reduce(event: Event): Option[State] = - fromEmpty.lift(event) - - def reduce(state: State, event: Event): Option[State] = - fromState.lift((state, event)) diff --git a/core/src/lu/foyer/Reducer.scala b/core/src/lu/foyer/Reducer.scala new file mode 100644 index 0000000..6d567fd --- /dev/null +++ b/core/src/lu/foyer/Reducer.scala @@ -0,0 +1,11 @@ +package lu.foyer + +trait Reducer[Event, State]: + def fromEmpty: PartialFunction[Event, State] + def fromState: PartialFunction[(State, Event), State] + + def reduce(event: Event): Option[State] = + fromEmpty.lift(event) + + def reduce(state: State, event: Event): Option[State] = + fromState.lift((state, event)) From 868f44e90e136e14b473bf8d4ab23b94dec3543d Mon Sep 17 00:00:00 2001 From: Paul-Henri Froidmont Date: Tue, 4 Nov 2025 17:57:44 +0100 Subject: [PATCH 2/3] Move reducer --- .envrc | 11 +---------- core/src/lu/foyer/EventSourcing.scala | 13 ------------- core/src/lu/foyer/Reducer.scala | 11 +++++++++++ 3 files changed, 12 insertions(+), 23 deletions(-) create mode 100644 core/src/lu/foyer/Reducer.scala diff --git a/.envrc b/.envrc index dc25ec7..a41f435 100644 --- a/.envrc +++ b/.envrc @@ -1,10 +1 @@ -if ! has nix_direnv_version || ! nix_direnv_version 2.2.1; then - source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/2.2.1/direnvrc" "sha256-zelF0vLbEl5uaqrfIzbgNzJWGmLzCmYAkInj/LNxvKs=" -fi - -watch_file flake.nix -watch_file flake.lock -if ! use flake . --no-pure-eval -then - echo "devenv could not be built. The devenv environment was not loaded. Make the necessary changes to devenv.nix and hit enter to try again." >&2 -fi +use flake . --no-pure-eval diff --git a/core/src/lu/foyer/EventSourcing.scala b/core/src/lu/foyer/EventSourcing.scala index bd157af..af4031a 100644 --- a/core/src/lu/foyer/EventSourcing.scala +++ b/core/src/lu/foyer/EventSourcing.scala @@ -1,9 +1,6 @@ package lu.foyer import zio.* -import zio.schema.Schema - -import lu.foyer.auth.UserInfo final case class Entity[T](entityId: String, data: T, version: Long) final case class Event[T](entityId: String, data: T, eventId: String) @@ -12,13 +9,3 @@ trait StateRepository[Data] extends Repository[Entity[Data], String] trait EventRepository[Data] extends Repository[Event[Data], String]: def fetchOne(entityId: String, eventId: String): Task[Option[Event[Data]]] def fetchMany(entityId: String, page: Page): Task[Paged[Event[Data]]] - -trait Reducer[Event, State]: - def fromEmpty: PartialFunction[Event, State] - def fromState: PartialFunction[(State, Event), State] - - def reduce(event: Event): Option[State] = - fromEmpty.lift(event) - - def reduce(state: State, event: Event): Option[State] = - fromState.lift((state, event)) diff --git a/core/src/lu/foyer/Reducer.scala b/core/src/lu/foyer/Reducer.scala new file mode 100644 index 0000000..6d567fd --- /dev/null +++ b/core/src/lu/foyer/Reducer.scala @@ -0,0 +1,11 @@ +package lu.foyer + +trait Reducer[Event, State]: + def fromEmpty: PartialFunction[Event, State] + def fromState: PartialFunction[(State, Event), State] + + def reduce(event: Event): Option[State] = + fromEmpty.lift(event) + + def reduce(state: State, event: Event): Option[State] = + fromState.lift((state, event)) From eb9b4201e64323a169fa30562f178b0a83550716 Mon Sep 17 00:00:00 2001 From: Paul-Henri Froidmont Date: Tue, 4 Nov 2025 18:48:09 +0100 Subject: [PATCH 3/3] Remove unused imports --- .envrc | 11 +---------- core/src/lu/foyer/EventSourcing.scala | 3 --- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/.envrc b/.envrc index dc25ec7..a41f435 100644 --- a/.envrc +++ b/.envrc @@ -1,10 +1 @@ -if ! has nix_direnv_version || ! nix_direnv_version 2.2.1; then - source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/2.2.1/direnvrc" "sha256-zelF0vLbEl5uaqrfIzbgNzJWGmLzCmYAkInj/LNxvKs=" -fi - -watch_file flake.nix -watch_file flake.lock -if ! use flake . --no-pure-eval -then - echo "devenv could not be built. The devenv environment was not loaded. Make the necessary changes to devenv.nix and hit enter to try again." >&2 -fi +use flake . --no-pure-eval diff --git a/core/src/lu/foyer/EventSourcing.scala b/core/src/lu/foyer/EventSourcing.scala index 370a4bf..af4031a 100644 --- a/core/src/lu/foyer/EventSourcing.scala +++ b/core/src/lu/foyer/EventSourcing.scala @@ -1,9 +1,6 @@ package lu.foyer import zio.* -import zio.schema.Schema - -import lu.foyer.auth.UserInfo final case class Entity[T](entityId: String, data: T, version: Long) final case class Event[T](entityId: String, data: T, eventId: String)