@izara_project/izara-core-library-service-schemas 1.0.59 → 1.0.60
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 +1 -1
- package/src/GetObjectSchema.js +10 -10
- package/src/SharedUtils.js +60 -18
- package/src/UploadObjSchema.js +6 -1
- package/src/Utils.js +1 -0
- package/src/ValidatorSchema.js +2 -0
- package/src/libs/SharedUtilsLibs.js +1 -1
- package/src/libs/s3Utils.js +20 -2
package/index.js
CHANGED
|
@@ -23,6 +23,7 @@ module.exports = {
|
|
|
23
23
|
explodedReqParams: require('./src/libs/ExplodedReqParams'),
|
|
24
24
|
uploadUseCase: require('./src/libs/UploadUseCase'),
|
|
25
25
|
relSchemaLib: require('./src/libs/RelSchemaLib'),
|
|
26
|
+
s3Utils: require('./src/libs/s3Utils'),
|
|
26
27
|
|
|
27
28
|
// .src
|
|
28
29
|
consts: require('./src/Consts'),
|
package/package.json
CHANGED
package/src/GetObjectSchema.js
CHANGED
|
@@ -53,7 +53,7 @@ const {
|
|
|
53
53
|
// const dynamodbSharedLib = require('@izara_project/izara-shared/src/DynamodbSharedLib');
|
|
54
54
|
// const Logger = require('@izara_project/izara-core-library-logger')
|
|
55
55
|
|
|
56
|
-
const { getObjectS3, headObjectS3,
|
|
56
|
+
const { getObjectS3, headObjectS3, getSchemaByNameWithCache } = require("./libs/s3Utils");
|
|
57
57
|
const { generateObjectSchemaForCombineFieldNames } = require("./libs/UploadUseCase");
|
|
58
58
|
|
|
59
59
|
const {
|
|
@@ -449,7 +449,7 @@ async function getObjSchemaS3(
|
|
|
449
449
|
objType,
|
|
450
450
|
getExtendObType = false
|
|
451
451
|
) {
|
|
452
|
-
return await getObjectSchemaS3Shared(
|
|
452
|
+
return await getObjectSchemaS3Shared(getSchemaByNameWithCache, objType, getExtendObType);
|
|
453
453
|
}
|
|
454
454
|
|
|
455
455
|
|
|
@@ -477,7 +477,7 @@ const getObjSchemaS3WithCache = inMemoryCacheLib(
|
|
|
477
477
|
*/
|
|
478
478
|
async function getObjSchemaS3WithHierarchy(_izContext, objType) {
|
|
479
479
|
// return await getObjSchemaS3WithCache(_izContext, objType, true)
|
|
480
|
-
return await getObjSchemaWithHierarchy(
|
|
480
|
+
return await getObjSchemaWithHierarchy(getSchemaByNameWithCache, objType)
|
|
481
481
|
}
|
|
482
482
|
|
|
483
483
|
/**
|
|
@@ -488,7 +488,7 @@ async function getObjSchemaS3WithHierarchy(_izContext, objType) {
|
|
|
488
488
|
*/
|
|
489
489
|
async function getObjSchemaS3WithoutHierarchy(_izContext, objType) {
|
|
490
490
|
// return await getObjSchemaS3WithCache(_izContext, objType, false)
|
|
491
|
-
return await getObjSchemaWithoutHierarchy(
|
|
491
|
+
return await getObjSchemaWithoutHierarchy(getSchemaByNameWithCache, objType)
|
|
492
492
|
}
|
|
493
493
|
|
|
494
494
|
|
|
@@ -598,7 +598,7 @@ function getLocalRelationshipSchemas(_izContext, relationshipTags, objSchemaPath
|
|
|
598
598
|
* @returns {Promise<Object>} - reference relationship schema of objType
|
|
599
599
|
*/
|
|
600
600
|
async function getRefObjectRelationship(_izContext, objType) {
|
|
601
|
-
return await getRefObjectRelationshipShared(
|
|
601
|
+
return await getRefObjectRelationshipShared(getSchemaByNameWithCache, objType)
|
|
602
602
|
}
|
|
603
603
|
|
|
604
604
|
/**
|
|
@@ -628,7 +628,7 @@ const getRefObjectRelationshipWithCache = inMemoryCacheLib(
|
|
|
628
628
|
*/
|
|
629
629
|
async function getRelationshipSchema(_izContext, relType) {
|
|
630
630
|
|
|
631
|
-
return await getRelationshipSchemaShared(
|
|
631
|
+
return await getRelationshipSchemaShared(getSchemaByNameWithCache, relType)
|
|
632
632
|
}
|
|
633
633
|
|
|
634
634
|
|
|
@@ -730,7 +730,7 @@ async function getObjectRelationship(
|
|
|
730
730
|
overWriteBaseObjType,
|
|
731
731
|
) {
|
|
732
732
|
|
|
733
|
-
return await getObjectRelationshipShared(
|
|
733
|
+
return await getObjectRelationshipShared(getSchemaByNameWithCache, objType, specificRelTags, overWriteBaseObjType)
|
|
734
734
|
}
|
|
735
735
|
|
|
736
736
|
|
|
@@ -774,7 +774,7 @@ async function getRequiredOnCreateLinks(
|
|
|
774
774
|
specificRelTags,
|
|
775
775
|
});
|
|
776
776
|
|
|
777
|
-
return await getRequiredOnCreateLinksShared(
|
|
777
|
+
return await getRequiredOnCreateLinksShared(getSchemaByNameWithCache, objType, specificRelTags)
|
|
778
778
|
}
|
|
779
779
|
|
|
780
780
|
|
|
@@ -849,7 +849,7 @@ async function getLinkConfigByLinkTypeId(_izContext, firstObjType, secondObjType
|
|
|
849
849
|
direction
|
|
850
850
|
});
|
|
851
851
|
|
|
852
|
-
return await getLinkConfigByLinkTypeIdShared(
|
|
852
|
+
return await getLinkConfigByLinkTypeIdShared(getSchemaByNameWithCache, firstObjType, secondObjType, relType, direction);
|
|
853
853
|
}
|
|
854
854
|
|
|
855
855
|
/**
|
|
@@ -881,7 +881,7 @@ const getLinkConfigByLinkTypeIdWithCache = inMemoryCacheLib(
|
|
|
881
881
|
*/
|
|
882
882
|
async function mergeExtendObjSchema(_izContext, objectSchema) {
|
|
883
883
|
// return mergedObjectSchema;
|
|
884
|
-
return await mergeExtendObjSchemaShared(
|
|
884
|
+
return await mergeExtendObjSchemaShared(getSchemaByNameWithCache, objectSchema);
|
|
885
885
|
}
|
|
886
886
|
|
|
887
887
|
|
package/src/SharedUtils.js
CHANGED
|
@@ -17,6 +17,8 @@ along with this program.If not, see < http://www.gnu.org/licenses/>.
|
|
|
17
17
|
|
|
18
18
|
'use strict';
|
|
19
19
|
|
|
20
|
+
const hash = require('object-hash');
|
|
21
|
+
|
|
20
22
|
const {
|
|
21
23
|
validateGraphServerTags,
|
|
22
24
|
mergeStorageResources,
|
|
@@ -97,6 +99,9 @@ async function _processNodeRelationships(
|
|
|
97
99
|
const baseNode = isBase ? newLinkRelSchema.from : newLinkRelSchema.to;
|
|
98
100
|
const otherNode = isBase ? newLinkRelSchema.to : newLinkRelSchema.from;
|
|
99
101
|
|
|
102
|
+
_izContext.logger.debug('baseNode:', baseNode);
|
|
103
|
+
_izContext.logger.debug('otherNode:', otherNode);
|
|
104
|
+
|
|
100
105
|
// Check for existing relationships
|
|
101
106
|
const existingObjRel = objectRelationshipsArray.find(objRel => (
|
|
102
107
|
objRel.relType.relationshipTag === relType.relationshipTag &&
|
|
@@ -107,6 +112,8 @@ async function _processNodeRelationships(
|
|
|
107
112
|
objRel.other.objType.objectType === otherNode.objType.objectType
|
|
108
113
|
));
|
|
109
114
|
|
|
115
|
+
_izContext.logger.debug('existingObjRel:', existingObjRel);
|
|
116
|
+
|
|
110
117
|
let updatedRelationships = [];
|
|
111
118
|
|
|
112
119
|
if (existingObjRel) {
|
|
@@ -178,6 +185,8 @@ async function _processNodeRelationships(
|
|
|
178
185
|
updatedRelationships = [...objectRelationshipsArray, newRelationship];
|
|
179
186
|
}
|
|
180
187
|
|
|
188
|
+
|
|
189
|
+
|
|
181
190
|
// Update objectRelationships object
|
|
182
191
|
if (objectRelationships[node.objType.objectType]) {
|
|
183
192
|
objectRelationships[node.objType.objectType].objType = node.objType;
|
|
@@ -219,7 +228,7 @@ async function _processObjectLinksGroup(_izContext, relationshipTag, objectLinks
|
|
|
219
228
|
_izContext.logger.error('Depth limit reached:', loopSetting.depth);
|
|
220
229
|
return {
|
|
221
230
|
success: false,
|
|
222
|
-
errorMessage: `relTag: ${
|
|
231
|
+
errorMessage: `relTag: ${relationshipTag} - Depth limit`
|
|
223
232
|
};
|
|
224
233
|
}
|
|
225
234
|
|
|
@@ -298,6 +307,8 @@ async function _processObjectLinksGroup(_izContext, relationshipTag, objectLinks
|
|
|
298
307
|
link.to.objType.objectType === secondNode.objType.objectType
|
|
299
308
|
));
|
|
300
309
|
_izContext.logger.debug('existingLink:', existingLink);
|
|
310
|
+
|
|
311
|
+
|
|
301
312
|
if (existingLink) {
|
|
302
313
|
// Create detailed property comparison for better debugging
|
|
303
314
|
const propertyComparison = {
|
|
@@ -321,16 +332,6 @@ async function _processObjectLinksGroup(_izContext, relationshipTag, objectLinks
|
|
|
321
332
|
requested: secondNode.requiredOnCreate,
|
|
322
333
|
matches: existingLink.to.requiredOnCreate === secondNode.requiredOnCreate
|
|
323
334
|
},
|
|
324
|
-
fromHandler: {
|
|
325
|
-
current: existingLink.from.handler,
|
|
326
|
-
requested: firstNode.handler,
|
|
327
|
-
matches: firstNode.handler === undefined || existingLink.from.handler === firstNode.handler
|
|
328
|
-
},
|
|
329
|
-
toHandler: {
|
|
330
|
-
current: existingLink.to.handler,
|
|
331
|
-
requested: secondNode.handler,
|
|
332
|
-
matches: secondNode.handler === undefined || existingLink.to.handler === secondNode.handler
|
|
333
|
-
},
|
|
334
335
|
canDelete: {
|
|
335
336
|
current: existingLink.canDelete,
|
|
336
337
|
requested: canDelete,
|
|
@@ -381,7 +382,10 @@ async function _processObjectLinksGroup(_izContext, relationshipTag, objectLinks
|
|
|
381
382
|
}
|
|
382
383
|
|
|
383
384
|
// Update existing link
|
|
384
|
-
relationshipSchema.links = relationshipSchema.links.filter(link =>
|
|
385
|
+
relationshipSchema.links = relationshipSchema.links.filter(link => {
|
|
386
|
+
_izContext.logger.debug('compare exists link:', link !== existingLink);
|
|
387
|
+
return link !== existingLink
|
|
388
|
+
});
|
|
385
389
|
|
|
386
390
|
// Create updated link with merged tags
|
|
387
391
|
newLinkRelSchema = {
|
|
@@ -394,13 +398,11 @@ async function _processObjectLinksGroup(_izContext, relationshipTag, objectLinks
|
|
|
394
398
|
...existingLink.from,
|
|
395
399
|
linkType: firstNode.linkType,
|
|
396
400
|
requiredOnCreate: firstNode.requiredOnCreate,
|
|
397
|
-
handler: firstNode.handler || existingLink.from.handler,
|
|
398
401
|
},
|
|
399
402
|
to: {
|
|
400
403
|
...existingLink.to,
|
|
401
404
|
linkType: secondNode.linkType,
|
|
402
405
|
requiredOnCreate: secondNode.requiredOnCreate,
|
|
403
|
-
handler: secondNode.handler || existingLink.to.handler
|
|
404
406
|
},
|
|
405
407
|
canDelete: canDelete
|
|
406
408
|
};
|
|
@@ -411,13 +413,11 @@ async function _processObjectLinksGroup(_izContext, relationshipTag, objectLinks
|
|
|
411
413
|
from: {
|
|
412
414
|
objType: firstNode.objType,
|
|
413
415
|
linkType: firstNode.linkType,
|
|
414
|
-
handler: firstNode.handler || false,
|
|
415
416
|
requiredOnCreate: firstNode.requiredOnCreate,
|
|
416
417
|
},
|
|
417
418
|
to: {
|
|
418
419
|
objType: secondNode.objType,
|
|
419
420
|
linkType: secondNode.linkType,
|
|
420
|
-
handler: secondNode.handler || false,
|
|
421
421
|
requiredOnCreate: secondNode.requiredOnCreate,
|
|
422
422
|
},
|
|
423
423
|
canDelete: canDelete
|
|
@@ -438,10 +438,10 @@ async function _processObjectLinksGroup(_izContext, relationshipTag, objectLinks
|
|
|
438
438
|
// Build link object structure
|
|
439
439
|
const link = {
|
|
440
440
|
relType: {
|
|
441
|
-
storageResourceTags: storageResourceTags,
|
|
442
441
|
relationshipTag: relType.relationshipTag,
|
|
443
442
|
serviceTag: relType.serviceTag
|
|
444
443
|
},
|
|
444
|
+
storageResourceTags: storageResourceTags,
|
|
445
445
|
from: newLinkRelSchema.from,
|
|
446
446
|
to: newLinkRelSchema.to,
|
|
447
447
|
canDelete: newLinkRelSchema.canDelete,
|
|
@@ -546,7 +546,47 @@ async function _processObjectLinksGroup(_izContext, relationshipTag, objectLinks
|
|
|
546
546
|
{ depth: loopSetting.depth + 1 }
|
|
547
547
|
)
|
|
548
548
|
}
|
|
549
|
-
|
|
549
|
+
|
|
550
|
+
//TODO: need fix bug that make duplicate relationship
|
|
551
|
+
// filter out duplicate relationships inside objectRelationships
|
|
552
|
+
|
|
553
|
+
let newObjectRelationships = {};
|
|
554
|
+
|
|
555
|
+
for (let [objectType, { objType, relationships }] of Object.entries(objectRelationships)) {
|
|
556
|
+
_izContext.logger.debug('objectRelationships length:', relationships.length);
|
|
557
|
+
|
|
558
|
+
if (!newObjectRelationships[objectType]) {
|
|
559
|
+
newObjectRelationships[objectType] = {
|
|
560
|
+
objType: objType,
|
|
561
|
+
relationships: []
|
|
562
|
+
};
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
|
|
566
|
+
let relationshipsHash = new Set()
|
|
567
|
+
let newRelationships = []
|
|
568
|
+
|
|
569
|
+
for (let relationship of relationships) {
|
|
570
|
+
|
|
571
|
+
if (Array.isArray(relationship.storageResourceTags)) {
|
|
572
|
+
relationship.storageResourceTags = relationship.storageResourceTags.sort();
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
if (!relationshipsHash.has(hash(relationship))) {
|
|
576
|
+
relationshipsHash.add(hash(relationship));
|
|
577
|
+
|
|
578
|
+
newRelationships.push(relationship);
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
newObjectRelationships[objectType].relationships = newRelationships
|
|
583
|
+
_izContext.logger.debug('newRelationships length:', newRelationships.length);
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
// _izContext.logger.debug('objectRelationships after modify: ', newObjectRelationships);
|
|
587
|
+
|
|
588
|
+
|
|
589
|
+
const objectRelationshipPromises = Object.values(newObjectRelationships).map(({ objType, relationships }) =>
|
|
550
590
|
uploadObjectToS3(
|
|
551
591
|
_izContext,
|
|
552
592
|
UPLOAD_PATH_S3.objectRelationship(_izContext, objType),
|
|
@@ -557,6 +597,8 @@ async function _processObjectLinksGroup(_izContext, relationshipTag, objectLinks
|
|
|
557
597
|
try {
|
|
558
598
|
// TODO-Part: Upload new LinkTypeId
|
|
559
599
|
_izContext.logger.debug('Uploading new LinkTypeId & ObjectRelationships...');
|
|
600
|
+
|
|
601
|
+
|
|
560
602
|
const uploadPromises = [
|
|
561
603
|
...linkByLinkTypeIds.map(({ linkTypeId, link }) =>
|
|
562
604
|
uploadObjectToS3(
|
package/src/UploadObjSchema.js
CHANGED
|
@@ -328,7 +328,6 @@ async function uploadObjectSchemaByUseCase(_izContext) {
|
|
|
328
328
|
}
|
|
329
329
|
|
|
330
330
|
// upload to refObjectRelationships for each objectType that have createBy at UserAccount Service and belongTo
|
|
331
|
-
// upload
|
|
332
331
|
let existsRefObjectRel = refRelationshipPerObjectType[objSchema.objectType];
|
|
333
332
|
if (existsRefObjectRel) {
|
|
334
333
|
Object.assign(existsRefObjectRel, await refRelationshipPerObjectSchema(_izContext, objSchema));
|
|
@@ -346,6 +345,12 @@ async function uploadObjectSchemaByUseCase(_izContext) {
|
|
|
346
345
|
)
|
|
347
346
|
)
|
|
348
347
|
} else {
|
|
348
|
+
// add new rule if objectType is not have storageType graph not upload to refObjectRelationships
|
|
349
|
+
if (!objSchema.storageResources || !Object.values(objSchema.storageResources)
|
|
350
|
+
.some(storageResource => storageResource.storageType === STORAGE_TYPES.graph)) {
|
|
351
|
+
continue;
|
|
352
|
+
}
|
|
353
|
+
|
|
349
354
|
uploadList.push(
|
|
350
355
|
uploadObjectToS3(
|
|
351
356
|
_izContext,
|
package/src/Utils.js
CHANGED
|
@@ -389,6 +389,7 @@ function validateRelationshipSchema(_izContext, relationshipSchema) {
|
|
|
389
389
|
}
|
|
390
390
|
|
|
391
391
|
} else {
|
|
392
|
+
_izContext.logger.debug("validateStatus: ", validateStatus.error);
|
|
392
393
|
validateStatus.error = `Relationship:${relationshipTag}, ` + validateStatus.error
|
|
393
394
|
return [false, validateStatus.error.split(",")]
|
|
394
395
|
}
|
package/src/ValidatorSchema.js
CHANGED
|
@@ -930,6 +930,8 @@ async function validateLocalSchema(_izContext, schemasPath, serviceConfigPath) {
|
|
|
930
930
|
const allObjectRelationships = getAllLocalRelationshipSchema(_izContext, schemasPath);
|
|
931
931
|
const allReferenceObjectRelationships = getAllLocalRefObjectRelationshipSchema(_izContext, schemasPath);
|
|
932
932
|
const allFlowSchemas = await getAllLocalFlowSchemas(_izContext, schemasPath).then(res => res.records);
|
|
933
|
+
console.log("allFlowSchemas", allFlowSchemas);
|
|
934
|
+
|
|
933
935
|
|
|
934
936
|
// validate all schema
|
|
935
937
|
for (const objSchema of allObjectSchema) {
|
|
@@ -104,7 +104,7 @@ function validateGraphServerTags(graphServerTags, relationshipSchema, firstNodeO
|
|
|
104
104
|
|
|
105
105
|
// Get all unique graphServerTags from schemas
|
|
106
106
|
const getGraphTags = schema =>
|
|
107
|
-
new Set(Object.values(schema
|
|
107
|
+
new Set(Object.values(schema?.storageResources || {})
|
|
108
108
|
.filter(resource => resource.storageType !== 'dynamoDB')
|
|
109
109
|
.map(resource => {
|
|
110
110
|
if (resource.storageType === 'graph') {
|
package/src/libs/s3Utils.js
CHANGED
|
@@ -28,7 +28,9 @@ const {
|
|
|
28
28
|
PutObjectCommand,
|
|
29
29
|
} = require("@aws-sdk/client-s3");
|
|
30
30
|
|
|
31
|
-
const
|
|
31
|
+
const hash = require('object-hash');
|
|
32
|
+
|
|
33
|
+
const { NoRetryError, inMemoryCacheLib } = require('@izara_project/izara-core-library-core');
|
|
32
34
|
const { SCHEMA_NAME_PER_S3_PATH } = require('@izara_project/izara-shared-service-schemas').consts;
|
|
33
35
|
const { OBJECT_SCHEMA_BUCKET_NAME } = require('../Consts');
|
|
34
36
|
|
|
@@ -80,6 +82,21 @@ async function getSchemaByName(params) {
|
|
|
80
82
|
return objectSchema;
|
|
81
83
|
}
|
|
82
84
|
|
|
85
|
+
/**
|
|
86
|
+
* Caches the getSchemaByName function
|
|
87
|
+
*
|
|
88
|
+
* @see {@link getSchemaByName}
|
|
89
|
+
*/
|
|
90
|
+
const getSchemaByNameWithCache = inMemoryCacheLib(
|
|
91
|
+
getSchemaByName, // fn
|
|
92
|
+
{ // setting
|
|
93
|
+
max: 100, maxAge: 86400000, promise: true, profileName: 'getSchemaByName',
|
|
94
|
+
normalizer: function (args) {
|
|
95
|
+
return hash([args[0]])
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
)
|
|
99
|
+
|
|
83
100
|
|
|
84
101
|
async function getObjectS3(_izContext, param) {
|
|
85
102
|
return await getObjectS3Shared(param);
|
|
@@ -131,5 +148,6 @@ module.exports = {
|
|
|
131
148
|
deleteObject,
|
|
132
149
|
putObjectS3,
|
|
133
150
|
deleteObjects,
|
|
134
|
-
getSchemaByName
|
|
151
|
+
getSchemaByName,
|
|
152
|
+
getSchemaByNameWithCache
|
|
135
153
|
}
|