Skip to content
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
24 changes: 12 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ cala-types = { path = "cala-ledger-core-types", package = "cala-ledger-core-type
cala-ledger = { path = "cala-ledger", version = "0.30.3-dev" }

cel = "0.14.5"
es-entity = "0.13.0"
job = { version = "0.15.2", features = ["es-entity"] }
obix = { version = "0.12.3", default-features = false }
es-entity = "0.14.1"
job = { version = "0.16.1", features = ["es-entity"] }
obix = { version = "0.13.1", default-features = false }

anyhow = "1.0.99"
cached = { version = "4.0", features = ["async"] }
Expand Down
11 changes: 7 additions & 4 deletions cala-ledger/src/entry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,19 @@ impl Entries {
&self,
transaction_id: TransactionId,
) -> Result<Vec<Entry>, EntryError> {
let mut entries = self
let page = self
.repo
.list_for_transaction_id_by_created_at(
transaction_id,
Default::default(),
Default::default(),
)
.await?
.into_parts()
.0;
.await?;
let mut entries = match page.into_page() {
es_entity::Page::Last { entities } | es_entity::Page::HasNext { entities, next: _ } => {
entities
}
};
entries.sort_by(|a, b| {
let a_sequence = a.values().sequence;
let b_sequence = b.values().sequence;
Expand Down
6 changes: 3 additions & 3 deletions cala-ledger/tests/account_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1502,7 +1502,7 @@ async fn members_pagination() -> anyhow::Result<()> {
.await?;

assert_eq!(ret.entities().len(), 2);
assert!(ret.has_next_page);
assert!(ret.has_next_page());
assert_eq!(
ret.entities()[0].id.clone(),
AccountSetMemberId::from(set_two.id())
Expand All @@ -1522,7 +1522,7 @@ async fn members_pagination() -> anyhow::Result<()> {
.list_members_by_created_at(parent.id(), query_args)
.await?;
assert_eq!(ret.entities().len(), 2);
assert!(ret.has_next_page);
assert!(ret.has_next_page());
assert_eq!(
ret.entities()[0].id.clone(),
AccountSetMemberId::from(account_one.id())
Expand All @@ -1542,7 +1542,7 @@ async fn members_pagination() -> anyhow::Result<()> {
.list_members_by_created_at(parent.id(), query_args)
.await?;
assert_eq!(ret.entities().len(), 1);
assert!(!ret.has_next_page);
assert!(!ret.has_next_page());
assert_eq!(
ret.entities()[0].id.clone(),
AccountSetMemberId::from(account_two.id())
Expand Down
14 changes: 5 additions & 9 deletions cala-ledger/tests/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,26 @@ fn assert_balance_amounts_sum(
);
}

fn all_balances_query<C: std::fmt::Debug>() -> es_entity::PaginatedQueryArgs<C> {
fn all_balances_query<C>() -> es_entity::PaginatedQueryArgs<C> {
es_entity::PaginatedQueryArgs {
first: 100,
after: None,
}
}

fn balances_by_currency<C: std::fmt::Debug>(
fn balances_by_currency<C>(
balances: es_entity::PaginatedQueryRet<AccountBalance, C>,
) -> HashMap<Currency, AccountBalance> {
balances
.into_parts()
.0
helpers::expect_single_page(balances)
.into_iter()
.map(|balance| (balance.details.currency, balance))
.collect()
}

fn balances_by_id<C: std::fmt::Debug>(
fn balances_by_id<C>(
balances: es_entity::PaginatedQueryRet<AccountBalance, C>,
) -> HashMap<BalanceId, AccountBalance> {
balances
.into_parts()
.0
helpers::expect_single_page(balances)
.into_iter()
.map(|balance| {
(
Expand Down
81 changes: 38 additions & 43 deletions cala-ledger/tests/effective_balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,30 +56,26 @@ fn assert_balance_range_amounts_sum(
assert_balance_amounts_sum(&actual.close, &first.close, &second.close);
}

fn all_balances_query<C: std::fmt::Debug>() -> es_entity::PaginatedQueryArgs<C> {
fn all_balances_query<C>() -> es_entity::PaginatedQueryArgs<C> {
es_entity::PaginatedQueryArgs {
first: 100,
after: None,
}
}

fn balances_by_currency<C: std::fmt::Debug>(
fn balances_by_currency<C>(
balances: es_entity::PaginatedQueryRet<AccountBalance, C>,
) -> HashMap<Currency, AccountBalance> {
balances
.into_parts()
.0
helpers::expect_single_page(balances)
.into_iter()
.map(|balance| (balance.details.currency, balance))
.collect()
}

fn balances_by_id<C: std::fmt::Debug>(
fn balances_by_id<C>(
balances: es_entity::PaginatedQueryRet<AccountBalance, C>,
) -> HashMap<BalanceId, AccountBalance> {
balances
.into_parts()
.0
helpers::expect_single_page(balances)
.into_iter()
.map(|balance| {
(
Expand All @@ -94,23 +90,19 @@ fn balances_by_id<C: std::fmt::Debug>(
.collect()
}

fn ranges_by_currency<C: std::fmt::Debug>(
fn ranges_by_currency<C>(
ranges: es_entity::PaginatedQueryRet<BalanceRange, C>,
) -> HashMap<Currency, BalanceRange> {
ranges
.into_parts()
.0
helpers::expect_single_page(ranges)
.into_iter()
.map(|range| (range.close.details.currency, range))
.collect()
}

fn ranges_by_id<C: std::fmt::Debug>(
fn ranges_by_id<C>(
ranges: es_entity::PaginatedQueryRet<BalanceRange, C>,
) -> HashMap<BalanceId, BalanceRange> {
ranges
.into_parts()
.0
helpers::expect_single_page(ranges)
.into_iter()
.map(|range| {
(
Expand Down Expand Up @@ -1196,7 +1188,7 @@ async fn list_modified_since_basic() -> anyhow::Result<()> {
.effective()
.list_modified_since(journal.id(), since, all_balances_query())
.await?;
assert!(!page.has_next_page);
assert!(!page.has_next_page());

let tuples: HashSet<(AccountId, Currency, NaiveDate)> = page
.entities()
Expand Down Expand Up @@ -1293,13 +1285,12 @@ async fn list_modified_since_backdating_fanout() -> anyhow::Result<()> {
.list_modified_since(journal.id(), since, all_balances_query())
.await?;

let recipient_btc: HashMap<NaiveDate, EffectiveBalanceSnapshot> = page
.into_parts()
.0
.into_iter()
.filter(|s| s.account_id == recipient_account.id() && s.currency == Currency::BTC)
.map(|s| (s.effective, s))
.collect();
let recipient_btc: HashMap<NaiveDate, EffectiveBalanceSnapshot> =
helpers::expect_single_page(page)
.into_iter()
.filter(|s| s.account_id == recipient_account.id() && s.currency == Currency::BTC)
.map(|s| (s.effective, s))
.collect();

assert_eq!(
recipient_btc.keys().copied().collect::<HashSet<_>>(),
Expand Down Expand Up @@ -1449,7 +1440,7 @@ async fn list_modified_since_pagination() -> anyhow::Result<()> {
.effective()
.list_modified_since(journal.id(), since, all_balances_query())
.await?;
assert!(!full.has_next_page);
assert!(!full.has_next_page());
assert_eq!(full.entities().len(), expected_count);
let expected_tuples: HashSet<(AccountId, Currency, NaiveDate)> = full
.entities()
Expand All @@ -1461,25 +1452,29 @@ async fn list_modified_since_pagination() -> anyhow::Result<()> {
// Page through with a small page size; the union must match exactly,
// with no duplicates or gaps across cursor boundaries.
let mut collected = Vec::new();
let mut after = None;
let mut query = es_entity::PaginatedQueryArgs {
first: 3,
after: None,
};
let mut pages = 0;
loop {
let page = cala
.balances()
.effective()
.list_modified_since(
journal.id(),
since,
es_entity::PaginatedQueryArgs { first: 3, after },
)
.list_modified_since(journal.id(), since, query)
.await?;
pages += 1;
let (entities, next) = page.into_parts();
assert!(entities.len() <= 3);
collected.extend(entities);
match next {
Some(query) => after = query.after,
None => break,
assert!(page.entities().len() <= 3);
match page.into_page() {
es_entity::Page::Last { entities } => {
collected.extend(entities);
break;
}
es_entity::Page::HasNext { entities, next } => {
collected.extend(entities);
assert_eq!(next.first, 3);
query = next.into();
}
}
}
assert!(pages > 1, "test setup should require multiple pages");
Expand Down Expand Up @@ -1508,7 +1503,7 @@ async fn list_modified_since_pagination() -> anyhow::Result<()> {
)
.await?;
assert_eq!(first_page.entities().len(), 1);
assert!(first_page.has_next_page);
assert!(first_page.has_next_page());
let boundary_tuple = (
first_page.entities()[0].account_id,
first_page.entities()[0].currency,
Expand All @@ -1523,11 +1518,11 @@ async fn list_modified_since_pagination() -> anyhow::Result<()> {
since,
es_entity::PaginatedQueryArgs {
first: expected_count,
after: first_page.end_cursor,
after: first_page.into_end_cursor(),
},
)
.await?;
assert!(!rest.has_next_page);
assert!(!rest.has_next_page());
assert_eq!(rest.entities().len(), expected_count - 1);
assert!(
rest.entities()
Expand All @@ -1545,8 +1540,8 @@ async fn list_modified_since_pagination() -> anyhow::Result<()> {
.list_modified_since(journal.id(), quiet_since, all_balances_query())
.await?;
assert!(empty.entities().is_empty());
assert!(!empty.has_next_page);
assert!(empty.end_cursor.is_none());
assert!(!empty.has_next_page());
assert!(empty.end_cursor().is_none());

Ok(())
}
Expand Down
Loading
Loading