@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
|
@@ -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
|
};
|