@octokit/plugin-paginate-rest
Advanced tools
Comparing version 2.1.0 to 2.2.0
@@ -5,3 +5,3 @@ 'use strict'; | ||
const VERSION = "2.1.0"; | ||
const VERSION = "2.2.0"; | ||
@@ -8,0 +8,0 @@ /** |
@@ -1,1 +0,1 @@ | ||
export const VERSION = "2.1.0"; | ||
export const VERSION = "2.2.0"; |
import { Octokit } from "@octokit/core"; | ||
import { MapFunction, PaginationResults, RequestParameters, Route, RequestInterface } from "./types"; | ||
export declare function paginate(octokit: Octokit, route: Route | RequestInterface, parameters?: RequestParameters, mapFn?: MapFunction): Promise<PaginationResults<any>>; | ||
export declare function paginate(octokit: Octokit, route: Route | RequestInterface, parameters?: RequestParameters, mapFn?: MapFunction): Promise<PaginationResults<unknown>>; |
import * as OctokitTypes from "@octokit/types"; | ||
export { EndpointOptions, RequestInterface, OctokitResponse, RequestParameters, Route, } from "@octokit/types"; | ||
import { PaginatingEndpoints } from "./generated/paginating-endpoints"; | ||
declare type KnownKeys<T> = Extract<{ | ||
[K in keyof T]: string extends K ? never : number extends K ? never : K; | ||
} extends { | ||
[_ in keyof T]: infer U; | ||
} ? U : never, keyof T>; | ||
declare type KeysMatching<T, V> = { | ||
[K in keyof T]: T[K] extends V ? K : never; | ||
}[keyof T]; | ||
declare type KnownKeysMatching<T, V> = KeysMatching<Pick<T, KnownKeys<T>>, V>; | ||
declare type GetResultsType<T> = T extends { | ||
data: any[]; | ||
} ? T["data"] : T extends { | ||
data: object; | ||
} ? T["data"][KnownKeysMatching<T["data"], any[]>] : never; | ||
declare type NormalizeResponse<T> = T & { | ||
data: GetResultsType<T>; | ||
}; | ||
export interface MapFunction<T = unknown, R = unknown> { | ||
(response: OctokitTypes.OctokitResponse<PaginationResults<T>>, done: () => void): R[]; | ||
} | ||
export declare type PaginationResults<T = unknown> = T[]; | ||
export interface PaginateInterface { | ||
@@ -18,3 +40,3 @@ /** | ||
/** | ||
* Paginate a request using an endpoint route string and map each response to a custom array | ||
* Paginate a request using a known endpoint route string and map each response to a custom array | ||
* | ||
@@ -24,5 +46,5 @@ * @param {string} route Request method + URL. Example: `'GET /orgs/:org'` | ||
*/ | ||
<T, R>(route: OctokitTypes.Route, mapFn: MapFunction<T>): Promise<PaginationResults<R>>; | ||
<R extends keyof PaginatingEndpoints, MR extends unknown[]>(route: R, mapFn: (response: PaginatingEndpoints[R]["response"], done: () => void) => MR): Promise<MR>; | ||
/** | ||
* Paginate a request using an endpoint route string and parameters, and map each response to a custom array | ||
* Paginate a request using a known endpoint route string and parameters, and map each response to a custom array | ||
* | ||
@@ -33,37 +55,39 @@ * @param {string} route Request method + URL. Example: `'GET /orgs/:org'` | ||
*/ | ||
<T, R>(route: OctokitTypes.Route, parameters: OctokitTypes.RequestParameters, mapFn: MapFunction<T>): Promise<PaginationResults<R>>; | ||
<R extends keyof PaginatingEndpoints, MR extends unknown[]>(route: R, parameters: PaginatingEndpoints[R]["parameters"], mapFn: (response: PaginatingEndpoints[R]["response"], done: () => void) => MR): Promise<MR>; | ||
/** | ||
* Paginate a request using an endpoint route string and parameters | ||
* Paginate a request using an known endpoint route string | ||
* | ||
* @param {string} route Request method + URL. Example: `'GET /orgs/:org'` | ||
* @param {object} parameters URL, query or body parameters, as well as `headers`, `mediaType.{format|previews}`, `request`, or `baseUrl`. | ||
* @param {object} parameters? URL, query or body parameters, as well as `headers`, `mediaType.{format|previews}`, `request`, or `baseUrl`. | ||
*/ | ||
<T>(route: OctokitTypes.Route, parameters: OctokitTypes.RequestParameters): Promise<PaginationResults<T>>; | ||
<R extends keyof PaginatingEndpoints>(route: R, parameters?: PaginatingEndpoints[R]["parameters"]): Promise<PaginatingEndpoints[R]["response"]["data"]>; | ||
/** | ||
* Paginate a request using an endpoint route string | ||
* Paginate a request using an unknown endpoint route string | ||
* | ||
* @param {string} route Request method + URL. Example: `'GET /orgs/:org'` | ||
* @param {object} parameters? URL, query or body parameters, as well as `headers`, `mediaType.{format|previews}`, `request`, or `baseUrl`. | ||
*/ | ||
<T>(route: OctokitTypes.Route): Promise<PaginationResults<T>>; | ||
<T, R extends OctokitTypes.Route = OctokitTypes.Route>(route: R, parameters?: R extends keyof PaginatingEndpoints ? PaginatingEndpoints[R]["parameters"] : OctokitTypes.RequestParameters): Promise<T[]>; | ||
/** | ||
* Paginate a request using an endpoint route string and parameters | ||
* Paginate a request using an endpoint method and a map function | ||
* | ||
* @param {string} request Request method (`octokit.request` or `@octokit/request`) | ||
* @param {object} parameters URL, query or body parameters, as well as `headers`, `mediaType.{format|previews}`, `request`, or `baseUrl`. | ||
* @param {function} mapFn Optional method to map each response to a custom array | ||
* @param {function} mapFn? Optional method to map each response to a custom array | ||
*/ | ||
<T, R>(request: OctokitTypes.RequestInterface, parameters: OctokitTypes.RequestParameters, mapFn: MapFunction<T>): Promise<PaginationResults<R>>; | ||
<R extends OctokitTypes.RequestInterface, MR extends unknown[]>(request: R, mapFn: (response: NormalizeResponse<OctokitTypes.GetResponseTypeFromEndpointMethod<R>>, done: () => void) => MR): Promise<MR>; | ||
/** | ||
* Paginate a request using an endpoint route string and parameters | ||
* Paginate a request using an endpoint method, parameters, and a map function | ||
* | ||
* @param {string} request Request method (`octokit.request` or `@octokit/request`) | ||
* @param {object} parameters URL, query or body parameters, as well as `headers`, `mediaType.{format|previews}`, `request`, or `baseUrl`. | ||
* @param {function} mapFn? Optional method to map each response to a custom array | ||
*/ | ||
<T>(request: OctokitTypes.RequestInterface, parameters: OctokitTypes.RequestParameters): Promise<PaginationResults<T>>; | ||
<R extends OctokitTypes.RequestInterface, MR extends unknown[]>(request: R, parameters: Parameters<R>[0], mapFn: (response: NormalizeResponse<OctokitTypes.GetResponseTypeFromEndpointMethod<R>>, done?: () => void) => MR): Promise<MR>; | ||
/** | ||
* Paginate a request using an endpoint function | ||
* Paginate a request using an endpoint method and parameters | ||
* | ||
* @param {function} request `octokit.endpoint` or `@octokit/endpoint` compatible method | ||
* @param {string} request Request method (`octokit.request` or `@octokit/request`) | ||
* @param {object} parameters? URL, query or body parameters, as well as `headers`, `mediaType.{format|previews}`, `request`, or `baseUrl`. | ||
*/ | ||
<T>(request: OctokitTypes.RequestInterface): Promise<PaginationResults<T>>; | ||
<R extends OctokitTypes.RequestInterface>(request: R, parameters?: Parameters<R>[0]): Promise<NormalizeResponse<OctokitTypes.GetResponseTypeFromEndpointMethod<R>>["data"]>; | ||
iterator: { | ||
@@ -78,3 +102,3 @@ /** | ||
/** | ||
* Get an async iterator to paginate a request using an endpoint route string and optional parameters | ||
* Get an async iterator to paginate a request using a known endpoint route string and optional parameters | ||
* | ||
@@ -85,4 +109,12 @@ * @see {link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of} for await...of | ||
*/ | ||
<T>(route: OctokitTypes.Route, parameters?: OctokitTypes.RequestParameters): AsyncIterableIterator<OctokitTypes.OctokitResponse<PaginationResults<T>>>; | ||
<R extends keyof PaginatingEndpoints>(route: R, parameters?: PaginatingEndpoints[R]["parameters"]): AsyncIterableIterator<OctokitTypes.OctokitResponse<PaginatingEndpoints[R]["response"]["data"]>>; | ||
/** | ||
* Get an async iterator to paginate a request using an unknown endpoint route string and optional parameters | ||
* | ||
* @see {link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of} for await...of | ||
* @param {string} route Request method + URL. Example: `'GET /orgs/:org'` | ||
* @param {object} [parameters] URL, query or body parameters, as well as `headers`, `mediaType.{format|previews}`, `request`, or `baseUrl`. | ||
*/ | ||
<T, R extends OctokitTypes.Route = OctokitTypes.Route>(route: R, parameters?: R extends keyof PaginatingEndpoints ? PaginatingEndpoints[R]["parameters"] : OctokitTypes.RequestParameters): AsyncIterableIterator<OctokitTypes.OctokitResponse<PaginationResults<T>>>; | ||
/** | ||
* Get an async iterator to paginate a request using a request method and optional parameters | ||
@@ -94,8 +126,4 @@ * | ||
*/ | ||
<T>(request: OctokitTypes.RequestInterface, parameters?: OctokitTypes.RequestParameters): AsyncIterableIterator<OctokitTypes.OctokitResponse<PaginationResults<T>>>; | ||
<R extends OctokitTypes.RequestInterface>(request: R, parameters?: Parameters<R>[0]): AsyncIterableIterator<NormalizeResponse<OctokitTypes.GetResponseTypeFromEndpointMethod<R>>>; | ||
}; | ||
} | ||
export interface MapFunction<T = any, R = any> { | ||
(response: OctokitTypes.OctokitResponse<PaginationResults<T>>, done: () => void): R[]; | ||
} | ||
export declare type PaginationResults<T = any> = T[]; |
@@ -1,1 +0,1 @@ | ||
export declare const VERSION = "2.1.0"; | ||
export declare const VERSION = "2.2.0"; |
@@ -1,2 +0,2 @@ | ||
const VERSION = "2.1.0"; | ||
const VERSION = "2.2.0"; | ||
@@ -3,0 +3,0 @@ /** |
{ | ||
"name": "@octokit/plugin-paginate-rest", | ||
"description": "Octokit plugin to paginate REST API endpoint responses", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"license": "MIT", | ||
@@ -20,6 +20,7 @@ "files": [ | ||
"dependencies": { | ||
"@octokit/types": "^2.9.0" | ||
"@octokit/types": "^2.12.1" | ||
}, | ||
"devDependencies": { | ||
"@octokit/core": "^2.0.0", | ||
"@octokit/plugin-rest-endpoint-methods": "^3.7.1", | ||
"@pika/pack": "^0.5.0", | ||
@@ -26,0 +27,0 @@ "@pika/plugin-build-node": "^0.9.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
102190
21
1621
16
1
Updated@octokit/types@^2.12.1