@izara_project/izara-core-library-service-schemas 1.0.60 → 1.0.62
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/index.js +1 -0
- package/package.json +7 -7
- package/src/SharedUtils.js +11 -3
- package/src/Utils.js +17 -3
- package/src/libs/CreateNodeLib.js +184 -0
- package/src/libs/UploadUseCase.js +46 -35
package/index.js
CHANGED
|
@@ -24,6 +24,7 @@ module.exports = {
|
|
|
24
24
|
uploadUseCase: require('./src/libs/UploadUseCase'),
|
|
25
25
|
relSchemaLib: require('./src/libs/RelSchemaLib'),
|
|
26
26
|
s3Utils: require('./src/libs/s3Utils'),
|
|
27
|
+
createNodeLib: require('./src/libs/CreateNodeLib'),
|
|
27
28
|
|
|
28
29
|
// .src
|
|
29
30
|
consts: require('./src/Consts'),
|
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.62",
|
|
4
4
|
"description": "Schemas for the service and objects it controls",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -20,15 +20,15 @@
|
|
|
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.812.0",
|
|
24
|
+
"@aws-sdk/client-s3": "^3.815.0",
|
|
25
|
+
"@aws-sdk/crc64-nvme-crt": "^3.815.0",
|
|
26
26
|
"@izara_project/izara-core-library-core": "^1.0.19",
|
|
27
|
-
"@izara_project/izara-core-library-external-request": "^1.0.
|
|
27
|
+
"@izara_project/izara-core-library-external-request": "^1.0.20",
|
|
28
28
|
"@izara_project/izara-core-library-lambda": "^1.0.4",
|
|
29
29
|
"@izara_project/izara-core-library-logger": "^1.0.7",
|
|
30
|
-
"@izara_project/izara-shared-service-schemas": "^1.0.
|
|
31
|
-
"glob": "^11.0.
|
|
30
|
+
"@izara_project/izara-shared-service-schemas": "^1.0.12",
|
|
31
|
+
"glob": "^11.0.2",
|
|
32
32
|
"lodash": "^4.17.21",
|
|
33
33
|
"object-hash": "^3.0.0",
|
|
34
34
|
"read-yaml-file": "^2.1.0"
|
package/src/SharedUtils.js
CHANGED
|
@@ -435,13 +435,21 @@ async function _processObjectLinksGroup(_izContext, relationshipTag, objectLinks
|
|
|
435
435
|
direction
|
|
436
436
|
);
|
|
437
437
|
|
|
438
|
+
let linkStorageResources = newLinkRelSchema.storageResourceTags.reduce((acc, tag) => {
|
|
439
|
+
const storageResource = relationshipSchema.storageResources[tag];
|
|
440
|
+
if (storageResource) {
|
|
441
|
+
acc[tag] = storageResource;
|
|
442
|
+
}
|
|
443
|
+
return acc;
|
|
444
|
+
}, {});
|
|
445
|
+
|
|
438
446
|
// Build link object structure
|
|
439
447
|
const link = {
|
|
440
448
|
relType: {
|
|
441
449
|
relationshipTag: relType.relationshipTag,
|
|
442
450
|
serviceTag: relType.serviceTag
|
|
443
451
|
},
|
|
444
|
-
|
|
452
|
+
storageResources: linkStorageResources,
|
|
445
453
|
from: newLinkRelSchema.from,
|
|
446
454
|
to: newLinkRelSchema.to,
|
|
447
455
|
canDelete: newLinkRelSchema.canDelete,
|
|
@@ -503,8 +511,8 @@ async function _processObjectLinksGroup(_izContext, relationshipTag, objectLinks
|
|
|
503
511
|
relationshipSchema.links.push(newLinkRelSchema);
|
|
504
512
|
linkByLinkTypeIds.push({ linkTypeId, link });
|
|
505
513
|
|
|
506
|
-
_izContext.logger.debug('relationshipSchema:', relationshipSchema);
|
|
507
|
-
_izContext.logger.debug('linkByLinkTypeIds:', linkByLinkTypeIds);
|
|
514
|
+
// _izContext.logger.debug('relationshipSchema:', relationshipSchema);
|
|
515
|
+
// _izContext.logger.debug('linkByLinkTypeIds:', linkByLinkTypeIds);
|
|
508
516
|
|
|
509
517
|
} catch (error) {
|
|
510
518
|
_izContext.logger.error('Error in addLinks:', error);
|
package/src/Utils.js
CHANGED
|
@@ -264,10 +264,11 @@ function validateAddOnDataStructure(_izContext, objectSchema) {
|
|
|
264
264
|
const storageResources = objectSchema.storageResources;
|
|
265
265
|
const storageTags = storageResources ? new Set(Object.keys(storageResources)) : new Set();
|
|
266
266
|
|
|
267
|
-
const allowedAddOnDataStructures = new Set(["versionedData", "attributeTree", "propertyNode", "translation"]);
|
|
267
|
+
const allowedAddOnDataStructures = new Set(["versionedData", "attributeTree", "propertyNode", "translation", "propertyValue"]);
|
|
268
268
|
|
|
269
269
|
let errors = [];
|
|
270
270
|
let fieldNameCollection = Object.keys(objectSchema.fieldNames || {});
|
|
271
|
+
let attriutebuteTreeTags = [];
|
|
271
272
|
|
|
272
273
|
if (objectSchema.addOnDataStructure?.length) {
|
|
273
274
|
for (const [idx, addOn] of objectSchema.addOnDataStructure.entries()) {
|
|
@@ -378,10 +379,17 @@ function validateRelationshipSchema(_izContext, relationshipSchema) {
|
|
|
378
379
|
if (link.from?.requiredOnCreate === true && link.to?.requiredOnCreate === true) {
|
|
379
380
|
errors.push(`Relationship:${relationshipTag}/links/${linkIdx}, requiredOnCreate should exists in one of 'from' or 'to'`);
|
|
380
381
|
}
|
|
382
|
+
|
|
383
|
+
for (const direction of Object.keys(link)) {
|
|
384
|
+
if (direction === "from" || direction === "to") {
|
|
385
|
+
if (link[direction]?.requiredOnCreate === true && link[switchDirection(direction)].linkType === "many") {
|
|
386
|
+
errors.push(`Relationship:${relationshipTag}/link/${linkIdx}/${switchDirection(direction)}.linkType must be one if ${direction}.requiredOnCreate = ${link[direction].requiredOnCreate}`)
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
}
|
|
381
390
|
}
|
|
382
391
|
}
|
|
383
392
|
|
|
384
|
-
|
|
385
393
|
if (errors.length) {
|
|
386
394
|
return [false, errors];
|
|
387
395
|
} else {
|
|
@@ -395,7 +403,6 @@ function validateRelationshipSchema(_izContext, relationshipSchema) {
|
|
|
395
403
|
}
|
|
396
404
|
}
|
|
397
405
|
|
|
398
|
-
|
|
399
406
|
function validateRefRelationshipSchema(_izContext, refRelationshipSchema, serviceTag) {
|
|
400
407
|
let validateStatus = validateObject(refRelationshipBasicSchema, refRelationshipSchema, null, { strict: false });
|
|
401
408
|
if (validateStatus.pass) {
|
|
@@ -606,6 +613,13 @@ function validateBasicFlowSchema(_izContext, flowSchema) {
|
|
|
606
613
|
}
|
|
607
614
|
}
|
|
608
615
|
|
|
616
|
+
function switchDirection(direction) {
|
|
617
|
+
if (direction === "from") {
|
|
618
|
+
return "to"
|
|
619
|
+
} else if (direction === "to") {
|
|
620
|
+
return "from"
|
|
621
|
+
}
|
|
622
|
+
}
|
|
609
623
|
|
|
610
624
|
module.exports = {
|
|
611
625
|
createObjType,
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright(C) 2021 Sven Mason < http://izara.io>
|
|
3
|
+
|
|
4
|
+
This program is free software: you can redistribute it and / or modify
|
|
5
|
+
it under the terms of the GNU Affero General Public License as
|
|
6
|
+
published by the Free Software Foundation, either version 3 of the
|
|
7
|
+
License, or(at your option) any later version.
|
|
8
|
+
|
|
9
|
+
This program is distributed in the hope that it will be useful,
|
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
|
|
12
|
+
GNU Affero General Public License for more details.
|
|
13
|
+
|
|
14
|
+
You should have received a copy of the GNU Affero General Public License
|
|
15
|
+
along with this program.If not, see < http://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
'use strict';
|
|
19
|
+
const { createRelTypeConcat, createLinkTypeId } = require('../Utils');
|
|
20
|
+
const getObjectSchema = require('../GetObjectSchema');
|
|
21
|
+
const serviceConfig = require('../ServiceConfig');
|
|
22
|
+
const { STORAGE_TYPES } = require('../Consts')
|
|
23
|
+
|
|
24
|
+
async function validateRequiredOnCreateLinks(_izContext, objType, relationships, settings = {}) {
|
|
25
|
+
_izContext.logger.debug("validateRequiredOnCreateLinks:::", { objType, relationships, settings })
|
|
26
|
+
let errorFound = [];
|
|
27
|
+
|
|
28
|
+
let requiredOnCreateLinks = await getObjectSchema.getRequiredOnCreateLinksWithCache(_izContext, objType)
|
|
29
|
+
_izContext.logger.debug("requiredOnCreateLinks::", requiredOnCreateLinks)
|
|
30
|
+
|
|
31
|
+
if (!requiredOnCreateLinks.length && relationships.length > 0) {
|
|
32
|
+
errorFound.push(`not have requireOnCreate will not create relationship: ${JSON.stringify(relationships)}`)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
let filteredRequiredOnCreateLinks = [];
|
|
36
|
+
if (settings.groupLinksByGraphServiceTag) {
|
|
37
|
+
await Promise.all(requiredOnCreateLinks.map(async requiredOnCreateLink => {
|
|
38
|
+
|
|
39
|
+
const serviceTags = await Promise.all(
|
|
40
|
+
requiredOnCreateLink.storageResourceTags.map(async (storageTag) => {
|
|
41
|
+
let storageResource = requiredOnCreateLink.storageResources[storageTag];
|
|
42
|
+
if (storageResource.storageType === STORAGE_TYPES.graph) {
|
|
43
|
+
return await serviceConfig.getGraphServiceTagWithCache(_izContext, storageResource.graphServerTag)
|
|
44
|
+
}
|
|
45
|
+
})
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
if (serviceTags.includes(settings.groupLinksByGraphServiceTag)) {
|
|
49
|
+
filteredRequiredOnCreateLinks.push(requiredOnCreateLink);
|
|
50
|
+
}
|
|
51
|
+
}))
|
|
52
|
+
} else {
|
|
53
|
+
filteredRequiredOnCreateLinks = requiredOnCreateLinks;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
let requiredOnCreateLinkGroups = groupRequiredOnCreateLink(_izContext, filteredRequiredOnCreateLinks);
|
|
57
|
+
_izContext.logger.debug("requiredOnCreateLinkGroups::", requiredOnCreateLinkGroups);
|
|
58
|
+
|
|
59
|
+
let requiredOnCreateRelTypeConcats = createRelTypeConcatWithDirection(_izContext, requiredOnCreateLinkGroups)
|
|
60
|
+
let validateOnCreateRelationships = new Set();
|
|
61
|
+
_izContext.logger.debug("start validate relationship from requestParams")
|
|
62
|
+
for (const relationship of relationships) {
|
|
63
|
+
// validate all relationship in requestParams
|
|
64
|
+
let relTypeConcat = createRelTypeConcat(_izContext, relationship.relType)
|
|
65
|
+
|
|
66
|
+
if (!requiredOnCreateLinkGroups[relTypeConcat]) {
|
|
67
|
+
errorFound.push(`cannot create relationship ${relTypeConcat}`)
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// match requiredOnCreateLinks with relationshipDirection from requestParams
|
|
72
|
+
const usedLinkGroup = requiredOnCreateLinkGroups[relTypeConcat][relationship.relationshipDirection];
|
|
73
|
+
|
|
74
|
+
if (!usedLinkGroup.length) {
|
|
75
|
+
errorFound.push(`cannot create relationship ${relTypeConcat}`)
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
for (let link of usedLinkGroup) {
|
|
80
|
+
// check other with targetObjType, check linkType of other should be 'one',
|
|
81
|
+
if (link.other.objType.objectType === relationship.targetObjType.objectType) {
|
|
82
|
+
if (link.other.linkType === "one") {
|
|
83
|
+
if (!validateOnCreateRelationships.has(`${relTypeConcat}_${relationship.relationshipDirection}`)) {
|
|
84
|
+
validateOnCreateRelationships.add(`${relTypeConcat}_${relationship.relationshipDirection}`)
|
|
85
|
+
} else {
|
|
86
|
+
errorFound.push(`unexpected dulicate relationship link ${JSON.stringify(relationship)}`)
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
} else {
|
|
90
|
+
errorFound.push(`invalid linkType should not be many when base: ${link} is requiredOnCreated`)
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
_izContext.logger.debug("requiredOnCreateRelTypeConcat", requiredOnCreateRelTypeConcats)
|
|
98
|
+
_izContext.logger.debug("validatedRelationships", validateOnCreateRelationships)
|
|
99
|
+
|
|
100
|
+
for (const requiredOnCreateRelTypeConcat of requiredOnCreateRelTypeConcats) {
|
|
101
|
+
if (!validateOnCreateRelationships.has(requiredOnCreateRelTypeConcat)) {
|
|
102
|
+
errorFound.push(`missing requiredOnCreate relationship ${requiredOnCreateRelTypeConcat}`)
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return errorFound;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function groupRequiredOnCreateLink(_izContext, relationshipSchemas) {
|
|
110
|
+
let groupLink = {};
|
|
111
|
+
for (let relationshipSchema of relationshipSchemas) {
|
|
112
|
+
let relTypeConcat = createRelTypeConcat(_izContext, relationshipSchema.relType);
|
|
113
|
+
if (!groupLink.hasOwnProperty(relTypeConcat)) {
|
|
114
|
+
Object.assign(groupLink, {
|
|
115
|
+
[relTypeConcat]: {
|
|
116
|
+
from: [],
|
|
117
|
+
to: []
|
|
118
|
+
}
|
|
119
|
+
})
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (relationshipSchema.base.direction === "from") {
|
|
123
|
+
groupLink[relTypeConcat].from.push(relationshipSchema)
|
|
124
|
+
} else if (relationshipSchema.base.direction === "to") {
|
|
125
|
+
groupLink[relTypeConcat].to.push(relationshipSchema)
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return groupLink
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function createRelTypeConcatWithDirection(_izContext, link) {
|
|
132
|
+
// console.log("createRelTypeConcat", { link })
|
|
133
|
+
let relTypeConcatSet = new Set();
|
|
134
|
+
for (const [relTypeConcat, direction] of Object.entries(link)) {
|
|
135
|
+
if (direction.from.length) {
|
|
136
|
+
relTypeConcatSet.add(`${relTypeConcat}_from`)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (direction.to.length) {
|
|
140
|
+
relTypeConcatSet.add(`${relTypeConcat}_to`)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
}
|
|
145
|
+
return relTypeConcatSet
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function createLinkTypeIdFromLinkGroup(_izContext, linkGroup) {
|
|
149
|
+
let linkTypeIds = new Set();
|
|
150
|
+
for (const objectRelationshipGroup of Object.values(linkGroup)) {
|
|
151
|
+
for (const direction of Object.keys(objectRelationshipGroup)) {
|
|
152
|
+
let objectRelationshipByDirection = objectRelationshipGroup[direction]
|
|
153
|
+
if (objectRelationshipGroup[direction].length) {
|
|
154
|
+
for (const objectRelLink of objectRelationshipGroup[direction]) {
|
|
155
|
+
linkTypeIds.add(createLinkTypeId(
|
|
156
|
+
_izContext,
|
|
157
|
+
objectRelLink?.base?.objType,
|
|
158
|
+
objectRelLink?.other?.objType,
|
|
159
|
+
objectRelLink?.relType,
|
|
160
|
+
objectRelLink?.base?.direction
|
|
161
|
+
))
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return [...linkTypeIds]
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
function switchDirection(direction) {
|
|
171
|
+
if (direction === "from") {
|
|
172
|
+
return "to"
|
|
173
|
+
} else if (direction === "to") {
|
|
174
|
+
return "from"
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
module.exports = {
|
|
179
|
+
validateRequiredOnCreateLinks,
|
|
180
|
+
groupRequiredOnCreateLink,
|
|
181
|
+
createLinkTypeIdFromLinkGroup,
|
|
182
|
+
switchDirection,
|
|
183
|
+
createRelTypeConcatWithDirection
|
|
184
|
+
}
|
|
@@ -380,13 +380,20 @@ function generateLinksDataPerLinkTypeId(_izContext, relationshipTag, relationshi
|
|
|
380
380
|
"from"
|
|
381
381
|
);
|
|
382
382
|
|
|
383
|
+
let linkStorageResources = link.storageResourceTags.reduce((acc, storageResourceTag) => {
|
|
384
|
+
if (storageResources.hasOwnProperty(storageResourceTag)) {
|
|
385
|
+
acc[storageResourceTag] = storageResources[storageResourceTag];
|
|
386
|
+
}
|
|
387
|
+
return acc;
|
|
388
|
+
}, {});
|
|
383
389
|
|
|
384
390
|
linksData[linkTypeId] = {
|
|
385
391
|
relType: {
|
|
386
392
|
relationshipTag,
|
|
387
393
|
serviceTag: process.env.iz_serviceTag
|
|
388
394
|
},
|
|
389
|
-
|
|
395
|
+
canDelete: link.canDelete || false,
|
|
396
|
+
storageResources: linkStorageResources,
|
|
390
397
|
from: link.from,
|
|
391
398
|
to: link.to
|
|
392
399
|
};
|
|
@@ -433,44 +440,48 @@ async function refRelationshipPerObjectSchema(_izContext, objSchema) {
|
|
|
433
440
|
let refObjectRel = {};
|
|
434
441
|
|
|
435
442
|
|
|
436
|
-
if (
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
443
|
+
if (process.env.iz_serviceTag !== "UserAccount") {
|
|
444
|
+
if (objSchema.hasOwnProperty("belongTo")) {
|
|
445
|
+
Object.assign(
|
|
446
|
+
refObjectRel,
|
|
447
|
+
{
|
|
448
|
+
"createdBy": {
|
|
449
|
+
relationshipServiceTag: "UserAccount"
|
|
450
|
+
},
|
|
451
|
+
"belongTo": {
|
|
452
|
+
relationshipServiceTag: "UserAccount"
|
|
453
|
+
}
|
|
445
454
|
}
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
455
|
+
)
|
|
456
|
+
} else {
|
|
457
|
+
Object.assign(
|
|
458
|
+
refObjectRel,
|
|
459
|
+
{
|
|
460
|
+
"createdBy": {
|
|
461
|
+
relationshipServiceTag: "UserAccount"
|
|
462
|
+
}
|
|
454
463
|
}
|
|
455
|
-
|
|
456
|
-
|
|
464
|
+
)
|
|
465
|
+
}
|
|
457
466
|
}
|
|
458
467
|
|
|
459
|
-
if (
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
468
|
+
if (process.env.iz_serviceTag !== "Translations") {
|
|
469
|
+
if (objSchema?.addOnDataStructure?.length && objSchema.addOnDataStructure.some(addOn => addOn.type === "translation")) {
|
|
470
|
+
Object.assign(
|
|
471
|
+
refObjectRel,
|
|
472
|
+
{
|
|
473
|
+
hasTranslationLink: {
|
|
474
|
+
relationshipServiceTag: "Translations",
|
|
475
|
+
},
|
|
476
|
+
currentTranslationLink: {
|
|
477
|
+
relationshipServiceTag: "Translations",
|
|
478
|
+
},
|
|
479
|
+
defaultTranslationLink: {
|
|
480
|
+
relationshipServiceTag: "Translations",
|
|
481
|
+
},
|
|
482
|
+
}
|
|
483
|
+
)
|
|
484
|
+
}
|
|
474
485
|
}
|
|
475
486
|
|
|
476
487
|
|