@jayfong/x-server 2.30.1 → 2.30.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.
@@ -5,12 +5,12 @@ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWild
5
5
  exports.__esModule = true;
6
6
  exports.ApiGenerator = void 0;
7
7
  var parseComment = _interopRequireWildcard(require("comment-parser"));
8
- var ts = _interopRequireWildcard(require("ts-morph"));
9
8
  var _debug = _interopRequireDefault(require("debug"));
10
9
  var _fsExtra = _interopRequireDefault(require("fs-extra"));
11
10
  var _nodePath = _interopRequireDefault(require("node:path"));
12
- var _http_method = require("../core/http_method");
11
+ var ts = _interopRequireWildcard(require("ts-morph"));
13
12
  var _vtils = require("vtils");
13
+ var _http_method = require("../core/http_method");
14
14
  class ApiGenerator {
15
15
  constructor() {
16
16
  this.debug = (0, _debug.default)('api');
@@ -98,6 +98,7 @@ class ApiGenerator {
98
98
  // 将交集类型视为对象
99
99
  isIntersection;
100
100
  const symbol = _symbol || type.getSymbol();
101
+ const parentSymbol = symbol;
101
102
  const apiName = (symbol == null ? void 0 : symbol.getName()) || '__type';
102
103
  const apiDesc = [symbol && this.getCommentBySymbol(symbol), isEnum && `枚举:${enumKeys.map((key, index) => `${key}->${enumValues[index]}`).join('; ')}`].filter(Boolean).join('\n');
103
104
  const apiEnum = isUnion ? unionTypes.map(t => t.getLiteralValue()) : isEnum ? enumValues : [];
@@ -123,7 +124,14 @@ class ApiGenerator {
123
124
  return symbols.map(symbol => {
124
125
  return this.typeToApiData(!symbol.compilerSymbol.declarations ?
125
126
  // 对于复杂对象,没有定义的,通过 type 直接获取(在前面通过 getText 预处理得到)
126
- compilerFactory.getType(symbol.compilerSymbol.type) : this.getTypeBySymbol(symbol), symbol);
127
+ symbol.compilerSymbol.type ? compilerFactory.getType(symbol.compilerSymbol.type) :
128
+ // fix: symbol.compilerSymbol.type 为 undefined
129
+ // https://github.com/styleguidist/react-docgen-typescript/blob/master/src/parser.ts#L696
130
+ compilerFactory.getType(rawChecker.getTypeOfSymbolAtLocation(
131
+ // @ts-ignore
132
+ symbol.compilerSymbol,
133
+ // @ts-ignore
134
+ parentSymbol.compilerSymbol.declarations[0])) : this.getTypeBySymbol(symbol), symbol);
127
135
  });
128
136
  }) : [];
129
137
  return {
@@ -3,6 +3,10 @@
3
3
  exports.__esModule = true;
4
4
  exports.SensitiveWordsService = void 0;
5
5
  var _vtils = require("vtils");
6
+ var _regexp = require("vtils/regexp");
7
+ const phoneNumberRegExp = _regexp.phoneNumberRegExpBuilder.build();
8
+ const toRegExp = (0, _vtils.memoize)(re => new RegExp(re.substring(1, re.length - 1)), re => re);
9
+
6
10
  /**
7
11
  * 敏感词服务。
8
12
  */
@@ -28,7 +32,8 @@ class SensitiveWordsService {
28
32
  // 转小写
29
33
  .toLowerCase()
30
34
  // 叠词归一
31
- .replace(/(.)\1+/g, '$1')
35
+ // 排除字母数字以支持qq、手机号等场景
36
+ .replace(/([^a-zA-Z0-9])\1+/g, '$1')
32
37
  );
33
38
  }
34
39
 
@@ -39,7 +44,11 @@ class SensitiveWordsService {
39
44
  text = this.transform(text);
40
45
  const words = [];
41
46
  for (const word of this.sensitiveWords) {
42
- if (text.includes(word)) {
47
+ if (
48
+ // 支持 <手机号>
49
+ word === '<手机号>' ? phoneNumberRegExp.test(text) :
50
+ // 支持正则
51
+ word[0] === '/' && word[word.length - 1] === '/' ? toRegExp(word).test(text) : text.includes(word)) {
43
52
  words.push(word);
44
53
  if (!every) break;
45
54
  }
@@ -1,6 +1,6 @@
1
- import * as ts from 'ts-morph';
2
1
  import createDebug from 'debug';
3
2
  import type { JSONSchema4 } from 'json-schema';
3
+ import * as ts from 'ts-morph';
4
4
  import type { XHandler } from '../core/types';
5
5
  interface ApiData {
6
6
  name: string;
@@ -1,10 +1,10 @@
1
1
  import * as parseComment from 'comment-parser';
2
- import * as ts from 'ts-morph';
3
2
  import createDebug from 'debug';
4
3
  import fs from 'fs-extra';
5
4
  import path from 'node:path';
6
- import { HandlerMethodToHttpMethod } from "../core/http_method";
5
+ import * as ts from 'ts-morph';
7
6
  import { ii, pascalCase, snakeCase } from 'vtils';
7
+ import { HandlerMethodToHttpMethod } from "../core/http_method";
8
8
  export class ApiGenerator {
9
9
  constructor() {
10
10
  this.debug = createDebug('api');
@@ -92,6 +92,7 @@ export class ApiGenerator {
92
92
  // 将交集类型视为对象
93
93
  isIntersection;
94
94
  const symbol = _symbol || type.getSymbol();
95
+ const parentSymbol = symbol;
95
96
  const apiName = (symbol == null ? void 0 : symbol.getName()) || '__type';
96
97
  const apiDesc = [symbol && this.getCommentBySymbol(symbol), isEnum && `枚举:${enumKeys.map((key, index) => `${key}->${enumValues[index]}`).join('; ')}`].filter(Boolean).join('\n');
97
98
  const apiEnum = isUnion ? unionTypes.map(t => t.getLiteralValue()) : isEnum ? enumValues : [];
@@ -117,7 +118,14 @@ export class ApiGenerator {
117
118
  return symbols.map(symbol => {
118
119
  return this.typeToApiData(!symbol.compilerSymbol.declarations ?
119
120
  // 对于复杂对象,没有定义的,通过 type 直接获取(在前面通过 getText 预处理得到)
120
- compilerFactory.getType(symbol.compilerSymbol.type) : this.getTypeBySymbol(symbol), symbol);
121
+ symbol.compilerSymbol.type ? compilerFactory.getType(symbol.compilerSymbol.type) :
122
+ // fix: symbol.compilerSymbol.type 为 undefined
123
+ // https://github.com/styleguidist/react-docgen-typescript/blob/master/src/parser.ts#L696
124
+ compilerFactory.getType(rawChecker.getTypeOfSymbolAtLocation(
125
+ // @ts-ignore
126
+ symbol.compilerSymbol,
127
+ // @ts-ignore
128
+ parentSymbol.compilerSymbol.declarations[0])) : this.getTypeBySymbol(symbol), symbol);
121
129
  });
122
130
  }) : [];
123
131
  return {
@@ -1,4 +1,8 @@
1
- import { removeBlankChars, removeNonWordChars, toHalfWidthString, uniq } from 'vtils';
1
+ import { memoize, removeBlankChars, removeNonWordChars, toHalfWidthString, uniq } from 'vtils';
2
+ import { phoneNumberRegExpBuilder } from 'vtils/regexp';
3
+ const phoneNumberRegExp = phoneNumberRegExpBuilder.build();
4
+ const toRegExp = memoize(re => new RegExp(re.substring(1, re.length - 1)), re => re);
5
+
2
6
  /**
3
7
  * 敏感词服务。
4
8
  */
@@ -24,7 +28,8 @@ export class SensitiveWordsService {
24
28
  // 转小写
25
29
  .toLowerCase()
26
30
  // 叠词归一
27
- .replace(/(.)\1+/g, '$1')
31
+ // 排除字母数字以支持qq、手机号等场景
32
+ .replace(/([^a-zA-Z0-9])\1+/g, '$1')
28
33
  );
29
34
  }
30
35
 
@@ -35,7 +40,11 @@ export class SensitiveWordsService {
35
40
  text = this.transform(text);
36
41
  const words = [];
37
42
  for (const word of this.sensitiveWords) {
38
- if (text.includes(word)) {
43
+ if (
44
+ // 支持 <手机号>
45
+ word === '<手机号>' ? phoneNumberRegExp.test(text) :
46
+ // 支持正则
47
+ word[0] === '/' && word[word.length - 1] === '/' ? toRegExp(word).test(text) : text.includes(word)) {
39
48
  words.push(word);
40
49
  if (!every) break;
41
50
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jayfong/x-server",
3
- "version": "2.30.1",
3
+ "version": "2.30.3",
4
4
  "license": "ISC",
5
5
  "sideEffects": false,
6
6
  "main": "lib/_cjs/index.js",
@@ -17,7 +17,9 @@
17
17
  "build_test_pkg": "tyn build && rm -rf ./lib_test && mkdir -p ./lib_test && cp -r ./lib ./lib_test/lib && cp ./package.json ./lib_test/package.json && cd ./tests/app && tyn add file:../../lib_test",
18
18
  "preinstall": "tnpx only-allow pnpm",
19
19
  "test": "tsc --noEmit -p ./tsconfig.build.json && jest \"$(pwd)/src/\"",
20
- "test_all": "tsc --noEmit -p ./tsconfig.build.json && jest"
20
+ "test_all": "tsc --noEmit -p ./tsconfig.build.json && jest",
21
+ "test_api_bot": "cd /Users/admin/Documents/jfWorks/qiqi-bot && DEBUG=api tsx /Users/admin/Documents/jfWorks/x/packages/x-server/src/cli/cli.ts api",
22
+ "test_api_qiqi": "cd /Users/admin/Documents/jfWorks/qiqi-server && DEBUG=api tsx /Users/admin/Documents/jfWorks/x/packages/x-server/src/cli/cli.ts api"
21
23
  },
22
24
  "dependencies": {
23
25
  "@fastify/cors": "^8.3.0",
@@ -64,7 +66,7 @@
64
66
  "svg-captcha": "^1.4.0",
65
67
  "tencentcloud-sdk-nodejs-sms": "^4.0.681",
66
68
  "ts-morph": "^12.2.0",
67
- "tsx": "^3.12.7",
69
+ "tsx": "^4.6.2",
68
70
  "utf-8-validate": "^5.0.9",
69
71
  "vscode-generate-index-standalone": "^1.7.1",
70
72
  "vtils": "^4.95.0",