@geek-fun/serverlessinsight 0.0.6 → 0.2.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 (63) hide show
  1. package/dist/package.json +24 -14
  2. package/dist/src/commands/deploy.js +2 -1
  3. package/dist/src/commands/destroy.js +10 -0
  4. package/dist/src/commands/index.js +28 -13
  5. package/dist/src/commands/template.js +26 -0
  6. package/dist/src/commands/validate.js +4 -5
  7. package/dist/src/common/actionContext.js +13 -7
  8. package/dist/src/common/base64.js +5 -0
  9. package/dist/src/common/constants.js +4 -0
  10. package/dist/src/common/iacHelper.js +48 -12
  11. package/dist/src/common/imsClient.js +52 -0
  12. package/dist/src/common/index.d.ts +4 -1
  13. package/dist/src/common/index.js +4 -1
  14. package/dist/src/common/providerEnum.js +11 -0
  15. package/dist/src/common/rosClient.js +92 -9
  16. package/dist/src/parser/databaseParser.js +33 -0
  17. package/dist/src/parser/eventParser.js +15 -0
  18. package/dist/src/parser/functionParser.js +20 -0
  19. package/dist/src/parser/index.d.ts +2 -0
  20. package/dist/src/parser/index.js +36 -0
  21. package/dist/src/parser/tagParser.js +10 -0
  22. package/dist/src/stack/deploy.js +57 -13
  23. package/dist/src/stack/index.d.ts +0 -2
  24. package/dist/src/stack/index.js +0 -16
  25. package/dist/src/stack/rfsStack/function.js +32 -0
  26. package/dist/src/stack/rfsStack/index.d.ts +9 -0
  27. package/dist/src/stack/rfsStack/index.js +39 -0
  28. package/dist/src/stack/rosStack/bootstrap.js +40 -0
  29. package/dist/src/stack/rosStack/database.js +314 -0
  30. package/dist/src/stack/rosStack/event.js +136 -0
  31. package/dist/src/stack/rosStack/function.js +108 -0
  32. package/dist/src/stack/rosStack/index.d.ts +7 -0
  33. package/dist/src/stack/rosStack/index.js +69 -0
  34. package/dist/src/stack/rosStack/stage.js +46 -0
  35. package/dist/src/stack/rosStack/tag.js +11 -0
  36. package/dist/src/stack/rosStack/vars.js +49 -0
  37. package/dist/src/types/assets.js +2 -0
  38. package/dist/src/types/domains/context.js +8 -0
  39. package/dist/src/types/domains/database.js +2 -0
  40. package/dist/src/types/domains/function.js +2 -0
  41. package/dist/src/types/domains/provider.js +2 -0
  42. package/dist/src/types/domains/tag.js +2 -0
  43. package/dist/src/types/domains/vars.js +2 -0
  44. package/dist/src/types/index.d.ts +44 -0
  45. package/dist/src/types/index.js +23 -0
  46. package/dist/src/validator/databaseSchema.js +83 -0
  47. package/dist/src/validator/eventSchema.js +41 -0
  48. package/dist/src/validator/functionSchema.js +45 -0
  49. package/dist/src/validator/iacSchema.js +42 -0
  50. package/dist/src/validator/index.d.ts +1 -0
  51. package/dist/src/validator/index.js +5 -0
  52. package/dist/src/validator/rootSchema.js +52 -0
  53. package/dist/tsconfig.tsbuildinfo +1 -1
  54. package/package.json +24 -14
  55. package/samples/aliyun-poc-es.yml +30 -0
  56. package/samples/aliyun-poc-fc.yml +60 -0
  57. package/samples/aliyun-poc-rds.yml +24 -0
  58. package/samples/huawei-poc-fc.yml +60 -0
  59. package/dist/src/common/provider.js +0 -11
  60. package/dist/src/stack/iacSchema.js +0 -145
  61. package/dist/src/stack/iacStack.js +0 -146
  62. package/dist/src/stack/parse.js +0 -46
  63. /package/dist/src/{types.js → types/domains/event.js} +0 -0
@@ -1,146 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.IacStack = void 0;
27
- const ros = __importStar(require("@alicloud/ros-cdk-core"));
28
- const ros_cdk_core_1 = require("@alicloud/ros-cdk-core");
29
- const types_1 = require("../types");
30
- const fc = __importStar(require("@alicloud/ros-cdk-fc3"));
31
- const ram = __importStar(require("@alicloud/ros-cdk-ram"));
32
- const agw = __importStar(require("@alicloud/ros-cdk-apigateway"));
33
- const common_1 = require("../common");
34
- class IacStack extends ros.Stack {
35
- constructor(scope, iac, context) {
36
- super(scope, iac.service, {
37
- stackName: context.stackName,
38
- tags: iac.tags.reduce((acc, tag) => {
39
- acc[tag.key] = (0, common_1.replaceReference)(tag.value, context.stage);
40
- return acc;
41
- }, {}),
42
- });
43
- // Define Parameters
44
- Object.entries(iac.vars).map(([key, value]) => new ros.RosParameter(this, key, {
45
- type: ros_cdk_core_1.RosParameterType.STRING,
46
- defaultValue: value,
47
- }));
48
- // Define Mappings
49
- new ros.RosMapping(this, 'stages', { mapping: (0, common_1.replaceReference)(iac.stages, context.stage) });
50
- new ros.RosInfo(this, ros.RosInfo.description, (0, common_1.replaceReference)(`${iac.service} stack`, context.stage));
51
- iac.functions.forEach((fnc) => {
52
- new fc.RosFunction(this, fnc.key, {
53
- functionName: (0, common_1.replaceReference)(fnc.name, context.stage),
54
- handler: (0, common_1.replaceReference)(fnc.handler, context.stage),
55
- runtime: (0, common_1.replaceReference)(fnc.runtime, context.stage),
56
- memorySize: (0, common_1.replaceReference)(fnc.memory, context.stage),
57
- timeout: (0, common_1.replaceReference)(fnc.timeout, context.stage),
58
- environmentVariables: (0, common_1.replaceReference)(fnc.environment, context.stage),
59
- code: {
60
- zipFile: (0, common_1.resolveCode)(fnc.code),
61
- },
62
- }, true);
63
- });
64
- const apiGateway = iac.events?.filter((event) => event.type === types_1.EventTypes.API_GATEWAY);
65
- if (apiGateway?.length) {
66
- const gatewayAccessRole = new ram.RosRole(this, (0, common_1.replaceReference)(`${iac.service}_role`, context.stage), {
67
- roleName: (0, common_1.replaceReference)(`${iac.service}-gateway-access-role`, context.stage),
68
- description: (0, common_1.replaceReference)(`${iac.service} role`, context.stage),
69
- assumeRolePolicyDocument: {
70
- version: '1',
71
- statement: [
72
- {
73
- action: 'sts:AssumeRole',
74
- effect: 'Allow',
75
- principal: {
76
- service: ['apigateway.aliyuncs.com'],
77
- },
78
- },
79
- ],
80
- },
81
- policies: [
82
- {
83
- policyName: (0, common_1.replaceReference)(`${iac.service}-policy`, context.stage),
84
- policyDocument: {
85
- version: '1',
86
- statement: [
87
- {
88
- action: ['fc:InvokeFunction'],
89
- effect: 'Allow',
90
- // @TODO implement at least permission granting
91
- resource: ['*'],
92
- },
93
- ],
94
- },
95
- },
96
- ],
97
- }, true);
98
- const apiGatewayGroup = new agw.RosGroup(this, (0, common_1.replaceReference)(`${iac.service}_apigroup`, context.stage), {
99
- groupName: (0, common_1.replaceReference)(`${iac.service}_apigroup`, context.stage),
100
- tags: (0, common_1.replaceReference)(iac.tags, context.stage),
101
- }, true);
102
- // new agw.RosCustomDomain(
103
- // this,
104
- // 'customDomain',
105
- // {
106
- // domainName: 'example.com',
107
- // certificateName: 'example.com',
108
- // certificateBody: 'example.com',
109
- // certificatePrivateKey: 'example.com',
110
- // groupId: apiGatewayGroup.attrGroupId,
111
- // },
112
- // true,
113
- // );
114
- apiGateway.forEach((event) => {
115
- event.triggers.forEach((trigger) => {
116
- const key = `${trigger.method}_${trigger.path}`.toLowerCase().replace(/\//g, '_');
117
- const api = new agw.RosApi(this, (0, common_1.replaceReference)(`${event.key}_api_${key}`, context.stage), {
118
- apiName: (0, common_1.replaceReference)(`${event.name}_api_${key}`, context.stage),
119
- groupId: apiGatewayGroup.attrGroupId,
120
- visibility: 'PRIVATE',
121
- requestConfig: {
122
- requestProtocol: 'HTTP',
123
- requestHttpMethod: (0, common_1.replaceReference)(trigger.method, context.stage),
124
- requestPath: (0, common_1.replaceReference)(trigger.path, context.stage),
125
- requestMode: 'PASSTHROUGH',
126
- },
127
- serviceConfig: {
128
- serviceProtocol: 'FunctionCompute',
129
- functionComputeConfig: {
130
- fcRegionId: context.region,
131
- functionName: (0, common_1.replaceReference)(trigger.backend, trigger.backend),
132
- roleArn: gatewayAccessRole.attrArn,
133
- fcVersion: '3.0',
134
- },
135
- },
136
- resultSample: 'ServerlessInsight resultSample',
137
- resultType: 'JSON',
138
- tags: (0, common_1.replaceReference)(iac.tags, context.stage),
139
- }, true);
140
- api.addDependsOn(apiGatewayGroup);
141
- });
142
- });
143
- }
144
- }
145
- }
146
- exports.IacStack = IacStack;
@@ -1,46 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseYaml = void 0;
4
- const yaml_1 = require("yaml");
5
- const node_fs_1 = require("node:fs");
6
- const iacSchema_1 = require("./iacSchema");
7
- const mapToArr = (obj) => {
8
- if (!obj) {
9
- return [];
10
- }
11
- return Object.entries(obj)?.map(([key, value]) => typeof value === 'string' ? { [key]: value } : { key, ...value });
12
- };
13
- const mapToKvArr = (obj) => {
14
- if (!obj) {
15
- return [];
16
- }
17
- return Object.entries(obj)?.map(([key, value]) => ({ key, value }));
18
- };
19
- const validateExistence = (path) => {
20
- if (!(0, node_fs_1.existsSync)(path)) {
21
- throw new Error(`File does not exist at path: ${path}`);
22
- }
23
- };
24
- const transformYaml = (iacJson) => {
25
- return {
26
- service: iacJson.service,
27
- version: iacJson.version,
28
- provider: iacJson.provider,
29
- vars: iacJson.vars,
30
- stages: iacJson.stages,
31
- functions: mapToArr(iacJson.functions),
32
- events: mapToArr(iacJson.events),
33
- tags: [
34
- { key: 'iac-provider', value: 'ServerlessInsight' },
35
- ...mapToKvArr(iacJson.tags),
36
- ],
37
- };
38
- };
39
- const parseYaml = (yamlPath) => {
40
- validateExistence(yamlPath);
41
- const yamlContent = (0, node_fs_1.readFileSync)(yamlPath, 'utf8');
42
- const iacJson = (0, yaml_1.parse)(yamlContent);
43
- (0, iacSchema_1.validateYaml)(iacJson);
44
- return transformYaml(iacJson);
45
- };
46
- exports.parseYaml = parseYaml;
File without changes