@jayfong/x-server 2.2.13 → 2.2.15
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/lib/_cjs/index.js +8 -0
- package/lib/_cjs/services/rate_limit.js +12 -0
- package/lib/_cjs/types/index.js +3 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +2 -1
- package/lib/services/rate_limit.d.ts +4 -0
- package/lib/services/rate_limit.js +11 -0
- package/lib/types/index.d.ts +23 -0
- package/lib/types/index.js +1 -0
- package/package.json +1 -1
package/lib/_cjs/index.js
CHANGED
|
@@ -250,6 +250,14 @@ Object.keys(_x).forEach(function (key) {
|
|
|
250
250
|
exports[key] = _x[key];
|
|
251
251
|
});
|
|
252
252
|
|
|
253
|
+
var _index = require("./types/index");
|
|
254
|
+
|
|
255
|
+
Object.keys(_index).forEach(function (key) {
|
|
256
|
+
if (key === "default" || key === "__esModule") return;
|
|
257
|
+
if (key in exports && exports[key] === _index[key]) return;
|
|
258
|
+
exports[key] = _index[key];
|
|
259
|
+
});
|
|
260
|
+
|
|
253
261
|
var _models = require(".x/models");
|
|
254
262
|
|
|
255
263
|
Object.keys(_models).forEach(function (key) {
|
|
@@ -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;
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -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
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { OmitStrict, PartialBy, RequiredBy, RequiredDeep, Simplify } from 'vtils/types';
|
|
2
|
+
export declare type MakeDtoRequired<TRawData extends Record<any, any>, TPickKey extends keyof TRawData = never, TPartialKey extends keyof Pick<RequiredDeep<TRawData>, [
|
|
3
|
+
TPickKey
|
|
4
|
+
] extends [never] ? keyof TRawData : TPickKey> = never> = Simplify<PartialBy<Pick<RequiredDeep<TRawData>, [
|
|
5
|
+
TPickKey
|
|
6
|
+
] extends [never] ? keyof TRawData : TPickKey>, TPartialKey>>;
|
|
7
|
+
export declare type MakeDtoPartial<TRawData extends Record<any, any>, TPickKey extends keyof TRawData = never, TRequiredKey extends keyof Pick<Partial<TRawData>, [
|
|
8
|
+
TPickKey
|
|
9
|
+
] extends [never] ? keyof TRawData : TPickKey> = never> = Simplify<RequiredBy<Pick<Partial<TRawData>, [
|
|
10
|
+
TPickKey
|
|
11
|
+
] extends [never] ? keyof TRawData : TPickKey>, TRequiredKey>>;
|
|
12
|
+
export declare type MakeDtoExcludeRequired<TRawData extends Record<any, any>, TExcludeKey extends keyof TRawData = never, TPartialKey extends keyof Omit<RequiredDeep<TRawData>, [
|
|
13
|
+
TExcludeKey
|
|
14
|
+
] extends [never] ? never : TExcludeKey> = never> = Simplify<PartialBy<Omit<RequiredDeep<TRawData>, [
|
|
15
|
+
TExcludeKey
|
|
16
|
+
] extends [never] ? never : TExcludeKey>, TPartialKey>>;
|
|
17
|
+
export declare type MakeDtoExcludePartial<TRawData extends Record<any, any>, TExcludeKey extends keyof TRawData = never, TRequiredKey extends keyof Omit<Partial<TRawData>, [
|
|
18
|
+
TExcludeKey
|
|
19
|
+
] extends [never] ? never : TExcludeKey> = never> = Simplify<RequiredBy<Omit<Partial<TRawData>, [
|
|
20
|
+
TExcludeKey
|
|
21
|
+
] extends [never] ? never : TExcludeKey>, TRequiredKey>>;
|
|
22
|
+
export declare type MakeDtoExclude<T, K extends keyof T> = OmitStrict<T, K>;
|
|
23
|
+
export declare type MakeDtoInclude<T, K extends keyof T> = Pick<T, K>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|