Comparing version 1.3.3 to 1.3.4
@@ -16,2 +16,7 @@ # Changelog | ||
# 1.3.4 | ||
- **Bug Fix** | ||
- should emit expected keys while decoding, fix #214 (@gcanti) | ||
# 1.3.3 | ||
@@ -18,0 +23,0 @@ |
106
lib/index.js
@@ -304,5 +304,6 @@ "use strict"; | ||
exports.KeyofType = KeyofType; | ||
var hasOwnProperty = Object.prototype.hasOwnProperty; | ||
exports.keyof = function (keys, name) { | ||
if (name === void 0) { name = "(keyof " + JSON.stringify(Object.keys(keys)) + ")"; } | ||
var is = function (m) { return exports.string.is(m) && keys.hasOwnProperty(m); }; | ||
var is = function (m) { return exports.string.is(m) && hasOwnProperty.call(keys, m); }; | ||
return new KeyofType(name, is, function (m, c) { return (is(m) ? exports.success(m) : exports.failure(m, c)); }, exports.identity, keys); | ||
@@ -426,3 +427,4 @@ }; | ||
for (var i = 0; i < len; i++) { | ||
if (!types[i].is(m[keys[i]])) { | ||
var k = keys[i]; | ||
if (!hasOwnProperty.call(m, k) || !types[i].is(m[k])) { | ||
return false; | ||
@@ -443,5 +445,11 @@ } | ||
var k = keys[i]; | ||
var ok = o[k]; | ||
if (!hasOwnProperty.call(a, k)) { | ||
if (a === o) { | ||
a = __assign({}, o); | ||
} | ||
a[k] = a[k]; | ||
} | ||
var ak = a[k]; | ||
var type_1 = types[i]; | ||
var validation = type_1.validate(ok, exports.appendContext(c, k, type_1)); | ||
var validation = type_1.validate(ak, exports.appendContext(c, k, type_1)); | ||
if (validation.isLeft()) { | ||
@@ -451,4 +459,4 @@ pushAll(errors, validation.value); | ||
else { | ||
var vok = validation.value; | ||
if (vok !== ok) { | ||
var vak = validation.value; | ||
if (vak !== ak) { | ||
/* istanbul ignore next */ | ||
@@ -458,3 +466,3 @@ if (a === o) { | ||
} | ||
a[k] = vok; | ||
a[k] = vak; | ||
} | ||
@@ -503,4 +511,44 @@ } | ||
} | ||
var partial = exports.type(partials); | ||
return new PartialType(name, partial.is, partial.validate, useIdentity(types, len) | ||
return new PartialType(name, function (m) { | ||
if (!exports.Dictionary.is(m)) { | ||
return false; | ||
} | ||
for (var i = 0; i < len; i++) { | ||
var k = keys[i]; | ||
if (!partials[k].is(m[k])) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
}, function (m, c) { | ||
var dictionaryValidation = exports.Dictionary.validate(m, c); | ||
if (dictionaryValidation.isLeft()) { | ||
return dictionaryValidation; | ||
} | ||
else { | ||
var o = dictionaryValidation.value; | ||
var a = o; | ||
var errors = []; | ||
for (var i = 0; i < len; i++) { | ||
var k = keys[i]; | ||
var ak = a[k]; | ||
var type_2 = partials[k]; | ||
var validation = type_2.validate(ak, exports.appendContext(c, k, type_2)); | ||
if (validation.isLeft()) { | ||
pushAll(errors, validation.value); | ||
} | ||
else { | ||
var vak = validation.value; | ||
if (vak !== ak) { | ||
/* istanbul ignore next */ | ||
if (a === o) { | ||
a = __assign({}, o); | ||
} | ||
a[k] = vak; | ||
} | ||
} | ||
} | ||
return errors.length ? exports.failures(errors) : exports.success(a); | ||
} | ||
}, useIdentity(types, len) | ||
? exports.identity | ||
@@ -608,4 +656,4 @@ : function (a) { | ||
for (var i = 0; i < len; i++) { | ||
var type_2 = types[i]; | ||
var validation = type_2.validate(m, exports.appendContext(c, String(i), type_2)); | ||
var type_3 = types[i]; | ||
var validation = type_3.validate(m, exports.appendContext(c, String(i), type_3)); | ||
if (validation.isRight()) { | ||
@@ -624,5 +672,5 @@ return validation; | ||
for (; i < len - 1; i++) { | ||
var type_3 = types[i]; | ||
if (type_3.is(a)) { | ||
return type_3.encode(a); | ||
var type_4 = types[i]; | ||
if (type_4.is(a)) { | ||
return type_4.encode(a); | ||
} | ||
@@ -654,4 +702,4 @@ } | ||
for (var i = 0; i < len; i++) { | ||
var type_4 = types[i]; | ||
var validation = type_4.validate(a, c); | ||
var type_5 = types[i]; | ||
var validation = type_5.validate(a, c); | ||
if (validation.isLeft()) { | ||
@@ -670,4 +718,4 @@ pushAll(errors, validation.value); | ||
for (var i = 0; i < len; i++) { | ||
var type_5 = types[i]; | ||
s = type_5.encode(s); | ||
var type_6 = types[i]; | ||
s = type_6.encode(s); | ||
} | ||
@@ -706,4 +754,4 @@ return s; | ||
var a = as[i]; | ||
var type_6 = types[i]; | ||
var validation = type_6.validate(a, exports.appendContext(c, String(i), type_6)); | ||
var type_7 = types[i]; | ||
var validation = type_7.validate(a, exports.appendContext(c, String(i), type_7)); | ||
if (validation.isLeft()) { | ||
@@ -810,3 +858,3 @@ pushAll(errors, validation.value); | ||
if (type instanceof InterfaceType || type instanceof StrictType) { | ||
return type.props.hasOwnProperty(tag); | ||
return hasOwnProperty.call(type.props, tag); | ||
} | ||
@@ -833,5 +881,5 @@ else if (type instanceof IntersectionType) { | ||
for (; i < len - 1; i++) { | ||
var type_7 = types[i]; | ||
if (is(type_7)) { | ||
return type_7; | ||
var type_8 = types[i]; | ||
if (is(type_8)) { | ||
return type_8; | ||
} | ||
@@ -884,3 +932,3 @@ } | ||
var isTagValue = useHash | ||
? function (m) { return exports.string.is(m) && hash.hasOwnProperty(m); } | ||
? function (m) { return exports.string.is(m) && hasOwnProperty.call(hash, m); } | ||
: function (m) { return values.indexOf(m) !== -1; }; | ||
@@ -918,4 +966,4 @@ var getIndex = useHash | ||
var i = getIndex(tagValueValidation.value); | ||
var type_8 = types[i]; | ||
return type_8.validate(d, exports.appendContext(c, String(i), type_8)); | ||
var type_9 = types[i]; | ||
return type_9.validate(d, exports.appendContext(c, String(i), type_9)); | ||
} | ||
@@ -955,3 +1003,3 @@ } | ||
var props = getProps(type); | ||
return new ExactType(name, function (m) { return type.is(m) && Object.getOwnPropertyNames(m).every(function (k) { return props.hasOwnProperty(k); }); }, function (m, c) { | ||
return new ExactType(name, function (m) { return type.is(m) && Object.getOwnPropertyNames(m).every(function (k) { return hasOwnProperty.call(props, k); }); }, function (m, c) { | ||
var looseValidation = type.validate(m, c); | ||
@@ -968,3 +1016,3 @@ if (looseValidation.isLeft()) { | ||
var key = keys[i]; | ||
if (!props.hasOwnProperty(key)) { | ||
if (!hasOwnProperty.call(props, key)) { | ||
errors.push(exports.getValidationError(o[key], exports.appendContext(c, key, exports.never))); | ||
@@ -971,0 +1019,0 @@ } |
{ | ||
"name": "io-ts", | ||
"version": "1.3.3", | ||
"version": "1.3.4", | ||
"description": "TypeScript compatible runtime type system for IO validation", | ||
@@ -5,0 +5,0 @@ "files": [ |
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
85735
1392