@izara_project/izara-market-library-service-schemas 1.0.2 → 1.0.3

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/package.json +1 -1
  2. package/src/SourceManager/src/CreateSource.js +0 -1
  3. package/src/SourceManager/src/Utils.js +15 -1
  4. package/src/TemplateManager/src/FunctionYaml/HdrApi/data.js +170 -0
  5. package/src/TemplateManager/src/FunctionYaml/HdrApi/request.json +14 -0
  6. package/src/TemplateManager/src/FunctionYaml/HdrApi/template.ejs +33 -0
  7. package/src/TemplateManager/src/FunctionYaml/HdrDsq/data.js +178 -0
  8. package/src/TemplateManager/src/FunctionYaml/HdrDsq/request.json +19 -0
  9. package/src/TemplateManager/src/FunctionYaml/HdrDsq/template.ejs +30 -0
  10. package/src/TemplateManager/src/FunctionYaml/HdrInv/data.js +169 -0
  11. package/src/TemplateManager/src/{PerActionEndpoint/TemplateAndData/ResourceYaml/Lambda/Template/HdrInv.exampleData.js → FunctionYaml/HdrInv/example req.js } +3 -3
  12. package/src/TemplateManager/src/FunctionYaml/HdrInv/request.json +14 -0
  13. package/src/TemplateManager/src/{PerActionEndpoint/TemplateAndData/ResourceYaml/Lambda/Template/HdrInv.ejs → FunctionYaml/HdrInv/template.ejs} +5 -5
  14. package/src/TemplateManager/src/FunctionYaml/HdrSqs/data.js +184 -0
  15. package/src/TemplateManager/src/FunctionYaml/HdrSqs/request.json +19 -0
  16. package/src/TemplateManager/src/FunctionYaml/HdrSqs/template.ejs +30 -0
  17. package/src/TemplateManager/src/GenerateCode(Old).js +135 -0
  18. package/src/TemplateManager/src/GenerateCode.js +86 -14
  19. package/src/TemplateManager/src/MainResourcesYaml/CreateSourceData.js +2 -2
  20. package/src/TemplateManager/src/MainResourcesYaml/TemplateAndData/DynamoDbMain/Data/MainDynamoDbYamlData.js +3 -1
  21. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrApi/data.js +100 -0
  22. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrApi/request.json +7 -0
  23. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrApi/template.ejs +76 -0
  24. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrDsq/data.js +109 -0
  25. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrDsq/request.json +7 -0
  26. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrDsq/template.ejs +105 -0
  27. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrInv/data.js +102 -0
  28. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrInv/request.json +7 -0
  29. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrInv/template.ejs +82 -0
  30. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrSqs/data.js +102 -0
  31. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrSqs/request.json +7 -0
  32. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrSqs/template.ejs +124 -0
  33. package/src/TemplateManager/src/PerActionEndpoint/Handler/testRequest.json +5 -0
  34. package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Get/data.js +88 -0
  35. package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Get/request.json +5 -0
  36. package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Get/template.ejs +219 -0
  37. package/src/TemplateManager/src/ResourceYaml/CreateSourceData.js +76 -0
  38. package/src/TemplateManager/src/ResourceYaml/dynamodb/mainResourcePerObjectSchemaData.js +173 -0
  39. package/src/TemplateManager/src/ResourceYaml/dynamodb/processLogicalAndFindData.js +102 -0
  40. package/src/TemplateManager/src/ResourceYaml/dynamodb/request.json +7 -0
  41. package/src/TemplateManager/src/ResourceYaml/dynamodb/template.ejs +31 -0
  42. package/src/TemplateManager/src/ResourceYaml/sns-in-sqs/defaultSnsInSqsForFindDataAndProcessLogical.js +81 -0
  43. package/src/TemplateManager/src/ResourceYaml/sns-in-sqs/request.json +4 -0
  44. package/src/TemplateManager/src/ResourceYaml/sns-in-sqs/snsAndSqsPerActiondata.js +108 -0
  45. package/src/TemplateManager/src/ResourceYaml/sns-in-sqs/snsTemplate.ejs +59 -0
  46. package/src/TemplateManager/src/ResourceYaml/sns-in-sqs/sqsTemplate.ejs +42 -0
  47. package/src/TemplateManager/src/externalService/LambdaRole/data.js +147 -0
  48. package/src/TemplateManager/src/externalService/LambdaRole/request.json +18 -0
  49. package/src/TemplateManager/src/externalService/LambdaRole/template.ejs +52 -0
  50. package/src/TemplateManager/src/{PerActionEndpoint/TemplateAndData/MainFunction/MainFunctionTemplate/Delete.js → externalService/SnsTopicSubscriotions/data.js} +13 -0
  51. package/src/TemplateManager/src/externalService/SnsTopicSubscriotions/template.ejs +14 -0
  52. package/src/TemplateManager/src/libs/Consts.js +39 -1
  53. package/src/TemplateManager/src/PerActionEndpoint/CreateSourceData.js +0 -131
  54. package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/Handler/Handler.js +0 -0
  55. package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/MainFunction/MainFunctionTemplate/Create.js +0 -18
  56. package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/MainFunction/MainFunctionTemplate/Get.js +0 -18
  57. package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/MainFunction/MainFunctionTemplate/Update.js +0 -18
  58. package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/MainFunction/MainFunctionTemplateData.js +0 -0
  59. package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/ResourceYaml/Lambda/Data/LambdaYamlData.js +0 -166
  60. package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/ResourceYaml/Lambda/Template/HdrApi.ejs +0 -0
  61. package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/ResourceYaml/Lambda/Template/HdrDsq.ejs +0 -0
  62. package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/ResourceYaml/Lambda/Template/HdrSqs.ejs +0 -0
  63. /package/src/TemplateManager/src/{PerActionEndpoint/DataPerActionEndpoint.js → externalService/SnsTopicSubscriotions/request.json} +0 -0
@@ -1,7 +1,7 @@
1
1
  <%_ const join = require('path').join; _%>
2
- <%- firstLetterUpperCase(resourceName) %><%- firstLetterUpperCase(handlerType) %>:
3
- handler: <%- join(resourceLocation, `${firstLetterUpperCase(resourceName)}_${firstLetterUpperCase(handlerType)}.main`)%>
4
- name: ${self:custom.iz_resourcePrefix}<%- firstLetterUpperCase(resourceName) %><%- firstLetterUpperCase(handlerType) %>
2
+ <%- firstLetterUpperCase(functionName) %><%- firstLetterUpperCase(handlerType) %>:
3
+ handler: <%- join(resourceLocation, `${firstLetterUpperCase(functionName)}_${firstLetterUpperCase(handlerType)}.main`)%>
4
+ name: ${self:custom.iz_resourcePrefix}<%- firstLetterUpperCase(functionName) %><%- firstLetterUpperCase(handlerType) %>
5
5
  iamRoleStatements:
6
6
  <%_ additionalResourcePermission.forEach(resourcePermission => { _%>
7
7
  - Effect: <%- resourcePermission.effect %>
@@ -16,8 +16,8 @@
16
16
  - <%- resource %>
17
17
  <%_ }) _%>
18
18
  <%_}) _%>
19
- #<#<%- resourceName %><%- handlerType %>IamRole#>
20
- #<#/<%- resourceName %><%- handlerType %>IamRole#>
19
+ #<#<%- functionName %><%- handlerType %>IamRole#>
20
+ #<#/<%- functionName %><%- handlerType %>IamRole#>
21
21
  <%_ function firstLetterUpperCase(text){
22
22
  return text.charAt(0).toUpperCase() + text.slice(1)
23
23
  } _%>
@@ -0,0 +1,184 @@
1
+ /*
2
+ Copyright (C) 2020 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ 'use strict';
19
+ const path = require('path');
20
+ const fs = require('fs');
21
+
22
+ const { ACTIONS, HANDLER, STORAGE_TYPES } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
23
+
24
+ const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("../../../../MainLibs/src/Utils")
25
+ const { DEFAULT_HANDLER_PER_ACTION, createIamRole, resourceNames, RESOURCE_CLASSES, DEFAULT_LAMBDA_ROLE_PER_ACTION, SQS_RESOURCE, SOURCE_PATH } = require("../../libs/Consts");
26
+
27
+ const templatePath = path.join(__dirname, "./template.ejs")
28
+
29
+
30
+ function defaultIamRolePerAction() {
31
+
32
+ let defaultIamRole = [];
33
+
34
+
35
+ defaultIamRole.push(
36
+ createIamRole(
37
+ {
38
+ [RESOURCE_CLASSES.s3]: ["GetObject", "GetObjectVersion"],
39
+ },
40
+ [
41
+ resourceNames(RESOURCE_CLASSES.s3, "object-schema/perServiceSchemas/*"),
42
+ resourceNames(RESOURCE_CLASSES.s3, "object-schema/serviceConfig/ServiceNameConfig.json"),
43
+ resourceNames(RESOURCE_CLASSES.s3, "object-schema/serviceConfig/GraphServerTags.json"),
44
+ ]
45
+ )
46
+ );
47
+
48
+ defaultIamRole.push(
49
+ createIamRole(
50
+ { [RESOURCE_CLASSES.s3]: ["ListBucket"] },
51
+ [
52
+ resourceNames(RESOURCE_CLASSES.s3, "object-schema"),
53
+ ]
54
+ )
55
+ );
56
+
57
+ return defaultIamRole
58
+ }
59
+
60
+ /**
61
+ * receive objectSchema
62
+ * create data for hdrInv template
63
+ *
64
+ * @param {Object} objectSchema
65
+ * @return {{ templatePath, templateData, setting } }
66
+ */
67
+ function data(_izContext, objectSchema, srcPath) {
68
+ let createSourceArray = [];
69
+ for (const action of Object.values(ACTIONS)) {
70
+ if (objectSchema.overWriteHandlers?.[action]) {
71
+ // if have overWriteHander of action check hdrApi inside
72
+ if (objectSchema.overWriteHandlers[action].includes(HANDLER.hdrSqs)) {
73
+ // create template data
74
+ const createSourceParam = createParamForCreateSource(objectSchema, action, srcPath)
75
+ createSourceArray.push(createSourceParam)
76
+ }
77
+ } else {
78
+ // if not have overWriteHander of action will use default handler
79
+ const defaultHandler = DEFAULT_HANDLER_PER_ACTION[action]
80
+ if (defaultHandler.includes(HANDLER.hdrSqs)) {
81
+ // create template data and object for create source
82
+ const createSourceParam = createParamForCreateSource(objectSchema, action, srcPath)
83
+ createSourceArray.push(createSourceParam)
84
+ }
85
+ }
86
+ }
87
+ return createSourceArray;
88
+ }
89
+
90
+
91
+
92
+ function createParamForCreateSource(objectSchema, action, srcPath) {
93
+ let objectType = objectSchema.objectType;
94
+ let actionHandler = action;
95
+ let functionName = objectType + upperCase(actionHandler);
96
+ let additionalResourcePermission = defaultIamRolePerAction();
97
+ let tableForGetItem = [];
98
+ let hasGraphStorage = false;
99
+ for (let storageResource of Object.values(objectSchema.storageResources)) {
100
+ if (storageResource.storageType === STORAGE_TYPES.dynamoDB) {
101
+ // add IamRole for dynamodb depend on tableName in storageResources of objectSchema
102
+ tableForGetItem.push(resourceNames(RESOURCE_CLASSES.dynamoDbTable, storageResource.tableName));
103
+
104
+ } else if (storageResource.storageType === STORAGE_TYPES.graph) {
105
+ // find graph serviceName from graphServerTag or *GetNodeHdrInv ?
106
+
107
+ if (hasGraphStorage) {
108
+ continue;
109
+ } else {
110
+ hasGraphStorage = true;
111
+ }
112
+ }
113
+ }
114
+
115
+
116
+
117
+ if (tableForGetItem.length) {
118
+ additionalResourcePermission.push(
119
+ createIamRole(
120
+ { [RESOURCE_CLASSES.dynamoDbTable]: [DEFAULT_LAMBDA_ROLE_PER_ACTION[action].dynamoDbPermission] },
121
+ tableForGetItem
122
+ )
123
+ );
124
+ }
125
+
126
+ additionalResourcePermission.push(
127
+ createIamRole({
128
+ [RESOURCE_CLASSES.sqs]:
129
+ [
130
+ SQS_RESOURCE.deleteMessage,
131
+ SQS_RESOURCE.getQueueAttributes,
132
+ SQS_RESOURCE.recieveMessage,
133
+ SQS_RESOURCE.sendMessage
134
+ ]
135
+ }, [
136
+ resourceNames(RESOURCE_CLASSES.sqs, functionName + upperCase(HANDLER.hdrSqs)),
137
+ resourceNames(RESOURCE_CLASSES.sqs, functionName + upperCase(HANDLER.hdrSqs) + "DLQ")
138
+ ]
139
+ )
140
+ )
141
+
142
+ additionalResourcePermission.push(
143
+ createIamRole({
144
+ [RESOURCE_CLASSES.sns]: ["Publish", "Subscribe"]
145
+ }, [resourceNames(RESOURCE_CLASSES.sns, functionName + upperCase(HANDLER.hdrSqs))])
146
+ )
147
+
148
+ console.log("additionalResourcePermissionBeforeReturn", additionalResourcePermission)
149
+ return {
150
+ templatePath: templatePath,
151
+ templateData: {
152
+ functionName: functionName,
153
+ actionHandler: actionHandler,
154
+ resourceLocation: SOURCE_PATH.resourceLocation,
155
+ handlerType: "HdrSqs",
156
+ additionalResourcePermission
157
+ },
158
+ setting: {
159
+ savePath: path.join(srcPath, SOURCE_PATH.appYaml),
160
+ saveFileName: `function`,
161
+ fileExtension: '.yml',
162
+ isAppend: true
163
+ }
164
+ }
165
+ }
166
+
167
+
168
+
169
+
170
+ // [
171
+ // {
172
+ // templatePath: '/home/toughnut/BasProgram/empty-service-template/app/node_modules/@izara_project/izara-market-library-service-schemas/src/TemplateManager/src/MainResourcesYaml/TemplateAndData/DynamoDbMain/Template/DynamoDb.ejs',
173
+ // templateData: { tableName: 'ObjectTypeSingle', attributes: [Array] },
174
+ // setting: {
175
+ // savePath: '/generatedCode/source/',
176
+ // saveFileName: 'ObjectTypeGet',
177
+ // fileExtension: '.js',
178
+ // isAppend: false
179
+ // }
180
+ // }
181
+ // ]
182
+
183
+
184
+ module.exports = data;
@@ -0,0 +1,19 @@
1
+ {
2
+ "functionName": "xxx",
3
+ "handler": "hdrSqs",
4
+ "event": {
5
+ "sqs": {
6
+ "arn": "queueName"
7
+ },
8
+ "iamRoleStatement": {
9
+ "Effect": "Allow",
10
+ "Action": {
11
+ "xxx": [
12
+ "yyy",
13
+ "xxx"
14
+ ]
15
+ },
16
+ "Resource": "xxxx"
17
+ }
18
+ }
19
+ }
@@ -0,0 +1,30 @@
1
+ <%_ const join = require('path').join; _%>
2
+ <%- firstLetterUpperCase(functionName) %><%- firstLetterUpperCase(handlerType) %>:
3
+ handler: <%- join(resourceLocation, `${firstLetterUpperCase(functionName)}_${firstLetterUpperCase(handlerType)}.main`)%>
4
+ name: ${self:custom.iz_resourcePrefix}<%- firstLetterUpperCase(functionName) %><%- firstLetterUpperCase(handlerType) %>
5
+ events:
6
+ - sqs:
7
+ arn: arn:aws:sqs:${self:custom.iz_region}:${self:custom.iz_accountId}:${self:custom.iz_resourcePrefix}<%- firstLetterUpperCase(functionName) %><%- firstLetterUpperCase(handlerType) %>
8
+ batchSize: 10
9
+ iamRoleStatements:
10
+ <%_ additionalResourcePermission.forEach(resourcePermission => { _%>
11
+ - Effect: <%- resourcePermission.effect %>
12
+ Action:
13
+ <%_ Object.keys(resourcePermission.action).forEach(resourcePerAction => { _%>
14
+ <%_ resourcePermission.action[resourcePerAction].forEach(permission => { _%>
15
+ - <%- resourcePerAction %>:<%- permission %>
16
+ <%_}) _%>
17
+ <%_ }) _%>
18
+ Resource:
19
+ <%_ resourcePermission.resource.forEach(resource => { _%>
20
+ - <%- resource %>
21
+ <%_ }) _%>
22
+ <%_}) _%>
23
+ #<#<%- functionName %><%- handlerType %>IamRole#>
24
+ #<#/<%- functionName %><%- handlerType %>IamRole#>
25
+ <%_ function firstLetterUpperCase(text){
26
+ return text.charAt(0).toUpperCase() + text.slice(1)
27
+ } _%>
28
+ <%_ function firstLetterLowerCase(str) {
29
+ return str.charAt(0).toLowerCase() + str.slice(1)
30
+ } _%>
@@ -0,0 +1,135 @@
1
+ /*
2
+ Copyright (C) 2020 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ 'use strict';
19
+
20
+ const join = require('path').join;
21
+ const { readFileSync } = require('fs');
22
+
23
+
24
+ const {
25
+ getAllLocalObjectSchemasWithHierarchy,
26
+ getAllLocalRelationshipSchemas
27
+ } = require('@izara_project/izara-core-library-service-schemas/src/GetObjectSchema');
28
+
29
+
30
+
31
+ const { createSource } = require("../../SourceManager/src/CreateSource");
32
+ const { deleteFileInDir } = require("../../SourceManager/src/Utils");
33
+
34
+ const perAction = require("./PerActionEndpoint/CreateSourceData");
35
+
36
+ const mainResources = require("./MainResourcesYaml/CreateSourceData");
37
+
38
+
39
+ /**
40
+ *
41
+ * get template and send to
42
+ *
43
+ * @param {object} objSchemaPath
44
+ * @returns
45
+ *
46
+ * add another param
47
+ * {string[]} objectTypes
48
+ * {string[]} templates
49
+ * {string} saveFilePath
50
+ */
51
+ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
52
+
53
+ try {
54
+
55
+ // point to app/src
56
+ let saveFilePath = join(objSchemaPath, `../`);
57
+
58
+ // define path for store yml file
59
+ const GENERATECODE_SOURCE_PATH = {
60
+ appYaml: join(saveFilePath, `../sls_yaml/generatedCode/source/`),
61
+ resourceYaml: join(saveFilePath, `../../resource/sls_yaml/generatedCode/source/`),
62
+ lambdaPerObjectTypePath: join(saveFilePath, `/generatedCode/lambdaPerObjectType/source/`), // test
63
+ lamdaPerCombindActionPath: join(saveFilePath, `/generatedCode/lamdaPerCombindAction/source/`), // test
64
+ };
65
+
66
+
67
+ // from app/src/shcemas
68
+ let allObjSchemas = await getAllLocalObjectSchemasWithHierarchy(_izContext, objSchemaPath);
69
+
70
+ const allObjectRelationships = await getAllLocalRelationshipSchemas(_izContext, objSchemaPath);
71
+
72
+ /*
73
+ Should we generateCode with objectSchema that not in hierarchy or not?
74
+ Should use objectSchema with hierarchy because we use storageResource of parent to create lambda iam role in .yml file
75
+ */
76
+
77
+ let createSourceParams = [];
78
+
79
+ for (const relTag in allObjectRelationships) {
80
+ const relTagData = allObjectRelationships[relTag];
81
+
82
+ // create main resource per relationshipSchema
83
+ const createSourceMainResourcesRelSchema = mainResources.createSourceDataRelSchema(_izContext, { [relTag]: relTagData }, saveFilePath);
84
+ console.log("createSourceMainResourcesRelSchema: ", createSourceMainResourcesRelSchema);
85
+
86
+ createSourceParams = createSourceParams.concat(createSourceMainResourcesRelSchema);
87
+ }
88
+
89
+
90
+ //
91
+ for (let objectSchema of allObjSchemas.records) {
92
+
93
+ // create main resource per objectSchema
94
+ let createSourceMainResourcesObjectSchema = mainResources.createSourceDataObjectSchema(_izContext, objectSchema, saveFilePath);
95
+ // console.log("createSourceMainResourcesObjectSchema: ", createSourceMainResourcesObjectSchema);
96
+
97
+ // mainFunction, handlerFunction, resourceYaml per action
98
+ let createSourcePerAction = perAction.createSourceDataObjectSchema(_izContext, objectSchema, saveFilePath);
99
+ // console.log("createSourcePerAction: ", createSourcePerAction)
100
+
101
+
102
+
103
+ // console.log("createSourceParams begore concat: ", createSourceParams);
104
+
105
+ createSourceParams = createSourceParams.concat([...createSourcePerAction, ...createSourceMainResourcesObjectSchema]);
106
+
107
+ // console.log("createSourceParams after concat: ", createSourceParams);
108
+ }
109
+
110
+
111
+ // delete file .yml before start to prevent confilct of data
112
+ for (let folderPathToEmpty of Object.keys(GENERATECODE_SOURCE_PATH)) {
113
+ await deleteFileInDir(GENERATECODE_SOURCE_PATH[folderPathToEmpty]);
114
+ }
115
+
116
+
117
+ // start create source
118
+ for (let { templatePath, templateData, setting } of createSourceParams) {
119
+ await createSource(
120
+ readFileSync(templatePath, 'utf8'),
121
+ templateData,
122
+ setting,
123
+ );
124
+ }
125
+
126
+
127
+ return "return values";
128
+
129
+ } catch (err) {
130
+ console.log('error templateManager: ', err);
131
+ throw (err);
132
+ }
133
+ };
134
+
135
+ module.exports = { generateCodeWithTemplate };
@@ -27,13 +27,42 @@ const {
27
27
  } = require('@izara_project/izara-core-library-service-schemas/src/GetObjectSchema');
28
28
 
29
29
 
30
+ const {
31
+ getGraphServiceNameFromGraphServerTagWithCache
32
+ } = require('@izara_project/izara-core-library-service-schemas/src/ServiceConfig');
30
33
 
31
34
  const { createSource } = require("../../SourceManager/src/CreateSource");
32
35
  const { deleteFileInDir } = require("../../SourceManager/src/Utils");
36
+ // create handler function
37
+ const perActionHdrInvData = require("./PerActionEndpoint/Handler/HdrInv/data");
38
+ const perActionHdrApiData = require("./PerActionEndpoint/Handler/HdrApi/data");
39
+ const perActionHdrSqsData = require("./PerActionEndpoint/Handler/HdrSqs/data");
40
+ const perActionHdrDsqData = require("./PerActionEndpoint/Handler/HdrDsq/data");
41
+
42
+ // create Main funcion
43
+ const mainFunctionGetData = require('./PerActionEndpoint/MainFunction/Get/data');
44
+
45
+ // create function.yaml
46
+ const functionGetYamlDataHdrInv = require('./FunctionYaml/HdrInv/data');
47
+ const functionGetYamlDataHdrApi = require('./FunctionYaml/HdrApi/data');
48
+ const functionGetYamlDataHdrSqs = require('./FunctionYaml/HdrSqs/data');
49
+ const functionGetYamlDataHdrDsq = require('./FunctionYaml/HdrDsq/data');
50
+
33
51
 
34
- const perAction = require("./PerActionEndpoint/CreateSourceData");
52
+ // create Main resource
53
+ const { createSourceDataDynamoDB } = require('./ResourceYaml/dynamodb/mainResourcePerObjectSchemaData');
54
+ const { createDefaultSourceDataDynamoDB } = require('./ResourceYaml/dynamodb/processLogicalAndFindData')
55
+ const { createSourceSnsAndSqs } = require('./ResourceYaml/sns-in-sqs/snsAndSqsPerActiondata');
56
+ const createFindDataAndProcessLogicalDefaultSnsInSqs = require('./ResourceYaml/sns-in-sqs/defaultSnsInSqsForFindDataAndProcessLogical')
35
57
 
36
- const mainResources = require("./MainResourcesYaml/CreateSourceData");
58
+ // create External Service
59
+ const createSnsSubscriptions = require('./externalService/SnsTopicSubscriotions/data');
60
+ const createLambdaRole = require('./externalService/LambdaRole/data');
61
+
62
+
63
+
64
+ //create resource
65
+ // const mainResources = require("./MainResourcesYaml/CreateSourceData");
37
66
 
38
67
 
39
68
  /**
@@ -59,16 +88,19 @@ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
59
88
  const GENERATECODE_SOURCE_PATH = {
60
89
  appYaml: join(saveFilePath, `../sls_yaml/generatedCode/source/`),
61
90
  resourceYaml: join(saveFilePath, `../../resource/sls_yaml/generatedCode/source/`),
62
- lambdaPerObjectTypePath: join(saveFilePath, `/generatedCode/lambdaPerObjectType/source/`), // test
63
- lamdaPerCombindActionPath: join(saveFilePath, `/generatedCode/lamdaPerCombindAction/source/`), // test
91
+ lambdaPerObjectTypePath: join(saveFilePath, `/generatedCode/perAction/source/`), // test
92
+ lamdaPerCombindActionPath: join(saveFilePath, `/generatedCode/lamdaPerCombindAction/source/`), // test,
93
+ externalService: join(saveFilePath, '../initial_setup/generatedCode/source/')
64
94
  };
65
95
 
66
96
 
67
97
  // from app/src/shcemas
68
98
  let allObjSchemas = await getAllLocalObjectSchemasWithHierarchy(_izContext, objSchemaPath);
99
+ // _izContext.logger.debug("allObjSchemas: ", allObjSchemas)
69
100
 
70
101
  const allObjectRelationships = await getAllLocalRelationshipSchemas(_izContext, objSchemaPath);
71
102
 
103
+ // _izContext.logger.debug("allObjectRelationships: ", allObjectRelationships)
72
104
  /*
73
105
  Should we generateCode with objectSchema that not in hierarchy or not?
74
106
  Should use objectSchema with hierarchy because we use storageResource of parent to create lambda iam role in .yml file
@@ -77,32 +109,70 @@ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
77
109
  let createSourceParams = [];
78
110
 
79
111
  for (const relTag in allObjectRelationships) {
80
- const relTagData = allObjectRelationships[relTag];
112
+ // const relTagData = allObjectRelationships[relTag];
81
113
 
82
114
  // create main resource per relationshipSchema
83
- const createSourceMainResourcesRelSchema = mainResources.createSourceDataRelSchema(_izContext, { [relTag]: relTagData }, saveFilePath);
84
- console.log("createSourceMainResourcesRelSchema: ", createSourceMainResourcesRelSchema);
115
+ // const createSourceMainResourcesRelSchema = mainResources.createSourceDataRelSchema(_izContext, { [relTag]: relTagData }, saveFilePath);
116
+ // console.log("createSourceMainResourcesRelSchema: ", createSourceMainResourcesRelSchema);
85
117
 
86
- createSourceParams = createSourceParams.concat(createSourceMainResourcesRelSchema);
118
+ // createSourceParams = createSourceParams.concat(createSourceMainResourcesRelSchema);
87
119
  }
88
120
 
89
-
121
+ // create External service
122
+ const createFunctionIamRole = await createLambdaRole(_izContext, allObjSchemas.records, saveFilePath);
90
123
  //
91
124
  for (let objectSchema of allObjSchemas.records) {
125
+ console.log("objectSchema: ", objectSchema);
92
126
 
93
127
  // create main resource per objectSchema
94
- let createSourceMainResourcesObjectSchema = mainResources.createSourceDataObjectSchema(_izContext, objectSchema, saveFilePath);
128
+ // const createSourceMainResourcesObjectSchema = mainResources.createSourceDataObjectSchema(_izContext, objectSchema, saveFilePath);
95
129
  // console.log("createSourceMainResourcesObjectSchema: ", createSourceMainResourcesObjectSchema);
96
130
 
97
131
  // mainFunction, handlerFunction, resourceYaml per action
98
- let createSourcePerAction = perAction.createSourceDataObjectSchema(_izContext, objectSchema, saveFilePath);
132
+ // let createSourcePerAction = perAction.createSourceDataObjectSchema(_izContext, objectSchema, saveFilePath);
99
133
  // console.log("createSourcePerAction: ", createSourcePerAction)
100
134
 
135
+ // generate handler
136
+ const createSourceHdrInv = perActionHdrInvData(_izContext, objectSchema, saveFilePath);
137
+ const createSourceHdrApi = perActionHdrApiData(_izContext, objectSchema, saveFilePath);
138
+ const createSourceHdrSqs = perActionHdrSqsData(_izContext, objectSchema, saveFilePath);
139
+ const createSourceHdrDsq = perActionHdrDsqData(_izContext, objectSchema, saveFilePath)
101
140
 
141
+ // wrap Handler Function
142
+ const createSourceHandler = [...createSourceHdrInv, ...createSourceHdrApi, ...createSourceHdrSqs, ...createSourceHdrDsq]
102
143
 
103
- // console.log("createSourceParams begore concat: ", createSourceParams);
144
+ // generate main function
145
+ const createMainFunctionGet = await mainFunctionGetData(_izContext, objectSchema, saveFilePath)
104
146
 
105
- createSourceParams = createSourceParams.concat([...createSourcePerAction, ...createSourceMainResourcesObjectSchema]);
147
+ // generate functionYaml File
148
+ const createFunctionGetYamlHdrInv = functionGetYamlDataHdrInv(_izContext, objectSchema, saveFilePath)
149
+ const createFunctionGetYamlHdrApi = functionGetYamlDataHdrApi(_izContext, objectSchema, saveFilePath)
150
+ const createFunctionGetYamlHdrSqs = functionGetYamlDataHdrSqs(_izContext, objectSchema, saveFilePath)
151
+ const createFunctionGetYamlHdrDsq = functionGetYamlDataHdrDsq(_izContext, objectSchema, saveFilePath)
152
+
153
+ // wrapMain Function
154
+ const createFunctionYaml = [...createFunctionGetYamlHdrApi, ...createFunctionGetYamlHdrDsq, ...createFunctionGetYamlHdrInv, ...createFunctionGetYamlHdrSqs]
155
+
156
+
157
+ // const createSnsSunbscription = createSnsSubscriptions.createSnsSubscription(_izContext, objectSchema, saveFilePath)
158
+
159
+ // generate Resource ..via dynamoDb sns-in-sqs sns-put
160
+ const createResourceDynamo = createSourceDataDynamoDB(_izContext, objectSchema, saveFilePath);
161
+ const createResourceSnsInSqs = createSourceSnsAndSqs(_izContext, objectSchema, saveFilePath);
162
+ const createResourceFindDataAndProcessLogical = createDefaultSourceDataDynamoDB(_izContext, saveFilePath);
163
+ const createResourceDefaultSnsInSqsFindDataAndProcessLogical = createFindDataAndProcessLogicalDefaultSnsInSqs(_izContext, saveFilePath);
164
+
165
+ // wrap main Resource
166
+ const createMainResource = [...createResourceDynamo, ...createResourceSnsInSqs, ...createResourceFindDataAndProcessLogical, ...createResourceDefaultSnsInSqsFindDataAndProcessLogical]
167
+
168
+ createSourceParams = createSourceParams.concat([
169
+ // ...createSourceMainResourcesObjectSchema,
170
+ ...createSourceHandler, // create handler function
171
+ ...createMainFunctionGet, // create main function
172
+ ...createFunctionYaml, // create function.yaml
173
+ ...createMainResource, // create resource yaml
174
+ createFunctionIamRole,
175
+ ]);
106
176
 
107
177
  // console.log("createSourceParams after concat: ", createSourceParams);
108
178
  }
@@ -113,9 +183,11 @@ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
113
183
  await deleteFileInDir(GENERATECODE_SOURCE_PATH[folderPathToEmpty]);
114
184
  }
115
185
 
116
-
186
+ // console.log("createSourceParams: ", createSourceParams)
117
187
  // start create source
118
188
  for (let { templatePath, templateData, setting } of createSourceParams) {
189
+ // console.log("templatePath in GenerateCode", templatePath);
190
+ // console.log("setting.savePath in GenerateCode", setting.savePath);
119
191
  await createSource(
120
192
  readFileSync(templatePath, 'utf8'),
121
193
  templateData,
@@ -40,7 +40,7 @@ module.exports.createSourceDataObjectSchema = (_izContext, objectSchema, saveFil
40
40
 
41
41
 
42
42
  const dynamoDbMainYamlDataList = dynamoDbMainYaml.dynamoDbMainYamlFromObjectSchema.templateDataFunction(_izContext, objectSchema);
43
- console.log("dynamoDbMainYamlDataList: ", dynamoDbMainYamlDataList);
43
+ // console.log("dynamoDbMainYamlDataList: ", dynamoDbMainYamlDataList);
44
44
 
45
45
  for (let dynamoDbMainYamlData of dynamoDbMainYamlDataList) {
46
46
  // create iam role of handler here
@@ -57,7 +57,7 @@ module.exports.createSourceDataObjectSchema = (_izContext, objectSchema, saveFil
57
57
  });
58
58
  }
59
59
 
60
- console.log("resultsForCreateSource: ", resultsForCreateSource);
60
+ // console.log("resultsForCreateSource: ", resultsForCreateSource);
61
61
 
62
62
  return resultsForCreateSource;
63
63
  }
@@ -52,6 +52,7 @@ function dataForMainDynamoDbYamlFromObjectSchema(_izContext, objectSchema) {
52
52
 
53
53
  // add identifiersDetail for dynamoDb storage
54
54
  for (let identifier of objectSchema.identifiers) {
55
+ // console.log("in identifiers")
55
56
  if (identifier.type === "partitionKey" || identifier.type === "sortKey") {
56
57
  identifiersDetail[identifier.type] = {};
57
58
 
@@ -83,7 +84,7 @@ function dataForMainDynamoDbYamlFromObjectSchema(_izContext, objectSchema) {
83
84
  }
84
85
  }
85
86
  }
86
-
87
+ // console.log("identifiersDetail: ", identifiersDetail)
87
88
  if (!identifiersDetail.hasOwnProperty("partitionKey")) {
88
89
  return [];
89
90
  }
@@ -118,6 +119,7 @@ function dataForMainDynamoDbYamlFromObjectSchema(_izContext, objectSchema) {
118
119
  }
119
120
  }
120
121
  dynamoDbYamlTemplateData.push(templateData);
122
+ // console.log("templateData: ", templateData)
121
123
  }
122
124
  }
123
125