@jayfong/x-server 1.26.5 → 1.26.6

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.26.6](https://github.com/jfWorks/x-server/compare/v1.26.5...v1.26.6) (2022-05-07)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * ServiceOptions ([bd86e66](https://github.com/jfWorks/x-server/commit/bd86e6618a5e115cbba26b56dfbeba2a427bfda7))
11
+
5
12
  ### [1.26.5](https://github.com/jfWorks/x-server/compare/v1.26.4...v1.26.5) (2022-05-06)
6
13
 
7
14
 
@@ -7,14 +7,21 @@ exports.SensitiveWordsService = void 0;
7
7
 
8
8
  var _mintFilter = _interopRequireDefault(require("mint-filter"));
9
9
 
10
+ /**
11
+ * 敏感词服务。
12
+ */
10
13
  class SensitiveWordsService {
11
14
  constructor(options) {
12
15
  this.options = options;
13
16
  this.serviceName = 'sensitiveWords';
14
17
  this.mint = void 0;
15
18
  }
19
+ /**
20
+ * 处理文本,敏感词将被替换为 * 号。
21
+ */
16
22
 
17
- async filter(text) {
23
+
24
+ async process(text) {
18
25
  if (!this.mint) {
19
26
  this.mint = new _mintFilter.default(this.options.words);
20
27
  }
@@ -1,10 +1,9 @@
1
1
  import { AsyncOrSync, IsEmptyArray, NonEmptyArray } from 'vtils/types';
2
2
  import { BaseService } from './base';
3
3
  import { MsValue } from 'vtils/date';
4
- export declare type CacheTTL = MsValue;
5
- export interface CacheOptions {
4
+ export interface CacheServiceOptions {
6
5
  /** 默认过期时间 */
7
- ttl: CacheTTL;
6
+ ttl: MsValue;
8
7
  }
9
8
  declare type Data = {
10
9
  [K in string]: (...args: any[]) => any;
@@ -18,10 +17,10 @@ declare type KeyPathForNumberValue<T extends Data> = {
18
17
  }[keyof T];
19
18
  declare type Value<T extends Data, P extends KeyPath<T>> = ReturnType<T[P extends any[] ? P[0] : P]>;
20
19
  export declare class CacheService<TData extends Data = Data, TKey extends Key<TData> = any, TKeyPath extends KeyPath<TData> = any, TKeyPathForNumberValue extends KeyPathForNumberValue<TData> = any> implements BaseService {
21
- options: CacheOptions;
20
+ options: CacheServiceOptions;
22
21
  serviceName: string;
23
22
  private prefix;
24
- constructor(options: CacheOptions);
23
+ constructor(options: CacheServiceOptions);
25
24
  private toRedisKey;
26
25
  /**
27
26
  * 设置缓存内容。对象类内容尽量避免使用,以免造成问题。
@@ -31,14 +30,14 @@ export declare class CacheService<TData extends Data = Data, TKey extends Key<TD
31
30
  * @param ttl 缓存时间(单位:时)
32
31
  * @returns 返回设置的缓存内容
33
32
  */
34
- set<K extends TKeyPath, V extends Value<TData, K>>(key: K, value: V, ttl?: CacheTTL | ((data: V, defaultTTL: CacheTTL) => CacheTTL)): Promise<V>;
33
+ set<K extends TKeyPath, V extends Value<TData, K>>(key: K, value: V, ttl?: MsValue | ((data: V, defaultTTL: MsValue) => MsValue)): Promise<V>;
35
34
  /**
36
35
  * 存储值然后返回其对应的键,该键 URL 友好。
37
36
  *
38
37
  * @param value 值
39
38
  * @param ttl 存活时间
40
39
  */
41
- save<T>(value: T | ((key: string) => AsyncOrSync<T>), ttl?: CacheTTL): Promise<string>;
40
+ save<T>(value: T | ((key: string) => AsyncOrSync<T>), ttl?: MsValue): Promise<string>;
42
41
  /**
43
42
  * 获取缓存内容。
44
43
  *
@@ -61,7 +60,7 @@ export declare class CacheService<TData extends Data = Data, TKey extends Key<TD
61
60
  * @param ttl 缓存时间(单位:时)
62
61
  * @returns 返回获取到的内容
63
62
  */
64
- remember<K extends TKeyPath, V extends Value<TData, K>>(key: K, action: () => V | Promise<V>, ttl?: CacheTTL | ((data: V, defaultTTL: CacheTTL) => CacheTTL)): Promise<V>;
63
+ remember<K extends TKeyPath, V extends Value<TData, K>>(key: K, action: () => V | Promise<V>, ttl?: MsValue | ((data: V, defaultTTL: MsValue) => MsValue)): Promise<V>;
65
64
  /**
66
65
  * 自增。
67
66
  *
@@ -107,7 +106,7 @@ export declare class CacheService<TData extends Data = Data, TKey extends Key<TD
107
106
  /**
108
107
  * 派生出一个指定类型的缓存服务。
109
108
  */
110
- fork<TNextData extends Data>(options?: Partial<CacheOptions>): CacheService<TNextData, Key<TNextData>, KeyPath<TNextData>, KeyPathForNumberValue<TNextData>>;
109
+ fork<TNextData extends Data>(options?: Partial<CacheServiceOptions>): CacheService<TNextData, Key<TNextData>, KeyPath<TNextData>, KeyPathForNumberValue<TNextData>>;
111
110
  }
112
111
  declare module '../x' {
113
112
  interface X {
@@ -1,6 +1,6 @@
1
1
  import { BaseService } from './base';
2
2
  import type { MsValue } from 'vtils/date';
3
- export interface CaptchaOptions {
3
+ export interface CaptchaServiceOptions {
4
4
  /**
5
5
  * 验证码长度
6
6
  */
@@ -10,32 +10,32 @@ export interface CaptchaOptions {
10
10
  */
11
11
  ttl: MsValue;
12
12
  }
13
- export interface CaptchaGenerateResult {
13
+ export interface CaptchaServiceGenerateResult {
14
14
  token: string;
15
15
  code: string;
16
16
  }
17
- export interface CaptchaGenerateImageResult {
17
+ export interface CaptchaServiceGenerateImageResult {
18
18
  token: string;
19
19
  code: string;
20
20
  svg: string;
21
21
  }
22
- export interface CaptchaGenerateDataUrlResult {
22
+ export interface CaptchaServiceGenerateDataUrlResult {
23
23
  token: string;
24
24
  code: string;
25
25
  dataUrl: string;
26
26
  }
27
- export interface CaptchaVerifyOptions {
27
+ export interface CaptchaServiceVerifyOptions {
28
28
  token: string;
29
29
  code: string;
30
30
  }
31
31
  export declare class CaptchaService implements BaseService {
32
32
  private options;
33
33
  serviceName: string;
34
- constructor(options: CaptchaOptions);
35
- generate(): Promise<CaptchaGenerateResult>;
36
- generateImage(): Promise<CaptchaGenerateImageResult>;
37
- generateDataUrl(): Promise<CaptchaGenerateDataUrlResult>;
38
- verify(options: CaptchaVerifyOptions): Promise<boolean>;
34
+ constructor(options: CaptchaServiceOptions);
35
+ generate(): Promise<CaptchaServiceGenerateResult>;
36
+ generateImage(): Promise<CaptchaServiceGenerateImageResult>;
37
+ generateDataUrl(): Promise<CaptchaServiceGenerateDataUrlResult>;
38
+ verify(options: CaptchaServiceVerifyOptions): Promise<boolean>;
39
39
  }
40
40
  declare module '../x' {
41
41
  interface X {
@@ -1,11 +1,11 @@
1
1
  import { BaseService } from './base';
2
- export interface DisposeOptions {
2
+ export interface DisposeServiceOptions {
3
3
  disposeOnExit?: boolean;
4
4
  }
5
5
  export declare class DisposeService implements BaseService {
6
6
  private options?;
7
7
  serviceName: string;
8
- constructor(options?: DisposeOptions);
8
+ constructor(options?: DisposeServiceOptions);
9
9
  private disposes;
10
10
  add(fn: () => any): void;
11
11
  dispose(): Promise<any[]>;
@@ -1,5 +1,5 @@
1
1
  import { BaseService } from './base';
2
- export interface PayOptions {
2
+ export interface PayServiceOptions {
3
3
  /** 支付宝 */
4
4
  alipay?: {
5
5
  /** 应用 ID */
@@ -23,7 +23,7 @@ export interface PayOptions {
23
23
  secretKey: string;
24
24
  };
25
25
  }
26
- export interface PayPrepareAlipayOptions {
26
+ export interface PayServicePrepareAlipayOptions {
27
27
  /** 商品名称 */
28
28
  goodsName: string;
29
29
  /** 交易单号 */
@@ -35,11 +35,11 @@ export interface PayPrepareAlipayOptions {
35
35
  /** 返回地址 */
36
36
  returnUrl?: string;
37
37
  }
38
- export interface PayPrepareAlipayResult {
38
+ export interface PayServicePrepareAlipayResult {
39
39
  /** 支付地址,需跳转过去 */
40
40
  payUrl: string;
41
41
  }
42
- export interface PayPrepareWepayOptions {
42
+ export interface PayServicePrepareWepayOptions {
43
43
  /** 商品名称 */
44
44
  goodsName: string;
45
45
  /** 交易单号 */
@@ -51,7 +51,7 @@ export interface PayPrepareWepayOptions {
51
51
  /** 对应公众号用户的 openid */
52
52
  openid: string;
53
53
  }
54
- export interface PayPrepareWepayResult {
54
+ export interface PayServicePrepareWepayResult {
55
55
  /** 支付参数,可直接传给 JSSDK 调用 */
56
56
  payParams: {
57
57
  appId: string;
@@ -66,9 +66,9 @@ export declare class PayService implements BaseService {
66
66
  private options;
67
67
  serviceName: string;
68
68
  private alipaySdk;
69
- constructor(options: PayOptions);
70
- prepareAlipay(options: PayPrepareAlipayOptions): Promise<PayPrepareAlipayResult>;
71
- prepareWepay(options: PayPrepareWepayOptions): Promise<PayPrepareWepayResult>;
69
+ constructor(options: PayServiceOptions);
70
+ prepareAlipay(options: PayServicePrepareAlipayOptions): Promise<PayServicePrepareAlipayResult>;
71
+ prepareWepay(options: PayServicePrepareWepayOptions): Promise<PayServicePrepareWepayResult>;
72
72
  verifyNotifyData(data: any): boolean;
73
73
  verifyNotifyDataOrFail(data: any, message?: string): void;
74
74
  private wepaySign;
@@ -1,13 +1,13 @@
1
1
  import { BaseService } from './base';
2
2
  import { MsValue } from 'vtils/date';
3
- export interface RateLimitLimitByCountOptions {
3
+ export interface RateLimitServiceLimitByCountOptions {
4
4
  key: string;
5
5
  count: number;
6
6
  ttl: MsValue;
7
7
  }
8
8
  export declare class RateLimitService implements BaseService {
9
9
  serviceName: string;
10
- limitByCount(options: RateLimitLimitByCountOptions): Promise<number>;
10
+ limitByCount(options: RateLimitServiceLimitByCountOptions): Promise<number>;
11
11
  }
12
12
  declare module '../x' {
13
13
  interface X {
@@ -1,5 +1,7 @@
1
1
  import Redis from 'ioredis';
2
2
  import { BaseService } from './base';
3
+ export interface RedisServiceOptions extends Redis.RedisOptions {
4
+ }
3
5
  export declare class RedisService extends Redis implements BaseService {
4
6
  serviceName: string;
5
7
  }
@@ -1,13 +1,20 @@
1
1
  import { BaseService } from './base';
2
- export interface SensitiveWordsOptions {
2
+ export interface SensitiveWordsServiceOptions {
3
+ /** 敏感词列表 */
3
4
  words: string[];
4
5
  }
6
+ /**
7
+ * 敏感词服务。
8
+ */
5
9
  export declare class SensitiveWordsService implements BaseService {
6
10
  private options;
7
11
  serviceName: string;
8
12
  private mint;
9
- constructor(options: SensitiveWordsOptions);
10
- filter(text: string): Promise<string>;
13
+ constructor(options: SensitiveWordsServiceOptions);
14
+ /**
15
+ * 处理文本,敏感词将被替换为 * 号。
16
+ */
17
+ process(text: string): Promise<string>;
11
18
  }
12
19
  declare module '../x' {
13
20
  interface X {
@@ -1,12 +1,20 @@
1
1
  import Mint from 'mint-filter';
2
+
3
+ /**
4
+ * 敏感词服务。
5
+ */
2
6
  export class SensitiveWordsService {
3
7
  constructor(options) {
4
8
  this.options = options;
5
9
  this.serviceName = 'sensitiveWords';
6
10
  this.mint = void 0;
7
11
  }
12
+ /**
13
+ * 处理文本,敏感词将被替换为 * 号。
14
+ */
15
+
8
16
 
9
- async filter(text) {
17
+ async process(text) {
10
18
  if (!this.mint) {
11
19
  this.mint = new Mint(this.options.words);
12
20
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jayfong/x-server",
3
- "version": "1.26.5",
3
+ "version": "1.26.6",
4
4
  "license": "ISC",
5
5
  "sideEffects": false,
6
6
  "main": "lib/_cjs/index.js",