@izara_project/izara-market-library-service-schemas 1.0.25 → 1.0.27
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 +2 -1
- package/package.json +3 -2
- package/src/GenerateCodeLibs/src/GenerateCodeLibs.js +1 -1
- package/src/MainLibs/src/Consts.js +1 -0
- package/src/TemplateManager/src/libs/Consts.js +0 -1
- package/src/reStructure/GenerateCode.js +30 -16
- package/src/reStructure/GenerateSchema.js +141 -0
- package/src/reStructure/SchemaConfig.js +28 -0
- package/src/reStructure/TemplateConfig.js +20 -0
- package/src/reStructure/TemplateData/attributeTreeSchema/generateTemplateData.js +52 -0
- package/src/reStructure/TemplateData/attributeTreeSchema/mainAttributeTreeSchema/attributeLink.ejs +21 -0
- package/src/reStructure/TemplateData/attributeTreeSchema/mainAttributeTreeSchema/data.js +128 -0
- package/src/reStructure/TemplateData/attributeTreeSchema/mainAttributeTreeSchema/request.json +11 -0
- package/src/reStructure/TemplateData/externalService/functionNameConfig/data.js +1 -1
- package/src/reStructure/TemplateData/externalService/snsTopicSubscriptions/data.js +1 -1
- package/src/reStructure/TemplateData/flowSchema/components/upload/confirmReserved/functionYaml/data.js +3 -1
- package/src/reStructure/TemplateData/flowSchema/components/upload/confirmReserved/functionYaml/template.ejs +1 -14
- package/src/reStructure/TemplateData/flowSchema/components/upload/createObject/functionYaml/data.js +4 -2
- package/src/reStructure/TemplateData/flowSchema/components/upload/createObject/functionYaml/template.ejs +1 -14
- package/src/reStructure/TemplateData/flowSchema/components/upload/createObjectComplete/functionYaml/data.js +3 -1
- package/src/reStructure/TemplateData/flowSchema/components/upload/createObjectComplete/functionYaml/template.ejs +1 -14
- package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/getSignUrls/functionYaml/data.js +3 -1
- package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/getSignUrls/functionYaml/template.ejs +1 -14
- package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/reservedLimit/functionYaml/data.js +3 -1
- package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/reservedLimit/functionYaml/template.ejs +1 -14
- package/src/reStructure/TemplateData/flowSchema/components/upload/processFile/functionYml/HdrS3/data.js +4 -2
- package/src/reStructure/TemplateData/flowSchema/components/upload/processFile/functionYml/HdrS3/template.ejs +1 -14
- package/src/reStructure/TemplateData/flowSchema/components/websocket/connect/functionYaml/data.js +4 -2
- package/src/reStructure/TemplateData/flowSchema/components/websocket/dynamoDb/ReservedTableData.js +1 -1
- package/src/reStructure/TemplateData/flowSchema/components/websocket/dynamoDb/WebSocketTaskData.js +1 -1
- package/src/reStructure/TemplateData/generateRole/createSharedResource.js +10 -0
- package/src/reStructure/TemplateData/perActionComplete/update/sns-in-sqs/data.js +1 -1
- package/src/reStructure/TemplateData/perActionEndpoint/generateTemplateData.js +7 -12
- package/src/reStructure/TemplateData/perActionEndpoint/handler/inv/data.js +2 -2
- package/src/reStructure/TemplateData/perActionEndpoint/yaml/dsq/data.js +1 -0
- package/src/reStructure/TemplateData/perActionEndpoint/yaml/sqs/data.js +3 -2
- package/src/reStructure/TemplateData/perActionEndpoint/yaml/wbs/data.js +17 -2
- package/src/reStructure/libs/GenerateCodeLibs.js +38 -0
package/index.js
CHANGED
|
@@ -23,5 +23,6 @@ module.exports = {
|
|
|
23
23
|
generateCodeLibs: require('./src/GenerateCodeLibs'),
|
|
24
24
|
|
|
25
25
|
generateSchemaWithTemplate: require('./src/TemplateManager/src/GenerateSchema').generateSchemaWithTemplate,
|
|
26
|
-
generateCodeWithTemplate: require('./src/reStructure/GenerateCode').generateCodeWithTemplate
|
|
26
|
+
generateCodeWithTemplate: require('./src/reStructure/GenerateCode').generateCodeWithTemplate,
|
|
27
|
+
generateSchema: require('./src/reStructure/GenerateSchema')
|
|
27
28
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@izara_project/izara-market-library-service-schemas",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.27",
|
|
4
4
|
"description": "Schemas for Izara Market project",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -22,8 +22,9 @@
|
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@izara_project/izara-core-library-core": "^1.0.16",
|
|
24
24
|
"@izara_project/izara-core-library-external-request": "^1.0.17",
|
|
25
|
-
"@izara_project/izara-core-library-service-schemas": "^1.0.
|
|
25
|
+
"@izara_project/izara-core-library-service-schemas": "^1.0.47",
|
|
26
26
|
"@izara_project/izara-shared": "^1.0.125",
|
|
27
|
+
"@izara_project/izara-shared-service-schemas": "^1.0.4",
|
|
27
28
|
"ejs": "^3.1.10",
|
|
28
29
|
"js-beautify": "^1.15.4",
|
|
29
30
|
"lodash": "^4.17.21",
|
|
@@ -46,7 +46,7 @@ const {
|
|
|
46
46
|
const Logger = require("@izara_project/izara-core-library-logger");
|
|
47
47
|
|
|
48
48
|
const nodeLabelRegexPattern = "^[a-zA-Z0-9_-]+(?:\:[a-zA-Z0-9_-]+)?$"
|
|
49
|
-
const { validateObjType } = require('@izara_project/izara-
|
|
49
|
+
const { validateObjType } = require('@izara_project/izara-shared-service-schemas').validateObjType;
|
|
50
50
|
|
|
51
51
|
|
|
52
52
|
|
|
@@ -367,6 +367,7 @@ const SOURCE_GENERATE_IAM_ROLE = {
|
|
|
367
367
|
NodeCompleteRole: "NodeCom",
|
|
368
368
|
RelationshipRole: "Relationship",
|
|
369
369
|
RelationshipCompleteRole: "RelationshipCom",
|
|
370
|
+
FlowSchemaUploadS3Role: "FlowSchemaUploadS3"
|
|
370
371
|
};
|
|
371
372
|
|
|
372
373
|
const ADD_ON_DATA_STRUCTURE_TYPE = {
|
|
@@ -23,7 +23,6 @@ const {
|
|
|
23
23
|
STORAGE_TYPES
|
|
24
24
|
} = require('@izara_project/izara-core-library-service-schemas/src/Consts');
|
|
25
25
|
|
|
26
|
-
const { firstLetterUpperCase: upperCase } = require("../../../MainLibs/src/Utils")
|
|
27
26
|
|
|
28
27
|
const { getGraphServiceNameFromGraphServerTagWithCache, getGraphServiceTagWithCache } = require('@izara_project/izara-core-library-service-schemas/src/ServiceConfig');
|
|
29
28
|
|
|
@@ -20,6 +20,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
20
20
|
const { join, resolve } = require("path");
|
|
21
21
|
const { readFileSync } = require("fs");
|
|
22
22
|
|
|
23
|
+
const { validatePathWithRootServicePath } = require("./libs/GenerateCodeLibs")
|
|
24
|
+
|
|
23
25
|
const templateConfig = require("./TemplateConfig");
|
|
24
26
|
|
|
25
27
|
// SourceManager
|
|
@@ -39,6 +41,9 @@ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
|
|
|
39
41
|
// point to app/src
|
|
40
42
|
let saveFilePath = join(objSchemaPath, `../`);
|
|
41
43
|
|
|
44
|
+
// point to root folder of service
|
|
45
|
+
let localServicePath = join(saveFilePath, "../../");
|
|
46
|
+
|
|
42
47
|
// // define path for store yml file
|
|
43
48
|
const GENERATE_CODE_SOURCE_PATH = {
|
|
44
49
|
appYaml: join(saveFilePath, SOURCE_PATH.appYaml),
|
|
@@ -50,29 +55,19 @@ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
|
|
|
50
55
|
generateCodeLib: join(saveFilePath, SOURCE_PATH.generateCodeLib),
|
|
51
56
|
};
|
|
52
57
|
|
|
53
|
-
|
|
54
58
|
//------ Start Create Source ------
|
|
55
59
|
|
|
56
60
|
// collect all result of template data for execute createSource
|
|
57
61
|
let allCreateSource = []
|
|
58
62
|
|
|
59
|
-
// Store original console.log function
|
|
60
|
-
const originalConsoleLog = console.log;
|
|
61
|
-
|
|
62
63
|
// * iterate templateConfig for generate data
|
|
63
64
|
for (const templateName in templateConfig.TemplateAndData) {
|
|
64
65
|
// Display log indicating which template is being loaded
|
|
65
66
|
console.log('Loading template:', templateName);
|
|
66
67
|
|
|
67
|
-
// Temporarily disable console.log before calling generateTemplateData
|
|
68
|
-
console.log = () => { };
|
|
69
|
-
|
|
70
68
|
let generateTemplateData = require(join(__dirname, templateConfig.TemplateAndData[templateName]));
|
|
71
69
|
let createSourceResult = await generateTemplateData(_izContext, objSchemaPath);
|
|
72
70
|
|
|
73
|
-
// Restore the original console.log function
|
|
74
|
-
console.log = originalConsoleLog;
|
|
75
|
-
|
|
76
71
|
// Filter out empty or invalid objects before adding to allCreateSource
|
|
77
72
|
if (Array.isArray(createSourceResult)) {
|
|
78
73
|
const validResults = createSourceResult.filter(item =>
|
|
@@ -82,11 +77,11 @@ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
|
|
|
82
77
|
}
|
|
83
78
|
}
|
|
84
79
|
|
|
85
|
-
// Generate function name configuration
|
|
80
|
+
// ** Generate function name configuration
|
|
86
81
|
const functionNameConfigs = functionNameConfigYamlData(_izContext, allCreateSource, saveFilePath);
|
|
87
82
|
allCreateSource.push(...functionNameConfigs);
|
|
88
83
|
|
|
89
|
-
//
|
|
84
|
+
// ** create Generate-Shared-resource
|
|
90
85
|
const generateSharedResource = createSharedResource(_izContext, allCreateSource, saveFilePath);
|
|
91
86
|
allCreateSource.push(generateSharedResource);
|
|
92
87
|
// console.log('---> allCreateSource', allCreateSource);
|
|
@@ -114,14 +109,22 @@ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
|
|
|
114
109
|
}
|
|
115
110
|
}
|
|
116
111
|
|
|
112
|
+
// validate path before empty folder
|
|
113
|
+
for (let folderPathToEmpty of Object.values(GENERATE_CODE_SOURCE_PATH)) {
|
|
114
|
+
validatePathWithRootServicePath(localServicePath, folderPathToEmpty)
|
|
115
|
+
}
|
|
117
116
|
|
|
118
|
-
for (let folderPathToEmpty of Object.
|
|
119
|
-
await deleteFileInDir(
|
|
117
|
+
for (let folderPathToEmpty of Object.values(GENERATE_CODE_SOURCE_PATH)) {
|
|
118
|
+
await deleteFileInDir(folderPathToEmpty);
|
|
120
119
|
}
|
|
121
120
|
|
|
122
121
|
|
|
123
122
|
// generate all source
|
|
124
123
|
for (let item of allCreateSource) {
|
|
124
|
+
if (item.setting.initialData) {
|
|
125
|
+
console.log("setting::", item.setting)
|
|
126
|
+
console.log("templatePath::", item.templatePath)
|
|
127
|
+
}
|
|
125
128
|
// throw error if item is invalid
|
|
126
129
|
if (!item || !item.templatePath || !item.templateData || !item.setting) {
|
|
127
130
|
console.log('Throwing invalid source item:', item);
|
|
@@ -138,7 +141,7 @@ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
|
|
|
138
141
|
);
|
|
139
142
|
}
|
|
140
143
|
|
|
141
|
-
console.log('Generated all source files');
|
|
144
|
+
console.log('Generated all source files successfully');
|
|
142
145
|
return 'return values';
|
|
143
146
|
} catch (error) {
|
|
144
147
|
console.error('Error generating code:', error);
|
|
@@ -148,4 +151,15 @@ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
|
|
|
148
151
|
|
|
149
152
|
module.exports = {
|
|
150
153
|
generateCodeWithTemplate
|
|
151
|
-
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
/*
|
|
158
|
+
GenerateCode will iterate through templateConfig and generate each template dependOn each templateAndData\
|
|
159
|
+
|
|
160
|
+
GenerateSchema now use for generate attribute tree only
|
|
161
|
+
generateSchema can be modify use used depend on use case eg: some objectType have attribute tree inside addOn
|
|
162
|
+
when generateSchema in own service need to generate ref objectRelationship only
|
|
163
|
+
and attribute tree service can generate schema
|
|
164
|
+
|
|
165
|
+
*/
|
|
@@ -0,0 +1,141 @@
|
|
|
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, resolve } = require("path");
|
|
21
|
+
const { readFileSync } = require("fs");
|
|
22
|
+
|
|
23
|
+
const schemaConfig = require("./SchemaConfig");
|
|
24
|
+
|
|
25
|
+
// SourceManager
|
|
26
|
+
const { deleteFileInDir, createHookFunction } = require("../SourceManager/src/Utils");
|
|
27
|
+
const { createSource } = require("../SourceManager/src/CreateSource");
|
|
28
|
+
|
|
29
|
+
const { SOURCE_PATH } = require('../TemplateManager/src/libs/Consts');
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
async function generateSchema(_izContext, objSchemaPath, generateSchemaSettings) {
|
|
34
|
+
try {
|
|
35
|
+
console.log('objSchemaPath', objSchemaPath);
|
|
36
|
+
// --------- Prepare path -------------
|
|
37
|
+
// point to app/src
|
|
38
|
+
let saveFilePath = join(objSchemaPath, `../`);
|
|
39
|
+
console.log("saveFilePath: ", saveFilePath);
|
|
40
|
+
|
|
41
|
+
// point to root folder of service
|
|
42
|
+
let localServicePath = join(saveFilePath, "../../");
|
|
43
|
+
console.log("localServicePath: ", localServicePath);
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
//------ Start Create Source ------
|
|
47
|
+
|
|
48
|
+
// collect all result of template data for execute createSource
|
|
49
|
+
let allCreateSource = [];
|
|
50
|
+
// collect all path that need to empty before createSource
|
|
51
|
+
let allEmptyPath = [];
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
// Validate that all generateNames in generateSettings are present in the schemaConfig
|
|
55
|
+
const generateNameSet = new Set(Object.keys(schemaConfig.TemplateAndData));
|
|
56
|
+
|
|
57
|
+
// Find any missing generateNames that are not in the schemaConfig
|
|
58
|
+
let missingGenerateName = generateSchemaSettings.
|
|
59
|
+
filter(({ generateName }) => !generateNameSet.has(generateName));
|
|
60
|
+
|
|
61
|
+
// If there are missing generateNames, throw an error with the list of missing names
|
|
62
|
+
if (missingGenerateName.length) {
|
|
63
|
+
throw Error(`Invalid generateName:[ ${missingGenerateName.map(({ generateName }) => generateName).join(", ")} ]`);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
// start create generateSchema depend on
|
|
68
|
+
for (const { generateName, settingData } of generateSchemaSettings) {
|
|
69
|
+
let generateSchemaData = require(join(__dirname, schemaConfig.TemplateAndData[generateName]));
|
|
70
|
+
let createSourceResult = await generateSchemaData(_izContext, objSchemaPath, settingData);
|
|
71
|
+
|
|
72
|
+
// Filter out empty or invalid objects before adding to allCreateSource
|
|
73
|
+
if (Array.isArray(createSourceResult)) {
|
|
74
|
+
const validResults = createSourceResult.filter(item =>
|
|
75
|
+
item && item.templatePath && item.templateData && item.setting
|
|
76
|
+
);
|
|
77
|
+
allCreateSource.push(...validResults);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// check each allCreateSource valid
|
|
82
|
+
for (let item of allCreateSource) {
|
|
83
|
+
// throw Error('Skipping invalid source item:', item);
|
|
84
|
+
if (!item || !item.templatePath || !item.templateData || !item.setting) {
|
|
85
|
+
console.log('throw Error Skipping invalid source item:', item);
|
|
86
|
+
throw Error('Skipping invalid source item:', item);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const { templatePath, templateData, setting, emptyPath: returnEmptyPath } = item;
|
|
90
|
+
setting.checkCreateSourcePass = true;
|
|
91
|
+
|
|
92
|
+
let [status, errors] = await createSource(
|
|
93
|
+
readFileSync(templatePath, 'utf8'),
|
|
94
|
+
templateData,
|
|
95
|
+
setting,
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
if (status === false) {
|
|
99
|
+
throw Error(errors);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
allEmptyPath.push(returnEmptyPath);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// validate path before empty folder
|
|
106
|
+
for (let emptyPath of allEmptyPath) {
|
|
107
|
+
validatePathWithRootServicePath(localServicePath, emptyPath)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
for (let emptyPath of allEmptyPath) {
|
|
111
|
+
await deleteFileInDir(emptyPath);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
// generate all source
|
|
116
|
+
for (let item of allCreateSource) {
|
|
117
|
+
// throw error if item is invalid
|
|
118
|
+
if (!item || !item.templatePath || !item.templateData || !item.setting) {
|
|
119
|
+
console.log('Throwing invalid source item:', item);
|
|
120
|
+
throw Error('Throwing invalid source item:', item);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const { templatePath, templateData, setting } = item;
|
|
124
|
+
setting.checkCreateSourcePass = false;
|
|
125
|
+
|
|
126
|
+
await createSource(
|
|
127
|
+
readFileSync(templatePath, 'utf8'),
|
|
128
|
+
templateData,
|
|
129
|
+
setting,
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
console.log('Generated all source files successfully');
|
|
134
|
+
return 'return values';
|
|
135
|
+
} catch (error) {
|
|
136
|
+
console.error('Error generating code:', error);
|
|
137
|
+
throw error;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
module.exports = generateSchema
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
module.exports = {
|
|
21
|
+
TemplateAndData: {
|
|
22
|
+
// ** mock schema config **
|
|
23
|
+
mainAttributeTree: './TemplateData/mainAttributeTree/generateTemplateData.js',
|
|
24
|
+
},
|
|
25
|
+
Plugin: {
|
|
26
|
+
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -1,3 +1,23 @@
|
|
|
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
|
+
|
|
1
21
|
module.exports = {
|
|
2
22
|
TemplateAndData: {
|
|
3
23
|
// ** PerActionEndpoint **
|
|
@@ -0,0 +1,52 @@
|
|
|
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
|
+
// Import required modules
|
|
21
|
+
const { join } = require('path');
|
|
22
|
+
|
|
23
|
+
const modules = {
|
|
24
|
+
mainAttributeTreeSchema: {}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Generates code with templates for different actions
|
|
28
|
+
* @param {Object} _izContext - Context object
|
|
29
|
+
* @param {string} objSchemaPath - Path to the schema
|
|
30
|
+
* @returns {Array} Array of generated code parameters
|
|
31
|
+
*/
|
|
32
|
+
async function generateCodeWithTemplate(_izContext, objSchemaPath) {
|
|
33
|
+
try {
|
|
34
|
+
const saveFilePath = join(objSchemaPath, '../');
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
// will receive objSchemaPath and prepare params for each data function
|
|
38
|
+
// then data function will return params for createSource
|
|
39
|
+
|
|
40
|
+
// (template, data, { savePath, hookPath, saveFileName, fileExtension, initialData, isAppend = false, checkCreateSourcePass = false })
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
|
|
45
|
+
};
|
|
46
|
+
} catch (error) {
|
|
47
|
+
_izContext.logger.error('Error generating code with template perActionComplete:', error);
|
|
48
|
+
return [];
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
module.exports = generateCodeWithTemplate;
|
package/src/reStructure/TemplateData/attributeTreeSchema/mainAttributeTreeSchema/attributeLink.ejs
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const izara = require("@izara_project/izara-middleware");
|
|
2
|
+
let { pattern } = izara.validatorSchema.stringNotEmpty(); // should not be empty string
|
|
3
|
+
|
|
4
|
+
module.exports = [
|
|
5
|
+
{
|
|
6
|
+
objectType: "<%- objectType %>",
|
|
7
|
+
overWriteHandlers: { // optional, if not set will create default handlers, if empty will not create handler and main function
|
|
8
|
+
//(<overWriteHandlers<%- objectType %>>)
|
|
9
|
+
//(</overWriteHandlers<%- objectType %>>)
|
|
10
|
+
},
|
|
11
|
+
overwriteGeneratedMainFunction: [
|
|
12
|
+
//(<overwriteGeneratedMainFunction<%- objectType %>>)
|
|
13
|
+
//(</overwriteGeneratedMainFunction<%- objectType %>>)
|
|
14
|
+
],
|
|
15
|
+
canDelete: true,
|
|
16
|
+
storageResources: <%- storageResources %>,
|
|
17
|
+
fieldNames: <%- fieldNames %>,
|
|
18
|
+
compositeKeyDeliminator: "<%- compositeKeyDeliminator %>",
|
|
19
|
+
identifiers: <%- identifiers %>
|
|
20
|
+
}
|
|
21
|
+
]
|
|
@@ -0,0 +1,128 @@
|
|
|
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 { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("../../../../MainLibs/src/Utils");
|
|
23
|
+
const { SOURCE_PATH, ADD_ON_DATA_STRUCTURE_TYPE, ATTRIBUTE_TAG, fieldNameSetting, FIELD_NAME_TPYE, SAVE_FILE_NAME } = require('../../libs/Consts');
|
|
24
|
+
const templatePath = path.join(__dirname, "./template.ejs");
|
|
25
|
+
|
|
26
|
+
function data(_izContext, objectSchema, srcPath) {
|
|
27
|
+
const createSources = [];
|
|
28
|
+
let attributeTreeObjSchemas = [];
|
|
29
|
+
if (objectSchema.hasOwnProperty("addOnDataStructure")) {
|
|
30
|
+
for (const versionedData of objectSchema.addOnDataStructure) {
|
|
31
|
+
if (versionedData.type === ADD_ON_DATA_STRUCTURE_TYPE.attributeTree) {
|
|
32
|
+
const objectType = objectSchema.objectType; // main objectType
|
|
33
|
+
const storageResources = objectSchema.storageResources // storageResource from main objectType
|
|
34
|
+
const storageResourceTag = Object.keys(storageResources) // storage ResourceTag from main objectType
|
|
35
|
+
const compositeKeyDeliminator = objectSchema.compositeKeyDeliminator
|
|
36
|
+
attributeTreeObjSchemas.push(
|
|
37
|
+
{
|
|
38
|
+
objectType: objectType + ATTRIBUTE_TAG.attributeTagLabel,
|
|
39
|
+
fieldNames: {
|
|
40
|
+
labelId: fieldNameSetting(FIELD_NAME_TPYE.identifiers)
|
|
41
|
+
},
|
|
42
|
+
identifiers: [
|
|
43
|
+
{
|
|
44
|
+
type: "identifier",
|
|
45
|
+
fieldName: "labelId"
|
|
46
|
+
}
|
|
47
|
+
]
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
objectType: objectType + ATTRIBUTE_TAG.attributeTagLink,
|
|
51
|
+
fieldNames: {
|
|
52
|
+
[objectType + ATTRIBUTE_TAG.attributeTagLink + "Id"]: fieldNameSetting(FIELD_NAME_TPYE.identifiers),
|
|
53
|
+
[objectType + "Id"]: fieldNameSetting(FIELD_NAME_TPYE.requiredOnCreateFieldName),
|
|
54
|
+
topLevelParentIdentifierProperties: fieldNameSetting(FIELD_NAME_TPYE.requiredOnCreateFieldName),
|
|
55
|
+
parentNodeIdentifierLabel: fieldNameSetting(FIELD_NAME_TPYE.requiredOnCreateFieldName),
|
|
56
|
+
parentNodeIdentifierProperties: fieldNameSetting(FIELD_NAME_TPYE.requiredOnCreateFieldName),
|
|
57
|
+
},
|
|
58
|
+
identifiers: [
|
|
59
|
+
{
|
|
60
|
+
type: "identifier",
|
|
61
|
+
fieldName: `${objectType + ATTRIBUTE_TAG.attributeTagLink}Id`
|
|
62
|
+
}
|
|
63
|
+
]
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
objectType: objectType + ATTRIBUTE_TAG.attributeTagProperty,
|
|
67
|
+
fieldNames: {
|
|
68
|
+
propertyId: fieldNameSetting(FIELD_NAME_TPYE.identifiers),
|
|
69
|
+
propertyLabelId: fieldNameSetting(FIELD_NAME_TPYE.optionalOnCreate)
|
|
70
|
+
},
|
|
71
|
+
identifiers: [
|
|
72
|
+
{
|
|
73
|
+
type: "identifier",
|
|
74
|
+
fieldName: "propertyId"
|
|
75
|
+
}
|
|
76
|
+
]
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
objectType: objectType + ATTRIBUTE_TAG.attributeTagPropertyLabel,
|
|
80
|
+
fieldNames: {
|
|
81
|
+
propertyLabelId: fieldNameSetting(FIELD_NAME_TPYE.identifiers)
|
|
82
|
+
},
|
|
83
|
+
identifiers: [
|
|
84
|
+
{
|
|
85
|
+
type: "identifier",
|
|
86
|
+
fieldName: "propertyLabelId"
|
|
87
|
+
}
|
|
88
|
+
]
|
|
89
|
+
}
|
|
90
|
+
)
|
|
91
|
+
for (let attributeTreeObjSchema of attributeTreeObjSchemas) {
|
|
92
|
+
Object.assign(attributeTreeObjSchema, {
|
|
93
|
+
storageResources: storageResources, // add storageResources
|
|
94
|
+
compositeKeyDeliminator: compositeKeyDeliminator
|
|
95
|
+
})
|
|
96
|
+
for (let attributeTreeFieldName of Object.values(attributeTreeObjSchema.fieldNames)) {
|
|
97
|
+
Object.assign(attributeTreeFieldName, { storageResourceTags: storageResourceTag }) // add storageResourceTags for each fieldName
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
}
|
|
103
|
+
// console.log("attributeTreeObjSchemas", attributeTreeObjSchemas)
|
|
104
|
+
for (const attributeTreeObjSchema of attributeTreeObjSchemas) {
|
|
105
|
+
createSources.push({
|
|
106
|
+
templatePath: templatePath,
|
|
107
|
+
templateData: {
|
|
108
|
+
fieldNames: JSON.stringify(attributeTreeObjSchema.fieldNames),
|
|
109
|
+
identifiers: JSON.stringify(attributeTreeObjSchema.identifiers),
|
|
110
|
+
objectType: attributeTreeObjSchema.objectType,
|
|
111
|
+
storageResources: JSON.stringify(attributeTreeObjSchema.storageResources),
|
|
112
|
+
compositeKeyDeliminator: attributeTreeObjSchema.compositeKeyDeliminator
|
|
113
|
+
},
|
|
114
|
+
setting: {
|
|
115
|
+
savePath: path.join(srcPath, SOURCE_PATH.generatedAttributeTree, attributeTreeObjSchema.objectType + "/"),
|
|
116
|
+
hookPath: path.join(srcPath, "schemaHook", attributeTreeObjSchema.objectType, "/"),
|
|
117
|
+
saveFileName: SAVE_FILE_NAME.attributeTreeObjectSchema,
|
|
118
|
+
fileExtension: ".js",
|
|
119
|
+
isAppend: false
|
|
120
|
+
}
|
|
121
|
+
})
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
console.log("createSources", createSources)
|
|
125
|
+
return createSources;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
module.exports = data
|
|
@@ -53,6 +53,7 @@ function data(_izContext, createSourceParams, srcPath) {
|
|
|
53
53
|
Object.entries(SOURCE_GENERATE_IAM_ROLE)
|
|
54
54
|
.filter(([_, enabled]) => enabled)
|
|
55
55
|
.forEach(([_, value]) => {
|
|
56
|
+
if (value === SOURCE_GENERATE_IAM_ROLE.NodeCompleteRole) return;
|
|
56
57
|
roleNameConfigs.add(`${upperCase(value)}Role`);
|
|
57
58
|
roleNameConcatConfigs.add(`${upperCase(value)}`);
|
|
58
59
|
});
|
|
@@ -69,7 +70,6 @@ function data(_izContext, createSourceParams, srcPath) {
|
|
|
69
70
|
}
|
|
70
71
|
});
|
|
71
72
|
|
|
72
|
-
|
|
73
73
|
// Generate YAML and JS configurations
|
|
74
74
|
const roleConfigYaml = createRoleNameConfigFileYaml(roleNameConfigs, srcPath);
|
|
75
75
|
const roleConfigJs = createRoleNameConfigFileJs(roleNameConcatConfigs, srcPath);
|
|
@@ -76,7 +76,7 @@ const createExternalSnsSubscriptions = async (_izContext, allObjSchemas, allRelS
|
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
|
-
console.log("snsServiceConfigArray::", snsServiceConfigArray)
|
|
79
|
+
// console.log("snsServiceConfigArray::", snsServiceConfigArray)
|
|
80
80
|
|
|
81
81
|
return {
|
|
82
82
|
templatePath: templatePath,
|
|
@@ -37,7 +37,8 @@ const {
|
|
|
37
37
|
externalResourceSns,
|
|
38
38
|
externalResourceName,
|
|
39
39
|
DYNAMO_RESOURCE,
|
|
40
|
-
LAMBDA_RESOURCE
|
|
40
|
+
LAMBDA_RESOURCE,
|
|
41
|
+
SOURCE_GENERATE_IAM_ROLE
|
|
41
42
|
} = require('../../../../../../../MainLibs/src/Consts');
|
|
42
43
|
|
|
43
44
|
/**
|
|
@@ -105,6 +106,7 @@ function createSourceParams(_izContext, srcPath) {
|
|
|
105
106
|
resourceLocation: SOURCE_PATH.resourceLocationWebSocket,
|
|
106
107
|
additionalResourcePermission,
|
|
107
108
|
functionNameConfig: upperCase(functionName) + upperCase(shortNameHandler(handlerType)),
|
|
109
|
+
roleName: SOURCE_GENERATE_IAM_ROLE.FlowSchemaUploadS3Role
|
|
108
110
|
},
|
|
109
111
|
setting: {
|
|
110
112
|
saveFileName: upperCase(SAVE_FILE_NAME.flowSchema),
|
|
@@ -9,20 +9,7 @@
|
|
|
9
9
|
filterPatterns: #**** need to update serverless framwork upper v.2.69.1
|
|
10
10
|
- body: {"MessageAttributes":{"callingFlow":{"Value":["${self:custom.iz_resourcePrefix}<%- firstLetterUpperCase(functionName) %><%- firstLetterUpperCase(handlerType) %>"]}}} # functionName of callingFlow
|
|
11
11
|
- body: {"MessageAttributes":{"callingFlow":{"Value":[{"exists":false}]}}}
|
|
12
|
-
|
|
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
|
-
<%_}) _%>
|
|
12
|
+
role: <%- roleName %>Role
|
|
26
13
|
#<#<%- functionName %><%- handlerType %>IamRole#>
|
|
27
14
|
#<#/<%- functionName %><%- handlerType %>IamRole#>
|
|
28
15
|
<%_ function firstLetterUpperCase(text){
|
package/src/reStructure/TemplateData/flowSchema/components/upload/createObject/functionYaml/data.js
CHANGED
|
@@ -31,7 +31,8 @@ const {
|
|
|
31
31
|
SAVE_FILE_NAME,
|
|
32
32
|
FUNCTION_NAME,
|
|
33
33
|
shortNameHandler,
|
|
34
|
-
externalResourceYaml
|
|
34
|
+
externalResourceYaml,
|
|
35
|
+
SOURCE_GENERATE_IAM_ROLE
|
|
35
36
|
} = require('../../../../../../../MainLibs/src/Consts');
|
|
36
37
|
|
|
37
38
|
const templatePath = path.join(__dirname, "template.ejs");
|
|
@@ -126,7 +127,8 @@ function createSourceParams(_izContext, flowSchema, srcPath) {
|
|
|
126
127
|
handlerType,
|
|
127
128
|
additionalResourcePermission,
|
|
128
129
|
route,
|
|
129
|
-
functionNameConfig: upperCase(functionName) + upperCase(shortNameHandler(handlerType))
|
|
130
|
+
functionNameConfig: upperCase(functionName) + upperCase(shortNameHandler(handlerType)),
|
|
131
|
+
roleName: SOURCE_GENERATE_IAM_ROLE.FlowSchemaUploadS3Role
|
|
130
132
|
},
|
|
131
133
|
setting: {
|
|
132
134
|
savePath: path.join(srcPath, SOURCE_PATH.appYaml),
|
|
@@ -13,20 +13,7 @@
|
|
|
13
13
|
route: <%- route %>
|
|
14
14
|
# authorizer: ${self:custom.iz_authorizerAppLevel}
|
|
15
15
|
# identifierResource: 'route.request.header.Auth'
|
|
16
|
-
|
|
17
|
-
<%_ additionalResourcePermission.forEach(resourcePermission => { _%>
|
|
18
|
-
- Effect: <%- resourcePermission.effect %>
|
|
19
|
-
Action:
|
|
20
|
-
<%_ Object.keys(resourcePermission.action).forEach(resourcePerAction => { _%>
|
|
21
|
-
<%_ resourcePermission.action[resourcePerAction].forEach(permission => { _%>
|
|
22
|
-
- <%- resourcePerAction %>:<%- permission %>
|
|
23
|
-
<%_}) _%>
|
|
24
|
-
<%_ }) _%>
|
|
25
|
-
Resource:
|
|
26
|
-
<%_ resourcePermission.resource.forEach(resource => { _%>
|
|
27
|
-
- <%- resource %>
|
|
28
|
-
<%_ }) _%>
|
|
29
|
-
<%_}) _%>
|
|
16
|
+
role: <%- roleName %>Role
|
|
30
17
|
#<#<%- functionName %><%- handlerType %>IamRole#>
|
|
31
18
|
#<#/<%- functionName %><%- handlerType %>IamRole#>
|
|
32
19
|
<%_ function firstLetterUpperCase(text){
|
|
@@ -35,7 +35,8 @@ const {
|
|
|
35
35
|
shortNameHandler,
|
|
36
36
|
defaultIamRolePerAction,
|
|
37
37
|
DYNAMO_RESOURCE,
|
|
38
|
-
SHORT_FUNCTION_NAME
|
|
38
|
+
SHORT_FUNCTION_NAME,
|
|
39
|
+
SOURCE_GENERATE_IAM_ROLE
|
|
39
40
|
} = require('../../../../../../../MainLibs/src/Consts');
|
|
40
41
|
|
|
41
42
|
|
|
@@ -102,6 +103,7 @@ function createSourceParams(_izContext, srcPath) {
|
|
|
102
103
|
handlerType: handlerType,
|
|
103
104
|
additionalResourcePermission: additionalResourcePermission,
|
|
104
105
|
functionNameConfig: upperCase(SHORT_FUNCTION_NAME.createObjectS3Complete) + upperCase(shortNameHandler(handlerType)),
|
|
106
|
+
roleName: SOURCE_GENERATE_IAM_ROLE.FlowSchemaUploadS3Role
|
|
105
107
|
},
|
|
106
108
|
setting: {
|
|
107
109
|
savePath: path.join(srcPath, SOURCE_PATH.appYaml),
|
|
@@ -9,20 +9,7 @@
|
|
|
9
9
|
filterPatterns: #**** need to update serverless framwork upper v.2.69.1
|
|
10
10
|
- body: {"MessageAttributes":{"callingFlow":{"Value":["${self:custom.iz_resourcePrefix}<%- functionName %>"]}}} # functionName of callingFlow
|
|
11
11
|
- body: {"MessageAttributes":{"callingFlow":{"Value":[{"exists":false}]}}}
|
|
12
|
-
|
|
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
|
-
<%_}) _%>
|
|
12
|
+
role: <%- roleName %>Role
|
|
26
13
|
#<#<%- functionName %><%- handlerType %>IamRole#>
|
|
27
14
|
#<#/<%- functionName %><%- handlerType %>IamRole#>
|
|
28
15
|
<%_ function firstLetterUpperCase(text){
|
|
@@ -35,7 +35,8 @@ const {
|
|
|
35
35
|
SAVE_FILE_NAME,
|
|
36
36
|
awaitingMultipleStepsRole,
|
|
37
37
|
externalResourceSns,
|
|
38
|
-
externalResourceName
|
|
38
|
+
externalResourceName,
|
|
39
|
+
SOURCE_GENERATE_IAM_ROLE
|
|
39
40
|
} = require('../../../../../../../../MainLibs/src/Consts');
|
|
40
41
|
|
|
41
42
|
const {
|
|
@@ -89,6 +90,7 @@ function createSourceParams(_izContext, srcPath) {
|
|
|
89
90
|
resourceLocation: SOURCE_PATH.resourceLocationWebSocket,
|
|
90
91
|
additionalResourcePermission,
|
|
91
92
|
functionNameConfig: upperCase(functionName) + upperCase(shortNameHandler(handlerType)),
|
|
93
|
+
roleName: SOURCE_GENERATE_IAM_ROLE.FlowSchemaUploadS3Role
|
|
92
94
|
},
|
|
93
95
|
setting: {
|
|
94
96
|
saveFileName: upperCase(SAVE_FILE_NAME.flowSchema),
|
|
@@ -6,20 +6,7 @@
|
|
|
6
6
|
- sqs:
|
|
7
7
|
arn: arn:aws:sqs:${self:custom.iz_region}:${self:custom.iz_accountId}:${self:custom.iz_resourcePrefix}<%- functionName %><%- firstLetterUpperCase(handlerType) %>
|
|
8
8
|
batchSize: 10
|
|
9
|
-
|
|
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
|
-
<%_}) _%>
|
|
9
|
+
role: <%- roleName %>Role
|
|
23
10
|
#<#<%- functionName %><%- handlerType %>IamRole#>
|
|
24
11
|
#<#/<%- functionName %><%- handlerType %>IamRole#>
|
|
25
12
|
<%_ function firstLetterUpperCase(text){
|
|
@@ -37,7 +37,8 @@ const {
|
|
|
37
37
|
externalResourceSns,
|
|
38
38
|
externalResourceName,
|
|
39
39
|
DYNAMO_RESOURCE,
|
|
40
|
-
LAMBDA_RESOURCE
|
|
40
|
+
LAMBDA_RESOURCE,
|
|
41
|
+
SOURCE_GENERATE_IAM_ROLE
|
|
41
42
|
} = require('../../../../../../../../MainLibs/src/Consts');
|
|
42
43
|
|
|
43
44
|
const {
|
|
@@ -118,6 +119,7 @@ function createSourceParams(_izContext, srcPath) {
|
|
|
118
119
|
resourceLocation: SOURCE_PATH.resourceLocationWebSocket,
|
|
119
120
|
additionalResourcePermission,
|
|
120
121
|
functionNameConfig: upperCase("ReservedLimitComp") + upperCase(shortNameHandler(handlerType)),
|
|
122
|
+
roleName: SOURCE_GENERATE_IAM_ROLE.FlowSchemaUploadS3Role
|
|
121
123
|
},
|
|
122
124
|
setting: {
|
|
123
125
|
saveFileName: upperCase(SAVE_FILE_NAME.flowSchema),
|
|
@@ -9,20 +9,7 @@
|
|
|
9
9
|
filterPatterns: #**** need to update serverless framwork upper v.2.69.1
|
|
10
10
|
- body: {"MessageAttributes":{"callingFlow":{"Value":["${self:custom.iz_resourcePrefix}<%- firstLetterUpperCase(functionName) %><%- firstLetterUpperCase(handlerType) %>"]}}} # functionName of callingFlow
|
|
11
11
|
- body: {"MessageAttributes":{"callingFlow":{"Value":[{"exists":false}]}}}
|
|
12
|
-
|
|
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
|
-
<%_}) _%>
|
|
12
|
+
role: <%- roleName %>Role
|
|
26
13
|
#<#<%- functionName %><%- handlerType %>IamRole#>
|
|
27
14
|
#<#/<%- functionName %><%- handlerType %>IamRole#>
|
|
28
15
|
<%_ function firstLetterUpperCase(text){
|
|
@@ -33,7 +33,8 @@ const {
|
|
|
33
33
|
SNS_RESOURCE,
|
|
34
34
|
shortNameHandler,
|
|
35
35
|
FUNCTION_NAME,
|
|
36
|
-
LAMBDA_RESOURCE
|
|
36
|
+
LAMBDA_RESOURCE,
|
|
37
|
+
SOURCE_GENERATE_IAM_ROLE
|
|
37
38
|
} = require('../../../../../../../../MainLibs/src/Consts');
|
|
38
39
|
|
|
39
40
|
const templatePath = path.join(__dirname, "./template.ejs")
|
|
@@ -113,7 +114,8 @@ function createSourceParam(_izContext, flowSchema, srcPath) {
|
|
|
113
114
|
additionalResourcePermission,
|
|
114
115
|
resourceLocation: SOURCE_PATH.resourceLocationWebSocket,
|
|
115
116
|
bucketName,
|
|
116
|
-
functionNameConfig: upperCase(functionName) + upperCase(shortNameHandler(handlerType))
|
|
117
|
+
functionNameConfig: upperCase(functionName) + upperCase(shortNameHandler(handlerType)),
|
|
118
|
+
roleName: SOURCE_GENERATE_IAM_ROLE.FlowSchemaUploadS3Role
|
|
117
119
|
},
|
|
118
120
|
setting: {
|
|
119
121
|
savePath: path.join(srcPath, SOURCE_PATH.appYaml),
|
|
@@ -14,20 +14,7 @@
|
|
|
14
14
|
# - prefix: uploads/
|
|
15
15
|
# - suffix: .csv
|
|
16
16
|
forceDeploy: true
|
|
17
|
-
|
|
18
|
-
<%_ additionalResourcePermission.forEach(resourcePermission => { _%>
|
|
19
|
-
- Effect: <%- resourcePermission.effect %>
|
|
20
|
-
Action:
|
|
21
|
-
<%_ Object.keys(resourcePermission.action).forEach(resourcePerAction => { _%>
|
|
22
|
-
<%_ resourcePermission.action[resourcePerAction].forEach(permission => { _%>
|
|
23
|
-
- <%- resourcePerAction %>:<%- permission %>
|
|
24
|
-
<%_}) _%>
|
|
25
|
-
<%_ }) _%>
|
|
26
|
-
Resource:
|
|
27
|
-
<%_ resourcePermission.resource.forEach(resource => { _%>
|
|
28
|
-
- <%- resource %>
|
|
29
|
-
<%_ }) _%>
|
|
30
|
-
<%_}) _%>
|
|
17
|
+
role: <%- roleName %>Role
|
|
31
18
|
#<#<%- functionName %><%- handlerType %>IamRole#>
|
|
32
19
|
#<#/<%- functionName %><%- handlerType %>IamRole#>
|
|
33
20
|
<%_ function firstLetterUpperCase(text){
|
package/src/reStructure/TemplateData/flowSchema/components/websocket/connect/functionYaml/data.js
CHANGED
|
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
18
18
|
'use strict';
|
|
19
19
|
const path = require('path');
|
|
20
20
|
|
|
21
|
-
const { SOURCE_PATH, SAVE_FILE_NAME, defaultIamRolePerAction, createIamRole, RESOURCE_CLASSES, DYNAMO_RESOURCE, resourceNames } = require("../../../../libs/Consts");
|
|
21
|
+
const { SOURCE_PATH, SAVE_FILE_NAME, defaultIamRolePerAction, createIamRole, RESOURCE_CLASSES, DYNAMO_RESOURCE, resourceNames, SOURCE_GENERATE_IAM_ROLE } = require("../../../../libs/Consts");
|
|
22
22
|
const { firstLetterUpperCase: upperCase } = require('../../../../../../MainLibs/src/Utils');
|
|
23
23
|
|
|
24
24
|
const templatePath = path.join(__dirname, "./template.ejs")
|
|
@@ -60,7 +60,9 @@ function createWebSocketConnectYaml(_izContext, srcPath) {
|
|
|
60
60
|
templateData: {
|
|
61
61
|
functionName,
|
|
62
62
|
resourceLocation: SOURCE_PATH.resourceLocationWebSocket,
|
|
63
|
-
additionalResourcePermission
|
|
63
|
+
additionalResourcePermission,
|
|
64
|
+
roleName: SOURCE_GENERATE_IAM_ROLE.FlowSchemaUploadS3Role
|
|
65
|
+
|
|
64
66
|
},
|
|
65
67
|
setting: {
|
|
66
68
|
savePath: path.join(srcPath, SOURCE_PATH.appYaml),
|
package/src/reStructure/TemplateData/flowSchema/components/websocket/dynamoDb/ReservedTableData.js
CHANGED
|
@@ -19,7 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
19
19
|
const path = require('path');
|
|
20
20
|
const { SOURCE_PATH, SAVE_FILE_NAME } = require('../../../../../../MainLibs/src/Consts');
|
|
21
21
|
|
|
22
|
-
const templatePath = path.join(__dirname, "
|
|
22
|
+
const templatePath = path.join(__dirname, "../../../../resourceYaml/dynamodb/template.ejs")
|
|
23
23
|
|
|
24
24
|
function data(_izContext, srcPath) {
|
|
25
25
|
let resultForCreateSources = [];
|
package/src/reStructure/TemplateData/flowSchema/components/websocket/dynamoDb/WebSocketTaskData.js
CHANGED
|
@@ -19,7 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
19
19
|
const path = require('path');
|
|
20
20
|
const { SOURCE_PATH, SAVE_FILE_NAME } = require('../../../../../../MainLibs/src/Consts');
|
|
21
21
|
|
|
22
|
-
const templatePath = path.join(__dirname, "
|
|
22
|
+
const templatePath = path.join(__dirname, "../../../../resourceYaml/dynamodb/template.ejs")
|
|
23
23
|
|
|
24
24
|
function data(_izContext, srcPath) {
|
|
25
25
|
let resultForCreateSources = [];
|
|
@@ -102,6 +102,10 @@ const createSharedResource = (_izContext, createSourceParams, srcPath) => {
|
|
|
102
102
|
handlerType: [],
|
|
103
103
|
resources: []
|
|
104
104
|
},
|
|
105
|
+
[SOURCE_GENERATE_IAM_ROLE.FlowSchemaUploadS3Role]: {
|
|
106
|
+
handlerType: [],
|
|
107
|
+
resources: {}
|
|
108
|
+
},
|
|
105
109
|
Other: []
|
|
106
110
|
};
|
|
107
111
|
const objectTypeList = [];
|
|
@@ -177,6 +181,12 @@ const createSharedResource = (_izContext, createSourceParams, srcPath) => {
|
|
|
177
181
|
templateData.additionalResourcePermission,
|
|
178
182
|
groupedByObjectType[SOURCE_GENERATE_IAM_ROLE.ProcessFindDataRole].resources
|
|
179
183
|
);
|
|
184
|
+
} else if (templateData.roleName.includes(SOURCE_GENERATE_IAM_ROLE.FlowSchemaUploadS3Role)) {
|
|
185
|
+
groupedByObjectType[SOURCE_GENERATE_IAM_ROLE.FlowSchemaUploadS3Role].handlerType.push(templateData);
|
|
186
|
+
processResourcePermissions(
|
|
187
|
+
templateData.additionalResourcePermission,
|
|
188
|
+
groupedByObjectType[SOURCE_GENERATE_IAM_ROLE.FlowSchemaUploadS3Role].resources
|
|
189
|
+
)
|
|
180
190
|
}
|
|
181
191
|
else {
|
|
182
192
|
// Handle other items
|
|
@@ -52,7 +52,7 @@ function data(_izContext, srcPath) {
|
|
|
52
52
|
templatePath: templatePath,
|
|
53
53
|
templateData: createUpdateNodeCompleteQueueName,
|
|
54
54
|
setting: {
|
|
55
|
-
initialData: "
|
|
55
|
+
initialData: "Resources:\n",
|
|
56
56
|
savePath: path.join(srcPath, SOURCE_PATH.resourceYaml),
|
|
57
57
|
saveFileName: SAVE_FILE_NAME.snsInSqsYaml,
|
|
58
58
|
fileExtension: ".yml",
|
|
@@ -63,29 +63,24 @@ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
|
|
|
63
63
|
for (const objectSchema of allObjSchemas.records) {
|
|
64
64
|
try {
|
|
65
65
|
// Generate handlers
|
|
66
|
-
const handlerParams = Object.entries(modules.handlers)
|
|
67
|
-
handlerFn(_izContext, objectSchema, saveFilePath)
|
|
68
|
-
);
|
|
66
|
+
const handlerParams = Object.entries(modules.handlers)
|
|
67
|
+
.flatMap(([type, handlerFn]) => handlerFn(_izContext, objectSchema, saveFilePath));
|
|
69
68
|
|
|
70
69
|
// Generate main functions
|
|
71
|
-
const functionParams = await Promise.all(
|
|
70
|
+
const functionParams = (await Promise.all(
|
|
72
71
|
Object.entries(modules.mainFunctions).map(([action, functionFn]) =>
|
|
73
72
|
functionFn(_izContext, objectSchema, saveFilePath)
|
|
74
73
|
)
|
|
75
|
-
);
|
|
74
|
+
)).flat();
|
|
76
75
|
|
|
77
76
|
// Generate function YAML files
|
|
78
|
-
const yamlParams = Object.entries(modules.yamlGenerators)
|
|
79
|
-
yamlFn(_izContext, objectSchema, saveFilePath)
|
|
80
|
-
);
|
|
77
|
+
const yamlParams = Object.entries(modules.yamlGenerators)
|
|
78
|
+
.flatMap(([type, yamlFn]) => yamlFn(_izContext, objectSchema, saveFilePath));
|
|
81
79
|
|
|
82
80
|
// Generate code libs
|
|
83
81
|
const libsParam = createGenerateCodeLibs(_izContext, saveFilePath);
|
|
84
82
|
|
|
85
|
-
|
|
86
|
-
if (objectSchema.flowSchema?.uploadS3 === true) {
|
|
87
|
-
createSourceParams.push(...handlerParams, ...functionParams, ...yamlParams, libsParam);
|
|
88
|
-
}
|
|
83
|
+
createSourceParams.push(...handlerParams, ...functionParams, ...yamlParams, libsParam);
|
|
89
84
|
} catch (error) {
|
|
90
85
|
_izContext.logger.error(`Error processing schema ${objectSchema.name || 'unknown'}: ${error}`);
|
|
91
86
|
}
|
|
@@ -23,8 +23,8 @@ const { ACTIONS, HANDLER } = require('@izara_project/izara-core-library-service-
|
|
|
23
23
|
|
|
24
24
|
// const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase, checkOverWriteGenerateMainFunction } = require("../#utils");
|
|
25
25
|
// const { DEFAULT_HANDLER_PER_ACTION, SOURCE_PATH, FUNCTION_NAME } = require("../../../#const");
|
|
26
|
-
const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("../../../../../MainLibs/index.js").utils;
|
|
27
|
-
const { DEFAULT_HANDLER_PER_ACTION } = require("../../../../../MainLibs/index.js").consts;
|
|
26
|
+
const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase, checkOverWriteGenerateMainFunction } = require("../../../../../MainLibs/index.js").utils;
|
|
27
|
+
const { DEFAULT_HANDLER_PER_ACTION, SOURCE_PATH, FUNCTION_NAME } = require("../../../../../MainLibs/index.js").consts;
|
|
28
28
|
|
|
29
29
|
const templatePath = path.join(__dirname, "./template.ejs")
|
|
30
30
|
/**
|
|
@@ -22,22 +22,23 @@ const path = require('path');
|
|
|
22
22
|
const { ACTIONS, HANDLER, STORAGE_TYPES } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
|
|
23
23
|
|
|
24
24
|
// const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("../#utils");
|
|
25
|
-
// const { DEFAULT_HANDLER_PER_ACTION, createIamRole, resourceNames, RESOURCE_CLASSES, DEFAULT_LAMBDA_ROLE_PER_ACTION, SQS_RESOURCE, SOURCE_PATH, SAVE_FILE_NAME, SNS_RESOURCE, FUNCTION_NAME, DYNAMO_RESOURCE, defaultIamRolePerAction, awaitingMultipleStepsRole, shortNameHandler } = require("../#const");
|
|
26
25
|
const {
|
|
27
26
|
firstLetterLowerCase: lowerCase,
|
|
28
27
|
firstLetterUpperCase: upperCase,
|
|
29
28
|
} = require("../../../../../MainLibs/index.js").utils;
|
|
29
|
+
// const { DEFAULT_HANDLER_PER_ACTION, createIamRole, resourceNames, RESOURCE_CLASSES, DEFAULT_LAMBDA_ROLE_PER_ACTION, SQS_RESOURCE, SOURCE_PATH, SAVE_FILE_NAME, SNS_RESOURCE, FUNCTION_NAME, DYNAMO_RESOURCE, defaultIamRolePerAction, awaitingMultipleStepsRole, shortNameHandler } = require("../#const");
|
|
30
30
|
const {
|
|
31
31
|
DEFAULT_HANDLER_PER_ACTION,
|
|
32
32
|
createIamRole,
|
|
33
33
|
resourceNames,
|
|
34
34
|
RESOURCE_CLASSES,
|
|
35
35
|
DEFAULT_LAMBDA_ROLE_PER_ACTION,
|
|
36
|
+
SQS_RESOURCE,
|
|
36
37
|
SOURCE_PATH,
|
|
37
38
|
SAVE_FILE_NAME,
|
|
38
|
-
DYNAMO_RESOURCE,
|
|
39
39
|
SNS_RESOURCE,
|
|
40
40
|
FUNCTION_NAME,
|
|
41
|
+
DYNAMO_RESOURCE,
|
|
41
42
|
defaultIamRolePerAction,
|
|
42
43
|
awaitingMultipleStepsRole,
|
|
43
44
|
shortNameHandler
|
|
@@ -20,8 +20,23 @@ const path = require('path');
|
|
|
20
20
|
|
|
21
21
|
const { ACTIONS, HANDLER, STORAGE_TYPES } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
|
|
22
22
|
|
|
23
|
-
const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("
|
|
24
|
-
const {
|
|
23
|
+
const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("../../../../../MainLibs/src/Utils");
|
|
24
|
+
const {
|
|
25
|
+
DEFAULT_HANDLER_PER_ACTION,
|
|
26
|
+
createIamRole,
|
|
27
|
+
resourceNames,
|
|
28
|
+
RESOURCE_CLASSES,
|
|
29
|
+
DEFAULT_LAMBDA_ROLE_PER_ACTION,
|
|
30
|
+
SQS_RESOURCE,
|
|
31
|
+
SOURCE_PATH,
|
|
32
|
+
SAVE_FILE_NAME,
|
|
33
|
+
SNS_RESOURCE,
|
|
34
|
+
FUNCTION_NAME,
|
|
35
|
+
DYNAMO_RESOURCE,
|
|
36
|
+
defaultIamRolePerAction,
|
|
37
|
+
awaitingMultipleStepsRole,
|
|
38
|
+
shortNameHandler
|
|
39
|
+
} = require("../../../../../MainLibs/src/Consts");
|
|
25
40
|
|
|
26
41
|
const templatePath = path.join(__dirname, "./template.ejs")
|
|
27
42
|
|
|
@@ -0,0 +1,38 @@
|
|
|
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");
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
function validatePathWithRootServicePath(rootServicePath, checkPath) {
|
|
24
|
+
if (typeof (checkPath) !== "string"
|
|
25
|
+
|| (typeof (checkPath) === "string" && (
|
|
26
|
+
!checkPath.startsWith(join(rootServicePath, "app"))
|
|
27
|
+
&& !checkPath.startsWith(join(rootServicePath, "resource"))
|
|
28
|
+
&& !checkPath.startsWith(join(rootServicePath, "layer")))
|
|
29
|
+
)
|
|
30
|
+
) {
|
|
31
|
+
throw Error(`invalid path:${checkPath} not contain inside service`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
module.exports = {
|
|
37
|
+
validatePathWithRootServicePath
|
|
38
|
+
}
|