@naturalcycles/nodejs-lib 15.65.2 → 15.65.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.
|
@@ -428,10 +428,21 @@ export function createAjv(opt) {
|
|
|
428
428
|
modifying: false,
|
|
429
429
|
errors: true,
|
|
430
430
|
schemaType: 'number',
|
|
431
|
-
validate: function validate(minProperties, data, _schema,
|
|
431
|
+
validate: function validate(minProperties, data, _schema, ctx) {
|
|
432
432
|
if (typeof data !== 'object')
|
|
433
433
|
return true;
|
|
434
|
-
|
|
434
|
+
const numberOfProperties = Object.getOwnPropertyNames(data).length;
|
|
435
|
+
const isValid = numberOfProperties >= minProperties;
|
|
436
|
+
if (!isValid) {
|
|
437
|
+
;
|
|
438
|
+
validate.errors = [
|
|
439
|
+
{
|
|
440
|
+
instancePath: ctx?.instancePath ?? '',
|
|
441
|
+
message: `must NOT have fewer than ${minProperties} properties`,
|
|
442
|
+
},
|
|
443
|
+
];
|
|
444
|
+
}
|
|
445
|
+
return isValid;
|
|
435
446
|
},
|
|
436
447
|
});
|
|
437
448
|
return ajv;
|
package/package.json
CHANGED
|
@@ -492,9 +492,21 @@ export function createAjv(opt?: Options): Ajv2020 {
|
|
|
492
492
|
modifying: false,
|
|
493
493
|
errors: true,
|
|
494
494
|
schemaType: 'number',
|
|
495
|
-
validate: function validate(minProperties: number, data: AnyObject, _schema,
|
|
495
|
+
validate: function validate(minProperties: number, data: AnyObject, _schema, ctx) {
|
|
496
496
|
if (typeof data !== 'object') return true
|
|
497
|
-
|
|
497
|
+
|
|
498
|
+
const numberOfProperties = Object.getOwnPropertyNames(data).length
|
|
499
|
+
const isValid = numberOfProperties >= minProperties
|
|
500
|
+
if (!isValid) {
|
|
501
|
+
;(validate as any).errors = [
|
|
502
|
+
{
|
|
503
|
+
instancePath: ctx?.instancePath ?? '',
|
|
504
|
+
message: `must NOT have fewer than ${minProperties} properties`,
|
|
505
|
+
},
|
|
506
|
+
]
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
return isValid
|
|
498
510
|
},
|
|
499
511
|
})
|
|
500
512
|
|