@izara_project/izara-core-library-service-schemas 1.0.96 → 1.0.98
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 +1 -1
- package/src/ValidatorSchema.js +146 -120
package/package.json
CHANGED
package/src/ValidatorSchema.js
CHANGED
|
@@ -53,7 +53,8 @@ const {
|
|
|
53
53
|
getAllLocalFlowSchemas,
|
|
54
54
|
getAllLocalRefObjectRelationshipSchema,
|
|
55
55
|
getAllLocalRelationshipSchema,
|
|
56
|
-
getLocalRelationshipSchemas
|
|
56
|
+
getLocalRelationshipSchemas,
|
|
57
|
+
getObjectSchemaCombineFieldNamesWithCache,
|
|
57
58
|
} = require("./GetObjectSchema");
|
|
58
59
|
|
|
59
60
|
const {
|
|
@@ -87,14 +88,21 @@ const { validateObjType } = require('@izara_project/izara-shared-service-schemas
|
|
|
87
88
|
// return prefix + 'FlowParams';
|
|
88
89
|
// }
|
|
89
90
|
|
|
90
|
-
function createSpecificFieldNameForCacheTable(prefix = 'cache') {
|
|
91
|
+
function createSpecificFieldNameForCacheTable(prefix = 'cache', statusType) {
|
|
91
92
|
return {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
93
|
+
'cacheTable': {
|
|
94
|
+
uniqueRequestId: prefix + "UniqueRequestId",
|
|
95
|
+
fieldNameStatus: prefix + "Status",
|
|
96
|
+
errorsFound: prefix + 'ErrorsFound',
|
|
97
|
+
cacheComplete: prefix + 'CacheComplete',
|
|
98
|
+
flowParams: prefix + 'FlowParams'
|
|
99
|
+
},
|
|
100
|
+
'statusField': {
|
|
101
|
+
uniqueRequestId: prefix + "UniqueRequestId",
|
|
102
|
+
errorsFound: prefix + "ErrorsFound",
|
|
103
|
+
fieldNameStatus: prefix + "Status"
|
|
104
|
+
}
|
|
105
|
+
}[statusType]
|
|
98
106
|
}
|
|
99
107
|
|
|
100
108
|
/**
|
|
@@ -536,46 +544,22 @@ async function generateValidatorSchemaForUpdate(_izContext, objType, settings =
|
|
|
536
544
|
// _izContext.logger.debug("objectSchema", objectSchema)
|
|
537
545
|
|
|
538
546
|
const objectSchemas = await uploadUseCase.generateObjectSchemaForCombineFieldNames(_izContext, objectSchema)
|
|
539
|
-
_izContext.logger.debug("objectSchemas", objectSchemas)
|
|
547
|
+
// _izContext.logger.debug("objectSchemas", objectSchemas)
|
|
540
548
|
|
|
541
549
|
let usedIdentifierTypes = getIdentifierTypeByPriority(_izContext, [], objectSchema);
|
|
542
550
|
_izContext.logger.debug({ usedIdentifierTypes });
|
|
543
551
|
// collect requiredFieldNames by fieldName that includes in identifiers
|
|
544
552
|
let identifiersFieldNames = getUsedFieldNamesOfIdentifiers(_izContext, objectSchemas.identifiers, usedIdentifierTypes);
|
|
553
|
+
// _izContext.logger.debug("identifiersFieldNames", identifiersFieldNames)
|
|
554
|
+
let fieldNameCanUpdates = [];
|
|
555
|
+
let versionedDataFieldNameCanUpdates = [];
|
|
545
556
|
|
|
546
|
-
let canUpdateFieldNames = [];
|
|
547
|
-
let canUpdateProperties = {};
|
|
557
|
+
// let canUpdateFieldNames = [];
|
|
558
|
+
// let canUpdateProperties = {};
|
|
548
559
|
let usedFieldNames = identifiersFieldNames;
|
|
549
|
-
let versionedDataFieldNames = [];
|
|
550
|
-
|
|
551
|
-
// collect canUpdate fieldName (all fieldName have CanUpdate setting = true)
|
|
552
|
-
for (let [fieldName, fieldNameSetting] of Object.entries(objectSchemas.fieldNames)) {
|
|
553
|
-
if (settings.handler === "ApiGateway") {
|
|
554
|
-
if (fieldNameSetting.userCanUpdate === true) {
|
|
555
|
-
canUpdateFieldNames.push(fieldName);
|
|
556
|
-
canUpdateProperties[fieldName] = {
|
|
557
|
-
type: fieldNameSetting.type
|
|
558
|
-
}
|
|
559
|
-
if (fieldNameSetting.hasOwnProperty("versionedDataLabel")) {
|
|
560
|
-
versionedDataFieldNames.push(fieldName)
|
|
561
|
-
}
|
|
562
|
-
}
|
|
563
|
-
} else {
|
|
564
|
-
if (fieldNameSetting.canUpdate === true || fieldNameSetting.canUpdate === undefined) {
|
|
565
|
-
canUpdateFieldNames.push(fieldName);
|
|
566
|
-
canUpdateProperties[fieldName] = {
|
|
567
|
-
type: fieldNameSetting.type,
|
|
568
|
-
}
|
|
569
|
-
if (fieldNameSetting.hasOwnProperty("versionedDataLabel")) {
|
|
570
|
-
versionedDataFieldNames.push(fieldName)
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
// _izContext.logger.debug("canUpdate::::", { canUpdateFieldNames, canUpdateProperties });
|
|
560
|
+
// let versionedDataFieldNames = [];
|
|
561
|
+
// collect fieldNames that canUpdate
|
|
577
562
|
|
|
578
|
-
// collect usedFieldNames
|
|
579
563
|
if (settings?.specificFieldNames) {
|
|
580
564
|
if (settings.specificFieldNames.length) {
|
|
581
565
|
for (let specificFieldName of settings.specificFieldNames) {
|
|
@@ -586,17 +570,56 @@ async function generateValidatorSchemaForUpdate(_izContext, objType, settings =
|
|
|
586
570
|
}
|
|
587
571
|
}
|
|
588
572
|
} else {
|
|
589
|
-
usedFieldNames = usedFieldNames.concat(
|
|
573
|
+
usedFieldNames = usedFieldNames.concat(fieldNameCanUpdates);
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
let versionedDataLabels = [];
|
|
577
|
+
for (const [fieldName, fieldSetting] of Object.entries(objectSchemas.fieldNames)) {
|
|
578
|
+
if (fieldSetting.canUpdate === true) {
|
|
579
|
+
fieldNameCanUpdates.push(fieldName)
|
|
580
|
+
if (fieldSetting.hasOwnProperty("versionedDataLabel")) {
|
|
581
|
+
versionedDataFieldNameCanUpdates.push(fieldName)
|
|
582
|
+
versionedDataLabels.push(fieldSetting.versionedDataLabel)
|
|
583
|
+
}
|
|
590
584
|
}
|
|
591
585
|
}
|
|
592
586
|
|
|
587
|
+
versionedDataLabels = [...new Set(versionedDataLabels)]
|
|
588
|
+
// console.log("versionedDataLabelValidatorSchema", versionedDataLabel)
|
|
589
|
+
// // collect canUpdate fieldName (all fieldName have CanUpdate setting = true)
|
|
590
|
+
// for (let [fieldName, fieldNameSetting] of Object.entries(objectSchemas.fieldNames)) {
|
|
591
|
+
// if (settings.handler === "ApiGateway") {
|
|
592
|
+
// if (fieldNameSetting.userCanUpdate === true) {
|
|
593
|
+
// canUpdateFieldNames.push(fieldName);
|
|
594
|
+
// canUpdateProperties[fieldName] = {
|
|
595
|
+
// type: fieldNameSetting.type
|
|
596
|
+
// }
|
|
597
|
+
// if (fieldNameSetting.hasOwnProperty("versionedDataLabel")) {
|
|
598
|
+
// versionedDataFieldNames.push(fieldName)
|
|
599
|
+
// }
|
|
600
|
+
// }
|
|
601
|
+
// } else {
|
|
602
|
+
// if (fieldNameSetting.canUpdate === true || fieldNameSetting.canUpdate === undefined) {
|
|
603
|
+
// canUpdateFieldNames.push(fieldName);
|
|
604
|
+
// canUpdateProperties[fieldName] = {
|
|
605
|
+
// type: fieldNameSetting.type,
|
|
606
|
+
// }
|
|
607
|
+
// if (fieldNameSetting.hasOwnProperty("versionedDataLabel")) {
|
|
608
|
+
// versionedDataFieldNames.push(fieldName)
|
|
609
|
+
// }
|
|
610
|
+
// }
|
|
611
|
+
// }
|
|
612
|
+
// }
|
|
613
|
+
|
|
614
|
+
// _izContext.logger.debug("canUpdate::::", { fieldNameCanUpdates, versionedDataFieldNameCanUpdates });
|
|
615
|
+
|
|
593
616
|
usedFieldNames = [...new Set(usedFieldNames)];
|
|
594
617
|
|
|
595
|
-
let defaultFieldNames = usedFieldNames.filter(fieldName => !identifiersFieldNames.includes(fieldName));
|
|
618
|
+
// let defaultFieldNames = usedFieldNames.filter(fieldName => !identifiersFieldNames.includes(fieldName));
|
|
596
619
|
|
|
597
|
-
// _izContext.logger.debug('identifiersFieldNames : ', identifiersFieldNames);
|
|
598
|
-
// _izContext.logger.debug('usedFieldNames : ', usedFieldNames); // all fieldName
|
|
599
|
-
// _izContext.logger.debug("defaultFieldNames :", defaultFieldNames);
|
|
620
|
+
// // _izContext.logger.debug('identifiersFieldNames : ', identifiersFieldNames);
|
|
621
|
+
// // _izContext.logger.debug('usedFieldNames : ', usedFieldNames); // all fieldName
|
|
622
|
+
// // _izContext.logger.debug("defaultFieldNames :", defaultFieldNames);
|
|
600
623
|
// _izContext.logger.debug("versionedDataFieldNames :", versionedDataFieldNames);
|
|
601
624
|
|
|
602
625
|
let initialValidatorSchemaForUpdate = {
|
|
@@ -620,7 +643,7 @@ async function generateValidatorSchemaForUpdate(_izContext, objType, settings =
|
|
|
620
643
|
additionalProperties: false,
|
|
621
644
|
// required: [],
|
|
622
645
|
// properties: {},
|
|
623
|
-
...await filteredFieldNamesOfValidatorSchema(_izContext, objType, [],
|
|
646
|
+
...await filteredFieldNamesOfValidatorSchema(_izContext, objType, [], fieldNameCanUpdates),
|
|
624
647
|
|
|
625
648
|
},
|
|
626
649
|
}
|
|
@@ -628,47 +651,55 @@ async function generateValidatorSchemaForUpdate(_izContext, objType, settings =
|
|
|
628
651
|
versionedDataIds: {
|
|
629
652
|
type: "object",
|
|
630
653
|
additionalProperties: false,
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
...await filteredFieldNamesOfValidatorSchema(_izContext, objType, [], versionedDataFieldNames)
|
|
634
|
-
|
|
654
|
+
required: [], // no need to required versionedDataLabel
|
|
655
|
+
properties: {},
|
|
635
656
|
},
|
|
636
657
|
additionalParams: {
|
|
637
658
|
type: "object"
|
|
638
659
|
}
|
|
639
660
|
}
|
|
640
661
|
}
|
|
641
|
-
const versionedDataReturnInFieldsObjInstanceFull = {}
|
|
642
|
-
for (const [versionedDataFieldName, versionedDataFieldNameSetting] of Object.entries(objectSchemas.fieldNames)) {
|
|
643
|
-
let versionedDataLabel = versionedDataFieldNameSetting.versionedDataLabel
|
|
644
|
-
if (versionedDataFieldNameSetting.hasOwnProperty("versionedDataLabel") && defaultFieldNames.includes(versionedDataFieldName)) {
|
|
645
|
-
Object.assign(versionedDataReturnInFieldsObjInstanceFull, {
|
|
646
|
-
[versionedDataFieldName]: createValidationFieldNameForEachType(
|
|
647
|
-
versionedDataFieldNameSetting.type,
|
|
648
|
-
versionedDataFieldNameSetting.validation
|
|
649
|
-
)
|
|
650
|
-
})
|
|
651
662
|
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
}
|
|
658
|
-
}
|
|
663
|
+
for (const versionedDataLabel of versionedDataLabels) {
|
|
664
|
+
Object.assign(initialValidatorSchemaForUpdate.properties.versionedDataIds.properties, {
|
|
665
|
+
[versionedDataLabel]: {
|
|
666
|
+
type: "string",
|
|
667
|
+
pattern: "^[a-zA-Z0-9_-]+$"
|
|
668
|
+
}
|
|
669
|
+
})
|
|
659
670
|
}
|
|
660
|
-
|
|
661
|
-
//
|
|
662
|
-
//
|
|
663
|
-
//
|
|
664
|
-
//
|
|
665
|
-
//
|
|
666
|
-
//
|
|
667
|
-
//
|
|
671
|
+
// _izContext.logger.debug("initialValidatorSchemaForUpdate", initialValidatorSchemaForUpdate)
|
|
672
|
+
// const versionedDataReturnInFieldsObjInstanceFull = {}
|
|
673
|
+
// for (const [versionedDataFieldName, versionedDataFieldNameSetting] of Object.entries(objectSchemas.fieldNames)) {
|
|
674
|
+
// let versionedDataLabel = versionedDataFieldNameSetting.versionedDataLabel
|
|
675
|
+
// if (versionedDataFieldNameSetting.hasOwnProperty("versionedDataLabel") && defaultFieldNames.includes(versionedDataFieldName)) {
|
|
676
|
+
// Object.assign(versionedDataReturnInFieldsObjInstanceFull, {
|
|
677
|
+
// [versionedDataFieldName]: createValidationFieldNameForEachType(
|
|
678
|
+
// versionedDataFieldNameSetting.type,
|
|
679
|
+
// versionedDataFieldNameSetting.validation
|
|
680
|
+
// )
|
|
681
|
+
// })
|
|
682
|
+
|
|
683
|
+
// Object.assign(initialValidatorSchemaForUpdate.properties.versionedDataIds.properties, {
|
|
684
|
+
// [versionedDataLabel]: {
|
|
685
|
+
// type: "string",
|
|
686
|
+
// pattern: "^[a-zA-Z0-9_-]+$"
|
|
687
|
+
// }
|
|
688
|
+
// })
|
|
668
689
|
// }
|
|
669
|
-
//
|
|
690
|
+
// }
|
|
670
691
|
|
|
671
|
-
//
|
|
692
|
+
// // console.debug("versionedDataReturnInFieldsObjInstanceFull::::", versionedDataReturnInFieldsObjInstanceFull);
|
|
693
|
+
// // console.debug("initialValidatorSchemaForUpdate:::::", initialValidatorSchemaForUpdate);
|
|
694
|
+
// // Object.assign(
|
|
695
|
+
// // initialValidatorSchemaForUpdate.properties.objInstanceFull.properties.fields.properties,
|
|
696
|
+
// // {
|
|
697
|
+
// // ...versionedDataReturnInFieldsObjInstanceFull,
|
|
698
|
+
// // ...canUpdateProperties
|
|
699
|
+
// // }
|
|
700
|
+
// // );
|
|
701
|
+
|
|
702
|
+
// // _izContext.logger.debug("validatorSchema-update::", initialValidatorSchemaForUpdate);
|
|
672
703
|
return initialValidatorSchemaForUpdate;
|
|
673
704
|
}
|
|
674
705
|
|
|
@@ -760,7 +791,7 @@ async function filteredFieldNamesOfValidatorSchema(_izContext, objType, required
|
|
|
760
791
|
|
|
761
792
|
}
|
|
762
793
|
}
|
|
763
|
-
|
|
794
|
+
console.log("returnValidatorSchema", returnValidatorSchema)
|
|
764
795
|
|
|
765
796
|
return returnValidatorSchema;
|
|
766
797
|
}
|
|
@@ -787,15 +818,16 @@ async function generateValidatorSchemaForExplodedData(_izContext, objType) {
|
|
|
787
818
|
properties: {}
|
|
788
819
|
};
|
|
789
820
|
|
|
790
|
-
let objectSchema = await
|
|
821
|
+
let objectSchema = await getObjectSchemaCombineFieldNamesWithCache(_izContext, objType);
|
|
791
822
|
// generate validatorSchema for each fieldName
|
|
792
823
|
for (let [fieldName, fieldData] of Object.entries(objectSchema.fieldNames)) {
|
|
793
824
|
let fieldNameValidator = await generateValidatorFieldNameWithCache(_izContext, fieldName, fieldData);
|
|
794
825
|
Object.assign(validatorSchema.properties, fieldNameValidator);
|
|
795
826
|
}
|
|
827
|
+
// console.log("validatorSchema.properties", validatorSchema.properties)
|
|
796
828
|
|
|
797
829
|
_izContext.logger.debug('--------------------------------------------');
|
|
798
|
-
_izContext.logger.debug('validatorSchema fieldName :: ', JSON.stringify(validatorSchema.properties));
|
|
830
|
+
_izContext.logger.debug('validatorSchema fieldName :: ', JSON.stringify(validatorSchema.properties, null, 2));
|
|
799
831
|
_izContext.logger.debug('--------------------------------------------');
|
|
800
832
|
|
|
801
833
|
// generate validatorSchema for each identifier
|
|
@@ -1260,27 +1292,33 @@ async function validateLocalSchema(_izContext, schemasPath, serviceConfigPath) {
|
|
|
1260
1292
|
for (const flowSchema of allFlowSchemas) {
|
|
1261
1293
|
const [status, errors] = validateBasicFlowSchema(_izContext, flowSchema)
|
|
1262
1294
|
|
|
1263
|
-
if (flowSchema.
|
|
1264
|
-
|
|
1295
|
+
if (!flowSchema.hasOwnProperty("objType")) {
|
|
1296
|
+
validateStatus.status = false;
|
|
1297
|
+
validateStatus.validateErrors.push(`flowSchema ${flowSchema.flowTag} must have objType`)
|
|
1298
|
+
} else {
|
|
1299
|
+
let [objSchema] = await getLocalOrS3ObjectSchema(flowSchema.objType);
|
|
1300
|
+
|
|
1301
|
+
if (!objSchema) {
|
|
1265
1302
|
validateStatus.status = false;
|
|
1266
|
-
validateStatus.validateErrors.push(
|
|
1303
|
+
validateStatus.validateErrors.push(`${flowSchema.flowTag}.objType is invalid`)
|
|
1267
1304
|
} else {
|
|
1268
|
-
|
|
1269
|
-
let [objSchema] = await getLocalOrS3ObjectSchema(flowSchema.objType);
|
|
1270
|
-
|
|
1271
|
-
console.log("objSchema: ", objSchema)
|
|
1272
|
-
|
|
1273
|
-
if (!objSchema) {
|
|
1305
|
+
if (Object.keys(objSchema.storageResources).length > 1) { // check for objectSchema must have 1 storageResource
|
|
1274
1306
|
validateStatus.status = false;
|
|
1275
|
-
validateStatus.validateErrors.push(
|
|
1276
|
-
} else {
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
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
|
+
}
|
|
1319
|
+
}
|
|
1320
|
+
} else if (flowSchema.statusType === "statusField") {
|
|
1321
|
+
let specificFieldNames = Object.values(createSpecificFieldNameForCacheTable(createFlowTypeConcat(_izContext, { flowTag: flowSchema.flowTag, serviceTag: iz_serviceTag }), 'statusField'))
|
|
1284
1322
|
const fieldNames = Object.keys(objSchema.fieldNames)
|
|
1285
1323
|
for (const specificFieldName of specificFieldNames) { // check for specific fieldName
|
|
1286
1324
|
if (!fieldNames.includes(specificFieldName)) {
|
|
@@ -1288,39 +1326,27 @@ async function validateLocalSchema(_izContext, schemasPath, serviceConfigPath) {
|
|
|
1288
1326
|
validateStatus.validateErrors.push(`objectType: ${objSchema.objectType} not have fieldNames: ${specificFieldName} in objectSchema.fieldNames`)
|
|
1289
1327
|
}
|
|
1290
1328
|
}
|
|
1291
|
-
} else {
|
|
1292
|
-
validateStatus.status = false;
|
|
1293
|
-
validateStatus.validateErrors.push(`storageResource of objectType:${objSchema.objectType} serviceTag:${flowSchema.objType.serviceTag} must be dynamoDb`)
|
|
1294
1329
|
}
|
|
1330
|
+
} else {
|
|
1331
|
+
validateStatus.status = false;
|
|
1332
|
+
validateStatus.validateErrors.push(`storageResource of ObjectType: $${flowSchema.objType.flowTag} from flowTag: ${flowSchema.flowTag} must be dynamoDB`);
|
|
1295
1333
|
}
|
|
1296
1334
|
}
|
|
1297
1335
|
}
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
if (!status) {
|
|
1302
|
-
validateStatus.status = false;
|
|
1303
|
-
validateStatus.validateErrors.push(errors);
|
|
1304
|
-
}
|
|
1305
1336
|
}
|
|
1306
1337
|
}
|
|
1307
1338
|
|
|
1308
|
-
if (
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
validateStatus.validateErrors.push(`flowSchema ${flowSchema.flowTag} must have objType`)
|
|
1312
|
-
} else {
|
|
1313
|
-
let [objSchema] = await getLocalOrS3ObjectSchema(flowSchema.objType);
|
|
1314
|
-
|
|
1315
|
-
if (!objSchema) {
|
|
1316
|
-
validateStatus.status = false;
|
|
1317
|
-
validateStatus.validateErrors.push(`${flowSchema.flowTag}.objType is invalid`)
|
|
1318
|
-
}
|
|
1319
|
-
}
|
|
1339
|
+
if (!status) {
|
|
1340
|
+
validateStatus.status = false;
|
|
1341
|
+
validateStatus.validateErrors.push(errors);
|
|
1320
1342
|
}
|
|
1321
1343
|
}
|
|
1344
|
+
|
|
1322
1345
|
}
|
|
1323
1346
|
|
|
1347
|
+
|
|
1348
|
+
|
|
1349
|
+
|
|
1324
1350
|
if (validateStatus.validateErrors.length) {
|
|
1325
1351
|
validateStatus.status = false;
|
|
1326
1352
|
} else {
|