@cloudbase/cli 2.10.0-beta.0 → 2.11.0-beta.0
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/lib/auth/login.js +51 -65
- package/lib/auth/logout.js +3 -14
- package/lib/commands/account/login.js +136 -149
- package/lib/commands/account/logout.js +3 -14
- package/lib/commands/ag/base.js +203 -0
- package/lib/commands/ag/create.js +301 -0
- package/lib/commands/ag/debug/index.html +699 -0
- package/lib/commands/ag/delete.js +200 -0
- package/lib/commands/ag/deploy.js +185 -0
- package/lib/commands/ag/detail.js +113 -0
- package/lib/commands/ag/index.js +22 -0
- package/lib/commands/ag/list.js +155 -0
- package/lib/commands/ag/run.js +644 -0
- package/lib/commands/ai/index.js +76 -95
- package/lib/commands/cloudfunction/base.js +182 -203
- package/lib/commands/cloudrun/base.js +578 -603
- package/lib/commands/common.js +48 -63
- package/lib/commands/config/delete.js +16 -27
- package/lib/commands/config/get.js +13 -24
- package/lib/commands/config/list.js +16 -27
- package/lib/commands/config/set.js +33 -44
- package/lib/commands/db/base.js +221 -240
- package/lib/commands/env/base.js +36 -49
- package/lib/commands/env/domain.js +79 -94
- package/lib/commands/env/login.js +120 -135
- package/lib/commands/framework/index.js +32 -49
- package/lib/commands/fun/base.js +223 -244
- package/lib/commands/functions/alias/getRoute.js +33 -44
- package/lib/commands/functions/alias/setRoute.js +36 -47
- package/lib/commands/functions/code-download.js +43 -54
- package/lib/commands/functions/code-update.js +23 -34
- package/lib/commands/functions/concurrency/delete.js +11 -22
- package/lib/commands/functions/concurrency/list.js +20 -31
- package/lib/commands/functions/concurrency/set.js +13 -24
- package/lib/commands/functions/config-update.js +30 -41
- package/lib/commands/functions/copy.js +12 -23
- package/lib/commands/functions/delete.js +30 -41
- package/lib/commands/functions/deploy.js +184 -202
- package/lib/commands/functions/detail.js +23 -34
- package/lib/commands/functions/invoke.js +69 -75
- package/lib/commands/functions/layer/bind.js +102 -105
- package/lib/commands/functions/layer/create.js +29 -35
- package/lib/commands/functions/layer/delete.js +42 -48
- package/lib/commands/functions/layer/download.js +52 -58
- package/lib/commands/functions/layer/list.js +44 -50
- package/lib/commands/functions/layer/sort.js +39 -45
- package/lib/commands/functions/list.js +25 -36
- package/lib/commands/functions/log.js +65 -73
- package/lib/commands/functions/run.js +118 -116
- package/lib/commands/functions/trigger-create.js +32 -43
- package/lib/commands/functions/trigger-delete.js +50 -61
- package/lib/commands/functions/version/list.js +29 -40
- package/lib/commands/functions/version/publish.js +11 -22
- package/lib/commands/gateway/create.js +50 -61
- package/lib/commands/gateway/delete.js +38 -49
- package/lib/commands/gateway/domain.js +65 -80
- package/lib/commands/gateway/list.js +31 -42
- package/lib/commands/gateway/switch.js +48 -61
- package/lib/commands/helpers/init.js +226 -249
- package/lib/commands/helpers/new.js +35 -46
- package/lib/commands/helpers/open.js +22 -33
- package/lib/commands/hosting/hosting.js +157 -178
- package/lib/commands/index.js +1 -0
- package/lib/commands/lowcode/app.js +114 -144
- package/lib/commands/lowcode/comps.js +136 -127
- package/lib/commands/lowcode/utils.js +11 -22
- package/lib/commands/pull/pull.js +33 -46
- package/lib/commands/run/delete.js +35 -46
- package/lib/commands/run/image/delete.js +32 -39
- package/lib/commands/run/image/download.js +26 -33
- package/lib/commands/run/image/list.js +41 -48
- package/lib/commands/run/image/upload.js +26 -33
- package/lib/commands/run/list.js +32 -43
- package/lib/commands/run/service/config.js +17 -28
- package/lib/commands/run/service/deploy.js +15 -26
- package/lib/commands/run/service/list.js +48 -59
- package/lib/commands/run/service/update.js +7 -18
- package/lib/commands/run/standalonegateway/create.js +35 -42
- package/lib/commands/run/standalonegateway/destroy.js +23 -30
- package/lib/commands/run/standalonegateway/list.js +19 -26
- package/lib/commands/run/standalonegateway/package.js +31 -38
- package/lib/commands/run/standalonegateway/turn.js +27 -34
- package/lib/commands/run/version/create.js +198 -205
- package/lib/commands/run/version/delete.js +31 -38
- package/lib/commands/run/version/list.js +42 -49
- package/lib/commands/run/version/modify.js +27 -34
- package/lib/commands/run/version/update.js +201 -208
- package/lib/commands/runf/base.js +216 -237
- package/lib/commands/self-update.js +59 -72
- package/lib/commands/smart.js +66 -79
- package/lib/commands/storage/storage.js +192 -219
- package/lib/commands/third/thirdAttach.js +16 -27
- package/lib/commands/utils.js +119 -149
- package/lib/db/index.js +48 -67
- package/lib/decorators/captureError.js +10 -21
- package/lib/decorators/guard.js +11 -22
- package/lib/decorators/injectParams.js +29 -40
- package/lib/decorators/params/common.js +5 -2
- package/lib/decorators/params/index.js +3 -12
- package/lib/env/domain.js +13 -28
- package/lib/env/index.js +25 -44
- package/lib/env/login.js +30 -45
- package/lib/function/alias.js +31 -44
- package/lib/function/base.js +187 -215
- package/lib/function/code.js +8 -19
- package/lib/function/concurrency.js +43 -58
- package/lib/function/create.js +43 -53
- package/lib/function/delete.js +22 -35
- package/lib/function/layer/attach.js +33 -46
- package/lib/function/layer/create.js +34 -45
- package/lib/function/layer/delete.js +5 -16
- package/lib/function/layer/download.js +11 -22
- package/lib/function/layer/list.js +12 -25
- package/lib/function/layer/sort.js +6 -17
- package/lib/function/trigger.js +65 -82
- package/lib/function/update.js +24 -32
- package/lib/function/version.js +29 -42
- package/lib/function/vpc.js +12 -25
- package/lib/gateway/index.js +77 -104
- package/lib/hosting.js +157 -188
- package/lib/run/delete.js +3 -12
- package/lib/run/image/build.js +6 -15
- package/lib/run/image/delete.js +3 -12
- package/lib/run/image/info.js +3 -12
- package/lib/run/image/list.js +6 -15
- package/lib/run/list.js +19 -30
- package/lib/run/repo.js +6 -15
- package/lib/run/service/common.js +160 -173
- package/lib/run/service/config.js +44 -57
- package/lib/run/service/deployPackage.js +33 -44
- package/lib/run/service/list.js +8 -14
- package/lib/run/service/showLogs.js +69 -90
- package/lib/run/service/update.js +50 -63
- package/lib/run/standalonegateway/create.js +3 -12
- package/lib/run/standalonegateway/destroy.js +3 -12
- package/lib/run/standalonegateway/list.js +3 -12
- package/lib/run/standalonegateway/package/list.js +3 -12
- package/lib/run/standalonegateway/turn/off.js +3 -12
- package/lib/run/standalonegateway/turn/on.js +3 -12
- package/lib/run/version/create.js +41 -31
- package/lib/run/version/delete.js +3 -12
- package/lib/run/version/list.js +3 -12
- package/lib/run/version/modify.js +3 -12
- package/lib/run/version/repo.js +6 -15
- package/lib/run/version/update.js +37 -26
- package/lib/storage.js +62 -93
- package/lib/third/index.js +6 -17
- package/lib/utils/ai/banner.js +49 -60
- package/lib/utils/ai/claudeWindows.js +2 -2
- package/lib/utils/ai/config.js +169 -206
- package/lib/utils/ai/ensureFiles.js +6 -17
- package/lib/utils/ai/env.js +16 -27
- package/lib/utils/ai/envLocalManager.js +35 -52
- package/lib/utils/ai/router.js +927 -1005
- package/lib/utils/ai/setup.js +527 -563
- package/lib/utils/auth.js +3 -14
- package/lib/utils/checkTcbrEnv.js +20 -31
- package/lib/utils/cli-table.js +6 -1
- package/lib/utils/config.js +4 -13
- package/lib/utils/dts.js +98 -113
- package/lib/utils/env.js +154 -175
- package/lib/utils/function-packer.js +29 -42
- package/lib/utils/log.js +10 -21
- package/lib/utils/mcp-config-modifier.js +105 -120
- package/lib/utils/net/cloud-api-request.js +15 -23
- package/lib/utils/net/credential.js +26 -39
- package/lib/utils/net/http-request.js +63 -80
- package/lib/utils/net/manager-service.js +22 -35
- package/lib/utils/notice.js +16 -27
- package/lib/utils/output/loading.js +3 -12
- package/lib/utils/parallel.js +32 -43
- package/lib/utils/platform/mac.js +4 -15
- package/lib/utils/platform/port.js +4 -15
- package/lib/utils/prompt/select.js +6 -15
- package/lib/utils/report.js +28 -33
- package/lib/utils/reporter/agree.js +11 -22
- package/lib/utils/reporter/download.js +17 -28
- package/lib/utils/reporter/usage.js +12 -23
- package/lib/utils/store/auth.js +17 -30
- package/lib/utils/store/config.js +11 -25
- package/lib/utils/store/db.js +17 -36
- package/lib/utils/tcbrApi/callTcbrApi.js +19 -28
- package/lib/utils/template-manager.js +215 -242
- package/lib/utils/template.js +81 -96
- package/lib/utils/tools/common.js +45 -56
- package/lib/utils/tools/time.js +5 -16
- package/lib/utils/url.js +10 -4
- package/package.json +2 -2
- package/specs/ag-command/design.md +421 -0
- package/specs/ag-command/doc.md +204 -0
- package/specs/ag-command/requirements.md +173 -0
- package/specs/ag-command/summary.md +174 -0
- package/specs/ag-command/tasks.md +197 -0
- package/specs/ag-command/usage-guide.md +420 -0
- package/tsconfig.json +1 -1
- package/types/commands/ag/base.d.ts +44 -0
- package/types/commands/ag/create.d.ts +25 -0
- package/types/commands/ag/delete.d.ts +32 -0
- package/types/commands/ag/deploy.d.ts +31 -0
- package/types/commands/ag/detail.d.ts +28 -0
- package/types/commands/ag/index.d.ts +6 -0
- package/types/commands/ag/list.d.ts +35 -0
- package/types/commands/ag/run.d.ts +52 -0
- package/types/commands/cloudrun/base.d.ts +10 -0
- package/types/commands/index.d.ts +1 -0
package/lib/utils/auth.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.getLoginState = exports.authSupevisor = void 0;
|
|
13
4
|
const toolbox_1 = require("@cloudbase/toolbox");
|
|
@@ -19,10 +10,8 @@ exports.authSupevisor = toolbox_1.AuthSupevisor.getInstance({
|
|
|
19
10
|
timeout: constant_1.REQUEST_TIMEOUT,
|
|
20
11
|
throwError: true
|
|
21
12
|
});
|
|
22
|
-
function getLoginState() {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return state;
|
|
26
|
-
});
|
|
13
|
+
async function getLoginState() {
|
|
14
|
+
const state = exports.authSupevisor.getLoginState();
|
|
15
|
+
return state;
|
|
27
16
|
}
|
|
28
17
|
exports.getLoginState = getLoginState;
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -40,29 +31,27 @@ ${(0, i18n_1.t)('更新云托管服务')}:tcb run service:update --envId <envI
|
|
|
40
31
|
${(0, i18n_1.t)('部署云托管服务')}:tcb run deploy --envId <envId> --serviceName <serviceName> --containerPort <containerPort>
|
|
41
32
|
${(0, i18n_1.t)('更新服务基础配置')}:tcb run service:config --envId <envId> --serviceName <serviceName>
|
|
42
33
|
`;
|
|
43
|
-
function checkTcbrEnv(envId, isTcbr) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
EnvId: envId
|
|
50
|
-
});
|
|
51
|
-
const { EnvList } = res;
|
|
52
|
-
const envInfo = EnvList === null || EnvList === void 0 ? void 0 : EnvList.find((item) => (item === null || item === void 0 ? void 0 : item.EnvId) === envId);
|
|
53
|
-
if (envInfo === undefined) {
|
|
54
|
-
throw new error_1.CloudBaseError((0, i18n_1.t)('无法读取到有效的环境信息,请检查环境 ID 是否正确\nrequestId: {{requestId}}', { requestId: res === null || res === void 0 ? void 0 : res.RequestId }));
|
|
55
|
-
}
|
|
56
|
-
if ((envInfo.EnvType === 'tcbr' && isTcbr) || (envInfo.EnvType !== 'tcbr' && !isTcbr)) {
|
|
57
|
-
return 0;
|
|
58
|
-
}
|
|
59
|
-
else if (envInfo.EnvType === 'tcbr' && !isTcbr) {
|
|
60
|
-
return 1;
|
|
61
|
-
}
|
|
62
|
-
else if (envInfo.EnvType !== 'tcbr' && isTcbr) {
|
|
63
|
-
return 2;
|
|
64
|
-
}
|
|
34
|
+
async function checkTcbrEnv(envId, isTcbr) {
|
|
35
|
+
if (envId === undefined) {
|
|
36
|
+
throw new error_1.CloudBaseError((0, i18n_1.t)('请使用 -e 或 --envId 指定环境 ID'));
|
|
37
|
+
}
|
|
38
|
+
const { data: res } = await (0, tcbrApi_1.callTcbrApi)('DescribeCloudRunEnvs', {
|
|
39
|
+
EnvId: envId
|
|
65
40
|
});
|
|
41
|
+
const { EnvList } = res;
|
|
42
|
+
const envInfo = EnvList === null || EnvList === void 0 ? void 0 : EnvList.find((item) => (item === null || item === void 0 ? void 0 : item.EnvId) === envId);
|
|
43
|
+
if (envInfo === undefined) {
|
|
44
|
+
throw new error_1.CloudBaseError((0, i18n_1.t)('无法读取到有效的环境信息,请检查环境 ID 是否正确\nrequestId: {{requestId}}', { requestId: res === null || res === void 0 ? void 0 : res.RequestId }));
|
|
45
|
+
}
|
|
46
|
+
if ((envInfo.EnvType === 'tcbr' && isTcbr) || (envInfo.EnvType !== 'tcbr' && !isTcbr)) {
|
|
47
|
+
return 0;
|
|
48
|
+
}
|
|
49
|
+
else if (envInfo.EnvType === 'tcbr' && !isTcbr) {
|
|
50
|
+
return 1;
|
|
51
|
+
}
|
|
52
|
+
else if (envInfo.EnvType !== 'tcbr' && isTcbr) {
|
|
53
|
+
return 2;
|
|
54
|
+
}
|
|
66
55
|
}
|
|
67
56
|
exports.checkTcbrEnv = checkTcbrEnv;
|
|
68
57
|
function logEnvCheck(envId, warningType) {
|
package/lib/utils/cli-table.js
CHANGED
|
@@ -10,7 +10,12 @@ function printHorizontalTable(head, data = [], options) {
|
|
|
10
10
|
if (!(data === null || data === void 0 ? void 0 : data.length)) {
|
|
11
11
|
console.log((0, i18n_1.t)('列表数据为空'));
|
|
12
12
|
}
|
|
13
|
-
const table = new cli_table3_1.default(
|
|
13
|
+
const table = new cli_table3_1.default({
|
|
14
|
+
head,
|
|
15
|
+
style: { head: ['yellow'] },
|
|
16
|
+
colAligns: new Array(head.length).fill('center'),
|
|
17
|
+
...options
|
|
18
|
+
});
|
|
14
19
|
data.forEach((item) => {
|
|
15
20
|
table.push(item);
|
|
16
21
|
});
|
package/lib/utils/config.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -34,12 +25,12 @@ function getPrivateSettings(config, cmd) {
|
|
|
34
25
|
const currentConfig = cmd ? config === null || config === void 0 ? void 0 : config[cmd] : config;
|
|
35
26
|
if (hasOwn(currentConfig || {}, 'privateSettings') ||
|
|
36
27
|
hasOwn(commonConfig || {}, 'privateSettings')) {
|
|
37
|
-
return
|
|
28
|
+
return { ...commonConfig.privateSettings, ...currentConfig.privateSettings };
|
|
38
29
|
}
|
|
39
30
|
return undefined;
|
|
40
31
|
}
|
|
41
32
|
exports.getPrivateSettings = getPrivateSettings;
|
|
42
|
-
const getCloudBaseConfig = (configPath) =>
|
|
33
|
+
const getCloudBaseConfig = async (configPath) => {
|
|
43
34
|
var _a;
|
|
44
35
|
const args = (0, exports.getArgs)();
|
|
45
36
|
if (args._.includes('help') || args.help) {
|
|
@@ -50,10 +41,10 @@ const getCloudBaseConfig = (configPath) => __awaiter(void 0, void 0, void 0, fun
|
|
|
50
41
|
const parser = new toolbox_1.ConfigParser({
|
|
51
42
|
configPath: specificConfigPath
|
|
52
43
|
});
|
|
53
|
-
const config =
|
|
44
|
+
const config = await parser.get();
|
|
54
45
|
if ((config === null || config === void 0 ? void 0 : config.functionDefaultConfig) && ((_a = config === null || config === void 0 ? void 0 : config.functions) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
55
46
|
config.functions = config.functions.map((rawConfig) => lodash_1.default.merge({}, config.functionDefaultConfig, rawConfig));
|
|
56
47
|
}
|
|
57
48
|
return config;
|
|
58
|
-
}
|
|
49
|
+
};
|
|
59
50
|
exports.getCloudBaseConfig = getCloudBaseConfig;
|
package/lib/utils/dts.js
CHANGED
|
@@ -1,43 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.generateDataModelDTS = void 0;
|
|
13
4
|
const json_schema_to_typescript_1 = require("json-schema-to-typescript");
|
|
14
5
|
const lodash_1 = require("lodash");
|
|
15
6
|
const tools_1 = require("./tools");
|
|
16
7
|
const i18n_1 = require("../i18n");
|
|
17
|
-
function generateDataModelDTS(dataModelList) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const result = `
|
|
8
|
+
async function generateDataModelDTS(dataModelList) {
|
|
9
|
+
const dtsList = await Promise.all(dataModelList.map(async (item) => {
|
|
10
|
+
let dts = await _handleOne(item.name, item.schema);
|
|
11
|
+
return {
|
|
12
|
+
name: item.name,
|
|
13
|
+
title: item.title,
|
|
14
|
+
dts
|
|
15
|
+
};
|
|
16
|
+
}));
|
|
17
|
+
const result = `
|
|
28
18
|
import { DataModelMethods } from "@cloudbase/wx-cloud-client-sdk";
|
|
29
19
|
${dtsList.map((item) => item.dts).join('\n')}
|
|
30
20
|
|
|
31
21
|
interface IModels {
|
|
32
22
|
${dtsList
|
|
33
|
-
|
|
34
|
-
|
|
23
|
+
.map((item) => {
|
|
24
|
+
return `
|
|
35
25
|
/**
|
|
36
26
|
* ${(0, i18n_1.t)('数据模型')}:${item.title}
|
|
37
27
|
*/
|
|
38
28
|
${_toValidFieldName(item.name)}: DataModelMethods<${getModelInterfaceName(item.name)}>;`;
|
|
39
|
-
|
|
40
|
-
|
|
29
|
+
})
|
|
30
|
+
.join('\n')}
|
|
41
31
|
}
|
|
42
32
|
|
|
43
33
|
declare module "@cloudbase/wx-cloud-client-sdk" {
|
|
@@ -49,106 +39,101 @@ declare global {
|
|
|
49
39
|
models: IModels;
|
|
50
40
|
}
|
|
51
41
|
}`;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
42
|
+
return result;
|
|
43
|
+
async function _handleOne(name, schema) {
|
|
44
|
+
if (!(schema === null || schema === void 0 ? void 0 : schema.properties))
|
|
45
|
+
return `interface ${getModelInterfaceName(name)} {}`;
|
|
46
|
+
Object.keys(schema.properties).forEach((key) => {
|
|
47
|
+
if (schema.properties[key]['x-system']) {
|
|
48
|
+
delete schema.properties[key];
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
Object.keys(schema.properties).forEach((key) => {
|
|
52
|
+
const field = schema.properties[key];
|
|
53
|
+
if (['related', 'father-son'].includes(field.format)) {
|
|
54
|
+
schema.properties[`@${key}`] = {
|
|
55
|
+
type: 'object',
|
|
56
|
+
description: (0, i18n_1.t)('关联{{title}}对象', { title: field.title }),
|
|
57
|
+
properties: {
|
|
58
|
+
v1: {
|
|
66
59
|
type: 'object',
|
|
67
|
-
description: (0, i18n_1.t)('关联{{title}}对象', { title: field.title }),
|
|
68
60
|
properties: {
|
|
69
|
-
|
|
70
|
-
type: '
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
format: field.format,
|
|
75
|
-
'x-parent': {
|
|
76
|
-
parentDataSourceName: field['x-parent'].parentDataSourceName
|
|
77
|
-
}
|
|
78
|
-
}
|
|
61
|
+
record: {
|
|
62
|
+
type: 'string',
|
|
63
|
+
format: field.format,
|
|
64
|
+
'x-parent': {
|
|
65
|
+
parentDataSourceName: field['x-parent'].parentDataSourceName
|
|
79
66
|
}
|
|
80
67
|
}
|
|
81
68
|
}
|
|
82
|
-
}
|
|
83
|
-
schema.properties[key].format = '';
|
|
69
|
+
}
|
|
84
70
|
}
|
|
85
|
-
}
|
|
86
|
-
schema
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
71
|
+
};
|
|
72
|
+
schema.properties[key].format = '';
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
schema = JSON.parse(JSON.stringify(schema, (_, value) => {
|
|
76
|
+
if ((0, lodash_1.has)(value, 'title') && !(0, lodash_1.has)(value, 'title.title')) {
|
|
77
|
+
(0, lodash_1.set)(value, 'description', value['title'] + '\n' + value['description']);
|
|
78
|
+
delete value['title'];
|
|
79
|
+
}
|
|
80
|
+
return value;
|
|
81
|
+
}));
|
|
82
|
+
const dts = await _compile(name, schema);
|
|
83
|
+
return dts;
|
|
84
|
+
}
|
|
85
|
+
async function _compile(name, jsonschema) {
|
|
86
|
+
try {
|
|
87
|
+
let dts = await (0, json_schema_to_typescript_1.compile)(jsonschema, getModelInterfaceName(name), {
|
|
88
|
+
additionalProperties: false,
|
|
89
|
+
bannerComment: '',
|
|
90
|
+
format: true,
|
|
91
|
+
unknownAny: false,
|
|
92
|
+
customName(_schema) {
|
|
93
|
+
var _a, _b;
|
|
94
|
+
const format = _schema.format;
|
|
95
|
+
let name = '';
|
|
96
|
+
if (['one-one', 'many-one', 'related', 'father-son'].includes(format)) {
|
|
97
|
+
name = getModelInterfaceName((_a = _schema === null || _schema === void 0 ? void 0 : _schema['x-parent']) === null || _a === void 0 ? void 0 : _a.parentDataSourceName);
|
|
90
98
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
99
|
-
try {
|
|
100
|
-
let dts = yield (0, json_schema_to_typescript_1.compile)(jsonschema, getModelInterfaceName(name), {
|
|
101
|
-
additionalProperties: false,
|
|
102
|
-
bannerComment: '',
|
|
103
|
-
format: true,
|
|
104
|
-
unknownAny: false,
|
|
105
|
-
customName(_schema) {
|
|
106
|
-
var _a, _b;
|
|
107
|
-
const format = _schema.format;
|
|
108
|
-
let name = '';
|
|
109
|
-
if (['one-one', 'many-one', 'related', 'father-son'].includes(format)) {
|
|
110
|
-
name = getModelInterfaceName((_a = _schema === null || _schema === void 0 ? void 0 : _schema['x-parent']) === null || _a === void 0 ? void 0 : _a.parentDataSourceName);
|
|
111
|
-
}
|
|
112
|
-
if (['one-many', 'many-many'].includes(format)) {
|
|
113
|
-
name = `ARRAY_TYPE_${getModelInterfaceName((_b = _schema === null || _schema === void 0 ? void 0 : _schema['x-parent']) === null || _b === void 0 ? void 0 : _b.parentDataSourceName)}`;
|
|
114
|
-
}
|
|
115
|
-
if (name) {
|
|
116
|
-
name = `${name}_TAIL${(0, tools_1.uuidv4)()}_END_`;
|
|
117
|
-
}
|
|
118
|
-
return name || undefined;
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
dts = dts
|
|
122
|
-
.replace(/export interface/g, 'interface')
|
|
123
|
-
.replace(/ARRAY_TYPE_(.*);/g, '$1[]')
|
|
124
|
-
.replace(/_TAIL.*?_END_/g, '')
|
|
125
|
-
.replace(/[\s\S]*?(?=interface)/, '');
|
|
126
|
-
return dts;
|
|
127
|
-
}
|
|
128
|
-
catch (e) {
|
|
129
|
-
console.error((0, i18n_1.t)('_compile error: {{error}}', { error: e }));
|
|
130
|
-
return '';
|
|
99
|
+
if (['one-many', 'many-many'].includes(format)) {
|
|
100
|
+
name = `ARRAY_TYPE_${getModelInterfaceName((_b = _schema === null || _schema === void 0 ? void 0 : _schema['x-parent']) === null || _b === void 0 ? void 0 : _b.parentDataSourceName)}`;
|
|
101
|
+
}
|
|
102
|
+
if (name) {
|
|
103
|
+
name = `${name}_TAIL${(0, tools_1.uuidv4)()}_END_`;
|
|
104
|
+
}
|
|
105
|
+
return name || undefined;
|
|
131
106
|
}
|
|
132
107
|
});
|
|
108
|
+
dts = dts
|
|
109
|
+
.replace(/export interface/g, 'interface')
|
|
110
|
+
.replace(/ARRAY_TYPE_(.*);/g, '$1[]')
|
|
111
|
+
.replace(/_TAIL.*?_END_/g, '')
|
|
112
|
+
.replace(/[\s\S]*?(?=interface)/, '');
|
|
113
|
+
return dts;
|
|
133
114
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
result = '_' + result;
|
|
138
|
-
}
|
|
139
|
-
return result;
|
|
115
|
+
catch (e) {
|
|
116
|
+
console.error((0, i18n_1.t)('_compile error: {{error}}', { error: e }));
|
|
117
|
+
return '';
|
|
140
118
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
.replace(/^_[a-z]/g, (match) => match.toUpperCase())
|
|
147
|
-
.replace(/_[a-z]/g, (match) => match.substr(1, match.length).toUpperCase())
|
|
148
|
-
.replace(/([\d$]+[a-zA-Z])/g, (match) => match.toUpperCase())
|
|
149
|
-
.replace(/\s+([a-zA-Z])/g, (match) => (0, lodash_1.trim)(match.toUpperCase()))
|
|
150
|
-
.replace(/\s/g, ''));
|
|
119
|
+
}
|
|
120
|
+
function _toValidFieldName(name) {
|
|
121
|
+
let result = name.replace(/[^a-zA-Z0-9_$]/g, '_');
|
|
122
|
+
if (/^[0-9]/.test(result)) {
|
|
123
|
+
result = '_' + result;
|
|
151
124
|
}
|
|
152
|
-
|
|
125
|
+
return result;
|
|
126
|
+
}
|
|
127
|
+
function getModelInterfaceName(name) {
|
|
128
|
+
if (!name)
|
|
129
|
+
return '';
|
|
130
|
+
return (0, lodash_1.upperFirst)((0, lodash_1.deburr)(`IModal_${name}`)
|
|
131
|
+
.replace(/(^\s*[^a-zA-Z_$])|([^a-zA-Z_$\d])/g, ' ')
|
|
132
|
+
.replace(/^_[a-z]/g, (match) => match.toUpperCase())
|
|
133
|
+
.replace(/_[a-z]/g, (match) => match.substr(1, match.length).toUpperCase())
|
|
134
|
+
.replace(/([\d$]+[a-zA-Z])/g, (match) => match.toUpperCase())
|
|
135
|
+
.replace(/\s+([a-zA-Z])/g, (match) => (0, lodash_1.trim)(match.toUpperCase()))
|
|
136
|
+
.replace(/\s/g, ''));
|
|
137
|
+
}
|
|
153
138
|
}
|
|
154
139
|
exports.generateDataModelDTS = generateDataModelDTS;
|