UNPKG

@controlplane/cli

Version:

Control Plane Corporation CLI

37 lines 1.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.fetchPages = void 0; const links_1 = require("../util/links"); /** * * @param client * @param max * undefined => only first page, * number < 0 => all results * number => not more than that * @param result */ async function fetchPages(client, max, result) { if (max === undefined) { return; } let nextLink = (0, links_1.linksOf)(result).next; while (true) { if (!nextLink) { break; } if (max > 0 && result.items.length >= max) { break; } const nextPage = await client.get(nextLink); result.items.splice(result.items.length, 0, ...nextPage.items); nextLink = (0, links_1.linksOf)(nextPage).next; // make the links of the main result valid in case someone want to continue iteration result.links = nextPage.links; } if (max > 0) { result.items = result.items.slice(0, max); } } exports.fetchPages = fetchPages; //# sourceMappingURL=resultFetcher.js.map