First upload version 0.0.1
This commit is contained in:
7
node_modules/@octokit/plugin-paginate-graphql/LICENSE
generated
vendored
Normal file
7
node_modules/@octokit/plugin-paginate-graphql/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
MIT License Copyright (c) 2019 Octokit contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
291
node_modules/@octokit/plugin-paginate-graphql/README.md
generated
vendored
Normal file
291
node_modules/@octokit/plugin-paginate-graphql/README.md
generated
vendored
Normal file
@@ -0,0 +1,291 @@
|
||||
# plugin-paginate-graphql.js
|
||||
|
||||
> Octokit plugin to paginate GraphQL API endpoint responses
|
||||
|
||||
[](https://www.npmjs.com/package/@octokit/plugin-paginate-graphql)
|
||||
[](https://github.com/octokit/plugin-paginate-graphql.js/actions?workflow=Test)
|
||||
|
||||
## Usage
|
||||
|
||||
<table>
|
||||
<tbody valign=top align=left>
|
||||
<tr><th>
|
||||
Browsers
|
||||
</th><td width=100%>
|
||||
|
||||
Load `@octokit/plugin-paginate-graphql` and [`@octokit/core`](https://github.com/octokit/core.js) (or core-compatible module) directly from [esm.sh](https://esm.sh)
|
||||
|
||||
```html
|
||||
<script type="module">
|
||||
import { Octokit } from "https://esm.sh/@octokit/core";
|
||||
import { paginateGraphQL } from "https://esm.sh/@octokit/plugin-paginate-graphql";
|
||||
</script>
|
||||
```
|
||||
|
||||
</td></tr>
|
||||
<tr><th>
|
||||
Node
|
||||
</th><td>
|
||||
|
||||
Install with `npm install @octokit/core @octokit/plugin-paginate-graphql`. Optionally replace `@octokit/core` with a core-compatible module
|
||||
|
||||
```js
|
||||
import { Octokit } from "@octokit/core";
|
||||
import { paginateGraphQL } from "@octokit/plugin-paginate-graphql";
|
||||
```
|
||||
|
||||
</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
> [!IMPORTANT]
|
||||
> As we use [conditional exports](https://nodejs.org/api/packages.html#conditional-exports), you will need to adapt your `tsconfig.json` by setting `"moduleResolution": "node16", "module": "node16"`.
|
||||
>
|
||||
> See the TypeScript docs on [package.json "exports"](https://www.typescriptlang.org/docs/handbook/modules/reference.html#packagejson-exports).<br>
|
||||
> See this [helpful guide on transitioning to ESM](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c) from [@sindresorhus](https://github.com/sindresorhus)
|
||||
|
||||
```js
|
||||
const MyOctokit = Octokit.plugin(paginateGraphQL);
|
||||
const octokit = new MyOctokit({ auth: "secret123" });
|
||||
|
||||
const { repository } = await octokit.graphql.paginate(
|
||||
`query paginate($cursor: String) {
|
||||
repository(owner: "octokit", name: "rest.js") {
|
||||
issues(first: 10, after: $cursor) {
|
||||
nodes {
|
||||
title
|
||||
}
|
||||
pageInfo {
|
||||
hasNextPage
|
||||
endCursor
|
||||
}
|
||||
}
|
||||
}
|
||||
}`,
|
||||
);
|
||||
|
||||
console.log(`Found ${repository.issues.nodes.length} issues!`);
|
||||
```
|
||||
|
||||
There are two conventions this plugin relies on:
|
||||
|
||||
1. The name of the cursor variable must be `$cursor`
|
||||
2. You must include a valid `pageInfo` object in the paginated resource (see [Pagination Direction](#pagination-direction) for more info on what is considered valid)
|
||||
|
||||
## `octokit.graphql.paginate()`
|
||||
|
||||
The `paginateGraphQL` plugin adds a new `octokit.graphql.paginate()` method which accepts a query with a single `$cursor` variable that is used to paginate.
|
||||
|
||||
The query gets passed over to the `octokit.graphql()`-function. The response is then scanned for the required `pageInfo`-object. If `hasNextPage` is `true`, it will automatically use the `endCursor` to execute the next query until `hasNextPage` is `false`.
|
||||
|
||||
While iterating, it continually merges all `nodes` and/or `edges` of all responses and returns a combined response in the end.
|
||||
|
||||
> **Warning**
|
||||
> Please note that this plugin only supports pagination of a single resource - so you can **not** execute queries with parallel or nested pagination. You can find more details in [the chapter below](#unsupported-nested-pagination).
|
||||
|
||||
## `octokit.graphql.paginate.iterator()`
|
||||
|
||||
If your target runtime environments supports async iterators (such as most modern browsers and Node 10+), you can iterate through each response:
|
||||
|
||||
```js
|
||||
const pageIterator = octokit.graphql.paginate.iterator(
|
||||
`query paginate($cursor: String) {
|
||||
repository(owner: "octokit", name: "rest.js") {
|
||||
issues(first: 10, after: $cursor) {
|
||||
nodes {
|
||||
title
|
||||
}
|
||||
pageInfo {
|
||||
hasNextPage
|
||||
endCursor
|
||||
}
|
||||
}
|
||||
}
|
||||
}`,
|
||||
);
|
||||
|
||||
for await (const response of pageIterator) {
|
||||
const issues = response.repository.issues;
|
||||
console.log(`${issues.length} issues found.`);
|
||||
}
|
||||
```
|
||||
|
||||
### Variables
|
||||
|
||||
Just like with [octokit/graphql.js](https://github.com/octokit/graphql.js/#variables), you can pass your own variables as a second parameter to the `paginate` or `iterator` function.
|
||||
|
||||
```js
|
||||
await octokit.graphql.paginate(
|
||||
`
|
||||
query paginate($cursor: String, $organization: String!) {
|
||||
repository(owner: $organization, name: "rest.js") {
|
||||
issues(first: 10, after: $cursor) {
|
||||
nodes {
|
||||
title
|
||||
}
|
||||
pageInfo {
|
||||
hasNextPage
|
||||
endCursor
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
{
|
||||
organization: "octokit",
|
||||
},
|
||||
);
|
||||
```
|
||||
|
||||
You can also use this to pass a initial cursor value:
|
||||
|
||||
```js
|
||||
await octokit.graphql.paginate(
|
||||
`
|
||||
query paginate($cursor: String, $organization: String!) {
|
||||
repository(owner: $organization, name: "rest.js") {
|
||||
issues(first: 10, after: $cursor) {
|
||||
nodes {
|
||||
title
|
||||
}
|
||||
pageInfo {
|
||||
hasNextPage
|
||||
endCursor
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
{
|
||||
organization: "octokit",
|
||||
cursor: "initialValue",
|
||||
},
|
||||
);
|
||||
```
|
||||
|
||||
### Pagination Direction
|
||||
|
||||
You can control the pagination direction by the properties defined in the `pageInfo` resource.
|
||||
|
||||
For a forward pagination, use:
|
||||
|
||||
```gql
|
||||
pageInfo {
|
||||
hasNextPage
|
||||
endCursor
|
||||
}
|
||||
```
|
||||
|
||||
For a backwards pagination, use:
|
||||
|
||||
```gql
|
||||
pageInfo {
|
||||
hasPreviousPage
|
||||
startCursor
|
||||
}
|
||||
```
|
||||
|
||||
If you provide all 4 properties in a `pageInfo`, the plugin will default to forward pagination.
|
||||
|
||||
### Unsupported: Nested pagination
|
||||
|
||||
Nested pagination with GraphQL is complicated, so the following **is not supported**:
|
||||
|
||||
```js
|
||||
await octokit.graphql.paginate((cursor) => {
|
||||
const issuesCursor = cursor.create("issuesCursor");
|
||||
const commentsCursor = cursor.create("issuesCursor");
|
||||
return `{
|
||||
repository(owner: "octokit", name: "rest.js") {
|
||||
issues(first: 10, after: ${issuesCursor}) {
|
||||
nodes {
|
||||
title,
|
||||
comments(first: 10, after: ${commentsCursor}) {
|
||||
nodes: {
|
||||
body
|
||||
}
|
||||
pageInfo {
|
||||
hasNextPage
|
||||
endCursor
|
||||
}
|
||||
}
|
||||
}
|
||||
pageInfo {
|
||||
hasNextPage
|
||||
endCursor
|
||||
}
|
||||
}
|
||||
}
|
||||
}`;
|
||||
});
|
||||
```
|
||||
|
||||
There is a great video from GitHub Universe 2019 [Advanced patterns for GitHub's GraphQL API](https://www.youtube.com/watch?v=i5pIszu9MeM&t=719s) by [@ReaLoretta](https://github.com/ReaLoretta) that goes into depth why this is so hard to achieve and patterns and ways around it.
|
||||
|
||||
### TypeScript Support
|
||||
|
||||
You can type the response of the `paginateGraphQL()` and `iterator()` functions like this:
|
||||
|
||||
```ts
|
||||
await octokit.graphql.paginate<RepositoryIssueResponseType>((cursor) => {
|
||||
return `{
|
||||
repository(owner: "octokit", name: "rest.js") {
|
||||
issues(first: 10, after: ${cursor.create()}) {
|
||||
nodes {
|
||||
title
|
||||
}
|
||||
pageInfo {
|
||||
hasNextPage
|
||||
endCursor
|
||||
}
|
||||
}
|
||||
}
|
||||
}`;
|
||||
});
|
||||
```
|
||||
|
||||
You can utilize the `PageInfoForward` and `PageInfoBackward`-Interfaces exported from this library to construct your response-types:
|
||||
|
||||
```ts
|
||||
import { PageInfoForward } from "@octokit/plugin-paginate-graphql";
|
||||
|
||||
type Issues = {
|
||||
title: string;
|
||||
};
|
||||
|
||||
type IssueResponseType = {
|
||||
repository: {
|
||||
issues: {
|
||||
nodes: Issues[];
|
||||
pageInfo: PageInfoForward;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
// Response will be of type IssueResponseType
|
||||
const response = await octokit.graphql.paginate<IssueResponseType>((cursor) => {
|
||||
return `{
|
||||
repository(owner: "octokit", name: "rest.js") {
|
||||
issues(first: 10, after: ${cursor.create()}) {
|
||||
nodes {
|
||||
title
|
||||
}
|
||||
pageInfo {
|
||||
hasNextPage
|
||||
endCursor
|
||||
}
|
||||
}
|
||||
}
|
||||
}`;
|
||||
});
|
||||
```
|
||||
|
||||
The `PageInfoBackward` contains the properties `hasPreviousPage` and `startCursor` and can be used accordingly when doing backwards pagination.
|
||||
|
||||
## Contributing
|
||||
|
||||
See [CONTRIBUTING.md](CONTRIBUTING.md)
|
||||
|
||||
## License
|
||||
|
||||
[MIT](LICENSE)
|
||||
181
node_modules/@octokit/plugin-paginate-graphql/dist-bundle/index.js
generated
vendored
Normal file
181
node_modules/@octokit/plugin-paginate-graphql/dist-bundle/index.js
generated
vendored
Normal file
@@ -0,0 +1,181 @@
|
||||
// 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;
|
||||
if (Error.captureStackTrace) {
|
||||
Error.captureStackTrace(this, this.constructor);
|
||||
}
|
||||
}
|
||||
name = "MissingCursorChangeError";
|
||||
};
|
||||
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;
|
||||
if (Error.captureStackTrace) {
|
||||
Error.captureStackTrace(this, this.constructor);
|
||||
}
|
||||
}
|
||||
name = "MissingPageInfo";
|
||||
};
|
||||
|
||||
// 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;
|
||||
}
|
||||
var deepFindPathToProperty = (object, searchProp, path = []) => {
|
||||
for (const key of Object.keys(object)) {
|
||||
const currentPath = [...path, key];
|
||||
const currentValue = object[key];
|
||||
if (isObject(currentValue)) {
|
||||
if (currentValue.hasOwnProperty(searchProp)) {
|
||||
return currentPath;
|
||||
}
|
||||
const result = deepFindPathToProperty(
|
||||
currentValue,
|
||||
searchProp,
|
||||
currentPath
|
||||
);
|
||||
if (result.length > 0) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
return [];
|
||||
};
|
||||
var get = (object, path) => {
|
||||
return path.reduce((current, nextProperty) => current[nextProperty], object);
|
||||
};
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
// pkg/dist-src/extract-page-info.js
|
||||
var extractPageInfos = (responseData) => {
|
||||
const pageInfoPath = findPaginatedResourcePath(responseData);
|
||||
return {
|
||||
pathInQuery: pageInfoPath,
|
||||
pageInfo: get(responseData, [...pageInfoPath, "pageInfo"])
|
||||
};
|
||||
};
|
||||
|
||||
// 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;
|
||||
|
||||
// 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 };
|
||||
}
|
||||
})
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
// 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;
|
||||
};
|
||||
|
||||
// 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/version.js
|
||||
var VERSION = "0.0.0-development";
|
||||
|
||||
// pkg/dist-src/index.js
|
||||
function paginateGraphQL(octokit) {
|
||||
return {
|
||||
graphql: Object.assign(octokit.graphql, {
|
||||
paginate: Object.assign(createPaginate(octokit), {
|
||||
iterator: createIterator(octokit)
|
||||
})
|
||||
})
|
||||
};
|
||||
}
|
||||
export {
|
||||
VERSION,
|
||||
paginateGraphQL
|
||||
};
|
||||
7
node_modules/@octokit/plugin-paginate-graphql/dist-bundle/index.js.map
generated
vendored
Normal file
7
node_modules/@octokit/plugin-paginate-graphql/dist-bundle/index.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
34
node_modules/@octokit/plugin-paginate-graphql/dist-src/errors.js
generated
vendored
Normal file
34
node_modules/@octokit/plugin-paginate-graphql/dist-src/errors.js
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
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;
|
||||
if (Error.captureStackTrace) {
|
||||
Error.captureStackTrace(this, this.constructor);
|
||||
}
|
||||
}
|
||||
name = "MissingCursorChangeError";
|
||||
}
|
||||
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;
|
||||
if (Error.captureStackTrace) {
|
||||
Error.captureStackTrace(this, this.constructor);
|
||||
}
|
||||
}
|
||||
name = "MissingPageInfo";
|
||||
}
|
||||
export {
|
||||
MissingCursorChange,
|
||||
MissingPageInfo
|
||||
};
|
||||
11
node_modules/@octokit/plugin-paginate-graphql/dist-src/extract-page-info.js
generated
vendored
Normal file
11
node_modules/@octokit/plugin-paginate-graphql/dist-src/extract-page-info.js
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
import { findPaginatedResourcePath, get } from "./object-helpers.js";
|
||||
const extractPageInfos = (responseData) => {
|
||||
const pageInfoPath = findPaginatedResourcePath(responseData);
|
||||
return {
|
||||
pathInQuery: pageInfoPath,
|
||||
pageInfo: get(responseData, [...pageInfoPath, "pageInfo"])
|
||||
};
|
||||
};
|
||||
export {
|
||||
extractPageInfos
|
||||
};
|
||||
16
node_modules/@octokit/plugin-paginate-graphql/dist-src/index.js
generated
vendored
Normal file
16
node_modules/@octokit/plugin-paginate-graphql/dist-src/index.js
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
import { createIterator } from "./iterator.js";
|
||||
import { createPaginate } from "./paginate.js";
|
||||
import { VERSION } from "./version.js";
|
||||
function paginateGraphQL(octokit) {
|
||||
return {
|
||||
graphql: Object.assign(octokit.graphql, {
|
||||
paginate: Object.assign(createPaginate(octokit), {
|
||||
iterator: createIterator(octokit)
|
||||
})
|
||||
})
|
||||
};
|
||||
}
|
||||
export {
|
||||
VERSION,
|
||||
paginateGraphQL
|
||||
};
|
||||
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
|
||||
};
|
||||
27
node_modules/@octokit/plugin-paginate-graphql/dist-src/merge-responses.js
generated
vendored
Normal file
27
node_modules/@octokit/plugin-paginate-graphql/dist-src/merge-responses.js
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
import { findPaginatedResourcePath, get, set } from "./object-helpers.js";
|
||||
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;
|
||||
};
|
||||
export {
|
||||
mergeResponses
|
||||
};
|
||||
50
node_modules/@octokit/plugin-paginate-graphql/dist-src/object-helpers.js
generated
vendored
Normal file
50
node_modules/@octokit/plugin-paginate-graphql/dist-src/object-helpers.js
generated
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
import { MissingPageInfo } from "./errors.js";
|
||||
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 deepFindPathToProperty = (object, searchProp, path = []) => {
|
||||
for (const key of Object.keys(object)) {
|
||||
const currentPath = [...path, key];
|
||||
const currentValue = object[key];
|
||||
if (isObject(currentValue)) {
|
||||
if (currentValue.hasOwnProperty(searchProp)) {
|
||||
return currentPath;
|
||||
}
|
||||
const result = deepFindPathToProperty(
|
||||
currentValue,
|
||||
searchProp,
|
||||
currentPath
|
||||
);
|
||||
if (result.length > 0) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
return [];
|
||||
};
|
||||
const 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;
|
||||
}
|
||||
};
|
||||
export {
|
||||
findPaginatedResourcePath,
|
||||
get,
|
||||
set
|
||||
};
|
||||
9
node_modules/@octokit/plugin-paginate-graphql/dist-src/page-info.js
generated
vendored
Normal file
9
node_modules/@octokit/plugin-paginate-graphql/dist-src/page-info.js
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
const isForwardSearch = (givenPageInfo) => {
|
||||
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
|
||||
};
|
||||
18
node_modules/@octokit/plugin-paginate-graphql/dist-src/paginate.js
generated
vendored
Normal file
18
node_modules/@octokit/plugin-paginate-graphql/dist-src/paginate.js
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
import { mergeResponses } from "./merge-responses.js";
|
||||
import { createIterator } from "./iterator.js";
|
||||
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;
|
||||
};
|
||||
};
|
||||
export {
|
||||
createPaginate
|
||||
};
|
||||
4
node_modules/@octokit/plugin-paginate-graphql/dist-src/version.js
generated
vendored
Normal file
4
node_modules/@octokit/plugin-paginate-graphql/dist-src/version.js
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
const VERSION = "6.0.0";
|
||||
export {
|
||||
VERSION
|
||||
};
|
||||
13
node_modules/@octokit/plugin-paginate-graphql/dist-types/errors.d.ts
generated
vendored
Normal file
13
node_modules/@octokit/plugin-paginate-graphql/dist-types/errors.d.ts
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
import type { CursorValue, PageInfoContext } from "./page-info.js";
|
||||
declare class MissingCursorChange extends Error {
|
||||
readonly pageInfo: PageInfoContext;
|
||||
readonly cursorValue: CursorValue;
|
||||
name: string;
|
||||
constructor(pageInfo: PageInfoContext, cursorValue: CursorValue);
|
||||
}
|
||||
declare class MissingPageInfo extends Error {
|
||||
readonly response: any;
|
||||
name: string;
|
||||
constructor(response: any);
|
||||
}
|
||||
export { MissingCursorChange, MissingPageInfo };
|
||||
3
node_modules/@octokit/plugin-paginate-graphql/dist-types/extract-page-info.d.ts
generated
vendored
Normal file
3
node_modules/@octokit/plugin-paginate-graphql/dist-types/extract-page-info.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import type { PageInfoContext } from "./page-info.js";
|
||||
declare const extractPageInfos: (responseData: any) => PageInfoContext;
|
||||
export { extractPageInfos };
|
||||
13
node_modules/@octokit/plugin-paginate-graphql/dist-types/index.d.ts
generated
vendored
Normal file
13
node_modules/@octokit/plugin-paginate-graphql/dist-types/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
import type { Octokit } from "@octokit/core";
|
||||
import { createIterator } from "./iterator.js";
|
||||
import { createPaginate } from "./paginate.js";
|
||||
export type { PageInfoForward, PageInfoBackward } from "./page-info.js";
|
||||
export { VERSION } from "./version.js";
|
||||
export type paginateGraphQLInterface = {
|
||||
graphql: Octokit["graphql"] & {
|
||||
paginate: ReturnType<typeof createPaginate> & {
|
||||
iterator: ReturnType<typeof createIterator>;
|
||||
};
|
||||
};
|
||||
};
|
||||
export declare function paginateGraphQL(octokit: Octokit): paginateGraphQLInterface;
|
||||
10
node_modules/@octokit/plugin-paginate-graphql/dist-types/iterator.d.ts
generated
vendored
Normal file
10
node_modules/@octokit/plugin-paginate-graphql/dist-types/iterator.d.ts
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
import type { Octokit } from "@octokit/core";
|
||||
declare const createIterator: (octokit: Octokit) => <ResponseType = any>(query: string, initialParameters?: Record<string, any>) => {
|
||||
[Symbol.asyncIterator]: () => {
|
||||
next(): Promise<{
|
||||
done: boolean;
|
||||
value: ResponseType;
|
||||
}>;
|
||||
};
|
||||
};
|
||||
export { createIterator };
|
||||
2
node_modules/@octokit/plugin-paginate-graphql/dist-types/merge-responses.d.ts
generated
vendored
Normal file
2
node_modules/@octokit/plugin-paginate-graphql/dist-types/merge-responses.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
declare const mergeResponses: <ResponseType extends object = any>(response1: ResponseType, response2: ResponseType) => ResponseType;
|
||||
export { mergeResponses };
|
||||
13
node_modules/@octokit/plugin-paginate-graphql/dist-types/object-helpers.d.ts
generated
vendored
Normal file
13
node_modules/@octokit/plugin-paginate-graphql/dist-types/object-helpers.d.ts
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
declare function findPaginatedResourcePath(responseData: any): string[];
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
declare const get: (object: any, path: string[]) => any;
|
||||
type Mutator = any | ((value: unknown) => any);
|
||||
declare const set: (object: any, path: string[], mutator: Mutator) => void;
|
||||
export { findPaginatedResourcePath, get, set };
|
||||
18
node_modules/@octokit/plugin-paginate-graphql/dist-types/page-info.d.ts
generated
vendored
Normal file
18
node_modules/@octokit/plugin-paginate-graphql/dist-types/page-info.d.ts
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
type CursorValue = string | null;
|
||||
type PageInfoForward = {
|
||||
hasNextPage: boolean;
|
||||
endCursor: CursorValue;
|
||||
};
|
||||
type PageInfoBackward = {
|
||||
hasPreviousPage: boolean;
|
||||
startCursor: CursorValue;
|
||||
};
|
||||
type PageInfo = PageInfoForward | PageInfoBackward;
|
||||
type PageInfoContext = {
|
||||
pageInfo: PageInfo;
|
||||
pathInQuery: string[];
|
||||
};
|
||||
declare const getCursorFrom: (pageInfo: PageInfo) => CursorValue;
|
||||
declare const hasAnotherPage: (pageInfo: PageInfo) => boolean;
|
||||
export { getCursorFrom, hasAnotherPage };
|
||||
export type { PageInfo, PageInfoForward, PageInfoBackward, PageInfoContext, CursorValue, };
|
||||
3
node_modules/@octokit/plugin-paginate-graphql/dist-types/paginate.d.ts
generated
vendored
Normal file
3
node_modules/@octokit/plugin-paginate-graphql/dist-types/paginate.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import type { Octokit } from "@octokit/core";
|
||||
declare const createPaginate: (octokit: Octokit) => <ResponseType extends object = any>(query: string, initialParameters?: Record<string, any>) => Promise<ResponseType>;
|
||||
export { createPaginate };
|
||||
1
node_modules/@octokit/plugin-paginate-graphql/dist-types/version.d.ts
generated
vendored
Normal file
1
node_modules/@octokit/plugin-paginate-graphql/dist-types/version.d.ts
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export declare const VERSION = "6.0.0";
|
||||
52
node_modules/@octokit/plugin-paginate-graphql/package.json
generated
vendored
Normal file
52
node_modules/@octokit/plugin-paginate-graphql/package.json
generated
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
{
|
||||
"name": "@octokit/plugin-paginate-graphql",
|
||||
"publishConfig": {
|
||||
"access": "public",
|
||||
"provenance": true
|
||||
},
|
||||
"type": "module",
|
||||
"version": "6.0.0",
|
||||
"description": "Octokit plugin to paginate GraphQL API endpoint responses",
|
||||
"repository": "github:octokit/plugin-paginate-graphql.js",
|
||||
"keywords": [
|
||||
"github",
|
||||
"api",
|
||||
"sdk",
|
||||
"toolkit"
|
||||
],
|
||||
"license": "MIT",
|
||||
"peerDependencies": {
|
||||
"@octokit/core": ">=6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@octokit/core": "^6.1.5",
|
||||
"@octokit/plugin-rest-endpoint-methods": "^14.0.0",
|
||||
"@octokit/tsconfig": "^4.0.0",
|
||||
"@types/node": "^22.0.0",
|
||||
"@vitest/coverage-v8": "^3.0.0",
|
||||
"esbuild": "^0.25.0",
|
||||
"fetch-mock": "^12.0.0",
|
||||
"glob": "^10.2.6",
|
||||
"prettier": "3.5.3",
|
||||
"semantic-release-plugin-update-version-in-files": "^2.0.0",
|
||||
"ts-jest": "^29.0.0",
|
||||
"typescript": "^5.0.0",
|
||||
"vitest": "^3.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 20"
|
||||
},
|
||||
"files": [
|
||||
"dist-*/**",
|
||||
"bin/**"
|
||||
],
|
||||
"types": "dist-types/index.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./dist-types/index.d.ts",
|
||||
"import": "./dist-bundle/index.js",
|
||||
"default": "./dist-bundle/index.js"
|
||||
}
|
||||
},
|
||||
"sideEffects": false
|
||||
}
|
||||
Reference in New Issue
Block a user