@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.
- package/package.json +1 -1
- package/src/SourceManager/src/CreateSource.js +0 -1
- package/src/SourceManager/src/Utils.js +15 -1
- package/src/TemplateManager/src/FunctionYaml/HdrApi/data.js +170 -0
- package/src/TemplateManager/src/FunctionYaml/HdrApi/request.json +14 -0
- package/src/TemplateManager/src/FunctionYaml/HdrApi/template.ejs +33 -0
- package/src/TemplateManager/src/FunctionYaml/HdrDsq/data.js +178 -0
- package/src/TemplateManager/src/FunctionYaml/HdrDsq/request.json +19 -0
- package/src/TemplateManager/src/FunctionYaml/HdrDsq/template.ejs +30 -0
- package/src/TemplateManager/src/FunctionYaml/HdrInv/data.js +169 -0
- package/src/TemplateManager/src/{PerActionEndpoint/TemplateAndData/ResourceYaml/Lambda/Template/HdrInv.exampleData.js → FunctionYaml/HdrInv/example req.js } +3 -3
- package/src/TemplateManager/src/FunctionYaml/HdrInv/request.json +14 -0
- package/src/TemplateManager/src/{PerActionEndpoint/TemplateAndData/ResourceYaml/Lambda/Template/HdrInv.ejs → FunctionYaml/HdrInv/template.ejs} +5 -5
- package/src/TemplateManager/src/FunctionYaml/HdrSqs/data.js +184 -0
- package/src/TemplateManager/src/FunctionYaml/HdrSqs/request.json +19 -0
- package/src/TemplateManager/src/FunctionYaml/HdrSqs/template.ejs +30 -0
- package/src/TemplateManager/src/GenerateCode(Old).js +135 -0
- package/src/TemplateManager/src/GenerateCode.js +86 -14
- package/src/TemplateManager/src/MainResourcesYaml/CreateSourceData.js +2 -2
- package/src/TemplateManager/src/MainResourcesYaml/TemplateAndData/DynamoDbMain/Data/MainDynamoDbYamlData.js +3 -1
- package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrApi/data.js +100 -0
- package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrApi/request.json +7 -0
- package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrApi/template.ejs +76 -0
- package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrDsq/data.js +109 -0
- package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrDsq/request.json +7 -0
- package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrDsq/template.ejs +105 -0
- package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrInv/data.js +102 -0
- package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrInv/request.json +7 -0
- package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrInv/template.ejs +82 -0
- package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrSqs/data.js +102 -0
- package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrSqs/request.json +7 -0
- package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrSqs/template.ejs +124 -0
- package/src/TemplateManager/src/PerActionEndpoint/Handler/testRequest.json +5 -0
- package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Get/data.js +88 -0
- package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Get/request.json +5 -0
- package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Get/template.ejs +219 -0
- package/src/TemplateManager/src/ResourceYaml/CreateSourceData.js +76 -0
- package/src/TemplateManager/src/ResourceYaml/dynamodb/mainResourcePerObjectSchemaData.js +173 -0
- package/src/TemplateManager/src/ResourceYaml/dynamodb/processLogicalAndFindData.js +102 -0
- package/src/TemplateManager/src/ResourceYaml/dynamodb/request.json +7 -0
- package/src/TemplateManager/src/ResourceYaml/dynamodb/template.ejs +31 -0
- package/src/TemplateManager/src/ResourceYaml/sns-in-sqs/defaultSnsInSqsForFindDataAndProcessLogical.js +81 -0
- package/src/TemplateManager/src/ResourceYaml/sns-in-sqs/request.json +4 -0
- package/src/TemplateManager/src/ResourceYaml/sns-in-sqs/snsAndSqsPerActiondata.js +108 -0
- package/src/TemplateManager/src/ResourceYaml/sns-in-sqs/snsTemplate.ejs +59 -0
- package/src/TemplateManager/src/ResourceYaml/sns-in-sqs/sqsTemplate.ejs +42 -0
- package/src/TemplateManager/src/externalService/LambdaRole/data.js +147 -0
- package/src/TemplateManager/src/externalService/LambdaRole/request.json +18 -0
- package/src/TemplateManager/src/externalService/LambdaRole/template.ejs +52 -0
- package/src/TemplateManager/src/{PerActionEndpoint/TemplateAndData/MainFunction/MainFunctionTemplate/Delete.js → externalService/SnsTopicSubscriotions/data.js} +13 -0
- package/src/TemplateManager/src/externalService/SnsTopicSubscriotions/template.ejs +14 -0
- package/src/TemplateManager/src/libs/Consts.js +39 -1
- package/src/TemplateManager/src/PerActionEndpoint/CreateSourceData.js +0 -131
- package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/Handler/Handler.js +0 -0
- package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/MainFunction/MainFunctionTemplate/Create.js +0 -18
- package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/MainFunction/MainFunctionTemplate/Get.js +0 -18
- package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/MainFunction/MainFunctionTemplate/Update.js +0 -18
- package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/MainFunction/MainFunctionTemplateData.js +0 -0
- package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/ResourceYaml/Lambda/Data/LambdaYamlData.js +0 -166
- package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/ResourceYaml/Lambda/Template/HdrApi.ejs +0 -0
- package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/ResourceYaml/Lambda/Template/HdrDsq.ejs +0 -0
- package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/ResourceYaml/Lambda/Template/HdrSqs.ejs +0 -0
- /package/src/TemplateManager/src/{PerActionEndpoint/DataPerActionEndpoint.js → externalService/SnsTopicSubscriotions/request.json} +0 -0
|
@@ -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
|
+
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.hdrSqs)) {
|
|
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.hdrSqs)) {
|
|
51
|
+
// create template data and object for create source
|
|
52
|
+
const createSourceParam = createParamForCreateSource(objectSchema, action, srcPath)
|
|
53
|
+
createSourceArray.push(createSourceParam)
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
console.log("createSourceArray in sqsData :", createSourceArray)
|
|
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
|
+
let queueName = objectType + firstLetterUpperCase(action) + "HdrSqs"
|
|
67
|
+
return {
|
|
68
|
+
templatePath: templatePath,
|
|
69
|
+
templateData: {
|
|
70
|
+
functionName: functionName,
|
|
71
|
+
objectType: objectType,
|
|
72
|
+
actionHandler: actionHandler,
|
|
73
|
+
queueName,
|
|
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)}_HdrSqs`,
|
|
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,124 @@
|
|
|
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
|
+
const Logger = require('@izara_project/izara-core-library-logger');
|
|
26
|
+
const recordHandlerSharedLib = require('@izara_project/izara-shared').recordHandlerSharedLib
|
|
27
|
+
|
|
28
|
+
<%_ if (isCreateMainFunction == true) { _%>
|
|
29
|
+
// user generate main function
|
|
30
|
+
<%_ } else { %>
|
|
31
|
+
const <%- functionName %> =require('./<%- firstLetterUpperCase(objectType) %><%- firstLetterUpperCase(actionHandler) %>_Main')
|
|
32
|
+
<%_ } _%>
|
|
33
|
+
|
|
34
|
+
//(<globalVarible>
|
|
35
|
+
//</globalVarible>)
|
|
36
|
+
|
|
37
|
+
const perRecordValidatorSchema = {
|
|
38
|
+
type: "object",
|
|
39
|
+
required: ['identifiers'],
|
|
40
|
+
properties: {
|
|
41
|
+
identifiers: {
|
|
42
|
+
type: 'object'
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const messageAttributeValidatorSchema = {
|
|
48
|
+
type: "object",
|
|
49
|
+
require: ['msgAtrrParam1','msgAtrrParam2'],
|
|
50
|
+
properties: {
|
|
51
|
+
msgAtrrParam1: {
|
|
52
|
+
type: 'string'
|
|
53
|
+
},
|
|
54
|
+
msgAtrrParam2: {
|
|
55
|
+
type: 'string'
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
//validate event params in middleware before into main function
|
|
61
|
+
validateSchemaMiddleware(
|
|
62
|
+
middleware,
|
|
63
|
+
"<%- firstLetterUpperCase(objectType) %>",
|
|
64
|
+
"<%- actionHandler %>"
|
|
65
|
+
//(<validateSchemaSetting>
|
|
66
|
+
//</validateSchemaSetting>)
|
|
67
|
+
)
|
|
68
|
+
// if need to validate authorizer or additional params , add code to hook tag below
|
|
69
|
+
|
|
70
|
+
//(<afterValidateWith)
|
|
71
|
+
module.exports.main = middleware.wrap(async (event, context, callback) => {
|
|
72
|
+
try {
|
|
73
|
+
|
|
74
|
+
let recordPromises = [];
|
|
75
|
+
|
|
76
|
+
await Promise.all(event.Records.map(async record => {
|
|
77
|
+
|
|
78
|
+
let passOnProperties = [];
|
|
79
|
+
record._izContext.logger.debug('record ReceiveMesOutHdrSqs' , record);
|
|
80
|
+
|
|
81
|
+
// validate message (and MessageAttributes)
|
|
82
|
+
await recordHandlerSharedLib.validateRecord(
|
|
83
|
+
record,
|
|
84
|
+
"<%- functionName %>",
|
|
85
|
+
perRecordValidatorSchema,
|
|
86
|
+
// messageAttributeValidatorSchema
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
// add argument (to invoke lambda) to passOnProperties[]
|
|
90
|
+
passOnProperties.push(record.body.Message)
|
|
91
|
+
record._izContext.logger.debug("passOnProperties in handler", passOnProperties);
|
|
92
|
+
|
|
93
|
+
// call recordHandlerSharedLib.recordHandler with 3 parameters and return Promise (resolve)
|
|
94
|
+
let recordPromise = recordHandlerSharedLib.recordHandler(
|
|
95
|
+
record,
|
|
96
|
+
<%- functionName %>.<%- functionName %>Main,
|
|
97
|
+
"<%- queueName %>",
|
|
98
|
+
passOnProperties,
|
|
99
|
+
);
|
|
100
|
+
record._izContext.logger.debug('after recoedPromise in handler');
|
|
101
|
+
recordPromises.push(recordPromise);
|
|
102
|
+
}))
|
|
103
|
+
|
|
104
|
+
Logger.debug('before Promise.all(recordPromises) in handler');
|
|
105
|
+
try {
|
|
106
|
+
// --- main await all Promises
|
|
107
|
+
await Promise.all(recordPromises); // await all Promises
|
|
108
|
+
|
|
109
|
+
return event.Records // return all for local testing
|
|
110
|
+
} catch {
|
|
111
|
+
Logger.debug('Promise.all(recordPromises) in handler threw error (at least one record did not resolve)');
|
|
112
|
+
}
|
|
113
|
+
Logger.debug('after Promise,all(recordPromises) in handler');
|
|
114
|
+
} catch (err) {
|
|
115
|
+
Logger.error('unhandler Error , <%- functionName %>:', err);
|
|
116
|
+
throw (err);
|
|
117
|
+
}
|
|
118
|
+
})
|
|
119
|
+
<%_ function firstLetterUpperCase(text){
|
|
120
|
+
return text.charAt(0).toUpperCase() + text.slice(1)
|
|
121
|
+
} _%>
|
|
122
|
+
<%_ function firstLetterLowerCase(str) {
|
|
123
|
+
return str.charAt(0).toLowerCase() + str.slice(1)
|
|
124
|
+
} _%>
|
|
@@ -0,0 +1,88 @@
|
|
|
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
|
+
const { createGetDataDetails } = require('../../../../../GenerateCodeLibs/src/GenerateCodeLibs')
|
|
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
|
+
async function data(_izContext, objectSchema, srcPath) {
|
|
39
|
+
|
|
40
|
+
// let createSourceArray = [];
|
|
41
|
+
if (objectSchema.overwriteGeneratedMainFunction?.length
|
|
42
|
+
&& objectSchema.overwriteGeneratedMainFunction.includes(ACTIONS.get)
|
|
43
|
+
) {
|
|
44
|
+
return [];
|
|
45
|
+
} else {
|
|
46
|
+
return [await createParamForCreateSource(_izContext, objectSchema, ACTIONS.get, srcPath)]
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function createParamForCreateSource(_izContext, objectSchema, action, srcPath) {
|
|
51
|
+
let objectType = objectSchema.objectType;
|
|
52
|
+
let actionHandler = action;
|
|
53
|
+
let functionName = objectType + upperCase(action);
|
|
54
|
+
let getDataDetail = await createGetDataDetails(_izContext, objectSchema);
|
|
55
|
+
console.log({ getDataDetail })
|
|
56
|
+
return {
|
|
57
|
+
templatePath: templatePath,
|
|
58
|
+
templateData: {
|
|
59
|
+
functionName: functionName,
|
|
60
|
+
objectType: objectType,
|
|
61
|
+
actionHandler: actionHandler,
|
|
62
|
+
getDataDetail: JSON.stringify(getDataDetail)
|
|
63
|
+
},
|
|
64
|
+
setting: {
|
|
65
|
+
savePath: path.join(srcPath, SOURCE_PATH.lambdaPerAction),
|
|
66
|
+
saveFileName: `${upperCase(objectSchema.objectType)}${upperCase(action)}_Main`,
|
|
67
|
+
fileExtension: '.js',
|
|
68
|
+
isAppend: false
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
// [
|
|
75
|
+
// {
|
|
76
|
+
// 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',
|
|
77
|
+
// templateData: { tableName: 'ObjectTypeSingle', attributes: [Array] },
|
|
78
|
+
// setting: {
|
|
79
|
+
// savePath: '/generatedCode/source/',
|
|
80
|
+
// saveFileName: 'ObjectTypeGet',
|
|
81
|
+
// fileExtension: '.js',
|
|
82
|
+
// isAppend: false
|
|
83
|
+
// }
|
|
84
|
+
// }
|
|
85
|
+
// ]
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
module.exports = data;
|
|
@@ -0,0 +1,219 @@
|
|
|
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
|
|
16
|
+
<http: //www.gnu.org/licenses />.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
'use strict';
|
|
20
|
+
|
|
21
|
+
const {
|
|
22
|
+
getObjSchemaS3WithHierarchy,
|
|
23
|
+
} = require('@izara_project/izara-core-library-service-schemas/src/GetObjectSchema');
|
|
24
|
+
|
|
25
|
+
const {
|
|
26
|
+
getGraphServiceTagWithCache,
|
|
27
|
+
getServiceNameWithCache
|
|
28
|
+
} = require('@izara_project/izara-core-library-service-schemas/src/ServiceConfig');
|
|
29
|
+
|
|
30
|
+
const consts = require('@izara_project/izara-core-library-service-schemas/src/Consts');
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
const {
|
|
34
|
+
dynamoDbIdentifiersByStorageResource,
|
|
35
|
+
collectGetData
|
|
36
|
+
} = require('@izara_project/izara-market-library-service-schemas/src/GenerateCodeLibs/src/GenerateCodeLibs');
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
const dynamodbSharedLib = require('@izara_project/izara-shared/src/DynamodbSharedLib');
|
|
40
|
+
const graphSharedLib = require('@izara_project/izara-shared/src/GraphSharedLib');
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
const NoRetryError = require('@izara_project/izara-core-library-core/src/NoRetryError');
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
*
|
|
48
|
+
*
|
|
49
|
+
* description of function.
|
|
50
|
+
* @param {Object} _izContext
|
|
51
|
+
* @param {CorrelationIds} _izContext.correlationIds - property of _izContext
|
|
52
|
+
* @param {Logger} _izContext.logger - property of _izContext
|
|
53
|
+
* @param {Object} requestParams - request params
|
|
54
|
+
* @param {Object} requestParams.identifiers - identifiers for get data
|
|
55
|
+
* @param {Object} requestParams.additionalRequest - additionalRequest
|
|
56
|
+
*
|
|
57
|
+
*
|
|
58
|
+
* @returns {object} description of return value
|
|
59
|
+
*/
|
|
60
|
+
module.exports.<%- functionName %>Main = async (
|
|
61
|
+
_izContext,
|
|
62
|
+
requestParams,
|
|
63
|
+
callingFlowConfig = {},
|
|
64
|
+
//(<additionalParams>)
|
|
65
|
+
//(</additionalParams>)
|
|
66
|
+
) => {
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
try {
|
|
70
|
+
_izContext.logger.debug('<%- functionName %> _izContext: ', _izContext);
|
|
71
|
+
_izContext.logger.debug('<%- functionName %> requestParams: ', requestParams);
|
|
72
|
+
_izContext.logger.debug('<%- functionName %> callingFlowConfig: ', callingFlowConfig);
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
const OBJECT_TYPE = "<%- objectType %>";
|
|
76
|
+
const SERVICE_TAG = process.env.iz_serviceTag;
|
|
77
|
+
|
|
78
|
+
let getDataDetails = <%- getDataDetail %>
|
|
79
|
+
//(<beforeQuery>)
|
|
80
|
+
//(</beforeQuery>)
|
|
81
|
+
|
|
82
|
+
let objectSchema = await getObjSchemaS3WithHierarchy(
|
|
83
|
+
_izContext,
|
|
84
|
+
{
|
|
85
|
+
objectType: OBJECT_TYPE,
|
|
86
|
+
serviceTag: SERVICE_TAG
|
|
87
|
+
}
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
_izContext.logger.debug("objectSchema: ", objectSchema);
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
// start to get data
|
|
94
|
+
let getResults = {}; // for collect result data from
|
|
95
|
+
let getRecordStatus = {
|
|
96
|
+
getAtLeastOneRecord: false,
|
|
97
|
+
notFoundSomeRecord: false
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
await Promise.all(
|
|
101
|
+
Object.entries(getDataDetails).map(
|
|
102
|
+
async ([storageTag, getDataDetail]) => {
|
|
103
|
+
if (getDataDetail.storageType === consts.STORAGE_TYPES.graph) {
|
|
104
|
+
// get data from graph
|
|
105
|
+
let graphServiceName = await getServiceNameWithCache(_izContext, getDataDetail.graphServiceTag);
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
let versionedDataLabels = [];
|
|
109
|
+
if (getDataDetail.versionedDatas && Object.keys(getDataDetail.versionedDatas).length) {
|
|
110
|
+
// have versionedData
|
|
111
|
+
versionedDataLabels = Object.keys(getDataDetail.versionedDatas);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
//(<beforeGetGraph>)
|
|
116
|
+
//(</beforeGetGraph>)
|
|
117
|
+
|
|
118
|
+
let dataFromGraph = await graphSharedLib.getNode(
|
|
119
|
+
_izContext,
|
|
120
|
+
graphServiceName,
|
|
121
|
+
{
|
|
122
|
+
nodeLabel: OBJECT_TYPE,
|
|
123
|
+
nodeProperties: {
|
|
124
|
+
...requestParams.identifiers
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
versionedDataLabels
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
_izContext.logger.debug("dataFromGraph: ", dataFromGraph);
|
|
131
|
+
|
|
132
|
+
if (Object.keys(dataFromGraph).length) {
|
|
133
|
+
getRecordStatus.getAtLeastOneRecord = true;
|
|
134
|
+
} else {
|
|
135
|
+
getRecordStatus.notFoundSomeRecord = true;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
//(<afterGetGraph>)
|
|
139
|
+
//(</afterGetGraph>)
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
// collect return data depend on getDataDetail
|
|
143
|
+
Object.assign(
|
|
144
|
+
getResults,
|
|
145
|
+
collectGetData(_izContext, dataFromGraph, getDataDetail)
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
} else {
|
|
150
|
+
|
|
151
|
+
let identifiersForGetData = await dynamoDbIdentifiersByStorageResource(
|
|
152
|
+
_izContext,
|
|
153
|
+
objectSchema,
|
|
154
|
+
getDataDetail,
|
|
155
|
+
requestParams.identifiers
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
_izContext.logger.debug("identifiersForGetData: ", identifiersForGetData);
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
//(<beforeGetDynamoDb>)
|
|
162
|
+
//(</beforeGetDynamoDb>)
|
|
163
|
+
|
|
164
|
+
let dataFromDynamoDb = await dynamodbSharedLib.getItem(
|
|
165
|
+
_izContext,
|
|
166
|
+
dynamodbSharedLib.tableName(getDataDetail.tableName),
|
|
167
|
+
identifiersForGetData
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
_izContext.logger.debug("dataFromDynamoDb: ", dataFromDynamoDb);
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
if (dataFromDynamoDb) {
|
|
174
|
+
getRecordStatus.getAtLeastOneRecord = true;
|
|
175
|
+
} else {
|
|
176
|
+
getRecordStatus.notFoundSomeRecord = true;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
//(<afterGetDynamoDb>)
|
|
180
|
+
//(</afterGetDynamoDb>)
|
|
181
|
+
|
|
182
|
+
// collect return data depend on getDataDetail
|
|
183
|
+
Object.assign(
|
|
184
|
+
getResults,
|
|
185
|
+
collectGetData(_izContext, dataFromDynamoDb, getDataDetail)
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
}
|
|
189
|
+
})
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
_izContext.logger.debug("getRecordStatus: ", getRecordStatus);
|
|
193
|
+
|
|
194
|
+
if (getRecordStatus.getAtLeastOneRecord === true && getRecordStatus.notFoundSomeRecord === true) {
|
|
195
|
+
throw Error("Not found some record while get data");
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (Object.keys(getResults).length) {
|
|
199
|
+
return getResults;
|
|
200
|
+
} else {
|
|
201
|
+
return null
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
} catch (err) {
|
|
205
|
+
_izContext.logger.error('error <%- firstLetterUpperCase(functionName) %>Main: ', err)
|
|
206
|
+
throw (err)
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
<%_ function firstLetterUpperCase(text){ return text.charAt(0).toUpperCase() + text.slice(1) } _%>
|
|
211
|
+
<%_ function firstLetterLowerCase(str) { return str.charAt(0).toLowerCase() + str.slice(1) } _%>
|
|
212
|
+
|
|
213
|
+
// request input
|
|
214
|
+
|
|
215
|
+
// {
|
|
216
|
+
// "identifiers": {
|
|
217
|
+
// "personId" : "basTest"
|
|
218
|
+
// }
|
|
219
|
+
// }
|
|
@@ -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
|
+
|
|
20
|
+
const path = require('path');
|
|
21
|
+
|
|
22
|
+
const schemaConsts = require('@izara_project/izara-core-library-service-schemas/src/Consts');
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
// const lambdaYaml = require("./Template/Resource/Lambda/LambdaYamlTemplateData");
|
|
27
|
+
|
|
28
|
+
const config = require('../libs/Consts')
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
const dynamoDbMainYaml = require("./TemplateAndData/DynamoDbMain/Data/MainDynamoDbYamlData")
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @param {Object} _izContext
|
|
35
|
+
* @param {Object} objectSchema
|
|
36
|
+
*/
|
|
37
|
+
module.exports.createSourceDataObjectSchema = (_izContext, objectSchema, saveFilePath) => {
|
|
38
|
+
|
|
39
|
+
let resultsForCreateSource = [];
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
const dynamoDbMainYamlDataList = dynamoDbMainYaml.dynamoDbMainYamlFromObjectSchema.templateDataFunction(_izContext, objectSchema);
|
|
43
|
+
console.log("dynamoDbMainYamlDataList: ", dynamoDbMainYamlDataList);
|
|
44
|
+
|
|
45
|
+
for (let dynamoDbMainYamlData of dynamoDbMainYamlDataList) {
|
|
46
|
+
// create iam role of handler here
|
|
47
|
+
resultsForCreateSource.push({
|
|
48
|
+
templatePath: dynamoDbMainYaml.dynamoDbMainYamlFromObjectSchema.templatePath,
|
|
49
|
+
templateData: dynamoDbMainYamlData,
|
|
50
|
+
setting: {
|
|
51
|
+
initialData: 'Resources:\n',
|
|
52
|
+
savePath: path.join(saveFilePath, config.SOURCE_PATH.resourceYaml),
|
|
53
|
+
saveFileName: 'generate-dynamodb-table',
|
|
54
|
+
fileExtension: '.yml',
|
|
55
|
+
isAppend: true
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
console.log("resultsForCreateSource: ", resultsForCreateSource);
|
|
61
|
+
|
|
62
|
+
return resultsForCreateSource;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
*
|
|
68
|
+
* @param {Object} _izContext
|
|
69
|
+
* @param {Object} relSchema
|
|
70
|
+
* @param {String} saveFilePath
|
|
71
|
+
* @returns
|
|
72
|
+
*/
|
|
73
|
+
module.exports.createSourceDataRelSchema = (_izContext, relSchema, saveFilePath) => {
|
|
74
|
+
|
|
75
|
+
return []
|
|
76
|
+
}
|