@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, _ctx) {
431
+ validate: function validate(minProperties, data, _schema, ctx) {
432
432
  if (typeof data !== 'object')
433
433
  return true;
434
- return Object.getOwnPropertyNames(data).length >= minProperties;
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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/nodejs-lib",
3
3
  "type": "module",
4
- "version": "15.65.2",
4
+ "version": "15.65.3",
5
5
  "dependencies": {
6
6
  "@naturalcycles/js-lib": "^15",
7
7
  "@types/js-yaml": "^4",
@@ -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, _ctx) {
495
+ validate: function validate(minProperties: number, data: AnyObject, _schema, ctx) {
496
496
  if (typeof data !== 'object') return true
497
- return Object.getOwnPropertyNames(data).length >= minProperties
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