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.13 to 2.2.14

6

CHANGELOG.md

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

# 2.2.14
- **Experimental**
- `Guard`
- relax `UnknownRecord` check, closes #559 (@waynevanson)
# 2.2.13

@@ -19,0 +25,0 @@

13

es6/Codec.d.ts

@@ -0,1 +1,12 @@

/**
* **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 { Refinement } from 'fp-ts/es6/function'
import { Invariant3 } from 'fp-ts/es6/Invariant'

@@ -69,3 +80,3 @@ import * as D from './Decoder'

export declare const refine: <A, B extends A>(
refinement: (a: A) => a is B,
refinement: Refinement<A, B>,
id: string

@@ -72,0 +83,0 @@ ) => <I, O>(from: Codec<I, O, A>) => Codec<I, O, B>

2

es6/Decoder.d.ts

@@ -110,3 +110,3 @@ /**

export declare const refine: <A, B extends A>(
refinement: (a: A) => a is B,
refinement: Refinement<A, B>,
id: string

@@ -113,0 +113,0 @@ ) => <I>(from: Decoder<I, A>) => Decoder<I, B>

@@ -420,7 +420,8 @@ import * as E from 'fp-ts/es6/Either';

res.push(toTree(focus.value));
if (stack.length === 0) {
var tmp = stack.pop();
if (tmp === undefined) {
return res;
}
else {
focus = stack.pop();
focus = tmp;
}

@@ -427,0 +428,0 @@ break;

@@ -0,1 +1,12 @@

/**
* **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 { Refinement } from 'fp-ts/es6/function'
import { Literal, Schemable1, WithRefine1, WithUnion1, WithUnknownContainers1 } from './Schemable'

@@ -54,3 +65,3 @@ /**

export declare const refine: <I, A extends I, B extends A>(
refinement: (a: A) => a is B
refinement: Refinement<A, B>
) => (from: Guard<I, A>) => Guard<I, B>

@@ -57,0 +68,0 @@ /**

@@ -1,11 +0,1 @@

/**
* **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';

@@ -67,3 +57,3 @@ import { memoize } from './Schemable';

export var UnknownRecord = {
is: function (u) { return Object.prototype.toString.call(u) === '[object Object]'; }
is: function (u) { return u !== null && typeof u === 'object' && !Array.isArray(u); }
};

@@ -70,0 +60,0 @@ // -------------------------------------------------------------------------------------

@@ -7,3 +7,3 @@ /**

/**
* @category Model
* @category Decode error
* @since 1.0.0

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

/**
* @category Model
* @category Decode error
* @since 1.0.0

@@ -24,3 +24,3 @@ */

/**
* @category Model
* @category Decode error
* @since 1.0.0

@@ -37,3 +37,3 @@ */

/**
* @category Model
* @category Decode error
* @since 1.0.0

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

/**
* @category Model
* @category Decode error
* @since 1.0.0

@@ -49,8 +49,21 @@ */

/**
* @category Model
* @category Decode error
* @since 1.0.0
*/
export declare const failures: <T>(errors: Errors) => Validation<T>
/**
* @category Decode error
* @since 1.0.0
*/
export declare const failure: <T>(value: unknown, context: Context, message?: string | undefined) => Either<Errors, T>
/**
* @category Decode error
* @since 1.0.0
*/
export declare const success: <T>(value: T) => Validation<T>
/**
* @since 1.0.0
*/
export declare type Is<A> = (u: unknown) => u is A
/**
* @category Model
* @since 1.0.0

@@ -60,3 +73,2 @@ */

/**
* @category Model
* @since 1.0.0

@@ -66,3 +78,2 @@ */

/**
* @category Model
* @since 1.0.0

@@ -80,2 +91,3 @@ */

/**
* @category Codec
* @since 1.0.0

@@ -85,2 +97,3 @@ */

/**
* @category Codec
* @since 1.0.0

@@ -90,2 +103,3 @@ */

/**
* @category Codec
* @since 1.0.0

@@ -95,3 +109,3 @@ */

/**
* @category Model
* @category Codec
* @since 1.0.0

@@ -105,3 +119,3 @@ */

/**
* @category Model
* @category Codec
* @since 1.0.0

@@ -113,3 +127,3 @@ */

/**
* @category Model
* @category Codec
* @since 1.0.0

@@ -173,26 +187,84 @@ */

*/
export declare const getFunctionName: (f: Function) => string
export declare function getFunctionName(f: Function): string
/**
* @since 1.0.0
*/
export declare const getContextEntry: (key: string, decoder: Decoder<any, any>) => ContextEntry
export declare function getContextEntry(key: string, decoder: Decoder<any, any>): ContextEntry
/**
* @since 1.0.0
*/
export declare const appendContext: (c: Context, key: string, decoder: Decoder<any, any>, actual?: unknown) => Context
export declare function appendContext(c: Context, key: string, decoder: Decoder<any, any>, actual?: unknown): Context
/**
* @since 1.0.0
*/
export declare const failures: <T>(errors: Errors) => Validation<T>
export interface AnyProps {
[key: string]: Any
}
/**
* @since 1.0.0
*/
export declare const failure: <T>(value: unknown, context: Context, message?: string | undefined) => Either<Errors, T>
export declare type TypeOfProps<P extends AnyProps> = {
[K in keyof P]: TypeOf<P[K]>
}
/**
* @since 1.0.0
*/
export declare const success: <T>(value: T) => Validation<T>
export declare type OutputOfProps<P extends AnyProps> = {
[K in keyof P]: OutputOf<P[K]>
}
/**
* @since 1.0.0
*/
export interface Props {
[key: string]: Mixed
}
/**
* @since 1.0.0
*/
export declare type TypeOfPartialProps<P extends AnyProps> = {
[K in keyof P]?: TypeOf<P[K]>
}
/**
* @since 1.0.0
*/
export declare type OutputOfPartialProps<P extends AnyProps> = {
[K in keyof P]?: OutputOf<P[K]>
}
/**
* @since 1.0.0
*/
export declare type TypeOfDictionary<D extends Any, C extends Any> = {
[K in TypeOf<D>]: TypeOf<C>
}
/**
* @since 1.0.0
*/
export declare type OutputOfDictionary<D extends Any, C extends Any> = {
[K in OutputOf<D>]: OutputOf<C>
}
/**
* @since 1.1.0
*/
export interface HasPropsRefinement extends RefinementType<HasProps, any, any, any> {}
/**
* @since 1.1.0
*/
export interface HasPropsReadonly extends ReadonlyType<HasProps, any, any, any> {}
/**
* @since 1.1.0
*/
export interface HasPropsIntersection extends IntersectionType<Array<HasProps>, any, any, any> {}
/**
* @since 1.1.0
*/
export declare type HasProps =
| HasPropsRefinement
| HasPropsReadonly
| HasPropsIntersection
| InterfaceType<any, any, any, any>
| StrictType<any, any, any, any>
| PartialType<any, any, any, any>
/**
* @since 1.0.0
*/
export declare class NullType extends Type<null> {

@@ -210,3 +282,3 @@ /**

/**
* @category Primitives
* @category primitives
* @since 1.0.0

@@ -245,3 +317,3 @@ */

/**
* @category Primitives
* @category primitives
* @since 1.2.0

@@ -265,3 +337,3 @@ */

/**
* @category Primitives
* @category primitives
* @since 1.5.0

@@ -285,3 +357,3 @@ */

/**
* @category Primitives
* @category primitives
* @since 1.0.0

@@ -305,3 +377,3 @@ */

/**
* @category Primitives
* @category primitives
* @since 1.0.0

@@ -325,3 +397,3 @@ */

/**
* @category Primitives
* @category primitives
* @since 2.1.0

@@ -345,3 +417,3 @@ */

/**
* @category Primitives
* @category primitives
* @since 1.0.0

@@ -365,3 +437,3 @@ */

/**
* @category Primitives
* @category primitives
* @since 1.7.1

@@ -383,34 +455,92 @@ */

/**
* @category Primitives
* @since 1.5.3
*/
export interface UnknownRecordC extends AnyDictionaryType {}
/**
* @category primitives
* @since 1.7.1
*/
export declare const UnknownRecord: UnknownRecordC
export {
/**
* @category primitives
* @since 1.0.0
*/
nullType as null,
/**
* @category primitives
* @since 1.0.0
*/
undefinedType as undefined,
/**
* @category primitives
* @since 1.0.0
*/
voidType as void
}
declare type LiteralValue = string | number | boolean
/**
* @since 1.0.0
*/
export declare class LiteralType<V extends LiteralValue> extends Type<V> {
readonly value: V
/**
* @since 1.0.0
*/
readonly _tag: 'LiteralType'
constructor(
name: string,
is: LiteralType<V>['is'],
validate: LiteralType<V>['validate'],
encode: LiteralType<V>['encode'],
value: V
)
}
/**
* @since 1.5.3
*/
export interface UnknownRecordC extends AnyDictionaryType {}
export interface LiteralC<V extends LiteralValue> extends LiteralType<V> {}
/**
* @category deprecated
* @category constructors
* @since 1.0.0
* @deprecated
*/
export declare class FunctionType extends Type<Function> {
export declare function literal<V extends LiteralValue>(value: V, name?: string): LiteralC<V>
/**
* @since 1.0.0
*/
export declare class KeyofType<
D extends {
[key: string]: unknown
}
> extends Type<keyof D> {
readonly keys: D
/**
* @since 1.0.0
*/
readonly _tag: 'FunctionType'
constructor()
readonly _tag: 'KeyofType'
constructor(
name: string,
is: KeyofType<D>['is'],
validate: KeyofType<D>['validate'],
encode: KeyofType<D>['encode'],
keys: D
)
}
/**
* @category deprecated
* @since 1.5.3
* @deprecated
*/
export interface FunctionC extends FunctionType {}
export interface KeyofC<
D extends {
[key: string]: unknown
}
> extends KeyofType<D> {}
/**
* @category deprecated
* @category constructors
* @since 1.0.0
* @deprecated
*/
export declare const Function: FunctionC
export declare function keyof<
D extends {
[key: string]: unknown
}
>(keys: D, name?: string): KeyofC<D>
/**

@@ -451,10 +581,12 @@ * @since 1.0.0

/**
* @category Combinators
* @category combinators
* @since 1.8.1
*/
export declare const brand: <C extends Any, N extends string, B extends { readonly [K in N]: symbol }>(
codec: C,
predicate: Refinement<TypeOf<C>, Branded<TypeOf<C>, B>>,
name: N
) => BrandC<C, B>
export declare function brand<
C extends Any,
N extends string,
B extends {
readonly [K in N]: symbol
}
>(codec: C, predicate: Refinement<TypeOf<C>, Branded<TypeOf<C>, B>>, name: N): BrandC<C, B>
/**

@@ -469,3 +601,3 @@ * @since 1.8.1

*
* @category Primitives
* @category primitives
* @since 1.8.1

@@ -478,71 +610,5 @@ */

export declare type Int = Branded<number, IntBrand>
declare type LiteralValue = string | number | boolean
/**
* @since 1.0.0
*/
export declare class LiteralType<V extends LiteralValue> extends Type<V> {
readonly value: V
/**
* @since 1.0.0
*/
readonly _tag: 'LiteralType'
constructor(
name: string,
is: LiteralType<V>['is'],
validate: LiteralType<V>['validate'],
encode: LiteralType<V>['encode'],
value: V
)
}
/**
* @since 1.5.3
*/
export interface LiteralC<V extends LiteralValue> extends LiteralType<V> {}
/**
* @category Combinators
* @since 1.0.0
*/
export declare const literal: <V extends string | number | boolean>(value: V, name?: string) => LiteralC<V>
/**
* @since 1.0.0
*/
export declare class KeyofType<
D extends {
[key: string]: unknown
}
> extends Type<keyof D> {
readonly keys: D
/**
* @since 1.0.0
*/
readonly _tag: 'KeyofType'
constructor(
name: string,
is: KeyofType<D>['is'],
validate: KeyofType<D>['validate'],
encode: KeyofType<D>['encode'],
keys: D
)
}
/**
* @since 1.5.3
*/
export interface KeyofC<
D extends {
[key: string]: unknown
}
> extends KeyofType<D> {}
/**
* @category Combinators
* @since 1.0.0
*/
export declare const keyof: <D extends {
[key: string]: unknown
}>(
keys: D,
name?: string
) => KeyofC<D>
/**
* @since 1.0.0
*/
export declare class RecursiveType<C extends Any, A = any, O = A, I = unknown> extends Type<A, O, I> {

@@ -567,9 +633,9 @@ runDefinition: () => C

/**
* @category Combinators
* @category combinators
* @since 1.0.0
*/
export declare const recursion: <A, O = A, I = unknown, C extends Type<A, O, I> = Type<A, O, I>>(
export declare function recursion<A, O = A, I = unknown, C extends Type<A, O, I> = Type<A, O, I>>(
name: string,
definition: (self: C) => C
) => RecursiveType<C, A, O, I>
): RecursiveType<C, A, O, I>
/**

@@ -597,6 +663,6 @@ * @since 1.0.0

/**
* @category Combinators
* @category combinators
* @since 1.0.0
*/
export declare const array: <C extends Mixed>(item: C, name?: string) => ArrayC<C>
export declare function array<C extends Mixed>(item: C, name?: string): ArrayC<C>
/**

@@ -620,26 +686,2 @@ * @since 1.0.0

/**
* @since 1.0.0
*/
export interface AnyProps {
[key: string]: Any
}
/**
* @since 1.0.0
*/
export declare type TypeOfProps<P extends AnyProps> = {
[K in keyof P]: TypeOf<P[K]>
}
/**
* @since 1.0.0
*/
export declare type OutputOfProps<P extends AnyProps> = {
[K in keyof P]: OutputOf<P[K]>
}
/**
* @since 1.0.0
*/
export interface Props {
[key: string]: Mixed
}
/**
* @since 1.5.3

@@ -659,6 +701,6 @@ */

/**
* @category Combinators
* @category combinators
* @since 1.0.0
*/
export declare const type: <P extends Props>(props: P, name?: string) => TypeC<P>
export declare function type<P extends Props>(props: P, name?: string): TypeC<P>
/**

@@ -682,14 +724,2 @@ * @since 1.0.0

/**
* @since 1.0.0
*/
export declare type TypeOfPartialProps<P extends AnyProps> = {
[K in keyof P]?: TypeOf<P[K]>
}
/**
* @since 1.0.0
*/
export declare type OutputOfPartialProps<P extends AnyProps> = {
[K in keyof P]?: OutputOf<P[K]>
}
/**
* @since 1.5.3

@@ -709,6 +739,6 @@ */

/**
* @category Combinators
* @category combinators
* @since 1.0.0
*/
export declare const partial: <P extends Props>(props: P, name?: string) => PartialC<P>
export declare function partial<P extends Props>(props: P, name?: string): PartialC<P>
/**

@@ -734,14 +764,2 @@ * @since 1.0.0

/**
* @since 1.0.0
*/
export declare type TypeOfDictionary<D extends Any, C extends Any> = {
[K in TypeOf<D>]: TypeOf<C>
}
/**
* @since 1.0.0
*/
export declare type OutputOfDictionary<D extends Any, C extends Any> = {
[K in OutputOf<D>]: OutputOf<C>
}
/**
* @since 1.5.3

@@ -762,3 +780,3 @@ */

/**
* @category Combinators
* @category combinators
* @since 1.7.1

@@ -790,6 +808,6 @@ */

/**
* @category Combinators
* @category combinators
* @since 1.0.0
*/
export declare const union: <CS extends [Mixed, Mixed, ...Mixed[]]>(codecs: CS, name?: string) => UnionC<CS>
export declare function union<CS extends [Mixed, Mixed, ...Array<Mixed>]>(codecs: CS, name?: string): UnionC<CS>
/**

@@ -855,3 +873,3 @@ * @since 1.0.0

/**
* @category Combinators
* @category combinators
* @since 1.0.0

@@ -946,3 +964,3 @@ */

/**
* @category Combinators
* @category combinators
* @since 1.0.0

@@ -987,6 +1005,6 @@ */

/**
* @category Combinators
* @category combinators
* @since 1.0.0
*/
export declare const readonly: <C extends Mixed>(codec: C, name?: string) => ReadonlyC<C>
export declare function readonly<C extends Mixed>(codec: C, name?: string): ReadonlyC<C>
/**

@@ -1015,10 +1033,10 @@ * @since 1.0.0

/**
* @category Combinators
* @category combinators
* @since 1.0.0
*/
export declare const readonlyArray: <C extends Mixed>(item: C, name?: string) => ReadonlyArrayC<C>
export declare function readonlyArray<C extends Mixed>(item: C, name?: string): ReadonlyArrayC<C>
/**
* Strips additional properties
* Strips additional properties, equivalent to `exact(type(props))`.
*
* @category Combinators
* @category combinators
* @since 1.0.0

@@ -1028,3 +1046,52 @@ */

/**
* @category deprecated
* @since 1.1.0
*/
export declare class ExactType<C extends Any, A = any, O = A, I = unknown> extends Type<A, O, I> {
readonly type: C
/**
* @since 1.0.0
*/
readonly _tag: 'ExactType'
constructor(
name: string,
is: ExactType<C, A, O, I>['is'],
validate: ExactType<C, A, O, I>['validate'],
encode: ExactType<C, A, O, I>['encode'],
type: C
)
}
/**
* @since 1.5.3
*/
export interface ExactC<C extends HasProps> extends ExactType<C, TypeOf<C>, OutputOf<C>, InputOf<C>> {}
/**
* Strips additional properties.
*
* @category combinators
* @since 1.1.0
*/
export declare function exact<C extends HasProps>(codec: C, name?: string): ExactC<C>
/**
* @since 1.0.0
* @deprecated
*/
export declare class FunctionType extends Type<Function> {
/**
* @since 1.0.0
*/
readonly _tag: 'FunctionType'
constructor()
}
/**
* @since 1.5.3
* @deprecated
*/
export interface FunctionC extends FunctionType {}
/**
* @category primitives
* @since 1.0.0
* @deprecated
*/
export declare const Function: FunctionC
/**
* @since 1.3.0

@@ -1051,3 +1118,2 @@ * @deprecated

/**
* @category deprecated
* @since 1.5.3

@@ -1059,5 +1125,5 @@ * @deprecated

/**
* Use `union` instead
* Use `union` instead.
*
* @category deprecated
* @category combinators
* @since 1.3.0

@@ -1071,67 +1137,7 @@ * @deprecated

) => TaggedUnionC<Tag, CS>
/**
* @since 1.1.0
*/
export declare class ExactType<C extends Any, A = any, O = A, I = unknown> extends Type<A, O, I> {
readonly type: C
/**
* @since 1.0.0
*/
readonly _tag: 'ExactType'
constructor(
name: string,
is: ExactType<C, A, O, I>['is'],
validate: ExactType<C, A, O, I>['validate'],
encode: ExactType<C, A, O, I>['encode'],
type: C
)
}
/**
* @since 1.1.0
*/
export interface HasPropsRefinement extends RefinementType<HasProps, any, any, any> {}
/**
* @since 1.1.0
*/
export interface HasPropsReadonly extends ReadonlyType<HasProps, any, any, any> {}
/**
* @since 1.1.0
*/
export interface HasPropsIntersection extends IntersectionType<Array<HasProps>, any, any, any> {}
/**
* @since 1.1.0
*/
export declare type HasProps =
| HasPropsRefinement
| HasPropsReadonly
| HasPropsIntersection
| InterfaceType<any, any, any, any>
| StrictType<any, any, any, any>
| PartialType<any, any, any, any>
/**
* @since 1.5.3
*/
export interface ExactC<C extends HasProps> extends ExactType<C, TypeOf<C>, OutputOf<C>, InputOf<C>> {}
/**
* Strips additional properties
* @since 1.1.0
*/
export declare const exact: <C extends HasProps>(codec: C, name?: string) => ExactC<C>
export {
/**
* @since 1.0.0
*/
nullType as null
}
export {
/**
* @since 1.0.0
*/
undefinedType as undefined
}
export {
/**
* Use `UnknownArray` instead
* Use `UnknownArray` instead.
*
* @category deprecated
* @category primitives
* @deprecated

@@ -1144,5 +1150,5 @@ * @since 1.0.0

/**
* Use `type` instead
* Use `type` instead.
*
* @category deprecated
* @category combinators
* @deprecated

@@ -1153,12 +1159,5 @@ * @since 1.0.0

}
export {
/**
* @since 1.0.0
*/
voidType as void
}
/**
* Use `unknown` instead
* Use `unknown` instead.
*
* @category deprecated
* @since 1.0.0

@@ -1169,3 +1168,2 @@ * @deprecated

/**
* @category deprecated
* @since 1.0.0

@@ -1176,3 +1174,2 @@ * @deprecated

/**
* @category deprecated
* @since 1.0.0

@@ -1183,3 +1180,2 @@ * @deprecated

/**
* @category deprecated
* @since 1.0.0

@@ -1196,3 +1192,2 @@ * @deprecated

/**
* @category deprecated
* @since 1.5.3

@@ -1203,3 +1198,3 @@ * @deprecated

/**
* @category deprecated
* @category primitives
* @since 1.0.0

@@ -1210,3 +1205,2 @@ * @deprecated

/**
* @category deprecated
* @since 1.0.0

@@ -1223,3 +1217,2 @@ * @deprecated

/**
* @category deprecated
* @since 1.5.3

@@ -1230,5 +1223,5 @@ * @deprecated

/**
* Use `unknown` instead
* Use `unknown` instead.
*
* @category deprecated
* @category primitives
* @since 1.0.0

@@ -1239,5 +1232,5 @@ * @deprecated

/**
* Use `UnknownRecord` instead
* Use `UnknownRecord` instead.
*
* @category deprecated
* @category primitives
* @since 1.0.0

@@ -1248,3 +1241,2 @@ * @deprecated

/**
* @category deprecated
* @since 1.0.0

@@ -1261,3 +1253,2 @@ * @deprecated

/**
* @category deprecated
* @since 1.5.3

@@ -1268,5 +1259,5 @@ * @deprecated

/**
* Use `UnknownRecord` instead
* Use `UnknownRecord` instead.
*
* @category deprecated
* @category primitives
* @since 1.0.0

@@ -1277,5 +1268,4 @@ * @deprecated

/**
* Use `BrandC` instead
* Use `BrandC` instead.
*
* @category deprecated
* @since 1.5.3

@@ -1286,5 +1276,5 @@ * @deprecated

/**
* Use `brand` instead
* Use `brand` instead.
*
* @category deprecated
* @category combinators
* @since 1.0.0

@@ -1299,5 +1289,5 @@ * @deprecated

/**
* Use `Int` instead
* Use `Int` instead.
*
* @category deprecated
* @category primitives
* @since 1.0.0

@@ -1308,5 +1298,5 @@ * @deprecated

/**
* Use `record` instead
* Use `record` instead.
*
* @category deprecated
* @category combinators
* @since 1.0.0

@@ -1317,5 +1307,2 @@ * @deprecated

/**
* used in `intersection` as a workaround for #234
*
* @category deprecated
* @since 1.4.2

@@ -1328,3 +1315,2 @@ * @deprecated

/**
* @category deprecated
* @since 1.0.0

@@ -1348,3 +1334,2 @@ * @deprecated

/**
* @category deprecated
* @since 1.5.3

@@ -1365,3 +1350,2 @@ * @deprecated

/**
* @category deprecated
* @since 1.3.0

@@ -1374,3 +1358,2 @@ * @deprecated

/**
* @category deprecated
* @since 1.3.0

@@ -1381,3 +1364,2 @@ * @deprecated

/**
* @category deprecated
* @since 1.3.0

@@ -1388,3 +1370,2 @@ * @deprecated

/**
* @category deprecated
* @since 1.3.0

@@ -1410,3 +1391,2 @@ * @deprecated

/**
* @category deprecated
* @since 1.3.0

@@ -1418,3 +1398,2 @@ * @deprecated

/**
* @category deprecated
* @since 1.3.0

@@ -1425,3 +1404,2 @@ * @deprecated

/**
* @category deprecated
* @since 1.3.0

@@ -1439,5 +1417,5 @@ * @deprecated

/**
* Drops the codec "kind"
* Drops the codec "kind".
*
* @category deprecated
* @category combinators
* @since 1.1.0

@@ -1448,3 +1426,2 @@ * @deprecated

/**
* @category deprecated
* @since 1.0.0

@@ -1459,3 +1436,2 @@ * @deprecated

/**
* @category deprecated
* @since 1.1.0

@@ -1476,5 +1452,5 @@ * @deprecated

/**
* Keeps the codec "kind"
* Keeps the codec "kind".
*
* @category deprecated
* @category combinators
* @since 1.1.0

@@ -1481,0 +1457,0 @@ * @deprecated

@@ -37,5 +37,22 @@ var __extends = (this && this.__extends) || (function () {

/**
* @category Model
* @category Decode error
* @since 1.0.0
*/
export var failures = left;
/**
* @category Decode error
* @since 1.0.0
*/
export var failure = function (value, context, message) {
return failures([{ value: value, context: context, message: message }]);
};
/**
* @category Decode error
* @since 1.0.0
*/
export var success = right;
/**
* @category Codec
* @since 1.0.0
*/
var Type = /** @class */ (function () {

@@ -93,2 +110,5 @@ function Type(

export { Type };
// -------------------------------------------------------------------------------------
// utils
// -------------------------------------------------------------------------------------
/**

@@ -101,13 +121,15 @@ * @since 1.0.0

*/
export var getFunctionName = function (f) {
export function getFunctionName(f) {
return f.displayName || f.name || "<function" + f.length + ">";
};
}
/**
* @since 1.0.0
*/
export var getContextEntry = function (key, decoder) { return ({ key: key, type: decoder }); };
export function getContextEntry(key, decoder) {
return { key: key, type: decoder };
}
/**
* @since 1.0.0
*/
export var appendContext = function (c, key, decoder, actual) {
export function appendContext(c, key, decoder, actual) {
var len = c.length;

@@ -120,23 +142,390 @@ var r = Array(len + 1);

return r;
};
}
function pushAll(xs, ys) {
var l = ys.length;
for (var i = 0; i < l; i++) {
xs.push(ys[i]);
}
}
var hasOwnProperty = Object.prototype.hasOwnProperty;
function getNameFromProps(props) {
return Object.keys(props)
.map(function (k) { return k + ": " + props[k].name; })
.join(', ');
}
function useIdentity(codecs) {
for (var i = 0; i < codecs.length; i++) {
if (codecs[i].encode !== identity) {
return false;
}
}
return true;
}
function getInterfaceTypeName(props) {
return "{ " + getNameFromProps(props) + " }";
}
function getPartialTypeName(inner) {
return "Partial<" + inner + ">";
}
function enumerableRecord(keys, domain, codomain, name) {
if (name === void 0) { name = "{ [K in " + domain.name + "]: " + codomain.name + " }"; }
var len = keys.length;
return new DictionaryType(name, function (u) { return UnknownRecord.is(u) && keys.every(function (k) { return codomain.is(u[k]); }); }, function (u, c) {
var e = UnknownRecord.validate(u, c);
if (isLeft(e)) {
return e;
}
var o = e.right;
var a = {};
var errors = [];
var changed = false;
for (var i = 0; i < len; i++) {
var k = keys[i];
var ok = o[k];
var codomainResult = codomain.validate(ok, appendContext(c, k, codomain, ok));
if (isLeft(codomainResult)) {
pushAll(errors, codomainResult.left);
}
else {
var vok = codomainResult.right;
changed = changed || vok !== ok;
a[k] = vok;
}
}
return errors.length > 0 ? failures(errors) : success((changed || Object.keys(o).length !== len ? a : o));
}, codomain.encode === identity
? identity
: function (a) {
var s = {};
for (var i = 0; i < len; i++) {
var k = keys[i];
s[k] = codomain.encode(a[k]);
}
return s;
}, domain, codomain);
}
/**
* @since 1.0.0
* @internal
*/
export var failures = left;
export function getDomainKeys(domain) {
var _a;
if (isLiteralC(domain)) {
var literal_1 = domain.value;
if (string.is(literal_1)) {
return _a = {}, _a[literal_1] = null, _a;
}
}
else if (isKeyofC(domain)) {
return domain.keys;
}
else if (isUnionC(domain)) {
var keys = domain.types.map(function (type) { return getDomainKeys(type); });
return keys.some(undefinedType.is) ? undefined : Object.assign.apply(Object, __spreadArrays([{}], keys));
}
return undefined;
}
function nonEnumerableRecord(domain, codomain, name) {
if (name === void 0) { name = "{ [K in " + domain.name + "]: " + codomain.name + " }"; }
return new DictionaryType(name, function (u) {
if (UnknownRecord.is(u)) {
return Object.keys(u).every(function (k) { return domain.is(k) && codomain.is(u[k]); });
}
return isAnyC(codomain) && Array.isArray(u);
}, function (u, c) {
if (UnknownRecord.is(u)) {
var a = {};
var errors = [];
var keys = Object.keys(u);
var len = keys.length;
var changed = false;
for (var i = 0; i < len; i++) {
var k = keys[i];
var ok = u[k];
var domainResult = domain.validate(k, appendContext(c, k, domain, k));
if (isLeft(domainResult)) {
pushAll(errors, domainResult.left);
}
else {
var vk = domainResult.right;
changed = changed || vk !== k;
k = vk;
var codomainResult = codomain.validate(ok, appendContext(c, k, codomain, ok));
if (isLeft(codomainResult)) {
pushAll(errors, codomainResult.left);
}
else {
var vok = codomainResult.right;
changed = changed || vok !== ok;
a[k] = vok;
}
}
}
return errors.length > 0 ? failures(errors) : success((changed ? a : u));
}
if (isAnyC(codomain) && Array.isArray(u)) {
return success(u);
}
return failure(u, c);
}, domain.encode === identity && codomain.encode === identity
? identity
: function (a) {
var s = {};
var keys = Object.keys(a);
var len = keys.length;
for (var i = 0; i < len; i++) {
var k = keys[i];
s[String(domain.encode(k))] = codomain.encode(a[k]);
}
return s;
}, domain, codomain);
}
function getUnionName(codecs) {
return '(' + codecs.map(function (type) { return type.name; }).join(' | ') + ')';
}
/**
* @since 1.0.0
* @internal
*/
export var failure = function (value, context, message) {
return failures([{ value: value, context: context, message: message }]);
};
export function mergeAll(base, us) {
var equal = true;
var primitive = true;
var baseIsNotADictionary = !UnknownRecord.is(base);
for (var _i = 0, us_1 = us; _i < us_1.length; _i++) {
var u = us_1[_i];
if (u !== base) {
equal = false;
}
if (UnknownRecord.is(u)) {
primitive = false;
}
}
if (equal) {
return base;
}
else if (primitive) {
return us[us.length - 1];
}
var r = {};
for (var _a = 0, us_2 = us; _a < us_2.length; _a++) {
var u = us_2[_a];
for (var k in u) {
if (!r.hasOwnProperty(k) || baseIsNotADictionary || u[k] !== base[k]) {
r[k] = u[k];
}
}
}
return r;
}
function getProps(codec) {
switch (codec._tag) {
case 'RefinementType':
case 'ReadonlyType':
return getProps(codec.type);
case 'InterfaceType':
case 'StrictType':
case 'PartialType':
return codec.props;
case 'IntersectionType':
return codec.types.reduce(function (props, type) { return Object.assign(props, getProps(type)); }, {});
}
}
function stripKeys(o, props) {
var keys = Object.getOwnPropertyNames(o);
var shouldStrip = false;
var r = {};
for (var i = 0; i < keys.length; i++) {
var key = keys[i];
if (!hasOwnProperty.call(props, key)) {
shouldStrip = true;
}
else {
r[key] = o[key];
}
}
return shouldStrip ? r : o;
}
function getExactTypeName(codec) {
if (isTypeC(codec)) {
return "{| " + getNameFromProps(codec.props) + " |}";
}
else if (isPartialC(codec)) {
return getPartialTypeName("{| " + getNameFromProps(codec.props) + " |}");
}
return "Exact<" + codec.name + ">";
}
function isNonEmpty(as) {
return as.length > 0;
}
/**
* @since 1.0.0
* @internal
*/
export var success = right;
var pushAll = function (xs, ys) {
var l = ys.length;
for (var i = 0; i < l; i++) {
xs.push(ys[i]);
export var emptyTags = {};
function intersect(a, b) {
var r = [];
for (var _i = 0, a_1 = a; _i < a_1.length; _i++) {
var v = a_1[_i];
if (b.indexOf(v) !== -1) {
r.push(v);
}
}
};
return r;
}
function mergeTags(a, b) {
if (a === emptyTags) {
return b;
}
if (b === emptyTags) {
return a;
}
var r = Object.assign({}, a);
for (var k in b) {
if (a.hasOwnProperty(k)) {
var intersection_1 = intersect(a[k], b[k]);
if (isNonEmpty(intersection_1)) {
r[k] = intersection_1;
}
else {
r = emptyTags;
break;
}
}
else {
r[k] = b[k];
}
}
return r;
}
function intersectTags(a, b) {
if (a === emptyTags || b === emptyTags) {
return emptyTags;
}
var r = emptyTags;
for (var k in a) {
if (b.hasOwnProperty(k)) {
var intersection_2 = intersect(a[k], b[k]);
if (intersection_2.length === 0) {
if (r === emptyTags) {
r = {};
}
r[k] = a[k].concat(b[k]);
}
}
}
return r;
}
// tslint:disable-next-line: deprecation
function isAnyC(codec) {
return codec._tag === 'AnyType';
}
function isLiteralC(codec) {
return codec._tag === 'LiteralType';
}
function isKeyofC(codec) {
return codec._tag === 'KeyofType';
}
function isTypeC(codec) {
return codec._tag === 'InterfaceType';
}
function isPartialC(codec) {
return codec._tag === 'PartialType';
}
// tslint:disable-next-line: deprecation
function isStrictC(codec) {
return codec._tag === 'StrictType';
}
function isExactC(codec) {
return codec._tag === 'ExactType';
}
// tslint:disable-next-line: deprecation
function isRefinementC(codec) {
return codec._tag === 'RefinementType';
}
function isIntersectionC(codec) {
return codec._tag === 'IntersectionType';
}
function isUnionC(codec) {
return codec._tag === 'UnionType';
}
function isRecursiveC(codec) {
return codec._tag === 'RecursiveType';
}
var lazyCodecs = [];
/**
* @internal
*/
export function getTags(codec) {
if (lazyCodecs.indexOf(codec) !== -1) {
return emptyTags;
}
if (isTypeC(codec) || isStrictC(codec)) {
var index = emptyTags;
// tslint:disable-next-line: forin
for (var k in codec.props) {
var prop = codec.props[k];
if (isLiteralC(prop)) {
if (index === emptyTags) {
index = {};
}
index[k] = [prop.value];
}
}
return index;
}
else if (isExactC(codec) || isRefinementC(codec)) {
return getTags(codec.type);
}
else if (isIntersectionC(codec)) {
return codec.types.reduce(function (tags, codec) { return mergeTags(tags, getTags(codec)); }, emptyTags);
}
else if (isUnionC(codec)) {
return codec.types.slice(1).reduce(function (tags, codec) { return intersectTags(tags, getTags(codec)); }, getTags(codec.types[0]));
}
else if (isRecursiveC(codec)) {
lazyCodecs.push(codec);
var tags = getTags(codec.type);
lazyCodecs.pop();
return tags;
}
return emptyTags;
}
/**
* @internal
*/
export function getIndex(codecs) {
var tags = getTags(codecs[0]);
var keys = Object.keys(tags);
var len = codecs.length;
var _loop_1 = function (k) {
var all = tags[k].slice();
var index = [tags[k]];
for (var i = 1; i < len; i++) {
var codec = codecs[i];
var ctags = getTags(codec);
var values = ctags[k];
// tslint:disable-next-line: strict-type-predicates
if (values === undefined) {
return "continue-keys";
}
else {
if (values.some(function (v) { return all.indexOf(v) !== -1; })) {
return "continue-keys";
}
else {
all.push.apply(all, values);
index.push(values);
}
}
}
return { value: [k, index] };
};
keys: for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) {
var k = keys_1[_i];
var state_1 = _loop_1(k);
if (typeof state_1 === "object")
return state_1.value;
switch (state_1) {
case "continue-keys": continue keys;
}
}
return undefined;
}
// -------------------------------------------------------------------------------------

@@ -162,3 +551,3 @@ // primitives

/**
* @category Primitives
* @category primitives
* @since 1.0.0

@@ -201,3 +590,3 @@ */

/**
* @category Primitives
* @category primitives
* @since 1.2.0

@@ -223,3 +612,3 @@ */

/**
* @category Primitives
* @category primitives
* @since 1.5.0

@@ -245,3 +634,3 @@ */

/**
* @category Primitives
* @category primitives
* @since 1.0.0

@@ -267,3 +656,3 @@ */

/**
* @category Primitives
* @category primitives
* @since 1.0.0

@@ -291,3 +680,3 @@ */

/**
* @category Primitives
* @category primitives
* @since 2.1.0

@@ -313,3 +702,3 @@ */

/**
* @category Primitives
* @category primitives
* @since 1.0.0

@@ -335,3 +724,3 @@ */

/**
* @category Primitives
* @category primitives
* @since 1.7.1

@@ -360,70 +749,23 @@ */

/**
* @category Primitives
* @category primitives
* @since 1.7.1
*/
export var UnknownRecord = new AnyDictionaryType();
export {
/**
* @category deprecated
* @category primitives
* @since 1.0.0
* @deprecated
*/
var FunctionType = /** @class */ (function (_super) {
__extends(FunctionType, _super);
function FunctionType() {
var _this = _super.call(this, 'Function',
// tslint:disable-next-line:strict-type-predicates
function (u) { return typeof u === 'function'; }, function (u, c) { return (_this.is(u) ? success(u) : failure(u, c)); }, identity) || this;
/**
* @since 1.0.0
*/
_this._tag = 'FunctionType';
return _this;
}
return FunctionType;
}(Type));
export { FunctionType };
nullType as null,
/**
* @category deprecated
* @category primitives
* @since 1.0.0
* @deprecated
*/
// tslint:disable-next-line: deprecation
export var Function = new FunctionType();
undefinedType as undefined,
/**
* @category primitives
* @since 1.0.0
*/
var RefinementType = /** @class */ (function (_super) {
__extends(RefinementType, _super);
function RefinementType(name, is, validate, encode, type, predicate) {
var _this = _super.call(this, name, is, validate, encode) || this;
_this.type = type;
_this.predicate = predicate;
/**
* @since 1.0.0
*/
_this._tag = 'RefinementType';
return _this;
}
return RefinementType;
}(Type));
export { RefinementType };
// -------------------------------------------------------------------------------------
// combinators
// -------------------------------------------------------------------------------------
voidType as void };
/**
* @category Combinators
* @since 1.8.1
*/
export var brand = function (codec, predicate, name) {
// tslint:disable-next-line: deprecation
return refinement(codec, predicate, name);
};
/**
* A branded codec representing an integer
*
* @category Primitives
* @since 1.8.1
*/
export var Int = brand(number, function (n) { return Number.isInteger(n); }, 'Int');
/**
* @since 1.0.0

@@ -446,10 +788,10 @@ */

/**
* @category Combinators
* @category constructors
* @since 1.0.0
*/
export var literal = function (value, name) {
export function literal(value, name) {
if (name === void 0) { name = JSON.stringify(value); }
var is = function (u) { return u === value; };
return new LiteralType(name, is, function (u, c) { return (is(u) ? success(value) : failure(u, c)); }, identity, value);
};
}
/**

@@ -472,8 +814,7 @@ * @since 1.0.0

export { KeyofType };
var hasOwnProperty = Object.prototype.hasOwnProperty;
/**
* @category Combinators
* @category constructors
* @since 1.0.0
*/
export var keyof = function (keys, name) {
export function keyof(keys, name) {
if (name === void 0) { name = Object.keys(keys)

@@ -484,6 +825,42 @@ .map(function (k) { return JSON.stringify(k); })

return new KeyofType(name, is, function (u, c) { return (is(u) ? success(u) : failure(u, c)); }, identity, keys);
};
}
// -------------------------------------------------------------------------------------
// combinators
// -------------------------------------------------------------------------------------
/**
* @since 1.0.0
*/
var RefinementType = /** @class */ (function (_super) {
__extends(RefinementType, _super);
function RefinementType(name, is, validate, encode, type, predicate) {
var _this = _super.call(this, name, is, validate, encode) || this;
_this.type = type;
_this.predicate = predicate;
/**
* @since 1.0.0
*/
_this._tag = 'RefinementType';
return _this;
}
return RefinementType;
}(Type));
export { RefinementType };
/**
* @category combinators
* @since 1.8.1
*/
export function brand(codec, predicate, name) {
// tslint:disable-next-line: deprecation
return refinement(codec, predicate, name);
}
/**
* A branded codec representing an integer
*
* @category primitives
* @since 1.8.1
*/
export var Int = brand(number, function (n) { return Number.isInteger(n); }, 'Int');
/**
* @since 1.0.0
*/
var RecursiveType = /** @class */ (function (_super) {

@@ -511,6 +888,6 @@ __extends(RecursiveType, _super);

/**
* @category Combinators
* @category combinators
* @since 1.0.0
*/
export var recursion = function (name, definition) {
export function recursion(name, definition) {
var cache;

@@ -526,3 +903,3 @@ var runDefinition = function () {

return Self;
};
}
/**

@@ -546,6 +923,6 @@ * @since 1.0.0

/**
* @category Combinators
* @category combinators
* @since 1.0.0
*/
export var array = function (item, name) {
export function array(item, name) {
if (name === void 0) { name = "Array<" + item.name + ">"; }

@@ -579,3 +956,3 @@ return new ArrayType(name, function (u) { return UnknownArray.is(u) && u.every(item.is); }, function (u, c) {

}, item.encode === identity ? identity : function (a) { return a.map(item.encode); }, item);
};
}
/**

@@ -598,23 +975,7 @@ * @since 1.0.0

export { InterfaceType };
var getNameFromProps = function (props) {
return Object.keys(props)
.map(function (k) { return k + ": " + props[k].name; })
.join(', ');
};
var useIdentity = function (codecs) {
for (var i = 0; i < codecs.length; i++) {
if (codecs[i].encode !== identity) {
return false;
}
}
return true;
};
var getInterfaceTypeName = function (props) {
return "{ " + getNameFromProps(props) + " }";
};
/**
* @category Combinators
* @category combinators
* @since 1.0.0
*/
export var type = function (props, name) {
export function type(props, name) {
if (name === void 0) { name = getInterfaceTypeName(props); }

@@ -677,3 +1038,3 @@ var keys = Object.keys(props);

}, props);
};
}
/**

@@ -696,10 +1057,7 @@ * @since 1.0.0

export { PartialType };
var getPartialTypeName = function (inner) {
return "Partial<" + inner + ">";
};
/**
* @category Combinators
* @category combinators
* @since 1.0.0
*/
export var partial = function (props, name) {
export function partial(props, name) {
if (name === void 0) { name = getPartialTypeName(getInterfaceTypeName(props)); }

@@ -764,3 +1122,3 @@ var keys = Object.keys(props);

}, props);
};
}
/**

@@ -784,116 +1142,4 @@ * @since 1.0.0

export { DictionaryType };
function enumerableRecord(keys, domain, codomain, name) {
if (name === void 0) { name = "{ [K in " + domain.name + "]: " + codomain.name + " }"; }
var len = keys.length;
return new DictionaryType(name, function (u) { return UnknownRecord.is(u) && keys.every(function (k) { return codomain.is(u[k]); }); }, function (u, c) {
var e = UnknownRecord.validate(u, c);
if (isLeft(e)) {
return e;
}
var o = e.right;
var a = {};
var errors = [];
var changed = false;
for (var i = 0; i < len; i++) {
var k = keys[i];
var ok = o[k];
var codomainResult = codomain.validate(ok, appendContext(c, k, codomain, ok));
if (isLeft(codomainResult)) {
pushAll(errors, codomainResult.left);
}
else {
var vok = codomainResult.right;
changed = changed || vok !== ok;
a[k] = vok;
}
}
return errors.length > 0 ? failures(errors) : success((changed || Object.keys(o).length !== len ? a : o));
}, codomain.encode === identity
? identity
: function (a) {
var s = {};
for (var i = 0; i < len; i++) {
var k = keys[i];
s[k] = codomain.encode(a[k]);
}
return s;
}, domain, codomain);
}
/**
* @internal
*/
export function getDomainKeys(domain) {
var _a;
if (isLiteralC(domain)) {
var literal_1 = domain.value;
if (string.is(literal_1)) {
return _a = {}, _a[literal_1] = null, _a;
}
}
else if (isKeyofC(domain)) {
return domain.keys;
}
else if (isUnionC(domain)) {
var keys = domain.types.map(function (type) { return getDomainKeys(type); });
return keys.some(undefinedType.is) ? undefined : Object.assign.apply(Object, __spreadArrays([{}], keys));
}
return undefined;
}
function nonEnumerableRecord(domain, codomain, name) {
if (name === void 0) { name = "{ [K in " + domain.name + "]: " + codomain.name + " }"; }
return new DictionaryType(name, function (u) {
if (UnknownRecord.is(u)) {
return Object.keys(u).every(function (k) { return domain.is(k) && codomain.is(u[k]); });
}
return isAnyC(codomain) && Array.isArray(u);
}, function (u, c) {
if (UnknownRecord.is(u)) {
var a = {};
var errors = [];
var keys = Object.keys(u);
var len = keys.length;
var changed = false;
for (var i = 0; i < len; i++) {
var k = keys[i];
var ok = u[k];
var domainResult = domain.validate(k, appendContext(c, k, domain, k));
if (isLeft(domainResult)) {
pushAll(errors, domainResult.left);
}
else {
var vk = domainResult.right;
changed = changed || vk !== k;
k = vk;
var codomainResult = codomain.validate(ok, appendContext(c, k, codomain, ok));
if (isLeft(codomainResult)) {
pushAll(errors, codomainResult.left);
}
else {
var vok = codomainResult.right;
changed = changed || vok !== ok;
a[k] = vok;
}
}
}
return errors.length > 0 ? failures(errors) : success((changed ? a : u));
}
if (isAnyC(codomain) && Array.isArray(u)) {
return success(u);
}
return failure(u, c);
}, domain.encode === identity && codomain.encode === identity
? identity
: function (a) {
var s = {};
var keys = Object.keys(a);
var len = keys.length;
for (var i = 0; i < len; i++) {
var k = keys[i];
s[String(domain.encode(k))] = codomain.encode(a[k]);
}
return s;
}, domain, codomain);
}
/**
* @category Combinators
* @category combinators
* @since 1.7.1

@@ -924,10 +1170,7 @@ */

export { UnionType };
var getUnionName = function (codecs) {
return '(' + codecs.map(function (type) { return type.name; }).join(' | ') + ')';
};
/**
* @category Combinators
* @category combinators
* @since 1.0.0
*/
export var union = function (codecs, name) {
export function union(codecs, name) {
if (name === void 0) { name = getUnionName(codecs); }

@@ -1005,3 +1248,3 @@ var index = getIndex(codecs);

}
};
}
/**

@@ -1024,35 +1267,2 @@ * @since 1.0.0

export { IntersectionType };
/**
* @internal
*/
export var mergeAll = function (base, us) {
var equal = true;
var primitive = true;
var baseIsNotADictionary = !UnknownRecord.is(base);
for (var _i = 0, us_1 = us; _i < us_1.length; _i++) {
var u = us_1[_i];
if (u !== base) {
equal = false;
}
if (UnknownRecord.is(u)) {
primitive = false;
}
}
if (equal) {
return base;
}
else if (primitive) {
return us[us.length - 1];
}
var r = {};
for (var _a = 0, us_2 = us; _a < us_2.length; _a++) {
var u = us_2[_a];
for (var k in u) {
if (!r.hasOwnProperty(k) || baseIsNotADictionary || u[k] !== base[k]) {
r[k] = u[k];
}
}
}
return r;
};
export function intersection(codecs, name) {

@@ -1150,9 +1360,9 @@ if (name === void 0) { name = "(" + codecs.map(function (type) { return type.name; }).join(' & ') + ")"; }

/**
* @category Combinators
* @category combinators
* @since 1.0.0
*/
export var readonly = function (codec, name) {
export function readonly(codec, name) {
if (name === void 0) { name = "Readonly<" + codec.name + ">"; }
return new ReadonlyType(name, codec.is, codec.validate, codec.encode, codec);
};
}
/**

@@ -1176,21 +1386,85 @@ * @since 1.0.0

/**
* @category Combinators
* @category combinators
* @since 1.0.0
*/
export var readonlyArray = function (item, name) {
export function readonlyArray(item, name) {
if (name === void 0) { name = "ReadonlyArray<" + item.name + ">"; }
var codec = array(item);
return new ReadonlyArrayType(name, codec.is, codec.validate, codec.encode, item);
};
}
/**
* Strips additional properties
* Strips additional properties, equivalent to `exact(type(props))`.
*
* @category Combinators
* @category combinators
* @since 1.0.0
*/
export var strict = function (props, name) {
return exact(type(props), name);
};
export var strict = function (props, name) { return exact(type(props), name); };
/**
* @category deprecated
* @since 1.1.0
*/
var ExactType = /** @class */ (function (_super) {
__extends(ExactType, _super);
function ExactType(name, is, validate, encode, type) {
var _this = _super.call(this, name, is, validate, encode) || this;
_this.type = type;
/**
* @since 1.0.0
*/
_this._tag = 'ExactType';
return _this;
}
return ExactType;
}(Type));
export { ExactType };
/**
* Strips additional properties.
*
* @category combinators
* @since 1.1.0
*/
export function exact(codec, name) {
if (name === void 0) { name = getExactTypeName(codec); }
var props = getProps(codec);
return new ExactType(name, codec.is, function (u, c) {
var e = UnknownRecord.validate(u, c);
if (isLeft(e)) {
return e;
}
var ce = codec.validate(u, c);
if (isLeft(ce)) {
return ce;
}
return right(stripKeys(ce.right, props));
}, function (a) { return codec.encode(stripKeys(a, props)); }, codec);
}
// -------------------------------------------------------------------------------------
// deprecated
// -------------------------------------------------------------------------------------
/**
* @since 1.0.0
* @deprecated
*/
var FunctionType = /** @class */ (function (_super) {
__extends(FunctionType, _super);
function FunctionType() {
var _this = _super.call(this, 'Function',
// tslint:disable-next-line:strict-type-predicates
function (u) { return typeof u === 'function'; }, function (u, c) { return (_this.is(u) ? success(u) : failure(u, c)); }, identity) || this;
/**
* @since 1.0.0
*/
_this._tag = 'FunctionType';
return _this;
}
return FunctionType;
}(Type));
export { FunctionType };
/**
* @category primitives
* @since 1.0.0
* @deprecated
*/
// tslint:disable-next-line: deprecation
export var Function = new FunctionType();
/**
* @since 1.3.0

@@ -1217,5 +1491,5 @@ * @deprecated

/**
* Use `union` instead
* Use `union` instead.
*
* @category deprecated
* @category combinators
* @since 1.3.0

@@ -1239,90 +1513,7 @@ * @deprecated

};
/**
* @since 1.1.0
*/
var ExactType = /** @class */ (function (_super) {
__extends(ExactType, _super);
function ExactType(name, is, validate, encode, type) {
var _this = _super.call(this, name, is, validate, encode) || this;
_this.type = type;
/**
* @since 1.0.0
*/
_this._tag = 'ExactType';
return _this;
}
return ExactType;
}(Type));
export { ExactType };
var getProps = function (codec) {
switch (codec._tag) {
case 'RefinementType':
case 'ReadonlyType':
return getProps(codec.type);
case 'InterfaceType':
case 'StrictType':
case 'PartialType':
return codec.props;
case 'IntersectionType':
return codec.types.reduce(function (props, type) { return Object.assign(props, getProps(type)); }, {});
}
};
var stripKeys = function (o, props) {
var keys = Object.getOwnPropertyNames(o);
var shouldStrip = false;
var r = {};
for (var i = 0; i < keys.length; i++) {
var key = keys[i];
if (!hasOwnProperty.call(props, key)) {
shouldStrip = true;
}
else {
r[key] = o[key];
}
}
return shouldStrip ? r : o;
};
var getExactTypeName = function (codec) {
if (isTypeC(codec)) {
return "{| " + getNameFromProps(codec.props) + " |}";
}
else if (isPartialC(codec)) {
return getPartialTypeName("{| " + getNameFromProps(codec.props) + " |}");
}
return "Exact<" + codec.name + ">";
};
/**
* Strips additional properties
* @since 1.1.0
*/
export var exact = function (codec, name) {
if (name === void 0) { name = getExactTypeName(codec); }
var props = getProps(codec);
return new ExactType(name, codec.is, function (u, c) {
var e = UnknownRecord.validate(u, c);
if (isLeft(e)) {
return e;
}
var ce = codec.validate(u, c);
if (isLeft(ce)) {
return ce;
}
return right(stripKeys(ce.right, props));
}, function (a) { return codec.encode(stripKeys(a, props)); }, codec);
};
export {
/**
* @since 1.0.0
*/
nullType as null };
export {
/**
* @since 1.0.0
*/
undefinedType as undefined };
export {
/**
* Use `UnknownArray` instead
* Use `UnknownArray` instead.
*
* @category deprecated
* @category primitives
* @deprecated

@@ -1334,5 +1525,5 @@ * @since 1.0.0

/**
* Use `type` instead
* Use `type` instead.
*
* @category deprecated
* @category combinators
* @deprecated

@@ -1342,10 +1533,4 @@ * @since 1.0.0

type as interface };
export {
/**
* @since 1.0.0
*/
voidType as void };
/**
* @category deprecated
* @since 1.0.0
* @deprecated

@@ -1358,3 +1543,2 @@ */

/**
* @category deprecated
* @since 1.0.0

@@ -1367,3 +1551,2 @@ * @deprecated

/**
* @category deprecated
* @since 1.0.0

@@ -1390,3 +1573,3 @@ * @deprecated

/**
* @category deprecated
* @category primitives
* @since 1.0.0

@@ -1398,3 +1581,2 @@ * @deprecated

/**
* @category deprecated
* @since 1.0.0

@@ -1417,5 +1599,5 @@ * @deprecated

/**
* Use `unknown` instead
* Use `unknown` instead.
*
* @category deprecated
* @category primitives
* @since 1.0.0

@@ -1427,5 +1609,5 @@ * @deprecated

/**
* Use `UnknownRecord` instead
* Use `UnknownRecord` instead.
*
* @category deprecated
* @category primitives
* @since 1.0.0

@@ -1436,3 +1618,2 @@ * @deprecated

/**
* @category deprecated
* @since 1.0.0

@@ -1455,5 +1636,5 @@ * @deprecated

/**
* Use `UnknownRecord` instead
* Use `UnknownRecord` instead.
*
* @category deprecated
* @category primitives
* @since 1.0.0

@@ -1465,5 +1646,5 @@ * @deprecated

/**
* Use `brand` instead
* Use `brand` instead.
*
* @category deprecated
* @category combinators
* @since 1.0.0

@@ -1484,5 +1665,5 @@ * @deprecated

/**
* Use `Int` instead
* Use `Int` instead.
*
* @category deprecated
* @category primitives
* @since 1.0.0

@@ -1494,5 +1675,5 @@ * @deprecated

/**
* Use `record` instead
* Use `record` instead.
*
* @category deprecated
* @category combinators
* @since 1.0.0

@@ -1503,3 +1684,2 @@ * @deprecated

/**
* @category deprecated
* @since 1.0.0

@@ -1529,5 +1709,5 @@ * @deprecated

/**
* Drops the codec "kind"
* Drops the codec "kind".
*
* @category deprecated
* @category combinators
* @since 1.1.0

@@ -1542,175 +1722,1 @@ * @deprecated

}
var isNonEmpty = function (as) { return as.length > 0; };
/**
* @internal
*/
export var emptyTags = {};
function intersect(a, b) {
var r = [];
for (var _i = 0, a_1 = a; _i < a_1.length; _i++) {
var v = a_1[_i];
if (b.indexOf(v) !== -1) {
r.push(v);
}
}
return r;
}
function mergeTags(a, b) {
if (a === emptyTags) {
return b;
}
if (b === emptyTags) {
return a;
}
var r = Object.assign({}, a);
for (var k in b) {
if (a.hasOwnProperty(k)) {
var intersection_1 = intersect(a[k], b[k]);
if (isNonEmpty(intersection_1)) {
r[k] = intersection_1;
}
else {
r = emptyTags;
break;
}
}
else {
r[k] = b[k];
}
}
return r;
}
function intersectTags(a, b) {
if (a === emptyTags || b === emptyTags) {
return emptyTags;
}
var r = emptyTags;
for (var k in a) {
if (b.hasOwnProperty(k)) {
var intersection_2 = intersect(a[k], b[k]);
if (intersection_2.length === 0) {
if (r === emptyTags) {
r = {};
}
r[k] = a[k].concat(b[k]);
}
}
}
return r;
}
// tslint:disable-next-line: deprecation
function isAnyC(codec) {
return codec._tag === 'AnyType';
}
function isLiteralC(codec) {
return codec._tag === 'LiteralType';
}
function isKeyofC(codec) {
return codec._tag === 'KeyofType';
}
function isTypeC(codec) {
return codec._tag === 'InterfaceType';
}
function isPartialC(codec) {
return codec._tag === 'PartialType';
}
// tslint:disable-next-line: deprecation
function isStrictC(codec) {
return codec._tag === 'StrictType';
}
function isExactC(codec) {
return codec._tag === 'ExactType';
}
// tslint:disable-next-line: deprecation
function isRefinementC(codec) {
return codec._tag === 'RefinementType';
}
function isIntersectionC(codec) {
return codec._tag === 'IntersectionType';
}
function isUnionC(codec) {
return codec._tag === 'UnionType';
}
function isRecursiveC(codec) {
return codec._tag === 'RecursiveType';
}
var lazyCodecs = [];
/**
* @internal
*/
export function getTags(codec) {
if (lazyCodecs.indexOf(codec) !== -1) {
return emptyTags;
}
if (isTypeC(codec) || isStrictC(codec)) {
var index = emptyTags;
// tslint:disable-next-line: forin
for (var k in codec.props) {
var prop = codec.props[k];
if (isLiteralC(prop)) {
if (index === emptyTags) {
index = {};
}
index[k] = [prop.value];
}
}
return index;
}
else if (isExactC(codec) || isRefinementC(codec)) {
return getTags(codec.type);
}
else if (isIntersectionC(codec)) {
return codec.types.reduce(function (tags, codec) { return mergeTags(tags, getTags(codec)); }, emptyTags);
}
else if (isUnionC(codec)) {
return codec.types.slice(1).reduce(function (tags, codec) { return intersectTags(tags, getTags(codec)); }, getTags(codec.types[0]));
}
else if (isRecursiveC(codec)) {
lazyCodecs.push(codec);
var tags = getTags(codec.type);
lazyCodecs.pop();
return tags;
}
return emptyTags;
}
/**
* @internal
*/
export function getIndex(codecs) {
var tags = getTags(codecs[0]);
var keys = Object.keys(tags);
var len = codecs.length;
var _loop_1 = function (k) {
var all = tags[k].slice();
var index = [tags[k]];
for (var i = 1; i < len; i++) {
var codec = codecs[i];
var ctags = getTags(codec);
var values = ctags[k];
// tslint:disable-next-line: strict-type-predicates
if (values === undefined) {
return "continue-keys";
}
else {
if (values.some(function (v) { return all.indexOf(v) !== -1; })) {
return "continue-keys";
}
else {
all.push.apply(all, values);
index.push(values);
}
}
}
return { value: [k, index] };
};
keys: for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) {
var k = keys_1[_i];
var state_1 = _loop_1(k);
if (typeof state_1 === "object")
return state_1.value;
switch (state_1) {
case "continue-keys": continue keys;
}
}
return undefined;
}

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

*/
import { Refinement } from 'fp-ts/es6/function'
import { HKT, Kind, Kind2, URIS, URIS2 } from 'fp-ts/es6/HKT'

@@ -221,3 +222,3 @@ /**

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>
readonly refine: <A, B extends A>(refinement: Refinement<A, B>, id: string) => (from: HKT<S, A>) => HKT<S, B>
}

@@ -228,3 +229,3 @@ /**

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>
readonly refine: <A, B extends A>(refinement: Refinement<A, B>, id: string) => (from: Kind<S, A>) => Kind<S, B>
}

@@ -236,3 +237,3 @@ /**

readonly refine: <A, B extends A>(
refinement: (a: A) => a is B,
refinement: Refinement<A, B>,
id: string

@@ -239,0 +240,0 @@ ) => (from: Kind2<S, E, A>) => Kind2<S, E, B>

@@ -119,3 +119,3 @@ /**

export declare const refine: <A, B extends A>(
refinement: (a: A) => a is B,
refinement: Refinement<A, B>,
id: string

@@ -122,0 +122,0 @@ ) => <I>(from: TaskDecoder<I, A>) => TaskDecoder<I, B>

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

import { Refinement } from 'fp-ts/es6/function'
import * as t from './index'

@@ -42,3 +43,3 @@ import * as S from './Schemable'

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

@@ -45,0 +46,0 @@ * @category combinators

@@ -0,1 +1,12 @@

/**
* **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 { Refinement } from 'fp-ts/lib/function'
import { Invariant3 } from 'fp-ts/lib/Invariant'

@@ -69,3 +80,3 @@ import * as D from './Decoder'

export declare const refine: <A, B extends A>(
refinement: (a: A) => a is B,
refinement: Refinement<A, B>,
id: string

@@ -72,0 +83,0 @@ ) => <I, O>(from: Codec<I, O, A>) => Codec<I, O, B>

@@ -119,3 +119,4 @@ "use strict";

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

@@ -125,6 +126,7 @@ * @category combinators

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

@@ -206,3 +208,3 @@ * @category combinators

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

@@ -214,2 +216,3 @@ for (var _i = 0; _i < arguments.length; _i++) {

};
exports.fromTuple = fromTuple;
/**

@@ -231,3 +234,3 @@ * @category combinators

*/
exports.intersect = function (right) {
var intersect = function (right) {
var intersectD = D.intersect(right);

@@ -237,2 +240,3 @@ var intersectE = E.intersect(right);

};
exports.intersect = intersect;
/**

@@ -242,3 +246,3 @@ * @category combinators

*/
exports.fromSum = function (tag) {
var fromSum = function (tag) {
var decoder = D.fromSum(tag);

@@ -248,2 +252,3 @@ var encoder = E.sum(tag);

};
exports.fromSum = fromSum;
/**

@@ -270,3 +275,4 @@ * @category combinators

*/
exports.compose = function (to) { return function (from) { return make(D.compose(to)(from), E.compose(from)(to)); }; };
var compose = function (to) { return function (from) { return make(D.compose(to)(from), E.compose(from)(to)); }; };
exports.compose = compose;
// -------------------------------------------------------------------------------------

@@ -283,3 +289,4 @@ // non-pipeables

*/
exports.imap = function (f, g) { return function (fa) { return imap_(fa, f, g); }; };
var imap = function (f, g) { return function (fa) { return imap_(fa, f, g); }; };
exports.imap = imap;
// -------------------------------------------------------------------------------------

@@ -286,0 +293,0 @@ // instances

@@ -38,3 +38,4 @@ "use strict";

*/
exports.leaf = function (actual, error) { return ({ _tag: 'Leaf', actual: actual, error: error }); };
var leaf = function (actual, error) { return ({ _tag: 'Leaf', actual: actual, error: error }); };
exports.leaf = leaf;
/**

@@ -44,3 +45,3 @@ * @category constructors

*/
exports.key = function (key, kind, errors) { return ({
var key = function (key, kind, errors) { return ({
_tag: 'Key',

@@ -51,2 +52,3 @@ key: key,

}); };
exports.key = key;
/**

@@ -56,3 +58,3 @@ * @category constructors

*/
exports.index = function (index, kind, errors) { return ({
var index = function (index, kind, errors) { return ({
_tag: 'Index',

@@ -63,2 +65,3 @@ index: index,

}); };
exports.index = index;
/**

@@ -68,3 +71,3 @@ * @category constructors

*/
exports.member = function (index, errors) { return ({
var member = function (index, errors) { return ({
_tag: 'Member',

@@ -74,2 +77,3 @@ index: index,

}); };
exports.member = member;
/**

@@ -79,3 +83,3 @@ * @category constructors

*/
exports.lazy = function (id, errors) { return ({
var lazy = function (id, errors) { return ({
_tag: 'Lazy',

@@ -85,2 +89,3 @@ id: id,

}); };
exports.lazy = lazy;
/**

@@ -90,3 +95,3 @@ * @category constructors

*/
exports.wrap = function (error, errors) { return ({
var wrap = function (error, errors) { return ({
_tag: 'Wrap',

@@ -96,2 +101,3 @@ error: error,

}); };
exports.wrap = wrap;
/**

@@ -101,3 +107,3 @@ * @category destructors

*/
exports.fold = function (patterns) {
var fold = function (patterns) {
var f = function (e) {

@@ -121,2 +127,3 @@ switch (e._tag) {

};
exports.fold = fold;
/**

@@ -123,0 +130,0 @@ * @category instances

@@ -110,3 +110,3 @@ /**

export declare const refine: <A, B extends A>(
refinement: (a: A) => a is B,
refinement: Refinement<A, B>,
id: string

@@ -113,0 +113,0 @@ ) => <I>(from: Decoder<I, A>) => Decoder<I, B>

@@ -41,3 +41,3 @@ "use strict";

*/
exports.ap = function (fab, fa) {
var ap = function (fab, fa) {
return E.isLeft(fab)

@@ -51,2 +51,3 @@ ? E.isLeft(fa)

};
exports.ap = ap;
var M = {

@@ -74,3 +75,4 @@ URI: E.URI,

*/
exports.error = function (actual, message) { return FS.of(DE.leaf(actual, message)); };
var error = function (actual, message) { return FS.of(DE.leaf(actual, message)); };
exports.error = error;
/**

@@ -85,5 +87,6 @@ * @category DecodeError

*/
exports.failure = function (actual, message) {
var failure = function (actual, message) {
return E.left(exports.error(actual, message));
};
exports.failure = failure;
// -------------------------------------------------------------------------------------

@@ -96,5 +99,6 @@ // constructors

*/
exports.fromRefinement = function (refinement, expected) {
var fromRefinement = function (refinement, expected) {
return K.fromRefinement(M)(refinement, function (u) { return exports.error(u, expected); });
};
exports.fromRefinement = fromRefinement;
/**

@@ -104,5 +108,6 @@ * @category constructors

*/
exports.fromGuard = function (guard, expected) {
var fromGuard = function (guard, expected) {
return exports.fromRefinement(guard.is, expected);
};
exports.fromGuard = fromGuard;
/**

@@ -167,5 +172,6 @@ * @category constructors

*/
exports.withMessage = function (message) {
var withMessage = function (message) {
return exports.mapLeftWithInput(function (input, e) { return FS.of(DE.wrap(message(input, e), e)); });
};
exports.withMessage = withMessage;
/**

@@ -175,3 +181,4 @@ * @category combinators

*/
exports.refine = function (refinement, id) { return K.refine(M)(refinement, function (a) { return exports.error(a, id); }); };
var refine = function (refinement, id) { return K.refine(M)(refinement, function (a) { return exports.error(a, id); }); };
exports.refine = refine;
/**

@@ -195,5 +202,6 @@ * @category combinators

*/
exports.fromType = function (properties) {
var fromType = function (properties) {
return K.fromType(M)(function (k, e) { return FS.of(DE.key(k, DE.required, e)); })(properties);
};
exports.fromType = fromType;
/**

@@ -203,3 +211,4 @@ * @category combinators

*/
exports.type = function (properties) { return pipeable_1.pipe(exports.UnknownRecord, exports.compose(exports.fromType(properties))); };
var type = function (properties) { return pipeable_1.pipe(exports.UnknownRecord, exports.compose(exports.fromType(properties))); };
exports.type = type;
/**

@@ -209,5 +218,6 @@ * @category combinators

*/
exports.fromPartial = function (properties) {
var fromPartial = function (properties) {
return K.fromPartial(M)(function (k, e) { return FS.of(DE.key(k, DE.optional, e)); })(properties);
};
exports.fromPartial = fromPartial;
/**

@@ -217,3 +227,4 @@ * @category combinators

*/
exports.partial = function (properties) { return pipeable_1.pipe(exports.UnknownRecord, exports.compose(exports.fromPartial(properties))); };
var partial = function (properties) { return pipeable_1.pipe(exports.UnknownRecord, exports.compose(exports.fromPartial(properties))); };
exports.partial = partial;
/**

@@ -223,5 +234,6 @@ * @category combinators

*/
exports.fromArray = function (item) {
var fromArray = function (item) {
return K.fromArray(M)(function (i, e) { return FS.of(DE.index(i, DE.optional, e)); })(item);
};
exports.fromArray = fromArray;
/**

@@ -231,5 +243,6 @@ * @category combinators

*/
exports.array = function (item) {
var array = function (item) {
return pipeable_1.pipe(exports.UnknownArray, exports.compose(exports.fromArray(item)));
};
exports.array = array;
/**

@@ -239,5 +252,6 @@ * @category combinators

*/
exports.fromRecord = function (codomain) {
var fromRecord = function (codomain) {
return K.fromRecord(M)(function (k, e) { return FS.of(DE.key(k, DE.optional, e)); })(codomain);
};
exports.fromRecord = fromRecord;
/**

@@ -247,5 +261,6 @@ * @category combinators

*/
exports.record = function (codomain) {
var record = function (codomain) {
return pipeable_1.pipe(exports.UnknownRecord, exports.compose(exports.fromRecord(codomain)));
};
exports.record = record;
/**

@@ -255,3 +270,3 @@ * @category combinators

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

@@ -263,2 +278,3 @@ for (var _i = 0; _i < arguments.length; _i++) {

};
exports.fromTuple = fromTuple;
/**

@@ -268,3 +284,3 @@ * @category combinators

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

@@ -276,2 +292,3 @@ for (var _i = 0; _i < arguments.length; _i++) {

};
exports.tuple = tuple;
/**

@@ -295,3 +312,3 @@ * @category combinators

*/
exports.fromSum = function (tag) { return function (members) {
var fromSum = function (tag) { return function (members) {
return K.fromSum(M)(function (tag, value, keys) {

@@ -301,2 +318,3 @@ return FS.of(DE.key(tag, DE.required, exports.error(value, keys.length === 0 ? 'never' : keys.map(function (k) { return JSON.stringify(k); }).join(' | '))));

}; };
exports.fromSum = fromSum;
/**

@@ -306,3 +324,4 @@ * @category combinators

*/
exports.sum = function (tag) { return function (members) { return pipeable_1.pipe(exports.UnknownRecord, exports.compose(exports.fromSum(tag)(members))); }; };
var sum = function (tag) { return function (members) { return pipeable_1.pipe(exports.UnknownRecord, exports.compose(exports.fromSum(tag)(members))); }; };
exports.sum = sum;
/**

@@ -465,7 +484,8 @@ * @category combinators

res.push(toTree(focus.value));
if (stack.length === 0) {
var tmp = stack.pop();
if (tmp === undefined) {
return res;
}
else {
focus = stack.pop();
focus = tmp;
}

@@ -483,3 +503,4 @@ break;

*/
exports.draw = function (e) { return toForest(e).map(drawTree).join('\n'); };
var draw = function (e) { return toForest(e).map(drawTree).join('\n'); };
exports.draw = draw;
/**

@@ -486,0 +507,0 @@ * @internal

@@ -100,5 +100,6 @@ "use strict";

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

@@ -141,5 +142,6 @@ * @category combinators

*/
exports.contramap = function (f) { return function (fa) {
var contramap = function (f) { return function (fa) {
return contramap_(fa, f);
}; };
exports.contramap = contramap;
/**

@@ -149,5 +151,6 @@ * @category Semigroupoid

*/
exports.compose = function (ea) { return function (ab) {
var compose = function (ea) { return function (ab) {
return compose_(ab, ea);
}; };
exports.compose = compose;
/**

@@ -154,0 +157,0 @@ * @category Category

@@ -133,5 +133,6 @@ "use strict";

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

@@ -138,0 +139,0 @@ * @category combinators

@@ -8,3 +8,4 @@ "use strict";

*/
exports.of = function (a) { return ({ _tag: 'Of', value: a }); };
var of = function (a) { return ({ _tag: 'Of', value: a }); };
exports.of = of;
/**

@@ -14,3 +15,3 @@ * @category constructors

*/
exports.concat = function (left, right) { return ({
var concat = function (left, right) { return ({
_tag: 'Concat',

@@ -20,2 +21,3 @@ left: left,

}); };
exports.concat = concat;
/**

@@ -25,3 +27,3 @@ * @category destructors

*/
exports.fold = function (onOf, onConcat) { return function (f) {
var fold = function (onOf, onConcat) { return function (f) {
switch (f._tag) {

@@ -34,2 +36,3 @@ case 'Of':

}; };
exports.fold = fold;
/**

@@ -36,0 +39,0 @@ * @category instances

@@ -0,1 +1,12 @@

/**
* **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 { Refinement } from 'fp-ts/lib/function'
import { Literal, Schemable1, WithRefine1, WithUnion1, WithUnknownContainers1 } from './Schemable'

@@ -54,3 +65,3 @@ /**

export declare const refine: <I, A extends I, B extends A>(
refinement: (a: A) => a is B
refinement: Refinement<A, B>
) => (from: Guard<I, A>) => Guard<I, B>

@@ -57,0 +68,0 @@ /**

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.WithRefine = exports.WithUnion = exports.WithUnknownContainers = exports.Schemable = exports.URI = exports.id = exports.compose = exports.zero = exports.alt = exports.lazy = exports.sum = exports.union = exports.intersect = exports.tuple = exports.record = exports.array = 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.0
*/
var pipeable_1 = require("fp-ts/lib/pipeable");

@@ -23,3 +13,3 @@ var Schemable_1 = require("./Schemable");

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

@@ -33,2 +23,3 @@ for (var _i = 0; _i < arguments.length; _i++) {

};
exports.literal = literal;
// -------------------------------------------------------------------------------------

@@ -72,3 +63,3 @@ // primitives

exports.UnknownRecord = {
is: function (u) { return Object.prototype.toString.call(u) === '[object Object]'; }
is: function (u) { return u !== null && typeof u === 'object' && !Array.isArray(u); }
};

@@ -82,5 +73,6 @@ // -------------------------------------------------------------------------------------

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

@@ -90,5 +82,6 @@ * @category combinators

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

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

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

@@ -109,2 +102,3 @@ for (var k in properties) {

};
exports.type = type;
/**

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

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

@@ -126,2 +120,3 @@ for (var k in properties) {

};
exports.partial = partial;
/**

@@ -131,5 +126,6 @@ * @category combinators

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

@@ -139,3 +135,3 @@ * @category combinators

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

@@ -150,2 +146,3 @@ for (var k in r) {

};
exports.record = record;
/**

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

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

@@ -165,2 +162,3 @@ for (var _i = 0; _i < arguments.length; _i++) {

};
exports.tuple = tuple;
/**

@@ -170,5 +168,6 @@ * @category combinators

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

@@ -178,3 +177,3 @@ * @category combinators

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

@@ -188,2 +187,3 @@ for (var _i = 0; _i < arguments.length; _i++) {

};
exports.union = union;
/**

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

*/
exports.sum = function (tag) { return function (members) {
var sum = function (tag) { return function (members) {
return pipeable_1.pipe(exports.UnknownRecord, exports.refine(function (r) {

@@ -203,2 +203,3 @@ var v = r[tag];

}; };
exports.sum = sum;
/**

@@ -208,3 +209,3 @@ * @category combinators

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

@@ -215,2 +216,3 @@ return {

};
exports.lazy = lazy;
/**

@@ -220,5 +222,6 @@ * @category combinators

*/
exports.alt = function (that) { return function (me) { return ({
var alt = function (that) { return function (me) { return ({
is: function (i) { return me.is(i) || that().is(i); }
}); }; };
exports.alt = alt;
/**

@@ -228,5 +231,6 @@ * @category combinators

*/
exports.zero = function () { return ({
var zero = function () { return ({
is: function (_) { return false; }
}); };
exports.zero = zero;
/**

@@ -236,5 +240,6 @@ * @category combinators

*/
exports.compose = function (to) { return function (from) { return ({
var compose = function (to) { return function (from) { return ({
is: function (i) { return from.is(i) && to.is(i); }
}); }; };
exports.compose = compose;
/**

@@ -244,5 +249,6 @@ * @category combinators

*/
exports.id = function () { return ({
var id = function () { return ({
is: function (_) { return true; }
}); };
exports.id = id;
// -------------------------------------------------------------------------------------

@@ -249,0 +255,0 @@ // instances

@@ -7,3 +7,3 @@ /**

/**
* @category Model
* @category Decode error
* @since 1.0.0

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

/**
* @category Model
* @category Decode error
* @since 1.0.0

@@ -24,3 +24,3 @@ */

/**
* @category Model
* @category Decode error
* @since 1.0.0

@@ -37,3 +37,3 @@ */

/**
* @category Model
* @category Decode error
* @since 1.0.0

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

/**
* @category Model
* @category Decode error
* @since 1.0.0

@@ -49,8 +49,21 @@ */

/**
* @category Model
* @category Decode error
* @since 1.0.0
*/
export declare const failures: <T>(errors: Errors) => Validation<T>
/**
* @category Decode error
* @since 1.0.0
*/
export declare const failure: <T>(value: unknown, context: Context, message?: string | undefined) => Either<Errors, T>
/**
* @category Decode error
* @since 1.0.0
*/
export declare const success: <T>(value: T) => Validation<T>
/**
* @since 1.0.0
*/
export declare type Is<A> = (u: unknown) => u is A
/**
* @category Model
* @since 1.0.0

@@ -60,3 +73,2 @@ */

/**
* @category Model
* @since 1.0.0

@@ -66,3 +78,2 @@ */

/**
* @category Model
* @since 1.0.0

@@ -80,2 +91,3 @@ */

/**
* @category Codec
* @since 1.0.0

@@ -85,2 +97,3 @@ */

/**
* @category Codec
* @since 1.0.0

@@ -90,2 +103,3 @@ */

/**
* @category Codec
* @since 1.0.0

@@ -95,3 +109,3 @@ */

/**
* @category Model
* @category Codec
* @since 1.0.0

@@ -105,3 +119,3 @@ */

/**
* @category Model
* @category Codec
* @since 1.0.0

@@ -113,3 +127,3 @@ */

/**
* @category Model
* @category Codec
* @since 1.0.0

@@ -173,26 +187,84 @@ */

*/
export declare const getFunctionName: (f: Function) => string
export declare function getFunctionName(f: Function): string
/**
* @since 1.0.0
*/
export declare const getContextEntry: (key: string, decoder: Decoder<any, any>) => ContextEntry
export declare function getContextEntry(key: string, decoder: Decoder<any, any>): ContextEntry
/**
* @since 1.0.0
*/
export declare const appendContext: (c: Context, key: string, decoder: Decoder<any, any>, actual?: unknown) => Context
export declare function appendContext(c: Context, key: string, decoder: Decoder<any, any>, actual?: unknown): Context
/**
* @since 1.0.0
*/
export declare const failures: <T>(errors: Errors) => Validation<T>
export interface AnyProps {
[key: string]: Any
}
/**
* @since 1.0.0
*/
export declare const failure: <T>(value: unknown, context: Context, message?: string | undefined) => Either<Errors, T>
export declare type TypeOfProps<P extends AnyProps> = {
[K in keyof P]: TypeOf<P[K]>
}
/**
* @since 1.0.0
*/
export declare const success: <T>(value: T) => Validation<T>
export declare type OutputOfProps<P extends AnyProps> = {
[K in keyof P]: OutputOf<P[K]>
}
/**
* @since 1.0.0
*/
export interface Props {
[key: string]: Mixed
}
/**
* @since 1.0.0
*/
export declare type TypeOfPartialProps<P extends AnyProps> = {
[K in keyof P]?: TypeOf<P[K]>
}
/**
* @since 1.0.0
*/
export declare type OutputOfPartialProps<P extends AnyProps> = {
[K in keyof P]?: OutputOf<P[K]>
}
/**
* @since 1.0.0
*/
export declare type TypeOfDictionary<D extends Any, C extends Any> = {
[K in TypeOf<D>]: TypeOf<C>
}
/**
* @since 1.0.0
*/
export declare type OutputOfDictionary<D extends Any, C extends Any> = {
[K in OutputOf<D>]: OutputOf<C>
}
/**
* @since 1.1.0
*/
export interface HasPropsRefinement extends RefinementType<HasProps, any, any, any> {}
/**
* @since 1.1.0
*/
export interface HasPropsReadonly extends ReadonlyType<HasProps, any, any, any> {}
/**
* @since 1.1.0
*/
export interface HasPropsIntersection extends IntersectionType<Array<HasProps>, any, any, any> {}
/**
* @since 1.1.0
*/
export declare type HasProps =
| HasPropsRefinement
| HasPropsReadonly
| HasPropsIntersection
| InterfaceType<any, any, any, any>
| StrictType<any, any, any, any>
| PartialType<any, any, any, any>
/**
* @since 1.0.0
*/
export declare class NullType extends Type<null> {

@@ -210,3 +282,3 @@ /**

/**
* @category Primitives
* @category primitives
* @since 1.0.0

@@ -245,3 +317,3 @@ */

/**
* @category Primitives
* @category primitives
* @since 1.2.0

@@ -265,3 +337,3 @@ */

/**
* @category Primitives
* @category primitives
* @since 1.5.0

@@ -285,3 +357,3 @@ */

/**
* @category Primitives
* @category primitives
* @since 1.0.0

@@ -305,3 +377,3 @@ */

/**
* @category Primitives
* @category primitives
* @since 1.0.0

@@ -325,3 +397,3 @@ */

/**
* @category Primitives
* @category primitives
* @since 2.1.0

@@ -345,3 +417,3 @@ */

/**
* @category Primitives
* @category primitives
* @since 1.0.0

@@ -365,3 +437,3 @@ */

/**
* @category Primitives
* @category primitives
* @since 1.7.1

@@ -383,34 +455,92 @@ */

/**
* @category Primitives
* @since 1.5.3
*/
export interface UnknownRecordC extends AnyDictionaryType {}
/**
* @category primitives
* @since 1.7.1
*/
export declare const UnknownRecord: UnknownRecordC
export {
/**
* @category primitives
* @since 1.0.0
*/
nullType as null,
/**
* @category primitives
* @since 1.0.0
*/
undefinedType as undefined,
/**
* @category primitives
* @since 1.0.0
*/
voidType as void
}
declare type LiteralValue = string | number | boolean
/**
* @since 1.0.0
*/
export declare class LiteralType<V extends LiteralValue> extends Type<V> {
readonly value: V
/**
* @since 1.0.0
*/
readonly _tag: 'LiteralType'
constructor(
name: string,
is: LiteralType<V>['is'],
validate: LiteralType<V>['validate'],
encode: LiteralType<V>['encode'],
value: V
)
}
/**
* @since 1.5.3
*/
export interface UnknownRecordC extends AnyDictionaryType {}
export interface LiteralC<V extends LiteralValue> extends LiteralType<V> {}
/**
* @category deprecated
* @category constructors
* @since 1.0.0
* @deprecated
*/
export declare class FunctionType extends Type<Function> {
export declare function literal<V extends LiteralValue>(value: V, name?: string): LiteralC<V>
/**
* @since 1.0.0
*/
export declare class KeyofType<
D extends {
[key: string]: unknown
}
> extends Type<keyof D> {
readonly keys: D
/**
* @since 1.0.0
*/
readonly _tag: 'FunctionType'
constructor()
readonly _tag: 'KeyofType'
constructor(
name: string,
is: KeyofType<D>['is'],
validate: KeyofType<D>['validate'],
encode: KeyofType<D>['encode'],
keys: D
)
}
/**
* @category deprecated
* @since 1.5.3
* @deprecated
*/
export interface FunctionC extends FunctionType {}
export interface KeyofC<
D extends {
[key: string]: unknown
}
> extends KeyofType<D> {}
/**
* @category deprecated
* @category constructors
* @since 1.0.0
* @deprecated
*/
export declare const Function: FunctionC
export declare function keyof<
D extends {
[key: string]: unknown
}
>(keys: D, name?: string): KeyofC<D>
/**

@@ -451,10 +581,12 @@ * @since 1.0.0

/**
* @category Combinators
* @category combinators
* @since 1.8.1
*/
export declare const brand: <C extends Any, N extends string, B extends { readonly [K in N]: symbol }>(
codec: C,
predicate: Refinement<TypeOf<C>, Branded<TypeOf<C>, B>>,
name: N
) => BrandC<C, B>
export declare function brand<
C extends Any,
N extends string,
B extends {
readonly [K in N]: symbol
}
>(codec: C, predicate: Refinement<TypeOf<C>, Branded<TypeOf<C>, B>>, name: N): BrandC<C, B>
/**

@@ -469,3 +601,3 @@ * @since 1.8.1

*
* @category Primitives
* @category primitives
* @since 1.8.1

@@ -478,71 +610,5 @@ */

export declare type Int = Branded<number, IntBrand>
declare type LiteralValue = string | number | boolean
/**
* @since 1.0.0
*/
export declare class LiteralType<V extends LiteralValue> extends Type<V> {
readonly value: V
/**
* @since 1.0.0
*/
readonly _tag: 'LiteralType'
constructor(
name: string,
is: LiteralType<V>['is'],
validate: LiteralType<V>['validate'],
encode: LiteralType<V>['encode'],
value: V
)
}
/**
* @since 1.5.3
*/
export interface LiteralC<V extends LiteralValue> extends LiteralType<V> {}
/**
* @category Combinators
* @since 1.0.0
*/
export declare const literal: <V extends string | number | boolean>(value: V, name?: string) => LiteralC<V>
/**
* @since 1.0.0
*/
export declare class KeyofType<
D extends {
[key: string]: unknown
}
> extends Type<keyof D> {
readonly keys: D
/**
* @since 1.0.0
*/
readonly _tag: 'KeyofType'
constructor(
name: string,
is: KeyofType<D>['is'],
validate: KeyofType<D>['validate'],
encode: KeyofType<D>['encode'],
keys: D
)
}
/**
* @since 1.5.3
*/
export interface KeyofC<
D extends {
[key: string]: unknown
}
> extends KeyofType<D> {}
/**
* @category Combinators
* @since 1.0.0
*/
export declare const keyof: <D extends {
[key: string]: unknown
}>(
keys: D,
name?: string
) => KeyofC<D>
/**
* @since 1.0.0
*/
export declare class RecursiveType<C extends Any, A = any, O = A, I = unknown> extends Type<A, O, I> {

@@ -567,9 +633,9 @@ runDefinition: () => C

/**
* @category Combinators
* @category combinators
* @since 1.0.0
*/
export declare const recursion: <A, O = A, I = unknown, C extends Type<A, O, I> = Type<A, O, I>>(
export declare function recursion<A, O = A, I = unknown, C extends Type<A, O, I> = Type<A, O, I>>(
name: string,
definition: (self: C) => C
) => RecursiveType<C, A, O, I>
): RecursiveType<C, A, O, I>
/**

@@ -597,6 +663,6 @@ * @since 1.0.0

/**
* @category Combinators
* @category combinators
* @since 1.0.0
*/
export declare const array: <C extends Mixed>(item: C, name?: string) => ArrayC<C>
export declare function array<C extends Mixed>(item: C, name?: string): ArrayC<C>
/**

@@ -620,26 +686,2 @@ * @since 1.0.0

/**
* @since 1.0.0
*/
export interface AnyProps {
[key: string]: Any
}
/**
* @since 1.0.0
*/
export declare type TypeOfProps<P extends AnyProps> = {
[K in keyof P]: TypeOf<P[K]>
}
/**
* @since 1.0.0
*/
export declare type OutputOfProps<P extends AnyProps> = {
[K in keyof P]: OutputOf<P[K]>
}
/**
* @since 1.0.0
*/
export interface Props {
[key: string]: Mixed
}
/**
* @since 1.5.3

@@ -659,6 +701,6 @@ */

/**
* @category Combinators
* @category combinators
* @since 1.0.0
*/
export declare const type: <P extends Props>(props: P, name?: string) => TypeC<P>
export declare function type<P extends Props>(props: P, name?: string): TypeC<P>
/**

@@ -682,14 +724,2 @@ * @since 1.0.0

/**
* @since 1.0.0
*/
export declare type TypeOfPartialProps<P extends AnyProps> = {
[K in keyof P]?: TypeOf<P[K]>
}
/**
* @since 1.0.0
*/
export declare type OutputOfPartialProps<P extends AnyProps> = {
[K in keyof P]?: OutputOf<P[K]>
}
/**
* @since 1.5.3

@@ -709,6 +739,6 @@ */

/**
* @category Combinators
* @category combinators
* @since 1.0.0
*/
export declare const partial: <P extends Props>(props: P, name?: string) => PartialC<P>
export declare function partial<P extends Props>(props: P, name?: string): PartialC<P>
/**

@@ -734,14 +764,2 @@ * @since 1.0.0

/**
* @since 1.0.0
*/
export declare type TypeOfDictionary<D extends Any, C extends Any> = {
[K in TypeOf<D>]: TypeOf<C>
}
/**
* @since 1.0.0
*/
export declare type OutputOfDictionary<D extends Any, C extends Any> = {
[K in OutputOf<D>]: OutputOf<C>
}
/**
* @since 1.5.3

@@ -762,3 +780,3 @@ */

/**
* @category Combinators
* @category combinators
* @since 1.7.1

@@ -790,6 +808,6 @@ */

/**
* @category Combinators
* @category combinators
* @since 1.0.0
*/
export declare const union: <CS extends [Mixed, Mixed, ...Mixed[]]>(codecs: CS, name?: string) => UnionC<CS>
export declare function union<CS extends [Mixed, Mixed, ...Array<Mixed>]>(codecs: CS, name?: string): UnionC<CS>
/**

@@ -855,3 +873,3 @@ * @since 1.0.0

/**
* @category Combinators
* @category combinators
* @since 1.0.0

@@ -946,3 +964,3 @@ */

/**
* @category Combinators
* @category combinators
* @since 1.0.0

@@ -987,6 +1005,6 @@ */

/**
* @category Combinators
* @category combinators
* @since 1.0.0
*/
export declare const readonly: <C extends Mixed>(codec: C, name?: string) => ReadonlyC<C>
export declare function readonly<C extends Mixed>(codec: C, name?: string): ReadonlyC<C>
/**

@@ -1015,10 +1033,10 @@ * @since 1.0.0

/**
* @category Combinators
* @category combinators
* @since 1.0.0
*/
export declare const readonlyArray: <C extends Mixed>(item: C, name?: string) => ReadonlyArrayC<C>
export declare function readonlyArray<C extends Mixed>(item: C, name?: string): ReadonlyArrayC<C>
/**
* Strips additional properties
* Strips additional properties, equivalent to `exact(type(props))`.
*
* @category Combinators
* @category combinators
* @since 1.0.0

@@ -1028,3 +1046,52 @@ */

/**
* @category deprecated
* @since 1.1.0
*/
export declare class ExactType<C extends Any, A = any, O = A, I = unknown> extends Type<A, O, I> {
readonly type: C
/**
* @since 1.0.0
*/
readonly _tag: 'ExactType'
constructor(
name: string,
is: ExactType<C, A, O, I>['is'],
validate: ExactType<C, A, O, I>['validate'],
encode: ExactType<C, A, O, I>['encode'],
type: C
)
}
/**
* @since 1.5.3
*/
export interface ExactC<C extends HasProps> extends ExactType<C, TypeOf<C>, OutputOf<C>, InputOf<C>> {}
/**
* Strips additional properties.
*
* @category combinators
* @since 1.1.0
*/
export declare function exact<C extends HasProps>(codec: C, name?: string): ExactC<C>
/**
* @since 1.0.0
* @deprecated
*/
export declare class FunctionType extends Type<Function> {
/**
* @since 1.0.0
*/
readonly _tag: 'FunctionType'
constructor()
}
/**
* @since 1.5.3
* @deprecated
*/
export interface FunctionC extends FunctionType {}
/**
* @category primitives
* @since 1.0.0
* @deprecated
*/
export declare const Function: FunctionC
/**
* @since 1.3.0

@@ -1051,3 +1118,2 @@ * @deprecated

/**
* @category deprecated
* @since 1.5.3

@@ -1059,5 +1125,5 @@ * @deprecated

/**
* Use `union` instead
* Use `union` instead.
*
* @category deprecated
* @category combinators
* @since 1.3.0

@@ -1071,67 +1137,7 @@ * @deprecated

) => TaggedUnionC<Tag, CS>
/**
* @since 1.1.0
*/
export declare class ExactType<C extends Any, A = any, O = A, I = unknown> extends Type<A, O, I> {
readonly type: C
/**
* @since 1.0.0
*/
readonly _tag: 'ExactType'
constructor(
name: string,
is: ExactType<C, A, O, I>['is'],
validate: ExactType<C, A, O, I>['validate'],
encode: ExactType<C, A, O, I>['encode'],
type: C
)
}
/**
* @since 1.1.0
*/
export interface HasPropsRefinement extends RefinementType<HasProps, any, any, any> {}
/**
* @since 1.1.0
*/
export interface HasPropsReadonly extends ReadonlyType<HasProps, any, any, any> {}
/**
* @since 1.1.0
*/
export interface HasPropsIntersection extends IntersectionType<Array<HasProps>, any, any, any> {}
/**
* @since 1.1.0
*/
export declare type HasProps =
| HasPropsRefinement
| HasPropsReadonly
| HasPropsIntersection
| InterfaceType<any, any, any, any>
| StrictType<any, any, any, any>
| PartialType<any, any, any, any>
/**
* @since 1.5.3
*/
export interface ExactC<C extends HasProps> extends ExactType<C, TypeOf<C>, OutputOf<C>, InputOf<C>> {}
/**
* Strips additional properties
* @since 1.1.0
*/
export declare const exact: <C extends HasProps>(codec: C, name?: string) => ExactC<C>
export {
/**
* @since 1.0.0
*/
nullType as null
}
export {
/**
* @since 1.0.0
*/
undefinedType as undefined
}
export {
/**
* Use `UnknownArray` instead
* Use `UnknownArray` instead.
*
* @category deprecated
* @category primitives
* @deprecated

@@ -1144,5 +1150,5 @@ * @since 1.0.0

/**
* Use `type` instead
* Use `type` instead.
*
* @category deprecated
* @category combinators
* @deprecated

@@ -1153,12 +1159,5 @@ * @since 1.0.0

}
export {
/**
* @since 1.0.0
*/
voidType as void
}
/**
* Use `unknown` instead
* Use `unknown` instead.
*
* @category deprecated
* @since 1.0.0

@@ -1169,3 +1168,2 @@ * @deprecated

/**
* @category deprecated
* @since 1.0.0

@@ -1176,3 +1174,2 @@ * @deprecated

/**
* @category deprecated
* @since 1.0.0

@@ -1183,3 +1180,2 @@ * @deprecated

/**
* @category deprecated
* @since 1.0.0

@@ -1196,3 +1192,2 @@ * @deprecated

/**
* @category deprecated
* @since 1.5.3

@@ -1203,3 +1198,3 @@ * @deprecated

/**
* @category deprecated
* @category primitives
* @since 1.0.0

@@ -1210,3 +1205,2 @@ * @deprecated

/**
* @category deprecated
* @since 1.0.0

@@ -1223,3 +1217,2 @@ * @deprecated

/**
* @category deprecated
* @since 1.5.3

@@ -1230,5 +1223,5 @@ * @deprecated

/**
* Use `unknown` instead
* Use `unknown` instead.
*
* @category deprecated
* @category primitives
* @since 1.0.0

@@ -1239,5 +1232,5 @@ * @deprecated

/**
* Use `UnknownRecord` instead
* Use `UnknownRecord` instead.
*
* @category deprecated
* @category primitives
* @since 1.0.0

@@ -1248,3 +1241,2 @@ * @deprecated

/**
* @category deprecated
* @since 1.0.0

@@ -1261,3 +1253,2 @@ * @deprecated

/**
* @category deprecated
* @since 1.5.3

@@ -1268,5 +1259,5 @@ * @deprecated

/**
* Use `UnknownRecord` instead
* Use `UnknownRecord` instead.
*
* @category deprecated
* @category primitives
* @since 1.0.0

@@ -1277,5 +1268,4 @@ * @deprecated

/**
* Use `BrandC` instead
* Use `BrandC` instead.
*
* @category deprecated
* @since 1.5.3

@@ -1286,5 +1276,5 @@ * @deprecated

/**
* Use `brand` instead
* Use `brand` instead.
*
* @category deprecated
* @category combinators
* @since 1.0.0

@@ -1299,5 +1289,5 @@ * @deprecated

/**
* Use `Int` instead
* Use `Int` instead.
*
* @category deprecated
* @category primitives
* @since 1.0.0

@@ -1308,5 +1298,5 @@ * @deprecated

/**
* Use `record` instead
* Use `record` instead.
*
* @category deprecated
* @category combinators
* @since 1.0.0

@@ -1317,5 +1307,2 @@ * @deprecated

/**
* used in `intersection` as a workaround for #234
*
* @category deprecated
* @since 1.4.2

@@ -1328,3 +1315,2 @@ * @deprecated

/**
* @category deprecated
* @since 1.0.0

@@ -1348,3 +1334,2 @@ * @deprecated

/**
* @category deprecated
* @since 1.5.3

@@ -1365,3 +1350,2 @@ * @deprecated

/**
* @category deprecated
* @since 1.3.0

@@ -1374,3 +1358,2 @@ * @deprecated

/**
* @category deprecated
* @since 1.3.0

@@ -1381,3 +1364,2 @@ * @deprecated

/**
* @category deprecated
* @since 1.3.0

@@ -1388,3 +1370,2 @@ * @deprecated

/**
* @category deprecated
* @since 1.3.0

@@ -1410,3 +1391,2 @@ * @deprecated

/**
* @category deprecated
* @since 1.3.0

@@ -1418,3 +1398,2 @@ * @deprecated

/**
* @category deprecated
* @since 1.3.0

@@ -1425,3 +1404,2 @@ * @deprecated

/**
* @category deprecated
* @since 1.3.0

@@ -1439,5 +1417,5 @@ * @deprecated

/**
* Drops the codec "kind"
* Drops the codec "kind".
*
* @category deprecated
* @category combinators
* @since 1.1.0

@@ -1448,3 +1426,2 @@ * @deprecated

/**
* @category deprecated
* @since 1.0.0

@@ -1459,3 +1436,2 @@ * @deprecated

/**
* @category deprecated
* @since 1.1.0

@@ -1476,5 +1452,5 @@ * @deprecated

/**
* Keeps the codec "kind"
* Keeps the codec "kind".
*
* @category deprecated
* @category combinators
* @since 1.1.0

@@ -1481,0 +1457,0 @@ * @deprecated

@@ -34,3 +34,4 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.getIndex = exports.getTags = exports.emptyTags = exports.alias = exports.clean = exports.StrictType = exports.dictionary = exports.Integer = exports.refinement = exports.object = exports.ObjectType = exports.Dictionary = exports.any = exports.AnyType = exports.never = exports.NeverType = exports.getDefaultContext = exports.getValidationError = exports.void = exports.interface = exports.Array = exports.undefined = exports.null = exports.exact = exports.ExactType = exports.taggedUnion = exports.TaggedUnionType = exports.strict = exports.readonlyArray = exports.ReadonlyArrayType = exports.readonly = exports.ReadonlyType = exports.tuple = exports.TupleType = exports.intersection = exports.mergeAll = exports.IntersectionType = exports.union = exports.UnionType = exports.record = exports.getDomainKeys = exports.DictionaryType = exports.partial = exports.PartialType = exports.type = exports.InterfaceType = exports.array = exports.ArrayType = exports.recursion = exports.RecursiveType = exports.keyof = exports.KeyofType = exports.literal = exports.LiteralType = exports.Int = exports.brand = exports.RefinementType = exports.Function = exports.FunctionType = exports.UnknownRecord = exports.AnyDictionaryType = exports.UnknownArray = exports.AnyArrayType = exports.boolean = exports.BooleanType = exports.bigint = exports.BigIntType = exports.number = exports.NumberType = exports.string = exports.StringType = exports.unknown = exports.UnknownType = exports.voidType = exports.VoidType = exports.UndefinedType = exports.nullType = exports.NullType = exports.success = exports.failure = exports.failures = exports.appendContext = exports.getContextEntry = exports.getFunctionName = exports.identity = exports.Type = void 0;
exports.partial = exports.PartialType = exports.type = exports.InterfaceType = exports.array = exports.ArrayType = exports.recursion = exports.RecursiveType = exports.Int = exports.brand = exports.RefinementType = exports.keyof = exports.KeyofType = exports.literal = exports.LiteralType = exports.void = exports.undefined = exports.null = exports.UnknownRecord = exports.AnyDictionaryType = exports.UnknownArray = exports.AnyArrayType = exports.boolean = exports.BooleanType = exports.bigint = exports.BigIntType = exports.number = exports.NumberType = exports.string = exports.StringType = exports.unknown = exports.UnknownType = exports.voidType = exports.VoidType = exports.UndefinedType = exports.nullType = exports.NullType = exports.getIndex = exports.getTags = exports.emptyTags = exports.mergeAll = exports.getDomainKeys = exports.appendContext = exports.getContextEntry = exports.getFunctionName = exports.identity = exports.Type = exports.success = exports.failure = exports.failures = void 0;
exports.alias = exports.clean = exports.StrictType = exports.dictionary = exports.Integer = exports.refinement = exports.object = exports.ObjectType = exports.Dictionary = exports.any = exports.AnyType = exports.never = exports.NeverType = exports.getDefaultContext = exports.getValidationError = exports.interface = exports.Array = exports.taggedUnion = exports.TaggedUnionType = exports.Function = exports.FunctionType = exports.exact = exports.ExactType = exports.strict = exports.readonlyArray = exports.ReadonlyArrayType = exports.readonly = exports.ReadonlyType = exports.tuple = exports.TupleType = exports.intersection = exports.IntersectionType = exports.union = exports.UnionType = exports.record = exports.DictionaryType = void 0;
/**

@@ -41,5 +42,23 @@ * @since 1.0.0

/**
* @category Model
* @category Decode error
* @since 1.0.0
*/
exports.failures = Either_1.left;
/**
* @category Decode error
* @since 1.0.0
*/
var failure = function (value, context, message) {
return exports.failures([{ value: value, context: context, message: message }]);
};
exports.failure = failure;
/**
* @category Decode error
* @since 1.0.0
*/
exports.success = Either_1.right;
/**
* @category Codec
* @since 1.0.0
*/
var Type = /** @class */ (function () {

@@ -97,20 +116,28 @@ function Type(

exports.Type = Type;
// -------------------------------------------------------------------------------------
// utils
// -------------------------------------------------------------------------------------
/**
* @since 1.0.0
*/
exports.identity = function (a) { return a; };
var identity = function (a) { return a; };
exports.identity = identity;
/**
* @since 1.0.0
*/
exports.getFunctionName = function (f) {
function getFunctionName(f) {
return f.displayName || f.name || "<function" + f.length + ">";
};
}
exports.getFunctionName = getFunctionName;
/**
* @since 1.0.0
*/
exports.getContextEntry = function (key, decoder) { return ({ key: key, type: decoder }); };
function getContextEntry(key, decoder) {
return { key: key, type: decoder };
}
exports.getContextEntry = getContextEntry;
/**
* @since 1.0.0
*/
exports.appendContext = function (c, key, decoder, actual) {
function appendContext(c, key, decoder, actual) {
var len = c.length;

@@ -123,23 +150,395 @@ var r = Array(len + 1);

return r;
};
}
exports.appendContext = appendContext;
function pushAll(xs, ys) {
var l = ys.length;
for (var i = 0; i < l; i++) {
xs.push(ys[i]);
}
}
var hasOwnProperty = Object.prototype.hasOwnProperty;
function getNameFromProps(props) {
return Object.keys(props)
.map(function (k) { return k + ": " + props[k].name; })
.join(', ');
}
function useIdentity(codecs) {
for (var i = 0; i < codecs.length; i++) {
if (codecs[i].encode !== exports.identity) {
return false;
}
}
return true;
}
function getInterfaceTypeName(props) {
return "{ " + getNameFromProps(props) + " }";
}
function getPartialTypeName(inner) {
return "Partial<" + inner + ">";
}
function enumerableRecord(keys, domain, codomain, name) {
if (name === void 0) { name = "{ [K in " + domain.name + "]: " + codomain.name + " }"; }
var len = keys.length;
return new DictionaryType(name, function (u) { return exports.UnknownRecord.is(u) && keys.every(function (k) { return codomain.is(u[k]); }); }, function (u, c) {
var e = exports.UnknownRecord.validate(u, c);
if (Either_1.isLeft(e)) {
return e;
}
var o = e.right;
var a = {};
var errors = [];
var changed = false;
for (var i = 0; i < len; i++) {
var k = keys[i];
var ok = o[k];
var codomainResult = codomain.validate(ok, appendContext(c, k, codomain, ok));
if (Either_1.isLeft(codomainResult)) {
pushAll(errors, codomainResult.left);
}
else {
var vok = codomainResult.right;
changed = changed || vok !== ok;
a[k] = vok;
}
}
return errors.length > 0 ? exports.failures(errors) : exports.success((changed || Object.keys(o).length !== len ? a : o));
}, codomain.encode === exports.identity
? exports.identity
: function (a) {
var s = {};
for (var i = 0; i < len; i++) {
var k = keys[i];
s[k] = codomain.encode(a[k]);
}
return s;
}, domain, codomain);
}
/**
* @since 1.0.0
* @internal
*/
exports.failures = Either_1.left;
function getDomainKeys(domain) {
var _a;
if (isLiteralC(domain)) {
var literal_1 = domain.value;
if (exports.string.is(literal_1)) {
return _a = {}, _a[literal_1] = null, _a;
}
}
else if (isKeyofC(domain)) {
return domain.keys;
}
else if (isUnionC(domain)) {
var keys = domain.types.map(function (type) { return getDomainKeys(type); });
return keys.some(undefinedType.is) ? undefined : Object.assign.apply(Object, __spreadArrays([{}], keys));
}
return undefined;
}
exports.getDomainKeys = getDomainKeys;
function nonEnumerableRecord(domain, codomain, name) {
if (name === void 0) { name = "{ [K in " + domain.name + "]: " + codomain.name + " }"; }
return new DictionaryType(name, function (u) {
if (exports.UnknownRecord.is(u)) {
return Object.keys(u).every(function (k) { return domain.is(k) && codomain.is(u[k]); });
}
return isAnyC(codomain) && Array.isArray(u);
}, function (u, c) {
if (exports.UnknownRecord.is(u)) {
var a = {};
var errors = [];
var keys = Object.keys(u);
var len = keys.length;
var changed = false;
for (var i = 0; i < len; i++) {
var k = keys[i];
var ok = u[k];
var domainResult = domain.validate(k, appendContext(c, k, domain, k));
if (Either_1.isLeft(domainResult)) {
pushAll(errors, domainResult.left);
}
else {
var vk = domainResult.right;
changed = changed || vk !== k;
k = vk;
var codomainResult = codomain.validate(ok, appendContext(c, k, codomain, ok));
if (Either_1.isLeft(codomainResult)) {
pushAll(errors, codomainResult.left);
}
else {
var vok = codomainResult.right;
changed = changed || vok !== ok;
a[k] = vok;
}
}
}
return errors.length > 0 ? exports.failures(errors) : exports.success((changed ? a : u));
}
if (isAnyC(codomain) && Array.isArray(u)) {
return exports.success(u);
}
return exports.failure(u, c);
}, domain.encode === exports.identity && codomain.encode === exports.identity
? exports.identity
: function (a) {
var s = {};
var keys = Object.keys(a);
var len = keys.length;
for (var i = 0; i < len; i++) {
var k = keys[i];
s[String(domain.encode(k))] = codomain.encode(a[k]);
}
return s;
}, domain, codomain);
}
function getUnionName(codecs) {
return '(' + codecs.map(function (type) { return type.name; }).join(' | ') + ')';
}
/**
* @since 1.0.0
* @internal
*/
exports.failure = function (value, context, message) {
return exports.failures([{ value: value, context: context, message: message }]);
};
function mergeAll(base, us) {
var equal = true;
var primitive = true;
var baseIsNotADictionary = !exports.UnknownRecord.is(base);
for (var _i = 0, us_1 = us; _i < us_1.length; _i++) {
var u = us_1[_i];
if (u !== base) {
equal = false;
}
if (exports.UnknownRecord.is(u)) {
primitive = false;
}
}
if (equal) {
return base;
}
else if (primitive) {
return us[us.length - 1];
}
var r = {};
for (var _a = 0, us_2 = us; _a < us_2.length; _a++) {
var u = us_2[_a];
for (var k in u) {
if (!r.hasOwnProperty(k) || baseIsNotADictionary || u[k] !== base[k]) {
r[k] = u[k];
}
}
}
return r;
}
exports.mergeAll = mergeAll;
function getProps(codec) {
switch (codec._tag) {
case 'RefinementType':
case 'ReadonlyType':
return getProps(codec.type);
case 'InterfaceType':
case 'StrictType':
case 'PartialType':
return codec.props;
case 'IntersectionType':
return codec.types.reduce(function (props, type) { return Object.assign(props, getProps(type)); }, {});
}
}
function stripKeys(o, props) {
var keys = Object.getOwnPropertyNames(o);
var shouldStrip = false;
var r = {};
for (var i = 0; i < keys.length; i++) {
var key = keys[i];
if (!hasOwnProperty.call(props, key)) {
shouldStrip = true;
}
else {
r[key] = o[key];
}
}
return shouldStrip ? r : o;
}
function getExactTypeName(codec) {
if (isTypeC(codec)) {
return "{| " + getNameFromProps(codec.props) + " |}";
}
else if (isPartialC(codec)) {
return getPartialTypeName("{| " + getNameFromProps(codec.props) + " |}");
}
return "Exact<" + codec.name + ">";
}
function isNonEmpty(as) {
return as.length > 0;
}
/**
* @since 1.0.0
* @internal
*/
exports.success = Either_1.right;
var pushAll = function (xs, ys) {
var l = ys.length;
for (var i = 0; i < l; i++) {
xs.push(ys[i]);
exports.emptyTags = {};
function intersect(a, b) {
var r = [];
for (var _i = 0, a_1 = a; _i < a_1.length; _i++) {
var v = a_1[_i];
if (b.indexOf(v) !== -1) {
r.push(v);
}
}
};
return r;
}
function mergeTags(a, b) {
if (a === exports.emptyTags) {
return b;
}
if (b === exports.emptyTags) {
return a;
}
var r = Object.assign({}, a);
for (var k in b) {
if (a.hasOwnProperty(k)) {
var intersection_1 = intersect(a[k], b[k]);
if (isNonEmpty(intersection_1)) {
r[k] = intersection_1;
}
else {
r = exports.emptyTags;
break;
}
}
else {
r[k] = b[k];
}
}
return r;
}
function intersectTags(a, b) {
if (a === exports.emptyTags || b === exports.emptyTags) {
return exports.emptyTags;
}
var r = exports.emptyTags;
for (var k in a) {
if (b.hasOwnProperty(k)) {
var intersection_2 = intersect(a[k], b[k]);
if (intersection_2.length === 0) {
if (r === exports.emptyTags) {
r = {};
}
r[k] = a[k].concat(b[k]);
}
}
}
return r;
}
// tslint:disable-next-line: deprecation
function isAnyC(codec) {
return codec._tag === 'AnyType';
}
function isLiteralC(codec) {
return codec._tag === 'LiteralType';
}
function isKeyofC(codec) {
return codec._tag === 'KeyofType';
}
function isTypeC(codec) {
return codec._tag === 'InterfaceType';
}
function isPartialC(codec) {
return codec._tag === 'PartialType';
}
// tslint:disable-next-line: deprecation
function isStrictC(codec) {
return codec._tag === 'StrictType';
}
function isExactC(codec) {
return codec._tag === 'ExactType';
}
// tslint:disable-next-line: deprecation
function isRefinementC(codec) {
return codec._tag === 'RefinementType';
}
function isIntersectionC(codec) {
return codec._tag === 'IntersectionType';
}
function isUnionC(codec) {
return codec._tag === 'UnionType';
}
function isRecursiveC(codec) {
return codec._tag === 'RecursiveType';
}
var lazyCodecs = [];
/**
* @internal
*/
function getTags(codec) {
if (lazyCodecs.indexOf(codec) !== -1) {
return exports.emptyTags;
}
if (isTypeC(codec) || isStrictC(codec)) {
var index = exports.emptyTags;
// tslint:disable-next-line: forin
for (var k in codec.props) {
var prop = codec.props[k];
if (isLiteralC(prop)) {
if (index === exports.emptyTags) {
index = {};
}
index[k] = [prop.value];
}
}
return index;
}
else if (isExactC(codec) || isRefinementC(codec)) {
return getTags(codec.type);
}
else if (isIntersectionC(codec)) {
return codec.types.reduce(function (tags, codec) { return mergeTags(tags, getTags(codec)); }, exports.emptyTags);
}
else if (isUnionC(codec)) {
return codec.types.slice(1).reduce(function (tags, codec) { return intersectTags(tags, getTags(codec)); }, getTags(codec.types[0]));
}
else if (isRecursiveC(codec)) {
lazyCodecs.push(codec);
var tags = getTags(codec.type);
lazyCodecs.pop();
return tags;
}
return exports.emptyTags;
}
exports.getTags = getTags;
/**
* @internal
*/
function getIndex(codecs) {
var tags = getTags(codecs[0]);
var keys = Object.keys(tags);
var len = codecs.length;
var _loop_1 = function (k) {
var all = tags[k].slice();
var index = [tags[k]];
for (var i = 1; i < len; i++) {
var codec = codecs[i];
var ctags = getTags(codec);
var values = ctags[k];
// tslint:disable-next-line: strict-type-predicates
if (values === undefined) {
return "continue-keys";
}
else {
if (values.some(function (v) { return all.indexOf(v) !== -1; })) {
return "continue-keys";
}
else {
all.push.apply(all, values);
index.push(values);
}
}
}
return { value: [k, index] };
};
keys: for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) {
var k = keys_1[_i];
var state_1 = _loop_1(k);
if (typeof state_1 === "object")
return state_1.value;
switch (state_1) {
case "continue-keys": continue keys;
}
}
return undefined;
}
exports.getIndex = getIndex;
// -------------------------------------------------------------------------------------

@@ -165,3 +564,3 @@ // primitives

/**
* @category Primitives
* @category primitives
* @since 1.0.0

@@ -206,3 +605,3 @@ */

/**
* @category Primitives
* @category primitives
* @since 1.2.0

@@ -229,3 +628,3 @@ */

/**
* @category Primitives
* @category primitives
* @since 1.5.0

@@ -251,3 +650,3 @@ */

/**
* @category Primitives
* @category primitives
* @since 1.0.0

@@ -273,3 +672,3 @@ */

/**
* @category Primitives
* @category primitives
* @since 1.0.0

@@ -297,3 +696,3 @@ */

/**
* @category Primitives
* @category primitives
* @since 2.1.0

@@ -319,3 +718,3 @@ */

/**
* @category Primitives
* @category primitives
* @since 1.0.0

@@ -341,3 +740,3 @@ */

/**
* @category Primitives
* @category primitives
* @since 1.7.1

@@ -367,3 +766,3 @@ */

/**
* @category Primitives
* @category primitives
* @since 1.7.1

@@ -373,67 +772,4 @@ */

/**
* @category deprecated
* @since 1.0.0
* @deprecated
*/
var FunctionType = /** @class */ (function (_super) {
__extends(FunctionType, _super);
function FunctionType() {
var _this = _super.call(this, 'Function',
// tslint:disable-next-line:strict-type-predicates
function (u) { return typeof u === 'function'; }, function (u, c) { return (_this.is(u) ? exports.success(u) : exports.failure(u, c)); }, exports.identity) || this;
/**
* @since 1.0.0
*/
_this._tag = 'FunctionType';
return _this;
}
return FunctionType;
}(Type));
exports.FunctionType = FunctionType;
/**
* @category deprecated
* @since 1.0.0
* @deprecated
*/
// tslint:disable-next-line: deprecation
exports.Function = new FunctionType();
/**
* @since 1.0.0
*/
var RefinementType = /** @class */ (function (_super) {
__extends(RefinementType, _super);
function RefinementType(name, is, validate, encode, type, predicate) {
var _this = _super.call(this, name, is, validate, encode) || this;
_this.type = type;
_this.predicate = predicate;
/**
* @since 1.0.0
*/
_this._tag = 'RefinementType';
return _this;
}
return RefinementType;
}(Type));
exports.RefinementType = RefinementType;
// -------------------------------------------------------------------------------------
// combinators
// -------------------------------------------------------------------------------------
/**
* @category Combinators
* @since 1.8.1
*/
exports.brand = function (codec, predicate, name) {
// tslint:disable-next-line: deprecation
return refinement(codec, predicate, name);
};
/**
* A branded codec representing an integer
*
* @category Primitives
* @since 1.8.1
*/
exports.Int = exports.brand(exports.number, function (n) { return Number.isInteger(n); }, 'Int');
/**
* @since 1.0.0
*/
var LiteralType = /** @class */ (function (_super) {

@@ -454,10 +790,11 @@ __extends(LiteralType, _super);

/**
* @category Combinators
* @category constructors
* @since 1.0.0
*/
exports.literal = function (value, name) {
function literal(value, name) {
if (name === void 0) { name = JSON.stringify(value); }
var is = function (u) { return u === value; };
return new LiteralType(name, is, function (u, c) { return (is(u) ? exports.success(value) : exports.failure(u, c)); }, exports.identity, value);
};
}
exports.literal = literal;
/**

@@ -480,8 +817,7 @@ * @since 1.0.0

exports.KeyofType = KeyofType;
var hasOwnProperty = Object.prototype.hasOwnProperty;
/**
* @category Combinators
* @category constructors
* @since 1.0.0
*/
exports.keyof = function (keys, name) {
function keyof(keys, name) {
if (name === void 0) { name = Object.keys(keys)

@@ -492,6 +828,44 @@ .map(function (k) { return JSON.stringify(k); })

return new KeyofType(name, is, function (u, c) { return (is(u) ? exports.success(u) : exports.failure(u, c)); }, exports.identity, keys);
};
}
exports.keyof = keyof;
// -------------------------------------------------------------------------------------
// combinators
// -------------------------------------------------------------------------------------
/**
* @since 1.0.0
*/
var RefinementType = /** @class */ (function (_super) {
__extends(RefinementType, _super);
function RefinementType(name, is, validate, encode, type, predicate) {
var _this = _super.call(this, name, is, validate, encode) || this;
_this.type = type;
_this.predicate = predicate;
/**
* @since 1.0.0
*/
_this._tag = 'RefinementType';
return _this;
}
return RefinementType;
}(Type));
exports.RefinementType = RefinementType;
/**
* @category combinators
* @since 1.8.1
*/
function brand(codec, predicate, name) {
// tslint:disable-next-line: deprecation
return refinement(codec, predicate, name);
}
exports.brand = brand;
/**
* A branded codec representing an integer
*
* @category primitives
* @since 1.8.1
*/
exports.Int = brand(exports.number, function (n) { return Number.isInteger(n); }, 'Int');
/**
* @since 1.0.0
*/
var RecursiveType = /** @class */ (function (_super) {

@@ -519,6 +893,6 @@ __extends(RecursiveType, _super);

/**
* @category Combinators
* @category combinators
* @since 1.0.0
*/
exports.recursion = function (name, definition) {
function recursion(name, definition) {
var cache;

@@ -534,3 +908,4 @@ var runDefinition = function () {

return Self;
};
}
exports.recursion = recursion;
/**

@@ -554,6 +929,6 @@ * @since 1.0.0

/**
* @category Combinators
* @category combinators
* @since 1.0.0
*/
exports.array = function (item, name) {
function array(item, name) {
if (name === void 0) { name = "Array<" + item.name + ">"; }

@@ -571,3 +946,3 @@ return new ArrayType(name, function (u) { return exports.UnknownArray.is(u) && u.every(item.is); }, function (u, c) {

var ui = us[i];
var result = item.validate(ui, exports.appendContext(c, String(i), item, ui));
var result = item.validate(ui, appendContext(c, String(i), item, ui));
if (Either_1.isLeft(result)) {

@@ -588,3 +963,4 @@ pushAll(errors, result.left);

}, item.encode === exports.identity ? exports.identity : function (a) { return a.map(item.encode); }, item);
};
}
exports.array = array;
/**

@@ -607,23 +983,7 @@ * @since 1.0.0

exports.InterfaceType = InterfaceType;
var getNameFromProps = function (props) {
return Object.keys(props)
.map(function (k) { return k + ": " + props[k].name; })
.join(', ');
};
var useIdentity = function (codecs) {
for (var i = 0; i < codecs.length; i++) {
if (codecs[i].encode !== exports.identity) {
return false;
}
}
return true;
};
var getInterfaceTypeName = function (props) {
return "{ " + getNameFromProps(props) + " }";
};
/**
* @category Combinators
* @category combinators
* @since 1.0.0
*/
exports.type = function (props, name) {
function type(props, name) {
if (name === void 0) { name = getInterfaceTypeName(props); }

@@ -657,3 +1017,3 @@ var keys = Object.keys(props);

var type_1 = types[i];
var result = type_1.validate(ak, exports.appendContext(c, k, type_1, ak));
var result = type_1.validate(ak, appendContext(c, k, type_1, ak));
if (Either_1.isLeft(result)) {

@@ -687,4 +1047,5 @@ pushAll(errors, result.left);

}, props);
};
exports.interface = exports.type;
}
exports.type = type;
exports.interface = type;
/**

@@ -707,10 +1068,7 @@ * @since 1.0.0

exports.PartialType = PartialType;
var getPartialTypeName = function (inner) {
return "Partial<" + inner + ">";
};
/**
* @category Combinators
* @category combinators
* @since 1.0.0
*/
exports.partial = function (props, name) {
function partial(props, name) {
if (name === void 0) { name = getPartialTypeName(getInterfaceTypeName(props)); }

@@ -744,3 +1102,3 @@ var keys = Object.keys(props);

var type_2 = props[k];
var result = type_2.validate(ak, exports.appendContext(c, k, type_2, ak));
var result = type_2.validate(ak, appendContext(c, k, type_2, ak));
if (Either_1.isLeft(result)) {

@@ -776,3 +1134,4 @@ if (ak !== undefined) {

}, props);
};
}
exports.partial = partial;
/**

@@ -796,117 +1155,4 @@ * @since 1.0.0

exports.DictionaryType = DictionaryType;
function enumerableRecord(keys, domain, codomain, name) {
if (name === void 0) { name = "{ [K in " + domain.name + "]: " + codomain.name + " }"; }
var len = keys.length;
return new DictionaryType(name, function (u) { return exports.UnknownRecord.is(u) && keys.every(function (k) { return codomain.is(u[k]); }); }, function (u, c) {
var e = exports.UnknownRecord.validate(u, c);
if (Either_1.isLeft(e)) {
return e;
}
var o = e.right;
var a = {};
var errors = [];
var changed = false;
for (var i = 0; i < len; i++) {
var k = keys[i];
var ok = o[k];
var codomainResult = codomain.validate(ok, exports.appendContext(c, k, codomain, ok));
if (Either_1.isLeft(codomainResult)) {
pushAll(errors, codomainResult.left);
}
else {
var vok = codomainResult.right;
changed = changed || vok !== ok;
a[k] = vok;
}
}
return errors.length > 0 ? exports.failures(errors) : exports.success((changed || Object.keys(o).length !== len ? a : o));
}, codomain.encode === exports.identity
? exports.identity
: function (a) {
var s = {};
for (var i = 0; i < len; i++) {
var k = keys[i];
s[k] = codomain.encode(a[k]);
}
return s;
}, domain, codomain);
}
/**
* @internal
*/
function getDomainKeys(domain) {
var _a;
if (isLiteralC(domain)) {
var literal_1 = domain.value;
if (exports.string.is(literal_1)) {
return _a = {}, _a[literal_1] = null, _a;
}
}
else if (isKeyofC(domain)) {
return domain.keys;
}
else if (isUnionC(domain)) {
var keys = domain.types.map(function (type) { return getDomainKeys(type); });
return keys.some(undefinedType.is) ? undefined : Object.assign.apply(Object, __spreadArrays([{}], keys));
}
return undefined;
}
exports.getDomainKeys = getDomainKeys;
function nonEnumerableRecord(domain, codomain, name) {
if (name === void 0) { name = "{ [K in " + domain.name + "]: " + codomain.name + " }"; }
return new DictionaryType(name, function (u) {
if (exports.UnknownRecord.is(u)) {
return Object.keys(u).every(function (k) { return domain.is(k) && codomain.is(u[k]); });
}
return isAnyC(codomain) && Array.isArray(u);
}, function (u, c) {
if (exports.UnknownRecord.is(u)) {
var a = {};
var errors = [];
var keys = Object.keys(u);
var len = keys.length;
var changed = false;
for (var i = 0; i < len; i++) {
var k = keys[i];
var ok = u[k];
var domainResult = domain.validate(k, exports.appendContext(c, k, domain, k));
if (Either_1.isLeft(domainResult)) {
pushAll(errors, domainResult.left);
}
else {
var vk = domainResult.right;
changed = changed || vk !== k;
k = vk;
var codomainResult = codomain.validate(ok, exports.appendContext(c, k, codomain, ok));
if (Either_1.isLeft(codomainResult)) {
pushAll(errors, codomainResult.left);
}
else {
var vok = codomainResult.right;
changed = changed || vok !== ok;
a[k] = vok;
}
}
}
return errors.length > 0 ? exports.failures(errors) : exports.success((changed ? a : u));
}
if (isAnyC(codomain) && Array.isArray(u)) {
return exports.success(u);
}
return exports.failure(u, c);
}, domain.encode === exports.identity && codomain.encode === exports.identity
? exports.identity
: function (a) {
var s = {};
var keys = Object.keys(a);
var len = keys.length;
for (var i = 0; i < len; i++) {
var k = keys[i];
s[String(domain.encode(k))] = codomain.encode(a[k]);
}
return s;
}, domain, codomain);
}
/**
* @category Combinators
* @category combinators
* @since 1.7.1

@@ -938,10 +1184,7 @@ */

exports.UnionType = UnionType;
var getUnionName = function (codecs) {
return '(' + codecs.map(function (type) { return type.name; }).join(' | ') + ')';
};
/**
* @category Combinators
* @category combinators
* @since 1.0.0
*/
exports.union = function (codecs, name) {
function union(codecs, name) {
if (name === void 0) { name = getUnionName(codecs); }

@@ -978,3 +1221,3 @@ var index = getIndex(codecs);

var codec = codecs[i];
return codec.validate(r, exports.appendContext(c, String(i), codec, r));
return codec.validate(r, appendContext(c, String(i), codec, r));
}, useIdentity(codecs)

@@ -998,3 +1241,3 @@ ? exports.identity

var codec = codecs[i];
var result = codec.validate(u, exports.appendContext(c, String(i), codec, u));
var result = codec.validate(u, appendContext(c, String(i), codec, u));
if (Either_1.isLeft(result)) {

@@ -1021,3 +1264,4 @@ pushAll(errors, result.left);

}
};
}
exports.union = union;
/**

@@ -1040,35 +1284,2 @@ * @since 1.0.0

exports.IntersectionType = IntersectionType;
/**
* @internal
*/
exports.mergeAll = function (base, us) {
var equal = true;
var primitive = true;
var baseIsNotADictionary = !exports.UnknownRecord.is(base);
for (var _i = 0, us_1 = us; _i < us_1.length; _i++) {
var u = us_1[_i];
if (u !== base) {
equal = false;
}
if (exports.UnknownRecord.is(u)) {
primitive = false;
}
}
if (equal) {
return base;
}
else if (primitive) {
return us[us.length - 1];
}
var r = {};
for (var _a = 0, us_2 = us; _a < us_2.length; _a++) {
var u = us_2[_a];
for (var k in u) {
if (!r.hasOwnProperty(k) || baseIsNotADictionary || u[k] !== base[k]) {
r[k] = u[k];
}
}
}
return r;
};
function intersection(codecs, name) {

@@ -1084,3 +1295,3 @@ if (name === void 0) { name = "(" + codecs.map(function (type) { return type.name; }).join(' & ') + ")"; }

var codec = codecs[i];
var result = codec.validate(u, exports.appendContext(c, String(i), codec, u));
var result = codec.validate(u, appendContext(c, String(i), codec, u));
if (Either_1.isLeft(result)) {

@@ -1093,7 +1304,7 @@ pushAll(errors, result.left);

}
return errors.length > 0 ? exports.failures(errors) : exports.success(exports.mergeAll(u, us));
return errors.length > 0 ? exports.failures(errors) : exports.success(mergeAll(u, us));
}, codecs.length === 0
? exports.identity
: function (a) {
return exports.mergeAll(a, codecs.map(function (codec) { return codec.encode(a); }));
return mergeAll(a, codecs.map(function (codec) { return codec.encode(a); }));
}, codecs);

@@ -1133,3 +1344,3 @@ }

var type_3 = codecs[i];
var result = type_3.validate(a, exports.appendContext(c, String(i), type_3, a));
var result = type_3.validate(a, appendContext(c, String(i), type_3, a));
if (Either_1.isLeft(result)) {

@@ -1171,9 +1382,10 @@ pushAll(errors, result.left);

/**
* @category Combinators
* @category combinators
* @since 1.0.0
*/
exports.readonly = function (codec, name) {
function readonly(codec, name) {
if (name === void 0) { name = "Readonly<" + codec.name + ">"; }
return new ReadonlyType(name, codec.is, codec.validate, codec.encode, codec);
};
}
exports.readonly = readonly;
/**

@@ -1197,21 +1409,88 @@ * @since 1.0.0

/**
* @category Combinators
* @category combinators
* @since 1.0.0
*/
exports.readonlyArray = function (item, name) {
function readonlyArray(item, name) {
if (name === void 0) { name = "ReadonlyArray<" + item.name + ">"; }
var codec = exports.array(item);
var codec = array(item);
return new ReadonlyArrayType(name, codec.is, codec.validate, codec.encode, item);
};
}
exports.readonlyArray = readonlyArray;
/**
* Strips additional properties
* Strips additional properties, equivalent to `exact(type(props))`.
*
* @category Combinators
* @category combinators
* @since 1.0.0
*/
exports.strict = function (props, name) {
return exports.exact(exports.type(props), name);
};
var strict = function (props, name) { return exact(type(props), name); };
exports.strict = strict;
/**
* @category deprecated
* @since 1.1.0
*/
var ExactType = /** @class */ (function (_super) {
__extends(ExactType, _super);
function ExactType(name, is, validate, encode, type) {
var _this = _super.call(this, name, is, validate, encode) || this;
_this.type = type;
/**
* @since 1.0.0
*/
_this._tag = 'ExactType';
return _this;
}
return ExactType;
}(Type));
exports.ExactType = ExactType;
/**
* Strips additional properties.
*
* @category combinators
* @since 1.1.0
*/
function exact(codec, name) {
if (name === void 0) { name = getExactTypeName(codec); }
var props = getProps(codec);
return new ExactType(name, codec.is, function (u, c) {
var e = exports.UnknownRecord.validate(u, c);
if (Either_1.isLeft(e)) {
return e;
}
var ce = codec.validate(u, c);
if (Either_1.isLeft(ce)) {
return ce;
}
return Either_1.right(stripKeys(ce.right, props));
}, function (a) { return codec.encode(stripKeys(a, props)); }, codec);
}
exports.exact = exact;
// -------------------------------------------------------------------------------------
// deprecated
// -------------------------------------------------------------------------------------
/**
* @since 1.0.0
* @deprecated
*/
var FunctionType = /** @class */ (function (_super) {
__extends(FunctionType, _super);
function FunctionType() {
var _this = _super.call(this, 'Function',
// tslint:disable-next-line:strict-type-predicates
function (u) { return typeof u === 'function'; }, function (u, c) { return (_this.is(u) ? exports.success(u) : exports.failure(u, c)); }, exports.identity) || this;
/**
* @since 1.0.0
*/
_this._tag = 'FunctionType';
return _this;
}
return FunctionType;
}(Type));
exports.FunctionType = FunctionType;
/**
* @category primitives
* @since 1.0.0
* @deprecated
*/
// tslint:disable-next-line: deprecation
exports.Function = new FunctionType();
/**
* @since 1.3.0

@@ -1238,13 +1517,13 @@ * @deprecated

/**
* Use `union` instead
* Use `union` instead.
*
* @category deprecated
* @category combinators
* @since 1.3.0
* @deprecated
*/
exports.taggedUnion = function (tag, codecs, name
var taggedUnion = function (tag, codecs, name
// tslint:disable-next-line: deprecation
) {
if (name === void 0) { name = getUnionName(codecs); }
var U = exports.union(codecs, name);
var U = union(codecs, name);
// tslint:disable-next-line: deprecation

@@ -1260,94 +1539,21 @@ if (U instanceof TaggedUnionType) {

};
exports.taggedUnion = taggedUnion;
/**
* @since 1.1.0
*/
var ExactType = /** @class */ (function (_super) {
__extends(ExactType, _super);
function ExactType(name, is, validate, encode, type) {
var _this = _super.call(this, name, is, validate, encode) || this;
_this.type = type;
/**
* @since 1.0.0
*/
_this._tag = 'ExactType';
return _this;
}
return ExactType;
}(Type));
exports.ExactType = ExactType;
var getProps = function (codec) {
switch (codec._tag) {
case 'RefinementType':
case 'ReadonlyType':
return getProps(codec.type);
case 'InterfaceType':
case 'StrictType':
case 'PartialType':
return codec.props;
case 'IntersectionType':
return codec.types.reduce(function (props, type) { return Object.assign(props, getProps(type)); }, {});
}
};
var stripKeys = function (o, props) {
var keys = Object.getOwnPropertyNames(o);
var shouldStrip = false;
var r = {};
for (var i = 0; i < keys.length; i++) {
var key = keys[i];
if (!hasOwnProperty.call(props, key)) {
shouldStrip = true;
}
else {
r[key] = o[key];
}
}
return shouldStrip ? r : o;
};
var getExactTypeName = function (codec) {
if (isTypeC(codec)) {
return "{| " + getNameFromProps(codec.props) + " |}";
}
else if (isPartialC(codec)) {
return getPartialTypeName("{| " + getNameFromProps(codec.props) + " |}");
}
return "Exact<" + codec.name + ">";
};
/**
* Strips additional properties
* @since 1.1.0
*/
exports.exact = function (codec, name) {
if (name === void 0) { name = getExactTypeName(codec); }
var props = getProps(codec);
return new ExactType(name, codec.is, function (u, c) {
var e = exports.UnknownRecord.validate(u, c);
if (Either_1.isLeft(e)) {
return e;
}
var ce = codec.validate(u, c);
if (Either_1.isLeft(ce)) {
return ce;
}
return Either_1.right(stripKeys(ce.right, props));
}, function (a) { return codec.encode(stripKeys(a, props)); }, codec);
};
/**
* @category deprecated
* @since 1.0.0
* @deprecated
*/
exports.getValidationError /* istanbul ignore next */ = function (value, context) { return ({
var getValidationError /* istanbul ignore next */ = function (value, context) { return ({
value: value,
context: context
}); };
exports.getValidationError /* istanbul ignore next */ = getValidationError;
/**
* @category deprecated
* @since 1.0.0
* @deprecated
*/
exports.getDefaultContext /* istanbul ignore next */ = function (decoder) { return [
var getDefaultContext /* istanbul ignore next */ = function (decoder) { return [
{ key: '', type: decoder }
]; };
exports.getDefaultContext /* istanbul ignore next */ = getDefaultContext;
/**
* @category deprecated
* @since 1.0.0

@@ -1374,3 +1580,3 @@ * @deprecated

/**
* @category deprecated
* @category primitives
* @since 1.0.0

@@ -1382,3 +1588,2 @@ * @deprecated

/**
* @category deprecated
* @since 1.0.0

@@ -1401,5 +1606,5 @@ * @deprecated

/**
* Use `unknown` instead
* Use `unknown` instead.
*
* @category deprecated
* @category primitives
* @since 1.0.0

@@ -1411,5 +1616,5 @@ * @deprecated

/**
* Use `UnknownRecord` instead
* Use `UnknownRecord` instead.
*
* @category deprecated
* @category primitives
* @since 1.0.0

@@ -1420,3 +1625,2 @@ * @deprecated

/**
* @category deprecated
* @since 1.0.0

@@ -1439,5 +1643,5 @@ * @deprecated

/**
* Use `UnknownRecord` instead
* Use `UnknownRecord` instead.
*
* @category deprecated
* @category primitives
* @since 1.0.0

@@ -1449,5 +1653,5 @@ * @deprecated

/**
* Use `brand` instead
* Use `brand` instead.
*
* @category deprecated
* @category combinators
* @since 1.0.0

@@ -1457,3 +1661,3 @@ * @deprecated

function refinement(codec, predicate, name) {
if (name === void 0) { name = "(" + codec.name + " | " + exports.getFunctionName(predicate) + ")"; }
if (name === void 0) { name = "(" + codec.name + " | " + getFunctionName(predicate) + ")"; }
return new RefinementType(name, function (u) { return codec.is(u) && predicate(u); }, function (i, c) {

@@ -1470,5 +1674,5 @@ var e = codec.validate(i, c);

/**
* Use `Int` instead
* Use `Int` instead.
*
* @category deprecated
* @category primitives
* @since 1.0.0

@@ -1480,5 +1684,5 @@ * @deprecated

/**
* Use `record` instead
* Use `record` instead.
*
* @category deprecated
* @category combinators
* @since 1.0.0

@@ -1489,3 +1693,2 @@ * @deprecated

/**
* @category deprecated
* @since 1.0.0

@@ -1515,5 +1718,5 @@ * @deprecated

/**
* Drops the codec "kind"
* Drops the codec "kind".
*
* @category deprecated
* @category combinators
* @since 1.1.0

@@ -1530,177 +1733,1 @@ * @deprecated

exports.alias = alias;
var isNonEmpty = function (as) { return as.length > 0; };
/**
* @internal
*/
exports.emptyTags = {};
function intersect(a, b) {
var r = [];
for (var _i = 0, a_1 = a; _i < a_1.length; _i++) {
var v = a_1[_i];
if (b.indexOf(v) !== -1) {
r.push(v);
}
}
return r;
}
function mergeTags(a, b) {
if (a === exports.emptyTags) {
return b;
}
if (b === exports.emptyTags) {
return a;
}
var r = Object.assign({}, a);
for (var k in b) {
if (a.hasOwnProperty(k)) {
var intersection_1 = intersect(a[k], b[k]);
if (isNonEmpty(intersection_1)) {
r[k] = intersection_1;
}
else {
r = exports.emptyTags;
break;
}
}
else {
r[k] = b[k];
}
}
return r;
}
function intersectTags(a, b) {
if (a === exports.emptyTags || b === exports.emptyTags) {
return exports.emptyTags;
}
var r = exports.emptyTags;
for (var k in a) {
if (b.hasOwnProperty(k)) {
var intersection_2 = intersect(a[k], b[k]);
if (intersection_2.length === 0) {
if (r === exports.emptyTags) {
r = {};
}
r[k] = a[k].concat(b[k]);
}
}
}
return r;
}
// tslint:disable-next-line: deprecation
function isAnyC(codec) {
return codec._tag === 'AnyType';
}
function isLiteralC(codec) {
return codec._tag === 'LiteralType';
}
function isKeyofC(codec) {
return codec._tag === 'KeyofType';
}
function isTypeC(codec) {
return codec._tag === 'InterfaceType';
}
function isPartialC(codec) {
return codec._tag === 'PartialType';
}
// tslint:disable-next-line: deprecation
function isStrictC(codec) {
return codec._tag === 'StrictType';
}
function isExactC(codec) {
return codec._tag === 'ExactType';
}
// tslint:disable-next-line: deprecation
function isRefinementC(codec) {
return codec._tag === 'RefinementType';
}
function isIntersectionC(codec) {
return codec._tag === 'IntersectionType';
}
function isUnionC(codec) {
return codec._tag === 'UnionType';
}
function isRecursiveC(codec) {
return codec._tag === 'RecursiveType';
}
var lazyCodecs = [];
/**
* @internal
*/
function getTags(codec) {
if (lazyCodecs.indexOf(codec) !== -1) {
return exports.emptyTags;
}
if (isTypeC(codec) || isStrictC(codec)) {
var index = exports.emptyTags;
// tslint:disable-next-line: forin
for (var k in codec.props) {
var prop = codec.props[k];
if (isLiteralC(prop)) {
if (index === exports.emptyTags) {
index = {};
}
index[k] = [prop.value];
}
}
return index;
}
else if (isExactC(codec) || isRefinementC(codec)) {
return getTags(codec.type);
}
else if (isIntersectionC(codec)) {
return codec.types.reduce(function (tags, codec) { return mergeTags(tags, getTags(codec)); }, exports.emptyTags);
}
else if (isUnionC(codec)) {
return codec.types.slice(1).reduce(function (tags, codec) { return intersectTags(tags, getTags(codec)); }, getTags(codec.types[0]));
}
else if (isRecursiveC(codec)) {
lazyCodecs.push(codec);
var tags = getTags(codec.type);
lazyCodecs.pop();
return tags;
}
return exports.emptyTags;
}
exports.getTags = getTags;
/**
* @internal
*/
function getIndex(codecs) {
var tags = getTags(codecs[0]);
var keys = Object.keys(tags);
var len = codecs.length;
var _loop_1 = function (k) {
var all = tags[k].slice();
var index = [tags[k]];
for (var i = 1; i < len; i++) {
var codec = codecs[i];
var ctags = getTags(codec);
var values = ctags[k];
// tslint:disable-next-line: strict-type-predicates
if (values === undefined) {
return "continue-keys";
}
else {
if (values.some(function (v) { return all.indexOf(v) !== -1; })) {
return "continue-keys";
}
else {
all.push.apply(all, values);
index.push(values);
}
}
}
return { value: [k, index] };
};
keys: for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) {
var k = keys_1[_i];
var state_1 = _loop_1(k);
if (typeof state_1 === "object")
return state_1.value;
switch (state_1) {
case "continue-keys": continue keys;
}
}
return undefined;
}
exports.getIndex = getIndex;

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

*/
import { Refinement } from 'fp-ts/lib/function'
import { HKT, Kind, Kind2, URIS, URIS2 } from 'fp-ts/lib/HKT'

@@ -221,3 +222,3 @@ /**

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>
readonly refine: <A, B extends A>(refinement: Refinement<A, B>, id: string) => (from: HKT<S, A>) => HKT<S, B>
}

@@ -228,3 +229,3 @@ /**

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>
readonly refine: <A, B extends A>(refinement: Refinement<A, B>, id: string) => (from: Kind<S, A>) => Kind<S, B>
}

@@ -236,3 +237,3 @@ /**

readonly refine: <A, B extends A>(
refinement: (a: A) => a is B,
refinement: Refinement<A, B>,
id: string

@@ -239,0 +240,0 @@ ) => (from: Kind2<S, E, A>) => Kind2<S, E, B>

@@ -26,3 +26,3 @@ "use strict";

*/
exports.intersect_ = function (a, b) {
var intersect_ = function (a, b) {
if (a !== undefined && b !== undefined) {

@@ -37,1 +37,2 @@ var tx = typeOf(a);

};
exports.intersect_ = intersect_;

@@ -119,3 +119,3 @@ /**

export declare const refine: <A, B extends A>(
refinement: (a: A) => a is B,
refinement: Refinement<A, B>,
id: string

@@ -122,0 +122,0 @@ ) => <I>(from: TaskDecoder<I, A>) => TaskDecoder<I, B>

@@ -68,5 +68,6 @@ "use strict";

*/
exports.failure = function (actual, message) {
var failure = function (actual, message) {
return TE.left(D.error(actual, message));
};
exports.failure = failure;
// -------------------------------------------------------------------------------------

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

*/
exports.fromDecoder = function (decoder) { return ({
var fromDecoder = function (decoder) { return ({
decode: TE.fromEitherK(decoder.decode)
}); };
exports.fromDecoder = fromDecoder;
/**

@@ -87,5 +89,6 @@ * @category constructors

*/
exports.fromRefinement = function (refinement, expected) {
var fromRefinement = function (refinement, expected) {
return exports.fromDecoder(D.fromRefinement(refinement, expected));
};
exports.fromRefinement = fromRefinement;
/**

@@ -95,5 +98,6 @@ * @category constructors

*/
exports.fromGuard = function (guard, expected) {
var fromGuard = function (guard, expected) {
return exports.fromRefinement(guard.is, expected);
};
exports.fromGuard = fromGuard;
/**

@@ -158,5 +162,6 @@ * @category constructors

*/
exports.withMessage = function (message) {
var withMessage = function (message) {
return exports.mapLeftWithInput(function (input, e) { return FS.of(DE.wrap(message(input, e), e)); });
};
exports.withMessage = withMessage;
/**

@@ -166,3 +171,4 @@ * @category combinators

*/
exports.refine = function (refinement, id) { return K.refine(M)(refinement, function (a) { return exports.error(a, id); }); };
var refine = function (refinement, id) { return K.refine(M)(refinement, function (a) { return exports.error(a, id); }); };
exports.refine = refine;
/**

@@ -186,5 +192,6 @@ * @category combinators

*/
exports.fromType = function (properties) {
var fromType = function (properties) {
return K.fromType(M)(function (k, e) { return FS.of(DE.key(k, DE.required, e)); })(properties);
};
exports.fromType = fromType;
/**

@@ -194,3 +201,4 @@ * @category combinators

*/
exports.type = function (properties) { return pipeable_1.pipe(exports.UnknownRecord, exports.compose(exports.fromType(properties))); };
var type = function (properties) { return pipeable_1.pipe(exports.UnknownRecord, exports.compose(exports.fromType(properties))); };
exports.type = type;
/**

@@ -200,5 +208,6 @@ * @category combinators

*/
exports.fromPartial = function (properties) {
var fromPartial = function (properties) {
return K.fromPartial(M)(function (k, e) { return FS.of(DE.key(k, DE.optional, e)); })(properties);
};
exports.fromPartial = fromPartial;
/**

@@ -208,5 +217,6 @@ * @category combinators

*/
exports.partial = function (properties) {
var partial = function (properties) {
return pipeable_1.pipe(exports.UnknownRecord, exports.compose(exports.fromPartial(properties)));
};
exports.partial = partial;
/**

@@ -216,5 +226,6 @@ * @category combinators

*/
exports.fromArray = function (item) {
var fromArray = function (item) {
return K.fromArray(M)(function (i, e) { return FS.of(DE.index(i, DE.optional, e)); })(item);
};
exports.fromArray = fromArray;
/**

@@ -224,5 +235,6 @@ * @category combinators

*/
exports.array = function (item) {
var array = function (item) {
return pipeable_1.pipe(exports.UnknownArray, exports.compose(exports.fromArray(item)));
};
exports.array = array;
/**

@@ -232,5 +244,6 @@ * @category combinators

*/
exports.fromRecord = function (codomain) {
var fromRecord = function (codomain) {
return K.fromRecord(M)(function (k, e) { return FS.of(DE.key(k, DE.optional, e)); })(codomain);
};
exports.fromRecord = fromRecord;
/**

@@ -240,5 +253,6 @@ * @category combinators

*/
exports.record = function (codomain) {
var record = function (codomain) {
return pipeable_1.pipe(exports.UnknownRecord, exports.compose(exports.fromRecord(codomain)));
};
exports.record = record;
/**

@@ -248,3 +262,3 @@ * @category combinators

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

@@ -256,2 +270,3 @@ for (var _i = 0; _i < arguments.length; _i++) {

};
exports.fromTuple = fromTuple;
/**

@@ -261,3 +276,3 @@ * @category combinators

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

@@ -269,2 +284,3 @@ for (var _i = 0; _i < arguments.length; _i++) {

};
exports.tuple = tuple;
/**

@@ -288,3 +304,3 @@ * @category combinators

*/
exports.fromSum = function (tag) { return function (members) {
var fromSum = function (tag) { return function (members) {
return K.fromSum(M)(function (tag, value, keys) {

@@ -294,2 +310,3 @@ return FS.of(DE.key(tag, DE.required, exports.error(value, keys.length === 0 ? 'never' : keys.map(function (k) { return JSON.stringify(k); }).join(' | '))));

}; };
exports.fromSum = fromSum;
/**

@@ -299,3 +316,4 @@ * @category combinators

*/
exports.sum = function (tag) { return function (members) { return pipeable_1.pipe(exports.UnknownRecord, exports.compose(exports.fromSum(tag)(members))); }; };
var sum = function (tag) { return function (members) { return pipeable_1.pipe(exports.UnknownRecord, exports.compose(exports.fromSum(tag)(members))); }; };
exports.sum = sum;
/**

@@ -302,0 +320,0 @@ * @category combinators

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

import { Refinement } from 'fp-ts/lib/function'
import * as t from './index'

@@ -42,3 +43,3 @@ import * as S from './Schemable'

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

@@ -45,0 +46,0 @@ * @category combinators

@@ -43,3 +43,3 @@ "use strict";

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

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

};
exports.literal = literal;
// -------------------------------------------------------------------------------------

@@ -89,6 +90,7 @@ // primitives

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

@@ -98,3 +100,4 @@ * @category combinators

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

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

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

@@ -112,5 +116,6 @@ * @category combinators

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

@@ -120,3 +125,4 @@ * @category combinators

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

@@ -126,3 +132,4 @@ * @category combinators

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

@@ -132,3 +139,3 @@ * @category combinators

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

@@ -140,2 +147,3 @@ for (var _i = 0; _i < arguments.length; _i++) {

};
exports.tuple = tuple;
/**

@@ -145,3 +153,4 @@ * @category combinators

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

@@ -151,3 +160,4 @@ * @category combinators

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

@@ -157,3 +167,4 @@ * @category combinators

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

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

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

@@ -171,2 +182,3 @@ for (var _i = 0; _i < arguments.length; _i++) {

};
exports.union = union;
// -------------------------------------------------------------------------------------

@@ -173,0 +185,0 @@ // instances

{
"name": "io-ts",
"version": "2.2.13",
"version": "2.2.14",
"description": "TypeScript runtime type system for IO decoding/encoding",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

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