@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.
- package/package.json +1 -1
- package/src/emit/coreFunction/emitCoreFunctionArtifacts.js +3 -0
- package/src/emit/coreFunction/templates/InitialSetupConfig.ejs +100 -28
- package/src/emit/coreFunction/templates/InitialSetupRunner_uploadSchema.ejs +2 -0
- package/src/emit/coreFunction/templates/UploadSchema_Main.ejs +2 -0
- package/src/emit/crud/emitCrudApplicationArtifacts.js +2 -2
- package/src/emit/crud/emitDynamicCrudFlowSchemas.js +43 -2
- package/src/emit/crud/templates/CreateComplete_HdrSqs.ejs +99 -0
- package/src/emit/crud/templates/CreateComplete_Main.ejs +188 -0
- package/src/emit/crud/templates/DeleteComplete_HdrSqs.ejs +99 -0
- package/src/emit/crud/templates/DeleteComplete_Main.ejs +188 -0
- package/src/emit/crud/templates/FlowEndpointComplete_Main.ejs +1 -1
- package/src/emit/crud/templates/UpdateComplete_HdrSqs.ejs +99 -0
- package/src/emit/crud/templates/UpdateComplete_Main.ejs +188 -0
- package/src/emit/custom/customFlows.js +56 -0
- package/src/emit/custom/emitCustomFlowApplicationArtifacts.js +24 -9
- package/src/emit/custom/templates/FlowEndpoint_Main.ejs +1 -1
- package/src/emit/custom/templates/triggerCache/CheckTriggerCache_HdrSqs.ejs +2 -1
- package/src/emit/function/functionYamlArtifact.js +8 -3
- package/src/emit/relationship/emitDynamicRelationshipFlowSchemas.js +21 -1
- package/src/emit/relationship/emitRelationshipApplicationArtifacts.js +1 -1
- package/src/emit/relationship/templates/ChangeRelationshipComplete_HdrSqs.ejs +99 -0
- package/src/emit/relationship/templates/ChangeRelationshipComplete_Main.ejs +99 -100
- package/src/emit/relationship/templates/ChangeRelationship_Main.ejs +5 -14
- package/src/emit/relationship/templates/CreateRelationshipComplete_HdrSqs.ejs +99 -0
- package/src/emit/relationship/templates/CreateRelationshipComplete_Main.ejs +98 -99
- package/src/emit/relationship/templates/CreateRelationship_Main.ejs +7 -16
- package/src/emit/relationship/templates/DeleteRelationshipComplete_HdrSqs.ejs +99 -0
- package/src/emit/relationship/templates/DeleteRelationshipComplete_Main.ejs +93 -85
- package/src/emit/relationship/templates/DeleteRelationship_Main.ejs +6 -24
- package/src/emit/relationship/templates/GetRelationshipComplete_HdrSqs.ejs +99 -0
- package/src/emit/relationship/templates/GetRelationshipComplete_Main.ejs +10 -4
- package/src/emit/relationship/templates/GetRelationship_Main.ejs +2 -20
- package/src/emit/relationship/templates/MoveRelationshipComplete_HdrSqs.ejs +99 -0
- package/src/emit/relationship/templates/MoveRelationshipComplete_Main.ejs +101 -104
- package/src/emit/relationship/templates/MoveRelationship_Main.ejs +6 -15
- package/src/emit/relationship/templates/UpdateRelationshipComplete_HdrSqs.ejs +99 -0
- package/src/emit/relationship/templates/UpdateRelationshipComplete_Main.ejs +92 -110
- package/src/emit/relationship/templates/UpdateRelationship_Main.ejs +6 -15
- package/src/emit/resource/emitResourceArtifacts.js +25 -1
- package/src/emit/resource/templates/DynamoDBTable_Yaml.ejs +3 -0
- package/src/emit/shared/templates/FindData_Main.ejs +1 -1
- package/src/emit/shared/templates/FlowHandler_HdrApi.ejs +1 -1
- package/src/emit/shared/templates/FlowHandler_HdrDsq.ejs +2 -1
- package/src/emit/shared/templates/FlowHandler_HdrInv.ejs +1 -1
- package/src/emit/shared/templates/FlowHandler_HdrSqs.ejs +2 -1
- package/src/emit/system/emitSystemWebSocketArtifacts.js +54 -2
- package/src/emit/system/templates/RegisterComplete_HdrSqs.ejs +64 -0
- package/src/emit/system/templates/RegisterComplete_Main.ejs +154 -0
- package/src/emit/system/templates/RegisterComplete_Yaml.ejs +17 -0
- package/src/emit/system/templates/RegisterWbs_Yaml.ejs +7 -0
- package/src/emit/system/templates/Register_HdrWbs.ejs +56 -0
- package/src/emit/system/templates/Register_Main.ejs +148 -0
- package/src/emit/system/templates/WebSocketComplete_Yaml.ejs +2 -0
- package/test/crudApplicationArtifacts.test.js +22 -0
- package/test/customFlowApplicationArtifacts.test.js +147 -1
- package/test/functionYamlArtifact.test.js +5 -2
- package/test/publicApi.test.js +50 -0
- package/test/relationshipApplicationArtifacts.test.js +42 -8
- package/test/resourceArtifacts.test.js +54 -16
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
customFlowRoleName,
|
|
14
14
|
flowDsqSteps,
|
|
15
15
|
flowExtTopicSteps,
|
|
16
|
+
generatedDsqFlows,
|
|
16
17
|
generatedOwnTopicFlows,
|
|
17
18
|
supportedCustomFlows,
|
|
18
19
|
upperFirst
|
|
@@ -94,6 +95,7 @@ export function customFlowApplicationManagedPaths(
|
|
|
94
95
|
}),
|
|
95
96
|
...(supportedCustomFlows(flows).length > 0 ||
|
|
96
97
|
generatedOwnTopicFlows(flows).length > 0 ||
|
|
98
|
+
generatedDsqFlows(flows).length > 0 ||
|
|
97
99
|
flowExtTopicSteps(flows).length > 0 ||
|
|
98
100
|
flowDsqSteps(flows).length > 0 ||
|
|
99
101
|
includeYaml
|
|
@@ -112,7 +114,7 @@ async function emitFlow(flow, objects) {
|
|
|
112
114
|
flowStepName: '',
|
|
113
115
|
mainFileName: `${process}_Main`,
|
|
114
116
|
functionName: process,
|
|
115
|
-
startConfig:
|
|
117
|
+
startConfig: _startConfig(flow)
|
|
116
118
|
};
|
|
117
119
|
const artifacts = needsProcessMain(flow)
|
|
118
120
|
? [
|
|
@@ -319,7 +321,7 @@ async function emitExtTopicStep({ flow, step, flowTag, stepName }) {
|
|
|
319
321
|
const artifacts = [
|
|
320
322
|
{
|
|
321
323
|
path: `${source}/${mainFileName}.js`,
|
|
322
|
-
content: await renderStepMain(functionName)
|
|
324
|
+
content: await renderStepMain(functionName, _startConfig(flow))
|
|
323
325
|
}
|
|
324
326
|
];
|
|
325
327
|
const functions = [];
|
|
@@ -373,7 +375,7 @@ async function emitDsqStep({ flow, step, flowTag, stepName }) {
|
|
|
373
375
|
if (!stepEvents.includes('extTopic')) {
|
|
374
376
|
artifacts.push({
|
|
375
377
|
path: `${source}/${mainFileName}.js`,
|
|
376
|
-
content: await renderStepMain(functionName)
|
|
378
|
+
content: await renderStepMain(functionName, startConfig)
|
|
377
379
|
});
|
|
378
380
|
}
|
|
379
381
|
const functions = [];
|
|
@@ -418,7 +420,7 @@ async function emitOwnTopicRoot(flow, objects) {
|
|
|
418
420
|
flowTag: flow.flowTag,
|
|
419
421
|
flowStepName: '',
|
|
420
422
|
upperCaseFlowTag: tag,
|
|
421
|
-
startConfig:
|
|
423
|
+
startConfig: _startConfig(flow)
|
|
422
424
|
};
|
|
423
425
|
return {
|
|
424
426
|
artifacts: [
|
|
@@ -638,8 +640,20 @@ function _s3HandlerData({ action, flow, functionName, mainFileName, handler }) {
|
|
|
638
640
|
return { functionName, handlerType: handler };
|
|
639
641
|
}
|
|
640
642
|
|
|
641
|
-
function
|
|
642
|
-
const
|
|
643
|
+
function _startConfig(flow) {
|
|
644
|
+
const steps = flow.flowSteps ?? [];
|
|
645
|
+
const start =
|
|
646
|
+
steps.find(
|
|
647
|
+
(s) =>
|
|
648
|
+
typeof s?.stepName === 'string' &&
|
|
649
|
+
s.stepName.toLowerCase() === 'inprocess'
|
|
650
|
+
) ??
|
|
651
|
+
steps.find(
|
|
652
|
+
(s) =>
|
|
653
|
+
typeof s?.stepName === 'string' &&
|
|
654
|
+
s.stepName.toLowerCase() === 'start'
|
|
655
|
+
) ??
|
|
656
|
+
steps[0];
|
|
643
657
|
if (start) {
|
|
644
658
|
return stepConfig(flow, start);
|
|
645
659
|
}
|
|
@@ -691,7 +705,8 @@ async function renderEndpointMain(flow, functionName, objects) {
|
|
|
691
705
|
flowTag: flow.flowTag,
|
|
692
706
|
upperCaseFlowTag: upperFirst(flow.flowTag),
|
|
693
707
|
functionName,
|
|
694
|
-
tableName: storedCacheTableName(flow, objects)
|
|
708
|
+
tableName: storedCacheTableName(flow, objects),
|
|
709
|
+
startConfig: _startConfig(flow)
|
|
695
710
|
});
|
|
696
711
|
}
|
|
697
712
|
|
|
@@ -715,8 +730,8 @@ function storedCacheTableName(flow, objects) {
|
|
|
715
730
|
);
|
|
716
731
|
}
|
|
717
732
|
|
|
718
|
-
async function renderStepMain(functionName) {
|
|
719
|
-
return renderCustom('FlowStep_Main.ejs', { functionName });
|
|
733
|
+
async function renderStepMain(functionName, startConfig = null) {
|
|
734
|
+
return renderCustom('FlowStep_Main.ejs', { functionName, startConfig });
|
|
720
735
|
}
|
|
721
736
|
|
|
722
737
|
function renderMain(functionName) {
|
|
@@ -88,7 +88,7 @@ export default async function <%- typeof functionName !== 'undefined' ? function
|
|
|
88
88
|
createFlowTypeConcat(_izContext, {
|
|
89
89
|
flowTag: '<%= flowTag %>',
|
|
90
90
|
serviceTag: process.env.iz_serviceTag
|
|
91
|
-
})
|
|
91
|
+
}),
|
|
92
92
|
//(<storedCacheConfig>)
|
|
93
93
|
//(</storedCacheConfig>)
|
|
94
94
|
);
|
|
@@ -11,7 +11,8 @@ let perRecordsValidatorSchema = {
|
|
|
11
11
|
properties: {
|
|
12
12
|
<%_ startConfig.properties.forEach((prop, index) => { _%>
|
|
13
13
|
<%- /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(prop.propertyName) ? prop.propertyName : `'${prop.propertyName}'` %>: {
|
|
14
|
-
type: '<%- prop.type || 'string' %>'
|
|
14
|
+
type: '<%- prop.type || 'string' %>'<% if (typeof prop.default !== 'undefined') { %>,
|
|
15
|
+
default: <%- typeof prop.default === 'string' ? `'${prop.default.replace(/'/g, "\\'")}'` : JSON.stringify(prop.default) %><% } %>
|
|
15
16
|
}<%- index < startConfig.properties.length - 1 ? ',' : '' %>
|
|
16
17
|
<%_ }) _%>
|
|
17
18
|
},
|
|
@@ -305,17 +305,22 @@ function _functionSetting(functionName) {
|
|
|
305
305
|
return ` #<#${functionName}FunctionSetting#>\n #<#/${functionName}FunctionSetting#>`;
|
|
306
306
|
}
|
|
307
307
|
|
|
308
|
-
function _sqsFilterPatterns(
|
|
309
|
-
|
|
308
|
+
function _sqsFilterPatterns(
|
|
309
|
+
callingFlowName,
|
|
310
|
+
hookFunctionName = callingFlowName
|
|
311
|
+
) {
|
|
312
|
+
return ` #<#${hookFunctionName}FilterPatterns#>
|
|
313
|
+
filterPatterns:
|
|
310
314
|
- body:
|
|
311
315
|
MessageAttributes:
|
|
312
316
|
callingFlow:
|
|
313
317
|
Value:
|
|
314
|
-
- \${self:custom.iz_resourcePrefix}${
|
|
318
|
+
- \${self:custom.iz_resourcePrefix}${callingFlowName}
|
|
315
319
|
- body:
|
|
316
320
|
MessageAttributes:
|
|
317
321
|
callingFlow:
|
|
318
322
|
Value:
|
|
319
323
|
- exists: false
|
|
324
|
+
#<#/${hookFunctionName}FilterPatterns#>
|
|
320
325
|
`;
|
|
321
326
|
}
|
|
@@ -41,6 +41,15 @@ function createDynamicRelationshipFlow(action) {
|
|
|
41
41
|
const flowSteps = [
|
|
42
42
|
{
|
|
43
43
|
stepName: 'start',
|
|
44
|
+
...(outputTopic
|
|
45
|
+
? {
|
|
46
|
+
nextSteps: [
|
|
47
|
+
{
|
|
48
|
+
stepName: 'Complete'
|
|
49
|
+
}
|
|
50
|
+
]
|
|
51
|
+
}
|
|
52
|
+
: {}),
|
|
44
53
|
properties: [],
|
|
45
54
|
messageAttributes: MESSAGE_ATTRIBUTES,
|
|
46
55
|
...(outputTopic
|
|
@@ -58,7 +67,18 @@ function createDynamicRelationshipFlow(action) {
|
|
|
58
67
|
flowSteps.push({
|
|
59
68
|
stepName: 'Complete',
|
|
60
69
|
event: ['extTopic'],
|
|
61
|
-
|
|
70
|
+
previousSteps: [
|
|
71
|
+
{
|
|
72
|
+
stepName: 'start'
|
|
73
|
+
}
|
|
74
|
+
],
|
|
75
|
+
properties: [
|
|
76
|
+
'returnValue',
|
|
77
|
+
'parentFlowId',
|
|
78
|
+
'status',
|
|
79
|
+
'errorsFound',
|
|
80
|
+
'graphServiceTag'
|
|
81
|
+
],
|
|
62
82
|
messageAttributes: MESSAGE_ATTRIBUTES
|
|
63
83
|
});
|
|
64
84
|
}
|
|
@@ -158,7 +158,7 @@ async function emitAction(action, relationships, flows, serviceTag) {
|
|
|
158
158
|
},
|
|
159
159
|
{
|
|
160
160
|
path: `${source}/${complete}_HdrSqs.js`,
|
|
161
|
-
content: await
|
|
161
|
+
content: await render(`${action}Complete_HdrSqs.ejs`, {
|
|
162
162
|
...shared,
|
|
163
163
|
flowStepName: 'Complete',
|
|
164
164
|
mainFileName: `${complete}_Main`,
|
|
@@ -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 ChangeRelationshipComplete from './ChangeRelationshipComplete_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
|
+
'ChangeRelationshipCompleteHdrSqs', // 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
|
+
ChangeRelationshipComplete, // mainFunction that need to invoke.
|
|
80
|
+
'ChangeRelationshipCompleteHdrSqs', // 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, ChangeRelationshipComplete_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
|
-
|
|
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,124 +36,123 @@ const { TOPIC_NAME_GENERATE_CODE, PREFIX } = consts;
|
|
|
36
36
|
|
|
37
37
|
export default async function changeRelationshipComplete(
|
|
38
38
|
_izContext,
|
|
39
|
-
|
|
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:ChangeRelationshipComplete', {
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
_izContext,
|
|
57
|
-
returnValue.requestParams.firstObject.objType,
|
|
58
|
-
returnValue.requestParams.secondObject.objType,
|
|
59
|
-
returnValue.requestParams.newRelType,
|
|
60
|
-
returnValue.requestParams.oldRelTypeAndDirection.relationshipDirection
|
|
61
|
-
);
|
|
62
|
-
|
|
63
|
-
let awaitingStepId = asyncFlowSharedLib.createAwaitingStepId(
|
|
64
|
-
returnValue.parentFlowId, // hash id
|
|
60
|
+
const awaitingStepId = asyncFlowSharedLib.createAwaitingStepId(
|
|
61
|
+
parentFlowId || returnValue?.parentFlowId, // hash id
|
|
65
62
|
PREFIX.changeRel // prefix, use constant further
|
|
66
63
|
);
|
|
67
64
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
65
|
+
const pending =
|
|
66
|
+
await asyncFlowSharedLib.findPendingStepAwaitingMultipleSteps(
|
|
67
|
+
_izContext,
|
|
68
|
+
awaitingStepId
|
|
69
|
+
);
|
|
70
|
+
_izContext.logger.debug('[ChangeRelationshipComplete] 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
|
+
'[ChangeRelationshipComplete] all awaiting steps result',
|
|
71
91
|
{
|
|
72
|
-
|
|
92
|
+
isComplete: result.isComplete,
|
|
93
|
+
awaitingStepId,
|
|
94
|
+
pendingStepId: pending.pendingStepId
|
|
73
95
|
}
|
|
74
96
|
);
|
|
75
|
-
_izContext.logger.debug(
|
|
76
|
-
'record of createRelPendingObjects ::',
|
|
77
|
-
createRelPendingObjects
|
|
78
|
-
);
|
|
79
97
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
parentFlowId: returnValue.parentFlowId,
|
|
100
|
-
status: status,
|
|
101
|
-
errorsFound: errorsFound
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
changeRelCompleteMsg =
|
|
105
|
-
callingFlowSharedLib.addParentPassBackPropertiesToSnsResponseMessageObject(
|
|
106
|
-
passBackProperties,
|
|
107
|
-
changeRelCompleteMsg
|
|
108
|
-
);
|
|
109
|
-
_izContext.logger.debug(
|
|
110
|
-
'After addCallingFlowToSnsResponseMessageObject',
|
|
111
|
-
changeRelCompleteMsg
|
|
112
|
-
);
|
|
113
|
-
|
|
114
|
-
let messageAttributes =
|
|
115
|
-
callingFlowSharedLib.addParentPassBackCallingFlowToSnsResponseMessageAttributes(
|
|
116
|
-
passBackProperties,
|
|
117
|
-
{}
|
|
118
|
-
);
|
|
119
|
-
_izContext.logger.debug(
|
|
120
|
-
'After addCallingFlowToSnsResponseMessageAttributes',
|
|
121
|
-
changeRelCompleteMsg
|
|
122
|
-
);
|
|
123
|
-
|
|
124
|
-
let sendMessageToOutChangeRelationshipComplete = {
|
|
125
|
-
Message: JSON.stringify(changeRelCompleteMsg),
|
|
126
|
-
MessageAttributes: sns.createStringMessageAttributes(
|
|
127
|
-
_izContext,
|
|
128
|
-
messageAttributes
|
|
129
|
-
),
|
|
130
|
-
TopicArn: snsSharedLib.snsTopicArnByFlowSchema(
|
|
131
|
-
_izContext,
|
|
132
|
-
TOPIC_NAME_GENERATE_CODE.outChangeRelationshipComplete
|
|
133
|
-
)
|
|
134
|
-
};
|
|
135
|
-
_izContext.logger.debug(
|
|
136
|
-
'Send message to OutChangeRelationshipComplete :::>',
|
|
137
|
-
sendMessageToOutChangeRelationshipComplete
|
|
138
|
-
);
|
|
139
|
-
await sns.publishAsync(
|
|
140
|
-
_izContext,
|
|
141
|
-
sendMessageToOutChangeRelationshipComplete
|
|
142
|
-
);
|
|
143
|
-
|
|
144
|
-
//(<afterCheckAwaitingStep>)
|
|
145
|
-
//(</afterCheckAwaitingStep>)
|
|
146
|
-
} // check pendingStepId finished
|
|
147
|
-
|
|
148
|
-
// remove awaitingMultipleStep after finished
|
|
149
|
-
await asyncFlowSharedLib.removeAwaitingMultipleStep(
|
|
150
|
-
_izContext,
|
|
151
|
-
awaitingStepId,
|
|
152
|
-
pendingStepId,
|
|
153
|
-
errorsFound
|
|
98
|
+
if (result.isComplete) {
|
|
99
|
+
_izContext.logger.debug('finished all awaitingStep');
|
|
100
|
+
|
|
101
|
+
let changeRelCompleteMsg = {
|
|
102
|
+
firstObject: returnValue.requestParams.firstObject,
|
|
103
|
+
secondObject: returnValue.requestParams.secondObject,
|
|
104
|
+
relType: returnValue.requestParams.relType,
|
|
105
|
+
oldRelTypeAndDirection:
|
|
106
|
+
returnValue.requestParams.oldRelTypeAndDirection,
|
|
107
|
+
newRelType: returnValue.requestParams.newRelType,
|
|
108
|
+
parentFlowId: parentFlowId || returnValue?.parentFlowId,
|
|
109
|
+
status: status,
|
|
110
|
+
errorsFound: errorsFound
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
changeRelCompleteMsg =
|
|
114
|
+
callingFlowSharedLib.addParentPassBackPropertiesToSnsResponseMessageObject(
|
|
115
|
+
passBackProperties,
|
|
116
|
+
changeRelCompleteMsg
|
|
154
117
|
);
|
|
155
|
-
|
|
156
|
-
|
|
118
|
+
_izContext.logger.debug(
|
|
119
|
+
'After addCallingFlowToSnsResponseMessageObject',
|
|
120
|
+
changeRelCompleteMsg
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
let messageAttributes =
|
|
124
|
+
callingFlowSharedLib.addParentPassBackCallingFlowToSnsResponseMessageAttributes(
|
|
125
|
+
passBackProperties,
|
|
126
|
+
{}
|
|
127
|
+
);
|
|
128
|
+
_izContext.logger.debug(
|
|
129
|
+
'After addCallingFlowToSnsResponseMessageAttributes',
|
|
130
|
+
changeRelCompleteMsg
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
let sendMessageToOutChangeRelationshipComplete = {
|
|
134
|
+
Message: JSON.stringify(changeRelCompleteMsg),
|
|
135
|
+
MessageAttributes: sns.createStringMessageAttributes(
|
|
136
|
+
_izContext,
|
|
137
|
+
messageAttributes
|
|
138
|
+
),
|
|
139
|
+
TopicArn: snsSharedLib.snsTopicArnByFlowSchema(
|
|
140
|
+
_izContext,
|
|
141
|
+
TOPIC_NAME_GENERATE_CODE.outChangeRelationshipComplete
|
|
142
|
+
)
|
|
143
|
+
};
|
|
144
|
+
_izContext.logger.debug(
|
|
145
|
+
'Send message to OutChangeRelationshipComplete :::>',
|
|
146
|
+
sendMessageToOutChangeRelationshipComplete
|
|
147
|
+
);
|
|
148
|
+
await sns.publishAsync(
|
|
149
|
+
_izContext,
|
|
150
|
+
sendMessageToOutChangeRelationshipComplete
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
//(<afterCheckAwaitingStep>)
|
|
154
|
+
//(</afterCheckAwaitingStep>)
|
|
155
|
+
} // check isComplete finished
|
|
157
156
|
|
|
158
157
|
//(<afterCheckAllAwaitingStep>)
|
|
159
158
|
//(</afterCheckAllAwaitingStep>)
|
|
@@ -390,15 +390,6 @@ export default async function <%- functionName %>(
|
|
|
390
390
|
return changeRelCompleteMsg;
|
|
391
391
|
}
|
|
392
392
|
|
|
393
|
-
// before create awaitingStepId per graph storageResource
|
|
394
|
-
const linkTypeId = createLinkTypeId(
|
|
395
|
-
_izContext,
|
|
396
|
-
firstObject.objType,
|
|
397
|
-
secondObject.objType,
|
|
398
|
-
newRelType,
|
|
399
|
-
oldRelTypeAndDirection.relationshipDirection
|
|
400
|
-
);
|
|
401
|
-
|
|
402
393
|
let usedGraphServiceTag = []; // collect used graph serviceTag, use to check duplicate graph serviceTag across graph serverTag
|
|
403
394
|
let targetGraphStorageResources = []; // collect used graph storageResources, filtered duplicate graphServiceTag from graphServerTag out
|
|
404
395
|
let awaitingStepIds = [];
|
|
@@ -412,12 +403,12 @@ export default async function <%- functionName %>(
|
|
|
412
403
|
targetGraphStorageResources.push(targetStorageResource);
|
|
413
404
|
|
|
414
405
|
// awaitingStepId per graphServiceTag
|
|
415
|
-
awaitingStepIds.push(
|
|
416
|
-
asyncFlowSharedLib.createAwaitingStepId(
|
|
406
|
+
awaitingStepIds.push({
|
|
407
|
+
awaitingStepId: asyncFlowSharedLib.createAwaitingStepId(
|
|
417
408
|
parentFlowId, // hash id
|
|
418
409
|
PREFIX.changeRel // prefix, use constant further
|
|
419
410
|
)
|
|
420
|
-
);
|
|
411
|
+
});
|
|
421
412
|
}
|
|
422
413
|
}
|
|
423
414
|
|
|
@@ -426,11 +417,11 @@ export default async function <%- functionName %>(
|
|
|
426
417
|
await asyncFlowSharedLib.createAwaitingMultipleSteps(
|
|
427
418
|
_izContext,
|
|
428
419
|
asyncFlowSharedLib.createPendingStepId(
|
|
429
|
-
// pendingStepId
|
|
430
420
|
_izContext.uniqueRequestId, // hash id
|
|
431
421
|
PREFIX.changeRel // prefix, use constant further
|
|
432
422
|
),
|
|
433
|
-
awaitingStepIds
|
|
423
|
+
awaitingStepIds,
|
|
424
|
+
{}
|
|
434
425
|
);
|
|
435
426
|
|
|
436
427
|
// 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 CreateRelationshipComplete from './CreateRelationshipComplete_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
|
+
'CreateRelationshipCompleteHdrSqs', // 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
|
+
CreateRelationshipComplete, // mainFunction that need to invoke.
|
|
80
|
+
'CreateRelationshipCompleteHdrSqs', // 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, CreateRelationshipComplete_HdrSqs: ', error);
|
|
97
|
+
throw error;
|
|
98
|
+
}
|
|
99
|
+
});
|