holsee / inventory_es

Macros for an Event Sourced inventory system (from CodeMesh training w/ Greg Young)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Inventory ES

The only interesting aspect is the way commands and events are defined.

Examples same for commands.

defmodule Inventory.Events do
  defevent CheckoutOut,
    count: integer()
end
iex -S mix

Generated type specification:

t Inventory.Events.CheckedOut.t()

@type t() :: %Inventory.Events.CheckedOut{
        count: integer(),
        id: Id.t(),
        timestamp: Timestamp.t()
      }

Create event:

Inventory.Events.CheckedOut.create(count: 100)

%Inventory.Events.CheckedOut{
  count: 100,
  id: "e5d37047-3873-4bad-b123-3d422adf25c5",
  timestamp: 1573060299826
}

Key validation (not type, only dialyzer will save you):

Inventory.Events.CheckedOut.create()
# => boom! 'count' missing

About

Macros for an Event Sourced inventory system (from CodeMesh training w/ Greg Young)


Languages

Language:Elixir 66.2%Language:CSS 21.7%Language:JavaScript 7.6%Language:HTML 4.4%