11import Redis from 'ioredis' ;
2- import { RateLimiter , RateLimiterResponse , RedisWindow } from '../@types/rateLimit' ;
2+ import { RateLimiter , RateLimiterResponse , FixedWindow as Window } from '../@types/rateLimit' ;
33
44/**
55 * The FixedWindow instance of a RateLimiter limits requests based on a unique user ID and a fixed time window.
@@ -69,7 +69,7 @@ class FixedWindow implements RateLimiter {
6969 const windowJSON = await this . client . get ( uuid ) ;
7070
7171 if ( windowJSON === null ) {
72- const newUserWindow : RedisWindow = {
72+ const newUserWindow : Window = {
7373 currentTokens : tokens > this . capacity ? 0 : tokens ,
7474 fixedWindowStart : timestamp ,
7575 } ;
@@ -81,7 +81,7 @@ class FixedWindow implements RateLimiter {
8181 await this . client . setex ( uuid , keyExpiry , JSON . stringify ( newUserWindow ) ) ;
8282 return { success : true , tokens : this . capacity - newUserWindow . currentTokens } ;
8383 }
84- const window : RedisWindow = await JSON . parse ( windowJSON ) ;
84+ const window : Window = await JSON . parse ( windowJSON ) ;
8585
8686 const updatedUserWindow = this . updateTimeWindow ( window , timestamp ) ;
8787 updatedUserWindow . currentTokens += tokens ;
@@ -113,8 +113,8 @@ class FixedWindow implements RateLimiter {
113113 this . client . flushall ( ) ;
114114 }
115115
116- private updateTimeWindow = ( window : RedisWindow , timestamp : number ) : RedisWindow => {
117- const updatedUserWindow : RedisWindow = {
116+ private updateTimeWindow = ( window : Window , timestamp : number ) : Window => {
117+ const updatedUserWindow : Window = {
118118 currentTokens : window . currentTokens ,
119119 fixedWindowStart : window . fixedWindowStart ,
120120 } ;
0 commit comments