@cloudbase/manager-node 5.6.8 → 5.7.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/cloudrun/index.js +0 -18
  3. package/lib/deploy/DatabaseDeployer.js +238 -0
  4. package/lib/deploy/DeployOrchestrator.js +564 -0
  5. package/lib/deploy/FunctionDeployer.js +611 -0
  6. package/lib/deploy/GatewayDeployer.js +522 -0
  7. package/lib/deploy/StateStore.js +327 -0
  8. package/lib/deploy/StaticDeployer.js +289 -0
  9. package/lib/deploy/domain.js +39 -0
  10. package/lib/deploy/framework.js +105 -0
  11. package/lib/deploy/function/artifact.js +207 -0
  12. package/lib/deploy/function/builders/cloud.js +454 -0
  13. package/lib/deploy/function/cam-preflight.js +157 -0
  14. package/lib/deploy/function/cloud-build-service.js +170 -0
  15. package/lib/deploy/function/config-guard.js +588 -0
  16. package/lib/deploy/function/docker-preflight.js +87 -0
  17. package/lib/deploy/function/image-preflight.js +164 -0
  18. package/lib/deploy/function/local-builder.js +110 -0
  19. package/lib/deploy/function/planner.js +282 -0
  20. package/lib/deploy/function/preflight.js +264 -0
  21. package/lib/deploy/types.js +99 -0
  22. package/lib/environment.js +11 -0
  23. package/lib/hosting/index.js +4 -1
  24. package/lib/index.js +31 -0
  25. package/lib/projectValidator/index.js +375 -0
  26. package/lib/projectValidator/types.js +2 -0
  27. package/lib/storage/index.js +6 -7
  28. package/lib/utils/index.js +41 -1
  29. package/package.json +2 -1
  30. package/types/cloudApp/index.d.ts +4 -0
  31. package/types/cloudApp/types.d.ts +87 -6
  32. package/types/cloudrun/index.d.ts +1 -7
  33. package/types/cloudrun/type.d.ts +0 -22
  34. package/types/deploy/DatabaseDeployer.d.ts +70 -0
  35. package/types/deploy/DeployOrchestrator.d.ts +150 -0
  36. package/types/deploy/FunctionDeployer.d.ts +158 -0
  37. package/types/deploy/GatewayDeployer.d.ts +175 -0
  38. package/types/deploy/StateStore.d.ts +170 -0
  39. package/types/deploy/StaticDeployer.d.ts +104 -0
  40. package/types/deploy/domain.d.ts +17 -0
  41. package/types/deploy/framework.d.ts +23 -0
  42. package/types/deploy/function/artifact.d.ts +40 -0
  43. package/types/deploy/function/builders/cloud.d.ts +110 -0
  44. package/types/deploy/function/cam-preflight.d.ts +51 -0
  45. package/types/deploy/function/cloud-build-service.d.ts +10 -0
  46. package/types/deploy/function/config-guard.d.ts +41 -0
  47. package/types/deploy/function/docker-preflight.d.ts +17 -0
  48. package/types/deploy/function/image-preflight.d.ts +21 -0
  49. package/types/deploy/function/local-builder.d.ts +26 -0
  50. package/types/deploy/function/planner.d.ts +15 -0
  51. package/types/deploy/function/preflight.d.ts +9 -0
  52. package/types/deploy/types.d.ts +429 -0
  53. package/types/env/type.d.ts +4 -4
  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 +24 -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,105 @@
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_BUILD_COMMANDS = void 0;
37
+ exports.detectFramework = detectFramework;
38
+ exports.resolveBuildCommand = resolveBuildCommand;
39
+ const fs = __importStar(require("fs"));
40
+ const path = __importStar(require("path"));
41
+ /**
42
+ * 框架 → 默认构建命令映射(hosting 本地构建 / app 云端构建复用)
43
+ */
44
+ exports.FRAMEWORK_BUILD_COMMANDS = {
45
+ react: 'react-scripts build',
46
+ vue: 'vue-cli-service build',
47
+ vite: 'vite build',
48
+ 'vite-react': 'vite build',
49
+ 'vite-vue': 'vite build',
50
+ next: 'next build',
51
+ nuxt: 'nuxt build',
52
+ angular: 'ng build'
53
+ };
54
+ /**
55
+ * package.json 依赖探测规则(识别度从高到低)
56
+ * 每个条目:[框架名, 触发依赖列表]
57
+ */
58
+ const FRAMEWORK_DEPENDENCIES = [
59
+ ['next', ['next']],
60
+ ['nuxt', ['nuxt', 'nuxt3']],
61
+ ['angular', ['@angular/core']],
62
+ ['vite', ['vite']],
63
+ ['react', ['react-scripts']],
64
+ ['vue', ['@vue/cli-service']]
65
+ ];
66
+ const defaultReadPkgFile = (filePath, encoding) => fs.readFileSync(filePath, encoding);
67
+ /**
68
+ * 探测项目根目录下的框架类型(读 package.json 依赖)
69
+ * 读取失败或无匹配返回 null(按纯静态处理)
70
+ */
71
+ function detectFramework(root, readPkgFile = defaultReadPkgFile) {
72
+ let pkg;
73
+ try {
74
+ pkg = JSON.parse(readPkgFile(path.join(root, 'package.json'), 'utf8'));
75
+ }
76
+ catch (_a) {
77
+ return null;
78
+ }
79
+ const deps = Object.assign(Object.assign({}, (pkg.dependencies || {})), (pkg.devDependencies || {}));
80
+ const match = FRAMEWORK_DEPENDENCIES.find(([, depsList]) => depsList.some(dep => !!deps[dep]));
81
+ return match ? match[0] : null;
82
+ }
83
+ /**
84
+ * 解析构建命令,优先级:
85
+ * 1. 显式配置 buildCommand(含空字符串,'' = 不构建)
86
+ * 2. 显式配置 framework → 映射推导(static/custom → null 不构建)
87
+ * 3. 未配置 framework → 读 package.json 自动探测框架并推导
88
+ * 均无法确定 → null(纯静态直接上传)
89
+ */
90
+ function resolveBuildCommand(config, root, readPkgFile = defaultReadPkgFile) {
91
+ // 1. 显式 buildCommand 优先(含空字符串)
92
+ if (config.buildCommand !== undefined) {
93
+ return config.buildCommand || null;
94
+ }
95
+ // 2. 显式 framework → 映射推导
96
+ if (config.framework) {
97
+ return exports.FRAMEWORK_BUILD_COMMANDS[config.framework] || null;
98
+ }
99
+ // 3. package.json 自动探测(忘记配置 framework 时兜底,如 vite 项目)
100
+ const detected = detectFramework(root, readPkgFile);
101
+ if (detected) {
102
+ return exports.FRAMEWORK_BUILD_COMMANDS[detected] || null;
103
+ }
104
+ return null;
105
+ }
@@ -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
+ }