@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,37 +15,35 @@ 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 { sns } from
|
|
28
|
-
import {
|
|
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 { sns } from '@izara_project/izara-core-library-external-request';
|
|
30
|
+
import {
|
|
31
|
+
getObjectSchema,
|
|
32
|
+
utils,
|
|
33
|
+
serviceConfig,
|
|
34
|
+
consts,
|
|
35
|
+
relSchemaLib,
|
|
36
|
+
identifiersObject
|
|
37
|
+
} from '@izara_project/izara-core-library-service-schemas';
|
|
29
38
|
const { findLinksByObjTypes } = relSchemaLib;
|
|
30
|
-
const {
|
|
31
|
-
|
|
32
|
-
getObjSchemaS3WithHierarchy
|
|
33
|
-
} = getObjectSchema
|
|
34
|
-
|
|
35
|
-
const {
|
|
36
|
-
createLinkTypeId
|
|
37
|
-
} = utils;
|
|
39
|
+
const { getRelationshipSchemaWithCache, getObjSchemaS3WithHierarchy } =
|
|
40
|
+
getObjectSchema;
|
|
38
41
|
|
|
39
|
-
const {
|
|
40
|
-
getGraphServiceTagWithCache
|
|
41
|
-
} = serviceConfig;
|
|
42
|
+
const { createLinkTypeId } = utils;
|
|
42
43
|
|
|
43
|
-
const {
|
|
44
|
-
PREFIX,
|
|
45
|
-
TOPIC_NAME_GENERATE_CODE,
|
|
46
|
-
TOPIC_NAME_GRAPH_HANDLER
|
|
47
|
-
} = consts;
|
|
44
|
+
const { getGraphServiceTagWithCache } = serviceConfig;
|
|
48
45
|
|
|
46
|
+
const { PREFIX, TOPIC_NAME_GENERATE_CODE, TOPIC_NAME_GRAPH_HANDLER } = consts;
|
|
49
47
|
|
|
50
48
|
//(<optionalRequire>)
|
|
51
49
|
//(</optionalRequire>)
|
|
@@ -63,17 +61,20 @@ const {
|
|
|
63
61
|
export default async function createRelationship(
|
|
64
62
|
_izContext,
|
|
65
63
|
requestParams,
|
|
66
|
-
callingFlowConfig = {}
|
|
64
|
+
callingFlowConfig = {}
|
|
67
65
|
//(<additionalParams>)
|
|
68
66
|
//(</additionalParams>)
|
|
69
67
|
) {
|
|
70
|
-
|
|
71
|
-
|
|
72
68
|
try {
|
|
73
69
|
_izContext.logger.debug('createRelationship _izContext: ', _izContext);
|
|
74
|
-
_izContext.logger.debug(
|
|
75
|
-
|
|
76
|
-
|
|
70
|
+
_izContext.logger.debug(
|
|
71
|
+
'createRelationship requestParams: ',
|
|
72
|
+
requestParams
|
|
73
|
+
);
|
|
74
|
+
_izContext.logger.debug(
|
|
75
|
+
'createRelationship callingFlowConfig: ',
|
|
76
|
+
callingFlowConfig
|
|
77
|
+
);
|
|
77
78
|
|
|
78
79
|
const {
|
|
79
80
|
firstObject,
|
|
@@ -94,34 +95,56 @@ export default async function createRelationship(
|
|
|
94
95
|
//(<beforeValidateCreateRel>)
|
|
95
96
|
//(</beforeValidateCreateRel>).
|
|
96
97
|
// validate object and identifiers
|
|
97
|
-
async function validateIdentifiersExists(
|
|
98
|
-
|
|
98
|
+
async function validateIdentifiersExists(
|
|
99
|
+
_izContext,
|
|
100
|
+
objType,
|
|
101
|
+
identifiersObject
|
|
102
|
+
) {
|
|
99
103
|
const objTypeString = `objType:{ serviceTag:${objType.serviceTag}, objectType:${objType.objectType} }`;
|
|
100
|
-
const objectSchema = await getObjSchemaS3WithHierarchy(
|
|
104
|
+
const objectSchema = await getObjSchemaS3WithHierarchy(
|
|
105
|
+
_izContext,
|
|
106
|
+
objType
|
|
107
|
+
);
|
|
101
108
|
|
|
102
109
|
if (!objectSchema) {
|
|
103
|
-
errorsFound.push(
|
|
110
|
+
errorsFound.push(
|
|
111
|
+
`validateIdentifiers, not found schema of ${objTypeString}`
|
|
112
|
+
);
|
|
104
113
|
}
|
|
105
114
|
|
|
106
115
|
for (const schemaIdentifier of objectSchema.identifiers) {
|
|
107
|
-
let identifierNames = schemaIdentifier.fieldNames || [
|
|
116
|
+
let identifierNames = schemaIdentifier.fieldNames || [
|
|
117
|
+
schemaIdentifier.fieldName
|
|
118
|
+
];
|
|
108
119
|
for (const identifierName of identifierNames) {
|
|
109
120
|
if (!identifiersObject.hasOwnProperty(identifierName)) {
|
|
110
|
-
errorsFound.push(
|
|
121
|
+
errorsFound.push(
|
|
122
|
+
`validateIdentifiers, ${objTypeString} property:${identifierName} not exists`
|
|
123
|
+
);
|
|
111
124
|
} else {
|
|
112
125
|
if (
|
|
113
|
-
typeof
|
|
114
|
-
typeof
|
|
126
|
+
typeof identifiersObject[identifierName] !== 'string' &&
|
|
127
|
+
typeof identifiersObject[identifierName] !== 'number'
|
|
115
128
|
) {
|
|
116
|
-
errorsFound.push(
|
|
129
|
+
errorsFound.push(
|
|
130
|
+
`validateIdentifiers, ${objTypeString} property:${identifierName} should be string or number`
|
|
131
|
+
);
|
|
117
132
|
}
|
|
118
133
|
}
|
|
119
134
|
}
|
|
120
135
|
}
|
|
121
136
|
}
|
|
122
137
|
|
|
123
|
-
await validateIdentifiersExists(
|
|
124
|
-
|
|
138
|
+
await validateIdentifiersExists(
|
|
139
|
+
_izContext,
|
|
140
|
+
firstObject.objType,
|
|
141
|
+
firstObject.identifiers
|
|
142
|
+
);
|
|
143
|
+
await validateIdentifiersExists(
|
|
144
|
+
_izContext,
|
|
145
|
+
secondObject.objType,
|
|
146
|
+
secondObject.identifiers
|
|
147
|
+
);
|
|
125
148
|
// finished validate object and identifiers
|
|
126
149
|
|
|
127
150
|
//(<afterValidateCreateRel>)
|
|
@@ -130,125 +153,177 @@ export default async function createRelationship(
|
|
|
130
153
|
//(<beforeGetRelCreateRel>)
|
|
131
154
|
//(</beforeGetRelCreateRel>)
|
|
132
155
|
|
|
133
|
-
const relationshipSchema = await getRelationshipSchemaWithCache(
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
const
|
|
140
|
-
|
|
156
|
+
const relationshipSchema = await getRelationshipSchemaWithCache(
|
|
157
|
+
_izContext,
|
|
158
|
+
relType
|
|
159
|
+
);
|
|
160
|
+
_izContext.logger.debug('relationshipSchema: ', relationshipSchema);
|
|
161
|
+
|
|
162
|
+
const firstObjectHie = await getObjectSchema.getObjSchemaS3WithHierarchy(
|
|
163
|
+
_izContext,
|
|
164
|
+
firstObject.objType
|
|
165
|
+
);
|
|
166
|
+
const secondObjectHie = await getObjectSchema.getObjSchemaS3WithHierarchy(
|
|
167
|
+
_izContext,
|
|
168
|
+
secondObject.objType
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
const links = await findLinksByObjTypes(
|
|
172
|
+
_izContext,
|
|
173
|
+
[firstObject.objType, secondObject.objType],
|
|
174
|
+
relationshipSchema.links
|
|
175
|
+
);
|
|
176
|
+
_izContext.logger.debug('links', links);
|
|
141
177
|
if (!links.length) {
|
|
142
|
-
errorsFound.push(
|
|
143
|
-
|
|
178
|
+
errorsFound.push(
|
|
179
|
+
`not found link between ${JSON.stringify({ firstObject: firstObject.objType })} ${JSON.stringify({ secondObject: secondObject.objType })}`
|
|
180
|
+
);
|
|
181
|
+
}
|
|
144
182
|
|
|
145
183
|
let checkCorrectLink = false;
|
|
146
184
|
for (let link of links) {
|
|
147
|
-
const { serviceTag: fromServiceTag, objectType: fromObjectType } =
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
185
|
+
const { serviceTag: fromServiceTag, objectType: fromObjectType } =
|
|
186
|
+
link.from.objType;
|
|
187
|
+
const { serviceTag: toServiceTag, objectType: toObjType } =
|
|
188
|
+
link.to.objType;
|
|
189
|
+
|
|
190
|
+
const { serviceTag: firstServiceTag, objectType: firstObjectType } =
|
|
191
|
+
firstObject.objType;
|
|
192
|
+
const { serviceTag: secondServiceTag, objectType: secondObjectType } =
|
|
193
|
+
secondObject.objType;
|
|
194
|
+
|
|
195
|
+
const matchFromTo =
|
|
196
|
+
fromServiceTag === firstServiceTag &&
|
|
197
|
+
fromObjectType === firstObjectType &&
|
|
198
|
+
toServiceTag === secondServiceTag &&
|
|
199
|
+
toObjType === secondObjectType;
|
|
200
|
+
|
|
201
|
+
const matchToFrom =
|
|
202
|
+
fromServiceTag === secondServiceTag &&
|
|
203
|
+
fromObjectType === secondObjectType &&
|
|
204
|
+
toServiceTag === firstServiceTag &&
|
|
205
|
+
toObjType === firstObjectType;
|
|
206
|
+
|
|
207
|
+
if (
|
|
208
|
+
(relationshipDirection === 'from' && matchFromTo) ||
|
|
209
|
+
(relationshipDirection === 'to' && matchToFrom)
|
|
210
|
+
) {
|
|
211
|
+
checkCorrectLink = true;
|
|
162
212
|
break;
|
|
163
213
|
}
|
|
164
|
-
}
|
|
214
|
+
}
|
|
165
215
|
|
|
166
216
|
if (checkCorrectLink == false) {
|
|
167
|
-
errorsFound.push(`Wrong Relationship Direction`)
|
|
168
|
-
}
|
|
217
|
+
errorsFound.push(`Wrong Relationship Direction`);
|
|
218
|
+
}
|
|
169
219
|
|
|
170
220
|
let targetStorageResources = [];
|
|
171
221
|
|
|
172
222
|
if (relationshipSchema) {
|
|
173
223
|
// find targetStorageResources and validate each storageResources
|
|
174
224
|
await Promise.all(
|
|
175
|
-
relationshipSchema.links.map(
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
225
|
+
relationshipSchema.links.map(
|
|
226
|
+
async ({ from, to, storageResourceTags }) => {
|
|
227
|
+
const { serviceTag: fromServiceTag, objectType: fromObjectType } =
|
|
228
|
+
from.objType;
|
|
229
|
+
const { serviceTag: toServiceTag, objectType: toObjectType } =
|
|
230
|
+
to.objType;
|
|
231
|
+
|
|
232
|
+
const { serviceTag: firstServiceTag, objectType: firstObjectType } =
|
|
233
|
+
firstObjectHie.extendObjType || firstObject.objType;
|
|
234
|
+
const {
|
|
235
|
+
serviceTag: secondServiceTag,
|
|
236
|
+
objectType: secondObjectType
|
|
237
|
+
} = secondObjectHie.extendObjType || secondObject.objType;
|
|
238
|
+
|
|
239
|
+
// find exists link
|
|
240
|
+
if (
|
|
241
|
+
(firstServiceTag === fromServiceTag &&
|
|
242
|
+
firstObjectType === fromObjectType &&
|
|
243
|
+
secondServiceTag === toServiceTag &&
|
|
244
|
+
secondObjectType === toObjectType) ||
|
|
245
|
+
(firstServiceTag === toServiceTag &&
|
|
246
|
+
firstObjectType === toObjectType &&
|
|
247
|
+
secondServiceTag === fromServiceTag &&
|
|
248
|
+
secondObjectType === fromObjectType)
|
|
249
|
+
) {
|
|
250
|
+
// check founded storageResource of link and collect used storageResources
|
|
251
|
+
await Promise.all(
|
|
252
|
+
storageResourceTags.map(async (storageResourceTag) => {
|
|
253
|
+
const usedStorageResource =
|
|
254
|
+
relationshipSchema.storageResources[storageResourceTag];
|
|
255
|
+
|
|
256
|
+
if (
|
|
257
|
+
usedStorageResource.storageType ===
|
|
258
|
+
consts.STORAGE_TYPES.graph
|
|
259
|
+
) {
|
|
260
|
+
const graphServiceTag = await getGraphServiceTagWithCache(
|
|
261
|
+
_izContext,
|
|
262
|
+
usedStorageResource.graphServerTag
|
|
263
|
+
);
|
|
264
|
+
if (!graphServiceTag) {
|
|
265
|
+
errorsFound.push(
|
|
266
|
+
`storageResourceTag: ${storageResourceTag} invalid, not found graph serviceTag from graphServerTag: ${usedStorageResource.graphServerTag}`
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
targetStorageResources.push({
|
|
271
|
+
...usedStorageResource,
|
|
272
|
+
graphServiceTag: graphServiceTag
|
|
273
|
+
});
|
|
274
|
+
} else {
|
|
275
|
+
targetStorageResources.push(usedStorageResource);
|
|
276
|
+
}
|
|
277
|
+
})
|
|
278
|
+
);
|
|
279
|
+
}
|
|
212
280
|
}
|
|
213
|
-
|
|
281
|
+
)
|
|
214
282
|
);
|
|
215
283
|
//(<afterGetRelCreateRel>)
|
|
216
284
|
//(</afterGetRelCreateRel>)
|
|
217
|
-
_izContext.logger.debug(
|
|
285
|
+
_izContext.logger.debug(
|
|
286
|
+
'targetStorageResources: ',
|
|
287
|
+
targetStorageResources
|
|
288
|
+
);
|
|
218
289
|
|
|
219
290
|
if (!targetStorageResources.length) {
|
|
220
291
|
errorsFound.push(`Not found link from relationship schema`);
|
|
221
292
|
}
|
|
222
293
|
|
|
223
|
-
|
|
224
294
|
// validate properties exists with schema
|
|
225
295
|
for (const propKey in relationshipProperties) {
|
|
226
296
|
if (!relationshipSchema.fieldNames.hasOwnProperty(propKey)) {
|
|
227
|
-
errorsFound.push(
|
|
297
|
+
errorsFound.push(
|
|
298
|
+
`property: ${propKey} not exists in relationshipSchema`
|
|
299
|
+
);
|
|
228
300
|
}
|
|
229
301
|
}
|
|
230
302
|
|
|
231
303
|
// validate canCreate properties relationship
|
|
232
|
-
for (const [propName, propSetting] of Object.entries(
|
|
304
|
+
for (const [propName, propSetting] of Object.entries(
|
|
305
|
+
relationshipSchema.fieldNames
|
|
306
|
+
)) {
|
|
233
307
|
if (propSetting.requiredOnCreate === true) {
|
|
234
308
|
if (!relationshipProperties.hasOwnProperty(propName)) {
|
|
235
309
|
errorsFound.push(`Missing requiredOnCreate property: ${propName}`);
|
|
236
310
|
}
|
|
237
311
|
}
|
|
238
312
|
|
|
239
|
-
if (
|
|
313
|
+
if (
|
|
314
|
+
!propSetting.optionalOnCreate &&
|
|
315
|
+
!propSetting.requiredOnCreate &&
|
|
316
|
+
relationshipProperties.hasOwnProperty(propName)
|
|
317
|
+
) {
|
|
240
318
|
errorsFound.push(`property: ${propName} cannot create`);
|
|
241
319
|
}
|
|
242
320
|
}
|
|
243
|
-
|
|
244
321
|
} else {
|
|
245
322
|
errorsFound.push(`relationshipSchema not exists`);
|
|
246
323
|
}
|
|
247
324
|
|
|
248
|
-
|
|
249
325
|
// if found errors will stop processing
|
|
250
326
|
if (errorsFound.length) {
|
|
251
|
-
|
|
252
327
|
let createRelCompleteMsg = {
|
|
253
328
|
firstObject: firstObject,
|
|
254
329
|
secondObject: secondObject,
|
|
@@ -263,35 +338,60 @@ export default async function createRelationship(
|
|
|
263
338
|
};
|
|
264
339
|
|
|
265
340
|
// if have callingFlow will send to message complete
|
|
266
|
-
if (
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
341
|
+
if (
|
|
342
|
+
callingFlowConfig[callingFlowSharedLib.consts.CALLINGFLOW_PROPERTYNAME]
|
|
343
|
+
) {
|
|
344
|
+
_izContext.logger.debug('HAVE CallingFlow');
|
|
345
|
+
|
|
346
|
+
createRelCompleteMsg =
|
|
347
|
+
callingFlowSharedLib.addPassBackPropertiesToSnsResponseMessageObject(
|
|
348
|
+
callingFlowConfig,
|
|
349
|
+
createRelCompleteMsg
|
|
350
|
+
);
|
|
351
|
+
let messageAttributes =
|
|
352
|
+
callingFlowSharedLib.addCallingFlowToSnsResponseMessageAttributes(
|
|
353
|
+
callingFlowConfig,
|
|
354
|
+
{}
|
|
355
|
+
);
|
|
271
356
|
|
|
272
357
|
let messageParams = {
|
|
273
358
|
Message: JSON.stringify(createRelCompleteMsg),
|
|
274
|
-
MessageAttributes: sns.createStringMessageAttributes(
|
|
275
|
-
|
|
359
|
+
MessageAttributes: sns.createStringMessageAttributes(
|
|
360
|
+
_izContext,
|
|
361
|
+
messageAttributes
|
|
362
|
+
),
|
|
363
|
+
TopicArn: snsSharedLib.snsTopicArnByFlowSchema(
|
|
364
|
+
_izContext,
|
|
365
|
+
TOPIC_NAME_GENERATE_CODE.outCreateRelComplete
|
|
366
|
+
)
|
|
276
367
|
};
|
|
277
368
|
|
|
278
|
-
_izContext.logger.debug(
|
|
369
|
+
_izContext.logger.debug(
|
|
370
|
+
'messageParams OutCreateRelationshipComplete ::::::: ',
|
|
371
|
+
messageParams
|
|
372
|
+
);
|
|
279
373
|
await sns.publishAsync(_izContext, messageParams);
|
|
280
374
|
}
|
|
281
375
|
|
|
282
376
|
return createRelCompleteMsg;
|
|
283
377
|
}
|
|
284
378
|
|
|
285
|
-
|
|
286
379
|
// before create awaitingStepId per graph storageResource
|
|
287
|
-
const linkTypeId = createLinkTypeId(
|
|
380
|
+
const linkTypeId = createLinkTypeId(
|
|
381
|
+
_izContext,
|
|
382
|
+
firstObject.objType,
|
|
383
|
+
secondObject.objType,
|
|
384
|
+
relType,
|
|
385
|
+
relationshipDirection
|
|
386
|
+
);
|
|
288
387
|
|
|
289
388
|
let usedGraphServiceTag = []; // collect used graph serviceTag, use to check duplicate graph serviceTag across graph serverTag
|
|
290
389
|
let targetGraphStorageResources = []; // collect used graph storageResources, filtered duplicate graphServiceTag from graphServerTag out
|
|
291
390
|
let awaitingStepIds = [];
|
|
292
391
|
|
|
293
392
|
for (const targetStorageResource of targetStorageResources) {
|
|
294
|
-
if (
|
|
393
|
+
if (
|
|
394
|
+
targetStorageResource.storageType === consts.STORAGE_TYPES.graph &&
|
|
295
395
|
!usedGraphServiceTag.includes(targetStorageResource.graphServiceTag)
|
|
296
396
|
) {
|
|
297
397
|
usedGraphServiceTag.push(targetStorageResource.graphServiceTag);
|
|
@@ -307,31 +407,45 @@ export default async function createRelationship(
|
|
|
307
407
|
}
|
|
308
408
|
|
|
309
409
|
// if have storageResource.storageType === "dynamoDB" will create relationship here
|
|
310
|
-
else if (
|
|
410
|
+
else if (
|
|
411
|
+
targetStorageResource.storageType === consts.STORAGE_TYPES.dynamoDB
|
|
412
|
+
) {
|
|
311
413
|
let tableNameFrom = `${firstObject.objType.serviceTag}_${firstObject.objType.objectType}__${relType.relationshipTag}__${secondObject.objType.serviceTag}_${secondObject.objType.objectType}`;
|
|
312
414
|
let tableNameTo = `${secondObject.objType.serviceTag}_${secondObject.objType.objectType}__${relType.relationshipTag}__${firstObject.objType.serviceTag}_${firstObject.objType.objectType}`;
|
|
313
415
|
|
|
314
|
-
let identifiersConcatFirstObject =
|
|
315
|
-
|
|
416
|
+
let identifiersConcatFirstObject =
|
|
417
|
+
await identifiersObject.identifiersConcatFromIdentifiers(
|
|
418
|
+
_izContext,
|
|
419
|
+
firstObject.objType,
|
|
420
|
+
firstObject.identifiers
|
|
421
|
+
);
|
|
422
|
+
let identifiersConcatSecondObject =
|
|
423
|
+
await identifiersObject.identifiersConcatFromIdentifiers(
|
|
424
|
+
_izContext,
|
|
425
|
+
secondObject.objType,
|
|
426
|
+
secondObject.identifiers
|
|
427
|
+
);
|
|
316
428
|
const firstObjectIdentifiersConcat = `${firstObject.objType.serviceTag}_${firstObject.objType.objectType}__identifiersConcat`;
|
|
317
429
|
const secondObjectIdentifiersConcat = `${secondObject.objType.serviceTag}_${secondObject.objType.objectType}__identifiersConcat`;
|
|
318
430
|
// putItem first Object DynamoDb
|
|
319
|
-
await dynamodbSharedLib.putItem(
|
|
431
|
+
await dynamodbSharedLib.putItem(
|
|
432
|
+
_izContext,
|
|
320
433
|
await dynamodbSharedLib.tableName(_izContext, tableNameFrom),
|
|
321
434
|
{
|
|
322
435
|
[firstObjectIdentifiersConcat]: identifiersConcatFirstObject,
|
|
323
436
|
[secondObjectIdentifiersConcat]: identifiersConcatSecondObject
|
|
324
437
|
}
|
|
325
|
-
)
|
|
438
|
+
);
|
|
326
439
|
|
|
327
440
|
// put Item second Object DynamoDb
|
|
328
|
-
await dynamodbSharedLib.putItem(
|
|
441
|
+
await dynamodbSharedLib.putItem(
|
|
442
|
+
_izContext,
|
|
329
443
|
await dynamodbSharedLib.tableName(_izContext, tableNameTo),
|
|
330
444
|
{
|
|
331
445
|
[secondObjectIdentifiersConcat]: identifiersConcatSecondObject,
|
|
332
446
|
[firstObjectIdentifiersConcat]: identifiersConcatFirstObject
|
|
333
447
|
}
|
|
334
|
-
)
|
|
448
|
+
);
|
|
335
449
|
}
|
|
336
450
|
}
|
|
337
451
|
|
|
@@ -340,7 +454,8 @@ export default async function createRelationship(
|
|
|
340
454
|
await asyncFlowSharedLib.createAwaitingMultipleSteps(
|
|
341
455
|
_izContext,
|
|
342
456
|
awaitingStepIds, // awaitingStepIds
|
|
343
|
-
asyncFlowSharedLib.createPendingStepId(
|
|
457
|
+
asyncFlowSharedLib.createPendingStepId(
|
|
458
|
+
// pendingStepId
|
|
344
459
|
_izContext.uniqueRequestId, // hash id
|
|
345
460
|
PREFIX.createRel // prefix, use constant further
|
|
346
461
|
)
|
|
@@ -355,46 +470,59 @@ export default async function createRelationship(
|
|
|
355
470
|
relationshipProperties,
|
|
356
471
|
deepPathConditional: deepPathConditional || [],
|
|
357
472
|
parentFlowId,
|
|
358
|
-
settings: {createOnConditionalFail: createOnConditionalFail}
|
|
473
|
+
settings: { createOnConditionalFail: createOnConditionalFail }
|
|
359
474
|
//(<inCreateRelMessageBodyCreateRel>)
|
|
360
475
|
//(</inCreateRelMessageBodyCreateRel>)
|
|
361
476
|
|
|
362
477
|
// assign originTimestamp if not exists in relationshipProperties
|
|
363
|
-
}
|
|
478
|
+
};
|
|
364
479
|
_izContext.logger.debug('createRelMessageBody: ', createRelMessageBody);
|
|
365
480
|
|
|
366
481
|
await Promise.all(
|
|
367
482
|
targetGraphStorageResources.map(async (storageResource) => {
|
|
368
483
|
if (storageResource.storageType === consts.STORAGE_TYPES.graph) {
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
484
|
+
createRelMessageBody =
|
|
485
|
+
callingFlowSharedLib.addCallingFlowToSnsRequestMessageObject(
|
|
486
|
+
createRelMessageBody,
|
|
487
|
+
callingFlowSharedLib.addParentCallingFlowConfig(
|
|
488
|
+
callingFlowConfig, // receive parent callingFlowConfig.
|
|
489
|
+
callingFlowSharedLib.createCallingFlowConfig(
|
|
490
|
+
// calling flow own service
|
|
491
|
+
//(<callingFlowProperties>)
|
|
492
|
+
await lambdaSharedLib.lambdaFunctionName(
|
|
493
|
+
_izContext,
|
|
494
|
+
TOPIC_NAME_GENERATE_CODE.createRelComplete
|
|
495
|
+
),
|
|
496
|
+
//(</callingFlowProperties>)
|
|
497
|
+
{
|
|
498
|
+
graphServiceTag: storageResource.graphServiceTag
|
|
499
|
+
}
|
|
500
|
+
)
|
|
381
501
|
)
|
|
382
|
-
)
|
|
502
|
+
);
|
|
503
|
+
_izContext.logger.debug(
|
|
504
|
+
'messageObject before send message:',
|
|
505
|
+
createRelMessageBody
|
|
383
506
|
);
|
|
384
|
-
_izContext.logger.debug("messageObject before send message:", createRelMessageBody)
|
|
385
507
|
|
|
386
508
|
let messageToInCreateRelationship = {
|
|
387
509
|
Message: JSON.stringify(createRelMessageBody),
|
|
388
|
-
TopicArn:
|
|
510
|
+
TopicArn: snsSharedLib.snsTopicArnByFlowSchema(
|
|
511
|
+
_izContext,
|
|
512
|
+
TOPIC_NAME_GRAPH_HANDLER.inCreateRel,
|
|
513
|
+
storageResource.graphServiceTag
|
|
514
|
+
)
|
|
389
515
|
};
|
|
390
|
-
_izContext.logger.debug(
|
|
516
|
+
_izContext.logger.debug(
|
|
517
|
+
'RequestParams before send to sqs messageToInUpdateRelationship ::::::: ',
|
|
518
|
+
messageToInCreateRelationship
|
|
519
|
+
);
|
|
391
520
|
await sns.publishAsync(_izContext, messageToInCreateRelationship);
|
|
392
521
|
}
|
|
393
522
|
})
|
|
394
|
-
)
|
|
395
|
-
|
|
523
|
+
);
|
|
396
524
|
} else if (!awaitingStepIds.length) {
|
|
397
|
-
_izContext.logger.debug(
|
|
525
|
+
_izContext.logger.debug('dynamoDb storageResourceTag');
|
|
398
526
|
// if relationshipSchema stored in dynamoDB only will send message to outComplete
|
|
399
527
|
let messageObject = {
|
|
400
528
|
firstObject: firstObject,
|
|
@@ -405,20 +533,38 @@ export default async function createRelationship(
|
|
|
405
533
|
parentFlowId
|
|
406
534
|
};
|
|
407
535
|
|
|
408
|
-
if (
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
536
|
+
if (
|
|
537
|
+
callingFlowConfig[callingFlowSharedLib.consts.CALLINGFLOW_PROPERTYNAME]
|
|
538
|
+
) {
|
|
539
|
+
_izContext.logger.debug('have callingFlow');
|
|
540
|
+
messageObject =
|
|
541
|
+
callingFlowSharedLib.addPassBackPropertiesToSnsResponseMessageObject(
|
|
542
|
+
callingFlowConfig,
|
|
543
|
+
messageObject
|
|
544
|
+
);
|
|
545
|
+
|
|
546
|
+
let messageAttributes =
|
|
547
|
+
callingFlowSharedLib.addCallingFlowToSnsResponseMessageAttributes(
|
|
548
|
+
callingFlowConfig,
|
|
549
|
+
{}
|
|
550
|
+
);
|
|
413
551
|
let sendMessageToOutCreateRelComplete = {
|
|
414
552
|
Message: JSON.stringify(messageObject),
|
|
415
|
-
MessageAttributes: sns.createStringMessageAttributes(
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
553
|
+
MessageAttributes: sns.createStringMessageAttributes(
|
|
554
|
+
_izContext,
|
|
555
|
+
messageAttributes
|
|
556
|
+
),
|
|
557
|
+
TopicArn: snsSharedLib.snsTopicArnByFlowSchema(
|
|
558
|
+
_izContext,
|
|
559
|
+
TOPIC_NAME_GENERATE_CODE.outCreateRelComplete
|
|
560
|
+
)
|
|
561
|
+
};
|
|
562
|
+
_izContext.logger.debug(
|
|
563
|
+
'send Message to outCreateRelationshipComplete :::',
|
|
564
|
+
sendMessageToOutCreateRelComplete
|
|
565
|
+
);
|
|
419
566
|
await sns.publishAsync(_izContext, sendMessageToOutCreateRelComplete);
|
|
420
567
|
}
|
|
421
|
-
|
|
422
568
|
}
|
|
423
569
|
|
|
424
570
|
return {
|
|
@@ -427,12 +573,10 @@ export default async function createRelationship(
|
|
|
427
573
|
relType: relType,
|
|
428
574
|
relationshipDirection,
|
|
429
575
|
relationshipProperties,
|
|
430
|
-
status:
|
|
576
|
+
status: 'complete'
|
|
431
577
|
};
|
|
432
|
-
|
|
433
|
-
|
|
434
578
|
} catch (err) {
|
|
435
|
-
_izContext.logger.error('error updateRelationship: ', err)
|
|
436
|
-
throw
|
|
579
|
+
_izContext.logger.error('error updateRelationship: ', err);
|
|
580
|
+
throw err;
|
|
437
581
|
}
|
|
438
582
|
}
|