@cloudbase/manager-node 5.7.1-beta.0 → 5.8.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 (62) hide show
  1. package/lib/cloudApp/index.js +12 -3
  2. package/lib/deploy/DatabaseDeployer.js +238 -0
  3. package/lib/deploy/DeployOrchestrator.js +645 -0
  4. package/lib/deploy/FunctionDeployer.js +611 -0
  5. package/lib/deploy/GatewayDeployer.js +612 -0
  6. package/lib/deploy/StateStore.js +327 -0
  7. package/lib/deploy/StaticDeployer.js +236 -0
  8. package/lib/deploy/domain.js +41 -0
  9. package/lib/deploy/framework.js +230 -0
  10. package/lib/deploy/function/artifact.js +207 -0
  11. package/lib/deploy/function/builders/cloud.js +654 -0
  12. package/lib/deploy/function/cam-preflight.js +157 -0
  13. package/lib/deploy/function/cloud-build-service.js +191 -0
  14. package/lib/deploy/function/config-guard.js +595 -0
  15. package/lib/deploy/function/docker-preflight.js +87 -0
  16. package/lib/deploy/function/image-preflight.js +164 -0
  17. package/lib/deploy/function/local-builder.js +129 -0
  18. package/lib/deploy/function/planner.js +278 -0
  19. package/lib/deploy/function/preflight.js +329 -0
  20. package/lib/deploy/types.js +103 -0
  21. package/lib/env/index.js +0 -9
  22. package/lib/environment.js +11 -0
  23. package/lib/function/index.js +1 -1
  24. package/lib/hosting/index.js +4 -1
  25. package/lib/index.js +31 -0
  26. package/lib/projectValidator/index.js +452 -0
  27. package/lib/projectValidator/types.js +2 -0
  28. package/lib/storage/index.js +6 -7
  29. package/lib/utils/index.js +62 -5
  30. package/package.json +2 -1
  31. package/types/cloudApp/index.d.ts +4 -0
  32. package/types/cloudApp/types.d.ts +87 -6
  33. package/types/deploy/DatabaseDeployer.d.ts +70 -0
  34. package/types/deploy/DeployOrchestrator.d.ts +170 -0
  35. package/types/deploy/FunctionDeployer.d.ts +159 -0
  36. package/types/deploy/GatewayDeployer.d.ts +194 -0
  37. package/types/deploy/StateStore.d.ts +170 -0
  38. package/types/deploy/StaticDeployer.d.ts +97 -0
  39. package/types/deploy/domain.d.ts +17 -0
  40. package/types/deploy/framework.d.ts +63 -0
  41. package/types/deploy/function/artifact.d.ts +40 -0
  42. package/types/deploy/function/builders/cloud.d.ts +110 -0
  43. package/types/deploy/function/cam-preflight.d.ts +51 -0
  44. package/types/deploy/function/cloud-build-service.d.ts +10 -0
  45. package/types/deploy/function/config-guard.d.ts +41 -0
  46. package/types/deploy/function/docker-preflight.d.ts +17 -0
  47. package/types/deploy/function/image-preflight.d.ts +21 -0
  48. package/types/deploy/function/local-builder.d.ts +26 -0
  49. package/types/deploy/function/planner.d.ts +15 -0
  50. package/types/deploy/function/preflight.d.ts +9 -0
  51. package/types/deploy/types.d.ts +429 -0
  52. package/types/env/index.d.ts +1 -8
  53. package/types/env/type.d.ts +6 -97
  54. package/types/environment.d.ts +7 -0
  55. package/types/function/types.d.ts +15 -0
  56. package/types/hosting/index.d.ts +6 -0
  57. package/types/index.d.ts +18 -0
  58. package/types/interfaces/function.interface.d.ts +1 -1
  59. package/types/projectValidator/index.d.ts +38 -0
  60. package/types/projectValidator/types.d.ts +26 -0
  61. package/types/storage/index.d.ts +6 -0
  62. package/types/utils/index.d.ts +13 -0
@@ -0,0 +1,230 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.FRAMEWORK_OUTPUT_DIRS = exports.FRAMEWORK_BUILD_COMMANDS = void 0;
37
+ exports.detectFramework = detectFramework;
38
+ exports.resolveBuildCommand = resolveBuildCommand;
39
+ exports.resolveOutputDir = resolveOutputDir;
40
+ exports.resolveHostingOutputDir = resolveHostingOutputDir;
41
+ const fs = __importStar(require("fs"));
42
+ const path = __importStar(require("path"));
43
+ /**
44
+ * 框架 → 默认构建命令映射(hosting 本地构建 / app 云端构建复用)
45
+ */
46
+ exports.FRAMEWORK_BUILD_COMMANDS = {
47
+ react: 'react-scripts build',
48
+ vue: 'vue-cli-service build',
49
+ vite: 'vite build',
50
+ 'vite-react': 'vite build',
51
+ 'vite-vue': 'vite build',
52
+ next: 'next build',
53
+ nuxt: 'nuxt build',
54
+ angular: 'ng build'
55
+ };
56
+ /**
57
+ * 框架 → 默认构建产物目录映射(与 FRAMEWORK_BUILD_COMMANDS 一一对应)
58
+ *
59
+ * 注意不能全部默认 dist:
60
+ * - CRA(react-scripts build)实际输出 build/
61
+ * - next/nuxt 输出 .next/.nuxt
62
+ * - vite/vue 输出 dist
63
+ * - angular 默认 outputPath 为 dist/<项目名>,产物在子目录而非 dist/ 根目录(见 resolveAngularOutputDir),
64
+ * 此处 'dist' 仅作 angular.json 推导失败时的回退值
65
+ * 构建场景 outputDir 未显式配置时必须按此映射取产物目录,否则上传路径与构建产物不一致导致部署失败
66
+ * (或上传到陈旧的 dist 目录)。
67
+ */
68
+ exports.FRAMEWORK_OUTPUT_DIRS = {
69
+ react: 'build',
70
+ vue: 'dist',
71
+ vite: 'dist',
72
+ 'vite-react': 'dist',
73
+ 'vite-vue': 'dist',
74
+ next: '.next',
75
+ nuxt: '.nuxt',
76
+ angular: 'dist'
77
+ };
78
+ /**
79
+ * package.json 依赖探测规则(识别度从高到低)
80
+ * 每个条目:[框架名, 触发依赖列表]
81
+ */
82
+ const FRAMEWORK_DEPENDENCIES = [
83
+ ['next', ['next']],
84
+ ['nuxt', ['nuxt', 'nuxt3']],
85
+ ['angular', ['@angular/core']],
86
+ ['vite', ['vite']],
87
+ ['react', ['react-scripts']],
88
+ ['vue', ['@vue/cli-service']]
89
+ ];
90
+ const defaultReadPkgFile = (filePath, encoding) => fs.readFileSync(filePath, encoding);
91
+ /**
92
+ * 探测项目根目录下的框架类型(读 package.json 依赖)
93
+ * 读取失败或无匹配返回 null(按纯静态处理)
94
+ */
95
+ function detectFramework(root, readPkgFile = defaultReadPkgFile) {
96
+ let pkg;
97
+ try {
98
+ pkg = JSON.parse(readPkgFile(path.join(root, 'package.json'), 'utf8'));
99
+ }
100
+ catch (_a) {
101
+ return null;
102
+ }
103
+ const deps = Object.assign(Object.assign({}, (pkg.dependencies || {})), (pkg.devDependencies || {}));
104
+ const match = FRAMEWORK_DEPENDENCIES.find(([, depsList]) => depsList.some(dep => !!deps[dep]));
105
+ return match ? match[0] : null;
106
+ }
107
+ /**
108
+ * 解析构建命令,优先级:
109
+ * 1. 显式配置 buildCommand(含空字符串,'' = 不构建)
110
+ * 2. 显式配置 framework → 映射推导(static/custom → null 不构建)
111
+ * 3. 未配置 framework → 读 package.json 自动探测框架并推导
112
+ * 均无法确定 → null(纯静态直接上传)
113
+ */
114
+ function resolveBuildCommand(config, root, readPkgFile = defaultReadPkgFile) {
115
+ // 1. 显式 buildCommand 优先(含空字符串)
116
+ if (config.buildCommand !== undefined) {
117
+ return config.buildCommand || null;
118
+ }
119
+ // 2. 显式 framework → 映射推导
120
+ if (config.framework) {
121
+ return exports.FRAMEWORK_BUILD_COMMANDS[config.framework] || null;
122
+ }
123
+ // 3. package.json 自动探测(忘记配置 framework 时兜底,如 vite 项目)
124
+ const detected = detectFramework(root, readPkgFile);
125
+ if (detected) {
126
+ return exports.FRAMEWORK_BUILD_COMMANDS[detected] || null;
127
+ }
128
+ return null;
129
+ }
130
+ /**
131
+ * Angular CLI(v8+)默认 outputPath 为 dist/<项目名>(angular.json 脚手架生成值),
132
+ * ng build 产物实际位于 dist/<项目名>/ 子目录而非 dist/ 根目录。静态映射 'dist' 会指向产物父级,
133
+ * 导致整棵 dist/ 被上传、站点文件落到 cloudPath/<项目名>/ 下。
134
+ * 因此 angular 场景需读取 angular.json(Nx workspace 为 workspace.json)的
135
+ * projects.<默认项目>.architect.build.options.outputPath 推导真实产物目录。
136
+ * 读取失败(文件缺失/解析失败/未配置 outputPath)返回 null,由调用方回退静态映射。
137
+ */
138
+ function resolveAngularOutputDir(root) {
139
+ var _a, _b, _c;
140
+ for (const configFile of ['angular.json', 'workspace.json']) {
141
+ const configPath = path.join(root, configFile);
142
+ if (!fs.existsSync(configPath)) {
143
+ continue;
144
+ }
145
+ try {
146
+ const workspace = JSON.parse(fs.readFileSync(configPath, 'utf8'));
147
+ const projects = workspace === null || workspace === void 0 ? void 0 : workspace.projects;
148
+ if (!projects || typeof projects !== 'object') {
149
+ continue;
150
+ }
151
+ const projectName = workspace.defaultProject && projects[workspace.defaultProject]
152
+ ? workspace.defaultProject
153
+ : Object.keys(projects)[0];
154
+ const project = projectName ? projects[projectName] : undefined;
155
+ const build = ((_a = project === null || project === void 0 ? void 0 : project.architect) === null || _a === void 0 ? void 0 : _a.build) || ((_b = project === null || project === void 0 ? void 0 : project.targets) === null || _b === void 0 ? void 0 : _b.build);
156
+ const outputPath = (_c = build === null || build === void 0 ? void 0 : build.options) === null || _c === void 0 ? void 0 : _c.outputPath;
157
+ if (typeof outputPath === 'string' && outputPath) {
158
+ return outputPath;
159
+ }
160
+ // 个别自定义 builder 的 outputPath 为数组(多产物场景),取首个
161
+ if (Array.isArray(outputPath) &&
162
+ outputPath.length > 0 &&
163
+ typeof outputPath[0] === 'string') {
164
+ return outputPath[0];
165
+ }
166
+ }
167
+ catch (_d) {
168
+ // 解析失败 → 继续尝试下一个配置文件
169
+ }
170
+ }
171
+ return null;
172
+ }
173
+ /**
174
+ * 按框架取默认产物目录(resolveOutputDir 步骤 2/3 共用)。
175
+ * angular 默认 outputPath 为 dist/<项目名>,需从 angular.json 推导真实产物目录;
176
+ * 推导失败(未找到 angular.json/workspace.json 或未配置 outputPath)回退静态映射 'dist'。
177
+ */
178
+ function resolveOutputDirByFramework(framework, root) {
179
+ if (framework === 'angular') {
180
+ return resolveAngularOutputDir(root) || exports.FRAMEWORK_OUTPUT_DIRS[framework] || null;
181
+ }
182
+ return exports.FRAMEWORK_OUTPUT_DIRS[framework] || null;
183
+ }
184
+ /**
185
+ * 解析默认产物目录(有构建场景),优先级:
186
+ * 1. 显式配置 outputDir → 直接返回(调用方负责 path.resolve)
187
+ * 2. 显式 framework → FRAMEWORK_OUTPUT_DIRS 映射(react → build,vite/vue → dist,next → .next;
188
+ * angular 默认 outputPath 为 dist/<项目名>,从 angular.json 推导真实产物目录)
189
+ * 3. package.json 自动探测框架 → 映射推导
190
+ * 均无法确定(纯静态)→ null,由调用方回退到 root
191
+ *
192
+ * 与 resolveBuildCommand 共用同一份「框架探测/推导」逻辑,保证「构建产物目录」与「构建命令」来自同一次探测,
193
+ * 避免 CRA 场景探测到 react-scripts build(产物在 build/)却默认上传 dist 导致路径不存在。
194
+ */
195
+ function resolveOutputDir(config, root, readPkgFile = defaultReadPkgFile) {
196
+ // 1. 显式配置优先
197
+ if (config.outputDir) {
198
+ return config.outputDir;
199
+ }
200
+ // 2. 显式 framework → 映射推导
201
+ if (config.framework) {
202
+ return resolveOutputDirByFramework(config.framework, root);
203
+ }
204
+ // 3. package.json 自动探测(需先读 package.json,与 resolveBuildCommand 同一探测源)
205
+ const detected = detectFramework(root, readPkgFile);
206
+ if (detected) {
207
+ return resolveOutputDirByFramework(detected, root);
208
+ }
209
+ return null;
210
+ }
211
+ /**
212
+ * 统一解析 hosting 上传目录(绝对路径),与 StaticDeployer.deployHosting 保持严格一致。
213
+ *
214
+ * 规则:
215
+ * 1) 有构建命令时:
216
+ * - 显式 buildCommand(自定义构建):outputDir 未配置回退 root/dist
217
+ * - 推导 buildCommand(framework / package.json):按 resolveOutputDir 框架映射,未命中回退 dist
218
+ * 2) 无构建命令时:
219
+ * - outputDir 未配置回退 root(纯静态直传)
220
+ */
221
+ function resolveHostingOutputDir(config, root, readPkgFile = defaultReadPkgFile) {
222
+ const buildCommand = resolveBuildCommand(config, root, readPkgFile);
223
+ if (buildCommand) {
224
+ if (config.buildCommand !== undefined) {
225
+ return path.resolve(root, config.outputDir || 'dist');
226
+ }
227
+ return path.resolve(root, resolveOutputDir(config, root, readPkgFile) || 'dist');
228
+ }
229
+ return config.outputDir ? path.resolve(root, config.outputDir) : root;
230
+ }
@@ -0,0 +1,207 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createCodeArtifact = createCodeArtifact;
4
+ exports.createImageArtifactFromConfig = createImageArtifactFromConfig;
5
+ exports.createImageArtifactFromBuild = createImageArtifactFromBuild;
6
+ exports.createImageArtifactFromCloudBuild = createImageArtifactFromCloudBuild;
7
+ exports.toCloudFunction = toCloudFunction;
8
+ const types_1 = require("../types");
9
+ /**
10
+ * 部署物构造与 SCF 参数映射
11
+ *
12
+ * 四种构建策略最终都产出统一的部署物,之后走同一条 SCF 创建或更新流程
13
+ */
14
+ /** 由本地代码来源构造代码类部署物 */
15
+ function createCodeArtifact(config) {
16
+ const functionRootPath = 'functionRootPath' in config ? config.functionRootPath : undefined;
17
+ const functionPath = 'functionPath' in config ? config.functionPath : undefined;
18
+ const base64Code = 'base64Code' in config ? config.base64Code : undefined;
19
+ // 直接给出 ZIP base64 时按 ZipFile 传输,其余情况统一走临时 COS,避免大包超限
20
+ const deployMode = base64Code ? 'zip' : 'cos';
21
+ return {
22
+ kind: 'code',
23
+ deployMode,
24
+ functionRootPath,
25
+ functionPath,
26
+ base64Code
27
+ };
28
+ }
29
+ /** 由已有镜像配置构造镜像类部署物 */
30
+ function createImageArtifactFromConfig(config) {
31
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
32
+ const { imageConfig } = config;
33
+ // imageType/registryId 的契约位置在配置顶层(IHttpImageRuntimeCommon),
34
+ // 与 local/cloud 策略一致;imageConfig 内的同名字段仅作向后兼容兜底。
35
+ // 个人版镜像(personal,如个人版 CCR)不应携带 registryId。
36
+ const imageType = (_b = (_a = config.imageType) !== null && _a !== void 0 ? _a : imageConfig.imageType) !== null && _b !== void 0 ? _b : 'enterprise';
37
+ const registryId = imageType === 'enterprise'
38
+ ? (_c = config.registryId) !== null && _c !== void 0 ? _c : imageConfig.registryId
39
+ : undefined;
40
+ return {
41
+ kind: 'image',
42
+ deployMode: 'image',
43
+ imageUri: imageConfig.imageUri,
44
+ imageType,
45
+ registryId,
46
+ imagePort: types_1.IMAGE_FUNCTION_PORT,
47
+ effectiveStrategy: 'image',
48
+ entryPoint: (_d = imageConfig.entryPoint) !== null && _d !== void 0 ? _d : config.entryPoint,
49
+ command: (_e = imageConfig.command) !== null && _e !== void 0 ? _e : config.command,
50
+ args: (_f = imageConfig.args) !== null && _f !== void 0 ? _f : config.args,
51
+ commandList: (_g = imageConfig.commandList) !== null && _g !== void 0 ? _g : config.commandList,
52
+ argsList: (_h = imageConfig.argsList) !== null && _h !== void 0 ? _h : config.argsList,
53
+ containerImageAccelerate: (_j = imageConfig.containerImageAccelerate) !== null && _j !== void 0 ? _j : config.containerImageAccelerate
54
+ };
55
+ }
56
+ /**
57
+ * 由本地构建结果构造镜像类部署物
58
+ *
59
+ * local 策略(个人版先行)产出:镜像已由 local-builder 构建并推送,
60
+ * 此处仅承载最终 imageUri/digest 与容器启动配置,之后复用镜像部署链。
61
+ */
62
+ function createImageArtifactFromBuild(config, build) {
63
+ var _a;
64
+ return {
65
+ kind: 'image',
66
+ deployMode: 'image',
67
+ imageUri: build.imageUri,
68
+ imageDigest: build.imageDigest,
69
+ // 个人版先行:local 构建统一按 personal 处理,企业版增强后置
70
+ imageType: (_a = config.imageType) !== null && _a !== void 0 ? _a : 'personal',
71
+ imagePort: types_1.IMAGE_FUNCTION_PORT,
72
+ effectiveStrategy: 'local',
73
+ entryPoint: config.entryPoint,
74
+ command: config.command,
75
+ args: config.args,
76
+ commandList: config.commandList,
77
+ argsList: config.argsList,
78
+ containerImageAccelerate: config.containerImageAccelerate
79
+ };
80
+ }
81
+ /**
82
+ * 由云端构建结果构造镜像类部署物
83
+ *
84
+ * cloud 策略(CloudApp custom)产出:镜像已在构建容器内 docker build + push到 TCR,
85
+ * 此处仅承载最终 imageUri/digest 与构建元信息(buildId/logsUrl),之后复用镜像部署链。
86
+ * effectiveStrategy 标记为 cloud,便于结果层如实回传实际生效的策略。
87
+ */
88
+ function createImageArtifactFromCloudBuild(config, build) {
89
+ var _a, _b;
90
+ const imageType = (_a = config.imageType) !== null && _a !== void 0 ? _a : (config.build.registryId ? 'enterprise' : 'personal');
91
+ const registryId = imageType === 'enterprise'
92
+ ? (_b = config.registryId) !== null && _b !== void 0 ? _b : config.build.registryId
93
+ : undefined;
94
+ return {
95
+ kind: 'image',
96
+ deployMode: 'image',
97
+ imageUri: build.imageUri,
98
+ imageDigest: build.imageDigest,
99
+ // 云端构建默认推送到个人版 TCR(CCR);企业版实例 ID 位于 build.registryId,
100
+ // 需继续透传到 Stage B 的 SCF ImageConfig,避免构建成功后拉取镜像时丢失 RegistryId。
101
+ imageType,
102
+ registryId,
103
+ imagePort: types_1.IMAGE_FUNCTION_PORT,
104
+ effectiveStrategy: 'cloud',
105
+ buildId: build.buildId,
106
+ logsUrl: build.logsUrl,
107
+ entryPoint: config.entryPoint,
108
+ command: config.command,
109
+ args: config.args,
110
+ commandList: config.commandList,
111
+ argsList: config.argsList,
112
+ containerImageAccelerate: config.containerImageAccelerate
113
+ };
114
+ }
115
+ /** 将镜像部署物转换为 SCF 镜像配置 */
116
+ function toFunctionImageConfig(artifact) {
117
+ const imageConfig = {
118
+ imageType: artifact.imageType,
119
+ imageUri: artifact.imageUri,
120
+ imagePort: artifact.imagePort
121
+ };
122
+ if (artifact.registryId !== undefined) {
123
+ imageConfig.registryId = artifact.registryId;
124
+ }
125
+ if (artifact.entryPoint !== undefined) {
126
+ imageConfig.entryPoint = artifact.entryPoint;
127
+ }
128
+ if (artifact.command !== undefined) {
129
+ imageConfig.command = artifact.command;
130
+ }
131
+ if (artifact.args !== undefined) {
132
+ imageConfig.args = artifact.args;
133
+ }
134
+ if (artifact.commandList !== undefined) {
135
+ imageConfig.commandList = artifact.commandList;
136
+ }
137
+ if (artifact.argsList !== undefined) {
138
+ imageConfig.argsList = artifact.argsList;
139
+ }
140
+ if (artifact.containerImageAccelerate !== undefined) {
141
+ imageConfig.containerImageAccelerate = artifact.containerImageAccelerate;
142
+ }
143
+ return imageConfig;
144
+ }
145
+ /**
146
+ * 将部署配置与部署物映射为 FunctionService 所需的云函数配置
147
+ *
148
+ * 只映射与 SCF 相关的字段,public、gatewayPath 等访问配置由后处理阶段负责
149
+ */
150
+ function toCloudFunction(config, artifact) {
151
+ const func = {
152
+ name: config.name,
153
+ type: config.type
154
+ };
155
+ // 通用透传字段用索引签名做动态拷贝而非裸 any,保留基本类型约束
156
+ const source = config;
157
+ const funcRecord = func;
158
+ const passthroughFields = [
159
+ 'description',
160
+ 'timeout',
161
+ 'memorySize',
162
+ 'envVariables',
163
+ 'vpc',
164
+ 'layers',
165
+ 'role',
166
+ 'codeSecret',
167
+ 'l5',
168
+ 'ignore'
169
+ ];
170
+ passthroughFields.forEach(field => {
171
+ if (source[field] !== undefined) {
172
+ funcRecord[field] = source[field];
173
+ }
174
+ });
175
+ if (config.type === 'HTTP') {
176
+ // config 已收窄为 HTTP 联合,以下字段均由 IHttpFunctionDeployCommon 定义,类型安全
177
+ if (config.protocolType !== undefined) {
178
+ func.protocolType = config.protocolType;
179
+ }
180
+ if (config.protocolParams !== undefined) {
181
+ func.protocolParams = config.protocolParams;
182
+ }
183
+ if (config.instanceConcurrencyConfig !== undefined) {
184
+ func.instanceConcurrencyConfig = config.instanceConcurrencyConfig;
185
+ }
186
+ }
187
+ else if (config.triggers !== undefined) {
188
+ func.triggers = config.triggers;
189
+ }
190
+ if (artifact.kind === 'image') {
191
+ // 镜像函数由容器启动命令决定入口,不传 handler 与 installDependency
192
+ func.runtime = 'CustomImage';
193
+ func.imageConfig = toFunctionImageConfig(artifact);
194
+ return func;
195
+ }
196
+ // 代码类函数的运行时字段:经funcRecord 动态拷贝,避免对联合类型逐一断言
197
+ if (source.runtime !== undefined) {
198
+ funcRecord.runtime = source.runtime;
199
+ }
200
+ if (source.handler !== undefined) {
201
+ funcRecord.handler = source.handler;
202
+ }
203
+ if (source.installDependency !== undefined) {
204
+ funcRecord.installDependency = source.installDependency;
205
+ }
206
+ return func;
207
+ }