@izara_project/izara-core-generate-service-code 1.0.67 → 1.0.69
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/.prettierrc +11 -0
- package/package.json +16 -12
- package/scripts/format-ejs.js +104 -0
- package/src/compile/compileProject.js +40 -9
- package/src/compile/loadSchemas.js +120 -11
- package/src/emit/crud/emitCrudApplicationArtifacts.js +188 -41
- package/src/emit/crud/emitDynamicCrudFlowSchemas.js +34 -18
- package/src/emit/crud/generateCrudApplicationArtifacts.js +14 -6
- package/src/emit/crud/generateDynamicCrudFlowSchemas.js +4 -1
- package/src/emit/crud/templates/CreateEndpoint_Main.ejs +296 -105
- package/src/emit/crud/templates/DeleteEndpoint_Main.ejs +222 -144
- package/src/emit/crud/templates/FlowEndpointBeforeLogical_Main.ejs +22 -6
- package/src/emit/crud/templates/FlowEndpointComplete_Main.ejs +134 -43
- package/src/emit/crud/templates/FlowEndpoint_HdrWbs.ejs +51 -31
- package/src/emit/crud/templates/FlowHandler_HdrApi.ejs +53 -45
- package/src/emit/crud/templates/FlowHandler_HdrInv.ejs +28 -26
- package/src/emit/crud/templates/FlowHandler_HdrSqs.ejs +15 -11
- package/src/emit/crud/templates/FlowMain_Wbs.ejs +53 -38
- package/src/emit/crud/templates/GetEndpoint_Main.ejs +6 -3
- package/src/emit/crud/templates/GetRangeEndpoint_Main.ejs +2 -2
- package/src/emit/crud/templates/UpdateEndpoint_Main.ejs +402 -249
- package/src/emit/custom/customFlows.js +68 -28
- package/src/emit/custom/emitCustomFlowApplicationArtifacts.js +520 -123
- package/src/emit/custom/generateCustomFlowApplicationArtifacts.js +28 -8
- package/src/emit/custom/templates/FlowEndpoint_Main.ejs +48 -36
- package/src/emit/custom/templates/FlowStep_Main.ejs +7 -9
- package/src/emit/custom/templates/s3/ConfirmReserved_HdrSqs.ejs +59 -54
- package/src/emit/custom/templates/s3/ConfirmReserved_Main.ejs +33 -23
- package/src/emit/custom/templates/s3/CreateObject_HdrWbs.ejs +30 -23
- package/src/emit/custom/templates/s3/CreateObject_Main.ejs +56 -39
- package/src/emit/custom/templates/s3/CreatePreSignUrl_HdrSqs.ejs +56 -51
- package/src/emit/custom/templates/s3/CreatePreSignUrl_Main.ejs +112 -75
- package/src/emit/custom/templates/s3/FlowHandler_HdrS3.ejs +14 -9
- package/src/emit/custom/templates/s3/ProcessS3File_Main.ejs +11 -8
- package/src/emit/custom/templates/s3/ReservedLimit_HdrSqs.ejs +65 -56
- package/src/emit/custom/templates/s3/ReservedLimit_Main.ejs +74 -52
- package/src/emit/custom/templates/triggerCache/CheckTriggerCache_HdrSqs.ejs +58 -14
- package/src/emit/custom/templates/triggerCache/CheckTriggerCache_Main.ejs +12 -17
- package/src/emit/custom/templates/triggerCache/TriggerCacheComplete_Main.ejs +20 -13
- package/src/emit/custom/templates/triggerCache/TriggerCache_Main.ejs +4 -1
- package/src/emit/function/functionYamlArtifact.js +272 -79
- 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 +40 -29
- package/src/emit/rbac/emitRbacApplicationArtifacts.js +171 -72
- 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/CreateTargetRole_HdrSqs.ejs +41 -18
- package/src/emit/rbac/templates/CreateTargetRole_Main.ejs +23 -3
- package/src/emit/rbac/templates/ListRbac_HdrApi.ejs +27 -5
- package/src/emit/rbac/templates/ListRbac_HdrSqs.ejs +41 -8
- package/src/emit/rbac/templates/ListRbac_Main.ejs +26 -6
- package/src/emit/rbac/templates/RbacMutation_Main.ejs +23 -3
- package/src/emit/rbac/templates/UserRbacFlow_HdrSqs.ejs +46 -0
- package/src/emit/rbac/templates/UserRbacFlow_Main.ejs +152 -33
- package/src/emit/rbac/templates/UserRoleMutation_Main.ejs +24 -4
- package/src/emit/relationship/emitDynamicRelationshipFlowSchemas.js +26 -11
- package/src/emit/relationship/emitRelationshipApplicationArtifacts.js +179 -37
- package/src/emit/relationship/generateDynamicRelationshipFlowSchemas.js +8 -2
- package/src/emit/relationship/generateRelationshipApplicationArtifacts.js +15 -6
- package/src/emit/relationship/templates/ChangeRelationshipComplete_Main.ejs +64 -37
- package/src/emit/relationship/templates/ChangeRelationship_Main.ejs +258 -142
- package/src/emit/relationship/templates/CreateRelationshipComplete_Main.ejs +68 -43
- package/src/emit/relationship/templates/CreateRelationship_Main.ejs +315 -171
- package/src/emit/relationship/templates/DeleteRelationshipComplete_Main.ejs +67 -41
- package/src/emit/relationship/templates/DeleteRelationship_Main.ejs +226 -115
- package/src/emit/relationship/templates/FlowHandler_HdrApi.ejs +41 -33
- package/src/emit/relationship/templates/FlowHandler_HdrDsq.ejs +15 -11
- package/src/emit/relationship/templates/FlowHandler_HdrInv.ejs +28 -26
- package/src/emit/relationship/templates/FlowHandler_HdrSqs.ejs +15 -11
- package/src/emit/relationship/templates/GetRelationshipComplete_Main.ejs +46 -26
- package/src/emit/relationship/templates/GetRelationship_Main.ejs +233 -126
- package/src/emit/relationship/templates/MoveRelationshipComplete_Main.ejs +72 -44
- package/src/emit/relationship/templates/MoveRelationship_Main.ejs +266 -150
- package/src/emit/relationship/templates/UpdateRelationshipComplete_Main.ejs +74 -45
- package/src/emit/relationship/templates/UpdateRelationship_Main.ejs +285 -152
- package/src/emit/resource/emitResourceArtifacts.js +274 -105
- package/src/emit/resource/generateResourceArtifacts.js +15 -6
- package/src/emit/resource/templates/GeneratedLambdaRoleServiceConfig.ejs +139 -0
- package/src/emit/resource/templates/S3Bucket_Yaml.ejs +19 -0
- package/src/emit/resource/templates/S3Subscription_Yaml.ejs +7 -0
- package/src/emit/resource/templates/WebSocketSubscription_Yaml.ejs +7 -0
- package/src/emit/system/emitSystemWebSocketArtifacts.js +61 -165
- package/src/emit/system/templates/WebSocketComplete_HdrSqs.ejs +32 -0
- package/src/emit/system/templates/WebSocketComplete_Main.ejs +46 -0
- package/src/emit/system/templates/WebSocketComplete_Yaml.ejs +19 -0
- package/src/emit/system/templates/WebSocketConnect.ejs +25 -0
- package/src/emit/system/templates/WebSocketConnect_Yaml.ejs +11 -0
- package/src/generate.js +141 -34
- 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 +24 -10
- package/src/output/validateArtifacts.js +37 -27
- package/src/plan/buildGenerationPlan.js +24 -13
- package/test/core.test.js +116 -49
- package/test/createTargetRoleHandler.test.js +63 -14
- package/test/crudApplicationArtifacts.test.js +128 -23
- package/test/customFlowApplicationArtifacts.test.js +391 -84
- package/test/dynamicCrudFlowSchemas.test.js +74 -26
- package/test/dynamicRbacFlowSchemas.test.js +63 -20
- 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 +184 -44
- package/test/relationshipApplicationArtifacts.test.js +90 -19
- package/test/resourceArtifacts.test.js +183 -33
- package/docs/test.png +0 -0
- package/src/emit/rbac/templates/UserRbacFlow_HdrInv.ejs +0 -10
- package/src/emit/relationship/dynamicRelationshipFlowSchemaTemplate.js +0 -11
- /package/docs/{test.mmd → TriggeredCacheFlow.mmd} +0 -0
package/src/generate.js
CHANGED
|
@@ -1,16 +1,47 @@
|
|
|
1
1
|
import { buildGenerationPlan } from './plan/buildGenerationPlan.js';
|
|
2
2
|
import { commitArtifacts } from './output/commitArtifacts.js';
|
|
3
3
|
import { compileProject } from './compile/compileProject.js';
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
import {
|
|
13
|
-
|
|
4
|
+
import {
|
|
5
|
+
crudApplicationManagedPaths,
|
|
6
|
+
emitCrudApplicationArtifacts
|
|
7
|
+
} from './emit/crud/emitCrudApplicationArtifacts.js';
|
|
8
|
+
import {
|
|
9
|
+
dynamicCrudFlowSchemaPaths,
|
|
10
|
+
emitDynamicCrudFlowSchemas
|
|
11
|
+
} from './emit/crud/emitDynamicCrudFlowSchemas.js';
|
|
12
|
+
import {
|
|
13
|
+
customFlowApplicationManagedPaths,
|
|
14
|
+
emitCustomFlowApplicationArtifacts
|
|
15
|
+
} from './emit/custom/emitCustomFlowApplicationArtifacts.js';
|
|
16
|
+
import {
|
|
17
|
+
emitDynamicRbacFlowSchemas,
|
|
18
|
+
rbacFlowSchemaManagedPaths
|
|
19
|
+
} from './emit/rbac/emitDynamicRbacFlowSchemas.js';
|
|
20
|
+
import {
|
|
21
|
+
emitRbacApplicationArtifacts,
|
|
22
|
+
rbacApplicationManagedPaths
|
|
23
|
+
} from './emit/rbac/emitRbacApplicationArtifacts.js';
|
|
24
|
+
import {
|
|
25
|
+
dynamicRelationshipFlowSchemaPaths,
|
|
26
|
+
emitDynamicRelationshipFlowSchemas
|
|
27
|
+
} from './emit/relationship/emitDynamicRelationshipFlowSchemas.js';
|
|
28
|
+
import {
|
|
29
|
+
emitRelationshipApplicationArtifacts,
|
|
30
|
+
relationshipApplicationManagedPaths
|
|
31
|
+
} from './emit/relationship/emitRelationshipApplicationArtifacts.js';
|
|
32
|
+
import {
|
|
33
|
+
emitResourceArtifacts,
|
|
34
|
+
resourceArtifactPaths
|
|
35
|
+
} from './emit/resource/emitResourceArtifacts.js';
|
|
36
|
+
import {
|
|
37
|
+
loadLocalSchemaDirectory,
|
|
38
|
+
resolveExtendedObjectSchemas
|
|
39
|
+
} from './compile/loadSchemas.js';
|
|
40
|
+
import {
|
|
41
|
+
emitSystemWebSocketArtifacts,
|
|
42
|
+
hasSystemWebSocket,
|
|
43
|
+
systemWebSocketManagedPaths
|
|
44
|
+
} from './emit/system/emitSystemWebSocketArtifacts.js';
|
|
14
45
|
|
|
15
46
|
export async function generate(rootPath, options = {}) {
|
|
16
47
|
const startedAt = Date.now();
|
|
@@ -18,47 +49,123 @@ export async function generate(rootPath, options = {}) {
|
|
|
18
49
|
logger?.info?.(`[INFO] [Generate] STATUS=STARTED | rootPath=${rootPath}`);
|
|
19
50
|
try {
|
|
20
51
|
const project = compileProject({ ...options, rootPath });
|
|
21
|
-
const [
|
|
52
|
+
const [rawObjects, relationships, flows] = await Promise.all([
|
|
22
53
|
loadLocalSchemaDirectory(project, 'ObjectSchemas'),
|
|
23
54
|
loadLocalSchemaDirectory(project, 'RelationshipSchemas'),
|
|
24
55
|
loadLocalSchemaDirectory(project, 'FlowSchemas')
|
|
25
56
|
]);
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
57
|
+
const objects = await resolveExtendedObjectSchemas(
|
|
58
|
+
rawObjects,
|
|
59
|
+
options.schemaBucketName
|
|
60
|
+
);
|
|
61
|
+
logger?.debug?.(
|
|
62
|
+
`[DEBUG] [Generate] STATUS=SCHEMAS_LOADED | objects=${objects.length} relationships=${relationships.length} flows=${flows.length}`
|
|
63
|
+
);
|
|
64
|
+
const groups = await _emitGroups({ project, objects, relationships, flows });
|
|
65
|
+
logger?.debug?.(
|
|
66
|
+
`[DEBUG] [Generate] STATUS=ARTIFACTS_EMITTED | ${groups.map((group) => `${group.scope}=${group.artifacts.length}`).join(' ')}`
|
|
67
|
+
);
|
|
68
|
+
let files = [];
|
|
69
|
+
if (groups.length > 0) {
|
|
70
|
+
files = await commitArtifacts(
|
|
71
|
+
buildGenerationPlan(
|
|
72
|
+
project,
|
|
73
|
+
groups.flatMap((group) => group.artifacts),
|
|
74
|
+
{
|
|
75
|
+
managedScopes: Object.fromEntries(
|
|
76
|
+
groups.map((group) => [group.scope, group.managedPaths])
|
|
77
|
+
)
|
|
78
|
+
}
|
|
79
|
+
)
|
|
80
|
+
);
|
|
81
|
+
}
|
|
34
82
|
const durationMs = Date.now() - startedAt;
|
|
35
|
-
logger?.info?.(
|
|
83
|
+
logger?.info?.(
|
|
84
|
+
`[INFO] [Generate] STATUS=FINISHED | files=${files.length} durationMs=${durationMs}`
|
|
85
|
+
);
|
|
36
86
|
|
|
37
87
|
return { project, durationMs, files };
|
|
38
88
|
} catch (error) {
|
|
39
|
-
logger?.error?.(
|
|
89
|
+
logger?.error?.(
|
|
90
|
+
`[ERROR] [Generate] STATUS=FAILED | durationMs=${Date.now() - startedAt}`,
|
|
91
|
+
error
|
|
92
|
+
);
|
|
40
93
|
throw error;
|
|
41
94
|
}
|
|
42
95
|
}
|
|
43
96
|
|
|
44
|
-
async function
|
|
97
|
+
async function _emitGroups({ project, objects, relationships, flows }) {
|
|
45
98
|
const [crud, relationship, rbac, system, resource] = await Promise.all([
|
|
46
|
-
emitCrudApplicationArtifacts({
|
|
47
|
-
|
|
99
|
+
emitCrudApplicationArtifacts({
|
|
100
|
+
objects,
|
|
101
|
+
flows,
|
|
102
|
+
serviceTag: project.serviceTag
|
|
103
|
+
}),
|
|
104
|
+
emitRelationshipApplicationArtifacts({
|
|
105
|
+
relationships,
|
|
106
|
+
flows,
|
|
107
|
+
serviceTag: project.serviceTag
|
|
108
|
+
}),
|
|
48
109
|
emitRbacApplicationArtifacts(objects),
|
|
49
110
|
emitSystemWebSocketArtifacts(flows, { includeRelationshipOwnTopic: true }),
|
|
50
111
|
emitResourceArtifacts({ objects, relationships, flows })
|
|
51
112
|
]);
|
|
52
|
-
const custom = await emitCustomFlowApplicationArtifacts(flows, {
|
|
113
|
+
const custom = await emitCustomFlowApplicationArtifacts(flows, {
|
|
114
|
+
systemFunctions: system.functions,
|
|
115
|
+
objects
|
|
116
|
+
});
|
|
53
117
|
return [
|
|
54
|
-
{
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
{
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
118
|
+
{
|
|
119
|
+
scope: 'crud-flow-schemas',
|
|
120
|
+
managedPaths: dynamicCrudFlowSchemaPaths,
|
|
121
|
+
artifacts: emitDynamicCrudFlowSchemas({ objects, flows })
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
scope: 'relationship-flow-schemas',
|
|
125
|
+
managedPaths: dynamicRelationshipFlowSchemaPaths,
|
|
126
|
+
artifacts: emitDynamicRelationshipFlowSchemas()
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
scope: 'rbac-flow-schemas',
|
|
130
|
+
managedPaths: rbacFlowSchemaManagedPaths(objects),
|
|
131
|
+
artifacts: await emitDynamicRbacFlowSchemas({
|
|
132
|
+
objects,
|
|
133
|
+
serviceTag: project.serviceTag
|
|
134
|
+
})
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
scope: 'crud-application',
|
|
138
|
+
managedPaths: crudApplicationManagedPaths(),
|
|
139
|
+
artifacts: crud
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
scope: 'relationship-application',
|
|
143
|
+
managedPaths: relationshipApplicationManagedPaths(),
|
|
144
|
+
artifacts: relationship
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
scope: 'rbac-application',
|
|
148
|
+
managedPaths: rbacApplicationManagedPaths(objects),
|
|
149
|
+
artifacts: rbac
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
scope: 'system-websocket',
|
|
153
|
+
managedPaths: systemWebSocketManagedPaths(),
|
|
154
|
+
artifacts: system.artifacts
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
scope: 'custom-flow-application',
|
|
158
|
+
managedPaths: customFlowApplicationManagedPaths(flows, {
|
|
159
|
+
includeYaml: hasSystemWebSocket(flows, {
|
|
160
|
+
includeRelationshipOwnTopic: true
|
|
161
|
+
})
|
|
162
|
+
}),
|
|
163
|
+
artifacts: custom
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
scope: 'shared-resources',
|
|
167
|
+
managedPaths: resourceArtifactPaths,
|
|
168
|
+
artifacts: resource
|
|
169
|
+
}
|
|
63
170
|
];
|
|
64
171
|
}
|
package/src/generateIntTest.js
CHANGED
|
@@ -14,14 +14,27 @@ You should have received a copy of the GNU Affero General Public License
|
|
|
14
14
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import {
|
|
17
|
+
import {
|
|
18
|
+
appendFileSync,
|
|
19
|
+
existsSync,
|
|
20
|
+
mkdirSync,
|
|
21
|
+
readFileSync,
|
|
22
|
+
writeFileSync
|
|
23
|
+
} from 'fs';
|
|
18
24
|
import { join } from 'path';
|
|
19
|
-
import
|
|
25
|
+
import ejsLib from 'ejs';
|
|
20
26
|
import beautify from 'js-beautify/js/index.js';
|
|
21
27
|
|
|
22
28
|
import generateTestTemplate from './generateResources/IntTest/generateTests/generateTemplate.js';
|
|
23
|
-
import {
|
|
24
|
-
|
|
29
|
+
import {
|
|
30
|
+
DEFAULT_BUCKET,
|
|
31
|
+
uploadToS3
|
|
32
|
+
} from './generateResources/IntTest/upload/uploadIntTest.js';
|
|
33
|
+
import {
|
|
34
|
+
getIntTestOutputPath,
|
|
35
|
+
getServiceTag,
|
|
36
|
+
runTemplateItems
|
|
37
|
+
} from './intTestGeneratorShared.js';
|
|
25
38
|
|
|
26
39
|
const BEAUTIFY_SETTING = {
|
|
27
40
|
indent_size: '2',
|
|
@@ -33,9 +46,14 @@ const BEAUTIFY_SETTING = {
|
|
|
33
46
|
space_before_conditional: true
|
|
34
47
|
};
|
|
35
48
|
|
|
36
|
-
async function
|
|
49
|
+
async function _writeSource(
|
|
50
|
+
{ templatePath, templateData, setting },
|
|
51
|
+
{ checkCreateSourcePass = false } = {}
|
|
52
|
+
) {
|
|
37
53
|
if (!templatePath || !templateData || !setting) {
|
|
38
|
-
throw new Error(
|
|
54
|
+
throw new Error(
|
|
55
|
+
'Invalid IntTest source item: missing templatePath/templateData/setting'
|
|
56
|
+
);
|
|
39
57
|
}
|
|
40
58
|
|
|
41
59
|
const {
|
|
@@ -50,7 +68,7 @@ async function writeSource({ templatePath, templateData, setting }, { checkCreat
|
|
|
50
68
|
|
|
51
69
|
if (checkCreateSourcePass) {
|
|
52
70
|
try {
|
|
53
|
-
|
|
71
|
+
ejsLib.compile(readFileSync(templatePath, 'utf8'))(templateData);
|
|
54
72
|
return [true, {}];
|
|
55
73
|
} catch (error) {
|
|
56
74
|
return [false, error];
|
|
@@ -63,36 +81,60 @@ async function writeSource({ templatePath, templateData, setting }, { checkCreat
|
|
|
63
81
|
const filePath = `${savePath}${saveFileName}${fileExtension}`.trim();
|
|
64
82
|
const hookFilePath = `${hookDataPath}${saveFileName}${fileExtension}`.trim();
|
|
65
83
|
|
|
66
|
-
if (!existsSync(savePath))
|
|
67
|
-
|
|
84
|
+
if (!existsSync(savePath)) {
|
|
85
|
+
mkdirSync(savePath, { recursive: true });
|
|
86
|
+
}
|
|
87
|
+
if (generateHookFile && !existsSync(hookDataPath)) {
|
|
88
|
+
mkdirSync(hookDataPath, { recursive: true });
|
|
89
|
+
}
|
|
68
90
|
|
|
69
|
-
let dataToSave =
|
|
91
|
+
let dataToSave = ejsLib.compile(readFileSync(templatePath, 'utf8'))(
|
|
92
|
+
templateData
|
|
93
|
+
);
|
|
70
94
|
|
|
71
95
|
if (existsSync(hookFilePath)) {
|
|
72
96
|
const hookData = readFileSync(hookFilePath, 'utf8');
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
97
|
+
let anyDoubleTag = null;
|
|
98
|
+
let doubleTag = null;
|
|
99
|
+
|
|
100
|
+
if (isJs) {
|
|
101
|
+
anyDoubleTag = new RegExp(
|
|
102
|
+
'\\/\\/\\(<(\\w+)>\\)([\\s\\S]*?)\\/\\/\\(<\\/\\1>\\)',
|
|
103
|
+
'gm'
|
|
104
|
+
);
|
|
105
|
+
doubleTag = (name) =>
|
|
106
|
+
new RegExp(
|
|
107
|
+
`\\/\\/\\(<${name}>\\)([\\s\\S]*?)\\/\\/\\(<\\/${name}>\\)`,
|
|
108
|
+
'gm'
|
|
109
|
+
);
|
|
110
|
+
} else if (isYml) {
|
|
111
|
+
anyDoubleTag = new RegExp(
|
|
112
|
+
'\\#<#(\\w+)#>([\\s\\S]*?)\\#<#\\/\\1#>',
|
|
113
|
+
'gm'
|
|
114
|
+
);
|
|
115
|
+
doubleTag = (name) =>
|
|
116
|
+
new RegExp(`\\#<#${name}#>([\\s\\S]*?)\\#<#\\/${name}#>`, 'gm');
|
|
117
|
+
}
|
|
83
118
|
|
|
84
119
|
if (anyDoubleTag && doubleTag) {
|
|
85
|
-
dataToSave = dataToSave.replace(
|
|
86
|
-
|
|
87
|
-
|
|
120
|
+
dataToSave = dataToSave.replace(
|
|
121
|
+
anyDoubleTag,
|
|
122
|
+
(match, tagName) => hookData.match(doubleTag(tagName)) ?? match
|
|
123
|
+
);
|
|
88
124
|
}
|
|
89
125
|
}
|
|
90
126
|
|
|
91
|
-
if (isJs)
|
|
127
|
+
if (isJs) {
|
|
128
|
+
dataToSave = beautify(dataToSave, BEAUTIFY_SETTING);
|
|
129
|
+
}
|
|
92
130
|
|
|
93
131
|
if (isAppend) {
|
|
94
132
|
const shouldWriteWithInitial = !existsSync(filePath) && initialData;
|
|
95
|
-
|
|
133
|
+
let initialPrefix = '';
|
|
134
|
+
if (shouldWriteWithInitial) {
|
|
135
|
+
initialPrefix = initialData;
|
|
136
|
+
}
|
|
137
|
+
const content = `${initialPrefix}${dataToSave}\n\n`;
|
|
96
138
|
|
|
97
139
|
if (shouldWriteWithInitial) {
|
|
98
140
|
writeFileSync(filePath, content, 'utf8');
|
|
@@ -139,7 +181,9 @@ export async function generateIntTest(rootPath, options = {}) {
|
|
|
139
181
|
const startTime = Date.now();
|
|
140
182
|
const serviceTag = getServiceTag(rootPath);
|
|
141
183
|
if (!serviceTag) {
|
|
142
|
-
throw new Error(
|
|
184
|
+
throw new Error(
|
|
185
|
+
'Missing iz_serviceTag in serverless.config.yml — required IntTest generation'
|
|
186
|
+
);
|
|
143
187
|
}
|
|
144
188
|
|
|
145
189
|
const savePath = getIntTestOutputPath(outputPath, rootPath);
|
|
@@ -150,7 +194,7 @@ export async function generateIntTest(rootPath, options = {}) {
|
|
|
150
194
|
});
|
|
151
195
|
|
|
152
196
|
await runTemplateItems(items, {
|
|
153
|
-
writeSource,
|
|
197
|
+
writeSource: _writeSource,
|
|
154
198
|
errorPrefix: 'IntTest source'
|
|
155
199
|
});
|
|
156
200
|
|
|
@@ -164,11 +208,15 @@ export async function generateIntTest(rootPath, options = {}) {
|
|
|
164
208
|
}
|
|
165
209
|
|
|
166
210
|
const durationMs = Date.now() - startTime;
|
|
211
|
+
let targetBucket = null;
|
|
212
|
+
if (shouldUploadToS3) {
|
|
213
|
+
targetBucket = s3Bucket;
|
|
214
|
+
}
|
|
167
215
|
return {
|
|
168
216
|
serviceTag,
|
|
169
217
|
count: items.length,
|
|
170
218
|
durationMs,
|
|
171
219
|
uploadedCount: uploadedKeys.length,
|
|
172
|
-
s3Bucket:
|
|
220
|
+
s3Bucket: targetBucket
|
|
173
221
|
};
|
|
174
222
|
}
|
|
@@ -16,22 +16,34 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16
16
|
|
|
17
17
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
|
|
18
18
|
import { join } from 'path';
|
|
19
|
-
import
|
|
19
|
+
import ejsLib from 'ejs';
|
|
20
20
|
|
|
21
21
|
import generateResourceTemplate from './generateResources/IntTest/generateResources/generateResources.js';
|
|
22
|
-
import {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
import {
|
|
23
|
+
DEFAULT_BUCKET,
|
|
24
|
+
uploadToS3
|
|
25
|
+
} from './generateResources/IntTest/upload/uploadIntTest.js';
|
|
26
|
+
import {
|
|
27
|
+
getIntTestOutputPath,
|
|
28
|
+
getServiceTag,
|
|
29
|
+
runTemplateItems
|
|
30
|
+
} from './intTestGeneratorShared.js';
|
|
31
|
+
|
|
32
|
+
function _writeSource(
|
|
33
|
+
{ templatePath, templateData, setting },
|
|
34
|
+
{ checkCreateSourcePass = false } = {}
|
|
35
|
+
) {
|
|
26
36
|
if (!templatePath || !templateData || !setting) {
|
|
27
|
-
throw new Error(
|
|
37
|
+
throw new Error(
|
|
38
|
+
'Invalid IntTest resource item: missing templatePath/templateData/setting'
|
|
39
|
+
);
|
|
28
40
|
}
|
|
29
41
|
|
|
30
42
|
const { savePath, saveFileName, fileExtension } = setting;
|
|
31
43
|
|
|
32
44
|
if (checkCreateSourcePass) {
|
|
33
45
|
try {
|
|
34
|
-
|
|
46
|
+
ejsLib.compile(readFileSync(templatePath, 'utf8'))(templateData);
|
|
35
47
|
return [true, {}];
|
|
36
48
|
} catch (error) {
|
|
37
49
|
return [false, error];
|
|
@@ -41,7 +53,9 @@ function writeSource({ templatePath, templateData, setting }, { checkCreateSourc
|
|
|
41
53
|
const filePath = `${savePath}${saveFileName}${fileExtension}`.trim();
|
|
42
54
|
if (!existsSync(savePath)) mkdirSync(savePath, { recursive: true });
|
|
43
55
|
|
|
44
|
-
const dataToSave =
|
|
56
|
+
const dataToSave = ejsLib.compile(readFileSync(templatePath, 'utf8'))(
|
|
57
|
+
templateData
|
|
58
|
+
);
|
|
45
59
|
writeFileSync(filePath, dataToSave, 'utf8');
|
|
46
60
|
return [true, {}];
|
|
47
61
|
}
|
|
@@ -78,14 +92,18 @@ export async function generateResourceIntTest(rootPath, options = {}) {
|
|
|
78
92
|
const startTime = Date.now();
|
|
79
93
|
const serviceTag = getServiceTag(rootPath);
|
|
80
94
|
if (!serviceTag) {
|
|
81
|
-
throw new Error(
|
|
95
|
+
throw new Error(
|
|
96
|
+
'Missing iz_serviceTag in serverless.config.yml — required IntTest resource generation'
|
|
97
|
+
);
|
|
82
98
|
}
|
|
83
99
|
|
|
84
100
|
const savePath = getIntTestOutputPath(outputPath, rootPath);
|
|
85
|
-
const items = await generateResourceTemplate(_izContext, savePath, {
|
|
101
|
+
const items = await generateResourceTemplate(_izContext, savePath, {
|
|
102
|
+
serviceTag
|
|
103
|
+
});
|
|
86
104
|
|
|
87
105
|
await runTemplateItems(items, {
|
|
88
|
-
writeSource,
|
|
106
|
+
writeSource: _writeSource,
|
|
89
107
|
errorPrefix: 'IntTest resource'
|
|
90
108
|
});
|
|
91
109
|
|
|
@@ -98,12 +116,17 @@ export async function generateResourceIntTest(rootPath, options = {}) {
|
|
|
98
116
|
});
|
|
99
117
|
}
|
|
100
118
|
|
|
119
|
+
let resultBucket = null;
|
|
120
|
+
if (shouldUploadToS3) {
|
|
121
|
+
resultBucket = s3Bucket;
|
|
122
|
+
}
|
|
123
|
+
|
|
101
124
|
const durationMs = Date.now() - startTime;
|
|
102
125
|
return {
|
|
103
126
|
serviceTag,
|
|
104
127
|
count: items.length,
|
|
105
128
|
durationMs,
|
|
106
129
|
uploadedCount: uploadedKeys.length,
|
|
107
|
-
s3Bucket:
|
|
130
|
+
s3Bucket: resultBucket
|
|
108
131
|
};
|
|
109
132
|
}
|
|
@@ -20,8 +20,11 @@ import { fileURLToPath } from 'url';
|
|
|
20
20
|
const __filename = fileURLToPath(import.meta.url);
|
|
21
21
|
const __dirname = path.dirname(__filename);
|
|
22
22
|
|
|
23
|
-
import {
|
|
24
|
-
|
|
23
|
+
import {
|
|
24
|
+
getObjectSchema,
|
|
25
|
+
consts as coreConsts
|
|
26
|
+
} from '@izara_project/izara-core-library-service-schemas';
|
|
27
|
+
import libs from '../libs/IntTestGenerateLib.js';
|
|
25
28
|
const { directoryPath } = libs;
|
|
26
29
|
const { STORAGE_TYPES } = coreConsts;
|
|
27
30
|
const templatePath = path.join(__dirname, './templateResources.ejs');
|
|
@@ -1,33 +1,21 @@
|
|
|
1
|
-
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
"localHandler": "main",
|
|
7
|
-
"functionName": "<%= funcName %>"
|
|
8
|
-
}<%= index < array.length - 1 ? "," : "" %>
|
|
9
|
-
<% }) %>
|
|
10
|
-
}<%= Object.keys(s3Component).length || Object.keys(tableNames).length ? "," : "" %>
|
|
1
|
+
{ "Lambda": { <% Object.entries(functionComponent).forEach(([funcName,
|
|
2
|
+
filePath], index, array) => { %> "<%= funcName %>": { "localLocation": "/<%= filePath %>.js",
|
|
3
|
+
"localHandler": "main", "functionName": "<%= funcName %>" }<%= index < array.length - 1 ? "," : "" %>
|
|
4
|
+
<% }) %>
|
|
5
|
+
}<%= Object.keys(s3Component).length || Object.keys(tableNames).length ? "," : "" %>
|
|
11
6
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}<%= index < array.length - 1 ? "," : "" %>
|
|
20
|
-
<% }) %>
|
|
21
|
-
}<%= Object.keys(tableNames).length ? "," : "" %>
|
|
22
|
-
<% } %>
|
|
7
|
+
<% if (Object.keys(s3Component).length) { %>
|
|
8
|
+
"S3": { <% Object.entries(s3Component).forEach(([functionName, filePath], index,
|
|
9
|
+
array) => { %> "<%= functionName %>": { "localLocation": "/<%= filePath %>",
|
|
10
|
+
"localHandler": "main", "functionName": "<%= functionName %>" }<%= index < array.length - 1 ? "," : "" %>
|
|
11
|
+
<% }) %>
|
|
12
|
+
}<%= Object.keys(tableNames).length ? "," : "" %>
|
|
13
|
+
<% } %>
|
|
23
14
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
<% }) %>
|
|
31
|
-
}
|
|
32
|
-
<% } %>
|
|
15
|
+
<% if (Object.keys(tableNames).length) { %>
|
|
16
|
+
"Dynamodb": { <% tableNames.forEach((tableName, index) => { %> "<%= tableName %>":
|
|
17
|
+
{ "tableName": "<%= tableName %>" }<%= index < tableNames.length - 1 ? "," : "" %>
|
|
18
|
+
<% }) %>
|
|
19
|
+
}
|
|
20
|
+
<% } %>
|
|
33
21
|
}
|
|
@@ -21,7 +21,7 @@ const __filename = fileURLToPath(import.meta.url);
|
|
|
21
21
|
const __dirname = path.dirname(__filename);
|
|
22
22
|
const templatePath = path.join(__dirname, './templateEvents.ejs');
|
|
23
23
|
|
|
24
|
-
import libs from '../../libs/
|
|
24
|
+
import libs from '../../libs/IntTestGenerateLib.js';
|
|
25
25
|
const {
|
|
26
26
|
setEvent,
|
|
27
27
|
createEventCaseByHandler,
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
{ "<%- inputEventTag %>":
|
|
2
|
+
<%- JSON.stringify(inputConfig, null, 2) %>, "<%- outputEventTag %>":
|
|
3
|
+
<%- JSON.stringify(outputConfig, null, 2) %>
|
|
4
|
+
<%- eventDynamos.length ? "," : "" -%>
|
|
5
|
+
<% eventDynamos.forEach((eventDynamo,idx) => { %> "<%- eventDynamo.eventTag %>":
|
|
6
|
+
<%- JSON.stringify(eventDynamo.event,null,2) %>
|
|
7
|
+
<%- idx < eventDynamos.length - 1 ? ",": "" -%>
|
|
8
|
+
<% }) %>
|
|
9
|
+
<%- eventInvokes.length ? "," : "" -%>
|
|
10
|
+
<% eventInvokes.forEach((invokeEventComponent,index) => { %> "<%- invokeEventComponent.inputInvokeName %>":
|
|
11
|
+
<%- JSON.stringify(invokeEventComponent.inputInvoke,null,2) %>, "<%- invokeEventComponent.outputInvokeName %>":
|
|
12
|
+
<%- JSON.stringify(invokeEventComponent.outputInvoke,null,2) %><%- index < eventInvokes.length - 1 ? ",": "" -%>
|
|
13
|
+
<% }) %>
|
|
11
14
|
}
|
|
@@ -20,7 +20,7 @@ import generateEvent from './events/events.js';
|
|
|
20
20
|
import generateTest from './tests/tests.js';
|
|
21
21
|
import generatePathIntTest from './pathIntTest/pathIntTest.js';
|
|
22
22
|
// import generateBashScript from './bashScript/data.js'
|
|
23
|
-
import libs from '../libs/
|
|
23
|
+
import libs from '../libs/IntTestGenerateLib.js';
|
|
24
24
|
const { getIntTestConfig } = libs;
|
|
25
25
|
|
|
26
26
|
/**
|
|
@@ -66,7 +66,7 @@ async function generateCodeWithTemplate(_izContext, savePath, settings) {
|
|
|
66
66
|
allCreateSource.push(
|
|
67
67
|
...[event, test, intTestBucketPath]
|
|
68
68
|
.flat()
|
|
69
|
-
.filter(item => !(Array.isArray(item) && item.length === 0))
|
|
69
|
+
.filter((item) => !(Array.isArray(item) && item.length === 0))
|
|
70
70
|
);
|
|
71
71
|
|
|
72
72
|
return allCreateSource;
|
|
@@ -21,7 +21,8 @@ import { bucketPathForUpload } from '../../upload/uploadIntTest.js';
|
|
|
21
21
|
const __filename = fileURLToPath(import.meta.url);
|
|
22
22
|
const __dirname = path.dirname(__filename);
|
|
23
23
|
const templatePath = path.join(__dirname, './template.ejs');
|
|
24
|
-
const INT_TEST_SUFFIX_PATTERN =
|
|
24
|
+
const INT_TEST_SUFFIX_PATTERN =
|
|
25
|
+
/(events|tests|resources|dynamoDBSeedDataTags|graphSeedDataTags)\.json$/;
|
|
25
26
|
|
|
26
27
|
async function data(_izContext, srcPath, settings) {
|
|
27
28
|
const pathIntTestInBuckets = await bucketPathForUpload(
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
let intTestPath = [
|
|
2
|
-
<% intTestPaths.forEach((intTestPath,index) => { -%>
|
|
3
|
-
"<%- intTestPath %>"<%= index < intTestPaths.length - 1 ? "," : "" %>
|
|
1
|
+
let intTestPath = [ <% intTestPaths.forEach((intTestPath,index) => { -%> "<%- intTestPath %>"<%= index < intTestPaths.length - 1 ? "," : "" %>
|
|
4
2
|
<% }) -%>
|
|
5
3
|
]
|
|
@@ -22,7 +22,7 @@ const __dirname = path.dirname(__filename);
|
|
|
22
22
|
|
|
23
23
|
const templatePath = path.join(__dirname, './templateTests.ejs');
|
|
24
24
|
|
|
25
|
-
import libs from '../../libs/
|
|
25
|
+
import libs from '../../libs/IntTestGenerateLib.js';
|
|
26
26
|
const {
|
|
27
27
|
createTestFunctionName,
|
|
28
28
|
getHandlerFromEventTag,
|
|
@@ -31,7 +31,11 @@ const {
|
|
|
31
31
|
setInvokeTest
|
|
32
32
|
} = libs;
|
|
33
33
|
|
|
34
|
-
import {
|
|
34
|
+
import {
|
|
35
|
+
HANDLER,
|
|
36
|
+
GENERATE_SEED_DATA_TYPE,
|
|
37
|
+
SEED_DATA_TAG
|
|
38
|
+
} from '../../consts.js';
|
|
35
39
|
|
|
36
40
|
async function data(_izContext, allIntTestConfig, srcPath, serviceTag) {
|
|
37
41
|
let createSourceData = [];
|
|
@@ -139,7 +143,7 @@ async function data(_izContext, allIntTestConfig, srcPath, serviceTag) {
|
|
|
139
143
|
// baseIntTest.stage[currentStageIdx].invokes = invokeTest.invokeEventTags;
|
|
140
144
|
stages[currentStageIdx].invokes = invokeTest.invokeEventTags;
|
|
141
145
|
|
|
142
|
-
const invokeStagesCloned = invokeTest.invokeStages.map(stage =>
|
|
146
|
+
const invokeStagesCloned = invokeTest.invokeStages.map((stage) =>
|
|
143
147
|
structuredClone(stage)
|
|
144
148
|
);
|
|
145
149
|
|