@izara_project/izara-core-generate-service-code 1.0.62 → 1.0.63

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@izara_project/izara-core-generate-service-code",
3
- "version": "1.0.62",
3
+ "version": "1.0.63",
4
4
  "description": "Code for locally generating per service files",
5
5
  "homepage": "https://bitbucket.org/izara-core-support-services/izara-core-support-services-generate-service-code#readme",
6
6
  "repository": {
@@ -10,7 +10,7 @@ export function generatedLambdaRole() {
10
10
  const externalLambdaRole = [
11
11
  <% datas.forEach((data, dataIdx) => { -%>
12
12
  {
13
- roleName: '<%- data.objectType %>',
13
+ roleName: '<%- data.objectType.replace(/Role$/, '') %>',
14
14
  statement: [
15
15
  <% data.additionalResourcePermission.forEach((resourcePermission, resourceIdx) => { -%>
16
16
  {
@@ -80,7 +80,7 @@ export async function generateEndpointsFlow(allSchemas, options) {
80
80
  const beforeLogicalConfigs = generateCode.filter(c => c.codeHookTag === 'beforeLogical');
81
81
  if (beforeLogicalConfigs.length > 0) {
82
82
  const beforeLogicalTemplateStr = await fs.readFile(
83
- path.join(templateDir, 'FlowEndpointBeforeLogical_Main.ejs'),
83
+ path.join(templateDir, 'step', 'FlowEndpointBeforeLogical_Main.ejs'),
84
84
  'utf-8'
85
85
  );
86
86
  const beforeLogicalFileName = `${upperAction}BeforeLogical_Main`;
@@ -41,9 +41,9 @@ const { TOPIC_NAME_GENERATE_CODE, TOPIC_NAME_GRAPH_HANDLER } = consts;
41
41
  const PREFIX = {
42
42
  ONE: 'one',
43
43
  MANY: 'many',
44
- CREATE_OBJECT_ASYNC: 'createObjectAsyncEndpoint',
45
- CREATE_OBJECT_ASYNC_COMPLETE: 'createObjectAsyncEndpointComplete',
46
- CREATE_OBJECT_EXTERNAL_TOPIC: 'createObjectExternalTopicEndpoint'
44
+ CREATE_OBJECT_ASYNC: 'CreateAsyncEndpoint',
45
+ CREATE_OBJECT_ASYNC_COMPLETE: 'CreateAsyncEndpointComplete',
46
+ CREATE_OBJECT_EXTERNAL_TOPIC: 'CreateExternalTopicEndpoint'
47
47
  };
48
48
 
49
49
  /**
@@ -256,13 +256,13 @@ export async function <%- flowTag %>MainLogical(
256
256
 
257
257
  // ── Create awaiting multiple steps ────────────────────────────────────────
258
258
  _izContext.logger.debug('not api will create awaitingStep');
259
- await asyncFlowSharedLib.createAwaitingMultipleStepsWithAdditionalAttributes(
259
+ await asyncFlowSharedLib.createAwaitingMultipleSteps(
260
260
  _izContext,
261
- allAwaitingStepsId,
262
261
  asyncFlowSharedLib.createPendingStepId(
263
262
  _izContext.uniqueRequestId,
264
263
  PREFIX.CREATE_OBJECT_ASYNC_COMPLETE
265
- )
264
+ ),
265
+ allAwaitingStepsId,
266
266
  );
267
267
 
268
268
  // ── Process graph objects ─────────────────────────────────────────────────
@@ -230,67 +230,77 @@ export default async function <%- functionName %>(
230
230
  );
231
231
  _izContext.logger.debug('awaitingStepId:', awaitingStepId);
232
232
 
233
- const recordAwaitingSteps = await dynamodbSharedLib.query(
233
+ const recordAwaitingStep = await asyncFlowSharedLib.findPendingStepAwaitingMultipleSteps(
234
234
  _izContext,
235
- await dynamodbSharedLib.tableName(_izContext, 'AwaitingMultipleSteps'),
236
- { awaitingStepId },
235
+ awaitingStepId
237
236
  );
238
- _izContext.logger.debug('record awaitingSteps::', recordAwaitingSteps);
239
-
240
- await Promise.all(
241
- recordAwaitingSteps.Items.map(async (recordAwaitingStep) => {
242
- if (
243
- await asyncFlowSharedLib.checkAllAwaitingStepsFinished(
244
- _izContext,
245
- recordAwaitingStep.pendingStepId,
246
- awaitingStepId,
247
- errorsFound,
248
- )
249
- ) {
250
- _izContext.logger.debug('finish all awaitingStep');
251
-
252
- await Promise.all(
253
- recordAwaitingStep.listOfRecords.map(async (listOfRecords) => {
254
- if (status === 'complete') {
255
- Object.entries(listOfRecords).map(async ([_, record]) => {
256
- await dynamodbSharedLib.putItem(
257
- _izContext,
258
- dynamodbSharedLib.tableName(_izContext,
259
- record.tableName,
260
- record.serviceTag
261
- ),
262
- {
263
- ...record.objInstanceFull.identifiers,
264
- ...record.objInstanceFull.fields
265
- }
266
- );
267
- })
268
- }
269
- }))
270
-
271
- const messageObject = _buildMessageObject(
272
- returnValue,
273
- existsNode,
274
- status,
275
- errorsFound,
276
- );
277
-
278
- //(<beforeSendMessage>)
279
- //(</beforeSendMessage>)
280
-
281
- await _sendSnsMessage(_izContext, passBackProperties, messageObject);
282
-
283
- //(<afterSendMessage>)
284
- //(</afterSendMessage>)
285
- }
286
-
287
- await asyncFlowSharedLib.removeAwaitingMultipleStep(
288
- _izContext,
289
- awaitingStepId,
290
- recordAwaitingStep.pendingStepId,
291
- errorsFound,
292
- );
293
- }),
237
+ _izContext.logger.debug('recordAwaitingStep:', recordAwaitingStep);
238
+
239
+ const {
240
+ isComplete,
241
+ collectedAttributes,
242
+ collectedErrors,
243
+ returnValues: _rvs,
244
+ additionalAttributes
245
+ } = await asyncFlowSharedLib.checkAllAwaitingStepsFinishedWithReturnParams(
246
+ _izContext,
247
+ recordAwaitingStep.pendingStepId,
248
+ awaitingStepId,
249
+ errorsFound,
250
+ );
251
+
252
+ _izContext.logger.debug('checkAllAwaitingStepsFinishedWithReturnParams:', {
253
+ isComplete,
254
+ collectedAttributes,
255
+ collectedErrors,
256
+ returnValues: _rvs,
257
+ additionalAttributes
258
+ });
259
+
260
+ if (isComplete) {
261
+ _izContext.logger.debug('finish all awaitingStep');
262
+
263
+ await Promise.all(
264
+ (recordAwaitingStep.listOfRecords ?? []).map(async (listOfRecords) => {
265
+ if (status === 'complete') {
266
+ Object.entries(listOfRecords).map(async ([_, record]) => {
267
+ await dynamodbSharedLib.putItem(
268
+ _izContext,
269
+ dynamodbSharedLib.tableName(_izContext,
270
+ record.tableName,
271
+ record.serviceTag
272
+ ),
273
+ {
274
+ ...record.objInstanceFull.identifiers,
275
+ ...record.objInstanceFull.fields
276
+ }
277
+ );
278
+ });
279
+ }
280
+ })
281
+ );
282
+
283
+ const messageObject = _buildMessageObject(
284
+ returnValue,
285
+ existsNode,
286
+ status,
287
+ errorsFound,
288
+ );
289
+
290
+ //(<beforeSendMessage>)
291
+ //(</beforeSendMessage>)
292
+
293
+ await _sendSnsMessage(_izContext, passBackProperties, messageObject);
294
+
295
+ //(<afterSendMessage>)
296
+ //(</afterSendMessage>)
297
+ }
298
+
299
+ await asyncFlowSharedLib.removeAwaitingMultipleStep(
300
+ _izContext,
301
+ awaitingStepId,
302
+ recordAwaitingStep.pendingStepId,
303
+ errorsFound,
294
304
  );
295
305
 
296
306
  //(<beforeReturn>)
@@ -171,8 +171,8 @@ export default async function <%- functionName %> (
171
171
  const matchToFrom = fromServiceTag === secondServiceTag && fromObjectType === secondObjectType &&
172
172
  toServiceTag === firstServiceTag && toObjType === firstObjectType;
173
173
 
174
- if ((newRelationshipSchema.relationshipDirection === "from" && matchFromTo) ||
175
- (newRelationshipSchema.relationshipDirection === "to" && matchToFrom)) {
174
+ if ((oldRelTypeAndDirection.relationshipDirection === "from" && matchFromTo) ||
175
+ (oldRelTypeAndDirection.relationshipDirection === "to" && matchToFrom)) {
176
176
  checkCorrectLink = true
177
177
  break;
178
178
  }
@@ -94,11 +94,19 @@ export const main = middleware.wrap(async (event, context) => {
94
94
 
95
95
  // add argument (to invoke lambda) to passOnProperties[]
96
96
  passOnProperties.push(record.body.Message);
97
+ <% if (functionName.endsWith('Complete')) { %>
98
+ passOnProperties.push(
99
+ callingFlowSharedLib.addPassBackPropertiesToPassOnProperties(
100
+ record.body.Message
101
+ )
102
+ );
103
+ <% } else { %>
97
104
  passOnProperties.push(
98
105
  callingFlowSharedLib.addCallingFlowToPassOnProperties(
99
106
  record.body.Message
100
107
  )
101
108
  );
109
+ <% } %>
102
110
  //(<additionalParams>)
103
111
  //(</additionalParams>)
104
112
  record._izContext.logger.debug(
@@ -76,11 +76,19 @@ export const main = middleware.wrap(async (event, context) => {
76
76
 
77
77
  // add argument (to invoke lambda) to passOnProperties[]
78
78
  passOnProperties.push(record.body.Message);
79
+ <% if (functionName.endsWith('Complete')) { %>
80
+ passOnProperties.push(
81
+ callingFlowSharedLib.addPassBackPropertiesToPassOnProperties(
82
+ record.body.Message
83
+ )
84
+ );
85
+ <% } else { %>
79
86
  passOnProperties.push(
80
87
  callingFlowSharedLib.addCallingFlowToPassOnProperties(
81
88
  record.body.Message
82
89
  )
83
90
  );
91
+ <% } %>
84
92
  //(<additionalParams>)
85
93
  //(</additionalParams>)
86
94
  record._izContext.logger.debug(
@@ -143,10 +143,8 @@ export async function generateFlowMainFunction(allSchemas, options) {
143
143
  // 2. Generate BeforeLogical Main Logic File if needed (CRUD flows only)
144
144
  const beforeLogicalConfigs = generateCode.filter(c => c.codeHookTag === 'beforeLogical');
145
145
  if (isCrud && beforeLogicalConfigs.length > 0) {
146
- const beforeLogicalTemplateStr = await fs.readFile(
147
- path.join(__dirname, '..', '..', 'FlowObjects', 'templates', 'FlowEndpointBeforeLogical_Main.ejs'),
148
- 'utf-8'
149
- );
146
+ const beforeLogicalTemplatePath = path.join(__dirname, '..', '..', 'FlowObjects', 'templates', 'step', 'FlowEndpointBeforeLogical_Main.ejs');
147
+ const beforeLogicalTemplateStr = await fs.readFile(beforeLogicalTemplatePath, 'utf-8');
150
148
 
151
149
  const beforeLogicalFileName = `${upperCaseFlowTag}BeforeLogical_Main`;
152
150
  const beforeLogicalContent = ejs.render(beforeLogicalTemplateStr, {
@@ -18,7 +18,7 @@ export async function generateFlowSteps(allSchemas, options) {
18
18
  // Read templates
19
19
  const templates = {
20
20
  main: await fs.readFile(path.join(__dirname, '..', '..', 'FlowSchemas', 'templates', 'step', 'FlowStep_Main.ejs'), 'utf-8'),
21
- complete: await fs.readFile(path.join(__dirname, '..', '..', 'FlowSchemas', 'templates', 'step', 'FlowEndpointComplete_Main.ejs'), 'utf-8'),
21
+ complete: await fs.readFile(path.join(__dirname, '..', '..', 'FlowObjects', 'templates', 'step', 'FlowEndpointComplete_Main.ejs'), 'utf-8'),
22
22
  sqs: await fs.readFile(path.join(__dirname, '..', 'handlers', 'FlowHandler_HdrSqs.ejs'), 'utf-8'),
23
23
  dsq: await fs.readFile(path.join(__dirname, '..', 'handlers', 'FlowHandler_HdrDsq.ejs'), 'utf-8'),
24
24
  api: await fs.readFile(path.join(__dirname, '..', 'handlers', 'FlowHandler_HdrApi.ejs'), 'utf-8'),
@@ -44,6 +44,7 @@ export async function generateFlowOut(allSchemas, options) {
44
44
  'Create',
45
45
  'Update',
46
46
  'Delete',
47
+ 'Get',
47
48
  'CreateRelationship',
48
49
  'UpdateRelationship',
49
50
  'DeleteRelationship',
package/src/generate.js CHANGED
@@ -93,7 +93,7 @@ async function generate(rootPath, options = {}) {
93
93
 
94
94
  function patchFlowStepsValidationSchema() {
95
95
  const flowStepsSchema = basicValidatorSchema.basicFlowSchema?.properties?.flowSteps;
96
- if (!flowStepsSchema || flowStepsSchema.oneOf) {
96
+ if (!flowStepsSchema || flowStepsSchema.oneOf || !flowStepsSchema.items) {
97
97
  return;
98
98
  }
99
99
 
package/test_schema.js ADDED
@@ -0,0 +1,2 @@
1
+ import { basicValidatorSchema } from '@izara_project/izara-shared-service-schemas';
2
+ console.log(JSON.stringify(basicValidatorSchema.basicFlowSchema?.properties?.flowSteps, null, 2));