@izara_project/izara-core-generate-service-code 1.0.13 → 1.0.15
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/TemplateData/EndpointPerService/handler/api/template.ejs +22 -8
- package/src/TemplateData/EndpointPerService/mainFunction/create/template.ejs +1 -1
- package/src/TemplateData/EndpointPerService/yaml/template.ejs +2 -2
- package/src/TemplateData/findData/GetByStorage/getByDynamo.ejs +1 -0
- package/src/TemplateData/findData/GetByStorage/getByGraph.ejs +1 -0
- package/src/TemplateData/findData/handler/template.ejs +6 -2
- package/src/TemplateData/findData/mainFunction/template.ejs +9 -3
- package/src/TemplateData/flowSchema/flowStep/afterPluginHook/templateMain.ejs +8 -5
- package/src/TemplateData/flowSchema/flowStep/firstFlowStep/templateMain.ejs +4 -1
- package/src/TemplateData/flowSchema/flowStep/flowStep.js +8 -2
- package/src/TemplateData/perActionComplete/create/mainFunction/createObjectComplete_main.js +17 -17
- package/src/TemplateData/processLogical/handler/template.ejs +53 -51
- package/src/TemplateData/processLogical/mainFunction/template.ejs +9 -1
- package/src/TemplateData/processLogicalPagination/handler/dsq/template.ejs +9 -4
- package/src/TemplateData/processLogicalPagination/handler/sqs/template.ejs +9 -4
- package/src/TemplateData/processLogicalPagination/mainFunction/template.ejs +6 -2
package/package.json
CHANGED
|
@@ -15,9 +15,11 @@ You should have received a copy of the GNU Affero General Public License
|
|
|
15
15
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
import {
|
|
19
|
+
middlewareHandler,
|
|
20
|
+
validatorSchema,
|
|
21
|
+
response
|
|
22
|
+
} from '@izara_project/izara-middleware';
|
|
21
23
|
import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
|
|
22
24
|
|
|
23
25
|
//(<optionalRequire>)
|
|
@@ -30,16 +32,28 @@ import <%- action %>Main from './<%- firstLetterUpperCase(action) %>_Main.js'
|
|
|
30
32
|
|
|
31
33
|
//validate event params in middlewareHandler before into main function
|
|
32
34
|
validatorSchema.validateSchemaMiddleware(
|
|
33
|
-
|
|
35
|
+
'<%- action %>',
|
|
34
36
|
//(<validateSchemaSetting>
|
|
35
37
|
//</validateSchemaSetting>)
|
|
36
38
|
)
|
|
39
|
+
|
|
37
40
|
// if need to validate authorizer or additional params , add code to hook tag below
|
|
38
41
|
|
|
42
|
+
let middlewareSettings = { noAuthorizer: <%- action === 'get' ? true : false %> };
|
|
43
|
+
//(<modifyMiddlewareSettings>
|
|
44
|
+
//</modifyMiddlewareSettings>)
|
|
45
|
+
|
|
46
|
+
middlewareHandler.setValidatorSchema(
|
|
47
|
+
{
|
|
48
|
+
//(<additionalValidatorSchema>
|
|
49
|
+
//</additionalValidatorSchema>)
|
|
50
|
+
},
|
|
51
|
+
middlewareSettings
|
|
52
|
+
);
|
|
53
|
+
|
|
39
54
|
//(<afterValidateWith>)
|
|
40
55
|
//(</afterValidateWith>)
|
|
41
56
|
|
|
42
|
-
|
|
43
57
|
export const main = middlewareHandler.wrap(async (event, context) => {
|
|
44
58
|
event._izContext.logger.debug('Event:', event);
|
|
45
59
|
try {
|
|
@@ -54,15 +68,15 @@ export const main = middlewareHandler.wrap(async (event, context) => {
|
|
|
54
68
|
|
|
55
69
|
// return error to client
|
|
56
70
|
if (lambdaFunctionResponse instanceof Error) {
|
|
57
|
-
return
|
|
71
|
+
return response.failure(lambdaFunctionResponse);
|
|
58
72
|
}
|
|
59
73
|
|
|
60
74
|
// return success to client
|
|
61
|
-
return
|
|
75
|
+
return response.success(lambdaFunctionResponse);
|
|
62
76
|
|
|
63
77
|
} catch (err) {
|
|
64
78
|
event._izContext.logger.error('Error, <%- firstLetterUpperCase(action) %>_<%- firstLetterUpperCase(handler) %>: ', err);
|
|
65
|
-
return
|
|
79
|
+
return response.failure(err);
|
|
66
80
|
}
|
|
67
81
|
});
|
|
68
82
|
<%_ function firstLetterUpperCase(text){
|
|
@@ -484,7 +484,7 @@ export default async function createMain(
|
|
|
484
484
|
}; // end loop listOfObjectForCreates
|
|
485
485
|
|
|
486
486
|
if (errorsFound.length > 0) {
|
|
487
|
-
_izContext.logger.debug("Case have
|
|
487
|
+
_izContext.logger.debug("Case have errorsFound:::", errorsFound);
|
|
488
488
|
|
|
489
489
|
// remove awaitingMultipleStep. [[[[[[[open when not test local.]]]]]]]
|
|
490
490
|
await asyncFlowSharedLib.clearAllAwaitingSteps(
|
|
@@ -16,14 +16,14 @@
|
|
|
16
16
|
- httpApi:
|
|
17
17
|
path: /<%- serviceTag %>/<%- resourceApi.event %>/<%- action %>
|
|
18
18
|
method: <%- resourceApi.method %>
|
|
19
|
-
authorizer: authorizerServiceSchema
|
|
20
19
|
#<#<%- firstLetterUpperCase(resourceApi.event) _%><%- firstLetterUpperCase(handlerType) %>AppLevelAuthorizer#>
|
|
20
|
+
# authorizer: authorizerServiceSchema
|
|
21
21
|
#<#/<%- firstLetterUpperCase(resourceApi.event) _%><%- firstLetterUpperCase(handlerType) %>AppLevelAuthorizer#>
|
|
22
22
|
- httpApi:
|
|
23
23
|
path: /<%- serviceTag %>/<%- resourceApi.event %>/<%- action %>/{targetUserId}
|
|
24
24
|
method: <%- resourceApi.method %>
|
|
25
|
-
authorizer: authorizerIdentifiers
|
|
26
25
|
#<#<%- firstLetterUpperCase(resourceApi.event) _%><%- firstLetterUpperCase(handlerType) %>UserLevelAuthorizer#>
|
|
26
|
+
# authorizer: authorizerIdentifiers
|
|
27
27
|
#<#/<%- firstLetterUpperCase(resourceApi.event) _%><%- firstLetterUpperCase(handlerType) %>UserLevelAuthorizer#>
|
|
28
28
|
<%_ }) _%>
|
|
29
29
|
<%_ } _%>
|
|
@@ -30,7 +30,7 @@ middleware.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema());
|
|
|
30
30
|
// set schema for record.body.Message
|
|
31
31
|
const perRecordsValidatorSchema = {
|
|
32
32
|
type: 'object',
|
|
33
|
-
required: ['fieldName', 'objType', 'identifiers'],
|
|
33
|
+
required: ['fieldName', 'objType', 'identifiers', 'overWriteCache'],
|
|
34
34
|
properties: {
|
|
35
35
|
fieldName: {
|
|
36
36
|
type: 'object'
|
|
@@ -49,6 +49,9 @@ const perRecordsValidatorSchema = {
|
|
|
49
49
|
identifiers: {
|
|
50
50
|
type: 'object'
|
|
51
51
|
},
|
|
52
|
+
overWriteCache: {
|
|
53
|
+
type: 'boolean'
|
|
54
|
+
},
|
|
52
55
|
callingFlow: {
|
|
53
56
|
type: 'string',
|
|
54
57
|
default: ''
|
|
@@ -94,6 +97,7 @@ export const main = middleware.wrap(async (event, context) => {
|
|
|
94
97
|
passOnProperties.push(record.body.Message.fieldName);
|
|
95
98
|
passOnProperties.push(record.body.Message.objType);
|
|
96
99
|
passOnProperties.push(record.body.Message.identifiers);
|
|
100
|
+
passOnProperties.push(record.body.Message.overWriteCache);
|
|
97
101
|
passOnProperties.push(record.body.Message.callingFlow);
|
|
98
102
|
record._izContext.logger.debug(
|
|
99
103
|
'passOnProperties in handler',
|
|
@@ -128,4 +132,4 @@ export const main = middleware.wrap(async (event, context) => {
|
|
|
128
132
|
Logger.error('Unhandled Error, FindDataHdrSqs: ', err);
|
|
129
133
|
throw err;
|
|
130
134
|
}
|
|
131
|
-
});
|
|
135
|
+
});
|
|
@@ -15,8 +15,6 @@ You should have received a copy of the GNU Affero General Public License
|
|
|
15
15
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
'use strict';
|
|
19
|
-
|
|
20
18
|
import findDataSharedLib from '@izara_project/izara-core-library-find-data';
|
|
21
19
|
import graphSharedLib from '@izara_project/izara-core-library-graph-service';
|
|
22
20
|
import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb'
|
|
@@ -32,6 +30,7 @@ import { serviceConfig, identifiersObject as identifierObj } from '@izara_projec
|
|
|
32
30
|
* @param {string} fieldName
|
|
33
31
|
* @param {Object} objType
|
|
34
32
|
* @param {Object} identifiers
|
|
33
|
+
* @param {Boolean} overWriteCache
|
|
35
34
|
*
|
|
36
35
|
* @returns {object} description of return value
|
|
37
36
|
*/
|
|
@@ -41,7 +40,9 @@ export default async function findData(
|
|
|
41
40
|
fieldName,
|
|
42
41
|
objType,
|
|
43
42
|
identifiers,
|
|
43
|
+
overWriteCache,
|
|
44
44
|
callingFlow,
|
|
45
|
+
|
|
45
46
|
//(<additionalParams>)
|
|
46
47
|
//(</additionalParams>)
|
|
47
48
|
) {
|
|
@@ -52,6 +53,7 @@ export default async function findData(
|
|
|
52
53
|
fieldName: fieldName,
|
|
53
54
|
objType: objType,
|
|
54
55
|
identifiers: identifiers,
|
|
56
|
+
overWriteCache: overWriteCache,
|
|
55
57
|
callingFlow: callingFlow
|
|
56
58
|
});
|
|
57
59
|
|
|
@@ -60,6 +62,8 @@ export default async function findData(
|
|
|
60
62
|
//(<removeAttributes>)
|
|
61
63
|
//(</removeAttributes>)
|
|
62
64
|
|
|
65
|
+
let deleteDataTableOnExpired = [];
|
|
66
|
+
|
|
63
67
|
// Check/create FindDataMain status
|
|
64
68
|
let [findDataMainStatus, findDataId, findDataMain] = await findDataSharedLib.checkFindDataMainStatus(
|
|
65
69
|
_izContext,
|
|
@@ -67,7 +71,8 @@ export default async function findData(
|
|
|
67
71
|
objType,
|
|
68
72
|
identifiers,
|
|
69
73
|
callingFlow,
|
|
70
|
-
removeAttributes
|
|
74
|
+
removeAttributes,
|
|
75
|
+
overWriteCache
|
|
71
76
|
);
|
|
72
77
|
_izContext.logger.debug('result after checkFindDataMainStatus is', {
|
|
73
78
|
findDataMainStatus: findDataMainStatus,
|
|
@@ -90,6 +95,7 @@ export default async function findData(
|
|
|
90
95
|
objType,
|
|
91
96
|
identifiers,
|
|
92
97
|
null,
|
|
98
|
+
overWriteCache,
|
|
93
99
|
callingFlow,
|
|
94
100
|
'error'
|
|
95
101
|
];
|
|
@@ -61,9 +61,12 @@ export default async function <%- functionName %>Main (
|
|
|
61
61
|
//(</hookCode>)
|
|
62
62
|
|
|
63
63
|
<% if (typeof afterPlugInHookTag !== 'undefined' && afterPlugInHookTag) { %>
|
|
64
|
-
await
|
|
64
|
+
await handlerPlugInHookTag(
|
|
65
65
|
_izContext,
|
|
66
|
-
'<%-
|
|
66
|
+
'<%- plugHookTag %>',
|
|
67
|
+
'<%- flowTag %>',
|
|
68
|
+
'<%- flowStepName %>',
|
|
69
|
+
'<%- flowStepIndex %>',
|
|
67
70
|
<%- (function(){
|
|
68
71
|
const s = JSON.stringify(objType, null, 2);
|
|
69
72
|
if (s === '{}') return '{\n }';
|
|
@@ -71,9 +74,9 @@ export default async function <%- functionName %>Main (
|
|
|
71
74
|
const t = s.replace(/"([^\"]+)":\s*"([^\"]*)"/g, "$1: '$2'");
|
|
72
75
|
return t.replace(/\n/g, '\n ');
|
|
73
76
|
})() %>,
|
|
74
|
-
'<%-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
+
'<%- queueNameDsq %>',
|
|
78
|
+
plugInIdentifiers,
|
|
79
|
+
plugInAdditionalRequest
|
|
77
80
|
);
|
|
78
81
|
<% } %>
|
|
79
82
|
return '<%- functionName %> completed successfully';
|
|
@@ -64,9 +64,12 @@ export default async function <%- functionName %>Main (
|
|
|
64
64
|
//(<hookCodePlugin>)
|
|
65
65
|
//(</hookCodePlugin>)
|
|
66
66
|
|
|
67
|
-
await
|
|
67
|
+
await handlerPlugInHookTag(
|
|
68
68
|
_izContext,
|
|
69
69
|
'<%- plugHookTag %>',
|
|
70
|
+
'<%- flowTag %>',
|
|
71
|
+
'<%- flowStepName %>',
|
|
72
|
+
'<%- flowStepIndex %>',
|
|
70
73
|
<%- (function(){
|
|
71
74
|
const s = JSON.stringify(objType, null, 2);
|
|
72
75
|
if (s === '{}') return '{\n }';
|
|
@@ -214,6 +214,9 @@ function buildFlowStepResources(_izContext, flowSchema, saveFilePath) {
|
|
|
214
214
|
functionName: `${lowerCase(flowStepName)}${firstIndex}`,
|
|
215
215
|
plugHookTag: flowStepConfig.plugInHooks[0].plugInHookTag,
|
|
216
216
|
objType: flowStepConfig.plugInHooks[0].objType,
|
|
217
|
+
flowTag: flowTag,
|
|
218
|
+
flowStepName: flowStepName,
|
|
219
|
+
flowStepIndex: firstIndex,
|
|
217
220
|
queueNameDsq: `${upperCase(flowTag)}${upperCase(flowStepName)}${currentIndex}HdrDsq`
|
|
218
221
|
},
|
|
219
222
|
setting: {
|
|
@@ -388,8 +391,11 @@ function buildFlowStepResources(_izContext, flowSchema, saveFilePath) {
|
|
|
388
391
|
functionName: `${lowerCase(flowStepName)}${currentIndex}`,
|
|
389
392
|
afterPlugInHookTag: afterPlugInHookTag,
|
|
390
393
|
plugInHookTag: plugInHookTag,
|
|
391
|
-
objType: pluginHook.objType
|
|
392
|
-
|
|
394
|
+
objType: pluginHook.objType,
|
|
395
|
+
queueNameDsq: `${upperCase(flowTag)}${upperCase(flowStepName)}${currentIndex}HdrDsq`,
|
|
396
|
+
flowTag: flowTag,
|
|
397
|
+
flowStepName: flowStepName,
|
|
398
|
+
flowStepIndex: firstIndex
|
|
393
399
|
},
|
|
394
400
|
setting: {
|
|
395
401
|
savePath: path.join(flowSchemaSourcePath),
|
|
@@ -64,7 +64,7 @@ module.exports.createObjectComplete = async (
|
|
|
64
64
|
callingFlowConfig
|
|
65
65
|
});
|
|
66
66
|
|
|
67
|
-
|
|
67
|
+
const errorsFound = [];
|
|
68
68
|
|
|
69
69
|
if (_.isEmpty(returnValue)) {
|
|
70
70
|
_izContext.logger.debug('message callingFlowProperties is empty');
|
|
@@ -72,43 +72,43 @@ module.exports.createObjectComplete = async (
|
|
|
72
72
|
}
|
|
73
73
|
// validate.
|
|
74
74
|
if (!returnValue.hasOwnProperty('queryResult')) {
|
|
75
|
-
|
|
75
|
+
errorsFound.push(
|
|
76
76
|
'message is not have property queryResult, should be not happen'
|
|
77
77
|
);
|
|
78
78
|
}
|
|
79
79
|
if (!returnValue.hasOwnProperty('objType')) {
|
|
80
|
-
|
|
80
|
+
errorsFound.push(
|
|
81
81
|
'message is not have property objType, should be not happen'
|
|
82
82
|
);
|
|
83
83
|
}
|
|
84
84
|
if (!returnValue.hasOwnProperty('objInstance')) {
|
|
85
|
-
|
|
85
|
+
errorsFound.push(
|
|
86
86
|
'message is not have property objInstance, should be not objInstance'
|
|
87
87
|
);
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
if (status == 'error' && errorsFound.length > 0) {
|
|
91
|
-
|
|
91
|
+
errorsFound.push(errorsFound);
|
|
92
92
|
} else if (status == 'error' && errorsFound.length == 0) {
|
|
93
|
-
|
|
94
|
-
'[invalid]
|
|
93
|
+
errorsFound.push(
|
|
94
|
+
'[invalid]status is error not have errorsFound form graphService'
|
|
95
95
|
);
|
|
96
96
|
}
|
|
97
97
|
if (status === 'complete' && errorsFound.length > 0) {
|
|
98
|
-
|
|
99
|
-
'[Invalid] status is
|
|
98
|
+
errorsFound.push(
|
|
99
|
+
'[Invalid] status is complete should be not have errorsFound'
|
|
100
100
|
);
|
|
101
101
|
}
|
|
102
102
|
if (graphServiceTag == '') {
|
|
103
|
-
|
|
103
|
+
errorsFound.push('[Invalid] graphServiceTag is not empty string');
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
if (errorsFound.length > 0) {
|
|
107
|
-
_izContext.logger.debug('Have error form
|
|
108
|
-
|
|
107
|
+
_izContext.logger.debug('Have error form graphService:', errorsFound);
|
|
108
|
+
errorsFound = errorsFound.concat(errorsFound);
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
// check and remove
|
|
111
|
+
// check and remove awaitingStep finish.
|
|
112
112
|
let awaitingStepId = asyncFlowSharedLib.createAwaitingStepId(
|
|
113
113
|
hash({
|
|
114
114
|
objType: returnValue.objType,
|
|
@@ -128,7 +128,7 @@ module.exports.createObjectComplete = async (
|
|
|
128
128
|
);
|
|
129
129
|
_izContext.logger.debug('record awaitingSteps::', recordAwaitingSteps);
|
|
130
130
|
|
|
131
|
-
|
|
131
|
+
nextAwaitingSteps: for (let listRecordAwaitingStep of recordAwaitingSteps.Items) {
|
|
132
132
|
_izContext.logger.debug(
|
|
133
133
|
'iterate RecordAwaitingStep:',
|
|
134
134
|
listRecordAwaitingStep
|
|
@@ -142,8 +142,8 @@ module.exports.createObjectComplete = async (
|
|
|
142
142
|
))
|
|
143
143
|
) {
|
|
144
144
|
_izContext.logger.debug('!Waiting record form other graph::');
|
|
145
|
-
// **** add step of remove
|
|
146
|
-
continue
|
|
145
|
+
// **** add step of remove awaitingMultiples!! ??
|
|
146
|
+
continue nextAwaitingSteps;
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
await asyncFlowSharedLib.removeAwaitingMultipleStep(
|
|
@@ -160,7 +160,7 @@ module.exports.createObjectComplete = async (
|
|
|
160
160
|
let messageObject = {
|
|
161
161
|
objType: returnValue.objType,
|
|
162
162
|
identifierId: returnValue.objInstance.identifiers,
|
|
163
|
-
|
|
163
|
+
errorsFound: errorsFound
|
|
164
164
|
};
|
|
165
165
|
|
|
166
166
|
messageObject =
|
|
@@ -15,42 +15,39 @@ You should have received a copy of the GNU Affero General Public License
|
|
|
15
15
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
import { middlewareHandler as middleware } from "@izara_project/izara-middleware";
|
|
18
|
+
import { middlewareHandler as middleware } from '@izara_project/izara-middleware';
|
|
21
19
|
import Logger from '@izara_project/izara-core-library-logger';
|
|
22
|
-
import { recordHandlerSharedLib } from
|
|
20
|
+
import { recordHandlerSharedLib } from '@izara_project/izara-core-library-record-handler';
|
|
23
21
|
import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
|
|
24
22
|
|
|
25
23
|
import processLogical from './ProcessLogical_Main.js';
|
|
26
24
|
|
|
27
|
-
|
|
28
25
|
// validate event properties in body.Message of sqs event
|
|
29
26
|
middleware.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema());
|
|
30
27
|
|
|
31
28
|
// set schema for record.body.Message
|
|
32
29
|
const perRecordsValidatorSchema = {
|
|
33
|
-
type:
|
|
34
|
-
required: [
|
|
35
|
-
'objType',
|
|
36
|
-
'element'
|
|
37
|
-
],
|
|
30
|
+
type: 'object',
|
|
31
|
+
required: ['objType', 'element', 'overWriteCache'],
|
|
38
32
|
properties: {
|
|
39
33
|
objType: {
|
|
40
34
|
type: 'object',
|
|
41
|
-
required: [
|
|
35
|
+
required: ['serviceTag', 'objectType'],
|
|
42
36
|
properties: {
|
|
43
37
|
serviceTag: {
|
|
44
|
-
type:
|
|
38
|
+
type: 'string',
|
|
45
39
|
enum: [process.env.iz_serviceTag]
|
|
46
40
|
},
|
|
47
41
|
objectType: {
|
|
48
|
-
type:
|
|
42
|
+
type: 'string'
|
|
49
43
|
}
|
|
50
44
|
}
|
|
51
45
|
},
|
|
52
46
|
element: {
|
|
53
|
-
type:
|
|
47
|
+
type: 'object'
|
|
48
|
+
},
|
|
49
|
+
overWriteCache: {
|
|
50
|
+
type: 'boolean'
|
|
54
51
|
},
|
|
55
52
|
callingFlow: {
|
|
56
53
|
type: 'string',
|
|
@@ -74,56 +71,61 @@ const perRecordsValidatorSchema = {
|
|
|
74
71
|
// };
|
|
75
72
|
|
|
76
73
|
export const main = middleware.wrap(async (event, context, callback) => {
|
|
77
|
-
|
|
78
74
|
try {
|
|
79
|
-
|
|
80
75
|
let recordPromises = [];
|
|
81
76
|
|
|
82
77
|
// loop each record and send to mainFunction
|
|
83
|
-
await Promise.all(
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
78
|
+
await Promise.all(
|
|
79
|
+
event.Records.map(async record => {
|
|
80
|
+
// promise.all for map() function
|
|
81
|
+
|
|
82
|
+
let passOnProperties = [];
|
|
83
|
+
record._izContext.logger.debug('record ReceiveMsgOutHdrSqs', record);
|
|
84
|
+
|
|
85
|
+
// validate message (and MessageAttributes)
|
|
86
|
+
await recordHandlerSharedLib.validateRecord(
|
|
87
|
+
record, // one record will send to mainFunction
|
|
88
|
+
'ProcessLogicalHdrSqs', // queue name that need to retry or send to dlq
|
|
89
|
+
perRecordsValidatorSchema // schema for record.Message
|
|
90
|
+
// messageAttributeValidatorSchema // ----- for msgAttr default is null -> do not send this parameter if not want to validate msgAtt
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
// add argument (to invoke lambda) to passOnProperties[]
|
|
94
|
+
passOnProperties.push(record.body.Message.objType);
|
|
95
|
+
passOnProperties.push(record.body.Message.element);
|
|
96
|
+
passOnProperties.push(record.body.Message.overWriteCache);
|
|
97
|
+
passOnProperties.push(record.body.Message.callingFlow);
|
|
98
|
+
record._izContext.logger.debug(
|
|
99
|
+
'passOnProperties in handler',
|
|
100
|
+
passOnProperties
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
// call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
|
|
104
|
+
let recordPromise = recordHandlerSharedLib.recordHandler(
|
|
105
|
+
record, // one record will send to mainFunction
|
|
106
|
+
processLogical, // mainFunction that need to invoke.
|
|
107
|
+
'ProcessLogicalHdrSqs', // queue name that need to retry or send to dlq
|
|
108
|
+
passOnProperties // all parameters that mainFunction needed.
|
|
109
|
+
);
|
|
110
|
+
record._izContext.logger.debug('after recordPromise in handler');
|
|
111
|
+
recordPromises.push(recordPromise); // push promise to recordPromises
|
|
112
|
+
})
|
|
113
|
+
);
|
|
112
114
|
|
|
113
115
|
Logger.debug('before Promise.all(recordPromises) in handler');
|
|
114
116
|
try {
|
|
115
117
|
// --- main await all promises
|
|
116
118
|
await Promise.all(recordPromises); // await all promises
|
|
117
119
|
|
|
118
|
-
return event.Records // return all for local testing
|
|
119
|
-
|
|
120
|
+
return event.Records; // return all for local testing
|
|
120
121
|
} catch {
|
|
121
|
-
Logger.debug(
|
|
122
|
+
Logger.debug(
|
|
123
|
+
'Promise.all(recordPromises) in handler threw error (at least one record did no resolve)'
|
|
124
|
+
);
|
|
122
125
|
}
|
|
123
126
|
Logger.debug('after Promise.all(recordPromises) in handler');
|
|
124
|
-
|
|
125
127
|
} catch (err) {
|
|
126
128
|
Logger.error('Unhandled Error, ProcessLogicalHdrSqs: ', err);
|
|
127
|
-
throw
|
|
129
|
+
throw err;
|
|
128
130
|
}
|
|
129
|
-
});
|
|
131
|
+
});
|
|
@@ -46,6 +46,7 @@ import { identifiersObject as identifierObj } from '@izara_project/izara-core-li
|
|
|
46
46
|
* @param {Object} [element.sortKeyValues] - value of fieldNames that is sortKey. (optional)
|
|
47
47
|
* @param {string} [element.comparison] - use for query in queryElements.sortKeyCondition. (optional)
|
|
48
48
|
* @param {string} [element.conditionalFieldValues] - user after query for filter data before save to logicalData table. (optional)
|
|
49
|
+
* @param {boolean} overWriteCache
|
|
49
50
|
*
|
|
50
51
|
* @returns {string} description of return value
|
|
51
52
|
*/
|
|
@@ -54,12 +55,14 @@ export default async function processLogical(
|
|
|
54
55
|
_izContext,
|
|
55
56
|
objType,
|
|
56
57
|
element,
|
|
58
|
+
overWriteCache,
|
|
57
59
|
callingFlow
|
|
58
60
|
) {
|
|
59
61
|
try {
|
|
60
62
|
_izContext.logger.debug('----- ProcessLogical event params -----', {
|
|
61
63
|
objType: objType,
|
|
62
64
|
element: element,
|
|
65
|
+
overWriteCache: overWriteCache,
|
|
63
66
|
callingFlow: callingFlow
|
|
64
67
|
});
|
|
65
68
|
|
|
@@ -75,7 +78,8 @@ export default async function processLogical(
|
|
|
75
78
|
element, // for create logicalResultId
|
|
76
79
|
objType,
|
|
77
80
|
callingFlow,
|
|
78
|
-
removeAttributes
|
|
81
|
+
removeAttributes,
|
|
82
|
+
overWriteCache
|
|
79
83
|
);
|
|
80
84
|
_izContext.logger.debug('After check logicalMainStatus: ', {
|
|
81
85
|
logicalResultsMainStatus: logicalResultsMainStatus,
|
|
@@ -99,6 +103,7 @@ export default async function processLogical(
|
|
|
99
103
|
logicalResultId,
|
|
100
104
|
logicalResultMain.logicalElement,
|
|
101
105
|
logicalResultMain.objType,
|
|
106
|
+
overWriteCache,
|
|
102
107
|
callingFlow,
|
|
103
108
|
'error'
|
|
104
109
|
];
|
|
@@ -284,6 +289,7 @@ export default async function processLogical(
|
|
|
284
289
|
sortKeyFieldName: sortKeyFieldName,
|
|
285
290
|
dynamoDbIdentifiers: dynamoDbIdentifiers,
|
|
286
291
|
comparison: comparison,
|
|
292
|
+
overWriteCache: overWriteCache,
|
|
287
293
|
callingFlow: callingFlow
|
|
288
294
|
}),
|
|
289
295
|
TopicArn: await snsSharedLib.snsTopicArnByFlowSchema(
|
|
@@ -361,6 +367,7 @@ export default async function processLogical(
|
|
|
361
367
|
partitionKeyFieldName: partitionKeyFieldName,
|
|
362
368
|
sortKeyFieldName: sortKeyFieldName,
|
|
363
369
|
dynamoDbIdentifiers: dynamoDbIdentifiers,
|
|
370
|
+
overWriteCache: overWriteCache,
|
|
364
371
|
callingFlow: callingFlow
|
|
365
372
|
}),
|
|
366
373
|
TopicArn: await snsSharedLib.snsTopicArnByFlowSchema(
|
|
@@ -424,6 +431,7 @@ export default async function processLogical(
|
|
|
424
431
|
logicalResultId,
|
|
425
432
|
element,
|
|
426
433
|
objType,
|
|
434
|
+
overWriteCache,
|
|
427
435
|
callingFlow,
|
|
428
436
|
'complete',
|
|
429
437
|
[]
|
|
@@ -48,7 +48,8 @@ const perRecordsValidatorSchema = {
|
|
|
48
48
|
'sortKeyFieldName',
|
|
49
49
|
'dynamoDbIdentifiers',
|
|
50
50
|
'startKey',
|
|
51
|
-
'overwriteUniqueRequestId'
|
|
51
|
+
'overwriteUniqueRequestId',
|
|
52
|
+
'overWriteCache'
|
|
52
53
|
],
|
|
53
54
|
properties: {
|
|
54
55
|
logicalResultId: {
|
|
@@ -76,6 +77,9 @@ const perRecordsValidatorSchema = {
|
|
|
76
77
|
overwriteUniqueRequestId: {
|
|
77
78
|
type: 'string'
|
|
78
79
|
},
|
|
80
|
+
overWriteCache: {
|
|
81
|
+
type: 'boolean'
|
|
82
|
+
},
|
|
79
83
|
callingFlow: {
|
|
80
84
|
type: 'string',
|
|
81
85
|
default: ''
|
|
@@ -85,14 +89,14 @@ const perRecordsValidatorSchema = {
|
|
|
85
89
|
|
|
86
90
|
// set schema for record.body.MessageAttributes
|
|
87
91
|
// const messageAttributeValidatorSchema = {
|
|
88
|
-
// type:
|
|
92
|
+
// type: 'object',
|
|
89
93
|
// required: ['msgAtrrParam1', 'msgAtrrParam2'],
|
|
90
94
|
// properties: {
|
|
91
95
|
// msgAtrrParam1: {
|
|
92
|
-
// type:
|
|
96
|
+
// type: 'string'
|
|
93
97
|
// },
|
|
94
98
|
// msgAtrrParam2: {
|
|
95
|
-
// type:
|
|
99
|
+
// type: 'object'
|
|
96
100
|
// }
|
|
97
101
|
// }
|
|
98
102
|
// };
|
|
@@ -135,6 +139,7 @@ export const main = middleware.wrap(async (event, context, callback) => {
|
|
|
135
139
|
passOnProperties.push(record.body.Message.comparison);
|
|
136
140
|
passOnProperties.push(record.body.Message.startKey);
|
|
137
141
|
passOnProperties.push(record.body.Message.overwriteUniqueRequestId);
|
|
142
|
+
passOnProperties.push(record.body.Message.overWriteCache);
|
|
138
143
|
passOnProperties.push(record.body.Message.callingFlow);
|
|
139
144
|
record._izContext.logger.debug(
|
|
140
145
|
'passOnProperties in handler',
|
|
@@ -33,7 +33,8 @@ const perRecordsValidatorSchema = {
|
|
|
33
33
|
'tableName',
|
|
34
34
|
'partitionKeyFieldName',
|
|
35
35
|
'sortKeyFieldName',
|
|
36
|
-
'dynamoDbIdentifiers'
|
|
36
|
+
'dynamoDbIdentifiers',
|
|
37
|
+
'overWriteCache'
|
|
37
38
|
],
|
|
38
39
|
properties: {
|
|
39
40
|
logicalResultId: {
|
|
@@ -63,6 +64,9 @@ const perRecordsValidatorSchema = {
|
|
|
63
64
|
type: 'string',
|
|
64
65
|
default: ''
|
|
65
66
|
},
|
|
67
|
+
overWriteCache: {
|
|
68
|
+
type: 'boolean'
|
|
69
|
+
},
|
|
66
70
|
callingFlow: {
|
|
67
71
|
type: 'string',
|
|
68
72
|
default: ''
|
|
@@ -72,14 +76,14 @@ const perRecordsValidatorSchema = {
|
|
|
72
76
|
|
|
73
77
|
// set schema for record.body.MessageAttributes
|
|
74
78
|
// const messageAttributeValidatorSchema = {
|
|
75
|
-
// type:
|
|
79
|
+
// type: 'object',
|
|
76
80
|
// required: ['msgAtrrParam1', 'msgAtrrParam2'],
|
|
77
81
|
// properties: {
|
|
78
82
|
// msgAtrrParam1: {
|
|
79
|
-
// type:
|
|
83
|
+
// type: 'string'
|
|
80
84
|
// },
|
|
81
85
|
// msgAtrrParam2: {
|
|
82
|
-
// type:
|
|
86
|
+
// type: 'object'
|
|
83
87
|
// }
|
|
84
88
|
// }
|
|
85
89
|
// };
|
|
@@ -113,6 +117,7 @@ export const main = middleware.wrap(async (event, context, callback) => {
|
|
|
113
117
|
passOnProperties.push(record.body.Message.comparison);
|
|
114
118
|
passOnProperties.push(record.body.Message.startKey);
|
|
115
119
|
passOnProperties.push(record.body.Message.overwriteUniqueRequestId);
|
|
120
|
+
passOnProperties.push(record.body.Message.overWriteCache);
|
|
116
121
|
passOnProperties.push(record.body.Message.callingFlow);
|
|
117
122
|
record._izContext.logger.debug(
|
|
118
123
|
'passOnProperties in handler',
|
|
@@ -38,6 +38,7 @@ const limit = 2;
|
|
|
38
38
|
* @param {string} comparison
|
|
39
39
|
* @param {Object} startKey
|
|
40
40
|
* @param {string} overwriteUniqueRequestId
|
|
41
|
+
* @param {boolean} overwriteCache
|
|
41
42
|
* @param {string} callingFlow
|
|
42
43
|
*
|
|
43
44
|
* @returns {string} description of return value
|
|
@@ -53,6 +54,7 @@ export default async function paginateProcessLogical(
|
|
|
53
54
|
comparison, // optional
|
|
54
55
|
startKey, // optional
|
|
55
56
|
overwriteUniqueRequestId, // optional
|
|
57
|
+
overWriteCache,
|
|
56
58
|
callingFlow // optional
|
|
57
59
|
) {
|
|
58
60
|
try {
|
|
@@ -65,6 +67,7 @@ export default async function paginateProcessLogical(
|
|
|
65
67
|
comparison: comparison,
|
|
66
68
|
startKey: startKey,
|
|
67
69
|
overwriteUniqueRequestId: overwriteUniqueRequestId,
|
|
70
|
+
overWriteCache: overWriteCache,
|
|
68
71
|
callingFlow: callingFlow
|
|
69
72
|
});
|
|
70
73
|
|
|
@@ -101,6 +104,7 @@ export default async function paginateProcessLogical(
|
|
|
101
104
|
logicalResultId,
|
|
102
105
|
logicalResultsMain.logicalElement,
|
|
103
106
|
logicalResultsMain.objType,
|
|
107
|
+
overWriteCache,
|
|
104
108
|
callingFlow,
|
|
105
109
|
'error'
|
|
106
110
|
];
|
|
@@ -247,9 +251,9 @@ export default async function paginateProcessLogical(
|
|
|
247
251
|
logicalResultId,
|
|
248
252
|
logicalResultsMain.logicalElement,
|
|
249
253
|
logicalResultsMain.objType,
|
|
254
|
+
overWriteCache,
|
|
250
255
|
callingFlow,
|
|
251
|
-
'complete'
|
|
252
|
-
[]
|
|
256
|
+
'complete'
|
|
253
257
|
);
|
|
254
258
|
}
|
|
255
259
|
|