@izara_project/izara-core-generate-service-code 1.0.16 → 1.0.17
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/processLogicalPagination/mainFunction/template.ejs +65 -115
- package/src/TemplateData/relationshipPerAction/delete/action/handler/templateByHandler/sqsTemplate.ejs +79 -67
- package/src/TemplateData/relationshipPerAction/update/action/handler/templateByHandler/sqsTemplate.ejs +81 -60
package/package.json
CHANGED
|
@@ -20,9 +20,13 @@ import sqsSharedLib from '@izara_project/izara-core-library-sqs';
|
|
|
20
20
|
import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
|
|
21
21
|
import asyncFlowSharedLib from '@izara_project/izara-core-library-asynchronous-flow';
|
|
22
22
|
|
|
23
|
-
import {
|
|
23
|
+
import {
|
|
24
|
+
sqs
|
|
25
|
+
} from '@izara_project/izara-core-library-external-request';
|
|
24
26
|
|
|
25
|
-
import {
|
|
27
|
+
import {
|
|
28
|
+
NoRetryError
|
|
29
|
+
} from '@izara_project/izara-core-library-core';
|
|
26
30
|
|
|
27
31
|
// set query limit
|
|
28
32
|
const limit = 2;
|
|
@@ -34,11 +38,9 @@ const limit = 2;
|
|
|
34
38
|
* @param {string} tableName
|
|
35
39
|
* @param {string} partitionKeyFieldName
|
|
36
40
|
* @param {string} sortKeyFieldName
|
|
37
|
-
* @param {Object} dynamoDbIdentifiers
|
|
38
41
|
* @param {string} comparison
|
|
39
42
|
* @param {Object} startKey
|
|
40
43
|
* @param {string} overwriteUniqueRequestId
|
|
41
|
-
* @param {boolean} overwriteCache
|
|
42
44
|
* @param {string} callingFlow
|
|
43
45
|
*
|
|
44
46
|
* @returns {string} description of return value
|
|
@@ -50,52 +52,46 @@ export default async function paginateProcessLogical(
|
|
|
50
52
|
tableName,
|
|
51
53
|
partitionKeyFieldName,
|
|
52
54
|
sortKeyFieldName,
|
|
53
|
-
dynamoDbIdentifiers,
|
|
54
55
|
comparison, // optional
|
|
55
56
|
startKey, // optional
|
|
56
57
|
overwriteUniqueRequestId, // optional
|
|
57
|
-
overWriteCache,
|
|
58
58
|
callingFlow // optional
|
|
59
59
|
) {
|
|
60
|
+
|
|
60
61
|
try {
|
|
61
|
-
|
|
62
|
+
|
|
63
|
+
_izContext.logger.debug(
|
|
64
|
+
'----- PaginateProcessLogical event params -----', {
|
|
62
65
|
logicalResultId: logicalResultId,
|
|
63
66
|
tableName: tableName,
|
|
64
67
|
partitionKeyFieldName: partitionKeyFieldName,
|
|
65
68
|
sortKeyFieldName: sortKeyFieldName,
|
|
66
|
-
dynamoDbIdentifiers: dynamoDbIdentifiers,
|
|
67
69
|
comparison: comparison,
|
|
68
70
|
startKey: startKey,
|
|
69
71
|
overwriteUniqueRequestId: overwriteUniqueRequestId,
|
|
70
|
-
overWriteCache: overWriteCache,
|
|
71
72
|
callingFlow: callingFlow
|
|
72
73
|
});
|
|
73
74
|
|
|
74
75
|
// Check/Create logicalResultsMain
|
|
75
76
|
let [checkUniqueRequestProcessingStatus, logicalResultsMain] =
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
_izContext.logger.debug('After check uniqueRequestProcessingStatus:', {
|
|
77
|
+
await asyncFlowSharedLib.checkUniqueRequestProcessing(
|
|
78
|
+
_izContext,
|
|
79
|
+
"LogicalResultsMain", {
|
|
80
|
+
logicalResultId: logicalResultId
|
|
81
|
+
},
|
|
82
|
+
"paginateProcessLogical",
|
|
83
|
+
overwriteUniqueRequestId
|
|
84
|
+
);
|
|
85
|
+
_izContext.logger.debug("After check uniqueRequestProcessingStatus:", {
|
|
86
86
|
checkUniqueRequestProcessingStatus: checkUniqueRequestProcessingStatus,
|
|
87
87
|
logicalResultsMain: logicalResultsMain
|
|
88
88
|
});
|
|
89
89
|
|
|
90
|
-
if (checkUniqueRequestProcessingStatus ==
|
|
91
|
-
return
|
|
92
|
-
|
|
93
|
-
};
|
|
94
|
-
} else if (checkUniqueRequestProcessingStatus == 'recordNotFound') {
|
|
90
|
+
if (checkUniqueRequestProcessingStatus == "stop") {
|
|
91
|
+
return;
|
|
92
|
+
} else if (checkUniqueRequestProcessingStatus == "recordNotFound") {
|
|
95
93
|
// should always have unless another request already completed it, in which case nothing to do
|
|
96
|
-
return
|
|
97
|
-
returnResponse: 'record not found'
|
|
98
|
-
};
|
|
94
|
+
return;
|
|
99
95
|
}
|
|
100
96
|
|
|
101
97
|
let errorsFound = [];
|
|
@@ -104,11 +100,11 @@ export default async function paginateProcessLogical(
|
|
|
104
100
|
logicalResultId,
|
|
105
101
|
logicalResultsMain.logicalElement,
|
|
106
102
|
logicalResultsMain.objType,
|
|
107
|
-
overWriteCache,
|
|
108
103
|
callingFlow,
|
|
109
|
-
|
|
104
|
+
"error"
|
|
110
105
|
];
|
|
111
106
|
|
|
107
|
+
const partitionKeyValue = logicalResultsMain.logicalElement.partitionKey;
|
|
112
108
|
let queryElements = {
|
|
113
109
|
limit: limit
|
|
114
110
|
};
|
|
@@ -122,101 +118,60 @@ export default async function paginateProcessLogical(
|
|
|
122
118
|
);
|
|
123
119
|
|
|
124
120
|
if (startKey === false) {
|
|
125
|
-
throw new NoRetryError(
|
|
121
|
+
throw new NoRetryError("split processing received invalid startKey");
|
|
126
122
|
}
|
|
127
|
-
_izContext.logger.debug(
|
|
123
|
+
_izContext.logger.debug("startKey :", startKey);
|
|
128
124
|
|
|
129
125
|
if (startKey) {
|
|
130
|
-
queryElements[
|
|
126
|
+
queryElements["exclusiveStartKey"] = {
|
|
131
127
|
[partitionKeyFieldName]: startKey[partitionKeyFieldName],
|
|
132
128
|
[sortKeyFieldName]: startKey[sortKeyFieldName]
|
|
133
|
-
}
|
|
134
|
-
}
|
|
129
|
+
}
|
|
130
|
+
};
|
|
135
131
|
|
|
136
132
|
if (comparison) {
|
|
137
|
-
|
|
133
|
+
const sortKeyValue = logicalResultsMain.logicalElement.sortKey;
|
|
134
|
+
|
|
135
|
+
queryElements["sortKeyCondition"] = {
|
|
138
136
|
comparison: comparison,
|
|
139
137
|
name: sortKeyFieldName,
|
|
140
|
-
value:
|
|
138
|
+
value: sortKeyValue
|
|
141
139
|
};
|
|
142
140
|
}
|
|
143
141
|
|
|
144
142
|
let queryDatas = await dynamodbSharedLib.query(
|
|
145
143
|
_izContext,
|
|
146
|
-
await dynamodbSharedLib.tableName(_izContext, tableName),
|
|
147
|
-
|
|
148
|
-
[partitionKeyFieldName]: dynamoDbIdentifiers[partitionKeyFieldName]
|
|
144
|
+
await dynamodbSharedLib.tableName(_izContext, tableName), {
|
|
145
|
+
[partitionKeyFieldName]: partitionKeyValue
|
|
149
146
|
},
|
|
150
147
|
queryElements
|
|
151
|
-
)
|
|
152
|
-
_izContext.logger.debug(
|
|
148
|
+
)
|
|
149
|
+
_izContext.logger.debug("queryDatas result: ", queryDatas)
|
|
153
150
|
|
|
154
151
|
if (!startKey && queryDatas.Items.length == 0) {
|
|
155
|
-
_izContext.logger.debug(`can't find data in table ${tableName}`)
|
|
156
|
-
errorsFound.push(`can't find data in table ${tableName}`)
|
|
157
|
-
standardErrorParams.push(errorsFound)
|
|
158
|
-
await logicalResultsSharedLib.completeLogicalResultsMain(
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
return {
|
|
162
|
-
returnResponse: 'Cannot find data in table'
|
|
163
|
-
};
|
|
152
|
+
_izContext.logger.debug(`can't find data in table ${tableName}`)
|
|
153
|
+
errorsFound.push(`can't find data in table ${tableName}`)
|
|
154
|
+
standardErrorParams.push(errorsFound)
|
|
155
|
+
await logicalResultsSharedLib.completeLogicalResultsMain(...
|
|
156
|
+
standardErrorParams);
|
|
157
|
+
return;
|
|
164
158
|
}
|
|
165
159
|
|
|
166
|
-
|
|
167
|
-
let objInstanceBases = queryDatas.Items;
|
|
168
|
-
const conditionalFieldValues =
|
|
169
|
-
logicalResultsMain.logicalElement.conditionalFieldValues;
|
|
170
|
-
|
|
171
|
-
if (
|
|
172
|
-
Array.isArray(conditionalFieldValues) &&
|
|
173
|
-
conditionalFieldValues.length > 0
|
|
174
|
-
) {
|
|
175
|
-
for (const conditionalFieldValue of conditionalFieldValues) {
|
|
176
|
-
_izContext.logger.debug(
|
|
177
|
-
'conditionalFieldValue: ',
|
|
178
|
-
conditionalFieldValue
|
|
179
|
-
);
|
|
180
|
-
|
|
181
|
-
let conditionalFieldName = conditionalFieldValue.fieldName;
|
|
182
|
-
|
|
183
|
-
if (conditionalFieldValue.hasOwnProperty('includeValues')) {
|
|
184
|
-
let includeValues = conditionalFieldValue.includeValues; // array
|
|
185
|
-
|
|
186
|
-
objInstanceBases = objInstanceBases.filter(objInstanceBase => {
|
|
187
|
-
return includeValues.includes(
|
|
188
|
-
objInstanceBase[conditionalFieldName]
|
|
189
|
-
);
|
|
190
|
-
});
|
|
191
|
-
} else if (conditionalFieldValue.hasOwnProperty('excludeValues')) {
|
|
192
|
-
let excludeValues = conditionalFieldValue.excludeValues; // array
|
|
193
|
-
|
|
194
|
-
objInstanceBases = objInstanceBases.filter(objInstanceBase => {
|
|
195
|
-
return !excludeValues.includes(
|
|
196
|
-
objInstanceBase[conditionalFieldName]
|
|
197
|
-
);
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
_izContext.logger.debug(
|
|
202
|
-
'objInstanceBases after conditionalFieldValues: ',
|
|
203
|
-
objInstanceBases
|
|
204
|
-
);
|
|
205
|
-
}
|
|
160
|
+
for (const objInstanceBase of queryDatas.Items) {
|
|
206
161
|
|
|
207
|
-
for (const objInstanceBase of objInstanceBases) {
|
|
208
162
|
await logicalResultsSharedLib.saveLogicalData(
|
|
209
163
|
_izContext,
|
|
210
164
|
logicalResultId,
|
|
211
165
|
logicalResultsMain.objType,
|
|
212
166
|
objInstanceBase
|
|
213
|
-
)
|
|
167
|
+
)
|
|
214
168
|
}
|
|
215
169
|
|
|
216
|
-
if (queryDatas.hasOwnProperty(
|
|
170
|
+
if (queryDatas.hasOwnProperty("LastEvaluatedKey")) {
|
|
171
|
+
|
|
217
172
|
if (!overwriteUniqueRequestId) {
|
|
218
|
-
overwriteUniqueRequestId = _izContext.uniqueRequestId
|
|
219
|
-
}
|
|
173
|
+
overwriteUniqueRequestId = _izContext.uniqueRequestId
|
|
174
|
+
};
|
|
220
175
|
|
|
221
176
|
let continuePaginationMsg = {
|
|
222
177
|
MessageBody: JSON.stringify({
|
|
@@ -224,44 +179,39 @@ export default async function paginateProcessLogical(
|
|
|
224
179
|
tableName: tableName,
|
|
225
180
|
partitionKeyFieldName: partitionKeyFieldName,
|
|
226
181
|
sortKeyFieldName: sortKeyFieldName,
|
|
227
|
-
dynamoDbIdentifiers: dynamoDbIdentifiers,
|
|
228
182
|
comparison: comparison,
|
|
229
183
|
overwriteUniqueRequestId: overwriteUniqueRequestId,
|
|
230
184
|
startKey: queryDatas.LastEvaluatedKey,
|
|
185
|
+
overWriteCache: overWriteCache,
|
|
231
186
|
callingFlow: callingFlow
|
|
232
187
|
}),
|
|
233
|
-
QueueUrl: await sqsSharedLib.sqsQueueUrl(
|
|
234
|
-
|
|
235
|
-
'PaginateProcessLogicalHdrDsq'
|
|
236
|
-
)
|
|
188
|
+
QueueUrl: await sqsSharedLib.sqsQueueUrl(_izContext,
|
|
189
|
+
"PaginateProcessLogicalHdrDsq"),
|
|
237
190
|
};
|
|
238
191
|
|
|
239
|
-
_izContext.logger.debug(
|
|
240
|
-
|
|
241
|
-
continuePaginationMsg
|
|
242
|
-
);
|
|
192
|
+
_izContext.logger.debug("continuePaginationMessage: ",
|
|
193
|
+
continuePaginationMsg);
|
|
243
194
|
await sqs.sendMessage(_izContext, continuePaginationMsg);
|
|
244
195
|
|
|
245
|
-
return
|
|
246
|
-
|
|
247
|
-
};
|
|
196
|
+
return "Continue PaginateProcessLogical"
|
|
197
|
+
|
|
248
198
|
} else {
|
|
199
|
+
|
|
249
200
|
await logicalResultsSharedLib.completeLogicalResultsMain(
|
|
250
201
|
_izContext,
|
|
251
202
|
logicalResultId,
|
|
252
203
|
logicalResultsMain.logicalElement,
|
|
253
204
|
logicalResultsMain.objType,
|
|
254
|
-
overWriteCache,
|
|
255
205
|
callingFlow,
|
|
256
|
-
|
|
257
|
-
|
|
206
|
+
"complete",
|
|
207
|
+
[],
|
|
208
|
+
)
|
|
258
209
|
}
|
|
259
210
|
|
|
260
|
-
return
|
|
261
|
-
|
|
262
|
-
};
|
|
211
|
+
return "Function PaginateProcessLogical is Finished"
|
|
212
|
+
|
|
263
213
|
} catch (err) {
|
|
264
214
|
_izContext.logger.error('error PaginateProcessLogicalMain: ', err);
|
|
265
|
-
throw err
|
|
215
|
+
throw (err)
|
|
266
216
|
}
|
|
267
|
-
}
|
|
217
|
+
}
|
|
@@ -15,9 +15,10 @@ 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 as middleware,
|
|
20
|
+
validatorSchema
|
|
21
|
+
} from '@izara_project/izara-middleware';
|
|
21
22
|
import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
|
|
22
23
|
import Logger from '@izara_project/izara-core-library-logger';
|
|
23
24
|
import { recordHandlerSharedLib } from '@izara_project/izara-core-library-record-handler';
|
|
@@ -31,129 +32,140 @@ middleware.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema());
|
|
|
31
32
|
|
|
32
33
|
// validate event params in middleware before into function
|
|
33
34
|
let validator = {
|
|
34
|
-
type:
|
|
35
|
-
|
|
35
|
+
type: 'object',
|
|
36
|
+
required: ['firstObject', 'relType', 'relId', 'relationshipDirection'],
|
|
36
37
|
properties: {
|
|
37
38
|
firstObject: {
|
|
38
|
-
type:
|
|
39
|
-
required: [
|
|
39
|
+
type: 'object',
|
|
40
|
+
required: ['objType', 'identifiers'],
|
|
40
41
|
properties: {
|
|
41
42
|
objType: {
|
|
42
|
-
type:
|
|
43
|
-
required: [
|
|
43
|
+
type: 'object',
|
|
44
|
+
required: ['serviceTag', 'objectType'],
|
|
44
45
|
properties: {
|
|
45
46
|
serviceTag: validatorSchema.stringNotEmpty(),
|
|
46
|
-
objectType: validatorSchema.stringNotEmpty()
|
|
47
|
+
objectType: validatorSchema.stringNotEmpty()
|
|
47
48
|
}
|
|
48
49
|
},
|
|
49
50
|
identifiers: {
|
|
50
|
-
type:
|
|
51
|
+
type: 'object',
|
|
51
52
|
minProperties: 1
|
|
52
53
|
}
|
|
53
54
|
}
|
|
54
55
|
},
|
|
55
56
|
secondObject: {
|
|
56
|
-
type:
|
|
57
|
-
required: [
|
|
57
|
+
type: 'object',
|
|
58
|
+
required: ['objType', 'identifiers'],
|
|
58
59
|
properties: {
|
|
59
60
|
objType: {
|
|
60
|
-
type:
|
|
61
|
-
required: [
|
|
61
|
+
type: 'object',
|
|
62
|
+
required: ['serviceTag', 'objectType'],
|
|
62
63
|
properties: {
|
|
63
64
|
serviceTag: validatorSchema.stringNotEmpty(),
|
|
64
|
-
objectType: validatorSchema.stringNotEmpty()
|
|
65
|
+
objectType: validatorSchema.stringNotEmpty()
|
|
65
66
|
}
|
|
66
67
|
},
|
|
67
68
|
identifiers: {
|
|
68
|
-
type:
|
|
69
|
+
type: 'object',
|
|
69
70
|
minProperties: 1
|
|
70
71
|
}
|
|
71
72
|
}
|
|
72
73
|
},
|
|
73
74
|
relType: {
|
|
74
|
-
type:
|
|
75
|
-
required: [
|
|
75
|
+
type: 'object',
|
|
76
|
+
required: ['relationshipTag', 'serviceTag'],
|
|
76
77
|
properties: {
|
|
77
78
|
relationshipTag: validatorSchema.stringNotEmpty(),
|
|
78
79
|
serviceTag: {
|
|
79
80
|
type: 'string',
|
|
80
|
-
pattern:
|
|
81
|
+
pattern: '^[a-zA-Z0-9_-]+$',
|
|
81
82
|
enum: [process.env.iz_serviceTag]
|
|
82
83
|
}
|
|
83
84
|
}
|
|
84
85
|
},
|
|
85
86
|
relId: validatorSchema.stringNotEmpty(),
|
|
86
87
|
relationshipDirection: {
|
|
87
|
-
type:
|
|
88
|
+
type: 'string',
|
|
88
89
|
enum: ['from', 'to']
|
|
89
90
|
}
|
|
90
91
|
}
|
|
91
92
|
};
|
|
92
93
|
|
|
93
94
|
//(<globalVariable>
|
|
94
|
-
|
|
95
|
+
//</globalVariable>)
|
|
95
96
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
97
|
+
// validate event params in middleware before into main function
|
|
98
|
+
validator =
|
|
99
|
+
callingFlowSharedLib.addOptionalCallingFlowToValidatorSchema(validator);
|
|
100
|
+
// if need to validate authorizer or additional params , add code to hook tag below
|
|
99
101
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
+
//(<afterValidateWith>)
|
|
103
|
+
//(</afterValidateWith>)
|
|
102
104
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
105
|
+
export const main = middleware.wrap(async (event, context, callback) => {
|
|
106
|
+
try {
|
|
107
|
+
let recordPromises = []; // final return
|
|
106
108
|
|
|
107
|
-
|
|
109
|
+
// loop each record and send to mainFunction
|
|
110
|
+
await Promise.all(
|
|
111
|
+
event.Records.map(async record => {
|
|
112
|
+
// promise.all for map() function
|
|
108
113
|
|
|
109
|
-
|
|
110
|
-
await Promise.all(event.Records.map(async record => { // promise.all for map() function
|
|
111
|
-
|
|
112
|
-
let passOnProperties = []
|
|
114
|
+
let passOnProperties = [];
|
|
113
115
|
|
|
114
116
|
// --- validate message (and MessageAttributes)
|
|
115
117
|
await recordHandlerSharedLib.validateRecord(
|
|
116
118
|
record, // one record will send to mainFunction
|
|
117
|
-
|
|
118
|
-
validator
|
|
119
|
+
'<%-firstLetterUpperCase(queueName) %>', // queue name that need to retry or send to dlq
|
|
120
|
+
validator // schema for record.Message
|
|
119
121
|
// messageAttributeValidatorSchema // ----- for msgAttr default is null -> do not send this parameter if not want to validate msgAtt
|
|
120
122
|
);
|
|
121
123
|
|
|
122
124
|
// add argument (to invoke lambda) to passOnProperties[]
|
|
123
|
-
passOnProperties.push(record.body.Message)
|
|
124
|
-
passOnProperties.push(
|
|
125
|
+
passOnProperties.push(record.body.Message);
|
|
126
|
+
passOnProperties.push(
|
|
127
|
+
callingFlowSharedLib.addCallingFlowToPassOnProperties(
|
|
128
|
+
record.body.Message
|
|
129
|
+
)
|
|
130
|
+
);
|
|
125
131
|
//(<afterPutParamIntoMainFunction>)
|
|
126
132
|
//(</afterPutParamIntoMainFunction>)
|
|
127
133
|
|
|
128
|
-
record._izContext.logger.debug(
|
|
134
|
+
record._izContext.logger.debug(
|
|
135
|
+
'passOnProperties in handler',
|
|
136
|
+
passOnProperties
|
|
137
|
+
);
|
|
129
138
|
|
|
130
139
|
// call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
|
|
131
140
|
let recordPromise = recordHandlerSharedLib.recordHandler(
|
|
132
141
|
record, // one record will send to mainFunction
|
|
133
|
-
<%- functionName %>.<%- functionName %>,
|
|
134
|
-
|
|
135
|
-
passOnProperties
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
142
|
+
<%- functionName %>.<%- functionName %>, // mainFunction that need to invoke.
|
|
143
|
+
'<%-firstLetterUpperCase(queueName) %>', // queue name that need to retry or send to dlq
|
|
144
|
+
passOnProperties // all parameters that mainFunction needed.
|
|
145
|
+
);
|
|
146
|
+
record._izContext.logger.debug('after recordPromise in handler');
|
|
147
|
+
recordPromises.push(recordPromise); // push promise to recordPromises
|
|
148
|
+
})
|
|
149
|
+
); //end record
|
|
150
|
+
|
|
151
|
+
Logger.debug('before Promise.all(recordPromises) in handler');
|
|
152
|
+
try {
|
|
153
|
+
await Promise.all(recordPromises); // await all promises
|
|
154
|
+
return event.Records; // return all for local test
|
|
155
|
+
} catch {
|
|
156
|
+
Logger.debug(
|
|
157
|
+
'Promise.all(recordPromises) in handler threw error (at least one record did no resolve)'
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
Logger.debug('after Promise.all(recordPromises) in handler');
|
|
161
|
+
} catch (err) {
|
|
162
|
+
Logger.error('Unhandled Error, updateRelationshipHdrDsq:', err);
|
|
163
|
+
throw err;
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
<%_ function firstLetterUpperCase(text) {
|
|
167
|
+
return text.charAt(0).toUpperCase() + text.slice(1)
|
|
168
|
+
} _%>
|
|
169
|
+
<%_ function firstLetterLowerCase(str) {
|
|
170
|
+
return str.charAt(0).toLowerCase() + str.slice(1)
|
|
171
|
+
} _%>
|
|
@@ -31,60 +31,66 @@ middlewareHandler.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema(
|
|
|
31
31
|
|
|
32
32
|
// validate event params in middlewareHandler before into function
|
|
33
33
|
let basicValidatorSchema = {
|
|
34
|
-
type:
|
|
35
|
-
required: [
|
|
34
|
+
type: 'object',
|
|
35
|
+
required: [
|
|
36
|
+
'firstObject',
|
|
37
|
+
'relType',
|
|
38
|
+
'relationshipProperties',
|
|
39
|
+
'relationshipDirection',
|
|
40
|
+
'relId'
|
|
41
|
+
],
|
|
36
42
|
properties: {
|
|
37
43
|
firstObject: {
|
|
38
|
-
type:
|
|
39
|
-
required: [
|
|
44
|
+
type: 'object',
|
|
45
|
+
required: ['objType', 'identifiers'],
|
|
40
46
|
properties: {
|
|
41
47
|
objType: {
|
|
42
|
-
type:
|
|
43
|
-
required: [
|
|
48
|
+
type: 'object',
|
|
49
|
+
required: ['serviceTag', 'objectType'],
|
|
44
50
|
properties: {
|
|
45
51
|
serviceTag: validatorSchema.stringNotEmpty(),
|
|
46
|
-
objectType: validatorSchema.stringNotEmpty()
|
|
52
|
+
objectType: validatorSchema.stringNotEmpty()
|
|
47
53
|
}
|
|
48
54
|
},
|
|
49
55
|
identifiers: {
|
|
50
|
-
type:
|
|
56
|
+
type: 'object',
|
|
51
57
|
minProperties: 1
|
|
52
58
|
}
|
|
53
59
|
}
|
|
54
60
|
},
|
|
55
61
|
secondObject: {
|
|
56
|
-
type:
|
|
57
|
-
required: [
|
|
62
|
+
type: 'object',
|
|
63
|
+
required: ['objType', 'identifiers'],
|
|
58
64
|
properties: {
|
|
59
65
|
objType: {
|
|
60
|
-
type:
|
|
61
|
-
required: [
|
|
66
|
+
type: 'object',
|
|
67
|
+
required: ['serviceTag', 'objectType'],
|
|
62
68
|
properties: {
|
|
63
69
|
serviceTag: validatorSchema.stringNotEmpty(),
|
|
64
|
-
objectType: validatorSchema.stringNotEmpty()
|
|
70
|
+
objectType: validatorSchema.stringNotEmpty()
|
|
65
71
|
}
|
|
66
72
|
},
|
|
67
73
|
identifiers: {
|
|
68
|
-
type:
|
|
74
|
+
type: 'object',
|
|
69
75
|
minProperties: 1
|
|
70
76
|
}
|
|
71
77
|
}
|
|
72
78
|
},
|
|
73
79
|
relType: {
|
|
74
|
-
type:
|
|
75
|
-
required: [
|
|
80
|
+
type: 'object',
|
|
81
|
+
required: ['relationshipTag', 'serviceTag'],
|
|
76
82
|
properties: {
|
|
77
83
|
relationshipTag: validatorSchema.stringNotEmpty(),
|
|
78
84
|
serviceTag: {
|
|
79
85
|
type: 'string',
|
|
80
|
-
pattern:
|
|
86
|
+
pattern: '^[a-zA-Z0-9_-]+$',
|
|
81
87
|
enum: [process.env.iz_serviceTag]
|
|
82
88
|
}
|
|
83
89
|
}
|
|
84
90
|
},
|
|
85
91
|
relId: validatorSchema.stringNotEmpty(),
|
|
86
92
|
relationshipDirection: {
|
|
87
|
-
type:
|
|
93
|
+
type: 'string',
|
|
88
94
|
enum: ['from', 'to']
|
|
89
95
|
}
|
|
90
96
|
}
|
|
@@ -94,63 +100,78 @@ let basicValidatorSchema = {
|
|
|
94
100
|
//</globalVariable>)
|
|
95
101
|
|
|
96
102
|
// validate event params in middlewareHandler before into main function
|
|
97
|
-
basicValidatorSchema =
|
|
103
|
+
basicValidatorSchema =
|
|
104
|
+
callingFlowSharedLib.addOptionalCallingFlowToValidatorSchema(
|
|
105
|
+
basicValidatorSchema
|
|
106
|
+
);
|
|
98
107
|
// if need to validate authorizer or additional params , add code to hook tag below
|
|
99
108
|
|
|
100
109
|
//(<afterValidateWith>)
|
|
101
110
|
//(</afterValidateWith>)
|
|
102
111
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
112
|
+
export const main = middlewareHandler.wrap(
|
|
113
|
+
async (event, context, callback) => {
|
|
114
|
+
try {
|
|
115
|
+
let recordPromises = []; // final return
|
|
116
|
+
|
|
117
|
+
// loop each record and send to mainFunction
|
|
118
|
+
await Promise.all(
|
|
119
|
+
event.Records.map(async record => {
|
|
120
|
+
// promise.all for map() function
|
|
121
|
+
|
|
122
|
+
let passOnProperties = [];
|
|
123
|
+
|
|
124
|
+
// --- validate message (and MessageAttributes)
|
|
125
|
+
await recordHandlerSharedLib.validateRecord(
|
|
126
|
+
record, // one record will send to mainFunction
|
|
127
|
+
"<%- queueName %>", // queue name that need to retry or send to dlq
|
|
128
|
+
basicValidatorSchema // schema for record.Message
|
|
129
|
+
// messageAttributeValidatorSchema // ----- for msgAttr default is null -> do not send this parameter if not want to validate msgAtt
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
// add argument (to invoke lambda) to passOnProperties[]
|
|
133
|
+
passOnProperties.push(record.body.Message);
|
|
134
|
+
passOnProperties.push(
|
|
135
|
+
callingFlowSharedLib.addCallingFlowToPassOnProperties(
|
|
136
|
+
record.body.Message
|
|
137
|
+
)
|
|
138
|
+
);
|
|
139
|
+
//(<afterPutParamIntoMainFunction>)
|
|
140
|
+
//(</afterPutParamIntoMainFunction>)
|
|
141
|
+
|
|
142
|
+
record._izContext.logger.debug(
|
|
143
|
+
'passOnProperties in handler',
|
|
144
|
+
passOnProperties
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
// call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
|
|
148
|
+
let recordPromise = recordHandlerSharedLib.recordHandler(
|
|
149
|
+
record, // one record will send to mainFunction
|
|
150
|
+
<%- functionName %>,, // mainFunction that need to invoke.
|
|
151
|
+
'<%- queueName %>', // queue name that need to retry or send to dlq
|
|
152
|
+
passOnProperties // all parameters that mainFunction needed.
|
|
153
|
+
);
|
|
154
|
+
record._izContext.logger.debug('after recordPromise in handler');
|
|
155
|
+
recordPromises.push(recordPromise); // push promise to recordPromises
|
|
156
|
+
})
|
|
157
|
+
); //end record
|
|
140
158
|
|
|
141
159
|
Logger.debug('before Promise.all(recordPromises) in handler');
|
|
142
160
|
try {
|
|
143
161
|
await Promise.all(recordPromises); // await all promises
|
|
144
|
-
return event.Records // return all for local test
|
|
162
|
+
return event.Records; // return all for local test
|
|
145
163
|
} catch {
|
|
146
|
-
Logger.debug(
|
|
164
|
+
Logger.debug(
|
|
165
|
+
'Promise.all(recordPromises) in handler threw error (at least one record did no resolve)'
|
|
166
|
+
);
|
|
147
167
|
}
|
|
148
168
|
Logger.debug('after Promise.all(recordPromises) in handler');
|
|
149
169
|
} catch (err) {
|
|
150
170
|
Logger.error('Unhandled Error, updateRelationshipHdrDsq:', err);
|
|
151
|
-
throw
|
|
171
|
+
throw err;
|
|
152
172
|
}
|
|
153
|
-
}
|
|
173
|
+
}
|
|
174
|
+
);
|
|
154
175
|
<%_ function firstLetterUpperCase(text) {
|
|
155
176
|
return text.charAt(0).toUpperCase() + text.slice(1)
|
|
156
177
|
} _%>
|