@geek-fun/serverlessinsight 0.9.0 → 0.9.2
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 +2 -2
- package/.serverlessinsight/state-insight-poc-app-log-insight-poc-tencent-log.json.backup +3 -3
- 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 +109 -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 +2 -2
- package/.serverlessinsight/state-role-reconcile-test-app-role-reconcile-test-service.json.backup +3 -3
- package/CHANGELOG.md +17 -0
- package/README.md +78 -2
- package/README.zh-CN.md +69 -2
- package/codecov +0 -0
- package/codecov.SHA256SUM +1 -0
- package/codecov.SHA256SUM.sig +16 -0
- package/dist/package.json +2 -2
- package/dist/src/commands/deploy.js +9 -3
- package/dist/src/commands/destroy.js +8 -2
- package/dist/src/commands/forceUnlock.js +5 -5
- package/dist/src/commands/index.js +173 -85
- package/dist/src/commands/login.js +12 -1
- package/dist/src/commands/migrate.js +287 -0
- package/dist/src/commands/plan.js +28 -2
- package/dist/src/commands/schema.js +24 -0
- package/dist/src/commands/show.js +99 -33
- package/dist/src/commands/validate.js +34 -2
- package/dist/src/common/aliyunClient/apigwOperations.js +4 -4
- package/dist/src/common/aliyunClient/ecsOperations.js +22 -13
- package/dist/src/common/aliyunClient/fc3Operations.js +39 -4
- package/dist/src/common/aliyunClient/nasOperations.js +4 -3
- package/dist/src/common/aliyunClient/ossOperations.js +52 -8
- package/dist/src/common/aliyunClient/slsOperations.js +3 -2
- package/dist/src/common/aliyunClient/tablestoreOperations.js +22 -11
- package/dist/src/common/apiClient.js +22 -5
- package/dist/src/common/constants.js +7 -1
- package/dist/src/common/context.js +5 -4
- package/dist/src/common/jsonOutput.js +77 -0
- package/dist/src/common/lockManager.js +1 -1
- package/dist/src/common/logger.js +6 -3
- package/dist/src/common/migrationMarker.js +34 -0
- package/dist/src/common/noColor.js +9 -0
- package/dist/src/common/planFormatter.js +12 -6
- package/dist/src/common/runtimeMapper.js +7 -3
- package/dist/src/common/siCron.js +415 -0
- package/dist/src/common/stateBackend/cosStateBackend.js +1 -1
- package/dist/src/common/stateBackend/index.js +5 -2
- package/dist/src/common/stateBackend/localStateBackend.js +8 -2
- package/dist/src/common/stateBackend/ossStateBackend.js +1 -1
- package/dist/src/common/stateBackend/remoteStateBackend.js +19 -2
- package/dist/src/common/stateBackend/saasStateBackend.js +88 -9
- package/dist/src/common/stateManager.js +56 -5
- package/dist/src/common/tencentClient/cosOperations.js +1 -1
- package/dist/src/common/tencentClient/scfOperations.js +4 -1
- package/dist/src/common/volcengineClient/apigwOperations.js +2 -2
- package/dist/src/common/volcengineClient/index.js +6 -2
- package/dist/src/common/volcengineClient/vefaasOperations.js +48 -3
- package/dist/src/lang/en.js +254 -1
- package/dist/src/lang/index.js +36 -1
- package/dist/src/lang/zh-CN.js +253 -1
- package/dist/src/parser/functionParser.js +47 -1
- package/dist/src/parser/index.js +1 -1
- package/dist/src/stack/aliyunStack/apigwExecutor.js +2 -2
- package/dist/src/stack/aliyunStack/apigwResource.js +22 -10
- package/dist/src/stack/aliyunStack/databaseExecutor.js +5 -5
- package/dist/src/stack/aliyunStack/databasePlanner.js +2 -2
- package/dist/src/stack/aliyunStack/databaseResource.js +18 -10
- package/dist/src/stack/aliyunStack/esServerlessTypes.js +2 -1
- package/dist/src/stack/aliyunStack/fc3Executor.js +2 -2
- package/dist/src/stack/aliyunStack/fc3Planner.js +26 -0
- package/dist/src/stack/aliyunStack/fc3Resource.js +190 -13
- package/dist/src/stack/aliyunStack/ossExecutor.js +2 -2
- package/dist/src/stack/aliyunStack/ossResource.js +5 -1
- package/dist/src/stack/aliyunStack/rdsTypes.js +5 -1
- package/dist/src/stack/aliyunStack/tablestoreExecutor.js +2 -2
- package/dist/src/stack/aliyunStack/tablestoreResource.js +3 -3
- package/dist/src/stack/aliyunStack/tablestoreTypes.js +3 -2
- package/dist/src/stack/deploy.js +2 -3
- package/dist/src/stack/localStack/event.js +2 -13
- package/dist/src/stack/localStack/function.js +2 -13
- package/dist/src/stack/localStack/functionRunner.js +5 -4
- package/dist/src/stack/localStack/index.js +8 -1
- package/dist/src/stack/localStack/timer.js +162 -0
- package/dist/src/stack/localStack/utils.js +19 -1
- package/dist/src/stack/scfStack/cosExecutor.js +2 -2
- package/dist/src/stack/scfStack/cosResource.js +2 -2
- package/dist/src/stack/scfStack/esServerlessExecutor.js +5 -5
- package/dist/src/stack/scfStack/esServerlessResource.js +7 -3
- package/dist/src/stack/scfStack/esServerlessTypes.js +2 -1
- package/dist/src/stack/scfStack/scfExecutor.js +2 -2
- package/dist/src/stack/scfStack/scfPlanner.js +52 -18
- package/dist/src/stack/scfStack/scfResource.js +202 -12
- package/dist/src/stack/scfStack/tdsqlcExecutor.js +5 -5
- package/dist/src/stack/scfStack/tdsqlcResource.js +7 -3
- package/dist/src/stack/volcengineStack/apigwExecutor.js +2 -2
- package/dist/src/stack/volcengineStack/apigwResource.js +7 -4
- package/dist/src/stack/volcengineStack/tosExecutor.js +2 -2
- package/dist/src/stack/volcengineStack/tosResource.js +1 -1
- package/dist/src/stack/volcengineStack/vefaasExecutor.js +2 -2
- package/dist/src/stack/volcengineStack/vefaasPlanner.js +49 -0
- package/dist/src/stack/volcengineStack/vefaasResource.js +221 -4
- 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 +77 -19
- 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 +2 -2
- package/samples/aliyun-poc-timer.yml +39 -0
|
@@ -6,12 +6,167 @@ const common_1 = require("../../common");
|
|
|
6
6
|
const iamStatements_1 = require("../../common/iamStatements");
|
|
7
7
|
const tlsOperations_1 = require("../../common/volcengineClient/tlsOperations");
|
|
8
8
|
const types_1 = require("../../types");
|
|
9
|
+
const siCron_1 = require("../../common/siCron");
|
|
9
10
|
const vefaasTypes_1 = require("./vefaasTypes");
|
|
10
11
|
const logger_1 = require("../../common/logger");
|
|
11
12
|
const lang_1 = require("../../lang");
|
|
12
13
|
const ownershipTag_1 = require("../ownershipTag");
|
|
13
14
|
const alreadyExists_1 = require("../alreadyExists");
|
|
14
15
|
const sharedLogProject_1 = require("./sharedLogProject");
|
|
16
|
+
const TIMER_TRIGGER_INSTANCE_TYPE = 'VOLCENGINE_VEFAAS_TIMER_TRIGGER';
|
|
17
|
+
/** veFaaS timer dialect: unix 5-field crontab; non-zero seconds never pass. */
|
|
18
|
+
const buildVefaasTimerTriggerSource = (timer) => ({
|
|
19
|
+
cron: (0, siCron_1.translateSiCron)(timer.cron, 'volcengine'),
|
|
20
|
+
enable: timer.enable,
|
|
21
|
+
...(timer.description !== undefined ? { description: timer.description } : {}),
|
|
22
|
+
...(timer.payload !== undefined ? { payload: timer.payload } : {}),
|
|
23
|
+
});
|
|
24
|
+
const parseVefaasTimerSource = (raw) => {
|
|
25
|
+
if (!raw) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
const parsed = JSON.parse(raw);
|
|
30
|
+
if (typeof parsed.cron !== 'string') {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
cron: parsed.cron,
|
|
35
|
+
enable: parsed.enable === true,
|
|
36
|
+
...(typeof parsed.description === 'string' && parsed.description.length > 0
|
|
37
|
+
? { description: parsed.description }
|
|
38
|
+
: {}),
|
|
39
|
+
...(typeof parsed.payload === 'string' ? { payload: parsed.payload } : {}),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const vefaasTimerConfigFromAttributes = (attrs) => {
|
|
47
|
+
const cron = typeof attrs.cron === 'string' ? attrs.cron : undefined;
|
|
48
|
+
if (!cron) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
return {
|
|
53
|
+
cron: (0, siCron_1.translateSiCron)(cron, 'volcengine'),
|
|
54
|
+
enable: attrs.enable !== false,
|
|
55
|
+
...(typeof attrs.description === 'string' ? { description: attrs.description } : {}),
|
|
56
|
+
...(attrs.payload !== undefined ? { payload: String(attrs.payload) } : {}),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
const buildVefaasTimerTriggerInstance = (context, fn, timer) => ({
|
|
64
|
+
type: TIMER_TRIGGER_INSTANCE_TYPE,
|
|
65
|
+
id: timer.name,
|
|
66
|
+
sid: (0, common_1.buildSid)('volcengine', 'vefaas-timer-trigger', context.stage, `${fn.name}.${timer.name}`),
|
|
67
|
+
attributes: {
|
|
68
|
+
cron: timer.cron,
|
|
69
|
+
...(timer.payload !== undefined ? { payload: timer.payload } : {}),
|
|
70
|
+
enable: timer.enable,
|
|
71
|
+
...(timer.description !== undefined ? { description: timer.description } : {}),
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
/**
|
|
75
|
+
* Reconcile the function's timer triggers against the provider (issue #258).
|
|
76
|
+
* The live trigger list is the baseline so console edits converge on every
|
|
77
|
+
* deploy; state-recorded instances take over when the probe fails. Name is
|
|
78
|
+
* the drift key; si-cron stays stored and is translated only here.
|
|
79
|
+
*/
|
|
80
|
+
const reconcileVefaasTimerTriggers = async (context, fn, functionId, previousInstances, client) => {
|
|
81
|
+
const desiredTimers = fn.triggers?.timer ?? [];
|
|
82
|
+
const previousTimers = previousInstances.filter((i) => i.type === TIMER_TRIGGER_INSTANCE_TYPE);
|
|
83
|
+
if (desiredTimers.length === 0 && previousTimers.length === 0) {
|
|
84
|
+
return [];
|
|
85
|
+
}
|
|
86
|
+
let liveTimers = [];
|
|
87
|
+
let liveAvailable = true;
|
|
88
|
+
try {
|
|
89
|
+
liveTimers = (await client.vefaas.listTriggers(functionId))
|
|
90
|
+
.filter((trigger) => trigger.sourceType?.toLowerCase() === 'timer' &&
|
|
91
|
+
trigger.name &&
|
|
92
|
+
parseVefaasTimerSource(trigger.source))
|
|
93
|
+
.map((trigger) => ({
|
|
94
|
+
id: trigger.id,
|
|
95
|
+
name: trigger.name,
|
|
96
|
+
config: parseVefaasTimerSource(trigger.source),
|
|
97
|
+
}));
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
liveAvailable = false;
|
|
101
|
+
logger_1.logger.warn(lang_1.lang.__('PLAN_TIMER_TRIGGER_PROBE_FAILED', { functionName: fn.name, error: String(error) }));
|
|
102
|
+
}
|
|
103
|
+
const baseline = liveAvailable
|
|
104
|
+
? liveTimers
|
|
105
|
+
: previousTimers.flatMap((instance) => {
|
|
106
|
+
const config = vefaasTimerConfigFromAttributes(instance.attributes ?? {});
|
|
107
|
+
return config ? [{ id: undefined, name: instance.id, config }] : [];
|
|
108
|
+
});
|
|
109
|
+
const resultingInstances = [];
|
|
110
|
+
for (const timer of desiredTimers) {
|
|
111
|
+
const desiredSource = buildVefaasTimerTriggerSource(timer);
|
|
112
|
+
const live = baseline.find((entry) => entry.name === timer.name);
|
|
113
|
+
if (!live) {
|
|
114
|
+
logger_1.logger.info(lang_1.lang.__('CREATING_TIMER_TRIGGER', { triggerName: timer.name, functionName: fn.name }));
|
|
115
|
+
}
|
|
116
|
+
else if (!(0, common_1.attributesEqual)(live.config, desiredSource)) {
|
|
117
|
+
logger_1.logger.info(lang_1.lang.__('UPDATING_TIMER_TRIGGER', { triggerName: timer.name, functionName: fn.name }));
|
|
118
|
+
if (live.id) {
|
|
119
|
+
try {
|
|
120
|
+
await client.vefaas.deleteTrigger(functionId, live.id);
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
const errorCode = error?.code;
|
|
124
|
+
if (errorCode !== 'FunctionNotFound' && errorCode !== 'ResourceNotFound')
|
|
125
|
+
throw error;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
resultingInstances.push(buildVefaasTimerTriggerInstance(context, fn, timer));
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
try {
|
|
134
|
+
await client.vefaas.createTrigger({
|
|
135
|
+
functionId,
|
|
136
|
+
name: timer.name,
|
|
137
|
+
source: desiredSource,
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
// a leftover trigger from an adopted function may already carry the name
|
|
142
|
+
if (!(0, alreadyExists_1.isResourceAlreadyExistsError)(error, VEFAAS_ALREADY_EXISTS_CODES))
|
|
143
|
+
throw error;
|
|
144
|
+
logger_1.logger.warn(lang_1.lang.__('TIMER_TRIGGER_ALREADY_ATTACHED', {
|
|
145
|
+
triggerName: timer.name,
|
|
146
|
+
functionName: fn.name,
|
|
147
|
+
}));
|
|
148
|
+
}
|
|
149
|
+
logger_1.logger.info(lang_1.lang.__('TIMER_TRIGGER_CREATED', { triggerName: timer.name, functionName: fn.name }));
|
|
150
|
+
resultingInstances.push(buildVefaasTimerTriggerInstance(context, fn, timer));
|
|
151
|
+
}
|
|
152
|
+
const desiredNames = new Set(desiredTimers.map((timer) => timer.name));
|
|
153
|
+
for (const stale of baseline.filter((entry) => !desiredNames.has(entry.name))) {
|
|
154
|
+
logger_1.logger.info(lang_1.lang.__('DELETING_TIMER_TRIGGER', { triggerName: stale.name, functionName: fn.name }));
|
|
155
|
+
if (stale.id) {
|
|
156
|
+
try {
|
|
157
|
+
await client.vefaas.deleteTrigger(functionId, stale.id);
|
|
158
|
+
logger_1.logger.info(lang_1.lang.__('TIMER_TRIGGER_DELETED', { triggerName: stale.name }));
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
const errorCode = error?.code;
|
|
162
|
+
if (errorCode !== 'FunctionNotFound' && errorCode !== 'ResourceNotFound')
|
|
163
|
+
throw error;
|
|
164
|
+
logger_1.logger.warn(lang_1.lang.__('TIMER_TRIGGER_NOT_FOUND', { triggerName: stale.name }));
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return resultingInstances;
|
|
169
|
+
};
|
|
15
170
|
const RECOVERY_GET_FUNCTION_DELAY_MS = 1500;
|
|
16
171
|
// volcengine role TRN format: trn:iam::{accountId}:role/{roleName}. Prefer the
|
|
17
172
|
// stored TRN; else construct from the known accountId, else fetch it via STS.
|
|
@@ -271,7 +426,7 @@ const deleteDependentResources = async (context, instances) => {
|
|
|
271
426
|
case 'VOLCENGINE_IAM_ROLE': {
|
|
272
427
|
const attrs = instance.attributes;
|
|
273
428
|
if (attrs?.external === true) {
|
|
274
|
-
logger_1.logger.info(
|
|
429
|
+
logger_1.logger.info(lang_1.lang.__('VOLC_EXTERNAL_ROLE_SKIP_DELETE', { roleName: instance.id }));
|
|
275
430
|
break;
|
|
276
431
|
}
|
|
277
432
|
logger_1.logger.info(lang_1.lang.__('DELETING_IAM_ROLE', { id: instance.id }));
|
|
@@ -374,7 +529,11 @@ const createResource = async (context, fn, state) => {
|
|
|
374
529
|
// a resource that was never ours).
|
|
375
530
|
const probe = await client.vefaas.getFunction(fn.name);
|
|
376
531
|
if (probe && (0, ownershipTag_1.isOwnedByStack)(context, logicalId, probe.Tags)) {
|
|
377
|
-
logger_1.logger.info(
|
|
532
|
+
logger_1.logger.info(lang_1.lang.__('RESOURCE_OWNERSHIP_TAG_ADOPT', {
|
|
533
|
+
resourceType: 'Function',
|
|
534
|
+
name: fn.name,
|
|
535
|
+
tag: ownershipTag_1.OWNERSHIP_TAG_KEY,
|
|
536
|
+
}));
|
|
378
537
|
}
|
|
379
538
|
else {
|
|
380
539
|
throw new types_1.PartialResourceError(stateAfterDependents, new Error(lang_1.lang.__('RESOURCE_EXISTS_NOT_OWNED_ADOPT', {
|
|
@@ -398,11 +557,21 @@ const createResource = async (context, fn, state) => {
|
|
|
398
557
|
if (releaseRecordId) {
|
|
399
558
|
vefaasInstance.releaseRecordId = releaseRecordId;
|
|
400
559
|
}
|
|
560
|
+
// Timer triggers bind to the function via FunctionId — reconcile after the
|
|
561
|
+
// function exists (fresh creates see an empty trigger list; adopted ones
|
|
562
|
+
// converge on leftovers).
|
|
563
|
+
const timerInstances = functionInfo.functionId
|
|
564
|
+
? await reconcileVefaasTimerTriggers(context, fn, functionInfo.functionId, [], client)
|
|
565
|
+
: [];
|
|
401
566
|
const resourceState = {
|
|
402
567
|
mode: 'managed',
|
|
403
568
|
region: context.region,
|
|
404
569
|
definition,
|
|
405
|
-
instances: [
|
|
570
|
+
instances: [
|
|
571
|
+
vefaasInstance,
|
|
572
|
+
...dependentInstances,
|
|
573
|
+
...timerInstances,
|
|
574
|
+
],
|
|
406
575
|
status: 'ready',
|
|
407
576
|
lastUpdated: new Date().toISOString(),
|
|
408
577
|
};
|
|
@@ -649,6 +818,8 @@ const updateResource = async (context, fn, state, options) => {
|
|
|
649
818
|
}
|
|
650
819
|
const existingDependentInstances = existingInstances
|
|
651
820
|
.filter((i) => i.type !== 'VOLCENGINE_VEFAAS_FUNCTION' &&
|
|
821
|
+
// timers are fully rebuilt from the reconcile result below
|
|
822
|
+
i.type !== TIMER_TRIGGER_INSTANCE_TYPE &&
|
|
652
823
|
(!!fn.log || !i.type.startsWith('VOLCENGINE_TLS_')))
|
|
653
824
|
.map((i) => {
|
|
654
825
|
const { sid: existingSid, id: existingId, ...rest } = i;
|
|
@@ -667,11 +838,21 @@ const updateResource = async (context, fn, state, options) => {
|
|
|
667
838
|
...(dep.trn ? { trn: dep.trn } : {}),
|
|
668
839
|
...dep.attributes,
|
|
669
840
|
}));
|
|
841
|
+
// Timer triggers reconcile against the live trigger list (issue #258);
|
|
842
|
+
// functionInfo above already carries the resolved function Id.
|
|
843
|
+
const timerInstances = functionInfo.functionId
|
|
844
|
+
? await reconcileVefaasTimerTriggers(context, fn, functionInfo.functionId, existingInstances, client)
|
|
845
|
+
: [];
|
|
670
846
|
const resourceState = {
|
|
671
847
|
mode: 'managed',
|
|
672
848
|
region: context.region,
|
|
673
849
|
definition: desiredDefinition,
|
|
674
|
-
instances: [
|
|
850
|
+
instances: [
|
|
851
|
+
vefaasInstance,
|
|
852
|
+
...existingDependentInstances,
|
|
853
|
+
...newDependentInstancesMapped,
|
|
854
|
+
...timerInstances,
|
|
855
|
+
],
|
|
675
856
|
status: 'ready',
|
|
676
857
|
lastUpdated: new Date().toISOString(),
|
|
677
858
|
};
|
|
@@ -684,6 +865,42 @@ const deleteResource = async (context, functionName, logicalId, state) => {
|
|
|
684
865
|
const vefaasInstance = existingInstances.find((i) => i.type === 'VOLCENGINE_VEFAAS_FUNCTION');
|
|
685
866
|
const functionId = vefaasInstance?.functionId;
|
|
686
867
|
const client = (0, volcengineClient_1.createVolcengineClient)(context);
|
|
868
|
+
// Delete timer triggers before the function (they hang off its FunctionId;
|
|
869
|
+
// si owns every timer on its function, so state-recorded ones all go).
|
|
870
|
+
const timerInstances = existingInstances.filter((i) => i.type === TIMER_TRIGGER_INSTANCE_TYPE);
|
|
871
|
+
if (functionId && timerInstances.length > 0) {
|
|
872
|
+
let liveTimerIds = [];
|
|
873
|
+
try {
|
|
874
|
+
liveTimerIds = await client.vefaas.listTriggers(functionId);
|
|
875
|
+
}
|
|
876
|
+
catch {
|
|
877
|
+
// probe failure must not block teardown — fall back to name lookup below
|
|
878
|
+
}
|
|
879
|
+
for (const timerInstance of timerInstances) {
|
|
880
|
+
logger_1.logger.info(lang_1.lang.__('DELETING_TIMER_TRIGGER', {
|
|
881
|
+
triggerName: timerInstance.id,
|
|
882
|
+
functionName,
|
|
883
|
+
}));
|
|
884
|
+
const liveId = liveTimerIds.find((t) => t.name === timerInstance.id)?.id ?? undefined;
|
|
885
|
+
if (!liveId) {
|
|
886
|
+
logger_1.logger.warn(lang_1.lang.__('TIMER_TRIGGER_NOT_FOUND', { triggerName: timerInstance.id }));
|
|
887
|
+
continue;
|
|
888
|
+
}
|
|
889
|
+
try {
|
|
890
|
+
await client.vefaas.deleteTrigger(functionId, liveId);
|
|
891
|
+
logger_1.logger.info(lang_1.lang.__('TIMER_TRIGGER_DELETED', { triggerName: timerInstance.id }));
|
|
892
|
+
}
|
|
893
|
+
catch (err) {
|
|
894
|
+
const errorCode = err?.code;
|
|
895
|
+
if (errorCode === 'FunctionNotFound' || errorCode === 'ResourceNotFound') {
|
|
896
|
+
logger_1.logger.warn(lang_1.lang.__('TIMER_TRIGGER_NOT_FOUND', { triggerName: timerInstance.id }));
|
|
897
|
+
}
|
|
898
|
+
else {
|
|
899
|
+
throw err;
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
}
|
|
687
904
|
if (functionId) {
|
|
688
905
|
try {
|
|
689
906
|
await client.vefaas.deleteFunction(functionId);
|
|
@@ -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,54 +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
|
+
},
|
|
111
|
+
// Target Console org (organizations.slug). Optional — required only when an
|
|
112
|
+
// explicit SaaS state backend is declared (allOf branch below); with
|
|
113
|
+
// LOCAL/BUCKET_STORE backends it is allowed but inert (decision D-6).
|
|
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
|
+
},
|
|
90
119
|
vars: {
|
|
91
120
|
type: 'object',
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
},
|
|
121
|
+
description: 'Reusable variables referenceable as ${vars.<key>} throughout the document.',
|
|
122
|
+
additionalProperties: templateRefSchema_1.scalarValue,
|
|
95
123
|
},
|
|
96
124
|
stages: {
|
|
97
125
|
type: 'object',
|
|
126
|
+
description: 'Per-stage variables referenceable as ${stages.<key>}, keyed by stage name.',
|
|
98
127
|
patternProperties: {
|
|
99
128
|
'.*': {
|
|
100
129
|
type: 'object',
|
|
101
|
-
additionalProperties:
|
|
102
|
-
type: ['string', 'number', 'boolean'],
|
|
103
|
-
},
|
|
130
|
+
additionalProperties: templateRefSchema_1.scalarValue,
|
|
104
131
|
},
|
|
105
132
|
},
|
|
106
133
|
},
|
|
107
134
|
tags: {
|
|
108
135
|
type: 'object',
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
},
|
|
136
|
+
description: 'Tags applied to every managed cloud resource.',
|
|
137
|
+
additionalProperties: templateRefSchema_1.scalarValue,
|
|
112
138
|
},
|
|
113
139
|
functions: {
|
|
140
|
+
description: 'Serverless function definitions keyed by logical id.',
|
|
114
141
|
$ref: 'https://serverlessinsight.geekfun.club/schemas/functionschema.json',
|
|
115
142
|
},
|
|
116
143
|
events: {
|
|
144
|
+
description: 'Event definitions (e.g. API_GATEWAY) keyed by logical id.',
|
|
117
145
|
$ref: 'https://serverlessinsight.geekfun.club/schemas/eventschema.json',
|
|
118
146
|
},
|
|
119
147
|
databases: {
|
|
148
|
+
description: 'Serverless database definitions keyed by logical id.',
|
|
120
149
|
$ref: 'https://serverlessinsight.geekfun.club/schemas/databaseschema.json',
|
|
121
150
|
},
|
|
122
151
|
buckets: {
|
|
152
|
+
description: 'Object-storage bucket definitions keyed by logical id.',
|
|
123
153
|
$ref: 'https://serverlessinsight.geekfun.club/schemas/bucketschema.json',
|
|
124
154
|
},
|
|
125
155
|
tables: {
|
|
156
|
+
description: 'Tablestore table definitions keyed by logical id.',
|
|
126
157
|
$ref: 'https://serverlessinsight.geekfun.club/schemas/tableschema.json',
|
|
127
158
|
},
|
|
128
159
|
backend: {
|
|
129
160
|
type: 'object',
|
|
161
|
+
description: 'Remote state backend configuration (defaults to the SaaS backend).',
|
|
130
162
|
properties: {
|
|
131
163
|
state_manager: {
|
|
132
164
|
type: 'object',
|
|
165
|
+
description: 'State storage: LOCAL directory, BUCKET_STORE, or the SaaS Console.',
|
|
133
166
|
properties: {
|
|
134
|
-
type: { type: 'string', enum: ['LOCAL', 'BUCKET_STORE'] },
|
|
135
|
-
bucket: { type: 'string' },
|
|
136
|
-
key: { type: 'string' },
|
|
167
|
+
type: { type: 'string', enum: ['LOCAL', 'BUCKET_STORE', 'SAAS'] },
|
|
168
|
+
bucket: { type: 'string', description: 'State bucket name (BUCKET_STORE only).' },
|
|
169
|
+
key: { type: 'string', description: 'State object key (BUCKET_STORE only).' },
|
|
137
170
|
},
|
|
138
171
|
required: ['type'],
|
|
139
172
|
additionalProperties: false,
|
|
@@ -144,5 +177,30 @@ exports.rootSchema = {
|
|
|
144
177
|
},
|
|
145
178
|
required: ['version', 'provider', 'app', 'service'],
|
|
146
179
|
additionalProperties: false,
|
|
147
|
-
allOf:
|
|
180
|
+
allOf: [
|
|
181
|
+
// Explicit SaaS state backend must declare the target org at top level.
|
|
182
|
+
// A missing backend block stays org-free (zero-config quick start — the
|
|
183
|
+
// API key decides the org there); every nested level needs its own
|
|
184
|
+
// `required` so the `if` can't match vacuously.
|
|
185
|
+
{
|
|
186
|
+
if: {
|
|
187
|
+
properties: {
|
|
188
|
+
backend: {
|
|
189
|
+
type: 'object',
|
|
190
|
+
properties: {
|
|
191
|
+
state_manager: {
|
|
192
|
+
type: 'object',
|
|
193
|
+
properties: { type: { const: 'SAAS' } },
|
|
194
|
+
required: ['type'],
|
|
195
|
+
},
|
|
196
|
+
},
|
|
197
|
+
required: ['state_manager'],
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
required: ['backend'],
|
|
201
|
+
},
|
|
202
|
+
then: { required: ['org'] },
|
|
203
|
+
},
|
|
204
|
+
...Object.entries(FUNCTION_NAME_MAX_LENGTH).map(([provider, maxLength]) => functionNameLimitBranch(provider, maxLength)),
|
|
205
|
+
],
|
|
148
206
|
};
|
|
@@ -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;
|