@izara_project/izara-core-generate-service-code 1.0.59 → 1.0.61

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.
Files changed (36) hide show
  1. package/package.json +7 -3
  2. package/src/codeGenerators/app/initial_setup/InitialSetupGenerator.js +7 -7
  3. package/src/codeGenerators/app/sls_yaml/FunctionYamlGenerator.js +4 -5
  4. package/src/codeGenerators/app/src/generatedCode/Flow/FlowObjects/EndpointsGenerator.js +3 -2
  5. package/src/codeGenerators/app/src/generatedCode/Flow/FlowRbac/RbacFlowGenerator.js +4 -0
  6. package/src/codeGenerators/app/src/generatedCode/Flow/FlowRelationships/RelationshipFlowGenerator.js +2 -1
  7. package/src/codeGenerators/app/src/generatedCode/Flow/FlowSchemas/templates/endpoint/FlowEndpoint_Main.ejs +33 -0
  8. package/src/codeGenerators/app/src/generatedCode/Flow/_shared/events/BaseDsqHandler.js +64 -0
  9. package/src/codeGenerators/app/src/generatedCode/Flow/_shared/events/BaseSqsHandler.js +9 -9
  10. package/src/codeGenerators/app/src/generatedCode/Flow/_shared/events/__tests__/BaseDsqHandler.test.js +93 -0
  11. package/src/codeGenerators/app/src/generatedCode/Flow/_shared/events/dsq.js +5 -0
  12. package/src/codeGenerators/app/src/generatedCode/Flow/_shared/events/lambdaSyncApi.js +9 -9
  13. package/src/codeGenerators/app/src/generatedCode/Flow/_shared/events/lambdaSyncInv.js +9 -9
  14. package/src/codeGenerators/app/src/generatedCode/Flow/_shared/events/registry.js +3 -1
  15. package/src/codeGenerators/app/src/generatedCode/Flow/_shared/handlers/FlowHandler_HdrApi.ejs +3 -3
  16. package/src/codeGenerators/app/src/generatedCode/Flow/_shared/handlers/FlowHandler_HdrDsq.ejs +129 -0
  17. package/src/codeGenerators/app/src/generatedCode/Flow/_shared/handlers/FlowHandler_HdrInv.ejs +3 -3
  18. package/src/codeGenerators/app/src/generatedCode/Flow/_shared/handlers/FlowHandler_HdrSqs.ejs +15 -8
  19. package/src/codeGenerators/app/src/generatedCode/Flow/_shared/shared/eventTypes.js +2 -2
  20. package/src/codeGenerators/app/src/generatedCode/Flow/_shared/shared/flowEntryPointBase.js +1 -0
  21. package/src/codeGenerators/app/src/generatedCode/Flow/_shared/shared/flowMainFunctionBase.js +26 -11
  22. package/src/codeGenerators/app/src/generatedCode/Flow/_shared/shared/flowSelection.js +0 -1
  23. package/src/codeGenerators/app/src/generatedCode/Flow/_shared/shared/flowStepBase.js +3 -2
  24. package/src/codeGenerators/app/src/generatedCode/Flow/_shared/shared/flowStepNormalizer.js +47 -1
  25. package/src/codeGenerators/app/src/generatedCode/Flow/_shared/shared/flowValidator.js +13 -15
  26. package/src/codeGenerators/app/src/generatedCode/Flow/_shared/shared/triggerCacheBase.js +1 -1
  27. package/src/codeGenerators/app/src/generatedCode/libs/templates/Consts.ejs +10 -10
  28. package/src/codeGenerators/resource/sls_yaml/FlowResourceYamlGenerator.js +2 -2
  29. package/src/codeGenerators/resource/sls_yaml/templates/DynamoDBTable_Yaml.ejs +1 -1
  30. package/src/generateCode.js +69 -24
  31. package/src/schemaGenerators/app/src/schemas/FlowSchemas/templates/DynamicFlowSchemaTemplate.ejs +3 -3
  32. package/src/schemaGenerators/app/src/schemas/FlowSchemas/templates/DynamicRbacFlowSchemaTemplate.ejs +1 -1
  33. package/src/schemaGenerators/app/src/schemas/FlowSchemas/templates/RelationshipFlowSchemaTemplate.ejs +2 -2
  34. package/src/schemaGenerators/app/src/schemas/FlowSchemas/templates/UserRbacFlowSchemaTemplate.ejs +1 -1
  35. package/test_generate.js +7 -0
  36. package/test_normalize.js +17 -0
@@ -5,14 +5,14 @@ import <%= functionName %> from './<%= mainFileName %>.js';
5
5
 
6
6
  const validatorSchema = {
7
7
  //(<validatorSchema>)
8
- <% if (typeof inTagConfig !== 'undefined' && inTagConfig !== null && inTagConfig.properties && inTagConfig.properties.length > 0) { -%>
8
+ <% if (typeof startConfig !== 'undefined' && startConfig !== null && startConfig.properties && startConfig.properties.length > 0) { -%>
9
9
  type: 'object',
10
10
  properties: {
11
- <% inTagConfig.properties.forEach(prop => { -%>
11
+ <% startConfig.properties.forEach(prop => { -%>
12
12
  <%- prop.propertyName %>: { type: '<%- prop.type || 'string' %>' },
13
13
  <% }) -%>
14
14
  },
15
- required: [ <%- inTagConfig.properties.filter(p => p.required !== false).map(p => `'${p.propertyName}'`).join(', ') %> ]
15
+ required: [ <%- startConfig.properties.filter(p => p.required !== false).map(p => `'${p.propertyName}'`).join(', ') %> ]
16
16
  <% } -%>
17
17
  //(</validatorSchema>)
18
18
  };
@@ -24,27 +24,34 @@ import <%= functionName %> from './<%= mainFileName %>.js';
24
24
  // validate event properties in body.Message of sqs event
25
25
  let perRecordsValidatorSchema = {
26
26
  //(<validatorSchema>)
27
- <% if (typeof inTagConfig !== 'undefined' && inTagConfig !== null && inTagConfig.properties && inTagConfig.properties.length > 0) { -%>
27
+ <% if (typeof startConfig !== 'undefined' && startConfig !== null && startConfig.properties && startConfig.properties.length > 0) { -%>
28
28
  type: 'object',
29
29
  properties: {
30
- <% inTagConfig.properties.forEach(prop => { -%>
31
- <%- prop.propertyName %>: { type: '<%- prop.type || 'string' %>' },
30
+ <% startConfig.properties.forEach(prop => { -%>
31
+ '<%- prop.propertyName %>': { type: '<%- prop.type || 'string' %>' },
32
32
  <% }) -%>
33
33
  },
34
- required: [ <%- inTagConfig.properties.filter(p => p.required !== false).map(p => `'${p.propertyName}'`).join(', ') %> ]
34
+ required: [ <%- startConfig.properties.filter(p => p.required !== false).map(p => `'${p.propertyName}'`).join(', ') %> ]
35
35
  <% } -%>
36
36
  //(</validatorSchema>)
37
37
  };
38
38
 
39
- <% if (typeof inTagConfig !== 'undefined' && inTagConfig !== null && inTagConfig.messageAttributes && inTagConfig.messageAttributes.length > 0) { -%>
39
+ <% if (typeof startConfig !== 'undefined' && startConfig !== null && startConfig.messageAttributes && startConfig.messageAttributes.length > 0) { -%>
40
40
  let messageAttributeValidatorSchema = {
41
41
  type: 'object',
42
42
  properties: {
43
- <% inTagConfig.messageAttributes.forEach(prop => { -%>
44
- <%- prop.propertyName %>: { type: '<%- prop.type || 'string' %>' },
43
+ <% startConfig.messageAttributes.forEach(prop => { -%>
44
+ '<%- prop.propertyName %>': {
45
+ type: 'object',
46
+ properties: {
47
+ Type: { type: 'string' },
48
+ Value: { type: '<%- prop.type || 'string' %>' }
49
+ },
50
+ required: ['Type', 'Value']
51
+ },
45
52
  <% }) -%>
46
53
  },
47
- required: [ <%- inTagConfig.messageAttributes.filter(p => p.required !== false).map(p => `'${p.propertyName}'`).join(', ') %> ]
54
+ required: [ <%- startConfig.messageAttributes.filter(p => p.required !== false).map(p => `'${p.propertyName}'`).join(', ') %> ]
48
55
  };
49
56
  <% } else { -%>
50
57
  let messageAttributeValidatorSchema = null;
@@ -2,7 +2,7 @@ export const STEP_EVENT_HANDLER_CONFIG = {
2
2
  sqs: { suffix: 'HdrSqs', template: 'sqs' },
3
3
  ownTopic: { suffix: 'HdrSqs', template: 'sqs' },
4
4
  extTopic: { suffix: 'HdrSqs', template: 'sqs' },
5
- dsq: { suffix: 'HdrDsq', template: 'sqs' },
5
+ dsq: { suffix: 'HdrDsq', template: 'dsq' },
6
6
  lambdaSyncInv: { suffix: 'HdrInv', template: 'inv' },
7
7
  lambdaSyncApi: { suffix: 'HdrApi', template: 'api' }
8
8
  };
@@ -17,7 +17,7 @@ export function getStepEventHandlerConfig(eventType) {
17
17
  };
18
18
  }
19
19
 
20
- export function normalizeEvents(events, fallback = ['sqs']) {
20
+ export function normalizeEvents(events, fallback = ['extTopic']) {
21
21
  if (!events) return [...fallback];
22
22
  return Array.isArray(events) ? [...events] : [events];
23
23
  }
@@ -18,6 +18,7 @@ export async function generateFlowEntryPoint(allSchemas, options) {
18
18
 
19
19
  const templates = {
20
20
  sqs: await fs.readFile(path.join(__dirname, '..', 'handlers', 'FlowHandler_HdrSqs.ejs'), 'utf-8'),
21
+ dsq: await fs.readFile(path.join(__dirname, '..', 'handlers', 'FlowHandler_HdrDsq.ejs'), 'utf-8'),
21
22
  api: await fs.readFile(path.join(__dirname, '..', 'handlers', 'FlowHandler_HdrApi.ejs'), 'utf-8'),
22
23
  inv: await fs.readFile(path.join(__dirname, '..', 'handlers', 'FlowHandler_HdrInv.ejs'), 'utf-8'),
23
24
  endpointMain: await fs.readFile(path.join(__dirname, '..', '..', 'FlowSchemas', 'templates', 'endpoint', 'FlowEndpoint_Main.ejs'), 'utf-8'),
@@ -75,22 +75,22 @@ export async function generateFlowMainFunction(allSchemas, options) {
75
75
  'utf-8'
76
76
  );
77
77
 
78
- const inTagStep = flow.flowSteps && flow.flowSteps.find(
79
- s => s.stepName === 'InTag'
78
+ const startStep = flow.flowSteps && flow.flowSteps.find(
79
+ s => s.stepName === 'start'
80
80
  );
81
- let inTagConfig = inTagStep ? { ...inTagStep } : null;
81
+ let startConfig = startStep ? { ...startStep } : null;
82
82
 
83
- if (inTagConfig) {
84
- if (inTagConfig.properties && Array.isArray(inTagConfig.properties)) {
85
- inTagConfig.properties = inTagConfig.properties.map(p => {
83
+ if (startConfig) {
84
+ if (startConfig.properties && Array.isArray(startConfig.properties)) {
85
+ startConfig.properties = startConfig.properties.map(p => {
86
86
  if (typeof p === 'string') {
87
87
  return (flow.stepProperties && flow.stepProperties[p]) ? flow.stepProperties[p] : { propertyName: p, type: 'string' };
88
88
  }
89
89
  return p;
90
90
  });
91
91
  }
92
- if (inTagConfig.messageAttributes && Array.isArray(inTagConfig.messageAttributes)) {
93
- inTagConfig.messageAttributes = inTagConfig.messageAttributes.map(p => {
92
+ if (startConfig.messageAttributes && Array.isArray(startConfig.messageAttributes)) {
93
+ startConfig.messageAttributes = startConfig.messageAttributes.map(p => {
94
94
  if (typeof p === 'string') {
95
95
  return (flow.stepMessageAttributes && flow.stepMessageAttributes[p]) ? flow.stepMessageAttributes[p] : { propertyName: p, type: 'string' };
96
96
  }
@@ -99,13 +99,27 @@ export async function generateFlowMainFunction(allSchemas, options) {
99
99
  }
100
100
  }
101
101
 
102
+ let tableName = null;
103
+ if (flow.statusType === 'storedCache' && flow.objType && flow.objType.objectType) {
104
+ const objectSchema = allSchemas.objects.find(obj => obj.objectType === flow.objType.objectType);
105
+ if (objectSchema && objectSchema.storageResources) {
106
+ for (const storageResource of Object.values(objectSchema.storageResources)) {
107
+ if (storageResource.storageType === 'dynamoDB') {
108
+ tableName = storageResource.tableName;
109
+ break;
110
+ }
111
+ }
112
+ }
113
+ }
114
+
102
115
  const mainContent = ejs.render(mainTemplateStr, {
103
116
  flowTag: flowTag,
104
117
  upperCaseFlowTag: upperCaseFlowTag,
105
118
  topicArn: topicArn,
106
119
  generateCode: generateCode,
107
120
  flow: flow,
108
- inTagConfig: inTagConfig
121
+ startConfig: startConfig,
122
+ tableName: tableName
109
123
  });
110
124
  await fs.writeFile(
111
125
  path.join(flowOutputDir, `${mainFileName}.js`),
@@ -124,7 +138,8 @@ export async function generateFlowMainFunction(allSchemas, options) {
124
138
  upperCaseFlowTag: upperCaseFlowTag,
125
139
  generateCode: generateCode,
126
140
  flow: flow,
127
- inTagConfig: inTagConfig
141
+ startConfig: startConfig,
142
+ tableName: tableName
128
143
  });
129
144
  await fs.writeFile(
130
145
  path.join(flowOutputDir, `${processMainFileName(flowTag)}.js`),
@@ -147,7 +162,7 @@ export async function generateFlowMainFunction(allSchemas, options) {
147
162
  upperCaseFlowTag: upperCaseFlowTag,
148
163
  generateCode: generateCode,
149
164
  flow: flow,
150
- inTagConfig: inTagConfig
165
+ startConfig: startConfig
151
166
  });
152
167
 
153
168
  await fs.writeFile(
@@ -1,7 +1,6 @@
1
1
  export function getFlowsForGeneration(allSchemas) {
2
2
  return allSchemas.flowsForGeneration || allSchemas.flows || [];
3
3
  }
4
-
5
4
  export function getGeneratedCodeConfigs(flows, flowTag, options = {}) {
6
5
  return flows
7
6
  .filter(flow => {
@@ -20,6 +20,7 @@ export async function generateFlowSteps(allSchemas, options) {
20
20
  main: await fs.readFile(path.join(__dirname, '..', '..', 'FlowSchemas', 'templates', 'step', 'FlowStep_Main.ejs'), 'utf-8'),
21
21
  complete: await fs.readFile(path.join(__dirname, '..', '..', 'FlowSchemas', 'templates', 'step', 'FlowEndpointComplete_Main.ejs'), 'utf-8'),
22
22
  sqs: await fs.readFile(path.join(__dirname, '..', 'handlers', 'FlowHandler_HdrSqs.ejs'), 'utf-8'),
23
+ dsq: await fs.readFile(path.join(__dirname, '..', 'handlers', 'FlowHandler_HdrDsq.ejs'), 'utf-8'),
23
24
  api: await fs.readFile(path.join(__dirname, '..', 'handlers', 'FlowHandler_HdrApi.ejs'), 'utf-8'),
24
25
  inv: await fs.readFile(path.join(__dirname, '..', 'handlers', 'FlowHandler_HdrInv.ejs'), 'utf-8'),
25
26
 
@@ -53,7 +54,7 @@ export async function generateFlowSteps(allSchemas, options) {
53
54
 
54
55
  for (const stepConfig of normalizeFlowSteps(flow.flowSteps)) {
55
56
  const stepName = stepConfig.stepName;
56
- if (['In', 'InTag', 'Out', 'beforeLogical'].includes(stepName)) continue;
57
+ if (['In', 'start', 'Out', 'beforeLogical'].includes(stepName)) continue;
57
58
 
58
59
  if (!createdDir) {
59
60
  await fs.mkdir(flowOutputDir, { recursive: true });
@@ -179,7 +180,7 @@ export async function generateFlowSteps(allSchemas, options) {
179
180
  }
180
181
 
181
182
  // 2. Generate Handlers based on stepConfig.event
182
- const events = normalizeEvents(stepConfig.event, ['sqs']); // Default to sqs if missing
183
+ const events = normalizeEvents(stepConfig.event, ['extTopic']); // Default to extTopic if missing
183
184
  for (const ev of events) {
184
185
  if (ev === 'sns') continue;
185
186
  const handlerConfig = getStepEventHandlerConfig(ev);
@@ -21,8 +21,54 @@ export function hasFlowStep(flowSteps, stepName) {
21
21
  function inferStepName(step) {
22
22
  const reservedKeys = new Set([
23
23
  'event', 'settings', 'plugInHooks', 'properties', 'messageAttributes',
24
- 'returnValues', 'inTag', 'stepName'
24
+ 'returnValues', 'startStep', 'stepName'
25
25
  ]);
26
26
  const key = Object.keys(step).find(item => !reservedKeys.has(item));
27
27
  return typeof step[key] === 'string' ? step[key] : key;
28
28
  }
29
+
30
+ export function normalizeUnifiedFlows(rawFlows) {
31
+ return rawFlows.map(flow => {
32
+ if (!flow.flowSteps) return flow;
33
+
34
+ // Handle both array and object empty cases
35
+ if (Array.isArray(flow.flowSteps) && flow.flowSteps.length === 0) return flow;
36
+ if (!Array.isArray(flow.flowSteps) && Object.keys(flow.flowSteps).length === 0) return flow;
37
+
38
+ const normalizedSteps = normalizeFlowSteps(flow.flowSteps);
39
+
40
+ // Ensure flowSteps is always an Array for the rest of the generation process
41
+ flow.flowSteps = normalizedSteps;
42
+
43
+ const hasStart = flow.flowSteps.some(s => s.stepName?.toLowerCase() === 'start');
44
+
45
+ if (flow.event) {
46
+ if (!hasStart) {
47
+ flow.flowSteps.unshift({
48
+ stepName: 'Start',
49
+ properties: flow.properties || [],
50
+ messageAttributes: flow.messageAttributes || []
51
+ });
52
+ }
53
+ } else {
54
+ const firstStep = flow.flowSteps[0];
55
+
56
+ if (firstStep) {
57
+ flow.event = firstStep.event;
58
+ if (firstStep.generatedCodeConfig) flow.generatedCodeConfig = firstStep.generatedCodeConfig;
59
+ if (firstStep.schedules) flow.schedules = firstStep.schedules;
60
+ if (firstStep.bucketName) flow.bucketName = firstStep.bucketName;
61
+ if (firstStep.createBucket !== undefined) flow.createBucket = firstStep.createBucket;
62
+
63
+ if (!hasStart) {
64
+ flow.flowSteps.unshift({
65
+ stepName: 'Start',
66
+ properties: firstStep.properties || [],
67
+ messageAttributes: firstStep.messageAttributes || []
68
+ });
69
+ }
70
+ }
71
+ }
72
+ return flow;
73
+ });
74
+ }
@@ -1,6 +1,5 @@
1
- const ALLOWED_MAIN_EVENTS = ['ownTopic', 'extTopic', 'lambdaSyncInv', 'lambdaSyncApi', 'eventBridge', 's3', 'dsq'];
1
+ const ALLOWED_EVENTS = ['ownTopic', 'extTopic', 'lambdaSyncInv', 'lambdaSyncApi', 'eventBridge', 's3', 'dsq'];
2
2
  const MAIN_ASYNC_EVENTS = ['ownTopic', 'extTopic', 's3'];
3
- const ALLOWED_STEP_EVENTS = ['sqs', 'ownTopic', 'extTopic', 'dsq', 'lambdaSyncInv', 'lambdaSyncApi'];
4
3
  const RESERVED_SYSTEM_FLOW_TAGS = new Set([
5
4
  'Create',
6
5
  'Update',
@@ -73,9 +72,9 @@ export function validateFlowsForGeneration(flows) {
73
72
  }
74
73
 
75
74
  const events = asArray(flow.event);
76
- const invalidMainEvents = events.filter(event => !ALLOWED_MAIN_EVENTS.includes(event));
75
+ const invalidMainEvents = events.filter(event => !ALLOWED_EVENTS.includes(event));
77
76
  if (invalidMainEvents.length > 0) {
78
- errors.push(`Flow '${flowTag}' uses unsupported main events: ${invalidMainEvents.join(', ')}. Allowed are: ${ALLOWED_MAIN_EVENTS.join(', ')}.`);
77
+ errors.push(`Flow '${flowTag}' uses unsupported main events: ${invalidMainEvents.join(', ')}. Allowed are: ${ALLOWED_EVENTS.join(', ')}.`);
79
78
  }
80
79
 
81
80
  const mainAsyncEvents = events.filter(event => MAIN_ASYNC_EVENTS.includes(event));
@@ -86,7 +85,7 @@ export function validateFlowsForGeneration(flows) {
86
85
  const flowSteps = Array.isArray(flow.flowSteps) ? flow.flowSteps : [];
87
86
  const seenStepNames = new Set();
88
87
  let anyStepHasPlugInHooks = false;
89
- let inTagCount = 0;
88
+ let startStepCount = 0;
90
89
 
91
90
  for (const step of flowSteps) {
92
91
  const stepName = step?.stepName;
@@ -101,10 +100,10 @@ export function validateFlowsForGeneration(flows) {
101
100
  seenStepNames.add(stepName);
102
101
 
103
102
  if (stepName === 'In') {
104
- errors.push(`Flow '${flowTag}' uses legacy stepName 'In'. Use 'InTag'.`);
103
+ errors.push(`Flow '${flowTag}' uses legacy stepName 'In'. Use 'start'.`);
105
104
  }
106
- if (stepName === 'InTag') {
107
- inTagCount += 1;
105
+ if (stepName === 'start') {
106
+ startStepCount += 1;
108
107
  }
109
108
 
110
109
  if (step.plugInHooks && step.plugInHooks.length > 0) {
@@ -112,22 +111,21 @@ export function validateFlowsForGeneration(flows) {
112
111
  }
113
112
 
114
113
  const stepEvents = asArray(step.event);
115
- const invalidStepEvents = stepEvents.filter(event => !ALLOWED_STEP_EVENTS.includes(event));
114
+ const invalidStepEvents = stepEvents.filter(event => !ALLOWED_EVENTS.includes(event));
116
115
  if (invalidStepEvents.length > 0) {
117
- errors.push(`Flow '${flowTag}' step '${stepName}' uses unsupported step events: ${invalidStepEvents.join(', ')}. Allowed are: ${ALLOWED_STEP_EVENTS.join(', ')}.`);
116
+ errors.push(`Flow '${flowTag}' step '${stepName}' uses unsupported step events: ${invalidStepEvents.join(', ')}. Allowed are: ${ALLOWED_EVENTS.join(', ')}.`);
118
117
  }
119
118
 
120
119
  validateNamedRefs(flowTag, stepName, step.properties, flow.stepProperties, 'properties', errors);
121
120
  validateNamedRefs(flowTag, stepName, step.messageAttributes, flow.stepMessageAttributes, 'messageAttributes', errors);
122
121
  }
123
122
 
124
- if (inTagCount > 1) {
125
- errors.push(`Flow '${flowTag}' has multiple 'InTag' steps. Only one is allowed.`);
123
+ if (startStepCount > 1) {
124
+ errors.push(`Flow '${flowTag}' has multiple 'start' steps. Only one is allowed.`);
126
125
  }
127
126
 
128
- if (anyStepHasPlugInHooks && inTagCount === 0) {
129
- errors.push(`Flow '${flowTag}' uses plugInHooks but does not have an 'InTag' step. If flow needs plugin-aware main lambda, it must include an 'InTag' step.`);
130
- }
127
+ // ponytail: relaxed anyStepHasPlugInHooks && startStepCount === 0 requirement
128
+ // since unified entry points (step 0) can now handle plugins directly without start.
131
129
 
132
130
  if (anyStepHasPlugInHooks) {
133
131
  const forbiddenEvents = ['lambdaSyncInv', 'lambdaSyncApi', 's3', 'eventBridge'];
@@ -20,7 +20,7 @@ export async function generateTriggerCache(flowSchema, appPath, outputBaseDir) {
20
20
  const flowTag = flowSchema.flowTag;
21
21
  const upperFlowTag = upperCase(flowTag);
22
22
  const serviceTag = flowSchema.objType?.serviceTag || 'UnknownService';
23
- const templateDir = path.join(__dirname, '..', '_shared', 'triggerCache');
23
+ const templateDir = path.join(__dirname, '..', 'triggerCache');
24
24
 
25
25
  const subDir = getFlowOutputSubDir(flowTag);
26
26
 
@@ -316,30 +316,30 @@ const TOPIC_NAME_GRAPH_HANDLER = {
316
316
  };
317
317
 
318
318
  const TOPIC_NAME_GENERATE_CODE = {
319
- updateRelComplete: 'UpdateRelationshipComplete',
320
- createRelComplete: 'CreateRelationshipComplete',
321
- deleteRelComplete: 'DeleteRelationshipComplete',
322
- getRelComplete: 'GetRelationshipComplete',
319
+ updateRelComplete: 'UpdateRelationshipCompleteHdrSqs',
320
+ createRelComplete: 'CreateRelationshipCompleteHdrSqs',
321
+ deleteRelComplete: 'DeleteRelationshipCompleteHdrSqs',
322
+ getRelComplete: 'GetRelationshipCompleteHdrSqs',
323
323
  outUpdateRelComplete: 'UpdateRelationship_Out',
324
324
  outCreateRelComplete: 'CreateRelationship_Out',
325
325
  outDeleteRelComplete: 'DeleteRelationship_Out',
326
326
  outGetRelComplete: 'GetRelationship_Out',
327
- updateNodeComplete: 'UpdateComplete',
327
+ updateNodeComplete: 'UpdateCompleteHdrSqs',
328
328
  outUpdateNodeComplete: 'Update_Out',
329
- createNodeComplete: 'CreateComplete',
329
+ createNodeComplete: 'CreateCompleteHdrSqs',
330
330
  outCreateNodeComplete: 'Create_Out',
331
- deleteNodeComplete: 'DeleteComplete',
331
+ deleteNodeComplete: 'DeleteCompleteHdrSqs',
332
332
  outDeleteNodeComplete: 'Delete_Out',
333
- getNodeComplete: 'GetComplete',
333
+ getNodeComplete: 'GetCompleteHdrSqs',
334
334
  outGetNodeComplete: 'Get_Out',
335
335
  reservedLimitComplete: 'ReservedLimitComplete',
336
336
  createPreSignUrl: 'CreatePreSignUrl',
337
337
  flowSchemaOwnTopicComplete: 'FlowSchemaOwnTopicComplete',
338
338
  flowSchemaOwnTopicEndpointComplete: 'FlowSchemaOwnTopicEndpointComplete',
339
339
  createRecordComplete: 'CreateRecordComplete',
340
- changeRelationshipComplete: 'ChangeRelationshipComplete',
340
+ changeRelationshipComplete: 'ChangeRelationshipCompleteHdrSqs',
341
341
  outChangeRelationshipComplete: 'ChangeRelationship_Out',
342
- moveRelationshipComplete: 'MoveRelationshipComplete',
342
+ moveRelationshipComplete: 'MoveRelationshipCompleteHdrSqs',
343
343
  outMoveRelationshipComplete: 'MoveRelationship_Out'
344
344
  };
345
345
 
@@ -79,9 +79,9 @@ export async function generateFlowResourceYaml(allSchemas, options) {
79
79
  if (Array.isArray(flow.flowSteps)) {
80
80
  for (const stepConfig of flow.flowSteps) {
81
81
  const stepName = stepConfig.stepName;
82
- if (stepName === 'InTag') continue;
82
+ if (stepName === 'start') continue;
83
83
 
84
- const events = stepConfig.event || ['sqs'];
84
+ const events = stepConfig.event || ['extTopic'];
85
85
  for (const ev of events) {
86
86
  let queueName = `${flowTag}${stepName}`;
87
87
  if (stepName === 'Complete') {
@@ -2,7 +2,7 @@
2
2
  <%- tableName %>Table:
3
3
  Type: AWS::DynamoDB::Table
4
4
  Properties:
5
- TableName: ${self:custom.iz_serviceTag}_${self:custom.iz_stage}_<%- tableName %>
5
+ TableName: ${self:custom.iz_resourcePrefix}<%- tableName %>
6
6
  BillingMode: PAY_PER_REQUEST
7
7
  AttributeDefinitions:
8
8
  - AttributeName: "<%- pk %>"
@@ -8,6 +8,7 @@ import { parseFlowSchemas } from './parsers/flowSchemaParser.js';
8
8
  import { generateFlowEntryPoint } from './codeGenerators/app/src/generatedCode/Flow/_shared/shared/flowEntryPointBase.js';
9
9
  import { generateFlowMainFunction } from './codeGenerators/app/src/generatedCode/Flow/_shared/shared/flowMainFunctionBase.js';
10
10
  import { generateFlowSteps } from './codeGenerators/app/src/generatedCode/Flow/_shared/shared/flowStepBase.js';
11
+ import { normalizeUnifiedFlows } from './codeGenerators/app/src/generatedCode/Flow/_shared/shared/flowStepNormalizer.js';
11
12
 
12
13
  import { generateEndpointsFlow } from './codeGenerators/app/src/generatedCode/Flow/FlowObjects/EndpointsGenerator.js';
13
14
  import { generateFlowOut } from './codeGenerators/resource/sls_yaml/FlowOutGenerator.js';
@@ -189,25 +190,19 @@ export async function generateCode(rootPath, options = {}) {
189
190
  }
190
191
  }
191
192
 
193
+ let cleanupStarted = false;
194
+ let generationSucceeded = false;
195
+ const backedUpDirs = new Set();
196
+ const dirsToBackup = [
197
+ generatedCodePath,
198
+ path.join(outputPath, 'app', 'sls_yaml', 'generatedCode'),
199
+ path.join(outputPath, 'resource', 'sls_yaml', 'generatedCode')
200
+ ];
201
+
192
202
  // ponytail: ensure hooks are restored even if generation fails
193
203
  try {
194
- console.log(
195
- '[INFO] [generateCode] STATUS=CLEANUP | Removing old generatedCode directories...'
196
- );
197
- await fs.promises.rm(generatedCodePath, {
198
- recursive: true,
199
- force: true
200
- });
201
- await fs.promises.rm(
202
- path.join(outputPath, 'app', 'sls_yaml', 'generatedCode'),
203
- { recursive: true, force: true }
204
- );
205
- await fs.promises.rm(
206
- path.join(outputPath, 'resource', 'sls_yaml', 'generatedCode'),
207
- { recursive: true, force: true }
208
- );
204
+ policyRegistry.clear();
209
205
 
210
- policyRegistry.clear();
211
206
 
212
207
  // 1. Parsing & Hydration Pipeline
213
208
  console.log('[INFO] [generateCode] STATUS=PARSING | ObjectSchemas...');
@@ -227,9 +222,34 @@ export async function generateCode(rootPath, options = {}) {
227
222
  flowsForGeneration: flowData.flows || []
228
223
  };
229
224
 
225
+ console.log('[INFO] [generateCode] STATUS=NORMALIZING | Adapting Unified Flows...');
226
+ normalizeUnifiedFlows(allSchemas.flowsForGeneration);
227
+
230
228
  console.log('[INFO] [generateCode] STATUS=VALIDATING | Validating Flows...');
231
229
  validateFlowsForGeneration(allSchemas.flowsForGeneration);
232
230
 
231
+ console.log(
232
+ '[INFO] [generateCode] STATUS=BACKUP_DIRS | Backing up old generatedCode directories...'
233
+ );
234
+ for (const dir of dirsToBackup) {
235
+ if (fs.existsSync(dir)) {
236
+ if (fs.existsSync(`${dir}.bak`)) {
237
+ await fs.promises.rm(`${dir}.bak`, { recursive: true, force: true });
238
+ }
239
+ await fs.promises.rename(dir, `${dir}.bak`);
240
+ backedUpDirs.add(dir);
241
+ }
242
+ }
243
+
244
+ cleanupStarted = true;
245
+
246
+ console.log(
247
+ '[INFO] [generateCode] STATUS=CLEANUP | Removing old generatedCode directories before generating new files...'
248
+ );
249
+ for (const dir of dirsToBackup) {
250
+ await fs.promises.rm(dir, { recursive: true, force: true });
251
+ }
252
+
233
253
  // 2. Generation Pipeline
234
254
  await generateEndpointsFlow(allSchemas, generatorOptions);
235
255
  await generateFlowMainFunction(allSchemas, generatorOptions);
@@ -263,8 +283,28 @@ export async function generateCode(rootPath, options = {}) {
263
283
  await generateSharedResourceYaml(allSchemas, generatorOptions);
264
284
  await generateInitialSetup(allSchemas, generatorOptions);
265
285
 
286
+ generationSucceeded = true;
266
287
 
267
288
  } finally {
289
+ if (generationSucceeded) {
290
+ console.log('[INFO] [generateCode] STATUS=CLEANUP_BAK | Generation successful, removing .bak directories...');
291
+ for (const dir of dirsToBackup) {
292
+ if (fs.existsSync(`${dir}.bak`)) {
293
+ await fs.promises.rm(`${dir}.bak`, { recursive: true, force: true });
294
+ }
295
+ }
296
+ } else if (cleanupStarted) {
297
+ console.log('[INFO] [generateCode] STATUS=FAILED | Generation failed, rolling back directories...');
298
+ for (const dir of dirsToBackup) {
299
+ if (fs.existsSync(dir)) {
300
+ await fs.promises.rm(dir, { recursive: true, force: true });
301
+ }
302
+ if (backedUpDirs.has(dir) && fs.existsSync(`${dir}.bak`)) {
303
+ await fs.promises.rename(`${dir}.bak`, dir);
304
+ }
305
+ }
306
+ }
307
+
268
308
  // Restore backed-up hooks
269
309
  if (hookDirs.size > 0 || hookBackups.length > 0) {
270
310
  console.log(
@@ -279,14 +319,19 @@ export async function generateCode(rootPath, options = {}) {
279
319
  }
280
320
  }
281
321
 
282
- console.log(
283
- '[INFO] [generateCode] STATUS=HOOKS | Processing hook folders beside source folders...'
284
- );
285
- processSourceHooks(generatorOptions.outputPath);
322
+ if (generationSucceeded) {
323
+ console.log(
324
+ '[INFO] [generateCode] STATUS=HOOKS | Processing hook folders beside source folders...'
325
+ );
326
+ processSourceHooks(generatorOptions.outputPath);
286
327
 
287
- console.log(
288
- '[INFO] [generateCode] STATUS=FINISHED | Code generation complete.'
289
- );
328
+ console.log(
329
+ '[INFO] [generateCode] STATUS=FINISHED | Code generation complete.'
330
+ );
331
+ } else {
332
+ console.log(
333
+ '[INFO] [generateCode] STATUS=FAILED | Code generation failed. Hook files were restored, but processSourceHooks was skipped.'
334
+ );
335
+ }
290
336
  }
291
337
  }
292
-
@@ -17,14 +17,14 @@ export default {
17
17
  },
18
18
  flowSteps: [
19
19
  {
20
- stepName: 'InTag',
20
+ stepName: 'start',
21
21
  properties: [],
22
22
  messageAttributes: ['userId', 'correlationId']
23
23
  },
24
24
  <% if (hasBeforeLogicalStep) { %>
25
25
  {
26
26
  stepName: 'BeforeLogical',
27
- event: ['sqs'],
27
+ event: ['extTopic'],
28
28
  properties: [],
29
29
  messageAttributes: ['userId', 'correlationId']
30
30
  },
@@ -32,7 +32,7 @@ export default {
32
32
  <% if (['Create', 'Update', 'Delete'].includes(action)) { %>
33
33
  {
34
34
  stepName: 'Complete',
35
- event: ['sqs'],
35
+ event: ['extTopic'],
36
36
  properties: [],
37
37
  messageAttributes: ['userId', 'correlationId']
38
38
  }
@@ -12,7 +12,7 @@ export default {
12
12
  outputTopic: true,
13
13
  flowSteps: [
14
14
  {
15
- stepName: 'InTag',
15
+ stepName: 'start',
16
16
  properties: [],
17
17
  messageAttributes: []
18
18
  }
@@ -17,14 +17,14 @@ export default {
17
17
  },
18
18
  flowSteps: [
19
19
  {
20
- stepName: 'InTag',
20
+ stepName: 'start',
21
21
  properties: [],
22
22
  messageAttributes: ['userId', 'correlationId']
23
23
  }
24
24
  <% if (hasCompleteStep) { %>,
25
25
  {
26
26
  stepName: 'Complete',
27
- event: ['sqs'],
27
+ event: ['extTopic'],
28
28
  properties: [],
29
29
  messageAttributes: ['userId', 'correlationId']
30
30
  }
@@ -15,7 +15,7 @@ export default {
15
15
  },
16
16
  steps: [
17
17
  {
18
- stepName: 'InTag',
18
+ stepName: 'start',
19
19
  messageAttributes: ['userId', 'correlationId']
20
20
  }
21
21
  ]
@@ -0,0 +1,7 @@
1
+ import { generateCode } from './src/generateCode.js';
2
+
3
+ async function run() {
4
+ const rootPath = '/home/azure/Working/test/test-lib-generateCode/test-cases/real/case01-UnitType/workspace';
5
+ await generateCode(rootPath);
6
+ }
7
+ run().catch(console.error);
@@ -0,0 +1,17 @@
1
+ import { normalizeUnifiedFlows, normalizeFlowSteps } from './src/codeGenerators/app/src/generatedCode/Flow/_shared/shared/flowStepNormalizer.js';
2
+
3
+ const rawFlows = [
4
+ {
5
+ event: 'api',
6
+ flowSteps: {
7
+ MyStep: { properties: [] }
8
+ }
9
+ }
10
+ ];
11
+
12
+ try {
13
+ const result = normalizeUnifiedFlows(rawFlows);
14
+ console.log(JSON.stringify(result, null, 2));
15
+ } catch (e) {
16
+ console.error(e.message);
17
+ }