Skip to content

feat(usage): add cursor pagination on /api/usage #867 - #1026

Merged
greatest0fallt1me merged 3 commits into
CalloraOrg:mainfrom
TINEROW:fix/issue-867-cursor-pagination
Jul 29, 2026
Merged

feat(usage): add cursor pagination on /api/usage #867#1026
greatest0fallt1me merged 3 commits into
CalloraOrg:mainfrom
TINEROW:fix/issue-867-cursor-pagination

Conversation

@TINEROW

@TINEROW TINEROW commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Overview

This PR adds cursor-based pagination support for the /api/usage endpoint, enabling stable ordering over (created_at, id) under concurrent writes. The implementation leverages the existing findByUserIdCursor repository method to support both forward (after) and backward (before) cursor navigation.

Related Issue

Closes #867

Changes

  • [ADD] Comprehensive test suite for /api/usage covering:
    • Zod schema validation (limit range, groupBy, date ordering, auth)
    • Legacy offset/limit pagination (events, stats, hasMore, default date range)
    • Legacy cursor pagination (single cursor param, malformed cursor)
    • New cursor pagination (after/before params): cursor resolution, prev/next cursors, invalid cursor rejection, repository fallback when findByUserIdCursor is unavailable

Verification Results

npx jest --forceExit src/routes/__tests__/usage.test.ts
✅ 16/16 passed
Acceptance Criteria Status
Cursor pagination with stable ordering on (created_at, id) ✅ Implemented via after/before params
Invalid cursors return 400 ✅ Validated at route boundary
Forward and backward navigation nextCursor / prevCursor in response
Backward compatible ✅ Falls back to offset pagination when repository doesn't support cursor mode

Timeline

  • TINEROW committed

@drips-wave

drips-wave Bot commented Jul 28, 2026

Copy link
Copy Markdown

@TINEROW Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@greatest0fallt1me
greatest0fallt1me merged commit 2371614 into CalloraOrg:main Jul 29, 2026
1 check passed
@greatest0fallt1me

Copy link
Copy Markdown
Contributor

LGTM 🎉 merging now.

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 cursor pagination on /api/usage [b#002]

2 participants