@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
|
@@ -14,18 +14,27 @@ test('generates dynamic CRUD schemas from local schema modules', async () => {
|
|
|
14
14
|
});
|
|
15
15
|
|
|
16
16
|
const result = await generateDynamicCrudFlowSchemas(rootPath);
|
|
17
|
-
assert.deepEqual(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
assert.deepEqual(
|
|
18
|
+
result.files.map((file) => file.path),
|
|
19
|
+
[
|
|
20
|
+
'app/src/schemas/FlowSchemas/generateCode/FlowObjects/Create.js',
|
|
21
|
+
'app/src/schemas/FlowSchemas/generateCode/FlowObjects/Update.js',
|
|
22
|
+
'app/src/schemas/FlowSchemas/generateCode/FlowObjects/Delete.js',
|
|
23
|
+
'app/src/schemas/FlowSchemas/generateCode/FlowObjects/Get.js'
|
|
24
|
+
]
|
|
25
|
+
);
|
|
23
26
|
|
|
24
27
|
const create = await readGeneratedFlow(rootPath, 'Create');
|
|
25
28
|
const get = await readGeneratedFlow(rootPath, 'Get');
|
|
26
29
|
assert.deepEqual(create.event, ['ownTopic']);
|
|
27
|
-
assert.deepEqual(
|
|
28
|
-
|
|
30
|
+
assert.deepEqual(
|
|
31
|
+
create.flowSteps.map((step) => step.stepName),
|
|
32
|
+
['start', 'BeforeLogical', 'Complete']
|
|
33
|
+
);
|
|
34
|
+
assert.deepEqual(create.flowSteps[0].returnValues.messageAttributes, [
|
|
35
|
+
'userId',
|
|
36
|
+
'correlationId'
|
|
37
|
+
]);
|
|
29
38
|
assert.equal(get.outputTopic, false);
|
|
30
39
|
assert.deepEqual(get.event, ['lambdaSyncInv', 'lambdaSyncApi']);
|
|
31
40
|
assert.equal(get.flowSteps[0].returnValues, undefined);
|
|
@@ -41,11 +50,12 @@ test('accepts singleton object exports used by existing schema files', async ()
|
|
|
41
50
|
const result = await generateDynamicCrudFlowSchemas(rootPath);
|
|
42
51
|
|
|
43
52
|
assert.equal(result.files.length, 4);
|
|
44
|
-
assert.deepEqual(
|
|
45
|
-
'
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
53
|
+
assert.deepEqual(
|
|
54
|
+
(await readGeneratedFlow(rootPath, 'Create')).flowSteps.map(
|
|
55
|
+
(step) => step.stepName
|
|
56
|
+
),
|
|
57
|
+
['start', 'BeforeLogical', 'Complete']
|
|
58
|
+
);
|
|
49
59
|
});
|
|
50
60
|
|
|
51
61
|
test('does not generate CRUD schemas without an applicable object', async () => {
|
|
@@ -66,17 +76,24 @@ test('does not allow options to override the rootPath argument', async () => {
|
|
|
66
76
|
const rootPath = await createProject({ generatedBy: 'userGenerated' });
|
|
67
77
|
const ignoredRootPath = await createProject({ generatedBy: 'external' });
|
|
68
78
|
|
|
69
|
-
const result = await generateDynamicCrudFlowSchemas(rootPath, {
|
|
79
|
+
const result = await generateDynamicCrudFlowSchemas(rootPath, {
|
|
80
|
+
rootPath: ignoredRootPath
|
|
81
|
+
});
|
|
70
82
|
|
|
71
83
|
assert.equal(result.project.rootPath, rootPath);
|
|
72
84
|
assert.equal(result.files.length, 4);
|
|
73
85
|
});
|
|
74
86
|
|
|
75
87
|
test('rejects source modules that do not default-export schema objects or arrays', async () => {
|
|
76
|
-
const rootPath = await mkdtemp(
|
|
88
|
+
const rootPath = await mkdtemp(
|
|
89
|
+
join(tmpdir(), 'generate-service-code-v2-invalid-schema-')
|
|
90
|
+
);
|
|
77
91
|
const objectDirectory = join(rootPath, 'app/src/schemas/ObjectSchemas');
|
|
78
92
|
await mkdir(objectDirectory, { recursive: true });
|
|
79
|
-
await writeFile(
|
|
93
|
+
await writeFile(
|
|
94
|
+
join(objectDirectory, 'Invalid.js'),
|
|
95
|
+
"export default 'not-a-schema';\n"
|
|
96
|
+
);
|
|
80
97
|
|
|
81
98
|
await assert.rejects(
|
|
82
99
|
generateDynamicCrudFlowSchemas(rootPath),
|
|
@@ -94,22 +111,40 @@ test('reloads changed local flow schemas instead of reusing module cache', async
|
|
|
94
111
|
await generateDynamicCrudFlowSchemas(rootPath);
|
|
95
112
|
assert.match(await readGeneratedFile(rootPath, 'Create'), /BeforeLogical/);
|
|
96
113
|
|
|
97
|
-
await writeFile(
|
|
114
|
+
await writeFile(
|
|
115
|
+
flowPath,
|
|
116
|
+
`export default [${JSON.stringify(createHookFlow([]))}];\n`
|
|
117
|
+
);
|
|
98
118
|
await generateDynamicCrudFlowSchemas(rootPath);
|
|
99
|
-
assert.doesNotMatch(
|
|
119
|
+
assert.doesNotMatch(
|
|
120
|
+
await readGeneratedFile(rootPath, 'Create'),
|
|
121
|
+
/BeforeLogical/
|
|
122
|
+
);
|
|
100
123
|
});
|
|
101
124
|
|
|
102
125
|
async function createProject({ generatedBy, flow, singletonExports = false }) {
|
|
103
|
-
const rootPath = await mkdtemp(
|
|
126
|
+
const rootPath = await mkdtemp(
|
|
127
|
+
join(tmpdir(), 'generate-service-code-v2-crud-')
|
|
128
|
+
);
|
|
104
129
|
const objectPath = join(rootPath, 'app/src/schemas/ObjectSchemas/Order.js');
|
|
105
130
|
const flowPath = join(rootPath, 'app/src/schemas/FlowSchemas/CreateHook.js');
|
|
106
|
-
await mkdir(join(rootPath, 'app/src/schemas/ObjectSchemas'), {
|
|
107
|
-
|
|
131
|
+
await mkdir(join(rootPath, 'app/src/schemas/ObjectSchemas'), {
|
|
132
|
+
recursive: true
|
|
133
|
+
});
|
|
134
|
+
await mkdir(join(rootPath, 'app/src/schemas/FlowSchemas'), {
|
|
135
|
+
recursive: true
|
|
136
|
+
});
|
|
108
137
|
const object = `{ objectType: 'order', generatedBy: '${generatedBy}' }`;
|
|
109
|
-
await writeFile(
|
|
138
|
+
await writeFile(
|
|
139
|
+
objectPath,
|
|
140
|
+
`export default ${singletonExports ? object : `[${object}]`};\n`
|
|
141
|
+
);
|
|
110
142
|
if (flow) {
|
|
111
143
|
const flowSource = JSON.stringify(flow);
|
|
112
|
-
await writeFile(
|
|
144
|
+
await writeFile(
|
|
145
|
+
flowPath,
|
|
146
|
+
`export default ${singletonExports ? flowSource : `[${flowSource}]`};\n`
|
|
147
|
+
);
|
|
113
148
|
}
|
|
114
149
|
return rootPath;
|
|
115
150
|
}
|
|
@@ -127,10 +162,23 @@ function createHookFlow(event) {
|
|
|
127
162
|
}
|
|
128
163
|
|
|
129
164
|
async function readGeneratedFlow(rootPath, action) {
|
|
130
|
-
const filePath = join(
|
|
131
|
-
|
|
165
|
+
const filePath = join(
|
|
166
|
+
rootPath,
|
|
167
|
+
'app/src/schemas/FlowSchemas/generateCode/FlowObjects',
|
|
168
|
+
`${action}.js`
|
|
169
|
+
);
|
|
170
|
+
return import(
|
|
171
|
+
`${pathToFileURL(filePath).href}?test=${process.hrtime.bigint()}`
|
|
172
|
+
).then((module) => module.default);
|
|
132
173
|
}
|
|
133
174
|
|
|
134
175
|
function readGeneratedFile(rootPath, action) {
|
|
135
|
-
return readFile(
|
|
176
|
+
return readFile(
|
|
177
|
+
join(
|
|
178
|
+
rootPath,
|
|
179
|
+
'app/src/schemas/FlowSchemas/generateCode/FlowObjects',
|
|
180
|
+
`${action}.js`
|
|
181
|
+
),
|
|
182
|
+
'utf8'
|
|
183
|
+
);
|
|
136
184
|
}
|
|
@@ -21,19 +21,34 @@ const STATIC_ACTIONS = [
|
|
|
21
21
|
];
|
|
22
22
|
|
|
23
23
|
after(async () => {
|
|
24
|
-
await Promise.all(
|
|
24
|
+
await Promise.all(
|
|
25
|
+
[...projectRoots].map((rootPath) =>
|
|
26
|
+
rm(rootPath, { recursive: true, force: true })
|
|
27
|
+
)
|
|
28
|
+
);
|
|
25
29
|
});
|
|
26
30
|
|
|
27
31
|
test('generates shared and object-specific RBAC flow schemas', async () => {
|
|
28
32
|
const rootPath = await createProject({ hasRbac: true });
|
|
29
33
|
|
|
30
|
-
const result = await generateDynamicRbacFlowSchemas(rootPath, {
|
|
34
|
+
const result = await generateDynamicRbacFlowSchemas(rootPath, {
|
|
35
|
+
serviceTag: 'UserAccount'
|
|
36
|
+
});
|
|
31
37
|
|
|
32
|
-
assert.deepEqual(
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
38
|
+
assert.deepEqual(
|
|
39
|
+
result.files.map((file) => file.path),
|
|
40
|
+
[
|
|
41
|
+
...STATIC_ACTIONS.map(
|
|
42
|
+
(action) =>
|
|
43
|
+
`app/src/schemas/FlowSchemas/generateCode/FlowRbac/${action}.js`
|
|
44
|
+
),
|
|
45
|
+
'app/src/schemas/FlowSchemas/generateCode/FlowRbac/UserRbacFlow.js'
|
|
46
|
+
]
|
|
47
|
+
);
|
|
48
|
+
const createTargetRole = await readGeneratedFlow(
|
|
49
|
+
rootPath,
|
|
50
|
+
'CreateTargetRole'
|
|
51
|
+
);
|
|
37
52
|
const user = await readGeneratedFlow(rootPath, 'UserRbacFlow');
|
|
38
53
|
assert.deepEqual(createTargetRole.flowSteps[0].returnValues, {
|
|
39
54
|
properties: ['returnResult'],
|
|
@@ -47,13 +62,30 @@ test('removes RBAC schemas when the last RBAC object is removed', async () => {
|
|
|
47
62
|
const rootPath = await createProject({ hasRbac: true });
|
|
48
63
|
const objectPath = join(rootPath, 'app/src/schemas/ObjectSchemas/User.js');
|
|
49
64
|
await generateDynamicRbacFlowSchemas(rootPath, { serviceTag: 'UserAccount' });
|
|
50
|
-
await writeFile(
|
|
65
|
+
await writeFile(
|
|
66
|
+
objectPath,
|
|
67
|
+
"export default { objectType: 'user', addOnDataStructure: [] };\n"
|
|
68
|
+
);
|
|
51
69
|
|
|
52
70
|
const result = await generateDynamicRbacFlowSchemas(rootPath);
|
|
53
71
|
|
|
54
72
|
assert.deepEqual(result.files, []);
|
|
55
|
-
await assert.rejects(
|
|
56
|
-
|
|
73
|
+
await assert.rejects(
|
|
74
|
+
readFile(
|
|
75
|
+
join(
|
|
76
|
+
rootPath,
|
|
77
|
+
'app/src/schemas/FlowSchemas/generateCode/FlowRbac/CreateTargetRole.js'
|
|
78
|
+
)
|
|
79
|
+
)
|
|
80
|
+
);
|
|
81
|
+
await assert.rejects(
|
|
82
|
+
readFile(
|
|
83
|
+
join(
|
|
84
|
+
rootPath,
|
|
85
|
+
'app/src/schemas/FlowSchemas/generateCode/FlowRbac/UserRbacFlow.js'
|
|
86
|
+
)
|
|
87
|
+
)
|
|
88
|
+
);
|
|
57
89
|
});
|
|
58
90
|
|
|
59
91
|
test('requires a serviceTag only when RBAC schemas are needed', async () => {
|
|
@@ -75,11 +107,20 @@ test('removes object-specific RBAC schemas when the ObjectSchema file is deleted
|
|
|
75
107
|
|
|
76
108
|
await generateDynamicRbacFlowSchemas(rootPath);
|
|
77
109
|
|
|
78
|
-
await assert.rejects(
|
|
110
|
+
await assert.rejects(
|
|
111
|
+
readFile(
|
|
112
|
+
join(
|
|
113
|
+
rootPath,
|
|
114
|
+
'app/src/schemas/FlowSchemas/generateCode/FlowRbac/UserRbacFlow.js'
|
|
115
|
+
)
|
|
116
|
+
)
|
|
117
|
+
);
|
|
79
118
|
});
|
|
80
119
|
|
|
81
120
|
async function createProject({ hasRbac = false } = {}) {
|
|
82
|
-
const rootPath = await mkdtemp(
|
|
121
|
+
const rootPath = await mkdtemp(
|
|
122
|
+
join(tmpdir(), 'generate-service-code-v2-rbac-')
|
|
123
|
+
);
|
|
83
124
|
projectRoots.add(rootPath);
|
|
84
125
|
const objectDirectory = join(rootPath, 'app/src/schemas/ObjectSchemas');
|
|
85
126
|
await mkdir(objectDirectory, { recursive: true });
|
|
@@ -91,7 +132,13 @@ async function createProject({ hasRbac = false } = {}) {
|
|
|
91
132
|
}
|
|
92
133
|
|
|
93
134
|
async function readGeneratedFlow(rootPath, flowTag) {
|
|
94
|
-
const filePath = join(
|
|
95
|
-
|
|
135
|
+
const filePath = join(
|
|
136
|
+
rootPath,
|
|
137
|
+
'app/src/schemas/FlowSchemas/generateCode/FlowRbac',
|
|
138
|
+
`${flowTag}.js`
|
|
139
|
+
);
|
|
140
|
+
const module = await import(
|
|
141
|
+
`${pathToFileURL(filePath).href}?test=${process.hrtime.bigint()}`
|
|
142
|
+
);
|
|
96
143
|
return module.default;
|
|
97
144
|
}
|
|
@@ -18,9 +18,11 @@ const RELATIONSHIP_ACTIONS = [
|
|
|
18
18
|
const projectRoots = new Set();
|
|
19
19
|
|
|
20
20
|
after(async () => {
|
|
21
|
-
await Promise.all(
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
await Promise.all(
|
|
22
|
+
[...projectRoots].map((rootPath) =>
|
|
23
|
+
rm(rootPath, { recursive: true, force: true })
|
|
24
|
+
)
|
|
25
|
+
);
|
|
24
26
|
});
|
|
25
27
|
|
|
26
28
|
test('generates dynamic relationship schemas even without declared relationships for legacy compatibility', async () => {
|
|
@@ -29,32 +31,58 @@ test('generates dynamic relationship schemas even without declared relationships
|
|
|
29
31
|
const result = await generateDynamicRelationshipFlowSchemas(rootPath);
|
|
30
32
|
|
|
31
33
|
assert.deepEqual(
|
|
32
|
-
result.files.map(file => file.path),
|
|
33
|
-
RELATIONSHIP_ACTIONS.map(
|
|
34
|
+
result.files.map((file) => file.path),
|
|
35
|
+
RELATIONSHIP_ACTIONS.map(
|
|
36
|
+
(action) =>
|
|
37
|
+
`app/src/schemas/FlowSchemas/generateCode/FlowRelationship/${action}.js`
|
|
38
|
+
)
|
|
34
39
|
);
|
|
35
40
|
|
|
36
41
|
const create = await readGeneratedFlow(rootPath, 'CreateRelationship');
|
|
37
42
|
const get = await readGeneratedFlow(rootPath, 'GetRelationship');
|
|
38
43
|
assert.deepEqual(create.event, ['ownTopic']);
|
|
39
|
-
assert.deepEqual(
|
|
40
|
-
|
|
41
|
-
|
|
44
|
+
assert.deepEqual(
|
|
45
|
+
create.flowSteps.map((step) => step.stepName),
|
|
46
|
+
['start', 'Complete']
|
|
47
|
+
);
|
|
48
|
+
assert.deepEqual(create.flowSteps[0].returnValues.messageAttributes, [
|
|
49
|
+
'userId',
|
|
50
|
+
'correlationId'
|
|
51
|
+
]);
|
|
52
|
+
assert.deepEqual(get.event, [
|
|
53
|
+
'lambdaSyncInv',
|
|
54
|
+
'lambdaSyncApi',
|
|
55
|
+
'dsq',
|
|
56
|
+
'ownTopic'
|
|
57
|
+
]);
|
|
42
58
|
assert.equal(get.outputTopic, false);
|
|
43
59
|
assert.equal(get.flowSteps[0].returnValues, undefined);
|
|
44
|
-
assert.equal(
|
|
60
|
+
assert.equal(
|
|
61
|
+
get.flowSteps.find((step) => step.stepName === 'Complete'),
|
|
62
|
+
undefined
|
|
63
|
+
);
|
|
45
64
|
});
|
|
46
65
|
|
|
47
66
|
test('accepts singleton and array RelationshipSchema exports', async () => {
|
|
48
67
|
const singletonRoot = await createProject({ singletonExport: true });
|
|
49
68
|
const arrayRoot = await createProject();
|
|
50
69
|
|
|
51
|
-
assert.equal(
|
|
52
|
-
|
|
70
|
+
assert.equal(
|
|
71
|
+
(await generateDynamicRelationshipFlowSchemas(singletonRoot)).files.length,
|
|
72
|
+
6
|
|
73
|
+
);
|
|
74
|
+
assert.equal(
|
|
75
|
+
(await generateDynamicRelationshipFlowSchemas(arrayRoot)).files.length,
|
|
76
|
+
6
|
|
77
|
+
);
|
|
53
78
|
});
|
|
54
79
|
|
|
55
80
|
test('reloads a changed RelationshipSchema instead of reusing the module cache', async () => {
|
|
56
81
|
const rootPath = await createProject();
|
|
57
|
-
const relationshipPath = join(
|
|
82
|
+
const relationshipPath = join(
|
|
83
|
+
rootPath,
|
|
84
|
+
'app/src/schemas/RelationshipSchemas/OrderCustomer.js'
|
|
85
|
+
);
|
|
58
86
|
|
|
59
87
|
await generateDynamicRelationshipFlowSchemas(rootPath);
|
|
60
88
|
await writeFile(relationshipPath, "export default 'not-a-schema';\n");
|
|
@@ -69,20 +97,33 @@ test('does not allow options to override the rootPath argument', async () => {
|
|
|
69
97
|
const rootPath = await createProject();
|
|
70
98
|
const ignoredRootPath = await createProject();
|
|
71
99
|
|
|
72
|
-
const result = await generateDynamicRelationshipFlowSchemas(rootPath, {
|
|
100
|
+
const result = await generateDynamicRelationshipFlowSchemas(rootPath, {
|
|
101
|
+
rootPath: ignoredRootPath
|
|
102
|
+
});
|
|
73
103
|
|
|
74
104
|
assert.equal(result.project.rootPath, rootPath);
|
|
75
105
|
assert.equal(result.files.length, 6);
|
|
76
106
|
assert.match(
|
|
77
|
-
await readFile(
|
|
107
|
+
await readFile(
|
|
108
|
+
join(
|
|
109
|
+
rootPath,
|
|
110
|
+
'app/src/schemas/FlowSchemas/generateCode/FlowRelationship/CreateRelationship.js'
|
|
111
|
+
),
|
|
112
|
+
'utf8'
|
|
113
|
+
),
|
|
78
114
|
/export default/
|
|
79
115
|
);
|
|
80
116
|
});
|
|
81
117
|
|
|
82
118
|
async function createProject({ singletonExport = false } = {}) {
|
|
83
|
-
const rootPath = await mkdtemp(
|
|
119
|
+
const rootPath = await mkdtemp(
|
|
120
|
+
join(tmpdir(), 'generate-service-code-v2-relationship-')
|
|
121
|
+
);
|
|
84
122
|
projectRoots.add(rootPath);
|
|
85
|
-
const relationshipDirectory = join(
|
|
123
|
+
const relationshipDirectory = join(
|
|
124
|
+
rootPath,
|
|
125
|
+
'app/src/schemas/RelationshipSchemas'
|
|
126
|
+
);
|
|
86
127
|
await mkdir(relationshipDirectory, { recursive: true });
|
|
87
128
|
const relationship = { relationshipTag: 'orderCustomer', links: [] };
|
|
88
129
|
await writeFile(
|
|
@@ -93,7 +134,13 @@ async function createProject({ singletonExport = false } = {}) {
|
|
|
93
134
|
}
|
|
94
135
|
|
|
95
136
|
async function readGeneratedFlow(rootPath, action) {
|
|
96
|
-
const filePath = join(
|
|
97
|
-
|
|
137
|
+
const filePath = join(
|
|
138
|
+
rootPath,
|
|
139
|
+
'app/src/schemas/FlowSchemas/generateCode/FlowRelationship',
|
|
140
|
+
`${action}.js`
|
|
141
|
+
);
|
|
142
|
+
const module = await import(
|
|
143
|
+
`${pathToFileURL(filePath).href}?test=${process.hrtime.bigint()}`
|
|
144
|
+
);
|
|
98
145
|
return module.default;
|
|
99
146
|
}
|
|
@@ -11,11 +11,51 @@ import {
|
|
|
11
11
|
|
|
12
12
|
test('renders function-setting hooks for every function transport', () => {
|
|
13
13
|
const functions = [
|
|
14
|
-
[
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
[
|
|
15
|
+
'CreateHdrSqs',
|
|
16
|
+
renderSqsFunctionYaml({
|
|
17
|
+
functionName: 'CreateHdrSqs',
|
|
18
|
+
handlerPath: 'src/create.main',
|
|
19
|
+
roleName: 'Role',
|
|
20
|
+
queueName: 'CreateHdrSqs'
|
|
21
|
+
})
|
|
22
|
+
],
|
|
23
|
+
[
|
|
24
|
+
'GetHdrApi',
|
|
25
|
+
renderApiFunctionYaml({
|
|
26
|
+
functionName: 'GetHdrApi',
|
|
27
|
+
handlerPath: 'src/get.main',
|
|
28
|
+
roleName: 'Role',
|
|
29
|
+
routes: [{ path: '/orders/get', upperName: 'Get' }]
|
|
30
|
+
})
|
|
31
|
+
],
|
|
32
|
+
[
|
|
33
|
+
'CreateHdrWbs',
|
|
34
|
+
renderWbsFunctionYaml({
|
|
35
|
+
functionName: 'CreateHdrWbs',
|
|
36
|
+
handlerPath: 'src/create.main',
|
|
37
|
+
roleName: 'Role',
|
|
38
|
+
routeName: 'create'
|
|
39
|
+
})
|
|
40
|
+
],
|
|
41
|
+
[
|
|
42
|
+
'GetHdrInv',
|
|
43
|
+
renderInvFunctionYaml({
|
|
44
|
+
functionName: 'GetHdrInv',
|
|
45
|
+
handlerPath: 'src/get.main',
|
|
46
|
+
roleName: 'Role'
|
|
47
|
+
})
|
|
48
|
+
],
|
|
49
|
+
[
|
|
50
|
+
'ScheduledHdrInv',
|
|
51
|
+
renderEventBridgeFunctionYaml({
|
|
52
|
+
functionName: 'ScheduledHdrInv',
|
|
53
|
+
handlerPath: 'src/scheduled.main',
|
|
54
|
+
roleName: 'Role',
|
|
55
|
+
flowTag: 'scheduled',
|
|
56
|
+
schedules: [{ name: 'daily', rate: ['rate(1 day)'] }]
|
|
57
|
+
})
|
|
58
|
+
]
|
|
19
59
|
];
|
|
20
60
|
|
|
21
61
|
for (const [functionName, yaml] of functions) {
|
|
@@ -24,11 +64,28 @@ test('renders function-setting hooks for every function transport', () => {
|
|
|
24
64
|
}
|
|
25
65
|
});
|
|
26
66
|
|
|
27
|
-
test('filters
|
|
28
|
-
const completion = renderSqsFunctionYaml({
|
|
29
|
-
|
|
67
|
+
test('filters all SQS functions by their calling flow', () => {
|
|
68
|
+
const completion = renderSqsFunctionYaml({
|
|
69
|
+
functionName: 'CreateCompleteHdrSqs',
|
|
70
|
+
handlerPath: 'src/create.main',
|
|
71
|
+
roleName: 'Role',
|
|
72
|
+
queueName: 'CreateCompleteHdrSqs'
|
|
73
|
+
});
|
|
74
|
+
const ordinary = renderSqsFunctionYaml({
|
|
75
|
+
functionName: 'CreateHdrSqs',
|
|
76
|
+
handlerPath: 'src/create.main',
|
|
77
|
+
roleName: 'Role',
|
|
78
|
+
queueName: 'CreateHdrSqs'
|
|
79
|
+
});
|
|
30
80
|
|
|
31
|
-
assert.match(
|
|
81
|
+
assert.match(
|
|
82
|
+
completion,
|
|
83
|
+
/filterPatterns:[\s\S]*\$\{self:custom\.iz_resourcePrefix\}CreateCompleteHdrSqs/
|
|
84
|
+
);
|
|
32
85
|
assert.match(completion, /exists: false/);
|
|
33
|
-
assert.
|
|
86
|
+
assert.match(
|
|
87
|
+
ordinary,
|
|
88
|
+
/filterPatterns:[\s\S]*\$\{self:custom\.iz_resourcePrefix\}CreateHdrSqs/
|
|
89
|
+
);
|
|
90
|
+
assert.match(ordinary, /exists: false/);
|
|
34
91
|
});
|
package/test/intTestApi.test.js
CHANGED
|
@@ -4,21 +4,20 @@ import os from 'node:os';
|
|
|
4
4
|
import path from 'node:path';
|
|
5
5
|
import test from 'node:test';
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
generateIntTest,
|
|
9
|
-
generateResourceIntTest
|
|
10
|
-
} from '../index.js';
|
|
7
|
+
import { generateIntTest, generateResourceIntTest } from '../index.js';
|
|
11
8
|
|
|
12
9
|
test('exports IntTest generators and requires a service tag', async () => {
|
|
13
|
-
const rootPath = await mkdtemp(
|
|
10
|
+
const rootPath = await mkdtemp(
|
|
11
|
+
path.join(os.tmpdir(), 'generate-service-code-inttest-')
|
|
12
|
+
);
|
|
14
13
|
await mkdir(path.join(rootPath, 'config'));
|
|
15
|
-
await writeFile(
|
|
14
|
+
await writeFile(
|
|
15
|
+
path.join(rootPath, 'config', 'serverless.config.yml'),
|
|
16
|
+
'main_config: {}\n'
|
|
17
|
+
);
|
|
16
18
|
|
|
17
19
|
try {
|
|
18
|
-
await assert.rejects(
|
|
19
|
-
generateIntTest(rootPath),
|
|
20
|
-
/Missing iz_serviceTag/
|
|
21
|
-
);
|
|
20
|
+
await assert.rejects(generateIntTest(rootPath), /Missing iz_serviceTag/);
|
|
22
21
|
await assert.rejects(
|
|
23
22
|
generateResourceIntTest(rootPath),
|
|
24
23
|
/Missing iz_serviceTag/
|