@izara_project/izara-core-library-service-schemas 1.0.73 → 1.0.74

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.73",
3
+ "version": "1.0.74",
4
4
  "description": "Schemas for the service and objects it controls",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -14,22 +14,22 @@
14
14
  "license": "AGPL-3.0-or-later",
15
15
  "homepage": "https://bitbucket.org/izara-core-libraries/izara-core-library-service-schemas/src/master/README.md",
16
16
  "devDependencies": {
17
- "jest": "^30.0.2"
17
+ "jest": "^30.0.3"
18
18
  },
19
19
  "jest": {
20
20
  "testEnvironment": "node"
21
21
  },
22
22
  "dependencies": {
23
- "@aws-sdk/client-lambda": "^3.835.0",
24
- "@aws-sdk/client-s3": "^3.835.0",
25
- "@aws-sdk/crc64-nvme-crt": "^3.835.0",
26
- "@aws-sdk/client-api-gateway": "^3.835.0",
23
+ "@aws-sdk/client-lambda": "^3.840.0",
24
+ "@aws-sdk/client-s3": "^3.840.0",
25
+ "@aws-sdk/crc64-nvme-crt": "^3.840.0",
26
+ "@aws-sdk/client-api-gateway": "^3.840.0",
27
27
  "@izara_project/izara-core-library-core": "^1.0.19",
28
28
  "@izara_project/izara-core-library-external-request": "^1.0.20",
29
29
  "@izara_project/izara-core-library-lambda": "^1.0.4",
30
30
  "@izara_project/izara-core-library-logger": "^1.0.7",
31
31
  "@izara_project/izara-shared-core": "^1.0.2",
32
- "@izara_project/izara-shared-service-schemas": "^1.0.19",
32
+ "@izara_project/izara-shared-service-schemas": "^1.0.20",
33
33
  "glob": "^11.0.3",
34
34
  "lodash": "^4.17.21",
35
35
  "object-hash": "^3.0.0",
@@ -222,7 +222,7 @@ async function getLocalObjectSchemas(_izContext, objectTypes, objSchemaPath = LO
222
222
  allObjectSchemas.map(async (objSchema, idx) => {
223
223
  const mergeResult = await mergeExtendObjSchema(_izContext, objSchema)
224
224
  if (mergeResult?.errorsFound?.length && mergeResult?.errorsFound?.length > 0) {
225
- throw new NoRetryError(mergeResult.errorsFound)
225
+ throw new NoRetryError(mergeResult.errorsFound.join(","))
226
226
  } else {
227
227
  allObjectSchemas[idx] = mergeResult;
228
228
  }
@@ -471,7 +471,7 @@ async function getObjSchemaS3(
471
471
  ) {
472
472
  return await getObjectSchemaS3Shared(getSchemaByNameWithCache, objType, getExtendObType).then(res => {
473
473
  if (res.errorsFound.length && res.errorsFound.length > 0) {
474
- throw new NoRetryError(res.errorsFound)
474
+ throw new NoRetryError(res.errorsFound.join(","))
475
475
  } else {
476
476
  return res.result
477
477
  }
@@ -505,7 +505,7 @@ async function getObjSchemaS3WithHierarchy(_izContext, objType) {
505
505
  // return await getObjSchemaS3WithCache(_izContext, objType, true)
506
506
  return await getObjSchemaWithHierarchy(getSchemaByNameWithCache, objType).then(res => {
507
507
  if (res.errorsFound.length && res.errorsFound.length > 0) {
508
- throw new NoRetryError(res.errorsFound)
508
+ throw new NoRetryError(res.errorsFound.join(","))
509
509
  } else {
510
510
  return res.result
511
511
  }
@@ -522,7 +522,7 @@ async function getObjSchemaS3WithoutHierarchy(_izContext, objType) {
522
522
  // return await getObjSchemaS3WithCache(_izContext, objType, false)
523
523
  return await getObjSchemaWithoutHierarchy(getSchemaByNameWithCache, objType).then(res => {
524
524
  if (res.errorsFound.length && res.errorsFound.length > 0) {
525
- throw new NoRetryError(res.errorsFound)
525
+ throw new NoRetryError(res.errorsFound.join(","))
526
526
  } else {
527
527
  return res.result
528
528
  }
@@ -642,7 +642,7 @@ function getLocalRelationshipSchemas(_izContext, relationshipTags, objSchemaPath
642
642
  async function getRefObjectRelationship(_izContext, objType) {
643
643
  return await getRefObjectRelationshipShared(getSchemaByNameWithCache, objType).then(res => {
644
644
  if (res.errorsFound.length && res.errorsFound.length > 0) {
645
- throw new NoRetryError(res.errorsFound)
645
+ throw new NoRetryError(res.errorsFound.join(","))
646
646
  } else {
647
647
  return res.result
648
648
  }
@@ -677,7 +677,7 @@ const getRefObjectRelationshipWithCache = inMemoryCacheLib(
677
677
  async function getRelationshipSchema(_izContext, relType) {
678
678
  return await getRelationshipSchemaShared(getSchemaByNameWithCache, relType).then(res => {
679
679
  if (res.errorsFound.length && res.errorsFound.length > 0) {
680
- throw new NoRetryError(res.errorsFound)
680
+ throw new NoRetryError(res.errorsFound.join(","))
681
681
  } else {
682
682
  return res.result
683
683
  }
@@ -790,7 +790,7 @@ async function getObjectRelationship(
790
790
 
791
791
  return await getObjectRelationshipShared(getSchemaByNameWithCache, objType, specificRelTags, overWriteBaseObjType).then(res => {
792
792
  if (res.errorsFound.length && res.errorsFound.length > 0) {
793
- throw new NoRetryError(res.errorsFound)
793
+ throw new NoRetryError(res.errorsFound.join(","))
794
794
  } else {
795
795
  return res.result
796
796
  }
@@ -840,7 +840,7 @@ async function getRequiredOnCreateLinks(
840
840
 
841
841
  return await getRequiredOnCreateLinksShared(getSchemaByNameWithCache, objType, specificRelTags).then(res => {
842
842
  if (res.errorsFound.length && res.errorsFound.length > 0) {
843
- throw new NoRetryError(res.errorsFound)
843
+ throw new NoRetryError(res.errorsFound.join(","))
844
844
  } else {
845
845
  return res.result
846
846
  }
@@ -922,7 +922,7 @@ async function getLinkConfigByLinkTypeId(_izContext, firstObjType, secondObjType
922
922
 
923
923
  await getLinkConfigByLinkTypeIdShared(getSchemaByNameWithCache, firstObjType, secondObjType, relType, direction, settings).then(res => {
924
924
  if (res.errorsFound.length && res.errorsFound.length > 0) {
925
- throw new NoRetryError(res.errorsFound)
925
+ throw new NoRetryError(res.errorsFound.join(","))
926
926
  } else {
927
927
  return res.result
928
928
  }
@@ -26,22 +26,34 @@ async function validateRequiredOnCreateLinks(_izContext, objType, relationships,
26
26
  _izContext.logger.debug("validateRequiredOnCreateLinks:::", { objType, relationships, settings })
27
27
 
28
28
 
29
- let objectHie = await getObjTypeHierarchy(_izContext, objType);
29
+ let objectHie = await getObjTypeHierarchy(_izContext, objType).then(objSchema => {
30
+ if (objSchema.errorsFound.length > 0) {
31
+ throw new NoRetryError(objSchema.errorsFound.join(","))
32
+ } else {
33
+ return objSchema.result
34
+ }
35
+ });
30
36
  _izContext.logger.debug("objectHierarchy::", objectHie)
31
37
 
32
38
  if (relationships.length) {
33
- let targetHierarchy = await getObjTypeHierarchy(_izContext, relationships[0].targetObjType);
39
+ let targetHierarchy = await getObjTypeHierarchy(_izContext, relationships[0].targetObjType).then(objSchema => {
40
+ if (objSchema.errorsFound.length > 0) {
41
+ throw new NoRetryError(objSchema.errorsFound.join(","))
42
+ } else {
43
+ return objSchema.result
44
+ }
45
+ });
34
46
  _izContext.logger.debug("targetHierarchy::", targetHierarchy)
35
47
  }
36
48
 
37
49
 
38
- let errorFound = [];
50
+ let errorsFound = [];
39
51
 
40
52
  let requiredOnCreateLinks = await getObjectSchema.getRequiredOnCreateLinksWithCache(_izContext, objType)
41
53
  _izContext.logger.debug("requiredOnCreateLinks::", requiredOnCreateLinks)
42
54
 
43
55
  if (!requiredOnCreateLinks.length && relationships.length > 0) {
44
- errorFound.push(`not have requireOnCreate will not create relationship: ${JSON.stringify(relationships)}`)
56
+ errorsFound.push(`not have requireOnCreate will not create relationship: ${JSON.stringify(relationships)}`)
45
57
  }
46
58
 
47
59
  let filteredRequiredOnCreateLinks = [];
@@ -76,22 +88,28 @@ async function validateRequiredOnCreateLinks(_izContext, objType, relationships,
76
88
  let relTypeConcat = createRelTypeConcat(_izContext, relationship.relType)
77
89
 
78
90
  if (!requiredOnCreateLinkGroups[relTypeConcat]) {
79
- errorFound.push(`cannot create relationship ${relTypeConcat}`)
91
+ errorsFound.push(`cannot create relationship ${relTypeConcat}`)
80
92
  break;
81
93
  }
82
94
 
83
95
  // match requiredOnCreateLinks with relationshipDirection from requestParams
84
96
  const usedLinkGroup = requiredOnCreateLinkGroups[relTypeConcat][relationship.relationshipDirection];
85
97
 
86
- if (!usedLinkGroup.length) {
87
- errorFound.push(`cannot create relationship ${relTypeConcat}`)
98
+ if (!usedLinkGroup?.length) {
99
+ errorsFound.push(`cannot create relationship ${relTypeConcat}`)
88
100
  break;
89
101
  }
90
102
 
91
103
  for (let link of usedLinkGroup) {
92
104
  // check other with targetObjType, check linkType of other should be 'one',
93
- let targetObjTypeHierarchy = await getObjTypeHierarchy(_izContext, relationship.targetObjType);
94
- _izContext.logger.debug(" ::", targetObjTypeHierarchy)
105
+ let targetObjTypeHierarchy = await getObjTypeHierarchy(_izContext, relationship.targetObjType).then(objSchema => {
106
+ if (objSchema.errorsFound.length > 0) {
107
+ throw new NoRetryError(objSchema.errorsFound.join(","))
108
+ } else {
109
+ return objSchema.result
110
+ }
111
+ });
112
+ _izContext.logger.debug("targetObjTypeHierarchy::", targetObjTypeHierarchy)
95
113
 
96
114
  // if (link.other.objType.objectType === relationship.targetObjType.objectType) {
97
115
  if (targetObjTypeHierarchy.some(objType =>
@@ -101,11 +119,11 @@ async function validateRequiredOnCreateLinks(_izContext, objType, relationships,
101
119
  if (!validateOnCreateRelationships.has(`${relTypeConcat}_${relationship.relationshipDirection}`)) {
102
120
  validateOnCreateRelationships.add(`${relTypeConcat}_${relationship.relationshipDirection}`)
103
121
  } else {
104
- errorFound.push(`unexpected dulicate relationship link ${JSON.stringify(relationship)}`)
122
+ errorsFound.push(`unexpected duplicate relationship link ${JSON.stringify(relationship)}`)
105
123
  break;
106
124
  }
107
125
  } else {
108
- errorFound.push(`invalid linkType should not be many when base: ${link} is requiredOnCreated`)
126
+ errorsFound.push(`invalid linkType should not be many when base: ${link} is requiredOnCreated`)
109
127
  break;
110
128
  }
111
129
  }
@@ -117,11 +135,11 @@ async function validateRequiredOnCreateLinks(_izContext, objType, relationships,
117
135
 
118
136
  for (const requiredOnCreateRelTypeConcat of requiredOnCreateRelTypeConcats) {
119
137
  if (!validateOnCreateRelationships.has(requiredOnCreateRelTypeConcat)) {
120
- errorFound.push(`missing requiredOnCreate relationship ${requiredOnCreateRelTypeConcat}`)
138
+ errorsFound.push(`missing requiredOnCreate relationship ${requiredOnCreateRelTypeConcat}`)
121
139
  }
122
140
  }
123
141
 
124
- return errorFound;
142
+ return errorsFound;
125
143
  }
126
144
 
127
145
  function groupRequiredOnCreateLink(_izContext, relationshipSchemas) {
@@ -205,24 +205,24 @@ async function generateDeliminatorTreeIdentifier(_izContext, objectSchema) {
205
205
  }));
206
206
 
207
207
  // calculate deliminatorTree of identifier
208
- let calCompoisteKeyDeliminatorList = {};
208
+ let calCompositeKeyDeliminatorList = {};
209
209
  for (let deliminatorValue of Object.values(compositeKeysDeliminatorTree)) {
210
210
  if (deliminatorValue.deliminatorList) {
211
211
  for (let [deliminator, deliminatorAmount] of Object.entries(deliminatorValue.deliminatorList)) {
212
- if (calCompoisteKeyDeliminatorList.hasOwnProperty(deliminator)) {
213
- calCompoisteKeyDeliminatorList[deliminator] = Math.max(deliminatorAmount, calCompoisteKeyDeliminatorList[deliminator]);
212
+ if (calCompositeKeyDeliminatorList.hasOwnProperty(deliminator)) {
213
+ calCompositeKeyDeliminatorList[deliminator] = Math.max(deliminatorAmount, calCompositeKeyDeliminatorList[deliminator]);
214
214
  } else {
215
- Object.assign(calCompoisteKeyDeliminatorList, { [deliminator]: deliminatorAmount });
215
+ Object.assign(calCompositeKeyDeliminatorList, { [deliminator]: deliminatorAmount });
216
216
  }
217
217
  }
218
218
  }
219
219
  }
220
220
 
221
221
 
222
- if (calCompoisteKeyDeliminatorList.hasOwnProperty(identifierDeliminator)) {
223
- calCompoisteKeyDeliminatorList[identifierDeliminator]++;
222
+ if (calCompositeKeyDeliminatorList.hasOwnProperty(identifierDeliminator)) {
223
+ calCompositeKeyDeliminatorList[identifierDeliminator]++;
224
224
  } else {
225
- Object.assign(calCompoisteKeyDeliminatorList, { [identifierDeliminator]: 1 });
225
+ Object.assign(calCompositeKeyDeliminatorList, { [identifierDeliminator]: 1 });
226
226
  }
227
227
 
228
228
  Object.assign(
@@ -230,7 +230,7 @@ async function generateDeliminatorTreeIdentifier(_izContext, objectSchema) {
230
230
  {
231
231
  [identifierName]: {
232
232
  deliminator: identifierDeliminator,
233
- deliminatorList: calCompoisteKeyDeliminatorList,
233
+ deliminatorList: calCompositeKeyDeliminatorList,
234
234
  children: compositeKeysDeliminatorTree
235
235
  }
236
236
  }
@@ -29,12 +29,12 @@ const { getObjTypeHierarchy } = require('../GetObjectSchema')
29
29
  *
30
30
  * @param {object} _izContext
31
31
  * @param {object[]} objTypes - 2 objType in array
32
- * @param {object[]} relatoinshipLinks - links inside relationshipSchema
32
+ * @param {object[]} relationshipLinks - links inside relationshipSchema
33
33
  */
34
- async function findLinksByObjTypes(_izContext, objTypes, relatoinshipLinks) {
34
+ async function findLinksByObjTypes(_izContext, objTypes, relationshipLinks) {
35
35
 
36
- if (!Array.isArray(relatoinshipLinks)) {
37
- throw new NoRetryError("relatoinshipLinks should be array");
36
+ if (!Array.isArray(relationshipLinks)) {
37
+ throw new NoRetryError("relationshipLinks should be array");
38
38
  }
39
39
 
40
40
  if (!objTypes || !Array.isArray(objTypes) || objTypes.length !== 2) {
@@ -52,8 +52,20 @@ async function findLinksByObjTypes(_izContext, objTypes, relatoinshipLinks) {
52
52
  const secondObjType = objTypes[1];
53
53
 
54
54
  // first create hierarchy of each objType
55
- const firstObjTypeTree = await getObjTypeHierarchy(_izContext, objTypes[0]);
56
- const secondObjTypeTree = await getObjTypeHierarchy(_izContext, objTypes[1]);
55
+ const firstObjTypeTree = await getObjTypeHierarchy(_izContext, objTypes[0]).then(objSchema => {
56
+ if (objSchema.errorsFound.length > 0) {
57
+ throw new NoRetryError(objSchema.errorsFound.join(","))
58
+ } else {
59
+ return objSchema.result
60
+ }
61
+ });
62
+ const secondObjTypeTree = await getObjTypeHierarchy(_izContext, objTypes[1]).then(objSchema => {
63
+ if (objSchema.errorsFound.length > 0) {
64
+ throw new NoRetryError(objSchema.errorsFound.join(","))
65
+ } else {
66
+ return objSchema.result
67
+ }
68
+ });
57
69
 
58
70
  const firstObjTypeTreeHashes = firstObjTypeTree.reduce(
59
71
  (result, objType) => {
@@ -74,7 +86,7 @@ async function findLinksByObjTypes(_izContext, objTypes, relatoinshipLinks) {
74
86
 
75
87
  let foundLinks = [];
76
88
 
77
- for (let link of relatoinshipLinks) {
89
+ for (let link of relationshipLinks) {
78
90
  const fromObjTypeHash = hash(link.from.objType);
79
91
  const toObjTypeHash = hash(link.to.objType);
80
92
 
@@ -100,6 +100,10 @@ function generateObjectSchemaForCreate(_izContext, objSchema) {
100
100
 
101
101
  for (let [fieldName, fieldNameSetting] of Object.entries(objSchema.fieldNames)) {
102
102
 
103
+ if (!fieldNameSetting.requiredOnCreate && !fieldNameSetting.optionalOnCreate) {
104
+ continue;
105
+ }
106
+
103
107
  if (!initReturnObj.fieldNames.hasOwnProperty(fieldName)) {
104
108
  initReturnObj.fieldNames[fieldName] = {}
105
109
  }
@@ -115,6 +119,11 @@ function generateObjectSchemaForCreate(_izContext, objSchema) {
115
119
  for (let addOn of objSchema.addOnDataStructure) {
116
120
  if (addOn.type === "versionedData") {
117
121
  for (let [versionedFieldName, fieldNameData] of Object.entries(addOn.fieldNames)) {
122
+
123
+ if (!fieldNameData.requiredOnCreate && !fieldNameData.optionalOnCreate) {
124
+ continue;
125
+ }
126
+
118
127
  Object.assign(
119
128
  initReturnObj.fieldNames,
120
129
  {
@@ -134,8 +143,6 @@ function generateObjectSchemaForCreate(_izContext, objSchema) {
134
143
  return initReturnObj;
135
144
  }
136
145
 
137
-
138
-
139
146
  /**
140
147
  * create object schema for update/display case
141
148
  *