nox-validation 1.2.8 → 1.3.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 +58 -15
- package/lib/validate.js +1 -1
- package/package.json +1 -1
package/lib/helpers.js
CHANGED
|
@@ -789,6 +789,48 @@ const buildNestedStructure = ({
|
|
|
789
789
|
childFields = createChildrenFieldsFiles(key);
|
|
790
790
|
}
|
|
791
791
|
|
|
792
|
+
const isArray =
|
|
793
|
+
item.type === item?.schema_definition.type && item.type === constants.types.ARRAY;
|
|
794
|
+
|
|
795
|
+
let children = [];
|
|
796
|
+
|
|
797
|
+
if (childFields?.length > 0) {
|
|
798
|
+
if (isV2File) {
|
|
799
|
+
children = childFields;
|
|
800
|
+
} else if (
|
|
801
|
+
apiVersion === constants.API_VERSION.V1 &&
|
|
802
|
+
item.meta?.interface !== constants.interfaces.TRANSLATIONS
|
|
803
|
+
) {
|
|
804
|
+
children = generateRelationalFieldV1(key, childFields, item.meta?.interface);
|
|
805
|
+
} else {
|
|
806
|
+
children = generateRelationalField(key, childFields, item.meta?.interface);
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
if (isArray) {
|
|
811
|
+
const idField = {
|
|
812
|
+
field_id: `${key}._id`,
|
|
813
|
+
schema_id: item?.schema_id,
|
|
814
|
+
display_label: "_id",
|
|
815
|
+
key: `${key}._id`,
|
|
816
|
+
value: `${key}._id`,
|
|
817
|
+
meta: {
|
|
818
|
+
interface: "none",
|
|
819
|
+
required: false,
|
|
820
|
+
nullable: false,
|
|
821
|
+
hidden: false,
|
|
822
|
+
options: {},
|
|
823
|
+
},
|
|
824
|
+
validations: [],
|
|
825
|
+
custom_error_message: null,
|
|
826
|
+
children: [],
|
|
827
|
+
type: constants.types.OBJECT_ID,
|
|
828
|
+
array_type: definedType.array_type,
|
|
829
|
+
default_value: null,
|
|
830
|
+
};
|
|
831
|
+
children.push(idField);
|
|
832
|
+
}
|
|
833
|
+
|
|
792
834
|
const node = {
|
|
793
835
|
field_id: item?._id,
|
|
794
836
|
schema_id: item?.schema_id,
|
|
@@ -804,15 +846,15 @@ const buildNestedStructure = ({
|
|
|
804
846
|
},
|
|
805
847
|
validations: generateModifiedRules(item?.meta, item?.meta?.validations?.validation_msg),
|
|
806
848
|
custom_error_message: item?.meta?.validations?.validation_msg,
|
|
807
|
-
children
|
|
808
|
-
childFields?.length > 0
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
849
|
+
children,
|
|
850
|
+
// childFields?.length > 0
|
|
851
|
+
// ? isV2File
|
|
852
|
+
// ? childFields
|
|
853
|
+
// : apiVersion === constants.API_VERSION.V1 &&
|
|
854
|
+
// item.meta?.interface !== constants.interfaces.TRANSLATIONS
|
|
855
|
+
// ? generateRelationalFieldV1(key, childFields, item.meta?.interface)
|
|
856
|
+
// : generateRelationalField(key, childFields, item.meta?.interface)
|
|
857
|
+
// : [],
|
|
816
858
|
type: definedType.type,
|
|
817
859
|
array_type: definedType.array_type,
|
|
818
860
|
default_value: item?.schema_definition?.default,
|
|
@@ -1168,16 +1210,17 @@ const getDefaultValues = (tree) => {
|
|
|
1168
1210
|
return defaultValues;
|
|
1169
1211
|
};
|
|
1170
1212
|
|
|
1171
|
-
const extractRelationalParents=(path)=> {
|
|
1213
|
+
const extractRelationalParents = (path) => {
|
|
1172
1214
|
const match = path?.match(/^([^.\[\]]+)\.(create|update|delete|existing)\[(\d+)\](?:\.(.*))?/);
|
|
1173
1215
|
if (match) {
|
|
1174
|
-
const secondParent = match[1];
|
|
1175
|
-
const firstParent =
|
|
1176
|
-
|
|
1216
|
+
const secondParent = match[1];
|
|
1217
|
+
const firstParent =
|
|
1218
|
+
match[0].split(".")[0] + "." + match[2] + "[" + path.match(/\[(\d+)\]/)[1] + "]"; //
|
|
1219
|
+
const afterKey = match[3] || "";
|
|
1177
1220
|
return { firstParent, secondParent, afterKey };
|
|
1178
1221
|
}
|
|
1179
1222
|
return null;
|
|
1180
|
-
}
|
|
1223
|
+
};
|
|
1181
1224
|
|
|
1182
1225
|
module.exports = {
|
|
1183
1226
|
generateModifiedRules,
|
|
@@ -1197,5 +1240,5 @@ module.exports = {
|
|
|
1197
1240
|
getAllFields,
|
|
1198
1241
|
getForeignCollectionDetails,
|
|
1199
1242
|
getDefaultValues,
|
|
1200
|
-
extractRelationalParents
|
|
1243
|
+
extractRelationalParents,
|
|
1201
1244
|
};
|
package/lib/validate.js
CHANGED
|
@@ -157,7 +157,7 @@ const isEmptyRelational = ({ api_version, value, interface }) => {
|
|
|
157
157
|
return value?.length > 0;
|
|
158
158
|
}
|
|
159
159
|
} else {
|
|
160
|
-
return value?.create?.length > 0 || value?.existing?.length > 0;
|
|
160
|
+
return value?.create?.length > 0 || value?.existing?.length > 0 || value?.update?.length > 0;
|
|
161
161
|
}
|
|
162
162
|
return false;
|
|
163
163
|
};
|