@jayfong/x-server 2.30.2 → 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
|
|
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) :
|
|
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 {
|
package/lib/cli/api_generator.js
CHANGED
|
@@ -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
|
|
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) :
|
|
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 {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jayfong/x-server",
|
|
3
|
-
"version": "2.30.
|
|
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": "^
|
|
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",
|