Comparing version 2.2.7 to 2.2.8
@@ -17,2 +17,82 @@ # Changelog | ||
# 2.2.8 | ||
- **Experimental** | ||
- (\*) remove `KleisliDecoder` module (@gcanti) | ||
- (\*) remove `KleisliTaskDecoder` module (@gcanti) | ||
- (\*) remove `JsonCodec` module (@gcanti) | ||
- (\*) remove `JsonEncoder` module (@gcanti) | ||
- `Codec` | ||
- (\*) make `Codec` more general by adding a `I` type parameter (@gcanti) | ||
- add `fromType` function (@gcanti) | ||
- add `fromPartial` function (@gcanti) | ||
- add `fromArray` function (@gcanti) | ||
- add `fromRecord` function (@gcanti) | ||
- add `fromTuple` function (@gcanti) | ||
- add `fromSum` function (@gcanti) | ||
- add `compose` function (@gcanti) | ||
- `Decoder` | ||
- (\*) make `Decoder` more general by adding a `I` type parameter (@gcanti) | ||
- add `fromRefinement` function (@gcanti) | ||
- change `fromGuard` signature (@gcanti) | ||
- add `fromType` function (@gcanti) | ||
- add `fromPartial` function (@gcanti) | ||
- add `fromArray` function (@gcanti) | ||
- add `fromRecord` function (@gcanti) | ||
- add `fromTuple` function (@gcanti) | ||
- add `fromSum` function (@gcanti) | ||
- add `compose` function (@gcanti) | ||
- add `id` function (@gcanti) | ||
- (\*) rename `functorDecoder` instance to `Functor` (@gcanti) | ||
- (\*) rename `altDecoder` instance to `Alt` (@gcanti) | ||
- (\*) rename and split `schemableDecoder` (@gcanti) | ||
- add `Category` instance (@gcanti) | ||
- add `InputOf` type (@gcanti) | ||
- `TaskDecoder` | ||
- (\*) make `TaskDecoder` more general by adding a `I` type parameter (@gcanti) | ||
- add `fromRefinement` function (@gcanti) | ||
- change `fromDecoder` signature (@gcanti) | ||
- add `fromType` function (@gcanti) | ||
- add `fromPartial` function (@gcanti) | ||
- add `fromArray` function (@gcanti) | ||
- add `fromRecord` function (@gcanti) | ||
- add `fromTuple` function (@gcanti) | ||
- add `fromSum` function (@gcanti) | ||
- add `compose` function (@gcanti) | ||
- add `id` function (@gcanti) | ||
- (\*) rename `functorTaskDecoder` instance to `Functor` (@gcanti) | ||
- (\*) rename `altTaskDecoder` instance to `Alt` (@gcanti) | ||
- (\*) rename and split `schemableTaskDecoder` (@gcanti) | ||
- add `Category` instance (@gcanti) | ||
- add `InputOf` type (@gcanti) | ||
- `Guard` | ||
- (\*) make `Guard` more general by adding a `I` type parameter (@gcanti) | ||
- (\*) rename `schemableGuard` (@gcanti) | ||
- add `InputOf` type (@gcanti) | ||
- add `alt` function (@gcanti) | ||
- add `zero` function (@gcanti) | ||
- add `compose` function (@gcanti) | ||
- add `id` function (@gcanti) | ||
- `Codec` | ||
- (\*) rename `invariantCodec` to `Invariant` (@gcanti) | ||
- `Encoder` | ||
- (\*) rename `contravariantEncoder` to `Contravariant` (@gcanti) | ||
- (\*) rename `categoryEncoder` to `Category` (@gcanti) | ||
- `Eq` | ||
- (\*) rename and split `schemableEq` (@gcanti) | ||
- `Kleisli` | ||
- add `id` (@gcanti) | ||
- rename `type` to `fromType` (@gcanti) | ||
- rename `partial` to `fromPartial` (@gcanti) | ||
- rename `array` to `fromArray` (@gcanti) | ||
- rename `record` to `fromRecord` (@gcanti) | ||
- rename `tuple` to `fromTuple` (@gcanti) | ||
- rename `sum` to `fromSum` (@gcanti) | ||
- `Schemable` | ||
- add `Schemable2C`, `WithUnknownContainers2C`, `WithUnion2C`, `WithRefine2C` (@gcanti) | ||
- `Type` | ||
- (\*) rename and split `schemableType` (@gcanti) | ||
(\*) breaking change | ||
# 2.2.7 | ||
@@ -19,0 +99,0 @@ |
@@ -1,12 +0,2 @@ | ||
/** | ||
* **This module is experimental** | ||
* | ||
* Experimental features are published in order to get early feedback from the community, see these tracking | ||
* [issues](https://github.com/gcanti/io-ts/issues?q=label%3Av2.2+) for further discussions and enhancements. | ||
* | ||
* A feature tagged as _Experimental_ is in a high state of flux, you're at risk of it changing without notice. | ||
* | ||
* @since 2.2.3 | ||
*/ | ||
import { Invariant2 } from 'fp-ts/es6/Invariant'; | ||
import { Invariant3 } from 'fp-ts/es6/Invariant'; | ||
import * as D from './Decoder'; | ||
@@ -24,17 +14,9 @@ import * as E from './Encoder'; | ||
*/ | ||
export interface Codec<O, A> extends D.Decoder<A>, E.Encoder<O, A> { | ||
export interface Codec<I, O, A> extends D.Decoder<I, A>, E.Encoder<O, A> { | ||
} | ||
/** | ||
* @since 2.2.3 | ||
*/ | ||
export declare type TypeOf<C> = E.TypeOf<C>; | ||
/** | ||
* @since 2.2.3 | ||
*/ | ||
export declare type OutputOf<C> = E.OutputOf<C>; | ||
/** | ||
* @category constructors | ||
* @since 2.2.3 | ||
*/ | ||
export declare function make<O, A>(decoder: D.Decoder<A>, encoder: E.Encoder<O, A>): Codec<O, A>; | ||
export declare function make<I, O, A>(decoder: D.Decoder<I, A>, encoder: E.Encoder<O, A>): Codec<I, O, A>; | ||
/** | ||
@@ -44,3 +26,3 @@ * @category constructors | ||
*/ | ||
export declare function fromDecoder<A>(decoder: D.Decoder<A>): Codec<A, A>; | ||
export declare function fromDecoder<I, A>(decoder: D.Decoder<I, A>): Codec<I, A, A>; | ||
/** | ||
@@ -50,3 +32,3 @@ * @category constructors | ||
*/ | ||
export declare function literal<A extends readonly [Literal, ...Array<Literal>]>(...values: A): Codec<A[number], A[number]>; | ||
export declare function literal<A extends readonly [Literal, ...Array<Literal>]>(...values: A): Codec<unknown, A[number], A[number]>; | ||
/** | ||
@@ -56,3 +38,3 @@ * @category primitives | ||
*/ | ||
export declare const string: Codec<string, string>; | ||
export declare const string: Codec<unknown, string, string>; | ||
/** | ||
@@ -62,3 +44,3 @@ * @category primitives | ||
*/ | ||
export declare const number: Codec<number, number>; | ||
export declare const number: Codec<unknown, number, number>; | ||
/** | ||
@@ -68,3 +50,3 @@ * @category primitives | ||
*/ | ||
export declare const boolean: Codec<boolean, boolean>; | ||
export declare const boolean: Codec<unknown, boolean, boolean>; | ||
/** | ||
@@ -74,3 +56,3 @@ * @category primitives | ||
*/ | ||
export declare const UnknownArray: Codec<Array<unknown>, Array<unknown>>; | ||
export declare const UnknownArray: Codec<unknown, Array<unknown>, Array<unknown>>; | ||
/** | ||
@@ -80,3 +62,3 @@ * @category primitives | ||
*/ | ||
export declare const UnknownRecord: Codec<Record<string, unknown>, Record<string, unknown>>; | ||
export declare const UnknownRecord: Codec<unknown, Record<string, unknown>, Record<string, unknown>>; | ||
/** | ||
@@ -86,3 +68,3 @@ * @category combinators | ||
*/ | ||
export declare const mapLeftWithInput: (f: (actual: unknown, e: D.DecodeError) => D.DecodeError) => <O, A>(codec: Codec<O, A>) => Codec<O, A>; | ||
export declare const mapLeftWithInput: <I>(f: (i: I, e: D.DecodeError) => D.DecodeError) => <O, A>(codec: Codec<I, O, A>) => Codec<I, O, A>; | ||
/** | ||
@@ -92,3 +74,3 @@ * @category combinators | ||
*/ | ||
export declare const refine: <A, B extends A>(refinement: (a: A) => a is B, id: string) => <O>(from: Codec<O, A>) => Codec<O, B>; | ||
export declare const refine: <A, B extends A>(refinement: (a: A) => a is B, id: string) => <I, O>(from: Codec<I, O, A>) => Codec<I, O, B>; | ||
/** | ||
@@ -98,8 +80,19 @@ * @category combinators | ||
*/ | ||
export declare function nullable<O, A>(or: Codec<O, A>): Codec<null | O, null | A>; | ||
export declare function nullable<I, O, A>(or: Codec<I, O, A>): Codec<null | I, null | O, null | A>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
export declare function fromType<P extends Record<string, Codec<any, any, any>>>(properties: P): Codec<{ | ||
[K in keyof P]: InputOf<P[K]>; | ||
}, { | ||
[K in keyof P]: OutputOf<P[K]>; | ||
}, { | ||
[K in keyof P]: TypeOf<P[K]>; | ||
}>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.3 | ||
*/ | ||
export declare function type<P extends Record<string, Codec<any, any>>>(properties: P): Codec<{ | ||
export declare function type<P extends Record<string, Codec<unknown, any, any>>>(properties: P): Codec<unknown, { | ||
[K in keyof P]: OutputOf<P[K]>; | ||
@@ -111,5 +104,16 @@ }, { | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
export declare function fromPartial<P extends Record<string, Codec<any, any, any>>>(properties: P): Codec<Partial<{ | ||
[K in keyof P]: InputOf<P[K]>; | ||
}>, Partial<{ | ||
[K in keyof P]: OutputOf<P[K]>; | ||
}>, Partial<{ | ||
[K in keyof P]: TypeOf<P[K]>; | ||
}>>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.3 | ||
*/ | ||
export declare function partial<P extends Record<string, Codec<any, any>>>(properties: P): Codec<Partial<{ | ||
export declare function partial<P extends Record<string, Codec<unknown, any, any>>>(properties: P): Codec<unknown, Partial<{ | ||
[K in keyof P]: OutputOf<P[K]>; | ||
@@ -123,3 +127,3 @@ }>, Partial<{ | ||
*/ | ||
export declare function record<O, A>(codomain: Codec<O, A>): Codec<Record<string, O>, Record<string, A>>; | ||
export declare function fromArray<I, O, A>(item: Codec<I, O, A>): Codec<Array<I>, Array<O>, Array<A>>; | ||
/** | ||
@@ -129,3 +133,3 @@ * @category combinators | ||
*/ | ||
export declare function array<O, A>(items: Codec<O, A>): Codec<Array<O>, Array<A>>; | ||
export declare function array<O, A>(item: Codec<unknown, O, A>): Codec<unknown, Array<O>, Array<A>>; | ||
/** | ||
@@ -135,3 +139,18 @@ * @category combinators | ||
*/ | ||
export declare function tuple<C extends ReadonlyArray<Codec<any, any>>>(...components: C): Codec<{ | ||
export declare function fromRecord<I, O, A>(codomain: Codec<I, O, A>): Codec<Record<string, I>, Record<string, O>, Record<string, A>>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.3 | ||
*/ | ||
export declare function record<O, A>(codomain: Codec<unknown, O, A>): Codec<unknown, Record<string, O>, Record<string, A>>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
export declare const fromTuple: <C extends readonly Codec<any, any, any>[]>(...components: C) => Codec<{ [K in keyof C]: import("./Kleisli").InputOf<"Either", C[K]>; }, { [K_1 in keyof C]: E.OutputOf<C[K_1]>; }, { [K_2 in keyof C]: E.TypeOf<C[K_2]>; }>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.3 | ||
*/ | ||
export declare function tuple<C extends ReadonlyArray<Codec<unknown, any, any>>>(...components: C): Codec<unknown, { | ||
[K in keyof C]: OutputOf<C[K]>; | ||
@@ -145,8 +164,13 @@ }, { | ||
*/ | ||
export declare const intersect: <P, B>(right: Codec<P, B>) => <O, A>(left: Codec<O, A>) => Codec<O & P, A & B>; | ||
export declare const intersect: <IB, OB, B>(right: Codec<IB, OB, B>) => <IA, OA, A>(left: Codec<IA, OA, A>) => Codec<IA & IB, OA & OB, A & B>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
export declare const fromSum: <T extends string>(tag: T) => <MS extends Record<string, Codec<any, any, any>>>(members: MS) => Codec<import("./Kleisli").InputOf<"Either", MS[keyof MS]>, E.OutputOf<MS[keyof MS]>, E.TypeOf<MS[keyof MS]>>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.3 | ||
*/ | ||
export declare function sum<T extends string>(tag: T): <M extends Record<string, Codec<any, any>>>(members: M) => Codec<OutputOf<M[keyof M]>, TypeOf<M[keyof M]>>; | ||
export declare function sum<T extends string>(tag: T): <M extends Record<string, Codec<unknown, any, any>>>(members: M) => Codec<unknown, OutputOf<M[keyof M]>, TypeOf<M[keyof M]>>; | ||
/** | ||
@@ -156,8 +180,13 @@ * @category combinators | ||
*/ | ||
export declare function lazy<O, A>(id: string, f: () => Codec<O, A>): Codec<O, A>; | ||
export declare function lazy<I, O, A>(id: string, f: () => Codec<I, O, A>): Codec<I, O, A>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
export declare const compose: <L, A extends L, P extends A, B>(to: Codec<L, P, B>) => <I, O>(from: Codec<I, O, A>) => Codec<I, O, B>; | ||
/** | ||
* @category Invariant | ||
* @since 2.2.3 | ||
*/ | ||
export declare const imap: <E, A, B>(f: (a: A) => B, g: (b: B) => A) => (fa: Codec<E, A>) => Codec<E, B>; | ||
export declare const imap: <I, O, A, B>(f: (a: A) => B, g: (b: B) => A) => (fa: Codec<I, O, A>) => Codec<I, O, B>; | ||
/** | ||
@@ -174,4 +203,4 @@ * @category instances | ||
declare module 'fp-ts/es6/HKT' { | ||
interface URItoKind2<E, A> { | ||
readonly [URI]: Codec<E, A>; | ||
interface URItoKind3<R, E, A> { | ||
readonly [URI]: Codec<R, E, A>; | ||
} | ||
@@ -181,4 +210,16 @@ } | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
export declare const Invariant: Invariant3<URI>; | ||
/** | ||
* @since 2.2.8 | ||
*/ | ||
export declare type InputOf<C> = D.InputOf<C>; | ||
/** | ||
* @since 2.2.3 | ||
*/ | ||
export declare const invariantCodec: Invariant2<URI>; | ||
export declare type OutputOf<C> = E.OutputOf<C>; | ||
/** | ||
* @since 2.2.3 | ||
*/ | ||
export declare type TypeOf<C> = E.TypeOf<C>; |
126
es6/Codec.js
@@ -0,5 +1,15 @@ | ||
/** | ||
* **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 { identity } from 'fp-ts/es6/function'; | ||
import { pipe } from 'fp-ts/es6/pipeable'; | ||
import * as D from './Decoder'; | ||
import * as E from './Encoder'; | ||
import { identity } from 'fp-ts/es6/function'; | ||
import { pipe } from 'fp-ts/es6/pipeable'; | ||
// ------------------------------------------------------------------------------------- | ||
@@ -46,3 +56,5 @@ // constructors | ||
*/ | ||
export var string = fromDecoder(D.string); | ||
export var string = | ||
/*#__PURE__*/ | ||
fromDecoder(D.string); | ||
/** | ||
@@ -52,3 +64,5 @@ * @category primitives | ||
*/ | ||
export var number = fromDecoder(D.number); | ||
export var number = | ||
/*#__PURE__*/ | ||
fromDecoder(D.number); | ||
/** | ||
@@ -58,3 +72,5 @@ * @category primitives | ||
*/ | ||
export var boolean = fromDecoder(D.boolean); | ||
export var boolean = | ||
/*#__PURE__*/ | ||
fromDecoder(D.boolean); | ||
/** | ||
@@ -64,3 +80,5 @@ * @category primitives | ||
*/ | ||
export var UnknownArray = fromDecoder(D.UnknownArray); | ||
export var UnknownArray = | ||
/*#__PURE__*/ | ||
fromDecoder(D.UnknownArray); | ||
/** | ||
@@ -70,3 +88,5 @@ * @category primitives | ||
*/ | ||
export var UnknownRecord = fromDecoder(D.UnknownRecord); | ||
export var UnknownRecord = | ||
/*#__PURE__*/ | ||
fromDecoder(D.UnknownRecord); | ||
// ------------------------------------------------------------------------------------- | ||
@@ -97,16 +117,27 @@ // combinators | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
export function fromType(properties) { | ||
return make(D.fromType(properties), E.type(properties)); | ||
} | ||
/** | ||
* @category combinators | ||
* @since 2.2.3 | ||
*/ | ||
export function type(properties) { | ||
var decoder = D.type(properties); | ||
return make(decoder, E.type(properties)); | ||
return pipe(UnknownRecord, compose(fromType(properties))); | ||
} | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
export function fromPartial(properties) { | ||
return make(D.fromPartial(properties), E.partial(properties)); | ||
} | ||
/** | ||
* @category combinators | ||
* @since 2.2.3 | ||
*/ | ||
export function partial(properties) { | ||
// these two `any`s are required to make typescript@3.5 compile | ||
// vvvvvv vvvvvv | ||
return make(D.partial(properties), E.partial(properties)); | ||
return pipe(UnknownRecord, compose(fromPartial(properties))); | ||
} | ||
@@ -117,4 +148,4 @@ /** | ||
*/ | ||
export function record(codomain) { | ||
return make(D.record(codomain), E.record(codomain)); | ||
export function fromArray(item) { | ||
return make(D.fromArray(item), E.array(item)); | ||
} | ||
@@ -125,4 +156,4 @@ /** | ||
*/ | ||
export function array(items) { | ||
return make(D.array(items), E.array(items)); | ||
export function array(item) { | ||
return pipe(UnknownArray, compose(fromArray(item))); | ||
} | ||
@@ -133,2 +164,27 @@ /** | ||
*/ | ||
export function fromRecord(codomain) { | ||
return make(D.fromRecord(codomain), E.record(codomain)); | ||
} | ||
/** | ||
* @category combinators | ||
* @since 2.2.3 | ||
*/ | ||
export function record(codomain) { | ||
return pipe(UnknownRecord, compose(fromRecord(codomain))); | ||
} | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
export var fromTuple = function () { | ||
var components = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
components[_i] = arguments[_i]; | ||
} | ||
return make(D.fromTuple.apply(D, components), E.tuple.apply(E, components)); | ||
}; | ||
/** | ||
* @category combinators | ||
* @since 2.2.3 | ||
*/ | ||
export function tuple() { | ||
@@ -139,5 +195,3 @@ var components = []; | ||
} | ||
var decoder = D.tuple.apply(D, components); | ||
var encoder = E.tuple.apply(E, components); | ||
return make(decoder, encoder); | ||
return pipe(UnknownArray, compose(fromTuple.apply(void 0, components))); | ||
} | ||
@@ -155,8 +209,16 @@ /** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
export var fromSum = function (tag) { | ||
var decoder = D.fromSum(tag); | ||
var encoder = E.sum(tag); | ||
return function (members) { return make(decoder(members), encoder(members)); }; | ||
}; | ||
/** | ||
* @category combinators | ||
* @since 2.2.3 | ||
*/ | ||
export function sum(tag) { | ||
var sumD = D.sum(tag); | ||
var sumE = E.sum(tag); | ||
return function (members) { return make(sumD(members), sumE(members)); }; | ||
var sum = fromSum(tag); | ||
return function (members) { return pipe(UnknownRecord, compose(sum(members))); }; | ||
} | ||
@@ -170,3 +232,12 @@ /** | ||
} | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
export var compose = function (to) { return function (from) { return make(D.compose(to)(from), E.compose(from)(to)); }; }; | ||
// ------------------------------------------------------------------------------------- | ||
// non-pipeables | ||
// ------------------------------------------------------------------------------------- | ||
var imap_ = function (fa, f, g) { return make(D.Functor.map(fa, f), E.Contravariant.contramap(fa, g)); }; | ||
// ------------------------------------------------------------------------------------- | ||
// pipeables | ||
@@ -178,8 +249,3 @@ // ------------------------------------------------------------------------------------- | ||
*/ | ||
export var imap = function (f, g) { return function (fa) { | ||
return imap_(fa, f, g); | ||
}; }; | ||
var imap_ = function (fa, f, g) { | ||
return make(D.functorDecoder.map(fa, f), E.contravariantEncoder.contramap(fa, g)); | ||
}; | ||
export var imap = function (f, g) { return function (fa) { return imap_(fa, f, g); }; }; | ||
// ------------------------------------------------------------------------------------- | ||
@@ -195,7 +261,7 @@ // instances | ||
* @category instances | ||
* @since 2.2.3 | ||
* @since 2.2.8 | ||
*/ | ||
export var invariantCodec = { | ||
export var Invariant = { | ||
URI: URI, | ||
imap: imap_ | ||
}; |
@@ -11,13 +11,17 @@ /** | ||
*/ | ||
import { Alt1 } from 'fp-ts/es6/Alt'; | ||
import { Alt2 } from 'fp-ts/es6/Alt'; | ||
import { Category2 } from 'fp-ts/es6/Category'; | ||
import * as E from 'fp-ts/es6/Either'; | ||
import { Functor1 } from 'fp-ts/es6/Functor'; | ||
import { Refinement } from 'fp-ts/es6/function'; | ||
import { Functor2 } from 'fp-ts/es6/Functor'; | ||
import * as DE from './DecodeError'; | ||
import * as FS from './FreeSemigroup'; | ||
import * as G from './Guard'; | ||
import * as KD from './KleisliDecoder'; | ||
import { Literal, Schemable1, WithRefine1, WithUnion1, WithUnknownContainers1 } from './Schemable'; | ||
import * as K from './Kleisli'; | ||
import * as S from './Schemable'; | ||
/** | ||
* @category model | ||
* @since 2.2.7 | ||
* @since 2.2.8 | ||
*/ | ||
export interface Decoder<A> extends KD.KleisliDecoder<unknown, A> { | ||
export interface Decoder<I, A> extends K.Kleisli<E.URI, I, DecodeError, A> { | ||
} | ||
@@ -28,3 +32,3 @@ /** | ||
*/ | ||
export declare type DecodeError = KD.DecodeError; | ||
export declare type DecodeError = FS.FreeSemigroup<DE.DecodeError<string>>; | ||
/** | ||
@@ -44,13 +48,18 @@ * @category DecodeError | ||
*/ | ||
export declare const failure: <A = never>(actual: unknown, message: string) => E.Either<DecodeError, A>; | ||
export declare const failure: <A = never>(actual: unknown, message: string) => E.Either<FS.FreeSemigroup<DE.DecodeError<string>>, A>; | ||
/** | ||
* @category constructors | ||
* @since 2.2.7 | ||
* @since 2.2.8 | ||
*/ | ||
export declare const fromGuard: <A>(guard: G.Guard<A>, expected: string) => Decoder<A>; | ||
export declare const fromRefinement: <I, A extends I>(refinement: Refinement<I, A>, expected: string) => Decoder<I, A>; | ||
/** | ||
* @category constructors | ||
* @since 2.2.8 | ||
*/ | ||
export declare const fromGuard: <I, A extends I>(guard: G.Guard<I, A>, expected: string) => Decoder<I, A>; | ||
/** | ||
* @category constructors | ||
* @since 2.2.7 | ||
*/ | ||
export declare const literal: <A extends readonly [Literal, ...Array<Literal>]>(...values: A) => Decoder<A[number]>; | ||
export declare const literal: <A extends readonly [S.Literal, ...Array<S.Literal>]>(...values: A) => Decoder<unknown, A[number]>; | ||
/** | ||
@@ -60,3 +69,3 @@ * @category primitives | ||
*/ | ||
export declare const string: Decoder<string>; | ||
export declare const string: Decoder<unknown, string>; | ||
/** | ||
@@ -66,3 +75,3 @@ * @category primitives | ||
*/ | ||
export declare const number: Decoder<number>; | ||
export declare const number: Decoder<unknown, number>; | ||
/** | ||
@@ -72,3 +81,3 @@ * @category primitives | ||
*/ | ||
export declare const boolean: Decoder<boolean>; | ||
export declare const boolean: Decoder<unknown, boolean>; | ||
/** | ||
@@ -78,3 +87,3 @@ * @category primitives | ||
*/ | ||
export declare const UnknownArray: Decoder<Array<unknown>>; | ||
export declare const UnknownArray: Decoder<unknown, Array<unknown>>; | ||
/** | ||
@@ -84,3 +93,3 @@ * @category primitives | ||
*/ | ||
export declare const UnknownRecord: Decoder<Record<string, unknown>>; | ||
export declare const UnknownRecord: Decoder<unknown, Record<string, unknown>>; | ||
/** | ||
@@ -90,3 +99,3 @@ * @category combinators | ||
*/ | ||
export declare const mapLeftWithInput: (f: (input: unknown, e: DecodeError) => DecodeError) => <A>(decoder: Decoder<A>) => Decoder<A>; | ||
export declare const mapLeftWithInput: <I>(f: (input: I, e: DecodeError) => DecodeError) => <A>(decoder: Decoder<I, A>) => Decoder<I, A>; | ||
/** | ||
@@ -96,3 +105,3 @@ * @category combinators | ||
*/ | ||
export declare const refine: <A, B extends A>(refinement: (a: A) => a is B, id: string) => (from: Decoder<A>) => Decoder<B>; | ||
export declare const refine: <A, B extends A>(refinement: (a: A) => a is B, id: string) => <I>(from: Decoder<I, A>) => Decoder<I, B>; | ||
/** | ||
@@ -102,3 +111,3 @@ * @category combinators | ||
*/ | ||
export declare const parse: <A, B>(parser: (a: A) => E.Either<DecodeError, B>) => (from: Decoder<A>) => Decoder<B>; | ||
export declare const parse: <A, B>(parser: (a: A) => E.Either<DecodeError, B>) => <I>(from: Decoder<I, A>) => Decoder<I, B>; | ||
/** | ||
@@ -108,8 +117,8 @@ * @category combinators | ||
*/ | ||
export declare const nullable: <A>(or: Decoder<A>) => Decoder<null | A>; | ||
export declare const nullable: <I, A>(or: Decoder<I, A>) => Decoder<null | I, null | A>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.7 | ||
* @since 2.2.8 | ||
*/ | ||
export declare const type: <A>(properties: { [K in keyof A]: Decoder<A[K]>; }) => Decoder<{ [K_1 in keyof A]: A[K_1]; }>; | ||
export declare const fromType: <P extends Record<string, Decoder<any, any>>>(properties: P) => Decoder<{ [K in keyof P]: K.InputOf<"Either", P[K]>; }, { [K_1 in keyof P]: K.TypeOf<"Either", P[K_1]>; }>; | ||
/** | ||
@@ -119,25 +128,43 @@ * @category combinators | ||
*/ | ||
export declare const partial: <A>(properties: { [K in keyof A]: Decoder<A[K]>; }) => Decoder<Partial<{ [K_1 in keyof A]: A[K_1]; }>>; | ||
export declare const type: <A>(properties: { [K in keyof A]: Decoder<unknown, A[K]>; }) => Decoder<unknown, { [K_1 in keyof A]: A[K_1]; }>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
export declare const fromPartial: <P extends Record<string, Decoder<any, any>>>(properties: P) => Decoder<Partial<{ [K in keyof P]: K.InputOf<"Either", P[K]>; }>, Partial<{ [K_1 in keyof P]: K.TypeOf<"Either", P[K_1]>; }>>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.7 | ||
*/ | ||
export declare const array: <A>(items: Decoder<A>) => Decoder<A[]>; | ||
export declare const partial: <A>(properties: { [K in keyof A]: Decoder<unknown, A[K]>; }) => Decoder<unknown, Partial<{ [K_1 in keyof A]: A[K_1]; }>>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
export declare const fromArray: <I, A>(item: Decoder<I, A>) => Decoder<I[], A[]>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.7 | ||
*/ | ||
export declare const record: <A>(codomain: Decoder<A>) => Decoder<Record<string, A>>; | ||
export declare const array: <A>(item: Decoder<unknown, A>) => Decoder<unknown, A[]>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
export declare const fromRecord: <I, A>(codomain: Decoder<I, A>) => Decoder<Record<string, I>, Record<string, A>>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.7 | ||
*/ | ||
export declare const tuple: <A extends readonly unknown[]>(...components: { [K in keyof A]: Decoder<A[K]>; }) => Decoder<A>; | ||
export declare const record: <A>(codomain: Decoder<unknown, A>) => Decoder<unknown, Record<string, A>>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
export declare const fromTuple: <C extends readonly Decoder<any, any>[]>(...components: C) => Decoder<{ [K in keyof C]: K.InputOf<"Either", C[K]>; }, { [K_1 in keyof C]: K.TypeOf<"Either", C[K_1]>; }>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.7 | ||
*/ | ||
export declare const union: <A extends readonly [unknown, ...Array<unknown>]>(...members: { | ||
[K in keyof A]: Decoder<A[K]>; | ||
}) => Decoder<A[number]>; | ||
export declare const tuple: <A extends readonly unknown[]>(...components: { [K in keyof A]: Decoder<unknown, A[K]>; }) => Decoder<unknown, A>; | ||
/** | ||
@@ -147,3 +174,3 @@ * @category combinators | ||
*/ | ||
export declare const intersect: <B>(right: Decoder<B>) => <A>(left: Decoder<A>) => Decoder<A & B>; | ||
export declare const union: <MS extends readonly [Decoder<any, any>, ...Array<Decoder<any, any>>]>(...members: MS) => Decoder<InputOf<MS[keyof MS]>, TypeOf<MS[keyof MS]>>; | ||
/** | ||
@@ -153,8 +180,13 @@ * @category combinators | ||
*/ | ||
export declare const sum: <T extends string>(tag: T) => <A>(members: { [K in keyof A]: Decoder<A[K]>; }) => Decoder<A[keyof A]>; | ||
export declare const intersect: <IB, B>(right: Decoder<IB, B>) => <IA, A>(left: Decoder<IA, A>) => Decoder<IA & IB, A & B>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
export declare const fromSum: <T extends string>(tag: T) => <MS extends Record<string, Decoder<any, any>>>(members: MS) => Decoder<K.InputOf<"Either", MS[keyof MS]>, K.TypeOf<"Either", MS[keyof MS]>>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.7 | ||
*/ | ||
export declare const lazy: <A>(id: string, f: () => Decoder<A>) => Decoder<A>; | ||
export declare const sum: <T extends string>(tag: T) => <A>(members: { [K in keyof A]: Decoder<unknown, A[K]>; }) => Decoder<unknown, A[keyof A]>; | ||
/** | ||
@@ -164,3 +196,3 @@ * @category combinators | ||
*/ | ||
export declare const compose: <A, B>(to: KD.KleisliDecoder<A, B>) => (from: Decoder<A>) => Decoder<B>; | ||
export declare const lazy: <I, A>(id: string, f: () => Decoder<I, A>) => Decoder<I, A>; | ||
/** | ||
@@ -170,3 +202,3 @@ * @category Functor | ||
*/ | ||
export declare const map: <A, B>(f: (a: A) => B) => (fa: Decoder<A>) => Decoder<B>; | ||
export declare const map: <A, B>(f: (a: A) => B) => <I>(fa: Decoder<I, A>) => Decoder<I, B>; | ||
/** | ||
@@ -176,4 +208,14 @@ * @category Alt | ||
*/ | ||
export declare const alt: <A>(that: () => Decoder<A>) => (me: Decoder<A>) => Decoder<A>; | ||
export declare const alt: <I, A>(that: () => Decoder<I, A>) => (me: Decoder<I, A>) => Decoder<I, A>; | ||
/** | ||
* @category Semigroupoid | ||
* @since 2.2.8 | ||
*/ | ||
export declare const compose: <A, B>(to: Decoder<A, B>) => <I>(from: Decoder<I, A>) => Decoder<I, B>; | ||
/** | ||
* @category Category | ||
* @since 2.2.8 | ||
*/ | ||
export declare const id: <A>() => Decoder<A, A>; | ||
/** | ||
* @category instances | ||
@@ -189,4 +231,4 @@ * @since 2.2.7 | ||
declare module 'fp-ts/es6/HKT' { | ||
interface URItoKind<A> { | ||
readonly [URI]: Decoder<A>; | ||
interface URItoKind2<E, A> { | ||
readonly [URI]: Decoder<E, A>; | ||
} | ||
@@ -196,19 +238,43 @@ } | ||
* @category instances | ||
* @since 2.2.7 | ||
* @since 2.2.8 | ||
*/ | ||
export declare const functorDecoder: Functor1<URI>; | ||
export declare const Functor: Functor2<URI>; | ||
/** | ||
* @category instances | ||
* @since 2.2.7 | ||
* @since 2.2.8 | ||
*/ | ||
export declare const altDecoder: Alt1<URI>; | ||
export declare const Alt: Alt2<URI>; | ||
/** | ||
* @category instances | ||
* @since 2.2.7 | ||
* @since 2.2.8 | ||
*/ | ||
export declare const schemableDecoder: Schemable1<URI> & WithUnknownContainers1<URI> & WithUnion1<URI> & WithRefine1<URI>; | ||
export declare const Category: Category2<URI>; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
export declare const Schemable: S.Schemable2C<URI, unknown>; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
export declare const WithUnknownContainers: S.WithUnknownContainers2C<URI, unknown>; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
export declare const WithUnion: S.WithUnion2C<URI, unknown>; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
export declare const WithRefine: S.WithRefine2C<URI, unknown>; | ||
/** | ||
* @since 2.2.8 | ||
*/ | ||
export declare type InputOf<D> = K.InputOf<E.URI, D>; | ||
/** | ||
* @since 2.2.7 | ||
*/ | ||
export declare type TypeOf<D> = KD.TypeOf<D>; | ||
export declare type TypeOf<D> = K.TypeOf<E.URI, D>; | ||
/** | ||
@@ -215,0 +281,0 @@ * @since 2.2.7 |
@@ -6,8 +6,47 @@ import * as E from 'fp-ts/es6/Either'; | ||
import * as G from './Guard'; | ||
import * as KD from './KleisliDecoder'; | ||
import * as K from './Kleisli'; | ||
// ------------------------------------------------------------------------------------- | ||
// Kleisli config | ||
// ------------------------------------------------------------------------------------- | ||
/** | ||
* @internal | ||
*/ | ||
export var SE = | ||
/*#__PURE__*/ | ||
DE.getSemigroup(); | ||
/** | ||
* @internal | ||
*/ | ||
export var ap = function (fab, fa) { | ||
return E.isLeft(fab) | ||
? E.isLeft(fa) | ||
? E.left(SE.concat(fab.left, fa.left)) | ||
: fab | ||
: E.isLeft(fa) | ||
? fa | ||
: E.right(fab.right(fa.right)); | ||
}; | ||
var M = { | ||
URI: E.URI, | ||
_E: undefined, | ||
map: function (fa, f) { return pipe(fa, E.map(f)); }, | ||
ap: ap, | ||
of: E.right, | ||
chain: function (ma, f) { return pipe(ma, E.chain(f)); }, | ||
throwError: E.left, | ||
bimap: function (fa, f, g) { return pipe(fa, E.bimap(f, g)); }, | ||
mapLeft: function (fa, f) { return pipe(fa, E.mapLeft(f)); }, | ||
alt: function (me, that) { | ||
if (E.isRight(me)) { | ||
return me; | ||
} | ||
var ea = that(); | ||
return E.isLeft(ea) ? E.left(SE.concat(me.left, ea.left)) : ea; | ||
} | ||
}; | ||
/** | ||
* @category DecodeError | ||
* @since 2.2.7 | ||
*/ | ||
export var error = KD.error; | ||
export var error = function (actual, message) { return FS.of(DE.leaf(actual, message)); }; | ||
/** | ||
@@ -17,3 +56,3 @@ * @category DecodeError | ||
*/ | ||
export var success = KD.success; | ||
export var success = E.right; | ||
/** | ||
@@ -23,3 +62,5 @@ * @category DecodeError | ||
*/ | ||
export var failure = KD.failure; | ||
export var failure = function (actual, message) { | ||
return E.left(error(actual, message)); | ||
}; | ||
// ------------------------------------------------------------------------------------- | ||
@@ -30,10 +71,21 @@ // constructors | ||
* @category constructors | ||
* @since 2.2.7 | ||
* @since 2.2.8 | ||
*/ | ||
export var fromGuard = function (guard, expected) { return KD.fromRefinement(guard.is, expected); }; | ||
export var fromRefinement = function (refinement, expected) { | ||
return K.fromRefinement(M)(refinement, function (u) { return error(u, expected); }); | ||
}; | ||
/** | ||
* @category constructors | ||
* @since 2.2.8 | ||
*/ | ||
export var fromGuard = function (guard, expected) { | ||
return fromRefinement(guard.is, expected); | ||
}; | ||
/** | ||
* @category constructors | ||
* @since 2.2.7 | ||
*/ | ||
export var literal = KD.literal; | ||
export var literal = | ||
/*#__PURE__*/ | ||
K.literal(M)(function (u, values) { return error(u, values.map(function (value) { return JSON.stringify(value); }).join(' | ')); }); | ||
// ------------------------------------------------------------------------------------- | ||
@@ -77,8 +129,2 @@ // primitives | ||
fromGuard(G.UnknownRecord, 'Record<string, unknown>'); | ||
/** | ||
* @internal | ||
*/ | ||
export var object = | ||
/*#__PURE__*/ | ||
fromGuard(G.object, 'object'); | ||
// ------------------------------------------------------------------------------------- | ||
@@ -91,3 +137,5 @@ // combinators | ||
*/ | ||
export var mapLeftWithInput = KD.mapLeftWithInput; | ||
export var mapLeftWithInput = | ||
/*#__PURE__*/ | ||
K.mapLeftWithInput(M); | ||
/** | ||
@@ -97,3 +145,3 @@ * @category combinators | ||
*/ | ||
export var refine = KD.refine; | ||
export var refine = function (refinement, id) { return K.refine(M)(refinement, function (a) { return error(a, id); }); }; | ||
/** | ||
@@ -103,3 +151,5 @@ * @category combinators | ||
*/ | ||
export var parse = KD.parse; | ||
export var parse = | ||
/*#__PURE__*/ | ||
K.parse(M); | ||
/** | ||
@@ -109,9 +159,23 @@ * @category combinators | ||
*/ | ||
export var nullable = KD.nullable; | ||
export var nullable = | ||
/*#__PURE__*/ | ||
K.nullable(M)(function (u, e) { return FS.concat(FS.of(DE.member(0, error(u, 'null'))), FS.of(DE.member(1, e))); }); | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
export var fromType = function (properties) { | ||
return K.fromType(M)(function (k, e) { return FS.of(DE.key(k, DE.required, e)); })(properties); | ||
}; | ||
/** | ||
* @category combinators | ||
* @since 2.2.7 | ||
*/ | ||
export var type = function (properties) { | ||
return pipe(object, compose(KD.type(properties))); | ||
export var type = function (properties) { return pipe(UnknownRecord, compose(fromType(properties))); }; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
export var fromPartial = function (properties) { | ||
return K.fromPartial(M)(function (k, e) { return FS.of(DE.key(k, DE.optional, e)); })(properties); | ||
}; | ||
@@ -122,4 +186,9 @@ /** | ||
*/ | ||
export var partial = function (properties) { | ||
return pipe(object, compose(KD.partial(properties))); | ||
export var partial = function (properties) { return pipe(UnknownRecord, compose(fromPartial(properties))); }; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
export var fromArray = function (item) { | ||
return K.fromArray(M)(function (i, e) { return FS.of(DE.index(i, DE.optional, e)); })(item); | ||
}; | ||
@@ -130,12 +199,32 @@ /** | ||
*/ | ||
export var array = function (items) { return pipe(UnknownArray, compose(KD.array(items))); }; | ||
export var array = function (item) { | ||
return pipe(UnknownArray, compose(fromArray(item))); | ||
}; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
export var fromRecord = function (codomain) { | ||
return K.fromRecord(M)(function (k, e) { return FS.of(DE.key(k, DE.optional, e)); })(codomain); | ||
}; | ||
/** | ||
* @category combinators | ||
* @since 2.2.7 | ||
*/ | ||
export var record = function (codomain) { | ||
return pipe(UnknownRecord, compose(KD.record(codomain))); | ||
return pipe(UnknownRecord, compose(fromRecord(codomain))); | ||
}; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
export var fromTuple = function () { | ||
var components = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
components[_i] = arguments[_i]; | ||
} | ||
return K.fromTuple(M)(function (i, e) { return FS.of(DE.index(i, DE.required, e)); }).apply(void 0, components); | ||
}; | ||
/** | ||
* @category combinators | ||
* @since 2.2.7 | ||
@@ -148,3 +237,3 @@ */ | ||
} | ||
return pipe(UnknownArray, compose(KD.tuple.apply(KD, components))); | ||
return pipe(UnknownArray, compose(fromTuple.apply(void 0, components))); | ||
}; | ||
@@ -155,3 +244,5 @@ /** | ||
*/ | ||
export var union = KD.union; | ||
export var union = | ||
/*#__PURE__*/ | ||
K.union(M)(function (i, e) { return FS.of(DE.member(i, e)); }); | ||
/** | ||
@@ -161,9 +252,13 @@ * @category combinators | ||
*/ | ||
export var intersect = KD.intersect; | ||
export var intersect = | ||
/*#__PURE__*/ | ||
K.intersect(M); | ||
/** | ||
* @category combinators | ||
* @since 2.2.7 | ||
* @since 2.2.8 | ||
*/ | ||
export var sum = function (tag) { return function (members) { | ||
return pipe(object, compose(KD.sum(tag)(members))); | ||
export var fromSum = function (tag) { return function (members) { | ||
return K.fromSum(M)(function (tag, value, keys) { | ||
return FS.of(DE.key(tag, DE.required, error(value, keys.length === 0 ? 'never' : keys.map(function (k) { return JSON.stringify(k); }).join(' | ')))); | ||
})(tag)(members); | ||
}; }; | ||
@@ -174,3 +269,3 @@ /** | ||
*/ | ||
export var lazy = KD.lazy; | ||
export var sum = function (tag) { return function (members) { return pipe(UnknownRecord, compose(fromSum(tag)(members))); }; }; | ||
/** | ||
@@ -180,3 +275,5 @@ * @category combinators | ||
*/ | ||
export var compose = KD.compose; | ||
export var lazy = | ||
/*#__PURE__*/ | ||
K.lazy(M)(function (id, e) { return FS.of(DE.lazy(id, e)); }); | ||
// ------------------------------------------------------------------------------------- | ||
@@ -187,2 +284,3 @@ // non-pipeables | ||
var alt_ = function (me, that) { return pipe(me, alt(that)); }; | ||
var compose_ = function (ab, la) { return pipe(la, compose(ab)); }; | ||
// ------------------------------------------------------------------------------------- | ||
@@ -195,3 +293,5 @@ // pipeables | ||
*/ | ||
export var map = KD.map; | ||
export var map = | ||
/*#__PURE__*/ | ||
K.map(M); | ||
/** | ||
@@ -201,3 +301,19 @@ * @category Alt | ||
*/ | ||
export var alt = KD.alt; | ||
export var alt = | ||
/*#__PURE__*/ | ||
K.alt(M); | ||
/** | ||
* @category Semigroupoid | ||
* @since 2.2.8 | ||
*/ | ||
export var compose = | ||
/*#__PURE__*/ | ||
K.compose(M); | ||
/** | ||
* @category Category | ||
* @since 2.2.8 | ||
*/ | ||
export var id = | ||
/*#__PURE__*/ | ||
K.id(M); | ||
// ------------------------------------------------------------------------------------- | ||
@@ -213,5 +329,5 @@ // instances | ||
* @category instances | ||
* @since 2.2.7 | ||
* @since 2.2.8 | ||
*/ | ||
export var functorDecoder = { | ||
export var Functor = { | ||
URI: URI, | ||
@@ -222,5 +338,5 @@ map: map_ | ||
* @category instances | ||
* @since 2.2.7 | ||
* @since 2.2.8 | ||
*/ | ||
export var altDecoder = { | ||
export var Alt = { | ||
URI: URI, | ||
@@ -232,6 +348,15 @@ map: map_, | ||
* @category instances | ||
* @since 2.2.7 | ||
* @since 2.2.8 | ||
*/ | ||
export var schemableDecoder = { | ||
export var Category = { | ||
URI: URI, | ||
compose: compose_, | ||
id: id | ||
}; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
export var Schemable = { | ||
URI: URI, | ||
literal: literal, | ||
@@ -249,6 +374,24 @@ string: string, | ||
sum: sum, | ||
lazy: lazy, | ||
lazy: lazy | ||
}; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
export var WithUnknownContainers = { | ||
UnknownArray: UnknownArray, | ||
UnknownRecord: UnknownRecord, | ||
union: union, | ||
UnknownRecord: UnknownRecord | ||
}; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
export var WithUnion = { | ||
union: union | ||
}; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
export var WithRefine = { | ||
refine: refine | ||
@@ -255,0 +398,0 @@ }; |
@@ -21,7 +21,2 @@ /** | ||
/** | ||
* @category constructors | ||
* @since 2.2.3 | ||
*/ | ||
export declare function id<A>(): Encoder<A, A>; | ||
/** | ||
* @category combinators | ||
@@ -58,3 +53,3 @@ * @since 2.2.3 | ||
*/ | ||
export declare function array<O, A>(items: Encoder<O, A>): Encoder<Array<O>, Array<A>>; | ||
export declare function array<O, A>(item: Encoder<O, A>): Encoder<Array<O>, Array<A>>; | ||
/** | ||
@@ -95,2 +90,7 @@ * @category combinators | ||
/** | ||
* @category Category | ||
* @since 2.2.3 | ||
*/ | ||
export declare function id<A>(): Encoder<A, A>; | ||
/** | ||
* @category instances | ||
@@ -112,10 +112,10 @@ * @since 2.2.3 | ||
* @category instances | ||
* @since 2.2.3 | ||
* @since 2.2.8 | ||
*/ | ||
export declare const contravariantEncoder: Contravariant2<URI>; | ||
export declare const Contravariant: Contravariant2<URI>; | ||
/** | ||
* @category instances | ||
* @since 2.2.3 | ||
* @since 2.2.8 | ||
*/ | ||
export declare const categoryEncoder: Category2<URI>; | ||
export declare const Category: Category2<URI>; | ||
/** | ||
@@ -122,0 +122,0 @@ * @since 2.2.3 |
import { memoize, intersect_ } from './Schemable'; | ||
import { identity } from 'fp-ts/es6/function'; | ||
// ------------------------------------------------------------------------------------- | ||
// constructors | ||
// ------------------------------------------------------------------------------------- | ||
/** | ||
* @category constructors | ||
* @since 2.2.3 | ||
*/ | ||
export function id() { | ||
return { | ||
encode: identity | ||
}; | ||
} | ||
// ------------------------------------------------------------------------------------- | ||
// combinators | ||
@@ -81,5 +69,5 @@ // ------------------------------------------------------------------------------------- | ||
*/ | ||
export function array(items) { | ||
export function array(item) { | ||
return { | ||
encode: function (as) { return as.map(items.encode); } | ||
encode: function (as) { return as.map(item.encode); } | ||
}; | ||
@@ -129,2 +117,9 @@ } | ||
// ------------------------------------------------------------------------------------- | ||
// non-pipeables | ||
// ------------------------------------------------------------------------------------- | ||
var contramap_ = function (ea, f) { return ({ | ||
encode: function (b) { return ea.encode(f(b)); } | ||
}); }; | ||
var compose_ = function (ab, ea) { return contramap_(ea, ab.encode); }; | ||
// ------------------------------------------------------------------------------------- | ||
// pipeables | ||
@@ -139,5 +134,2 @@ // ------------------------------------------------------------------------------------- | ||
}; }; | ||
var contramap_ = function (fa, f) { return ({ | ||
encode: function (b) { return fa.encode(f(b)); } | ||
}); }; | ||
/** | ||
@@ -150,5 +142,11 @@ * @category Semigroupoid | ||
}; }; | ||
var compose_ = function (ab, ea) { return ({ | ||
encode: function (b) { return ea.encode(ab.encode(b)); } | ||
}); }; | ||
/** | ||
* @category Category | ||
* @since 2.2.3 | ||
*/ | ||
export function id() { | ||
return { | ||
encode: identity | ||
}; | ||
} | ||
// ------------------------------------------------------------------------------------- | ||
@@ -164,5 +162,5 @@ // instances | ||
* @category instances | ||
* @since 2.2.3 | ||
* @since 2.2.8 | ||
*/ | ||
export var contravariantEncoder = { | ||
export var Contravariant = { | ||
URI: URI, | ||
@@ -173,5 +171,5 @@ contramap: contramap_ | ||
* @category instances | ||
* @since 2.2.3 | ||
* @since 2.2.8 | ||
*/ | ||
export var categoryEncoder = { | ||
export var Category = { | ||
URI: URI, | ||
@@ -178,0 +176,0 @@ compose: compose_, |
@@ -96,4 +96,14 @@ import * as E from 'fp-ts/es6/Eq'; | ||
* @category instances | ||
* @since 2.2.3 | ||
* @since 2.2.8 | ||
*/ | ||
export declare const schemableEq: Schemable1<E.URI> & WithUnknownContainers1<E.URI> & WithRefine1<E.URI>; | ||
export declare const Schemable: Schemable1<E.URI>; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
export declare const WithUnknownContainers: WithUnknownContainers1<E.URI>; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
export declare const WithRefine: WithRefine1<E.URI>; |
@@ -145,5 +145,5 @@ /** | ||
* @category instances | ||
* @since 2.2.3 | ||
* @since 2.2.8 | ||
*/ | ||
export var schemableEq = { | ||
export var Schemable = { | ||
URI: E.URI, | ||
@@ -162,6 +162,18 @@ literal: function () { return E.eqStrict; }, | ||
sum: sum, | ||
lazy: function (_, f) { return lazy(f); }, | ||
lazy: function (_, f) { return lazy(f); } | ||
}; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
export var WithUnknownContainers = { | ||
UnknownArray: UnknownArray, | ||
UnknownRecord: UnknownRecord, | ||
UnknownRecord: UnknownRecord | ||
}; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
export var WithRefine = { | ||
refine: function () { return function (from) { return from; }; } | ||
}; |
import { Literal, Schemable1, WithRefine1, WithUnion1, WithUnknownContainers1 } from './Schemable'; | ||
/** | ||
* @category model | ||
* @since 2.2.0 | ||
* @since 2.2.8 | ||
*/ | ||
export interface Guard<A> { | ||
is: (u: unknown) => u is A; | ||
export interface Guard<I, A extends I> { | ||
is: (i: I) => i is A; | ||
} | ||
@@ -12,8 +12,12 @@ /** | ||
*/ | ||
export declare type TypeOf<G> = G extends Guard<infer A> ? A : never; | ||
export declare type TypeOf<G> = G extends Guard<any, infer A> ? A : never; | ||
/** | ||
* @since 2.2.8 | ||
*/ | ||
export declare type InputOf<G> = G extends Guard<infer I, any> ? I : never; | ||
/** | ||
* @category constructors | ||
* @since 2.2.0 | ||
*/ | ||
export declare const literal: <A extends readonly [Literal, ...Literal[]]>(...values: A) => Guard<A[number]>; | ||
export declare const literal: <A extends readonly [Literal, ...Literal[]]>(...values: A) => Guard<unknown, A[number]>; | ||
/** | ||
@@ -23,3 +27,3 @@ * @category primitives | ||
*/ | ||
export declare const string: Guard<string>; | ||
export declare const string: Guard<unknown, string>; | ||
/** | ||
@@ -31,3 +35,3 @@ * Note: `NaN` is excluded. | ||
*/ | ||
export declare const number: Guard<number>; | ||
export declare const number: Guard<unknown, number>; | ||
/** | ||
@@ -37,3 +41,3 @@ * @category primitives | ||
*/ | ||
export declare const boolean: Guard<boolean>; | ||
export declare const boolean: Guard<unknown, boolean>; | ||
/** | ||
@@ -43,3 +47,3 @@ * @category primitives | ||
*/ | ||
export declare const UnknownArray: Guard<Array<unknown>>; | ||
export declare const UnknownArray: Guard<unknown, Array<unknown>>; | ||
/** | ||
@@ -49,3 +53,3 @@ * @category primitives | ||
*/ | ||
export declare const UnknownRecord: Guard<Record<string, unknown>>; | ||
export declare const UnknownRecord: Guard<unknown, Record<string, unknown>>; | ||
/** | ||
@@ -55,3 +59,3 @@ * @category combinators | ||
*/ | ||
export declare const refine: <A, B extends A>(refinement: (a: A) => a is B) => (from: Guard<A>) => Guard<B>; | ||
export declare const refine: <I, A extends I, B extends A>(refinement: (a: A) => a is B) => (from: Guard<I, A>) => Guard<I, B>; | ||
/** | ||
@@ -61,3 +65,3 @@ * @category combinators | ||
*/ | ||
export declare const nullable: <A>(or: Guard<A>) => Guard<A | null>; | ||
export declare const nullable: <I, A extends I>(or: Guard<I, A>) => Guard<I | null, A | null>; | ||
/** | ||
@@ -67,3 +71,3 @@ * @category combinators | ||
*/ | ||
export declare const type: <A>(properties: { [K in keyof A]: Guard<A[K]>; }) => Guard<{ [K_1 in keyof A]: A[K_1]; }>; | ||
export declare const type: <A>(properties: { [K in keyof A]: Guard<unknown, A[K]>; }) => Guard<unknown, { [K_1 in keyof A]: A[K_1]; }>; | ||
/** | ||
@@ -73,3 +77,3 @@ * @category combinators | ||
*/ | ||
export declare const partial: <A>(properties: { [K in keyof A]: Guard<A[K]>; }) => Guard<Partial<{ [K_1 in keyof A]: A[K_1]; }>>; | ||
export declare const partial: <A>(properties: { [K in keyof A]: Guard<unknown, A[K]>; }) => Guard<unknown, Partial<{ [K_1 in keyof A]: A[K_1]; }>>; | ||
/** | ||
@@ -79,3 +83,3 @@ * @category combinators | ||
*/ | ||
export declare const record: <A>(codomain: Guard<A>) => Guard<Record<string, A>>; | ||
export declare const array: <A>(item: Guard<unknown, A>) => Guard<unknown, A[]>; | ||
/** | ||
@@ -85,3 +89,3 @@ * @category combinators | ||
*/ | ||
export declare const array: <A>(items: Guard<A>) => Guard<A[]>; | ||
export declare const record: <A>(codomain: Guard<unknown, A>) => Guard<unknown, Record<string, A>>; | ||
/** | ||
@@ -91,3 +95,3 @@ * @category combinators | ||
*/ | ||
export declare const tuple: <A extends readonly unknown[]>(...components: { [K in keyof A]: Guard<A[K]>; }) => Guard<A>; | ||
export declare const tuple: <A extends readonly unknown[]>(...components: { [K in keyof A]: Guard<unknown, A[K]>; }) => Guard<unknown, A>; | ||
/** | ||
@@ -97,3 +101,3 @@ * @category combinators | ||
*/ | ||
export declare const intersect: <B>(right: Guard<B>) => <A>(left: Guard<A>) => Guard<A & B>; | ||
export declare const intersect: <B>(right: Guard<unknown, B>) => <A>(left: Guard<unknown, A>) => Guard<unknown, A & B>; | ||
/** | ||
@@ -103,3 +107,3 @@ * @category combinators | ||
*/ | ||
export declare const union: <A extends readonly [unknown, ...unknown[]]>(...members: { [K in keyof A]: Guard<A[K]>; }) => Guard<A[number]>; | ||
export declare const union: <A extends readonly [unknown, ...unknown[]]>(...members: { [K in keyof A]: Guard<unknown, A[K]>; }) => Guard<unknown, A[number]>; | ||
/** | ||
@@ -109,3 +113,3 @@ * @category combinators | ||
*/ | ||
export declare const sum: <T extends string>(tag: T) => <A>(members: { [K in keyof A]: Guard<A[K]>; }) => Guard<A[keyof A]>; | ||
export declare const sum: <T extends string>(tag: T) => <A>(members: { [K in keyof A]: Guard<unknown, A[K]>; }) => Guard<unknown, A[keyof A]>; | ||
/** | ||
@@ -115,4 +119,24 @@ * @category combinators | ||
*/ | ||
export declare const lazy: <A>(f: () => Guard<A>) => Guard<A>; | ||
export declare const lazy: <A>(f: () => Guard<unknown, A>) => Guard<unknown, A>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
export declare const alt: <I, A extends I>(that: () => Guard<I, A>) => (me: Guard<I, A>) => Guard<I, A>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
export declare const zero: <I, A extends I>() => Guard<I, A>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
export declare const compose: <I, A extends I, B extends A>(to: Guard<A, B>) => (from: Guard<I, A>) => Guard<I, B>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
export declare const id: <A>() => Guard<A, A>; | ||
/** | ||
* @category instances | ||
@@ -129,3 +153,3 @@ * @since 2.2.0 | ||
interface URItoKind<A> { | ||
readonly [URI]: Guard<A>; | ||
readonly [URI]: Guard<unknown, A>; | ||
} | ||
@@ -135,4 +159,19 @@ } | ||
* @category instances | ||
* @since 2.2.3 | ||
* @since 2.2.8 | ||
*/ | ||
export declare const schemableGuard: Schemable1<URI> & WithUnknownContainers1<URI> & WithUnion1<URI> & WithRefine1<URI>; | ||
export declare const Schemable: Schemable1<URI>; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
export declare const WithUnknownContainers: WithUnknownContainers1<URI>; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
export declare const WithUnion: WithUnion1<URI>; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
export declare const WithRefine: WithRefine1<URI>; |
@@ -69,8 +69,2 @@ /** | ||
}; | ||
/** | ||
* @internal | ||
*/ | ||
export var object = { | ||
is: function (u) { return u != null && !string.is(u) && !number.is(u) && !boolean.is(u); } | ||
}; | ||
// ------------------------------------------------------------------------------------- | ||
@@ -84,3 +78,3 @@ // combinators | ||
export var refine = function (refinement) { return function (from) { return ({ | ||
is: function (u) { return from.is(u) && refinement(u); } | ||
is: function (i) { return from.is(i) && refinement(i); } | ||
}); }; }; | ||
@@ -92,3 +86,3 @@ /** | ||
export var nullable = function (or) { return ({ | ||
is: function (u) { return u === null || or.is(u); } | ||
is: function (i) { return i === null || or.is(i); } | ||
}); }; | ||
@@ -128,2 +122,9 @@ /** | ||
*/ | ||
export var array = function (item) { | ||
return pipe(UnknownArray, refine(function (us) { return us.every(item.is); })); | ||
}; | ||
/** | ||
* @category combinators | ||
* @since 2.2.0 | ||
*/ | ||
export var record = function (codomain) { | ||
@@ -143,9 +144,2 @@ return pipe(UnknownRecord, refine(function (r) { | ||
*/ | ||
export var array = function (items) { | ||
return pipe(UnknownArray, refine(function (us) { return us.every(items.is); })); | ||
}; | ||
/** | ||
* @category combinators | ||
* @since 2.2.0 | ||
*/ | ||
export var tuple = function () { | ||
@@ -203,2 +197,30 @@ var components = []; | ||
}; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
export var alt = function (that) { return function (me) { return ({ | ||
is: function (i) { return me.is(i) || that().is(i); } | ||
}); }; }; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
export var zero = function () { return ({ | ||
is: function (_) { return false; } | ||
}); }; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
export var compose = function (to) { return function (from) { return ({ | ||
is: function (i) { return from.is(i) && to.is(i); } | ||
}); }; }; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
export var id = function () { return ({ | ||
is: function (_) { return true; } | ||
}); }; | ||
// ------------------------------------------------------------------------------------- | ||
@@ -214,5 +236,5 @@ // instances | ||
* @category instances | ||
* @since 2.2.3 | ||
* @since 2.2.8 | ||
*/ | ||
export var schemableGuard = { | ||
export var Schemable = { | ||
URI: URI, | ||
@@ -231,7 +253,25 @@ literal: literal, | ||
sum: sum, | ||
lazy: function (_, f) { return lazy(f); }, | ||
lazy: function (_, f) { return lazy(f); } | ||
}; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
export var WithUnknownContainers = { | ||
UnknownArray: UnknownArray, | ||
UnknownRecord: UnknownRecord, | ||
union: union, | ||
UnknownRecord: UnknownRecord | ||
}; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
export var WithUnion = { | ||
union: union | ||
}; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
export var WithRefine = { | ||
refine: refine | ||
}; |
@@ -59,14 +59,6 @@ /** | ||
/** | ||
* @since 2.2.7 | ||
*/ | ||
export declare type TypeOf<M extends URIS2, KD> = KD extends Kleisli<M, any, any, infer A> ? A : never; | ||
/** | ||
* @since 2.2.7 | ||
*/ | ||
export declare type InputOf<M extends URIS2, KD> = KD extends Kleisli<M, infer I, any, any> ? I : never; | ||
/** | ||
* @category combinators | ||
* @since 2.2.7 | ||
*/ | ||
export declare function type<M extends URIS2, E>(M: Applicative2C<M, E> & Bifunctor2<M>): (onPropertyError: (key: string, e: E) => E) => <P extends Record<string, Kleisli<M, any, E, any>>>(properties: P) => Kleisli<M, { | ||
export declare function fromType<M extends URIS2, E>(M: Applicative2C<M, E> & Bifunctor2<M>): (onPropertyError: (key: string, e: E) => E) => <P extends Record<string, Kleisli<M, any, E, any>>>(properties: P) => Kleisli<M, { | ||
[K in keyof P]: InputOf<M, P[K]>; | ||
@@ -80,5 +72,5 @@ }, E, { | ||
*/ | ||
export declare function partial<M extends URIS2, E>(M: Applicative2C<M, E> & Bifunctor2<M>): (onPropertyError: (key: string, e: E) => E) => <P extends Record<string, Kleisli<M, any, E, any>>>(properties: P) => Kleisli<M, { | ||
export declare function fromPartial<M extends URIS2, E>(M: Applicative2C<M, E> & Bifunctor2<M>): (onPropertyError: (key: string, e: E) => E) => <P extends Record<string, Kleisli<M, any, E, any>>>(properties: P) => Kleisli<M, Partial<{ | ||
[K in keyof P]: InputOf<M, P[K]>; | ||
}, E, Partial<{ | ||
}>, E, Partial<{ | ||
[K in keyof P]: TypeOf<M, P[K]>; | ||
@@ -90,3 +82,3 @@ }>>; | ||
*/ | ||
export declare function array<M extends URIS2, E>(M: Applicative2C<M, E> & Bifunctor2<M>): (onItemError: (index: number, e: E) => E) => <I, A>(items: Kleisli<M, I, E, A>) => Kleisli<M, Array<I>, E, Array<A>>; | ||
export declare function fromArray<M extends URIS2, E>(M: Applicative2C<M, E> & Bifunctor2<M>): (onItemError: (index: number, e: E) => E) => <I, A>(item: Kleisli<M, I, E, A>) => Kleisli<M, Array<I>, E, Array<A>>; | ||
/** | ||
@@ -96,3 +88,3 @@ * @category combinators | ||
*/ | ||
export declare function record<M extends URIS2, E>(M: Applicative2C<M, E> & Bifunctor2<M>): (onKeyError: (key: string, e: E) => E) => <I, A>(codomain: Kleisli<M, I, E, A>) => Kleisli<M, Record<string, I>, E, Record<string, A>>; | ||
export declare function fromRecord<M extends URIS2, E>(M: Applicative2C<M, E> & Bifunctor2<M>): (onKeyError: (key: string, e: E) => E) => <I, A>(codomain: Kleisli<M, I, E, A>) => Kleisli<M, Record<string, I>, E, Record<string, A>>; | ||
/** | ||
@@ -102,3 +94,3 @@ * @category combinators | ||
*/ | ||
export declare function tuple<M extends URIS2, E>(M: Applicative2C<M, E> & Bifunctor2<M>): (onIndexError: (index: number, e: E) => E) => <C extends ReadonlyArray<Kleisli<M, any, E, any>>>(...components: C) => Kleisli<M, { | ||
export declare function fromTuple<M extends URIS2, E>(M: Applicative2C<M, E> & Bifunctor2<M>): (onIndexError: (index: number, e: E) => E) => <C extends ReadonlyArray<Kleisli<M, any, E, any>>>(...components: C) => Kleisli<M, { | ||
[K in keyof C]: InputOf<M, C[K]>; | ||
@@ -122,3 +114,3 @@ }, E, { | ||
*/ | ||
export declare function sum<M extends URIS2, E>(M: MonadThrow2C<M, E>): (onTagError: (tag: string, value: unknown, tags: ReadonlyArray<string>) => E) => <T extends string>(tag: T) => <MS extends Record<string, Kleisli<M, any, E, any>>>(members: MS) => Kleisli<M, InputOf<M, MS[keyof MS]>, E, TypeOf<M, MS[keyof MS]>>; | ||
export declare function fromSum<M extends URIS2, E>(M: MonadThrow2C<M, E>): (onTagError: (tag: string, value: unknown, tags: ReadonlyArray<string>) => E) => <T extends string>(tag: T) => <MS extends Record<string, Kleisli<M, any, E, any>>>(members: MS) => Kleisli<M, InputOf<M, MS[keyof MS]>, E, TypeOf<M, MS[keyof MS]>>; | ||
/** | ||
@@ -136,2 +128,7 @@ * @category combinators | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
export declare function id<M extends URIS2, E>(M: Applicative2C<M, E>): <A>() => Kleisli<M, A, E, A>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.7 | ||
@@ -145,1 +142,9 @@ */ | ||
export declare function alt<F extends URIS2, E>(A: Alt2C<F, E>): <I, A>(that: Lazy<Kleisli<F, I, E, A>>) => (me: Kleisli<F, I, E, A>) => Kleisli<F, I, E, A>; | ||
/** | ||
* @since 2.2.7 | ||
*/ | ||
export declare type TypeOf<M extends URIS2, KD> = KD extends Kleisli<M, any, any, infer A> ? A : never; | ||
/** | ||
* @since 2.2.7 | ||
*/ | ||
export declare type InputOf<M extends URIS2, KD> = KD extends Kleisli<M, infer I, any, any> ? I : never; |
@@ -74,3 +74,3 @@ import * as E from 'fp-ts/es6/Either'; | ||
*/ | ||
export function type(M) { | ||
export function fromType(M) { | ||
var traverse = traverseRecordWithIndex(M); | ||
@@ -89,3 +89,3 @@ return function (onPropertyError) { return function (properties) { return ({ | ||
*/ | ||
export function partial(M) { | ||
export function fromPartial(M) { | ||
var traverse = traverseRecordWithIndex(M); | ||
@@ -114,6 +114,6 @@ var undefinedProperty = M.of(E.right(undefined)); | ||
*/ | ||
export function array(M) { | ||
export function fromArray(M) { | ||
var traverse = traverseArrayWithIndex(M); | ||
return function (onItemError) { return function (items) { return ({ | ||
decode: function (is) { return traverse(is, function (index, i) { return M.mapLeft(items.decode(i), function (e) { return onItemError(index, e); }); }); } | ||
return function (onItemError) { return function (item) { return ({ | ||
decode: function (is) { return traverse(is, function (index, i) { return M.mapLeft(item.decode(i), function (e) { return onItemError(index, e); }); }); } | ||
}); }; }; | ||
@@ -125,3 +125,3 @@ } | ||
*/ | ||
export function record(M) { | ||
export function fromRecord(M) { | ||
var traverse = traverseRecordWithIndex(M); | ||
@@ -136,3 +136,3 @@ return function (onKeyError) { return function (codomain) { return ({ | ||
*/ | ||
export function tuple(M) { | ||
export function fromTuple(M) { | ||
var traverse = traverseArrayWithIndex(M); | ||
@@ -192,3 +192,3 @@ return function (onIndexError) { return function () { | ||
*/ | ||
export function sum(M) { | ||
export function fromSum(M) { | ||
return function (onTagError) { return function (tag) { return function (members) { | ||
@@ -230,2 +230,11 @@ var keys = Object.keys(members); | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
export function id(M) { | ||
return function () { return ({ | ||
decode: M.of | ||
}); }; | ||
} | ||
/** | ||
* @category combinators | ||
* @since 2.2.7 | ||
@@ -232,0 +241,0 @@ */ |
@@ -11,4 +11,4 @@ /** | ||
*/ | ||
import { HKT, URIS, Kind } from 'fp-ts/es6/HKT'; | ||
import { Schemable, Schemable1 } from './Schemable'; | ||
import { HKT, Kind, Kind2, URIS, URIS2 } from 'fp-ts/es6/HKT'; | ||
import { Schemable, Schemable1, Schemable2C } from './Schemable'; | ||
/** | ||
@@ -33,2 +33,5 @@ * @category model | ||
*/ | ||
export declare function interpreter<S extends URIS>(S: Schemable1<S>): <A>(schema: Schema<A>) => Kind<S, A>; | ||
export declare const interpreter: { | ||
<S extends URIS2>(S: Schemable2C<S, unknown>): <A>(schema: Schema<A>) => Kind2<S, unknown, A>; | ||
<S extends URIS>(S: Schemable1<S>): <A>(schema: Schema<A>) => Kind<S, A>; | ||
}; |
@@ -15,4 +15,2 @@ import { memoize } from './Schemable'; | ||
*/ | ||
export function interpreter(S) { | ||
return function (schema) { return schema(S); }; | ||
} | ||
export var interpreter = function (S) { return function (schema) { return schema(S); }; }; |
@@ -11,3 +11,3 @@ /** | ||
*/ | ||
import { Kind, URIS, HKT } from 'fp-ts/es6/HKT'; | ||
import { HKT, Kind, Kind2, URIS, URIS2 } from 'fp-ts/es6/HKT'; | ||
/** | ||
@@ -38,3 +38,3 @@ * @since 2.2.0 | ||
readonly record: <A>(codomain: HKT<S, A>) => HKT<S, Record<string, A>>; | ||
readonly array: <A>(items: HKT<S, A>) => HKT<S, Array<A>>; | ||
readonly array: <A>(item: HKT<S, A>) => HKT<S, Array<A>>; | ||
readonly tuple: <A extends ReadonlyArray<unknown>>(...components: { | ||
@@ -70,3 +70,3 @@ [K in keyof A]: HKT<S, A[K]>; | ||
readonly record: <A>(codomain: Kind<S, A>) => Kind<S, Record<string, A>>; | ||
readonly array: <A>(items: Kind<S, A>) => Kind<S, Array<A>>; | ||
readonly array: <A>(item: Kind<S, A>) => Kind<S, Array<A>>; | ||
readonly tuple: <A extends ReadonlyArray<unknown>>(...components: { | ||
@@ -82,2 +82,33 @@ [K in keyof A]: Kind<S, A[K]>; | ||
/** | ||
* @since 2.2.8 | ||
*/ | ||
export interface Schemable2C<S extends URIS2, E> { | ||
readonly URI: S; | ||
readonly literal: <A extends readonly [Literal, ...Array<Literal>]>(...values: A) => Kind2<S, E, A[number]>; | ||
readonly string: Kind2<S, E, string>; | ||
readonly number: Kind2<S, E, number>; | ||
readonly boolean: Kind2<S, E, boolean>; | ||
readonly nullable: <A>(or: Kind2<S, E, A>) => Kind2<S, E, null | A>; | ||
readonly type: <A>(properties: { | ||
[K in keyof A]: Kind2<S, E, A[K]>; | ||
}) => Kind2<S, E, { | ||
[K in keyof A]: A[K]; | ||
}>; | ||
readonly partial: <A>(properties: { | ||
[K in keyof A]: Kind2<S, E, A[K]>; | ||
}) => Kind2<S, E, Partial<{ | ||
[K in keyof A]: A[K]; | ||
}>>; | ||
readonly record: <A>(codomain: Kind2<S, E, A>) => Kind2<S, E, Record<string, A>>; | ||
readonly array: <A>(item: Kind2<S, E, A>) => Kind2<S, E, Array<A>>; | ||
readonly tuple: <A extends ReadonlyArray<unknown>>(...components: { | ||
[K in keyof A]: Kind2<S, E, A[K]>; | ||
}) => Kind2<S, E, A>; | ||
readonly intersect: <B>(right: Kind2<S, E, B>) => <A>(left: Kind2<S, E, A>) => Kind2<S, E, A & B>; | ||
readonly sum: <T extends string>(tag: T) => <A>(members: { | ||
[K in keyof A]: Kind2<S, E, A[K]>; | ||
}) => Kind2<S, E, A[keyof A]>; | ||
readonly lazy: <A>(id: string, f: () => Kind2<S, E, A>) => Kind2<S, E, A>; | ||
} | ||
/** | ||
* @since 2.2.3 | ||
@@ -97,2 +128,9 @@ */ | ||
/** | ||
* @since 2.2.8 | ||
*/ | ||
export interface WithUnknownContainers2C<S extends URIS2, E> { | ||
readonly UnknownArray: Kind2<S, E, Array<unknown>>; | ||
readonly UnknownRecord: Kind2<S, E, Record<string, unknown>>; | ||
} | ||
/** | ||
* @since 2.2.3 | ||
@@ -114,2 +152,10 @@ */ | ||
/** | ||
* @since 2.2.8 | ||
*/ | ||
export interface WithUnion2C<S extends URIS2, E> { | ||
readonly union: <A extends readonly [unknown, ...Array<unknown>]>(...members: { | ||
[K in keyof A]: Kind2<S, E, A[K]>; | ||
}) => Kind2<S, E, A[number]>; | ||
} | ||
/** | ||
* @since 2.2.3 | ||
@@ -127,4 +173,10 @@ */ | ||
/** | ||
* @since 2.2.8 | ||
*/ | ||
export interface WithRefine2C<S extends URIS2, E> { | ||
readonly refine: <A, B extends A>(refinement: (a: A) => a is B, id: string) => (from: Kind2<S, E, A>) => Kind2<S, E, B>; | ||
} | ||
/** | ||
* @since 2.2.0 | ||
*/ | ||
export declare function memoize<A, B>(f: (a: A) => B): (a: A) => B; |
@@ -11,14 +11,18 @@ /** | ||
*/ | ||
import { Alt1 } from 'fp-ts/es6/Alt'; | ||
import { Functor1 } from 'fp-ts/es6/Functor'; | ||
import { Alt2 } from 'fp-ts/es6/Alt'; | ||
import { Category2 } from 'fp-ts/es6/Category'; | ||
import { Refinement } from 'fp-ts/es6/function'; | ||
import { Functor2 } from 'fp-ts/es6/Functor'; | ||
import * as TE from 'fp-ts/es6/TaskEither'; | ||
import * as DE from './DecodeError'; | ||
import * as D from './Decoder'; | ||
import * as FS from './FreeSemigroup'; | ||
import * as G from './Guard'; | ||
import * as KTD from './KleisliTaskDecoder'; | ||
import { Literal, Schemable1, WithRefine1, WithUnion1, WithUnknownContainers1 } from './Schemable'; | ||
import * as K from './Kleisli'; | ||
import * as S from './Schemable'; | ||
/** | ||
* @category model | ||
* @since 2.2.7 | ||
* @since 2.2.8 | ||
*/ | ||
export interface TaskDecoder<A> extends KTD.KleisliTaskDecoder<unknown, A> { | ||
export interface TaskDecoder<I, A> extends K.Kleisli<TE.URI, I, DecodeError, A> { | ||
} | ||
@@ -44,3 +48,3 @@ /** | ||
*/ | ||
export declare const failure: <A = never>(actual: unknown, message: string) => TE.TaskEither<DecodeError, A>; | ||
export declare const failure: <A = never>(actual: unknown, message: string) => TE.TaskEither<FS.FreeSemigroup<DE.DecodeError<string>>, A>; | ||
/** | ||
@@ -50,8 +54,13 @@ * @category constructors | ||
*/ | ||
export declare const fromDecoder: <A>(decoder: D.Decoder<A>) => TaskDecoder<A>; | ||
export declare const fromDecoder: <I, A>(decoder: D.Decoder<I, A>) => TaskDecoder<I, A>; | ||
/** | ||
* @category constructors | ||
* @since 2.2.8 | ||
*/ | ||
export declare const fromRefinement: <I, A extends I>(refinement: Refinement<I, A>, expected: string) => TaskDecoder<I, A>; | ||
/** | ||
* @category constructors | ||
* @since 2.2.7 | ||
*/ | ||
export declare const fromGuard: <A>(guard: G.Guard<A>, expected: string) => TaskDecoder<A>; | ||
export declare const fromGuard: <I, A extends I>(guard: G.Guard<I, A>, expected: string) => TaskDecoder<I, A>; | ||
/** | ||
@@ -61,3 +70,3 @@ * @category constructors | ||
*/ | ||
export declare const literal: <A extends readonly [Literal, ...Array<Literal>]>(...values: A) => TaskDecoder<A[number]>; | ||
export declare const literal: <A extends readonly [S.Literal, ...Array<S.Literal>]>(...values: A) => TaskDecoder<unknown, A[number]>; | ||
/** | ||
@@ -67,3 +76,3 @@ * @category primitives | ||
*/ | ||
export declare const string: TaskDecoder<string>; | ||
export declare const string: TaskDecoder<unknown, string>; | ||
/** | ||
@@ -73,3 +82,3 @@ * @category primitives | ||
*/ | ||
export declare const number: TaskDecoder<number>; | ||
export declare const number: TaskDecoder<unknown, number>; | ||
/** | ||
@@ -79,3 +88,3 @@ * @category primitives | ||
*/ | ||
export declare const boolean: TaskDecoder<boolean>; | ||
export declare const boolean: TaskDecoder<unknown, boolean>; | ||
/** | ||
@@ -85,3 +94,3 @@ * @category primitives | ||
*/ | ||
export declare const UnknownArray: TaskDecoder<Array<unknown>>; | ||
export declare const UnknownArray: TaskDecoder<unknown, Array<unknown>>; | ||
/** | ||
@@ -91,3 +100,3 @@ * @category primitives | ||
*/ | ||
export declare const UnknownRecord: TaskDecoder<Record<string, unknown>>; | ||
export declare const UnknownRecord: TaskDecoder<unknown, Record<string, unknown>>; | ||
/** | ||
@@ -97,3 +106,3 @@ * @category combinators | ||
*/ | ||
export declare const mapLeftWithInput: (f: (input: unknown, e: DecodeError) => DecodeError) => <A>(decoder: TaskDecoder<A>) => TaskDecoder<A>; | ||
export declare const mapLeftWithInput: <I>(f: (input: I, e: DecodeError) => DecodeError) => <A>(decoder: TaskDecoder<I, A>) => TaskDecoder<I, A>; | ||
/** | ||
@@ -103,3 +112,3 @@ * @category combinators | ||
*/ | ||
export declare const refine: <A, B extends A>(refinement: (a: A) => a is B, id: string) => (from: TaskDecoder<A>) => TaskDecoder<B>; | ||
export declare const refine: <A, B extends A>(refinement: (a: A) => a is B, id: string) => <I>(from: TaskDecoder<I, A>) => TaskDecoder<I, B>; | ||
/** | ||
@@ -109,3 +118,3 @@ * @category combinators | ||
*/ | ||
export declare const parse: <A, B>(parser: (a: A) => TE.TaskEither<DecodeError, B>) => (from: TaskDecoder<A>) => TaskDecoder<B>; | ||
export declare const parse: <A, B>(parser: (a: A) => TE.TaskEither<DecodeError, B>) => <I>(from: TaskDecoder<I, A>) => TaskDecoder<I, B>; | ||
/** | ||
@@ -115,8 +124,8 @@ * @category combinators | ||
*/ | ||
export declare const nullable: <A>(or: TaskDecoder<A>) => TaskDecoder<null | A>; | ||
export declare const nullable: <I, A>(or: TaskDecoder<I, A>) => TaskDecoder<null | I, null | A>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.7 | ||
* @since 2.2.8 | ||
*/ | ||
export declare const type: <A>(properties: { [K in keyof A]: TaskDecoder<A[K]>; }) => TaskDecoder<{ [K_1 in keyof A]: A[K_1]; }>; | ||
export declare const fromType: <P extends Record<string, TaskDecoder<any, any>>>(properties: P) => TaskDecoder<{ [K in keyof P]: K.InputOf<"TaskEither", P[K]>; }, { [K_1 in keyof P]: K.TypeOf<"TaskEither", P[K_1]>; }>; | ||
/** | ||
@@ -126,25 +135,43 @@ * @category combinators | ||
*/ | ||
export declare const partial: <A>(properties: { [K in keyof A]: TaskDecoder<A[K]>; }) => TaskDecoder<Partial<{ [K_1 in keyof A]: A[K_1]; }>>; | ||
export declare const type: <A>(properties: { [K in keyof A]: TaskDecoder<unknown, A[K]>; }) => TaskDecoder<unknown, { [K_1 in keyof A]: A[K_1]; }>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
export declare const fromPartial: <P extends Record<string, TaskDecoder<any, any>>>(properties: P) => TaskDecoder<Partial<{ [K in keyof P]: K.InputOf<"TaskEither", P[K]>; }>, Partial<{ [K_1 in keyof P]: K.TypeOf<"TaskEither", P[K_1]>; }>>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.7 | ||
*/ | ||
export declare const array: <A>(items: TaskDecoder<A>) => TaskDecoder<A[]>; | ||
export declare const partial: <A>(properties: { [K in keyof A]: TaskDecoder<unknown, A[K]>; }) => TaskDecoder<unknown, Partial<{ [K_1 in keyof A]: A[K_1]; }>>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
export declare const fromArray: <I, A>(item: TaskDecoder<I, A>) => TaskDecoder<I[], A[]>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.7 | ||
*/ | ||
export declare const record: <A>(codomain: TaskDecoder<A>) => TaskDecoder<Record<string, A>>; | ||
export declare const array: <A>(item: TaskDecoder<unknown, A>) => TaskDecoder<unknown, A[]>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
export declare const fromRecord: <I, A>(codomain: TaskDecoder<I, A>) => TaskDecoder<Record<string, I>, Record<string, A>>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.7 | ||
*/ | ||
export declare const tuple: <A extends readonly unknown[]>(...components: { [K in keyof A]: TaskDecoder<A[K]>; }) => TaskDecoder<A>; | ||
export declare const record: <A>(codomain: TaskDecoder<unknown, A>) => TaskDecoder<unknown, Record<string, A>>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
export declare const fromTuple: <C extends readonly TaskDecoder<any, any>[]>(...components: C) => TaskDecoder<{ [K in keyof C]: K.InputOf<"TaskEither", C[K]>; }, { [K_1 in keyof C]: K.TypeOf<"TaskEither", C[K_1]>; }>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.7 | ||
*/ | ||
export declare const union: <A extends readonly [unknown, ...Array<unknown>]>(...members: { | ||
[K in keyof A]: TaskDecoder<A[K]>; | ||
}) => TaskDecoder<A[number]>; | ||
export declare const tuple: <A extends readonly unknown[]>(...components: { [K in keyof A]: TaskDecoder<unknown, A[K]>; }) => TaskDecoder<unknown, A>; | ||
/** | ||
@@ -154,3 +181,3 @@ * @category combinators | ||
*/ | ||
export declare const intersect: <B>(right: TaskDecoder<B>) => <A>(left: TaskDecoder<A>) => TaskDecoder<A & B>; | ||
export declare const union: <MS extends readonly [TaskDecoder<any, any>, ...Array<TaskDecoder<any, any>>]>(...members: MS) => TaskDecoder<InputOf<MS[keyof MS]>, TypeOf<MS[keyof MS]>>; | ||
/** | ||
@@ -160,8 +187,13 @@ * @category combinators | ||
*/ | ||
export declare const sum: <T extends string>(tag: T) => <A>(members: { [K in keyof A]: TaskDecoder<A[K]>; }) => TaskDecoder<A[keyof A]>; | ||
export declare const intersect: <IB, B>(right: TaskDecoder<IB, B>) => <IA, A>(left: TaskDecoder<IA, A>) => TaskDecoder<IA & IB, A & B>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
export declare const fromSum: <T extends string>(tag: T) => <MS extends Record<string, TaskDecoder<any, any>>>(members: MS) => TaskDecoder<K.InputOf<"TaskEither", MS[keyof MS]>, K.TypeOf<"TaskEither", MS[keyof MS]>>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.7 | ||
*/ | ||
export declare const lazy: <A>(id: string, f: () => TaskDecoder<A>) => TaskDecoder<A>; | ||
export declare const sum: <T extends string>(tag: T) => <A>(members: { [K in keyof A]: TaskDecoder<unknown, A[K]>; }) => TaskDecoder<unknown, A[keyof A]>; | ||
/** | ||
@@ -171,3 +203,3 @@ * @category combinators | ||
*/ | ||
export declare const compose: <A, B>(to: KTD.KleisliTaskDecoder<A, B>) => (from: TaskDecoder<A>) => TaskDecoder<B>; | ||
export declare const lazy: <I, A>(id: string, f: () => TaskDecoder<I, A>) => TaskDecoder<I, A>; | ||
/** | ||
@@ -177,3 +209,3 @@ * @category Functor | ||
*/ | ||
export declare const map: <A, B>(f: (a: A) => B) => (fa: TaskDecoder<A>) => TaskDecoder<B>; | ||
export declare const map: <A, B>(f: (a: A) => B) => <I>(fa: TaskDecoder<I, A>) => TaskDecoder<I, B>; | ||
/** | ||
@@ -183,4 +215,14 @@ * @category Alt | ||
*/ | ||
export declare const alt: <A>(that: () => TaskDecoder<A>) => (me: TaskDecoder<A>) => TaskDecoder<A>; | ||
export declare const alt: <I, A>(that: () => TaskDecoder<I, A>) => (me: TaskDecoder<I, A>) => TaskDecoder<I, A>; | ||
/** | ||
* @category Semigroupoid | ||
* @since 2.2.8 | ||
*/ | ||
export declare const compose: <A, B>(to: TaskDecoder<A, B>) => <I>(from: TaskDecoder<I, A>) => TaskDecoder<I, B>; | ||
/** | ||
* @category Category | ||
* @since 2.2.8 | ||
*/ | ||
export declare const id: <A>() => TaskDecoder<A, A>; | ||
/** | ||
* @category instances | ||
@@ -196,4 +238,4 @@ * @since 2.2.7 | ||
declare module 'fp-ts/es6/HKT' { | ||
interface URItoKind<A> { | ||
readonly [URI]: TaskDecoder<A>; | ||
interface URItoKind2<E, A> { | ||
readonly [URI]: TaskDecoder<E, A>; | ||
} | ||
@@ -203,22 +245,46 @@ } | ||
* @category instances | ||
* @since 2.2.7 | ||
* @since 2.2.8 | ||
*/ | ||
export declare const functorTaskDecoder: Functor1<URI>; | ||
export declare const Functor: Functor2<URI>; | ||
/** | ||
* @category instances | ||
* @since 2.2.7 | ||
* @since 2.2.8 | ||
*/ | ||
export declare const altTaskDecoder: Alt1<URI>; | ||
export declare const Alt: Alt2<URI>; | ||
/** | ||
* @category instances | ||
* @since 2.2.7 | ||
* @since 2.2.8 | ||
*/ | ||
export declare const schemableTaskDecoder: Schemable1<URI> & WithUnknownContainers1<URI> & WithUnion1<URI> & WithRefine1<URI>; | ||
export declare const Category: Category2<URI>; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
export declare const Schemable: S.Schemable2C<URI, unknown>; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
export declare const WithUnknownContainers: S.WithUnknownContainers2C<URI, unknown>; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
export declare const WithUnion: S.WithUnion2C<URI, unknown>; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
export declare const WithRefine: S.WithRefine2C<URI, unknown>; | ||
/** | ||
* @since 2.2.7 | ||
*/ | ||
export declare type TypeOf<TD> = KTD.TypeOf<TD>; | ||
export declare type TypeOf<KTD> = K.TypeOf<TE.URI, KTD>; | ||
/** | ||
* @since 2.2.8 | ||
*/ | ||
export declare type InputOf<KTD> = K.InputOf<TE.URI, KTD>; | ||
/** | ||
* @since 2.2.7 | ||
*/ | ||
export declare const draw: (e: DecodeError) => string; |
@@ -0,6 +1,32 @@ | ||
import * as E from 'fp-ts/es6/Either'; | ||
import { pipe } from 'fp-ts/es6/pipeable'; | ||
import * as T from 'fp-ts/es6/Task'; | ||
import * as TE from 'fp-ts/es6/TaskEither'; | ||
import * as DE from './DecodeError'; | ||
import * as D from './Decoder'; | ||
import * as KTD from './KleisliTaskDecoder'; | ||
import * as FS from './FreeSemigroup'; | ||
import * as K from './Kleisli'; | ||
// ------------------------------------------------------------------------------------- | ||
// Kleisli config | ||
// ------------------------------------------------------------------------------------- | ||
var M = { | ||
URI: TE.URI, | ||
_E: undefined, | ||
map: function (fa, f) { return pipe(fa, TE.map(f)); }, | ||
ap: function (fab, fa) { | ||
return pipe(pipe(fab, T.map(function (h) { return function (ga) { return D.ap(h, ga); }; })), T.ap(fa)); | ||
}, | ||
of: TE.right, | ||
chain: function (ma, f) { return pipe(ma, TE.chain(f)); }, | ||
throwError: TE.left, | ||
bimap: function (fa, f, g) { return pipe(fa, TE.bimap(f, g)); }, | ||
mapLeft: function (fa, f) { return pipe(fa, TE.mapLeft(f)); }, | ||
alt: function (me, that) { | ||
return pipe(me, T.chain(function (e1) { | ||
return E.isRight(e1) | ||
? T.of(e1) | ||
: pipe(that(), T.map(function (e2) { return (E.isLeft(e2) ? E.left(D.SE.concat(e1.left, e2.left)) : e2); })); | ||
})); | ||
} | ||
}; | ||
/** | ||
@@ -15,3 +41,3 @@ * @category DecodeError | ||
*/ | ||
export var success = KTD.success; | ||
export var success = TE.right; | ||
/** | ||
@@ -21,3 +47,5 @@ * @category DecodeError | ||
*/ | ||
export var failure = KTD.failure; | ||
export var failure = function (actual, message) { | ||
return TE.left(D.error(actual, message)); | ||
}; | ||
// ------------------------------------------------------------------------------------- | ||
@@ -30,9 +58,18 @@ // constructors | ||
*/ | ||
export var fromDecoder = KTD.fromKleisliDecoder; | ||
export var fromDecoder = function (decoder) { return ({ | ||
decode: TE.fromEitherK(decoder.decode) | ||
}); }; | ||
/** | ||
* @category constructors | ||
* @since 2.2.8 | ||
*/ | ||
export var fromRefinement = function (refinement, expected) { | ||
return fromDecoder(D.fromRefinement(refinement, expected)); | ||
}; | ||
/** | ||
* @category constructors | ||
* @since 2.2.7 | ||
*/ | ||
export var fromGuard = function (guard, expected) { | ||
return KTD.fromRefinement(guard.is, expected); | ||
return fromRefinement(guard.is, expected); | ||
}; | ||
@@ -43,3 +80,5 @@ /** | ||
*/ | ||
export var literal = KTD.literal; | ||
export var literal = | ||
/*#__PURE__*/ | ||
K.literal(M)(function (u, values) { return error(u, values.map(function (value) { return JSON.stringify(value); }).join(' | ')); }); | ||
// ------------------------------------------------------------------------------------- | ||
@@ -83,8 +122,2 @@ // primitives | ||
fromDecoder(D.UnknownRecord); | ||
/** | ||
* @internal | ||
*/ | ||
export var object = | ||
/*#__PURE__*/ | ||
fromDecoder(D.object); | ||
// ------------------------------------------------------------------------------------- | ||
@@ -97,3 +130,5 @@ // combinators | ||
*/ | ||
export var mapLeftWithInput = KTD.mapLeftWithInput; | ||
export var mapLeftWithInput = | ||
/*#__PURE__*/ | ||
K.mapLeftWithInput(M); | ||
/** | ||
@@ -103,3 +138,3 @@ * @category combinators | ||
*/ | ||
export var refine = KTD.refine; | ||
export var refine = function (refinement, id) { return K.refine(M)(refinement, function (a) { return error(a, id); }); }; | ||
/** | ||
@@ -109,3 +144,5 @@ * @category combinators | ||
*/ | ||
export var parse = KTD.parse; | ||
export var parse = | ||
/*#__PURE__*/ | ||
K.parse(M); | ||
/** | ||
@@ -115,9 +152,23 @@ * @category combinators | ||
*/ | ||
export var nullable = KTD.nullable; | ||
export var nullable = | ||
/*#__PURE__*/ | ||
K.nullable(M)(function (u, e) { return FS.concat(FS.of(DE.member(0, error(u, 'null'))), FS.of(DE.member(1, e))); }); | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
export var fromType = function (properties) { | ||
return K.fromType(M)(function (k, e) { return FS.of(DE.key(k, DE.required, e)); })(properties); | ||
}; | ||
/** | ||
* @category combinators | ||
* @since 2.2.7 | ||
*/ | ||
export var type = function (properties) { | ||
return pipe(object, compose(KTD.type(properties))); | ||
export var type = function (properties) { return pipe(UnknownRecord, compose(fromType(properties))); }; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
export var fromPartial = function (properties) { | ||
return K.fromPartial(M)(function (k, e) { return FS.of(DE.key(k, DE.optional, e)); })(properties); | ||
}; | ||
@@ -128,17 +179,46 @@ /** | ||
*/ | ||
export var partial = function (properties) { return pipe(object, compose(KTD.partial(properties))); }; | ||
export var partial = function (properties) { | ||
return pipe(UnknownRecord, compose(fromPartial(properties))); | ||
}; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
export var fromArray = function (item) { | ||
return K.fromArray(M)(function (i, e) { return FS.of(DE.index(i, DE.optional, e)); })(item); | ||
}; | ||
/** | ||
* @category combinators | ||
* @since 2.2.7 | ||
*/ | ||
export var array = function (items) { return pipe(UnknownArray, compose(KTD.array(items))); }; | ||
export var array = function (item) { | ||
return pipe(UnknownArray, compose(fromArray(item))); | ||
}; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
export var fromRecord = function (codomain) { | ||
return K.fromRecord(M)(function (k, e) { return FS.of(DE.key(k, DE.optional, e)); })(codomain); | ||
}; | ||
/** | ||
* @category combinators | ||
* @since 2.2.7 | ||
*/ | ||
export var record = function (codomain) { | ||
return pipe(UnknownRecord, compose(KTD.record(codomain))); | ||
return pipe(UnknownRecord, compose(fromRecord(codomain))); | ||
}; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
export var fromTuple = function () { | ||
var components = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
components[_i] = arguments[_i]; | ||
} | ||
return K.fromTuple(M)(function (i, e) { return FS.of(DE.index(i, DE.required, e)); }).apply(void 0, components); | ||
}; | ||
/** | ||
* @category combinators | ||
* @since 2.2.7 | ||
@@ -151,3 +231,3 @@ */ | ||
} | ||
return pipe(UnknownArray, compose(KTD.tuple.apply(KTD, components))); | ||
return pipe(UnknownArray, compose(fromTuple.apply(void 0, components))); | ||
}; | ||
@@ -158,3 +238,5 @@ /** | ||
*/ | ||
export var union = KTD.union; | ||
export var union = | ||
/*#__PURE__*/ | ||
K.union(M)(function (i, e) { return FS.of(DE.member(i, e)); }); | ||
/** | ||
@@ -164,8 +246,14 @@ * @category combinators | ||
*/ | ||
export var intersect = KTD.intersect; | ||
export var intersect = | ||
/*#__PURE__*/ | ||
K.intersect(M); | ||
/** | ||
* @category combinators | ||
* @since 2.2.7 | ||
* @since 2.2.8 | ||
*/ | ||
export var sum = function (tag) { return function (members) { return pipe(object, compose(KTD.sum(tag)(members))); }; }; | ||
export var fromSum = function (tag) { return function (members) { | ||
return K.fromSum(M)(function (tag, value, keys) { | ||
return FS.of(DE.key(tag, DE.required, error(value, keys.length === 0 ? 'never' : keys.map(function (k) { return JSON.stringify(k); }).join(' | ')))); | ||
})(tag)(members); | ||
}; }; | ||
/** | ||
@@ -175,3 +263,3 @@ * @category combinators | ||
*/ | ||
export var lazy = KTD.lazy; | ||
export var sum = function (tag) { return function (members) { return pipe(UnknownRecord, compose(fromSum(tag)(members))); }; }; | ||
/** | ||
@@ -181,3 +269,5 @@ * @category combinators | ||
*/ | ||
export var compose = KTD.compose; | ||
export var lazy = | ||
/*#__PURE__*/ | ||
K.lazy(M)(function (id, e) { return FS.of(DE.lazy(id, e)); }); | ||
// ------------------------------------------------------------------------------------- | ||
@@ -188,2 +278,3 @@ // non-pipeables | ||
var alt_ = function (me, that) { return pipe(me, alt(that)); }; | ||
var compose_ = function (ab, la) { return pipe(la, compose(ab)); }; | ||
// ------------------------------------------------------------------------------------- | ||
@@ -196,3 +287,5 @@ // pipeables | ||
*/ | ||
export var map = KTD.map; | ||
export var map = | ||
/*#__PURE__*/ | ||
K.map(M); | ||
/** | ||
@@ -202,3 +295,19 @@ * @category Alt | ||
*/ | ||
export var alt = KTD.alt; | ||
export var alt = | ||
/*#__PURE__*/ | ||
K.alt(M); | ||
/** | ||
* @category Semigroupoid | ||
* @since 2.2.8 | ||
*/ | ||
export var compose = | ||
/*#__PURE__*/ | ||
K.compose(M); | ||
/** | ||
* @category Category | ||
* @since 2.2.8 | ||
*/ | ||
export var id = | ||
/*#__PURE__*/ | ||
K.id(M); | ||
// ------------------------------------------------------------------------------------- | ||
@@ -214,5 +323,5 @@ // instances | ||
* @category instances | ||
* @since 2.2.7 | ||
* @since 2.2.8 | ||
*/ | ||
export var functorTaskDecoder = { | ||
export var Functor = { | ||
URI: URI, | ||
@@ -223,5 +332,5 @@ map: map_ | ||
* @category instances | ||
* @since 2.2.7 | ||
* @since 2.2.8 | ||
*/ | ||
export var altTaskDecoder = { | ||
export var Alt = { | ||
URI: URI, | ||
@@ -233,6 +342,15 @@ map: map_, | ||
* @category instances | ||
* @since 2.2.7 | ||
* @since 2.2.8 | ||
*/ | ||
export var schemableTaskDecoder = { | ||
export var Category = { | ||
URI: URI, | ||
compose: compose_, | ||
id: id | ||
}; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
export var Schemable = { | ||
URI: URI, | ||
literal: literal, | ||
@@ -250,6 +368,24 @@ string: string, | ||
sum: sum, | ||
lazy: lazy, | ||
lazy: lazy | ||
}; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
export var WithUnknownContainers = { | ||
UnknownArray: UnknownArray, | ||
UnknownRecord: UnknownRecord, | ||
union: union, | ||
UnknownRecord: UnknownRecord | ||
}; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
export var WithUnion = { | ||
union: union | ||
}; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
export var WithRefine = { | ||
refine: refine | ||
@@ -256,0 +392,0 @@ }; |
@@ -78,3 +78,3 @@ /** | ||
*/ | ||
export declare const array: <A>(items: Type<A>) => Type<A[]>; | ||
export declare const array: <A>(item: Type<A>) => Type<A[]>; | ||
/** | ||
@@ -122,4 +122,19 @@ * @category combinators | ||
* @category instances | ||
* @since 2.2.3 | ||
* @since 2.2.8 | ||
*/ | ||
export declare const schemableType: Schemable1<URI> & WithUnknownContainers1<URI> & WithUnion1<URI> & WithRefine1<URI>; | ||
export declare const Schemable: Schemable1<URI>; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
export declare const WithUnknownContainers: WithUnknownContainers1<URI>; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
export declare const WithUnion: WithUnion1<URI>; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
export declare const WithRefine: WithRefine1<URI>; |
@@ -97,3 +97,3 @@ /** | ||
*/ | ||
export var array = function (items) { return t.array(items); }; | ||
export var array = function (item) { return t.array(item); }; | ||
/** | ||
@@ -148,5 +148,5 @@ * @category combinators | ||
* @category instances | ||
* @since 2.2.3 | ||
* @since 2.2.8 | ||
*/ | ||
export var schemableType = { | ||
export var Schemable = { | ||
URI: URI, | ||
@@ -165,7 +165,25 @@ literal: literal, | ||
sum: sum, | ||
lazy: lazy, | ||
lazy: lazy | ||
}; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
export var WithUnknownContainers = { | ||
UnknownArray: UnknownArray, | ||
UnknownRecord: UnknownRecord, | ||
union: union, | ||
UnknownRecord: UnknownRecord | ||
}; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
export var WithUnion = { | ||
union: union | ||
}; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
export var WithRefine = { | ||
refine: refine | ||
}; |
@@ -1,12 +0,2 @@ | ||
/** | ||
* **This module is experimental** | ||
* | ||
* Experimental features are published in order to get early feedback from the community, see these tracking | ||
* [issues](https://github.com/gcanti/io-ts/issues?q=label%3Av2.2+) for further discussions and enhancements. | ||
* | ||
* A feature tagged as _Experimental_ is in a high state of flux, you're at risk of it changing without notice. | ||
* | ||
* @since 2.2.3 | ||
*/ | ||
import { Invariant2 } from 'fp-ts/lib/Invariant'; | ||
import { Invariant3 } from 'fp-ts/lib/Invariant'; | ||
import * as D from './Decoder'; | ||
@@ -24,17 +14,9 @@ import * as E from './Encoder'; | ||
*/ | ||
export interface Codec<O, A> extends D.Decoder<A>, E.Encoder<O, A> { | ||
export interface Codec<I, O, A> extends D.Decoder<I, A>, E.Encoder<O, A> { | ||
} | ||
/** | ||
* @since 2.2.3 | ||
*/ | ||
export declare type TypeOf<C> = E.TypeOf<C>; | ||
/** | ||
* @since 2.2.3 | ||
*/ | ||
export declare type OutputOf<C> = E.OutputOf<C>; | ||
/** | ||
* @category constructors | ||
* @since 2.2.3 | ||
*/ | ||
export declare function make<O, A>(decoder: D.Decoder<A>, encoder: E.Encoder<O, A>): Codec<O, A>; | ||
export declare function make<I, O, A>(decoder: D.Decoder<I, A>, encoder: E.Encoder<O, A>): Codec<I, O, A>; | ||
/** | ||
@@ -44,3 +26,3 @@ * @category constructors | ||
*/ | ||
export declare function fromDecoder<A>(decoder: D.Decoder<A>): Codec<A, A>; | ||
export declare function fromDecoder<I, A>(decoder: D.Decoder<I, A>): Codec<I, A, A>; | ||
/** | ||
@@ -50,3 +32,3 @@ * @category constructors | ||
*/ | ||
export declare function literal<A extends readonly [Literal, ...Array<Literal>]>(...values: A): Codec<A[number], A[number]>; | ||
export declare function literal<A extends readonly [Literal, ...Array<Literal>]>(...values: A): Codec<unknown, A[number], A[number]>; | ||
/** | ||
@@ -56,3 +38,3 @@ * @category primitives | ||
*/ | ||
export declare const string: Codec<string, string>; | ||
export declare const string: Codec<unknown, string, string>; | ||
/** | ||
@@ -62,3 +44,3 @@ * @category primitives | ||
*/ | ||
export declare const number: Codec<number, number>; | ||
export declare const number: Codec<unknown, number, number>; | ||
/** | ||
@@ -68,3 +50,3 @@ * @category primitives | ||
*/ | ||
export declare const boolean: Codec<boolean, boolean>; | ||
export declare const boolean: Codec<unknown, boolean, boolean>; | ||
/** | ||
@@ -74,3 +56,3 @@ * @category primitives | ||
*/ | ||
export declare const UnknownArray: Codec<Array<unknown>, Array<unknown>>; | ||
export declare const UnknownArray: Codec<unknown, Array<unknown>, Array<unknown>>; | ||
/** | ||
@@ -80,3 +62,3 @@ * @category primitives | ||
*/ | ||
export declare const UnknownRecord: Codec<Record<string, unknown>, Record<string, unknown>>; | ||
export declare const UnknownRecord: Codec<unknown, Record<string, unknown>, Record<string, unknown>>; | ||
/** | ||
@@ -86,3 +68,3 @@ * @category combinators | ||
*/ | ||
export declare const mapLeftWithInput: (f: (actual: unknown, e: D.DecodeError) => D.DecodeError) => <O, A>(codec: Codec<O, A>) => Codec<O, A>; | ||
export declare const mapLeftWithInput: <I>(f: (i: I, e: D.DecodeError) => D.DecodeError) => <O, A>(codec: Codec<I, O, A>) => Codec<I, O, A>; | ||
/** | ||
@@ -92,3 +74,3 @@ * @category combinators | ||
*/ | ||
export declare const refine: <A, B extends A>(refinement: (a: A) => a is B, id: string) => <O>(from: Codec<O, A>) => Codec<O, B>; | ||
export declare const refine: <A, B extends A>(refinement: (a: A) => a is B, id: string) => <I, O>(from: Codec<I, O, A>) => Codec<I, O, B>; | ||
/** | ||
@@ -98,8 +80,19 @@ * @category combinators | ||
*/ | ||
export declare function nullable<O, A>(or: Codec<O, A>): Codec<null | O, null | A>; | ||
export declare function nullable<I, O, A>(or: Codec<I, O, A>): Codec<null | I, null | O, null | A>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
export declare function fromType<P extends Record<string, Codec<any, any, any>>>(properties: P): Codec<{ | ||
[K in keyof P]: InputOf<P[K]>; | ||
}, { | ||
[K in keyof P]: OutputOf<P[K]>; | ||
}, { | ||
[K in keyof P]: TypeOf<P[K]>; | ||
}>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.3 | ||
*/ | ||
export declare function type<P extends Record<string, Codec<any, any>>>(properties: P): Codec<{ | ||
export declare function type<P extends Record<string, Codec<unknown, any, any>>>(properties: P): Codec<unknown, { | ||
[K in keyof P]: OutputOf<P[K]>; | ||
@@ -111,5 +104,16 @@ }, { | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
export declare function fromPartial<P extends Record<string, Codec<any, any, any>>>(properties: P): Codec<Partial<{ | ||
[K in keyof P]: InputOf<P[K]>; | ||
}>, Partial<{ | ||
[K in keyof P]: OutputOf<P[K]>; | ||
}>, Partial<{ | ||
[K in keyof P]: TypeOf<P[K]>; | ||
}>>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.3 | ||
*/ | ||
export declare function partial<P extends Record<string, Codec<any, any>>>(properties: P): Codec<Partial<{ | ||
export declare function partial<P extends Record<string, Codec<unknown, any, any>>>(properties: P): Codec<unknown, Partial<{ | ||
[K in keyof P]: OutputOf<P[K]>; | ||
@@ -123,3 +127,3 @@ }>, Partial<{ | ||
*/ | ||
export declare function record<O, A>(codomain: Codec<O, A>): Codec<Record<string, O>, Record<string, A>>; | ||
export declare function fromArray<I, O, A>(item: Codec<I, O, A>): Codec<Array<I>, Array<O>, Array<A>>; | ||
/** | ||
@@ -129,3 +133,3 @@ * @category combinators | ||
*/ | ||
export declare function array<O, A>(items: Codec<O, A>): Codec<Array<O>, Array<A>>; | ||
export declare function array<O, A>(item: Codec<unknown, O, A>): Codec<unknown, Array<O>, Array<A>>; | ||
/** | ||
@@ -135,3 +139,18 @@ * @category combinators | ||
*/ | ||
export declare function tuple<C extends ReadonlyArray<Codec<any, any>>>(...components: C): Codec<{ | ||
export declare function fromRecord<I, O, A>(codomain: Codec<I, O, A>): Codec<Record<string, I>, Record<string, O>, Record<string, A>>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.3 | ||
*/ | ||
export declare function record<O, A>(codomain: Codec<unknown, O, A>): Codec<unknown, Record<string, O>, Record<string, A>>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
export declare const fromTuple: <C extends readonly Codec<any, any, any>[]>(...components: C) => Codec<{ [K in keyof C]: import("./Kleisli").InputOf<"Either", C[K]>; }, { [K_1 in keyof C]: E.OutputOf<C[K_1]>; }, { [K_2 in keyof C]: E.TypeOf<C[K_2]>; }>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.3 | ||
*/ | ||
export declare function tuple<C extends ReadonlyArray<Codec<unknown, any, any>>>(...components: C): Codec<unknown, { | ||
[K in keyof C]: OutputOf<C[K]>; | ||
@@ -145,8 +164,13 @@ }, { | ||
*/ | ||
export declare const intersect: <P, B>(right: Codec<P, B>) => <O, A>(left: Codec<O, A>) => Codec<O & P, A & B>; | ||
export declare const intersect: <IB, OB, B>(right: Codec<IB, OB, B>) => <IA, OA, A>(left: Codec<IA, OA, A>) => Codec<IA & IB, OA & OB, A & B>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
export declare const fromSum: <T extends string>(tag: T) => <MS extends Record<string, Codec<any, any, any>>>(members: MS) => Codec<import("./Kleisli").InputOf<"Either", MS[keyof MS]>, E.OutputOf<MS[keyof MS]>, E.TypeOf<MS[keyof MS]>>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.3 | ||
*/ | ||
export declare function sum<T extends string>(tag: T): <M extends Record<string, Codec<any, any>>>(members: M) => Codec<OutputOf<M[keyof M]>, TypeOf<M[keyof M]>>; | ||
export declare function sum<T extends string>(tag: T): <M extends Record<string, Codec<unknown, any, any>>>(members: M) => Codec<unknown, OutputOf<M[keyof M]>, TypeOf<M[keyof M]>>; | ||
/** | ||
@@ -156,8 +180,13 @@ * @category combinators | ||
*/ | ||
export declare function lazy<O, A>(id: string, f: () => Codec<O, A>): Codec<O, A>; | ||
export declare function lazy<I, O, A>(id: string, f: () => Codec<I, O, A>): Codec<I, O, A>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
export declare const compose: <L, A extends L, P extends A, B>(to: Codec<L, P, B>) => <I, O>(from: Codec<I, O, A>) => Codec<I, O, B>; | ||
/** | ||
* @category Invariant | ||
* @since 2.2.3 | ||
*/ | ||
export declare const imap: <E, A, B>(f: (a: A) => B, g: (b: B) => A) => (fa: Codec<E, A>) => Codec<E, B>; | ||
export declare const imap: <I, O, A, B>(f: (a: A) => B, g: (b: B) => A) => (fa: Codec<I, O, A>) => Codec<I, O, B>; | ||
/** | ||
@@ -174,4 +203,4 @@ * @category instances | ||
declare module 'fp-ts/lib/HKT' { | ||
interface URItoKind2<E, A> { | ||
readonly [URI]: Codec<E, A>; | ||
interface URItoKind3<R, E, A> { | ||
readonly [URI]: Codec<R, E, A>; | ||
} | ||
@@ -181,4 +210,16 @@ } | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
export declare const Invariant: Invariant3<URI>; | ||
/** | ||
* @since 2.2.8 | ||
*/ | ||
export declare type InputOf<C> = D.InputOf<C>; | ||
/** | ||
* @since 2.2.3 | ||
*/ | ||
export declare const invariantCodec: Invariant2<URI>; | ||
export declare type OutputOf<C> = E.OutputOf<C>; | ||
/** | ||
* @since 2.2.3 | ||
*/ | ||
export declare type TypeOf<C> = E.TypeOf<C>; |
134
lib/Codec.js
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.invariantCodec = exports.URI = exports.imap = exports.lazy = exports.sum = exports.intersect = exports.tuple = exports.array = exports.record = exports.partial = exports.type = exports.nullable = exports.refine = exports.mapLeftWithInput = exports.UnknownRecord = exports.UnknownArray = exports.boolean = exports.number = exports.string = exports.literal = exports.fromDecoder = exports.make = void 0; | ||
exports.Invariant = exports.URI = exports.imap = exports.compose = exports.lazy = exports.sum = exports.fromSum = exports.intersect = exports.tuple = exports.fromTuple = exports.record = exports.fromRecord = exports.array = exports.fromArray = exports.partial = exports.fromPartial = exports.type = exports.fromType = exports.nullable = exports.refine = exports.mapLeftWithInput = exports.UnknownRecord = exports.UnknownArray = exports.boolean = exports.number = exports.string = exports.literal = exports.fromDecoder = exports.make = void 0; | ||
/** | ||
* **This module is experimental** | ||
* | ||
* Experimental features are published in order to get early feedback from the community, see these tracking | ||
* [issues](https://github.com/gcanti/io-ts/issues?q=label%3Av2.2+) for further discussions and enhancements. | ||
* | ||
* A feature tagged as _Experimental_ is in a high state of flux, you're at risk of it changing without notice. | ||
* | ||
* @since 2.2.3 | ||
*/ | ||
var function_1 = require("fp-ts/lib/function"); | ||
var pipeable_1 = require("fp-ts/lib/pipeable"); | ||
var D = require("./Decoder"); | ||
var E = require("./Encoder"); | ||
var function_1 = require("fp-ts/lib/function"); | ||
var pipeable_1 = require("fp-ts/lib/pipeable"); | ||
// ------------------------------------------------------------------------------------- | ||
@@ -52,3 +62,5 @@ // constructors | ||
*/ | ||
exports.string = fromDecoder(D.string); | ||
exports.string = | ||
/*#__PURE__*/ | ||
fromDecoder(D.string); | ||
/** | ||
@@ -58,3 +70,5 @@ * @category primitives | ||
*/ | ||
exports.number = fromDecoder(D.number); | ||
exports.number = | ||
/*#__PURE__*/ | ||
fromDecoder(D.number); | ||
/** | ||
@@ -64,3 +78,5 @@ * @category primitives | ||
*/ | ||
exports.boolean = fromDecoder(D.boolean); | ||
exports.boolean = | ||
/*#__PURE__*/ | ||
fromDecoder(D.boolean); | ||
/** | ||
@@ -70,3 +86,5 @@ * @category primitives | ||
*/ | ||
exports.UnknownArray = fromDecoder(D.UnknownArray); | ||
exports.UnknownArray = | ||
/*#__PURE__*/ | ||
fromDecoder(D.UnknownArray); | ||
/** | ||
@@ -76,3 +94,5 @@ * @category primitives | ||
*/ | ||
exports.UnknownRecord = fromDecoder(D.UnknownRecord); | ||
exports.UnknownRecord = | ||
/*#__PURE__*/ | ||
fromDecoder(D.UnknownRecord); | ||
// ------------------------------------------------------------------------------------- | ||
@@ -104,7 +124,14 @@ // combinators | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
function fromType(properties) { | ||
return make(D.fromType(properties), E.type(properties)); | ||
} | ||
exports.fromType = fromType; | ||
/** | ||
* @category combinators | ||
* @since 2.2.3 | ||
*/ | ||
function type(properties) { | ||
var decoder = D.type(properties); | ||
return make(decoder, E.type(properties)); | ||
return pipeable_1.pipe(exports.UnknownRecord, exports.compose(fromType(properties))); | ||
} | ||
@@ -114,8 +141,14 @@ exports.type = type; | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
function fromPartial(properties) { | ||
return make(D.fromPartial(properties), E.partial(properties)); | ||
} | ||
exports.fromPartial = fromPartial; | ||
/** | ||
* @category combinators | ||
* @since 2.2.3 | ||
*/ | ||
function partial(properties) { | ||
// these two `any`s are required to make typescript@3.5 compile | ||
// vvvvvv vvvvvv | ||
return make(D.partial(properties), E.partial(properties)); | ||
return pipeable_1.pipe(exports.UnknownRecord, exports.compose(fromPartial(properties))); | ||
} | ||
@@ -127,6 +160,6 @@ exports.partial = partial; | ||
*/ | ||
function record(codomain) { | ||
return make(D.record(codomain), E.record(codomain)); | ||
function fromArray(item) { | ||
return make(D.fromArray(item), E.array(item)); | ||
} | ||
exports.record = record; | ||
exports.fromArray = fromArray; | ||
/** | ||
@@ -136,4 +169,4 @@ * @category combinators | ||
*/ | ||
function array(items) { | ||
return make(D.array(items), E.array(items)); | ||
function array(item) { | ||
return pipeable_1.pipe(exports.UnknownArray, exports.compose(fromArray(item))); | ||
} | ||
@@ -145,2 +178,29 @@ exports.array = array; | ||
*/ | ||
function fromRecord(codomain) { | ||
return make(D.fromRecord(codomain), E.record(codomain)); | ||
} | ||
exports.fromRecord = fromRecord; | ||
/** | ||
* @category combinators | ||
* @since 2.2.3 | ||
*/ | ||
function record(codomain) { | ||
return pipeable_1.pipe(exports.UnknownRecord, exports.compose(fromRecord(codomain))); | ||
} | ||
exports.record = record; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
exports.fromTuple = function () { | ||
var components = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
components[_i] = arguments[_i]; | ||
} | ||
return make(D.fromTuple.apply(D, components), E.tuple.apply(E, components)); | ||
}; | ||
/** | ||
* @category combinators | ||
* @since 2.2.3 | ||
*/ | ||
function tuple() { | ||
@@ -151,5 +211,3 @@ var components = []; | ||
} | ||
var decoder = D.tuple.apply(D, components); | ||
var encoder = E.tuple.apply(E, components); | ||
return make(decoder, encoder); | ||
return pipeable_1.pipe(exports.UnknownArray, exports.compose(exports.fromTuple.apply(void 0, components))); | ||
} | ||
@@ -168,8 +226,16 @@ exports.tuple = tuple; | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
exports.fromSum = function (tag) { | ||
var decoder = D.fromSum(tag); | ||
var encoder = E.sum(tag); | ||
return function (members) { return make(decoder(members), encoder(members)); }; | ||
}; | ||
/** | ||
* @category combinators | ||
* @since 2.2.3 | ||
*/ | ||
function sum(tag) { | ||
var sumD = D.sum(tag); | ||
var sumE = E.sum(tag); | ||
return function (members) { return make(sumD(members), sumE(members)); }; | ||
var sum = exports.fromSum(tag); | ||
return function (members) { return pipeable_1.pipe(exports.UnknownRecord, exports.compose(sum(members))); }; | ||
} | ||
@@ -185,3 +251,12 @@ exports.sum = sum; | ||
exports.lazy = lazy; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
exports.compose = function (to) { return function (from) { return make(D.compose(to)(from), E.compose(from)(to)); }; }; | ||
// ------------------------------------------------------------------------------------- | ||
// non-pipeables | ||
// ------------------------------------------------------------------------------------- | ||
var imap_ = function (fa, f, g) { return make(D.Functor.map(fa, f), E.Contravariant.contramap(fa, g)); }; | ||
// ------------------------------------------------------------------------------------- | ||
// pipeables | ||
@@ -193,8 +268,3 @@ // ------------------------------------------------------------------------------------- | ||
*/ | ||
exports.imap = function (f, g) { return function (fa) { | ||
return imap_(fa, f, g); | ||
}; }; | ||
var imap_ = function (fa, f, g) { | ||
return make(D.functorDecoder.map(fa, f), E.contravariantEncoder.contramap(fa, g)); | ||
}; | ||
exports.imap = function (f, g) { return function (fa) { return imap_(fa, f, g); }; }; | ||
// ------------------------------------------------------------------------------------- | ||
@@ -210,7 +280,7 @@ // instances | ||
* @category instances | ||
* @since 2.2.3 | ||
* @since 2.2.8 | ||
*/ | ||
exports.invariantCodec = { | ||
exports.Invariant = { | ||
URI: exports.URI, | ||
imap: imap_ | ||
}; |
@@ -11,13 +11,17 @@ /** | ||
*/ | ||
import { Alt1 } from 'fp-ts/lib/Alt'; | ||
import { Alt2 } from 'fp-ts/lib/Alt'; | ||
import { Category2 } from 'fp-ts/lib/Category'; | ||
import * as E from 'fp-ts/lib/Either'; | ||
import { Functor1 } from 'fp-ts/lib/Functor'; | ||
import { Refinement } from 'fp-ts/lib/function'; | ||
import { Functor2 } from 'fp-ts/lib/Functor'; | ||
import * as DE from './DecodeError'; | ||
import * as FS from './FreeSemigroup'; | ||
import * as G from './Guard'; | ||
import * as KD from './KleisliDecoder'; | ||
import { Literal, Schemable1, WithRefine1, WithUnion1, WithUnknownContainers1 } from './Schemable'; | ||
import * as K from './Kleisli'; | ||
import * as S from './Schemable'; | ||
/** | ||
* @category model | ||
* @since 2.2.7 | ||
* @since 2.2.8 | ||
*/ | ||
export interface Decoder<A> extends KD.KleisliDecoder<unknown, A> { | ||
export interface Decoder<I, A> extends K.Kleisli<E.URI, I, DecodeError, A> { | ||
} | ||
@@ -28,3 +32,3 @@ /** | ||
*/ | ||
export declare type DecodeError = KD.DecodeError; | ||
export declare type DecodeError = FS.FreeSemigroup<DE.DecodeError<string>>; | ||
/** | ||
@@ -44,13 +48,18 @@ * @category DecodeError | ||
*/ | ||
export declare const failure: <A = never>(actual: unknown, message: string) => E.Either<DecodeError, A>; | ||
export declare const failure: <A = never>(actual: unknown, message: string) => E.Either<FS.FreeSemigroup<DE.DecodeError<string>>, A>; | ||
/** | ||
* @category constructors | ||
* @since 2.2.7 | ||
* @since 2.2.8 | ||
*/ | ||
export declare const fromGuard: <A>(guard: G.Guard<A>, expected: string) => Decoder<A>; | ||
export declare const fromRefinement: <I, A extends I>(refinement: Refinement<I, A>, expected: string) => Decoder<I, A>; | ||
/** | ||
* @category constructors | ||
* @since 2.2.8 | ||
*/ | ||
export declare const fromGuard: <I, A extends I>(guard: G.Guard<I, A>, expected: string) => Decoder<I, A>; | ||
/** | ||
* @category constructors | ||
* @since 2.2.7 | ||
*/ | ||
export declare const literal: <A extends readonly [Literal, ...Array<Literal>]>(...values: A) => Decoder<A[number]>; | ||
export declare const literal: <A extends readonly [S.Literal, ...Array<S.Literal>]>(...values: A) => Decoder<unknown, A[number]>; | ||
/** | ||
@@ -60,3 +69,3 @@ * @category primitives | ||
*/ | ||
export declare const string: Decoder<string>; | ||
export declare const string: Decoder<unknown, string>; | ||
/** | ||
@@ -66,3 +75,3 @@ * @category primitives | ||
*/ | ||
export declare const number: Decoder<number>; | ||
export declare const number: Decoder<unknown, number>; | ||
/** | ||
@@ -72,3 +81,3 @@ * @category primitives | ||
*/ | ||
export declare const boolean: Decoder<boolean>; | ||
export declare const boolean: Decoder<unknown, boolean>; | ||
/** | ||
@@ -78,3 +87,3 @@ * @category primitives | ||
*/ | ||
export declare const UnknownArray: Decoder<Array<unknown>>; | ||
export declare const UnknownArray: Decoder<unknown, Array<unknown>>; | ||
/** | ||
@@ -84,3 +93,3 @@ * @category primitives | ||
*/ | ||
export declare const UnknownRecord: Decoder<Record<string, unknown>>; | ||
export declare const UnknownRecord: Decoder<unknown, Record<string, unknown>>; | ||
/** | ||
@@ -90,3 +99,3 @@ * @category combinators | ||
*/ | ||
export declare const mapLeftWithInput: (f: (input: unknown, e: DecodeError) => DecodeError) => <A>(decoder: Decoder<A>) => Decoder<A>; | ||
export declare const mapLeftWithInput: <I>(f: (input: I, e: DecodeError) => DecodeError) => <A>(decoder: Decoder<I, A>) => Decoder<I, A>; | ||
/** | ||
@@ -96,3 +105,3 @@ * @category combinators | ||
*/ | ||
export declare const refine: <A, B extends A>(refinement: (a: A) => a is B, id: string) => (from: Decoder<A>) => Decoder<B>; | ||
export declare const refine: <A, B extends A>(refinement: (a: A) => a is B, id: string) => <I>(from: Decoder<I, A>) => Decoder<I, B>; | ||
/** | ||
@@ -102,3 +111,3 @@ * @category combinators | ||
*/ | ||
export declare const parse: <A, B>(parser: (a: A) => E.Either<DecodeError, B>) => (from: Decoder<A>) => Decoder<B>; | ||
export declare const parse: <A, B>(parser: (a: A) => E.Either<DecodeError, B>) => <I>(from: Decoder<I, A>) => Decoder<I, B>; | ||
/** | ||
@@ -108,8 +117,8 @@ * @category combinators | ||
*/ | ||
export declare const nullable: <A>(or: Decoder<A>) => Decoder<null | A>; | ||
export declare const nullable: <I, A>(or: Decoder<I, A>) => Decoder<null | I, null | A>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.7 | ||
* @since 2.2.8 | ||
*/ | ||
export declare const type: <A>(properties: { [K in keyof A]: Decoder<A[K]>; }) => Decoder<{ [K_1 in keyof A]: A[K_1]; }>; | ||
export declare const fromType: <P extends Record<string, Decoder<any, any>>>(properties: P) => Decoder<{ [K in keyof P]: K.InputOf<"Either", P[K]>; }, { [K_1 in keyof P]: K.TypeOf<"Either", P[K_1]>; }>; | ||
/** | ||
@@ -119,25 +128,43 @@ * @category combinators | ||
*/ | ||
export declare const partial: <A>(properties: { [K in keyof A]: Decoder<A[K]>; }) => Decoder<Partial<{ [K_1 in keyof A]: A[K_1]; }>>; | ||
export declare const type: <A>(properties: { [K in keyof A]: Decoder<unknown, A[K]>; }) => Decoder<unknown, { [K_1 in keyof A]: A[K_1]; }>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
export declare const fromPartial: <P extends Record<string, Decoder<any, any>>>(properties: P) => Decoder<Partial<{ [K in keyof P]: K.InputOf<"Either", P[K]>; }>, Partial<{ [K_1 in keyof P]: K.TypeOf<"Either", P[K_1]>; }>>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.7 | ||
*/ | ||
export declare const array: <A>(items: Decoder<A>) => Decoder<A[]>; | ||
export declare const partial: <A>(properties: { [K in keyof A]: Decoder<unknown, A[K]>; }) => Decoder<unknown, Partial<{ [K_1 in keyof A]: A[K_1]; }>>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
export declare const fromArray: <I, A>(item: Decoder<I, A>) => Decoder<I[], A[]>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.7 | ||
*/ | ||
export declare const record: <A>(codomain: Decoder<A>) => Decoder<Record<string, A>>; | ||
export declare const array: <A>(item: Decoder<unknown, A>) => Decoder<unknown, A[]>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
export declare const fromRecord: <I, A>(codomain: Decoder<I, A>) => Decoder<Record<string, I>, Record<string, A>>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.7 | ||
*/ | ||
export declare const tuple: <A extends readonly unknown[]>(...components: { [K in keyof A]: Decoder<A[K]>; }) => Decoder<A>; | ||
export declare const record: <A>(codomain: Decoder<unknown, A>) => Decoder<unknown, Record<string, A>>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
export declare const fromTuple: <C extends readonly Decoder<any, any>[]>(...components: C) => Decoder<{ [K in keyof C]: K.InputOf<"Either", C[K]>; }, { [K_1 in keyof C]: K.TypeOf<"Either", C[K_1]>; }>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.7 | ||
*/ | ||
export declare const union: <A extends readonly [unknown, ...Array<unknown>]>(...members: { | ||
[K in keyof A]: Decoder<A[K]>; | ||
}) => Decoder<A[number]>; | ||
export declare const tuple: <A extends readonly unknown[]>(...components: { [K in keyof A]: Decoder<unknown, A[K]>; }) => Decoder<unknown, A>; | ||
/** | ||
@@ -147,3 +174,3 @@ * @category combinators | ||
*/ | ||
export declare const intersect: <B>(right: Decoder<B>) => <A>(left: Decoder<A>) => Decoder<A & B>; | ||
export declare const union: <MS extends readonly [Decoder<any, any>, ...Array<Decoder<any, any>>]>(...members: MS) => Decoder<InputOf<MS[keyof MS]>, TypeOf<MS[keyof MS]>>; | ||
/** | ||
@@ -153,8 +180,13 @@ * @category combinators | ||
*/ | ||
export declare const sum: <T extends string>(tag: T) => <A>(members: { [K in keyof A]: Decoder<A[K]>; }) => Decoder<A[keyof A]>; | ||
export declare const intersect: <IB, B>(right: Decoder<IB, B>) => <IA, A>(left: Decoder<IA, A>) => Decoder<IA & IB, A & B>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
export declare const fromSum: <T extends string>(tag: T) => <MS extends Record<string, Decoder<any, any>>>(members: MS) => Decoder<K.InputOf<"Either", MS[keyof MS]>, K.TypeOf<"Either", MS[keyof MS]>>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.7 | ||
*/ | ||
export declare const lazy: <A>(id: string, f: () => Decoder<A>) => Decoder<A>; | ||
export declare const sum: <T extends string>(tag: T) => <A>(members: { [K in keyof A]: Decoder<unknown, A[K]>; }) => Decoder<unknown, A[keyof A]>; | ||
/** | ||
@@ -164,3 +196,3 @@ * @category combinators | ||
*/ | ||
export declare const compose: <A, B>(to: KD.KleisliDecoder<A, B>) => (from: Decoder<A>) => Decoder<B>; | ||
export declare const lazy: <I, A>(id: string, f: () => Decoder<I, A>) => Decoder<I, A>; | ||
/** | ||
@@ -170,3 +202,3 @@ * @category Functor | ||
*/ | ||
export declare const map: <A, B>(f: (a: A) => B) => (fa: Decoder<A>) => Decoder<B>; | ||
export declare const map: <A, B>(f: (a: A) => B) => <I>(fa: Decoder<I, A>) => Decoder<I, B>; | ||
/** | ||
@@ -176,4 +208,14 @@ * @category Alt | ||
*/ | ||
export declare const alt: <A>(that: () => Decoder<A>) => (me: Decoder<A>) => Decoder<A>; | ||
export declare const alt: <I, A>(that: () => Decoder<I, A>) => (me: Decoder<I, A>) => Decoder<I, A>; | ||
/** | ||
* @category Semigroupoid | ||
* @since 2.2.8 | ||
*/ | ||
export declare const compose: <A, B>(to: Decoder<A, B>) => <I>(from: Decoder<I, A>) => Decoder<I, B>; | ||
/** | ||
* @category Category | ||
* @since 2.2.8 | ||
*/ | ||
export declare const id: <A>() => Decoder<A, A>; | ||
/** | ||
* @category instances | ||
@@ -189,4 +231,4 @@ * @since 2.2.7 | ||
declare module 'fp-ts/lib/HKT' { | ||
interface URItoKind<A> { | ||
readonly [URI]: Decoder<A>; | ||
interface URItoKind2<E, A> { | ||
readonly [URI]: Decoder<E, A>; | ||
} | ||
@@ -196,19 +238,43 @@ } | ||
* @category instances | ||
* @since 2.2.7 | ||
* @since 2.2.8 | ||
*/ | ||
export declare const functorDecoder: Functor1<URI>; | ||
export declare const Functor: Functor2<URI>; | ||
/** | ||
* @category instances | ||
* @since 2.2.7 | ||
* @since 2.2.8 | ||
*/ | ||
export declare const altDecoder: Alt1<URI>; | ||
export declare const Alt: Alt2<URI>; | ||
/** | ||
* @category instances | ||
* @since 2.2.7 | ||
* @since 2.2.8 | ||
*/ | ||
export declare const schemableDecoder: Schemable1<URI> & WithUnknownContainers1<URI> & WithUnion1<URI> & WithRefine1<URI>; | ||
export declare const Category: Category2<URI>; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
export declare const Schemable: S.Schemable2C<URI, unknown>; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
export declare const WithUnknownContainers: S.WithUnknownContainers2C<URI, unknown>; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
export declare const WithUnion: S.WithUnion2C<URI, unknown>; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
export declare const WithRefine: S.WithRefine2C<URI, unknown>; | ||
/** | ||
* @since 2.2.8 | ||
*/ | ||
export declare type InputOf<D> = K.InputOf<E.URI, D>; | ||
/** | ||
* @since 2.2.7 | ||
*/ | ||
export declare type TypeOf<D> = KD.TypeOf<D>; | ||
export declare type TypeOf<D> = K.TypeOf<E.URI, D>; | ||
/** | ||
@@ -215,0 +281,0 @@ * @since 2.2.7 |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.stringify = exports.draw = exports.schemableDecoder = exports.altDecoder = exports.functorDecoder = exports.URI = exports.alt = exports.map = exports.compose = exports.lazy = exports.sum = exports.intersect = exports.union = exports.tuple = exports.record = exports.array = exports.partial = exports.type = exports.nullable = exports.parse = exports.refine = exports.mapLeftWithInput = exports.object = exports.UnknownRecord = exports.UnknownArray = exports.boolean = exports.number = exports.string = exports.literal = exports.fromGuard = exports.failure = exports.success = exports.error = void 0; | ||
exports.stringify = exports.draw = exports.WithRefine = exports.WithUnion = exports.WithUnknownContainers = exports.Schemable = exports.Category = exports.Alt = exports.Functor = exports.URI = exports.id = exports.compose = exports.alt = exports.map = exports.lazy = exports.sum = exports.fromSum = exports.intersect = exports.union = exports.tuple = exports.fromTuple = exports.record = exports.fromRecord = exports.array = exports.fromArray = exports.partial = exports.fromPartial = exports.type = exports.fromType = exports.nullable = exports.parse = exports.refine = exports.mapLeftWithInput = exports.UnknownRecord = exports.UnknownArray = exports.boolean = exports.number = exports.string = exports.literal = exports.fromGuard = exports.fromRefinement = exports.failure = exports.success = exports.error = exports.ap = exports.SE = void 0; | ||
var E = require("fp-ts/lib/Either"); | ||
@@ -9,8 +9,47 @@ var pipeable_1 = require("fp-ts/lib/pipeable"); | ||
var G = require("./Guard"); | ||
var KD = require("./KleisliDecoder"); | ||
var K = require("./Kleisli"); | ||
// ------------------------------------------------------------------------------------- | ||
// Kleisli config | ||
// ------------------------------------------------------------------------------------- | ||
/** | ||
* @internal | ||
*/ | ||
exports.SE = | ||
/*#__PURE__*/ | ||
DE.getSemigroup(); | ||
/** | ||
* @internal | ||
*/ | ||
exports.ap = function (fab, fa) { | ||
return E.isLeft(fab) | ||
? E.isLeft(fa) | ||
? E.left(exports.SE.concat(fab.left, fa.left)) | ||
: fab | ||
: E.isLeft(fa) | ||
? fa | ||
: E.right(fab.right(fa.right)); | ||
}; | ||
var M = { | ||
URI: E.URI, | ||
_E: undefined, | ||
map: function (fa, f) { return pipeable_1.pipe(fa, E.map(f)); }, | ||
ap: exports.ap, | ||
of: E.right, | ||
chain: function (ma, f) { return pipeable_1.pipe(ma, E.chain(f)); }, | ||
throwError: E.left, | ||
bimap: function (fa, f, g) { return pipeable_1.pipe(fa, E.bimap(f, g)); }, | ||
mapLeft: function (fa, f) { return pipeable_1.pipe(fa, E.mapLeft(f)); }, | ||
alt: function (me, that) { | ||
if (E.isRight(me)) { | ||
return me; | ||
} | ||
var ea = that(); | ||
return E.isLeft(ea) ? E.left(exports.SE.concat(me.left, ea.left)) : ea; | ||
} | ||
}; | ||
/** | ||
* @category DecodeError | ||
* @since 2.2.7 | ||
*/ | ||
exports.error = KD.error; | ||
exports.error = function (actual, message) { return FS.of(DE.leaf(actual, message)); }; | ||
/** | ||
@@ -20,3 +59,3 @@ * @category DecodeError | ||
*/ | ||
exports.success = KD.success; | ||
exports.success = E.right; | ||
/** | ||
@@ -26,3 +65,5 @@ * @category DecodeError | ||
*/ | ||
exports.failure = KD.failure; | ||
exports.failure = function (actual, message) { | ||
return E.left(exports.error(actual, message)); | ||
}; | ||
// ------------------------------------------------------------------------------------- | ||
@@ -33,10 +74,21 @@ // constructors | ||
* @category constructors | ||
* @since 2.2.7 | ||
* @since 2.2.8 | ||
*/ | ||
exports.fromGuard = function (guard, expected) { return KD.fromRefinement(guard.is, expected); }; | ||
exports.fromRefinement = function (refinement, expected) { | ||
return K.fromRefinement(M)(refinement, function (u) { return exports.error(u, expected); }); | ||
}; | ||
/** | ||
* @category constructors | ||
* @since 2.2.8 | ||
*/ | ||
exports.fromGuard = function (guard, expected) { | ||
return exports.fromRefinement(guard.is, expected); | ||
}; | ||
/** | ||
* @category constructors | ||
* @since 2.2.7 | ||
*/ | ||
exports.literal = KD.literal; | ||
exports.literal = | ||
/*#__PURE__*/ | ||
K.literal(M)(function (u, values) { return exports.error(u, values.map(function (value) { return JSON.stringify(value); }).join(' | ')); }); | ||
// ------------------------------------------------------------------------------------- | ||
@@ -80,8 +132,2 @@ // primitives | ||
exports.fromGuard(G.UnknownRecord, 'Record<string, unknown>'); | ||
/** | ||
* @internal | ||
*/ | ||
exports.object = | ||
/*#__PURE__*/ | ||
exports.fromGuard(G.object, 'object'); | ||
// ------------------------------------------------------------------------------------- | ||
@@ -94,3 +140,5 @@ // combinators | ||
*/ | ||
exports.mapLeftWithInput = KD.mapLeftWithInput; | ||
exports.mapLeftWithInput = | ||
/*#__PURE__*/ | ||
K.mapLeftWithInput(M); | ||
/** | ||
@@ -100,3 +148,3 @@ * @category combinators | ||
*/ | ||
exports.refine = KD.refine; | ||
exports.refine = function (refinement, id) { return K.refine(M)(refinement, function (a) { return exports.error(a, id); }); }; | ||
/** | ||
@@ -106,3 +154,5 @@ * @category combinators | ||
*/ | ||
exports.parse = KD.parse; | ||
exports.parse = | ||
/*#__PURE__*/ | ||
K.parse(M); | ||
/** | ||
@@ -112,9 +162,23 @@ * @category combinators | ||
*/ | ||
exports.nullable = KD.nullable; | ||
exports.nullable = | ||
/*#__PURE__*/ | ||
K.nullable(M)(function (u, e) { return FS.concat(FS.of(DE.member(0, exports.error(u, 'null'))), FS.of(DE.member(1, e))); }); | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
exports.fromType = function (properties) { | ||
return K.fromType(M)(function (k, e) { return FS.of(DE.key(k, DE.required, e)); })(properties); | ||
}; | ||
/** | ||
* @category combinators | ||
* @since 2.2.7 | ||
*/ | ||
exports.type = function (properties) { | ||
return pipeable_1.pipe(exports.object, exports.compose(KD.type(properties))); | ||
exports.type = function (properties) { return pipeable_1.pipe(exports.UnknownRecord, exports.compose(exports.fromType(properties))); }; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
exports.fromPartial = function (properties) { | ||
return K.fromPartial(M)(function (k, e) { return FS.of(DE.key(k, DE.optional, e)); })(properties); | ||
}; | ||
@@ -125,4 +189,9 @@ /** | ||
*/ | ||
exports.partial = function (properties) { | ||
return pipeable_1.pipe(exports.object, exports.compose(KD.partial(properties))); | ||
exports.partial = function (properties) { return pipeable_1.pipe(exports.UnknownRecord, exports.compose(exports.fromPartial(properties))); }; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
exports.fromArray = function (item) { | ||
return K.fromArray(M)(function (i, e) { return FS.of(DE.index(i, DE.optional, e)); })(item); | ||
}; | ||
@@ -133,12 +202,32 @@ /** | ||
*/ | ||
exports.array = function (items) { return pipeable_1.pipe(exports.UnknownArray, exports.compose(KD.array(items))); }; | ||
exports.array = function (item) { | ||
return pipeable_1.pipe(exports.UnknownArray, exports.compose(exports.fromArray(item))); | ||
}; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
exports.fromRecord = function (codomain) { | ||
return K.fromRecord(M)(function (k, e) { return FS.of(DE.key(k, DE.optional, e)); })(codomain); | ||
}; | ||
/** | ||
* @category combinators | ||
* @since 2.2.7 | ||
*/ | ||
exports.record = function (codomain) { | ||
return pipeable_1.pipe(exports.UnknownRecord, exports.compose(KD.record(codomain))); | ||
return pipeable_1.pipe(exports.UnknownRecord, exports.compose(exports.fromRecord(codomain))); | ||
}; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
exports.fromTuple = function () { | ||
var components = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
components[_i] = arguments[_i]; | ||
} | ||
return K.fromTuple(M)(function (i, e) { return FS.of(DE.index(i, DE.required, e)); }).apply(void 0, components); | ||
}; | ||
/** | ||
* @category combinators | ||
* @since 2.2.7 | ||
@@ -151,3 +240,3 @@ */ | ||
} | ||
return pipeable_1.pipe(exports.UnknownArray, exports.compose(KD.tuple.apply(KD, components))); | ||
return pipeable_1.pipe(exports.UnknownArray, exports.compose(exports.fromTuple.apply(void 0, components))); | ||
}; | ||
@@ -158,3 +247,5 @@ /** | ||
*/ | ||
exports.union = KD.union; | ||
exports.union = | ||
/*#__PURE__*/ | ||
K.union(M)(function (i, e) { return FS.of(DE.member(i, e)); }); | ||
/** | ||
@@ -164,9 +255,13 @@ * @category combinators | ||
*/ | ||
exports.intersect = KD.intersect; | ||
exports.intersect = | ||
/*#__PURE__*/ | ||
K.intersect(M); | ||
/** | ||
* @category combinators | ||
* @since 2.2.7 | ||
* @since 2.2.8 | ||
*/ | ||
exports.sum = function (tag) { return function (members) { | ||
return pipeable_1.pipe(exports.object, exports.compose(KD.sum(tag)(members))); | ||
exports.fromSum = function (tag) { return function (members) { | ||
return K.fromSum(M)(function (tag, value, keys) { | ||
return FS.of(DE.key(tag, DE.required, exports.error(value, keys.length === 0 ? 'never' : keys.map(function (k) { return JSON.stringify(k); }).join(' | ')))); | ||
})(tag)(members); | ||
}; }; | ||
@@ -177,3 +272,3 @@ /** | ||
*/ | ||
exports.lazy = KD.lazy; | ||
exports.sum = function (tag) { return function (members) { return pipeable_1.pipe(exports.UnknownRecord, exports.compose(exports.fromSum(tag)(members))); }; }; | ||
/** | ||
@@ -183,3 +278,5 @@ * @category combinators | ||
*/ | ||
exports.compose = KD.compose; | ||
exports.lazy = | ||
/*#__PURE__*/ | ||
K.lazy(M)(function (id, e) { return FS.of(DE.lazy(id, e)); }); | ||
// ------------------------------------------------------------------------------------- | ||
@@ -190,2 +287,3 @@ // non-pipeables | ||
var alt_ = function (me, that) { return pipeable_1.pipe(me, exports.alt(that)); }; | ||
var compose_ = function (ab, la) { return pipeable_1.pipe(la, exports.compose(ab)); }; | ||
// ------------------------------------------------------------------------------------- | ||
@@ -198,3 +296,5 @@ // pipeables | ||
*/ | ||
exports.map = KD.map; | ||
exports.map = | ||
/*#__PURE__*/ | ||
K.map(M); | ||
/** | ||
@@ -204,3 +304,19 @@ * @category Alt | ||
*/ | ||
exports.alt = KD.alt; | ||
exports.alt = | ||
/*#__PURE__*/ | ||
K.alt(M); | ||
/** | ||
* @category Semigroupoid | ||
* @since 2.2.8 | ||
*/ | ||
exports.compose = | ||
/*#__PURE__*/ | ||
K.compose(M); | ||
/** | ||
* @category Category | ||
* @since 2.2.8 | ||
*/ | ||
exports.id = | ||
/*#__PURE__*/ | ||
K.id(M); | ||
// ------------------------------------------------------------------------------------- | ||
@@ -216,5 +332,5 @@ // instances | ||
* @category instances | ||
* @since 2.2.7 | ||
* @since 2.2.8 | ||
*/ | ||
exports.functorDecoder = { | ||
exports.Functor = { | ||
URI: exports.URI, | ||
@@ -225,5 +341,5 @@ map: map_ | ||
* @category instances | ||
* @since 2.2.7 | ||
* @since 2.2.8 | ||
*/ | ||
exports.altDecoder = { | ||
exports.Alt = { | ||
URI: exports.URI, | ||
@@ -235,6 +351,15 @@ map: map_, | ||
* @category instances | ||
* @since 2.2.7 | ||
* @since 2.2.8 | ||
*/ | ||
exports.schemableDecoder = { | ||
exports.Category = { | ||
URI: exports.URI, | ||
compose: compose_, | ||
id: exports.id | ||
}; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
exports.Schemable = { | ||
URI: exports.URI, | ||
literal: exports.literal, | ||
@@ -252,6 +377,24 @@ string: exports.string, | ||
sum: exports.sum, | ||
lazy: exports.lazy, | ||
lazy: exports.lazy | ||
}; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
exports.WithUnknownContainers = { | ||
UnknownArray: exports.UnknownArray, | ||
UnknownRecord: exports.UnknownRecord, | ||
union: exports.union, | ||
UnknownRecord: exports.UnknownRecord | ||
}; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
exports.WithUnion = { | ||
union: exports.union | ||
}; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
exports.WithRefine = { | ||
refine: exports.refine | ||
@@ -258,0 +401,0 @@ }; |
@@ -21,7 +21,2 @@ /** | ||
/** | ||
* @category constructors | ||
* @since 2.2.3 | ||
*/ | ||
export declare function id<A>(): Encoder<A, A>; | ||
/** | ||
* @category combinators | ||
@@ -58,3 +53,3 @@ * @since 2.2.3 | ||
*/ | ||
export declare function array<O, A>(items: Encoder<O, A>): Encoder<Array<O>, Array<A>>; | ||
export declare function array<O, A>(item: Encoder<O, A>): Encoder<Array<O>, Array<A>>; | ||
/** | ||
@@ -95,2 +90,7 @@ * @category combinators | ||
/** | ||
* @category Category | ||
* @since 2.2.3 | ||
*/ | ||
export declare function id<A>(): Encoder<A, A>; | ||
/** | ||
* @category instances | ||
@@ -112,10 +112,10 @@ * @since 2.2.3 | ||
* @category instances | ||
* @since 2.2.3 | ||
* @since 2.2.8 | ||
*/ | ||
export declare const contravariantEncoder: Contravariant2<URI>; | ||
export declare const Contravariant: Contravariant2<URI>; | ||
/** | ||
* @category instances | ||
* @since 2.2.3 | ||
* @since 2.2.8 | ||
*/ | ||
export declare const categoryEncoder: Category2<URI>; | ||
export declare const Category: Category2<URI>; | ||
/** | ||
@@ -122,0 +122,0 @@ * @since 2.2.3 |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.categoryEncoder = exports.contravariantEncoder = exports.URI = exports.compose = exports.contramap = exports.lazy = exports.sum = exports.intersect = exports.tuple = exports.array = exports.record = exports.partial = exports.type = exports.nullable = exports.id = void 0; | ||
exports.Category = exports.Contravariant = exports.URI = exports.id = exports.compose = exports.contramap = exports.lazy = exports.sum = exports.intersect = exports.tuple = exports.array = exports.record = exports.partial = exports.type = exports.nullable = void 0; | ||
var Schemable_1 = require("./Schemable"); | ||
var function_1 = require("fp-ts/lib/function"); | ||
// ------------------------------------------------------------------------------------- | ||
// constructors | ||
// ------------------------------------------------------------------------------------- | ||
/** | ||
* @category constructors | ||
* @since 2.2.3 | ||
*/ | ||
function id() { | ||
return { | ||
encode: function_1.identity | ||
}; | ||
} | ||
exports.id = id; | ||
// ------------------------------------------------------------------------------------- | ||
// combinators | ||
@@ -89,5 +76,5 @@ // ------------------------------------------------------------------------------------- | ||
*/ | ||
function array(items) { | ||
function array(item) { | ||
return { | ||
encode: function (as) { return as.map(items.encode); } | ||
encode: function (as) { return as.map(item.encode); } | ||
}; | ||
@@ -141,2 +128,9 @@ } | ||
// ------------------------------------------------------------------------------------- | ||
// non-pipeables | ||
// ------------------------------------------------------------------------------------- | ||
var contramap_ = function (ea, f) { return ({ | ||
encode: function (b) { return ea.encode(f(b)); } | ||
}); }; | ||
var compose_ = function (ab, ea) { return contramap_(ea, ab.encode); }; | ||
// ------------------------------------------------------------------------------------- | ||
// pipeables | ||
@@ -151,5 +145,2 @@ // ------------------------------------------------------------------------------------- | ||
}; }; | ||
var contramap_ = function (fa, f) { return ({ | ||
encode: function (b) { return fa.encode(f(b)); } | ||
}); }; | ||
/** | ||
@@ -162,5 +153,12 @@ * @category Semigroupoid | ||
}; }; | ||
var compose_ = function (ab, ea) { return ({ | ||
encode: function (b) { return ea.encode(ab.encode(b)); } | ||
}); }; | ||
/** | ||
* @category Category | ||
* @since 2.2.3 | ||
*/ | ||
function id() { | ||
return { | ||
encode: function_1.identity | ||
}; | ||
} | ||
exports.id = id; | ||
// ------------------------------------------------------------------------------------- | ||
@@ -176,5 +174,5 @@ // instances | ||
* @category instances | ||
* @since 2.2.3 | ||
* @since 2.2.8 | ||
*/ | ||
exports.contravariantEncoder = { | ||
exports.Contravariant = { | ||
URI: exports.URI, | ||
@@ -185,5 +183,5 @@ contramap: contramap_ | ||
* @category instances | ||
* @since 2.2.3 | ||
* @since 2.2.8 | ||
*/ | ||
exports.categoryEncoder = { | ||
exports.Category = { | ||
URI: exports.URI, | ||
@@ -190,0 +188,0 @@ compose: compose_, |
@@ -96,4 +96,14 @@ import * as E from 'fp-ts/lib/Eq'; | ||
* @category instances | ||
* @since 2.2.3 | ||
* @since 2.2.8 | ||
*/ | ||
export declare const schemableEq: Schemable1<E.URI> & WithUnknownContainers1<E.URI> & WithRefine1<E.URI>; | ||
export declare const Schemable: Schemable1<E.URI>; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
export declare const WithUnknownContainers: WithUnknownContainers1<E.URI>; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
export declare const WithRefine: WithRefine1<E.URI>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.schemableEq = exports.lazy = exports.sum = exports.intersect = exports.tuple = exports.array = exports.record = exports.partial = exports.type = exports.nullable = exports.UnknownRecord = exports.UnknownArray = exports.boolean = exports.number = exports.string = void 0; | ||
exports.WithRefine = exports.WithUnknownContainers = exports.Schemable = exports.lazy = exports.sum = exports.intersect = exports.tuple = exports.array = exports.record = exports.partial = exports.type = exports.nullable = exports.UnknownRecord = exports.UnknownArray = exports.boolean = exports.number = exports.string = void 0; | ||
/** | ||
@@ -152,5 +152,5 @@ * **This module is experimental** | ||
* @category instances | ||
* @since 2.2.3 | ||
* @since 2.2.8 | ||
*/ | ||
exports.schemableEq = { | ||
exports.Schemable = { | ||
URI: E.URI, | ||
@@ -169,6 +169,18 @@ literal: function () { return E.eqStrict; }, | ||
sum: sum, | ||
lazy: function (_, f) { return lazy(f); }, | ||
lazy: function (_, f) { return lazy(f); } | ||
}; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
exports.WithUnknownContainers = { | ||
UnknownArray: exports.UnknownArray, | ||
UnknownRecord: exports.UnknownRecord, | ||
UnknownRecord: exports.UnknownRecord | ||
}; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
exports.WithRefine = { | ||
refine: function () { return function (from) { return from; }; } | ||
}; |
import { Literal, Schemable1, WithRefine1, WithUnion1, WithUnknownContainers1 } from './Schemable'; | ||
/** | ||
* @category model | ||
* @since 2.2.0 | ||
* @since 2.2.8 | ||
*/ | ||
export interface Guard<A> { | ||
is: (u: unknown) => u is A; | ||
export interface Guard<I, A extends I> { | ||
is: (i: I) => i is A; | ||
} | ||
@@ -12,8 +12,12 @@ /** | ||
*/ | ||
export declare type TypeOf<G> = G extends Guard<infer A> ? A : never; | ||
export declare type TypeOf<G> = G extends Guard<any, infer A> ? A : never; | ||
/** | ||
* @since 2.2.8 | ||
*/ | ||
export declare type InputOf<G> = G extends Guard<infer I, any> ? I : never; | ||
/** | ||
* @category constructors | ||
* @since 2.2.0 | ||
*/ | ||
export declare const literal: <A extends readonly [Literal, ...Literal[]]>(...values: A) => Guard<A[number]>; | ||
export declare const literal: <A extends readonly [Literal, ...Literal[]]>(...values: A) => Guard<unknown, A[number]>; | ||
/** | ||
@@ -23,3 +27,3 @@ * @category primitives | ||
*/ | ||
export declare const string: Guard<string>; | ||
export declare const string: Guard<unknown, string>; | ||
/** | ||
@@ -31,3 +35,3 @@ * Note: `NaN` is excluded. | ||
*/ | ||
export declare const number: Guard<number>; | ||
export declare const number: Guard<unknown, number>; | ||
/** | ||
@@ -37,3 +41,3 @@ * @category primitives | ||
*/ | ||
export declare const boolean: Guard<boolean>; | ||
export declare const boolean: Guard<unknown, boolean>; | ||
/** | ||
@@ -43,3 +47,3 @@ * @category primitives | ||
*/ | ||
export declare const UnknownArray: Guard<Array<unknown>>; | ||
export declare const UnknownArray: Guard<unknown, Array<unknown>>; | ||
/** | ||
@@ -49,3 +53,3 @@ * @category primitives | ||
*/ | ||
export declare const UnknownRecord: Guard<Record<string, unknown>>; | ||
export declare const UnknownRecord: Guard<unknown, Record<string, unknown>>; | ||
/** | ||
@@ -55,3 +59,3 @@ * @category combinators | ||
*/ | ||
export declare const refine: <A, B extends A>(refinement: (a: A) => a is B) => (from: Guard<A>) => Guard<B>; | ||
export declare const refine: <I, A extends I, B extends A>(refinement: (a: A) => a is B) => (from: Guard<I, A>) => Guard<I, B>; | ||
/** | ||
@@ -61,3 +65,3 @@ * @category combinators | ||
*/ | ||
export declare const nullable: <A>(or: Guard<A>) => Guard<A | null>; | ||
export declare const nullable: <I, A extends I>(or: Guard<I, A>) => Guard<I | null, A | null>; | ||
/** | ||
@@ -67,3 +71,3 @@ * @category combinators | ||
*/ | ||
export declare const type: <A>(properties: { [K in keyof A]: Guard<A[K]>; }) => Guard<{ [K_1 in keyof A]: A[K_1]; }>; | ||
export declare const type: <A>(properties: { [K in keyof A]: Guard<unknown, A[K]>; }) => Guard<unknown, { [K_1 in keyof A]: A[K_1]; }>; | ||
/** | ||
@@ -73,3 +77,3 @@ * @category combinators | ||
*/ | ||
export declare const partial: <A>(properties: { [K in keyof A]: Guard<A[K]>; }) => Guard<Partial<{ [K_1 in keyof A]: A[K_1]; }>>; | ||
export declare const partial: <A>(properties: { [K in keyof A]: Guard<unknown, A[K]>; }) => Guard<unknown, Partial<{ [K_1 in keyof A]: A[K_1]; }>>; | ||
/** | ||
@@ -79,3 +83,3 @@ * @category combinators | ||
*/ | ||
export declare const record: <A>(codomain: Guard<A>) => Guard<Record<string, A>>; | ||
export declare const array: <A>(item: Guard<unknown, A>) => Guard<unknown, A[]>; | ||
/** | ||
@@ -85,3 +89,3 @@ * @category combinators | ||
*/ | ||
export declare const array: <A>(items: Guard<A>) => Guard<A[]>; | ||
export declare const record: <A>(codomain: Guard<unknown, A>) => Guard<unknown, Record<string, A>>; | ||
/** | ||
@@ -91,3 +95,3 @@ * @category combinators | ||
*/ | ||
export declare const tuple: <A extends readonly unknown[]>(...components: { [K in keyof A]: Guard<A[K]>; }) => Guard<A>; | ||
export declare const tuple: <A extends readonly unknown[]>(...components: { [K in keyof A]: Guard<unknown, A[K]>; }) => Guard<unknown, A>; | ||
/** | ||
@@ -97,3 +101,3 @@ * @category combinators | ||
*/ | ||
export declare const intersect: <B>(right: Guard<B>) => <A>(left: Guard<A>) => Guard<A & B>; | ||
export declare const intersect: <B>(right: Guard<unknown, B>) => <A>(left: Guard<unknown, A>) => Guard<unknown, A & B>; | ||
/** | ||
@@ -103,3 +107,3 @@ * @category combinators | ||
*/ | ||
export declare const union: <A extends readonly [unknown, ...unknown[]]>(...members: { [K in keyof A]: Guard<A[K]>; }) => Guard<A[number]>; | ||
export declare const union: <A extends readonly [unknown, ...unknown[]]>(...members: { [K in keyof A]: Guard<unknown, A[K]>; }) => Guard<unknown, A[number]>; | ||
/** | ||
@@ -109,3 +113,3 @@ * @category combinators | ||
*/ | ||
export declare const sum: <T extends string>(tag: T) => <A>(members: { [K in keyof A]: Guard<A[K]>; }) => Guard<A[keyof A]>; | ||
export declare const sum: <T extends string>(tag: T) => <A>(members: { [K in keyof A]: Guard<unknown, A[K]>; }) => Guard<unknown, A[keyof A]>; | ||
/** | ||
@@ -115,4 +119,24 @@ * @category combinators | ||
*/ | ||
export declare const lazy: <A>(f: () => Guard<A>) => Guard<A>; | ||
export declare const lazy: <A>(f: () => Guard<unknown, A>) => Guard<unknown, A>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
export declare const alt: <I, A extends I>(that: () => Guard<I, A>) => (me: Guard<I, A>) => Guard<I, A>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
export declare const zero: <I, A extends I>() => Guard<I, A>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
export declare const compose: <I, A extends I, B extends A>(to: Guard<A, B>) => (from: Guard<I, A>) => Guard<I, B>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
export declare const id: <A>() => Guard<A, A>; | ||
/** | ||
* @category instances | ||
@@ -129,3 +153,3 @@ * @since 2.2.0 | ||
interface URItoKind<A> { | ||
readonly [URI]: Guard<A>; | ||
readonly [URI]: Guard<unknown, A>; | ||
} | ||
@@ -135,4 +159,19 @@ } | ||
* @category instances | ||
* @since 2.2.3 | ||
* @since 2.2.8 | ||
*/ | ||
export declare const schemableGuard: Schemable1<URI> & WithUnknownContainers1<URI> & WithUnion1<URI> & WithRefine1<URI>; | ||
export declare const Schemable: Schemable1<URI>; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
export declare const WithUnknownContainers: WithUnknownContainers1<URI>; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
export declare const WithUnion: WithUnion1<URI>; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
export declare const WithRefine: WithRefine1<URI>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.schemableGuard = exports.URI = exports.lazy = exports.sum = exports.union = exports.intersect = exports.tuple = exports.array = exports.record = exports.partial = exports.type = exports.nullable = exports.refine = exports.object = exports.UnknownRecord = exports.UnknownArray = exports.boolean = exports.number = exports.string = exports.literal = void 0; | ||
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; | ||
/** | ||
@@ -72,8 +72,2 @@ * **This module is experimental** | ||
}; | ||
/** | ||
* @internal | ||
*/ | ||
exports.object = { | ||
is: function (u) { return u != null && !exports.string.is(u) && !exports.number.is(u) && !exports.boolean.is(u); } | ||
}; | ||
// ------------------------------------------------------------------------------------- | ||
@@ -87,3 +81,3 @@ // combinators | ||
exports.refine = function (refinement) { return function (from) { return ({ | ||
is: function (u) { return from.is(u) && refinement(u); } | ||
is: function (i) { return from.is(i) && refinement(i); } | ||
}); }; }; | ||
@@ -95,3 +89,3 @@ /** | ||
exports.nullable = function (or) { return ({ | ||
is: function (u) { return u === null || or.is(u); } | ||
is: function (i) { return i === null || or.is(i); } | ||
}); }; | ||
@@ -131,2 +125,9 @@ /** | ||
*/ | ||
exports.array = function (item) { | ||
return pipeable_1.pipe(exports.UnknownArray, exports.refine(function (us) { return us.every(item.is); })); | ||
}; | ||
/** | ||
* @category combinators | ||
* @since 2.2.0 | ||
*/ | ||
exports.record = function (codomain) { | ||
@@ -146,9 +147,2 @@ return pipeable_1.pipe(exports.UnknownRecord, exports.refine(function (r) { | ||
*/ | ||
exports.array = function (items) { | ||
return pipeable_1.pipe(exports.UnknownArray, exports.refine(function (us) { return us.every(items.is); })); | ||
}; | ||
/** | ||
* @category combinators | ||
* @since 2.2.0 | ||
*/ | ||
exports.tuple = function () { | ||
@@ -206,2 +200,30 @@ var components = []; | ||
}; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
exports.alt = function (that) { return function (me) { return ({ | ||
is: function (i) { return me.is(i) || that().is(i); } | ||
}); }; }; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
exports.zero = function () { return ({ | ||
is: function (_) { return false; } | ||
}); }; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
exports.compose = function (to) { return function (from) { return ({ | ||
is: function (i) { return from.is(i) && to.is(i); } | ||
}); }; }; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
exports.id = function () { return ({ | ||
is: function (_) { return true; } | ||
}); }; | ||
// ------------------------------------------------------------------------------------- | ||
@@ -217,5 +239,5 @@ // instances | ||
* @category instances | ||
* @since 2.2.3 | ||
* @since 2.2.8 | ||
*/ | ||
exports.schemableGuard = { | ||
exports.Schemable = { | ||
URI: exports.URI, | ||
@@ -234,7 +256,25 @@ literal: exports.literal, | ||
sum: exports.sum, | ||
lazy: function (_, f) { return exports.lazy(f); }, | ||
lazy: function (_, f) { return exports.lazy(f); } | ||
}; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
exports.WithUnknownContainers = { | ||
UnknownArray: exports.UnknownArray, | ||
UnknownRecord: exports.UnknownRecord, | ||
union: exports.union, | ||
UnknownRecord: exports.UnknownRecord | ||
}; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
exports.WithUnion = { | ||
union: exports.union | ||
}; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
exports.WithRefine = { | ||
refine: exports.refine | ||
}; |
@@ -59,14 +59,6 @@ /** | ||
/** | ||
* @since 2.2.7 | ||
*/ | ||
export declare type TypeOf<M extends URIS2, KD> = KD extends Kleisli<M, any, any, infer A> ? A : never; | ||
/** | ||
* @since 2.2.7 | ||
*/ | ||
export declare type InputOf<M extends URIS2, KD> = KD extends Kleisli<M, infer I, any, any> ? I : never; | ||
/** | ||
* @category combinators | ||
* @since 2.2.7 | ||
*/ | ||
export declare function type<M extends URIS2, E>(M: Applicative2C<M, E> & Bifunctor2<M>): (onPropertyError: (key: string, e: E) => E) => <P extends Record<string, Kleisli<M, any, E, any>>>(properties: P) => Kleisli<M, { | ||
export declare function fromType<M extends URIS2, E>(M: Applicative2C<M, E> & Bifunctor2<M>): (onPropertyError: (key: string, e: E) => E) => <P extends Record<string, Kleisli<M, any, E, any>>>(properties: P) => Kleisli<M, { | ||
[K in keyof P]: InputOf<M, P[K]>; | ||
@@ -80,5 +72,5 @@ }, E, { | ||
*/ | ||
export declare function partial<M extends URIS2, E>(M: Applicative2C<M, E> & Bifunctor2<M>): (onPropertyError: (key: string, e: E) => E) => <P extends Record<string, Kleisli<M, any, E, any>>>(properties: P) => Kleisli<M, { | ||
export declare function fromPartial<M extends URIS2, E>(M: Applicative2C<M, E> & Bifunctor2<M>): (onPropertyError: (key: string, e: E) => E) => <P extends Record<string, Kleisli<M, any, E, any>>>(properties: P) => Kleisli<M, Partial<{ | ||
[K in keyof P]: InputOf<M, P[K]>; | ||
}, E, Partial<{ | ||
}>, E, Partial<{ | ||
[K in keyof P]: TypeOf<M, P[K]>; | ||
@@ -90,3 +82,3 @@ }>>; | ||
*/ | ||
export declare function array<M extends URIS2, E>(M: Applicative2C<M, E> & Bifunctor2<M>): (onItemError: (index: number, e: E) => E) => <I, A>(items: Kleisli<M, I, E, A>) => Kleisli<M, Array<I>, E, Array<A>>; | ||
export declare function fromArray<M extends URIS2, E>(M: Applicative2C<M, E> & Bifunctor2<M>): (onItemError: (index: number, e: E) => E) => <I, A>(item: Kleisli<M, I, E, A>) => Kleisli<M, Array<I>, E, Array<A>>; | ||
/** | ||
@@ -96,3 +88,3 @@ * @category combinators | ||
*/ | ||
export declare function record<M extends URIS2, E>(M: Applicative2C<M, E> & Bifunctor2<M>): (onKeyError: (key: string, e: E) => E) => <I, A>(codomain: Kleisli<M, I, E, A>) => Kleisli<M, Record<string, I>, E, Record<string, A>>; | ||
export declare function fromRecord<M extends URIS2, E>(M: Applicative2C<M, E> & Bifunctor2<M>): (onKeyError: (key: string, e: E) => E) => <I, A>(codomain: Kleisli<M, I, E, A>) => Kleisli<M, Record<string, I>, E, Record<string, A>>; | ||
/** | ||
@@ -102,3 +94,3 @@ * @category combinators | ||
*/ | ||
export declare function tuple<M extends URIS2, E>(M: Applicative2C<M, E> & Bifunctor2<M>): (onIndexError: (index: number, e: E) => E) => <C extends ReadonlyArray<Kleisli<M, any, E, any>>>(...components: C) => Kleisli<M, { | ||
export declare function fromTuple<M extends URIS2, E>(M: Applicative2C<M, E> & Bifunctor2<M>): (onIndexError: (index: number, e: E) => E) => <C extends ReadonlyArray<Kleisli<M, any, E, any>>>(...components: C) => Kleisli<M, { | ||
[K in keyof C]: InputOf<M, C[K]>; | ||
@@ -122,3 +114,3 @@ }, E, { | ||
*/ | ||
export declare function sum<M extends URIS2, E>(M: MonadThrow2C<M, E>): (onTagError: (tag: string, value: unknown, tags: ReadonlyArray<string>) => E) => <T extends string>(tag: T) => <MS extends Record<string, Kleisli<M, any, E, any>>>(members: MS) => Kleisli<M, InputOf<M, MS[keyof MS]>, E, TypeOf<M, MS[keyof MS]>>; | ||
export declare function fromSum<M extends URIS2, E>(M: MonadThrow2C<M, E>): (onTagError: (tag: string, value: unknown, tags: ReadonlyArray<string>) => E) => <T extends string>(tag: T) => <MS extends Record<string, Kleisli<M, any, E, any>>>(members: MS) => Kleisli<M, InputOf<M, MS[keyof MS]>, E, TypeOf<M, MS[keyof MS]>>; | ||
/** | ||
@@ -136,2 +128,7 @@ * @category combinators | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
export declare function id<M extends URIS2, E>(M: Applicative2C<M, E>): <A>() => Kleisli<M, A, E, A>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.7 | ||
@@ -145,1 +142,9 @@ */ | ||
export declare function alt<F extends URIS2, E>(A: Alt2C<F, E>): <I, A>(that: Lazy<Kleisli<F, I, E, A>>) => (me: Kleisli<F, I, E, A>) => Kleisli<F, I, E, A>; | ||
/** | ||
* @since 2.2.7 | ||
*/ | ||
export declare type TypeOf<M extends URIS2, KD> = KD extends Kleisli<M, any, any, infer A> ? A : never; | ||
/** | ||
* @since 2.2.7 | ||
*/ | ||
export declare type InputOf<M extends URIS2, KD> = KD extends Kleisli<M, infer I, any, any> ? I : never; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.alt = exports.map = exports.compose = exports.lazy = exports.sum = exports.intersect = exports.union = exports.tuple = exports.record = exports.array = exports.partial = exports.type = exports.nullable = exports.parse = exports.refine = exports.mapLeftWithInput = exports.literal = exports.fromRefinement = void 0; | ||
exports.alt = exports.map = exports.id = exports.compose = exports.lazy = exports.fromSum = exports.intersect = exports.union = exports.fromTuple = exports.fromRecord = exports.fromArray = exports.fromPartial = exports.fromType = exports.nullable = exports.parse = exports.refine = exports.mapLeftWithInput = exports.literal = exports.fromRefinement = void 0; | ||
var E = require("fp-ts/lib/Either"); | ||
@@ -83,3 +83,3 @@ var G = require("./Guard"); | ||
*/ | ||
function type(M) { | ||
function fromType(M) { | ||
var traverse = traverseRecordWithIndex(M); | ||
@@ -94,3 +94,3 @@ return function (onPropertyError) { return function (properties) { return ({ | ||
} | ||
exports.type = type; | ||
exports.fromType = fromType; | ||
/** | ||
@@ -100,3 +100,3 @@ * @category combinators | ||
*/ | ||
function partial(M) { | ||
function fromPartial(M) { | ||
var traverse = traverseRecordWithIndex(M); | ||
@@ -121,3 +121,3 @@ var undefinedProperty = M.of(E.right(undefined)); | ||
} | ||
exports.partial = partial; | ||
exports.fromPartial = fromPartial; | ||
/** | ||
@@ -127,9 +127,9 @@ * @category combinators | ||
*/ | ||
function array(M) { | ||
function fromArray(M) { | ||
var traverse = traverseArrayWithIndex(M); | ||
return function (onItemError) { return function (items) { return ({ | ||
decode: function (is) { return traverse(is, function (index, i) { return M.mapLeft(items.decode(i), function (e) { return onItemError(index, e); }); }); } | ||
return function (onItemError) { return function (item) { return ({ | ||
decode: function (is) { return traverse(is, function (index, i) { return M.mapLeft(item.decode(i), function (e) { return onItemError(index, e); }); }); } | ||
}); }; }; | ||
} | ||
exports.array = array; | ||
exports.fromArray = fromArray; | ||
/** | ||
@@ -139,3 +139,3 @@ * @category combinators | ||
*/ | ||
function record(M) { | ||
function fromRecord(M) { | ||
var traverse = traverseRecordWithIndex(M); | ||
@@ -146,3 +146,3 @@ return function (onKeyError) { return function (codomain) { return ({ | ||
} | ||
exports.record = record; | ||
exports.fromRecord = fromRecord; | ||
/** | ||
@@ -152,3 +152,3 @@ * @category combinators | ||
*/ | ||
function tuple(M) { | ||
function fromTuple(M) { | ||
var traverse = traverseArrayWithIndex(M); | ||
@@ -169,3 +169,3 @@ return function (onIndexError) { return function () { | ||
} | ||
exports.tuple = tuple; | ||
exports.fromTuple = fromTuple; | ||
/** | ||
@@ -212,3 +212,3 @@ * @category combinators | ||
*/ | ||
function sum(M) { | ||
function fromSum(M) { | ||
return function (onTagError) { return function (tag) { return function (members) { | ||
@@ -227,3 +227,3 @@ var keys = Object.keys(members); | ||
} | ||
exports.sum = sum; | ||
exports.fromSum = fromSum; | ||
/** | ||
@@ -254,2 +254,12 @@ * @category combinators | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
function id(M) { | ||
return function () { return ({ | ||
decode: M.of | ||
}); }; | ||
} | ||
exports.id = id; | ||
/** | ||
* @category combinators | ||
* @since 2.2.7 | ||
@@ -256,0 +266,0 @@ */ |
@@ -11,4 +11,4 @@ /** | ||
*/ | ||
import { HKT, URIS, Kind } from 'fp-ts/lib/HKT'; | ||
import { Schemable, Schemable1 } from './Schemable'; | ||
import { HKT, Kind, Kind2, URIS, URIS2 } from 'fp-ts/lib/HKT'; | ||
import { Schemable, Schemable1, Schemable2C } from './Schemable'; | ||
/** | ||
@@ -33,2 +33,5 @@ * @category model | ||
*/ | ||
export declare function interpreter<S extends URIS>(S: Schemable1<S>): <A>(schema: Schema<A>) => Kind<S, A>; | ||
export declare const interpreter: { | ||
<S extends URIS2>(S: Schemable2C<S, unknown>): <A>(schema: Schema<A>) => Kind2<S, unknown, A>; | ||
<S extends URIS>(S: Schemable1<S>): <A>(schema: Schema<A>) => Kind<S, A>; | ||
}; |
@@ -19,5 +19,2 @@ "use strict"; | ||
*/ | ||
function interpreter(S) { | ||
return function (schema) { return schema(S); }; | ||
} | ||
exports.interpreter = interpreter; | ||
exports.interpreter = function (S) { return function (schema) { return schema(S); }; }; |
@@ -11,3 +11,3 @@ /** | ||
*/ | ||
import { Kind, URIS, HKT } from 'fp-ts/lib/HKT'; | ||
import { HKT, Kind, Kind2, URIS, URIS2 } from 'fp-ts/lib/HKT'; | ||
/** | ||
@@ -38,3 +38,3 @@ * @since 2.2.0 | ||
readonly record: <A>(codomain: HKT<S, A>) => HKT<S, Record<string, A>>; | ||
readonly array: <A>(items: HKT<S, A>) => HKT<S, Array<A>>; | ||
readonly array: <A>(item: HKT<S, A>) => HKT<S, Array<A>>; | ||
readonly tuple: <A extends ReadonlyArray<unknown>>(...components: { | ||
@@ -70,3 +70,3 @@ [K in keyof A]: HKT<S, A[K]>; | ||
readonly record: <A>(codomain: Kind<S, A>) => Kind<S, Record<string, A>>; | ||
readonly array: <A>(items: Kind<S, A>) => Kind<S, Array<A>>; | ||
readonly array: <A>(item: Kind<S, A>) => Kind<S, Array<A>>; | ||
readonly tuple: <A extends ReadonlyArray<unknown>>(...components: { | ||
@@ -82,2 +82,33 @@ [K in keyof A]: Kind<S, A[K]>; | ||
/** | ||
* @since 2.2.8 | ||
*/ | ||
export interface Schemable2C<S extends URIS2, E> { | ||
readonly URI: S; | ||
readonly literal: <A extends readonly [Literal, ...Array<Literal>]>(...values: A) => Kind2<S, E, A[number]>; | ||
readonly string: Kind2<S, E, string>; | ||
readonly number: Kind2<S, E, number>; | ||
readonly boolean: Kind2<S, E, boolean>; | ||
readonly nullable: <A>(or: Kind2<S, E, A>) => Kind2<S, E, null | A>; | ||
readonly type: <A>(properties: { | ||
[K in keyof A]: Kind2<S, E, A[K]>; | ||
}) => Kind2<S, E, { | ||
[K in keyof A]: A[K]; | ||
}>; | ||
readonly partial: <A>(properties: { | ||
[K in keyof A]: Kind2<S, E, A[K]>; | ||
}) => Kind2<S, E, Partial<{ | ||
[K in keyof A]: A[K]; | ||
}>>; | ||
readonly record: <A>(codomain: Kind2<S, E, A>) => Kind2<S, E, Record<string, A>>; | ||
readonly array: <A>(item: Kind2<S, E, A>) => Kind2<S, E, Array<A>>; | ||
readonly tuple: <A extends ReadonlyArray<unknown>>(...components: { | ||
[K in keyof A]: Kind2<S, E, A[K]>; | ||
}) => Kind2<S, E, A>; | ||
readonly intersect: <B>(right: Kind2<S, E, B>) => <A>(left: Kind2<S, E, A>) => Kind2<S, E, A & B>; | ||
readonly sum: <T extends string>(tag: T) => <A>(members: { | ||
[K in keyof A]: Kind2<S, E, A[K]>; | ||
}) => Kind2<S, E, A[keyof A]>; | ||
readonly lazy: <A>(id: string, f: () => Kind2<S, E, A>) => Kind2<S, E, A>; | ||
} | ||
/** | ||
* @since 2.2.3 | ||
@@ -97,2 +128,9 @@ */ | ||
/** | ||
* @since 2.2.8 | ||
*/ | ||
export interface WithUnknownContainers2C<S extends URIS2, E> { | ||
readonly UnknownArray: Kind2<S, E, Array<unknown>>; | ||
readonly UnknownRecord: Kind2<S, E, Record<string, unknown>>; | ||
} | ||
/** | ||
* @since 2.2.3 | ||
@@ -114,2 +152,10 @@ */ | ||
/** | ||
* @since 2.2.8 | ||
*/ | ||
export interface WithUnion2C<S extends URIS2, E> { | ||
readonly union: <A extends readonly [unknown, ...Array<unknown>]>(...members: { | ||
[K in keyof A]: Kind2<S, E, A[K]>; | ||
}) => Kind2<S, E, A[number]>; | ||
} | ||
/** | ||
* @since 2.2.3 | ||
@@ -127,4 +173,10 @@ */ | ||
/** | ||
* @since 2.2.8 | ||
*/ | ||
export interface WithRefine2C<S extends URIS2, E> { | ||
readonly refine: <A, B extends A>(refinement: (a: A) => a is B, id: string) => (from: Kind2<S, E, A>) => Kind2<S, E, B>; | ||
} | ||
/** | ||
* @since 2.2.0 | ||
*/ | ||
export declare function memoize<A, B>(f: (a: A) => B): (a: A) => B; |
@@ -11,14 +11,18 @@ /** | ||
*/ | ||
import { Alt1 } from 'fp-ts/lib/Alt'; | ||
import { Functor1 } from 'fp-ts/lib/Functor'; | ||
import { Alt2 } from 'fp-ts/lib/Alt'; | ||
import { Category2 } from 'fp-ts/lib/Category'; | ||
import { Refinement } from 'fp-ts/lib/function'; | ||
import { Functor2 } from 'fp-ts/lib/Functor'; | ||
import * as TE from 'fp-ts/lib/TaskEither'; | ||
import * as DE from './DecodeError'; | ||
import * as D from './Decoder'; | ||
import * as FS from './FreeSemigroup'; | ||
import * as G from './Guard'; | ||
import * as KTD from './KleisliTaskDecoder'; | ||
import { Literal, Schemable1, WithRefine1, WithUnion1, WithUnknownContainers1 } from './Schemable'; | ||
import * as K from './Kleisli'; | ||
import * as S from './Schemable'; | ||
/** | ||
* @category model | ||
* @since 2.2.7 | ||
* @since 2.2.8 | ||
*/ | ||
export interface TaskDecoder<A> extends KTD.KleisliTaskDecoder<unknown, A> { | ||
export interface TaskDecoder<I, A> extends K.Kleisli<TE.URI, I, DecodeError, A> { | ||
} | ||
@@ -44,3 +48,3 @@ /** | ||
*/ | ||
export declare const failure: <A = never>(actual: unknown, message: string) => TE.TaskEither<DecodeError, A>; | ||
export declare const failure: <A = never>(actual: unknown, message: string) => TE.TaskEither<FS.FreeSemigroup<DE.DecodeError<string>>, A>; | ||
/** | ||
@@ -50,8 +54,13 @@ * @category constructors | ||
*/ | ||
export declare const fromDecoder: <A>(decoder: D.Decoder<A>) => TaskDecoder<A>; | ||
export declare const fromDecoder: <I, A>(decoder: D.Decoder<I, A>) => TaskDecoder<I, A>; | ||
/** | ||
* @category constructors | ||
* @since 2.2.8 | ||
*/ | ||
export declare const fromRefinement: <I, A extends I>(refinement: Refinement<I, A>, expected: string) => TaskDecoder<I, A>; | ||
/** | ||
* @category constructors | ||
* @since 2.2.7 | ||
*/ | ||
export declare const fromGuard: <A>(guard: G.Guard<A>, expected: string) => TaskDecoder<A>; | ||
export declare const fromGuard: <I, A extends I>(guard: G.Guard<I, A>, expected: string) => TaskDecoder<I, A>; | ||
/** | ||
@@ -61,3 +70,3 @@ * @category constructors | ||
*/ | ||
export declare const literal: <A extends readonly [Literal, ...Array<Literal>]>(...values: A) => TaskDecoder<A[number]>; | ||
export declare const literal: <A extends readonly [S.Literal, ...Array<S.Literal>]>(...values: A) => TaskDecoder<unknown, A[number]>; | ||
/** | ||
@@ -67,3 +76,3 @@ * @category primitives | ||
*/ | ||
export declare const string: TaskDecoder<string>; | ||
export declare const string: TaskDecoder<unknown, string>; | ||
/** | ||
@@ -73,3 +82,3 @@ * @category primitives | ||
*/ | ||
export declare const number: TaskDecoder<number>; | ||
export declare const number: TaskDecoder<unknown, number>; | ||
/** | ||
@@ -79,3 +88,3 @@ * @category primitives | ||
*/ | ||
export declare const boolean: TaskDecoder<boolean>; | ||
export declare const boolean: TaskDecoder<unknown, boolean>; | ||
/** | ||
@@ -85,3 +94,3 @@ * @category primitives | ||
*/ | ||
export declare const UnknownArray: TaskDecoder<Array<unknown>>; | ||
export declare const UnknownArray: TaskDecoder<unknown, Array<unknown>>; | ||
/** | ||
@@ -91,3 +100,3 @@ * @category primitives | ||
*/ | ||
export declare const UnknownRecord: TaskDecoder<Record<string, unknown>>; | ||
export declare const UnknownRecord: TaskDecoder<unknown, Record<string, unknown>>; | ||
/** | ||
@@ -97,3 +106,3 @@ * @category combinators | ||
*/ | ||
export declare const mapLeftWithInput: (f: (input: unknown, e: DecodeError) => DecodeError) => <A>(decoder: TaskDecoder<A>) => TaskDecoder<A>; | ||
export declare const mapLeftWithInput: <I>(f: (input: I, e: DecodeError) => DecodeError) => <A>(decoder: TaskDecoder<I, A>) => TaskDecoder<I, A>; | ||
/** | ||
@@ -103,3 +112,3 @@ * @category combinators | ||
*/ | ||
export declare const refine: <A, B extends A>(refinement: (a: A) => a is B, id: string) => (from: TaskDecoder<A>) => TaskDecoder<B>; | ||
export declare const refine: <A, B extends A>(refinement: (a: A) => a is B, id: string) => <I>(from: TaskDecoder<I, A>) => TaskDecoder<I, B>; | ||
/** | ||
@@ -109,3 +118,3 @@ * @category combinators | ||
*/ | ||
export declare const parse: <A, B>(parser: (a: A) => TE.TaskEither<DecodeError, B>) => (from: TaskDecoder<A>) => TaskDecoder<B>; | ||
export declare const parse: <A, B>(parser: (a: A) => TE.TaskEither<DecodeError, B>) => <I>(from: TaskDecoder<I, A>) => TaskDecoder<I, B>; | ||
/** | ||
@@ -115,8 +124,8 @@ * @category combinators | ||
*/ | ||
export declare const nullable: <A>(or: TaskDecoder<A>) => TaskDecoder<null | A>; | ||
export declare const nullable: <I, A>(or: TaskDecoder<I, A>) => TaskDecoder<null | I, null | A>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.7 | ||
* @since 2.2.8 | ||
*/ | ||
export declare const type: <A>(properties: { [K in keyof A]: TaskDecoder<A[K]>; }) => TaskDecoder<{ [K_1 in keyof A]: A[K_1]; }>; | ||
export declare const fromType: <P extends Record<string, TaskDecoder<any, any>>>(properties: P) => TaskDecoder<{ [K in keyof P]: K.InputOf<"TaskEither", P[K]>; }, { [K_1 in keyof P]: K.TypeOf<"TaskEither", P[K_1]>; }>; | ||
/** | ||
@@ -126,25 +135,43 @@ * @category combinators | ||
*/ | ||
export declare const partial: <A>(properties: { [K in keyof A]: TaskDecoder<A[K]>; }) => TaskDecoder<Partial<{ [K_1 in keyof A]: A[K_1]; }>>; | ||
export declare const type: <A>(properties: { [K in keyof A]: TaskDecoder<unknown, A[K]>; }) => TaskDecoder<unknown, { [K_1 in keyof A]: A[K_1]; }>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
export declare const fromPartial: <P extends Record<string, TaskDecoder<any, any>>>(properties: P) => TaskDecoder<Partial<{ [K in keyof P]: K.InputOf<"TaskEither", P[K]>; }>, Partial<{ [K_1 in keyof P]: K.TypeOf<"TaskEither", P[K_1]>; }>>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.7 | ||
*/ | ||
export declare const array: <A>(items: TaskDecoder<A>) => TaskDecoder<A[]>; | ||
export declare const partial: <A>(properties: { [K in keyof A]: TaskDecoder<unknown, A[K]>; }) => TaskDecoder<unknown, Partial<{ [K_1 in keyof A]: A[K_1]; }>>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
export declare const fromArray: <I, A>(item: TaskDecoder<I, A>) => TaskDecoder<I[], A[]>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.7 | ||
*/ | ||
export declare const record: <A>(codomain: TaskDecoder<A>) => TaskDecoder<Record<string, A>>; | ||
export declare const array: <A>(item: TaskDecoder<unknown, A>) => TaskDecoder<unknown, A[]>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
export declare const fromRecord: <I, A>(codomain: TaskDecoder<I, A>) => TaskDecoder<Record<string, I>, Record<string, A>>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.7 | ||
*/ | ||
export declare const tuple: <A extends readonly unknown[]>(...components: { [K in keyof A]: TaskDecoder<A[K]>; }) => TaskDecoder<A>; | ||
export declare const record: <A>(codomain: TaskDecoder<unknown, A>) => TaskDecoder<unknown, Record<string, A>>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
export declare const fromTuple: <C extends readonly TaskDecoder<any, any>[]>(...components: C) => TaskDecoder<{ [K in keyof C]: K.InputOf<"TaskEither", C[K]>; }, { [K_1 in keyof C]: K.TypeOf<"TaskEither", C[K_1]>; }>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.7 | ||
*/ | ||
export declare const union: <A extends readonly [unknown, ...Array<unknown>]>(...members: { | ||
[K in keyof A]: TaskDecoder<A[K]>; | ||
}) => TaskDecoder<A[number]>; | ||
export declare const tuple: <A extends readonly unknown[]>(...components: { [K in keyof A]: TaskDecoder<unknown, A[K]>; }) => TaskDecoder<unknown, A>; | ||
/** | ||
@@ -154,3 +181,3 @@ * @category combinators | ||
*/ | ||
export declare const intersect: <B>(right: TaskDecoder<B>) => <A>(left: TaskDecoder<A>) => TaskDecoder<A & B>; | ||
export declare const union: <MS extends readonly [TaskDecoder<any, any>, ...Array<TaskDecoder<any, any>>]>(...members: MS) => TaskDecoder<InputOf<MS[keyof MS]>, TypeOf<MS[keyof MS]>>; | ||
/** | ||
@@ -160,8 +187,13 @@ * @category combinators | ||
*/ | ||
export declare const sum: <T extends string>(tag: T) => <A>(members: { [K in keyof A]: TaskDecoder<A[K]>; }) => TaskDecoder<A[keyof A]>; | ||
export declare const intersect: <IB, B>(right: TaskDecoder<IB, B>) => <IA, A>(left: TaskDecoder<IA, A>) => TaskDecoder<IA & IB, A & B>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
export declare const fromSum: <T extends string>(tag: T) => <MS extends Record<string, TaskDecoder<any, any>>>(members: MS) => TaskDecoder<K.InputOf<"TaskEither", MS[keyof MS]>, K.TypeOf<"TaskEither", MS[keyof MS]>>; | ||
/** | ||
* @category combinators | ||
* @since 2.2.7 | ||
*/ | ||
export declare const lazy: <A>(id: string, f: () => TaskDecoder<A>) => TaskDecoder<A>; | ||
export declare const sum: <T extends string>(tag: T) => <A>(members: { [K in keyof A]: TaskDecoder<unknown, A[K]>; }) => TaskDecoder<unknown, A[keyof A]>; | ||
/** | ||
@@ -171,3 +203,3 @@ * @category combinators | ||
*/ | ||
export declare const compose: <A, B>(to: KTD.KleisliTaskDecoder<A, B>) => (from: TaskDecoder<A>) => TaskDecoder<B>; | ||
export declare const lazy: <I, A>(id: string, f: () => TaskDecoder<I, A>) => TaskDecoder<I, A>; | ||
/** | ||
@@ -177,3 +209,3 @@ * @category Functor | ||
*/ | ||
export declare const map: <A, B>(f: (a: A) => B) => (fa: TaskDecoder<A>) => TaskDecoder<B>; | ||
export declare const map: <A, B>(f: (a: A) => B) => <I>(fa: TaskDecoder<I, A>) => TaskDecoder<I, B>; | ||
/** | ||
@@ -183,4 +215,14 @@ * @category Alt | ||
*/ | ||
export declare const alt: <A>(that: () => TaskDecoder<A>) => (me: TaskDecoder<A>) => TaskDecoder<A>; | ||
export declare const alt: <I, A>(that: () => TaskDecoder<I, A>) => (me: TaskDecoder<I, A>) => TaskDecoder<I, A>; | ||
/** | ||
* @category Semigroupoid | ||
* @since 2.2.8 | ||
*/ | ||
export declare const compose: <A, B>(to: TaskDecoder<A, B>) => <I>(from: TaskDecoder<I, A>) => TaskDecoder<I, B>; | ||
/** | ||
* @category Category | ||
* @since 2.2.8 | ||
*/ | ||
export declare const id: <A>() => TaskDecoder<A, A>; | ||
/** | ||
* @category instances | ||
@@ -196,4 +238,4 @@ * @since 2.2.7 | ||
declare module 'fp-ts/lib/HKT' { | ||
interface URItoKind<A> { | ||
readonly [URI]: TaskDecoder<A>; | ||
interface URItoKind2<E, A> { | ||
readonly [URI]: TaskDecoder<E, A>; | ||
} | ||
@@ -203,22 +245,46 @@ } | ||
* @category instances | ||
* @since 2.2.7 | ||
* @since 2.2.8 | ||
*/ | ||
export declare const functorTaskDecoder: Functor1<URI>; | ||
export declare const Functor: Functor2<URI>; | ||
/** | ||
* @category instances | ||
* @since 2.2.7 | ||
* @since 2.2.8 | ||
*/ | ||
export declare const altTaskDecoder: Alt1<URI>; | ||
export declare const Alt: Alt2<URI>; | ||
/** | ||
* @category instances | ||
* @since 2.2.7 | ||
* @since 2.2.8 | ||
*/ | ||
export declare const schemableTaskDecoder: Schemable1<URI> & WithUnknownContainers1<URI> & WithUnion1<URI> & WithRefine1<URI>; | ||
export declare const Category: Category2<URI>; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
export declare const Schemable: S.Schemable2C<URI, unknown>; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
export declare const WithUnknownContainers: S.WithUnknownContainers2C<URI, unknown>; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
export declare const WithUnion: S.WithUnion2C<URI, unknown>; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
export declare const WithRefine: S.WithRefine2C<URI, unknown>; | ||
/** | ||
* @since 2.2.7 | ||
*/ | ||
export declare type TypeOf<TD> = KTD.TypeOf<TD>; | ||
export declare type TypeOf<KTD> = K.TypeOf<TE.URI, KTD>; | ||
/** | ||
* @since 2.2.8 | ||
*/ | ||
export declare type InputOf<KTD> = K.InputOf<TE.URI, KTD>; | ||
/** | ||
* @since 2.2.7 | ||
*/ | ||
export declare const draw: (e: DecodeError) => string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.stringify = exports.draw = exports.schemableTaskDecoder = exports.altTaskDecoder = exports.functorTaskDecoder = exports.URI = exports.alt = exports.map = exports.compose = exports.lazy = exports.sum = exports.intersect = exports.union = exports.tuple = exports.record = exports.array = exports.partial = exports.type = exports.nullable = exports.parse = exports.refine = exports.mapLeftWithInput = exports.object = exports.UnknownRecord = exports.UnknownArray = exports.boolean = exports.number = exports.string = exports.literal = exports.fromGuard = exports.fromDecoder = exports.failure = exports.success = exports.error = void 0; | ||
exports.stringify = exports.draw = exports.WithRefine = exports.WithUnion = exports.WithUnknownContainers = exports.Schemable = exports.Category = exports.Alt = exports.Functor = exports.URI = exports.id = exports.compose = exports.alt = exports.map = exports.lazy = exports.sum = exports.fromSum = exports.intersect = exports.union = exports.tuple = exports.fromTuple = exports.record = exports.fromRecord = exports.array = exports.fromArray = exports.partial = exports.fromPartial = exports.type = exports.fromType = exports.nullable = exports.parse = exports.refine = exports.mapLeftWithInput = exports.UnknownRecord = exports.UnknownArray = exports.boolean = exports.number = exports.string = exports.literal = exports.fromGuard = exports.fromRefinement = exports.fromDecoder = exports.failure = exports.success = exports.error = void 0; | ||
var E = require("fp-ts/lib/Either"); | ||
var pipeable_1 = require("fp-ts/lib/pipeable"); | ||
var T = require("fp-ts/lib/Task"); | ||
var TE = require("fp-ts/lib/TaskEither"); | ||
var DE = require("./DecodeError"); | ||
var D = require("./Decoder"); | ||
var KTD = require("./KleisliTaskDecoder"); | ||
var FS = require("./FreeSemigroup"); | ||
var K = require("./Kleisli"); | ||
// ------------------------------------------------------------------------------------- | ||
// Kleisli config | ||
// ------------------------------------------------------------------------------------- | ||
var M = { | ||
URI: TE.URI, | ||
_E: undefined, | ||
map: function (fa, f) { return pipeable_1.pipe(fa, TE.map(f)); }, | ||
ap: function (fab, fa) { | ||
return pipeable_1.pipe(pipeable_1.pipe(fab, T.map(function (h) { return function (ga) { return D.ap(h, ga); }; })), T.ap(fa)); | ||
}, | ||
of: TE.right, | ||
chain: function (ma, f) { return pipeable_1.pipe(ma, TE.chain(f)); }, | ||
throwError: TE.left, | ||
bimap: function (fa, f, g) { return pipeable_1.pipe(fa, TE.bimap(f, g)); }, | ||
mapLeft: function (fa, f) { return pipeable_1.pipe(fa, TE.mapLeft(f)); }, | ||
alt: function (me, that) { | ||
return pipeable_1.pipe(me, T.chain(function (e1) { | ||
return E.isRight(e1) | ||
? T.of(e1) | ||
: pipeable_1.pipe(that(), T.map(function (e2) { return (E.isLeft(e2) ? E.left(D.SE.concat(e1.left, e2.left)) : e2); })); | ||
})); | ||
} | ||
}; | ||
/** | ||
@@ -18,3 +44,3 @@ * @category DecodeError | ||
*/ | ||
exports.success = KTD.success; | ||
exports.success = TE.right; | ||
/** | ||
@@ -24,3 +50,5 @@ * @category DecodeError | ||
*/ | ||
exports.failure = KTD.failure; | ||
exports.failure = function (actual, message) { | ||
return TE.left(D.error(actual, message)); | ||
}; | ||
// ------------------------------------------------------------------------------------- | ||
@@ -33,9 +61,18 @@ // constructors | ||
*/ | ||
exports.fromDecoder = KTD.fromKleisliDecoder; | ||
exports.fromDecoder = function (decoder) { return ({ | ||
decode: TE.fromEitherK(decoder.decode) | ||
}); }; | ||
/** | ||
* @category constructors | ||
* @since 2.2.8 | ||
*/ | ||
exports.fromRefinement = function (refinement, expected) { | ||
return exports.fromDecoder(D.fromRefinement(refinement, expected)); | ||
}; | ||
/** | ||
* @category constructors | ||
* @since 2.2.7 | ||
*/ | ||
exports.fromGuard = function (guard, expected) { | ||
return KTD.fromRefinement(guard.is, expected); | ||
return exports.fromRefinement(guard.is, expected); | ||
}; | ||
@@ -46,3 +83,5 @@ /** | ||
*/ | ||
exports.literal = KTD.literal; | ||
exports.literal = | ||
/*#__PURE__*/ | ||
K.literal(M)(function (u, values) { return exports.error(u, values.map(function (value) { return JSON.stringify(value); }).join(' | ')); }); | ||
// ------------------------------------------------------------------------------------- | ||
@@ -86,8 +125,2 @@ // primitives | ||
exports.fromDecoder(D.UnknownRecord); | ||
/** | ||
* @internal | ||
*/ | ||
exports.object = | ||
/*#__PURE__*/ | ||
exports.fromDecoder(D.object); | ||
// ------------------------------------------------------------------------------------- | ||
@@ -100,3 +133,5 @@ // combinators | ||
*/ | ||
exports.mapLeftWithInput = KTD.mapLeftWithInput; | ||
exports.mapLeftWithInput = | ||
/*#__PURE__*/ | ||
K.mapLeftWithInput(M); | ||
/** | ||
@@ -106,3 +141,3 @@ * @category combinators | ||
*/ | ||
exports.refine = KTD.refine; | ||
exports.refine = function (refinement, id) { return K.refine(M)(refinement, function (a) { return exports.error(a, id); }); }; | ||
/** | ||
@@ -112,3 +147,5 @@ * @category combinators | ||
*/ | ||
exports.parse = KTD.parse; | ||
exports.parse = | ||
/*#__PURE__*/ | ||
K.parse(M); | ||
/** | ||
@@ -118,9 +155,23 @@ * @category combinators | ||
*/ | ||
exports.nullable = KTD.nullable; | ||
exports.nullable = | ||
/*#__PURE__*/ | ||
K.nullable(M)(function (u, e) { return FS.concat(FS.of(DE.member(0, exports.error(u, 'null'))), FS.of(DE.member(1, e))); }); | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
exports.fromType = function (properties) { | ||
return K.fromType(M)(function (k, e) { return FS.of(DE.key(k, DE.required, e)); })(properties); | ||
}; | ||
/** | ||
* @category combinators | ||
* @since 2.2.7 | ||
*/ | ||
exports.type = function (properties) { | ||
return pipeable_1.pipe(exports.object, exports.compose(KTD.type(properties))); | ||
exports.type = function (properties) { return pipeable_1.pipe(exports.UnknownRecord, exports.compose(exports.fromType(properties))); }; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
exports.fromPartial = function (properties) { | ||
return K.fromPartial(M)(function (k, e) { return FS.of(DE.key(k, DE.optional, e)); })(properties); | ||
}; | ||
@@ -131,17 +182,46 @@ /** | ||
*/ | ||
exports.partial = function (properties) { return pipeable_1.pipe(exports.object, exports.compose(KTD.partial(properties))); }; | ||
exports.partial = function (properties) { | ||
return pipeable_1.pipe(exports.UnknownRecord, exports.compose(exports.fromPartial(properties))); | ||
}; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
exports.fromArray = function (item) { | ||
return K.fromArray(M)(function (i, e) { return FS.of(DE.index(i, DE.optional, e)); })(item); | ||
}; | ||
/** | ||
* @category combinators | ||
* @since 2.2.7 | ||
*/ | ||
exports.array = function (items) { return pipeable_1.pipe(exports.UnknownArray, exports.compose(KTD.array(items))); }; | ||
exports.array = function (item) { | ||
return pipeable_1.pipe(exports.UnknownArray, exports.compose(exports.fromArray(item))); | ||
}; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
exports.fromRecord = function (codomain) { | ||
return K.fromRecord(M)(function (k, e) { return FS.of(DE.key(k, DE.optional, e)); })(codomain); | ||
}; | ||
/** | ||
* @category combinators | ||
* @since 2.2.7 | ||
*/ | ||
exports.record = function (codomain) { | ||
return pipeable_1.pipe(exports.UnknownRecord, exports.compose(KTD.record(codomain))); | ||
return pipeable_1.pipe(exports.UnknownRecord, exports.compose(exports.fromRecord(codomain))); | ||
}; | ||
/** | ||
* @category combinators | ||
* @since 2.2.8 | ||
*/ | ||
exports.fromTuple = function () { | ||
var components = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
components[_i] = arguments[_i]; | ||
} | ||
return K.fromTuple(M)(function (i, e) { return FS.of(DE.index(i, DE.required, e)); }).apply(void 0, components); | ||
}; | ||
/** | ||
* @category combinators | ||
* @since 2.2.7 | ||
@@ -154,3 +234,3 @@ */ | ||
} | ||
return pipeable_1.pipe(exports.UnknownArray, exports.compose(KTD.tuple.apply(KTD, components))); | ||
return pipeable_1.pipe(exports.UnknownArray, exports.compose(exports.fromTuple.apply(void 0, components))); | ||
}; | ||
@@ -161,3 +241,5 @@ /** | ||
*/ | ||
exports.union = KTD.union; | ||
exports.union = | ||
/*#__PURE__*/ | ||
K.union(M)(function (i, e) { return FS.of(DE.member(i, e)); }); | ||
/** | ||
@@ -167,8 +249,14 @@ * @category combinators | ||
*/ | ||
exports.intersect = KTD.intersect; | ||
exports.intersect = | ||
/*#__PURE__*/ | ||
K.intersect(M); | ||
/** | ||
* @category combinators | ||
* @since 2.2.7 | ||
* @since 2.2.8 | ||
*/ | ||
exports.sum = function (tag) { return function (members) { return pipeable_1.pipe(exports.object, exports.compose(KTD.sum(tag)(members))); }; }; | ||
exports.fromSum = function (tag) { return function (members) { | ||
return K.fromSum(M)(function (tag, value, keys) { | ||
return FS.of(DE.key(tag, DE.required, exports.error(value, keys.length === 0 ? 'never' : keys.map(function (k) { return JSON.stringify(k); }).join(' | ')))); | ||
})(tag)(members); | ||
}; }; | ||
/** | ||
@@ -178,3 +266,3 @@ * @category combinators | ||
*/ | ||
exports.lazy = KTD.lazy; | ||
exports.sum = function (tag) { return function (members) { return pipeable_1.pipe(exports.UnknownRecord, exports.compose(exports.fromSum(tag)(members))); }; }; | ||
/** | ||
@@ -184,3 +272,5 @@ * @category combinators | ||
*/ | ||
exports.compose = KTD.compose; | ||
exports.lazy = | ||
/*#__PURE__*/ | ||
K.lazy(M)(function (id, e) { return FS.of(DE.lazy(id, e)); }); | ||
// ------------------------------------------------------------------------------------- | ||
@@ -191,2 +281,3 @@ // non-pipeables | ||
var alt_ = function (me, that) { return pipeable_1.pipe(me, exports.alt(that)); }; | ||
var compose_ = function (ab, la) { return pipeable_1.pipe(la, exports.compose(ab)); }; | ||
// ------------------------------------------------------------------------------------- | ||
@@ -199,3 +290,5 @@ // pipeables | ||
*/ | ||
exports.map = KTD.map; | ||
exports.map = | ||
/*#__PURE__*/ | ||
K.map(M); | ||
/** | ||
@@ -205,3 +298,19 @@ * @category Alt | ||
*/ | ||
exports.alt = KTD.alt; | ||
exports.alt = | ||
/*#__PURE__*/ | ||
K.alt(M); | ||
/** | ||
* @category Semigroupoid | ||
* @since 2.2.8 | ||
*/ | ||
exports.compose = | ||
/*#__PURE__*/ | ||
K.compose(M); | ||
/** | ||
* @category Category | ||
* @since 2.2.8 | ||
*/ | ||
exports.id = | ||
/*#__PURE__*/ | ||
K.id(M); | ||
// ------------------------------------------------------------------------------------- | ||
@@ -217,5 +326,5 @@ // instances | ||
* @category instances | ||
* @since 2.2.7 | ||
* @since 2.2.8 | ||
*/ | ||
exports.functorTaskDecoder = { | ||
exports.Functor = { | ||
URI: exports.URI, | ||
@@ -226,5 +335,5 @@ map: map_ | ||
* @category instances | ||
* @since 2.2.7 | ||
* @since 2.2.8 | ||
*/ | ||
exports.altTaskDecoder = { | ||
exports.Alt = { | ||
URI: exports.URI, | ||
@@ -236,6 +345,15 @@ map: map_, | ||
* @category instances | ||
* @since 2.2.7 | ||
* @since 2.2.8 | ||
*/ | ||
exports.schemableTaskDecoder = { | ||
exports.Category = { | ||
URI: exports.URI, | ||
compose: compose_, | ||
id: exports.id | ||
}; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
exports.Schemable = { | ||
URI: exports.URI, | ||
literal: exports.literal, | ||
@@ -253,6 +371,24 @@ string: exports.string, | ||
sum: exports.sum, | ||
lazy: exports.lazy, | ||
lazy: exports.lazy | ||
}; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
exports.WithUnknownContainers = { | ||
UnknownArray: exports.UnknownArray, | ||
UnknownRecord: exports.UnknownRecord, | ||
union: exports.union, | ||
UnknownRecord: exports.UnknownRecord | ||
}; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
exports.WithUnion = { | ||
union: exports.union | ||
}; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
exports.WithRefine = { | ||
refine: exports.refine | ||
@@ -259,0 +395,0 @@ }; |
@@ -78,3 +78,3 @@ /** | ||
*/ | ||
export declare const array: <A>(items: Type<A>) => Type<A[]>; | ||
export declare const array: <A>(item: Type<A>) => Type<A[]>; | ||
/** | ||
@@ -122,4 +122,19 @@ * @category combinators | ||
* @category instances | ||
* @since 2.2.3 | ||
* @since 2.2.8 | ||
*/ | ||
export declare const schemableType: Schemable1<URI> & WithUnknownContainers1<URI> & WithUnion1<URI> & WithRefine1<URI>; | ||
export declare const Schemable: Schemable1<URI>; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
export declare const WithUnknownContainers: WithUnknownContainers1<URI>; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
export declare const WithUnion: WithUnion1<URI>; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
export declare const WithRefine: WithRefine1<URI>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.schemableType = exports.URI = exports.union = exports.sum = exports.lazy = exports.intersect = exports.tuple = exports.array = exports.record = exports.partial = exports.type = exports.nullable = exports.refine = exports.UnknownRecord = exports.UnknownArray = exports.boolean = exports.number = exports.string = exports.literal = void 0; | ||
exports.WithRefine = exports.WithUnion = exports.WithUnknownContainers = exports.Schemable = exports.URI = exports.union = exports.sum = exports.lazy = exports.intersect = exports.tuple = exports.array = exports.record = exports.partial = exports.type = exports.nullable = exports.refine = exports.UnknownRecord = exports.UnknownArray = exports.boolean = exports.number = exports.string = exports.literal = void 0; | ||
/** | ||
@@ -100,3 +100,3 @@ * **This module is experimental** | ||
*/ | ||
exports.array = function (items) { return t.array(items); }; | ||
exports.array = function (item) { return t.array(item); }; | ||
/** | ||
@@ -151,5 +151,5 @@ * @category combinators | ||
* @category instances | ||
* @since 2.2.3 | ||
* @since 2.2.8 | ||
*/ | ||
exports.schemableType = { | ||
exports.Schemable = { | ||
URI: exports.URI, | ||
@@ -168,7 +168,25 @@ literal: exports.literal, | ||
sum: exports.sum, | ||
lazy: exports.lazy, | ||
lazy: exports.lazy | ||
}; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
exports.WithUnknownContainers = { | ||
UnknownArray: exports.UnknownArray, | ||
UnknownRecord: exports.UnknownRecord, | ||
union: exports.union, | ||
UnknownRecord: exports.UnknownRecord | ||
}; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
exports.WithUnion = { | ||
union: exports.union | ||
}; | ||
/** | ||
* @category instances | ||
* @since 2.2.8 | ||
*/ | ||
exports.WithRefine = { | ||
refine: exports.refine | ||
}; |
{ | ||
"name": "io-ts", | ||
"version": "2.2.7", | ||
"version": "2.2.8", | ||
"description": "TypeScript runtime type system for IO decoding/encoding", | ||
@@ -52,3 +52,3 @@ "files": [ | ||
"fast-check": "^1.24.2", | ||
"fp-ts": "2.5.3", | ||
"fp-ts": "^2.7.0", | ||
"import-path-rewrite": "github:gcanti/import-path-rewrite", | ||
@@ -55,0 +55,0 @@ "jest": "25.2.7", |
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
427673
68
14208