@izara_project/izara-market-library-service-schemas 1.0.1 → 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/index.js +25 -0
- package/package.json +6 -2
- package/src/GenerateCodeLibs/index.js +24 -0
- package/src/GenerateCodeLibs/src/GenerateCodeLibs.js +1373 -0
- package/src/MainLibs/index.js +24 -0
- package/src/MainLibs/src/Consts.js +0 -0
- package/src/MainLibs/src/Utils.js +27 -0
- package/src/SourceManager/index.js +23 -0
- package/src/SourceManager/src/CreateSource.js +181 -0
- package/src/SourceManager/src/Utils.js +64 -0
- package/src/TemplateManager/index.js +23 -0
- 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/FunctionYaml/HdrInv/example req.js +15 -0
- package/src/TemplateManager/src/FunctionYaml/HdrInv/request.json +14 -0
- package/src/TemplateManager/src/FunctionYaml/HdrInv/template.ejs +26 -0
- 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 +207 -0
- package/src/TemplateManager/src/MainResourcesYaml/CreateSourceData.js +76 -0
- package/src/TemplateManager/src/MainResourcesYaml/TemplateAndData/DynamoDbMain/Data/MainDynamoDbYamlData.js +155 -0
- package/src/TemplateManager/src/MainResourcesYaml/TemplateAndData/DynamoDbMain/Template/DynamoDb.ejs +31 -0
- package/src/TemplateManager/src/MainResourcesYaml/TemplateAndData/DynamoDbMain/Template/DynamoDb.exampleData.js +12 -0
- 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/externalService/SnsTopicSubscriotions/data.js +31 -0
- package/src/TemplateManager/src/externalService/SnsTopicSubscriotions/request.json +0 -0
- package/src/TemplateManager/src/externalService/SnsTopicSubscriotions/template.ejs +14 -0
- package/src/TemplateManager/src/libs/Consts.js +146 -0
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
// MainLibs use for contain shared logic and constant
|
|
21
|
+
module.exports = {
|
|
22
|
+
consts: require('./src/Consts'),
|
|
23
|
+
utils: require('./src/Utils')
|
|
24
|
+
};
|
|
File without changes
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
|
|
21
|
+
module.exports.firstLetterUpperCase = (text) => {
|
|
22
|
+
return text.charAt(0).toUpperCase() + text.slice(1)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
module.exports.firstLetterLowerCase = (str) => {
|
|
26
|
+
return str.charAt(0).toLowerCase() + str.slice(1)
|
|
27
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright(C) 2021 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
|
+
module.exports = {
|
|
21
|
+
utils: require('./src/Utils'),
|
|
22
|
+
createSource: require('./src/CreateSource')
|
|
23
|
+
}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright(C) 2021 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
|
+
|
|
21
|
+
const fs = require('fs');
|
|
22
|
+
const ejs = require('ejs');
|
|
23
|
+
const join = require('path').join;
|
|
24
|
+
const beautify = require('js-beautify/js').js;
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
const beautifySetting = {
|
|
28
|
+
"indent_size": "2",
|
|
29
|
+
"indent_char": " ",
|
|
30
|
+
"max_preserve_newlines": "0",
|
|
31
|
+
// "preserve_newlines": true,
|
|
32
|
+
"keep_array_indentation": true,
|
|
33
|
+
"indent_scripts": "separate",
|
|
34
|
+
"brace_style": ["preserve-inline", "none"],
|
|
35
|
+
"space_before_conditional": true,
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const TAG_CLASSES = {
|
|
39
|
+
doubleTag: 'doubleTag',
|
|
40
|
+
singleTag: 'singleTag',
|
|
41
|
+
nameTag: 'nameTag',
|
|
42
|
+
anyTag: 'anyTag',
|
|
43
|
+
anyDoubleTag: 'anyDoubleTag',
|
|
44
|
+
ymlDoubleTag: 'ymlDoubleTag',
|
|
45
|
+
ymlAnyDoubleTag: 'ymlAnyDoubleTag'
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
function tagList(tagClass = TAG_CLASSES.singleTag, tagName) {
|
|
50
|
+
return {
|
|
51
|
+
// return regex depend on tagClass
|
|
52
|
+
[TAG_CLASSES.singleTag]: new RegExp(`\/\/\\(<${tagName}>\\)`, 'gm'), // match //(<tagName>)
|
|
53
|
+
[TAG_CLASSES.doubleTag]: new RegExp(`\/\/\\(<${tagName}>\\)([\\s\\S]*?)\/\/\\(<\\/${tagName}>\\)`, 'gm'), // get data between tag -> //(<tagName>) data //(</tagName>)
|
|
54
|
+
[TAG_CLASSES.nameTag]: new RegExp(`__${tagName}`, 'gm'), // match //(<tagName>)
|
|
55
|
+
[TAG_CLASSES.anyTag]: new RegExp(`\/\/\\(<([^>]+)>\\)`, 'g'), // match //(<anyname>)
|
|
56
|
+
[TAG_CLASSES.anyDoubleTag]: new RegExp('\/\/\\(<(\\w+)>\\)([\\s\\S]*?)\/\/\\(<\/\\1>\\)', 'gm'),
|
|
57
|
+
[TAG_CLASSES.ymlDoubleTag]: new RegExp(`\#<#${tagName}#>([\\s\\S]*?)#<#\/${tagName}#>`, 'gm'), // match #<#tag#> #<#/tag#>
|
|
58
|
+
[TAG_CLASSES.ymlAnyDoubleTag]: new RegExp(`\#<#(\\w+)#>([\\s\\S]*?)#<#\/\\1#>`, 'gm'), // get tagName from doubleTag #<#tagName#> #<#/tagName#>
|
|
59
|
+
}[tagClass]
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
*
|
|
65
|
+
* @param {string} template
|
|
66
|
+
* @param {object} data
|
|
67
|
+
* @returns
|
|
68
|
+
*/
|
|
69
|
+
function generateDataFromTemplate(template, data,) {
|
|
70
|
+
let dataToSave = ejs.compile(template)(data);
|
|
71
|
+
return dataToSave;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* generate code from template and data then save generated data
|
|
77
|
+
*
|
|
78
|
+
* @param {string} template
|
|
79
|
+
* @param {object} data
|
|
80
|
+
* @param {object} setting
|
|
81
|
+
* @param {string} setting.savePath
|
|
82
|
+
* @param {string} [setting.hookPath]
|
|
83
|
+
* @param {string} setting.saveFileName
|
|
84
|
+
* @param {string} setting.fileExtension
|
|
85
|
+
* @param {boolean} setting.isAppend
|
|
86
|
+
* @param {string} setting.initialData // initialData can use when isAppend = true
|
|
87
|
+
* @returns
|
|
88
|
+
*/
|
|
89
|
+
async function createSource(template, data, { savePath, hookPath, saveFileName, fileExtension, initialData, isAppend = false }) {
|
|
90
|
+
|
|
91
|
+
try {
|
|
92
|
+
|
|
93
|
+
let dataToSave = generateDataFromTemplate(template, data);
|
|
94
|
+
|
|
95
|
+
let anyDoubleTagClass
|
|
96
|
+
let doubleTagClass
|
|
97
|
+
|
|
98
|
+
if (fileExtension === '.js') {
|
|
99
|
+
anyDoubleTagClass = TAG_CLASSES.anyDoubleTag;
|
|
100
|
+
doubleTagClass = TAG_CLASSES.doubleTag;
|
|
101
|
+
} else if (fileExtension === '.yml') {
|
|
102
|
+
anyDoubleTagClass = TAG_CLASSES.ymlAnyDoubleTag;
|
|
103
|
+
doubleTagClass = TAG_CLASSES.ymlDoubleTag;
|
|
104
|
+
}
|
|
105
|
+
let hookDataPath = hookPath ? hookPath : join(savePath, '../hook/');
|
|
106
|
+
|
|
107
|
+
if (!fs.existsSync(savePath)) fs.mkdirSync(savePath, { recursive: true });
|
|
108
|
+
if (!fs.existsSync(hookDataPath)) fs.mkdirSync(hookDataPath, { recursive: true });
|
|
109
|
+
|
|
110
|
+
// check saveFileName for Hook exists
|
|
111
|
+
if (fs.existsSync(`${hookDataPath}${saveFileName}${fileExtension}`.trim())) {
|
|
112
|
+
const hookData = fs.readFileSync(`${hookDataPath}${saveFileName}${fileExtension}`, 'utf8');
|
|
113
|
+
|
|
114
|
+
//replace data in tag from hook file to actual file
|
|
115
|
+
let dataAfterHook = dataToSave.replace(tagList(anyDoubleTagClass), (match, tagName, content) => {
|
|
116
|
+
let hookRegex = tagList(doubleTagClass, tagName);
|
|
117
|
+
let replaceData = hookData.match(hookRegex);
|
|
118
|
+
|
|
119
|
+
if (replaceData) {
|
|
120
|
+
return replaceData;
|
|
121
|
+
} else {
|
|
122
|
+
return match;
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
dataAfterHook = fileExtension === '.js' ? beautify(dataAfterHook, beautifySetting) : dataAfterHook
|
|
127
|
+
if (isAppend) {
|
|
128
|
+
if (!fs.existsSync(`${savePath}${saveFileName}${fileExtension}`) && initialData) {
|
|
129
|
+
fs.writeFileSync(`${savePath}${saveFileName}${fileExtension}`.trim(), initialData + dataAfterHook + '\n\n', 'utf8');
|
|
130
|
+
} else {
|
|
131
|
+
fs.appendFileSync(`${savePath}${saveFileName}${fileExtension}`.trim(), dataAfterHook + '\n\n', 'utf8');
|
|
132
|
+
}
|
|
133
|
+
} else {
|
|
134
|
+
fs.writeFileSync(`${savePath}${saveFileName}${fileExtension}`.trim(), dataAfterHook, 'utf8');
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
} else {
|
|
138
|
+
dataToSave = fileExtension === '.js' ? beautify(dataToSave, beautifySetting) : dataToSave
|
|
139
|
+
if (isAppend) {
|
|
140
|
+
if (!fs.existsSync(`${savePath}${saveFileName}${fileExtension}`) && initialData) {
|
|
141
|
+
fs.writeFileSync(`${savePath}${saveFileName}${fileExtension}`.trim(), initialData + dataToSave + '\n\n', 'utf8');
|
|
142
|
+
} else {
|
|
143
|
+
fs.appendFileSync(`${savePath}${saveFileName}${fileExtension}`.trim(), dataToSave + '\n\n', 'utf8');
|
|
144
|
+
}
|
|
145
|
+
} else {
|
|
146
|
+
fs.writeFileSync(`${savePath}${saveFileName}${fileExtension}`.trim(), dataToSave, 'utf8');
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return;
|
|
151
|
+
|
|
152
|
+
} catch (err) {
|
|
153
|
+
console.log('error createSource: ', err);// generate
|
|
154
|
+
throw (err)
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
// Function to extract multiple code between tags
|
|
163
|
+
// function extractMultipleCodeBetweenTags(content, tagName) {
|
|
164
|
+
// const result = [];
|
|
165
|
+
// const startTag = `//(<${tagName}>)`;
|
|
166
|
+
// const endTag = `//(</${tagName}>)`;
|
|
167
|
+
// let startIndex = content.indexOf(startTag);
|
|
168
|
+
// let endIndex = content.indexOf(endTag, startIndex);
|
|
169
|
+
// while (startIndex >= 0 && endIndex >= 0) {
|
|
170
|
+
// result.push(content.substring(startIndex + startTag.length + 1, endIndex));
|
|
171
|
+
// startIndex = content.indexOf(startTag, endIndex);
|
|
172
|
+
// endIndex = content.indexOf(endTag, startIndex);
|
|
173
|
+
// }
|
|
174
|
+
// return result;
|
|
175
|
+
// }
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
module.exports = {
|
|
179
|
+
createSource,
|
|
180
|
+
generateDataFromTemplate
|
|
181
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright(C) 2021 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
|
+
|
|
21
|
+
const fs = require('fs');
|
|
22
|
+
// const { unlink, readdir } = require('node:fs/promises');
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
// empty dir
|
|
26
|
+
async function deleteFileInDir(directory) {
|
|
27
|
+
try {
|
|
28
|
+
if (fs.existsSync(directory)) {
|
|
29
|
+
fs.rmSync(directory, { recursive: true });
|
|
30
|
+
}
|
|
31
|
+
} catch (err) {
|
|
32
|
+
console.log(err);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function deleteFile(filePath) {
|
|
37
|
+
if (fs.existsSync(filePath)) {
|
|
38
|
+
try {
|
|
39
|
+
// If the file exists, delete it
|
|
40
|
+
fs.unlinkSync(filePath);
|
|
41
|
+
console.log('File deleted successfully');
|
|
42
|
+
} catch (err) {
|
|
43
|
+
console.error(`Error deleting file: ${err.message}`);
|
|
44
|
+
}
|
|
45
|
+
} else {
|
|
46
|
+
console.log('File does not exist');
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
module.exports = {
|
|
51
|
+
deleteFileInDir,
|
|
52
|
+
deleteFile
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
// remove file
|
|
57
|
+
// async function deleteFileInDir(directory) {
|
|
58
|
+
// if (fs.existsSync(directory)) {
|
|
59
|
+
// for (const file of await readdir(directory)) {
|
|
60
|
+
// await unlink(path.join(directory, file));
|
|
61
|
+
// }
|
|
62
|
+
// }
|
|
63
|
+
// return;
|
|
64
|
+
// }
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2021 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
|
+
|
|
21
|
+
module.exports = {
|
|
22
|
+
generateCode: require('./src/GenerateCode'),
|
|
23
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
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, SOURCE_PATH } = require("../../libs/Consts");
|
|
26
|
+
|
|
27
|
+
const templatePath = path.join(__dirname, "./template.ejs")
|
|
28
|
+
|
|
29
|
+
function defaultIamRolePerAction() {
|
|
30
|
+
|
|
31
|
+
let defaultIamRole = [];
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
defaultIamRole.push(
|
|
35
|
+
createIamRole(
|
|
36
|
+
{
|
|
37
|
+
[RESOURCE_CLASSES.s3]: ["GetObject", "GetObjectVersion"],
|
|
38
|
+
},
|
|
39
|
+
[
|
|
40
|
+
resourceNames(RESOURCE_CLASSES.s3, "object-schema/perServiceSchemas/*"),
|
|
41
|
+
resourceNames(RESOURCE_CLASSES.s3, "object-schema/serviceConfig/ServiceNameConfig.json"),
|
|
42
|
+
resourceNames(RESOURCE_CLASSES.s3, "object-schema/serviceConfig/GraphServerTags.json"),
|
|
43
|
+
]
|
|
44
|
+
)
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
defaultIamRole.push(
|
|
48
|
+
createIamRole(
|
|
49
|
+
{ [RESOURCE_CLASSES.s3]: ["ListBucket"] },
|
|
50
|
+
[
|
|
51
|
+
resourceNames(RESOURCE_CLASSES.s3, "object-schema"),
|
|
52
|
+
]
|
|
53
|
+
)
|
|
54
|
+
);
|
|
55
|
+
console.log("defaultIamRole Api", defaultIamRole)
|
|
56
|
+
return defaultIamRole
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* receive objectSchema
|
|
61
|
+
* create data for hdrInv template
|
|
62
|
+
*
|
|
63
|
+
* @param {Object} objectSchema
|
|
64
|
+
* @return {{ templatePath, templateData, setting } }
|
|
65
|
+
*/
|
|
66
|
+
function data(_izContext, objectSchema, srcPath) {
|
|
67
|
+
let createSourceArray = [];
|
|
68
|
+
|
|
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.hdrApi)) {
|
|
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.hdrApi)) {
|
|
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
|
+
function createParamForCreateSource(objectSchema, action, srcPath) {
|
|
91
|
+
let objectType = objectSchema.objectType;
|
|
92
|
+
let actionHandler = action;
|
|
93
|
+
let functionName = objectType + upperCase(actionHandler);
|
|
94
|
+
let additionalResourcePermission = defaultIamRolePerAction();
|
|
95
|
+
let tableForGetItem = [];
|
|
96
|
+
let hasGraphStorage = false;
|
|
97
|
+
for (let storageResource of Object.values(objectSchema.storageResources)) {
|
|
98
|
+
if (storageResource.storageType === STORAGE_TYPES.dynamoDB) {
|
|
99
|
+
// add IamRole for dynamodb depend on tableName in storageResources of objectSchema
|
|
100
|
+
tableForGetItem.push(resourceNames(RESOURCE_CLASSES.dynamoDbTable, storageResource.tableName));
|
|
101
|
+
|
|
102
|
+
} else if (storageResource.storageType === STORAGE_TYPES.graph) {
|
|
103
|
+
// find graph serviceName from graphServerTag or *GetNodeHdrInv ?
|
|
104
|
+
|
|
105
|
+
if (hasGraphStorage) {
|
|
106
|
+
continue;
|
|
107
|
+
} else {
|
|
108
|
+
hasGraphStorage = true;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (tableForGetItem.length) {
|
|
114
|
+
additionalResourcePermission.push(
|
|
115
|
+
createIamRole(
|
|
116
|
+
{ [RESOURCE_CLASSES.dynamoDbTable]: [DEFAULT_LAMBDA_ROLE_PER_ACTION[action].dynamoDbPermission] },
|
|
117
|
+
tableForGetItem
|
|
118
|
+
)
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
function httpEvent(lambdaActiom) {
|
|
122
|
+
return {
|
|
123
|
+
create: "put",
|
|
124
|
+
update: "post",
|
|
125
|
+
get: "post",
|
|
126
|
+
delete: "delete"
|
|
127
|
+
}[lambdaActiom]
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
let event = httpEvent(action)
|
|
131
|
+
console.log("event:", event)
|
|
132
|
+
|
|
133
|
+
return {
|
|
134
|
+
templatePath: templatePath,
|
|
135
|
+
templateData: {
|
|
136
|
+
functionName: functionName,
|
|
137
|
+
resourceLocation: SOURCE_PATH.resourceLocation,
|
|
138
|
+
handlerType: "HdrApi",
|
|
139
|
+
additionalResourcePermission,
|
|
140
|
+
event: event,
|
|
141
|
+
objectType: objectType,
|
|
142
|
+
action: actionHandler
|
|
143
|
+
},
|
|
144
|
+
setting: {
|
|
145
|
+
savePath: path.join(srcPath, SOURCE_PATH.appYaml),
|
|
146
|
+
saveFileName: `function`,
|
|
147
|
+
fileExtension: '.yml',
|
|
148
|
+
isAppend: true
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
// [
|
|
157
|
+
// {
|
|
158
|
+
// 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',
|
|
159
|
+
// templateData: { tableName: 'ObjectTypeSingle', attributes: [Array] },
|
|
160
|
+
// setting: {
|
|
161
|
+
// savePath: '/generatedCode/source/',
|
|
162
|
+
// saveFileName: 'ObjectTypeGet',
|
|
163
|
+
// fileExtension: '.js',
|
|
164
|
+
// isAppend: false
|
|
165
|
+
// }
|
|
166
|
+
// }
|
|
167
|
+
// ]
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
module.exports = data;
|
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
- http:
|
|
7
|
+
path: <%- objectType %>/<%- firstLetterUpperCase(action) %>
|
|
8
|
+
method: <%- event %>
|
|
9
|
+
cors: true
|
|
10
|
+
#<#Authorizer#>
|
|
11
|
+
#<#/Authorizer#>
|
|
12
|
+
iamRoleStatements:
|
|
13
|
+
<%_ additionalResourcePermission.forEach(resourcePermission => { _%>
|
|
14
|
+
- Effect: <%- resourcePermission.effect %>
|
|
15
|
+
Action:
|
|
16
|
+
<%_ Object.keys(resourcePermission.action).forEach(resourcePerAction => { _%>
|
|
17
|
+
<%_ resourcePermission.action[resourcePerAction].forEach(permission => { _%>
|
|
18
|
+
- <%- resourcePerAction %>:<%- permission %>
|
|
19
|
+
<%_}) _%>
|
|
20
|
+
<%_ }) _%>
|
|
21
|
+
Resource:
|
|
22
|
+
<%_ resourcePermission.resource.forEach(resource => { _%>
|
|
23
|
+
- <%- resource %>
|
|
24
|
+
<%_ }) _%>
|
|
25
|
+
<%_}) _%>
|
|
26
|
+
#<#<%- functionName %><%- handlerType %>IamRole#>
|
|
27
|
+
#<#/<%- functionName %><%- handlerType %>IamRole#>
|
|
28
|
+
<%_ function firstLetterUpperCase(text){
|
|
29
|
+
return text.charAt(0).toUpperCase() + text.slice(1)
|
|
30
|
+
} _%>
|
|
31
|
+
<%_ function firstLetterLowerCase(str) {
|
|
32
|
+
return str.charAt(0).toLowerCase() + str.slice(1)
|
|
33
|
+
} _%>
|