morphic-ts
Advanced tools
Comparing version
@@ -16,2 +16,57 @@ # Changelog | ||
## 0.7.0-RC10 | ||
- New Feature | ||
- Interpreter constraints | ||
## 0.7.0-RC9 | ||
- New Feature | ||
- provides function to help with configuration specification. | ||
- Eq for unknown is configurable (using fast-equals as default) | ||
## 0.7.0-RC8 | ||
- New Feature | ||
- refined Algebra and implementations | ||
## 0.7.0-RC7 | ||
- New Feature | ||
- newtype Algebra and implementations | ||
## 0.7.0-RC6 | ||
- New Feature | ||
- unknown Algebra and implementations | ||
## 0.7.0-RC5 | ||
- Breaking Change | ||
- Simplify API Surface for better DX | ||
## 0.7.0-RC4 | ||
- New Feature | ||
- better startup DX - exports AsOpaque and AsUOpaque from interpreters | ||
## 0.7.0-RC3 | ||
- Breaking Change | ||
- Only keep kind2 variant of io-ts interpreters | ||
## 0.7.0-RC2 | ||
- New Feature | ||
- makeTagged works with both inferrerd and non inferred Morphs | ||
## 0.7.0-RC1 | ||
@@ -18,0 +73,0 @@ |
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var function_1 = require("fp-ts/lib/function"); | ||
@@ -19,3 +9,3 @@ var fp_ts_1 = require("fp-ts"); | ||
var _a; | ||
return (__assign((_a = {}, _a[tag] = key, _a), props)); | ||
return (tslib_1.__assign((_a = {}, _a[tag] = key, _a), props)); | ||
}; })(keys); | ||
@@ -22,0 +12,0 @@ return { |
@@ -10,4 +10,4 @@ import { ElemType, ExtractUnion, ExcludeUnion } from './utils'; | ||
export interface ADT<A, Tag extends keyof A & string> extends Ma.Matchers<A, Tag>, PU.Predicates<A, Tag>, CU.Ctors<A, Tag>, M.MonocleFor<A> { | ||
select: <Keys extends A[Tag][]>(...keys: Keys) => ADT<ExtractUnion<A, Tag, ElemType<Keys>>, Tag>; | ||
exclude: <Keys extends A[Tag][]>(...keys: Keys) => ADT<ExcludeUnion<A, Tag, ElemType<Keys>>, Tag>; | ||
select: <Keys extends A[Tag][]>(keys: Keys) => ADT<ExtractUnion<A, Tag, ElemType<Keys>>, Tag>; | ||
exclude: <Keys extends A[Tag][]>(keys: Keys) => ADT<ExcludeUnion<A, Tag, ElemType<Keys>>, Tag>; | ||
tag: Tag; | ||
@@ -14,0 +14,0 @@ keys: KeysDefinition<A, Tag>; |
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var M = require("./monocle"); | ||
@@ -22,3 +12,3 @@ var Ma = require("./matcher"); | ||
var function_1 = require("fp-ts/lib/function"); | ||
var mergeKeys = function (a, b) { return (__assign(__assign({}, a), b)); }; | ||
var mergeKeys = function (a, b) { return (tslib_1.__assign(tslib_1.__assign({}, a), b)); }; | ||
var recordFromArray = fp_ts_1.record.fromFoldable({ concat: function_1.identity }, fp_ts_1.array.array); | ||
@@ -44,17 +34,9 @@ var toTupleNull = function (k) { return function_1.tuple(k, null); }; | ||
var matchers = Ma.Matchers(tag)(keys); // any | ||
var select = function () { | ||
var selectedKeys = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
selectedKeys[_i] = arguments[_i]; | ||
} | ||
var select = function (selectedKeys) { | ||
return exports.makeADT(tag)(keepKeys(keys, selectedKeys)); | ||
}; | ||
var exclude = function () { | ||
var excludedKeys = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
excludedKeys[_i] = arguments[_i]; | ||
} | ||
var exclude = function (excludedKeys) { | ||
return exports.makeADT(tag)(excludeKeys(keys, excludedKeys)); | ||
}; | ||
var res = __assign(__assign(__assign(__assign(__assign({}, ctors), predicates), monocles), matchers), { tag: tag, | ||
var res = tslib_1.__assign(tslib_1.__assign(tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, ctors), predicates), monocles), matchers), { tag: tag, | ||
keys: keys, | ||
@@ -61,0 +43,0 @@ select: select, |
@@ -12,3 +12,5 @@ import { KeysDefinition } from '.'; | ||
}; | ||
declare type Folder<A> = <R>(f: (a: A) => R) => (a: A) => R; | ||
interface Folder<A> { | ||
<R>(f: (a: A) => R): (a: A) => R; | ||
} | ||
interface Default<A, R> { | ||
@@ -15,0 +17,0 @@ default: (a: A) => R; |
@@ -7,9 +7,6 @@ "use strict"; | ||
var inKeys = _1.isIn(keys); | ||
var match = function (match) { return function (a) { | ||
var key = a[tag]; | ||
return key in match ? match[key](a) : match['default'](a); | ||
}; }; | ||
var match = function (match) { return function (a) { return (match[a[tag]] || match['default'])(a); }; }; | ||
var transform = function (match) { return function (a) { | ||
var key = a[tag]; | ||
return key in match ? match[key](a) : a; | ||
var c = match[a[tag]]; | ||
return c ? c(a) : a; | ||
}; }; | ||
@@ -21,10 +18,4 @@ var matchWiden = match; | ||
return function (s, a) { | ||
var key = a[tag]; | ||
var state = s === undefined ? initialState : s; | ||
if (inKeys(key)) { | ||
return matcher(a)(state); | ||
} | ||
else { | ||
return state; | ||
} | ||
return inKeys(a[tag]) ? matcher(a)(state) : state; | ||
}; | ||
@@ -31,0 +22,0 @@ }; }; |
import { Predicate, Refinement } from 'fp-ts/lib/function'; | ||
import * as m from 'monocle-ts'; | ||
import { Option } from 'fp-ts/lib/Option'; | ||
declare type LenseFromProp<S> = <P extends keyof S>(prop: P) => m.Lens<S, S[P]>; | ||
declare type LenseFromProps<S> = <P extends keyof S>(props: Array<P>) => m.Lens<S, { | ||
[K in P]: S[K]; | ||
}>; | ||
interface LenseFromProp<S> { | ||
<P extends keyof S>(prop: P): m.Lens<S, S[P]>; | ||
} | ||
interface LenseFromProps<S> { | ||
<P extends keyof S>(props: Array<P>): m.Lens<S, { | ||
[K in P]: S[K]; | ||
}>; | ||
} | ||
declare type OptionPropertyNames<S> = { | ||
@@ -12,5 +16,11 @@ [K in keyof S]-?: S[K] extends Option<any> ? K : never; | ||
declare type OptionPropertyType<S, K extends OptionPropertyNames<S>> = S[K] extends Option<infer A> ? A : never; | ||
declare type OptionalFromOptionProp<S> = <P extends OptionPropertyNames<S>>(prop: P) => m.Optional<S, OptionPropertyType<S, P>>; | ||
declare type OptionalFromNullableProp<S> = <K extends keyof S>(k: K) => m.Optional<S, NonNullable<S[K]>>; | ||
declare type IndexFromAt<T> = <J, B>(at: m.At<T, J, Option<B>>) => m.Index<T, J, B>; | ||
interface OptionalFromOptionProp<S> { | ||
<P extends OptionPropertyNames<S>>(prop: P): m.Optional<S, OptionPropertyType<S, P>>; | ||
} | ||
interface OptionalFromNullableProp<S> { | ||
<K extends keyof S>(k: K): m.Optional<S, NonNullable<S[K]>>; | ||
} | ||
interface IndexFromAt<T> { | ||
<J, B>(at: m.At<T, J, Option<B>>): m.Index<T, J, B>; | ||
} | ||
interface PrismFromPredicate<S> { | ||
@@ -17,0 +27,0 @@ <A extends S>(refinement: Refinement<S, A>): m.Prism<S, A>; |
@@ -6,4 +6,8 @@ import { ExtractUnion, ElemType } from './utils'; | ||
}; | ||
export declare type IsAny<A, Tag extends keyof A> = <Keys extends A[Tag][]>(...keys: Keys) => (a: A) => a is ExtractUnion<A, Tag, ElemType<Keys>>; | ||
export declare type Verified<A> = (a: A) => a is A; | ||
export interface IsAny<A, Tag extends keyof A> { | ||
<Keys extends A[Tag][]>(keys: Keys): (a: A) => a is ExtractUnion<A, Tag, ElemType<Keys>>; | ||
} | ||
export interface Verified<A> { | ||
(a: A): a is A; | ||
} | ||
export interface Predicates<A, Tag extends keyof A & string> { | ||
@@ -10,0 +14,0 @@ is: Is<A, Tag>; |
@@ -6,15 +6,6 @@ "use strict"; | ||
is: fp_ts_1.record.mapWithIndex(function (key, _) { return function (rest) { return rest[tag] === key; }; })(keys), | ||
verified: function (a) { | ||
var key = a[tag]; | ||
return key in keys; | ||
}, | ||
isAnyOf: function () { | ||
var keys = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
keys[_i] = arguments[_i]; | ||
} | ||
return function (rest) { | ||
return keys.indexOf(rest[tag]) !== -1; | ||
}; | ||
} | ||
verified: function (a) { return a[tag] in keys; }, | ||
isAnyOf: function (keys) { return function (rest) { | ||
return keys.indexOf(rest[tag]) !== -1; | ||
}; } | ||
}); }; }; |
@@ -37,2 +37,4 @@ import { Arbitrary } from 'fast-check/*'; | ||
} | ||
export declare const AsOpaque: <E, A>(x: M<E, A>) => M<E, A>; | ||
export declare const AsUOpaque: <A>(x: UM<A>) => UM<A>; | ||
export interface MorphAs { | ||
@@ -39,0 +41,0 @@ <L, A>(F: ProgramType<L, A>[ProgramUnionURI]): M<L, A>; |
@@ -10,3 +10,3 @@ "use strict"; | ||
var utils_1 = require("../json-schema-interpreters/utils"); | ||
var interpreters_3 = require("../io-ts-2-interpreters/interpreters"); | ||
var interpreters_3 = require("../io-ts-interpreters/interpreters"); | ||
exports.BASTJInterpreterURI = Symbol(); | ||
@@ -18,6 +18,8 @@ exports.BASTJInterpreter = function (_program) { | ||
arb: program(interpreters_1.modelFastCheckInterpreter).arb, | ||
strictType: program(interpreters_3.modelIoTs2StrictInterpreter).type, | ||
type: program(interpreters_3.modelIoTs2NonStrictInterpreter).type, | ||
strictType: program(interpreters_3.modelIoTsStrictInterpreter).type, | ||
type: program(interpreters_3.modelIoTsNonStrictInterpreter).type, | ||
jsonSchema: pipeable_1.pipe(program(interpreters_2.modelJsonSchemaInterpreter).schema({}), E.chain(utils_1.resolveSchema)) | ||
}; | ||
}; | ||
exports.AsOpaque = function (x) { return x; }; | ||
exports.AsUOpaque = function (x) { return x; }; |
@@ -41,2 +41,4 @@ import { Eq } from 'fp-ts/lib/Eq'; | ||
} | ||
export declare const AsOpaque: <E, A>(x: M<E, A>) => M<E, A>; | ||
export declare const AsUOpaque: <A>(x: UM<A>) => UM<A>; | ||
export interface MorphAs { | ||
@@ -43,0 +45,0 @@ <L, A>(F: ProgramType<L, A>[ProgramNoUnionURI]): M<L, A>; |
@@ -12,3 +12,3 @@ "use strict"; | ||
var utils_1 = require("../json-schema-interpreters/utils"); | ||
var interpreters_5 = require("../io-ts-2-interpreters/interpreters"); | ||
var interpreters_5 = require("../io-ts-interpreters/interpreters"); | ||
exports.ESBASTJInterpreterURI = Symbol(); | ||
@@ -22,6 +22,8 @@ exports.ESBASTJInterpreter = function (_program) { | ||
arb: program(interpreters_3.modelFastCheckInterpreter).arb, | ||
strictType: program(interpreters_5.modelIoTs2NonStrictInterpreter).type, | ||
type: program(interpreters_5.modelIoTs2NonStrictInterpreter).type, | ||
strictType: program(interpreters_5.modelIoTsNonStrictInterpreter).type, | ||
type: program(interpreters_5.modelIoTsNonStrictInterpreter).type, | ||
jsonSchema: pipeable_1.pipe(program(interpreters_4.modelJsonSchemaInterpreter).schema({}), E.chain(utils_1.resolveSchema)) | ||
}; | ||
}; | ||
exports.AsOpaque = function (x) { return x; }; | ||
exports.AsUOpaque = function (x) { return x; }; |
@@ -10,2 +10,5 @@ import { GetAlgebra } from '../algebras/core'; | ||
import { TaggedUnionsURI } from '../model-algebras/tagged-unions'; | ||
import { UnknownURI } from '../model-algebras/unknown'; | ||
import { NewtypeURI } from '../model-algebras/newtype'; | ||
import { RefinedURI } from '../model-algebras/refined'; | ||
export declare const ProgramNoUnionURI: unique symbol; | ||
@@ -19,3 +22,3 @@ export declare type ProgramNoUnionURI = typeof ProgramNoUnionURI; | ||
interface ProgramAlgebraURI { | ||
[ProgramNoUnionURI]: GetAlgebra<PrimitiveURI | IntersectionURI | ObjectURI | RecursiveURI | SetURI | StrMapURI | TaggedUnionsURI>; | ||
[ProgramNoUnionURI]: GetAlgebra<PrimitiveURI | IntersectionURI | ObjectURI | RecursiveURI | SetURI | StrMapURI | TaggedUnionsURI | UnknownURI | NewtypeURI | RefinedURI>; | ||
} | ||
@@ -22,0 +25,0 @@ interface ProgramAlgebra<F> { |
@@ -8,2 +8,4 @@ import { GetAlgebra } from '../algebras/core'; | ||
import { TaggedUnionsURI } from '../model-algebras/tagged-unions'; | ||
import { NewtypeURI } from '../model-algebras/newtype'; | ||
import { RefinedURI } from '../model-algebras/refined'; | ||
export declare const ProgramOrderableURI: unique symbol; | ||
@@ -17,3 +19,3 @@ export declare type ProgramOrderableURI = typeof ProgramOrderableURI; | ||
interface ProgramAlgebraURI { | ||
[ProgramOrderableURI]: GetAlgebra<PrimitiveURI | IntersectionURI | SetURI | StrMapURI | TaggedUnionsURI>; | ||
[ProgramOrderableURI]: GetAlgebra<PrimitiveURI | IntersectionURI | SetURI | StrMapURI | TaggedUnionsURI | NewtypeURI | RefinedURI>; | ||
} | ||
@@ -20,0 +22,0 @@ interface ProgramAlgebra<F> { |
@@ -11,2 +11,5 @@ import { GetAlgebra } from '../algebras/core'; | ||
import { UnionsURI } from '../model-algebras/unions'; | ||
import { UnknownURI } from '../model-algebras/unknown'; | ||
import { NewtypeURI } from '../model-algebras/newtype'; | ||
import { RefinedURI } from '../model-algebras/refined'; | ||
export declare const ProgramUnionURI: unique symbol; | ||
@@ -20,3 +23,3 @@ export declare type ProgramUnionURI = typeof ProgramUnionURI; | ||
interface ProgramAlgebraURI { | ||
[ProgramUnionURI]: GetAlgebra<PrimitiveURI | IntersectionURI | ObjectURI | RecursiveURI | SetURI | StrMapURI | TaggedUnionsURI | UnionsURI>; | ||
[ProgramUnionURI]: GetAlgebra<PrimitiveURI | IntersectionURI | ObjectURI | RecursiveURI | SetURI | StrMapURI | TaggedUnionsURI | UnionsURI | UnknownURI | NewtypeURI | RefinedURI>; | ||
} | ||
@@ -23,0 +26,0 @@ interface ProgramAlgebra<F> { |
@@ -1,1 +0,4 @@ | ||
export declare const summonAs: <L, A>(F: import("../usage/programs-infer").InferredProgram<L, A, typeof import("./program-no-union").ProgramNoUnionURI>) => import("../usage/materializer").Materialized<L, A, typeof import("./program-no-union").ProgramNoUnionURI, typeof import("./interpreters-ESBAST").ESBASTJInterpreterURI>, summonAsA: <A>() => <L>(F: import("../usage/programs-infer").InferredProgram<L, A, typeof import("./program-no-union").ProgramNoUnionURI>) => import("../usage/materializer").Materialized<L, A, typeof import("./program-no-union").ProgramNoUnionURI, typeof import("./interpreters-ESBAST").ESBASTJInterpreterURI>, summonAsL: <L>() => <A>(F: import("../usage/programs-infer").InferredProgram<L, A, typeof import("./program-no-union").ProgramNoUnionURI>) => import("../usage/materializer").Materialized<L, A, typeof import("./program-no-union").ProgramNoUnionURI, typeof import("./interpreters-ESBAST").ESBASTJInterpreterURI>, summon: <A>(F: import("../usage/programs-infer").InferredProgram<unknown, A, typeof import("./program-no-union").ProgramNoUnionURI>) => import("../usage/materializer").Materialized<unknown, A, typeof import("./program-no-union").ProgramNoUnionURI, typeof import("./interpreters-ESBAST").ESBASTJInterpreterURI>; | ||
import { M, UM, AsOpaque, AsUOpaque } from './interpreters-ESBAST'; | ||
declare const summon: import("../usage/summoner").Summoners<typeof import("./program-no-union").ProgramNoUnionURI, typeof import("./interpreters-ESBAST").ESBASTJInterpreterURI>; | ||
declare const tagged: <Tag extends string>(tag: Tag) => <Types extends { [k in keyof Types]: import("../usage/materializer").Materialized<Types[k]["_E"], Types[k]["_A"] & { [t in Tag]: k; }, typeof import("./program-no-union").ProgramNoUnionURI, typeof import("./interpreters-ESBAST").ESBASTJInterpreterURI>; }>(o: Types) => import("../usage/materializer").MorphADT<Types[keyof Types]["_E"], Types[keyof Types]["_A"], import("../usage/utils").TagsOf<Types[keyof Types]["_A"]>, typeof import("./program-no-union").ProgramNoUnionURI, typeof import("./interpreters-ESBAST").ESBASTJInterpreterURI>; | ||
export { M, UM, AsOpaque, AsUOpaque, summon, tagged }; |
"use strict"; | ||
var _a; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -7,2 +6,8 @@ var summoner_1 = require("../usage/summoner"); | ||
var interpreters_ESBAST_1 = require("./interpreters-ESBAST"); | ||
exports.summonAs = (_a = summoner_1.makeSummoner(core_1.cacheUnaryFunction, interpreters_ESBAST_1.ESBASTJInterpreter), _a.summonAs), exports.summonAsA = _a.summonAsA, exports.summonAsL = _a.summonAsL, exports.summon = _a.summon; | ||
exports.AsOpaque = interpreters_ESBAST_1.AsOpaque; | ||
exports.AsUOpaque = interpreters_ESBAST_1.AsUOpaque; | ||
var tagged_union_1 = require("../usage/tagged-union"); | ||
var summon = summoner_1.makeSummoner(core_1.cacheUnaryFunction, interpreters_ESBAST_1.ESBASTJInterpreter); | ||
exports.summon = summon; | ||
var tagged = tagged_union_1.makeTagged(summon); | ||
exports.tagged = tagged; |
@@ -1,3 +0,4 @@ | ||
import { M } from './interpreters-BAST'; | ||
export declare const summonAs: <L, A>(F: import("../usage/programs-infer").InferredProgram<L, A, typeof import("./program").ProgramUnionURI>) => import("../usage/materializer").Materialized<L, A, typeof import("./program").ProgramUnionURI, typeof import("./interpreters-BAST").BASTJInterpreterURI>, summonAsA: <A>() => <L>(F: import("../usage/programs-infer").InferredProgram<L, A, typeof import("./program").ProgramUnionURI>) => import("../usage/materializer").Materialized<L, A, typeof import("./program").ProgramUnionURI, typeof import("./interpreters-BAST").BASTJInterpreterURI>, summonAsL: <L>() => <A>(F: import("../usage/programs-infer").InferredProgram<L, A, typeof import("./program").ProgramUnionURI>) => import("../usage/materializer").Materialized<L, A, typeof import("./program").ProgramUnionURI, typeof import("./interpreters-BAST").BASTJInterpreterURI>, summon: <A>(F: import("../usage/programs-infer").InferredProgram<unknown, A, typeof import("./program").ProgramUnionURI>) => import("../usage/materializer").Materialized<unknown, A, typeof import("./program").ProgramUnionURI, typeof import("./interpreters-BAST").BASTJInterpreterURI>; | ||
export { M }; | ||
import { M, UM, AsOpaque, AsUOpaque } from './interpreters-BAST'; | ||
declare const summon: import("../usage/summoner").Summoners<typeof import("./program").ProgramUnionURI, typeof import("./interpreters-BAST").BASTJInterpreterURI>; | ||
declare const tagged: <Tag extends string>(tag: Tag) => <Types extends { [k in keyof Types]: import("../usage/materializer").Materialized<Types[k]["_E"], Types[k]["_A"] & { [t in Tag]: k; }, typeof import("./program").ProgramUnionURI, typeof import("./interpreters-BAST").BASTJInterpreterURI>; }>(o: Types) => import("../usage/materializer").MorphADT<Types[keyof Types]["_E"], Types[keyof Types]["_A"], import("../usage/utils").TagsOf<Types[keyof Types]["_A"]>, typeof import("./program").ProgramUnionURI, typeof import("./interpreters-BAST").BASTJInterpreterURI>; | ||
export { M, UM, AsOpaque, AsUOpaque, summon, tagged }; |
@@ -6,3 +6,8 @@ "use strict"; | ||
var interpreters_BAST_1 = require("./interpreters-BAST"); | ||
var summoner = summoner_1.makeSummoner(core_1.cacheUnaryFunction, interpreters_BAST_1.BASTJInterpreter); | ||
exports.summonAs = summoner.summonAs, exports.summonAsA = summoner.summonAsA, exports.summonAsL = summoner.summonAsL, exports.summon = summoner.summon; | ||
exports.AsOpaque = interpreters_BAST_1.AsOpaque; | ||
exports.AsUOpaque = interpreters_BAST_1.AsUOpaque; | ||
var tagged_union_1 = require("../usage/tagged-union"); | ||
var summon = summoner_1.makeSummoner(core_1.cacheUnaryFunction, interpreters_BAST_1.BASTJInterpreter); | ||
exports.summon = summon; | ||
var tagged = tagged_union_1.makeTagged(summon); | ||
exports.tagged = tagged; |
@@ -37,2 +37,20 @@ import { Kind, URIS, URIS2, Kind2 } from './HKT'; | ||
export declare type isOptionalConfig<C, Y, N> = keyof KeepNotUndefined<ByInterp<C, URIS | URIS2>> extends never ? Y : N; | ||
/** | ||
* generates a config wrapper: | ||
* | ||
* Example: | ||
* | ||
* ```typescript | ||
* const eqConfig = genConfig(EqURI) | ||
* ``` | ||
* | ||
* Usage: | ||
* | ||
* ```typescript | ||
* summonAs(F => F.unknown(eqConfig({ compare: 'default-circular' }))) | ||
* summonAs(F => F.unknown({...eqConfig({ compare: 'default-circular' }), ...iotsConfig(x => x)})) | ||
* ``` | ||
* | ||
*/ | ||
export declare const genConfig: <K extends typeof import("../fast-check-interpreters").FastCheckURI | typeof import("../json-schema-interpreters").JsonSchemaURI | typeof import("../eq-interpreters").EqURI | typeof import("../show-interpreters").ShowURI | typeof import("../ord-interpreters").OrdURI | typeof import("../io-ts-interpreters").IoTsURI>(k: K) => <T>(c: T extends { [k in K]?: infer C | undefined; } ? C : never) => T; | ||
export {}; |
@@ -24,1 +24,22 @@ "use strict"; | ||
exports.cacheUnaryFunction = cacheUnaryFunction; | ||
/** | ||
* generates a config wrapper: | ||
* | ||
* Example: | ||
* | ||
* ```typescript | ||
* const eqConfig = genConfig(EqURI) | ||
* ``` | ||
* | ||
* Usage: | ||
* | ||
* ```typescript | ||
* summonAs(F => F.unknown(eqConfig({ compare: 'default-circular' }))) | ||
* summonAs(F => F.unknown({...eqConfig({ compare: 'default-circular' }), ...iotsConfig(x => x)})) | ||
* ``` | ||
* | ||
*/ | ||
exports.genConfig = function (k) { return function (c) { | ||
var _a; | ||
return (_a = {}, _a[k] = c, _a); | ||
}; }; |
@@ -11,4 +11,7 @@ export declare const mapRecord: <Dic extends { [k in keyof Dic]: any; }, B>(d: Dic, f: (v: Dic[keyof Dic]) => B) => { [k_1 in keyof Dic]: B; }; | ||
export declare function conjunction<A, B, C, D, E, F, G, H, I>(...x: [A, B, C, D, E, F, G, H, I]): A & B & C & D & E & F & G & H & I; | ||
export declare function conjunction<A, B, C, D, E, F, G, H, I, J>(...x: [A, B, C, D, E, F, G, H, I, J]): A & B & C & D & E & F & G & H & I & J; | ||
export declare function conjunction<A, B, C, D, E, F, G, H, I, J, K>(...x: [A, B, C, D, E, F, G, H, I, J, K]): A & B & C & D & E & F & G & H & I & J & K; | ||
export declare function conjunction<A, B, C, D, E, F, G, H, I, J, K, L>(...x: [A, B, C, D, E, F, G, H, I, J, K, L]): A & B & C & D & E & F & G & H & I & J & K & L; | ||
export declare const merge: typeof conjunction; | ||
export declare const collect: <K extends string, A, B>(d: Record<K, A>, f: (k: K, a: A) => B) => B[]; | ||
export declare const memo: <A>(get: () => A) => () => A; |
"use strict"; | ||
var __spreadArrays = (this && this.__spreadArrays) || function () { | ||
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; | ||
for (var r = Array(s), k = 0, i = 0; i < il; i++) | ||
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) | ||
r[k] = a[j]; | ||
return r; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var fp_ts_1 = require("fp-ts"); | ||
@@ -20,3 +14,3 @@ exports.mapRecord = function (d, f) { return fp_ts_1.record.record.map(d, f); }; | ||
} | ||
return Object.assign.apply(Object, __spreadArrays([{}], x)); | ||
return Object.assign.apply(Object, tslib_1.__spreadArrays([{}], x)); | ||
} | ||
@@ -23,0 +17,0 @@ exports.conjunction = conjunction; |
@@ -13,1 +13,4 @@ import { Eq } from 'fp-ts/lib/Eq'; | ||
} | ||
export declare const eqConfig: <T>(c: T extends { | ||
[EqURI]?: infer C | undefined; | ||
} ? C : never) => T; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var core_1 = require("../common/core"); | ||
exports.EqURI = Symbol(); | ||
@@ -11,1 +12,2 @@ var EqType = /** @class */ (function () { | ||
exports.EqType = EqType; | ||
exports.eqConfig = core_1.genConfig(exports.EqURI); |
@@ -5,2 +5,2 @@ import { InterpreterFor } from '../common/core'; | ||
export declare const defineEqInterpreter: <O extends object>(o: O) => InterpreterFor<typeof EqURI> & O; | ||
export declare const modelEqInterpreter: InterpreterFor<typeof EqURI> & import("../model-algebras/primitives").ModelAlgebraPrimitive1<typeof EqURI> & import("../model-algebras/intersections").ModelAlgebraIntersection1<typeof EqURI> & import("../model-algebras/object").ModelAlgebraObject1<typeof EqURI> & import("../model-algebras/tagged-unions").ModelAlgebraTaggedUnions1<typeof EqURI> & import("../model-algebras/recursive").ModelAlgebraRecursive1<typeof EqURI> & import("../model-algebras/str-map").ModelAlgebraStrMap1<typeof EqURI> & import("../model-algebras/set").ModelAlgebraSet1<typeof EqURI>; | ||
export declare const modelEqInterpreter: InterpreterFor<typeof EqURI> & import("../model-algebras/refined").ModelAlgebraRefined1<typeof EqURI> & import("../model-algebras/newtype").ModelAlgebraNewtype1<typeof EqURI> & import("../model-algebras/unknown").ModelAlgebraUnknown1<typeof EqURI> & import("../model-algebras/primitives").ModelAlgebraPrimitive1<typeof EqURI> & import("../model-algebras/intersections").ModelAlgebraIntersection1<typeof EqURI> & import("../model-algebras/object").ModelAlgebraObject1<typeof EqURI> & import("../model-algebras/tagged-unions").ModelAlgebraTaggedUnions1<typeof EqURI> & import("../model-algebras/recursive").ModelAlgebraRecursive1<typeof EqURI> & import("../model-algebras/str-map").ModelAlgebraStrMap1<typeof EqURI> & import("../model-algebras/set").ModelAlgebraSet1<typeof EqURI>; |
@@ -1,1 +0,1 @@ | ||
export declare const allModelEq: import("../../model-algebras/primitives").ModelAlgebraPrimitive1<typeof import("..").EqURI> & import("../../model-algebras/intersections").ModelAlgebraIntersection1<typeof import("..").EqURI> & import("../../model-algebras/object").ModelAlgebraObject1<typeof import("..").EqURI> & import("../../model-algebras/tagged-unions").ModelAlgebraTaggedUnions1<typeof import("..").EqURI> & import("../../model-algebras/recursive").ModelAlgebraRecursive1<typeof import("..").EqURI> & import("../../model-algebras/str-map").ModelAlgebraStrMap1<typeof import("..").EqURI> & import("../../model-algebras/set").ModelAlgebraSet1<typeof import("..").EqURI>; | ||
export declare const allModelEq: import("../../model-algebras/refined").ModelAlgebraRefined1<typeof import("..").EqURI> & import("../../model-algebras/newtype").ModelAlgebraNewtype1<typeof import("..").EqURI> & import("../../model-algebras/unknown").ModelAlgebraUnknown1<typeof import("..").EqURI> & import("../../model-algebras/primitives").ModelAlgebraPrimitive1<typeof import("..").EqURI> & import("../../model-algebras/intersections").ModelAlgebraIntersection1<typeof import("..").EqURI> & import("../../model-algebras/object").ModelAlgebraObject1<typeof import("..").EqURI> & import("../../model-algebras/tagged-unions").ModelAlgebraTaggedUnions1<typeof import("..").EqURI> & import("../../model-algebras/recursive").ModelAlgebraRecursive1<typeof import("..").EqURI> & import("../../model-algebras/str-map").ModelAlgebraStrMap1<typeof import("..").EqURI> & import("../../model-algebras/set").ModelAlgebraSet1<typeof import("..").EqURI>; |
@@ -11,2 +11,5 @@ "use strict"; | ||
var set_1 = require("./set"); | ||
exports.allModelEq = utils_1.merge(primitives_1.eqPrimitiveInterpreter, intersections_1.eqIntersectionInterpreter, object_1.eqObjectInterpreter, tagged_unions_1.eqTaggedUnionInterpreter, recursive_1.eqRecursiveInterpreter, str_map_1.eqStrMapInterpreter, set_1.eqSetInterpreter); | ||
var unknown_1 = require("./unknown"); | ||
var newtype_1 = require("./newtype"); | ||
var refined_1 = require("./refined"); | ||
exports.allModelEq = utils_1.merge(refined_1.eqRefinedInterpreter, newtype_1.eqNewtypeInterpreter, unknown_1.eqUnknownInterpreter, primitives_1.eqPrimitiveInterpreter, intersections_1.eqIntersectionInterpreter, object_1.eqObjectInterpreter, tagged_unions_1.eqTaggedUnionInterpreter, recursive_1.eqRecursiveInterpreter, str_map_1.eqStrMapInterpreter, set_1.eqSetInterpreter); |
@@ -13,1 +13,4 @@ import * as fc from 'fast-check'; | ||
} | ||
export declare const fastCheckConfig: <T>(c: T extends { | ||
[FastCheckURI]?: infer C | undefined; | ||
} ? C : never) => T; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var core_1 = require("../common/core"); | ||
exports.FastCheckURI = Symbol(); | ||
@@ -11,1 +12,2 @@ var FastCheckType = /** @class */ (function () { | ||
exports.FastCheckType = FastCheckType; | ||
exports.fastCheckConfig = core_1.genConfig(exports.FastCheckURI); |
@@ -5,2 +5,2 @@ import { InterpreterFor } from '../common/core'; | ||
export declare const defineFastCheckInterpreter: <O extends object>(o: O) => InterpreterFor<typeof FastCheckURI> & O; | ||
export declare const modelFastCheckInterpreter: InterpreterFor<typeof FastCheckURI> & import("../model-algebras/primitives").ModelAlgebraPrimitive1<typeof FastCheckURI> & import("../model-algebras/intersections").ModelAlgebraIntersection1<typeof FastCheckURI> & import("../model-algebras/object").ModelAlgebraObject1<typeof FastCheckURI> & import("../model-algebras/unions").ModelAlgebraUnions1<typeof FastCheckURI> & import("../model-algebras/tagged-unions").ModelAlgebraTaggedUnions1<typeof FastCheckURI> & import("../model-algebras/recursive").ModelAlgebraRecursive1<typeof FastCheckURI> & import("../model-algebras/str-map").ModelAlgebraStrMap1<typeof FastCheckURI> & import("../model-algebras/set").ModelAlgebraSet1<typeof FastCheckURI>; | ||
export declare const modelFastCheckInterpreter: InterpreterFor<typeof FastCheckURI> & import("../model-algebras/refined").ModelAlgebraRefined1<typeof FastCheckURI> & import("../model-algebras/newtype").ModelAlgebraNewtype1<typeof FastCheckURI> & import("../model-algebras/unknown").ModelAlgebraUnknown1<typeof FastCheckURI> & import("../model-algebras/primitives").ModelAlgebraPrimitive1<typeof FastCheckURI> & import("../model-algebras/intersections").ModelAlgebraIntersection1<typeof FastCheckURI> & import("../model-algebras/object").ModelAlgebraObject1<typeof FastCheckURI> & import("../model-algebras/unions").ModelAlgebraUnions1<typeof FastCheckURI> & import("../model-algebras/tagged-unions").ModelAlgebraTaggedUnions1<typeof FastCheckURI> & import("../model-algebras/recursive").ModelAlgebraRecursive1<typeof FastCheckURI> & import("../model-algebras/str-map").ModelAlgebraStrMap1<typeof FastCheckURI> & import("../model-algebras/set").ModelAlgebraSet1<typeof FastCheckURI>; |
@@ -1,1 +0,1 @@ | ||
export declare const allModelFastCheck: import("../../model-algebras/primitives").ModelAlgebraPrimitive1<typeof import("..").FastCheckURI> & import("../../model-algebras/intersections").ModelAlgebraIntersection1<typeof import("..").FastCheckURI> & import("../../model-algebras/object").ModelAlgebraObject1<typeof import("..").FastCheckURI> & import("../../model-algebras/unions").ModelAlgebraUnions1<typeof import("..").FastCheckURI> & import("../../model-algebras/tagged-unions").ModelAlgebraTaggedUnions1<typeof import("..").FastCheckURI> & import("../../model-algebras/recursive").ModelAlgebraRecursive1<typeof import("..").FastCheckURI> & import("../../model-algebras/str-map").ModelAlgebraStrMap1<typeof import("..").FastCheckURI> & import("../../model-algebras/set").ModelAlgebraSet1<typeof import("..").FastCheckURI>; | ||
export declare const allModelFastCheck: import("../../model-algebras/refined").ModelAlgebraRefined1<typeof import("..").FastCheckURI> & import("../../model-algebras/newtype").ModelAlgebraNewtype1<typeof import("..").FastCheckURI> & import("../../model-algebras/unknown").ModelAlgebraUnknown1<typeof import("..").FastCheckURI> & import("../../model-algebras/primitives").ModelAlgebraPrimitive1<typeof import("..").FastCheckURI> & import("../../model-algebras/intersections").ModelAlgebraIntersection1<typeof import("..").FastCheckURI> & import("../../model-algebras/object").ModelAlgebraObject1<typeof import("..").FastCheckURI> & import("../../model-algebras/unions").ModelAlgebraUnions1<typeof import("..").FastCheckURI> & import("../../model-algebras/tagged-unions").ModelAlgebraTaggedUnions1<typeof import("..").FastCheckURI> & import("../../model-algebras/recursive").ModelAlgebraRecursive1<typeof import("..").FastCheckURI> & import("../../model-algebras/str-map").ModelAlgebraStrMap1<typeof import("..").FastCheckURI> & import("../../model-algebras/set").ModelAlgebraSet1<typeof import("..").FastCheckURI>; |
@@ -12,2 +12,5 @@ "use strict"; | ||
var set_1 = require("./set"); | ||
exports.allModelFastCheck = utils_1.merge(primitives_1.fastCheckPrimitiveInterpreter, intersections_1.fastCheckIntersectionInterpreter, object_1.fastCheckObjectInterpreter, unions_1.fastCheckUnionInterpreter, tagged_unions_1.fastCheckTaggedUnionInterpreter, recursive_1.fastCheckRecursiveInterpreter, str_map_1.fastCheckStrMapInterpreter, set_1.fastCheckSetInterpreter); | ||
var unknown_1 = require("./unknown"); | ||
var newtype_1 = require("./newtype"); | ||
var refined_1 = require("./refined"); | ||
exports.allModelFastCheck = utils_1.merge(refined_1.fastCheckRefinedInterpreter, newtype_1.fastCheckNewtypeInterpreter, unknown_1.fastCheckUnknownInterpreter, primitives_1.fastCheckPrimitiveInterpreter, intersections_1.fastCheckIntersectionInterpreter, object_1.fastCheckObjectInterpreter, unions_1.fastCheckUnionInterpreter, tagged_unions_1.fastCheckTaggedUnionInterpreter, recursive_1.fastCheckRecursiveInterpreter, str_map_1.fastCheckStrMapInterpreter, set_1.fastCheckSetInterpreter); |
"use strict"; | ||
var __spreadArrays = (this && this.__spreadArrays) || function () { | ||
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; | ||
for (var r = Array(s), k = 0, i = 0; i < il; i++) | ||
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) | ||
r[k] = a[j]; | ||
return r; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var fc = require("fast-check"); | ||
@@ -17,4 +11,4 @@ var __1 = require(".."); | ||
return arb; | ||
})).map(function (all) { return Object.assign.apply(Object, __spreadArrays([{}], all)); })); | ||
})).map(function (all) { return Object.assign.apply(Object, tslib_1.__spreadArrays([{}], all)); })); | ||
} | ||
}; |
import * as t from 'io-ts'; | ||
export declare const IoTsURI: unique symbol; | ||
export declare type IoTsURI = typeof IoTsURI; | ||
export declare class IOTSType<A> { | ||
type: t.Type<A, unknown>; | ||
constructor(type: t.Type<A, unknown>); | ||
export declare class IOTSType<O, A> { | ||
type: t.Type<A, O>; | ||
constructor(type: t.Type<A, O>); | ||
} | ||
declare module '../common/HKT' { | ||
interface URItoKind<A> { | ||
[IoTsURI]: IOTSType<A>; | ||
interface URItoKind2<E, A> { | ||
[IoTsURI]: IOTSType<E, A>; | ||
} | ||
} | ||
export interface IOTS<Configs> { | ||
[IoTsURI]: Configs; | ||
} | ||
export declare const iotsConfig: <T>(c: T extends { | ||
[IoTsURI]?: infer C | undefined; | ||
} ? C : never) => T; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var core_1 = require("../common/core"); | ||
exports.IoTsURI = Symbol(); | ||
@@ -11,1 +12,2 @@ var IOTSType = /** @class */ (function () { | ||
exports.IOTSType = IOTSType; | ||
exports.iotsConfig = core_1.genConfig(exports.IoTsURI); |
import { InterpreterFor } from '../common/core'; | ||
import { IoTsURI } from '.'; | ||
export { IoTsURI }; | ||
export declare const defineIoTsInterpreter: <O extends object>(o: O) => InterpreterFor<typeof IoTsURI> & O; | ||
export declare const modelIoTsStrictInterpreter: InterpreterFor<typeof IoTsURI> & import("../model-algebras/primitives").ModelAlgebraPrimitive1<typeof IoTsURI> & import("../model-algebras/intersections").ModelAlgebraIntersection1<typeof IoTsURI> & import("../model-algebras/unions").ModelAlgebraUnions1<typeof IoTsURI> & import("../model-algebras/tagged-unions").ModelAlgebraTaggedUnions1<typeof IoTsURI> & import("../model-algebras/str-map").ModelAlgebraStrMap1<typeof IoTsURI> & import("../model-algebras/set").ModelAlgebraSet1<typeof IoTsURI> & import("../model-algebras/recursive").ModelAlgebraRecursive1<typeof IoTsURI> & import("../model-algebras/object").ModelAlgebraObject1<typeof IoTsURI>; | ||
export declare const modelIoTsNonStrictInterpreter: InterpreterFor<typeof IoTsURI> & import("../model-algebras/primitives").ModelAlgebraPrimitive1<typeof IoTsURI> & import("../model-algebras/intersections").ModelAlgebraIntersection1<typeof IoTsURI> & import("../model-algebras/unions").ModelAlgebraUnions1<typeof IoTsURI> & import("../model-algebras/tagged-unions").ModelAlgebraTaggedUnions1<typeof IoTsURI> & import("../model-algebras/str-map").ModelAlgebraStrMap1<typeof IoTsURI> & import("../model-algebras/set").ModelAlgebraSet1<typeof IoTsURI> & import("../model-algebras/recursive").ModelAlgebraRecursive1<typeof IoTsURI> & import("../model-algebras/object").ModelAlgebraObject1<typeof IoTsURI>; | ||
export declare const modelIoTsNonStrictInterpreter: InterpreterFor<typeof IoTsURI> & import("../model-algebras/refined").ModelAlgebraRefined2<typeof IoTsURI> & import("../model-algebras/newtype").ModelAlgebraNewtype2<typeof IoTsURI> & import("../model-algebras/unknown").ModelAlgebraUnknown2<typeof IoTsURI> & import("../model-algebras/primitives").ModelAlgebraPrimitive2<typeof IoTsURI> & import("../model-algebras/intersections").ModelAlgebraIntersection2<typeof IoTsURI> & import("../model-algebras/unions").ModelAlgebraUnions2<typeof IoTsURI> & import("../model-algebras/tagged-unions").ModelAlgebraTaggedUnions2<typeof IoTsURI> & import("../model-algebras/str-map").ModelAlgebraStrMap2<typeof IoTsURI> & import("../model-algebras/set").ModelAlgebraSet2<typeof IoTsURI> & import("../model-algebras/recursive").ModelAlgebraRecursive2<typeof IoTsURI> & import("../model-algebras/object").ModelAlgebraObject2<typeof IoTsURI>; | ||
export declare const modelIoTsStrictInterpreter: InterpreterFor<typeof IoTsURI> & import("../model-algebras/refined").ModelAlgebraRefined2<typeof IoTsURI> & import("../model-algebras/newtype").ModelAlgebraNewtype2<typeof IoTsURI> & import("../model-algebras/unknown").ModelAlgebraUnknown2<typeof IoTsURI> & import("../model-algebras/primitives").ModelAlgebraPrimitive2<typeof IoTsURI> & import("../model-algebras/intersections").ModelAlgebraIntersection2<typeof IoTsURI> & import("../model-algebras/unions").ModelAlgebraUnions2<typeof IoTsURI> & import("../model-algebras/tagged-unions").ModelAlgebraTaggedUnions2<typeof IoTsURI> & import("../model-algebras/str-map").ModelAlgebraStrMap2<typeof IoTsURI> & import("../model-algebras/set").ModelAlgebraSet2<typeof IoTsURI> & import("../model-algebras/recursive").ModelAlgebraRecursive2<typeof IoTsURI> & import("../model-algebras/object").ModelAlgebraObject2<typeof IoTsURI>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var core_1 = require("../common/core"); | ||
var _1 = require("."); | ||
var utils_1 = require("../common/utils"); | ||
var object_1 = require("./model/object"); | ||
var _1 = require("."); | ||
exports.IoTsURI = _1.IoTsURI; | ||
var model_1 = require("./model"); | ||
exports.defineIoTsInterpreter = core_1.InterpreterFor(_1.IoTsURI); | ||
exports.modelIoTsNonStrictInterpreter = exports.defineIoTsInterpreter(utils_1.merge(model_1.allModelBaseIoTs, object_1.ioTsNonStrictObjectInterpreter // NonStrict | ||
)); | ||
exports.modelIoTsStrictInterpreter = exports.defineIoTsInterpreter(utils_1.merge(model_1.allModelBaseIoTs, object_1.ioTsStrictObjectInterpreter // Strict | ||
)); | ||
exports.modelIoTsNonStrictInterpreter = exports.defineIoTsInterpreter(utils_1.merge(model_1.allModelBaseIoTs, object_1.ioTsNonStrictObjectInterpreter // NonStrict | ||
)); |
@@ -1,1 +0,1 @@ | ||
export declare const allModelBaseIoTs: import("../../model-algebras/primitives").ModelAlgebraPrimitive1<typeof import("..").IoTsURI> & import("../../model-algebras/intersections").ModelAlgebraIntersection1<typeof import("..").IoTsURI> & import("../../model-algebras/unions").ModelAlgebraUnions1<typeof import("..").IoTsURI> & import("../../model-algebras/tagged-unions").ModelAlgebraTaggedUnions1<typeof import("..").IoTsURI> & import("../../model-algebras/str-map").ModelAlgebraStrMap1<typeof import("..").IoTsURI> & import("../../model-algebras/set").ModelAlgebraSet1<typeof import("..").IoTsURI> & import("../../model-algebras/recursive").ModelAlgebraRecursive1<typeof import("..").IoTsURI>; | ||
export declare const allModelBaseIoTs: import("../../model-algebras/refined").ModelAlgebraRefined2<typeof import("..").IoTsURI> & import("../../model-algebras/newtype").ModelAlgebraNewtype2<typeof import("..").IoTsURI> & import("../../model-algebras/unknown").ModelAlgebraUnknown2<typeof import("..").IoTsURI> & import("../../model-algebras/primitives").ModelAlgebraPrimitive2<typeof import("..").IoTsURI> & import("../../model-algebras/intersections").ModelAlgebraIntersection2<typeof import("..").IoTsURI> & import("../../model-algebras/unions").ModelAlgebraUnions2<typeof import("..").IoTsURI> & import("../../model-algebras/tagged-unions").ModelAlgebraTaggedUnions2<typeof import("..").IoTsURI> & import("../../model-algebras/str-map").ModelAlgebraStrMap2<typeof import("..").IoTsURI> & import("../../model-algebras/set").ModelAlgebraSet2<typeof import("..").IoTsURI> & import("../../model-algebras/recursive").ModelAlgebraRecursive2<typeof import("..").IoTsURI>; |
@@ -11,2 +11,5 @@ "use strict"; | ||
var recursive_1 = require("./recursive"); | ||
exports.allModelBaseIoTs = utils_1.merge(primitives_1.ioTsPrimitiveInterpreter, intersections_1.ioTsIntersectionInterpreter, unions_1.ioTsUnionInterpreter, tagged_unions_1.ioTsTaggedUnionInterpreter, str_map_1.ioTsStrMapInterpreter, set_1.ioTsSetInterpreter, recursive_1.ioTsRecursiveInterpreter); | ||
var unknown_1 = require("./unknown"); | ||
var newtype_1 = require("./newtype"); | ||
var refined_1 = require("./refined"); | ||
exports.allModelBaseIoTs = utils_1.merge(refined_1.ioTsRefinedInterpreter, newtype_1.ioTsNewtypeInterpreter, unknown_1.ioTsUnknownInterpreter, primitives_1.ioTsPrimitiveInterpreter, intersections_1.ioTsIntersectionInterpreter, unions_1.ioTsUnionInterpreter, tagged_unions_1.ioTsTaggedUnionInterpreter, str_map_1.ioTsStrMapInterpreter, set_1.ioTsSetInterpreter, recursive_1.ioTsRecursiveInterpreter); |
@@ -1,3 +0,3 @@ | ||
import { IoTsURI } from '..'; | ||
import { ModelAlgebraIntersection1 } from '../../model-algebras/intersections'; | ||
export declare const ioTsIntersectionInterpreter: ModelAlgebraIntersection1<IoTsURI>; | ||
import { IoTsURI } from '../index'; | ||
import { ModelAlgebraIntersection2 } from '../../model-algebras/intersections'; | ||
export declare const ioTsIntersectionInterpreter: ModelAlgebraIntersection2<IoTsURI>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var t = require("io-ts"); | ||
var __1 = require(".."); | ||
var index_1 = require("../index"); | ||
exports.ioTsIntersectionInterpreter = { | ||
intersection: function (items, name) { | ||
return new __1.IOTSType(t.intersection(items.map(function (x) { return x.type; }), name)); | ||
return new index_1.IOTSType(t.intersection(items.map(function (x) { return x.type; }), name)); | ||
} // TODO: fix (follow up: https://github.com/gcanti/io-ts/issues/312) | ||
}; |
@@ -1,8 +0,4 @@ | ||
import * as t from 'io-ts'; | ||
import { IoTsURI } from '..'; | ||
import { ModelAlgebraObject1 } from '../../model-algebras/object'; | ||
export declare type IOTypes<Props> = { | ||
[k in keyof Props]: t.Type<Props[k], unknown>; | ||
}; | ||
export declare const ioTsNonStrictObjectInterpreter: ModelAlgebraObject1<IoTsURI>; | ||
export declare const ioTsStrictObjectInterpreter: ModelAlgebraObject1<IoTsURI>; | ||
import { ModelAlgebraObject2 } from '../../model-algebras/object'; | ||
export declare const ioTsNonStrictObjectInterpreter: ModelAlgebraObject2<IoTsURI>; | ||
export declare const ioTsStrictObjectInterpreter: ModelAlgebraObject2<IoTsURI>; |
@@ -7,18 +7,16 @@ "use strict"; | ||
exports.ioTsNonStrictObjectInterpreter = { | ||
interface: function (props, name, _config) { | ||
var interfaceType = t.type(utils_1.projectField(props)('type'), name); | ||
return new __1.IOTSType(interfaceType); | ||
interface: function (props, name) { | ||
return new __1.IOTSType(t.type(utils_1.projectField(props)('type'), name)); | ||
}, | ||
partial: function (props, name, _config) { | ||
var interfaceType = t.partial(utils_1.projectField(props)('type'), name); | ||
return new __1.IOTSType(interfaceType); | ||
partial: function (props, name) { | ||
return new __1.IOTSType(t.partial(utils_1.projectField(props)('type'), name)); | ||
} | ||
}; | ||
exports.ioTsStrictObjectInterpreter = { | ||
interface: function (props, name, _config) { | ||
interface: function (props, name) { | ||
return new __1.IOTSType(t.strict(utils_1.projectField(props)('type'), name)); | ||
}, | ||
partial: function (props, name, _config) { | ||
partial: function (props, name) { | ||
return new __1.IOTSType(t.exact(t.partial(utils_1.projectField(props)('type'), name))); | ||
} | ||
}; |
import * as t from 'io-ts'; | ||
import { IoTsURI } from '..'; | ||
import { ModelAlgebraPrimitive1 } from '../../model-algebras/primitives'; | ||
import { ModelAlgebraPrimitive2 } from '../../model-algebras/primitives'; | ||
declare module '../../algebras/hkt' { | ||
interface PrimitiveConfig { | ||
[IoTsURI]: Customize<string> | undefined; | ||
[IoTsURI]: Customize<string, string> | undefined; | ||
} | ||
interface PrimitiveDateConfig { | ||
[IoTsURI]: Customize<Date> | undefined; | ||
[IoTsURI]: Customize<string, Date> | undefined; | ||
} | ||
interface PrimitiveStringConfig { | ||
[IoTsURI]: Customize<string> | undefined; | ||
[IoTsURI]: Customize<string, string> | undefined; | ||
} | ||
interface PrimitiveNumberConfig { | ||
[IoTsURI]: Customize<number> | undefined; | ||
[IoTsURI]: Customize<number, number> | undefined; | ||
} | ||
interface PrimitiveBooleanConfig { | ||
[IoTsURI]: Customize<boolean> | undefined; | ||
[IoTsURI]: Customize<boolean, boolean> | undefined; | ||
} | ||
interface PrimitiveArrayConfig<A> { | ||
[IoTsURI]: Customize<A[]> | undefined; | ||
interface PrimitiveArrayConfig2<E, A> { | ||
[IoTsURI]: Customize<E[], A[]> | undefined; | ||
} | ||
} | ||
interface Customize<A> { | ||
(a: t.Type<A, unknown, unknown>): t.Type<A, unknown, unknown>; | ||
interface Customize<E, A> { | ||
(a: t.Type<A, E, unknown>): t.Type<A, E, unknown>; | ||
} | ||
export declare const ioTsPrimitiveInterpreter: ModelAlgebraPrimitive1<IoTsURI>; | ||
export declare const ioTsPrimitiveInterpreter: ModelAlgebraPrimitive2<IoTsURI>; | ||
export {}; |
import { IoTsURI } from '..'; | ||
import { ModelAlgebraRecursive1 } from '../../model-algebras/recursive'; | ||
export declare const ioTsRecursiveInterpreter: ModelAlgebraRecursive1<IoTsURI>; | ||
import { ModelAlgebraRecursive2 } from '../../model-algebras/recursive'; | ||
export declare const ioTsRecursiveInterpreter: ModelAlgebraRecursive2<IoTsURI>; |
import { IoTsURI } from '..'; | ||
import { ModelAlgebraSet1 } from '../../model-algebras/set'; | ||
export declare const ioTsSetInterpreter: ModelAlgebraSet1<IoTsURI>; | ||
import { ModelAlgebraSet2 } from '../../model-algebras/set'; | ||
export declare const ioTsSetInterpreter: ModelAlgebraSet2<IoTsURI>; |
import { IoTsURI } from '..'; | ||
import { ModelAlgebraStrMap1 } from '../../model-algebras/str-map'; | ||
export declare const ioTsStrMapInterpreter: ModelAlgebraStrMap1<IoTsURI>; | ||
import { ModelAlgebraStrMap2 } from '../../model-algebras/str-map'; | ||
export declare const ioTsStrMapInterpreter: ModelAlgebraStrMap2<IoTsURI>; |
import { IoTsURI } from '..'; | ||
import { ModelAlgebraTaggedUnions1 } from '../../model-algebras/tagged-unions'; | ||
export declare const ioTsTaggedUnionInterpreter: ModelAlgebraTaggedUnions1<IoTsURI>; | ||
import { ModelAlgebraTaggedUnions2 } from '../../model-algebras/tagged-unions'; | ||
export declare const ioTsTaggedUnionInterpreter: ModelAlgebraTaggedUnions2<IoTsURI>; |
import { IoTsURI } from '..'; | ||
import { ModelAlgebraUnions1 } from '../../model-algebras/unions'; | ||
export declare const ioTsUnionInterpreter: ModelAlgebraUnions1<IoTsURI>; | ||
import { ModelAlgebraUnions2 } from '../../model-algebras/unions'; | ||
export declare const ioTsUnionInterpreter: ModelAlgebraUnions2<IoTsURI>; |
@@ -6,3 +6,5 @@ "use strict"; | ||
exports.ioTsUnionInterpreter = { | ||
union: function (items, name) { return new __1.IOTSType(t.union(items.map(function (x) { return x.type; }), name)); } // TODO: fix (follow up: https://github.com/gcanti/io-ts/issues/312) | ||
union: function (items, name) { | ||
return new __1.IOTSType(t.union(items.map(function (x) { return x.type; }), name)); | ||
} // TODO: fix (follow up: https://github.com/gcanti/io-ts/issues/312) | ||
}; |
@@ -13,2 +13,3 @@ import { OptionalJSONSchema, JsonSchemaError } from '../json-schema/json-schema-ctors'; | ||
schema: JsonSchemaResult<OptionalJSONSchema>; | ||
_A: A; | ||
constructor(schema: JsonSchemaResult<OptionalJSONSchema>); | ||
@@ -21,1 +22,4 @@ } | ||
} | ||
export declare const jsonSchemaConfig: <T>(c: T extends { | ||
[JsonSchemaURI]?: infer C | undefined; | ||
} ? C : never) => T; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var core_1 = require("../common/core"); | ||
exports.JsonSchemaURI = Symbol(); | ||
@@ -11,1 +12,2 @@ var JsonSchema = /** @class */ (function () { | ||
exports.JsonSchema = JsonSchema; | ||
exports.jsonSchemaConfig = core_1.genConfig(exports.JsonSchemaURI); |
@@ -5,2 +5,2 @@ import { InterpreterFor } from '../common/core'; | ||
export declare const defineJsonSchemaInterpreter: <O extends object>(o: O) => InterpreterFor<typeof JsonSchemaURI> & O; | ||
export declare const modelJsonSchemaInterpreter: InterpreterFor<typeof JsonSchemaURI> & import("../model-algebras/primitives").ModelAlgebraPrimitive1<typeof JsonSchemaURI> & import("../model-algebras/intersections").ModelAlgebraIntersection1<typeof JsonSchemaURI> & import("../model-algebras/object").ModelAlgebraObject1<typeof JsonSchemaURI> & import("../model-algebras/tagged-unions").ModelAlgebraTaggedUnions1<typeof JsonSchemaURI> & import("../model-algebras/recursive").ModelAlgebraRecursive1<typeof JsonSchemaURI> & import("../model-algebras/str-map").ModelAlgebraStrMap1<typeof JsonSchemaURI> & import("../model-algebras/set").ModelAlgebraSet1<typeof JsonSchemaURI> & import("../model-algebras/unions").ModelAlgebraUnions1<typeof JsonSchemaURI>; | ||
export declare const modelJsonSchemaInterpreter: InterpreterFor<typeof JsonSchemaURI> & import("../model-algebras/refined").ModelAlgebraRefined1<typeof JsonSchemaURI> & import("../model-algebras/newtype").ModelAlgebraNewtype1<typeof JsonSchemaURI> & import("../model-algebras/unknown").ModelAlgebraUnknown1<typeof JsonSchemaURI> & import("../model-algebras/primitives").ModelAlgebraPrimitive1<typeof JsonSchemaURI> & import("../model-algebras/intersections").ModelAlgebraIntersection1<typeof JsonSchemaURI> & import("../model-algebras/object").ModelAlgebraObject1<typeof JsonSchemaURI> & import("../model-algebras/tagged-unions").ModelAlgebraTaggedUnions1<typeof JsonSchemaURI> & import("../model-algebras/recursive").ModelAlgebraRecursive1<typeof JsonSchemaURI> & import("../model-algebras/str-map").ModelAlgebraStrMap1<typeof JsonSchemaURI> & import("../model-algebras/set").ModelAlgebraSet1<typeof JsonSchemaURI> & import("../model-algebras/unions").ModelAlgebraUnions1<typeof JsonSchemaURI>; |
@@ -1,1 +0,1 @@ | ||
export declare const allModelJsonSchema: import("../../model-algebras/primitives").ModelAlgebraPrimitive1<typeof import("..").JsonSchemaURI> & import("../../model-algebras/intersections").ModelAlgebraIntersection1<typeof import("..").JsonSchemaURI> & import("../../model-algebras/object").ModelAlgebraObject1<typeof import("..").JsonSchemaURI> & import("../../model-algebras/tagged-unions").ModelAlgebraTaggedUnions1<typeof import("..").JsonSchemaURI> & import("../../model-algebras/recursive").ModelAlgebraRecursive1<typeof import("..").JsonSchemaURI> & import("../../model-algebras/str-map").ModelAlgebraStrMap1<typeof import("..").JsonSchemaURI> & import("../../model-algebras/set").ModelAlgebraSet1<typeof import("..").JsonSchemaURI> & import("../../model-algebras/unions").ModelAlgebraUnions1<typeof import("..").JsonSchemaURI>; | ||
export declare const allModelJsonSchema: import("../../model-algebras/refined").ModelAlgebraRefined1<typeof import("..").JsonSchemaURI> & import("../../model-algebras/newtype").ModelAlgebraNewtype1<typeof import("..").JsonSchemaURI> & import("../../model-algebras/unknown").ModelAlgebraUnknown1<typeof import("..").JsonSchemaURI> & import("../../model-algebras/primitives").ModelAlgebraPrimitive1<typeof import("..").JsonSchemaURI> & import("../../model-algebras/intersections").ModelAlgebraIntersection1<typeof import("..").JsonSchemaURI> & import("../../model-algebras/object").ModelAlgebraObject1<typeof import("..").JsonSchemaURI> & import("../../model-algebras/tagged-unions").ModelAlgebraTaggedUnions1<typeof import("..").JsonSchemaURI> & import("../../model-algebras/recursive").ModelAlgebraRecursive1<typeof import("..").JsonSchemaURI> & import("../../model-algebras/str-map").ModelAlgebraStrMap1<typeof import("..").JsonSchemaURI> & import("../../model-algebras/set").ModelAlgebraSet1<typeof import("..").JsonSchemaURI> & import("../../model-algebras/unions").ModelAlgebraUnions1<typeof import("..").JsonSchemaURI>; |
@@ -12,2 +12,5 @@ "use strict"; | ||
var unions_1 = require("./unions"); | ||
exports.allModelJsonSchema = utils_1.merge(primitives_1.jsonSchemaPrimitiveInterpreter, intersections_1.jsonSchemaIntersectionInterpreter, object_1.jsonSchemaObjectInterpreter, tagged_unions_1.jsonSchemaTaggedUnionInterpreter, recursive_1.jsonSchemaRecursiveInterpreter, str_map_1.jsonSchemaStrMapInterpreter, set_1.jsonSchemaSetInterpreter, unions_1.jsonSchemaUnionInterpreter); | ||
var unknown_1 = require("./unknown"); | ||
var newtype_1 = require("./newtype"); | ||
var refined_1 = require("./refined"); | ||
exports.allModelJsonSchema = utils_1.merge(refined_1.jsonSchemaRefinedInterpreter, newtype_1.jsonSchemaNewtypeInterpreter, unknown_1.jsonSchemaUnknownInterpreter, primitives_1.jsonSchemaPrimitiveInterpreter, intersections_1.jsonSchemaIntersectionInterpreter, object_1.jsonSchemaObjectInterpreter, tagged_unions_1.jsonSchemaTaggedUnionInterpreter, recursive_1.jsonSchemaRecursiveInterpreter, str_map_1.jsonSchemaStrMapInterpreter, set_1.jsonSchemaSetInterpreter, unions_1.jsonSchemaUnionInterpreter); |
@@ -10,3 +10,3 @@ "use strict"; | ||
exports.jsonSchemaTaggedUnionInterpreter = { | ||
taggedUnion: function (tag, types) { | ||
taggedUnion: function (_tag, types) { | ||
return new __1.JsonSchema(pipeable_1.pipe(utils_1.arrayTraverseStateEither(fp_ts_1.record.toArray(types), function (_a) { | ||
@@ -13,0 +13,0 @@ var _ = _a[0], v = _a[1]; |
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var E = require("fp-ts/lib/Either"); | ||
@@ -134,3 +124,3 @@ var StateT_1 = require("fp-ts/lib/StateT"); | ||
*/ | ||
exports.stateEitherSeq = __assign(__assign({}, exports.stateEither), { ap: function (mab, ma) { return T.chain(mab, function (f) { return T.map(ma, f); }); } }); | ||
exports.stateEitherSeq = tslib_1.__assign(tslib_1.__assign({}, exports.stateEither), { ap: function (mab, ma) { return T.chain(mab, function (f) { return T.map(ma, f); }); } }); | ||
var _a = pipeable_1.pipeable(exports.stateEither), ap = _a.ap, apFirst = _a.apFirst, apSecond = _a.apSecond, chain = _a.chain, chainFirst = _a.chainFirst, flatten = _a.flatten, map = _a.map, filterOrElse = _a.filterOrElse, fromEither = _a.fromEither, fromOption = _a.fromOption, fromPredicate = _a.fromPredicate; | ||
@@ -137,0 +127,0 @@ exports.ap = ap; |
@@ -9,3 +9,3 @@ import { OptionalJSONSchema, JsonSchemaError } from '../json-schema/json-schema-ctors'; | ||
export declare const addSchema: (name: string) => (schema: JSONSchema) => JsonSchemaResult<void>; | ||
export declare const registerSchema: (name: string) => <R, E>(v: OptionalJSONSchema) => SE.StateEither<NamedSchemas, NonEmptyArray<JsonSchemaError>, OptionalJSONSchema>; | ||
export declare const registerSchema: (name: string) => (v: OptionalJSONSchema) => SE.StateEither<NamedSchemas, NonEmptyArray<JsonSchemaError>, OptionalJSONSchema>; | ||
export declare const getSchema: (name: string) => JsonSchemaResult<O.Option<JSONSchema>>; | ||
@@ -12,0 +12,0 @@ export declare const getSchemaStrict: (name: string) => JsonSchemaResult<JSONSchema>; |
@@ -27,2 +27,3 @@ import * as js from './json-schema'; | ||
}) => OptionalJSONSchema; | ||
export declare const AnythingTypeCtor: () => OptionalJSONSchema; | ||
export declare const StringTypeCtor: (extras?: { | ||
@@ -29,0 +30,0 @@ format?: "date-time" | "date" | undefined; |
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __spreadArrays = (this && this.__spreadArrays) || function () { | ||
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; | ||
for (var r = Array(s), k = 0, i = 0; i < il; i++) | ||
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) | ||
r[k] = a[j]; | ||
return r; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var A = require("fp-ts/lib/Array"); | ||
@@ -101,4 +84,5 @@ var js = require("./json-schema"); | ||
}; | ||
exports.AnythingTypeCtor = function () { return exports.notOptional({}); }; | ||
exports.StringTypeCtor = function (extras) { | ||
return exports.notOptional(__assign({ type: 'string' }, (extras !== undefined ? extras : {}))); | ||
return exports.notOptional(tslib_1.__assign({ type: 'string' }, (extras !== undefined ? extras : {}))); | ||
}; | ||
@@ -131,3 +115,3 @@ exports.NumberTypeCtor = function () { | ||
var obj = { type: 'object', properties: properties }; | ||
return exports.notOptional(required.length === 0 ? obj : __assign(__assign({}, obj), { required: required })); | ||
return exports.notOptional(required.length === 0 ? obj : tslib_1.__assign(tslib_1.__assign({}, obj), { required: required })); | ||
}; | ||
@@ -137,8 +121,8 @@ var magmaObjectSchema = { | ||
// tslint:disable-next-line: strict-boolean-expressions | ||
var oneOf = __spreadArrays((a.oneOf || []), (b.oneOf || [])); | ||
var properties = __assign(__assign({}, (a.properties || {})), (b.properties || {})); | ||
var oneOf = tslib_1.__spreadArrays((a.oneOf || []), (b.oneOf || [])); | ||
var properties = tslib_1.__assign(tslib_1.__assign({}, (a.properties || {})), (b.properties || {})); | ||
// tslint:disable-next-line: strict-boolean-expressions | ||
var required = __spreadArrays((a.required || []), (b.required || [])); | ||
var required = tslib_1.__spreadArrays((a.required || []), (b.required || [])); | ||
// tslint:disable-next-line: strict-boolean-expressions | ||
return Object.assign.apply(Object, __spreadArrays([{ | ||
return Object.assign.apply(Object, tslib_1.__spreadArrays([{ | ||
type: 'object', | ||
@@ -145,0 +129,0 @@ required: required |
@@ -90,2 +90,4 @@ import * as m from 'monocle-ts'; | ||
export declare const SubSchema: (x: SubSchema) => SubSchema; | ||
export declare type Anything = {}; | ||
export declare const Anything: Anything; | ||
export declare type JSONSchema = StringSchema | NumberSchema | BooleanSchema | ArraySchema | ObjectSchema | (EnumSchema & { | ||
@@ -92,0 +94,0 @@ $schema?: string; |
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var m = require("monocle-ts"); | ||
var Option_1 = require("fp-ts/lib/Option"); | ||
exports.StringSchema = function (x) { return (__assign({ type: 'string' }, (x === undefined ? {} : x))); }; | ||
exports.EnumSchema = function (p) { return (__assign({ type: 'string' }, p)); }; | ||
exports.StringSchema = function (x) { return (tslib_1.__assign({ type: 'string' }, (x === undefined ? {} : x))); }; | ||
exports.EnumSchema = function (p) { return (tslib_1.__assign({ type: 'string' }, p)); }; | ||
exports.isEnumSchema = function (x) { | ||
return x.type === 'string' && Array.isArray(x.enum); | ||
}; | ||
exports.NumberSchema = function (x) { return (__assign({ type: 'number' }, (x === undefined ? {} : x))); }; | ||
exports.BooleanSchema = function (p) { return (__assign({ type: 'boolean' }, p)); }; | ||
exports.ArraySchema = function (p) { return (__assign({ type: 'array' }, p)); }; | ||
exports.NumberSchema = function (x) { return (tslib_1.__assign({ type: 'number' }, (x === undefined ? {} : x))); }; | ||
exports.BooleanSchema = function (p) { return (tslib_1.__assign({ type: 'boolean' }, p)); }; | ||
exports.ArraySchema = function (p) { return (tslib_1.__assign({ type: 'array' }, p)); }; | ||
exports.itemsOfArrayLense = m.Lens.fromProp()('items'); | ||
exports.Ref = function ($ref) { return ({ $ref: $ref }); }; | ||
exports.objectSchemaOnRequired = m.Lens.fromProp()('required'); | ||
exports.ObjectSchema = function (x) { return (__assign({ type: 'object' }, x)); }; | ||
exports.ObjectSchema = function (x) { return (tslib_1.__assign({ type: 'object' }, x)); }; | ||
exports.isObjectSchema = function (x) { return 'type' in x && x.type === 'object'; }; | ||
exports.jsonToObjectSchemaPrism = m.Prism.fromPredicate(exports.isObjectSchema); | ||
exports.SubSchema = function (x) { return x; }; | ||
exports.Anything = {}; | ||
exports.isTypeObject = function (schema) { | ||
@@ -32,0 +23,0 @@ return !exports.isTypeRef(schema) && (schema.type === 'object' || schema.hasOwnProperty('properties')); |
@@ -37,14 +37,6 @@ import { URIS, Kind, URIS2, Kind2, HKT2 } from '../common/HKT'; | ||
[o in keyof Types]: DecorateTag<Types[o], Tag, o>; | ||
}, name: string): isOptionalConfig<TaggedUnionConfig, HKT2<F, { | ||
[k in keyof Types]: Types[k]['_E']; | ||
}[keyof Types], { | ||
[k in keyof Types]: Types[k]['_A']; | ||
}[keyof Types]>, 'Requiring some config via taggedUnion(..., { <Interp>: ... })'>; | ||
}, name: string): isOptionalConfig<TaggedUnionConfig, HKT2<F, Types[keyof Types]['_E'], Types[keyof Types]['_A']>, 'Requiring some config via taggedUnion(..., { <Interp>: ... })'>; | ||
taggedUnion<Tag extends string, Types extends TaggedTypes<F, Tag, any, any>>(tag: Tag, types: Types & { | ||
[o in keyof Types]: DecorateTag<Types[o], Tag, o>; | ||
}, name: string, config: ByInterp<TaggedUnionConfig, URIS | URIS2>): HKT2<F, { | ||
[k in keyof Types]: Types[k]['_E']; | ||
}[keyof Types], { | ||
[k in keyof Types]: Types[k]['_A']; | ||
}[keyof Types]>; | ||
}, name: string, config: ByInterp<TaggedUnionConfig, URIS | URIS2>): HKT2<F, Types[keyof Types]['_E'], Types[keyof Types]['_A']>; | ||
} | ||
@@ -51,0 +43,0 @@ export declare type TaggedTypes1<F extends URIS, Tag extends string, O> = { |
@@ -13,1 +13,4 @@ import { Ord } from 'fp-ts/lib/Ord'; | ||
} | ||
export declare const ordConfig: <T>(c: T extends { | ||
[OrdURI]?: infer C | undefined; | ||
} ? C : never) => T; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var core_1 = require("../common/core"); | ||
exports.OrdURI = Symbol(); | ||
@@ -11,1 +12,2 @@ var OrdType = /** @class */ (function () { | ||
exports.OrdType = OrdType; | ||
exports.ordConfig = core_1.genConfig(exports.OrdURI); |
@@ -5,2 +5,2 @@ import { InterpreterFor } from '../common/core'; | ||
export declare const defineOrdInterpreter: <O extends object>(o: O) => InterpreterFor<typeof OrdURI> & O; | ||
export declare const modelOrdInterpreter: InterpreterFor<typeof OrdURI> & import("../model-algebras/primitives").ModelAlgebraPrimitive1<typeof OrdURI> & import("../model-algebras/intersections").ModelAlgebraIntersection1<typeof OrdURI> & import("../model-algebras/set").ModelAlgebraSet1<typeof OrdURI> & import("../model-algebras/str-map").ModelAlgebraStrMap1<typeof OrdURI> & import("../model-algebras/tagged-unions").ModelAlgebraTaggedUnions1<typeof OrdURI>; | ||
export declare const modelOrdInterpreter: InterpreterFor<typeof OrdURI> & import("../model-algebras/refined").ModelAlgebraRefined1<typeof OrdURI> & import("../model-algebras/newtype").ModelAlgebraNewtype1<typeof OrdURI> & import("../model-algebras/primitives").ModelAlgebraPrimitive1<typeof OrdURI> & import("../model-algebras/intersections").ModelAlgebraIntersection1<typeof OrdURI> & import("../model-algebras/set").ModelAlgebraSet1<typeof OrdURI> & import("../model-algebras/str-map").ModelAlgebraStrMap1<typeof OrdURI> & import("../model-algebras/tagged-unions").ModelAlgebraTaggedUnions1<typeof OrdURI>; |
@@ -1,1 +0,1 @@ | ||
export declare const allModelOrd: import("../../model-algebras/primitives").ModelAlgebraPrimitive1<typeof import("..").OrdURI> & import("../../model-algebras/intersections").ModelAlgebraIntersection1<typeof import("..").OrdURI> & import("../../model-algebras/set").ModelAlgebraSet1<typeof import("..").OrdURI> & import("../../model-algebras/str-map").ModelAlgebraStrMap1<typeof import("..").OrdURI> & import("../../model-algebras/tagged-unions").ModelAlgebraTaggedUnions1<typeof import("..").OrdURI>; | ||
export declare const allModelOrd: import("../../model-algebras/refined").ModelAlgebraRefined1<typeof import("..").OrdURI> & import("../../model-algebras/newtype").ModelAlgebraNewtype1<typeof import("..").OrdURI> & import("../../model-algebras/primitives").ModelAlgebraPrimitive1<typeof import("..").OrdURI> & import("../../model-algebras/intersections").ModelAlgebraIntersection1<typeof import("..").OrdURI> & import("../../model-algebras/set").ModelAlgebraSet1<typeof import("..").OrdURI> & import("../../model-algebras/str-map").ModelAlgebraStrMap1<typeof import("..").OrdURI> & import("../../model-algebras/tagged-unions").ModelAlgebraTaggedUnions1<typeof import("..").OrdURI>; |
@@ -9,2 +9,4 @@ "use strict"; | ||
var tagged_unions_1 = require("./tagged-unions"); | ||
exports.allModelOrd = utils_1.merge(primitives_1.ordPrimitiveInterpreter, intersections_1.ordIntersectionInterpreter, set_1.ordSetInterpreter, str_map_1.ordStrMapInterpreter, tagged_unions_1.ordTaggedUnionInterpreter); | ||
var newtype_1 = require("./newtype"); | ||
var refined_1 = require("./refined"); | ||
exports.allModelOrd = utils_1.merge(refined_1.ordRefinedInterpreter, newtype_1.ordNewtypeInterpreter, primitives_1.ordPrimitiveInterpreter, intersections_1.ordIntersectionInterpreter, set_1.ordSetInterpreter, str_map_1.ordStrMapInterpreter, tagged_unions_1.ordTaggedUnionInterpreter); |
@@ -13,1 +13,4 @@ import { Show } from 'fp-ts/lib/Show'; | ||
} | ||
export declare const showConfig: <T>(c: T extends { | ||
[ShowURI]?: infer C | undefined; | ||
} ? C : never) => T; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var core_1 = require("../common/core"); | ||
exports.ShowURI = Symbol(); | ||
@@ -11,1 +12,2 @@ var ShowType = /** @class */ (function () { | ||
exports.ShowType = ShowType; | ||
exports.showConfig = core_1.genConfig(exports.ShowURI); |
@@ -5,2 +5,2 @@ import { InterpreterFor } from '../common/core'; | ||
export declare const defineShowInterpreter: <O extends object>(o: O) => InterpreterFor<typeof ShowURI> & O; | ||
export declare const modelShowInterpreter: InterpreterFor<typeof ShowURI> & import("../model-algebras/primitives").ModelAlgebraPrimitive1<typeof ShowURI> & import("../model-algebras/intersections").ModelAlgebraIntersection1<typeof ShowURI> & import("../model-algebras/object").ModelAlgebraObject1<typeof ShowURI> & import("../model-algebras/tagged-unions").ModelAlgebraTaggedUnions1<typeof ShowURI> & import("../model-algebras/recursive").ModelAlgebraRecursive1<typeof ShowURI> & import("../model-algebras/set").ModelAlgebraSet1<typeof ShowURI> & import("../model-algebras/str-map").ModelAlgebraStrMap1<typeof ShowURI>; | ||
export declare const modelShowInterpreter: InterpreterFor<typeof ShowURI> & import("../model-algebras/refined").ModelAlgebraRefined1<typeof ShowURI> & import("../model-algebras/newtype").ModelAlgebraNewtype1<typeof ShowURI> & import("../model-algebras/unknown").ModelAlgebraUnknown1<typeof ShowURI> & import("../model-algebras/primitives").ModelAlgebraPrimitive1<typeof ShowURI> & import("../model-algebras/intersections").ModelAlgebraIntersection1<typeof ShowURI> & import("../model-algebras/object").ModelAlgebraObject1<typeof ShowURI> & import("../model-algebras/tagged-unions").ModelAlgebraTaggedUnions1<typeof ShowURI> & import("../model-algebras/recursive").ModelAlgebraRecursive1<typeof ShowURI> & import("../model-algebras/set").ModelAlgebraSet1<typeof ShowURI> & import("../model-algebras/str-map").ModelAlgebraStrMap1<typeof ShowURI>; |
@@ -1,1 +0,1 @@ | ||
export declare const allModelShow: import("../../model-algebras/primitives").ModelAlgebraPrimitive1<typeof import("..").ShowURI> & import("../../model-algebras/intersections").ModelAlgebraIntersection1<typeof import("..").ShowURI> & import("../../model-algebras/object").ModelAlgebraObject1<typeof import("..").ShowURI> & import("../../model-algebras/tagged-unions").ModelAlgebraTaggedUnions1<typeof import("..").ShowURI> & import("../../model-algebras/recursive").ModelAlgebraRecursive1<typeof import("..").ShowURI> & import("../../model-algebras/set").ModelAlgebraSet1<typeof import("..").ShowURI> & import("../../model-algebras/str-map").ModelAlgebraStrMap1<typeof import("..").ShowURI>; | ||
export declare const allModelShow: import("../../model-algebras/refined").ModelAlgebraRefined1<typeof import("..").ShowURI> & import("../../model-algebras/newtype").ModelAlgebraNewtype1<typeof import("..").ShowURI> & import("../../model-algebras/unknown").ModelAlgebraUnknown1<typeof import("..").ShowURI> & import("../../model-algebras/primitives").ModelAlgebraPrimitive1<typeof import("..").ShowURI> & import("../../model-algebras/intersections").ModelAlgebraIntersection1<typeof import("..").ShowURI> & import("../../model-algebras/object").ModelAlgebraObject1<typeof import("..").ShowURI> & import("../../model-algebras/tagged-unions").ModelAlgebraTaggedUnions1<typeof import("..").ShowURI> & import("../../model-algebras/recursive").ModelAlgebraRecursive1<typeof import("..").ShowURI> & import("../../model-algebras/set").ModelAlgebraSet1<typeof import("..").ShowURI> & import("../../model-algebras/str-map").ModelAlgebraStrMap1<typeof import("..").ShowURI>; |
@@ -11,2 +11,5 @@ "use strict"; | ||
var str_map_1 = require("./str-map"); | ||
exports.allModelShow = utils_1.merge(primitives_1.showPrimitiveInterpreter, intersections_1.showIntersectionInterpreter, object_1.showObjectInterpreter, tagged_unions_1.showTaggedUnionInterpreter, recursive_1.showRecursiveInterpreter, set_1.showSetInterpreter, str_map_1.showStrMapInterpreter); | ||
var unknown_1 = require("./unknown"); | ||
var newtype_1 = require("./newtype"); | ||
var refined_1 = require("./refined"); | ||
exports.allModelShow = utils_1.merge(refined_1.showRefinedInterpreter, newtype_1.showNewtypeInterpreter, unknown_1.showUnknownInterpreter, primitives_1.showPrimitiveInterpreter, intersections_1.showIntersectionInterpreter, object_1.showObjectInterpreter, tagged_unions_1.showTaggedUnionInterpreter, recursive_1.showRecursiveInterpreter, set_1.showSetInterpreter, str_map_1.showStrMapInterpreter); |
@@ -12,3 +12,3 @@ import { InterpreterURIOfProgramInterpreter } from './materializer'; | ||
*/ | ||
static of<ProgURI extends ProgramURI>(p: ProgURI): Extension<ProgURI, {}>; | ||
static of<ProgURI extends ProgramURI>(_p: ProgURI): Extension<ProgURI, {}>; | ||
/** | ||
@@ -15,0 +15,0 @@ * Extends the current algebra with new definitions |
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var Extension = /** @class */ (function () { | ||
@@ -21,3 +11,3 @@ function Extension(ext) { | ||
*/ | ||
Extension.of = function (p) { | ||
Extension.of = function (_p) { | ||
return new Extension({}); | ||
@@ -29,3 +19,3 @@ }; | ||
Extension.prototype.with = function (o) { | ||
return new Extension(__assign(__assign({}, this.ext), o)); | ||
return new Extension(tslib_1.__assign(tslib_1.__assign({}, this.ext), o)); | ||
}; | ||
@@ -43,3 +33,3 @@ /** | ||
var _this = this; | ||
return function (prog) { return int(function (alg) { return prog(__assign(__assign({}, alg), _this.ext)); }); }; | ||
return function (prog) { return int(function (alg) { return prog(tslib_1.__assign(tslib_1.__assign({}, alg), _this.ext)); }); }; | ||
}; | ||
@@ -46,0 +36,0 @@ return Extension; |
@@ -0,1 +1,2 @@ | ||
import { SelectKeyOfMatchingValues } from './utils'; | ||
export interface InterpreterResult<E, A> extends Record<keyof InterpreterResult<any, any>, { | ||
@@ -6,1 +7,2 @@ build: (x: A) => A; | ||
export declare type InterpreterURI = keyof InterpreterResult<any, any>; | ||
export declare type SelectInterpURIs<E, A, ShapeConstraint> = SelectKeyOfMatchingValues<InterpreterResult<E, A>, ShapeConstraint>; |
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var utils_1 = require("./utils"); | ||
@@ -36,3 +26,3 @@ var adt_1 = require("../adt"); | ||
function asADT(m, tag, keys) { | ||
return assignCallable(wrapFun(m), __assign(__assign({}, m), adt_1.makeADT(tag)(keys))); | ||
return assignCallable(wrapFun(m), tslib_1.__assign(tslib_1.__assign({}, m), adt_1.makeADT(tag)(keys))); | ||
} | ||
@@ -46,4 +36,4 @@ function withTaggableAndMonocle(morphes) { | ||
}; | ||
var res = assignCallable(morphes, __assign({ tagged: tagged }, monocle_1.MonocleFor())); | ||
var res = assignCallable(morphes, tslib_1.__assign({ tagged: tagged }, monocle_1.MonocleFor())); | ||
return res; | ||
} |
@@ -19,3 +19,3 @@ import { HKT2, Kind, Kind2, URIS, URIS2 } from '../common/HKT'; | ||
*/ | ||
export declare const makeDefines: <PURI extends typeof import("../batteries/program").ProgramUnionURI | typeof import("../batteries/program-no-union").ProgramNoUnionURI | typeof import("../batteries/program-orderable").ProgramOrderableURI>(prog: PURI) => { | ||
export declare const makeDefines: <PURI extends typeof import("../batteries/program").ProgramUnionURI | typeof import("../batteries/program-no-union").ProgramNoUnionURI | typeof import("../batteries/program-orderable").ProgramOrderableURI>(_prog: PURI) => { | ||
define: <A>(program: ProgramType<unknown, A>[PURI]) => NonNullable<ProgramType<unknown, A>[PURI][typeof interpretSymb]>; | ||
@@ -22,0 +22,0 @@ defineAs: <E, A_1>(program: ProgramType<E, A_1>[PURI]) => NonNullable<ProgramType<E, A_1>[PURI][typeof interpretSymb]>; |
@@ -10,3 +10,3 @@ "use strict"; | ||
*/ | ||
exports.makeDefines = function (prog) { | ||
exports.makeDefines = function (_prog) { | ||
var defineAs = function (program) { return program; }; // White lie | ||
@@ -13,0 +13,0 @@ var define = function (program) { return program; }; |
@@ -7,7 +7,4 @@ import { InferredProgram } from './programs-infer'; | ||
export interface Summoners<ProgURI extends ProgramURI, InterpURI extends InterpreterURI> { | ||
summonAs: <L, A>(F: InferredProgram<L, A, ProgURI>) => Materialized<L, A, ProgURI, InterpURI>; | ||
summonAsA: <A>() => <L>(F: InferredProgram<L, A, ProgURI>) => Materialized<L, A, ProgURI, InterpURI>; | ||
summonAsL: <L>() => <A>(F: InferredProgram<L, A, ProgURI>) => Materialized<L, A, ProgURI, InterpURI>; | ||
summon: <A>(F: InferredProgram<unknown, A, ProgURI>) => Materialized<unknown, A, ProgURI, InterpURI>; | ||
<L, A>(F: InferredProgram<L, A, ProgURI>): Materialized<L, A, ProgURI, InterpURI>; | ||
} | ||
export declare function makeSummoner<PI extends ProgramInterpreter<any, any>>(cacheProgramEval: CacheType, programInterpreter: PI): Summoners<ProgramURIOfProgramInterpreter<PI>, InterpreterURIOfProgramInterpreter<PI>>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var materializer_1 = require("./materializer"); | ||
// TODO: generalize to be able to extend several times, starting from just an Algebra | ||
// Starting from base Algebra and building.. | ||
/** | ||
@@ -12,12 +10,4 @@ * - Cache application of the given interpreter | ||
function makeSummonerInternal(cacheProgramEval, programInterpreter) { | ||
var summonAs = function (F) { return materializer_1.materialize(cacheProgramEval(F), programInterpreter); }; | ||
var summonAsA = function () { return summonAs; }; | ||
var summonAsL = function () { return summonAs; }; | ||
var summon = summonAs; | ||
return { | ||
summonAs: summonAs, | ||
summonAsA: summonAsA, | ||
summonAsL: summonAsL, | ||
summon: summon | ||
}; | ||
var summon = function (F) { return materializer_1.materialize(cacheProgramEval(F), programInterpreter); }; | ||
return summon; | ||
} | ||
@@ -24,0 +14,0 @@ function makeSummoner(cacheProgramEval, programInterpreter) { |
@@ -12,5 +12,4 @@ import { EType, AType, InhabitedTypes, Materialized, MorphADT } from './materializer'; | ||
declare type TagType<Types extends AnyTypes> = TagsOf<AType<Types[keyof Types]>> & string; | ||
declare type AParam<Types extends AnyTypes> = { | ||
[k in keyof Types]: AType<Types[k]>; | ||
}[keyof Types]; | ||
declare type AParam<Types extends AnyTypes> = AType<Types[keyof Types]>; | ||
declare type EParam<Types extends AnyTypes> = EType<Types[keyof Types]>; | ||
declare type UnionTypes<Types extends AnyTypes, Tag extends keyof any, ProgURI extends ProgramURI, InterpURI extends InterpreterURI> = { | ||
@@ -21,3 +20,4 @@ [k in keyof Types]: M<EType<Types[k]>, AType<Types[k]> & { | ||
}; | ||
export declare function makeTagged<ProgURI extends ProgramURI, InterpURI extends InterpreterURI>(summ: <E, A>(F: TaggedUnionProg<E, A, ProgURI>) => M<E, A, ProgURI, InterpURI>): <Tag extends string>(tag: Tag) => <Types extends UnionTypes<Types, Tag, ProgURI, InterpURI>>(o: Types) => MorphADT<EParam<Types>, AParam<Types>, TagType<Types>, ProgURI, InterpURI>; | ||
export declare function makeTagged<ProgURI extends ProgramURI, InterpURI extends InterpreterURI>(summ: <A>(F: TaggedUnionProg<unknown, A, ProgURI>) => M<unknown, A, ProgURI, InterpURI>): <Tag extends string>(tag: Tag) => <Types extends UnionTypes<Types, Tag, ProgURI, InterpURI>>(o: Types) => MorphADT<unknown, AParam<Types>, TagType<Types>, ProgURI, InterpURI>; | ||
export {}; |
@@ -7,4 +7,5 @@ "use strict"; | ||
// Trust the outer signature - type lookup via unknown URI cannot have any semantic here | ||
var summoned = summ(function (F) { return F.taggedUnion(tag, fp_ts_1.record.mapWithIndex(function (k, v) { return v(F); })(o)); } // Trust | ||
); | ||
var summoned = summ(function (F) { | ||
return F.taggedUnion(tag, fp_ts_1.record.mapWithIndex(function (_k, v) { return v(F); })(o)); | ||
}); // Trust | ||
return summoned.tagged(tag)(o); // We're bending reality as bit | ||
@@ -11,0 +12,0 @@ }; }; |
@@ -10,2 +10,5 @@ export declare type IfStringLiteral<T, IfLiteral, IfString, IfNotString> = T extends string ? string extends T ? IfString : IfLiteral : IfNotString; | ||
export declare const assignFunction: <F extends Function, C>(ab: F, c: C) => F & C; | ||
export declare type SelectKeyOfMatchingValues<KeyedValues, Constraint> = { | ||
[k in keyof KeyedValues]: KeyedValues[k] extends Constraint ? k : never; | ||
}[keyof KeyedValues]; | ||
export {}; |
{ | ||
"name": "morphic-ts", | ||
"version": "0.7.0-RC1", | ||
"version": "0.7.0-RC10", | ||
"description": "Interpretable Generic Model Definition Encoding", | ||
@@ -37,3 +37,5 @@ "files": [ | ||
"homepage": "https://github.com/sledorze/face-ts", | ||
"dependencies": {}, | ||
"dependencies": { | ||
"tslib": "^1.10.0" | ||
}, | ||
"peerDependencies": { | ||
@@ -45,3 +47,4 @@ "fast-check": "^1.21.0", | ||
"monocle-ts": "^2.0.1", | ||
"newtype-ts": "^0.3.3" | ||
"newtype-ts": "^0.3.3", | ||
"fast-equals": "2.0.0" | ||
}, | ||
@@ -70,3 +73,4 @@ "devDependencies": { | ||
"typescript": "3.7.5", | ||
"yarn-deduplicate": "1.1.1" | ||
"yarn-deduplicate": "1.1.1", | ||
"fast-equals": "2.0.0" | ||
}, | ||
@@ -73,0 +77,0 @@ "tags": [ |
335
README.md
@@ -1,47 +0,332 @@ | ||
# Morphic-ts (temporary name) | ||
# Morphic-ts | ||
The Extensible Code First approach you've been dreaming of | ||
Business Models just got a lot easier | ||
This library adress the pain of writting and maintaining derived code for business logic | ||
Namely: | ||
This library adress the pain of writting _and maintaining_ code for business _without any Magic_ in Typescript | ||
The goal is to increase, in order of importance | ||
- Correctness | ||
- Productivity | ||
- Developper Experience | ||
It is has two side blended into one; generic ADT manipulation AND Generic, customizable and extensible derivations | ||
## Two minutes intro | ||
```bash | ||
npm install 'morphic-ts' | ||
``` | ||
Or | ||
```bash | ||
yarn add 'morphic-ts' | ||
``` | ||
Then | ||
```typescript | ||
import { summon } from 'morphic-ts/lib/batteries/summoner' | ||
export const Person = summon(F => | ||
F.interface( | ||
{ | ||
name: F.string(), | ||
age: F.number() | ||
}, | ||
'Person' | ||
) | ||
) | ||
// You now have acces to everything to develop around this Type | ||
Person.build // basic build function (enforcing correct type) | ||
Person.show // Show from fp-ts | ||
Person.type // io-ts | ||
Person.strictType // io-ts | ||
Person.eq // Eq from fp-ts | ||
Person.lenseFromPath // and other optics (optionnals, prism, ) from monocle-ts | ||
Person.arb // fast-check | ||
Person.jsonSchema // JsonSchema-ish representation | ||
``` | ||
### Discriminated, taggedUnion-like models | ||
```typescript | ||
import { summon, tagged } from 'morphic-ts/lib/batteries/summoner-no-union' | ||
export const Bicycle = summon(F => | ||
F.interface( | ||
{ | ||
type: F.stringLiteral('Bicycle'), | ||
color: F.string() | ||
}, | ||
'Bicycle' | ||
) | ||
) | ||
export const Car = summon(F => | ||
F.interface( | ||
{ | ||
type: F.stringLiteral('Car'), | ||
kind: F.keysOf({ electric: null, fuel: null, gaz: null }), | ||
power: F.number() | ||
}, | ||
'Car' | ||
) | ||
) | ||
const Vehicule = tagged('type')({ Car, Bicycle }) | ||
// Now you have access to previously depicted derivation + ADT support (ctors, predicates, optics, matchers,reducers, etc.. see `ADT Manipulation` below) | ||
``` | ||
### Want opaque nominal (instead of structural) infered types | ||
You may use this pattern | ||
```typescript | ||
const Car_ = summon(F => | ||
F.interface( | ||
{ | ||
type: F.stringLiteral('Car'), | ||
kind: F.keysOf({ electric: null, fuel: null, gaz: null }), | ||
power: F.number() | ||
}, | ||
'Car' | ||
) | ||
) | ||
export interface Car extends AType<typeof Car_> {} | ||
export interface CarRaw extends EType<typeof Car_> {} | ||
export const Car = AsOpaque<CarRaw, Car>(Car_) | ||
``` | ||
We're sorry for the boilerplate, this is a current Typescript limitation but in our experience, this is worth the effort. | ||
### Configurable | ||
As nice as a General DSL solution to specify your Schema is, there's still some specifics you would like to use. | ||
Morphic provides `Interpreter` to expose `Config` for a specific `Algebra` combinator. | ||
For example, we may want to specify how fastcheck should generate some arrays. | ||
We can add an extra parameter to a definition (last position) and use `Interpreter` specific function (named '*Interpreter*Config', here `fastCheckConfig`) and it will expose the ability to specify the configuration for this `Interpreter` and `combinator`. | ||
```typescript | ||
summon(F => F.array(F.string(), fastCheckConfig({ minLength: 2, maxLength: 4 }))) | ||
``` | ||
Note: _this is type guided and type safe, it's *not* an `any` in disguise_ | ||
You may provide several Configuration | ||
```typescript | ||
summon(F => F.array(F.string(), { ...fastCheckConfig({ minLength: 2, maxLength: 4 }), ...showConfig(...)} )) | ||
``` | ||
## How it works | ||
When you specify a Schema, you're using an API (eDSL implemented using final tagless). | ||
This `API` defines a `Program` (your schema) using an `Algebra` (the combinators exposed to do so). | ||
This `Algebra` you're using is actually composed of several `Algebras` merged together, some defines how to encode a `boolean`, some others a `strMap` (string Map), etc.. | ||
Then for each possible derivation there's possibly an Ìnterpreter` implementing some Algebras. | ||
What Morphic does is orchestrating this machinery for you | ||
This pattern has some interesting properties; it is extensible in both the `Algebra` and the `Interpreter` | ||
## Generic Derivation | ||
Specify the structure of your Schema only once and automatically has access various supported implementations | ||
Participate into expanding implementation and/or schema capabilities | ||
Example of implementations: | ||
- Structural equality (via Eq from fp-ts) | ||
- Validators (io-ts) | ||
- Schema generation (JsonSchema flavor) | ||
- Pretty print of data structure (Show from fp-ts) | ||
- Generators (FastCheck) | ||
- ... | ||
- TypeOrm (WIP) | ||
This is not an exhaustive list, because the design of Morphic enables to define more and more `Interpreters` for your `Schemas` (composed of `Algebras`). | ||
## ADT Manipulation | ||
ADT stands for `Algebraic Data Types`, this may be strange, just think about it as the pattern to represent your casual Business objects | ||
ADT manipulation support maybe be used without relying on full Morphic objects. | ||
The feature can be used standalone via the `makeADT` function with support for: | ||
- Smart Ctors | ||
- Predicates | ||
- Structural equality | ||
- Optics (Arcane name for libraries helping manipulate immutable data structures in FP) | ||
- Matchers | ||
- Validators | ||
- Schema generation | ||
- Pretty print of data structure | ||
- ... | ||
- Reducers | ||
- Creation of new ADTs via selection, exclusion, intersection or union of existing ADTs | ||
## Getting Started | ||
Ad'hoc usage via `makeADT` (Morphic's `summon` already does that for you): | ||
(TODO: add the steps) | ||
Let's define some Types | ||
## How | ||
```typescript | ||
interface Bicycle { | ||
type: 'Bicycle' | ||
color: string | ||
} | ||
The library uses a Code first approach | ||
In order to be open to new kind of data (via Algebras) and derivation (via Interpreters) we use an approach via a (finally) tagless encoding | ||
interface Motorbike { | ||
type: 'Motorbike' | ||
seats: number | ||
} | ||
On may define what Algebra he needs (either reusing some or writing some new one), writes it's scheme and immediately benefits from derivation by interpreting the Schema by some interpreters | ||
In case no interepreter exist for a particular Algebra, the end user can extend it non intrusively thanks to the composable nature of the technic employed | ||
interface Car { | ||
type: 'Car' | ||
kind: 'electric' | 'fuel' | 'gaz' | ||
power: number | ||
seats: number | ||
} | ||
``` | ||
## Batteries included | ||
Then build an ADT from them for PROFIT! | ||
(TODO: add links to the libs implemented) | ||
```typescript | ||
// ADT<Car | Motorbike | Bicycle, "type"> | ||
const Vehicle = makeADT('type')({ | ||
Car: ofType<Car>(), | ||
Motorbike: ofType<Motorbike>(), | ||
Bicycle: ofType<Bicycle>() | ||
}) | ||
``` | ||
## Examples | ||
Then you have.. | ||
(TODO: add some reassuring examples of creation and usages) | ||
### Constuctors | ||
## Limitations | ||
```typescript | ||
Vehicle.of.Bicycle({ color: 'red' }) // type is Car | Motorbike | Bicycle | ||
// `as` offer a narrowed type | ||
Vehicle.as.Car({ kind: 'electric', power: 2, seats: 4 }) // type is Car | ||
``` | ||
### Predicates | ||
```typescript | ||
// Predicate and Refinements | ||
Vehicle.is.Bicycle // (a: Car | Motorbike | Bicycle) => a is Bicycle | ||
// Exist also for several Types | ||
const isTrafficJamProof = Vehicle.isAnyOf('Motorbike', 'Bicycle') // (a: Car | Motorbike | Bicycle) => a is Motorbike | Bicycle | ||
``` | ||
### Matchers | ||
```typescript | ||
const nbSeats = Vehicle.match({ | ||
Car: ({ seats }) => seats, | ||
Motorbike: ({ seats }) => seats, | ||
Bicycle: _ => 1 | ||
}) | ||
// Alternatively you may use `default` | ||
Vehicle.match({ | ||
Car: ({ seats }) => seats, | ||
Motorbike: ({ seats }) => seats, | ||
default: _ => 1 | ||
}) | ||
// Use matchWiden, then the resturn type will be unified from each results | ||
// Here it would be number | 'none' | ||
Vehicle.matchWiden({ | ||
Car: ({ seats }) => seats, | ||
Motorbike: ({ seats }) => seats, | ||
default: _ => 'none' as const | ||
}) | ||
``` | ||
### Transformers | ||
```typescript | ||
// You may tranform matching a subset | ||
Vehicle.transform({ | ||
Car: car => ({ ...car, seats: car.seats + 1 }) | ||
}) | ||
``` | ||
### Reducers | ||
```typescript | ||
// Creating a reducer is made as easy as specifying a type | ||
Vehicle.createReducer({ totalSeats: 0 })({ | ||
Car: ({ seats }) => ({ totalSeats }) => ({ totalSeats: totalSeats + seats }), | ||
Motorbike: ({ seats }) => ({ totalSeats }) => ({ totalSeats: totalSeats + seats }), | ||
default: _ => identity | ||
}) | ||
``` | ||
### Selection, Exclusion, Intersection and Union of ADTs | ||
This will help getting unique advantage of Typescript ability to refine Unions | ||
```typescript | ||
const Motorised = Vehicle.select('Car', 'Motorbike') // ADT<Car | Motorbike, "type"> | ||
const TrafficJamProof = Vehicle.exclude('Car') // ADT<Motorbike | Bicycle, "type"> | ||
const Faster = intersectADT(Motorised, TrafficJamProof) // ADT<Motorbike, "type"> | ||
const Faster = intersectADT(Motorised, TrafficJamProof) // ADT<Motorbike, "type"> | ||
const ManyChoice = unionADT(Motorised, TrafficJamProof) // ADT<Car | Motorbike | Bicycle, "type"> | ||
``` | ||
### Optics (via Monocle) | ||
We support lenses, optionel, prism pretyped helpers | ||
Lense example: | ||
```typescript | ||
const seatLense = Motorised.lenseFromProp('seats') // Lens<Car | Motorbike, number> | ||
const incSeat = seatLense.modify(increment) // (s: Car | Motorbike) => Car | Motorbike | ||
``` | ||
## Generic functions - Interepreters constraints [Advanced usage] | ||
When one want to make a generic code, available to several interpreters, he can constraint the Interpreters URI by using some type level function | ||
```typescript | ||
export function foo< | ||
E, | ||
A, | ||
ProgURI extends ProgramURI, | ||
InterpURI extends SelectInterpURI<E, A, { type: t.Type<A, E> }> // This will only accepts URIs of Interpreters defining a member `type` of type t.Type<A, E> (io-ts) | ||
>( | ||
S: MorphADT<E, A, Tag, ProgURI, InterpURI> | ||
) { | ||
// Here S will completes all the available members of known Interpreters with the acceptable Interpreters URIs, so matching the constraint above | ||
... | ||
} | ||
``` | ||
## Roadmap | ||
- Stategy for a growing number of Algebras / Interpreters | ||
- Switch to Monorepo | ||
- Interpreter for persistency (TypeORM) | ||
- Implement Algebra for APIs | ||
## Disclaimer | ||
BEWARE, THIS REPO IS A POC (WORK-IN-PROGRESS) | ||
THE API IS IN UNSTABLE STATE AND MAY CHANGE | ||
USE AT YOUR OWN RISK) | ||
THIS LIBRARY IS USED INTO TWO PROFESSIONAL PROJECTS IN DEVELPOMENT AT THE MOMENT | ||
BUT BEWARE, THIS REPO IS A POC (WORK-IN-PROGRESS) | ||
THE API IS UNLIKELY TO CHANGE TRENDEMOUSLY BUT YOU MAY BE SAFER TO CONSIDER IT UNSTABLE AND USE AT YOUR OWN RISK |
201117
14.96%243
8.48%3584
3.82%333
593.75%8
33.33%23
4.55%+ Added
+ Added
+ Added