Skip to content

Commit 32b598d

Browse files
wolfy1339gr2m
andauthoredMay 22, 2023
feat: v6 (#592)
BREAKING CHANGE: Drop support for NodeJS v14, v16 BREAKING CHANGE: remove deprecated `options.throttle.minimalSecondaryRateRetryAfter` BREAKING CHANGE: remove deprecated `options.throttle.onAbuseLimit` Co-authored-by: Gregor Martynus <39992+gr2m@users.noreply.github.com>
1 parent 5335870 commit 32b598d

8 files changed

+47
-187
lines changed
 

‎.github/workflows/test.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ jobs:
1313
strategy:
1414
matrix:
1515
node_version:
16-
- 14
17-
- 16
1816
- 18
17+
- 20
1918
steps:
2019
- uses: actions/checkout@v3
2120
- name: Test with Node.js ${{ matrix.node_version }}

‎package-lock.json

+38-38
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
[
6565
"@pika/plugin-build-node",
6666
{
67-
"minNodeVersion": "14"
67+
"minNodeVersion": 18
6868
}
6969
],
7070
[
@@ -105,6 +105,6 @@
105105
]
106106
},
107107
"engines": {
108-
"node": ">= 14"
108+
"node": ">= 18"
109109
}
110110
}

‎src/index.ts

-23
Original file line numberDiff line numberDiff line change
@@ -59,29 +59,6 @@ export function throttling(octokit: Octokit, octokitOptions: OctokitOptions) {
5959
createGroups(Bottleneck, common);
6060
}
6161

62-
if (
63-
octokitOptions.throttle &&
64-
octokitOptions.throttle.minimalSecondaryRateRetryAfter
65-
) {
66-
octokit.log.warn(
67-
"[@octokit/plugin-throttling] `options.throttle.minimalSecondaryRateRetryAfter` is deprecated, please use `options.throttle.fallbackSecondaryRateRetryAfter` instead"
68-
);
69-
octokitOptions.throttle.fallbackSecondaryRateRetryAfter =
70-
octokitOptions.throttle.minimalSecondaryRateRetryAfter;
71-
delete octokitOptions.throttle.minimalSecondaryRateRetryAfter;
72-
}
73-
74-
if (octokitOptions.throttle && octokitOptions.throttle.onAbuseLimit) {
75-
octokit.log.warn(
76-
"[@octokit/plugin-throttling] `onAbuseLimit()` is deprecated and will be removed in a future release of `@octokit/plugin-throttling`, please use the `onSecondaryRateLimit` handler instead"
77-
);
78-
// @ts-ignore types don't allow for both properties to be set
79-
octokitOptions.throttle.onSecondaryRateLimit =
80-
octokitOptions.throttle.onAbuseLimit;
81-
// @ts-ignore
82-
delete octokitOptions.throttle.onAbuseLimit;
83-
}
84-
8562
const state = Object.assign(
8663
{
8764
clustering: connection != null,

‎src/types.ts

+4-16
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,7 @@ type LimitHandler = (
88
retryCount: number
99
) => void;
1010

11-
export type AbuseLimitHandler = {
12-
/**
13-
* @deprecated "[@octokit/plugin-throttling] `onAbuseLimit()` is deprecated and will be removed in a future release of `@octokit/plugin-throttling`, please use the `onSecondaryRateLimit` handler instead"
14-
*/
15-
onAbuseLimit: LimitHandler;
16-
onSecondaryRateLimit?: never;
17-
};
18-
1911
export type SecondaryLimitHandler = {
20-
/**
21-
* @deprecated "[@octokit/plugin-throttling] `onAbuseLimit()` is deprecated and will be removed in a future release of `@octokit/plugin-throttling`, please use the `onSecondaryRateLimit` handler instead"
22-
*/
23-
onAbuseLimit?: never;
2412
onSecondaryRateLimit: LimitHandler;
2513
};
2614

@@ -43,10 +31,10 @@ export type ThrottlingOptionsBase = {
4331
};
4432

4533
export type ThrottlingOptions =
46-
| (ThrottlingOptionsBase & (AbuseLimitHandler | SecondaryLimitHandler))
47-
| (Partial<
48-
ThrottlingOptionsBase & (AbuseLimitHandler | SecondaryLimitHandler)
49-
> & { enabled: false });
34+
| (ThrottlingOptionsBase & SecondaryLimitHandler)
35+
| (Partial<ThrottlingOptionsBase & SecondaryLimitHandler> & {
36+
enabled: false;
37+
});
5038

5139
export type Groups = {
5240
global?: Bottleneck.Group;

‎test/deprecations.test.ts

+2-40
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,6 @@ import { throttling } from "../src";
33

44
const TestOctokit = Octokit.plugin(throttling);
55

6-
describe("deprecations", () => {
7-
it("throttle.minimalSecondaryRateRetryAfter option", () => {
8-
const log = {
9-
warn: jest.fn(),
10-
};
11-
new TestOctokit({
12-
// @ts-expect-error
13-
log,
14-
throttle: {
15-
minimalSecondaryRateRetryAfter: 1,
16-
onSecondaryRateLimit: () => 1,
17-
onRateLimit: () => 1,
18-
},
19-
});
20-
21-
expect(log.warn).toHaveBeenCalledWith(
22-
"[@octokit/plugin-throttling] `options.throttle.minimalSecondaryRateRetryAfter` is deprecated, please use `options.throttle.fallbackSecondaryRateRetryAfter` instead"
23-
);
24-
});
25-
26-
describe("throttle.onAbuseLimit", function () {
27-
it("Should detect SecondaryRate limit and broadcast event", async function () {
28-
const log = {
29-
warn: jest.fn(),
30-
};
31-
32-
new TestOctokit({
33-
// @ts-expect-error
34-
log,
35-
throttle: {
36-
onAbuseLimit: () => 1,
37-
onRateLimit: () => 1,
38-
},
39-
});
40-
41-
expect(log.warn).toHaveBeenCalledWith(
42-
"[@octokit/plugin-throttling] `onAbuseLimit()` is deprecated and will be removed in a future release of `@octokit/plugin-throttling`, please use the `onSecondaryRateLimit` handler instead"
43-
);
44-
});
45-
});
6+
describe.skip("deprecations", () => {
7+
it("No deprecations", () => {});
468
});

‎test/events.test.ts

-47
Original file line numberDiff line numberDiff line change
@@ -121,53 +121,6 @@ describe("Events", function () {
121121
expect(error.status).toEqual(403);
122122
}
123123

124-
expect(eventCount).toEqual(1);
125-
});
126-
});
127-
describe("with 'onSecondaryRateLimit'", function () {
128-
it("Should detect SecondaryRate limit and broadcast event", async function () {
129-
let eventCount = 0;
130-
131-
const octokit = new TestOctokit({
132-
throttle: {
133-
onSecondaryRateLimit: (retryAfter, options, octokitFromOptions) => {
134-
expect(octokit).toBe(octokitFromOptions);
135-
expect(retryAfter).toEqual(60);
136-
expect(options).toMatchObject({
137-
method: "GET",
138-
url: "/route2",
139-
request: { retryCount: 0 },
140-
});
141-
eventCount++;
142-
},
143-
onRateLimit: () => 1,
144-
},
145-
});
146-
147-
await octokit.request("GET /route1", {
148-
request: {
149-
responses: [{ status: 201, headers: {}, data: {} }],
150-
},
151-
});
152-
try {
153-
await octokit.request("GET /route2", {
154-
request: {
155-
responses: [
156-
{
157-
status: 403,
158-
headers: { "retry-after": "60" },
159-
data: {
160-
message: "You have exceeded a secondary rate limit",
161-
},
162-
},
163-
],
164-
},
165-
});
166-
throw new Error("Should not reach this point");
167-
} catch (error: any) {
168-
expect(error.status).toEqual(403);
169-
}
170-
171124
expect(eventCount).toEqual(1);
172125
});
173126
});

‎test/typescript-validate.ts

-19
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@ import { throttling } from "../src/index";
66

77
const octokit = new Octokit();
88

9-
// will be deprecated soon
10-
// onAbuseLimit()
11-
throttling(octokit, {
12-
throttle: { enabled: true, onRateLimit: () => {}, onAbuseLimit: () => {} },
13-
});
14-
159
// onSecondaryLimit()
1610
throttling(octokit, {
1711
throttle: {
@@ -21,22 +15,10 @@ throttling(octokit, {
2115
},
2216
});
2317

24-
// onSecondaryLimit() and onAbuseLimit() should be a TS Error
25-
throttling(octokit, {
26-
// @ts-expect-error
27-
throttle: {
28-
enabled: true,
29-
onRateLimit: () => {},
30-
onSecondaryRateLimit: () => {},
31-
onAbuseLimit: () => {},
32-
},
33-
});
34-
3518
// onRateLimit() missing should be a TS Error
3619
throttling(octokit, {
3720
// @ts-expect-error
3821
throttle: {
39-
enabled: true,
4022
onSecondaryRateLimit: () => {},
4123
},
4224
});
@@ -45,7 +27,6 @@ throttling(octokit, {
4527
throttling(octokit, {
4628
// @ts-expect-error
4729
throttle: {
48-
enabled: true,
4930
onRateLimit: () => {},
5031
},
5132
});

0 commit comments

Comments
 (0)
Please sign in to comment.