From 942fb8d4eb8e5aba7ee8c6829881b0d27b71599a Mon Sep 17 00:00:00 2001 From: ytkimirti Date: Thu, 5 Dec 2024 16:00:23 +0300 Subject: [PATCH] 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 --- bun.lockb | Bin 118145 -> 118145 bytes package.json | 6 ++++-- src/ratelimit.ts | 2 +- src/single.ts | 7 +++++-- src/types.ts | 19 +------------------ 5 files changed, 11 insertions(+), 23 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/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