Comparing version 1.10.3 to 1.10.4
@@ -17,2 +17,7 @@ # Changelog | ||
# 1.10.4 | ||
- **Polish** | ||
- remove unneeded internal code (@gcanti) | ||
# 1.10.3 | ||
@@ -19,0 +24,0 @@ |
@@ -25,23 +25,4 @@ var __extends = (this && this.__extends) || (function () { | ||
}; | ||
import { either, left, right } from 'fp-ts/lib/Either'; | ||
var map = either.map; | ||
var chain = either.chain; | ||
import { left, right } from 'fp-ts/lib/Either'; | ||
/** | ||
* @internal | ||
*/ | ||
export function fold(ma, onLeft, onRight) { | ||
var e = ma; | ||
return e._tag === 'Left' | ||
? onLeft(e.hasOwnProperty('left') | ||
? /* istanbul ignore next */ | ||
e.left | ||
: /* istanbul ignore next */ | ||
e.value) | ||
: onRight(e.hasOwnProperty('right') | ||
? /* istanbul ignore next */ | ||
e.right | ||
: /* istanbul ignore next */ | ||
e.value); | ||
} | ||
/** | ||
* @since 1.0.0 | ||
@@ -68,3 +49,3 @@ */ | ||
if (name === void 0) { name = "pipe(" + this.name + ", " + ab.name + ")"; } | ||
return new Type(name, ab.is, function (i, c) { return chain(_this.validate(i, c), function (a) { return ab.validate(a, c); }); }, this.encode === identity && ab.encode === identity ? identity : function (b) { return _this.encode(ab.encode(b)); }); | ||
return new Type(name, ab.is, function (i, c) { return _this.validate(i, c).chain(function (a) { return ab.validate(a, c); }); }, this.encode === identity && ab.encode === identity ? identity : function (b) { return _this.encode(ab.encode(b)); }); | ||
}; | ||
@@ -443,3 +424,3 @@ Type.prototype.asDecoder = function () { | ||
return new ArrayType(name, function (u) { return UnknownArray.is(u) && u.every(codec.is); }, function (u, c) { | ||
return chain(UnknownArray.validate(u, c), function (us) { | ||
return UnknownArray.validate(u, c).chain(function (us) { | ||
var len = us.length; | ||
@@ -450,3 +431,3 @@ var as = us; | ||
var ui = us[i]; | ||
fold(codec.validate(ui, appendContext(c, String(i), codec, ui)), function (e) { return pushAll(errors, e); }, function (ai) { | ||
codec.validate(ui, appendContext(c, String(i), codec, ui)).fold(function (e) { return pushAll(errors, e); }, function (ai) { | ||
if (ai !== ui) { | ||
@@ -518,3 +499,3 @@ if (as === us) { | ||
}, function (u, c) { | ||
return chain(UnknownRecord.validate(u, c), function (o) { | ||
return UnknownRecord.validate(u, c).chain(function (o) { | ||
var a = o; | ||
@@ -532,3 +513,3 @@ var errors = []; | ||
var type_1 = types[i]; | ||
fold(type_1.validate(ak, appendContext(c, k, type_1, ak)), function (e) { return pushAll(errors, e); }, function (vak) { | ||
type_1.validate(ak, appendContext(c, k, type_1, ak)).fold(function (e) { return pushAll(errors, e); }, function (vak) { | ||
if (vak !== ak) { | ||
@@ -600,3 +581,3 @@ /* istanbul ignore next */ | ||
}, function (u, c) { | ||
return chain(UnknownRecord.validate(u, c), function (o) { | ||
return UnknownRecord.validate(u, c).chain(function (o) { | ||
var a = o; | ||
@@ -608,3 +589,3 @@ var errors = []; | ||
var type_2 = props[k]; | ||
fold(type_2.validate(ak, appendContext(c, k, type_2, ak)), function (e) { | ||
type_2.validate(ak, appendContext(c, k, type_2, ak)).fold(function (e) { | ||
if (ak !== undefined) { | ||
@@ -672,3 +653,3 @@ pushAll(errors, e); | ||
}, function (u, c) { | ||
return chain(UnknownRecord.validate(u, c), function (o) { | ||
return UnknownRecord.validate(u, c).chain(function (o) { | ||
if (!isUnknownCodec(codomain) && !isAnyCodec(codomain) && !isObject(o)) { | ||
@@ -685,6 +666,6 @@ return failure(u, c); | ||
var ok = o[k]; | ||
fold(domain.validate(k, appendContext(c, k, domain, k)), function (e) { return pushAll(errors, e); }, function (vk) { | ||
domain.validate(k, appendContext(c, k, domain, k)).fold(function (e) { return pushAll(errors, e); }, function (vk) { | ||
changed = changed || vk !== k; | ||
k = vk; | ||
fold(codomain.validate(ok, appendContext(c, k, codomain, ok)), function (e) { return pushAll(errors, e); }, function (vok) { | ||
codomain.validate(ok, appendContext(c, k, codomain, ok)).fold(function (e) { return pushAll(errors, e); }, function (vok) { | ||
changed = changed || vok !== ok; | ||
@@ -755,3 +736,3 @@ a[k] = vok; | ||
}, function (u, c) { | ||
return chain(UnknownRecord.validate(u, c), function (r) { | ||
return UnknownRecord.validate(u, c).chain(function (r) { | ||
var i = find_1(r[tag_1]); | ||
@@ -782,3 +763,5 @@ if (i === undefined) { | ||
var codec = codecs[i]; | ||
var r = fold(codec.validate(u, appendContext(c, String(i), codec, u)), function (e) { return pushAll(errors, e); }, success); | ||
var r = codec | ||
.validate(u, appendContext(c, String(i), codec, u)) | ||
.fold(function (e) { return pushAll(errors, e); }, success); | ||
if (r !== undefined) { | ||
@@ -846,3 +829,3 @@ return r; | ||
var codec = codecs[i]; | ||
fold(codec.validate(u, appendContext(c, String(i), codec, u)), function (e) { return pushAll(errors, e); }, function (a) { return us.push(a); }); | ||
codec.validate(u, appendContext(c, String(i), codec, u)).fold(function (e) { return pushAll(errors, e); }, function (a) { return us.push(a); }); | ||
} | ||
@@ -870,3 +853,3 @@ return errors.length > 0 ? failures(errors) : success(mergeAll(u, us)); | ||
return new TupleType(name, function (u) { return UnknownArray.is(u) && u.length === len && codecs.every(function (type, i) { return type.is(u[i]); }); }, function (u, c) { | ||
return chain(UnknownArray.validate(u, c), function (us) { | ||
return UnknownArray.validate(u, c).chain(function (us) { | ||
var as = us.length > len ? us.slice(0, len) : us; // strip additional components | ||
@@ -877,3 +860,3 @@ var errors = []; | ||
var type_3 = codecs[i]; | ||
fold(type_3.validate(a, appendContext(c, String(i), type_3, a)), function (e) { return pushAll(errors, e); }, function (va) { | ||
type_3.validate(a, appendContext(c, String(i), type_3, a)).fold(function (e) { return pushAll(errors, e); }, function (va) { | ||
if (va !== a) { | ||
@@ -915,3 +898,3 @@ /* istanbul ignore next */ | ||
return new ReadonlyType(name, codec.is, function (u, c) { | ||
return map(codec.validate(u, c), function (x) { | ||
return codec.validate(u, c).map(function (x) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
@@ -945,3 +928,3 @@ return Object.freeze(x); | ||
return new ReadonlyArrayType(name, arrayType.is, function (u, c) { | ||
return map(arrayType.validate(u, c), function (x) { | ||
return arrayType.validate(u, c).map(function (x) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
@@ -1062,3 +1045,3 @@ return Object.freeze(x); | ||
return new ExactType(name, codec.is, function (u, c) { | ||
return chain(UnknownRecord.validate(u, c), function () { return fold(codec.validate(u, c), left, function (a) { return success(stripKeys(a, props)); }); }); | ||
return UnknownRecord.validate(u, c).chain(function () { return codec.validate(u, c).fold(left, function (a) { return success(stripKeys(a, props)); }); }); | ||
}, function (a) { return codec.encode(stripKeys(a, props)); }, codec); | ||
@@ -1173,3 +1156,3 @@ }; | ||
if (name === void 0) { name = "(" + codec.name + " | " + getFunctionName(predicate) + ")"; } | ||
return new RefinementType(name, function (u) { return codec.is(u) && predicate(u); }, function (i, c) { return chain(codec.validate(i, c), function (a) { return (predicate(a) ? success(a) : failure(a, c)); }); }, codec.encode, codec, predicate); | ||
return new RefinementType(name, function (u) { return codec.is(u) && predicate(u); }, function (i, c) { return codec.validate(i, c).chain(function (a) { return (predicate(a) ? success(a) : failure(a, c)); }); }, codec.encode, codec, predicate); | ||
} | ||
@@ -1176,0 +1159,0 @@ /** |
@@ -1,2 +0,2 @@ | ||
import { getFunctionName, fold } from '.'; | ||
import { getFunctionName } from '.'; | ||
function stringify(v) { | ||
@@ -41,3 +41,3 @@ if (typeof v === 'function') { | ||
export var PathReporter = { | ||
report: function (validation) { return fold(validation, failure, success); } | ||
report: function (validation) { return validation.fold(failure, success); } | ||
}; |
import { PathReporter } from './PathReporter'; | ||
import { fold } from '.'; | ||
/** | ||
@@ -9,8 +8,6 @@ * @since 1.0.0 | ||
report: function (validation) { | ||
return fold(validation, function () { | ||
if (validation.isLeft()) { | ||
throw PathReporter.report(validation).join('\n'); | ||
}, function () { | ||
return; | ||
}); | ||
} | ||
} | ||
}; |
@@ -28,23 +28,3 @@ "use strict"; | ||
var Either_1 = require("fp-ts/lib/Either"); | ||
var map = Either_1.either.map; | ||
var chain = Either_1.either.chain; | ||
/** | ||
* @internal | ||
*/ | ||
function fold(ma, onLeft, onRight) { | ||
var e = ma; | ||
return e._tag === 'Left' | ||
? onLeft(e.hasOwnProperty('left') | ||
? /* istanbul ignore next */ | ||
e.left | ||
: /* istanbul ignore next */ | ||
e.value) | ||
: onRight(e.hasOwnProperty('right') | ||
? /* istanbul ignore next */ | ||
e.right | ||
: /* istanbul ignore next */ | ||
e.value); | ||
} | ||
exports.fold = fold; | ||
/** | ||
* @since 1.0.0 | ||
@@ -71,3 +51,3 @@ */ | ||
if (name === void 0) { name = "pipe(" + this.name + ", " + ab.name + ")"; } | ||
return new Type(name, ab.is, function (i, c) { return chain(_this.validate(i, c), function (a) { return ab.validate(a, c); }); }, this.encode === exports.identity && ab.encode === exports.identity ? exports.identity : function (b) { return _this.encode(ab.encode(b)); }); | ||
return new Type(name, ab.is, function (i, c) { return _this.validate(i, c).chain(function (a) { return ab.validate(a, c); }); }, this.encode === exports.identity && ab.encode === exports.identity ? exports.identity : function (b) { return _this.encode(ab.encode(b)); }); | ||
}; | ||
@@ -450,3 +430,3 @@ Type.prototype.asDecoder = function () { | ||
return new ArrayType(name, function (u) { return exports.UnknownArray.is(u) && u.every(codec.is); }, function (u, c) { | ||
return chain(exports.UnknownArray.validate(u, c), function (us) { | ||
return exports.UnknownArray.validate(u, c).chain(function (us) { | ||
var len = us.length; | ||
@@ -457,3 +437,3 @@ var as = us; | ||
var ui = us[i]; | ||
fold(codec.validate(ui, exports.appendContext(c, String(i), codec, ui)), function (e) { return pushAll(errors, e); }, function (ai) { | ||
codec.validate(ui, exports.appendContext(c, String(i), codec, ui)).fold(function (e) { return pushAll(errors, e); }, function (ai) { | ||
if (ai !== ui) { | ||
@@ -525,3 +505,3 @@ if (as === us) { | ||
}, function (u, c) { | ||
return chain(exports.UnknownRecord.validate(u, c), function (o) { | ||
return exports.UnknownRecord.validate(u, c).chain(function (o) { | ||
var a = o; | ||
@@ -539,3 +519,3 @@ var errors = []; | ||
var type_1 = types[i]; | ||
fold(type_1.validate(ak, exports.appendContext(c, k, type_1, ak)), function (e) { return pushAll(errors, e); }, function (vak) { | ||
type_1.validate(ak, exports.appendContext(c, k, type_1, ak)).fold(function (e) { return pushAll(errors, e); }, function (vak) { | ||
if (vak !== ak) { | ||
@@ -608,3 +588,3 @@ /* istanbul ignore next */ | ||
}, function (u, c) { | ||
return chain(exports.UnknownRecord.validate(u, c), function (o) { | ||
return exports.UnknownRecord.validate(u, c).chain(function (o) { | ||
var a = o; | ||
@@ -616,3 +596,3 @@ var errors = []; | ||
var type_2 = props[k]; | ||
fold(type_2.validate(ak, exports.appendContext(c, k, type_2, ak)), function (e) { | ||
type_2.validate(ak, exports.appendContext(c, k, type_2, ak)).fold(function (e) { | ||
if (ak !== undefined) { | ||
@@ -680,3 +660,3 @@ pushAll(errors, e); | ||
}, function (u, c) { | ||
return chain(exports.UnknownRecord.validate(u, c), function (o) { | ||
return exports.UnknownRecord.validate(u, c).chain(function (o) { | ||
if (!isUnknownCodec(codomain) && !isAnyCodec(codomain) && !isObject(o)) { | ||
@@ -693,6 +673,6 @@ return exports.failure(u, c); | ||
var ok = o[k]; | ||
fold(domain.validate(k, exports.appendContext(c, k, domain, k)), function (e) { return pushAll(errors, e); }, function (vk) { | ||
domain.validate(k, exports.appendContext(c, k, domain, k)).fold(function (e) { return pushAll(errors, e); }, function (vk) { | ||
changed = changed || vk !== k; | ||
k = vk; | ||
fold(codomain.validate(ok, exports.appendContext(c, k, codomain, ok)), function (e) { return pushAll(errors, e); }, function (vok) { | ||
codomain.validate(ok, exports.appendContext(c, k, codomain, ok)).fold(function (e) { return pushAll(errors, e); }, function (vok) { | ||
changed = changed || vok !== ok; | ||
@@ -763,3 +743,3 @@ a[k] = vok; | ||
}, function (u, c) { | ||
return chain(exports.UnknownRecord.validate(u, c), function (r) { | ||
return exports.UnknownRecord.validate(u, c).chain(function (r) { | ||
var i = find_1(r[tag_1]); | ||
@@ -790,3 +770,5 @@ if (i === undefined) { | ||
var codec = codecs[i]; | ||
var r = fold(codec.validate(u, exports.appendContext(c, String(i), codec, u)), function (e) { return pushAll(errors, e); }, exports.success); | ||
var r = codec | ||
.validate(u, exports.appendContext(c, String(i), codec, u)) | ||
.fold(function (e) { return pushAll(errors, e); }, exports.success); | ||
if (r !== undefined) { | ||
@@ -854,3 +836,3 @@ return r; | ||
var codec = codecs[i]; | ||
fold(codec.validate(u, exports.appendContext(c, String(i), codec, u)), function (e) { return pushAll(errors, e); }, function (a) { return us.push(a); }); | ||
codec.validate(u, exports.appendContext(c, String(i), codec, u)).fold(function (e) { return pushAll(errors, e); }, function (a) { return us.push(a); }); | ||
} | ||
@@ -879,3 +861,3 @@ return errors.length > 0 ? exports.failures(errors) : exports.success(mergeAll(u, us)); | ||
return new TupleType(name, function (u) { return exports.UnknownArray.is(u) && u.length === len && codecs.every(function (type, i) { return type.is(u[i]); }); }, function (u, c) { | ||
return chain(exports.UnknownArray.validate(u, c), function (us) { | ||
return exports.UnknownArray.validate(u, c).chain(function (us) { | ||
var as = us.length > len ? us.slice(0, len) : us; // strip additional components | ||
@@ -886,3 +868,3 @@ var errors = []; | ||
var type_3 = codecs[i]; | ||
fold(type_3.validate(a, exports.appendContext(c, String(i), type_3, a)), function (e) { return pushAll(errors, e); }, function (va) { | ||
type_3.validate(a, exports.appendContext(c, String(i), type_3, a)).fold(function (e) { return pushAll(errors, e); }, function (va) { | ||
if (va !== a) { | ||
@@ -925,3 +907,3 @@ /* istanbul ignore next */ | ||
return new ReadonlyType(name, codec.is, function (u, c) { | ||
return map(codec.validate(u, c), function (x) { | ||
return codec.validate(u, c).map(function (x) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
@@ -955,3 +937,3 @@ return Object.freeze(x); | ||
return new ReadonlyArrayType(name, arrayType.is, function (u, c) { | ||
return map(arrayType.validate(u, c), function (x) { | ||
return arrayType.validate(u, c).map(function (x) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
@@ -1072,3 +1054,3 @@ return Object.freeze(x); | ||
return new ExactType(name, codec.is, function (u, c) { | ||
return chain(exports.UnknownRecord.validate(u, c), function () { return fold(codec.validate(u, c), Either_1.left, function (a) { return exports.success(stripKeys(a, props)); }); }); | ||
return exports.UnknownRecord.validate(u, c).chain(function () { return codec.validate(u, c).fold(Either_1.left, function (a) { return exports.success(stripKeys(a, props)); }); }); | ||
}, function (a) { return codec.encode(stripKeys(a, props)); }, codec); | ||
@@ -1170,3 +1152,3 @@ }; | ||
if (name === void 0) { name = "(" + codec.name + " | " + exports.getFunctionName(predicate) + ")"; } | ||
return new RefinementType(name, function (u) { return codec.is(u) && predicate(u); }, function (i, c) { return chain(codec.validate(i, c), function (a) { return (predicate(a) ? exports.success(a) : exports.failure(a, c)); }); }, codec.encode, codec, predicate); | ||
return new RefinementType(name, function (u) { return codec.is(u) && predicate(u); }, function (i, c) { return codec.validate(i, c).chain(function (a) { return (predicate(a) ? exports.success(a) : exports.failure(a, c)); }); }, codec.encode, codec, predicate); | ||
} | ||
@@ -1173,0 +1155,0 @@ exports.refinement = refinement; |
@@ -45,3 +45,3 @@ "use strict"; | ||
exports.PathReporter = { | ||
report: function (validation) { return _1.fold(validation, failure, success); } | ||
report: function (validation) { return validation.fold(failure, success); } | ||
}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var PathReporter_1 = require("./PathReporter"); | ||
var _1 = require("."); | ||
/** | ||
@@ -11,8 +10,6 @@ * @since 1.0.0 | ||
report: function (validation) { | ||
return _1.fold(validation, function () { | ||
if (validation.isLeft()) { | ||
throw PathReporter_1.PathReporter.report(validation).join('\n'); | ||
}, function () { | ||
return; | ||
}); | ||
} | ||
} | ||
}; |
{ | ||
"name": "io-ts", | ||
"version": "1.10.3", | ||
"version": "1.10.4", | ||
"description": "TypeScript compatible runtime type system for IO validation", | ||
@@ -22,3 +22,3 @@ "files": [ | ||
"prepublish": "npm run build", | ||
"perf": "node perf/index", | ||
"perf": "ts-node perf/index", | ||
"dtslint": "dtslint dtslint", | ||
@@ -25,0 +25,0 @@ "declaration": "tsc -p declaration/tsconfig.json", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
178970
4789