@jayfong/x-server 2.62.1 → 2.62.3
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/cli/api_generator.js +5 -11
- package/lib/_cjs/cli/build_util.js +4 -6
- package/lib/_cjs/cli/env_util.js +1 -2
- package/lib/_cjs/core/define_task.js +5 -5
- package/lib/_cjs/core/server.js +7 -8
- package/lib/_cjs/plugins/file_parser.js +1 -2
- package/lib/_cjs/services/captcha.js +1 -2
- package/lib/_cjs/services/db_value.js +3 -3
- package/lib/_cjs/services/dispose.js +1 -2
- package/lib/_cjs/services/jwt.js +1 -2
- package/lib/_cjs/services/pay.js +1 -2
- package/lib/_cjs/services/rate_limit.js +1 -2
- package/lib/cli/api_generator.js +5 -11
- package/lib/cli/build_util.js +1 -2
- package/lib/cli/env_util.js +1 -2
- package/lib/core/define_task.js +5 -5
- package/lib/core/http_redirect.d.ts +2 -2
- package/lib/core/server.js +7 -7
- package/lib/plugins/cookie.d.ts +1 -1
- package/lib/plugins/file_parser.d.ts +1 -1
- package/lib/plugins/file_parser.js +1 -2
- package/lib/plugins/form_body_parser.d.ts +1 -1
- package/lib/plugins/ws_parser.d.ts +1 -1
- package/lib/plugins/xml_parser.d.ts +1 -1
- package/lib/services/captcha.js +1 -2
- package/lib/services/db_value.js +3 -3
- package/lib/services/dispose.d.ts +1 -1
- package/lib/services/dispose.js +1 -2
- package/lib/services/jwt.js +1 -2
- package/lib/services/pay.js +1 -2
- package/lib/services/rate_limit.js +1 -2
- package/package.json +1 -1
|
@@ -47,7 +47,6 @@ class ApiGenerator {
|
|
|
47
47
|
const categorySymbols = checker.getExportsOfModule(moduleSymbol);
|
|
48
48
|
const apiData = [];
|
|
49
49
|
for (const categorySymbol of categorySymbols) {
|
|
50
|
-
var _ref, _categoryUrlMatch$;
|
|
51
50
|
// 分类的类型
|
|
52
51
|
const categoryType = checker.getTypeOfSymbol(categorySymbol);
|
|
53
52
|
|
|
@@ -62,7 +61,7 @@ class ApiGenerator {
|
|
|
62
61
|
|
|
63
62
|
// 分类 URL
|
|
64
63
|
const categoryUrlMatch = categorySourceFilePath.match(this.categoryUrlRe);
|
|
65
|
-
let categoryUrl =
|
|
64
|
+
let categoryUrl = categoryUrlMatch[1] ?? categoryUrlMatch[2] ?? '';
|
|
66
65
|
categoryUrl = categoryUrl === '' ? '/' : `/${categoryUrl}/`;
|
|
67
66
|
for (const handlerSymbol of handlerSymbols) {
|
|
68
67
|
// 处理器路径
|
|
@@ -78,10 +77,7 @@ class ApiGenerator {
|
|
|
78
77
|
// defineHandler({})
|
|
79
78
|
_tsMorph.ts.isObjectLiteralExpression(handlerNode.initializer.arguments[0])) {
|
|
80
79
|
const props = handlerNode.initializer.arguments[0].properties;
|
|
81
|
-
const requestPathNode = props.find(item =>
|
|
82
|
-
var _item$name;
|
|
83
|
-
return ((_item$name = item.name) == null ? void 0 : _item$name.getText()) === 'requestPath';
|
|
84
|
-
});
|
|
80
|
+
const requestPathNode = props.find(item => item.name?.getText() === 'requestPath');
|
|
85
81
|
if (requestPathNode &&
|
|
86
82
|
// requestPath: ''
|
|
87
83
|
_tsMorph.ts.isPropertyAssignment(requestPathNode)) {
|
|
@@ -172,11 +168,10 @@ class ApiGenerator {
|
|
|
172
168
|
type,
|
|
173
169
|
keySymbol = type.symbol || type.aliasSymbol
|
|
174
170
|
}) {
|
|
175
|
-
var _valueSymbol;
|
|
176
171
|
const hasTypeFlag = (flag, _type = type) => (_type.flags & flag) === flag;
|
|
177
172
|
let valueSymbol = type.symbol || type.aliasSymbol;
|
|
178
|
-
const keySymbolName =
|
|
179
|
-
let valueSymbolName =
|
|
173
|
+
const keySymbolName = keySymbol?.getName() || '';
|
|
174
|
+
let valueSymbolName = valueSymbol?.getName() || '';
|
|
180
175
|
const comment = this.getComment(keySymbol);
|
|
181
176
|
let isRequired = keySymbol ? !(keySymbol.getFlags() & _tsMorph.ts.SymbolFlags.Optional) : false;
|
|
182
177
|
|
|
@@ -222,13 +217,12 @@ class ApiGenerator {
|
|
|
222
217
|
const unionTypes = rawUnionTypes.filter(item => !hasTypeFlag(_tsMorph.ts.TypeFlags.Null, item) && !hasTypeFlag(_tsMorph.ts.TypeFlags.Undefined, item));
|
|
223
218
|
const isUnion = !!unionTypes.length;
|
|
224
219
|
if (isUnion) {
|
|
225
|
-
var _this$checker$getBase;
|
|
226
220
|
if (unionTypes.length !== rawUnionTypes.length) {
|
|
227
221
|
isRequired = false;
|
|
228
222
|
}
|
|
229
223
|
type = unionTypes[0];
|
|
230
224
|
valueSymbol = type.symbol || type.aliasSymbol;
|
|
231
|
-
valueSymbolName =
|
|
225
|
+
valueSymbolName = this.checker.getBaseTypeOfLiteralType(type).getSymbol()?.getName() || '';
|
|
232
226
|
}
|
|
233
227
|
const isIntersection = type.isIntersection();
|
|
234
228
|
const intersectionTypes = isIntersection && type.types || [];
|
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
4
4
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
5
5
|
exports.__esModule = true;
|
|
6
6
|
exports.BuildUtil = void 0;
|
|
7
|
-
var _interopRequireWildcard2 = _interopRequireDefault(require("@babel/runtime/helpers/interopRequireWildcard"));
|
|
8
7
|
var _nodePath = _interopRequireDefault(require("node:path"));
|
|
9
8
|
var _compressing = _interopRequireDefault(require("compressing"));
|
|
10
|
-
var esbuild =
|
|
9
|
+
var esbuild = _interopRequireWildcard(require("esbuild"));
|
|
11
10
|
var _execa = _interopRequireDefault(require("execa"));
|
|
12
11
|
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
13
12
|
var _globby = _interopRequireDefault(require("globby"));
|
|
14
13
|
var _vtils = require("vtils");
|
|
15
14
|
class BuildUtil {
|
|
16
15
|
static async build(options) {
|
|
17
|
-
var _options$minify;
|
|
18
16
|
const mainFile = _nodePath.default.join(options.cwd, 'src/main.ts');
|
|
19
17
|
const pkgFile = _nodePath.default.join(options.cwd, 'package.json');
|
|
20
18
|
const pkgContent = await _fsExtra.default.readJson(pkgFile);
|
|
@@ -64,7 +62,7 @@ class BuildUtil {
|
|
|
64
62
|
// @ts-ignore
|
|
65
63
|
const {
|
|
66
64
|
default: macrosPlugin
|
|
67
|
-
} = await
|
|
65
|
+
} = await import('unplugin-macros/esbuild');
|
|
68
66
|
await esbuild.build({
|
|
69
67
|
entryPoints: [mainFile],
|
|
70
68
|
bundle: true,
|
|
@@ -77,7 +75,7 @@ class BuildUtil {
|
|
|
77
75
|
mainFields: ['module', 'main'],
|
|
78
76
|
target: `node${process.version.slice(1)}`,
|
|
79
77
|
external: external,
|
|
80
|
-
minify:
|
|
78
|
+
minify: options.minify ?? true,
|
|
81
79
|
format: 'cjs',
|
|
82
80
|
sourcemap: false,
|
|
83
81
|
treeShaking: true,
|
package/lib/_cjs/cli/env_util.js
CHANGED
|
@@ -12,11 +12,10 @@ class EnvUtil {
|
|
|
12
12
|
const envs = [];
|
|
13
13
|
const envObj = (0, _yaml.parse)(src);
|
|
14
14
|
Object.keys(envObj).forEach(key => {
|
|
15
|
-
var _src$match;
|
|
16
15
|
envs.push({
|
|
17
16
|
key: key,
|
|
18
17
|
value: envObj[key],
|
|
19
|
-
comment:
|
|
18
|
+
comment: src.match(new RegExp(`((#\\s*(.+?)\\s*[\\r\\n]+)+)\\s*${(0, _vtils.escapeRegExp)(key)}:`))?.[1].split(/(\r\n){2,}|\r{2,}|\n{2,}/g).pop()?.replace(/^#/gm, '').trim() || ''
|
|
20
19
|
});
|
|
21
20
|
});
|
|
22
21
|
return envs;
|
|
@@ -42,10 +42,10 @@ function defineSliceTask(options) {
|
|
|
42
42
|
});
|
|
43
43
|
const addAction = async (data, addOptions) => {
|
|
44
44
|
const redisKeyPrefix = `${_x.x.appId}_batch_task_${options.name}`;
|
|
45
|
-
const key =
|
|
46
|
-
const duration =
|
|
47
|
-
const threshold =
|
|
48
|
-
const thresholdTimeout =
|
|
45
|
+
const key = addOptions?.key || '';
|
|
46
|
+
const duration = addOptions?.duration != null ? (0, _vtils.ms)(addOptions.duration) : typeof options.duration === 'function' ? (0, _vtils.ms)(options.duration(key)) : options.duration && (0, _vtils.ms)(options.duration);
|
|
47
|
+
const threshold = addOptions?.threshold || typeof options.threshold && (typeof options.threshold === 'function' ? options.threshold(key) : options.threshold);
|
|
48
|
+
const thresholdTimeout = addOptions?.thresholdTimeout != null ? (0, _vtils.ms)(addOptions.thresholdTimeout) : typeof options.thresholdTimeout === 'function' ? (0, _vtils.ms)(options.thresholdTimeout(key)) : options.thresholdTimeout && (0, _vtils.ms)(options.thresholdTimeout);
|
|
49
49
|
(0, _assert.default)(duration != null || threshold != null, '参数 threshold 和 duration 必须至少设置 1 个');
|
|
50
50
|
const redisKey = !key ? redisKeyPrefix : `${redisKeyPrefix}_${key}`;
|
|
51
51
|
const res = await _x.x.redis.multi([['llen', redisKey], ['lpush', redisKey, JSON.stringify(data)]]).exec();
|
|
@@ -71,7 +71,7 @@ function defineSliceTask(options) {
|
|
|
71
71
|
|
|
72
72
|
// 到达阈值,立即发送
|
|
73
73
|
if (count === threshold) {
|
|
74
|
-
await
|
|
74
|
+
await prevJob?.remove();
|
|
75
75
|
await task.add({
|
|
76
76
|
key: key,
|
|
77
77
|
redisKey: redisKey
|
package/lib/_cjs/core/server.js
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
4
|
exports.__esModule = true;
|
|
5
5
|
exports.Server = void 0;
|
|
6
|
-
var _interopRequireWildcard2 = _interopRequireDefault(require("@babel/runtime/helpers/interopRequireWildcard"));
|
|
7
6
|
var _nodeProcess = _interopRequireDefault(require("node:process"));
|
|
8
7
|
var _fastify = _interopRequireDefault(require("fastify"));
|
|
9
8
|
var _vtils = require("vtils");
|
|
@@ -33,8 +32,7 @@ class Server {
|
|
|
33
32
|
await this.applyAutoClose();
|
|
34
33
|
}
|
|
35
34
|
async close() {
|
|
36
|
-
|
|
37
|
-
await ((_this$fastify = this.fastify) == null ? void 0 : _this$fastify.close());
|
|
35
|
+
await this.fastify?.close();
|
|
38
36
|
}
|
|
39
37
|
async prepareFastify() {
|
|
40
38
|
this.fastify = await (0, _fastify.default)({
|
|
@@ -59,12 +57,12 @@ class Server {
|
|
|
59
57
|
// @ts-ignore
|
|
60
58
|
const {
|
|
61
59
|
routes
|
|
62
|
-
} = await
|
|
60
|
+
} = await require('.x/routes');
|
|
63
61
|
this.routes = routes;
|
|
64
62
|
}
|
|
65
63
|
async applyHooks() {
|
|
66
64
|
// @ts-ignore
|
|
67
|
-
await
|
|
65
|
+
await require('.x/hooks');
|
|
68
66
|
}
|
|
69
67
|
applyServices() {
|
|
70
68
|
_x2.x.register(...(this.options.services || []));
|
|
@@ -83,8 +81,9 @@ class Server {
|
|
|
83
81
|
const handlerOptions = item.handler.options;
|
|
84
82
|
const handlerMethod = handlerOptions.requestMethod || 'POST';
|
|
85
83
|
const isWS = handlerMethod === 'WS';
|
|
86
|
-
const url = `${appUrl}${
|
|
87
|
-
|
|
84
|
+
const url = `${appUrl}${
|
|
85
|
+
// 结构:/test/sss?x=2
|
|
86
|
+
path ?? (isWS ? res.url : req.url)}`;
|
|
88
87
|
if (isWS) {
|
|
89
88
|
await item.handler.handle(undefined, {
|
|
90
89
|
traceId: (0, _x.cuid2)(),
|
|
@@ -212,7 +211,7 @@ class Server {
|
|
|
212
211
|
}
|
|
213
212
|
async startCrons() {
|
|
214
213
|
// @ts-ignore
|
|
215
|
-
await
|
|
214
|
+
await require('.x/crons');
|
|
216
215
|
}
|
|
217
216
|
async applyAutoClose() {
|
|
218
217
|
_x2.x.dispose.add(() => this.close());
|
|
@@ -16,12 +16,11 @@ class FileParserPlugin {
|
|
|
16
16
|
this.options = options;
|
|
17
17
|
}
|
|
18
18
|
register(fastify) {
|
|
19
|
-
var _this$options;
|
|
20
19
|
fastify.register(_multipart.default, {
|
|
21
20
|
...this.options,
|
|
22
21
|
limits: {
|
|
23
22
|
fileSize: (0, _vtils.bytes)(1, 'MB'),
|
|
24
|
-
...
|
|
23
|
+
...this.options?.limits
|
|
25
24
|
}
|
|
26
25
|
});
|
|
27
26
|
}
|
|
@@ -23,7 +23,6 @@ class CaptchaService {
|
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
25
|
async generate(payload) {
|
|
26
|
-
var _payload$retryCount;
|
|
27
26
|
const chars = this.charsetMap[payload.charset];
|
|
28
27
|
let code = '';
|
|
29
28
|
for (let i = 0; i < payload.size; i++) {
|
|
@@ -32,7 +31,7 @@ class CaptchaService {
|
|
|
32
31
|
const token = await _x.x.cache.save({
|
|
33
32
|
code: code,
|
|
34
33
|
scene: payload.scene,
|
|
35
|
-
retryCount:
|
|
34
|
+
retryCount: payload.retryCount ?? 0,
|
|
36
35
|
extra: payload.extra
|
|
37
36
|
}, payload.ttl);
|
|
38
37
|
return {
|
|
@@ -23,9 +23,9 @@ class DbValueService {
|
|
|
23
23
|
const text = !value || !Array.isArray(value) ? undefined : value.filter(v => v != null && v !== '').join(this.separator);
|
|
24
24
|
return !text || !this.affix ? text : `${this.affix}${text}${this.affix}`;
|
|
25
25
|
};
|
|
26
|
-
this.separator =
|
|
27
|
-
this.affix =
|
|
28
|
-
this.number = !!
|
|
26
|
+
this.separator = options?.separator || ',';
|
|
27
|
+
this.affix = options?.affix || '';
|
|
28
|
+
this.number = !!options?.number;
|
|
29
29
|
}
|
|
30
30
|
};
|
|
31
31
|
this.JsonArray = class {
|
|
@@ -6,11 +6,10 @@ exports.DisposeService = void 0;
|
|
|
6
6
|
var _exitHook = _interopRequireDefault(require("exit-hook"));
|
|
7
7
|
class DisposeService {
|
|
8
8
|
constructor(options) {
|
|
9
|
-
var _this$options;
|
|
10
9
|
this.options = options;
|
|
11
10
|
this.serviceName = 'dispose';
|
|
12
11
|
this.disposes = [];
|
|
13
|
-
if (
|
|
12
|
+
if (this.options?.disposeOnExit) {
|
|
14
13
|
(0, _exitHook.default)(() => this.dispose());
|
|
15
14
|
}
|
|
16
15
|
}
|
package/lib/_cjs/services/jwt.js
CHANGED
|
@@ -29,7 +29,6 @@ class JwtService {
|
|
|
29
29
|
return token;
|
|
30
30
|
}
|
|
31
31
|
async verify(token) {
|
|
32
|
-
var _this$options$onVerif, _this$options;
|
|
33
32
|
const data = await new Promise((resolve, reject) => {
|
|
34
33
|
if (this.cache && this.cache.has(token)) {
|
|
35
34
|
resolve(this.cache.get(token));
|
|
@@ -50,7 +49,7 @@ class JwtService {
|
|
|
50
49
|
});
|
|
51
50
|
}
|
|
52
51
|
});
|
|
53
|
-
await
|
|
52
|
+
await this.options.onVerify?.(data);
|
|
54
53
|
return data;
|
|
55
54
|
}
|
|
56
55
|
async verifyFromHttpHeaders(headers) {
|
package/lib/_cjs/services/pay.js
CHANGED
|
@@ -86,8 +86,7 @@ class PayService {
|
|
|
86
86
|
// 支付宝
|
|
87
87
|
// https://opendocs.alipay.com/open/270/105902
|
|
88
88
|
if (data.passback_params === 'alipay') {
|
|
89
|
-
|
|
90
|
-
if (!((_this$alipaySdk = this.alipaySdk) != null && _this$alipaySdk.checkNotifySign(data))) {
|
|
89
|
+
if (!this.alipaySdk?.checkNotifySign(data)) {
|
|
91
90
|
return false;
|
|
92
91
|
}
|
|
93
92
|
return {
|
|
@@ -47,8 +47,7 @@ class RateLimitService {
|
|
|
47
47
|
async limitByManyCountOrFail(options) {
|
|
48
48
|
const pass = await this.limitByManyCount(options);
|
|
49
49
|
if (pass !== true) {
|
|
50
|
-
|
|
51
|
-
throw new _http_error.HttpError.Forbidden((_options$limits$pass$ = options.limits[pass].message) != null ? _options$limits$pass$ : options.message);
|
|
50
|
+
throw new _http_error.HttpError.Forbidden(options.limits[pass].message ?? options.message);
|
|
52
51
|
}
|
|
53
52
|
}
|
|
54
53
|
}
|
package/lib/cli/api_generator.js
CHANGED
|
@@ -42,7 +42,6 @@ export class ApiGenerator {
|
|
|
42
42
|
const categorySymbols = checker.getExportsOfModule(moduleSymbol);
|
|
43
43
|
const apiData = [];
|
|
44
44
|
for (const categorySymbol of categorySymbols) {
|
|
45
|
-
var _ref, _categoryUrlMatch$;
|
|
46
45
|
// 分类的类型
|
|
47
46
|
const categoryType = checker.getTypeOfSymbol(categorySymbol);
|
|
48
47
|
|
|
@@ -57,7 +56,7 @@ export class ApiGenerator {
|
|
|
57
56
|
|
|
58
57
|
// 分类 URL
|
|
59
58
|
const categoryUrlMatch = categorySourceFilePath.match(this.categoryUrlRe);
|
|
60
|
-
let categoryUrl =
|
|
59
|
+
let categoryUrl = categoryUrlMatch[1] ?? categoryUrlMatch[2] ?? '';
|
|
61
60
|
categoryUrl = categoryUrl === '' ? '/' : `/${categoryUrl}/`;
|
|
62
61
|
for (const handlerSymbol of handlerSymbols) {
|
|
63
62
|
// 处理器路径
|
|
@@ -73,10 +72,7 @@ export class ApiGenerator {
|
|
|
73
72
|
// defineHandler({})
|
|
74
73
|
ts.isObjectLiteralExpression(handlerNode.initializer.arguments[0])) {
|
|
75
74
|
const props = handlerNode.initializer.arguments[0].properties;
|
|
76
|
-
const requestPathNode = props.find(item =>
|
|
77
|
-
var _item$name;
|
|
78
|
-
return ((_item$name = item.name) == null ? void 0 : _item$name.getText()) === 'requestPath';
|
|
79
|
-
});
|
|
75
|
+
const requestPathNode = props.find(item => item.name?.getText() === 'requestPath');
|
|
80
76
|
if (requestPathNode &&
|
|
81
77
|
// requestPath: ''
|
|
82
78
|
ts.isPropertyAssignment(requestPathNode)) {
|
|
@@ -167,11 +163,10 @@ export class ApiGenerator {
|
|
|
167
163
|
type,
|
|
168
164
|
keySymbol = type.symbol || type.aliasSymbol
|
|
169
165
|
}) {
|
|
170
|
-
var _valueSymbol;
|
|
171
166
|
const hasTypeFlag = (flag, _type = type) => (_type.flags & flag) === flag;
|
|
172
167
|
let valueSymbol = type.symbol || type.aliasSymbol;
|
|
173
|
-
const keySymbolName =
|
|
174
|
-
let valueSymbolName =
|
|
168
|
+
const keySymbolName = keySymbol?.getName() || '';
|
|
169
|
+
let valueSymbolName = valueSymbol?.getName() || '';
|
|
175
170
|
const comment = this.getComment(keySymbol);
|
|
176
171
|
let isRequired = keySymbol ? !(keySymbol.getFlags() & ts.SymbolFlags.Optional) : false;
|
|
177
172
|
|
|
@@ -217,13 +212,12 @@ export class ApiGenerator {
|
|
|
217
212
|
const unionTypes = rawUnionTypes.filter(item => !hasTypeFlag(ts.TypeFlags.Null, item) && !hasTypeFlag(ts.TypeFlags.Undefined, item));
|
|
218
213
|
const isUnion = !!unionTypes.length;
|
|
219
214
|
if (isUnion) {
|
|
220
|
-
var _this$checker$getBase;
|
|
221
215
|
if (unionTypes.length !== rawUnionTypes.length) {
|
|
222
216
|
isRequired = false;
|
|
223
217
|
}
|
|
224
218
|
type = unionTypes[0];
|
|
225
219
|
valueSymbol = type.symbol || type.aliasSymbol;
|
|
226
|
-
valueSymbolName =
|
|
220
|
+
valueSymbolName = this.checker.getBaseTypeOfLiteralType(type).getSymbol()?.getName() || '';
|
|
227
221
|
}
|
|
228
222
|
const isIntersection = type.isIntersection();
|
|
229
223
|
const intersectionTypes = isIntersection && type.types || [];
|
package/lib/cli/build_util.js
CHANGED
|
@@ -7,7 +7,6 @@ import globby from 'globby';
|
|
|
7
7
|
import { dedent, uniq } from 'vtils';
|
|
8
8
|
export class BuildUtil {
|
|
9
9
|
static async build(options) {
|
|
10
|
-
var _options$minify;
|
|
11
10
|
const mainFile = path.join(options.cwd, 'src/main.ts');
|
|
12
11
|
const pkgFile = path.join(options.cwd, 'package.json');
|
|
13
12
|
const pkgContent = await fs.readJson(pkgFile);
|
|
@@ -70,7 +69,7 @@ export class BuildUtil {
|
|
|
70
69
|
mainFields: ['module', 'main'],
|
|
71
70
|
target: `node${process.version.slice(1)}`,
|
|
72
71
|
external: external,
|
|
73
|
-
minify:
|
|
72
|
+
minify: options.minify ?? true,
|
|
74
73
|
format: 'cjs',
|
|
75
74
|
sourcemap: false,
|
|
76
75
|
treeShaking: true,
|
package/lib/cli/env_util.js
CHANGED
|
@@ -7,11 +7,10 @@ export class EnvUtil {
|
|
|
7
7
|
const envs = [];
|
|
8
8
|
const envObj = yamlParse(src);
|
|
9
9
|
Object.keys(envObj).forEach(key => {
|
|
10
|
-
var _src$match;
|
|
11
10
|
envs.push({
|
|
12
11
|
key: key,
|
|
13
12
|
value: envObj[key],
|
|
14
|
-
comment:
|
|
13
|
+
comment: src.match(new RegExp(`((#\\s*(.+?)\\s*[\\r\\n]+)+)\\s*${escapeRegExp(key)}:`))?.[1].split(/(\r\n){2,}|\r{2,}|\n{2,}/g).pop()?.replace(/^#/gm, '').trim() || ''
|
|
15
14
|
});
|
|
16
15
|
});
|
|
17
16
|
return envs;
|
package/lib/core/define_task.js
CHANGED
|
@@ -36,10 +36,10 @@ export function defineSliceTask(options) {
|
|
|
36
36
|
});
|
|
37
37
|
const addAction = async (data, addOptions) => {
|
|
38
38
|
const redisKeyPrefix = `${x.appId}_batch_task_${options.name}`;
|
|
39
|
-
const key =
|
|
40
|
-
const duration =
|
|
41
|
-
const threshold =
|
|
42
|
-
const thresholdTimeout =
|
|
39
|
+
const key = addOptions?.key || '';
|
|
40
|
+
const duration = addOptions?.duration != null ? ms(addOptions.duration) : typeof options.duration === 'function' ? ms(options.duration(key)) : options.duration && ms(options.duration);
|
|
41
|
+
const threshold = addOptions?.threshold || typeof options.threshold && (typeof options.threshold === 'function' ? options.threshold(key) : options.threshold);
|
|
42
|
+
const thresholdTimeout = addOptions?.thresholdTimeout != null ? ms(addOptions.thresholdTimeout) : typeof options.thresholdTimeout === 'function' ? ms(options.thresholdTimeout(key)) : options.thresholdTimeout && ms(options.thresholdTimeout);
|
|
43
43
|
assert(duration != null || threshold != null, '参数 threshold 和 duration 必须至少设置 1 个');
|
|
44
44
|
const redisKey = !key ? redisKeyPrefix : `${redisKeyPrefix}_${key}`;
|
|
45
45
|
const res = await x.redis.multi([['llen', redisKey], ['lpush', redisKey, JSON.stringify(data)]]).exec();
|
|
@@ -65,7 +65,7 @@ export function defineSliceTask(options) {
|
|
|
65
65
|
|
|
66
66
|
// 到达阈值,立即发送
|
|
67
67
|
if (count === threshold) {
|
|
68
|
-
await
|
|
68
|
+
await prevJob?.remove();
|
|
69
69
|
await task.add({
|
|
70
70
|
key: key,
|
|
71
71
|
redisKey: redisKey
|
package/lib/core/server.js
CHANGED
|
@@ -27,8 +27,7 @@ export class Server {
|
|
|
27
27
|
await this.applyAutoClose();
|
|
28
28
|
}
|
|
29
29
|
async close() {
|
|
30
|
-
|
|
31
|
-
await ((_this$fastify = this.fastify) == null ? void 0 : _this$fastify.close());
|
|
30
|
+
await this.fastify?.close();
|
|
32
31
|
}
|
|
33
32
|
async prepareFastify() {
|
|
34
33
|
this.fastify = await Fastify({
|
|
@@ -53,12 +52,12 @@ export class Server {
|
|
|
53
52
|
// @ts-ignore
|
|
54
53
|
const {
|
|
55
54
|
routes
|
|
56
|
-
} = await
|
|
55
|
+
} = await require('.x/routes');
|
|
57
56
|
this.routes = routes;
|
|
58
57
|
}
|
|
59
58
|
async applyHooks() {
|
|
60
59
|
// @ts-ignore
|
|
61
|
-
await
|
|
60
|
+
await require('.x/hooks');
|
|
62
61
|
}
|
|
63
62
|
applyServices() {
|
|
64
63
|
x.register(...(this.options.services || []));
|
|
@@ -77,8 +76,9 @@ export class Server {
|
|
|
77
76
|
const handlerOptions = item.handler.options;
|
|
78
77
|
const handlerMethod = handlerOptions.requestMethod || 'POST';
|
|
79
78
|
const isWS = handlerMethod === 'WS';
|
|
80
|
-
const url = `${appUrl}${
|
|
81
|
-
|
|
79
|
+
const url = `${appUrl}${
|
|
80
|
+
// 结构:/test/sss?x=2
|
|
81
|
+
path ?? (isWS ? res.url : req.url)}`;
|
|
82
82
|
if (isWS) {
|
|
83
83
|
await item.handler.handle(undefined, {
|
|
84
84
|
traceId: cuid2(),
|
|
@@ -206,7 +206,7 @@ export class Server {
|
|
|
206
206
|
}
|
|
207
207
|
async startCrons() {
|
|
208
208
|
// @ts-ignore
|
|
209
|
-
await
|
|
209
|
+
await require('.x/crons');
|
|
210
210
|
}
|
|
211
211
|
async applyAutoClose() {
|
|
212
212
|
x.dispose.add(() => this.close());
|
package/lib/plugins/cookie.d.ts
CHANGED
|
@@ -8,6 +8,6 @@ export interface CookiePluginOptions extends FastifyCookieOptions {
|
|
|
8
8
|
*/
|
|
9
9
|
export declare class CookiePlugin implements BasePlugin {
|
|
10
10
|
private options?;
|
|
11
|
-
constructor(options?: CookiePluginOptions);
|
|
11
|
+
constructor(options?: CookiePluginOptions | undefined);
|
|
12
12
|
register(fastify: FastifyInstance<any, any, any, any, any>): void;
|
|
13
13
|
}
|
|
@@ -11,6 +11,6 @@ export interface FileParserPluginOptions extends FastifyMultipartOptions {
|
|
|
11
11
|
*/
|
|
12
12
|
export declare class FileParserPlugin implements BasePlugin {
|
|
13
13
|
private options?;
|
|
14
|
-
constructor(options?: FileParserPluginOptions);
|
|
14
|
+
constructor(options?: FileParserPluginOptions | undefined);
|
|
15
15
|
register(fastify: FastifyInstance<any, any, any, any, any>): void;
|
|
16
16
|
}
|
|
@@ -11,12 +11,11 @@ export class FileParserPlugin {
|
|
|
11
11
|
this.options = options;
|
|
12
12
|
}
|
|
13
13
|
register(fastify) {
|
|
14
|
-
var _this$options;
|
|
15
14
|
fastify.register(FastifyMultipart, {
|
|
16
15
|
...this.options,
|
|
17
16
|
limits: {
|
|
18
17
|
fileSize: bytes(1, 'MB'),
|
|
19
|
-
...
|
|
18
|
+
...this.options?.limits
|
|
20
19
|
}
|
|
21
20
|
});
|
|
22
21
|
}
|
|
@@ -8,6 +8,6 @@ export interface FormBodyParserPluginOptions extends FastifyFormbodyOptions {
|
|
|
8
8
|
*/
|
|
9
9
|
export declare class FormBodyParserPlugin implements BasePlugin {
|
|
10
10
|
private options?;
|
|
11
|
-
constructor(options?: FormBodyParserPluginOptions);
|
|
11
|
+
constructor(options?: FormBodyParserPluginOptions | undefined);
|
|
12
12
|
register(fastify: FastifyInstance<any, any, any, any, any>): void;
|
|
13
13
|
}
|
|
@@ -8,6 +8,6 @@ export interface WsParserPluginOptions extends WebsocketPluginOptions {
|
|
|
8
8
|
*/
|
|
9
9
|
export declare class WsParserPlugin implements BasePlugin {
|
|
10
10
|
private options?;
|
|
11
|
-
constructor(options?: WsParserPluginOptions);
|
|
11
|
+
constructor(options?: WsParserPluginOptions | undefined);
|
|
12
12
|
register(fastify: FastifyInstance<any, any, any, any, any>): void;
|
|
13
13
|
}
|
|
@@ -14,6 +14,6 @@ export interface XmlParserPluginOptions extends Partial<X2jOptions> {
|
|
|
14
14
|
*/
|
|
15
15
|
export declare class XmlParserPlugin implements BasePlugin {
|
|
16
16
|
private options?;
|
|
17
|
-
constructor(options?: XmlParserPluginOptions);
|
|
17
|
+
constructor(options?: XmlParserPluginOptions | undefined);
|
|
18
18
|
register(fastify: FastifyInstance<any, any, any, any, any>): void;
|
|
19
19
|
}
|
package/lib/services/captcha.js
CHANGED
|
@@ -18,7 +18,6 @@ export class CaptchaService {
|
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
20
|
async generate(payload) {
|
|
21
|
-
var _payload$retryCount;
|
|
22
21
|
const chars = this.charsetMap[payload.charset];
|
|
23
22
|
let code = '';
|
|
24
23
|
for (let i = 0; i < payload.size; i++) {
|
|
@@ -27,7 +26,7 @@ export class CaptchaService {
|
|
|
27
26
|
const token = await x.cache.save({
|
|
28
27
|
code: code,
|
|
29
28
|
scene: payload.scene,
|
|
30
|
-
retryCount:
|
|
29
|
+
retryCount: payload.retryCount ?? 0,
|
|
31
30
|
extra: payload.extra
|
|
32
31
|
}, payload.ttl);
|
|
33
32
|
return {
|
package/lib/services/db_value.js
CHANGED
|
@@ -19,9 +19,9 @@ export class DbValueService {
|
|
|
19
19
|
const text = !value || !Array.isArray(value) ? undefined : value.filter(v => v != null && v !== '').join(this.separator);
|
|
20
20
|
return !text || !this.affix ? text : `${this.affix}${text}${this.affix}`;
|
|
21
21
|
};
|
|
22
|
-
this.separator =
|
|
23
|
-
this.affix =
|
|
24
|
-
this.number = !!
|
|
22
|
+
this.separator = options?.separator || ',';
|
|
23
|
+
this.affix = options?.affix || '';
|
|
24
|
+
this.number = !!options?.number;
|
|
25
25
|
}
|
|
26
26
|
};
|
|
27
27
|
this.JsonArray = class {
|
|
@@ -5,7 +5,7 @@ export interface DisposeServiceOptions {
|
|
|
5
5
|
export declare class DisposeService implements BaseService {
|
|
6
6
|
private options?;
|
|
7
7
|
serviceName: string;
|
|
8
|
-
constructor(options?: DisposeServiceOptions);
|
|
8
|
+
constructor(options?: DisposeServiceOptions | undefined);
|
|
9
9
|
private disposes;
|
|
10
10
|
add(fn: () => any): void;
|
|
11
11
|
dispose(): Promise<any[]>;
|
package/lib/services/dispose.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import onExit from 'exit-hook';
|
|
2
2
|
export class DisposeService {
|
|
3
3
|
constructor(options) {
|
|
4
|
-
var _this$options;
|
|
5
4
|
this.options = options;
|
|
6
5
|
this.serviceName = 'dispose';
|
|
7
6
|
this.disposes = [];
|
|
8
|
-
if (
|
|
7
|
+
if (this.options?.disposeOnExit) {
|
|
9
8
|
onExit(() => this.dispose());
|
|
10
9
|
}
|
|
11
10
|
}
|
package/lib/services/jwt.js
CHANGED
|
@@ -24,7 +24,6 @@ export class JwtService {
|
|
|
24
24
|
return token;
|
|
25
25
|
}
|
|
26
26
|
async verify(token) {
|
|
27
|
-
var _this$options$onVerif, _this$options;
|
|
28
27
|
const data = await new Promise((resolve, reject) => {
|
|
29
28
|
if (this.cache && this.cache.has(token)) {
|
|
30
29
|
resolve(this.cache.get(token));
|
|
@@ -45,7 +44,7 @@ export class JwtService {
|
|
|
45
44
|
});
|
|
46
45
|
}
|
|
47
46
|
});
|
|
48
|
-
await
|
|
47
|
+
await this.options.onVerify?.(data);
|
|
49
48
|
return data;
|
|
50
49
|
}
|
|
51
50
|
async verifyFromHttpHeaders(headers) {
|
package/lib/services/pay.js
CHANGED
|
@@ -81,8 +81,7 @@ export class PayService {
|
|
|
81
81
|
// 支付宝
|
|
82
82
|
// https://opendocs.alipay.com/open/270/105902
|
|
83
83
|
if (data.passback_params === 'alipay') {
|
|
84
|
-
|
|
85
|
-
if (!((_this$alipaySdk = this.alipaySdk) != null && _this$alipaySdk.checkNotifySign(data))) {
|
|
84
|
+
if (!this.alipaySdk?.checkNotifySign(data)) {
|
|
86
85
|
return false;
|
|
87
86
|
}
|
|
88
87
|
return {
|
|
@@ -43,8 +43,7 @@ export class RateLimitService {
|
|
|
43
43
|
async limitByManyCountOrFail(options) {
|
|
44
44
|
const pass = await this.limitByManyCount(options);
|
|
45
45
|
if (pass !== true) {
|
|
46
|
-
|
|
47
|
-
throw new HttpError.Forbidden((_options$limits$pass$ = options.limits[pass].message) != null ? _options$limits$pass$ : options.message);
|
|
46
|
+
throw new HttpError.Forbidden(options.limits[pass].message ?? options.message);
|
|
48
47
|
}
|
|
49
48
|
}
|
|
50
49
|
}
|