diff --git a/src/index.ts b/src/index.ts index bd4bbfb8..d3466127 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,7 @@ // @ts-ignore import BottleneckLight from "bottleneck/light"; import { Octokit } from "@octokit/core"; - +import { OctokitThrottlingOptions } from "./types"; import { VERSION } from "./version"; import { wrapRequest } from "./wrap-request"; @@ -45,7 +45,10 @@ const createGroups = function (Bottleneck, common) { }); }; -export function throttling(octokit: Octokit, octokitOptions = {}) { +export function throttling( + octokit: Octokit, + octokitOptions: OctokitThrottlingOptions +) { const { enabled = true, Bottleneck = BottleneckLight, diff --git a/src/types.ts b/src/types.ts new file mode 100644 index 00000000..f39c79c7 --- /dev/null +++ b/src/types.ts @@ -0,0 +1,22 @@ +import { OctokitOptions } from "@octokit/core/dist-types/types.d"; +import { Octokit } from "@octokit/core"; + +type LimitHandler = ( + retryAfter: number, + options: OctokitThrottlingOptions, + octokit: Octokit +) => void; + +export interface ThrottlingOptions extends OctokitOptions { + throttle: { + enabled?: boolean; + Bottleneck?: any; + id?: string; + timeout?: number; + connection?: any; + onAbuseLimit: LimitHandler; + onRateLimit: LimitHandler; + }; +} + +export type OctokitThrottlingOptions = OctokitOptions | ThrottlingOptions;