@gct-paas/cli 0.1.4 → 0.1.5-dev.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/dist/actions/gen-api/api-manage.cjs +38 -0
- package/dist/actions/gen-api/api-manage.d.ts +12 -0
- package/dist/actions/gen-api/model-manage.cjs +58 -55
- package/dist/actions/gen-api/special-entities.config.cjs +16 -0
- package/dist/actions/gen-api/special-entities.config.d.ts +15 -0
- package/es/actions/gen-api/api-manage.d.ts +12 -0
- package/es/actions/gen-api/api-manage.mjs +32 -0
- package/es/actions/gen-api/model-manage.mjs +59 -56
- package/es/actions/gen-api/special-entities.config.d.ts +15 -0
- package/es/actions/gen-api/special-entities.config.mjs +11 -0
- package/hbs-temp/apis/{{api}}.service.d.ts.hbs +2 -1
- package/package.json +2 -2
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.EntityApiManage = exports.ApiManage = void 0;
|
|
7
|
+
var _specialEntities = require("./special-entities.config.cjs");
|
|
7
8
|
class EntityApiManage {
|
|
8
9
|
constructor(name) {
|
|
9
10
|
this.name = name;
|
|
@@ -24,6 +25,25 @@ class EntityApiManage {
|
|
|
24
25
|
exports.EntityApiManage = EntityApiManage;
|
|
25
26
|
class ApiManage {
|
|
26
27
|
cache = /* @__PURE__ */new Map();
|
|
28
|
+
constructor() {
|
|
29
|
+
this.specialTreatment();
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* 根据配置文件中的特殊实体映射来处理
|
|
33
|
+
*
|
|
34
|
+
* @protected
|
|
35
|
+
*/
|
|
36
|
+
specialTreatment() {
|
|
37
|
+
_specialEntities.SPECIAL_ENTITIES.forEach(({
|
|
38
|
+
canonical,
|
|
39
|
+
aliases
|
|
40
|
+
}) => {
|
|
41
|
+
const manage = new EntityApiManage(canonical);
|
|
42
|
+
aliases.forEach(alias => {
|
|
43
|
+
this.cache.set(alias, manage);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
}
|
|
27
47
|
/**
|
|
28
48
|
* 新增 api
|
|
29
49
|
*
|
|
@@ -46,5 +66,23 @@ class ApiManage {
|
|
|
46
66
|
entity.add(method, mode, _cfg);
|
|
47
67
|
});
|
|
48
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* 结束新增 api 后调用
|
|
71
|
+
*
|
|
72
|
+
*/
|
|
73
|
+
done() {
|
|
74
|
+
_specialEntities.SPECIAL_ENTITIES.forEach(({
|
|
75
|
+
canonical,
|
|
76
|
+
aliases
|
|
77
|
+
}) => {
|
|
78
|
+
if (this.cache.has(canonical)) {
|
|
79
|
+
aliases.forEach(alias => {
|
|
80
|
+
if (alias !== canonical) {
|
|
81
|
+
this.cache.delete(alias);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
49
87
|
}
|
|
50
88
|
exports.ApiManage = ApiManage;
|
|
@@ -26,6 +26,13 @@ export declare class EntityApiManage {
|
|
|
26
26
|
*/
|
|
27
27
|
export declare class ApiManage {
|
|
28
28
|
readonly cache: Map<string, EntityApiManage>;
|
|
29
|
+
constructor();
|
|
30
|
+
/**
|
|
31
|
+
* 根据配置文件中的特殊实体映射来处理
|
|
32
|
+
*
|
|
33
|
+
* @protected
|
|
34
|
+
*/
|
|
35
|
+
protected specialTreatment(): void;
|
|
29
36
|
/**
|
|
30
37
|
* 新增 api
|
|
31
38
|
*
|
|
@@ -33,4 +40,9 @@ export declare class ApiManage {
|
|
|
33
40
|
* @param {IObject} cfg swagger 配置
|
|
34
41
|
*/
|
|
35
42
|
add(pathStr: string, cfg: IObject): void;
|
|
43
|
+
/**
|
|
44
|
+
* 结束新增 api 后调用
|
|
45
|
+
*
|
|
46
|
+
*/
|
|
47
|
+
done(): void;
|
|
36
48
|
}
|
|
@@ -33,73 +33,76 @@ class ModelManage {
|
|
|
33
33
|
const pathCfg = cfg.paths[pathStr];
|
|
34
34
|
apiManage.add(pathStr, pathCfg);
|
|
35
35
|
});
|
|
36
|
+
apiManage.done();
|
|
36
37
|
const entityNames = apiManage.cache.keys();
|
|
37
38
|
for (const entityName of entityNames) {
|
|
38
39
|
const entitySet = /* @__PURE__ */new Set();
|
|
39
40
|
const entityManage = apiManage.cache.get(entityName);
|
|
40
41
|
const methods = [];
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
42
|
+
if (entityManage.cache.size > 0) {
|
|
43
|
+
const tags = entityManage.cache.keys();
|
|
44
|
+
for (const tag2 of tags) {
|
|
45
|
+
const [methodName, mode] = tag2.split(":");
|
|
46
|
+
const config = entityManage.cache.get(tag2);
|
|
47
|
+
let requestEntity = void 0;
|
|
48
|
+
const param = config.parameters.find(param2 => {
|
|
49
|
+
if (param2.in === "body") {
|
|
50
|
+
return param2;
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
if (param && param.schema) {
|
|
54
|
+
const refKey = this.getOriginRef(param.schema);
|
|
55
|
+
requestEntity = cfg.definitions[refKey];
|
|
56
|
+
if (requestEntity && Object.keys(requestEntity).length > 0) {
|
|
57
|
+
this.definitions.set(refKey, requestEntity);
|
|
58
|
+
entitySet.add(refKey);
|
|
59
|
+
}
|
|
57
60
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
61
|
+
let responseEntity = void 0;
|
|
62
|
+
if (config.responses["200"].schema) {
|
|
63
|
+
const refKey = this.getOriginRef(config.responses["200"].schema);
|
|
64
|
+
responseEntity = cfg.definitions[refKey];
|
|
65
|
+
if (responseEntity && Object.keys(responseEntity).length > 0) {
|
|
66
|
+
this.definitions.set(refKey, responseEntity);
|
|
67
|
+
entitySet.add(refKey);
|
|
68
|
+
}
|
|
66
69
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
70
|
+
const queries = config.parameters.filter(param2 => {
|
|
71
|
+
if (param2.in === "query") {
|
|
72
|
+
return param2;
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
if (methodName === "{id}") {
|
|
76
|
+
queries.push({
|
|
77
|
+
name: "id",
|
|
78
|
+
in: "query",
|
|
79
|
+
description: "\u6570\u636E\u4E3B\u952E",
|
|
80
|
+
required: true,
|
|
81
|
+
type: "string"
|
|
82
|
+
});
|
|
71
83
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
type: "string"
|
|
84
|
+
methods.push({
|
|
85
|
+
name: methodName !== "undefined" ? methodName : "",
|
|
86
|
+
mode,
|
|
87
|
+
model: config,
|
|
88
|
+
requestEntity,
|
|
89
|
+
responseEntity,
|
|
90
|
+
queries
|
|
80
91
|
});
|
|
81
92
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
93
|
+
this.entities.set(entityName, {
|
|
94
|
+
tag,
|
|
95
|
+
entityName,
|
|
96
|
+
api: entityName,
|
|
97
|
+
model: cfg.definitions[entityName],
|
|
98
|
+
methods,
|
|
99
|
+
entityRefs: Array.from(entitySet.values()).filter(item => {
|
|
100
|
+
return this.basicDataType.findIndex(type => {
|
|
101
|
+
return item.indexOf(`\xAB${type}\xBB`) !== -1;
|
|
102
|
+
}) === -1 && !this.basicDataType.includes(item);
|
|
103
|
+
})
|
|
89
104
|
});
|
|
90
105
|
}
|
|
91
|
-
this.entities.set(entityName, {
|
|
92
|
-
tag,
|
|
93
|
-
entityName,
|
|
94
|
-
api: entityName,
|
|
95
|
-
model: cfg.definitions[entityName],
|
|
96
|
-
methods,
|
|
97
|
-
entityRefs: Array.from(entitySet.values()).filter(item => {
|
|
98
|
-
return this.basicDataType.findIndex(type => {
|
|
99
|
-
return item.indexOf(`\xAB${type}\xBB`) !== -1;
|
|
100
|
-
}) === -1 && !this.basicDataType.includes(item);
|
|
101
|
-
})
|
|
102
|
-
});
|
|
103
106
|
}
|
|
104
107
|
}
|
|
105
108
|
/**
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.SPECIAL_ENTITIES = void 0;
|
|
7
|
+
const SPECIAL_ENTITIES = exports.SPECIAL_ENTITIES = [{
|
|
8
|
+
canonical: "med-pro",
|
|
9
|
+
aliases: ["medpro", "medPro", "med-pro"]
|
|
10
|
+
}
|
|
11
|
+
// 示例:如果后续有其他特殊映射,按照下面的格式添加
|
|
12
|
+
// {
|
|
13
|
+
// canonical: 'some-entity',
|
|
14
|
+
// aliases: ['someEntity', 'someentity', 'some-entity'],
|
|
15
|
+
// },
|
|
16
|
+
];
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 特殊实体映射配置
|
|
3
|
+
* 用于处理 swagger 中存在的特殊命名或映射规则
|
|
4
|
+
*/
|
|
5
|
+
export interface SpecialEntityMapping {
|
|
6
|
+
/** 标准实体名称 */
|
|
7
|
+
canonical: string;
|
|
8
|
+
/** 别名映射列表 */
|
|
9
|
+
aliases: string[];
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* 特殊实体配置列表
|
|
13
|
+
* 当后续有类似的特殊处理需求时,直接在此列表中添加新条目即可
|
|
14
|
+
*/
|
|
15
|
+
export declare const SPECIAL_ENTITIES: SpecialEntityMapping[];
|
|
@@ -26,6 +26,13 @@ export declare class EntityApiManage {
|
|
|
26
26
|
*/
|
|
27
27
|
export declare class ApiManage {
|
|
28
28
|
readonly cache: Map<string, EntityApiManage>;
|
|
29
|
+
constructor();
|
|
30
|
+
/**
|
|
31
|
+
* 根据配置文件中的特殊实体映射来处理
|
|
32
|
+
*
|
|
33
|
+
* @protected
|
|
34
|
+
*/
|
|
35
|
+
protected specialTreatment(): void;
|
|
29
36
|
/**
|
|
30
37
|
* 新增 api
|
|
31
38
|
*
|
|
@@ -33,4 +40,9 @@ export declare class ApiManage {
|
|
|
33
40
|
* @param {IObject} cfg swagger 配置
|
|
34
41
|
*/
|
|
35
42
|
add(pathStr: string, cfg: IObject): void;
|
|
43
|
+
/**
|
|
44
|
+
* 结束新增 api 后调用
|
|
45
|
+
*
|
|
46
|
+
*/
|
|
47
|
+
done(): void;
|
|
36
48
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SPECIAL_ENTITIES } from "./special-entities.config.mjs";
|
|
1
2
|
export class EntityApiManage {
|
|
2
3
|
constructor(name) {
|
|
3
4
|
this.name = name;
|
|
@@ -17,6 +18,22 @@ export class EntityApiManage {
|
|
|
17
18
|
}
|
|
18
19
|
export class ApiManage {
|
|
19
20
|
cache = /* @__PURE__ */ new Map();
|
|
21
|
+
constructor() {
|
|
22
|
+
this.specialTreatment();
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* 根据配置文件中的特殊实体映射来处理
|
|
26
|
+
*
|
|
27
|
+
* @protected
|
|
28
|
+
*/
|
|
29
|
+
specialTreatment() {
|
|
30
|
+
SPECIAL_ENTITIES.forEach(({ canonical, aliases }) => {
|
|
31
|
+
const manage = new EntityApiManage(canonical);
|
|
32
|
+
aliases.forEach((alias) => {
|
|
33
|
+
this.cache.set(alias, manage);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
}
|
|
20
37
|
/**
|
|
21
38
|
* 新增 api
|
|
22
39
|
*
|
|
@@ -39,4 +56,19 @@ export class ApiManage {
|
|
|
39
56
|
entity.add(method, mode, _cfg);
|
|
40
57
|
});
|
|
41
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* 结束新增 api 后调用
|
|
61
|
+
*
|
|
62
|
+
*/
|
|
63
|
+
done() {
|
|
64
|
+
SPECIAL_ENTITIES.forEach(({ canonical, aliases }) => {
|
|
65
|
+
if (this.cache.has(canonical)) {
|
|
66
|
+
aliases.forEach((alias) => {
|
|
67
|
+
if (alias !== canonical) {
|
|
68
|
+
this.cache.delete(alias);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
42
74
|
}
|
|
@@ -35,75 +35,78 @@ export class ModelManage {
|
|
|
35
35
|
const pathCfg = cfg.paths[pathStr];
|
|
36
36
|
apiManage.add(pathStr, pathCfg);
|
|
37
37
|
});
|
|
38
|
+
apiManage.done();
|
|
38
39
|
const entityNames = apiManage.cache.keys();
|
|
39
40
|
for (const entityName of entityNames) {
|
|
40
41
|
const entitySet = /* @__PURE__ */ new Set();
|
|
41
42
|
const entityManage = apiManage.cache.get(entityName);
|
|
42
43
|
const methods = [];
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
44
|
+
if (entityManage.cache.size > 0) {
|
|
45
|
+
const tags = entityManage.cache.keys();
|
|
46
|
+
for (const tag2 of tags) {
|
|
47
|
+
const [methodName, mode] = tag2.split(":");
|
|
48
|
+
const config = entityManage.cache.get(tag2);
|
|
49
|
+
let requestEntity = void 0;
|
|
50
|
+
const param = config.parameters.find((param2) => {
|
|
51
|
+
if (param2.in === "body") {
|
|
52
|
+
return param2;
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
if (param && param.schema) {
|
|
56
|
+
const refKey = this.getOriginRef(param.schema);
|
|
57
|
+
requestEntity = cfg.definitions[refKey];
|
|
58
|
+
if (requestEntity && Object.keys(requestEntity).length > 0) {
|
|
59
|
+
this.definitions.set(refKey, requestEntity);
|
|
60
|
+
entitySet.add(refKey);
|
|
61
|
+
}
|
|
59
62
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
63
|
+
let responseEntity = void 0;
|
|
64
|
+
if (config.responses["200"].schema) {
|
|
65
|
+
const refKey = this.getOriginRef(config.responses["200"].schema);
|
|
66
|
+
responseEntity = cfg.definitions[refKey];
|
|
67
|
+
if (responseEntity && Object.keys(responseEntity).length > 0) {
|
|
68
|
+
this.definitions.set(refKey, responseEntity);
|
|
69
|
+
entitySet.add(refKey);
|
|
70
|
+
}
|
|
68
71
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
72
|
+
const queries = config.parameters.filter(
|
|
73
|
+
(param2) => {
|
|
74
|
+
if (param2.in === "query") {
|
|
75
|
+
return param2;
|
|
76
|
+
}
|
|
74
77
|
}
|
|
78
|
+
);
|
|
79
|
+
if (methodName === "{id}") {
|
|
80
|
+
queries.push({
|
|
81
|
+
name: "id",
|
|
82
|
+
in: "query",
|
|
83
|
+
description: "\u6570\u636E\u4E3B\u952E",
|
|
84
|
+
required: true,
|
|
85
|
+
type: "string"
|
|
86
|
+
});
|
|
75
87
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
type: "string"
|
|
88
|
+
methods.push({
|
|
89
|
+
name: methodName !== "undefined" ? methodName : "",
|
|
90
|
+
mode,
|
|
91
|
+
model: config,
|
|
92
|
+
requestEntity,
|
|
93
|
+
responseEntity,
|
|
94
|
+
queries
|
|
84
95
|
});
|
|
85
96
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
97
|
+
this.entities.set(entityName, {
|
|
98
|
+
tag,
|
|
99
|
+
entityName,
|
|
100
|
+
api: entityName,
|
|
101
|
+
model: cfg.definitions[entityName],
|
|
102
|
+
methods,
|
|
103
|
+
entityRefs: Array.from(entitySet.values()).filter((item) => {
|
|
104
|
+
return this.basicDataType.findIndex((type) => {
|
|
105
|
+
return item.indexOf(`\xAB${type}\xBB`) !== -1;
|
|
106
|
+
}) === -1 && !this.basicDataType.includes(item);
|
|
107
|
+
})
|
|
93
108
|
});
|
|
94
109
|
}
|
|
95
|
-
this.entities.set(entityName, {
|
|
96
|
-
tag,
|
|
97
|
-
entityName,
|
|
98
|
-
api: entityName,
|
|
99
|
-
model: cfg.definitions[entityName],
|
|
100
|
-
methods,
|
|
101
|
-
entityRefs: Array.from(entitySet.values()).filter((item) => {
|
|
102
|
-
return this.basicDataType.findIndex((type) => {
|
|
103
|
-
return item.indexOf(`\xAB${type}\xBB`) !== -1;
|
|
104
|
-
}) === -1 && !this.basicDataType.includes(item);
|
|
105
|
-
})
|
|
106
|
-
});
|
|
107
110
|
}
|
|
108
111
|
}
|
|
109
112
|
/**
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 特殊实体映射配置
|
|
3
|
+
* 用于处理 swagger 中存在的特殊命名或映射规则
|
|
4
|
+
*/
|
|
5
|
+
export interface SpecialEntityMapping {
|
|
6
|
+
/** 标准实体名称 */
|
|
7
|
+
canonical: string;
|
|
8
|
+
/** 别名映射列表 */
|
|
9
|
+
aliases: string[];
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* 特殊实体配置列表
|
|
13
|
+
* 当后续有类似的特殊处理需求时,直接在此列表中添加新条目即可
|
|
14
|
+
*/
|
|
15
|
+
export declare const SPECIAL_ENTITIES: SpecialEntityMapping[];
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { AxiosRequestConfig } from 'axios';
|
|
1
2
|
{{#gt entityRefs.length 0}}
|
|
2
3
|
import type { {{formatImport entityRefs}} } from '../entities';
|
|
3
4
|
|
|
@@ -14,6 +15,6 @@ export interface {{ method.mode }}{{#if method.name}}{{pascalCase (camelCase met
|
|
|
14
15
|
export interface {{pascalCase (camelCase entityName) }}Service {
|
|
15
16
|
{{#each methods as |method|}}
|
|
16
17
|
// {{ method.model.summary }}
|
|
17
|
-
{{ method.mode }}{{#if method.name}}{{pascalCase (camelCase method.name) }}{{/if}}({{#gt method.queries.length 0}}query: {{ method.mode }}{{#if method.name}}{{pascalCase (camelCase method.name) }}{{/if}}Query, {{/gt}}{{#if method.requestEntity}}data: {{method.requestEntity.title}}, {{/if}}config?:
|
|
18
|
+
{{ method.mode }}{{#if method.name}}{{pascalCase (camelCase method.name) }}{{/if}}({{#gt method.queries.length 0}}query: {{ method.mode }}{{#if method.name}}{{pascalCase (camelCase method.name) }}{{/if}}Query, {{/gt}}{{#if method.requestEntity}}data: {{method.requestEntity.title}}, {{/if}}config?: Partial<AxiosRequestConfig>): Promise<IHttpResponse<{{#if method.responseEntity}}{{formatImportItem method.responseEntity.title}}{{else}}unknown{{/if}}>>;
|
|
18
19
|
{{/each}}
|
|
19
20
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gct-paas/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5-dev.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "paas 平台核心包",
|
|
6
6
|
"bin": {
|
|
@@ -66,5 +66,5 @@
|
|
|
66
66
|
"typescript": "^5.9.3",
|
|
67
67
|
"unbuild": "^3.6.1"
|
|
68
68
|
},
|
|
69
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "694dd0de8927d3cb6ae87d3b8b4ce0902e878ddc"
|
|
70
70
|
}
|