@izara_project/izara-core-generate-service-code 1.0.48 → 1.0.49

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.48",
3
+ "version": "1.0.49",
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": {
@@ -23,8 +23,8 @@ const __dirname = path.dirname(__filename);
23
23
  import { getObjectSchema } from '@izara_project/izara-core-library-service-schemas';
24
24
  import util from '#libs/Utils.js';
25
25
  import consts from '#libs/Consts.js';
26
- import intTestLibs from '#libs/Libs.js';
27
- const { directoryPath } = intTestLibs;
26
+ import libs from '../libs/libs';
27
+ const { directoryPath } = libs;
28
28
  const { getLocalConfig } = util;
29
29
  const templatePath = path.join(__dirname, './templateResources.ejs');
30
30
 
@@ -23,7 +23,7 @@ const templatePath = path.join(__dirname, './templateEvents.ejs');
23
23
  import utils from '#libs/Utils.js';
24
24
  const { getLocalConfig } = utils;
25
25
 
26
- import libs from '#libs/Libs.js';
26
+ import libs from '../../libs/libs';
27
27
  const {
28
28
  setEvent,
29
29
  createEventCaseByHandler,
@@ -20,7 +20,7 @@ import generateEvent from './events/events.js';
20
20
  import generateTest from './tests/tests.js';
21
21
  import generatePathIntTest from './pathIntTest/pathIntTest.js';
22
22
  // import generateBashScript from './bashScript/data.js'
23
- import libs from '#libs/Libs.js';
23
+ import libs from '../libs/libs.js';
24
24
  const { getIntTestConfig } = libs;
25
25
  import utils from '#libs/Utils.js';
26
26
  const { getLocalConfig } = utils;
@@ -40,7 +40,7 @@ async function generateCodeWithTemplate(_izContext, savePath, settings) {
40
40
  // console.log("oo:", process.env.iz_resourcePrefix);
41
41
  let allIntTestConfig = await getIntTestConfig(
42
42
  _izContext,
43
- join(savePath, './libs/')
43
+ 'generateIntegrationTest/libs/'
44
44
  );
45
45
  // console.log({ settings })
46
46
  const event = await generateEvent(_izContext, allIntTestConfig, savePath);
@@ -24,7 +24,7 @@ const templatePath = path.join(__dirname, './templateTests.ejs');
24
24
  import utils from '#libs/Utils.js';
25
25
  const { getLocalConfig } = utils;
26
26
 
27
- import libs from '#libs/Libs.js';
27
+ import libs from '../../libs/libs';
28
28
  const {
29
29
  createTestFunctionName,
30
30
  getHandlerFromEventTag,
@@ -10,44 +10,51 @@ function lowercaseFirst(str) {
10
10
  return str[0].toLowerCase() + str.slice(1);
11
11
  }
12
12
 
13
- function directoryPath(dirPath) {
14
- let result = [];
13
+ function directoryPath(dirPath, result = []) {
14
+ if (!fs.existsSync(dirPath)) return {};
15
15
  const items = fs.readdirSync(dirPath);
16
+
16
17
  for (let item of items) {
17
18
  const fullPath = path.join(dirPath, item);
18
19
  const stat = fs.statSync(fullPath);
19
20
 
20
21
  if (stat.isDirectory()) {
21
- directoryPath(fullPath, result); // recursion
22
+ directoryPath(fullPath, result); // ✅ ใช้ result เดียวกัน
22
23
  } else if (stat.isFile()) {
23
24
  if (
24
- !fullPath.includes('shared-resource.yml') &&
25
- !fullPath.includes('core-function.yml')
25
+ !fullPath.includes("shared-resource.yml") &&
26
+ !fullPath.includes("core-function.yml")
26
27
  ) {
27
- if (fullPath.endsWith('.yml')) {
28
+ if (fullPath.endsWith(".yml")) {
28
29
  result.push(fullPath);
29
30
  } else {
30
- console.log('Skipped File:', fullPath);
31
+ console.log("Skipped File:", fullPath);
31
32
  }
32
33
  }
33
34
  }
34
35
  }
35
36
 
36
37
  let functionComponent = {};
38
+
37
39
  for (let ymlFilesPath of result) {
38
- const fileContent = fs.readFileSync(ymlFilesPath, 'utf8');
40
+ const fileContent = fs.readFileSync(ymlFilesPath, "utf8");
39
41
  const parsedYaml = yaml.parse(fileContent);
42
+
40
43
  for (const component of Object.values(parsedYaml)) {
41
44
  if (component.handler && component.name) {
42
45
  const clearName = component.name.replace(
43
- '${self:custom.iz_resourcePrefix}',
44
- ''
46
+ "${self:custom.iz_resourcePrefix}",
47
+ ""
45
48
  );
46
- const clearMain = component.handler.replace(/\.main$/, '');
47
- Object.assign(functionComponent, { [clearName]: clearMain });
49
+ const clearMain = component.handler.replace(/\.main$/, "");
50
+
51
+ Object.assign(functionComponent, {
52
+ [clearName]: clearMain,
53
+ });
48
54
  }
49
55
  }
50
56
  }
57
+
51
58
  return functionComponent;
52
59
  }
53
60
 
@@ -386,10 +393,11 @@ function createResourceName(eventTag) {
386
393
  }
387
394
 
388
395
  async function getIntTestConfig(_izContext, intTestPath) {
389
- return await getDataFromPath(
396
+ return await getObjectSchema.getDataFromPath(
390
397
  _izContext,
391
- 'GenerateIntegrationTestConfig.js',
392
- intTestPath
398
+ intTestPath, // :white_check_mark: ใช้ relative
399
+ path.join(process.cwd(), 'src/'), // :white_check_mark: root ที่ถูก
400
+ { exceptFileName: 'saveConfig' }
393
401
  );
394
402
  }
395
403
 
@@ -427,5 +435,6 @@ export default {
427
435
  getHandlerFromTestTag,
428
436
  createResourceName,
429
437
  setInvokeTest,
430
- getIntTestConfig
438
+ getIntTestConfig,
439
+ buildInvokeStages
431
440
  };
@@ -204,15 +204,17 @@ export async function createMainLogical(
204
204
  createObjInstanceFullFieldsByStorageTag(_izContext, storageTag, createDataDetail));
205
205
  _izContext.logger.debug('objInstanceFull before send to Graph', objInstanceFullForGraph);
206
206
 
207
+ //(<additionalAttributeCreateNode>)
208
+ const additionalAttributes = {};
209
+ //(</additionalAttributeCreateNode>)
210
+
207
211
  const records = allAwaitingStepsId.length === 0 ? listOfRecords : [];
208
212
  allAwaitingStepsId.push({
209
213
  awaitingStepId: await asyncFlowSharedLib.createAwaitingStepId(
210
214
  parentFlowId,
211
215
  PREFIX.CREATE_OBJECT_ASYNC
212
216
  ),
213
- //(<additionalAttributeCreateNode>)
214
- additionalAttributes: { listOfRecords: records }
215
- //(</additionalAttributeCreateNode>)
217
+ additionalAttributes: { listOfRecords: records ,additionalAttributes: additionalAttributes}
216
218
  });
217
219
 
218
220
  listOfObjectForCreates.push({
@@ -239,9 +241,7 @@ export async function createMainLogical(
239
241
  parentFlowId,
240
242
  PREFIX.CREATE_OBJECT_EXTERNAL_TOPIC
241
243
  ),
242
- //(<additionalAttributeCreateExternalTopic>)
243
244
  additionalAttributes: {}
244
- //(</additionalAttributeCreateExternalTopic>)
245
245
  });
246
246
 
247
247
  Object.assign(objInstanceFullForExternalTopic, { parentFlowId: parentFlowId });
@@ -260,7 +260,7 @@ export async function createMainLogical(
260
260
  _izContext,
261
261
  allAwaitingStepsId,
262
262
  asyncFlowSharedLib.createPendingStepId(
263
- hash({ objType, identifiers: objInstanceFull.identifiers }),
263
+ _izContext.uniqueRequestId,
264
264
  PREFIX.CREATE_OBJECT_ASYNC_COMPLETE
265
265
  )
266
266
  );
@@ -326,7 +326,7 @@ export async function createMainLogical(
326
326
  await asyncFlowSharedLib.clearAllAwaitingSteps(
327
327
  _izContext,
328
328
  asyncFlowSharedLib.createPendingStepId(
329
- hash({ objType, identifiers: objInstanceFull.identifiers }),
329
+ _izContext.uniqueRequestId,
330
330
  PREFIX.CREATE_OBJECT_ASYNC_COMPLETE
331
331
  )
332
332
  );
@@ -610,7 +610,7 @@ export default async function createMain(
610
610
  _izContext,
611
611
  awaitingMultipleStepIds,
612
612
  asyncFlowSharedLib.createPendingStepId(
613
- hash(objInstanceFull.identifiers),
613
+ _izContext.uniqueRequestId,
614
614
  'beforeLogical_<%= objectType %>'
615
615
  )
616
616
  );
@@ -187,6 +187,10 @@ export async function updateMainLogical(
187
187
  //(<beforeUpdateNode>)
188
188
  //(</beforeUpdateNode>)
189
189
 
190
+ //(<additionalAttributes>)
191
+ const additionalAttributes = {}
192
+ //(</additionalAttributes>)
193
+
190
194
 
191
195
  records = awaitingStepIds.lenght === 0 ? listOfRecords : [];
192
196
  awaitingStepIds.push({
@@ -194,16 +198,14 @@ export async function updateMainLogical(
194
198
  parentFlowId,
195
199
  PREFIX.updateNode
196
200
  ),
197
- //(<additionalAttributes>)
198
- additionalAttributes: { listOfRecords: records }
199
- //(</additionalAttributes>)
201
+ additionalAttributes: { listOfRecords: records, additionalAttributes: additionalAttributes }
200
202
  });
201
203
 
202
204
  if (awaitingStepIds.length) {
203
205
  const awaitingMultipleStep = await asyncFlowSharedLib.createAwaitingMultipleStepsWithAdditionalAttributes(
204
206
  _izContext,
205
207
  awaitingStepIds,
206
- asyncFlowSharedLib.createPendingStepId(hash({ identifiers, fields }))
208
+ asyncFlowSharedLib.createPendingStepId(_izContext.uniqueRequestId)
207
209
  );
208
210
  _izContext.logger.debug('awaitingMultipleStep', awaitingMultipleStep);
209
211
  }
@@ -444,7 +446,7 @@ export default async function updateMain(
444
446
  _izContext,
445
447
  awaitingMultipleStepIds,
446
448
  asyncFlowSharedLib.createPendingStepId(
447
- hash(identifiers),
449
+ _izContext.uniqueRequestId,
448
450
  'beforeLogical_<%= objectType %>'
449
451
  )
450
452
  );
@@ -286,7 +286,7 @@ export default async function createObjectComplete(
286
286
  await asyncFlowSharedLib.removeAwaitingMultipleStep(
287
287
  _izContext,
288
288
  awaitingStepId,
289
- pendingStepId,
289
+ recordAwaitingStep.pendingStepId,
290
290
  errorsFound,
291
291
  );
292
292
  }),
@@ -316,15 +316,7 @@ export default async function <%- functionName %> (
316
316
  _izContext,
317
317
  awaitingStepIds, // awaitingStepIds
318
318
  asyncFlowSharedLib.createPendingStepId( // pendingStepId
319
- hash({
320
- linkTypeId,
321
- correlationId: _izContext.correlationIds.get("id"),
322
- callingFlowProperties: callingFlowConfig.callingFlowProperties || {},
323
- firstObject,
324
- secondObject,
325
- oldRelTypeAndDirection,
326
- newRelType,
327
- }), // hash id
319
+ _izContext.uniqueRequestId, // hash id
328
320
  PREFIX.changeRel // prefix, use constant further
329
321
  )
330
322
  );
@@ -337,15 +337,7 @@ export default async function createRelationship(
337
337
  _izContext,
338
338
  awaitingStepIds, // awaitingStepIds
339
339
  asyncFlowSharedLib.createPendingStepId( // pendingStepId
340
- hash({
341
- linkTypeId,
342
- relationshipProperties,
343
- correlationId: _izContext.correlationIds.get("id"),
344
- callingFlowProperties: callingFlowConfig.callingFlowProperties || {},
345
- firstObject: firstObject,
346
- secondObject: secondObject,
347
- relType: relType
348
- }), // hash id
340
+ _izContext.uniqueRequestId, // hash id
349
341
  PREFIX.createRel // prefix, use constant further
350
342
  )
351
343
  );
@@ -268,7 +268,7 @@ export default async function deleteRelationship(
268
268
  _izContext,
269
269
  awaitingStepIds, // awaitingStepIds
270
270
  asyncFlowSharedLib.createPendingStepId( // pendingStepId
271
- hash({ linkTypeId, correlationId: _izContext.correlationIds.get("id") }), // hash id
271
+ _izContext.uniqueRequestId, // hash id
272
272
  PREFIX.deleteRel // prefix, use constant further
273
273
  )
274
274
  );
@@ -308,17 +308,7 @@ export default async function moveRelationship(
308
308
  _izContext,
309
309
  awaitingStepIds, // awaitingStepIds
310
310
  asyncFlowSharedLib.createPendingStepId( // pendingStepId
311
- hash({
312
- linkTypeId,
313
- correlationId: _izContext.correlationIds.get("id"),
314
- callingFlowProperties: callingFlowConfig.callingFlowProperties || {},
315
- firstObject,
316
- secondObject,
317
- relType,
318
- relationshipDirection,
319
- relationshipProperties,
320
- moveObject
321
- }), // hash id
311
+ _izContext.uniqueRequestId, // hash id
322
312
  PREFIX.changeRel // prefix, use constant further
323
313
  )
324
314
  );
@@ -314,7 +314,7 @@ export default async function updateRelationship(
314
314
  _izContext,
315
315
  awaitingStepIds, // awaitingStepIds
316
316
  asyncFlowSharedLib.createPendingStepId( // pendingStepId
317
- hash({ linkTypeId, relId, relationshipProperties, correlationId: _izContext.correlationIds.get("id") }), // hash id
317
+ _izContext.uniqueRequestId, // hash id
318
318
  PREFIX.updateRel // prefix, use constant further
319
319
  )
320
320
  );
@@ -14,20 +14,7 @@ await asyncFlowSharedLib.createAwaitingMultipleStepsWithAdditionalAttributes(
14
14
  _izContext,
15
15
  allAwaitingStepsId,
16
16
  asyncFlowSharedLib.createPendingStepId(
17
- hash({
18
- <% if (mainObjType) { -%>
19
- objType: {
20
- serviceTag: "<%- mainObjType.serviceTag %>",
21
- objectType: "<%- mainObjType.objectType %>"
22
- },
23
- //(<createPendingStepIds>)
24
- //(</createPendingStepIds>)
25
- <% } else { -%>
26
- xCorrelationId: _izContext.correlationIds.xCorrelationId,
27
- //(<createPendingStepIds>)
28
- //(</createPendingStepIds>)
29
- <% } %>
30
- }),
17
+ _izContext.awsRequestId,
31
18
  "<%- upperFlowTag %><%- upperFlowStepName %><%- upperHandleLogic %>"
32
19
  )
33
20
  );
@@ -52,6 +39,3 @@ await asyncFlowSharedLib.createAwaitingMultipleStepsWithAdditionalAttributes(
52
39
  )
53
40
  )
54
41
  );
55
-
56
-
57
-
@@ -106,7 +106,7 @@ async function generatePlunIg(
106
106
  flowStepName,
107
107
  flowTag,
108
108
  resourceApis,
109
- hookTagSetting: `${flowSchema.flowTag}FunctionSetting`,
109
+ hookTagSetting: `${flowSchema.flowTag}${upperCase(flowStepName)}FunctionSetting`,
110
110
  functionName: upperCase(flowSchema.flowTag) + upperCase(flowStepName),
111
111
  roleName
112
112
  };
@@ -136,8 +136,8 @@ async function generatePlunIg(
136
136
  event: resourceNames(
137
137
  RESOURCE_CLASSES.sqs,
138
138
  upperCase(flowSchema.flowTag) +
139
- upperCase(flowStepName) +
140
- upperCase(data.handlerType)
139
+ upperCase(flowStepName) +
140
+ upperCase(data.handlerType)
141
141
  ),
142
142
  queueName:
143
143
  upperCase(flowSchema.flowTag) +
@@ -183,9 +183,9 @@ async function generatePlunIg(
183
183
  data.event = resourceNames(
184
184
  RESOURCE_CLASSES.sqs,
185
185
  upperCase(flowSchema.flowTag) +
186
- upperCase(flowStepName) +
187
- upperCase(data.handleLogic) +
188
- upperCase(data.handlerType)
186
+ upperCase(flowStepName) +
187
+ upperCase(data.handleLogic) +
188
+ upperCase(data.handlerType)
189
189
  );
190
190
  const generateLambdaFlowStepByConfig = buildFlowStepResourceByConfig(
191
191
  _izContext,
@@ -405,9 +405,9 @@ function resolveHandlerConfig(
405
405
  createSqsResource([
406
406
  upperCase(flowTag) + upperCase(flowStepName) + upperCase(handler),
407
407
  upperCase(flowTag) +
408
- upperCase(flowStepName) +
409
- upperCase(handler) +
410
- 'DLQ'
408
+ upperCase(flowStepName) +
409
+ upperCase(handler) +
410
+ 'DLQ'
411
411
  ])
412
412
  );
413
413
  } else if (events.includes('extTopic')) {
@@ -417,9 +417,9 @@ function resolveHandlerConfig(
417
417
  createSqsResource([
418
418
  upperCase(flowTag) + upperCase(flowStepName) + upperCase(handler),
419
419
  upperCase(flowTag) +
420
- upperCase(flowStepName) +
421
- upperCase(handler) +
422
- 'DLQ'
420
+ upperCase(flowStepName) +
421
+ upperCase(handler) +
422
+ 'DLQ'
423
423
  ])
424
424
  );
425
425
  } else if (events.includes('lambdaSyncInv')) {
@@ -439,9 +439,9 @@ function resolveHandlerConfig(
439
439
  createSqsResource([
440
440
  upperCase(flowTag) + upperCase(flowStepName) + upperCase(handler),
441
441
  upperCase(flowTag) +
442
- upperCase(flowStepName) +
443
- upperCase(handler) +
444
- 'DSQ'
442
+ upperCase(flowStepName) +
443
+ upperCase(handler) +
444
+ 'DSQ'
445
445
  ])
446
446
  );
447
447
  }
@@ -456,14 +456,14 @@ function resolveHandlerConfig(
456
456
  additionalResourcePermission.push(
457
457
  createSqsResource([
458
458
  upperCase(flowTag) +
459
- upperCase(flowStepName) +
460
- upperCase(flowStepConfig.settings.handleLogic) +
461
- upperCase(HANDLER.hdrSqs),
459
+ upperCase(flowStepName) +
460
+ upperCase(flowStepConfig.settings.handleLogic) +
461
+ upperCase(HANDLER.hdrSqs),
462
462
  upperCase(flowTag) +
463
- upperCase(flowStepName) +
464
- upperCase(flowStepConfig.settings.handleLogic) +
465
- upperCase(HANDLER.hdrSqs) +
466
- 'DLQ'
463
+ upperCase(flowStepName) +
464
+ upperCase(flowStepConfig.settings.handleLogic) +
465
+ upperCase(HANDLER.hdrSqs) +
466
+ 'DLQ'
467
467
  ])
468
468
  );
469
469
  } else if (handleLogic === 'paginated') {
@@ -471,12 +471,12 @@ function resolveHandlerConfig(
471
471
  additionalResourcePermission.push(
472
472
  createSqsResource([
473
473
  upperCase(flowTag) +
474
- upperCase(flowStepName) +
475
- upperCase(HANDLER.hdrDsq),
474
+ upperCase(flowStepName) +
475
+ upperCase(HANDLER.hdrDsq),
476
476
  upperCase(flowTag) +
477
- upperCase(flowStepName) +
478
- upperCase(HANDLER.hdrDsq) +
479
- 'DLQ'
477
+ upperCase(flowStepName) +
478
+ upperCase(HANDLER.hdrDsq) +
479
+ 'DLQ'
480
480
  ])
481
481
  );
482
482
  }