@geek-fun/serverlessinsight 0.8.4 → 0.8.6
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/.serverlessinsight/state-cdn-flow-app-cdn-flow-service.json.backup +1 -2
- package/.serverlessinsight/state-iam-test-app-iam-test-service.json.backup +2 -3
- package/.serverlessinsight/state-insight-poc-deploy-app-insight-poc-deploy.json.backup +5 -169
- package/.serverlessinsight/state-insight-poc-destroy-app-insight-poc-destroy.json.backup +1 -2
- package/.serverlessinsight/state-insight-volc-app-insight-volc.json.backup +3 -64
- package/CHANGELOG.md +55 -0
- package/README.md +1 -13
- package/README.zh-CN.md +146 -286
- package/dist/package.json +24 -24
- package/dist/src/commands/deploy.js +4 -6
- package/dist/src/common/aliyunClient/fc3Operations.js +7 -0
- package/dist/src/common/aliyunClient/slsOperations.js +1 -1
- package/dist/src/common/index.js +2 -0
- package/dist/src/common/nameBuilder.js +80 -0
- package/dist/src/common/providerNames.js +54 -0
- package/dist/src/common/runtimeMapper.js +25 -4
- package/dist/src/common/stateBackend/remoteStateBackend.js +1 -3
- package/dist/src/common/stateBackend/saasStateBackend.js +26 -5
- package/dist/src/common/stateManager.js +8 -4
- package/dist/src/lang/en.js +6 -0
- package/dist/src/lang/zh-CN.js +6 -0
- package/dist/src/parser/index.js +2 -1
- package/dist/src/stack/aliyunStack/apigwTypes.js +14 -20
- package/dist/src/stack/volcengineStack/apigwTypes.js +1 -7
- package/dist/src/validator/bucketSchema.js +3 -5
- package/dist/src/validator/eventSchema.js +7 -4
- package/dist/src/validator/functionSchema.js +3 -2
- package/dist/src/validator/iacSchema.js +11 -4
- package/dist/src/validator/rootSchema.js +27 -0
- package/dist/src/validator/semanticValidation.js +122 -0
- package/dist/src/validator/tableschema.js +2 -0
- package/dist/src/validator/templateRefSchema.js +23 -3
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +24 -24
- package/samples/aliyun-poc-fc-gpu.yml +2 -2
- package/samples/aliyun-poc-table.yml +1 -1
- package/samples/volcengine-poc-advanced.yml +4 -8
- package/samples/volcengine-poc-api.yml +1 -1
- package/samples/volcengine-poc-function.yml +1 -1
- package/samples/volcengine-poc-vpc.yml +3 -7
package/dist/src/common/index.js
CHANGED
|
@@ -36,3 +36,5 @@ __exportStar(require("./planFormatter"), exports);
|
|
|
36
36
|
__exportStar(require("./credentialStore"), exports);
|
|
37
37
|
__exportStar(require("./apiClient"), exports);
|
|
38
38
|
__exportStar(require("./triggerMapper"), exports);
|
|
39
|
+
__exportStar(require("./nameBuilder"), exports);
|
|
40
|
+
__exportStar(require("./providerNames"), exports);
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Deterministic constrained-name builder.
|
|
4
|
+
*
|
|
5
|
+
* Contract (see GitHub issue #222):
|
|
6
|
+
* - Identifiers are derived from user config and must respect a provider
|
|
7
|
+
* maximum length. Silent truncation used to discard the distinguishing
|
|
8
|
+
* discriminator (issue #221: RepeatedApiName collisions).
|
|
9
|
+
* - When the composed name fits the maximum length, it is returned verbatim
|
|
10
|
+
* (minus charset sanitisation) so existing well-fitting configurations keep
|
|
11
|
+
* their deployed names and do not churn.
|
|
12
|
+
* - When it does not fit, the human-readable prefix is truncated FIRST while
|
|
13
|
+
* the discriminator (later parts) is preserved whenever possible, and a
|
|
14
|
+
* deterministic hash of the raw parts is always appended so distinct inputs
|
|
15
|
+
* never collapse to the same name. Theoretical digest collisions within a
|
|
16
|
+
* deploy set are additionally rejected up-front by semantic validation.
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.CONSTRAINT_NAME_LIMITS = exports.buildConstrainedName = exports.stableHash = exports.DEFAULT_HASH_LENGTH = void 0;
|
|
20
|
+
const FNV_OFFSET_BASIS = 0x811c9dc5;
|
|
21
|
+
const FNV_PRIME = 0x01000193;
|
|
22
|
+
const SANITISERS = {
|
|
23
|
+
// Aliyun identifiers (CreateApi apiName: [A-Za-z0-9_], hyphens forbidden)
|
|
24
|
+
underscore: { invalidChars: /[^A-Za-z0-9_]/g, separator: '_' },
|
|
25
|
+
// Volcengine identifiers (letters/digits/hyphens, underscores folded to hyphens)
|
|
26
|
+
hyphen: { invalidChars: /[^A-Za-z0-9-]/g, separator: '-' },
|
|
27
|
+
};
|
|
28
|
+
exports.DEFAULT_HASH_LENGTH = 7;
|
|
29
|
+
const toUtf8Bytes = (input) => Array.from(Buffer.from(input, 'utf8'));
|
|
30
|
+
/** Deterministic 32-bit FNV-1a rendered as fixed-width base36. */
|
|
31
|
+
const stableHash = (raw, length = exports.DEFAULT_HASH_LENGTH) => toUtf8Bytes(raw)
|
|
32
|
+
.reduce((hash, byte) => ((hash ^ byte) * FNV_PRIME) >>> 0, FNV_OFFSET_BASIS)
|
|
33
|
+
.toString(36)
|
|
34
|
+
.padStart(length, '0')
|
|
35
|
+
.slice(0, length);
|
|
36
|
+
exports.stableHash = stableHash;
|
|
37
|
+
const sanitizePart = (part, mode) => part.replace(SANITISERS[mode].invalidChars, SANITISERS[mode].separator);
|
|
38
|
+
/**
|
|
39
|
+
* Build a provider-constrained identifier from ordered user-derived segments,
|
|
40
|
+
* joined by the charset separator. Over-long compositions truncate the leading
|
|
41
|
+
* (human-readable) segments first and append a hash of the raw segments so
|
|
42
|
+
* distinct inputs never collapse into one name.
|
|
43
|
+
*/
|
|
44
|
+
const buildConstrainedName = ({ parts, maxLength, charset, }) => {
|
|
45
|
+
const { separator } = SANITISERS[charset];
|
|
46
|
+
const joinSegments = (segments) => segments
|
|
47
|
+
.map((part) => sanitizePart(part, charset))
|
|
48
|
+
.filter((part) => part.length > 0)
|
|
49
|
+
.join(separator);
|
|
50
|
+
const readable = joinSegments(parts);
|
|
51
|
+
if (readable.length <= maxLength) {
|
|
52
|
+
return readable;
|
|
53
|
+
}
|
|
54
|
+
const hashLength = Math.max(1, Math.min(exports.DEFAULT_HASH_LENGTH, maxLength - 1));
|
|
55
|
+
// Hash over the RAW segments so inputs sanitising identically stay distinct.
|
|
56
|
+
const hash = (0, exports.stableHash)(parts.join('\u0000'), hashLength);
|
|
57
|
+
const clampPrefix = (cap) => {
|
|
58
|
+
const prefix = joinSegments(parts.slice(0, -1)).slice(0, Math.max(cap, 0));
|
|
59
|
+
return prefix.replace(new RegExp(`\\${separator}+$`), '');
|
|
60
|
+
};
|
|
61
|
+
const separatorAllowance = separator.length * 2;
|
|
62
|
+
const discriminatorRoom = maxLength - hashLength - separatorAllowance;
|
|
63
|
+
const discriminatorSanitized = sanitizePart(parts[parts.length - 1], charset);
|
|
64
|
+
if (parts.length > 1 && discriminatorSanitized.length <= discriminatorRoom) {
|
|
65
|
+
const headSegments = [
|
|
66
|
+
clampPrefix(discriminatorRoom - discriminatorSanitized.length),
|
|
67
|
+
discriminatorSanitized,
|
|
68
|
+
].filter((segment) => segment.length > 0);
|
|
69
|
+
return `${headSegments.join(separator)}${separator}${hash}`;
|
|
70
|
+
}
|
|
71
|
+
const headOnly = clampPrefix(maxLength - hashLength - separator.length);
|
|
72
|
+
return [headOnly, hash].filter((segment) => segment.length > 0).join(separator);
|
|
73
|
+
};
|
|
74
|
+
exports.buildConstrainedName = buildConstrainedName;
|
|
75
|
+
/** Per-provider maximum lengths for names generated through this module. */
|
|
76
|
+
exports.CONSTRAINT_NAME_LIMITS = {
|
|
77
|
+
ALIYUN_CREATE_API_NAME: 50,
|
|
78
|
+
ALIYUN_API_GROUP_NAME: 50,
|
|
79
|
+
VOLCENGINE_ROUTE_NAME: 63,
|
|
80
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildVolcengineRouteName = exports.buildAliyunApigwApiName = exports.generateApiKey = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Leaf module for generated provider resource names.
|
|
6
|
+
*
|
|
7
|
+
* Lives in src/common (not in the stack modules) so that both the deployment
|
|
8
|
+
* stacks and the pre-deploy semantic validator share ONE source of truth for
|
|
9
|
+
* generated names without introducing import cycles. See issue #222.
|
|
10
|
+
*/
|
|
11
|
+
const nameBuilder_1 = require("./nameBuilder");
|
|
12
|
+
/**
|
|
13
|
+
* Generate a unique API key from an HTTP method and path.
|
|
14
|
+
* Uses URL encoding to preserve path structure and avoid collisions.
|
|
15
|
+
*/
|
|
16
|
+
const generateApiKey = (method, path) => {
|
|
17
|
+
// Replace slashes with double underscores to preserve path structure
|
|
18
|
+
// Replace other non-alphanumeric chars with single underscore
|
|
19
|
+
const sanitizedPath = path
|
|
20
|
+
.replace(/\//g, '__')
|
|
21
|
+
.replace(/[^a-zA-Z0-9_]/g, '_')
|
|
22
|
+
.replace(/^__/, '') // Remove leading double underscore
|
|
23
|
+
.replace(/__$/, ''); // Remove trailing double underscore
|
|
24
|
+
return `${method}_${sanitizedPath}`;
|
|
25
|
+
};
|
|
26
|
+
exports.generateApiKey = generateApiKey;
|
|
27
|
+
/**
|
|
28
|
+
* Aliyun API Gateway apiName. Aliyun CreateApi requires 4-50 chars of
|
|
29
|
+
* [A-Za-z0-9_] — no hyphens.
|
|
30
|
+
*
|
|
31
|
+
* Resolves issue #221: long event names no longer truncate the trailing
|
|
32
|
+
* method/path discriminator out of existence.
|
|
33
|
+
*/
|
|
34
|
+
const buildAliyunApigwApiName = (eventName, stage, apiKey) => (0, nameBuilder_1.buildConstrainedName)({
|
|
35
|
+
parts: [eventName, stage, 'agw_api', apiKey],
|
|
36
|
+
maxLength: nameBuilder_1.CONSTRAINT_NAME_LIMITS.ALIYUN_CREATE_API_NAME,
|
|
37
|
+
charset: 'underscore',
|
|
38
|
+
});
|
|
39
|
+
exports.buildAliyunApigwApiName = buildAliyunApigwApiName;
|
|
40
|
+
/**
|
|
41
|
+
* Volcengine API Gateway route name (max 63 chars, letters/digits/hyphens).
|
|
42
|
+
*/
|
|
43
|
+
const buildVolcengineRouteName = (eventName, method, path) => {
|
|
44
|
+
const sanitizedPath = path
|
|
45
|
+
.replace(/\//g, '_')
|
|
46
|
+
.replace(/[^a-zA-Z0-9_]/g, '_')
|
|
47
|
+
.replace(/^_+|_+$/g, '');
|
|
48
|
+
return (0, nameBuilder_1.buildConstrainedName)({
|
|
49
|
+
parts: [eventName, `${method}_${sanitizedPath}`],
|
|
50
|
+
maxLength: nameBuilder_1.CONSTRAINT_NAME_LIMITS.VOLCENGINE_ROUTE_NAME,
|
|
51
|
+
charset: 'hyphen',
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
exports.buildVolcengineRouteName = buildVolcengineRouteName;
|
|
@@ -42,26 +42,32 @@ const runtimeMappings = {
|
|
|
42
42
|
[StandardRuntime.NODEJS20]: {
|
|
43
43
|
[providerEnum_1.ProviderEnum.ALIYUN]: 'nodejs20',
|
|
44
44
|
[providerEnum_1.ProviderEnum.AWS]: 'nodejs20.x',
|
|
45
|
+
[providerEnum_1.ProviderEnum.HUAWEI]: 'nodejs20.15',
|
|
45
46
|
},
|
|
46
47
|
[StandardRuntime.NODEJS18]: {
|
|
47
48
|
[providerEnum_1.ProviderEnum.ALIYUN]: 'nodejs18',
|
|
48
49
|
[providerEnum_1.ProviderEnum.TENCENT]: 'Nodejs18.15',
|
|
50
|
+
[providerEnum_1.ProviderEnum.HUAWEI]: 'nodejs18.15',
|
|
49
51
|
},
|
|
50
52
|
[StandardRuntime.NODEJS16]: {
|
|
51
53
|
[providerEnum_1.ProviderEnum.ALIYUN]: 'nodejs16',
|
|
52
54
|
[providerEnum_1.ProviderEnum.TENCENT]: 'Nodejs16.13',
|
|
55
|
+
[providerEnum_1.ProviderEnum.HUAWEI]: 'nodejs16.17',
|
|
53
56
|
},
|
|
54
57
|
[StandardRuntime.NODEJS14]: {
|
|
55
58
|
[providerEnum_1.ProviderEnum.ALIYUN]: 'nodejs14',
|
|
56
59
|
[providerEnum_1.ProviderEnum.TENCENT]: 'Nodejs14.18',
|
|
60
|
+
[providerEnum_1.ProviderEnum.HUAWEI]: 'nodejs14.18',
|
|
57
61
|
},
|
|
58
62
|
[StandardRuntime.NODEJS12]: {
|
|
59
63
|
[providerEnum_1.ProviderEnum.ALIYUN]: 'nodejs12',
|
|
60
64
|
[providerEnum_1.ProviderEnum.TENCENT]: 'Nodejs12.16',
|
|
65
|
+
[providerEnum_1.ProviderEnum.HUAWEI]: 'nodejs12.13',
|
|
61
66
|
},
|
|
62
67
|
[StandardRuntime.NODEJS10]: {
|
|
63
68
|
[providerEnum_1.ProviderEnum.ALIYUN]: 'nodejs10',
|
|
64
69
|
[providerEnum_1.ProviderEnum.TENCENT]: 'Nodejs10.15',
|
|
70
|
+
[providerEnum_1.ProviderEnum.HUAWEI]: 'nodejs10.16',
|
|
65
71
|
},
|
|
66
72
|
[StandardRuntime.PYTHON3_14]: {
|
|
67
73
|
[providerEnum_1.ProviderEnum.AWS]: 'python3.14',
|
|
@@ -72,6 +78,7 @@ const runtimeMappings = {
|
|
|
72
78
|
[StandardRuntime.PYTHON3_12]: {
|
|
73
79
|
[providerEnum_1.ProviderEnum.ALIYUN]: 'python3.12',
|
|
74
80
|
[providerEnum_1.ProviderEnum.AWS]: 'python3.12',
|
|
81
|
+
[providerEnum_1.ProviderEnum.HUAWEI]: 'python3.12',
|
|
75
82
|
},
|
|
76
83
|
[StandardRuntime.PYTHON3_11]: {
|
|
77
84
|
[providerEnum_1.ProviderEnum.AWS]: 'python3.11',
|
|
@@ -80,10 +87,12 @@ const runtimeMappings = {
|
|
|
80
87
|
[providerEnum_1.ProviderEnum.ALIYUN]: 'python3.10',
|
|
81
88
|
[providerEnum_1.ProviderEnum.TENCENT]: 'Python3.10',
|
|
82
89
|
[providerEnum_1.ProviderEnum.AWS]: 'python3.10',
|
|
90
|
+
[providerEnum_1.ProviderEnum.HUAWEI]: 'python3.10',
|
|
83
91
|
},
|
|
84
92
|
[StandardRuntime.PYTHON3_9]: {
|
|
85
93
|
[providerEnum_1.ProviderEnum.ALIYUN]: 'python3.9',
|
|
86
94
|
[providerEnum_1.ProviderEnum.TENCENT]: 'Python3.9',
|
|
95
|
+
[providerEnum_1.ProviderEnum.HUAWEI]: 'python3.9',
|
|
87
96
|
},
|
|
88
97
|
[StandardRuntime.PYTHON3_7]: {
|
|
89
98
|
[providerEnum_1.ProviderEnum.TENCENT]: 'Python3.7',
|
|
@@ -91,24 +100,30 @@ const runtimeMappings = {
|
|
|
91
100
|
[StandardRuntime.PYTHON3_6]: {
|
|
92
101
|
[providerEnum_1.ProviderEnum.ALIYUN]: 'python3.6',
|
|
93
102
|
[providerEnum_1.ProviderEnum.TENCENT]: 'Python3.6',
|
|
103
|
+
[providerEnum_1.ProviderEnum.HUAWEI]: 'python3.6',
|
|
94
104
|
},
|
|
95
105
|
[StandardRuntime.JAVA25]: {
|
|
96
106
|
[providerEnum_1.ProviderEnum.AWS]: 'java25',
|
|
97
107
|
},
|
|
98
108
|
[StandardRuntime.JAVA21]: {
|
|
99
109
|
[providerEnum_1.ProviderEnum.AWS]: 'java21',
|
|
110
|
+
// Huawei java21 is regional (ME-Riyadh, TR-Istanbul) per FunctionGraph docs.
|
|
111
|
+
[providerEnum_1.ProviderEnum.HUAWEI]: 'java21',
|
|
100
112
|
},
|
|
101
113
|
[StandardRuntime.JAVA17]: {
|
|
102
114
|
[providerEnum_1.ProviderEnum.AWS]: 'java17',
|
|
115
|
+
[providerEnum_1.ProviderEnum.HUAWEI]: 'java17',
|
|
103
116
|
},
|
|
104
117
|
[StandardRuntime.JAVA11]: {
|
|
105
118
|
[providerEnum_1.ProviderEnum.ALIYUN]: 'java11',
|
|
106
119
|
[providerEnum_1.ProviderEnum.AWS]: 'java11',
|
|
120
|
+
[providerEnum_1.ProviderEnum.HUAWEI]: 'java11',
|
|
107
121
|
},
|
|
108
122
|
[StandardRuntime.JAVA8]: {
|
|
109
123
|
[providerEnum_1.ProviderEnum.ALIYUN]: 'java8',
|
|
110
124
|
[providerEnum_1.ProviderEnum.TENCENT]: 'Java8',
|
|
111
125
|
[providerEnum_1.ProviderEnum.AWS]: 'java8.al2',
|
|
126
|
+
[providerEnum_1.ProviderEnum.HUAWEI]: 'java8',
|
|
112
127
|
},
|
|
113
128
|
[StandardRuntime.PHP8_0]: {
|
|
114
129
|
[providerEnum_1.ProviderEnum.TENCENT]: 'Php8.0',
|
|
@@ -126,9 +141,11 @@ const runtimeMappings = {
|
|
|
126
141
|
[StandardRuntime.GO1]: {
|
|
127
142
|
[providerEnum_1.ProviderEnum.ALIYUN]: 'go 1.x',
|
|
128
143
|
[providerEnum_1.ProviderEnum.TENCENT]: 'Go1',
|
|
144
|
+
[providerEnum_1.ProviderEnum.HUAWEI]: 'go1.x',
|
|
129
145
|
},
|
|
130
146
|
[StandardRuntime.DOTNET_CORE3_1]: {
|
|
131
147
|
[providerEnum_1.ProviderEnum.ALIYUN]: '.NET Core 3.1',
|
|
148
|
+
[providerEnum_1.ProviderEnum.HUAWEI]: 'dotnetcore3.1',
|
|
132
149
|
},
|
|
133
150
|
};
|
|
134
151
|
const mapRuntime = (standardRuntime, provider) => {
|
|
@@ -144,9 +161,12 @@ const mapRuntime = (standardRuntime, provider) => {
|
|
|
144
161
|
return providerRuntime;
|
|
145
162
|
};
|
|
146
163
|
exports.mapRuntime = mapRuntime;
|
|
147
|
-
// Valid veFaaS runtimes per the official CreateFunction API reference
|
|
148
|
-
//
|
|
149
|
-
//
|
|
164
|
+
// Valid veFaaS runtimes per the official CreateFunction API reference, adjusted
|
|
165
|
+
// for product notices: python3.8/v1 retired (volcengine notice 2121844) and the
|
|
166
|
+
// native-family ids added from Volcengine-maintained tooling (mcp-server / veadk).
|
|
167
|
+
// Verified 2026-08: golang/v1, native/v1, nativejava8/v1, node14/v1, node20/v1,
|
|
168
|
+
// nodeprime14/v1, python3.12/v1, python3.9/v1, native-python3.12/v1,
|
|
169
|
+
// native-node20/v1
|
|
150
170
|
const VOLCENGINE_NATIVE_RUNTIMES = [
|
|
151
171
|
'golang/v1',
|
|
152
172
|
'native/v1',
|
|
@@ -155,8 +175,9 @@ const VOLCENGINE_NATIVE_RUNTIMES = [
|
|
|
155
175
|
'node20/v1',
|
|
156
176
|
'nodeprime14/v1',
|
|
157
177
|
'python3.12/v1',
|
|
158
|
-
'python3.8/v1',
|
|
159
178
|
'python3.9/v1',
|
|
179
|
+
'native-python3.12/v1',
|
|
180
|
+
'native-node20/v1',
|
|
160
181
|
];
|
|
161
182
|
const isRuntimeSupported = (runtime, provider) => {
|
|
162
183
|
if (provider === providerEnum_1.ProviderEnum.VOLCENGINE) {
|
|
@@ -84,12 +84,11 @@ const createRemoteStateBackend = (adapter, config) => {
|
|
|
84
84
|
app,
|
|
85
85
|
service,
|
|
86
86
|
stages: {},
|
|
87
|
-
resources: {},
|
|
88
87
|
};
|
|
89
88
|
try {
|
|
90
89
|
const raw = await adapter.read(config.key);
|
|
91
90
|
if (raw)
|
|
92
|
-
existing = raw;
|
|
91
|
+
existing = (0, stateManager_1.toPersistedState)(raw);
|
|
93
92
|
}
|
|
94
93
|
catch {
|
|
95
94
|
// noop
|
|
@@ -107,7 +106,6 @@ const createRemoteStateBackend = (adapter, config) => {
|
|
|
107
106
|
shared: state.stages?.[stage]?.shared ?? existing.stages?.[stage]?.shared ?? {},
|
|
108
107
|
},
|
|
109
108
|
},
|
|
110
|
-
resources: state.resources,
|
|
111
109
|
};
|
|
112
110
|
await adapter.write(config.key, stateToSave);
|
|
113
111
|
},
|
|
@@ -98,9 +98,19 @@ const createSaasStateBackend = (context) => {
|
|
|
98
98
|
await ensureProvisioned(provider, stage);
|
|
99
99
|
try {
|
|
100
100
|
const state = await client.get(`/api/v1/apps/${resolvedAppId}/services/${resolvedServiceId}/state/current?stage=${encodeURIComponent(stage)}`);
|
|
101
|
+
const migrated = (0, stateManager_1.migrateState)(state.stateJson);
|
|
102
|
+
// Legacy Console states hold fresh resources only in the top-level
|
|
103
|
+
// field (pre-stage-syncing saves) — prefer the stage store, fall back.
|
|
104
|
+
const stageResources = migrated.stages?.[stage]?.resources;
|
|
105
|
+
const resources = stageResources && Object.keys(stageResources).length > 0
|
|
106
|
+
? stageResources
|
|
107
|
+
: migrated.resources && Object.keys(migrated.resources).length > 0
|
|
108
|
+
? migrated.resources
|
|
109
|
+
: {};
|
|
101
110
|
// Attach console metadata so subsequent deploys have the UUIDs
|
|
102
111
|
return {
|
|
103
|
-
...
|
|
112
|
+
...migrated,
|
|
113
|
+
resources,
|
|
104
114
|
orgId,
|
|
105
115
|
appId: resolvedAppId,
|
|
106
116
|
serviceId: resolvedServiceId,
|
|
@@ -119,15 +129,26 @@ const createSaasStateBackend = (context) => {
|
|
|
119
129
|
saveState: async (state, app, service, stage) => {
|
|
120
130
|
// If not provisioned yet, use the state's provider for provisioning
|
|
121
131
|
await ensureProvisioned(state.provider, stage);
|
|
122
|
-
//
|
|
123
|
-
//
|
|
132
|
+
// Sync the runtime projection into the stage store before stripping, so
|
|
133
|
+
// stages[stage].resources carries the fresh working set (mirrors the fs
|
|
134
|
+
// and remote backends' save contract)
|
|
135
|
+
const stateJson = (0, stateManager_1.toPersistedState)({
|
|
136
|
+
...state,
|
|
137
|
+
stages: {
|
|
138
|
+
...state.stages,
|
|
139
|
+
[stage]: {
|
|
140
|
+
...state.stages?.[stage],
|
|
141
|
+
resources: state.resources,
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
});
|
|
124
145
|
const body = {
|
|
125
146
|
appName: app,
|
|
126
147
|
serviceName: service,
|
|
127
148
|
provider: state.provider,
|
|
128
149
|
stage,
|
|
129
|
-
stateJson
|
|
130
|
-
contentHash: node_crypto_1.default.createHash('sha256').update(JSON.stringify(
|
|
150
|
+
stateJson,
|
|
151
|
+
contentHash: node_crypto_1.default.createHash('sha256').update(JSON.stringify(stateJson)).digest('hex'),
|
|
131
152
|
resourceCount: Object.keys(state.resources).length,
|
|
132
153
|
};
|
|
133
154
|
await client.post(`/api/v1/apps/${resolvedAppId}/services/${resolvedServiceId}/state/sync`, body);
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getRoleArnFromState = exports.removeSharedResource = exports.setSharedResource = exports.getSharedResource = exports.getAllSharedResources = exports.getAllResources = exports.removeResource = exports.setResource = exports.getResource = exports.saveStateWithLock = exports.saveState = exports.loadState = exports.migrateState = exports.clearStateMigrations = exports.registerStateMigration = exports.ensureStateDir = exports.getStatePath = void 0;
|
|
6
|
+
exports.getRoleArnFromState = exports.removeSharedResource = exports.setSharedResource = exports.getSharedResource = exports.getAllSharedResources = exports.getAllResources = exports.removeResource = exports.setResource = exports.getResource = exports.saveStateWithLock = exports.saveState = exports.loadState = exports.toPersistedState = exports.migrateState = exports.clearStateMigrations = exports.registerStateMigration = exports.ensureStateDir = exports.getStatePath = void 0;
|
|
7
7
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
8
|
const node_path_1 = __importDefault(require("node:path"));
|
|
9
9
|
const node_crypto_1 = __importDefault(require("node:crypto"));
|
|
@@ -90,6 +90,12 @@ const migrateState = (raw) => {
|
|
|
90
90
|
return migrated;
|
|
91
91
|
};
|
|
92
92
|
exports.migrateState = migrateState;
|
|
93
|
+
/** Strip the runtime-only `resources` projection — `stages` is the authoritative store (issue #225). */
|
|
94
|
+
const toPersistedState = (state) => {
|
|
95
|
+
const { resources: _projection, ...persisted } = state;
|
|
96
|
+
return persisted;
|
|
97
|
+
};
|
|
98
|
+
exports.toPersistedState = toPersistedState;
|
|
93
99
|
/**
|
|
94
100
|
* Load state file, scoped to the given stage.
|
|
95
101
|
* The returned StateFile has `resources` populated from `stages[stage].resources`.
|
|
@@ -150,12 +156,11 @@ const saveState = (state, app, service, stage, baseDir = process.cwd()) => {
|
|
|
150
156
|
app,
|
|
151
157
|
service,
|
|
152
158
|
stages: {},
|
|
153
|
-
resources: {},
|
|
154
159
|
};
|
|
155
160
|
try {
|
|
156
161
|
if (node_fs_1.default.existsSync(statePath)) {
|
|
157
162
|
const content = node_fs_1.default.readFileSync(statePath, 'utf-8');
|
|
158
|
-
existing = JSON.parse(content);
|
|
163
|
+
existing = (0, exports.toPersistedState)(JSON.parse(content));
|
|
159
164
|
}
|
|
160
165
|
}
|
|
161
166
|
catch {
|
|
@@ -177,7 +182,6 @@ const saveState = (state, app, service, stage, baseDir = process.cwd()) => {
|
|
|
177
182
|
shared: state.stages?.[stage]?.shared ?? existing.stages?.[stage]?.shared ?? {},
|
|
178
183
|
},
|
|
179
184
|
},
|
|
180
|
-
resources: state.resources,
|
|
181
185
|
};
|
|
182
186
|
// Atomic write: back up the previous state, then write tmp + fsync + rename
|
|
183
187
|
try {
|
package/dist/src/lang/en.js
CHANGED
|
@@ -407,6 +407,12 @@ exports.en = {
|
|
|
407
407
|
CANNOT_RESOLVE_FUNCTION_REF: 'Cannot resolve function reference {{backendRef}}: IAC not available in context',
|
|
408
408
|
FUNCTION_REF_NOT_RESOLVED: 'Function reference {{backendRef}} could not be resolved from IAC',
|
|
409
409
|
RESOLVED_FUNCTION_REF: 'Resolved function reference {{backendRef}} to function name: {{functionName}}',
|
|
410
|
+
// Pre-deploy semantic validation (issue #222)
|
|
411
|
+
PARSE_BACKEND_BUCKET_STORE_FIELDS_REQUIRED: 'Backend type BUCKET_STORE requires both "bucket" and "key" fields',
|
|
412
|
+
SEMANTIC_DUPLICATE_TRIGGER: 'Duplicate trigger in event "{{eventKey}}": {{method}} {{path}} is defined more than once',
|
|
413
|
+
SEMANTIC_DUPLICATE_GENERATED_API_NAME: 'Generated API Gateway apiName "{{apiName}}" collides between "{{firstPath}}" and "{{secondPath}}" in this deployment; shorten the event name or differentiate trigger method/path',
|
|
414
|
+
SEMANTIC_DUPLICATE_ROUTE_NAME: 'Generated API Gateway route name "{{routeName}}" collides between "{{firstPath}}" and "{{secondPath}}" in this deployment; shorten the event name or differentiate trigger method/path',
|
|
415
|
+
SEMANTIC_UNRESOLVED_FUNCTION_BACKEND: 'Trigger backend "{{reference}}" in event "{{eventKey}}" does not match any function definition in the configuration',
|
|
410
416
|
// Show command messages
|
|
411
417
|
LOADING_STATE_FOR: 'Loading state for app: {{app}}, service: {{service}}, stage: {{stage}}...',
|
|
412
418
|
NO_RESOURCES_FOUND: 'No resources found in state.',
|
package/dist/src/lang/zh-CN.js
CHANGED
|
@@ -404,6 +404,12 @@ exports.zhCN = {
|
|
|
404
404
|
CANNOT_RESOLVE_FUNCTION_REF: '无法解析函数引用 {{backendRef}}: 上下文中无 IAC',
|
|
405
405
|
FUNCTION_REF_NOT_RESOLVED: '无法从 IAC 解析函数引用 {{backendRef}}',
|
|
406
406
|
RESOLVED_FUNCTION_REF: '已将函数引用 {{backendRef}} 解析为函数名: {{functionName}}',
|
|
407
|
+
// Pre-deploy semantic validation (issue #222)
|
|
408
|
+
PARSE_BACKEND_BUCKET_STORE_FIELDS_REQUIRED: '后端类型 BUCKET_STORE 需要同时提供 "bucket" 和 "key" 字段',
|
|
409
|
+
SEMANTIC_DUPLICATE_TRIGGER: '事件 "{{eventKey}}" 中存在重复触发器: {{method}} {{path}} 定义了不止一次',
|
|
410
|
+
SEMANTIC_DUPLICATE_GENERATED_API_NAME: '生成的 API Gateway apiName "{{apiName}}" 在 "{{firstPath}}" 与 "{{secondPath}}" 之间发生冲突;请缩短事件名称或区分触发器的 method/path',
|
|
411
|
+
SEMANTIC_DUPLICATE_ROUTE_NAME: '生成的 API Gateway route name "{{routeName}}" 在 "{{firstPath}}" 与 "{{secondPath}}" 之间发生冲突;请缩短事件名称或区分触发器的 method/path',
|
|
412
|
+
SEMANTIC_UNRESOLVED_FUNCTION_BACKEND: '事件 "{{eventKey}}" 的触发器后端 "{{reference}}" 未匹配到配置中的任何函数定义',
|
|
407
413
|
// Show command messages
|
|
408
414
|
LOADING_STATE_FOR: '正在加载应用 {{app}}、服务 {{service}}、阶段 {{stage}} 的状态...',
|
|
409
415
|
NO_RESOURCES_FOUND: '状态中未找到资源。',
|
package/dist/src/parser/index.js
CHANGED
|
@@ -12,6 +12,7 @@ const validator_1 = require("../validator");
|
|
|
12
12
|
const bucketParser_1 = require("./bucketParser");
|
|
13
13
|
const tableParser_1 = require("./tableParser");
|
|
14
14
|
const common_1 = require("../common");
|
|
15
|
+
const lang_1 = require("../lang");
|
|
15
16
|
const validateExistence = (path) => {
|
|
16
17
|
if (!(0, node_fs_1.existsSync)(path)) {
|
|
17
18
|
throw new Error(`File does not exist at path: ${path}`);
|
|
@@ -26,7 +27,7 @@ const parseBackend = (raw) => {
|
|
|
26
27
|
const type = stateManager.type?.toUpperCase();
|
|
27
28
|
if (type === types_1.StateBackendType.BUCKET_STORE) {
|
|
28
29
|
if (!stateManager.bucket || !stateManager.key) {
|
|
29
|
-
throw new Error('
|
|
30
|
+
throw new Error(lang_1.lang.__('PARSE_BACKEND_BUCKET_STORE_FIELDS_REQUIRED'));
|
|
30
31
|
}
|
|
31
32
|
return {
|
|
32
33
|
type: types_1.StateBackendType.BUCKET_STORE,
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.extractEventDomainDefinition = exports.buildEventLogSnapshot = exports.inferProtocolConfig = exports.extractApigwDeploymentDefinition = exports.extractApigwApiDefinition = exports.extractApigwGroupDefinition = exports.triggerToApigwApiConfig = exports.generateApiKey = exports.
|
|
3
|
+
exports.extractEventDomainDefinition = exports.buildEventLogSnapshot = exports.inferProtocolConfig = exports.extractApigwDeploymentDefinition = exports.extractApigwApiDefinition = exports.extractApigwGroupDefinition = exports.triggerToApigwApiConfig = exports.eventToApigwGroupConfig = exports.generateApiKey = exports.buildAliyunApigwApiName = void 0;
|
|
4
4
|
const common_1 = require("../../common");
|
|
5
5
|
const lang_1 = require("../../lang");
|
|
6
6
|
const ownershipTag_1 = require("../ownershipTag");
|
|
7
|
+
var common_2 = require("../../common");
|
|
8
|
+
Object.defineProperty(exports, "buildAliyunApigwApiName", { enumerable: true, get: function () { return common_2.buildAliyunApigwApiName; } });
|
|
9
|
+
Object.defineProperty(exports, "generateApiKey", { enumerable: true, get: function () { return common_2.generateApiKey; } });
|
|
7
10
|
/**
|
|
8
11
|
* Convert EventDomain to API Gateway group config
|
|
9
12
|
*
|
|
@@ -14,7 +17,14 @@ const ownershipTag_1 = require("../ownershipTag");
|
|
|
14
17
|
*/
|
|
15
18
|
const eventToApigwGroupConfig = (event, serviceName, stage, context, logicalId) => {
|
|
16
19
|
const groupConfig = {
|
|
17
|
-
|
|
20
|
+
// Per-event group: each API_GATEWAY event owns its group so the
|
|
21
|
+
// single-owner adoption tag stays exact. 4-50 chars per Aliyun
|
|
22
|
+
// ALIYUN::ApiGateway::Group docs; charset proven in this repo (hyphens).
|
|
23
|
+
groupName: (0, common_1.buildConstrainedName)({
|
|
24
|
+
parts: [serviceName, stage, event.key ?? '', 'agw_group'],
|
|
25
|
+
maxLength: common_1.CONSTRAINT_NAME_LIMITS.ALIYUN_API_GROUP_NAME,
|
|
26
|
+
charset: 'hyphen',
|
|
27
|
+
}),
|
|
18
28
|
description: `API Gateway group for ${serviceName}`,
|
|
19
29
|
};
|
|
20
30
|
if (context && logicalId) {
|
|
@@ -25,21 +35,6 @@ const eventToApigwGroupConfig = (event, serviceName, stage, context, logicalId)
|
|
|
25
35
|
return groupConfig;
|
|
26
36
|
};
|
|
27
37
|
exports.eventToApigwGroupConfig = eventToApigwGroupConfig;
|
|
28
|
-
/**
|
|
29
|
-
* Generate a unique API key from method and path
|
|
30
|
-
* Uses URL encoding to preserve path structure and avoid collisions
|
|
31
|
-
*/
|
|
32
|
-
const generateApiKey = (method, path) => {
|
|
33
|
-
// Replace slashes with double underscores to preserve path structure
|
|
34
|
-
// Replace other non-alphanumeric chars with single underscore
|
|
35
|
-
const sanitizedPath = path
|
|
36
|
-
.replace(/\//g, '__')
|
|
37
|
-
.replace(/[^a-zA-Z0-9_]/g, '_')
|
|
38
|
-
.replace(/^__/, '') // Remove leading double underscore
|
|
39
|
-
.replace(/__$/, ''); // Remove trailing double underscore
|
|
40
|
-
return `${method}_${sanitizedPath}`;
|
|
41
|
-
};
|
|
42
|
-
exports.generateApiKey = generateApiKey;
|
|
43
38
|
/**
|
|
44
39
|
* Resolves a function reference like ${functions.xxx} to the actual function name
|
|
45
40
|
*/
|
|
@@ -69,12 +64,11 @@ const triggerToApigwApiConfig = (event, trigger, groupId, serviceName, region, s
|
|
|
69
64
|
const path = trigger.path;
|
|
70
65
|
const backend = trigger.backend;
|
|
71
66
|
const resolvedFunctionName = resolveFunctionReference(backend);
|
|
72
|
-
const apiKey = (0,
|
|
67
|
+
const apiKey = (0, common_1.generateApiKey)(method, path);
|
|
73
68
|
const protocolConfig = (0, exports.inferProtocolConfig)(event.domain?.protocol);
|
|
74
69
|
return {
|
|
75
70
|
groupId,
|
|
76
|
-
|
|
77
|
-
apiName: `${event.name.replace(/-/g, '_')}_${stage}_agw_api_${apiKey}`.slice(0, 50),
|
|
71
|
+
apiName: (0, common_1.buildAliyunApigwApiName)(event.name, stage, apiKey),
|
|
78
72
|
visibility: 'PRIVATE',
|
|
79
73
|
authType: 'ANONYMOUS',
|
|
80
74
|
requestConfig: {
|
|
@@ -15,13 +15,7 @@ const buildUpstreamName = (event, backendRef, stage) => {
|
|
|
15
15
|
return `${event.name}-${stage}-upstream-${fnKey.replace(/_/g, '-')}`;
|
|
16
16
|
};
|
|
17
17
|
exports.buildUpstreamName = buildUpstreamName;
|
|
18
|
-
const buildRouteName = (event, method, path) =>
|
|
19
|
-
const sanitized = path
|
|
20
|
-
.replace(/\//g, '_')
|
|
21
|
-
.replace(/[^a-zA-Z0-9_]/g, '_')
|
|
22
|
-
.replace(/^_+|_+$/g, '');
|
|
23
|
-
return `${event.name}-${method}_${sanitized}`.replace(/_/g, '-').slice(0, 63);
|
|
24
|
-
};
|
|
18
|
+
const buildRouteName = (event, method, path) => (0, common_1.buildVolcengineRouteName)(event.name, method, path);
|
|
25
19
|
exports.buildRouteName = buildRouteName;
|
|
26
20
|
/**
|
|
27
21
|
* Resolves a function reference like ${functions.xxx} to the actual function name
|
|
@@ -27,7 +27,7 @@ const bucketDomainSchema = {
|
|
|
27
27
|
{
|
|
28
28
|
type: 'object',
|
|
29
29
|
properties: {
|
|
30
|
-
domain_name: {
|
|
30
|
+
domain_name: (0, templateRefSchema_1.resolvableConstrained)({ pattern: templateRefSchema_1.HOST_NAME_PATTERN }),
|
|
31
31
|
certificate_id: { type: 'string' },
|
|
32
32
|
certificate_body: { type: 'string' },
|
|
33
33
|
certificate_private_key: { type: 'string' },
|
|
@@ -78,7 +78,7 @@ const bucketWebsiteDomainSchema = {
|
|
|
78
78
|
{
|
|
79
79
|
type: 'object',
|
|
80
80
|
properties: {
|
|
81
|
-
domain_name: {
|
|
81
|
+
domain_name: (0, templateRefSchema_1.resolvableConstrained)({ pattern: templateRefSchema_1.HOST_NAME_PATTERN }),
|
|
82
82
|
certificate_id: { type: 'string' },
|
|
83
83
|
certificate_body: { type: 'string' },
|
|
84
84
|
certificate_private_key: { type: 'string' },
|
|
@@ -173,9 +173,7 @@ exports.bucketSchema = {
|
|
|
173
173
|
'.*': {
|
|
174
174
|
type: 'object',
|
|
175
175
|
properties: {
|
|
176
|
-
name: {
|
|
177
|
-
type: 'string',
|
|
178
|
-
},
|
|
176
|
+
name: (0, templateRefSchema_1.resolvableConstrained)({ pattern: templateRefSchema_1.BUCKET_NAME_PATTERN }),
|
|
179
177
|
storage: {
|
|
180
178
|
type: 'object',
|
|
181
179
|
properties: {
|
|
@@ -43,9 +43,12 @@ exports.eventSchema = {
|
|
|
43
43
|
triggers: {
|
|
44
44
|
type: 'array',
|
|
45
45
|
items: {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
type: 'object',
|
|
47
|
+
properties: {
|
|
48
|
+
method: (0, templateRefSchema_1.resolvableEnum)(['GET', 'POST', 'PUT', 'DELETE', 'ANY']),
|
|
49
|
+
path: (0, templateRefSchema_1.resolvableConstrained)({ pattern: '^/\\S*$' }),
|
|
50
|
+
backend: { type: 'string' },
|
|
51
|
+
},
|
|
49
52
|
required: ['method', 'path', 'backend'],
|
|
50
53
|
},
|
|
51
54
|
},
|
|
@@ -54,7 +57,7 @@ exports.eventSchema = {
|
|
|
54
57
|
additionalProperties: false,
|
|
55
58
|
required: ['domain_name'],
|
|
56
59
|
properties: {
|
|
57
|
-
domain_name: {
|
|
60
|
+
domain_name: (0, templateRefSchema_1.resolvableConstrained)({ pattern: templateRefSchema_1.HOST_NAME_PATTERN }),
|
|
58
61
|
certificate_id: { type: 'string' },
|
|
59
62
|
certificate_body: { type: 'string' },
|
|
60
63
|
certificate_private_key: { type: 'string' },
|
|
@@ -52,8 +52,9 @@ exports.functionSchema = {
|
|
|
52
52
|
'node20/v1',
|
|
53
53
|
'nodeprime14/v1',
|
|
54
54
|
'python3.12/v1',
|
|
55
|
-
'python3.8/v1',
|
|
56
55
|
'python3.9/v1',
|
|
56
|
+
'native-python3.12/v1',
|
|
57
|
+
'native-node20/v1',
|
|
57
58
|
]),
|
|
58
59
|
handler: { type: 'string' },
|
|
59
60
|
path: { type: 'string' },
|
|
@@ -179,7 +180,7 @@ exports.functionSchema = {
|
|
|
179
180
|
required: ['domain_name'],
|
|
180
181
|
additionalProperties: false,
|
|
181
182
|
properties: {
|
|
182
|
-
domain_name: {
|
|
183
|
+
domain_name: (0, templateRefSchema_1.resolvableConstrained)({ pattern: templateRefSchema_1.HOST_NAME_PATTERN }),
|
|
183
184
|
certificate_id: { type: 'string' },
|
|
184
185
|
protocol: (0, templateRefSchema_1.resolvableEnum)(['HTTP', 'HTTPS']),
|
|
185
186
|
},
|
|
@@ -13,6 +13,7 @@ const functionSchema_1 = require("./functionSchema");
|
|
|
13
13
|
const bucketSchema_1 = require("./bucketSchema");
|
|
14
14
|
const tableschema_1 = require("./tableschema");
|
|
15
15
|
const lang_1 = require("../lang");
|
|
16
|
+
const semanticValidation_1 = require("./semanticValidation");
|
|
16
17
|
class IacSchemaErrors extends Error {
|
|
17
18
|
schemaErrors;
|
|
18
19
|
constructor(errors) {
|
|
@@ -31,7 +32,7 @@ class IacSchemaErrors extends Error {
|
|
|
31
32
|
` Type: ${error.type}`,
|
|
32
33
|
` Message: ${error.message}`,
|
|
33
34
|
];
|
|
34
|
-
if (error.allowedValues) {
|
|
35
|
+
if (error.allowedValues && error.allowedValues.length > 0) {
|
|
35
36
|
parts.push(` Allowed values: ${error.allowedValues.join(', ')}`);
|
|
36
37
|
}
|
|
37
38
|
return parts.join('\n');
|
|
@@ -86,9 +87,15 @@ const validateRuntimeCompatibility = (iacJson) => {
|
|
|
86
87
|
};
|
|
87
88
|
const validateYaml = (iacJson) => {
|
|
88
89
|
const valid = validate(iacJson);
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
90
|
+
const semanticErrors = (0, semanticValidation_1.validateSemantics)(iacJson);
|
|
91
|
+
if (!valid || semanticErrors.length > 0) {
|
|
92
|
+
common_1.logger.debug(lang_1.lang.__('INVALID_YAML', {
|
|
93
|
+
errors: JSON.stringify([...(validate.errors ?? []), ...semanticErrors]),
|
|
94
|
+
}));
|
|
95
|
+
throw new IacSchemaErrors([
|
|
96
|
+
...(validate.errors ?? []),
|
|
97
|
+
...semanticErrors,
|
|
98
|
+
]);
|
|
92
99
|
}
|
|
93
100
|
validateRuntimeCompatibility(iacJson);
|
|
94
101
|
return true;
|