Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@octokit/plugin-paginate-graphql

Package Overview
Dependencies
Maintainers
4
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@octokit/plugin-paginate-graphql - npm Package Compare versions

Comparing version 2.0.1 to 2.0.2

164

dist-node/index.js

@@ -1,9 +0,32 @@

'use strict';
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
Object.defineProperty(exports, '__esModule', { value: true });
// pkg/dist-src/index.js
var dist_src_exports = {};
__export(dist_src_exports, {
paginateGraphql: () => paginateGraphql
});
module.exports = __toCommonJS(dist_src_exports);
// Todo: Add link to explanation
const generateMessage = (path, cursorValue) => `The cursor at "${path.join(",")}" did not change its value "${cursorValue}" after a page transition. Please make sure your that your query is set up correctly.`;
class MissingCursorChange extends Error {
// pkg/dist-src/errors.js
var generateMessage = (path, cursorValue) => `The cursor at "${path.join(
","
)}" did not change its value "${cursorValue}" after a page transition. Please make sure your that your query is set up correctly.`;
var MissingCursorChange = class extends Error {
constructor(pageInfo, cursorValue) {

@@ -14,3 +37,2 @@ super(generateMessage(pageInfo.pathInQuery, cursorValue));

this.name = "MissingCursorChangeError";
if (Error.captureStackTrace) {

@@ -20,11 +42,14 @@ Error.captureStackTrace(this, this.constructor);

}
}
class MissingPageInfo extends Error {
};
var MissingPageInfo = class extends Error {
constructor(response) {
super(`No pageInfo property found in response. Please make sure to specify the pageInfo in your query. Response-Data: ${JSON.stringify(response, null, 2)}`);
super(
`No pageInfo property found in response. Please make sure to specify the pageInfo in your query. Response-Data: ${JSON.stringify(
response,
null,
2
)}`
);
this.response = response;
this.name = "MissingPageInfo";
if (Error.captureStackTrace) {

@@ -34,29 +59,29 @@ Error.captureStackTrace(this, this.constructor);

}
};
}
const isObject = value => Object.prototype.toString.call(value) === "[object Object]";
// pkg/dist-src/object-helpers.js
var isObject = (value) => Object.prototype.toString.call(value) === "[object Object]";
function findPaginatedResourcePath(responseData) {
const paginatedResourcePath = deepFindPathToProperty(responseData, "pageInfo");
const paginatedResourcePath = deepFindPathToProperty(
responseData,
"pageInfo"
);
if (paginatedResourcePath.length === 0) {
throw new MissingPageInfo(responseData);
}
return paginatedResourcePath;
}
const deepFindPathToProperty = (object, searchProp, path = []) => {
var deepFindPathToProperty = (object, searchProp, path = []) => {
for (const key of Object.keys(object)) {
const currentPath = [...path, key];
const currentValue = object[key];
if (currentValue.hasOwnProperty(searchProp)) {
return currentPath;
}
if (isObject(currentValue)) {
const result = deepFindPathToProperty(currentValue, searchProp, currentPath);
const result = deepFindPathToProperty(
currentValue,
searchProp,
currentPath
);
if (result.length > 0) {

@@ -67,24 +92,11 @@ return result;

}
return [];
};
/**
* The interfaces of the "get" and "set" functions are equal to those of lodash:
* https://lodash.com/docs/4.17.15#get
* https://lodash.com/docs/4.17.15#set
*
* They are cut down to our purposes, but could be replaced by the lodash calls
* if we ever want to have that dependency.
*/
const get = (object, path) => {
var get = (object, path) => {
return path.reduce((current, nextProperty) => current[nextProperty], object);
};
const set = (object, path, mutator) => {
var set = (object, path, mutator) => {
const lastProperty = path[path.length - 1];
const parentPath = [...path].slice(0, -1);
const parent = get(object, parentPath);
if (typeof mutator === "function") {

@@ -97,3 +109,4 @@ parent[lastProperty] = mutator(parent[lastProperty]);

const extractPageInfos = responseData => {
// pkg/dist-src/extract-page-info.js
var extractPageInfos = (responseData) => {
const pageInfoPath = findPaginatedResourcePath(responseData);

@@ -106,40 +119,35 @@ return {

const isForwardSearch = givenPageInfo => {
// pkg/dist-src/page-info.js
var isForwardSearch = (givenPageInfo) => {
return givenPageInfo.hasOwnProperty("hasNextPage");
};
var getCursorFrom = (pageInfo) => isForwardSearch(pageInfo) ? pageInfo.endCursor : pageInfo.startCursor;
var hasAnotherPage = (pageInfo) => isForwardSearch(pageInfo) ? pageInfo.hasNextPage : pageInfo.hasPreviousPage;
const getCursorFrom = pageInfo => isForwardSearch(pageInfo) ? pageInfo.endCursor : pageInfo.startCursor;
const hasAnotherPage = pageInfo => isForwardSearch(pageInfo) ? pageInfo.hasNextPage : pageInfo.hasPreviousPage;
const createIterator = octokit => {
// pkg/dist-src/iterator.js
var createIterator = (octokit) => {
return (query, initialParameters = {}) => {
let nextPageExists = true;
let parameters = { ...initialParameters
};
let parameters = { ...initialParameters };
return {
[Symbol.asyncIterator]: () => ({
async next() {
if (!nextPageExists) return {
done: true,
value: {}
};
const response = await octokit.graphql(query, parameters);
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,
parameters = {
...parameters,
cursor: nextCursorValue
};
return {
done: false,
value: response
};
return { done: false, value: response };
}
})

@@ -150,26 +158,22 @@ };

const mergeResponses = (response1, response2) => {
// pkg/dist-src/merge-responses.js
var mergeResponses = (response1, response2) => {
if (Object.keys(response1).length === 0) {
return Object.assign(response1, response2);
}
const path = findPaginatedResourcePath(response1);
const nodesPath = [...path, "nodes"];
const newNodes = get(response2, nodesPath);
if (newNodes) {
set(response1, nodesPath, values => {
set(response1, nodesPath, (values) => {
return [...values, ...newNodes];
});
}
const edgesPath = [...path, "edges"];
const newEdges = get(response2, edgesPath);
if (newEdges) {
set(response1, edgesPath, values => {
set(response1, edgesPath, (values) => {
return [...values, ...newEdges];
});
}
const pageInfoPath = [...path, "pageInfo"];

@@ -180,11 +184,13 @@ set(response1, pageInfoPath, get(response2, pageInfoPath));

const createPaginate = octokit => {
// pkg/dist-src/paginate.js
var createPaginate = (octokit) => {
const iterator = createIterator(octokit);
return async (query, initialParameters = {}) => {
let mergedResponse = {};
for await (const response of iterator(query, initialParameters)) {
for await (const response of iterator(
query,
initialParameters
)) {
mergedResponse = mergeResponses(mergedResponse, response);
}
return mergedResponse;

@@ -194,2 +200,3 @@ };

// pkg/dist-src/index.js
function paginateGraphql(octokit) {

@@ -205,4 +212,5 @@ octokit.graphql;

}
exports.paginateGraphql = paginateGraphql;
//# sourceMappingURL=index.js.map
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
paginateGraphql
});

@@ -1,24 +0,34 @@

// Todo: Add link to explanation
const generateMessage = (path, cursorValue) => `The cursor at "${path.join(",")}" did not change its value "${cursorValue}" after a page transition. Please make sure your that your query is set up correctly.`;
const generateMessage = (path, cursorValue) => `The cursor at "${path.join(
","
)}" did not change its value "${cursorValue}" after a page transition. Please make sure your that your query is set up correctly.`;
class MissingCursorChange extends Error {
constructor(pageInfo, cursorValue) {
super(generateMessage(pageInfo.pathInQuery, cursorValue));
this.pageInfo = pageInfo;
this.cursorValue = cursorValue;
this.name = "MissingCursorChangeError";
if (Error.captureStackTrace) {
Error.captureStackTrace(this, this.constructor);
}
constructor(pageInfo, cursorValue) {
super(generateMessage(pageInfo.pathInQuery, cursorValue));
this.pageInfo = pageInfo;
this.cursorValue = cursorValue;
this.name = "MissingCursorChangeError";
if (Error.captureStackTrace) {
Error.captureStackTrace(this, this.constructor);
}
}
}
class MissingPageInfo extends Error {
constructor(response) {
super(`No pageInfo property found in response. Please make sure to specify the pageInfo in your query. Response-Data: ${JSON.stringify(response, null, 2)}`);
this.response = response;
this.name = "MissingPageInfo";
if (Error.captureStackTrace) {
Error.captureStackTrace(this, this.constructor);
}
constructor(response) {
super(
`No pageInfo property found in response. Please make sure to specify the pageInfo in your query. Response-Data: ${JSON.stringify(
response,
null,
2
)}`
);
this.response = response;
this.name = "MissingPageInfo";
if (Error.captureStackTrace) {
Error.captureStackTrace(this, this.constructor);
}
}
}
export { MissingCursorChange, MissingPageInfo };
export {
MissingCursorChange,
MissingPageInfo
};
import { findPaginatedResourcePath, get } from "./object-helpers";
const extractPageInfos = (responseData) => {
const pageInfoPath = findPaginatedResourcePath(responseData);
return {
pathInQuery: pageInfoPath,
pageInfo: get(responseData, [...pageInfoPath, "pageInfo"]),
};
const pageInfoPath = findPaginatedResourcePath(responseData);
return {
pathInQuery: pageInfoPath,
pageInfo: get(responseData, [...pageInfoPath, "pageInfo"])
};
};
export { extractPageInfos };
export {
extractPageInfos
};
import { createIterator } from "./iterator";
import { createPaginate } from "./paginate";
export function paginateGraphql(octokit) {
octokit.graphql;
return {
graphql: Object.assign(octokit.graphql, {
paginate: Object.assign(createPaginate(octokit), {
iterator: createIterator(octokit),
}),
}),
};
function paginateGraphql(octokit) {
octokit.graphql;
return {
graphql: Object.assign(octokit.graphql, {
paginate: Object.assign(createPaginate(octokit), {
iterator: createIterator(octokit)
})
})
};
}
export {
paginateGraphql
};

@@ -5,27 +5,32 @@ import { extractPageInfos } from "./extract-page-info";

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 };
},
}),
};
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 };
export {
createIterator
};
import { findPaginatedResourcePath, get, set } from "./object-helpers";
const mergeResponses = (response1, response2) => {
if (Object.keys(response1).length === 0) {
return Object.assign(response1, response2);
}
const path = findPaginatedResourcePath(response1);
const nodesPath = [...path, "nodes"];
const newNodes = get(response2, nodesPath);
if (newNodes) {
set(response1, nodesPath, (values) => {
return [...values, ...newNodes];
});
}
const edgesPath = [...path, "edges"];
const newEdges = get(response2, edgesPath);
if (newEdges) {
set(response1, edgesPath, (values) => {
return [...values, ...newEdges];
});
}
const pageInfoPath = [...path, "pageInfo"];
set(response1, pageInfoPath, get(response2, pageInfoPath));
return response1;
if (Object.keys(response1).length === 0) {
return Object.assign(response1, response2);
}
const path = findPaginatedResourcePath(response1);
const nodesPath = [...path, "nodes"];
const newNodes = get(response2, nodesPath);
if (newNodes) {
set(response1, nodesPath, (values) => {
return [...values, ...newNodes];
});
}
const edgesPath = [...path, "edges"];
const newEdges = get(response2, edgesPath);
if (newEdges) {
set(response1, edgesPath, (values) => {
return [...values, ...newEdges];
});
}
const pageInfoPath = [...path, "pageInfo"];
set(response1, pageInfoPath, get(response2, pageInfoPath));
return response1;
};
export { mergeResponses };
export {
mergeResponses
};
import { MissingPageInfo } from "./errors";
const isObject = (value) => Object.prototype.toString.call(value) === "[object Object]";
function findPaginatedResourcePath(responseData) {
const paginatedResourcePath = deepFindPathToProperty(responseData, "pageInfo");
if (paginatedResourcePath.length === 0) {
throw new MissingPageInfo(responseData);
}
return paginatedResourcePath;
const paginatedResourcePath = deepFindPathToProperty(
responseData,
"pageInfo"
);
if (paginatedResourcePath.length === 0) {
throw new MissingPageInfo(responseData);
}
return paginatedResourcePath;
}
const deepFindPathToProperty = (object, searchProp, path = []) => {
for (const key of Object.keys(object)) {
const currentPath = [...path, key];
const currentValue = object[key];
if (currentValue.hasOwnProperty(searchProp)) {
return currentPath;
}
if (isObject(currentValue)) {
const result = deepFindPathToProperty(currentValue, searchProp, currentPath);
if (result.length > 0) {
return result;
}
}
for (const key of Object.keys(object)) {
const currentPath = [...path, key];
const currentValue = object[key];
if (currentValue.hasOwnProperty(searchProp)) {
return currentPath;
}
return [];
if (isObject(currentValue)) {
const result = deepFindPathToProperty(
currentValue,
searchProp,
currentPath
);
if (result.length > 0) {
return result;
}
}
}
return [];
};
/**
* The interfaces of the "get" and "set" functions are equal to those of lodash:
* https://lodash.com/docs/4.17.15#get
* https://lodash.com/docs/4.17.15#set
*
* They are cut down to our purposes, but could be replaced by the lodash calls
* if we ever want to have that dependency.
*/
const get = (object, path) => {
return path.reduce((current, nextProperty) => current[nextProperty], object);
return path.reduce((current, nextProperty) => current[nextProperty], object);
};
const set = (object, path, mutator) => {
const lastProperty = path[path.length - 1];
const parentPath = [...path].slice(0, -1);
const parent = get(object, parentPath);
if (typeof mutator === "function") {
parent[lastProperty] = mutator(parent[lastProperty]);
}
else {
parent[lastProperty] = mutator;
}
const lastProperty = path[path.length - 1];
const parentPath = [...path].slice(0, -1);
const parent = get(object, parentPath);
if (typeof mutator === "function") {
parent[lastProperty] = mutator(parent[lastProperty]);
} else {
parent[lastProperty] = mutator;
}
};
export { findPaginatedResourcePath, get, set };
export {
findPaginatedResourcePath,
get,
set
};
const isForwardSearch = (givenPageInfo) => {
return givenPageInfo.hasOwnProperty("hasNextPage");
return givenPageInfo.hasOwnProperty("hasNextPage");
};
const getCursorFrom = (pageInfo) => isForwardSearch(pageInfo) ? pageInfo.endCursor : pageInfo.startCursor;
const hasAnotherPage = (pageInfo) => isForwardSearch(pageInfo) ? pageInfo.hasNextPage : pageInfo.hasPreviousPage;
export { getCursorFrom, hasAnotherPage };
export {
getCursorFrom,
hasAnotherPage
};
import { mergeResponses } from "./merge-responses";
import { createIterator } from "./iterator";
const createPaginate = (octokit) => {
const iterator = createIterator(octokit);
return async (query, initialParameters = {}) => {
let mergedResponse = {};
for await (const response of iterator(query, initialParameters)) {
mergedResponse = mergeResponses(mergedResponse, response);
}
return mergedResponse;
};
const iterator = createIterator(octokit);
return async (query, initialParameters = {}) => {
let mergedResponse = {};
for await (const response of iterator(
query,
initialParameters
)) {
mergedResponse = mergeResponses(mergedResponse, response);
}
return mergedResponse;
};
};
export { createPaginate };
export {
createPaginate
};
import { Octokit } from "@octokit/core";
export { PageInfoForward, PageInfoBackward } from "./page-info";
export type { PageInfoForward, PageInfoBackward } from "./page-info";
export declare function paginateGraphql(octokit: Octokit): {

@@ -4,0 +4,0 @@ graphql: import("@octokit/graphql/dist-types/types").graphql & {

@@ -11,4 +11,4 @@ declare function findPaginatedResourcePath(responseData: any): string[];

declare const get: (object: any, path: string[]) => any;
declare type Mutator = any | ((value: unknown) => any);
type Mutator = any | ((value: unknown) => any);
declare const set: (object: any, path: string[], mutator: Mutator) => void;
export { findPaginatedResourcePath, get, set };

@@ -1,12 +0,12 @@

declare type CursorValue = string | null;
declare type PageInfoForward = {
type CursorValue = string | null;
type PageInfoForward = {
hasNextPage: boolean;
endCursor: CursorValue;
};
declare type PageInfoBackward = {
type PageInfoBackward = {
hasPreviousPage: boolean;
startCursor: CursorValue;
};
declare type PageInfo = PageInfoForward | PageInfoBackward;
declare type PageInfoContext = {
type PageInfo = PageInfoForward | PageInfoBackward;
type PageInfoContext = {
pageInfo: PageInfo;

@@ -13,0 +13,0 @@ pathInQuery: string[];

@@ -1,160 +0,179 @@

// Todo: Add link to explanation
const generateMessage = (path, cursorValue) => `The cursor at "${path.join(",")}" did not change its value "${cursorValue}" after a page transition. Please make sure your that your query is set up correctly.`;
class MissingCursorChange extends Error {
constructor(pageInfo, cursorValue) {
super(generateMessage(pageInfo.pathInQuery, cursorValue));
this.pageInfo = pageInfo;
this.cursorValue = cursorValue;
this.name = "MissingCursorChangeError";
if (Error.captureStackTrace) {
Error.captureStackTrace(this, this.constructor);
}
// pkg/dist-src/errors.js
var generateMessage = (path, cursorValue) => `The cursor at "${path.join(
","
)}" did not change its value "${cursorValue}" after a page transition. Please make sure your that your query is set up correctly.`;
var MissingCursorChange = class extends Error {
constructor(pageInfo, cursorValue) {
super(generateMessage(pageInfo.pathInQuery, cursorValue));
this.pageInfo = pageInfo;
this.cursorValue = cursorValue;
this.name = "MissingCursorChangeError";
if (Error.captureStackTrace) {
Error.captureStackTrace(this, this.constructor);
}
}
class MissingPageInfo extends Error {
constructor(response) {
super(`No pageInfo property found in response. Please make sure to specify the pageInfo in your query. Response-Data: ${JSON.stringify(response, null, 2)}`);
this.response = response;
this.name = "MissingPageInfo";
if (Error.captureStackTrace) {
Error.captureStackTrace(this, this.constructor);
}
}
};
var MissingPageInfo = class extends Error {
constructor(response) {
super(
`No pageInfo property found in response. Please make sure to specify the pageInfo in your query. Response-Data: ${JSON.stringify(
response,
null,
2
)}`
);
this.response = response;
this.name = "MissingPageInfo";
if (Error.captureStackTrace) {
Error.captureStackTrace(this, this.constructor);
}
}
}
};
const isObject = (value) => Object.prototype.toString.call(value) === "[object Object]";
// pkg/dist-src/object-helpers.js
var isObject = (value) => Object.prototype.toString.call(value) === "[object Object]";
function findPaginatedResourcePath(responseData) {
const paginatedResourcePath = deepFindPathToProperty(responseData, "pageInfo");
if (paginatedResourcePath.length === 0) {
throw new MissingPageInfo(responseData);
}
return paginatedResourcePath;
const paginatedResourcePath = deepFindPathToProperty(
responseData,
"pageInfo"
);
if (paginatedResourcePath.length === 0) {
throw new MissingPageInfo(responseData);
}
return paginatedResourcePath;
}
const deepFindPathToProperty = (object, searchProp, path = []) => {
for (const key of Object.keys(object)) {
const currentPath = [...path, key];
const currentValue = object[key];
if (currentValue.hasOwnProperty(searchProp)) {
return currentPath;
}
if (isObject(currentValue)) {
const result = deepFindPathToProperty(currentValue, searchProp, currentPath);
if (result.length > 0) {
return result;
}
}
var deepFindPathToProperty = (object, searchProp, path = []) => {
for (const key of Object.keys(object)) {
const currentPath = [...path, key];
const currentValue = object[key];
if (currentValue.hasOwnProperty(searchProp)) {
return currentPath;
}
return [];
if (isObject(currentValue)) {
const result = deepFindPathToProperty(
currentValue,
searchProp,
currentPath
);
if (result.length > 0) {
return result;
}
}
}
return [];
};
/**
* The interfaces of the "get" and "set" functions are equal to those of lodash:
* https://lodash.com/docs/4.17.15#get
* https://lodash.com/docs/4.17.15#set
*
* They are cut down to our purposes, but could be replaced by the lodash calls
* if we ever want to have that dependency.
*/
const get = (object, path) => {
return path.reduce((current, nextProperty) => current[nextProperty], object);
var get = (object, path) => {
return path.reduce((current, nextProperty) => current[nextProperty], object);
};
const set = (object, path, mutator) => {
const lastProperty = path[path.length - 1];
const parentPath = [...path].slice(0, -1);
const parent = get(object, parentPath);
if (typeof mutator === "function") {
parent[lastProperty] = mutator(parent[lastProperty]);
}
else {
parent[lastProperty] = mutator;
}
var set = (object, path, mutator) => {
const lastProperty = path[path.length - 1];
const parentPath = [...path].slice(0, -1);
const parent = get(object, parentPath);
if (typeof mutator === "function") {
parent[lastProperty] = mutator(parent[lastProperty]);
} else {
parent[lastProperty] = mutator;
}
};
const extractPageInfos = (responseData) => {
const pageInfoPath = findPaginatedResourcePath(responseData);
return {
pathInQuery: pageInfoPath,
pageInfo: get(responseData, [...pageInfoPath, "pageInfo"]),
};
// pkg/dist-src/extract-page-info.js
var extractPageInfos = (responseData) => {
const pageInfoPath = findPaginatedResourcePath(responseData);
return {
pathInQuery: pageInfoPath,
pageInfo: get(responseData, [...pageInfoPath, "pageInfo"])
};
};
const isForwardSearch = (givenPageInfo) => {
return givenPageInfo.hasOwnProperty("hasNextPage");
// pkg/dist-src/page-info.js
var isForwardSearch = (givenPageInfo) => {
return givenPageInfo.hasOwnProperty("hasNextPage");
};
const getCursorFrom = (pageInfo) => isForwardSearch(pageInfo) ? pageInfo.endCursor : pageInfo.startCursor;
const hasAnotherPage = (pageInfo) => isForwardSearch(pageInfo) ? pageInfo.hasNextPage : pageInfo.hasPreviousPage;
var getCursorFrom = (pageInfo) => isForwardSearch(pageInfo) ? pageInfo.endCursor : pageInfo.startCursor;
var hasAnotherPage = (pageInfo) => isForwardSearch(pageInfo) ? pageInfo.hasNextPage : pageInfo.hasPreviousPage;
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 };
},
}),
};
// pkg/dist-src/iterator.js
var 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 };
}
})
};
};
};
const mergeResponses = (response1, response2) => {
if (Object.keys(response1).length === 0) {
return Object.assign(response1, response2);
}
const path = findPaginatedResourcePath(response1);
const nodesPath = [...path, "nodes"];
const newNodes = get(response2, nodesPath);
if (newNodes) {
set(response1, nodesPath, (values) => {
return [...values, ...newNodes];
});
}
const edgesPath = [...path, "edges"];
const newEdges = get(response2, edgesPath);
if (newEdges) {
set(response1, edgesPath, (values) => {
return [...values, ...newEdges];
});
}
const pageInfoPath = [...path, "pageInfo"];
set(response1, pageInfoPath, get(response2, pageInfoPath));
return response1;
// pkg/dist-src/merge-responses.js
var mergeResponses = (response1, response2) => {
if (Object.keys(response1).length === 0) {
return Object.assign(response1, response2);
}
const path = findPaginatedResourcePath(response1);
const nodesPath = [...path, "nodes"];
const newNodes = get(response2, nodesPath);
if (newNodes) {
set(response1, nodesPath, (values) => {
return [...values, ...newNodes];
});
}
const edgesPath = [...path, "edges"];
const newEdges = get(response2, edgesPath);
if (newEdges) {
set(response1, edgesPath, (values) => {
return [...values, ...newEdges];
});
}
const pageInfoPath = [...path, "pageInfo"];
set(response1, pageInfoPath, get(response2, pageInfoPath));
return response1;
};
const createPaginate = (octokit) => {
const iterator = createIterator(octokit);
return async (query, initialParameters = {}) => {
let mergedResponse = {};
for await (const response of iterator(query, initialParameters)) {
mergedResponse = mergeResponses(mergedResponse, response);
}
return mergedResponse;
};
// pkg/dist-src/paginate.js
var createPaginate = (octokit) => {
const iterator = createIterator(octokit);
return async (query, initialParameters = {}) => {
let mergedResponse = {};
for await (const response of iterator(
query,
initialParameters
)) {
mergedResponse = mergeResponses(mergedResponse, response);
}
return mergedResponse;
};
};
// pkg/dist-src/index.js
function paginateGraphql(octokit) {
octokit.graphql;
return {
graphql: Object.assign(octokit.graphql, {
paginate: Object.assign(createPaginate(octokit), {
iterator: createIterator(octokit),
}),
}),
};
octokit.graphql;
return {
graphql: Object.assign(octokit.graphql, {
paginate: Object.assign(createPaginate(octokit), {
iterator: createIterator(octokit)
})
})
};
}
export { paginateGraphql };
//# sourceMappingURL=index.js.map
export {
paginateGraphql
};
{
"name": "@octokit/plugin-paginate-graphql",
"publishConfig": {
"access": "public"
},
"version": "2.0.2",
"description": "Octokit plugin to paginate GraphQL API endpoint responses",
"version": "2.0.1",
"license": "MIT",
"files": [
"dist-*/",
"bin/"
],
"source": "dist-src/index.js",
"types": "dist-types/index.d.ts",
"main": "dist-node/index.js",
"module": "dist-web/index.js",
"pika": true,
"sideEffects": false,
"repository": "github:octokit/plugin-paginate-graphql.js",
"keywords": [

@@ -22,4 +16,3 @@ "github",

],
"repository": "github:octokit/plugin-paginate-graphql.js",
"dependencies": {},
"license": "MIT",
"peerDependencies": {

@@ -30,22 +23,25 @@ "@octokit/core": ">=4"

"@octokit/core": "^4.0.0",
"@octokit/plugin-rest-endpoint-methods": "^6.0.0",
"@octokit/tsconfig": "1.0.2",
"@pika/pack": "^0.3.7",
"@pika/plugin-build-node": "^0.9.0",
"@pika/plugin-build-web": "^0.9.0",
"@pika/plugin-ts-standard-pkg": "^0.9.0",
"@octokit/plugin-rest-endpoint-methods": "^7.0.0",
"@octokit/tsconfig": "^1.0.2",
"@types/fetch-mock": "^7.3.1",
"@types/jest": "^29.0.0",
"@types/node": "^16.0.0",
"@types/node": "^18.0.0",
"esbuild": "^0.17.19",
"fetch-mock": "^9.0.0",
"glob": "^10.2.6",
"jest": "^29.0.0",
"npm-run-all": "^4.1.5",
"prettier": "2.7.1",
"prettier": "2.8.8",
"semantic-release-plugin-update-version-in-files": "^1.0.0",
"ts-jest": "^29.0.0",
"typescript": "^4.0.2"
"typescript": "^5.0.0"
},
"publishConfig": {
"access": "public"
}
"files": [
"dist-*/**",
"bin/**"
],
"browser": "dist-web/index.js",
"types": "dist-types/index.d.ts",
"module": "dist-src/index.js",
"sideEffects": false
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc