@gct-paas/cli 0.1.1 → 0.1.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/CHANGELOG.md CHANGED
@@ -7,6 +7,12 @@
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.1.3] - 2025-06-16
11
+
12
+ ### Added
13
+
14
+ - 新增对 ResponseEntity«List«Tree«string»»»、ResponseEntity«PageBase«AgentResponse»» 类似类型的处理
15
+
10
16
  ## [0.0.1] - 2025-01-07
11
17
 
12
18
  ### Added
@@ -31,15 +31,19 @@ class ApiManage {
31
31
  * @param {IObject} cfg swagger 配置
32
32
  */
33
33
  add(pathStr, cfg) {
34
- const entityName = pathStr.split("/")[3];
35
- const method = pathStr.split("/")[4];
34
+ const splits = pathStr.split("/");
35
+ const entityName = splits[3];
36
+ const method = splits[4];
37
+ const requestPath = splits.slice(4).join("/");
36
38
  if (!this.cache.has(entityName)) {
37
39
  this.cache.set(entityName, new EntityApiManage(entityName));
38
40
  }
39
41
  const entity = this.cache.get(entityName);
40
42
  const modes = Object.keys(cfg);
41
43
  modes.forEach(mode => {
42
- entity.add(method, mode, cfg[mode]);
44
+ const _cfg = cfg[mode];
45
+ _cfg.requestPath = requestPath;
46
+ entity.add(method, mode, _cfg);
43
47
  });
44
48
  }
45
49
  }
@@ -21,7 +21,8 @@ class GenApiAction {
21
21
  modelManage = new _modelManage.ModelManage();
22
22
  configs = {
23
23
  platform: "/gct-platform/v2/api-docs?group=%E7%AE%A1%E7%90%86%E5%B9%B3%E5%8F%B0API",
24
- apaas: "/gct-apaas/v2/api-docs?group=apaas%E5%B9%B3%E5%8F%B0API"
24
+ apaas: "/gct-apaas/v2/api-docs?group=apaas%E5%B9%B3%E5%8F%B0API",
25
+ rag: "/gct-rag/v2/api-docs?group=%E7%AE%A1%E7%90%86%E5%B9%B3%E5%8F%B0API"
25
26
  };
26
27
  /**
27
28
  * 生成 api
@@ -14,8 +14,15 @@ class HelperFormatImportItem extends _helperBase.HelperBase {
14
14
  return "";
15
15
  }
16
16
  if (param.indexOf("\xAB") > -1) {
17
- const arr = param.split("\xAB");
18
- const text = arr[arr.length - 1].split("\xBB")[0];
17
+ const start = param.indexOf("\xAB");
18
+ const end = param.indexOf("\xBB");
19
+ param = param.substring(start + 1, end);
20
+ param = param.replace(/«/g, "___");
21
+ param = param.replace(/»/g, "___");
22
+ const arr = param.split("___");
23
+ const isType = arr.length > 1;
24
+ const type = isType ? arr[0] : "";
25
+ const text = isType ? arr[1] : arr[0];
19
26
  let keys = text.split(",");
20
27
  if (keys.length > 1) {
21
28
  return "IObject";
@@ -32,7 +39,22 @@ class HelperFormatImportItem extends _helperBase.HelperBase {
32
39
  }
33
40
  return key;
34
41
  });
35
- return keys.join(",");
42
+ const val = keys.join(",");
43
+ if (isType) {
44
+ if (type === "List") {
45
+ if (val === "Tree") {
46
+ return "IObject[]";
47
+ }
48
+ return val + "[]";
49
+ }
50
+ if (type === "PageBase") {
51
+ return `IPage<${val}>`;
52
+ }
53
+ if (type === "Tree") {
54
+ return "IObject";
55
+ }
56
+ }
57
+ return val;
36
58
  }
37
59
  return param;
38
60
  }
@@ -24,15 +24,19 @@ export class ApiManage {
24
24
  * @param {IObject} cfg swagger 配置
25
25
  */
26
26
  add(pathStr, cfg) {
27
- const entityName = pathStr.split("/")[3];
28
- const method = pathStr.split("/")[4];
27
+ const splits = pathStr.split("/");
28
+ const entityName = splits[3];
29
+ const method = splits[4];
30
+ const requestPath = splits.slice(4).join("/");
29
31
  if (!this.cache.has(entityName)) {
30
32
  this.cache.set(entityName, new EntityApiManage(entityName));
31
33
  }
32
34
  const entity = this.cache.get(entityName);
33
35
  const modes = Object.keys(cfg);
34
36
  modes.forEach((mode) => {
35
- entity.add(method, mode, cfg[mode]);
37
+ const _cfg = cfg[mode];
38
+ _cfg.requestPath = requestPath;
39
+ entity.add(method, mode, _cfg);
36
40
  });
37
41
  }
38
42
  }
@@ -12,7 +12,8 @@ export class GenApiAction {
12
12
  modelManage = new ModelManage();
13
13
  configs = {
14
14
  platform: "/gct-platform/v2/api-docs?group=%E7%AE%A1%E7%90%86%E5%B9%B3%E5%8F%B0API",
15
- apaas: "/gct-apaas/v2/api-docs?group=apaas%E5%B9%B3%E5%8F%B0API"
15
+ apaas: "/gct-apaas/v2/api-docs?group=apaas%E5%B9%B3%E5%8F%B0API",
16
+ rag: "/gct-rag/v2/api-docs?group=%E7%AE%A1%E7%90%86%E5%B9%B3%E5%8F%B0API"
16
17
  };
17
18
  /**
18
19
  * 生成 api
@@ -8,8 +8,15 @@ export class HelperFormatImportItem extends HelperBase {
8
8
  return "";
9
9
  }
10
10
  if (param.indexOf("\xAB") > -1) {
11
- const arr = param.split("\xAB");
12
- const text = arr[arr.length - 1].split("\xBB")[0];
11
+ const start = param.indexOf("\xAB");
12
+ const end = param.indexOf("\xBB");
13
+ param = param.substring(start + 1, end);
14
+ param = param.replace(/«/g, "___");
15
+ param = param.replace(/»/g, "___");
16
+ const arr = param.split("___");
17
+ const isType = arr.length > 1;
18
+ const type = isType ? arr[0] : "";
19
+ const text = isType ? arr[1] : arr[0];
13
20
  let keys = text.split(",");
14
21
  if (keys.length > 1) {
15
22
  return "IObject";
@@ -26,7 +33,22 @@ export class HelperFormatImportItem extends HelperBase {
26
33
  }
27
34
  return key;
28
35
  });
29
- return keys.join(",");
36
+ const val = keys.join(",");
37
+ if (isType) {
38
+ if (type === "List") {
39
+ if (val === "Tree") {
40
+ return "IObject[]";
41
+ }
42
+ return val + "[]";
43
+ }
44
+ if (type === "PageBase") {
45
+ return `IPage<${val}>`;
46
+ }
47
+ if (type === "Tree") {
48
+ return "IObject";
49
+ }
50
+ }
51
+ return val;
30
52
  }
31
53
  return param;
32
54
  }
@@ -0,0 +1,19 @@
1
+ /* eslint-disable @typescript-eslint/no-empty-object-type */
2
+ {{#each definitions as |entity|}}
3
+ {{#notIncludes entity.title '«'}}
4
+ export interface {{ entity.title }} {
5
+ {{#gt entity.propertySize 0}}
6
+ {{#each entity.properties as |property key|}}
7
+ /**
8
+ * {{ property.description }}
9
+ *
10
+ * @type {{{formatJsType property.type property.items }}}
11
+ */
12
+ {{ key }}{{#if property.required}}{{else}}?{{/if}}: {{formatJsType property.type property.items }};
13
+ {{/each}}
14
+ {{else}}
15
+ // 暂无属性
16
+ {{/gt}}
17
+ }
18
+ {{/notIncludes}}
19
+ {{/each}}
@@ -0,0 +1,9 @@
1
+ {{#each entities as |entity|}}
2
+ import { {{pascalCase (camelCase entity.entityName) }}Service } from './{{entity.entityName}}.service';
3
+ {{/each}}
4
+
5
+ export class ApiManage {
6
+ {{#each entities as |entity|}}
7
+ {{camelCase entity.entityName}}: {{pascalCase (camelCase entity.entityName)}}Service = new {{pascalCase (camelCase entity.entityName)}}Service();
8
+ {{/each}}
9
+ }
@@ -0,0 +1,34 @@
1
+ import type { IHttpResponse } from '../../interface';
2
+ {{#eq tag 'apaas'}}
3
+ import { ApaasBaseService } from '../base/apaas-base.service';
4
+ {{/eq}}
5
+ {{#eq tag 'platform'}}
6
+ import { PlatformBaseService } from '../base/platform-base.service';
7
+ {{/eq}}
8
+ {{#eq tag 'rag'}}
9
+ import { RagBaseService } from '../base/rag-base.service';
10
+ {{/eq}}
11
+ {{#gt entityRefs.length 0}}
12
+ import type { {{formatImport entityRefs}} } from './entities';
13
+
14
+ {{/gt}}
15
+ {{#each methods as |method|}}
16
+ {{#gt method.queries.length 0}}
17
+ export interface {{ method.mode }}{{#if method.name}}{{pascalCase (camelCase method.name) }}{{/if}}Query {
18
+ {{#each method.queries as |query|}}
19
+ {{camelCase query.name}}{{#if query.required}}{{else}}?{{/if}}: {{#if query.items}}{{formatJsType query.items.type}}{{else}}{{formatJsType query.type}}{{/if}}; // {{query.description}}
20
+ {{/each}}
21
+ }
22
+ {{/gt}}
23
+ {{/each}}
24
+ export class {{pascalCase (camelCase entityName) }}Service extends {{#eq tag 'apaas'}}ApaasBaseService{{/eq}}{{#eq tag 'platform'}}PlatformBaseService{{/eq}}{{#eq tag 'rag'}}RagBaseService{{/eq}} {
25
+ constructor() {
26
+ super('{{ entityName }}');
27
+ }
28
+ {{#each methods as |method|}}
29
+ // {{ method.model.summary }}
30
+ async {{ 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}}>> {
31
+ return this._{{ method.mode }}('{{#eq method.name '{id}'}}{{else}}{{method.model.requestPath}}{{/eq}}'{{#if method.requestEntity}}, data{{else}}, null{{/if}}{{#gt method.queries.length 0}}, query{{else}}, null{{/gt}}, config);
32
+ }
33
+ {{/each}}
34
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gct-paas/cli",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "type": "module",
5
5
  "description": "paas 平台核心包",
6
6
  "bin": {
@@ -19,6 +19,7 @@
19
19
  "files": [
20
20
  "dist",
21
21
  "es",
22
+ "hbs-temp",
22
23
  "CHANGELOG.md",
23
24
  "README.md"
24
25
  ],
@@ -35,6 +36,7 @@
35
36
  "scripts": {
36
37
  "build": "npm run lint && unbuild",
37
38
  "lint": "eslint src/",
39
+ "link2global": "pnpm link --global",
38
40
  "publish:next": "npm run build && npm publish --access public --tag=next --registry=https://registry.npmjs.org/",
39
41
  "publish:dev": "npm run build && npm publish --access public --tag=dev --registry=https://registry.npmjs.org/",
40
42
  "publish:alpha": "npm run build && npm publish --access public --tag=alpha --registry=https://registry.npmjs.org/",
@@ -62,6 +64,5 @@
62
64
  "@types/node": "^22.13.9",
63
65
  "typescript": "^5.8.2",
64
66
  "unbuild": "^3.5.0"
65
- },
66
- "gitHead": "7a166eedf06af8342dfe256c5c57dfe2a304a9bd"
67
+ }
67
68
  }