@upstash/ratelimit 2.0.2 → 2.0.4

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,10 +1,10 @@
1
1
  import { Aggregate } from '@upstash/core-analytics';
2
- import { Pipeline } from '@upstash/redis';
2
+ import { Redis as Redis$1 } 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.
6
6
  */
7
- interface EphemeralCache {
7
+ type EphemeralCache = {
8
8
  isBlocked: (identifier: string) => {
9
9
  blocked: boolean;
10
10
  reset: number;
@@ -16,16 +16,10 @@ interface EphemeralCache {
16
16
  pop: (key: string) => void;
17
17
  empty: () => void;
18
18
  size: () => number;
19
- }
19
+ };
20
20
  type RegionContext = {
21
21
  redis: Redis;
22
22
  cache?: EphemeralCache;
23
- scriptHashes: {
24
- limitHash?: string;
25
- getRemainingHash?: string;
26
- resetHash?: string;
27
- };
28
- cacheScripts: boolean;
29
23
  };
30
24
  type MultiRegionContext = {
31
25
  regionContexts: Omit<RegionContext[], "cache">;
@@ -96,7 +90,6 @@ type Algorithm<TContext> = () => {
96
90
  }>;
97
91
  resetTokens: (ctx: TContext, identifier: string) => Promise<void>;
98
92
  };
99
- type IsDenied = 0 | 1;
100
93
  type DeniedValue = string | undefined;
101
94
  type LimitOptions = {
102
95
  geo?: Geo;
@@ -108,17 +101,15 @@ type LimitOptions = {
108
101
  /**
109
102
  * This is all we need from the redis sdk.
110
103
  */
111
- interface Redis {
112
- sadd: <TData>(key: string, ...members: TData[]) => Promise<number>;
113
- hset: <TValue>(key: string, obj: {
114
- [key: string]: TValue;
115
- }) => Promise<number>;
116
- eval: <TArgs extends unknown[], TData = unknown>(...args: [script: string, keys: string[], args: TArgs]) => Promise<TData>;
117
- evalsha: <TArgs extends unknown[], TData = unknown>(...args: [sha1: string, keys: string[], args: TArgs]) => Promise<TData>;
118
- scriptLoad: (...args: [script: string]) => Promise<string>;
119
- smismember: (key: string, members: string[]) => Promise<IsDenied[]>;
120
- multi: () => Pipeline;
121
- }
104
+ type Redis = {
105
+ sadd: Redis$1["sadd"];
106
+ hset: Redis$1["hset"];
107
+ eval: Redis$1["eval"];
108
+ evalsha: Redis$1["evalsha"];
109
+ scriptLoad: Redis$1["scriptLoad"];
110
+ smismember: Redis$1["smismember"];
111
+ multi: Redis$1["multi"];
112
+ };
122
113
 
123
114
  type Geo = {
124
115
  country?: string;
@@ -570,8 +561,12 @@ type RegionRatelimitConfig = {
570
561
  */
571
562
  analytics?: boolean;
572
563
  /**
573
- * If enabled, lua scripts will be sent to Redis with SCRIPT LOAD durint the first request.
574
- * In the subsequent requests, hash of the script will be used to invoke it
564
+ * @deprecated Has no affect since v2.0.3. Instead, hash values of scripts are
565
+ * hardcoded in the sdk and it attempts to run the script using EVALSHA (with the hash).
566
+ * If it fails, runs script load.
567
+ *
568
+ * Previously, if enabled, lua scripts were sent to Redis with SCRIPT LOAD durint the first request.
569
+ * In the subsequent requests, hash of the script would be used to invoke the scripts
575
570
  *
576
571
  * @default true
577
572
  */
package/dist/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import { Aggregate } from '@upstash/core-analytics';
2
- import { Pipeline } from '@upstash/redis';
2
+ import { Redis as Redis$1 } 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.
6
6
  */
7
- interface EphemeralCache {
7
+ type EphemeralCache = {
8
8
  isBlocked: (identifier: string) => {
9
9
  blocked: boolean;
10
10
  reset: number;
@@ -16,16 +16,10 @@ interface EphemeralCache {
16
16
  pop: (key: string) => void;
17
17
  empty: () => void;
18
18
  size: () => number;
19
- }
19
+ };
20
20
  type RegionContext = {
21
21
  redis: Redis;
22
22
  cache?: EphemeralCache;
23
- scriptHashes: {
24
- limitHash?: string;
25
- getRemainingHash?: string;
26
- resetHash?: string;
27
- };
28
- cacheScripts: boolean;
29
23
  };
30
24
  type MultiRegionContext = {
31
25
  regionContexts: Omit<RegionContext[], "cache">;
@@ -96,7 +90,6 @@ type Algorithm<TContext> = () => {
96
90
  }>;
97
91
  resetTokens: (ctx: TContext, identifier: string) => Promise<void>;
98
92
  };
99
- type IsDenied = 0 | 1;
100
93
  type DeniedValue = string | undefined;
101
94
  type LimitOptions = {
102
95
  geo?: Geo;
@@ -108,17 +101,15 @@ type LimitOptions = {
108
101
  /**
109
102
  * This is all we need from the redis sdk.
110
103
  */
111
- interface Redis {
112
- sadd: <TData>(key: string, ...members: TData[]) => Promise<number>;
113
- hset: <TValue>(key: string, obj: {
114
- [key: string]: TValue;
115
- }) => Promise<number>;
116
- eval: <TArgs extends unknown[], TData = unknown>(...args: [script: string, keys: string[], args: TArgs]) => Promise<TData>;
117
- evalsha: <TArgs extends unknown[], TData = unknown>(...args: [sha1: string, keys: string[], args: TArgs]) => Promise<TData>;
118
- scriptLoad: (...args: [script: string]) => Promise<string>;
119
- smismember: (key: string, members: string[]) => Promise<IsDenied[]>;
120
- multi: () => Pipeline;
121
- }
104
+ type Redis = {
105
+ sadd: Redis$1["sadd"];
106
+ hset: Redis$1["hset"];
107
+ eval: Redis$1["eval"];
108
+ evalsha: Redis$1["evalsha"];
109
+ scriptLoad: Redis$1["scriptLoad"];
110
+ smismember: Redis$1["smismember"];
111
+ multi: Redis$1["multi"];
112
+ };
122
113
 
123
114
  type Geo = {
124
115
  country?: string;
@@ -570,8 +561,12 @@ type RegionRatelimitConfig = {
570
561
  */
571
562
  analytics?: boolean;
572
563
  /**
573
- * If enabled, lua scripts will be sent to Redis with SCRIPT LOAD durint the first request.
574
- * In the subsequent requests, hash of the script will be used to invoke it
564
+ * @deprecated Has no affect since v2.0.3. Instead, hash values of scripts are
565
+ * hardcoded in the sdk and it attempts to run the script using EVALSHA (with the hash).
566
+ * If it fails, runs script load.
567
+ *
568
+ * Previously, if enabled, lua scripts were sent to Redis with SCRIPT LOAD durint the first request.
569
+ * In the subsequent requests, hash of the script would be used to invoke the scripts
575
570
  *
576
571
  * @default true
577
572
  */