@geek-fun/serverlessinsight 0.8.6 → 0.8.8

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 (76) 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 +94 -0
  4. package/.serverlessinsight/state-insight-poc-deploy-app-insight-poc-deploy.json.backup +47 -27
  5. package/.serverlessinsight/state-insight-poc-destroy-app-insight-poc-destroy.json.backup +1 -1
  6. package/.serverlessinsight/state-insight-volc-app-insight-volc.json.backup +35 -73
  7. package/.serverlessinsight/state-role-reconcile-test-app-role-reconcile-test-service.json.backup +148 -0
  8. package/AGENTS.md +29 -0
  9. package/dist/package.json +1 -1
  10. package/dist/src/commands/deploy.js +1 -0
  11. package/dist/src/commands/index.js +6 -2
  12. package/dist/src/commands/plan.js +1 -0
  13. package/dist/src/common/aliyunClient/ecsOperations.js +70 -1
  14. package/dist/src/common/aliyunClient/nasOperations.js +21 -0
  15. package/dist/src/common/aliyunClient/ramOperations.js +116 -15
  16. package/dist/src/common/aliyunClient/slsOperations.js +16 -3
  17. package/dist/src/common/concurrency.js +30 -0
  18. package/dist/src/common/context.js +3 -0
  19. package/dist/src/common/dependencyGraph/graph.js +5 -0
  20. package/dist/src/common/iacHelper.js +3 -1
  21. package/dist/src/common/iamStatements.js +21 -1
  22. package/dist/src/common/index.js +5 -0
  23. package/dist/src/common/nameBuilder.js +12 -1
  24. package/dist/src/common/planCompare.js +62 -0
  25. package/dist/src/common/planFormatter.js +15 -3
  26. package/dist/src/common/refreshCache.js +32 -0
  27. package/dist/src/common/refreshPlanner.js +105 -0
  28. package/dist/src/common/tencentClient/camOperations.js +24 -12
  29. package/dist/src/common/tencentClient/clsOperations.js +27 -3
  30. package/dist/src/common/tencentClient/tdsqlcOperations.js +22 -0
  31. package/dist/src/common/throttleRetry.js +56 -0
  32. package/dist/src/common/volcengineClient/iamOperations.js +15 -11
  33. package/dist/src/common/volcengineClient/tlsOperations.js +12 -4
  34. package/dist/src/lang/en.js +23 -0
  35. package/dist/src/lang/zh-CN.js +22 -0
  36. package/dist/src/stack/aliyunStack/apigwExecutor.js +5 -5
  37. package/dist/src/stack/aliyunStack/apigwPlanner.js +75 -7
  38. package/dist/src/stack/aliyunStack/apigwResource.js +10 -8
  39. package/dist/src/stack/aliyunStack/apigwTypes.js +86 -5
  40. package/dist/src/stack/aliyunStack/databasePlanner.js +26 -62
  41. package/dist/src/stack/aliyunStack/deployer.js +33 -3
  42. package/dist/src/stack/aliyunStack/esServerlessTypes.js +50 -1
  43. package/dist/src/stack/aliyunStack/fc3Executor.js +5 -3
  44. package/dist/src/stack/aliyunStack/fc3Planner.js +299 -12
  45. package/dist/src/stack/aliyunStack/fc3Resource.js +358 -34
  46. package/dist/src/stack/aliyunStack/fc3Types.js +61 -1
  47. package/dist/src/stack/aliyunStack/ossPlanner.js +21 -63
  48. package/dist/src/stack/aliyunStack/ossTypes.js +25 -1
  49. package/dist/src/stack/aliyunStack/rdsTypes.js +38 -1
  50. package/dist/src/stack/aliyunStack/sharedLogProject.js +22 -5
  51. package/dist/src/stack/aliyunStack/tablestorePlanner.js +20 -74
  52. package/dist/src/stack/aliyunStack/tablestoreTypes.js +33 -1
  53. package/dist/src/stack/scfStack/cosPlanner.js +30 -50
  54. package/dist/src/stack/scfStack/cosTypes.js +29 -1
  55. package/dist/src/stack/scfStack/esServerlessPlanner.js +21 -54
  56. package/dist/src/stack/scfStack/esServerlessTypes.js +13 -1
  57. package/dist/src/stack/scfStack/scfExecutor.js +5 -3
  58. package/dist/src/stack/scfStack/scfPlanner.js +72 -51
  59. package/dist/src/stack/scfStack/scfResource.js +109 -12
  60. package/dist/src/stack/scfStack/scfTypes.js +35 -1
  61. package/dist/src/stack/scfStack/sharedLogset.js +12 -3
  62. package/dist/src/stack/scfStack/tdsqlcPlanner.js +37 -55
  63. package/dist/src/stack/scfStack/tdsqlcTypes.js +21 -1
  64. package/dist/src/stack/volcengineStack/apigwPlanner.js +59 -8
  65. package/dist/src/stack/volcengineStack/apigwResource.js +52 -30
  66. package/dist/src/stack/volcengineStack/apigwTypes.js +44 -8
  67. package/dist/src/stack/volcengineStack/sharedLogProject.js +9 -3
  68. package/dist/src/stack/volcengineStack/tosPlanner.js +28 -55
  69. package/dist/src/stack/volcengineStack/tosTypes.js +18 -1
  70. package/dist/src/stack/volcengineStack/vefaasExecutor.js +5 -3
  71. package/dist/src/stack/volcengineStack/vefaasPlanner.js +119 -10
  72. package/dist/src/stack/volcengineStack/vefaasResource.js +112 -13
  73. package/dist/src/stack/volcengineStack/vefaasTypes.js +61 -7
  74. package/dist/src/validator/semanticValidation.js +41 -0
  75. package/dist/tsconfig.tsbuildinfo +1 -1
  76. package/package.json +1 -1
@@ -6,9 +6,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.generateBucketPlan = void 0;
7
7
  const node_path_1 = __importDefault(require("node:path"));
8
8
  const aliyunClient_1 = require("../../common/aliyunClient");
9
+ const refreshCache_1 = require("../../common/refreshCache");
10
+ const concurrency_1 = require("../../common/concurrency");
9
11
  const ossTypes_1 = require("./ossTypes");
10
12
  const stateManager_1 = require("../../common/stateManager");
11
13
  const hashUtils_1 = require("../../common/hashUtils");
14
+ const refreshPlanner_1 = require("../../common/refreshPlanner");
12
15
  const ownershipTag_1 = require("../ownershipTag");
13
16
  const planBucketDeletion = (logicalId, definition) => ({
14
17
  logicalId,
@@ -32,7 +35,7 @@ const generateBucketPlan = async (context, state, buckets) => {
32
35
  return { items };
33
36
  }
34
37
  const desiredLogicalIds = new Set(buckets.map((bucket) => `buckets.${bucket.key}`));
35
- const bucketItems = await Promise.all(buckets.map(async (bucket) => {
38
+ const bucketItems = await (0, concurrency_1.mapWithConcurrency)(buckets, concurrency_1.PLAN_READ_CONCURRENCY, async (bucket) => {
36
39
  const logicalId = `buckets.${bucket.key}`;
37
40
  const currentState = (0, stateManager_1.getResource)(state, logicalId);
38
41
  const config = (0, ossTypes_1.bucketToOssBucketConfig)(bucket);
@@ -47,68 +50,23 @@ const generateBucketPlan = async (context, state, buckets) => {
47
50
  }
48
51
  })();
49
52
  const desiredDefinition = (0, ossTypes_1.extractOssBucketDefinition)(config, websiteCodeHash);
50
- if (!currentState || currentState.status === 'tainted') {
51
- // No usable local state: probe the provider before planning create.
52
- // If a same-named bucket already exists WITHOUT our ownership tag it
53
- // may belong to another project — fail fast in the plan instead of
54
- // letting the executor discover it mid-deploy.
55
- const client = (0, aliyunClient_1.createAliyunClient)(context);
56
- const remoteBucket = await client.oss.getBucket(bucket.name);
57
- if (remoteBucket &&
58
- !(0, ownershipTag_1.isOwnedByStack)(context, logicalId, toOwnershipTags(remoteBucket.tags))) {
59
- throw new Error(`Bucket ${bucket.name} already exists in provider but is not owned by this stack (missing ${ownershipTag_1.OWNERSHIP_TAG_KEY} tag). Refusing to create — resolve manually.`);
60
- }
61
- return {
62
- logicalId,
63
- action: 'create',
64
- resourceType: 'ALIYUN_OSS_BUCKET',
65
- changes: { after: desiredDefinition },
66
- };
67
- }
68
- try {
69
- const client = (0, aliyunClient_1.createAliyunClient)(context);
70
- const remoteBucket = await client.oss.getBucket(bucket.name);
71
- if (!remoteBucket) {
72
- return {
73
- logicalId,
74
- action: 'create',
75
- resourceType: 'ALIYUN_OSS_BUCKET',
76
- changes: {
77
- before: normalizeDefinitionForDisplay(currentState.definition),
78
- after: desiredDefinition,
79
- },
80
- drifted: true,
81
- };
82
- }
83
- const currentDefinition = currentState.definition || {};
84
- const normalizedCurrent = normalizeDefinitionForDisplay(currentDefinition);
85
- const normalizedDesired = normalizeDefinitionForDisplay(desiredDefinition);
86
- const { domainBound } = currentDefinition;
87
- const definitionChanged = !(0, hashUtils_1.attributesEqual)(normalizedCurrent, normalizedDesired);
88
- const domainBindingPending = domainBound === false;
89
- if (definitionChanged || domainBindingPending) {
90
- return {
91
- logicalId,
92
- action: 'update',
93
- resourceType: 'ALIYUN_OSS_BUCKET',
94
- changes: { before: normalizedCurrent, after: normalizedDesired },
95
- ...(definitionChanged ? { drifted: true } : {}),
96
- };
97
- }
98
- return { logicalId, action: 'noop', resourceType: 'ALIYUN_OSS_BUCKET' };
99
- }
100
- catch {
101
- return {
102
- logicalId,
103
- action: 'create',
104
- resourceType: 'ALIYUN_OSS_BUCKET',
105
- changes: {
106
- before: normalizeDefinitionForDisplay(currentState.definition),
107
- after: desiredDefinition,
108
- },
109
- };
110
- }
111
- }));
53
+ const client = (0, aliyunClient_1.createAliyunClient)(context);
54
+ const domainBindingPending = currentState?.definition?.domainBound ===
55
+ false;
56
+ return (0, refreshPlanner_1.planRefreshedResource)({
57
+ logicalId,
58
+ resourceType: 'ALIYUN_OSS_BUCKET',
59
+ currentState,
60
+ desiredDefinition,
61
+ read: () => (0, refreshCache_1.cachedRefreshRead)(context, `oss.getBucket:${bucket.name}`, () => client.oss.getBucket(bucket.name)),
62
+ isOwned: (remote) => (0, ownershipTag_1.isOwnedByStack)(context, logicalId, toOwnershipTags(remote.tags)),
63
+ foreignError: () => new Error(`Bucket ${bucket.name} already exists in provider but is not owned by this stack (missing ${ownershipTag_1.OWNERSHIP_TAG_KEY} tag). Refusing to create — resolve manually.`),
64
+ cloudToDefinition: ossTypes_1.cloudOssToDefinition,
65
+ normalizeForDisplay: normalizeDefinitionForDisplay,
66
+ extraUpdate: () => Promise.resolve({ update: domainBindingPending, drifted: false }),
67
+ refresh: context.refresh,
68
+ });
69
+ });
112
70
  const allStates = (0, stateManager_1.getAllResources)(state);
113
71
  const deletionItems = Object.entries(allStates)
114
72
  .filter(([logicalId]) => logicalId.startsWith('buckets.') && !desiredLogicalIds.has(logicalId))
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.extractOssBucketDefinition = exports.bucketToOssBucketConfig = void 0;
3
+ exports.cloudOssToDefinition = exports.extractOssBucketDefinition = exports.bucketToOssBucketConfig = void 0;
4
4
  const types_1 = require("../../types");
5
5
  const bucketTypes_1 = require("../bucketTypes");
6
6
  const aclMap = {
@@ -132,3 +132,27 @@ const extractOssBucketDefinition = (config, websiteCodeHash) => {
132
132
  return def;
133
133
  };
134
134
  exports.extractOssBucketDefinition = extractOssBucketDefinition;
135
+ const cloudOssToDefinition = (info) => ({
136
+ bucketName: info.name,
137
+ ...(info.acl !== undefined ? { acl: info.acl } : {}),
138
+ ...(info.websiteConfig
139
+ ? {
140
+ websiteConfiguration: {
141
+ indexDocument: info.websiteConfig.indexDocument,
142
+ errorDocument: info.websiteConfig.errorDocument ?? null,
143
+ },
144
+ }
145
+ : {}),
146
+ ...(info.storageClass !== undefined ? { storageClass: info.storageClass } : {}),
147
+ ...(info.versioningConfig?.status !== undefined
148
+ ? { versioningStatus: info.versioningConfig.status }
149
+ : {}),
150
+ ...(info.encryptionConfig?.sseAlgorithm !== undefined
151
+ ? { sseAlgorithm: info.encryptionConfig.sseAlgorithm }
152
+ : {}),
153
+ ...(info.policy !== undefined ? { policy: info.policy } : {}),
154
+ ...(typeof info.transferAccelerationStatus === 'boolean'
155
+ ? { accelerateEnabled: info.transferAccelerationStatus }
156
+ : {}),
157
+ });
158
+ exports.cloudOssToDefinition = cloudOssToDefinition;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.extractRdsDefinition = exports.databaseToRdsConfig = void 0;
3
+ exports.cloudRdsToDefinition = exports.extractRdsDefinition = exports.databaseToRdsConfig = void 0;
4
4
  // Map database versions to RDS engine versions
5
5
  const rdsEngineMap = new Map([
6
6
  [
@@ -215,3 +215,40 @@ const extractRdsDefinition = (config) => {
215
215
  };
216
216
  };
217
217
  exports.extractRdsDefinition = extractRdsDefinition;
218
+ const cloudRdsToDefinition = (info) => ({
219
+ ...(info.dbInstanceDescription === undefined
220
+ ? {}
221
+ : { dbInstanceDescription: info.dbInstanceDescription }),
222
+ ...(info.engine === undefined ? {} : { engine: info.engine }),
223
+ ...(info.engineVersion === undefined ? {} : { engineVersion: info.engineVersion }),
224
+ ...(info.dbInstanceClass === undefined ? {} : { dbInstanceClass: info.dbInstanceClass }),
225
+ ...(info.dbInstanceStorage === undefined ? {} : { dbInstanceStorage: info.dbInstanceStorage }),
226
+ ...(info.category === undefined ? {} : { category: info.category }),
227
+ ...(info.dbInstanceStorageType === undefined
228
+ ? {}
229
+ : { dbInstanceStorageType: info.dbInstanceStorageType }),
230
+ ...(info.burstingEnabled === undefined ? {} : { burstingEnabled: info.burstingEnabled }),
231
+ ...(info.serverlessConfig === undefined
232
+ ? {}
233
+ : {
234
+ serverlessConfig: {
235
+ ...(info.serverlessConfig.minCapacity === undefined
236
+ ? {}
237
+ : { minCapacity: info.serverlessConfig.minCapacity }),
238
+ ...(info.serverlessConfig.maxCapacity === undefined
239
+ ? {}
240
+ : { maxCapacity: info.serverlessConfig.maxCapacity }),
241
+ ...(info.serverlessConfig.autoPause === undefined
242
+ ? {}
243
+ : { autoPause: info.serverlessConfig.autoPause }),
244
+ ...(info.serverlessConfig.switchForce === undefined
245
+ ? {}
246
+ : { switchForce: info.serverlessConfig.switchForce }),
247
+ },
248
+ }),
249
+ ...(info.multiAZ === undefined ? {} : { multiAZ: info.multiAZ }),
250
+ ...(info.securityIPList === undefined ? {} : { securityIPList: info.securityIPList }),
251
+ ...(info.vpcId === undefined ? {} : { vpcId: info.vpcId }),
252
+ ...(info.vSwitchId === undefined ? {} : { vSwitchId: info.vSwitchId }),
253
+ });
254
+ exports.cloudRdsToDefinition = cloudRdsToDefinition;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ensureGatewayLogstore = exports.ensureFunctionLogstore = exports.releaseSharedSlsProjectIfUnused = exports.isSharedProjectOwnedByApp = exports.adoptSharedSlsProjectState = exports.buildSharedProjectResourceState = exports.ensureSharedSlsProject = exports.resolveSharedProjectName = exports.buildSharedProjectName = exports.SHARED_LOG_PROJECT_KEY = void 0;
3
+ exports.ensureGatewayLogstore = exports.ensureFunctionLogstore = exports.releaseSharedSlsProjectIfUnused = exports.isSharedProjectOwnedByApp = exports.adoptSharedSlsProjectState = exports.buildSharedProjectResourceState = exports.ensureSharedSlsProject = exports.resolveSharedProjectName = exports.buildGatewayLogstoreName = exports.buildFunctionLogstoreName = exports.buildSharedProjectName = exports.SHARED_LOG_PROJECT_KEY = void 0;
4
4
  const common_1 = require("../../common");
5
5
  const logger_1 = require("../../common/logger");
6
6
  const lang_1 = require("../../lang");
@@ -13,8 +13,25 @@ const ownershipTag_1 = require("../ownershipTag");
13
13
  * reports zero remaining logstores.
14
14
  */
15
15
  exports.SHARED_LOG_PROJECT_KEY = 'logs.project';
16
- const buildSharedProjectName = (app, stage) => `${app}-${stage}-sls`;
16
+ const SLS_NAME_MAX_LENGTH = 63;
17
+ const buildSharedProjectName = (app, stage) => (0, common_1.buildConstrainedName)({
18
+ parts: [app, stage, 'sls'],
19
+ maxLength: SLS_NAME_MAX_LENGTH,
20
+ charset: 'hyphen',
21
+ });
17
22
  exports.buildSharedProjectName = buildSharedProjectName;
23
+ const buildFunctionLogstoreName = (service, stage, fnKey) => (0, common_1.buildConstrainedName)({
24
+ parts: [service, stage, fnKey, 'fn-logs'],
25
+ maxLength: SLS_NAME_MAX_LENGTH,
26
+ charset: 'hyphen',
27
+ });
28
+ exports.buildFunctionLogstoreName = buildFunctionLogstoreName;
29
+ const buildGatewayLogstoreName = (service, stage) => (0, common_1.buildConstrainedName)({
30
+ parts: [service, stage, 'apigw-logs'],
31
+ maxLength: SLS_NAME_MAX_LENGTH,
32
+ charset: 'hyphen',
33
+ });
34
+ exports.buildGatewayLogstoreName = buildGatewayLogstoreName;
18
35
  const resolveSharedProjectName = (shared) => {
19
36
  const instanceId = shared.instances?.[0]?.id;
20
37
  return instanceId ?? shared.definition?.projectName;
@@ -127,11 +144,11 @@ const ensureLogstoreInSharedProject = async (context, client, projectName, logst
127
144
  await client.sls.waitForLogstore(projectName, logstoreName);
128
145
  return { logstoreName };
129
146
  };
130
- const ensureFunctionLogstore = async (context, client, projectName) => {
131
- return ensureLogstoreInSharedProject(context, client, projectName, `${context.service}-${context.stage}-fn-logs`);
147
+ const ensureFunctionLogstore = async (context, client, projectName, fnKey) => {
148
+ return ensureLogstoreInSharedProject(context, client, projectName, (0, exports.buildFunctionLogstoreName)(context.service, context.stage, fnKey));
132
149
  };
133
150
  exports.ensureFunctionLogstore = ensureFunctionLogstore;
134
151
  const ensureGatewayLogstore = async (context, client, projectName) => {
135
- return ensureLogstoreInSharedProject(context, client, projectName, `${context.service}-${context.stage}-apigw-logs`);
152
+ return ensureLogstoreInSharedProject(context, client, projectName, (0, exports.buildGatewayLogstoreName)(context.service, context.stage));
136
153
  };
137
154
  exports.ensureGatewayLogstore = ensureGatewayLogstore;
@@ -2,9 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateTablePlan = void 0;
4
4
  const aliyunClient_1 = require("../../common/aliyunClient");
5
+ const refreshCache_1 = require("../../common/refreshCache");
6
+ const concurrency_1 = require("../../common/concurrency");
5
7
  const tablestoreTypes_1 = require("./tablestoreTypes");
8
+ const refreshPlanner_1 = require("../../common/refreshPlanner");
6
9
  const stateManager_1 = require("../../common/stateManager");
7
- const hashUtils_1 = require("../../common/hashUtils");
8
10
  const planTableDeletion = (logicalId, definition) => ({
9
11
  logicalId,
10
12
  action: 'delete',
@@ -20,83 +22,27 @@ const generateTablePlan = async (context, state, tables) => {
20
22
  return { items };
21
23
  }
22
24
  const desiredLogicalIds = new Set(tables.map((table) => `tables.${table.key}`));
23
- const tableItems = await Promise.all(tables.map(async (table) => {
25
+ const tableItems = await (0, concurrency_1.mapWithConcurrency)(tables, concurrency_1.PLAN_READ_CONCURRENCY, async (table) => {
24
26
  const logicalId = `tables.${table.key}`;
25
27
  const currentState = (0, stateManager_1.getResource)(state, logicalId);
26
28
  const config = (0, tablestoreTypes_1.tableToTableStoreConfig)(table);
27
29
  const desiredDefinition = (0, tablestoreTypes_1.extractTableStoreDefinition)(config);
28
- if (!currentState || currentState.status === 'tainted') {
29
- // No usable local state: probe the provider before planning create.
30
- // Aliyun Tablestore (OTS) supports only instance-level tags — table
31
- // ownership cannot be verified, so tag-based adoption is IMPOSSIBLE.
32
- // If a same-named table already exists it may belong to another
33
- // project: fail fast in the plan instead of letting the executor
34
- // discover the collision mid-deploy.
35
- const client = (0, aliyunClient_1.createAliyunClient)(context);
36
- const tablestoreClient = client.tablestore(config.instanceName);
37
- const remoteTable = await tablestoreClient.getTable(config.tableName);
38
- if (remoteTable) {
39
- throw new Error(`Table ${config.tableName} already exists in provider but ownership cannot be verified (no table-level tags). Refusing to adopt — resolve manually.`);
40
- }
41
- return {
42
- logicalId,
43
- action: 'create',
44
- resourceType: 'ALIYUN_TABLESTORE_TABLE',
45
- changes: { after: desiredDefinition },
46
- };
47
- }
48
- try {
49
- const client = (0, aliyunClient_1.createAliyunClient)(context);
50
- const tablestoreClient = client.tablestore(config.instanceName);
51
- const remoteTable = await tablestoreClient.getTable(config.tableName);
52
- if (!remoteTable) {
53
- return {
54
- logicalId,
55
- action: 'create',
56
- resourceType: 'ALIYUN_TABLESTORE_TABLE',
57
- changes: { before: currentState.definition, after: desiredDefinition },
58
- drifted: true,
59
- };
60
- }
61
- const currentDefinition = currentState.definition || {};
62
- const definitionChanged = !(0, hashUtils_1.attributesEqual)(currentDefinition, desiredDefinition);
63
- if (definitionChanged) {
64
- // Check if primary keys changed (not updatable in TableStore)
65
- const currentPrimaryKey = JSON.stringify(currentDefinition.primaryKey || []);
66
- const desiredPrimaryKey = JSON.stringify(desiredDefinition.primaryKey || []);
67
- if (currentPrimaryKey !== desiredPrimaryKey) {
68
- // Primary key changes require table recreation (delete + create)
69
- // For now, we plan it as an update action with drift detection
70
- // The user should manually recreate the table if primary keys need to change
71
- return {
72
- logicalId,
73
- action: 'update',
74
- resourceType: 'ALIYUN_TABLESTORE_TABLE',
75
- changes: { before: currentDefinition, after: desiredDefinition },
76
- drifted: true,
77
- };
78
- }
79
- // Only throughput and table options changes can be applied via update
80
- return {
81
- logicalId,
82
- action: 'update',
83
- resourceType: 'ALIYUN_TABLESTORE_TABLE',
84
- changes: { before: currentDefinition, after: desiredDefinition },
85
- drifted: true,
86
- };
87
- }
88
- return { logicalId, action: 'noop', resourceType: 'ALIYUN_TABLESTORE_TABLE' };
89
- }
90
- catch {
91
- // If we can't check remote state, assume we need to create
92
- return {
93
- logicalId,
94
- action: 'create',
95
- resourceType: 'ALIYUN_TABLESTORE_TABLE',
96
- changes: { before: currentState.definition, after: desiredDefinition },
97
- };
98
- }
99
- }));
30
+ const client = (0, aliyunClient_1.createAliyunClient)(context);
31
+ const tablestoreClient = client.tablestore(config.instanceName);
32
+ return (0, refreshPlanner_1.planRefreshedResource)({
33
+ logicalId,
34
+ resourceType: 'ALIYUN_TABLESTORE_TABLE',
35
+ currentState,
36
+ desiredDefinition,
37
+ read: () => (0, refreshCache_1.cachedRefreshRead)(context, `tablestore.getTable:${config.instanceName}:${config.tableName}`, () => tablestoreClient.getTable(config.tableName)),
38
+ // TableStore has no table-level tags: an existing same-named table can
39
+ // never be verified as ours, so it is always refused on the probe path.
40
+ isOwned: () => false,
41
+ foreignError: () => new Error(`Table ${config.tableName} already exists in provider but ownership cannot be verified (no table-level tags). Refusing to adopt — resolve manually.`),
42
+ cloudToDefinition: tablestoreTypes_1.cloudTableStoreToDefinition,
43
+ refresh: context.refresh,
44
+ });
45
+ });
100
46
  const allStates = (0, stateManager_1.getAllResources)(state);
101
47
  const deletionItems = Object.entries(allStates)
102
48
  .filter(([logicalId]) => logicalId.startsWith('tables.') && !desiredLogicalIds.has(logicalId))
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.extractTableStoreDefinition = exports.tableToTableStoreConfig = void 0;
3
+ exports.cloudTableStoreToDefinition = exports.extractTableStoreDefinition = exports.tableToTableStoreConfig = void 0;
4
4
  const types_1 = require("../../types");
5
5
  // Map from TableStore cluster type to TableEnum
6
6
  const clusterTypeMap = new Map([
@@ -89,3 +89,35 @@ const extractTableStoreDefinition = (config) => {
89
89
  };
90
90
  };
91
91
  exports.extractTableStoreDefinition = extractTableStoreDefinition;
92
+ const cloudTableStoreToDefinition = (info) => {
93
+ const capacityUnit = info.reservedThroughputDetails?.capacityUnit;
94
+ const tableOptions = info.tableOptions;
95
+ return {
96
+ tableName: info.tableName,
97
+ ...(info.primaryKey ? { primaryKey: info.primaryKey } : {}),
98
+ ...(capacityUnit?.read !== undefined && capacityUnit.write !== undefined
99
+ ? {
100
+ reservedThroughput: {
101
+ capacityUnit: {
102
+ read: capacityUnit.read,
103
+ write: capacityUnit.write,
104
+ },
105
+ },
106
+ }
107
+ : {}),
108
+ ...(tableOptions &&
109
+ (tableOptions.timeToLive !== undefined || tableOptions.maxVersions !== undefined)
110
+ ? {
111
+ tableOptions: {
112
+ ...(tableOptions.timeToLive !== undefined
113
+ ? { timeToLive: tableOptions.timeToLive }
114
+ : {}),
115
+ ...(tableOptions.maxVersions !== undefined
116
+ ? { maxVersions: tableOptions.maxVersions }
117
+ : {}),
118
+ },
119
+ }
120
+ : {}),
121
+ };
122
+ };
123
+ exports.cloudTableStoreToDefinition = cloudTableStoreToDefinition;
@@ -2,9 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateBucketPlan = void 0;
4
4
  const tencentClient_1 = require("../../common/tencentClient");
5
+ const refreshCache_1 = require("../../common/refreshCache");
6
+ const concurrency_1 = require("../../common/concurrency");
5
7
  const cosTypes_1 = require("./cosTypes");
6
8
  const stateManager_1 = require("../../common/stateManager");
7
- const hashUtils_1 = require("../../common/hashUtils");
9
+ const refreshPlanner_1 = require("../../common/refreshPlanner");
10
+ const planCompare_1 = require("../../common/planCompare");
8
11
  const ownershipTag_1 = require("../ownershipTag");
9
12
  const planBucketDeletion = (logicalId, definition) => ({
10
13
  logicalId,
@@ -21,62 +24,39 @@ const generateBucketPlan = async (context, state, buckets) => {
21
24
  return { items };
22
25
  }
23
26
  const desiredLogicalIds = new Set(buckets.map((bucket) => `buckets.${bucket.key}`));
24
- const bucketItems = await Promise.all(buckets.map(async (bucket) => {
27
+ const bucketItems = await (0, concurrency_1.mapWithConcurrency)(buckets, concurrency_1.PLAN_READ_CONCURRENCY, async (bucket) => {
25
28
  const logicalId = `buckets.${bucket.key}`;
26
29
  const currentState = (0, stateManager_1.getResource)(state, logicalId);
27
30
  const config = (0, cosTypes_1.bucketToCosBucketConfig)(bucket, context.region);
28
31
  const desiredDefinition = (0, cosTypes_1.extractCosBucketDefinition)(config);
29
- if (!currentState || currentState.status === 'tainted') {
30
- // No usable local state: probe the provider before planning create.
31
- // If a same-named bucket already exists WITHOUT our ownership tag it
32
- // may belong to another project — fail fast in the plan instead of
33
- // letting the executor discover it mid-deploy.
34
- const client = (0, tencentClient_1.createTencentClient)(context);
35
- const remoteBucket = await client.cos.getBucket(bucket.name, context.region);
36
- if (remoteBucket && !(0, ownershipTag_1.isOwnedByStack)(context, logicalId, remoteBucket.Tags)) {
37
- throw new Error(`Bucket ${bucket.name} already exists in provider but is not owned by this stack (missing ${ownershipTag_1.OWNERSHIP_TAG_KEY} tag). Refusing to create — resolve manually.`);
38
- }
39
- return {
40
- logicalId,
41
- action: 'create',
42
- resourceType: 'COS_BUCKET',
43
- changes: { after: desiredDefinition },
44
- };
45
- }
46
- try {
47
- const client = (0, tencentClient_1.createTencentClient)(context);
48
- const remoteBucket = await client.cos.getBucket(bucket.name, context.region);
49
- if (!remoteBucket) {
32
+ const client = (0, tencentClient_1.createTencentClient)(context);
33
+ const readBucket = () => (0, refreshCache_1.cachedRefreshRead)(context, `cos.getBucket:${context.region}:${bucket.name}`, () => client.cos.getBucket(bucket.name, context.region));
34
+ return (0, refreshPlanner_1.planRefreshedResource)({
35
+ logicalId,
36
+ resourceType: 'COS_BUCKET',
37
+ currentState,
38
+ desiredDefinition,
39
+ read: readBucket,
40
+ isOwned: (remote) => (0, ownershipTag_1.isOwnedByStack)(context, logicalId, remote.Tags),
41
+ foreignError: () => new Error(`Bucket ${bucket.name} already exists in provider but is not owned by this stack (missing ${ownershipTag_1.OWNERSHIP_TAG_KEY} tag). Refusing to create — resolve manually.`),
42
+ cloudToDefinition: cosTypes_1.cloudCosToDefinition,
43
+ extraUpdate: async () => {
44
+ // Policy needs a canonical compare: the cloud returns a parsed
45
+ // object while the config serializes it — see jsonDocumentDiffers.
46
+ const desiredPolicy = desiredDefinition.policy ?? null;
47
+ if (desiredPolicy === null) {
48
+ return { update: false, drifted: false };
49
+ }
50
+ const remote = await readBucket();
51
+ const cloudPolicy = remote?.Policy;
50
52
  return {
51
- logicalId,
52
- action: 'create',
53
- resourceType: 'COS_BUCKET',
54
- changes: { before: currentState.definition, after: desiredDefinition },
53
+ update: (0, planCompare_1.jsonDocumentDiffers)(desiredPolicy, cloudPolicy),
55
54
  drifted: true,
56
55
  };
57
- }
58
- const currentDefinition = currentState.definition || {};
59
- const definitionChanged = !(0, hashUtils_1.attributesEqual)(currentDefinition, desiredDefinition);
60
- if (definitionChanged) {
61
- return {
62
- logicalId,
63
- action: 'update',
64
- resourceType: 'COS_BUCKET',
65
- changes: { before: currentDefinition, after: desiredDefinition },
66
- drifted: true,
67
- };
68
- }
69
- return { logicalId, action: 'noop', resourceType: 'COS_BUCKET' };
70
- }
71
- catch {
72
- return {
73
- logicalId,
74
- action: 'create',
75
- resourceType: 'COS_BUCKET',
76
- changes: { before: currentState.definition, after: desiredDefinition },
77
- };
78
- }
79
- }));
56
+ },
57
+ refresh: context.refresh,
58
+ });
59
+ });
80
60
  const allStates = (0, stateManager_1.getAllResources)(state);
81
61
  const deletionItems = Object.entries(allStates)
82
62
  .filter(([logicalId]) => logicalId.startsWith('buckets.') && !desiredLogicalIds.has(logicalId))
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.extractCosBucketDefinition = exports.bucketToCosBucketConfig = void 0;
3
+ exports.cloudCosToDefinition = exports.extractCosBucketDefinition = exports.bucketToCosBucketConfig = void 0;
4
4
  const bucketToCosBucketConfig = (bucket, region) => {
5
5
  const config = {
6
6
  Bucket: bucket.name,
@@ -86,3 +86,31 @@ const extractCosBucketDefinition = (config) => {
86
86
  };
87
87
  };
88
88
  exports.extractCosBucketDefinition = extractCosBucketDefinition;
89
+ // issue #234 phase 2: cloud-side counterpart of extractCosBucketDefinition.
90
+ // Mirrors the executor write shape key-for-key. Not refreshable (omitted so
91
+ // they can never phantom-drift): region (cloud Location uses a different
92
+ // format), domain/wwwBindApex/domainCertificate*/domainProtocol (GetBucket
93
+ // returns none of these), policy (cloud returns a policy object; byte-order
94
+ // comparison against the serialized desired document would false-drift).
95
+ const cloudCosToDefinition = (info) => ({
96
+ bucket: info.Name,
97
+ ...(info.ACL !== undefined ? { acl: info.ACL } : {}),
98
+ ...(info.WebsiteConfiguration
99
+ ? {
100
+ websiteConfiguration: {
101
+ indexDocument: info.WebsiteConfiguration.IndexDocument?.Suffix ?? null,
102
+ errorDocument: info.WebsiteConfiguration.ErrorDocument?.Key ?? null,
103
+ },
104
+ }
105
+ : {}),
106
+ ...(info.VersioningConfiguration?.status !== undefined
107
+ ? { versioningStatus: info.VersioningConfiguration.status }
108
+ : {}),
109
+ ...(info.SseConfiguration?.sseAlgorithm !== undefined
110
+ ? { sseAlgorithm: info.SseConfiguration.sseAlgorithm }
111
+ : {}),
112
+ ...(info.SseConfiguration?.sseKmsMasterKeyId !== undefined
113
+ ? { sseKmsMasterKeyId: info.SseConfiguration.sseKmsMasterKeyId }
114
+ : {}),
115
+ });
116
+ exports.cloudCosToDefinition = cloudCosToDefinition;
@@ -2,9 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateEsPlan = void 0;
4
4
  const tencentClient_1 = require("../../common/tencentClient");
5
+ const refreshCache_1 = require("../../common/refreshCache");
6
+ const concurrency_1 = require("../../common/concurrency");
5
7
  const esServerlessTypes_1 = require("./esServerlessTypes");
6
8
  const stateManager_1 = require("../../common/stateManager");
7
- const hashUtils_1 = require("../../common/hashUtils");
9
+ const refreshPlanner_1 = require("../../common/refreshPlanner");
8
10
  const ownershipTag_1 = require("../ownershipTag");
9
11
  const planEsDeletion = (logicalId, definition) => ({
10
12
  logicalId,
@@ -25,63 +27,28 @@ const generateEsPlan = async (context, state, databases) => {
25
27
  return { items };
26
28
  }
27
29
  const desiredLogicalIds = new Set(esDatabases.map((db) => `databases.${db.key}`));
28
- const databaseItems = await Promise.all(esDatabases.map(async (database) => {
30
+ const databaseItems = await (0, concurrency_1.mapWithConcurrency)(esDatabases, concurrency_1.PLAN_READ_CONCURRENCY, async (database) => {
29
31
  const logicalId = `databases.${database.key}`;
30
32
  const currentState = (0, stateManager_1.getResource)(state, logicalId);
31
33
  const config = (0, esServerlessTypes_1.databaseToTencentEsConfig)(database);
32
34
  const desiredDefinition = (0, esServerlessTypes_1.extractTencentEsDefinition)(config);
33
- if (!currentState || currentState.status === 'tainted') {
34
- // No usable local state: probe the provider before planning create.
35
- // If a same-named space already exists WITHOUT our ownership tag it may
36
- // belong to another project — fail fast in the plan instead of letting
37
- // the executor discover it mid-deploy.
38
- const client = (0, tencentClient_1.createTencentClient)(context);
39
- const remoteSpace = await client.es.getSpaceByName(config.SpaceName);
40
- if (remoteSpace && !(0, ownershipTag_1.isOwnedByStack)(context, logicalId, remoteSpace.Tags)) {
41
- throw new Error(`ES space ${config.SpaceName} already exists in provider but is not owned by this stack (missing ${ownershipTag_1.OWNERSHIP_TAG_KEY} tag). Refusing to create — resolve manually.`);
42
- }
43
- return {
44
- logicalId,
45
- action: 'create',
46
- resourceType: 'TENCENT_ES_SERVERLESS',
47
- changes: { after: desiredDefinition },
48
- };
49
- }
50
- const spaceId = currentState.metadata?.spaceId || currentState.instances?.[0]?.id;
51
- try {
52
- const client = (0, tencentClient_1.createTencentClient)(context);
53
- const remoteSpace = spaceId ? await client.es.getSpace(spaceId) : null;
54
- if (!remoteSpace) {
55
- return {
56
- logicalId,
57
- action: 'create',
58
- resourceType: 'TENCENT_ES_SERVERLESS',
59
- changes: { before: currentState.definition, after: desiredDefinition },
60
- drifted: true,
61
- };
62
- }
63
- const currentDefinition = currentState.definition || {};
64
- const definitionChanged = !(0, hashUtils_1.attributesEqual)(currentDefinition, desiredDefinition);
65
- if (definitionChanged) {
66
- return {
67
- logicalId,
68
- action: 'update',
69
- resourceType: 'TENCENT_ES_SERVERLESS',
70
- changes: { before: currentDefinition, after: desiredDefinition },
71
- drifted: true,
72
- };
73
- }
74
- return { logicalId, action: 'noop', resourceType: 'TENCENT_ES_SERVERLESS' };
75
- }
76
- catch {
77
- return {
78
- logicalId,
79
- action: 'create',
80
- resourceType: 'TENCENT_ES_SERVERLESS',
81
- changes: { before: currentState.definition, after: desiredDefinition },
82
- };
83
- }
84
- }));
35
+ const client = (0, tencentClient_1.createTencentClient)(context);
36
+ const spaceId = currentState?.metadata?.spaceId || currentState?.instances?.[0]?.id;
37
+ return (0, refreshPlanner_1.planRefreshedResource)({
38
+ logicalId,
39
+ resourceType: 'TENCENT_ES_SERVERLESS',
40
+ currentState,
41
+ desiredDefinition,
42
+ probeRead: () => (0, refreshCache_1.cachedRefreshRead)(context, `es.getSpaceByName:${config.SpaceName}`, () => client.es.getSpaceByName(config.SpaceName)),
43
+ read: () => spaceId
44
+ ? (0, refreshCache_1.cachedRefreshRead)(context, `es.getSpace:${spaceId}`, () => client.es.getSpace(spaceId))
45
+ : Promise.resolve(null),
46
+ isOwned: (remote) => (0, ownershipTag_1.isOwnedByStack)(context, logicalId, remote.Tags),
47
+ foreignError: () => new Error(`ES space ${config.SpaceName} already exists in provider but is not owned by this stack (missing ${ownershipTag_1.OWNERSHIP_TAG_KEY} tag). Refusing to create — resolve manually.`),
48
+ cloudToDefinition: esServerlessTypes_1.cloudTencentEsToDefinition,
49
+ refresh: context.refresh,
50
+ });
51
+ });
85
52
  const allStates = (0, stateManager_1.getAllResources)(state);
86
53
  const deletionItems = Object.entries(allStates)
87
54
  .filter(([logicalId, resourceState]) => {