Skip to content

Commit

Permalink
Use peer dependency for Redis and cast the object to prevent conflict (
Browse files Browse the repository at this point in the history
…#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
  • Loading branch information
ytkimirti authored Dec 5, 2024
1 parent f8529d2 commit 942fb8d
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 23 deletions.
Binary file modified bun.lockb
Binary file not shown.
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@
},
"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",
"tsup": "^7.2.0",
"turbo": "^1.10.15",
"typescript": "^5.0.0"
},
"peerDependencies": {
"@upstash/redis": "^1.34.3"
},
"license": "MIT",
"dependencies": {
"@upstash/core-analytics": "^0.0.10"
}
}
}
2 changes: 1 addition & 1 deletion src/ratelimit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,6 @@ export abstract class Ratelimit<TContext extends Context> {
req?: Pick<LimitOptions, "ip" | "userAgent" | "country">
): 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);
}
}
7 changes: 5 additions & 2 deletions src/single.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<RedisCore, "get" | "set">

export type RegionRatelimitConfig = {
/**
Expand Down Expand Up @@ -114,7 +117,7 @@ export class RegionRatelimit extends Ratelimit<RegionContext> {
timeout: config.timeout,
analytics: config.analytics,
ctx: {
redis: config.redis,
redis: config.redis as RedisCore,
},
ephemeralCache: config.ephemeralCache,
enableProtection: config.enableProtection,
Expand Down
19 changes: 1 addition & 18 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 942fb8d

Please sign in to comment.