@izara_project/izara-core-generate-service-code 1.0.32 → 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 +21 -12
- package/src/libs/Libs.js +111 -22
|
@@ -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
|
|
|
@@ -72,19 +74,23 @@ async function generateCodeWithTemplate(
|
|
|
72
74
|
// ── 1. Fetch all schemas ─────────────────────────────────────────────────
|
|
73
75
|
console.info('[INFO] [generateCode] STATUS=FETCHING | schemas...');
|
|
74
76
|
const fetchStartTime = Date.now();
|
|
75
|
-
const [
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
77
|
+
const [
|
|
78
|
+
allLocalFlowSchemas,
|
|
79
|
+
allObjSchemas,
|
|
80
|
+
allLocalRelationshipSchemas,
|
|
81
|
+
allLocalNotificationSystem
|
|
82
|
+
] = await Promise.all([
|
|
83
|
+
getObjectSchema.getAllLocalFlowSchemas(_izContext, schemasPath),
|
|
84
|
+
getObjectSchema.getAllLocalObjectSchemasWithHierarchy(
|
|
85
|
+
_izContext,
|
|
86
|
+
schemasPath
|
|
87
|
+
),
|
|
88
|
+
getObjectSchema.getAllLocalRelationshipSchema(_izContext, schemasPath),
|
|
89
|
+
getObjectSchema.getLocalNotificationSystemSchemas(_izContext, schemasPath)
|
|
90
|
+
]);
|
|
85
91
|
|
|
86
92
|
const fetchDuration = Date.now() - fetchStartTime;
|
|
87
|
-
const fetchStr = `flow=${allLocalFlowSchemas.records?.length ?? 0} obj=${allObjSchemas.records?.length ?? 0} rel=${allLocalRelationshipSchemas.
|
|
93
|
+
const fetchStr = `flow=${allLocalFlowSchemas.records?.length ?? 0} obj=${allObjSchemas.records?.length ?? 0} rel=${allLocalRelationshipSchemas.length ?? 0}`;
|
|
88
94
|
console.info(
|
|
89
95
|
`[INFO] [generateCode] STATUS=FETCHED | ${fetchStr.padEnd(40)} | elapsedMs=${fetchDuration}`
|
|
90
96
|
);
|
|
@@ -98,6 +104,7 @@ async function generateCodeWithTemplate(
|
|
|
98
104
|
schemaResult,
|
|
99
105
|
initialSetupResult,
|
|
100
106
|
otherResult,
|
|
107
|
+
generatePlugInResult
|
|
101
108
|
] = await Promise.all([
|
|
102
109
|
generateTemplateDataFromFlowSchema(
|
|
103
110
|
_izContext,
|
|
@@ -126,7 +133,8 @@ async function generateCodeWithTemplate(
|
|
|
126
133
|
allLocalFlowSchemas.records,
|
|
127
134
|
settings
|
|
128
135
|
),
|
|
129
|
-
generateTemplateDataOther(_izContext, appPath)
|
|
136
|
+
generateTemplateDataOther(_izContext, appPath),
|
|
137
|
+
generatePlugIn(_izContext, appPath, allObjSchemas.records, allLocalFlowSchemas.records)
|
|
130
138
|
]);
|
|
131
139
|
|
|
132
140
|
const genDuration = Date.now() - genStartTime;
|
|
@@ -140,6 +148,7 @@ async function generateCodeWithTemplate(
|
|
|
140
148
|
...schemaResult,
|
|
141
149
|
...initialSetupResult,
|
|
142
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
|
|
@@ -52,21 +54,21 @@ function resourceNames(resourceClass, resourceName) {
|
|
|
52
54
|
[RESOURCE_CLASSES.webSocket]:
|
|
53
55
|
'arn:aws:execute-api:${self:custom.iz_region}:${self:custom.iz_accountId}:${self:custom.iz_webSocketHostId}/${self:custom.iz_stage}/POST/@connections/{connectionId}',
|
|
54
56
|
[RESOURCE_CLASSES.s3]:
|
|
55
|
-
'arn:aws:s3:::${self:custom.iz_serviceSchemaBucketName}/' + resourceName
|
|
57
|
+
'arn:aws:s3:::${self:custom.iz_serviceSchemaBucketName}/' + resourceName
|
|
56
58
|
}[resourceClass];
|
|
57
59
|
}
|
|
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
|
*/
|
|
66
68
|
function createIamRole(action, resource = [], effect = 'Allow') {
|
|
67
69
|
if (!Array.isArray(resource)) {
|
|
68
70
|
resource = [resource];
|
|
69
|
-
}
|
|
71
|
+
}
|
|
70
72
|
|
|
71
73
|
if (Array.isArray(action)) {
|
|
72
74
|
const actionObj = {};
|
|
@@ -187,24 +189,15 @@ function defaultIamRolePerAction() {
|
|
|
187
189
|
]
|
|
188
190
|
},
|
|
189
191
|
[
|
|
190
|
-
resourceNames(
|
|
191
|
-
|
|
192
|
-
'${self:custom.iz_serviceSchemaBucketName}/perServiceSchemas/*'
|
|
193
|
-
),
|
|
194
|
-
resourceNames(
|
|
195
|
-
RESOURCE_CLASSES.s3,
|
|
196
|
-
'${self:custom.iz_serviceSchemaBucketName}/serviceConfig/GraphServerTags.json'
|
|
197
|
-
)
|
|
192
|
+
resourceNames(RESOURCE_CLASSES.s3, 'perServiceSchemas/*'),
|
|
193
|
+
resourceNames(RESOURCE_CLASSES.s3, 'serviceConfig/GraphServerTags.json')
|
|
198
194
|
]
|
|
199
195
|
)
|
|
200
196
|
);
|
|
201
197
|
|
|
202
198
|
defaultIamRole.push(
|
|
203
199
|
createIamRole({ [RESOURCE_CLASSES.s3]: [S3_RESOURCE.listBucket] }, [
|
|
204
|
-
resourceNames(
|
|
205
|
-
RESOURCE_CLASSES.s3,
|
|
206
|
-
'${self:custom.iz_serviceSchemaBucketName}'
|
|
207
|
-
)
|
|
200
|
+
resourceNames(RESOURCE_CLASSES.s3, '*')
|
|
208
201
|
])
|
|
209
202
|
);
|
|
210
203
|
|
|
@@ -458,11 +451,13 @@ function tableRoleForFlowSchema(objectSchema) {
|
|
|
458
451
|
return resourcePermission;
|
|
459
452
|
}
|
|
460
453
|
|
|
461
|
-
|
|
462
|
-
`${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 || ''}`;
|
|
463
456
|
|
|
464
|
-
|
|
465
|
-
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
function toUniqueFilePaths(items) {
|
|
460
|
+
return Array.from(
|
|
466
461
|
new Set(
|
|
467
462
|
items
|
|
468
463
|
.flat(5)
|
|
@@ -470,6 +465,96 @@ const toUniqueFilePaths = items =>
|
|
|
470
465
|
.map(toFilePath)
|
|
471
466
|
)
|
|
472
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
|
+
}
|
|
473
558
|
|
|
474
559
|
export default {
|
|
475
560
|
resourceNames,
|
|
@@ -487,5 +572,9 @@ export default {
|
|
|
487
572
|
getStorageResourceFromObjectSchemas,
|
|
488
573
|
getExternalTopicComponentFromAllObjectSchemas,
|
|
489
574
|
tableRoleForFlowSchema,
|
|
490
|
-
toUniqueFilePaths
|
|
575
|
+
toUniqueFilePaths,
|
|
576
|
+
getLocalOrS3ObjectSchema,
|
|
577
|
+
getLocalOrS3FlowSchema,
|
|
578
|
+
createSqsResource,
|
|
579
|
+
createSnsResource
|
|
491
580
|
};
|