@naturalcycles/nodejs-lib 15.80.0 → 15.80.2

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.
@@ -481,7 +481,7 @@ export function createAjv(opt) {
481
481
  keyword: 'anyOfBy',
482
482
  type: 'object',
483
483
  modifying: true,
484
- errors: false,
484
+ errors: true,
485
485
  schemaType: 'object',
486
486
  compile(config, _parentSchema, _it) {
487
487
  const { propertyName, schemaDictionary } = config;
@@ -503,7 +503,12 @@ export function createAjv(opt) {
503
503
  ];
504
504
  return false;
505
505
  }
506
- return isValidFn(data);
506
+ const result = isValidFn(data);
507
+ if (!result) {
508
+ ;
509
+ validate.errors = isValidFn.errors;
510
+ }
511
+ return result;
507
512
  }
508
513
  return validate;
509
514
  },
@@ -126,7 +126,7 @@ export const j = {
126
126
  */
127
127
  oneOf(items) {
128
128
  const schemas = items.map(b => b.build());
129
- _assert(schemas.every(hasOnlySchemasForPrimitives), 'Do not use `oneOf` validation with non-primitive types!');
129
+ _assert(schemas.every(hasNoObjectSchemas), 'Do not use `oneOf` validation with non-primitive types!');
130
130
  return new JsonSchemaAnyBuilder({
131
131
  oneOf: schemas,
132
132
  });
@@ -144,7 +144,7 @@ export const j = {
144
144
  */
145
145
  anyOf(items) {
146
146
  const schemas = items.map(b => b.build());
147
- _assert(schemas.every(hasOnlySchemasForPrimitives), 'Do not use `anyOf` validation with non-primitive types!');
147
+ _assert(schemas.every(hasNoObjectSchemas), 'Do not use `anyOf` validation with non-primitive types!');
148
148
  return new JsonSchemaAnyBuilder({
149
149
  anyOf: schemas,
150
150
  });
@@ -899,15 +899,21 @@ function withEnumKeys(keys, schema) {
899
899
  const props = Object.fromEntries(typedValues.map(key => [key, schema]));
900
900
  return new JsonSchemaObjectBuilder(props, { hasIsOfTypeCheck: false });
901
901
  }
902
- function hasOnlySchemasForPrimitives(schema) {
902
+ function hasNoObjectSchemas(schema) {
903
903
  if (Array.isArray(schema.type)) {
904
904
  schema.type.every(type => ['string', 'number', 'integer', 'boolean', 'null'].includes(type));
905
905
  }
906
906
  else if (schema.anyOf) {
907
- return schema.anyOf.every(hasOnlySchemasForPrimitives);
907
+ return schema.anyOf.every(hasNoObjectSchemas);
908
908
  }
909
909
  else if (schema.oneOf) {
910
- return schema.oneOf.every(hasOnlySchemasForPrimitives);
910
+ return schema.oneOf.every(hasNoObjectSchemas);
911
+ }
912
+ else if (schema.enum) {
913
+ return true;
914
+ }
915
+ else if (schema.type === 'array') {
916
+ return !schema.items || hasNoObjectSchemas(schema.items);
911
917
  }
912
918
  else {
913
919
  return !!schema.type && ['string', 'number', 'integer', 'boolean', 'null'].includes(schema.type);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/nodejs-lib",
3
3
  "type": "module",
4
- "version": "15.80.0",
4
+ "version": "15.80.2",
5
5
  "dependencies": {
6
6
  "@naturalcycles/js-lib": "^15",
7
7
  "@types/js-yaml": "^4",
@@ -547,7 +547,7 @@ export function createAjv(opt?: Options): Ajv2020 {
547
547
  keyword: 'anyOfBy',
548
548
  type: 'object',
549
549
  modifying: true,
550
- errors: false,
550
+ errors: true,
551
551
  schemaType: 'object',
552
552
  compile(config, _parentSchema, _it) {
553
553
  const { propertyName, schemaDictionary } = config
@@ -574,7 +574,11 @@ export function createAjv(opt?: Options): Ajv2020 {
574
574
  return false
575
575
  }
576
576
 
577
- return isValidFn(data)
577
+ const result = isValidFn(data)
578
+ if (!result) {
579
+ ;(validate as any).errors = isValidFn.errors
580
+ }
581
+ return result
578
582
  }
579
583
 
580
584
  return validate
@@ -206,7 +206,7 @@ export const j = {
206
206
  >(items: [...B]): JsonSchemaAnyBuilder<IN, OUT, false> {
207
207
  const schemas = items.map(b => b.build())
208
208
  _assert(
209
- schemas.every(hasOnlySchemasForPrimitives),
209
+ schemas.every(hasNoObjectSchemas),
210
210
  'Do not use `oneOf` validation with non-primitive types!',
211
211
  )
212
212
 
@@ -233,7 +233,7 @@ export const j = {
233
233
  >(items: [...B]): JsonSchemaAnyBuilder<IN, OUT, false> {
234
234
  const schemas = items.map(b => b.build())
235
235
  _assert(
236
- schemas.every(hasOnlySchemasForPrimitives),
236
+ schemas.every(hasNoObjectSchemas),
237
237
  'Do not use `anyOf` validation with non-primitive types!',
238
238
  )
239
239
 
@@ -1515,13 +1515,17 @@ function withEnumKeys<
1515
1515
  >(props, { hasIsOfTypeCheck: false })
1516
1516
  }
1517
1517
 
1518
- function hasOnlySchemasForPrimitives(schema: JsonSchema): boolean {
1518
+ function hasNoObjectSchemas(schema: JsonSchema): boolean {
1519
1519
  if (Array.isArray(schema.type)) {
1520
1520
  schema.type.every(type => ['string', 'number', 'integer', 'boolean', 'null'].includes(type))
1521
1521
  } else if (schema.anyOf) {
1522
- return schema.anyOf.every(hasOnlySchemasForPrimitives)
1522
+ return schema.anyOf.every(hasNoObjectSchemas)
1523
1523
  } else if (schema.oneOf) {
1524
- return schema.oneOf.every(hasOnlySchemasForPrimitives)
1524
+ return schema.oneOf.every(hasNoObjectSchemas)
1525
+ } else if (schema.enum) {
1526
+ return true
1527
+ } else if (schema.type === 'array') {
1528
+ return !schema.items || hasNoObjectSchemas(schema.items)
1525
1529
  } else {
1526
1530
  return !!schema.type && ['string', 'number', 'integer', 'boolean', 'null'].includes(schema.type)
1527
1531
  }