@izara_project/izara-core-generate-service-code 1.0.67 → 1.0.69
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prettierrc +11 -0
- package/package.json +16 -12
- package/scripts/format-ejs.js +104 -0
- package/src/compile/compileProject.js +40 -9
- package/src/compile/loadSchemas.js +120 -11
- package/src/emit/crud/emitCrudApplicationArtifacts.js +188 -41
- package/src/emit/crud/emitDynamicCrudFlowSchemas.js +34 -18
- package/src/emit/crud/generateCrudApplicationArtifacts.js +14 -6
- package/src/emit/crud/generateDynamicCrudFlowSchemas.js +4 -1
- package/src/emit/crud/templates/CreateEndpoint_Main.ejs +296 -105
- package/src/emit/crud/templates/DeleteEndpoint_Main.ejs +222 -144
- package/src/emit/crud/templates/FlowEndpointBeforeLogical_Main.ejs +22 -6
- package/src/emit/crud/templates/FlowEndpointComplete_Main.ejs +134 -43
- package/src/emit/crud/templates/FlowEndpoint_HdrWbs.ejs +51 -31
- package/src/emit/crud/templates/FlowHandler_HdrApi.ejs +53 -45
- package/src/emit/crud/templates/FlowHandler_HdrInv.ejs +28 -26
- package/src/emit/crud/templates/FlowHandler_HdrSqs.ejs +15 -11
- package/src/emit/crud/templates/FlowMain_Wbs.ejs +53 -38
- package/src/emit/crud/templates/GetEndpoint_Main.ejs +6 -3
- package/src/emit/crud/templates/GetRangeEndpoint_Main.ejs +2 -2
- package/src/emit/crud/templates/UpdateEndpoint_Main.ejs +402 -249
- package/src/emit/custom/customFlows.js +68 -28
- package/src/emit/custom/emitCustomFlowApplicationArtifacts.js +520 -123
- package/src/emit/custom/generateCustomFlowApplicationArtifacts.js +28 -8
- package/src/emit/custom/templates/FlowEndpoint_Main.ejs +48 -36
- package/src/emit/custom/templates/FlowStep_Main.ejs +7 -9
- package/src/emit/custom/templates/s3/ConfirmReserved_HdrSqs.ejs +59 -54
- package/src/emit/custom/templates/s3/ConfirmReserved_Main.ejs +33 -23
- package/src/emit/custom/templates/s3/CreateObject_HdrWbs.ejs +30 -23
- package/src/emit/custom/templates/s3/CreateObject_Main.ejs +56 -39
- package/src/emit/custom/templates/s3/CreatePreSignUrl_HdrSqs.ejs +56 -51
- package/src/emit/custom/templates/s3/CreatePreSignUrl_Main.ejs +112 -75
- package/src/emit/custom/templates/s3/FlowHandler_HdrS3.ejs +14 -9
- package/src/emit/custom/templates/s3/ProcessS3File_Main.ejs +11 -8
- package/src/emit/custom/templates/s3/ReservedLimit_HdrSqs.ejs +65 -56
- package/src/emit/custom/templates/s3/ReservedLimit_Main.ejs +74 -52
- package/src/emit/custom/templates/triggerCache/CheckTriggerCache_HdrSqs.ejs +58 -14
- package/src/emit/custom/templates/triggerCache/CheckTriggerCache_Main.ejs +12 -17
- package/src/emit/custom/templates/triggerCache/TriggerCacheComplete_Main.ejs +20 -13
- package/src/emit/custom/templates/triggerCache/TriggerCache_Main.ejs +4 -1
- package/src/emit/function/functionYamlArtifact.js +272 -79
- package/src/emit/function/templates/ApiFunction_Yaml.ejs +7 -0
- package/src/emit/function/templates/EventBridgeFunction_Yaml.ejs +6 -0
- package/src/emit/function/templates/InvFunction_Yaml.ejs +5 -0
- package/src/emit/function/templates/S3Function_Yaml.ejs +16 -0
- package/src/emit/function/templates/SqsFunction_Yaml.ejs +10 -0
- package/src/emit/function/templates/WbsFunction_Yaml.ejs +10 -0
- package/src/emit/rbac/emitDynamicRbacFlowSchemas.js +40 -29
- package/src/emit/rbac/emitRbacApplicationArtifacts.js +171 -72
- package/src/emit/rbac/generateCreateTargetRoleHandler.js +6 -4
- package/src/emit/rbac/generateDynamicRbacFlowSchemas.js +8 -2
- package/src/emit/rbac/rbacFlowTag.js +3 -1
- package/src/emit/rbac/templates/CreateTargetRole_HdrSqs.ejs +41 -18
- package/src/emit/rbac/templates/CreateTargetRole_Main.ejs +23 -3
- package/src/emit/rbac/templates/ListRbac_HdrApi.ejs +27 -5
- package/src/emit/rbac/templates/ListRbac_HdrSqs.ejs +41 -8
- package/src/emit/rbac/templates/ListRbac_Main.ejs +26 -6
- package/src/emit/rbac/templates/RbacMutation_Main.ejs +23 -3
- package/src/emit/rbac/templates/UserRbacFlow_HdrSqs.ejs +46 -0
- package/src/emit/rbac/templates/UserRbacFlow_Main.ejs +152 -33
- package/src/emit/rbac/templates/UserRoleMutation_Main.ejs +24 -4
- package/src/emit/relationship/emitDynamicRelationshipFlowSchemas.js +26 -11
- package/src/emit/relationship/emitRelationshipApplicationArtifacts.js +179 -37
- package/src/emit/relationship/generateDynamicRelationshipFlowSchemas.js +8 -2
- package/src/emit/relationship/generateRelationshipApplicationArtifacts.js +15 -6
- package/src/emit/relationship/templates/ChangeRelationshipComplete_Main.ejs +64 -37
- package/src/emit/relationship/templates/ChangeRelationship_Main.ejs +258 -142
- package/src/emit/relationship/templates/CreateRelationshipComplete_Main.ejs +68 -43
- package/src/emit/relationship/templates/CreateRelationship_Main.ejs +315 -171
- package/src/emit/relationship/templates/DeleteRelationshipComplete_Main.ejs +67 -41
- package/src/emit/relationship/templates/DeleteRelationship_Main.ejs +226 -115
- package/src/emit/relationship/templates/FlowHandler_HdrApi.ejs +41 -33
- package/src/emit/relationship/templates/FlowHandler_HdrDsq.ejs +15 -11
- package/src/emit/relationship/templates/FlowHandler_HdrInv.ejs +28 -26
- package/src/emit/relationship/templates/FlowHandler_HdrSqs.ejs +15 -11
- package/src/emit/relationship/templates/GetRelationshipComplete_Main.ejs +46 -26
- package/src/emit/relationship/templates/GetRelationship_Main.ejs +233 -126
- package/src/emit/relationship/templates/MoveRelationshipComplete_Main.ejs +72 -44
- package/src/emit/relationship/templates/MoveRelationship_Main.ejs +266 -150
- package/src/emit/relationship/templates/UpdateRelationshipComplete_Main.ejs +74 -45
- package/src/emit/relationship/templates/UpdateRelationship_Main.ejs +285 -152
- package/src/emit/resource/emitResourceArtifacts.js +274 -105
- package/src/emit/resource/generateResourceArtifacts.js +15 -6
- package/src/emit/resource/templates/GeneratedLambdaRoleServiceConfig.ejs +139 -0
- package/src/emit/resource/templates/S3Bucket_Yaml.ejs +19 -0
- package/src/emit/resource/templates/S3Subscription_Yaml.ejs +7 -0
- package/src/emit/resource/templates/WebSocketSubscription_Yaml.ejs +7 -0
- package/src/emit/system/emitSystemWebSocketArtifacts.js +61 -165
- package/src/emit/system/templates/WebSocketComplete_HdrSqs.ejs +32 -0
- package/src/emit/system/templates/WebSocketComplete_Main.ejs +46 -0
- package/src/emit/system/templates/WebSocketComplete_Yaml.ejs +19 -0
- package/src/emit/system/templates/WebSocketConnect.ejs +25 -0
- package/src/emit/system/templates/WebSocketConnect_Yaml.ejs +11 -0
- package/src/generate.js +141 -34
- package/src/generateIntTest.js +76 -28
- package/src/generateResourceIntTest.js +35 -12
- package/src/generateResources/IntTest/generateResources/generateResources.js +5 -2
- package/src/generateResources/IntTest/generateResources/templateResources.ejs +18 -30
- package/src/generateResources/IntTest/generateTests/events/events.js +1 -1
- package/src/generateResources/IntTest/generateTests/events/templateEvents.ejs +13 -10
- package/src/generateResources/IntTest/generateTests/generateTemplate.js +2 -2
- package/src/generateResources/IntTest/generateTests/pathIntTest/pathIntTest.js +2 -1
- package/src/generateResources/IntTest/generateTests/pathIntTest/template.ejs +1 -3
- package/src/generateResources/IntTest/generateTests/tests/templateTests.ejs +1 -1
- package/src/generateResources/IntTest/generateTests/tests/tests.js +7 -3
- package/src/generateResources/IntTest/libs/{libs.js → IntTestGenerateLib.js} +34 -23
- package/src/generateResources/IntTest/upload/uploadIntTest.js +33 -19
- package/src/intTestGeneratorShared.js +15 -10
- package/src/output/commitArtifacts.js +99 -39
- package/src/output/mergeHooks.js +24 -10
- package/src/output/validateArtifacts.js +37 -27
- package/src/plan/buildGenerationPlan.js +24 -13
- package/test/core.test.js +116 -49
- package/test/createTargetRoleHandler.test.js +63 -14
- package/test/crudApplicationArtifacts.test.js +128 -23
- package/test/customFlowApplicationArtifacts.test.js +391 -84
- package/test/dynamicCrudFlowSchemas.test.js +74 -26
- package/test/dynamicRbacFlowSchemas.test.js +63 -20
- package/test/dynamicRelationshipFlowSchemas.test.js +65 -18
- package/test/functionYamlArtifact.test.js +67 -10
- package/test/intTestApi.test.js +9 -10
- package/test/publicApi.test.js +184 -44
- package/test/relationshipApplicationArtifacts.test.js +90 -19
- package/test/resourceArtifacts.test.js +183 -33
- package/docs/test.png +0 -0
- package/src/emit/rbac/templates/UserRbacFlow_HdrInv.ejs +0 -10
- package/src/emit/relationship/dynamicRelationshipFlowSchemaTemplate.js +0 -11
- /package/docs/{test.mmd → TriggeredCacheFlow.mmd} +0 -0
|
@@ -15,38 +15,40 @@ 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
|
-
|
|
19
|
-
|
|
18
|
+
import {
|
|
19
|
+
objectHash as hash,
|
|
20
|
+
identifierUuid
|
|
21
|
+
} from '@izara_project/izara-shared-core';
|
|
20
22
|
|
|
21
23
|
import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
|
|
22
|
-
import lambdaSharedLib from
|
|
23
|
-
import snsSharedLib from
|
|
24
|
-
import asyncFlowSharedLib from
|
|
25
|
-
import dynamodbSharedLib from
|
|
26
|
-
|
|
27
|
-
import {
|
|
28
|
-
|
|
29
|
-
|
|
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';
|
|
27
|
+
import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
|
|
28
|
+
|
|
29
|
+
import {
|
|
30
|
+
sns,
|
|
31
|
+
lambda
|
|
32
|
+
} from '@izara_project/izara-core-library-external-request';
|
|
33
|
+
|
|
34
|
+
import {
|
|
35
|
+
getObjectSchema,
|
|
36
|
+
utils,
|
|
37
|
+
serviceConfig,
|
|
38
|
+
consts,
|
|
39
|
+
relSchemaLib,
|
|
40
|
+
identifiersObject
|
|
41
|
+
} from '@izara_project/izara-core-library-service-schemas';
|
|
30
42
|
const { findLinksByObjTypes } = relSchemaLib;
|
|
31
43
|
|
|
32
|
-
const {
|
|
33
|
-
|
|
34
|
-
getObjSchemaS3WithHierarchy
|
|
35
|
-
} = getObjectSchema
|
|
44
|
+
const { getRelationshipSchemaWithCache, getObjSchemaS3WithHierarchy } =
|
|
45
|
+
getObjectSchema;
|
|
36
46
|
|
|
37
|
-
const {
|
|
38
|
-
createLinkTypeId
|
|
39
|
-
} = utils;
|
|
47
|
+
const { createLinkTypeId } = utils;
|
|
40
48
|
|
|
41
|
-
const {
|
|
42
|
-
getGraphServiceTagWithCache
|
|
43
|
-
} = serviceConfig;
|
|
49
|
+
const { getGraphServiceTagWithCache } = serviceConfig;
|
|
44
50
|
|
|
45
|
-
const {
|
|
46
|
-
PREFIX,
|
|
47
|
-
TOPIC_NAME_GENERATE_CODE,
|
|
48
|
-
TOPIC_NAME_GRAPH_HANDLER
|
|
49
|
-
} = consts;
|
|
51
|
+
const { PREFIX, TOPIC_NAME_GENERATE_CODE, TOPIC_NAME_GRAPH_HANDLER } = consts;
|
|
50
52
|
|
|
51
53
|
import { consts as coreConsts } from '@izara_project/izara-core-library-core';
|
|
52
54
|
|
|
@@ -67,14 +69,17 @@ import { consts as coreConsts } from '@izara_project/izara-core-library-core';
|
|
|
67
69
|
export default async function moveRelationship(
|
|
68
70
|
_izContext,
|
|
69
71
|
requestParams,
|
|
70
|
-
callingFlowConfig = {}
|
|
72
|
+
callingFlowConfig = {}
|
|
71
73
|
//(<additionalParams>)
|
|
72
74
|
//(</additionalParams>)
|
|
73
75
|
) {
|
|
74
76
|
try {
|
|
75
77
|
_izContext.logger.debug('moveRelationship _izContext: ', _izContext);
|
|
76
78
|
_izContext.logger.debug('moveRelationship requestParams: ', requestParams);
|
|
77
|
-
_izContext.logger.debug(
|
|
79
|
+
_izContext.logger.debug(
|
|
80
|
+
'moveRelationship callingFlowConfig: ',
|
|
81
|
+
callingFlowConfig
|
|
82
|
+
);
|
|
78
83
|
|
|
79
84
|
const {
|
|
80
85
|
firstObject,
|
|
@@ -93,43 +98,71 @@ export default async function moveRelationship(
|
|
|
93
98
|
//(<beforeValidateMoveRel>)
|
|
94
99
|
//(</beforeValidateMoveRel>).
|
|
95
100
|
// validate object and identifiers
|
|
96
|
-
async function validateIdentifiersExists(
|
|
97
|
-
|
|
101
|
+
async function validateIdentifiersExists(
|
|
102
|
+
_izContext,
|
|
103
|
+
objType,
|
|
104
|
+
identifiersObject
|
|
105
|
+
) {
|
|
98
106
|
const objTypeString = `objType:{ serviceTag:${objType.serviceTag}, objectType:${objType.objectType} }`;
|
|
99
|
-
const objectSchema = await getObjSchemaS3WithHierarchy(
|
|
107
|
+
const objectSchema = await getObjSchemaS3WithHierarchy(
|
|
108
|
+
_izContext,
|
|
109
|
+
objType
|
|
110
|
+
);
|
|
100
111
|
|
|
101
112
|
if (!objectSchema) {
|
|
102
|
-
errorsFound.push(
|
|
113
|
+
errorsFound.push(
|
|
114
|
+
`validateIdentifiers, not found schema of ${objTypeString}`
|
|
115
|
+
);
|
|
103
116
|
}
|
|
104
117
|
|
|
105
118
|
for (const schemaIdentifier of objectSchema.identifiers) {
|
|
106
|
-
let identifierNames = schemaIdentifier.fieldNames || [
|
|
119
|
+
let identifierNames = schemaIdentifier.fieldNames || [
|
|
120
|
+
schemaIdentifier.fieldName
|
|
121
|
+
];
|
|
107
122
|
for (const identifierName of identifierNames) {
|
|
108
123
|
if (!identifiersObject.hasOwnProperty(identifierName)) {
|
|
109
|
-
errorsFound.push(
|
|
124
|
+
errorsFound.push(
|
|
125
|
+
`validateIdentifiers, ${objTypeString} property:${identifierName} not exists`
|
|
126
|
+
);
|
|
110
127
|
} else {
|
|
111
128
|
if (
|
|
112
|
-
typeof
|
|
113
|
-
typeof
|
|
129
|
+
typeof identifiersObject[identifierName] !== 'string' &&
|
|
130
|
+
typeof identifiersObject[identifierName] !== 'number'
|
|
114
131
|
) {
|
|
115
|
-
errorsFound.push(
|
|
132
|
+
errorsFound.push(
|
|
133
|
+
`validateIdentifiers, ${objTypeString} property:${identifierName} should be string or number`
|
|
134
|
+
);
|
|
116
135
|
}
|
|
117
136
|
}
|
|
118
137
|
}
|
|
119
138
|
}
|
|
120
139
|
}
|
|
121
140
|
|
|
122
|
-
await validateIdentifiersExists(
|
|
123
|
-
|
|
141
|
+
await validateIdentifiersExists(
|
|
142
|
+
_izContext,
|
|
143
|
+
firstObject.objType,
|
|
144
|
+
firstObject.identifiers
|
|
145
|
+
);
|
|
146
|
+
await validateIdentifiersExists(
|
|
147
|
+
_izContext,
|
|
148
|
+
secondObject.objType,
|
|
149
|
+
secondObject.identifiers
|
|
150
|
+
);
|
|
124
151
|
// finished validate object and identifiers
|
|
125
152
|
|
|
126
153
|
//(<afterValidateMoveRel>)
|
|
127
154
|
//(</afterValidateMoveRel>)
|
|
128
155
|
|
|
129
|
-
const relationshipSchema = await getRelationshipSchemaWithCache(
|
|
130
|
-
|
|
156
|
+
const relationshipSchema = await getRelationshipSchemaWithCache(
|
|
157
|
+
_izContext,
|
|
158
|
+
relType
|
|
159
|
+
);
|
|
160
|
+
_izContext.logger.debug('relationshipSchema: ', relationshipSchema);
|
|
131
161
|
|
|
132
|
-
if (
|
|
162
|
+
if (
|
|
163
|
+
!relationshipSchema.hasOwnProperty('moveBy') ||
|
|
164
|
+
relationshipSchema.moveBy === 'none'
|
|
165
|
+
) {
|
|
133
166
|
errorsFound.push(`relationship: ${relType.relationshipTag} can't move`);
|
|
134
167
|
// ? Legacy Code:
|
|
135
168
|
/*
|
|
@@ -141,116 +174,161 @@ export default async function moveRelationship(
|
|
|
141
174
|
}
|
|
142
175
|
}
|
|
143
176
|
*/
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
} else if (relationshipSchema.moveBy !==
|
|
147
|
-
errorsFound.push(
|
|
177
|
+
// ? [Fix]: The legacy logic incorrectly blocked "user" from regular execution and allowed non-user values.
|
|
178
|
+
// ? It has been corrected to require moveBy === "user" for normal execution.
|
|
179
|
+
} else if (relationshipSchema.moveBy !== 'user') {
|
|
180
|
+
errorsFound.push(
|
|
181
|
+
`relationship: ${relType.relationshipTag} moveBy is not user`
|
|
182
|
+
);
|
|
148
183
|
}
|
|
149
184
|
|
|
150
|
-
const links = await findLinksByObjTypes(
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
185
|
+
const links = await findLinksByObjTypes(
|
|
186
|
+
_izContext,
|
|
187
|
+
[firstObject.objType, secondObject.objType],
|
|
188
|
+
relationshipSchema.links
|
|
189
|
+
);
|
|
190
|
+
_izContext.logger.debug('links', links);
|
|
191
|
+
|
|
192
|
+
const firstObjectHie = await getObjectSchema.getObjSchemaS3WithHierarchy(
|
|
193
|
+
_izContext,
|
|
194
|
+
firstObject.objType
|
|
195
|
+
);
|
|
196
|
+
const secondObjectHie = await getObjectSchema.getObjSchemaS3WithHierarchy(
|
|
197
|
+
_izContext,
|
|
198
|
+
secondObject.objType
|
|
199
|
+
);
|
|
155
200
|
|
|
156
201
|
if (!links.length) {
|
|
157
|
-
errorsFound.push(
|
|
158
|
-
|
|
202
|
+
errorsFound.push(
|
|
203
|
+
`not found link between ${JSON.stringify({ firstObject: firstObject.objType })} ${JSON.stringify({ secondObject: secondObject.objType })}`
|
|
204
|
+
);
|
|
205
|
+
}
|
|
159
206
|
|
|
160
207
|
let checkCorrectLink = false;
|
|
161
208
|
for (let link of links) {
|
|
162
|
-
const { serviceTag: fromServiceTag, objectType: fromObjectType } =
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
209
|
+
const { serviceTag: fromServiceTag, objectType: fromObjectType } =
|
|
210
|
+
link.from.objType;
|
|
211
|
+
const { serviceTag: toServiceTag, objectType: toObjType } =
|
|
212
|
+
link.to.objType;
|
|
213
|
+
|
|
214
|
+
const { serviceTag: firstServiceTag, objectType: firstObjectType } =
|
|
215
|
+
firstObjectHie.extendObjType || firstObject.objType;
|
|
216
|
+
const { serviceTag: secondServiceTag, objectType: secondObjectType } =
|
|
217
|
+
secondObjectHie.extendObjType || secondObject.objType;
|
|
218
|
+
|
|
219
|
+
const matchFromTo =
|
|
220
|
+
fromServiceTag === firstServiceTag &&
|
|
221
|
+
fromObjectType === firstObjectType &&
|
|
222
|
+
toServiceTag === secondServiceTag &&
|
|
223
|
+
toObjType === secondObjectType;
|
|
224
|
+
|
|
225
|
+
const matchToFrom =
|
|
226
|
+
fromServiceTag === secondServiceTag &&
|
|
227
|
+
fromObjectType === secondObjectType &&
|
|
228
|
+
toServiceTag === firstServiceTag &&
|
|
229
|
+
toObjType === firstObjectType;
|
|
230
|
+
|
|
231
|
+
if (
|
|
232
|
+
(relationshipDirection === 'from' && matchFromTo) ||
|
|
233
|
+
(relationshipDirection === 'to' && matchToFrom)
|
|
234
|
+
) {
|
|
235
|
+
checkCorrectLink = true;
|
|
177
236
|
break;
|
|
178
237
|
}
|
|
179
|
-
}
|
|
238
|
+
}
|
|
180
239
|
|
|
181
240
|
if (checkCorrectLink == false) {
|
|
182
|
-
errorsFound.push(`Wrong Relationship Direction`)
|
|
183
|
-
}
|
|
241
|
+
errorsFound.push(`Wrong Relationship Direction`);
|
|
242
|
+
}
|
|
184
243
|
|
|
185
244
|
let targetStorageResources = [];
|
|
186
245
|
|
|
187
246
|
if (relationshipSchema) {
|
|
188
247
|
// find targetStorageResources and validate each storageResources
|
|
189
248
|
await Promise.all(
|
|
190
|
-
relationshipSchema.links.map(
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
249
|
+
relationshipSchema.links.map(
|
|
250
|
+
async ({ from, to, storageResourceTags }) => {
|
|
251
|
+
const { serviceTag: fromServiceTag, objectType: fromObjectType } =
|
|
252
|
+
from.objType;
|
|
253
|
+
const { serviceTag: toServiceTag, objectType: toObjectType } =
|
|
254
|
+
to.objType;
|
|
255
|
+
|
|
256
|
+
const { serviceTag: firstServiceTag, objectType: firstObjectType } =
|
|
257
|
+
firstObjectHie.extendObjType || firstObject.objType;
|
|
258
|
+
const {
|
|
259
|
+
serviceTag: secondServiceTag,
|
|
260
|
+
objectType: secondObjectType
|
|
261
|
+
} = secondObjectHie.extendObjType || secondObject.objType;
|
|
262
|
+
|
|
263
|
+
// find exists link
|
|
264
|
+
if (
|
|
265
|
+
(firstServiceTag === fromServiceTag &&
|
|
266
|
+
firstObjectType === fromObjectType &&
|
|
267
|
+
secondServiceTag === toServiceTag &&
|
|
268
|
+
secondObjectType === toObjectType) ||
|
|
269
|
+
(firstServiceTag === toServiceTag &&
|
|
270
|
+
firstObjectType === toObjectType &&
|
|
271
|
+
secondServiceTag === fromServiceTag &&
|
|
272
|
+
secondObjectType === fromObjectType)
|
|
273
|
+
) {
|
|
274
|
+
// check founded storageResource of link and collect used storageResources
|
|
275
|
+
await Promise.all(
|
|
276
|
+
storageResourceTags.map(async (storageResourceTag) => {
|
|
277
|
+
const usedStorageResource =
|
|
278
|
+
relationshipSchema.storageResources[storageResourceTag];
|
|
279
|
+
|
|
280
|
+
if (
|
|
281
|
+
usedStorageResource.storageType ===
|
|
282
|
+
consts.STORAGE_TYPES.graph
|
|
283
|
+
) {
|
|
284
|
+
const graphServiceTag = await getGraphServiceTagWithCache(
|
|
285
|
+
_izContext,
|
|
286
|
+
usedStorageResource.graphServerTag
|
|
287
|
+
);
|
|
288
|
+
if (!graphServiceTag) {
|
|
289
|
+
errorsFound.push(
|
|
290
|
+
`storageResourceTag: ${storageResourceTag} invalid, not found graph serviceTag from graphServerTag: ${usedStorageResource.graphServerTag}`
|
|
291
|
+
);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
targetStorageResources.push({
|
|
295
|
+
...usedStorageResource,
|
|
296
|
+
graphServiceTag: graphServiceTag
|
|
297
|
+
});
|
|
298
|
+
} else {
|
|
299
|
+
targetStorageResources.push(usedStorageResource);
|
|
300
|
+
}
|
|
301
|
+
})
|
|
302
|
+
);
|
|
303
|
+
}
|
|
227
304
|
}
|
|
228
|
-
|
|
305
|
+
)
|
|
229
306
|
);
|
|
230
307
|
//(<afterGetRelMoveRel>)
|
|
231
308
|
//(</afterGetRelMoveRel>)
|
|
232
|
-
_izContext.logger.debug(
|
|
309
|
+
_izContext.logger.debug(
|
|
310
|
+
'targetStorageResources: ',
|
|
311
|
+
targetStorageResources
|
|
312
|
+
);
|
|
233
313
|
|
|
234
314
|
if (!targetStorageResources.length) {
|
|
235
315
|
errorsFound.push(`Not found link from relationship schema`);
|
|
236
316
|
}
|
|
237
317
|
|
|
238
|
-
|
|
239
318
|
// validate properties exists with schema
|
|
240
319
|
for (const propKey in relationshipProperties) {
|
|
241
320
|
if (!relationshipSchema.fieldNames.hasOwnProperty(propKey)) {
|
|
242
|
-
errorsFound.push(
|
|
321
|
+
errorsFound.push(
|
|
322
|
+
`property: ${propKey} not exists in relationshipSchema`
|
|
323
|
+
);
|
|
243
324
|
}
|
|
244
325
|
}
|
|
245
|
-
|
|
246
326
|
} else {
|
|
247
327
|
errorsFound.push(`relationshipSchema not exists`);
|
|
248
328
|
}
|
|
249
329
|
|
|
250
|
-
|
|
251
330
|
// if found errors will stop processing
|
|
252
331
|
if (errorsFound.length) {
|
|
253
|
-
|
|
254
332
|
let moveRelCompleteMsg = {
|
|
255
333
|
firstObject,
|
|
256
334
|
secondObject,
|
|
@@ -266,35 +344,60 @@ export default async function moveRelationship(
|
|
|
266
344
|
};
|
|
267
345
|
|
|
268
346
|
// if have callingFlow will send to message complete
|
|
269
|
-
if (
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
347
|
+
if (
|
|
348
|
+
callingFlowConfig[callingFlowSharedLib.consts.CALLINGFLOW_PROPERTYNAME]
|
|
349
|
+
) {
|
|
350
|
+
_izContext.logger.debug('HAVE CallingFlow');
|
|
351
|
+
|
|
352
|
+
moveRelCompleteMsg =
|
|
353
|
+
callingFlowSharedLib.addPassBackPropertiesToSnsResponseMessageObject(
|
|
354
|
+
callingFlowConfig,
|
|
355
|
+
moveRelCompleteMsg
|
|
356
|
+
);
|
|
357
|
+
let messageAttributes =
|
|
358
|
+
callingFlowSharedLib.addCallingFlowToSnsResponseMessageAttributes(
|
|
359
|
+
callingFlowConfig,
|
|
360
|
+
{}
|
|
361
|
+
);
|
|
274
362
|
|
|
275
363
|
let messageParams = {
|
|
276
364
|
Message: JSON.stringify(moveRelCompleteMsg),
|
|
277
|
-
MessageAttributes: sns.createStringMessageAttributes(
|
|
278
|
-
|
|
365
|
+
MessageAttributes: sns.createStringMessageAttributes(
|
|
366
|
+
_izContext,
|
|
367
|
+
messageAttributes
|
|
368
|
+
),
|
|
369
|
+
TopicArn: snsSharedLib.snsTopicArnByFlowSchema(
|
|
370
|
+
_izContext,
|
|
371
|
+
TOPIC_NAME_GENERATE_CODE.outMoveRelationshipComplete
|
|
372
|
+
)
|
|
279
373
|
};
|
|
280
374
|
|
|
281
|
-
_izContext.logger.debug(
|
|
375
|
+
_izContext.logger.debug(
|
|
376
|
+
'messageParams OutCreateRelationshipComplete ::::::: ',
|
|
377
|
+
messageParams
|
|
378
|
+
);
|
|
282
379
|
await sns.publishAsync(_izContext, messageParams);
|
|
283
380
|
}
|
|
284
381
|
|
|
285
382
|
return moveRelCompleteMsg;
|
|
286
383
|
}
|
|
287
384
|
|
|
288
|
-
|
|
289
385
|
// before create awaitingStepId per graph storageResource
|
|
290
|
-
const linkTypeId = createLinkTypeId(
|
|
386
|
+
const linkTypeId = createLinkTypeId(
|
|
387
|
+
_izContext,
|
|
388
|
+
firstObject.objType,
|
|
389
|
+
secondObject.objType,
|
|
390
|
+
relType,
|
|
391
|
+
relationshipDirection
|
|
392
|
+
);
|
|
291
393
|
|
|
292
394
|
let usedGraphServiceTag = []; // collect used graph serviceTag, use to check duplicate graph serviceTag across graph serverTag
|
|
293
395
|
let targetGraphStorageResources = []; // collect used graph storageResources, filtered duplicate graphServiceTag from graphServerTag out
|
|
294
396
|
let awaitingStepIds = [];
|
|
295
397
|
|
|
296
398
|
for (const targetStorageResource of targetStorageResources) {
|
|
297
|
-
if (
|
|
399
|
+
if (
|
|
400
|
+
targetStorageResource.storageType === consts.STORAGE_TYPES.graph &&
|
|
298
401
|
!usedGraphServiceTag.includes(targetStorageResource.graphServiceTag)
|
|
299
402
|
) {
|
|
300
403
|
usedGraphServiceTag.push(targetStorageResource.graphServiceTag);
|
|
@@ -315,7 +418,8 @@ export default async function moveRelationship(
|
|
|
315
418
|
await asyncFlowSharedLib.createAwaitingMultipleSteps(
|
|
316
419
|
_izContext,
|
|
317
420
|
awaitingStepIds, // awaitingStepIds
|
|
318
|
-
asyncFlowSharedLib.createPendingStepId(
|
|
421
|
+
asyncFlowSharedLib.createPendingStepId(
|
|
422
|
+
// pendingStepId
|
|
319
423
|
_izContext.uniqueRequestId, // hash id
|
|
320
424
|
PREFIX.changeRel // prefix, use constant further
|
|
321
425
|
)
|
|
@@ -329,43 +433,57 @@ export default async function moveRelationship(
|
|
|
329
433
|
relationshipDirection,
|
|
330
434
|
relationshipProperties,
|
|
331
435
|
moveObject,
|
|
332
|
-
parentFlowId: parentFlowId
|
|
436
|
+
parentFlowId: parentFlowId
|
|
333
437
|
//(<messageBodyMoveRel>)
|
|
334
438
|
//(</messageBodyMoveRel>)
|
|
335
439
|
|
|
336
440
|
// assign originTimestamp if not exists in relationshipProperties
|
|
337
|
-
}
|
|
441
|
+
};
|
|
338
442
|
_izContext.logger.debug('changeRelMessageBody: ', moveRelMessageBody);
|
|
339
443
|
|
|
340
444
|
await Promise.all(
|
|
341
445
|
targetGraphStorageResources.map(async (storageResource) => {
|
|
342
446
|
if (storageResource.storageType === consts.STORAGE_TYPES.graph) {
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
447
|
+
moveRelMessageBody =
|
|
448
|
+
callingFlowSharedLib.addCallingFlowToSnsRequestMessageObject(
|
|
449
|
+
moveRelMessageBody,
|
|
450
|
+
callingFlowSharedLib.addParentCallingFlowConfig(
|
|
451
|
+
callingFlowConfig, // receive parent callingFlowConfig.
|
|
452
|
+
callingFlowSharedLib.createCallingFlowConfig(
|
|
453
|
+
// calling flow own service
|
|
454
|
+
//(<callingFlowProperties>)
|
|
455
|
+
await lambdaSharedLib.lambdaFunctionName(
|
|
456
|
+
_izContext,
|
|
457
|
+
TOPIC_NAME_GENERATE_CODE.moveRelationshipComplete
|
|
458
|
+
),
|
|
459
|
+
//(</callingFlowProperties>)
|
|
460
|
+
{
|
|
461
|
+
graphServiceTag: storageResource.graphServiceTag
|
|
462
|
+
}
|
|
463
|
+
)
|
|
355
464
|
)
|
|
356
|
-
)
|
|
465
|
+
);
|
|
466
|
+
_izContext.logger.debug(
|
|
467
|
+
'messageObject before send message:',
|
|
468
|
+
moveRelMessageBody
|
|
357
469
|
);
|
|
358
|
-
_izContext.logger.debug("messageObject before send message:", moveRelMessageBody)
|
|
359
470
|
|
|
360
471
|
let messageToInChangeRelationship = {
|
|
361
472
|
Message: JSON.stringify(moveRelMessageBody),
|
|
362
|
-
TopicArn:
|
|
473
|
+
TopicArn: snsSharedLib.snsTopicArnByFlowSchema(
|
|
474
|
+
_izContext,
|
|
475
|
+
TOPIC_NAME_GRAPH_HANDLER.inMoveRelationship,
|
|
476
|
+
storageResource.graphServiceTag
|
|
477
|
+
)
|
|
363
478
|
};
|
|
364
|
-
_izContext.logger.debug(
|
|
479
|
+
_izContext.logger.debug(
|
|
480
|
+
'RequestParams before send to sqs messageToInUpdateRelationship ::::::: ',
|
|
481
|
+
messageToInChangeRelationship
|
|
482
|
+
);
|
|
365
483
|
await sns.publishAsync(_izContext, messageToInChangeRelationship);
|
|
366
484
|
}
|
|
367
485
|
})
|
|
368
|
-
)
|
|
486
|
+
);
|
|
369
487
|
}
|
|
370
488
|
|
|
371
489
|
return {
|
|
@@ -375,12 +493,10 @@ export default async function moveRelationship(
|
|
|
375
493
|
relationshipDirection,
|
|
376
494
|
relationshipProperties,
|
|
377
495
|
moveObject,
|
|
378
|
-
status:
|
|
496
|
+
status: 'complete'
|
|
379
497
|
};
|
|
380
|
-
|
|
381
|
-
|
|
382
498
|
} catch (err) {
|
|
383
|
-
_izContext.logger.error('error ChangeRelationship: ', err)
|
|
384
|
-
throw
|
|
499
|
+
_izContext.logger.error('error ChangeRelationship: ', err);
|
|
500
|
+
throw err;
|
|
385
501
|
}
|
|
386
502
|
}
|