Comparing version 2.2.1 to 2.2.2
@@ -17,6 +17,20 @@ # Changelog | ||
# 2.2.2 | ||
- **Experimental** | ||
- add `Eq` module (@gcanti) | ||
- `Codec` | ||
- add `TypeOf` operator (@gcanti) | ||
- `Decoder` | ||
- add `DecodeError` interface (@gcanti) | ||
- `Encoder` | ||
- add `TypeOf` operator (@gcanti) | ||
- `Guard` | ||
- add `TypeOf` operator (@gcanti) | ||
# 2.2.1 | ||
- **Experimental** | ||
- collect all errors while decoding, closes #449 (@gcanti) | ||
- `Decoder` | ||
- collect all errors while decoding, closes #449 (@gcanti) | ||
@@ -23,0 +37,0 @@ # 2.2.0 |
@@ -5,4 +5,2 @@ /** | ||
import { Invariant1 } from 'fp-ts/es6/Invariant'; | ||
import { NonEmptyArray } from 'fp-ts/es6/NonEmptyArray'; | ||
import { Tree } from 'fp-ts/es6/Tree'; | ||
import * as D from './Decoder'; | ||
@@ -14,3 +12,3 @@ import * as E from './Encoder'; | ||
* | ||
* 1. `pipe(codec.decode(u), E.fold(() => u, codec.encode) = u` for all `u` in `unknown` | ||
* 1. `pipe(codec.decode(u), E.fold(() => u, codec.encode)) = u` for all `u` in `unknown` | ||
* 2. `codec.decode(codec.encode(a)) = E.right(a)` for all `a` in `A` | ||
@@ -23,2 +21,6 @@ * | ||
/** | ||
* @since 2.2.2 | ||
*/ | ||
export declare type TypeOf<C> = C extends Codec<infer A> ? A : never; | ||
/** | ||
* @since 2.2.0 | ||
@@ -54,3 +56,3 @@ */ | ||
*/ | ||
export declare function withExpected<A>(codec: Codec<A>, expected: (actual: unknown, nea: NonEmptyArray<Tree<string>>) => NonEmptyArray<Tree<string>>): Codec<A>; | ||
export declare function withExpected<A>(codec: Codec<A>, expected: (actual: unknown, e: D.DecodeError) => D.DecodeError): Codec<A>; | ||
/** | ||
@@ -57,0 +59,0 @@ * @since 2.2.0 |
@@ -12,6 +12,11 @@ /** | ||
/** | ||
* @since 2.2.2 | ||
*/ | ||
export interface DecodeError extends NonEmptyArray<Tree<string>> { | ||
} | ||
/** | ||
* @since 2.2.0 | ||
*/ | ||
export interface Decoder<A> { | ||
readonly decode: (u: unknown) => Either<NonEmptyArray<Tree<string>>, A>; | ||
readonly decode: (u: unknown) => Either<DecodeError, A>; | ||
} | ||
@@ -29,8 +34,12 @@ /** | ||
*/ | ||
export declare function success<A>(a: A): Either<NonEmptyArray<Tree<string>>, A>; | ||
export declare function success<A>(a: A): Either<DecodeError, A>; | ||
/** | ||
* @since 2.2.0 | ||
*/ | ||
export declare function failure<A = never>(message: string): Either<NonEmptyArray<Tree<string>>, A>; | ||
export declare function failure<A = never>(message: string): Either<DecodeError, A>; | ||
/** | ||
* @since 2.2.2 | ||
*/ | ||
export declare function isNotEmpty<A>(as: ReadonlyArray<A>): as is NonEmptyArray<A>; | ||
/** | ||
* @since 2.2.0 | ||
@@ -70,3 +79,3 @@ */ | ||
*/ | ||
export declare function withExpected<A>(decoder: Decoder<A>, expected: (actual: unknown, nea: NonEmptyArray<Tree<string>>) => NonEmptyArray<Tree<string>>): Decoder<A>; | ||
export declare function withExpected<A>(decoder: Decoder<A>, expected: (actual: unknown, e: DecodeError) => DecodeError): Decoder<A>; | ||
/** | ||
@@ -73,0 +82,0 @@ * @since 2.2.0 |
@@ -31,3 +31,6 @@ import { either, isLeft, isRight, left, mapLeft, right } from 'fp-ts/es6/Either'; | ||
} | ||
function isNotEmpty(as) { | ||
/** | ||
* @since 2.2.2 | ||
*/ | ||
export function isNotEmpty(as) { | ||
return as.length > 0; | ||
@@ -383,3 +386,3 @@ } | ||
else { | ||
var forest = [tree("member 0", e.left)]; | ||
var errors = [tree("member 0", e.left)]; | ||
for (var i = 1; i < len; i++) { | ||
@@ -391,6 +394,6 @@ var e_6 = members[i].decode(u); | ||
else { | ||
forest.push(tree("member " + i, e_6.left)); | ||
errors.push(tree("member " + i, e_6.left)); | ||
} | ||
} | ||
return left(forest); | ||
return left(errors); | ||
} | ||
@@ -397,0 +400,0 @@ } |
@@ -13,2 +13,6 @@ /** | ||
/** | ||
* @since 2.2.2 | ||
*/ | ||
export declare type TypeOf<E> = E extends Encoder<infer A> ? A : never; | ||
/** | ||
* @since 2.2.0 | ||
@@ -15,0 +19,0 @@ */ |
@@ -12,2 +12,6 @@ /** | ||
/** | ||
* @since 2.2.2 | ||
*/ | ||
export declare type TypeOf<G> = G extends Guard<infer A> ? A : never; | ||
/** | ||
* @since 2.2.0 | ||
@@ -14,0 +18,0 @@ */ |
@@ -0,9 +1,5 @@ | ||
import { DecodeError } from './Decoder'; | ||
/** | ||
* @since 2.2.0 | ||
*/ | ||
import { Tree } from 'fp-ts/es6/Tree'; | ||
import { NonEmptyArray } from 'fp-ts/es6/NonEmptyArray'; | ||
/** | ||
* @since 2.2.0 | ||
*/ | ||
export declare function draw(es: NonEmptyArray<Tree<string>>): string; | ||
export declare function draw(e: DecodeError): string; |
@@ -8,4 +8,4 @@ /** | ||
*/ | ||
export function draw(es) { | ||
return es.map(drawTree).join('\n'); | ||
export function draw(e) { | ||
return e.map(drawTree).join('\n'); | ||
} |
@@ -5,4 +5,2 @@ /** | ||
import { Invariant1 } from 'fp-ts/lib/Invariant'; | ||
import { NonEmptyArray } from 'fp-ts/lib/NonEmptyArray'; | ||
import { Tree } from 'fp-ts/lib/Tree'; | ||
import * as D from './Decoder'; | ||
@@ -14,3 +12,3 @@ import * as E from './Encoder'; | ||
* | ||
* 1. `pipe(codec.decode(u), E.fold(() => u, codec.encode) = u` for all `u` in `unknown` | ||
* 1. `pipe(codec.decode(u), E.fold(() => u, codec.encode)) = u` for all `u` in `unknown` | ||
* 2. `codec.decode(codec.encode(a)) = E.right(a)` for all `a` in `A` | ||
@@ -23,2 +21,6 @@ * | ||
/** | ||
* @since 2.2.2 | ||
*/ | ||
export declare type TypeOf<C> = C extends Codec<infer A> ? A : never; | ||
/** | ||
* @since 2.2.0 | ||
@@ -54,3 +56,3 @@ */ | ||
*/ | ||
export declare function withExpected<A>(codec: Codec<A>, expected: (actual: unknown, nea: NonEmptyArray<Tree<string>>) => NonEmptyArray<Tree<string>>): Codec<A>; | ||
export declare function withExpected<A>(codec: Codec<A>, expected: (actual: unknown, e: D.DecodeError) => D.DecodeError): Codec<A>; | ||
/** | ||
@@ -57,0 +59,0 @@ * @since 2.2.0 |
@@ -12,6 +12,11 @@ /** | ||
/** | ||
* @since 2.2.2 | ||
*/ | ||
export interface DecodeError extends NonEmptyArray<Tree<string>> { | ||
} | ||
/** | ||
* @since 2.2.0 | ||
*/ | ||
export interface Decoder<A> { | ||
readonly decode: (u: unknown) => Either<NonEmptyArray<Tree<string>>, A>; | ||
readonly decode: (u: unknown) => Either<DecodeError, A>; | ||
} | ||
@@ -29,8 +34,12 @@ /** | ||
*/ | ||
export declare function success<A>(a: A): Either<NonEmptyArray<Tree<string>>, A>; | ||
export declare function success<A>(a: A): Either<DecodeError, A>; | ||
/** | ||
* @since 2.2.0 | ||
*/ | ||
export declare function failure<A = never>(message: string): Either<NonEmptyArray<Tree<string>>, A>; | ||
export declare function failure<A = never>(message: string): Either<DecodeError, A>; | ||
/** | ||
* @since 2.2.2 | ||
*/ | ||
export declare function isNotEmpty<A>(as: ReadonlyArray<A>): as is NonEmptyArray<A>; | ||
/** | ||
* @since 2.2.0 | ||
@@ -70,3 +79,3 @@ */ | ||
*/ | ||
export declare function withExpected<A>(decoder: Decoder<A>, expected: (actual: unknown, nea: NonEmptyArray<Tree<string>>) => NonEmptyArray<Tree<string>>): Decoder<A>; | ||
export declare function withExpected<A>(decoder: Decoder<A>, expected: (actual: unknown, e: DecodeError) => DecodeError): Decoder<A>; | ||
/** | ||
@@ -73,0 +82,0 @@ * @since 2.2.0 |
@@ -36,5 +36,9 @@ "use strict"; | ||
exports.failure = failure; | ||
/** | ||
* @since 2.2.2 | ||
*/ | ||
function isNotEmpty(as) { | ||
return as.length > 0; | ||
} | ||
exports.isNotEmpty = isNotEmpty; | ||
/** | ||
@@ -403,3 +407,3 @@ * @since 2.2.0 | ||
else { | ||
var forest = [tree("member 0", e.left)]; | ||
var errors = [tree("member 0", e.left)]; | ||
for (var i = 1; i < len; i++) { | ||
@@ -411,6 +415,6 @@ var e_6 = members[i].decode(u); | ||
else { | ||
forest.push(tree("member " + i, e_6.left)); | ||
errors.push(tree("member " + i, e_6.left)); | ||
} | ||
} | ||
return Either_1.left(forest); | ||
return Either_1.left(errors); | ||
} | ||
@@ -417,0 +421,0 @@ } |
@@ -13,2 +13,6 @@ /** | ||
/** | ||
* @since 2.2.2 | ||
*/ | ||
export declare type TypeOf<E> = E extends Encoder<infer A> ? A : never; | ||
/** | ||
* @since 2.2.0 | ||
@@ -15,0 +19,0 @@ */ |
@@ -12,2 +12,6 @@ /** | ||
/** | ||
* @since 2.2.2 | ||
*/ | ||
export declare type TypeOf<G> = G extends Guard<infer A> ? A : never; | ||
/** | ||
* @since 2.2.0 | ||
@@ -14,0 +18,0 @@ */ |
@@ -0,9 +1,5 @@ | ||
import { DecodeError } from './Decoder'; | ||
/** | ||
* @since 2.2.0 | ||
*/ | ||
import { Tree } from 'fp-ts/lib/Tree'; | ||
import { NonEmptyArray } from 'fp-ts/lib/NonEmptyArray'; | ||
/** | ||
* @since 2.2.0 | ||
*/ | ||
export declare function draw(es: NonEmptyArray<Tree<string>>): string; | ||
export declare function draw(e: DecodeError): string; |
@@ -10,5 +10,5 @@ "use strict"; | ||
*/ | ||
function draw(es) { | ||
return es.map(Tree_1.drawTree).join('\n'); | ||
function draw(e) { | ||
return e.map(Tree_1.drawTree).join('\n'); | ||
} | ||
exports.draw = draw; |
{ | ||
"name": "io-ts", | ||
"version": "2.2.1", | ||
"version": "2.2.2", | ||
"description": "TypeScript runtime type system for IO decoding/encoding", | ||
@@ -18,3 +18,3 @@ "files": [ | ||
"fix-prettier": "prettier --no-semi --single-quote --print-width 120 --parser typescript --write \"{src,test,examples,exercises}/**/*.ts\"", | ||
"test": "npm run prettier && npm run lint && npm run dtslint && npm run declaration && npm run jest && npm run docs", | ||
"test": "npm run prettier && npm run lint && npm run dtslint && npm run jest && npm run docs", | ||
"clean": "rimraf lib/* es6/*", | ||
@@ -25,5 +25,4 @@ "build": "npm run clean && tsc && tsc -p tsconfig.es6.json && npm run import-path-rewrite", | ||
"dtslint": "dtslint dtslint", | ||
"declaration": "tsc -p declaration/tsconfig.json", | ||
"mocha": "TS_NODE_CACHE=false mocha -r ts-node/register test/*.ts", | ||
"doctoc": "doctoc README.md Type.md Decoder.md Encoder.md Codec.md", | ||
"doctoc": "doctoc README.md Type.md Decoder.md Encoder.md Codec.md Eq.md", | ||
"docs": "docs-ts", | ||
@@ -54,2 +53,3 @@ "import-path-rewrite": "import-path-rewrite" | ||
"dtslint": "github:gcanti/dtslint", | ||
"fast-check": "^1.24.2", | ||
"fp-ts": "2.5.3", | ||
@@ -56,0 +56,0 @@ "import-path-rewrite": "github:gcanti/import-path-rewrite", |
@@ -11,2 +11,3 @@ [![build status](https://img.shields.io/travis/gcanti/io-ts/master.svg?style=flat-square)](https://travis-ci.org/gcanti/io-ts) | ||
- [Documentation](#documentation) | ||
- [Usage](#usage) | ||
@@ -31,11 +32,14 @@ <!-- END doctoc generated TOC please keep comment here to allow auto update --> | ||
**Stable features** | ||
- [`Type`](Type.md) | ||
**Experimental features** (version `2.2+`) | ||
Experimental features are published in order to get early feedback from the community, see these tracking [issues](https://github.com/gcanti/io-ts/issues?q=label%3Av2.2+) for further discussions and enhancements. | ||
- [`Decoder`](Decoder.md) | ||
- [`Encoder`](Encoder.md) | ||
- [`Codec`](Codec.md) | ||
- [`Eq`](Eq.md) | ||
- [`Schema` (advanced feature)](Schema.md) | ||
**Stable** (old) | ||
- [`Type`](Type.md) |
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
269104
52
9197
44
19