@exromany/lido-csm-sdk
Version:
[](https://github.com/lidofinance/lido-csm-sdk/blob/main/LICENSE.txt) [](h
23 lines • 915 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.onePage = exports.byTotalCount = exports.iteratePages = void 0;
const iteratePages = async (fetchPage, pagination, getNextOffset) => {
const allResults = [];
const limit = pagination?.limit ?? 1000n;
let offset = pagination?.offset ?? 0n;
while (offset !== undefined) {
const items = await fetchPage({ offset, limit });
allResults.push(...Array.from(items));
offset = getNextOffset?.({ items: items, offset, limit });
}
return allResults;
};
exports.iteratePages = iteratePages;
const byTotalCount = (totalCount) => ({ offset, limit }) => {
const nextOffset = offset + limit;
return nextOffset < totalCount ? nextOffset : undefined;
};
exports.byTotalCount = byTotalCount;
const onePage = () => undefined;
exports.onePage = onePage;
//# sourceMappingURL=iterate-pages.js.map