nox-validation 1.3.7 → 1.3.8
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/lib/helpers.js +53 -35
- package/package.json +1 -1
package/lib/helpers.js
CHANGED
|
@@ -731,6 +731,7 @@ const buildNestedStructure = ({
|
|
|
731
731
|
currentDepthMap,
|
|
732
732
|
rootPath,
|
|
733
733
|
isRoot,
|
|
734
|
+
modifyChild = true,
|
|
734
735
|
}) => {
|
|
735
736
|
const root = {};
|
|
736
737
|
const nodeMap = new Map();
|
|
@@ -778,7 +779,7 @@ const buildNestedStructure = ({
|
|
|
778
779
|
} else {
|
|
779
780
|
childFields = getCachedFields(relationDetail, relational_fields);
|
|
780
781
|
}
|
|
781
|
-
if(item.meta.interface === constants.interfaces.TRANSLATIONS){
|
|
782
|
+
if (item.meta.interface === constants.interfaces.TRANSLATIONS) {
|
|
782
783
|
childFields = childFields.filter(
|
|
783
784
|
(f) =>
|
|
784
785
|
f.field !== relationDetail.foreign_field &&
|
|
@@ -801,6 +802,7 @@ const buildNestedStructure = ({
|
|
|
801
802
|
currentDepthMap,
|
|
802
803
|
rootPath: isRoot ? item.path : rootPath,
|
|
803
804
|
isRoot: false,
|
|
805
|
+
modifyChild,
|
|
804
806
|
});
|
|
805
807
|
}
|
|
806
808
|
}
|
|
@@ -816,25 +818,41 @@ const buildNestedStructure = ({
|
|
|
816
818
|
item.type === constants.types.ARRAY;
|
|
817
819
|
|
|
818
820
|
let children = [];
|
|
819
|
-
|
|
820
821
|
if (childFields?.length > 0) {
|
|
821
|
-
if (isV2File) {
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
key,
|
|
829
|
-
childFields,
|
|
830
|
-
item.meta?.interface
|
|
831
|
-
);
|
|
822
|
+
if (modifyChild && !isV2File) {
|
|
823
|
+
const isTranslationInterface =
|
|
824
|
+
item.meta?.interface === constants.interfaces.TRANSLATIONS;
|
|
825
|
+
children =
|
|
826
|
+
apiVersion === constants.API_VERSION.V1 && !isTranslationInterface
|
|
827
|
+
? generateRelationalFieldV1(key, childFields, item.meta?.interface)
|
|
828
|
+
: generateRelationalField(key, childFields, item.meta?.interface);
|
|
832
829
|
} else {
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
)
|
|
830
|
+
// if (!modifyChild) {
|
|
831
|
+
// if (Array.isArray(childFields) && item.meta?.interface === constants.interfaces.TRANSLATIONS) {
|
|
832
|
+
// function prefixChildKeys(child, parentKey) {
|
|
833
|
+
// // If the key already starts with parentKey, return as is
|
|
834
|
+
// if (child.key && child.key.startsWith(`${parentKey}.`)) {
|
|
835
|
+
// return {
|
|
836
|
+
// ...child,
|
|
837
|
+
// children: Array.isArray(child.children)
|
|
838
|
+
// ? child.children.map(grandChild => prefixChildKeys(grandChild, child.key))
|
|
839
|
+
// : child.children
|
|
840
|
+
// };
|
|
841
|
+
// }
|
|
842
|
+
// // Otherwise, prefix the key and value, and recurse into children
|
|
843
|
+
// return {
|
|
844
|
+
// ...child,
|
|
845
|
+
// key: `${parentKey}.${child.key}`,
|
|
846
|
+
// value: `${parentKey}.${child.key}`,
|
|
847
|
+
// children: Array.isArray(child.children)
|
|
848
|
+
// ? child.children.map(grandChild => prefixChildKeys(grandChild, parentKey))
|
|
849
|
+
// : child.children
|
|
850
|
+
// };
|
|
851
|
+
// }
|
|
852
|
+
// childFields = childFields.map(child => prefixChildKeys(child, key));
|
|
853
|
+
// }
|
|
854
|
+
// }
|
|
855
|
+
children = childFields;
|
|
838
856
|
}
|
|
839
857
|
}
|
|
840
858
|
|
|
@@ -882,29 +900,27 @@ const buildNestedStructure = ({
|
|
|
882
900
|
),
|
|
883
901
|
custom_error_message: item?.meta?.validations?.validation_msg,
|
|
884
902
|
children,
|
|
885
|
-
// childFields?.length > 0
|
|
886
|
-
// ? isV2File
|
|
887
|
-
// ? childFields
|
|
888
|
-
// : apiVersion === constants.API_VERSION.V1 &&
|
|
889
|
-
// item.meta?.interface !== constants.interfaces.TRANSLATIONS
|
|
890
|
-
// ? generateRelationalFieldV1(key, childFields, item.meta?.interface)
|
|
891
|
-
// : generateRelationalField(key, childFields, item.meta?.interface)
|
|
892
|
-
// : [],
|
|
893
903
|
type: definedType.type,
|
|
894
904
|
array_type: definedType.array_type,
|
|
895
905
|
default_value: item?.schema_definition?.default,
|
|
896
906
|
};
|
|
897
907
|
|
|
898
|
-
|
|
908
|
+
const compositeKey = `${key}::${node.schema_id}`;
|
|
909
|
+
nodeMap.set(compositeKey, node);
|
|
899
910
|
|
|
900
911
|
if (pathParts.length === 1) {
|
|
901
|
-
root[
|
|
912
|
+
root[compositeKey] = node;
|
|
902
913
|
} else {
|
|
903
914
|
const parentPath = pathParts.slice(0, -1).join(".");
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
915
|
+
const parentCompositeKey = `${parentPath}::${node.schema_id}`;
|
|
916
|
+
const parentNode = nodeMap.get(parentCompositeKey);
|
|
917
|
+
|
|
918
|
+
if (parentNode) {
|
|
919
|
+
parentNode.children.push(node);
|
|
920
|
+
}
|
|
921
|
+
// else {
|
|
922
|
+
// console.warn("[WARN] Parent node not found for:", node);
|
|
923
|
+
// }
|
|
908
924
|
}
|
|
909
925
|
});
|
|
910
926
|
|
|
@@ -1285,21 +1301,23 @@ const getM2AItemParentPath = (path) => {
|
|
|
1285
1301
|
|
|
1286
1302
|
const getSelectedNodes = ({
|
|
1287
1303
|
node,
|
|
1288
|
-
skipFn= (node)=> node.meta?.interface === constants.interfaces.MANY_TO_ANY,
|
|
1304
|
+
skipFn = (node) => node.meta?.interface === constants.interfaces.MANY_TO_ANY,
|
|
1289
1305
|
conditionFn = (node) => node.meta?.required === true,
|
|
1290
1306
|
mapFn = (node) => ({ key: node.key, label: node.display_label }),
|
|
1291
1307
|
actionFn = (node) => {},
|
|
1292
1308
|
}) => {
|
|
1293
1309
|
const result = [];
|
|
1294
1310
|
|
|
1295
|
-
function traverse(currentNode) {
|
|
1311
|
+
function traverse(currentNode) {
|
|
1296
1312
|
if (conditionFn(currentNode)) {
|
|
1297
1313
|
actionFn(currentNode);
|
|
1298
1314
|
result.push(mapFn(currentNode));
|
|
1299
1315
|
}
|
|
1300
1316
|
|
|
1301
1317
|
if (Array.isArray(currentNode.children)) {
|
|
1302
|
-
currentNode.children.forEach((child) =>{
|
|
1318
|
+
currentNode.children.forEach((child) => {
|
|
1319
|
+
if (!skipFn(currentNode)) traverse(child);
|
|
1320
|
+
});
|
|
1303
1321
|
}
|
|
1304
1322
|
}
|
|
1305
1323
|
|