Skip to content

feat(pagination): add generic paginateArray helper to horizonPaginator (#618) - #809

Draft
s6pa1rta3n-lab wants to merge 1 commit into
Stellar-split:mainfrom
s6pa1rta3n-lab:fix-issue-618
Draft

feat(pagination): add generic paginateArray helper to horizonPaginator (#618)#809
s6pa1rta3n-lab wants to merge 1 commit into
Stellar-split:mainfrom
s6pa1rta3n-lab:fix-issue-618

Conversation

@s6pa1rta3n-lab

Copy link
Copy Markdown

Overview

Implements a generic paginateArray helper in src/horizonPaginator.ts for paginating in-memory arrays (such as local arrays of invoices or payments) with 1-indexed pagination, range boundary checks, and SdkError error handling.

Related Issue

Closes #618

Changes

  • [MODIFY] src/horizonPaginator.ts
    • Implemented and exported generic paginateArray<T>(items: T[], opts: { page: number; pageSize: number }) returning PaginateArrayResult<T> (data, total, totalPages, hasNext, hasPrev)
    • Validated pageSize to be between 1 and 200, throwing SdkError with SdkErrorCode.INVALID_RECIPIENT when invalid
    • Handled out-of-range page requests returning data: [] without errors
    • Exported PaginateArrayOptions and PaginateArrayResult types
  • [MODIFY] src/index.ts
    • Exported paginateArray, PaginateArrayOptions, and PaginateArrayResult on the public SDK entrypoint
  • [MODIFY] test/horizonPaginator.test.ts
    • Added unit tests covering:
      • First page, middle page, last page
      • Out-of-range page beyond totalPages and page < 1 returning empty array
      • Single item array and array with exactly pageSize items
      • Empty array edge case
      • hasNext and hasPrev correctness across pages
      • Throwing SdkError with INVALID_RECIPIENT code when pageSize < 1 or pageSize > 200 or non-integer
      • Boundary values for pageSize = 1 and pageSize = 200
      • Generic array typing with custom interfaces (Invoice[], Payment[])

Acceptance Criteria Checklist

  • paginateArray<T>(items: T[], opts: { page: number; pageSize: number }): { data: T[]; total: number; totalPages: number; hasNext: boolean; hasPrev: boolean } exported from src/horizonPaginator.ts
  • page is 1-indexed; page=1 returns the first pageSize items
  • Out-of-range page (beyond totalPages) returns data: [] without error
  • pageSize must be between 1 and 200 — throws SdkError with INVALID_RECIPIENT code otherwise
  • Exported from src/index.ts
  • Unit tests: first page, last page, out-of-range page returns empty, single item, exactly pageSize items, hasNext/hasPrev correctness

Verification Results

 RUN  v1.6.1 /Users/solveetcoagula/Desktop/activeProjects/bounty_operations/split-sdk-618

 ✓ test/horizonPaginator.test.ts  (37 tests) 7ms

 Test Files  1 passed (1)
      Tests  37 passed (37)

Payout Routing

  • EVM (Base/Arbitrum/Polygon/ETH): 0xF46C9F6d70C50BF81ef3588AB523a90a594a2F89
  • Stellar: GCL6OXAMLD75BMTINA6EMRUDWK5THQUSHMYNLSNBCJAPZJHNYJTUNIBC

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.

Add generic paginateArray helper to horizonPaginator

1 participant