@based/schema 5.1.0 → 5.1.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/dist/def/validation.js +56 -7
- package/package.json +1 -1
package/dist/def/validation.js
CHANGED
|
@@ -381,13 +381,62 @@ const validateObj = (value, props, errors, path, required) => {
|
|
|
381
381
|
}
|
|
382
382
|
else if (val !== undefined) {
|
|
383
383
|
const test = getValidator(prop);
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
384
|
+
if ('items' in prop) {
|
|
385
|
+
if (typeof val !== 'object' || val === null) {
|
|
386
|
+
errors.push({
|
|
387
|
+
path: [...path, key],
|
|
388
|
+
value: val,
|
|
389
|
+
error: 'Invalid value',
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
let arr = val;
|
|
393
|
+
if (!Array.isArray(val)) {
|
|
394
|
+
arr = [];
|
|
395
|
+
for (const i in val) {
|
|
396
|
+
if (i === 'add') {
|
|
397
|
+
arr.push(...val.add);
|
|
398
|
+
}
|
|
399
|
+
else if (i === 'update') {
|
|
400
|
+
arr.push(...val.update);
|
|
401
|
+
}
|
|
402
|
+
else if (i === 'delete') {
|
|
403
|
+
arr.push(...val.delete);
|
|
404
|
+
}
|
|
405
|
+
else {
|
|
406
|
+
arr = [];
|
|
407
|
+
break;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
if (!arr.length) {
|
|
411
|
+
errors.push({
|
|
412
|
+
path: [...path, key],
|
|
413
|
+
value: arr,
|
|
414
|
+
error: 'Invalid value',
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
for (const val of arr) {
|
|
419
|
+
const msg = typeof val === 'object' ? test(val?.id, prop) : test(val, prop);
|
|
420
|
+
if (msg !== true) {
|
|
421
|
+
errors.push({
|
|
422
|
+
path: [...path, key],
|
|
423
|
+
value: val,
|
|
424
|
+
error: typeof msg === 'string' ? msg : 'Invalid value',
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
else {
|
|
430
|
+
const msg = getPropType(prop) === 'reference' && typeof val === 'object'
|
|
431
|
+
? test(val?.id, prop)
|
|
432
|
+
: test(val, prop);
|
|
433
|
+
if (msg !== true) {
|
|
434
|
+
errors.push({
|
|
435
|
+
path: [...path, key],
|
|
436
|
+
value: val,
|
|
437
|
+
error: typeof msg === 'string' ? msg : 'Invalid value',
|
|
438
|
+
});
|
|
439
|
+
}
|
|
391
440
|
}
|
|
392
441
|
}
|
|
393
442
|
}
|