@gct-paas/cli 0.1.4 → 0.1.5-dev.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.
@@ -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
- const tags = entityManage.cache.keys();
42
- for (const tag2 of tags) {
43
- const [methodName, mode] = tag2.split(":");
44
- const config = entityManage.cache.get(tag2);
45
- let requestEntity = void 0;
46
- const param = config.parameters.find(param2 => {
47
- if (param2.in === "body") {
48
- return param2;
49
- }
50
- });
51
- if (param && param.schema) {
52
- const refKey = this.getOriginRef(param.schema);
53
- requestEntity = cfg.definitions[refKey];
54
- if (requestEntity && Object.keys(requestEntity).length > 0) {
55
- this.definitions.set(refKey, requestEntity);
56
- entitySet.add(refKey);
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
- let responseEntity = void 0;
60
- if (config.responses["200"].schema) {
61
- const refKey = this.getOriginRef(config.responses["200"].schema);
62
- responseEntity = cfg.definitions[refKey];
63
- if (responseEntity && Object.keys(responseEntity).length > 0) {
64
- this.definitions.set(refKey, responseEntity);
65
- entitySet.add(refKey);
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
- const queries = config.parameters.filter(param2 => {
69
- if (param2.in === "query") {
70
- return param2;
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
- if (methodName === "{id}") {
74
- queries.push({
75
- name: "id",
76
- in: "query",
77
- description: "\u6570\u636E\u4E3B\u952E",
78
- required: true,
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
- methods.push({
83
- name: methodName !== "undefined" ? methodName : "",
84
- mode,
85
- model: config,
86
- requestEntity,
87
- responseEntity,
88
- queries
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
- 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);
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
- 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);
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
- const queries = config.parameters.filter(
71
- (param2) => {
72
- if (param2.in === "query") {
73
- return param2;
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
- if (methodName === "{id}") {
78
- queries.push({
79
- name: "id",
80
- in: "query",
81
- description: "\u6570\u636E\u4E3B\u952E",
82
- required: true,
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
- methods.push({
87
- name: methodName !== "undefined" ? methodName : "",
88
- mode,
89
- model: config,
90
- requestEntity,
91
- responseEntity,
92
- queries
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[];
@@ -0,0 +1,11 @@
1
+ export const SPECIAL_ENTITIES = [
2
+ {
3
+ canonical: "med-pro",
4
+ aliases: ["medpro", "medPro", "med-pro"]
5
+ }
6
+ // 示例:如果后续有其他特殊映射,按照下面的格式添加
7
+ // {
8
+ // canonical: 'some-entity',
9
+ // aliases: ['someEntity', 'someentity', 'some-entity'],
10
+ // },
11
+ ];
@@ -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?: Record<string, string>): Promise<IHttpResponse<{{#if method.responseEntity}}{{formatImportItem method.responseEntity.title}}{{else}}unknown{{/if}}>>;
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.4",
3
+ "version": "0.1.5-dev.2",
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": "7f04ca4a10d5aa5466977c782663dff6e3965cef"
69
+ "gitHead": "d5c70cf34961e0bd1736b97f04b4afdf06386d23"
70
70
  }