@geek-fun/serverlessinsight 0.6.14 → 0.7.0

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 (45) hide show
  1. package/AGENTS.md +405 -10
  2. package/README.md +1 -0
  3. package/dist/package.json +8 -2
  4. package/dist/src/commands/deploy.js +4 -0
  5. package/dist/src/commands/destroy.js +4 -0
  6. package/dist/src/common/credentials.js +12 -0
  7. package/dist/src/common/providerEnum.js +1 -0
  8. package/dist/src/common/runtimeMapper.js +24 -3
  9. package/dist/src/common/volcengineClient/apigwOperations.js +271 -0
  10. package/dist/src/common/volcengineClient/iamOperations.js +349 -0
  11. package/dist/src/common/volcengineClient/index.js +99 -0
  12. package/dist/src/common/volcengineClient/tlsOperations.js +256 -0
  13. package/dist/src/common/volcengineClient/tosOperations.js +440 -0
  14. package/dist/src/common/volcengineClient/types.js +26 -0
  15. package/dist/src/common/volcengineClient/vefaasOperations.js +386 -0
  16. package/dist/src/lang/en.js +120 -0
  17. package/dist/src/lang/zh-CN.js +119 -0
  18. package/dist/src/stack/aliyunStack/fc3Resource.js +18 -3
  19. package/dist/src/stack/deploy.js +4 -0
  20. package/dist/src/stack/volcengineStack/apigwExecutor.js +87 -0
  21. package/dist/src/stack/volcengineStack/apigwPlanner.js +110 -0
  22. package/dist/src/stack/volcengineStack/apigwResource.js +302 -0
  23. package/dist/src/stack/volcengineStack/apigwTypes.js +106 -0
  24. package/dist/src/stack/volcengineStack/deployer.js +59 -0
  25. package/dist/src/stack/volcengineStack/destroyer.js +72 -0
  26. package/dist/src/stack/volcengineStack/index.js +44 -0
  27. package/dist/src/stack/volcengineStack/planner.js +27 -0
  28. package/dist/src/stack/volcengineStack/tosExecutor.js +106 -0
  29. package/dist/src/stack/volcengineStack/tosPlanner.js +96 -0
  30. package/dist/src/stack/volcengineStack/tosResource.js +103 -0
  31. package/dist/src/stack/volcengineStack/tosTypes.js +65 -0
  32. package/dist/src/stack/volcengineStack/vefaasExecutor.js +102 -0
  33. package/dist/src/stack/volcengineStack/vefaasPlanner.js +84 -0
  34. package/dist/src/stack/volcengineStack/vefaasResource.js +513 -0
  35. package/dist/src/stack/volcengineStack/vefaasTypes.js +75 -0
  36. package/dist/src/types/domains/state.js +3 -0
  37. package/dist/src/validator/functionSchema.js +13 -0
  38. package/dist/src/validator/rootSchema.js +1 -1
  39. package/dist/tsconfig.tsbuildinfo +1 -1
  40. package/package.json +8 -2
  41. package/samples/volcengine-poc-advanced.yml +59 -0
  42. package/samples/volcengine-poc-api.yml +31 -0
  43. package/samples/volcengine-poc-bucket.yml +17 -0
  44. package/samples/volcengine-poc-function.yml +19 -0
  45. package/samples/volcengine-poc-vpc.yml +34 -0
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.executeFunctionPlan = void 0;
4
+ const types_1 = require("../../types");
5
+ const vefaasResource_1 = require("./vefaasResource");
6
+ const common_1 = require("../../common");
7
+ const stateManager_1 = require("../../common/stateManager");
8
+ const lang_1 = require("../../lang");
9
+ const executeCreateAction = async (context, fn, currentState) => {
10
+ common_1.logger.info(lang_1.lang.__('CREATING_RESOURCE', { resourceType: 'function', name: fn.name }));
11
+ const newState = await (0, vefaasResource_1.createResource)(context, fn, currentState);
12
+ common_1.logger.info(lang_1.lang.__('RESOURCE_CREATED', { resourceType: 'function', name: fn.name }));
13
+ return newState;
14
+ };
15
+ const executeUpdateAction = async (context, fn, currentState) => {
16
+ common_1.logger.info(lang_1.lang.__('UPDATING_RESOURCE', { resourceType: 'function', name: fn.name }));
17
+ const newState = await (0, vefaasResource_1.updateResource)(context, fn, currentState);
18
+ common_1.logger.info(lang_1.lang.__('RESOURCE_UPDATED', { resourceType: 'function', name: fn.name }));
19
+ return newState;
20
+ };
21
+ const executeDeleteAction = async (context, functionName, logicalId, currentState) => {
22
+ common_1.logger.info(lang_1.lang.__('DELETING_RESOURCE', { resourceType: 'function', name: functionName }));
23
+ const newState = await (0, vefaasResource_1.deleteResource)(context, functionName, logicalId, currentState);
24
+ common_1.logger.info(lang_1.lang.__('RESOURCE_DELETED', { resourceType: 'function', name: functionName }));
25
+ return newState;
26
+ };
27
+ const executeSingleItem = async (context, item, functionsMap, currentState) => {
28
+ switch (item.action) {
29
+ case 'noop':
30
+ common_1.logger.info(lang_1.lang.__('NO_CHANGESForResource', { logicalId: item.logicalId }));
31
+ return null;
32
+ case 'create': {
33
+ const fn = functionsMap.get(item.logicalId);
34
+ if (!fn) {
35
+ throw new Error(`Function not found for logical ID: ${item.logicalId}`);
36
+ }
37
+ return executeCreateAction(context, fn, currentState);
38
+ }
39
+ case 'update': {
40
+ const fn = functionsMap.get(item.logicalId);
41
+ if (!fn) {
42
+ throw new Error(`Function not found for logical ID: ${item.logicalId}`);
43
+ }
44
+ return executeUpdateAction(context, fn, currentState);
45
+ }
46
+ case 'delete': {
47
+ const state = (0, stateManager_1.getResource)(currentState, item.logicalId);
48
+ if (!state) {
49
+ common_1.logger.warn(lang_1.lang.__('STATE_NOT_FOUND_SKIPPING', { logicalId: item.logicalId }));
50
+ return null;
51
+ }
52
+ const functionName = state.definition.functionName;
53
+ return executeDeleteAction(context, functionName, item.logicalId, currentState);
54
+ }
55
+ default:
56
+ common_1.logger.warn(lang_1.lang.__('UNKNOWN_ACTION_FOR_RESOURCE', { action: item.action, logicalId: item.logicalId }));
57
+ return null;
58
+ }
59
+ };
60
+ const executeFunctionPlan = async (context, plan, functions, initialState, onStateChange) => {
61
+ const functionsMap = new Map(functions?.map((fn) => [`functions.${fn.key}`, fn]) ?? []);
62
+ const successfulItems = [];
63
+ let currentState = initialState;
64
+ for (const item of plan.items) {
65
+ try {
66
+ const newState = await executeSingleItem(context, item, functionsMap, currentState);
67
+ if (newState !== null) {
68
+ currentState = newState;
69
+ successfulItems.push(item);
70
+ if (onStateChange) {
71
+ onStateChange(currentState);
72
+ }
73
+ }
74
+ }
75
+ catch (error) {
76
+ if (error instanceof types_1.PartialResourceError) {
77
+ const updatedState = error.updatedState;
78
+ if (onStateChange) {
79
+ onStateChange(updatedState);
80
+ }
81
+ return {
82
+ state: updatedState,
83
+ partialFailure: {
84
+ failedItem: item,
85
+ error: error.cause,
86
+ successfulItems,
87
+ },
88
+ };
89
+ }
90
+ return {
91
+ state: currentState,
92
+ partialFailure: {
93
+ failedItem: item,
94
+ error: error instanceof Error ? error : new Error(String(error)),
95
+ successfulItems,
96
+ },
97
+ };
98
+ }
99
+ }
100
+ return { state: currentState };
101
+ };
102
+ exports.executeFunctionPlan = executeFunctionPlan;
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateFunctionPlan = void 0;
4
+ const common_1 = require("../../common");
5
+ const stateManager_1 = require("../../common/stateManager");
6
+ const volcengineClient_1 = require("../../common/volcengineClient");
7
+ const vefaasTypes_1 = require("./vefaasTypes");
8
+ const planFunctionDeletion = (logicalId, definition) => ({
9
+ logicalId,
10
+ action: 'delete',
11
+ resourceType: 'VOLCENGINE_VEFAAS',
12
+ changes: { before: definition },
13
+ });
14
+ const generateFunctionPlan = async (context, state, functions) => {
15
+ if (!functions || functions.length === 0) {
16
+ const allStates = (0, stateManager_1.getAllResources)(state);
17
+ const items = Object.entries(allStates)
18
+ .filter(([logicalId]) => logicalId.startsWith('functions.'))
19
+ .map(([logicalId, resourceState]) => planFunctionDeletion(logicalId, resourceState.definition));
20
+ return { items };
21
+ }
22
+ const desiredLogicalIds = new Set(functions.map((fn) => `functions.${fn.key}`));
23
+ const functionItems = await Promise.all(functions.map(async (fn) => {
24
+ const logicalId = `functions.${fn.key}`;
25
+ const currentState = (0, common_1.getResource)(state, logicalId);
26
+ const config = (0, vefaasTypes_1.functionToVefaasConfig)(fn);
27
+ const codePath = fn.code.path;
28
+ const desiredCodeHash = (0, common_1.computeFileHash)(codePath);
29
+ const desiredDefinition = (0, vefaasTypes_1.extractVefaasDefinition)(config, desiredCodeHash);
30
+ if (!currentState || currentState.status === 'tainted') {
31
+ return {
32
+ logicalId,
33
+ action: 'create',
34
+ resourceType: 'VOLCENGINE_VEFAAS',
35
+ changes: { after: desiredDefinition },
36
+ };
37
+ }
38
+ try {
39
+ const client = (0, volcengineClient_1.createVolcengineClient)(context);
40
+ const remoteFunction = await client.vefaas.getFunction(fn.name);
41
+ if (!remoteFunction) {
42
+ return {
43
+ logicalId,
44
+ action: 'create',
45
+ resourceType: 'VOLCENGINE_VEFAAS',
46
+ changes: {
47
+ before: currentState.definition,
48
+ after: desiredDefinition,
49
+ },
50
+ drifted: true,
51
+ };
52
+ }
53
+ const currentDefinition = currentState.definition || {};
54
+ const definitionChanged = !(0, common_1.attributesEqual)(currentDefinition, desiredDefinition);
55
+ if (definitionChanged) {
56
+ return {
57
+ logicalId,
58
+ action: 'update',
59
+ resourceType: 'VOLCENGINE_VEFAAS',
60
+ changes: { before: currentDefinition, after: desiredDefinition },
61
+ drifted: true,
62
+ };
63
+ }
64
+ return { logicalId, action: 'noop', resourceType: 'VOLCENGINE_VEFAAS' };
65
+ }
66
+ catch {
67
+ return {
68
+ logicalId,
69
+ action: 'create',
70
+ resourceType: 'VOLCENGINE_VEFAAS',
71
+ changes: {
72
+ before: currentState.definition,
73
+ after: desiredDefinition,
74
+ },
75
+ };
76
+ }
77
+ }));
78
+ const allStates = (0, stateManager_1.getAllResources)(state);
79
+ const deletionItems = Object.entries(allStates)
80
+ .filter(([logicalId]) => logicalId.startsWith('functions.') && !desiredLogicalIds.has(logicalId))
81
+ .map(([logicalId, resourceState]) => planFunctionDeletion(logicalId, resourceState.definition));
82
+ return { items: [...functionItems, ...deletionItems] };
83
+ };
84
+ exports.generateFunctionPlan = generateFunctionPlan;