Comparing version 1.0.3 to 1.0.4
@@ -16,6 +16,13 @@ # Changelog | ||
# 1.0.4 | ||
* **Bug Fix** | ||
* make `Context` readonly (@gcanti) | ||
* **Internal** | ||
* optimizations, #137 (@gcanti, @sledorze) | ||
# 1.0.3 | ||
* **Internal** | ||
* optimizations, https://github.com/gcanti/io-ts/pull/134 (@gcanti, @sledorze) | ||
* optimizations, #134 (@gcanti, @sledorze) | ||
@@ -22,0 +29,0 @@ # 1.0.2 |
@@ -13,3 +13,3 @@ import { Either } from 'fp-ts/lib/Either'; | ||
} | ||
export declare type Context = Array<ContextEntry>; | ||
export declare type Context = ReadonlyArray<ContextEntry>; | ||
export interface ValidationError { | ||
@@ -75,7 +75,7 @@ readonly value: mixed; | ||
export declare const getContextEntry: (key: string, type: Decoder<any, any>) => ContextEntry; | ||
export declare const getValidationError: (value: mixed, context: ContextEntry[]) => ValidationError; | ||
export declare const getDefaultContext: (type: Decoder<any, any>) => ContextEntry[]; | ||
export declare const appendContext: (c: ContextEntry[], key: string, type: Decoder<any, any>) => ContextEntry[]; | ||
export declare const getValidationError: (value: mixed, context: ReadonlyArray<ContextEntry>) => ValidationError; | ||
export declare const getDefaultContext: (type: Decoder<any, any>) => ReadonlyArray<ContextEntry>; | ||
export declare const appendContext: (c: ReadonlyArray<ContextEntry>, key: string, type: Decoder<any, any>) => ReadonlyArray<ContextEntry>; | ||
export declare const failures: <T>(errors: ValidationError[]) => Either<ValidationError[], T>; | ||
export declare const failure: <T>(value: mixed, context: ContextEntry[]) => Either<ValidationError[], T>; | ||
export declare const failure: <T>(value: mixed, context: ReadonlyArray<ContextEntry>) => Either<ValidationError[], T>; | ||
export declare const success: <T>(value: T) => Either<ValidationError[], T>; | ||
@@ -82,0 +82,0 @@ export declare class NullType extends Type<null> { |
@@ -390,5 +390,5 @@ "use strict"; | ||
}; | ||
var useIdentity = function (props) { | ||
for (var k in props) { | ||
if (props[k].encode !== exports.identity) { | ||
var useIdentity = function (types, len) { | ||
for (var i = 0; i < len; i++) { | ||
if (types[i].encode !== exports.identity) { | ||
return false; | ||
@@ -402,2 +402,5 @@ } | ||
if (name === void 0) { name = getNameFromProps(props); } | ||
var keys = Object.keys(props); | ||
var types = keys.map(function (key) { return props[key]; }); | ||
var len = keys.length; | ||
return new InterfaceType(name, function (m) { | ||
@@ -407,4 +410,4 @@ if (!exports.Dictionary.is(m)) { | ||
} | ||
for (var k in props) { | ||
if (!props[k].is(m[k])) { | ||
for (var i = 0; i < len; i++) { | ||
if (!types[i].is(m[keys[i]])) { | ||
return false; | ||
@@ -423,5 +426,6 @@ } | ||
var errors = []; | ||
for (var k in props) { | ||
for (var i = 0; i < len; i++) { | ||
var k = keys[i]; | ||
var ok = o[k]; | ||
var type_1 = props[k]; | ||
var type_1 = types[i]; | ||
var validation = type_1.validate(ok, exports.appendContext(c, k, type_1)); | ||
@@ -443,8 +447,9 @@ if (validation.isLeft()) { | ||
} | ||
}, useIdentity(props) | ||
}, useIdentity(types, len) | ||
? exports.identity | ||
: function (a) { | ||
var s = __assign({}, a); | ||
for (var k in props) { | ||
s[k] = props[k].encode(a[k]); | ||
for (var i = 0; i < len; i++) { | ||
var k = keys[i]; | ||
s[k] = types[i].encode(a[k]); | ||
} | ||
@@ -471,15 +476,19 @@ return s; | ||
if (name === void 0) { name = "PartialType<" + getNameFromProps(props) + ">"; } | ||
var keys = Object.keys(props); | ||
var types = keys.map(function (key) { return props[key]; }); | ||
var len = keys.length; | ||
var partials = {}; | ||
for (var k in props) { | ||
partials[k] = exports.union([props[k], undefinedType]); | ||
for (var i = 0; i < len; i++) { | ||
partials[keys[i]] = exports.union([types[i], undefinedType]); | ||
} | ||
var partial = exports.type(partials); | ||
return new PartialType(name, partial.is, partial.validate, useIdentity(props) | ||
return new PartialType(name, partial.is, partial.validate, useIdentity(types, len) | ||
? exports.identity | ||
: function (a) { | ||
var s = {}; | ||
for (var k in props) { | ||
for (var i = 0; i < len; i++) { | ||
var k = keys[i]; | ||
var ak = a[k]; | ||
if (ak !== undefined) { | ||
s[k] = props[k].encode(ak); | ||
s[k] = types[i].encode(ak); | ||
} | ||
@@ -518,4 +527,7 @@ } | ||
var errors = []; | ||
var keys = Object.keys(o); | ||
var len = keys.length; | ||
var changed = false; | ||
for (var k in o) { | ||
for (var i = 0; i < len; i++) { | ||
var k = keys[i]; | ||
var ok = o[k]; | ||
@@ -547,3 +559,6 @@ var domainValidation = domain.validate(k, exports.appendContext(c, k, domain)); | ||
var s = {}; | ||
for (var k in a) { | ||
var keys = Object.keys(a); | ||
var len = keys.length; | ||
for (var i = 0; i < len; i++) { | ||
var k = keys[i]; | ||
s[String(domain.encode(k))] = codomain.encode(a[k]); | ||
@@ -550,0 +565,0 @@ } |
{ | ||
"name": "io-ts", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "TypeScript compatible runtime type system for IO validation", | ||
@@ -5,0 +5,0 @@ "files": ["lib"], |
Sorry, the diff of this file is not supported yet
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
107982
1202