@izara_project/izara-core-generate-service-code 1.0.39 → 1.0.41
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 +6 -6
- package/src/generateCode/generateFlowSchema/event/ownTopicComponent/flowSchemaComponent/handler/template.ejs +6 -3
- package/src/generateCode/generateFlowSchema/event/ownTopicComponent/flowSchemaComponent/mainFunction/template.ejs +7 -3
- package/src/generateCode/generateFlowSchema/event/s3Component/upload/createObject/handler/template.ejs +2 -1
- package/src/generateCode/generateFlowSchema/event/s3Component/upload/createObjectComplete/mainFunction/template.ejs +3 -2
- package/src/generateCode/generateFlowSchema/event/s3Component/upload/preSignUrl/reservedLimit/mainFunction/template.ejs +3 -2
- package/src/generateCode/generateFlowSchema/registerComponent/complete/mainFunction/template.ejs +2 -2
- package/src/generateCode/generateFlowSchema/registerComponent/wbs/handler/template.ejs +3 -1
- package/src/generateCode/generateFlowSchema/registerComponent/wbs/mainFunction/template.ejs +3 -4
- package/src/generateCode/generateFlowSchema/webSocketComponent/webSocketComplete/mainFunction/template.ejs +2 -1
- package/src/generateCode/generateFlowStepWithPlugIn/byConfig/handler/data.js +56 -0
- package/src/generateCode/generateFlowStepWithPlugIn/byConfig/handler/templateAwaitingStep.ejs +105 -0
- package/src/generateCode/generateFlowStepWithPlugIn/byConfig/handler/templatePaginated.ejs +137 -0
- package/src/generateCode/generateFlowStepWithPlugIn/byConfig/mainFunction/data.js +57 -0
- package/src/generateCode/generateFlowStepWithPlugIn/byConfig/mainFunction/templateAwaitingStep.ejs +129 -0
- package/src/generateCode/generateFlowStepWithPlugIn/byConfig/mainFunction/templatePaginated.ejs +59 -0
- package/src/generateCode/generateFlowStepWithPlugIn/byConfig/sns-sqs/data.js +50 -0
- package/src/generateCode/generateFlowStepWithPlugIn/byConfig/sns-sqs/queueNoTopic.ejs +43 -0
- package/src/generateCode/generateFlowStepWithPlugIn/byConfig/sns-sqs/snsTemplate.ejs +58 -0
- package/src/generateCode/generateFlowStepWithPlugIn/byConfig/sns-sqs/sqsTemplate.ejs +43 -0
- package/src/generateCode/generateFlowStepWithPlugIn/byConfig/yaml/data.js +47 -0
- package/src/generateCode/generateFlowStepWithPlugIn/byConfig/yaml/template.ejs +43 -0
- package/src/generateCode/generateFlowStepWithPlugIn/firstFlowStep/handler/data.js +7 -1
- package/src/generateCode/generateFlowStepWithPlugIn/firstFlowStep/mainFunction/data.js +38 -6
- package/src/generateCode/generateFlowStepWithPlugIn/firstFlowStep/mainFunction/template.ejs +5 -16
- package/src/generateCode/generateFlowStepWithPlugIn/firstFlowStep/mainFunction/templateByConfig/awaitingSteps.ejs +63 -0
- package/src/generateCode/generateFlowStepWithPlugIn/firstFlowStep/mainFunction/templateByConfig/templateSendPlugin.ejs +18 -0
- package/src/generateCode/generateFlowStepWithPlugIn/firstFlowStep/queueNtopic/sqsTemplate.ejs +7 -7
- package/src/generateCode/generateFlowStepWithPlugIn/firstFlowStep/topicOut/data.js +1 -1
- package/src/generateCode/generateFlowStepWithPlugIn/index(old).js +290 -0
- package/src/generateCode/generateFlowStepWithPlugIn/index.js +413 -155
- package/src/generateCode/generateInitialSetup/externalServiceComponent/lambdaRole/data.js +22 -0
- package/src/generateCode/generateInitialSetup/externalServiceComponent/snsTopicSubscriptions/data.js +16 -0
- package/src/generateCode/generateSchema/actionEndpointCompleteComponent/create/mainFunction/template.ejs +44 -4
- package/src/generateCode/generateSchema/actionEndpointComponent/mainFunction/create/main/template.ejs +58 -40
- package/src/libs/Libs.js +21 -15
- package/src/generateCode/generateInitialSetup/externalServiceComponent/lambdaRole/request.json +0 -18
- package/src/generateCode/generateInitialSetup/externalServiceComponent/snsTopicSubscriptions/request.json +0 -12
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.41",
|
|
4
4
|
"description": "Code for locally generating per service files",
|
|
5
5
|
"author": "Sven Mason <thebarbariansven@gmail.com>",
|
|
6
6
|
"license": "AGPL-3.0-or-later",
|
|
@@ -24,11 +24,11 @@
|
|
|
24
24
|
},
|
|
25
25
|
"type": "module",
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@izara_project/izara-core-library-core": "^1.0.
|
|
28
|
-
"@izara_project/izara-core-library-logger": "^1.0.
|
|
29
|
-
"@izara_project/izara-core-library-s3": "^1.0.
|
|
30
|
-
"@izara_project/izara-core-library-service-schemas": "^1.0.
|
|
31
|
-
"@izara_project/izara-shared-core": "^1.0.
|
|
27
|
+
"@izara_project/izara-core-library-core": "^1.0.32",
|
|
28
|
+
"@izara_project/izara-core-library-logger": "^1.0.9",
|
|
29
|
+
"@izara_project/izara-core-library-s3": "^1.0.8",
|
|
30
|
+
"@izara_project/izara-core-library-service-schemas": "^1.0.141",
|
|
31
|
+
"@izara_project/izara-shared-core": "^1.0.12",
|
|
32
32
|
"ejs": "^5.0.1",
|
|
33
33
|
"js-beautify": "^1.15.4",
|
|
34
34
|
"yaml": "^2.8.2"
|
|
@@ -21,10 +21,13 @@ import { middlewareHandler as middleware, validatorSchema, consts, response } fr
|
|
|
21
21
|
import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
|
|
22
22
|
import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
|
|
23
23
|
import { objectHash as hash } from '@izara_project/izara-shared-core';
|
|
24
|
-
import { postToConnection } from '../../../../libs/source/GenerateCodeLibs.js';
|
|
25
|
-
import <%- functionName %> from './<%- functionName %>_Main.js';
|
|
26
24
|
import { utils, getObjectSchema } from "@izara_project/izara-core-library-service-schemas";
|
|
27
|
-
const { createFlowTypeConcat } = utils
|
|
25
|
+
const { createFlowTypeConcat } = utils;
|
|
26
|
+
|
|
27
|
+
import { webSocket } from '@izara_project/izara-core-library-external-request';
|
|
28
|
+
const { postToConnection } = webSocket;
|
|
29
|
+
|
|
30
|
+
import <%- functionName %> from './<%- functionName %>_Main.js';
|
|
28
31
|
|
|
29
32
|
export const main = middleware.wrap(async (event, context) => {
|
|
30
33
|
|
|
@@ -23,13 +23,13 @@ import { getObjectSchema } from '@izara_project/izara-core-library-service-schem
|
|
|
23
23
|
import snsSharedLib from '@izara_project/izara-core-library-sns';
|
|
24
24
|
import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
|
|
25
25
|
import lambdaSharedLib from '@izara_project/izara-core-library-lambda';
|
|
26
|
-
import { sns } from '@izara_project/izara-core-library-external-request';
|
|
26
|
+
import { sns, webSocket } from '@izara_project/izara-core-library-external-request';
|
|
27
27
|
|
|
28
28
|
import { NoRetryError } from '@izara_project/izara-core-library-core';
|
|
29
29
|
import { consts as coreConsts } from "@izara_project/izara-middleware";
|
|
30
30
|
import { consts as generateCodeConsts } from '@izara_project/izara-core-generate-service-code';
|
|
31
31
|
const { TOPIC_NAME_GENERATE_CODE } = generateCodeConsts;
|
|
32
|
-
|
|
32
|
+
const { postToConnection } = webSocket;
|
|
33
33
|
|
|
34
34
|
//(<optionalRequire>)
|
|
35
35
|
//(</optionalRequire>)
|
|
@@ -66,7 +66,11 @@ export default async function <%- functionName %> (
|
|
|
66
66
|
serviceTag: process.env.iz_serviceTag,
|
|
67
67
|
})
|
|
68
68
|
|
|
69
|
-
_izContext.logger.debug("flowSchema", flowSchema)
|
|
69
|
+
_izContext.logger.debug("flowSchema", flowSchema);
|
|
70
|
+
|
|
71
|
+
if (flowSchema.initiateBy === 'user') {
|
|
72
|
+
_izContext.correlationIds.set(coreConsts.USER_AGENT, 'webSocket');
|
|
73
|
+
};
|
|
70
74
|
|
|
71
75
|
let connectionId = _izContext.correlationIds.get(coreConsts.CONNECTION_ID);
|
|
72
76
|
|
|
@@ -20,7 +20,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
20
20
|
import { middlewareHandler as middleware, consts, response } from "@izara_project/izara-middleware";
|
|
21
21
|
import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
|
|
22
22
|
import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
|
|
23
|
-
import {
|
|
23
|
+
import { webSocket } from '@izara_project/izara-core-library-external-request';
|
|
24
|
+
const { postToConnection } = webSocket;
|
|
24
25
|
import { utils } from "@izara_project/izara-core-library-service-schemas";
|
|
25
26
|
const { createFlowTypeConcat } = utils
|
|
26
27
|
|
|
@@ -16,9 +16,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
|
|
19
|
-
import { consts as coreConsts } from '@izara_project/izara-middleware'
|
|
19
|
+
import { consts as coreConsts } from '@izara_project/izara-middleware';
|
|
20
|
+
import { webSocket } from '@izara_project/izara-core-library-external-request';
|
|
21
|
+
const { postToConnection } = webSocket;
|
|
20
22
|
|
|
21
|
-
import { postToConnection } from '../../../../libs/source/GenerateCodeLibs.js'
|
|
22
23
|
export async function webSocketTaskComplete(
|
|
23
24
|
_izContext,
|
|
24
25
|
updateItem
|
|
@@ -21,14 +21,15 @@ import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow
|
|
|
21
21
|
import lambdaSharedLib from '@izara_project/izara-core-library-lambda';
|
|
22
22
|
import snsSharedLib from '@izara_project/izara-core-library-sns';
|
|
23
23
|
import asyncFlowSharedLib from "@izara_project/izara-core-library-asynchronous-flow";
|
|
24
|
-
import { sns } from '@izara_project/izara-core-library-external-request';
|
|
24
|
+
import { sns, webSocket } from '@izara_project/izara-core-library-external-request';
|
|
25
25
|
import { consts as generateCodeConsts } from '@izara_project/izara-core-generate-service-code';
|
|
26
26
|
import { consts as coreConsts } from '@izara_project/izara-middleware';
|
|
27
27
|
import { objectHash as hash } from '@izara_project/izara-shared-core';
|
|
28
28
|
import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
|
|
29
|
-
import { processStaticLimit
|
|
29
|
+
import { processStaticLimit } from '../../../../libs/source/GenerateCodeLibs.js';
|
|
30
30
|
import { utils } from "@izara_project/izara-core-library-service-schemas";
|
|
31
31
|
const { createFlowTypeConcat } = utils
|
|
32
|
+
const { postToConnection } = webSocket;
|
|
32
33
|
|
|
33
34
|
//(<optionalRequired>)
|
|
34
35
|
//(</optionalRequired>)
|
package/src/generateCode/generateFlowSchema/registerComponent/complete/mainFunction/template.ejs
CHANGED
|
@@ -24,8 +24,8 @@ import { getObjectSchema, identifiersObject } from '@izara_project/izara-core-li
|
|
|
24
24
|
import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
|
|
25
25
|
import lambdaSharedLib from '@izara_project/izara-core-library-lambda';
|
|
26
26
|
|
|
27
|
-
import { lambda } from '@izara_project/izara-core-library-external-request';
|
|
28
|
-
|
|
27
|
+
import { lambda, webSocket } from '@izara_project/izara-core-library-external-request';
|
|
28
|
+
const { postToConnection } = webSocket;
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
31
|
* description of function.
|
|
@@ -22,7 +22,9 @@ import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow
|
|
|
22
22
|
|
|
23
23
|
import registerMain from './Register_Main.js';
|
|
24
24
|
import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
|
|
25
|
-
|
|
25
|
+
|
|
26
|
+
import { webSocket } from '@izara_project/izara-core-library-external-request';
|
|
27
|
+
const { postToConnection } = webSocket;
|
|
26
28
|
|
|
27
29
|
export const main = middleware.wrap(async (event, context) => {
|
|
28
30
|
|
|
@@ -20,13 +20,12 @@ along with this program. If not, see
|
|
|
20
20
|
|
|
21
21
|
import { objectHash as hash } from '@izara_project/izara-shared-core';
|
|
22
22
|
import { getObjectSchema, identifiersObject } from '@izara_project/izara-core-library-service-schemas';
|
|
23
|
-
import lodash from 'lodash'
|
|
24
23
|
import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
|
|
25
24
|
import lambdaSharedLib from '@izara_project/izara-core-library-lambda';
|
|
26
|
-
import { lambda } from '@izara_project/izara-core-library-external-request'
|
|
25
|
+
import { lambda, webSocket } from '@izara_project/izara-core-library-external-request'
|
|
27
26
|
import { NoRetryError } from '@izara_project/izara-core-library-core';
|
|
28
27
|
import { consts } from '@izara_project/izara-middleware';
|
|
29
|
-
|
|
28
|
+
const { postToConnection } = webSocket;
|
|
30
29
|
|
|
31
30
|
/**
|
|
32
31
|
*
|
|
@@ -123,7 +122,7 @@ export default async function registerMain(
|
|
|
123
122
|
}
|
|
124
123
|
identifier = identifier;
|
|
125
124
|
} else {
|
|
126
|
-
let pureRequestParams =
|
|
125
|
+
let pureRequestParams = structuredClone(requestParams);
|
|
127
126
|
delete pureRequestParams.flowTag
|
|
128
127
|
identifier = pureRequestParams
|
|
129
128
|
}
|
|
@@ -24,7 +24,8 @@ import { getObjectSchema, utils } from '@izara_project/izara-core-library-servic
|
|
|
24
24
|
const { createFlowTypeConcat } = utils;
|
|
25
25
|
import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
|
|
26
26
|
|
|
27
|
-
import {
|
|
27
|
+
import { webSocket } from '@izara_project/izara-core-library-external-request';
|
|
28
|
+
const { postToConnection } = webSocket;
|
|
28
29
|
|
|
29
30
|
//(<optionalRequire>)
|
|
30
31
|
//(</optionalRequire>)
|
|
@@ -0,0 +1,56 @@
|
|
|
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
|
+
|
|
23
|
+
import consts from '#libs/Consts.js';
|
|
24
|
+
import utils from '#libs/Utils.js';
|
|
25
|
+
|
|
26
|
+
const { firstLetterUpperCase: upperCase } = utils;
|
|
27
|
+
const { SOURCE_PATH, SAVE_FILE_NAME, HANDLER } = consts;
|
|
28
|
+
const templatePathByLogic = {
|
|
29
|
+
awaitingMultipleSteps: path.join(__dirname, 'templateAwaitingStep.ejs'),
|
|
30
|
+
paginated: path.join(__dirname, 'templatePaginated.ejs'),
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
function data(_izContext, data, appPath) {
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
templatePath: templatePathByLogic[data.handleLogic],
|
|
37
|
+
templateData: { ...data },
|
|
38
|
+
setting: {
|
|
39
|
+
savePath: path.join(
|
|
40
|
+
appPath,
|
|
41
|
+
SOURCE_PATH.flowSchema,
|
|
42
|
+
`${upperCase(data.flowTag)}`,
|
|
43
|
+
`${upperCase(data.flowStepName)}`,
|
|
44
|
+
'source/'
|
|
45
|
+
),
|
|
46
|
+
saveFileName: upperCase(data.functionName) +
|
|
47
|
+
'_' +
|
|
48
|
+
upperCase(data.handlerType),
|
|
49
|
+
fileExtension: '.js',
|
|
50
|
+
isAppend: false
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
export default data;
|
|
@@ -0,0 +1,105 @@
|
|
|
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 { middlewareHandler as middleware } from "@izara_project/izara-middleware";
|
|
19
|
+
import Logger from '@izara_project/izara-core-library-logger';
|
|
20
|
+
import { recordHandlerSharedLib } from "@izara_project/izara-core-library-record-handler";
|
|
21
|
+
import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
|
|
22
|
+
|
|
23
|
+
import <%- functionName %> from './<%- functionName %>_Main.js';
|
|
24
|
+
|
|
25
|
+
// validate event properties in body.Message of sqs event
|
|
26
|
+
middleware.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema());
|
|
27
|
+
// set schema for record.body.Message
|
|
28
|
+
let perRecordsValidatorSchema = {
|
|
29
|
+
type: "object",
|
|
30
|
+
required: [
|
|
31
|
+
'returnValue',
|
|
32
|
+
'status',
|
|
33
|
+
'errorsFound'
|
|
34
|
+
],
|
|
35
|
+
properties: {
|
|
36
|
+
returnValue: {
|
|
37
|
+
type: 'object',
|
|
38
|
+
},
|
|
39
|
+
status: {
|
|
40
|
+
type: 'string',
|
|
41
|
+
},
|
|
42
|
+
errorsFound: {
|
|
43
|
+
type: 'array',
|
|
44
|
+
default: []
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
perRecordsValidatorSchema = callingFlowSharedLib.addOptionalPassBackPropertiesToValidatorSchema(perRecordsValidatorSchema); // is Ok passBackProperties
|
|
50
|
+
export const main = middleware.wrap(async (event, context) => {
|
|
51
|
+
|
|
52
|
+
try {
|
|
53
|
+
|
|
54
|
+
let recordPromises = [];
|
|
55
|
+
|
|
56
|
+
// loop each record and send to mainFunction
|
|
57
|
+
await Promise.all(event.Records.map(async record => { // promise.all for map() function
|
|
58
|
+
|
|
59
|
+
let passOnProperties = []
|
|
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
|
+
"<%- functionName %>", // 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.returnValue)
|
|
72
|
+
passOnProperties.push(record.body.Message.status)
|
|
73
|
+
passOnProperties.push(record.body.Message.errorsFound)
|
|
74
|
+
passOnProperties.push(callingFlowSharedLib.addPassBackPropertiesToPassOnProperties(record.body.Message)) // is Ok PassBackProperties
|
|
75
|
+
// passOnProperties.push(callingFlowSharedLib.addCallingFlowToPassOnProperties(record.body.Message)) // is Ok callinfFlow
|
|
76
|
+
record._izContext.logger.debug('passOnProperties in handler', passOnProperties);
|
|
77
|
+
|
|
78
|
+
// call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
|
|
79
|
+
let recordPromise = recordHandlerSharedLib.recordHandler(
|
|
80
|
+
record, // one record will send to mainFunction
|
|
81
|
+
<%- functionName %>, // mainFunction that need to invoke.
|
|
82
|
+
"<%- functionName %>", // queue name that need to retry or send to dlq
|
|
83
|
+
passOnProperties, // all parameters that mainFunction needed.
|
|
84
|
+
);
|
|
85
|
+
record._izContext.logger.debug('after recordPromise in handler');
|
|
86
|
+
recordPromises.push(recordPromise); // push promise to recordPromises
|
|
87
|
+
}))
|
|
88
|
+
|
|
89
|
+
Logger.debug('before Promise.all(recordPromises) in handler');
|
|
90
|
+
try {
|
|
91
|
+
// --- main await all promises
|
|
92
|
+
await Promise.all(recordPromises); // await all promises
|
|
93
|
+
|
|
94
|
+
return event.Records // return all for local testing
|
|
95
|
+
|
|
96
|
+
} catch {
|
|
97
|
+
Logger.debug('Promise.all(recordPromises) in handler threw error (at least one record did no resolve)');
|
|
98
|
+
}
|
|
99
|
+
Logger.debug('after Promise.all(recordPromises) in handler');
|
|
100
|
+
|
|
101
|
+
} catch (err) {
|
|
102
|
+
Logger.error('Unhandled Error, <%- functionName %>: ', err);
|
|
103
|
+
throw (err);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
@@ -0,0 +1,137 @@
|
|
|
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 { middlewareHandler as middleware } from '@izara_project/izara-middleware';
|
|
19
|
+
import Logger from '@izara_project/izara-core-library-logger';
|
|
20
|
+
import { recordHandlerSharedLib } from '@izara_project/izara-core-library-record-handler';
|
|
21
|
+
import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
|
|
22
|
+
|
|
23
|
+
import <%- functionName %> from './<%- functionName %>_Main.js';
|
|
24
|
+
|
|
25
|
+
// validate event properties in body.Message of sqs event
|
|
26
|
+
middleware.setValidatorSchema(
|
|
27
|
+
recordHandlerSharedLib.baseValidatorSchema({
|
|
28
|
+
type: 'object',
|
|
29
|
+
required: ['body', 'messageAttributes'],
|
|
30
|
+
properties: {
|
|
31
|
+
body: {
|
|
32
|
+
type: 'object'
|
|
33
|
+
},
|
|
34
|
+
messageAttributes: {
|
|
35
|
+
type: 'object'
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
})
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
// set schema for record.body.Message
|
|
42
|
+
const perRecordsValidatorSchema = {
|
|
43
|
+
type: 'object',
|
|
44
|
+
required: [
|
|
45
|
+
//(<<%- functionName %>ValidateSchemaRequired>)
|
|
46
|
+
//(</<%- functionName %>ValidateSchemaRequired>)
|
|
47
|
+
'overWriteCache'
|
|
48
|
+
],
|
|
49
|
+
properties: {
|
|
50
|
+
//(<<%- functionName %>ValidateSchemaProperties>)
|
|
51
|
+
//(</<%- functionName %>ValidateSchemaProperties>)
|
|
52
|
+
startKey: {
|
|
53
|
+
type: 'object'
|
|
54
|
+
},
|
|
55
|
+
overwriteUniqueRequestId: {
|
|
56
|
+
type: 'string'
|
|
57
|
+
},
|
|
58
|
+
overWriteCache: {
|
|
59
|
+
type: 'boolean'
|
|
60
|
+
},
|
|
61
|
+
callingFlow: {
|
|
62
|
+
type: 'string',
|
|
63
|
+
default: ''
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export const main = middleware.wrap(async (event, context, callback) => {
|
|
69
|
+
try {
|
|
70
|
+
let recordPromises = [];
|
|
71
|
+
|
|
72
|
+
// loop each record and send to mainFunction
|
|
73
|
+
await Promise.all(
|
|
74
|
+
event.Records.map(async record => {
|
|
75
|
+
// promise.all for map() function
|
|
76
|
+
|
|
77
|
+
// --- reforming record.body for Dsq request
|
|
78
|
+
record = recordHandlerSharedLib.reformatDsqMessage(
|
|
79
|
+
record._izContext,
|
|
80
|
+
record
|
|
81
|
+
);
|
|
82
|
+
record._izContext.logger.debug(
|
|
83
|
+
'record PaginateProcessLogicalHdrDsq after reform',
|
|
84
|
+
record
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
let passOnProperties = [];
|
|
88
|
+
|
|
89
|
+
// validate message (and MessageAttributes)
|
|
90
|
+
await recordHandlerSharedLib.validateRecord(
|
|
91
|
+
record, // one record will send to mainFunction
|
|
92
|
+
'PaginateProcessLogicalHdrDsq', // queue name that need to retry or send to dlq
|
|
93
|
+
perRecordsValidatorSchema // schema for record.Message
|
|
94
|
+
// messageAttributeValidatorSchema // ----- for msgAttr default is null -> do not send this parameter if not want to validate msgAtt
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
// add argument (to invoke lambda) to passOnProperties[]
|
|
98
|
+
//(<<%- functionName %>AddPassOnProperties>)
|
|
99
|
+
//(</<%- functionName %>AddPassOnProperties>)
|
|
100
|
+
passOnProperties.push(record.body.startKey);
|
|
101
|
+
passOnProperties.push(record.body.overwriteUniqueRequestId);
|
|
102
|
+
passOnProperties.push(record.body.overWriteCache);
|
|
103
|
+
callingFlowSharedLib.addCallingFlowToPassOnProperties(record.body.Message),
|
|
104
|
+
record._izContext.logger.debug(
|
|
105
|
+
'passOnProperties in handler',
|
|
106
|
+
passOnProperties
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
// call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
|
|
110
|
+
let recordPromise = recordHandlerSharedLib.recordHandler(
|
|
111
|
+
record, // one record will send to mainFunction
|
|
112
|
+
paginateProcessLogical, // mainFunction that need to invoke.
|
|
113
|
+
'PaginateProcessLogicalHdrDsq', // queue name that need to retry or send to dlq
|
|
114
|
+
passOnProperties // all parameters that mainFunction needed.
|
|
115
|
+
);
|
|
116
|
+
record._izContext.logger.debug('after recordPromise in handler');
|
|
117
|
+
recordPromises.push(recordPromise); // push promise to recordPromises
|
|
118
|
+
})
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
Logger.debug('before Promise.all(recordPromises) in handler');
|
|
122
|
+
try {
|
|
123
|
+
// --- main await all promises
|
|
124
|
+
await Promise.all(recordPromises); // await all promises
|
|
125
|
+
|
|
126
|
+
return event.Records; // return all for local testing
|
|
127
|
+
} catch {
|
|
128
|
+
Logger.debug(
|
|
129
|
+
'Promise.all(recordPromises) in handler threw error (at least one record did no resolve)'
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
Logger.debug('after Promise.all(recordPromises) in handler');
|
|
133
|
+
} catch (err) {
|
|
134
|
+
Logger.error('Unhandled Error, PaginateProcessLogicalHdrDsq: ', err);
|
|
135
|
+
throw err;
|
|
136
|
+
}
|
|
137
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
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
|
+
|
|
23
|
+
import consts from '#libs/Consts.js';
|
|
24
|
+
import utils from '#libs/Utils.js';
|
|
25
|
+
|
|
26
|
+
const { firstLetterUpperCase: upperCase } = utils;
|
|
27
|
+
const { SOURCE_PATH, SAVE_FILE_NAME, HANDLER } = consts;
|
|
28
|
+
const templateByHandleLogic = {
|
|
29
|
+
awaitingMultipleSteps: path.join(__dirname, 'templateAwaitingStep.ejs'),
|
|
30
|
+
paginated: path.join(__dirname, 'templatePaginated.ejs')
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
function data(_izContext, data, appPath) {
|
|
35
|
+
console.log("data main", data)
|
|
36
|
+
return {
|
|
37
|
+
templatePath: templateByHandleLogic[data.handleLogic],
|
|
38
|
+
templateData: {
|
|
39
|
+
...data,
|
|
40
|
+
},
|
|
41
|
+
setting: {
|
|
42
|
+
savePath: path.join(
|
|
43
|
+
appPath,
|
|
44
|
+
SOURCE_PATH.flowSchema,
|
|
45
|
+
`${upperCase(data.flowTag)}`,
|
|
46
|
+
`${upperCase(data.flowStepName)}`,
|
|
47
|
+
'source/'
|
|
48
|
+
),
|
|
49
|
+
saveFileName: upperCase(data.functionName) + '_Main',
|
|
50
|
+
fileExtension: '.js',
|
|
51
|
+
isAppend: false
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
export default data;
|
package/src/generateCode/generateFlowStepWithPlugIn/byConfig/mainFunction/templateAwaitingStep.ejs
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
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
|
|
16
|
+
<http: //www.gnu.org/licenses />.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import asyncFlowSharedLib from '@izara_project/izara-core-library-asynchronous-flow';
|
|
20
|
+
import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
|
|
21
|
+
import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
|
|
22
|
+
import snsSharedLib from '@izara_project/izara-core-library-sns';
|
|
23
|
+
|
|
24
|
+
import { sns } from '@izara_project/izara-core-library-external-request';
|
|
25
|
+
import { objectHash as hash } from '@izara_project/izara-shared-core';
|
|
26
|
+
import { consts } from '@izara_project/izara-core-library-service-schemas';
|
|
27
|
+
import { NoRetryError } from '@izara_project/izara-core-library-core';
|
|
28
|
+
|
|
29
|
+
const { TOPIC_NAME_GENERATE_CODE } = consts;
|
|
30
|
+
const PREFIX = {
|
|
31
|
+
CREATE_OBJECT_ASYNC: 'createObjectAsync',
|
|
32
|
+
CREATE_OBJECT_ASYNC_COMPLETE: 'createObjectAsyncComplete',
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
//(<optionalRequire>)
|
|
36
|
+
//(</optionalRequire>)
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
*
|
|
40
|
+
*
|
|
41
|
+
* description of function.
|
|
42
|
+
* @param {Object} _izContext
|
|
43
|
+
* @param {CorrelationIds} _izContext.correlationIds - property of _izContext
|
|
44
|
+
* @param {Logger} _izContext.logger - property of _izContext
|
|
45
|
+
* @param {*} returnValue
|
|
46
|
+
* @param {*} status
|
|
47
|
+
* @param {*} errorsFound
|
|
48
|
+
*
|
|
49
|
+
* @returns {object} description of return value
|
|
50
|
+
*/
|
|
51
|
+
export default async function AFlowStepsAwaitingMultipleSteps(
|
|
52
|
+
_izContext,
|
|
53
|
+
returnValue,
|
|
54
|
+
status,
|
|
55
|
+
errorsFound,
|
|
56
|
+
passBackProperties,
|
|
57
|
+
//(<additionalParams>)
|
|
58
|
+
//(</additionalParams>)
|
|
59
|
+
) {
|
|
60
|
+
try {
|
|
61
|
+
_izContext.logger.debug('AFlowStepsAwaitingMultipleSteps _izContext: ', _izContext);
|
|
62
|
+
_izContext.logger.debug('AFlowStepsAwaitingMultipleSteps requestParams: ', {
|
|
63
|
+
returnValue: returnValue,
|
|
64
|
+
status: status
|
|
65
|
+
});
|
|
66
|
+
_izContext.logger.debug('AFlowStepsAwaitingMultipleSteps passBackProperties: ', passBackProperties);
|
|
67
|
+
|
|
68
|
+
//(<beforeCheckAwaitingStep>)
|
|
69
|
+
//(</beforeCheckAwaitingStep>)
|
|
70
|
+
|
|
71
|
+
const awaitingStepId = await asyncFlowSharedLib.createAwaitingStepId(
|
|
72
|
+
hash({
|
|
73
|
+
//(<createAwaitingStep>)
|
|
74
|
+
//(</createAwaitingStep>)
|
|
75
|
+
}),
|
|
76
|
+
"<%- firstLetterUpperCase(flowTag) %><%- firstLetterUpperCase(flowStepName) %>"
|
|
77
|
+
);
|
|
78
|
+
_izContext.logger.debug('awaitingStepId:', awaitingStepId);
|
|
79
|
+
|
|
80
|
+
const recordAwaitingSteps = await dynamodbSharedLib.query(
|
|
81
|
+
_izContext,
|
|
82
|
+
await dynamodbSharedLib.tableName(_izContext,
|
|
83
|
+
'AwaitingMultipleSteps'
|
|
84
|
+
),
|
|
85
|
+
{
|
|
86
|
+
awaitingStepId
|
|
87
|
+
},
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
await Promise.all(
|
|
91
|
+
recordAwaitingSteps.Items.map(async ({ pendingStepId }) => {
|
|
92
|
+
if (
|
|
93
|
+
await asyncFlowSharedLib.checkAllAwaitingStepsFinished(
|
|
94
|
+
_izContext,
|
|
95
|
+
pendingStepId,
|
|
96
|
+
awaitingStepId,
|
|
97
|
+
errorsFound,
|
|
98
|
+
)
|
|
99
|
+
) {
|
|
100
|
+
_izContext.logger.debug('finish all awaitingStep');
|
|
101
|
+
//(<checkAwaitingStepFinish>)
|
|
102
|
+
//(</checkAwaitingStepFinish>)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
//(<beforeRemoveAwatingStep>)
|
|
106
|
+
//(</beforeRemoveAwatingStep>)
|
|
107
|
+
await asyncFlowSharedLib.removeAwaitingMultipleStep(
|
|
108
|
+
_izContext,
|
|
109
|
+
awaitingStepId,
|
|
110
|
+
pendingStepId,
|
|
111
|
+
errorsFound,
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
)
|
|
115
|
+
)
|
|
116
|
+
_izContext.logger.debug('record awaitingSteps::', recordAwaitingSteps);
|
|
117
|
+
|
|
118
|
+
//(<afterCheckAwatingFinish>)
|
|
119
|
+
//(</afterCheckAwatingFinish>)
|
|
120
|
+
|
|
121
|
+
} catch (err) {
|
|
122
|
+
_izContext.logger.error('error AFlowStepsAwaitingMultipleStepsMain: ', err)
|
|
123
|
+
throw (err)
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
<%_ function firstLetterUpperCase(text) {
|
|
128
|
+
return text.charAt(0).toUpperCase() + text.slice(1);
|
|
129
|
+
} -%>
|