fortepiano 1.0.2 → 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.
Files changed (3) hide show
  1. package/CHANGELOG.md +230 -0
  2. package/README.md +102 -6
  3. package/package.json +7 -3
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 `fp-ts` notes_ 🎶
7
+ _Playing actual music over functional notes_ 🎶
8
8
 
9
9
  [![GitHub Workflow Status](https://img.shields.io/github/workflow/status/facile-it/fortepiano/main)](https://github.com/facile-it/fortepiano/actions)
10
10
  [![Codecov](https://img.shields.io/codecov/c/gh/facile-it/fortepiano)](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 yarn:
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
- Here's an example:
38
+ Import Fortepiano as a namespace:
39
39
 
40
40
  ```typescript
41
- import { $mock } from 'fortepiano'
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
- console.log(UserMock()()()) // Output: { firstName: 'randomString', lastName: 'randomString' }
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fortepiano",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Playing actual music over fp-ts notes",
5
5
  "keywords": [
6
6
  "typescript",
@@ -43,13 +43,17 @@
43
43
  "eslint:fix": "eslint --fix ./",
44
44
  "prettier": "prettier --check ./",
45
45
  "prettier:fix": "prettier --write ./",
46
+ "changeset": "changeset",
47
+ "changeset:version": "changeset version",
46
48
  "prerelease": "yarn build",
47
- "release": "yarn prerelease && npm publish",
49
+ "release": "yarn prerelease && changeset publish",
48
50
  "test": "jest",
49
51
  "test:watch": "jest --watchAll",
50
52
  "test:coverage": "jest --coverage"
51
53
  },
52
54
  "devDependencies": {
55
+ "@changesets/changelog-github": "^1.0.1",
56
+ "@changesets/cli": "^3.0.3",
53
57
  "@rushstack/eslint-patch": "^1.1.3",
54
58
  "@types/jest": "^26.0.24",
55
59
  "@types/node": "^22.8.7",
@@ -68,4 +72,4 @@
68
72
  "io-ts": "^2.2.0"
69
73
  },
70
74
  "packageManager": "yarn@4.18.1"
71
- }
75
+ }