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

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.98",
3
+ "version": "1.0.100",
4
4
  "description": "Schemas for the service and objects it controls",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -25,11 +25,11 @@
25
25
  "@aws-sdk/client-lambda": "^3.862.0",
26
26
  "@aws-sdk/client-s3": "^3.862.0",
27
27
  "@aws-sdk/crc64-nvme-crt": "^3.862.0",
28
- "@izara_project/izara-core-library-core": "^1.0.24",
28
+ "@izara_project/izara-core-library-core": "^1.0.27",
29
29
  "@izara_project/izara-core-library-external-request": "^1.0.21",
30
30
  "@izara_project/izara-core-library-lambda": "^1.0.5",
31
31
  "@izara_project/izara-core-library-logger": "^1.0.7",
32
- "@izara_project/izara-shared-core": "^1.0.2",
32
+ "@izara_project/izara-shared-core": "^1.0.4",
33
33
  "@izara_project/izara-shared-service-schemas": "^1.0.32",
34
34
  "glob": "^11.0.3",
35
35
  "lodash": "^4.17.21",
@@ -21,7 +21,6 @@ along with this program.If not, see < http://www.gnu.org/licenses/>.
21
21
  const glob = require('glob')
22
22
  const path = require('path')
23
23
  const lodash = require('lodash');
24
-
25
24
  const hash = require('@izara_project/izara-shared-core').objectHash;
26
25
 
27
26
  const sharedServiceSchema = require("@izara_project/izara-shared-service-schemas");
@@ -1128,6 +1127,46 @@ async function getObjectSchemaForUpdate(_izContext, objType) {
1128
1127
  return await getObjectSchemaForUpdateShared(getSchemaByNameWithCache, objType, process.env.iz_serviceSchemaBucketName)
1129
1128
  }
1130
1129
 
1130
+
1131
+ // collect dynamoDB storageResources of objType in flowType
1132
+ async function getTableNamesByFlowType(_izContext, flowType) {
1133
+ let tableNamesStorageResource = [];
1134
+ const flowSchema = await getFlowSchemaS3WithCache(_izContext, flowType);
1135
+
1136
+ // validate flowSchema
1137
+ if (!flowSchema) {
1138
+ throw new NoRetryError(`Flow schema not found for flowType: ${JSON.stringify(flowType)}`);
1139
+ }
1140
+
1141
+ // validate flowSchema
1142
+ if (!flowSchema.objType) {
1143
+ throw new NoRetryError(`Invalid Flow schema not have objType: ${JSON.stringify(flowType)}`);
1144
+ }
1145
+
1146
+
1147
+ const objectSchema = await getObjSchemaS3WithHierarchy(_izContext, flowSchema.objType);
1148
+
1149
+ // validate objectSchemaTriggerCache
1150
+ if (!objectSchema) {
1151
+ throw new NoRetryError(`Object schema not found for flowType: ${JSON.stringify(flowType)}, objType: ${JSON.stringify(flowSchema.objType)}`);
1152
+ }
1153
+
1154
+ //collect storageResourceDynamoDB
1155
+ for (const storageTag in objectSchema.storageResources) {
1156
+ const storageResource = objectSchema.storageResources[storageTag];
1157
+ if (storageResource.storageType === 'dynamoDB') {
1158
+
1159
+ tableNamesStorageResource.push({
1160
+ ...storageResource,
1161
+ storageTag
1162
+ })
1163
+ }
1164
+ }
1165
+
1166
+ return tableNamesStorageResource;
1167
+ }
1168
+
1169
+
1131
1170
  module.exports = {
1132
1171
  // getObjectTypes,
1133
1172
  getDataFromPath,
@@ -1186,6 +1225,8 @@ module.exports = {
1186
1225
 
1187
1226
  getObjectSchemaForCreate,
1188
1227
  getObjectSchemaForUpdate,
1228
+
1229
+ getTableNamesByFlowType
1189
1230
  }
1190
1231
 
1191
1232
 
@@ -1302,34 +1302,49 @@ async function validateLocalSchema(_izContext, schemasPath, serviceConfigPath) {
1302
1302
  validateStatus.status = false;
1303
1303
  validateStatus.validateErrors.push(`${flowSchema.flowTag}.objType is invalid`)
1304
1304
  } else {
1305
- if (Object.keys(objSchema.storageResources).length > 1) { // check for objectSchema must have 1 storageResource
1305
+
1306
+ let dynamoDBStorageTags = [];
1307
+
1308
+ for (const [storageTag, storageResource] of Object.entries(objSchema.storageResources)) {
1309
+ if (storageResource.storageType === STORAGE_TYPES.dynamoDB) {
1310
+ dynamoDBStorageTags.push(storageTag)
1311
+ }
1312
+ }
1313
+
1314
+ if (dynamoDBStorageTags.length > 1) {
1306
1315
  validateStatus.status = false;
1307
- validateStatus.validateErrors.push(`storageResource of objectType:${objSchema.objectType} serviceTag:${flowSchema.objType.serviceTag} is not single storageResource`)
1308
- } else if (Object.keys(objSchema.storageResources).length = 1) {
1309
- for (const storageResource of Object.values(objSchema.storageResources)) {
1310
- if (storageResource.storageType === STORAGE_TYPES.dynamoDB) {
1311
- if (flowSchema.statusType === "triggerCache" || flowSchema.statusType === "storedCache") {
1312
- let specificFieldNames = Object.values(createSpecificFieldNameForCacheTable(createFlowTypeConcat(_izContext, { flowTag: flowSchema.flowTag, serviceTag: iz_serviceTag }), "cacheTable"))
1313
- const fieldNames = Object.keys(objSchema.fieldNames)
1314
- for (const specificFieldName of specificFieldNames) { // check for specific fieldName
1315
- if (!fieldNames.includes(specificFieldName)) {
1316
- validateStatus.status = false;
1317
- validateStatus.validateErrors.push(`objectType: ${objSchema.objectType} not have fieldNames: ${specificFieldName} in objectSchema.fieldNames`)
1318
- }
1316
+ validateStatus.validateErrors.push(`objectType:${objSchema.objectType} should not shave more than 1 dynamoDB storageResource`)
1317
+ } else {
1318
+
1319
+ if (flowSchema.statusType === "statusField") {
1320
+ let specificFieldNames = Object.values(createSpecificFieldNameForCacheTable(createFlowTypeConcat(_izContext, { flowTag: flowSchema.flowTag, serviceTag: iz_serviceTag }), 'statusField'))
1321
+
1322
+ for (const specificFieldName of specificFieldNames) { // check for specific fieldName
1323
+ if (objSchema.fieldNames.hasOwnProperty(specificFieldName)) {
1324
+ if (!objSchema.fieldNames[specificFieldName].storageResourceTags.includes(dynamoDBStorageTags[0])) {
1325
+ validateStatus.status = false;
1326
+ validateStatus.validateErrors.push(`objectType: ${objSchema.objectType} fieldNames: ${specificFieldName} not have storageResourceTag: ${dynamoDBStorageTags[0]}`);
1319
1327
  }
1320
- } else if (flowSchema.statusType === "statusField") {
1321
- let specificFieldNames = Object.values(createSpecificFieldNameForCacheTable(createFlowTypeConcat(_izContext, { flowTag: flowSchema.flowTag, serviceTag: iz_serviceTag }), 'statusField'))
1322
- const fieldNames = Object.keys(objSchema.fieldNames)
1323
- for (const specificFieldName of specificFieldNames) { // check for specific fieldName
1324
- if (!fieldNames.includes(specificFieldName)) {
1325
- validateStatus.status = false;
1326
- validateStatus.validateErrors.push(`objectType: ${objSchema.objectType} not have fieldNames: ${specificFieldName} in objectSchema.fieldNames`)
1327
- }
1328
+ } else {
1329
+ validateStatus.status = false;
1330
+ validateStatus.validateErrors.push(`objectType: ${objSchema.objectType} not have fieldNames: ${specificFieldName} in objectSchema.fieldNames`)
1331
+ }
1332
+ }
1333
+
1334
+
1335
+ } else if (flowSchema.statusType === "storedCache" || flowSchema.statusType === "triggerCache") {
1336
+ let specificFieldNames = Object.values(createSpecificFieldNameForCacheTable(createFlowTypeConcat(_izContext, { flowTag: flowSchema.flowTag, serviceTag: iz_serviceTag }), "cacheTable"))
1337
+
1338
+ for (const specificFieldName of specificFieldNames) { // check for specific fieldName
1339
+ if (objSchema.fieldNames.hasOwnProperty(specificFieldName)) {
1340
+ if (!objSchema.fieldNames[specificFieldName].storageResourceTags.includes(dynamoDBStorageTags[0])) {
1341
+ validateStatus.status = false;
1342
+ validateStatus.validateErrors.push(`objectType: ${objSchema.objectType} fieldNames: ${specificFieldName} not have storageResourceTag: ${dynamoDBStorageTags[0]}`);
1328
1343
  }
1344
+ } else {
1345
+ validateStatus.status = false;
1346
+ validateStatus.validateErrors.push(`objectType: ${objSchema.objectType} not have fieldNames: ${specificFieldName} in objectSchema.fieldNames`)
1329
1347
  }
1330
- } else {
1331
- validateStatus.status = false;
1332
- validateStatus.validateErrors.push(`storageResource of ObjectType: $${flowSchema.objType.flowTag} from flowTag: ${flowSchema.flowTag} must be dynamoDB`);
1333
1348
  }
1334
1349
  }
1335
1350
  }