Skip to content

Commit

Permalink
tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
renatillas committed Aug 4, 2024
1 parent a480c26 commit 9ed6ec8
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 46 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ pub fn aggregate_type() -> String {
}
//
pub fn main() {
let postgres_store =
postgres_store.new(
Expand Down
7 changes: 4 additions & 3 deletions gleam.toml
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
name = "eventsourcing"
version = "1.0.0"
version = "0.1.0"

# Fill out these fields if you intend to generate HTML documentation or publish
# your project to the Hex package manager.
#
description = "CQRS and Event Soucing in Gleam!"
licences = ["Apache-2.0"]
repository = { type = "github", user = "renatillas", repo = "eventsoucing" }
repository = { type = "github", user = "renatillas", repo = "eventsourcing" }

[dependencies]
gleam_stdlib = ">= 0.34.0 and < 2.0.0"
gleam_otp = ">= 0.10.0 and < 1.0.0"
gleam_erlang = ">= 0.25.0 and < 1.0.0"
gleam_pgo = ">= 0.13.0 and < 1.0.0"
gleam_json = ">= 1.0.1 and < 2.0.0"
decode = ">= 0.2.0 and < 1.0.0"

[dev-dependencies]
gleeunit = ">= 1.0.0 and < 2.0.0"
birdie = ">= 1.1.8 and < 2.0.0"
pprint = ">= 1.0.3 and < 2.0.0"
testcontainers = ">= 1.8.4 and < 2.0.0"
decode = ">= 0.2.0 and < 1.0.0"
41 changes: 41 additions & 0 deletions manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,21 @@ packages = [
{ name = "argv", version = "1.0.2", build_tools = ["gleam"], requirements = [], otp_app = "argv", source = "hex", outer_checksum = "BA1FF0929525DEBA1CE67256E5ADF77A7CDDFE729E3E3F57A5BDCAA031DED09D" },
{ name = "backoff", version = "1.1.6", build_tools = ["rebar3"], requirements = [], otp_app = "backoff", source = "hex", outer_checksum = "CF0CFFF8995FB20562F822E5CC47D8CCF664C5ECDC26A684CBE85C225F9D7C39" },
{ name = "birdie", version = "1.1.8", build_tools = ["gleam"], requirements = ["argv", "filepath", "glance", "gleam_community_ansi", "gleam_erlang", "gleam_stdlib", "justin", "rank", "simplifile", "trie_again"], otp_app = "birdie", source = "hex", outer_checksum = "D225C0A3035FCD73A88402925A903AAD3567A1515C9EAE8364F11C17AD1805BB" },
{ name = "castore", version = "1.0.8", build_tools = ["mix"], requirements = [], otp_app = "castore", source = "hex", outer_checksum = "0B2B66D2EE742CB1D9CB8C8BE3B43C3A70EE8651F37B75A8B982E036752983F1" },
{ name = "certifi", version = "2.12.0", build_tools = ["rebar3"], requirements = [], otp_app = "certifi", source = "hex", outer_checksum = "EE68D85DF22E554040CDB4BE100F33873AC6051387BAF6A8F6CE82272340FF1C" },
{ name = "cowlib", version = "2.13.0", build_tools = ["make", "rebar3"], requirements = [], otp_app = "cowlib", source = "hex", outer_checksum = "E1E1284DC3FC030A64B1AD0D8382AE7E99DA46C3246B815318A4B848873800A4" },
{ name = "db_connection", version = "2.7.0", build_tools = ["mix"], requirements = ["telemetry"], otp_app = "db_connection", source = "hex", outer_checksum = "DCF08F31B2701F857DFC787FBAD78223D61A32204F217F15E881DD93E4BDD3FF" },
{ name = "decimal", version = "2.1.1", build_tools = ["mix"], requirements = [], otp_app = "decimal", source = "hex", outer_checksum = "53CFE5F497ED0E7771AE1A475575603D77425099BA5FAEF9394932B35020FFCC" },
{ name = "decode", version = "0.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "decode", source = "hex", outer_checksum = "965F517F67B8C172CA27A5C8E34C73733139E8C9E64736181B8C3179281F9793" },
{ name = "ecto", version = "3.11.2", build_tools = ["mix"], requirements = ["decimal", "jason", "telemetry"], otp_app = "ecto", source = "hex", outer_checksum = "3C38BCA2C6F8D8023F2145326CC8A80100C3FFE4DCBD9842FF867F7FC6156C65" },
{ name = "ecto_sql", version = "3.11.3", build_tools = ["mix"], requirements = ["db_connection", "ecto", "myxql", "postgrex", "tds", "telemetry"], otp_app = "ecto_sql", source = "hex", outer_checksum = "E5F36E3D736B99C7FEE3E631333B8394ADE4BAFE9D96D35669FCA2D81C2BE928" },
{ name = "elixir_uuid", version = "1.2.1", build_tools = ["mix"], requirements = [], otp_app = "elixir_uuid", source = "hex", outer_checksum = "F7EBA2EA6C3555CEA09706492716B0D87397B88946E6380898C2889D68585752" },
{ name = "ex_docker_engine_api", version = "1.43.1", build_tools = ["mix"], requirements = ["hackney", "jason", "tesla"], otp_app = "ex_docker_engine_api", source = "hex", outer_checksum = "EC8FC499389AEEF56DDCA67E89E9E98098CFF50587B56E8B4613279F382793B1" },
{ name = "exjsx", version = "4.0.0", build_tools = ["mix"], requirements = ["jsx"], otp_app = "exjsx", source = "hex", outer_checksum = "32E95820A97CFFEA67830E91514A2AD53B888850442D6D395F53A1AC60C82E07" },
{ name = "filepath", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "filepath", source = "hex", outer_checksum = "EFB6FF65C98B2A16378ABC3EE2B14124168C0CE5201553DE652E2644DCFDB594" },
{ name = "finch", version = "0.18.0", build_tools = ["mix"], requirements = ["castore", "mime", "mint", "nimble_options", "nimble_pool", "telemetry"], otp_app = "finch", source = "hex", outer_checksum = "69F5045B042E531E53EDC2574F15E25E735B522C37E2DDB766E15B979E03AA65" },
{ name = "fuse", version = "2.5.0", build_tools = ["rebar3"], requirements = [], otp_app = "fuse", source = "hex", outer_checksum = "7F52A1C84571731AD3C91D569E03131CC220EBAA7E2A11034405F0BAC46A4FEF" },
{ name = "geo", version = "3.6.0", build_tools = ["mix"], requirements = ["jason"], otp_app = "geo", source = "hex", outer_checksum = "1DBDEBF617183B54BC3C8AD7A36531A9A76ADA8CA93F75F573B0AE94006168DA" },
{ name = "glam", version = "2.0.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "glam", source = "hex", outer_checksum = "66EC3BCD632E51EED029678F8DF419659C1E57B1A93D874C5131FE220DFAD2B2" },
{ name = "glance", version = "0.11.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "glexer"], otp_app = "glance", source = "hex", outer_checksum = "8F3314D27773B7C3B9FB58D8C02C634290422CE531988C0394FA0DF8676B964D" },
{ name = "gleam_community_ansi", version = "1.4.0", build_tools = ["gleam"], requirements = ["gleam_community_colour", "gleam_stdlib"], otp_app = "gleam_community_ansi", source = "hex", outer_checksum = "FE79E08BF97009729259B6357EC058315B6FBB916FAD1C2FF9355115FEB0D3A4" },
Expand All @@ -18,16 +31,43 @@ packages = [
{ name = "gleam_stdlib", version = "0.39.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "2D7DE885A6EA7F1D5015D1698920C9BAF7241102836CE0C3837A4F160128A9C4" },
{ name = "gleeunit", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "F7A7228925D3EE7D0813C922E062BFD6D7E9310F0BEE585D3A42F3307E3CFD13" },
{ name = "glexer", version = "1.0.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "glexer", source = "hex", outer_checksum = "BD477AD657C2B637FEF75F2405FAEFFA533F277A74EF1A5E17B55B1178C228FB" },
{ name = "gun", version = "2.1.0", build_tools = ["make", "rebar3"], requirements = ["cowlib"], otp_app = "gun", source = "hex", outer_checksum = "52FC7FC246BFC3B00E01AEA1C2854C70A366348574AB50C57DFE796D24A0101D" },
{ name = "hackney", version = "1.20.1", build_tools = ["rebar3"], requirements = ["certifi", "idna", "metrics", "mimerl", "parse_trans", "ssl_verify_fun", "unicode_util_compat"], otp_app = "hackney", source = "hex", outer_checksum = "FE9094E5F1A2A2C0A7D10918FEE36BFEC0EC2A979994CFF8CFE8058CD9AF38E3" },
{ name = "hpax", version = "1.0.0", build_tools = ["mix"], requirements = [], otp_app = "hpax", source = "hex", outer_checksum = "7F1314731D711E2CA5FDC7FD361296593FC2542570B3105595BB0BC6D0FAD601" },
{ name = "ibrowse", version = "4.4.2", build_tools = ["rebar3"], requirements = [], otp_app = "ibrowse", source = "hex", outer_checksum = "F088CEE1FAF6514B18C7783E8BC64C628D140A239786DC1F58FE9766E9584F41" },
{ name = "idna", version = "6.1.1", build_tools = ["rebar3"], requirements = ["unicode_util_compat"], otp_app = "idna", source = "hex", outer_checksum = "92376EB7894412ED19AC475E4A86F7B413C1B9FBB5BD16DCCD57934157944CEA" },
{ name = "jason", version = "1.4.4", build_tools = ["mix"], requirements = ["decimal"], otp_app = "jason", source = "hex", outer_checksum = "C5EB0CAB91F094599F94D55BC63409236A8EC69A21A67814529E8D5F6CC90B3B" },
{ name = "jsx", version = "2.8.3", build_tools = ["mix", "rebar3"], requirements = [], otp_app = "jsx", source = "hex", outer_checksum = "FC3499FED7A726995AA659143A248534ADC754EBD16CCD437CD93B649A95091F" },
{ name = "justin", version = "1.0.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "justin", source = "hex", outer_checksum = "7FA0C6DB78640C6DC5FBFD59BF3456009F3F8B485BF6825E97E1EB44E9A1E2CD" },
{ name = "metrics", version = "1.0.1", build_tools = ["rebar3"], requirements = [], otp_app = "metrics", source = "hex", outer_checksum = "69B09ADDDC4F74A40716AE54D140F93BEB0FB8978D8636EADED0C31B6F099F16" },
{ name = "mime", version = "2.0.6", build_tools = ["mix"], requirements = [], otp_app = "mime", source = "hex", outer_checksum = "C9945363A6B26D747389AAC3643F8E0E09D30499A138AD64FE8FD1D13D9B153E" },
{ name = "mimerl", version = "1.3.0", build_tools = ["rebar3"], requirements = [], otp_app = "mimerl", source = "hex", outer_checksum = "A1E15A50D1887217DE95F0B9B0793E32853F7C258A5CD227650889B38839FE9D" },
{ name = "mint", version = "1.6.2", build_tools = ["mix"], requirements = ["castore", "hpax"], otp_app = "mint", source = "hex", outer_checksum = "5EE441DFFC1892F1AE59127F74AFE8FD82FDA6587794278D924E4D90EA3D63F9" },
{ name = "msgpax", version = "2.4.0", build_tools = ["mix"], requirements = ["plug"], otp_app = "msgpax", source = "hex", outer_checksum = "CA933891B0E7075701A17507C61642BF6E0407BB244040D5D0A58597A06369D2" },
{ name = "myxql", version = "0.7.1", build_tools = ["mix"], requirements = ["db_connection", "decimal", "geo", "jason", "table"], otp_app = "myxql", source = "hex", outer_checksum = "A491CDFF53353A09B5850AC2D472816EBE19F76C30B0D36A43317A67C9004936" },
{ name = "nimble_options", version = "1.1.1", build_tools = ["mix"], requirements = [], otp_app = "nimble_options", source = "hex", outer_checksum = "821B2470CA9442C4B6984882FE9BB0389371B8DDEC4D45A9504F00A66F650B44" },
{ name = "nimble_pool", version = "1.1.0", build_tools = ["mix"], requirements = [], otp_app = "nimble_pool", source = "hex", outer_checksum = "AF2E4E6B34197DB81F7AAD230C1118EAC993ACC0DAE6BC83BAC0126D4AE0813A" },
{ name = "opentelemetry_api", version = "1.3.0", build_tools = ["rebar3", "mix"], requirements = ["opentelemetry_semantic_conventions"], otp_app = "opentelemetry_api", source = "hex", outer_checksum = "B9E5FF775FD064FA098DBA3C398490B77649A352B40B0B730A6B7DC0BDD68858" },
{ name = "opentelemetry_semantic_conventions", version = "0.2.0", build_tools = ["rebar3", "mix"], requirements = [], otp_app = "opentelemetry_semantic_conventions", source = "hex", outer_checksum = "D61FA1F5639EE8668D74B527E6806E0503EFC55A42DB7B5F39939D84C07D6895" },
{ name = "parse_trans", version = "3.4.1", build_tools = ["rebar3"], requirements = [], otp_app = "parse_trans", source = "hex", outer_checksum = "620A406CE75DADA827B82E453C19CF06776BE266F5A67CFF34E1EF2CBB60E49A" },
{ name = "pg_types", version = "0.4.0", build_tools = ["rebar3"], requirements = [], otp_app = "pg_types", source = "hex", outer_checksum = "B02EFA785CAECECF9702C681C80A9CA12A39F9161A846CE17B01FB20AEEED7EB" },
{ name = "pgo", version = "0.14.0", build_tools = ["rebar3"], requirements = ["backoff", "opentelemetry_api", "pg_types"], otp_app = "pgo", source = "hex", outer_checksum = "71016C22599936E042DC0012EE4589D24C71427D266292F775EBF201D97DF9C9" },
{ name = "plug", version = "1.16.1", build_tools = ["mix"], requirements = ["mime", "plug_crypto", "telemetry"], otp_app = "plug", source = "hex", outer_checksum = "A13FF6B9006B03D7E33874945B2755253841B238C34071ED85B0E86057F8CDDC" },
{ name = "plug_crypto", version = "2.1.0", build_tools = ["mix"], requirements = [], otp_app = "plug_crypto", source = "hex", outer_checksum = "131216A4B030B8F8CE0F26038BC4421AE60E4BB95C5CF5395E1421437824C4FA" },
{ name = "poison", version = "6.0.0", build_tools = ["mix"], requirements = ["decimal"], otp_app = "poison", source = "hex", outer_checksum = "BB9064632B94775A3964642D6A78281C07B7BE1319E0016E1643790704E739A2" },
{ name = "postgrex", version = "0.19.0", build_tools = ["mix"], requirements = ["db_connection", "decimal", "jason", "table"], otp_app = "postgrex", source = "hex", outer_checksum = "DBA2D2A0A8637DEFBF2307E8629CB2526388BA7348F67D04EC77A5D6A72ECFAE" },
{ name = "pprint", version = "1.0.3", build_tools = ["gleam"], requirements = ["glam", "gleam_stdlib"], otp_app = "pprint", source = "hex", outer_checksum = "76BBB92E23D12D954BD452686543F29EDE8EBEBB7FC0ACCBCA66EEF276EC3A06" },
{ name = "rank", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "rank", source = "hex", outer_checksum = "5660E361F0E49CBB714CC57CC4C89C63415D8986F05B2DA0C719D5642FAD91C9" },
{ name = "simplifile", version = "2.0.1", build_tools = ["gleam"], requirements = ["filepath", "gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "5FFEBD0CAB39BDD343C3E1CCA6438B2848847DC170BA2386DF9D7064F34DF000" },
{ name = "ssl_verify_fun", version = "1.1.7", build_tools = ["mix", "rebar3", "make"], requirements = [], otp_app = "ssl_verify_fun", source = "hex", outer_checksum = "FE4C190E8F37401D30167C8C405EDA19469F34577987C76DDE613E838BBC67F8" },
{ name = "table", version = "0.1.2", build_tools = ["mix"], requirements = [], otp_app = "table", source = "hex", outer_checksum = "7E99BC7EFEF806315C7E65640724BF165C3061CDC5D854060F74468367065029" },
{ name = "tds", version = "2.3.5", build_tools = ["mix"], requirements = ["db_connection", "decimal", "jason", "table"], otp_app = "tds", source = "hex", outer_checksum = "52E350F5DD5584BBCFF9859E331BE144D290B41BD4C749B936014A17660662F2" },
{ name = "telemetry", version = "1.2.1", build_tools = ["rebar3"], requirements = [], otp_app = "telemetry", source = "hex", outer_checksum = "DAD9CE9D8EFFC621708F99EAC538EF1CBE05D6A874DD741DE2E689C47FEAFED5" },
{ name = "tesla", version = "1.12.0", build_tools = ["mix"], requirements = ["castore", "exjsx", "finch", "fuse", "gun", "hackney", "ibrowse", "jason", "mime", "mint", "msgpax", "poison", "telemetry"], otp_app = "tesla", source = "hex", outer_checksum = "2FD07D9E3FDB0E39DD2CB16064E28CE02808A26CF33A44D269EF3B1FC20FC914" },
{ name = "testcontainers", version = "1.8.4", build_tools = ["mix"], requirements = ["ecto", "ecto_sql", "elixir_uuid", "ex_docker_engine_api"], otp_app = "testcontainers", source = "hex", outer_checksum = "3C21FD2E9A7951DA5280F3D70AF8319320C0F41095AE46AF5E85CD0FD1C51AB1" },
{ name = "thoas", version = "1.2.1", build_tools = ["rebar3"], requirements = [], otp_app = "thoas", source = "hex", outer_checksum = "E38697EDFFD6E91BD12CEA41B155115282630075C2A727E7A6B2947F5408B86A" },
{ name = "trie_again", version = "1.1.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "trie_again", source = "hex", outer_checksum = "5B19176F52B1BD98831B57FDC97BD1F88C8A403D6D8C63471407E78598E27184" },
{ name = "unicode_util_compat", version = "0.7.0", build_tools = ["rebar3"], requirements = [], otp_app = "unicode_util_compat", source = "hex", outer_checksum = "25EEE6D67DF61960CF6A794239566599B09E17E668D3700247BC498638152521" },
]

[requirements]
Expand All @@ -40,3 +80,4 @@ gleam_pgo = { version = ">= 0.13.0 and < 1.0.0" }
gleam_stdlib = { version = ">= 0.34.0 and < 2.0.0" }
gleeunit = { version = ">= 1.0.0 and < 2.0.0" }
pprint = { version = ">= 1.0.3 and < 2.0.0" }
testcontainers = { version = ">= 1.8.4 and < 2.0.0" }
4 changes: 2 additions & 2 deletions src/eventsourcing/postgres_store.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub fn new(
)
}

fn load_aggregate(
pub fn load_aggregate(
postgres_store: PostgresStore(entity, command, event, error),
aggregate_id: eventsourcing.AggregateId,
) {
Expand All @@ -80,7 +80,7 @@ fn load_aggregate(
eventsourcing.AggregateContext(aggregate_id:, aggregate:, sequence:)
}

fn load_events(
pub fn load_events(
postgres_store: PostgresStore(entity, command, event, error),
aggregate_id: eventsourcing.AggregateId,
) {
Expand Down
42 changes: 3 additions & 39 deletions test/eventsourcing_test.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub fn main() {
gleeunit.main()
}

pub fn memory_store_execute_open_account() {
pub fn memory_store_execute_open_account_test() {
let mem_store =
memory_store.new(BankAccount(opened: False, balance: 0.0), handle, apply)
let event_sourcing = eventsourcing.new(mem_store, [])
Expand All @@ -36,42 +36,6 @@ pub fn memory_store_execute_open_account() {
|> birdie.snap(title: "memory store open account")
}

pub fn postgres_store_execute_open_account_test() {
let postgres_store =
postgres_store.new(
pgo_config: pgo.Config(
..pgo.default_config(),
host: "localhost",
database: "postgres",
pool_size: 15,
password: option.Some("password"),
),
emtpy_entity: BankAccount(opened: False, balance: 0.0),
handle_command_function: handle,
apply_function: apply,
event_encoder: encode_event,
event_decoder: decode_event,
event_type: event_type(),
event_version: "1",
aggregate_type: aggregate_type(),
)
let event_sourcing = eventsourcing.new(postgres_store, [])
eventsourcing.execute(
event_sourcing,
"92085b42-032c-4d7a-84de-a86d67123858",
DepositMoney(10.0),
)
|> should.be_ok
|> should.equal(Nil)

postgres_store.load_aggregate(
postgres_store.eventstore,
"92085b42-032c-4d7a-84de-a86d67123858",
).aggregate.entity
|> pprint.format
|> birdie.snap(title: "memory store open account")
}

pub type BankAccount {
BankAccount(opened: Bool, balance: Float)
}
Expand Down Expand Up @@ -172,8 +136,8 @@ pub fn handle(
}
WithDrawMoney(amount) -> {
let balance = bank_account.balance -. amount
case amount >. 0.0 {
True -> Ok([CustomerDepositedCash(amount:, balance:)])
case amount >. 0.0 && balance >. 0.0 {
True -> Ok([CustomerWithdrewCash(amount:, balance:)])
False -> Error(Nil)
}
}
Expand Down

0 comments on commit 9ed6ec8

Please sign in to comment.