@naturalcycles/nodejs-lib 15.80.1 → 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.
@@ -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.1",
4
+ "version": "15.80.2",
5
5
  "dependencies": {
6
6
  "@naturalcycles/js-lib": "^15",
7
7
  "@types/js-yaml": "^4",
@@ -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
  }