diff --git a/bun.lockb b/bun.lockb index 665316b..f3d3736 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index b79c379..9bca80c 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,6 @@ }, "devDependencies": { "@typescript-eslint/eslint-plugin": "^8.4.0", - "@upstash/redis": "^1.34.3", "bun-types": "latest", "eslint": "^9.10.0", "eslint-plugin-unicorn": "^55.0.0", @@ -22,8 +21,11 @@ "turbo": "^1.10.15", "typescript": "^5.0.0" }, + "peerDependencies": { + "@upstash/redis": "^1.34.3" + }, "license": "MIT", "dependencies": { "@upstash/core-analytics": "^0.0.10" } -} +} \ No newline at end of file diff --git a/src/ratelimit.ts b/src/ratelimit.ts index 0c669cc..44884e5 100644 --- a/src/ratelimit.ts +++ b/src/ratelimit.ts @@ -405,6 +405,6 @@ export abstract class Ratelimit { req?: Pick ): string[] => { const members = [identifier, req?.ip, req?.userAgent, req?.country]; - return members.filter((item): item is string => Boolean(item)); + return (members as string[]).filter(Boolean); } } diff --git a/src/single.ts b/src/single.ts index a9dd352..fcac2a5 100644 --- a/src/single.ts +++ b/src/single.ts @@ -6,7 +6,10 @@ import { tokenBucketIdentifierNotFound } from "./lua-scripts/single"; import { Ratelimit } from "./ratelimit"; import type { Algorithm, RegionContext } from "./types"; -import type { Redis } from "./types"; +import type { Redis as RedisCore } from "./types"; + +// Fix for https://github.com/upstash/ratelimit-js/issues/125 +type Redis = Pick export type RegionRatelimitConfig = { /** @@ -114,7 +117,7 @@ export class RegionRatelimit extends Ratelimit { timeout: config.timeout, analytics: config.analytics, ctx: { - redis: config.redis, + redis: config.redis as RedisCore, }, ephemeralCache: config.ephemeralCache, enableProtection: config.enableProtection, diff --git a/src/types.ts b/src/types.ts index 5a993c1..aab9493 100644 --- a/src/types.ts +++ b/src/types.ts @@ -119,21 +119,4 @@ export type LimitOptions = { country?: string } -/** - * This is all we need from the redis sdk. - */ -export type Redis = { - sadd: RedisCore["sadd"] - - hset: RedisCore["hset"] - - eval: RedisCore["eval"] - - evalsha: RedisCore["evalsha"] - - scriptLoad: RedisCore["scriptLoad"] - - smismember: RedisCore["smismember"] - - multi: RedisCore["multi"] -} +export type Redis = RedisCore