nox-validation 1.3.6 → 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 +62 -35
- package/package.json +1 -1
package/lib/helpers.js
CHANGED
|
@@ -505,7 +505,8 @@ const generateRelationalField = (
|
|
|
505
505
|
constants.types.OBJECT,
|
|
506
506
|
[...collectionFields],
|
|
507
507
|
"none",
|
|
508
|
-
[constants.types.OBJECT_ID]
|
|
508
|
+
[constants.types.OBJECT_ID],
|
|
509
|
+
{ ...collection_id_meta, is_m2a_item: true }
|
|
509
510
|
),
|
|
510
511
|
];
|
|
511
512
|
return [existingField, deleteField, createField, updateField];
|
|
@@ -730,6 +731,7 @@ const buildNestedStructure = ({
|
|
|
730
731
|
currentDepthMap,
|
|
731
732
|
rootPath,
|
|
732
733
|
isRoot,
|
|
734
|
+
modifyChild = true,
|
|
733
735
|
}) => {
|
|
734
736
|
const root = {};
|
|
735
737
|
const nodeMap = new Map();
|
|
@@ -777,6 +779,14 @@ const buildNestedStructure = ({
|
|
|
777
779
|
} else {
|
|
778
780
|
childFields = getCachedFields(relationDetail, relational_fields);
|
|
779
781
|
}
|
|
782
|
+
if (item.meta.interface === constants.interfaces.TRANSLATIONS) {
|
|
783
|
+
childFields = childFields.filter(
|
|
784
|
+
(f) =>
|
|
785
|
+
f.field !== relationDetail.foreign_field &&
|
|
786
|
+
f.field !== relationDetail.junction_field_this &&
|
|
787
|
+
f.field !== relationDetail.junction_field_foreign
|
|
788
|
+
);
|
|
789
|
+
}
|
|
780
790
|
|
|
781
791
|
if (childFields) {
|
|
782
792
|
if (!isRoot) currentDepthMap.set(rootPath, currentDepth + 1);
|
|
@@ -792,6 +802,7 @@ const buildNestedStructure = ({
|
|
|
792
802
|
currentDepthMap,
|
|
793
803
|
rootPath: isRoot ? item.path : rootPath,
|
|
794
804
|
isRoot: false,
|
|
805
|
+
modifyChild,
|
|
795
806
|
});
|
|
796
807
|
}
|
|
797
808
|
}
|
|
@@ -807,25 +818,41 @@ const buildNestedStructure = ({
|
|
|
807
818
|
item.type === constants.types.ARRAY;
|
|
808
819
|
|
|
809
820
|
let children = [];
|
|
810
|
-
|
|
811
821
|
if (childFields?.length > 0) {
|
|
812
|
-
if (isV2File) {
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
key,
|
|
820
|
-
childFields,
|
|
821
|
-
item.meta?.interface
|
|
822
|
-
);
|
|
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);
|
|
823
829
|
} else {
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
)
|
|
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;
|
|
829
856
|
}
|
|
830
857
|
}
|
|
831
858
|
|
|
@@ -873,29 +900,27 @@ const buildNestedStructure = ({
|
|
|
873
900
|
),
|
|
874
901
|
custom_error_message: item?.meta?.validations?.validation_msg,
|
|
875
902
|
children,
|
|
876
|
-
// childFields?.length > 0
|
|
877
|
-
// ? isV2File
|
|
878
|
-
// ? childFields
|
|
879
|
-
// : apiVersion === constants.API_VERSION.V1 &&
|
|
880
|
-
// item.meta?.interface !== constants.interfaces.TRANSLATIONS
|
|
881
|
-
// ? generateRelationalFieldV1(key, childFields, item.meta?.interface)
|
|
882
|
-
// : generateRelationalField(key, childFields, item.meta?.interface)
|
|
883
|
-
// : [],
|
|
884
903
|
type: definedType.type,
|
|
885
904
|
array_type: definedType.array_type,
|
|
886
905
|
default_value: item?.schema_definition?.default,
|
|
887
906
|
};
|
|
888
907
|
|
|
889
|
-
|
|
908
|
+
const compositeKey = `${key}::${node.schema_id}`;
|
|
909
|
+
nodeMap.set(compositeKey, node);
|
|
890
910
|
|
|
891
911
|
if (pathParts.length === 1) {
|
|
892
|
-
root[
|
|
912
|
+
root[compositeKey] = node;
|
|
893
913
|
} else {
|
|
894
914
|
const parentPath = pathParts.slice(0, -1).join(".");
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
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
|
+
// }
|
|
899
924
|
}
|
|
900
925
|
});
|
|
901
926
|
|
|
@@ -1276,21 +1301,23 @@ const getM2AItemParentPath = (path) => {
|
|
|
1276
1301
|
|
|
1277
1302
|
const getSelectedNodes = ({
|
|
1278
1303
|
node,
|
|
1279
|
-
skipFn= (node)=> node.meta?.interface === constants.interfaces.MANY_TO_ANY,
|
|
1304
|
+
skipFn = (node) => node.meta?.interface === constants.interfaces.MANY_TO_ANY,
|
|
1280
1305
|
conditionFn = (node) => node.meta?.required === true,
|
|
1281
1306
|
mapFn = (node) => ({ key: node.key, label: node.display_label }),
|
|
1282
1307
|
actionFn = (node) => {},
|
|
1283
1308
|
}) => {
|
|
1284
1309
|
const result = [];
|
|
1285
1310
|
|
|
1286
|
-
function traverse(currentNode) {
|
|
1311
|
+
function traverse(currentNode) {
|
|
1287
1312
|
if (conditionFn(currentNode)) {
|
|
1288
1313
|
actionFn(currentNode);
|
|
1289
1314
|
result.push(mapFn(currentNode));
|
|
1290
1315
|
}
|
|
1291
1316
|
|
|
1292
1317
|
if (Array.isArray(currentNode.children)) {
|
|
1293
|
-
currentNode.children.forEach((child) =>{
|
|
1318
|
+
currentNode.children.forEach((child) => {
|
|
1319
|
+
if (!skipFn(currentNode)) traverse(child);
|
|
1320
|
+
});
|
|
1294
1321
|
}
|
|
1295
1322
|
}
|
|
1296
1323
|
|