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 2.2.6 to 2.2.7

es6/DecodeError.d.ts

27

CHANGELOG.md

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

# 2.2.7
- **Experimental**
- add `DecodeError` module (@gcanti)
- add `FreeSemigroup` module (@gcanti)
- add `TaskDecoder` module (@gcanti)
- add `Kleisli` module (@gcanti)
- add `KleisliDecoder` module (@gcanti)
- add `KleisliTaskDecoder` module (@gcanti)
- (\*) remove `NaN` from `number` instances (@gcanti)
- (\*) remove `Tree` module (@gcanti)
- (\*) make `Json` type immutable (@gcanti)
- `Decoder`
- (\*) remove `never` (@gcanti)
- (\*) make `parse` pipeable and change its `parser` argument (@gcanti)
- (\*) change `DecoderError` (@gcanti)
- (\*) remove `withExpected` in favour of `mapLeftWithInput` (@gcanti)
- `Guard`
- (\*) remove `never` (@gcanti)
- `Schemable`
- (\*) better `literal` signature (@gcanti)
- (\*) better `union` signature (@gcanti)
- (\*) make intersections pipeables (@gcanti)
- (\*) make refinements pipeables (@gcanti)
(\*) breaking change
# 2.2.6

@@ -19,0 +46,0 @@

15

es6/Codec.d.ts
/**
* **This module is experimental**
*
* 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.
*
* A feature tagged as _Experimental_ is in a high state of flux, you're at risk of it changing without notice.
*
* @since 2.2.3

@@ -41,3 +48,3 @@ */

*/
export declare function literal<A extends ReadonlyArray<Literal>>(...values: A): Codec<A[number], A[number]>;
export declare function literal<A extends readonly [Literal, ...Array<Literal>]>(...values: A): Codec<A[number], A[number]>;
/**

@@ -72,3 +79,3 @@ * @category primitives

*/
export declare function withExpected<O, A>(codec: Codec<O, A>, expected: (actual: unknown, e: D.DecodeError) => D.DecodeError): Codec<O, A>;
export declare const mapLeftWithInput: (f: (actual: unknown, e: D.DecodeError) => D.DecodeError) => <O, A>(codec: Codec<O, A>) => Codec<O, A>;
/**

@@ -78,3 +85,3 @@ * @category combinators

*/
export declare function refinement<O, A, B extends A>(from: Codec<O, A>, refinement: (a: A) => a is B, expected: string): Codec<O, B>;
export declare const refine: <A, B extends A>(refinement: (a: A) => a is B, id: string) => <O>(from: Codec<O, A>) => Codec<O, B>;
/**

@@ -126,3 +133,3 @@ * @category combinators

*/
export declare function intersection<O, A, P, B>(left: Codec<O, A>, right: Codec<P, B>): Codec<O & P, A & B>;
export declare const intersect: <P, B>(right: Codec<P, B>) => <O, A>(left: Codec<O, A>) => Codec<O & P, A & B>;
/**

@@ -129,0 +136,0 @@ * @category combinators

import * as D from './Decoder';
import * as E from './Encoder';
import { identity } from 'fp-ts/es6/function';
import { pipe } from 'fp-ts/es6/pipeable';
// -------------------------------------------------------------------------------------

@@ -73,5 +74,3 @@ // constructors

*/
export function withExpected(codec, expected) {
return make(D.withExpected(codec, expected), codec);
}
export var mapLeftWithInput = function (f) { return function (codec) { return make(pipe(codec, D.mapLeftWithInput(f)), codec); }; };
/**

@@ -81,5 +80,6 @@ * @category combinators

*/
export function refinement(from, refinement, expected) {
return make(D.refinement(from, refinement, expected), from);
}
export var refine = function (refinement, id) {
var refine = D.refine(refinement, id);
return function (from) { return make(refine(from), from); };
};
/**

@@ -140,5 +140,7 @@ * @category combinators

*/
export function intersection(left, right) {
return make(D.intersection(left, right), E.intersection(left, right));
}
export var intersect = function (right) {
var intersectD = D.intersect(right);
var intersectE = E.intersect(right);
return function (left) { return make(intersectD(left), intersectE(left)); };
};
/**

@@ -145,0 +147,0 @@ * @category combinators

/**
* @since 2.2.0
* **This module is experimental**
*
* 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.
*
* A feature tagged as _Experimental_ is in a high state of flux, you're at risk of it changing without notice.
*
* @since 2.2.7
*/
import { Alt1 } from 'fp-ts/es6/Alt';
import * as E from 'fp-ts/es6/Either';
import { NonEmptyArray } from 'fp-ts/es6/NonEmptyArray';
import { Forest, Tree } from 'fp-ts/es6/Tree';
import { Functor1 } from 'fp-ts/es6/Functor';
import * as G from './Guard';
import { Literal, Schemable1, WithRefinement1, WithUnion1, WithUnknownContainers1 } from './Schemable';
import { Functor1 } from 'fp-ts/es6/Functor';
import { Alt1 } from 'fp-ts/es6/Alt';
import Either = E.Either;
import * as KD from './KleisliDecoder';
import { Literal, Schemable1, WithRefine1, WithUnion1, WithUnknownContainers1 } from './Schemable';
/**
* @category model
* @since 2.2.0
* @since 2.2.7
*/
export interface Decoder<A> {
readonly decode: (u: unknown) => Either<DecodeError, A>;
export interface Decoder<A> extends KD.KleisliDecoder<unknown, A> {
}
/**
* @since 2.2.0
*/
export declare type TypeOf<D> = D extends Decoder<infer A> ? A : never;
/**
* @category DecodeError
* @since 2.2.2
* @since 2.2.7
*/
export interface DecodeError extends NonEmptyArray<Tree<string>> {
}
export declare type DecodeError = KD.DecodeError;
/**
* @category DecodeError
* @since 2.2.0
* @since 2.2.7
*/
export declare function tree<A>(value: A, forest?: Forest<A>): Tree<A>;
export declare const error: (actual: unknown, message: string) => DecodeError;
/**
* @category DecodeError
* @since 2.2.0
* @since 2.2.7
*/
export declare function success<A>(a: A): Either<DecodeError, A>;
export declare const success: <A>(a: A) => E.Either<DecodeError, A>;
/**
* @category DecodeError
* @since 2.2.0
* @since 2.2.7
*/
export declare function failure<A = never>(message: string): Either<DecodeError, A>;
export declare const failure: <A = never>(actual: unknown, message: string) => E.Either<DecodeError, A>;
/**
* @category DecodeError
* @since 2.2.2
*/
export declare function isNotEmpty<A>(as: ReadonlyArray<A>): as is NonEmptyArray<A>;
/**
* @category constructors
* @since 2.2.3
* @since 2.2.7
*/
export declare function of<A>(a: A): Decoder<A>;
export declare const fromGuard: <A>(guard: G.Guard<A>, expected: string) => Decoder<A>;
/**
* @category constructors
* @since 2.2.0
* @since 2.2.7
*/
export declare function fromGuard<A>(guard: G.Guard<A>, expected: string): Decoder<A>;
export declare const literal: <A extends readonly [Literal, ...Array<Literal>]>(...values: A) => Decoder<A[number]>;
/**
* @category constructors
* @since 2.2.0
*/
export declare function literal<A extends ReadonlyArray<Literal>>(...values: A): Decoder<A[number]>;
/**
* @category primitives
* @since 2.2.0
* @since 2.2.7
*/
export declare const never: Decoder<never>;
/**
* @category primitives
* @since 2.2.0
*/
export declare const string: Decoder<string>;
/**
* @category primitives
* @since 2.2.0
* @since 2.2.7
*/

@@ -81,3 +65,3 @@ export declare const number: Decoder<number>;

* @category primitives
* @since 2.2.0
* @since 2.2.7
*/

@@ -87,3 +71,3 @@ export declare const boolean: Decoder<boolean>;

* @category primitives
* @since 2.2.0
* @since 2.2.7
*/

@@ -93,3 +77,3 @@ export declare const UnknownArray: Decoder<Array<unknown>>;

* @category primitives
* @since 2.2.0
* @since 2.2.7
*/

@@ -99,82 +83,75 @@ export declare const UnknownRecord: Decoder<Record<string, unknown>>;

* @category combinators
* @since 2.2.0
* @since 2.2.7
*/
export declare function withExpected<A>(decoder: Decoder<A>, expected: (actual: unknown, e: DecodeError) => DecodeError): Decoder<A>;
export declare const mapLeftWithInput: (f: (input: unknown, e: DecodeError) => DecodeError) => <A>(decoder: Decoder<A>) => Decoder<A>;
/**
* @category combinators
* @since 2.2.0
* @since 2.2.7
*/
export declare function refinement<A, B extends A>(from: Decoder<A>, refinement: (a: A) => a is B, expected: string): Decoder<B>;
export declare const refine: <A, B extends A>(refinement: (a: A) => a is B, id: string) => (from: Decoder<A>) => Decoder<B>;
/**
* @category combinators
* @since 2.2.0
* @since 2.2.7
*/
export declare function parse<A, B>(from: Decoder<A>, parser: (a: A) => Either<string, B>): Decoder<B>;
export declare const parse: <A, B>(parser: (a: A) => E.Either<DecodeError, B>) => (from: Decoder<A>) => Decoder<B>;
/**
* @category combinators
* @since 2.2.0
* @since 2.2.7
*/
export declare function nullable<A>(or: Decoder<A>): Decoder<null | A>;
export declare const nullable: <A>(or: Decoder<A>) => Decoder<null | A>;
/**
* @category combinators
* @since 2.2.0
* @since 2.2.7
*/
export declare function type<A>(properties: {
[K in keyof A]: Decoder<A[K]>;
}): Decoder<{
[K in keyof A]: A[K];
}>;
export declare const type: <A>(properties: { [K in keyof A]: Decoder<A[K]>; }) => Decoder<{ [K_1 in keyof A]: A[K_1]; }>;
/**
* @category combinators
* @since 2.2.0
* @since 2.2.7
*/
export declare function partial<A>(properties: {
[K in keyof A]: Decoder<A[K]>;
}): Decoder<Partial<{
[K in keyof A]: A[K];
}>>;
export declare const partial: <A>(properties: { [K in keyof A]: Decoder<A[K]>; }) => Decoder<Partial<{ [K_1 in keyof A]: A[K_1]; }>>;
/**
* @category combinators
* @since 2.2.0
* @since 2.2.7
*/
export declare function record<A>(codomain: Decoder<A>): Decoder<Record<string, A>>;
export declare const array: <A>(items: Decoder<A>) => Decoder<A[]>;
/**
* @category combinators
* @since 2.2.0
* @since 2.2.7
*/
export declare function array<A>(items: Decoder<A>): Decoder<Array<A>>;
export declare const record: <A>(codomain: Decoder<A>) => Decoder<Record<string, A>>;
/**
* @category combinators
* @since 2.2.0
* @since 2.2.7
*/
export declare function tuple<A extends ReadonlyArray<unknown>>(...components: {
export declare const tuple: <A extends readonly unknown[]>(...components: { [K in keyof A]: Decoder<A[K]>; }) => Decoder<A>;
/**
* @category combinators
* @since 2.2.7
*/
export declare const union: <A extends readonly [unknown, ...Array<unknown>]>(...members: {
[K in keyof A]: Decoder<A[K]>;
}): Decoder<A>;
}) => Decoder<A[number]>;
/**
* @category combinators
* @since 2.2.0
* @since 2.2.7
*/
export declare function intersection<A, B>(left: Decoder<A>, right: Decoder<B>): Decoder<A & B>;
export declare const intersect: <B>(right: Decoder<B>) => <A>(left: Decoder<A>) => Decoder<A & B>;
/**
* @category combinators
* @since 2.2.0
* @since 2.2.7
*/
export declare function lazy<A>(id: string, f: () => Decoder<A>): Decoder<A>;
export declare const sum: <T extends string>(tag: T) => <A>(members: { [K in keyof A]: Decoder<A[K]>; }) => Decoder<A[keyof A]>;
/**
* @category combinators
* @since 2.2.0
* @since 2.2.7
*/
export declare function sum<T extends string>(tag: T): <A>(members: {
[K in keyof A]: Decoder<A[K]>;
}) => Decoder<A[keyof A]>;
export declare const lazy: <A>(id: string, f: () => Decoder<A>) => Decoder<A>;
/**
* @category combinators
* @since 2.2.0
* @since 2.2.7
*/
export declare function union<A extends ReadonlyArray<unknown>>(...members: {
[K in keyof A]: Decoder<A[K]>;
}): Decoder<A[number]>;
export declare const compose: <A, B>(to: KD.KleisliDecoder<A, B>) => (from: Decoder<A>) => Decoder<B>;
/**
* @category Functor
* @since 2.2.0
* @since 2.2.7
*/

@@ -184,8 +161,8 @@ export declare const map: <A, B>(f: (a: A) => B) => (fa: Decoder<A>) => Decoder<B>;

* @category Alt
* @since 2.2.0
* @since 2.2.7
*/
export declare const alt: <A>(that: () => Decoder<A>) => (fa: Decoder<A>) => Decoder<A>;
export declare const alt: <A>(that: () => Decoder<A>) => (me: Decoder<A>) => Decoder<A>;
/**
* @category instances
* @since 2.2.0
* @since 2.2.7
*/

@@ -195,3 +172,3 @@ export declare const URI = "io-ts/Decoder";

* @category instances
* @since 2.2.0
* @since 2.2.7
*/

@@ -206,3 +183,3 @@ export declare type URI = typeof URI;

* @category instances
* @since 2.2.3
* @since 2.2.7
*/

@@ -212,3 +189,3 @@ export declare const functorDecoder: Functor1<URI>;

* @category instances
* @since 2.2.3
* @since 2.2.7
*/

@@ -218,4 +195,12 @@ export declare const altDecoder: Alt1<URI>;

* @category instances
* @since 2.2.3
* @since 2.2.7
*/
export declare const schemableDecoder: Schemable1<URI> & WithUnknownContainers1<URI> & WithUnion1<URI> & WithRefinement1<URI>;
export declare const schemableDecoder: Schemable1<URI> & WithUnknownContainers1<URI> & WithUnion1<URI> & WithRefine1<URI>;
/**
* @since 2.2.7
*/
export declare type TypeOf<D> = KD.TypeOf<D>;
/**
* @since 2.2.7
*/
export declare const draw: (e: DecodeError) => string;

@@ -1,41 +0,22 @@

/**
* @since 2.2.0
*/
import * as E from 'fp-ts/es6/Either';
import { pipe } from 'fp-ts/es6/pipeable';
import * as DE from './DecodeError';
import * as FS from './FreeSemigroup';
import * as G from './Guard';
import { memoize } from './Schemable';
var empty = [];
import * as KD from './KleisliDecoder';
/**
* @category DecodeError
* @since 2.2.0
* @since 2.2.7
*/
export function tree(value, forest) {
if (forest === void 0) { forest = empty; }
return {
value: value,
forest: forest
};
}
export var error = KD.error;
/**
* @category DecodeError
* @since 2.2.0
* @since 2.2.7
*/
export function success(a) {
return E.right(a);
}
export var success = KD.success;
/**
* @category DecodeError
* @since 2.2.0
* @since 2.2.7
*/
export function failure(message) {
return E.left([tree(message)]);
}
/**
* @category DecodeError
* @since 2.2.2
*/
export function isNotEmpty(as) {
return as.length > 0;
}
export var failure = KD.failure;
// -------------------------------------------------------------------------------------

@@ -46,34 +27,10 @@ // constructors

* @category constructors
* @since 2.2.3
* @since 2.2.7
*/
export function of(a) {
return {
decode: function () { return success(a); }
};
}
export var fromGuard = function (guard, expected) { return KD.fromRefinement(guard.is, expected); };
/**
* @category constructors
* @since 2.2.0
* @since 2.2.7
*/
export function fromGuard(guard, expected) {
return {
decode: function (u) { return (guard.is(u) ? success(u) : failure("cannot decode " + JSON.stringify(u) + ", should be " + expected)); }
};
}
/**
* @category constructors
* @since 2.2.0
*/
export function literal() {
var _a;
var values = [];
for (var _i = 0; _i < arguments.length; _i++) {
values[_i] = arguments[_i];
}
if (values.length === 0) {
return never;
}
var expected = values.map(function (value) { return JSON.stringify(value); }).join(' | ');
return fromGuard((_a = G.schemableGuard).literal.apply(_a, values), expected);
}
export var literal = KD.literal;
// -------------------------------------------------------------------------------------

@@ -84,30 +41,41 @@ // primitives

* @category primitives
* @since 2.2.0
* @since 2.2.7
*/
export var never = fromGuard(G.never, 'never');
export var string =
/*#__PURE__*/
fromGuard(G.string, 'string');
/**
* @category primitives
* @since 2.2.0
* @since 2.2.7
*/
export var string = fromGuard(G.string, 'string');
export var number =
/*#__PURE__*/
fromGuard(G.number, 'number');
/**
* @category primitives
* @since 2.2.0
* @since 2.2.7
*/
export var number = fromGuard(G.number, 'number');
export var boolean =
/*#__PURE__*/
fromGuard(G.boolean, 'boolean');
/**
* @category primitives
* @since 2.2.0
* @since 2.2.7
*/
export var boolean = fromGuard(G.boolean, 'boolean');
export var UnknownArray =
/*#__PURE__*/
fromGuard(G.UnknownArray, 'Array<unknown>');
/**
* @category primitives
* @since 2.2.0
* @since 2.2.7
*/
export var UnknownArray = fromGuard(G.UnknownArray, 'Array<unknown>');
export var UnknownRecord =
/*#__PURE__*/
fromGuard(G.UnknownRecord, 'Record<string, unknown>');
/**
* @category primitives
* @since 2.2.0
* @internal
*/
export var UnknownRecord = fromGuard(G.UnknownRecord, 'Record<string, unknown>');
export var object =
/*#__PURE__*/
fromGuard(G.object, 'object');
// -------------------------------------------------------------------------------------

@@ -118,185 +86,51 @@ // combinators

* @category combinators
* @since 2.2.0
* @since 2.2.7
*/
export function withExpected(decoder, expected) {
return {
decode: function (u) {
return pipe(decoder.decode(u), E.mapLeft(function (nea) { return expected(u, nea); }));
}
};
}
export var mapLeftWithInput = KD.mapLeftWithInput;
/**
* @category combinators
* @since 2.2.0
* @since 2.2.7
*/
export function refinement(from, refinement, expected) {
return {
decode: function (u) {
var e = from.decode(u);
if (E.isLeft(e)) {
return e;
}
var a = e.right;
return refinement(a) ? success(a) : failure("cannot refine " + JSON.stringify(u) + ", should be " + expected);
}
};
}
export var refine = KD.refine;
/**
* @category combinators
* @since 2.2.0
* @since 2.2.7
*/
export function parse(from, parser) {
return {
decode: function (u) {
var e = from.decode(u);
if (E.isLeft(e)) {
return e;
}
var pe = parser(e.right);
if (E.isLeft(pe)) {
return failure(pe.left);
}
return pe;
}
};
}
export var parse = KD.parse;
/**
* @category combinators
* @since 2.2.0
* @since 2.2.7
*/
export function nullable(or) {
return union(literal(null), or);
}
export var nullable = KD.nullable;
/**
* @category combinators
* @since 2.2.0
* @since 2.2.7
*/
export function type(properties) {
return {
decode: function (u) {
var e = UnknownRecord.decode(u);
if (E.isLeft(e)) {
return e;
}
else {
var r = e.right;
var a = {};
var errors = [];
for (var k in properties) {
var e_1 = properties[k].decode(r[k]);
if (E.isLeft(e_1)) {
errors.push(tree("required property " + JSON.stringify(k), e_1.left));
}
else {
a[k] = e_1.right;
}
}
return isNotEmpty(errors) ? E.left(errors) : success(a);
}
}
};
}
export var type = function (properties) {
return pipe(object, compose(KD.type(properties)));
};
/**
* @category combinators
* @since 2.2.0
* @since 2.2.7
*/
export function partial(properties) {
return {
decode: function (u) {
var e = UnknownRecord.decode(u);
if (E.isLeft(e)) {
return e;
}
else {
var r = e.right;
var a = {};
var errors = [];
for (var k in properties) {
// don't add missing properties
if (k in r) {
var rk = r[k];
// don't strip undefined properties
if (rk === undefined) {
a[k] = undefined;
}
else {
var e_2 = properties[k].decode(rk);
if (E.isLeft(e_2)) {
errors.push(tree("optional property " + JSON.stringify(k), e_2.left));
}
else {
a[k] = e_2.right;
}
}
}
}
return isNotEmpty(errors) ? E.left(errors) : success(a);
}
}
};
}
export var partial = function (properties) {
return pipe(object, compose(KD.partial(properties)));
};
/**
* @category combinators
* @since 2.2.0
* @since 2.2.7
*/
export function record(codomain) {
return {
decode: function (u) {
var e = UnknownRecord.decode(u);
if (E.isLeft(e)) {
return e;
}
else {
var r = e.right;
var a = {};
var errors = [];
for (var k in r) {
var e_3 = codomain.decode(r[k]);
if (E.isLeft(e_3)) {
errors.push(tree("key " + JSON.stringify(k), e_3.left));
}
else {
a[k] = e_3.right;
}
}
return isNotEmpty(errors) ? E.left(errors) : success(a);
}
}
};
}
export var array = function (items) { return pipe(UnknownArray, compose(KD.array(items))); };
/**
* @category combinators
* @since 2.2.0
* @since 2.2.7
*/
export function array(items) {
return {
decode: function (u) {
var e = UnknownArray.decode(u);
if (E.isLeft(e)) {
return e;
}
else {
var us = e.right;
var len = us.length;
var a = new Array(len);
var errors = [];
for (var i = 0; i < len; i++) {
var e_4 = items.decode(us[i]);
if (E.isLeft(e_4)) {
errors.push(tree("item " + i, e_4.left));
}
else {
a[i] = e_4.right;
}
}
return isNotEmpty(errors) ? E.left(errors) : success(a);
}
}
};
}
export var record = function (codomain) {
return pipe(UnknownRecord, compose(KD.record(codomain)));
};
/**
* @category combinators
* @since 2.2.0
* @since 2.2.7
*/
export function tuple() {
export var tuple = function () {
var components = [];

@@ -306,137 +140,37 @@ for (var _i = 0; _i < arguments.length; _i++) {

}
return {
decode: function (u) {
var e = UnknownArray.decode(u);
if (E.isLeft(e)) {
return e;
}
var us = e.right;
var a = [];
var errors = [];
for (var i = 0; i < components.length; i++) {
var e_5 = components[i].decode(us[i]);
if (E.isLeft(e_5)) {
errors.push(tree("component " + i, e_5.left));
}
else {
a.push(e_5.right);
}
}
return isNotEmpty(errors) ? E.left(errors) : success(a);
}
};
}
function typeOf(x) {
return x === null ? 'null' : typeof x;
}
return pipe(UnknownArray, compose(KD.tuple.apply(KD, components)));
};
/**
* @internal
* @category combinators
* @since 2.2.7
*/
export function intersect(a, b) {
if (a !== undefined && b !== undefined) {
var tx = typeOf(a);
var ty = typeOf(b);
if (tx === 'object' || ty === 'object') {
return Object.assign({}, a, b);
}
}
return b;
}
export var union = KD.union;
/**
* @category combinators
* @since 2.2.0
* @since 2.2.7
*/
export function intersection(left, right) {
return {
decode: function (u) {
var ea = left.decode(u);
var eb = right.decode(u);
if (E.isLeft(ea)) {
return E.isLeft(eb) ? E.left(ea.left.concat(eb.left)) : ea;
}
if (E.isLeft(eb)) {
return eb;
}
return success(intersect(ea.right, eb.right));
}
};
}
export var intersect = KD.intersect;
/**
* @category combinators
* @since 2.2.0
* @since 2.2.7
*/
export function lazy(id, f) {
var get = memoize(f);
return {
decode: function (u) {
return pipe(get().decode(u), E.mapLeft(function (nea) { return [tree(id, nea)]; }));
}
};
}
export var sum = function (tag) { return function (members) {
return pipe(object, compose(KD.sum(tag)(members)));
}; };
/**
* @category combinators
* @since 2.2.0
* @since 2.2.7
*/
export function sum(tag) {
return function (members) {
var keys = Object.keys(members);
if (keys.length === 0) {
return never;
}
var expected = keys.map(function (k) { return JSON.stringify(k); }).join(' | ');
return {
decode: function (u) {
var e = UnknownRecord.decode(u);
if (E.isLeft(e)) {
return e;
}
var v = e.right[tag];
if (v in members) {
return members[v].decode(u);
}
return E.left([
tree("required property " + JSON.stringify(tag), [
tree("cannot decode " + JSON.stringify(v) + ", should be " + expected)
])
]);
}
};
};
}
export var lazy = KD.lazy;
/**
* @category combinators
* @since 2.2.0
* @since 2.2.7
*/
export function union() {
var members = [];
for (var _i = 0; _i < arguments.length; _i++) {
members[_i] = arguments[_i];
}
var len = members.length;
if (len === 0) {
return never;
}
return {
decode: function (u) {
var e = members[0].decode(u);
if (E.isRight(e)) {
return e;
}
else {
var errors = [tree("member 0", e.left)];
for (var i = 1; i < len; i++) {
var e_6 = members[i].decode(u);
if (E.isRight(e_6)) {
return e_6;
}
else {
errors.push(tree("member " + i, e_6.left));
}
}
return E.left(errors);
}
}
};
}
export var compose = KD.compose;
// -------------------------------------------------------------------------------------
// non-pipeables
// -------------------------------------------------------------------------------------
var map_ = function (fa, f) { return pipe(fa, map(f)); };
var alt_ = function (me, that) { return pipe(me, alt(that)); };
// -------------------------------------------------------------------------------------
// pipeables

@@ -446,22 +180,10 @@ // -------------------------------------------------------------------------------------

* @category Functor
* @since 2.2.0
* @since 2.2.7
*/
export var map = function (f) { return function (fa) { return map_(fa, f); }; };
var map_ = function (fa, f) { return ({
decode: function (u) {
var e = fa.decode(u);
return E.isLeft(e) ? e : E.right(f(e.right));
}
}); };
export var map = KD.map;
/**
* @category Alt
* @since 2.2.0
* @since 2.2.7
*/
export var alt = function (that) { return function (fa) { return alt_(fa, that); }; };
var alt_ = function (fx, fy) { return ({
decode: function (u) {
var e = fx.decode(u);
return E.isLeft(e) ? fy().decode(u) : e;
}
}); };
export var alt = KD.alt;
// -------------------------------------------------------------------------------------

@@ -472,3 +194,3 @@ // instances

* @category instances
* @since 2.2.0
* @since 2.2.7
*/

@@ -478,3 +200,3 @@ export var URI = 'io-ts/Decoder';

* @category instances
* @since 2.2.3
* @since 2.2.7
*/

@@ -487,3 +209,3 @@ export var functorDecoder = {

* @category instances
* @since 2.2.3
* @since 2.2.7
*/

@@ -497,3 +219,3 @@ export var altDecoder = {

* @category instances
* @since 2.2.3
* @since 2.2.7
*/

@@ -512,3 +234,3 @@ export var schemableDecoder = {

tuple: tuple,
intersection: intersection,
intersect: intersect,
sum: sum,

@@ -519,3 +241,42 @@ lazy: lazy,

union: union,
refinement: refinement
refine: refine
};
var empty = [];
var make = function (value, forest) {
if (forest === void 0) { forest = empty; }
return ({
value: value,
forest: forest
});
};
var drawTree = function (tree) { return tree.value + drawForest('\n', tree.forest); };
var drawForest = function (indentation, forest) {
var r = '';
var len = forest.length;
var tree;
for (var i = 0; i < len; i++) {
tree = forest[i];
var isLast = i === len - 1;
r += indentation + (isLast ? '└' : '├') + '─ ' + tree.value;
r += drawForest(indentation + (len > 1 && !isLast ? '│ ' : ' '), tree.forest);
}
return r;
};
var toTree = DE.fold({
Leaf: function (input, error) { return make("cannot decode " + JSON.stringify(input) + ", should be " + error); },
Key: function (key, kind, errors) { return make(kind + " property " + JSON.stringify(key), toForest(errors)); },
Index: function (index, kind, errors) { return make(kind + " index " + index, toForest(errors)); },
Member: function (index, errors) { return make("member " + index, toForest(errors)); },
Lazy: function (id, errors) { return make("lazy type " + id, toForest(errors)); }
});
var toForest = FS.fold(function (value) { return [toTree(value)]; }, function (left, right) { return toForest(left).concat(toForest(right)); });
/**
* @since 2.2.7
*/
export var draw = function (e) { return toForest(e).map(drawTree).join('\n'); };
/**
* @internal
*/
export var stringify =
/*#__PURE__*/
E.fold(draw, function (a) { return JSON.stringify(a, null, 2); });
/**
* **This module is experimental**
*
* 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.
*
* A feature tagged as _Experimental_ is in a high state of flux, you're at risk of it changing without notice.
*
* @since 2.2.3

@@ -14,10 +21,2 @@ */

/**
* @since 2.2.3
*/
export declare type TypeOf<E> = E extends Encoder<any, infer A> ? A : never;
/**
* @since 2.2.3
*/
export declare type OutputOf<E> = E extends Encoder<infer O, any> ? O : never;
/**
* @category constructors

@@ -73,3 +72,3 @@ * @since 2.2.3

*/
export declare function intersection<O, A, P, B>(left: Encoder<O, A>, right: Encoder<P, B>): Encoder<O & P, A & B>;
export declare const intersect: <P, B>(right: Encoder<P, B>) => <O, A>(left: Encoder<O, A>) => Encoder<O & P, A & B>;
/**

@@ -79,3 +78,3 @@ * @category combinators

*/
export declare function sum<T extends string>(tag: T): <M extends Record<string, Encoder<any, any>>>(members: M) => Encoder<OutputOf<M[keyof M]>, TypeOf<M[keyof M]>>;
export declare function sum<T extends string>(tag: T): <MS extends Record<string, Encoder<any, any>>>(members: MS) => Encoder<OutputOf<MS[keyof MS]>, TypeOf<MS[keyof MS]>>;
/**

@@ -121,1 +120,9 @@ * @category combinators

export declare const categoryEncoder: Category2<URI>;
/**
* @since 2.2.3
*/
export declare type TypeOf<E> = E extends Encoder<any, infer A> ? A : never;
/**
* @since 2.2.3
*/
export declare type OutputOf<E> = E extends Encoder<infer O, any> ? O : never;

@@ -1,3 +0,2 @@

import { intersect } from './Decoder';
import { memoize } from './Schemable';
import { memoize, intersect_ } from './Schemable';
import { identity } from 'fp-ts/es6/function';

@@ -104,7 +103,5 @@ // -------------------------------------------------------------------------------------

*/
export function intersection(left, right) {
return {
encode: function (ab) { return intersect(left.encode(ab), right.encode(ab)); }
};
}
export var intersect = function (right) { return function (left) { return ({
encode: function (ab) { return intersect_(left.encode(ab), right.encode(ab)); }
}); }; };
/**

@@ -111,0 +108,0 @@ * @category combinators

import * as E from 'fp-ts/es6/Eq';
import { Schemable1, WithRefinement1, WithUnknownContainers1 } from './Schemable';
import { Schemable1, WithRefine1, WithUnknownContainers1 } from './Schemable';
import Eq = E.Eq;

@@ -81,3 +81,3 @@ /**

*/
export declare function intersection<A, B>(left: Eq<A>, right: Eq<B>): Eq<A & B>;
export declare const intersect: <B>(right: E.Eq<B>) => <A>(left: E.Eq<A>) => E.Eq<A & B>;
/**

@@ -99,2 +99,2 @@ * @category combinators

*/
export declare const schemableEq: Schemable1<E.URI> & WithUnknownContainers1<E.URI> & WithRefinement1<E.URI>;
export declare const schemableEq: Schemable1<E.URI> & WithUnknownContainers1<E.URI> & WithRefine1<E.URI>;
/**
* **This module is experimental**
*
* 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.
*
* A feature tagged as _Experimental_ is in a high state of flux, you're at risk of it changing without notice.
*
* @since 2.2.2

@@ -102,7 +109,5 @@ */

*/
export function intersection(left, right) {
return {
equals: function (x, y) { return left.equals(x, y) && right.equals(x, y); }
};
}
export var intersect = function (right) { return function (left) { return ({
equals: function (x, y) { return left.equals(x, y) && right.equals(x, y); }
}); }; };
/**

@@ -155,3 +160,3 @@ * @category combinators

tuple: tuple,
intersection: intersection,
intersect: intersect,
sum: sum,

@@ -161,3 +166,3 @@ lazy: function (_, f) { return lazy(f); },

UnknownRecord: UnknownRecord,
refinement: function (from) { return from; }
refine: function () { return function (from) { return from; }; }
};

@@ -0,6 +1,3 @@

import { Literal, Schemable1, WithRefine1, WithUnion1, WithUnknownContainers1 } from './Schemable';
/**
* @since 2.2.0
*/
import { Literal, Schemable1, WithRefinement1, WithUnion1, WithUnknownContainers1 } from './Schemable';
/**
* @category model

@@ -20,3 +17,3 @@ * @since 2.2.0

*/
export declare function literal<A extends ReadonlyArray<Literal>>(...values: A): Guard<A[number]>;
export declare const literal: <A extends readonly [Literal, ...Literal[]]>(...values: A) => Guard<A[number]>;
/**

@@ -26,9 +23,6 @@ * @category primitives

*/
export declare const never: Guard<never>;
/**
* @category primitives
* @since 2.2.0
*/
export declare const string: Guard<string>;
/**
* Note: `NaN` is excluded.
*
* @category primitives

@@ -57,3 +51,3 @@ * @since 2.2.0

*/
export declare function refinement<A, B extends A>(from: Guard<A>, refinement: (a: A) => a is B): Guard<B>;
export declare const refine: <A, B extends A>(refinement: (a: A) => a is B) => (from: Guard<A>) => Guard<B>;
/**

@@ -63,3 +57,3 @@ * @category combinators

*/
export declare function nullable<A>(or: Guard<A>): Guard<null | A>;
export declare const nullable: <A>(or: Guard<A>) => Guard<A | null>;
/**

@@ -69,7 +63,3 @@ * @category combinators

*/
export declare function type<A>(properties: {
[K in keyof A]: Guard<A[K]>;
}): Guard<{
[K in keyof A]: A[K];
}>;
export declare const type: <A>(properties: { [K in keyof A]: Guard<A[K]>; }) => Guard<{ [K_1 in keyof A]: A[K_1]; }>;
/**

@@ -79,7 +69,3 @@ * @category combinators

*/
export declare function partial<A>(properties: {
[K in keyof A]: Guard<A[K]>;
}): Guard<Partial<{
[K in keyof A]: A[K];
}>>;
export declare const partial: <A>(properties: { [K in keyof A]: Guard<A[K]>; }) => Guard<Partial<{ [K_1 in keyof A]: A[K_1]; }>>;
/**

@@ -89,3 +75,3 @@ * @category combinators

*/
export declare function record<A>(codomain: Guard<A>): Guard<Record<string, A>>;
export declare const record: <A>(codomain: Guard<A>) => Guard<Record<string, A>>;
/**

@@ -95,3 +81,3 @@ * @category combinators

*/
export declare function array<A>(items: Guard<A>): Guard<Array<A>>;
export declare const array: <A>(items: Guard<A>) => Guard<A[]>;
/**

@@ -101,5 +87,3 @@ * @category combinators

*/
export declare function tuple<A extends ReadonlyArray<unknown>>(...components: {
[K in keyof A]: Guard<A[K]>;
}): Guard<A>;
export declare const tuple: <A extends readonly unknown[]>(...components: { [K in keyof A]: Guard<A[K]>; }) => Guard<A>;
/**

@@ -109,3 +93,3 @@ * @category combinators

*/
export declare function intersection<A, B>(left: Guard<A>, right: Guard<B>): Guard<A & B>;
export declare const intersect: <B>(right: Guard<B>) => <A>(left: Guard<A>) => Guard<A & B>;
/**

@@ -115,5 +99,3 @@ * @category combinators

*/
export declare function union<A extends ReadonlyArray<unknown>>(...members: {
[K in keyof A]: Guard<A[K]>;
}): Guard<A[number]>;
export declare const union: <A extends readonly [unknown, ...unknown[]]>(...members: { [K in keyof A]: Guard<A[K]>; }) => Guard<A[number]>;
/**

@@ -123,5 +105,3 @@ * @category combinators

*/
export declare function sum<T extends string>(tag: T): <A>(members: {
[K in keyof A]: Guard<A[K]>;
}) => Guard<A[keyof A]>;
export declare const sum: <T extends string>(tag: T) => <A>(members: { [K in keyof A]: Guard<A[K]>; }) => Guard<A[keyof A]>;
/**

@@ -131,3 +111,3 @@ * @category combinators

*/
export declare function lazy<A>(f: () => Guard<A>): Guard<A>;
export declare const lazy: <A>(f: () => Guard<A>) => Guard<A>;
/**

@@ -152,2 +132,2 @@ * @category instances

*/
export declare const schemableGuard: Schemable1<URI> & WithUnknownContainers1<URI> & WithUnion1<URI> & WithRefinement1<URI>;
export declare const schemableGuard: Schemable1<URI> & WithUnknownContainers1<URI> & WithUnion1<URI> & WithRefine1<URI>;
/**
* **This module is experimental**
*
* 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.
*
* A feature tagged as _Experimental_ is in a high state of flux, you're at risk of it changing without notice.
*
* @since 2.2.0
*/
import { pipe } from 'fp-ts/es6/pipeable';
import { memoize } from './Schemable';

@@ -12,3 +20,3 @@ // -------------------------------------------------------------------------------------

*/
export function literal() {
export var literal = function () {
var values = [];

@@ -18,6 +26,6 @@ for (var _i = 0; _i < arguments.length; _i++) {

}
return {
return ({
is: function (u) { return values.findIndex(function (a) { return a === u; }) !== -1; }
};
}
});
};
// -------------------------------------------------------------------------------------

@@ -30,9 +38,2 @@ // primitives

*/
export var never = {
is: function (_u) { return false; }
};
/**
* @category primitives
* @since 2.2.0
*/
export var string = {

@@ -42,2 +43,4 @@ is: function (u) { return typeof u === 'string'; }

/**
* Note: `NaN` is excluded.
*
* @category primitives

@@ -47,3 +50,3 @@ * @since 2.2.0

export var number = {
is: function (u) { return typeof u === 'number'; }
is: function (u) { return typeof u === 'number' && !isNaN(u); }
};

@@ -71,2 +74,8 @@ /**

};
/**
* @internal
*/
export var object = {
is: function (u) { return u != null && !string.is(u) && !number.is(u) && !boolean.is(u); }
};
// -------------------------------------------------------------------------------------

@@ -79,7 +88,5 @@ // combinators

*/
export function refinement(from, refinement) {
return {
is: function (u) { return from.is(u) && refinement(u); }
};
}
export var refine = function (refinement) { return function (from) { return ({
is: function (u) { return from.is(u) && refinement(u); }
}); }; };
/**

@@ -89,7 +96,5 @@ * @category combinators

*/
export function nullable(or) {
return {
is: function (u) { return u === null || or.is(u); }
};
}
export var nullable = function (or) { return ({
is: function (u) { return u === null || or.is(u); }
}); };
/**

@@ -99,4 +104,4 @@ * @category combinators

*/
export function type(properties) {
return refinement(UnknownRecord, function (r) {
export var type = function (properties) {
return pipe(UnknownRecord, refine(function (r) {
for (var k in properties) {

@@ -108,4 +113,4 @@ if (!(k in r) || !properties[k].is(r[k])) {

return true;
});
}
}));
};
/**

@@ -115,4 +120,4 @@ * @category combinators

*/
export function partial(properties) {
return refinement(UnknownRecord, function (r) {
export var partial = function (properties) {
return pipe(UnknownRecord, refine(function (r) {
for (var k in properties) {

@@ -125,4 +130,4 @@ var v = r[k];

return true;
});
}
}));
};
/**

@@ -132,4 +137,4 @@ * @category combinators

*/
export function record(codomain) {
return refinement(UnknownRecord, function (r) {
export var record = function (codomain) {
return pipe(UnknownRecord, refine(function (r) {
for (var k in r) {

@@ -141,4 +146,4 @@ if (!codomain.is(r[k])) {

return true;
});
}
}));
};
/**

@@ -148,5 +153,5 @@ * @category combinators

*/
export function array(items) {
return refinement(UnknownArray, function (us) { return us.every(items.is); });
}
export var array = function (items) {
return pipe(UnknownArray, refine(function (us) { return us.every(items.is); }));
};
/**

@@ -156,3 +161,3 @@ * @category combinators

*/
export function tuple() {
export var tuple = function () {
var components = [];

@@ -162,6 +167,6 @@ for (var _i = 0; _i < arguments.length; _i++) {

}
return {
return ({
is: function (u) { return Array.isArray(u) && u.length === components.length && components.every(function (c, i) { return c.is(u[i]); }); }
};
}
});
};
/**

@@ -171,7 +176,5 @@ * @category combinators

*/
export function intersection(left, right) {
return {
is: function (u) { return left.is(u) && right.is(u); }
};
}
export var intersect = function (right) { return function (left) { return ({
is: function (u) { return left.is(u) && right.is(u); }
}); }; };
/**

@@ -181,3 +184,3 @@ * @category combinators

*/
export function union() {
export var union = function () {
var members = [];

@@ -187,6 +190,6 @@ for (var _i = 0; _i < arguments.length; _i++) {

}
return {
return ({
is: function (u) { return members.some(function (m) { return m.is(u); }); }
};
}
});
};
/**

@@ -196,13 +199,11 @@ * @category combinators

*/
export function sum(tag) {
return function (members) {
return refinement(UnknownRecord, function (r) {
var v = r[tag];
if (v in members) {
return members[v].is(r);
}
return false;
});
};
}
export var sum = function (tag) { return function (members) {
return pipe(UnknownRecord, refine(function (r) {
var v = r[tag];
if (v in members) {
return members[v].is(r);
}
return false;
}));
}; };
/**

@@ -212,3 +213,3 @@ * @category combinators

*/
export function lazy(f) {
export var lazy = function (f) {
var get = memoize(f);

@@ -218,3 +219,3 @@ return {

};
}
};
// -------------------------------------------------------------------------------------

@@ -244,3 +245,3 @@ // instances

tuple: tuple,
intersection: intersection,
intersect: intersect,
sum: sum,

@@ -251,3 +252,3 @@ lazy: function (_, f) { return lazy(f); },

union: union,
refinement: refinement
refine: refine
};
/**
* **This module is experimental**
*
* 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.
*
* A feature tagged as _Experimental_ is in a high state of flux, you're at risk of it changing without notice.
*
* @since 2.2.3

@@ -8,3 +15,3 @@ */

import * as C from './Codec';
import { Literal, Schemable1, WithRefinement1 } from './Schemable';
import { Literal, Schemable1, WithRefine1 } from './Schemable';
/**

@@ -34,3 +41,3 @@ * Laws:

*/
export declare const literal: <A extends ReadonlyArray<Literal>>(...values: A) => JsonCodec<A[number]>;
export declare const literal: <A extends readonly [Literal, ...Array<Literal>]>(...values: A) => JsonCodec<A[number]>;
/**

@@ -55,3 +62,3 @@ * @category primitives

*/
export declare const withExpected: <A>(codec: JsonCodec<A>, expected: (actual: unknown, e: D.DecodeError) => D.DecodeError) => JsonCodec<A>;
export declare const mapLeftWithInput: (f: (actual: unknown, e: D.DecodeError) => D.DecodeError) => <A>(codec: JsonCodec<A>) => JsonCodec<A>;
/**

@@ -61,3 +68,3 @@ * @category combinators

*/
export declare const refinement: <A, B extends A>(from: JsonCodec<A>, refinement: (a: A) => a is B, expected: string) => JsonCodec<B>;
export declare const refine: <A, B extends A>(refinement: (a: A) => a is B, id: string) => (from: JsonCodec<A>) => JsonCodec<B>;
/**

@@ -107,3 +114,3 @@ * @category combinators

*/
export declare const intersection: <A, B>(left: JsonCodec<A>, right: JsonCodec<B>) => JsonCodec<A & B>;
export declare const intersect: <B>(right: JsonCodec<B>) => <A>(left: JsonCodec<A>) => JsonCodec<A & B>;
/**

@@ -150,2 +157,2 @@ * @category combinators

*/
export declare const schemableJsonCodec: Schemable1<URI> & WithRefinement1<URI>;
export declare const schemableJsonCodec: Schemable1<URI> & WithRefine1<URI>;

@@ -40,3 +40,3 @@ import * as C from './Codec';

*/
export var withExpected = C.withExpected;
export var mapLeftWithInput = C.mapLeftWithInput;
/**

@@ -46,3 +46,3 @@ * @category combinators

*/
export var refinement = C.refinement;
export var refine = C.refine;
/**

@@ -82,3 +82,3 @@ * @category combinators

*/
export var intersection = C.intersection;
export var intersect = C.intersect;
/**

@@ -134,6 +134,6 @@ * @category combinators

tuple: tuple,
intersection: intersection,
intersect: intersect,
sum: sum,
lazy: lazy,
refinement: refinement
refine: refine
};
/**
* **This module is experimental**
*
* 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.
*
* A feature tagged as _Experimental_ is in a high state of flux, you're at risk of it changing without notice.
*
* @since 2.2.3

@@ -11,3 +18,3 @@ */

*/
export interface JsonArray extends Array<Json> {
export interface JsonArray extends ReadonlyArray<Json> {
}

@@ -18,5 +25,5 @@ /**

*/
export declare type JsonObject = {
[key: string]: Json;
};
export interface JsonRecord {
readonly [key: string]: Json;
}
/**

@@ -26,3 +33,3 @@ * @category model

*/
export declare type Json = null | string | number | boolean | JsonObject | JsonArray;
export declare type Json = null | string | number | boolean | JsonRecord | JsonArray;
/**

@@ -88,3 +95,3 @@ * @category model

*/
export declare const intersection: <A, B>(left: JsonEncoder<A>, right: JsonEncoder<B>) => JsonEncoder<A & B>;
export declare const intersect: <B>(right: JsonEncoder<B>) => <A>(left: JsonEncoder<A>) => JsonEncoder<A & B>;
/**

@@ -91,0 +98,0 @@ * @category combinators

@@ -52,3 +52,3 @@ import { identity } from 'fp-ts/es6/function';

*/
export var intersection = E.intersection;
export var intersect = E.intersect;
/**

@@ -104,5 +104,5 @@ * @category combinators

tuple: tuple,
intersection: intersection,
intersect: intersect,
sum: sum,
lazy: function (_, f) { return lazy(f); }
};
/**
* **This module is experimental**
*
* 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.
*
* A feature tagged as _Experimental_ is in a high state of flux, you're at risk of it changing without notice.
*
* @since 2.2.0

@@ -3,0 +10,0 @@ */

/**
* **This module is experimental**
*
* 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.
*
* A feature tagged as _Experimental_ is in a high state of flux, you're at risk of it changing without notice.
*
* @since 2.2.0

@@ -14,3 +21,3 @@ */

readonly URI: S;
readonly literal: <A extends ReadonlyArray<Literal>>(...values: A) => HKT<S, A[number]>;
readonly literal: <A extends readonly [Literal, ...Array<Literal>]>(...values: A) => HKT<S, A[number]>;
readonly string: HKT<S, string>;

@@ -35,3 +42,3 @@ readonly number: HKT<S, number>;

}) => HKT<S, A>;
readonly intersection: <A, B>(left: HKT<S, A>, right: HKT<S, B>) => HKT<S, A & B>;
readonly intersect: <B>(right: HKT<S, B>) => <A>(left: HKT<S, A>) => HKT<S, A & B>;
readonly sum: <T extends string>(tag: T) => <A>(members: {

@@ -47,3 +54,3 @@ [K in keyof A]: HKT<S, A[K]>;

readonly URI: S;
readonly literal: <A extends ReadonlyArray<Literal>>(...values: A) => Kind<S, A[number]>;
readonly literal: <A extends readonly [Literal, ...Array<Literal>]>(...values: A) => Kind<S, A[number]>;
readonly string: Kind<S, string>;

@@ -68,3 +75,3 @@ readonly number: Kind<S, number>;

}) => Kind<S, A>;
readonly intersection: <A, B>(left: Kind<S, A>, right: Kind<S, B>) => Kind<S, A & B>;
readonly intersect: <B>(right: Kind<S, B>) => <A>(left: Kind<S, A>) => Kind<S, A & B>;
readonly sum: <T extends string>(tag: T) => <A>(members: {

@@ -93,3 +100,3 @@ [K in keyof A]: Kind<S, A[K]>;

export interface WithUnion<S> {
readonly union: <A extends ReadonlyArray<unknown>>(...members: {
readonly union: <A extends readonly [unknown, ...Array<unknown>]>(...members: {
[K in keyof A]: HKT<S, A[K]>;

@@ -102,3 +109,3 @@ }) => HKT<S, A[number]>;

export interface WithUnion1<S extends URIS> {
readonly union: <A extends ReadonlyArray<unknown>>(...members: {
readonly union: <A extends readonly [unknown, ...Array<unknown>]>(...members: {
[K in keyof A]: Kind<S, A[K]>;

@@ -110,4 +117,4 @@ }) => Kind<S, A[number]>;

*/
export interface WithRefinement<S> {
readonly refinement: <A, B extends A>(from: HKT<S, A>, refinement: (a: A) => a is B, expected: string) => HKT<S, B>;
export interface WithRefine<S> {
readonly refine: <A, B extends A>(refinement: (a: A) => a is B, id: string) => (from: HKT<S, A>) => HKT<S, B>;
}

@@ -117,4 +124,4 @@ /**

*/
export interface WithRefinement1<S extends URIS> {
readonly refinement: <A, B extends A>(from: Kind<S, A>, refinement: (a: A) => a is B, expected: string) => Kind<S, B>;
export interface WithRefine1<S extends URIS> {
readonly refine: <A, B extends A>(refinement: (a: A) => a is B, id: string) => (from: Kind<S, A>) => Kind<S, B>;
}

@@ -121,0 +128,0 @@ /**

@@ -15,1 +15,18 @@ /**

}
// -------------------------------------------------------------------------------------
// utils
// -------------------------------------------------------------------------------------
var typeOf = function (x) { return (x === null ? 'null' : typeof x); };
/**
* @internal
*/
export var intersect_ = function (a, b) {
if (a !== undefined && b !== undefined) {
var tx = typeOf(a);
var ty = typeOf(b);
if (tx === 'object' || ty === 'object') {
return Object.assign({}, a, b);
}
}
return b;
};
/**
* **This module is experimental**
*
* 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.
*
* A feature tagged as _Experimental_ is in a high state of flux, you're at risk of it changing without notice.
*
* @since 2.2.3
*/
import * as t from './index';
import { Literal, Schemable1, WithUnion1, WithRefinement1, WithUnknownContainers1 } from './Schemable';
import { Literal, Schemable1, WithUnion1, WithRefine1, WithUnknownContainers1 } from './Schemable';
/**

@@ -16,3 +23,3 @@ * @category model

*/
export declare function literal<A extends ReadonlyArray<Literal>>(...values: A): Type<A[number]>;
export declare const literal: <A extends readonly [Literal, ...Literal[]]>(...values: A) => Type<A[number]>;
/**

@@ -47,3 +54,3 @@ * @category primitives

*/
export declare function refinement<A, B extends A>(from: Type<A>, refinement: (a: A) => a is B, expected: string): Type<B>;
export declare const refine: <A, B extends A>(refinement: (a: A) => a is B, id: string) => (from: Type<A>) => Type<B>;
/**

@@ -53,3 +60,3 @@ * @category combinators

*/
export declare function nullable<A>(or: Type<A>): Type<null | A>;
export declare const nullable: <A>(or: Type<A>) => Type<A | null>;
/**

@@ -59,7 +66,3 @@ * @category combinators

*/
export declare function type<A>(properties: {
[K in keyof A]: Type<A[K]>;
}): Type<{
[K in keyof A]: A[K];
}>;
export declare const type: <A>(properties: { [K in keyof A]: Type<A[K]>; }) => Type<{ [K_1 in keyof A]: A[K_1]; }>;
/**

@@ -69,7 +72,3 @@ * @category combinators

*/
export declare function partial<A>(properties: {
[K in keyof A]: Type<A[K]>;
}): Type<Partial<{
[K in keyof A]: A[K];
}>>;
export declare const partial: <A>(properties: { [K in keyof A]: Type<A[K]>; }) => Type<Partial<{ [K_1 in keyof A]: A[K_1]; }>>;
/**

@@ -79,3 +78,3 @@ * @category combinators

*/
export declare function record<A>(codomain: Type<A>): Type<Record<string, A>>;
export declare const record: <A>(codomain: Type<A>) => Type<Record<string, A>>;
/**

@@ -85,3 +84,3 @@ * @category combinators

*/
export declare function array<A>(items: Type<A>): Type<Array<A>>;
export declare const array: <A>(items: Type<A>) => Type<A[]>;
/**

@@ -91,5 +90,3 @@ * @category combinators

*/
export declare function tuple<A extends ReadonlyArray<unknown>>(...components: {
[K in keyof A]: Type<A[K]>;
}): Type<A>;
export declare const tuple: <A extends readonly unknown[]>(...components: { [K in keyof A]: Type<A[K]>; }) => Type<A>;
/**

@@ -99,3 +96,3 @@ * @category combinators

*/
export declare function intersection<A, B>(left: Type<A>, right: Type<B>): Type<A & B>;
export declare const intersect: <B>(right: Type<B>) => <A>(left: Type<A>) => Type<A & B>;
/**

@@ -105,3 +102,3 @@ * @category combinators

*/
export declare function lazy<A>(id: string, f: () => Type<A>): Type<A>;
export declare const lazy: <A>(id: string, f: () => Type<A>) => Type<A>;
/**

@@ -111,5 +108,3 @@ * @category combinators

*/
export declare function sum<T extends string>(_tag: T): <A>(members: {
[K in keyof A]: Type<A[K]>;
}) => Type<A[keyof A]>;
export declare const sum: <T extends string>(_tag: T) => <A>(members: { [K in keyof A]: Type<A[K]>; }) => Type<A[keyof A]>;
/**

@@ -119,5 +114,3 @@ * @category combinators

*/
export declare function union<A extends ReadonlyArray<unknown>>(...members: {
[K in keyof A]: Type<A[K]>;
}): Type<A[number]>;
export declare const union: <A extends readonly [unknown, ...unknown[]]>(...members: { [K in keyof A]: Type<A[K]>; }) => Type<A[number]>;
/**

@@ -142,2 +135,2 @@ * @category instances

*/
export declare const schemableType: Schemable1<URI> & WithUnknownContainers1<URI> & WithUnion1<URI> & WithRefinement1<URI>;
export declare const schemableType: Schemable1<URI> & WithUnknownContainers1<URI> & WithUnion1<URI> & WithRefine1<URI>;
/**
* **This module is experimental**
*
* 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.
*
* A feature tagged as _Experimental_ is in a high state of flux, you're at risk of it changing without notice.
*
* @since 2.2.3
*/
import * as t from './index';
import * as E from 'fp-ts/es6/Either';
import { pipe } from 'fp-ts/es6/pipeable';
// -------------------------------------------------------------------------------------

@@ -12,3 +21,3 @@ // constructors

*/
export function literal() {
export var literal = function () {
var values = [];

@@ -19,3 +28,3 @@ for (var _i = 0; _i < arguments.length; _i++) {

return t.union(values.map(function (v) { return t.literal(v); }));
}
};
// -------------------------------------------------------------------------------------

@@ -33,3 +42,5 @@ // primitives

*/
export var number = t.number;
export var number = new t.Type(t.number.name, t.number.is, function (u, c) {
return pipe(t.number.decode(u), E.chain(function (n) { return (isNaN(n) ? t.failure(u, c) : t.success(n)); }));
}, t.number.encode);
/**

@@ -57,6 +68,6 @@ * @category primitives

*/
export function refinement(from, refinement, expected) {
export var refine = function (refinement, id) { return function (from) {
// tslint:disable-next-line: deprecation
return t.refinement(from, refinement, expected);
}
return t.refinement(from, refinement, id);
}; };
/**

@@ -66,5 +77,3 @@ * @category combinators

*/
export function nullable(or) {
return t.union([t.null, or]);
}
export var nullable = function (or) { return t.union([t.null, or]); };
/**

@@ -74,5 +83,5 @@ * @category combinators

*/
export function type(properties) {
export var type = function (properties) {
return t.type(properties);
}
};
/**

@@ -82,5 +91,5 @@ * @category combinators

*/
export function partial(properties) {
export var partial = function (properties) {
return t.partial(properties);
}
};
/**

@@ -90,5 +99,3 @@ * @category combinators

*/
export function record(codomain) {
return t.record(t.string, codomain);
}
export var record = function (codomain) { return t.record(t.string, codomain); };
/**

@@ -98,5 +105,3 @@ * @category combinators

*/
export function array(items) {
return t.array(items);
}
export var array = function (items) { return t.array(items); };
/**

@@ -106,3 +111,3 @@ * @category combinators

*/
export function tuple() {
export var tuple = function () {
var components = [];

@@ -113,3 +118,3 @@ for (var _i = 0; _i < arguments.length; _i++) {

return t.tuple(components);
}
};
/**

@@ -119,5 +124,3 @@ * @category combinators

*/
export function intersection(left, right) {
return t.intersection([left, right]);
}
export var intersect = function (right) { return function (left) { return t.intersection([left, right]); }; };
/**

@@ -127,5 +130,3 @@ * @category combinators

*/
export function lazy(id, f) {
return t.recursion(id, f);
}
export var lazy = function (id, f) { return t.recursion(id, f); };
/**

@@ -135,5 +136,5 @@ * @category combinators

*/
export function sum(_tag) {
return function (members) { return t.union(Object.values(members)); };
}
export var sum = function (_tag) { return function (members) {
return t.union(Object.values(members));
}; };
/**

@@ -143,3 +144,3 @@ * @category combinators

*/
export function union() {
export var union = function () {
var members = [];

@@ -150,3 +151,3 @@ for (var _i = 0; _i < arguments.length; _i++) {

return t.union(members);
}
};
// -------------------------------------------------------------------------------------

@@ -176,3 +177,3 @@ // instances

tuple: tuple,
intersection: intersection,
intersect: intersect,
sum: sum,

@@ -183,3 +184,3 @@ lazy: lazy,

union: union,
refinement: refinement
refine: refine
};
/**
* **This module is experimental**
*
* 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.
*
* A feature tagged as _Experimental_ is in a high state of flux, you're at risk of it changing without notice.
*
* @since 2.2.3

@@ -41,3 +48,3 @@ */

*/
export declare function literal<A extends ReadonlyArray<Literal>>(...values: A): Codec<A[number], A[number]>;
export declare function literal<A extends readonly [Literal, ...Array<Literal>]>(...values: A): Codec<A[number], A[number]>;
/**

@@ -72,3 +79,3 @@ * @category primitives

*/
export declare function withExpected<O, A>(codec: Codec<O, A>, expected: (actual: unknown, e: D.DecodeError) => D.DecodeError): Codec<O, A>;
export declare const mapLeftWithInput: (f: (actual: unknown, e: D.DecodeError) => D.DecodeError) => <O, A>(codec: Codec<O, A>) => Codec<O, A>;
/**

@@ -78,3 +85,3 @@ * @category combinators

*/
export declare function refinement<O, A, B extends A>(from: Codec<O, A>, refinement: (a: A) => a is B, expected: string): Codec<O, B>;
export declare const refine: <A, B extends A>(refinement: (a: A) => a is B, id: string) => <O>(from: Codec<O, A>) => Codec<O, B>;
/**

@@ -126,3 +133,3 @@ * @category combinators

*/
export declare function intersection<O, A, P, B>(left: Codec<O, A>, right: Codec<P, B>): Codec<O & P, A & B>;
export declare const intersect: <P, B>(right: Codec<P, B>) => <O, A>(left: Codec<O, A>) => Codec<O & P, A & B>;
/**

@@ -129,0 +136,0 @@ * @category combinators

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.invariantCodec = exports.URI = exports.imap = exports.lazy = exports.sum = exports.intersection = exports.tuple = exports.array = exports.record = exports.partial = exports.type = exports.nullable = exports.refinement = exports.withExpected = exports.UnknownRecord = exports.UnknownArray = exports.boolean = exports.number = exports.string = exports.literal = exports.fromDecoder = exports.make = void 0;
exports.invariantCodec = exports.URI = exports.imap = exports.lazy = exports.sum = exports.intersect = exports.tuple = exports.array = exports.record = exports.partial = exports.type = exports.nullable = exports.refine = exports.mapLeftWithInput = exports.UnknownRecord = exports.UnknownArray = exports.boolean = exports.number = exports.string = exports.literal = exports.fromDecoder = exports.make = void 0;
var D = require("./Decoder");
var E = require("./Encoder");
var function_1 = require("fp-ts/lib/function");
var pipeable_1 = require("fp-ts/lib/pipeable");
// -------------------------------------------------------------------------------------

@@ -79,6 +80,3 @@ // constructors

*/
function withExpected(codec, expected) {
return make(D.withExpected(codec, expected), codec);
}
exports.withExpected = withExpected;
exports.mapLeftWithInput = function (f) { return function (codec) { return make(pipeable_1.pipe(codec, D.mapLeftWithInput(f)), codec); }; };
/**

@@ -88,6 +86,6 @@ * @category combinators

*/
function refinement(from, refinement, expected) {
return make(D.refinement(from, refinement, expected), from);
}
exports.refinement = refinement;
exports.refine = function (refinement, id) {
var refine = D.refine(refinement, id);
return function (from) { return make(refine(from), from); };
};
/**

@@ -154,6 +152,7 @@ * @category combinators

*/
function intersection(left, right) {
return make(D.intersection(left, right), E.intersection(left, right));
}
exports.intersection = intersection;
exports.intersect = function (right) {
var intersectD = D.intersect(right);
var intersectE = E.intersect(right);
return function (left) { return make(intersectD(left), intersectE(left)); };
};
/**

@@ -160,0 +159,0 @@ * @category combinators

/**
* @since 2.2.0
* **This module is experimental**
*
* 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.
*
* A feature tagged as _Experimental_ is in a high state of flux, you're at risk of it changing without notice.
*
* @since 2.2.7
*/
import { Alt1 } from 'fp-ts/lib/Alt';
import * as E from 'fp-ts/lib/Either';
import { NonEmptyArray } from 'fp-ts/lib/NonEmptyArray';
import { Forest, Tree } from 'fp-ts/lib/Tree';
import { Functor1 } from 'fp-ts/lib/Functor';
import * as G from './Guard';
import { Literal, Schemable1, WithRefinement1, WithUnion1, WithUnknownContainers1 } from './Schemable';
import { Functor1 } from 'fp-ts/lib/Functor';
import { Alt1 } from 'fp-ts/lib/Alt';
import Either = E.Either;
import * as KD from './KleisliDecoder';
import { Literal, Schemable1, WithRefine1, WithUnion1, WithUnknownContainers1 } from './Schemable';
/**
* @category model
* @since 2.2.0
* @since 2.2.7
*/
export interface Decoder<A> {
readonly decode: (u: unknown) => Either<DecodeError, A>;
export interface Decoder<A> extends KD.KleisliDecoder<unknown, A> {
}
/**
* @since 2.2.0
*/
export declare type TypeOf<D> = D extends Decoder<infer A> ? A : never;
/**
* @category DecodeError
* @since 2.2.2
* @since 2.2.7
*/
export interface DecodeError extends NonEmptyArray<Tree<string>> {
}
export declare type DecodeError = KD.DecodeError;
/**
* @category DecodeError
* @since 2.2.0
* @since 2.2.7
*/
export declare function tree<A>(value: A, forest?: Forest<A>): Tree<A>;
export declare const error: (actual: unknown, message: string) => DecodeError;
/**
* @category DecodeError
* @since 2.2.0
* @since 2.2.7
*/
export declare function success<A>(a: A): Either<DecodeError, A>;
export declare const success: <A>(a: A) => E.Either<DecodeError, A>;
/**
* @category DecodeError
* @since 2.2.0
* @since 2.2.7
*/
export declare function failure<A = never>(message: string): Either<DecodeError, A>;
export declare const failure: <A = never>(actual: unknown, message: string) => E.Either<DecodeError, A>;
/**
* @category DecodeError
* @since 2.2.2
*/
export declare function isNotEmpty<A>(as: ReadonlyArray<A>): as is NonEmptyArray<A>;
/**
* @category constructors
* @since 2.2.3
* @since 2.2.7
*/
export declare function of<A>(a: A): Decoder<A>;
export declare const fromGuard: <A>(guard: G.Guard<A>, expected: string) => Decoder<A>;
/**
* @category constructors
* @since 2.2.0
* @since 2.2.7
*/
export declare function fromGuard<A>(guard: G.Guard<A>, expected: string): Decoder<A>;
export declare const literal: <A extends readonly [Literal, ...Array<Literal>]>(...values: A) => Decoder<A[number]>;
/**
* @category constructors
* @since 2.2.0
*/
export declare function literal<A extends ReadonlyArray<Literal>>(...values: A): Decoder<A[number]>;
/**
* @category primitives
* @since 2.2.0
* @since 2.2.7
*/
export declare const never: Decoder<never>;
/**
* @category primitives
* @since 2.2.0
*/
export declare const string: Decoder<string>;
/**
* @category primitives
* @since 2.2.0
* @since 2.2.7
*/

@@ -81,3 +65,3 @@ export declare const number: Decoder<number>;

* @category primitives
* @since 2.2.0
* @since 2.2.7
*/

@@ -87,3 +71,3 @@ export declare const boolean: Decoder<boolean>;

* @category primitives
* @since 2.2.0
* @since 2.2.7
*/

@@ -93,3 +77,3 @@ export declare const UnknownArray: Decoder<Array<unknown>>;

* @category primitives
* @since 2.2.0
* @since 2.2.7
*/

@@ -99,82 +83,75 @@ export declare const UnknownRecord: Decoder<Record<string, unknown>>;

* @category combinators
* @since 2.2.0
* @since 2.2.7
*/
export declare function withExpected<A>(decoder: Decoder<A>, expected: (actual: unknown, e: DecodeError) => DecodeError): Decoder<A>;
export declare const mapLeftWithInput: (f: (input: unknown, e: DecodeError) => DecodeError) => <A>(decoder: Decoder<A>) => Decoder<A>;
/**
* @category combinators
* @since 2.2.0
* @since 2.2.7
*/
export declare function refinement<A, B extends A>(from: Decoder<A>, refinement: (a: A) => a is B, expected: string): Decoder<B>;
export declare const refine: <A, B extends A>(refinement: (a: A) => a is B, id: string) => (from: Decoder<A>) => Decoder<B>;
/**
* @category combinators
* @since 2.2.0
* @since 2.2.7
*/
export declare function parse<A, B>(from: Decoder<A>, parser: (a: A) => Either<string, B>): Decoder<B>;
export declare const parse: <A, B>(parser: (a: A) => E.Either<DecodeError, B>) => (from: Decoder<A>) => Decoder<B>;
/**
* @category combinators
* @since 2.2.0
* @since 2.2.7
*/
export declare function nullable<A>(or: Decoder<A>): Decoder<null | A>;
export declare const nullable: <A>(or: Decoder<A>) => Decoder<null | A>;
/**
* @category combinators
* @since 2.2.0
* @since 2.2.7
*/
export declare function type<A>(properties: {
[K in keyof A]: Decoder<A[K]>;
}): Decoder<{
[K in keyof A]: A[K];
}>;
export declare const type: <A>(properties: { [K in keyof A]: Decoder<A[K]>; }) => Decoder<{ [K_1 in keyof A]: A[K_1]; }>;
/**
* @category combinators
* @since 2.2.0
* @since 2.2.7
*/
export declare function partial<A>(properties: {
[K in keyof A]: Decoder<A[K]>;
}): Decoder<Partial<{
[K in keyof A]: A[K];
}>>;
export declare const partial: <A>(properties: { [K in keyof A]: Decoder<A[K]>; }) => Decoder<Partial<{ [K_1 in keyof A]: A[K_1]; }>>;
/**
* @category combinators
* @since 2.2.0
* @since 2.2.7
*/
export declare function record<A>(codomain: Decoder<A>): Decoder<Record<string, A>>;
export declare const array: <A>(items: Decoder<A>) => Decoder<A[]>;
/**
* @category combinators
* @since 2.2.0
* @since 2.2.7
*/
export declare function array<A>(items: Decoder<A>): Decoder<Array<A>>;
export declare const record: <A>(codomain: Decoder<A>) => Decoder<Record<string, A>>;
/**
* @category combinators
* @since 2.2.0
* @since 2.2.7
*/
export declare function tuple<A extends ReadonlyArray<unknown>>(...components: {
export declare const tuple: <A extends readonly unknown[]>(...components: { [K in keyof A]: Decoder<A[K]>; }) => Decoder<A>;
/**
* @category combinators
* @since 2.2.7
*/
export declare const union: <A extends readonly [unknown, ...Array<unknown>]>(...members: {
[K in keyof A]: Decoder<A[K]>;
}): Decoder<A>;
}) => Decoder<A[number]>;
/**
* @category combinators
* @since 2.2.0
* @since 2.2.7
*/
export declare function intersection<A, B>(left: Decoder<A>, right: Decoder<B>): Decoder<A & B>;
export declare const intersect: <B>(right: Decoder<B>) => <A>(left: Decoder<A>) => Decoder<A & B>;
/**
* @category combinators
* @since 2.2.0
* @since 2.2.7
*/
export declare function lazy<A>(id: string, f: () => Decoder<A>): Decoder<A>;
export declare const sum: <T extends string>(tag: T) => <A>(members: { [K in keyof A]: Decoder<A[K]>; }) => Decoder<A[keyof A]>;
/**
* @category combinators
* @since 2.2.0
* @since 2.2.7
*/
export declare function sum<T extends string>(tag: T): <A>(members: {
[K in keyof A]: Decoder<A[K]>;
}) => Decoder<A[keyof A]>;
export declare const lazy: <A>(id: string, f: () => Decoder<A>) => Decoder<A>;
/**
* @category combinators
* @since 2.2.0
* @since 2.2.7
*/
export declare function union<A extends ReadonlyArray<unknown>>(...members: {
[K in keyof A]: Decoder<A[K]>;
}): Decoder<A[number]>;
export declare const compose: <A, B>(to: KD.KleisliDecoder<A, B>) => (from: Decoder<A>) => Decoder<B>;
/**
* @category Functor
* @since 2.2.0
* @since 2.2.7
*/

@@ -184,8 +161,8 @@ export declare const map: <A, B>(f: (a: A) => B) => (fa: Decoder<A>) => Decoder<B>;

* @category Alt
* @since 2.2.0
* @since 2.2.7
*/
export declare const alt: <A>(that: () => Decoder<A>) => (fa: Decoder<A>) => Decoder<A>;
export declare const alt: <A>(that: () => Decoder<A>) => (me: Decoder<A>) => Decoder<A>;
/**
* @category instances
* @since 2.2.0
* @since 2.2.7
*/

@@ -195,3 +172,3 @@ export declare const URI = "io-ts/Decoder";

* @category instances
* @since 2.2.0
* @since 2.2.7
*/

@@ -206,3 +183,3 @@ export declare type URI = typeof URI;

* @category instances
* @since 2.2.3
* @since 2.2.7
*/

@@ -212,3 +189,3 @@ export declare const functorDecoder: Functor1<URI>;

* @category instances
* @since 2.2.3
* @since 2.2.7
*/

@@ -218,4 +195,12 @@ export declare const altDecoder: Alt1<URI>;

* @category instances
* @since 2.2.3
* @since 2.2.7
*/
export declare const schemableDecoder: Schemable1<URI> & WithUnknownContainers1<URI> & WithUnion1<URI> & WithRefinement1<URI>;
export declare const schemableDecoder: Schemable1<URI> & WithUnknownContainers1<URI> & WithUnion1<URI> & WithRefine1<URI>;
/**
* @since 2.2.7
*/
export declare type TypeOf<D> = KD.TypeOf<D>;
/**
* @since 2.2.7
*/
export declare const draw: (e: DecodeError) => string;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.schemableDecoder = exports.altDecoder = exports.functorDecoder = exports.URI = exports.alt = exports.map = exports.union = exports.sum = exports.lazy = exports.intersection = exports.intersect = exports.tuple = exports.array = exports.record = exports.partial = exports.type = exports.nullable = exports.parse = exports.refinement = exports.withExpected = exports.UnknownRecord = exports.UnknownArray = exports.boolean = exports.number = exports.string = exports.never = exports.literal = exports.fromGuard = exports.of = exports.isNotEmpty = exports.failure = exports.success = exports.tree = void 0;
/**
* @since 2.2.0
*/
exports.stringify = exports.draw = exports.schemableDecoder = exports.altDecoder = exports.functorDecoder = exports.URI = exports.alt = exports.map = exports.compose = exports.lazy = exports.sum = exports.intersect = exports.union = exports.tuple = exports.record = exports.array = exports.partial = exports.type = exports.nullable = exports.parse = exports.refine = exports.mapLeftWithInput = exports.object = exports.UnknownRecord = exports.UnknownArray = exports.boolean = exports.number = exports.string = exports.literal = exports.fromGuard = exports.failure = exports.success = exports.error = void 0;
var E = require("fp-ts/lib/Either");
var pipeable_1 = require("fp-ts/lib/pipeable");
var DE = require("./DecodeError");
var FS = require("./FreeSemigroup");
var G = require("./Guard");
var Schemable_1 = require("./Schemable");
var empty = [];
var KD = require("./KleisliDecoder");
/**
* @category DecodeError
* @since 2.2.0
* @since 2.2.7
*/
function tree(value, forest) {
if (forest === void 0) { forest = empty; }
return {
value: value,
forest: forest
};
}
exports.tree = tree;
exports.error = KD.error;
/**
* @category DecodeError
* @since 2.2.0
* @since 2.2.7
*/
function success(a) {
return E.right(a);
}
exports.success = success;
exports.success = KD.success;
/**
* @category DecodeError
* @since 2.2.0
* @since 2.2.7
*/
function failure(message) {
return E.left([tree(message)]);
}
exports.failure = failure;
/**
* @category DecodeError
* @since 2.2.2
*/
function isNotEmpty(as) {
return as.length > 0;
}
exports.isNotEmpty = isNotEmpty;
exports.failure = KD.failure;
// -------------------------------------------------------------------------------------

@@ -53,37 +30,10 @@ // constructors

* @category constructors
* @since 2.2.3
* @since 2.2.7
*/
function of(a) {
return {
decode: function () { return success(a); }
};
}
exports.of = of;
exports.fromGuard = function (guard, expected) { return KD.fromRefinement(guard.is, expected); };
/**
* @category constructors
* @since 2.2.0
* @since 2.2.7
*/
function fromGuard(guard, expected) {
return {
decode: function (u) { return (guard.is(u) ? success(u) : failure("cannot decode " + JSON.stringify(u) + ", should be " + expected)); }
};
}
exports.fromGuard = fromGuard;
/**
* @category constructors
* @since 2.2.0
*/
function literal() {
var _a;
var values = [];
for (var _i = 0; _i < arguments.length; _i++) {
values[_i] = arguments[_i];
}
if (values.length === 0) {
return exports.never;
}
var expected = values.map(function (value) { return JSON.stringify(value); }).join(' | ');
return fromGuard((_a = G.schemableGuard).literal.apply(_a, values), expected);
}
exports.literal = literal;
exports.literal = KD.literal;
// -------------------------------------------------------------------------------------

@@ -94,30 +44,41 @@ // primitives

* @category primitives
* @since 2.2.0
* @since 2.2.7
*/
exports.never = fromGuard(G.never, 'never');
exports.string =
/*#__PURE__*/
exports.fromGuard(G.string, 'string');
/**
* @category primitives
* @since 2.2.0
* @since 2.2.7
*/
exports.string = fromGuard(G.string, 'string');
exports.number =
/*#__PURE__*/
exports.fromGuard(G.number, 'number');
/**
* @category primitives
* @since 2.2.0
* @since 2.2.7
*/
exports.number = fromGuard(G.number, 'number');
exports.boolean =
/*#__PURE__*/
exports.fromGuard(G.boolean, 'boolean');
/**
* @category primitives
* @since 2.2.0
* @since 2.2.7
*/
exports.boolean = fromGuard(G.boolean, 'boolean');
exports.UnknownArray =
/*#__PURE__*/
exports.fromGuard(G.UnknownArray, 'Array<unknown>');
/**
* @category primitives
* @since 2.2.0
* @since 2.2.7
*/
exports.UnknownArray = fromGuard(G.UnknownArray, 'Array<unknown>');
exports.UnknownRecord =
/*#__PURE__*/
exports.fromGuard(G.UnknownRecord, 'Record<string, unknown>');
/**
* @category primitives
* @since 2.2.0
* @internal
*/
exports.UnknownRecord = fromGuard(G.UnknownRecord, 'Record<string, unknown>');
exports.object =
/*#__PURE__*/
exports.fromGuard(G.object, 'object');
// -------------------------------------------------------------------------------------

@@ -128,193 +89,51 @@ // combinators

* @category combinators
* @since 2.2.0
* @since 2.2.7
*/
function withExpected(decoder, expected) {
return {
decode: function (u) {
return pipeable_1.pipe(decoder.decode(u), E.mapLeft(function (nea) { return expected(u, nea); }));
}
};
}
exports.withExpected = withExpected;
exports.mapLeftWithInput = KD.mapLeftWithInput;
/**
* @category combinators
* @since 2.2.0
* @since 2.2.7
*/
function refinement(from, refinement, expected) {
return {
decode: function (u) {
var e = from.decode(u);
if (E.isLeft(e)) {
return e;
}
var a = e.right;
return refinement(a) ? success(a) : failure("cannot refine " + JSON.stringify(u) + ", should be " + expected);
}
};
}
exports.refinement = refinement;
exports.refine = KD.refine;
/**
* @category combinators
* @since 2.2.0
* @since 2.2.7
*/
function parse(from, parser) {
return {
decode: function (u) {
var e = from.decode(u);
if (E.isLeft(e)) {
return e;
}
var pe = parser(e.right);
if (E.isLeft(pe)) {
return failure(pe.left);
}
return pe;
}
};
}
exports.parse = parse;
exports.parse = KD.parse;
/**
* @category combinators
* @since 2.2.0
* @since 2.2.7
*/
function nullable(or) {
return union(literal(null), or);
}
exports.nullable = nullable;
exports.nullable = KD.nullable;
/**
* @category combinators
* @since 2.2.0
* @since 2.2.7
*/
function type(properties) {
return {
decode: function (u) {
var e = exports.UnknownRecord.decode(u);
if (E.isLeft(e)) {
return e;
}
else {
var r = e.right;
var a = {};
var errors = [];
for (var k in properties) {
var e_1 = properties[k].decode(r[k]);
if (E.isLeft(e_1)) {
errors.push(tree("required property " + JSON.stringify(k), e_1.left));
}
else {
a[k] = e_1.right;
}
}
return isNotEmpty(errors) ? E.left(errors) : success(a);
}
}
};
}
exports.type = type;
exports.type = function (properties) {
return pipeable_1.pipe(exports.object, exports.compose(KD.type(properties)));
};
/**
* @category combinators
* @since 2.2.0
* @since 2.2.7
*/
function partial(properties) {
return {
decode: function (u) {
var e = exports.UnknownRecord.decode(u);
if (E.isLeft(e)) {
return e;
}
else {
var r = e.right;
var a = {};
var errors = [];
for (var k in properties) {
// don't add missing properties
if (k in r) {
var rk = r[k];
// don't strip undefined properties
if (rk === undefined) {
a[k] = undefined;
}
else {
var e_2 = properties[k].decode(rk);
if (E.isLeft(e_2)) {
errors.push(tree("optional property " + JSON.stringify(k), e_2.left));
}
else {
a[k] = e_2.right;
}
}
}
}
return isNotEmpty(errors) ? E.left(errors) : success(a);
}
}
};
}
exports.partial = partial;
exports.partial = function (properties) {
return pipeable_1.pipe(exports.object, exports.compose(KD.partial(properties)));
};
/**
* @category combinators
* @since 2.2.0
* @since 2.2.7
*/
function record(codomain) {
return {
decode: function (u) {
var e = exports.UnknownRecord.decode(u);
if (E.isLeft(e)) {
return e;
}
else {
var r = e.right;
var a = {};
var errors = [];
for (var k in r) {
var e_3 = codomain.decode(r[k]);
if (E.isLeft(e_3)) {
errors.push(tree("key " + JSON.stringify(k), e_3.left));
}
else {
a[k] = e_3.right;
}
}
return isNotEmpty(errors) ? E.left(errors) : success(a);
}
}
};
}
exports.record = record;
exports.array = function (items) { return pipeable_1.pipe(exports.UnknownArray, exports.compose(KD.array(items))); };
/**
* @category combinators
* @since 2.2.0
* @since 2.2.7
*/
function array(items) {
return {
decode: function (u) {
var e = exports.UnknownArray.decode(u);
if (E.isLeft(e)) {
return e;
}
else {
var us = e.right;
var len = us.length;
var a = new Array(len);
var errors = [];
for (var i = 0; i < len; i++) {
var e_4 = items.decode(us[i]);
if (E.isLeft(e_4)) {
errors.push(tree("item " + i, e_4.left));
}
else {
a[i] = e_4.right;
}
}
return isNotEmpty(errors) ? E.left(errors) : success(a);
}
}
};
}
exports.array = array;
exports.record = function (codomain) {
return pipeable_1.pipe(exports.UnknownRecord, exports.compose(KD.record(codomain)));
};
/**
* @category combinators
* @since 2.2.0
* @since 2.2.7
*/
function tuple() {
exports.tuple = function () {
var components = [];

@@ -324,143 +143,37 @@ for (var _i = 0; _i < arguments.length; _i++) {

}
return {
decode: function (u) {
var e = exports.UnknownArray.decode(u);
if (E.isLeft(e)) {
return e;
}
var us = e.right;
var a = [];
var errors = [];
for (var i = 0; i < components.length; i++) {
var e_5 = components[i].decode(us[i]);
if (E.isLeft(e_5)) {
errors.push(tree("component " + i, e_5.left));
}
else {
a.push(e_5.right);
}
}
return isNotEmpty(errors) ? E.left(errors) : success(a);
}
};
}
exports.tuple = tuple;
function typeOf(x) {
return x === null ? 'null' : typeof x;
}
return pipeable_1.pipe(exports.UnknownArray, exports.compose(KD.tuple.apply(KD, components)));
};
/**
* @internal
* @category combinators
* @since 2.2.7
*/
function intersect(a, b) {
if (a !== undefined && b !== undefined) {
var tx = typeOf(a);
var ty = typeOf(b);
if (tx === 'object' || ty === 'object') {
return Object.assign({}, a, b);
}
}
return b;
}
exports.intersect = intersect;
exports.union = KD.union;
/**
* @category combinators
* @since 2.2.0
* @since 2.2.7
*/
function intersection(left, right) {
return {
decode: function (u) {
var ea = left.decode(u);
var eb = right.decode(u);
if (E.isLeft(ea)) {
return E.isLeft(eb) ? E.left(ea.left.concat(eb.left)) : ea;
}
if (E.isLeft(eb)) {
return eb;
}
return success(intersect(ea.right, eb.right));
}
};
}
exports.intersection = intersection;
exports.intersect = KD.intersect;
/**
* @category combinators
* @since 2.2.0
* @since 2.2.7
*/
function lazy(id, f) {
var get = Schemable_1.memoize(f);
return {
decode: function (u) {
return pipeable_1.pipe(get().decode(u), E.mapLeft(function (nea) { return [tree(id, nea)]; }));
}
};
}
exports.lazy = lazy;
exports.sum = function (tag) { return function (members) {
return pipeable_1.pipe(exports.object, exports.compose(KD.sum(tag)(members)));
}; };
/**
* @category combinators
* @since 2.2.0
* @since 2.2.7
*/
function sum(tag) {
return function (members) {
var keys = Object.keys(members);
if (keys.length === 0) {
return exports.never;
}
var expected = keys.map(function (k) { return JSON.stringify(k); }).join(' | ');
return {
decode: function (u) {
var e = exports.UnknownRecord.decode(u);
if (E.isLeft(e)) {
return e;
}
var v = e.right[tag];
if (v in members) {
return members[v].decode(u);
}
return E.left([
tree("required property " + JSON.stringify(tag), [
tree("cannot decode " + JSON.stringify(v) + ", should be " + expected)
])
]);
}
};
};
}
exports.sum = sum;
exports.lazy = KD.lazy;
/**
* @category combinators
* @since 2.2.0
* @since 2.2.7
*/
function union() {
var members = [];
for (var _i = 0; _i < arguments.length; _i++) {
members[_i] = arguments[_i];
}
var len = members.length;
if (len === 0) {
return exports.never;
}
return {
decode: function (u) {
var e = members[0].decode(u);
if (E.isRight(e)) {
return e;
}
else {
var errors = [tree("member 0", e.left)];
for (var i = 1; i < len; i++) {
var e_6 = members[i].decode(u);
if (E.isRight(e_6)) {
return e_6;
}
else {
errors.push(tree("member " + i, e_6.left));
}
}
return E.left(errors);
}
}
};
}
exports.union = union;
exports.compose = KD.compose;
// -------------------------------------------------------------------------------------
// non-pipeables
// -------------------------------------------------------------------------------------
var map_ = function (fa, f) { return pipeable_1.pipe(fa, exports.map(f)); };
var alt_ = function (me, that) { return pipeable_1.pipe(me, exports.alt(that)); };
// -------------------------------------------------------------------------------------
// pipeables

@@ -470,22 +183,10 @@ // -------------------------------------------------------------------------------------

* @category Functor
* @since 2.2.0
* @since 2.2.7
*/
exports.map = function (f) { return function (fa) { return map_(fa, f); }; };
var map_ = function (fa, f) { return ({
decode: function (u) {
var e = fa.decode(u);
return E.isLeft(e) ? e : E.right(f(e.right));
}
}); };
exports.map = KD.map;
/**
* @category Alt
* @since 2.2.0
* @since 2.2.7
*/
exports.alt = function (that) { return function (fa) { return alt_(fa, that); }; };
var alt_ = function (fx, fy) { return ({
decode: function (u) {
var e = fx.decode(u);
return E.isLeft(e) ? fy().decode(u) : e;
}
}); };
exports.alt = KD.alt;
// -------------------------------------------------------------------------------------

@@ -496,3 +197,3 @@ // instances

* @category instances
* @since 2.2.0
* @since 2.2.7
*/

@@ -502,3 +203,3 @@ exports.URI = 'io-ts/Decoder';

* @category instances
* @since 2.2.3
* @since 2.2.7
*/

@@ -511,3 +212,3 @@ exports.functorDecoder = {

* @category instances
* @since 2.2.3
* @since 2.2.7
*/

@@ -521,23 +222,62 @@ exports.altDecoder = {

* @category instances
* @since 2.2.3
* @since 2.2.7
*/
exports.schemableDecoder = {
URI: exports.URI,
literal: literal,
literal: exports.literal,
string: exports.string,
number: exports.number,
boolean: exports.boolean,
nullable: nullable,
type: type,
partial: partial,
record: record,
array: array,
tuple: tuple,
intersection: intersection,
sum: sum,
lazy: lazy,
nullable: exports.nullable,
type: exports.type,
partial: exports.partial,
record: exports.record,
array: exports.array,
tuple: exports.tuple,
intersect: exports.intersect,
sum: exports.sum,
lazy: exports.lazy,
UnknownArray: exports.UnknownArray,
UnknownRecord: exports.UnknownRecord,
union: union,
refinement: refinement
union: exports.union,
refine: exports.refine
};
var empty = [];
var make = function (value, forest) {
if (forest === void 0) { forest = empty; }
return ({
value: value,
forest: forest
});
};
var drawTree = function (tree) { return tree.value + drawForest('\n', tree.forest); };
var drawForest = function (indentation, forest) {
var r = '';
var len = forest.length;
var tree;
for (var i = 0; i < len; i++) {
tree = forest[i];
var isLast = i === len - 1;
r += indentation + (isLast ? '└' : '├') + '─ ' + tree.value;
r += drawForest(indentation + (len > 1 && !isLast ? '│ ' : ' '), tree.forest);
}
return r;
};
var toTree = DE.fold({
Leaf: function (input, error) { return make("cannot decode " + JSON.stringify(input) + ", should be " + error); },
Key: function (key, kind, errors) { return make(kind + " property " + JSON.stringify(key), toForest(errors)); },
Index: function (index, kind, errors) { return make(kind + " index " + index, toForest(errors)); },
Member: function (index, errors) { return make("member " + index, toForest(errors)); },
Lazy: function (id, errors) { return make("lazy type " + id, toForest(errors)); }
});
var toForest = FS.fold(function (value) { return [toTree(value)]; }, function (left, right) { return toForest(left).concat(toForest(right)); });
/**
* @since 2.2.7
*/
exports.draw = function (e) { return toForest(e).map(drawTree).join('\n'); };
/**
* @internal
*/
exports.stringify =
/*#__PURE__*/
E.fold(exports.draw, function (a) { return JSON.stringify(a, null, 2); });
/**
* **This module is experimental**
*
* 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.
*
* A feature tagged as _Experimental_ is in a high state of flux, you're at risk of it changing without notice.
*
* @since 2.2.3

@@ -14,10 +21,2 @@ */

/**
* @since 2.2.3
*/
export declare type TypeOf<E> = E extends Encoder<any, infer A> ? A : never;
/**
* @since 2.2.3
*/
export declare type OutputOf<E> = E extends Encoder<infer O, any> ? O : never;
/**
* @category constructors

@@ -73,3 +72,3 @@ * @since 2.2.3

*/
export declare function intersection<O, A, P, B>(left: Encoder<O, A>, right: Encoder<P, B>): Encoder<O & P, A & B>;
export declare const intersect: <P, B>(right: Encoder<P, B>) => <O, A>(left: Encoder<O, A>) => Encoder<O & P, A & B>;
/**

@@ -79,3 +78,3 @@ * @category combinators

*/
export declare function sum<T extends string>(tag: T): <M extends Record<string, Encoder<any, any>>>(members: M) => Encoder<OutputOf<M[keyof M]>, TypeOf<M[keyof M]>>;
export declare function sum<T extends string>(tag: T): <MS extends Record<string, Encoder<any, any>>>(members: MS) => Encoder<OutputOf<MS[keyof MS]>, TypeOf<MS[keyof MS]>>;
/**

@@ -121,1 +120,9 @@ * @category combinators

export declare const categoryEncoder: Category2<URI>;
/**
* @since 2.2.3
*/
export declare type TypeOf<E> = E extends Encoder<any, infer A> ? A : never;
/**
* @since 2.2.3
*/
export declare type OutputOf<E> = E extends Encoder<infer O, any> ? O : never;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.categoryEncoder = exports.contravariantEncoder = exports.URI = exports.compose = exports.contramap = exports.lazy = exports.sum = exports.intersection = exports.tuple = exports.array = exports.record = exports.partial = exports.type = exports.nullable = exports.id = void 0;
var Decoder_1 = require("./Decoder");
exports.categoryEncoder = exports.contravariantEncoder = exports.URI = exports.compose = exports.contramap = exports.lazy = exports.sum = exports.intersect = exports.tuple = exports.array = exports.record = exports.partial = exports.type = exports.nullable = exports.id = void 0;
var Schemable_1 = require("./Schemable");

@@ -114,8 +113,5 @@ var function_1 = require("fp-ts/lib/function");

*/
function intersection(left, right) {
return {
encode: function (ab) { return Decoder_1.intersect(left.encode(ab), right.encode(ab)); }
};
}
exports.intersection = intersection;
exports.intersect = function (right) { return function (left) { return ({
encode: function (ab) { return Schemable_1.intersect_(left.encode(ab), right.encode(ab)); }
}); }; };
/**

@@ -122,0 +118,0 @@ * @category combinators

import * as E from 'fp-ts/lib/Eq';
import { Schemable1, WithRefinement1, WithUnknownContainers1 } from './Schemable';
import { Schemable1, WithRefine1, WithUnknownContainers1 } from './Schemable';
import Eq = E.Eq;

@@ -81,3 +81,3 @@ /**

*/
export declare function intersection<A, B>(left: Eq<A>, right: Eq<B>): Eq<A & B>;
export declare const intersect: <B>(right: E.Eq<B>) => <A>(left: E.Eq<A>) => E.Eq<A & B>;
/**

@@ -99,2 +99,2 @@ * @category combinators

*/
export declare const schemableEq: Schemable1<E.URI> & WithUnknownContainers1<E.URI> & WithRefinement1<E.URI>;
export declare const schemableEq: Schemable1<E.URI> & WithUnknownContainers1<E.URI> & WithRefine1<E.URI>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.schemableEq = exports.lazy = exports.sum = exports.intersection = exports.tuple = exports.array = exports.record = exports.partial = exports.type = exports.nullable = exports.UnknownRecord = exports.UnknownArray = exports.boolean = exports.number = exports.string = void 0;
exports.schemableEq = exports.lazy = exports.sum = exports.intersect = exports.tuple = exports.array = exports.record = exports.partial = exports.type = exports.nullable = exports.UnknownRecord = exports.UnknownArray = exports.boolean = exports.number = exports.string = void 0;
/**
* **This module is experimental**
*
* 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.
*
* A feature tagged as _Experimental_ is in a high state of flux, you're at risk of it changing without notice.
*
* @since 2.2.2

@@ -107,8 +114,5 @@ */

*/
function intersection(left, right) {
return {
equals: function (x, y) { return left.equals(x, y) && right.equals(x, y); }
};
}
exports.intersection = intersection;
exports.intersect = function (right) { return function (left) { return ({
equals: function (x, y) { return left.equals(x, y) && right.equals(x, y); }
}); }; };
/**

@@ -163,3 +167,3 @@ * @category combinators

tuple: exports.tuple,
intersection: intersection,
intersect: exports.intersect,
sum: sum,

@@ -169,3 +173,3 @@ lazy: function (_, f) { return lazy(f); },

UnknownRecord: exports.UnknownRecord,
refinement: function (from) { return from; }
refine: function () { return function (from) { return from; }; }
};

@@ -0,6 +1,3 @@

import { Literal, Schemable1, WithRefine1, WithUnion1, WithUnknownContainers1 } from './Schemable';
/**
* @since 2.2.0
*/
import { Literal, Schemable1, WithRefinement1, WithUnion1, WithUnknownContainers1 } from './Schemable';
/**
* @category model

@@ -20,3 +17,3 @@ * @since 2.2.0

*/
export declare function literal<A extends ReadonlyArray<Literal>>(...values: A): Guard<A[number]>;
export declare const literal: <A extends readonly [Literal, ...Literal[]]>(...values: A) => Guard<A[number]>;
/**

@@ -26,9 +23,6 @@ * @category primitives

*/
export declare const never: Guard<never>;
/**
* @category primitives
* @since 2.2.0
*/
export declare const string: Guard<string>;
/**
* Note: `NaN` is excluded.
*
* @category primitives

@@ -57,3 +51,3 @@ * @since 2.2.0

*/
export declare function refinement<A, B extends A>(from: Guard<A>, refinement: (a: A) => a is B): Guard<B>;
export declare const refine: <A, B extends A>(refinement: (a: A) => a is B) => (from: Guard<A>) => Guard<B>;
/**

@@ -63,3 +57,3 @@ * @category combinators

*/
export declare function nullable<A>(or: Guard<A>): Guard<null | A>;
export declare const nullable: <A>(or: Guard<A>) => Guard<A | null>;
/**

@@ -69,7 +63,3 @@ * @category combinators

*/
export declare function type<A>(properties: {
[K in keyof A]: Guard<A[K]>;
}): Guard<{
[K in keyof A]: A[K];
}>;
export declare const type: <A>(properties: { [K in keyof A]: Guard<A[K]>; }) => Guard<{ [K_1 in keyof A]: A[K_1]; }>;
/**

@@ -79,7 +69,3 @@ * @category combinators

*/
export declare function partial<A>(properties: {
[K in keyof A]: Guard<A[K]>;
}): Guard<Partial<{
[K in keyof A]: A[K];
}>>;
export declare const partial: <A>(properties: { [K in keyof A]: Guard<A[K]>; }) => Guard<Partial<{ [K_1 in keyof A]: A[K_1]; }>>;
/**

@@ -89,3 +75,3 @@ * @category combinators

*/
export declare function record<A>(codomain: Guard<A>): Guard<Record<string, A>>;
export declare const record: <A>(codomain: Guard<A>) => Guard<Record<string, A>>;
/**

@@ -95,3 +81,3 @@ * @category combinators

*/
export declare function array<A>(items: Guard<A>): Guard<Array<A>>;
export declare const array: <A>(items: Guard<A>) => Guard<A[]>;
/**

@@ -101,5 +87,3 @@ * @category combinators

*/
export declare function tuple<A extends ReadonlyArray<unknown>>(...components: {
[K in keyof A]: Guard<A[K]>;
}): Guard<A>;
export declare const tuple: <A extends readonly unknown[]>(...components: { [K in keyof A]: Guard<A[K]>; }) => Guard<A>;
/**

@@ -109,3 +93,3 @@ * @category combinators

*/
export declare function intersection<A, B>(left: Guard<A>, right: Guard<B>): Guard<A & B>;
export declare const intersect: <B>(right: Guard<B>) => <A>(left: Guard<A>) => Guard<A & B>;
/**

@@ -115,5 +99,3 @@ * @category combinators

*/
export declare function union<A extends ReadonlyArray<unknown>>(...members: {
[K in keyof A]: Guard<A[K]>;
}): Guard<A[number]>;
export declare const union: <A extends readonly [unknown, ...unknown[]]>(...members: { [K in keyof A]: Guard<A[K]>; }) => Guard<A[number]>;
/**

@@ -123,5 +105,3 @@ * @category combinators

*/
export declare function sum<T extends string>(tag: T): <A>(members: {
[K in keyof A]: Guard<A[K]>;
}) => Guard<A[keyof A]>;
export declare const sum: <T extends string>(tag: T) => <A>(members: { [K in keyof A]: Guard<A[K]>; }) => Guard<A[keyof A]>;
/**

@@ -131,3 +111,3 @@ * @category combinators

*/
export declare function lazy<A>(f: () => Guard<A>): Guard<A>;
export declare const lazy: <A>(f: () => Guard<A>) => Guard<A>;
/**

@@ -152,2 +132,2 @@ * @category instances

*/
export declare const schemableGuard: Schemable1<URI> & WithUnknownContainers1<URI> & WithUnion1<URI> & WithRefinement1<URI>;
export declare const schemableGuard: Schemable1<URI> & WithUnknownContainers1<URI> & WithUnion1<URI> & WithRefine1<URI>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.schemableGuard = exports.URI = exports.lazy = exports.sum = exports.union = exports.intersection = exports.tuple = exports.array = exports.record = exports.partial = exports.type = exports.nullable = exports.refinement = exports.UnknownRecord = exports.UnknownArray = exports.boolean = exports.number = exports.string = exports.never = exports.literal = void 0;
exports.schemableGuard = exports.URI = exports.lazy = exports.sum = exports.union = exports.intersect = exports.tuple = exports.array = exports.record = exports.partial = exports.type = exports.nullable = exports.refine = exports.object = exports.UnknownRecord = exports.UnknownArray = exports.boolean = exports.number = exports.string = exports.literal = void 0;
/**
* **This module is experimental**
*
* 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.
*
* A feature tagged as _Experimental_ is in a high state of flux, you're at risk of it changing without notice.
*
* @since 2.2.0
*/
var pipeable_1 = require("fp-ts/lib/pipeable");
var Schemable_1 = require("./Schemable");

@@ -15,3 +23,3 @@ // -------------------------------------------------------------------------------------

*/
function literal() {
exports.literal = function () {
var values = [];

@@ -21,7 +29,6 @@ for (var _i = 0; _i < arguments.length; _i++) {

}
return {
return ({
is: function (u) { return values.findIndex(function (a) { return a === u; }) !== -1; }
};
}
exports.literal = literal;
});
};
// -------------------------------------------------------------------------------------

@@ -34,9 +41,2 @@ // primitives

*/
exports.never = {
is: function (_u) { return false; }
};
/**
* @category primitives
* @since 2.2.0
*/
exports.string = {

@@ -46,2 +46,4 @@ is: function (u) { return typeof u === 'string'; }

/**
* Note: `NaN` is excluded.
*
* @category primitives

@@ -51,3 +53,3 @@ * @since 2.2.0

exports.number = {
is: function (u) { return typeof u === 'number'; }
is: function (u) { return typeof u === 'number' && !isNaN(u); }
};

@@ -75,2 +77,8 @@ /**

};
/**
* @internal
*/
exports.object = {
is: function (u) { return u != null && !exports.string.is(u) && !exports.number.is(u) && !exports.boolean.is(u); }
};
// -------------------------------------------------------------------------------------

@@ -83,8 +91,5 @@ // combinators

*/
function refinement(from, refinement) {
return {
is: function (u) { return from.is(u) && refinement(u); }
};
}
exports.refinement = refinement;
exports.refine = function (refinement) { return function (from) { return ({
is: function (u) { return from.is(u) && refinement(u); }
}); }; };
/**

@@ -94,8 +99,5 @@ * @category combinators

*/
function nullable(or) {
return {
is: function (u) { return u === null || or.is(u); }
};
}
exports.nullable = nullable;
exports.nullable = function (or) { return ({
is: function (u) { return u === null || or.is(u); }
}); };
/**

@@ -105,4 +107,4 @@ * @category combinators

*/
function type(properties) {
return refinement(exports.UnknownRecord, function (r) {
exports.type = function (properties) {
return pipeable_1.pipe(exports.UnknownRecord, exports.refine(function (r) {
for (var k in properties) {

@@ -114,5 +116,4 @@ if (!(k in r) || !properties[k].is(r[k])) {

return true;
});
}
exports.type = type;
}));
};
/**

@@ -122,4 +123,4 @@ * @category combinators

*/
function partial(properties) {
return refinement(exports.UnknownRecord, function (r) {
exports.partial = function (properties) {
return pipeable_1.pipe(exports.UnknownRecord, exports.refine(function (r) {
for (var k in properties) {

@@ -132,5 +133,4 @@ var v = r[k];

return true;
});
}
exports.partial = partial;
}));
};
/**

@@ -140,4 +140,4 @@ * @category combinators

*/
function record(codomain) {
return refinement(exports.UnknownRecord, function (r) {
exports.record = function (codomain) {
return pipeable_1.pipe(exports.UnknownRecord, exports.refine(function (r) {
for (var k in r) {

@@ -149,5 +149,4 @@ if (!codomain.is(r[k])) {

return true;
});
}
exports.record = record;
}));
};
/**

@@ -157,6 +156,5 @@ * @category combinators

*/
function array(items) {
return refinement(exports.UnknownArray, function (us) { return us.every(items.is); });
}
exports.array = array;
exports.array = function (items) {
return pipeable_1.pipe(exports.UnknownArray, exports.refine(function (us) { return us.every(items.is); }));
};
/**

@@ -166,3 +164,3 @@ * @category combinators

*/
function tuple() {
exports.tuple = function () {
var components = [];

@@ -172,7 +170,6 @@ for (var _i = 0; _i < arguments.length; _i++) {

}
return {
return ({
is: function (u) { return Array.isArray(u) && u.length === components.length && components.every(function (c, i) { return c.is(u[i]); }); }
};
}
exports.tuple = tuple;
});
};
/**

@@ -182,8 +179,5 @@ * @category combinators

*/
function intersection(left, right) {
return {
is: function (u) { return left.is(u) && right.is(u); }
};
}
exports.intersection = intersection;
exports.intersect = function (right) { return function (left) { return ({
is: function (u) { return left.is(u) && right.is(u); }
}); }; };
/**

@@ -193,3 +187,3 @@ * @category combinators

*/
function union() {
exports.union = function () {
var members = [];

@@ -199,7 +193,6 @@ for (var _i = 0; _i < arguments.length; _i++) {

}
return {
return ({
is: function (u) { return members.some(function (m) { return m.is(u); }); }
};
}
exports.union = union;
});
};
/**

@@ -209,14 +202,11 @@ * @category combinators

*/
function sum(tag) {
return function (members) {
return refinement(exports.UnknownRecord, function (r) {
var v = r[tag];
if (v in members) {
return members[v].is(r);
}
return false;
});
};
}
exports.sum = sum;
exports.sum = function (tag) { return function (members) {
return pipeable_1.pipe(exports.UnknownRecord, exports.refine(function (r) {
var v = r[tag];
if (v in members) {
return members[v].is(r);
}
return false;
}));
}; };
/**

@@ -226,3 +216,3 @@ * @category combinators

*/
function lazy(f) {
exports.lazy = function (f) {
var get = Schemable_1.memoize(f);

@@ -232,4 +222,3 @@ return {

};
}
exports.lazy = lazy;
};
// -------------------------------------------------------------------------------------

@@ -249,19 +238,19 @@ // instances

URI: exports.URI,
literal: literal,
literal: exports.literal,
string: exports.string,
number: exports.number,
boolean: exports.boolean,
nullable: nullable,
type: type,
partial: partial,
record: record,
array: array,
tuple: tuple,
intersection: intersection,
sum: sum,
lazy: function (_, f) { return lazy(f); },
nullable: exports.nullable,
type: exports.type,
partial: exports.partial,
record: exports.record,
array: exports.array,
tuple: exports.tuple,
intersect: exports.intersect,
sum: exports.sum,
lazy: function (_, f) { return exports.lazy(f); },
UnknownArray: exports.UnknownArray,
UnknownRecord: exports.UnknownRecord,
union: union,
refinement: refinement
union: exports.union,
refine: exports.refine
};
/**
* **This module is experimental**
*
* 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.
*
* A feature tagged as _Experimental_ is in a high state of flux, you're at risk of it changing without notice.
*
* @since 2.2.3

@@ -8,3 +15,3 @@ */

import * as C from './Codec';
import { Literal, Schemable1, WithRefinement1 } from './Schemable';
import { Literal, Schemable1, WithRefine1 } from './Schemable';
/**

@@ -34,3 +41,3 @@ * Laws:

*/
export declare const literal: <A extends ReadonlyArray<Literal>>(...values: A) => JsonCodec<A[number]>;
export declare const literal: <A extends readonly [Literal, ...Array<Literal>]>(...values: A) => JsonCodec<A[number]>;
/**

@@ -55,3 +62,3 @@ * @category primitives

*/
export declare const withExpected: <A>(codec: JsonCodec<A>, expected: (actual: unknown, e: D.DecodeError) => D.DecodeError) => JsonCodec<A>;
export declare const mapLeftWithInput: (f: (actual: unknown, e: D.DecodeError) => D.DecodeError) => <A>(codec: JsonCodec<A>) => JsonCodec<A>;
/**

@@ -61,3 +68,3 @@ * @category combinators

*/
export declare const refinement: <A, B extends A>(from: JsonCodec<A>, refinement: (a: A) => a is B, expected: string) => JsonCodec<B>;
export declare const refine: <A, B extends A>(refinement: (a: A) => a is B, id: string) => (from: JsonCodec<A>) => JsonCodec<B>;
/**

@@ -107,3 +114,3 @@ * @category combinators

*/
export declare const intersection: <A, B>(left: JsonCodec<A>, right: JsonCodec<B>) => JsonCodec<A & B>;
export declare const intersect: <B>(right: JsonCodec<B>) => <A>(left: JsonCodec<A>) => JsonCodec<A & B>;
/**

@@ -150,2 +157,2 @@ * @category combinators

*/
export declare const schemableJsonCodec: Schemable1<URI> & WithRefinement1<URI>;
export declare const schemableJsonCodec: Schemable1<URI> & WithRefine1<URI>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.schemableJsonCodec = exports.invariantJsonCodec = exports.URI = exports.imap = exports.lazy = exports.sum = exports.intersection = exports.tuple = exports.array = exports.record = exports.partial = exports.type = exports.nullable = exports.refinement = exports.withExpected = exports.boolean = exports.number = exports.string = exports.literal = exports.make = void 0;
exports.schemableJsonCodec = exports.invariantJsonCodec = exports.URI = exports.imap = exports.lazy = exports.sum = exports.intersect = exports.tuple = exports.array = exports.record = exports.partial = exports.type = exports.nullable = exports.refine = exports.mapLeftWithInput = exports.boolean = exports.number = exports.string = exports.literal = exports.make = void 0;
var C = require("./Codec");

@@ -43,3 +43,3 @@ // -------------------------------------------------------------------------------------

*/
exports.withExpected = C.withExpected;
exports.mapLeftWithInput = C.mapLeftWithInput;
/**

@@ -49,3 +49,3 @@ * @category combinators

*/
exports.refinement = C.refinement;
exports.refine = C.refine;
/**

@@ -85,3 +85,3 @@ * @category combinators

*/
exports.intersection = C.intersection;
exports.intersect = C.intersect;
/**

@@ -137,6 +137,6 @@ * @category combinators

tuple: exports.tuple,
intersection: exports.intersection,
intersect: exports.intersect,
sum: exports.sum,
lazy: exports.lazy,
refinement: exports.refinement
refine: exports.refine
};
/**
* **This module is experimental**
*
* 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.
*
* A feature tagged as _Experimental_ is in a high state of flux, you're at risk of it changing without notice.
*
* @since 2.2.3

@@ -11,3 +18,3 @@ */

*/
export interface JsonArray extends Array<Json> {
export interface JsonArray extends ReadonlyArray<Json> {
}

@@ -18,5 +25,5 @@ /**

*/
export declare type JsonObject = {
[key: string]: Json;
};
export interface JsonRecord {
readonly [key: string]: Json;
}
/**

@@ -26,3 +33,3 @@ * @category model

*/
export declare type Json = null | string | number | boolean | JsonObject | JsonArray;
export declare type Json = null | string | number | boolean | JsonRecord | JsonArray;
/**

@@ -88,3 +95,3 @@ * @category model

*/
export declare const intersection: <A, B>(left: JsonEncoder<A>, right: JsonEncoder<B>) => JsonEncoder<A & B>;
export declare const intersect: <B>(right: JsonEncoder<B>) => <A>(left: JsonEncoder<A>) => JsonEncoder<A & B>;
/**

@@ -91,0 +98,0 @@ * @category combinators

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.schemableJsonEncoder = exports.contravariantJsonEncoder = exports.URI = exports.contramap = exports.lazy = exports.sum = exports.intersection = exports.tuple = exports.array = exports.record = exports.partial = exports.type = exports.nullable = exports.id = void 0;
exports.schemableJsonEncoder = exports.contravariantJsonEncoder = exports.URI = exports.contramap = exports.lazy = exports.sum = exports.intersect = exports.tuple = exports.array = exports.record = exports.partial = exports.type = exports.nullable = exports.id = void 0;
var function_1 = require("fp-ts/lib/function");

@@ -56,3 +56,3 @@ var E = require("./Encoder");

*/
exports.intersection = E.intersection;
exports.intersect = E.intersect;
/**

@@ -108,5 +108,5 @@ * @category combinators

tuple: exports.tuple,
intersection: exports.intersection,
intersect: exports.intersect,
sum: exports.sum,
lazy: function (_, f) { return exports.lazy(f); }
};
/**
* **This module is experimental**
*
* 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.
*
* A feature tagged as _Experimental_ is in a high state of flux, you're at risk of it changing without notice.
*
* @since 2.2.0

@@ -3,0 +10,0 @@ */

/**
* **This module is experimental**
*
* 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.
*
* A feature tagged as _Experimental_ is in a high state of flux, you're at risk of it changing without notice.
*
* @since 2.2.0

@@ -14,3 +21,3 @@ */

readonly URI: S;
readonly literal: <A extends ReadonlyArray<Literal>>(...values: A) => HKT<S, A[number]>;
readonly literal: <A extends readonly [Literal, ...Array<Literal>]>(...values: A) => HKT<S, A[number]>;
readonly string: HKT<S, string>;

@@ -35,3 +42,3 @@ readonly number: HKT<S, number>;

}) => HKT<S, A>;
readonly intersection: <A, B>(left: HKT<S, A>, right: HKT<S, B>) => HKT<S, A & B>;
readonly intersect: <B>(right: HKT<S, B>) => <A>(left: HKT<S, A>) => HKT<S, A & B>;
readonly sum: <T extends string>(tag: T) => <A>(members: {

@@ -47,3 +54,3 @@ [K in keyof A]: HKT<S, A[K]>;

readonly URI: S;
readonly literal: <A extends ReadonlyArray<Literal>>(...values: A) => Kind<S, A[number]>;
readonly literal: <A extends readonly [Literal, ...Array<Literal>]>(...values: A) => Kind<S, A[number]>;
readonly string: Kind<S, string>;

@@ -68,3 +75,3 @@ readonly number: Kind<S, number>;

}) => Kind<S, A>;
readonly intersection: <A, B>(left: Kind<S, A>, right: Kind<S, B>) => Kind<S, A & B>;
readonly intersect: <B>(right: Kind<S, B>) => <A>(left: Kind<S, A>) => Kind<S, A & B>;
readonly sum: <T extends string>(tag: T) => <A>(members: {

@@ -93,3 +100,3 @@ [K in keyof A]: Kind<S, A[K]>;

export interface WithUnion<S> {
readonly union: <A extends ReadonlyArray<unknown>>(...members: {
readonly union: <A extends readonly [unknown, ...Array<unknown>]>(...members: {
[K in keyof A]: HKT<S, A[K]>;

@@ -102,3 +109,3 @@ }) => HKT<S, A[number]>;

export interface WithUnion1<S extends URIS> {
readonly union: <A extends ReadonlyArray<unknown>>(...members: {
readonly union: <A extends readonly [unknown, ...Array<unknown>]>(...members: {
[K in keyof A]: Kind<S, A[K]>;

@@ -110,4 +117,4 @@ }) => Kind<S, A[number]>;

*/
export interface WithRefinement<S> {
readonly refinement: <A, B extends A>(from: HKT<S, A>, refinement: (a: A) => a is B, expected: string) => HKT<S, B>;
export interface WithRefine<S> {
readonly refine: <A, B extends A>(refinement: (a: A) => a is B, id: string) => (from: HKT<S, A>) => HKT<S, B>;
}

@@ -117,4 +124,4 @@ /**

*/
export interface WithRefinement1<S extends URIS> {
readonly refinement: <A, B extends A>(from: Kind<S, A>, refinement: (a: A) => a is B, expected: string) => Kind<S, B>;
export interface WithRefine1<S extends URIS> {
readonly refine: <A, B extends A>(refinement: (a: A) => a is B, id: string) => (from: Kind<S, A>) => Kind<S, B>;
}

@@ -121,0 +128,0 @@ /**

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.memoize = void 0;
exports.intersect_ = exports.memoize = void 0;
/**

@@ -19,1 +19,18 @@ * @since 2.2.0

exports.memoize = memoize;
// -------------------------------------------------------------------------------------
// utils
// -------------------------------------------------------------------------------------
var typeOf = function (x) { return (x === null ? 'null' : typeof x); };
/**
* @internal
*/
exports.intersect_ = function (a, b) {
if (a !== undefined && b !== undefined) {
var tx = typeOf(a);
var ty = typeOf(b);
if (tx === 'object' || ty === 'object') {
return Object.assign({}, a, b);
}
}
return b;
};
/**
* **This module is experimental**
*
* 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.
*
* A feature tagged as _Experimental_ is in a high state of flux, you're at risk of it changing without notice.
*
* @since 2.2.3
*/
import * as t from './index';
import { Literal, Schemable1, WithUnion1, WithRefinement1, WithUnknownContainers1 } from './Schemable';
import { Literal, Schemable1, WithUnion1, WithRefine1, WithUnknownContainers1 } from './Schemable';
/**

@@ -16,3 +23,3 @@ * @category model

*/
export declare function literal<A extends ReadonlyArray<Literal>>(...values: A): Type<A[number]>;
export declare const literal: <A extends readonly [Literal, ...Literal[]]>(...values: A) => Type<A[number]>;
/**

@@ -47,3 +54,3 @@ * @category primitives

*/
export declare function refinement<A, B extends A>(from: Type<A>, refinement: (a: A) => a is B, expected: string): Type<B>;
export declare const refine: <A, B extends A>(refinement: (a: A) => a is B, id: string) => (from: Type<A>) => Type<B>;
/**

@@ -53,3 +60,3 @@ * @category combinators

*/
export declare function nullable<A>(or: Type<A>): Type<null | A>;
export declare const nullable: <A>(or: Type<A>) => Type<A | null>;
/**

@@ -59,7 +66,3 @@ * @category combinators

*/
export declare function type<A>(properties: {
[K in keyof A]: Type<A[K]>;
}): Type<{
[K in keyof A]: A[K];
}>;
export declare const type: <A>(properties: { [K in keyof A]: Type<A[K]>; }) => Type<{ [K_1 in keyof A]: A[K_1]; }>;
/**

@@ -69,7 +72,3 @@ * @category combinators

*/
export declare function partial<A>(properties: {
[K in keyof A]: Type<A[K]>;
}): Type<Partial<{
[K in keyof A]: A[K];
}>>;
export declare const partial: <A>(properties: { [K in keyof A]: Type<A[K]>; }) => Type<Partial<{ [K_1 in keyof A]: A[K_1]; }>>;
/**

@@ -79,3 +78,3 @@ * @category combinators

*/
export declare function record<A>(codomain: Type<A>): Type<Record<string, A>>;
export declare const record: <A>(codomain: Type<A>) => Type<Record<string, A>>;
/**

@@ -85,3 +84,3 @@ * @category combinators

*/
export declare function array<A>(items: Type<A>): Type<Array<A>>;
export declare const array: <A>(items: Type<A>) => Type<A[]>;
/**

@@ -91,5 +90,3 @@ * @category combinators

*/
export declare function tuple<A extends ReadonlyArray<unknown>>(...components: {
[K in keyof A]: Type<A[K]>;
}): Type<A>;
export declare const tuple: <A extends readonly unknown[]>(...components: { [K in keyof A]: Type<A[K]>; }) => Type<A>;
/**

@@ -99,3 +96,3 @@ * @category combinators

*/
export declare function intersection<A, B>(left: Type<A>, right: Type<B>): Type<A & B>;
export declare const intersect: <B>(right: Type<B>) => <A>(left: Type<A>) => Type<A & B>;
/**

@@ -105,3 +102,3 @@ * @category combinators

*/
export declare function lazy<A>(id: string, f: () => Type<A>): Type<A>;
export declare const lazy: <A>(id: string, f: () => Type<A>) => Type<A>;
/**

@@ -111,5 +108,3 @@ * @category combinators

*/
export declare function sum<T extends string>(_tag: T): <A>(members: {
[K in keyof A]: Type<A[K]>;
}) => Type<A[keyof A]>;
export declare const sum: <T extends string>(_tag: T) => <A>(members: { [K in keyof A]: Type<A[K]>; }) => Type<A[keyof A]>;
/**

@@ -119,5 +114,3 @@ * @category combinators

*/
export declare function union<A extends ReadonlyArray<unknown>>(...members: {
[K in keyof A]: Type<A[K]>;
}): Type<A[number]>;
export declare const union: <A extends readonly [unknown, ...unknown[]]>(...members: { [K in keyof A]: Type<A[K]>; }) => Type<A[number]>;
/**

@@ -142,2 +135,2 @@ * @category instances

*/
export declare const schemableType: Schemable1<URI> & WithUnknownContainers1<URI> & WithUnion1<URI> & WithRefinement1<URI>;
export declare const schemableType: Schemable1<URI> & WithUnknownContainers1<URI> & WithUnion1<URI> & WithRefine1<URI>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.schemableType = exports.URI = exports.union = exports.sum = exports.lazy = exports.intersection = exports.tuple = exports.array = exports.record = exports.partial = exports.type = exports.nullable = exports.refinement = exports.UnknownRecord = exports.UnknownArray = exports.boolean = exports.number = exports.string = exports.literal = void 0;
exports.schemableType = exports.URI = exports.union = exports.sum = exports.lazy = exports.intersect = exports.tuple = exports.array = exports.record = exports.partial = exports.type = exports.nullable = exports.refine = exports.UnknownRecord = exports.UnknownArray = exports.boolean = exports.number = exports.string = exports.literal = void 0;
/**
* **This module is experimental**
*
* 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.
*
* A feature tagged as _Experimental_ is in a high state of flux, you're at risk of it changing without notice.
*
* @since 2.2.3
*/
var t = require("./index");
var E = require("fp-ts/lib/Either");
var pipeable_1 = require("fp-ts/lib/pipeable");
// -------------------------------------------------------------------------------------

@@ -15,3 +24,3 @@ // constructors

*/
function literal() {
exports.literal = function () {
var values = [];

@@ -22,4 +31,3 @@ for (var _i = 0; _i < arguments.length; _i++) {

return t.union(values.map(function (v) { return t.literal(v); }));
}
exports.literal = literal;
};
// -------------------------------------------------------------------------------------

@@ -37,3 +45,5 @@ // primitives

*/
exports.number = t.number;
exports.number = new t.Type(t.number.name, t.number.is, function (u, c) {
return pipeable_1.pipe(t.number.decode(u), E.chain(function (n) { return (isNaN(n) ? t.failure(u, c) : t.success(n)); }));
}, t.number.encode);
/**

@@ -61,7 +71,6 @@ * @category primitives

*/
function refinement(from, refinement, expected) {
exports.refine = function (refinement, id) { return function (from) {
// tslint:disable-next-line: deprecation
return t.refinement(from, refinement, expected);
}
exports.refinement = refinement;
return t.refinement(from, refinement, id);
}; };
/**

@@ -71,6 +80,3 @@ * @category combinators

*/
function nullable(or) {
return t.union([t.null, or]);
}
exports.nullable = nullable;
exports.nullable = function (or) { return t.union([t.null, or]); };
/**

@@ -80,6 +86,5 @@ * @category combinators

*/
function type(properties) {
exports.type = function (properties) {
return t.type(properties);
}
exports.type = type;
};
/**

@@ -89,6 +94,5 @@ * @category combinators

*/
function partial(properties) {
exports.partial = function (properties) {
return t.partial(properties);
}
exports.partial = partial;
};
/**

@@ -98,6 +102,3 @@ * @category combinators

*/
function record(codomain) {
return t.record(t.string, codomain);
}
exports.record = record;
exports.record = function (codomain) { return t.record(t.string, codomain); };
/**

@@ -107,6 +108,3 @@ * @category combinators

*/
function array(items) {
return t.array(items);
}
exports.array = array;
exports.array = function (items) { return t.array(items); };
/**

@@ -116,3 +114,3 @@ * @category combinators

*/
function tuple() {
exports.tuple = function () {
var components = [];

@@ -123,4 +121,3 @@ for (var _i = 0; _i < arguments.length; _i++) {

return t.tuple(components);
}
exports.tuple = tuple;
};
/**

@@ -130,6 +127,3 @@ * @category combinators

*/
function intersection(left, right) {
return t.intersection([left, right]);
}
exports.intersection = intersection;
exports.intersect = function (right) { return function (left) { return t.intersection([left, right]); }; };
/**

@@ -139,6 +133,3 @@ * @category combinators

*/
function lazy(id, f) {
return t.recursion(id, f);
}
exports.lazy = lazy;
exports.lazy = function (id, f) { return t.recursion(id, f); };
/**

@@ -148,6 +139,5 @@ * @category combinators

*/
function sum(_tag) {
return function (members) { return t.union(Object.values(members)); };
}
exports.sum = sum;
exports.sum = function (_tag) { return function (members) {
return t.union(Object.values(members));
}; };
/**

@@ -157,3 +147,3 @@ * @category combinators

*/
function union() {
exports.union = function () {
var members = [];

@@ -164,4 +154,3 @@ for (var _i = 0; _i < arguments.length; _i++) {

return t.union(members);
}
exports.union = union;
};
// -------------------------------------------------------------------------------------

@@ -181,19 +170,19 @@ // instances

URI: exports.URI,
literal: literal,
literal: exports.literal,
string: exports.string,
number: exports.number,
boolean: exports.boolean,
nullable: nullable,
type: type,
partial: partial,
record: record,
array: array,
tuple: tuple,
intersection: intersection,
sum: sum,
lazy: lazy,
nullable: exports.nullable,
type: exports.type,
partial: exports.partial,
record: exports.record,
array: exports.array,
tuple: exports.tuple,
intersect: exports.intersect,
sum: exports.sum,
lazy: exports.lazy,
UnknownArray: exports.UnknownArray,
UnknownRecord: exports.UnknownRecord,
union: union,
refinement: refinement
union: exports.union,
refine: exports.refine
};
{
"name": "io-ts",
"version": "2.2.6",
"version": "2.2.7",
"description": "TypeScript runtime type system for IO decoding/encoding",

@@ -25,3 +25,3 @@ "files": [

"mocha": "TS_NODE_CACHE=false mocha -r ts-node/register test/*.ts",
"doctoc": "doctoc README.md Type.md Decoder.md Encoder.md Codec.md Eq.md Schema.md",
"doctoc": "doctoc README.md index.md Decoder.md Encoder.md Codec.md Eq.md Schema.md",
"docs": "docs-ts",

@@ -28,0 +28,0 @@ "import-path-rewrite": "import-path-rewrite"

@@ -33,3 +33,3 @@ [![build status](https://img.shields.io/travis/gcanti/io-ts/master.svg?style=flat-square)](https://travis-ci.org/gcanti/io-ts)

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.
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.

@@ -41,1 +41,3 @@ - [`Decoder.ts` module](Decoder.md)

- [`Schema.ts` module (advanced feature)](Schema.md)
(\*) A feature tagged as _Experimental_ is in a high state of flux, you're at risk of it changing without notice.
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