@geek-fun/serverlessinsight 0.9.1 → 0.9.3
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 -1
- package/.serverlessinsight/state-iam-test-app-iam-test-service.json.backup +2 -2
- package/.serverlessinsight/state-insight-poc-app-insight-poc-tencent.json.backup +4 -8
- package/.serverlessinsight/state-insight-poc-app-log-insight-poc-tencent-log.json.backup +3 -8
- package/.serverlessinsight/state-insight-poc-deploy-app-insight-poc-deploy.json.backup +4 -4
- package/.serverlessinsight/state-insight-poc-destroy-app-insight-poc-destroy.json.backup +1 -1
- package/.serverlessinsight/state-insight-poc-timer-app-insight-poc-timer.json.backup +132 -0
- package/.serverlessinsight/state-insight-volc-app-insight-volc.json.backup +2 -2
- package/.serverlessinsight/state-insight-volc-nested-app-insight-volc-nested.json.backup +3 -3
- package/.serverlessinsight/state-nested-drift-app-nested-drift-service.json.backup +20 -5
- package/.serverlessinsight/state-role-reconcile-test-app-role-reconcile-test-service.json.backup +3 -3
- package/AGENTS.md +10 -0
- package/CHANGELOG.md +51 -0
- package/README.md +103 -13
- package/README.zh-CN.md +73 -13
- package/codecov +0 -0
- package/codecov.SHA256SUM +1 -0
- package/codecov.SHA256SUM.sig +16 -0
- package/dist/package.json +1 -1
- package/dist/src/commands/index.js +92 -24
- package/dist/src/commands/local.js +16 -3
- package/dist/src/commands/plan.js +31 -4
- package/dist/src/commands/schema.js +24 -0
- package/dist/src/commands/show.js +64 -10
- package/dist/src/commands/validate.js +34 -2
- package/dist/src/common/aliyunClient/apigwOperations.js +17 -1
- package/dist/src/common/aliyunClient/fc3Operations.js +39 -2
- package/dist/src/common/aliyunClient/ossOperations.js +214 -221
- package/dist/src/common/bucketPolicy.js +63 -0
- package/dist/src/common/constants.js +7 -1
- package/dist/src/common/domainUtils.js +4 -1
- package/dist/src/common/functionDefinition.js +25 -0
- package/dist/src/common/index.js +4 -0
- package/dist/src/common/jsonOutput.js +82 -0
- package/dist/src/common/logger.js +6 -3
- package/dist/src/common/nameBuilder.js +3 -1
- package/dist/src/common/noColor.js +9 -0
- package/dist/src/common/planCapabilities.js +119 -0
- package/dist/src/common/planCompare.js +119 -66
- package/dist/src/common/planFormatter.js +34 -20
- package/dist/src/common/planRedaction.js +26 -0
- package/dist/src/common/refreshPlanner.js +66 -21
- package/dist/src/common/siCron.js +415 -0
- package/dist/src/common/stateBackend/saasStateBackend.js +5 -4
- package/dist/src/common/tencentClient/cosOperations.js +326 -322
- package/dist/src/common/tencentClient/scfOperations.js +11 -2
- package/dist/src/common/tencentClient/tdsqlcOperations.js +6 -11
- package/dist/src/common/triggerMapper.js +16 -1
- package/dist/src/common/volcengineClient/apigwOperations.js +82 -0
- package/dist/src/common/volcengineClient/iamOperations.js +27 -3
- package/dist/src/common/volcengineClient/tosOperations.js +62 -56
- package/dist/src/common/volcengineClient/vefaasOperations.js +45 -0
- package/dist/src/lang/en.js +70 -3
- package/dist/src/lang/index.js +36 -1
- package/dist/src/lang/zh-CN.js +70 -3
- package/dist/src/parser/eventParser.js +1 -0
- package/dist/src/parser/functionParser.js +48 -2
- package/dist/src/stack/aliyunStack/apigwExecutor.js +1 -1
- package/dist/src/stack/aliyunStack/apigwPlanner.js +103 -23
- package/dist/src/stack/aliyunStack/apigwResource.js +4 -3
- package/dist/src/stack/aliyunStack/apigwTypes.js +3 -7
- package/dist/src/stack/aliyunStack/deployer.js +2 -0
- package/dist/src/stack/aliyunStack/esServerlessTypes.js +8 -4
- package/dist/src/stack/aliyunStack/fc3Executor.js +7 -3
- package/dist/src/stack/aliyunStack/fc3Planner.js +148 -153
- package/dist/src/stack/aliyunStack/fc3Resource.js +206 -53
- package/dist/src/stack/aliyunStack/fc3Types.js +30 -16
- package/dist/src/stack/aliyunStack/ossPlanner.js +15 -1
- package/dist/src/stack/aliyunStack/ossResource.js +113 -102
- package/dist/src/stack/aliyunStack/ossTypes.js +20 -20
- package/dist/src/stack/localStack/aliyunFc.js +1 -6
- package/dist/src/stack/localStack/event.js +31 -71
- package/dist/src/stack/localStack/function.js +25 -77
- package/dist/src/stack/localStack/functionRunner.js +10 -2
- package/dist/src/stack/localStack/httpAdapter.js +54 -0
- package/dist/src/stack/localStack/httpError.js +5 -0
- package/dist/src/stack/localStack/index.js +8 -1
- package/dist/src/stack/localStack/legacyLambda.js +26 -0
- package/dist/src/stack/localStack/localContext.js +29 -0
- package/dist/src/stack/localStack/localRoute.js +12 -0
- package/dist/src/stack/localStack/localRuntimes.js +22 -0
- package/dist/src/stack/localStack/localServer.js +8 -3
- package/dist/src/stack/localStack/requestBody.js +24 -0
- package/dist/src/stack/localStack/requestId.js +18 -0
- package/dist/src/stack/localStack/tencent.js +147 -0
- package/dist/src/stack/localStack/timer.js +183 -0
- package/dist/src/stack/localStack/utils.js +19 -1
- package/dist/src/stack/localStack/volcengine.js +68 -0
- package/dist/src/stack/scfStack/cosPlanner.js +9 -14
- package/dist/src/stack/scfStack/cosResource.js +42 -50
- package/dist/src/stack/scfStack/cosTypes.js +19 -14
- package/dist/src/stack/scfStack/deployer.js +2 -0
- package/dist/src/stack/scfStack/scfExecutor.js +7 -3
- package/dist/src/stack/scfStack/scfHttpTrigger.js +106 -0
- package/dist/src/stack/scfStack/scfPlanner.js +114 -29
- package/dist/src/stack/scfStack/scfResource.js +329 -311
- package/dist/src/stack/scfStack/scfTypes.js +4 -3
- package/dist/src/stack/scfStack/tdsqlcPlanner.js +10 -13
- package/dist/src/stack/volcengineStack/apigwDomains.js +64 -0
- package/dist/src/stack/volcengineStack/apigwPlanner.js +71 -15
- package/dist/src/stack/volcengineStack/apigwResource.js +60 -24
- package/dist/src/stack/volcengineStack/apigwTypes.js +5 -1
- package/dist/src/stack/volcengineStack/deployer.js +6 -0
- package/dist/src/stack/volcengineStack/tosPlanner.js +8 -13
- package/dist/src/stack/volcengineStack/tosResource.js +22 -35
- package/dist/src/stack/volcengineStack/tosTypes.js +5 -8
- package/dist/src/stack/volcengineStack/vefaasPlanner.js +186 -44
- package/dist/src/stack/volcengineStack/vefaasResource.js +232 -14
- package/dist/src/stack/volcengineStack/vefaasTypes.js +6 -3
- package/dist/src/validator/functionSchema.js +25 -2
- package/dist/src/validator/iacSchema.js +2 -1
- package/dist/src/validator/index.js +4 -1
- package/dist/src/validator/rootSchema.js +49 -18
- package/dist/src/validator/schemaExport.js +60 -0
- package/dist/src/validator/semanticValidation.js +79 -0
- package/dist/src/validator/templateRefSchema.js +9 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/release-notes.md +79 -0
- package/samples/aliyun-poc-timer.yml +39 -0
- package/samples/tencent-local/index.js +13 -0
- package/samples/tencent-local/serverlessinsight.yml +23 -0
- package/samples/volcengine-local/index.js +13 -0
- package/samples/volcengine-local/serverlessinsight.yml +28 -0
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.displayPlan = exports.formatPlan = exports.formatPlanItem = exports.computeAttributeDiffs = void 0;
|
|
3
|
+
exports.displayPlan = exports.formatPlan = exports.formatPlanItem = exports.isRecreate = exports.computeAttributeDiffs = void 0;
|
|
4
|
+
const planRedaction_1 = require("./planRedaction");
|
|
4
5
|
const hashUtils_1 = require("./hashUtils");
|
|
5
6
|
const lang_1 = require("../lang");
|
|
6
7
|
const logger_1 = require("./logger");
|
|
8
|
+
const noColor_1 = require("./noColor");
|
|
7
9
|
const COLOR = {
|
|
8
10
|
RESET: '\x1b[0m',
|
|
9
11
|
GREEN: '\x1b[32m',
|
|
@@ -140,15 +142,18 @@ const computeMaxKeyWidth = (diffs, baseIndent) => diffs.reduce((maxWidth, diff)
|
|
|
140
142
|
: 0;
|
|
141
143
|
return Math.max(maxWidth, keyWidth, childWidth);
|
|
142
144
|
}, 0);
|
|
143
|
-
const formatAttributeLines = (diff, indent, config, keyWidth, revertKeys) => {
|
|
145
|
+
const formatAttributeLines = (diff, indent, config, keyWidth, revertKeys, parentPath = '', inheritedRevert = false) => {
|
|
144
146
|
const spaces = ' '.repeat(indent);
|
|
145
147
|
const alignedKey = (diff.key + ':').padEnd(keyWidth);
|
|
148
|
+
const fieldPath = parentPath ? `${parentPath}.${diff.key}` : diff.key;
|
|
149
|
+
const reverted = inheritedRevert || revertKeys?.has(fieldPath);
|
|
150
|
+
const marker = { add: '+', remove: '-', change: '~' }[diff.action];
|
|
146
151
|
// Issue #246: a field whose stored value already matched the config while
|
|
147
152
|
// the cloud diverged is annotated at the line level — the resource block
|
|
148
153
|
// stays in place, only this line explains why it appears. Only leaf lines
|
|
149
154
|
// reach suffix (parent cases early-return on children), so a revert key
|
|
150
155
|
// with nested children never carries the annotation.
|
|
151
|
-
const suffix = (line) =>
|
|
156
|
+
const suffix = (line) => reverted
|
|
152
157
|
? `${line} ${colorize(lang_1.lang.__('PLAN_REVERT_ANNOTATION'), 'CYAN', config.colorize)}`
|
|
153
158
|
: line;
|
|
154
159
|
switch (diff.action) {
|
|
@@ -156,39 +161,41 @@ const formatAttributeLines = (diff, indent, config, keyWidth, revertKeys) => {
|
|
|
156
161
|
if (diff.children && diff.children.length > 0) {
|
|
157
162
|
const childKeyWidth = computeMaxKeyWidth(diff.children, indent);
|
|
158
163
|
return [
|
|
159
|
-
colorize(`${spaces}${alignedKey}`, 'GREEN', config.colorize),
|
|
160
|
-
...diff.children.flatMap((child) => formatAttributeLines(child, indent + config.indentSize, config, childKeyWidth)),
|
|
164
|
+
colorize(`${spaces}${marker} ${alignedKey}`, 'GREEN', config.colorize),
|
|
165
|
+
...diff.children.flatMap((child) => formatAttributeLines(child, indent + config.indentSize, config, childKeyWidth, revertKeys, fieldPath, reverted)),
|
|
161
166
|
];
|
|
162
167
|
}
|
|
163
168
|
const value = diff.isComputed
|
|
164
169
|
? colorize(lang_1.lang.__('PLAN_COMPUTED_VALUE'), 'CYAN', config.colorize)
|
|
165
170
|
: formatValue(diff.after);
|
|
166
|
-
return [
|
|
171
|
+
return [
|
|
172
|
+
suffix(colorize(`${spaces}${marker} ${alignedKey} ${value}`, 'GREEN', config.colorize)),
|
|
173
|
+
];
|
|
167
174
|
}
|
|
168
175
|
case 'remove': {
|
|
169
176
|
if (diff.children && diff.children.length > 0) {
|
|
170
177
|
const childKeyWidth = computeMaxKeyWidth(diff.children, indent);
|
|
171
178
|
return [
|
|
172
|
-
colorize(`${spaces}${alignedKey}`, 'RED', config.colorize),
|
|
173
|
-
...diff.children.flatMap((child) => formatAttributeLines(child, indent + config.indentSize, config, childKeyWidth)),
|
|
179
|
+
colorize(`${spaces}${marker} ${alignedKey}`, 'RED', config.colorize),
|
|
180
|
+
...diff.children.flatMap((child) => formatAttributeLines(child, indent + config.indentSize, config, childKeyWidth, revertKeys, fieldPath, reverted)),
|
|
174
181
|
];
|
|
175
182
|
}
|
|
176
183
|
return [
|
|
177
|
-
suffix(colorize(`${spaces}${alignedKey} ${formatValue(diff.before)}`, 'RED', config.colorize)),
|
|
184
|
+
suffix(colorize(`${spaces}${marker} ${alignedKey} ${formatValue(diff.before)}`, 'RED', config.colorize)),
|
|
178
185
|
];
|
|
179
186
|
}
|
|
180
187
|
case 'change': {
|
|
181
188
|
if (diff.children && diff.children.length > 0) {
|
|
182
189
|
const childKeyWidth = computeMaxKeyWidth(diff.children, indent);
|
|
183
190
|
return [
|
|
184
|
-
colorize(`${spaces}${alignedKey}`, 'YELLOW', config.colorize),
|
|
185
|
-
...diff.children.flatMap((child) => formatAttributeLines(child, indent + config.indentSize, config, childKeyWidth)),
|
|
191
|
+
colorize(`${spaces}${marker} ${alignedKey}`, 'YELLOW', config.colorize),
|
|
192
|
+
...diff.children.flatMap((child) => formatAttributeLines(child, indent + config.indentSize, config, childKeyWidth, revertKeys, fieldPath, reverted)),
|
|
186
193
|
];
|
|
187
194
|
}
|
|
188
195
|
const beforeStr = formatValue(diff.before);
|
|
189
196
|
const afterStr = formatValue(diff.after);
|
|
190
197
|
return [
|
|
191
|
-
suffix(colorize(`${spaces}${alignedKey} ${beforeStr} -> ${afterStr}`, 'YELLOW', config.colorize)),
|
|
198
|
+
suffix(colorize(`${spaces}${marker} ${alignedKey} ${beforeStr} -> ${afterStr}`, 'YELLOW', config.colorize)),
|
|
192
199
|
];
|
|
193
200
|
}
|
|
194
201
|
}
|
|
@@ -216,14 +223,17 @@ const ACTION_COLOR = {
|
|
|
216
223
|
* add/remove blocks (issue #246 resource-paradigm invariant).
|
|
217
224
|
*/
|
|
218
225
|
const isRecreate = (item) => item.action === 'create' && !!item.changes?.before;
|
|
226
|
+
exports.isRecreate = isRecreate;
|
|
219
227
|
/* istanbul ignore next */
|
|
220
228
|
const formatPlanItem = (item, config = DEFAULT_CONFIG) => {
|
|
221
229
|
if (item.action === 'noop') {
|
|
222
230
|
// Unchanged resources are not rendered as blocks — they only surface in
|
|
223
231
|
// the plan summary count (issue #246 display spec).
|
|
224
|
-
return
|
|
232
|
+
return item.stateUpdate
|
|
233
|
+
? ` # ${lang_1.lang.__('PLAN_STATE_ONLY', { logicalId: item.logicalId })}`
|
|
234
|
+
: '';
|
|
225
235
|
}
|
|
226
|
-
const recreate = isRecreate(item);
|
|
236
|
+
const recreate = (0, exports.isRecreate)(item);
|
|
227
237
|
const descKey = recreate ? 'PLAN_WILL_RECREATE' : (ACTION_DESC[item.action] ?? 'PLAN_NO_CHANGES');
|
|
228
238
|
const headerLine = ` # ${item.logicalId} ${lang_1.lang.__(descKey)}`;
|
|
229
239
|
const symbol = recreate ? '-/+' : (ACTION_SYMBOL[item.action] ?? ' ');
|
|
@@ -244,7 +254,7 @@ const formatPlanItem = (item, config = DEFAULT_CONFIG) => {
|
|
|
244
254
|
const keyWidth = Math.max(config.keyAlignWidth, computeMaxKeyWidth(diffs, config.indentSize));
|
|
245
255
|
const revertKeys = new Set(item.revertKeys ?? []);
|
|
246
256
|
const attrLines = diffs.length > 0
|
|
247
|
-
? diffs.flatMap((diff) => formatAttributeLines(diff, config.indentSize, config, keyWidth, revertKeys))
|
|
257
|
+
? (0, planRedaction_1.redactAttributeDiffs)(diffs).flatMap((diff) => formatAttributeLines(diff, config.indentSize, config, keyWidth, revertKeys))
|
|
248
258
|
: [];
|
|
249
259
|
const hiddenLine = unchangedCount > 0
|
|
250
260
|
? [
|
|
@@ -272,13 +282,13 @@ const formatPlan = (items, config = DEFAULT_CONFIG) => {
|
|
|
272
282
|
// resources only surface in the summary count.
|
|
273
283
|
const unchangedCount = items.filter((i) => i.action === 'noop').length;
|
|
274
284
|
const itemLines = items
|
|
275
|
-
.filter((i) => i.action !== 'noop')
|
|
285
|
+
.filter((i) => i.action !== 'noop' || i.stateUpdate)
|
|
276
286
|
.flatMap((item) => {
|
|
277
287
|
const block = (0, exports.formatPlanItem)(item, config);
|
|
278
288
|
return block ? [block, ''] : [];
|
|
279
289
|
});
|
|
280
|
-
const recreateCount = items.filter(isRecreate).length;
|
|
281
|
-
const addCount = items.filter((i) => i.action === 'create' && !isRecreate(i)).length;
|
|
290
|
+
const recreateCount = items.filter(exports.isRecreate).length;
|
|
291
|
+
const addCount = items.filter((i) => i.action === 'create' && !(0, exports.isRecreate)(i)).length;
|
|
282
292
|
const modifyCount = items.filter((i) => i.action === 'update').length;
|
|
283
293
|
const removeCount = items.filter((i) => i.action === 'delete').length;
|
|
284
294
|
const header = [`${lang_1.lang.__('PLAN_HEADER')}\n`];
|
|
@@ -293,8 +303,12 @@ const formatPlan = (items, config = DEFAULT_CONFIG) => {
|
|
|
293
303
|
};
|
|
294
304
|
exports.formatPlan = formatPlan;
|
|
295
305
|
/* istanbul ignore next */
|
|
296
|
-
const displayPlan = (planResult) => {
|
|
297
|
-
const output = (0, exports.formatPlan)(planResult.items
|
|
306
|
+
const displayPlan = (planResult, config) => {
|
|
307
|
+
const output = (0, exports.formatPlan)(planResult.items, {
|
|
308
|
+
...DEFAULT_CONFIG,
|
|
309
|
+
colorize: !(0, noColor_1.isNoColorEnabled)(),
|
|
310
|
+
...config,
|
|
311
|
+
});
|
|
298
312
|
logger_1.logger.info(output);
|
|
299
313
|
};
|
|
300
314
|
exports.displayPlan = displayPlan;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.redactAttributeDiffs = void 0;
|
|
4
|
+
const lang_1 = require("../lang");
|
|
5
|
+
const SENSITIVE_FIELDS = new Set([
|
|
6
|
+
'authentication',
|
|
7
|
+
'credentials',
|
|
8
|
+
'domainCertificatePrivateKey',
|
|
9
|
+
'certificatePrivateKey',
|
|
10
|
+
]);
|
|
11
|
+
/** Comparison markers never become public credential values in human or JSON plans. */
|
|
12
|
+
const redactAttributeDiffs = (diffs) => diffs.map((diff) => {
|
|
13
|
+
if (SENSITIVE_FIELDS.has(diff.key)) {
|
|
14
|
+
const { children: _children, before, after, ...rest } = diff;
|
|
15
|
+
return {
|
|
16
|
+
...rest,
|
|
17
|
+
...(before !== undefined ? { before: lang_1.lang.__('PLAN_SENSITIVE_VALUE') } : {}),
|
|
18
|
+
...(after !== undefined ? { after: lang_1.lang.__('PLAN_SENSITIVE_VALUE') } : {}),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
...diff,
|
|
23
|
+
...(diff.children ? { children: (0, exports.redactAttributeDiffs)(diff.children) } : {}),
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
exports.redactAttributeDiffs = redactAttributeDiffs;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.planRefreshedResource = exports.decideRefreshedExistsAction = void 0;
|
|
3
|
+
exports.applyPlanStateUpdates = exports.planRefreshedResource = exports.decideRefreshedExistsAction = void 0;
|
|
4
4
|
const hashUtils_1 = require("./hashUtils");
|
|
5
|
+
const planCapabilities_1 = require("./planCapabilities");
|
|
6
|
+
const stateManager_1 = require("./stateManager");
|
|
5
7
|
const planCompare_1 = require("./planCompare");
|
|
6
8
|
const logger_1 = require("./logger");
|
|
7
9
|
const lang_1 = require("../lang");
|
|
@@ -15,18 +17,27 @@ const decideRefreshedExistsAction = async (args) => {
|
|
|
15
17
|
attributes = await args.enrichRemoteAttributes(remote, attributes);
|
|
16
18
|
}
|
|
17
19
|
const remoteDiffers = (0, planCompare_1.remoteDiffersFromDesired)(attributes, args.desiredDefinition);
|
|
18
|
-
|
|
19
|
-
return { action: 'update', drifted: true, liveAttributes: attributes };
|
|
20
|
-
}
|
|
20
|
+
const effectiveChanged = (0, planCompare_1.definitionsDiffer)((0, planCompare_1.mergeLiveBefore)(args.storedDefinition, attributes, args.desiredDefinition), args.desiredDefinition);
|
|
21
21
|
const extra = await args.extraUpdate?.();
|
|
22
|
-
if (extra?.update) {
|
|
22
|
+
if (effectiveChanged || extra?.update) {
|
|
23
|
+
const drifted = (0, planCompare_1.remoteDiffersFromDesired)(attributes, (0, planCompare_1.managedDefinition)(args.storedDefinition, args.desiredDefinition)) ||
|
|
24
|
+
(extra?.update === true && extra.drifted === true);
|
|
23
25
|
return {
|
|
24
26
|
action: 'update',
|
|
25
|
-
drifted
|
|
27
|
+
drifted,
|
|
26
28
|
liveAttributes: attributes,
|
|
27
|
-
...(extra
|
|
29
|
+
...(extra?.reasons?.length || extra?.reason
|
|
30
|
+
? {
|
|
31
|
+
driftReasons: [
|
|
32
|
+
...new Set([...(extra?.reasons ?? []), ...(extra?.reason ? [extra.reason] : [])]),
|
|
33
|
+
],
|
|
34
|
+
}
|
|
35
|
+
: {}),
|
|
28
36
|
};
|
|
29
37
|
}
|
|
38
|
+
if (args.definitionChanged && !remoteDiffers) {
|
|
39
|
+
return { action: 'state', liveAttributes: attributes };
|
|
40
|
+
}
|
|
30
41
|
return { action: 'noop' };
|
|
31
42
|
};
|
|
32
43
|
exports.decideRefreshedExistsAction = decideRefreshedExistsAction;
|
|
@@ -42,8 +53,31 @@ exports.decideRefreshedExistsAction = decideRefreshedExistsAction;
|
|
|
42
53
|
* renders a complete live→desired field diff, and `revertKeys` marks the
|
|
43
54
|
* fields whose difference is purely an out-of-config cloud edit.
|
|
44
55
|
*/
|
|
45
|
-
const
|
|
56
|
+
const withRemovedDependents = (item, removed, desired) => {
|
|
57
|
+
if (Object.keys(removed).length === 0 || item.action === 'create' || item.action === 'delete') {
|
|
58
|
+
return item;
|
|
59
|
+
}
|
|
60
|
+
const { stateUpdate: _stateUpdate, ...rest } = item;
|
|
61
|
+
return {
|
|
62
|
+
...rest,
|
|
63
|
+
action: 'update',
|
|
64
|
+
changes: {
|
|
65
|
+
before: { ...(item.changes?.before ?? {}), ...removed },
|
|
66
|
+
after: item.changes?.after ?? (0, planCompare_1.managedDefinition)(desired),
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
const planRefreshedResource = async (args) => withRemovedDependents(await planRefreshedResourceCore(args), args.currentState ? (args.removedDependents ?? {}) : {}, args.desiredDefinition);
|
|
71
|
+
exports.planRefreshedResource = planRefreshedResource;
|
|
72
|
+
const planRefreshedResourceCore = async (args) => {
|
|
46
73
|
const { logicalId, resourceType, currentState, desiredDefinition } = args;
|
|
74
|
+
if (currentState) {
|
|
75
|
+
if (currentState.metadata?.resourceType &&
|
|
76
|
+
currentState.metadata.resourceType !== resourceType) {
|
|
77
|
+
throw new Error(lang_1.lang.__('PLAN_REPLACEMENT_REQUIRED', { logicalId, fields: 'resourceType' }));
|
|
78
|
+
}
|
|
79
|
+
(0, planCapabilities_1.assertPlanIdentity)(logicalId, resourceType, currentState.definition || {}, desiredDefinition);
|
|
80
|
+
}
|
|
47
81
|
if (!currentState || currentState.status === 'tainted') {
|
|
48
82
|
const probeRead = args.probeRead ?? args.read;
|
|
49
83
|
const remote = await probeRead();
|
|
@@ -59,8 +93,8 @@ const planRefreshedResource = async (args) => {
|
|
|
59
93
|
}
|
|
60
94
|
const normalize = args.normalizeForDisplay ?? ((d) => d);
|
|
61
95
|
const currentDefinition = currentState.definition || {};
|
|
62
|
-
const normalizedCurrent = normalize(currentDefinition);
|
|
63
|
-
const normalizedDesired = normalize(desiredDefinition);
|
|
96
|
+
const normalizedCurrent = (0, planCompare_1.managedDefinition)(normalize(currentDefinition), normalize(desiredDefinition));
|
|
97
|
+
const normalizedDesired = (0, planCompare_1.managedDefinition)(normalize(desiredDefinition));
|
|
64
98
|
const definitionChanged = !(0, hashUtils_1.attributesEqual)(normalizedCurrent, normalizedDesired);
|
|
65
99
|
const refreshEnabled = args.refresh ?? true;
|
|
66
100
|
try {
|
|
@@ -69,6 +103,7 @@ const planRefreshedResource = async (args) => {
|
|
|
69
103
|
if (!definitionChanged) {
|
|
70
104
|
return { logicalId, action: 'noop', resourceType };
|
|
71
105
|
}
|
|
106
|
+
(0, planCapabilities_1.assertSupportedPlanUpdate)(logicalId, resourceType, { ...currentDefinition, ...normalizedCurrent }, normalizedDesired);
|
|
72
107
|
return {
|
|
73
108
|
logicalId,
|
|
74
109
|
action: 'update',
|
|
@@ -78,9 +113,10 @@ const planRefreshedResource = async (args) => {
|
|
|
78
113
|
}
|
|
79
114
|
const decision = await (0, exports.decideRefreshedExistsAction)({
|
|
80
115
|
read: args.read,
|
|
81
|
-
cloudToDefinition: args.cloudToDefinition,
|
|
116
|
+
cloudToDefinition: (remote) => normalize(args.cloudToDefinition(remote)),
|
|
82
117
|
enrichRemoteAttributes: args.enrichRemoteAttributes,
|
|
83
|
-
desiredDefinition,
|
|
118
|
+
desiredDefinition: normalizedDesired,
|
|
119
|
+
storedDefinition: normalizedCurrent,
|
|
84
120
|
definitionChanged,
|
|
85
121
|
extraUpdate: args.extraUpdate,
|
|
86
122
|
});
|
|
@@ -96,14 +132,19 @@ const planRefreshedResource = async (args) => {
|
|
|
96
132
|
drifted: true,
|
|
97
133
|
};
|
|
98
134
|
}
|
|
135
|
+
if (decision.action === 'state') {
|
|
136
|
+
return { logicalId, action: 'noop', resourceType, stateUpdate: desiredDefinition };
|
|
137
|
+
}
|
|
99
138
|
const normalizedLive = normalize(decision.liveAttributes);
|
|
139
|
+
const before = (0, planCompare_1.mergeLiveBefore)(normalizedCurrent, normalizedLive, normalizedDesired);
|
|
140
|
+
(0, planCapabilities_1.assertSupportedPlanUpdate)(logicalId, resourceType, { ...currentDefinition, ...before }, normalizedDesired);
|
|
100
141
|
const revertKeys = (0, planCompare_1.computeRevertKeys)(normalizedCurrent, normalizedLive, normalizedDesired);
|
|
101
142
|
return {
|
|
102
143
|
logicalId,
|
|
103
144
|
action: 'update',
|
|
104
145
|
resourceType,
|
|
105
146
|
changes: {
|
|
106
|
-
before
|
|
147
|
+
before,
|
|
107
148
|
after: normalizedDesired,
|
|
108
149
|
},
|
|
109
150
|
...(decision.drifted ? { drifted: true } : {}),
|
|
@@ -116,13 +157,17 @@ const planRefreshedResource = async (args) => {
|
|
|
116
157
|
logicalId,
|
|
117
158
|
error: error instanceof Error ? error.message : String(error),
|
|
118
159
|
}));
|
|
119
|
-
|
|
120
|
-
logicalId,
|
|
121
|
-
action: 'create',
|
|
122
|
-
resourceType,
|
|
123
|
-
changes: { before: normalizedCurrent, after: normalizedDesired },
|
|
124
|
-
drifted: true,
|
|
125
|
-
};
|
|
160
|
+
throw error;
|
|
126
161
|
}
|
|
127
162
|
};
|
|
128
|
-
|
|
163
|
+
/** Applied only under the deployment lock, never by the read-only plan command. */
|
|
164
|
+
const applyPlanStateUpdates = (state, items) => items.reduce((current, item) => {
|
|
165
|
+
const resource = (0, stateManager_1.getResource)(current, item.logicalId);
|
|
166
|
+
if (item.action !== 'noop' || !item.stateUpdate || !resource)
|
|
167
|
+
return current;
|
|
168
|
+
return (0, stateManager_1.setResource)(current, item.logicalId, {
|
|
169
|
+
...resource,
|
|
170
|
+
definition: (0, planCompare_1.mergeManagedIntent)(resource.definition ?? {}, item.stateUpdate),
|
|
171
|
+
});
|
|
172
|
+
}, state);
|
|
173
|
+
exports.applyPlanStateUpdates = applyPlanStateUpdates;
|