Socket
Socket
Sign inDemoInstall

io-ts

Package Overview
Dependencies
1
Maintainers
1
Versions
120
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.2.3 to 2.2.4

5

CHANGELOG.md

@@ -17,2 +17,7 @@ # Changelog

# 2.2.4
- **Polish**
- remove the dependency on the `either` instance as a mean of improving tree shaking (@gcanti)
# 2.2.3

@@ -19,0 +24,0 @@

297

es6/index.js

@@ -35,5 +35,3 @@ var __extends = (this && this.__extends) || (function () {

*/
import { either, isLeft, left, right } from 'fp-ts/es6/Either';
var map = either.map;
var chain = either.chain;
import { isLeft, left, right } from 'fp-ts/es6/Either';
/**

@@ -64,3 +62,9 @@ * @since 1.0.0

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) {
var e = _this.validate(i, c);
if (isLeft(e)) {
return e;
}
return ab.validate(e.right, c);
}, this.encode === identity && ab.encode === identity ? identity : function (b) { return _this.encode(ab.encode(b)); });
};

@@ -510,24 +514,27 @@ /**

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) {
var len = us.length;
var as = us;
var errors = [];
for (var i = 0; i < len; i++) {
var ui = us[i];
var result = codec.validate(ui, appendContext(c, String(i), codec, ui));
if (isLeft(result)) {
pushAll(errors, result.left);
}
else {
var ai = result.right;
if (ai !== ui) {
if (as === us) {
as = us.slice();
}
as[i] = ai;
var e = UnknownArray.validate(u, c);
if (isLeft(e)) {
return e;
}
var us = e.right;
var len = us.length;
var as = us;
var errors = [];
for (var i = 0; i < len; i++) {
var ui = us[i];
var result = codec.validate(ui, appendContext(c, String(i), codec, ui));
if (isLeft(result)) {
pushAll(errors, result.left);
}
else {
var ai = result.right;
if (ai !== ui) {
if (as === us) {
as = us.slice();
}
as[i] = ai;
}
}
return errors.length > 0 ? failures(errors) : success(as);
});
}
return errors.length > 0 ? failures(errors) : success(as);
}, codec.encode === identity ? identity : function (a) { return a.map(codec.encode); }, codec);

@@ -589,26 +596,29 @@ };

}, function (u, c) {
return chain(UnknownRecord.validate(u, c), function (o) {
var a = o;
var errors = [];
for (var i = 0; i < len; i++) {
var k = keys[i];
var ak = a[k];
var type_1 = types[i];
var result = type_1.validate(ak, appendContext(c, k, type_1, ak));
if (isLeft(result)) {
pushAll(errors, result.left);
}
else {
var vak = result.right;
if (vak !== ak || (vak === undefined && !hasOwnProperty.call(a, k))) {
/* istanbul ignore next */
if (a === o) {
a = __assign({}, o);
}
a[k] = vak;
var e = UnknownRecord.validate(u, c);
if (isLeft(e)) {
return e;
}
var o = e.right;
var a = o;
var errors = [];
for (var i = 0; i < len; i++) {
var k = keys[i];
var ak = a[k];
var type_1 = types[i];
var result = type_1.validate(ak, appendContext(c, k, type_1, ak));
if (isLeft(result)) {
pushAll(errors, result.left);
}
else {
var vak = result.right;
if (vak !== ak || (vak === undefined && !hasOwnProperty.call(a, k))) {
/* istanbul ignore next */
if (a === o) {
a = __assign({}, o);
}
a[k] = vak;
}
}
return errors.length > 0 ? failures(errors) : success(a);
});
}
return errors.length > 0 ? failures(errors) : success(a);
}, useIdentity(types)

@@ -669,28 +679,31 @@ ? identity

}, function (u, c) {
return chain(UnknownRecord.validate(u, c), function (o) {
var a = o;
var errors = [];
for (var i = 0; i < len; i++) {
var k = keys[i];
var ak = a[k];
var type_2 = props[k];
var result = type_2.validate(ak, appendContext(c, k, type_2, ak));
if (isLeft(result)) {
if (ak !== undefined) {
pushAll(errors, result.left);
}
var e = UnknownRecord.validate(u, c);
if (isLeft(e)) {
return e;
}
var o = e.right;
var a = o;
var errors = [];
for (var i = 0; i < len; i++) {
var k = keys[i];
var ak = a[k];
var type_2 = props[k];
var result = type_2.validate(ak, appendContext(c, k, type_2, ak));
if (isLeft(result)) {
if (ak !== undefined) {
pushAll(errors, result.left);
}
else {
var vak = result.right;
if (vak !== ak) {
/* istanbul ignore next */
if (a === o) {
a = __assign({}, o);
}
a[k] = vak;
}
else {
var vak = result.right;
if (vak !== ak) {
/* istanbul ignore next */
if (a === o) {
a = __assign({}, o);
}
a[k] = vak;
}
}
return errors.length > 0 ? failures(errors) : success(a);
});
}
return errors.length > 0 ? failures(errors) : success(a);
}, useIdentity(types)

@@ -732,21 +745,24 @@ ? identity

return new DictionaryType(name, function (u) { return UnknownRecord.is(u) && keys.every(function (k) { return codomain.is(u[k]); }); }, function (u, c) {
return chain(UnknownRecord.validate(u, c), function (o) {
var a = {};
var errors = [];
var changed = false;
for (var i = 0; i < len; i++) {
var k = keys[i];
var ok = o[k];
var codomainResult = codomain.validate(ok, appendContext(c, k, codomain, ok));
if (isLeft(codomainResult)) {
pushAll(errors, codomainResult.left);
}
else {
var vok = codomainResult.right;
changed = changed || vok !== ok;
a[k] = vok;
}
var e = UnknownRecord.validate(u, c);
if (isLeft(e)) {
return e;
}
var o = e.right;
var a = {};
var errors = [];
var changed = false;
for (var i = 0; i < len; i++) {
var k = keys[i];
var ok = o[k];
var codomainResult = codomain.validate(ok, appendContext(c, k, codomain, ok));
if (isLeft(codomainResult)) {
pushAll(errors, codomainResult.left);
}
return errors.length > 0 ? failures(errors) : success((changed || Object.keys(o).length !== len ? a : o));
});
else {
var vok = codomainResult.right;
changed = changed || vok !== ok;
a[k] = vok;
}
}
return errors.length > 0 ? failures(errors) : success((changed || Object.keys(o).length !== len ? a : o));
}, codomain.encode === identity

@@ -892,10 +908,13 @@ ? identity

}, function (u, c) {
return chain(UnknownRecord.validate(u, c), function (r) {
var i = find_1(r[tag_1]);
if (i === undefined) {
return failure(u, c);
}
var codec = codecs[i];
return codec.validate(r, appendContext(c, String(i), codec, r));
});
var e = UnknownRecord.validate(u, c);
if (isLeft(e)) {
return e;
}
var r = e.right;
var i = find_1(r[tag_1]);
if (i === undefined) {
return failure(u, c);
}
var codec = codecs[i];
return codec.validate(r, appendContext(c, String(i), codec, r));
}, useIdentity(codecs)

@@ -1034,25 +1053,28 @@ ? identity

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) {
var as = us.length > len ? us.slice(0, len) : us; // strip additional components
var errors = [];
for (var i = 0; i < len; i++) {
var a = us[i];
var type_3 = codecs[i];
var result = type_3.validate(a, appendContext(c, String(i), type_3, a));
if (isLeft(result)) {
pushAll(errors, result.left);
}
else {
var va = result.right;
if (va !== a) {
/* istanbul ignore next */
if (as === us) {
as = us.slice();
}
as[i] = va;
var e = UnknownArray.validate(u, c);
if (isLeft(e)) {
return e;
}
var us = e.right;
var as = us.length > len ? us.slice(0, len) : us; // strip additional components
var errors = [];
for (var i = 0; i < len; i++) {
var a = us[i];
var type_3 = codecs[i];
var result = type_3.validate(a, appendContext(c, String(i), type_3, a));
if (isLeft(result)) {
pushAll(errors, result.left);
}
else {
var va = result.right;
if (va !== a) {
/* istanbul ignore next */
if (as === us) {
as = us.slice();
}
as[i] = va;
}
}
return errors.length > 0 ? failures(errors) : success(as);
});
}
return errors.length > 0 ? failures(errors) : success(as);
}, useIdentity(codecs) ? identity : function (a) { return codecs.map(function (type, i) { return type.encode(a[i]); }); }, codecs);

@@ -1083,8 +1105,11 @@ }

return new ReadonlyType(name, codec.is, function (u, c) {
return map(codec.validate(u, c), function (x) {
if (process.env.NODE_ENV !== 'production') {
return Object.freeze(x);
}
return x;
});
var e = codec.validate(u, c);
if (isLeft(e)) {
return e;
}
var x = e.right;
if (process.env.NODE_ENV !== 'production') {
return right(Object.freeze(x));
}
return right(x);
}, codec.encode === identity ? identity : codec.encode, codec);

@@ -1116,8 +1141,11 @@ };

return new ReadonlyArrayType(name, arrayType.is, function (u, c) {
return map(arrayType.validate(u, c), function (x) {
if (process.env.NODE_ENV !== 'production') {
return Object.freeze(x);
}
return x;
});
var e = arrayType.validate(u, c);
if (isLeft(e)) {
return e;
}
var x = e.right;
if (process.env.NODE_ENV !== 'production') {
return right(Object.freeze(x));
}
return right(x);
}, arrayType.encode, codec);

@@ -1235,3 +1263,13 @@ };

var props = getProps(codec);
return new ExactType(name, codec.is, function (u, c) { return chain(UnknownRecord.validate(u, c), function () { return map(codec.validate(u, c), function (a) { return stripKeys(a, props); }); }); }, function (a) { return codec.encode(stripKeys(a, props)); }, codec);
return new ExactType(name, codec.is, function (u, c) {
var e = UnknownRecord.validate(u, c);
if (isLeft(e)) {
return e;
}
var ce = codec.validate(u, c);
if (isLeft(ce)) {
return ce;
}
return right(stripKeys(ce.right, props));
}, function (a) { return codec.encode(stripKeys(a, props)); }, codec);
};

@@ -1370,3 +1408,10 @@ export {

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) {
var e = codec.validate(i, c);
if (isLeft(e)) {
return e;
}
var a = e.right;
return predicate(a) ? success(a) : failure(a, c);
}, codec.encode, codec, predicate);
}

@@ -1373,0 +1418,0 @@ /**

@@ -39,4 +39,2 @@ "use strict";

var Either_1 = require("fp-ts/lib/Either");
var map = Either_1.either.map;
var chain = Either_1.either.chain;
/**

@@ -67,3 +65,9 @@ * @since 1.0.0

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) {
var e = _this.validate(i, c);
if (Either_1.isLeft(e)) {
return e;
}
return ab.validate(e.right, c);
}, this.encode === exports.identity && ab.encode === exports.identity ? exports.identity : function (b) { return _this.encode(ab.encode(b)); });
};

@@ -517,24 +521,27 @@ /**

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) {
var len = us.length;
var as = us;
var errors = [];
for (var i = 0; i < len; i++) {
var ui = us[i];
var result = codec.validate(ui, exports.appendContext(c, String(i), codec, ui));
if (Either_1.isLeft(result)) {
pushAll(errors, result.left);
}
else {
var ai = result.right;
if (ai !== ui) {
if (as === us) {
as = us.slice();
}
as[i] = ai;
var e = exports.UnknownArray.validate(u, c);
if (Either_1.isLeft(e)) {
return e;
}
var us = e.right;
var len = us.length;
var as = us;
var errors = [];
for (var i = 0; i < len; i++) {
var ui = us[i];
var result = codec.validate(ui, exports.appendContext(c, String(i), codec, ui));
if (Either_1.isLeft(result)) {
pushAll(errors, result.left);
}
else {
var ai = result.right;
if (ai !== ui) {
if (as === us) {
as = us.slice();
}
as[i] = ai;
}
}
return errors.length > 0 ? exports.failures(errors) : exports.success(as);
});
}
return errors.length > 0 ? exports.failures(errors) : exports.success(as);
}, codec.encode === exports.identity ? exports.identity : function (a) { return a.map(codec.encode); }, codec);

@@ -596,26 +603,29 @@ };

}, function (u, c) {
return chain(exports.UnknownRecord.validate(u, c), function (o) {
var a = o;
var errors = [];
for (var i = 0; i < len; i++) {
var k = keys[i];
var ak = a[k];
var type_1 = types[i];
var result = type_1.validate(ak, exports.appendContext(c, k, type_1, ak));
if (Either_1.isLeft(result)) {
pushAll(errors, result.left);
}
else {
var vak = result.right;
if (vak !== ak || (vak === undefined && !hasOwnProperty.call(a, k))) {
/* istanbul ignore next */
if (a === o) {
a = __assign({}, o);
}
a[k] = vak;
var e = exports.UnknownRecord.validate(u, c);
if (Either_1.isLeft(e)) {
return e;
}
var o = e.right;
var a = o;
var errors = [];
for (var i = 0; i < len; i++) {
var k = keys[i];
var ak = a[k];
var type_1 = types[i];
var result = type_1.validate(ak, exports.appendContext(c, k, type_1, ak));
if (Either_1.isLeft(result)) {
pushAll(errors, result.left);
}
else {
var vak = result.right;
if (vak !== ak || (vak === undefined && !hasOwnProperty.call(a, k))) {
/* istanbul ignore next */
if (a === o) {
a = __assign({}, o);
}
a[k] = vak;
}
}
return errors.length > 0 ? exports.failures(errors) : exports.success(a);
});
}
return errors.length > 0 ? exports.failures(errors) : exports.success(a);
}, useIdentity(types)

@@ -677,28 +687,31 @@ ? exports.identity

}, function (u, c) {
return chain(exports.UnknownRecord.validate(u, c), function (o) {
var a = o;
var errors = [];
for (var i = 0; i < len; i++) {
var k = keys[i];
var ak = a[k];
var type_2 = props[k];
var result = type_2.validate(ak, exports.appendContext(c, k, type_2, ak));
if (Either_1.isLeft(result)) {
if (ak !== undefined) {
pushAll(errors, result.left);
}
var e = exports.UnknownRecord.validate(u, c);
if (Either_1.isLeft(e)) {
return e;
}
var o = e.right;
var a = o;
var errors = [];
for (var i = 0; i < len; i++) {
var k = keys[i];
var ak = a[k];
var type_2 = props[k];
var result = type_2.validate(ak, exports.appendContext(c, k, type_2, ak));
if (Either_1.isLeft(result)) {
if (ak !== undefined) {
pushAll(errors, result.left);
}
else {
var vak = result.right;
if (vak !== ak) {
/* istanbul ignore next */
if (a === o) {
a = __assign({}, o);
}
a[k] = vak;
}
else {
var vak = result.right;
if (vak !== ak) {
/* istanbul ignore next */
if (a === o) {
a = __assign({}, o);
}
a[k] = vak;
}
}
return errors.length > 0 ? exports.failures(errors) : exports.success(a);
});
}
return errors.length > 0 ? exports.failures(errors) : exports.success(a);
}, useIdentity(types)

@@ -740,21 +753,24 @@ ? exports.identity

return new DictionaryType(name, function (u) { return exports.UnknownRecord.is(u) && keys.every(function (k) { return codomain.is(u[k]); }); }, function (u, c) {
return chain(exports.UnknownRecord.validate(u, c), function (o) {
var a = {};
var errors = [];
var changed = false;
for (var i = 0; i < len; i++) {
var k = keys[i];
var ok = o[k];
var codomainResult = codomain.validate(ok, exports.appendContext(c, k, codomain, ok));
if (Either_1.isLeft(codomainResult)) {
pushAll(errors, codomainResult.left);
}
else {
var vok = codomainResult.right;
changed = changed || vok !== ok;
a[k] = vok;
}
var e = exports.UnknownRecord.validate(u, c);
if (Either_1.isLeft(e)) {
return e;
}
var o = e.right;
var a = {};
var errors = [];
var changed = false;
for (var i = 0; i < len; i++) {
var k = keys[i];
var ok = o[k];
var codomainResult = codomain.validate(ok, exports.appendContext(c, k, codomain, ok));
if (Either_1.isLeft(codomainResult)) {
pushAll(errors, codomainResult.left);
}
return errors.length > 0 ? exports.failures(errors) : exports.success((changed || Object.keys(o).length !== len ? a : o));
});
else {
var vok = codomainResult.right;
changed = changed || vok !== ok;
a[k] = vok;
}
}
return errors.length > 0 ? exports.failures(errors) : exports.success((changed || Object.keys(o).length !== len ? a : o));
}, codomain.encode === exports.identity

@@ -902,10 +918,13 @@ ? exports.identity

}, function (u, c) {
return chain(exports.UnknownRecord.validate(u, c), function (r) {
var i = find_1(r[tag_1]);
if (i === undefined) {
return exports.failure(u, c);
}
var codec = codecs[i];
return codec.validate(r, exports.appendContext(c, String(i), codec, r));
});
var e = exports.UnknownRecord.validate(u, c);
if (Either_1.isLeft(e)) {
return e;
}
var r = e.right;
var i = find_1(r[tag_1]);
if (i === undefined) {
return exports.failure(u, c);
}
var codec = codecs[i];
return codec.validate(r, exports.appendContext(c, String(i), codec, r));
}, useIdentity(codecs)

@@ -1045,25 +1064,28 @@ ? exports.identity

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) {
var as = us.length > len ? us.slice(0, len) : us; // strip additional components
var errors = [];
for (var i = 0; i < len; i++) {
var a = us[i];
var type_3 = codecs[i];
var result = type_3.validate(a, exports.appendContext(c, String(i), type_3, a));
if (Either_1.isLeft(result)) {
pushAll(errors, result.left);
}
else {
var va = result.right;
if (va !== a) {
/* istanbul ignore next */
if (as === us) {
as = us.slice();
}
as[i] = va;
var e = exports.UnknownArray.validate(u, c);
if (Either_1.isLeft(e)) {
return e;
}
var us = e.right;
var as = us.length > len ? us.slice(0, len) : us; // strip additional components
var errors = [];
for (var i = 0; i < len; i++) {
var a = us[i];
var type_3 = codecs[i];
var result = type_3.validate(a, exports.appendContext(c, String(i), type_3, a));
if (Either_1.isLeft(result)) {
pushAll(errors, result.left);
}
else {
var va = result.right;
if (va !== a) {
/* istanbul ignore next */
if (as === us) {
as = us.slice();
}
as[i] = va;
}
}
return errors.length > 0 ? exports.failures(errors) : exports.success(as);
});
}
return errors.length > 0 ? exports.failures(errors) : exports.success(as);
}, useIdentity(codecs) ? exports.identity : function (a) { return codecs.map(function (type, i) { return type.encode(a[i]); }); }, codecs);

@@ -1095,8 +1117,11 @@ }

return new ReadonlyType(name, codec.is, function (u, c) {
return map(codec.validate(u, c), function (x) {
if (process.env.NODE_ENV !== 'production') {
return Object.freeze(x);
}
return x;
});
var e = codec.validate(u, c);
if (Either_1.isLeft(e)) {
return e;
}
var x = e.right;
if (process.env.NODE_ENV !== 'production') {
return Either_1.right(Object.freeze(x));
}
return Either_1.right(x);
}, codec.encode === exports.identity ? exports.identity : codec.encode, codec);

@@ -1128,8 +1153,11 @@ };

return new ReadonlyArrayType(name, arrayType.is, function (u, c) {
return map(arrayType.validate(u, c), function (x) {
if (process.env.NODE_ENV !== 'production') {
return Object.freeze(x);
}
return x;
});
var e = arrayType.validate(u, c);
if (Either_1.isLeft(e)) {
return e;
}
var x = e.right;
if (process.env.NODE_ENV !== 'production') {
return Either_1.right(Object.freeze(x));
}
return Either_1.right(x);
}, arrayType.encode, codec);

@@ -1247,3 +1275,13 @@ };

var props = getProps(codec);
return new ExactType(name, codec.is, function (u, c) { return chain(exports.UnknownRecord.validate(u, c), function () { return map(codec.validate(u, c), function (a) { return stripKeys(a, props); }); }); }, function (a) { return codec.encode(stripKeys(a, props)); }, codec);
return new ExactType(name, codec.is, function (u, c) {
var e = exports.UnknownRecord.validate(u, c);
if (Either_1.isLeft(e)) {
return e;
}
var ce = codec.validate(u, c);
if (Either_1.isLeft(ce)) {
return ce;
}
return Either_1.right(stripKeys(ce.right, props));
}, function (a) { return codec.encode(stripKeys(a, props)); }, codec);
};

@@ -1353,3 +1391,10 @@ /**

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) {
var e = codec.validate(i, c);
if (Either_1.isLeft(e)) {
return e;
}
var a = e.right;
return predicate(a) ? exports.success(a) : exports.failure(a, c);
}, codec.encode, codec, predicate);
}

@@ -1356,0 +1401,0 @@ exports.refinement = refinement;

{
"name": "io-ts",
"version": "2.2.3",
"version": "2.2.4",
"description": "TypeScript runtime type system for IO decoding/encoding",

@@ -5,0 +5,0 @@ "files": [

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc