@izara_project/izara-core-generate-service-code 1.0.68 → 1.0.70
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/scripts/format-ejs.js +36 -32
- package/src/compile/compileProject.js +26 -10
- package/src/compile/loadSchemas.js +122 -59
- package/src/emit/coreFunction/emitCoreFunctionArtifacts.js +163 -0
- package/src/emit/coreFunction/templates/CoreFunction_Yaml.ejs +38 -0
- package/src/emit/coreFunction/templates/CoreResource_Yaml.ejs +235 -0
- package/src/emit/coreFunction/templates/GenerateSeedDataDynamo_HdrInv.ejs +16 -0
- package/src/emit/coreFunction/templates/GenerateSeedDataDynamo_Main.ejs +38 -0
- package/src/emit/coreFunction/templates/GenerateSeedDataGraphData_HdrInv.ejs +16 -0
- package/src/emit/coreFunction/templates/GenerateSeedDataGraphData_Main.ejs +32 -0
- package/src/emit/coreFunction/templates/GenerateSeedDataGraphSchema_HdrInv.ejs +16 -0
- package/src/emit/coreFunction/templates/GenerateSeedDataGraphSchema_Main.ejs +71 -0
- package/src/emit/coreFunction/templates/GeneratedGraphNodeSchemas.ejs +47 -0
- package/src/emit/coreFunction/templates/GeneratedGraphRelSchemas.ejs +27 -0
- package/src/emit/coreFunction/templates/GeneratedTableConfigs.ejs +34 -0
- package/src/emit/coreFunction/templates/InitialSetupConfig.ejs +108 -0
- package/src/emit/coreFunction/templates/InitialSetup_HdrInv.ejs +12 -0
- package/src/emit/coreFunction/templates/InitialSetup_Main.ejs +51 -0
- package/src/emit/coreFunction/templates/RemoveSeedDataDynamo_HdrInv.ejs +16 -0
- package/src/emit/coreFunction/templates/RemoveSeedDataDynamo_Main.ejs +31 -0
- package/src/emit/coreFunction/templates/UploadSchema_HdrInv.ejs +37 -0
- package/src/emit/coreFunction/templates/UploadSchema_Main.ejs +52 -0
- package/src/emit/crud/emitCrudApplicationArtifacts.js +194 -41
- package/src/emit/crud/emitDynamicCrudFlowSchemas.js +34 -17
- package/src/emit/crud/generateCrudApplicationArtifacts.js +14 -6
- package/src/emit/crud/generateDynamicCrudFlowSchemas.js +4 -1
- package/src/emit/crud/templates/CreateEndpoint_Main.ejs +1 -1
- package/src/emit/crud/templates/DeleteEndpoint_Main.ejs +1 -1
- package/src/emit/crud/templates/GetEndpoint_Main.ejs +2 -2
- package/src/emit/crud/templates/GetRangeEndpoint_Main.ejs +1 -1
- package/src/emit/crud/templates/UpdateEndpoint_Main.ejs +1 -1
- package/src/emit/custom/customFlows.js +23 -13
- package/src/emit/custom/emitCustomFlowApplicationArtifacts.js +535 -114
- package/src/emit/custom/generateCustomFlowApplicationArtifacts.js +28 -8
- package/src/emit/custom/templates/FlowEndpoint_Main.ejs +2 -2
- package/src/emit/custom/templates/FlowStep_Main.ejs +1 -1
- package/src/emit/custom/templates/s3/CreateObject_Main.ejs +1 -1
- package/src/emit/custom/templates/s3/FlowHandler_HdrS3.ejs +2 -2
- package/src/emit/custom/templates/s3/ReservedLimit_HdrSqs.ejs +1 -1
- package/src/emit/custom/templates/s3/ReservedLimit_Main.ejs +1 -1
- package/src/emit/custom/templates/triggerCache/CheckTriggerCache_HdrSqs.ejs +4 -4
- package/src/emit/function/functionYamlArtifact.js +273 -97
- package/src/emit/function/templates/ApiFunction_Yaml.ejs +7 -0
- package/src/emit/function/templates/EventBridgeFunction_Yaml.ejs +6 -0
- package/src/emit/function/templates/InvFunction_Yaml.ejs +5 -0
- package/src/emit/function/templates/S3Function_Yaml.ejs +16 -0
- package/src/emit/function/templates/SqsFunction_Yaml.ejs +10 -0
- package/src/emit/function/templates/WbsFunction_Yaml.ejs +10 -0
- package/src/emit/rbac/emitDynamicRbacFlowSchemas.js +28 -30
- package/src/emit/rbac/emitRbacApplicationArtifacts.js +6 -6
- package/src/emit/rbac/generateCreateTargetRoleHandler.js +6 -4
- package/src/emit/rbac/generateDynamicRbacFlowSchemas.js +8 -2
- package/src/emit/rbac/rbacFlowTag.js +3 -1
- package/src/emit/rbac/templates/UserRbacFlow_Main.ejs +1 -1
- package/src/emit/relationship/emitDynamicRelationshipFlowSchemas.js +26 -10
- package/src/emit/relationship/emitRelationshipApplicationArtifacts.js +189 -37
- package/src/emit/relationship/generateDynamicRelationshipFlowSchemas.js +8 -2
- package/src/emit/relationship/generateRelationshipApplicationArtifacts.js +15 -6
- package/src/emit/relationship/templates/ChangeRelationship_Main.ejs +1 -1
- package/src/emit/relationship/templates/CreateRelationship_Main.ejs +1 -1
- package/src/emit/relationship/templates/DeleteRelationship_Main.ejs +1 -1
- package/src/emit/relationship/templates/GetRelationship_Main.ejs +1 -1
- package/src/emit/relationship/templates/MoveRelationship_Main.ejs +1 -1
- package/src/emit/relationship/templates/UpdateRelationship_Main.ejs +1 -1
- package/src/emit/resource/emitResourceArtifacts.js +249 -123
- package/src/emit/resource/generateResourceArtifacts.js +15 -6
- package/src/emit/resource/templates/DynamoDBTable_Yaml.ejs +18 -18
- package/src/emit/resource/templates/FlowOut_Yaml.ejs +5 -5
- package/src/emit/resource/templates/GeneratedLambdaRoleServiceConfig.ejs +10 -9
- package/src/emit/resource/templates/ResourceBeforeLogicalYaml.ejs +44 -44
- package/src/emit/resource/templates/ResourceSqsYaml.ejs +36 -36
- package/src/emit/resource/templates/ResourceYaml.ejs +48 -48
- package/src/emit/resource/templates/S3Subscription_Yaml.ejs +7 -0
- package/src/emit/resource/templates/SharedResource_Yaml.ejs +11 -11
- package/src/emit/resource/templates/SystemDynamoDB_Yaml.ejs +122 -105
- package/src/emit/resource/templates/WebSocketSubscription_Yaml.ejs +7 -0
- package/src/emit/shared/templates/FindData_HdrSqs.ejs +120 -0
- package/src/emit/shared/templates/FindData_Main.ejs +345 -0
- package/src/emit/{crud → shared}/templates/FlowHandler_HdrApi.ejs +1 -1
- package/src/emit/{relationship → shared}/templates/FlowHandler_HdrDsq.ejs +4 -4
- package/src/emit/{crud → shared}/templates/FlowHandler_HdrInv.ejs +1 -1
- package/src/emit/{crud → shared}/templates/FlowHandler_HdrSqs.ejs +4 -4
- package/src/emit/shared/templates/PaginateProcessLogical_HdrDsq.ejs +162 -0
- package/src/emit/shared/templates/PaginateProcessLogical_HdrSqs.ejs +140 -0
- package/src/emit/shared/templates/PaginateProcessLogical_Main.ejs +268 -0
- package/src/emit/{relationship/templates/FlowHandler_HdrSqs.ejs → shared/templates/ProcessLogical_HdrSqs.ejs} +40 -55
- package/src/emit/shared/templates/ProcessLogical_Main.ejs +448 -0
- package/src/emit/system/emitSystemFindDataArtifacts.js +266 -0
- package/src/emit/system/emitSystemWebSocketArtifacts.js +61 -165
- package/src/emit/system/templates/WebSocketComplete_HdrSqs.ejs +48 -0
- package/src/emit/system/templates/WebSocketComplete_Main.ejs +91 -0
- package/src/emit/system/templates/WebSocketComplete_Yaml.ejs +19 -0
- package/src/emit/system/templates/WebSocketConnect.ejs +45 -0
- package/src/emit/system/templates/WebSocketConnect_Yaml.ejs +11 -0
- package/src/generate.js +166 -36
- package/src/generateIntTest.js +76 -28
- package/src/generateResourceIntTest.js +35 -12
- package/src/generateResources/IntTest/generateResources/generateResources.js +5 -2
- package/src/generateResources/IntTest/generateResources/templateResources.ejs +18 -30
- package/src/generateResources/IntTest/generateTests/events/events.js +1 -1
- package/src/generateResources/IntTest/generateTests/events/templateEvents.ejs +13 -10
- package/src/generateResources/IntTest/generateTests/generateTemplate.js +2 -2
- package/src/generateResources/IntTest/generateTests/pathIntTest/pathIntTest.js +2 -1
- package/src/generateResources/IntTest/generateTests/pathIntTest/template.ejs +1 -3
- package/src/generateResources/IntTest/generateTests/tests/templateTests.ejs +1 -1
- package/src/generateResources/IntTest/generateTests/tests/tests.js +7 -3
- package/src/generateResources/IntTest/libs/{libs.js → IntTestGenerateLib.js} +34 -23
- package/src/generateResources/IntTest/upload/uploadIntTest.js +33 -19
- package/src/intTestGeneratorShared.js +15 -10
- package/src/output/commitArtifacts.js +99 -39
- package/src/output/mergeHooks.js +34 -21
- package/src/output/validateArtifacts.js +37 -27
- package/src/plan/buildGenerationPlan.js +24 -13
- package/test/core.test.js +117 -58
- package/test/createTargetRoleHandler.test.js +1 -1
- package/test/crudApplicationArtifacts.test.js +132 -31
- package/test/customFlowApplicationArtifacts.test.js +353 -71
- package/test/dynamicCrudFlowSchemas.test.js +74 -26
- package/test/dynamicRbacFlowSchemas.test.js +61 -14
- package/test/dynamicRelationshipFlowSchemas.test.js +65 -18
- package/test/functionYamlArtifact.test.js +67 -10
- package/test/intTestApi.test.js +9 -10
- package/test/publicApi.test.js +178 -36
- package/test/relationshipApplicationArtifacts.test.js +90 -19
- package/test/resourceArtifacts.test.js +173 -33
- package/src/emit/relationship/dynamicRelationshipFlowSchemaTemplate.js +0 -11
- package/src/emit/relationship/templates/FlowHandler_HdrApi.ejs +0 -59
- package/src/emit/relationship/templates/FlowHandler_HdrInv.ejs +0 -47
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import initialSetupSharedLib from '@izara_project/izara-core-library-initial-setup';
|
|
2
|
+
import config from './InitialSetupConfig.js';
|
|
3
|
+
import Logger from '@izara_project/izara-core-library-logger';
|
|
4
|
+
import correlationIds from '@izara_project/izara-core-library-correlation-ids';
|
|
5
|
+
|
|
6
|
+
const initialSetup = async (event, context, izContext) => {
|
|
7
|
+
const _izContext = {
|
|
8
|
+
correlationIds: correlationIds,
|
|
9
|
+
logger: Logger
|
|
10
|
+
};
|
|
11
|
+
try {
|
|
12
|
+
Logger.debug('======== InitialSetup start ========');
|
|
13
|
+
|
|
14
|
+
// ====== Generate IAM Role of function ======
|
|
15
|
+
await initialSetupSharedLib.generateIamRoleExternalService(
|
|
16
|
+
_izContext,
|
|
17
|
+
await config.roleConfigs() // If implemented in config
|
|
18
|
+
);
|
|
19
|
+
Logger.debug('-------- Finish generate role IAM --------');
|
|
20
|
+
|
|
21
|
+
// ====== Generate Seed Data ======
|
|
22
|
+
// await initialSetupSharedLib.generateSeedData(_izContext, config);
|
|
23
|
+
// Logger.debug('------ Finish InitialSetup generateSeedData ------');
|
|
24
|
+
|
|
25
|
+
// ====== Generate Subscriptions of SNS topic ======
|
|
26
|
+
await initialSetupSharedLib.generateTopicSubscriptions(
|
|
27
|
+
_izContext,
|
|
28
|
+
config.snsTopicSubscriptions // If implemented in config
|
|
29
|
+
);
|
|
30
|
+
Logger.debug('-------- Finish generate subscribe --------');
|
|
31
|
+
|
|
32
|
+
<% if (hasGenerateGraph) { -%>
|
|
33
|
+
// ====== Generate Schema for graphDb ======
|
|
34
|
+
// await initialSetupSharedLib.generateSchema(_izContext, config.graphNodeSchemas(), 'node');
|
|
35
|
+
// await initialSetupSharedLib.generateSchema(_izContext, config.graphRelationshipSchemas(), 'relationship');
|
|
36
|
+
|
|
37
|
+
// const [versionedDataNodeSchemas, versionedDataRelationshipSchemas] = config.graphVersionedDataSchemas();
|
|
38
|
+
// await initialSetupSharedLib.generateSchema(_izContext, versionedDataNodeSchemas, 'node');
|
|
39
|
+
// await initialSetupSharedLib.generateSchema(_izContext, versionedDataRelationshipSchemas, 'relationship');
|
|
40
|
+
|
|
41
|
+
// Logger.debug('-------- Finished generate main schema --------');
|
|
42
|
+
<% } -%>
|
|
43
|
+
|
|
44
|
+
return 'InitialSetup Complete';
|
|
45
|
+
} catch (err) {
|
|
46
|
+
Logger.error('Error InitialSetup (prod)', err);
|
|
47
|
+
throw err;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export default { initialSetup };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { middlewareHandler as middleware } from '@izara_project/izara-middleware';
|
|
2
|
+
import removeMain from './RemoveSeedDataDynamo_Main.js';
|
|
3
|
+
|
|
4
|
+
const main = middleware.wrap(async (event, context, callback) => {
|
|
5
|
+
event._izContext.logger.debug('Event:', event);
|
|
6
|
+
event._izContext.logger.debug('context:', context);
|
|
7
|
+
|
|
8
|
+
try {
|
|
9
|
+
return await removeMain.removeSeedDataDynamo(event);
|
|
10
|
+
} catch (err) {
|
|
11
|
+
event._izContext.logger.error('Error, RemoveSeedDataDynamo_HdrInv: ', err);
|
|
12
|
+
throw err;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
export { main };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import initialSetupSharedLib from '@izara_project/izara-core-library-initial-setup';
|
|
2
|
+
import Logger from '@izara_project/izara-core-library-logger';
|
|
3
|
+
import correlationIds from '@izara_project/izara-core-library-correlation-ids';
|
|
4
|
+
import config from './InitialSetupConfig.js';
|
|
5
|
+
|
|
6
|
+
const removeSeedDataDynamo = async (event) => {
|
|
7
|
+
const _izContext = {
|
|
8
|
+
correlationIds: correlationIds,
|
|
9
|
+
logger: Logger
|
|
10
|
+
};
|
|
11
|
+
try {
|
|
12
|
+
console.log('======== Start Refresh Seed Data ========');
|
|
13
|
+
|
|
14
|
+
// === generate new seed data test env ===
|
|
15
|
+
// remove both prod and test and create new just test env??
|
|
16
|
+
// NOTE: in refresh seed data flow will need to remove all dynamodb including graph schema
|
|
17
|
+
await initialSetupSharedLib.removeSeedDataDynamoTestEnv(
|
|
18
|
+
_izContext,
|
|
19
|
+
config.tableConfigs,
|
|
20
|
+
config.tableConfigsTestEnv
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
console.log('-------- Finish All RemoveSeedData --------');
|
|
24
|
+
return 'Finish RemoveSeedDataDynamo Test stage';
|
|
25
|
+
} catch (err) {
|
|
26
|
+
console.log(err);
|
|
27
|
+
throw err;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export default { removeSeedDataDynamo };
|
|
@@ -0,0 +1,37 @@
|
|
|
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
|
+
|
|
20
|
+
import uploadSchema from './UploadSchema_Main.js';
|
|
21
|
+
|
|
22
|
+
const main = middleware.wrap(async (event, context, callback) => {
|
|
23
|
+
event._izContext.logger.debug('Event:', event);
|
|
24
|
+
event._izContext.logger.debug('context:', context);
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
// invoke LambdaFunction
|
|
28
|
+
return await uploadSchema.uploadSchema(
|
|
29
|
+
event._izContext
|
|
30
|
+
);
|
|
31
|
+
} catch (err) {
|
|
32
|
+
event._izContext.logger.error('Error, LambdaFunctionHdrInv: ', err);
|
|
33
|
+
throw err;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
export { main };
|
|
@@ -0,0 +1,52 @@
|
|
|
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 { uploadObjSchema } from '@izara_project/izara-core-library-service-schemas';
|
|
19
|
+
|
|
20
|
+
const SERVICE_TAG = {
|
|
21
|
+
TRANSLATIONS: 'Translations',
|
|
22
|
+
GRAPH_HANDLER: 'GraphHandler',
|
|
23
|
+
TRANSLATE_IDS: 'TranslateIds',
|
|
24
|
+
USER_ACCOUNT: 'UserAccount',
|
|
25
|
+
MEDIA: 'Media'
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const ignoreExternalServices = {
|
|
29
|
+
[SERVICE_TAG.TRANSLATIONS]: false,
|
|
30
|
+
[SERVICE_TAG.GRAPH_HANDLER]: false,
|
|
31
|
+
[SERVICE_TAG.USER_ACCOUNT]: false,
|
|
32
|
+
[SERVICE_TAG.TRANSLATE_IDS]: false,
|
|
33
|
+
[SERVICE_TAG.MEDIA]: false
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const uploadSchema = async _izContext => {
|
|
37
|
+
try {
|
|
38
|
+
_izContext.logger.debug('uploadSchema _izContext: ', _izContext);
|
|
39
|
+
|
|
40
|
+
await uploadObjSchema.uploadObjectSchemaByUseCase(_izContext, {
|
|
41
|
+
ignoreExternalServices: ignoreExternalServices
|
|
42
|
+
});
|
|
43
|
+
return 'upload successfully';
|
|
44
|
+
} catch (err) {
|
|
45
|
+
_izContext.logger.error('error LambdaFunction: ', err);
|
|
46
|
+
throw err;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export default {
|
|
51
|
+
uploadSchema
|
|
52
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import ejsLib from 'ejs';
|
|
2
2
|
import { readFile } from 'node:fs/promises';
|
|
3
3
|
|
|
4
4
|
import {
|
|
@@ -11,31 +11,44 @@ import {
|
|
|
11
11
|
const ACTIONS = ['Create', 'Update', 'Delete', 'Get'];
|
|
12
12
|
const YAML_PATH = 'app/sls_yaml/generatedCode/source/flow-objects.yml';
|
|
13
13
|
const TEMPLATE_URL = new URL('./templates/', import.meta.url);
|
|
14
|
+
const SHARED_TEMPLATE_URL = new URL('../shared/templates/', import.meta.url);
|
|
14
15
|
|
|
15
|
-
export async function emitCrudApplicationArtifacts({
|
|
16
|
+
export async function emitCrudApplicationArtifacts({
|
|
17
|
+
objects,
|
|
18
|
+
flows = [],
|
|
19
|
+
serviceTag
|
|
20
|
+
}) {
|
|
16
21
|
if (!Array.isArray(objects) || !Array.isArray(flows)) {
|
|
17
22
|
throw new TypeError('objects and flows must be arrays');
|
|
18
23
|
}
|
|
19
24
|
if (!objects.some(isCrudObject)) return [];
|
|
20
25
|
|
|
21
|
-
const handlers = await Promise.all(
|
|
26
|
+
const handlers = await Promise.all(
|
|
27
|
+
ACTIONS.map((action) => emitAction(action, objects, flows, serviceTag))
|
|
28
|
+
);
|
|
22
29
|
return [
|
|
23
|
-
...handlers.flatMap(handler => handler.artifacts),
|
|
30
|
+
...handlers.flatMap((handler) => handler.artifacts),
|
|
24
31
|
{
|
|
25
32
|
path: YAML_PATH,
|
|
26
|
-
content: handlers
|
|
33
|
+
content: handlers
|
|
34
|
+
.flatMap((handler) => handler.functions)
|
|
35
|
+
.map(renderFunction)
|
|
36
|
+
.join('\n')
|
|
27
37
|
}
|
|
28
38
|
];
|
|
29
39
|
}
|
|
30
40
|
|
|
31
41
|
export function crudApplicationManagedPaths() {
|
|
32
42
|
return [
|
|
33
|
-
...ACTIONS.flatMap(action => {
|
|
43
|
+
...ACTIONS.flatMap((action) => {
|
|
34
44
|
const source = `app/src/generatedCode/FlowObjects/${action}/source`;
|
|
35
45
|
const paths = [`${source}/${action}_Main.js`];
|
|
36
46
|
if (action === 'Get') {
|
|
37
47
|
paths.push(`${source}/Get_HdrInv.js`, `${source}/Get_HdrApi.js`);
|
|
38
|
-
paths.push(
|
|
48
|
+
paths.push(
|
|
49
|
+
`${source}/GetRange_Main.js`,
|
|
50
|
+
`${source}/GetRange_HdrApi.js`
|
|
51
|
+
);
|
|
39
52
|
} else {
|
|
40
53
|
paths.push(
|
|
41
54
|
`${source}/${action}_HdrSqs.js`,
|
|
@@ -44,7 +57,10 @@ export function crudApplicationManagedPaths() {
|
|
|
44
57
|
`${source}/${action}BeforeLogical_Main.js`,
|
|
45
58
|
`${source}/${action}BeforeLogical_HdrSqs.js`
|
|
46
59
|
);
|
|
47
|
-
paths.push(
|
|
60
|
+
paths.push(
|
|
61
|
+
`${source}/${action}Complete_Main.js`,
|
|
62
|
+
`${source}/${action}Complete_HdrSqs.js`
|
|
63
|
+
);
|
|
48
64
|
}
|
|
49
65
|
return paths;
|
|
50
66
|
}),
|
|
@@ -56,8 +72,12 @@ async function emitAction(action, objects, flows, serviceTag) {
|
|
|
56
72
|
const source = `app/src/generatedCode/FlowObjects/${action}/source`;
|
|
57
73
|
const handlerRoot = `src/generatedCode/FlowObjects/${action}/source`;
|
|
58
74
|
const generateCode = flows
|
|
59
|
-
.filter(
|
|
60
|
-
|
|
75
|
+
.filter(
|
|
76
|
+
(flow) =>
|
|
77
|
+
flow?.generatedCodeConfig?.generatedCodeTag?.toLowerCase() ===
|
|
78
|
+
action.toLowerCase()
|
|
79
|
+
)
|
|
80
|
+
.map((flow) => ({ ...flow.generatedCodeConfig, flowTag: flow.flowTag }));
|
|
61
81
|
const mainFileName = `${action}_Main`;
|
|
62
82
|
const shared = {
|
|
63
83
|
flowTag: action,
|
|
@@ -68,22 +88,66 @@ async function emitAction(action, objects, flows, serviceTag) {
|
|
|
68
88
|
flowStepName: '',
|
|
69
89
|
startConfig: null
|
|
70
90
|
};
|
|
71
|
-
const artifacts = [
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
91
|
+
const artifacts = [
|
|
92
|
+
{
|
|
93
|
+
path: `${source}/${mainFileName}.js`,
|
|
94
|
+
content: await render(`${action}Endpoint_Main.ejs`, shared)
|
|
95
|
+
}
|
|
96
|
+
];
|
|
75
97
|
|
|
98
|
+
let targetServiceTag = '${self:custom.iz_serviceName}';
|
|
99
|
+
if (serviceTag) {
|
|
100
|
+
targetServiceTag = serviceTag;
|
|
101
|
+
}
|
|
76
102
|
if (action === 'Get') {
|
|
77
103
|
artifacts.push(
|
|
78
|
-
{
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
104
|
+
{
|
|
105
|
+
path: `${source}/Get_HdrInv.js`,
|
|
106
|
+
content: await renderShared('FlowHandler_HdrInv.ejs', {
|
|
107
|
+
...shared,
|
|
108
|
+
mainFileName,
|
|
109
|
+
functionName: 'Get',
|
|
110
|
+
queueName: 'GetHdrInv'
|
|
111
|
+
})
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
path: `${source}/Get_HdrApi.js`,
|
|
115
|
+
content: await renderShared('FlowHandler_HdrApi.ejs', {
|
|
116
|
+
...shared,
|
|
117
|
+
mainFileName,
|
|
118
|
+
functionName: 'Get',
|
|
119
|
+
queueName: 'GetHdrApi'
|
|
120
|
+
})
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
path: `${source}/GetRange_Main.js`,
|
|
124
|
+
content: await render('GetRangeEndpoint_Main.ejs', {
|
|
125
|
+
...shared,
|
|
126
|
+
mainFileName: 'GetRange_Main',
|
|
127
|
+
functionName: 'GetRange'
|
|
128
|
+
})
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
path: `${source}/GetRange_HdrApi.js`,
|
|
132
|
+
content: await renderShared('FlowHandler_HdrApi.ejs', {
|
|
133
|
+
...shared,
|
|
134
|
+
mainFileName: 'GetRange_Main',
|
|
135
|
+
functionName: 'GetRange',
|
|
136
|
+
queueName: 'GetRangeHdrApi'
|
|
137
|
+
})
|
|
138
|
+
}
|
|
82
139
|
);
|
|
83
140
|
return {
|
|
84
141
|
artifacts,
|
|
85
142
|
functions: [
|
|
86
|
-
{
|
|
143
|
+
{
|
|
144
|
+
type: 'inv',
|
|
145
|
+
functionName: 'GetHdrInv',
|
|
146
|
+
handlerPath: `${handlerRoot}/Get_HdrInv.main`,
|
|
147
|
+
roleName: 'FlowObjectsRole',
|
|
148
|
+
flowTag: action,
|
|
149
|
+
flowStepName: ''
|
|
150
|
+
},
|
|
87
151
|
{
|
|
88
152
|
type: 'api',
|
|
89
153
|
functionName: 'GetHdrApi',
|
|
@@ -91,8 +155,8 @@ async function emitAction(action, objects, flows, serviceTag) {
|
|
|
91
155
|
roleName: 'FlowObjectsRole',
|
|
92
156
|
flowTag: action,
|
|
93
157
|
flowStepName: '',
|
|
94
|
-
routes: objects.filter(isCrudObject).map(object => ({
|
|
95
|
-
path: `/${
|
|
158
|
+
routes: objects.filter(isCrudObject).map((object) => ({
|
|
159
|
+
path: `/${targetServiceTag}/${object.objectType}/get`,
|
|
96
160
|
upperName: upperFirst(object.objectType)
|
|
97
161
|
}))
|
|
98
162
|
},
|
|
@@ -103,45 +167,129 @@ async function emitAction(action, objects, flows, serviceTag) {
|
|
|
103
167
|
roleName: 'FlowObjectsRole',
|
|
104
168
|
flowTag: 'GetRange',
|
|
105
169
|
flowStepName: '',
|
|
106
|
-
routes: objects
|
|
107
|
-
.filter(
|
|
108
|
-
.
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
170
|
+
routes: objects
|
|
171
|
+
.filter(isCrudObject)
|
|
172
|
+
.filter(
|
|
173
|
+
(object) =>
|
|
174
|
+
object.identifiers &&
|
|
175
|
+
object.identifiers.some((i) => i.type === 'sortKey')
|
|
176
|
+
)
|
|
177
|
+
.map((object) => ({
|
|
178
|
+
path: `/${targetServiceTag}/${object.objectType}/getRange`,
|
|
179
|
+
upperName: upperFirst(object.objectType)
|
|
180
|
+
}))
|
|
112
181
|
}
|
|
113
182
|
]
|
|
114
183
|
};
|
|
115
184
|
}
|
|
116
185
|
|
|
117
186
|
artifacts.push(
|
|
118
|
-
{
|
|
119
|
-
|
|
120
|
-
|
|
187
|
+
{
|
|
188
|
+
path: `${source}/${action}_HdrSqs.js`,
|
|
189
|
+
content: await renderShared('FlowHandler_HdrSqs.ejs', {
|
|
190
|
+
...shared,
|
|
191
|
+
mainFileName,
|
|
192
|
+
functionName: action,
|
|
193
|
+
queueName: `${action}HdrSqs`
|
|
194
|
+
})
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
path: `${source}/${action}_WbsMain.js`,
|
|
198
|
+
content: await render('FlowMain_Wbs.ejs', {
|
|
199
|
+
...shared,
|
|
200
|
+
functionName: action
|
|
201
|
+
})
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
path: `${source}/${action}_HdrWbs.js`,
|
|
205
|
+
content: await render('FlowEndpoint_HdrWbs.ejs', {
|
|
206
|
+
...shared,
|
|
207
|
+
mainFileName: `${action}_WbsMain`,
|
|
208
|
+
functionName: action,
|
|
209
|
+
route: action
|
|
210
|
+
})
|
|
211
|
+
}
|
|
121
212
|
);
|
|
122
213
|
const functions = [
|
|
123
|
-
{
|
|
124
|
-
|
|
214
|
+
{
|
|
215
|
+
type: 'wbs',
|
|
216
|
+
functionName: `${action}HdrWbs`,
|
|
217
|
+
handlerPath: `${handlerRoot}/${action}_HdrWbs.main`,
|
|
218
|
+
roleName: 'FlowObjectsRole',
|
|
219
|
+
routeName: action,
|
|
220
|
+
flowTag: action,
|
|
221
|
+
flowStepName: ''
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
type: 'sqs',
|
|
225
|
+
functionName: `${action}HdrSqs`,
|
|
226
|
+
handlerPath: `${handlerRoot}/${action}_HdrSqs.main`,
|
|
227
|
+
roleName: 'FlowObjectsRole',
|
|
228
|
+
queueName: `${action}HdrSqs`,
|
|
229
|
+
flowTag: action,
|
|
230
|
+
flowStepName: ''
|
|
231
|
+
}
|
|
125
232
|
];
|
|
126
233
|
const complete = `${action}Complete`;
|
|
127
234
|
artifacts.push(
|
|
128
|
-
{
|
|
129
|
-
|
|
235
|
+
{
|
|
236
|
+
path: `${source}/${complete}_Main.js`,
|
|
237
|
+
content: await render('FlowEndpointComplete_Main.ejs', { action })
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
path: `${source}/${complete}_HdrSqs.js`,
|
|
241
|
+
content: await renderShared('FlowHandler_HdrSqs.ejs', {
|
|
242
|
+
...shared,
|
|
243
|
+
mainFileName: `${complete}_Main`,
|
|
244
|
+
functionName: complete,
|
|
245
|
+
queueName: `${action}CompleteHdrSqs`
|
|
246
|
+
})
|
|
247
|
+
}
|
|
130
248
|
);
|
|
131
|
-
functions.push({
|
|
132
|
-
|
|
249
|
+
functions.push({
|
|
250
|
+
type: 'sqs',
|
|
251
|
+
functionName: `${action}CompleteHdrSqs`,
|
|
252
|
+
handlerPath: `${handlerRoot}/${complete}_HdrSqs.main`,
|
|
253
|
+
roleName: 'FlowObjectsRole',
|
|
254
|
+
queueName: `${action}CompleteHdrSqs`,
|
|
255
|
+
flowTag: action,
|
|
256
|
+
flowStepName: 'Complete'
|
|
257
|
+
});
|
|
258
|
+
if (generateCode.some((config) => config.codeHookTag === 'beforeLogical')) {
|
|
133
259
|
const beforeMain = `${action}BeforeLogical_Main`;
|
|
134
260
|
artifacts.push(
|
|
135
|
-
{
|
|
136
|
-
|
|
261
|
+
{
|
|
262
|
+
path: `${source}/${beforeMain}.js`,
|
|
263
|
+
content: await render('FlowEndpointBeforeLogical_Main.ejs', shared)
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
path: `${source}/${action}BeforeLogical_HdrSqs.js`,
|
|
267
|
+
content: await renderShared('FlowHandler_HdrSqs.ejs', {
|
|
268
|
+
...shared,
|
|
269
|
+
mainFileName: beforeMain,
|
|
270
|
+
functionName: `${action}BeforeLogicalMain`,
|
|
271
|
+
queueName: `${action}BeforeLogicalHdrSqs`
|
|
272
|
+
})
|
|
273
|
+
}
|
|
137
274
|
);
|
|
138
|
-
functions.push({
|
|
275
|
+
functions.push({
|
|
276
|
+
type: 'sqs',
|
|
277
|
+
functionName: `${action}BeforeLogicalHdrSqs`,
|
|
278
|
+
handlerPath: `${handlerRoot}/${action}BeforeLogical_HdrSqs.main`,
|
|
279
|
+
roleName: 'FlowObjectsRole',
|
|
280
|
+
queueName: `${action}BeforeLogicalHdrSqs`,
|
|
281
|
+
flowTag: action,
|
|
282
|
+
flowStepName: 'BeforeLogical'
|
|
283
|
+
});
|
|
139
284
|
}
|
|
140
285
|
return { artifacts, functions };
|
|
141
286
|
}
|
|
142
287
|
|
|
143
288
|
function isCrudObject(object) {
|
|
144
|
-
return
|
|
289
|
+
return (
|
|
290
|
+
object?.generatedBy === 'userGenerated' ||
|
|
291
|
+
object?.generatedBy === 'systemGenerated'
|
|
292
|
+
);
|
|
145
293
|
}
|
|
146
294
|
|
|
147
295
|
function upperFirst(value) {
|
|
@@ -150,7 +298,12 @@ function upperFirst(value) {
|
|
|
150
298
|
|
|
151
299
|
async function render(templateName, data) {
|
|
152
300
|
const template = await readFile(new URL(templateName, TEMPLATE_URL), 'utf8');
|
|
153
|
-
return
|
|
301
|
+
return ejsLib.render(template, data);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
async function renderShared(templateName, data) {
|
|
305
|
+
const template = await readFile(new URL(templateName, SHARED_TEMPLATE_URL), 'utf8');
|
|
306
|
+
return ejsLib.render(template, data);
|
|
154
307
|
}
|
|
155
308
|
|
|
156
309
|
function renderFunction(descriptor) {
|
|
@@ -4,19 +4,26 @@ const ACTIONS = ['Create', 'Update', 'Delete', 'Get'];
|
|
|
4
4
|
const MESSAGE_ATTRIBUTES = ['userId', 'correlationId'];
|
|
5
5
|
|
|
6
6
|
export const dynamicCrudFlowSchemaPaths = ACTIONS.map(
|
|
7
|
-
action =>
|
|
7
|
+
(action) =>
|
|
8
|
+
`app/src/schemas/FlowSchemas/generateCode/FlowObjects/${action}.js`
|
|
8
9
|
);
|
|
9
10
|
|
|
10
11
|
export function emitDynamicCrudFlowSchemas({ objects, flows = [] }) {
|
|
11
12
|
if (!Array.isArray(objects) || !Array.isArray(flows)) {
|
|
12
13
|
throw new TypeError('objects and flows must be arrays');
|
|
13
14
|
}
|
|
14
|
-
if (
|
|
15
|
+
if (
|
|
16
|
+
!objects.some(
|
|
17
|
+
(object) =>
|
|
18
|
+
object?.generatedBy === 'userGenerated' ||
|
|
19
|
+
object?.generatedBy === 'systemGenerated'
|
|
20
|
+
)
|
|
21
|
+
) {
|
|
15
22
|
return [];
|
|
16
23
|
}
|
|
17
24
|
|
|
18
25
|
return ACTIONS.map((action, index) => {
|
|
19
|
-
const flow =
|
|
26
|
+
const flow = _createDynamicFlow(action, _hasBeforeLogicalStep(flows, action));
|
|
20
27
|
return {
|
|
21
28
|
path: dynamicCrudFlowSchemaPaths[index],
|
|
22
29
|
content: renderDynamicCrudFlowSchema(action, flow)
|
|
@@ -24,19 +31,21 @@ export function emitDynamicCrudFlowSchemas({ objects, flows = [] }) {
|
|
|
24
31
|
});
|
|
25
32
|
}
|
|
26
33
|
|
|
27
|
-
function
|
|
34
|
+
function _createDynamicFlow(action, hasBeforeLogicalStep) {
|
|
28
35
|
const outputTopic = action !== 'Get';
|
|
29
36
|
const flowSteps = [
|
|
30
37
|
{
|
|
31
38
|
stepName: 'start',
|
|
32
39
|
properties: [],
|
|
33
40
|
messageAttributes: MESSAGE_ATTRIBUTES,
|
|
34
|
-
...(outputTopic
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
41
|
+
...(outputTopic
|
|
42
|
+
? {
|
|
43
|
+
returnValues: {
|
|
44
|
+
properties: [],
|
|
45
|
+
messageAttributes: MESSAGE_ATTRIBUTES
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
: {})
|
|
40
49
|
}
|
|
41
50
|
];
|
|
42
51
|
|
|
@@ -48,6 +57,7 @@ function createDynamicFlow(action, hasBeforeLogicalStep) {
|
|
|
48
57
|
messageAttributes: MESSAGE_ATTRIBUTES
|
|
49
58
|
});
|
|
50
59
|
}
|
|
60
|
+
|
|
51
61
|
if (action !== 'Get') {
|
|
52
62
|
flowSteps.push({
|
|
53
63
|
stepName: 'Complete',
|
|
@@ -57,12 +67,17 @@ function createDynamicFlow(action, hasBeforeLogicalStep) {
|
|
|
57
67
|
});
|
|
58
68
|
}
|
|
59
69
|
|
|
70
|
+
let eventTypes = ['lambdaSyncInv', 'lambdaSyncApi'];
|
|
71
|
+
if (outputTopic) {
|
|
72
|
+
eventTypes = ['ownTopic'];
|
|
73
|
+
}
|
|
74
|
+
|
|
60
75
|
return {
|
|
61
76
|
flowTag: action,
|
|
62
77
|
initiateBy: 'system',
|
|
63
78
|
handleObj: 'one',
|
|
64
79
|
statusType: 'none',
|
|
65
|
-
event:
|
|
80
|
+
event: eventTypes,
|
|
66
81
|
outputTopic,
|
|
67
82
|
stepMessageAttributes: {
|
|
68
83
|
userId: { propertyName: 'x-correlation-base-user-id', type: 'string' },
|
|
@@ -72,12 +87,14 @@ function createDynamicFlow(action, hasBeforeLogicalStep) {
|
|
|
72
87
|
};
|
|
73
88
|
}
|
|
74
89
|
|
|
75
|
-
function
|
|
76
|
-
return flows.some(flow => {
|
|
90
|
+
function _hasBeforeLogicalStep(flows, action) {
|
|
91
|
+
return flows.some((flow) => {
|
|
77
92
|
const config = flow?.generatedCodeConfig;
|
|
78
|
-
return
|
|
79
|
-
|
|
80
|
-
&&
|
|
81
|
-
|
|
93
|
+
return (
|
|
94
|
+
config?.generatedCodeTag === action.toLowerCase() &&
|
|
95
|
+
config.codeHookTag === 'beforeLogical' &&
|
|
96
|
+
Array.isArray(flow.event) &&
|
|
97
|
+
flow.event.includes(config.invocationType)
|
|
98
|
+
);
|
|
82
99
|
});
|
|
83
100
|
}
|
|
@@ -2,15 +2,23 @@ import { buildGenerationPlan } from '../../plan/buildGenerationPlan.js';
|
|
|
2
2
|
import { commitArtifacts } from '../../output/commitArtifacts.js';
|
|
3
3
|
import { compileProject } from '../../compile/compileProject.js';
|
|
4
4
|
import { loadLocalSchemaArrays } from './loadLocalSchemaArrays.js';
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
crudApplicationManagedPaths,
|
|
7
|
+
emitCrudApplicationArtifacts
|
|
8
|
+
} from './emitCrudApplicationArtifacts.js';
|
|
6
9
|
|
|
7
10
|
export async function generateCrudApplicationArtifacts(rootPath, options = {}) {
|
|
8
11
|
const project = compileProject({ ...options, rootPath });
|
|
9
12
|
const schemas = await loadLocalSchemaArrays(project);
|
|
10
|
-
const artifacts = await emitCrudApplicationArtifacts({
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
const artifacts = await emitCrudApplicationArtifacts({
|
|
14
|
+
...schemas,
|
|
15
|
+
serviceTag: project.serviceTag
|
|
16
|
+
});
|
|
17
|
+
const files = await commitArtifacts(
|
|
18
|
+
buildGenerationPlan(project, artifacts, {
|
|
19
|
+
managedPaths: crudApplicationManagedPaths(),
|
|
20
|
+
managedScope: 'crud-application'
|
|
21
|
+
})
|
|
22
|
+
);
|
|
15
23
|
return { project, files };
|
|
16
24
|
}
|
|
@@ -13,7 +13,10 @@ export async function generateDynamicCrudFlowSchemas(rootPath, options = {}) {
|
|
|
13
13
|
const plan = buildGenerationPlan(
|
|
14
14
|
project,
|
|
15
15
|
emitDynamicCrudFlowSchemas(schemaInputs),
|
|
16
|
-
{
|
|
16
|
+
{
|
|
17
|
+
managedPaths: dynamicCrudFlowSchemaPaths,
|
|
18
|
+
managedScope: 'crud-flow-schemas'
|
|
19
|
+
}
|
|
17
20
|
);
|
|
18
21
|
const files = await commitArtifacts(plan);
|
|
19
22
|
|