Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use peer dependency for Redis and cast the object to prevent conflict #129

Merged
merged 5 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading