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

chore: drop Input suffix from Velocity Limit #147

Merged
merged 1 commit into from
Jul 1, 2024
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
12 changes: 6 additions & 6 deletions cala-ledger-core-types/src/velocity/limit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,27 @@ pub struct VelocityLimitValues {
pub id: VelocityLimitId,
pub name: String,
pub description: String,
pub window: Vec<PartitionKeyInput>,
pub window: Vec<PartitionKey>,
pub condition: Option<CelExpression>,
pub currency: Option<Currency>,
pub params: Option<Vec<ParamDefinition>>,
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<CelExpression>,
pub balance: Vec<BalanceLimitInput>,
pub balance: Vec<BalanceLimit>,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct BalanceLimitInput {
pub struct BalanceLimit {
pub layer: CelExpression,
pub amount: CelExpression,
pub enforcement_direction: CelExpression,
Expand Down
42 changes: 21 additions & 21 deletions cala-ledger/src/velocity/limit/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ pub struct NewVelocityLimit {
pub(super) name: String,
#[builder(setter(into))]
description: String,
window: Vec<NewPartitionKeyInput>,
window: Vec<NewPartitionKey>,
#[builder(setter(strip_option, into), default)]
condition: Option<String>,
currency: Option<Currency>,
#[builder(setter(strip_option), default)]
params: Option<Vec<NewParamDefinition>>,
limit: NewLimitInput,
limit: NewLimit,
}

impl NewVelocityLimit {
Expand All @@ -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"),
})
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -156,38 +156,38 @@ 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<String>,
balance: Vec<NewBalanceLimitInput>,
balance: Vec<NewBalanceLimit>,
}
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)
}
}

#[derive(Clone, Builder, Debug)]
#[builder(build_fn(validate = "Self::validate"))]
pub struct NewBalanceLimitInput {
pub struct NewBalanceLimit {
#[builder(setter(into))]
layer: String,
#[builder(setter(into))]
amount: String,
#[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
Expand Down
7 changes: 1 addition & 6 deletions cala-ledger/tests/velocity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
Loading