@izara_project/izara-core-library-service-schemas 1.0.67 → 1.0.69

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@izara_project/izara-core-library-service-schemas",
3
- "version": "1.0.67",
3
+ "version": "1.0.69",
4
4
  "description": "Schemas for the service and objects it controls",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -28,7 +28,7 @@
28
28
  "@izara_project/izara-core-library-lambda": "^1.0.4",
29
29
  "@izara_project/izara-core-library-logger": "^1.0.7",
30
30
  "@izara_project/izara-shared-core": "^1.0.2",
31
- "@izara_project/izara-shared-service-schemas": "^1.0.15",
31
+ "@izara_project/izara-shared-service-schemas": "^1.0.16",
32
32
  "glob": "^11.0.2",
33
33
  "lodash": "^4.17.21",
34
34
  "object-hash": "^3.0.0",
@@ -36,6 +36,7 @@ const {
36
36
  getObjectRelationship: getObjectRelationshipShared,
37
37
  getRequiredOnCreateLinks: getRequiredOnCreateLinksShared,
38
38
  getLinkConfigByLinkTypeId: getLinkConfigByLinkTypeIdShared,
39
+ getObjTypeHierarchy: getObjTypeHierarchyShared
39
40
  } = sharedServiceSchema.getObjectSchema;
40
41
  const { validateObjType, validateRelType, validateFlowType } = sharedServiceSchema.validateObjType;
41
42
  const {
@@ -840,16 +841,17 @@ const getLinkConfigWithCache = inMemoryCacheLib(
840
841
  * @param {String} relType.relationshipTag
841
842
  * @returns {Promise<{from:Object, to:Object}>}
842
843
  */
843
- async function getLinkConfigByLinkTypeId(_izContext, firstObjType, secondObjType, relType, direction) {
844
+ async function getLinkConfigByLinkTypeId(_izContext, firstObjType, secondObjType, relType, direction, settings) {
844
845
 
845
846
  _izContext.logger.debug("getLinkConfigByLinkTypeId: ", {
846
847
  firstObjType,
847
848
  secondObjType,
848
849
  relType,
849
- direction
850
+ direction,
851
+ settings
850
852
  });
851
853
 
852
- return await getLinkConfigByLinkTypeIdShared(getSchemaByNameWithCache, firstObjType, secondObjType, relType, direction);
854
+ return await getLinkConfigByLinkTypeIdShared(getSchemaByNameWithCache, firstObjType, secondObjType, relType, direction, settings);
853
855
  }
854
856
 
855
857
  /**
@@ -1009,6 +1011,33 @@ function getAllLocalRefObjectRelationshipSchema(_izContext, objSchemaPath = LOCA
1009
1011
 
1010
1012
  }
1011
1013
 
1014
+ /**
1015
+ * create hierarchy of objType
1016
+ *
1017
+ * @param {object} _izContext
1018
+ * @param {object} objType
1019
+ * @param {object} currentHierarchy
1020
+ * @param {number} iter
1021
+ * @returns
1022
+ */
1023
+ async function getObjTypeHierarchy(_izContext, objType) {
1024
+ return await getObjTypeHierarchyShared(getSchemaByNameWithCache, objType);
1025
+ }
1026
+
1027
+ /**
1028
+ * Caches the getObjTypeHierarchy function
1029
+ *
1030
+ * @see {@link getObjTypeHierarchy}
1031
+ */
1032
+ const getObjTypeHierarchyWithCache = inMemoryCacheLib(
1033
+ getObjTypeHierarchy,
1034
+ { //seting
1035
+ max: 100, maxAge: 8640000, promise: true, profileName: 'getObjTypeHierarchy',
1036
+ normalizer: function (args) {
1037
+ return hash([args[1]])
1038
+ }
1039
+ }
1040
+ )
1012
1041
 
1013
1042
  module.exports = {
1014
1043
  // getObjectTypes,
@@ -1063,7 +1092,8 @@ module.exports = {
1063
1092
  getFlowSchemaS3,
1064
1093
  getFlowSchemaS3WithCache,
1065
1094
 
1066
-
1095
+ getObjTypeHierarchy,
1096
+ getObjTypeHierarchyWithCache
1067
1097
  }
1068
1098
 
1069
1099
 
@@ -929,7 +929,6 @@ async function validateLocalSchema(_izContext, schemasPath, serviceConfigPath) {
929
929
  const allObjectRelationships = getAllLocalRelationshipSchema(_izContext, schemasPath);
930
930
  const allReferenceObjectRelationships = getAllLocalRefObjectRelationshipSchema(_izContext, schemasPath);
931
931
  const allFlowSchemas = await getAllLocalFlowSchemas(_izContext, schemasPath).then(res => res.records);
932
- console.log("allObjectRelationships", allObjectRelationships)
933
932
 
934
933
  // validate all schema
935
934
  for (const objSchema of allObjectSchema) {
@@ -1129,6 +1128,23 @@ async function validateLocalSchema(_izContext, schemasPath, serviceConfigPath) {
1129
1128
  }
1130
1129
  })
1131
1130
  )
1131
+ // validate dulicate link
1132
+ let relSchemaLinkType = new Set();
1133
+ for (let link of relData.links) {
1134
+ console.log("link", link)
1135
+ let linkTypeRelSchema = createLinkTypeId(_izContext,
1136
+ link.from.objType,
1137
+ link.to.objType,
1138
+ { relationshipTag: relTagName, serviceTag: process.env.iz_serviceTag },
1139
+ "from"
1140
+ )
1141
+
1142
+ if (!relSchemaLinkType.has(linkTypeRelSchema)) {
1143
+ relSchemaLinkType.add(linkTypeRelSchema)
1144
+ } else {
1145
+ throw new NoRetryError(`error Schema relationship duplicate link with objType ${JSON.stringify(link.from.objType)} and ${JSON.stringify(link.to.objType)}`)
1146
+ }
1147
+ }
1132
1148
  }
1133
1149
  }
1134
1150
 
@@ -1152,13 +1168,6 @@ async function validateLocalSchema(_izContext, schemasPath, serviceConfigPath) {
1152
1168
  for (const flowSchema of allFlowSchemas) {
1153
1169
  const [status, errors] = validateBasicFlowSchema(_izContext, flowSchema)
1154
1170
 
1155
- if (flowSchema.handleObj === "multi") {
1156
- if (flowSchema.outputTopic === true) {
1157
- validateStatus.status = false;
1158
- validateStatus.validateErrors.push(`flowSchema ${flowSchema.flowTag} should not have outputTopic if handleObj === true`)
1159
- }
1160
- }
1161
-
1162
1171
  if (flowSchema.statusType === "storedCache" || flowSchema.statusType === "statusField" || flowSchema.statusType === "triggerCache") {
1163
1172
  if (!flowSchema.hasOwnProperty("objType")) {
1164
1173
  validateStatus.status = false;
@@ -20,17 +20,17 @@ const { createRelTypeConcat, createLinkTypeId } = require('../Utils');
20
20
  const getObjectSchema = require('../GetObjectSchema');
21
21
  const serviceConfig = require('../ServiceConfig');
22
22
  const { STORAGE_TYPES } = require('../Consts')
23
- const { createObjTypeHierarchy } = require('../libs/RelSchemaLib')
23
+ const { getObjTypeHierarchy } = require('../GetObjectSchema')
24
24
 
25
25
  async function validateRequiredOnCreateLinks(_izContext, objType, relationships, settings = {}) {
26
26
  _izContext.logger.debug("validateRequiredOnCreateLinks:::", { objType, relationships, settings })
27
27
 
28
28
 
29
- let objectHie = await createObjTypeHierarchy(_izContext, objType);
29
+ let objectHie = await getObjTypeHierarchy(_izContext, objType);
30
30
  _izContext.logger.debug("objectHierarchy::", objectHie)
31
31
 
32
32
  if (relationships.length) {
33
- let targetHierarchy = await createObjTypeHierarchy(_izContext, relationships[0].targetObjType);
33
+ let targetHierarchy = await getObjTypeHierarchy(_izContext, relationships[0].targetObjType);
34
34
  _izContext.logger.debug("targetHierarchy::", targetHierarchy)
35
35
  }
36
36
 
@@ -90,7 +90,7 @@ async function validateRequiredOnCreateLinks(_izContext, objType, relationships,
90
90
 
91
91
  for (let link of usedLinkGroup) {
92
92
  // check other with targetObjType, check linkType of other should be 'one',
93
- let targetObjTypeHierarchy = await createObjTypeHierarchy(_izContext, relationship.targetObjType);
93
+ let targetObjTypeHierarchy = await getObjTypeHierarchy(_izContext, relationship.targetObjType);
94
94
  _izContext.logger.debug(" ::", targetObjTypeHierarchy)
95
95
 
96
96
  // if (link.other.objType.objectType === relationship.targetObjType.objectType) {
@@ -23,43 +23,7 @@ const hash = require('@izara_project/izara-shared-core').objectHash;
23
23
  const { NoRetryError } = require('@izara_project/izara-core-library-core');
24
24
  const getObjectSchema = require("../GetObjectSchema");
25
25
  const { validateObjType: { validateObjType } } = require("@izara_project/izara-shared-service-schemas");
26
-
27
- /**
28
- * create hierarchy of objType
29
- *
30
- * @param {object} _izContext
31
- * @param {object} objType
32
- * @param {object} currentHierarchy
33
- * @param {number} iter
34
- * @returns
35
- */
36
- async function createObjTypeHierarchy(_izContext, objType, passObjTypeHierarchy, iter = 1) {
37
- if (iter >= 20) {
38
- throw NoRetryError("createObjTypeHierarchy reach limit iteration");
39
- }
40
-
41
- validateObjType(objType);
42
-
43
- let objTypeHierarchy
44
-
45
- if (!passObjTypeHierarchy) {
46
- objTypeHierarchy = [objType];
47
- } else {
48
- objTypeHierarchy = passObjTypeHierarchy;
49
- }
50
-
51
- const objectSchema = await getObjectSchema.getObjSchemaS3WithCache(_izContext, objType);
52
-
53
- if (objectSchema.extendObjType) {
54
- iter++;
55
- objTypeHierarchy.push(objectSchema.extendObjType);
56
- await createObjTypeHierarchy(_izContext, objectSchema.extendObjType, objTypeHierarchy, iter);
57
- }
58
-
59
- return objTypeHierarchy;
60
- }
61
-
62
-
26
+ const { getObjTypeHierarchy } = require('../GetObjectSchema')
63
27
  /**
64
28
  * helper function for find link of 2 objects in links and refactor each link
65
29
  *
@@ -85,8 +49,8 @@ async function findLinksByObjTypes(_izContext, objTypes, relatoinshipLinks) {
85
49
  const secondObjType = objTypes[1];
86
50
 
87
51
  // first create hierarchy of each objType
88
- const firstObjTypeTree = await createObjTypeHierarchy(_izContext, objTypes[0]);
89
- const secondObjTypeTree = await createObjTypeHierarchy(_izContext, objTypes[1]);
52
+ const firstObjTypeTree = await getObjTypeHierarchy(_izContext, objTypes[0]);
53
+ const secondObjTypeTree = await getObjTypeHierarchy(_izContext, objTypes[1]);
90
54
 
91
55
  const firstObjTypeTreeHashes = firstObjTypeTree.reduce(
92
56
  (result, objType) => {
@@ -135,6 +99,5 @@ async function findLinksByObjTypes(_izContext, objTypes, relatoinshipLinks) {
135
99
  }
136
100
 
137
101
  module.exports = {
138
- createObjTypeHierarchy,
139
102
  findLinksByObjTypes
140
103
  }