@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.
Files changed (128) hide show
  1. package/.prettierrc +11 -0
  2. package/package.json +16 -12
  3. package/scripts/format-ejs.js +104 -0
  4. package/src/compile/compileProject.js +40 -9
  5. package/src/compile/loadSchemas.js +120 -11
  6. package/src/emit/crud/emitCrudApplicationArtifacts.js +188 -41
  7. package/src/emit/crud/emitDynamicCrudFlowSchemas.js +34 -18
  8. package/src/emit/crud/generateCrudApplicationArtifacts.js +14 -6
  9. package/src/emit/crud/generateDynamicCrudFlowSchemas.js +4 -1
  10. package/src/emit/crud/templates/CreateEndpoint_Main.ejs +296 -105
  11. package/src/emit/crud/templates/DeleteEndpoint_Main.ejs +222 -144
  12. package/src/emit/crud/templates/FlowEndpointBeforeLogical_Main.ejs +22 -6
  13. package/src/emit/crud/templates/FlowEndpointComplete_Main.ejs +134 -43
  14. package/src/emit/crud/templates/FlowEndpoint_HdrWbs.ejs +51 -31
  15. package/src/emit/crud/templates/FlowHandler_HdrApi.ejs +53 -45
  16. package/src/emit/crud/templates/FlowHandler_HdrInv.ejs +28 -26
  17. package/src/emit/crud/templates/FlowHandler_HdrSqs.ejs +15 -11
  18. package/src/emit/crud/templates/FlowMain_Wbs.ejs +53 -38
  19. package/src/emit/crud/templates/GetEndpoint_Main.ejs +6 -3
  20. package/src/emit/crud/templates/GetRangeEndpoint_Main.ejs +2 -2
  21. package/src/emit/crud/templates/UpdateEndpoint_Main.ejs +402 -249
  22. package/src/emit/custom/customFlows.js +68 -28
  23. package/src/emit/custom/emitCustomFlowApplicationArtifacts.js +520 -123
  24. package/src/emit/custom/generateCustomFlowApplicationArtifacts.js +28 -8
  25. package/src/emit/custom/templates/FlowEndpoint_Main.ejs +48 -36
  26. package/src/emit/custom/templates/FlowStep_Main.ejs +7 -9
  27. package/src/emit/custom/templates/s3/ConfirmReserved_HdrSqs.ejs +59 -54
  28. package/src/emit/custom/templates/s3/ConfirmReserved_Main.ejs +33 -23
  29. package/src/emit/custom/templates/s3/CreateObject_HdrWbs.ejs +30 -23
  30. package/src/emit/custom/templates/s3/CreateObject_Main.ejs +56 -39
  31. package/src/emit/custom/templates/s3/CreatePreSignUrl_HdrSqs.ejs +56 -51
  32. package/src/emit/custom/templates/s3/CreatePreSignUrl_Main.ejs +112 -75
  33. package/src/emit/custom/templates/s3/FlowHandler_HdrS3.ejs +14 -9
  34. package/src/emit/custom/templates/s3/ProcessS3File_Main.ejs +11 -8
  35. package/src/emit/custom/templates/s3/ReservedLimit_HdrSqs.ejs +65 -56
  36. package/src/emit/custom/templates/s3/ReservedLimit_Main.ejs +74 -52
  37. package/src/emit/custom/templates/triggerCache/CheckTriggerCache_HdrSqs.ejs +58 -14
  38. package/src/emit/custom/templates/triggerCache/CheckTriggerCache_Main.ejs +12 -17
  39. package/src/emit/custom/templates/triggerCache/TriggerCacheComplete_Main.ejs +20 -13
  40. package/src/emit/custom/templates/triggerCache/TriggerCache_Main.ejs +4 -1
  41. package/src/emit/function/functionYamlArtifact.js +272 -79
  42. package/src/emit/function/templates/ApiFunction_Yaml.ejs +7 -0
  43. package/src/emit/function/templates/EventBridgeFunction_Yaml.ejs +6 -0
  44. package/src/emit/function/templates/InvFunction_Yaml.ejs +5 -0
  45. package/src/emit/function/templates/S3Function_Yaml.ejs +16 -0
  46. package/src/emit/function/templates/SqsFunction_Yaml.ejs +10 -0
  47. package/src/emit/function/templates/WbsFunction_Yaml.ejs +10 -0
  48. package/src/emit/rbac/emitDynamicRbacFlowSchemas.js +40 -29
  49. package/src/emit/rbac/emitRbacApplicationArtifacts.js +171 -72
  50. package/src/emit/rbac/generateCreateTargetRoleHandler.js +6 -4
  51. package/src/emit/rbac/generateDynamicRbacFlowSchemas.js +8 -2
  52. package/src/emit/rbac/rbacFlowTag.js +3 -1
  53. package/src/emit/rbac/templates/CreateTargetRole_HdrSqs.ejs +41 -18
  54. package/src/emit/rbac/templates/CreateTargetRole_Main.ejs +23 -3
  55. package/src/emit/rbac/templates/ListRbac_HdrApi.ejs +27 -5
  56. package/src/emit/rbac/templates/ListRbac_HdrSqs.ejs +41 -8
  57. package/src/emit/rbac/templates/ListRbac_Main.ejs +26 -6
  58. package/src/emit/rbac/templates/RbacMutation_Main.ejs +23 -3
  59. package/src/emit/rbac/templates/UserRbacFlow_HdrSqs.ejs +46 -0
  60. package/src/emit/rbac/templates/UserRbacFlow_Main.ejs +152 -33
  61. package/src/emit/rbac/templates/UserRoleMutation_Main.ejs +24 -4
  62. package/src/emit/relationship/emitDynamicRelationshipFlowSchemas.js +26 -11
  63. package/src/emit/relationship/emitRelationshipApplicationArtifacts.js +179 -37
  64. package/src/emit/relationship/generateDynamicRelationshipFlowSchemas.js +8 -2
  65. package/src/emit/relationship/generateRelationshipApplicationArtifacts.js +15 -6
  66. package/src/emit/relationship/templates/ChangeRelationshipComplete_Main.ejs +64 -37
  67. package/src/emit/relationship/templates/ChangeRelationship_Main.ejs +258 -142
  68. package/src/emit/relationship/templates/CreateRelationshipComplete_Main.ejs +68 -43
  69. package/src/emit/relationship/templates/CreateRelationship_Main.ejs +315 -171
  70. package/src/emit/relationship/templates/DeleteRelationshipComplete_Main.ejs +67 -41
  71. package/src/emit/relationship/templates/DeleteRelationship_Main.ejs +226 -115
  72. package/src/emit/relationship/templates/FlowHandler_HdrApi.ejs +41 -33
  73. package/src/emit/relationship/templates/FlowHandler_HdrDsq.ejs +15 -11
  74. package/src/emit/relationship/templates/FlowHandler_HdrInv.ejs +28 -26
  75. package/src/emit/relationship/templates/FlowHandler_HdrSqs.ejs +15 -11
  76. package/src/emit/relationship/templates/GetRelationshipComplete_Main.ejs +46 -26
  77. package/src/emit/relationship/templates/GetRelationship_Main.ejs +233 -126
  78. package/src/emit/relationship/templates/MoveRelationshipComplete_Main.ejs +72 -44
  79. package/src/emit/relationship/templates/MoveRelationship_Main.ejs +266 -150
  80. package/src/emit/relationship/templates/UpdateRelationshipComplete_Main.ejs +74 -45
  81. package/src/emit/relationship/templates/UpdateRelationship_Main.ejs +285 -152
  82. package/src/emit/resource/emitResourceArtifacts.js +274 -105
  83. package/src/emit/resource/generateResourceArtifacts.js +15 -6
  84. package/src/emit/resource/templates/GeneratedLambdaRoleServiceConfig.ejs +139 -0
  85. package/src/emit/resource/templates/S3Bucket_Yaml.ejs +19 -0
  86. package/src/emit/resource/templates/S3Subscription_Yaml.ejs +7 -0
  87. package/src/emit/resource/templates/WebSocketSubscription_Yaml.ejs +7 -0
  88. package/src/emit/system/emitSystemWebSocketArtifacts.js +61 -165
  89. package/src/emit/system/templates/WebSocketComplete_HdrSqs.ejs +32 -0
  90. package/src/emit/system/templates/WebSocketComplete_Main.ejs +46 -0
  91. package/src/emit/system/templates/WebSocketComplete_Yaml.ejs +19 -0
  92. package/src/emit/system/templates/WebSocketConnect.ejs +25 -0
  93. package/src/emit/system/templates/WebSocketConnect_Yaml.ejs +11 -0
  94. package/src/generate.js +141 -34
  95. package/src/generateIntTest.js +76 -28
  96. package/src/generateResourceIntTest.js +35 -12
  97. package/src/generateResources/IntTest/generateResources/generateResources.js +5 -2
  98. package/src/generateResources/IntTest/generateResources/templateResources.ejs +18 -30
  99. package/src/generateResources/IntTest/generateTests/events/events.js +1 -1
  100. package/src/generateResources/IntTest/generateTests/events/templateEvents.ejs +13 -10
  101. package/src/generateResources/IntTest/generateTests/generateTemplate.js +2 -2
  102. package/src/generateResources/IntTest/generateTests/pathIntTest/pathIntTest.js +2 -1
  103. package/src/generateResources/IntTest/generateTests/pathIntTest/template.ejs +1 -3
  104. package/src/generateResources/IntTest/generateTests/tests/templateTests.ejs +1 -1
  105. package/src/generateResources/IntTest/generateTests/tests/tests.js +7 -3
  106. package/src/generateResources/IntTest/libs/{libs.js → IntTestGenerateLib.js} +34 -23
  107. package/src/generateResources/IntTest/upload/uploadIntTest.js +33 -19
  108. package/src/intTestGeneratorShared.js +15 -10
  109. package/src/output/commitArtifacts.js +99 -39
  110. package/src/output/mergeHooks.js +24 -10
  111. package/src/output/validateArtifacts.js +37 -27
  112. package/src/plan/buildGenerationPlan.js +24 -13
  113. package/test/core.test.js +116 -49
  114. package/test/createTargetRoleHandler.test.js +63 -14
  115. package/test/crudApplicationArtifacts.test.js +128 -23
  116. package/test/customFlowApplicationArtifacts.test.js +391 -84
  117. package/test/dynamicCrudFlowSchemas.test.js +74 -26
  118. package/test/dynamicRbacFlowSchemas.test.js +63 -20
  119. package/test/dynamicRelationshipFlowSchemas.test.js +65 -18
  120. package/test/functionYamlArtifact.test.js +67 -10
  121. package/test/intTestApi.test.js +9 -10
  122. package/test/publicApi.test.js +184 -44
  123. package/test/relationshipApplicationArtifacts.test.js +90 -19
  124. package/test/resourceArtifacts.test.js +183 -33
  125. package/docs/test.png +0 -0
  126. package/src/emit/rbac/templates/UserRbacFlow_HdrInv.ejs +0 -10
  127. package/src/emit/relationship/dynamicRelationshipFlowSchemaTemplate.js +0 -11
  128. /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 { crudApplicationManagedPaths, emitCrudApplicationArtifacts } from './emit/crud/emitCrudApplicationArtifacts.js';
5
- import { dynamicCrudFlowSchemaPaths, emitDynamicCrudFlowSchemas } from './emit/crud/emitDynamicCrudFlowSchemas.js';
6
- import { customFlowApplicationManagedPaths, emitCustomFlowApplicationArtifacts } from './emit/custom/emitCustomFlowApplicationArtifacts.js';
7
- import { emitDynamicRbacFlowSchemas, rbacFlowSchemaManagedPaths } from './emit/rbac/emitDynamicRbacFlowSchemas.js';
8
- import { emitRbacApplicationArtifacts, rbacApplicationManagedPaths } from './emit/rbac/emitRbacApplicationArtifacts.js';
9
- import { dynamicRelationshipFlowSchemaPaths, emitDynamicRelationshipFlowSchemas } from './emit/relationship/emitDynamicRelationshipFlowSchemas.js';
10
- import { emitRelationshipApplicationArtifacts, relationshipApplicationManagedPaths } from './emit/relationship/emitRelationshipApplicationArtifacts.js';
11
- import { emitResourceArtifacts, resourceArtifactPaths } from './emit/resource/emitResourceArtifacts.js';
12
- import { loadLocalSchemaDirectory } from './compile/loadSchemas.js';
13
- import { emitSystemWebSocketArtifacts, hasSystemWebSocket, systemWebSocketManagedPaths } from './emit/system/emitSystemWebSocketArtifacts.js';
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 [objects, relationships, flows] = await Promise.all([
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
- logger?.debug?.(`[DEBUG] [Generate] STATUS=SCHEMAS_LOADED | objects=${objects.length} relationships=${relationships.length} flows=${flows.length}`);
27
- const groups = await emitGroups({ project, objects, relationships, flows });
28
- logger?.debug?.(`[DEBUG] [Generate] STATUS=ARTIFACTS_EMITTED | ${groups.map(group => `${group.scope}=${group.artifacts.length}`).join(' ')}`);
29
- const files = groups.length === 0
30
- ? []
31
- : await commitArtifacts(buildGenerationPlan(project, groups.flatMap(group => group.artifacts), {
32
- managedScopes: Object.fromEntries(groups.map(group => [group.scope, group.managedPaths]))
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?.(`[INFO] [Generate] STATUS=FINISHED | files=${files.length} durationMs=${durationMs}`);
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?.(`[ERROR] [Generate] STATUS=FAILED | durationMs=${Date.now() - startedAt}`, 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 emitGroups({ project, objects, relationships, flows }) {
97
+ async function _emitGroups({ project, objects, relationships, flows }) {
45
98
  const [crud, relationship, rbac, system, resource] = await Promise.all([
46
- emitCrudApplicationArtifacts({ objects, flows, serviceTag: project.serviceTag }),
47
- emitRelationshipApplicationArtifacts({ relationships, flows, serviceTag: project.serviceTag }),
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, { systemFunctions: system.functions, objects });
113
+ const custom = await emitCustomFlowApplicationArtifacts(flows, {
114
+ systemFunctions: system.functions,
115
+ objects
116
+ });
53
117
  return [
54
- { scope: 'crud-flow-schemas', managedPaths: dynamicCrudFlowSchemaPaths, artifacts: emitDynamicCrudFlowSchemas({ objects, flows }) },
55
- { scope: 'relationship-flow-schemas', managedPaths: dynamicRelationshipFlowSchemaPaths, artifacts: emitDynamicRelationshipFlowSchemas() },
56
- { scope: 'rbac-flow-schemas', managedPaths: rbacFlowSchemaManagedPaths(objects), artifacts: await emitDynamicRbacFlowSchemas({ objects, serviceTag: project.serviceTag }) },
57
- { scope: 'crud-application', managedPaths: crudApplicationManagedPaths(), artifacts: crud },
58
- { scope: 'relationship-application', managedPaths: relationshipApplicationManagedPaths(), artifacts: relationship },
59
- { scope: 'rbac-application', managedPaths: rbacApplicationManagedPaths(objects), artifacts: rbac },
60
- { scope: 'system-websocket', managedPaths: systemWebSocketManagedPaths(), artifacts: system.artifacts },
61
- { scope: 'custom-flow-application', managedPaths: customFlowApplicationManagedPaths(flows, { includeYaml: hasSystemWebSocket(flows, { includeRelationshipOwnTopic: true }) }), artifacts: custom },
62
- { scope: 'shared-resources', managedPaths: resourceArtifactPaths, artifacts: resource }
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
  }
@@ -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 { appendFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
17
+ import {
18
+ appendFileSync,
19
+ existsSync,
20
+ mkdirSync,
21
+ readFileSync,
22
+ writeFileSync
23
+ } from 'fs';
18
24
  import { join } from 'path';
19
- import ejs from 'ejs';
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 { DEFAULT_BUCKET, uploadToS3 } from './generateResources/IntTest/upload/uploadIntTest.js';
24
- import { getIntTestOutputPath, getServiceTag, runTemplateItems } from './intTestGeneratorShared.js';
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 writeSource({ templatePath, templateData, setting }, { checkCreateSourcePass = false } = {}) {
49
+ async function _writeSource(
50
+ { templatePath, templateData, setting },
51
+ { checkCreateSourcePass = false } = {}
52
+ ) {
37
53
  if (!templatePath || !templateData || !setting) {
38
- throw new Error('Invalid IntTest source item: missing templatePath/templateData/setting');
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
- ejs.compile(readFileSync(templatePath, 'utf8'))(templateData);
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)) mkdirSync(savePath, { recursive: true });
67
- if (generateHookFile && !existsSync(hookDataPath)) mkdirSync(hookDataPath, { recursive: true });
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 = ejs.compile(readFileSync(templatePath, 'utf8'))(templateData);
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
- const anyDoubleTag = isJs
74
- ? new RegExp('\\/\\/\\(<(\\w+)>\\)([\\s\\S]*?)\\/\\/\\(<\\/\\1>\\)', 'gm')
75
- : isYml
76
- ? new RegExp('\\#<#(\\w+)#>([\\s\\S]*?)\\#<#\\/\\1#>', 'gm')
77
- : null;
78
- const doubleTag = isJs
79
- ? (name) => new RegExp(`\\/\\/\\(<${name}>\\)([\\s\\S]*?)\\/\\/\\(<\\/${name}>\\)`, 'gm')
80
- : isYml
81
- ? (name) => new RegExp(`\\#<#${name}#>([\\s\\S]*?)\\#<#\\/${name}#>`, 'gm')
82
- : null;
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(anyDoubleTag, (match, tagName) => (
86
- hookData.match(doubleTag(tagName)) ?? match
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) dataToSave = beautify(dataToSave, BEAUTIFY_SETTING);
127
+ if (isJs) {
128
+ dataToSave = beautify(dataToSave, BEAUTIFY_SETTING);
129
+ }
92
130
 
93
131
  if (isAppend) {
94
132
  const shouldWriteWithInitial = !existsSync(filePath) && initialData;
95
- const content = `${shouldWriteWithInitial ? initialData : ''}${dataToSave}\n\n`;
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('Missing iz_serviceTag in serverless.config.yml — required IntTest generation');
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: shouldUploadToS3 ? s3Bucket : null
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 ejs from 'ejs';
19
+ import ejsLib from 'ejs';
20
20
 
21
21
  import generateResourceTemplate from './generateResources/IntTest/generateResources/generateResources.js';
22
- import { DEFAULT_BUCKET, uploadToS3 } from './generateResources/IntTest/upload/uploadIntTest.js';
23
- import { getIntTestOutputPath, getServiceTag, runTemplateItems } from './intTestGeneratorShared.js';
24
-
25
- function writeSource({ templatePath, templateData, setting }, { checkCreateSourcePass = false } = {}) {
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('Invalid IntTest resource item: missing templatePath/templateData/setting');
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
- ejs.compile(readFileSync(templatePath, 'utf8'))(templateData);
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 = ejs.compile(readFileSync(templatePath, 'utf8'))(templateData);
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('Missing iz_serviceTag in serverless.config.yml — required IntTest resource generation');
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, { serviceTag });
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: shouldUploadToS3 ? s3Bucket : null
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 { getObjectSchema, consts as coreConsts } from '@izara_project/izara-core-library-service-schemas';
24
- import libs from '../libs/libs.js';
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
- "Lambda": {
3
- <% Object.entries(functionComponent).forEach(([funcName, filePath], index, array) => { %>
4
- "<%= funcName %>": {
5
- "localLocation": "/<%= filePath %>.js",
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
- <% if (Object.keys(s3Component).length) { %>
13
- "S3": {
14
- <% Object.entries(s3Component).forEach(([functionName, filePath], index, array) => { %>
15
- "<%= functionName %>": {
16
- "localLocation": "/<%= filePath %>",
17
- "localHandler": "main",
18
- "functionName": "<%= functionName %>"
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
- <% if (Object.keys(tableNames).length) { %>
25
- "Dynamodb": {
26
- <% tableNames.forEach((tableName, index) => { %>
27
- "<%= tableName %>": {
28
- "tableName": "<%= tableName %>"
29
- }<%= index < tableNames.length - 1 ? "," : "" %>
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/libs.js';
24
+ import libs from '../../libs/IntTestGenerateLib.js';
25
25
  const {
26
26
  setEvent,
27
27
  createEventCaseByHandler,
@@ -1,11 +1,14 @@
1
- {
2
- "<%- inputEventTag %>": <%- JSON.stringify(inputConfig, null, 2) %>,
3
- "<%- outputEventTag %>": <%- JSON.stringify(outputConfig, null, 2) %> <%- eventDynamos.length ? "," : "" -%>
4
- <% eventDynamos.forEach((eventDynamo,idx) => { %>
5
- "<%- eventDynamo.eventTag %>": <%- JSON.stringify(eventDynamo.event,null,2) %> <%- idx < eventDynamos.length - 1 ? ",": "" -%>
6
- <% }) %> <%- eventInvokes.length ? "," : "" -%>
7
- <% eventInvokes.forEach((invokeEventComponent,index) => { %>
8
- "<%- invokeEventComponent.inputInvokeName %>": <%- JSON.stringify(invokeEventComponent.inputInvoke,null,2) %>,
9
- "<%- invokeEventComponent.outputInvokeName %>": <%- JSON.stringify(invokeEventComponent.outputInvoke,null,2) %><%- index < eventInvokes.length - 1 ? ",": "" -%>
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/libs.js';
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 = /(events|tests|resources|dynamoDBSeedDataTags|graphSeedDataTags)\.json$/;
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
  ]
@@ -1,3 +1,3 @@
1
1
  [
2
- <%- JSON.stringify(baseIntTest, null, 2) %>
2
+ <%- JSON.stringify(baseIntTest, null, 2) %>
3
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/libs.js';
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 { HANDLER, GENERATE_SEED_DATA_TYPE, SEED_DATA_TAG } from '../../consts.js';
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