@jayfong/x-server 1.16.0 → 1.16.1

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
@@ -2,6 +2,13 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [1.16.1](https://github.com/jfWorks/x-server/compare/v1.16.0...v1.16.1) (2022-04-27)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * RateLimitService ([20a489e](https://github.com/jfWorks/x-server/commit/20a489e3cb119ba055d4c77983354f607f61af0b))
11
+
5
12
  ## [1.16.0](https://github.com/jfWorks/x-server/compare/v1.15.3...v1.16.0) (2022-04-27)
6
13
 
7
14
 
@@ -8,14 +8,14 @@ var _x = require("../x");
8
8
  class RateLimitService {
9
9
  constructor() {
10
10
  this.serviceName = 'rateLimit';
11
- this.cacheService = _x.x.cache.fork();
12
11
  }
13
12
 
14
13
  async limitByCount(options) {
15
- const remainingCount = await this.cacheService.get(['rateLimit', options.key]);
14
+ const cacheKey = `rateLimit_${options.key}`;
15
+ const remainingCount = await _x.x.cache.get(cacheKey);
16
16
 
17
17
  if (remainingCount == null) {
18
- await this.cacheService.set(['rateLimit', options.key], options.count, options.ttl);
18
+ await _x.x.cache.set(cacheKey, options.count, options.ttl);
19
19
  return options.count;
20
20
  }
21
21
 
@@ -23,7 +23,7 @@ class RateLimitService {
23
23
  return 0;
24
24
  }
25
25
 
26
- await this.cacheService.decrease(['rateLimit', options.key]);
26
+ await _x.x.cache.decrease(cacheKey);
27
27
  return remainingCount - 1;
28
28
  }
29
29
 
@@ -7,7 +7,6 @@ export interface RateLimitLimitByCountOptions {
7
7
  }
8
8
  export declare class RateLimitService implements BaseService {
9
9
  serviceName: string;
10
- private cacheService;
11
10
  limitByCount(options: RateLimitLimitByCountOptions): Promise<number>;
12
11
  }
13
12
  declare module '../x' {
@@ -2,14 +2,14 @@ import { x } from "../x";
2
2
  export class RateLimitService {
3
3
  constructor() {
4
4
  this.serviceName = 'rateLimit';
5
- this.cacheService = x.cache.fork();
6
5
  }
7
6
 
8
7
  async limitByCount(options) {
9
- const remainingCount = await this.cacheService.get(['rateLimit', options.key]);
8
+ const cacheKey = `rateLimit_${options.key}`;
9
+ const remainingCount = await x.cache.get(cacheKey);
10
10
 
11
11
  if (remainingCount == null) {
12
- await this.cacheService.set(['rateLimit', options.key], options.count, options.ttl);
12
+ await x.cache.set(cacheKey, options.count, options.ttl);
13
13
  return options.count;
14
14
  }
15
15
 
@@ -17,7 +17,7 @@ export class RateLimitService {
17
17
  return 0;
18
18
  }
19
19
 
20
- await this.cacheService.decrease(['rateLimit', options.key]);
20
+ await x.cache.decrease(cacheKey);
21
21
  return remainingCount - 1;
22
22
  }
23
23
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jayfong/x-server",
3
- "version": "1.16.0",
3
+ "version": "1.16.1",
4
4
  "license": "ISC",
5
5
  "sideEffects": false,
6
6
  "main": "lib/_cjs/index.js",