@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 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;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
package/lib/index.d.ts CHANGED
@@ -29,4 +29,5 @@ export * from './services/rate_limit';
29
29
  export * from './services/redis';
30
30
  export * from './services/sensitive_words';
31
31
  export * from './x';
32
+ export * from './types/index';
32
33
  export * from '.x/models';
package/lib/index.js CHANGED
@@ -30,6 +30,7 @@ export * from "./services/rate_limit";
30
30
  export * from "./services/redis";
31
31
  export * from "./services/sensitive_words";
32
32
  export * from "./x"; // @endindex
33
- // @ts-ignore
33
+
34
+ export * from "./types/index"; // @ts-ignore
34
35
 
35
36
  export * from '.x/models';
@@ -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 {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jayfong/x-server",
3
- "version": "2.2.13",
3
+ "version": "2.2.15",
4
4
  "license": "ISC",
5
5
  "sideEffects": false,
6
6
  "main": "lib/_cjs/index.js",