fortepiano 0.1.9 → 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.
Files changed (252) hide show
  1. package/README.md +30 -17
  2. package/{lib/Mock.d.ts → dist/cjs/index.d.ts} +1 -1
  3. package/{lib/Mock.js → dist/cjs/index.js} +31 -24
  4. package/dist/cjs/utils/Type.d.ts +2 -0
  5. package/{lib/Magma.js → dist/cjs/utils/Type.js} +4 -4
  6. package/dist/cjs/utils/function.d.ts +16 -0
  7. package/dist/cjs/utils/function.js +39 -0
  8. package/dist/cjs/utils/struct.d.ts +16 -0
  9. package/{lib → dist/cjs/utils}/struct.js +1 -7
  10. package/{Mock.d.ts → dist/esm/index.d.ts} +1 -1
  11. package/{esm/Mock.js → dist/esm/index.js} +13 -6
  12. package/dist/esm/utils/Type.d.ts +2 -0
  13. package/dist/esm/utils/Type.js +4 -0
  14. package/dist/esm/utils/function.d.ts +16 -0
  15. package/dist/esm/utils/function.js +33 -0
  16. package/dist/esm/utils/struct.d.ts +16 -0
  17. package/{esm → dist/esm/utils}/struct.js +0 -3
  18. package/package.json +23 -56
  19. package/Aggregate/package.json +0 -6
  20. package/Aggregate.d.ts +0 -4
  21. package/AsyncYield/package.json +0 -6
  22. package/AsyncYield.d.ts +0 -104
  23. package/Binary/package.json +0 -6
  24. package/Binary.d.ts +0 -5
  25. package/Buffer/package.json +0 -6
  26. package/Buffer.d.ts +0 -4
  27. package/CHANGELOG.md +0 -168
  28. package/CONTRIBUTING.md +0 -51
  29. package/Cache/package.json +0 -6
  30. package/Cache.d.ts +0 -18
  31. package/Console/package.json +0 -6
  32. package/Console.d.ts +0 -20
  33. package/Crypto/package.json +0 -6
  34. package/Crypto.d.ts +0 -4
  35. package/Date/package.json +0 -6
  36. package/Date.d.ts +0 -4
  37. package/Eq/package.json +0 -6
  38. package/Eq.d.ts +0 -4
  39. package/Error/package.json +0 -6
  40. package/Error.d.ts +0 -13
  41. package/GeneratorL/package.json +0 -6
  42. package/GeneratorL.d.ts +0 -714
  43. package/Has/package.json +0 -6
  44. package/Has.d.ts +0 -16
  45. package/Http/package.json +0 -6
  46. package/Http.d.ts +0 -59
  47. package/Log/package.json +0 -6
  48. package/Log.d.ts +0 -4
  49. package/Magma/package.json +0 -6
  50. package/Magma.d.ts +0 -2
  51. package/Matrix/package.json +0 -6
  52. package/Matrix.d.ts +0 -9
  53. package/Mock/package.json +0 -6
  54. package/Option/package.json +0 -6
  55. package/Option.d.ts +0 -2
  56. package/Random/package.json +0 -6
  57. package/Random.d.ts +0 -7
  58. package/Reader/package.json +0 -6
  59. package/Reader.d.ts +0 -4
  60. package/ReaderEither/package.json +0 -6
  61. package/ReaderEither.d.ts +0 -9
  62. package/ReaderTask/package.json +0 -6
  63. package/ReaderTask.d.ts +0 -8
  64. package/ReaderTaskEither/package.json +0 -6
  65. package/ReaderTaskEither.d.ts +0 -66
  66. package/ReadonlyArray/package.json +0 -6
  67. package/ReadonlyArray.d.ts +0 -75
  68. package/ReadonlyRecord/package.json +0 -6
  69. package/ReadonlyRecord.d.ts +0 -5
  70. package/ReadonlyTuple/package.json +0 -6
  71. package/ReadonlyTuple.d.ts +0 -14
  72. package/Storage/package.json +0 -6
  73. package/Storage.d.ts +0 -14
  74. package/Stream/package.json +0 -6
  75. package/Stream.d.ts +0 -4
  76. package/TaskEither/package.json +0 -6
  77. package/TaskEither.d.ts +0 -2
  78. package/Type/package.json +0 -6
  79. package/Type.d.ts +0 -13
  80. package/Validation/package.json +0 -6
  81. package/Validation.d.ts +0 -4
  82. package/Yield/package.json +0 -6
  83. package/Yield.d.ts +0 -210
  84. package/cache/Memcached/package.json +0 -6
  85. package/cache/Memcached.d.ts +0 -4
  86. package/cache/Memory/package.json +0 -6
  87. package/cache/Memory.d.ts +0 -2
  88. package/cache/Redis/package.json +0 -6
  89. package/cache/Redis.d.ts +0 -4
  90. package/cache/Storage/package.json +0 -6
  91. package/cache/Storage.d.ts +0 -4
  92. package/esm/Aggregate.js +0 -1
  93. package/esm/AsyncYield.js +0 -411
  94. package/esm/Binary.js +0 -12
  95. package/esm/Buffer.js +0 -22
  96. package/esm/Cache.js +0 -25
  97. package/esm/Console.js +0 -20
  98. package/esm/Crypto.js +0 -12
  99. package/esm/Date.js +0 -5
  100. package/esm/Eq.js +0 -6
  101. package/esm/Error.js +0 -45
  102. package/esm/GeneratorL.js +0 -802
  103. package/esm/Has.js +0 -5
  104. package/esm/Http.js +0 -138
  105. package/esm/Log.js +0 -2
  106. package/esm/Magma.js +0 -3
  107. package/esm/Matrix.js +0 -12
  108. package/esm/Option.js +0 -3
  109. package/esm/Random.js +0 -3
  110. package/esm/Reader.js +0 -6
  111. package/esm/ReaderEither.js +0 -7
  112. package/esm/ReaderTask.js +0 -8
  113. package/esm/ReaderTaskEither.js +0 -58
  114. package/esm/ReadonlyArray.js +0 -44
  115. package/esm/ReadonlyRecord.js +0 -5
  116. package/esm/ReadonlyTuple.js +0 -10
  117. package/esm/Storage.js +0 -34
  118. package/esm/Stream.js +0 -9
  119. package/esm/TaskEither.js +0 -9
  120. package/esm/Type.js +0 -29
  121. package/esm/Validation.js +0 -6
  122. package/esm/Yield.js +0 -401
  123. package/esm/cache/Memcached.js +0 -27
  124. package/esm/cache/Memory.js +0 -43
  125. package/esm/cache/Redis.js +0 -35
  126. package/esm/cache/Storage.js +0 -40
  127. package/esm/function.js +0 -92
  128. package/esm/http/Axios.js +0 -36
  129. package/esm/http/Fetch.js +0 -48
  130. package/esm/http/Got.js +0 -40
  131. package/esm/http/Mock.js +0 -30
  132. package/esm/index.js +0 -39
  133. package/esm/log/Void.js +0 -3
  134. package/esm/number.js +0 -5
  135. package/esm/storage/Flydrive.js +0 -44
  136. package/esm/storage/Fs.js +0 -27
  137. package/esm/string.js +0 -9
  138. package/function/package.json +0 -6
  139. package/function.d.ts +0 -52
  140. package/http/Axios/package.json +0 -6
  141. package/http/Axios.d.ts +0 -3
  142. package/http/Fetch/package.json +0 -6
  143. package/http/Fetch.d.ts +0 -2
  144. package/http/Got/package.json +0 -6
  145. package/http/Got.d.ts +0 -6
  146. package/http/Mock/package.json +0 -6
  147. package/http/Mock.d.ts +0 -2
  148. package/index.d.ts +0 -55
  149. package/lib/Aggregate.d.ts +0 -4
  150. package/lib/Aggregate.js +0 -2
  151. package/lib/AsyncYield.d.ts +0 -104
  152. package/lib/AsyncYield.js +0 -461
  153. package/lib/Binary.d.ts +0 -5
  154. package/lib/Binary.js +0 -15
  155. package/lib/Buffer.d.ts +0 -4
  156. package/lib/Buffer.js +0 -49
  157. package/lib/Cache.d.ts +0 -18
  158. package/lib/Cache.js +0 -54
  159. package/lib/Console.d.ts +0 -20
  160. package/lib/Console.js +0 -25
  161. package/lib/Crypto.d.ts +0 -4
  162. package/lib/Crypto.js +0 -43
  163. package/lib/Date.d.ts +0 -4
  164. package/lib/Date.js +0 -34
  165. package/lib/Eq.d.ts +0 -4
  166. package/lib/Eq.js +0 -33
  167. package/lib/Error.d.ts +0 -13
  168. package/lib/Error.js +0 -74
  169. package/lib/GeneratorL.d.ts +0 -714
  170. package/lib/GeneratorL.js +0 -905
  171. package/lib/Has.d.ts +0 -16
  172. package/lib/Has.js +0 -13
  173. package/lib/Http.d.ts +0 -59
  174. package/lib/Http.js +0 -172
  175. package/lib/Log.d.ts +0 -4
  176. package/lib/Log.js +0 -5
  177. package/lib/Magma.d.ts +0 -2
  178. package/lib/Matrix.d.ts +0 -9
  179. package/lib/Matrix.js +0 -40
  180. package/lib/Option.d.ts +0 -2
  181. package/lib/Option.js +0 -30
  182. package/lib/Random.d.ts +0 -7
  183. package/lib/Random.js +0 -7
  184. package/lib/Reader.d.ts +0 -4
  185. package/lib/Reader.js +0 -35
  186. package/lib/ReaderEither.d.ts +0 -9
  187. package/lib/ReaderEither.js +0 -38
  188. package/lib/ReaderTask.d.ts +0 -8
  189. package/lib/ReaderTask.js +0 -39
  190. package/lib/ReaderTaskEither.d.ts +0 -66
  191. package/lib/ReaderTaskEither.js +0 -138
  192. package/lib/ReadonlyArray.d.ts +0 -75
  193. package/lib/ReadonlyArray.js +0 -74
  194. package/lib/ReadonlyRecord.d.ts +0 -5
  195. package/lib/ReadonlyRecord.js +0 -34
  196. package/lib/ReadonlyTuple.d.ts +0 -14
  197. package/lib/ReadonlyTuple.js +0 -38
  198. package/lib/Storage.d.ts +0 -14
  199. package/lib/Storage.js +0 -61
  200. package/lib/Stream.d.ts +0 -4
  201. package/lib/Stream.js +0 -35
  202. package/lib/TaskEither.d.ts +0 -2
  203. package/lib/TaskEither.js +0 -36
  204. package/lib/Type.d.ts +0 -13
  205. package/lib/Type.js +0 -61
  206. package/lib/Validation.d.ts +0 -4
  207. package/lib/Validation.js +0 -34
  208. package/lib/Yield.d.ts +0 -210
  209. package/lib/Yield.js +0 -504
  210. package/lib/cache/Memcached.d.ts +0 -4
  211. package/lib/cache/Memcached.js +0 -54
  212. package/lib/cache/Memory.d.ts +0 -2
  213. package/lib/cache/Memory.js +0 -70
  214. package/lib/cache/Redis.d.ts +0 -4
  215. package/lib/cache/Redis.js +0 -62
  216. package/lib/cache/Storage.d.ts +0 -4
  217. package/lib/cache/Storage.js +0 -66
  218. package/lib/function.d.ts +0 -52
  219. package/lib/function.js +0 -101
  220. package/lib/http/Axios.d.ts +0 -3
  221. package/lib/http/Axios.js +0 -63
  222. package/lib/http/Fetch.d.ts +0 -2
  223. package/lib/http/Fetch.js +0 -75
  224. package/lib/http/Got.d.ts +0 -6
  225. package/lib/http/Got.js +0 -67
  226. package/lib/http/Mock.d.ts +0 -2
  227. package/lib/http/Mock.js +0 -56
  228. package/lib/index.d.ts +0 -55
  229. package/lib/index.js +0 -98
  230. package/lib/log/Void.d.ts +0 -3
  231. package/lib/log/Void.js +0 -6
  232. package/lib/number.d.ts +0 -3
  233. package/lib/number.js +0 -8
  234. package/lib/storage/Flydrive.d.ts +0 -4
  235. package/lib/storage/Flydrive.js +0 -71
  236. package/lib/storage/Fs.d.ts +0 -3
  237. package/lib/storage/Fs.js +0 -57
  238. package/lib/string.d.ts +0 -8
  239. package/lib/string.js +0 -43
  240. package/lib/struct.d.ts +0 -13
  241. package/log/Void/package.json +0 -6
  242. package/log/Void.d.ts +0 -3
  243. package/number/package.json +0 -6
  244. package/number.d.ts +0 -3
  245. package/storage/Flydrive/package.json +0 -6
  246. package/storage/Flydrive.d.ts +0 -4
  247. package/storage/Fs/package.json +0 -6
  248. package/storage/Fs.d.ts +0 -3
  249. package/string/package.json +0 -6
  250. package/string.d.ts +0 -8
  251. package/struct/package.json +0 -6
  252. package/struct.d.ts +0 -13
package/README.md CHANGED
@@ -1,6 +1,10 @@
1
+ <p align="center">
2
+ <img src="./logo.png" width=150px" height="auto"/>
3
+ </p>
4
+
1
5
  # fortepiano [ˌfɔrteˈpjaːno]
2
6
 
3
- _Playing actual music over `fp-ts` notes_
7
+ _Playing actual music over `fp-ts` notes_ 🎶
4
8
 
5
9
  [![GitHub Workflow Status](https://img.shields.io/github/workflow/status/facile-it/fortepiano/main)](https://github.com/facile-it/fortepiano/actions)
6
10
  [![Codecov](https://img.shields.io/codecov/c/gh/facile-it/fortepiano)](https://app.codecov.io/gh/facile-it/fortepiano)
@@ -9,36 +13,45 @@ _Playing actual music over `fp-ts` notes_
9
13
 
10
14
  ## Description
11
15
 
12
- `fortepiano` provides a set of common abstractions for functional application development (e.g., `Http`, `Storage`...), while extending [`fp-ts`](https://github.com/gcanti/fp-ts) with useful modules _à la_ [`fp-ts-contrib`](https://github.com/gcanti/fp-ts-contrib).
16
+ Fortepiano is a mocking library for TypeScript. It promotes immutability, composability and purity, making it ideal for projects that embrace functional programming principles.
13
17
 
14
18
  ## Getting Started
15
19
 
16
- `fortepiano` stands on the shoulders of the giant `fp-ts`. As such, a good understanding of its [concepts](https://gcanti.github.io/fp-ts/) is suggested.
17
-
18
20
  ### Installation
19
21
 
20
- The package is available via [npm](https://www.npmjs.com/package/fortepiano), and must be installed along with its peer dependencies:
22
+ To install the stable version:
21
23
 
22
- ```
23
- npm install fortepiano fp-ts io-ts io-ts-types
24
+ ```bash
25
+ npm install fortepiano
24
26
  ```
25
27
 
26
- Additional packages are required, shall you want to use specific abstractions:
28
+ or using yarn:
27
29
 
28
- - [`memcached`](https://www.npmjs.com/package/memcached) and [`@types/memcached`](https://www.npmjs.com/package/@types/memcached) (`cache/Memcached`)
29
- - [`redis`](https://www.npmjs.com/package/redis) and [`@types/redis`](https://www.npmjs.com/package/@types/redis) (`cache/Redis`)
30
- - [`axios`](https://www.npmjs.com/package/axios) (`http/Axios`)
31
- - [`@slynova/flydrive`](https://www.npmjs.com/package/@slynova/flydrive) (`storage/Flydrive`)
30
+ ```bash
31
+ yarn add fortepiano
32
+ ```
32
33
 
33
34
  ### Usage
34
35
 
35
- Import modules (e.g., values) from package index and types from specific modules. "Function" module and abstraction implementations are an exception:
36
+ Fortepiano uses a functional API to create and configure mocks, encouraging pure function usage and immutable mock objects.
37
+
38
+ Here's an example:
36
39
 
37
40
  ```typescript
38
- import { $type } from 'fortepiano'
39
- import { Struct } from 'fortepiano/struct'
40
- import { curry } from 'fortepiano/function'
41
- import { $axios } from 'fortepiano/http/Axios'
41
+ import { $mock } from 'fortepiano'
42
+
43
+ interface User {
44
+ firstName: string
45
+ lastName: string
46
+ }
47
+
48
+ export const UserMock = (): $mock.Mock<User> =>
49
+ $mock.struct({
50
+ firstName: $mock.string,
51
+ lastName: $mock.string,
52
+ })
53
+
54
+ console.log(UserMock()()()) // Output: { firstName: 'randomString', lastName: 'randomString' }
42
55
  ```
43
56
 
44
57
  ## Contributing
@@ -1,4 +1,3 @@
1
- import { PartialDeep } from '.';
2
1
  import * as Appli from 'fp-ts/Applicative';
3
2
  import * as _Apply from 'fp-ts/Apply';
4
3
  import * as C from 'fp-ts/Chain';
@@ -10,6 +9,7 @@ import * as MIO from 'fp-ts/MonadIO';
10
9
  import * as P from 'fp-ts/Pointed';
11
10
  import * as RNEA from 'fp-ts/ReadonlyNonEmptyArray';
12
11
  import * as RR from 'fp-ts/ReadonlyRecord';
12
+ import { PartialDeep } from './utils/struct';
13
13
  export declare const URI = "Mock";
14
14
  export declare type URI = typeof URI;
15
15
  declare module 'fp-ts/HKT' {
@@ -24,14 +24,10 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
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 function_1 = require("./function");
28
- const $St = __importStar(require("./struct"));
29
- const $t = __importStar(require("./Type"));
30
- const $Y = __importStar(require("./Yield"));
31
27
  const _Apply = __importStar(require("fp-ts/Apply"));
32
28
  const C = __importStar(require("fp-ts/Chain"));
33
29
  const FIO = __importStar(require("fp-ts/FromIO"));
34
- const function_2 = require("fp-ts/function");
30
+ const function_1 = require("fp-ts/function");
35
31
  const F = __importStar(require("fp-ts/Functor"));
36
32
  const IO = __importStar(require("fp-ts/IO"));
37
33
  const N = __importStar(require("fp-ts/number"));
@@ -44,59 +40,62 @@ const RNEA = __importStar(require("fp-ts/ReadonlyNonEmptyArray"));
44
40
  const RR = __importStar(require("fp-ts/ReadonlyRecord"));
45
41
  const Se = __importStar(require("fp-ts/Semigroup"));
46
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"));
47
46
  exports.URI = 'Mock';
48
47
  exports.Functor = {
49
48
  URI: exports.URI,
50
- map: (fa, f) => (0, function_2.pipe)(fa(), IO.map(f), exports.FromIO.fromIO),
49
+ map: (fa, f) => (0, function_1.pipe)(fa(), IO.map(f), exports.FromIO.fromIO),
51
50
  };
52
- exports.map = (0, function_1.curry)((0, function_2.flip)(exports.Functor.map));
51
+ exports.map = (0, function_2.curry)((0, function_1.flip)(exports.Functor.map));
53
52
  exports.flap = F.flap(exports.Functor);
54
53
  exports.bindTo = F.bindTo(exports.Functor);
55
54
  exports.Pointed = {
56
55
  URI: exports.URI,
57
- of: (a) => (...as) => (0, function_2.pipe)(as, RNEA.fromReadonlyArray, Op.traverse(IO.Applicative)(R.randomElem), IO.map(Op.match(() => a, (_a) => $t.struct.is(a) && $t.struct.is(_a)
58
- ? (0, function_2.pipe)(_a, $St.filterDeep(Pr.not(t.undefined.is)), (_a) => $St.patch(_a)(a))
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))
59
58
  : _a))),
60
59
  };
61
60
  exports.of = exports.Pointed.of;
62
61
  exports.Do = exports.Pointed.of({});
63
- exports.Apply = Object.assign(Object.assign({}, exports.Functor), { ap: (fab, fa) => exports.Chain.chain(fab, (0, function_1.curry)(exports.Functor.map)(fa)) });
64
- exports.ap = (0, function_1.curry)((0, function_2.flip)(exports.Apply.ap));
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));
65
64
  exports.apFirst = _Apply.apFirst(exports.Apply);
66
65
  exports.apSecond = _Apply.apSecond(exports.Apply);
67
66
  exports.apS = _Apply.apS(exports.Apply);
68
67
  exports.Applicative = Object.assign(Object.assign({}, exports.Pointed), exports.Apply);
69
68
  exports.Chain = Object.assign(Object.assign({}, exports.Apply), { chain: (fa, f) => exports.Functor.map(exports.Functor.map(fa, f), (fb) => fb()()) });
70
- exports.chain = (0, function_1.curry)((0, function_2.flip)(exports.Chain.chain));
69
+ exports.chain = (0, function_2.curry)((0, function_1.flip)(exports.Chain.chain));
71
70
  exports.chainFirst = C.chainFirst(exports.Chain);
72
71
  exports.bind = C.bind(exports.Chain);
73
72
  exports.Monad = Object.assign(Object.assign({}, exports.Applicative), exports.Chain);
74
73
  exports.FromIO = {
75
74
  URI: exports.URI,
76
- fromIO: (fa) => (...as) => (0, function_2.pipe)(fa, IO.chain((a) => exports.Pointed.of(a)(...as))),
75
+ fromIO: (fa) => (...as) => (0, function_1.pipe)(fa, IO.chain((a) => exports.Pointed.of(a)(...as))),
77
76
  };
78
77
  exports.fromIO = exports.FromIO.fromIO;
79
78
  exports.fromIOK = FIO.fromIOK(exports.FromIO);
80
79
  exports.chainIOK = FIO.chainIOK(exports.FromIO, exports.Chain);
81
80
  exports.chainFirstIOK = FIO.chainFirstIOK(exports.FromIO, exports.Chain);
82
81
  exports.MonadIO = Object.assign(Object.assign({}, exports.Monad), exports.FromIO);
83
- const _void = () => function_2.constVoid;
82
+ const _void = () => function_1.constVoid;
84
83
  exports.void = _void;
85
- const _undefined = () => function_2.constUndefined;
84
+ const _undefined = () => function_1.constUndefined;
86
85
  exports.undefined = _undefined;
87
- const _null = () => function_2.constNull;
86
+ const _null = () => function_1.constNull;
88
87
  exports.null = _null;
89
88
  exports.boolean = (0, exports.fromIO)(R.randomBool);
90
- const float = (min = Number.MIN_SAFE_INTEGER * 1e-6, max = Number.MAX_SAFE_INTEGER * 1e-6) => (...as) => (0, function_2.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))));
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))));
91
90
  exports.float = float;
92
- const integer = (min = Number.MIN_SAFE_INTEGER * 1e-6, max = Number.MAX_SAFE_INTEGER * 1e-6) => (...as) => (0, function_2.pipe)((0, exports.float)(min, max)(...as), IO.map(Math.floor));
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));
93
92
  exports.integer = integer;
94
- const number = (min = Number.MIN_SAFE_INTEGER * 1e-6, max = Number.MAX_SAFE_INTEGER * 1e-6) => (...as) => (0, function_2.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))));
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))));
95
94
  exports.number = number;
96
95
  exports.string = (0, exports.fromIO)(() => Math.random().toString(36).split('.')[1]);
97
96
  const literal = (a) => (0, exports.of)(a);
98
97
  exports.literal = literal;
99
- const unknown = (depth = 10) => (0, function_1.recurse)((_unknown, _depth) => (_depth < depth
98
+ const unknown = (depth = 10) => (0, function_2.recurse)((_unknown, _depth) => (_depth < depth
100
99
  ? union(_undefined, _null, exports.boolean, (0, exports.number)(), exports.string, (0, exports.readonlyArray)(_unknown), (0, exports.readonlyRecord)(exports.string, _unknown))
101
100
  : union(_undefined, _null, exports.boolean, (0, exports.number)(), exports.string)));
102
101
  exports.unknown = unknown;
@@ -104,15 +103,23 @@ const nullable = (M) => union(M, _undefined);
104
103
  exports.nullable = nullable;
105
104
  exports.tuple = _Apply.sequenceT(exports.Apply);
106
105
  exports.struct = _Apply.sequenceS(exports.Apply);
107
- const partial = (Ms) => (0, function_2.pipe)(Ms, RR.map(exports.nullable), exports.struct);
106
+ const partial = (Ms) => (0, function_1.pipe)(Ms, RR.map(exports.nullable), exports.struct);
108
107
  exports.partial = partial;
109
108
  function union(...Ms) {
110
- return (0, function_2.pipe)(Ms, R.randomElem, IO.chain(function_1.run), exports.fromIO);
109
+ return (0, function_1.pipe)(Ms, R.randomElem, IO.chain(function_2.run), exports.fromIO);
111
110
  }
112
111
  exports.union = union;
113
- const readonlyArray = (M, min = 0, max = 10) => (0, function_2.pipe)(R.randomInt(Math.max(0, min), Math.max(0, min, max)), IO.map((n) => (0, function_2.pipe)($Y.fromIO(M()), $Y.takeLeft(n), $Y.toReadonlyArray)), exports.fromIO);
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
+ };
114
121
  exports.readonlyArray = readonlyArray;
115
122
  const readonlyNonEmptyArray = (M, min = 1, max = 10) => (0, exports.readonlyArray)(M, Math.max(1, min), Math.max(1, min, max));
116
123
  exports.readonlyNonEmptyArray = readonlyNonEmptyArray;
117
- const readonlyRecord = (KM, TM, min = 0, max = 10) => (0, function_2.pipe)((0, exports.readonlyArray)((0, exports.tuple)(KM, TM), Math.max(0, min), Math.max(0, min, max))(), IO.map(RR.fromFoldable(Se.last(), RA.Foldable)), exports.fromIO);
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);
118
125
  exports.readonlyRecord = readonlyRecord;
@@ -0,0 +1,2 @@
1
+ import * as t from 'io-ts';
2
+ export declare const struct: t.Type<object, object, unknown>;
@@ -23,8 +23,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.concatAll = void 0;
26
+ exports.struct = void 0;
27
27
  const function_1 = require("fp-ts/function");
28
- const RA = __importStar(require("fp-ts/ReadonlyArray"));
29
- const concatAll = (M) => (startWith) => (as) => (0, function_1.pipe)(as, RA.reduce(startWith, M.concat));
30
- exports.concatAll = concatAll;
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 {};
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.patch = exports.filterDeep = exports.updateAt = exports.modifyAt = exports.lookup = exports.toReadonlyArray = void 0;
26
+ exports.patch = exports.filterDeep = exports.toReadonlyArray = void 0;
27
27
  const function_1 = require("fp-ts/function");
28
28
  const RA = __importStar(require("fp-ts/ReadonlyArray"));
29
29
  const RR = __importStar(require("fp-ts/ReadonlyRecord"));
@@ -32,12 +32,6 @@ const function_2 = require("./function");
32
32
  const $t = __importStar(require("./Type"));
33
33
  const toReadonlyArray = (a) => RR.toReadonlyArray(a);
34
34
  exports.toReadonlyArray = toReadonlyArray;
35
- const lookup = (k) => (s) => s[k];
36
- exports.lookup = lookup;
37
- const modifyAt = (k, f) => (s) => (Object.assign(Object.assign({}, s), { [k]: f(s[k]) }));
38
- exports.modifyAt = modifyAt;
39
- const updateAt = (k, a) => (0, exports.modifyAt)(k, () => a);
40
- exports.updateAt = updateAt;
41
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)
42
36
  ? [
43
37
  key,
@@ -1,4 +1,3 @@
1
- import { PartialDeep } from '.';
2
1
  import * as Appli from 'fp-ts/Applicative';
3
2
  import * as _Apply from 'fp-ts/Apply';
4
3
  import * as C from 'fp-ts/Chain';
@@ -10,6 +9,7 @@ import * as MIO from 'fp-ts/MonadIO';
10
9
  import * as P from 'fp-ts/Pointed';
11
10
  import * as RNEA from 'fp-ts/ReadonlyNonEmptyArray';
12
11
  import * as RR from 'fp-ts/ReadonlyRecord';
12
+ import { PartialDeep } from './utils/struct';
13
13
  export declare const URI = "Mock";
14
14
  export declare type URI = typeof URI;
15
15
  declare module 'fp-ts/HKT' {
@@ -1,7 +1,3 @@
1
- import { curry, recurse, run } from './function';
2
- import * as $St from './struct';
3
- import * as $t from './Type';
4
- import * as $Y from './Yield';
5
1
  import * as _Apply from 'fp-ts/Apply';
6
2
  import * as C from 'fp-ts/Chain';
7
3
  import * as FIO from 'fp-ts/FromIO';
@@ -18,6 +14,9 @@ import * as RNEA from 'fp-ts/ReadonlyNonEmptyArray';
18
14
  import * as RR from 'fp-ts/ReadonlyRecord';
19
15
  import * as Se from 'fp-ts/Semigroup';
20
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';
21
20
  export const URI = 'Mock';
22
21
  export const Functor = {
23
22
  URI,
@@ -73,7 +72,15 @@ export const partial = (Ms) => pipe(Ms, RR.map(nullable), struct);
73
72
  export function union(...Ms) {
74
73
  return pipe(Ms, R.randomElem, IO.chain(run), fromIO);
75
74
  }
76
- export const readonlyArray = (M, min = 0, max = 10) => pipe(R.randomInt(Math.max(0, min), Math.max(0, min, max)), IO.map((n) => pipe($Y.fromIO(M()), $Y.takeLeft(n), $Y.toReadonlyArray)), fromIO);
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
+ };
77
84
  export const readonlyNonEmptyArray = (M, min = 1, max = 10) => readonlyArray(M, Math.max(1, min), Math.max(1, min, max));
78
- 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(RR.fromFoldable(Se.last(), RA.Foldable)), fromIO);
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);
79
86
  export { _void as void, _undefined as undefined, _null as null };
@@ -0,0 +1,2 @@
1
+ import * as t from 'io-ts';
2
+ export declare const struct: t.Type<object, object, unknown>;
@@ -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 {};
@@ -5,9 +5,6 @@ import * as S from 'fp-ts/struct';
5
5
  import { curry } from './function';
6
6
  import * as $t from './Type';
7
7
  export const toReadonlyArray = (a) => RR.toReadonlyArray(a);
8
- export const lookup = (k) => (s) => s[k];
9
- export const modifyAt = (k, f) => (s) => (Object.assign(Object.assign({}, s), { [k]: f(s[k]) }));
10
- export const updateAt = (k, a) => modifyAt(k, () => a);
11
8
  export const filterDeep = (f) => (a) => pipe(a, toReadonlyArray, RA.filter(([_, value]) => f(value)), RA.map(([key, value]) => $t.struct.is(value)
12
9
  ? [
13
10
  key,
package/package.json CHANGED
@@ -1,12 +1,23 @@
1
1
  {
2
2
  "name": "fortepiano",
3
- "version": "0.1.9",
3
+ "version": "1.0.2",
4
4
  "description": "Playing actual music over fp-ts notes",
5
5
  "keywords": [
6
6
  "typescript",
7
7
  "functional-programming",
8
8
  "fp-ts",
9
- "io-ts"
9
+ "testing"
10
+ ],
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/esm/index.d.ts",
14
+ "require": "./dist/cjs/index.js",
15
+ "import": "./dist/cjs/index.js"
16
+ }
17
+ },
18
+ "files": [
19
+ "./dist/cjs/**",
20
+ "./dist/esm/**"
10
21
  ],
11
22
  "homepage": "https://github.com/facile-it/fortepiano#readme",
12
23
  "bugs": {
@@ -19,9 +30,9 @@
19
30
  "license": "MIT",
20
31
  "author": "Alberto Villa <villa.alberto@gmail.com>",
21
32
  "sideEffects": false,
22
- "main": "./lib/index.js",
23
- "module": "./esm/index.js",
24
- "types": "./index.d.ts",
33
+ "main": "./dist/cjs/index.js",
34
+ "module": "./dist/esm/index.js",
35
+ "types": "./dist/esm/index.d.ts",
25
36
  "scripts": {
26
37
  "prebuild": "yarn clean",
27
38
  "build": "yarn prebuild && yarn build:esm && yarn build:cjs",
@@ -32,73 +43,29 @@
32
43
  "eslint:fix": "eslint --fix ./",
33
44
  "prettier": "prettier --check ./",
34
45
  "prettier:fix": "prettier --write ./",
35
- "prerelease": "yarn build && ./scripts/hybridize.sh && cp ./package.json ./*.md ./dist/",
36
- "release": "yarn prerelease && npm publish ./dist/",
46
+ "prerelease": "yarn build",
47
+ "release": "yarn prerelease && npm publish",
37
48
  "test": "jest",
49
+ "test:watch": "jest --watchAll",
38
50
  "test:coverage": "jest --coverage"
39
51
  },
40
52
  "devDependencies": {
41
53
  "@rushstack/eslint-patch": "^1.1.3",
42
- "@slynova/flydrive": "^1.0.0",
43
54
  "@types/jest": "^26.0.24",
44
- "@types/memcached": "^2.0.0",
45
- "@types/node-fetch": "^2.5.12",
46
- "@types/redis": "^2.0.0",
47
- "@types/redis-mock": "^0.17.0",
48
- "axios": "^0.28.0",
55
+ "@types/node": "^22.8.7",
49
56
  "eslint": "^8.16.0",
50
57
  "eslint-config-facile": "^0.5.0",
51
58
  "fp-ts": "^2.0.0",
52
- "got": "^11.0.0",
53
59
  "io-ts": "^2.0.0",
54
- "io-ts-types": "^0.5.0",
55
60
  "jest": "^26.6.3",
56
- "memcached": "^2.0.0",
57
- "memcached-mock": "^0.1.0",
58
- "monocle-ts": "^2.3.10",
59
- "newtype-ts": "^0.3.4",
60
- "node-fetch": "^2.6.7",
61
61
  "prettier": "^2.6.2",
62
- "redis": "^3.0.0",
63
- "redis-mock": "^0.56.3",
64
62
  "ts-jest": "^26.5.6",
65
63
  "ts-node": "^10.9.2",
66
64
  "typescript": "^4.6.4"
67
65
  },
68
66
  "peerDependencies": {
69
- "@slynova/flydrive": "^1.0.0",
70
- "@types/memcached": "^2.0.0",
71
- "@types/redis": "^2.0.0",
72
- "axios": "^0.21.2 || ^0.28.0",
73
- "fp-ts": "^2.0.0",
74
- "got": "^11.0.0",
75
- "io-ts": "^2.0.0",
76
- "io-ts-types": "^0.5.0",
77
- "memcached": "^2.0.0",
78
- "redis": "^3.0.0"
79
- },
80
- "peerDependenciesMeta": {
81
- "@slynova/flydrive": {
82
- "optional": true
83
- },
84
- "@types/memcached": {
85
- "optional": true
86
- },
87
- "@types/redis": {
88
- "optional": true
89
- },
90
- "axios": {
91
- "optional": true
92
- },
93
- "got": {
94
- "optional": true
95
- },
96
- "memcached": {
97
- "optional": true
98
- },
99
- "redis": {
100
- "optional": true
101
- }
67
+ "fp-ts": "^2.5.0",
68
+ "io-ts": "^2.2.0"
102
69
  },
103
- "packageManager": "yarn@3.2.3"
70
+ "packageManager": "yarn@4.18.1"
104
71
  }
@@ -1,6 +0,0 @@
1
- {
2
- "main": "../lib/Aggregate.js",
3
- "module": "../esm/Aggregate.js",
4
- "types": "../Aggregate.d.ts",
5
- "sideEffects": false
6
- }
package/Aggregate.d.ts DELETED
@@ -1,4 +0,0 @@
1
- export interface Aggregate<A> {
2
- isEmpty: (a: A) => boolean;
3
- size: (a: A) => number;
4
- }
@@ -1,6 +0,0 @@
1
- {
2
- "main": "../lib/AsyncYield.js",
3
- "module": "../esm/AsyncYield.js",
4
- "types": "../AsyncYield.d.ts",
5
- "sideEffects": false
6
- }