@cloudbase/cli 2.10.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/function/base.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
|
};
|
|
@@ -21,246 +12,227 @@ const vpc_1 = require("./vpc");
|
|
|
21
12
|
const toolbox_1 = require("@cloudbase/toolbox");
|
|
22
13
|
const i18n_1 = require("../i18n");
|
|
23
14
|
const scfService = utils_1.CloudApiService.getInstance('scf');
|
|
24
|
-
function getFunctionService(envId) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
proxy: (0, utils_1.getProxy)()
|
|
35
|
-
});
|
|
36
|
-
return app.functions;
|
|
15
|
+
async function getFunctionService(envId) {
|
|
16
|
+
const region = await (0, toolbox_1.getRegion)();
|
|
17
|
+
const { secretId, secretKey, token } = await (0, utils_1.checkAndGetCredential)(true);
|
|
18
|
+
const app = new manager_node_1.default({
|
|
19
|
+
region,
|
|
20
|
+
token,
|
|
21
|
+
envId,
|
|
22
|
+
secretId,
|
|
23
|
+
secretKey,
|
|
24
|
+
proxy: (0, utils_1.getProxy)()
|
|
37
25
|
});
|
|
26
|
+
return app.functions;
|
|
38
27
|
}
|
|
39
28
|
exports.getFunctionService = getFunctionService;
|
|
40
|
-
function listFunction(options) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
Status
|
|
59
|
-
});
|
|
29
|
+
async function listFunction(options) {
|
|
30
|
+
const { limit = 20, offset = 0, envId } = options;
|
|
31
|
+
const res = await scfService.request('ListFunctions', {
|
|
32
|
+
Namespace: envId,
|
|
33
|
+
Limit: limit,
|
|
34
|
+
Offset: offset
|
|
35
|
+
});
|
|
36
|
+
const { Functions = [] } = res;
|
|
37
|
+
const data = [];
|
|
38
|
+
Functions.forEach(func => {
|
|
39
|
+
const { FunctionId, FunctionName, Runtime, AddTime, ModTime, Status } = func;
|
|
40
|
+
data.push({
|
|
41
|
+
FunctionId,
|
|
42
|
+
FunctionName,
|
|
43
|
+
Runtime,
|
|
44
|
+
AddTime,
|
|
45
|
+
ModTime,
|
|
46
|
+
Status
|
|
60
47
|
});
|
|
61
|
-
return data;
|
|
62
48
|
});
|
|
49
|
+
return data;
|
|
63
50
|
}
|
|
64
51
|
exports.listFunction = listFunction;
|
|
65
|
-
function listAllFunctions(options) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
break;
|
|
81
|
-
}
|
|
82
|
-
allFunctions.push(...Functions);
|
|
83
|
-
if (allFunctions.length >= TotalCount || Functions.length < pageSize) {
|
|
84
|
-
break;
|
|
85
|
-
}
|
|
86
|
-
currentOffset += pageSize;
|
|
52
|
+
async function listAllFunctions(options) {
|
|
53
|
+
const allFunctions = [];
|
|
54
|
+
let currentOffset = 0;
|
|
55
|
+
const pageSize = 20;
|
|
56
|
+
const { envId } = options;
|
|
57
|
+
while (true) {
|
|
58
|
+
try {
|
|
59
|
+
const res = await scfService.request('ListFunctions', {
|
|
60
|
+
Namespace: envId,
|
|
61
|
+
Limit: pageSize,
|
|
62
|
+
Offset: currentOffset
|
|
63
|
+
});
|
|
64
|
+
const { Functions = [], TotalCount } = res;
|
|
65
|
+
if (Functions.length === 0) {
|
|
66
|
+
break;
|
|
87
67
|
}
|
|
88
|
-
|
|
89
|
-
|
|
68
|
+
allFunctions.push(...Functions);
|
|
69
|
+
if (allFunctions.length >= TotalCount || Functions.length < pageSize) {
|
|
70
|
+
break;
|
|
90
71
|
}
|
|
72
|
+
currentOffset += pageSize;
|
|
91
73
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
74
|
+
catch (error) {
|
|
75
|
+
throw new error_1.CloudBaseError((0, i18n_1.t)('获取函数列表失败: {{error}}', { error: error.message }));
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const data = [];
|
|
79
|
+
allFunctions.forEach(func => {
|
|
80
|
+
const { FunctionId, FunctionName, Runtime, AddTime, ModTime, Status } = func;
|
|
81
|
+
data.push({
|
|
82
|
+
FunctionId,
|
|
83
|
+
FunctionName,
|
|
84
|
+
Runtime,
|
|
85
|
+
AddTime,
|
|
86
|
+
ModTime,
|
|
87
|
+
Status
|
|
103
88
|
});
|
|
104
|
-
return data;
|
|
105
89
|
});
|
|
90
|
+
return data;
|
|
106
91
|
}
|
|
107
92
|
exports.listAllFunctions = listAllFunctions;
|
|
108
|
-
function getFunctionDetail(options) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
CodeSecret: codeSecret
|
|
116
|
-
});
|
|
117
|
-
const data = res;
|
|
118
|
-
const { VpcId = '', SubnetId = '' } = data.VpcConfig || {};
|
|
119
|
-
if (VpcId && SubnetId) {
|
|
120
|
-
try {
|
|
121
|
-
const vpcs = yield (0, vpc_1.getVpcs)();
|
|
122
|
-
const subnets = yield (0, vpc_1.getSubnets)(VpcId);
|
|
123
|
-
const vpc = vpcs.find(item => item.VpcId === VpcId);
|
|
124
|
-
const subnet = subnets.find(item => item.SubnetId === SubnetId);
|
|
125
|
-
data.VpcConfig = {
|
|
126
|
-
vpc,
|
|
127
|
-
subnet
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
catch (e) {
|
|
131
|
-
data.VpcConfig = {
|
|
132
|
-
vpc: VpcId,
|
|
133
|
-
subnet: SubnetId
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
return data;
|
|
93
|
+
async function getFunctionDetail(options) {
|
|
94
|
+
const { functionName, envId, codeSecret } = options;
|
|
95
|
+
const res = await scfService.request('GetFunction', {
|
|
96
|
+
FunctionName: functionName,
|
|
97
|
+
Namespace: envId,
|
|
98
|
+
ShowCode: 'TRUE',
|
|
99
|
+
CodeSecret: codeSecret
|
|
138
100
|
});
|
|
101
|
+
const data = res;
|
|
102
|
+
const { VpcId = '', SubnetId = '' } = data.VpcConfig || {};
|
|
103
|
+
if (VpcId && SubnetId) {
|
|
104
|
+
try {
|
|
105
|
+
const vpcs = await (0, vpc_1.getVpcs)();
|
|
106
|
+
const subnets = await (0, vpc_1.getSubnets)(VpcId);
|
|
107
|
+
const vpc = vpcs.find(item => item.VpcId === VpcId);
|
|
108
|
+
const subnet = subnets.find(item => item.SubnetId === SubnetId);
|
|
109
|
+
data.VpcConfig = {
|
|
110
|
+
vpc,
|
|
111
|
+
subnet
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
catch (e) {
|
|
115
|
+
data.VpcConfig = {
|
|
116
|
+
vpc: VpcId,
|
|
117
|
+
subnet: SubnetId
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return data;
|
|
139
122
|
}
|
|
140
123
|
exports.getFunctionDetail = getFunctionDetail;
|
|
141
|
-
function batchGetFunctionsDetail({ names, envId, codeSecret }) {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
return data;
|
|
159
|
-
});
|
|
124
|
+
async function batchGetFunctionsDetail({ names, envId, codeSecret }) {
|
|
125
|
+
const data = [];
|
|
126
|
+
const promises = names.map(name => (async () => {
|
|
127
|
+
try {
|
|
128
|
+
const info = await getFunctionDetail({
|
|
129
|
+
envId,
|
|
130
|
+
codeSecret,
|
|
131
|
+
functionName: name
|
|
132
|
+
});
|
|
133
|
+
data.push(info);
|
|
134
|
+
}
|
|
135
|
+
catch (e) {
|
|
136
|
+
throw new error_1.CloudBaseError((0, i18n_1.t)('{{name}} 获取信息失败:{{error}}', { name, error: e.message }));
|
|
137
|
+
}
|
|
138
|
+
})());
|
|
139
|
+
await Promise.all(promises);
|
|
140
|
+
return data;
|
|
160
141
|
}
|
|
161
142
|
exports.batchGetFunctionsDetail = batchGetFunctionsDetail;
|
|
162
|
-
function getFunctionLog(options) {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
params[keyFirstCharUpperCase] = options[key];
|
|
173
|
-
});
|
|
174
|
-
const { Data = [] } = yield scfService.request('GetFunctionLogs', params);
|
|
175
|
-
return Data;
|
|
143
|
+
async function getFunctionLog(options) {
|
|
144
|
+
const { envId } = options;
|
|
145
|
+
const params = {
|
|
146
|
+
Namespace: envId
|
|
147
|
+
};
|
|
148
|
+
Object.keys(options).forEach(key => {
|
|
149
|
+
if (key === 'envId')
|
|
150
|
+
return;
|
|
151
|
+
const keyFirstCharUpperCase = key.charAt(0).toUpperCase() + key.slice(1);
|
|
152
|
+
params[keyFirstCharUpperCase] = options[key];
|
|
176
153
|
});
|
|
154
|
+
const { Data = [] } = await scfService.request('GetFunctionLogs', params);
|
|
155
|
+
return Data;
|
|
177
156
|
}
|
|
178
157
|
exports.getFunctionLog = getFunctionLog;
|
|
179
|
-
function updateFunctionConfig(options) {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
158
|
+
async function updateFunctionConfig(options) {
|
|
159
|
+
const { functionName, config, envId } = options;
|
|
160
|
+
const functionService = await getFunctionService(envId);
|
|
161
|
+
await functionService.updateFunctionConfig({
|
|
162
|
+
name: functionName,
|
|
163
|
+
...config
|
|
184
164
|
});
|
|
185
165
|
}
|
|
186
166
|
exports.updateFunctionConfig = updateFunctionConfig;
|
|
187
|
-
function batchUpdateFunctionConfig(options) {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
const promises = functions.map(func => (() => __awaiter(this, void 0, void 0, function* () {
|
|
191
|
-
try {
|
|
192
|
-
yield updateFunctionConfig({
|
|
193
|
-
functionName: func.name,
|
|
194
|
-
config: func,
|
|
195
|
-
envId
|
|
196
|
-
});
|
|
197
|
-
log && (0, logger_1.successLog)((0, i18n_1.t)('[{{name}}] 更新云函数配置成功!', { name: func.name }));
|
|
198
|
-
}
|
|
199
|
-
catch (e) {
|
|
200
|
-
throw new error_1.CloudBaseError((0, i18n_1.t)('{{name}} 更新配置失败:{{error}}', { name: func.name, error: e.message }));
|
|
201
|
-
}
|
|
202
|
-
}))());
|
|
203
|
-
yield Promise.all(promises);
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
exports.batchUpdateFunctionConfig = batchUpdateFunctionConfig;
|
|
207
|
-
function invokeFunction(options) {
|
|
208
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
209
|
-
const { functionName, envId, params = {} } = options;
|
|
210
|
-
const _params = {
|
|
211
|
-
FunctionName: functionName,
|
|
212
|
-
Namespace: envId,
|
|
213
|
-
ClientContext: JSON.stringify(params),
|
|
214
|
-
LogType: 'Tail'
|
|
215
|
-
};
|
|
167
|
+
async function batchUpdateFunctionConfig(options) {
|
|
168
|
+
const { functions, envId, log } = options;
|
|
169
|
+
const promises = functions.map(func => (async () => {
|
|
216
170
|
try {
|
|
217
|
-
|
|
218
|
-
|
|
171
|
+
await updateFunctionConfig({
|
|
172
|
+
functionName: func.name,
|
|
173
|
+
config: func,
|
|
174
|
+
envId
|
|
175
|
+
});
|
|
176
|
+
log && (0, logger_1.successLog)((0, i18n_1.t)('[{{name}}] 更新云函数配置成功!', { name: func.name }));
|
|
219
177
|
}
|
|
220
178
|
catch (e) {
|
|
221
|
-
throw new error_1.CloudBaseError((0, i18n_1.t)('
|
|
179
|
+
throw new error_1.CloudBaseError((0, i18n_1.t)('{{name}} 更新配置失败:{{error}}', { name: func.name, error: e.message }));
|
|
222
180
|
}
|
|
223
|
-
});
|
|
181
|
+
})());
|
|
182
|
+
await Promise.all(promises);
|
|
183
|
+
}
|
|
184
|
+
exports.batchUpdateFunctionConfig = batchUpdateFunctionConfig;
|
|
185
|
+
async function invokeFunction(options) {
|
|
186
|
+
const { functionName, envId, params = {} } = options;
|
|
187
|
+
const _params = {
|
|
188
|
+
FunctionName: functionName,
|
|
189
|
+
Namespace: envId,
|
|
190
|
+
ClientContext: JSON.stringify(params),
|
|
191
|
+
LogType: 'Tail'
|
|
192
|
+
};
|
|
193
|
+
try {
|
|
194
|
+
const { Result } = await scfService.request('Invoke', _params);
|
|
195
|
+
return Result;
|
|
196
|
+
}
|
|
197
|
+
catch (e) {
|
|
198
|
+
throw new error_1.CloudBaseError((0, i18n_1.t)('[{{name}}] 调用失败:\n{{error}}', { name: functionName, error: e.message }));
|
|
199
|
+
}
|
|
224
200
|
}
|
|
225
201
|
exports.invokeFunction = invokeFunction;
|
|
226
|
-
function batchInvokeFunctions(options) {
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
console.log(result);
|
|
239
|
-
}
|
|
240
|
-
return result;
|
|
241
|
-
}
|
|
242
|
-
catch (e) {
|
|
243
|
-
throw new error_1.CloudBaseError((0, i18n_1.t)('{{name}} 函数调用失败:{{error}}', { name: func.name, error: e.message }));
|
|
202
|
+
async function batchInvokeFunctions(options) {
|
|
203
|
+
const { functions, envId, log = false } = options;
|
|
204
|
+
const promises = functions.map(func => (async () => {
|
|
205
|
+
try {
|
|
206
|
+
const result = await invokeFunction({
|
|
207
|
+
functionName: func.name,
|
|
208
|
+
params: func.params,
|
|
209
|
+
envId
|
|
210
|
+
});
|
|
211
|
+
if (log) {
|
|
212
|
+
(0, logger_1.successLog)((0, i18n_1.t)('[{{name}}] 调用成功\n响应结果:\n', { name: func.name }));
|
|
213
|
+
console.log(result);
|
|
244
214
|
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
215
|
+
return result;
|
|
216
|
+
}
|
|
217
|
+
catch (e) {
|
|
218
|
+
throw new error_1.CloudBaseError((0, i18n_1.t)('{{name}} 函数调用失败:{{error}}', { name: func.name, error: e.message }));
|
|
219
|
+
}
|
|
220
|
+
})());
|
|
221
|
+
return Promise.all(promises);
|
|
248
222
|
}
|
|
249
223
|
exports.batchInvokeFunctions = batchInvokeFunctions;
|
|
250
|
-
function copyFunction(options) {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
CodeSecret: codeSecret
|
|
263
|
-
});
|
|
224
|
+
async function copyFunction(options) {
|
|
225
|
+
const { envId, functionName, newFunctionName, targetEnvId, force, codeSecret } = options;
|
|
226
|
+
if (!envId || !functionName || !newFunctionName) {
|
|
227
|
+
throw new error_1.CloudBaseError((0, i18n_1.t)('参数缺失'));
|
|
228
|
+
}
|
|
229
|
+
await scfService.request('CopyFunction', {
|
|
230
|
+
FunctionName: functionName,
|
|
231
|
+
NewFunctionName: newFunctionName,
|
|
232
|
+
Namespace: envId,
|
|
233
|
+
TargetNamespace: targetEnvId || envId,
|
|
234
|
+
Override: force ? true : false,
|
|
235
|
+
CodeSecret: codeSecret
|
|
264
236
|
});
|
|
265
237
|
}
|
|
266
238
|
exports.copyFunction = copyFunction;
|
package/lib/function/code.js
CHANGED
|
@@ -1,28 +1,17 @@
|
|
|
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.downloadFunctionCode = void 0;
|
|
13
4
|
const utils_1 = require("../utils");
|
|
14
5
|
const common_1 = require("../utils/tools/common");
|
|
15
6
|
const scfService = utils_1.CloudApiService.getInstance('scf');
|
|
16
|
-
function downloadFunctionCode(options) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
CodeSecret: codeSecret
|
|
24
|
-
});
|
|
25
|
-
return (0, common_1.downloadAndExtractRemoteZip)(Url, destPath);
|
|
7
|
+
async function downloadFunctionCode(options) {
|
|
8
|
+
const { destPath, envId, functionName, codeSecret } = options;
|
|
9
|
+
(0, utils_1.checkFullAccess)(destPath, true);
|
|
10
|
+
const { Url } = await scfService.request('GetFunctionAddress', {
|
|
11
|
+
FunctionName: functionName,
|
|
12
|
+
Namespace: envId,
|
|
13
|
+
CodeSecret: codeSecret
|
|
26
14
|
});
|
|
15
|
+
return (0, common_1.downloadAndExtractRemoteZip)(Url, destPath);
|
|
27
16
|
}
|
|
28
17
|
exports.downloadFunctionCode = downloadFunctionCode;
|
|
@@ -1,70 +1,55 @@
|
|
|
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.deleteProvisionedConcurrencyConfig = exports.getProvisionedConcurrencyConfig = exports.setProvisionedConcurrencyConfig = void 0;
|
|
13
4
|
const error_1 = require("../error");
|
|
14
5
|
const base_1 = require("./base");
|
|
15
6
|
const i18n_1 = require("../i18n");
|
|
16
|
-
function setProvisionedConcurrencyConfig(options) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
});
|
|
7
|
+
async function setProvisionedConcurrencyConfig(options) {
|
|
8
|
+
const { envId, functionName, qualifier, versionProvisionedConcurrencyNum } = options;
|
|
9
|
+
const scfService = await (0, base_1.getFunctionService)(envId);
|
|
10
|
+
try {
|
|
11
|
+
await scfService.setProvisionedConcurrencyConfig({
|
|
12
|
+
functionName,
|
|
13
|
+
qualifier,
|
|
14
|
+
versionProvisionedConcurrencyNum
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
catch (e) {
|
|
18
|
+
throw new error_1.CloudBaseError((0, i18n_1.t)('[{{name}}] 设置函数预置并发失败: {{error}}', { name: functionName, error: e.message }), {
|
|
19
|
+
code: e.code
|
|
20
|
+
});
|
|
21
|
+
}
|
|
33
22
|
}
|
|
34
23
|
exports.setProvisionedConcurrencyConfig = setProvisionedConcurrencyConfig;
|
|
35
|
-
function getProvisionedConcurrencyConfig(options) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
});
|
|
24
|
+
async function getProvisionedConcurrencyConfig(options) {
|
|
25
|
+
const { envId, functionName, qualifier } = options;
|
|
26
|
+
const scfService = await (0, base_1.getFunctionService)(envId);
|
|
27
|
+
try {
|
|
28
|
+
return scfService.getProvisionedConcurrencyConfig({
|
|
29
|
+
functionName,
|
|
30
|
+
qualifier,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
throw new error_1.CloudBaseError((0, i18n_1.t)('[{{name}}] 查看函数预置并发信息失败: {{error}}', { name: functionName, error: e.message }), {
|
|
35
|
+
code: e.code
|
|
36
|
+
});
|
|
37
|
+
}
|
|
51
38
|
}
|
|
52
39
|
exports.getProvisionedConcurrencyConfig = getProvisionedConcurrencyConfig;
|
|
53
|
-
function deleteProvisionedConcurrencyConfig(options) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
});
|
|
40
|
+
async function deleteProvisionedConcurrencyConfig(options) {
|
|
41
|
+
const { envId, functionName, qualifier } = options;
|
|
42
|
+
const scfService = await (0, base_1.getFunctionService)(envId);
|
|
43
|
+
try {
|
|
44
|
+
await scfService.deleteProvisionedConcurrencyConfig({
|
|
45
|
+
functionName,
|
|
46
|
+
qualifier
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
catch (e) {
|
|
50
|
+
throw new error_1.CloudBaseError((0, i18n_1.t)('[{{name}}] 删除函数预置并发失败: {{error}}', { name: functionName, error: e.message }), {
|
|
51
|
+
code: e.code
|
|
52
|
+
});
|
|
53
|
+
}
|
|
69
54
|
}
|
|
70
55
|
exports.deleteProvisionedConcurrencyConfig = deleteProvisionedConcurrencyConfig;
|