diff --git a/Cargo.lock b/Cargo.lock index c1d4a1b785..e7eaebf4dd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2488,7 +2488,6 @@ dependencies = [ "sha2", "sim-time", "sqlx", - "statements", "strum", "thiserror 1.0.69", "tokio", @@ -3472,7 +3471,6 @@ dependencies = [ "governance", "lana-ids", "serde", - "statements", "strum", "thiserror 1.0.69", "uuid", @@ -4502,21 +4500,6 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" -[[package]] -name = "statements" -version = "0.3.7-dev" -dependencies = [ - "audit", - "authz", - "cala-ledger", - "derive_builder", - "es-entity", - "serde", - "sqlx", - "strum", - "thiserror 1.0.69", -] - [[package]] name = "static_assertions" version = "1.1.0" diff --git a/Cargo.toml b/Cargo.toml index 6411a78a73..32395ca701 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,6 @@ members = [ "core/money", "core/chart-of-accounts", "core/deposit", - "core/statements", "lib/authz", "lib/audit", @@ -34,16 +33,34 @@ cala-ledger = { git = "https://github.com/galoymoney/cala.git", branch = "main" # cala-types = "0.3.1" anyhow = "1.0.95" -async-graphql = { version = "7.0.11", default-features = false, features = ["dataloader", "tracing", "chrono", "playground"] } +async-graphql = { version = "7.0.11", default-features = false, features = [ + "dataloader", + "tracing", + "chrono", + "playground", +] } async-graphql-axum = "7.0.9" async-trait = "0.1.80" axum = { version = "0.7.9", features = ["macros"] } -axum-extra = { version = "0.9.6", default-features = false, features = ["tracing", "typed-header"] } -chrono = { version = "0.4.31", features = ["clock", "serde"], default-features = false } +axum-extra = { version = "0.9.6", default-features = false, features = [ + "tracing", + "typed-header", +] } +chrono = { version = "0.4.31", features = [ + "clock", + "serde", +], default-features = false } clap = { version = "4.5", features = ["derive", "env"] } derive_builder = "0.20.0" -graphql_client = {version = "0.14.0", features = ["reqwest-rustls"]} -sqlx = { version = "0.8.2", features = [ "runtime-tokio-rustls", "postgres", "rust_decimal", "uuid", "chrono", "json" ] } +graphql_client = { version = "0.14.0", features = ["reqwest-rustls"] } +sqlx = { version = "0.8.2", features = [ + "runtime-tokio-rustls", + "postgres", + "rust_decimal", + "uuid", + "chrono", + "json", +] } thiserror = "1.0.69" uuid = { version = "1.11", features = ["serde", "v4"] } tracing = "0.1.40" @@ -51,10 +68,18 @@ tracing-opentelemetry = "0.25.0" tracing-subscriber = { version = "0.3.18", features = ["env-filter", "json"] } opentelemetry = { version = "0.24.0" } opentelemetry_sdk = { version = "0.24.1", features = ["rt-tokio"] } -opentelemetry-otlp = { version = "0.17.0", features = ["http-proto", "reqwest-client"] } +opentelemetry-otlp = { version = "0.17.0", features = [ + "http-proto", + "reqwest-client", +] } opentelemetry-http = "0.13" opentelemetry-semantic-conventions = "0.16.0" -tokio = { version = "1.43", features = ["rt-multi-thread", "macros", "time", "sync"] } +tokio = { version = "1.43", features = [ + "rt-multi-thread", + "macros", + "time", + "sync", +] } tokio-stream = { version = "0.1.16", features = ["sync"] } strum = { version = "0.26", features = ["derive"] } serde = { version = "1.0.214", features = ["derive"] } @@ -62,7 +87,10 @@ serde_yaml = "0.9.32" serde_json = "1.0.133" serde_with = "3.8.1" futures = "0.3.29" -reqwest = { version = "0.12", default-features = false, features = ["json", "rustls-tls"] } +reqwest = { version = "0.12", default-features = false, features = [ + "json", + "rustls-tls", +] } rust_decimal_macros = "1.34.2" rust_decimal = "1.35.0" rusty-money = { version = "0.4", features = ["iso", "crypto"] } @@ -72,12 +100,21 @@ hex = "0.4.3" hmac = "0.12.1" sha2 = "0.10.8" tower-http = { version = "0.5.2", features = ["cors"] } -sqlx-adapter = { version = "1.6.0", default-features = false, features = ["postgres", "runtime-tokio-rustls"]} +sqlx-adapter = { version = "1.6.0", default-features = false, features = [ + "postgres", + "runtime-tokio-rustls", +] } ory-kratos-client = "1.1.0" cached = { version = "0.53.1", features = ["async"] } gcp_auth = { version = "0.12.2", features = ["webpki-roots"] } -gcp-bigquery-client = { git = "https://github.com/bodymindarts/gcp-bigquery-client.git", branch = "feat--webpki", features = ["rust-tls"] } -cloud-storage = { version = "0.11.1",default-features = false, features = ["rustls-tls", "sync", "global-client"] } +gcp-bigquery-client = { git = "https://github.com/bodymindarts/gcp-bigquery-client.git", branch = "feat--webpki", features = [ + "rust-tls", +] } +cloud-storage = { version = "0.11.1", default-features = false, features = [ + "rustls-tls", + "sync", + "global-client", +] } rand = "0.8" [profile.release] diff --git a/Makefile b/Makefile index 228fff0c0d..4a4133b1b4 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,6 @@ sqlx-prepare: cd core/user && cargo sqlx prepare cd core/deposit && cargo sqlx prepare cd core/chart-of-accounts && cargo sqlx prepare - cd core/statements && cargo sqlx prepare cd lana/app && cargo sqlx prepare cd lana/dashboard && cargo sqlx prepare diff --git a/core/statements/.sqlx/query-144cc294e8a912592649fa574c78f759b591a77251ead79c1a45f0651a2f0ad0.json b/core/statements/.sqlx/query-144cc294e8a912592649fa574c78f759b591a77251ead79c1a45f0651a2f0ad0.json deleted file mode 100644 index c72407fb70..0000000000 --- a/core/statements/.sqlx/query-144cc294e8a912592649fa574c78f759b591a77251ead79c1a45f0651a2f0ad0.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "INSERT INTO core_trial_balance_statement_events (id, recorded_at, sequence, event_type, event) SELECT $1, $2, ROW_NUMBER() OVER () + $3, unnested.event_type, unnested.event FROM UNNEST($4::text[], $5::jsonb[]) AS unnested(event_type, event)", - "describe": { - "columns": [], - "parameters": { - "Left": [ - "Uuid", - "Timestamptz", - "Int8", - "TextArray", - "JsonbArray" - ] - }, - "nullable": [] - }, - "hash": "144cc294e8a912592649fa574c78f759b591a77251ead79c1a45f0651a2f0ad0" -} diff --git a/core/statements/.sqlx/query-1954a364cfb3c353baff51d874836e6eebb285fddd322a0b56c117364db5b9db.json b/core/statements/.sqlx/query-1954a364cfb3c353baff51d874836e6eebb285fddd322a0b56c117364db5b9db.json deleted file mode 100644 index 1180aa21c1..0000000000 --- a/core/statements/.sqlx/query-1954a364cfb3c353baff51d874836e6eebb285fddd322a0b56c117364db5b9db.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "WITH entities AS (SELECT id FROM core_trial_balance_statements WHERE id = $1) SELECT i.id AS \"entity_id: TrialBalanceStatementId\", e.sequence, e.event, e.recorded_at FROM entities i JOIN core_trial_balance_statement_events e ON i.id = e.id ORDER BY i.id, e.sequence", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "entity_id: TrialBalanceStatementId", - "type_info": "Uuid" - }, - { - "ordinal": 1, - "name": "sequence", - "type_info": "Int4" - }, - { - "ordinal": 2, - "name": "event", - "type_info": "Jsonb" - }, - { - "ordinal": 3, - "name": "recorded_at", - "type_info": "Timestamptz" - } - ], - "parameters": { - "Left": [ - "Uuid" - ] - }, - "nullable": [ - false, - false, - false, - false - ] - }, - "hash": "1954a364cfb3c353baff51d874836e6eebb285fddd322a0b56c117364db5b9db" -} diff --git a/core/statements/.sqlx/query-36e1c82fe21d6bc7d831339439de006962f303879b0c0ec7e39fa138feeb490d.json b/core/statements/.sqlx/query-36e1c82fe21d6bc7d831339439de006962f303879b0c0ec7e39fa138feeb490d.json deleted file mode 100644 index e5f8d31685..0000000000 --- a/core/statements/.sqlx/query-36e1c82fe21d6bc7d831339439de006962f303879b0c0ec7e39fa138feeb490d.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "UPDATE core_trial_balance_statements SET reference = $2 WHERE id = $1", - "describe": { - "columns": [], - "parameters": { - "Left": [ - "Uuid", - "Varchar" - ] - }, - "nullable": [] - }, - "hash": "36e1c82fe21d6bc7d831339439de006962f303879b0c0ec7e39fa138feeb490d" -} diff --git a/core/statements/.sqlx/query-37fabbe08b87896bf8ec6502ca509b70d86ab51bbc6f0ba827e94831faf55cf3.json b/core/statements/.sqlx/query-37fabbe08b87896bf8ec6502ca509b70d86ab51bbc6f0ba827e94831faf55cf3.json deleted file mode 100644 index 4511e1a8b9..0000000000 --- a/core/statements/.sqlx/query-37fabbe08b87896bf8ec6502ca509b70d86ab51bbc6f0ba827e94831faf55cf3.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "WITH entities AS (SELECT created_at, id FROM core_trial_balance_statements WHERE (COALESCE((created_at, id) < ($3, $2), $2 IS NULL)) ORDER BY created_at DESC, id DESC LIMIT $1) SELECT i.id AS \"entity_id: TrialBalanceStatementId\", e.sequence, e.event, e.recorded_at FROM entities i JOIN core_trial_balance_statement_events e ON i.id = e.id ORDER BY i.created_at desc, i.id desc, i.id, e.sequence", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "entity_id: TrialBalanceStatementId", - "type_info": "Uuid" - }, - { - "ordinal": 1, - "name": "sequence", - "type_info": "Int4" - }, - { - "ordinal": 2, - "name": "event", - "type_info": "Jsonb" - }, - { - "ordinal": 3, - "name": "recorded_at", - "type_info": "Timestamptz" - } - ], - "parameters": { - "Left": [ - "Int8", - "Uuid", - "Timestamptz" - ] - }, - "nullable": [ - false, - false, - false, - false - ] - }, - "hash": "37fabbe08b87896bf8ec6502ca509b70d86ab51bbc6f0ba827e94831faf55cf3" -} diff --git a/core/statements/.sqlx/query-5e23a46b500f9666ff427581b82d824b77132eeb6834b071c631a7ce4614262f.json b/core/statements/.sqlx/query-5e23a46b500f9666ff427581b82d824b77132eeb6834b071c631a7ce4614262f.json deleted file mode 100644 index 8c9cf7d801..0000000000 --- a/core/statements/.sqlx/query-5e23a46b500f9666ff427581b82d824b77132eeb6834b071c631a7ce4614262f.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "WITH entities AS (SELECT created_at, id FROM core_trial_balance_statements WHERE (COALESCE((created_at, id) > ($3, $2), $2 IS NULL)) ORDER BY created_at ASC, id ASC LIMIT $1) SELECT i.id AS \"entity_id: TrialBalanceStatementId\", e.sequence, e.event, e.recorded_at FROM entities i JOIN core_trial_balance_statement_events e ON i.id = e.id ORDER BY i.created_at asc, i.id asc, i.id, e.sequence", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "entity_id: TrialBalanceStatementId", - "type_info": "Uuid" - }, - { - "ordinal": 1, - "name": "sequence", - "type_info": "Int4" - }, - { - "ordinal": 2, - "name": "event", - "type_info": "Jsonb" - }, - { - "ordinal": 3, - "name": "recorded_at", - "type_info": "Timestamptz" - } - ], - "parameters": { - "Left": [ - "Int8", - "Uuid", - "Timestamptz" - ] - }, - "nullable": [ - false, - false, - false, - false - ] - }, - "hash": "5e23a46b500f9666ff427581b82d824b77132eeb6834b071c631a7ce4614262f" -} diff --git a/core/statements/.sqlx/query-67f873a34caf029f0353723cf5d62f3fc3dbfce673046aa7120c7e4cd704a87f.json b/core/statements/.sqlx/query-67f873a34caf029f0353723cf5d62f3fc3dbfce673046aa7120c7e4cd704a87f.json deleted file mode 100644 index f77bb6359b..0000000000 --- a/core/statements/.sqlx/query-67f873a34caf029f0353723cf5d62f3fc3dbfce673046aa7120c7e4cd704a87f.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "INSERT INTO core_trial_balance_statements (id, reference, created_at) VALUES ($1, $2, $3)", - "describe": { - "columns": [], - "parameters": { - "Left": [ - "Uuid", - "Varchar", - "Timestamptz" - ] - }, - "nullable": [] - }, - "hash": "67f873a34caf029f0353723cf5d62f3fc3dbfce673046aa7120c7e4cd704a87f" -} diff --git a/core/statements/.sqlx/query-696b0fa98b1239a20b181de2291bfe2a457db8cabddc17c0dad362ae135309d7.json b/core/statements/.sqlx/query-696b0fa98b1239a20b181de2291bfe2a457db8cabddc17c0dad362ae135309d7.json deleted file mode 100644 index 1f371f4bf7..0000000000 --- a/core/statements/.sqlx/query-696b0fa98b1239a20b181de2291bfe2a457db8cabddc17c0dad362ae135309d7.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "WITH entities AS (SELECT id FROM core_trial_balance_statements WHERE reference = $1) SELECT i.id AS \"entity_id: TrialBalanceStatementId\", e.sequence, e.event, e.recorded_at FROM entities i JOIN core_trial_balance_statement_events e ON i.id = e.id ORDER BY i.id, e.sequence", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "entity_id: TrialBalanceStatementId", - "type_info": "Uuid" - }, - { - "ordinal": 1, - "name": "sequence", - "type_info": "Int4" - }, - { - "ordinal": 2, - "name": "event", - "type_info": "Jsonb" - }, - { - "ordinal": 3, - "name": "recorded_at", - "type_info": "Timestamptz" - } - ], - "parameters": { - "Left": [ - "Text" - ] - }, - "nullable": [ - false, - false, - false, - false - ] - }, - "hash": "696b0fa98b1239a20b181de2291bfe2a457db8cabddc17c0dad362ae135309d7" -} diff --git a/core/statements/.sqlx/query-b5463577c3ee7839f3dce5be2d7f620c0bc40c539826ec49f7d5a538482c1345.json b/core/statements/.sqlx/query-b5463577c3ee7839f3dce5be2d7f620c0bc40c539826ec49f7d5a538482c1345.json deleted file mode 100644 index 5e8c8815c1..0000000000 --- a/core/statements/.sqlx/query-b5463577c3ee7839f3dce5be2d7f620c0bc40c539826ec49f7d5a538482c1345.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "INSERT INTO core_trial_balance_statement_events (id, recorded_at, sequence, event_type, event) SELECT unnested.id, $1, unnested.sequence, unnested.event_type, unnested.event FROM UNNEST($2::UUID[], $3::INT[], $4::TEXT[], $5::JSONB[]) AS unnested(id, sequence, event_type, event)", - "describe": { - "columns": [], - "parameters": { - "Left": [ - "Timestamptz", - "UuidArray", - "Int4Array", - "TextArray", - "JsonbArray" - ] - }, - "nullable": [] - }, - "hash": "b5463577c3ee7839f3dce5be2d7f620c0bc40c539826ec49f7d5a538482c1345" -} diff --git a/core/statements/.sqlx/query-dbbc28e42131658a0dbdaa54f90735753582ae9d707fcf39aa3bb133d8b74b9c.json b/core/statements/.sqlx/query-dbbc28e42131658a0dbdaa54f90735753582ae9d707fcf39aa3bb133d8b74b9c.json deleted file mode 100644 index cce98216cd..0000000000 --- a/core/statements/.sqlx/query-dbbc28e42131658a0dbdaa54f90735753582ae9d707fcf39aa3bb133d8b74b9c.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "SELECT i.id AS \"id: TrialBalanceStatementId\", e.sequence, e.event, e.recorded_at FROM core_trial_balance_statements i JOIN core_trial_balance_statement_events e ON i.id = e.id WHERE i.id = ANY($1) ORDER BY i.id, e.sequence", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "id: TrialBalanceStatementId", - "type_info": "Uuid" - }, - { - "ordinal": 1, - "name": "sequence", - "type_info": "Int4" - }, - { - "ordinal": 2, - "name": "event", - "type_info": "Jsonb" - }, - { - "ordinal": 3, - "name": "recorded_at", - "type_info": "Timestamptz" - } - ], - "parameters": { - "Left": [ - "UuidArray" - ] - }, - "nullable": [ - false, - false, - false, - false - ] - }, - "hash": "dbbc28e42131658a0dbdaa54f90735753582ae9d707fcf39aa3bb133d8b74b9c" -} diff --git a/core/statements/.sqlx/query-f562c1e35627c40bfc6883afa52284930d17e54ede2622d97048baf953262d0b.json b/core/statements/.sqlx/query-f562c1e35627c40bfc6883afa52284930d17e54ede2622d97048baf953262d0b.json deleted file mode 100644 index ba9bb21a20..0000000000 --- a/core/statements/.sqlx/query-f562c1e35627c40bfc6883afa52284930d17e54ede2622d97048baf953262d0b.json +++ /dev/null @@ -1,41 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "WITH entities AS (SELECT id FROM core_trial_balance_statements WHERE (COALESCE(id < $2, true)) ORDER BY id DESC LIMIT $1) SELECT i.id AS \"entity_id: TrialBalanceStatementId\", e.sequence, e.event, e.recorded_at FROM entities i JOIN core_trial_balance_statement_events e ON i.id = e.id ORDER BY i.id desc, i.id, e.sequence", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "entity_id: TrialBalanceStatementId", - "type_info": "Uuid" - }, - { - "ordinal": 1, - "name": "sequence", - "type_info": "Int4" - }, - { - "ordinal": 2, - "name": "event", - "type_info": "Jsonb" - }, - { - "ordinal": 3, - "name": "recorded_at", - "type_info": "Timestamptz" - } - ], - "parameters": { - "Left": [ - "Int8", - "Uuid" - ] - }, - "nullable": [ - false, - false, - false, - false - ] - }, - "hash": "f562c1e35627c40bfc6883afa52284930d17e54ede2622d97048baf953262d0b" -} diff --git a/core/statements/.sqlx/query-f7a932907a1feac3d3a269e8cad558bb9908942dc184775ba24a1bc5d8a5fe40.json b/core/statements/.sqlx/query-f7a932907a1feac3d3a269e8cad558bb9908942dc184775ba24a1bc5d8a5fe40.json deleted file mode 100644 index 87b2529a2c..0000000000 --- a/core/statements/.sqlx/query-f7a932907a1feac3d3a269e8cad558bb9908942dc184775ba24a1bc5d8a5fe40.json +++ /dev/null @@ -1,41 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "WITH entities AS (SELECT id FROM core_trial_balance_statements WHERE (COALESCE(id > $2, true)) ORDER BY id ASC LIMIT $1) SELECT i.id AS \"entity_id: TrialBalanceStatementId\", e.sequence, e.event, e.recorded_at FROM entities i JOIN core_trial_balance_statement_events e ON i.id = e.id ORDER BY i.id asc, i.id, e.sequence", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "entity_id: TrialBalanceStatementId", - "type_info": "Uuid" - }, - { - "ordinal": 1, - "name": "sequence", - "type_info": "Int4" - }, - { - "ordinal": 2, - "name": "event", - "type_info": "Jsonb" - }, - { - "ordinal": 3, - "name": "recorded_at", - "type_info": "Timestamptz" - } - ], - "parameters": { - "Left": [ - "Int8", - "Uuid" - ] - }, - "nullable": [ - false, - false, - false, - false - ] - }, - "hash": "f7a932907a1feac3d3a269e8cad558bb9908942dc184775ba24a1bc5d8a5fe40" -} diff --git a/core/statements/Cargo.toml b/core/statements/Cargo.toml deleted file mode 100644 index f14814f752..0000000000 --- a/core/statements/Cargo.toml +++ /dev/null @@ -1,20 +0,0 @@ -[package] -name = "statements" -version = "0.3.7-dev" -edition = "2021" - -[features] -fail-on-warnings = [] - -[dependencies] -audit = { path = "../../lib/audit" } -authz = { path = "../../lib/authz" } - -cala-ledger = { workspace = true } -es-entity = { workspace = true } -sqlx = { workspace = true } - -derive_builder = { workspace = true } -serde = { workspace = true } -strum = { workspace = true } -thiserror = { workspace = true } diff --git a/core/statements/src/auth.rs b/core/statements/src/auth.rs deleted file mode 100644 index 2e29c92b82..0000000000 --- a/core/statements/src/auth.rs +++ /dev/null @@ -1,104 +0,0 @@ -use std::{fmt::Display, str::FromStr}; - -use authz::AllOrOne; - -use super::primitives::StatementId; - -pub type StatementAllOrOne = AllOrOne; - -#[derive(Clone, Copy, Debug, PartialEq, strum::EnumDiscriminants)] -#[strum_discriminants(derive(strum::Display, strum::EnumString))] -#[strum_discriminants(strum(serialize_all = "kebab-case"))] -pub enum CoreStatementsAction { - StatementAction(StatementAction), -} - -#[derive(Clone, Copy, Debug, PartialEq, strum::EnumDiscriminants)] -#[strum_discriminants(derive(strum::Display, strum::EnumString))] -#[strum_discriminants(strum(serialize_all = "kebab-case"))] -pub enum CoreStatementsObject { - Statement(StatementAllOrOne), -} - -impl CoreStatementsObject { - pub fn statement(id: StatementId) -> Self { - CoreStatementsObject::Statement(AllOrOne::ById(id)) - } - - pub fn all_statements() -> Self { - CoreStatementsObject::Statement(AllOrOne::All) - } -} - -impl Display for CoreStatementsObject { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let discriminant = CoreStatementsObjectDiscriminants::from(self); - use CoreStatementsObject::*; - match self { - Statement(obj_ref) => write!(f, "{}/{}", discriminant, obj_ref), - } - } -} - -impl FromStr for CoreStatementsObject { - type Err = &'static str; - - fn from_str(s: &str) -> Result { - let (entity, id) = s.split_once('/').expect("missing slash"); - use CoreStatementsObjectDiscriminants::*; - let res = match entity.parse().expect("invalid entity") { - Statement => { - let obj_ref = id - .parse() - .map_err(|_| "could not parse CoreStatementObject")?; - CoreStatementsObject::Statement(obj_ref) - } - }; - Ok(res) - } -} - -impl CoreStatementsAction { - pub const STATEMENT_CREATE: Self = - CoreStatementsAction::StatementAction(StatementAction::Create); - pub const STATEMENT_READ: Self = CoreStatementsAction::StatementAction(StatementAction::Read); - pub const STATEMENT_LIST: Self = CoreStatementsAction::StatementAction(StatementAction::List); -} - -impl Display for CoreStatementsAction { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{}:", CoreStatementsActionDiscriminants::from(self))?; - use CoreStatementsAction::*; - match self { - StatementAction(action) => action.fmt(f), - } - } -} - -impl FromStr for CoreStatementsAction { - type Err = strum::ParseError; - - fn from_str(s: &str) -> Result { - let (entity, action) = s.split_once(':').expect("missing colon"); - let res = match entity.parse()? { - CoreStatementsActionDiscriminants::StatementAction => { - CoreStatementsAction::from(action.parse::()?) - } - }; - Ok(res) - } -} - -#[derive(PartialEq, Clone, Copy, Debug, strum::Display, strum::EnumString)] -#[strum(serialize_all = "kebab-case")] -pub enum StatementAction { - Create, - Read, - List, -} - -impl From for CoreStatementsAction { - fn from(action: StatementAction) -> Self { - CoreStatementsAction::StatementAction(action) - } -} diff --git a/core/statements/src/error.rs b/core/statements/src/error.rs deleted file mode 100644 index 9de5acb9c5..0000000000 --- a/core/statements/src/error.rs +++ /dev/null @@ -1,15 +0,0 @@ -use thiserror::Error; - -#[derive(Error, Debug)] -pub enum CoreStatementsError { - #[error("CoreStatementsError - Sqlx: {0}")] - Sqlx(#[from] sqlx::Error), - #[error("CoreStatementsError - AuditError: {0}")] - AuditError(#[from] audit::error::AuditError), - #[error("CoreStatementsError - TrialBalanceStatementError: {0}")] - TrialBalanceStatementError(#[from] crate::trial_balance::error::TrialBalanceStatementError), - #[error("CoreStatementsError - TrialBalanceStatementLedgerError: {0}")] - TrialBalanceStatementLedgerError( - #[from] crate::trial_balance::ledger::error::TrialBalanceStatementLedgerError, - ), -} diff --git a/core/statements/src/lib.rs b/core/statements/src/lib.rs deleted file mode 100644 index 02a4f738f9..0000000000 --- a/core/statements/src/lib.rs +++ /dev/null @@ -1,150 +0,0 @@ -#![cfg_attr(feature = "fail-on-warnings", deny(warnings))] -#![cfg_attr(feature = "fail-on-warnings", deny(clippy::all))] - -mod auth; -pub mod error; -mod primitives; -mod trial_balance; - -use cala_ledger::CalaLedger; - -use audit::AuditSvc; -use authz::PermissionCheck; - -pub use auth::*; -use error::*; -pub use primitives::*; -use trial_balance::*; - -pub struct CoreStatements -where - Perms: PermissionCheck, -{ - pool: sqlx::PgPool, - trial_balance_repo: TrialBalanceStatementRepo, - trial_balance_ledger: TrialBalanceStatementLedger, - authz: Perms, - journal_id: LedgerJournalId, -} - -impl Clone for CoreStatements -where - Perms: PermissionCheck, -{ - fn clone(&self) -> Self { - Self { - pool: self.pool.clone(), - trial_balance_repo: self.trial_balance_repo.clone(), - trial_balance_ledger: self.trial_balance_ledger.clone(), - authz: self.authz.clone(), - journal_id: self.journal_id, - } - } -} - -impl CoreStatements -where - Perms: PermissionCheck, - <::Audit as AuditSvc>::Action: From, - <::Audit as AuditSvc>::Object: From, -{ - pub async fn init( - pool: &sqlx::PgPool, - authz: &Perms, - cala: &CalaLedger, - journal_id: LedgerJournalId, - ) -> Result { - let trial_balance_repo = TrialBalanceStatementRepo::new(pool); - let trial_balance_ledger = TrialBalanceStatementLedger::new(cala, journal_id); - - let res = Self { - pool: pool.clone(), - trial_balance_repo, - trial_balance_ledger, - authz: authz.clone(), - journal_id, - }; - Ok(res) - } - - pub async fn create_trial_balance_statement( - &self, - id: impl Into, - name: String, - reference: String, - ) -> Result { - let id = id.into(); - let statement_id: StatementId = id.into(); - let account_set_id: LedgerAccountSetId = id.into(); - - let mut op = self.trial_balance_repo.begin_op().await?; - - let audit_info = self - .authz - .audit() - .record_system_entry_in_tx( - op.tx(), - CoreStatementsObject::statement(statement_id), - CoreStatementsAction::STATEMENT_CREATE, - ) - .await?; - - let new_trial_balance = NewTrialBalanceStatement::builder() - .id(id) - .name(name.to_string()) - .reference(reference) - .audit_info(audit_info) - .build() - .expect("Could not build new chart of accounts"); - - let trial_balance = self - .trial_balance_repo - .create_in_op(&mut op, new_trial_balance) - .await?; - - self.trial_balance_ledger - .create(op, account_set_id, &name) - .await?; - - Ok(trial_balance) - } - - pub async fn find_by_reference( - &self, - reference: String, - ) -> Result, CoreStatementsError> { - let mut op = self.trial_balance_repo.begin_op().await?; - self.authz - .audit() - .record_system_entry_in_tx( - op.tx(), - CoreStatementsObject::all_statements(), - CoreStatementsAction::STATEMENT_LIST, - ) - .await?; - - let statement = match self.trial_balance_repo.find_by_reference(reference).await { - Ok(statement) => Some(statement), - Err(e) if e.was_not_found() => None, - Err(e) => return Err(e.into()), - }; - op.commit().await?; - - Ok(statement) - } - - pub async fn add_to_trial_balance_statement( - &self, - statement_id: TrialBalanceStatementId, - member_id: impl Into, - ) -> Result<(), CoreStatementsError> { - let member_id = member_id.into(); - - let op = es_entity::DbOp::init(&self.pool).await?; - self.trial_balance_ledger - .add_member(op, statement_id, member_id) - .await?; - - Ok(()) - } -} diff --git a/core/statements/src/primitives.rs b/core/statements/src/primitives.rs deleted file mode 100644 index ce3d5f6214..0000000000 --- a/core/statements/src/primitives.rs +++ /dev/null @@ -1,11 +0,0 @@ -pub use cala_ledger::{ - primitives::AccountSetId as LedgerAccountSetId, primitives::JournalId as LedgerJournalId, -}; - -es_entity::entity_id! { - StatementId, - TrialBalanceStatementId; - - TrialBalanceStatementId => StatementId, - TrialBalanceStatementId => LedgerAccountSetId, -} diff --git a/core/statements/src/trial_balance/entity.rs b/core/statements/src/trial_balance/entity.rs deleted file mode 100644 index da4d46698a..0000000000 --- a/core/statements/src/trial_balance/entity.rs +++ /dev/null @@ -1,85 +0,0 @@ -use derive_builder::Builder; -use serde::{Deserialize, Serialize}; - -use audit::AuditInfo; - -use es_entity::*; - -use crate::primitives::TrialBalanceStatementId; - -pub use super::error::*; - -#[derive(EsEvent, Debug, Clone, Serialize, Deserialize)] -#[serde(tag = "type", rename_all = "snake_case")] -#[es_event(id = "TrialBalanceStatementId")] -pub enum TrialBalanceStatementEvent { - Initialized { - id: TrialBalanceStatementId, - name: String, - reference: String, - audit_info: AuditInfo, - }, -} - -#[derive(EsEntity, Builder)] -#[builder(pattern = "owned", build_fn(error = "EsEntityError"))] -pub struct TrialBalanceStatement { - pub id: TrialBalanceStatementId, - pub name: String, - pub reference: String, - pub(super) events: EntityEvents, -} - -impl TryFromEvents for TrialBalanceStatement { - fn try_from_events( - events: EntityEvents, - ) -> Result { - let mut builder = TrialBalanceStatementBuilder::default(); - for event in events.iter_all() { - match event { - TrialBalanceStatementEvent::Initialized { - id, - name, - reference, - .. - } => { - builder = builder - .id(*id) - .name(name.to_string()) - .reference(reference.to_string()) - } - } - } - builder.events(events).build() - } -} - -#[derive(Debug, Builder)] -pub struct NewTrialBalanceStatement { - #[builder(setter(into))] - pub(super) id: TrialBalanceStatementId, - pub(super) name: String, - pub(super) reference: String, - #[builder(setter(into))] - pub audit_info: AuditInfo, -} - -impl NewTrialBalanceStatement { - pub fn builder() -> NewTrialBalanceStatementBuilder { - NewTrialBalanceStatementBuilder::default() - } -} - -impl IntoEvents for NewTrialBalanceStatement { - fn into_events(self) -> EntityEvents { - EntityEvents::init( - self.id, - [TrialBalanceStatementEvent::Initialized { - id: self.id, - name: self.name, - reference: self.reference, - audit_info: self.audit_info, - }], - ) - } -} diff --git a/core/statements/src/trial_balance/error.rs b/core/statements/src/trial_balance/error.rs deleted file mode 100644 index 9911e77127..0000000000 --- a/core/statements/src/trial_balance/error.rs +++ /dev/null @@ -1,13 +0,0 @@ -use thiserror::Error; - -#[derive(Error, Debug)] -pub enum TrialBalanceStatementError { - #[error("TrialBalanceStatementError - Sqlx: {0}")] - Sqlx(#[from] sqlx::Error), - #[error("TrialBalanceStatementError - EsEntityError: {0}")] - EsEntityError(es_entity::EsEntityError), - #[error("TrialBalanceStatementError - CursorDestructureError: {0}")] - CursorDestructureError(#[from] es_entity::CursorDestructureError), -} - -es_entity::from_es_entity_error!(TrialBalanceStatementError); diff --git a/core/statements/src/trial_balance/ledger/error.rs b/core/statements/src/trial_balance/ledger/error.rs deleted file mode 100644 index 44df94e080..0000000000 --- a/core/statements/src/trial_balance/ledger/error.rs +++ /dev/null @@ -1,11 +0,0 @@ -use thiserror::Error; - -#[derive(Error, Debug)] -pub enum TrialBalanceStatementLedgerError { - #[error("TrialBalanceStatementLedgerError - Sqlx: {0}")] - Sqlx(#[from] sqlx::Error), - #[error("TrialBalanceStatementLedgerError - CalaLedger: {0}")] - CalaLedger(#[from] cala_ledger::error::LedgerError), - #[error("TrialBalanceStatementLedgerError - CalaAccountSetError: {0}")] - CalaAccountSet(#[from] cala_ledger::account_set::error::AccountSetError), -} diff --git a/core/statements/src/trial_balance/ledger/mod.rs b/core/statements/src/trial_balance/ledger/mod.rs deleted file mode 100644 index ae1268976a..0000000000 --- a/core/statements/src/trial_balance/ledger/mod.rs +++ /dev/null @@ -1,65 +0,0 @@ -pub mod error; - -use cala_ledger::{account_set::NewAccountSet, CalaLedger, DebitOrCredit, JournalId}; - -use crate::primitives::LedgerAccountSetId; - -use error::*; - -#[derive(Clone)] -pub struct TrialBalanceStatementLedger { - cala: CalaLedger, - journal_id: JournalId, -} - -impl TrialBalanceStatementLedger { - pub fn new(cala: &CalaLedger, journal_id: JournalId) -> Self { - Self { - cala: cala.clone(), - journal_id, - } - } - - pub async fn create( - &self, - op: es_entity::DbOp<'_>, - statement_id: impl Into, - name: &str, - ) -> Result<(), TrialBalanceStatementLedgerError> { - let mut op = self.cala.ledger_operation_from_db_op(op); - - let new_account_set = NewAccountSet::builder() - .id(statement_id) - .journal_id(self.journal_id) - .name(name) - .description(name) - .normal_balance_type(DebitOrCredit::Debit) - .build() - .expect("Could not build new account set"); - self.cala - .account_sets() - .create_in_op(&mut op, new_account_set) - .await?; - - op.commit().await?; - Ok(()) - } - - pub async fn add_member( - &self, - op: es_entity::DbOp<'_>, - statement_id: impl Into, - member: LedgerAccountSetId, - ) -> Result<(), TrialBalanceStatementLedgerError> { - let statement_id = statement_id.into(); - - let mut op = self.cala.ledger_operation_from_db_op(op); - self.cala - .account_sets() - .add_member_in_op(&mut op, statement_id, member) - .await?; - - op.commit().await?; - Ok(()) - } -} diff --git a/core/statements/src/trial_balance/mod.rs b/core/statements/src/trial_balance/mod.rs deleted file mode 100644 index 50097fb986..0000000000 --- a/core/statements/src/trial_balance/mod.rs +++ /dev/null @@ -1,8 +0,0 @@ -mod entity; -pub mod error; -pub mod ledger; -mod repo; - -pub(super) use entity::*; -pub use ledger::*; -pub(super) use repo::*; diff --git a/core/statements/src/trial_balance/repo.rs b/core/statements/src/trial_balance/repo.rs deleted file mode 100644 index 2a4940fe56..0000000000 --- a/core/statements/src/trial_balance/repo.rs +++ /dev/null @@ -1,24 +0,0 @@ -use sqlx::PgPool; - -use es_entity::*; - -use crate::primitives::TrialBalanceStatementId; - -use super::entity::*; - -#[derive(EsRepo, Clone)] -#[es_repo( - entity = "TrialBalanceStatement", - err = "TrialBalanceStatementError", - columns(reference(ty = "String")), - tbl_prefix = "core" -)] -pub struct TrialBalanceStatementRepo { - pool: PgPool, -} - -impl TrialBalanceStatementRepo { - pub fn new(pool: &PgPool) -> Self { - Self { pool: pool.clone() } - } -} diff --git a/lana/app/Cargo.toml b/lana/app/Cargo.toml index 626e9cb99f..3ec89958a8 100644 --- a/lana/app/Cargo.toml +++ b/lana/app/Cargo.toml @@ -20,7 +20,6 @@ core-money = { path = "../../core/money" } core-user = { path = "../../core/user", features = ["graphql"] } deposit = { path = "../../core/deposit", features = ["graphql"] } chart-of-accounts = { path = "../../core/chart-of-accounts" } -statements = { path = "../../core/statements" } tracing-utils = { path = "../../lib/tracing-utils", features = ["http"] } job = { path = "../../lib/job" } diff --git a/lana/app/migrations/20240517074612_core_setup.sql b/lana/app/migrations/20240517074612_core_setup.sql index 10a1c1a22c..981759c18b 100644 --- a/lana/app/migrations/20240517074612_core_setup.sql +++ b/lana/app/migrations/20240517074612_core_setup.sql @@ -61,23 +61,6 @@ CREATE TABLE core_chart_events ( UNIQUE(id, sequence) ); - -CREATE TABLE core_trial_balance_statements ( - id UUID PRIMARY KEY, - reference VARCHAR NOT NULL UNIQUE, - created_at TIMESTAMPTZ NOT NULL -); - -CREATE TABLE core_trial_balance_statement_events ( - id UUID NOT NULL REFERENCES core_trial_balance_statements(id), - sequence INT NOT NULL, - event_type VARCHAR NOT NULL, - event JSONB NOT NULL, - recorded_at TIMESTAMPTZ NOT NULL, - UNIQUE(id, sequence) -); - - CREATE TABLE deposit_accounts ( id UUID PRIMARY KEY, account_holder_id UUID NOT NULL, diff --git a/lana/app/src/app/error.rs b/lana/app/src/app/error.rs index 659a66c5c6..9d3edb2829 100644 --- a/lana/app/src/app/error.rs +++ b/lana/app/src/app/error.rs @@ -34,8 +34,6 @@ pub enum ApplicationError { CalaError(#[from] cala_ledger::error::LedgerError), #[error("ApplicationError - ChartOfAccountsError: {0}")] ChartOfAccountsError(#[from] chart_of_accounts::error::CoreChartOfAccountsError), - #[error("ApplicationError - StatementsError: {0}")] - StatementsError(#[from] statements::error::CoreStatementsError), #[error("ApplicationError - DepositError: {0}")] DepositError(#[from] crate::deposit::error::CoreDepositError), } diff --git a/lana/app/src/lib.rs b/lana/app/src/lib.rs index fe00ec0afe..af648d1f64 100644 --- a/lana/app/src/lib.rs +++ b/lana/app/src/lib.rs @@ -72,8 +72,3 @@ pub mod chart_of_accounts { pub type ChartOfAccounts = chart_of_accounts::CoreChartOfAccounts; } - -pub mod statements { - - pub type Statements = statements::CoreStatements; -} diff --git a/lana/rbac-types/Cargo.toml b/lana/rbac-types/Cargo.toml index f8173d67c0..0ad5c50186 100644 --- a/lana/rbac-types/Cargo.toml +++ b/lana/rbac-types/Cargo.toml @@ -14,7 +14,6 @@ dashboard = { path = "../dashboard" } governance = { path = "../../core/governance" } core-user = { path = "../../core/user" } chart-of-accounts = { path = "../../core/chart-of-accounts" } -statements = { path = "../../core/statements" } deposit = { path = "../../core/deposit" } audit = { path = "../../lib/audit" } authz = { path = "../../lib/authz" } diff --git a/lana/rbac-types/src/action.rs b/lana/rbac-types/src/action.rs index ef0ee38cfa..5963892eb3 100644 --- a/lana/rbac-types/src/action.rs +++ b/lana/rbac-types/src/action.rs @@ -5,7 +5,6 @@ use core_user::CoreUserAction; use dashboard::DashboardModuleAction; use deposit::CoreDepositAction; use governance::GovernanceAction; -use statements::CoreStatementsAction; #[derive(Clone, Copy, Debug, PartialEq, strum::EnumDiscriminants)] #[strum_discriminants(derive(strum::Display, strum::EnumString))] @@ -15,7 +14,6 @@ pub enum LanaAction { Governance(GovernanceAction), User(CoreUserAction), ChartOfAccounts(CoreChartOfAccountsAction), - Statements(CoreStatementsAction), Dashboard(DashboardModuleAction), Deposit(CoreDepositAction), } @@ -45,11 +43,6 @@ impl From for LanaAction { LanaAction::ChartOfAccounts(action) } } -impl From for LanaAction { - fn from(action: CoreStatementsAction) -> Self { - LanaAction::Statements(action) - } -} impl From for LanaAction { fn from(action: CoreDepositAction) -> Self { LanaAction::Deposit(action) @@ -66,7 +59,6 @@ impl Display for LanaAction { User(action) => action.fmt(f), Dashboard(action) => action.fmt(f), ChartOfAccounts(action) => action.fmt(f), - Statements(action) => action.fmt(f), Deposit(action) => action.fmt(f), } } @@ -84,7 +76,6 @@ impl FromStr for LanaAction { User => LanaAction::from(action.parse::()?), Dashboard => LanaAction::from(action.parse::()?), ChartOfAccounts => LanaAction::from(action.parse::()?), - Statements => LanaAction::from(action.parse::()?), Deposit => LanaAction::from(action.parse::()?), }; Ok(res) diff --git a/lana/rbac-types/src/object.rs b/lana/rbac-types/src/object.rs index 6a9b2da3c9..c3b6c97a7f 100644 --- a/lana/rbac-types/src/object.rs +++ b/lana/rbac-types/src/object.rs @@ -7,7 +7,6 @@ use dashboard::DashboardModuleObject; use deposit::CoreDepositObject; use governance::GovernanceObject; use lana_ids::CustomerId; -use statements::CoreStatementsObject; #[derive(Clone, Copy, Debug, PartialEq, strum::EnumDiscriminants)] #[strum_discriminants(derive(strum::Display, strum::EnumString))] @@ -17,7 +16,6 @@ pub enum LanaObject { Governance(GovernanceObject), User(UserObject), ChartOfAccounts(CoreChartOfAccountsObject), - Statements(CoreStatementsObject), Deposit(CoreDepositObject), Dashboard(DashboardModuleObject), } @@ -47,11 +45,6 @@ impl From for LanaObject { LanaObject::ChartOfAccounts(object) } } -impl From for LanaObject { - fn from(object: CoreStatementsObject) -> Self { - LanaObject::Statements(object) - } -} impl From for LanaObject { fn from(object: CoreDepositObject) -> Self { LanaObject::Deposit(object) @@ -67,7 +60,6 @@ impl Display for LanaObject { Governance(action) => action.fmt(f), User(action) => action.fmt(f), ChartOfAccounts(action) => action.fmt(f), - Statements(action) => action.fmt(f), Deposit(action) => action.fmt(f), Dashboard(action) => action.fmt(f), } @@ -85,7 +77,6 @@ impl FromStr for LanaObject { Governance => LanaObject::from(object.parse::()?), User => LanaObject::from(object.parse::()?), ChartOfAccounts => LanaObject::from(object.parse::()?), - Statements => LanaObject::from(object.parse::()?), Deposit => LanaObject::from(object.parse::()?), Dashboard => LanaObject::from( object