@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
@@ -0,0 +1,100 @@
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 } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
23
+
24
+ const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase, firstLetterUpperCase } = require("../../../../../MainLibs/src/Utils")
25
+ const { DEFAULT_HANDLER_PER_ACTION, SOURCE_PATH } = require("../../../libs/Consts");
26
+
27
+ const templatePath = path.join(__dirname, "./template.ejs")
28
+
29
+ /**
30
+ * receive objectSchema
31
+ * create data for hdrInv template
32
+ *
33
+ * @param {Object} objectSchema
34
+ * @return {{ templatePath, templateData, setting } }
35
+ */
36
+ function data(_izContext, objectSchema, srcPath) {
37
+ let createSourceArray = [];
38
+
39
+ for (const action of Object.values(ACTIONS)) {
40
+ if (objectSchema.overWriteHandlers?.[action]) {
41
+ // if have overWriteHander of action check hdrInv inside
42
+ if (objectSchema.overWriteHandlers[action].includes(HANDLER.hdrApi)) {
43
+ // create template data
44
+ const createSourceParam = createParamForCreateSource(objectSchema, action, srcPath)
45
+ createSourceArray.push(createSourceParam)
46
+ }
47
+ } else {
48
+ // if not have overWriteHander of action will use default handler
49
+ const defaultHandler = DEFAULT_HANDLER_PER_ACTION[action]
50
+ if (defaultHandler.includes(HANDLER.hdrApi)) {
51
+ // create template data and object for create source
52
+ const createSourceParam = createParamForCreateSource(objectSchema, action, srcPath)
53
+ createSourceArray.push(createSourceParam)
54
+ }
55
+ }
56
+ }
57
+
58
+ return createSourceArray;
59
+ }
60
+
61
+
62
+ function createParamForCreateSource(objectSchema, action, srcPath) {
63
+ let objectType = objectSchema.objectType;
64
+ let actionHandler = action;
65
+ let functionName = objectType + firstLetterUpperCase(action);
66
+ return {
67
+ templatePath: templatePath,
68
+ templateData: {
69
+ functionName: functionName,
70
+ objectType: objectType,
71
+ actionHandler: actionHandler,
72
+ isCreateMainFunction: (objectSchema.overwriteGeneratedMainFunction?.length
73
+ && objectSchema.overwriteGeneratedMainFunction.includes(action)
74
+ ) ? true : false,
75
+ },
76
+ setting: {
77
+ savePath: path.join(srcPath, SOURCE_PATH.lambdaPerAction),
78
+ saveFileName: `${upperCase(objectSchema.objectType)}${upperCase(action)}_HdrApi`,
79
+ fileExtension: '.js',
80
+ isAppend: false
81
+ }
82
+ }
83
+ }
84
+
85
+
86
+ // [
87
+ // {
88
+ // 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',
89
+ // templateData: { tableName: 'ObjectTypeSingle', attributes: [Array] },
90
+ // setting: {
91
+ // savePath: '/generatedCode/source/',
92
+ // saveFileName: 'ObjectTypeGet',
93
+ // fileExtension: '.js',
94
+ // isAppend: false
95
+ // }
96
+ // }
97
+ // ]
98
+
99
+
100
+ module.exports = data;
@@ -0,0 +1,7 @@
1
+ {
2
+ "objectType": "objectType",
3
+ "action": "get",
4
+ "mainFunction": "xxx",
5
+ "mainFunctionFile": "directoryOfMainFunction",
6
+ "isCreateMainByDev": "boolean"
7
+ }
@@ -0,0 +1,76 @@
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 izara = require("@izara_project/izara-middleware");
20
+ const middleware = izara.middlewareHandler;
21
+ const callingFlowSharedLib = require('@izara_project/izara-shared/src/CallingFlowSharedLib')
22
+ const {
23
+ validateSchemaMiddleware
24
+ } = require('@izara_project/izara-market-library-service-schemas/src/GenerateCodeLibs/src/GenerateCodeLibs');
25
+
26
+ <%_ if (isCreateMainFunction == true) { _%>
27
+ // user generate main function
28
+ <%_ } else { %>
29
+ const <%- functionName %> =require('./<%- firstLetterUpperCase(objectType) %><%- firstLetterUpperCase(actionHandler) %>_Main')
30
+ <%_ } _%>
31
+
32
+ //(<globalVarible>
33
+ //</globalVarible>)
34
+
35
+ //validate event params in middleware before into main function
36
+ validateSchemaMiddleware(
37
+ middleware,
38
+ "<%- firstLetterUpperCase(objectType) %>",
39
+ "<%- actionHandler %>"
40
+ //(<validateSchemaSetting>
41
+ //</validateSchemaSetting>)
42
+ )
43
+ // if need to validate authorizer or additional params , add code to hook tag below
44
+
45
+ //(<afterValidateWith>)
46
+ //(</afterValidateWith>)
47
+
48
+
49
+ module.exports.main = middleware.wrap(async (event, context, callback) => {
50
+ event._izContext.logger.debug('Event:', event);
51
+ try {
52
+ // invoke LambdaFunction
53
+ let lambdaFunctionResponse = await <%- functionName %>.<%- functionName %>Main(
54
+ event._izContext, // correlationId/logger/integrationTestDetail/uniqueRequestId/userId
55
+ event,
56
+ );
57
+
58
+ // return error to client
59
+ if (lambdaFunctionResponse instanceof Error) {
60
+ return (izara.response.failure(lambdaFunctionResponse));
61
+ }
62
+
63
+ // return success to client
64
+ return (izara.response.success(lambdaFunctionResponse));
65
+
66
+ } catch (err) {
67
+ event._izContext.logger.error('Error, <%- functionName %>Main: ', err);
68
+ return (izara.response.failure(err));
69
+ }
70
+ });
71
+ <%_ function firstLetterUpperCase(text){
72
+ return text.charAt(0).toUpperCase() + text.slice(1)
73
+ } _%>
74
+ <%_ function firstLetterLowerCase(str) {
75
+ return str.charAt(0).toLowerCase() + str.slice(1)
76
+ } _%>
@@ -0,0 +1,109 @@
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 } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
23
+
24
+
25
+ const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase, firstLetterUpperCase } = require("../../../../../MainLibs/src/Utils")
26
+ const { DEFAULT_HANDLER_PER_ACTION, SOURCE_PATH } = require("../../../libs/Consts");
27
+
28
+
29
+ const templatePath = path.join(__dirname, "./template.ejs")
30
+
31
+ /**
32
+ * receive objectSchema
33
+ * create data for hdrInv template
34
+ *
35
+ * @param {Object} objectSchema
36
+ * @return {{ templatePath, templateData, setting } }
37
+ */
38
+ function data(_izContext, objectSchema, srcPath) {
39
+ let createSourceArray = [];
40
+
41
+ for (const action of Object.values(ACTIONS)) {
42
+ if (objectSchema.overWriteHandlers?.[action]) {
43
+ // if have overWriteHander of action check hdrInv inside
44
+ if (objectSchema.overWriteHandlers[action].includes(HANDLER.hdrDsq)) {
45
+ // create template data
46
+ const createSourceParam = createParamForCreateSource(objectSchema, action, srcPath)
47
+ createSourceArray.push(createSourceParam)
48
+ }
49
+ } else {
50
+ // if not have overWriteHander of action will use default handler
51
+ const defaultHandler = DEFAULT_HANDLER_PER_ACTION[action]
52
+ if (defaultHandler.includes(HANDLER.hdrDsq)) {
53
+ // create template data and object for create source
54
+ const createSourceParam = createParamForCreateSource(objectSchema, action, srcPath)
55
+ createSourceArray.push(createSourceParam)
56
+ }
57
+ }
58
+ }
59
+
60
+ return createSourceArray;
61
+ }
62
+
63
+
64
+ function createParamForCreateSource(objectSchema, action, srcPath) {
65
+ let objectType = objectSchema.objectType;
66
+ let actionHandler = action;
67
+ let functionName = objectType + upperCase(action);
68
+ let queueName = objectType + firstLetterUpperCase(action) + "HdrSqs";
69
+ let identifiers = [];
70
+ for (const identifier of Object.values(objectSchema.identifiers)) {
71
+ identifiers.push(identifier.fieldName)
72
+ }
73
+ return {
74
+ templatePath: templatePath,
75
+ templateData: {
76
+ functionName: functionName,
77
+ objectType: objectType,
78
+ actionHandler: actionHandler,
79
+ queueName,
80
+ identifiers,
81
+ isCreateMainFunction: (objectSchema.overwriteGeneratedMainFunction?.length
82
+ && objectSchema.overwriteGeneratedMainFunction.includes(action)
83
+ ) ? true : false,
84
+ },
85
+ setting: {
86
+ savePath: path.join(srcPath, SOURCE_PATH.lambdaPerAction),
87
+ saveFileName: `${upperCase(objectSchema.objectType)}${upperCase(action)}_HdrDsq`,
88
+ fileExtension: '.js',
89
+ isAppend: false
90
+ }
91
+ }
92
+ }
93
+
94
+
95
+ // [
96
+ // {
97
+ // 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',
98
+ // templateData: { tableName: 'ObjectTypeSingle', attributes: [Array] },
99
+ // setting: {
100
+ // savePath: '/generatedCode/source/',
101
+ // saveFileName: 'ObjectTypeGet',
102
+ // fileExtension: '.js',
103
+ // isAppend: false
104
+ // }
105
+ // }
106
+ // ]
107
+
108
+
109
+ module.exports = data;
@@ -0,0 +1,7 @@
1
+ {
2
+ "objectType": "objectType",
3
+ "action": "get",
4
+ "mainFunction": "xxx",
5
+ "mainFunctionFile": "directoryOfMainFunction",
6
+ "isCreateMainByDev": "boolean"
7
+ }
@@ -0,0 +1,105 @@
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 izara = require("@izara_project/izara-middleware");
20
+ const middleware = izara.middlewareHandler;
21
+ const callingFlowSharedLib = require('@izara_project/izara-shared/src/CallingFlowSharedLib');
22
+ const recordHandlerSharedLib = require('@izara_project/izara-shared').recordHandlerSharedLib;
23
+ const {
24
+ validateSchemaMiddleware
25
+ } = require('@izara_project/izara-market-library-service-schemas/src/GenerateCodeLibs/src/GenerateCodeLibs');
26
+ const Logger = require('@izara_project/izara-core-library-logger');
27
+
28
+ <%_ if (isCreateMainFunction == true) { _%>
29
+ // user generate main function
30
+ <%_ } else { %>
31
+ const <%- functionName %> =require('./<%- firstLetterUpperCase(objectType) %><%- firstLetterUpperCase(actionHandler) %>_Main')
32
+ <%_ } _%>
33
+
34
+ const perRecordsValidatorSchema = {
35
+ type: "object",
36
+ required: ['identifiers'],
37
+ properties: {
38
+ identifiers: {
39
+ type: "object"
40
+ }
41
+ }
42
+ }
43
+
44
+ module.exports.main = middleware.wrap(async(event,context,callback) => {
45
+
46
+ try {
47
+
48
+ let recordPromises = []; // final return
49
+
50
+ // loop each record and send to mainFunction
51
+ await Promise.all(event.Records.map(async record => { // promise.all for map() function
52
+
53
+ // --- reforming record.body for Dsq request
54
+ record = recordHandlerSharedLib.reformatDsqMessage(record._izContext, record);
55
+ record._izContext.logger.debug('record LambdaFunctionHdrDsq after reform', record);
56
+
57
+ let passOnProperties = []
58
+
59
+ // --- validate message (and MessageAttributes)
60
+ await recordHandlerSharedLib.validateRecord(
61
+ record, // one record will send to mainFunction
62
+ "<%- queueName %>", // queue name that need to retry or send to dlq
63
+ perRecordsValidatorSchema, // schema for record.Message
64
+ // messageAttributeValidatorSchema // ----- for msgAttr default is null -> do not send this parameter if not want to validate msgAtt
65
+ );
66
+
67
+ // add argument (to invoke lambda) to passOnProperties[]
68
+ passOnProperties.push(record.body.Message)
69
+ record._izContext.logger.debug('passOnProperties in handler', passOnProperties);
70
+
71
+ // call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
72
+ let recordPromise = recordHandlerSharedLib.recordHandler(
73
+ record, // one record will send to mainFunction
74
+ <%- functionName %>.<%- functionName %>Main, // mainFunction that need to invoke.
75
+ "<%- queueName %>", // queue name that need to retry or send to dlq
76
+ passOnProperties, // all parameters that mainFunction needed.
77
+ );
78
+ record._izContext.logger.debug('after recordPromise in handler');
79
+ recordPromises.push(recordPromise); // push promise to recordPromises
80
+ })) //end record
81
+
82
+ Logger.debug('before Promise.all(recordPromises) in handler');
83
+ try {
84
+ await Promise.all(recordPromises); // await all promises
85
+ return event.Records // return all for local test
86
+ } catch {
87
+ Logger.debug('Promise.all(recordPromises) in handler threw error (at least one record did no resolve)');
88
+ }
89
+ Logger.debug('after Promise.all(recordPromises) in handler');
90
+ } catch (err) {
91
+ Logger.error('Unhandled Error, <%- firstLetterUpperCase(objectType) %><%- firstLetterUpperCase(actionHandler) %>Dsq :', err);
92
+ throw (err);
93
+ }
94
+ })
95
+
96
+
97
+
98
+
99
+
100
+ <%_ function firstLetterUpperCase(text){
101
+ return text.charAt(0).toUpperCase() + text.slice(1)
102
+ } _%>
103
+ <%_ function firstLetterLowerCase(str) {
104
+ return str.charAt(0).toLowerCase() + str.slice(1)
105
+ } _%>
@@ -0,0 +1,102 @@
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 } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
23
+
24
+ const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase, firstLetterUpperCase } = require("../../../../../MainLibs/src/Utils")
25
+ const { DEFAULT_HANDLER_PER_ACTION, SOURCE_PATH } = require("../../../libs/Consts");
26
+
27
+
28
+ const templatePath = path.join(__dirname, "./template.ejs")
29
+
30
+ /**
31
+ * receive objectSchema
32
+ * create data for hdrInv template
33
+ *
34
+ * @param {Object} objectSchema
35
+ * @return {{ templatePath, templateData, setting } }
36
+ */
37
+ function data(_izContext, objectSchema, srcPath) {
38
+ let createSourceArray = [];
39
+
40
+ for (const action of Object.values(ACTIONS)) {
41
+ if (objectSchema.overWriteHandlers?.[action]) {
42
+ // if have overWriteHander of action check hdrInv inside
43
+ if (objectSchema.overWriteHandlers[action].includes(HANDLER.hdrInv)) {
44
+ // create template data
45
+ const createSourceParam = createParamForCreateSource(objectSchema, action, srcPath)
46
+ createSourceArray.push(createSourceParam)
47
+ }
48
+ } else {
49
+ // if not have overWriteHander of action will use default handler
50
+ const defaultHandler = DEFAULT_HANDLER_PER_ACTION[action]
51
+ if (defaultHandler.includes(HANDLER.hdrInv)) {
52
+ // create template data and object for create source
53
+ const createSourceParam = createParamForCreateSource(objectSchema, action, srcPath)
54
+ createSourceArray.push(createSourceParam)
55
+ }
56
+ }
57
+ }
58
+ console.log("createSourceArrayInHdrInv", createSourceArray)
59
+ return createSourceArray;
60
+ }
61
+
62
+
63
+ function createParamForCreateSource(objectSchema, action, srcPath) {
64
+ let objectType = objectSchema.objectType;
65
+ let actionHandler = action;
66
+ let functionName = objectType + upperCase(action);
67
+
68
+ return {
69
+ templatePath: templatePath,
70
+ templateData: {
71
+ functionName: functionName,
72
+ objectType: objectType,
73
+ actionHandler: actionHandler,
74
+ isCreateMainFunction: (objectSchema.overwriteGeneratedMainFunction?.length
75
+ && objectSchema.overwriteGeneratedMainFunction.includes(action)
76
+ ) ? true : false,
77
+ },
78
+ setting: {
79
+ savePath: path.join(srcPath, SOURCE_PATH.lambdaPerAction),
80
+ saveFileName: `${upperCase(objectSchema.objectType)}${upperCase(action)}_HdrInv`,
81
+ fileExtension: '.js',
82
+ isAppend: false
83
+ }
84
+ }
85
+ }
86
+
87
+
88
+ // [
89
+ // {
90
+ // 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',
91
+ // templateData: { tableName: 'ObjectTypeSingle', attributes: [Array] },
92
+ // setting: {
93
+ // savePath: '/generatedCode/source/',
94
+ // saveFileName: 'ObjectTypeGet',
95
+ // fileExtension: '.js',
96
+ // isAppend: false
97
+ // }
98
+ // }
99
+ // ]
100
+
101
+
102
+ module.exports = data;
@@ -0,0 +1,7 @@
1
+ {
2
+ "objectType": "objectType",
3
+ "action": "get",
4
+ "mainFunction": "xxx",
5
+ "mainFunctionFile": "directoryOfMainFunction",
6
+ "isCreateMainByDev": "boolean"
7
+ }
@@ -0,0 +1,82 @@
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 middleware = require("@izara_project/izara-middleware/src/MiddlewareCore/MiddlewareHandler");
21
+
22
+ const callingFlowSharedLib = require('@izara_project/izara-shared/src/CallingFlowSharedLib')
23
+
24
+
25
+ const {
26
+ validateSchemaMiddleware
27
+ } = require('@izara_project/izara-market-library-service-schemas/src/GenerateCodeLibs/src/GenerateCodeLibs');
28
+
29
+
30
+ <%_ if (isCreateMainFunction == true) { _%>
31
+ // user generate main function
32
+ <%_ } else { %>
33
+ const <%- functionName %> =require('./<%- firstLetterUpperCase(objectType) %><%- firstLetterUpperCase(actionHandler) %>_Main')
34
+ <%_ } _%>
35
+
36
+ //(<globalVariable>
37
+ //</globalVariable>)
38
+
39
+
40
+ //validate event params in middleware before into function
41
+ validateSchemaMiddleware(
42
+ middleware,
43
+ "<%- firstLetterUpperCase(objectType) %>", // objectType
44
+ "<%- actionHandler %>", // action
45
+ //(<validateSchemaSetting>)
46
+ //(</validateSchemaSetting>)
47
+ )
48
+
49
+ // if need to validate authorizer or additional params, add code to hook tag below
50
+
51
+ //(<afterValidateWithGenereatedSchema>)
52
+ //(</afterValidateWithGenereatedSchema>)
53
+
54
+
55
+ module.exports.main = middleware.wrap(async (event, context, callback) => {
56
+ event._izContext.logger.debug('Event:', event);
57
+ event._izContext.logger.debug('context:', context);
58
+
59
+ try {
60
+
61
+ //(<beforeInvoke>)
62
+ //(</beforeInvoke>)
63
+
64
+ // invoke LambdaFunction
65
+ return await <%- functionName %>.<%- functionName %>Main(
66
+ event._izContext, // correlationId/logger/integrationTestDetail/uniqueRequestId
67
+ event,
68
+ callingFlowSharedLib.addCallingFlowToPassOnProperties(event)
69
+ );
70
+
71
+ } catch (err) {
72
+ event._izContext.logger.error('Error, <%- firstLetterUpperCase(objectType) %>: ', err);
73
+ throw (err);
74
+ }
75
+ });
76
+
77
+ <%_ function firstLetterUpperCase(text){
78
+ return text.charAt(0).toUpperCase() + text.slice(1)
79
+ } _%>
80
+ <%_ function firstLetterLowerCase(str) {
81
+ return str.charAt(0).toLowerCase() + str.slice(1)
82
+ } _%>