Skip to content

Commit 942fb8d

Browse files
authored
Use peer dependency for Redis and cast the object to prevent conflict (#129)
* fix: use peer dep instead * chore: remove comment * chore: lint fix * fix: remove multi field from config redis object to prevent conflicts * fix: change omit to pick
1 parent f8529d2 commit 942fb8d

File tree

5 files changed

+11
-23
lines changed

5 files changed

+11
-23
lines changed

bun.lockb

0 Bytes
Binary file not shown.

package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,18 @@
1414
},
1515
"devDependencies": {
1616
"@typescript-eslint/eslint-plugin": "^8.4.0",
17-
"@upstash/redis": "^1.34.3",
1817
"bun-types": "latest",
1918
"eslint": "^9.10.0",
2019
"eslint-plugin-unicorn": "^55.0.0",
2120
"tsup": "^7.2.0",
2221
"turbo": "^1.10.15",
2322
"typescript": "^5.0.0"
2423
},
24+
"peerDependencies": {
25+
"@upstash/redis": "^1.34.3"
26+
},
2527
"license": "MIT",
2628
"dependencies": {
2729
"@upstash/core-analytics": "^0.0.10"
2830
}
29-
}
31+
}

src/ratelimit.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,6 @@ export abstract class Ratelimit<TContext extends Context> {
405405
req?: Pick<LimitOptions, "ip" | "userAgent" | "country">
406406
): string[] => {
407407
const members = [identifier, req?.ip, req?.userAgent, req?.country];
408-
return members.filter((item): item is string => Boolean(item));
408+
return (members as string[]).filter(Boolean);
409409
}
410410
}

src/single.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ import { tokenBucketIdentifierNotFound } from "./lua-scripts/single";
66

77
import { Ratelimit } from "./ratelimit";
88
import type { Algorithm, RegionContext } from "./types";
9-
import type { Redis } from "./types";
9+
import type { Redis as RedisCore } from "./types";
10+
11+
// Fix for https://github.com/upstash/ratelimit-js/issues/125
12+
type Redis = Pick<RedisCore, "get" | "set">
1013

1114
export type RegionRatelimitConfig = {
1215
/**
@@ -114,7 +117,7 @@ export class RegionRatelimit extends Ratelimit<RegionContext> {
114117
timeout: config.timeout,
115118
analytics: config.analytics,
116119
ctx: {
117-
redis: config.redis,
120+
redis: config.redis as RedisCore,
118121
},
119122
ephemeralCache: config.ephemeralCache,
120123
enableProtection: config.enableProtection,

src/types.ts

+1-18
Original file line numberDiff line numberDiff line change
@@ -119,21 +119,4 @@ export type LimitOptions = {
119119
country?: string
120120
}
121121

122-
/**
123-
* This is all we need from the redis sdk.
124-
*/
125-
export type Redis = {
126-
sadd: RedisCore["sadd"]
127-
128-
hset: RedisCore["hset"]
129-
130-
eval: RedisCore["eval"]
131-
132-
evalsha: RedisCore["evalsha"]
133-
134-
scriptLoad: RedisCore["scriptLoad"]
135-
136-
smismember: RedisCore["smismember"]
137-
138-
multi: RedisCore["multi"]
139-
}
122+
export type Redis = RedisCore

0 commit comments

Comments
 (0)