@izara_project/izara-core-library-service-schemas 1.0.100 → 1.0.101

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.
@@ -17,13 +17,13 @@ along with this program.If not, see < http://www.gnu.org/licenses/>.
17
17
 
18
18
  'use strict';
19
19
 
20
- const NoRetryError = require('@izara_project/izara-core-library-core/src/NoRetryError');
21
- const { validateObjType } = require('@izara_project/izara-shared-service-schemas').validateObjType;
20
+ import { NoRetryError } from '@izara_project/izara-core-library-core';
21
+ import { validateObjType } from '@izara_project/izara-shared-service-schemas';
22
22
 
23
- const deliminatorTree = require('./libs/DeliminatorTree');
24
- const getSchema = require('./GetObjectSchema')
25
- const { getUsedFieldNamesOfIdentifiers } = require('./Utils');
26
- const { STORAGE_TYPES, STORAGE_IDENTIFIER_TYPES, DEFAULT_IDENTIFIER_DELIMINATOR } = require('./Consts');
23
+ import deliminatorTree from './libs/DeliminatorTree.js';
24
+ import getSchema from './GetObjectSchema.js';
25
+ import utils from './Utils.js';
26
+ import consts from './Consts.js';
27
27
 
28
28
 
29
29
  /**
@@ -38,7 +38,7 @@ const { STORAGE_TYPES, STORAGE_IDENTIFIER_TYPES, DEFAULT_IDENTIFIER_DELIMINATOR
38
38
  function checkStorageTypeOfObjectSchemaIdentifiers(_izContext, objectSchema) {
39
39
 
40
40
  let objectSchemaStorageType;
41
- for (const [storageType, identifierTypes] of Object.entries(STORAGE_IDENTIFIER_TYPES)) {
41
+ for (const [storageType, identifierTypes] of Object.entries(consts.STORAGE_IDENTIFIER_TYPES)) {
42
42
  if (identifierTypes.includes(objectSchema.identifiers[0].type)) {
43
43
  objectSchemaStorageType = storageType
44
44
  }
@@ -59,7 +59,7 @@ function checkStorageTypeOfObjectSchemaIdentifiers(_izContext, objectSchema) {
59
59
  * @returns {Promise<Object>} - identifiersObject
60
60
  */
61
61
  async function identifiersFromObjInstanceBase(_izContext, objType, objInstanceBase, bucketName = process.env.iz_serviceSchemaBucketName) {
62
- const validateObjTypeResult = validateObjType(objType);
62
+ const validateObjTypeResult = validateObjType.validateObjType(objType);
63
63
  if (validateObjTypeResult.errorsFound.length > 0) {
64
64
  _izContext.logger.error("identifiersObjectFromBaseObjInstance: Invalid objType: ", validateObjTypeResult.errorsFound);
65
65
  throw new NoRetryError(`identifiersObjectFromBaseObjInstance: Invalid objType: ${validateObjTypeResult.errorsFound.join(', ')}`);
@@ -76,20 +76,20 @@ async function identifiersFromObjInstanceBase(_izContext, objType, objInstanceBa
76
76
  // check which baseObjInstance come from
77
77
  let storageOfBaseObjInstance;
78
78
 
79
- if (checkStorageTypeOfObjectSchemaIdentifiers(_izContext, objSchema) === STORAGE_TYPES.graph) {
79
+ if (checkStorageTypeOfObjectSchemaIdentifiers(_izContext, objSchema) === consts.STORAGE_TYPES.graph) {
80
80
  const graphIdentifierName = Object.keys(deliminatorTreeResult)[0];
81
81
 
82
82
  if (objInstanceBase.hasOwnProperty(graphIdentifierName)) {
83
- storageOfBaseObjInstance = STORAGE_TYPES.dynamoDB;
83
+ storageOfBaseObjInstance = consts.STORAGE_TYPES.dynamoDB;
84
84
  } else {
85
- storageOfBaseObjInstance = STORAGE_TYPES.graph;
85
+ storageOfBaseObjInstance = consts.STORAGE_TYPES.graph;
86
86
  }
87
87
  }
88
88
 
89
89
 
90
90
  let explodedResults = {};
91
91
  // overwrite deliminatorTree if found
92
- if (storageOfBaseObjInstance === STORAGE_TYPES.graph) {
92
+ if (storageOfBaseObjInstance === consts.STORAGE_TYPES.graph) {
93
93
  const identifierFieldNames = objSchema.identifiers[0].fieldNames || [objSchema.identifiers[0].fieldName];
94
94
 
95
95
  for (const identifierName of identifierFieldNames) {
@@ -145,7 +145,7 @@ async function identifiersFromObjInstanceBase(_izContext, objType, objInstanceBa
145
145
  * @returns {Promise<Object>} - concatIdentifiersObject
146
146
  */
147
147
  async function identifiersBaseFromIdentifiers(_izContext, objType, identifiers, bucketName = process.env.iz_serviceSchemaBucketName) {
148
- const validateObjTypeResult = validateObjType(objType);
148
+ const validateObjTypeResult = validateObjType.validateObjType(objType);
149
149
  if (validateObjTypeResult.errorsFound.length > 0) {
150
150
  _izContext.logger.error("identifiersBaseFromIdentifiers: Invalid objType: ", validateObjTypeResult.errorsFound);
151
151
  throw new NoRetryError(`identifiersBaseFromIdentifiers: Invalid objType: ${JSON.stringify(objType)}, ${validateObjTypeResult.errorsFound.join(", ")}`);
@@ -158,7 +158,7 @@ async function identifiersBaseFromIdentifiers(_izContext, objType, identifiers,
158
158
 
159
159
  // validate identifiersObject
160
160
  // maybe validate with all deliminatorTree instead of identifiersName
161
- const identifiersNames = getUsedFieldNamesOfIdentifiers(_izContext, objSchema.identifiers);
161
+ const identifiersNames = utils.getUsedFieldNamesOfIdentifiers(_izContext, objSchema.identifiers);
162
162
  _izContext.logger.debug("identifiersNames: ", identifiersNames);
163
163
 
164
164
  for (const identifierName of identifiersNames) {
@@ -201,7 +201,7 @@ async function identifiersBaseFromIdentifiers(_izContext, objType, identifiers,
201
201
  * @returns {Promise<Object>} - refactoredObjInstance
202
202
  */
203
203
  async function objInstanceFromObjInstanceBase(_izContext, objType, objInstance, bucketName = process.env.iz_serviceSchemaBucketName) {
204
- const validateObjTypeResult = validateObjType(objType);
204
+ const validateObjTypeResult = validateObjType.validateObjType(objType);
205
205
  if (validateObjTypeResult.errorsFound.length > 0) {
206
206
  _izContext.logger.error("objInstanceFromObjInstanceBase: Invalid objType: ", validateObjTypeResult.errorsFound);
207
207
  throw new NoRetryError(`objInstanceFromObjInstanceBase: Invalid objType: ${JSON.stringify(objType)}, ${validateObjTypeResult.errorsFound.join(", ")}`);
@@ -236,7 +236,7 @@ async function objInstanceFromObjInstanceBase(_izContext, objType, objInstance,
236
236
  * @returns {Promise<String>} - compositeIdentifier
237
237
  */
238
238
  async function identifiersConcatFromIdentifiers(_izContext, objType, identifiers, bucketName = process.env.iz_serviceSchemaBucketName) {
239
- const validateObjTypeResult = validateObjType(objType);
239
+ const validateObjTypeResult = validateObjType.validateObjType(objType);
240
240
  if (validateObjTypeResult.errorsFound.length > 0) {
241
241
  _izContext.logger.error("compositeIdentifierFromIdentifiersObject: Invalid objType: ", validateObjTypeResult.errorsFound);
242
242
  throw new NoRetryError(`compositeIdentifierFromIdentifiersObject: Invalid objType: ${JSON.stringify(objType)}, ${validateObjTypeResult.errorsFound.join(", ")}`);
@@ -250,7 +250,7 @@ async function identifiersConcatFromIdentifiers(_izContext, objType, identifiers
250
250
 
251
251
  // validate identifiersObject
252
252
  // maybe validate with all deliminatorTree instead of identifiersName
253
- const identifiersNames = getUsedFieldNamesOfIdentifiers(_izContext, objSchema.identifiers,);
253
+ const identifiersNames = utils.getUsedFieldNamesOfIdentifiers(_izContext, objSchema.identifiers,);
254
254
  _izContext.logger.debug("identifiersNames: ", identifiersNames);
255
255
 
256
256
  for (const identifierName of identifiersNames) {
@@ -334,7 +334,7 @@ async function identifiersConcatFromIdentifiers(_izContext, objType, identifiers
334
334
  * @returns {Promise<Object>} - identifiersObject
335
335
  */
336
336
  async function identifiersFromIdentifiersConcat(_izContext, objType, identifiersConcat, bucketName = process.env.iz_serviceSchemaBucketName) {
337
- const validateObjTypeResult = validateObjType(objType);
337
+ const validateObjTypeResult = validateObjType.validateObjType(objType);
338
338
  if (validateObjTypeResult.errorsFound.length > 0) {
339
339
  _izContext.logger.error("identifiersObjectFromCompositeIdentifier: Invalid objType: ", validateObjTypeResult.errorsFound);
340
340
  throw new NoRetryError(`identifiersObjectFromCompositeIdentifier: Invalid objType: ${JSON.stringify(objType)}, ${validateObjTypeResult.errorsFound.join(", ")}`);
@@ -435,7 +435,7 @@ async function createNestedIdentifiersConcat(
435
435
  prefixes = [],
436
436
  suffixes = [],
437
437
  level = 1,
438
- deliminator = DEFAULT_IDENTIFIER_DELIMINATOR,
438
+ deliminator = consts.DEFAULT_IDENTIFIER_DELIMINATOR,
439
439
  ) {
440
440
 
441
441
  const strNotEmptyRegex = /^[a-zA-Z0-9_-]+$/;
@@ -448,7 +448,7 @@ async function createNestedIdentifiersConcat(
448
448
  throw new NoRetryError(`one of prefixes and suffixes should exists`);
449
449
  }
450
450
 
451
- const validateObjTypeResult = validateObjType(objType);
451
+ const validateObjTypeResult = validateObjType.validateObjType(objType);
452
452
  if (validateObjTypeResult.errorsFound.length > 0) {
453
453
  _izContext.logger.error("createConcatIdentifier: Invalid objType: ", validateObjTypeResult.errorsFound);
454
454
  throw new NoRetryError(`createConcatIdentifier: Invalid objType: ${JSON.stringify(objType)}, ${validateObjTypeResult.errorsFound.join(", ")}`);
@@ -465,7 +465,7 @@ async function createNestedIdentifiersConcat(
465
465
  ? deliminatorTreeCompositeIdentifier.deliminatorList[deliminator]
466
466
  : 0;
467
467
 
468
- // start conatenate data
468
+ // start concatenate data
469
469
  const concatenatedIdentifier = [...prefixes, identifiersConcat, ...suffixes].join(deliminator.repeat(compositeDeliminatorAmount + level));
470
470
 
471
471
  return concatenatedIdentifier;
@@ -478,7 +478,7 @@ async function explodedNestedIdentifiersConcat(
478
478
  concatIdentifier,
479
479
  bucketName = process.env.iz_serviceSchemaBucketName,
480
480
  level = 1,
481
- deliminator = DEFAULT_IDENTIFIER_DELIMINATOR,
481
+ deliminator = consts.DEFAULT_IDENTIFIER_DELIMINATOR,
482
482
  ) {
483
483
 
484
484
  const strNotEmptyRegex = /^[a-zA-Z0-9_-]+$/;
@@ -487,7 +487,7 @@ async function explodedNestedIdentifiersConcat(
487
487
  throw new NoRetryError(`invalid compositeIdentifier`);
488
488
  }
489
489
 
490
- const validateObjTypeResult = validateObjType(objType);
490
+ const validateObjTypeResult = validateObjType.validateObjType(objType);
491
491
  if (validateObjTypeResult.errorsFound.length > 0) {
492
492
  _izContext.logger.error("explodedConcatIdentifier: Invalid objType: ", validateObjTypeResult.errorsFound);
493
493
  throw new NoRetryError(`explodedConcatIdentifier: Invalid objType: ${JSON.stringify(objType)}, ${validateObjTypeResult.errorsFound.join(", ")}`);
@@ -509,7 +509,7 @@ async function explodedNestedIdentifiersConcat(
509
509
 
510
510
 
511
511
 
512
- module.exports = {
512
+ export default {
513
513
  identifiersFromObjInstanceBase,
514
514
  identifiersBaseFromIdentifiers, // concatIdentifiersObjectFromIdentifiersObject
515
515
  objInstanceFromObjInstanceBase, // refactoredObjInstanceFromBaseObjInstance
@@ -17,16 +17,11 @@ along with this program.If not, see < http://www.gnu.org/licenses/>.
17
17
 
18
18
  'use strict';
19
19
 
20
- const hash = require('@izara_project/izara-shared-core').objectHash;
20
+ import { objectHash as hash } from '@izara_project/izara-shared-core';
21
21
 
22
- const { inMemoryCacheLib } = require('@izara_project/izara-core-library-core');
23
-
24
- const {
25
- OBJECT_SCHEMA_BUCKET_NAME,
26
- UPLOAD_PATH_S3,
27
- } = require('./Consts');
28
-
29
- const { getObjectS3 } = require("./libs/s3Utils")
22
+ import { inMemoryCacheLib } from '@izara_project/izara-core-library-core';
23
+ import consts from './Consts.js'
24
+ import s3Utils from "./libs/s3Utils.js"
30
25
 
31
26
  /**
32
27
  * get serviceName in s3 depend on serviceTag
@@ -42,12 +37,12 @@ async function getServiceName(
42
37
  _izContext.logger.debug("getServiceName: ", serviceTag)
43
38
 
44
39
  const getObjectParam = {
45
- Bucket: process.env.iz_serviceSchemaBucketName || OBJECT_SCHEMA_BUCKET_NAME,
46
- Key: UPLOAD_PATH_S3.serviceName(_izContext, serviceTag),
40
+ Bucket: process.env.iz_serviceSchemaBucketName || consts.OBJECT_SCHEMA_BUCKET_NAME,
41
+ Key: consts.UPLOAD_PATH_S3.serviceName(_izContext, serviceTag),
47
42
  };
48
43
  _izContext.logger.debug("getObjectParam", getObjectParam)
49
44
 
50
- const [bodyResponse] = await getObjectS3(_izContext, getObjectParam);
45
+ const [bodyResponse] = await s3Utils.getObjectS3(_izContext, getObjectParam);
51
46
 
52
47
  if (!bodyResponse) {
53
48
  return null;
@@ -82,15 +77,15 @@ const getServiceNameWithCache = inMemoryCacheLib(
82
77
  async function getGraphServiceTag(
83
78
  _izContext,
84
79
  graphServerTag,
85
- bucketName = process.env.iz_serviceSchemaBucketName || OBJECT_SCHEMA_BUCKET_NAME
80
+ bucketName = process.env.iz_serviceSchemaBucketName || consts.OBJECT_SCHEMA_BUCKET_NAME
86
81
  ) {
87
82
 
88
83
  // get all graph serverTag
89
- let [serverTags] = await getObjectS3(
84
+ let [serverTags] = await s3Utils.getObjectS3(
90
85
  _izContext,
91
86
  {
92
87
  Bucket: bucketName,
93
- Key: UPLOAD_PATH_S3.graphServerTagsConfig
88
+ Key: consts.UPLOAD_PATH_S3.graphServerTagsConfig
94
89
  }
95
90
  );
96
91
 
@@ -170,7 +165,7 @@ const getGraphServiceNameFromGraphServerTagWithCache = inMemoryCacheLib(
170
165
 
171
166
 
172
167
 
173
- module.exports = {
168
+ export default {
174
169
  getServiceName,
175
170
  getServiceNameWithCache,
176
171
 
@@ -17,20 +17,14 @@ along with this program.If not, see < http://www.gnu.org/licenses/>.
17
17
 
18
18
  'use strict';
19
19
 
20
- const hash = require('@izara_project/izara-shared-core').objectHash;
20
+ import { objectHash as hash } from '@izara_project/izara-shared-core';
21
+ import sharedUtilsLibs from './libs/SharedUtilsLibs.js'
22
+ import s3Utils from "./libs/s3Utils.js";
21
23
 
22
- const {
23
- validateGraphServerTags,
24
- mergeStorageResources,
25
- getStorageResources,
26
- validateObjectLinksInput
27
- } = require('./libs/SharedUtilsLibs');
28
- const { getObjectS3 } = require("./libs/s3Utils");
29
-
30
- const { getObjSchemaS3WithCache } = require("./GetObjectSchema");
31
- const { createLinkTypeId } = require('./Utils');
32
- const { uploadObjectToS3 } = require('./UploadObjSchema');
33
- const { OBJECT_SCHEMA_BUCKET_NAME, UPLOAD_PATH_S3 } = require('./Consts');
24
+ import getObjectSchema from './GetObjectSchema.js';
25
+ import utils from './Utils.js';
26
+ import uploadObjectToS3 from './UploadObjSchema.js';
27
+ import consts from './Consts.js'
34
28
 
35
29
  /**
36
30
  * Function to add links between objects
@@ -44,7 +38,7 @@ async function addLinks(_izContext, relationshipTag, objectLinks) {
44
38
  // objectLinks = { relType, firstNode, secondNode, graphServerTags, direction }
45
39
  try {
46
40
  // ** == validate input ==
47
- validateObjectLinksInput(objectLinks);
41
+ sharedUtilsLibs.validateObjectLinksInput(objectLinks);
48
42
 
49
43
  // ** == process each group of objectLinks ==
50
44
  const results = await _processObjectLinksGroup(
@@ -87,12 +81,12 @@ async function _processNodeRelationships(
87
81
 
88
82
  // Get object relationships from S3
89
83
  const getObjRelPathParam = {
90
- Bucket: bucketName ? bucketName : OBJECT_SCHEMA_BUCKET_NAME,
91
- Key: UPLOAD_PATH_S3.objectRelationship(_izContext, node.objType)
84
+ Bucket: bucketName ? bucketName : consts.OBJECT_SCHEMA_BUCKET_NAME,
85
+ Key: consts.UPLOAD_PATH_S3.objectRelationship(_izContext, node.objType)
92
86
  };
93
87
  _izContext.logger.debug('==> getObjRelPathParam:', getObjRelPathParam);
94
88
 
95
- const [objectRelationshipsArray] = await getObjectS3(_izContext, getObjRelPathParam);
89
+ const [objectRelationshipsArray] = await s3Utils.getObjectS3(_izContext, getObjRelPathParam);
96
90
  _izContext.logger.debug(`Object relationships for ${isBase ? 'base' : 'other'} node:`,
97
91
  JSON.stringify(objectRelationshipsArray, null, 2));
98
92
 
@@ -148,7 +142,7 @@ async function _processNodeRelationships(
148
142
 
149
143
  // Merge storage resources if available
150
144
  if (newLinkRelSchema.storageResources) {
151
- updatedObjRel.storageResources = mergeStorageResources(
145
+ updatedObjRel.storageResources = sharedUtilsLibs.mergeStorageResources(
152
146
  existingObjRel.storageResources || {},
153
147
  newLinkRelSchema.storageResources
154
148
  );
@@ -163,7 +157,7 @@ async function _processNodeRelationships(
163
157
  _izContext.logger.debug('=> CASE: No existing relationship found - create new one');
164
158
 
165
159
  // Create storage resources data
166
- const storageResourcesData = getStorageResources(relationshipSchema, storageResourceTags);
160
+ const storageResourcesData = sharedUtilsLibs.getStorageResources(relationshipSchema, storageResourceTags);
167
161
 
168
162
  // Create new relationship
169
163
  const newRelationship = {
@@ -238,11 +232,11 @@ async function _processObjectLinksGroup(_izContext, relationshipTag, objectLinks
238
232
  relationshipTag: relationshipTag,
239
233
  serviceTag: process.env.iz_serviceTag
240
234
  };
241
- const [relationshipSchema, rawRelationshipSchema] = await getObjectS3(
235
+ const [relationshipSchema, rawRelationshipSchema] = await s3Utils.getObjectS3(
242
236
  _izContext,
243
237
  {
244
238
  Bucket: process.env.iz_serviceSchemaBucketName,
245
- Key: UPLOAD_PATH_S3.relationshipTag(_izContext, relType)
239
+ Key: consts.UPLOAD_PATH_S3.relationshipTag(_izContext, relType)
246
240
  }
247
241
  );
248
242
  const ETagRelSchema = rawRelationshipSchema.ETag;
@@ -283,8 +277,8 @@ async function _processObjectLinksGroup(_izContext, relationshipTag, objectLinks
283
277
  _izContext.logger.debug('createObjectRelationshipConfig:', createObjectRelationshipConfig);
284
278
 
285
279
  // ** get object schema for firstNode and secondNode
286
- let firstNodeObjSchema = await getObjSchemaS3WithCache(_izContext, firstNode.objType);
287
- let secondNodeObjSchema = await getObjSchemaS3WithCache(_izContext, secondNode.objType);
280
+ let firstNodeObjSchema = await getObjectSchema.getObjSchemaS3WithCache(_izContext, firstNode.objType);
281
+ let secondNodeObjSchema = await getObjectSchema.getObjSchemaS3WithCache(_izContext, secondNode.objType);
288
282
  _izContext.logger.debug(`
289
283
  firstNodeObjSchema: ${JSON.stringify(firstNodeObjSchema, null, 2)}
290
284
  , secondNodeObjSchema: ${JSON.stringify(secondNodeObjSchema, null, 2)}`);
@@ -292,7 +286,7 @@ async function _processObjectLinksGroup(_izContext, relationshipTag, objectLinks
292
286
  // ? Validate the graph server tags
293
287
  // returns an array of error messages if validation fails
294
288
  // example: ['relationship schema missing tags: tag1, tag2', 'firstNode schema missing tags: tag3']
295
- const storageResourceTags = validateGraphServerTags(
289
+ const storageResourceTags = sharedUtilsLibs.validateGraphServerTags(
296
290
  graphServerTags,
297
291
  relationshipSchema,
298
292
  firstNodeObjSchema,
@@ -428,7 +422,7 @@ async function _processObjectLinksGroup(_izContext, relationshipTag, objectLinks
428
422
 
429
423
  // TODO-Part: Create LinkTypeId
430
424
  // Create linkTypeId for the relationship
431
- const linkTypeId = createLinkTypeId(
425
+ const linkTypeId = utils.createLinkTypeId(
432
426
  _izContext,
433
427
  firstNode.objType,
434
428
  secondNode.objType,
@@ -536,9 +530,9 @@ async function _processObjectLinksGroup(_izContext, relationshipTag, objectLinks
536
530
  try {
537
531
  _izContext.logger.debug('Uploading new relationship schema...');
538
532
  await Promise.all([
539
- uploadObjectToS3(
533
+ uploadObjectToS3.uploadObjectToS3(
540
534
  _izContext,
541
- UPLOAD_PATH_S3.relationshipTag(
535
+ consts.UPLOAD_PATH_S3.relationshipTag(
542
536
  _izContext,
543
537
  relType
544
538
  ),
@@ -598,9 +592,9 @@ async function _processObjectLinksGroup(_izContext, relationshipTag, objectLinks
598
592
 
599
593
 
600
594
  const objectRelationshipPromises = Object.values(newObjectRelationships).map(({ objType, relationships }) =>
601
- uploadObjectToS3(
595
+ uploadObjectToS3.uploadObjectToS3(
602
596
  _izContext,
603
- UPLOAD_PATH_S3.objectRelationship(_izContext, objType),
597
+ consts.UPLOAD_PATH_S3.objectRelationship(_izContext, objType),
604
598
  relationships,
605
599
  )
606
600
  );
@@ -612,9 +606,9 @@ async function _processObjectLinksGroup(_izContext, relationshipTag, objectLinks
612
606
 
613
607
  const uploadPromises = [
614
608
  ...linkByLinkTypeIds.map(({ linkTypeId, link }) =>
615
- uploadObjectToS3(
609
+ uploadObjectToS3.uploadObjectToS3(
616
610
  _izContext,
617
- UPLOAD_PATH_S3.linkByLinkTypeId(
611
+ consts.UPLOAD_PATH_S3.linkByLinkTypeId(
618
612
  _izContext,
619
613
  process.env.iz_serviceTag,
620
614
  linkTypeId
@@ -647,6 +641,4 @@ async function _processObjectLinksGroup(_izContext, relationshipTag, objectLinks
647
641
  }
648
642
  }
649
643
 
650
- module.exports = {
651
- addLinks,
652
- };
644
+ export default { addLinks };