@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
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildPlanJson = exports.buildPlanChange = exports.buildPlanSummary = exports.writeJson = exports.isJsonMode = exports.setJsonMode = exports.SHOW_JSON_VERSION = exports.VALIDATE_JSON_VERSION = exports.PLAN_JSON_VERSION = void 0;
|
|
4
|
+
const planFormatter_1 = require("./planFormatter");
|
|
5
|
+
/**
|
|
6
|
+
* Machine-readable output channel (issue #250): the `--json` surface of the CLI.
|
|
7
|
+
*
|
|
8
|
+
* Contract with agents:
|
|
9
|
+
* - logs (pino) go to stderr, JSON results go to stdout — a pipe of stdout is
|
|
10
|
+
* always a single JSON document (jq-parseable);
|
|
11
|
+
* - every envelope carries a version field (`planVersion` / `validateVersion` /
|
|
12
|
+
* `showVersion`) so consumers can pin a shape;
|
|
13
|
+
* - failures emit `{ error: { code, message } }` where `code` is the stable
|
|
14
|
+
* i18n key behind the message — locale changes never change the code.
|
|
15
|
+
*/
|
|
16
|
+
exports.PLAN_JSON_VERSION = 1;
|
|
17
|
+
exports.VALIDATE_JSON_VERSION = 1;
|
|
18
|
+
exports.SHOW_JSON_VERSION = 1;
|
|
19
|
+
let jsonMode = false;
|
|
20
|
+
const setJsonMode = (enabled) => {
|
|
21
|
+
jsonMode = enabled;
|
|
22
|
+
};
|
|
23
|
+
exports.setJsonMode = setJsonMode;
|
|
24
|
+
const isJsonMode = () => jsonMode;
|
|
25
|
+
exports.isJsonMode = isJsonMode;
|
|
26
|
+
const writeJson = (payload) => {
|
|
27
|
+
process.stdout.write(`${JSON.stringify(payload, null, 2)}\n`);
|
|
28
|
+
};
|
|
29
|
+
exports.writeJson = writeJson;
|
|
30
|
+
const buildPlanSummary = (items) => items.reduce((summary, item) => {
|
|
31
|
+
if (item.action === 'noop') {
|
|
32
|
+
return { ...summary, unchanged: summary.unchanged + 1 };
|
|
33
|
+
}
|
|
34
|
+
if (item.action === 'create') {
|
|
35
|
+
return (0, planFormatter_1.isRecreate)(item)
|
|
36
|
+
? { ...summary, recreate: summary.recreate + 1 }
|
|
37
|
+
: { ...summary, create: summary.create + 1 };
|
|
38
|
+
}
|
|
39
|
+
if (item.action === 'update') {
|
|
40
|
+
return { ...summary, update: summary.update + 1 };
|
|
41
|
+
}
|
|
42
|
+
return { ...summary, destroy: summary.destroy + 1 };
|
|
43
|
+
}, { create: 0, update: 0, destroy: 0, recreate: 0, unchanged: 0 });
|
|
44
|
+
exports.buildPlanSummary = buildPlanSummary;
|
|
45
|
+
const toPlanJsonAction = (item) => {
|
|
46
|
+
if (item.action === 'delete')
|
|
47
|
+
return 'destroy';
|
|
48
|
+
if (item.action === 'create' && (0, planFormatter_1.isRecreate)(item))
|
|
49
|
+
return 'recreate';
|
|
50
|
+
return item.action === 'update' ? 'update' : 'create';
|
|
51
|
+
};
|
|
52
|
+
const buildPlanChange = (item) => {
|
|
53
|
+
const attributes = item.changes
|
|
54
|
+
? (0, planFormatter_1.computeAttributeDiffs)(item.changes.before, item.changes.after).diffs
|
|
55
|
+
: [];
|
|
56
|
+
return {
|
|
57
|
+
logicalId: item.logicalId,
|
|
58
|
+
type: item.resourceType,
|
|
59
|
+
action: toPlanJsonAction(item),
|
|
60
|
+
attributes,
|
|
61
|
+
...(item.drifted ? { drifted: true } : {}),
|
|
62
|
+
...(item.driftReasons && item.driftReasons.length > 0
|
|
63
|
+
? { driftReasons: item.driftReasons }
|
|
64
|
+
: {}),
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
exports.buildPlanChange = buildPlanChange;
|
|
68
|
+
const buildPlanJson = (planResult, identity) => {
|
|
69
|
+
const items = planResult.items ?? [];
|
|
70
|
+
return {
|
|
71
|
+
planVersion: exports.PLAN_JSON_VERSION,
|
|
72
|
+
...identity,
|
|
73
|
+
changes: items.filter((item) => item.action !== 'noop').map(exports.buildPlanChange),
|
|
74
|
+
summary: (0, exports.buildPlanSummary)(items),
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
exports.buildPlanJson = buildPlanJson;
|
|
@@ -229,7 +229,7 @@ const forceUnlock = (statePath, lockId) => {
|
|
|
229
229
|
return false; // No lock to remove
|
|
230
230
|
}
|
|
231
231
|
if (existingLock.id !== lockId) {
|
|
232
|
-
throw new Error(
|
|
232
|
+
throw new Error(lang_1.lang.__('LOCK_ID_MISMATCH', { actualId: existingLock.id, providedId: lockId }));
|
|
233
233
|
}
|
|
234
234
|
removeLockFile(lockPath);
|
|
235
235
|
return true;
|
|
@@ -9,6 +9,7 @@ const pino_pretty_1 = __importDefault(require("pino-pretty"));
|
|
|
9
9
|
const child_process_1 = require("child_process");
|
|
10
10
|
const iconv_lite_1 = __importDefault(require("iconv-lite"));
|
|
11
11
|
const stream_1 = require("stream");
|
|
12
|
+
const noColor_1 = require("./noColor");
|
|
12
13
|
const CODE_PAGE_TO_ENCODING = {
|
|
13
14
|
932: 'shift_jis', // Japanese
|
|
14
15
|
936: 'gbk', // Simplified Chinese
|
|
@@ -71,7 +72,7 @@ class EncodingTransformStream extends stream_1.Writable {
|
|
|
71
72
|
super();
|
|
72
73
|
this.encoding = encoding;
|
|
73
74
|
this.formatLog = pino_pretty_1.default.prettyFactory({
|
|
74
|
-
colorize:
|
|
75
|
+
colorize: !(0, noColor_1.isNoColorEnabled)(),
|
|
75
76
|
translateTime: 'HH:MM:ss',
|
|
76
77
|
ignore: 'pid,hostname',
|
|
77
78
|
messageFormat: '{msg}',
|
|
@@ -81,11 +82,13 @@ class EncodingTransformStream extends stream_1.Writable {
|
|
|
81
82
|
try {
|
|
82
83
|
const stringChunk = typeof chunk === 'string' ? chunk : chunk.toString();
|
|
83
84
|
const formattedChunk = this.formatLog(stringChunk);
|
|
85
|
+
// Issue #250: logs go to stderr — stdout carries only command result
|
|
86
|
+
// data (--json payloads), so agents can pipe stdout straight to jq.
|
|
84
87
|
if (this.encoding !== 'utf8' && iconv_lite_1.default.encodingExists(this.encoding)) {
|
|
85
|
-
process.
|
|
88
|
+
process.stderr.write(iconv_lite_1.default.toEncoding(formattedChunk, 'utf8'));
|
|
86
89
|
}
|
|
87
90
|
else {
|
|
88
|
-
process.
|
|
91
|
+
process.stderr.write(formattedChunk);
|
|
89
92
|
}
|
|
90
93
|
callback();
|
|
91
94
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.enforceMigrationMarker = exports.isMigratedToSaas = exports.MANAGED_BY_SAAS = void 0;
|
|
4
|
+
const logger_1 = require("./logger");
|
|
5
|
+
const lang_1 = require("../lang");
|
|
6
|
+
/**
|
|
7
|
+
* Value written into the legacy state's top-level `managedBy` field once
|
|
8
|
+
* `si migrate` has copied the state to the Console (docs/state-migration-saas.md
|
|
9
|
+
* §6.3). The marker is just a new persisted version of the state — there is no
|
|
10
|
+
* separate tombstone mechanism.
|
|
11
|
+
*/
|
|
12
|
+
exports.MANAGED_BY_SAAS = 'saas';
|
|
13
|
+
/** True when the state has been migrated to (and is now owned by) the Console. */
|
|
14
|
+
const isMigratedToSaas = (state) => {
|
|
15
|
+
return state?.managedBy === exports.MANAGED_BY_SAAS;
|
|
16
|
+
};
|
|
17
|
+
exports.isMigratedToSaas = isMigratedToSaas;
|
|
18
|
+
/**
|
|
19
|
+
* Ownership handover check (decision D-4): after migration the Console is the
|
|
20
|
+
* single source of truth. Mutating commands (deploy/destroy) pass 'refuse' so
|
|
21
|
+
* a legacy-backend write attempt fails closed; read-only commands (plan/diff/
|
|
22
|
+
* show) pass 'warn'; `si migrate` itself passes 'off' (it must be able to read
|
|
23
|
+
* marked state for idempotent re-runs and --rollback).
|
|
24
|
+
*/
|
|
25
|
+
const enforceMigrationMarker = (state, action) => {
|
|
26
|
+
if (action === 'off' || !(0, exports.isMigratedToSaas)(state)) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (action === 'refuse') {
|
|
30
|
+
throw new Error(lang_1.lang.__('MIGRATION_MARKER_REFUSED'));
|
|
31
|
+
}
|
|
32
|
+
logger_1.logger.warn(lang_1.lang.__('MIGRATION_MARKER_WARN'));
|
|
33
|
+
};
|
|
34
|
+
exports.enforceMigrationMarker = enforceMigrationMarker;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isNoColorEnabled = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* no-color.org convention (issue #250): a NO_COLOR environment variable that
|
|
6
|
+
* is present and not an empty string disables ANSI color, regardless of value.
|
|
7
|
+
*/
|
|
8
|
+
const isNoColorEnabled = () => process.env.NO_COLOR !== undefined && process.env.NO_COLOR !== '';
|
|
9
|
+
exports.isNoColorEnabled = isNoColorEnabled;
|
|
@@ -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;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getSupportedRuntimes = exports.isRuntimeSupported = exports.mapRuntime = exports.StandardRuntime = void 0;
|
|
4
4
|
const providerEnum_1 = require("./providerEnum");
|
|
5
|
+
const lang_1 = require("../lang");
|
|
5
6
|
var StandardRuntime;
|
|
6
7
|
(function (StandardRuntime) {
|
|
7
8
|
StandardRuntime["NODEJS24"] = "nodejs24";
|
|
@@ -151,12 +152,15 @@ const runtimeMappings = {
|
|
|
151
152
|
const mapRuntime = (standardRuntime, provider) => {
|
|
152
153
|
const mapping = runtimeMappings[standardRuntime];
|
|
153
154
|
if (!mapping) {
|
|
154
|
-
throw new Error(
|
|
155
|
+
throw new Error(lang_1.lang.__('RUNTIME_UNSUPPORTED_STANDARD', { standardRuntime }));
|
|
155
156
|
}
|
|
156
157
|
const providerRuntime = mapping[provider];
|
|
157
158
|
if (!providerRuntime) {
|
|
158
|
-
throw new Error(
|
|
159
|
-
|
|
159
|
+
throw new Error(lang_1.lang.__('RUNTIME_NOT_SUPPORTED_FOR_PROVIDER', {
|
|
160
|
+
runtime: standardRuntime,
|
|
161
|
+
provider,
|
|
162
|
+
supportedProviders: Object.keys(mapping).join(', '),
|
|
163
|
+
}));
|
|
160
164
|
}
|
|
161
165
|
return providerRuntime;
|
|
162
166
|
};
|
|
@@ -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;
|
|
@@ -69,6 +69,6 @@ const createCosStorageAdapter = (config) => {
|
|
|
69
69
|
};
|
|
70
70
|
const createCosStateBackend = (config) => {
|
|
71
71
|
const adapter = createCosStorageAdapter(config);
|
|
72
|
-
return (0, remoteStateBackend_1.createRemoteStateBackend)(adapter, { key: config.key });
|
|
72
|
+
return (0, remoteStateBackend_1.createRemoteStateBackend)(adapter, { key: config.key, markerAction: config.markerAction });
|
|
73
73
|
};
|
|
74
74
|
exports.createCosStateBackend = createCosStateBackend;
|