@aomex/rate-limit-redis-store 3.30.6 → 3.30.8-alpha.62.sha-92b25bb

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/CHANGELOG.md CHANGED
@@ -3,6 +3,14 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [3.30.7](https://github.com/aomex/aomex/compare/v3.30.6...v3.30.7) (2026-11-01)
7
+
8
+ **Note:** Version bump only for package @aomex/rate-limit-redis-store
9
+
10
+
11
+
12
+
13
+
6
14
  ## [3.30.6](https://github.com/aomex/aomex/compare/v3.30.5...v3.30.6) (2026-10-19)
7
15
 
8
16
  **Note:** Version bump only for package @aomex/rate-limit-redis-store
package/dist/index.d.ts CHANGED
@@ -1,14 +1,11 @@
1
- import { RateLimitStore, RateLimitState } from '@aomex/rate-limit';
2
- import { Redis, RedisOptions } from 'ioredis';
3
-
4
- declare class RateLimitRedisStore extends RateLimitStore {
5
- protected readonly redis: Redis;
6
- constructor(opts: Redis | RedisOptions);
7
- getAndSet(data: {
8
- key: string;
9
- maxRequest: number;
10
- duration: number;
11
- }): Promise<RateLimitState>;
12
- }
13
-
14
- export { RateLimitRedisStore };
1
+ import { RateLimitState, RateLimitStore } from "@aomex/rate-limit";
2
+ import { Redis, RedisOptions } from "ioredis";
3
+ export declare class RateLimitRedisStore extends RateLimitStore {
4
+ protected readonly redis: Redis;
5
+ constructor(opts: Redis | RedisOptions);
6
+ getAndSet(data: {
7
+ key: string;
8
+ maxRequest: number;
9
+ duration: number;
10
+ }): Promise<RateLimitState>;
11
+ }
package/dist/index.js CHANGED
@@ -1,25 +1,27 @@
1
- // src/index.ts
2
1
  import { RateLimitStore } from "@aomex/rate-limit";
3
2
  import { Redis } from "ioredis";
3
+ // src/index.ts
4
4
  var RateLimitRedisStore = class extends RateLimitStore {
5
- redis;
6
- constructor(opts) {
7
- super();
8
- this.redis = opts instanceof Redis ? opts : new Redis(opts);
9
- }
10
- async getAndSet(data) {
11
- const { key, maxRequest, duration } = data;
12
- const now = this.getMicroTime();
13
- const durationMicro = duration * 1e3;
14
- const startTime = now - durationMicro;
15
- const result = await this.redis.multi().zremrangebyscore(key, 0, startTime).zcard(key).zadd(key, now, now).zrange(key, 0, 0).zrange(key, -maxRequest, -maxRequest).zremrangebyrank(key, 0, -(maxRequest + 1)).pexpire(key, duration).exec();
16
- const usedCount = Number(result[1][1]);
17
- const remaining = Math.max(maxRequest - usedCount, 0);
18
- const resetAt = Number(result[remaining ? 3 : 4][1][0]) + durationMicro;
19
- return { key, remaining, resetAt };
20
- }
21
- };
22
- export {
23
- RateLimitRedisStore
5
+ redis;
6
+ constructor(opts) {
7
+ super();
8
+ this.redis = opts instanceof Redis ? opts : new Redis(opts);
9
+ }
10
+ async getAndSet(data) {
11
+ const { key, maxRequest, duration } = data;
12
+ const now = this.getMicroTime();
13
+ const durationMicro = duration * 1e3;
14
+ const startTime = now - durationMicro;
15
+ const result = await this.redis.multi().zremrangebyscore(key, 0, startTime).zcard(key).zadd(key, now, now).zrange(key, 0, 0).zrange(key, -maxRequest, -maxRequest).zremrangebyrank(key, 0, -(maxRequest + 1)).pexpire(key, duration).exec();
16
+ const usedCount = Number(result[1][1]);
17
+ const remaining = Math.max(maxRequest - usedCount, 0);
18
+ return {
19
+ key,
20
+ remaining,
21
+ resetAt: Number(result[remaining ? 3 : 4][1][0]) + durationMicro
22
+ };
23
+ }
24
24
  };
25
+ export { RateLimitRedisStore };
26
+
25
27
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { RateLimitStore, type RateLimitState } from '@aomex/rate-limit';\nimport { Redis, type RedisOptions } from 'ioredis';\n\nexport class RateLimitRedisStore extends RateLimitStore {\n protected readonly redis: Redis;\n\n constructor(opts: Redis | RedisOptions) {\n super();\n this.redis = opts instanceof Redis ? opts : new Redis(opts);\n }\n\n override async getAndSet(data: {\n key: string;\n maxRequest: number;\n duration: number;\n }): Promise<RateLimitState> {\n const { key, maxRequest, duration } = data;\n const now = this.getMicroTime();\n const durationMicro = duration * 1_000;\n const startTime = now - durationMicro;\n\n const result = (await this.redis\n .multi()\n .zremrangebyscore(key, 0, startTime)\n .zcard(key)\n .zadd(key, now, now)\n .zrange(key, 0, 0)\n .zrange(key, -maxRequest, -maxRequest)\n .zremrangebyrank(key, 0, -(maxRequest + 1))\n .pexpire(key, duration)\n .exec()) as [\n never,\n [null, usedCount: Awaited<ReturnType<Redis['zcard']>>],\n never,\n [null, oldest: Awaited<ReturnType<Redis['zrange']>>],\n [null, oldestInRange: Awaited<ReturnType<Redis['zrange']>>],\n never,\n never,\n ];\n\n const usedCount = Number(result[1][1]);\n const remaining = Math.max(maxRequest - usedCount, 0);\n const resetAt = Number(result[remaining ? 3 : 4][1][0]) + durationMicro;\n\n return { key, remaining, resetAt };\n }\n}\n"],"mappings":";AAAA,SAAS,sBAA2C;AACpD,SAAS,aAAgC;AAElC,IAAM,sBAAN,cAAkC,eAAe;AAAA,EACnC;AAAA,EAEnB,YAAY,MAA4B;AACtC,UAAM;AACN,SAAK,QAAQ,gBAAgB,QAAQ,OAAO,IAAI,MAAM,IAAI;AAAA,EAC5D;AAAA,EAEA,MAAe,UAAU,MAIG;AAC1B,UAAM,EAAE,KAAK,YAAY,SAAS,IAAI;AACtC,UAAM,MAAM,KAAK,aAAa;AAC9B,UAAM,gBAAgB,WAAW;AACjC,UAAM,YAAY,MAAM;AAExB,UAAM,SAAU,MAAM,KAAK,MACxB,MAAM,EACN,iBAAiB,KAAK,GAAG,SAAS,EAClC,MAAM,GAAG,EACT,KAAK,KAAK,KAAK,GAAG,EAClB,OAAO,KAAK,GAAG,CAAC,EAChB,OAAO,KAAK,CAAC,YAAY,CAAC,UAAU,EACpC,gBAAgB,KAAK,GAAG,EAAE,aAAa,EAAE,EACzC,QAAQ,KAAK,QAAQ,EACrB,KAAK;AAUR,UAAM,YAAY,OAAO,OAAO,CAAC,EAAE,CAAC,CAAC;AACrC,UAAM,YAAY,KAAK,IAAI,aAAa,WAAW,CAAC;AACpD,UAAM,UAAU,OAAO,OAAO,YAAY,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,IAAI;AAE1D,WAAO,EAAE,KAAK,WAAW,QAAQ;AAAA,EACnC;AACF;","names":[]}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { RateLimitStore, type RateLimitState } from '@aomex/rate-limit';\nimport { Redis, type RedisOptions } from 'ioredis';\n\nexport class RateLimitRedisStore extends RateLimitStore {\n protected readonly redis: Redis;\n\n constructor(opts: Redis | RedisOptions) {\n super();\n this.redis = opts instanceof Redis ? opts : new Redis(opts);\n }\n\n override async getAndSet(data: {\n key: string;\n maxRequest: number;\n duration: number;\n }): Promise<RateLimitState> {\n const { key, maxRequest, duration } = data;\n const now = this.getMicroTime();\n const durationMicro = duration * 1_000;\n const startTime = now - durationMicro;\n\n const result = (await this.redis\n .multi()\n .zremrangebyscore(key, 0, startTime)\n .zcard(key)\n .zadd(key, now, now)\n // ioredis@6.0 生成类型漏了 stop: number(#2162 / #2163,修在 6.1.0-beta.1)\n // @ts-expect-error stop 运行时仍接受 number\n .zrange(key, 0, 0)\n // @ts-expect-error stop 运行时仍接受 number\n .zrange(key, -maxRequest, -maxRequest)\n .zremrangebyrank(key, 0, -(maxRequest + 1))\n .pexpire(key, duration)\n .exec()) as [\n never,\n [null, usedCount: Awaited<ReturnType<Redis['zcard']>>],\n never,\n [null, oldest: Awaited<ReturnType<Redis['zrange']>>],\n [null, oldestInRange: Awaited<ReturnType<Redis['zrange']>>],\n never,\n never,\n ];\n\n const usedCount = Number(result[1][1]);\n const remaining = Math.max(maxRequest - usedCount, 0);\n const resetAt = Number(result[remaining ? 3 : 4][1][0]) + durationMicro;\n\n return { key, remaining, resetAt };\n }\n}\n"],"mappings":";;;AAGA,IAAa,sBAAb,cAAyC,eAAe;CACtD;CAEA,YAAY,MAA4B;EACtC,MAAM;EACN,KAAK,QAAQ,gBAAgB,QAAQ,OAAO,IAAI,MAAM,IAAI;CAC5D;CAEA,MAAe,UAAU,MAIG;EAC1B,MAAM,EAAE,KAAK,YAAY,aAAa;EACtC,MAAM,MAAM,KAAK,aAAa;EAC9B,MAAM,gBAAgB,WAAW;EACjC,MAAM,YAAY,MAAM;EAExB,MAAM,SAAU,MAAM,KAAK,MACxB,MAAM,CAAC,CACP,iBAAiB,KAAK,GAAG,SAAS,CAAC,CACnC,MAAM,GAAG,CAAC,CACV,KAAK,KAAK,KAAK,GAAG,CAAC,CAGnB,OAAO,KAAK,GAAG,CAAC,CAAC,CAEjB,OAAO,KAAK,CAAC,YAAY,CAAC,UAAU,CAAC,CACrC,gBAAgB,KAAK,GAAG,EAAE,aAAa,EAAE,CAAC,CAC1C,QAAQ,KAAK,QAAQ,CAAC,CACtB,KAAK;EAUR,MAAM,YAAY,OAAO,OAAO,EAAE,CAAC,EAAE;EACrC,MAAM,YAAY,KAAK,IAAI,aAAa,WAAW,CAAC;EAGpD,OAAO;GAAE;GAAK;GAAW,SAFT,OAAO,OAAO,YAAY,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,IAAI;EAEzB;CACnC;AACF"}
package/package.json CHANGED
@@ -1,23 +1,17 @@
1
1
  {
2
2
  "name": "@aomex/rate-limit-redis-store",
3
- "version": "3.30.6",
3
+ "version": "3.30.8-alpha.62.sha-92b25bb",
4
4
  "description": "请求限速redis存储引擎",
5
- "repository": {
6
- "type": "git",
7
- "url": "git@github.com:aomex/aomex.git"
8
- },
5
+ "repository": "git@github.com:aomex/aomex.git",
9
6
  "homepage": "https://aomex.js.org",
10
7
  "license": "MIT",
11
8
  "type": "module",
12
9
  "sideEffects": false,
13
- "types": "dist/index.d.ts",
14
- "exports": {
15
- ".": {
16
- "types": "./dist/index.d.ts",
17
- "import": "./dist/index.js"
18
- },
19
- "./package.json": "./package.json"
10
+ "scripts": {
11
+ "prepublishOnly": "tsdown"
20
12
  },
13
+ "types": "src/index.ts",
14
+ "exports": "./src/index.ts",
21
15
  "files": [
22
16
  "dist",
23
17
  "LICENSE",
@@ -26,15 +20,23 @@
26
20
  "CHANGELOG.md"
27
21
  ],
28
22
  "publishConfig": {
23
+ "types": "dist/index.d.ts",
24
+ "exports": {
25
+ ".": {
26
+ "types": "./dist/index.d.ts",
27
+ "import": "./dist/index.js"
28
+ },
29
+ "./package.json": "./package.json"
30
+ },
29
31
  "access": "public"
30
32
  },
31
33
  "peerDependencies": {
32
- "@aomex/rate-limit": "^3.0.0",
34
+ "@aomex/rate-limit": "^4.0.0",
33
35
  "ioredis": ">=5"
34
36
  },
35
37
  "devDependencies": {
36
- "@aomex/rate-limit": "3.30.6",
37
- "ioredis": "^5.4.1"
38
+ "@aomex/rate-limit": "3.30.8-alpha.62.sha-92b25bb",
39
+ "ioredis": "^6.0.0"
38
40
  },
39
- "scripts": {}
40
- }
41
+ "gitHead": "92b25bbcd6c3ae28160316117a74c88619b5bc8d"
42
+ }