@upstash/ratelimit 0.0.0-ci.e36c7a4668d76e92b9a8650ce5d3967a8d0a7e36-20241006173732 → 0.0.0-ci.e51294002f34d535e9a8cb7fd64dd4940cd67362-20251031125635

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Aggregate } from '@upstash/core-analytics';
2
- import { Pipeline } from '@upstash/redis';
2
+ import { Redis as Redis$2 } from '@upstash/redis';
3
3
 
4
4
  /**
5
5
  * EphemeralCache is used to block certain identifiers right away in case they have already exceeded the ratelimit.
@@ -12,13 +12,13 @@ type EphemeralCache = {
12
12
  blockUntil: (identifier: string, reset: number) => void;
13
13
  set: (key: string, value: number) => void;
14
14
  get: (key: string) => number | null;
15
- incr: (key: string) => number;
15
+ incr: (key: string, incrementAmount?: number) => number;
16
16
  pop: (key: string) => void;
17
17
  empty: () => void;
18
18
  size: () => number;
19
19
  };
20
20
  type RegionContext = {
21
- redis: Redis;
21
+ redis: Redis$1;
22
22
  cache?: EphemeralCache;
23
23
  };
24
24
  type MultiRegionContext = {
@@ -90,7 +90,6 @@ type Algorithm<TContext> = () => {
90
90
  }>;
91
91
  resetTokens: (ctx: TContext, identifier: string) => Promise<void>;
92
92
  };
93
- type IsDenied = 0 | 1;
94
93
  type DeniedValue = string | undefined;
95
94
  type LimitOptions = {
96
95
  geo?: Geo;
@@ -99,20 +98,7 @@ type LimitOptions = {
99
98
  userAgent?: string;
100
99
  country?: string;
101
100
  };
102
- /**
103
- * This is all we need from the redis sdk.
104
- */
105
- type Redis = {
106
- sadd: <TData>(key: string, ...members: TData[]) => Promise<number>;
107
- hset: <TValue>(key: string, obj: {
108
- [key: string]: TValue;
109
- }) => Promise<number>;
110
- eval: <TArgs extends unknown[], TData = unknown>(...args: [script: string, keys: string[], args: TArgs]) => Promise<TData>;
111
- evalsha: <TArgs extends unknown[], TData = unknown>(...args: [sha1: string, keys: string[], args: TArgs]) => Promise<TData>;
112
- scriptLoad: (...args: [script: string]) => Promise<string>;
113
- smismember: (key: string, members: string[]) => Promise<IsDenied[]>;
114
- multi: () => Pipeline;
115
- };
101
+ type Redis$1 = Redis$2;
116
102
 
117
103
  type Geo = {
118
104
  country?: string;
@@ -132,7 +118,7 @@ type Event = Geo & {
132
118
  success: EventSuccess;
133
119
  };
134
120
  type AnalyticsConfig = {
135
- redis: Redis;
121
+ redis: Redis$1;
136
122
  prefix?: string;
137
123
  };
138
124
  /**
@@ -259,7 +245,7 @@ declare abstract class Ratelimit<TContext extends Context> {
259
245
  protected readonly ctx: TContext;
260
246
  protected readonly prefix: string;
261
247
  protected readonly timeout: number;
262
- protected readonly primaryRedis: Redis;
248
+ protected readonly primaryRedis: Redis$1;
263
249
  protected readonly analytics?: Analytics;
264
250
  protected readonly enableProtection: boolean;
265
251
  protected readonly denyListThreshold: number;
@@ -384,7 +370,7 @@ type MultiRegionRatelimitConfig = {
384
370
  * Instances of `@upstash/redis`
385
371
  * @see https://github.com/upstash/upstash-redis#quick-start
386
372
  */
387
- redis: Redis[];
373
+ redis: Redis$1[];
388
374
  /**
389
375
  * The ratelimiter function to use.
390
376
  *
@@ -511,6 +497,7 @@ declare class MultiRegionRatelimit extends Ratelimit<MultiRegionContext> {
511
497
  window: Duration): Algorithm<MultiRegionContext>;
512
498
  }
513
499
 
500
+ type Redis = Pick<Redis$1, "evalsha" | "get" | "set">;
514
501
  type RegionRatelimitConfig = {
515
502
  /**
516
503
  * Instance of `@upstash/redis`
@@ -743,7 +730,7 @@ declare class ThresholdError extends Error {
743
730
  * passed, ttl is infferred from current time.
744
731
  * @returns list of ips which are not in the deny list
745
732
  */
746
- declare const updateIpDenyList: (redis: Redis, prefix: string, threshold: number, ttl?: number) => Promise<unknown[]>;
733
+ declare const updateIpDenyList: (redis: Redis$1, prefix: string, threshold: number, ttl?: number) => Promise<unknown[]>;
747
734
  /**
748
735
  * Disables the ip deny list by removing the ip deny list from the all
749
736
  * set and removing the ip deny list. Also sets the status key to disabled
@@ -753,7 +740,7 @@ declare const updateIpDenyList: (redis: Redis, prefix: string, threshold: number
753
740
  * @param prefix ratelimit prefix
754
741
  * @returns
755
742
  */
756
- declare const disableIpDenyList: (redis: Redis, prefix: string) => Promise<unknown[]>;
743
+ declare const disableIpDenyList: (redis: Redis$1, prefix: string) => Promise<unknown[]>;
757
744
 
758
745
  type ipDenyList_ThresholdError = ThresholdError;
759
746
  declare const ipDenyList_ThresholdError: typeof ThresholdError;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Aggregate } from '@upstash/core-analytics';
2
- import { Pipeline } from '@upstash/redis';
2
+ import { Redis as Redis$2 } from '@upstash/redis';
3
3
 
4
4
  /**
5
5
  * EphemeralCache is used to block certain identifiers right away in case they have already exceeded the ratelimit.
@@ -12,13 +12,13 @@ type EphemeralCache = {
12
12
  blockUntil: (identifier: string, reset: number) => void;
13
13
  set: (key: string, value: number) => void;
14
14
  get: (key: string) => number | null;
15
- incr: (key: string) => number;
15
+ incr: (key: string, incrementAmount?: number) => number;
16
16
  pop: (key: string) => void;
17
17
  empty: () => void;
18
18
  size: () => number;
19
19
  };
20
20
  type RegionContext = {
21
- redis: Redis;
21
+ redis: Redis$1;
22
22
  cache?: EphemeralCache;
23
23
  };
24
24
  type MultiRegionContext = {
@@ -90,7 +90,6 @@ type Algorithm<TContext> = () => {
90
90
  }>;
91
91
  resetTokens: (ctx: TContext, identifier: string) => Promise<void>;
92
92
  };
93
- type IsDenied = 0 | 1;
94
93
  type DeniedValue = string | undefined;
95
94
  type LimitOptions = {
96
95
  geo?: Geo;
@@ -99,20 +98,7 @@ type LimitOptions = {
99
98
  userAgent?: string;
100
99
  country?: string;
101
100
  };
102
- /**
103
- * This is all we need from the redis sdk.
104
- */
105
- type Redis = {
106
- sadd: <TData>(key: string, ...members: TData[]) => Promise<number>;
107
- hset: <TValue>(key: string, obj: {
108
- [key: string]: TValue;
109
- }) => Promise<number>;
110
- eval: <TArgs extends unknown[], TData = unknown>(...args: [script: string, keys: string[], args: TArgs]) => Promise<TData>;
111
- evalsha: <TArgs extends unknown[], TData = unknown>(...args: [sha1: string, keys: string[], args: TArgs]) => Promise<TData>;
112
- scriptLoad: (...args: [script: string]) => Promise<string>;
113
- smismember: (key: string, members: string[]) => Promise<IsDenied[]>;
114
- multi: () => Pipeline;
115
- };
101
+ type Redis$1 = Redis$2;
116
102
 
117
103
  type Geo = {
118
104
  country?: string;
@@ -132,7 +118,7 @@ type Event = Geo & {
132
118
  success: EventSuccess;
133
119
  };
134
120
  type AnalyticsConfig = {
135
- redis: Redis;
121
+ redis: Redis$1;
136
122
  prefix?: string;
137
123
  };
138
124
  /**
@@ -259,7 +245,7 @@ declare abstract class Ratelimit<TContext extends Context> {
259
245
  protected readonly ctx: TContext;
260
246
  protected readonly prefix: string;
261
247
  protected readonly timeout: number;
262
- protected readonly primaryRedis: Redis;
248
+ protected readonly primaryRedis: Redis$1;
263
249
  protected readonly analytics?: Analytics;
264
250
  protected readonly enableProtection: boolean;
265
251
  protected readonly denyListThreshold: number;
@@ -384,7 +370,7 @@ type MultiRegionRatelimitConfig = {
384
370
  * Instances of `@upstash/redis`
385
371
  * @see https://github.com/upstash/upstash-redis#quick-start
386
372
  */
387
- redis: Redis[];
373
+ redis: Redis$1[];
388
374
  /**
389
375
  * The ratelimiter function to use.
390
376
  *
@@ -511,6 +497,7 @@ declare class MultiRegionRatelimit extends Ratelimit<MultiRegionContext> {
511
497
  window: Duration): Algorithm<MultiRegionContext>;
512
498
  }
513
499
 
500
+ type Redis = Pick<Redis$1, "evalsha" | "get" | "set">;
514
501
  type RegionRatelimitConfig = {
515
502
  /**
516
503
  * Instance of `@upstash/redis`
@@ -743,7 +730,7 @@ declare class ThresholdError extends Error {
743
730
  * passed, ttl is infferred from current time.
744
731
  * @returns list of ips which are not in the deny list
745
732
  */
746
- declare const updateIpDenyList: (redis: Redis, prefix: string, threshold: number, ttl?: number) => Promise<unknown[]>;
733
+ declare const updateIpDenyList: (redis: Redis$1, prefix: string, threshold: number, ttl?: number) => Promise<unknown[]>;
747
734
  /**
748
735
  * Disables the ip deny list by removing the ip deny list from the all
749
736
  * set and removing the ip deny list. Also sets the status key to disabled
@@ -753,7 +740,7 @@ declare const updateIpDenyList: (redis: Redis, prefix: string, threshold: number
753
740
  * @param prefix ratelimit prefix
754
741
  * @returns
755
742
  */
756
- declare const disableIpDenyList: (redis: Redis, prefix: string) => Promise<unknown[]>;
743
+ declare const disableIpDenyList: (redis: Redis$1, prefix: string) => Promise<unknown[]>;
757
744
 
758
745
  type ipDenyList_ThresholdError = ThresholdError;
759
746
  declare const ipDenyList_ThresholdError: typeof ThresholdError;