fortepiano 1.0.0 → 1.0.3
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/CHANGELOG.md +230 -0
- package/README.md +102 -6
- 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 +15 -6
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 1.0.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#107](https://github.com/facile-it/fortepiano/pull/107) [`8268baf`](https://github.com/facile-it/fortepiano/commit/8268bafa66db140d4ee91917ef86ba712ce338e5) Thanks [@pierroberto](https://github.com/pierroberto)! - Add Changesets to automate versioning, changelog generation, and npm releases.
|
|
8
|
+
|
|
9
|
+
## [1.0.2](https://github.com/facile-it/fortepiano/compare/v1.0.1...v1.0.2) - 2026-08-10
|
|
10
|
+
|
|
11
|
+
### Changed
|
|
12
|
+
|
|
13
|
+
- Upgrade CI workflows to supported Node.js versions.
|
|
14
|
+
- Upgrade Yarn from 3.2.3 to 4.18.1.
|
|
15
|
+
|
|
16
|
+
## [1.0.1](https://github.com/facile-it/fortepiano/compare/v1.0.0...v1.0.1) - 2026-08-10
|
|
17
|
+
|
|
18
|
+
### Fixed
|
|
19
|
+
|
|
20
|
+
- Fix `prerelease` and `release` script.
|
|
21
|
+
|
|
22
|
+
## [1.0.0](https://github.com/facile-it/fortepiano/compare/v0.1.9...v1.0.0) - 2025-27-02
|
|
23
|
+
|
|
24
|
+
### Removed
|
|
25
|
+
|
|
26
|
+
- Remove `Http` module.
|
|
27
|
+
- Remove `Cache` module.
|
|
28
|
+
- Remove `Memcached` module.
|
|
29
|
+
- Remove `Buffer` module.
|
|
30
|
+
- Remove `Stream` module.
|
|
31
|
+
- Remove `Memory` module.
|
|
32
|
+
- Remove `Redis` module.
|
|
33
|
+
- Remove `Storage` module.
|
|
34
|
+
- Remove `Axios` module.
|
|
35
|
+
- Remove `Fetch` module.
|
|
36
|
+
- Remove `Got` module.
|
|
37
|
+
- Remove `Flydrive` module.
|
|
38
|
+
- Remove `Fs` module.
|
|
39
|
+
- Remove `Random` module.
|
|
40
|
+
- Remove `Log` module.
|
|
41
|
+
- Remove `Void` module.
|
|
42
|
+
- Remove `GeneratorL` module.
|
|
43
|
+
- Remove `number` module.
|
|
44
|
+
- Remove `Console` module.
|
|
45
|
+
- Remove `Crypto` module.
|
|
46
|
+
- Remove `Binary` module.
|
|
47
|
+
- Remove `Date` module.
|
|
48
|
+
- Remove `AsyncYield` module.
|
|
49
|
+
- Remove `Magma` module.
|
|
50
|
+
- Remove `Matrix` module.
|
|
51
|
+
- Remove `Option` module.
|
|
52
|
+
- Remove `Reader` module.
|
|
53
|
+
- Remove `ReaderEither` module.
|
|
54
|
+
- Remove `ReaderTask` module.
|
|
55
|
+
- Remove `ReaderTaskEither` module.
|
|
56
|
+
- Remove `ReadonlyTuple` module.
|
|
57
|
+
- Remove `TaskEither` module.
|
|
58
|
+
- Remove `Validation` module.
|
|
59
|
+
- Remove `Has` module.
|
|
60
|
+
- Remove `Aggregate` module.
|
|
61
|
+
- Remove `Eq` module.
|
|
62
|
+
- Remove `string` module.
|
|
63
|
+
- Remove `Error` module.
|
|
64
|
+
- Remove `ReadonlyRecord` module.
|
|
65
|
+
- Remove `ReadonlyArray` module.
|
|
66
|
+
- Remove `Yield` module.
|
|
67
|
+
- Remove unused functions `ReadonlyArray`, `Type`, `function` and `struct` modules.
|
|
68
|
+
|
|
69
|
+
## [0.1.9](https://github.com/facile-it/fortepiano/compare/v0.1.8...v0.1.9) - 2024-05-14
|
|
70
|
+
|
|
71
|
+
### Security
|
|
72
|
+
|
|
73
|
+
- Fix CVE-2022-25883.
|
|
74
|
+
|
|
75
|
+
## [0.1.8](https://github.com/facile-it/fortepiano/compare/v0.1.7...v0.1.8) - 2023-07-10
|
|
76
|
+
|
|
77
|
+
### Added
|
|
78
|
+
|
|
79
|
+
- Complete the list of `Http` errors.
|
|
80
|
+
|
|
81
|
+
### Security
|
|
82
|
+
|
|
83
|
+
- Fix CVE-2022-46175.
|
|
84
|
+
- Fix CVE-2022-25881.
|
|
85
|
+
- Fix CVE-2023-26136.
|
|
86
|
+
|
|
87
|
+
## [0.1.7](https://github.com/facile-it/fortepiano/compare/v0.1.6...v0.1.7) - 2023-01-02
|
|
88
|
+
|
|
89
|
+
### Added
|
|
90
|
+
|
|
91
|
+
- Add `infix` to `string` module.
|
|
92
|
+
|
|
93
|
+
## [0.1.6](https://github.com/facile-it/fortepiano/compare/v0.1.5...v0.1.6) - 2022-09-30
|
|
94
|
+
|
|
95
|
+
### Added
|
|
96
|
+
|
|
97
|
+
- Add `collectWithIndex` function to `ReadonlyRecord` module.
|
|
98
|
+
|
|
99
|
+
## [0.1.5](https://github.com/facile-it/fortepiano/compare/v0.1.4...v0.1.5) - 2022-09-22
|
|
100
|
+
|
|
101
|
+
### Added
|
|
102
|
+
|
|
103
|
+
- Add `prefix` to `string` module.
|
|
104
|
+
- Add `suffix` to `string` module.
|
|
105
|
+
|
|
106
|
+
### Changed
|
|
107
|
+
|
|
108
|
+
- Changed overloads of `$mock.union` function.
|
|
109
|
+
|
|
110
|
+
### Fixed
|
|
111
|
+
|
|
112
|
+
- Update `yarn.lock` in order to fix "typescript (18.x)" and "jest (18.x)" jobs in CI.
|
|
113
|
+
|
|
114
|
+
## [0.1.4](https://github.com/facile-it/fortepiano/compare/v0.1.3...v0.1.4) - 2022-06-24
|
|
115
|
+
|
|
116
|
+
### Security
|
|
117
|
+
|
|
118
|
+
- Fix CVE-2022-33987.
|
|
119
|
+
|
|
120
|
+
## [0.1.3](https://github.com/facile-it/fortepiano/compare/v0.1.2...v0.1.3) - 2022-05-31
|
|
121
|
+
|
|
122
|
+
### Added
|
|
123
|
+
|
|
124
|
+
- Add `AggregateError` inspired from TC39.
|
|
125
|
+
- Add `decode` method to `Type` module to help wrapping `io-ts` `Errors` into an `Error` subclass.
|
|
126
|
+
- Add unit tests for the `set` function of the `Redis` module.
|
|
127
|
+
- Add `Has` module and enhance `ReaderTaskEither` for smart dependencies management (inspired by [Effect-TS](https://www.matechs.com/open-source)):
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
// Foo.ts
|
|
131
|
+
import { TaskEither } from 'fp-ts/TaskEither'
|
|
132
|
+
import { $has, $readerTaskEither } from 'fortepiano'
|
|
133
|
+
|
|
134
|
+
export interface Foo {
|
|
135
|
+
bar(a: number): TaskEither<Error, string>
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export const TagFoo = $has.tag<Foo>()
|
|
139
|
+
|
|
140
|
+
export const $foo = {
|
|
141
|
+
bar: $readerTaskEither.derivesTaskEither(TagFoo, 'bar'),
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
// Bar.ts
|
|
147
|
+
import { IOEither } from 'fp-ts/IOEither'
|
|
148
|
+
import { $has, $readerTaskEither } from 'fortepiano'
|
|
149
|
+
|
|
150
|
+
export interface Bar {
|
|
151
|
+
(a: string): IOEither<Error, boolean>
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export const TagBar = $has.tag<Bar>()
|
|
155
|
+
|
|
156
|
+
export const bar = $readerTaskEither.deriveIOEither(TagBar)
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
```typescript
|
|
160
|
+
// index.ts
|
|
161
|
+
import { $has } from 'fortepiano'
|
|
162
|
+
import { ioEither, readerTaskEither, taskEither } from 'fp-ts'
|
|
163
|
+
import { pipe } from 'fp-ts/function'
|
|
164
|
+
import { TagBar, bar } from './Bar'
|
|
165
|
+
import { $foo, TagFoo } from './Foo'
|
|
166
|
+
|
|
167
|
+
// const a: ReaderTaskEither<Has<Foo> & Has<Bar>, Error, boolean>
|
|
168
|
+
const a = pipe($foo.bar(42), readerTaskEither.chainW(bar))
|
|
169
|
+
|
|
170
|
+
// const b: TaskEither<Error, boolean>
|
|
171
|
+
const b = a(
|
|
172
|
+
// Let's mock our dependencies.
|
|
173
|
+
pipe(
|
|
174
|
+
$has.singleton(TagFoo, { bar: () => taskEither.of('foobar') }),
|
|
175
|
+
$has.upsertAt(TagBar, () => ioEither.of(true)),
|
|
176
|
+
),
|
|
177
|
+
)
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### Changed
|
|
181
|
+
|
|
182
|
+
- Replace `struct` type with `Struct`.
|
|
183
|
+
- Rename `GeneratorL` module to `Yield`.
|
|
184
|
+
- Use `cause` property to record wrapped errors (inspired by TC39).
|
|
185
|
+
|
|
186
|
+
### Deprecated
|
|
187
|
+
|
|
188
|
+
- Deprecate `struct` (use `Struct` instead).
|
|
189
|
+
- Deprecate `GeneratorL` module (use `Yield` instead).
|
|
190
|
+
|
|
191
|
+
### Fixed
|
|
192
|
+
|
|
193
|
+
- Decode from Json and then from the given codec in the `get` function of the `Redis` module.
|
|
194
|
+
|
|
195
|
+
## [0.1.2](https://github.com/facile-it/fortepiano/compare/v0.1.1...v0.1.2) - 2022-04-29
|
|
196
|
+
|
|
197
|
+
### Added
|
|
198
|
+
|
|
199
|
+
- Add `LICENSE.md`.
|
|
200
|
+
- Add `CONTRIBUTING.md`.
|
|
201
|
+
- Add `CHANGELOG.md`.
|
|
202
|
+
|
|
203
|
+
### Changed
|
|
204
|
+
|
|
205
|
+
- Relicense as MIT.
|
|
206
|
+
- Update `README.md`.
|
|
207
|
+
|
|
208
|
+
### Deprecated
|
|
209
|
+
|
|
210
|
+
- Deprecate `$got` (use `$axios` instead).
|
|
211
|
+
|
|
212
|
+
## [0.1.1](https://github.com/facile-it/fortepiano/compare/v0.1.0...v0.1.1) - 2022-04-26
|
|
213
|
+
|
|
214
|
+
### Added
|
|
215
|
+
|
|
216
|
+
- Support [tree shaking](https://webpack.js.org/guides/tree-shaking/) via top-level imports:
|
|
217
|
+
```typescript
|
|
218
|
+
import { curry } from 'fortepiano/function'
|
|
219
|
+
// ...instead of `import { curry } from 'fortepiano/lib/function'`
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### Deprecated
|
|
223
|
+
|
|
224
|
+
- Discourage imports from `fortepiano/lib/*` as they break tree shaking.
|
|
225
|
+
|
|
226
|
+
## [0.1.0](https://github.com/facile-it/fortepiano/releases/tag/v0.1.0) - 2022-04-20
|
|
227
|
+
|
|
228
|
+
### Added
|
|
229
|
+
|
|
230
|
+
- First public release of `fortepiano`.
|
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
<p align="center">
|
|
2
|
-
<img src="./logo.png" width=150px" height="auto"/>
|
|
2
|
+
<img src="./logo.png" width="150px" height="auto"/>
|
|
3
3
|
</p>
|
|
4
4
|
|
|
5
5
|
# fortepiano [ˌfɔrteˈpjaːno]
|
|
6
6
|
|
|
7
|
-
_Playing actual music over
|
|
7
|
+
_Playing actual music over functional notes_ 🎶
|
|
8
8
|
|
|
9
9
|
[](https://github.com/facile-it/fortepiano/actions)
|
|
10
10
|
[](https://app.codecov.io/gh/facile-it/fortepiano)
|
|
@@ -25,7 +25,7 @@ To install the stable version:
|
|
|
25
25
|
npm install fortepiano
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
-
or using
|
|
28
|
+
or using Yarn:
|
|
29
29
|
|
|
30
30
|
```bash
|
|
31
31
|
yarn add fortepiano
|
|
@@ -35,10 +35,26 @@ yarn add fortepiano
|
|
|
35
35
|
|
|
36
36
|
Fortepiano uses a functional API to create and configure mocks, encouraging pure function usage and immutable mock objects.
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
Import Fortepiano as a namespace:
|
|
39
39
|
|
|
40
40
|
```typescript
|
|
41
|
-
import
|
|
41
|
+
import * as $mock from 'fortepiano'
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
A mock is a function that produces an `IO`, so call it twice to generate a value:
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
const value = $mock.string()()
|
|
48
|
+
|
|
49
|
+
console.log(value) // A randomly generated string
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
#### Creating structured mocks
|
|
53
|
+
|
|
54
|
+
Use `$mock.struct` to combine mocks:
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
import * as $mock from 'fortepiano'
|
|
42
58
|
|
|
43
59
|
interface User {
|
|
44
60
|
firstName: string
|
|
@@ -51,7 +67,87 @@ export const UserMock = (): $mock.Mock<User> =>
|
|
|
51
67
|
lastName: $mock.string,
|
|
52
68
|
})
|
|
53
69
|
|
|
54
|
-
|
|
70
|
+
const user = UserMock()()()
|
|
71
|
+
|
|
72
|
+
console.log(user)
|
|
73
|
+
// { firstName: "<random string>", lastName: "<random string>" }
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
`UserMock()` creates the mock, the second call creates its `IO`, and the third call executes that `IO`.
|
|
77
|
+
|
|
78
|
+
You can also define the mock directly:
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
const userMock: $mock.Mock<User> = $mock.struct({
|
|
82
|
+
firstName: $mock.string,
|
|
83
|
+
lastName: $mock.string,
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
const user = userMock()()
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
#### Using fixed values
|
|
90
|
+
|
|
91
|
+
Use `$mock.of` when a mock should always produce a specific value:
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
const testString = $mock.of('test')
|
|
95
|
+
|
|
96
|
+
console.log(testString()()) // "test"
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Fixed and generated values can be combined in a structured mock:
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
const userMock: $mock.Mock<User> = $mock.struct({
|
|
103
|
+
firstName: $mock.of('test'),
|
|
104
|
+
lastName: $mock.string,
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
console.log(userMock()())
|
|
108
|
+
// { firstName: "test", lastName: "<random string>" }
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
#### Overriding generated values
|
|
112
|
+
|
|
113
|
+
A value can be supplied when invoking a mock:
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
console.log($mock.string('test')()) // "test"
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Structured mocks accept partial overrides:
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
const userMock: $mock.Mock<User> = $mock.struct({
|
|
123
|
+
firstName: $mock.string,
|
|
124
|
+
lastName: $mock.string,
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
console.log(userMock({ firstName: 'John' })())
|
|
128
|
+
// { firstName: "John", lastName: "<random string>" }
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
This lets you reuse a mock while customizing only the properties relevant to a test.
|
|
132
|
+
|
|
133
|
+
#### Importing individual exports
|
|
134
|
+
|
|
135
|
+
You can import individual functions and types instead of using a namespace:
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
import { of, string, struct, type Mock } from 'fortepiano'
|
|
139
|
+
|
|
140
|
+
interface User {
|
|
141
|
+
firstName: string
|
|
142
|
+
lastName: string
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const userMock: Mock<User> = struct({
|
|
146
|
+
firstName: of('test'),
|
|
147
|
+
lastName: string,
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
console.log(userMock()())
|
|
55
151
|
```
|
|
56
152
|
|
|
57
153
|
## Contributing
|
|
@@ -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.3",
|
|
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,13 +43,17 @@
|
|
|
42
43
|
"eslint:fix": "eslint --fix ./",
|
|
43
44
|
"prettier": "prettier --check ./",
|
|
44
45
|
"prettier:fix": "prettier --write ./",
|
|
45
|
-
"
|
|
46
|
-
"
|
|
46
|
+
"changeset": "changeset",
|
|
47
|
+
"changeset:version": "changeset version",
|
|
48
|
+
"prerelease": "yarn build",
|
|
49
|
+
"release": "yarn prerelease && changeset publish",
|
|
47
50
|
"test": "jest",
|
|
48
51
|
"test:watch": "jest --watchAll",
|
|
49
52
|
"test:coverage": "jest --coverage"
|
|
50
53
|
},
|
|
51
54
|
"devDependencies": {
|
|
55
|
+
"@changesets/changelog-github": "^1.0.1",
|
|
56
|
+
"@changesets/cli": "^3.0.3",
|
|
52
57
|
"@rushstack/eslint-patch": "^1.1.3",
|
|
53
58
|
"@types/jest": "^26.0.24",
|
|
54
59
|
"@types/node": "^22.8.7",
|
|
@@ -62,5 +67,9 @@
|
|
|
62
67
|
"ts-node": "^10.9.2",
|
|
63
68
|
"typescript": "^4.6.4"
|
|
64
69
|
},
|
|
65
|
-
"
|
|
66
|
-
|
|
70
|
+
"peerDependencies": {
|
|
71
|
+
"fp-ts": "^2.5.0",
|
|
72
|
+
"io-ts": "^2.2.0"
|
|
73
|
+
},
|
|
74
|
+
"packageManager": "yarn@4.18.1"
|
|
75
|
+
}
|