@izara_project/izara-core-generate-service-code 1.0.67 → 1.0.68

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 (86) hide show
  1. package/.prettierrc +11 -0
  2. package/package.json +16 -12
  3. package/scripts/format-ejs.js +105 -0
  4. package/src/compile/compileProject.js +16 -1
  5. package/src/compile/loadSchemas.js +89 -4
  6. package/src/emit/crud/emitDynamicCrudFlowSchemas.js +1 -2
  7. package/src/emit/crud/templates/CreateEndpoint_Main.ejs +296 -105
  8. package/src/emit/crud/templates/DeleteEndpoint_Main.ejs +222 -144
  9. package/src/emit/crud/templates/FlowEndpointBeforeLogical_Main.ejs +22 -6
  10. package/src/emit/crud/templates/FlowEndpointComplete_Main.ejs +134 -43
  11. package/src/emit/crud/templates/FlowEndpoint_HdrWbs.ejs +51 -31
  12. package/src/emit/crud/templates/FlowHandler_HdrApi.ejs +53 -45
  13. package/src/emit/crud/templates/FlowHandler_HdrInv.ejs +28 -26
  14. package/src/emit/crud/templates/FlowHandler_HdrSqs.ejs +15 -11
  15. package/src/emit/crud/templates/FlowMain_Wbs.ejs +53 -38
  16. package/src/emit/crud/templates/GetEndpoint_Main.ejs +5 -2
  17. package/src/emit/crud/templates/GetRangeEndpoint_Main.ejs +2 -2
  18. package/src/emit/crud/templates/UpdateEndpoint_Main.ejs +402 -249
  19. package/src/emit/custom/customFlows.js +51 -21
  20. package/src/emit/custom/emitCustomFlowApplicationArtifacts.js +13 -18
  21. package/src/emit/custom/templates/FlowEndpoint_Main.ejs +48 -36
  22. package/src/emit/custom/templates/FlowStep_Main.ejs +7 -9
  23. package/src/emit/custom/templates/s3/ConfirmReserved_HdrSqs.ejs +59 -54
  24. package/src/emit/custom/templates/s3/ConfirmReserved_Main.ejs +33 -23
  25. package/src/emit/custom/templates/s3/CreateObject_HdrWbs.ejs +30 -23
  26. package/src/emit/custom/templates/s3/CreateObject_Main.ejs +56 -39
  27. package/src/emit/custom/templates/s3/CreatePreSignUrl_HdrSqs.ejs +56 -51
  28. package/src/emit/custom/templates/s3/CreatePreSignUrl_Main.ejs +112 -75
  29. package/src/emit/custom/templates/s3/FlowHandler_HdrS3.ejs +12 -7
  30. package/src/emit/custom/templates/s3/ProcessS3File_Main.ejs +11 -8
  31. package/src/emit/custom/templates/s3/ReservedLimit_HdrSqs.ejs +64 -55
  32. package/src/emit/custom/templates/s3/ReservedLimit_Main.ejs +74 -52
  33. package/src/emit/custom/templates/triggerCache/CheckTriggerCache_HdrSqs.ejs +58 -14
  34. package/src/emit/custom/templates/triggerCache/CheckTriggerCache_Main.ejs +12 -17
  35. package/src/emit/custom/templates/triggerCache/TriggerCacheComplete_Main.ejs +20 -13
  36. package/src/emit/custom/templates/triggerCache/TriggerCache_Main.ejs +4 -1
  37. package/src/emit/function/functionYamlArtifact.js +20 -0
  38. package/src/emit/rbac/emitDynamicRbacFlowSchemas.js +28 -15
  39. package/src/emit/rbac/emitRbacApplicationArtifacts.js +168 -69
  40. package/src/emit/rbac/templates/CreateTargetRole_HdrSqs.ejs +41 -18
  41. package/src/emit/rbac/templates/CreateTargetRole_Main.ejs +23 -3
  42. package/src/emit/rbac/templates/ListRbac_HdrApi.ejs +27 -5
  43. package/src/emit/rbac/templates/ListRbac_HdrSqs.ejs +41 -8
  44. package/src/emit/rbac/templates/ListRbac_Main.ejs +26 -6
  45. package/src/emit/rbac/templates/RbacMutation_Main.ejs +23 -3
  46. package/src/emit/rbac/templates/UserRbacFlow_HdrSqs.ejs +46 -0
  47. package/src/emit/rbac/templates/UserRbacFlow_Main.ejs +152 -33
  48. package/src/emit/rbac/templates/UserRoleMutation_Main.ejs +24 -4
  49. package/src/emit/relationship/emitDynamicRelationshipFlowSchemas.js +1 -2
  50. package/src/emit/relationship/templates/ChangeRelationshipComplete_Main.ejs +64 -37
  51. package/src/emit/relationship/templates/ChangeRelationship_Main.ejs +258 -142
  52. package/src/emit/relationship/templates/CreateRelationshipComplete_Main.ejs +68 -43
  53. package/src/emit/relationship/templates/CreateRelationship_Main.ejs +315 -171
  54. package/src/emit/relationship/templates/DeleteRelationshipComplete_Main.ejs +67 -41
  55. package/src/emit/relationship/templates/DeleteRelationship_Main.ejs +226 -115
  56. package/src/emit/relationship/templates/FlowHandler_HdrApi.ejs +41 -33
  57. package/src/emit/relationship/templates/FlowHandler_HdrDsq.ejs +15 -11
  58. package/src/emit/relationship/templates/FlowHandler_HdrInv.ejs +28 -26
  59. package/src/emit/relationship/templates/FlowHandler_HdrSqs.ejs +15 -11
  60. package/src/emit/relationship/templates/GetRelationshipComplete_Main.ejs +46 -26
  61. package/src/emit/relationship/templates/GetRelationship_Main.ejs +233 -126
  62. package/src/emit/relationship/templates/MoveRelationshipComplete_Main.ejs +72 -44
  63. package/src/emit/relationship/templates/MoveRelationship_Main.ejs +266 -150
  64. package/src/emit/relationship/templates/UpdateRelationshipComplete_Main.ejs +74 -45
  65. package/src/emit/relationship/templates/UpdateRelationship_Main.ejs +285 -152
  66. package/src/emit/resource/emitResourceArtifacts.js +107 -11
  67. package/src/emit/resource/templates/DynamoDBTable_Yaml.ejs +18 -18
  68. package/src/emit/resource/templates/FlowOut_Yaml.ejs +5 -5
  69. package/src/emit/resource/templates/GeneratedLambdaRoleServiceConfig.ejs +138 -0
  70. package/src/emit/resource/templates/ResourceBeforeLogicalYaml.ejs +44 -44
  71. package/src/emit/resource/templates/ResourceSqsYaml.ejs +36 -36
  72. package/src/emit/resource/templates/ResourceYaml.ejs +48 -48
  73. package/src/emit/resource/templates/S3Bucket_Yaml.ejs +19 -0
  74. package/src/emit/resource/templates/SharedResource_Yaml.ejs +11 -11
  75. package/src/emit/resource/templates/SystemDynamoDB_Yaml.ejs +105 -105
  76. package/src/generate.js +6 -2
  77. package/test/createTargetRoleHandler.test.js +63 -14
  78. package/test/customFlowApplicationArtifacts.test.js +48 -23
  79. package/test/dynamicCrudFlowSchemas.test.js +6 -6
  80. package/test/dynamicRbacFlowSchemas.test.js +8 -12
  81. package/test/dynamicRelationshipFlowSchemas.test.js +3 -3
  82. package/test/publicApi.test.js +10 -12
  83. package/test/resourceArtifacts.test.js +12 -2
  84. package/docs/test.png +0 -0
  85. package/src/emit/rbac/templates/UserRbacFlow_HdrInv.ejs +0 -10
  86. /package/docs/{test.mmd → TriggeredCacheFlow.mmd} +0 -0
@@ -15,14 +15,17 @@ You should have received a copy of the GNU Affero General Public License
15
15
  along with this program. If not, see <http://www.gnu.org/licenses/>.
16
16
  */
17
17
 
18
- import { objectHash as hash, identifierUuid } from '@izara_project/izara-shared-core';
18
+ import {
19
+ objectHash as hash,
20
+ identifierUuid
21
+ } from '@izara_project/izara-shared-core';
19
22
 
20
23
  import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
21
- import lambdaSharedLib from "@izara_project/izara-core-library-lambda";
22
- import snsSharedLib from "@izara_project/izara-core-library-sns";
23
- import asyncFlowSharedLib from "@izara_project/izara-core-library-asynchronous-flow";
24
+ import lambdaSharedLib from '@izara_project/izara-core-library-lambda';
25
+ import snsSharedLib from '@izara_project/izara-core-library-sns';
26
+ import asyncFlowSharedLib from '@izara_project/izara-core-library-asynchronous-flow';
24
27
 
25
- import { sns } from "@izara_project/izara-core-library-external-request";
28
+ import { sns } from '@izara_project/izara-core-library-external-request';
26
29
 
27
30
  import {
28
31
  getObjectSchema,
@@ -32,7 +35,8 @@ import {
32
35
  relSchemaLib
33
36
  } from '@izara_project/izara-core-library-service-schemas';
34
37
 
35
- const { getRelationshipSchemaWithCache, getObjSchemaS3WithHierarchy } = getObjectSchema;
38
+ const { getRelationshipSchemaWithCache, getObjSchemaS3WithHierarchy } =
39
+ getObjectSchema;
36
40
 
37
41
  const { createLinkTypeId } = utils;
38
42
 
@@ -40,11 +44,7 @@ const { getGraphServiceTagWithCache } = serviceConfig;
40
44
 
41
45
  const { findLinksByObjTypes } = relSchemaLib;
42
46
 
43
- const {
44
- PREFIX,
45
- TOPIC_NAME_GENERATE_CODE,
46
- TOPIC_NAME_GRAPH_HANDLER
47
- } = consts;
47
+ const { PREFIX, TOPIC_NAME_GENERATE_CODE, TOPIC_NAME_GRAPH_HANDLER } = consts;
48
48
 
49
49
  import { consts as coreConsts } from '@izara_project/izara-core-library-core';
50
50
 
@@ -61,25 +61,30 @@ import { consts as coreConsts } from '@izara_project/izara-core-library-core';
61
61
  *
62
62
  * @returns {object} description of return value
63
63
  */
64
- export default async function <%- functionName %> (
64
+ export default async function <%- functionName %>(
65
65
  _izContext,
66
66
  requestParams,
67
- callingFlowConfig = {},
67
+ callingFlowConfig = {}
68
68
  //(<additionalParams>)
69
69
  //(</additionalParams>)
70
70
  ) {
71
71
  try {
72
72
  _izContext.logger.debug('<%- functionName %> _izContext: ', _izContext);
73
73
  _izContext.logger.debug('<%- functionName %> requestParams: ', requestParams);
74
- _izContext.logger.debug('<%- functionName %> callingFlowConfig: ', callingFlowConfig);
74
+ _izContext.logger.debug(
75
+ '<%- functionName %> callingFlowConfig: ',
76
+ callingFlowConfig
77
+ );
75
78
 
76
79
  let originTimestamp = Date.now();
77
- let changedByUserId = _izContext.correlationIds.get(coreConsts.BASE_USER_ID)
80
+ let changedByUserId = _izContext.correlationIds.get(
81
+ coreConsts.BASE_USER_ID
82
+ );
78
83
  const {
79
84
  firstObject,
80
85
  secondObject,
81
86
  oldRelTypeAndDirection,
82
- newRelType,
87
+ newRelType
83
88
  //(<requestParamCreateRel>)
84
89
  //(</requestParamCreateRel>)
85
90
  } = requestParams;
@@ -89,54 +94,89 @@ export default async function <%- functionName %> (
89
94
  //(<beforeValidateChangeRel>)
90
95
  //(</beforeValidateChangeRel>).
91
96
  // validate object and identifiers
92
- async function validateIdentifiersExists(_izContext, objType, identifiersObject) {
93
-
97
+ async function validateIdentifiersExists(
98
+ _izContext,
99
+ objType,
100
+ identifiersObject
101
+ ) {
94
102
  const objTypeString = `objType:{ serviceTag:${objType.serviceTag}, objectType:${objType.objectType} }`;
95
- const objectSchema = await getObjSchemaS3WithHierarchy(_izContext, objType);
103
+ const objectSchema = await getObjSchemaS3WithHierarchy(
104
+ _izContext,
105
+ objType
106
+ );
96
107
 
97
108
  if (!objectSchema) {
98
- errorsFound.push(`validateIdentifiers, not found schema of ${objTypeString}`);
109
+ errorsFound.push(
110
+ `validateIdentifiers, not found schema of ${objTypeString}`
111
+ );
99
112
  }
100
113
 
101
114
  for (const schemaIdentifier of objectSchema.identifiers) {
102
- let identifierNames = schemaIdentifier.fieldNames || [schemaIdentifier.fieldName];
115
+ let identifierNames = schemaIdentifier.fieldNames || [
116
+ schemaIdentifier.fieldName
117
+ ];
103
118
  for (const identifierName of identifierNames) {
104
119
  if (!identifiersObject.hasOwnProperty(identifierName)) {
105
- errorsFound.push(`validateIdentifiers, ${objTypeString} property:${identifierName} not exists`);
120
+ errorsFound.push(
121
+ `validateIdentifiers, ${objTypeString} property:${identifierName} not exists`
122
+ );
106
123
  } else {
107
124
  if (
108
- typeof (identifiersObject[identifierName]) !== "string" &&
109
- typeof (identifiersObject[identifierName]) !== "number"
125
+ typeof identifiersObject[identifierName] !== 'string' &&
126
+ typeof identifiersObject[identifierName] !== 'number'
110
127
  ) {
111
- errorsFound.push(`validateIdentifiers, ${objTypeString} property:${identifierName} should be string or number`);
128
+ errorsFound.push(
129
+ `validateIdentifiers, ${objTypeString} property:${identifierName} should be string or number`
130
+ );
112
131
  }
113
132
  }
114
133
  }
115
134
  }
116
135
  }
117
136
 
118
- await validateIdentifiersExists(_izContext, firstObject.objType, firstObject.identifiers);
119
- await validateIdentifiersExists(_izContext, secondObject.objType, secondObject.identifiers);
137
+ await validateIdentifiersExists(
138
+ _izContext,
139
+ firstObject.objType,
140
+ firstObject.identifiers
141
+ );
142
+ await validateIdentifiersExists(
143
+ _izContext,
144
+ secondObject.objType,
145
+ secondObject.identifiers
146
+ );
120
147
  // finished validate object and identifiers
121
148
 
122
149
  //(<afterValidateChangeRel>)
123
150
  //(</afterValidateChangeRel>)
124
151
 
125
152
  // check old relType canChangeToRelType
126
- const oldRelationshipSchema = await getRelationshipSchemaWithCache(_izContext, oldRelTypeAndDirection.relType);
127
- _izContext.logger.debug("oldRelationshipSchema ", oldRelationshipSchema);
128
-
129
- const newRelationshipSchema = await getRelationshipSchemaWithCache(_izContext, newRelType.relType);
130
- _izContext.logger.debug("newRelationshipSchema: ", newRelationshipSchema);
153
+ const oldRelationshipSchema = await getRelationshipSchemaWithCache(
154
+ _izContext,
155
+ oldRelTypeAndDirection.relType
156
+ );
157
+ _izContext.logger.debug('oldRelationshipSchema ', oldRelationshipSchema);
158
+
159
+ const newRelationshipSchema = await getRelationshipSchemaWithCache(
160
+ _izContext,
161
+ newRelType.relType
162
+ );
163
+ _izContext.logger.debug('newRelationshipSchema: ', newRelationshipSchema);
131
164
  if (!oldRelationshipSchema.hasOwnProperty('canChangeToRelTypes')) {
132
- errorsFound.push(`${oldRelTypeAndDirection.relType} not have property to change to another relType`);
165
+ errorsFound.push(
166
+ `${oldRelTypeAndDirection.relType} not have property to change to another relType`
167
+ );
133
168
  } else {
134
169
  if (!newRelationshipSchema) {
135
- errorsFound.push(`${newRelationshipSchema} not exists can't changeToRelType`);
170
+ errorsFound.push(
171
+ `${newRelationshipSchema} not exists can't changeToRelType`
172
+ );
136
173
  } else {
137
- oldRelationshipSchema.canChangeToRelTypes.find(canChangeToRelType => {
138
- if (canChangeToRelType.relType.serviceTag === newRelType.serviceTag &&
139
- canChangeToRelType.relType.relationshipTag === newRelType.relationshipTag) {
174
+ oldRelationshipSchema.canChangeToRelTypes.find((canChangeToRelType) => {
175
+ if (
176
+ canChangeToRelType.relType.serviceTag === newRelType.serviceTag &&
177
+ canChangeToRelType.relType.relationshipTag ===
178
+ newRelType.relationshipTag
179
+ ) {
140
180
  // check changeBy
141
181
  // ? Legacy Code:
142
182
  /*
@@ -151,114 +191,152 @@ export default async function <%- functionName %> (
151
191
  */
152
192
  // ? [Fix]: The legacy logic incorrectly blocked "user" from regular execution and allowed non-user values.
153
193
  // ? It has been corrected to require changeBy === "user" for normal execution.
154
- if (canChangeToRelType.changeBy !== "user") {
194
+ if (canChangeToRelType.changeBy !== 'user') {
155
195
  errorsFound.push(`CanChangeToRelType changeBy is not user`);
156
196
  }
157
197
  }
158
198
  });
159
- };
160
- };
199
+ }
200
+ }
161
201
 
162
- const links = await findLinksByObjTypes(_izContext, [firstObject.objType, secondObject.objType], newRelationshipSchema.links)
163
- _izContext.logger.debug("links", links)
202
+ const links = await findLinksByObjTypes(
203
+ _izContext,
204
+ [firstObject.objType, secondObject.objType],
205
+ newRelationshipSchema.links
206
+ );
207
+ _izContext.logger.debug('links', links);
164
208
  if (!links.length) {
165
- errorsFound.push(`not found link between ${JSON.stringify({ firstObject: firstObject.objType })} ${JSON.stringify({ secondObject: secondObject.objType })}`)
166
- };
209
+ errorsFound.push(
210
+ `not found link between ${JSON.stringify({ firstObject: firstObject.objType })} ${JSON.stringify({ secondObject: secondObject.objType })}`
211
+ );
212
+ }
167
213
 
168
214
  let checkCorrectLink = false;
169
215
  for (let link of links) {
170
- const { serviceTag: fromServiceTag, objectType: fromObjectType } = link.from.objType;
171
- const { serviceTag: toServiceTag, objectType: toObjType } = link.to.objType;
172
-
173
- const { serviceTag: firstServiceTag, objectType: firstObjectType } = firstObject.objType
174
- const { serviceTag: secondServiceTag, objectType: secondObjectType } = secondObject.objType
175
-
176
- const matchFromTo = fromServiceTag === firstServiceTag && fromObjectType === firstObjectType &&
177
- toServiceTag === secondServiceTag && toObjType === secondObjectType;
178
-
179
- const matchToFrom = fromServiceTag === secondServiceTag && fromObjectType === secondObjectType &&
180
- toServiceTag === firstServiceTag && toObjType === firstObjectType;
181
-
182
- if ((oldRelTypeAndDirection.relationshipDirection === "from" && matchFromTo) ||
183
- (oldRelTypeAndDirection.relationshipDirection === "to" && matchToFrom)) {
184
- checkCorrectLink = true
216
+ const { serviceTag: fromServiceTag, objectType: fromObjectType } =
217
+ link.from.objType;
218
+ const { serviceTag: toServiceTag, objectType: toObjType } =
219
+ link.to.objType;
220
+
221
+ const { serviceTag: firstServiceTag, objectType: firstObjectType } =
222
+ firstObject.objType;
223
+ const { serviceTag: secondServiceTag, objectType: secondObjectType } =
224
+ secondObject.objType;
225
+
226
+ const matchFromTo =
227
+ fromServiceTag === firstServiceTag &&
228
+ fromObjectType === firstObjectType &&
229
+ toServiceTag === secondServiceTag &&
230
+ toObjType === secondObjectType;
231
+
232
+ const matchToFrom =
233
+ fromServiceTag === secondServiceTag &&
234
+ fromObjectType === secondObjectType &&
235
+ toServiceTag === firstServiceTag &&
236
+ toObjType === firstObjectType;
237
+
238
+ if (
239
+ (oldRelTypeAndDirection.relationshipDirection === 'from' &&
240
+ matchFromTo) ||
241
+ (oldRelTypeAndDirection.relationshipDirection === 'to' && matchToFrom)
242
+ ) {
243
+ checkCorrectLink = true;
185
244
  break;
186
245
  }
187
- };
246
+ }
188
247
 
189
248
  if (checkCorrectLink == false) {
190
- errorsFound.push(`Wrong Relationship Direction`)
191
- };
249
+ errorsFound.push(`Wrong Relationship Direction`);
250
+ }
192
251
 
193
252
  let targetStorageResources = [];
194
253
 
195
254
  if (newRelationshipSchema) {
196
255
  // find targetStorageResources and validate each storageResources
197
256
  await Promise.all(
198
- newRelationshipSchema.links.map(async ({ from, to, storageResourceTags }) => {
199
- const { serviceTag: fromServiceTag, objectType: fromObjectType } = from.objType
200
- const { serviceTag: toServiceTag, objectType: toObjectType } = to.objType
201
-
202
- const { serviceTag: firstServiceTag, objectType: firstObjectType } = firstObject.objType;
203
- const { serviceTag: secondServiceTag, objectType: secondObjectType } = secondObject.objType;
204
-
205
- // find exists link
206
- if (
207
- (
208
- (firstServiceTag === fromServiceTag && firstObjectType === fromObjectType) &&
209
- (secondServiceTag === toServiceTag && secondObjectType === toObjectType)
210
- ) ||
211
- (
212
- (firstServiceTag === toServiceTag && firstObjectType === toObjectType) &&
213
- (secondServiceTag === fromServiceTag && secondObjectType === fromObjectType)
214
- )
215
- ) {
216
-
217
- // check founded storageResource of link and collect used storageResources
218
- await Promise.all(storageResourceTags.map(async storageResourceTag => {
219
- const usedStorageResource = newRelationshipSchema.storageResources[storageResourceTag];
220
-
221
- if (usedStorageResource.storageType === consts.STORAGE_TYPES.graph) {
222
- const graphServiceTag = await getGraphServiceTagWithCache(_izContext, usedStorageResource.graphServerTag);
223
- if (!graphServiceTag) {
224
- errorsFound.push(`storageResourceTag: ${storageResourceTag} invalid, not found graph serviceTag from graphServerTag: ${usedStorageResource.graphServerTag}`)
225
- }
226
-
227
- targetStorageResources.push({
228
- ...usedStorageResource,
229
- graphServiceTag: graphServiceTag
230
- });
231
- } else {
232
- targetStorageResources.push(usedStorageResource);
233
- }
234
- }));
257
+ newRelationshipSchema.links.map(
258
+ async ({ from, to, storageResourceTags }) => {
259
+ const { serviceTag: fromServiceTag, objectType: fromObjectType } =
260
+ from.objType;
261
+ const { serviceTag: toServiceTag, objectType: toObjectType } =
262
+ to.objType;
263
+
264
+ const { serviceTag: firstServiceTag, objectType: firstObjectType } =
265
+ firstObject.objType;
266
+ const {
267
+ serviceTag: secondServiceTag,
268
+ objectType: secondObjectType
269
+ } = secondObject.objType;
270
+
271
+ // find exists link
272
+ if (
273
+ (firstServiceTag === fromServiceTag &&
274
+ firstObjectType === fromObjectType &&
275
+ secondServiceTag === toServiceTag &&
276
+ secondObjectType === toObjectType) ||
277
+ (firstServiceTag === toServiceTag &&
278
+ firstObjectType === toObjectType &&
279
+ secondServiceTag === fromServiceTag &&
280
+ secondObjectType === fromObjectType)
281
+ ) {
282
+ // check founded storageResource of link and collect used storageResources
283
+ await Promise.all(
284
+ storageResourceTags.map(async (storageResourceTag) => {
285
+ const usedStorageResource =
286
+ newRelationshipSchema.storageResources[storageResourceTag];
287
+
288
+ if (
289
+ usedStorageResource.storageType ===
290
+ consts.STORAGE_TYPES.graph
291
+ ) {
292
+ const graphServiceTag = await getGraphServiceTagWithCache(
293
+ _izContext,
294
+ usedStorageResource.graphServerTag
295
+ );
296
+ if (!graphServiceTag) {
297
+ errorsFound.push(
298
+ `storageResourceTag: ${storageResourceTag} invalid, not found graph serviceTag from graphServerTag: ${usedStorageResource.graphServerTag}`
299
+ );
300
+ }
301
+
302
+ targetStorageResources.push({
303
+ ...usedStorageResource,
304
+ graphServiceTag: graphServiceTag
305
+ });
306
+ } else {
307
+ targetStorageResources.push(usedStorageResource);
308
+ }
309
+ })
310
+ );
311
+ }
235
312
  }
236
- })
313
+ )
237
314
  );
238
315
  //(<afterGetRelChangeRel>)
239
316
  //(</afterGetRelChangeRel>)
240
- _izContext.logger.debug("targetStorageResources: ", targetStorageResources);
317
+ _izContext.logger.debug(
318
+ 'targetStorageResources: ',
319
+ targetStorageResources
320
+ );
241
321
 
242
322
  if (!targetStorageResources.length) {
243
323
  errorsFound.push(`Not found link from relationship schema`);
244
324
  }
245
325
 
246
-
247
326
  // validate properties exists with schema
248
327
  for (const propKey in oldRelTypeAndDirection.fieldNames) {
249
328
  if (!newRelationshipSchema.fieldNames.hasOwnProperty(propKey)) {
250
- errorsFound.push(`property: ${propKey} not exists in relationshipSchema`);
329
+ errorsFound.push(
330
+ `property: ${propKey} not exists in relationshipSchema`
331
+ );
251
332
  }
252
333
  }
253
-
254
334
  } else {
255
335
  errorsFound.push(`relationshipSchema not exists`);
256
336
  }
257
337
 
258
-
259
338
  // if found errors will stop processing
260
339
  if (errorsFound.length) {
261
-
262
340
  let changeRelCompleteMsg = {
263
341
  firstObject,
264
342
  secondObject,
@@ -274,35 +352,60 @@ export default async function <%- functionName %> (
274
352
  };
275
353
 
276
354
  // if have callingFlow will send to message complete
277
- if (callingFlowConfig[callingFlowSharedLib.consts.CALLINGFLOW_PROPERTYNAME]) {
278
- _izContext.logger.debug("HAVE CallingFlow");
279
-
280
- changeRelCompleteMsg = callingFlowSharedLib.addPassBackPropertiesToSnsResponseMessageObject(callingFlowConfig, changeRelCompleteMsg);
281
- let messageAttributes = callingFlowSharedLib.addCallingFlowToSnsResponseMessageAttributes(callingFlowConfig, {});
355
+ if (
356
+ callingFlowConfig[callingFlowSharedLib.consts.CALLINGFLOW_PROPERTYNAME]
357
+ ) {
358
+ _izContext.logger.debug('HAVE CallingFlow');
359
+
360
+ changeRelCompleteMsg =
361
+ callingFlowSharedLib.addPassBackPropertiesToSnsResponseMessageObject(
362
+ callingFlowConfig,
363
+ changeRelCompleteMsg
364
+ );
365
+ let messageAttributes =
366
+ callingFlowSharedLib.addCallingFlowToSnsResponseMessageAttributes(
367
+ callingFlowConfig,
368
+ {}
369
+ );
282
370
 
283
371
  let messageParams = {
284
372
  Message: JSON.stringify(changeRelCompleteMsg),
285
- MessageAttributes: sns.createStringMessageAttributes(_izContext, messageAttributes),
286
- TopicArn: await snsSharedLib.snsTopicArnByFlowSchema(_izContext, TOPIC_NAME_GENERATE_CODE.outChangeRelationshipComplete),
373
+ MessageAttributes: sns.createStringMessageAttributes(
374
+ _izContext,
375
+ messageAttributes
376
+ ),
377
+ TopicArn: snsSharedLib.snsTopicArnByFlowSchema(
378
+ _izContext,
379
+ TOPIC_NAME_GENERATE_CODE.outChangeRelationshipComplete
380
+ )
287
381
  };
288
382
 
289
- _izContext.logger.debug("messageParams OutCreateRelationshipComplete ::::::: ", messageParams);
383
+ _izContext.logger.debug(
384
+ 'messageParams OutCreateRelationshipComplete ::::::: ',
385
+ messageParams
386
+ );
290
387
  await sns.publishAsync(_izContext, messageParams);
291
388
  }
292
389
 
293
390
  return changeRelCompleteMsg;
294
391
  }
295
392
 
296
-
297
393
  // before create awaitingStepId per graph storageResource
298
- const linkTypeId = createLinkTypeId(_izContext, firstObject.objType, secondObject.objType, newRelType, oldRelTypeAndDirection.relationshipDirection);
394
+ const linkTypeId = createLinkTypeId(
395
+ _izContext,
396
+ firstObject.objType,
397
+ secondObject.objType,
398
+ newRelType,
399
+ oldRelTypeAndDirection.relationshipDirection
400
+ );
299
401
 
300
402
  let usedGraphServiceTag = []; // collect used graph serviceTag, use to check duplicate graph serviceTag across graph serverTag
301
403
  let targetGraphStorageResources = []; // collect used graph storageResources, filtered duplicate graphServiceTag from graphServerTag out
302
404
  let awaitingStepIds = [];
303
405
 
304
406
  for (const targetStorageResource of targetStorageResources) {
305
- if (targetStorageResource.storageType === consts.STORAGE_TYPES.graph &&
407
+ if (
408
+ targetStorageResource.storageType === consts.STORAGE_TYPES.graph &&
306
409
  !usedGraphServiceTag.includes(targetStorageResource.graphServiceTag)
307
410
  ) {
308
411
  usedGraphServiceTag.push(targetStorageResource.graphServiceTag);
@@ -322,7 +425,8 @@ export default async function <%- functionName %> (
322
425
  // save awaiting
323
426
  await asyncFlowSharedLib.createAwaitingMultipleSteps(
324
427
  _izContext,
325
- asyncFlowSharedLib.createPendingStepId( // pendingStepId
428
+ asyncFlowSharedLib.createPendingStepId(
429
+ // pendingStepId
326
430
  _izContext.uniqueRequestId, // hash id
327
431
  PREFIX.changeRel // prefix, use constant further
328
432
  ),
@@ -337,43 +441,57 @@ export default async function <%- functionName %> (
337
441
  newRelType,
338
442
  originTimestamp,
339
443
  changedByUserId,
340
- parentFlowId,
444
+ parentFlowId
341
445
  //(<messageBodyChangeRel>)
342
446
  //(</messageBodyChangeRel>)
343
447
 
344
448
  // assign originTimestamp if not exists in relationshipProperties
345
- }
449
+ };
346
450
  _izContext.logger.debug('changeRelMessageBody: ', changeRelMessageBody);
347
451
 
348
452
  await Promise.all(
349
453
  targetGraphStorageResources.map(async (storageResource) => {
350
454
  if (storageResource.storageType === consts.STORAGE_TYPES.graph) {
351
-
352
- changeRelMessageBody = callingFlowSharedLib.addCallingFlowToSnsRequestMessageObject(
353
- changeRelMessageBody,
354
- callingFlowSharedLib.addParentCallingFlowConfig(
355
- callingFlowConfig, // receive parent callingFlowConfig.
356
- callingFlowSharedLib.createCallingFlowConfig( // calling flow own service
357
- //(<callingFlowProperties>)
358
- await lambdaSharedLib.lambdaFunctionName(_izContext, TOPIC_NAME_GENERATE_CODE.changeRelationshipComplete),
359
- //(</callingFlowProperties>)
360
- {
361
- graphServiceTag: storageResource.graphServiceTag
362
- }
455
+ changeRelMessageBody =
456
+ callingFlowSharedLib.addCallingFlowToSnsRequestMessageObject(
457
+ changeRelMessageBody,
458
+ callingFlowSharedLib.addParentCallingFlowConfig(
459
+ callingFlowConfig, // receive parent callingFlowConfig.
460
+ callingFlowSharedLib.createCallingFlowConfig(
461
+ // calling flow own service
462
+ //(<callingFlowProperties>)
463
+ await lambdaSharedLib.lambdaFunctionName(
464
+ _izContext,
465
+ TOPIC_NAME_GENERATE_CODE.changeRelationshipComplete
466
+ ),
467
+ //(</callingFlowProperties>)
468
+ {
469
+ graphServiceTag: storageResource.graphServiceTag
470
+ }
471
+ )
363
472
  )
364
- )
473
+ );
474
+ _izContext.logger.debug(
475
+ 'messageObject before send message:',
476
+ changeRelMessageBody
365
477
  );
366
- _izContext.logger.debug("messageObject before send message:", changeRelMessageBody)
367
478
 
368
479
  let messageToInChangeRelationship = {
369
480
  Message: JSON.stringify(changeRelMessageBody),
370
- TopicArn: await snsSharedLib.snsTopicArnByFlowSchema(_izContext, TOPIC_NAME_GRAPH_HANDLER.inChangeRelationship, storageResource.graphServiceTag),
481
+ TopicArn: snsSharedLib.snsTopicArnByFlowSchema(
482
+ _izContext,
483
+ TOPIC_NAME_GRAPH_HANDLER.inChangeRelationship,
484
+ storageResource.graphServiceTag
485
+ )
371
486
  };
372
- _izContext.logger.debug("RequestParams before send to sqs messageToInUpdateRelationship ::::::: ", messageToInChangeRelationship);
487
+ _izContext.logger.debug(
488
+ 'RequestParams before send to sqs messageToInUpdateRelationship ::::::: ',
489
+ messageToInChangeRelationship
490
+ );
373
491
  await sns.publishAsync(_izContext, messageToInChangeRelationship);
374
492
  }
375
493
  })
376
- )
494
+ );
377
495
  }
378
496
 
379
497
  return {
@@ -383,12 +501,10 @@ export default async function <%- functionName %> (
383
501
  newRelType,
384
502
  originTimestamp,
385
503
  changedByUserId,
386
- status: "complete"
504
+ status: 'complete'
387
505
  };
388
-
389
-
390
506
  } catch (err) {
391
- _izContext.logger.error('error ChangeRelationship: ', err)
392
- throw (err)
507
+ _izContext.logger.error('error ChangeRelationship: ', err);
508
+ throw err;
393
509
  }
394
510
  }