@izara_project/izara-core-library-service-schemas 1.0.72 → 1.0.74
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +8 -7
- package/src/Consts.js +69 -41
- package/src/GetObjectSchema.js +116 -30
- package/src/IdentifiersObject.js +39 -9
- package/src/UploadObjSchema.js +20 -1
- package/src/Utils.js +98 -11
- package/src/ValidatorSchema.js +30 -10
- package/src/libs/CreateNodeLib.js +31 -13
- package/src/libs/DeliminatorTree.js +8 -8
- package/src/libs/RelSchemaLib.js +24 -9
- package/src/libs/UploadUseCase.js +9 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@izara_project/izara-core-library-service-schemas",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.74",
|
|
4
4
|
"description": "Schemas for the service and objects it controls",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -14,22 +14,23 @@
|
|
|
14
14
|
"license": "AGPL-3.0-or-later",
|
|
15
15
|
"homepage": "https://bitbucket.org/izara-core-libraries/izara-core-library-service-schemas/src/master/README.md",
|
|
16
16
|
"devDependencies": {
|
|
17
|
-
"jest": "^
|
|
17
|
+
"jest": "^30.0.3"
|
|
18
18
|
},
|
|
19
19
|
"jest": {
|
|
20
20
|
"testEnvironment": "node"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@aws-sdk/client-lambda": "^3.
|
|
24
|
-
"@aws-sdk/client-s3": "^3.
|
|
25
|
-
"@aws-sdk/crc64-nvme-crt": "^3.
|
|
23
|
+
"@aws-sdk/client-lambda": "^3.840.0",
|
|
24
|
+
"@aws-sdk/client-s3": "^3.840.0",
|
|
25
|
+
"@aws-sdk/crc64-nvme-crt": "^3.840.0",
|
|
26
|
+
"@aws-sdk/client-api-gateway": "^3.840.0",
|
|
26
27
|
"@izara_project/izara-core-library-core": "^1.0.19",
|
|
27
28
|
"@izara_project/izara-core-library-external-request": "^1.0.20",
|
|
28
29
|
"@izara_project/izara-core-library-lambda": "^1.0.4",
|
|
29
30
|
"@izara_project/izara-core-library-logger": "^1.0.7",
|
|
30
31
|
"@izara_project/izara-shared-core": "^1.0.2",
|
|
31
|
-
"@izara_project/izara-shared-service-schemas": "^1.0.
|
|
32
|
-
"glob": "^11.0.
|
|
32
|
+
"@izara_project/izara-shared-service-schemas": "^1.0.20",
|
|
33
|
+
"glob": "^11.0.3",
|
|
33
34
|
"lodash": "^4.17.21",
|
|
34
35
|
"object-hash": "^3.0.0",
|
|
35
36
|
"read-yaml-file": "^2.1.0"
|
package/src/Consts.js
CHANGED
|
@@ -106,84 +106,109 @@ const PREFIX_PATH_S3 = {
|
|
|
106
106
|
// --------- Upload path ---------------
|
|
107
107
|
|
|
108
108
|
function relationshipTagPathS3(_izContext, relType) {
|
|
109
|
-
validateRelType(relType);
|
|
109
|
+
const validateRelTypeResult = validateRelType(relType);
|
|
110
|
+
if (validateRelTypeResult.errorsFound.length > 0) {
|
|
111
|
+
throw new NoRetryError(`function relationshipTagPathS3: invalid relType ${relType.name} - ${validateRelTypeResult.errorsFound.join(", ")}`);
|
|
112
|
+
}
|
|
110
113
|
return `${PREFIX_PATH_S3.perServiceSchemas}/${relType.serviceTag}/Relationships/RelationshipTags/${relType.relationshipTag}.json`
|
|
111
114
|
}
|
|
112
115
|
|
|
113
116
|
function objectRelationshipPathS3(_izContext, objType) {
|
|
114
|
-
validateObjType(objType);
|
|
117
|
+
const validateObjTypeResult = validateObjType(objType);
|
|
118
|
+
if (validateObjTypeResult.errorsFound.length > 0) {
|
|
119
|
+
throw new NoRetryError(`function objectRelationshipPathS3: invalid objType ${objType.name} - ${validateObjTypeResult.errorsFound.join(", ")}`);
|
|
120
|
+
}
|
|
115
121
|
return `${PREFIX_PATH_S3.perServiceSchemas}/${objType.serviceTag}/Relationships/ObjectRelationships/${objType.objectType}.json`
|
|
116
122
|
}
|
|
117
123
|
|
|
118
124
|
function linkByLinkTypeIdPathS3(_izContext, serviceTag, linkTypeId) {
|
|
119
125
|
if (!serviceTag || !linkTypeId || typeof (serviceTag) !== "string" || typeof (linkTypeId) !== "string") {
|
|
120
|
-
throw new NoRetryError("invalid serviceTag or linkTypeId")
|
|
126
|
+
// throw new NoRetryError("invalid serviceTag or linkTypeId")
|
|
127
|
+
throw new NoRetryError("invalid serviceTag or linkTypeId");
|
|
121
128
|
}
|
|
122
|
-
return `${PREFIX_PATH_S3.perServiceSchemas}/${serviceTag}/Relationships/LinkByLinkTypeId/${linkTypeId}.json
|
|
129
|
+
return `${PREFIX_PATH_S3.perServiceSchemas}/${serviceTag}/Relationships/LinkByLinkTypeId/${linkTypeId}.json`;
|
|
123
130
|
}
|
|
124
131
|
|
|
125
132
|
|
|
126
133
|
function refObjectRelationshipPathS3(_izContext, objType) {
|
|
127
|
-
validateObjType(objType);
|
|
128
|
-
|
|
134
|
+
const validateObjTypeResult = validateObjType(objType);
|
|
135
|
+
if (validateObjTypeResult.errorsFound.length > 0) {
|
|
136
|
+
throw new NoRetryError(`function refObjectRelationshipPathS3: invalid objType ${objType.name} - ${validateObjTypeResult.errorsFound.join(", ")}`);
|
|
137
|
+
}
|
|
138
|
+
return `${PREFIX_PATH_S3.perServiceSchemas}/${objType.serviceTag}/Relationships/RefObjectRelationships/${objType.objectType}.json`;
|
|
129
139
|
}
|
|
130
140
|
|
|
131
141
|
function objectSchemaAllPathS3(_izContext, objType) {
|
|
132
|
-
validateObjType(objType);
|
|
133
|
-
|
|
142
|
+
const validateObjTypeResult = validateObjType(objType);
|
|
143
|
+
if (validateObjTypeResult.errorsFound.length > 0) {
|
|
144
|
+
throw new NoRetryError(`function objectSchemaAllPathS3: invalid objType ${objType.name} - ${validateObjTypeResult.errorsFound.join(", ")}`);
|
|
145
|
+
}
|
|
146
|
+
return `${PREFIX_PATH_S3.perServiceSchemas}/${objType.serviceTag}/ObjectSchemaAll/${objType.objectType}.json`;
|
|
134
147
|
}
|
|
135
148
|
|
|
136
149
|
function objectSchemaCreatePathS3(_izContext, objType) {
|
|
137
|
-
validateObjType(objType);
|
|
138
|
-
|
|
150
|
+
const validateObjTypeResult = validateObjType(objType);
|
|
151
|
+
if (validateObjTypeResult.errorsFound.length > 0) {
|
|
152
|
+
throw new NoRetryError(`function objectSchemaCreatePathS3: invalid objType ${objType.name} - ${validateObjTypeResult.errorsFound.join(", ")}`);
|
|
153
|
+
}
|
|
154
|
+
return `${PREFIX_PATH_S3.perServiceSchemas}/${objType.serviceTag}/ObjectSchemaCreate/${objType.objectType}.json`;
|
|
139
155
|
}
|
|
140
156
|
|
|
141
157
|
function objectSchemaDisplayPathS3(_izContext, objType) {
|
|
142
|
-
validateObjType(objType);
|
|
143
|
-
|
|
158
|
+
const validateObjTypeResult = validateObjType(objType);
|
|
159
|
+
if (validateObjTypeResult.errorsFound.length > 0) {
|
|
160
|
+
throw new NoRetryError(`function objectSchemaDisplayPathS3: invalid objType ${objType.name} - ${validateObjTypeResult.errorsFound.join(", ")}`);
|
|
161
|
+
}
|
|
162
|
+
return `${PREFIX_PATH_S3.perServiceSchemas}/${objType.serviceTag}/ObjectSchemaDisplay/${objType.objectType}.json`;
|
|
144
163
|
}
|
|
145
164
|
|
|
146
165
|
function objectSchemaCombineFieldNamesPathS3(_izContext, objType) {
|
|
147
|
-
validateObjType(objType);
|
|
148
|
-
|
|
166
|
+
const validateObjTypeResult = validateObjType(objType);
|
|
167
|
+
if (validateObjTypeResult.errorsFound.length > 0) {
|
|
168
|
+
throw new NoRetryError(`function objectSchemaCombineFieldNamesPathS3: invalid objType ${objType.name} - ${validateObjTypeResult.errorsFound.join(", ")}`);
|
|
169
|
+
}
|
|
170
|
+
return `${PREFIX_PATH_S3.perServiceSchemas}/${objType.serviceTag}/ObjectSchemaCombineFieldNames/${objType.objectType}.json`;
|
|
149
171
|
}
|
|
150
172
|
|
|
151
173
|
function objectListAllPathS3(_izContext, serviceTag) {
|
|
152
174
|
if (!serviceTag || typeof (serviceTag) !== "string") {
|
|
153
|
-
throw new NoRetryError("invalid serviceTag.")
|
|
175
|
+
throw new NoRetryError("invalid serviceTag.");
|
|
154
176
|
}
|
|
155
|
-
return `${PREFIX_PATH_S3.perServiceSchemas}/${serviceTag}/ObjectListAll.json
|
|
177
|
+
return `${PREFIX_PATH_S3.perServiceSchemas}/${serviceTag}/ObjectListAll.json`;
|
|
156
178
|
}
|
|
157
179
|
|
|
158
180
|
function objectListCreatePathS3(_izContext, serviceTag) {
|
|
159
181
|
if (!serviceTag || typeof (serviceTag) !== "string") {
|
|
160
|
-
throw new NoRetryError("invalid serviceTag.")
|
|
182
|
+
throw new NoRetryError("invalid serviceTag.");
|
|
161
183
|
}
|
|
162
|
-
return `${PREFIX_PATH_S3.perServiceSchemas}/${serviceTag}/ObjectListCreate.json
|
|
184
|
+
return `${PREFIX_PATH_S3.perServiceSchemas}/${serviceTag}/ObjectListCreate.json`;
|
|
163
185
|
}
|
|
164
186
|
|
|
165
187
|
function lambdaFunctionsPathS3(_izContext, serviceTag) {
|
|
166
188
|
if (!serviceTag || typeof (serviceTag) !== "string") {
|
|
167
|
-
throw new NoRetryError("invalid serviceTag.")
|
|
189
|
+
throw new NoRetryError("invalid serviceTag.");
|
|
168
190
|
}
|
|
169
|
-
return `${PREFIX_PATH_S3.perServiceSchemas}/${serviceTag}/LambdaFunctions.json
|
|
191
|
+
return `${PREFIX_PATH_S3.perServiceSchemas}/${serviceTag}/LambdaFunctions.json`;
|
|
170
192
|
}
|
|
171
193
|
|
|
172
194
|
function serviceNamePathS3(_izContext, serviceTag) {
|
|
173
195
|
if (!serviceTag || typeof (serviceTag) !== "string") {
|
|
174
|
-
throw new NoRetryError("invalid serviceTag.")
|
|
196
|
+
throw new NoRetryError("invalid serviceTag.");
|
|
175
197
|
}
|
|
176
|
-
return `${PREFIX_PATH_S3.perServiceSchemas}/${serviceTag}/ServiceName.json
|
|
198
|
+
return `${PREFIX_PATH_S3.perServiceSchemas}/${serviceTag}/ServiceName.json`;
|
|
177
199
|
}
|
|
178
200
|
|
|
179
201
|
function flowSchemaPathS3(_izContext, flowType) {
|
|
180
|
-
validateFlowType(flowType);
|
|
181
|
-
|
|
202
|
+
const validateFlowTypeResult = validateFlowType(flowType);
|
|
203
|
+
if (validateFlowTypeResult.errorsFound.length > 0) {
|
|
204
|
+
throw new NoRetryError(`function flowSchemaPathS3: invalid flowType ${flowType.name} - ${validateFlowTypeResult.errorsFound.join(", ")}`);
|
|
205
|
+
}
|
|
206
|
+
return `${PREFIX_PATH_S3.perServiceSchemas}/${flowType.serviceTag}/FlowSchema/${flowType.flowTag}.json`;
|
|
182
207
|
}
|
|
183
208
|
|
|
184
209
|
function coreFunctionNames(_izContext, prefix, stage) {
|
|
185
210
|
if (!prefix || typeof (prefix) !== "string" && !stage || typeof (stage) !== "string") {
|
|
186
|
-
throw new NoRetryError("invalid serviceTag or stage.")
|
|
211
|
+
throw new NoRetryError("invalid serviceTag or stage.");
|
|
187
212
|
}
|
|
188
213
|
const coreFunctionNames = [
|
|
189
214
|
`${prefix}${stage}InitialSetup`,
|
|
@@ -272,7 +297,22 @@ function createValidationFieldNameForEachType(type, validation) {
|
|
|
272
297
|
}[type]
|
|
273
298
|
}
|
|
274
299
|
|
|
275
|
-
|
|
300
|
+
function flowSchemaPathS3(_izContext, flowType) {
|
|
301
|
+
validateFlowType(flowType);
|
|
302
|
+
return `${PREFIX_PATH_S3.perServiceSchemas}/${flowType.serviceTag}/FlowSchema/${flowType.flowTag}.json`
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
function getEndpointPerObjectType(_izContext, objType) {
|
|
306
|
+
validateObjType(objType);
|
|
307
|
+
return `${PREFIX_PATH_S3.perServiceSchemas}/${objType.serviceTag}/FrontEnd/Endpoint/Endpoint_Get_${objType.objectType}.json`
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function getEndpointPerService(serviceTag) {
|
|
311
|
+
if (typeof serviceTag !== "string" || !serviceTag) {
|
|
312
|
+
throw new NoRetryError("invalid serviceTag.")
|
|
313
|
+
}
|
|
314
|
+
return `${PREFIX_PATH_S3.perServiceSchemas}/${serviceTag}/FrontEnd/Endpoint/Endpoint_Get.json`
|
|
315
|
+
}
|
|
276
316
|
|
|
277
317
|
const UPLOAD_PATH_S3 = {
|
|
278
318
|
relationshipTag: relationshipTagPathS3,
|
|
@@ -294,19 +334,9 @@ const UPLOAD_PATH_S3 = {
|
|
|
294
334
|
|
|
295
335
|
lambdaFunctions: lambdaFunctionsPathS3,
|
|
296
336
|
serviceName: serviceNamePathS3,
|
|
297
|
-
coreFunctionNames: coreFunctionNames
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
const FLOW_SCHEMA_HOOK_STATE = {
|
|
301
|
-
beforeCreate: "before:Create",
|
|
302
|
-
afterCreate: "after:Create",
|
|
303
|
-
beforeCheckLimit: "before:CheckLimit",
|
|
304
|
-
afterCheckLimit: "after:CheckLimit",
|
|
305
|
-
beforeCreatePreSignedUrl: "before:CreatePreSignedUrl",
|
|
306
|
-
afterCreatePreSignedUrl: "after:CreatePreSignedUrl",
|
|
307
|
-
afterUploadS3: "after:UploadS3",
|
|
308
|
-
beforeProcessCalculate: "before:ProcessCalculate",
|
|
309
|
-
afterProcessCalculate: "after:ProcessCalculate"
|
|
337
|
+
coreFunctionNames: coreFunctionNames,
|
|
338
|
+
getEndpointPerObjectType: getEndpointPerObjectType,
|
|
339
|
+
getEndpointPerService: getEndpointPerService
|
|
310
340
|
}
|
|
311
341
|
|
|
312
342
|
// --------- End Upload path ---------------
|
|
@@ -337,6 +367,4 @@ module.exports = {
|
|
|
337
367
|
|
|
338
368
|
LOCAL_FILENAME: LOCAL_FILENAME,
|
|
339
369
|
createValidationFieldNameForEachType,
|
|
340
|
-
S3_UPLOAD_TYPE,
|
|
341
|
-
FLOW_SCHEMA_HOOK_STATE
|
|
342
370
|
}
|
package/src/GetObjectSchema.js
CHANGED
|
@@ -30,7 +30,7 @@ const {
|
|
|
30
30
|
getObjSchemaWithHierarchy,
|
|
31
31
|
getObjSchemaWithoutHierarchy,
|
|
32
32
|
mergeExtendObjSchema: mergeExtendObjSchemaShared,
|
|
33
|
-
recursiveMergeExtendObjSchema: recursiveMergeExtendObjSchemaShared,
|
|
33
|
+
// recursiveMergeExtendObjSchema: recursiveMergeExtendObjSchemaShared,
|
|
34
34
|
getRefObjectRelationship: getRefObjectRelationshipShared,
|
|
35
35
|
getRelationshipSchema: getRelationshipSchemaShared,
|
|
36
36
|
getObjectRelationship: getObjectRelationshipShared,
|
|
@@ -38,7 +38,7 @@ const {
|
|
|
38
38
|
getLinkConfigByLinkTypeId: getLinkConfigByLinkTypeIdShared,
|
|
39
39
|
getObjTypeHierarchy: getObjTypeHierarchyShared
|
|
40
40
|
} = sharedServiceSchema.getObjectSchema;
|
|
41
|
-
const { validateObjType,
|
|
41
|
+
const { validateObjType, validateFlowType } = sharedServiceSchema.validateObjType;
|
|
42
42
|
const {
|
|
43
43
|
basicFieldNameSchema,
|
|
44
44
|
basicFieldNameSchemaForCombineFieldName
|
|
@@ -165,9 +165,11 @@ function getDataFromPath(
|
|
|
165
165
|
* @returns {Promise<object>} Return object schema of objectTypes
|
|
166
166
|
*/
|
|
167
167
|
async function getLocalObjectSchemas(_izContext, objectTypes, objSchemaPath = LOCAL_OBJECT_SCHEMA_PATH, getExtendObType = false) {
|
|
168
|
+
let errorsFound = [];
|
|
168
169
|
// validate objectTypes
|
|
169
170
|
if (!objectTypes) {
|
|
170
|
-
throw new NoRetryError("required objectTypes");
|
|
171
|
+
// throw new NoRetryError("required objectTypes");
|
|
172
|
+
errorsFound.push("getLocalObjectSchemas: Parameter 'objectTypes' is required but was not provided.");
|
|
171
173
|
}
|
|
172
174
|
|
|
173
175
|
if (typeof (objectTypes) === "string") {
|
|
@@ -175,11 +177,20 @@ async function getLocalObjectSchemas(_izContext, objectTypes, objSchemaPath = LO
|
|
|
175
177
|
}
|
|
176
178
|
|
|
177
179
|
if (!Array.isArray(objectTypes)) {
|
|
178
|
-
throw new NoRetryError(`Unhandled objectTypes param: ${objectTypes}`);
|
|
180
|
+
// throw new NoRetryError(`Unhandled objectTypes param: ${objectTypes}`);
|
|
181
|
+
errorsFound.push(`getLocalObjectSchemas: Parameter 'objectTypes' must be an array, received: ${typeof objectTypes}`);
|
|
179
182
|
}
|
|
180
183
|
|
|
181
184
|
if (!objectTypes.length) {
|
|
182
|
-
throw new NoRetryError(`ObjectTypes cannot empty`);
|
|
185
|
+
// throw new NoRetryError(`ObjectTypes cannot empty`);
|
|
186
|
+
errorsFound.push(`getLocalObjectSchemas: Parameter 'objectTypes' cannot be an empty array.`);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (errorsFound.length > 0) {
|
|
190
|
+
return {
|
|
191
|
+
errorsFound: errorsFound,
|
|
192
|
+
result: null
|
|
193
|
+
}
|
|
183
194
|
}
|
|
184
195
|
|
|
185
196
|
|
|
@@ -209,13 +220,17 @@ async function getLocalObjectSchemas(_izContext, objectTypes, objSchemaPath = LO
|
|
|
209
220
|
if (getExtendObType) {
|
|
210
221
|
await Promise.all(
|
|
211
222
|
allObjectSchemas.map(async (objSchema, idx) => {
|
|
212
|
-
|
|
223
|
+
const mergeResult = await mergeExtendObjSchema(_izContext, objSchema)
|
|
224
|
+
if (mergeResult?.errorsFound?.length && mergeResult?.errorsFound?.length > 0) {
|
|
225
|
+
throw new NoRetryError(mergeResult.errorsFound.join(","))
|
|
226
|
+
} else {
|
|
227
|
+
allObjectSchemas[idx] = mergeResult;
|
|
228
|
+
}
|
|
213
229
|
})
|
|
214
230
|
)
|
|
215
231
|
}
|
|
216
232
|
|
|
217
233
|
|
|
218
|
-
|
|
219
234
|
// add objectSchema to returnValue object
|
|
220
235
|
for (let [idx, objSchema] of allObjectSchemas.entries()) {
|
|
221
236
|
if (!returnValue.fieldLookup.hasOwnProperty(objSchema.objectType)) {
|
|
@@ -233,7 +248,8 @@ async function getLocalObjectSchemas(_izContext, objectTypes, objSchemaPath = LO
|
|
|
233
248
|
}
|
|
234
249
|
returnValue.records = allObjectSchemas;
|
|
235
250
|
|
|
236
|
-
return returnValue
|
|
251
|
+
return returnValue
|
|
252
|
+
|
|
237
253
|
}
|
|
238
254
|
|
|
239
255
|
|
|
@@ -281,7 +297,6 @@ async function getAllLocalObjectSchemas(_izContext, objSchemaPath = LOCAL_OBJECT
|
|
|
281
297
|
// .filter(schema => objectTypeList.includes(schema.objectType))
|
|
282
298
|
);
|
|
283
299
|
|
|
284
|
-
|
|
285
300
|
// check objectType that not found in ObjectFieldSchema.js
|
|
286
301
|
// const remainingObjectTypes = objectTypeList.filter(objectType => !allObjectSchemas.some(schema => schema.objectType === objectType));
|
|
287
302
|
|
|
@@ -296,7 +311,9 @@ async function getAllLocalObjectSchemas(_izContext, objSchemaPath = LOCAL_OBJECT
|
|
|
296
311
|
if (getExtendObType) {
|
|
297
312
|
await Promise.all(
|
|
298
313
|
allObjectSchemas.map(async (objSchema, idx) => {
|
|
299
|
-
|
|
314
|
+
const mergeResult = await mergeExtendObjSchema(_izContext, objSchema)
|
|
315
|
+
|
|
316
|
+
allObjectSchemas[idx] = mergeResult;
|
|
300
317
|
})
|
|
301
318
|
)
|
|
302
319
|
}
|
|
@@ -305,7 +322,11 @@ async function getAllLocalObjectSchemas(_izContext, objSchemaPath = LOCAL_OBJECT
|
|
|
305
322
|
if (!returnValue.fieldLookup.hasOwnProperty(objSchema.objectType)) {
|
|
306
323
|
returnValue.fieldLookup[objSchema.objectType] = idx;
|
|
307
324
|
} else {
|
|
308
|
-
throw new NoRetryError(`Found duplicate objectType: '${objSchema.objectType}' in file ObjectFieldSchema.js`);
|
|
325
|
+
// throw new NoRetryError(`Found duplicate objectType: '${objSchema.objectType}' in file ObjectFieldSchema.js`);
|
|
326
|
+
return {
|
|
327
|
+
errorsFound: [`getAllLocalObjectSchemas: Found duplicate objectType: '${objSchema.objectType}' in file ObjectFieldSchema.js`],
|
|
328
|
+
result: null
|
|
329
|
+
};
|
|
309
330
|
}
|
|
310
331
|
if (objSchema?.shortNameObjectType) {
|
|
311
332
|
if (!returnValue.shortNameObjectTypeLookup.hasOwnProperty(objSchema.shortNameObjectType)) {
|
|
@@ -319,8 +340,7 @@ async function getAllLocalObjectSchemas(_izContext, objSchemaPath = LOCAL_OBJECT
|
|
|
319
340
|
|
|
320
341
|
returnValue.records = allObjectSchemas;
|
|
321
342
|
|
|
322
|
-
return returnValue
|
|
323
|
-
|
|
343
|
+
return returnValue
|
|
324
344
|
}
|
|
325
345
|
|
|
326
346
|
/**
|
|
@@ -449,7 +469,13 @@ async function getObjSchemaS3(
|
|
|
449
469
|
objType,
|
|
450
470
|
getExtendObType = false
|
|
451
471
|
) {
|
|
452
|
-
return await getObjectSchemaS3Shared(getSchemaByNameWithCache, objType, getExtendObType)
|
|
472
|
+
return await getObjectSchemaS3Shared(getSchemaByNameWithCache, objType, getExtendObType).then(res => {
|
|
473
|
+
if (res.errorsFound.length && res.errorsFound.length > 0) {
|
|
474
|
+
throw new NoRetryError(res.errorsFound.join(","))
|
|
475
|
+
} else {
|
|
476
|
+
return res.result
|
|
477
|
+
}
|
|
478
|
+
});
|
|
453
479
|
}
|
|
454
480
|
|
|
455
481
|
|
|
@@ -477,7 +503,13 @@ const getObjSchemaS3WithCache = inMemoryCacheLib(
|
|
|
477
503
|
*/
|
|
478
504
|
async function getObjSchemaS3WithHierarchy(_izContext, objType) {
|
|
479
505
|
// return await getObjSchemaS3WithCache(_izContext, objType, true)
|
|
480
|
-
return await getObjSchemaWithHierarchy(getSchemaByNameWithCache, objType)
|
|
506
|
+
return await getObjSchemaWithHierarchy(getSchemaByNameWithCache, objType).then(res => {
|
|
507
|
+
if (res.errorsFound.length && res.errorsFound.length > 0) {
|
|
508
|
+
throw new NoRetryError(res.errorsFound.join(","))
|
|
509
|
+
} else {
|
|
510
|
+
return res.result
|
|
511
|
+
}
|
|
512
|
+
});
|
|
481
513
|
}
|
|
482
514
|
|
|
483
515
|
/**
|
|
@@ -488,7 +520,13 @@ async function getObjSchemaS3WithHierarchy(_izContext, objType) {
|
|
|
488
520
|
*/
|
|
489
521
|
async function getObjSchemaS3WithoutHierarchy(_izContext, objType) {
|
|
490
522
|
// return await getObjSchemaS3WithCache(_izContext, objType, false)
|
|
491
|
-
return await getObjSchemaWithoutHierarchy(getSchemaByNameWithCache, objType)
|
|
523
|
+
return await getObjSchemaWithoutHierarchy(getSchemaByNameWithCache, objType).then(res => {
|
|
524
|
+
if (res.errorsFound.length && res.errorsFound.length > 0) {
|
|
525
|
+
throw new NoRetryError(res.errorsFound.join(","))
|
|
526
|
+
} else {
|
|
527
|
+
return res.result
|
|
528
|
+
}
|
|
529
|
+
});
|
|
492
530
|
}
|
|
493
531
|
|
|
494
532
|
|
|
@@ -504,7 +542,11 @@ async function getObjSchemaS3WithoutHierarchy(_izContext, objType) {
|
|
|
504
542
|
async function getObjectSchemaCombineFieldNames(_izContext, objType) {
|
|
505
543
|
|
|
506
544
|
const objSchema = await getObjSchemaS3WithHierarchy(_izContext, objType);
|
|
507
|
-
|
|
545
|
+
if (objSchema.errorsFound.length > 0) {
|
|
546
|
+
throw new NoRetryError(`getObjectSchemaCombineFieldNames: ${objSchema.errorsFound.join(', ')}`);
|
|
547
|
+
}
|
|
548
|
+
const combinedSchema = generateObjectSchemaForCombineFieldNames(_izContext, objSchema.result);
|
|
549
|
+
return combinedSchema
|
|
508
550
|
}
|
|
509
551
|
|
|
510
552
|
/**
|
|
@@ -598,7 +640,13 @@ function getLocalRelationshipSchemas(_izContext, relationshipTags, objSchemaPath
|
|
|
598
640
|
* @returns {Promise<Object>} - reference relationship schema of objType
|
|
599
641
|
*/
|
|
600
642
|
async function getRefObjectRelationship(_izContext, objType) {
|
|
601
|
-
return await getRefObjectRelationshipShared(getSchemaByNameWithCache, objType)
|
|
643
|
+
return await getRefObjectRelationshipShared(getSchemaByNameWithCache, objType).then(res => {
|
|
644
|
+
if (res.errorsFound.length && res.errorsFound.length > 0) {
|
|
645
|
+
throw new NoRetryError(res.errorsFound.join(","))
|
|
646
|
+
} else {
|
|
647
|
+
return res.result
|
|
648
|
+
}
|
|
649
|
+
})
|
|
602
650
|
}
|
|
603
651
|
|
|
604
652
|
/**
|
|
@@ -627,8 +675,13 @@ const getRefObjectRelationshipWithCache = inMemoryCacheLib(
|
|
|
627
675
|
*
|
|
628
676
|
*/
|
|
629
677
|
async function getRelationshipSchema(_izContext, relType) {
|
|
630
|
-
|
|
631
|
-
|
|
678
|
+
return await getRelationshipSchemaShared(getSchemaByNameWithCache, relType).then(res => {
|
|
679
|
+
if (res.errorsFound.length && res.errorsFound.length > 0) {
|
|
680
|
+
throw new NoRetryError(res.errorsFound.join(","))
|
|
681
|
+
} else {
|
|
682
|
+
return res.result
|
|
683
|
+
}
|
|
684
|
+
})
|
|
632
685
|
}
|
|
633
686
|
|
|
634
687
|
|
|
@@ -665,7 +718,11 @@ async function getRelationshipServiceTag(_izContext, relationshipTag, objType) {
|
|
|
665
718
|
objType,
|
|
666
719
|
});
|
|
667
720
|
|
|
668
|
-
validateObjType(objType);
|
|
721
|
+
const validateObjTypeResult = validateObjType(objType);
|
|
722
|
+
if (validateObjTypeResult.errorsFound.length > 0) {
|
|
723
|
+
_izContext.logger.error("getRelationshipServiceTag: Invalid objType: ", validateObjTypeResult.errorsFound);
|
|
724
|
+
throw new NoRetryError(`getRelationshipServiceTag: Invalid objType: ${JSON.stringify(objType)}, ${validateObjTypeResult.errorsFound.join(", ")}`);
|
|
725
|
+
}
|
|
669
726
|
|
|
670
727
|
const relTagPath = UPLOAD_PATH_S3.relationshipTag(
|
|
671
728
|
_izContext,
|
|
@@ -683,8 +740,9 @@ async function getRelationshipServiceTag(_izContext, relationshipTag, objType) {
|
|
|
683
740
|
if (relSchemaHeadData) {
|
|
684
741
|
return objType.serviceTag;
|
|
685
742
|
} else {
|
|
686
|
-
const refObjRel = await getRefObjectRelationship(_izContext, objType);
|
|
687
|
-
|
|
743
|
+
// const refObjRel = await getRefObjectRelationship(_izContext, objType);
|
|
744
|
+
const getRefObjRelWithCacheResult = await getRefObjectRelationshipWithCache(_izContext, objType);
|
|
745
|
+
const refObjRel = getRefObjRelWithCacheResult.records;
|
|
688
746
|
if (refObjRel.hasOwnProperty(relationshipTag)) {
|
|
689
747
|
return refObjRel[relationshipTag].relationshipServiceTag
|
|
690
748
|
} else {
|
|
@@ -714,7 +772,7 @@ const getRelationshipServiceTagWithCache = inMemoryCacheLib(
|
|
|
714
772
|
|
|
715
773
|
/**
|
|
716
774
|
*
|
|
717
|
-
* get
|
|
775
|
+
* get relationshipSchema of objType depend on specific relationshipTags
|
|
718
776
|
*
|
|
719
777
|
* @param {Object} _izContext
|
|
720
778
|
* @param {Object} objType
|
|
@@ -730,7 +788,13 @@ async function getObjectRelationship(
|
|
|
730
788
|
overWriteBaseObjType,
|
|
731
789
|
) {
|
|
732
790
|
|
|
733
|
-
return await getObjectRelationshipShared(getSchemaByNameWithCache, objType, specificRelTags, overWriteBaseObjType)
|
|
791
|
+
return await getObjectRelationshipShared(getSchemaByNameWithCache, objType, specificRelTags, overWriteBaseObjType).then(res => {
|
|
792
|
+
if (res.errorsFound.length && res.errorsFound.length > 0) {
|
|
793
|
+
throw new NoRetryError(res.errorsFound.join(","))
|
|
794
|
+
} else {
|
|
795
|
+
return res.result
|
|
796
|
+
}
|
|
797
|
+
})
|
|
734
798
|
}
|
|
735
799
|
|
|
736
800
|
|
|
@@ -774,7 +838,13 @@ async function getRequiredOnCreateLinks(
|
|
|
774
838
|
specificRelTags,
|
|
775
839
|
});
|
|
776
840
|
|
|
777
|
-
return await getRequiredOnCreateLinksShared(getSchemaByNameWithCache, objType, specificRelTags)
|
|
841
|
+
return await getRequiredOnCreateLinksShared(getSchemaByNameWithCache, objType, specificRelTags).then(res => {
|
|
842
|
+
if (res.errorsFound.length && res.errorsFound.length > 0) {
|
|
843
|
+
throw new NoRetryError(res.errorsFound.join(","))
|
|
844
|
+
} else {
|
|
845
|
+
return res.result
|
|
846
|
+
}
|
|
847
|
+
})
|
|
778
848
|
}
|
|
779
849
|
|
|
780
850
|
|
|
@@ -850,7 +920,13 @@ async function getLinkConfigByLinkTypeId(_izContext, firstObjType, secondObjType
|
|
|
850
920
|
settings
|
|
851
921
|
});
|
|
852
922
|
|
|
853
|
-
|
|
923
|
+
await getLinkConfigByLinkTypeIdShared(getSchemaByNameWithCache, firstObjType, secondObjType, relType, direction, settings).then(res => {
|
|
924
|
+
if (res.errorsFound.length && res.errorsFound.length > 0) {
|
|
925
|
+
throw new NoRetryError(res.errorsFound.join(","))
|
|
926
|
+
} else {
|
|
927
|
+
return res.result
|
|
928
|
+
}
|
|
929
|
+
});
|
|
854
930
|
}
|
|
855
931
|
|
|
856
932
|
/**
|
|
@@ -881,8 +957,14 @@ const getLinkConfigByLinkTypeIdWithCache = inMemoryCacheLib(
|
|
|
881
957
|
* @returns
|
|
882
958
|
*/
|
|
883
959
|
async function mergeExtendObjSchema(_izContext, objectSchema) {
|
|
884
|
-
|
|
885
|
-
|
|
960
|
+
let mergedObjectSchema = await mergeExtendObjSchemaShared(getSchemaByNameWithCache, objectSchema).then(res => {
|
|
961
|
+
if (res.errorsFound.length && res.errorsFound.length > 0) {
|
|
962
|
+
throw new NoRetryError(`objectSchema.objectType: ${objectSchema.objectType} ${res.errorsFound}`)
|
|
963
|
+
} else {
|
|
964
|
+
return res.result
|
|
965
|
+
}
|
|
966
|
+
});
|
|
967
|
+
return mergedObjectSchema
|
|
886
968
|
}
|
|
887
969
|
|
|
888
970
|
|
|
@@ -965,7 +1047,11 @@ async function getFlowSchemaS3(
|
|
|
965
1047
|
_izContext,
|
|
966
1048
|
flowType,
|
|
967
1049
|
) {
|
|
968
|
-
validateFlowType(flowType);
|
|
1050
|
+
const validateFlowTypeResult = validateFlowType(flowType);
|
|
1051
|
+
if (validateFlowTypeResult.errorsFound.length > 0) {
|
|
1052
|
+
_izContext.logger.error("getFlowSchemaS3: Invalid flowType: ", validateFlowTypeResult.errorsFound);
|
|
1053
|
+
throw new NoRetryError(`getFlowSchemaS3: Invalid flowType: ${JSON.stringify(flowType)}, ${validateFlowTypeResult.errorsFound.join(", ")}`);
|
|
1054
|
+
}
|
|
969
1055
|
|
|
970
1056
|
const getObjSchemaParam = {
|
|
971
1057
|
Bucket: OBJECT_SCHEMA_BUCKET_NAME,
|
package/src/IdentifiersObject.js
CHANGED
|
@@ -59,7 +59,12 @@ function checkStorageTypeOfObjectSchemaIdentifiers(_izContext, objectSchema) {
|
|
|
59
59
|
* @returns {Promise<Object>} - identifiersObject
|
|
60
60
|
*/
|
|
61
61
|
async function identifiersFromObjInstanceBase(_izContext, objType, objInstanceBase) {
|
|
62
|
-
validateObjType(objType);
|
|
62
|
+
const validateObjTypeResult = validateObjType(objType);
|
|
63
|
+
if (validateObjTypeResult.errorsFound.length > 0) {
|
|
64
|
+
_izContext.logger.error("identifiersObjectFromBaseObjInstance: Invalid objType: ", validateObjTypeResult.errorsFound);
|
|
65
|
+
throw new NoRetryError(`identifiersObjectFromBaseObjInstance: Invalid objType: ${validateObjTypeResult.errorsFound.join(', ')}`);
|
|
66
|
+
}
|
|
67
|
+
|
|
63
68
|
_izContext.logger.debug("identifiersObjectFromBaseObjInstance: ", { objType, baseObjInstance: objInstanceBase });
|
|
64
69
|
|
|
65
70
|
const objSchema = await getSchema.getObjSchemaS3WithHierarchy(_izContext, objType);
|
|
@@ -140,7 +145,12 @@ async function identifiersFromObjInstanceBase(_izContext, objType, objInstanceBa
|
|
|
140
145
|
* @returns {Promise<Object>} - concatIdentifiersObject
|
|
141
146
|
*/
|
|
142
147
|
async function identifiersBaseFromIdentifiers(_izContext, objType, identifiers) {
|
|
143
|
-
validateObjType(objType);
|
|
148
|
+
const validateObjTypeResult = validateObjType(objType);
|
|
149
|
+
if (validateObjTypeResult.errorsFound.length > 0) {
|
|
150
|
+
_izContext.logger.error("identifiersBaseFromIdentifiers: Invalid objType: ", validateObjTypeResult.errorsFound);
|
|
151
|
+
throw new NoRetryError(`identifiersBaseFromIdentifiers: Invalid objType: ${JSON.stringify(objType)}, ${validateObjTypeResult.errorsFound.join(", ")}`);
|
|
152
|
+
}
|
|
153
|
+
|
|
144
154
|
_izContext.logger.debug("concatIdentifiersFromIdentifiersObject: ", { objType, identifiersObject: identifiers });
|
|
145
155
|
|
|
146
156
|
const objSchema = await getSchema.getObjSchemaS3WithHierarchy(_izContext, objType);
|
|
@@ -191,7 +201,11 @@ async function identifiersBaseFromIdentifiers(_izContext, objType, identifiers)
|
|
|
191
201
|
* @returns {Promise<Object>} - refactoredObjInstance
|
|
192
202
|
*/
|
|
193
203
|
async function objInstanceFromobjInstanceBase(_izContext, objType, objInstance) {
|
|
194
|
-
validateObjType(objType)
|
|
204
|
+
const validateObjTypeResult = validateObjType(objType);
|
|
205
|
+
if (validateObjTypeResult.errorsFound.length > 0) {
|
|
206
|
+
_izContext.logger.error("objInstanceFromobjInstanceBase: Invalid objType: ", validateObjTypeResult.errorsFound);
|
|
207
|
+
throw new NoRetryError(`objInstanceFromobjInstanceBase: Invalid objType: ${JSON.stringify(objType)}, ${validateObjTypeResult.errorsFound.join(", ")}`);
|
|
208
|
+
}
|
|
195
209
|
|
|
196
210
|
const objSchema = await getSchema.getObjSchemaS3WithHierarchy(_izContext, objType);
|
|
197
211
|
|
|
@@ -222,7 +236,12 @@ async function objInstanceFromobjInstanceBase(_izContext, objType, objInstance)
|
|
|
222
236
|
* @returns {Promise<String>} - compositeIdentifier
|
|
223
237
|
*/
|
|
224
238
|
async function identifiersConcatFromIdentifiers(_izContext, objType, identifiers) {
|
|
225
|
-
validateObjType(objType);
|
|
239
|
+
const validateObjTypeResult = validateObjType(objType);
|
|
240
|
+
if (validateObjTypeResult.errorsFound.length > 0) {
|
|
241
|
+
_izContext.logger.error("compositeIdentifierFromIdentifiersObject: Invalid objType: ", validateObjTypeResult.errorsFound);
|
|
242
|
+
throw new NoRetryError(`compositeIdentifierFromIdentifiersObject: Invalid objType: ${JSON.stringify(objType)}, ${validateObjTypeResult.errorsFound.join(", ")}`);
|
|
243
|
+
}
|
|
244
|
+
|
|
226
245
|
_izContext.logger.debug("compositeIdentifierFromIdentifiersObject: ", { objType, identifiersObject: identifiers });
|
|
227
246
|
|
|
228
247
|
const objSchema = await getSchema.getObjSchemaS3WithHierarchy(_izContext, objType);
|
|
@@ -315,7 +334,12 @@ async function identifiersConcatFromIdentifiers(_izContext, objType, identifiers
|
|
|
315
334
|
* @returns {Promise<Object>} - identifiersObject
|
|
316
335
|
*/
|
|
317
336
|
async function identifiersFromIdentifiersConcat(_izContext, objType, identifiersConcat) {
|
|
318
|
-
validateObjType(objType);
|
|
337
|
+
const validateObjTypeResult = validateObjType(objType);
|
|
338
|
+
if (validateObjTypeResult.errorsFound.length > 0) {
|
|
339
|
+
_izContext.logger.error("identifiersObjectFromCompositeIdentifier: Invalid objType: ", validateObjTypeResult.errorsFound);
|
|
340
|
+
throw new NoRetryError(`identifiersObjectFromCompositeIdentifier: Invalid objType: ${JSON.stringify(objType)}, ${validateObjTypeResult.errorsFound.join(", ")}`);
|
|
341
|
+
}
|
|
342
|
+
|
|
319
343
|
_izContext.logger.debug("identifiersObjectFromCompositeIdentifier: ", { objType, compositeIdentifier: identifiersConcat });
|
|
320
344
|
|
|
321
345
|
const objSchema = await getSchema.getObjSchemaS3WithHierarchy(_izContext, objType);
|
|
@@ -423,8 +447,11 @@ async function createNestedIdentifiersConcat(
|
|
|
423
447
|
throw new NoRetryError(`one of prefixes and suffixes should exists`);
|
|
424
448
|
}
|
|
425
449
|
|
|
426
|
-
validateObjType(objType);
|
|
427
|
-
|
|
450
|
+
const validateObjTypeResult = validateObjType(objType);
|
|
451
|
+
if (validateObjTypeResult.errorsFound.length > 0) {
|
|
452
|
+
_izContext.logger.error("createConcatIdentifier: Invalid objType: ", validateObjTypeResult.errorsFound);
|
|
453
|
+
throw new NoRetryError(`createConcatIdentifier: Invalid objType: ${JSON.stringify(objType)}, ${validateObjTypeResult.errorsFound.join(", ")}`);
|
|
454
|
+
}
|
|
428
455
|
|
|
429
456
|
const objSchema = await getSchema.getObjSchemaS3WithHierarchy(_izContext, objType);
|
|
430
457
|
_izContext.logger.debug("objSchema in createConcatIdentifier", objSchema);
|
|
@@ -458,8 +485,11 @@ async function explodedNestedIdentifiersConcat(
|
|
|
458
485
|
throw new NoRetryError(`invalid compositeIdentifier`);
|
|
459
486
|
}
|
|
460
487
|
|
|
461
|
-
validateObjType(objType);
|
|
462
|
-
|
|
488
|
+
const validateObjTypeResult = validateObjType(objType);
|
|
489
|
+
if (validateObjTypeResult.errorsFound.length > 0) {
|
|
490
|
+
_izContext.logger.error("explodedConcatIdentifier: Invalid objType: ", validateObjTypeResult.errorsFound);
|
|
491
|
+
throw new NoRetryError(`explodedConcatIdentifier: Invalid objType: ${JSON.stringify(objType)}, ${validateObjTypeResult.errorsFound.join(", ")}`);
|
|
492
|
+
}
|
|
463
493
|
|
|
464
494
|
const objSchema = await getSchema.getObjSchemaS3WithHierarchy(_izContext, objType);
|
|
465
495
|
_izContext.logger.debug("objSchema in explodedConcatIdentifier", objSchema);
|
package/src/UploadObjSchema.js
CHANGED
|
@@ -48,7 +48,8 @@ const {
|
|
|
48
48
|
validateObjectSchema,
|
|
49
49
|
validateRelationshipSchema,
|
|
50
50
|
validateRefRelationshipSchema,
|
|
51
|
-
validateBasicFlowSchema
|
|
51
|
+
validateBasicFlowSchema,
|
|
52
|
+
getApiLinks
|
|
52
53
|
} = require('./Utils')
|
|
53
54
|
|
|
54
55
|
const {
|
|
@@ -311,6 +312,7 @@ async function uploadObjectSchemaByUseCase(_izContext) {
|
|
|
311
312
|
|
|
312
313
|
// case schema combine fieldNames
|
|
313
314
|
let combineFieldNamesObjectSchema = generateObjectSchemaForCombineFieldNames(_izContext, objSchema);
|
|
315
|
+
console.log("combineFieldNamesObjectSchema", combineFieldNamesObjectSchema)
|
|
314
316
|
uploadList.push(
|
|
315
317
|
uploadObjectToS3(
|
|
316
318
|
_izContext,
|
|
@@ -325,6 +327,23 @@ async function uploadObjectSchemaByUseCase(_izContext) {
|
|
|
325
327
|
)
|
|
326
328
|
);
|
|
327
329
|
|
|
330
|
+
let apiLink = await getApiLinks();
|
|
331
|
+
console.log("apiLink", apiLink)
|
|
332
|
+
uploadList.push(
|
|
333
|
+
uploadObjectToS3(
|
|
334
|
+
_izContext,
|
|
335
|
+
UPLOAD_PATH_S3.getEndpointPerObjectType(_izContext, { objectType: objSchema.objectType, serviceTag: process.env.iz_serviceTag }),
|
|
336
|
+
apiLink
|
|
337
|
+
)
|
|
338
|
+
)
|
|
339
|
+
|
|
340
|
+
uploadList.push(
|
|
341
|
+
uploadObjectToS3(
|
|
342
|
+
_izContext,
|
|
343
|
+
UPLOAD_PATH_S3.getEndpointPerService(process.env.iz_serviceTag),
|
|
344
|
+
apiLink
|
|
345
|
+
)
|
|
346
|
+
)
|
|
328
347
|
|
|
329
348
|
// upload to refObjectRelationships for each objectType that have createBy at UserAccount Service and belongTo
|
|
330
349
|
let existsRefObjectRel = refRelationshipPerObjectType[objSchema.objectType];
|
package/src/Utils.js
CHANGED
|
@@ -42,6 +42,13 @@ const consts = require('./Consts');
|
|
|
42
42
|
// const getSchema = require('./GetObjectSchema');
|
|
43
43
|
// const deliminatorTree = require('./libs/DeliminatorTree');
|
|
44
44
|
|
|
45
|
+
const {
|
|
46
|
+
APIGatewayClient,
|
|
47
|
+
GetRestApisCommand,
|
|
48
|
+
GetResourcesCommand,
|
|
49
|
+
GetMethodCommand,
|
|
50
|
+
} = require("@aws-sdk/client-api-gateway");
|
|
51
|
+
|
|
45
52
|
function createObjType(objectType, serviceTag) {
|
|
46
53
|
if (!process.env.iz_serviceTag && !serviceTag) {
|
|
47
54
|
throw new NoRetryError('serviceNameTag not defined and iz_serviceNameTag not defined in environment variables');
|
|
@@ -451,7 +458,11 @@ function validateRefRelationshipSchema(_izContext, refRelationshipSchema, servic
|
|
|
451
458
|
* @returns
|
|
452
459
|
*/
|
|
453
460
|
function findLinkByObjType(_izContext, objType, relationshipSchema) {
|
|
454
|
-
validateObjType(objType)
|
|
461
|
+
const validateObjTypeResult = validateObjType(objType);
|
|
462
|
+
if (validateObjTypeResult.errorsFound.length > 0) {
|
|
463
|
+
_izContext.logger.error(`findLinkByObjType: invalid objType: ${JSON.stringify(objType)}`);
|
|
464
|
+
throw new NoRetryError(`findLinkByObjType: invalid objType: ${JSON.stringify(objType)}`);
|
|
465
|
+
}
|
|
455
466
|
let linkFounds = 0;
|
|
456
467
|
let linkRecords = [];
|
|
457
468
|
|
|
@@ -498,7 +509,11 @@ function findLinkByObjType(_izContext, objType, relationshipSchema) {
|
|
|
498
509
|
* @returns
|
|
499
510
|
*/
|
|
500
511
|
function findLinkByObjTypeV2(_izContext, objType, relType, relationshipSchema) {
|
|
501
|
-
validateObjType(objType)
|
|
512
|
+
const validateObjTypeResult = validateObjType(objType);
|
|
513
|
+
if (validateObjTypeResult.errorsFound.length > 0) {
|
|
514
|
+
_izContext.logger.error(`findLinkByObjTypeV2: invalid objType: ${JSON.stringify(objType)}`);
|
|
515
|
+
throw new NoRetryError(`findLinkByObjTypeV2: invalid objType: ${JSON.stringify(objType)}`);
|
|
516
|
+
}
|
|
502
517
|
|
|
503
518
|
const initialLinkData = {
|
|
504
519
|
relType: {
|
|
@@ -558,8 +573,12 @@ function findLinkByObjTypeV2(_izContext, objType, relType, relationshipSchema) {
|
|
|
558
573
|
|
|
559
574
|
|
|
560
575
|
function createObjTypeConcat(_izContext, objType) {
|
|
561
|
-
validateObjType(objType)
|
|
562
|
-
|
|
576
|
+
const validateObjTypeResult = validateObjType(objType);
|
|
577
|
+
if (validateObjTypeResult.errorsFound.length > 0) {
|
|
578
|
+
_izContext.logger.error("createObjTypeConcat validateObjTypeResult", validateObjTypeResult);
|
|
579
|
+
throw new NoRetryError(`Invalid objType:${JSON.stringify(objType)}, ${validateObjTypeResult.errorsFound.join(", ")}`);
|
|
580
|
+
}
|
|
581
|
+
return `${objType.serviceTag}_${objType.objectType}`;
|
|
563
582
|
}
|
|
564
583
|
|
|
565
584
|
function explodedObjTypeConcat(_izContext, objectTypeId) {
|
|
@@ -567,8 +586,12 @@ function explodedObjTypeConcat(_izContext, objectTypeId) {
|
|
|
567
586
|
}
|
|
568
587
|
|
|
569
588
|
function createRelTypeConcat(_izContext, relType) {
|
|
570
|
-
validateRelType(relType)
|
|
571
|
-
|
|
589
|
+
const validateRelTypeResult = validateRelType(relType);
|
|
590
|
+
if (validateRelTypeResult.errorsFound.length > 0) {
|
|
591
|
+
_izContext.logger.error("createRelTypeConcat validateRelTypeResult", validateRelTypeResult);
|
|
592
|
+
throw new NoRetryError(`Invalid relType:${JSON.stringify(relType)}, ${validateRelTypeResult.errorsFound.join(", ")}`);
|
|
593
|
+
}
|
|
594
|
+
return `${relType.serviceTag}_${relType.relationshipTag}`;
|
|
572
595
|
}
|
|
573
596
|
|
|
574
597
|
function explodedRelTypeConcat(_izContext, relationshipTypeId) {
|
|
@@ -576,8 +599,12 @@ function explodedRelTypeConcat(_izContext, relationshipTypeId) {
|
|
|
576
599
|
}
|
|
577
600
|
|
|
578
601
|
function createFlowTypeConcat(_izContext, flowType) {
|
|
579
|
-
validateFlowType(flowType);
|
|
580
|
-
|
|
602
|
+
const validateFlowTypeResult = validateFlowType(flowType);
|
|
603
|
+
if (validateFlowTypeResult.errorsFound.length > 0) {
|
|
604
|
+
_izContext.logger.error("createFlowTypeConcat validateFlowTypeResult", validateFlowTypeResult);
|
|
605
|
+
throw new NoRetryError(`Invalid flowType:${JSON.stringify(flowType)}, ${validateFlowTypeResult.errorsFound.join(", ")}`);
|
|
606
|
+
}
|
|
607
|
+
return `${flowType.serviceTag}_${flowType.flowTag}`;
|
|
581
608
|
}
|
|
582
609
|
|
|
583
610
|
function explodedFlowTypeConcat(_izContext, flowTypeId) {
|
|
@@ -586,11 +613,25 @@ function explodedFlowTypeConcat(_izContext, flowTypeId) {
|
|
|
586
613
|
|
|
587
614
|
function createLinkTypeId(_izContext, firstObjType, secondObjType, relType, direction) {
|
|
588
615
|
// validate objType
|
|
589
|
-
validateObjType(firstObjType);
|
|
590
|
-
|
|
616
|
+
let validateObjTypeResult = validateObjType(firstObjType);
|
|
617
|
+
if (validateObjTypeResult.errorsFound.length > 0) {
|
|
618
|
+
_izContext.logger.error("createLinkTypeId validateObjTypeResult", validateObjTypeResult);
|
|
619
|
+
throw new NoRetryError(`Invalid objType:${JSON.stringify(firstObjType)}, ${validateObjTypeResult.errorsFound.join(", ")}`);
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
validateObjTypeResult = validateObjType(secondObjType);
|
|
623
|
+
if (validateObjTypeResult.errorsFound.length > 0) {
|
|
624
|
+
_izContext.logger.error("createLinkTypeId validateObjTypeResult", validateObjTypeResult);
|
|
625
|
+
throw new NoRetryError(`Invalid objType:${JSON.stringify(secondObjType)}, ${validateObjTypeResult.errorsFound.join(", ")}`);
|
|
626
|
+
}
|
|
591
627
|
|
|
592
628
|
// validate relType
|
|
593
|
-
validateRelType(relType);
|
|
629
|
+
let validateRelTypeResult = validateRelType(relType);
|
|
630
|
+
|
|
631
|
+
if (validateRelTypeResult.errorsFound.length > 0) {
|
|
632
|
+
_izContext.logger.error("createLinkTypeId validateRelTypeResult", validateRelTypeResult);
|
|
633
|
+
throw new NoRetryError(`Invalid relType:${JSON.stringify(relType)}, ${validateRelTypeResult.errorsFound.join(", ")}`);
|
|
634
|
+
}
|
|
594
635
|
|
|
595
636
|
if (!direction || typeof direction !== "string" || (direction !== "from" && direction !== "to")) {
|
|
596
637
|
throw new NoRetryError('getLinkConfigByLinkTypeId invalid direction');
|
|
@@ -634,6 +675,51 @@ function switchDirection(direction) {
|
|
|
634
675
|
}
|
|
635
676
|
}
|
|
636
677
|
|
|
678
|
+
async function getApiLinks() {
|
|
679
|
+
try {
|
|
680
|
+
let apiGateway = {}
|
|
681
|
+
let position;
|
|
682
|
+
let foundApi;
|
|
683
|
+
const client = new APIGatewayClient({ region: process.env.iz_region });
|
|
684
|
+
|
|
685
|
+
do {
|
|
686
|
+
const apisRes = await client.send(new GetRestApisCommand({ position }));
|
|
687
|
+
// foundApi = apisRes.items.find(api => api.name === "Test-GCTpBas");
|
|
688
|
+
foundApi = apisRes.items.find(api => api.name === `${process.env.iz_stage}-${process.env.iz_serviceTag}`);
|
|
689
|
+
|
|
690
|
+
if (foundApi) break;
|
|
691
|
+
position = apisRes.position;
|
|
692
|
+
} while (position);
|
|
693
|
+
|
|
694
|
+
if (!foundApi) {
|
|
695
|
+
console.error("API not found");
|
|
696
|
+
return;
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
const resourcesRes = await client.send(
|
|
700
|
+
new GetResourcesCommand({ restApiId: foundApi.id })
|
|
701
|
+
);
|
|
702
|
+
|
|
703
|
+
for (const resource of resourcesRes.items) {
|
|
704
|
+
if (resource.resourceMethods) {
|
|
705
|
+
const methods = Object.keys(resource.resourceMethods);
|
|
706
|
+
for (const method of methods) {
|
|
707
|
+
const fullUrl = `https://${foundApi.id}.execute-api.${process.env.iz_region}.amazonaws.com/${process.env.iz_stage}${resource.path}`;
|
|
708
|
+
if (fullUrl.endsWith("Get") && (method === "POST")) {
|
|
709
|
+
Object.assign(apiGateway, {
|
|
710
|
+
Url: fullUrl
|
|
711
|
+
})
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
console.log("apiGateway in function getApiLink", apiGateway)
|
|
717
|
+
return apiGateway
|
|
718
|
+
} catch (err) {
|
|
719
|
+
console.error("Error fetching API info:", err);
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
|
|
637
723
|
module.exports = {
|
|
638
724
|
createObjType,
|
|
639
725
|
getIdentifierTypeByPriority,
|
|
@@ -659,4 +745,5 @@ module.exports = {
|
|
|
659
745
|
explodedFlowTypeConcat,
|
|
660
746
|
|
|
661
747
|
createLinkTypeId,
|
|
748
|
+
getApiLinks
|
|
662
749
|
}
|
package/src/ValidatorSchema.js
CHANGED
|
@@ -241,7 +241,11 @@ async function validatorSchemaTreeIdentifiersFieldNames(_izContext, objectSchema
|
|
|
241
241
|
* @param {String} objType.serviceTag
|
|
242
242
|
*/
|
|
243
243
|
async function generateRelationshipValidatorSchemaForCreate(_izContext, objType) {
|
|
244
|
-
validateObjType(objType);
|
|
244
|
+
const validateObjTypeResult = validateObjType(objType);
|
|
245
|
+
if (validateObjTypeResult.errorsFound.length > 0) {
|
|
246
|
+
_izContext.logger.error("generateRelationshipValidatorSchemaForCreate validateObjTypeResult", validateObjTypeResult);
|
|
247
|
+
throw new NoRetryError(`Invalid objType:${JSON.stringify(objType)}, ${validateObjTypeResult.errorsFound.join(", ")}`);
|
|
248
|
+
}
|
|
245
249
|
|
|
246
250
|
let relValidatorSchemas = {
|
|
247
251
|
type: "array",
|
|
@@ -374,7 +378,11 @@ async function generateRelationshipValidatorSchemaForCreate(_izContext, objType)
|
|
|
374
378
|
* @returns
|
|
375
379
|
*/
|
|
376
380
|
async function generateValidatorSchemaForCreate(_izContext, objType, specificFieldNames = []) {
|
|
377
|
-
validateObjType(objType);
|
|
381
|
+
const validateObjTypeResult = validateObjType(objType);
|
|
382
|
+
if (validateObjTypeResult.errorsFound.length > 0) {
|
|
383
|
+
_izContext.logger.error("generateValidatorSchemaForCreate validateObjTypeResult", validateObjTypeResult);
|
|
384
|
+
throw new NoRetryError(`Invalid objType:${JSON.stringify(objType)}, ${validateObjTypeResult.errorsFound.join(", ")}`);
|
|
385
|
+
}
|
|
378
386
|
_izContext.logger.debug("Function:generateValidatorSchemaForCreate ", {
|
|
379
387
|
objType,
|
|
380
388
|
specificFieldNames
|
|
@@ -616,7 +624,11 @@ async function generateValidatorSchemaForUpdate(_izContext, objType, setting = {
|
|
|
616
624
|
* @returns {object} json validator schema
|
|
617
625
|
*/
|
|
618
626
|
async function generateValidatorSchemaForIdentifier(_izContext, objType) {
|
|
619
|
-
validateObjType(objType);
|
|
627
|
+
const validateObjTypeResult = validateObjType(objType);
|
|
628
|
+
if (validateObjTypeResult.errorsFound.length > 0) {
|
|
629
|
+
_izContext.logger.error("generateValidatorSchemaForIdentifier validateObjTypeResult", validateObjTypeResult);
|
|
630
|
+
throw new NoRetryError(`Invalid objType:${JSON.stringify(objType)}, ${validateObjTypeResult.errorsFound.join(", ")}`);
|
|
631
|
+
}
|
|
620
632
|
_izContext.logger.debug("Function:generateValidatorSchemaForIdentifier ", {
|
|
621
633
|
objType,
|
|
622
634
|
})
|
|
@@ -653,7 +665,11 @@ async function generateValidatorSchemaForIdentifier(_izContext, objType) {
|
|
|
653
665
|
* @returns
|
|
654
666
|
*/
|
|
655
667
|
async function filteredFieldNamesOfValidatorSchema(_izContext, objType, requiredFieldNames, usedFieldNames) {
|
|
656
|
-
validateObjType(objType);
|
|
668
|
+
const validateObjTypeResult = validateObjType(objType);
|
|
669
|
+
if (validateObjTypeResult.errorsFound.length > 0) {
|
|
670
|
+
_izContext.logger.error("filteredFieldNamesOfValidatorSchema validateObjTypeResult", validateObjTypeResult);
|
|
671
|
+
throw new NoRetryError(`Invalid objType:${JSON.stringify(objType)}, ${validateObjTypeResult.errorsFound.join(", ")}`);
|
|
672
|
+
}
|
|
657
673
|
_izContext.logger.debug("Function filteredFieldNamesOfValidatorSchema : ", {
|
|
658
674
|
objType,
|
|
659
675
|
requiredFieldNames,
|
|
@@ -695,7 +711,12 @@ async function filteredFieldNamesOfValidatorSchema(_izContext, objType, required
|
|
|
695
711
|
* 3 >> not required, Use for validate only
|
|
696
712
|
*/
|
|
697
713
|
async function generateValidatorSchemaForExplodedData(_izContext, objType) {
|
|
698
|
-
validateObjType(objType)
|
|
714
|
+
const validateObjTypeResult = validateObjType(objType);
|
|
715
|
+
if (validateObjTypeResult.errorsFound.length > 0) {
|
|
716
|
+
_izContext.logger.error("generateValidatorSchemaForExplodedData validateObjTypeResult", validateObjTypeResult);
|
|
717
|
+
throw new NoRetryError(`Invalid objType:${JSON.stringify(objType)}, ${validateObjTypeResult.errorsFound.join(", ")}`);
|
|
718
|
+
}
|
|
719
|
+
|
|
699
720
|
let validatorSchema = {
|
|
700
721
|
type: "object",
|
|
701
722
|
required: [],
|
|
@@ -1128,15 +1149,14 @@ async function validateLocalSchema(_izContext, schemasPath, serviceConfigPath) {
|
|
|
1128
1149
|
}
|
|
1129
1150
|
})
|
|
1130
1151
|
)
|
|
1131
|
-
// validate
|
|
1152
|
+
// validate duplicate link
|
|
1132
1153
|
let relSchemaLinkType = new Set();
|
|
1133
1154
|
for (let link of relData.links) {
|
|
1134
|
-
|
|
1135
|
-
let linkTypeRelSchema = createLinkTypeId(_izContext,
|
|
1155
|
+
let linkTypeRelSchema = hash([
|
|
1136
1156
|
link.from.objType,
|
|
1137
1157
|
link.to.objType,
|
|
1138
|
-
{ relationshipTag: relTagName, serviceTag: iz_serviceTag},
|
|
1139
|
-
"from"
|
|
1158
|
+
{ relationshipTag: relTagName, serviceTag: iz_serviceTag },
|
|
1159
|
+
"from"]
|
|
1140
1160
|
)
|
|
1141
1161
|
|
|
1142
1162
|
if (!relSchemaLinkType.has(linkTypeRelSchema)) {
|
|
@@ -26,22 +26,34 @@ async function validateRequiredOnCreateLinks(_izContext, objType, relationships,
|
|
|
26
26
|
_izContext.logger.debug("validateRequiredOnCreateLinks:::", { objType, relationships, settings })
|
|
27
27
|
|
|
28
28
|
|
|
29
|
-
let objectHie = await getObjTypeHierarchy(_izContext, objType)
|
|
29
|
+
let objectHie = await getObjTypeHierarchy(_izContext, objType).then(objSchema => {
|
|
30
|
+
if (objSchema.errorsFound.length > 0) {
|
|
31
|
+
throw new NoRetryError(objSchema.errorsFound.join(","))
|
|
32
|
+
} else {
|
|
33
|
+
return objSchema.result
|
|
34
|
+
}
|
|
35
|
+
});
|
|
30
36
|
_izContext.logger.debug("objectHierarchy::", objectHie)
|
|
31
37
|
|
|
32
38
|
if (relationships.length) {
|
|
33
|
-
let targetHierarchy = await getObjTypeHierarchy(_izContext, relationships[0].targetObjType)
|
|
39
|
+
let targetHierarchy = await getObjTypeHierarchy(_izContext, relationships[0].targetObjType).then(objSchema => {
|
|
40
|
+
if (objSchema.errorsFound.length > 0) {
|
|
41
|
+
throw new NoRetryError(objSchema.errorsFound.join(","))
|
|
42
|
+
} else {
|
|
43
|
+
return objSchema.result
|
|
44
|
+
}
|
|
45
|
+
});
|
|
34
46
|
_izContext.logger.debug("targetHierarchy::", targetHierarchy)
|
|
35
47
|
}
|
|
36
48
|
|
|
37
49
|
|
|
38
|
-
let
|
|
50
|
+
let errorsFound = [];
|
|
39
51
|
|
|
40
52
|
let requiredOnCreateLinks = await getObjectSchema.getRequiredOnCreateLinksWithCache(_izContext, objType)
|
|
41
53
|
_izContext.logger.debug("requiredOnCreateLinks::", requiredOnCreateLinks)
|
|
42
54
|
|
|
43
55
|
if (!requiredOnCreateLinks.length && relationships.length > 0) {
|
|
44
|
-
|
|
56
|
+
errorsFound.push(`not have requireOnCreate will not create relationship: ${JSON.stringify(relationships)}`)
|
|
45
57
|
}
|
|
46
58
|
|
|
47
59
|
let filteredRequiredOnCreateLinks = [];
|
|
@@ -76,22 +88,28 @@ async function validateRequiredOnCreateLinks(_izContext, objType, relationships,
|
|
|
76
88
|
let relTypeConcat = createRelTypeConcat(_izContext, relationship.relType)
|
|
77
89
|
|
|
78
90
|
if (!requiredOnCreateLinkGroups[relTypeConcat]) {
|
|
79
|
-
|
|
91
|
+
errorsFound.push(`cannot create relationship ${relTypeConcat}`)
|
|
80
92
|
break;
|
|
81
93
|
}
|
|
82
94
|
|
|
83
95
|
// match requiredOnCreateLinks with relationshipDirection from requestParams
|
|
84
96
|
const usedLinkGroup = requiredOnCreateLinkGroups[relTypeConcat][relationship.relationshipDirection];
|
|
85
97
|
|
|
86
|
-
if (!usedLinkGroup
|
|
87
|
-
|
|
98
|
+
if (!usedLinkGroup?.length) {
|
|
99
|
+
errorsFound.push(`cannot create relationship ${relTypeConcat}`)
|
|
88
100
|
break;
|
|
89
101
|
}
|
|
90
102
|
|
|
91
103
|
for (let link of usedLinkGroup) {
|
|
92
104
|
// check other with targetObjType, check linkType of other should be 'one',
|
|
93
|
-
let targetObjTypeHierarchy = await getObjTypeHierarchy(_izContext, relationship.targetObjType)
|
|
94
|
-
|
|
105
|
+
let targetObjTypeHierarchy = await getObjTypeHierarchy(_izContext, relationship.targetObjType).then(objSchema => {
|
|
106
|
+
if (objSchema.errorsFound.length > 0) {
|
|
107
|
+
throw new NoRetryError(objSchema.errorsFound.join(","))
|
|
108
|
+
} else {
|
|
109
|
+
return objSchema.result
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
_izContext.logger.debug("targetObjTypeHierarchy::", targetObjTypeHierarchy)
|
|
95
113
|
|
|
96
114
|
// if (link.other.objType.objectType === relationship.targetObjType.objectType) {
|
|
97
115
|
if (targetObjTypeHierarchy.some(objType =>
|
|
@@ -101,11 +119,11 @@ async function validateRequiredOnCreateLinks(_izContext, objType, relationships,
|
|
|
101
119
|
if (!validateOnCreateRelationships.has(`${relTypeConcat}_${relationship.relationshipDirection}`)) {
|
|
102
120
|
validateOnCreateRelationships.add(`${relTypeConcat}_${relationship.relationshipDirection}`)
|
|
103
121
|
} else {
|
|
104
|
-
|
|
122
|
+
errorsFound.push(`unexpected duplicate relationship link ${JSON.stringify(relationship)}`)
|
|
105
123
|
break;
|
|
106
124
|
}
|
|
107
125
|
} else {
|
|
108
|
-
|
|
126
|
+
errorsFound.push(`invalid linkType should not be many when base: ${link} is requiredOnCreated`)
|
|
109
127
|
break;
|
|
110
128
|
}
|
|
111
129
|
}
|
|
@@ -117,11 +135,11 @@ async function validateRequiredOnCreateLinks(_izContext, objType, relationships,
|
|
|
117
135
|
|
|
118
136
|
for (const requiredOnCreateRelTypeConcat of requiredOnCreateRelTypeConcats) {
|
|
119
137
|
if (!validateOnCreateRelationships.has(requiredOnCreateRelTypeConcat)) {
|
|
120
|
-
|
|
138
|
+
errorsFound.push(`missing requiredOnCreate relationship ${requiredOnCreateRelTypeConcat}`)
|
|
121
139
|
}
|
|
122
140
|
}
|
|
123
141
|
|
|
124
|
-
return
|
|
142
|
+
return errorsFound;
|
|
125
143
|
}
|
|
126
144
|
|
|
127
145
|
function groupRequiredOnCreateLink(_izContext, relationshipSchemas) {
|
|
@@ -205,24 +205,24 @@ async function generateDeliminatorTreeIdentifier(_izContext, objectSchema) {
|
|
|
205
205
|
}));
|
|
206
206
|
|
|
207
207
|
// calculate deliminatorTree of identifier
|
|
208
|
-
let
|
|
208
|
+
let calCompositeKeyDeliminatorList = {};
|
|
209
209
|
for (let deliminatorValue of Object.values(compositeKeysDeliminatorTree)) {
|
|
210
210
|
if (deliminatorValue.deliminatorList) {
|
|
211
211
|
for (let [deliminator, deliminatorAmount] of Object.entries(deliminatorValue.deliminatorList)) {
|
|
212
|
-
if (
|
|
213
|
-
|
|
212
|
+
if (calCompositeKeyDeliminatorList.hasOwnProperty(deliminator)) {
|
|
213
|
+
calCompositeKeyDeliminatorList[deliminator] = Math.max(deliminatorAmount, calCompositeKeyDeliminatorList[deliminator]);
|
|
214
214
|
} else {
|
|
215
|
-
Object.assign(
|
|
215
|
+
Object.assign(calCompositeKeyDeliminatorList, { [deliminator]: deliminatorAmount });
|
|
216
216
|
}
|
|
217
217
|
}
|
|
218
218
|
}
|
|
219
219
|
}
|
|
220
220
|
|
|
221
221
|
|
|
222
|
-
if (
|
|
223
|
-
|
|
222
|
+
if (calCompositeKeyDeliminatorList.hasOwnProperty(identifierDeliminator)) {
|
|
223
|
+
calCompositeKeyDeliminatorList[identifierDeliminator]++;
|
|
224
224
|
} else {
|
|
225
|
-
Object.assign(
|
|
225
|
+
Object.assign(calCompositeKeyDeliminatorList, { [identifierDeliminator]: 1 });
|
|
226
226
|
}
|
|
227
227
|
|
|
228
228
|
Object.assign(
|
|
@@ -230,7 +230,7 @@ async function generateDeliminatorTreeIdentifier(_izContext, objectSchema) {
|
|
|
230
230
|
{
|
|
231
231
|
[identifierName]: {
|
|
232
232
|
deliminator: identifierDeliminator,
|
|
233
|
-
deliminatorList:
|
|
233
|
+
deliminatorList: calCompositeKeyDeliminatorList,
|
|
234
234
|
children: compositeKeysDeliminatorTree
|
|
235
235
|
}
|
|
236
236
|
}
|
package/src/libs/RelSchemaLib.js
CHANGED
|
@@ -29,28 +29,43 @@ const { getObjTypeHierarchy } = require('../GetObjectSchema')
|
|
|
29
29
|
*
|
|
30
30
|
* @param {object} _izContext
|
|
31
31
|
* @param {object[]} objTypes - 2 objType in array
|
|
32
|
-
* @param {object[]}
|
|
32
|
+
* @param {object[]} relationshipLinks - links inside relationshipSchema
|
|
33
33
|
*/
|
|
34
|
-
async function findLinksByObjTypes(_izContext, objTypes,
|
|
34
|
+
async function findLinksByObjTypes(_izContext, objTypes, relationshipLinks) {
|
|
35
35
|
|
|
36
|
-
if (!Array.isArray(
|
|
37
|
-
throw NoRetryError("
|
|
36
|
+
if (!Array.isArray(relationshipLinks)) {
|
|
37
|
+
throw new NoRetryError("relationshipLinks should be array");
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
if (!objTypes || !Array.isArray(objTypes) || objTypes.length !== 2) {
|
|
41
|
-
throw NoRetryError("function checkLinkValid: invalid objTypes");
|
|
41
|
+
throw new NoRetryError("function checkLinkValid: invalid objTypes");
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
for (const objType of objTypes) {
|
|
45
|
-
validateObjType(objType);
|
|
45
|
+
const validateObjTypeResult = validateObjType(objType);
|
|
46
|
+
if (validateObjTypeResult.errorsFound.length > 0) {
|
|
47
|
+
throw NoRetryError(`function checkLinkValid: invalid objType ${objType.name} - ${validateObjTypeResult.errorsFound.join(", ")}`);
|
|
48
|
+
}
|
|
46
49
|
}
|
|
47
50
|
|
|
48
51
|
const firstObjType = objTypes[0];
|
|
49
52
|
const secondObjType = objTypes[1];
|
|
50
53
|
|
|
51
54
|
// first create hierarchy of each objType
|
|
52
|
-
const firstObjTypeTree = await getObjTypeHierarchy(_izContext, objTypes[0])
|
|
53
|
-
|
|
55
|
+
const firstObjTypeTree = await getObjTypeHierarchy(_izContext, objTypes[0]).then(objSchema => {
|
|
56
|
+
if (objSchema.errorsFound.length > 0) {
|
|
57
|
+
throw new NoRetryError(objSchema.errorsFound.join(","))
|
|
58
|
+
} else {
|
|
59
|
+
return objSchema.result
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
const secondObjTypeTree = await getObjTypeHierarchy(_izContext, objTypes[1]).then(objSchema => {
|
|
63
|
+
if (objSchema.errorsFound.length > 0) {
|
|
64
|
+
throw new NoRetryError(objSchema.errorsFound.join(","))
|
|
65
|
+
} else {
|
|
66
|
+
return objSchema.result
|
|
67
|
+
}
|
|
68
|
+
});
|
|
54
69
|
|
|
55
70
|
const firstObjTypeTreeHashes = firstObjTypeTree.reduce(
|
|
56
71
|
(result, objType) => {
|
|
@@ -71,7 +86,7 @@ async function findLinksByObjTypes(_izContext, objTypes, relatoinshipLinks) {
|
|
|
71
86
|
|
|
72
87
|
let foundLinks = [];
|
|
73
88
|
|
|
74
|
-
for (let link of
|
|
89
|
+
for (let link of relationshipLinks) {
|
|
75
90
|
const fromObjTypeHash = hash(link.from.objType);
|
|
76
91
|
const toObjTypeHash = hash(link.to.objType);
|
|
77
92
|
|
|
@@ -100,6 +100,10 @@ function generateObjectSchemaForCreate(_izContext, objSchema) {
|
|
|
100
100
|
|
|
101
101
|
for (let [fieldName, fieldNameSetting] of Object.entries(objSchema.fieldNames)) {
|
|
102
102
|
|
|
103
|
+
if (!fieldNameSetting.requiredOnCreate && !fieldNameSetting.optionalOnCreate) {
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
|
|
103
107
|
if (!initReturnObj.fieldNames.hasOwnProperty(fieldName)) {
|
|
104
108
|
initReturnObj.fieldNames[fieldName] = {}
|
|
105
109
|
}
|
|
@@ -115,6 +119,11 @@ function generateObjectSchemaForCreate(_izContext, objSchema) {
|
|
|
115
119
|
for (let addOn of objSchema.addOnDataStructure) {
|
|
116
120
|
if (addOn.type === "versionedData") {
|
|
117
121
|
for (let [versionedFieldName, fieldNameData] of Object.entries(addOn.fieldNames)) {
|
|
122
|
+
|
|
123
|
+
if (!fieldNameData.requiredOnCreate && !fieldNameData.optionalOnCreate) {
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
|
|
118
127
|
Object.assign(
|
|
119
128
|
initReturnObj.fieldNames,
|
|
120
129
|
{
|
|
@@ -134,8 +143,6 @@ function generateObjectSchemaForCreate(_izContext, objSchema) {
|
|
|
134
143
|
return initReturnObj;
|
|
135
144
|
}
|
|
136
145
|
|
|
137
|
-
|
|
138
|
-
|
|
139
146
|
/**
|
|
140
147
|
* create object schema for update/display case
|
|
141
148
|
*
|