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.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”fetchPage
Section titled “fetchPage”Function that fetches a single page of results
Returns
Section titled “Returns”AsyncGenerator<T, void, undefined>
Yields
Section titled “Yields”Individual items from each page
Example
Section titled “Example”// Process blocks one at a timefor 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 filteringfor 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 timefor await (const result of paginateIterator((cursor) => notion.search.query({ query: 'meeting', start_cursor: cursor }))) { console.log(result.url);}