First upload version 0.0.1
This commit is contained in:
34
node_modules/@octokit/plugin-paginate-graphql/dist-src/iterator.js
generated
vendored
Normal file
34
node_modules/@octokit/plugin-paginate-graphql/dist-src/iterator.js
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
import { extractPageInfos } from "./extract-page-info.js";
|
||||
import { getCursorFrom, hasAnotherPage } from "./page-info.js";
|
||||
import { MissingCursorChange } from "./errors.js";
|
||||
const createIterator = (octokit) => {
|
||||
return (query, initialParameters = {}) => {
|
||||
let nextPageExists = true;
|
||||
let parameters = { ...initialParameters };
|
||||
return {
|
||||
[Symbol.asyncIterator]: () => ({
|
||||
async next() {
|
||||
if (!nextPageExists) return { done: true, value: {} };
|
||||
const response = await octokit.graphql(
|
||||
query,
|
||||
parameters
|
||||
);
|
||||
const pageInfoContext = extractPageInfos(response);
|
||||
const nextCursorValue = getCursorFrom(pageInfoContext.pageInfo);
|
||||
nextPageExists = hasAnotherPage(pageInfoContext.pageInfo);
|
||||
if (nextPageExists && nextCursorValue === parameters.cursor) {
|
||||
throw new MissingCursorChange(pageInfoContext, nextCursorValue);
|
||||
}
|
||||
parameters = {
|
||||
...parameters,
|
||||
cursor: nextCursorValue
|
||||
};
|
||||
return { done: false, value: response };
|
||||
}
|
||||
})
|
||||
};
|
||||
};
|
||||
};
|
||||
export {
|
||||
createIterator
|
||||
};
|
||||
Reference in New Issue
Block a user