@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,17 +1,174 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.deleteResource = exports.updateResource = exports.readResource = exports.createResource = exports.resolveRoleGrant = void 0;
|
|
4
|
+
const functionDefinition_1 = require("../../common/functionDefinition");
|
|
5
|
+
const planCompare_1 = require("../../common/planCompare");
|
|
4
6
|
const volcengineClient_1 = require("../../common/volcengineClient");
|
|
5
7
|
const common_1 = require("../../common");
|
|
6
8
|
const iamStatements_1 = require("../../common/iamStatements");
|
|
7
9
|
const tlsOperations_1 = require("../../common/volcengineClient/tlsOperations");
|
|
8
10
|
const types_1 = require("../../types");
|
|
11
|
+
const siCron_1 = require("../../common/siCron");
|
|
9
12
|
const vefaasTypes_1 = require("./vefaasTypes");
|
|
10
13
|
const logger_1 = require("../../common/logger");
|
|
11
14
|
const lang_1 = require("../../lang");
|
|
12
15
|
const ownershipTag_1 = require("../ownershipTag");
|
|
13
16
|
const alreadyExists_1 = require("../alreadyExists");
|
|
14
17
|
const sharedLogProject_1 = require("./sharedLogProject");
|
|
18
|
+
const TIMER_TRIGGER_INSTANCE_TYPE = 'VOLCENGINE_VEFAAS_TIMER_TRIGGER';
|
|
19
|
+
/** veFaaS timer dialect: unix 5-field crontab; non-zero seconds never pass. */
|
|
20
|
+
const buildVefaasTimerTriggerSource = (timer) => ({
|
|
21
|
+
cron: (0, siCron_1.translateSiCron)(timer.cron, 'volcengine'),
|
|
22
|
+
enable: timer.enable,
|
|
23
|
+
...(timer.description !== undefined ? { description: timer.description } : {}),
|
|
24
|
+
...(timer.payload !== undefined ? { payload: timer.payload } : {}),
|
|
25
|
+
});
|
|
26
|
+
const parseVefaasTimerSource = (raw) => {
|
|
27
|
+
if (!raw) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
const parsed = JSON.parse(raw);
|
|
32
|
+
if (typeof parsed.cron !== 'string') {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
cron: parsed.cron,
|
|
37
|
+
enable: parsed.enable === true,
|
|
38
|
+
...(typeof parsed.description === 'string' && parsed.description.length > 0
|
|
39
|
+
? { description: parsed.description }
|
|
40
|
+
: {}),
|
|
41
|
+
...(typeof parsed.payload === 'string' ? { payload: parsed.payload } : {}),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
const vefaasTimerConfigFromAttributes = (attrs) => {
|
|
49
|
+
const cron = typeof attrs.cron === 'string' ? attrs.cron : undefined;
|
|
50
|
+
if (!cron) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
return {
|
|
55
|
+
cron: (0, siCron_1.translateSiCron)(cron, 'volcengine'),
|
|
56
|
+
enable: attrs.enable !== false,
|
|
57
|
+
...(typeof attrs.description === 'string' ? { description: attrs.description } : {}),
|
|
58
|
+
...(attrs.payload !== undefined ? { payload: String(attrs.payload) } : {}),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
const buildVefaasTimerTriggerInstance = (context, fn, timer) => ({
|
|
66
|
+
type: TIMER_TRIGGER_INSTANCE_TYPE,
|
|
67
|
+
id: timer.name,
|
|
68
|
+
sid: (0, common_1.buildSid)('volcengine', 'vefaas-timer-trigger', context.stage, `${fn.name}.${timer.name}`),
|
|
69
|
+
attributes: {
|
|
70
|
+
cron: timer.cron,
|
|
71
|
+
...(timer.payload !== undefined ? { payload: timer.payload } : {}),
|
|
72
|
+
enable: timer.enable,
|
|
73
|
+
...(timer.description !== undefined ? { description: timer.description } : {}),
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
/**
|
|
77
|
+
* Reconcile the function's timer triggers against the provider (issue #258).
|
|
78
|
+
* The live trigger list is the baseline so console edits converge on every
|
|
79
|
+
* deploy; state-recorded instances take over when the probe fails. Name is
|
|
80
|
+
* the drift key; si-cron stays stored and is translated only here.
|
|
81
|
+
*/
|
|
82
|
+
const reconcileVefaasTimerTriggers = async (context, fn, functionId, previousInstances, client) => {
|
|
83
|
+
const desiredTimers = fn.triggers?.timer ?? [];
|
|
84
|
+
const previousTimers = previousInstances.filter((i) => i.type === TIMER_TRIGGER_INSTANCE_TYPE);
|
|
85
|
+
if (desiredTimers.length === 0 && previousTimers.length === 0) {
|
|
86
|
+
return [];
|
|
87
|
+
}
|
|
88
|
+
let liveTimers = [];
|
|
89
|
+
let liveAvailable = true;
|
|
90
|
+
try {
|
|
91
|
+
liveTimers = (await client.vefaas.listTriggers(functionId))
|
|
92
|
+
.filter((trigger) => trigger.sourceType?.toLowerCase() === 'timer' &&
|
|
93
|
+
trigger.name &&
|
|
94
|
+
parseVefaasTimerSource(trigger.source))
|
|
95
|
+
.map((trigger) => ({
|
|
96
|
+
id: trigger.id,
|
|
97
|
+
name: trigger.name,
|
|
98
|
+
config: parseVefaasTimerSource(trigger.source),
|
|
99
|
+
}));
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
liveAvailable = false;
|
|
103
|
+
logger_1.logger.warn(lang_1.lang.__('PLAN_TIMER_TRIGGER_PROBE_FAILED', { functionName: fn.name, error: String(error) }));
|
|
104
|
+
}
|
|
105
|
+
const baseline = liveAvailable
|
|
106
|
+
? liveTimers
|
|
107
|
+
: previousTimers.flatMap((instance) => {
|
|
108
|
+
const config = vefaasTimerConfigFromAttributes(instance.attributes ?? {});
|
|
109
|
+
return config ? [{ id: undefined, name: instance.id, config }] : [];
|
|
110
|
+
});
|
|
111
|
+
const resultingInstances = [];
|
|
112
|
+
for (const timer of desiredTimers) {
|
|
113
|
+
const desiredSource = buildVefaasTimerTriggerSource(timer);
|
|
114
|
+
const live = baseline.find((entry) => entry.name === timer.name);
|
|
115
|
+
if (!live) {
|
|
116
|
+
logger_1.logger.info(lang_1.lang.__('CREATING_TIMER_TRIGGER', { triggerName: timer.name, functionName: fn.name }));
|
|
117
|
+
}
|
|
118
|
+
else if (!(0, common_1.attributesEqual)(live.config, desiredSource)) {
|
|
119
|
+
logger_1.logger.info(lang_1.lang.__('UPDATING_TIMER_TRIGGER', { triggerName: timer.name, functionName: fn.name }));
|
|
120
|
+
if (live.id) {
|
|
121
|
+
try {
|
|
122
|
+
await client.vefaas.deleteTrigger(functionId, live.id);
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
const errorCode = error?.code;
|
|
126
|
+
if (errorCode !== 'FunctionNotFound' && errorCode !== 'ResourceNotFound')
|
|
127
|
+
throw error;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
resultingInstances.push(buildVefaasTimerTriggerInstance(context, fn, timer));
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
try {
|
|
136
|
+
await client.vefaas.createTrigger({
|
|
137
|
+
functionId,
|
|
138
|
+
name: timer.name,
|
|
139
|
+
source: desiredSource,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
catch (error) {
|
|
143
|
+
// a leftover trigger from an adopted function may already carry the name
|
|
144
|
+
if (!(0, alreadyExists_1.isResourceAlreadyExistsError)(error, VEFAAS_ALREADY_EXISTS_CODES))
|
|
145
|
+
throw error;
|
|
146
|
+
logger_1.logger.warn(lang_1.lang.__('TIMER_TRIGGER_ALREADY_ATTACHED', {
|
|
147
|
+
triggerName: timer.name,
|
|
148
|
+
functionName: fn.name,
|
|
149
|
+
}));
|
|
150
|
+
}
|
|
151
|
+
logger_1.logger.info(lang_1.lang.__('TIMER_TRIGGER_CREATED', { triggerName: timer.name, functionName: fn.name }));
|
|
152
|
+
resultingInstances.push(buildVefaasTimerTriggerInstance(context, fn, timer));
|
|
153
|
+
}
|
|
154
|
+
const desiredNames = new Set(desiredTimers.map((timer) => timer.name));
|
|
155
|
+
for (const stale of baseline.filter((entry) => !desiredNames.has(entry.name))) {
|
|
156
|
+
logger_1.logger.info(lang_1.lang.__('DELETING_TIMER_TRIGGER', { triggerName: stale.name, functionName: fn.name }));
|
|
157
|
+
if (stale.id) {
|
|
158
|
+
try {
|
|
159
|
+
await client.vefaas.deleteTrigger(functionId, stale.id);
|
|
160
|
+
logger_1.logger.info(lang_1.lang.__('TIMER_TRIGGER_DELETED', { triggerName: stale.name }));
|
|
161
|
+
}
|
|
162
|
+
catch (error) {
|
|
163
|
+
const errorCode = error?.code;
|
|
164
|
+
if (errorCode !== 'FunctionNotFound' && errorCode !== 'ResourceNotFound')
|
|
165
|
+
throw error;
|
|
166
|
+
logger_1.logger.warn(lang_1.lang.__('TIMER_TRIGGER_NOT_FOUND', { triggerName: stale.name }));
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return resultingInstances;
|
|
171
|
+
};
|
|
15
172
|
const RECOVERY_GET_FUNCTION_DELAY_MS = 1500;
|
|
16
173
|
// volcengine role TRN format: trn:iam::{accountId}:role/{roleName}. Prefer the
|
|
17
174
|
// stored TRN; else construct from the known accountId, else fetch it via STS.
|
|
@@ -309,7 +466,7 @@ const createResource = async (context, fn, state) => {
|
|
|
309
466
|
config.Tags = [{ Key: ownershipTag_1.OWNERSHIP_TAG_KEY, Value: (0, ownershipTag_1.buildOwnershipTagValue)(context, logicalId) }];
|
|
310
467
|
const codePath = fn.code.path;
|
|
311
468
|
const codeHash = await (0, common_1.computeZipContentHash)(codePath);
|
|
312
|
-
const resourceAttributes = (0, vefaasTypes_1.extractVefaasDefinition)(config, codeHash);
|
|
469
|
+
const resourceAttributes = (0, vefaasTypes_1.extractVefaasDefinition)(config, codeHash, fn);
|
|
313
470
|
const definition = fn.iam ? { ...resourceAttributes, iam: fn.iam } : resourceAttributes;
|
|
314
471
|
const sid = (0, common_1.buildSid)('volcengine', context.service, context.stage, fn.name);
|
|
315
472
|
const dependentInstances = dependentResources.instances.map((dep) => ({
|
|
@@ -402,11 +559,21 @@ const createResource = async (context, fn, state) => {
|
|
|
402
559
|
if (releaseRecordId) {
|
|
403
560
|
vefaasInstance.releaseRecordId = releaseRecordId;
|
|
404
561
|
}
|
|
562
|
+
// Timer triggers bind to the function via FunctionId — reconcile after the
|
|
563
|
+
// function exists (fresh creates see an empty trigger list; adopted ones
|
|
564
|
+
// converge on leftovers).
|
|
565
|
+
const timerInstances = functionInfo.functionId
|
|
566
|
+
? await reconcileVefaasTimerTriggers(context, fn, functionInfo.functionId, [], client)
|
|
567
|
+
: [];
|
|
405
568
|
const resourceState = {
|
|
406
569
|
mode: 'managed',
|
|
407
570
|
region: context.region,
|
|
408
571
|
definition,
|
|
409
|
-
instances: [
|
|
572
|
+
instances: [
|
|
573
|
+
vefaasInstance,
|
|
574
|
+
...dependentInstances,
|
|
575
|
+
...timerInstances,
|
|
576
|
+
],
|
|
410
577
|
status: 'ready',
|
|
411
578
|
lastUpdated: new Date().toISOString(),
|
|
412
579
|
};
|
|
@@ -418,10 +585,11 @@ const readResource = async (context, functionName) => {
|
|
|
418
585
|
return await client.vefaas.getFunction(functionName);
|
|
419
586
|
};
|
|
420
587
|
exports.readResource = readResource;
|
|
421
|
-
const updateResource = async (context,
|
|
588
|
+
const updateResource = async (context, providedFn, state, options) => {
|
|
422
589
|
const serviceName = `${context.app}-${context.service}`;
|
|
423
|
-
const logicalId = `functions.${
|
|
590
|
+
const logicalId = `functions.${providedFn.key}`;
|
|
424
591
|
const currentState = (0, common_1.getResource)(state, logicalId);
|
|
592
|
+
const fn = (0, functionDefinition_1.withStoredFunctionIam)(providedFn, currentState?.definition);
|
|
425
593
|
if (!currentState) {
|
|
426
594
|
throw new Error(lang_1.lang.__('RESOURCE_STATE_NOT_FOUND', { logicalId }));
|
|
427
595
|
}
|
|
@@ -467,7 +635,7 @@ const updateResource = async (context, fn, state, options) => {
|
|
|
467
635
|
}
|
|
468
636
|
}
|
|
469
637
|
}
|
|
470
|
-
else {
|
|
638
|
+
else if (fn.log === false) {
|
|
471
639
|
const tlsToRemove = existingInstances.filter((i) => i.type.startsWith('VOLCENGINE_TLS_'));
|
|
472
640
|
if (tlsToRemove.length > 0) {
|
|
473
641
|
try {
|
|
@@ -487,10 +655,10 @@ const updateResource = async (context, fn, state, options) => {
|
|
|
487
655
|
}
|
|
488
656
|
// Determine if the current role is external (string TRN)
|
|
489
657
|
const currentIam = currentState.definition?.iam;
|
|
490
|
-
const isExternalRole =
|
|
658
|
+
const isExternalRole = typeof fn.iam?.role === 'string';
|
|
491
659
|
if (isExternalRole) {
|
|
492
660
|
// External role - skip role management, use TRN directly
|
|
493
|
-
role = { roleName:
|
|
661
|
+
role = { roleName: fn.iam.role, trn: fn.iam.role };
|
|
494
662
|
}
|
|
495
663
|
else if (!hasIamRole && !isTainted) {
|
|
496
664
|
// Role creation only: skip TLS so existing log resources are untouched,
|
|
@@ -541,14 +709,16 @@ const updateResource = async (context, fn, state, options) => {
|
|
|
541
709
|
// the role: drift is detected by comparing desired peer signals (network /
|
|
542
710
|
// TOS mount) against those recorded in each stored definition.
|
|
543
711
|
const derivedBaselineChanged = roleGrant?.derivedBaselineChanged ?? false;
|
|
544
|
-
if ((derivedBaselineChanged || customStatementsChanged) && iamRoleInstance) {
|
|
712
|
+
if ((options?.force || derivedBaselineChanged || customStatementsChanged) && iamRoleInstance) {
|
|
545
713
|
await client.iam.updateRolePolicy(iamRoleInstance.id, roleGrant?.executionStatements ?? (0, vefaasTypes_1.deriveVefaasExecutionStatements)(fn, context), desiredIamStatements);
|
|
546
714
|
}
|
|
547
715
|
// Check managed policy changes
|
|
548
716
|
const desiredManagedPolicies = desiredRoleConfig?.managed_policies;
|
|
549
717
|
const currentManagedPoliciesList = currentRoleConfig?.managed_policies;
|
|
550
718
|
const managedPoliciesChanged = JSON.stringify(currentManagedPoliciesList) !== JSON.stringify(desiredManagedPolicies);
|
|
551
|
-
if (
|
|
719
|
+
if (desiredManagedPolicies !== undefined &&
|
|
720
|
+
(options?.force || managedPoliciesChanged) &&
|
|
721
|
+
iamRoleInstance) {
|
|
552
722
|
await client.iam.updateManagedPolicies(iamRoleInstance.id, desiredManagedPolicies ?? []);
|
|
553
723
|
}
|
|
554
724
|
}
|
|
@@ -586,7 +756,7 @@ const updateResource = async (context, fn, state, options) => {
|
|
|
586
756
|
});
|
|
587
757
|
const codePath = fn.code.path;
|
|
588
758
|
const desiredCodeHash = await (0, common_1.computeZipContentHash)(codePath);
|
|
589
|
-
const baseDefinition = (0, vefaasTypes_1.extractVefaasDefinition)(config, desiredCodeHash);
|
|
759
|
+
const baseDefinition = (0, vefaasTypes_1.extractVefaasDefinition)(config, desiredCodeHash, fn);
|
|
590
760
|
const desiredDefinition = fn.iam ? { ...baseDefinition, iam: fn.iam } : baseDefinition;
|
|
591
761
|
const currentDefinition = currentState.definition || {};
|
|
592
762
|
const currentCodeHash = currentDefinition.codeHash;
|
|
@@ -615,7 +785,7 @@ const updateResource = async (context, fn, state, options) => {
|
|
|
615
785
|
tosMountConfig: desiredDefinition.tosMountConfig,
|
|
616
786
|
logConfig: desiredDefinition.logConfig,
|
|
617
787
|
};
|
|
618
|
-
const configChanged =
|
|
788
|
+
const configChanged = (0, planCompare_1.definitionsDiffer)(existingConfigOnly, desiredConfigOnly);
|
|
619
789
|
// The instance in state carries the provider function Id — use it directly
|
|
620
790
|
// for all follow-up calls instead of re-resolving the name every time.
|
|
621
791
|
const currentFunctionId = currentInstance.functionId;
|
|
@@ -653,7 +823,9 @@ const updateResource = async (context, fn, state, options) => {
|
|
|
653
823
|
}
|
|
654
824
|
const existingDependentInstances = existingInstances
|
|
655
825
|
.filter((i) => i.type !== 'VOLCENGINE_VEFAAS_FUNCTION' &&
|
|
656
|
-
|
|
826
|
+
// timers are fully rebuilt from the reconcile result below
|
|
827
|
+
i.type !== TIMER_TRIGGER_INSTANCE_TYPE &&
|
|
828
|
+
(fn.log !== false || !i.type.startsWith('VOLCENGINE_TLS_')))
|
|
657
829
|
.map((i) => {
|
|
658
830
|
const { sid: existingSid, id: existingId, ...rest } = i;
|
|
659
831
|
return {
|
|
@@ -671,11 +843,21 @@ const updateResource = async (context, fn, state, options) => {
|
|
|
671
843
|
...(dep.trn ? { trn: dep.trn } : {}),
|
|
672
844
|
...dep.attributes,
|
|
673
845
|
}));
|
|
846
|
+
// Timer triggers reconcile against the live trigger list (issue #258);
|
|
847
|
+
// functionInfo above already carries the resolved function Id.
|
|
848
|
+
const timerInstances = functionInfo.functionId
|
|
849
|
+
? await reconcileVefaasTimerTriggers(context, fn, functionInfo.functionId, existingInstances, client)
|
|
850
|
+
: [];
|
|
674
851
|
const resourceState = {
|
|
675
852
|
mode: 'managed',
|
|
676
853
|
region: context.region,
|
|
677
|
-
definition: desiredDefinition,
|
|
678
|
-
instances: [
|
|
854
|
+
definition: (0, functionDefinition_1.withLifecycleIntent)((0, planCompare_1.mergeManagedIntent)(currentState.definition ?? {}, desiredDefinition), desiredDefinition, ['timers']),
|
|
855
|
+
instances: [
|
|
856
|
+
vefaasInstance,
|
|
857
|
+
...existingDependentInstances,
|
|
858
|
+
...newDependentInstancesMapped,
|
|
859
|
+
...timerInstances,
|
|
860
|
+
],
|
|
679
861
|
status: 'ready',
|
|
680
862
|
lastUpdated: new Date().toISOString(),
|
|
681
863
|
};
|
|
@@ -688,6 +870,42 @@ const deleteResource = async (context, functionName, logicalId, state) => {
|
|
|
688
870
|
const vefaasInstance = existingInstances.find((i) => i.type === 'VOLCENGINE_VEFAAS_FUNCTION');
|
|
689
871
|
const functionId = vefaasInstance?.functionId;
|
|
690
872
|
const client = (0, volcengineClient_1.createVolcengineClient)(context);
|
|
873
|
+
// Delete timer triggers before the function (they hang off its FunctionId;
|
|
874
|
+
// si owns every timer on its function, so state-recorded ones all go).
|
|
875
|
+
const timerInstances = existingInstances.filter((i) => i.type === TIMER_TRIGGER_INSTANCE_TYPE);
|
|
876
|
+
if (functionId && timerInstances.length > 0) {
|
|
877
|
+
let liveTimerIds = [];
|
|
878
|
+
try {
|
|
879
|
+
liveTimerIds = await client.vefaas.listTriggers(functionId);
|
|
880
|
+
}
|
|
881
|
+
catch {
|
|
882
|
+
// probe failure must not block teardown — fall back to name lookup below
|
|
883
|
+
}
|
|
884
|
+
for (const timerInstance of timerInstances) {
|
|
885
|
+
logger_1.logger.info(lang_1.lang.__('DELETING_TIMER_TRIGGER', {
|
|
886
|
+
triggerName: timerInstance.id,
|
|
887
|
+
functionName,
|
|
888
|
+
}));
|
|
889
|
+
const liveId = liveTimerIds.find((t) => t.name === timerInstance.id)?.id ?? undefined;
|
|
890
|
+
if (!liveId) {
|
|
891
|
+
logger_1.logger.warn(lang_1.lang.__('TIMER_TRIGGER_NOT_FOUND', { triggerName: timerInstance.id }));
|
|
892
|
+
continue;
|
|
893
|
+
}
|
|
894
|
+
try {
|
|
895
|
+
await client.vefaas.deleteTrigger(functionId, liveId);
|
|
896
|
+
logger_1.logger.info(lang_1.lang.__('TIMER_TRIGGER_DELETED', { triggerName: timerInstance.id }));
|
|
897
|
+
}
|
|
898
|
+
catch (err) {
|
|
899
|
+
const errorCode = err?.code;
|
|
900
|
+
if (errorCode === 'FunctionNotFound' || errorCode === 'ResourceNotFound') {
|
|
901
|
+
logger_1.logger.warn(lang_1.lang.__('TIMER_TRIGGER_NOT_FOUND', { triggerName: timerInstance.id }));
|
|
902
|
+
}
|
|
903
|
+
else {
|
|
904
|
+
throw err;
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
}
|
|
691
909
|
if (functionId) {
|
|
692
910
|
try {
|
|
693
911
|
await client.vefaas.deleteFunction(functionId);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getTrustedServicesForFunction = exports.deriveVefaasExecutionStatements = exports.buildDefaultTrustPolicy = exports.extractVefaasDefinition = exports.functionToVefaasConfig = void 0;
|
|
4
|
+
const functionDefinition_1 = require("../../common/functionDefinition");
|
|
4
5
|
const TEMPLATE_REF_PATTERN = /^\$\{[^}]+\}$/;
|
|
5
6
|
/**
|
|
6
7
|
* Determines which Volcengine services should be trusted to assume the function's IAM role.
|
|
@@ -54,8 +55,8 @@ const functionToVefaasConfig = (fn, options) => {
|
|
|
54
55
|
return config;
|
|
55
56
|
};
|
|
56
57
|
exports.functionToVefaasConfig = functionToVefaasConfig;
|
|
57
|
-
const extractVefaasDefinition = (config, codeHash) => {
|
|
58
|
-
return {
|
|
58
|
+
const extractVefaasDefinition = (config, codeHash, fn) => {
|
|
59
|
+
return (0, functionDefinition_1.withFunctionLifecycle)({
|
|
59
60
|
functionName: config.functionName,
|
|
60
61
|
runtime: config.runtime,
|
|
61
62
|
handler: config.handler,
|
|
@@ -68,7 +69,9 @@ const extractVefaasDefinition = (config, codeHash) => {
|
|
|
68
69
|
vpcConfig: config.vpcConfig,
|
|
69
70
|
tosMountConfig: config.tosMountConfig,
|
|
70
71
|
logConfig: config.logConfig,
|
|
71
|
-
}
|
|
72
|
+
}, fn,
|
|
73
|
+
// veFaaS executor never applies HTTP triggers or custom domains; persisting them would record intent the cloud never receives.
|
|
74
|
+
{ http: false, domain: false });
|
|
72
75
|
};
|
|
73
76
|
exports.extractVefaasDefinition = extractVefaasDefinition;
|
|
74
77
|
const buildDefaultTrustPolicy = (trustedServices) => {
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.functionSchema = void 0;
|
|
3
|
+
exports.functionSchema = exports.TIMER_TRIGGER_NAME_PATTERN = void 0;
|
|
4
4
|
const templateRefSchema_1 = require("./templateRefSchema");
|
|
5
5
|
const securityGroupRulePattern = '^[A-Za-z]+:\\d{1,3}(?:\\.\\d{1,3}){3}\\/\\d{1,2}:(?:ALL|\\d{1,5}(?:\\/\\d{1,5})?)$';
|
|
6
|
+
/**
|
|
7
|
+
* Timer trigger names become physical cloud trigger names (FC3 triggerName,
|
|
8
|
+
* SCF TriggerName, veFaaS Name) — all three accept letters/digits/`-`/`_`
|
|
9
|
+
* with a 60-char budget on the strictest provider (Tencent).
|
|
10
|
+
*/
|
|
11
|
+
exports.TIMER_TRIGGER_NAME_PATTERN = '^[A-Za-z][A-Za-z0-9_-]{0,59}$';
|
|
6
12
|
exports.functionSchema = {
|
|
7
13
|
$id: 'https://serverlessinsight.geekfun.club/schemas/functionschema.json',
|
|
8
14
|
type: 'object',
|
|
@@ -86,7 +92,7 @@ exports.functionSchema = {
|
|
|
86
92
|
environment: {
|
|
87
93
|
type: 'object',
|
|
88
94
|
additionalProperties: {
|
|
89
|
-
|
|
95
|
+
...templateRefSchema_1.scalarValue,
|
|
90
96
|
},
|
|
91
97
|
},
|
|
92
98
|
network: {
|
|
@@ -173,6 +179,23 @@ exports.functionSchema = {
|
|
|
173
179
|
},
|
|
174
180
|
},
|
|
175
181
|
},
|
|
182
|
+
timer: {
|
|
183
|
+
type: 'array',
|
|
184
|
+
items: {
|
|
185
|
+
type: 'object',
|
|
186
|
+
required: ['name', 'cron'],
|
|
187
|
+
additionalProperties: false,
|
|
188
|
+
properties: {
|
|
189
|
+
name: (0, templateRefSchema_1.resolvableConstrained)({ pattern: exports.TIMER_TRIGGER_NAME_PATTERN }),
|
|
190
|
+
// si-cron syntax (issue #258); full grammar validation runs
|
|
191
|
+
// in semantic validation where errors can carry the reason
|
|
192
|
+
cron: (0, templateRefSchema_1.resolvableConstrained)({ pattern: '.+' }),
|
|
193
|
+
payload: { type: 'string' },
|
|
194
|
+
enable: templateRefSchema_1.resolvableBoolean,
|
|
195
|
+
description: { type: 'string' },
|
|
196
|
+
},
|
|
197
|
+
},
|
|
198
|
+
},
|
|
176
199
|
},
|
|
177
200
|
},
|
|
178
201
|
domain: {
|
|
@@ -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.validateYaml = void 0;
|
|
6
|
+
exports.validateYaml = exports.IacSchemaErrors = void 0;
|
|
7
7
|
const ajv_1 = __importDefault(require("ajv"));
|
|
8
8
|
const common_1 = require("../common");
|
|
9
9
|
const rootSchema_1 = require("./rootSchema");
|
|
@@ -45,6 +45,7 @@ class IacSchemaErrors extends Error {
|
|
|
45
45
|
return this.schemaErrors;
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
+
exports.IacSchemaErrors = IacSchemaErrors;
|
|
48
49
|
const ajv = new ajv_1.default({ allowUnionTypes: true, strict: false, allErrors: true });
|
|
49
50
|
const validate = ajv
|
|
50
51
|
.addSchema(functionSchema_1.functionSchema)
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateYaml = void 0;
|
|
3
|
+
exports.exportIacJsonSchema = exports.IacSchemaErrors = exports.validateYaml = void 0;
|
|
4
4
|
var iacSchema_1 = require("./iacSchema");
|
|
5
5
|
Object.defineProperty(exports, "validateYaml", { enumerable: true, get: function () { return iacSchema_1.validateYaml; } });
|
|
6
|
+
Object.defineProperty(exports, "IacSchemaErrors", { enumerable: true, get: function () { return iacSchema_1.IacSchemaErrors; } });
|
|
7
|
+
var schemaExport_1 = require("./schemaExport");
|
|
8
|
+
Object.defineProperty(exports, "exportIacJsonSchema", { enumerable: true, get: function () { return schemaExport_1.exportIacJsonSchema; } });
|
|
@@ -9,14 +9,18 @@ const FUNCTION_NAME_MAX_LENGTH = {
|
|
|
9
9
|
};
|
|
10
10
|
const functionNameLimitBranch = (provider, maxLength) => ({
|
|
11
11
|
if: {
|
|
12
|
-
properties: {
|
|
12
|
+
properties: {
|
|
13
|
+
provider: { type: 'object', properties: { name: { const: provider } }, required: ['name'] },
|
|
14
|
+
},
|
|
13
15
|
required: ['provider'],
|
|
14
16
|
},
|
|
15
17
|
then: {
|
|
16
18
|
properties: {
|
|
17
19
|
functions: {
|
|
20
|
+
type: 'object',
|
|
18
21
|
patternProperties: {
|
|
19
22
|
'.*': {
|
|
23
|
+
type: 'object',
|
|
20
24
|
properties: {
|
|
21
25
|
// Whole-value template references bypass the literal limit.
|
|
22
26
|
name: { anyOf: [{ type: 'string', maxLength }, templateRefSchema_1.templateRefSchema] },
|
|
@@ -31,13 +35,26 @@ exports.rootSchema = {
|
|
|
31
35
|
$id: 'https://serverlessinsight.geekfun.club/schemas/schema.json',
|
|
32
36
|
type: 'object',
|
|
33
37
|
properties: {
|
|
34
|
-
version: {
|
|
35
|
-
|
|
38
|
+
version: {
|
|
39
|
+
type: 'string',
|
|
40
|
+
enum: ['0.0.0', '0.0.1', '0.1.0'],
|
|
41
|
+
description: 'ServerlessInsight IaC document version.',
|
|
42
|
+
},
|
|
43
|
+
app: {
|
|
44
|
+
type: 'string',
|
|
45
|
+
pattern: '^[a-z][a-z0-9-]*$',
|
|
46
|
+
description: 'Application name — the top-level grouping of services. Lowercase letters, digits and hyphens, starting with a letter.',
|
|
47
|
+
},
|
|
36
48
|
provider: {
|
|
37
49
|
type: 'object',
|
|
50
|
+
description: 'Target cloud provider and deployment region.',
|
|
38
51
|
properties: {
|
|
39
|
-
name: {
|
|
40
|
-
|
|
52
|
+
name: {
|
|
53
|
+
type: 'string',
|
|
54
|
+
enum: ['huawei', 'aliyun', 'tencent', 'aws', 'volcengine'],
|
|
55
|
+
description: 'Cloud provider identifier.',
|
|
56
|
+
},
|
|
57
|
+
region: { type: 'string', description: 'Deployment region, e.g. cn-hangzhou.' },
|
|
41
58
|
},
|
|
42
59
|
required: ['name', 'region'],
|
|
43
60
|
allOf: [
|
|
@@ -86,58 +103,70 @@ exports.rootSchema = {
|
|
|
86
103
|
},
|
|
87
104
|
],
|
|
88
105
|
},
|
|
89
|
-
service: {
|
|
106
|
+
service: {
|
|
107
|
+
type: 'string',
|
|
108
|
+
pattern: '^[a-z][a-z0-9-]*$',
|
|
109
|
+
description: 'Service name inside the application. Lowercase letters, digits and hyphens, starting with a letter.',
|
|
110
|
+
},
|
|
90
111
|
// Target Console org (organizations.slug). Optional — required only when an
|
|
91
112
|
// explicit SaaS state backend is declared (allOf branch below); with
|
|
92
113
|
// LOCAL/BUCKET_STORE backends it is allowed but inert (decision D-6).
|
|
93
|
-
org: {
|
|
114
|
+
org: {
|
|
115
|
+
type: 'string',
|
|
116
|
+
pattern: '^[a-z0-9][a-z0-9-]*$',
|
|
117
|
+
description: 'Target ServerlessInsight Console organization slug (required for SaaS state backend).',
|
|
118
|
+
},
|
|
94
119
|
vars: {
|
|
95
120
|
type: 'object',
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
},
|
|
121
|
+
description: 'Reusable variables referenceable as ${vars.<key>} throughout the document.',
|
|
122
|
+
additionalProperties: templateRefSchema_1.scalarValue,
|
|
99
123
|
},
|
|
100
124
|
stages: {
|
|
101
125
|
type: 'object',
|
|
126
|
+
description: 'Per-stage variables referenceable as ${stages.<key>}, keyed by stage name.',
|
|
102
127
|
patternProperties: {
|
|
103
128
|
'.*': {
|
|
104
129
|
type: 'object',
|
|
105
|
-
additionalProperties:
|
|
106
|
-
type: ['string', 'number', 'boolean'],
|
|
107
|
-
},
|
|
130
|
+
additionalProperties: templateRefSchema_1.scalarValue,
|
|
108
131
|
},
|
|
109
132
|
},
|
|
110
133
|
},
|
|
111
134
|
tags: {
|
|
112
135
|
type: 'object',
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
},
|
|
136
|
+
description: 'Tags applied to every managed cloud resource.',
|
|
137
|
+
additionalProperties: templateRefSchema_1.scalarValue,
|
|
116
138
|
},
|
|
117
139
|
functions: {
|
|
140
|
+
description: 'Serverless function definitions keyed by logical id.',
|
|
118
141
|
$ref: 'https://serverlessinsight.geekfun.club/schemas/functionschema.json',
|
|
119
142
|
},
|
|
120
143
|
events: {
|
|
144
|
+
description: 'Event definitions (e.g. API_GATEWAY) keyed by logical id.',
|
|
121
145
|
$ref: 'https://serverlessinsight.geekfun.club/schemas/eventschema.json',
|
|
122
146
|
},
|
|
123
147
|
databases: {
|
|
148
|
+
description: 'Serverless database definitions keyed by logical id.',
|
|
124
149
|
$ref: 'https://serverlessinsight.geekfun.club/schemas/databaseschema.json',
|
|
125
150
|
},
|
|
126
151
|
buckets: {
|
|
152
|
+
description: 'Object-storage bucket definitions keyed by logical id.',
|
|
127
153
|
$ref: 'https://serverlessinsight.geekfun.club/schemas/bucketschema.json',
|
|
128
154
|
},
|
|
129
155
|
tables: {
|
|
156
|
+
description: 'Tablestore table definitions keyed by logical id.',
|
|
130
157
|
$ref: 'https://serverlessinsight.geekfun.club/schemas/tableschema.json',
|
|
131
158
|
},
|
|
132
159
|
backend: {
|
|
133
160
|
type: 'object',
|
|
161
|
+
description: 'Remote state backend configuration (defaults to the SaaS backend).',
|
|
134
162
|
properties: {
|
|
135
163
|
state_manager: {
|
|
136
164
|
type: 'object',
|
|
165
|
+
description: 'State storage: LOCAL directory, BUCKET_STORE, or the SaaS Console.',
|
|
137
166
|
properties: {
|
|
138
167
|
type: { type: 'string', enum: ['LOCAL', 'BUCKET_STORE', 'SAAS'] },
|
|
139
|
-
bucket: { type: 'string' },
|
|
140
|
-
key: { type: 'string' },
|
|
168
|
+
bucket: { type: 'string', description: 'State bucket name (BUCKET_STORE only).' },
|
|
169
|
+
key: { type: 'string', description: 'State object key (BUCKET_STORE only).' },
|
|
141
170
|
},
|
|
142
171
|
required: ['type'],
|
|
143
172
|
additionalProperties: false,
|
|
@@ -157,8 +186,10 @@ exports.rootSchema = {
|
|
|
157
186
|
if: {
|
|
158
187
|
properties: {
|
|
159
188
|
backend: {
|
|
189
|
+
type: 'object',
|
|
160
190
|
properties: {
|
|
161
191
|
state_manager: {
|
|
192
|
+
type: 'object',
|
|
162
193
|
properties: { type: { const: 'SAAS' } },
|
|
163
194
|
required: ['type'],
|
|
164
195
|
},
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.exportIacJsonSchema = void 0;
|
|
4
|
+
const rootSchema_1 = require("./rootSchema");
|
|
5
|
+
const functionSchema_1 = require("./functionSchema");
|
|
6
|
+
const eventSchema_1 = require("./eventSchema");
|
|
7
|
+
const databaseSchema_1 = require("./databaseSchema");
|
|
8
|
+
const bucketSchema_1 = require("./bucketSchema");
|
|
9
|
+
const tableschema_1 = require("./tableschema");
|
|
10
|
+
/**
|
|
11
|
+
* Issue #250: export the schemas Ajv compiles against as one self-contained,
|
|
12
|
+
* standard JSON Schema document. The compiled stack uses draft-07 style with
|
|
13
|
+
* external `$ref`s by `$id`; the export bundles every referenced schema under
|
|
14
|
+
* `definitions` and rewrites the refs to local pointers, so the artifact
|
|
15
|
+
* loads in a bare Ajv (or any draft-07 validator) with zero setup — usable as
|
|
16
|
+
* an anchor for structured YAML generation, editor completion, and
|
|
17
|
+
* `si validate` loops.
|
|
18
|
+
*/
|
|
19
|
+
const REF_TARGETS = {
|
|
20
|
+
'https://serverlessinsight.geekfun.club/schemas/functionschema.json': 'functions',
|
|
21
|
+
'https://serverlessinsight.geekfun.club/schemas/eventschema.json': 'events',
|
|
22
|
+
'https://serverlessinsight.geekfun.club/schemas/databaseschema.json': 'databases',
|
|
23
|
+
'https://serverlessinsight.geekfun.club/schemas/bucketschema.json': 'buckets',
|
|
24
|
+
'https://serverlessinsight.geekfun.club/schemas/tableschema.json': 'tables',
|
|
25
|
+
};
|
|
26
|
+
const rewriteRefs = (node) => {
|
|
27
|
+
if (Array.isArray(node)) {
|
|
28
|
+
node.forEach(rewriteRefs);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (node && typeof node === 'object') {
|
|
32
|
+
Object.entries(node).forEach(([key, value]) => {
|
|
33
|
+
if (key === '$ref' && typeof value === 'string' && REF_TARGETS[value]) {
|
|
34
|
+
node['$ref'] = `#/definitions/${REF_TARGETS[value]}`;
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
rewriteRefs(value);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
const exportIacJsonSchema = () => {
|
|
42
|
+
const bundled = {
|
|
43
|
+
...rootSchema_1.rootSchema,
|
|
44
|
+
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
45
|
+
title: 'ServerlessInsight IaC configuration',
|
|
46
|
+
description: 'JSON Schema for ServerlessInsight serverless IaC YAML files. Use it to generate or ' +
|
|
47
|
+
'complete `serverless-insight.yml` documents; validate results with `si validate`.',
|
|
48
|
+
definitions: {
|
|
49
|
+
functions: functionSchema_1.functionSchema,
|
|
50
|
+
events: eventSchema_1.eventSchema,
|
|
51
|
+
databases: databaseSchema_1.databaseSchema,
|
|
52
|
+
buckets: bucketSchema_1.bucketSchema,
|
|
53
|
+
tables: tableschema_1.tableSchema,
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
const plain = JSON.parse(JSON.stringify(bundled));
|
|
57
|
+
rewriteRefs(plain);
|
|
58
|
+
return plain;
|
|
59
|
+
};
|
|
60
|
+
exports.exportIacJsonSchema = exportIacJsonSchema;
|