Repository navigation
fix: paginate worker deployments from nested result - #2819
airshakur88 wants to merge 1 commit into
Conversation
mangeshraut712
left a comment
There was a problem hiding this comment.
Reading result.deployments is the right fix for this list endpoint, and the test shows the second page is requested. Two edge cases around an empty or already-final result are untested.
| } | ||
|
|
||
| getPaginatedItems(): Item[] { | ||
| return this.result.deployments; |
There was a problem hiding this comment.
this.result = body.result || { deployments: [] } only substitutes when result is missing or falsy. A body like { result: {}, result_info: { page: 1 } } is truthy, so getPaginatedItems() returns undefined and a for await over the list will throw. I'd use body.result?.deployments ?? [] (and keep a definite array on this.result).
nextPageRequestOptions also never returns null and increments query.page (defaulting a missing param to 1) instead of this.result_info.page. That is fine if AbstractPage stops on an empty items array, which the test relies on by serving a second page with deployments: []. If a last page still has items, or if the helper only stops when this method returns null, iteration would request page n+1 forever. I'd return null when the current page has fewer than per_page items, or when result_info.page is already the last page (if the API exposes a total), and add a test where result is {} and one where the first page is the last page.
Summary
result.deploymentsfield for iteration and async pagination.Fixes #2805
Verification
bun run jest tests/api-resources/workers/deployments-pagination.test.ts --runInBandbun run tsc --noEmit --pretty falsebun run prettier --check src/resources/workers/scripts/deployments.ts src/lib/worker-deployments-page.ts tests/api-resources/workers/deployments-pagination.test.ts