From 04e36482e2d1a9f620f5e1efbe18bf6a7b68d2a1 Mon Sep 17 00:00:00 2001 From: Oscar Dominguez Date: Fri, 18 Feb 2022 12:31:35 +0100 Subject: [PATCH] WIP --- src/index.ts | 7 +++++-- src/types.ts | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 src/types.ts 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..5406d39e --- /dev/null +++ b/src/types.ts @@ -0,0 +1,17 @@ +import { OctokitOptions } from "@octokit/core/dist-types/types.d"; + +type LimitHandler = (retryAfter: number, options: any, octokit: any) => 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;