paginate
paginate<
T>(getPage,options?):OutputType<T>
Defined in: packages/synapse-core/src/pagination.ts:108
Iterate over every item returned by a cursor-paginated action.
The generator passes each returned nextCursor back to getPage. Cursors
are opaque: callers must not calculate the next value themselves. A
repeated or non-advancing cursor is rejected to prevent an infinite loop.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
T |
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
getPage | GetPage<T> | Function that fetches one page for the supplied cursor. |
options | OptionsType | Initial pagination options. |
Returns
Section titled “Returns”OutputType<T>
An async generator that yields items from every page.
Examples
Section titled “Examples”Stream items as pages are fetched
import { paginate } from '@filoz/synapse-core'import { getClientDataSetIds } from '@filoz/synapse-core/warm-storage'
for await (const dataSetId of paginate(({ cursor }) => getClientDataSetIds(client, { address, cursor }))) { console.log(dataSetId)}Accumulate every item into an array
import { paginate } from '@filoz/synapse-core'import { getClientDataSetIds } from '@filoz/synapse-core/warm-storage'
const dataSetIds = await Array.fromAsync( paginate(({ cursor }) => getClientDataSetIds(client, { address, cursor })))