Comparing version 1.4.2 to 1.5.0
@@ -12,2 +12,3 @@ # Changelog | ||
> - [Experimental] | ||
> - [Deprecation] | ||
@@ -17,2 +18,9 @@ **Note**: Gaps between patch versions are faulty/broken releases. **Note**: A feature tagged as Experimental is in a | ||
# 1.5.0 | ||
- **New Feature** | ||
- add `UnknownType`, closes #238 (@gcanti) | ||
- **Deprecation** | ||
- `ThrowReporter` is now deprecated (@gcanti) | ||
# 1.4.2 | ||
@@ -19,0 +27,0 @@ |
@@ -8,3 +8,9 @@ import { Either } from 'fp-ts/lib/Either'; | ||
} | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare type mixed = unknown; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export interface ContextEntry { | ||
@@ -14,4 +20,10 @@ readonly key: string; | ||
} | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export interface Context extends ReadonlyArray<ContextEntry> { | ||
} | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export interface ValidationError { | ||
@@ -21,16 +33,52 @@ readonly value: mixed; | ||
} | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export interface Errors extends Array<ValidationError> { | ||
} | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare type Validation<A> = Either<Errors, A>; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare type Is<A> = (m: mixed) => m is A; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare type Validate<I, A> = (i: I, context: Context) => Validation<A>; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare type Decode<I, A> = (i: I) => Validation<A>; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare type Encode<A, O> = (a: A) => O; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export interface Any extends Type<any, any, any> { | ||
} | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export interface Mixed extends Type<any, any, mixed> { | ||
} | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare type TypeOf<RT extends Any> = RT['_A']; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare type InputOf<RT extends Any> = RT['_I']; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare type OutputOf<RT extends Any> = RT['_O']; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export interface Decoder<I, A> { | ||
@@ -41,5 +89,11 @@ readonly name: string; | ||
} | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export interface Encoder<A, O> { | ||
readonly encode: Encode<A, O>; | ||
} | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare class Type<A, O = A, I = mixed> implements Decoder<I, A>, Encoder<A, O> { | ||
@@ -72,11 +126,41 @@ /** a unique name for this runtime type */ | ||
} | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare const identity: <A>(a: A) => A; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare const getFunctionName: (f: Function) => string; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare const getContextEntry: (key: string, type: Decoder<any, any>) => ContextEntry; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare const getValidationError: (value: unknown, context: Context) => ValidationError; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare const getDefaultContext: (type: Decoder<any, any>) => Context; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare const appendContext: (c: Context, key: string, type: Decoder<any, any>) => Context; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare const failures: <T>(errors: Errors) => Either<Errors, T>; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare const failure: <T>(value: unknown, context: Context) => Either<Errors, T>; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare const success: <T>(value: T) => Either<Errors, T>; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare class NullType extends Type<null> { | ||
@@ -86,4 +170,10 @@ readonly _tag: 'NullType'; | ||
} | ||
/** @alias `null` */ | ||
/** | ||
* @alias `null` | ||
* @since 1.0.0 | ||
*/ | ||
export declare const nullType: NullType; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare class UndefinedType extends Type<undefined> { | ||
@@ -94,2 +184,5 @@ readonly _tag: 'UndefinedType'; | ||
declare const undefinedType: UndefinedType; | ||
/** | ||
* @since 1.2.0 | ||
*/ | ||
export declare class VoidType extends Type<void> { | ||
@@ -99,4 +192,10 @@ readonly _tag: 'VoidType'; | ||
} | ||
/** @alias `void` */ | ||
/** | ||
* @alias `void` | ||
* @since 1.2.0 | ||
*/ | ||
export declare const voidType: VoidType; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare class AnyType extends Type<any> { | ||
@@ -106,3 +205,20 @@ readonly _tag: 'AnyType'; | ||
} | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare const any: AnyType; | ||
/** | ||
* @since 1.5.0 | ||
*/ | ||
export declare class UnknownType extends Type<unknown> { | ||
readonly _tag: 'UnknownType'; | ||
constructor(); | ||
} | ||
/** | ||
* @since 1.5.0 | ||
*/ | ||
export declare const unknown: UnknownType; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare class NeverType extends Type<never> { | ||
@@ -112,3 +228,9 @@ readonly _tag: 'NeverType'; | ||
} | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare const never: NeverType; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare class StringType extends Type<string> { | ||
@@ -118,3 +240,9 @@ readonly _tag: 'StringType'; | ||
} | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare const string: StringType; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare class NumberType extends Type<number> { | ||
@@ -124,3 +252,9 @@ readonly _tag: 'NumberType'; | ||
} | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare const number: NumberType; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare class BooleanType extends Type<boolean> { | ||
@@ -130,3 +264,9 @@ readonly _tag: 'BooleanType'; | ||
} | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare const boolean: BooleanType; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare class AnyArrayType extends Type<Array<mixed>> { | ||
@@ -137,2 +277,5 @@ readonly _tag: 'AnyArrayType'; | ||
declare const arrayType: AnyArrayType; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare class AnyDictionaryType extends Type<{ | ||
@@ -144,3 +287,9 @@ [key: string]: mixed; | ||
} | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare const Dictionary: AnyDictionaryType; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare class ObjectType extends Type<object> { | ||
@@ -150,3 +299,9 @@ readonly _tag: 'ObjectType'; | ||
} | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare const object: ObjectType; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare class FunctionType extends Type<Function> { | ||
@@ -156,3 +311,9 @@ readonly _tag: 'FunctionType'; | ||
} | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare const Function: FunctionType; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare class RefinementType<RT extends Any, A = any, O = A, I = mixed> extends Type<A, O, I> { | ||
@@ -164,4 +325,13 @@ readonly type: RT; | ||
} | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare const refinement: <RT extends Any>(type: RT, predicate: Predicate<RT["_A"]>, name?: string) => RefinementType<RT, RT["_A"], RT["_O"], RT["_I"]>; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare const Integer: RefinementType<NumberType, number, number, unknown>; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare class LiteralType<V extends string | number | boolean> extends Type<V> { | ||
@@ -172,3 +342,9 @@ readonly value: V; | ||
} | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare const literal: <V extends string | number | boolean>(value: V, name?: string) => LiteralType<V>; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare class KeyofType<D extends { | ||
@@ -181,5 +357,11 @@ [key: string]: mixed; | ||
} | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare const keyof: <D extends { | ||
[key: string]: unknown; | ||
}>(keys: D, name?: string) => KeyofType<D>; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare class RecursiveType<RT extends Any, A = any, O = A, I = mixed> extends Type<A, O, I> { | ||
@@ -191,3 +373,9 @@ private runDefinition; | ||
} | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare const recursion: <A, O = A, I = unknown, RT extends Type<A, O, I> = Type<A, O, I>>(name: string, definition: (self: RT) => RT) => RecursiveType<RT, A, O, I>; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare class ArrayType<RT extends Any, A = any, O = A, I = mixed> extends Type<A, O, I> { | ||
@@ -198,3 +386,9 @@ readonly type: RT; | ||
} | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare const array: <RT extends Mixed>(type: RT, name?: string) => ArrayType<RT, RT["_A"][], RT["_O"][], unknown>; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare class InterfaceType<P, A = any, O = A, I = mixed> extends Type<A, O, I> { | ||
@@ -205,16 +399,34 @@ readonly props: P; | ||
} | ||
/** | ||
* @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; | ||
} | ||
/** @alias `interface` */ | ||
/** | ||
* @alias `interface` | ||
* @since 1.0.0 | ||
*/ | ||
export declare const type: <P extends Props>(props: P, name?: string) => InterfaceType<P, TypeOfProps<P>, OutputOfProps<P>, unknown>; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare class PartialType<P, A = any, O = A, I = mixed> extends Type<A, O, I> { | ||
@@ -225,9 +437,21 @@ readonly props: P; | ||
} | ||
/** | ||
* @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 const partial: <P extends Props>(props: P, name?: string) => PartialType<P, TypeOfPartialProps<P>, OutputOfPartialProps<P>, unknown>; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare class DictionaryType<D extends Any, C extends Any, A = any, O = A, I = mixed> extends Type<A, O, I> { | ||
@@ -239,9 +463,21 @@ readonly domain: D; | ||
} | ||
/** | ||
* @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.0.0 | ||
*/ | ||
export declare const dictionary: <D extends Mixed, C extends Mixed>(domain: D, codomain: C, name?: string) => DictionaryType<D, C, TypeOfDictionary<D, C>, OutputOfDictionary<D, C>, unknown>; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare class UnionType<RTS extends Array<Any>, A = any, O = A, I = mixed> extends Type<A, O, I> { | ||
@@ -252,3 +488,9 @@ readonly types: RTS; | ||
} | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare const union: <RTS extends Mixed[]>(types: RTS, name?: string) => UnionType<RTS, RTS["_A"]["_A"], RTS["_A"]["_O"], unknown>; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare class IntersectionType<RTS extends Array<Any>, A = any, O = A, I = mixed> extends Type<A, O, I> { | ||
@@ -259,5 +501,12 @@ readonly types: RTS; | ||
} | ||
/** | ||
* used in `intersection` as a workaround for #234 | ||
* @since 1.4.2 | ||
*/ | ||
export declare type Compact<A> = { | ||
[K in keyof A]: A[K]; | ||
}; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare function intersection<A extends Mixed, B extends Mixed, C extends Mixed, D extends Mixed, E extends Mixed>(types: [A, B, C, D, E], name?: string): IntersectionType<[A, B, C, D, E], Compact<TypeOf<A> & TypeOf<B> & TypeOf<C> & TypeOf<D> & TypeOf<E>>, Compact<OutputOf<A> & OutputOf<B> & OutputOf<C> & OutputOf<D> & OutputOf<E>>, mixed>; | ||
@@ -268,2 +517,5 @@ export declare function intersection<A extends Mixed, B extends Mixed, C extends Mixed, D extends Mixed>(types: [A, B, C, D], name?: string): IntersectionType<[A, B, C, D], Compact<TypeOf<A> & TypeOf<B> & TypeOf<C> & TypeOf<D>>, Compact<OutputOf<A> & OutputOf<B> & OutputOf<C> & OutputOf<D>>, mixed>; | ||
export declare function intersection<A extends Mixed>(types: [A], name?: string): IntersectionType<[A], TypeOf<A>, OutputOf<A>, mixed>; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare class TupleType<RTS extends Array<Any>, A = any, O = A, I = mixed> extends Type<A, O, I> { | ||
@@ -274,2 +526,5 @@ readonly types: RTS; | ||
} | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare function tuple<A extends Mixed, B extends Mixed, C extends Mixed, D extends Mixed, E extends Mixed>(types: [A, B, C, D, E], name?: string): TupleType<[A, B, C, D, E], [TypeOf<A>, TypeOf<B>, TypeOf<C>, TypeOf<D>, TypeOf<E>], [OutputOf<A>, OutputOf<B>, OutputOf<C>, OutputOf<D>, OutputOf<E>], mixed>; | ||
@@ -280,2 +535,5 @@ export declare function tuple<A extends Mixed, B extends Mixed, C extends Mixed, D extends Mixed>(types: [A, B, C, D], name?: string): TupleType<[A, B, C, D], [TypeOf<A>, TypeOf<B>, TypeOf<C>, TypeOf<D>], [OutputOf<A>, OutputOf<B>, OutputOf<C>, OutputOf<D>], mixed>; | ||
export declare function tuple<A extends Mixed>(types: [A], name?: string): TupleType<[A], [TypeOf<A>], [OutputOf<A>], mixed>; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare class ReadonlyType<RT extends Any, A = any, O = A, I = mixed> extends Type<A, O, I> { | ||
@@ -286,3 +544,9 @@ readonly type: RT; | ||
} | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare const readonly: <RT extends Mixed>(type: RT, name?: string) => ReadonlyType<RT, Readonly<RT["_A"]>, Readonly<RT["_O"]>, unknown>; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare class ReadonlyArrayType<RT extends Any, A = any, O = A, I = mixed> extends Type<A, O, I> { | ||
@@ -293,3 +557,9 @@ readonly type: RT; | ||
} | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare const readonlyArray: <RT extends Mixed>(type: RT, name?: string) => ReadonlyArrayType<RT, ReadonlyArray<RT["_A"]>, ReadonlyArray<RT["_O"]>, unknown>; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare class StrictType<P, A = any, O = A, I = mixed> extends Type<A, O, I> { | ||
@@ -303,19 +573,50 @@ readonly props: P; | ||
* @deprecated use `exact` instead | ||
* @since 1.0.0 | ||
*/ | ||
export declare const strict: <P extends Props>(props: P, name?: string) => StrictType<P, TypeOfProps<P>, OutputOfProps<P>, unknown>; | ||
/** | ||
* @since 1.3.0 | ||
*/ | ||
export declare type TaggedProps<Tag extends string> = { | ||
[K in Tag]: LiteralType<any>; | ||
}; | ||
/** | ||
* @since 1.3.0 | ||
*/ | ||
export interface TaggedRefinement<Tag extends string, A, O = A> extends RefinementType<Tagged<Tag>, A, O> { | ||
} | ||
/** | ||
* @since 1.3.0 | ||
*/ | ||
export interface TaggedUnion<Tag extends string, A, O = A> extends UnionType<Array<Tagged<Tag>>, A, O> { | ||
} | ||
/** | ||
* @since 1.3.0 | ||
*/ | ||
export declare type TaggedIntersectionArgument<Tag extends string> = [Tagged<Tag>] | [Tagged<Tag>, Mixed] | [Mixed, Tagged<Tag>] | [Tagged<Tag>, Mixed, Mixed] | [Mixed, Tagged<Tag>, Mixed] | [Mixed, Mixed, Tagged<Tag>] | [Tagged<Tag>, Mixed, Mixed, Mixed] | [Mixed, Tagged<Tag>, Mixed, Mixed] | [Mixed, Mixed, Tagged<Tag>, Mixed] | [Mixed, Mixed, Mixed, Tagged<Tag>] | [Tagged<Tag>, Mixed, Mixed, Mixed, Mixed] | [Mixed, Tagged<Tag>, Mixed, Mixed, Mixed] | [Mixed, Mixed, Tagged<Tag>, Mixed, Mixed] | [Mixed, Mixed, Mixed, Tagged<Tag>, Mixed] | [Mixed, Mixed, Mixed, Mixed, Tagged<Tag>]; | ||
/** | ||
* @since 1.3.0 | ||
*/ | ||
export interface TaggedIntersection<Tag extends string, A, O = A> extends IntersectionType<TaggedIntersectionArgument<Tag>, A, O> { | ||
} | ||
/** | ||
* @since 1.3.0 | ||
*/ | ||
export interface TaggedExact<Tag extends string, A, O = A> extends ExactType<Tagged<Tag>, A, O> { | ||
} | ||
/** | ||
* @since 1.3.0 | ||
*/ | ||
export declare type Tagged<Tag extends string, A = any, O = A> = InterfaceType<TaggedProps<Tag>, A, O> | StrictType<TaggedProps<Tag>, A, O> | TaggedRefinement<Tag, A, O> | TaggedUnion<Tag, A, O> | TaggedIntersection<Tag, A, O> | TaggedExact<Tag, A, O> | RecursiveType<any, A, O>; | ||
/** | ||
* @since 1.3.0 | ||
*/ | ||
export declare const isTagged: <Tag extends string>(tag: Tag) => (type: Mixed) => type is Tagged<Tag, any, any>; | ||
/** | ||
* @since 1.3.0 | ||
*/ | ||
export declare const getTagValue: <Tag extends string>(tag: Tag) => (type: Tagged<Tag, any, any>) => string | number | boolean; | ||
/** | ||
* @since 1.3.0 | ||
*/ | ||
export declare class TaggedUnionType<Tag extends string, RTS extends Array<Tagged<Tag>>, A = any, O = A, I = mixed> extends UnionType<RTS, A, O, I> { | ||
@@ -325,3 +626,9 @@ readonly tag: Tag; | ||
} | ||
/** | ||
* @since 1.3.0 | ||
*/ | ||
export declare const taggedUnion: <Tag extends string, RTS extends Tagged<Tag, any, any>[]>(tag: Tag, types: RTS, name?: string) => TaggedUnionType<Tag, RTS, RTS["_A"]["_A"], RTS["_A"]["_O"], unknown>; | ||
/** | ||
* @since 1.1.0 | ||
*/ | ||
export declare class ExactType<RT extends Any, A = any, O = A, I = mixed> extends Type<A, O, I> { | ||
@@ -332,15 +639,39 @@ readonly type: RT; | ||
} | ||
/** | ||
* @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.1.0 | ||
*/ | ||
export declare function exact<RT extends HasProps>(type: RT, name?: string): ExactType<RT, TypeOf<RT>, OutputOf<RT>, InputOf<RT>>; | ||
/** Drops the runtime type "kind" */ | ||
/** | ||
* Drops the runtime type "kind" | ||
* @since 1.1.0 | ||
*/ | ||
export declare function clean<A, O = A, I = mixed>(type: Type<A, O, I>): Type<A, O, I>; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare type PropsOf<T extends { | ||
props: any; | ||
}> = T['props']; | ||
/** | ||
* @since 1.1.0 | ||
*/ | ||
export declare type Exact<T, X extends T> = T & { | ||
@@ -355,3 +686,6 @@ [K in ({ | ||
}; | ||
/** Keeps the runtime type "kind" */ | ||
/** | ||
* Keeps the runtime type "kind" | ||
* @since 1.1.0 | ||
*/ | ||
export declare function alias<A, O, P, I>(type: PartialType<P, A, O, I>): <AA extends Exact<A, AA>, OO extends Exact<O, OO> = O, PP extends Exact<P, PP> = P, II extends I = I>() => PartialType<PP, AA, OO, II>; | ||
@@ -358,0 +692,0 @@ export declare function alias<A, O, P, I>(type: StrictType<P, A, O, I>): <AA extends Exact<A, AA>, OO extends Exact<O, OO> = O, PP extends Exact<P, PP> = P, II extends I = I>() => StrictType<PP, AA, OO, II>; |
268
lib/index.js
@@ -8,3 +8,3 @@ "use strict"; | ||
return extendStatics(d, b); | ||
} | ||
}; | ||
return function (d, b) { | ||
@@ -29,2 +29,5 @@ extendStatics(d, b); | ||
var Either_1 = require("fp-ts/lib/Either"); | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
var Type = /** @class */ (function () { | ||
@@ -71,9 +74,27 @@ function Type( | ||
exports.Type = Type; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
exports.identity = function (a) { return a; }; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
exports.getFunctionName = function (f) { | ||
return f.displayName || f.name || "<function" + f.length + ">"; | ||
}; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
exports.getContextEntry = function (key, type) { return ({ key: key, type: type }); }; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
exports.getValidationError = function (value, context) { return ({ value: value, context: context }); }; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
exports.getDefaultContext = function (type) { return [{ key: '', type: type }]; }; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
exports.appendContext = function (c, key, type) { | ||
@@ -88,6 +109,15 @@ var len = c.length; | ||
}; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
exports.failures = function (errors) { return new Either_1.Left(errors); }; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
exports.failure = function (value, context) { | ||
return exports.failures([exports.getValidationError(value, context)]); | ||
}; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
exports.success = function (value) { return new Either_1.Right(value); }; | ||
@@ -103,2 +133,5 @@ var pushAll = function (xs, ys) { | ||
// | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
var NullType = /** @class */ (function (_super) { | ||
@@ -114,5 +147,11 @@ __extends(NullType, _super); | ||
exports.NullType = NullType; | ||
/** @alias `null` */ | ||
/** | ||
* @alias `null` | ||
* @since 1.0.0 | ||
*/ | ||
exports.nullType = new NullType(); | ||
exports.null = exports.nullType; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
var UndefinedType = /** @class */ (function (_super) { | ||
@@ -130,2 +169,5 @@ __extends(UndefinedType, _super); | ||
exports.undefined = undefinedType; | ||
/** | ||
* @since 1.2.0 | ||
*/ | ||
var VoidType = /** @class */ (function (_super) { | ||
@@ -141,5 +183,11 @@ __extends(VoidType, _super); | ||
exports.VoidType = VoidType; | ||
/** @alias `void` */ | ||
/** | ||
* @alias `void` | ||
* @since 1.2.0 | ||
*/ | ||
exports.voidType = new VoidType(); | ||
exports.void = exports.voidType; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
var AnyType = /** @class */ (function (_super) { | ||
@@ -155,3 +203,26 @@ __extends(AnyType, _super); | ||
exports.AnyType = AnyType; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
exports.any = new AnyType(); | ||
/** | ||
* @since 1.5.0 | ||
*/ | ||
var UnknownType = /** @class */ (function (_super) { | ||
__extends(UnknownType, _super); | ||
function UnknownType() { | ||
var _this = _super.call(this, 'unknown', function (_) { return true; }, exports.success, exports.identity) || this; | ||
_this._tag = 'UnknownType'; | ||
return _this; | ||
} | ||
return UnknownType; | ||
}(Type)); | ||
exports.UnknownType = UnknownType; | ||
/** | ||
* @since 1.5.0 | ||
*/ | ||
exports.unknown = new UnknownType(); | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
var NeverType = /** @class */ (function (_super) { | ||
@@ -171,3 +242,9 @@ __extends(NeverType, _super); | ||
exports.NeverType = NeverType; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
exports.never = new NeverType(); | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
var StringType = /** @class */ (function (_super) { | ||
@@ -183,3 +260,9 @@ __extends(StringType, _super); | ||
exports.StringType = StringType; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
exports.string = new StringType(); | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
var NumberType = /** @class */ (function (_super) { | ||
@@ -195,3 +278,9 @@ __extends(NumberType, _super); | ||
exports.NumberType = NumberType; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
exports.number = new NumberType(); | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
var BooleanType = /** @class */ (function (_super) { | ||
@@ -207,3 +296,9 @@ __extends(BooleanType, _super); | ||
exports.BooleanType = BooleanType; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
exports.boolean = new BooleanType(); | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
var AnyArrayType = /** @class */ (function (_super) { | ||
@@ -221,2 +316,5 @@ __extends(AnyArrayType, _super); | ||
exports.Array = arrayType; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
var AnyDictionaryType = /** @class */ (function (_super) { | ||
@@ -232,3 +330,9 @@ __extends(AnyDictionaryType, _super); | ||
exports.AnyDictionaryType = AnyDictionaryType; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
exports.Dictionary = new AnyDictionaryType(); | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
var ObjectType = /** @class */ (function (_super) { | ||
@@ -244,3 +348,9 @@ __extends(ObjectType, _super); | ||
exports.ObjectType = ObjectType; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
exports.object = new ObjectType(); | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
var FunctionType = /** @class */ (function (_super) { | ||
@@ -258,6 +368,9 @@ __extends(FunctionType, _super); | ||
exports.FunctionType = FunctionType; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
exports.Function = new FunctionType(); | ||
// | ||
// refinements | ||
// | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
var RefinementType = /** @class */ (function (_super) { | ||
@@ -275,2 +388,5 @@ __extends(RefinementType, _super); | ||
exports.RefinementType = RefinementType; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
exports.refinement = function (type, predicate, name) { | ||
@@ -289,6 +405,9 @@ if (name === void 0) { name = "(" + type.name + " | " + exports.getFunctionName(predicate) + ")"; } | ||
}; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
exports.Integer = exports.refinement(exports.number, function (n) { return n % 1 === 0; }, 'Integer'); | ||
// | ||
// literals | ||
// | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
var LiteralType = /** @class */ (function (_super) { | ||
@@ -305,2 +424,5 @@ __extends(LiteralType, _super); | ||
exports.LiteralType = LiteralType; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
exports.literal = function (value, name) { | ||
@@ -311,5 +433,5 @@ if (name === void 0) { name = JSON.stringify(value); } | ||
}; | ||
// | ||
// keyof | ||
// | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
var KeyofType = /** @class */ (function (_super) { | ||
@@ -327,2 +449,5 @@ __extends(KeyofType, _super); | ||
var hasOwnProperty = Object.prototype.hasOwnProperty; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
exports.keyof = function (keys, name) { | ||
@@ -333,5 +458,5 @@ if (name === void 0) { name = "(keyof " + JSON.stringify(Object.keys(keys)) + ")"; } | ||
}; | ||
// | ||
// recursive types | ||
// | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
var RecursiveType = /** @class */ (function (_super) { | ||
@@ -355,2 +480,5 @@ __extends(RecursiveType, _super); | ||
exports.RecursiveType = RecursiveType; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
exports.recursion = function (name, definition) { | ||
@@ -367,5 +495,5 @@ var cache; | ||
}; | ||
// | ||
// arrays | ||
// | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
var ArrayType = /** @class */ (function (_super) { | ||
@@ -382,2 +510,5 @@ __extends(ArrayType, _super); | ||
exports.ArrayType = ArrayType; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
exports.array = function (type, name) { | ||
@@ -415,5 +546,5 @@ if (name === void 0) { name = "Array<" + type.name + ">"; } | ||
}; | ||
// | ||
// interfaces | ||
// | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
var InterfaceType = /** @class */ (function (_super) { | ||
@@ -443,3 +574,6 @@ __extends(InterfaceType, _super); | ||
}; | ||
/** @alias `interface` */ | ||
/** | ||
* @alias `interface` | ||
* @since 1.0.0 | ||
*/ | ||
exports.type = function (props, name) { | ||
@@ -512,5 +646,5 @@ if (name === void 0) { name = getNameFromProps(props); } | ||
exports.interface = exports.type; | ||
// | ||
// partials | ||
// | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
var PartialType = /** @class */ (function (_super) { | ||
@@ -527,2 +661,5 @@ __extends(PartialType, _super); | ||
exports.PartialType = PartialType; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
exports.partial = function (props, name) { | ||
@@ -592,5 +729,5 @@ if (name === void 0) { name = "PartialType<" + getNameFromProps(props) + ">"; } | ||
}; | ||
// | ||
// dictionaries | ||
// | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
var DictionaryType = /** @class */ (function (_super) { | ||
@@ -609,2 +746,5 @@ __extends(DictionaryType, _super); | ||
var refinedDictionary = exports.refinement(exports.Dictionary, function (d) { return Object.prototype.toString.call(d) === '[object Object]'; }); | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
exports.dictionary = function (domain, codomain, name) { | ||
@@ -663,5 +803,5 @@ if (name === void 0) { name = "{ [K in " + domain.name + "]: " + codomain.name + " }"; } | ||
}; | ||
// | ||
// unions | ||
// | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
var UnionType = /** @class */ (function (_super) { | ||
@@ -678,2 +818,5 @@ __extends(UnionType, _super); | ||
exports.UnionType = UnionType; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
exports.union = function (types, name) { | ||
@@ -708,5 +851,5 @@ if (name === void 0) { name = "(" + types.map(function (type) { return type.name; }).join(' | ') + ")"; } | ||
}; | ||
// | ||
// intersections | ||
// | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
var IntersectionType = /** @class */ (function (_super) { | ||
@@ -752,5 +895,5 @@ __extends(IntersectionType, _super); | ||
exports.intersection = intersection; | ||
// | ||
// tuples | ||
// | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
var TupleType = /** @class */ (function (_super) { | ||
@@ -805,5 +948,5 @@ __extends(TupleType, _super); | ||
exports.tuple = tuple; | ||
// | ||
// readonly objects | ||
// | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
var ReadonlyType = /** @class */ (function (_super) { | ||
@@ -820,2 +963,5 @@ __extends(ReadonlyType, _super); | ||
exports.ReadonlyType = ReadonlyType; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
exports.readonly = function (type, name) { | ||
@@ -832,5 +978,5 @@ if (name === void 0) { name = "Readonly<" + type.name + ">"; } | ||
}; | ||
// | ||
// readonly arrays | ||
// | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
var ReadonlyArrayType = /** @class */ (function (_super) { | ||
@@ -847,2 +993,5 @@ __extends(ReadonlyArrayType, _super); | ||
exports.ReadonlyArrayType = ReadonlyArrayType; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
exports.readonlyArray = function (type, name) { | ||
@@ -862,5 +1011,5 @@ if (name === void 0) { name = "ReadonlyArray<" + type.name + ">"; } | ||
}; | ||
// | ||
// strict types | ||
// | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
var StrictType = /** @class */ (function (_super) { | ||
@@ -880,2 +1029,3 @@ __extends(StrictType, _super); | ||
* @deprecated use `exact` instead | ||
* @since 1.0.0 | ||
*/ | ||
@@ -887,2 +1037,5 @@ exports.strict = function (props, name) { | ||
}; | ||
/** | ||
* @since 1.3.0 | ||
*/ | ||
exports.isTagged = function (tag) { | ||
@@ -920,2 +1073,5 @@ var f = function (type) { | ||
}; | ||
/** | ||
* @since 1.3.0 | ||
*/ | ||
exports.getTagValue = function (tag) { | ||
@@ -939,2 +1095,5 @@ var f = function (type) { | ||
}; | ||
/** | ||
* @since 1.3.0 | ||
*/ | ||
var TaggedUnionType = /** @class */ (function (_super) { | ||
@@ -951,2 +1110,5 @@ __extends(TaggedUnionType, _super); | ||
exports.TaggedUnionType = TaggedUnionType; | ||
/** | ||
* @since 1.3.0 | ||
*/ | ||
exports.taggedUnion = function (tag, types, name) { | ||
@@ -1005,5 +1167,5 @@ if (name === void 0) { name = "(" + types.map(function (type) { return type.name; }).join(' | ') + ")"; } | ||
}; | ||
// | ||
// exact types | ||
// | ||
/** | ||
* @since 1.1.0 | ||
*/ | ||
var ExactType = /** @class */ (function (_super) { | ||
@@ -1033,2 +1195,5 @@ __extends(ExactType, _super); | ||
}; | ||
/** | ||
* @since 1.1.0 | ||
*/ | ||
function exact(type, name) { | ||
@@ -1058,3 +1223,6 @@ if (name === void 0) { name = "ExactType<" + type.name + ">"; } | ||
exports.exact = exact; | ||
/** Drops the runtime type "kind" */ | ||
/** | ||
* Drops the runtime type "kind" | ||
* @since 1.1.0 | ||
*/ | ||
function clean(type) { | ||
@@ -1061,0 +1229,0 @@ return type; |
import { Reporter } from './Reporter'; | ||
import { ValidationError } from './index'; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare function failure(es: Array<ValidationError>): Array<string>; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare function success(): Array<string>; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export declare const PathReporter: Reporter<Array<string>>; |
@@ -16,2 +16,5 @@ "use strict"; | ||
} | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
function failure(es) { | ||
@@ -21,2 +24,5 @@ return es.map(function (e) { return getMessage(e.value, e.context); }); | ||
exports.failure = failure; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
function success() { | ||
@@ -26,4 +32,7 @@ return ['No errors!']; | ||
exports.success = success; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
exports.PathReporter = { | ||
report: function (validation) { return validation.fold(failure, success); } | ||
}; |
import { Validation } from './index'; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export interface Reporter<A> { | ||
report: (validation: Validation<any>) => A; | ||
} |
import { Reporter } from './Reporter'; | ||
/** | ||
* @since 1.0.0 | ||
* @deprecated | ||
*/ | ||
export declare const ThrowReporter: Reporter<void>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var PathReporter_1 = require("./PathReporter"); | ||
/** | ||
* @since 1.0.0 | ||
* @deprecated | ||
*/ | ||
exports.ThrowReporter = { | ||
@@ -5,0 +9,0 @@ report: function (validation) { |
{ | ||
"name": "io-ts", | ||
"version": "1.4.2", | ||
"version": "1.5.0", | ||
"description": "TypeScript compatible runtime type system for IO validation", | ||
@@ -47,3 +47,3 @@ "files": [ | ||
"tslint-config-standard": "^8.0.1", | ||
"typescript": "^3.1.6" | ||
"typescript": "^3.2.2" | ||
}, | ||
@@ -50,0 +50,0 @@ "tags": [ |
@@ -85,3 +85,3 @@ [![build status](https://img.shields.io/travis/gcanti/io-ts/master.svg?style=flat-square)](https://travis-ci.org/gcanti/io-ts) | ||
The stable version is tested against TypeScript 3.1.4, but should run with TypeScript 2.7.2+ too | ||
The stable version is tested against TypeScript 3.2.2, but should run with TypeScript 2.7.2+ too | ||
@@ -102,7 +102,4 @@ **Note**. If you are running `< typescript@3.0.1` you have to polyfill `unknown`. | ||
This package exports two default reporters | ||
This package exports a default `PathReporter` reporter | ||
- `PathReporter: Reporter<Array<string>>` | ||
- `ThrowReporter: Reporter<void>` | ||
Example | ||
@@ -112,3 +109,2 @@ | ||
import { PathReporter } from 'io-ts/lib/PathReporter' | ||
import { ThrowReporter } from 'io-ts/lib/ThrowReporter' | ||
@@ -119,5 +115,2 @@ const result = Person.decode({ name: 'Giulio' }) | ||
// => ['Invalid value undefined supplied to : { name: string, age: number }/age: number'] | ||
ThrowReporter.report(result) | ||
// => throws 'Invalid value undefined supplied to : { name: string, age: number }/age: number' | ||
``` | ||
@@ -486,3 +479,3 @@ | ||
export function unsafeDecode<A, O>(value: t.mixed, type: t.Type<A, O>): Either<t.Errors, A> { | ||
export function unsafeDecode<A, O, I>(value: I, type: t.Type<A, O, I>): Either<t.Errors, A> { | ||
if (NODE_ENV !== 'production' || type.encode !== t.identity) { | ||
@@ -492,3 +485,3 @@ return type.decode(value) | ||
// unsafe cast | ||
return right(value as A) | ||
return right(value as any) | ||
} | ||
@@ -501,3 +494,3 @@ } | ||
export function unsafeGet<A, O>(value: t.mixed, type: t.Type<A, O>): A { | ||
export function unsafeGet<A, O, I>(value: I, type: t.Type<A, O, I>): A { | ||
if (NODE_ENV !== 'production' || type.encode !== t.identity) { | ||
@@ -509,3 +502,3 @@ return type.decode(value).getOrElseL(errors => { | ||
// unsafe cast | ||
return value as A | ||
return value as any | ||
} | ||
@@ -512,0 +505,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
91370
1926
608