@jayfong/x-server 2.2.13 → 2.2.14
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.
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
4
|
exports.RateLimitService = void 0;
|
|
5
5
|
|
|
6
|
+
var _http_error = require("../core/http_error");
|
|
7
|
+
|
|
6
8
|
var _x = require("../x");
|
|
7
9
|
|
|
8
10
|
class RateLimitService {
|
|
@@ -27,6 +29,16 @@ class RateLimitService {
|
|
|
27
29
|
return remainingCount - 1;
|
|
28
30
|
}
|
|
29
31
|
|
|
32
|
+
async limitByCountOrFail(options) {
|
|
33
|
+
const count = await this.limitByCount(options);
|
|
34
|
+
|
|
35
|
+
if (count === 0) {
|
|
36
|
+
throw new _http_error.HttpError.Forbidden(options.message);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return count;
|
|
40
|
+
}
|
|
41
|
+
|
|
30
42
|
}
|
|
31
43
|
|
|
32
44
|
exports.RateLimitService = RateLimitService;
|
|
@@ -5,9 +5,13 @@ export interface RateLimitServiceLimitByCountOptions {
|
|
|
5
5
|
count: number;
|
|
6
6
|
ttl: MsValue;
|
|
7
7
|
}
|
|
8
|
+
export interface RateLimitServiceLimitByCountOrFailOptions extends RateLimitServiceLimitByCountOptions {
|
|
9
|
+
message?: string;
|
|
10
|
+
}
|
|
8
11
|
export declare class RateLimitService implements BaseService {
|
|
9
12
|
serviceName: string;
|
|
10
13
|
limitByCount(options: RateLimitServiceLimitByCountOptions): Promise<number>;
|
|
14
|
+
limitByCountOrFail(options: RateLimitServiceLimitByCountOrFailOptions): Promise<number>;
|
|
11
15
|
}
|
|
12
16
|
declare module '../x' {
|
|
13
17
|
interface X {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { HttpError } from "../core/http_error";
|
|
1
2
|
import { x } from "../x";
|
|
2
3
|
export class RateLimitService {
|
|
3
4
|
constructor() {
|
|
@@ -21,4 +22,14 @@ export class RateLimitService {
|
|
|
21
22
|
return remainingCount - 1;
|
|
22
23
|
}
|
|
23
24
|
|
|
25
|
+
async limitByCountOrFail(options) {
|
|
26
|
+
const count = await this.limitByCount(options);
|
|
27
|
+
|
|
28
|
+
if (count === 0) {
|
|
29
|
+
throw new HttpError.Forbidden(options.message);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return count;
|
|
33
|
+
}
|
|
34
|
+
|
|
24
35
|
}
|