Skip to content

paginateIterator

paginateIterator<T>(fetchPage): AsyncGenerator<T, void, undefined>

Defined in: src/helpers/pagination.helpers.ts:149

Creates an async iterator that yields individual items from paginated results.

This function iterates over large result sets without loading everything into memory. It fetches one page at a time and yields items as needed. Use this function with for await...of to process results one at a time.

T

PaginatedFetchFunction<T>

Function that fetches a single page of results

AsyncGenerator<T, void, undefined>

Individual items from each page

// Process blocks one at a time
for await (const block of paginateIterator((cursor) =>
notion.blocks.children.list('page-id', { start_cursor: cursor })
)) {
console.log(block.type, block.id);
if (block.isTextBlock()) {
console.log(block.getPlainText());
}
}
// Process database pages one at a time with filtering
for await (const page of paginateIterator((cursor) =>
notion.databases.query('database-id', {
start_cursor: cursor,
filter: filter.status('Status').equals('Active'),
})
)) {
console.log(page.getTitle());
// Process page without loading all pages into memory
}
// Process search results one at a time
for await (const result of paginateIterator((cursor) =>
notion.search.query({ query: 'meeting', start_cursor: cursor })
)) {
console.log(result.url);
}