@jayfong/x-server 2.62.0 → 2.62.2

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.
@@ -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 = (_ref = (_categoryUrlMatch$ = categoryUrlMatch[1]) != null ? _categoryUrlMatch$ : categoryUrlMatch[2]) != null ? _ref : '';
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 = (keySymbol == null ? void 0 : keySymbol.getName()) || '';
179
- let valueSymbolName = ((_valueSymbol = valueSymbol) == null ? void 0 : _valueSymbol.getName()) || '';
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 = ((_this$checker$getBase = this.checker.getBaseTypeOfLiteralType(type).getSymbol()) == null ? void 0 : _this$checker$getBase.getName()) || '';
225
+ valueSymbolName = this.checker.getBaseTypeOfLiteralType(type).getSymbol()?.getName() || '';
232
226
  }
233
227
  const isIntersection = type.isIntersection();
234
228
  const intersectionTypes = isIntersection && type.types || [];
@@ -10,11 +10,9 @@ var esbuild = _interopRequireWildcard(require("esbuild"));
10
10
  var _execa = _interopRequireDefault(require("execa"));
11
11
  var _fsExtra = _interopRequireDefault(require("fs-extra"));
12
12
  var _globby = _interopRequireDefault(require("globby"));
13
- var _esbuild2 = _interopRequireDefault(require("unplugin-macros/esbuild"));
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);
@@ -61,6 +59,10 @@ class BuildUtil {
61
59
 
62
60
  // 构建
63
61
  await _fsExtra.default.emptyDir(distDir);
62
+ // @ts-ignore
63
+ const {
64
+ default: macrosPlugin
65
+ } = await import('unplugin-macros/esbuild');
64
66
  await esbuild.build({
65
67
  entryPoints: [mainFile],
66
68
  bundle: true,
@@ -73,7 +75,7 @@ class BuildUtil {
73
75
  mainFields: ['module', 'main'],
74
76
  target: `node${process.version.slice(1)}`,
75
77
  external: external,
76
- minify: (_options$minify = options.minify) != null ? _options$minify : true,
78
+ minify: options.minify ?? true,
77
79
  format: 'cjs',
78
80
  sourcemap: false,
79
81
  treeShaking: true,
@@ -128,7 +130,7 @@ class BuildUtil {
128
130
  }
129
131
  },
130
132
  // @ts-ignore
131
- (0, _esbuild2.default)()],
133
+ macrosPlugin()],
132
134
  loader: {
133
135
  // 兼容 x-text-render 在服务端使用
134
136
  // dev 时用 css_register 兼容
@@ -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: ((_src$match = src.match(new RegExp(`((#\\s*(.+?)\\s*[\\r\\n]+)+)\\s*${(0, _vtils.escapeRegExp)(key)}:`))) == null || (_src$match = _src$match[1].split(/(\r\n){2,}|\r{2,}|\n{2,}/g).pop()) == null ? void 0 : _src$match.replace(/^#/gm, '').trim()) || ''
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 = (addOptions == null ? void 0 : addOptions.key) || '';
46
- const duration = (addOptions == null ? void 0 : 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 == null ? void 0 : addOptions.threshold) || typeof options.threshold && (typeof options.threshold === 'function' ? options.threshold(key) : options.threshold);
48
- const thresholdTimeout = (addOptions == null ? void 0 : 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);
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 (prevJob == null ? void 0 : prevJob.remove());
74
+ await prevJob?.remove();
75
75
  await task.add({
76
76
  key: key,
77
77
  redisKey: redisKey
@@ -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
- var _this$fastify;
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 Promise.resolve().then(() => (0, _interopRequireWildcard2.default)(require('.x/routes')));
60
+ } = await import('.x/routes');
63
61
  this.routes = routes;
64
62
  }
65
63
  async applyHooks() {
66
64
  // @ts-ignore
67
- await Promise.resolve().then(() => (0, _interopRequireWildcard2.default)(require('.x/hooks')));
65
+ await import('.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}${// 结构:/test/sss?x=2
87
- path != null ? path : isWS ? res.url : req.url}`;
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 Promise.resolve().then(() => (0, _interopRequireWildcard2.default)(require('.x/crons')));
214
+ await import('.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
- ...((_this$options = this.options) == null ? void 0 : _this$options.limits)
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: (_payload$retryCount = payload.retryCount) != null ? _payload$retryCount : 0,
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 = (options == null ? void 0 : options.separator) || ',';
27
- this.affix = (options == null ? void 0 : options.affix) || '';
28
- this.number = !!(options != null && options.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 ((_this$options = this.options) != null && _this$options.disposeOnExit) {
12
+ if (this.options?.disposeOnExit) {
14
13
  (0, _exitHook.default)(() => this.dispose());
15
14
  }
16
15
  }
@@ -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 ((_this$options$onVerif = (_this$options = this.options).onVerify) == null ? void 0 : _this$options$onVerif.call(_this$options, data));
52
+ await this.options.onVerify?.(data);
54
53
  return data;
55
54
  }
56
55
  async verifyFromHttpHeaders(headers) {
@@ -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
- var _this$alipaySdk;
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
- var _options$limits$pass$;
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
  }
@@ -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 = (_ref = (_categoryUrlMatch$ = categoryUrlMatch[1]) != null ? _categoryUrlMatch$ : categoryUrlMatch[2]) != null ? _ref : '';
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 = (keySymbol == null ? void 0 : keySymbol.getName()) || '';
174
- let valueSymbolName = ((_valueSymbol = valueSymbol) == null ? void 0 : _valueSymbol.getName()) || '';
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 = ((_this$checker$getBase = this.checker.getBaseTypeOfLiteralType(type).getSymbol()) == null ? void 0 : _this$checker$getBase.getName()) || '';
220
+ valueSymbolName = this.checker.getBaseTypeOfLiteralType(type).getSymbol()?.getName() || '';
227
221
  }
228
222
  const isIntersection = type.isIntersection();
229
223
  const intersectionTypes = isIntersection && type.types || [];
@@ -4,11 +4,9 @@ import * as esbuild from 'esbuild';
4
4
  import exec from 'execa';
5
5
  import fs from 'fs-extra';
6
6
  import globby from 'globby';
7
- import macrosPlugin from 'unplugin-macros/esbuild';
8
7
  import { dedent, uniq } from 'vtils';
9
8
  export class BuildUtil {
10
9
  static async build(options) {
11
- var _options$minify;
12
10
  const mainFile = path.join(options.cwd, 'src/main.ts');
13
11
  const pkgFile = path.join(options.cwd, 'package.json');
14
12
  const pkgContent = await fs.readJson(pkgFile);
@@ -55,6 +53,10 @@ export class BuildUtil {
55
53
 
56
54
  // 构建
57
55
  await fs.emptyDir(distDir);
56
+ // @ts-ignore
57
+ const {
58
+ default: macrosPlugin
59
+ } = await import('unplugin-macros/esbuild');
58
60
  await esbuild.build({
59
61
  entryPoints: [mainFile],
60
62
  bundle: true,
@@ -67,7 +69,7 @@ export class BuildUtil {
67
69
  mainFields: ['module', 'main'],
68
70
  target: `node${process.version.slice(1)}`,
69
71
  external: external,
70
- minify: (_options$minify = options.minify) != null ? _options$minify : true,
72
+ minify: options.minify ?? true,
71
73
  format: 'cjs',
72
74
  sourcemap: false,
73
75
  treeShaking: true,
@@ -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: ((_src$match = src.match(new RegExp(`((#\\s*(.+?)\\s*[\\r\\n]+)+)\\s*${escapeRegExp(key)}:`))) == null || (_src$match = _src$match[1].split(/(\r\n){2,}|\r{2,}|\n{2,}/g).pop()) == null ? void 0 : _src$match.replace(/^#/gm, '').trim()) || ''
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;
@@ -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 = (addOptions == null ? void 0 : addOptions.key) || '';
40
- const duration = (addOptions == null ? void 0 : addOptions.duration) != null ? ms(addOptions.duration) : typeof options.duration === 'function' ? ms(options.duration(key)) : options.duration && ms(options.duration);
41
- const threshold = (addOptions == null ? void 0 : addOptions.threshold) || typeof options.threshold && (typeof options.threshold === 'function' ? options.threshold(key) : options.threshold);
42
- const thresholdTimeout = (addOptions == null ? void 0 : addOptions.thresholdTimeout) != null ? ms(addOptions.thresholdTimeout) : typeof options.thresholdTimeout === 'function' ? ms(options.thresholdTimeout(key)) : options.thresholdTimeout && ms(options.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 (prevJob == null ? void 0 : prevJob.remove());
68
+ await prevJob?.remove();
69
69
  await task.add({
70
70
  key: key,
71
71
  redisKey: redisKey
@@ -1,5 +1,5 @@
1
1
  export declare class HttpRedirect {
2
2
  url: string;
3
- permanently?: boolean;
4
- constructor(url: string, permanently?: boolean);
3
+ permanently?: boolean | undefined;
4
+ constructor(url: string, permanently?: boolean | undefined);
5
5
  }
@@ -27,8 +27,7 @@ export class Server {
27
27
  await this.applyAutoClose();
28
28
  }
29
29
  async close() {
30
- var _this$fastify;
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({
@@ -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}${// 结构:/test/sss?x=2
81
- path != null ? path : isWS ? res.url : req.url}`;
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(),
@@ -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
- ...((_this$options = this.options) == null ? void 0 : _this$options.limits)
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
  }
@@ -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: (_payload$retryCount = payload.retryCount) != null ? _payload$retryCount : 0,
29
+ retryCount: payload.retryCount ?? 0,
31
30
  extra: payload.extra
32
31
  }, payload.ttl);
33
32
  return {
@@ -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 = (options == null ? void 0 : options.separator) || ',';
23
- this.affix = (options == null ? void 0 : options.affix) || '';
24
- this.number = !!(options != null && options.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[]>;
@@ -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 ((_this$options = this.options) != null && _this$options.disposeOnExit) {
7
+ if (this.options?.disposeOnExit) {
9
8
  onExit(() => this.dispose());
10
9
  }
11
10
  }
@@ -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 ((_this$options$onVerif = (_this$options = this.options).onVerify) == null ? void 0 : _this$options$onVerif.call(_this$options, data));
47
+ await this.options.onVerify?.(data);
49
48
  return data;
50
49
  }
51
50
  async verifyFromHttpHeaders(headers) {
@@ -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
- var _this$alipaySdk;
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
- var _options$limits$pass$;
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jayfong/x-server",
3
- "version": "2.62.0",
3
+ "version": "2.62.2",
4
4
  "license": "ISC",
5
5
  "sideEffects": false,
6
6
  "main": "lib/_cjs/index.js",