@izara_project/izara-core-library-service-schemas 1.0.96 → 1.0.97
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 +98 -73
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 {
|
|
@@ -536,46 +537,22 @@ async function generateValidatorSchemaForUpdate(_izContext, objType, settings =
|
|
|
536
537
|
// _izContext.logger.debug("objectSchema", objectSchema)
|
|
537
538
|
|
|
538
539
|
const objectSchemas = await uploadUseCase.generateObjectSchemaForCombineFieldNames(_izContext, objectSchema)
|
|
539
|
-
_izContext.logger.debug("objectSchemas", objectSchemas)
|
|
540
|
+
// _izContext.logger.debug("objectSchemas", objectSchemas)
|
|
540
541
|
|
|
541
542
|
let usedIdentifierTypes = getIdentifierTypeByPriority(_izContext, [], objectSchema);
|
|
542
543
|
_izContext.logger.debug({ usedIdentifierTypes });
|
|
543
544
|
// collect requiredFieldNames by fieldName that includes in identifiers
|
|
544
545
|
let identifiersFieldNames = getUsedFieldNamesOfIdentifiers(_izContext, objectSchemas.identifiers, usedIdentifierTypes);
|
|
546
|
+
// _izContext.logger.debug("identifiersFieldNames", identifiersFieldNames)
|
|
547
|
+
let fieldNameCanUpdates = [];
|
|
548
|
+
let versionedDataFieldNameCanUpdates = [];
|
|
545
549
|
|
|
546
|
-
let canUpdateFieldNames = [];
|
|
547
|
-
let canUpdateProperties = {};
|
|
550
|
+
// let canUpdateFieldNames = [];
|
|
551
|
+
// let canUpdateProperties = {};
|
|
548
552
|
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 });
|
|
553
|
+
// let versionedDataFieldNames = [];
|
|
554
|
+
// collect fieldNames that canUpdate
|
|
577
555
|
|
|
578
|
-
// collect usedFieldNames
|
|
579
556
|
if (settings?.specificFieldNames) {
|
|
580
557
|
if (settings.specificFieldNames.length) {
|
|
581
558
|
for (let specificFieldName of settings.specificFieldNames) {
|
|
@@ -586,17 +563,56 @@ async function generateValidatorSchemaForUpdate(_izContext, objType, settings =
|
|
|
586
563
|
}
|
|
587
564
|
}
|
|
588
565
|
} else {
|
|
589
|
-
usedFieldNames = usedFieldNames.concat(
|
|
566
|
+
usedFieldNames = usedFieldNames.concat(fieldNameCanUpdates);
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
let versionedDataLabels = [];
|
|
570
|
+
for (const [fieldName, fieldSetting] of Object.entries(objectSchemas.fieldNames)) {
|
|
571
|
+
if (fieldSetting.canUpdate === true) {
|
|
572
|
+
fieldNameCanUpdates.push(fieldName)
|
|
573
|
+
if (fieldSetting.hasOwnProperty("versionedDataLabel")) {
|
|
574
|
+
versionedDataFieldNameCanUpdates.push(fieldName)
|
|
575
|
+
versionedDataLabels.push(fieldSetting.versionedDataLabel)
|
|
576
|
+
}
|
|
590
577
|
}
|
|
591
578
|
}
|
|
592
579
|
|
|
580
|
+
versionedDataLabels = [...new Set(versionedDataLabels)]
|
|
581
|
+
// console.log("versionedDataLabelValidatorSchema", versionedDataLabel)
|
|
582
|
+
// // collect canUpdate fieldName (all fieldName have CanUpdate setting = true)
|
|
583
|
+
// for (let [fieldName, fieldNameSetting] of Object.entries(objectSchemas.fieldNames)) {
|
|
584
|
+
// if (settings.handler === "ApiGateway") {
|
|
585
|
+
// if (fieldNameSetting.userCanUpdate === true) {
|
|
586
|
+
// canUpdateFieldNames.push(fieldName);
|
|
587
|
+
// canUpdateProperties[fieldName] = {
|
|
588
|
+
// type: fieldNameSetting.type
|
|
589
|
+
// }
|
|
590
|
+
// if (fieldNameSetting.hasOwnProperty("versionedDataLabel")) {
|
|
591
|
+
// versionedDataFieldNames.push(fieldName)
|
|
592
|
+
// }
|
|
593
|
+
// }
|
|
594
|
+
// } else {
|
|
595
|
+
// if (fieldNameSetting.canUpdate === true || fieldNameSetting.canUpdate === undefined) {
|
|
596
|
+
// canUpdateFieldNames.push(fieldName);
|
|
597
|
+
// canUpdateProperties[fieldName] = {
|
|
598
|
+
// type: fieldNameSetting.type,
|
|
599
|
+
// }
|
|
600
|
+
// if (fieldNameSetting.hasOwnProperty("versionedDataLabel")) {
|
|
601
|
+
// versionedDataFieldNames.push(fieldName)
|
|
602
|
+
// }
|
|
603
|
+
// }
|
|
604
|
+
// }
|
|
605
|
+
// }
|
|
606
|
+
|
|
607
|
+
// _izContext.logger.debug("canUpdate::::", { fieldNameCanUpdates, versionedDataFieldNameCanUpdates });
|
|
608
|
+
|
|
593
609
|
usedFieldNames = [...new Set(usedFieldNames)];
|
|
594
610
|
|
|
595
|
-
let defaultFieldNames = usedFieldNames.filter(fieldName => !identifiersFieldNames.includes(fieldName));
|
|
611
|
+
// let defaultFieldNames = usedFieldNames.filter(fieldName => !identifiersFieldNames.includes(fieldName));
|
|
596
612
|
|
|
597
|
-
// _izContext.logger.debug('identifiersFieldNames : ', identifiersFieldNames);
|
|
598
|
-
// _izContext.logger.debug('usedFieldNames : ', usedFieldNames); // all fieldName
|
|
599
|
-
// _izContext.logger.debug("defaultFieldNames :", defaultFieldNames);
|
|
613
|
+
// // _izContext.logger.debug('identifiersFieldNames : ', identifiersFieldNames);
|
|
614
|
+
// // _izContext.logger.debug('usedFieldNames : ', usedFieldNames); // all fieldName
|
|
615
|
+
// // _izContext.logger.debug("defaultFieldNames :", defaultFieldNames);
|
|
600
616
|
// _izContext.logger.debug("versionedDataFieldNames :", versionedDataFieldNames);
|
|
601
617
|
|
|
602
618
|
let initialValidatorSchemaForUpdate = {
|
|
@@ -620,7 +636,7 @@ async function generateValidatorSchemaForUpdate(_izContext, objType, settings =
|
|
|
620
636
|
additionalProperties: false,
|
|
621
637
|
// required: [],
|
|
622
638
|
// properties: {},
|
|
623
|
-
...await filteredFieldNamesOfValidatorSchema(_izContext, objType, [],
|
|
639
|
+
...await filteredFieldNamesOfValidatorSchema(_izContext, objType, [], fieldNameCanUpdates),
|
|
624
640
|
|
|
625
641
|
},
|
|
626
642
|
}
|
|
@@ -628,47 +644,55 @@ async function generateValidatorSchemaForUpdate(_izContext, objType, settings =
|
|
|
628
644
|
versionedDataIds: {
|
|
629
645
|
type: "object",
|
|
630
646
|
additionalProperties: false,
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
...await filteredFieldNamesOfValidatorSchema(_izContext, objType, [], versionedDataFieldNames)
|
|
634
|
-
|
|
647
|
+
required: [], // no need to required versionedDataLabel
|
|
648
|
+
properties: {},
|
|
635
649
|
},
|
|
636
650
|
additionalParams: {
|
|
637
651
|
type: "object"
|
|
638
652
|
}
|
|
639
653
|
}
|
|
640
654
|
}
|
|
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
655
|
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
}
|
|
658
|
-
}
|
|
656
|
+
for (const versionedDataLabel of versionedDataLabels) {
|
|
657
|
+
Object.assign(initialValidatorSchemaForUpdate.properties.versionedDataIds.properties, {
|
|
658
|
+
[versionedDataLabel]: {
|
|
659
|
+
type: "string",
|
|
660
|
+
pattern: "^[a-zA-Z0-9_-]+$"
|
|
661
|
+
}
|
|
662
|
+
})
|
|
659
663
|
}
|
|
660
|
-
|
|
661
|
-
//
|
|
662
|
-
//
|
|
663
|
-
//
|
|
664
|
-
//
|
|
665
|
-
//
|
|
666
|
-
//
|
|
667
|
-
//
|
|
664
|
+
// _izContext.logger.debug("initialValidatorSchemaForUpdate", initialValidatorSchemaForUpdate)
|
|
665
|
+
// const versionedDataReturnInFieldsObjInstanceFull = {}
|
|
666
|
+
// for (const [versionedDataFieldName, versionedDataFieldNameSetting] of Object.entries(objectSchemas.fieldNames)) {
|
|
667
|
+
// let versionedDataLabel = versionedDataFieldNameSetting.versionedDataLabel
|
|
668
|
+
// if (versionedDataFieldNameSetting.hasOwnProperty("versionedDataLabel") && defaultFieldNames.includes(versionedDataFieldName)) {
|
|
669
|
+
// Object.assign(versionedDataReturnInFieldsObjInstanceFull, {
|
|
670
|
+
// [versionedDataFieldName]: createValidationFieldNameForEachType(
|
|
671
|
+
// versionedDataFieldNameSetting.type,
|
|
672
|
+
// versionedDataFieldNameSetting.validation
|
|
673
|
+
// )
|
|
674
|
+
// })
|
|
675
|
+
|
|
676
|
+
// Object.assign(initialValidatorSchemaForUpdate.properties.versionedDataIds.properties, {
|
|
677
|
+
// [versionedDataLabel]: {
|
|
678
|
+
// type: "string",
|
|
679
|
+
// pattern: "^[a-zA-Z0-9_-]+$"
|
|
680
|
+
// }
|
|
681
|
+
// })
|
|
668
682
|
// }
|
|
669
|
-
//
|
|
683
|
+
// }
|
|
670
684
|
|
|
671
|
-
//
|
|
685
|
+
// // console.debug("versionedDataReturnInFieldsObjInstanceFull::::", versionedDataReturnInFieldsObjInstanceFull);
|
|
686
|
+
// // console.debug("initialValidatorSchemaForUpdate:::::", initialValidatorSchemaForUpdate);
|
|
687
|
+
// // Object.assign(
|
|
688
|
+
// // initialValidatorSchemaForUpdate.properties.objInstanceFull.properties.fields.properties,
|
|
689
|
+
// // {
|
|
690
|
+
// // ...versionedDataReturnInFieldsObjInstanceFull,
|
|
691
|
+
// // ...canUpdateProperties
|
|
692
|
+
// // }
|
|
693
|
+
// // );
|
|
694
|
+
|
|
695
|
+
// // _izContext.logger.debug("validatorSchema-update::", initialValidatorSchemaForUpdate);
|
|
672
696
|
return initialValidatorSchemaForUpdate;
|
|
673
697
|
}
|
|
674
698
|
|
|
@@ -760,7 +784,7 @@ async function filteredFieldNamesOfValidatorSchema(_izContext, objType, required
|
|
|
760
784
|
|
|
761
785
|
}
|
|
762
786
|
}
|
|
763
|
-
|
|
787
|
+
console.log("returnValidatorSchema", returnValidatorSchema)
|
|
764
788
|
|
|
765
789
|
return returnValidatorSchema;
|
|
766
790
|
}
|
|
@@ -787,15 +811,16 @@ async function generateValidatorSchemaForExplodedData(_izContext, objType) {
|
|
|
787
811
|
properties: {}
|
|
788
812
|
};
|
|
789
813
|
|
|
790
|
-
let objectSchema = await
|
|
814
|
+
let objectSchema = await getObjectSchemaCombineFieldNamesWithCache(_izContext, objType);
|
|
791
815
|
// generate validatorSchema for each fieldName
|
|
792
816
|
for (let [fieldName, fieldData] of Object.entries(objectSchema.fieldNames)) {
|
|
793
817
|
let fieldNameValidator = await generateValidatorFieldNameWithCache(_izContext, fieldName, fieldData);
|
|
794
818
|
Object.assign(validatorSchema.properties, fieldNameValidator);
|
|
795
819
|
}
|
|
820
|
+
// console.log("validatorSchema.properties", validatorSchema.properties)
|
|
796
821
|
|
|
797
822
|
_izContext.logger.debug('--------------------------------------------');
|
|
798
|
-
_izContext.logger.debug('validatorSchema fieldName :: ', JSON.stringify(validatorSchema.properties));
|
|
823
|
+
_izContext.logger.debug('validatorSchema fieldName :: ', JSON.stringify(validatorSchema.properties, null, 2));
|
|
799
824
|
_izContext.logger.debug('--------------------------------------------');
|
|
800
825
|
|
|
801
826
|
// generate validatorSchema for each identifier
|