@geek-fun/serverlessinsight 0.8.7 → 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 (62) 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 +36 -16
  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/dist/package.json +1 -1
  9. package/dist/src/commands/deploy.js +1 -0
  10. package/dist/src/commands/index.js +6 -2
  11. package/dist/src/commands/plan.js +1 -0
  12. package/dist/src/common/aliyunClient/ecsOperations.js +70 -1
  13. package/dist/src/common/aliyunClient/nasOperations.js +21 -0
  14. package/dist/src/common/aliyunClient/ramOperations.js +32 -20
  15. package/dist/src/common/aliyunClient/slsOperations.js +16 -3
  16. package/dist/src/common/concurrency.js +30 -0
  17. package/dist/src/common/context.js +3 -0
  18. package/dist/src/common/dependencyGraph/graph.js +5 -0
  19. package/dist/src/common/index.js +5 -0
  20. package/dist/src/common/planCompare.js +62 -0
  21. package/dist/src/common/planFormatter.js +15 -3
  22. package/dist/src/common/refreshCache.js +32 -0
  23. package/dist/src/common/refreshPlanner.js +105 -0
  24. package/dist/src/common/tencentClient/clsOperations.js +27 -3
  25. package/dist/src/common/tencentClient/tdsqlcOperations.js +22 -0
  26. package/dist/src/common/throttleRetry.js +56 -0
  27. package/dist/src/common/volcengineClient/tlsOperations.js +12 -4
  28. package/dist/src/lang/en.js +16 -0
  29. package/dist/src/lang/zh-CN.js +16 -0
  30. package/dist/src/stack/aliyunStack/apigwPlanner.js +75 -7
  31. package/dist/src/stack/aliyunStack/apigwTypes.js +67 -1
  32. package/dist/src/stack/aliyunStack/databasePlanner.js +26 -62
  33. package/dist/src/stack/aliyunStack/esServerlessTypes.js +50 -1
  34. package/dist/src/stack/aliyunStack/fc3Executor.js +5 -3
  35. package/dist/src/stack/aliyunStack/fc3Planner.js +299 -12
  36. package/dist/src/stack/aliyunStack/fc3Resource.js +200 -30
  37. package/dist/src/stack/aliyunStack/fc3Types.js +61 -1
  38. package/dist/src/stack/aliyunStack/ossPlanner.js +21 -63
  39. package/dist/src/stack/aliyunStack/ossTypes.js +25 -1
  40. package/dist/src/stack/aliyunStack/rdsTypes.js +38 -1
  41. package/dist/src/stack/aliyunStack/tablestorePlanner.js +20 -74
  42. package/dist/src/stack/aliyunStack/tablestoreTypes.js +33 -1
  43. package/dist/src/stack/scfStack/cosPlanner.js +30 -50
  44. package/dist/src/stack/scfStack/cosTypes.js +29 -1
  45. package/dist/src/stack/scfStack/esServerlessPlanner.js +21 -54
  46. package/dist/src/stack/scfStack/esServerlessTypes.js +13 -1
  47. package/dist/src/stack/scfStack/scfExecutor.js +5 -3
  48. package/dist/src/stack/scfStack/scfPlanner.js +71 -50
  49. package/dist/src/stack/scfStack/scfResource.js +37 -2
  50. package/dist/src/stack/scfStack/scfTypes.js +35 -1
  51. package/dist/src/stack/scfStack/sharedLogset.js +3 -2
  52. package/dist/src/stack/scfStack/tdsqlcPlanner.js +37 -55
  53. package/dist/src/stack/scfStack/tdsqlcTypes.js +21 -1
  54. package/dist/src/stack/volcengineStack/apigwPlanner.js +54 -7
  55. package/dist/src/stack/volcengineStack/apigwTypes.js +26 -1
  56. package/dist/src/stack/volcengineStack/tosPlanner.js +28 -55
  57. package/dist/src/stack/volcengineStack/tosTypes.js +18 -1
  58. package/dist/src/stack/volcengineStack/vefaasExecutor.js +5 -3
  59. package/dist/src/stack/volcengineStack/vefaasPlanner.js +114 -6
  60. package/dist/src/stack/volcengineStack/vefaasResource.js +40 -5
  61. package/dist/tsconfig.tsbuildinfo +1 -1
  62. package/package.json +1 -1
@@ -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]) => {
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.extractTencentEsDefinition = exports.databaseToTencentEsConfig = void 0;
3
+ exports.cloudTencentEsToDefinition = exports.extractTencentEsDefinition = exports.databaseToTencentEsConfig = void 0;
4
4
  // Map database versions to ES versions
5
5
  const esVersionMap = new Map([
6
6
  [
@@ -46,3 +46,15 @@ const extractTencentEsDefinition = (config) => {
46
46
  };
47
47
  };
48
48
  exports.extractTencentEsDefinition = extractTencentEsDefinition;
49
+ // issue #234 phase 2: cloud-side counterpart of extractTencentEsDefinition.
50
+ // Mirrors the executor write shape key-for-key. Not refreshable (omitted so it
51
+ // can never phantom-drift): version (DescribeServerlessSpaceVCU / getSpace
52
+ // does not report the configured engine version).
53
+ const cloudTencentEsToDefinition = (info) => ({
54
+ spaceName: info.SpaceName,
55
+ vpcId: info.VpcInfo?.[0]?.VpcId ?? null,
56
+ subnetId: info.VpcInfo?.[0]?.SubnetId ?? null,
57
+ zone: info.Zone ?? null,
58
+ kibanaWhiteIpList: info.KibanaPublicAcl?.WhiteIpList ?? null,
59
+ });
60
+ exports.cloudTencentEsToDefinition = cloudTencentEsToDefinition;
@@ -13,9 +13,11 @@ const executeCreateAction = async (context, fn, currentState) => {
13
13
  common_1.logger.info(lang_1.lang.__('RESOURCE_CREATED', { resourceType: 'function', name: fn.name }));
14
14
  return newState;
15
15
  };
16
- const executeUpdateAction = async (context, fn, currentState) => {
16
+ const executeUpdateAction = async (context, fn, currentState, drifted) => {
17
17
  common_1.logger.info(lang_1.lang.__('UPDATING_RESOURCE', { resourceType: 'function', name: fn.name }));
18
- const newState = await (0, scfResource_1.updateResource)(context, fn, currentState);
18
+ // A drifted plan item means the cloud left the config: force the config
19
+ // re-push even when state-vs-desired sees no change.
20
+ const newState = await (0, scfResource_1.updateResource)(context, fn, currentState, { force: drifted === true });
19
21
  common_1.logger.info(lang_1.lang.__('RESOURCE_UPDATED', { resourceType: 'function', name: fn.name }));
20
22
  return newState;
21
23
  };
@@ -42,7 +44,7 @@ const executeSingleItem = async (context, item, functionsMap, currentState) => {
42
44
  if (!fn) {
43
45
  throw new Error(`Function not found for logical ID: ${item.logicalId}`);
44
46
  }
45
- return executeUpdateAction(context, fn, currentState);
47
+ return executeUpdateAction(context, fn, currentState, item.drifted);
46
48
  }
47
49
  case 'delete': {
48
50
  const state = (0, stateManager_1.getResource)(currentState, item.logicalId);
@@ -2,9 +2,15 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateFunctionPlan = void 0;
4
4
  const tencentClient_1 = require("../../common/tencentClient");
5
+ const logger_1 = require("../../common/logger");
6
+ const lang_1 = require("../../lang");
7
+ const refreshCache_1 = require("../../common/refreshCache");
8
+ const clsOperations_1 = require("../../common/tencentClient/clsOperations");
9
+ const concurrency_1 = require("../../common/concurrency");
5
10
  const scfTypes_1 = require("./scfTypes");
6
11
  const stateManager_1 = require("../../common/stateManager");
7
12
  const hashUtils_1 = require("../../common/hashUtils");
13
+ const refreshPlanner_1 = require("../../common/refreshPlanner");
8
14
  const ownershipTag_1 = require("../ownershipTag");
9
15
  const sharedLogset_1 = require("./sharedLogset");
10
16
  const planFunctionDeletion = (logicalId, definition) => ({
@@ -22,7 +28,7 @@ const generateFunctionPlan = async (context, state, functions) => {
22
28
  return { items };
23
29
  }
24
30
  const desiredLogicalIds = new Set(functions.map((fn) => `functions.${fn.key}`));
25
- const functionItems = await Promise.all(functions.map(async (fn) => {
31
+ const functionItems = await (0, concurrency_1.mapWithConcurrency)(functions, concurrency_1.PLAN_READ_CONCURRENCY, async (fn) => {
26
32
  const logicalId = `functions.${fn.key}`;
27
33
  const currentState = (0, stateManager_1.getResource)(state, logicalId);
28
34
  let config = (0, scfTypes_1.functionToScfConfig)(fn);
@@ -36,57 +42,72 @@ const generateFunctionPlan = async (context, state, functions) => {
36
42
  const codePath = fn.code.path;
37
43
  const desiredCodeHash = await (0, hashUtils_1.computeZipContentHash)(codePath);
38
44
  const desiredDefinition = (0, scfTypes_1.extractScfDefinition)(config, desiredCodeHash, fn.iam);
39
- if (!currentState || currentState.status === 'tainted') {
40
- // No usable local state: probe the provider before planning create.
41
- // If a same-named function already exists WITHOUT our ownership tag it
42
- // may belong to another project — fail fast in the plan instead of
43
- // letting the executor discover it mid-deploy.
44
- const client = (0, tencentClient_1.createTencentClient)(context);
45
- const remoteFunction = await client.scf.getFunction(fn.name);
46
- if (remoteFunction && !(0, ownershipTag_1.isOwnedByStack)(context, logicalId, remoteFunction.Tags)) {
47
- throw new Error(`Function ${fn.name} already exists in provider but is not owned by this stack (missing ${ownershipTag_1.OWNERSHIP_TAG_KEY} tag). Refusing to create — resolve manually.`);
45
+ const client = (0, tencentClient_1.createTencentClient)(context);
46
+ // Issue #234 M3: nested topic drift — probed only when logging is
47
+ // declared; unresolvable/unreadable topics are not drift.
48
+ if (currentState &&
49
+ currentState.status !== 'tainted' &&
50
+ fn.log &&
51
+ context.refresh !== false) {
52
+ const topicInstance = currentState.instances?.find((i) => i.type === 'TENCENT_CLS_TOPIC');
53
+ if (topicInstance?.id) {
54
+ const topicId = topicInstance.id;
55
+ try {
56
+ const liveTopic = await (0, refreshCache_1.cachedRefreshRead)(context, `cls.getTopicById:${topicId}`, () => client.cls.getTopicById(topicId));
57
+ const topicDrifted = !liveTopic ||
58
+ liveTopic.StorageType !== clsOperations_1.CLS_TOPIC_STORAGE_TYPE ||
59
+ liveTopic.Period !== clsOperations_1.CLS_TOPIC_PERIOD;
60
+ if (topicDrifted) {
61
+ return {
62
+ logicalId,
63
+ action: 'update',
64
+ resourceType: 'SCF',
65
+ changes: { before: currentState.definition || {}, after: desiredDefinition },
66
+ drifted: true,
67
+ };
68
+ }
69
+ }
70
+ catch (error) {
71
+ logger_1.logger.warn(lang_1.lang.__('PLAN_FUNCTION_NESTED_PROBE_FAILED', {
72
+ functionName: fn.name,
73
+ error: String(error),
74
+ }));
75
+ }
48
76
  }
49
- return {
50
- logicalId,
51
- action: 'create',
52
- resourceType: 'SCF',
53
- changes: { after: desiredDefinition },
54
- };
55
- }
56
- try {
57
- const client = (0, tencentClient_1.createTencentClient)(context);
58
- const remoteFunction = await client.scf.getFunction(fn.name);
59
- if (!remoteFunction) {
60
- return {
61
- logicalId,
62
- action: 'create',
63
- resourceType: 'SCF',
64
- changes: { before: currentState.definition, after: desiredDefinition },
65
- drifted: true,
66
- };
67
- }
68
- const currentDefinition = currentState.definition || {};
69
- const definitionChanged = !(0, hashUtils_1.attributesEqual)(currentDefinition, desiredDefinition);
70
- if (definitionChanged) {
71
- return {
72
- logicalId,
73
- action: 'update',
74
- resourceType: 'SCF',
75
- changes: { before: currentDefinition, after: desiredDefinition },
76
- drifted: true,
77
- };
78
- }
79
- return { logicalId, action: 'noop', resourceType: 'SCF' };
80
- }
81
- catch {
82
- return {
83
- logicalId,
84
- action: 'create',
85
- resourceType: 'SCF',
86
- changes: { before: currentState.definition, after: desiredDefinition },
87
- };
88
77
  }
89
- }));
78
+ return (0, refreshPlanner_1.planRefreshedResource)({
79
+ logicalId,
80
+ resourceType: 'SCF',
81
+ currentState,
82
+ desiredDefinition,
83
+ read: () => (0, refreshCache_1.cachedRefreshRead)(context, `scf.getFunction:${fn.name}`, () => client.scf.getFunction(fn.name)),
84
+ isOwned: (remote) => (0, ownershipTag_1.isOwnedByStack)(context, logicalId, remote.Tags),
85
+ foreignError: () => new Error(`Function ${fn.name} already exists in provider but is not owned by this stack (missing ${ownershipTag_1.OWNERSHIP_TAG_KEY} tag). Refusing to create — resolve manually.`),
86
+ cloudToDefinition: scfTypes_1.cloudScfToDefinition,
87
+ enrichRemoteAttributes: async (remote, attributes) => {
88
+ // Resolve cloud CLS ids back to the stable names the desired
89
+ // definition uses; unresolvable ids are skipped, not fabricated into
90
+ // drift.
91
+ const desiredLog = desiredDefinition.logConfig;
92
+ if (!desiredLog || !remote.ClsLogsetId || !remote.ClsTopicId) {
93
+ return attributes;
94
+ }
95
+ try {
96
+ const logsetName = await (0, refreshCache_1.cachedRefreshRead)(context, `cls.getLogsetNameById:${remote.ClsLogsetId}`, () => client.cls.getLogsetNameById(remote.ClsLogsetId));
97
+ const topics = await (0, refreshCache_1.cachedRefreshRead)(context, `cls.listTopicsByLogset:${remote.ClsLogsetId}`, () => client.cls.listTopicsByLogset(remote.ClsLogsetId));
98
+ const topicName = topics?.find((t) => t.TopicId === remote.ClsTopicId)?.TopicName;
99
+ if (!logsetName || !topicName) {
100
+ return attributes;
101
+ }
102
+ return { ...attributes, logConfig: { logset: logsetName, topic: topicName } };
103
+ }
104
+ catch {
105
+ return attributes;
106
+ }
107
+ },
108
+ refresh: context.refresh,
109
+ });
110
+ });
90
111
  const allStates = (0, stateManager_1.getAllResources)(state);
91
112
  const deletionItems = Object.entries(allStates)
92
113
  .filter(([logicalId]) => logicalId.startsWith('functions.') && !desiredLogicalIds.has(logicalId))