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

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.
@@ -18,64 +18,22 @@ along with this program.If not, see < http://www.gnu.org/licenses/>.
18
18
  'use strict';
19
19
 
20
20
 
21
- const glob = require('glob')
22
- const path = require('path')
23
- const lodash = require('lodash');
24
- const hash = require('@izara_project/izara-shared-core').objectHash;
25
-
26
- const sharedServiceSchema = require("@izara_project/izara-shared-service-schemas");
27
- const {
28
- getObjSchemaS3: getObjectSchemaS3Shared,
29
- getObjSchemaWithHierarchy,
30
- getObjSchemaWithoutHierarchy,
31
- mergeExtendObjSchema: mergeExtendObjSchemaShared,
32
- // recursiveMergeExtendObjSchema: recursiveMergeExtendObjSchemaShared,
33
- getRefObjectRelationship: getRefObjectRelationshipShared,
34
- getRelationshipSchema: getRelationshipSchemaShared,
35
- getObjectRelationship: getObjectRelationshipShared,
36
- getRequiredOnCreateLinks: getRequiredOnCreateLinksShared,
37
- getLinkConfigByLinkTypeId: getLinkConfigByLinkTypeIdShared,
38
- getObjTypeHierarchy: getObjTypeHierarchyShared,
39
- getObjectSchemaForCreate: getObjectSchemaForCreateShared,
40
- getObjectSchemaForUpdate: getObjectSchemaForUpdateShared,
41
- getFlowSchemaS3: getFlowSchemaS3Shared
42
- } = sharedServiceSchema.getObjectSchema;
43
- const { validateObjType, validateFlowType } = sharedServiceSchema.validateObjType;
44
- const {
45
- basicFieldNameSchema,
46
- basicFieldNameSchemaForCombineFieldName
47
- } = sharedServiceSchema.basicValidatorSchema;
48
-
49
- const {
50
- inMemoryCacheLib,
51
- NoRetryError,
52
- validator: { validateObject },
53
- } = require('@izara_project/izara-core-library-core');
54
-
55
-
56
- // const dynamodbSharedLib = require('@izara_project/izara-shared/src/DynamodbSharedLib');
57
- // const Logger = require('@izara_project/izara-core-library-logger')
58
-
59
- const { getObjectS3, headObjectS3, getSchemaByNameWithCache, getSchemaByName } = require("./libs/s3Utils");
60
- const { generateObjectSchemaForCombineFieldNames } = require("./libs/UploadUseCase");
61
-
62
- const {
63
- LOCAL_OBJECT_SCHEMA_PATH,
64
-
65
- UPLOAD_PATH_S3,
66
-
67
- LOCAL_FILENAME,
68
- STORAGE_TYPES
69
- } = require('./Consts')
70
-
71
- const {
72
- findLinkByObjTypeV2,
73
- getUsedFieldNamesOfIdentifiers,
74
- createLinkTypeId
75
- } = require('./Utils');
76
-
77
-
78
- const { listLambdaFunctions } = require('./libs/LambdaUtils');
21
+ import { glob } from 'glob';
22
+ import path from 'path';
23
+ import { pathToFileURL } from 'url';
24
+ import lodash from 'lodash';
25
+ import { objectHash as hash } from '@izara_project/izara-shared-core';
26
+ import { getObjectSchema, validateObjType } from "@izara_project/izara-shared-service-schemas";
27
+ import { inMemoryCacheLib, NoRetryError } from '@izara_project/izara-core-library-core';
28
+
29
+
30
+ // import dynamodbSharedLib from ('@izara_project/izara-shared/src/DynamodbSharedLib');
31
+ // import Logger from ('@izara_project/izara-core-library-logger')
32
+
33
+ import s3Utils from "./libs/s3Utils.js";
34
+ import uploadUseCase from "./libs/UploadUseCase.js"
35
+ import consts from './Consts.js'
36
+ import lambdaUtils from './libs/LambdaUtils.js';
79
37
 
80
38
  /**
81
39
  * get array of data from specific path in local environment
@@ -88,7 +46,7 @@ const { listLambdaFunctions } = require('./libs/LambdaUtils');
88
46
  * @param {Boolean} setting.onNotFoundError - optional, default = false -- if true will throw error when not find any file
89
47
  * @returns - array of data
90
48
  */
91
- function getDataFromPath(
49
+ async function getDataFromPath(
92
50
  _izContext,
93
51
  fileName,
94
52
  fileStoragePath,
@@ -112,7 +70,7 @@ function getDataFromPath(
112
70
  }
113
71
 
114
72
  // list exists file path from fileStoragePath path
115
- const allFilePath = glob.sync(`**/${fileName}`, { cwd: fileStoragePath, dot: true });
73
+ const allFilePath = await glob(`**/${fileName}`, { cwd: fileStoragePath, dot: true });
116
74
 
117
75
  // validate fileLimit
118
76
  if (fileLimit && allFilePath.length > fileLimit) {
@@ -120,8 +78,13 @@ function getDataFromPath(
120
78
  }
121
79
 
122
80
  if (allFilePath.length > 0) {
123
- const allFileData = allFilePath.map(file => require(path.join(fileStoragePath, file)));
124
- return allFileData;
81
+ // const allFileData = allFilePath.map(file => require(path.join(fileStoragePath, file)));
82
+ const allFileData = await Promise.all(allFilePath.map(async (file) => {
83
+ let data = await import(pathToFileURL(path.join(fileStoragePath, file)).href);
84
+ data = data.default;
85
+ return data;
86
+ }))
87
+ return allFileData.flat();
125
88
  } else {
126
89
 
127
90
  if (onNotFoundError === true) {
@@ -132,7 +95,7 @@ function getDataFromPath(
132
95
  }
133
96
  }
134
97
 
135
- // currenly not use
98
+ // currently not use
136
99
  // /**
137
100
  // * get data from file ObjectTypes.js depend on path
138
101
  // *
@@ -144,7 +107,7 @@ function getDataFromPath(
144
107
 
145
108
  // const objectTypesData = getDataFromPath(
146
109
  // _izContext,
147
- // LOCAL_FILENAME.OBJECT_TYPES,
110
+ // consts.LOCAL_FILENAME.OBJECT_TYPES,
148
111
  // objSchemaPath,
149
112
  // {
150
113
  // fileLimit: 1,
@@ -165,7 +128,7 @@ function getDataFromPath(
165
128
  * @param {boolean} [getExtendObType = false] Optional default = false , If = true will get extendObjectType before return
166
129
  * @returns {Promise<object>} Return object schema of objectTypes
167
130
  */
168
- async function getLocalObjectSchemas(_izContext, objectTypes, objSchemaPath = LOCAL_OBJECT_SCHEMA_PATH, getExtendObType = false) {
131
+ async function getLocalObjectSchemas(_izContext, objectTypes, objSchemaPath = consts.LOCAL_OBJECT_SCHEMA_PATH, getExtendObType = false) {
169
132
  let errorsFound = [];
170
133
  // validate objectTypes
171
134
  if (!objectTypes) {
@@ -211,12 +174,10 @@ async function getLocalObjectSchemas(_izContext, objectTypes, objSchemaPath = LO
211
174
  // returnValue.fieldLookup[objectType] = null;
212
175
  }
213
176
 
214
- let allObjectSchemas = lodash.cloneDeep(getDataFromPath(_izContext, LOCAL_FILENAME.OBJECT_SCHEMA, objSchemaPath)
215
- .flat()
177
+ let allObjectSchemas = lodash.cloneDeep((await getDataFromPath(_izContext, consts.LOCAL_FILENAME.OBJECT_SCHEMA, objSchemaPath)).flat()
216
178
  .filter(schema => filteredObjectTypes.includes(schema.objectType))
217
179
  );
218
180
 
219
-
220
181
  // add extendObjectType before assign to returnValue object
221
182
  if (getExtendObType) {
222
183
  await Promise.all(
@@ -259,7 +220,7 @@ async function getLocalObjectSchemas(_izContext, objectTypes, objSchemaPath = LO
259
220
  *
260
221
  * @see {@link getLocalObjectSchemas}
261
222
  */
262
- async function getLocalObjectSchemasWithHierarchy(_izContext, objectTypes, objSchemaPath = LOCAL_OBJECT_SCHEMA_PATH) {
223
+ async function getLocalObjectSchemasWithHierarchy(_izContext, objectTypes, objSchemaPath = consts.LOCAL_OBJECT_SCHEMA_PATH) {
263
224
  return await getLocalObjectSchemas(_izContext, objectTypes, objSchemaPath, true)
264
225
  }
265
226
 
@@ -269,7 +230,7 @@ async function getLocalObjectSchemasWithHierarchy(_izContext, objectTypes, objSc
269
230
  *
270
231
  * @see {@link getLocalObjectSchemas}
271
232
  */
272
- async function getLocalObjectSchemasWithoutHierarchy(_izContext, objectTypes, objSchemaPath = LOCAL_OBJECT_SCHEMA_PATH) {
233
+ async function getLocalObjectSchemasWithoutHierarchy(_izContext, objectTypes, objSchemaPath = consts.LOCAL_OBJECT_SCHEMA_PATH) {
273
234
  return await getLocalObjectSchemas(_izContext, objectTypes, objSchemaPath, false)
274
235
  }
275
236
 
@@ -282,7 +243,7 @@ async function getLocalObjectSchemasWithoutHierarchy(_izContext, objectTypes, ob
282
243
  * @param {boolean} [getExtendObType = false] - Optional default = false , If = true will get extendObjectType before return
283
244
  * @returns {Promise<object>} - Return all objectSchema from local service
284
245
  */
285
- async function getAllLocalObjectSchemas(_izContext, objSchemaPath = LOCAL_OBJECT_SCHEMA_PATH, getExtendObType = false) {
246
+ async function getAllLocalObjectSchemas(_izContext, objSchemaPath = consts.LOCAL_OBJECT_SCHEMA_PATH, getExtendObType = false) {
286
247
 
287
248
  //initial return value
288
249
  let returnValue = {
@@ -293,11 +254,9 @@ async function getAllLocalObjectSchemas(_izContext, objSchemaPath = LOCAL_OBJECT
293
254
 
294
255
  // const objectTypeList = getObjectTypes(_izContext, objSchemaPath)
295
256
 
296
- const allObjectSchemas = lodash.cloneDeep(getDataFromPath(_izContext, LOCAL_FILENAME.OBJECT_SCHEMA, objSchemaPath)
297
- .flat()
257
+ const allObjectSchemas = lodash.cloneDeep((await getDataFromPath(_izContext, consts.LOCAL_FILENAME.OBJECT_SCHEMA, objSchemaPath)).flat()
298
258
  // .filter(schema => objectTypeList.includes(schema.objectType))
299
259
  );
300
-
301
260
  // check objectType that not found in ObjectFieldSchema.js
302
261
  // const remainingObjectTypes = objectTypeList.filter(objectType => !allObjectSchemas.some(schema => schema.objectType === objectType));
303
262
 
@@ -349,7 +308,7 @@ async function getAllLocalObjectSchemas(_izContext, objSchemaPath = LOCAL_OBJECT
349
308
  *
350
309
  * @see {@link getAllLocalObjectSchemas}
351
310
  */
352
- async function getAllLocalObjectSchemasWithHierarchy(_izContext, objSchemaPath = LOCAL_OBJECT_SCHEMA_PATH) {
311
+ async function getAllLocalObjectSchemasWithHierarchy(_izContext, objSchemaPath = consts.LOCAL_OBJECT_SCHEMA_PATH) {
353
312
  return await getAllLocalObjectSchemas(_izContext, objSchemaPath, true)
354
313
  }
355
314
 
@@ -358,7 +317,7 @@ async function getAllLocalObjectSchemasWithHierarchy(_izContext, objSchemaPath =
358
317
  *
359
318
  * @see {@link getAllLocalObjectSchemas}
360
319
  */
361
- async function getAllLocalObjectSchemasWithoutHierarchy(_izContext, objSchemaPath = LOCAL_OBJECT_SCHEMA_PATH) {
320
+ async function getAllLocalObjectSchemasWithoutHierarchy(_izContext, objSchemaPath = consts.LOCAL_OBJECT_SCHEMA_PATH) {
362
321
  return await getAllLocalObjectSchemas(_izContext, objSchemaPath, false)
363
322
  }
364
323
 
@@ -370,7 +329,7 @@ async function getLambdaFunctionNames(_izContext) {
370
329
  try {
371
330
  _izContext.logger.debug("-- function getLambdaFunctionNames --");
372
331
 
373
- const LambdaFunctions = getDataFromPath(_izContext, LOCAL_FILENAME.LAMBDA_FUNCTIONS, LOCAL_OBJECT_SCHEMA_PATH, {
332
+ const LambdaFunctions = await getDataFromPath(_izContext, consts.LOCAL_FILENAME.LAMBDA_FUNCTIONS, consts.LOCAL_OBJECT_SCHEMA_PATH, {
374
333
  fileLimit: 1
375
334
  })[0];
376
335
  _izContext.logger.debug("LambdaFunctions: ", LambdaFunctions);
@@ -383,7 +342,7 @@ async function getLambdaFunctionNames(_izContext) {
383
342
 
384
343
  try {
385
344
  do {
386
- const { Functions, NextMarker } = await listLambdaFunctions(_izContext, { Marker: marker });
345
+ const { Functions, NextMarker } = await lambdaUtils(_izContext, { Marker: marker });
387
346
 
388
347
  const filteredNames = Functions
389
348
  .map(func => func.FunctionName)
@@ -471,7 +430,7 @@ async function getObjSchemaS3(
471
430
  getExtendObType = false
472
431
  ) {
473
432
 
474
- return await getObjectSchemaS3Shared(getSchemaByNameWithCache, objType, process.env.iz_serviceSchemaBucketName, getExtendObType).then(res => {
433
+ return await getObjectSchema.getObjSchemaS3(s3Utils.getSchemaByNameWithCache, objType, process.env.iz_serviceSchemaBucketName, getExtendObType).then(res => {
475
434
  if (res.errorsFound.length && res.errorsFound.length > 0) {
476
435
  throw new NoRetryError(res.errorsFound.join(","))
477
436
  } else {
@@ -505,7 +464,7 @@ const getObjSchemaS3WithCache = inMemoryCacheLib(
505
464
  */
506
465
  async function getObjSchemaS3WithHierarchy(_izContext, objType, bucketName = process.env.iz_serviceSchemaBucketName) {
507
466
  // return await getObjSchemaS3WithCache(_izContext, objType, true)
508
- return await getObjSchemaWithHierarchy(getSchemaByNameWithCache, objType, bucketName).then(res => {
467
+ return await getObjectSchema.getObjSchemaWithHierarchy(s3Utils.getSchemaByNameWithCache, objType, bucketName).then(res => {
509
468
  if (res.errorsFound.length && res.errorsFound.length > 0) {
510
469
  throw new NoRetryError(res.errorsFound.join(","))
511
470
  } else {
@@ -522,7 +481,7 @@ async function getObjSchemaS3WithHierarchy(_izContext, objType, bucketName = pro
522
481
  */
523
482
  async function getObjSchemaS3WithoutHierarchy(_izContext, objType, bucketName = process.env.iz_serviceSchemaBucketName) {
524
483
  // return await getObjSchemaS3WithCache(_izContext, objType, false)
525
- return await getObjSchemaWithoutHierarchy(getSchemaByNameWithCache, objType, bucketName).then(res => {
484
+ return await getObjectSchema.getObjSchemaWithoutHierarchy(s3Utils.getSchemaByNameWithCache, objType, bucketName).then(res => {
526
485
  if (res.errorsFound.length && res.errorsFound.length > 0) {
527
486
  throw new NoRetryError(res.errorsFound.join(","))
528
487
  } else {
@@ -544,7 +503,7 @@ async function getObjSchemaS3WithoutHierarchy(_izContext, objType, bucketName =
544
503
  async function getObjectSchemaCombineFieldNames(_izContext, objType) {
545
504
 
546
505
  const objSchema = await getObjSchemaS3WithHierarchy(_izContext, objType);
547
- const combinedSchema = generateObjectSchemaForCombineFieldNames(_izContext, objSchema);
506
+ const combinedSchema = uploadUseCase.generateObjectSchemaForCombineFieldNames(_izContext, objSchema);
548
507
  return combinedSchema
549
508
  }
550
509
 
@@ -580,7 +539,7 @@ const getObjectSchemaCombineFieldNamesWithCache = inMemoryCacheLib(
580
539
  * @param {String} [objSchemaPath] - Optional default = './src/schemas', need objSchemaPath if use in local machine
581
540
  * @returns {Object} - specific relationship schema
582
541
  */
583
- function getLocalRelationshipSchemas(_izContext, relationshipTags, objSchemaPath = LOCAL_OBJECT_SCHEMA_PATH) {
542
+ async function getLocalRelationshipSchemas(_izContext, relationshipTags, objSchemaPath = consts.LOCAL_OBJECT_SCHEMA_PATH) {
584
543
 
585
544
  // validate objectTypes
586
545
  if (!relationshipTags) {
@@ -596,9 +555,9 @@ function getLocalRelationshipSchemas(_izContext, relationshipTags, objSchemaPath
596
555
  }
597
556
 
598
557
 
599
- const objectRelationshipDatas = getDataFromPath(
558
+ const objectRelationshipDatas = await getDataFromPath(
600
559
  _izContext,
601
- LOCAL_FILENAME.OBJECT_RELATIONSHIPS,
560
+ consts.LOCAL_FILENAME.OBJECT_RELATIONSHIPS,
602
561
  objSchemaPath,
603
562
  {
604
563
  fileLimit: 1,
@@ -639,7 +598,7 @@ function getLocalRelationshipSchemas(_izContext, relationshipTags, objSchemaPath
639
598
  * @returns {Promise<Object>} - reference relationship schema of objType
640
599
  */
641
600
  async function getRefObjectRelationship(_izContext, objType, bucketName = process.env.iz_serviceSchemaBucketName) {
642
- return await getRefObjectRelationshipShared(getSchemaByNameWithCache, objType, bucketName).then(res => {
601
+ return await getObjectSchema.getRefObjectRelationship(s3Utils.getSchemaByNameWithCache, objType, bucketName).then(res => {
643
602
  if (res.errorsFound.length && res.errorsFound.length > 0) {
644
603
  throw new NoRetryError(res.errorsFound.join(","))
645
604
  } else {
@@ -674,7 +633,7 @@ const getRefObjectRelationshipWithCache = inMemoryCacheLib(
674
633
  *
675
634
  */
676
635
  async function getRelationshipSchema(_izContext, relType, bucketName = process.env.iz_serviceSchemaBucketName) {
677
- return await getRelationshipSchemaShared(getSchemaByNameWithCache, relType, bucketName).then(res => {
636
+ return await getObjectSchema.getRelationshipSchema(s3Utils.getSchemaByNameWithCache, relType, bucketName).then(res => {
678
637
  if (res.errorsFound.length && res.errorsFound.length > 0) {
679
638
  throw new NoRetryError(res.errorsFound.join(","))
680
639
  } else {
@@ -717,13 +676,13 @@ async function getRelationshipServiceTag(_izContext, relationshipTag, objType) {
717
676
  objType,
718
677
  });
719
678
 
720
- const validateObjTypeResult = validateObjType(objType);
679
+ const validateObjTypeResult = validateObjType.validateObjType(objType);
721
680
  if (validateObjTypeResult.errorsFound.length > 0) {
722
681
  _izContext.logger.error("getRelationshipServiceTag: Invalid objType: ", validateObjTypeResult.errorsFound);
723
682
  throw new NoRetryError(`getRelationshipServiceTag: Invalid objType: ${JSON.stringify(objType)}, ${validateObjTypeResult.errorsFound.join(", ")}`);
724
683
  }
725
684
 
726
- const relTagPath = UPLOAD_PATH_S3.relationshipTag(
685
+ const relTagPath = consts.UPLOAD_PATH_S3.relationshipTag(
727
686
  _izContext,
728
687
  { // relType
729
688
  serviceTag: objType.serviceTag,
@@ -731,7 +690,7 @@ async function getRelationshipServiceTag(_izContext, relationshipTag, objType) {
731
690
  }
732
691
  );
733
692
 
734
- let relSchemaHeadData = await headObjectS3(_izContext, { Bucket: process.env.iz_serviceSchemaBucketName, Key: relTagPath })
693
+ let relSchemaHeadData = await s3Util.headObjectS3(_izContext, { Bucket: process.env.iz_serviceSchemaBucketName, Key: relTagPath })
735
694
 
736
695
  // _izContext.logger.debug("relSchemaHeadData: ", relSchemaHeadData);
737
696
 
@@ -787,7 +746,7 @@ async function getObjectRelationship(
787
746
  overWriteBaseObjType,
788
747
  ) {
789
748
 
790
- return await getObjectRelationshipShared(getSchemaByNameWithCache, objType, specificRelTags, overWriteBaseObjType, process.env.iz_serviceSchemaBucketName).then(res => {
749
+ return await getObjectSchema.getObjectRelationship(s3Utils.getSchemaByNameWithCache, objType, specificRelTags, overWriteBaseObjType, process.env.iz_serviceSchemaBucketName).then(res => {
791
750
  if (res.errorsFound.length && res.errorsFound.length > 0) {
792
751
  throw new NoRetryError(res.errorsFound.join(","))
793
752
  } else {
@@ -837,7 +796,7 @@ async function getRequiredOnCreateLinks(
837
796
  specificRelTags,
838
797
  });
839
798
 
840
- return await getRequiredOnCreateLinksShared(getSchemaByNameWithCache, objType, specificRelTags, process.env.iz_serviceSchemaBucketName).then(res => {
799
+ return await getObjectSchema.getRequiredOnCreateLinks(s3Utils.getSchemaByNameWithCache, objType, specificRelTags, process.env.iz_serviceSchemaBucketName).then(res => {
841
800
  if (res.errorsFound.length && res.errorsFound.length > 0) {
842
801
  throw new NoRetryError(res.errorsFound.join(","))
843
802
  } else {
@@ -920,7 +879,7 @@ async function getLinkConfigByLinkTypeId(_izContext, firstObjType, secondObjType
920
879
  settings,
921
880
  });
922
881
 
923
- return await getLinkConfigByLinkTypeIdShared(getSchemaByNameWithCache, firstObjType, secondObjType, relType, direction, settings, process.env.iz_serviceSchemaBucketName).then(res => {
882
+ return await getObjectSchema.getLinkConfigByLinkTypeId(s3Utils.getSchemaByNameWithCache, firstObjType, secondObjType, relType, direction, settings, process.env.iz_serviceSchemaBucketName).then(res => {
924
883
  if (res.errorsFound.length && res.errorsFound.length > 0) {
925
884
  throw new NoRetryError(res.errorsFound.join(","))
926
885
  } else {
@@ -957,7 +916,7 @@ const getLinkConfigByLinkTypeIdWithCache = inMemoryCacheLib(
957
916
  * @returns
958
917
  */
959
918
  async function mergeExtendObjSchema(_izContext, objectSchema) {
960
- let mergedObjectSchema = await mergeExtendObjSchemaShared(getSchemaByNameWithCache, objectSchema, process.env.iz_serviceSchemaBucketName).then(res => {
919
+ let mergedObjectSchema = await getObjectSchema.mergeExtendObjSchema(s3Utils.getSchemaByNameWithCache, objectSchema, process.env.iz_serviceSchemaBucketName).then(res => {
961
920
  if (res.errorsFound.length && res.errorsFound.length > 0) {
962
921
  throw new NoRetryError(`objectSchema.objectType: ${objectSchema.objectType} ${res.errorsFound}`)
963
922
  } else {
@@ -968,14 +927,14 @@ async function mergeExtendObjSchema(_izContext, objectSchema) {
968
927
  }
969
928
 
970
929
 
971
- async function getAllLocalFlowSchemas(_izContext, flowSchemaPath = LOCAL_OBJECT_SCHEMA_PATH) {
930
+ async function getAllLocalFlowSchemas(_izContext, flowSchemaPath = consts.LOCAL_OBJECT_SCHEMA_PATH) {
972
931
  // initial return Value
973
932
  let returnValue = {
974
933
  records: [],
975
934
  fieldLookup: {}
976
935
  }
977
936
 
978
- const allFlowSchemas = lodash.cloneDeep(getDataFromPath(_izContext, LOCAL_FILENAME.FLOW_SCHEMA, flowSchemaPath).flat());
937
+ const allFlowSchemas = lodash.cloneDeep((await getDataFromPath(_izContext, consts.LOCAL_FILENAME.FLOW_SCHEMA, flowSchemaPath)).flat());
979
938
  _izContext.logger.debug("allFlowSchemas::", allFlowSchemas)
980
939
  for (let [idx, flowSchema] of allFlowSchemas.entries()) {
981
940
  if (!returnValue.fieldLookup.hasOwnProperty(flowSchema.flowTag)) {
@@ -989,7 +948,7 @@ async function getAllLocalFlowSchemas(_izContext, flowSchemaPath = LOCAL_OBJECT_
989
948
  return returnValue
990
949
  }
991
950
 
992
- async function getLocalFlowSchemas(_izContext, flowTags, flowSchemaPath = LOCAL_OBJECT_SCHEMA_PATH) {
951
+ async function getLocalFlowSchemas(_izContext, flowTags, flowSchemaPath = consts.LOCAL_OBJECT_SCHEMA_PATH) {
993
952
  if (!flowTags) {
994
953
  throw new NoRetryError("required flowTags");
995
954
  }
@@ -1016,8 +975,7 @@ async function getLocalFlowSchemas(_izContext, flowTags, flowSchemaPath = LOCAL_
1016
975
  filteredFlowTags.push(flowTag)
1017
976
  }
1018
977
 
1019
- const filterFlowSchemas = lodash.cloneDeep(getDataFromPath(_izContext, LOCAL_FILENAME.FLOW_SCHEMA, flowSchemaPath)
1020
- .flat()
978
+ const filterFlowSchemas = lodash.cloneDeep((await getDataFromPath(_izContext, consts.LOCAL_FILENAME.FLOW_SCHEMA, flowSchemaPath)).flat()
1021
979
  .filter(schema => filteredFlowTags.includes(schema.flowTag))
1022
980
  );
1023
981
  _izContext.logger.debug("filterFlowSchemas::", filterFlowSchemas)
@@ -1048,7 +1006,7 @@ async function getFlowSchemaS3(
1048
1006
  flowType,
1049
1007
  ) {
1050
1008
 
1051
- return await getFlowSchemaS3Shared(getSchemaByNameWithCache, flowType, process.env.iz_serviceSchemaBucketName).then(res => {
1009
+ return await getObjectSchema.getFlowSchemaS3(s3Utils.getSchemaByNameWithCache, flowType, process.env.iz_serviceSchemaBucketName).then(res => {
1052
1010
  if (res.errorsFound.length) {
1053
1011
  throw new NoRetryError(res.errorsFound.join(","))
1054
1012
  } else {
@@ -1072,20 +1030,16 @@ const getFlowSchemaS3WithCache = inMemoryCacheLib(
1072
1030
  }
1073
1031
  )
1074
1032
 
1075
- function getAllLocalRelationshipSchema(_izContext, objSchemaPath = LOCAL_OBJECT_SCHEMA_PATH) {
1033
+ async function getAllLocalRelationshipSchema(_izContext, objSchemaPath = consts.LOCAL_OBJECT_SCHEMA_PATH) {
1076
1034
 
1077
- const allObjectSchemas = lodash.cloneDeep(getDataFromPath(_izContext, LOCAL_FILENAME.OBJECT_RELATIONSHIPS, objSchemaPath)
1078
- .flat()
1079
- );
1035
+ const allObjectSchemas = lodash.cloneDeep((await getDataFromPath(_izContext, consts.LOCAL_FILENAME.OBJECT_RELATIONSHIPS, objSchemaPath)).flat());
1080
1036
 
1081
1037
  return allObjectSchemas
1082
1038
  }
1083
1039
 
1084
- function getAllLocalRefObjectRelationshipSchema(_izContext, objSchemaPath = LOCAL_OBJECT_SCHEMA_PATH) {
1040
+ async function getAllLocalRefObjectRelationshipSchema(_izContext, objSchemaPath = consts.LOCAL_OBJECT_SCHEMA_PATH) {
1085
1041
 
1086
- const allRefObjectRelationshipSchemas = lodash.cloneDeep(getDataFromPath(_izContext, LOCAL_FILENAME.REFERENCE_OBJECT_RELATIONSHIPS, objSchemaPath)
1087
- .flat()
1088
- );
1042
+ const allRefObjectRelationshipSchemas = lodash.cloneDeep((await getDataFromPath(_izContext, consts.LOCAL_FILENAME.REFERENCE_OBJECT_RELATIONSHIPS, objSchemaPath)).flat());
1089
1043
 
1090
1044
  return allRefObjectRelationshipSchemas
1091
1045
 
@@ -1101,7 +1055,7 @@ function getAllLocalRefObjectRelationshipSchema(_izContext, objSchemaPath = LOCA
1101
1055
  * @returns
1102
1056
  */
1103
1057
  async function getObjTypeHierarchy(_izContext, objType) {
1104
- return await getObjTypeHierarchyShared(getSchemaByNameWithCache, objType, objType, process.env.iz_serviceSchemaBucketName);
1058
+ return await getObjectSchema.getObjTypeHierarchy(s3Utils.getSchemaByNameWithCache, objType, objType, process.env.iz_serviceSchemaBucketName);
1105
1059
  }
1106
1060
 
1107
1061
  /**
@@ -1120,11 +1074,11 @@ const getObjTypeHierarchyWithCache = inMemoryCacheLib(
1120
1074
  )
1121
1075
 
1122
1076
  async function getObjectSchemaForCreate(_izContext, objType) {
1123
- return await getObjectSchemaForCreateShared(getSchemaByNameWithCache, objType, process.env.iz_serviceSchemaBucketName)
1077
+ return await getObjectSchema.getObjectSchemaForCreate(s3Utils.getSchemaByNameWithCache, objType, process.env.iz_serviceSchemaBucketName)
1124
1078
  }
1125
1079
 
1126
1080
  async function getObjectSchemaForUpdate(_izContext, objType) {
1127
- return await getObjectSchemaForUpdateShared(getSchemaByNameWithCache, objType, process.env.iz_serviceSchemaBucketName)
1081
+ return await getObjectSchema.getObjectSchemaForUpdate(s3Utils.getSchemaByNameWithCache, objType, process.env.iz_serviceSchemaBucketName)
1128
1082
  }
1129
1083
 
1130
1084
 
@@ -1167,7 +1121,7 @@ async function getTableNamesByFlowType(_izContext, flowType) {
1167
1121
  }
1168
1122
 
1169
1123
 
1170
- module.exports = {
1124
+ export default {
1171
1125
  // getObjectTypes,
1172
1126
  getDataFromPath,
1173
1127
 
@@ -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