From c1691833019ffe63a3e804825867e0703ec9a845 Mon Sep 17 00:00:00 2001 From: Oscar Dominguez Date: Fri, 18 Feb 2022 12:31:35 +0100 Subject: [PATCH] feat(types): improve types for ThrottlingOptions to make it more accurate --- src/index.ts | 7 +++++-- src/types.ts | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 src/types.ts diff --git a/src/index.ts b/src/index.ts index bd4bbfb8..a66b89c9 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 { ThrottlingOptions } 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: ThrottlingOptions +) { const { enabled = true, Bottleneck = BottleneckLight, diff --git a/src/types.ts b/src/types.ts new file mode 100644 index 00000000..1062607d --- /dev/null +++ b/src/types.ts @@ -0,0 +1,26 @@ +import { OctokitOptions } from "@octokit/core/dist-types/types.d"; +import { Octokit } from "@octokit/core"; + +declare module "@octokit/core" { + interface OctokitOptions { + throttle?: ThrottlingOptions; + } +} + +type LimitHandler = ( + retryAfter: number, + options: ThrottlingOptions, + octokit: Octokit +) => void; + +export interface ThrottlingOptions extends OctokitOptions { + throttle: { + enabled?: boolean; + Bottleneck?: any; + id?: string; + timeout?: number; + connection?: any; + onAbuseLimit: LimitHandler; + onRateLimit: LimitHandler; + }; +}