/** * @since 1.0.0 */ import { Either } from 'fp-ts/lib/Either' import { Predicate, Refinement } from 'fp-ts/lib/function' /** * @category Decode error * @since 1.0.0 */ export interface ContextEntry { readonly key: string readonly type: Decoder /** the input data */ readonly actual?: unknown } /** * @category Decode error * @since 1.0.0 */ export interface Context extends ReadonlyArray {} /** * @category Decode error * @since 1.0.0 */ export interface ValidationError { /** the offending (sub)value */ readonly value: unknown /** where the error originated */ readonly context: Context /** optional custom error message */ readonly message?: string } /** * @category Decode error * @since 1.0.0 */ export interface Errors extends Array {} /** * @category Decode error * @since 1.0.0 */ export declare type Validation = Either /** * @category Decode error * @since 1.0.0 */ export declare const failures: (errors: Errors) => Validation /** * @category Decode error * @since 1.0.0 */ export declare const failure: (value: unknown, context: Context, message?: string) => Validation /** * @category Decode error * @since 1.0.0 */ export declare const success: (value: T) => Validation /** * @since 1.0.0 */ export declare type Is = (u: unknown) => u is A /** * @since 1.0.0 */ export declare type Validate = (i: I, context: Context) => Validation /** * @since 1.0.0 */ export declare type Decode = (i: I) => Validation /** * @since 1.0.0 */ export declare type Encode = (a: A) => O /** * @since 1.0.0 */ export interface Any extends Type {} /** * @since 1.0.0 */ export interface Mixed extends Type {} /** * @category Codec * @since 1.0.0 */ export declare type TypeOf = C['_A'] /** * @category Codec * @since 1.0.0 */ export declare type InputOf = C['_I'] /** * @category Codec * @since 1.0.0 */ export declare type OutputOf = C['_O'] /** * @category Codec * @since 1.0.0 */ export interface Decoder { readonly name: string readonly validate: Validate readonly decode: Decode } /** * @category Codec * @since 1.0.0 */ export interface Encoder { readonly encode: Encode } /** * @category Codec * @since 1.0.0 */ export declare class Type implements Decoder, Encoder { /** a unique name for this codec */ readonly name: string /** a custom type guard */ readonly is: Is /** succeeds if a value of type I can be decoded to a value of type A */ readonly validate: Validate /** converts a value of type A to a value of type O */ readonly encode: Encode /** * @since 1.0.0 */ readonly _A: A /** * @since 1.0.0 */ readonly _O: O /** * @since 1.0.0 */ readonly _I: I constructor( /** a unique name for this codec */ name: string, /** a custom type guard */ is: Is, /** succeeds if a value of type I can be decoded to a value of type A */ validate: Validate, /** converts a value of type A to a value of type O */ encode: Encode ) /** * @since 1.0.0 */ pipe(this: Type, ab: Type, name?: string): Type /** * @since 1.0.0 */ asDecoder(): Decoder /** * @since 1.0.0 */ asEncoder(): Encoder /** * a version of `validate` with a default context * @since 1.0.0 */ decode(i: I): Validation } /** * @since 1.0.0 */ export declare const identity: (a: A) => A /** * @since 1.0.0 */ export declare function getFunctionName(f: Function): string /** * @since 1.0.0 */ export declare function getContextEntry(key: string, decoder: Decoder): ContextEntry /** * @since 1.0.0 */ export declare function appendContext(c: Context, key: string, decoder: Decoder, actual?: unknown): Context /** * @since 1.0.0 */ export interface AnyProps { [key: string]: Any } /** * @since 1.0.0 */ export declare type TypeOfProps

= { [K in keyof P]: TypeOf } /** * @since 1.0.0 */ export declare type OutputOfProps

= { [K in keyof P]: OutputOf } /** * @since 1.0.0 */ export interface Props { [key: string]: Mixed } /** * @since 1.0.0 */ export declare type TypeOfPartialProps

= { [K in keyof P]?: TypeOf } /** * @since 1.0.0 */ export declare type OutputOfPartialProps

= { [K in keyof P]?: OutputOf } /** * @since 1.0.0 */ export declare type TypeOfDictionary = { [K in TypeOf]: TypeOf } /** * @since 1.0.0 */ export declare type OutputOfDictionary = { [K in OutputOf]: OutputOf } /** * @since 1.1.0 */ export interface HasPropsRefinement extends RefinementType {} /** * @since 1.1.0 */ export interface HasPropsReadonly extends ReadonlyType {} /** * @since 1.1.0 */ export interface HasPropsIntersection extends IntersectionType, any, any, any> {} /** * @since 1.1.0 */ export declare type HasProps = | HasPropsRefinement | HasPropsReadonly | HasPropsIntersection | InterfaceType | StrictType | PartialType /** * @since 1.0.0 */ export declare class NullType extends Type { /** * @since 1.0.0 */ readonly _tag: 'NullType' constructor() } /** * @since 1.5.3 */ export interface NullC extends NullType {} /** * @category primitives * @since 1.0.0 */ export declare const nullType: NullC /** * @since 1.0.0 */ export declare class UndefinedType extends Type { /** * @since 1.0.0 */ readonly _tag: 'UndefinedType' constructor() } /** * @since 1.5.3 */ export interface UndefinedC extends UndefinedType {} declare const undefinedType: UndefinedC /** * @since 1.2.0 */ export declare class VoidType extends Type { /** * @since 1.0.0 */ readonly _tag: 'VoidType' constructor() } /** * @since 1.5.3 */ export interface VoidC extends VoidType {} /** * @category primitives * @since 1.2.0 */ export declare const voidType: VoidC /** * @since 1.5.0 */ export declare class UnknownType extends Type { /** * @since 1.0.0 */ readonly _tag: 'UnknownType' constructor() } /** * @since 1.5.3 */ export interface UnknownC extends UnknownType {} /** * @category primitives * @since 1.5.0 */ export declare const unknown: UnknownC /** * @since 1.0.0 */ export declare class StringType extends Type { /** * @since 1.0.0 */ readonly _tag: 'StringType' constructor() } /** * @since 1.5.3 */ export interface StringC extends StringType {} /** * @category primitives * @since 1.0.0 */ export declare const string: StringC /** * @since 1.0.0 */ export declare class NumberType extends Type { /** * @since 1.0.0 */ readonly _tag: 'NumberType' constructor() } /** * @since 1.5.3 */ export interface NumberC extends NumberType {} /** * @category primitives * @since 1.0.0 */ export declare const number: NumberC /** * @since 2.1.0 */ export declare class BigIntType extends Type { /** * @since 1.0.0 */ readonly _tag: 'BigIntType' constructor() } /** * @since 2.1.0 */ export interface BigIntC extends BigIntType {} /** * @category primitives * @since 2.1.0 */ export declare const bigint: BigIntC /** * @since 1.0.0 */ export declare class BooleanType extends Type { /** * @since 1.0.0 */ readonly _tag: 'BooleanType' constructor() } /** * @since 1.5.3 */ export interface BooleanC extends BooleanType {} /** * @category primitives * @since 1.0.0 */ export declare const boolean: BooleanC /** * @since 1.0.0 */ export declare class AnyArrayType extends Type> { /** * @since 1.0.0 */ readonly _tag: 'AnyArrayType' constructor() } /** * @since 1.5.3 */ export interface UnknownArrayC extends AnyArrayType {} /** * @category primitives * @since 1.7.1 */ export declare const UnknownArray: UnknownArrayC /** * @since 1.0.0 */ export declare class AnyDictionaryType extends Type<{ [key: string]: unknown }> { /** * @since 1.0.0 */ readonly _tag: 'AnyDictionaryType' constructor() } /** * @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 extends Type { readonly value: V /** * @since 1.0.0 */ readonly _tag: 'LiteralType' constructor( name: string, is: LiteralType['is'], validate: LiteralType['validate'], encode: LiteralType['encode'], value: V ) } /** * @since 1.5.3 */ export interface LiteralC extends LiteralType {} /** * @category constructors * @since 1.0.0 */ export declare function literal(value: V, name?: string): LiteralC /** * @since 1.0.0 */ export declare class KeyofType< D extends { [key: string]: unknown } > extends Type { readonly keys: D /** * @since 1.0.0 */ readonly _tag: 'KeyofType' constructor( name: string, is: KeyofType['is'], validate: KeyofType['validate'], encode: KeyofType['encode'], keys: D ) } /** * @since 1.5.3 */ export interface KeyofC< D extends { [key: string]: unknown } > extends KeyofType {} /** * @category constructors * @since 1.0.0 */ export declare function keyof< D extends { [key: string]: unknown } >(keys: D, name?: string): KeyofC /** * @since 1.0.0 */ export declare class RefinementType extends Type { readonly type: C readonly predicate: Predicate /** * @since 1.0.0 */ readonly _tag: 'RefinementType' constructor( name: string, is: RefinementType['is'], validate: RefinementType['validate'], encode: RefinementType['encode'], type: C, predicate: Predicate ) } declare const _brand: unique symbol /** * @since 1.8.1 */ export interface Brand { readonly [_brand]: B } /** * @since 1.8.1 */ export declare type Branded = A & Brand /** * @since 1.8.1 */ export interface BrandC extends RefinementType, B>, OutputOf, InputOf> {} /** * @category combinators * @since 1.8.1 */ export declare function brand< C extends Any, N extends string, B extends { readonly [K in N]: symbol } >(codec: C, predicate: Refinement, Branded, B>>, name: N): BrandC /** * @since 1.8.1 */ export interface IntBrand { readonly Int: unique symbol } /** * A branded codec representing an integer * * @category primitives * @since 1.8.1 */ export declare const Int: BrandC /** * @since 1.8.1 */ export declare type Int = Branded /** * @since 1.0.0 */ export declare class RecursiveType extends Type { runDefinition: () => C /** * @since 1.0.0 */ readonly _tag: 'RecursiveType' constructor( name: string, is: RecursiveType['is'], validate: RecursiveType['validate'], encode: RecursiveType['encode'], runDefinition: () => C ) /** * @since 1.0.0 */ readonly type: C } /** * @category combinators * @since 1.0.0 */ export declare function recursion = Type>( name: string, definition: (self: C) => C ): RecursiveType /** * @since 1.0.0 */ export declare class ArrayType extends Type { readonly type: C /** * @since 1.0.0 */ readonly _tag: 'ArrayType' constructor( name: string, is: ArrayType['is'], validate: ArrayType['validate'], encode: ArrayType['encode'], type: C ) } /** * @since 1.5.3 */ export interface ArrayC extends ArrayType>, Array>, unknown> {} /** * @category combinators * @since 1.0.0 */ export declare function array(item: C, name?: string): ArrayC /** * @since 1.0.0 */ export declare class InterfaceType extends Type { readonly props: P /** * @since 1.0.0 */ readonly _tag: 'InterfaceType' constructor( name: string, is: InterfaceType['is'], validate: InterfaceType['validate'], encode: InterfaceType['encode'], props: P ) } /** * @since 1.5.3 */ export interface TypeC

extends InterfaceType< P, { [K in keyof P]: TypeOf }, { [K in keyof P]: OutputOf }, unknown > {} /** * @category combinators * @since 1.0.0 */ export declare function type

(props: P, name?: string): TypeC

/** * @since 1.0.0 */ export declare class PartialType extends Type { readonly props: P /** * @since 1.0.0 */ readonly _tag: 'PartialType' constructor( name: string, is: PartialType['is'], validate: PartialType['validate'], encode: PartialType['encode'], props: P ) } /** * @since 1.5.3 */ export interface PartialC

extends PartialType< P, { [K in keyof P]?: TypeOf }, { [K in keyof P]?: OutputOf }, unknown > {} /** * @category combinators * @since 1.0.0 */ export declare function partial

(props: P, name?: string): PartialC

/** * @since 1.0.0 */ export declare class DictionaryType extends Type { readonly domain: D readonly codomain: C /** * @since 1.0.0 */ readonly _tag: 'DictionaryType' constructor( name: string, is: DictionaryType['is'], validate: DictionaryType['validate'], encode: DictionaryType['encode'], domain: D, codomain: C ) } /** * @since 1.5.3 */ export interface RecordC extends DictionaryType< D, C, { [K in TypeOf]: TypeOf }, { [K in OutputOf]: OutputOf }, unknown > {} /** * @category combinators * @since 1.7.1 */ export declare function record(domain: D, codomain: C, name?: string): RecordC /** * @since 1.0.0 */ export declare class UnionType, A = any, O = A, I = unknown> extends Type { readonly types: CS /** * @since 1.0.0 */ readonly _tag: 'UnionType' constructor( name: string, is: UnionType['is'], validate: UnionType['validate'], encode: UnionType['encode'], types: CS ) } /** * @since 1.5.3 */ export interface UnionC]> extends UnionType, OutputOf, unknown> {} /** * @category combinators * @since 1.0.0 */ export declare function union]>(codecs: CS, name?: string): UnionC /** * @since 1.0.0 */ export declare class IntersectionType, A = any, O = A, I = unknown> extends Type { readonly types: CS /** * @since 1.0.0 */ readonly _tag: 'IntersectionType' constructor( name: string, is: IntersectionType['is'], validate: IntersectionType['validate'], encode: IntersectionType['encode'], types: CS ) } /** * @since 1.5.3 */ export interface IntersectionC]> extends IntersectionType< CS, CS extends { length: 2 } ? TypeOf & TypeOf : CS extends { length: 3 } ? TypeOf & TypeOf & TypeOf : CS extends { length: 4 } ? TypeOf & TypeOf & TypeOf & TypeOf : CS extends { length: 5 } ? TypeOf & TypeOf & TypeOf & TypeOf & TypeOf : unknown, CS extends { length: 2 } ? OutputOf & OutputOf : CS extends { length: 3 } ? OutputOf & OutputOf & OutputOf : CS extends { length: 4 } ? OutputOf & OutputOf & OutputOf & OutputOf : CS extends { length: 5 } ? OutputOf & OutputOf & OutputOf & OutputOf & OutputOf : unknown, unknown > {} /** * @category combinators * @since 1.0.0 */ export declare function intersection< A extends Mixed, B extends Mixed, C extends Mixed, D extends Mixed, E extends Mixed >(codecs: [A, B, C, D, E], name?: string): IntersectionC<[A, B, C, D, E]> export declare function intersection( codecs: [A, B, C, D], name?: string ): IntersectionC<[A, B, C, D]> export declare function intersection( codecs: [A, B, C], name?: string ): IntersectionC<[A, B, C]> export declare function intersection( codecs: [A, B], name?: string ): IntersectionC<[A, B]> /** * @since 1.0.0 */ export declare class TupleType, A = any, O = A, I = unknown> extends Type { readonly types: CS /** * @since 1.0.0 */ readonly _tag: 'TupleType' constructor( name: string, is: TupleType['is'], validate: TupleType['validate'], encode: TupleType['encode'], types: CS ) } /** * @since 1.5.3 */ export interface TupleC]> extends TupleType< CS, CS extends { length: 1 } ? [TypeOf] : CS extends { length: 2 } ? [TypeOf, TypeOf] : CS extends { length: 3 } ? [TypeOf, TypeOf, TypeOf] : CS extends { length: 4 } ? [TypeOf, TypeOf, TypeOf, TypeOf] : CS extends { length: 5 } ? [TypeOf, TypeOf, TypeOf, TypeOf, TypeOf] : unknown, CS extends { length: 1 } ? [OutputOf] : CS extends { length: 2 } ? [OutputOf, OutputOf] : CS extends { length: 3 } ? [OutputOf, OutputOf, OutputOf] : CS extends { length: 4 } ? [OutputOf, OutputOf, OutputOf, OutputOf] : CS extends { length: 5 } ? [OutputOf, OutputOf, OutputOf, OutputOf, OutputOf] : unknown, unknown > {} /** * @category combinators * @since 1.0.0 */ export declare function tuple( codecs: [A, B, C, D, E], name?: string ): TupleC<[A, B, C, D, E]> export declare function tuple( codecs: [A, B, C, D], name?: string ): TupleC<[A, B, C, D]> export declare function tuple( codecs: [A, B, C], name?: string ): TupleC<[A, B, C]> export declare function tuple(codecs: [A, B], name?: string): TupleC<[A, B]> export declare function tuple(codecs: [A], name?: string): TupleC<[A]> /** * @since 1.0.0 */ export declare class ReadonlyType extends Type { readonly type: C /** * @since 1.0.0 */ readonly _tag: 'ReadonlyType' constructor( name: string, is: ReadonlyType['is'], validate: ReadonlyType['validate'], encode: ReadonlyType['encode'], type: C ) } /** * @since 1.5.3 */ export interface ReadonlyC extends ReadonlyType>, Readonly>, unknown> {} /** * @category combinators * @since 1.0.0 */ export declare function readonly(codec: C, name?: string): ReadonlyC /** * @since 1.0.0 */ export declare class ReadonlyArrayType extends Type { readonly type: C /** * @since 1.0.0 */ readonly _tag: 'ReadonlyArrayType' constructor( name: string, is: ReadonlyArrayType['is'], validate: ReadonlyArrayType['validate'], encode: ReadonlyArrayType['encode'], type: C ) } /** * @since 1.5.3 */ export interface ReadonlyArrayC extends ReadonlyArrayType>, ReadonlyArray>, unknown> {} /** * @category combinators * @since 1.0.0 */ export declare function readonlyArray(item: C, name?: string): ReadonlyArrayC /** * Strips additional properties, equivalent to `exact(type(props))`. * * @category combinators * @since 1.0.0 */ export declare const strict:

(props: P, name?: string) => ExactC> /** * @since 1.1.0 */ export declare class ExactType extends Type { readonly type: C /** * @since 1.0.0 */ readonly _tag: 'ExactType' constructor( name: string, is: ExactType['is'], validate: ExactType['validate'], encode: ExactType['encode'], type: C ) } /** * @since 1.5.3 */ export interface ExactC extends ExactType, OutputOf, InputOf> {} /** * Strips additional properties. * * @category combinators * @since 1.1.0 */ export declare function exact(codec: C, name?: string): ExactC /** * @since 1.0.0 */ export declare class FunctionType extends Type { /** * @since 1.0.0 */ readonly _tag: 'FunctionType' constructor() } /** * @since 1.5.3 */ export interface FunctionC extends FunctionType {} /** * @category primitives * @since 1.0.0 */ export declare const Function: FunctionC /** * @since 1.0.0 */ export declare class NeverType extends Type { /** * @since 1.0.0 */ readonly _tag: 'NeverType' constructor() } /** * @since 1.5.3 */ export interface NeverC extends NeverType {} /** * @category primitives * @since 1.0.0 */ export declare const never: NeverC /** * @since 1.0.0 */ export declare class AnyType extends Type { /** * @since 1.0.0 */ readonly _tag: 'AnyType' constructor() } /** * @since 1.5.3 */ export interface AnyC extends AnyType {} /** * @category primitives * @since 1.0.0 */ export declare const any: AnyC /** * @since 1.5.3 */ export interface RefinementC> extends RefinementType, InputOf> {} /** * @category combinators * @since 1.0.0 */ export declare function refinement>( codec: C, refinement: Refinement, B>, name?: string ): RefinementC export declare function refinement( codec: C, predicate: Predicate>, name?: string ): RefinementC /** * @category primitives * @since 1.0.0 */ export declare const Integer: RefinementC /** * @since 1.3.0 * @deprecated */ export declare class TaggedUnionType< Tag extends string, CS extends Array, A = any, O = A, I = unknown > extends UnionType { readonly tag: Tag constructor( name: string, is: TaggedUnionType['is'], validate: TaggedUnionType['validate'], encode: TaggedUnionType['encode'], codecs: CS, tag: Tag ) } /** * @since 1.5.3 * @deprecated */ export interface TaggedUnionC]> // tslint:disable-next-line: deprecation extends TaggedUnionType, OutputOf, unknown> {} /** * Use `union` instead. * * @category combinators * @since 1.3.0 * @deprecated */ export declare const taggedUnion: ( tag: Tag, codecs: CS, name?: string ) => TaggedUnionC export { /** * Use `UnknownArray` instead. * * @category primitives * @deprecated * @since 1.0.0 */ UnknownArray as Array } export { /** * Use `type` instead. * * @category combinators * @deprecated * @since 1.0.0 */ type as interface } /** * Use `unknown` instead. * * @since 1.0.0 * @deprecated */ export declare type mixed = unknown /** * @since 1.0.0 * @deprecated */ export declare const getValidationError: (value: unknown, context: Context) => ValidationError /** * @since 1.0.0 * @deprecated */ export declare const getDefaultContext: (decoder: Decoder) => Context /** * Use `UnknownRecord` instead. * * @category primitives * @since 1.0.0 * @deprecated */ export declare const Dictionary: UnknownRecordC /** * @since 1.0.0 * @deprecated */ export declare class ObjectType extends Type { /** * @since 1.0.0 */ readonly _tag: 'ObjectType' constructor() } /** * @since 1.5.3 * @deprecated */ export interface ObjectC extends ObjectType {} /** * Use `UnknownRecord` instead. * * @category primitives * @since 1.0.0 * @deprecated */ export declare const object: ObjectC /** * Use `record` instead. * * @category combinators * @since 1.0.0 * @deprecated */ export declare const dictionary: typeof record /** * @since 1.4.2 * @deprecated */ export declare type Compact = { [K in keyof A]: A[K] } /** * @since 1.0.0 * @deprecated */ export declare class StrictType extends Type { readonly props: P /** * @since 1.0.0 */ readonly _tag: 'StrictType' constructor( name: string, is: StrictType['is'], validate: StrictType['validate'], encode: StrictType['encode'], props: P ) } /** * @since 1.5.3 * @deprecated */ export interface StrictC

// tslint:disable-next-line: deprecation extends StrictType< P, { [K in keyof P]: TypeOf }, { [K in keyof P]: OutputOf }, unknown > {} /** * @since 1.3.0 * @deprecated */ export declare type TaggedProps = { [K in Tag]: LiteralType } /** * @since 1.3.0 * @deprecated */ export interface TaggedRefinement extends RefinementType, A, O> {} /** * @since 1.3.0 * @deprecated */ export interface TaggedUnion extends UnionType>, A, O> {} /** * @since 1.3.0 * @deprecated */ export declare type TaggedIntersectionArgument = | [Tagged] | [Tagged, Mixed] | [Mixed, Tagged] | [Tagged, Mixed, Mixed] | [Mixed, Tagged, Mixed] | [Mixed, Mixed, Tagged] | [Tagged, Mixed, Mixed, Mixed] | [Mixed, Tagged, Mixed, Mixed] | [Mixed, Mixed, Tagged, Mixed] | [Mixed, Mixed, Mixed, Tagged] | [Tagged, Mixed, Mixed, Mixed, Mixed] | [Mixed, Tagged, Mixed, Mixed, Mixed] | [Mixed, Mixed, Tagged, Mixed, Mixed] | [Mixed, Mixed, Mixed, Tagged, Mixed] | [Mixed, Mixed, Mixed, Mixed, Tagged] /** * @since 1.3.0 * @deprecated */ export interface TaggedIntersection // tslint:disable-next-line: deprecation extends IntersectionType, A, O> {} /** * @since 1.3.0 * @deprecated */ export interface TaggedExact extends ExactType, A, O> {} /** * @since 1.3.0 * @deprecated */ export declare type Tagged = | InterfaceType, A, O> | StrictType, A, O> | TaggedRefinement | TaggedUnion | TaggedIntersection | TaggedExact | RecursiveType /** * Drops the codec "kind". * * @category combinators * @since 1.1.0 * @deprecated */ export declare function clean(codec: Type): Type /** * @since 1.0.0 * @deprecated */ export declare type PropsOf< T extends { props: any } > = T['props'] /** * @since 1.1.0 * @deprecated */ export declare type Exact = T & { [K in ({ [K in keyof X]: K } & { [K in keyof T]: never } & { [key: string]: never })[keyof X]]?: never } /** * Keeps the codec "kind". * * @category combinators * @since 1.1.0 * @deprecated */ export declare function alias( codec: PartialType ): () => PartialType export declare function alias( codec: StrictType ): () => StrictType export declare function alias( codec: InterfaceType ): () => InterfaceType