nox-validation 1.6.2 → 1.6.4
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 +26 -1
- package/lib/validate.js +64 -29
- package/package.json +1 -1
package/lib/helpers.js
CHANGED
|
@@ -1404,6 +1404,20 @@ const getM2AItemParentPath = (path) => {
|
|
|
1404
1404
|
return match ? path.replace(".item", "") : null;
|
|
1405
1405
|
};
|
|
1406
1406
|
|
|
1407
|
+
const addIndexToStaticType = (key, staticType) => {
|
|
1408
|
+
const parts = key.split(".");
|
|
1409
|
+
|
|
1410
|
+
return parts
|
|
1411
|
+
.map((part) => {
|
|
1412
|
+
if (part === staticType) {
|
|
1413
|
+
// If staticType is found AND missing index → add [0]
|
|
1414
|
+
return part.includes("[") ? part : `${part}[0]`;
|
|
1415
|
+
}
|
|
1416
|
+
return part;
|
|
1417
|
+
})
|
|
1418
|
+
.join(".");
|
|
1419
|
+
};
|
|
1420
|
+
|
|
1407
1421
|
const getSelectedNodes = ({
|
|
1408
1422
|
node,
|
|
1409
1423
|
skipFn = (node) => node.meta?.interface === constants.interfaces.MANY_TO_ANY,
|
|
@@ -1456,6 +1470,17 @@ const getSelectedNodes = ({
|
|
|
1456
1470
|
return [...par, ...cur].join(".");
|
|
1457
1471
|
}
|
|
1458
1472
|
|
|
1473
|
+
if (currentNode?.meta?.staticType) {
|
|
1474
|
+
currentNode.key = addIndexToStaticType(
|
|
1475
|
+
currentNode.key,
|
|
1476
|
+
currentNode?.meta?.staticType
|
|
1477
|
+
);
|
|
1478
|
+
currentNode.value = addIndexToStaticType(
|
|
1479
|
+
currentNode.value,
|
|
1480
|
+
currentNode?.meta?.staticType
|
|
1481
|
+
);
|
|
1482
|
+
}
|
|
1483
|
+
|
|
1459
1484
|
if (parentKey)
|
|
1460
1485
|
currentNode.key = mergePathLevels(currentNode.key, parentKey);
|
|
1461
1486
|
|
|
@@ -1564,7 +1589,7 @@ const rebuildFullPath = (nodePath, fullPath, modifierFn) => {
|
|
|
1564
1589
|
// 1. Find parent path
|
|
1565
1590
|
const index = fullPath.lastIndexOf(nodePath);
|
|
1566
1591
|
if (index === -1) {
|
|
1567
|
-
|
|
1592
|
+
return fullPath;
|
|
1568
1593
|
}
|
|
1569
1594
|
|
|
1570
1595
|
const parentPath = fullPath.slice(0, index).replace(/\.$/, "");
|
package/lib/validate.js
CHANGED
|
@@ -278,7 +278,8 @@ const validateMetaRules = (
|
|
|
278
278
|
formData,
|
|
279
279
|
language_codes = [],
|
|
280
280
|
existingForm = {},
|
|
281
|
-
getNodes = true
|
|
281
|
+
getNodes = true,
|
|
282
|
+
translatedPath = null
|
|
282
283
|
) => {
|
|
283
284
|
const fieldValue = providedValue;
|
|
284
285
|
|
|
@@ -393,12 +394,20 @@ const validateMetaRules = (
|
|
|
393
394
|
);
|
|
394
395
|
addError(
|
|
395
396
|
currentPath,
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
397
|
+
translatedPath
|
|
398
|
+
? {
|
|
399
|
+
label: formatLabel(field.display_label),
|
|
400
|
+
fieldPath: currentPath,
|
|
401
|
+
description: "",
|
|
402
|
+
translation_path: translatedPath,
|
|
403
|
+
message,
|
|
404
|
+
}
|
|
405
|
+
: {
|
|
406
|
+
label: formatLabel(field.display_label),
|
|
407
|
+
fieldPath: currentPath,
|
|
408
|
+
description: "",
|
|
409
|
+
message,
|
|
410
|
+
},
|
|
402
411
|
field
|
|
403
412
|
);
|
|
404
413
|
}
|
|
@@ -464,7 +473,6 @@ const validateMetaRules = (
|
|
|
464
473
|
field?.meta?.interface === constants.interfaces.TRANSLATIONS;
|
|
465
474
|
let fPath = node.key?.replace("[0][0]", "[0]");
|
|
466
475
|
const types = ["update", "delete", "existing", "create"];
|
|
467
|
-
|
|
468
476
|
const extractFirstType = (key) => {
|
|
469
477
|
const regex = new RegExp(`(${types.join("|")})\\[`, "i");
|
|
470
478
|
const match = key.match(regex);
|
|
@@ -505,34 +513,48 @@ const validateMetaRules = (
|
|
|
505
513
|
isTranslationNode &&
|
|
506
514
|
Array.isArray(language_codes) &&
|
|
507
515
|
language_codes.length > 1;
|
|
508
|
-
|
|
509
516
|
if (isMultiLang) {
|
|
510
517
|
language_codes.forEach((lang, index) => {
|
|
511
|
-
let langPath,
|
|
512
|
-
|
|
513
|
-
|
|
518
|
+
let langPath, transformedPath;
|
|
519
|
+
let isAdded = false;
|
|
520
|
+
|
|
521
|
+
// Check if current language entry exists in fieldValue.create
|
|
522
|
+
if (
|
|
523
|
+
Array.isArray(fieldValue?.create) &&
|
|
524
|
+
fieldValue?.create.some((item, idx) => {
|
|
525
|
+
// Check by languages_code or by index match
|
|
526
|
+
return item.languages_code === lang || idx === index;
|
|
527
|
+
})
|
|
528
|
+
) {
|
|
529
|
+
isAdded = true;
|
|
530
|
+
}
|
|
514
531
|
|
|
515
|
-
if (
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
if (exist) isAdded = true;
|
|
532
|
+
if (
|
|
533
|
+
node?.value?.includes("create[0].") ||
|
|
534
|
+
node?.value?.includes("create[0]")
|
|
535
|
+
) {
|
|
520
536
|
langPath = rebuildFullPath(node.value, node.key, (path) =>
|
|
521
|
-
path.replace(
|
|
537
|
+
path.replace(/create\[0\]\./, `create[${index}].`)
|
|
522
538
|
);
|
|
523
539
|
transformedPath = rebuildFullPath(node.value, node.key, (path) =>
|
|
524
|
-
path
|
|
540
|
+
path
|
|
541
|
+
.replace(/create\[0\]\./, `create[${index}].`)
|
|
542
|
+
.replace(/\[0\]\./, `[${lang}].`)
|
|
525
543
|
);
|
|
526
544
|
} else {
|
|
527
|
-
langPath = rebuildFullPath(node.value, node.key, (path) =>
|
|
528
|
-
path.replace(
|
|
529
|
-
);
|
|
545
|
+
langPath = rebuildFullPath(node.value, node.key, (path) => {
|
|
546
|
+
return path.replace(/create\./, `create[${index}].`);
|
|
547
|
+
});
|
|
530
548
|
transformedPath = rebuildFullPath(node.value, node.key, (path) =>
|
|
531
|
-
path
|
|
549
|
+
path
|
|
550
|
+
.replace(/create\./, `create[${index}].`)
|
|
551
|
+
.replace(/\[0\]\./, `[${lang}].`)
|
|
532
552
|
);
|
|
533
553
|
}
|
|
534
554
|
|
|
535
|
-
if (!isAdded)
|
|
555
|
+
if (!isAdded) {
|
|
556
|
+
buildError(langPath, transformedPath);
|
|
557
|
+
}
|
|
536
558
|
});
|
|
537
559
|
} else {
|
|
538
560
|
const singlePath = fPath.replace(
|
|
@@ -1083,7 +1105,8 @@ const validateField = (
|
|
|
1083
1105
|
language_codes,
|
|
1084
1106
|
existingForm,
|
|
1085
1107
|
getNodes = true,
|
|
1086
|
-
timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
1108
|
+
timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
1109
|
+
translatedPath = null
|
|
1087
1110
|
) => {
|
|
1088
1111
|
if (onlyFormFields == true && value === undefined) return;
|
|
1089
1112
|
|
|
@@ -1092,6 +1115,11 @@ const validateField = (
|
|
|
1092
1115
|
? `${fieldPath}.${field.key.split(".").pop()}`
|
|
1093
1116
|
: field.key;
|
|
1094
1117
|
|
|
1118
|
+
if (translatedPath) {
|
|
1119
|
+
translatedPath = translatedPath
|
|
1120
|
+
? `${translatedPath}.${field.key.split(".").pop()}`
|
|
1121
|
+
: field.key;
|
|
1122
|
+
}
|
|
1095
1123
|
const fieldLabel = formatLabel(field.display_label);
|
|
1096
1124
|
|
|
1097
1125
|
validateMetaRules(
|
|
@@ -1107,7 +1135,8 @@ const validateField = (
|
|
|
1107
1135
|
formData,
|
|
1108
1136
|
language_codes,
|
|
1109
1137
|
existingForm,
|
|
1110
|
-
getNodes
|
|
1138
|
+
getNodes,
|
|
1139
|
+
translatedPath
|
|
1111
1140
|
);
|
|
1112
1141
|
|
|
1113
1142
|
if (
|
|
@@ -1146,7 +1175,8 @@ const validateField = (
|
|
|
1146
1175
|
language_codes,
|
|
1147
1176
|
existingForm,
|
|
1148
1177
|
false,
|
|
1149
|
-
timeZone
|
|
1178
|
+
timeZone,
|
|
1179
|
+
null
|
|
1150
1180
|
)
|
|
1151
1181
|
);
|
|
1152
1182
|
} else if (field.type === constants.types.ARRAY && Array.isArray(value)) {
|
|
@@ -1205,7 +1235,11 @@ const validateField = (
|
|
|
1205
1235
|
language_codes,
|
|
1206
1236
|
existingForm,
|
|
1207
1237
|
false,
|
|
1208
|
-
timeZone
|
|
1238
|
+
timeZone,
|
|
1239
|
+
field?.meta?.parentInterface ===
|
|
1240
|
+
constants.interfaces.TRANSLATIONS && item["languages_code"]
|
|
1241
|
+
? `${currentPath}.${item["languages_code"]}`
|
|
1242
|
+
: null
|
|
1209
1243
|
)
|
|
1210
1244
|
);
|
|
1211
1245
|
});
|
|
@@ -1581,7 +1615,8 @@ const validate = (data) => {
|
|
|
1581
1615
|
data.language_codes,
|
|
1582
1616
|
existingForm,
|
|
1583
1617
|
true,
|
|
1584
|
-
timeZone
|
|
1618
|
+
timeZone,
|
|
1619
|
+
null
|
|
1585
1620
|
);
|
|
1586
1621
|
});
|
|
1587
1622
|
return result;
|