Skip to content

feat: add searchByMemo, validateSplitTotal/normalizeSplits, and has/purgeExpired to cache (Closes #614, #609, #606) - #628

Open
waterWang wants to merge 1 commit into
Stellar-split:mainfrom
waterWang:feat/search-cache-validator-batch
Open

feat: add searchByMemo, validateSplitTotal/normalizeSplits, and has/purgeExpired to cache (Closes #614, #609, #606)#628
waterWang wants to merge 1 commit into
Stellar-split:mainfrom
waterWang:feat/search-cache-validator-batch

Conversation

@waterWang

Copy link
Copy Markdown

Summary

This PR implements three independent features:

#614 — Add searchByMemo to search.ts

  • searchByMemo(invoices, query, opts?) performs substring search on invoice memo fields
  • Case-insensitive by default, with opts.caseSensitive override
  • Returns all invoices unchanged when query is empty
  • Skips invoices with undefined/null memo without error

#609 — Add validateSplitTotal and normalizeSplits to splitRatioValidator

  • validateSplitTotal(splits, totalBasisPoints?) validates bigint splits sum to exact total (default 10000n)
  • Throws StellarSplitError with code INVALID_RECIPIENT on mismatch
  • normalizeSplits(amounts, total) distributes rounding remainder to the last element
  • Pure bigint arithmetic — no floating-point conversion

#606 — Add has() and purgeExpired() to SimpleCache

  • has(key) checks existence and TTL expiry
  • purgeExpired() removes all expired entries in one sweep, returns count removed
  • Respects disabled cache state (returns false/0 when disabled)

Tests

  • test/search-memo.test.ts — 6 tests: substring match, case-insensitive default, case-sensitive override, empty query, null memo skip, no match
  • test/splitRatioValidator.test.ts — 9 tests: exact sum passes, off-by-one throws, INVALID_RECIPIENT code, empty array throws, normalizeSplits round-trip, remainder distribution, over-sum handling
  • test/cache.test.ts (extended) — 11 tests (8 new): has() exists, has() nonexistent, has() expired, has() disabled, purgeExpired() removes expired, purgeExpired() nothing expired, purgeExpired() disabled

All 26 tests pass.

…urgeExpired to cache

- Stellar-split#614: searchByMemo invoices by memo content substring (case-insensitive by default)
- Stellar-split#609: validateSplitTotal with bigint precision + normalizeSplits with remainder distribution
- Stellar-split#606: has() and purgeExpired() methods on SimpleCache

All 26 tests pass across 3 new/updated test files.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant