@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
  };
@@ -37,7 +28,10 @@ const common_2 = require("./common");
37
28
  const i18n_1 = require("../../../i18n");
38
29
  let DownloadFileLayer = class DownloadFileLayer extends common_1.Command {
39
30
  get options() {
40
- return Object.assign(Object.assign({}, (0, common_2.layerCommonOptions)('download')), { deprecateCmd: 'functions:layer:download', options: [
31
+ return {
32
+ ...(0, common_2.layerCommonOptions)('download'),
33
+ deprecateCmd: 'functions:layer:download',
34
+ options: [
41
35
  {
42
36
  flags: '-e, --envId <envId>',
43
37
  desc: (0, i18n_1.t)('环境 Id')
@@ -46,56 +40,56 @@ let DownloadFileLayer = class DownloadFileLayer extends common_1.Command {
46
40
  flags: '--dest <dest>',
47
41
  desc: (0, i18n_1.t)('下载文件存放的地址')
48
42
  }
49
- ], desc: (0, i18n_1.t)('下载云函数文件层') });
43
+ ],
44
+ desc: (0, i18n_1.t)('下载云函数文件层')
45
+ };
50
46
  }
51
- execute(envId, options) {
52
- return __awaiter(this, void 0, void 0, function* () {
53
- const { dest } = options;
54
- const functionService = yield (0, function_1.getFunctionService)(envId);
55
- const loading = (0, utils_1.loadingFactory)();
56
- loading.start((0, i18n_1.t)('数据加载中...'));
57
- const listLayersRes = yield functionService.listLayers({
58
- offset: 0,
59
- limit: 200,
60
- });
61
- const layers = listLayersRes.Layers || [];
62
- loading.stop();
63
- if (!layers.length) {
64
- throw new error_1.CloudBaseError((0, i18n_1.t)('当前环境没有可用的文件层,请先创建文件层!'));
65
- }
66
- const { layer } = yield (0, enquirer_1.prompt)({
67
- type: 'select',
68
- name: 'layer',
69
- message: (0, i18n_1.t)('选择文件层名称'),
70
- choices: layers.map((item) => item.LayerName)
71
- });
72
- let listLayerVersionsRes = yield functionService.listLayerVersions({
73
- name: layer
74
- });
75
- const layerVersions = listLayerVersionsRes.LayerVersions || [];
76
- const versions = layerVersions.map((item) => String(item.LayerVersion));
77
- const { version } = yield (0, enquirer_1.prompt)({
78
- type: 'select',
79
- name: 'version',
80
- message: (0, i18n_1.t)('选择文件层版本'),
81
- choices: versions
82
- });
83
- let destPath;
84
- if (!dest) {
85
- destPath = path_1.default.resolve(process.cwd(), 'layers');
86
- }
87
- else {
88
- destPath = path_1.default.resolve(dest);
89
- }
90
- loading.start((0, i18n_1.t)('文件下载中...'));
91
- yield fs_extra_1.default.ensureDir(destPath);
92
- yield functionService.downloadLayer({
93
- destPath,
94
- version: Number(version),
95
- name: layer
96
- });
97
- loading.succeed((0, i18n_1.t)('文件下载成功!'));
47
+ async execute(envId, options) {
48
+ const { dest } = options;
49
+ const functionService = await (0, function_1.getFunctionService)(envId);
50
+ const loading = (0, utils_1.loadingFactory)();
51
+ loading.start((0, i18n_1.t)('数据加载中...'));
52
+ const listLayersRes = await functionService.listLayers({
53
+ offset: 0,
54
+ limit: 200,
55
+ });
56
+ const layers = listLayersRes.Layers || [];
57
+ loading.stop();
58
+ if (!layers.length) {
59
+ throw new error_1.CloudBaseError((0, i18n_1.t)('当前环境没有可用的文件层,请先创建文件层!'));
60
+ }
61
+ const { layer } = await (0, enquirer_1.prompt)({
62
+ type: 'select',
63
+ name: 'layer',
64
+ message: (0, i18n_1.t)('选择文件层名称'),
65
+ choices: layers.map((item) => item.LayerName)
66
+ });
67
+ let listLayerVersionsRes = await functionService.listLayerVersions({
68
+ name: layer
69
+ });
70
+ const layerVersions = listLayerVersionsRes.LayerVersions || [];
71
+ const versions = layerVersions.map((item) => String(item.LayerVersion));
72
+ const { version } = await (0, enquirer_1.prompt)({
73
+ type: 'select',
74
+ name: 'version',
75
+ message: (0, i18n_1.t)('选择文件层版本'),
76
+ choices: versions
77
+ });
78
+ let destPath;
79
+ if (!dest) {
80
+ destPath = path_1.default.resolve(process.cwd(), 'layers');
81
+ }
82
+ else {
83
+ destPath = path_1.default.resolve(dest);
84
+ }
85
+ loading.start((0, i18n_1.t)('文件下载中...'));
86
+ await fs_extra_1.default.ensureDir(destPath);
87
+ await functionService.downloadLayer({
88
+ destPath,
89
+ version: Number(version),
90
+ name: layer
98
91
  });
92
+ loading.succeed((0, i18n_1.t)('文件下载成功!'));
99
93
  }
100
94
  };
101
95
  __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.ListFileLayer = void 0;
25
16
  const common_1 = require("../../common");
@@ -30,7 +21,10 @@ const common_2 = require("./common");
30
21
  const i18n_1 = require("../../../i18n");
31
22
  let ListFileLayer = class ListFileLayer extends common_1.Command {
32
23
  get options() {
33
- return Object.assign(Object.assign({}, (0, common_2.layerCommonOptions)('list')), { deprecateCmd: 'functions:layer:list', options: [
24
+ return {
25
+ ...(0, common_2.layerCommonOptions)('list'),
26
+ deprecateCmd: 'functions:layer:list',
27
+ options: [
34
28
  {
35
29
  flags: '-e, --envId <envId>',
36
30
  desc: (0, i18n_1.t)('环境 Id')
@@ -47,47 +41,47 @@ let ListFileLayer = class ListFileLayer 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, options, log) {
53
- return __awaiter(this, void 0, void 0, function* () {
54
- const { name, layer, codeSecret } = options;
55
- const loading = (0, utils_1.loadingFactory)();
56
- loading.start((0, i18n_1.t)('数据加载中...'));
57
- let data;
58
- const functionService = yield (0, function_1.getFunctionService)(envId);
59
- if (layer && typeof layer === 'string') {
60
- const layerName = `${layer}_${envId}`;
61
- const listLayerVersionsRes = yield functionService.listLayerVersions({
62
- name: layerName
63
- });
64
- data = listLayerVersionsRes.LayerVersions || [];
65
- }
66
- else if (name && typeof name === 'string') {
67
- const res = yield functionService.getFunctionDetail(name, codeSecret);
68
- data = (res === null || res === void 0 ? void 0 : res.Layers) || [];
69
- }
70
- else {
71
- const listLayersRes = yield functionService.listLayers({
72
- offset: 0,
73
- limit: 200
74
- });
75
- data = listLayersRes.Layers || [];
76
- }
77
- loading.stop();
78
- const head = [(0, i18n_1.t)('优先级'), (0, i18n_1.t)('名称'), (0, i18n_1.t)('状态'), (0, i18n_1.t)('版本'), (0, i18n_1.t)('证书'), (0, i18n_1.t)('支持运行时'), (0, i18n_1.t)('创建时间')];
79
- const tableData = data.map((item, index) => [
80
- index + 1,
81
- item.LayerName,
82
- item.Status,
83
- item.LayerVersion,
84
- item.LicenseInfo || (0, i18n_1.t)(''),
85
- item.CompatibleRuntimes.join(' | '),
86
- item.AddTime
87
- ]);
88
- (0, utils_1.printHorizontalTable)(head, tableData);
89
- log.info((0, i18n_1.t)('Tips:函数绑定多个版本时,同名文件将按优先级从小到大的顺序进行覆盖执行。'));
90
- });
48
+ async execute(envId, options, log) {
49
+ const { name, layer, codeSecret } = options;
50
+ const loading = (0, utils_1.loadingFactory)();
51
+ loading.start((0, i18n_1.t)('数据加载中...'));
52
+ let data;
53
+ const functionService = await (0, function_1.getFunctionService)(envId);
54
+ if (layer && typeof layer === 'string') {
55
+ const layerName = `${layer}_${envId}`;
56
+ const listLayerVersionsRes = await functionService.listLayerVersions({
57
+ name: layerName
58
+ });
59
+ data = listLayerVersionsRes.LayerVersions || [];
60
+ }
61
+ else if (name && typeof name === 'string') {
62
+ const res = await functionService.getFunctionDetail(name, codeSecret);
63
+ data = (res === null || res === void 0 ? void 0 : res.Layers) || [];
64
+ }
65
+ else {
66
+ const listLayersRes = await functionService.listLayers({
67
+ offset: 0,
68
+ limit: 200
69
+ });
70
+ data = listLayersRes.Layers || [];
71
+ }
72
+ loading.stop();
73
+ const head = [(0, i18n_1.t)('优先级'), (0, i18n_1.t)('名称'), (0, i18n_1.t)('状态'), (0, i18n_1.t)('版本'), (0, i18n_1.t)('证书'), (0, i18n_1.t)('支持运行时'), (0, i18n_1.t)('创建时间')];
74
+ const tableData = data.map((item, index) => [
75
+ index + 1,
76
+ item.LayerName,
77
+ item.Status,
78
+ item.LayerVersion,
79
+ item.LicenseInfo || (0, i18n_1.t)('空'),
80
+ item.CompatibleRuntimes.join(' | '),
81
+ item.AddTime
82
+ ]);
83
+ (0, utils_1.printHorizontalTable)(head, tableData);
84
+ log.info((0, i18n_1.t)('Tips:函数绑定多个版本时,同名文件将按优先级从小到大的顺序进行覆盖执行。'));
91
85
  }
92
86
  };
93
87
  __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
  };
@@ -36,7 +27,10 @@ const common_2 = require("./common");
36
27
  const i18n_1 = require("../../../i18n");
37
28
  let SortFileLayer = class SortFileLayer extends common_1.Command {
38
29
  get options() {
39
- return Object.assign(Object.assign({}, (0, common_2.layerCommonOptions)('sort <name>')), { deprecateCmd: 'functions:layer:sort <name>', options: [
30
+ return {
31
+ ...(0, common_2.layerCommonOptions)('sort <name>'),
32
+ deprecateCmd: 'functions:layer:sort <name>',
33
+ options: [
40
34
  {
41
35
  flags: '-e, --envId <envId>',
42
36
  desc: (0, i18n_1.t)('环境 Id')
@@ -45,44 +39,44 @@ let SortFileLayer = class SortFileLayer extends common_1.Command {
45
39
  flags: '--code-secret, <codeSecret>',
46
40
  desc: (0, i18n_1.t)('代码加密的函数的 CodeSecret')
47
41
  }
48
- ], desc: (0, i18n_1.t)('重新排列云函数绑定的文件层的顺序') });
42
+ ],
43
+ desc: (0, i18n_1.t)('重新排列云函数绑定的文件层的顺序')
44
+ };
49
45
  }
50
- execute(ctx) {
51
- return __awaiter(this, void 0, void 0, function* () {
52
- const { envId, options, params } = ctx;
53
- const { codeSecret } = options;
54
- const fnName = params === null || params === void 0 ? void 0 : params[0];
55
- const loading = (0, utils_1.loadingFactory)();
56
- loading.start((0, i18n_1.t)('数据加载中...'));
57
- const functionService = yield (0, function_1.getFunctionService)(envId);
58
- const detail = yield functionService.getFunctionDetail(fnName, codeSecret);
59
- loading.stop();
60
- const layers = detail.Layers.map((item) => ({
61
- name: `${item.LayerName} - ${item.LayerVersion}`,
62
- value: item
63
- }));
64
- if (!layers.length) {
65
- throw new error_1.CloudBaseError((0, i18n_1.t)('没有可用的文件层,请先创建文件层!'));
46
+ async execute(ctx) {
47
+ const { envId, options, params } = ctx;
48
+ const { codeSecret } = options;
49
+ const fnName = params === null || params === void 0 ? void 0 : params[0];
50
+ const loading = (0, utils_1.loadingFactory)();
51
+ loading.start((0, i18n_1.t)('数据加载中...'));
52
+ const functionService = await (0, function_1.getFunctionService)(envId);
53
+ const detail = await functionService.getFunctionDetail(fnName, codeSecret);
54
+ loading.stop();
55
+ const layers = detail.Layers.map((item) => ({
56
+ name: `${item.LayerName} - ${item.LayerVersion}`,
57
+ value: item
58
+ }));
59
+ if (!layers.length) {
60
+ throw new error_1.CloudBaseError((0, i18n_1.t)('没有可用的文件层,请先创建文件层!'));
61
+ }
62
+ let { sortLayers } = await (0, enquirer_1.prompt)({
63
+ type: 'sort',
64
+ name: 'sortLayers',
65
+ message: (0, i18n_1.t)('选择文件层'),
66
+ numbered: true,
67
+ choices: layers,
68
+ result(choices) {
69
+ return Object.values(this.map(choices));
66
70
  }
67
- let { sortLayers } = yield (0, enquirer_1.prompt)({
68
- type: 'sort',
69
- name: 'sortLayers',
70
- message: (0, i18n_1.t)('选择文件层'),
71
- numbered: true,
72
- choices: layers,
73
- result(choices) {
74
- return Object.values(this.map(choices));
75
- }
76
- });
77
- sortLayers = sortLayers.map((item) => lodash_1.default.pick(item, ['LayerName', 'LayerVersion']));
78
- loading.start((0, i18n_1.t)('文件层排序中...'));
79
- yield functionService.updateFunctionLayer({
80
- envId,
81
- functionName: fnName,
82
- layers: sortLayers
83
- });
84
- loading.succeed((0, i18n_1.t)('文件层排序成功!'));
85
71
  });
72
+ sortLayers = sortLayers.map((item) => lodash_1.default.pick(item, ['LayerName', 'LayerVersion']));
73
+ loading.start((0, i18n_1.t)('文件层排序中...'));
74
+ await functionService.updateFunctionLayer({
75
+ envId,
76
+ functionName: fnName,
77
+ layers: sortLayers
78
+ });
79
+ loading.succeed((0, i18n_1.t)('文件层排序成功!'));
86
80
  }
87
81
  };
88
82
  __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.ListFunction = void 0;
25
16
  const common_1 = require("../common");
@@ -49,33 +40,31 @@ let ListFunction = class ListFunction extends common_1.Command {
49
40
  desc: (0, i18n_1.t)('展示云函数列表')
50
41
  };
51
42
  }
52
- execute(envId, options) {
53
- return __awaiter(this, void 0, void 0, function* () {
54
- const functionsService = yield (0, function_1.getFunctionService)(envId);
55
- let { limit = 20, offset = 0 } = options;
56
- limit = Number(limit);
57
- offset = Number(offset);
58
- if (!Number.isInteger(limit) || !Number.isInteger(offset)) {
59
- throw new error_1.CloudBaseError((0, i18n_1.t)('limit 和 offset 必须为整数'));
60
- }
61
- if (limit < 0 || offset < 0) {
62
- throw new error_1.CloudBaseError((0, i18n_1.t)('limit 和 offset 必须为大于 0 的整数'));
63
- }
64
- const loading = (0, utils_1.loadingFactory)();
65
- loading.start((0, i18n_1.t)('数据加载中...'));
66
- const data = yield functionsService.listFunctions(Number(limit), Number(offset));
67
- loading.stop();
68
- const head = [(0, i18n_1.t)('函数 Id'), (0, i18n_1.t)('函数名称'), (0, i18n_1.t)('运行时'), (0, i18n_1.t)('创建时间'), (0, i18n_1.t)('修改时间'), (0, i18n_1.t)('状态')];
69
- const tableData = data.map((item) => [
70
- item.FunctionId,
71
- item.FunctionName,
72
- item.Runtime,
73
- item.AddTime,
74
- item.ModTime,
75
- constant_1.StatusMap[item.Status]
76
- ]);
77
- (0, utils_1.printHorizontalTable)(head, tableData);
78
- });
43
+ async execute(envId, options) {
44
+ const functionsService = await (0, function_1.getFunctionService)(envId);
45
+ let { limit = 20, offset = 0 } = options;
46
+ limit = Number(limit);
47
+ offset = Number(offset);
48
+ if (!Number.isInteger(limit) || !Number.isInteger(offset)) {
49
+ throw new error_1.CloudBaseError((0, i18n_1.t)('limit offset 必须为整数'));
50
+ }
51
+ if (limit < 0 || offset < 0) {
52
+ throw new error_1.CloudBaseError((0, i18n_1.t)('limit offset 必须为大于 0 的整数'));
53
+ }
54
+ const loading = (0, utils_1.loadingFactory)();
55
+ loading.start((0, i18n_1.t)('数据加载中...'));
56
+ const data = await functionsService.listFunctions(Number(limit), Number(offset));
57
+ loading.stop();
58
+ const head = [(0, i18n_1.t)('函数 Id'), (0, i18n_1.t)('函数名称'), (0, i18n_1.t)('运行时'), (0, i18n_1.t)('创建时间'), (0, i18n_1.t)('修改时间'), (0, i18n_1.t)('状态')];
59
+ const tableData = data.map((item) => [
60
+ item.FunctionId,
61
+ item.FunctionName,
62
+ item.Runtime,
63
+ item.AddTime,
64
+ item.ModTime,
65
+ constant_1.StatusMap[item.Status]
66
+ ]);
67
+ (0, utils_1.printHorizontalTable)(head, tableData);
79
68
  }
80
69
  };
81
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
  var __importDefault = (this && this.__importDefault) || function (mod) {
24
15
  return (mod && mod.__esModule) ? mod : { "default": mod };
25
16
  };
@@ -74,70 +65,71 @@ let FunctionLog = class FunctionLog extends common_1.Command {
74
65
  desc: (0, i18n_1.t)('打印云函数日志')
75
66
  };
76
67
  }
77
- execute(ctx, argsParams, log) {
78
- return __awaiter(this, void 0, void 0, function* () {
79
- const { envId, options } = ctx;
80
- const name = argsParams === null || argsParams === void 0 ? void 0 : argsParams[0];
81
- let { offset = 0, limit = 10, order, orderBy, error, success, startTime, endTime, reqId: requestId, qualifier } = options;
82
- if (!name) {
83
- throw new error_1.CloudBaseError((0, i18n_1.t)('云函数名称不能为空'));
84
- }
85
- const TimeLength = 19;
86
- if (typeof startTime !== 'undefined' &&
87
- typeof endTime !== 'undefined' &&
88
- (startTime.length !== TimeLength || endTime.length !== TimeLength)) {
89
- throw new error_1.CloudBaseError((0, i18n_1.t)('时间格式错误,必须为 2019-05-16 20:59:59 类型'));
90
- }
91
- if (new Date(endTime).getTime() < new Date(startTime).getTime()) {
92
- throw new error_1.CloudBaseError((0, i18n_1.t)('开始时间不能晚于结束时间'));
93
- }
94
- const OneDay = 86400000;
95
- if (new Date(endTime).getTime() - new Date(startTime).getTime() > OneDay) {
96
- throw new error_1.CloudBaseError((0, i18n_1.t)('endTime 与 startTime 只能相差一天之内'));
97
- }
98
- let params = {
99
- order,
100
- orderBy,
101
- startTime,
102
- endTime,
103
- requestId,
104
- offset: Number(offset),
105
- limit: Number(limit),
106
- qualifier
107
- };
108
- error && (params.filter = { RetCode: 'not0' });
109
- success && (params.filter = { RetCode: 'is0' });
110
- params = JSON.parse(JSON.stringify(params));
111
- const functionService = yield (0, function_1.getFunctionService)(envId);
112
- const logs = yield functionService.getCompleteFunctionLogs(Object.assign({ name }, params));
113
- const ResMap = {
114
- StartTime: (0, i18n_1.t)('请求时间'),
115
- FunctionName: (0, i18n_1.t)('函数名称'),
116
- Duration: (0, i18n_1.t)('运行时间(ms)'),
117
- MemUsage: (0, i18n_1.t)('占用内存'),
118
- RequestId: (0, i18n_1.t)('请求 Id'),
119
- RetCode: (0, i18n_1.t)('调用状态'),
120
- RetMsg: (0, i18n_1.t)('返回结果')
121
- };
122
- log.success(chalk_1.default.green((0, i18n_1.t)('函数:{{name}} 调用日志:\n', { name })));
123
- if (logs.length === 0) {
124
- return log.info((0, i18n_1.t)('无调用日志'));
125
- }
126
- logs.forEach((log) => {
127
- const info = Object.keys(ResMap)
128
- .map((key) => {
129
- if (key === 'RetCode') {
130
- return `${ResMap[key]}:${Number(log[key]) === 0 ? (0, i18n_1.t)('成功') : (0, i18n_1.t)('失败')}\n`;
131
- }
132
- if (key === 'MemUsage') {
133
- const str = Number(Number(log[key]) / 1024 / 1024).toFixed(3);
134
- return `${ResMap[key]}:${str} MB\n`;
135
- }
136
- return `${ResMap[key]}:${log[key]} \n`;
137
- })
138
- .reduce((prev, next) => prev + next);
139
- console.log(info + (0, i18n_1.t)('日志:\n {{log}} \n', { log: log.LogJson }));
140
- });
68
+ async execute(ctx, argsParams, log) {
69
+ const { envId, options } = ctx;
70
+ const name = argsParams === null || argsParams === void 0 ? void 0 : argsParams[0];
71
+ let { offset = 0, limit = 10, order, orderBy, error, success, startTime, endTime, reqId: requestId, qualifier } = options;
72
+ if (!name) {
73
+ throw new error_1.CloudBaseError((0, i18n_1.t)('云函数名称不能为空'));
74
+ }
75
+ const TimeLength = 19;
76
+ if (typeof startTime !== 'undefined' &&
77
+ typeof endTime !== 'undefined' &&
78
+ (startTime.length !== TimeLength || endTime.length !== TimeLength)) {
79
+ throw new error_1.CloudBaseError((0, i18n_1.t)('时间格式错误,必须为 2019-05-16 20:59:59 类型'));
80
+ }
81
+ if (new Date(endTime).getTime() < new Date(startTime).getTime()) {
82
+ throw new error_1.CloudBaseError((0, i18n_1.t)('开始时间不能晚于结束时间'));
83
+ }
84
+ const OneDay = 86400000;
85
+ if (new Date(endTime).getTime() - new Date(startTime).getTime() > OneDay) {
86
+ throw new error_1.CloudBaseError((0, i18n_1.t)('endTime startTime 只能相差一天之内'));
87
+ }
88
+ let params = {
89
+ order,
90
+ orderBy,
91
+ startTime,
92
+ endTime,
93
+ requestId,
94
+ offset: Number(offset),
95
+ limit: Number(limit),
96
+ qualifier
97
+ };
98
+ error && (params.filter = { RetCode: 'not0' });
99
+ success && (params.filter = { RetCode: 'is0' });
100
+ params = JSON.parse(JSON.stringify(params));
101
+ const functionService = await (0, function_1.getFunctionService)(envId);
102
+ const logs = await functionService.getCompleteFunctionLogs({
103
+ name,
104
+ ...params
105
+ });
106
+ const ResMap = {
107
+ StartTime: (0, i18n_1.t)('请求时间'),
108
+ FunctionName: (0, i18n_1.t)('函数名称'),
109
+ Duration: (0, i18n_1.t)('运行时间(ms)'),
110
+ MemUsage: (0, i18n_1.t)('占用内存'),
111
+ RequestId: (0, i18n_1.t)('请求 Id'),
112
+ RetCode: (0, i18n_1.t)('调用状态'),
113
+ RetMsg: (0, i18n_1.t)('返回结果')
114
+ };
115
+ log.success(chalk_1.default.green((0, i18n_1.t)('函数:{{name}} 调用日志:\n', { name })));
116
+ if (logs.length === 0) {
117
+ return log.info((0, i18n_1.t)('无调用日志'));
118
+ }
119
+ logs.forEach((log) => {
120
+ const info = Object.keys(ResMap)
121
+ .map((key) => {
122
+ if (key === 'RetCode') {
123
+ return `${ResMap[key]}:${Number(log[key]) === 0 ? (0, i18n_1.t)('成功') : (0, i18n_1.t)('失败')}\n`;
124
+ }
125
+ if (key === 'MemUsage') {
126
+ const str = Number(Number(log[key]) / 1024 / 1024).toFixed(3);
127
+ return `${ResMap[key]}:${str} MB\n`;
128
+ }
129
+ return `${ResMap[key]}:${log[key]} \n`;
130
+ })
131
+ .reduce((prev, next) => prev + next);
132
+ console.log(info + (0, i18n_1.t)('日志:\n {{log}} \n', { log: log.LogJson }));
141
133
  });
142
134
  }
143
135
  };