@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.
package/src/Utils.js CHANGED
@@ -17,47 +17,26 @@ 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;
21
- const {
20
+ import { objectHash as hash } from '@izara_project/izara-shared-core';
21
+ import {
22
22
  NoRetryError,
23
- validator: { validateObject }
24
- } = require('@izara_project/izara-core-library-core');
25
-
26
- const {
27
- basicValidatorSchema: {
28
- basicObjectSchema,
29
- basicExtendObjectSchema,
30
- relationshipBasicSchema,
31
- refRelationshipBasicSchema,
32
- basicFlowSchema
33
- },
34
- validateObjType: {
35
- validateObjType,
36
- validateRelType,
37
- validateFlowType
38
- },
39
- reformatObjectSchema: {
40
- getUsedFieldNamesOfIdentifiers: getUsedFieldNamesOfIdentifiersShared
41
- }
42
- } = require('@izara_project/izara-shared-service-schemas');
23
+ validator
24
+ } from '@izara_project/izara-core-library-core';
25
+ import { basicValidatorSchema, validateObjType, reformatObjectSchema } from '@izara_project/izara-shared-service-schemas'
43
26
 
44
- const consts = require('./Consts');
45
- // const getSchema = require('./GetObjectSchema');
46
- // const deliminatorTree = require('./libs/DeliminatorTree');
27
+ import consts from './Consts.js';
47
28
 
48
- const {
29
+ import {
49
30
  APIGatewayClient,
50
31
  GetRestApisCommand,
51
32
  GetResourcesCommand,
52
- GetMethodCommand,
53
- } = require("@aws-sdk/client-api-gateway");
33
+ } from "@aws-sdk/client-api-gateway";
54
34
 
55
- const {
35
+ import {
56
36
  ApiGatewayV2Client,
57
37
  GetApisCommand,
58
38
  GetRoutesCommand,
59
- GetStagesCommand,
60
- } = require("@aws-sdk/client-apigatewayv2");
39
+ } from "@aws-sdk/client-apigatewayv2";
61
40
 
62
41
  function createObjType(objectType, serviceTag) {
63
42
  if (!process.env.iz_serviceTag && !serviceTag) {
@@ -116,7 +95,7 @@ function getIdentifierTypeByPriority(_izContext, storageTypes = [], objSchema) {
116
95
  * @returns {string[]} - array of fieldName from objectSchema.identifiers
117
96
  */
118
97
  function getUsedFieldNamesOfIdentifiers(_izContext, identifiers, identifierTypes = []) {
119
- return getUsedFieldNamesOfIdentifiersShared(identifiers, identifierTypes)
98
+ return reformatObjectSchema.getUsedFieldNamesOfIdentifiers(identifiers, identifierTypes)
120
99
  // let identifierFieldNames = [];
121
100
 
122
101
  // for (let identifier of identifiers) {
@@ -138,7 +117,7 @@ function getUsedFieldNamesOfIdentifiers(_izContext, identifiers, identifierTypes
138
117
 
139
118
  function validateBasicObjectSchema(_izContext, objectSchema) {
140
119
 
141
- const validateStatus = validateObject(basicObjectSchema, objectSchema, null, { strict: false });
120
+ const validateStatus = validator(basicValidatorSchema.basicObjectSchema, objectSchema, null, { strict: false });
142
121
 
143
122
  if (validateStatus.pass) {
144
123
  let errors = []
@@ -256,7 +235,7 @@ function validateBasicObjectSchema(_izContext, objectSchema) {
256
235
  }
257
236
 
258
237
  function validateExtendObjectSchema(_izContext, extendObjectSchema) {
259
- let validateStatus = validateObject(basicExtendObjectSchema, extendObjectSchema, null, { strict: false });
238
+ let validateStatus = validator(basicValidatorSchema.basicExtendObjectSchema, extendObjectSchema, null, { strict: false });
260
239
 
261
240
  if (validateStatus.pass) {
262
241
  let errors = []
@@ -385,7 +364,7 @@ function validateObjectSchema(_izContext, objectSchema) {
385
364
 
386
365
 
387
366
  function validateRelationshipSchema(_izContext, relationshipSchema) {
388
- let validateStatus = validateObject(relationshipBasicSchema, relationshipSchema, null, { strict: false });
367
+ let validateStatus = validator(basicValidatorSchema.relationshipBasicSchema, relationshipSchema, null, { strict: false });
389
368
 
390
369
  const relationshipTag = Object.keys(relationshipSchema)[0];
391
370
  _izContext.logger.debug("relationshipSchema: ", relationshipSchema);
@@ -439,7 +418,7 @@ function validateRelationshipSchema(_izContext, relationshipSchema) {
439
418
  }
440
419
 
441
420
  function validateRefRelationshipSchema(_izContext, refRelationshipSchema, serviceTag) {
442
- let validateStatus = validateObject(refRelationshipBasicSchema, refRelationshipSchema, null, { strict: false });
421
+ let validateStatus = validator(basicValidatorSchema.refRelationshipBasicSchema, refRelationshipSchema, null, { strict: false });
443
422
  if (validateStatus.pass) {
444
423
  if (!serviceTag) {
445
424
  serviceTag = process.env.iz_serviceTag
@@ -473,7 +452,7 @@ function validateRefRelationshipSchema(_izContext, refRelationshipSchema, servic
473
452
  * @returns
474
453
  */
475
454
  function findLinkByObjType(_izContext, objType, relationshipSchema) {
476
- const validateObjTypeResult = validateObjType(objType);
455
+ const validateObjTypeResult = validateObjType.validateObjType(objType);
477
456
  if (validateObjTypeResult.errorsFound.length > 0) {
478
457
  _izContext.logger.error(`findLinkByObjType: invalid objType: ${JSON.stringify(objType)}`);
479
458
  throw new NoRetryError(`findLinkByObjType: invalid objType: ${JSON.stringify(objType)}`);
@@ -524,7 +503,7 @@ function findLinkByObjType(_izContext, objType, relationshipSchema) {
524
503
  * @returns
525
504
  */
526
505
  function findLinkByObjTypeV2(_izContext, objType, relType, relationshipSchema) {
527
- const validateObjTypeResult = validateObjType(objType);
506
+ const validateObjTypeResult = validateObjType.validateObjType(objType);
528
507
  if (validateObjTypeResult.errorsFound.length > 0) {
529
508
  _izContext.logger.error(`findLinkByObjTypeV2: invalid objType: ${JSON.stringify(objType)}`);
530
509
  throw new NoRetryError(`findLinkByObjTypeV2: invalid objType: ${JSON.stringify(objType)}`);
@@ -588,7 +567,7 @@ function findLinkByObjTypeV2(_izContext, objType, relType, relationshipSchema) {
588
567
 
589
568
 
590
569
  function createObjTypeConcat(_izContext, objType) {
591
- const validateObjTypeResult = validateObjType(objType);
570
+ const validateObjTypeResult = validateObjType.validateObjType(objType);
592
571
  if (validateObjTypeResult.errorsFound.length > 0) {
593
572
  _izContext.logger.error("createObjTypeConcat validateObjTypeResult", validateObjTypeResult);
594
573
  throw new NoRetryError(`Invalid objType:${JSON.stringify(objType)}, ${validateObjTypeResult.errorsFound.join(", ")}`);
@@ -601,7 +580,7 @@ function explodedObjTypeConcat(_izContext, objectTypeId) {
601
580
  }
602
581
 
603
582
  function createRelTypeConcat(_izContext, relType) {
604
- const validateRelTypeResult = validateRelType(relType);
583
+ const validateRelTypeResult = validateObjType.validateRelType(relType);
605
584
  if (validateRelTypeResult.errorsFound.length > 0) {
606
585
  _izContext.logger.error("createRelTypeConcat validateRelTypeResult", validateRelTypeResult);
607
586
  throw new NoRetryError(`Invalid relType:${JSON.stringify(relType)}, ${validateRelTypeResult.errorsFound.join(", ")}`);
@@ -614,7 +593,7 @@ function explodedRelTypeConcat(_izContext, relationshipTypeId) {
614
593
  }
615
594
 
616
595
  function createFlowTypeConcat(_izContext, flowType) {
617
- const validateFlowTypeResult = validateFlowType(flowType);
596
+ const validateFlowTypeResult = validateObjType.validateFlowType(flowType);
618
597
  if (validateFlowTypeResult.errorsFound.length > 0) {
619
598
  _izContext.logger.error("createFlowTypeConcat validateFlowTypeResult", validateFlowTypeResult);
620
599
  throw new NoRetryError(`Invalid flowType:${JSON.stringify(flowType)}, ${validateFlowTypeResult.errorsFound.join(", ")}`);
@@ -628,20 +607,20 @@ function explodedFlowTypeConcat(_izContext, flowTypeId) {
628
607
 
629
608
  function createLinkTypeId(_izContext, firstObjType, secondObjType, relType, direction) {
630
609
  // validate objType
631
- let validateObjTypeResult = validateObjType(firstObjType);
610
+ let validateObjTypeResult = validateObjType.validateObjType(firstObjType);
632
611
  if (validateObjTypeResult.errorsFound.length > 0) {
633
612
  _izContext.logger.error("createLinkTypeId validateObjTypeResult", validateObjTypeResult);
634
613
  throw new NoRetryError(`Invalid objType:${JSON.stringify(firstObjType)}, ${validateObjTypeResult.errorsFound.join(", ")}`);
635
614
  }
636
615
 
637
- validateObjTypeResult = validateObjType(secondObjType);
616
+ validateObjTypeResult = validateObjType.validateObjType(secondObjType);
638
617
  if (validateObjTypeResult.errorsFound.length > 0) {
639
618
  _izContext.logger.error("createLinkTypeId validateObjTypeResult", validateObjTypeResult);
640
619
  throw new NoRetryError(`Invalid objType:${JSON.stringify(secondObjType)}, ${validateObjTypeResult.errorsFound.join(", ")}`);
641
620
  }
642
621
 
643
622
  // validate relType
644
- let validateRelTypeResult = validateRelType(relType);
623
+ let validateRelTypeResult = validateObjType.validateRelType(relType);
645
624
 
646
625
  if (validateRelTypeResult.errorsFound.length > 0) {
647
626
  _izContext.logger.error("createLinkTypeId validateRelTypeResult", validateRelTypeResult);
@@ -667,7 +646,7 @@ function createLinkTypeId(_izContext, firstObjType, secondObjType, relType, dire
667
646
  }
668
647
 
669
648
  function validateBasicFlowSchema(_izContext, flowSchema) {
670
- const validateStatus = validateObject(basicFlowSchema, flowSchema, null, { strict: false });
649
+ const validateStatus = validator(basicValidatorSchema.basicFlowSchema, flowSchema, null, { strict: false });
671
650
 
672
651
  if (validateStatus.pass) {
673
652
  let errors = [];
@@ -793,7 +772,7 @@ async function getApiLinksV2(objectTypes) {
793
772
  }
794
773
  }
795
774
 
796
- module.exports = {
775
+ export default {
797
776
  createObjType,
798
777
  getIdentifierTypeByPriority,
799
778
  getUsedFieldNamesOfIdentifiers,
@@ -18,55 +18,17 @@ along with this program.If not, see < http://www.gnu.org/licenses/>.
18
18
  'use strict';
19
19
 
20
20
 
21
- const readYamlFile = require('read-yaml-file');
22
- const lodash = require('lodash')
23
- const { inMemoryCacheLib, NoRetryError, consts } = require('@izara_project/izara-core-library-core');
24
- const Logger = require('@izara_project/izara-core-library-logger');
25
- const uploadUseCase = require('./libs/UploadUseCase')
26
-
27
- const { getGraphServiceTag, getServiceName } = require('./ServiceConfig')
28
- const { createLinkTypeId, createFlowTypeConcat } = require('./Utils');
29
- const hash = require('@izara_project/izara-shared-core').objectHash;
30
- const {
31
- validateObjectSchema,
32
- validateRelationshipSchema,
33
- validateRefRelationshipSchema,
34
- findLinkByObjTypeV2,
35
- validateBasicFlowSchema,
36
-
37
- getUsedFieldNamesOfIdentifiers,
38
- createObjType,
39
- getIdentifierTypeByPriority,
40
- } = require("./Utils");
41
-
42
- const {
43
- getDataFromPath,
44
-
45
- getAllLocalObjectSchemasWithoutHierarchy,
46
- getLocalObjectSchemasWithHierarchy,
47
-
48
- getObjSchemaS3WithHierarchy,
49
-
50
- getRelationshipSchema,
51
- getObjSchemaS3WithCache,
52
-
53
- getAllLocalFlowSchemas,
54
- getAllLocalRefObjectRelationshipSchema,
55
- getAllLocalRelationshipSchema,
56
- getLocalRelationshipSchemas,
57
- getObjectSchemaCombineFieldNamesWithCache,
58
- } = require("./GetObjectSchema");
59
-
60
- const {
61
- LOCAL_FILENAME,
62
- STORAGE_TYPES,
63
- createValidationFieldNameForEachType,
64
- S3_UPLOAD_TYPE,
65
- FLOW_SCHEMA_HOOK_STATE,
66
- HANDLER,
67
- OBJECT_SCHEMA_BUCKET_NAME
68
- } = require("./Consts");
69
- const { validateObjType } = require('@izara_project/izara-shared-service-schemas').validateObjType;
21
+ import readYamlFile from 'read-yaml-file';
22
+ import { inMemoryCacheLib, NoRetryError } from '@izara_project/izara-core-library-core';
23
+ import { objectHash as hash } from '@izara_project/izara-shared-core';
24
+ import Logger from '@izara_project/izara-core-library-logger';
25
+ import uploadUseCase from './libs/UploadUseCase.js';
26
+
27
+ import serviceConfig from './ServiceConfig.js';
28
+ import utils from './Utils.js';
29
+ import getObjectSchema from './GetObjectSchema.js';
30
+ import consts from './Consts.js'
31
+ import { validateObjType } from '@izara_project/izara-shared-service-schemas';
70
32
 
71
33
  // module.exports.createFieldNameUniqueRequestId = (prefix = 'cache') => {
72
34
  // return prefix + "UniqueRequestId";
@@ -137,7 +99,7 @@ async function generateValidatorSchemaTreePerFieldName(_izContext, fieldName, fi
137
99
  }
138
100
  )
139
101
 
140
- let childObjectSchema = await getObjSchemaS3WithHierarchy(
102
+ let childObjectSchema = await getObjectSchema.getObjSchemaS3WithHierarchy(
141
103
  _izContext,
142
104
  fieldNameSetting.fromObjType
143
105
  );
@@ -173,7 +135,7 @@ async function generateValidatorSchemaTreePerFieldName(_izContext, fieldName, fi
173
135
  } else {
174
136
  Object.assign(
175
137
  validatorTree[fieldName],
176
- createValidationFieldNameForEachType(
138
+ consts.createValidationFieldNameForEachType(
177
139
  fieldNameSetting.type,
178
140
  fieldNameSetting.validation
179
141
  )
@@ -276,7 +238,7 @@ async function validatorSchemaTreeIdentifiersFieldNames(_izContext, objectSchema
276
238
  * @param {String} objType.serviceTag
277
239
  */
278
240
  async function generateRelationshipValidatorSchemaForCreate(_izContext, objType) {
279
- const validateObjTypeResult = validateObjType(objType);
241
+ const validateObjTypeResult = validateObjType.validateObjType(objType);
280
242
  if (validateObjTypeResult.errorsFound.length > 0) {
281
243
  _izContext.logger.error("generateRelationshipValidatorSchemaForCreate validateObjTypeResult", validateObjTypeResult);
282
244
  throw new NoRetryError(`Invalid objType:${JSON.stringify(objType)}, ${validateObjTypeResult.errorsFound.join(", ")}`);
@@ -332,7 +294,7 @@ async function generateRelationshipValidatorSchemaForCreate(_izContext, objType)
332
294
  && parent.linkConfig.requiredOnCreate === true
333
295
  ) {
334
296
 
335
- let parentObjSchema = await getObjSchemaS3WithHierarchy(_izContext, parent.objType);
297
+ let parentObjSchema = await getObjectSchema.getObjSchemaS3WithHierarchy(_izContext, parent.objType);
336
298
 
337
299
  if (!parentObjSchema) {
338
300
  throw new NoRetryError(`Not found parent ${JSON.stringify(parent.objType)} in relationship:${relTag}`);
@@ -413,7 +375,7 @@ async function generateRelationshipValidatorSchemaForCreate(_izContext, objType)
413
375
  * @returns
414
376
  */
415
377
  async function generateValidatorSchemaForCreate(_izContext, objType, settings = { specificFieldNames: [] }) {
416
- const validateObjTypeResult = validateObjType(objType);
378
+ const validateObjTypeResult = validateObjType.validateObjType(objType);
417
379
  if (validateObjTypeResult.errorsFound.length > 0) {
418
380
  _izContext.logger.error("generateValidatorSchemaForCreate validateObjTypeResult", validateObjTypeResult);
419
381
  throw new NoRetryError(`Invalid objType:${JSON.stringify(objType)}, ${validateObjTypeResult.errorsFound.join(", ")}`);
@@ -423,7 +385,7 @@ async function generateValidatorSchemaForCreate(_izContext, objType, settings =
423
385
  settings
424
386
  })
425
387
 
426
- const objectSchema = await getObjSchemaS3WithHierarchy(_izContext, objType);
388
+ const objectSchema = await getObjectSchema.getObjSchemaS3WithHierarchy(_izContext, objType);
427
389
  _izContext.logger.debug("objectSchema in generateValidatorSchemaForCreate", objectSchema)
428
390
  let usedFieldNamesData = {};
429
391
  let requiredFieldNames = [];
@@ -539,17 +501,17 @@ async function generateValidatorSchemaForUpdate(_izContext, objType, settings =
539
501
  objType,
540
502
  setting: settings,
541
503
  })
542
- // const objType = createObjType(objectType);
543
- const objectSchema = await getObjSchemaS3WithHierarchy(_izContext, objType);
504
+ // const objType = utils.createObjType(objectType);
505
+ const objectSchema = await getObjectSchema.getObjSchemaS3WithHierarchy(_izContext, objType);
544
506
  // _izContext.logger.debug("objectSchema", objectSchema)
545
507
 
546
508
  const objectSchemas = await uploadUseCase.generateObjectSchemaForCombineFieldNames(_izContext, objectSchema)
547
509
  // _izContext.logger.debug("objectSchemas", objectSchemas)
548
510
 
549
- let usedIdentifierTypes = getIdentifierTypeByPriority(_izContext, [], objectSchema);
511
+ let usedIdentifierTypes = utils.getIdentifierTypeByPriority(_izContext, [], objectSchema);
550
512
  _izContext.logger.debug({ usedIdentifierTypes });
551
513
  // collect requiredFieldNames by fieldName that includes in identifiers
552
- let identifiersFieldNames = getUsedFieldNamesOfIdentifiers(_izContext, objectSchemas.identifiers, usedIdentifierTypes);
514
+ let identifiersFieldNames = utils.getUsedFieldNamesOfIdentifiers(_izContext, objectSchemas.identifiers, usedIdentifierTypes);
553
515
  // _izContext.logger.debug("identifiersFieldNames", identifiersFieldNames)
554
516
  let fieldNameCanUpdates = [];
555
517
  let versionedDataFieldNameCanUpdates = [];
@@ -674,7 +636,7 @@ async function generateValidatorSchemaForUpdate(_izContext, objType, settings =
674
636
  // let versionedDataLabel = versionedDataFieldNameSetting.versionedDataLabel
675
637
  // if (versionedDataFieldNameSetting.hasOwnProperty("versionedDataLabel") && defaultFieldNames.includes(versionedDataFieldName)) {
676
638
  // Object.assign(versionedDataReturnInFieldsObjInstanceFull, {
677
- // [versionedDataFieldName]: createValidationFieldNameForEachType(
639
+ // [versionedDataFieldName]: consts.createValidationFieldNameForEachType(
678
640
  // versionedDataFieldNameSetting.type,
679
641
  // versionedDataFieldNameSetting.validation
680
642
  // )
@@ -715,8 +677,8 @@ async function generateValidatorSchemaForUpdate(_izContext, objType, settings =
715
677
  *
716
678
  * @returns {object} json validator schema
717
679
  */
718
- async function generateValidatorSchemaForIdentifier(_izContext, objType, settings = { bucketName: OBJECT_SCHEMA_BUCKET_NAME }) {
719
- const validateObjTypeResult = validateObjType(objType);
680
+ async function generateValidatorSchemaForIdentifier(_izContext, objType, settings = { bucketName: consts.OBJECT_SCHEMA_BUCKET_NAME }) {
681
+ const validateObjTypeResult = validateObjType.validateObjType(objType);
720
682
  if (validateObjTypeResult.errorsFound.length > 0) {
721
683
  _izContext.logger.error("generateValidatorSchemaForIdentifier validateObjTypeResult", validateObjTypeResult);
722
684
  throw new NoRetryError(`Invalid objType:${JSON.stringify(objType)}, ${validateObjTypeResult.errorsFound.join(", ")}`);
@@ -725,7 +687,7 @@ async function generateValidatorSchemaForIdentifier(_izContext, objType, setting
725
687
  objType,
726
688
  })
727
689
 
728
- const objectSchema = await getObjSchemaS3WithHierarchy(_izContext, objType, settings.bucketName);
690
+ const objectSchema = await getObjectSchema.getObjSchemaS3WithHierarchy(_izContext, objType, settings.bucketName);
729
691
 
730
692
  let generatedIdentifiersValidatorSchema = await validatorSchemaTreeIdentifiersFieldNames(_izContext, objectSchema, settings.bucketName);
731
693
  _izContext.logger.debug("generatedIdentifiersValidatorSchema: ", generatedIdentifiersValidatorSchema);
@@ -758,7 +720,7 @@ async function generateValidatorSchemaForIdentifier(_izContext, objType, setting
758
720
  * @returns
759
721
  */
760
722
  async function filteredFieldNamesOfValidatorSchema(_izContext, objType, requiredFieldNames, usedFieldNames) {
761
- const validateObjTypeResult = validateObjType(objType);
723
+ const validateObjTypeResult = validateObjType.validateObjType(objType);
762
724
  if (validateObjTypeResult.errorsFound.length > 0) {
763
725
  _izContext.logger.error("filteredFieldNamesOfValidatorSchema validateObjTypeResult", validateObjTypeResult);
764
726
  throw new NoRetryError(`Invalid objType:${JSON.stringify(objType)}, ${validateObjTypeResult.errorsFound.join(", ")}`);
@@ -806,7 +768,7 @@ async function filteredFieldNamesOfValidatorSchema(_izContext, objType, required
806
768
  * 3 >> not required, Use for validate only
807
769
  */
808
770
  async function generateValidatorSchemaForExplodedData(_izContext, objType) {
809
- const validateObjTypeResult = validateObjType(objType);
771
+ const validateObjTypeResult = validateObjType.validateObjType(objType);
810
772
  if (validateObjTypeResult.errorsFound.length > 0) {
811
773
  _izContext.logger.error("generateValidatorSchemaForExplodedData validateObjTypeResult", validateObjTypeResult);
812
774
  throw new NoRetryError(`Invalid objType:${JSON.stringify(objType)}, ${validateObjTypeResult.errorsFound.join(", ")}`);
@@ -818,7 +780,7 @@ async function generateValidatorSchemaForExplodedData(_izContext, objType) {
818
780
  properties: {}
819
781
  };
820
782
 
821
- let objectSchema = await getObjectSchemaCombineFieldNamesWithCache(_izContext, objType);
783
+ let objectSchema = await getObjectSchema.getObjectSchemaCombineFieldNamesWithCache(_izContext, objType);
822
784
  // generate validatorSchema for each fieldName
823
785
  for (let [fieldName, fieldData] of Object.entries(objectSchema.fieldNames)) {
824
786
  let fieldNameValidator = await generateValidatorFieldNameWithCache(_izContext, fieldName, fieldData);
@@ -914,7 +876,7 @@ async function generateValidatorFieldName(_izContext, fieldName, fieldData) {
914
876
  throw new Error(`Invalid reference fieldName:${fieldName}`);
915
877
  }
916
878
 
917
- let objectSchemaChild = await getObjSchemaS3WithHierarchy(
879
+ let objectSchemaChild = await getObjectSchema.getObjSchemaS3WithHierarchy(
918
880
  _izContext,
919
881
  // {
920
882
  // serviceTag: fieldData.fromServiceNameTag,
@@ -964,7 +926,7 @@ async function generateValidatorFieldName(_izContext, fieldName, fieldData) {
964
926
  // })
965
927
  // }
966
928
  Object.assign(returnValidator, {
967
- [compositeKey]: createValidationFieldNameForEachType(
929
+ [compositeKey]: consts.createValidationFieldNameForEachType(
968
930
  validateType,
969
931
  fieldValidation
970
932
  )
@@ -991,7 +953,7 @@ async function generateValidatorFieldName(_izContext, fieldName, fieldData) {
991
953
  // ...fieldValidation
992
954
  // }
993
955
  [fieldName]:
994
- createValidationFieldNameForEachType(
956
+ consts.createValidationFieldNameForEachType(
995
957
  validateType,
996
958
  fieldValidation
997
959
  )
@@ -1009,9 +971,9 @@ async function generateValidatorFieldName(_izContext, fieldName, fieldData) {
1009
971
  */
1010
972
  async function validateLocalSchema(_izContext, schemasPath, serviceConfigPath) {
1011
973
  try {
1012
- const serviceConfig = readYamlFile.sync(serviceConfigPath);
1013
- const iz_serviceTag = serviceConfig.main_config.iz_serviceTag;
1014
- const iz_serviceSchemaBucketName = serviceConfig.main_config.iz_serviceSchemaBucketName
974
+ const config = readYamlFile.sync(serviceConfigPath);
975
+ const iz_serviceTag = config.main_config.iz_serviceTag;
976
+ const iz_serviceSchemaBucketName = config.main_config.iz_serviceSchemaBucketName
1015
977
  console.log("schemasPath", schemasPath);
1016
978
  console.log("serviceConfigPath", serviceConfigPath)
1017
979
 
@@ -1020,7 +982,7 @@ async function validateLocalSchema(_izContext, schemasPath, serviceConfigPath) {
1020
982
  let objSchema
1021
983
  let errorMessage
1022
984
  if (objType.serviceTag === iz_serviceTag) {
1023
- objSchema = await getLocalObjectSchemasWithHierarchy(_izContext, objType.objectType, schemasPath)
985
+ objSchema = await getObjectSchema.getLocalObjectSchemasWithHierarchy(_izContext, objType.objectType, schemasPath)
1024
986
  .then(res => {
1025
987
  return res.records[0]
1026
988
  })
@@ -1029,7 +991,7 @@ async function validateLocalSchema(_izContext, schemasPath, serviceConfigPath) {
1029
991
  errorMessage = "local not exists"
1030
992
  }
1031
993
  } else {
1032
- objSchema = await getObjSchemaS3WithHierarchy(_izContext, objType);
994
+ objSchema = await getObjectSchema.getObjSchemaS3WithHierarchy(_izContext, objType);
1033
995
  errorMessage = "s3 not exists"
1034
996
  }
1035
997
  return [objSchema, errorMessage]
@@ -1060,14 +1022,14 @@ async function validateLocalSchema(_izContext, schemasPath, serviceConfigPath) {
1060
1022
  return validateStatus;
1061
1023
  }
1062
1024
 
1063
- const allObjectSchema = await getAllLocalObjectSchemasWithoutHierarchy(_izContext, schemasPath).then(res => res.records);
1064
- const allObjectRelationships = getAllLocalRelationshipSchema(_izContext, schemasPath);
1065
- const allReferenceObjectRelationships = getAllLocalRefObjectRelationshipSchema(_izContext, schemasPath);
1066
- const allFlowSchemas = await getAllLocalFlowSchemas(_izContext, schemasPath).then(res => res.records);
1067
-
1025
+ const allObjectSchema = await getObjectSchema.getAllLocalObjectSchemasWithoutHierarchy(_izContext, schemasPath).then(res => res.records);
1026
+ const allObjectRelationships = await getObjectSchema.getAllLocalRelationshipSchema(_izContext, schemasPath);
1027
+ const allReferenceObjectRelationships = await getObjectSchema.getAllLocalRefObjectRelationshipSchema(_izContext, schemasPath);
1028
+ const allFlowSchemas = await getObjectSchema.getAllLocalFlowSchemas(_izContext, schemasPath).then(res => res.records);
1029
+ // console.log({ allObjectSchema, allObjectRelationships, allReferenceObjectRelationships, allFlowSchemas })
1068
1030
  // validate all schema
1069
1031
  for (const objSchema of allObjectSchema) {
1070
- const [status, errors] = validateObjectSchema(_izContext, objSchema);
1032
+ const [status, errors] = utils.validateObjectSchema(_izContext, objSchema);
1071
1033
 
1072
1034
  if (!status) {
1073
1035
  validateStatus.status = false;
@@ -1081,8 +1043,8 @@ async function validateLocalSchema(_izContext, schemasPath, serviceConfigPath) {
1081
1043
  for (const storageTag in objSchema.storageResources) {
1082
1044
  const storageResource = objSchema.storageResources[storageTag];
1083
1045
 
1084
- if (storageResource.storageType === STORAGE_TYPES.graph) {
1085
- const graphServiceTag = await getGraphServiceTag(_izContext, storageResource.graphServerTag, iz_serviceSchemaBucketName);
1046
+ if (storageResource.storageType === consts.STORAGE_TYPES.graph) {
1047
+ const graphServiceTag = await serviceConfig.getGraphServiceTag(_izContext, storageResource.graphServerTag, iz_serviceSchemaBucketName);
1086
1048
 
1087
1049
  if (!graphServiceTag) {
1088
1050
  validateStatus.status = false;
@@ -1090,7 +1052,7 @@ async function validateLocalSchema(_izContext, schemasPath, serviceConfigPath) {
1090
1052
  }
1091
1053
  }
1092
1054
  // validate storageResource TableName should not be the same in all objectSchema
1093
- if (storageResource.storageType === STORAGE_TYPES.dynamoDB) {
1055
+ if (storageResource.storageType === consts.STORAGE_TYPES.dynamoDB) {
1094
1056
  if (tableNameList.has(storageResource.tableName)) {
1095
1057
  validateStatus.status = false;
1096
1058
  validateStatus.validateErrors.push(`objectType:${objSchema.objectType} storageResources. Should not have duplicate tableName inside storageResources`);
@@ -1134,7 +1096,7 @@ async function validateLocalSchema(_izContext, schemasPath, serviceConfigPath) {
1134
1096
 
1135
1097
  // validate relationships schema
1136
1098
  for (const relSchema of allObjectRelationships) {
1137
- const [status, errors] = validateRelationshipSchema(_izContext, relSchema);
1099
+ const [status, errors] = utils.validateRelationshipSchema(_izContext, relSchema);
1138
1100
 
1139
1101
  if (!status) {
1140
1102
  validateStatus.status = false;
@@ -1152,8 +1114,8 @@ async function validateLocalSchema(_izContext, schemasPath, serviceConfigPath) {
1152
1114
  for (const storageTag in relData.storageResources) {
1153
1115
  const storageResource = relData.storageResources[storageTag];
1154
1116
 
1155
- if (storageResource.storageType === STORAGE_TYPES.graph) {
1156
- const graphServiceTag = await getGraphServiceTag(_izContext, storageResource.graphServerTag, iz_serviceSchemaBucketName);
1117
+ if (storageResource.storageType === consts.STORAGE_TYPES.graph) {
1118
+ const graphServiceTag = await serviceConfig.getGraphServiceTag(_izContext, storageResource.graphServerTag, iz_serviceSchemaBucketName);
1157
1119
 
1158
1120
  if (!graphServiceTag) {
1159
1121
  validateStatus.status = false;
@@ -1162,7 +1124,7 @@ async function validateLocalSchema(_izContext, schemasPath, serviceConfigPath) {
1162
1124
  }
1163
1125
 
1164
1126
 
1165
- if (storageResource.storageType === STORAGE_TYPES.dynamoDB) {
1127
+ if (storageResource.storageType === consts.STORAGE_TYPES.dynamoDB) {
1166
1128
  if (tableNameList.has(storageResource.tableName)) {
1167
1129
  validateStatus.status = false;
1168
1130
  validateStatus.validateErrors.push(`relationshipTag:${relTagName} storageResources. Should not have duplicate tableName inside storageResources`);
@@ -1191,7 +1153,7 @@ async function validateLocalSchema(_izContext, schemasPath, serviceConfigPath) {
1191
1153
  // canChangeToRelSchema = canChangeRelSchemaLocal[relData.canChangeToRelType.relationshipTag]
1192
1154
  // }
1193
1155
  // } else {
1194
- // canChangeToRelSchema = await getRelationshipSchema(_izContext, { relationshipTag: relData.canChangeToRelType.relationshipTag, serviceTag: relData.canChangeToRelType.serviceTag }) // return {}
1156
+ // canChangeToRelSchema = await getObjectSchema.getRelationshipSchema(_izContext, { relationshipTag: relData.canChangeToRelType.relationshipTag, serviceTag: relData.canChangeToRelType.serviceTag }) // return {}
1195
1157
  // }
1196
1158
 
1197
1159
  // if (!canChangeToRelSchema || !Object.keys(canChangeToRelSchema).length) {
@@ -1274,7 +1236,7 @@ async function validateLocalSchema(_izContext, schemasPath, serviceConfigPath) {
1274
1236
 
1275
1237
  // validate reference relationship
1276
1238
  for (let refRelSchema of allReferenceObjectRelationships) {
1277
- const [status, errors] = validateRefRelationshipSchema(_izContext, refRelSchema, iz_serviceTag);
1239
+ const [status, errors] = utils.validateRefRelationshipSchema(_izContext, refRelSchema, iz_serviceTag);
1278
1240
  if (!status) {
1279
1241
  validateStatus.status = false;
1280
1242
  validateStatus.validateErrors.push(errors);
@@ -1290,7 +1252,7 @@ async function validateLocalSchema(_izContext, schemasPath, serviceConfigPath) {
1290
1252
 
1291
1253
  if (allFlowSchemas) {
1292
1254
  for (const flowSchema of allFlowSchemas) {
1293
- const [status, errors] = validateBasicFlowSchema(_izContext, flowSchema)
1255
+ const [status, errors] = utils.validateBasicFlowSchema(_izContext, flowSchema)
1294
1256
 
1295
1257
  if (!flowSchema.hasOwnProperty("objType")) {
1296
1258
  validateStatus.status = false;
@@ -1306,7 +1268,7 @@ async function validateLocalSchema(_izContext, schemasPath, serviceConfigPath) {
1306
1268
  let dynamoDBStorageTags = [];
1307
1269
 
1308
1270
  for (const [storageTag, storageResource] of Object.entries(objSchema.storageResources)) {
1309
- if (storageResource.storageType === STORAGE_TYPES.dynamoDB) {
1271
+ if (storageResource.storageType === consts.STORAGE_TYPES.dynamoDB) {
1310
1272
  dynamoDBStorageTags.push(storageTag)
1311
1273
  }
1312
1274
  }
@@ -1317,7 +1279,7 @@ async function validateLocalSchema(_izContext, schemasPath, serviceConfigPath) {
1317
1279
  } else {
1318
1280
 
1319
1281
  if (flowSchema.statusType === "statusField") {
1320
- let specificFieldNames = Object.values(createSpecificFieldNameForCacheTable(createFlowTypeConcat(_izContext, { flowTag: flowSchema.flowTag, serviceTag: iz_serviceTag }), 'statusField'))
1282
+ let specificFieldNames = Object.values(createSpecificFieldNameForCacheTable(utils.createFlowTypeConcat(_izContext, { flowTag: flowSchema.flowTag, serviceTag: iz_serviceTag }), 'statusField'))
1321
1283
 
1322
1284
  for (const specificFieldName of specificFieldNames) { // check for specific fieldName
1323
1285
  if (objSchema.fieldNames.hasOwnProperty(specificFieldName)) {
@@ -1333,7 +1295,7 @@ async function validateLocalSchema(_izContext, schemasPath, serviceConfigPath) {
1333
1295
 
1334
1296
 
1335
1297
  } else if (flowSchema.statusType === "storedCache" || flowSchema.statusType === "triggerCache") {
1336
- let specificFieldNames = Object.values(createSpecificFieldNameForCacheTable(createFlowTypeConcat(_izContext, { flowTag: flowSchema.flowTag, serviceTag: iz_serviceTag }), "cacheTable"))
1298
+ let specificFieldNames = Object.values(createSpecificFieldNameForCacheTable(utils.createFlowTypeConcat(_izContext, { flowTag: flowSchema.flowTag, serviceTag: iz_serviceTag }), "cacheTable"))
1337
1299
 
1338
1300
  for (const specificFieldName of specificFieldNames) { // check for specific fieldName
1339
1301
  if (objSchema.fieldNames.hasOwnProperty(specificFieldName)) {
@@ -1368,7 +1330,7 @@ async function validateLocalSchema(_izContext, schemasPath, serviceConfigPath) {
1368
1330
  // validate ref relationships in external path s3
1369
1331
  await Promise.all(
1370
1332
  allReferenceObjectRelationships.map(async (refRelSchema) => {
1371
- const relSchemaFromRef = await getRelationshipSchema(
1333
+ const relSchemaFromRef = await getObjectSchema.getRelationshipSchema(
1372
1334
  _izContext,
1373
1335
  {
1374
1336
  serviceTag: refRelSchema.relationshipServiceTag,
@@ -1380,7 +1342,7 @@ async function validateLocalSchema(_izContext, schemasPath, serviceConfigPath) {
1380
1342
  validateStatus.referenceErrors.push(`Invalid reference relationship of objectType: '${refRelSchema.objectType}' >> relationshipTag: '${refRelSchema.relationshipTag}' not exists in service: '${refRelSchema.relationshipServiceTag}'`)
1381
1343
  } else {
1382
1344
 
1383
- const linkRecords = findLinkByObjTypeV2(
1345
+ const linkRecords = utils.findLinkByObjTypeV2(
1384
1346
  _izContext,
1385
1347
  {
1386
1348
  objectType: refRelSchema.objectType,
@@ -1410,7 +1372,7 @@ async function validateLocalSchema(_izContext, schemasPath, serviceConfigPath) {
1410
1372
  }
1411
1373
  }
1412
1374
 
1413
- module.exports = {
1375
+ export default {
1414
1376
  generateValidatorSchemaForCreate,
1415
1377
  generateValidatorSchemaForUpdate,
1416
1378
  generateValidatorSchemaForIdentifier,