@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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@izara_project/izara-core-generate-service-code",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.70",
|
|
4
4
|
"description": "Code for locally generating per service files",
|
|
5
5
|
"homepage": "https://bitbucket.org/izara-core-support-services/izara-core-support-services-generate-service-code#readme",
|
|
6
6
|
"repository": {
|
package/scripts/format-ejs.js
CHANGED
|
@@ -34,8 +34,7 @@ export async function formatEjsFiles(targetDir = 'src/emit') {
|
|
|
34
34
|
const id = placeholders.length;
|
|
35
35
|
const isExpr = match.startsWith('<%=') || match.startsWith('<%-');
|
|
36
36
|
const isConditionalComma =
|
|
37
|
-
match.includes('?') &&
|
|
38
|
-
(match.includes("','") || match.includes('","'));
|
|
37
|
+
match.includes('?') && (match.includes("','") || match.includes('","'));
|
|
39
38
|
|
|
40
39
|
let replacement;
|
|
41
40
|
if (isYaml) {
|
|
@@ -58,38 +57,42 @@ export async function formatEjsFiles(targetDir = 'src/emit') {
|
|
|
58
57
|
return replacement;
|
|
59
58
|
});
|
|
60
59
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
60
|
+
try {
|
|
61
|
+
const parser = isYaml ? 'yaml' : 'babel';
|
|
62
|
+
let formatted = await prettier.format(masked, {
|
|
63
|
+
parser,
|
|
64
|
+
singleQuote: true,
|
|
65
|
+
semi: true,
|
|
66
|
+
tabWidth: 2,
|
|
67
|
+
useTabs: false,
|
|
68
|
+
trailingComma: 'none',
|
|
69
|
+
printWidth: 80,
|
|
70
|
+
endOfLine: 'lf'
|
|
71
|
+
});
|
|
72
72
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
73
|
+
for (const item of placeholders) {
|
|
74
|
+
if (item.isConditionalComma) {
|
|
75
|
+
formatted = formatted.replace(item.replacement, item.original);
|
|
76
|
+
formatted = formatted.replace(
|
|
77
|
+
`, /*__EJS_COMMA_${item.id}__*/`,
|
|
78
|
+
item.original
|
|
79
|
+
);
|
|
80
|
+
} else {
|
|
81
|
+
formatted = formatted.replace(item.replacement, item.original);
|
|
82
|
+
}
|
|
82
83
|
}
|
|
83
|
-
}
|
|
84
84
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
85
|
+
// Ensure unix newline at EOF
|
|
86
|
+
if (!formatted.endsWith('\n')) {
|
|
87
|
+
formatted += '\n';
|
|
88
|
+
}
|
|
89
89
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
90
|
+
if (formatted !== content) {
|
|
91
|
+
fs.writeFileSync(filePath, formatted, 'utf8');
|
|
92
|
+
updatedCount++;
|
|
93
|
+
}
|
|
94
|
+
} catch (err) {
|
|
95
|
+
console.warn(`[WARN] Skipping ${filePath}: prettier error: ${err.message}`);
|
|
93
96
|
}
|
|
94
97
|
}
|
|
95
98
|
|
|
@@ -97,9 +100,10 @@ export async function formatEjsFiles(targetDir = 'src/emit') {
|
|
|
97
100
|
}
|
|
98
101
|
|
|
99
102
|
if (process.argv[1] === new URL(import.meta.url).pathname) {
|
|
100
|
-
|
|
103
|
+
const targetDir = process.argv[2] || 'src/emit';
|
|
104
|
+
formatEjsFiles(targetDir).then(({ total, updated }) => {
|
|
101
105
|
console.log(
|
|
102
|
-
`Successfully formatted ${updated} / ${total} EJS template files in
|
|
106
|
+
`Successfully formatted ${updated} / ${total} EJS template files in ${targetDir}.`
|
|
103
107
|
);
|
|
104
108
|
});
|
|
105
109
|
}
|
|
@@ -1,17 +1,24 @@
|
|
|
1
|
+
import Logger from '@izara_project/izara-core-library-logger';
|
|
1
2
|
import { join, resolve } from 'node:path';
|
|
2
3
|
import { readFileSync, existsSync } from 'node:fs';
|
|
3
4
|
import { parse as parseYaml } from 'yaml';
|
|
4
5
|
|
|
5
6
|
export function compileProject(request = {}) {
|
|
6
|
-
if (!
|
|
7
|
-
throw new TypeError(
|
|
7
|
+
if (!_isNonEmptyString(request.rootPath)) {
|
|
8
|
+
throw new TypeError(
|
|
9
|
+
'GenerationRequest.rootPath must be a non-empty string'
|
|
10
|
+
);
|
|
8
11
|
}
|
|
9
12
|
|
|
10
13
|
const rootPath = resolve(request.rootPath);
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
let outputPath = rootPath;
|
|
15
|
+
if (request.outputPath) {
|
|
16
|
+
outputPath = resolve(request.outputPath);
|
|
17
|
+
}
|
|
18
|
+
let configPath = join(rootPath, 'config', 'serverless.config.yml');
|
|
19
|
+
if (request.configPath) {
|
|
20
|
+
configPath = resolve(request.configPath);
|
|
21
|
+
}
|
|
15
22
|
|
|
16
23
|
let serviceTag = request.serviceTag;
|
|
17
24
|
if (!serviceTag && existsSync(configPath)) {
|
|
@@ -19,23 +26,32 @@ export function compileProject(request = {}) {
|
|
|
19
26
|
const configContent = readFileSync(configPath, 'utf8');
|
|
20
27
|
const parsedConfig = parseYaml(configContent);
|
|
21
28
|
if (parsedConfig && parsedConfig.main_config) {
|
|
22
|
-
|
|
29
|
+
if (parsedConfig.main_config.iz_serviceTag) {
|
|
30
|
+
serviceTag = parsedConfig.main_config.iz_serviceTag;
|
|
31
|
+
} else if (parsedConfig.main_config.iz_serviceName) {
|
|
32
|
+
serviceTag = parsedConfig.main_config.iz_serviceName;
|
|
33
|
+
}
|
|
23
34
|
}
|
|
24
35
|
} catch (err) {
|
|
25
|
-
|
|
36
|
+
Logger?.debug?.('Could not read serverless.config.yml', err);
|
|
26
37
|
}
|
|
27
38
|
}
|
|
28
39
|
|
|
40
|
+
let schemaTemplateConfig = [];
|
|
41
|
+
if (request.schemaTemplateConfig) {
|
|
42
|
+
schemaTemplateConfig = request.schemaTemplateConfig;
|
|
43
|
+
}
|
|
44
|
+
|
|
29
45
|
return Object.freeze({
|
|
30
46
|
rootPath,
|
|
31
47
|
outputPath,
|
|
32
48
|
configPath,
|
|
33
49
|
schemaRoot: join(rootPath, 'app', 'src', 'schemas'),
|
|
34
50
|
serviceTag,
|
|
35
|
-
schemaTemplateConfig
|
|
51
|
+
schemaTemplateConfig
|
|
36
52
|
});
|
|
37
53
|
}
|
|
38
54
|
|
|
39
|
-
function
|
|
55
|
+
function _isNonEmptyString(value) {
|
|
40
56
|
return typeof value === 'string' && value.trim() !== '';
|
|
41
57
|
}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { readdir, stat } from 'node:fs/promises';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import { pathToFileURL } from 'node:url';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
getObjectSchema,
|
|
6
|
+
utils
|
|
7
|
+
} from '@izara_project/izara-core-library-service-schemas';
|
|
5
8
|
import Logger from '@izara_project/izara-core-library-logger';
|
|
6
9
|
|
|
7
10
|
export async function loadLocalSchemaDirectory(project, directoryName) {
|
|
@@ -16,35 +19,61 @@ export async function loadLocalSchemaDirectory(project, directoryName) {
|
|
|
16
19
|
throw error;
|
|
17
20
|
}
|
|
18
21
|
|
|
22
|
+
const validEntries = entries.filter(
|
|
23
|
+
(entry) => entry.isFile() && entry.name.endsWith('.js')
|
|
24
|
+
);
|
|
25
|
+
validEntries.sort((a, b) => a.name.localeCompare(b.name));
|
|
26
|
+
|
|
19
27
|
const schemas = [];
|
|
20
|
-
for (const entry of
|
|
28
|
+
for (const entry of validEntries) {
|
|
21
29
|
const filePath = join(directoryPath, entry.name);
|
|
22
30
|
const details = await stat(filePath);
|
|
23
|
-
const module = await import(
|
|
31
|
+
const module = await import(
|
|
32
|
+
`${pathToFileURL(filePath).href}?schemaVersion=${details.mtimeMs}-${details.size}`
|
|
33
|
+
);
|
|
24
34
|
if (!module.default || typeof module.default !== 'object') {
|
|
25
|
-
throw new TypeError(
|
|
35
|
+
throw new TypeError(
|
|
36
|
+
`Schema module must default-export an object or array: ${filePath}`
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
let loadedSchemas = [module.default];
|
|
40
|
+
if (Array.isArray(module.default)) {
|
|
41
|
+
loadedSchemas = module.default;
|
|
26
42
|
}
|
|
27
|
-
const loadedSchemas = Array.isArray(module.default) ? module.default : [module.default];
|
|
28
43
|
|
|
29
|
-
if (process.env.NODE_ENV !== 'test') {
|
|
44
|
+
if (process.env.NODE_ENV && process.env.NODE_ENV !== 'test') {
|
|
30
45
|
for (const schema of loadedSchemas) {
|
|
31
46
|
let status = true;
|
|
32
47
|
let errors = [];
|
|
33
|
-
|
|
48
|
+
|
|
34
49
|
if (directoryName === 'ObjectSchemas') {
|
|
35
|
-
[status, errors] = utils.validateObjectSchema(
|
|
50
|
+
[status, errors] = utils.validateObjectSchema(
|
|
51
|
+
{ logger: Logger },
|
|
52
|
+
schema
|
|
53
|
+
);
|
|
36
54
|
} else if (directoryName === 'RelationshipSchemas') {
|
|
37
55
|
if (entry.name.toLowerCase() === 'refobjectrelationships.js') {
|
|
38
|
-
[status, errors] = utils.validateRefRelationshipSchema(
|
|
56
|
+
[status, errors] = utils.validateRefRelationshipSchema(
|
|
57
|
+
{ logger: Logger },
|
|
58
|
+
schema
|
|
59
|
+
);
|
|
39
60
|
} else {
|
|
40
|
-
[status, errors] = utils.validateRelationshipSchema(
|
|
61
|
+
[status, errors] = utils.validateRelationshipSchema(
|
|
62
|
+
{ logger: Logger },
|
|
63
|
+
schema
|
|
64
|
+
);
|
|
41
65
|
}
|
|
42
66
|
} else if (directoryName === 'FlowSchemas') {
|
|
43
|
-
[status, errors] = utils.validateBasicFlowSchema(
|
|
67
|
+
[status, errors] = utils.validateBasicFlowSchema(
|
|
68
|
+
{ logger: Logger },
|
|
69
|
+
schema
|
|
70
|
+
);
|
|
44
71
|
}
|
|
45
72
|
|
|
46
73
|
if (!status) {
|
|
47
|
-
throw new Error(
|
|
74
|
+
throw new Error(
|
|
75
|
+
`Schema validation failed for ${entry.name}:\n${errors.join('\n')}`
|
|
76
|
+
);
|
|
48
77
|
}
|
|
49
78
|
}
|
|
50
79
|
}
|
|
@@ -70,66 +99,100 @@ export async function loadLocalSchemaDirectory(project, directoryName) {
|
|
|
70
99
|
*/
|
|
71
100
|
export async function resolveExtendedObjectSchemas(
|
|
72
101
|
objectSchemas,
|
|
73
|
-
bucketName
|
|
102
|
+
bucketName = process.env.iz_serviceSchemaBucketName
|
|
74
103
|
) {
|
|
75
104
|
if (!Array.isArray(objectSchemas)) {
|
|
76
105
|
throw new TypeError('objectSchemas must be an array');
|
|
77
106
|
}
|
|
78
107
|
const resolvedSchemas = [];
|
|
79
108
|
for (const schema of objectSchemas) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
109
|
+
let currentSchema = schema;
|
|
110
|
+
if (currentSchema.hasOwnProperty('extendObjType')) {
|
|
111
|
+
try {
|
|
112
|
+
Logger.debug(
|
|
113
|
+
`[DEBUG] [resolveExtendedObjectSchemas] Merging extendObjType for objectType=${currentSchema.objectType}`,
|
|
114
|
+
{ extendObjType: currentSchema.extendObjType }
|
|
115
|
+
);
|
|
116
|
+
const initialResources = currentSchema.storageResources || {};
|
|
117
|
+
const childStorageResourceKeys = new Set(Object.keys(initialResources));
|
|
118
|
+
const parentServiceTag = currentSchema.extendObjType.serviceTag;
|
|
90
119
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
120
|
+
const mergedSchema = await getObjectSchema.mergeExtendObjSchema(
|
|
121
|
+
{ logger: Logger },
|
|
122
|
+
currentSchema,
|
|
123
|
+
bucketName
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
const externalDynamoResources = [];
|
|
127
|
+
const ownStorageResources = {};
|
|
128
|
+
const mergedStorageResources = mergedSchema.storageResources || {};
|
|
129
|
+
for (const [key, resource] of Object.entries(mergedStorageResources)) {
|
|
130
|
+
if (
|
|
131
|
+
resource &&
|
|
132
|
+
resource.storageType === 'dynamoDB' &&
|
|
133
|
+
!childStorageResourceKeys.has(key)
|
|
134
|
+
) {
|
|
135
|
+
externalDynamoResources.push({
|
|
136
|
+
serviceTag: parentServiceTag,
|
|
137
|
+
tableName: resource.tableName
|
|
138
|
+
});
|
|
139
|
+
} else {
|
|
140
|
+
ownStorageResources[key] = resource;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
96
143
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
// emitResourceArtifacts can add cross-service ARNs to IAM roles.
|
|
101
|
-
const externalDynamoResources = [];
|
|
102
|
-
const ownStorageResources = {};
|
|
103
|
-
for (const [key, resource] of Object.entries(
|
|
104
|
-
mergedSchema.storageResources ?? {}
|
|
105
|
-
)) {
|
|
106
|
-
if (
|
|
107
|
-
resource?.storageType === 'dynamoDB' &&
|
|
108
|
-
!childStorageResourceKeys.has(key)
|
|
109
|
-
) {
|
|
110
|
-
externalDynamoResources.push({
|
|
111
|
-
serviceTag: parentServiceTag,
|
|
112
|
-
tableName: resource.tableName
|
|
113
|
-
});
|
|
114
|
-
} else {
|
|
115
|
-
ownStorageResources[key] = resource;
|
|
144
|
+
mergedSchema.storageResources = ownStorageResources;
|
|
145
|
+
if (externalDynamoResources.length > 0) {
|
|
146
|
+
mergedSchema.externalDynamoResources = externalDynamoResources;
|
|
116
147
|
}
|
|
117
|
-
}
|
|
118
148
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
149
|
+
currentSchema = mergedSchema;
|
|
150
|
+
} catch (error) {
|
|
151
|
+
Logger.error(
|
|
152
|
+
`[ERROR] [resolveExtendedObjectSchemas] Failed to merge extendObjType for objectType=${currentSchema.objectType}`,
|
|
153
|
+
{ error }
|
|
154
|
+
);
|
|
155
|
+
throw error;
|
|
122
156
|
}
|
|
157
|
+
}
|
|
123
158
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
159
|
+
/*
|
|
160
|
+
if (
|
|
161
|
+
currentSchema.hasOwnProperty('belongTo') &&
|
|
162
|
+
currentSchema.belongTo &&
|
|
163
|
+
currentSchema.belongTo.serviceTag &&
|
|
164
|
+
currentSchema.belongTo.objectType
|
|
165
|
+
) {
|
|
166
|
+
try {
|
|
167
|
+
Logger.debug(
|
|
168
|
+
`[DEBUG] [resolveExtendedObjectSchemas] Fetching belongTo schema for objectType=${currentSchema.objectType}`,
|
|
169
|
+
{ belongTo: currentSchema.belongTo }
|
|
170
|
+
);
|
|
171
|
+
const belongToObjType = {
|
|
172
|
+
serviceTag: currentSchema.belongTo.serviceTag,
|
|
173
|
+
objectType: currentSchema.belongTo.objectType
|
|
174
|
+
};
|
|
175
|
+
const belongToSchema = await getObjectSchema.getObjSchemaS3(
|
|
176
|
+
{ logger: Logger },
|
|
177
|
+
belongToObjType,
|
|
178
|
+
false,
|
|
179
|
+
bucketName
|
|
180
|
+
);
|
|
181
|
+
currentSchema.belongToSchema = belongToSchema;
|
|
182
|
+
Logger.debug(
|
|
183
|
+
`[DEBUG] [resolveExtendedObjectSchemas] Successfully fetched belongTo schema for objectType=${currentSchema.objectType}`,
|
|
184
|
+
{ belongToObjectType: belongToSchema?.objectType }
|
|
185
|
+
);
|
|
186
|
+
} catch (error) {
|
|
187
|
+
Logger.warn(
|
|
188
|
+
`[WARN] [resolveExtendedObjectSchemas] Failed to fetch belongTo schema for objectType=${currentSchema.objectType}`,
|
|
189
|
+
{ error }
|
|
190
|
+
);
|
|
191
|
+
}
|
|
132
192
|
}
|
|
193
|
+
*/
|
|
194
|
+
|
|
195
|
+
resolvedSchemas.push(currentSchema);
|
|
133
196
|
}
|
|
134
197
|
return resolvedSchemas;
|
|
135
198
|
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import ejsLib from 'ejs';
|
|
2
|
+
import { readFile } from 'node:fs/promises';
|
|
3
|
+
|
|
4
|
+
const TEMPLATE_URL = new URL('./templates/', import.meta.url);
|
|
5
|
+
const APP_ROOT = 'app/sls_yaml/generatedCode/source';
|
|
6
|
+
const SRC_ROOT = 'app/src/generatedCode/CoreFunctions';
|
|
7
|
+
|
|
8
|
+
export const coreFunctionManagedPaths = [
|
|
9
|
+
`${APP_ROOT}/core-function.yml`,
|
|
10
|
+
`${APP_ROOT}/core-resource.yml`,
|
|
11
|
+
`${SRC_ROOT}/UploadSchema_HdrInv.js`,
|
|
12
|
+
`${SRC_ROOT}/UploadSchema_Main.js`,
|
|
13
|
+
`${SRC_ROOT}/GenerateSeedDataDynamo_HdrInv.js`,
|
|
14
|
+
`${SRC_ROOT}/GenerateSeedDataDynamo_Main.js`,
|
|
15
|
+
`${SRC_ROOT}/RemoveSeedDataDynamo_HdrInv.js`,
|
|
16
|
+
`${SRC_ROOT}/RemoveSeedDataDynamo_Main.js`,
|
|
17
|
+
`${SRC_ROOT}/GenerateSeedDataGraphData_HdrInv.js`,
|
|
18
|
+
`${SRC_ROOT}/GenerateSeedDataGraphData_Main.js`,
|
|
19
|
+
`${SRC_ROOT}/GenerateSeedDataGraphSchema_HdrInv.js`,
|
|
20
|
+
`${SRC_ROOT}/GenerateSeedDataGraphSchema_Main.js`,
|
|
21
|
+
`${SRC_ROOT}/InitialSetup_HdrInv.js`,
|
|
22
|
+
`${SRC_ROOT}/InitialSetup_Main.js`,
|
|
23
|
+
`${SRC_ROOT}/generated/GeneratedTableConfigs.js`,
|
|
24
|
+
`${SRC_ROOT}/generated/GeneratedGraphNodeSchemas.js`,
|
|
25
|
+
`${SRC_ROOT}/generated/GeneratedGraphRelSchemas.js`,
|
|
26
|
+
`${SRC_ROOT}/InitialSetupConfig.js`
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
export async function emitCoreFunctionArtifacts({ project, objects = [], relationships = [] }) {
|
|
30
|
+
const state = {
|
|
31
|
+
project,
|
|
32
|
+
objects,
|
|
33
|
+
relationships,
|
|
34
|
+
hasGenerateGraph: objects.length > 0 || relationships.length > 0
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const [
|
|
38
|
+
coreFunctionYaml,
|
|
39
|
+
coreResourceYaml,
|
|
40
|
+
uploadSchemaHdrInv,
|
|
41
|
+
uploadSchemaMain,
|
|
42
|
+
generateSeedDataDynamoHdrInv,
|
|
43
|
+
generateSeedDataDynamoMain,
|
|
44
|
+
removeSeedDataDynamoHdrInv,
|
|
45
|
+
removeSeedDataDynamoMain,
|
|
46
|
+
generateSeedDataGraphDataHdrInv,
|
|
47
|
+
generateSeedDataGraphDataMain,
|
|
48
|
+
generateSeedDataGraphSchemaHdrInv,
|
|
49
|
+
generateSeedDataGraphSchemaMain,
|
|
50
|
+
generatedTableConfigs,
|
|
51
|
+
generatedGraphNodeSchemas,
|
|
52
|
+
generatedGraphRelSchemas,
|
|
53
|
+
initialSetupConfig,
|
|
54
|
+
initialSetupHdrInv,
|
|
55
|
+
initialSetupMain
|
|
56
|
+
] = await Promise.all([
|
|
57
|
+
render('CoreFunction_Yaml.ejs', state),
|
|
58
|
+
render('CoreResource_Yaml.ejs', state),
|
|
59
|
+
render('UploadSchema_HdrInv.ejs', state),
|
|
60
|
+
render('UploadSchema_Main.ejs', state),
|
|
61
|
+
render('GenerateSeedDataDynamo_HdrInv.ejs', state),
|
|
62
|
+
render('GenerateSeedDataDynamo_Main.ejs', state),
|
|
63
|
+
render('RemoveSeedDataDynamo_HdrInv.ejs', state),
|
|
64
|
+
render('RemoveSeedDataDynamo_Main.ejs', state),
|
|
65
|
+
render('GenerateSeedDataGraphData_HdrInv.ejs', state),
|
|
66
|
+
render('GenerateSeedDataGraphData_Main.ejs', state),
|
|
67
|
+
render('GenerateSeedDataGraphSchema_HdrInv.ejs', state),
|
|
68
|
+
render('GenerateSeedDataGraphSchema_Main.ejs', state),
|
|
69
|
+
render('GeneratedTableConfigs.ejs', state),
|
|
70
|
+
render('GeneratedGraphNodeSchemas.ejs', state),
|
|
71
|
+
render('GeneratedGraphRelSchemas.ejs', state),
|
|
72
|
+
render('InitialSetupConfig.ejs', state),
|
|
73
|
+
render('InitialSetup_HdrInv.ejs', state),
|
|
74
|
+
render('InitialSetup_Main.ejs', state)
|
|
75
|
+
]);
|
|
76
|
+
|
|
77
|
+
return [
|
|
78
|
+
{
|
|
79
|
+
path: `${APP_ROOT}/core-function.yml`,
|
|
80
|
+
content: normalizeYaml(coreFunctionYaml)
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
path: `${APP_ROOT}/core-resource.yml`,
|
|
84
|
+
content: normalizeYaml(coreResourceYaml)
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
path: `${SRC_ROOT}/UploadSchema_HdrInv.js`,
|
|
88
|
+
content: uploadSchemaHdrInv
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
path: `${SRC_ROOT}/UploadSchema_Main.js`,
|
|
92
|
+
content: uploadSchemaMain
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
path: `${SRC_ROOT}/GenerateSeedDataDynamo_HdrInv.js`,
|
|
96
|
+
content: generateSeedDataDynamoHdrInv
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
path: `${SRC_ROOT}/GenerateSeedDataDynamo_Main.js`,
|
|
100
|
+
content: generateSeedDataDynamoMain
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
path: `${SRC_ROOT}/RemoveSeedDataDynamo_HdrInv.js`,
|
|
104
|
+
content: removeSeedDataDynamoHdrInv
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
path: `${SRC_ROOT}/RemoveSeedDataDynamo_Main.js`,
|
|
108
|
+
content: removeSeedDataDynamoMain
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
path: `${SRC_ROOT}/GenerateSeedDataGraphData_HdrInv.js`,
|
|
112
|
+
content: generateSeedDataGraphDataHdrInv
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
path: `${SRC_ROOT}/GenerateSeedDataGraphData_Main.js`,
|
|
116
|
+
content: generateSeedDataGraphDataMain
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
path: `${SRC_ROOT}/GenerateSeedDataGraphSchema_HdrInv.js`,
|
|
120
|
+
content: generateSeedDataGraphSchemaHdrInv
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
path: `${SRC_ROOT}/GenerateSeedDataGraphSchema_Main.js`,
|
|
124
|
+
content: generateSeedDataGraphSchemaMain
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
path: `${SRC_ROOT}/generated/GeneratedTableConfigs.js`,
|
|
128
|
+
content: generatedTableConfigs
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
path: `${SRC_ROOT}/generated/GeneratedGraphNodeSchemas.js`,
|
|
132
|
+
content: generatedGraphNodeSchemas
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
path: `${SRC_ROOT}/generated/GeneratedGraphRelSchemas.js`,
|
|
136
|
+
content: generatedGraphRelSchemas
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
path: `${SRC_ROOT}/InitialSetupConfig.js`,
|
|
140
|
+
content: initialSetupConfig,
|
|
141
|
+
writeWhenFileExist: false // Don't overwrite the file that dev modifies
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
path: `${SRC_ROOT}/InitialSetup_HdrInv.js`,
|
|
145
|
+
content: initialSetupHdrInv
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
path: `${SRC_ROOT}/InitialSetup_Main.js`,
|
|
149
|
+
content: initialSetupMain
|
|
150
|
+
}
|
|
151
|
+
];
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function normalizeYaml(content) {
|
|
155
|
+
return `${content.trimEnd()}\n`;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
async function render(templateName, data) {
|
|
159
|
+
return ejsLib.render(
|
|
160
|
+
await readFile(new URL(templateName, TEMPLATE_URL), 'utf8'),
|
|
161
|
+
data
|
|
162
|
+
);
|
|
163
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# --- FOR PROD STAGE
|
|
2
|
+
UploadSchemaHdrInv:
|
|
3
|
+
handler: src/generatedCode/CoreFunctions/UploadSchema_HdrInv.main
|
|
4
|
+
name: ${self:custom.iz_resourcePrefix}UploadSchemaHdrInv
|
|
5
|
+
role: UploadSchemaRole
|
|
6
|
+
timeout: 30
|
|
7
|
+
#<#UploadSchemaHdrInvHookCode#>
|
|
8
|
+
#<#/UploadSchemaHdrInvHookCode#>
|
|
9
|
+
|
|
10
|
+
# --- FOR TEST STAGE
|
|
11
|
+
GenerateSeedGraph: # --- FOR TEST STAGE
|
|
12
|
+
handler: src/generatedCode/CoreFunctions/GenerateSeedDataGraphData_HdrInv.main
|
|
13
|
+
name: ${self:custom.iz_resourcePrefix}GenerateSeedDataGraphDataTestEnv
|
|
14
|
+
role: GenerateSeedGraphRole
|
|
15
|
+
#<#GenerateSeedGraphHookCode#>
|
|
16
|
+
#<#/GenerateSeedGraphHookCode#>
|
|
17
|
+
|
|
18
|
+
GenerateGraphSchema:
|
|
19
|
+
handler: src/generatedCode/CoreFunctions/GenerateSeedDataGraphSchema_HdrInv.main
|
|
20
|
+
name: ${self:custom.iz_resourcePrefix}GenerateSeedDataGraphSchemaTestEnv
|
|
21
|
+
role: GenerateGraphSchemaRole
|
|
22
|
+
#<#GenerateGraphSchemaHookCode#>
|
|
23
|
+
#<#/GenerateGraphSchemaHookCode#>
|
|
24
|
+
|
|
25
|
+
RemoveSeedDataDynamo:
|
|
26
|
+
handler: src/generatedCode/CoreFunctions/RemoveSeedDataDynamo_HdrInv.main
|
|
27
|
+
name: ${self:custom.iz_resourcePrefix}RemoveSeedDataDynamo
|
|
28
|
+
role: RemoveSeedDataDynamoRole
|
|
29
|
+
#<#RemoveSeedDataDynamoHookCode#>
|
|
30
|
+
#<#/RemoveSeedDataDynamoHookCode#>
|
|
31
|
+
|
|
32
|
+
InitialSetup:
|
|
33
|
+
handler: src/generatedCode/CoreFunctions/InitialSetup_HdrInv.main
|
|
34
|
+
name: ${self:custom.iz_resourcePrefix}InitialSetup
|
|
35
|
+
role: InitialSetupRole
|
|
36
|
+
timeout: 300
|
|
37
|
+
#<#InitialSetupHookCode#>
|
|
38
|
+
#<#/InitialSetupHookCode#>
|