fortepiano 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.d.ts +81 -0
- package/dist/cjs/index.js +125 -0
- package/dist/cjs/utils/Type.d.ts +2 -0
- package/dist/cjs/utils/Type.js +30 -0
- package/dist/cjs/utils/function.d.ts +16 -0
- package/dist/cjs/utils/function.js +39 -0
- package/dist/cjs/utils/struct.d.ts +16 -0
- package/dist/cjs/utils/struct.js +45 -0
- package/dist/esm/index.d.ts +81 -0
- package/dist/esm/index.js +86 -0
- package/dist/esm/utils/Type.d.ts +2 -0
- package/dist/esm/utils/Type.js +4 -0
- package/dist/esm/utils/function.d.ts +16 -0
- package/dist/esm/utils/function.js +33 -0
- package/dist/esm/utils/struct.d.ts +16 -0
- package/dist/esm/utils/struct.js +16 -0
- package/package.json +10 -5
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import * as Appli from 'fp-ts/Applicative';
|
|
2
|
+
import * as _Apply from 'fp-ts/Apply';
|
|
3
|
+
import * as C from 'fp-ts/Chain';
|
|
4
|
+
import * as FIO from 'fp-ts/FromIO';
|
|
5
|
+
import * as F from 'fp-ts/Functor';
|
|
6
|
+
import * as IO from 'fp-ts/IO';
|
|
7
|
+
import * as M from 'fp-ts/Monad';
|
|
8
|
+
import * as MIO from 'fp-ts/MonadIO';
|
|
9
|
+
import * as P from 'fp-ts/Pointed';
|
|
10
|
+
import * as RNEA from 'fp-ts/ReadonlyNonEmptyArray';
|
|
11
|
+
import * as RR from 'fp-ts/ReadonlyRecord';
|
|
12
|
+
import { PartialDeep } from './utils/struct';
|
|
13
|
+
export declare const URI = "Mock";
|
|
14
|
+
export declare type URI = typeof URI;
|
|
15
|
+
declare module 'fp-ts/HKT' {
|
|
16
|
+
interface URItoKind<A> {
|
|
17
|
+
readonly [URI]: Mock<A>;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
declare type EnforceNonEmptyRecord<R> = keyof R extends never ? never : R;
|
|
21
|
+
export interface Mock<A> {
|
|
22
|
+
(...as: ReadonlyArray<PartialDeep<A>>): IO.IO<A>;
|
|
23
|
+
}
|
|
24
|
+
export declare const Functor: F.Functor1<URI>;
|
|
25
|
+
export declare const map: <A, B>(a: (a: A) => B) => (b: Mock<A>) => Mock<B>;
|
|
26
|
+
export declare const flap: <A>(a: A) => <B>(fab: Mock<(a: A) => B>) => Mock<B>;
|
|
27
|
+
export declare const bindTo: <N extends string>(name: N) => <A>(fa: Mock<A>) => Mock<{ readonly [K in N]: A; }>;
|
|
28
|
+
export declare const Pointed: P.Pointed1<URI>;
|
|
29
|
+
export declare const of: <A>(a: A) => Mock<A>;
|
|
30
|
+
export declare const Do: Mock<{}>;
|
|
31
|
+
export declare const Apply: _Apply.Apply1<URI>;
|
|
32
|
+
export declare const ap: <A, B>(a: Mock<A>) => (b: Mock<(a: A) => B>) => Mock<B>;
|
|
33
|
+
export declare const apFirst: <B>(second: Mock<B>) => <A>(first: Mock<A>) => Mock<A>;
|
|
34
|
+
export declare const apSecond: <B>(second: Mock<B>) => <A>(first: Mock<A>) => Mock<B>;
|
|
35
|
+
export declare const apS: <N extends string, A, B>(name: Exclude<N, keyof A>, fb: Mock<B>) => (fa: Mock<A>) => Mock<{ readonly [K in N | keyof A]: K extends keyof A ? A[K] : B; }>;
|
|
36
|
+
export declare const Applicative: Appli.Applicative1<URI>;
|
|
37
|
+
export declare const Chain: C.Chain1<URI>;
|
|
38
|
+
export declare const chain: <A, B>(a: (a: A) => Mock<B>) => (b: Mock<A>) => Mock<B>;
|
|
39
|
+
export declare const chainFirst: <A, B>(f: (a: A) => Mock<B>) => (first: Mock<A>) => Mock<A>;
|
|
40
|
+
export declare const bind: <N extends string, A, B>(name: Exclude<N, keyof A>, f: (a: A) => Mock<B>) => (ma: Mock<A>) => Mock<{ readonly [K in N | keyof A]: K extends keyof A ? A[K] : B; }>;
|
|
41
|
+
export declare const Monad: M.Monad1<URI>;
|
|
42
|
+
export declare const FromIO: FIO.FromIO1<URI>;
|
|
43
|
+
export declare const fromIO: import("fp-ts/lib/NaturalTransformation").NaturalTransformation11<"IO", "Mock">;
|
|
44
|
+
export declare const fromIOK: <A extends readonly unknown[], B>(f: (...a: A) => IO.IO<B>) => (...a: A) => Mock<B>;
|
|
45
|
+
export declare const chainIOK: <A, B>(f: (a: A) => IO.IO<B>) => (first: Mock<A>) => Mock<B>;
|
|
46
|
+
export declare const chainFirstIOK: <A, B>(f: (a: A) => IO.IO<B>) => (first: Mock<A>) => Mock<A>;
|
|
47
|
+
export declare const MonadIO: MIO.MonadIO1<URI>;
|
|
48
|
+
declare const _void: Mock<void>;
|
|
49
|
+
declare const _undefined: Mock<undefined>;
|
|
50
|
+
declare const _null: Mock<null>;
|
|
51
|
+
export declare const boolean: Mock<boolean>;
|
|
52
|
+
export declare const float: (min?: number, max?: number) => Mock<number>;
|
|
53
|
+
export declare const integer: (min?: number, max?: number) => Mock<number>;
|
|
54
|
+
export declare const number: (min?: number, max?: number) => Mock<number>;
|
|
55
|
+
export declare const string: Mock<string>;
|
|
56
|
+
export declare const literal: <A extends string | number | boolean>(a: A) => Mock<A>;
|
|
57
|
+
export declare const unknown: (depth?: number) => Mock<unknown>;
|
|
58
|
+
export declare const nullable: <A>(M: Mock<A>) => Mock<A | undefined>;
|
|
59
|
+
export declare const tuple: <T extends Mock<any>[]>(...t: T & {
|
|
60
|
+
readonly 0: Mock<any>;
|
|
61
|
+
}) => Mock<{ [K in keyof T]: [T[K]] extends [Mock<infer A>] ? A : never; }>;
|
|
62
|
+
export declare const struct: <NER extends Record<string, Mock<any>>>(r: keyof NER extends never ? never : NER) => Mock<{ [K in keyof NER]: [NER[K]] extends [Mock<infer A>] ? A : never; }>;
|
|
63
|
+
export declare const partial: <A>(Ms: EnforceNonEmptyRecord<{ readonly [K in keyof A]: Mock<A[K]>; }>) => Mock<Partial<Readonly<A>>>;
|
|
64
|
+
export declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O>(a: Mock<A>, b: Mock<B>, c: Mock<C>, d: Mock<D>, e: Mock<E>, f: Mock<F>, g: Mock<G>, h: Mock<H>, i: Mock<I>, j: Mock<J>, k: Mock<K>, l: Mock<L>, m: Mock<M>, n: Mock<N>, o: Mock<O>): Mock<A | B | C | D | E | F | G | H | I | J | K | L | M | N | O>;
|
|
65
|
+
export declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M, N>(a: Mock<A>, b: Mock<B>, c: Mock<C>, d: Mock<D>, e: Mock<E>, f: Mock<F>, g: Mock<G>, h: Mock<H>, i: Mock<I>, j: Mock<J>, k: Mock<K>, l: Mock<L>, m: Mock<M>, n: Mock<N>): Mock<A | B | C | D | E | F | G | H | I | J | K | L | M | N>;
|
|
66
|
+
export declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M>(a: Mock<A>, b: Mock<B>, c: Mock<C>, d: Mock<D>, e: Mock<E>, f: Mock<F>, g: Mock<G>, h: Mock<H>, i: Mock<I>, j: Mock<J>, k: Mock<K>, l: Mock<L>, m: Mock<M>): Mock<A | B | C | D | E | F | G | H | I | J | K | L | M>;
|
|
67
|
+
export declare function union<A, B, C, D, E, F, G, H, I, J, K, L>(a: Mock<A>, b: Mock<B>, c: Mock<C>, d: Mock<D>, e: Mock<E>, f: Mock<F>, g: Mock<G>, h: Mock<H>, i: Mock<I>, j: Mock<J>, k: Mock<K>, l: Mock<L>): Mock<A | B | C | D | E | F | G | H | I | J | K | L>;
|
|
68
|
+
export declare function union<A, B, C, D, E, F, G, H, I, J, K>(a: Mock<A>, b: Mock<B>, c: Mock<C>, d: Mock<D>, e: Mock<E>, f: Mock<F>, g: Mock<G>, h: Mock<H>, i: Mock<I>, j: Mock<J>, k: Mock<K>): Mock<A | B | C | D | E | F | G | H | I | J | K>;
|
|
69
|
+
export declare function union<A, B, C, D, E, F, G, H, I, J>(a: Mock<A>, b: Mock<B>, c: Mock<C>, d: Mock<D>, e: Mock<E>, f: Mock<F>, g: Mock<G>, h: Mock<H>, i: Mock<I>, j: Mock<J>): Mock<A | B | C | D | E | F | G | H | I | J>;
|
|
70
|
+
export declare function union<A, B, C, D, E, F, G, H, I>(a: Mock<A>, b: Mock<B>, c: Mock<C>, d: Mock<D>, e: Mock<E>, f: Mock<F>, g: Mock<G>, h: Mock<H>, i: Mock<I>): Mock<A | B | C | D | E | F | G | H | I>;
|
|
71
|
+
export declare function union<A, B, C, D, E, F, G, H>(a: Mock<A>, b: Mock<B>, c: Mock<C>, d: Mock<D>, e: Mock<E>, f: Mock<F>, g: Mock<G>, h: Mock<H>): Mock<A | B | C | D | E | F | G | H>;
|
|
72
|
+
export declare function union<A, B, C, D, E, F, G>(a: Mock<A>, b: Mock<B>, c: Mock<C>, d: Mock<D>, e: Mock<E>, f: Mock<F>, g: Mock<G>): Mock<A | B | C | D | E | F | G>;
|
|
73
|
+
export declare function union<A, B, C, D, E, F>(a: Mock<A>, b: Mock<B>, c: Mock<C>, d: Mock<D>, e: Mock<E>, f: Mock<F>): Mock<A | B | C | D | E | F>;
|
|
74
|
+
export declare function union<A, B, C, D, E>(a: Mock<A>, b: Mock<B>, c: Mock<C>, d: Mock<D>, e: Mock<E>): Mock<A | B | C | D | E>;
|
|
75
|
+
export declare function union<A, B, C, D>(a: Mock<A>, b: Mock<B>, c: Mock<C>, d: Mock<D>): Mock<A | B | C | D>;
|
|
76
|
+
export declare function union<A, B, C>(a: Mock<A>, b: Mock<B>, c: Mock<C>): Mock<A | B | C>;
|
|
77
|
+
export declare function union<A, B>(a: Mock<A>, b: Mock<B>): Mock<A | B>;
|
|
78
|
+
export declare const readonlyArray: <A>(M: Mock<A>, min?: number, max?: number) => Mock<readonly A[]>;
|
|
79
|
+
export declare const readonlyNonEmptyArray: <A>(M: Mock<A>, min?: number, max?: number) => Mock<RNEA.ReadonlyNonEmptyArray<A>>;
|
|
80
|
+
export declare const readonlyRecord: <K extends string, T>(KM: Mock<K>, TM: Mock<T>, min?: number, max?: number) => Mock<Readonly<Record<K, T>>>;
|
|
81
|
+
export { _void as void, _undefined as undefined, _null as null };
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.null = exports.undefined = exports.void = exports.readonlyRecord = exports.readonlyNonEmptyArray = exports.readonlyArray = exports.union = exports.partial = exports.struct = exports.tuple = exports.nullable = exports.unknown = exports.literal = exports.string = exports.number = exports.integer = exports.float = exports.boolean = exports.MonadIO = exports.chainFirstIOK = exports.chainIOK = exports.fromIOK = exports.fromIO = exports.FromIO = exports.Monad = exports.bind = exports.chainFirst = exports.chain = exports.Chain = exports.Applicative = exports.apS = exports.apSecond = exports.apFirst = exports.ap = exports.Apply = exports.Do = exports.of = exports.Pointed = exports.bindTo = exports.flap = exports.map = exports.Functor = exports.URI = void 0;
|
|
27
|
+
const _Apply = __importStar(require("fp-ts/Apply"));
|
|
28
|
+
const C = __importStar(require("fp-ts/Chain"));
|
|
29
|
+
const FIO = __importStar(require("fp-ts/FromIO"));
|
|
30
|
+
const function_1 = require("fp-ts/function");
|
|
31
|
+
const F = __importStar(require("fp-ts/Functor"));
|
|
32
|
+
const IO = __importStar(require("fp-ts/IO"));
|
|
33
|
+
const N = __importStar(require("fp-ts/number"));
|
|
34
|
+
const Op = __importStar(require("fp-ts/Option"));
|
|
35
|
+
const Or = __importStar(require("fp-ts/Ord"));
|
|
36
|
+
const Pr = __importStar(require("fp-ts/Predicate"));
|
|
37
|
+
const R = __importStar(require("fp-ts/Random"));
|
|
38
|
+
const RA = __importStar(require("fp-ts/ReadonlyArray"));
|
|
39
|
+
const RNEA = __importStar(require("fp-ts/ReadonlyNonEmptyArray"));
|
|
40
|
+
const RR = __importStar(require("fp-ts/ReadonlyRecord"));
|
|
41
|
+
const Se = __importStar(require("fp-ts/Semigroup"));
|
|
42
|
+
const t = __importStar(require("io-ts"));
|
|
43
|
+
const function_2 = require("./utils/function");
|
|
44
|
+
const $St = __importStar(require("./utils/struct"));
|
|
45
|
+
const $t = __importStar(require("./utils/Type"));
|
|
46
|
+
exports.URI = 'Mock';
|
|
47
|
+
exports.Functor = {
|
|
48
|
+
URI: exports.URI,
|
|
49
|
+
map: (fa, f) => (0, function_1.pipe)(fa(), IO.map(f), exports.FromIO.fromIO),
|
|
50
|
+
};
|
|
51
|
+
exports.map = (0, function_2.curry)((0, function_1.flip)(exports.Functor.map));
|
|
52
|
+
exports.flap = F.flap(exports.Functor);
|
|
53
|
+
exports.bindTo = F.bindTo(exports.Functor);
|
|
54
|
+
exports.Pointed = {
|
|
55
|
+
URI: exports.URI,
|
|
56
|
+
of: (a) => (...as) => (0, function_1.pipe)(as, RNEA.fromReadonlyArray, Op.traverse(IO.Applicative)(R.randomElem), IO.map(Op.match(() => a, (_a) => $t.struct.is(a) && $t.struct.is(_a)
|
|
57
|
+
? (0, function_1.pipe)(_a, $St.filterDeep(Pr.not(t.undefined.is)), (_a) => $St.patch(_a)(a))
|
|
58
|
+
: _a))),
|
|
59
|
+
};
|
|
60
|
+
exports.of = exports.Pointed.of;
|
|
61
|
+
exports.Do = exports.Pointed.of({});
|
|
62
|
+
exports.Apply = Object.assign(Object.assign({}, exports.Functor), { ap: (fab, fa) => exports.Chain.chain(fab, (0, function_2.curry)(exports.Functor.map)(fa)) });
|
|
63
|
+
exports.ap = (0, function_2.curry)((0, function_1.flip)(exports.Apply.ap));
|
|
64
|
+
exports.apFirst = _Apply.apFirst(exports.Apply);
|
|
65
|
+
exports.apSecond = _Apply.apSecond(exports.Apply);
|
|
66
|
+
exports.apS = _Apply.apS(exports.Apply);
|
|
67
|
+
exports.Applicative = Object.assign(Object.assign({}, exports.Pointed), exports.Apply);
|
|
68
|
+
exports.Chain = Object.assign(Object.assign({}, exports.Apply), { chain: (fa, f) => exports.Functor.map(exports.Functor.map(fa, f), (fb) => fb()()) });
|
|
69
|
+
exports.chain = (0, function_2.curry)((0, function_1.flip)(exports.Chain.chain));
|
|
70
|
+
exports.chainFirst = C.chainFirst(exports.Chain);
|
|
71
|
+
exports.bind = C.bind(exports.Chain);
|
|
72
|
+
exports.Monad = Object.assign(Object.assign({}, exports.Applicative), exports.Chain);
|
|
73
|
+
exports.FromIO = {
|
|
74
|
+
URI: exports.URI,
|
|
75
|
+
fromIO: (fa) => (...as) => (0, function_1.pipe)(fa, IO.chain((a) => exports.Pointed.of(a)(...as))),
|
|
76
|
+
};
|
|
77
|
+
exports.fromIO = exports.FromIO.fromIO;
|
|
78
|
+
exports.fromIOK = FIO.fromIOK(exports.FromIO);
|
|
79
|
+
exports.chainIOK = FIO.chainIOK(exports.FromIO, exports.Chain);
|
|
80
|
+
exports.chainFirstIOK = FIO.chainFirstIOK(exports.FromIO, exports.Chain);
|
|
81
|
+
exports.MonadIO = Object.assign(Object.assign({}, exports.Monad), exports.FromIO);
|
|
82
|
+
const _void = () => function_1.constVoid;
|
|
83
|
+
exports.void = _void;
|
|
84
|
+
const _undefined = () => function_1.constUndefined;
|
|
85
|
+
exports.undefined = _undefined;
|
|
86
|
+
const _null = () => function_1.constNull;
|
|
87
|
+
exports.null = _null;
|
|
88
|
+
exports.boolean = (0, exports.fromIO)(R.randomBool);
|
|
89
|
+
const float = (min = Number.MIN_SAFE_INTEGER * 1e-6, max = Number.MAX_SAFE_INTEGER * 1e-6) => (...as) => (0, function_1.pipe)((0, exports.fromIO)(R.randomRange(min, Math.max(min + Number.EPSILON, max)))(...as), IO.map(Or.clamp(N.Ord)(min, Math.max(min + Number.EPSILON, max - Number.EPSILON))));
|
|
90
|
+
exports.float = float;
|
|
91
|
+
const integer = (min = Number.MIN_SAFE_INTEGER * 1e-6, max = Number.MAX_SAFE_INTEGER * 1e-6) => (...as) => (0, function_1.pipe)((0, exports.float)(min, max)(...as), IO.map(Math.floor));
|
|
92
|
+
exports.integer = integer;
|
|
93
|
+
const number = (min = Number.MIN_SAFE_INTEGER * 1e-6, max = Number.MAX_SAFE_INTEGER * 1e-6) => (...as) => (0, function_1.pipe)(union((0, exports.float)(min, max), (0, exports.integer)(min, max))(...as), IO.map(Or.clamp(N.Ord)(min, Math.max(min + Number.EPSILON, max - Number.EPSILON))));
|
|
94
|
+
exports.number = number;
|
|
95
|
+
exports.string = (0, exports.fromIO)(() => Math.random().toString(36).split('.')[1]);
|
|
96
|
+
const literal = (a) => (0, exports.of)(a);
|
|
97
|
+
exports.literal = literal;
|
|
98
|
+
const unknown = (depth = 10) => (0, function_2.recurse)((_unknown, _depth) => (_depth < depth
|
|
99
|
+
? union(_undefined, _null, exports.boolean, (0, exports.number)(), exports.string, (0, exports.readonlyArray)(_unknown), (0, exports.readonlyRecord)(exports.string, _unknown))
|
|
100
|
+
: union(_undefined, _null, exports.boolean, (0, exports.number)(), exports.string)));
|
|
101
|
+
exports.unknown = unknown;
|
|
102
|
+
const nullable = (M) => union(M, _undefined);
|
|
103
|
+
exports.nullable = nullable;
|
|
104
|
+
exports.tuple = _Apply.sequenceT(exports.Apply);
|
|
105
|
+
exports.struct = _Apply.sequenceS(exports.Apply);
|
|
106
|
+
const partial = (Ms) => (0, function_1.pipe)(Ms, RR.map(exports.nullable), exports.struct);
|
|
107
|
+
exports.partial = partial;
|
|
108
|
+
function union(...Ms) {
|
|
109
|
+
return (0, function_1.pipe)(Ms, R.randomElem, IO.chain(function_2.run), exports.fromIO);
|
|
110
|
+
}
|
|
111
|
+
exports.union = union;
|
|
112
|
+
const readonlyArray = (M, min = 0, max = 10) => {
|
|
113
|
+
return (as) => () => {
|
|
114
|
+
if (as !== undefined) {
|
|
115
|
+
return as;
|
|
116
|
+
}
|
|
117
|
+
const rndNum = R.randomInt(Math.max(0, min), Math.max(0, min, max))();
|
|
118
|
+
return Array.from({ length: rndNum }, M());
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
exports.readonlyArray = readonlyArray;
|
|
122
|
+
const readonlyNonEmptyArray = (M, min = 1, max = 10) => (0, exports.readonlyArray)(M, Math.max(1, min), Math.max(1, min, max));
|
|
123
|
+
exports.readonlyNonEmptyArray = readonlyNonEmptyArray;
|
|
124
|
+
const readonlyRecord = (KM, TM, min = 0, max = 10) => (0, function_1.pipe)((0, exports.readonlyArray)((0, exports.tuple)(KM, TM), Math.max(0, min), Math.max(0, min, max))(), IO.map((entries) => RR.fromFoldable(Se.last(), RA.Foldable)(entries)), exports.fromIO);
|
|
125
|
+
exports.readonlyRecord = readonlyRecord;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.struct = void 0;
|
|
27
|
+
const function_1 = require("fp-ts/function");
|
|
28
|
+
const t = __importStar(require("io-ts"));
|
|
29
|
+
const isStruct = (u) => 'object' === typeof u && null !== u && !Array.isArray(u);
|
|
30
|
+
exports.struct = new t.Type('struct', isStruct, (u, c) => (isStruct(u) ? t.success(u) : t.failure(u, c)), function_1.identity);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Lazy } from 'fp-ts/function';
|
|
2
|
+
export declare const run: <A>(f: Lazy<A>) => A;
|
|
3
|
+
export declare function curry<A, B, C>(f: (a: A, b: B) => C): (a: A) => (b: B) => C;
|
|
4
|
+
export declare function curry<A, B, C, D>(f: (a: A, b: B, c: C) => D): (a: A) => (b: B) => (c: C) => D;
|
|
5
|
+
/**
|
|
6
|
+
* @example
|
|
7
|
+
* const pi = (max: number) => (): ((n?: number) => number) =>
|
|
8
|
+
* recurse((self, depth) => (n = 1) =>
|
|
9
|
+
* 4 / n + (depth < max ? self(-1 * n + (n < 0 ? 2 : -2)) : 0)
|
|
10
|
+
* )
|
|
11
|
+
* const pi100 = pi(100)()()
|
|
12
|
+
*
|
|
13
|
+
* expect(pi100).toBeGreaterThan(3.15)
|
|
14
|
+
* expect(pi100).toBeLessThan(3.16)
|
|
15
|
+
*/
|
|
16
|
+
export declare const recurse: <A extends (...args: any) => any>(f: (self: A, depth: number) => A, cache?: boolean) => A;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.recurse = exports.curry = exports.run = void 0;
|
|
4
|
+
const run = (f) => f();
|
|
5
|
+
exports.run = run;
|
|
6
|
+
function curry(f) {
|
|
7
|
+
return function curried(...head) {
|
|
8
|
+
return head.length >= f.length
|
|
9
|
+
? f(...head)
|
|
10
|
+
: (...rest) => curried(...head.concat(rest));
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
exports.curry = curry;
|
|
14
|
+
/**
|
|
15
|
+
* @example
|
|
16
|
+
* const pi = (max: number) => (): ((n?: number) => number) =>
|
|
17
|
+
* recurse((self, depth) => (n = 1) =>
|
|
18
|
+
* 4 / n + (depth < max ? self(-1 * n + (n < 0 ? 2 : -2)) : 0)
|
|
19
|
+
* )
|
|
20
|
+
* const pi100 = pi(100)()()
|
|
21
|
+
*
|
|
22
|
+
* expect(pi100).toBeGreaterThan(3.15)
|
|
23
|
+
* expect(pi100).toBeLessThan(3.16)
|
|
24
|
+
*/
|
|
25
|
+
const recurse = (f, cache = false) => {
|
|
26
|
+
let depth = 0;
|
|
27
|
+
let _cache = null;
|
|
28
|
+
const run = !cache
|
|
29
|
+
? f
|
|
30
|
+
: (_self, _depth) => {
|
|
31
|
+
if (!_cache) {
|
|
32
|
+
_cache = f(_self, _depth);
|
|
33
|
+
}
|
|
34
|
+
return _cache;
|
|
35
|
+
};
|
|
36
|
+
const self = ((...args) => run(self, depth++)(...args));
|
|
37
|
+
return self;
|
|
38
|
+
};
|
|
39
|
+
exports.recurse = recurse;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Predicate } from 'fp-ts/Predicate';
|
|
2
|
+
export declare type Struct = object;
|
|
3
|
+
export declare type PartialDeep<A> = A extends {
|
|
4
|
+
readonly [x: string]: unknown;
|
|
5
|
+
} ? Partial<{
|
|
6
|
+
readonly [K in keyof A]: PartialDeep<A[K]>;
|
|
7
|
+
}> : A;
|
|
8
|
+
declare type IntersectionDeep<A, B> = A extends {
|
|
9
|
+
readonly [x: string]: unknown;
|
|
10
|
+
} ? A & {
|
|
11
|
+
readonly [K in keyof B]: IntersectionDeep<K extends keyof A ? A[K] : unknown, B[K]>;
|
|
12
|
+
} : B;
|
|
13
|
+
export declare const toReadonlyArray: <A extends object>(a: A) => readonly (readonly [keyof A, A[keyof A]])[];
|
|
14
|
+
export declare const filterDeep: <A extends object>(f: Predicate<unknown>) => (a: A) => PartialDeep<A>;
|
|
15
|
+
export declare const patch: <A extends object, B extends PartialDeep<A> & object>(b: B) => (a: A) => IntersectionDeep<A, B>;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.patch = exports.filterDeep = exports.toReadonlyArray = void 0;
|
|
27
|
+
const function_1 = require("fp-ts/function");
|
|
28
|
+
const RA = __importStar(require("fp-ts/ReadonlyArray"));
|
|
29
|
+
const RR = __importStar(require("fp-ts/ReadonlyRecord"));
|
|
30
|
+
const S = __importStar(require("fp-ts/struct"));
|
|
31
|
+
const function_2 = require("./function");
|
|
32
|
+
const $t = __importStar(require("./Type"));
|
|
33
|
+
const toReadonlyArray = (a) => RR.toReadonlyArray(a);
|
|
34
|
+
exports.toReadonlyArray = toReadonlyArray;
|
|
35
|
+
const filterDeep = (f) => (a) => (0, function_1.pipe)(a, exports.toReadonlyArray, RA.filter(([_, value]) => f(value)), RA.map(([key, value]) => $t.struct.is(value)
|
|
36
|
+
? [
|
|
37
|
+
key,
|
|
38
|
+
(0, function_1.pipe)(value, (0, exports.filterDeep)(f)),
|
|
39
|
+
]
|
|
40
|
+
: [key, value]), RA.reduce({}, (b, [key, value]) => (Object.assign(Object.assign({}, b), { [key]: value }))));
|
|
41
|
+
exports.filterDeep = filterDeep;
|
|
42
|
+
const patch = (b) => (a) => (0, function_1.pipe)(b, exports.toReadonlyArray, RA.map(([key, b]) => $t.struct.is(b)
|
|
43
|
+
? [key, (0, exports.patch)(b)(a[key])]
|
|
44
|
+
: [key, b]), RA.reduce({}, (ab, [key, b]) => (Object.assign(Object.assign({}, ab), { [key]: b }))), (0, function_2.curry)(S.getAssignSemigroup().concat)(a));
|
|
45
|
+
exports.patch = patch;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import * as Appli from 'fp-ts/Applicative';
|
|
2
|
+
import * as _Apply from 'fp-ts/Apply';
|
|
3
|
+
import * as C from 'fp-ts/Chain';
|
|
4
|
+
import * as FIO from 'fp-ts/FromIO';
|
|
5
|
+
import * as F from 'fp-ts/Functor';
|
|
6
|
+
import * as IO from 'fp-ts/IO';
|
|
7
|
+
import * as M from 'fp-ts/Monad';
|
|
8
|
+
import * as MIO from 'fp-ts/MonadIO';
|
|
9
|
+
import * as P from 'fp-ts/Pointed';
|
|
10
|
+
import * as RNEA from 'fp-ts/ReadonlyNonEmptyArray';
|
|
11
|
+
import * as RR from 'fp-ts/ReadonlyRecord';
|
|
12
|
+
import { PartialDeep } from './utils/struct';
|
|
13
|
+
export declare const URI = "Mock";
|
|
14
|
+
export declare type URI = typeof URI;
|
|
15
|
+
declare module 'fp-ts/HKT' {
|
|
16
|
+
interface URItoKind<A> {
|
|
17
|
+
readonly [URI]: Mock<A>;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
declare type EnforceNonEmptyRecord<R> = keyof R extends never ? never : R;
|
|
21
|
+
export interface Mock<A> {
|
|
22
|
+
(...as: ReadonlyArray<PartialDeep<A>>): IO.IO<A>;
|
|
23
|
+
}
|
|
24
|
+
export declare const Functor: F.Functor1<URI>;
|
|
25
|
+
export declare const map: <A, B>(a: (a: A) => B) => (b: Mock<A>) => Mock<B>;
|
|
26
|
+
export declare const flap: <A>(a: A) => <B>(fab: Mock<(a: A) => B>) => Mock<B>;
|
|
27
|
+
export declare const bindTo: <N extends string>(name: N) => <A>(fa: Mock<A>) => Mock<{ readonly [K in N]: A; }>;
|
|
28
|
+
export declare const Pointed: P.Pointed1<URI>;
|
|
29
|
+
export declare const of: <A>(a: A) => Mock<A>;
|
|
30
|
+
export declare const Do: Mock<{}>;
|
|
31
|
+
export declare const Apply: _Apply.Apply1<URI>;
|
|
32
|
+
export declare const ap: <A, B>(a: Mock<A>) => (b: Mock<(a: A) => B>) => Mock<B>;
|
|
33
|
+
export declare const apFirst: <B>(second: Mock<B>) => <A>(first: Mock<A>) => Mock<A>;
|
|
34
|
+
export declare const apSecond: <B>(second: Mock<B>) => <A>(first: Mock<A>) => Mock<B>;
|
|
35
|
+
export declare const apS: <N extends string, A, B>(name: Exclude<N, keyof A>, fb: Mock<B>) => (fa: Mock<A>) => Mock<{ readonly [K in N | keyof A]: K extends keyof A ? A[K] : B; }>;
|
|
36
|
+
export declare const Applicative: Appli.Applicative1<URI>;
|
|
37
|
+
export declare const Chain: C.Chain1<URI>;
|
|
38
|
+
export declare const chain: <A, B>(a: (a: A) => Mock<B>) => (b: Mock<A>) => Mock<B>;
|
|
39
|
+
export declare const chainFirst: <A, B>(f: (a: A) => Mock<B>) => (first: Mock<A>) => Mock<A>;
|
|
40
|
+
export declare const bind: <N extends string, A, B>(name: Exclude<N, keyof A>, f: (a: A) => Mock<B>) => (ma: Mock<A>) => Mock<{ readonly [K in N | keyof A]: K extends keyof A ? A[K] : B; }>;
|
|
41
|
+
export declare const Monad: M.Monad1<URI>;
|
|
42
|
+
export declare const FromIO: FIO.FromIO1<URI>;
|
|
43
|
+
export declare const fromIO: import("fp-ts/lib/NaturalTransformation").NaturalTransformation11<"IO", "Mock">;
|
|
44
|
+
export declare const fromIOK: <A extends readonly unknown[], B>(f: (...a: A) => IO.IO<B>) => (...a: A) => Mock<B>;
|
|
45
|
+
export declare const chainIOK: <A, B>(f: (a: A) => IO.IO<B>) => (first: Mock<A>) => Mock<B>;
|
|
46
|
+
export declare const chainFirstIOK: <A, B>(f: (a: A) => IO.IO<B>) => (first: Mock<A>) => Mock<A>;
|
|
47
|
+
export declare const MonadIO: MIO.MonadIO1<URI>;
|
|
48
|
+
declare const _void: Mock<void>;
|
|
49
|
+
declare const _undefined: Mock<undefined>;
|
|
50
|
+
declare const _null: Mock<null>;
|
|
51
|
+
export declare const boolean: Mock<boolean>;
|
|
52
|
+
export declare const float: (min?: number, max?: number) => Mock<number>;
|
|
53
|
+
export declare const integer: (min?: number, max?: number) => Mock<number>;
|
|
54
|
+
export declare const number: (min?: number, max?: number) => Mock<number>;
|
|
55
|
+
export declare const string: Mock<string>;
|
|
56
|
+
export declare const literal: <A extends string | number | boolean>(a: A) => Mock<A>;
|
|
57
|
+
export declare const unknown: (depth?: number) => Mock<unknown>;
|
|
58
|
+
export declare const nullable: <A>(M: Mock<A>) => Mock<A | undefined>;
|
|
59
|
+
export declare const tuple: <T extends Mock<any>[]>(...t: T & {
|
|
60
|
+
readonly 0: Mock<any>;
|
|
61
|
+
}) => Mock<{ [K in keyof T]: [T[K]] extends [Mock<infer A>] ? A : never; }>;
|
|
62
|
+
export declare const struct: <NER extends Record<string, Mock<any>>>(r: keyof NER extends never ? never : NER) => Mock<{ [K in keyof NER]: [NER[K]] extends [Mock<infer A>] ? A : never; }>;
|
|
63
|
+
export declare const partial: <A>(Ms: EnforceNonEmptyRecord<{ readonly [K in keyof A]: Mock<A[K]>; }>) => Mock<Partial<Readonly<A>>>;
|
|
64
|
+
export declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O>(a: Mock<A>, b: Mock<B>, c: Mock<C>, d: Mock<D>, e: Mock<E>, f: Mock<F>, g: Mock<G>, h: Mock<H>, i: Mock<I>, j: Mock<J>, k: Mock<K>, l: Mock<L>, m: Mock<M>, n: Mock<N>, o: Mock<O>): Mock<A | B | C | D | E | F | G | H | I | J | K | L | M | N | O>;
|
|
65
|
+
export declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M, N>(a: Mock<A>, b: Mock<B>, c: Mock<C>, d: Mock<D>, e: Mock<E>, f: Mock<F>, g: Mock<G>, h: Mock<H>, i: Mock<I>, j: Mock<J>, k: Mock<K>, l: Mock<L>, m: Mock<M>, n: Mock<N>): Mock<A | B | C | D | E | F | G | H | I | J | K | L | M | N>;
|
|
66
|
+
export declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M>(a: Mock<A>, b: Mock<B>, c: Mock<C>, d: Mock<D>, e: Mock<E>, f: Mock<F>, g: Mock<G>, h: Mock<H>, i: Mock<I>, j: Mock<J>, k: Mock<K>, l: Mock<L>, m: Mock<M>): Mock<A | B | C | D | E | F | G | H | I | J | K | L | M>;
|
|
67
|
+
export declare function union<A, B, C, D, E, F, G, H, I, J, K, L>(a: Mock<A>, b: Mock<B>, c: Mock<C>, d: Mock<D>, e: Mock<E>, f: Mock<F>, g: Mock<G>, h: Mock<H>, i: Mock<I>, j: Mock<J>, k: Mock<K>, l: Mock<L>): Mock<A | B | C | D | E | F | G | H | I | J | K | L>;
|
|
68
|
+
export declare function union<A, B, C, D, E, F, G, H, I, J, K>(a: Mock<A>, b: Mock<B>, c: Mock<C>, d: Mock<D>, e: Mock<E>, f: Mock<F>, g: Mock<G>, h: Mock<H>, i: Mock<I>, j: Mock<J>, k: Mock<K>): Mock<A | B | C | D | E | F | G | H | I | J | K>;
|
|
69
|
+
export declare function union<A, B, C, D, E, F, G, H, I, J>(a: Mock<A>, b: Mock<B>, c: Mock<C>, d: Mock<D>, e: Mock<E>, f: Mock<F>, g: Mock<G>, h: Mock<H>, i: Mock<I>, j: Mock<J>): Mock<A | B | C | D | E | F | G | H | I | J>;
|
|
70
|
+
export declare function union<A, B, C, D, E, F, G, H, I>(a: Mock<A>, b: Mock<B>, c: Mock<C>, d: Mock<D>, e: Mock<E>, f: Mock<F>, g: Mock<G>, h: Mock<H>, i: Mock<I>): Mock<A | B | C | D | E | F | G | H | I>;
|
|
71
|
+
export declare function union<A, B, C, D, E, F, G, H>(a: Mock<A>, b: Mock<B>, c: Mock<C>, d: Mock<D>, e: Mock<E>, f: Mock<F>, g: Mock<G>, h: Mock<H>): Mock<A | B | C | D | E | F | G | H>;
|
|
72
|
+
export declare function union<A, B, C, D, E, F, G>(a: Mock<A>, b: Mock<B>, c: Mock<C>, d: Mock<D>, e: Mock<E>, f: Mock<F>, g: Mock<G>): Mock<A | B | C | D | E | F | G>;
|
|
73
|
+
export declare function union<A, B, C, D, E, F>(a: Mock<A>, b: Mock<B>, c: Mock<C>, d: Mock<D>, e: Mock<E>, f: Mock<F>): Mock<A | B | C | D | E | F>;
|
|
74
|
+
export declare function union<A, B, C, D, E>(a: Mock<A>, b: Mock<B>, c: Mock<C>, d: Mock<D>, e: Mock<E>): Mock<A | B | C | D | E>;
|
|
75
|
+
export declare function union<A, B, C, D>(a: Mock<A>, b: Mock<B>, c: Mock<C>, d: Mock<D>): Mock<A | B | C | D>;
|
|
76
|
+
export declare function union<A, B, C>(a: Mock<A>, b: Mock<B>, c: Mock<C>): Mock<A | B | C>;
|
|
77
|
+
export declare function union<A, B>(a: Mock<A>, b: Mock<B>): Mock<A | B>;
|
|
78
|
+
export declare const readonlyArray: <A>(M: Mock<A>, min?: number, max?: number) => Mock<readonly A[]>;
|
|
79
|
+
export declare const readonlyNonEmptyArray: <A>(M: Mock<A>, min?: number, max?: number) => Mock<RNEA.ReadonlyNonEmptyArray<A>>;
|
|
80
|
+
export declare const readonlyRecord: <K extends string, T>(KM: Mock<K>, TM: Mock<T>, min?: number, max?: number) => Mock<Readonly<Record<K, T>>>;
|
|
81
|
+
export { _void as void, _undefined as undefined, _null as null };
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import * as _Apply from 'fp-ts/Apply';
|
|
2
|
+
import * as C from 'fp-ts/Chain';
|
|
3
|
+
import * as FIO from 'fp-ts/FromIO';
|
|
4
|
+
import { constNull, constUndefined, constVoid, flip, pipe, } from 'fp-ts/function';
|
|
5
|
+
import * as F from 'fp-ts/Functor';
|
|
6
|
+
import * as IO from 'fp-ts/IO';
|
|
7
|
+
import * as N from 'fp-ts/number';
|
|
8
|
+
import * as Op from 'fp-ts/Option';
|
|
9
|
+
import * as Or from 'fp-ts/Ord';
|
|
10
|
+
import * as Pr from 'fp-ts/Predicate';
|
|
11
|
+
import * as R from 'fp-ts/Random';
|
|
12
|
+
import * as RA from 'fp-ts/ReadonlyArray';
|
|
13
|
+
import * as RNEA from 'fp-ts/ReadonlyNonEmptyArray';
|
|
14
|
+
import * as RR from 'fp-ts/ReadonlyRecord';
|
|
15
|
+
import * as Se from 'fp-ts/Semigroup';
|
|
16
|
+
import * as t from 'io-ts';
|
|
17
|
+
import { curry, recurse, run } from './utils/function';
|
|
18
|
+
import * as $St from './utils/struct';
|
|
19
|
+
import * as $t from './utils/Type';
|
|
20
|
+
export const URI = 'Mock';
|
|
21
|
+
export const Functor = {
|
|
22
|
+
URI,
|
|
23
|
+
map: (fa, f) => pipe(fa(), IO.map(f), FromIO.fromIO),
|
|
24
|
+
};
|
|
25
|
+
export const map = curry(flip(Functor.map));
|
|
26
|
+
export const flap = F.flap(Functor);
|
|
27
|
+
export const bindTo = F.bindTo(Functor);
|
|
28
|
+
export const Pointed = {
|
|
29
|
+
URI,
|
|
30
|
+
of: (a) => (...as) => pipe(as, RNEA.fromReadonlyArray, Op.traverse(IO.Applicative)(R.randomElem), IO.map(Op.match(() => a, (_a) => $t.struct.is(a) && $t.struct.is(_a)
|
|
31
|
+
? pipe(_a, $St.filterDeep(Pr.not(t.undefined.is)), (_a) => $St.patch(_a)(a))
|
|
32
|
+
: _a))),
|
|
33
|
+
};
|
|
34
|
+
export const of = Pointed.of;
|
|
35
|
+
export const Do = Pointed.of({});
|
|
36
|
+
export const Apply = Object.assign(Object.assign({}, Functor), { ap: (fab, fa) => Chain.chain(fab, curry(Functor.map)(fa)) });
|
|
37
|
+
export const ap = curry(flip(Apply.ap));
|
|
38
|
+
export const apFirst = _Apply.apFirst(Apply);
|
|
39
|
+
export const apSecond = _Apply.apSecond(Apply);
|
|
40
|
+
export const apS = _Apply.apS(Apply);
|
|
41
|
+
export const Applicative = Object.assign(Object.assign({}, Pointed), Apply);
|
|
42
|
+
export const Chain = Object.assign(Object.assign({}, Apply), { chain: (fa, f) => Functor.map(Functor.map(fa, f), (fb) => fb()()) });
|
|
43
|
+
export const chain = curry(flip(Chain.chain));
|
|
44
|
+
export const chainFirst = C.chainFirst(Chain);
|
|
45
|
+
export const bind = C.bind(Chain);
|
|
46
|
+
export const Monad = Object.assign(Object.assign({}, Applicative), Chain);
|
|
47
|
+
export const FromIO = {
|
|
48
|
+
URI,
|
|
49
|
+
fromIO: (fa) => (...as) => pipe(fa, IO.chain((a) => Pointed.of(a)(...as))),
|
|
50
|
+
};
|
|
51
|
+
export const fromIO = FromIO.fromIO;
|
|
52
|
+
export const fromIOK = FIO.fromIOK(FromIO);
|
|
53
|
+
export const chainIOK = FIO.chainIOK(FromIO, Chain);
|
|
54
|
+
export const chainFirstIOK = FIO.chainFirstIOK(FromIO, Chain);
|
|
55
|
+
export const MonadIO = Object.assign(Object.assign({}, Monad), FromIO);
|
|
56
|
+
const _void = () => constVoid;
|
|
57
|
+
const _undefined = () => constUndefined;
|
|
58
|
+
const _null = () => constNull;
|
|
59
|
+
export const boolean = fromIO(R.randomBool);
|
|
60
|
+
export const float = (min = Number.MIN_SAFE_INTEGER * 1e-6, max = Number.MAX_SAFE_INTEGER * 1e-6) => (...as) => pipe(fromIO(R.randomRange(min, Math.max(min + Number.EPSILON, max)))(...as), IO.map(Or.clamp(N.Ord)(min, Math.max(min + Number.EPSILON, max - Number.EPSILON))));
|
|
61
|
+
export const integer = (min = Number.MIN_SAFE_INTEGER * 1e-6, max = Number.MAX_SAFE_INTEGER * 1e-6) => (...as) => pipe(float(min, max)(...as), IO.map(Math.floor));
|
|
62
|
+
export const number = (min = Number.MIN_SAFE_INTEGER * 1e-6, max = Number.MAX_SAFE_INTEGER * 1e-6) => (...as) => pipe(union(float(min, max), integer(min, max))(...as), IO.map(Or.clamp(N.Ord)(min, Math.max(min + Number.EPSILON, max - Number.EPSILON))));
|
|
63
|
+
export const string = fromIO(() => Math.random().toString(36).split('.')[1]);
|
|
64
|
+
export const literal = (a) => of(a);
|
|
65
|
+
export const unknown = (depth = 10) => recurse((_unknown, _depth) => (_depth < depth
|
|
66
|
+
? union(_undefined, _null, boolean, number(), string, readonlyArray(_unknown), readonlyRecord(string, _unknown))
|
|
67
|
+
: union(_undefined, _null, boolean, number(), string)));
|
|
68
|
+
export const nullable = (M) => union(M, _undefined);
|
|
69
|
+
export const tuple = _Apply.sequenceT(Apply);
|
|
70
|
+
export const struct = _Apply.sequenceS(Apply);
|
|
71
|
+
export const partial = (Ms) => pipe(Ms, RR.map(nullable), struct);
|
|
72
|
+
export function union(...Ms) {
|
|
73
|
+
return pipe(Ms, R.randomElem, IO.chain(run), fromIO);
|
|
74
|
+
}
|
|
75
|
+
export const readonlyArray = (M, min = 0, max = 10) => {
|
|
76
|
+
return (as) => () => {
|
|
77
|
+
if (as !== undefined) {
|
|
78
|
+
return as;
|
|
79
|
+
}
|
|
80
|
+
const rndNum = R.randomInt(Math.max(0, min), Math.max(0, min, max))();
|
|
81
|
+
return Array.from({ length: rndNum }, M());
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
export const readonlyNonEmptyArray = (M, min = 1, max = 10) => readonlyArray(M, Math.max(1, min), Math.max(1, min, max));
|
|
85
|
+
export const readonlyRecord = (KM, TM, min = 0, max = 10) => pipe(readonlyArray(tuple(KM, TM), Math.max(0, min), Math.max(0, min, max))(), IO.map((entries) => RR.fromFoldable(Se.last(), RA.Foldable)(entries)), fromIO);
|
|
86
|
+
export { _void as void, _undefined as undefined, _null as null };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { identity } from 'fp-ts/function';
|
|
2
|
+
import * as t from 'io-ts';
|
|
3
|
+
const isStruct = (u) => 'object' === typeof u && null !== u && !Array.isArray(u);
|
|
4
|
+
export const struct = new t.Type('struct', isStruct, (u, c) => (isStruct(u) ? t.success(u) : t.failure(u, c)), identity);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Lazy } from 'fp-ts/function';
|
|
2
|
+
export declare const run: <A>(f: Lazy<A>) => A;
|
|
3
|
+
export declare function curry<A, B, C>(f: (a: A, b: B) => C): (a: A) => (b: B) => C;
|
|
4
|
+
export declare function curry<A, B, C, D>(f: (a: A, b: B, c: C) => D): (a: A) => (b: B) => (c: C) => D;
|
|
5
|
+
/**
|
|
6
|
+
* @example
|
|
7
|
+
* const pi = (max: number) => (): ((n?: number) => number) =>
|
|
8
|
+
* recurse((self, depth) => (n = 1) =>
|
|
9
|
+
* 4 / n + (depth < max ? self(-1 * n + (n < 0 ? 2 : -2)) : 0)
|
|
10
|
+
* )
|
|
11
|
+
* const pi100 = pi(100)()()
|
|
12
|
+
*
|
|
13
|
+
* expect(pi100).toBeGreaterThan(3.15)
|
|
14
|
+
* expect(pi100).toBeLessThan(3.16)
|
|
15
|
+
*/
|
|
16
|
+
export declare const recurse: <A extends (...args: any) => any>(f: (self: A, depth: number) => A, cache?: boolean) => A;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export const run = (f) => f();
|
|
2
|
+
export function curry(f) {
|
|
3
|
+
return function curried(...head) {
|
|
4
|
+
return head.length >= f.length
|
|
5
|
+
? f(...head)
|
|
6
|
+
: (...rest) => curried(...head.concat(rest));
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* @example
|
|
11
|
+
* const pi = (max: number) => (): ((n?: number) => number) =>
|
|
12
|
+
* recurse((self, depth) => (n = 1) =>
|
|
13
|
+
* 4 / n + (depth < max ? self(-1 * n + (n < 0 ? 2 : -2)) : 0)
|
|
14
|
+
* )
|
|
15
|
+
* const pi100 = pi(100)()()
|
|
16
|
+
*
|
|
17
|
+
* expect(pi100).toBeGreaterThan(3.15)
|
|
18
|
+
* expect(pi100).toBeLessThan(3.16)
|
|
19
|
+
*/
|
|
20
|
+
export const recurse = (f, cache = false) => {
|
|
21
|
+
let depth = 0;
|
|
22
|
+
let _cache = null;
|
|
23
|
+
const run = !cache
|
|
24
|
+
? f
|
|
25
|
+
: (_self, _depth) => {
|
|
26
|
+
if (!_cache) {
|
|
27
|
+
_cache = f(_self, _depth);
|
|
28
|
+
}
|
|
29
|
+
return _cache;
|
|
30
|
+
};
|
|
31
|
+
const self = ((...args) => run(self, depth++)(...args));
|
|
32
|
+
return self;
|
|
33
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Predicate } from 'fp-ts/Predicate';
|
|
2
|
+
export declare type Struct = object;
|
|
3
|
+
export declare type PartialDeep<A> = A extends {
|
|
4
|
+
readonly [x: string]: unknown;
|
|
5
|
+
} ? Partial<{
|
|
6
|
+
readonly [K in keyof A]: PartialDeep<A[K]>;
|
|
7
|
+
}> : A;
|
|
8
|
+
declare type IntersectionDeep<A, B> = A extends {
|
|
9
|
+
readonly [x: string]: unknown;
|
|
10
|
+
} ? A & {
|
|
11
|
+
readonly [K in keyof B]: IntersectionDeep<K extends keyof A ? A[K] : unknown, B[K]>;
|
|
12
|
+
} : B;
|
|
13
|
+
export declare const toReadonlyArray: <A extends object>(a: A) => readonly (readonly [keyof A, A[keyof A]])[];
|
|
14
|
+
export declare const filterDeep: <A extends object>(f: Predicate<unknown>) => (a: A) => PartialDeep<A>;
|
|
15
|
+
export declare const patch: <A extends object, B extends PartialDeep<A> & object>(b: B) => (a: A) => IntersectionDeep<A, B>;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { pipe } from 'fp-ts/function';
|
|
2
|
+
import * as RA from 'fp-ts/ReadonlyArray';
|
|
3
|
+
import * as RR from 'fp-ts/ReadonlyRecord';
|
|
4
|
+
import * as S from 'fp-ts/struct';
|
|
5
|
+
import { curry } from './function';
|
|
6
|
+
import * as $t from './Type';
|
|
7
|
+
export const toReadonlyArray = (a) => RR.toReadonlyArray(a);
|
|
8
|
+
export const filterDeep = (f) => (a) => pipe(a, toReadonlyArray, RA.filter(([_, value]) => f(value)), RA.map(([key, value]) => $t.struct.is(value)
|
|
9
|
+
? [
|
|
10
|
+
key,
|
|
11
|
+
pipe(value, filterDeep(f)),
|
|
12
|
+
]
|
|
13
|
+
: [key, value]), RA.reduce({}, (b, [key, value]) => (Object.assign(Object.assign({}, b), { [key]: value }))));
|
|
14
|
+
export const patch = (b) => (a) => pipe(b, toReadonlyArray, RA.map(([key, b]) => $t.struct.is(b)
|
|
15
|
+
? [key, patch(b)(a[key])]
|
|
16
|
+
: [key, b]), RA.reduce({}, (ab, [key, b]) => (Object.assign(Object.assign({}, ab), { [key]: b }))), curry(S.getAssignSemigroup().concat)(a));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fortepiano",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Playing actual music over fp-ts notes",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -10,8 +10,9 @@
|
|
|
10
10
|
],
|
|
11
11
|
"exports": {
|
|
12
12
|
".": {
|
|
13
|
+
"types": "./dist/esm/index.d.ts",
|
|
13
14
|
"require": "./dist/cjs/index.js",
|
|
14
|
-
"import": "./dist/
|
|
15
|
+
"import": "./dist/cjs/index.js"
|
|
15
16
|
}
|
|
16
17
|
},
|
|
17
18
|
"files": [
|
|
@@ -42,8 +43,8 @@
|
|
|
42
43
|
"eslint:fix": "eslint --fix ./",
|
|
43
44
|
"prettier": "prettier --check ./",
|
|
44
45
|
"prettier:fix": "prettier --write ./",
|
|
45
|
-
"prerelease": "yarn build
|
|
46
|
-
"release": "yarn prerelease && npm publish
|
|
46
|
+
"prerelease": "yarn build",
|
|
47
|
+
"release": "yarn prerelease && npm publish",
|
|
47
48
|
"test": "jest",
|
|
48
49
|
"test:watch": "jest --watchAll",
|
|
49
50
|
"test:coverage": "jest --coverage"
|
|
@@ -62,5 +63,9 @@
|
|
|
62
63
|
"ts-node": "^10.9.2",
|
|
63
64
|
"typescript": "^4.6.4"
|
|
64
65
|
},
|
|
65
|
-
"
|
|
66
|
+
"peerDependencies": {
|
|
67
|
+
"fp-ts": "^2.5.0",
|
|
68
|
+
"io-ts": "^2.2.0"
|
|
69
|
+
},
|
|
70
|
+
"packageManager": "yarn@4.18.1"
|
|
66
71
|
}
|