rate-limiter-flexible 7.3.0 → 7.3.2
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/README.md +2 -7
- package/lib/RateLimiterDrizzle.js +12 -8
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -42,14 +42,9 @@ It uses a **fixed window**, as it is much faster than a rolling window.
|
|
|
42
42
|
## Import
|
|
43
43
|
|
|
44
44
|
```javascript
|
|
45
|
-
// CommonJS
|
|
46
|
-
const { RateLimiterMemory } = require("rate-limiter-flexible");
|
|
47
|
-
|
|
48
|
-
// or
|
|
49
|
-
|
|
50
|
-
// ECMAScript
|
|
51
45
|
import { RateLimiterMemory } from "rate-limiter-flexible";
|
|
52
|
-
|
|
46
|
+
|
|
47
|
+
// or import directly
|
|
53
48
|
import RateLimiterMemory from "rate-limiter-flexible/lib/RateLimiterMemory.js";
|
|
54
49
|
```
|
|
55
50
|
|
|
@@ -9,12 +9,17 @@ class RateLimiterDrizzleError extends Error {
|
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
function getDrizzleOperators() {
|
|
12
|
+
async function getDrizzleOperators() {
|
|
13
13
|
if (drizzleOperators) return drizzleOperators;
|
|
14
14
|
|
|
15
15
|
try {
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
// Use dynamic import to prevent static analysis tools from detecting the import
|
|
17
|
+
function getPackageName() {
|
|
18
|
+
return ['drizzle', 'orm'].join('-');
|
|
19
|
+
}
|
|
20
|
+
const drizzleOrm = await import(`${getPackageName()}`);
|
|
21
|
+
const { and, or, gt, lt, eq, isNull, sql } = drizzleOrm.default || drizzleOrm;
|
|
22
|
+
drizzleOperators = { and, or, gt, lt, eq, isNull, sql };
|
|
18
23
|
return drizzleOperators;
|
|
19
24
|
} catch (error) {
|
|
20
25
|
throw new RateLimiterDrizzleError(
|
|
@@ -66,7 +71,7 @@ class RateLimiterDrizzle extends RateLimiterStoreAbstract {
|
|
|
66
71
|
return Promise.reject(new RateLimiterDrizzleError('Drizzle client is not established'))
|
|
67
72
|
}
|
|
68
73
|
|
|
69
|
-
const { eq
|
|
74
|
+
const { eq, sql } = await getDrizzleOperators();
|
|
70
75
|
const now = new Date();
|
|
71
76
|
const newExpire = msDuration > 0 ? new Date(now.getTime() + msDuration) : null;
|
|
72
77
|
|
|
@@ -112,7 +117,7 @@ class RateLimiterDrizzle extends RateLimiterStoreAbstract {
|
|
|
112
117
|
return Promise.reject(new RateLimiterDrizzleError('Drizzle client is not established'))
|
|
113
118
|
}
|
|
114
119
|
|
|
115
|
-
const { and, or, gt, eq, isNull } = getDrizzleOperators();
|
|
120
|
+
const { and, or, gt, eq, isNull } = await getDrizzleOperators();
|
|
116
121
|
|
|
117
122
|
const [response] = await this.drizzleClient
|
|
118
123
|
.select()
|
|
@@ -134,7 +139,7 @@ class RateLimiterDrizzle extends RateLimiterStoreAbstract {
|
|
|
134
139
|
return Promise.reject(new RateLimiterDrizzleError('Drizzle client is not established'))
|
|
135
140
|
}
|
|
136
141
|
|
|
137
|
-
const { eq } = getDrizzleOperators();
|
|
142
|
+
const { eq } = await getDrizzleOperators();
|
|
138
143
|
|
|
139
144
|
const [result] = await this.drizzleClient
|
|
140
145
|
.delete(this.schema)
|
|
@@ -149,10 +154,9 @@ class RateLimiterDrizzle extends RateLimiterStoreAbstract {
|
|
|
149
154
|
clearTimeout(this._clearExpiredTimeoutId);
|
|
150
155
|
}
|
|
151
156
|
|
|
152
|
-
const { lt } = getDrizzleOperators();
|
|
153
|
-
|
|
154
157
|
this._clearExpiredTimeoutId = setTimeout(async () => {
|
|
155
158
|
try {
|
|
159
|
+
const { lt } = await getDrizzleOperators();
|
|
156
160
|
await this.drizzleClient
|
|
157
161
|
.delete(this.schema)
|
|
158
162
|
.where(lt(this.schema.expire, new Date(Date.now() - EXPIRED_THRESHOLD_MS)));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rate-limiter-flexible",
|
|
3
|
-
"version": "7.3.
|
|
3
|
+
"version": "7.3.2",
|
|
4
4
|
"description": "Node.js rate limiter by key and protection from DDoS and Brute-Force attacks in process Memory, Redis, MongoDb, Memcached, MySQL, PostgreSQL, Cluster or PM",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"test:valkey-cluster": "VALKEY_CLUSTER_PORT=7001 mocha test/RateLimiterValkeyGlide.test.js -- -g 'RateLimiterValkeyGlide with cluster client'",
|
|
12
12
|
"prisma:postgres": "prisma generate --schema=./test/RateLimiterPrisma/Postgres/schema.prisma && prisma db push --schema=./test/RateLimiterPrisma/Postgres/schema.prisma",
|
|
13
13
|
"drizzle:postgres": "cd ./test/RateLimiterDrizzle/Postgres && drizzle-kit push",
|
|
14
|
-
"test": "npm run prisma:postgres && npm run drizzle:postgres && nyc --reporter=html --reporter=text mocha",
|
|
14
|
+
"test": "npm run prisma:postgres && npm run drizzle:postgres && nyc --reporter=html --reporter=text mocha \"test/**/*.test.js\"",
|
|
15
15
|
"debug-test": "mocha --inspect-brk lib/**/**.test.js",
|
|
16
16
|
"coveralls": "cat ./coverage/lcov.info | coveralls",
|
|
17
17
|
"eslint": "eslint --quiet lib/**/**.js test/**/**.js",
|