@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.
Files changed (205) hide show
  1. package/lib/auth/login.js +51 -65
  2. package/lib/auth/logout.js +3 -14
  3. package/lib/commands/account/login.js +136 -149
  4. package/lib/commands/account/logout.js +3 -14
  5. package/lib/commands/ag/base.js +203 -0
  6. package/lib/commands/ag/create.js +301 -0
  7. package/lib/commands/ag/debug/index.html +699 -0
  8. package/lib/commands/ag/delete.js +200 -0
  9. package/lib/commands/ag/deploy.js +185 -0
  10. package/lib/commands/ag/detail.js +113 -0
  11. package/lib/commands/ag/index.js +22 -0
  12. package/lib/commands/ag/list.js +155 -0
  13. package/lib/commands/ag/run.js +644 -0
  14. package/lib/commands/ai/index.js +76 -95
  15. package/lib/commands/cloudfunction/base.js +182 -203
  16. package/lib/commands/cloudrun/base.js +578 -603
  17. package/lib/commands/common.js +48 -63
  18. package/lib/commands/config/delete.js +16 -27
  19. package/lib/commands/config/get.js +13 -24
  20. package/lib/commands/config/list.js +16 -27
  21. package/lib/commands/config/set.js +33 -44
  22. package/lib/commands/db/base.js +221 -240
  23. package/lib/commands/env/base.js +36 -49
  24. package/lib/commands/env/domain.js +79 -94
  25. package/lib/commands/env/login.js +120 -135
  26. package/lib/commands/framework/index.js +32 -49
  27. package/lib/commands/fun/base.js +223 -244
  28. package/lib/commands/functions/alias/getRoute.js +33 -44
  29. package/lib/commands/functions/alias/setRoute.js +36 -47
  30. package/lib/commands/functions/code-download.js +43 -54
  31. package/lib/commands/functions/code-update.js +23 -34
  32. package/lib/commands/functions/concurrency/delete.js +11 -22
  33. package/lib/commands/functions/concurrency/list.js +20 -31
  34. package/lib/commands/functions/concurrency/set.js +13 -24
  35. package/lib/commands/functions/config-update.js +30 -41
  36. package/lib/commands/functions/copy.js +12 -23
  37. package/lib/commands/functions/delete.js +30 -41
  38. package/lib/commands/functions/deploy.js +184 -202
  39. package/lib/commands/functions/detail.js +23 -34
  40. package/lib/commands/functions/invoke.js +69 -75
  41. package/lib/commands/functions/layer/bind.js +102 -105
  42. package/lib/commands/functions/layer/create.js +29 -35
  43. package/lib/commands/functions/layer/delete.js +42 -48
  44. package/lib/commands/functions/layer/download.js +52 -58
  45. package/lib/commands/functions/layer/list.js +44 -50
  46. package/lib/commands/functions/layer/sort.js +39 -45
  47. package/lib/commands/functions/list.js +25 -36
  48. package/lib/commands/functions/log.js +65 -73
  49. package/lib/commands/functions/run.js +118 -116
  50. package/lib/commands/functions/trigger-create.js +32 -43
  51. package/lib/commands/functions/trigger-delete.js +50 -61
  52. package/lib/commands/functions/version/list.js +29 -40
  53. package/lib/commands/functions/version/publish.js +11 -22
  54. package/lib/commands/gateway/create.js +50 -61
  55. package/lib/commands/gateway/delete.js +38 -49
  56. package/lib/commands/gateway/domain.js +65 -80
  57. package/lib/commands/gateway/list.js +31 -42
  58. package/lib/commands/gateway/switch.js +48 -61
  59. package/lib/commands/helpers/init.js +226 -249
  60. package/lib/commands/helpers/new.js +35 -46
  61. package/lib/commands/helpers/open.js +22 -33
  62. package/lib/commands/hosting/hosting.js +157 -178
  63. package/lib/commands/index.js +1 -0
  64. package/lib/commands/lowcode/app.js +114 -144
  65. package/lib/commands/lowcode/comps.js +136 -127
  66. package/lib/commands/lowcode/utils.js +11 -22
  67. package/lib/commands/pull/pull.js +33 -46
  68. package/lib/commands/run/delete.js +35 -46
  69. package/lib/commands/run/image/delete.js +32 -39
  70. package/lib/commands/run/image/download.js +26 -33
  71. package/lib/commands/run/image/list.js +41 -48
  72. package/lib/commands/run/image/upload.js +26 -33
  73. package/lib/commands/run/list.js +32 -43
  74. package/lib/commands/run/service/config.js +17 -28
  75. package/lib/commands/run/service/deploy.js +15 -26
  76. package/lib/commands/run/service/list.js +48 -59
  77. package/lib/commands/run/service/update.js +7 -18
  78. package/lib/commands/run/standalonegateway/create.js +35 -42
  79. package/lib/commands/run/standalonegateway/destroy.js +23 -30
  80. package/lib/commands/run/standalonegateway/list.js +19 -26
  81. package/lib/commands/run/standalonegateway/package.js +31 -38
  82. package/lib/commands/run/standalonegateway/turn.js +27 -34
  83. package/lib/commands/run/version/create.js +198 -205
  84. package/lib/commands/run/version/delete.js +31 -38
  85. package/lib/commands/run/version/list.js +42 -49
  86. package/lib/commands/run/version/modify.js +27 -34
  87. package/lib/commands/run/version/update.js +201 -208
  88. package/lib/commands/runf/base.js +216 -237
  89. package/lib/commands/self-update.js +59 -72
  90. package/lib/commands/smart.js +66 -79
  91. package/lib/commands/storage/storage.js +192 -219
  92. package/lib/commands/third/thirdAttach.js +16 -27
  93. package/lib/commands/utils.js +119 -149
  94. package/lib/db/index.js +48 -67
  95. package/lib/decorators/captureError.js +10 -21
  96. package/lib/decorators/guard.js +11 -22
  97. package/lib/decorators/injectParams.js +29 -40
  98. package/lib/decorators/params/common.js +5 -2
  99. package/lib/decorators/params/index.js +3 -12
  100. package/lib/env/domain.js +13 -28
  101. package/lib/env/index.js +25 -44
  102. package/lib/env/login.js +30 -45
  103. package/lib/function/alias.js +31 -44
  104. package/lib/function/base.js +187 -215
  105. package/lib/function/code.js +8 -19
  106. package/lib/function/concurrency.js +43 -58
  107. package/lib/function/create.js +43 -53
  108. package/lib/function/delete.js +22 -35
  109. package/lib/function/layer/attach.js +33 -46
  110. package/lib/function/layer/create.js +34 -45
  111. package/lib/function/layer/delete.js +5 -16
  112. package/lib/function/layer/download.js +11 -22
  113. package/lib/function/layer/list.js +12 -25
  114. package/lib/function/layer/sort.js +6 -17
  115. package/lib/function/trigger.js +65 -82
  116. package/lib/function/update.js +24 -32
  117. package/lib/function/version.js +29 -42
  118. package/lib/function/vpc.js +12 -25
  119. package/lib/gateway/index.js +77 -104
  120. package/lib/hosting.js +157 -188
  121. package/lib/run/delete.js +3 -12
  122. package/lib/run/image/build.js +6 -15
  123. package/lib/run/image/delete.js +3 -12
  124. package/lib/run/image/info.js +3 -12
  125. package/lib/run/image/list.js +6 -15
  126. package/lib/run/list.js +19 -30
  127. package/lib/run/repo.js +6 -15
  128. package/lib/run/service/common.js +160 -173
  129. package/lib/run/service/config.js +44 -57
  130. package/lib/run/service/deployPackage.js +33 -44
  131. package/lib/run/service/list.js +8 -14
  132. package/lib/run/service/showLogs.js +69 -90
  133. package/lib/run/service/update.js +50 -63
  134. package/lib/run/standalonegateway/create.js +3 -12
  135. package/lib/run/standalonegateway/destroy.js +3 -12
  136. package/lib/run/standalonegateway/list.js +3 -12
  137. package/lib/run/standalonegateway/package/list.js +3 -12
  138. package/lib/run/standalonegateway/turn/off.js +3 -12
  139. package/lib/run/standalonegateway/turn/on.js +3 -12
  140. package/lib/run/version/create.js +41 -31
  141. package/lib/run/version/delete.js +3 -12
  142. package/lib/run/version/list.js +3 -12
  143. package/lib/run/version/modify.js +3 -12
  144. package/lib/run/version/repo.js +6 -15
  145. package/lib/run/version/update.js +37 -26
  146. package/lib/storage.js +62 -93
  147. package/lib/third/index.js +6 -17
  148. package/lib/utils/ai/banner.js +49 -60
  149. package/lib/utils/ai/claudeWindows.js +2 -2
  150. package/lib/utils/ai/config.js +169 -206
  151. package/lib/utils/ai/ensureFiles.js +6 -17
  152. package/lib/utils/ai/env.js +16 -27
  153. package/lib/utils/ai/envLocalManager.js +35 -52
  154. package/lib/utils/ai/router.js +927 -1005
  155. package/lib/utils/ai/setup.js +527 -563
  156. package/lib/utils/auth.js +3 -14
  157. package/lib/utils/checkTcbrEnv.js +20 -31
  158. package/lib/utils/cli-table.js +6 -1
  159. package/lib/utils/config.js +4 -13
  160. package/lib/utils/dts.js +98 -113
  161. package/lib/utils/env.js +154 -175
  162. package/lib/utils/function-packer.js +29 -42
  163. package/lib/utils/log.js +10 -21
  164. package/lib/utils/mcp-config-modifier.js +105 -120
  165. package/lib/utils/net/cloud-api-request.js +15 -23
  166. package/lib/utils/net/credential.js +26 -39
  167. package/lib/utils/net/http-request.js +63 -80
  168. package/lib/utils/net/manager-service.js +22 -35
  169. package/lib/utils/notice.js +16 -27
  170. package/lib/utils/output/loading.js +3 -12
  171. package/lib/utils/parallel.js +32 -43
  172. package/lib/utils/platform/mac.js +4 -15
  173. package/lib/utils/platform/port.js +4 -15
  174. package/lib/utils/prompt/select.js +6 -15
  175. package/lib/utils/report.js +28 -33
  176. package/lib/utils/reporter/agree.js +11 -22
  177. package/lib/utils/reporter/download.js +17 -28
  178. package/lib/utils/reporter/usage.js +12 -23
  179. package/lib/utils/store/auth.js +17 -30
  180. package/lib/utils/store/config.js +11 -25
  181. package/lib/utils/store/db.js +17 -36
  182. package/lib/utils/tcbrApi/callTcbrApi.js +19 -28
  183. package/lib/utils/template-manager.js +215 -242
  184. package/lib/utils/template.js +81 -96
  185. package/lib/utils/tools/common.js +45 -56
  186. package/lib/utils/tools/time.js +5 -16
  187. package/lib/utils/url.js +10 -4
  188. package/package.json +2 -2
  189. package/specs/ag-command/design.md +421 -0
  190. package/specs/ag-command/doc.md +204 -0
  191. package/specs/ag-command/requirements.md +173 -0
  192. package/specs/ag-command/summary.md +174 -0
  193. package/specs/ag-command/tasks.md +197 -0
  194. package/specs/ag-command/usage-guide.md +420 -0
  195. package/tsconfig.json +1 -1
  196. package/types/commands/ag/base.d.ts +44 -0
  197. package/types/commands/ag/create.d.ts +25 -0
  198. package/types/commands/ag/delete.d.ts +32 -0
  199. package/types/commands/ag/deploy.d.ts +31 -0
  200. package/types/commands/ag/detail.d.ts +28 -0
  201. package/types/commands/ag/index.d.ts +6 -0
  202. package/types/commands/ag/list.d.ts +35 -0
  203. package/types/commands/ag/run.d.ts +52 -0
  204. package/types/commands/cloudrun/base.d.ts +10 -0
  205. package/types/commands/index.d.ts +1 -0
@@ -11,15 +11,6 @@ var __metadata = (this && this.__metadata) || function (k, v) {
11
11
  var __param = (this && this.__param) || function (paramIndex, decorator) {
12
12
  return function (target, key) { decorator(target, key, paramIndex); }
13
13
  };
14
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
15
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16
- return new (P || (P = Promise))(function (resolve, reject) {
17
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
18
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
19
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
20
- step((generator = generator.apply(thisArg, _arguments || [])).next());
21
- });
22
- };
23
14
  var __importDefault = (this && this.__importDefault) || function (mod) {
24
15
  return (mod && mod.__esModule) ? mod : { "default": mod };
25
16
  };
@@ -51,78 +42,81 @@ let InvokeFunction = class InvokeFunction extends common_1.Command {
51
42
  desc: (0, i18n_1.t)('触发云端部署的云函数')
52
43
  };
53
44
  }
54
- execute(ctx, argsParams, log) {
55
- return __awaiter(this, void 0, void 0, function* () {
56
- const { envId, config: { functions }, options } = ctx;
57
- const name = argsParams === null || argsParams === void 0 ? void 0 : argsParams[0];
58
- let isBatchInvoke = false;
59
- const functionService = yield (0, function_1.getFunctionService)(envId);
60
- if (!name) {
61
- const { isBatch } = yield inquirer_1.default.prompt({
62
- type: 'confirm',
63
- name: 'isBatch',
64
- message: (0, i18n_1.t)('无云函数名称,是否需要触发配置文件中的全部云函数?'),
65
- default: false
66
- });
67
- isBatchInvoke = isBatch;
68
- if (!isBatchInvoke) {
69
- throw new error_1.CloudBaseError((0, i18n_1.t)('请指定云函数名称!'));
70
- }
45
+ async execute(ctx, argsParams, log) {
46
+ const { envId, config: { functions }, options } = ctx;
47
+ const name = argsParams === null || argsParams === void 0 ? void 0 : argsParams[0];
48
+ let isBatchInvoke = false;
49
+ const functionService = await (0, function_1.getFunctionService)(envId);
50
+ if (!name) {
51
+ const { isBatch } = await inquirer_1.default.prompt({
52
+ type: 'confirm',
53
+ name: 'isBatch',
54
+ message: (0, i18n_1.t)('无云函数名称,是否需要触发配置文件中的全部云函数?'),
55
+ default: false
56
+ });
57
+ isBatchInvoke = isBatch;
58
+ if (!isBatchInvoke) {
59
+ throw new error_1.CloudBaseError((0, i18n_1.t)('请指定云函数名称!'));
71
60
  }
72
- let params;
73
- const jsonStringParams = options.params;
74
- if (jsonStringParams) {
75
- try {
76
- params = JSON.parse(jsonStringParams);
77
- }
78
- catch (e) {
79
- console.log(e);
80
- throw new error_1.CloudBaseError((0, i18n_1.t)('jsonStringParams 参数不是正确的 JSON 字符串'));
81
- }
61
+ }
62
+ let params;
63
+ const jsonStringParams = options.params;
64
+ if (jsonStringParams) {
65
+ try {
66
+ params = JSON.parse(jsonStringParams);
67
+ }
68
+ catch (e) {
69
+ console.log(e);
70
+ throw new error_1.CloudBaseError((0, i18n_1.t)('jsonStringParams 参数不是正确的 JSON 字符串'));
82
71
  }
83
- if (isBatchInvoke) {
84
- return functionService.batchInvokeFunctions({
85
- envId,
86
- functions,
87
- log: true
88
- });
72
+ }
73
+ if (isBatchInvoke) {
74
+ return functionService.batchInvokeFunctions({
75
+ envId,
76
+ functions,
77
+ log: true
78
+ });
79
+ }
80
+ const func = functions.find((item) => item.name === name);
81
+ const configParams = (func === null || func === void 0 ? void 0 : func.params) ? func.params : undefined;
82
+ params = params || configParams;
83
+ const result = await functionService.invokeFunction(name, params);
84
+ if (result.InvokeResult === 0) {
85
+ log.success((0, i18n_1.t)('[{{name}}] 调用成功\n', { name }));
86
+ }
87
+ else {
88
+ log.error((0, i18n_1.t)('[{{name}}] 调用失败\n', { name }));
89
+ }
90
+ const ResMap = {
91
+ Duration: (0, i18n_1.t)('运行时间'),
92
+ MemUsage: (0, i18n_1.t)('内存占用'),
93
+ BillDuration: (0, i18n_1.t)('计费时间'),
94
+ FunctionRequestId: (0, i18n_1.t)('请求 Id '),
95
+ RetMsg: (0, i18n_1.t)('返回结果'),
96
+ ErrMsg: (0, i18n_1.t)('错误信息'),
97
+ Log: (0, i18n_1.t)('调用日志')
98
+ };
99
+ const formatInfo = {
100
+ ...result,
101
+ Duration: Number(result.Duration).toFixed(2) + 'ms',
102
+ MemUsage: Number(Number(result.MemUsage) / Math.pow(1024, 2)).toFixed(2) + 'MB',
103
+ BillDuration: result.BillDuration + 'ms'
104
+ };
105
+ const logInfo = Object.keys(ResMap)
106
+ .map((key) => {
107
+ if (key === 'Log') {
108
+ return `${chalk_1.default.bold.cyan(ResMap[key])}:\n${formatInfo[key]}`;
89
109
  }
90
- const func = functions.find((item) => item.name === name);
91
- const configParams = (func === null || func === void 0 ? void 0 : func.params) ? func.params : undefined;
92
- params = params || configParams;
93
- const result = yield functionService.invokeFunction(name, params);
94
- if (result.InvokeResult === 0) {
95
- log.success((0, i18n_1.t)('[{{name}}] 调用成功\n', { name }));
110
+ else if (result.InvokeResult === 0 && key === 'ErrMsg') {
111
+ return false;
96
112
  }
97
113
  else {
98
- log.error((0, i18n_1.t)('[{{name}}] 调用失败\n', { name }));
114
+ return `${chalk_1.default.bold.cyan(ResMap[key])}:${formatInfo[key]}`;
99
115
  }
100
- const ResMap = {
101
- Duration: (0, i18n_1.t)('运行时间'),
102
- MemUsage: (0, i18n_1.t)('内存占用'),
103
- BillDuration: (0, i18n_1.t)('计费时间'),
104
- FunctionRequestId: (0, i18n_1.t)('请求 Id '),
105
- RetMsg: (0, i18n_1.t)('返回结果'),
106
- ErrMsg: (0, i18n_1.t)('错误信息'),
107
- Log: (0, i18n_1.t)('调用日志')
108
- };
109
- const formatInfo = Object.assign(Object.assign({}, result), { Duration: Number(result.Duration).toFixed(2) + 'ms', MemUsage: Number(Number(result.MemUsage) / Math.pow(1024, 2)).toFixed(2) + 'MB', BillDuration: result.BillDuration + 'ms' });
110
- const logInfo = Object.keys(ResMap)
111
- .map((key) => {
112
- if (key === 'Log') {
113
- return `${chalk_1.default.bold.cyan(ResMap[key])}:\n${formatInfo[key]}`;
114
- }
115
- else if (result.InvokeResult === 0 && key === 'ErrMsg') {
116
- return false;
117
- }
118
- else {
119
- return `${chalk_1.default.bold.cyan(ResMap[key])}:${formatInfo[key]}`;
120
- }
121
- })
122
- .filter((item) => item)
123
- .join('\n');
124
- console.log(logInfo);
125
- });
116
+ })
117
+ .filter((item) => item)
118
+ .join('\n');
119
+ console.log(logInfo);
126
120
  }
127
121
  };
128
122
  __decorate([
@@ -11,15 +11,6 @@ var __metadata = (this && this.__metadata) || function (k, v) {
11
11
  var __param = (this && this.__param) || function (paramIndex, decorator) {
12
12
  return function (target, key) { decorator(target, key, paramIndex); }
13
13
  };
14
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
15
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16
- return new (P || (P = Promise))(function (resolve, reject) {
17
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
18
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
19
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
20
- step((generator = generator.apply(thisArg, _arguments || [])).next());
21
- });
22
- };
23
14
  Object.defineProperty(exports, "__esModule", { value: true });
24
15
  exports.UnAttachFileLayer = exports.AttachFileLayer = void 0;
25
16
  const enquirer_1 = require("enquirer");
@@ -38,7 +29,10 @@ const LayerStatusMap = {
38
29
  };
39
30
  let AttachFileLayer = class AttachFileLayer extends common_1.Command {
40
31
  get options() {
41
- return Object.assign(Object.assign({}, (0, common_2.layerCommonOptions)('bind <name>')), { deprecateCmd: 'functions:layer:bind <name>', options: [
32
+ return {
33
+ ...(0, common_2.layerCommonOptions)('bind <name>'),
34
+ deprecateCmd: 'functions:layer:bind <name>',
35
+ options: [
42
36
  {
43
37
  flags: '-e, --envId <envId>',
44
38
  desc: (0, i18n_1.t)('环境 Id')
@@ -47,69 +41,69 @@ let AttachFileLayer = class AttachFileLayer extends common_1.Command {
47
41
  flags: '--code-secret, <codeSecret>',
48
42
  desc: (0, i18n_1.t)('代码加密的函数的 CodeSecret')
49
43
  }
50
- ], desc: (0, i18n_1.t)('绑定文件层到云函数') });
44
+ ],
45
+ desc: (0, i18n_1.t)('绑定文件层到云函数')
46
+ };
51
47
  }
52
- execute(envId, params, options) {
53
- return __awaiter(this, void 0, void 0, function* () {
54
- const { codeSecret } = options;
55
- const fnName = params === null || params === void 0 ? void 0 : params[0];
56
- const functionService = yield (0, function_1.getFunctionService)(envId);
57
- const loading = (0, utils_1.loadingFactory)();
58
- loading.start((0, i18n_1.t)('数据加载中...'));
59
- const envFunctions = yield functionService.listAllFunctions({
60
- envId
61
- });
62
- const exist = envFunctions.find((fn) => fn.FunctionName === fnName);
63
- if (!exist) {
64
- throw new error_1.CloudBaseError((0, i18n_1.t)('当前环境不存在此函数 [{{fnName}}]', { fnName }));
65
- }
66
- const listLayersRes = yield functionService.listLayers({
67
- offset: 0,
68
- limit: 200,
69
- });
70
- const layers = listLayersRes.Layers || [];
71
- loading.stop();
72
- const newLayers = layers.map((item) => ({
73
- name: `[${LayerStatusMap[item.Status] || (0, i18n_1.t)('异常')}] ${item.LayerName}`,
74
- value: item.LayerName
75
- }));
76
- if (!newLayers.length) {
77
- throw new error_1.CloudBaseError((0, i18n_1.t)('没有可用的文件层,请先创建文件层!'));
78
- }
79
- const { layer } = yield (0, enquirer_1.prompt)({
80
- type: 'select',
81
- name: 'layer',
82
- message: (0, i18n_1.t)('选择文件层名称'),
83
- choices: newLayers,
84
- result(choices) {
85
- const keys = Object.values(this.map(choices));
86
- return keys[0];
87
- }
88
- });
89
- let listLayerVersionsRes = yield functionService.listLayerVersions({
90
- name: layer
91
- });
92
- let layerVersions = listLayerVersionsRes.LayerVersions || [];
93
- const versions = layerVersions.map((item) => String(item.LayerVersion));
94
- if (!versions.length) {
95
- throw new error_1.CloudBaseError((0, i18n_1.t)('没有可用的文件层版本,请先创建文件层版本!'));
48
+ async execute(envId, params, options) {
49
+ const { codeSecret } = options;
50
+ const fnName = params === null || params === void 0 ? void 0 : params[0];
51
+ const functionService = await (0, function_1.getFunctionService)(envId);
52
+ const loading = (0, utils_1.loadingFactory)();
53
+ loading.start((0, i18n_1.t)('数据加载中...'));
54
+ const envFunctions = await functionService.listAllFunctions({
55
+ envId
56
+ });
57
+ const exist = envFunctions.find((fn) => fn.FunctionName === fnName);
58
+ if (!exist) {
59
+ throw new error_1.CloudBaseError((0, i18n_1.t)('当前环境不存在此函数 [{{fnName}}]', { fnName }));
60
+ }
61
+ const listLayersRes = await functionService.listLayers({
62
+ offset: 0,
63
+ limit: 200,
64
+ });
65
+ const layers = listLayersRes.Layers || [];
66
+ loading.stop();
67
+ const newLayers = layers.map((item) => ({
68
+ name: `[${LayerStatusMap[item.Status] || (0, i18n_1.t)('异常')}] ${item.LayerName}`,
69
+ value: item.LayerName
70
+ }));
71
+ if (!newLayers.length) {
72
+ throw new error_1.CloudBaseError((0, i18n_1.t)('没有可用的文件层,请先创建文件层!'));
73
+ }
74
+ const { layer } = await (0, enquirer_1.prompt)({
75
+ type: 'select',
76
+ name: 'layer',
77
+ message: (0, i18n_1.t)('选择文件层名称'),
78
+ choices: newLayers,
79
+ result(choices) {
80
+ const keys = Object.values(this.map(choices));
81
+ return keys[0];
96
82
  }
97
- const { version } = yield (0, enquirer_1.prompt)({
98
- type: 'select',
99
- name: 'version',
100
- message: (0, i18n_1.t)('选择文件层版本'),
101
- choices: versions
102
- });
103
- loading.start((0, i18n_1.t)('文件层绑定中...'));
104
- yield functionService.attachLayer({
105
- envId,
106
- functionName: fnName,
107
- layerName: layer,
108
- layerVersion: Number(version),
109
- codeSecret
110
- });
111
- loading.succeed((0, i18n_1.t)('文件层绑定成功!'));
112
83
  });
84
+ let listLayerVersionsRes = await functionService.listLayerVersions({
85
+ name: layer
86
+ });
87
+ let layerVersions = listLayerVersionsRes.LayerVersions || [];
88
+ const versions = layerVersions.map((item) => String(item.LayerVersion));
89
+ if (!versions.length) {
90
+ throw new error_1.CloudBaseError((0, i18n_1.t)('没有可用的文件层版本,请先创建文件层版本!'));
91
+ }
92
+ const { version } = await (0, enquirer_1.prompt)({
93
+ type: 'select',
94
+ name: 'version',
95
+ message: (0, i18n_1.t)('选择文件层版本'),
96
+ choices: versions
97
+ });
98
+ loading.start((0, i18n_1.t)('文件层绑定中...'));
99
+ await functionService.attachLayer({
100
+ envId,
101
+ functionName: fnName,
102
+ layerName: layer,
103
+ layerVersion: Number(version),
104
+ codeSecret
105
+ });
106
+ loading.succeed((0, i18n_1.t)('文件层绑定成功!'));
113
107
  }
114
108
  };
115
109
  __decorate([
@@ -127,7 +121,10 @@ AttachFileLayer = __decorate([
127
121
  exports.AttachFileLayer = AttachFileLayer;
128
122
  let UnAttachFileLayer = class UnAttachFileLayer extends common_1.Command {
129
123
  get options() {
130
- return Object.assign(Object.assign({}, (0, common_2.layerCommonOptions)('unbind <name>')), { deprecateCmd: 'functions:layer:unbind <name>', options: [
124
+ return {
125
+ ...(0, common_2.layerCommonOptions)('unbind <name>'),
126
+ deprecateCmd: 'functions:layer:unbind <name>',
127
+ options: [
131
128
  {
132
129
  flags: '-e, --envId <envId>',
133
130
  desc: (0, i18n_1.t)('环境 Id')
@@ -136,44 +133,44 @@ let UnAttachFileLayer = class UnAttachFileLayer extends common_1.Command {
136
133
  flags: '--code-secret, <codeSecret>',
137
134
  desc: (0, i18n_1.t)('代码加密的函数的 CodeSecret')
138
135
  }
139
- ], desc: (0, i18n_1.t)('删除云函数绑定的文件层') });
136
+ ],
137
+ desc: (0, i18n_1.t)('删除云函数绑定的文件层')
138
+ };
140
139
  }
141
- execute(envId, params, options) {
140
+ async execute(envId, params, options) {
142
141
  var _a;
143
- return __awaiter(this, void 0, void 0, function* () {
144
- const { codeSecret } = options;
145
- const fnName = params === null || params === void 0 ? void 0 : params[0];
146
- const loading = (0, utils_1.loadingFactory)();
147
- loading.start((0, i18n_1.t)('数据加载中...'));
148
- const functionService = yield (0, function_1.getFunctionService)(envId);
149
- const detail = yield functionService.getFunctionDetail(fnName, codeSecret);
150
- if (!((_a = detail === null || detail === void 0 ? void 0 : detail.Layers) === null || _a === void 0 ? void 0 : _a.length)) {
151
- throw new error_1.CloudBaseError((0, i18n_1.t)('该云函数未绑定文件层!'));
142
+ const { codeSecret } = options;
143
+ const fnName = params === null || params === void 0 ? void 0 : params[0];
144
+ const loading = (0, utils_1.loadingFactory)();
145
+ loading.start((0, i18n_1.t)('数据加载中...'));
146
+ const functionService = await (0, function_1.getFunctionService)(envId);
147
+ const detail = await functionService.getFunctionDetail(fnName, codeSecret);
148
+ if (!((_a = detail === null || detail === void 0 ? void 0 : detail.Layers) === null || _a === void 0 ? void 0 : _a.length)) {
149
+ throw new error_1.CloudBaseError((0, i18n_1.t)('该云函数未绑定文件层!'));
150
+ }
151
+ loading.stop();
152
+ const layers = detail.Layers.map((item) => ({
153
+ name: (0, i18n_1.t)('名称:{{layerName}} / 版本: {{layerVersion}}', { layerName: item.LayerName, layerVersion: item.LayerVersion }),
154
+ value: item
155
+ }));
156
+ const { layer } = await (0, enquirer_1.prompt)({
157
+ type: 'select',
158
+ name: 'layer',
159
+ message: (0, i18n_1.t)('选择文件层'),
160
+ choices: layers,
161
+ result(choice) {
162
+ return this.map(choice)[choice];
152
163
  }
153
- loading.stop();
154
- const layers = detail.Layers.map((item) => ({
155
- name: (0, i18n_1.t)('名称:{{layerName}} / 版本: {{layerVersion}}', { layerName: item.LayerName, layerVersion: item.LayerVersion }),
156
- value: item
157
- }));
158
- const { layer } = yield (0, enquirer_1.prompt)({
159
- type: 'select',
160
- name: 'layer',
161
- message: (0, i18n_1.t)('选择文件层'),
162
- choices: layers,
163
- result(choice) {
164
- return this.map(choice)[choice];
165
- }
166
- });
167
- loading.start((0, i18n_1.t)('文件层解绑中...'));
168
- yield functionService.unAttachLayer({
169
- envId,
170
- functionName: fnName,
171
- layerName: layer.LayerName,
172
- layerVersion: layer.LayerVersion,
173
- codeSecret
174
- });
175
- loading.succeed((0, i18n_1.t)('文件层解绑成功!'));
176
164
  });
165
+ loading.start((0, i18n_1.t)('文件层解绑中...'));
166
+ await functionService.unAttachLayer({
167
+ envId,
168
+ functionName: fnName,
169
+ layerName: layer.LayerName,
170
+ layerVersion: layer.LayerVersion,
171
+ codeSecret
172
+ });
173
+ loading.succeed((0, i18n_1.t)('文件层解绑成功!'));
177
174
  }
178
175
  };
179
176
  __decorate([
@@ -11,15 +11,6 @@ var __metadata = (this && this.__metadata) || function (k, v) {
11
11
  var __param = (this && this.__param) || function (paramIndex, decorator) {
12
12
  return function (target, key) { decorator(target, key, paramIndex); }
13
13
  };
14
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
15
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16
- return new (P || (P = Promise))(function (resolve, reject) {
17
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
18
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
19
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
20
- step((generator = generator.apply(thisArg, _arguments || [])).next());
21
- });
22
- };
23
14
  var __importDefault = (this && this.__importDefault) || function (mod) {
24
15
  return (mod && mod.__esModule) ? mod : { "default": mod };
25
16
  };
@@ -35,7 +26,10 @@ const toolbox_1 = require("@cloudbase/toolbox");
35
26
  const i18n_1 = require("../../../i18n");
36
27
  let CreateFileLayer = class CreateFileLayer extends common_1.Command {
37
28
  get options() {
38
- return Object.assign(Object.assign({}, (0, common_2.layerCommonOptions)('create <alias>')), { deprecateCmd: 'functions:layer:create <alias>', options: [
29
+ return {
30
+ ...(0, common_2.layerCommonOptions)('create <alias>'),
31
+ deprecateCmd: 'functions:layer:create <alias>',
32
+ options: [
39
33
  {
40
34
  flags: '-e, --envId <envId>',
41
35
  desc: (0, i18n_1.t)('环境 Id')
@@ -44,33 +38,33 @@ let CreateFileLayer = class CreateFileLayer extends common_1.Command {
44
38
  flags: '--file, <file>',
45
39
  desc: (0, i18n_1.t)('文件路径')
46
40
  }
47
- ], desc: (0, i18n_1.t)('创建函数文件层') });
41
+ ],
42
+ desc: (0, i18n_1.t)('创建函数文件层')
43
+ };
48
44
  }
49
- execute(envId, options, params) {
50
- return __awaiter(this, void 0, void 0, function* () {
51
- const functionsService = yield (0, function_1.getFunctionService)(envId);
52
- const alias = params === null || params === void 0 ? void 0 : params[0];
53
- const { file } = options;
54
- const layerName = `${alias}_${envId}`;
55
- const listLayerRes = yield functionsService.listLayers({
56
- offset: 0,
57
- limit: 200
58
- });
59
- const layers = listLayerRes.Layers || [];
60
- if (layers.find(({ LayerName }) => LayerName === layerName)) {
61
- throw new toolbox_1.CloudBaseError((0, i18n_1.t)('层名称 {{layerName}} 已被您的当前环境或其他环境占用,请换用别的名称', { layerName }));
62
- }
63
- const filePath = path_1.default.resolve(file);
64
- const runtimes = ['Nodejs14.18', 'Nodejs12.16', 'Nodejs8.9', 'Php7', 'Java8'];
65
- const loading = (0, utils_1.loadingFactory)();
66
- loading.start((0, i18n_1.t)('文件层创建中...'));
67
- yield functionsService.createLayer({
68
- name: layerName,
69
- runtimes,
70
- contentPath: filePath
71
- });
72
- loading.succeed((0, i18n_1.t)('文件层创建成功!'));
45
+ async execute(envId, options, params) {
46
+ const functionsService = await (0, function_1.getFunctionService)(envId);
47
+ const alias = params === null || params === void 0 ? void 0 : params[0];
48
+ const { file } = options;
49
+ const layerName = `${alias}_${envId}`;
50
+ const listLayerRes = await functionsService.listLayers({
51
+ offset: 0,
52
+ limit: 200
53
+ });
54
+ const layers = listLayerRes.Layers || [];
55
+ if (layers.find(({ LayerName }) => LayerName === layerName)) {
56
+ throw new toolbox_1.CloudBaseError((0, i18n_1.t)('层名称 {{layerName}} 已被您的当前环境或其他环境占用,请换用别的名称', { layerName }));
57
+ }
58
+ const filePath = path_1.default.resolve(file);
59
+ const runtimes = ['Nodejs14.18', 'Nodejs12.16', 'Nodejs8.9', 'Php7', 'Java8'];
60
+ const loading = (0, utils_1.loadingFactory)();
61
+ loading.start((0, i18n_1.t)('文件层创建中...'));
62
+ await functionsService.createLayer({
63
+ name: layerName,
64
+ runtimes,
65
+ contentPath: filePath
73
66
  });
67
+ loading.succeed((0, i18n_1.t)('文件层创建成功!'));
74
68
  }
75
69
  };
76
70
  __decorate([
@@ -11,15 +11,6 @@ var __metadata = (this && this.__metadata) || function (k, v) {
11
11
  var __param = (this && this.__param) || function (paramIndex, decorator) {
12
12
  return function (target, key) { decorator(target, key, paramIndex); }
13
13
  };
14
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
15
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16
- return new (P || (P = Promise))(function (resolve, reject) {
17
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
18
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
19
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
20
- step((generator = generator.apply(thisArg, _arguments || [])).next());
21
- });
22
- };
23
14
  Object.defineProperty(exports, "__esModule", { value: true });
24
15
  exports.DeleteFileLayer = void 0;
25
16
  const enquirer_1 = require("enquirer");
@@ -32,51 +23,54 @@ const common_2 = require("./common");
32
23
  const i18n_1 = require("../../../i18n");
33
24
  let DeleteFileLayer = class DeleteFileLayer extends common_1.Command {
34
25
  get options() {
35
- return Object.assign(Object.assign({}, (0, common_2.layerCommonOptions)('delete')), { deprecateCmd: 'functions:layer:delete', options: [
26
+ return {
27
+ ...(0, common_2.layerCommonOptions)('delete'),
28
+ deprecateCmd: 'functions:layer:delete',
29
+ options: [
36
30
  {
37
31
  flags: '-e, --envId <envId>',
38
32
  desc: (0, i18n_1.t)('环境 Id')
39
33
  }
40
- ], desc: (0, i18n_1.t)('删除当前环境的文件层') });
34
+ ],
35
+ desc: (0, i18n_1.t)('删除当前环境的文件层')
36
+ };
41
37
  }
42
- execute(envId) {
43
- return __awaiter(this, void 0, void 0, function* () {
44
- const loading = (0, utils_1.loadingFactory)();
45
- loading.start((0, i18n_1.t)('数据加载中...'));
46
- const functionService = yield (0, function_1.getFunctionService)(envId);
47
- const listLayersRes = yield functionService.listLayers({
48
- offset: 0,
49
- limit: 200,
50
- });
51
- loading.stop();
52
- const layers = listLayersRes.Layers || [];
53
- if (!layers.length) {
54
- throw new error_1.CloudBaseError((0, i18n_1.t)('当前环境没有可用的文件层,请先创建文件层!'));
55
- }
56
- const { layer } = yield (0, enquirer_1.prompt)({
57
- type: 'select',
58
- name: 'layer',
59
- message: (0, i18n_1.t)('选择文件层名称'),
60
- choices: layers.map((item) => item.LayerName)
61
- });
62
- let listLayerVersionsRes = yield functionService.listLayerVersions({
63
- name: layer
64
- });
65
- const layerVersions = listLayerVersionsRes.LayerVersions || [];
66
- const versions = layerVersions.map((item) => String(item.LayerVersion));
67
- const { version } = yield (0, enquirer_1.prompt)({
68
- type: 'select',
69
- name: 'version',
70
- message: (0, i18n_1.t)('选择文件层版本'),
71
- choices: versions
72
- });
73
- loading.start((0, i18n_1.t)('文件层删除中...'));
74
- yield functionService.deleteLayerVersion({
75
- name: layer,
76
- version: Number(version)
77
- });
78
- loading.succeed((0, i18n_1.t)('文件层删除成功!'));
38
+ async execute(envId) {
39
+ const loading = (0, utils_1.loadingFactory)();
40
+ loading.start((0, i18n_1.t)('数据加载中...'));
41
+ const functionService = await (0, function_1.getFunctionService)(envId);
42
+ const listLayersRes = await functionService.listLayers({
43
+ offset: 0,
44
+ limit: 200,
45
+ });
46
+ loading.stop();
47
+ const layers = listLayersRes.Layers || [];
48
+ if (!layers.length) {
49
+ throw new error_1.CloudBaseError((0, i18n_1.t)('当前环境没有可用的文件层,请先创建文件层!'));
50
+ }
51
+ const { layer } = await (0, enquirer_1.prompt)({
52
+ type: 'select',
53
+ name: 'layer',
54
+ message: (0, i18n_1.t)('选择文件层名称'),
55
+ choices: layers.map((item) => item.LayerName)
56
+ });
57
+ let listLayerVersionsRes = await functionService.listLayerVersions({
58
+ name: layer
59
+ });
60
+ const layerVersions = listLayerVersionsRes.LayerVersions || [];
61
+ const versions = layerVersions.map((item) => String(item.LayerVersion));
62
+ const { version } = await (0, enquirer_1.prompt)({
63
+ type: 'select',
64
+ name: 'version',
65
+ message: (0, i18n_1.t)('选择文件层版本'),
66
+ choices: versions
67
+ });
68
+ loading.start((0, i18n_1.t)('文件层删除中...'));
69
+ await functionService.deleteLayerVersion({
70
+ name: layer,
71
+ version: Number(version)
79
72
  });
73
+ loading.succeed((0, i18n_1.t)('文件层删除成功!'));
80
74
  }
81
75
  };
82
76
  __decorate([