Socket
Socket
Sign inDemoInstall

io-ts

Package Overview
Dependencies
Maintainers
1
Versions
120
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

io-ts - npm Package Compare versions

Comparing version 0.9.5 to 0.9.6

7

CHANGELOG.md

@@ -16,2 +16,9 @@ # Changelog

# 0.9.6
* **New Feature**
* `recursive` combinator
* add support for mutually recursive types, closes #114 (@gcanti)
* make it safer: `RT` now must extend `Type<mixed, A>` (@gcanti)
# 0.9.5

@@ -18,0 +25,0 @@

19

lib/index.d.ts

@@ -35,4 +35,6 @@ import { Either } from 'fp-ts/lib/Either';

* Laws:
* 1. validate(x).fold(() => x, serialize) = x
* 2. validate(serialize(x)) = Right(x)
* 1. validate(x, T).fold(() => x, T.serialize) = x
* 2. validate(T.serialize(x), T) = Right(x)
*
* where `T` is a runtime type
*/

@@ -84,3 +86,3 @@ export declare class Type<S, A> implements Decoder<S, A>, Encoder<S, A> {

declare const undefinedType: UndefinedType;
export declare class AnyType extends Type<mixed, any> {
export declare class AnyType extends Type<any, any> {
readonly _tag: 'AnyType';

@@ -157,7 +159,8 @@ constructor();

export declare class RecursiveType<RT extends Any, A> extends Type<mixed, A> {
private runDefinition;
readonly _tag: 'RecursiveType';
readonly 'type': RT;
constructor(name: string, is: RecursiveType<RT, A>['is'], validate: RecursiveType<RT, A>['validate'], serialize: RecursiveType<RT, A>['serialize']);
constructor(name: string, is: RecursiveType<RT, A>['is'], validate: RecursiveType<RT, A>['validate'], serialize: RecursiveType<RT, A>['serialize'], runDefinition: () => RT);
readonly type: RT;
}
export declare const recursion: <A, RT extends Type<mixed, any> = Type<mixed, any>>(name: string, definition: (self: RT) => RT) => RecursiveType<RT, A>;
export declare const recursion: <A, RT extends Type<mixed, A> = Type<mixed, A>>(name: string, definition: (self: RT) => RT) => RecursiveType<RT, A>;
export declare class ArrayType<RT extends Any, A> extends Type<mixed, A> {

@@ -209,3 +212,3 @@ readonly type: RT;

readonly _tag: 'IntersectionType';
constructor(name: string, is: Is<A>, validate: Validate<mixed, A>, serialize: Serialize<mixed, A>, types: RTS);
constructor(name: string, is: IntersectionType<RTS, A>['is'], validate: IntersectionType<RTS, A>['validate'], serialize: IntersectionType<RTS, A>['serialize'], types: RTS);
}

@@ -220,3 +223,3 @@ export declare function intersection<A extends Any, B extends Any, C extends Any, D extends Any, E extends Any>(types: [A, B, C, D, E], name?: string): IntersectionType<[A, B, C, D, E], TypeOf<A> & TypeOf<B> & TypeOf<C> & TypeOf<D> & TypeOf<E>>;

readonly _tag: 'TupleType';
constructor(name: string, is: Is<A>, validate: Validate<mixed, A>, serialize: Serialize<mixed, A>, types: RTS);
constructor(name: string, is: TupleType<RTS, A>['is'], validate: TupleType<RTS, A>['validate'], serialize: TupleType<RTS, A>['serialize'], types: RTS);
}

@@ -223,0 +226,0 @@ export declare function tuple<A extends Any, B extends Any, C extends Any, D extends Any, E extends Any>(types: [A, B, C, D, E], name?: string): TupleType<[A, B, C, D, E], [TypeOf<A>, TypeOf<B>, TypeOf<C>, TypeOf<D>, TypeOf<E>]>;

@@ -24,4 +24,6 @@ "use strict";

* Laws:
* 1. validate(x).fold(() => x, serialize) = x
* 2. validate(serialize(x)) = Right(x)
* 1. validate(x, T).fold(() => x, T.serialize) = x
* 2. validate(T.serialize(x), T) = Right(x)
*
* where `T` is a runtime type
*/

@@ -276,7 +278,15 @@ var Type = /** @class */ (function () {

__extends(RecursiveType, _super);
function RecursiveType(name, is, validate, serialize) {
function RecursiveType(name, is, validate, serialize, runDefinition) {
var _this = _super.call(this, name, is, validate, serialize) || this;
_this.runDefinition = runDefinition;
_this._tag = 'RecursiveType';
return _this;
}
Object.defineProperty(RecursiveType.prototype, "type", {
get: function () {
return this.runDefinition();
},
enumerable: true,
configurable: true
});
return RecursiveType;

@@ -286,6 +296,10 @@ }(Type));

exports.recursion = function (name, definition) {
var Self = new RecursiveType(name, function (v) { return type.is(v); }, function (s, c) { return type.validate(s, c); }, exports.identity);
var type = definition(Self);
Self.type = type;
Self.serialize = type.serialize;
var cache;
var runDefinition = function () {
if (!cache) {
cache = definition(Self);
}
return cache;
};
var Self = new RecursiveType(name, function (m) { return runDefinition().is(m); }, function (m, c) { return runDefinition().validate(m, c); }, function (a) { return runDefinition().serialize(a); }, runDefinition);
return Self;

@@ -292,0 +306,0 @@ };

{
"name": "io-ts",
"version": "0.9.5",
"version": "0.9.6",
"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

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc