@izara_project/izara-core-generate-service-code 1.0.33 → 1.0.34
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/generateCode/generateFlowSchema/GenerateCodeFlowSchema.js +1 -1
- package/src/generateCode/generateFlowSchema/event/s3Component/upload/preSignUrl/createPreSignUrl/mainFunction/template.ejs +1 -1
- package/src/generateCode/generateFlowSchema/flowSchemaMainFunction/template.ejs +11 -5
- package/src/generateCode/generateFlowSchema/flowStep/flowStep.js +3 -3
- package/src/generateCode/generateFlowSchema/statusType/statusFieldComponent/mainFunction/template.ejs +0 -2
- package/src/generateCode/generateFlowStepWithPlugIn/afterFirstFlowStep/recievePlugIn/handler/data.js +61 -0
- package/src/generateCode/generateFlowStepWithPlugIn/afterFirstFlowStep/recievePlugIn/handler/templateApi.ejs +84 -0
- package/src/generateCode/generateFlowStepWithPlugIn/afterFirstFlowStep/recievePlugIn/handler/templateWebSocket.ejs +64 -0
- package/src/generateCode/generateFlowStepWithPlugIn/afterFirstFlowStep/recievePlugIn/mainFunction/data.js +52 -0
- package/src/generateCode/generateFlowStepWithPlugIn/afterFirstFlowStep/recievePlugIn/mainFunction/template.ejs +76 -0
- package/src/generateCode/generateFlowStepWithPlugIn/afterFirstFlowStep/recievePlugIn/yaml/data.js +86 -0
- package/src/generateCode/generateFlowStepWithPlugIn/afterFirstFlowStep/recievePlugIn/yaml/template.ejs +18 -0
- package/src/generateCode/generateFlowStepWithPlugIn/afterFirstFlowStep/sendPlugIn/handler/data.js +0 -0
- package/src/generateCode/generateFlowStepWithPlugIn/afterFirstFlowStep/sendPlugIn/handler/template.ejs +0 -0
- package/src/generateCode/generateFlowStepWithPlugIn/afterFirstFlowStep/sendPlugIn/mainFunction/data.js +0 -0
- package/src/generateCode/generateFlowStepWithPlugIn/afterFirstFlowStep/sendPlugIn/mainFunction/template.ejs +0 -0
- package/src/generateCode/generateFlowStepWithPlugIn/afterFirstFlowStep/sendPlugIn/yaml/data.js +0 -0
- package/src/generateCode/generateFlowStepWithPlugIn/afterFirstFlowStep/sendPlugIn/yaml/template.ejs +0 -0
- package/src/generateCode/generateFlowStepWithPlugIn/firstFlowStep/handler/data.js +53 -0
- package/src/generateCode/generateFlowStepWithPlugIn/firstFlowStep/handler/templateApi.ejs +84 -0
- package/src/generateCode/generateFlowStepWithPlugIn/firstFlowStep/handler/templateDsq.ejs +105 -0
- package/src/generateCode/generateFlowStepWithPlugIn/firstFlowStep/handler/templateInv.ejs +53 -0
- package/src/generateCode/generateFlowStepWithPlugIn/firstFlowStep/handler/templateSqs.ejs +87 -0
- package/src/generateCode/generateFlowStepWithPlugIn/firstFlowStep/mainFunction/data.js +45 -0
- package/src/generateCode/generateFlowStepWithPlugIn/firstFlowStep/mainFunction/template.ejs +83 -0
- package/src/generateCode/generateFlowStepWithPlugIn/firstFlowStep/queueNtopic/data.js +50 -0
- package/src/generateCode/generateFlowStepWithPlugIn/firstFlowStep/queueNtopic/template.ejs +0 -0
- package/src/generateCode/generateFlowStepWithPlugIn/firstFlowStep/topicOut/data.js +46 -0
- package/src/generateCode/generateFlowStepWithPlugIn/firstFlowStep/yaml/data.js +47 -0
- package/src/generateCode/generateFlowStepWithPlugIn/firstFlowStep/yaml/template.ejs +28 -0
- package/src/generateCode/generateFlowStepWithPlugIn/index.js +256 -0
- package/src/generateCode/generateSchema/generateTextTag/systemText/data.js +55 -46
- package/src/generateCode/resourceYamlComponent/sns-out/template.ejs +4 -0
- package/src/generateCode.js +41 -32
- package/src/libs/Libs.js +106 -8
|
@@ -0,0 +1,256 @@
|
|
|
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
|
+
import path from 'path'
|
|
19
|
+
import yaml from 'yaml';
|
|
20
|
+
import { consts as coreConsts } from '@izara_project/izara-core-library-service-schemas';
|
|
21
|
+
import libs from '#libs/Libs.js';
|
|
22
|
+
const { createSnsResource, createSqsResource, defaultIamRolePerAction, getLocalOrS3ObjectSchema, getLocalOrS3FlowSchema, resourceNames } = libs;
|
|
23
|
+
import utils from '#libs/Utils.js';
|
|
24
|
+
const { firstLetterUpperCase: upperCase, firstLetterLowerCase: lowerCase } = utils;
|
|
25
|
+
import consts from '#libs/Consts.js';
|
|
26
|
+
const { SOURCE_PATH, HANDLER, RESOURCE_CLASSES } = consts;
|
|
27
|
+
|
|
28
|
+
import yamlFlowStep from './firstFlowStep/yaml/data.js';
|
|
29
|
+
import handlerFlowStep from './firstFlowStep/handler/data.js';
|
|
30
|
+
import mainFunctionFlowStep from './firstFlowStep/mainFunction/data.js';
|
|
31
|
+
import sqsFlowStep from './firstFlowStep/queueNtopic/data.js';
|
|
32
|
+
import snsOut from './firstFlowStep/topicOut/data.js';
|
|
33
|
+
|
|
34
|
+
import yamlRecievePlugIn from './afterFirstFlowStep/recievePlugIn/yaml/data.js';
|
|
35
|
+
import handlerRecievePlugIn from './afterFirstFlowStep/recievePlugIn/handler/data.js';
|
|
36
|
+
import mainFunctionRecievePlugIn from './afterFirstFlowStep/recievePlugIn/mainFunction/data.js';
|
|
37
|
+
|
|
38
|
+
// import yamlSendPlugIn from './afterFirstFlowStep/sendPlugIn/yaml/data.js';
|
|
39
|
+
// import handlerSendPlugIn from './afterFirstFlowStep/sendPlugIn/handler/data.js';
|
|
40
|
+
// import mainFunctionSendPlugIn from './afterFirstFlowStep/sendPlugIn/mainFunction/data.js';
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Generates code from templates based on object schemas
|
|
45
|
+
* @param {Object} _izContext
|
|
46
|
+
* @param {string} appPath
|
|
47
|
+
* @param {Array} allObjSchemas
|
|
48
|
+
* @param {Array} allRelationshipSchemas
|
|
49
|
+
* @param {Object} settings
|
|
50
|
+
* @returns {Promise<Array>}
|
|
51
|
+
*/
|
|
52
|
+
async function generatePlunIg(
|
|
53
|
+
_izContext,
|
|
54
|
+
appPath,
|
|
55
|
+
allObjSchemas,
|
|
56
|
+
allLocalFlowSchemas,
|
|
57
|
+
) {
|
|
58
|
+
const allCreateSourceParams = [];
|
|
59
|
+
|
|
60
|
+
try {
|
|
61
|
+
const startAllMs = Date.now();
|
|
62
|
+
const totalSchemas = Array.isArray(allObjSchemas)
|
|
63
|
+
? allObjSchemas.length
|
|
64
|
+
: 0;
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
console.info(`[plugIn] start totalSchemas=${totalSchemas}`);
|
|
68
|
+
if (totalSchemas === 0) return [];
|
|
69
|
+
|
|
70
|
+
const configPath = path.join(appPath, '../config/serverless.config.yml');
|
|
71
|
+
const serverlessConfig = fs.readFileSync(configPath, 'utf8');
|
|
72
|
+
const config = yaml.parse(serverlessConfig);
|
|
73
|
+
const serviceTag = config.main_config.iz_serviceTag;
|
|
74
|
+
|
|
75
|
+
for (const flowSchema of allLocalFlowSchemas) {
|
|
76
|
+
for (const [flowStepName, flowStepConfig] of Object.entries(flowSchema.flowSteps)) {
|
|
77
|
+
if (flowStepName === "In" || flowStepName === "Out") {
|
|
78
|
+
continue;
|
|
79
|
+
} else {
|
|
80
|
+
const flowTag = flowSchema.flowTag;
|
|
81
|
+
const roleName = upperCase(flowTag);
|
|
82
|
+
const resourceApis = [];
|
|
83
|
+
let handler;
|
|
84
|
+
const additionalResourcePremission = defaultIamRolePerAction();
|
|
85
|
+
|
|
86
|
+
const data = {
|
|
87
|
+
additionalResourcePremission: additionalResourcePremission,
|
|
88
|
+
flowStepName: flowStepName,
|
|
89
|
+
flowTag: flowTag,
|
|
90
|
+
resourceApis: resourceApis,
|
|
91
|
+
hookTagSetting: `${flowSchema.flowTag}FunctionSetting`,
|
|
92
|
+
functionName: upperCase(flowSchema.flowTag) + upperCase(flowStepName),
|
|
93
|
+
roleName: roleName,
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
if (flowStepConfig.event.includes("ownTopic")) {
|
|
97
|
+
data['eventFlow'] = 'ownTopic'
|
|
98
|
+
handler = HANDLER.hdrSqs;
|
|
99
|
+
additionalResourcePremission.push(
|
|
100
|
+
createSnsResource(
|
|
101
|
+
[
|
|
102
|
+
upperCase(flowSchema.flowTag) + upperCase(flowStepName) + "_In"
|
|
103
|
+
]
|
|
104
|
+
),
|
|
105
|
+
createSqsResource(
|
|
106
|
+
[
|
|
107
|
+
upperCase(flowSchema.flowTag) + upperCase(flowStepName) + upperCase(handler),
|
|
108
|
+
upperCase(flowSchema.flowTag) + upperCase(flowStepName) + upperCase(handler) + "DSQ"
|
|
109
|
+
]
|
|
110
|
+
)
|
|
111
|
+
);
|
|
112
|
+
} else if (flowStepConfig.event.includes("extTopic")) {
|
|
113
|
+
data['eventFlow'] = 'extTopic'
|
|
114
|
+
handler = HANDLER.hdrSqs;
|
|
115
|
+
additionalResourcePremission.push(
|
|
116
|
+
createSqsResource(
|
|
117
|
+
[
|
|
118
|
+
upperCase(flowSchema.flowTag) + upperCase(flowStepName) + upperCase(handler),
|
|
119
|
+
upperCase(flowSchema.flowTag) + upperCase(flowStepName) + upperCase(handler) + "DSQ"
|
|
120
|
+
]
|
|
121
|
+
)
|
|
122
|
+
);
|
|
123
|
+
} else if (flowStepConfig.event.includes("lambdaSyncInv")) {
|
|
124
|
+
handler = HANDLER.hdrInv;
|
|
125
|
+
} else if (flowStepConfig.event.includes("lambdaSyncApi")) {
|
|
126
|
+
handler = HANDLER.hdrApi;
|
|
127
|
+
resourceApis.push({
|
|
128
|
+
path: `${serviceTag}/${lowerCase(flowTag)}${lowerCase(flowStepName)}`,
|
|
129
|
+
pathWithUser: `${serviceTag}/${lowerCase(flowTag)}${lowerCase(flowStepName)}/{targetUserId}`,
|
|
130
|
+
method: 'post',
|
|
131
|
+
hookTagApp: `${upperCase(flowStepName)}${upperCase(handler)}AppLevelAuthorizer`,
|
|
132
|
+
hookTagUser: `${upperCase(flowStepName)}${upperCase(handler)}UserLevelAuthorizer`
|
|
133
|
+
})
|
|
134
|
+
} else if (flowStepConfig.event.includes("queue")) {
|
|
135
|
+
handler = HANDLER.hdrDsq;
|
|
136
|
+
additionalResourcePremission.push(
|
|
137
|
+
createSqsResource(
|
|
138
|
+
[
|
|
139
|
+
upperCase(flowSchema.flowTag) + upperCase(flowStepName) + upperCase(handler),
|
|
140
|
+
upperCase(flowSchema.flowTag) + upperCase(flowStepName) + upperCase(handler) + "DSQ"
|
|
141
|
+
]
|
|
142
|
+
)
|
|
143
|
+
);
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
Object.assign(data, {
|
|
147
|
+
handlerType: handler,
|
|
148
|
+
handlerPath: path.join(
|
|
149
|
+
SOURCE_PATH.resourceLocationFlowSchema,
|
|
150
|
+
upperCase(flowSchema.flowTag),
|
|
151
|
+
upperCase(flowStepName),
|
|
152
|
+
'source/',
|
|
153
|
+
`${upperCase(flowTag)}${upperCase(flowStepName)}_${upperCase(handler)}`,
|
|
154
|
+
),
|
|
155
|
+
functionNameConfig: upperCase(flowSchema.flowTag) + upperCase(flowStepName) + upperCase(handler),
|
|
156
|
+
event: resourceNames(RESOURCE_CLASSES.sqs, upperCase(flowSchema.flowTag) + upperCase(flowStepName) + upperCase(handler)),
|
|
157
|
+
queueName: upperCase(flowSchema.flowTag) + upperCase(flowStepName) + upperCase(handler),
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
const yamlFlowStepRes = await yamlFlowStep(_izContext, data, appPath);
|
|
161
|
+
const handlerResult = await handlerFlowStep(_izContext, data, appPath);
|
|
162
|
+
allCreateSourceParams.push(yamlFlowStepRes, handlerResult);
|
|
163
|
+
|
|
164
|
+
if (handler === HANDLER.hdrSqs || handler === HANDLER.hdrDsq) {
|
|
165
|
+
const sqsResult = await sqsFlowStep(_izContext, data, appPath);
|
|
166
|
+
allCreateSourceParams.push(sqsResult);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const snsOutResult = await snsOut(_izContext, data, appPath);
|
|
170
|
+
allCreateSourceParams.push(snsOutResult);
|
|
171
|
+
|
|
172
|
+
let mainResult;
|
|
173
|
+
if (flowStepConfig.hasOwnProperty("plugInHooks")) {
|
|
174
|
+
// for (const plugInHookFlow of flowStepConfig.plugInHooks) {
|
|
175
|
+
for (let i = 0; i < flowStepConfig.plugInHooks.length; i++) {
|
|
176
|
+
if (i === 0) { // create main function for first flowStep
|
|
177
|
+
const [objSchema] = await getLocalOrS3ObjectSchema(_izContext, flowStepConfig.plugInHooks[i].objType, path.join(appPath, './src/schemas'));
|
|
178
|
+
let targetPlugIn = null;
|
|
179
|
+
if (objSchema.hasOwnProperty('plugIns')) {
|
|
180
|
+
for (const plugInConfig of Object.values(objSchema.plugIns)) {
|
|
181
|
+
targetPlugIn = plugInConfig.plugInHooks.find(h => h.plugInHookTagType.plugInHookTag === flowStepConfig.plugInHooks[i].plugInHookTag);
|
|
182
|
+
if (targetPlugIn) {
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
if (targetPlugIn) {
|
|
188
|
+
let targetUrl = targetPlugIn.plugInHookTagType.targetUrl;
|
|
189
|
+
if (targetPlugIn.invocationType === 'sync') {
|
|
190
|
+
targetUrl += '/recievePlugInRequestSync'
|
|
191
|
+
}
|
|
192
|
+
mainResult = await mainFunctionFlowStep(
|
|
193
|
+
_izContext,
|
|
194
|
+
{
|
|
195
|
+
...data,
|
|
196
|
+
invokeType: targetPlugIn.invocationType, // Ensure this matches "sync" or "async"
|
|
197
|
+
havePlugIn: true,
|
|
198
|
+
targetUrl: targetUrl
|
|
199
|
+
},
|
|
200
|
+
appPath
|
|
201
|
+
);
|
|
202
|
+
} else {
|
|
203
|
+
mainResult = await mainFunctionFlowStep(_izContext, { ...data, havePlugIn: false }, appPath);
|
|
204
|
+
}
|
|
205
|
+
allCreateSourceParams.push(mainResult);
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
if (objSchema.hasOwnProperty('recievePlugInHookTag')) {
|
|
209
|
+
for (const recieveConfig of Object.values(objSchema.recievePlugInHookTag)) {
|
|
210
|
+
if (recieveConfig.hasOwnProperty('flowType')) {
|
|
211
|
+
data['recieveType'] = "async",
|
|
212
|
+
data['flowType'] = recieveConfig.flowType
|
|
213
|
+
} else {
|
|
214
|
+
data['recieveType'] = 'sync'
|
|
215
|
+
}
|
|
216
|
+
const yamlRecievePlugInResult = await yamlRecievePlugIn(_izContext, data, appPath);
|
|
217
|
+
const handlerRecievePlugInResult = await handlerRecievePlugIn(_izContext, data, appPath);
|
|
218
|
+
const mainFunctionRecievePlugInResult = await mainFunctionRecievePlugIn(_izContext, data, appPath);
|
|
219
|
+
// console.log("mainFunctionRecievePlugInResult", mainFunctionRecievePlugInResult)
|
|
220
|
+
allCreateSourceParams.push(...yamlRecievePlugInResult, ...handlerRecievePlugInResult, mainFunctionRecievePlugInResult);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
const uniqueSortedTargetFiles = Array.from(
|
|
231
|
+
new Set(
|
|
232
|
+
allCreateSourceParams
|
|
233
|
+
.filter(
|
|
234
|
+
item => item?.setting?.savePath && item?.setting?.saveFileName
|
|
235
|
+
)
|
|
236
|
+
.map(
|
|
237
|
+
item =>
|
|
238
|
+
`${item.setting.savePath.replace(/\/+$/, '')}/${item.setting.saveFileName}${item.setting.fileExtension || ''}`
|
|
239
|
+
)
|
|
240
|
+
)
|
|
241
|
+
).sort();
|
|
242
|
+
|
|
243
|
+
console.info(
|
|
244
|
+
`[plugIn] completed total=${allCreateSourceParams.length} uniqueFiles=${uniqueSortedTargetFiles.length} elapsedMs=${Date.now() - startAllMs}`
|
|
245
|
+
);
|
|
246
|
+
if (uniqueSortedTargetFiles.length > 0 && _izContext.logger?.debug)
|
|
247
|
+
console.log('[plugIn] targetFiles=', uniqueSortedTargetFiles);
|
|
248
|
+
|
|
249
|
+
return allCreateSourceParams;
|
|
250
|
+
} catch (error) {
|
|
251
|
+
console.error('[plugIn] error:', error);
|
|
252
|
+
return [];
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export default generatePlunIg;
|
|
@@ -49,67 +49,76 @@ function createSourceSystemText(
|
|
|
49
49
|
schemaPath
|
|
50
50
|
) {
|
|
51
51
|
const createSourceArray = [];
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
52
|
+
|
|
53
|
+
if (allObjectSchema.length > 0) {
|
|
54
|
+
for (const objectSchema of allObjectSchema) {
|
|
55
|
+
const fieldNames = [...Object.keys(objectSchema.fieldNames)];
|
|
56
|
+
if (objectSchema.hasOwnProperty("addOnDataStructure")) {
|
|
57
|
+
for (const addOn of objectSchema.addOnDataStructure) {
|
|
58
|
+
if (addOn.type === "versionedData") {
|
|
59
|
+
fieldNames.push(...Object.keys(addOn.fieldNames))
|
|
60
|
+
}
|
|
59
61
|
}
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
for (const fieldName of fieldNames) {
|
|
65
|
+
const objType = {
|
|
66
|
+
objectType: objectSchema.objectType,
|
|
67
|
+
serviceTag: getLocalConfig('iz_serviceTag')
|
|
68
|
+
};
|
|
69
|
+
const systemTextObjectSchemas = {
|
|
70
|
+
nameSpace: `${coreUtils.createObjTypeConcat(_izContext, objType)}_description`, // for each objectType
|
|
71
|
+
systemTextTag: `${fieldName}_${coreUtils.createObjTypeConcat(_izContext, objType)}` // for each fieldName
|
|
72
|
+
};
|
|
73
|
+
createSourceArray.push(systemTextObjectSchemas);
|
|
60
74
|
}
|
|
61
|
-
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
62
77
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
78
|
+
if (allFlowSchemas.length > 0) {
|
|
79
|
+
for (const flowSchema of allFlowSchemas) {
|
|
80
|
+
const flowType = {
|
|
81
|
+
flowTag: flowSchema.flowTag,
|
|
66
82
|
serviceTag: getLocalConfig('iz_serviceTag')
|
|
67
83
|
};
|
|
68
|
-
const
|
|
69
|
-
nameSpace: `${coreUtils.
|
|
70
|
-
systemTextTag:
|
|
84
|
+
const systemTextFlowSchemas = {
|
|
85
|
+
nameSpace: `${coreUtils.createFlowTypeConcat(_izContext, flowType)}`, // for each flowType
|
|
86
|
+
systemTextTag: `errors_${coreUtils.createFlowTypeConcat(_izContext, flowType)}`
|
|
71
87
|
};
|
|
72
|
-
createSourceArray.push(
|
|
88
|
+
createSourceArray.push(systemTextFlowSchemas);
|
|
73
89
|
}
|
|
74
90
|
}
|
|
75
91
|
|
|
76
|
-
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
systemTextTag: `errors_${coreUtils.createFlowTypeConcat(_izContext, flowType)}`
|
|
84
|
-
};
|
|
85
|
-
createSourceArray.push(systemTextFlowSchemas);
|
|
86
|
-
}
|
|
92
|
+
if (allRelSchema.length > 0) {
|
|
93
|
+
for (const relSchema of allRelSchema) {
|
|
94
|
+
const relTag = Object.keys(relSchema)[0]
|
|
95
|
+
const relType = {
|
|
96
|
+
serviceTag: getLocalConfig('iz_serviceTag'),
|
|
97
|
+
relationshipTag: relTag
|
|
98
|
+
};
|
|
87
99
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const systemTextRelSchemas = {
|
|
97
|
-
nameSpace: `${coreUtils.createRelTypeConcat(_izContext, relType)}_description`,
|
|
98
|
-
systemTextTag: `${fieldName}_${coreUtils.createRelTypeConcat(_izContext, relType)}`
|
|
100
|
+
if (relSchema[relTag].hasOwnProperty('fieldNames') && Object.keys(relSchema[relTag].fieldNames).length > 0) {
|
|
101
|
+
for (const fieldName of Object.keys(relSchema[relTag].fieldNames)) {
|
|
102
|
+
const systemTextRelSchemas = {
|
|
103
|
+
nameSpace: `${coreUtils.createRelTypeConcat(_izContext, relType)}_description`,
|
|
104
|
+
systemTextTag: `${fieldName}_${coreUtils.createRelTypeConcat(_izContext, relType)}`
|
|
105
|
+
}
|
|
106
|
+
createSourceArray.push(systemTextRelSchemas);
|
|
107
|
+
}
|
|
99
108
|
}
|
|
100
|
-
createSourceArray.push(systemTextRelSchemas);
|
|
101
109
|
}
|
|
102
110
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
|
|
111
|
+
|
|
112
|
+
if (notificationSchemas.length > 0) {
|
|
113
|
+
for (const notification of notificationSchemas) {
|
|
114
|
+
const notificationSystemText = {
|
|
115
|
+
nameSpace: `sysNotification_${notification.notificationGrouping}`,
|
|
116
|
+
systemTextTag: notification.notificationTag
|
|
117
|
+
}
|
|
118
|
+
createSourceArray.push(notificationSystemText)
|
|
108
119
|
}
|
|
109
|
-
createSourceArray.push(notificationSystemText)
|
|
110
120
|
}
|
|
111
|
-
|
|
112
|
-
// console.log("createSourceArray", createSourceArray)
|
|
121
|
+
|
|
113
122
|
return {
|
|
114
123
|
templatePath: templatePath,
|
|
115
124
|
templateData: { datas: createSourceArray },
|
package/src/generateCode.js
CHANGED
|
@@ -38,6 +38,8 @@ import generateTemplateDataOther from './generateCode/generateOther/generateCode
|
|
|
38
38
|
|
|
39
39
|
import generateTemplateDataRole from './generateCode/generateRole/generateCodeRole.js';
|
|
40
40
|
|
|
41
|
+
import generatePlugIn from './generateCode/generateFlowStepWithPlugIn/index.js';
|
|
42
|
+
|
|
41
43
|
const __filename = fileURLToPath(import.meta.url);
|
|
42
44
|
const __dirname = dirname(__filename);
|
|
43
45
|
|
|
@@ -97,37 +99,43 @@ async function generateCodeWithTemplate(
|
|
|
97
99
|
console.info('[INFO] [generateCode] STATUS=GENERATING| template data...');
|
|
98
100
|
_izContext.logger.info('[generateCode] generating template data...');
|
|
99
101
|
const genStartTime = Date.now();
|
|
100
|
-
const [
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
102
|
+
const [
|
|
103
|
+
flowSchemaResult,
|
|
104
|
+
schemaResult,
|
|
105
|
+
initialSetupResult,
|
|
106
|
+
otherResult,
|
|
107
|
+
generatePlugInResult
|
|
108
|
+
] = await Promise.all([
|
|
109
|
+
generateTemplateDataFromFlowSchema(
|
|
110
|
+
_izContext,
|
|
111
|
+
appPath,
|
|
112
|
+
allLocalFlowSchemas.records,
|
|
113
|
+
settings
|
|
114
|
+
),
|
|
115
|
+
generateTemplateDataFromSchema(
|
|
116
|
+
_izContext,
|
|
117
|
+
appPath,
|
|
118
|
+
allObjSchemas,
|
|
119
|
+
allLocalRelationshipSchemas,
|
|
120
|
+
allLocalFlowSchemas.records,
|
|
121
|
+
allLocalNotificationSystem,
|
|
122
|
+
settings
|
|
123
|
+
).catch(error => {
|
|
124
|
+
console.error('[generateCode] schemaResult error:', error);
|
|
125
|
+
_izContext.logger.error('[generateCode] schemaResult error:', error);
|
|
126
|
+
return [];
|
|
127
|
+
}),
|
|
128
|
+
generateTemplateDataInitialSetup(
|
|
129
|
+
_izContext,
|
|
130
|
+
appPath,
|
|
131
|
+
allObjSchemas.records,
|
|
132
|
+
allLocalRelationshipSchemas,
|
|
133
|
+
allLocalFlowSchemas.records,
|
|
134
|
+
settings
|
|
135
|
+
),
|
|
136
|
+
generateTemplateDataOther(_izContext, appPath),
|
|
137
|
+
generatePlugIn(_izContext, appPath, allObjSchemas.records, allLocalFlowSchemas.records)
|
|
138
|
+
]);
|
|
131
139
|
|
|
132
140
|
const genDuration = Date.now() - genStartTime;
|
|
133
141
|
const genStr = `flow=${flowSchemaResult.length} sch=${schemaResult.length} setup=${initialSetupResult.length} other=${otherResult.length}`;
|
|
@@ -139,7 +147,8 @@ async function generateCodeWithTemplate(
|
|
|
139
147
|
...flowSchemaResult,
|
|
140
148
|
...schemaResult,
|
|
141
149
|
...initialSetupResult,
|
|
142
|
-
...otherResult
|
|
150
|
+
...otherResult,
|
|
151
|
+
...generatePlugInResult
|
|
143
152
|
];
|
|
144
153
|
|
|
145
154
|
// ── 3. Generate role configs ─────────────────────────────────────────────
|
package/src/libs/Libs.js
CHANGED
|
@@ -15,11 +15,13 @@ You should have received a copy of the GNU Affero General Public License
|
|
|
15
15
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
import { serviceConfig } from '@izara_project/izara-core-library-service-schemas';
|
|
18
|
+
import { serviceConfig, getObjectSchema } from '@izara_project/izara-core-library-service-schemas';
|
|
19
19
|
import consts from './Consts.js';
|
|
20
20
|
const {
|
|
21
21
|
STORAGE_TYPES,
|
|
22
22
|
RESOURCE_CLASSES,
|
|
23
|
+
SQS_RESOURCE,
|
|
24
|
+
SNS_RESOURCE,
|
|
23
25
|
DYNAMO_RESOURCE,
|
|
24
26
|
S3_RESOURCE,
|
|
25
27
|
FIELD_NAME_TYPE
|
|
@@ -58,8 +60,8 @@ function resourceNames(resourceClass, resourceName) {
|
|
|
58
60
|
|
|
59
61
|
/**
|
|
60
62
|
*
|
|
61
|
-
* @param {
|
|
62
|
-
* @param {
|
|
63
|
+
* @param {object} action - key:resourceClass value:actionValue
|
|
64
|
+
* @param {array} resource
|
|
63
65
|
* @param {string} effect - optional default Allow
|
|
64
66
|
* @returns {{ effect, action, resource}}
|
|
65
67
|
*/
|
|
@@ -449,11 +451,13 @@ function tableRoleForFlowSchema(objectSchema) {
|
|
|
449
451
|
return resourcePermission;
|
|
450
452
|
}
|
|
451
453
|
|
|
452
|
-
|
|
453
|
-
`${item.setting.savePath.replace(/\/+$/, '')}/${item.setting.saveFileName}${item.setting.fileExtension || ''}`;
|
|
454
|
+
function toFilePath(item) {
|
|
455
|
+
return `${item.setting.savePath.replace(/\/+$/, '')}/${item.setting.saveFileName}${item.setting.fileExtension || ''}`;
|
|
454
456
|
|
|
455
|
-
|
|
456
|
-
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
function toUniqueFilePaths(items) {
|
|
460
|
+
return Array.from(
|
|
457
461
|
new Set(
|
|
458
462
|
items
|
|
459
463
|
.flat(5)
|
|
@@ -461,6 +465,96 @@ const toUniqueFilePaths = items =>
|
|
|
461
465
|
.map(toFilePath)
|
|
462
466
|
)
|
|
463
467
|
).sort();
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
function createSqsResource(queueNames) {
|
|
471
|
+
if (!Array.isArray(queueNames)) {
|
|
472
|
+
queueNames = [queueNames];
|
|
473
|
+
};
|
|
474
|
+
|
|
475
|
+
return createIamRole(
|
|
476
|
+
{
|
|
477
|
+
[RESOURCE_CLASSES.sqs]: Object.values(SQS_RESOURCE)
|
|
478
|
+
},
|
|
479
|
+
queueNames.map(queueName =>
|
|
480
|
+
resourceNames(RESOURCE_CLASSES.sqs, queueName))
|
|
481
|
+
);
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
function createSnsResource(topicNames) {
|
|
485
|
+
if (!Array.isArray(topicNames)) {
|
|
486
|
+
topicNames = [topicNames];
|
|
487
|
+
};
|
|
488
|
+
|
|
489
|
+
return createIamRole(
|
|
490
|
+
{
|
|
491
|
+
[RESOURCE_CLASSES.sns]: Object.values(SNS_RESOURCE)
|
|
492
|
+
},
|
|
493
|
+
topicNames.map(topicName =>
|
|
494
|
+
resourceNames(RESOURCE_CLASSES.sns, topicName))
|
|
495
|
+
);
|
|
496
|
+
}
|
|
497
|
+
async function getLocalOrS3ObjectSchema(_izContext, objType, schemasPath) {
|
|
498
|
+
console.log("objType, schemasPath", objType, schemasPath)
|
|
499
|
+
const iz_serviceTag = getLocalConfig('iz_serviceTag');
|
|
500
|
+
const iz_serviceSchemaBucketName = getLocalConfig('iz_serviceSchemaBucketName');
|
|
501
|
+
let objSchema;
|
|
502
|
+
let errorMessage;
|
|
503
|
+
if (objType.serviceTag === iz_serviceTag) {
|
|
504
|
+
objSchema = await getObjectSchema
|
|
505
|
+
.getLocalObjectSchemasWithHierarchy(
|
|
506
|
+
_izContext,
|
|
507
|
+
objType.objectType,
|
|
508
|
+
schemasPath
|
|
509
|
+
)
|
|
510
|
+
.then(res => {
|
|
511
|
+
return res.records[0];
|
|
512
|
+
});
|
|
513
|
+
|
|
514
|
+
if (!objSchema) {
|
|
515
|
+
errorMessage = 'local not exists';
|
|
516
|
+
}
|
|
517
|
+
} else {
|
|
518
|
+
objSchema = await getObjectSchema.getObjSchemaS3WithHierarchy(
|
|
519
|
+
_izContext,
|
|
520
|
+
objType,
|
|
521
|
+
iz_serviceSchemaBucketName
|
|
522
|
+
);
|
|
523
|
+
errorMessage = 's3 not exists';
|
|
524
|
+
}
|
|
525
|
+
return [objSchema, errorMessage];
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
async function getLocalOrS3FlowSchema(_izContext, flowType, schemasPath) {
|
|
529
|
+
const iz_serviceTag = getLocalConfig('iz_serviceTag');
|
|
530
|
+
const iz_serviceSchemaBucketName = getLocalConfig('iz_serviceSchemaBucketName');
|
|
531
|
+
|
|
532
|
+
let flowSchema;
|
|
533
|
+
let errorMessage;
|
|
534
|
+
if (flowType.serviceTag === iz_serviceTag) {
|
|
535
|
+
flowSchema = await getObjectSchema
|
|
536
|
+
.getLocalFlowSchemas(
|
|
537
|
+
_izContext,
|
|
538
|
+
flowType.flowTag,
|
|
539
|
+
schemasPath
|
|
540
|
+
)
|
|
541
|
+
.then(res => {
|
|
542
|
+
return res.records[0];
|
|
543
|
+
});
|
|
544
|
+
|
|
545
|
+
if (!flowSchema) {
|
|
546
|
+
errorMessage = 'local not exists';
|
|
547
|
+
}
|
|
548
|
+
} else {
|
|
549
|
+
flowSchema = await getObjectSchema.getFlowSchemaS3(
|
|
550
|
+
_izContext,
|
|
551
|
+
flowType,
|
|
552
|
+
iz_serviceSchemaBucketName
|
|
553
|
+
);
|
|
554
|
+
errorMessage = 's3 not exists';
|
|
555
|
+
}
|
|
556
|
+
return [flowSchema, errorMessage];
|
|
557
|
+
}
|
|
464
558
|
|
|
465
559
|
export default {
|
|
466
560
|
resourceNames,
|
|
@@ -478,5 +572,9 @@ export default {
|
|
|
478
572
|
getStorageResourceFromObjectSchemas,
|
|
479
573
|
getExternalTopicComponentFromAllObjectSchemas,
|
|
480
574
|
tableRoleForFlowSchema,
|
|
481
|
-
toUniqueFilePaths
|
|
575
|
+
toUniqueFilePaths,
|
|
576
|
+
getLocalOrS3ObjectSchema,
|
|
577
|
+
getLocalOrS3FlowSchema,
|
|
578
|
+
createSqsResource,
|
|
579
|
+
createSnsResource
|
|
482
580
|
};
|