@jayfong/x-server 1.26.5 → 1.26.8
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 +21 -0
- package/lib/_cjs/cli/cli.js +3 -3
- package/lib/_cjs/cli/template_util.js +25 -0
- package/lib/_cjs/cli/templates/handlers.ts +1 -1
- package/lib/_cjs/cli/templates/hooks.ts +1 -1
- package/lib/_cjs/cli/templates/routes.ts +1 -1
- package/lib/_cjs/cli/templates/tasks.ts +1 -2
- package/lib/_cjs/services/sensitive_words.js +8 -1
- package/lib/cli/cli.js +3 -3
- package/lib/cli/template_util.d.ts +8 -0
- package/lib/cli/template_util.js +24 -0
- package/lib/cli/templates/handlers.ts +1 -1
- package/lib/cli/templates/hooks.ts +1 -1
- package/lib/cli/templates/routes.ts +1 -1
- package/lib/cli/templates/tasks.ts +1 -2
- package/lib/services/cache.d.ts +8 -9
- package/lib/services/captcha.d.ts +10 -10
- package/lib/services/dispose.d.ts +2 -2
- package/lib/services/pay.d.ts +8 -8
- package/lib/services/rate_limit.d.ts +2 -2
- package/lib/services/redis.d.ts +2 -0
- package/lib/services/sensitive_words.d.ts +10 -3
- package/lib/services/sensitive_words.js +9 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,27 @@
|
|
|
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.8](https://github.com/jfWorks/x-server/compare/v1.26.7...v1.26.8) (2022-05-07)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* init ([b8f8e44](https://github.com/jfWorks/x-server/commit/b8f8e44ed1cf282293938ab3678796a402832dc2))
|
|
11
|
+
|
|
12
|
+
### [1.26.7](https://github.com/jfWorks/x-server/compare/v1.26.6...v1.26.7) (2022-05-07)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Bug Fixes
|
|
16
|
+
|
|
17
|
+
* _ => index ([e3000d0](https://github.com/jfWorks/x-server/commit/e3000d09f20d983e3edc00d7a307b419f786e485))
|
|
18
|
+
|
|
19
|
+
### [1.26.6](https://github.com/jfWorks/x-server/compare/v1.26.5...v1.26.6) (2022-05-07)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Bug Fixes
|
|
23
|
+
|
|
24
|
+
* ServiceOptions ([bd86e66](https://github.com/jfWorks/x-server/commit/bd86e6618a5e115cbba26b56dfbeba2a427bfda7))
|
|
25
|
+
|
|
5
26
|
### [1.26.5](https://github.com/jfWorks/x-server/compare/v1.26.4...v1.26.5) (2022-05-06)
|
|
6
27
|
|
|
7
28
|
|
package/lib/_cjs/cli/cli.js
CHANGED
|
@@ -50,7 +50,7 @@ _yargs.default.command('dev', '开始开发', _ => _.positional('index', {
|
|
|
50
50
|
});
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
await _template_util.TemplateUtil.
|
|
53
|
+
await _template_util.TemplateUtil.init(process.cwd());
|
|
54
54
|
|
|
55
55
|
const watcher = _chokidar.default.watch(['src', '.env'], {
|
|
56
56
|
cwd: process.cwd()
|
|
@@ -70,7 +70,7 @@ _yargs.default.command('dev', '开始开发', _ => _.positional('index', {
|
|
|
70
70
|
|
|
71
71
|
(0, _vscodeGenerateIndexStandalone.generateManyIndex)({
|
|
72
72
|
cwd: process.cwd(),
|
|
73
|
-
patterns: ['src/**/index.ts', 'node_modules/.x/*.ts', ...(argv.index || [])],
|
|
73
|
+
patterns: ['src/**/index.ts', 'node_modules/.x/*.ts', '!src/handlers/**/*', ...(argv.index || [])],
|
|
74
74
|
replaceFile: true,
|
|
75
75
|
onSuccess: filePath => {
|
|
76
76
|
console.log(`✔️ 索引文件已更新: ${filePath}`);
|
|
@@ -107,7 +107,7 @@ _yargs.default.command('dev', '开始开发', _ => _.positional('index', {
|
|
|
107
107
|
value: 'production',
|
|
108
108
|
comment: ''
|
|
109
109
|
});
|
|
110
|
-
await _template_util.TemplateUtil.
|
|
110
|
+
await _template_util.TemplateUtil.init(process.cwd());
|
|
111
111
|
await (0, _vscodeGenerateIndexStandalone.generateManyIndex)({
|
|
112
112
|
cwd: process.cwd(),
|
|
113
113
|
patterns: ['src/.x/*.ts'],
|
|
@@ -14,9 +14,17 @@ var _vtils = require("vtils");
|
|
|
14
14
|
var _vscodeGenerateIndexStandalone = require("vscode-generate-index-standalone");
|
|
15
15
|
|
|
16
16
|
class TemplateUtil {
|
|
17
|
+
/**
|
|
18
|
+
* 初始化。
|
|
19
|
+
*/
|
|
20
|
+
static async init(cwd) {
|
|
21
|
+
await Promise.all([this.initHelperPackage(cwd), this.initTasks(cwd)]);
|
|
22
|
+
}
|
|
17
23
|
/**
|
|
18
24
|
* 初始化辅助包。
|
|
19
25
|
*/
|
|
26
|
+
|
|
27
|
+
|
|
20
28
|
static async initHelperPackage(cwd) {
|
|
21
29
|
const fromDir = _path.default.join(__dirname, 'templates');
|
|
22
30
|
|
|
@@ -31,6 +39,23 @@ class TemplateUtil {
|
|
|
31
39
|
replaceFile: true
|
|
32
40
|
});
|
|
33
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* 初始化任务。
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
static async initTasks(cwd) {
|
|
48
|
+
const tasksDir = _path.default.join(cwd, 'tasks');
|
|
49
|
+
|
|
50
|
+
const tasksIndexFile = _path.default.join(tasksDir, 'index.ts');
|
|
51
|
+
|
|
52
|
+
if (!(await _fsExtra.default.pathExists(tasksIndexFile))) {
|
|
53
|
+
await _fsExtra.default.writeFile(tasksIndexFile, (0, _vtils.dedent)`
|
|
54
|
+
// @index(['./**/*.ts', '!**/*.test.ts', '!**/_*'], f => \`export * from '\${f.path}'\`)
|
|
55
|
+
// @endindex
|
|
56
|
+
`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
34
59
|
/**
|
|
35
60
|
* 初始化模型。
|
|
36
61
|
*/
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
// @index('../../src/handlers/**/*.ts', (f, _) => `export * as __${_.pascal(f.path.replace('/src/handlers/', ''))}__ from '${f.path}'`)
|
|
1
|
+
// @index(['../../src/handlers/**/*.ts', '!**/_*'], (f, _) => `export * as __${_.pascal(f.path.replace('/src/handlers/', ''))}__ from '${f.path}'`)
|
|
2
2
|
|
|
3
3
|
// @endindex
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
// @index('../../src/hooks/**/*.ts', (f, _) => `import '${f.path}'`)
|
|
1
|
+
// @index(['../../src/hooks/**/*.ts', '!**/_*'], (f, _) => `import '${f.path}'`)
|
|
2
2
|
// @endindex
|
|
@@ -2,7 +2,7 @@ import * as handlers from './handlers'
|
|
|
2
2
|
import { Handler, XServer } from '@jayfong/x-server'
|
|
3
3
|
|
|
4
4
|
const basePathWithHandlers: Array<[string, Record<string, Handler>]> = [
|
|
5
|
-
// @index('../../src/handlers/**/*.ts', (f, _) => `['${('/'
|
|
5
|
+
// @index(['../../src/handlers/**/*.ts', '!**/_*'], (f, _) => `['${(f.path+'/').replace('../../src/handlers/', '/').replace(/\/index\/$/, '/').split('/').map(v => _.snake(v)).join('/')}', handlers.__${_.pascal(f.path.replace('/src/handlers/', ''))}__ as any],`)
|
|
6
6
|
// @endindex
|
|
7
7
|
]
|
|
8
8
|
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
// @endindex
|
|
1
|
+
import '../../src/tasks/index'
|
|
@@ -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
|
-
|
|
23
|
+
|
|
24
|
+
async process(text) {
|
|
18
25
|
if (!this.mint) {
|
|
19
26
|
this.mint = new _mintFilter.default(this.options.words);
|
|
20
27
|
}
|
package/lib/cli/cli.js
CHANGED
|
@@ -36,7 +36,7 @@ yargs.command('dev', '开始开发', _ => _.positional('index', {
|
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
await TemplateUtil.
|
|
39
|
+
await TemplateUtil.init(process.cwd());
|
|
40
40
|
const watcher = chokidar.watch(['src', '.env'], {
|
|
41
41
|
cwd: process.cwd()
|
|
42
42
|
});
|
|
@@ -52,7 +52,7 @@ yargs.command('dev', '开始开发', _ => _.positional('index', {
|
|
|
52
52
|
});
|
|
53
53
|
generateManyIndex({
|
|
54
54
|
cwd: process.cwd(),
|
|
55
|
-
patterns: ['src/**/index.ts', 'node_modules/.x/*.ts', ...(argv.index || [])],
|
|
55
|
+
patterns: ['src/**/index.ts', 'node_modules/.x/*.ts', '!src/handlers/**/*', ...(argv.index || [])],
|
|
56
56
|
replaceFile: true,
|
|
57
57
|
onSuccess: filePath => {
|
|
58
58
|
console.log(`✔️ 索引文件已更新: ${filePath}`);
|
|
@@ -89,7 +89,7 @@ yargs.command('dev', '开始开发', _ => _.positional('index', {
|
|
|
89
89
|
value: 'production',
|
|
90
90
|
comment: ''
|
|
91
91
|
});
|
|
92
|
-
await TemplateUtil.
|
|
92
|
+
await TemplateUtil.init(process.cwd());
|
|
93
93
|
await generateManyIndex({
|
|
94
94
|
cwd: process.cwd(),
|
|
95
95
|
patterns: ['src/.x/*.ts'],
|
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
export declare class TemplateUtil {
|
|
2
|
+
/**
|
|
3
|
+
* 初始化。
|
|
4
|
+
*/
|
|
5
|
+
static init(cwd: string): Promise<void>;
|
|
2
6
|
/**
|
|
3
7
|
* 初始化辅助包。
|
|
4
8
|
*/
|
|
5
9
|
static initHelperPackage(cwd: string): Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* 初始化任务。
|
|
12
|
+
*/
|
|
13
|
+
static initTasks(cwd: string): Promise<void>;
|
|
6
14
|
/**
|
|
7
15
|
* 初始化模型。
|
|
8
16
|
*/
|
package/lib/cli/template_util.js
CHANGED
|
@@ -3,9 +3,17 @@ import path from 'path';
|
|
|
3
3
|
import { camelCase, dedent, snakeCase, upperFirst } from 'vtils';
|
|
4
4
|
import { generateManyIndex } from 'vscode-generate-index-standalone';
|
|
5
5
|
export class TemplateUtil {
|
|
6
|
+
/**
|
|
7
|
+
* 初始化。
|
|
8
|
+
*/
|
|
9
|
+
static async init(cwd) {
|
|
10
|
+
await Promise.all([this.initHelperPackage(cwd), this.initTasks(cwd)]);
|
|
11
|
+
}
|
|
6
12
|
/**
|
|
7
13
|
* 初始化辅助包。
|
|
8
14
|
*/
|
|
15
|
+
|
|
16
|
+
|
|
9
17
|
static async initHelperPackage(cwd) {
|
|
10
18
|
const fromDir = path.join(__dirname, 'templates');
|
|
11
19
|
const toDir = path.join(cwd, 'node_modules/.x');
|
|
@@ -18,6 +26,22 @@ export class TemplateUtil {
|
|
|
18
26
|
replaceFile: true
|
|
19
27
|
});
|
|
20
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* 初始化任务。
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
static async initTasks(cwd) {
|
|
35
|
+
const tasksDir = path.join(cwd, 'tasks');
|
|
36
|
+
const tasksIndexFile = path.join(tasksDir, 'index.ts');
|
|
37
|
+
|
|
38
|
+
if (!(await fs.pathExists(tasksIndexFile))) {
|
|
39
|
+
await fs.writeFile(tasksIndexFile, dedent`
|
|
40
|
+
// @index(['./**/*.ts', '!**/*.test.ts', '!**/_*'], f => \`export * from '\${f.path}'\`)
|
|
41
|
+
// @endindex
|
|
42
|
+
`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
21
45
|
/**
|
|
22
46
|
* 初始化模型。
|
|
23
47
|
*/
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
// @index('../../src/handlers/**/*.ts', (f, _) => `export * as __${_.pascal(f.path.replace('/src/handlers/', ''))}__ from '${f.path}'`)
|
|
1
|
+
// @index(['../../src/handlers/**/*.ts', '!**/_*'], (f, _) => `export * as __${_.pascal(f.path.replace('/src/handlers/', ''))}__ from '${f.path}'`)
|
|
2
2
|
|
|
3
3
|
// @endindex
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
// @index('../../src/hooks/**/*.ts', (f, _) => `import '${f.path}'`)
|
|
1
|
+
// @index(['../../src/hooks/**/*.ts', '!**/_*'], (f, _) => `import '${f.path}'`)
|
|
2
2
|
// @endindex
|
|
@@ -2,7 +2,7 @@ import * as handlers from './handlers'
|
|
|
2
2
|
import { Handler, XServer } from '@jayfong/x-server'
|
|
3
3
|
|
|
4
4
|
const basePathWithHandlers: Array<[string, Record<string, Handler>]> = [
|
|
5
|
-
// @index('../../src/handlers/**/*.ts', (f, _) => `['${('/'
|
|
5
|
+
// @index(['../../src/handlers/**/*.ts', '!**/_*'], (f, _) => `['${(f.path+'/').replace('../../src/handlers/', '/').replace(/\/index\/$/, '/').split('/').map(v => _.snake(v)).join('/')}', handlers.__${_.pascal(f.path.replace('/src/handlers/', ''))}__ as any],`)
|
|
6
6
|
// @endindex
|
|
7
7
|
]
|
|
8
8
|
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
// @endindex
|
|
1
|
+
import '../../src/tasks/index'
|
package/lib/services/cache.d.ts
CHANGED
|
@@ -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
|
|
5
|
-
export interface CacheOptions {
|
|
4
|
+
export interface CacheServiceOptions {
|
|
6
5
|
/** 默认过期时间 */
|
|
7
|
-
ttl:
|
|
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:
|
|
20
|
+
options: CacheServiceOptions;
|
|
22
21
|
serviceName: string;
|
|
23
22
|
private prefix;
|
|
24
|
-
constructor(options:
|
|
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?:
|
|
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?:
|
|
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?:
|
|
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<
|
|
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
|
|
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
|
|
13
|
+
export interface CaptchaServiceGenerateResult {
|
|
14
14
|
token: string;
|
|
15
15
|
code: string;
|
|
16
16
|
}
|
|
17
|
-
export interface
|
|
17
|
+
export interface CaptchaServiceGenerateImageResult {
|
|
18
18
|
token: string;
|
|
19
19
|
code: string;
|
|
20
20
|
svg: string;
|
|
21
21
|
}
|
|
22
|
-
export interface
|
|
22
|
+
export interface CaptchaServiceGenerateDataUrlResult {
|
|
23
23
|
token: string;
|
|
24
24
|
code: string;
|
|
25
25
|
dataUrl: string;
|
|
26
26
|
}
|
|
27
|
-
export interface
|
|
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:
|
|
35
|
-
generate(): Promise<
|
|
36
|
-
generateImage(): Promise<
|
|
37
|
-
generateDataUrl(): Promise<
|
|
38
|
-
verify(options:
|
|
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
|
|
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?:
|
|
8
|
+
constructor(options?: DisposeServiceOptions);
|
|
9
9
|
private disposes;
|
|
10
10
|
add(fn: () => any): void;
|
|
11
11
|
dispose(): Promise<any[]>;
|
package/lib/services/pay.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BaseService } from './base';
|
|
2
|
-
export interface
|
|
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
|
|
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
|
|
38
|
+
export interface PayServicePrepareAlipayResult {
|
|
39
39
|
/** 支付地址,需跳转过去 */
|
|
40
40
|
payUrl: string;
|
|
41
41
|
}
|
|
42
|
-
export interface
|
|
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
|
|
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:
|
|
70
|
-
prepareAlipay(options:
|
|
71
|
-
prepareWepay(options:
|
|
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
|
|
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:
|
|
10
|
+
limitByCount(options: RateLimitServiceLimitByCountOptions): Promise<number>;
|
|
11
11
|
}
|
|
12
12
|
declare module '../x' {
|
|
13
13
|
interface X {
|
package/lib/services/redis.d.ts
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
import { BaseService } from './base';
|
|
2
|
-
export interface
|
|
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:
|
|
10
|
-
|
|
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
|
|
17
|
+
async process(text) {
|
|
10
18
|
if (!this.mint) {
|
|
11
19
|
this.mint = new Mint(this.options.words);
|
|
12
20
|
}
|