@izara_project/izara-core-library-service-schemas 1.0.73 → 1.0.75
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 +7 -7
- package/src/Consts.js +8 -5
- package/src/GetObjectSchema.js +24 -11
- package/src/Utils.js +19 -15
- package/src/libs/CreateNodeLib.js +31 -13
- package/src/libs/DeliminatorTree.js +8 -8
- package/src/libs/RelSchemaLib.js +19 -7
- package/src/libs/UploadUseCase.js +165 -187
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.75",
|
|
4
4
|
"description": "Schemas for the service and objects it controls",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -14,22 +14,22 @@
|
|
|
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": "^30.0.
|
|
17
|
+
"jest": "^30.0.4"
|
|
18
18
|
},
|
|
19
19
|
"jest": {
|
|
20
20
|
"testEnvironment": "node"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@aws-sdk/client-
|
|
24
|
-
"@aws-sdk/client-
|
|
25
|
-
"@aws-sdk/
|
|
26
|
-
"@aws-sdk/
|
|
23
|
+
"@aws-sdk/client-api-gateway": "^3.840.0",
|
|
24
|
+
"@aws-sdk/client-lambda": "^3.840.0",
|
|
25
|
+
"@aws-sdk/client-s3": "^3.842.0",
|
|
26
|
+
"@aws-sdk/crc64-nvme-crt": "^3.840.0",
|
|
27
27
|
"@izara_project/izara-core-library-core": "^1.0.19",
|
|
28
28
|
"@izara_project/izara-core-library-external-request": "^1.0.20",
|
|
29
29
|
"@izara_project/izara-core-library-lambda": "^1.0.4",
|
|
30
30
|
"@izara_project/izara-core-library-logger": "^1.0.7",
|
|
31
31
|
"@izara_project/izara-shared-core": "^1.0.2",
|
|
32
|
-
"@izara_project/izara-shared-service-schemas": "^1.0.
|
|
32
|
+
"@izara_project/izara-shared-service-schemas": "^1.0.21",
|
|
33
33
|
"glob": "^11.0.3",
|
|
34
34
|
"lodash": "^4.17.21",
|
|
35
35
|
"object-hash": "^3.0.0",
|
package/src/Consts.js
CHANGED
|
@@ -297,13 +297,16 @@ function createValidationFieldNameForEachType(type, validation) {
|
|
|
297
297
|
}[type]
|
|
298
298
|
}
|
|
299
299
|
|
|
300
|
-
function flowSchemaPathS3(_izContext, flowType) {
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
}
|
|
300
|
+
// function flowSchemaPathS3(_izContext, flowType) {
|
|
301
|
+
// validateFlowType(flowType);
|
|
302
|
+
// return `${PREFIX_PATH_S3.perServiceSchemas}/${flowType.serviceTag}/FlowSchema/${flowType.flowTag}.json`
|
|
303
|
+
// }
|
|
304
304
|
|
|
305
305
|
function getEndpointPerObjectType(_izContext, objType) {
|
|
306
|
-
validateObjType(objType);
|
|
306
|
+
let validateObjTypeResult = validateObjType(objType);
|
|
307
|
+
if (validateObjTypeResult.errorsFound.length > 0) {
|
|
308
|
+
throw new NoRetryError(`function flowSchemaPathS3: invalid flowType ${flowType.name} - ${validateFlowTypeResult.errorsFound.join(", ")}`);
|
|
309
|
+
}
|
|
307
310
|
return `${PREFIX_PATH_S3.perServiceSchemas}/${objType.serviceTag}/FrontEnd/Endpoint/Endpoint_Get_${objType.objectType}.json`
|
|
308
311
|
}
|
|
309
312
|
|
package/src/GetObjectSchema.js
CHANGED
|
@@ -36,7 +36,9 @@ const {
|
|
|
36
36
|
getObjectRelationship: getObjectRelationshipShared,
|
|
37
37
|
getRequiredOnCreateLinks: getRequiredOnCreateLinksShared,
|
|
38
38
|
getLinkConfigByLinkTypeId: getLinkConfigByLinkTypeIdShared,
|
|
39
|
-
getObjTypeHierarchy: getObjTypeHierarchyShared
|
|
39
|
+
getObjTypeHierarchy: getObjTypeHierarchyShared,
|
|
40
|
+
getObjectSchemaForCreate: getObjectSchemaForCreateShared,
|
|
41
|
+
getObjectSchemaForUpdate: getObjectSchemaForUpdateShared,
|
|
40
42
|
} = sharedServiceSchema.getObjectSchema;
|
|
41
43
|
const { validateObjType, validateFlowType } = sharedServiceSchema.validateObjType;
|
|
42
44
|
const {
|
|
@@ -222,7 +224,7 @@ async function getLocalObjectSchemas(_izContext, objectTypes, objSchemaPath = LO
|
|
|
222
224
|
allObjectSchemas.map(async (objSchema, idx) => {
|
|
223
225
|
const mergeResult = await mergeExtendObjSchema(_izContext, objSchema)
|
|
224
226
|
if (mergeResult?.errorsFound?.length && mergeResult?.errorsFound?.length > 0) {
|
|
225
|
-
throw new NoRetryError(mergeResult.errorsFound)
|
|
227
|
+
throw new NoRetryError(mergeResult.errorsFound.join(","))
|
|
226
228
|
} else {
|
|
227
229
|
allObjectSchemas[idx] = mergeResult;
|
|
228
230
|
}
|
|
@@ -471,7 +473,7 @@ async function getObjSchemaS3(
|
|
|
471
473
|
) {
|
|
472
474
|
return await getObjectSchemaS3Shared(getSchemaByNameWithCache, objType, getExtendObType).then(res => {
|
|
473
475
|
if (res.errorsFound.length && res.errorsFound.length > 0) {
|
|
474
|
-
throw new NoRetryError(res.errorsFound)
|
|
476
|
+
throw new NoRetryError(res.errorsFound.join(","))
|
|
475
477
|
} else {
|
|
476
478
|
return res.result
|
|
477
479
|
}
|
|
@@ -505,7 +507,7 @@ async function getObjSchemaS3WithHierarchy(_izContext, objType) {
|
|
|
505
507
|
// return await getObjSchemaS3WithCache(_izContext, objType, true)
|
|
506
508
|
return await getObjSchemaWithHierarchy(getSchemaByNameWithCache, objType).then(res => {
|
|
507
509
|
if (res.errorsFound.length && res.errorsFound.length > 0) {
|
|
508
|
-
throw new NoRetryError(res.errorsFound)
|
|
510
|
+
throw new NoRetryError(res.errorsFound.join(","))
|
|
509
511
|
} else {
|
|
510
512
|
return res.result
|
|
511
513
|
}
|
|
@@ -522,7 +524,7 @@ async function getObjSchemaS3WithoutHierarchy(_izContext, objType) {
|
|
|
522
524
|
// return await getObjSchemaS3WithCache(_izContext, objType, false)
|
|
523
525
|
return await getObjSchemaWithoutHierarchy(getSchemaByNameWithCache, objType).then(res => {
|
|
524
526
|
if (res.errorsFound.length && res.errorsFound.length > 0) {
|
|
525
|
-
throw new NoRetryError(res.errorsFound)
|
|
527
|
+
throw new NoRetryError(res.errorsFound.join(","))
|
|
526
528
|
} else {
|
|
527
529
|
return res.result
|
|
528
530
|
}
|
|
@@ -642,7 +644,7 @@ function getLocalRelationshipSchemas(_izContext, relationshipTags, objSchemaPath
|
|
|
642
644
|
async function getRefObjectRelationship(_izContext, objType) {
|
|
643
645
|
return await getRefObjectRelationshipShared(getSchemaByNameWithCache, objType).then(res => {
|
|
644
646
|
if (res.errorsFound.length && res.errorsFound.length > 0) {
|
|
645
|
-
throw new NoRetryError(res.errorsFound)
|
|
647
|
+
throw new NoRetryError(res.errorsFound.join(","))
|
|
646
648
|
} else {
|
|
647
649
|
return res.result
|
|
648
650
|
}
|
|
@@ -677,7 +679,7 @@ const getRefObjectRelationshipWithCache = inMemoryCacheLib(
|
|
|
677
679
|
async function getRelationshipSchema(_izContext, relType) {
|
|
678
680
|
return await getRelationshipSchemaShared(getSchemaByNameWithCache, relType).then(res => {
|
|
679
681
|
if (res.errorsFound.length && res.errorsFound.length > 0) {
|
|
680
|
-
throw new NoRetryError(res.errorsFound)
|
|
682
|
+
throw new NoRetryError(res.errorsFound.join(","))
|
|
681
683
|
} else {
|
|
682
684
|
return res.result
|
|
683
685
|
}
|
|
@@ -790,7 +792,7 @@ async function getObjectRelationship(
|
|
|
790
792
|
|
|
791
793
|
return await getObjectRelationshipShared(getSchemaByNameWithCache, objType, specificRelTags, overWriteBaseObjType).then(res => {
|
|
792
794
|
if (res.errorsFound.length && res.errorsFound.length > 0) {
|
|
793
|
-
throw new NoRetryError(res.errorsFound)
|
|
795
|
+
throw new NoRetryError(res.errorsFound.join(","))
|
|
794
796
|
} else {
|
|
795
797
|
return res.result
|
|
796
798
|
}
|
|
@@ -840,7 +842,7 @@ async function getRequiredOnCreateLinks(
|
|
|
840
842
|
|
|
841
843
|
return await getRequiredOnCreateLinksShared(getSchemaByNameWithCache, objType, specificRelTags).then(res => {
|
|
842
844
|
if (res.errorsFound.length && res.errorsFound.length > 0) {
|
|
843
|
-
throw new NoRetryError(res.errorsFound)
|
|
845
|
+
throw new NoRetryError(res.errorsFound.join(","))
|
|
844
846
|
} else {
|
|
845
847
|
return res.result
|
|
846
848
|
}
|
|
@@ -922,7 +924,7 @@ async function getLinkConfigByLinkTypeId(_izContext, firstObjType, secondObjType
|
|
|
922
924
|
|
|
923
925
|
await getLinkConfigByLinkTypeIdShared(getSchemaByNameWithCache, firstObjType, secondObjType, relType, direction, settings).then(res => {
|
|
924
926
|
if (res.errorsFound.length && res.errorsFound.length > 0) {
|
|
925
|
-
throw new NoRetryError(res.errorsFound)
|
|
927
|
+
throw new NoRetryError(res.errorsFound.join(","))
|
|
926
928
|
} else {
|
|
927
929
|
return res.result
|
|
928
930
|
}
|
|
@@ -1124,6 +1126,14 @@ const getObjTypeHierarchyWithCache = inMemoryCacheLib(
|
|
|
1124
1126
|
}
|
|
1125
1127
|
)
|
|
1126
1128
|
|
|
1129
|
+
async function getObjectSchemaForCreate(_izContext, objType) {
|
|
1130
|
+
return await getObjectSchemaForCreateShared(getSchemaByNameWithCache, objType)
|
|
1131
|
+
}
|
|
1132
|
+
|
|
1133
|
+
async function getObjectSchemaForUpdate(_izContext, objType) {
|
|
1134
|
+
return await getObjectSchemaForUpdateShared(getSchemaByNameWithCache, objType)
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1127
1137
|
module.exports = {
|
|
1128
1138
|
// getObjectTypes,
|
|
1129
1139
|
getDataFromPath,
|
|
@@ -1178,7 +1188,10 @@ module.exports = {
|
|
|
1178
1188
|
getFlowSchemaS3WithCache,
|
|
1179
1189
|
|
|
1180
1190
|
getObjTypeHierarchy,
|
|
1181
|
-
getObjTypeHierarchyWithCache
|
|
1191
|
+
getObjTypeHierarchyWithCache,
|
|
1192
|
+
|
|
1193
|
+
getObjectSchemaForCreate,
|
|
1194
|
+
getObjectSchemaForUpdate,
|
|
1182
1195
|
}
|
|
1183
1196
|
|
|
1184
1197
|
|
package/src/Utils.js
CHANGED
|
@@ -35,6 +35,9 @@ const {
|
|
|
35
35
|
validateObjType,
|
|
36
36
|
validateRelType,
|
|
37
37
|
validateFlowType
|
|
38
|
+
},
|
|
39
|
+
reformatObjectSchema: {
|
|
40
|
+
getUsedFieldNamesOfIdentifiers: getUsedFieldNamesOfIdentifiersShared
|
|
38
41
|
}
|
|
39
42
|
} = require('@izara_project/izara-shared-service-schemas');
|
|
40
43
|
|
|
@@ -106,21 +109,22 @@ function getIdentifierTypeByPriority(_izContext, storageTypes = [], objSchema) {
|
|
|
106
109
|
* @returns {string[]} - array of fieldName from objectSchema.identifiers
|
|
107
110
|
*/
|
|
108
111
|
function getUsedFieldNamesOfIdentifiers(_izContext, identifiers, identifierTypes = []) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
|
|
112
|
+
return getUsedFieldNamesOfIdentifiersShared(identifiers, identifierTypes)
|
|
113
|
+
// let identifierFieldNames = [];
|
|
114
|
+
|
|
115
|
+
// for (let identifier of identifiers) {
|
|
116
|
+
// if (Array.isArray(identifierTypes) && identifierTypes.length && !identifierTypes.includes(identifier.type)) {
|
|
117
|
+
// continue;
|
|
118
|
+
// }
|
|
119
|
+
|
|
120
|
+
// if (identifier.fieldName) {
|
|
121
|
+
// identifierFieldNames.push(identifier.fieldName);
|
|
122
|
+
// } else if (identifier.fieldNames) {
|
|
123
|
+
// identifierFieldNames = identifierFieldNames.concat(identifier.fieldNames);
|
|
124
|
+
// }
|
|
125
|
+
// }
|
|
126
|
+
|
|
127
|
+
// return [...new Set(identifierFieldNames)];
|
|
124
128
|
}
|
|
125
129
|
|
|
126
130
|
|
|
@@ -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,12 +29,12 @@ 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 new 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) {
|
|
@@ -52,8 +52,20 @@ async function findLinksByObjTypes(_izContext, objTypes, relatoinshipLinks) {
|
|
|
52
52
|
const secondObjType = objTypes[1];
|
|
53
53
|
|
|
54
54
|
// first create hierarchy of each objType
|
|
55
|
-
const firstObjTypeTree = await getObjTypeHierarchy(_izContext, objTypes[0])
|
|
56
|
-
|
|
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
|
+
});
|
|
57
69
|
|
|
58
70
|
const firstObjTypeTreeHashes = firstObjTypeTree.reduce(
|
|
59
71
|
(result, objType) => {
|
|
@@ -74,7 +86,7 @@ async function findLinksByObjTypes(_izContext, objTypes, relatoinshipLinks) {
|
|
|
74
86
|
|
|
75
87
|
let foundLinks = [];
|
|
76
88
|
|
|
77
|
-
for (let link of
|
|
89
|
+
for (let link of relationshipLinks) {
|
|
78
90
|
const fromObjTypeHash = hash(link.from.objType);
|
|
79
91
|
const toObjTypeHash = hash(link.to.objType);
|
|
80
92
|
|
|
@@ -18,7 +18,11 @@ along with this program.If not, see < http://www.gnu.org/licenses/>.
|
|
|
18
18
|
'use strict';
|
|
19
19
|
|
|
20
20
|
const { NoRetryError } = require('@izara_project/izara-core-library-core');
|
|
21
|
-
|
|
21
|
+
const {
|
|
22
|
+
generateObjectSchemaForCreate: generateObjectSchemaForCreateShared,
|
|
23
|
+
generateObjectSchemaForUpdate: generateObjectSchemaForUpdateShared,
|
|
24
|
+
generateObjectSchemaForCombineFieldNames: generateObjectSchemaForCombineFieldNamesShared
|
|
25
|
+
} = require('@izara_project/izara-shared-service-schemas').reformatObjectSchema
|
|
22
26
|
const {
|
|
23
27
|
getUsedFieldNamesOfIdentifiers,
|
|
24
28
|
findLinkByObjType,
|
|
@@ -45,44 +49,6 @@ const DEFAULT_REL_ID_SETTING = {
|
|
|
45
49
|
}
|
|
46
50
|
}
|
|
47
51
|
|
|
48
|
-
|
|
49
|
-
// add default versionedData fieldNames when upload
|
|
50
|
-
function defaultVersionedDataFieldNames(_izContext, versionedDataLabel, storageTag) {
|
|
51
|
-
return {
|
|
52
|
-
[`versionedDataField_${versionedDataLabel}_versionedDataId`]: {
|
|
53
|
-
type: "string",
|
|
54
|
-
generatedField: true,
|
|
55
|
-
versionedDataLabel: versionedDataLabel,
|
|
56
|
-
storageResourceTags: [storageTag],
|
|
57
|
-
requiredOnCreate: false,
|
|
58
|
-
optionalOnCreate: false,
|
|
59
|
-
canUpdate: false,
|
|
60
|
-
validation: {},
|
|
61
|
-
},
|
|
62
|
-
[`versionedDataField_${versionedDataLabel}_forMatchedId`]: {
|
|
63
|
-
type: "string",
|
|
64
|
-
generatedField: true,
|
|
65
|
-
versionedDataLabel: versionedDataLabel,
|
|
66
|
-
storageResourceTags: [storageTag],
|
|
67
|
-
requiredOnCreate: false,
|
|
68
|
-
optionalOnCreate: false,
|
|
69
|
-
canUpdate: false,
|
|
70
|
-
validation: {},
|
|
71
|
-
},
|
|
72
|
-
[`versionedDataField_${versionedDataLabel}_originTimestamp`]: {
|
|
73
|
-
type: "number",
|
|
74
|
-
generatedField: true,
|
|
75
|
-
versionedDataLabel: versionedDataLabel,
|
|
76
|
-
storageResourceTags: [storageTag],
|
|
77
|
-
requiredOnCreate: false,
|
|
78
|
-
optionalOnCreate: false,
|
|
79
|
-
canUpdate: false,
|
|
80
|
-
validation: {},
|
|
81
|
-
},
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
|
|
86
52
|
/**
|
|
87
53
|
* create object schema for create case
|
|
88
54
|
*
|
|
@@ -92,50 +58,58 @@ function defaultVersionedDataFieldNames(_izContext, versionedDataLabel, storageT
|
|
|
92
58
|
*/
|
|
93
59
|
function generateObjectSchemaForCreate(_izContext, objSchema) {
|
|
94
60
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
//
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
61
|
+
return generateObjectSchemaForCreateShared(objSchema)
|
|
62
|
+
// // generate data for case create
|
|
63
|
+
// let initReturnObj = {
|
|
64
|
+
// objectType: objSchema.objectType,
|
|
65
|
+
// fieldNames: {}
|
|
66
|
+
// };
|
|
67
|
+
|
|
68
|
+
// for (let [fieldName, fieldNameSetting] of Object.entries(objSchema.fieldNames)) {
|
|
69
|
+
|
|
70
|
+
// if (!fieldNameSetting.requiredOnCreate && !fieldNameSetting.optionalOnCreate) {
|
|
71
|
+
// continue;
|
|
72
|
+
// }
|
|
73
|
+
|
|
74
|
+
// if (!initReturnObj.fieldNames.hasOwnProperty(fieldName)) {
|
|
75
|
+
// initReturnObj.fieldNames[fieldName] = {}
|
|
76
|
+
// }
|
|
77
|
+
|
|
78
|
+
// initReturnObj.fieldNames[fieldName].type = fieldNameSetting.type;
|
|
79
|
+
// initReturnObj.fieldNames[fieldName].validation = fieldNameSetting.validation || {};
|
|
80
|
+
// initReturnObj.fieldNames[fieldName].requiredOnCreate = (fieldNameSetting.requiredOnCreate === true) ? true : false;
|
|
81
|
+
// initReturnObj.fieldNames[fieldName].optionalOnCreate = (fieldNameSetting.optionalOnCreate === true) ? true : false;
|
|
82
|
+
// }
|
|
83
|
+
|
|
84
|
+
// // add fieldNames from versionedData
|
|
85
|
+
// if (objSchema.addOnDataStructure?.length) {
|
|
86
|
+
// for (let addOn of objSchema.addOnDataStructure) {
|
|
87
|
+
// if (addOn.type === "versionedData") {
|
|
88
|
+
// for (let [versionedFieldName, fieldNameData] of Object.entries(addOn.fieldNames)) {
|
|
89
|
+
|
|
90
|
+
// if (!fieldNameData.requiredOnCreate && !fieldNameData.optionalOnCreate) {
|
|
91
|
+
// continue;
|
|
92
|
+
// }
|
|
93
|
+
|
|
94
|
+
// Object.assign(
|
|
95
|
+
// initReturnObj.fieldNames,
|
|
96
|
+
// {
|
|
97
|
+
// [versionedFieldName]: {
|
|
98
|
+
// type: fieldNameData.type,
|
|
99
|
+
// validation: fieldNameData.validation || {},
|
|
100
|
+
// requiredOnCreate: fieldNameData.requiredOnCreate || false,
|
|
101
|
+
// optionalOnCreate: fieldNameData.optionalOnCreate || false,
|
|
102
|
+
// }
|
|
103
|
+
// });
|
|
104
|
+
// }
|
|
105
|
+
// }
|
|
106
|
+
// }
|
|
107
|
+
// }
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
// return initReturnObj;
|
|
135
111
|
}
|
|
136
112
|
|
|
137
|
-
|
|
138
|
-
|
|
139
113
|
/**
|
|
140
114
|
* create object schema for update/display case
|
|
141
115
|
*
|
|
@@ -144,65 +118,67 @@ function generateObjectSchemaForCreate(_izContext, objSchema) {
|
|
|
144
118
|
* @returns {Object} - objectSchema that has property for case update
|
|
145
119
|
*/
|
|
146
120
|
function generateObjectSchemaForUpdate(_izContext, objSchema) {
|
|
147
|
-
// generate data for case update
|
|
148
|
-
let initReturnObj = {
|
|
149
|
-
objectType: objSchema.objectType,
|
|
150
|
-
fieldNames: {},
|
|
151
|
-
identifiers: objSchema.identifiers,
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
if (objSchema.extendObjType) {
|
|
155
|
-
initReturnObj.extendObjType = objSchema.extendObjType;
|
|
156
|
-
} else {
|
|
157
|
-
initReturnObj.identifierFieldNames = getUsedFieldNamesOfIdentifiers(_izContext, objSchema.identifiers);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
for (let [fieldName, fieldNameSetting] of Object.entries(objSchema.fieldNames)) {
|
|
161
|
-
|
|
162
|
-
if (!initReturnObj.fieldNames.hasOwnProperty(fieldName)) {
|
|
163
|
-
initReturnObj.fieldNames[fieldName] = {}
|
|
164
|
-
}
|
|
165
121
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
//
|
|
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
|
-
|
|
122
|
+
return generateObjectSchemaForUpdateShared(objSchema)
|
|
123
|
+
// // generate data for case update
|
|
124
|
+
// let initReturnObj = {
|
|
125
|
+
// objectType: objSchema.objectType,
|
|
126
|
+
// fieldNames: {},
|
|
127
|
+
// identifiers: objSchema.identifiers,
|
|
128
|
+
// };
|
|
129
|
+
|
|
130
|
+
// if (objSchema.extendObjType) {
|
|
131
|
+
// initReturnObj.extendObjType = objSchema.extendObjType;
|
|
132
|
+
// } else {
|
|
133
|
+
// initReturnObj.identifierFieldNames = getUsedFieldNamesOfIdentifiers(_izContext, objSchema.identifiers);
|
|
134
|
+
// }
|
|
135
|
+
|
|
136
|
+
// for (let [fieldName, fieldNameSetting] of Object.entries(objSchema.fieldNames)) {
|
|
137
|
+
|
|
138
|
+
// if (!initReturnObj.fieldNames.hasOwnProperty(fieldName)) {
|
|
139
|
+
// initReturnObj.fieldNames[fieldName] = {}
|
|
140
|
+
// }
|
|
141
|
+
|
|
142
|
+
// if (fieldNameSetting.canUpdate === true || fieldNameSetting.canUpdate === undefined) {
|
|
143
|
+
// initReturnObj.fieldNames[fieldName].type = fieldNameSetting.type;
|
|
144
|
+
// initReturnObj.fieldNames[fieldName].validation = fieldNameSetting.validation || {};
|
|
145
|
+
// initReturnObj.fieldNames[fieldName].canUpdate = true;
|
|
146
|
+
// } else {
|
|
147
|
+
// initReturnObj.fieldNames[fieldName].type = fieldNameSetting.type;
|
|
148
|
+
// }
|
|
149
|
+
// }
|
|
150
|
+
|
|
151
|
+
// // add fieldNames from versionedData
|
|
152
|
+
// if (objSchema.addOnDataStructure?.length) {
|
|
153
|
+
// for (let addOn of objSchema.addOnDataStructure) {
|
|
154
|
+
// if (addOn.type === "versionedData") {
|
|
155
|
+
// for (let [versionedFieldName, fieldNameData] of Object.entries(addOn.fieldNames)) {
|
|
156
|
+
|
|
157
|
+
// if (fieldNameData.canUpdate === true || fieldNameData.canUpdate === undefined) {
|
|
158
|
+
// Object.assign(
|
|
159
|
+
// initReturnObj.fieldNames,
|
|
160
|
+
// {
|
|
161
|
+
// [versionedFieldName]: {
|
|
162
|
+
// type: fieldNameData.type,
|
|
163
|
+
// canUpdate: true,
|
|
164
|
+
// validation: fieldNameData.validation || {},
|
|
165
|
+
// }
|
|
166
|
+
// });
|
|
167
|
+
// } else {
|
|
168
|
+
// Object.assign(
|
|
169
|
+
// initReturnObj.fieldNames,
|
|
170
|
+
// {
|
|
171
|
+
// [versionedFieldName]: {
|
|
172
|
+
// type: fieldNameData.type,
|
|
173
|
+
// }
|
|
174
|
+
// });
|
|
175
|
+
// }
|
|
176
|
+
// }
|
|
177
|
+
// }
|
|
178
|
+
// }
|
|
179
|
+
// }
|
|
180
|
+
|
|
181
|
+
// return initReturnObj;
|
|
206
182
|
}
|
|
207
183
|
|
|
208
184
|
|
|
@@ -216,55 +192,57 @@ function generateObjectSchemaForUpdate(_izContext, objSchema) {
|
|
|
216
192
|
* @returns {Object} - objectSchema that has property for case update
|
|
217
193
|
*/
|
|
218
194
|
function generateObjectSchemaForCombineFieldNames(_izContext, objSchema) {
|
|
219
|
-
// generate data for case update
|
|
220
|
-
let initReturnObj = {
|
|
221
|
-
objectType: objSchema.objectType,
|
|
222
|
-
fieldNames: objSchema.fieldNames,
|
|
223
|
-
canDelete: objSchema.canDelete,
|
|
224
|
-
storageResources: objSchema.storageResources
|
|
225
|
-
};
|
|
226
|
-
|
|
227
|
-
if (objSchema.extendObjType) {
|
|
228
|
-
initReturnObj.extendObjType = objSchema.extendObjType;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
if (objSchema.identifiers) {
|
|
232
|
-
initReturnObj.identifiers = objSchema.identifiers;
|
|
233
|
-
initReturnObj.identifierFieldNames = getUsedFieldNamesOfIdentifiers(_izContext, objSchema.identifiers);
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
// add fieldNames from versionedData
|
|
237
|
-
if (objSchema.addOnDataStructure?.length) {
|
|
238
|
-
let versionedDataLabels = [];
|
|
239
|
-
// versionedDataField_ceo_versionedDataId
|
|
240
|
-
for (let addOn of objSchema.addOnDataStructure) {
|
|
241
|
-
if (addOn.type === "versionedData") {
|
|
242
|
-
// add default fieldNames of versionedData to main fieldNames
|
|
243
|
-
Object.assign(
|
|
244
|
-
initReturnObj.fieldNames,
|
|
245
|
-
defaultVersionedDataFieldNames(_izContext, addOn.versionedDataLabel, addOn.storageResourceTag)
|
|
246
|
-
);
|
|
247
195
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
196
|
+
return generateObjectSchemaForCombineFieldNamesShared(objSchema)
|
|
197
|
+
// generate data for case update
|
|
198
|
+
// let initReturnObj = {
|
|
199
|
+
// objectType: objSchema.objectType,
|
|
200
|
+
// fieldNames: objSchema.fieldNames,
|
|
201
|
+
// canDelete: objSchema.canDelete,
|
|
202
|
+
// storageResources: objSchema.storageResources
|
|
203
|
+
// };
|
|
204
|
+
|
|
205
|
+
// if (objSchema.extendObjType) {
|
|
206
|
+
// initReturnObj.extendObjType = objSchema.extendObjType;
|
|
207
|
+
// }
|
|
208
|
+
|
|
209
|
+
// if (objSchema.identifiers) {
|
|
210
|
+
// initReturnObj.identifiers = objSchema.identifiers;
|
|
211
|
+
// initReturnObj.identifierFieldNames = getUsedFieldNamesOfIdentifiers(_izContext, objSchema.identifiers);
|
|
212
|
+
// }
|
|
213
|
+
|
|
214
|
+
// // add fieldNames from versionedData
|
|
215
|
+
// if (objSchema.addOnDataStructure?.length) {
|
|
216
|
+
// let versionedDataLabels = [];
|
|
217
|
+
// // versionedDataField_ceo_versionedDataId
|
|
218
|
+
// for (let addOn of objSchema.addOnDataStructure) {
|
|
219
|
+
// if (addOn.type === "versionedData") {
|
|
220
|
+
// // add default fieldNames of versionedData to main fieldNames
|
|
221
|
+
// Object.assign(
|
|
222
|
+
// initReturnObj.fieldNames,
|
|
223
|
+
// defaultVersionedDataFieldNames(_izContext, addOn.versionedDataLabel, addOn.storageResourceTag)
|
|
224
|
+
// );
|
|
225
|
+
|
|
226
|
+
// // add each versionedData fieldName to main fieldNames
|
|
227
|
+
// for (let [versionedFieldName, fieldNameData] of Object.entries(addOn.fieldNames)) {
|
|
228
|
+
// Object.assign(initReturnObj.fieldNames, {
|
|
229
|
+
// [versionedFieldName]: {
|
|
230
|
+
// ...fieldNameData,
|
|
231
|
+
// versionedDataLabel: addOn.versionedDataLabel,
|
|
232
|
+
// storageResourceTags: [addOn.storageResourceTag]
|
|
233
|
+
// }
|
|
234
|
+
// });
|
|
235
|
+
// }
|
|
236
|
+
// versionedDataLabels.push(addOn.versionedDataLabel);
|
|
237
|
+
// }
|
|
238
|
+
// }
|
|
239
|
+
|
|
240
|
+
// if (versionedDataLabels.length) {
|
|
241
|
+
// initReturnObj.versionedDataLabels = versionedDataLabels;
|
|
242
|
+
// }
|
|
243
|
+
// }
|
|
244
|
+
|
|
245
|
+
// return initReturnObj;
|
|
268
246
|
}
|
|
269
247
|
|
|
270
248
|
|