Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
oscard0m committed Feb 22, 2022
1 parent e797c02 commit c567474
Show file tree
Hide file tree
Showing 2 changed files with 27 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 { OctokitThrottlingOptions } 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: OctokitThrottlingOptions
) {
const {
enabled = true,
Bottleneck = BottleneckLight,
Expand Down
22 changes: 22 additions & 0 deletions 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;

0 comments on commit c567474

Please sign in to comment.