nox-validation 1.7.8 → 1.8.0
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 +57 -57
- package/lib/validate.js +94 -88
- package/package.json +1 -1
- package/lib/helpers.optimized.js +0 -1975
- package/lib/validate.optimized.js +0 -1855
package/lib/helpers.js
CHANGED
|
@@ -7,7 +7,7 @@ const getAllFields = (obj, parentPath = "") => {
|
|
|
7
7
|
return obj[key].flatMap((item, index) =>
|
|
8
8
|
typeof item === "object" && item !== null
|
|
9
9
|
? getAllFields(item, `${path}[${index}]`)
|
|
10
|
-
: `${path}[${index}]
|
|
10
|
+
: `${path}[${index}]`,
|
|
11
11
|
);
|
|
12
12
|
}
|
|
13
13
|
return typeof obj[key] === "object" &&
|
|
@@ -315,9 +315,9 @@ const generateField = (
|
|
|
315
315
|
alternateType = [],
|
|
316
316
|
meta = {
|
|
317
317
|
required: false,
|
|
318
|
-
nullable:
|
|
318
|
+
nullable: true,
|
|
319
319
|
hidden: false,
|
|
320
|
-
}
|
|
320
|
+
},
|
|
321
321
|
) => {
|
|
322
322
|
const { staticType = null, parentInterface = null } = meta;
|
|
323
323
|
childrenFields = childrenFields?.map((child) => {
|
|
@@ -355,18 +355,18 @@ const generateField = (
|
|
|
355
355
|
};
|
|
356
356
|
};
|
|
357
357
|
|
|
358
|
-
const createChildrenFieldsFiles = (key) => {
|
|
358
|
+
const createChildrenFieldsFiles = (key, item) => {
|
|
359
359
|
const existingField = generateField(
|
|
360
360
|
"existing",
|
|
361
361
|
`${key}.existing`,
|
|
362
362
|
constants.types.OBJECT_ID,
|
|
363
|
-
constants.types.ARRAY
|
|
363
|
+
constants.types.ARRAY,
|
|
364
364
|
);
|
|
365
365
|
const deleteField = generateField(
|
|
366
366
|
"delete",
|
|
367
367
|
`${key}.delete`,
|
|
368
368
|
constants.types.OBJECT_ID,
|
|
369
|
-
constants.types.ARRAY
|
|
369
|
+
constants.types.ARRAY,
|
|
370
370
|
);
|
|
371
371
|
return [existingField, deleteField];
|
|
372
372
|
};
|
|
@@ -374,7 +374,7 @@ const createChildrenFieldsFiles = (key) => {
|
|
|
374
374
|
const generateRelationalFieldV1 = (
|
|
375
375
|
key = "",
|
|
376
376
|
collectionFields = [],
|
|
377
|
-
relationType
|
|
377
|
+
relationType,
|
|
378
378
|
) => {
|
|
379
379
|
if (relationType === constants.interfaces.MANY_TO_ANY) {
|
|
380
380
|
return [
|
|
@@ -382,19 +382,19 @@ const generateRelationalFieldV1 = (
|
|
|
382
382
|
"collection",
|
|
383
383
|
`${key}.collection`,
|
|
384
384
|
constants.types.STRING,
|
|
385
|
-
constants.types.STRING
|
|
385
|
+
constants.types.STRING,
|
|
386
386
|
),
|
|
387
387
|
generateField(
|
|
388
388
|
"sort",
|
|
389
389
|
`${key}.sort`,
|
|
390
390
|
constants.types.NUMBER,
|
|
391
|
-
constants.types.NUMBER
|
|
391
|
+
constants.types.NUMBER,
|
|
392
392
|
),
|
|
393
393
|
generateField(
|
|
394
394
|
"item",
|
|
395
395
|
`${key}.item`,
|
|
396
396
|
constants.types.OBJECT_ID,
|
|
397
|
-
constants.types.OBJECT_ID
|
|
397
|
+
constants.types.OBJECT_ID,
|
|
398
398
|
),
|
|
399
399
|
];
|
|
400
400
|
} else {
|
|
@@ -405,7 +405,7 @@ const generateRelationalFieldV1 = (
|
|
|
405
405
|
const generateRelationalField = (
|
|
406
406
|
key = "",
|
|
407
407
|
collectionFields = [],
|
|
408
|
-
relationType
|
|
408
|
+
relationType,
|
|
409
409
|
) => {
|
|
410
410
|
if (relationType === constants.interfaces.MANY_TO_ANY) {
|
|
411
411
|
const collection_id_meta = {
|
|
@@ -421,20 +421,20 @@ const generateRelationalField = (
|
|
|
421
421
|
[],
|
|
422
422
|
"none",
|
|
423
423
|
[],
|
|
424
|
-
{ staticType: "existing", parentInterface: relationType }
|
|
424
|
+
{ staticType: "existing", parentInterface: relationType },
|
|
425
425
|
);
|
|
426
426
|
existingField.children = [
|
|
427
427
|
generateField(
|
|
428
428
|
"collection",
|
|
429
429
|
`${key}.existing.collection`,
|
|
430
430
|
constants.types.STRING,
|
|
431
|
-
constants.types.STRING
|
|
431
|
+
constants.types.STRING,
|
|
432
432
|
),
|
|
433
433
|
generateField(
|
|
434
434
|
"sort",
|
|
435
435
|
`${key}.existing.sort`,
|
|
436
436
|
constants.types.NUMBER,
|
|
437
|
-
constants.types.NUMBER
|
|
437
|
+
constants.types.NUMBER,
|
|
438
438
|
),
|
|
439
439
|
generateField(
|
|
440
440
|
"collection_id",
|
|
@@ -444,13 +444,13 @@ const generateRelationalField = (
|
|
|
444
444
|
[],
|
|
445
445
|
"none",
|
|
446
446
|
[],
|
|
447
|
-
collection_id_meta
|
|
447
|
+
collection_id_meta,
|
|
448
448
|
),
|
|
449
449
|
generateField(
|
|
450
450
|
"item",
|
|
451
451
|
`${key}.existing.item`,
|
|
452
452
|
constants.types.OBJECT_ID,
|
|
453
|
-
constants.types.OBJECT_ID
|
|
453
|
+
constants.types.OBJECT_ID,
|
|
454
454
|
),
|
|
455
455
|
];
|
|
456
456
|
const deleteField = generateField(
|
|
@@ -461,20 +461,20 @@ const generateRelationalField = (
|
|
|
461
461
|
[],
|
|
462
462
|
"none",
|
|
463
463
|
[],
|
|
464
|
-
{ staticType: "delete", parentInterface: relationType }
|
|
464
|
+
{ staticType: "delete", parentInterface: relationType },
|
|
465
465
|
);
|
|
466
466
|
deleteField.children = [
|
|
467
467
|
generateField(
|
|
468
468
|
"collection",
|
|
469
469
|
`${key}.delete.collection`,
|
|
470
470
|
constants.types.STRING,
|
|
471
|
-
constants.types.STRING
|
|
471
|
+
constants.types.STRING,
|
|
472
472
|
),
|
|
473
473
|
generateField(
|
|
474
474
|
"sort",
|
|
475
475
|
`${key}.delete.sort`,
|
|
476
476
|
constants.types.NUMBER,
|
|
477
|
-
constants.types.NUMBER
|
|
477
|
+
constants.types.NUMBER,
|
|
478
478
|
),
|
|
479
479
|
generateField(
|
|
480
480
|
"collection_id",
|
|
@@ -484,13 +484,13 @@ const generateRelationalField = (
|
|
|
484
484
|
[],
|
|
485
485
|
"none",
|
|
486
486
|
[],
|
|
487
|
-
collection_id_meta
|
|
487
|
+
collection_id_meta,
|
|
488
488
|
),
|
|
489
489
|
generateField(
|
|
490
490
|
"item",
|
|
491
491
|
`${key}.delete.item`,
|
|
492
492
|
constants.types.OBJECT_ID,
|
|
493
|
-
constants.types.OBJECT_ID
|
|
493
|
+
constants.types.OBJECT_ID,
|
|
494
494
|
),
|
|
495
495
|
];
|
|
496
496
|
const createField = generateField(
|
|
@@ -502,14 +502,14 @@ const generateRelationalField = (
|
|
|
502
502
|
[],
|
|
503
503
|
"none",
|
|
504
504
|
[],
|
|
505
|
-
{ staticType: "create", parentInterface: relationType }
|
|
505
|
+
{ staticType: "create", parentInterface: relationType },
|
|
506
506
|
);
|
|
507
507
|
createField.children = [
|
|
508
508
|
generateField(
|
|
509
509
|
"collection",
|
|
510
510
|
`${key}.create.collection`,
|
|
511
511
|
constants.types.STRING,
|
|
512
|
-
constants.types.STRING
|
|
512
|
+
constants.types.STRING,
|
|
513
513
|
),
|
|
514
514
|
generateField(
|
|
515
515
|
"collection_id",
|
|
@@ -519,13 +519,13 @@ const generateRelationalField = (
|
|
|
519
519
|
[],
|
|
520
520
|
"none",
|
|
521
521
|
[],
|
|
522
|
-
collection_id_meta
|
|
522
|
+
collection_id_meta,
|
|
523
523
|
),
|
|
524
524
|
generateField(
|
|
525
525
|
"sort",
|
|
526
526
|
`${key}.create.sort`,
|
|
527
527
|
constants.types.NUMBER,
|
|
528
|
-
constants.types.NUMBER
|
|
528
|
+
constants.types.NUMBER,
|
|
529
529
|
),
|
|
530
530
|
generateField(
|
|
531
531
|
"item",
|
|
@@ -535,7 +535,7 @@ const generateRelationalField = (
|
|
|
535
535
|
[...collectionFields],
|
|
536
536
|
"none",
|
|
537
537
|
[constants.types.OBJECT_ID],
|
|
538
|
-
{ ...collection_id_meta, is_m2a_item: true }
|
|
538
|
+
{ ...collection_id_meta, is_m2a_item: true },
|
|
539
539
|
),
|
|
540
540
|
];
|
|
541
541
|
const updateField = generateField(
|
|
@@ -547,14 +547,14 @@ const generateRelationalField = (
|
|
|
547
547
|
[],
|
|
548
548
|
"none",
|
|
549
549
|
[],
|
|
550
|
-
{ staticType: "update", parentInterface: relationType }
|
|
550
|
+
{ staticType: "update", parentInterface: relationType },
|
|
551
551
|
);
|
|
552
552
|
updateField.children = [
|
|
553
553
|
generateField(
|
|
554
554
|
"collection",
|
|
555
555
|
`${key}.update.collection`,
|
|
556
556
|
constants.types.STRING,
|
|
557
|
-
constants.types.STRING
|
|
557
|
+
constants.types.STRING,
|
|
558
558
|
),
|
|
559
559
|
generateField(
|
|
560
560
|
"collection_id",
|
|
@@ -564,13 +564,13 @@ const generateRelationalField = (
|
|
|
564
564
|
[],
|
|
565
565
|
"none",
|
|
566
566
|
[],
|
|
567
|
-
collection_id_meta
|
|
567
|
+
collection_id_meta,
|
|
568
568
|
),
|
|
569
569
|
generateField(
|
|
570
570
|
"sort",
|
|
571
571
|
`${key}.update.sort`,
|
|
572
572
|
constants.types.NUMBER,
|
|
573
|
-
constants.types.NUMBER
|
|
573
|
+
constants.types.NUMBER,
|
|
574
574
|
),
|
|
575
575
|
generateField(
|
|
576
576
|
"item",
|
|
@@ -580,7 +580,7 @@ const generateRelationalField = (
|
|
|
580
580
|
[...collectionFields],
|
|
581
581
|
"none",
|
|
582
582
|
[constants.types.OBJECT_ID],
|
|
583
|
-
{ ...collection_id_meta, is_m2a_item: true }
|
|
583
|
+
{ ...collection_id_meta, is_m2a_item: true },
|
|
584
584
|
),
|
|
585
585
|
];
|
|
586
586
|
return [existingField, deleteField, createField, updateField];
|
|
@@ -594,7 +594,7 @@ const generateRelationalField = (
|
|
|
594
594
|
[],
|
|
595
595
|
"none",
|
|
596
596
|
[],
|
|
597
|
-
{ staticType: "existing", parentInterface: relationType }
|
|
597
|
+
{ staticType: "existing", parentInterface: relationType },
|
|
598
598
|
),
|
|
599
599
|
generateField(
|
|
600
600
|
"delete",
|
|
@@ -604,7 +604,7 @@ const generateRelationalField = (
|
|
|
604
604
|
[],
|
|
605
605
|
"none",
|
|
606
606
|
[],
|
|
607
|
-
{ staticType: "delete", parentInterface: relationType }
|
|
607
|
+
{ staticType: "delete", parentInterface: relationType },
|
|
608
608
|
),
|
|
609
609
|
generateField(
|
|
610
610
|
"create",
|
|
@@ -614,7 +614,7 @@ const generateRelationalField = (
|
|
|
614
614
|
collectionFields,
|
|
615
615
|
"none",
|
|
616
616
|
[],
|
|
617
|
-
{ staticType: "create", parentInterface: relationType }
|
|
617
|
+
{ staticType: "create", parentInterface: relationType },
|
|
618
618
|
),
|
|
619
619
|
generateField(
|
|
620
620
|
"update",
|
|
@@ -624,7 +624,7 @@ const generateRelationalField = (
|
|
|
624
624
|
collectionFields,
|
|
625
625
|
"none",
|
|
626
626
|
[],
|
|
627
|
-
{ staticType: "update", parentInterface: relationType }
|
|
627
|
+
{ staticType: "update", parentInterface: relationType },
|
|
628
628
|
),
|
|
629
629
|
];
|
|
630
630
|
}
|
|
@@ -657,7 +657,7 @@ const getForeignCollectionDetails = ({
|
|
|
657
657
|
|
|
658
658
|
if (isListInterface) {
|
|
659
659
|
const mainTable = relations.find(
|
|
660
|
-
(d) => d.one_collection_id === collection && d.one_field_id === field
|
|
660
|
+
(d) => d.one_collection_id === collection && d.one_field_id === field,
|
|
661
661
|
);
|
|
662
662
|
if (!mainTable) return {};
|
|
663
663
|
|
|
@@ -666,7 +666,7 @@ const getForeignCollectionDetails = ({
|
|
|
666
666
|
? relations.find(
|
|
667
667
|
(d) =>
|
|
668
668
|
d.many_collection === mainTable.many_collection &&
|
|
669
|
-
d.junction_field === mainTable.many_field
|
|
669
|
+
d.junction_field === mainTable.many_field,
|
|
670
670
|
)
|
|
671
671
|
: [];
|
|
672
672
|
|
|
@@ -678,15 +678,15 @@ const getForeignCollectionDetails = ({
|
|
|
678
678
|
iFace === constants.interfaces.MANY_TO_MANY
|
|
679
679
|
? relational?.one_collection_id
|
|
680
680
|
: iFace === constants.interfaces.MANY_TO_ANY
|
|
681
|
-
|
|
682
|
-
|
|
681
|
+
? relational?.one_allowed_collections_id
|
|
682
|
+
: mainTable.many_collection_id,
|
|
683
683
|
foreign_field:
|
|
684
684
|
iFace === constants.interfaces.MANY_TO_MANY ||
|
|
685
685
|
iFace === constants.interfaces.TRANSLATIONS
|
|
686
686
|
? "_id"
|
|
687
687
|
: iFace === constants.interfaces.MANY_TO_ANY
|
|
688
|
-
|
|
689
|
-
|
|
688
|
+
? "Primary Key"
|
|
689
|
+
: mainTable.many_field_id,
|
|
690
690
|
...(isJunction && {
|
|
691
691
|
junction_collection: relational?.many_collection_id,
|
|
692
692
|
junction_field_this: relational?.junction_field,
|
|
@@ -719,7 +719,7 @@ const getForeignCollectionDetails = ({
|
|
|
719
719
|
|
|
720
720
|
if (isSingleRelation) {
|
|
721
721
|
const mainTable = relations.find(
|
|
722
|
-
(d) => d.many_collection_id === collection && d.many_field_id === field
|
|
722
|
+
(d) => d.many_collection_id === collection && d.many_field_id === field,
|
|
723
723
|
);
|
|
724
724
|
if (!mainTable) return {};
|
|
725
725
|
|
|
@@ -752,7 +752,7 @@ const getCachedFields = (relationDetail, relational_fields) => {
|
|
|
752
752
|
return getField(relationDetail.foreign_collection);
|
|
753
753
|
} else {
|
|
754
754
|
return relationDetail.foreign_collection.flatMap((schemaId) =>
|
|
755
|
-
getField(schemaId)
|
|
755
|
+
getField(schemaId),
|
|
756
756
|
);
|
|
757
757
|
}
|
|
758
758
|
};
|
|
@@ -773,7 +773,7 @@ const getChildFields = (
|
|
|
773
773
|
allFields,
|
|
774
774
|
relational_fields,
|
|
775
775
|
isTranslation,
|
|
776
|
-
name
|
|
776
|
+
name,
|
|
777
777
|
) => {
|
|
778
778
|
let key = isTranslation
|
|
779
779
|
? [
|
|
@@ -792,7 +792,7 @@ const getChildFields = (
|
|
|
792
792
|
return getCachedOrFetchFields(key, allFields, relational_fields);
|
|
793
793
|
} else {
|
|
794
794
|
return key.flatMap((schemaId) =>
|
|
795
|
-
getCachedOrFetchFields(schemaId, allFields, relational_fields)
|
|
795
|
+
getCachedOrFetchFields(schemaId, allFields, relational_fields),
|
|
796
796
|
);
|
|
797
797
|
}
|
|
798
798
|
};
|
|
@@ -826,7 +826,7 @@ const buildNestedStructure = ({
|
|
|
826
826
|
const nodeMap = new Map();
|
|
827
827
|
|
|
828
828
|
schemaFields.sort(
|
|
829
|
-
(a, b) => a.path.split(".").length - b.path.split(".").length
|
|
829
|
+
(a, b) => a.path.split(".").length - b.path.split(".").length,
|
|
830
830
|
);
|
|
831
831
|
|
|
832
832
|
schemaFields.forEach((item) => {
|
|
@@ -863,7 +863,7 @@ const buildNestedStructure = ({
|
|
|
863
863
|
allFields,
|
|
864
864
|
relational_fields,
|
|
865
865
|
item?.meta?.interface === constants.interfaces.TRANSLATIONS,
|
|
866
|
-
key
|
|
866
|
+
key,
|
|
867
867
|
);
|
|
868
868
|
} else {
|
|
869
869
|
childFields = getCachedFields(relationDetail, relational_fields);
|
|
@@ -998,7 +998,7 @@ const buildNestedStructure = ({
|
|
|
998
998
|
item?.meta,
|
|
999
999
|
item?.meta?.validations?.validation_msg?.trim() === ""
|
|
1000
1000
|
? null
|
|
1001
|
-
: item?.meta?.validations?.validation_msg
|
|
1001
|
+
: item?.meta?.validations?.validation_msg,
|
|
1002
1002
|
),
|
|
1003
1003
|
custom_error_message:
|
|
1004
1004
|
item?.meta?.validations?.validation_msg?.trim() === ""
|
|
@@ -1033,7 +1033,7 @@ const buildNestedStructure = ({
|
|
|
1033
1033
|
return nodes.map(({ children, ...node }) =>
|
|
1034
1034
|
children && children?.length
|
|
1035
1035
|
? { ...node, children: removeEmptyChildren(children) }
|
|
1036
|
-
: node
|
|
1036
|
+
: node,
|
|
1037
1037
|
);
|
|
1038
1038
|
};
|
|
1039
1039
|
|
|
@@ -1066,7 +1066,7 @@ const findDisallowedKeys = (formData, structure, maxLevel) => {
|
|
|
1066
1066
|
const keyLevel = keyParts.length;
|
|
1067
1067
|
const levelParent = keyParts.slice(0, maxLevel - 1).join(".");
|
|
1068
1068
|
return !validKeys.has(
|
|
1069
|
-
normalizeKey(keyLevel > maxLevel ? levelParent : key)
|
|
1069
|
+
normalizeKey(keyLevel > maxLevel ? levelParent : key),
|
|
1070
1070
|
);
|
|
1071
1071
|
});
|
|
1072
1072
|
};
|
|
@@ -1359,7 +1359,7 @@ const getDefaultValues = (tree) => {
|
|
|
1359
1359
|
setValue(
|
|
1360
1360
|
defaultValues,
|
|
1361
1361
|
cleanKey,
|
|
1362
|
-
children?.length ? getDefaultValues(children) : {}
|
|
1362
|
+
children?.length ? getDefaultValues(children) : {},
|
|
1363
1363
|
);
|
|
1364
1364
|
} else if (type === "Array") {
|
|
1365
1365
|
if (array_type === "String" || array_type === "Number") {
|
|
@@ -1369,7 +1369,7 @@ const getDefaultValues = (tree) => {
|
|
|
1369
1369
|
setValue(
|
|
1370
1370
|
defaultValues,
|
|
1371
1371
|
cleanKey,
|
|
1372
|
-
children?.length ? [getDefaultValues(children)] : []
|
|
1372
|
+
children?.length ? [getDefaultValues(children)] : [],
|
|
1373
1373
|
);
|
|
1374
1374
|
}
|
|
1375
1375
|
} else {
|
|
@@ -1382,7 +1382,7 @@ const getDefaultValues = (tree) => {
|
|
|
1382
1382
|
|
|
1383
1383
|
const extractRelationalParents = (path) => {
|
|
1384
1384
|
const match = path?.match(
|
|
1385
|
-
/^([^.\[\]]+)\.(create|update|delete|existing)\[(\d+)\](?:\.(.*))
|
|
1385
|
+
/^([^.\[\]]+)\.(create|update|delete|existing)\[(\d+)\](?:\.(.*))?/,
|
|
1386
1386
|
);
|
|
1387
1387
|
if (match) {
|
|
1388
1388
|
const secondParent = match[1];
|
|
@@ -1438,7 +1438,7 @@ const getSelectedNodes = ({
|
|
|
1438
1438
|
}
|
|
1439
1439
|
if (Array.isArray(node.children) && node.children.length > 0) {
|
|
1440
1440
|
updatedNode.children = node.children.map((c) =>
|
|
1441
|
-
updateChildKeys(c, parentKey, newParentKey)
|
|
1441
|
+
updateChildKeys(c, parentKey, newParentKey),
|
|
1442
1442
|
);
|
|
1443
1443
|
}
|
|
1444
1444
|
return updatedNode;
|
|
@@ -1473,11 +1473,11 @@ const getSelectedNodes = ({
|
|
|
1473
1473
|
if (currentNode?.meta?.staticType) {
|
|
1474
1474
|
currentNode.key = addIndexToStaticType(
|
|
1475
1475
|
currentNode.key,
|
|
1476
|
-
currentNode?.meta?.staticType
|
|
1476
|
+
currentNode?.meta?.staticType,
|
|
1477
1477
|
);
|
|
1478
1478
|
currentNode.value = addIndexToStaticType(
|
|
1479
1479
|
currentNode.value,
|
|
1480
|
-
currentNode?.meta?.staticType
|
|
1480
|
+
currentNode?.meta?.staticType,
|
|
1481
1481
|
);
|
|
1482
1482
|
}
|
|
1483
1483
|
|
|
@@ -1567,7 +1567,7 @@ const formatDate = ({
|
|
|
1567
1567
|
|
|
1568
1568
|
const { year, month, day, hour, minute, second, dayPeriod } = getParts(
|
|
1569
1569
|
date,
|
|
1570
|
-
timeZone
|
|
1570
|
+
timeZone,
|
|
1571
1571
|
);
|
|
1572
1572
|
|
|
1573
1573
|
let hour24 = Number(hour);
|