Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unmaintained elixir_uuid dependency #253

Merged
merged 2 commits into from
Aug 5, 2022
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Event store implemented in Elixir. Uses [PostgreSQL](http://www.postgresql.org/) as the underlying storage engine.

Requires Elixir v1.6 and PostgreSQL v9.5 or newer.
Requires Elixir v1.10 and PostgreSQL v9.5 or newer.

EventStore supports [running on a cluster of nodes](guides/Cluster.md).

Expand Down Expand Up @@ -83,7 +83,7 @@ end
Append events to a stream:

```elixir
stream_uuid = UUID.uuid4()
stream_uuid = EventStore.UUID.uuid4()
expected_version = 0

events = [
Expand Down
4 changes: 2 additions & 2 deletions bench/seed_eventstore.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
# dropdb eventstore_bench
# createdb eventstore_bench
# pg_restore -d eventstore_bench eventstore_bench.dump
#
#
# MIX_ENV=bench mix do app.start, bench
#
#
defmodule EventBuilder do
alias EventStore.EventFactory
alias EventStore.{EventFactory, UUID}

def seed(total_event_count, events_per_stream, initial_event_number \\ 0)

Expand Down
2 changes: 1 addition & 1 deletion bench/storage/append_events_bench.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule AppendEventsBench do
use Benchfella

alias EventStore.{EventFactory, ProcessHelper, StorageInitializer}
alias EventStore.{EventFactory, ProcessHelper, StorageInitializer, UUID}
alias TestEventStore, as: EventStore

@await_timeout_ms 100_000
Expand Down
2 changes: 1 addition & 1 deletion bench/storage/read_events_bench.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule ReadEventsBench do
use Benchfella

alias EventStore.{EventFactory, ProcessHelper, StorageInitializer}
alias EventStore.{EventFactory, ProcessHelper, StorageInitializer, UUID}
alias TestEventStore, as: EventStore

@await_timeout_ms 100_000
Expand Down
2 changes: 1 addition & 1 deletion bench/storage/subscribe_to_stream_bench.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule SubscribeToStreamBench do
use Benchfella

alias EventStore.{EventFactory, ProcessHelper, StorageInitializer}
alias EventStore.{EventFactory, ProcessHelper, StorageInitializer, UUID}
alias TestEventStore, as: EventStore

@await_timeout_ms 100_000
Expand Down
2 changes: 1 addition & 1 deletion guides/Cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ defmodule ExampleEvent do
defstruct [:key]
end

stream_uuid = UUID.uuid4()
stream_uuid = EventStore.UUID.uuid4()

events = [
%EventData{
Expand Down
2 changes: 1 addition & 1 deletion guides/Subscriptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ Subscribe to events appended to a *single* stream:
```elixir
alias MyApp.EventStore

stream_uuid = UUID.uuid4()
stream_uuid = EventStore.UUID.uuid4()
{:ok, subscription} = EventStore.subscribe_to_stream(stream_uuid, "example_single_subscription", self())

# Wait for the subscription confirmation
Expand Down
2 changes: 1 addition & 1 deletion guides/Usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ end
Create a unique identity for each stream. It **must** be a string. This example uses the [elixir_uuid](https://hex.pm/packages/elixir_uuid) package.

```elixir
stream_uuid = UUID.uuid4()
stream_uuid = EventStore.UUID.uuid4()
```

Set the expected version of the stream. This is used for optimistic concurrency. A new stream will be created when the expected version is zero.
Expand Down
2 changes: 1 addition & 1 deletion lib/event_store/storage/appender.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule EventStore.Storage.Appender do

require Logger

alias EventStore.RecordedEvent
alias EventStore.{RecordedEvent, UUID}
alias EventStore.Sql.Statements

@doc """
Expand Down
2 changes: 1 addition & 1 deletion lib/event_store/storage/reader.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule EventStore.Storage.Reader do

require Logger

alias EventStore.RecordedEvent
alias EventStore.{RecordedEvent, UUID}
alias EventStore.Sql.Statements
alias EventStore.Storage.Reader

Expand Down
2 changes: 1 addition & 1 deletion lib/event_store/streams/stream.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule EventStore.Streams.Stream do
@moduledoc false

alias EventStore.{EventData, RecordedEvent, Storage}
alias EventStore.{EventData, RecordedEvent, Storage, UUID}
alias EventStore.Streams.StreamInfo

def append_to_stream(conn, stream_uuid, expected_version, events, opts)
Expand Down
102 changes: 102 additions & 0 deletions lib/event_store/uuid.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
defmodule EventStore.UUID do
@moduledoc false

# implementation taken from https://github.com/elixir-ecto/ecto/blob/v3.8.4/lib/ecto/uuid.ex
# license: Apache License 2.0 https://github.com/elixir-ecto/ecto/blob/master/LICENSE.md

@typedoc """
A hex-encoded UUID string.
"""
@type hex :: <<_::288>>

@typedoc """
A raw binary representation of a UUID.
"""
@type raw :: <<_::128>>

@doc """
Generates a random, version 4 UUID.
"""
@spec uuid4() :: hex()
def uuid4, do: hex_encode(bingenerate())

@doc """
Converts a string repreenting a UUID into a raw binary.
"""
@spec string_to_binary!(hex()) :: raw()
def string_to_binary!(
<<a1, a2, a3, a4, a5, a6, a7, a8, ?-, b1, b2, b3, b4, ?-, c1, c2, c3, c4, ?-, d1, d2, d3,
d4, ?-, e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12>>
) do
<<d(a1)::4, d(a2)::4, d(a3)::4, d(a4)::4, d(a5)::4, d(a6)::4, d(a7)::4, d(a8)::4, d(b1)::4,
d(b2)::4, d(b3)::4, d(b4)::4, d(c1)::4, d(c2)::4, d(c3)::4, d(c4)::4, d(d1)::4, d(d2)::4,
d(d3)::4, d(d4)::4, d(e1)::4, d(e2)::4, d(e3)::4, d(e4)::4, d(e5)::4, d(e6)::4, d(e7)::4,
d(e8)::4, d(e9)::4, d(e10)::4, d(e11)::4, d(e12)::4>>
end

@spec binary_to_string!(raw()) :: hex()
def binary_to_string!(<<_::128>> = raw_uuid) do
hex_encode(raw_uuid)
end

defp bingenerate() do
<<u0::48, _::4, u1::12, _::2, u2::62>> = :crypto.strong_rand_bytes(16)
<<u0::48, 4::4, u1::12, 2::2, u2::62>>
end

@spec hex_encode(raw()) :: hex()
defp hex_encode(
<<a1::4, a2::4, a3::4, a4::4, a5::4, a6::4, a7::4, a8::4, b1::4, b2::4, b3::4, b4::4,
c1::4, c2::4, c3::4, c4::4, d1::4, d2::4, d3::4, d4::4, e1::4, e2::4, e3::4, e4::4,
e5::4, e6::4, e7::4, e8::4, e9::4, e10::4, e11::4, e12::4>>
) do
<<e(a1), e(a2), e(a3), e(a4), e(a5), e(a6), e(a7), e(a8), ?-, e(b1), e(b2), e(b3), e(b4), ?-,
e(c1), e(c2), e(c3), e(c4), ?-, e(d1), e(d2), e(d3), e(d4), ?-, e(e1), e(e2), e(e3), e(e4),
e(e5), e(e6), e(e7), e(e8), e(e9), e(e10), e(e11), e(e12)>>
end

@compile {:inline, d: 1}

defp d(?0), do: 0
defp d(?1), do: 1
defp d(?2), do: 2
defp d(?3), do: 3
defp d(?4), do: 4
defp d(?5), do: 5
defp d(?6), do: 6
defp d(?7), do: 7
defp d(?8), do: 8
defp d(?9), do: 9
defp d(?A), do: 10
defp d(?B), do: 11
defp d(?C), do: 12
defp d(?D), do: 13
defp d(?E), do: 14
defp d(?F), do: 15
defp d(?a), do: 10
defp d(?b), do: 11
defp d(?c), do: 12
defp d(?d), do: 13
defp d(?e), do: 14
defp d(?f), do: 15
defp d(_), do: throw(:error)

@compile {:inline, e: 1}

defp e(0), do: ?0
defp e(1), do: ?1
defp e(2), do: ?2
defp e(3), do: ?3
defp e(4), do: ?4
defp e(5), do: ?5
defp e(6), do: ?6
defp e(7), do: ?7
defp e(8), do: ?8
defp e(9), do: ?9
defp e(10), do: ?a
defp e(11), do: ?b
defp e(12), do: ?c
defp e(13), do: ?d
defp e(14), do: ?e
defp e(15), do: ?f
end
3 changes: 1 addition & 2 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defmodule EventStore.Mixfile do
[
app: :eventstore,
version: @version,
elixir: "~> 1.6",
elixir: "~> 1.10",
elixirc_paths: elixirc_paths(Mix.env()),
deps: deps(),
description: description(),
Expand Down Expand Up @@ -39,7 +39,6 @@ defmodule EventStore.Mixfile do

defp deps do
[
{:elixir_uuid, "~> 1.2"},
{:fsm, "~> 0.3"},
{:gen_stage, "~> 1.1"},
{:postgrex, "~> 0.15"},
Expand Down
1 change: 0 additions & 1 deletion mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"decimal": {:hex, :decimal, "2.0.0", "a78296e617b0f5dd4c6caf57c714431347912ffb1d0842e998e9792b5642d697", [:mix], [], "hexpm", "34666e9c55dea81013e77d9d87370fe6cb6291d1ef32f46a1600230b1d44f577"},
"dialyxir": {:hex, :dialyxir, "1.1.0", "c5aab0d6e71e5522e77beff7ba9e08f8e02bad90dfbeffae60eaf0cb47e29488", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "07ea8e49c45f15264ebe6d5b93799d4dd56a44036cf42d0ad9c960bc266c0b9a"},
"earmark_parser": {:hex, :earmark_parser, "1.4.19", "de0d033d5ff9fc396a24eadc2fcf2afa3d120841eb3f1004d138cbf9273210e8", [:mix], [], "hexpm", "527ab6630b5c75c3a3960b75844c314ec305c76d9899bb30f71cb85952a9dc45"},
"elixir_uuid": {:hex, :elixir_uuid, "1.2.1", "dce506597acb7e6b0daeaff52ff6a9043f5919a4c3315abb4143f0b00378c097", [:mix], [], "hexpm", "f7eba2ea6c3555cea09706492716b0d87397b88946e6380898c2889d68585752"},
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
"ex_doc": {:hex, :ex_doc, "0.27.3", "d09ed7ab590b71123959d9017f6715b54a448d76b43cf909eb0b2e5a78a977b2", [:mix], [{:earmark_parser, "~> 1.4.19", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "ee60b329d08195039bfeb25231a208749be4f2274eae42ce38f9be0538a2f2e6"},
"fsm": {:hex, :fsm, "0.3.1", "087aa9b02779a84320dc7a2d8464452b5308e29877921b2bde81cdba32a12390", [:mix], [], "hexpm", "fbf0d53f89e9082b326b0b5828b94b4c549ff9d1452bbfd00b4d1ac082208e96"},
Expand Down
2 changes: 1 addition & 1 deletion test/append_to_stream_test.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule EventStore.AppendToStreamTest do
use EventStore.StorageCase

alias EventStore.EventFactory
alias EventStore.{EventFactory, UUID}
alias TestEventStore, as: EventStore

describe "append to new stream using `:any_version`" do
Expand Down
2 changes: 1 addition & 1 deletion test/dynamic_event_store_test.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule EventStore.DynamicEventStoreTest do
use EventStore.StorageCase

alias EventStore.EventFactory
alias EventStore.{EventFactory, UUID}

describe "dynamic event store" do
setup do
Expand Down
2 changes: 1 addition & 1 deletion test/event_store_test.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule EventStore.EventStoreTest do
use EventStore.StorageCase

alias EventStore.{EventData, EventFactory, RecordedEvent}
alias EventStore.{EventData, EventFactory, RecordedEvent, UUID}
alias EventStore.Snapshots.SnapshotData
alias TestEventStore, as: EventStore

Expand Down
2 changes: 1 addition & 1 deletion test/manual/long_running_subscription.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# mix run --no-halt test/manual/long_running_subscription.exs
#

alias EventStore.EventData
alias EventStore.{EventData, UUID}

defmodule LoggingSubscriber do
use GenServer
Expand Down
2 changes: 1 addition & 1 deletion test/manual/seed_eventstore.exs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ defmodule Snapshot do
end

defmodule Seed do
alias EventStore.EventData
alias EventStore.{EventData, UUID}
alias EventStore.Snapshots.SnapshotData

def run(opts \\ []) do
Expand Down
2 changes: 1 addition & 1 deletion test/multi_event_store_test.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule EventStore.MultiEventStoreTest do
use EventStore.StorageCase

alias EventStore.{Config, EventData, EventFactory, RecordedEvent, Storage}
alias EventStore.{Config, EventData, EventFactory, RecordedEvent, Storage, UUID}
alias EventStore.Snapshots.SnapshotData

setup do
Expand Down
3 changes: 1 addition & 2 deletions test/schema_test.exs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
defmodule EventStore.SchemaTest do
use EventStore.StorageCase

alias EventStore.Config
alias EventStore.EventFactory
alias EventStore.{Config, EventFactory, UUID}
alias EventStore.Storage.Initializer

setup_all do
Expand Down
4 changes: 1 addition & 3 deletions test/shared_connection_pool_test.exs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
defmodule EventStore.SharedConnectionPoolTest do
use ExUnit.Case

alias EventStore.EventFactory
alias EventStore.MonitoredServer
alias EventStore.{EventFactory, MonitoredServer, UUID, Wait}
alias EventStore.MonitoredServer.State, as: MonitoredServerState
alias EventStore.Tasks.{Create, Drop, Init}
alias EventStore.Wait

describe "connection pool sharing" do
setup do
Expand Down
3 changes: 1 addition & 2 deletions test/storage/append_events_test.exs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
defmodule EventStore.Storage.AppendEventsTest do
use EventStore.StorageCase

alias EventStore.EventFactory
alias EventStore.RecordedEvent
alias EventStore.{EventFactory, RecordedEvent, UUID}
alias EventStore.Storage.{Appender, CreateStream}

test "append single event to new stream", %{conn: conn, schema: schema} = context do
Expand Down
2 changes: 1 addition & 1 deletion test/storage/link_events_test.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule EventStore.Storage.LinkEventsTest do
use EventStore.StorageCase

alias EventStore.{EventFactory, RecordedEvent}
alias EventStore.{EventFactory, RecordedEvent, UUID}
alias EventStore.Storage.{Appender, CreateStream}

test "link single event to new stream", context do
Expand Down
3 changes: 1 addition & 2 deletions test/storage/read_events_test.exs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
defmodule EventStore.Storage.ReadEventsTest do
use EventStore.StorageCase

alias EventStore.EventFactory
alias EventStore.{RecordedEvent, Storage}
alias EventStore.{EventFactory, RecordedEvent, Storage, UUID}
alias EventStore.Storage.{Appender, CreateStream}

describe "read stream forward" do
Expand Down
2 changes: 1 addition & 1 deletion test/storage/snapshot_test.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule EventStore.Storage.SnapshotTest do
use EventStore.StorageCase

alias EventStore.EventFactory
alias EventStore.{EventFactory, UUID}
alias EventStore.Snapshots.SnapshotData
alias EventStore.Storage.Snapshot

Expand Down
2 changes: 1 addition & 1 deletion test/storage/stream_persistence_test.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule EventStore.Storage.StreamPersistenceTest do
use EventStore.StorageCase

alias EventStore.EventFactory
alias EventStore.{EventFactory, UUID}
alias EventStore.Storage.{Appender, CreateStream, Stream}
alias EventStore.Streams.StreamInfo

Expand Down
2 changes: 1 addition & 1 deletion test/streams/all_stream_test.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule EventStore.Streams.AllStreamTest do
use EventStore.StorageCase

alias EventStore.EventFactory
alias EventStore.{EventFactory, UUID}
alias EventStore.Streams.Stream
alias EventStore.Subscriptions.Subscription
alias TestEventStore, as: EventStore
Expand Down
4 changes: 1 addition & 3 deletions test/streams/hard_delete_stream_test.exs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
defmodule EventStore.Streams.HardDeleteStreamTest do
use EventStore.StorageCase

alias EventStore.EventFactory
alias EventStore.ProcessHelper
alias EventStore.RecordedEvent
alias EventStore.{EventFactory, ProcessHelper, RecordedEvent, UUID}
alias TestEventStore, as: EventStore

describe "hard delete stream when enabled" do
Expand Down
2 changes: 1 addition & 1 deletion test/streams/paginate_streams_test.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule EventStore.Streams.PaginateStreamsTest do
use EventStore.StorageCase

alias EventStore.{EventFactory, Page}
alias EventStore.{EventFactory, Page, UUID}
alias EventStore.Streams.StreamInfo
alias TestEventStore, as: EventStore

Expand Down
Loading