Skip to content

Commit

Permalink
feat(types): improve types for ThrottlingOptions to make it more accu…
Browse files Browse the repository at this point in the history
…rate
  • Loading branch information
oscard0m committed Mar 3, 2022
1 parent e797c02 commit c169183
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
7 changes: 5 additions & 2 deletions 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";
Expand Down Expand Up @@ -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,
Expand Down
26 changes: 26 additions & 0 deletions 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;
};
}

0 comments on commit c169183

Please sign in to comment.