nox-validation 1.3.0 → 1.3.1
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 +8 -91
- package/lib/validate.js +7 -3
- package/package.json +1 -1
package/lib/helpers.js
CHANGED
|
@@ -267,101 +267,14 @@ const generateType = (field, api) => {
|
|
|
267
267
|
}
|
|
268
268
|
};
|
|
269
269
|
|
|
270
|
-
const convertTypes = (field) => {
|
|
271
|
-
let { type, schema_definition, meta } = field;
|
|
272
|
-
let array_type = schema_definition?.type ?? null;
|
|
273
|
-
let interfaceType = meta?.interface;
|
|
274
|
-
let find_relations = false;
|
|
275
|
-
|
|
276
|
-
if (
|
|
277
|
-
[
|
|
278
|
-
constants.interfaces.ONE_TO_MANY,
|
|
279
|
-
constants.interfaces.MANY_TO_MANY,
|
|
280
|
-
constants.interfaces.MANY_TO_ANY,
|
|
281
|
-
constants.interfaces.MANY_TO_ONE,
|
|
282
|
-
constants.interfaces.TRANSLATIONS,
|
|
283
|
-
].includes(interfaceType)
|
|
284
|
-
) {
|
|
285
|
-
return {
|
|
286
|
-
type: constants.types.OBJECT,
|
|
287
|
-
array_type: null,
|
|
288
|
-
find_relations: true,
|
|
289
|
-
};
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
if (interfaceType === constants.interfaces.FILES) {
|
|
293
|
-
return {
|
|
294
|
-
type: constants.types.ARRAY,
|
|
295
|
-
array_type: constants.types.OBJECT_ID,
|
|
296
|
-
find_relations: false,
|
|
297
|
-
};
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
if (type !== schema_definition?.type && schema_definition?.type !== constants.types.ALIAS) {
|
|
301
|
-
array_type = schema_definition.type;
|
|
302
|
-
}
|
|
303
|
-
return { type, array_type, find_relations };
|
|
304
|
-
};
|
|
305
|
-
|
|
306
|
-
const convertTypesV1 = (field) => {
|
|
307
|
-
let { type, schema_definition, meta } = field;
|
|
308
|
-
let array_type = schema_definition?.type ?? null;
|
|
309
|
-
let interfaceType = meta?.interface;
|
|
310
|
-
let find_relations = false;
|
|
311
|
-
|
|
312
|
-
if ([constants.interfaces.TRANSLATIONS].includes(interfaceType)) {
|
|
313
|
-
return {
|
|
314
|
-
type: constants.types.OBJECT,
|
|
315
|
-
array_type: null,
|
|
316
|
-
find_relations: true,
|
|
317
|
-
};
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
if ([constants.interfaces.MANY_TO_ANY].includes(interfaceType)) {
|
|
321
|
-
return {
|
|
322
|
-
type: constants.types.ARRAY,
|
|
323
|
-
array_type: constants.types.OBJECT,
|
|
324
|
-
find_relations: true,
|
|
325
|
-
};
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
if ([constants.interfaces.MANY_TO_ONE].includes(interfaceType)) {
|
|
329
|
-
return {
|
|
330
|
-
type: constants.types.OBJECT_ID,
|
|
331
|
-
array_type: null,
|
|
332
|
-
find_relations: false,
|
|
333
|
-
};
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
if (
|
|
337
|
-
[
|
|
338
|
-
constants.interfaces.ONE_TO_MANY,
|
|
339
|
-
constants.interfaces.MANY_TO_MANY,
|
|
340
|
-
constants.interfaces.FILES,
|
|
341
|
-
].includes(interfaceType)
|
|
342
|
-
) {
|
|
343
|
-
return {
|
|
344
|
-
type: constants.types.ARRAY,
|
|
345
|
-
array_type: constants.types.OBJECT_ID,
|
|
346
|
-
find_relations: false,
|
|
347
|
-
};
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
if (type !== schema_definition?.type && schema_definition?.type !== constants.types.ALIAS) {
|
|
351
|
-
array_type = schema_definition.type;
|
|
352
|
-
find_relations = false;
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
return { type, array_type, find_relations };
|
|
356
|
-
};
|
|
357
|
-
|
|
358
270
|
const generateField = (
|
|
359
271
|
name,
|
|
360
272
|
path,
|
|
361
273
|
schema_definition_type,
|
|
362
274
|
type,
|
|
363
275
|
childrenFields = [],
|
|
364
|
-
relationType = "none"
|
|
276
|
+
relationType = "none",
|
|
277
|
+
alternateType=[]
|
|
365
278
|
) => {
|
|
366
279
|
childrenFields = childrenFields?.map((child) => {
|
|
367
280
|
return {
|
|
@@ -378,6 +291,7 @@ const generateField = (
|
|
|
378
291
|
value: path,
|
|
379
292
|
children: childrenFields,
|
|
380
293
|
type: type,
|
|
294
|
+
alternateType,
|
|
381
295
|
meta: {
|
|
382
296
|
required: false,
|
|
383
297
|
nullable: false,
|
|
@@ -489,7 +403,8 @@ const generateRelationalField = (key = "", collectionFields = [], relationType)
|
|
|
489
403
|
constants.types.OBJECT,
|
|
490
404
|
constants.types.OBJECT,
|
|
491
405
|
collectionFields,
|
|
492
|
-
|
|
406
|
+
'none',
|
|
407
|
+
[constants.types.OBJECT_ID]
|
|
493
408
|
),
|
|
494
409
|
];
|
|
495
410
|
const updateField = generateField(
|
|
@@ -513,7 +428,8 @@ const generateRelationalField = (key = "", collectionFields = [], relationType)
|
|
|
513
428
|
constants.types.OBJECT,
|
|
514
429
|
constants.types.OBJECT,
|
|
515
430
|
collectionFields,
|
|
516
|
-
|
|
431
|
+
"none",
|
|
432
|
+
[constants.types.OBJECT_ID]
|
|
517
433
|
),
|
|
518
434
|
];
|
|
519
435
|
return [existingField, deleteField, createField, updateField];
|
|
@@ -814,6 +730,7 @@ const buildNestedStructure = ({
|
|
|
814
730
|
display_label: "_id",
|
|
815
731
|
key: `${key}._id`,
|
|
816
732
|
value: `${key}._id`,
|
|
733
|
+
alternateType:[],
|
|
817
734
|
meta: {
|
|
818
735
|
interface: "none",
|
|
819
736
|
required: false,
|
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
|
};
|
|
@@ -244,10 +244,14 @@ const validateMetaRules = (
|
|
|
244
244
|
);
|
|
245
245
|
}
|
|
246
246
|
|
|
247
|
+
const validType =
|
|
248
|
+
field?.alternateType?.length > 0
|
|
249
|
+
? [field.type, ...field?.alternateType].some((type) => typeChecks[type](fieldValue))
|
|
250
|
+
: typeChecks[field.type](fieldValue,{ key: currentPath, updateValue });
|
|
251
|
+
|
|
247
252
|
if (
|
|
248
253
|
!isEmpty(fieldValue) &&
|
|
249
|
-
|
|
250
|
-
!typeChecks[field.type](fieldValue, { key: currentPath, updateValue })
|
|
254
|
+
!validType
|
|
251
255
|
) {
|
|
252
256
|
const message = error_messages.INVALID_TYPE.replace(
|
|
253
257
|
`{field}`,
|