@izara_project/izara-core-generate-service-code 1.0.61 → 1.0.62
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 +5 -6
- package/src/codeGenerators/app/initial_setup/InitialSetupGenerator.js +100 -150
- package/src/codeGenerators/app/initial_setup/templates/InitialSetup_LambdaRole.ejs +27 -20
- package/src/codeGenerators/app/sls_yaml/FunctionYamlGenerator.js +8 -17
- package/src/codeGenerators/app/sls_yaml/RoleNameConfigGenerator.js +13 -72
- package/src/codeGenerators/app/sls_yaml/_policy/PolicyEmitter.js +3 -2
- package/src/codeGenerators/app/sls_yaml/_policy/__tests__/PolicyEmitter.test.js +3 -3
- package/src/codeGenerators/app/sls_yaml/_policy/templates/ManagedPolicy_Yaml.ejs +2 -2
- package/src/codeGenerators/app/sls_yaml/templates/SharedResource_Yaml.ejs +1 -1
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/endpoint/FlowEndpoint_HdrWbs.ejs +2 -2
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/endpoint/FlowEndpoint_Main.ejs +8 -4
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/endpoint/FlowMain_Wbs.ejs +4 -4
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/s3/CreatePreSignUrl_Main.ejs +1 -1
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/s3/ProcessS3File_Main.ejs +1 -1
- package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/step/FlowEndpointComplete_Main.ejs +11 -12
- package/src/codeGenerators/app/src/generatedCode/Flow/_shared/events/BaseDsqHandler.js +4 -13
- package/src/codeGenerators/app/src/generatedCode/Flow/_shared/events/BaseSqsHandler.js +14 -15
- package/src/codeGenerators/app/src/generatedCode/Flow/_shared/events/lambdaSyncApi.js +4 -13
- package/src/codeGenerators/app/src/generatedCode/Flow/_shared/events/lambdaSyncInv.js +4 -13
- package/src/codeGenerators/app/src/generatedCode/Flow/_shared/events/ownTopic.js +16 -4
- package/src/codeGenerators/app/src/generatedCode/Flow/_shared/handlers/FlowHandler_HdrDsq.ejs +71 -63
- package/src/codeGenerators/app/src/generatedCode/Flow/_shared/handlers/FlowHandler_HdrSqs.ejs +54 -50
- package/src/codeGenerators/app/src/generatedCode/Flow/_shared/shared/flowEntryPointBase.js +7 -4
- package/src/codeGenerators/app/src/generatedCode/Flow/_shared/shared/flowMainFunctionBase.js +21 -29
- package/src/codeGenerators/app/src/generatedCode/Flow/_shared/shared/flowNaming.js +16 -0
- package/src/codeGenerators/app/src/generatedCode/Flow/_shared/shared/flowStepBase.js +9 -4
- package/src/codeGenerators/app/src/generatedCode/Flow/_shared/shared/flowStepNormalizer.js +21 -20
- package/src/codeGenerators/app/src/generatedCode/Flow/_shared/shared/flowValidator.js +1 -13
- package/src/codeGenerators/app/src/generatedCode/Flow/_shared/shared/propertyNormalizer.js +20 -0
- package/src/codeGenerators/app/src/generatedCode/Flow/_shared/shared/roleNameDetection.js +49 -0
- package/src/codeGenerators/resource/sls_yaml/DynamoDBGenerator.js +1 -10
- package/src/codeGenerators/resource/sls_yaml/FlowOutGenerator.js +1 -10
- package/src/codeGenerators/resource/sls_yaml/FlowResourceYamlGenerator.js +2 -11
- package/src/core/validate.js +9 -5
- package/src/generate.js +1 -1
- package/src/generateCode.js +21 -0
- package/src/schemaGenerators/app/src/schemas/FlowSchemas/FlowSchemaGenerator.js +0 -43
- package/test_generate.js +0 -7
- package/test_normalize.js +0 -17
package/src/codeGenerators/app/src/generatedCode/Flow/_shared/handlers/FlowHandler_HdrSqs.ejs
CHANGED
|
@@ -15,8 +15,8 @@ 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 { middlewareHandler as middleware } from
|
|
19
|
-
import { recordHandlerSharedLib } from
|
|
18
|
+
import { middlewareHandler as middleware } from '@izara_project/izara-middleware';
|
|
19
|
+
import { recordHandlerSharedLib } from '@izara_project/izara-core-library-record-handler';
|
|
20
20
|
import Logger from '@izara_project/izara-core-library-logger';
|
|
21
21
|
import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
|
|
22
22
|
import <%= functionName %> from './<%= mainFileName %>.js';
|
|
@@ -27,11 +27,9 @@ let perRecordsValidatorSchema = {
|
|
|
27
27
|
<% if (typeof startConfig !== 'undefined' && startConfig !== null && startConfig.properties && startConfig.properties.length > 0) { -%>
|
|
28
28
|
type: 'object',
|
|
29
29
|
properties: {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
},
|
|
34
|
-
required: [ <%- startConfig.properties.filter(p => p.required !== false).map(p => `'${p.propertyName}'`).join(', ') %> ]
|
|
30
|
+
<% startConfig.properties.forEach((prop, index) => { %> <%- prop.propertyName %>: { type: '<%- prop.type || 'string' %>' }<%= index < startConfig.properties.length - 1 ? ',' : '' %>
|
|
31
|
+
<% }) %> },
|
|
32
|
+
required: [<%- startConfig.properties.filter(p => p.required !== false).map(p => `'${p.propertyName}'`).join(', ') %>]
|
|
35
33
|
<% } -%>
|
|
36
34
|
//(</validatorSchema>)
|
|
37
35
|
};
|
|
@@ -40,18 +38,16 @@ let perRecordsValidatorSchema = {
|
|
|
40
38
|
let messageAttributeValidatorSchema = {
|
|
41
39
|
type: 'object',
|
|
42
40
|
properties: {
|
|
43
|
-
|
|
44
|
-
'<%- prop.propertyName %>': {
|
|
41
|
+
<% startConfig.messageAttributes.forEach((prop, index) => { %> '<%- prop.propertyName %>': {
|
|
45
42
|
type: 'object',
|
|
46
43
|
properties: {
|
|
47
44
|
Type: { type: 'string' },
|
|
48
45
|
Value: { type: '<%- prop.type || 'string' %>' }
|
|
49
46
|
},
|
|
50
47
|
required: ['Type', 'Value']
|
|
51
|
-
},
|
|
52
|
-
|
|
53
|
-
},
|
|
54
|
-
required: [ <%- startConfig.messageAttributes.filter(p => p.required !== false).map(p => `'${p.propertyName}'`).join(', ') %> ]
|
|
48
|
+
}<%= index < startConfig.messageAttributes.length - 1 ? ',' : '' %>
|
|
49
|
+
<% }) %> },
|
|
50
|
+
required: [<%- startConfig.messageAttributes.filter(p => p.required !== false).map(p => `'${p.propertyName}'`).join(', ') %>]
|
|
55
51
|
};
|
|
56
52
|
<% } else { -%>
|
|
57
53
|
let messageAttributeValidatorSchema = null;
|
|
@@ -59,57 +55,65 @@ let messageAttributeValidatorSchema = null;
|
|
|
59
55
|
middleware.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema());
|
|
60
56
|
|
|
61
57
|
export const main = middleware.wrap(async (event, context) => {
|
|
62
|
-
|
|
63
58
|
try {
|
|
64
|
-
|
|
65
59
|
let recordPromises = [];
|
|
66
60
|
|
|
67
61
|
// loop each record and send to mainFunction
|
|
68
|
-
await Promise.all(
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
62
|
+
await Promise.all(
|
|
63
|
+
event.Records.map(async record => {
|
|
64
|
+
// promise.all for map() function
|
|
65
|
+
|
|
66
|
+
let passOnProperties = [];
|
|
67
|
+
record._izContext.logger.debug('record ReceiveMsgOutHdrSqs', record);
|
|
68
|
+
|
|
69
|
+
//validate message (and MessageAttributes)
|
|
70
|
+
await recordHandlerSharedLib.validateRecord(
|
|
71
|
+
record, // one record will send to mainFunction
|
|
72
|
+
'<%= queueName %>', // queue name that need to retry or send to dlq
|
|
73
|
+
perRecordsValidatorSchema, // schema for record.Message
|
|
74
|
+
messageAttributeValidatorSchema
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
// add argument (to invoke lambda) to passOnProperties[]
|
|
78
|
+
passOnProperties.push(record.body.Message);
|
|
79
|
+
passOnProperties.push(
|
|
80
|
+
callingFlowSharedLib.addCallingFlowToPassOnProperties(
|
|
81
|
+
record.body.Message
|
|
82
|
+
)
|
|
83
|
+
);
|
|
84
|
+
//(<additionalParams>)
|
|
85
|
+
//(</additionalParams>)
|
|
86
|
+
record._izContext.logger.debug(
|
|
87
|
+
'passOnProperties in handler',
|
|
88
|
+
passOnProperties
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
// call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
|
|
92
|
+
let recordPromise = recordHandlerSharedLib.recordHandler(
|
|
93
|
+
record, // one record will send to mainFunction
|
|
94
|
+
<%= functionName %>, // mainFunction that need to invoke.
|
|
95
|
+
'<%= queueName %>', // queue name that need to retry or send to dlq
|
|
96
|
+
passOnProperties // all parameters that mainFunction needed.
|
|
97
|
+
);
|
|
98
|
+
record._izContext.logger.debug('after recordPromise in handler');
|
|
99
|
+
recordPromises.push(recordPromise); // push promise to recordPromises
|
|
100
|
+
})
|
|
101
|
+
);
|
|
98
102
|
|
|
99
103
|
Logger.debug('before Promise.all(recordPromises) in handler');
|
|
100
104
|
try {
|
|
101
105
|
// --- main await all promises
|
|
102
106
|
await Promise.all(recordPromises); // await all promises
|
|
103
107
|
|
|
104
|
-
return event.Records // return all for local testing
|
|
105
|
-
|
|
108
|
+
return event.Records; // return all for local testing
|
|
106
109
|
} catch {
|
|
107
|
-
Logger.debug(
|
|
110
|
+
Logger.debug(
|
|
111
|
+
'Promise.all(recordPromises) in handler threw error (at least one record did no resolve)'
|
|
112
|
+
);
|
|
108
113
|
}
|
|
109
114
|
Logger.debug('after Promise.all(recordPromises) in handler');
|
|
110
|
-
|
|
111
115
|
} catch (err) {
|
|
112
116
|
Logger.error('Unhandled Error, LambdaFunctionHdrSqs: ', err);
|
|
113
|
-
throw
|
|
117
|
+
throw err;
|
|
114
118
|
}
|
|
115
119
|
});
|
|
@@ -4,9 +4,9 @@ import { fileURLToPath } from 'url';
|
|
|
4
4
|
import ejs from 'ejs';
|
|
5
5
|
import { EVENT_HANDLERS } from '../events/registry.js';
|
|
6
6
|
import { STATUS_HANDLERS } from './registry.js';
|
|
7
|
-
import { getFlowOutputSubDir, isRbacFlow, isRelationshipFlow } from './flowClassifier.js';
|
|
7
|
+
import { getFlowOutputSubDir, isCrudFlow, isRbacFlow, isRelationshipFlow } from './flowClassifier.js';
|
|
8
8
|
import { normalizeEvents } from './eventTypes.js';
|
|
9
|
-
import { processMainFileName, upperFirst } from './flowNaming.js';
|
|
9
|
+
import { processMainFileName, ownTopicMainFileName, upperFirst } from './flowNaming.js';
|
|
10
10
|
import { getFlowsForGeneration, getGeneratedCodeConfigs } from './flowSelection.js';
|
|
11
11
|
|
|
12
12
|
const __filename = fileURLToPath(import.meta.url);
|
|
@@ -41,10 +41,13 @@ export async function generateFlowEntryPoint(allSchemas, options) {
|
|
|
41
41
|
const flowOutputDir = path.join(baseOutputDir, subDir, upperCaseFlowTag, 'source');
|
|
42
42
|
await fs.mkdir(flowOutputDir, { recursive: true });
|
|
43
43
|
|
|
44
|
-
// NOTE: Changed to Process${upperCaseFlowTag}_Main to match legacy.
|
|
45
|
-
const mainFileName = processMainFileName(flowTag);
|
|
46
44
|
// 2. Generate Handlers based on event array using Registry
|
|
47
45
|
const events = normalizeEvents(flow.event, ['ownTopic']);
|
|
46
|
+
|
|
47
|
+
const isOwnTopic = !isCrudFlow(flowTag) && !isRbacFlow(flowTag) && !isRelationshipFlow(flowTag) && events.includes('ownTopic');
|
|
48
|
+
const mainFileName = isOwnTopic
|
|
49
|
+
? ownTopicMainFileName(flowTag)
|
|
50
|
+
: processMainFileName(flowTag);
|
|
48
51
|
|
|
49
52
|
// Use invocationType from generatedCodeConfig if available
|
|
50
53
|
if (flow.generatedCodeConfig && flow.generatedCodeConfig.invocationType) {
|
package/src/codeGenerators/app/src/generatedCode/Flow/_shared/shared/flowMainFunctionBase.js
CHANGED
|
@@ -3,8 +3,9 @@ import fs from 'fs/promises';
|
|
|
3
3
|
import { fileURLToPath } from 'url';
|
|
4
4
|
import ejs from 'ejs';
|
|
5
5
|
import { getFlowOutputSubDir, isCrudFlow, isRbacFlow, isRelationshipFlow } from './flowClassifier.js';
|
|
6
|
-
import { processMainFileName, upperFirst } from './flowNaming.js';
|
|
6
|
+
import { processMainFileName, processFunctionName, ownTopicMainFileName, ownTopicFunctionName, ownTopicWebSocketMainFileName, ownTopicWebSocketFunctionName, upperFirst } from './flowNaming.js';
|
|
7
7
|
import { getFlowsForGeneration, getGeneratedCodeConfigs } from './flowSelection.js';
|
|
8
|
+
import { normalizePropertyType } from './propertyNormalizer.js';
|
|
8
9
|
|
|
9
10
|
const __filename = fileURLToPath(import.meta.url);
|
|
10
11
|
const __dirname = path.dirname(__filename);
|
|
@@ -41,11 +42,13 @@ export async function generateFlowMainFunction(allSchemas, options) {
|
|
|
41
42
|
const flowOutputDir = path.join(baseOutputDir, subDir, upperCaseFlowTag, 'source');
|
|
42
43
|
await fs.mkdir(flowOutputDir, { recursive: true });
|
|
43
44
|
|
|
44
|
-
// For ownTopic flows the SNS-publish file is <FlowTag>_Main.js; others stay Process<FlowTag>_Main.js
|
|
45
45
|
const isOwnTopic = !isCrud && flow.event && flow.event.includes('ownTopic');
|
|
46
46
|
const mainFileName = isOwnTopic
|
|
47
|
-
?
|
|
47
|
+
? ownTopicMainFileName(flowTag)
|
|
48
48
|
: processMainFileName(flowTag);
|
|
49
|
+
const functionName = isOwnTopic
|
|
50
|
+
? ownTopicFunctionName(flowTag)
|
|
51
|
+
: processFunctionName(flowTag);
|
|
49
52
|
const topicArn = `${upperCaseFlowTag}_In`;
|
|
50
53
|
|
|
51
54
|
const generateCode = getGeneratedCodeConfigs(flows, flowTag, { includeFlowTag: true });
|
|
@@ -55,9 +58,6 @@ export async function generateFlowMainFunction(allSchemas, options) {
|
|
|
55
58
|
templateName = `${flowTag}Endpoint_Main.ejs`;
|
|
56
59
|
} else if (String(flowTag || '').toLowerCase().endsWith('rbacflow')) {
|
|
57
60
|
templateName = 'FlowRbac_Main.ejs';
|
|
58
|
-
} else if (isOwnTopic) {
|
|
59
|
-
// Non-CRUD flow with ownTopic: WebSocket entry that fetches flowSchema and publishes to SNS In topic
|
|
60
|
-
templateName = 'FlowMain_Wbs.ejs';
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
// crud templates live under FlowObjects (the only output child that uses them);
|
|
@@ -75,27 +75,15 @@ export async function generateFlowMainFunction(allSchemas, options) {
|
|
|
75
75
|
'utf-8'
|
|
76
76
|
);
|
|
77
77
|
|
|
78
|
-
const startStep = flow.flowSteps && flow.flowSteps.
|
|
79
|
-
s => s.stepName === 'start'
|
|
80
|
-
);
|
|
78
|
+
const startStep = flow.flowSteps && flow.flowSteps.length > 0 ? flow.flowSteps[0] : null;
|
|
81
79
|
let startConfig = startStep ? { ...startStep } : null;
|
|
82
80
|
|
|
83
81
|
if (startConfig) {
|
|
84
82
|
if (startConfig.properties && Array.isArray(startConfig.properties)) {
|
|
85
|
-
startConfig.properties = startConfig.properties.map(p =>
|
|
86
|
-
if (typeof p === 'string') {
|
|
87
|
-
return (flow.stepProperties && flow.stepProperties[p]) ? flow.stepProperties[p] : { propertyName: p, type: 'string' };
|
|
88
|
-
}
|
|
89
|
-
return p;
|
|
90
|
-
});
|
|
83
|
+
startConfig.properties = startConfig.properties.map(p => normalizePropertyType(p, flow.stepProperties));
|
|
91
84
|
}
|
|
92
85
|
if (startConfig.messageAttributes && Array.isArray(startConfig.messageAttributes)) {
|
|
93
|
-
startConfig.messageAttributes = startConfig.messageAttributes.map(p =>
|
|
94
|
-
if (typeof p === 'string') {
|
|
95
|
-
return (flow.stepMessageAttributes && flow.stepMessageAttributes[p]) ? flow.stepMessageAttributes[p] : { propertyName: p, type: 'string' };
|
|
96
|
-
}
|
|
97
|
-
return p;
|
|
98
|
-
});
|
|
86
|
+
startConfig.messageAttributes = startConfig.messageAttributes.map(p => normalizePropertyType(p, flow.stepMessageAttributes));
|
|
99
87
|
}
|
|
100
88
|
}
|
|
101
89
|
|
|
@@ -119,7 +107,8 @@ export async function generateFlowMainFunction(allSchemas, options) {
|
|
|
119
107
|
generateCode: generateCode,
|
|
120
108
|
flow: flow,
|
|
121
109
|
startConfig: startConfig,
|
|
122
|
-
tableName: tableName
|
|
110
|
+
tableName: tableName,
|
|
111
|
+
functionName: functionName
|
|
123
112
|
});
|
|
124
113
|
await fs.writeFile(
|
|
125
114
|
path.join(flowOutputDir, `${mainFileName}.js`),
|
|
@@ -127,25 +116,28 @@ export async function generateFlowMainFunction(allSchemas, options) {
|
|
|
127
116
|
'utf-8'
|
|
128
117
|
);
|
|
129
118
|
|
|
130
|
-
// For ownTopic flows:
|
|
119
|
+
// For ownTopic flows: generate WebSocket main that publishes to SNS In topic
|
|
131
120
|
if (isOwnTopic) {
|
|
132
|
-
const
|
|
133
|
-
path.join(__dirname, '..', '..', 'FlowSchemas', 'templates', 'endpoint', '
|
|
121
|
+
const wbsMainTemplateStr = await fs.readFile(
|
|
122
|
+
path.join(__dirname, '..', '..', 'FlowSchemas', 'templates', 'endpoint', 'FlowMain_Wbs.ejs'),
|
|
134
123
|
'utf-8'
|
|
135
124
|
);
|
|
136
|
-
const
|
|
125
|
+
const wbsMainContent = ejs.render(wbsMainTemplateStr, {
|
|
137
126
|
flowTag: flowTag,
|
|
138
127
|
upperCaseFlowTag: upperCaseFlowTag,
|
|
128
|
+
topicArn: topicArn,
|
|
139
129
|
generateCode: generateCode,
|
|
140
130
|
flow: flow,
|
|
141
131
|
startConfig: startConfig,
|
|
142
|
-
tableName: tableName
|
|
132
|
+
tableName: tableName,
|
|
133
|
+
functionName: ownTopicWebSocketFunctionName(flowTag)
|
|
143
134
|
});
|
|
144
135
|
await fs.writeFile(
|
|
145
|
-
path.join(flowOutputDir, `${
|
|
146
|
-
|
|
136
|
+
path.join(flowOutputDir, `${ownTopicWebSocketMainFileName(flowTag)}.js`),
|
|
137
|
+
wbsMainContent,
|
|
147
138
|
'utf-8'
|
|
148
139
|
);
|
|
140
|
+
generatedCount++;
|
|
149
141
|
}
|
|
150
142
|
|
|
151
143
|
// 2. Generate BeforeLogical Main Logic File if needed (CRUD flows only)
|
|
@@ -16,6 +16,22 @@ export function processFunctionName(flowTag) {
|
|
|
16
16
|
return `Process${upperFirst(flowTag)}`;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
export function ownTopicMainFileName(flowTag) {
|
|
20
|
+
return `${upperFirst(flowTag)}_Main`;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function ownTopicFunctionName(flowTag) {
|
|
24
|
+
return `${upperFirst(flowTag)}_Main`;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function ownTopicWebSocketMainFileName(flowTag) {
|
|
28
|
+
return `${upperFirst(flowTag)}_WbsMain`;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function ownTopicWebSocketFunctionName(flowTag) {
|
|
32
|
+
return `${upperFirst(flowTag)}_WbsMain`;
|
|
33
|
+
}
|
|
34
|
+
|
|
19
35
|
export function flowSourceLocation(subDir, flowTag) {
|
|
20
36
|
return `src/generatedCode/${subDir}/${upperFirst(flowTag)}/source/`;
|
|
21
37
|
}
|
|
@@ -2,7 +2,7 @@ import path from 'path';
|
|
|
2
2
|
import fs from 'fs/promises';
|
|
3
3
|
import { fileURLToPath } from 'url';
|
|
4
4
|
import ejs from 'ejs';
|
|
5
|
-
import { getFlowOutputSubDir, isRbacFlow, isRelationshipFlow } from './flowClassifier.js';
|
|
5
|
+
import { getFlowOutputSubDir, isRbacFlow, isRelationshipFlow, isCrudFlow } from './flowClassifier.js';
|
|
6
6
|
import { getStepEventHandlerConfig, normalizeEvents } from './eventTypes.js';
|
|
7
7
|
import { normalizeFlowSteps } from './flowStepNormalizer.js';
|
|
8
8
|
import { getFlowsForGeneration } from './flowSelection.js';
|
|
@@ -52,9 +52,14 @@ export async function generateFlowSteps(allSchemas, options) {
|
|
|
52
52
|
|
|
53
53
|
let createdDir = false;
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
const normalizedSteps = normalizeFlowSteps(flow.flowSteps);
|
|
56
|
+
for (let index = 0; index < normalizedSteps.length; index++) {
|
|
57
|
+
const stepConfig = normalizedSteps[index];
|
|
56
58
|
const stepName = stepConfig.stepName;
|
|
57
|
-
|
|
59
|
+
|
|
60
|
+
// Skip the first step (which is the entry point, handled by flowMainFunctionBase)
|
|
61
|
+
// Also skip traditional skipped steps by name for backward compatibility
|
|
62
|
+
if (index === 0 || ['in', 'start', 'out', 'beforelogical'].includes(stepName?.toLowerCase())) continue;
|
|
58
63
|
|
|
59
64
|
if (!createdDir) {
|
|
60
65
|
await fs.mkdir(flowOutputDir, { recursive: true });
|
|
@@ -79,7 +84,7 @@ export async function generateFlowSteps(allSchemas, options) {
|
|
|
79
84
|
functionName: `${flowTag}${stepName}`,
|
|
80
85
|
};
|
|
81
86
|
|
|
82
|
-
const isCompleteStep = stepName === 'Complete';
|
|
87
|
+
const isCompleteStep = stepName === 'Complete' && isCrudFlow(flowTag);
|
|
83
88
|
// Base Step Generation
|
|
84
89
|
if (isCompleteStep) {
|
|
85
90
|
templateToUse = templates.complete;
|
|
@@ -40,35 +40,36 @@ export function normalizeUnifiedFlows(rawFlows) {
|
|
|
40
40
|
// Ensure flowSteps is always an Array for the rest of the generation process
|
|
41
41
|
flow.flowSteps = normalizedSteps;
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
// ponytail: root-level event is standard, flowStep[0] has no event.
|
|
45
44
|
if (flow.event) {
|
|
46
|
-
|
|
45
|
+
const firstStep = flow.flowSteps[0];
|
|
46
|
+
const needsStartStep = !firstStep || firstStep.event;
|
|
47
|
+
|
|
48
|
+
if (needsStartStep) {
|
|
47
49
|
flow.flowSteps.unshift({
|
|
48
50
|
stepName: 'Start',
|
|
49
51
|
properties: flow.properties || [],
|
|
50
52
|
messageAttributes: flow.messageAttributes || []
|
|
51
53
|
});
|
|
52
54
|
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if (
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
stepName: '
|
|
66
|
-
|
|
67
|
-
messageAttributes: firstStep.messageAttributes || []
|
|
68
|
-
});
|
|
55
|
+
}
|
|
56
|
+
// Validate flowStep events
|
|
57
|
+
flow.flowSteps.forEach((step, index) => {
|
|
58
|
+
if (index === 0) {
|
|
59
|
+
if (step.event) {
|
|
60
|
+
throw new Error(`[Schema Error] Flow '${flow.flowTag || 'Unknown'}' -> stepName '${step.stepName}' (Index 0) must not have an 'event'. Set it at the flow root instead.`);
|
|
61
|
+
}
|
|
62
|
+
} else {
|
|
63
|
+
if (step.event) {
|
|
64
|
+
const validStepEvents = ['extTopic', 'lambdaSyncInv', 'dsq'];
|
|
65
|
+
const invalidEvents = step.event.filter(e => !validStepEvents.includes(e));
|
|
66
|
+
if (invalidEvents.length > 0) {
|
|
67
|
+
throw new Error(`[Schema Error] Flow '${flow.flowTag || 'Unknown'}' -> stepName '${step.stepName}' has invalid event: ${invalidEvents.join(', ')}. Allowed: ${validStepEvents.join(', ')}`);
|
|
68
|
+
}
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
|
-
}
|
|
71
|
+
});
|
|
72
|
+
|
|
72
73
|
return flow;
|
|
73
74
|
});
|
|
74
75
|
}
|
|
@@ -85,7 +85,6 @@ export function validateFlowsForGeneration(flows) {
|
|
|
85
85
|
const flowSteps = Array.isArray(flow.flowSteps) ? flow.flowSteps : [];
|
|
86
86
|
const seenStepNames = new Set();
|
|
87
87
|
let anyStepHasPlugInHooks = false;
|
|
88
|
-
let startStepCount = 0;
|
|
89
88
|
|
|
90
89
|
for (const step of flowSteps) {
|
|
91
90
|
const stepName = step?.stepName;
|
|
@@ -99,13 +98,6 @@ export function validateFlowsForGeneration(flows) {
|
|
|
99
98
|
}
|
|
100
99
|
seenStepNames.add(stepName);
|
|
101
100
|
|
|
102
|
-
if (stepName === 'In') {
|
|
103
|
-
errors.push(`Flow '${flowTag}' uses legacy stepName 'In'. Use 'start'.`);
|
|
104
|
-
}
|
|
105
|
-
if (stepName === 'start') {
|
|
106
|
-
startStepCount += 1;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
101
|
if (step.plugInHooks && step.plugInHooks.length > 0) {
|
|
110
102
|
anyStepHasPlugInHooks = true;
|
|
111
103
|
}
|
|
@@ -120,11 +112,7 @@ export function validateFlowsForGeneration(flows) {
|
|
|
120
112
|
validateNamedRefs(flowTag, stepName, step.messageAttributes, flow.stepMessageAttributes, 'messageAttributes', errors);
|
|
121
113
|
}
|
|
122
114
|
|
|
123
|
-
|
|
124
|
-
errors.push(`Flow '${flowTag}' has multiple 'start' steps. Only one is allowed.`);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// ponytail: relaxed anyStepHasPlugInHooks && startStepCount === 0 requirement
|
|
115
|
+
// ponytail: relaxed anyStepHasPlugInHooks requirement
|
|
128
116
|
// since unified entry points (step 0) can now handle plugins directly without start.
|
|
129
117
|
|
|
130
118
|
if (anyStepHasPlugInHooks) {
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const TYPE_MAP = {
|
|
2
|
+
string: 'string', number: 'number', integer: 'number',
|
|
3
|
+
currency: 'string', currencyValue: 'number', numeric: 'number',
|
|
4
|
+
float: 'number', special: 'string', object: 'object',
|
|
5
|
+
boolean: 'boolean', array: 'array', arrayMixed: 'array',
|
|
6
|
+
arrayObject: 'array', arrayNumeric: 'array', arrayString: 'array',
|
|
7
|
+
timestamp: 'number'
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export function normalizePropertyType(p, lookupSource) {
|
|
11
|
+
let prop = typeof p === 'string'
|
|
12
|
+
? ((lookupSource && lookupSource[p]) ? lookupSource[p] : { propertyName: p, type: 'string' })
|
|
13
|
+
: p;
|
|
14
|
+
|
|
15
|
+
if (prop && prop.type) {
|
|
16
|
+
prop = { ...prop, type: TYPE_MAP[prop.type] || prop.type };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return prop;
|
|
20
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { getFlowsForGeneration } from './flowSelection.js';
|
|
2
|
+
import { isCrudFlow, isRbacFlow, isRelationshipFlow } from './flowClassifier.js';
|
|
3
|
+
|
|
4
|
+
export const FLOW_OBJECTS_ROLE = 'FlowObjectsRole';
|
|
5
|
+
export const FLOW_RBAC_ROLE = 'FlowRbacRole';
|
|
6
|
+
export const FLOW_RELATIONSHIP_ROLE = 'FlowRelationshipRole';
|
|
7
|
+
export const WEB_SOCKET_MAIN_ROLE = 'WebSocketMainRole';
|
|
8
|
+
export const PROC_FIND_DATA_ROLE = 'ProcFindDataRole';
|
|
9
|
+
|
|
10
|
+
function upperCase(str) {
|
|
11
|
+
if (!str) return str;
|
|
12
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function isCustomRbacFlow(flowTag) {
|
|
16
|
+
return String(flowTag || '').toLowerCase().endsWith('rbacflow');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function detectRoleNames(allSchemas) {
|
|
20
|
+
const flows = getFlowsForGeneration(allSchemas);
|
|
21
|
+
const roleNames = new Set([PROC_FIND_DATA_ROLE]);
|
|
22
|
+
|
|
23
|
+
for (const flow of flows) {
|
|
24
|
+
if (!flow.flowTag) continue;
|
|
25
|
+
|
|
26
|
+
if (isCrudFlow(flow.flowTag)) {
|
|
27
|
+
roleNames.add(FLOW_OBJECTS_ROLE);
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (isRbacFlow(flow.flowTag) || isCustomRbacFlow(flow.flowTag)) {
|
|
32
|
+
roleNames.add(FLOW_RBAC_ROLE);
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (isRelationshipFlow(flow.flowTag)) {
|
|
37
|
+
roleNames.add(FLOW_RELATIONSHIP_ROLE);
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if ((flow.event || []).includes('ownTopic')) {
|
|
42
|
+
roleNames.add(WEB_SOCKET_MAIN_ROLE);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
roleNames.add(`${upperCase(flow.flowTag)}Role`);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return { flows, roleNames };
|
|
49
|
+
}
|
|
@@ -6,15 +6,6 @@ import ejs from 'ejs';
|
|
|
6
6
|
const __filename = fileURLToPath(import.meta.url);
|
|
7
7
|
const __dirname = path.dirname(__filename);
|
|
8
8
|
|
|
9
|
-
async function appendToFile(filePath, content) {
|
|
10
|
-
try {
|
|
11
|
-
await fs.mkdir(path.dirname(filePath), { recursive: true });
|
|
12
|
-
await fs.appendFile(filePath, content + '\n', 'utf-8');
|
|
13
|
-
} catch (error) {
|
|
14
|
-
console.error(`[Error] Failed to append to file: ${filePath}`, error);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
9
|
export async function generateDynamoDBTables(allSchemas, options) {
|
|
19
10
|
console.log(' [DynamoDBGenerator] Generating DynamoDB Tables...');
|
|
20
11
|
|
|
@@ -88,7 +79,7 @@ export async function generateDynamoDBTables(allSchemas, options) {
|
|
|
88
79
|
pk: keys.pk,
|
|
89
80
|
sk: keys.sk
|
|
90
81
|
});
|
|
91
|
-
|
|
82
|
+
await fs.appendFile(yamlOutputPath, `${yamlContent}\n`, 'utf-8');
|
|
92
83
|
generatedCount++;
|
|
93
84
|
}
|
|
94
85
|
|
|
@@ -8,15 +8,6 @@ import { getFlowsForGeneration } from '../../app/src/generatedCode/Flow/_shared/
|
|
|
8
8
|
const __filename = fileURLToPath(import.meta.url);
|
|
9
9
|
const __dirname = path.dirname(__filename);
|
|
10
10
|
|
|
11
|
-
async function appendToFile(filePath, content) {
|
|
12
|
-
try {
|
|
13
|
-
await fs.mkdir(path.dirname(filePath), { recursive: true });
|
|
14
|
-
await fs.appendFile(filePath, `${content}\n`, 'utf-8');
|
|
15
|
-
} catch (error) {
|
|
16
|
-
console.error(`[Error] Failed to append file: ${filePath}`, error);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
11
|
export async function generateFlowOut(allSchemas, options) {
|
|
21
12
|
console.log(' [FlowOutGenerator] Generating Flow Out nodes (SNS Topics)...');
|
|
22
13
|
|
|
@@ -37,7 +28,7 @@ export async function generateFlowOut(allSchemas, options) {
|
|
|
37
28
|
|
|
38
29
|
generatedTopics.add(topicName);
|
|
39
30
|
const yamlContent = ejs.render(yamlTpl, { topicName });
|
|
40
|
-
await
|
|
31
|
+
await fs.appendFile(yamlOutputPath, `${yamlContent}\n`, 'utf-8');
|
|
41
32
|
generatedCount++;
|
|
42
33
|
}
|
|
43
34
|
|
|
@@ -8,15 +8,6 @@ import { getFlowsForGeneration } from '../../app/src/generatedCode/Flow/_shared/
|
|
|
8
8
|
const __filename = fileURLToPath(import.meta.url);
|
|
9
9
|
const __dirname = path.dirname(__filename);
|
|
10
10
|
|
|
11
|
-
async function appendToFile(filePath, content) {
|
|
12
|
-
try {
|
|
13
|
-
await fs.mkdir(path.dirname(filePath), { recursive: true });
|
|
14
|
-
await fs.appendFile(filePath, `${content}\n`, 'utf-8');
|
|
15
|
-
} catch (error) {
|
|
16
|
-
console.error(`[Error] Failed to append file: ${filePath}`, error);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
11
|
export async function generateFlowResourceYaml(allSchemas, options) {
|
|
21
12
|
console.log(' [FlowResourceYamlGenerator] Generating SQS/SNS YAML resources for flows...');
|
|
22
13
|
|
|
@@ -42,7 +33,7 @@ export async function generateFlowResourceYaml(allSchemas, options) {
|
|
|
42
33
|
|
|
43
34
|
generatedResources.add(resourceKey);
|
|
44
35
|
const yamlContent = ejs.render(template, templateData);
|
|
45
|
-
await
|
|
36
|
+
await fs.appendFile(yamlOutputPath, `${yamlContent}\n`, 'utf-8');
|
|
46
37
|
generatedCount++;
|
|
47
38
|
}
|
|
48
39
|
|
|
@@ -79,7 +70,7 @@ export async function generateFlowResourceYaml(allSchemas, options) {
|
|
|
79
70
|
if (Array.isArray(flow.flowSteps)) {
|
|
80
71
|
for (const stepConfig of flow.flowSteps) {
|
|
81
72
|
const stepName = stepConfig.stepName;
|
|
82
|
-
if (stepName === 'start') continue;
|
|
73
|
+
if (stepName?.toLowerCase() === 'start') continue;
|
|
83
74
|
|
|
84
75
|
const events = stepConfig.event || ['extTopic'];
|
|
85
76
|
for (const ev of events) {
|
package/src/core/validate.js
CHANGED
|
@@ -20,17 +20,21 @@ export async function validateSchemas(rootPath) {
|
|
|
20
20
|
// 1. Read config for bucket name and service tag
|
|
21
21
|
let configStr = '';
|
|
22
22
|
let iz_serviceTag = '';
|
|
23
|
+
let iz_serviceName = '';
|
|
23
24
|
let iz_serviceSchemaBucketName = '';
|
|
24
25
|
try {
|
|
25
26
|
configStr = await fs.readFile(serviceConfigPath, 'utf8');
|
|
26
27
|
const config = yaml.parse(configStr);
|
|
27
28
|
iz_serviceTag = config?.main_config?.iz_serviceTag;
|
|
29
|
+
iz_serviceName = config?.main_config?.iz_serviceName || iz_serviceTag;
|
|
28
30
|
iz_serviceSchemaBucketName = config?.main_config?.iz_serviceSchemaBucketName || 'unknown-bucket';
|
|
29
31
|
|
|
30
|
-
if (!
|
|
31
|
-
validateStatus.validateErrors.push('Missing iz_serviceTag in serverless.config.yml. This is a critical configuration field.');
|
|
32
|
-
} else if (!/^[a-zA-Z0-9]+$/.test(
|
|
33
|
-
validateStatus.validateErrors.push(`
|
|
32
|
+
if (!iz_serviceName) {
|
|
33
|
+
validateStatus.validateErrors.push('Missing iz_serviceName or iz_serviceTag in serverless.config.yml. This is a critical configuration field.');
|
|
34
|
+
} else if (!/^[a-zA-Z0-9]+$/.test(iz_serviceName)) {
|
|
35
|
+
validateStatus.validateErrors.push(`Service Name '${iz_serviceName}' must contain only alphanumeric characters ([a-zA-Z0-9]).`);
|
|
36
|
+
} else {
|
|
37
|
+
console.log(` [Validator] Validating with serviceName: '${iz_serviceName}'`);
|
|
34
38
|
}
|
|
35
39
|
} catch (e) {
|
|
36
40
|
validateStatus.validateErrors.push(`Could not read or parse serverless.config.yml at ${serviceConfigPath}: ${e.message}`);
|
|
@@ -124,7 +128,7 @@ export async function validateSchemas(rootPath) {
|
|
|
124
128
|
if (flow.objType && flow.objType.objectType) {
|
|
125
129
|
const targetObj = objectSchemasMap[flow.objType.objectType];
|
|
126
130
|
if (targetObj) {
|
|
127
|
-
const expectedPrefix =
|
|
131
|
+
const expectedPrefix = `${iz_serviceName}_${flow.flowTag}`; // Prefix logic based on service name
|
|
128
132
|
const isMissingFields = !targetObj.fieldNames || !targetObj.fieldNames[`${expectedPrefix}Status`];
|
|
129
133
|
|
|
130
134
|
if (isMissingFields) {
|
package/src/generate.js
CHANGED