@izara_project/izara-core-library-service-schemas 1.0.58 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@izara_project/izara-core-library-service-schemas",
3
- "version": "1.0.58",
3
+ "version": "1.0.59",
4
4
  "description": "Schemas for the service and objects it controls",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -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
- if (allReferenceObjectRelationships.length) {
330
- _izContext.logger.debug("have refRelationship add createdBy and belongTo(if have) to RefRelationship")
331
- let refRelationshipData = groupRefObjectRelPerObjectType(_izContext, allReferenceObjectRelationships);
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
- uploadList.push(
338
- uploadObjectToS3(
339
- _izContext,
340
- UPLOAD_PATH_S3.refObjectRelationship(_izContext,
341
- {
342
- objectType: refRelObjType,
343
- serviceTag: process.env.iz_serviceTag
344
- }
345
- ),
346
- refRelData
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
- // uploadList.push(
438
- // uploadObjectToS3(
439
- // _izContext,
440
- // UPLOAD_PATH_S3.objectListCreate(_izContext, process.env.iz_serviceTag),
441
- // objectTypesForCreate
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
- * return new createdBy links of service UserAccount
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
- let newLinks = [];
477
- for (const linkData of createdByRelSchema.links) {
478
- if (linkData.from.objType.serviceTag !== process.env.iz_serviceTag) {
479
- newLinks.push(linkData)
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
- // add link for local objectType
484
- for (const localObjType of addObjectTypes) {
485
- newLinks.push(
486
- {
487
- storageResourceTags: Object.keys(createdByRelSchema.storageResources),
488
- from: {
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
- _izContext.logger.debug("result newLinks: ", newLinks);
505
-
506
- // new createdBy relationship schema
507
- Object.assign(createdByRelSchema, { links: newLinks });
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
- async function refRelationshipPerObjectSchema(_izContext, objSchema) {
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
  };