@izara_project/izara-core-library-service-schemas 1.0.66 → 1.0.68

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.66",
3
+ "version": "1.0.68",
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
 
@@ -256,76 +256,75 @@ async function uploadObjectSchemaByUseCase(_izContext) {
256
256
 
257
257
  for (let objSchema of allObjectSchema) {
258
258
  // ignore objSchema that not has properties in fieldNames
259
- if (objSchema.hasOwnProperty("fieldNames") && Object.keys(objSchema.fieldNames).length) {
260
259
 
261
- // case All
262
- uploadList.push(
263
- uploadObjectToS3(
260
+ // case All
261
+ uploadList.push(
262
+ uploadObjectToS3(
263
+ _izContext,
264
+ UPLOAD_PATH_S3.objectSchemaAll(
264
265
  _izContext,
265
- UPLOAD_PATH_S3.objectSchemaAll(
266
- _izContext,
267
- {
268
- serviceTag: process.env.iz_serviceTag,
269
- objectType: objSchema.objectType
270
- }
271
- ),
272
- objSchema
273
- )
274
- );
266
+ {
267
+ serviceTag: process.env.iz_serviceTag,
268
+ objectType: objSchema.objectType
269
+ }
270
+ ),
271
+ objSchema
272
+ )
273
+ );
275
274
 
276
275
 
277
- // case create
278
- let createFieldSchema = generateObjectSchemaForCreate(_izContext, objSchema);
279
- uploadList.push(
280
- uploadObjectToS3(
276
+ // case create
277
+ let createFieldSchema = generateObjectSchemaForCreate(_izContext, objSchema);
278
+ uploadList.push(
279
+ uploadObjectToS3(
280
+ _izContext,
281
+ UPLOAD_PATH_S3.objectSchemaCreate(
281
282
  _izContext,
282
- UPLOAD_PATH_S3.objectSchemaCreate(
283
- _izContext,
284
- {
285
- serviceTag: process.env.iz_serviceTag,
286
- objectType: createFieldSchema.objectType
287
- }
288
- ),
289
- createFieldSchema
290
- )
291
- );
283
+ {
284
+ serviceTag: process.env.iz_serviceTag,
285
+ objectType: createFieldSchema.objectType
286
+ }
287
+ ),
288
+ createFieldSchema
289
+ )
290
+ );
292
291
 
293
- objectTypesForCreate.push(createFieldSchema.objectType);
292
+ objectTypesForCreate.push(createFieldSchema.objectType);
294
293
 
295
294
 
296
- // case update and display
297
- let updateFieldSchema = generateObjectSchemaForUpdate(_izContext, objSchema);
298
- uploadList.push(
299
- uploadObjectToS3(
295
+ // case update and display
296
+ let updateFieldSchema = generateObjectSchemaForUpdate(_izContext, objSchema);
297
+ uploadList.push(
298
+ uploadObjectToS3(
299
+ _izContext,
300
+ UPLOAD_PATH_S3.objectSchemaDisplay(
300
301
  _izContext,
301
- UPLOAD_PATH_S3.objectSchemaDisplay(
302
- _izContext,
303
- {
304
- serviceTag: process.env.iz_serviceTag,
305
- objectType: createFieldSchema.objectType
306
- }
307
- ),
308
- updateFieldSchema
309
- )
310
- );
302
+ {
303
+ serviceTag: process.env.iz_serviceTag,
304
+ objectType: createFieldSchema.objectType
305
+ }
306
+ ),
307
+ updateFieldSchema
308
+ )
309
+ );
311
310
 
312
311
 
313
- // case schema combine fieldNames
314
- let combineFieldNamesObjectSchema = generateObjectSchemaForCombineFieldNames(_izContext, objSchema);
315
- uploadList.push(
316
- uploadObjectToS3(
312
+ // case schema combine fieldNames
313
+ let combineFieldNamesObjectSchema = generateObjectSchemaForCombineFieldNames(_izContext, objSchema);
314
+ uploadList.push(
315
+ uploadObjectToS3(
316
+ _izContext,
317
+ UPLOAD_PATH_S3.objectSchemaCombineFieldNames(
317
318
  _izContext,
318
- UPLOAD_PATH_S3.objectSchemaCombineFieldNames(
319
- _izContext,
320
- {
321
- serviceTag: process.env.iz_serviceTag,
322
- objectType: combineFieldNamesObjectSchema.objectType
323
- }
324
- ),
325
- combineFieldNamesObjectSchema
326
- )
327
- );
328
- }
319
+ {
320
+ serviceTag: process.env.iz_serviceTag,
321
+ objectType: combineFieldNamesObjectSchema.objectType
322
+ }
323
+ ),
324
+ combineFieldNamesObjectSchema
325
+ )
326
+ );
327
+
329
328
 
330
329
  // upload to refObjectRelationships for each objectType that have createBy at UserAccount Service and belongTo
331
330
  let existsRefObjectRel = refRelationshipPerObjectType[objSchema.objectType];
package/src/Utils.js CHANGED
@@ -339,6 +339,16 @@ function validateFieldNamesWithStorageResources(_izContext, objectSchema) {
339
339
  * @returns {[boolean, string[]]} - [status, errors], errors will return when status=false
340
340
  */
341
341
  function validateObjectSchema(_izContext, objectSchema) {
342
+
343
+ for (const storageResourceTag in objectSchema.storageResources) {
344
+ let storageResource = objectSchema.storageResources[storageResourceTag]
345
+ if (storageResource.storageType === consts.STORAGE_TYPES.dynamoDB) {
346
+ if (!storageResource.serviceTag) {
347
+ Object.assign(objectSchema.storageResources[storageResourceTag], { serviceTag: process.env.iz_serviceTag })
348
+ }
349
+ }
350
+ }
351
+
342
352
  if (objectSchema.hasOwnProperty("extendObjType")) {
343
353
  return validateExtendObjectSchema(_izContext, objectSchema)
344
354
  } else {
@@ -1152,13 +1152,6 @@ async function validateLocalSchema(_izContext, schemasPath, serviceConfigPath) {
1152
1152
  for (const flowSchema of allFlowSchemas) {
1153
1153
  const [status, errors] = validateBasicFlowSchema(_izContext, flowSchema)
1154
1154
 
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
1155
  if (flowSchema.statusType === "storedCache" || flowSchema.statusType === "statusField" || flowSchema.statusType === "triggerCache") {
1163
1156
  if (!flowSchema.hasOwnProperty("objType")) {
1164
1157
  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
  }