frontend/.pnpm-store/v3/files/45/5f84dae3dd7882cc678157d26f3c67dcd4b62877192ec2f4318dcc6f228a47393db882b003d8601a42bd3cbc912b06ebcd6c4ba71584011fd24510fe96dabf

25 lines
795 B
Plaintext

import { iterator } from "./iterator";
export function paginate(octokit, route, parameters, mapFn) {
if (typeof parameters === "function") {
mapFn = parameters;
parameters = undefined;
}
return gather(octokit, [], iterator(octokit, route, parameters)[Symbol.asyncIterator](), mapFn);
}
function gather(octokit, results, iterator, mapFn) {
return iterator.next().then((result) => {
if (result.done) {
return results;
}
let earlyExit = false;
function done() {
earlyExit = true;
}
results = results.concat(mapFn ? mapFn(result.value, done) : result.value.data);
if (earlyExit) {
return results;
}
return gather(octokit, results, iterator, mapFn);
});
}