diff --git a/cala-ledger-core-types/src/velocity/limit.rs b/cala-ledger-core-types/src/velocity/limit.rs index ae1ee661..d62fc563 100644 --- a/cala-ledger-core-types/src/velocity/limit.rs +++ b/cala-ledger-core-types/src/velocity/limit.rs @@ -8,27 +8,27 @@ pub struct VelocityLimitValues { pub id: VelocityLimitId, pub name: String, pub description: String, - pub window: Vec, + pub window: Vec, pub condition: Option, pub currency: Option, pub params: Option>, - pub limit: LimitInput, + pub limit: Limit, } #[derive(Clone, Debug, Serialize, Deserialize)] -pub struct PartitionKeyInput { +pub struct PartitionKey { pub alias: String, pub value: CelExpression, } #[derive(Clone, Debug, Serialize, Deserialize)] -pub struct LimitInput { +pub struct Limit { pub timestamp_source: Option, - pub balance: Vec, + pub balance: Vec, } #[derive(Clone, Debug, Serialize, Deserialize)] -pub struct BalanceLimitInput { +pub struct BalanceLimit { pub layer: CelExpression, pub amount: CelExpression, pub enforcement_direction: CelExpression, diff --git a/cala-ledger/src/velocity/limit/entity.rs b/cala-ledger/src/velocity/limit/entity.rs index 274f8728..9cbbf215 100644 --- a/cala-ledger/src/velocity/limit/entity.rs +++ b/cala-ledger/src/velocity/limit/entity.rs @@ -58,13 +58,13 @@ pub struct NewVelocityLimit { pub(super) name: String, #[builder(setter(into))] description: String, - window: Vec, + window: Vec, #[builder(setter(strip_option, into), default)] condition: Option, currency: Option, #[builder(setter(strip_option), default)] params: Option>, - limit: NewLimitInput, + limit: NewLimit, } impl NewVelocityLimit { @@ -85,7 +85,7 @@ impl NewVelocityLimit { window: self .window .into_iter() - .map(|input| PartitionKeyInput { + .map(|input| PartitionKey { alias: input.alias, value: CelExpression::try_from(input.value).expect("already validated"), }) @@ -96,7 +96,7 @@ impl NewVelocityLimit { params: self .params .map(|params| params.into_iter().map(ParamDefinition::from).collect()), - limit: LimitInput { + limit: Limit { timestamp_source: limit .timestamp_source .map(CelExpression::try_from) @@ -105,7 +105,7 @@ impl NewVelocityLimit { balance: limit .balance .into_iter() - .map(|input| BalanceLimitInput { + .map(|input| BalanceLimit { layer: CelExpression::try_from(input.layer) .expect("already validated"), amount: CelExpression::try_from(input.amount) @@ -132,18 +132,18 @@ impl NewVelocityLimitBuilder { #[derive(Clone, Builder, Debug)] #[builder(build_fn(validate = "Self::validate"))] -pub struct NewPartitionKeyInput { +pub struct NewPartitionKey { #[builder(setter(into))] alias: String, #[builder(setter(into))] value: String, } -impl NewPartitionKeyInput { - pub fn builder() -> NewPartitionKeyInputBuilder { - NewPartitionKeyInputBuilder::default() +impl NewPartitionKey { + pub fn builder() -> NewPartitionKeyBuilder { + NewPartitionKeyBuilder::default() } } -impl NewPartitionKeyInputBuilder { +impl NewPartitionKeyBuilder { fn validate(&self) -> Result<(), String> { validate_expression( self.value @@ -156,17 +156,17 @@ impl NewPartitionKeyInputBuilder { #[derive(Clone, Builder, Debug)] #[builder(build_fn(validate = "Self::validate"))] -pub struct NewLimitInput { +pub struct NewLimit { #[builder(setter(strip_option, into), default)] timestamp_source: Option, - balance: Vec, + balance: Vec, } -impl NewLimitInput { - pub fn builder() -> NewLimitInputBuilder { - NewLimitInputBuilder::default() +impl NewLimit { + pub fn builder() -> NewLimitBuilder { + NewLimitBuilder::default() } } -impl NewLimitInputBuilder { +impl NewLimitBuilder { fn validate(&self) -> Result<(), String> { validate_optional_expression(&self.timestamp_source) } @@ -174,7 +174,7 @@ impl NewLimitInputBuilder { #[derive(Clone, Builder, Debug)] #[builder(build_fn(validate = "Self::validate"))] -pub struct NewBalanceLimitInput { +pub struct NewBalanceLimit { #[builder(setter(into))] layer: String, #[builder(setter(into))] @@ -182,12 +182,12 @@ pub struct NewBalanceLimitInput { #[builder(setter(into))] enforcement_direction: String, } -impl NewBalanceLimitInput { - pub fn builder() -> NewBalanceLimitInputBuilder { - NewBalanceLimitInputBuilder::default() +impl NewBalanceLimit { + pub fn builder() -> NewBalanceLimitBuilder { + NewBalanceLimitBuilder::default() } } -impl NewBalanceLimitInputBuilder { +impl NewBalanceLimitBuilder { fn validate(&self) -> Result<(), String> { validate_expression( self.layer diff --git a/cala-ledger/tests/velocity.rs b/cala-ledger/tests/velocity.rs index 8ed8f2ae..0bda29ce 100644 --- a/cala-ledger/tests/velocity.rs +++ b/cala-ledger/tests/velocity.rs @@ -19,12 +19,7 @@ async fn create_control() -> anyhow::Result<()> { .description("test") .window(vec![]) .currency(None) - .limit( - NewLimitInput::builder() - .balance(vec![]) - .build() - .expect("limit"), - ) + .limit(NewLimit::builder().balance(vec![]).build().expect("limit")) .build() .expect("build control");