@geek-fun/serverlessinsight 0.9.1 → 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 +76 -0
- package/README.zh-CN.md +67 -0
- 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 +75 -23
- package/dist/src/commands/plan.js +21 -1
- 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/fc3Operations.js +32 -1
- package/dist/src/common/constants.js +7 -1
- package/dist/src/common/jsonOutput.js +77 -0
- package/dist/src/common/logger.js +6 -3
- package/dist/src/common/noColor.js +9 -0
- package/dist/src/common/planFormatter.js +12 -6
- package/dist/src/common/siCron.js +415 -0
- package/dist/src/common/stateBackend/saasStateBackend.js +5 -4
- package/dist/src/common/tencentClient/scfOperations.js +2 -0
- package/dist/src/common/volcengineClient/vefaasOperations.js +45 -0
- package/dist/src/lang/en.js +43 -0
- package/dist/src/lang/index.js +36 -1
- package/dist/src/lang/zh-CN.js +43 -0
- package/dist/src/parser/functionParser.js +47 -1
- package/dist/src/stack/aliyunStack/fc3Planner.js +26 -0
- package/dist/src/stack/aliyunStack/fc3Resource.js +159 -2
- package/dist/src/stack/localStack/event.js +2 -13
- package/dist/src/stack/localStack/function.js +2 -13
- 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/scfPlanner.js +52 -18
- package/dist/src/stack/scfStack/scfResource.js +170 -1
- package/dist/src/stack/volcengineStack/vefaasPlanner.js +49 -0
- package/dist/src/stack/volcengineStack/vefaasResource.js +215 -2
- 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/samples/aliyun-poc-timer.yml +39 -0
|
@@ -1,9 +1,10 @@
|
|
|
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
4
|
const hashUtils_1 = require("./hashUtils");
|
|
5
5
|
const lang_1 = require("../lang");
|
|
6
6
|
const logger_1 = require("./logger");
|
|
7
|
+
const noColor_1 = require("./noColor");
|
|
7
8
|
const COLOR = {
|
|
8
9
|
RESET: '\x1b[0m',
|
|
9
10
|
GREEN: '\x1b[32m',
|
|
@@ -216,6 +217,7 @@ const ACTION_COLOR = {
|
|
|
216
217
|
* add/remove blocks (issue #246 resource-paradigm invariant).
|
|
217
218
|
*/
|
|
218
219
|
const isRecreate = (item) => item.action === 'create' && !!item.changes?.before;
|
|
220
|
+
exports.isRecreate = isRecreate;
|
|
219
221
|
/* istanbul ignore next */
|
|
220
222
|
const formatPlanItem = (item, config = DEFAULT_CONFIG) => {
|
|
221
223
|
if (item.action === 'noop') {
|
|
@@ -223,7 +225,7 @@ const formatPlanItem = (item, config = DEFAULT_CONFIG) => {
|
|
|
223
225
|
// the plan summary count (issue #246 display spec).
|
|
224
226
|
return '';
|
|
225
227
|
}
|
|
226
|
-
const recreate = isRecreate(item);
|
|
228
|
+
const recreate = (0, exports.isRecreate)(item);
|
|
227
229
|
const descKey = recreate ? 'PLAN_WILL_RECREATE' : (ACTION_DESC[item.action] ?? 'PLAN_NO_CHANGES');
|
|
228
230
|
const headerLine = ` # ${item.logicalId} ${lang_1.lang.__(descKey)}`;
|
|
229
231
|
const symbol = recreate ? '-/+' : (ACTION_SYMBOL[item.action] ?? ' ');
|
|
@@ -277,8 +279,8 @@ const formatPlan = (items, config = DEFAULT_CONFIG) => {
|
|
|
277
279
|
const block = (0, exports.formatPlanItem)(item, config);
|
|
278
280
|
return block ? [block, ''] : [];
|
|
279
281
|
});
|
|
280
|
-
const recreateCount = items.filter(isRecreate).length;
|
|
281
|
-
const addCount = items.filter((i) => i.action === 'create' && !isRecreate(i)).length;
|
|
282
|
+
const recreateCount = items.filter(exports.isRecreate).length;
|
|
283
|
+
const addCount = items.filter((i) => i.action === 'create' && !(0, exports.isRecreate)(i)).length;
|
|
282
284
|
const modifyCount = items.filter((i) => i.action === 'update').length;
|
|
283
285
|
const removeCount = items.filter((i) => i.action === 'delete').length;
|
|
284
286
|
const header = [`${lang_1.lang.__('PLAN_HEADER')}\n`];
|
|
@@ -293,8 +295,12 @@ const formatPlan = (items, config = DEFAULT_CONFIG) => {
|
|
|
293
295
|
};
|
|
294
296
|
exports.formatPlan = formatPlan;
|
|
295
297
|
/* istanbul ignore next */
|
|
296
|
-
const displayPlan = (planResult) => {
|
|
297
|
-
const output = (0, exports.formatPlan)(planResult.items
|
|
298
|
+
const displayPlan = (planResult, config) => {
|
|
299
|
+
const output = (0, exports.formatPlan)(planResult.items, {
|
|
300
|
+
...DEFAULT_CONFIG,
|
|
301
|
+
colorize: !(0, noColor_1.isNoColorEnabled)(),
|
|
302
|
+
...config,
|
|
303
|
+
});
|
|
298
304
|
logger_1.logger.info(output);
|
|
299
305
|
};
|
|
300
306
|
exports.displayPlan = displayPlan;
|
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.checkSiCronForProvider = exports.translateSiCron = exports.validateSiCron = exports.parseSiCron = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* si-cron — provider-agnostic cron syntax (issue #258).
|
|
6
|
+
*
|
|
7
|
+
* Grammar (decision D3; ALL fields are interpreted in UTC, decision D7):
|
|
8
|
+
* 5-field: minute hour day-of-month month day-of-week
|
|
9
|
+
* 6-field: second minute hour day-of-month month day-of-week
|
|
10
|
+
* '@every <duration>' — units s/m/h/d, compound sums allowed ('@every 90m')
|
|
11
|
+
*
|
|
12
|
+
* Dialects (synthesis layer; the schema-level `cron` field NEVER stores one):
|
|
13
|
+
* aliyun 6-field (second minute hour dom month dow)
|
|
14
|
+
* tencent 7-field (second minute hour dom month dow year)
|
|
15
|
+
* volcengine unix crontab 5-field (minute hour dom month dow)
|
|
16
|
+
*
|
|
17
|
+
* Aliyun/Tencent/Volcengine interpret cron expressions in UTC+8 (no DST), so
|
|
18
|
+
* translation applies a deterministic +8h field shift. Day-of-month and
|
|
19
|
+
* day-of-week only shift when an hour value crosses midnight (>= 16 UTC);
|
|
20
|
+
* crossings that cannot be shifted without changing which dates fire (month
|
|
21
|
+
* boundaries) throw instead of silently drifting the schedule.
|
|
22
|
+
*/
|
|
23
|
+
const lang_1 = require("../lang");
|
|
24
|
+
const MONTH_NAMES = {
|
|
25
|
+
jan: 1,
|
|
26
|
+
feb: 2,
|
|
27
|
+
mar: 3,
|
|
28
|
+
apr: 4,
|
|
29
|
+
may: 5,
|
|
30
|
+
jun: 6,
|
|
31
|
+
jul: 7,
|
|
32
|
+
aug: 8,
|
|
33
|
+
sep: 9,
|
|
34
|
+
oct: 10,
|
|
35
|
+
nov: 11,
|
|
36
|
+
dec: 12,
|
|
37
|
+
};
|
|
38
|
+
const DOW_NAMES = {
|
|
39
|
+
sun: 0,
|
|
40
|
+
mon: 1,
|
|
41
|
+
tue: 2,
|
|
42
|
+
wed: 3,
|
|
43
|
+
thu: 4,
|
|
44
|
+
fri: 5,
|
|
45
|
+
sat: 6,
|
|
46
|
+
};
|
|
47
|
+
const FIELD_SPECS = {
|
|
48
|
+
second: { min: 0, max: 59, domainMax: 59 },
|
|
49
|
+
minute: { min: 0, max: 59, domainMax: 59 },
|
|
50
|
+
hour: { min: 0, max: 23, domainMax: 23 },
|
|
51
|
+
dayOfMonth: { min: 1, max: 31, domainMax: 31 },
|
|
52
|
+
month: { min: 1, max: 12, domainMax: 12, cyclic: true, names: MONTH_NAMES },
|
|
53
|
+
dayOfWeek: { min: 0, max: 7, domainMax: 6, cyclic: true, names: DOW_NAMES },
|
|
54
|
+
};
|
|
55
|
+
const DAYS_IN_MONTH = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
56
|
+
/** si-cron is UTC-based; these providers interpret cron in UTC+8 (no DST). */
|
|
57
|
+
const UTC_PLUS_8 = 8;
|
|
58
|
+
const DURATION_UNIT_SECONDS = {
|
|
59
|
+
s: 1,
|
|
60
|
+
m: 60,
|
|
61
|
+
h: 3600,
|
|
62
|
+
d: 86400,
|
|
63
|
+
w: 604800,
|
|
64
|
+
};
|
|
65
|
+
const fieldError = (name, value) => new Error(lang_1.lang.__('SI_CRON_FIELD_INVALID', { field: name, value }));
|
|
66
|
+
/** Normalize one input value into the field's value domain (dow 7 -> 0). */
|
|
67
|
+
const parseValue = (token, name) => {
|
|
68
|
+
const spec = FIELD_SPECS[name];
|
|
69
|
+
const normalized = token.trim().toLowerCase();
|
|
70
|
+
const named = spec.names?.[normalized];
|
|
71
|
+
const value = named ?? Number(normalized);
|
|
72
|
+
if (!Number.isInteger(value) || normalized.length === 0) {
|
|
73
|
+
throw fieldError(name, token);
|
|
74
|
+
}
|
|
75
|
+
const canonical = name === 'dayOfWeek' && value === 7 ? 0 : value;
|
|
76
|
+
if (canonical < spec.min || canonical > spec.max) {
|
|
77
|
+
throw new Error(lang_1.lang.__('SI_CRON_FIELD_RANGE', {
|
|
78
|
+
field: name,
|
|
79
|
+
value: token,
|
|
80
|
+
min: String(spec.min),
|
|
81
|
+
max: String(spec.max),
|
|
82
|
+
}));
|
|
83
|
+
}
|
|
84
|
+
return canonical;
|
|
85
|
+
};
|
|
86
|
+
const parseStep = (token, name) => {
|
|
87
|
+
const step = Number(token);
|
|
88
|
+
const spec = FIELD_SPECS[name];
|
|
89
|
+
if (!Number.isInteger(step) || step < 1 || step > spec.domainMax - spec.min) {
|
|
90
|
+
throw new Error(lang_1.lang.__('SI_CRON_STEP_INVALID', { field: name, step: token }));
|
|
91
|
+
}
|
|
92
|
+
return step;
|
|
93
|
+
};
|
|
94
|
+
const wrapValue = (value, spec) => {
|
|
95
|
+
const span = spec.domainMax - spec.min + 1;
|
|
96
|
+
return ((((value - spec.min) % span) + span) % span) + spec.min;
|
|
97
|
+
};
|
|
98
|
+
const expandRange = (start, end, step, spec) => {
|
|
99
|
+
const values = [];
|
|
100
|
+
// non-cyclic fields walk monotonically — stepping past `end` must stop,
|
|
101
|
+
// never wrap around the domain (vixie semantics: 10-20/8 = {10, 18})
|
|
102
|
+
if (!spec.cyclic) {
|
|
103
|
+
for (let value = start; value <= end; value += step) {
|
|
104
|
+
values.push(value);
|
|
105
|
+
}
|
|
106
|
+
return values;
|
|
107
|
+
}
|
|
108
|
+
const span = spec.domainMax - spec.min + 1;
|
|
109
|
+
let current = start;
|
|
110
|
+
for (let guard = 0; guard < span; guard += 1) {
|
|
111
|
+
values.push(current);
|
|
112
|
+
if (current === end) {
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
const next = wrapValue(current + step, spec);
|
|
116
|
+
if (next === start) {
|
|
117
|
+
break; // wrapped past `end` — the full cycle has been collected
|
|
118
|
+
}
|
|
119
|
+
current = next;
|
|
120
|
+
}
|
|
121
|
+
return values;
|
|
122
|
+
};
|
|
123
|
+
const parseElement = (element, name) => {
|
|
124
|
+
const spec = FIELD_SPECS[name];
|
|
125
|
+
const slashParts = element.split('/');
|
|
126
|
+
if (slashParts.length > 2 || slashParts.some((part) => part.trim().length === 0)) {
|
|
127
|
+
throw fieldError(name, element);
|
|
128
|
+
}
|
|
129
|
+
const [rangePart, stepPart] = slashParts;
|
|
130
|
+
const step = stepPart !== undefined ? parseStep(stepPart, name) : 1;
|
|
131
|
+
const range = rangePart.trim();
|
|
132
|
+
if (range === '*') {
|
|
133
|
+
return expandRange(spec.min, spec.domainMax, step, spec);
|
|
134
|
+
}
|
|
135
|
+
const hyphenIndex = range.indexOf('-');
|
|
136
|
+
if (hyphenIndex < 0) {
|
|
137
|
+
return [parseValue(range, name)];
|
|
138
|
+
}
|
|
139
|
+
const start = parseValue(range.slice(0, hyphenIndex), name);
|
|
140
|
+
// dow range end 7 means the full weekly cycle, not a second Sunday
|
|
141
|
+
const endToken = range.slice(hyphenIndex + 1);
|
|
142
|
+
const end = name === 'dayOfWeek' && endToken.trim() === '7' ? 6 : parseValue(endToken, name);
|
|
143
|
+
if (start > end && !spec.cyclic) {
|
|
144
|
+
throw new Error(lang_1.lang.__('SI_CRON_RANGE_DESCENDING', { field: name, range }));
|
|
145
|
+
}
|
|
146
|
+
return expandRange(start, end, step, spec);
|
|
147
|
+
};
|
|
148
|
+
const parseField = (text, name) => {
|
|
149
|
+
const trimmed = text.trim();
|
|
150
|
+
if (trimmed.length === 0) {
|
|
151
|
+
throw new Error(lang_1.lang.__('SI_CRON_FIELD_EMPTY', { field: name }));
|
|
152
|
+
}
|
|
153
|
+
if (trimmed === '*') {
|
|
154
|
+
return { wildcard: true, values: [], text: trimmed };
|
|
155
|
+
}
|
|
156
|
+
const values = Array.from(new Set(trimmed.split(',').flatMap((e) => parseElement(e, name)))).sort((a, b) => a - b);
|
|
157
|
+
if (values.length === 0) {
|
|
158
|
+
throw fieldError(name, text);
|
|
159
|
+
}
|
|
160
|
+
return { wildcard: false, values, text: trimmed };
|
|
161
|
+
};
|
|
162
|
+
const EVERY_PATTERN = /^@every\s+((?:\d+\s*[smhdw]\s*)+)$/i;
|
|
163
|
+
const parseEveryDuration = (text) => {
|
|
164
|
+
const match = EVERY_PATTERN.exec(text.trim());
|
|
165
|
+
if (!match) {
|
|
166
|
+
throw new Error(lang_1.lang.__('SI_CRON_EVERY_INVALID', { duration: text.trim() }));
|
|
167
|
+
}
|
|
168
|
+
const totalSeconds = Array.from(match[1].matchAll(/(\d+)\s*([smhdw])/gi)).reduce((sum, [, amount, unit]) => sum + Number(amount) * DURATION_UNIT_SECONDS[unit.toLowerCase()], 0);
|
|
169
|
+
if (totalSeconds <= 0) {
|
|
170
|
+
throw new Error(lang_1.lang.__('SI_CRON_EVERY_INVALID', { duration: text.trim() }));
|
|
171
|
+
}
|
|
172
|
+
return totalSeconds;
|
|
173
|
+
};
|
|
174
|
+
/**
|
|
175
|
+
* Parse and validate an si-cron expression. Throws an i18n Error describing
|
|
176
|
+
* the first problem — run during parse (fail fast) and semantic validation
|
|
177
|
+
* (pre-deploy UX).
|
|
178
|
+
*/
|
|
179
|
+
const parseSiCron = (expression) => {
|
|
180
|
+
const trimmed = expression.trim().replace(/\s+/g, ' ');
|
|
181
|
+
if (trimmed.length === 0) {
|
|
182
|
+
throw new Error(lang_1.lang.__('SI_CRON_EMPTY'));
|
|
183
|
+
}
|
|
184
|
+
if (trimmed.toLowerCase().startsWith('@every')) {
|
|
185
|
+
return { kind: 'every', totalSeconds: parseEveryDuration(trimmed) };
|
|
186
|
+
}
|
|
187
|
+
const parts = trimmed.split(' ');
|
|
188
|
+
const hasSeconds = parts.length === 6;
|
|
189
|
+
if (parts.length !== 5 && parts.length !== 6) {
|
|
190
|
+
throw new Error(lang_1.lang.__('SI_CRON_WRONG_FIELD_COUNT', { count: String(parts.length) }));
|
|
191
|
+
}
|
|
192
|
+
// 6-field prefixes the seconds domain: minute/hour/... start at parts[1]
|
|
193
|
+
const [secondPart, minute, hour, dayOfMonth, month, dayOfWeek] = hasSeconds
|
|
194
|
+
? parts
|
|
195
|
+
: ['0', ...parts];
|
|
196
|
+
const fields = {
|
|
197
|
+
second: parseField(secondPart, 'second'),
|
|
198
|
+
minute: parseField(minute, 'minute'),
|
|
199
|
+
hour: parseField(hour, 'hour'),
|
|
200
|
+
dayOfMonth: parseField(dayOfMonth, 'dayOfMonth'),
|
|
201
|
+
month: parseField(month, 'month'),
|
|
202
|
+
dayOfWeek: parseField(dayOfWeek, 'dayOfWeek'),
|
|
203
|
+
};
|
|
204
|
+
return { kind: 'cron', hasSeconds, fields };
|
|
205
|
+
};
|
|
206
|
+
exports.parseSiCron = parseSiCron;
|
|
207
|
+
/** Validate only — throws when the expression is not valid si-cron. */
|
|
208
|
+
const validateSiCron = (expression) => {
|
|
209
|
+
(0, exports.parseSiCron)(expression);
|
|
210
|
+
};
|
|
211
|
+
exports.validateSiCron = validateSiCron;
|
|
212
|
+
const encodeNumbers = (values, spec) => {
|
|
213
|
+
const sorted = Array.from(new Set(values)).sort((a, b) => a - b);
|
|
214
|
+
if (sorted.length === spec.domainMax - spec.min + 1 &&
|
|
215
|
+
sorted.every((value, index) => value === spec.min + index)) {
|
|
216
|
+
return '*';
|
|
217
|
+
}
|
|
218
|
+
const runs = [];
|
|
219
|
+
let runStart = sorted[0];
|
|
220
|
+
let previous = sorted[0];
|
|
221
|
+
for (const value of sorted.slice(1)) {
|
|
222
|
+
if (value === previous + 1) {
|
|
223
|
+
previous = value;
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
runs.push(runStart === previous ? `${runStart}` : `${runStart}-${previous}`);
|
|
227
|
+
runStart = value;
|
|
228
|
+
previous = value;
|
|
229
|
+
}
|
|
230
|
+
runs.push(runStart === previous ? `${runStart}` : `${runStart}-${previous}`);
|
|
231
|
+
return runs.join(',');
|
|
232
|
+
};
|
|
233
|
+
const field = (values, spec) => ({
|
|
234
|
+
wildcard: false,
|
|
235
|
+
values,
|
|
236
|
+
text: encodeNumbers(values, spec),
|
|
237
|
+
});
|
|
238
|
+
/**
|
|
239
|
+
* Shift a parsed si-cron (UTC) into the UTC+8 field space the CN providers
|
|
240
|
+
* use. Hours wrap mod 24; when an hour value crosses midnight (>= 16 UTC) the
|
|
241
|
+
* day fields shift one day forward — but only where that is lossless.
|
|
242
|
+
* Month-boundary crossings throw (SI_CRON_SHIFT_UNSUPPORTED) rather than
|
|
243
|
+
* silently changing which dates fire.
|
|
244
|
+
*/
|
|
245
|
+
const shiftToUtcPlus8 = (fields, expression) => {
|
|
246
|
+
const hour = fields.hour;
|
|
247
|
+
if (hour.wildcard) {
|
|
248
|
+
return fields;
|
|
249
|
+
}
|
|
250
|
+
const crossing = hour.values.some((value) => value >= 24 - UTC_PLUS_8);
|
|
251
|
+
const shiftedHour = field(hour.values.map((value) => (value + UTC_PLUS_8) % 24), FIELD_SPECS.hour);
|
|
252
|
+
if (!crossing) {
|
|
253
|
+
return { ...fields, hour: shiftedHour };
|
|
254
|
+
}
|
|
255
|
+
const { dayOfMonth: dom, dayOfWeek: dow, month } = fields;
|
|
256
|
+
if (dom.wildcard && dow.wildcard) {
|
|
257
|
+
// daily schedule — the day rollover is absorbed by the wildcards
|
|
258
|
+
return { ...fields, hour: shiftedHour };
|
|
259
|
+
}
|
|
260
|
+
if (dom.wildcard && !dow.wildcard) {
|
|
261
|
+
// day-of-week cycles weekly: shifting +1 day is always lossless
|
|
262
|
+
return {
|
|
263
|
+
...fields,
|
|
264
|
+
hour: shiftedHour,
|
|
265
|
+
dayOfWeek: field(dow.values.map((value) => (value + 1) % 7), FIELD_SPECS.dayOfWeek),
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
if (!dom.wildcard && dow.wildcard) {
|
|
269
|
+
const shiftedDays = dom.values.map((value) => value + 1);
|
|
270
|
+
const maxAllowed = month.wildcard
|
|
271
|
+
? 28
|
|
272
|
+
: month.values.length === 1
|
|
273
|
+
? DAYS_IN_MONTH[month.values[0] - 1]
|
|
274
|
+
: undefined;
|
|
275
|
+
if (maxAllowed !== undefined && shiftedDays.every((value) => value <= maxAllowed)) {
|
|
276
|
+
return {
|
|
277
|
+
...fields,
|
|
278
|
+
hour: shiftedHour,
|
|
279
|
+
dayOfMonth: field(shiftedDays, FIELD_SPECS.dayOfMonth),
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
// month-end crossing with a single concrete day+month is unambiguous:
|
|
283
|
+
// Jan 31 20:00 UTC === Feb 1 04:00 UTC+8
|
|
284
|
+
const singleMonth = month.wildcard
|
|
285
|
+
? undefined
|
|
286
|
+
: month.values.length === 1
|
|
287
|
+
? month.values[0]
|
|
288
|
+
: undefined;
|
|
289
|
+
if (singleMonth !== undefined &&
|
|
290
|
+
dom.values.length === 1 &&
|
|
291
|
+
dom.values[0] === DAYS_IN_MONTH[singleMonth - 1]) {
|
|
292
|
+
const nextMonth = (singleMonth % 12) + 1;
|
|
293
|
+
return {
|
|
294
|
+
...fields,
|
|
295
|
+
hour: shiftedHour,
|
|
296
|
+
dayOfMonth: field([1], FIELD_SPECS.dayOfMonth),
|
|
297
|
+
month: field([nextMonth], FIELD_SPECS.month),
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
throw new Error(lang_1.lang.__('SI_CRON_SHIFT_UNSUPPORTED', { cron: expression }));
|
|
301
|
+
}
|
|
302
|
+
// both day-of-month and day-of-week restricted — the OR semantics plus the
|
|
303
|
+
// day shift cannot be expressed as one expression
|
|
304
|
+
throw new Error(lang_1.lang.__('SI_CRON_SHIFT_UNSUPPORTED', { cron: expression }));
|
|
305
|
+
};
|
|
306
|
+
const DOW_SPEC = FIELD_SPECS.dayOfWeek;
|
|
307
|
+
const passthroughField = (parsed, name) => {
|
|
308
|
+
// normalize the non-canonical Sunday spelling `7` so providers that only
|
|
309
|
+
// accept 0-6 keep the intended day
|
|
310
|
+
if (name === 'dayOfWeek' && /(^|[,\-/])7(?=$|[,\-/])/.test(parsed.text)) {
|
|
311
|
+
return encodeNumbers(parsed.values, DOW_SPEC);
|
|
312
|
+
}
|
|
313
|
+
return parsed.text;
|
|
314
|
+
};
|
|
315
|
+
const asText = (parsed, name) => parsed.wildcard ? '*' : passthroughField(parsed, name);
|
|
316
|
+
const everyDialectError = (dialect) => new Error(lang_1.lang.__('SI_CRON_EVERY_NOT_EXPRESSIBLE', { dialect }));
|
|
317
|
+
/**
|
|
318
|
+
* Translate `@every <duration>` into a provider step expression. Cron is
|
|
319
|
+
* calendar-anchored, so only durations that divide a calendar field evenly
|
|
320
|
+
* are expressible; the anchor is UTC midnight (intervals are anchor-free, so
|
|
321
|
+
* no UTC+8 shift applies).
|
|
322
|
+
*/
|
|
323
|
+
const translateEvery = (totalSeconds, dialect) => {
|
|
324
|
+
const year = dialect === 'tencent' ? ' *' : '';
|
|
325
|
+
const sixField = dialect !== 'volcengine';
|
|
326
|
+
const assemble = (fields) => sixField ? `${fields.join(' ')}${year}` : fields.slice(1).join(' ');
|
|
327
|
+
if (totalSeconds < 60) {
|
|
328
|
+
if (!sixField || 60 % totalSeconds !== 0) {
|
|
329
|
+
throw everyDialectError(dialect);
|
|
330
|
+
}
|
|
331
|
+
return assemble([`*/${totalSeconds}`, '*', '*', '*', '*', '*']);
|
|
332
|
+
}
|
|
333
|
+
if (totalSeconds % 86400 === 0) {
|
|
334
|
+
const days = totalSeconds / 86400;
|
|
335
|
+
if (days === 7) {
|
|
336
|
+
// weekly — anchored to Monday 00:00 (interval-preserving approximation)
|
|
337
|
+
return assemble(['0', '0', '0', '*', '*', '1']);
|
|
338
|
+
}
|
|
339
|
+
return assemble(['0', '0', '0', days === 1 ? '*' : `*/${days}`, '*', '*']);
|
|
340
|
+
}
|
|
341
|
+
if (totalSeconds % 3600 === 0) {
|
|
342
|
+
const hours = totalSeconds / 3600;
|
|
343
|
+
if (24 % hours !== 0) {
|
|
344
|
+
throw everyDialectError(dialect);
|
|
345
|
+
}
|
|
346
|
+
return assemble(['0', '0', hours === 1 ? '*' : `*/${hours}`, '*', '*', '*']);
|
|
347
|
+
}
|
|
348
|
+
if (totalSeconds % 60 === 0) {
|
|
349
|
+
const minutes = totalSeconds / 60;
|
|
350
|
+
if (60 % minutes !== 0) {
|
|
351
|
+
throw everyDialectError(dialect);
|
|
352
|
+
}
|
|
353
|
+
return assemble(['0', minutes === 1 ? '*' : `*/${minutes}`, '*', '*', '*', '*']);
|
|
354
|
+
}
|
|
355
|
+
throw everyDialectError(dialect);
|
|
356
|
+
};
|
|
357
|
+
/**
|
|
358
|
+
* Translate an si-cron expression into a provider cron dialect.
|
|
359
|
+
* Throws on invalid si-cron, or when the schedule cannot be represented in
|
|
360
|
+
* the target dialect without changing when it fires.
|
|
361
|
+
*/
|
|
362
|
+
const translateSiCron = (expression, dialect) => {
|
|
363
|
+
const parsed = (0, exports.parseSiCron)(expression);
|
|
364
|
+
if (parsed.kind === 'every') {
|
|
365
|
+
return translateEvery(parsed.totalSeconds, dialect);
|
|
366
|
+
}
|
|
367
|
+
if (dialect === 'volcengine') {
|
|
368
|
+
// unix crontab has no seconds field: only a single 0 second is expressible
|
|
369
|
+
const second = parsed.fields.second;
|
|
370
|
+
if (second.wildcard || second.values.length !== 1 || second.values[0] !== 0) {
|
|
371
|
+
throw new Error(lang_1.lang.__('SI_CRON_SECONDS_UNSUPPORTED', { cron: expression }));
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
const shifted = shiftToUtcPlus8(parsed.fields, expression);
|
|
375
|
+
const base = [
|
|
376
|
+
asText(shifted.minute, 'minute'),
|
|
377
|
+
asText(shifted.hour, 'hour'),
|
|
378
|
+
asText(shifted.dayOfMonth, 'dayOfMonth'),
|
|
379
|
+
asText(shifted.month, 'month'),
|
|
380
|
+
asText(shifted.dayOfWeek, 'dayOfWeek'),
|
|
381
|
+
];
|
|
382
|
+
if (dialect === 'volcengine') {
|
|
383
|
+
return base.join(' ');
|
|
384
|
+
}
|
|
385
|
+
const secondsText = parsed.hasSeconds ? asText(shifted.second, 'second') : '0';
|
|
386
|
+
const sixField = [secondsText, ...base].join(' ');
|
|
387
|
+
return dialect === 'tencent' ? `${sixField} *` : sixField;
|
|
388
|
+
};
|
|
389
|
+
exports.translateSiCron = translateSiCron;
|
|
390
|
+
const DIALECT_BY_PROVIDER = {
|
|
391
|
+
aliyun: 'aliyun',
|
|
392
|
+
tencent: 'tencent',
|
|
393
|
+
volcengine: 'volcengine',
|
|
394
|
+
};
|
|
395
|
+
/**
|
|
396
|
+
* Combined pre-deploy check for semantic validation: parse errors and
|
|
397
|
+
* provider expressibility problems both surface as the returned message
|
|
398
|
+
* (i18n); null means the expression is usable on the provider.
|
|
399
|
+
*/
|
|
400
|
+
const checkSiCronForProvider = (expression, provider) => {
|
|
401
|
+
try {
|
|
402
|
+
const dialect = DIALECT_BY_PROVIDER[provider];
|
|
403
|
+
if (!dialect) {
|
|
404
|
+
// Huawei FunctionGraph timers arrive with provider issue #19 — the
|
|
405
|
+
// capability gaps (e.g. no custom payload) surface in validate, not here.
|
|
406
|
+
return lang_1.lang.__('TIMER_TRIGGER_NOT_SUPPORTED_PROVIDER', { provider });
|
|
407
|
+
}
|
|
408
|
+
(0, exports.translateSiCron)(expression, dialect);
|
|
409
|
+
return null;
|
|
410
|
+
}
|
|
411
|
+
catch (error) {
|
|
412
|
+
return error instanceof Error ? error.message : String(error);
|
|
413
|
+
}
|
|
414
|
+
};
|
|
415
|
+
exports.checkSiCronForProvider = checkSiCronForProvider;
|
|
@@ -24,7 +24,7 @@ const createSaasStateBackend = (context, options) => {
|
|
|
24
24
|
const creds = (0, credentialStore_1.loadCredentials)();
|
|
25
25
|
const apiKey = options?.apiKey || creds?.apiKey;
|
|
26
26
|
const consoleUrl = (0, credentialStore_1.getConsoleUrl)();
|
|
27
|
-
|
|
27
|
+
let knownOrgId = creds?.orgId ?? '';
|
|
28
28
|
if (!apiKey) {
|
|
29
29
|
throw new Error(lang_1.lang.__('SAAS_BACKEND_NO_CREDENTIALS'));
|
|
30
30
|
}
|
|
@@ -42,7 +42,7 @@ const createSaasStateBackend = (context, options) => {
|
|
|
42
42
|
const client = (0, apiClient_1.createApiClient)({
|
|
43
43
|
apiKey,
|
|
44
44
|
baseUrl: consoleUrl,
|
|
45
|
-
orgId,
|
|
45
|
+
orgId: knownOrgId,
|
|
46
46
|
});
|
|
47
47
|
let currentDeploymentId = null;
|
|
48
48
|
let currentStage = null;
|
|
@@ -107,6 +107,7 @@ const createSaasStateBackend = (context, options) => {
|
|
|
107
107
|
orgId: local.orgId ?? fetched.orgId,
|
|
108
108
|
orgSlug: local.orgSlug ?? fetched.orgSlug,
|
|
109
109
|
};
|
|
110
|
+
knownOrgId = resolvedIdentity.orgId ?? knownOrgId;
|
|
110
111
|
}
|
|
111
112
|
catch {
|
|
112
113
|
resolvedIdentity = local;
|
|
@@ -183,7 +184,7 @@ const createSaasStateBackend = (context, options) => {
|
|
|
183
184
|
return {
|
|
184
185
|
...migrated,
|
|
185
186
|
resources,
|
|
186
|
-
orgId,
|
|
187
|
+
orgId: knownOrgId,
|
|
187
188
|
appId: resolvedAppId,
|
|
188
189
|
serviceId: resolvedServiceId,
|
|
189
190
|
};
|
|
@@ -198,7 +199,7 @@ const createSaasStateBackend = (context, options) => {
|
|
|
198
199
|
const defaultState = getDefaultState(provider, app, service);
|
|
199
200
|
return {
|
|
200
201
|
...defaultState,
|
|
201
|
-
orgId,
|
|
202
|
+
orgId: knownOrgId,
|
|
202
203
|
appId: resolvedAppId,
|
|
203
204
|
serviceId: resolvedServiceId,
|
|
204
205
|
};
|
|
@@ -212,6 +212,8 @@ const createScfOperations = (scfClient, deps) => {
|
|
|
212
212
|
...(params.TriggerDesc ? { TriggerDesc: params.TriggerDesc } : {}),
|
|
213
213
|
...(params.Qualifier ? { Qualifier: params.Qualifier } : {}),
|
|
214
214
|
...(params.Enable ? { Enable: params.Enable } : {}),
|
|
215
|
+
...(params.CustomArgument !== undefined ? { CustomArgument: params.CustomArgument } : {}),
|
|
216
|
+
...(params.Description ? { Description: params.Description } : {}),
|
|
215
217
|
});
|
|
216
218
|
},
|
|
217
219
|
deleteTrigger: async (params) => {
|
|
@@ -598,6 +598,51 @@ const createVefaasOperations = (client) => {
|
|
|
598
598
|
lastModifiedTime: fn.LastUpdateTime,
|
|
599
599
|
}));
|
|
600
600
|
},
|
|
601
|
+
// veFaaS timer triggers (issue #258): CreateTrigger/ListTriggers/
|
|
602
|
+
// DeleteTrigger of the veFaaS OpenAPI (Version 2024-06-06). A timer
|
|
603
|
+
// trigger binds one function via FunctionId; the config travels as a JSON
|
|
604
|
+
// `Source` string with SourceType 'Timer' — unix 5-field crontab
|
|
605
|
+
// (translation handled in common/siCron, which rejects non-zero seconds).
|
|
606
|
+
createTrigger: async (params) => {
|
|
607
|
+
await client.fetchOpenAPI({
|
|
608
|
+
Action: 'CreateTrigger',
|
|
609
|
+
Version: '2024-06-06',
|
|
610
|
+
method: 'POST',
|
|
611
|
+
headers: { 'content-type': 'application/json' },
|
|
612
|
+
data: {
|
|
613
|
+
FunctionId: params.functionId,
|
|
614
|
+
Name: params.name,
|
|
615
|
+
SourceType: 'Timer',
|
|
616
|
+
Source: JSON.stringify(params.source),
|
|
617
|
+
},
|
|
618
|
+
});
|
|
619
|
+
},
|
|
620
|
+
listTriggers: async (functionId) => {
|
|
621
|
+
const response = await client.fetchOpenAPI({
|
|
622
|
+
Action: 'ListTriggers',
|
|
623
|
+
Version: '2024-06-06',
|
|
624
|
+
method: 'POST',
|
|
625
|
+
headers: { 'content-type': 'application/json' },
|
|
626
|
+
data: { FunctionId: functionId },
|
|
627
|
+
});
|
|
628
|
+
const result = (response.Result || {});
|
|
629
|
+
const items = (result.Triggers ?? result.Items ?? []);
|
|
630
|
+
return items.map((item) => ({
|
|
631
|
+
id: item.Id ?? item.TriggerId,
|
|
632
|
+
name: item.Name ?? item.TriggerName,
|
|
633
|
+
sourceType: item.SourceType,
|
|
634
|
+
source: item.Source,
|
|
635
|
+
}));
|
|
636
|
+
},
|
|
637
|
+
deleteTrigger: async (functionId, triggerId) => {
|
|
638
|
+
await client.fetchOpenAPI({
|
|
639
|
+
Action: 'DeleteTrigger',
|
|
640
|
+
Version: '2024-06-06',
|
|
641
|
+
method: 'POST',
|
|
642
|
+
headers: { 'content-type': 'application/json' },
|
|
643
|
+
data: { FunctionId: functionId, TriggerId: triggerId },
|
|
644
|
+
});
|
|
645
|
+
},
|
|
601
646
|
};
|
|
602
647
|
return operations;
|
|
603
648
|
};
|
package/dist/src/lang/en.js
CHANGED
|
@@ -49,6 +49,10 @@ exports.en = {
|
|
|
49
49
|
LOCAL_GATEWAY_ERROR: 'Local gateway error',
|
|
50
50
|
ERROR_STOPPING_LOCAL_SERVER: 'Error stopping localServer',
|
|
51
51
|
RUN_LOCAL_STARTING: 'run-local starting: stage={{stage}} debug={{debug}} watch={{watch}}',
|
|
52
|
+
LOCAL_TIMER_SCHEDULED: "Local timer '{{triggerName}}' scheduled for function '{{functionName}}' (cron: {{cron}}, UTC)",
|
|
53
|
+
LOCAL_TIMER_FIRED: "Local timer '{{triggerName}}' firing function '{{functionName}}'...",
|
|
54
|
+
LOCAL_TIMER_DISABLED: "Local timer '{{triggerName}}' is disabled (enable: false), skipping schedule",
|
|
55
|
+
LOCAL_TIMER_INVALID_CRON: "Local timer '{{triggerName}}' has invalid cron '{{cron}}', skipping schedule",
|
|
52
56
|
// Function execution
|
|
53
57
|
FUNCTION_REQUEST_RECEIVED: 'Function request received by local server -> {{method}} {{identifier}} ',
|
|
54
58
|
INVOKING_WORKER_WITH_EVENT_TYPE: 'Invoking worker with event type: {{eventType}} and context',
|
|
@@ -876,6 +880,37 @@ exports.en = {
|
|
|
876
880
|
EVENT_FLUSH_FAILED: 'Failed to flush deployment events for {{deploymentId}} ({{count}} events): {{error}}',
|
|
877
881
|
EVENT_REPLAY_FAILED: 'Failed to replay event queue file {{file}}: {{error}}',
|
|
878
882
|
INVALID_HTTP_TRIGGER_AUTH_TYPE: "Invalid HTTP trigger auth_type '{{authType}}'; must be 'public' or 'iam'",
|
|
883
|
+
// Timer trigger messages (issue #258)
|
|
884
|
+
TIMER_TRIGGER_NAME_REQUIRED: "Timer trigger on function '{{functionName}}' requires 'name'",
|
|
885
|
+
TIMER_TRIGGER_CRON_REQUIRED: "Timer trigger '{{name}}' requires 'cron'",
|
|
886
|
+
TIMER_TRIGGER_DUPLICATE_NAME: "Duplicate timer trigger name '{{name}}' on function '{{functionName}}'",
|
|
887
|
+
TIMER_TRIGGER_LIMIT_EXCEEDED: "Function '{{functionName}}' has {{count}} timer triggers; provider {{provider}} allows at most {{max}}",
|
|
888
|
+
SEMANTIC_TIMER_CRON_INVALID: "Timer trigger '{{name}}' on function '{{functionName}}' has invalid cron '{{cron}}': {{reason}}",
|
|
889
|
+
TIMER_TRIGGER_NOT_SUPPORTED_PROVIDER: "Timer triggers are not supported for provider '{{provider}}'",
|
|
890
|
+
TIMER_TRIGGER_PAYLOAD_NOT_SUPPORTED: "Timer trigger '{{name}}' on provider {{provider}} does not support 'payload'",
|
|
891
|
+
CREATING_TIMER_TRIGGER: "Creating timer trigger '{{triggerName}}' for function '{{functionName}}'...",
|
|
892
|
+
TIMER_TRIGGER_CREATED: "Timer trigger '{{triggerName}}' created for function '{{functionName}}'",
|
|
893
|
+
UPDATING_TIMER_TRIGGER: "Recreating timer trigger '{{triggerName}}' for function '{{functionName}}'...",
|
|
894
|
+
DELETING_TIMER_TRIGGER: "Deleting timer trigger '{{triggerName}}' for function '{{functionName}}'...",
|
|
895
|
+
TIMER_TRIGGER_DELETED: "Timer trigger '{{triggerName}}' deleted",
|
|
896
|
+
TIMER_TRIGGER_NOT_FOUND: "Timer trigger '{{triggerName}}' not found in provider, skipping delete",
|
|
897
|
+
TIMER_TRIGGER_ALREADY_ATTACHED: "Timer trigger '{{triggerName}}' is already attached to function '{{functionName}}', skipping create",
|
|
898
|
+
PLAN_DRIFT_TIMER_TRIGGER: 'Timer triggers changed in the cloud',
|
|
899
|
+
PLAN_TIMER_TRIGGER_PROBE_FAILED: "Failed to probe timer triggers for function '{{functionName}}': {{error}}",
|
|
900
|
+
// si-cron messages (issue #258)
|
|
901
|
+
SI_CRON_EMPTY: 'si-cron expression is empty',
|
|
902
|
+
SI_CRON_WRONG_FIELD_COUNT: 'expects 5 fields (minute hour day month weekday), 6 fields with a seconds prefix, or @every <duration>; got {{count}}',
|
|
903
|
+
SI_CRON_FIELD_INVALID: "field '{{field}}' has invalid value '{{value}}'",
|
|
904
|
+
SI_CRON_FIELD_EMPTY: "field '{{field}}' is empty",
|
|
905
|
+
SI_CRON_FIELD_RANGE: "field '{{field}}' value '{{value}}' out of range {{min}}-{{max}}",
|
|
906
|
+
SI_CRON_STEP_INVALID: "field '{{field}}' has invalid step '{{step}}'",
|
|
907
|
+
SI_CRON_RANGE_DESCENDING: "field '{{field}}' has descending range '{{range}}'",
|
|
908
|
+
SI_CRON_EVERY_INVALID: "'@every {{duration}}' is not a valid duration; use forms like '30s', '5m', '1h', '1d'",
|
|
909
|
+
SI_CRON_EVERY_NOT_EXPRESSIBLE: 'this @every interval cannot be expressed as a {{dialect}} cron; use durations that divide evenly (15s, 30s, 1m, 5m, 15m, 30m, 1h, 2h, 6h, 12h, 1d)',
|
|
910
|
+
SI_CRON_SHIFT_UNSUPPORTED: "cron '{{cron}}' cannot be shifted to UTC+8 without changing which dates fire; avoid day-of-month/day-of-week schedules with UTC hours >= 16 that cross a month boundary",
|
|
911
|
+
SI_CRON_SECONDS_UNSUPPORTED: "cron '{{cron}}' has non-zero seconds which a 5-field crontab provider does not support",
|
|
912
|
+
// Nested live-repair failures (issue #234 executor reconciles)
|
|
913
|
+
NESTED_REPAIR_FAILED: "Failed to repair nested resource '{{resource}}': {{error}}",
|
|
879
914
|
// ===== Issue #251: previously hardcoded messages (now i18n) =====
|
|
880
915
|
UNSUPPORTED_PROVIDER: 'Unsupported provider: {{provider}}',
|
|
881
916
|
FORCE_UNLOCK_NO_LOCATION_MODE: 'Not supported in no-location mode',
|
|
@@ -885,6 +920,7 @@ exports.en = {
|
|
|
885
920
|
SHOW_NO_RESOURCES: 'No resources found in state.',
|
|
886
921
|
SHOW_STATE_LOCATION: 'State location: {{stateLocation}}',
|
|
887
922
|
SHOW_BACKEND_REMOTE: 'Backend: Remote',
|
|
923
|
+
SHOW_BACKEND_SAAS: 'Console (SaaS state)',
|
|
888
924
|
SHOW_DEPLOY_HINT: 'To deploy resources, run: si deploy',
|
|
889
925
|
SHOW_HEADER_DEPLOYED: 'DEPLOYED RESOURCES',
|
|
890
926
|
SHOW_CATEGORY_HEADER: '📦 {{label}}',
|
|
@@ -1040,4 +1076,11 @@ exports.en = {
|
|
|
1040
1076
|
OPT_PARAMETER: 'override parameters',
|
|
1041
1077
|
OPT_DEBUG: 'enable debug mode',
|
|
1042
1078
|
OPT_WATCH: 'enable file watch',
|
|
1079
|
+
// ===== Issue #250: agent-friendly CLI surface =====
|
|
1080
|
+
CMD_SCHEMA_DESC: 'export the IaC JSON Schema used for validation (draft-07, self-contained)',
|
|
1081
|
+
OPT_SCHEMA_OUTPUT: 'write the JSON Schema to a file instead of stdout',
|
|
1082
|
+
OPT_JSON: 'output the result as machine-readable JSON to stdout (logs stay on stderr)',
|
|
1083
|
+
OPT_NO_COLOR: 'disable colored output (also honors the NO_COLOR environment variable)',
|
|
1084
|
+
SCHEMA_WRITTEN_TO: 'JSON Schema written to: {{path}}',
|
|
1085
|
+
ERROR_CODE: 'Error code: {{code}}',
|
|
1043
1086
|
};
|