Comparing version 1.0.0 to 1.0.1
@@ -832,3 +832,3 @@ "use strict"; | ||
value = typeof this.defaultValue === 'function' ? this.defaultValue() : this.defaultValue) { | ||
const errors = []; | ||
const errors = new Set(); | ||
for (const schema of this.schemas) { | ||
@@ -842,6 +842,10 @@ try { | ||
catch (err) { | ||
errors.push(err.message); | ||
errors.add(err.message); | ||
} | ||
} | ||
throw new ValidationError('No union satisfied:\n ' + errors.join('\n ')); | ||
const messages = Array.from(errors); | ||
if (messages.length === 1) { | ||
throw new ValidationError(messages[0]); | ||
} | ||
throw new ValidationError('No union satisfied:\n ' + messages.join('\n ')); | ||
} | ||
@@ -870,7 +874,21 @@ and(schema) { | ||
// TODO Investigate why I unwrap partials in a new intersection again | ||
if (this.left instanceof UnionType) { | ||
const unionSchemas = this.left.schemas; | ||
const schemas = unionSchemas.map(schema => this.right.and(schema)); | ||
const _schema = new UnionType(schemas); | ||
return (value) => _schema.parse(value); | ||
} | ||
if (this.right instanceof UnionType) { | ||
const unionSchemas = this.right.schemas; | ||
const schemas = unionSchemas.map(schema => this.left.and(schema)); | ||
const _schema = new UnionType(schemas); | ||
return (value) => _schema.parse(value); | ||
} | ||
if (this.left instanceof PartialType) { | ||
return (value) => new IntersectionType(this.left.schema, this.right).parse(value); | ||
const _schema = new IntersectionType(this.left.schema, this.right); | ||
return (value) => _schema.parse(value); | ||
} | ||
if (this.right instanceof PartialType) { | ||
return (value) => new IntersectionType(this.left, this.right.schema).parse(value); | ||
const _schema = new IntersectionType(this.left, this.right.schema); | ||
return (value) => _schema.parse(value); | ||
} | ||
@@ -877,0 +895,0 @@ return (value) => { |
{ | ||
"name": "myzod", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "", | ||
@@ -29,5 +29,5 @@ "main": "./libs/index.js", | ||
"@types/mocha": "^7.0.2", | ||
"@types/node": "^14.0.4", | ||
"@types/node": "^14.0.5", | ||
"benchmonkey": "0.0.7", | ||
"mocha": "^7.1.2", | ||
"mocha": "^7.2.0", | ||
"nyc": "^15.0.1", | ||
@@ -34,0 +34,0 @@ "prettier": "^2.0.5", |
91579
1505