Repository navigation
fix(sdk): walk backward through cursor pages in the TypeScript listAll iterators - #5601
Conversation
…l iterators A listAll call that started with page.before kept that cursor and added page.after from meta.page.next. The API rejects both cursors together, so the iterator threw after the first page. The direction now follows the caller's request, as in the Go client: with page.before the walk follows meta.page.previous, otherwise it follows meta.page.next. No page request carries both cursors, a request that starts with both throws before fetching, and an empty page ends the walk.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Overview
What
listAlliterators walk backward when the request starts withpage.before: they followmeta.page.previousthroughpage.before.page.beforekeep followingmeta.page.nextthroughpage.after.Why
page.afterfrommeta.page.nextbut kept the caller'spage.before. The API rejects both cursors together, solistAllwithpage.beforethrew after the first page. This affects every cursor list that acceptspage.before, such as credit transactions.previouskeeps the walk inside the caller'sbeforebound; followingnextwould return items past it.paginateCursorinapi/v3/client/pagination.go), so both SDKs now agree.How
api/spec/packages/typespec-typescript/templates/runtime/paginate.ts: the runtime template picks the direction from the first request.previousis optional in the envelope type, so forward-only callers type-check unchanged.api/spec/packages/aip-client-javascript/src/lib/paginate.tsis regenerated withmake gen-api.tests/paginate.spec.tsadds the backward walk, the never-both-cursors check, the up-front rejection, and the empty-page stop. All four fail without the fix.Notes for reviewer
paginate.spec.tsandtypecheck, thetypespec-typescriptvitest suite, and prettier on the touched files.

Confidence Score: 5/5
The PR appears safe to merge.Summary
Fixes backward cursor walks in the TypeScript SDK’s
listAlliterators.No actionable issues found. Review used source inspection; tests were not run.
Diagram
%%{init: {'theme': 'neutral'}}%% flowchart TD A[Start iteration] --> B{Both cursors supplied?} B -->|Yes| C[Throw before fetching] B -->|No| D{before supplied?} D -->|Yes| E[Fetch backward using before] D -->|No| F[Fetch forward using after] E --> G[Yield page items] F --> G G --> H{Empty page or no cursor?} H -->|Yes| I[Stop] H -->|No, backward| J[Set before to previous] H -->|No, forward| K[Set after to next] J --> E K --> FReviews (1) · Last reviewed commit: "fix(sdk): walk backward through cursor p..." · Reviewed by Greptile
Summary by CodeRabbit