Function: paginateByOffset()
@kortexya/reasoninglayer / paginateByOffset
Function: paginateByOffset()
Section titled “Function: paginateByOffset()”paginateByOffset<
TItem>(read,options?,requestOptions?):AsyncGenerator<TItem,void,undefined>
Defined in: src/pagination.ts:135
Iterate a limit/offset endpoint, one item at a time.
Type Parameters
Section titled “Type Parameters”TItem
Parameters
Section titled “Parameters”OffsetPageReader<TItem>
Reads one page.
options?
Section titled “options?”Page size, an optional overall cap, the offset to start
at, and an onPage callback that sees each page’s total.
requestOptions?
Section titled “requestOptions?”Per-call options, applied to EVERY page request.
Returns
Section titled “Returns”AsyncGenerator<TItem, void, undefined>
An async iterator over the items.
Remarks
Section titled “Remarks”A signal in requestOptions cancels the whole walk, not just the page in
flight — which is the behaviour a caller breaking out of a for await wants,
and the reason the options are threaded into each page rather than the first.
When the page reports total, the walk ends at total (or on an empty
page), NOT on a short page: an engine that caps a page below the requested
size answers a short page with rows still to come. Only a page without a
total ends the walk by being short.
Example
Section titled “Example”for await (const term of client.terms.iterateTerms({ sortName: 'employee' })) { console.log(term.id);}
// Resume after a page already read, and keep the total beside the rows.const first = await client.terms.listTerms({ limit: 500 });let total = first.total;for await (const term of client.terms.iterateTerms(undefined, { offset: first.terms.length, onPage: (page) => (total = page.total),})) { console.log(term.id);}