nox-validation 1.6.3 → 1.6.5

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 CHANGED
@@ -1475,6 +1475,10 @@ const getSelectedNodes = ({
1475
1475
  currentNode.key,
1476
1476
  currentNode?.meta?.staticType
1477
1477
  );
1478
+ currentNode.value = addIndexToStaticType(
1479
+ currentNode.value,
1480
+ currentNode?.meta?.staticType
1481
+ );
1478
1482
  }
1479
1483
 
1480
1484
  if (parentKey)
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
- label: formatLabel(field.display_label),
398
- fieldPath: currentPath,
399
- description: "",
400
- message,
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,50 @@ 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
- transformedPath,
513
- isAdded = false;
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 (node?.value?.includes("create[0].")) {
516
- const exist = fieldValue?.create?.find(
517
- (item) => item.languages_code === lang
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("create[0].", `create[${index}].`)
537
+ path.replace(/create\[0\]\./, `create[${index}].`)
522
538
  );
523
- transformedPath = rebuildFullPath(node.value, node.key, (path) =>
524
- path.replace("create[0].", `${lang}.`)
539
+ transformedPath = rebuildFullPath(
540
+ node.value,
541
+ node.key,
542
+ (path) => {
543
+ const newPath = path.replace(/\[0\]\./, `${lang}.`);
544
+ return newPath;
545
+ }
525
546
  );
526
547
  } else {
527
- langPath = rebuildFullPath(node.value, node.key, (path) =>
528
- path.replace("create.", `create[${index}].`)
529
- );
548
+ langPath = rebuildFullPath(node.value, node.key, (path) => {
549
+ return path.replace(/create\./, `create[${index}].`);
550
+ });
551
+
530
552
  transformedPath = rebuildFullPath(node.value, node.key, (path) =>
531
- path.replace("create.", `${lang}.`)
553
+ path.replace(/\[0\]\./, `${lang}.`)
532
554
  );
533
555
  }
534
556
 
535
- if (!isAdded) buildError(langPath, transformedPath);
557
+ if (!isAdded) {
558
+ buildError(langPath, transformedPath);
559
+ }
536
560
  });
537
561
  } else {
538
562
  const singlePath = fPath.replace(
@@ -1083,7 +1107,8 @@ const validateField = (
1083
1107
  language_codes,
1084
1108
  existingForm,
1085
1109
  getNodes = true,
1086
- timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone
1110
+ timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone,
1111
+ translatedPath = null
1087
1112
  ) => {
1088
1113
  if (onlyFormFields == true && value === undefined) return;
1089
1114
 
@@ -1092,6 +1117,11 @@ const validateField = (
1092
1117
  ? `${fieldPath}.${field.key.split(".").pop()}`
1093
1118
  : field.key;
1094
1119
 
1120
+ if (translatedPath) {
1121
+ translatedPath = translatedPath
1122
+ ? `${translatedPath}.${field.key.split(".").pop()}`
1123
+ : field.key;
1124
+ }
1095
1125
  const fieldLabel = formatLabel(field.display_label);
1096
1126
 
1097
1127
  validateMetaRules(
@@ -1107,7 +1137,8 @@ const validateField = (
1107
1137
  formData,
1108
1138
  language_codes,
1109
1139
  existingForm,
1110
- getNodes
1140
+ getNodes,
1141
+ translatedPath
1111
1142
  );
1112
1143
 
1113
1144
  if (
@@ -1146,7 +1177,8 @@ const validateField = (
1146
1177
  language_codes,
1147
1178
  existingForm,
1148
1179
  false,
1149
- timeZone
1180
+ timeZone,
1181
+ null
1150
1182
  )
1151
1183
  );
1152
1184
  } else if (field.type === constants.types.ARRAY && Array.isArray(value)) {
@@ -1205,7 +1237,11 @@ const validateField = (
1205
1237
  language_codes,
1206
1238
  existingForm,
1207
1239
  false,
1208
- timeZone
1240
+ timeZone,
1241
+ field?.meta?.parentInterface ===
1242
+ constants.interfaces.TRANSLATIONS && item["languages_code"]
1243
+ ? `${currentPath}.${item["languages_code"]}`
1244
+ : null
1209
1245
  )
1210
1246
  );
1211
1247
  });
@@ -1581,7 +1617,8 @@ const validate = (data) => {
1581
1617
  data.language_codes,
1582
1618
  existingForm,
1583
1619
  true,
1584
- timeZone
1620
+ timeZone,
1621
+ null
1585
1622
  );
1586
1623
  });
1587
1624
  return result;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nox-validation",
3
- "version": "1.6.3",
3
+ "version": "1.6.5",
4
4
  "description": "validate dynamic schema",
5
5
  "main": "index.js",
6
6
  "scripts": {