feat: add pagination to GET /api/streams/:id/history - #900
Conversation
Add page/limit query params (max 100) to the stream history endpoint,
defaulting to limit 50 and returning events sorted ascending by
timestamp. The response now returns {data, total, page, limit} and
invalid params (non-integer, out-of-range, >100 limit) return 400 via
the shared Zod validation schema. pageSize is kept as a supported alias
for backwards compatibility.
Also fixes a pre-existing syntax error in streamStore#createStream
introduced by the Soroban wiring merge that prevented the module (and
the whole app/test suite) from parsing.
Tests extend the history integration coverage for the new spec,
including pagination correctness across 500+ events and 400 on invalid
params. Swagger spec and TESTING.md updated to document the params.
Closes ritik4ever#726
🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
|
@ZuLu0890 is attempting to deploy a commit to the ritik4ever's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
@ZuLu0890 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! 🚀 |
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Adds pagination to
GET /api/streams/:id/historyas described in #726. The endpoint now acceptspageandlimitquery parameters (with a hard cap of100), returns events sorted ascending by timestamp (oldest first), and responds with{ data, total, page, limit }. Invalid parameters return a400 VALIDATION_ERRORinstead of being silently clamped.Closes #726
Changes
Backend (
backend/src/index.ts)listEventsQuerySchema, matching the/api/eventsand/api/metrics/historypatterns (coerce to int,page >= 1,1 <= limit <= 100→400withVALIDATION_ERRORon failure).limitis now50(was a clampedpageSizedefault of20).getStreamHistory(..., 'asc')).{ data, total, page, limit }; the previouspageSize/hasMorefields are removed.pageSizeremains a supported alias forlimitfor backwards compatibility.Docs
backend/src/swagger.ts: documented thepage/limitquery params, the400response, and thetotal/page/limitfields in the 200 schema.backend/TESTING.md: updated the manual test checklist.Tests (
backend/src/integration.test.ts)limit, nohasMore) and ascending order.limitexceeds100;page/limit(zero, negative, non-integer);limitof50;pageSizealias.Necessary build fix (
backend/src/services/streamStore.ts)createStream(const built = await rpcServer.prepareTransaction() left over from the Soroban wiring merge (feat(backend): wire Soroban create_stream contract call with simulati… #650) that produced aSyntaxError, preventing the module — and therefore the whole backend and its test suite — from loading. Without this the endpoint cannot even be tested. Minimal, behavior-preserving.Acceptance criteria
LIMIT/OFFSETagainststream_events(~1–10ms in test logs).Verification
npx vitest run src/integration.test.ts— pagination/history tests pass.npx eslinton changed files — clean.maincurrently has pre-existing breakage unrelated to this PR (other integration tests and the fulltsctypecheck fail due to missingdb.tsexports likegetAllowedAssets/searchStreamsFts, Soroban claimable/reconcile wiring, and several test files). That is out of scope and intentionally left for separate follow-ups; this PR is scoped to the pagination feature.