Skip to content

collectAllPages

collectAllPages<T>(fetchPage, pageSize?): Promise<T[]>

Defined in: packages/core/src/pagination/PaginationHelper.ts:69

Collect all pages of an offset-paginated endpoint into a single array.

Fetches pages sequentially until the last page is reached, then returns all items concatenated. For large result sets, prefer iteratePages to avoid loading everything into memory at once.

T

(startAt, maxResults) => Promise<OffsetPage<T>>

A function that fetches one page given startAt and maxResults

number = 50

Number of items to request per page (default: 50)

Promise<T[]>

import { collectAllPages } from '@forge-clients/core';
import { searchForIssuesUsingJql } from '@forge-clients/jira/v3';
const allIssues = await collectAllPages(
(startAt, maxResults) =>
searchForIssuesUsingJql(client, { body: { jql: 'project = PROJ', startAt, maxResults } }),
);
console.log(`Found ${allIssues.length} issues`);