@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.
Files changed (112) hide show
  1. package/.serverlessinsight/state-cdn-flow-app-cdn-flow-service.json.backup +1 -1
  2. package/.serverlessinsight/state-iam-test-app-iam-test-service.json.backup +2 -2
  3. package/.serverlessinsight/state-insight-poc-app-insight-poc-tencent.json.backup +2 -2
  4. package/.serverlessinsight/state-insight-poc-app-log-insight-poc-tencent-log.json.backup +3 -3
  5. package/.serverlessinsight/state-insight-poc-deploy-app-insight-poc-deploy.json.backup +4 -4
  6. package/.serverlessinsight/state-insight-poc-destroy-app-insight-poc-destroy.json.backup +1 -1
  7. package/.serverlessinsight/state-insight-poc-timer-app-insight-poc-timer.json.backup +109 -0
  8. package/.serverlessinsight/state-insight-volc-app-insight-volc.json.backup +2 -2
  9. package/.serverlessinsight/state-insight-volc-nested-app-insight-volc-nested.json.backup +3 -3
  10. package/.serverlessinsight/state-nested-drift-app-nested-drift-service.json.backup +2 -2
  11. package/.serverlessinsight/state-role-reconcile-test-app-role-reconcile-test-service.json.backup +3 -3
  12. package/CHANGELOG.md +17 -0
  13. package/README.md +78 -2
  14. package/README.zh-CN.md +69 -2
  15. package/codecov +0 -0
  16. package/codecov.SHA256SUM +1 -0
  17. package/codecov.SHA256SUM.sig +16 -0
  18. package/dist/package.json +2 -2
  19. package/dist/src/commands/deploy.js +9 -3
  20. package/dist/src/commands/destroy.js +8 -2
  21. package/dist/src/commands/forceUnlock.js +5 -5
  22. package/dist/src/commands/index.js +173 -85
  23. package/dist/src/commands/login.js +12 -1
  24. package/dist/src/commands/migrate.js +287 -0
  25. package/dist/src/commands/plan.js +28 -2
  26. package/dist/src/commands/schema.js +24 -0
  27. package/dist/src/commands/show.js +99 -33
  28. package/dist/src/commands/validate.js +34 -2
  29. package/dist/src/common/aliyunClient/apigwOperations.js +4 -4
  30. package/dist/src/common/aliyunClient/ecsOperations.js +22 -13
  31. package/dist/src/common/aliyunClient/fc3Operations.js +39 -4
  32. package/dist/src/common/aliyunClient/nasOperations.js +4 -3
  33. package/dist/src/common/aliyunClient/ossOperations.js +52 -8
  34. package/dist/src/common/aliyunClient/slsOperations.js +3 -2
  35. package/dist/src/common/aliyunClient/tablestoreOperations.js +22 -11
  36. package/dist/src/common/apiClient.js +22 -5
  37. package/dist/src/common/constants.js +7 -1
  38. package/dist/src/common/context.js +5 -4
  39. package/dist/src/common/jsonOutput.js +77 -0
  40. package/dist/src/common/lockManager.js +1 -1
  41. package/dist/src/common/logger.js +6 -3
  42. package/dist/src/common/migrationMarker.js +34 -0
  43. package/dist/src/common/noColor.js +9 -0
  44. package/dist/src/common/planFormatter.js +12 -6
  45. package/dist/src/common/runtimeMapper.js +7 -3
  46. package/dist/src/common/siCron.js +415 -0
  47. package/dist/src/common/stateBackend/cosStateBackend.js +1 -1
  48. package/dist/src/common/stateBackend/index.js +5 -2
  49. package/dist/src/common/stateBackend/localStateBackend.js +8 -2
  50. package/dist/src/common/stateBackend/ossStateBackend.js +1 -1
  51. package/dist/src/common/stateBackend/remoteStateBackend.js +19 -2
  52. package/dist/src/common/stateBackend/saasStateBackend.js +88 -9
  53. package/dist/src/common/stateManager.js +56 -5
  54. package/dist/src/common/tencentClient/cosOperations.js +1 -1
  55. package/dist/src/common/tencentClient/scfOperations.js +4 -1
  56. package/dist/src/common/volcengineClient/apigwOperations.js +2 -2
  57. package/dist/src/common/volcengineClient/index.js +6 -2
  58. package/dist/src/common/volcengineClient/vefaasOperations.js +48 -3
  59. package/dist/src/lang/en.js +254 -1
  60. package/dist/src/lang/index.js +36 -1
  61. package/dist/src/lang/zh-CN.js +253 -1
  62. package/dist/src/parser/functionParser.js +47 -1
  63. package/dist/src/parser/index.js +1 -1
  64. package/dist/src/stack/aliyunStack/apigwExecutor.js +2 -2
  65. package/dist/src/stack/aliyunStack/apigwResource.js +22 -10
  66. package/dist/src/stack/aliyunStack/databaseExecutor.js +5 -5
  67. package/dist/src/stack/aliyunStack/databasePlanner.js +2 -2
  68. package/dist/src/stack/aliyunStack/databaseResource.js +18 -10
  69. package/dist/src/stack/aliyunStack/esServerlessTypes.js +2 -1
  70. package/dist/src/stack/aliyunStack/fc3Executor.js +2 -2
  71. package/dist/src/stack/aliyunStack/fc3Planner.js +26 -0
  72. package/dist/src/stack/aliyunStack/fc3Resource.js +190 -13
  73. package/dist/src/stack/aliyunStack/ossExecutor.js +2 -2
  74. package/dist/src/stack/aliyunStack/ossResource.js +5 -1
  75. package/dist/src/stack/aliyunStack/rdsTypes.js +5 -1
  76. package/dist/src/stack/aliyunStack/tablestoreExecutor.js +2 -2
  77. package/dist/src/stack/aliyunStack/tablestoreResource.js +3 -3
  78. package/dist/src/stack/aliyunStack/tablestoreTypes.js +3 -2
  79. package/dist/src/stack/deploy.js +2 -3
  80. package/dist/src/stack/localStack/event.js +2 -13
  81. package/dist/src/stack/localStack/function.js +2 -13
  82. package/dist/src/stack/localStack/functionRunner.js +5 -4
  83. package/dist/src/stack/localStack/index.js +8 -1
  84. package/dist/src/stack/localStack/timer.js +162 -0
  85. package/dist/src/stack/localStack/utils.js +19 -1
  86. package/dist/src/stack/scfStack/cosExecutor.js +2 -2
  87. package/dist/src/stack/scfStack/cosResource.js +2 -2
  88. package/dist/src/stack/scfStack/esServerlessExecutor.js +5 -5
  89. package/dist/src/stack/scfStack/esServerlessResource.js +7 -3
  90. package/dist/src/stack/scfStack/esServerlessTypes.js +2 -1
  91. package/dist/src/stack/scfStack/scfExecutor.js +2 -2
  92. package/dist/src/stack/scfStack/scfPlanner.js +52 -18
  93. package/dist/src/stack/scfStack/scfResource.js +202 -12
  94. package/dist/src/stack/scfStack/tdsqlcExecutor.js +5 -5
  95. package/dist/src/stack/scfStack/tdsqlcResource.js +7 -3
  96. package/dist/src/stack/volcengineStack/apigwExecutor.js +2 -2
  97. package/dist/src/stack/volcengineStack/apigwResource.js +7 -4
  98. package/dist/src/stack/volcengineStack/tosExecutor.js +2 -2
  99. package/dist/src/stack/volcengineStack/tosResource.js +1 -1
  100. package/dist/src/stack/volcengineStack/vefaasExecutor.js +2 -2
  101. package/dist/src/stack/volcengineStack/vefaasPlanner.js +49 -0
  102. package/dist/src/stack/volcengineStack/vefaasResource.js +221 -4
  103. package/dist/src/validator/functionSchema.js +25 -2
  104. package/dist/src/validator/iacSchema.js +2 -1
  105. package/dist/src/validator/index.js +4 -1
  106. package/dist/src/validator/rootSchema.js +77 -19
  107. package/dist/src/validator/schemaExport.js +60 -0
  108. package/dist/src/validator/semanticValidation.js +79 -0
  109. package/dist/src/validator/templateRefSchema.js +9 -1
  110. package/dist/tsconfig.tsbuildinfo +1 -1
  111. package/package.json +2 -2
  112. package/samples/aliyun-poc-timer.yml +39 -0
@@ -10,7 +10,6 @@ const common_1 = require("../../common");
10
10
  const function_1 = require("./function");
11
11
  const aliyunFc_1 = require("./aliyunFc");
12
12
  const functionRunner_1 = require("./functionRunner");
13
- const node_path_1 = __importDefault(require("node:path"));
14
13
  const node_fs_1 = __importDefault(require("node:fs"));
15
14
  const utils_1 = require("./utils");
16
15
  const lang_1 = require("../../lang");
@@ -78,18 +77,8 @@ const servEvent = async (req, parsed, iac) => {
78
77
  let tempDir = null;
79
78
  try {
80
79
  const { event: aliyunEvent } = await (0, aliyunFc_1.transformToAliyunEvent)(req, parsed.url, parsed.query);
81
- const codePath = node_path_1.default.resolve(process.cwd(), backendDef.code.path);
82
- let codeDir;
83
- if (codePath.endsWith('.zip') && node_fs_1.default.existsSync(codePath)) {
84
- tempDir = await (0, utils_1.extractZipFile)(codePath);
85
- codeDir = tempDir;
86
- }
87
- else if (node_fs_1.default.existsSync(codePath) && node_fs_1.default.statSync(codePath).isDirectory()) {
88
- codeDir = codePath;
89
- }
90
- else {
91
- codeDir = node_path_1.default.dirname(codePath);
92
- }
80
+ const { codeDir, tempDir: resolvedTempDir } = await (0, utils_1.resolveCodeDir)(backendDef.code.path);
81
+ tempDir = resolvedTempDir;
93
82
  const funOptions = {
94
83
  codeDir,
95
84
  functionKey: backendDef.key,
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.functionsHandler = void 0;
7
7
  const common_1 = require("../../common");
8
8
  const functionRunner_1 = require("./functionRunner");
9
- const node_path_1 = __importDefault(require("node:path"));
10
9
  const node_fs_1 = __importDefault(require("node:fs"));
11
10
  const aliyunFc_1 = require("./aliyunFc");
12
11
  const utils_1 = require("./utils");
@@ -31,18 +30,8 @@ const functionsHandler = async (req, parsed, iac) => {
31
30
  }
32
31
  let tempDir = null;
33
32
  try {
34
- const codePath = node_path_1.default.resolve(process.cwd(), fcDef.code.path);
35
- let codeDir;
36
- if (codePath.endsWith('.zip') && node_fs_1.default.existsSync(codePath)) {
37
- tempDir = await (0, utils_1.extractZipFile)(codePath);
38
- codeDir = tempDir;
39
- }
40
- else if (node_fs_1.default.existsSync(codePath) && node_fs_1.default.statSync(codePath).isDirectory()) {
41
- codeDir = codePath;
42
- }
43
- else {
44
- codeDir = node_path_1.default.dirname(codePath);
45
- }
33
+ const { codeDir, tempDir: resolvedTempDir } = await (0, utils_1.resolveCodeDir)(fcDef.code.path);
34
+ tempDir = resolvedTempDir;
46
35
  const funOptions = {
47
36
  codeDir,
48
37
  functionKey: fcDef.key,
@@ -37,6 +37,7 @@ exports.invokeFunction = exports.runFunction = void 0;
37
37
  const node_fs_1 = require("node:fs");
38
38
  const node_path_1 = __importStar(require("node:path"));
39
39
  const node_url_1 = require("node:url");
40
+ const lang_1 = require("../../lang");
40
41
  const node_worker_threads_1 = require("node:worker_threads");
41
42
  // ============================================================================
42
43
  // Worker Thread Code (runs in worker context)
@@ -64,7 +65,7 @@ const loadHandlerModule = async (handlerPath) => {
64
65
  const getHandlerFunction = (handlerModule, handlerMethod, handlerPath) => {
65
66
  const handlerFn = handlerModule[handlerMethod];
66
67
  if (typeof handlerFn !== 'function') {
67
- throw new Error(`Handler "${handlerMethod}" not found or is not a function in ${handlerPath}`);
68
+ throw new Error(lang_1.lang.__('LOCAL_HANDLER_NOT_FOUND', { handlerMethod, handlerPath }));
68
69
  }
69
70
  return handlerFn;
70
71
  };
@@ -86,7 +87,7 @@ const invokeHandler = (handlerFn, event, context) => new Promise((resolve, rejec
86
87
  });
87
88
  const createTimeoutHandler = (port, timeoutMs) => {
88
89
  const timeoutId = setTimeout(() => {
89
- port.postMessage(new Error(`Function execution timed out after ${timeoutMs}ms`));
90
+ port.postMessage(new Error(lang_1.lang.__('LOCAL_EXECUTION_TIMEOUT', { timeoutMs: String(timeoutMs) })));
90
91
  port.close();
91
92
  }, timeoutMs);
92
93
  return {
@@ -209,7 +210,7 @@ const createMessageHandler = (port, resolve, reject) => {
209
210
  if (resolved)
210
211
  return;
211
212
  resolved = true;
212
- reject(new Error('Port closed before receiving response'));
213
+ reject(new Error(lang_1.lang.__('LOCAL_PORT_CLOSED')));
213
214
  };
214
215
  port.on('message', handleMessage).on('error', handleError).on('close', handleClose);
215
216
  return () => {
@@ -239,7 +240,7 @@ const runFunction = (funOptions, env) => {
239
240
  const handleWorkerExit = (code) => {
240
241
  if (code !== 0) {
241
242
  cleanup();
242
- reject(new Error(`Worker stopped with exit code ${code}`));
243
+ reject(new Error(lang_1.lang.__('LOCAL_WORKER_EXITED', { code: String(code) })));
243
244
  }
244
245
  };
245
246
  worker.once('error', handleWorkerError);
@@ -17,10 +17,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.startLocalStack = exports.stopLocal = void 0;
18
18
  const localStack_1 = require("../../types/localStack");
19
19
  const localServer_1 = require("./localServer");
20
- Object.defineProperty(exports, "stopLocal", { enumerable: true, get: function () { return localServer_1.stopLocal; } });
21
20
  const event_1 = require("./event");
22
21
  const function_1 = require("./function");
23
22
  const bucket_1 = require("./bucket");
23
+ const timer_1 = require("./timer");
24
24
  __exportStar(require("./event"), exports);
25
25
  const handlers = [
26
26
  { kind: localStack_1.RouteKind.SI_FUNCTIONS, handler: function_1.functionsHandler },
@@ -29,5 +29,12 @@ const handlers = [
29
29
  ];
30
30
  const startLocalStack = async (iac) => {
31
31
  await (0, localServer_1.servLocal)(handlers, iac);
32
+ // functions.*.triggers.timer fire locally too (issue #258)
33
+ (0, timer_1.startLocalTimers)(iac);
32
34
  };
33
35
  exports.startLocalStack = startLocalStack;
36
+ const stopLocal = async () => {
37
+ (0, timer_1.stopLocalTimers)();
38
+ await (0, localServer_1.stopLocal)();
39
+ };
40
+ exports.stopLocal = stopLocal;
@@ -0,0 +1,162 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.stopLocalTimers = exports.startLocalTimers = exports.matchesNow = void 0;
7
+ const siCron_1 = require("../../common/siCron");
8
+ const aliyunFc_1 = require("./aliyunFc");
9
+ const utils_1 = require("./utils");
10
+ const functionRunner_1 = require("./functionRunner");
11
+ const common_1 = require("../../common");
12
+ const node_fs_1 = __importDefault(require("node:fs"));
13
+ const lang_1 = require("../../lang");
14
+ const timers = [];
15
+ const toSchedule = (cron) => {
16
+ try {
17
+ const parsed = (0, siCron_1.parseSiCron)(cron);
18
+ return parsed.kind === 'every'
19
+ ? { kind: 'every', intervalMs: parsed.totalSeconds * 1000 }
20
+ : { kind: 'cron', fields: parsed.fields, hasSeconds: parsed.hasSeconds };
21
+ }
22
+ catch {
23
+ return undefined;
24
+ }
25
+ };
26
+ const matchesField = (field, value) => field.wildcard || field.values.includes(value);
27
+ /** Pure UTC wall-clock match of a cron schedule against a point in time. */
28
+ const matchesNow = (schedule, now) => {
29
+ if (schedule.kind !== 'cron') {
30
+ return false; // @every is interval-driven, not wall-clock driven
31
+ }
32
+ const fields = schedule.fields;
33
+ if (!matchesField(fields.minute, now.getUTCMinutes())) {
34
+ return false;
35
+ }
36
+ if (!matchesField(fields.hour, now.getUTCHours())) {
37
+ return false;
38
+ }
39
+ if (!matchesField(fields.month, now.getUTCMonth() + 1)) {
40
+ return false;
41
+ }
42
+ // standard cron day semantics: both day fields restricted → OR (either may
43
+ // fire); at least one wildcard → the restricted side must match
44
+ const domRestricted = !fields.dayOfMonth.wildcard;
45
+ const dowRestricted = !fields.dayOfWeek.wildcard;
46
+ if (domRestricted && dowRestricted) {
47
+ const domHit = fields.dayOfMonth.values.includes(now.getUTCDate());
48
+ const dowHit = fields.dayOfWeek.values.includes(now.getUTCDay());
49
+ if (!domHit && !dowHit) {
50
+ return false;
51
+ }
52
+ }
53
+ else {
54
+ if (domRestricted && !fields.dayOfMonth.values.includes(now.getUTCDate())) {
55
+ return false;
56
+ }
57
+ if (dowRestricted && !fields.dayOfWeek.values.includes(now.getUTCDay())) {
58
+ return false;
59
+ }
60
+ }
61
+ if (schedule.hasSeconds && !matchesField(fields.second, now.getUTCSeconds())) {
62
+ return false;
63
+ }
64
+ return true;
65
+ };
66
+ exports.matchesNow = matchesNow;
67
+ const buildTimerEvent = (provider, triggerName, payload) => {
68
+ const triggerTime = new Date().toISOString();
69
+ if (provider === common_1.ProviderEnum.ALIYUN) {
70
+ // Aliyun FC timer event — the handler receives a Buffer of this JSON
71
+ return Buffer.from(JSON.stringify({ triggerName, triggerTime, payload }));
72
+ }
73
+ // Tencent SCF timer event shape (default for other providers)
74
+ return { Type: 'Timer', TriggerName: triggerName, Time: triggerTime, Message: payload };
75
+ };
76
+ const fireTimer = async (iac, fn, triggerName, payload) => {
77
+ if (!fn.code) {
78
+ return;
79
+ }
80
+ let tempDir = null;
81
+ try {
82
+ const resolved = await (0, utils_1.resolveCodeDir)(fn.code.path);
83
+ tempDir = resolved.tempDir;
84
+ const funOptions = {
85
+ codeDir: resolved.codeDir,
86
+ functionKey: fn.key,
87
+ handler: fn.code.handler,
88
+ servicePath: '',
89
+ timeout: (fn.timeout ?? 3) * 1000,
90
+ };
91
+ const event = buildTimerEvent(iac.provider.name, triggerName, payload);
92
+ const context = (0, aliyunFc_1.createAliyunContextSerializable)(iac, fn.name, fn.code.handler, fn.memory ?? 128, fn.timeout ?? 3, (0, aliyunFc_1.generateRequestId)());
93
+ common_1.logger.info(lang_1.lang.__('LOCAL_TIMER_FIRED', { triggerName, functionName: fn.name }));
94
+ const result = await (0, functionRunner_1.invokeFunction)(funOptions, { ...fn.environment }, event, context);
95
+ common_1.logger.info(lang_1.lang.__('FUNCTION_EXECUTION_RESULT', { result: JSON.stringify(result) }));
96
+ }
97
+ catch (error) {
98
+ common_1.logger.error(lang_1.lang.__('FUNCTION_EXECUTION_ERROR', { error: String(error) }));
99
+ }
100
+ finally {
101
+ if (tempDir && node_fs_1.default.existsSync(tempDir)) {
102
+ node_fs_1.default.rmSync(tempDir, { recursive: true, force: true });
103
+ }
104
+ }
105
+ };
106
+ const evaluateTimer = (iac, fn, triggerName, payload, schedule, state) => {
107
+ const now = new Date();
108
+ if (schedule.kind === 'every') {
109
+ if (Date.now() - state.lastFiredAt < schedule.intervalMs) {
110
+ return;
111
+ }
112
+ state.lastFiredAt = Date.now();
113
+ }
114
+ else {
115
+ // dedup to once per matching second (minute precision without seconds)
116
+ const tickKey = now.toISOString().slice(0, schedule.hasSeconds ? 19 : 16);
117
+ if (tickKey === state.lastTickKey || !(0, exports.matchesNow)(schedule, now)) {
118
+ return;
119
+ }
120
+ state.lastTickKey = tickKey;
121
+ }
122
+ if (state.running) {
123
+ return; // previous invocation still running — skip this tick
124
+ }
125
+ state.running = true;
126
+ void fireTimer(iac, fn, triggerName, payload).finally(() => {
127
+ state.running = false;
128
+ });
129
+ };
130
+ const startLocalTimers = (iac) => {
131
+ (0, exports.stopLocalTimers)();
132
+ iac.functions?.forEach((fn) => {
133
+ fn.triggers?.timer?.forEach((timer) => {
134
+ if (timer.enable === false) {
135
+ common_1.logger.info(lang_1.lang.__('LOCAL_TIMER_DISABLED', { triggerName: timer.name, functionName: fn.name }));
136
+ return;
137
+ }
138
+ const schedule = toSchedule(timer.cron);
139
+ if (!schedule) {
140
+ // unreachable for validated configs — the parser rejects bad si-cron
141
+ common_1.logger.warn(lang_1.lang.__('LOCAL_TIMER_INVALID_CRON', { triggerName: timer.name, cron: timer.cron }));
142
+ return;
143
+ }
144
+ common_1.logger.info(lang_1.lang.__('LOCAL_TIMER_SCHEDULED', {
145
+ triggerName: timer.name,
146
+ cron: timer.cron,
147
+ functionName: fn.name,
148
+ }));
149
+ const state = { lastTickKey: '', lastFiredAt: Date.now(), running: false };
150
+ const tick = setInterval(() => {
151
+ evaluateTimer(iac, fn, timer.name, timer.payload ?? '', schedule, state);
152
+ }, 1000);
153
+ timers.push(tick);
154
+ });
155
+ });
156
+ };
157
+ exports.startLocalTimers = startLocalTimers;
158
+ const stopLocalTimers = () => {
159
+ timers.forEach((tick) => clearInterval(tick));
160
+ timers.length = 0;
161
+ };
162
+ exports.stopLocalTimers = stopLocalTimers;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.extractZipFile = void 0;
6
+ exports.resolveCodeDir = exports.extractZipFile = void 0;
7
7
  const jszip_1 = __importDefault(require("jszip"));
8
8
  const node_fs_1 = __importDefault(require("node:fs"));
9
9
  const node_path_1 = __importDefault(require("node:path"));
@@ -34,3 +34,21 @@ const extractZipFile = async (zipPath) => {
34
34
  return tempDir;
35
35
  };
36
36
  exports.extractZipFile = extractZipFile;
37
+ /**
38
+ * Resolve the handler directory from a function's configured code path:
39
+ * a zip artifact is extracted to a temp dir, a directory is used as-is,
40
+ * anything else falls back to its parent directory. Returns the temp dir
41
+ * so callers can clean it up after execution.
42
+ */
43
+ const resolveCodeDir = async (codePath) => {
44
+ const resolved = node_path_1.default.resolve(process.cwd(), codePath);
45
+ if (resolved.endsWith('.zip') && node_fs_1.default.existsSync(resolved)) {
46
+ const tempDir = await (0, exports.extractZipFile)(resolved);
47
+ return { codeDir: tempDir, tempDir };
48
+ }
49
+ if (node_fs_1.default.existsSync(resolved) && node_fs_1.default.statSync(resolved).isDirectory()) {
50
+ return { codeDir: resolved, tempDir: null };
51
+ }
52
+ return { codeDir: node_path_1.default.dirname(resolved), tempDir: null };
53
+ };
54
+ exports.resolveCodeDir = resolveCodeDir;
@@ -33,14 +33,14 @@ const executeSingleItem = async (context, item, bucketsMap, currentState) => {
33
33
  case 'create': {
34
34
  const bucket = bucketsMap.get(item.logicalId);
35
35
  if (!bucket) {
36
- throw new Error(`Bucket not found for logical ID: ${item.logicalId}`);
36
+ throw new Error(lang_1.lang.__('RESOURCE_BUCKET_NOT_FOUND', { logicalId: item.logicalId }));
37
37
  }
38
38
  return executeCreateAction(context, bucket, currentState);
39
39
  }
40
40
  case 'update': {
41
41
  const bucket = bucketsMap.get(item.logicalId);
42
42
  if (!bucket) {
43
- throw new Error(`Bucket not found for logical ID: ${item.logicalId}`);
43
+ throw new Error(lang_1.lang.__('RESOURCE_BUCKET_NOT_FOUND', { logicalId: item.logicalId }));
44
44
  }
45
45
  return executeUpdateAction(context, bucket, currentState);
46
46
  }
@@ -258,7 +258,7 @@ const createBucketResource = async (context, bucket, state) => {
258
258
  }
259
259
  const bucketInfo = await client.cos.getBucket(bucket.name, context.region);
260
260
  if (!bucketInfo) {
261
- throw new Error(`Failed to refresh state for bucket: ${bucket.name}`);
261
+ throw new Error(lang_1.lang.__('REFRESH_STATE_BUCKET', { name: bucket.name }));
262
262
  }
263
263
  // PutBucket succeeding does NOT prove the bucket is ours: a pre-existing
264
264
  // bucket is returned idempotently. Only a bucket carrying our ownership tag
@@ -362,7 +362,7 @@ const updateBucketResource = async (context, bucket, state) => {
362
362
  }
363
363
  const bucketInfo = await client.cos.getBucket(bucket.name, context.region);
364
364
  if (!bucketInfo) {
365
- throw new Error(`Failed to refresh state for bucket: ${bucket.name}`);
365
+ throw new Error(lang_1.lang.__('REFRESH_STATE_BUCKET', { name: bucket.name }));
366
366
  }
367
367
  const definition = (0, cosTypes_1.extractCosBucketDefinition)(config);
368
368
  const sid = (0, common_1.buildSid)('tencent', 'cos', context.stage, bucket.name);
@@ -48,22 +48,22 @@ const executeSingleItem = async (context, item, databasesMap, currentState) => {
48
48
  case 'create': {
49
49
  const database = databasesMap.get(item.logicalId);
50
50
  if (!database) {
51
- throw new Error(`Database not found for logical ID: ${item.logicalId}`);
51
+ throw new Error(lang_1.lang.__('RESOURCE_DATABASE_NOT_FOUND', { logicalId: item.logicalId }));
52
52
  }
53
53
  return executeCreateAction(context, database, currentState);
54
54
  }
55
55
  case 'update': {
56
56
  const database = databasesMap.get(item.logicalId);
57
57
  if (!database) {
58
- throw new Error(`Database not found for logical ID: ${item.logicalId}`);
58
+ throw new Error(lang_1.lang.__('RESOURCE_DATABASE_NOT_FOUND', { logicalId: item.logicalId }));
59
59
  }
60
60
  const state = (0, stateManager_1.getResource)(currentState, item.logicalId);
61
61
  if (!state) {
62
- throw new Error(`State not found for ${item.logicalId}`);
62
+ throw new Error(lang_1.lang.__('EXECUTOR_STATE_NOT_FOUND', { logicalId: item.logicalId }));
63
63
  }
64
64
  const spaceId = state.metadata?.spaceId || state.instances?.[0]?.id;
65
65
  if (!spaceId) {
66
- throw new Error(`Space ID not found in state for ${item.logicalId}`);
66
+ throw new Error(lang_1.lang.__('RESOURCE_SPACE_ID_NOT_FOUND', { logicalId: item.logicalId }));
67
67
  }
68
68
  return executeUpdateAction(context, database, spaceId, currentState);
69
69
  }
@@ -75,7 +75,7 @@ const executeSingleItem = async (context, item, databasesMap, currentState) => {
75
75
  }
76
76
  const spaceId = state.metadata?.spaceId || state.instances?.[0]?.id;
77
77
  if (!spaceId) {
78
- throw new Error(`Space ID not found in state for ${item.logicalId}`);
78
+ throw new Error(lang_1.lang.__('RESOURCE_SPACE_ID_NOT_FOUND', { logicalId: item.logicalId }));
79
79
  }
80
80
  return executeDeleteAction(context, spaceId, item.logicalId, currentState);
81
81
  }
@@ -97,7 +97,7 @@ const createEsResource = async (context, database, state) => {
97
97
  // Refresh state from provider to get all attributes
98
98
  const spaceInfo = await client.es.getSpace(spaceId);
99
99
  if (!spaceInfo) {
100
- throw new Error(`Failed to refresh state for ES space: ${spaceId}`);
100
+ throw new Error(lang_1.lang.__('REFRESH_STATE_ES_SPACE', { spaceId }));
101
101
  }
102
102
  return (0, stateManager_1.setResource)(state, logicalId, buildResourceState(spaceInfo));
103
103
  }
@@ -110,7 +110,11 @@ const createEsResource = async (context, database, state) => {
110
110
  // fail loudly rather than silently taking it over.
111
111
  const probe = await client.es.getSpaceByName(config.SpaceName);
112
112
  if (probe && (0, ownershipTag_1.isOwnedByStack)(context, logicalId, probe.Tags)) {
113
- logger_1.logger.info(`ES space ${config.SpaceName} exists and carries ownership tag (${ownershipTag_1.OWNERSHIP_TAG_KEY}), adopting idempotently`);
113
+ logger_1.logger.info(lang_1.lang.__('RESOURCE_OWNERSHIP_TAG_ADOPT', {
114
+ resourceType: 'ES space',
115
+ name: config.SpaceName,
116
+ tag: ownershipTag_1.OWNERSHIP_TAG_KEY,
117
+ }));
114
118
  return (0, stateManager_1.setResource)(state, logicalId, buildResourceState(probe));
115
119
  }
116
120
  throw new types_1.PartialResourceError(stateAfterDependents, new Error(lang_1.lang.__('RESOURCE_EXISTS_NOT_OWNED_ADOPT', {
@@ -138,7 +142,7 @@ const updateEsResource = async (context, database, spaceId, state) => {
138
142
  // Refresh state from provider to get all attributes
139
143
  const spaceInfo = await client.es.getSpace(spaceId);
140
144
  if (!spaceInfo) {
141
- throw new Error(`Failed to refresh state for ES space: ${spaceId}`);
145
+ throw new Error(lang_1.lang.__('REFRESH_STATE_ES_SPACE', { spaceId }));
142
146
  }
143
147
  const definition = (0, esServerlessTypes_1.extractTencentEsDefinition)(config);
144
148
  const sid = (0, common_1.buildSid)('tencent', 'es', context.stage, spaceId);
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.cloudTencentEsToDefinition = exports.extractTencentEsDefinition = exports.databaseToTencentEsConfig = void 0;
4
+ const lang_1 = require("../../lang");
4
5
  // Map database versions to ES versions
5
6
  const esVersionMap = new Map([
6
7
  [
@@ -15,7 +16,7 @@ const esVersionMap = new Map([
15
16
  const databaseToTencentEsConfig = (database) => {
16
17
  const engineConfig = esVersionMap.get(`${database.type}-${database.version}`);
17
18
  if (!engineConfig) {
18
- throw new Error(`Unsupported ES database type/version: ${database.type}-${database.version}`);
19
+ throw new Error(lang_1.lang.__('ES_DB_TYPE_VERSION_UNSUPPORTED', { type: database.type, version: database.version }));
19
20
  }
20
21
  const config = {
21
22
  SpaceName: database.name,
@@ -35,14 +35,14 @@ const executeSingleItem = async (context, item, functionsMap, currentState) => {
35
35
  case 'create': {
36
36
  const fn = functionsMap.get(item.logicalId);
37
37
  if (!fn) {
38
- throw new Error(`Function not found for logical ID: ${item.logicalId}`);
38
+ throw new Error(lang_1.lang.__('RESOURCE_FUNCTION_NOT_FOUND', { logicalId: item.logicalId }));
39
39
  }
40
40
  return executeCreateAction(context, fn, currentState);
41
41
  }
42
42
  case 'update': {
43
43
  const fn = functionsMap.get(item.logicalId);
44
44
  if (!fn) {
45
- throw new Error(`Function not found for logical ID: ${item.logicalId}`);
45
+ throw new Error(lang_1.lang.__('RESOURCE_FUNCTION_NOT_FOUND', { logicalId: item.logicalId }));
46
46
  }
47
47
  return executeUpdateAction(context, fn, currentState, item.drifted);
48
48
  }
@@ -7,6 +7,7 @@ const lang_1 = require("../../lang");
7
7
  const refreshCache_1 = require("../../common/refreshCache");
8
8
  const clsOperations_1 = require("../../common/tencentClient/clsOperations");
9
9
  const concurrency_1 = require("../../common/concurrency");
10
+ const siCron_1 = require("../../common/siCron");
10
11
  const scfTypes_1 = require("./scfTypes");
11
12
  const stateManager_1 = require("../../common/stateManager");
12
13
  const hashUtils_1 = require("../../common/hashUtils");
@@ -61,26 +62,59 @@ const generateFunctionPlan = async (context, state, functions) => {
61
62
  // the skeleton's extraUpdate hook (issue #246) so a topic-only
62
63
  // drift gets the live→desired diff baseline too.
63
64
  const topicInstance = currentState?.instances?.find((i) => i.type === 'TENCENT_CLS_TOPIC');
64
- if (!fn.log || !topicInstance?.id) {
65
- return { update: false, drifted: false };
66
- }
67
- const topicId = topicInstance.id;
68
- try {
69
- const liveTopic = await (0, refreshCache_1.cachedRefreshRead)(context, `cls.getTopicById:${topicId}`, () => client.cls.getTopicById(topicId));
70
- const topicDrifted = !liveTopic ||
71
- liveTopic.StorageType !== clsOperations_1.CLS_TOPIC_STORAGE_TYPE ||
72
- liveTopic.Period !== clsOperations_1.CLS_TOPIC_PERIOD;
73
- return topicDrifted
74
- ? { update: true, drifted: true, reason: 'PLAN_DRIFT_CLS_TOPIC' }
75
- : { update: false, drifted: false };
65
+ if (fn.log && topicInstance?.id) {
66
+ const topicId = topicInstance.id;
67
+ try {
68
+ const liveTopic = await (0, refreshCache_1.cachedRefreshRead)(context, `cls.getTopicById:${topicId}`, () => client.cls.getTopicById(topicId));
69
+ const topicDrifted = !liveTopic ||
70
+ liveTopic.StorageType !== clsOperations_1.CLS_TOPIC_STORAGE_TYPE ||
71
+ liveTopic.Period !== clsOperations_1.CLS_TOPIC_PERIOD;
72
+ if (topicDrifted) {
73
+ return { update: true, drifted: true, reason: 'PLAN_DRIFT_CLS_TOPIC' };
74
+ }
75
+ }
76
+ catch (error) {
77
+ logger_1.logger.warn(lang_1.lang.__('PLAN_FUNCTION_NESTED_PROBE_FAILED', {
78
+ functionName: fn.name,
79
+ error: String(error),
80
+ }));
81
+ }
76
82
  }
77
- catch (error) {
78
- logger_1.logger.warn(lang_1.lang.__('PLAN_FUNCTION_NESTED_PROBE_FAILED', {
79
- functionName: fn.name,
80
- error: String(error),
81
- }));
82
- return { update: false, drifted: false };
83
+ // Issue #258: timer trigger drift — the live GetFunction trigger
84
+ // list is compared against the desired timers (name-keyed). The
85
+ // read is refresh-cached, so this reuses the fetch the skeleton
86
+ // already made. Manual deletes, console cron edits and extra
87
+ // triggers all mark the function drifted.
88
+ const timerStateInstances = (currentState?.instances ?? []).filter((i) => i.type === 'TENCENT_SCF_TIMER_TRIGGER');
89
+ const desiredTimers = fn.triggers?.timer ?? [];
90
+ if (desiredTimers.length > 0 || timerStateInstances.length > 0) {
91
+ try {
92
+ const live = await (0, refreshCache_1.cachedRefreshRead)(context, `scf.getFunction:${fn.name}`, () => client.scf.getFunction(fn.name));
93
+ const liveTimers = (live?.Triggers ?? []).filter((trigger) => trigger.Type === 'timer' && trigger.TriggerName);
94
+ const desiredNames = new Set(desiredTimers.map((timer) => timer.name));
95
+ const extraTimer = liveTimers.some((trigger) => !desiredNames.has(trigger.TriggerName));
96
+ const desiredChanged = desiredTimers.some((timer) => {
97
+ const liveTimer = liveTimers.find((trigger) => trigger.TriggerName === timer.name);
98
+ if (!liveTimer) {
99
+ return true;
100
+ }
101
+ // GetFunction reports Enable as 1/0
102
+ return (liveTimer.TriggerDesc !== (0, siCron_1.translateSiCron)(timer.cron, 'tencent') ||
103
+ (liveTimer.CustomArgument ?? undefined) !== timer.payload ||
104
+ (liveTimer.Enable === 1) !== timer.enable);
105
+ });
106
+ if (extraTimer || desiredChanged) {
107
+ return { update: true, drifted: true, reason: 'PLAN_DRIFT_TIMER_TRIGGER' };
108
+ }
109
+ }
110
+ catch (error) {
111
+ logger_1.logger.warn(lang_1.lang.__('PLAN_TIMER_TRIGGER_PROBE_FAILED', {
112
+ functionName: fn.name,
113
+ error: String(error),
114
+ }));
115
+ }
83
116
  }
117
+ return { update: false, drifted: false };
84
118
  },
85
119
  cloudToDefinition: scfTypes_1.cloudScfToDefinition,
86
120
  enrichRemoteAttributes: async (remote, attributes) => {