@izara_project/izara-core-library-service-schemas 1.0.57 → 1.0.59
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 +4 -4
- package/src/SharedUtils.js +13 -4
- package/src/UploadObjSchema.js +40 -29
- package/src/libs/UploadUseCase.js +39 -100
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.59",
|
|
4
4
|
"description": "Schemas for the service and objects it controls",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -23,11 +23,11 @@
|
|
|
23
23
|
"@aws-sdk/client-lambda": "^3.787.0",
|
|
24
24
|
"@aws-sdk/client-s3": "^3.787.0",
|
|
25
25
|
"@aws-sdk/crc64-nvme-crt": "^3.787.0",
|
|
26
|
-
"@izara_project/izara-core-library-core": "^1.0.
|
|
27
|
-
"@izara_project/izara-core-library-external-request": "^1.0.
|
|
26
|
+
"@izara_project/izara-core-library-core": "^1.0.19",
|
|
27
|
+
"@izara_project/izara-core-library-external-request": "^1.0.19",
|
|
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.
|
|
30
|
+
"@izara_project/izara-shared-service-schemas": "^1.0.10",
|
|
31
31
|
"glob": "^11.0.1",
|
|
32
32
|
"lodash": "^4.17.21",
|
|
33
33
|
"object-hash": "^3.0.0",
|
package/src/SharedUtils.js
CHANGED
|
@@ -251,7 +251,9 @@ async function _processObjectLinksGroup(_izContext, relationshipTag, objectLinks
|
|
|
251
251
|
firstNode: false,
|
|
252
252
|
secondNode: false,
|
|
253
253
|
};
|
|
254
|
-
let { firstNode, secondNode, graphServerTags, direction, settings } = objectLink;
|
|
254
|
+
let { firstNode, secondNode, graphServerTags, direction, settings, canDelete } = objectLink;
|
|
255
|
+
|
|
256
|
+
canDelete = canDelete || false;
|
|
255
257
|
|
|
256
258
|
try {
|
|
257
259
|
// check direction if direction is 'to' then swap firstNode and secondNode
|
|
@@ -328,6 +330,11 @@ async function _processObjectLinksGroup(_izContext, relationshipTag, objectLinks
|
|
|
328
330
|
current: existingLink.to.handler,
|
|
329
331
|
requested: secondNode.handler,
|
|
330
332
|
matches: secondNode.handler === undefined || existingLink.to.handler === secondNode.handler
|
|
333
|
+
},
|
|
334
|
+
canDelete: {
|
|
335
|
+
current: existingLink.canDelete,
|
|
336
|
+
requested: canDelete,
|
|
337
|
+
matches: existingLink.canDelete === canDelete
|
|
331
338
|
}
|
|
332
339
|
};
|
|
333
340
|
|
|
@@ -394,7 +401,8 @@ async function _processObjectLinksGroup(_izContext, relationshipTag, objectLinks
|
|
|
394
401
|
linkType: secondNode.linkType,
|
|
395
402
|
requiredOnCreate: secondNode.requiredOnCreate,
|
|
396
403
|
handler: secondNode.handler || existingLink.to.handler
|
|
397
|
-
}
|
|
404
|
+
},
|
|
405
|
+
canDelete: canDelete
|
|
398
406
|
};
|
|
399
407
|
} else {
|
|
400
408
|
// Create new link
|
|
@@ -412,7 +420,7 @@ async function _processObjectLinksGroup(_izContext, relationshipTag, objectLinks
|
|
|
412
420
|
handler: secondNode.handler || false,
|
|
413
421
|
requiredOnCreate: secondNode.requiredOnCreate,
|
|
414
422
|
},
|
|
415
|
-
canDelete:
|
|
423
|
+
canDelete: canDelete
|
|
416
424
|
};
|
|
417
425
|
}
|
|
418
426
|
_izContext.logger.debug('newLinkRelSchema:', newLinkRelSchema);
|
|
@@ -435,7 +443,8 @@ async function _processObjectLinksGroup(_izContext, relationshipTag, objectLinks
|
|
|
435
443
|
serviceTag: relType.serviceTag
|
|
436
444
|
},
|
|
437
445
|
from: newLinkRelSchema.from,
|
|
438
|
-
to: newLinkRelSchema.to
|
|
446
|
+
to: newLinkRelSchema.to,
|
|
447
|
+
canDelete: newLinkRelSchema.canDelete,
|
|
439
448
|
};
|
|
440
449
|
_izContext.logger.debug('linkTypeId:', linkTypeId);
|
|
441
450
|
_izContext.logger.debug('link:', link);
|
package/src/UploadObjSchema.js
CHANGED
|
@@ -62,7 +62,6 @@ const {
|
|
|
62
62
|
generateLinksDataPerLinkTypeId,
|
|
63
63
|
groupRefObjectRelPerObjectType,
|
|
64
64
|
|
|
65
|
-
generateCreatedByLinks,
|
|
66
65
|
refRelationshipPerObjectSchema
|
|
67
66
|
} = require('./libs/UploadUseCase');
|
|
68
67
|
|
|
@@ -177,6 +176,9 @@ async function uploadObjectSchemaByUseCase(_izContext) {
|
|
|
177
176
|
|
|
178
177
|
const allObjectRelationships = getAllLocalRelationshipSchema(_izContext)
|
|
179
178
|
const allReferenceObjectRelationships = getAllLocalRefObjectRelationshipSchema(_izContext)
|
|
179
|
+
let refRelationshipPerObjectType = groupRefObjectRelPerObjectType(_izContext, allReferenceObjectRelationships);
|
|
180
|
+
_izContext.logger.debug("refRelationshipPerObjectType: ", refRelationshipPerObjectType);
|
|
181
|
+
|
|
180
182
|
|
|
181
183
|
const lambdaFunctions = await getLambdaFunctionNames(_izContext);
|
|
182
184
|
_izContext.logger.debug("lambdaFunctions: ", lambdaFunctions);
|
|
@@ -326,29 +328,24 @@ async function uploadObjectSchemaByUseCase(_izContext) {
|
|
|
326
328
|
}
|
|
327
329
|
|
|
328
330
|
// upload to refObjectRelationships for each objectType that have createBy at UserAccount Service and belongTo
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
for (const [refRelObjType, refRelData] of Object.entries(refRelationshipData)) {
|
|
334
|
-
let refObjectTypeIndex = allObjectSchemasResult.fieldLookup[refRelObjType];
|
|
335
|
-
Object.assign(refRelData, await refRelationshipPerObjectSchema(_izContext, allObjectSchema[refObjectTypeIndex]));
|
|
331
|
+
// upload
|
|
332
|
+
let existsRefObjectRel = refRelationshipPerObjectType[objSchema.objectType];
|
|
333
|
+
if (existsRefObjectRel) {
|
|
334
|
+
Object.assign(existsRefObjectRel, await refRelationshipPerObjectSchema(_izContext, objSchema));
|
|
336
335
|
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
)
|
|
336
|
+
uploadList.push(
|
|
337
|
+
uploadObjectToS3(
|
|
338
|
+
_izContext,
|
|
339
|
+
UPLOAD_PATH_S3.refObjectRelationship(_izContext,
|
|
340
|
+
{
|
|
341
|
+
objectType: objSchema.objectType,
|
|
342
|
+
serviceTag: process.env.iz_serviceTag
|
|
343
|
+
}
|
|
344
|
+
),
|
|
345
|
+
existsRefObjectRel
|
|
348
346
|
)
|
|
349
|
-
|
|
347
|
+
)
|
|
350
348
|
} else {
|
|
351
|
-
_izContext.logger.debug("not have refRelationship add createdBy and belongTo(if have) to RefRelationship")
|
|
352
349
|
uploadList.push(
|
|
353
350
|
uploadObjectToS3(
|
|
354
351
|
_izContext,
|
|
@@ -377,8 +374,10 @@ async function uploadObjectSchemaByUseCase(_izContext) {
|
|
|
377
374
|
|
|
378
375
|
let belongsTo = [];
|
|
379
376
|
let createdBys = [];
|
|
377
|
+
let translations = [];
|
|
380
378
|
|
|
381
379
|
// invoke AddBelongTo in userAccount to upload belongTo Relationships
|
|
380
|
+
// prepare params for invoke AddLinkToTranslationLinksHdrInv
|
|
382
381
|
for (const objectSchema of allObjectSchema) {
|
|
383
382
|
let graphServerTags = new Set();
|
|
384
383
|
|
|
@@ -412,6 +411,18 @@ async function uploadObjectSchemaByUseCase(_izContext) {
|
|
|
412
411
|
}
|
|
413
412
|
)
|
|
414
413
|
};
|
|
414
|
+
|
|
415
|
+
if (objectSchema?.addOnDataStructure?.length) {
|
|
416
|
+
if (objectSchema.addOnDataStructure.some(addOnData => addOnData.type === "translation") && graphServerTags.size) {
|
|
417
|
+
translations.push({
|
|
418
|
+
objType: {
|
|
419
|
+
objectType: objectSchema.objectType,
|
|
420
|
+
serviceTag: process.env.iz_serviceTag
|
|
421
|
+
},
|
|
422
|
+
graphServerTags: [...graphServerTags]
|
|
423
|
+
})
|
|
424
|
+
}
|
|
425
|
+
}
|
|
415
426
|
};
|
|
416
427
|
|
|
417
428
|
|
|
@@ -434,14 +445,14 @@ async function uploadObjectSchemaByUseCase(_izContext) {
|
|
|
434
445
|
}
|
|
435
446
|
|
|
436
447
|
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
448
|
+
if (translations.length && process.env.iz_serviceTag !== "Translations") {
|
|
449
|
+
await lambda.invokeSync(_izContext,
|
|
450
|
+
await lambdaSharedLib.lambdaFunctionName(_izContext, "AddLinkToTranslationLinksHdrInv", "Translations"),
|
|
451
|
+
{
|
|
452
|
+
linksData: translations
|
|
453
|
+
}
|
|
454
|
+
)
|
|
455
|
+
}
|
|
445
456
|
|
|
446
457
|
// ------------ Upload Relationship ------------------
|
|
447
458
|
if (allObjectRelationships) {
|
|
@@ -427,114 +427,54 @@ function groupRefObjectRelPerObjectType(_izContext, allRefObjectRelationships) {
|
|
|
427
427
|
return refRelPerObjectType;
|
|
428
428
|
}
|
|
429
429
|
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
*
|
|
433
|
-
* @param {object} _izContext
|
|
434
|
-
* @param {object[]} objectTypes - objectTypes that need to add in createdByLink
|
|
435
|
-
* @returns
|
|
436
|
-
*/
|
|
437
|
-
async function generateCreatedByLinks(_izContext, addObjectTypes) {
|
|
438
|
-
|
|
439
|
-
// modify createdBy relSchema
|
|
440
|
-
const relTagPath = UPLOAD_PATH_S3.relationshipTag(
|
|
441
|
-
_izContext,
|
|
442
|
-
{
|
|
443
|
-
serviceTag: "UserAccount",
|
|
444
|
-
relationshipTag: "createdBy"
|
|
445
|
-
},
|
|
446
|
-
);
|
|
447
|
-
|
|
448
|
-
const getObjRelPathParam = {
|
|
449
|
-
Bucket: OBJECT_SCHEMA_BUCKET_NAME,
|
|
450
|
-
Key: relTagPath
|
|
451
|
-
};
|
|
452
|
-
|
|
453
|
-
// let createdByRelSchema = await s3.getObject(getObjRelPathParam).promise()
|
|
454
|
-
// .catch(error => {
|
|
455
|
-
// if (error.code === "NoSuchKey") {
|
|
456
|
-
// return {}
|
|
457
|
-
// } else {
|
|
458
|
-
// _izContext.logger.error(error);
|
|
459
|
-
// throw new NoRetryError(error);
|
|
460
|
-
// }
|
|
461
|
-
// });
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
let [createdByRelSchema, s3Response] = await getObjectS3(_izContext, getObjRelPathParam) || {};
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
_izContext.logger.debug("createdByRelSchema ETag: ", s3Response.ETag)
|
|
469
|
-
_izContext.logger.debug("createdByRelSchema: ", createdByRelSchema)
|
|
470
|
-
|
|
471
|
-
// let createdByRelSchemaObj = createdByRelSchema.Body ? JSON.parse(createdByRelSchema.Body.toString('utf-8')) : null;
|
|
430
|
+
async function refRelationshipPerObjectSchema(_izContext, objSchema) {
|
|
431
|
+
_izContext.logger.debug('refObjectRelationshipCreate Libs:: ', objSchema)
|
|
472
432
|
|
|
433
|
+
let refObjectRel = {};
|
|
473
434
|
|
|
474
|
-
if (createdByRelSchema?.links?.length) {
|
|
475
435
|
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
436
|
+
if (objSchema.hasOwnProperty("belongTo")) {
|
|
437
|
+
Object.assign(
|
|
438
|
+
refObjectRel,
|
|
439
|
+
{
|
|
440
|
+
"createdBy": {
|
|
441
|
+
relationshipServiceTag: "UserAccount"
|
|
442
|
+
},
|
|
443
|
+
"belongTo": {
|
|
444
|
+
relationshipServiceTag: "UserAccount"
|
|
445
|
+
}
|
|
480
446
|
}
|
|
481
|
-
|
|
447
|
+
)
|
|
448
|
+
} else {
|
|
449
|
+
Object.assign(
|
|
450
|
+
refObjectRel,
|
|
451
|
+
{
|
|
452
|
+
"createdBy": {
|
|
453
|
+
relationshipServiceTag: "UserAccount"
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
)
|
|
457
|
+
}
|
|
482
458
|
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
objType: { serviceTag: process.env.iz_serviceTag, objectType: localObjType },
|
|
490
|
-
linkType: 'many',
|
|
491
|
-
handler: true,
|
|
492
|
-
requiredOnCreate: false
|
|
493
|
-
},
|
|
494
|
-
to: {
|
|
495
|
-
objType: { serviceTag: 'UserAccount', objectType: 'user' },
|
|
496
|
-
linkType: 'one',
|
|
497
|
-
handler: false,
|
|
498
|
-
requiredOnCreate: false
|
|
499
|
-
}
|
|
459
|
+
if (objSchema?.addOnDataStructure?.length && objSchema.addOnDataStructure.some(addOn => addOn.type === "translation")) {
|
|
460
|
+
Object.assign(
|
|
461
|
+
refObjectRel,
|
|
462
|
+
{
|
|
463
|
+
hasTranslationLink: {
|
|
464
|
+
relationshipServiceTag: "Translations",
|
|
500
465
|
},
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
// check ETag before return
|
|
510
|
-
const createdByRelHead = await headObjectS3(_izContext, getObjRelPathParam);
|
|
511
|
-
_izContext.logger.debug("createdByRelHead: ", createdByRelHead);
|
|
512
|
-
|
|
513
|
-
if (createdByRelHead.ETag === s3Response.ETag) {
|
|
514
|
-
return createdByRelSchema;
|
|
515
|
-
}
|
|
466
|
+
currentTranslationLink: {
|
|
467
|
+
relationshipServiceTag: "Translations",
|
|
468
|
+
},
|
|
469
|
+
defaultTranslationLink: {
|
|
470
|
+
relationshipServiceTag: "Translations",
|
|
471
|
+
},
|
|
472
|
+
}
|
|
473
|
+
)
|
|
516
474
|
}
|
|
517
475
|
|
|
518
|
-
}
|
|
519
476
|
|
|
520
|
-
|
|
521
|
-
_izContext.logger.debug('refObjectRelationshipCreate Libs:: ', objSchema)
|
|
522
|
-
if (objSchema.hasOwnProperty("belongTo")) {
|
|
523
|
-
return {
|
|
524
|
-
"createdBy": {
|
|
525
|
-
relationshipServiceTag: "UserAccount"
|
|
526
|
-
},
|
|
527
|
-
"belongTo": {
|
|
528
|
-
relationshipServiceTag: "UserAccount"
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
} else {
|
|
532
|
-
return {
|
|
533
|
-
"createdBy": {
|
|
534
|
-
relationshipServiceTag: "UserAccount"
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
}
|
|
477
|
+
return refObjectRel;
|
|
538
478
|
}
|
|
539
479
|
|
|
540
480
|
|
|
@@ -550,6 +490,5 @@ module.exports = {
|
|
|
550
490
|
DEFAULT_REL_ID_SETTING,
|
|
551
491
|
|
|
552
492
|
// external service
|
|
553
|
-
generateCreatedByLinks,
|
|
554
493
|
refRelationshipPerObjectSchema
|
|
555
494
|
};
|