@cloudbase/cli 2.8.27-beta.0 → 2.8.27-beta.1

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/bin/ccr.js CHANGED
File without changes
@@ -66,12 +66,9 @@ let CodeDownload = class CodeDownload extends common_1.Command {
66
66
  if (!name) {
67
67
  throw new error_1.CloudBaseError('请指定云函数名称!');
68
68
  }
69
+ const functionService = yield (0, function_1.getFunctionService)(envId);
69
70
  try {
70
- yield (0, function_1.getFunctionDetail)({
71
- envId,
72
- codeSecret,
73
- functionName: name
74
- });
71
+ yield functionService.getFunctionDetail(name, codeSecret);
75
72
  }
76
73
  catch (e) {
77
74
  if (e.code === 'ResourceNotFound.FunctionName') {
@@ -98,7 +95,7 @@ let CodeDownload = class CodeDownload extends common_1.Command {
98
95
  }
99
96
  const loading = (0, utils_1.loadingFactory)();
100
97
  loading.start('文件下载中...');
101
- yield (0, function_1.downloadFunctionCode)({
98
+ yield functionService.downloadFunctionCode({
102
99
  envId,
103
100
  functionName: name,
104
101
  destPath: destPath,
@@ -52,19 +52,15 @@ let FunctionCopy = class FunctionCopy extends common_1.Command {
52
52
  execute(envId, options, params, log) {
53
53
  return __awaiter(this, void 0, void 0, function* () {
54
54
  const name = params === null || params === void 0 ? void 0 : params[0];
55
- const newFunctionName = params === null || params === void 0 ? void 0 : params[1];
56
- const { force, codeSecret, targetEnvId } = options;
55
+ let newFunctionName = params === null || params === void 0 ? void 0 : params[1];
56
+ let { force, codeSecret, targetEnvId } = options;
57
57
  if (!name) {
58
58
  throw new error_1.CloudBaseError('请指定函数名称!');
59
59
  }
60
- yield (0, function_1.copyFunction)({
61
- force,
62
- envId,
63
- codeSecret,
64
- functionName: name,
65
- newFunctionName: newFunctionName || name,
66
- targetEnvId: targetEnvId || envId
67
- });
60
+ const functionService = yield (0, function_1.getFunctionService)(envId);
61
+ newFunctionName = newFunctionName || name;
62
+ targetEnvId = targetEnvId || envId;
63
+ yield functionService.copyFunction(name, newFunctionName, targetEnvId, force);
68
64
  log.success('拷贝函数成功');
69
65
  });
70
66
  }
@@ -50,6 +50,7 @@ let DeleteFunction = class DeleteFunction extends common_1.Command {
50
50
  return __awaiter(this, void 0, void 0, function* () {
51
51
  const name = params === null || params === void 0 ? void 0 : params[0];
52
52
  const { envId, config: { functions } } = ctx;
53
+ const functionService = yield (0, function_1.getFunctionService)(envId);
53
54
  let isBatchDelete = false;
54
55
  if (!name) {
55
56
  const answer = yield inquirer_1.default.prompt({
@@ -73,16 +74,14 @@ let DeleteFunction = class DeleteFunction extends common_1.Command {
73
74
  }
74
75
  if (isBatchDelete) {
75
76
  const names = functions.map((item) => item.name);
76
- return (0, function_1.batchDeleteFunctions)({
77
- names,
78
- envId
77
+ return functionService.batchDeleteFunctions({
78
+ names
79
79
  });
80
80
  }
81
81
  const loading = (0, utils_1.loadingFactory)();
82
82
  loading.start(`删除函数 [${name}] 中...`);
83
- yield (0, function_1.deleteFunction)({
84
- envId,
85
- functionName: name
83
+ yield functionService.deleteFunction({
84
+ name
86
85
  });
87
86
  loading.succeed(`删除函数 [${name}] 成功!`);
88
87
  });
@@ -67,12 +67,9 @@ let FunctionDetail = class FunctionDetail extends common_1.Command {
67
67
  }
68
68
  const loading = (0, utils_1.loadingFactory)();
69
69
  loading.start('获取函数信息中...');
70
+ const functionService = yield (0, function_1.getFunctionService)(envId);
70
71
  try {
71
- const data = yield (0, function_1.getFunctionDetail)({
72
- envId,
73
- functionName: name,
74
- codeSecret
75
- });
72
+ const data = yield functionService.getFunctionDetail(name, codeSecret);
76
73
  loading.stop();
77
74
  this.logDetail(data, name);
78
75
  }
@@ -55,6 +55,7 @@ let InvokeFunction = class InvokeFunction extends common_1.Command {
55
55
  const { envId, config: { functions }, options } = ctx;
56
56
  const name = argsParams === null || argsParams === void 0 ? void 0 : argsParams[0];
57
57
  let isBatchInvoke = false;
58
+ const functionService = yield (0, function_1.getFunctionService)(envId);
58
59
  if (!name) {
59
60
  const { isBatch } = yield inquirer_1.default.prompt({
60
61
  type: 'confirm',
@@ -79,7 +80,7 @@ let InvokeFunction = class InvokeFunction extends common_1.Command {
79
80
  }
80
81
  }
81
82
  if (isBatchInvoke) {
82
- return (0, function_1.batchInvokeFunctions)({
83
+ return functionService.batchInvokeFunctions({
83
84
  envId,
84
85
  functions,
85
86
  log: true
@@ -87,11 +88,8 @@ let InvokeFunction = class InvokeFunction extends common_1.Command {
87
88
  }
88
89
  const func = functions.find((item) => item.name === name);
89
90
  const configParams = (func === null || func === void 0 ? void 0 : func.params) ? func.params : undefined;
90
- const result = yield (0, function_1.invokeFunction)({
91
- envId,
92
- functionName: name,
93
- params: params || configParams
94
- });
91
+ params = params || configParams;
92
+ const result = yield functionService.invokeFunction(name, params);
95
93
  if (result.InvokeResult === 0) {
96
94
  log.success(`[${name}] 调用成功\n`);
97
95
  }
@@ -54,7 +54,8 @@ let AttachFileLayer = class AttachFileLayer extends common_1.Command {
54
54
  const fnName = params === null || params === void 0 ? void 0 : params[0];
55
55
  const loading = (0, utils_1.loadingFactory)();
56
56
  loading.start('数据加载中...');
57
- const envFunctions = yield (0, function_1.listAllFunctions)({
57
+ const functionService = yield (0, function_1.getFunctionService)(envId);
58
+ const envFunctions = yield functionService.listAllFunctions({
58
59
  envId
59
60
  });
60
61
  const exist = envFunctions.find((fn) => fn.FunctionName === fnName);
@@ -142,11 +143,8 @@ let UnAttachFileLayer = class UnAttachFileLayer extends common_1.Command {
142
143
  const fnName = params === null || params === void 0 ? void 0 : params[0];
143
144
  const loading = (0, utils_1.loadingFactory)();
144
145
  loading.start('数据加载中...');
145
- const detail = yield (0, function_1.getFunctionDetail)({
146
- envId,
147
- codeSecret,
148
- functionName: fnName
149
- });
146
+ const functionService = yield (0, function_1.getFunctionService)(envId);
147
+ const detail = yield functionService.getFunctionDetail(fnName, codeSecret);
150
148
  if (!((_a = detail === null || detail === void 0 ? void 0 : detail.Layers) === null || _a === void 0 ? void 0 : _a.length)) {
151
149
  throw new error_1.CloudBaseError('该云函数未绑定文件层!');
152
150
  }
@@ -47,6 +47,7 @@ let CreateFileLayer = class CreateFileLayer extends common_1.Command {
47
47
  }
48
48
  execute(envId, options, params) {
49
49
  return __awaiter(this, void 0, void 0, function* () {
50
+ const functionsService = yield (0, function_1.getFunctionService)(envId);
50
51
  const alias = params === null || params === void 0 ? void 0 : params[0];
51
52
  const { file } = options;
52
53
  const layerName = `${alias}_${envId}`;
@@ -54,6 +54,7 @@ let ListFileLayer = class ListFileLayer extends common_1.Command {
54
54
  const loading = (0, utils_1.loadingFactory)();
55
55
  loading.start('数据加载中...');
56
56
  let data;
57
+ const functionService = yield (0, function_1.getFunctionService)(envId);
57
58
  if (layer && typeof layer === 'string') {
58
59
  const layerName = `${layer}_${envId}`;
59
60
  data = yield (0, function_1.listLayerVersions)({
@@ -61,11 +62,7 @@ let ListFileLayer = class ListFileLayer extends common_1.Command {
61
62
  });
62
63
  }
63
64
  else if (name && typeof name === 'string') {
64
- const res = yield (0, function_1.getFunctionDetail)({
65
- envId,
66
- functionName: name,
67
- codeSecret
68
- });
65
+ const res = yield functionService.getFunctionDetail(name, codeSecret);
69
66
  data = (res === null || res === void 0 ? void 0 : res.Layers) || [];
70
67
  }
71
68
  else if (envId) {
@@ -53,11 +53,8 @@ let SortFileLayer = class SortFileLayer extends common_1.Command {
53
53
  const fnName = params === null || params === void 0 ? void 0 : params[0];
54
54
  const loading = (0, utils_1.loadingFactory)();
55
55
  loading.start('数据加载中...');
56
- const detail = yield (0, function_1.getFunctionDetail)({
57
- envId,
58
- codeSecret,
59
- functionName: fnName
60
- });
56
+ const functionService = yield (0, function_1.getFunctionService)(envId);
57
+ const detail = yield functionService.getFunctionDetail(fnName, codeSecret);
61
58
  loading.stop();
62
59
  const layers = detail.Layers.map((item) => ({
63
60
  name: `${item.LayerName} - ${item.LayerVersion}`,
@@ -50,6 +50,7 @@ let ListFunction = class ListFunction extends common_1.Command {
50
50
  }
51
51
  execute(envId, options) {
52
52
  return __awaiter(this, void 0, void 0, function* () {
53
+ const functionsService = yield (0, function_1.getFunctionService)(envId);
53
54
  let { limit = 20, offset = 0 } = options;
54
55
  limit = Number(limit);
55
56
  offset = Number(offset);
@@ -61,11 +62,7 @@ let ListFunction = class ListFunction extends common_1.Command {
61
62
  }
62
63
  const loading = (0, utils_1.loadingFactory)();
63
64
  loading.start('数据加载中...');
64
- const data = yield (0, function_1.listFunction)({
65
- envId,
66
- limit: Number(limit),
67
- offset: Number(offset)
68
- });
65
+ const data = yield functionsService.listFunctions(Number(limit), Number(offset));
69
66
  loading.stop();
70
67
  const head = ['函数 Id', '函数名称', '运行时', '创建时间', '修改时间', '状态'];
71
68
  const tableData = data.map((item) => [
@@ -67,7 +67,8 @@ let FunctionLog = class FunctionLog extends common_1.Command {
67
67
  desc: '查询的具体日期,例如:2019-05-16 20:59:59,只能与 startTime 相差一天之内'
68
68
  },
69
69
  { flags: '-e, --error', desc: '只返回错误类型的日志' },
70
- { flags: '-s, --success', desc: '只返回正确类型的日志' }
70
+ { flags: '-s, --success', desc: '只返回正确类型的日志' },
71
+ { flags: '-q, --qualifier <qualifier>', desc: '函数版本,,默认为 $LATEST' }
71
72
  ],
72
73
  desc: '打印云函数日志'
73
74
  };
@@ -76,7 +77,7 @@ let FunctionLog = class FunctionLog extends common_1.Command {
76
77
  return __awaiter(this, void 0, void 0, function* () {
77
78
  const { envId, options } = ctx;
78
79
  const name = argsParams === null || argsParams === void 0 ? void 0 : argsParams[0];
79
- let { offset, limit, order, orderBy, error, success, startTime, endTime, reqId: functionRequestId } = options;
80
+ let { offset = 0, limit = 10, order, orderBy, error, success, startTime, endTime, reqId: requestId, qualifier } = options;
80
81
  if (!name) {
81
82
  throw new error_1.CloudBaseError('云函数名称不能为空');
82
83
  }
@@ -98,20 +99,20 @@ let FunctionLog = class FunctionLog extends common_1.Command {
98
99
  orderBy,
99
100
  startTime,
100
101
  endTime,
101
- functionRequestId,
102
+ requestId,
102
103
  offset: Number(offset),
103
- limit: Number(limit)
104
+ limit: Number(limit),
105
+ qualifier
104
106
  };
105
107
  error && (params.filter = { RetCode: 'not0' });
106
108
  success && (params.filter = { RetCode: 'is0' });
107
109
  params = JSON.parse(JSON.stringify(params));
108
- const logs = yield (0, function_1.getFunctionLog)(Object.assign({ envId, functionName: name }, params));
110
+ const functionService = yield (0, function_1.getFunctionService)(envId);
111
+ const logs = yield functionService.getCompleteFunctionLogs(Object.assign({ name }, params));
109
112
  const ResMap = {
110
113
  StartTime: '请求时间',
111
114
  FunctionName: '函数名称',
112
- BillDuration: '计费时间(ms)',
113
115
  Duration: '运行时间(ms)',
114
- InvokeFinished: '调用次数',
115
116
  MemUsage: '占用内存',
116
117
  RequestId: '请求 Id',
117
118
  RetCode: '调用状态',
@@ -134,7 +135,7 @@ let FunctionLog = class FunctionLog extends common_1.Command {
134
135
  return `${ResMap[key]}:${log[key]} \n`;
135
136
  })
136
137
  .reduce((prev, next) => prev + next);
137
- console.log(info + `日志:\n ${log.Log} \n`);
138
+ console.log(info + `日志:\n ${log.LogJson} \n`);
138
139
  });
139
140
  });
140
141
  }
@@ -164,11 +164,9 @@ function debugByConfig(ctx, name) {
164
164
  }
165
165
  try {
166
166
  const finalPath = path_1.default.join(debugDirname, indexFile);
167
- console.log("finalPath", finalPath);
168
167
  const requirePath = process.platform === 'win32'
169
168
  ? finalPath.replace(/\\/g, '\\\\')
170
169
  : finalPath;
171
- console.log("requirePath", requirePath);
172
170
  const fileExports = require(requirePath);
173
171
  if (!fileExports[mainFunction]) {
174
172
  errorLog(`handler 中的 ${mainFunction} 方法不存在,请检查你的配置!`, debug);
@@ -55,15 +55,12 @@ let CreateService = class CreateService extends common_1.Command {
55
55
  }
56
56
  execute(envId, options) {
57
57
  return __awaiter(this, void 0, void 0, function* () {
58
+ const functionsService = yield (0, function_1.getFunctionService)(envId);
58
59
  let { function: functionName, servicePath } = options;
59
60
  const loading = (0, utils_1.loadingFactory)();
60
61
  if (!servicePath || !functionName) {
61
62
  loading.start('数据加载中...');
62
- const functions = yield (0, function_1.listFunction)({
63
- envId,
64
- limit: 100,
65
- offset: 0
66
- });
63
+ const functions = yield functionsService.listFunctions(100, 0);
67
64
  loading.stop();
68
65
  if (!functions.length) {
69
66
  throw new error_1.CloudBaseError('当前环境下不存在可用的云函数,请先创建云函数!');
@@ -14,18 +14,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.unAttachLayer = exports.attachLayer = void 0;
16
16
  const lodash_1 = __importDefault(require("lodash"));
17
- const base_1 = require("../base");
18
17
  const utils_1 = require("../../utils");
19
18
  const error_1 = require("../../error");
19
+ const __1 = require("../");
20
20
  const scfService = new utils_1.CloudApiService('scf');
21
21
  function attachLayer(options) {
22
22
  return __awaiter(this, void 0, void 0, function* () {
23
23
  const { envId, functionName, layerName, layerVersion, codeSecret } = options;
24
- let { Layers } = yield (0, base_1.getFunctionDetail)({
25
- envId,
26
- codeSecret,
27
- functionName
28
- });
24
+ const functionService = yield (0, __1.getFunctionService)(envId);
25
+ let { Layers } = yield functionService.getFunctionDetail(functionName, codeSecret);
29
26
  Layers = Layers.map(item => lodash_1.default.pick(item, ['LayerName', 'LayerVersion']));
30
27
  Layers.push({
31
28
  LayerName: layerName,
@@ -43,11 +40,8 @@ exports.attachLayer = attachLayer;
43
40
  function unAttachLayer(options) {
44
41
  return __awaiter(this, void 0, void 0, function* () {
45
42
  const { envId, functionName, layerName, layerVersion, codeSecret } = options;
46
- let { Layers } = yield (0, base_1.getFunctionDetail)({
47
- envId,
48
- codeSecret,
49
- functionName
50
- });
43
+ const functionService = yield (0, __1.getFunctionService)(envId);
44
+ let { Layers } = yield functionService.getFunctionDetail(functionName, codeSecret);
51
45
  Layers = Layers.map(item => lodash_1.default.pick(item, ['LayerName', 'LayerVersion']));
52
46
  const index = Layers.findIndex(item => item.LayerName === layerName && item.LayerVersion === layerVersion);
53
47
  if (index === -1) {
@@ -24,18 +24,24 @@ __exportStar(require("./del"), exports);
24
24
  function checkFullAccess(dest, throwError = false) {
25
25
  try {
26
26
  fs_1.default.accessSync(dest, fs_1.default.constants.F_OK);
27
+ }
28
+ catch (e) {
29
+ if (throwError) {
30
+ throw new error_1.CloudBaseError(`路径不存在:${dest}`);
31
+ }
32
+ return false;
33
+ }
34
+ try {
27
35
  fs_1.default.accessSync(dest, fs_1.default.constants.W_OK);
28
36
  fs_1.default.accessSync(dest, fs_1.default.constants.R_OK);
29
- return true;
30
37
  }
31
38
  catch (e) {
32
39
  if (throwError) {
33
- throw new error_1.CloudBaseError(`路径不存在或没有权限访问:${dest}`);
34
- }
35
- else {
36
- return false;
40
+ throw new error_1.CloudBaseError(`路径无读写权限:${dest}`);
37
41
  }
42
+ return false;
38
43
  }
44
+ return true;
39
45
  }
40
46
  exports.checkFullAccess = checkFullAccess;
41
47
  function checkWritable(dest, throwError = false) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbase/cli",
3
- "version": "2.8.27-beta.0",
3
+ "version": "2.8.27-beta.1",
4
4
  "description": "cli tool for cloudbase",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -53,7 +53,7 @@
53
53
  "@cloudbase/functions-framework": "1.16.0",
54
54
  "@cloudbase/iac-core": "0.0.3-alpha.11",
55
55
  "@cloudbase/lowcode-cli": "^0.22.2",
56
- "@cloudbase/manager-node": "4.4.4",
56
+ "@cloudbase/manager-node": "^4.4.9-beta.0",
57
57
  "@cloudbase/toolbox": "^0.7.9",
58
58
  "@dotenvx/dotenvx": "^1.48.3",
59
59
  "@musistudio/claude-code-router": "1.0.36",
@@ -11,5 +11,5 @@ export declare class InvokeFunction extends Command {
11
11
  }[];
12
12
  desc: string;
13
13
  };
14
- execute(ctx: any, argsParams: any, log: Logger): Promise<any[]>;
14
+ execute(ctx: any, argsParams: any, log: Logger): Promise<import("@cloudbase/manager-node/types/interfaces").IFunctionInvokeRes[]>;
15
15
  }