From af407fe5c3e1d5b8b315db029805fa7290c83fae Mon Sep 17 00:00:00 2001 From: rtkay123 Date: Sun, 10 Aug 2025 12:09:22 +0200 Subject: feat(pseudonyms): proto definitions --- lib/warden-core/Cargo.toml | 4 +- lib/warden-core/build.rs | 82 +++++++++------- lib/warden-core/src/google/parser.rs | 1 + lib/warden-core/src/google/parser/dt.rs | 161 +++++++++++++++++--------------- lib/warden-core/src/iso20022.rs | 4 - lib/warden-core/src/lib.rs | 16 +++- lib/warden-core/src/pseudonyms.rs | 15 +++ 7 files changed, 163 insertions(+), 120 deletions(-) create mode 100644 lib/warden-core/src/pseudonyms.rs (limited to 'lib') diff --git a/lib/warden-core/Cargo.toml b/lib/warden-core/Cargo.toml index bdf0af0..759e018 100644 --- a/lib/warden-core/Cargo.toml +++ b/lib/warden-core/Cargo.toml @@ -17,12 +17,14 @@ serde = { workspace = true, optional = true } serde_json = { workspace = true, optional = true } time = { workspace = true, optional = true } tonic = { workspace = true, optional = true } +tonic-prost = { version = "0.14.1", optional = true } tonic-types = { version = "0.14.0", optional = true } utoipa = { workspace = true, optional = true } [features] default = [] -iso20022 = ["dep:prost", "dep:tonic", "dep:tonic-types"] +message = ["dep:prost", "dep:tonic", "dep:tonic-types", "dep:tonic-prost"] +pseudonyms = ["dep:prost", "dep:tonic", "dep:tonic-types", "dep:tonic-prost"] serde = ["dep:serde", "serde/derive", "dep:serde_json"] serde-time = [ "time", diff --git a/lib/warden-core/build.rs b/lib/warden-core/build.rs index 46793ed..57e20e0 100644 --- a/lib/warden-core/build.rs +++ b/lib/warden-core/build.rs @@ -1,29 +1,48 @@ -#[cfg(feature = "iso20022")] +#[cfg(any(feature = "message", feature = "pseudonyms"))] enum Entity { - #[cfg(feature = "iso20022")] + #[cfg(feature = "message")] ISO2022, + #[cfg(feature = "pseudonyms")] + Pseudonyms, } -#[cfg(feature = "iso20022")] +#[cfg(any(feature = "message", feature = "pseudonyms"))] impl Entity { fn protos(&self) -> Vec<&'static str> { - let mut res: Vec<&'static str> = vec![]; + let mut res: Vec<&'static str> = vec![ + // "proto/googleapis/google/type/date.proto", + // "proto/googleapis/google/type/money.proto", + // "proto/googleapis/google/type/latlng.proto", + ]; - #[cfg(feature = "iso20022")] + #[cfg(feature = "message")] fn iso20022_protos() -> Vec<&'static str> { vec![ - "proto/iso20022/pacs_008_001_12.proto", - "proto/iso20022/pacs_002_001_12.proto", - "proto/googleapis/google/type/money.proto", + // "proto/iso20022/pacs_008_001_12.proto", + // "proto/iso20022/pacs_002_001_12.proto", "proto/warden_message.proto", ] } + #[cfg(feature = "pseudonyms")] + fn pseudonyms_protos() -> Vec<&'static str> { + vec![ + "proto/pseudonyms/account.proto", + "proto/pseudonyms/entity.proto", + "proto/pseudonyms/account_holder.proto", + "proto/pseudonyms/transaction_relationship.proto", + ] + } + match self { - #[cfg(feature = "iso20022")] + #[cfg(feature = "message")] Entity::ISO2022 => { res.extend(iso20022_protos()); } + #[cfg(feature = "pseudonyms")] + Entity::Pseudonyms => { + res.extend(pseudonyms_protos()); + } } res } @@ -32,25 +51,26 @@ impl Entity { fn main() -> Result<(), Box> { println!("cargo:rerun-if-changed=../../proto"); - #[cfg(feature = "iso20022")] - build_proto("iso20022", Entity::ISO2022)?; +#[cfg(any(feature = "message", feature = "pseudonyms"))] + let mut protos: Vec<&'static str> = vec![]; + + #[cfg(feature = "message")] + protos.extend(Entity::ISO2022.protos()); + + #[cfg(feature = "pseudonyms")] + protos.extend(Entity::Pseudonyms.protos()); + +#[cfg(any(feature = "message", feature = "pseudonyms"))] + build_proto(&protos)?; Ok(()) } -#[cfg(feature = "iso20022")] -fn build_proto(package: &str, entity: Entity) -> Result<(), Box> { +#[cfg(any(feature = "message", feature = "pseudonyms"))] +fn build_proto(protos: &[&str]) -> Result<(), Box> { let out_dir = std::path::PathBuf::from(std::env::var("OUT_DIR").unwrap()); - let config = tonic_prost_build::configure() - .server_mod_attribute( - package, - format!("#[cfg(feature = \"rpc-server-{package}\")] #[cfg_attr(docsrs, doc(cfg(feature = \"rpc-server-{package}\")))]"), - ) - .client_mod_attribute( - package, - format!("#[cfg(feature = \"rpc-client-{package}\")] #[cfg_attr(docsrs, doc(cfg(feature = \"rpc-client-{package}\")))]"), - ); + let config = tonic_prost_build::configure(); #[cfg(feature = "serde")] let config = add_serde(config); @@ -59,26 +79,18 @@ fn build_proto(package: &str, entity: Entity) -> Result<(), Box tonic_prost_build::Builder { let config = config.type_attribute( ".", @@ -94,7 +106,7 @@ fn add_serde(config: tonic_prost_build::Builder) -> tonic_prost_build::Builder { config } -#[cfg(all(feature = "openapi", feature = "iso20022"))] +#[cfg(all(feature = "openapi", any(feature = "message", feature = "pseudonyms")))] fn add_openapi(config: tonic_prost_build::Builder) -> tonic_prost_build::Builder { config.type_attribute(".", "#[derive(utoipa::ToSchema)]") } diff --git a/lib/warden-core/src/google/parser.rs b/lib/warden-core/src/google/parser.rs index f2fe5bc..7f160a3 100644 --- a/lib/warden-core/src/google/parser.rs +++ b/lib/warden-core/src/google/parser.rs @@ -1,4 +1,5 @@ #[cfg(feature = "time")] mod dt; +#[cfg(feature = "pseudonyms")] mod money; diff --git a/lib/warden-core/src/google/parser/dt.rs b/lib/warden-core/src/google/parser/dt.rs index ced6f12..0e57833 100644 --- a/lib/warden-core/src/google/parser/dt.rs +++ b/lib/warden-core/src/google/parser/dt.rs @@ -1,100 +1,107 @@ -use crate::google::{protobuf::Timestamp, r#type::Date}; +use crate::google::protobuf::Timestamp; -impl From for Date { - fn from(dt: time::OffsetDateTime) -> Self { - Self { - year: dt.year(), - month: dt.month() as i32, - day: dt.day() as i32, +#[cfg(feature = "message")] +mod date { + use super::*; + use crate::google::r#type::Date; + + impl From for Date { + fn from(dt: time::OffsetDateTime) -> Self { + Self { + year: dt.year(), + month: dt.month() as i32, + day: dt.day() as i32, + } } } -} -impl From for Date { - fn from(value: time::Date) -> Self { - Self { - year: value.year(), - month: value.month() as i32, - day: value.day() as i32, + impl From for Date { + fn from(value: time::Date) -> Self { + Self { + year: value.year(), + month: value.month() as i32, + day: value.day() as i32, + } } } -} -impl TryFrom for time::Date { - type Error = time::Error; + impl TryFrom for time::Date { + type Error = time::Error; - fn try_from(value: Date) -> Result { - Ok(Self::from_calendar_date( - value.year, - time::Month::try_from(value.month as u8)?, - value.day as u8, - )?) + fn try_from(value: Date) -> Result { + Ok(Self::from_calendar_date( + value.year, + time::Month::try_from(value.month as u8)?, + value.day as u8, + )?) + } } -} -impl std::str::FromStr for Date { - type Err = time::Error; + impl std::str::FromStr for Date { + type Err = time::Error; - fn from_str(s: &str) -> Result { - let date = time::OffsetDateTime::parse(s, &time::format_description::well_known::Rfc3339) - .map(Date::from); - - match date { - Ok(dt) => Ok(dt), - Err(_e) => { - let my_format = time::macros::format_description!("[year]-[month]-[day]"); - let date = time::Date::parse(s, &my_format)?; - Ok(Date::from(date)) + fn from_str(s: &str) -> Result { + let date = + time::OffsetDateTime::parse(s, &time::format_description::well_known::Rfc3339) + .map(Date::from); + + match date { + Ok(dt) => Ok(dt), + Err(_e) => { + let my_format = time::macros::format_description!("[year]-[month]-[day]"); + let date = time::Date::parse(s, &my_format)?; + Ok(Date::from(date)) + } } } } -} -impl TryFrom for Date { - type Error = time::Error; + impl TryFrom for Date { + type Error = time::Error; - fn try_from(value: String) -> Result { - ::from_str(&value) + fn try_from(value: String) -> Result { + ::from_str(&value) + } } -} - -impl TryFrom for Date { - type Error = time::Error; - fn try_from(value: DateItem) -> Result { - match value { - DateItem::String(ref string) => ::from_str(string), - #[cfg(feature = "iso20022")] - DateItem::Date { year, month, day } => Ok(Date { year, month, day }), - DateItem::Timestamp { seconds, nanos } => { - let odt = time::OffsetDateTime::try_from(crate::google::protobuf::Timestamp { - seconds, - nanos, - })?; - Ok(Self { - year: odt.year(), - month: odt.month() as i32, - day: odt.day() as i32, - }) + impl TryFrom for Date { + type Error = time::Error; + + fn try_from(value: DateItem) -> Result { + match value { + DateItem::String(ref string) => ::from_str(string), + #[cfg(feature = "message")] + DateItem::Date { year, month, day } => Ok(Date { year, month, day }), + DateItem::Timestamp { seconds, nanos } => { + let odt = time::OffsetDateTime::try_from(crate::google::protobuf::Timestamp { + seconds, + nanos, + })?; + Ok(Self { + year: odt.year(), + month: odt.month() as i32, + day: odt.day() as i32, + }) + } } } } -} -impl From for String { - fn from(value: Date) -> Self { - let prepend = |value: i32| -> String { - match value.lt(&10) { - true => format!("0{}", value), - false => value.to_string(), - } - }; - format!( - "{}-{}-{}", - value.year, - prepend(value.month), - prepend(value.day), - ) + impl From for String { + fn from(value: Date) -> Self { + let prepend = |value: i32| -> String { + match value.lt(&10) { + true => format!("0{}", value), + false => value.to_string(), + } + }; + format!( + "{}-{}-{}", + value.year, + prepend(value.month), + prepend(value.day), + ) + } } } @@ -108,7 +115,7 @@ pub enum DateItem { /// ts Timestamp { seconds: i64, nanos: i32 }, /// date - #[cfg(feature = "iso20022")] + #[cfg(feature = "message")] Date { year: i32, month: i32, day: i32 }, } @@ -118,7 +125,7 @@ impl TryFrom for Timestamp { fn try_from(value: DateItem) -> Result { match value { DateItem::String(ref string) => ::from_str(string), - #[cfg(feature = "iso20022")] + #[cfg(feature = "message")] DateItem::Date { year, month, day } => { let date = time::Date::try_from(crate::google::r#type::Date { year, month, day })?; let time = time::Time::MIDNIGHT; diff --git a/lib/warden-core/src/iso20022.rs b/lib/warden-core/src/iso20022.rs index 78365a9..436ee2f 100644 --- a/lib/warden-core/src/iso20022.rs +++ b/lib/warden-core/src/iso20022.rs @@ -17,10 +17,6 @@ impl std::fmt::Display for TransactionType { } } -/// Pacs008 file descriptor -pub const ISO20022_FILE_DESCRIPTOR_SET: &[u8] = - tonic::include_file_descriptor_set!("iso20022_descriptor"); - /// pacs.008.001.12 pub mod pacs008 { tonic::include_proto!("iso20022.pacs008"); diff --git a/lib/warden-core/src/lib.rs b/lib/warden-core/src/lib.rs index 19d02f3..53f25f2 100644 --- a/lib/warden-core/src/lib.rs +++ b/lib/warden-core/src/lib.rs @@ -6,17 +6,27 @@ missing_debug_implementations )] +/// Type file descriptor +#[cfg(any(feature = "message", feature = "pseudonyms"))] +pub const FILE_DESCRIPTOR_SET: &[u8] = + tonic::include_file_descriptor_set!("warden_descriptor"); + /// Google well known types #[allow(missing_docs)] -#[cfg(feature = "iso20022")] +#[cfg(any(feature = "message", feature = "pseudonyms"))] pub mod google; /// ISO20022 messages #[allow(missing_docs)] -#[cfg(feature = "iso20022")] +#[cfg(feature = "message")] pub mod iso20022; /// Message in transit #[allow(missing_docs)] -#[cfg(feature = "iso20022")] +#[cfg(feature = "message")] pub mod message; + +/// Pseudonyms +#[allow(missing_docs)] +#[cfg(feature = "pseudonyms")] +pub mod pseudonyms; diff --git a/lib/warden-core/src/pseudonyms.rs b/lib/warden-core/src/pseudonyms.rs new file mode 100644 index 0000000..1d36074 --- /dev/null +++ b/lib/warden-core/src/pseudonyms.rs @@ -0,0 +1,15 @@ +pub mod account { + tonic::include_proto!("pseudonyms.account"); +} + +pub mod entity { + tonic::include_proto!("pseudonyms.entity"); +} + +pub mod transaction_relationship { + tonic::include_proto!("pseudonyms.transaction_relationship"); +} + +pub mod account_holder { + tonic::include_proto!("pseudonyms.account_holder"); +} -- cgit v1.2.3