@izara_project/izara-core-generate-service-code 1.0.73 → 1.0.75

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 (60) hide show
  1. package/package.json +1 -1
  2. package/src/emit/coreFunction/emitCoreFunctionArtifacts.js +3 -0
  3. package/src/emit/coreFunction/templates/InitialSetupConfig.ejs +100 -28
  4. package/src/emit/coreFunction/templates/InitialSetupRunner_uploadSchema.ejs +2 -0
  5. package/src/emit/coreFunction/templates/UploadSchema_Main.ejs +2 -0
  6. package/src/emit/crud/emitCrudApplicationArtifacts.js +2 -2
  7. package/src/emit/crud/emitDynamicCrudFlowSchemas.js +43 -2
  8. package/src/emit/crud/templates/CreateComplete_HdrSqs.ejs +99 -0
  9. package/src/emit/crud/templates/CreateComplete_Main.ejs +188 -0
  10. package/src/emit/crud/templates/DeleteComplete_HdrSqs.ejs +99 -0
  11. package/src/emit/crud/templates/DeleteComplete_Main.ejs +188 -0
  12. package/src/emit/crud/templates/FlowEndpointComplete_Main.ejs +1 -1
  13. package/src/emit/crud/templates/UpdateComplete_HdrSqs.ejs +99 -0
  14. package/src/emit/crud/templates/UpdateComplete_Main.ejs +188 -0
  15. package/src/emit/custom/customFlows.js +56 -0
  16. package/src/emit/custom/emitCustomFlowApplicationArtifacts.js +24 -9
  17. package/src/emit/custom/templates/FlowEndpoint_Main.ejs +1 -1
  18. package/src/emit/custom/templates/triggerCache/CheckTriggerCache_HdrSqs.ejs +2 -1
  19. package/src/emit/function/functionYamlArtifact.js +8 -3
  20. package/src/emit/relationship/emitDynamicRelationshipFlowSchemas.js +21 -1
  21. package/src/emit/relationship/emitRelationshipApplicationArtifacts.js +1 -1
  22. package/src/emit/relationship/templates/ChangeRelationshipComplete_HdrSqs.ejs +99 -0
  23. package/src/emit/relationship/templates/ChangeRelationshipComplete_Main.ejs +99 -100
  24. package/src/emit/relationship/templates/ChangeRelationship_Main.ejs +5 -14
  25. package/src/emit/relationship/templates/CreateRelationshipComplete_HdrSqs.ejs +99 -0
  26. package/src/emit/relationship/templates/CreateRelationshipComplete_Main.ejs +98 -99
  27. package/src/emit/relationship/templates/CreateRelationship_Main.ejs +7 -16
  28. package/src/emit/relationship/templates/DeleteRelationshipComplete_HdrSqs.ejs +99 -0
  29. package/src/emit/relationship/templates/DeleteRelationshipComplete_Main.ejs +93 -85
  30. package/src/emit/relationship/templates/DeleteRelationship_Main.ejs +6 -24
  31. package/src/emit/relationship/templates/GetRelationshipComplete_HdrSqs.ejs +99 -0
  32. package/src/emit/relationship/templates/GetRelationshipComplete_Main.ejs +10 -4
  33. package/src/emit/relationship/templates/GetRelationship_Main.ejs +2 -20
  34. package/src/emit/relationship/templates/MoveRelationshipComplete_HdrSqs.ejs +99 -0
  35. package/src/emit/relationship/templates/MoveRelationshipComplete_Main.ejs +101 -104
  36. package/src/emit/relationship/templates/MoveRelationship_Main.ejs +6 -15
  37. package/src/emit/relationship/templates/UpdateRelationshipComplete_HdrSqs.ejs +99 -0
  38. package/src/emit/relationship/templates/UpdateRelationshipComplete_Main.ejs +92 -110
  39. package/src/emit/relationship/templates/UpdateRelationship_Main.ejs +6 -15
  40. package/src/emit/resource/emitResourceArtifacts.js +25 -1
  41. package/src/emit/resource/templates/DynamoDBTable_Yaml.ejs +3 -0
  42. package/src/emit/shared/templates/FindData_Main.ejs +1 -1
  43. package/src/emit/shared/templates/FlowHandler_HdrApi.ejs +1 -1
  44. package/src/emit/shared/templates/FlowHandler_HdrDsq.ejs +2 -1
  45. package/src/emit/shared/templates/FlowHandler_HdrInv.ejs +1 -1
  46. package/src/emit/shared/templates/FlowHandler_HdrSqs.ejs +2 -1
  47. package/src/emit/system/emitSystemWebSocketArtifacts.js +54 -2
  48. package/src/emit/system/templates/RegisterComplete_HdrSqs.ejs +64 -0
  49. package/src/emit/system/templates/RegisterComplete_Main.ejs +154 -0
  50. package/src/emit/system/templates/RegisterComplete_Yaml.ejs +17 -0
  51. package/src/emit/system/templates/RegisterWbs_Yaml.ejs +7 -0
  52. package/src/emit/system/templates/Register_HdrWbs.ejs +56 -0
  53. package/src/emit/system/templates/Register_Main.ejs +148 -0
  54. package/src/emit/system/templates/WebSocketComplete_Yaml.ejs +2 -0
  55. package/test/crudApplicationArtifacts.test.js +22 -0
  56. package/test/customFlowApplicationArtifacts.test.js +147 -1
  57. package/test/functionYamlArtifact.test.js +5 -2
  58. package/test/publicApi.test.js +50 -0
  59. package/test/relationshipApplicationArtifacts.test.js +42 -8
  60. package/test/resourceArtifacts.test.js +54 -16
@@ -0,0 +1,99 @@
1
+ import { middlewareHandler as middleware } from '@izara_project/izara-middleware';
2
+ import { recordHandlerSharedLib } from '@izara_project/izara-core-library-record-handler';
3
+ import Logger from '@izara_project/izara-core-library-logger';
4
+ import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
5
+ import GetRelationshipComplete from './GetRelationshipComplete_Main.js';
6
+
7
+ //(<optionalRequire>)
8
+ //(</optionalRequire>)
9
+
10
+ // validate event properties in body.Message of sqs event
11
+ let perRecordsValidatorSchema = {
12
+ type: 'object',
13
+ properties: {
14
+ returnValue: {
15
+ type: 'object'
16
+ },
17
+ parentFlowId: {
18
+ type: 'string'
19
+ },
20
+ status: {
21
+ type: 'string'
22
+ },
23
+ errorsFound: {
24
+ type: 'array'
25
+ },
26
+ graphServiceTag: {
27
+ type: 'string'
28
+ }
29
+ },
30
+ required: [
31
+ 'returnValue',
32
+ 'parentFlowId',
33
+ 'status',
34
+ 'errorsFound',
35
+ 'graphServiceTag'
36
+ ]
37
+ //(<validatorSchema>)
38
+ //(</validatorSchema>)
39
+ };
40
+
41
+ let messageAttributeValidatorSchema = null;
42
+ middleware.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema());
43
+
44
+ export const main = middleware.wrap(async (event, context) => {
45
+ try {
46
+ let recordPromises = [];
47
+
48
+ // loop each record and send to mainFunction
49
+ await Promise.all(
50
+ event.Records.map(async (record) => {
51
+ let passOnProperties = [];
52
+ record._izContext.logger.debug('record ReceiveMsgOutHdrSqs', record);
53
+
54
+ //validate message (and MessageAttributes)
55
+ await recordHandlerSharedLib.validateRecord(
56
+ record, // one record will send to mainFunction
57
+ 'GetRelationshipCompleteHdrSqs', // queue name that need to retry or send to dlq
58
+ perRecordsValidatorSchema, // schema for record.Message
59
+ messageAttributeValidatorSchema
60
+ );
61
+
62
+ // add argument (to invoke lambda) to passOnProperties[]
63
+ passOnProperties.push(record.body.Message);
64
+ passOnProperties.push(
65
+ callingFlowSharedLib.addPassBackPropertiesToPassOnProperties(
66
+ record.body.Message
67
+ )
68
+ );
69
+ //(<additionalParams>)
70
+ //(</additionalParams>)
71
+ record._izContext.logger.debug(
72
+ 'passOnProperties in handler',
73
+ passOnProperties
74
+ );
75
+
76
+ // call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
77
+ let recordPromise = recordHandlerSharedLib.recordHandler(
78
+ record, // one record will send to mainFunction
79
+ GetRelationshipComplete, // mainFunction that need to invoke.
80
+ 'GetRelationshipCompleteHdrSqs', // queue name that need to retry or send to dlq
81
+ passOnProperties // all parameters that mainFunction needed.
82
+ );
83
+ record._izContext.logger.debug('after recordPromise in handler');
84
+ recordPromises.push(recordPromise); // push promise to recordPromises
85
+ })
86
+ );
87
+ try {
88
+ await Promise.all(recordPromises);
89
+ return event.Records;
90
+ } catch {
91
+ Logger.debug(
92
+ 'Promise.all(recordPromises) in handler threw error (at least one record did no resolve)'
93
+ );
94
+ }
95
+ } catch (error) {
96
+ Logger.error('Unhandled Error, GetRelationshipComplete_HdrSqs: ', error);
97
+ throw error;
98
+ }
99
+ });
@@ -36,15 +36,21 @@ const { TOPIC_NAME_GENERATE_CODE, PREFIX } = consts;
36
36
 
37
37
  export default async function getRelationshipComplete(
38
38
  _izContext,
39
- returnValue,
40
- status,
41
- errorsFound,
42
- graphServiceTag,
39
+ requestParams,
43
40
  passBackProperties = {}
44
41
  ) {
45
42
  try {
43
+ const {
44
+ returnValue,
45
+ parentFlowId,
46
+ status,
47
+ errorsFound,
48
+ graphServiceTag
49
+ } = requestParams;
50
+
46
51
  _izContext.logger.debug('Function:getRelationshipComplete', {
47
52
  returnValue: returnValue,
53
+ parentFlowId: parentFlowId,
48
54
  status: status,
49
55
  errorsFound: errorsFound,
50
56
  graphServiceTag: graphServiceTag,
@@ -162,24 +162,6 @@ export default async function getRelationship(
162
162
  );
163
163
  _izContext.logger.debug('relationshipSchema: ', relationshipSchema);
164
164
 
165
- const links = await findLinksByObjTypes(
166
- _izContext,
167
- [firstObject.objType, secondObject.objType],
168
- relationshipSchema.links
169
- );
170
- _izContext.logger.debug('links', links);
171
- if (!links.length) {
172
- const firstTypeStr = JSON.stringify({
173
- firstObject: firstObject.objType
174
- });
175
- const secondTypeStr = JSON.stringify({
176
- secondObject: secondObject.objType
177
- });
178
- errorsFound.push(
179
- `not found link between ${firstTypeStr} ${secondTypeStr}`
180
- );
181
- }
182
-
183
165
  let targetStorageResources = [];
184
166
 
185
167
  if (relationshipSchema) {
@@ -213,11 +195,11 @@ export default async function getRelationship(
213
195
  const {
214
196
  serviceTag: firstServiceTag,
215
197
  objectType: firstObjectType
216
- } = firstObjectHie.extendObjType || firstObject.objType;
198
+ } = firstObjectHie?.extendObjType || firstObject?.objType || {};
217
199
  const {
218
200
  serviceTag: secondServiceTag,
219
201
  objectType: secondObjectType
220
- } = secondObjectHie.extendObjType || secondObject.objType;
202
+ } = secondObjectHie?.extendObjType || secondObject?.objType || {};
221
203
 
222
204
  // find exists link
223
205
  if (
@@ -0,0 +1,99 @@
1
+ import { middlewareHandler as middleware } from '@izara_project/izara-middleware';
2
+ import { recordHandlerSharedLib } from '@izara_project/izara-core-library-record-handler';
3
+ import Logger from '@izara_project/izara-core-library-logger';
4
+ import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
5
+ import MoveRelationshipComplete from './MoveRelationshipComplete_Main.js';
6
+
7
+ //(<optionalRequire>)
8
+ //(</optionalRequire>)
9
+
10
+ // validate event properties in body.Message of sqs event
11
+ let perRecordsValidatorSchema = {
12
+ type: 'object',
13
+ properties: {
14
+ returnValue: {
15
+ type: 'object'
16
+ },
17
+ parentFlowId: {
18
+ type: 'string'
19
+ },
20
+ status: {
21
+ type: 'string'
22
+ },
23
+ errorsFound: {
24
+ type: 'array'
25
+ },
26
+ graphServiceTag: {
27
+ type: 'string'
28
+ }
29
+ },
30
+ required: [
31
+ 'returnValue',
32
+ 'parentFlowId',
33
+ 'status',
34
+ 'errorsFound',
35
+ 'graphServiceTag'
36
+ ]
37
+ //(<validatorSchema>)
38
+ //(</validatorSchema>)
39
+ };
40
+
41
+ let messageAttributeValidatorSchema = null;
42
+ middleware.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema());
43
+
44
+ export const main = middleware.wrap(async (event, context) => {
45
+ try {
46
+ let recordPromises = [];
47
+
48
+ // loop each record and send to mainFunction
49
+ await Promise.all(
50
+ event.Records.map(async (record) => {
51
+ let passOnProperties = [];
52
+ record._izContext.logger.debug('record ReceiveMsgOutHdrSqs', record);
53
+
54
+ //validate message (and MessageAttributes)
55
+ await recordHandlerSharedLib.validateRecord(
56
+ record, // one record will send to mainFunction
57
+ 'MoveRelationshipCompleteHdrSqs', // queue name that need to retry or send to dlq
58
+ perRecordsValidatorSchema, // schema for record.Message
59
+ messageAttributeValidatorSchema
60
+ );
61
+
62
+ // add argument (to invoke lambda) to passOnProperties[]
63
+ passOnProperties.push(record.body.Message);
64
+ passOnProperties.push(
65
+ callingFlowSharedLib.addPassBackPropertiesToPassOnProperties(
66
+ record.body.Message
67
+ )
68
+ );
69
+ //(<additionalParams>)
70
+ //(</additionalParams>)
71
+ record._izContext.logger.debug(
72
+ 'passOnProperties in handler',
73
+ passOnProperties
74
+ );
75
+
76
+ // call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
77
+ let recordPromise = recordHandlerSharedLib.recordHandler(
78
+ record, // one record will send to mainFunction
79
+ MoveRelationshipComplete, // mainFunction that need to invoke.
80
+ 'MoveRelationshipCompleteHdrSqs', // queue name that need to retry or send to dlq
81
+ passOnProperties // all parameters that mainFunction needed.
82
+ );
83
+ record._izContext.logger.debug('after recordPromise in handler');
84
+ recordPromises.push(recordPromise); // push promise to recordPromises
85
+ })
86
+ );
87
+ try {
88
+ await Promise.all(recordPromises);
89
+ return event.Records;
90
+ } catch {
91
+ Logger.debug(
92
+ 'Promise.all(recordPromises) in handler threw error (at least one record did no resolve)'
93
+ );
94
+ }
95
+ } catch (error) {
96
+ Logger.error('Unhandled Error, MoveRelationshipComplete_HdrSqs: ', error);
97
+ throw error;
98
+ }
99
+ });
@@ -19,7 +19,7 @@ import { objectHash as hash } from '@izara_project/izara-shared-core';
19
19
 
20
20
  import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
21
21
  import snsSharedLib from '@izara_project/izara-core-library-sns';
22
- import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
22
+
23
23
  import asyncFlowSharedLib from '@izara_project/izara-core-library-asynchronous-flow';
24
24
 
25
25
  import { sns } from '@izara_project/izara-core-library-external-request';
@@ -36,128 +36,125 @@ const { TOPIC_NAME_GENERATE_CODE, PREFIX } = consts;
36
36
 
37
37
  export default async function <%- functionName %>(
38
38
  _izContext,
39
- returnValue,
40
- status,
41
- errorsFound,
42
- graphServiceTag,
39
+ requestParams,
43
40
  passBackProperties = {}
44
41
  ) {
45
42
  try {
43
+ const {
44
+ returnValue,
45
+ parentFlowId,
46
+ status,
47
+ errorsFound,
48
+ graphServiceTag
49
+ } = requestParams;
50
+
46
51
  _izContext.logger.debug('Function:<%- functionName %>', {
47
52
  returnValue: returnValue,
53
+ parentFlowId: parentFlowId,
48
54
  status: status,
49
55
  errorsFound: errorsFound,
50
56
  graphServiceTag: graphServiceTag,
51
57
  passBackProperties: passBackProperties
52
58
  });
53
59
 
54
- // start create awaitingStepId
55
- const linkTypeId = createLinkTypeId(
56
- _izContext,
57
- returnValue.requestParams.firstObject.objType,
58
- returnValue.requestParams.secondObject.objType,
59
- returnValue.requestParams.relType,
60
- returnValue.requestParams.relationshipProperties,
61
- returnValue.requestParams.relationshipDirection,
62
- returnValue.requestParams.moveObject
63
- );
64
-
65
- let awaitingStepId = asyncFlowSharedLib.createAwaitingStepId(
66
- returnValue.parentFlowId, // hash id
60
+ const awaitingStepId = asyncFlowSharedLib.createAwaitingStepId(
61
+ parentFlowId || returnValue?.parentFlowId, // hash id
67
62
  PREFIX.changeRel // prefix, use constant further
68
63
  );
69
64
 
70
- let moveRelPendingObjects = await dynamodbSharedLib.query(
71
- _izContext,
72
- await dynamodbSharedLib.tableName(_izContext, 'AwaitingMultipleSteps'),
65
+ const pending =
66
+ await asyncFlowSharedLib.findPendingStepAwaitingMultipleSteps(
67
+ _izContext,
68
+ awaitingStepId
69
+ );
70
+ _izContext.logger.debug('[<%- functionName %>] awaiting step', {
71
+ awaitingStepId,
72
+ pending
73
+ });
74
+
75
+ if (!pending) {
76
+ _izContext.logger.warn(
77
+ `No pending step found for awaitingStepId: ${awaitingStepId}`
78
+ );
79
+ return { returnValue, status, errorsFound };
80
+ }
81
+
82
+ const result =
83
+ await asyncFlowSharedLib.checkAllAwaitingStepsFinishedWithReturnParams(
84
+ _izContext,
85
+ pending.pendingStepId,
86
+ awaitingStepId,
87
+ errorsFound
88
+ );
89
+ _izContext.logger.debug(
90
+ '[<%- functionName %>] all awaiting steps result',
73
91
  {
74
- awaitingStepId: awaitingStepId
92
+ isComplete: result.isComplete,
93
+ awaitingStepId,
94
+ pendingStepId: pending.pendingStepId
75
95
  }
76
96
  );
77
- _izContext.logger.debug(
78
- 'record of moveRelPendingObjects ::',
79
- moveRelPendingObjects
80
- );
81
97
 
82
- await Promise.all(
83
- moveRelPendingObjects.Items.map(async ({ pendingStepId }) => {
84
- if (
85
- await asyncFlowSharedLib.checkAllAwaitingStepsFinished(
86
- _izContext,
87
- pendingStepId, // task waiting
88
- awaitingStepId,
89
- errorsFound
90
- )
91
- ) {
92
- _izContext.logger.debug('finished all awaitingStep');
93
-
94
- let moveRelCompleteMsg = {
95
- firstObject: returnValue.requestParams.firstObject,
96
- secondObject: returnValue.requestParams.secondObject,
97
- relType: returnValue.requestParams.relType,
98
- relationshipProperties:
99
- returnValue.requestParams.relationshipProperties,
100
- relationshipDirection:
101
- returnValue.requestParams.relationshipDirection,
102
- moveObject: returnValue.requestParams.moveObject,
103
- status: status,
104
- parentFlowId: returnValue.parentFlowId,
105
- errorsFound: errorsFound
106
- };
107
-
108
- moveRelCompleteMsg =
109
- callingFlowSharedLib.addParentPassBackPropertiesToSnsResponseMessageObject(
110
- passBackProperties,
111
- moveRelCompleteMsg
112
- );
113
- _izContext.logger.debug(
114
- 'After addCallingFlowToSnsResponseMessageObject',
115
- moveRelCompleteMsg
116
- );
117
-
118
- let messageAttributes =
119
- callingFlowSharedLib.addParentPassBackCallingFlowToSnsResponseMessageAttributes(
120
- passBackProperties,
121
- {}
122
- );
123
- _izContext.logger.debug(
124
- 'After addCallingFlowToSnsResponseMessageAttributes',
125
- moveRelCompleteMsg
126
- );
127
-
128
- let sendMessageToOutMoveRelationshipComplete = {
129
- Message: JSON.stringify(moveRelCompleteMsg),
130
- MessageAttributes: sns.createStringMessageAttributes(
131
- _izContext,
132
- messageAttributes
133
- ),
134
- TopicArn: snsSharedLib.snsTopicArnByFlowSchema(
135
- _izContext,
136
- TOPIC_NAME_GENERATE_CODE.outMoveRelComplete
137
- )
138
- };
139
- _izContext.logger.debug(
140
- 'Send message to OutCreateRelationshipComplete :::>',
141
- sendMessageToOutMoveRelationshipComplete
142
- );
143
- await sns.publishAsync(
144
- _izContext,
145
- sendMessageToOutMoveRelationshipComplete
146
- );
147
-
148
- //(<afterCheckAwaitingStep>)
149
- //(</afterCheckAwaitingStep>)
150
- } // check pendingStepId finished
151
-
152
- // remove awaitingMultipleStep after finished
153
- await asyncFlowSharedLib.removeAwaitingMultipleStep(
154
- _izContext,
155
- awaitingStepId,
156
- pendingStepId,
157
- errorsFound
98
+ if (result.isComplete) {
99
+ _izContext.logger.debug('finished all awaitingStep');
100
+
101
+ let moveRelCompleteMsg = {
102
+ firstObject: returnValue.requestParams.firstObject,
103
+ secondObject: returnValue.requestParams.secondObject,
104
+ relType: returnValue.requestParams.relType,
105
+ relationshipProperties:
106
+ returnValue.requestParams.relationshipProperties,
107
+ relationshipDirection:
108
+ returnValue.requestParams.relationshipDirection,
109
+ moveObject: returnValue.requestParams.moveObject,
110
+ status: status,
111
+ parentFlowId: parentFlowId || returnValue?.parentFlowId,
112
+ errorsFound: errorsFound
113
+ };
114
+
115
+ moveRelCompleteMsg =
116
+ callingFlowSharedLib.addParentPassBackPropertiesToSnsResponseMessageObject(
117
+ passBackProperties,
118
+ moveRelCompleteMsg
158
119
  );
159
- }) // end per pendingStep
160
- );
120
+ _izContext.logger.debug(
121
+ 'After addCallingFlowToSnsResponseMessageObject',
122
+ moveRelCompleteMsg
123
+ );
124
+
125
+ let messageAttributes =
126
+ callingFlowSharedLib.addParentPassBackCallingFlowToSnsResponseMessageAttributes(
127
+ passBackProperties,
128
+ {}
129
+ );
130
+ _izContext.logger.debug(
131
+ 'After addCallingFlowToSnsResponseMessageAttributes',
132
+ moveRelCompleteMsg
133
+ );
134
+
135
+ let sendMessageToOutMoveRelationshipComplete = {
136
+ Message: JSON.stringify(moveRelCompleteMsg),
137
+ MessageAttributes: sns.createStringMessageAttributes(
138
+ _izContext,
139
+ messageAttributes
140
+ ),
141
+ TopicArn: snsSharedLib.snsTopicArnByFlowSchema(
142
+ _izContext,
143
+ TOPIC_NAME_GENERATE_CODE.outMoveRelComplete
144
+ )
145
+ };
146
+ _izContext.logger.debug(
147
+ 'Send message to OutCreateRelationshipComplete :::>',
148
+ sendMessageToOutMoveRelationshipComplete
149
+ );
150
+ await sns.publishAsync(
151
+ _izContext,
152
+ sendMessageToOutMoveRelationshipComplete
153
+ );
154
+
155
+ //(<afterCheckAwaitingStep>)
156
+ //(</afterCheckAwaitingStep>)
157
+ } // check isComplete finished
161
158
 
162
159
  //(<afterCheckAllAwaitingStep>)
163
160
  //(</afterCheckAllAwaitingStep>)
@@ -382,15 +382,6 @@ export default async function moveRelationship(
382
382
  return moveRelCompleteMsg;
383
383
  }
384
384
 
385
- // before create awaitingStepId per graph storageResource
386
- const linkTypeId = createLinkTypeId(
387
- _izContext,
388
- firstObject.objType,
389
- secondObject.objType,
390
- relType,
391
- relationshipDirection
392
- );
393
-
394
385
  let usedGraphServiceTag = []; // collect used graph serviceTag, use to check duplicate graph serviceTag across graph serverTag
395
386
  let targetGraphStorageResources = []; // collect used graph storageResources, filtered duplicate graphServiceTag from graphServerTag out
396
387
  let awaitingStepIds = [];
@@ -404,12 +395,12 @@ export default async function moveRelationship(
404
395
  targetGraphStorageResources.push(targetStorageResource);
405
396
 
406
397
  // awaitingStepId per graphServiceTag
407
- awaitingStepIds.push(
408
- asyncFlowSharedLib.createAwaitingStepId(
398
+ awaitingStepIds.push({
399
+ awaitingStepId: asyncFlowSharedLib.createAwaitingStepId(
409
400
  parentFlowId, // hash id
410
401
  PREFIX.changeRel // prefix, use constant further
411
402
  )
412
- );
403
+ });
413
404
  }
414
405
  }
415
406
 
@@ -417,12 +408,12 @@ export default async function moveRelationship(
417
408
  // save awaiting
418
409
  await asyncFlowSharedLib.createAwaitingMultipleSteps(
419
410
  _izContext,
420
- awaitingStepIds, // awaitingStepIds
421
411
  asyncFlowSharedLib.createPendingStepId(
422
- // pendingStepId
423
412
  _izContext.uniqueRequestId, // hash id
424
413
  PREFIX.changeRel // prefix, use constant further
425
- )
414
+ ),
415
+ awaitingStepIds,
416
+ {}
426
417
  );
427
418
 
428
419
  // prepare message body
@@ -0,0 +1,99 @@
1
+ import { middlewareHandler as middleware } from '@izara_project/izara-middleware';
2
+ import { recordHandlerSharedLib } from '@izara_project/izara-core-library-record-handler';
3
+ import Logger from '@izara_project/izara-core-library-logger';
4
+ import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
5
+ import UpdateRelationshipComplete from './UpdateRelationshipComplete_Main.js';
6
+
7
+ //(<optionalRequire>)
8
+ //(</optionalRequire>)
9
+
10
+ // validate event properties in body.Message of sqs event
11
+ let perRecordsValidatorSchema = {
12
+ type: 'object',
13
+ properties: {
14
+ returnValue: {
15
+ type: 'object'
16
+ },
17
+ parentFlowId: {
18
+ type: 'string'
19
+ },
20
+ status: {
21
+ type: 'string'
22
+ },
23
+ errorsFound: {
24
+ type: 'array'
25
+ },
26
+ graphServiceTag: {
27
+ type: 'string'
28
+ }
29
+ },
30
+ required: [
31
+ 'returnValue',
32
+ 'parentFlowId',
33
+ 'status',
34
+ 'errorsFound',
35
+ 'graphServiceTag'
36
+ ]
37
+ //(<validatorSchema>)
38
+ //(</validatorSchema>)
39
+ };
40
+
41
+ let messageAttributeValidatorSchema = null;
42
+ middleware.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema());
43
+
44
+ export const main = middleware.wrap(async (event, context) => {
45
+ try {
46
+ let recordPromises = [];
47
+
48
+ // loop each record and send to mainFunction
49
+ await Promise.all(
50
+ event.Records.map(async (record) => {
51
+ let passOnProperties = [];
52
+ record._izContext.logger.debug('record ReceiveMsgOutHdrSqs', record);
53
+
54
+ //validate message (and MessageAttributes)
55
+ await recordHandlerSharedLib.validateRecord(
56
+ record, // one record will send to mainFunction
57
+ 'UpdateRelationshipCompleteHdrSqs', // queue name that need to retry or send to dlq
58
+ perRecordsValidatorSchema, // schema for record.Message
59
+ messageAttributeValidatorSchema
60
+ );
61
+
62
+ // add argument (to invoke lambda) to passOnProperties[]
63
+ passOnProperties.push(record.body.Message);
64
+ passOnProperties.push(
65
+ callingFlowSharedLib.addPassBackPropertiesToPassOnProperties(
66
+ record.body.Message
67
+ )
68
+ );
69
+ //(<additionalParams>)
70
+ //(</additionalParams>)
71
+ record._izContext.logger.debug(
72
+ 'passOnProperties in handler',
73
+ passOnProperties
74
+ );
75
+
76
+ // call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
77
+ let recordPromise = recordHandlerSharedLib.recordHandler(
78
+ record, // one record will send to mainFunction
79
+ UpdateRelationshipComplete, // mainFunction that need to invoke.
80
+ 'UpdateRelationshipCompleteHdrSqs', // queue name that need to retry or send to dlq
81
+ passOnProperties // all parameters that mainFunction needed.
82
+ );
83
+ record._izContext.logger.debug('after recordPromise in handler');
84
+ recordPromises.push(recordPromise); // push promise to recordPromises
85
+ })
86
+ );
87
+ try {
88
+ await Promise.all(recordPromises);
89
+ return event.Records;
90
+ } catch {
91
+ Logger.debug(
92
+ 'Promise.all(recordPromises) in handler threw error (at least one record did no resolve)'
93
+ );
94
+ }
95
+ } catch (error) {
96
+ Logger.error('Unhandled Error, UpdateRelationshipComplete_HdrSqs: ', error);
97
+ throw error;
98
+ }
99
+ });