nox-validation 1.7.2 → 1.7.3

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.
Files changed (2) hide show
  1. package/lib/validate.js +56 -46
  2. package/package.json +1 -1
package/lib/validate.js CHANGED
@@ -228,13 +228,13 @@ const isEmptyRelational = ({
228
228
  ? existingValue.length === 0
229
229
  ? []
230
230
  : typeof existingValue[0] === "string"
231
- ? existingValue
232
- : existingValue.map((item) => item._id)
231
+ ? existingValue
232
+ : existingValue.map((item) => item._id)
233
233
  : typeof existingValue === "string"
234
- ? [existingValue]
235
- : existingValue && typeof existingValue === "object"
236
- ? [existingValue._id]
237
- : [];
234
+ ? [existingValue]
235
+ : existingValue && typeof existingValue === "object"
236
+ ? [existingValue._id]
237
+ : [];
238
238
  all = Array.isArray(all) ? all?.filter(Boolean) : all;
239
239
  switch (interface) {
240
240
  case constants.interfaces.FILE:
@@ -359,21 +359,21 @@ const validateMetaRules = (
359
359
  const isValidRelational =
360
360
  required && isRelational
361
361
  ? isEmptyRelational({
362
- api_version: apiVersion,
363
- value: fieldValue,
364
- interface: field?.meta?.interface,
365
- onlyFormFields,
366
- existingValue:
367
- getValue(existingForm, currentPath) ||
368
- getValue(
369
- existingForm,
370
- currentPath
371
- ?.replace(".create", "")
372
- ?.replace(".update", "")
373
- ?.replace(".existing", "")
374
- ?.replace(".delete", "")
375
- ), // TODO: Need to Generate Form Path Without create, update, existing, delete
376
- })
362
+ api_version: apiVersion,
363
+ value: fieldValue,
364
+ interface: field?.meta?.interface,
365
+ onlyFormFields,
366
+ existingValue:
367
+ getValue(existingForm, currentPath) ||
368
+ getValue(
369
+ existingForm,
370
+ currentPath
371
+ ?.replace(".create", "")
372
+ ?.replace(".update", "")
373
+ ?.replace(".existing", "")
374
+ ?.replace(".delete", "")
375
+ ), // TODO: Need to Generate Form Path Without create, update, existing, delete
376
+ })
377
377
  : true;
378
378
 
379
379
  const isEmptyVal = is_m2a_item ? !fieldValue : isEmpty(fieldValue);
@@ -392,29 +392,29 @@ const validateMetaRules = (
392
392
  if (invalidRequire || !isValidRelational) {
393
393
  const message = field?.meta?.required
394
394
  ? error_messages.REQUIRED.replace(
395
- `{field}`,
396
- formatLabel(field.display_label)
397
- )
395
+ `{field}`,
396
+ formatLabel(field.display_label)
397
+ )
398
398
  : error_messages.NOT_EMPTY.replace(
399
- `{field}`,
400
- formatLabel(field.display_label)
401
- );
399
+ `{field}`,
400
+ formatLabel(field.display_label)
401
+ );
402
402
  addError(
403
403
  currentPath,
404
404
  translatedPath
405
405
  ? {
406
- label: formatLabel(field.display_label),
407
- fieldPath: currentPath,
408
- description: "",
409
- translation_path: translatedPath,
410
- message,
411
- }
406
+ label: formatLabel(field.display_label),
407
+ fieldPath: currentPath,
408
+ description: "",
409
+ translation_path: translatedPath,
410
+ message,
411
+ }
412
412
  : {
413
- label: formatLabel(field.display_label),
414
- fieldPath: currentPath,
415
- description: "",
416
- message,
417
- },
413
+ label: formatLabel(field.display_label),
414
+ fieldPath: currentPath,
415
+ description: "",
416
+ message,
417
+ },
418
418
  field
419
419
  );
420
420
  }
@@ -470,8 +470,19 @@ const validateMetaRules = (
470
470
  ) {
471
471
  getSelectedNodes({
472
472
  node: field,
473
- skipFn: (node) =>
474
- node.meta?.interface === constants.interfaces.MANY_TO_ANY,
473
+ skipFn: (node) => {
474
+ let status = false;
475
+ if (
476
+ node.meta?.interface === constants.interfaces.MANY_TO_ANY
477
+ ) status = true
478
+
479
+ if ([constants.interfaces.MANY_TO_MANY,
480
+ constants.interfaces.ONE_TO_MANY,
481
+ constants.interfaces.MANY_TO_ONE,
482
+ constants.interfaces.SEO,
483
+ ].includes(node.meta?.interface) && (!node.meta?.required || !node.meta?.hidden)) status = true
484
+ return status
485
+ },
475
486
  conditionFn: (node) =>
476
487
  node.meta?.required === true && !node.isRelationalUpdate,
477
488
  mapFn: (node) => ({
@@ -595,8 +606,8 @@ const validateMetaRules = (
595
606
  const validType =
596
607
  field?.alternateType?.length > 0
597
608
  ? [field.type, ...field?.alternateType].some((type) =>
598
- typeChecks[type](fieldValue)
599
- )
609
+ typeChecks[type](fieldValue)
610
+ )
600
611
  : typeChecks[field.type](fieldValue, { key: currentPath, updateValue });
601
612
 
602
613
  if (!isEmpty(fieldValue) && !validType) {
@@ -634,9 +645,8 @@ const handleRegexValidation = (
634
645
  const fieldLabel = formatLabel(field.display_label);
635
646
 
636
647
  // Determine regex flags
637
- const flags = `${rule.options?.case_sensitive ? "" : "i"}${
638
- rule.options?.multiline ? "m" : ""
639
- }${rule.options?.global ? "g" : ""}`;
648
+ const flags = `${rule.options?.case_sensitive ? "" : "i"}${rule.options?.multiline ? "m" : ""
649
+ }${rule.options?.global ? "g" : ""}`;
640
650
 
641
651
  // Build regex for MATCH/CONTAINS/NOT_CONTAINS
642
652
  let regex;
@@ -1435,7 +1445,7 @@ const validate = (data) => {
1435
1445
  if (
1436
1446
  secondParentField &&
1437
1447
  secondParentField?.meta?.interface ===
1438
- constants.interfaces.TRANSLATIONS
1448
+ constants.interfaces.TRANSLATIONS
1439
1449
  ) {
1440
1450
  const languageKey = secondParentField?.meta?.options?.language_field;
1441
1451
  const firstParentValue = getValue(formData, firstParent);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nox-validation",
3
- "version": "1.7.2",
3
+ "version": "1.7.3",
4
4
  "description": "validate dynamic schema",
5
5
  "main": "index.js",
6
6
  "scripts": {