From b58f97534b8e7e9559b7c4b130f04cbe2d5f3988 Mon Sep 17 00:00:00 2001 From: ytkimirti Date: Mon, 28 Oct 2024 09:31:43 +0300 Subject: [PATCH 1/5] fix: use peer dep instead --- bun.lockb | Bin 118145 -> 118145 bytes package.json | 6 ++++-- src/types.ts | 16 +--------------- 3 files changed, 5 insertions(+), 17 deletions(-) diff --git a/bun.lockb b/bun.lockb index 665316b9619caf20cf53886744ce67bd21c18552..f3d3736342fbdb6dc94538cf8edae1e795ea34bb 100755 GIT binary patch delta 1518 zcmd6n?{AY;6vyxBTGnT?*sdd^&TbV(_M@)rXxFE*4$!KMG`cOz>?Ur>h?91fV4N@o z$6$dBg=K7q)5} zx#v75_x9eS6S+qxa!;S8f~m1mtNgS#lllNO>M}V+18|MF7({7s?I}o zt}5}g5Us1K73#69GM$Cm&QCb&wX5(#h@059L)Qv-39$uA)N+as?Nx^QeDe?MhHJt4!4x++Eyr)%jGert{sH>cjE7$nvhG+UxIP7Qw5C> zTX>|T-tbl@zup;OYoRe|-0jr{^RXFwNr*LIA7};-fd+5@R6j-K9?ob*wpb_~|P^~{hA`e(`1SM~E>;J2H2KHC<@U80+D(9UuQEr^E@P(NO zRq{=!WvI^C2)X(F*(kp^YhlY=gsQn?F3Rn57XA#XhPC-9o98XOcRoV3{0Y>@P|k%2 z`8d81<=BFSzk#Y_$6}P%FIsqDF|3ieeeZ4TkiZ{qM$bJDuxDq`!BG1<6mCLCU2 zviYVpL~+?&M@br&>jHF=4#>9yWT$@lQGojCn5@>Ro{r17PG79SR*T&vtAezF5~;Qz z<&#Mr!+5IaA^O`uhh$HPHku9~)GtRuRIClbJq9~0r$SU@QD^%UEC?HxKZdB4^i*X7 z4VxN1#|Z`ycEi4gUkAPm`oT(=4|Wc^9Q**Rx+7j8Z#+WwO*IHr!&HlG`klW3>2vUNlD+v>>ZesXX01_xxN&o-= delta 1489 zcmb`HT})eL7{}kI(9w5zkOB%FHq=1E7*Z$&P94R~R5zDKDOs>%8%v7Twb02TETGwf zWZA^IDddTH6%s#!E^1=p)@Y~Gq1lCBlSHG&t$b>{(L1jgiPQgCPjTvv7bboBJOAgq zr{}z*Q+cCPdE?{McxIwPdK!fg1wuSo1iHXLmk-!1l!fh; zKARcJ;jaU_T)#I{mdo}EU2cPFLShbgRO|8yGnU5_PF=nS_1D7r*smR#ne}%=tt};A zhBAf|dw%jJb9)-(?S$L<5We!kN5OUAAZP;*gBI@YD}4Y$j6mUo>I_FgEA(;D0*;yf zr%j$P{U^a(#K%D+|9MKTMmGP)$sH*8A19+(^2ni$Q9iO1kR-0%d<{!g^NUx)d|z7Q z->(FzhIgdHyaM%hI!LvA73z&Sjl1W9RL5`5g?ZP!#@c+4>bYw^%(exMKZ5eGTnO_y zr~?Z@^78vou|oc`om%O*itBVyHTlRT`>_83SWl|cNBLwmZZfB$ zchVmgI;^68sN`K}r0P^n8$D$m$-$kP zf$0d{0s8{iE#T{5Gq?%X1bYQ~Bls3rdxO8mj2Zr4U=dgYd~TT0FPry*0}+hkg$dV0x6|A^1_ zA)eVhv$VsUVdkk&0tuPTZ=7z+{(#gs3F@#YPd`-@Y&~>vU@$TetA8x|aC{&Y>ZiG| b`uq~P)b~fJT+Mz)#i_eKrG6`avi!oI-LzZP 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/types.ts b/src/types.ts index 5a993c1..d980fb0 100644 --- a/src/types.ts +++ b/src/types.ts @@ -122,18 +122,4 @@ export type LimitOptions = { /** * 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 From 1274d3b11b7db718f31eda83896a030040855957 Mon Sep 17 00:00:00 2001 From: ytkimirti Date: Tue, 3 Dec 2024 10:41:50 +0300 Subject: [PATCH 2/5] chore: remove comment --- src/types.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/types.ts b/src/types.ts index d980fb0..aab9493 100644 --- a/src/types.ts +++ b/src/types.ts @@ -119,7 +119,4 @@ export type LimitOptions = { country?: string } -/** - * This is all we need from the redis sdk. - */ export type Redis = RedisCore From 2656d2991b7af04b9f39d6dd7689b793da66952b Mon Sep 17 00:00:00 2001 From: ytkimirti Date: Tue, 3 Dec 2024 10:45:25 +0300 Subject: [PATCH 3/5] chore: lint fix --- src/ratelimit.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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); } } From 344099fab54b6a4f75b772498b7eeae8df83edf2 Mon Sep 17 00:00:00 2001 From: ytkimirti Date: Tue, 3 Dec 2024 10:45:53 +0300 Subject: [PATCH 4/5] fix: remove multi field from config redis object to prevent conflicts --- src/single.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/single.ts b/src/single.ts index a9dd352..5edecfe 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 = Omit 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, From b8e310f30c233ebca137175a3816ebb69767f8a6 Mon Sep 17 00:00:00 2001 From: ytkimirti Date: Tue, 3 Dec 2024 11:19:57 +0300 Subject: [PATCH 5/5] fix: change omit to pick --- src/single.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/single.ts b/src/single.ts index 5edecfe..fcac2a5 100644 --- a/src/single.ts +++ b/src/single.ts @@ -9,7 +9,7 @@ import type { Algorithm, RegionContext } from "./types"; import type { Redis as RedisCore } from "./types"; // Fix for https://github.com/upstash/ratelimit-js/issues/125 -type Redis = Omit +type Redis = Pick export type RegionRatelimitConfig = { /**