Skip to content

Commit b978900

Browse files
authored
Fixes plugin instances duplication (#52)
* fix: plugin deduplication * fix: rebase * refactor: reduce seed calculation complexity * feat: exit pre mode
1 parent 5a13f25 commit b978900

File tree

7 files changed

+43
-3
lines changed

7 files changed

+43
-3
lines changed

.changeset/cuddly-bees-change.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"elysia-rate-limit": patch
3+
---
4+
5+
seeding logic complexity reduction

.changeset/nice-pumas-sneeze.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"elysia-rate-limit": patch
3+
---
4+
5+
fix plugin duplication due to missing seed provided to Elysia instances

.changeset/pre.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"mode": "exit",
3+
"tag": "beta",
4+
"initialVersions": {
5+
"elysia-rate-limit": "4.2.0"
6+
},
7+
"changesets": [
8+
"cuddly-bees-change",
9+
"nice-pumas-sneeze"
10+
]
11+
}

.npmignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
.git
22
.gitignore
3-
.prettierrc
43
bun.lockb
54

65
node_modules

CHANGELOG.md

+18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# elysia-rate-limit
22

3+
## 4.2.1-beta.1
4+
5+
### Patch Changes
6+
7+
- seeding logic complexity reduction
8+
9+
## 4.2.1-beta.0
10+
11+
### Patch Changes
12+
13+
- fix plugin duplication due to missing seed provided to Elysia instances
14+
315
## 4.2.0
416

517
### Minor Changes
@@ -24,6 +36,12 @@
2436

2537
- change build pipeline to serve builds from both tsup, and tsc
2638

39+
## 4.1.1-beta.0
40+
41+
### Patch Changes
42+
43+
- fix plugin duplication due to missing seed provided to Elysia instances
44+
2745
## 4.1.0
2846

2947
### Minor Changes

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "elysia-rate-limit",
3-
"version": "4.2.0",
3+
"version": "4.2.1-beta.1",
44
"description": "Rate-limiter for Elysia.js",
55
"author": {
66
"name": "rayriffy",

src/services/plugin.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export const plugin = (userOptions?: Partial<Options>) => {
2222
return (app: Elysia) => {
2323
const plugin = new Elysia({
2424
name: 'elysia-rate-limit',
25+
seed: options.max,
2526
})
2627

2728
plugin.onBeforeHandle(
@@ -71,6 +72,7 @@ export const plugin = (userOptions?: Partial<Options>) => {
7172
)
7273

7374
const { count, nextReset } = await options.context.increment(
75+
// biome-ignore lint/style/noNonNullAssertion: <explanation>
7476
clientKey!
7577
)
7678

@@ -87,7 +89,7 @@ export const plugin = (userOptions?: Partial<Options>) => {
8789
Math.ceil((nextReset.getTime() - Date.now()) / 1000)
8890
)
8991

90-
let builtHeaders: Record<string, string> = {
92+
const builtHeaders: Record<string, string> = {
9193
'RateLimit-Limit': String(options.max),
9294
'RateLimit-Remaining': String(payload.remaining),
9395
'RateLimit-Reset': String(reset),

0 commit comments

Comments
 (0)