@izara_project/izara-core-generate-service-code 1.0.6 → 1.0.7
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 +2 -1
- package/src/TemplateData/IntTest/generateTests/events/data.js +3 -3
- package/src/TemplateData/IntTest/generateTests/events/templateEvents.ejs +2 -2
- package/src/TemplateData/IntTest/generateTests/tests/data.js +6 -12
- package/src/TemplateData/flowSchema/generateTemplateData.js +8 -4
- package/src/TemplateData/flowSchema/triggerCacheComponent/triggerCacheComplete/functionYaml/dsq/data.js +134 -0
- package/src/TemplateData/flowSchema/triggerCacheComponent/triggerCacheComplete/functionYaml/{data.js → sqs/data.js} +3 -3
- package/src/TemplateData/flowSchema/triggerCacheComponent/triggerCacheComplete/functionYaml/sqs/template.ejs +21 -0
- package/src/TemplateData/flowSchema/triggerCacheComponent/triggerCacheComplete/handler/dsq/data.js +69 -0
- package/src/TemplateData/flowSchema/triggerCacheComponent/triggerCacheComplete/handler/dsq/template.ejs +104 -0
- package/src/TemplateData/flowSchema/triggerCacheComponent/triggerCacheComplete/handler/{data.js → sqs/data.js} +2 -2
- package/src/TemplateData/flowSchema/triggerCacheComponent/triggerCacheQueue/data.js +3 -0
- package/src/libs/Consts.js +3 -1
- /package/src/TemplateData/flowSchema/triggerCacheComponent/triggerCacheComplete/functionYaml/{template.ejs → dsq/template.ejs} +0 -0
- /package/src/TemplateData/flowSchema/triggerCacheComponent/triggerCacheComplete/handler/{template.ejs → sqs/template.ejs} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@izara_project/izara-core-generate-service-code",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "Code for locally generating per service files",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
"jest": {
|
|
20
20
|
"testEnvironment": "node"
|
|
21
21
|
},
|
|
22
|
+
"type": "module",
|
|
22
23
|
"dependencies": {
|
|
23
24
|
"@izara_project/izara-core-library-core": "^1.0.31",
|
|
24
25
|
"@izara_project/izara-core-library-service-schemas": "^1.0.108",
|
|
@@ -77,9 +77,9 @@ async function data(_izContext, allIntTestConfig, srcPath) {
|
|
|
77
77
|
// console.log("have dynamoConfig", inputEventTag, eachStage.dynamoDBConfig)
|
|
78
78
|
for (const dynamoDBConfig of eachStage.dynamoDBConfig) {
|
|
79
79
|
let eventDynamo = {
|
|
80
|
-
keyValues: dynamoDBConfig.dynamoEvent.identifiers,
|
|
81
80
|
forStageMatching: true,
|
|
82
|
-
|
|
81
|
+
keyValues: dynamoDBConfig.dynamoEvent.identifiers,
|
|
82
|
+
...setEvent(
|
|
83
83
|
dynamoDBConfig.dynamoEvent.fields,
|
|
84
84
|
dynamoDBConfig.dynamoEventSettings
|
|
85
85
|
)
|
|
@@ -137,7 +137,7 @@ async function data(_izContext, allIntTestConfig, srcPath) {
|
|
|
137
137
|
}
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
|
-
console.log("createEventSources", JSON.stringify(createEventSources, null, 2))
|
|
140
|
+
// console.log("createEventSources", JSON.stringify(createEventSources, null, 2))
|
|
141
141
|
return createEventSources;
|
|
142
142
|
}
|
|
143
143
|
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
"<%- inputEventTag %>": <%- JSON.stringify(inputConfig, null, 2) %>,
|
|
3
3
|
"<%- outputEventTag %>": <%- JSON.stringify(outputConfig, null, 2) %> <%- eventDynamos.length ? "," : "" -%>
|
|
4
4
|
<% eventDynamos.forEach((eventDynamo,idx) => { %>
|
|
5
|
-
"<%- eventDynamo.eventTag %>": <%- JSON.stringify(eventDynamo.event,null,2) %>
|
|
5
|
+
"<%- eventDynamo.eventTag %>": <%- JSON.stringify(eventDynamo.event,null,2) %> <%- idx < eventDynamos.length - 1 ? ",": "" -%>
|
|
6
6
|
<% }) %> <%- eventInvokes.length ? "," : "" -%>
|
|
7
7
|
<% eventInvokes.forEach((invokeEventComponent,index) => { %>
|
|
8
8
|
"<%- invokeEventComponent.inputInvokeName %>": <%- JSON.stringify(invokeEventComponent.inputInvoke,null,2) %>,
|
|
9
|
-
"<%- invokeEventComponent.outputInvokeName %>": <%- JSON.stringify(invokeEventComponent.outputInvoke,null,2)
|
|
9
|
+
"<%- invokeEventComponent.outputInvokeName %>": <%- JSON.stringify(invokeEventComponent.outputInvoke,null,2) %><%- index < eventInvokes.length - 1 ? ",": "" -%>
|
|
10
10
|
<% }) %>
|
|
11
11
|
}
|
|
@@ -60,11 +60,10 @@ async function data(_izContext, allIntTestConfig, srcPath) {
|
|
|
60
60
|
// 'testConfig.seedDataConfig[seedDataTag]',
|
|
61
61
|
// testConfig.seedDataConfig[seedDataTag]
|
|
62
62
|
// );
|
|
63
|
-
if (
|
|
64
|
-
testConfig.seedDataConfig.hasOwnProperty(seedDataTag) &&
|
|
65
|
-
testConfig.seedDataConfig[seedDataTag].length > 0
|
|
66
|
-
) {
|
|
63
|
+
if (testConfig.seedDataConfig.hasOwnProperty(seedDataTag) && testConfig.seedDataConfig[seedDataTag].length > 0) {
|
|
67
64
|
baseIntTest[seedDataTag] = testConfig.seedDataConfig[seedDataTag];
|
|
65
|
+
} else {
|
|
66
|
+
baseIntTest[seedDataTag] = [];
|
|
68
67
|
}
|
|
69
68
|
}
|
|
70
69
|
}
|
|
@@ -163,16 +162,11 @@ async function data(_izContext, allIntTestConfig, srcPath) {
|
|
|
163
162
|
}
|
|
164
163
|
|
|
165
164
|
// generatedSeedData
|
|
166
|
-
if (
|
|
167
|
-
|
|
168
|
-
Object.keys(stage.generatedSeedData).length > 0
|
|
169
|
-
) {
|
|
170
|
-
for (const generateSeedType of Object.values(
|
|
171
|
-
GENERATE_SEED_DATA_TYPE
|
|
172
|
-
)) {
|
|
165
|
+
if (stage.generatedSeedData && Object.keys(stage.generatedSeedData).length > 0) {
|
|
166
|
+
for (const generateSeedType of Object.values(GENERATE_SEED_DATA_TYPE)) {
|
|
173
167
|
if (stage.generatedSeedData.hasOwnProperty(generateSeedType)) {
|
|
174
168
|
// baseIntTest.stage[currentStageIdx]["generateSeedDatas"] = {
|
|
175
|
-
stages[currentStageIdx]['
|
|
169
|
+
stages[currentStageIdx]['generateSeedData'] = {
|
|
176
170
|
[generateSeedType]: [...stage.generatedSeedData[generateSeedType]]
|
|
177
171
|
};
|
|
178
172
|
}
|
|
@@ -133,21 +133,25 @@ import createFlowSchemaRegisterDynamoDb from './register/dynamoDB/register.js';
|
|
|
133
133
|
|
|
134
134
|
import createProcessTriggerCacheYaml from './triggerCacheComponent/processTriggerCache/functionYaml/data.js';
|
|
135
135
|
import createCheckTriggerCacheYaml from './triggerCacheComponent/checkTriggerCacheComplete/functionYaml/data.js';
|
|
136
|
-
import
|
|
136
|
+
import createTriggerCacheCompleteYamlSqs from './triggerCacheComponent/triggerCacheComplete/functionYaml/sqs/data.js';
|
|
137
|
+
import createTriggerCacheCompleteYamlDsq from './triggerCacheComponent/triggerCacheComplete/functionYaml/dsq/data.js';
|
|
137
138
|
const createFlowSchemaTriggerCacheFunctionYaml = {
|
|
138
139
|
createProcessTriggerCacheYaml,
|
|
139
140
|
createCheckTriggerCacheYaml,
|
|
140
|
-
|
|
141
|
+
createTriggerCacheCompleteYamlSqs,
|
|
142
|
+
createTriggerCacheCompleteYamlDsq
|
|
141
143
|
};
|
|
142
144
|
|
|
143
145
|
import createProcessTriggerCacheHandler from './triggerCacheComponent/processTriggerCache/handler/data.js';
|
|
144
146
|
import createCheckTriggerCacheHandler from './triggerCacheComponent/checkTriggerCacheComplete/handler/data.js';
|
|
145
|
-
import
|
|
147
|
+
import createTriggerCacheCompleteHandlerSqs from './triggerCacheComponent/triggerCacheComplete/handler/sqs/data.js';
|
|
148
|
+
import createTriggerCacheCompleteHandlerDsq from './triggerCacheComponent/triggerCacheComplete/handler/dsq/data.js';
|
|
146
149
|
|
|
147
150
|
const createFlowSchemaTriggerCacheHandler = {
|
|
148
151
|
createProcessTriggerCacheHandler,
|
|
149
152
|
createCheckTriggerCacheHandler,
|
|
150
|
-
|
|
153
|
+
createTriggerCacheCompleteHandlerSqs,
|
|
154
|
+
createTriggerCacheCompleteHandlerDsq
|
|
151
155
|
};
|
|
152
156
|
|
|
153
157
|
import createProcessTriggerCacheMainFunction from './triggerCacheComponent/processTriggerCache/mainFunction/data.js';
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2020 Sven Mason <http://izara.io>
|
|
3
|
+
|
|
4
|
+
This program is free software: you can redistribute it and/or modify
|
|
5
|
+
it under the terms of the GNU Affero General Public License as
|
|
6
|
+
published by the Free Software Foundation, either version 3 of the
|
|
7
|
+
License, or (at your option) any later version.
|
|
8
|
+
|
|
9
|
+
This program is distributed in the hope that it will be useful,
|
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
GNU Affero General Public License for more details.
|
|
13
|
+
|
|
14
|
+
You should have received a copy of the GNU Affero General Public License
|
|
15
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import path from 'path';
|
|
19
|
+
import { fileURLToPath } from 'url';
|
|
20
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
21
|
+
const __dirname = path.dirname(__filename);
|
|
22
|
+
import { NoRetryError } from '@izara_project/izara-core-library-core';
|
|
23
|
+
import { getObjectSchema } from '@izara_project/izara-core-library-service-schemas';
|
|
24
|
+
import consts from '../../../../../../libs/Consts.js';
|
|
25
|
+
import utils from '../../../../../../libs/Utils.js';
|
|
26
|
+
import libs from '../../../../../../libs/Libs.js';
|
|
27
|
+
|
|
28
|
+
const {
|
|
29
|
+
SOURCE_PATH,
|
|
30
|
+
SAVE_FILE_NAME,
|
|
31
|
+
HANDLER,
|
|
32
|
+
RESOURCE_CLASSES,
|
|
33
|
+
SQS_RESOURCE,
|
|
34
|
+
DYNAMO_RESOURCE,
|
|
35
|
+
STORAGE_TYPES
|
|
36
|
+
} = consts;
|
|
37
|
+
const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = utils;
|
|
38
|
+
const {
|
|
39
|
+
awaitingMultipleStepsRole,
|
|
40
|
+
resourceNames,
|
|
41
|
+
defaultIamRolePerAction,
|
|
42
|
+
createIamRole,
|
|
43
|
+
shortNameHandler
|
|
44
|
+
} = libs;
|
|
45
|
+
const templatePath = path.join(__dirname, './template.ejs');
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* receive objectSchema
|
|
49
|
+
*
|
|
50
|
+
* @param {Object} objectSchema
|
|
51
|
+
* @return {{templatePath, templateData,setting}}
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
async function data(_izContext, flowSchema, srcPath) {
|
|
55
|
+
return [await createSourceParams(_izContext, flowSchema, srcPath)];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async function createSourceParams(_izContext, flowSchema, srcPath) {
|
|
59
|
+
let functionName =
|
|
60
|
+
'TriggerCache' + upperCase(flowSchema.flowTag) + 'Complete';
|
|
61
|
+
let handlerType = upperCase(HANDLER.hdrDsq);
|
|
62
|
+
let additionalResourcePermission = defaultIamRolePerAction();
|
|
63
|
+
let queueName =
|
|
64
|
+
'TriggerCache' + upperCase(flowSchema.flowTag) + 'Complete' + handlerType;
|
|
65
|
+
|
|
66
|
+
additionalResourcePermission.push(
|
|
67
|
+
createIamRole(
|
|
68
|
+
{
|
|
69
|
+
[RESOURCE_CLASSES.sqs]: Object.values(SQS_RESOURCE)
|
|
70
|
+
},
|
|
71
|
+
[
|
|
72
|
+
resourceNames(RESOURCE_CLASSES.sqs, queueName),
|
|
73
|
+
resourceNames(RESOURCE_CLASSES.sqs, queueName + 'DLQ')
|
|
74
|
+
]
|
|
75
|
+
)
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
let tableTriggerCache = new Set();
|
|
79
|
+
let objectSchema = await getObjectSchema
|
|
80
|
+
.getLocalObjectSchemas(
|
|
81
|
+
_izContext,
|
|
82
|
+
[flowSchema.objType.objectType],
|
|
83
|
+
path.join(srcPath, './schemas')
|
|
84
|
+
)
|
|
85
|
+
.then(res => res.records[0]);
|
|
86
|
+
if (!objectSchema) {
|
|
87
|
+
throw new NoRetryError('ObjectSchema not found');
|
|
88
|
+
}
|
|
89
|
+
for (const storageResource of Object.values(objectSchema.storageResources)) {
|
|
90
|
+
if (storageResource.storageType === STORAGE_TYPES.dynamoDB) {
|
|
91
|
+
if (!tableTriggerCache.has(storageResource.tableName)) {
|
|
92
|
+
tableTriggerCache.add(storageResource.tableName);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
additionalResourcePermission.push(
|
|
98
|
+
createIamRole(
|
|
99
|
+
{
|
|
100
|
+
[RESOURCE_CLASSES.dynamoDbTable]: Object.values(DYNAMO_RESOURCE)
|
|
101
|
+
},
|
|
102
|
+
[...tableTriggerCache].map(tableName =>
|
|
103
|
+
resourceNames(RESOURCE_CLASSES.dynamoDbTable, tableName)
|
|
104
|
+
)
|
|
105
|
+
)
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
additionalResourcePermission.push(awaitingMultipleStepsRole());
|
|
109
|
+
return {
|
|
110
|
+
templatePath: templatePath,
|
|
111
|
+
templateData: {
|
|
112
|
+
resourceLocation: path.join(
|
|
113
|
+
SOURCE_PATH.resourceLocationFlowSchema,
|
|
114
|
+
upperCase(flowSchema.flowTag),
|
|
115
|
+
'source/'
|
|
116
|
+
),
|
|
117
|
+
functionName,
|
|
118
|
+
handlerType,
|
|
119
|
+
additionalResourcePermission,
|
|
120
|
+
functionNameConfig:
|
|
121
|
+
upperCase(functionName) + upperCase(shortNameHandler(handlerType)),
|
|
122
|
+
roleName: upperCase(flowSchema.flowTag),
|
|
123
|
+
queueName
|
|
124
|
+
},
|
|
125
|
+
setting: {
|
|
126
|
+
savePath: path.join(srcPath, SOURCE_PATH.appYaml),
|
|
127
|
+
saveFileName: upperCase(SAVE_FILE_NAME.flowSchema),
|
|
128
|
+
fileExtension: '.yml',
|
|
129
|
+
isAppend: true
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export default data;
|
|
@@ -21,9 +21,9 @@ const __filename = fileURLToPath(import.meta.url);
|
|
|
21
21
|
const __dirname = path.dirname(__filename);
|
|
22
22
|
import { NoRetryError } from '@izara_project/izara-core-library-core';
|
|
23
23
|
import { getObjectSchema } from '@izara_project/izara-core-library-service-schemas';
|
|
24
|
-
import consts from '
|
|
25
|
-
import utils from '
|
|
26
|
-
import libs from '
|
|
24
|
+
import consts from '../../../../../../libs/Consts.js';
|
|
25
|
+
import utils from '../../../../../../libs/Utils.js';
|
|
26
|
+
import libs from '../../../../../../libs/Libs.js';
|
|
27
27
|
|
|
28
28
|
const {
|
|
29
29
|
SOURCE_PATH,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
<%_ const join = require('path').join; _%>
|
|
2
|
+
<%- firstLetterUpperCase(functionNameConfig) %>:
|
|
3
|
+
handler: <%- join(resourceLocation, `${firstLetterUpperCase(functionName)}_${firstLetterUpperCase(handlerType)}.main`)%>
|
|
4
|
+
name: ${self:custom.iz_resourcePrefix}<%- firstLetterUpperCase(functionName) %><%- firstLetterUpperCase(handlerType) %>
|
|
5
|
+
role: <%- roleName %>Role
|
|
6
|
+
#<#<%- functionName %><%- handlerType %>FunctionSetting#>
|
|
7
|
+
#<#/<%- functionName %><%- handlerType %>FunctionSetting#>
|
|
8
|
+
events:
|
|
9
|
+
- sqs:
|
|
10
|
+
arn: arn:aws:sqs:${self:custom.iz_region}:${self:custom.iz_accountId}:${self:custom.iz_resourcePrefix}<%- queueName %>
|
|
11
|
+
batchSize: 10
|
|
12
|
+
filterPatterns: #**** need to update serverless framework upper v.2.69.1
|
|
13
|
+
- body: {"MessageAttributes":{"callingFlow":{"Value":["${self:custom.iz_resourcePrefix}<%- functionName %>"]}}} # functionName of callingFlow
|
|
14
|
+
- body: {"MessageAttributes":{"callingFlow":{"Value":[{"exists":false}]}}}
|
|
15
|
+
|
|
16
|
+
<%_ function firstLetterUpperCase(text){
|
|
17
|
+
return text.charAt(0).toUpperCase() + text.slice(1)
|
|
18
|
+
} _%>
|
|
19
|
+
<%_ function firstLetterLowerCase(str) {
|
|
20
|
+
return str.charAt(0).toLowerCase() + str.slice(1)
|
|
21
|
+
} _%>
|
package/src/TemplateData/flowSchema/triggerCacheComponent/triggerCacheComplete/handler/dsq/data.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2020 Sven Mason <http://izara.io>
|
|
3
|
+
|
|
4
|
+
This program is free software: you can redistribute it and/or modify
|
|
5
|
+
it under the terms of the GNU Affero General Public License as
|
|
6
|
+
published by the Free Software Foundation, either version 3 of the
|
|
7
|
+
License, or (at your option) any later version.
|
|
8
|
+
|
|
9
|
+
This program is distributed in the hope that it will be useful,
|
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
GNU Affero General Public License for more details.
|
|
13
|
+
|
|
14
|
+
You should have received a copy of the GNU Affero General Public License
|
|
15
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import path from 'path';
|
|
19
|
+
import { fileURLToPath } from 'url';
|
|
20
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
21
|
+
const __dirname = path.dirname(__filename);
|
|
22
|
+
import consts from '../../../../../../libs/Consts.js';
|
|
23
|
+
import utils from '../../../../../../libs/Utils.js';
|
|
24
|
+
const { SOURCE_PATH, HANDLER } = consts;
|
|
25
|
+
const {
|
|
26
|
+
firstLetterLowerCase: lowerCase,
|
|
27
|
+
firstLetterUpperCase: upperCase,
|
|
28
|
+
getLocalConfig
|
|
29
|
+
} = utils;
|
|
30
|
+
const templatePath = path.join(__dirname, 'template.ejs');
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* receive objectSchema
|
|
34
|
+
*
|
|
35
|
+
* @param {Object} objectSchema
|
|
36
|
+
* @return {{templatePath, templateData,setting}}
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
function data(_izContext, flowSchema, srcPath) {
|
|
40
|
+
return [createSourceParams(_izContext, flowSchema, srcPath)];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function createSourceParams(_izContext, flowSchema, srcPath) {
|
|
44
|
+
let functionName =
|
|
45
|
+
'TriggerCache' + upperCase(flowSchema.flowTag) + 'Complete';
|
|
46
|
+
let handlerType = upperCase(HANDLER.hdrDsq);
|
|
47
|
+
let queueName = 'TriggerCache' + upperCase(flowSchema.flowTag) + 'Complete' + handlerType;
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
templatePath: templatePath,
|
|
51
|
+
templateData: {
|
|
52
|
+
functionName,
|
|
53
|
+
queueName
|
|
54
|
+
},
|
|
55
|
+
setting: {
|
|
56
|
+
savePath: path.join(
|
|
57
|
+
srcPath,
|
|
58
|
+
SOURCE_PATH.flowSchema,
|
|
59
|
+
upperCase(flowSchema.flowTag),
|
|
60
|
+
'source/'
|
|
61
|
+
),
|
|
62
|
+
saveFileName: `${upperCase(functionName)}_${upperCase(handlerType)}`,
|
|
63
|
+
fileExtension: '.js',
|
|
64
|
+
isAppend: true
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export default data;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2020 Sven Mason <http://izara.io>
|
|
3
|
+
|
|
4
|
+
This program is free software: you can redistribute it and/or modify
|
|
5
|
+
it under the terms of the GNU Affero General Public License as
|
|
6
|
+
published by the Free Software Foundation, either version 3 of the
|
|
7
|
+
License, or (at your option) any later version.
|
|
8
|
+
|
|
9
|
+
This program is distributed in the hope that it will be useful,
|
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
GNU Affero General Public License for more details.
|
|
13
|
+
|
|
14
|
+
You should have received a copy of the GNU Affero General Public License
|
|
15
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
import { middlewareHandler as middleware } from "@izara_project/izara-middleware";
|
|
21
|
+
import Logger from '@izara_project/izara-core-library-logger';
|
|
22
|
+
import { recordHandlerSharedLib } from "@izara_project/izara-core-library-record-handler";
|
|
23
|
+
import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
|
|
24
|
+
|
|
25
|
+
import <%- functionName %> from './<%- functionName %>_Main.js';
|
|
26
|
+
|
|
27
|
+
// validate event properties in body.Message of sqs event
|
|
28
|
+
let perRecordsValidatorSchema = {
|
|
29
|
+
//(<validatorSchema>)
|
|
30
|
+
//(</validatorSchema>)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
middleware.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema(
|
|
34
|
+
{
|
|
35
|
+
type: "object",
|
|
36
|
+
required: ['body', 'messageAttributes'],
|
|
37
|
+
properties: {
|
|
38
|
+
body: {
|
|
39
|
+
type: 'object',
|
|
40
|
+
},
|
|
41
|
+
messageAttributes: {
|
|
42
|
+
type: 'object'
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}));
|
|
46
|
+
|
|
47
|
+
middleware.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema());
|
|
48
|
+
|
|
49
|
+
export const main = middleware.wrap(async (event, context, callback) => {
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
|
|
53
|
+
let recordPromises = [];
|
|
54
|
+
|
|
55
|
+
// loop each record and send to mainFunction
|
|
56
|
+
await Promise.all(event.Records.map(async record => { // promise.all for map() function
|
|
57
|
+
|
|
58
|
+
let passOnProperties = []
|
|
59
|
+
record = recordHandlerSharedLib.reformatDsqMessage(record._izContext, record);
|
|
60
|
+
record._izContext.logger.debug('record ReceiveMsgOutHdrSqs', record);
|
|
61
|
+
|
|
62
|
+
//validate message (and MessageAttributes)
|
|
63
|
+
await recordHandlerSharedLib.validateRecord(
|
|
64
|
+
record, // one record will send to mainFunction
|
|
65
|
+
"<%- queueName %>", // queue name that need to retry or send to dlq
|
|
66
|
+
perRecordsValidatorSchema, // schema for record.Message
|
|
67
|
+
// messageAttributeValidatorSchema // ----- for msgAttr default is null -> do not send this parameter if not want to validate msgAtt
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
// add argument (to invoke lambda) to passOnProperties[]
|
|
71
|
+
passOnProperties.push(record.body.Message)
|
|
72
|
+
//(<additionalParams>)
|
|
73
|
+
//(</additionalParams>)
|
|
74
|
+
passOnProperties.push(callingFlowSharedLib.addCallingFlowToPassOnProperties(record.body.Message));
|
|
75
|
+
record._izContext.logger.debug('passOnProperties in handler', passOnProperties);
|
|
76
|
+
|
|
77
|
+
// call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
|
|
78
|
+
let recordPromise = recordHandlerSharedLib.recordHandler(
|
|
79
|
+
record, // one record will send to mainFunction
|
|
80
|
+
<%- functionName %>, // mainFunction that need to invoke.
|
|
81
|
+
"<%- queueName %>", // queue name that need to retry or send to dlq
|
|
82
|
+
passOnProperties, // all parameters that mainFunction needed.
|
|
83
|
+
);
|
|
84
|
+
record._izContext.logger.debug('after recordPromise in handler');
|
|
85
|
+
recordPromises.push(recordPromise); // push promise to recordPromises
|
|
86
|
+
}))
|
|
87
|
+
|
|
88
|
+
Logger.debug('before Promise.all(recordPromises) in handler');
|
|
89
|
+
try {
|
|
90
|
+
// --- main await all promises
|
|
91
|
+
await Promise.all(recordPromises); // await all promises
|
|
92
|
+
|
|
93
|
+
return event.Records // return all for local testing
|
|
94
|
+
|
|
95
|
+
} catch {
|
|
96
|
+
Logger.debug('Promise.all(recordPromises) in handler threw error (at least one record did no resolve)');
|
|
97
|
+
}
|
|
98
|
+
Logger.debug('after Promise.all(recordPromises) in handler');
|
|
99
|
+
|
|
100
|
+
} catch (err) {
|
|
101
|
+
Logger.error('Unhandled Error, LambdaFunctionHdrSqs: ', err);
|
|
102
|
+
throw (err);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
@@ -19,8 +19,8 @@ import path from 'path';
|
|
|
19
19
|
import { fileURLToPath } from 'url';
|
|
20
20
|
const __filename = fileURLToPath(import.meta.url);
|
|
21
21
|
const __dirname = path.dirname(__filename);
|
|
22
|
-
import consts from '
|
|
23
|
-
import utils from '
|
|
22
|
+
import consts from '../../../../../../libs/Consts.js';
|
|
23
|
+
import utils from '../../../../../../libs/Utils.js';
|
|
24
24
|
const { SOURCE_PATH, HANDLER } = consts;
|
|
25
25
|
const {
|
|
26
26
|
firstLetterLowerCase: lowerCase,
|
|
@@ -66,6 +66,9 @@ function createDataForDefaultSnsInSqs(_izContext, flowSchema, srcPath) {
|
|
|
66
66
|
},
|
|
67
67
|
{
|
|
68
68
|
queueName: 'TriggerCache' + upperCase(flowTag) + 'Complete' + upperCase(HANDLER.hdrSqs)
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
queueName: 'TriggerCache' + upperCase(flowTag) + 'Complete' + upperCase(HANDLER.hdrDsq)
|
|
69
72
|
}
|
|
70
73
|
];
|
|
71
74
|
|
package/src/libs/Consts.js
CHANGED
|
@@ -275,7 +275,9 @@ const GENERATE_SEED_DATA_TYPE = {
|
|
|
275
275
|
|
|
276
276
|
const SEED_DATA_TAG = {
|
|
277
277
|
dynamoDBSeedDataTags: "dynamoDBSeedDataTags",
|
|
278
|
-
graphSeedDataTags: "graphSeedDataTags"
|
|
278
|
+
graphSeedDataTags: "graphSeedDataTags",
|
|
279
|
+
cleaningeDynamoOneRecordsTags: "cleaningeDynamoOneRecordsTags",
|
|
280
|
+
cleaningeDynamoManyRecordsTags: "cleaningeDynamoManyRecordsTags"
|
|
279
281
|
}
|
|
280
282
|
|
|
281
283
|
const DEFAULT_LAMBDA_ROLE_PER_ACTION = {
|
|
File without changes
|