klubok 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +38 -0
- package/dist/index.d.ts +898 -0
- package/dist/index.js +24 -0
- package/package.json +40 -0
package/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# Klubok
|
2
|
+
|
3
|
+
![logo](logo.png)
|
4
|
+
|
5
|
+
Do notation pipes for Promise-based or pure functions which easy to mock <br/>
|
6
|
+
Inspired by fp-ts/Effect `bind` Do-notation, but much more small and simple <br/>
|
7
|
+
Primarly created for easy mocking of functions, which allows to write tons of unit tests
|
8
|
+
|
9
|
+
## Example
|
10
|
+
|
11
|
+
```ts
|
12
|
+
import { pure, eff, klubok } from 'klubok';
|
13
|
+
|
14
|
+
const catsBirthdays = klubok(
|
15
|
+
eff('cats', async ({ ids }: { ids: number[] }) => { /* fetch cats from DB */ }),
|
16
|
+
pure('catsOneYearOld', ({ cats }) => cats.map(c => ({ ...c, age: c.age + 1 })),
|
17
|
+
eff('saved', async ({ catsOneYearOld }) => { /* save to DB */ })
|
18
|
+
)
|
19
|
+
|
20
|
+
// production usage
|
21
|
+
catsBirthdays({ ids: [1, 2, 3] })
|
22
|
+
|
23
|
+
// in tests usage
|
24
|
+
catsBirthdays(
|
25
|
+
{ ids: [1, 2, 3] },
|
26
|
+
{
|
27
|
+
// DB response mock
|
28
|
+
cats: () => [
|
29
|
+
{ name: 'Barsik', age: 10 },
|
30
|
+
{ name: 'Marfa', age: 7 }
|
31
|
+
]
|
32
|
+
},
|
33
|
+
// call only this functions
|
34
|
+
['catsOneYearOld']
|
35
|
+
) // Promise<{ ..., catsOneYearOld: [{ name: 'Barsik', age: 11 }, { name: 'Marfa', age: 8 }] }>
|
36
|
+
|
37
|
+
```
|
38
|
+
|
package/dist/index.d.ts
ADDED
@@ -0,0 +1,898 @@
|
|
1
|
+
type KeyedFunction<K extends string, F extends Function> = F & {
|
2
|
+
key: K;
|
3
|
+
mutable: boolean;
|
4
|
+
};
|
5
|
+
export declare const pure: <K extends string, C, R>(key: K, fn: (ctx: C) => R) => KeyedFunction<K, (ctx: C) => R>;
|
6
|
+
export declare const eff: <K extends string, C, R>(key: K, fn: (ctx: C) => Promise<R>) => KeyedFunction<K, (ctx: C) => Promise<R>>;
|
7
|
+
export declare const mut: <K extends string, C, R>(fn: KeyedFunction<K, (ctx: C) => R>) => KeyedFunction<K, (ctx: C) => R>;
|
8
|
+
export declare function klubok<K1 extends string, C extends object, R1>(fn1: KeyedFunction<K1, (ctx: C) => Promise<R1> | R1>): (ctx: C, mock?: {
|
9
|
+
[k in K1]?: R1 | ((ctx: C) => R1);
|
10
|
+
}, only?: K1[]) => Promise<C & {
|
11
|
+
[k in K1]: R1;
|
12
|
+
}>;
|
13
|
+
export declare function klubok<K1 extends string, K2 extends string, C extends object, R1, R2>(fn1: KeyedFunction<K1, (ctx: C) => Promise<R1> | R1>, fn2: KeyedFunction<K2, (ctx: C & {
|
14
|
+
[k in K1]: R1;
|
15
|
+
}) => Promise<R2> | R2>): (ctx: C, mock?: {
|
16
|
+
[k in K1]?: R1 | ((ctx: C) => R1);
|
17
|
+
} & {
|
18
|
+
[k in K2]?: R2 | ((ctx: C & {
|
19
|
+
[k in K1]: R1;
|
20
|
+
}) => R2);
|
21
|
+
}, only?: (K1 | K2)[]) => Promise<C & {
|
22
|
+
[k in K1]: R1;
|
23
|
+
} & {
|
24
|
+
[k in K2]: R2;
|
25
|
+
}>;
|
26
|
+
export declare function klubok<K1 extends string, K2 extends string, K3 extends string, C extends object, R1, R2, R3>(fn1: KeyedFunction<K1, (ctx: C) => Promise<R1> | R1>, fn2: KeyedFunction<K2, (ctx: C & {
|
27
|
+
[k in K1]: R1;
|
28
|
+
}) => Promise<R2> | R2>, fn3: KeyedFunction<K3, (ctx: C & {
|
29
|
+
[k in K1]: R1;
|
30
|
+
} & {
|
31
|
+
[k in K2]: R2;
|
32
|
+
}) => Promise<R3> | R3>): (ctx: C, mock?: {
|
33
|
+
[k in K1]?: R1 | ((ctx: C) => R1);
|
34
|
+
} & {
|
35
|
+
[k in K2]?: R2 | ((ctx: C & {
|
36
|
+
[k in K1]: R1;
|
37
|
+
}) => R2);
|
38
|
+
} & {
|
39
|
+
[k in K3]?: R3 | ((ctx: C & {
|
40
|
+
[k in K1]: R1;
|
41
|
+
} & {
|
42
|
+
[k in K2]: R2;
|
43
|
+
}) => R3);
|
44
|
+
}, only?: (K1 | K2 | K3)[]) => Promise<C & {
|
45
|
+
[k in K1]: R1;
|
46
|
+
} & {
|
47
|
+
[k in K2]: R2;
|
48
|
+
} & {
|
49
|
+
[k in K3]: R3;
|
50
|
+
}>;
|
51
|
+
export declare function klubok<K1 extends string, K2 extends string, K3 extends string, K4 extends string, C extends object, R1, R2, R3, R4>(fn1: KeyedFunction<K1, (ctx: C) => Promise<R1> | R1>, fn2: KeyedFunction<K2, (ctx: C & {
|
52
|
+
[k in K1]: R1;
|
53
|
+
}) => Promise<R2> | R2>, fn3: KeyedFunction<K3, (ctx: C & {
|
54
|
+
[k in K1]: R1;
|
55
|
+
} & {
|
56
|
+
[k in K2]: R2;
|
57
|
+
}) => Promise<R3> | R3>, fn4: KeyedFunction<K4, (ctx: C & {
|
58
|
+
[k in K1]: R1;
|
59
|
+
} & {
|
60
|
+
[k in K2]: R2;
|
61
|
+
} & {
|
62
|
+
[k in K3]: R3;
|
63
|
+
}) => Promise<R4> | R4>): (ctx: C, mock?: {
|
64
|
+
[k in K1]?: R1 | ((ctx: C) => R1);
|
65
|
+
} & {
|
66
|
+
[k in K2]?: R2 | ((ctx: C & {
|
67
|
+
[k in K1]: R1;
|
68
|
+
}) => R2);
|
69
|
+
} & {
|
70
|
+
[k in K3]?: R3 | ((ctx: C & {
|
71
|
+
[k in K1]: R1;
|
72
|
+
} & {
|
73
|
+
[k in K2]: R2;
|
74
|
+
}) => R3);
|
75
|
+
} & {
|
76
|
+
[k in K4]?: R4 | ((ctx: C & {
|
77
|
+
[k in K1]: R1;
|
78
|
+
} & {
|
79
|
+
[k in K2]: R2;
|
80
|
+
} & {
|
81
|
+
[k in K3]: R3;
|
82
|
+
}) => R4);
|
83
|
+
}, only?: (K1 | K2 | K3 | K4)[]) => Promise<C & {
|
84
|
+
[k in K1]: R1;
|
85
|
+
} & {
|
86
|
+
[k in K2]: R2;
|
87
|
+
} & {
|
88
|
+
[k in K3]: R3;
|
89
|
+
} & {
|
90
|
+
[k in K4]: R4;
|
91
|
+
}>;
|
92
|
+
export declare function klubok<K1 extends string, K2 extends string, K3 extends string, K4 extends string, K5 extends string, C extends object, R1, R2, R3, R4, R5>(fn1: KeyedFunction<K1, (ctx: C) => Promise<R1> | R1>, fn2: KeyedFunction<K2, (ctx: C & {
|
93
|
+
[k in K1]: R1;
|
94
|
+
}) => Promise<R2> | R2>, fn3: KeyedFunction<K3, (ctx: C & {
|
95
|
+
[k in K1]: R1;
|
96
|
+
} & {
|
97
|
+
[k in K2]: R2;
|
98
|
+
}) => Promise<R3> | R3>, fn4: KeyedFunction<K4, (ctx: C & {
|
99
|
+
[k in K1]: R1;
|
100
|
+
} & {
|
101
|
+
[k in K2]: R2;
|
102
|
+
} & {
|
103
|
+
[k in K3]: R3;
|
104
|
+
}) => Promise<R4> | R4>, fn5: KeyedFunction<K5, (ctx: C & {
|
105
|
+
[k in K1]: R1;
|
106
|
+
} & {
|
107
|
+
[k in K2]: R2;
|
108
|
+
} & {
|
109
|
+
[k in K3]: R3;
|
110
|
+
} & {
|
111
|
+
[k in K4]: R4;
|
112
|
+
}) => Promise<R5> | R5>): (ctx: C, mock?: {
|
113
|
+
[k in K1]?: R1 | ((ctx: C) => R1);
|
114
|
+
} & {
|
115
|
+
[k in K2]?: R2 | ((ctx: C & {
|
116
|
+
[k in K1]: R1;
|
117
|
+
}) => R2);
|
118
|
+
} & {
|
119
|
+
[k in K3]?: R3 | ((ctx: C & {
|
120
|
+
[k in K1]: R1;
|
121
|
+
} & {
|
122
|
+
[k in K2]: R2;
|
123
|
+
}) => R3);
|
124
|
+
} & {
|
125
|
+
[k in K4]?: R4 | ((ctx: C & {
|
126
|
+
[k in K1]: R1;
|
127
|
+
} & {
|
128
|
+
[k in K2]: R2;
|
129
|
+
} & {
|
130
|
+
[k in K3]: R3;
|
131
|
+
}) => R4);
|
132
|
+
} & {
|
133
|
+
[k in K5]?: R5 | ((ctx: C & {
|
134
|
+
[k in K1]: R1;
|
135
|
+
} & {
|
136
|
+
[k in K2]: R2;
|
137
|
+
} & {
|
138
|
+
[k in K3]: R3;
|
139
|
+
} & {
|
140
|
+
[k in K4]: R4;
|
141
|
+
}) => R5);
|
142
|
+
}, only?: (K1 | K2 | K3 | K4 | K5)[]) => Promise<C & {
|
143
|
+
[k in K1]: R1;
|
144
|
+
} & {
|
145
|
+
[k in K2]: R2;
|
146
|
+
} & {
|
147
|
+
[k in K3]: R3;
|
148
|
+
} & {
|
149
|
+
[k in K4]: R4;
|
150
|
+
} & {
|
151
|
+
[k in K5]: R5;
|
152
|
+
}>;
|
153
|
+
export declare function klubok<K1 extends string, K2 extends string, K3 extends string, K4 extends string, K5 extends string, K6 extends string, C extends object, R1, R2, R3, R4, R5, R6>(fn1: KeyedFunction<K1, (ctx: C) => Promise<R1> | R1>, fn2: KeyedFunction<K2, (ctx: C & {
|
154
|
+
[k in K1]: R1;
|
155
|
+
}) => Promise<R2> | R2>, fn3: KeyedFunction<K3, (ctx: C & {
|
156
|
+
[k in K1]: R1;
|
157
|
+
} & {
|
158
|
+
[k in K2]: R2;
|
159
|
+
}) => Promise<R3> | R3>, fn4: KeyedFunction<K4, (ctx: C & {
|
160
|
+
[k in K1]: R1;
|
161
|
+
} & {
|
162
|
+
[k in K2]: R2;
|
163
|
+
} & {
|
164
|
+
[k in K3]: R3;
|
165
|
+
}) => Promise<R4> | R4>, fn5: KeyedFunction<K5, (ctx: C & {
|
166
|
+
[k in K1]: R1;
|
167
|
+
} & {
|
168
|
+
[k in K2]: R2;
|
169
|
+
} & {
|
170
|
+
[k in K3]: R3;
|
171
|
+
} & {
|
172
|
+
[k in K4]: R4;
|
173
|
+
}) => Promise<R5> | R5>, fn6: KeyedFunction<K6, (ctx: C & {
|
174
|
+
[k in K1]: R1;
|
175
|
+
} & {
|
176
|
+
[k in K2]: R2;
|
177
|
+
} & {
|
178
|
+
[k in K3]: R3;
|
179
|
+
} & {
|
180
|
+
[k in K4]: R4;
|
181
|
+
} & {
|
182
|
+
[k in K5]: R5;
|
183
|
+
}) => Promise<R6> | R6>): (ctx: C, mock?: {
|
184
|
+
[k in K1]?: R1 | ((ctx: C) => R1);
|
185
|
+
} & {
|
186
|
+
[k in K2]?: R2 | ((ctx: C & {
|
187
|
+
[k in K1]: R1;
|
188
|
+
}) => R2);
|
189
|
+
} & {
|
190
|
+
[k in K3]?: R3 | ((ctx: C & {
|
191
|
+
[k in K1]: R1;
|
192
|
+
} & {
|
193
|
+
[k in K2]: R2;
|
194
|
+
}) => R3);
|
195
|
+
} & {
|
196
|
+
[k in K4]?: R4 | ((ctx: C & {
|
197
|
+
[k in K1]: R1;
|
198
|
+
} & {
|
199
|
+
[k in K2]: R2;
|
200
|
+
} & {
|
201
|
+
[k in K3]: R3;
|
202
|
+
}) => R4);
|
203
|
+
} & {
|
204
|
+
[k in K5]?: R5 | ((ctx: C & {
|
205
|
+
[k in K1]: R1;
|
206
|
+
} & {
|
207
|
+
[k in K2]: R2;
|
208
|
+
} & {
|
209
|
+
[k in K3]: R3;
|
210
|
+
} & {
|
211
|
+
[k in K4]: R4;
|
212
|
+
}) => R5);
|
213
|
+
} & {
|
214
|
+
[k in K6]?: R6 | ((ctx: C & {
|
215
|
+
[k in K1]: R1;
|
216
|
+
} & {
|
217
|
+
[k in K2]: R2;
|
218
|
+
} & {
|
219
|
+
[k in K3]: R3;
|
220
|
+
} & {
|
221
|
+
[k in K4]: R4;
|
222
|
+
} & {
|
223
|
+
[k in K5]: R5;
|
224
|
+
}) => R6);
|
225
|
+
}, only?: (K1 | K2 | K3 | K4 | K5 | K6)[]) => Promise<C & {
|
226
|
+
[k in K1]: R1;
|
227
|
+
} & {
|
228
|
+
[k in K2]: R2;
|
229
|
+
} & {
|
230
|
+
[k in K3]: R3;
|
231
|
+
} & {
|
232
|
+
[k in K4]: R4;
|
233
|
+
} & {
|
234
|
+
[k in K5]: R5;
|
235
|
+
} & {
|
236
|
+
[k in K6]: R6;
|
237
|
+
}>;
|
238
|
+
export declare function klubok<K1 extends string, K2 extends string, K3 extends string, K4 extends string, K5 extends string, K6 extends string, K7 extends string, C extends object, R1, R2, R3, R4, R5, R6, R7>(fn1: KeyedFunction<K1, (ctx: C) => Promise<R1> | R1>, fn2: KeyedFunction<K2, (ctx: C & {
|
239
|
+
[k in K1]: R1;
|
240
|
+
}) => Promise<R2> | R2>, fn3: KeyedFunction<K3, (ctx: C & {
|
241
|
+
[k in K1]: R1;
|
242
|
+
} & {
|
243
|
+
[k in K2]: R2;
|
244
|
+
}) => Promise<R3> | R3>, fn4: KeyedFunction<K4, (ctx: C & {
|
245
|
+
[k in K1]: R1;
|
246
|
+
} & {
|
247
|
+
[k in K2]: R2;
|
248
|
+
} & {
|
249
|
+
[k in K3]: R3;
|
250
|
+
}) => Promise<R4> | R4>, fn5: KeyedFunction<K5, (ctx: C & {
|
251
|
+
[k in K1]: R1;
|
252
|
+
} & {
|
253
|
+
[k in K2]: R2;
|
254
|
+
} & {
|
255
|
+
[k in K3]: R3;
|
256
|
+
} & {
|
257
|
+
[k in K4]: R4;
|
258
|
+
}) => Promise<R5> | R5>, fn6: KeyedFunction<K6, (ctx: C & {
|
259
|
+
[k in K1]: R1;
|
260
|
+
} & {
|
261
|
+
[k in K2]: R2;
|
262
|
+
} & {
|
263
|
+
[k in K3]: R3;
|
264
|
+
} & {
|
265
|
+
[k in K4]: R4;
|
266
|
+
} & {
|
267
|
+
[k in K5]: R5;
|
268
|
+
}) => Promise<R6> | R6>, fn7: KeyedFunction<K7, (ctx: C & {
|
269
|
+
[k in K1]: R1;
|
270
|
+
} & {
|
271
|
+
[k in K2]: R2;
|
272
|
+
} & {
|
273
|
+
[k in K3]: R3;
|
274
|
+
} & {
|
275
|
+
[k in K4]: R4;
|
276
|
+
} & {
|
277
|
+
[k in K5]: R5;
|
278
|
+
} & {
|
279
|
+
[k in K6]: R6;
|
280
|
+
}) => Promise<R7> | R7>): (ctx: C, mock?: {
|
281
|
+
[k in K1]?: R1 | ((ctx: C) => R1);
|
282
|
+
} & {
|
283
|
+
[k in K2]?: R2 | ((ctx: C & {
|
284
|
+
[k in K1]: R1;
|
285
|
+
}) => R2);
|
286
|
+
} & {
|
287
|
+
[k in K3]?: R3 | ((ctx: C & {
|
288
|
+
[k in K1]: R1;
|
289
|
+
} & {
|
290
|
+
[k in K2]: R2;
|
291
|
+
}) => R3);
|
292
|
+
} & {
|
293
|
+
[k in K4]?: R4 | ((ctx: C & {
|
294
|
+
[k in K1]: R1;
|
295
|
+
} & {
|
296
|
+
[k in K2]: R2;
|
297
|
+
} & {
|
298
|
+
[k in K3]: R3;
|
299
|
+
}) => R4);
|
300
|
+
} & {
|
301
|
+
[k in K5]?: R5 | ((ctx: C & {
|
302
|
+
[k in K1]: R1;
|
303
|
+
} & {
|
304
|
+
[k in K2]: R2;
|
305
|
+
} & {
|
306
|
+
[k in K3]: R3;
|
307
|
+
} & {
|
308
|
+
[k in K4]: R4;
|
309
|
+
}) => R5);
|
310
|
+
} & {
|
311
|
+
[k in K6]?: R6 | ((ctx: C & {
|
312
|
+
[k in K1]: R1;
|
313
|
+
} & {
|
314
|
+
[k in K2]: R2;
|
315
|
+
} & {
|
316
|
+
[k in K3]: R3;
|
317
|
+
} & {
|
318
|
+
[k in K4]: R4;
|
319
|
+
} & {
|
320
|
+
[k in K5]: R5;
|
321
|
+
}) => R6);
|
322
|
+
} & {
|
323
|
+
[k in K7]?: R7 | ((ctx: C & {
|
324
|
+
[k in K1]: R1;
|
325
|
+
} & {
|
326
|
+
[k in K2]: R2;
|
327
|
+
} & {
|
328
|
+
[k in K3]: R3;
|
329
|
+
} & {
|
330
|
+
[k in K4]: R4;
|
331
|
+
} & {
|
332
|
+
[k in K5]: R5;
|
333
|
+
} & {
|
334
|
+
[k in K6]: R6;
|
335
|
+
}) => R7);
|
336
|
+
}, only?: (K1 | K2 | K3 | K4 | K5 | K6 | K7)[]) => Promise<C & {
|
337
|
+
[k in K1]: R1;
|
338
|
+
} & {
|
339
|
+
[k in K2]: R2;
|
340
|
+
} & {
|
341
|
+
[k in K3]: R3;
|
342
|
+
} & {
|
343
|
+
[k in K4]: R4;
|
344
|
+
} & {
|
345
|
+
[k in K5]: R5;
|
346
|
+
} & {
|
347
|
+
[k in K6]: R6;
|
348
|
+
} & {
|
349
|
+
[k in K7]: R7;
|
350
|
+
}>;
|
351
|
+
export declare function klubok<K1 extends string, K2 extends string, K3 extends string, K4 extends string, K5 extends string, K6 extends string, K7 extends string, K8 extends string, C extends object, R1, R2, R3, R4, R5, R6, R7, R8>(fn1: KeyedFunction<K1, (ctx: C) => Promise<R1> | R1>, fn2: KeyedFunction<K2, (ctx: C & {
|
352
|
+
[k in K1]: R1;
|
353
|
+
}) => Promise<R2> | R2>, fn3: KeyedFunction<K3, (ctx: C & {
|
354
|
+
[k in K1]: R1;
|
355
|
+
} & {
|
356
|
+
[k in K2]: R2;
|
357
|
+
}) => Promise<R3> | R3>, fn4: KeyedFunction<K4, (ctx: C & {
|
358
|
+
[k in K1]: R1;
|
359
|
+
} & {
|
360
|
+
[k in K2]: R2;
|
361
|
+
} & {
|
362
|
+
[k in K3]: R3;
|
363
|
+
}) => Promise<R4> | R4>, fn5: KeyedFunction<K5, (ctx: C & {
|
364
|
+
[k in K1]: R1;
|
365
|
+
} & {
|
366
|
+
[k in K2]: R2;
|
367
|
+
} & {
|
368
|
+
[k in K3]: R3;
|
369
|
+
} & {
|
370
|
+
[k in K4]: R4;
|
371
|
+
}) => Promise<R5> | R5>, fn6: KeyedFunction<K6, (ctx: C & {
|
372
|
+
[k in K1]: R1;
|
373
|
+
} & {
|
374
|
+
[k in K2]: R2;
|
375
|
+
} & {
|
376
|
+
[k in K3]: R3;
|
377
|
+
} & {
|
378
|
+
[k in K4]: R4;
|
379
|
+
} & {
|
380
|
+
[k in K5]: R5;
|
381
|
+
}) => Promise<R6> | R6>, fn7: KeyedFunction<K7, (ctx: C & {
|
382
|
+
[k in K1]: R1;
|
383
|
+
} & {
|
384
|
+
[k in K2]: R2;
|
385
|
+
} & {
|
386
|
+
[k in K3]: R3;
|
387
|
+
} & {
|
388
|
+
[k in K4]: R4;
|
389
|
+
} & {
|
390
|
+
[k in K5]: R5;
|
391
|
+
} & {
|
392
|
+
[k in K6]: R6;
|
393
|
+
}) => Promise<R7> | R7>, fn8: KeyedFunction<K8, (ctx: C & {
|
394
|
+
[k in K1]: R1;
|
395
|
+
} & {
|
396
|
+
[k in K2]: R2;
|
397
|
+
} & {
|
398
|
+
[k in K3]: R3;
|
399
|
+
} & {
|
400
|
+
[k in K4]: R4;
|
401
|
+
} & {
|
402
|
+
[k in K5]: R5;
|
403
|
+
} & {
|
404
|
+
[k in K6]: R6;
|
405
|
+
} & {
|
406
|
+
[k in K7]: R7;
|
407
|
+
}) => Promise<R8> | R8>): (ctx: C, mock?: {
|
408
|
+
[k in K1]?: R1 | ((ctx: C) => R1);
|
409
|
+
} & {
|
410
|
+
[k in K2]?: R2 | ((ctx: C & {
|
411
|
+
[k in K1]: R1;
|
412
|
+
}) => R2);
|
413
|
+
} & {
|
414
|
+
[k in K3]?: R3 | ((ctx: C & {
|
415
|
+
[k in K1]: R1;
|
416
|
+
} & {
|
417
|
+
[k in K2]: R2;
|
418
|
+
}) => R3);
|
419
|
+
} & {
|
420
|
+
[k in K4]?: R4 | ((ctx: C & {
|
421
|
+
[k in K1]: R1;
|
422
|
+
} & {
|
423
|
+
[k in K2]: R2;
|
424
|
+
} & {
|
425
|
+
[k in K3]: R3;
|
426
|
+
}) => R4);
|
427
|
+
} & {
|
428
|
+
[k in K5]?: R5 | ((ctx: C & {
|
429
|
+
[k in K1]: R1;
|
430
|
+
} & {
|
431
|
+
[k in K2]: R2;
|
432
|
+
} & {
|
433
|
+
[k in K3]: R3;
|
434
|
+
} & {
|
435
|
+
[k in K4]: R4;
|
436
|
+
}) => R5);
|
437
|
+
} & {
|
438
|
+
[k in K6]?: R6 | ((ctx: C & {
|
439
|
+
[k in K1]: R1;
|
440
|
+
} & {
|
441
|
+
[k in K2]: R2;
|
442
|
+
} & {
|
443
|
+
[k in K3]: R3;
|
444
|
+
} & {
|
445
|
+
[k in K4]: R4;
|
446
|
+
} & {
|
447
|
+
[k in K5]: R5;
|
448
|
+
}) => R6);
|
449
|
+
} & {
|
450
|
+
[k in K7]?: R7 | ((ctx: C & {
|
451
|
+
[k in K1]: R1;
|
452
|
+
} & {
|
453
|
+
[k in K2]: R2;
|
454
|
+
} & {
|
455
|
+
[k in K3]: R3;
|
456
|
+
} & {
|
457
|
+
[k in K4]: R4;
|
458
|
+
} & {
|
459
|
+
[k in K5]: R5;
|
460
|
+
} & {
|
461
|
+
[k in K6]: R6;
|
462
|
+
}) => R7);
|
463
|
+
} & {
|
464
|
+
[k in K8]?: R8 | ((ctx: C & {
|
465
|
+
[k in K1]: R1;
|
466
|
+
} & {
|
467
|
+
[k in K2]: R2;
|
468
|
+
} & {
|
469
|
+
[k in K3]: R3;
|
470
|
+
} & {
|
471
|
+
[k in K4]: R4;
|
472
|
+
} & {
|
473
|
+
[k in K5]: R5;
|
474
|
+
} & {
|
475
|
+
[k in K6]: R6;
|
476
|
+
} & {
|
477
|
+
[k in K7]: R7;
|
478
|
+
}) => R8);
|
479
|
+
}, only?: (K1 | K2 | K3 | K4 | K5 | K6 | K7 | K8)[]) => Promise<C & {
|
480
|
+
[k in K1]: R1;
|
481
|
+
} & {
|
482
|
+
[k in K2]: R2;
|
483
|
+
} & {
|
484
|
+
[k in K3]: R3;
|
485
|
+
} & {
|
486
|
+
[k in K4]: R4;
|
487
|
+
} & {
|
488
|
+
[k in K5]: R5;
|
489
|
+
} & {
|
490
|
+
[k in K6]: R6;
|
491
|
+
} & {
|
492
|
+
[k in K7]: R7;
|
493
|
+
} & {
|
494
|
+
[k in K8]: R8;
|
495
|
+
}>;
|
496
|
+
export declare function klubok<K1 extends string, K2 extends string, K3 extends string, K4 extends string, K5 extends string, K6 extends string, K7 extends string, K8 extends string, K9 extends string, C extends object, R1, R2, R3, R4, R5, R6, R7, R8, R9>(fn1: KeyedFunction<K1, (ctx: C) => Promise<R1> | R1>, fn2: KeyedFunction<K2, (ctx: C & {
|
497
|
+
[k in K1]: R1;
|
498
|
+
}) => Promise<R2> | R2>, fn3: KeyedFunction<K3, (ctx: C & {
|
499
|
+
[k in K1]: R1;
|
500
|
+
} & {
|
501
|
+
[k in K2]: R2;
|
502
|
+
}) => Promise<R3> | R3>, fn4: KeyedFunction<K4, (ctx: C & {
|
503
|
+
[k in K1]: R1;
|
504
|
+
} & {
|
505
|
+
[k in K2]: R2;
|
506
|
+
} & {
|
507
|
+
[k in K3]: R3;
|
508
|
+
}) => Promise<R4> | R4>, fn5: KeyedFunction<K5, (ctx: C & {
|
509
|
+
[k in K1]: R1;
|
510
|
+
} & {
|
511
|
+
[k in K2]: R2;
|
512
|
+
} & {
|
513
|
+
[k in K3]: R3;
|
514
|
+
} & {
|
515
|
+
[k in K4]: R4;
|
516
|
+
}) => Promise<R5> | R5>, fn6: KeyedFunction<K6, (ctx: C & {
|
517
|
+
[k in K1]: R1;
|
518
|
+
} & {
|
519
|
+
[k in K2]: R2;
|
520
|
+
} & {
|
521
|
+
[k in K3]: R3;
|
522
|
+
} & {
|
523
|
+
[k in K4]: R4;
|
524
|
+
} & {
|
525
|
+
[k in K5]: R5;
|
526
|
+
}) => Promise<R6> | R6>, fn7: KeyedFunction<K7, (ctx: C & {
|
527
|
+
[k in K1]: R1;
|
528
|
+
} & {
|
529
|
+
[k in K2]: R2;
|
530
|
+
} & {
|
531
|
+
[k in K3]: R3;
|
532
|
+
} & {
|
533
|
+
[k in K4]: R4;
|
534
|
+
} & {
|
535
|
+
[k in K5]: R5;
|
536
|
+
} & {
|
537
|
+
[k in K6]: R6;
|
538
|
+
}) => Promise<R7> | R7>, fn8: KeyedFunction<K8, (ctx: C & {
|
539
|
+
[k in K1]: R1;
|
540
|
+
} & {
|
541
|
+
[k in K2]: R2;
|
542
|
+
} & {
|
543
|
+
[k in K3]: R3;
|
544
|
+
} & {
|
545
|
+
[k in K4]: R4;
|
546
|
+
} & {
|
547
|
+
[k in K5]: R5;
|
548
|
+
} & {
|
549
|
+
[k in K6]: R6;
|
550
|
+
} & {
|
551
|
+
[k in K7]: R7;
|
552
|
+
}) => Promise<R8> | R8>, fn9: KeyedFunction<K9, (ctx: C & {
|
553
|
+
[k in K1]: R1;
|
554
|
+
} & {
|
555
|
+
[k in K2]: R2;
|
556
|
+
} & {
|
557
|
+
[k in K3]: R3;
|
558
|
+
} & {
|
559
|
+
[k in K4]: R4;
|
560
|
+
} & {
|
561
|
+
[k in K5]: R5;
|
562
|
+
} & {
|
563
|
+
[k in K6]: R6;
|
564
|
+
} & {
|
565
|
+
[k in K7]: R7;
|
566
|
+
} & {
|
567
|
+
[k in K8]: R8;
|
568
|
+
}) => Promise<R9> | R9>): (ctx: C, mock?: {
|
569
|
+
[k in K1]?: R1 | ((ctx: C) => R1);
|
570
|
+
} & {
|
571
|
+
[k in K2]?: R2 | ((ctx: C & {
|
572
|
+
[k in K1]: R1;
|
573
|
+
}) => R2);
|
574
|
+
} & {
|
575
|
+
[k in K3]?: R3 | ((ctx: C & {
|
576
|
+
[k in K1]: R1;
|
577
|
+
} & {
|
578
|
+
[k in K2]: R2;
|
579
|
+
}) => R3);
|
580
|
+
} & {
|
581
|
+
[k in K4]?: R4 | ((ctx: C & {
|
582
|
+
[k in K1]: R1;
|
583
|
+
} & {
|
584
|
+
[k in K2]: R2;
|
585
|
+
} & {
|
586
|
+
[k in K3]: R3;
|
587
|
+
}) => R4);
|
588
|
+
} & {
|
589
|
+
[k in K5]?: R5 | ((ctx: C & {
|
590
|
+
[k in K1]: R1;
|
591
|
+
} & {
|
592
|
+
[k in K2]: R2;
|
593
|
+
} & {
|
594
|
+
[k in K3]: R3;
|
595
|
+
} & {
|
596
|
+
[k in K4]: R4;
|
597
|
+
}) => R5);
|
598
|
+
} & {
|
599
|
+
[k in K6]?: R6 | ((ctx: C & {
|
600
|
+
[k in K1]: R1;
|
601
|
+
} & {
|
602
|
+
[k in K2]: R2;
|
603
|
+
} & {
|
604
|
+
[k in K3]: R3;
|
605
|
+
} & {
|
606
|
+
[k in K4]: R4;
|
607
|
+
} & {
|
608
|
+
[k in K5]: R5;
|
609
|
+
}) => R6);
|
610
|
+
} & {
|
611
|
+
[k in K7]?: R7 | ((ctx: C & {
|
612
|
+
[k in K1]: R1;
|
613
|
+
} & {
|
614
|
+
[k in K2]: R2;
|
615
|
+
} & {
|
616
|
+
[k in K3]: R3;
|
617
|
+
} & {
|
618
|
+
[k in K4]: R4;
|
619
|
+
} & {
|
620
|
+
[k in K5]: R5;
|
621
|
+
} & {
|
622
|
+
[k in K6]: R6;
|
623
|
+
}) => R7);
|
624
|
+
} & {
|
625
|
+
[k in K8]?: R8 | ((ctx: C & {
|
626
|
+
[k in K1]: R1;
|
627
|
+
} & {
|
628
|
+
[k in K2]: R2;
|
629
|
+
} & {
|
630
|
+
[k in K3]: R3;
|
631
|
+
} & {
|
632
|
+
[k in K4]: R4;
|
633
|
+
} & {
|
634
|
+
[k in K5]: R5;
|
635
|
+
} & {
|
636
|
+
[k in K6]: R6;
|
637
|
+
} & {
|
638
|
+
[k in K7]: R7;
|
639
|
+
}) => R8);
|
640
|
+
} & {
|
641
|
+
[k in K9]?: R9 | ((ctx: C & {
|
642
|
+
[k in K1]: R1;
|
643
|
+
} & {
|
644
|
+
[k in K2]: R2;
|
645
|
+
} & {
|
646
|
+
[k in K3]: R3;
|
647
|
+
} & {
|
648
|
+
[k in K4]: R4;
|
649
|
+
} & {
|
650
|
+
[k in K5]: R5;
|
651
|
+
} & {
|
652
|
+
[k in K6]: R6;
|
653
|
+
} & {
|
654
|
+
[k in K7]: R7;
|
655
|
+
} & {
|
656
|
+
[k in K8]: R8;
|
657
|
+
}) => R9);
|
658
|
+
}, only?: (K1 | K2 | K3 | K4 | K5 | K6 | K7 | K8 | K9)[]) => Promise<C & {
|
659
|
+
[k in K1]: R1;
|
660
|
+
} & {
|
661
|
+
[k in K2]: R2;
|
662
|
+
} & {
|
663
|
+
[k in K3]: R3;
|
664
|
+
} & {
|
665
|
+
[k in K4]: R4;
|
666
|
+
} & {
|
667
|
+
[k in K5]: R5;
|
668
|
+
} & {
|
669
|
+
[k in K6]: R6;
|
670
|
+
} & {
|
671
|
+
[k in K7]: R7;
|
672
|
+
} & {
|
673
|
+
[k in K8]: R8;
|
674
|
+
} & {
|
675
|
+
[k in K9]: R9;
|
676
|
+
}>;
|
677
|
+
export declare function klubok<K1 extends string, K2 extends string, K3 extends string, K4 extends string, K5 extends string, K6 extends string, K7 extends string, K8 extends string, K9 extends string, K10 extends string, C extends object, R1, R2, R3, R4, R5, R6, R7, R8, R9, R10>(fn1: KeyedFunction<K1, (ctx: C) => Promise<R1> | R1>, fn2: KeyedFunction<K2, (ctx: C & {
|
678
|
+
[k in K1]: R1;
|
679
|
+
}) => Promise<R2> | R2>, fn3: KeyedFunction<K3, (ctx: C & {
|
680
|
+
[k in K1]: R1;
|
681
|
+
} & {
|
682
|
+
[k in K2]: R2;
|
683
|
+
}) => Promise<R3> | R3>, fn4: KeyedFunction<K4, (ctx: C & {
|
684
|
+
[k in K1]: R1;
|
685
|
+
} & {
|
686
|
+
[k in K2]: R2;
|
687
|
+
} & {
|
688
|
+
[k in K3]: R3;
|
689
|
+
}) => Promise<R4> | R4>, fn5: KeyedFunction<K5, (ctx: C & {
|
690
|
+
[k in K1]: R1;
|
691
|
+
} & {
|
692
|
+
[k in K2]: R2;
|
693
|
+
} & {
|
694
|
+
[k in K3]: R3;
|
695
|
+
} & {
|
696
|
+
[k in K4]: R4;
|
697
|
+
}) => Promise<R5> | R5>, fn6: KeyedFunction<K6, (ctx: C & {
|
698
|
+
[k in K1]: R1;
|
699
|
+
} & {
|
700
|
+
[k in K2]: R2;
|
701
|
+
} & {
|
702
|
+
[k in K3]: R3;
|
703
|
+
} & {
|
704
|
+
[k in K4]: R4;
|
705
|
+
} & {
|
706
|
+
[k in K5]: R5;
|
707
|
+
}) => Promise<R6> | R6>, fn7: KeyedFunction<K7, (ctx: C & {
|
708
|
+
[k in K1]: R1;
|
709
|
+
} & {
|
710
|
+
[k in K2]: R2;
|
711
|
+
} & {
|
712
|
+
[k in K3]: R3;
|
713
|
+
} & {
|
714
|
+
[k in K4]: R4;
|
715
|
+
} & {
|
716
|
+
[k in K5]: R5;
|
717
|
+
} & {
|
718
|
+
[k in K6]: R6;
|
719
|
+
}) => Promise<R7> | R7>, fn8: KeyedFunction<K8, (ctx: C & {
|
720
|
+
[k in K1]: R1;
|
721
|
+
} & {
|
722
|
+
[k in K2]: R2;
|
723
|
+
} & {
|
724
|
+
[k in K3]: R3;
|
725
|
+
} & {
|
726
|
+
[k in K4]: R4;
|
727
|
+
} & {
|
728
|
+
[k in K5]: R5;
|
729
|
+
} & {
|
730
|
+
[k in K6]: R6;
|
731
|
+
} & {
|
732
|
+
[k in K7]: R7;
|
733
|
+
}) => Promise<R8> | R8>, fn9: KeyedFunction<K9, (ctx: C & {
|
734
|
+
[k in K1]: R1;
|
735
|
+
} & {
|
736
|
+
[k in K2]: R2;
|
737
|
+
} & {
|
738
|
+
[k in K3]: R3;
|
739
|
+
} & {
|
740
|
+
[k in K4]: R4;
|
741
|
+
} & {
|
742
|
+
[k in K5]: R5;
|
743
|
+
} & {
|
744
|
+
[k in K6]: R6;
|
745
|
+
} & {
|
746
|
+
[k in K7]: R7;
|
747
|
+
} & {
|
748
|
+
[k in K8]: R8;
|
749
|
+
}) => Promise<R9> | R9>, fn10: KeyedFunction<K10, (ctx: C & {
|
750
|
+
[k in K1]: R1;
|
751
|
+
} & {
|
752
|
+
[k in K2]: R2;
|
753
|
+
} & {
|
754
|
+
[k in K3]: R3;
|
755
|
+
} & {
|
756
|
+
[k in K4]: R4;
|
757
|
+
} & {
|
758
|
+
[k in K5]: R5;
|
759
|
+
} & {
|
760
|
+
[k in K6]: R6;
|
761
|
+
} & {
|
762
|
+
[k in K7]: R7;
|
763
|
+
} & {
|
764
|
+
[k in K8]: R8;
|
765
|
+
} & {
|
766
|
+
[k in K9]: R9;
|
767
|
+
}) => Promise<R10> | R10>): (ctx: C, mock?: {
|
768
|
+
[k in K1]?: R1 | ((ctx: C) => R1);
|
769
|
+
} & {
|
770
|
+
[k in K2]?: R2 | ((ctx: C & {
|
771
|
+
[k in K1]: R1;
|
772
|
+
}) => R2);
|
773
|
+
} & {
|
774
|
+
[k in K3]?: R3 | ((ctx: C & {
|
775
|
+
[k in K1]: R1;
|
776
|
+
} & {
|
777
|
+
[k in K2]: R2;
|
778
|
+
}) => R3);
|
779
|
+
} & {
|
780
|
+
[k in K4]?: R4 | ((ctx: C & {
|
781
|
+
[k in K1]: R1;
|
782
|
+
} & {
|
783
|
+
[k in K2]: R2;
|
784
|
+
} & {
|
785
|
+
[k in K3]: R3;
|
786
|
+
}) => R4);
|
787
|
+
} & {
|
788
|
+
[k in K5]?: R5 | ((ctx: C & {
|
789
|
+
[k in K1]: R1;
|
790
|
+
} & {
|
791
|
+
[k in K2]: R2;
|
792
|
+
} & {
|
793
|
+
[k in K3]: R3;
|
794
|
+
} & {
|
795
|
+
[k in K4]: R4;
|
796
|
+
}) => R5);
|
797
|
+
} & {
|
798
|
+
[k in K6]?: R6 | ((ctx: C & {
|
799
|
+
[k in K1]: R1;
|
800
|
+
} & {
|
801
|
+
[k in K2]: R2;
|
802
|
+
} & {
|
803
|
+
[k in K3]: R3;
|
804
|
+
} & {
|
805
|
+
[k in K4]: R4;
|
806
|
+
} & {
|
807
|
+
[k in K5]: R5;
|
808
|
+
}) => R6);
|
809
|
+
} & {
|
810
|
+
[k in K7]?: R7 | ((ctx: C & {
|
811
|
+
[k in K1]: R1;
|
812
|
+
} & {
|
813
|
+
[k in K2]: R2;
|
814
|
+
} & {
|
815
|
+
[k in K3]: R3;
|
816
|
+
} & {
|
817
|
+
[k in K4]: R4;
|
818
|
+
} & {
|
819
|
+
[k in K5]: R5;
|
820
|
+
} & {
|
821
|
+
[k in K6]: R6;
|
822
|
+
}) => R7);
|
823
|
+
} & {
|
824
|
+
[k in K8]?: R8 | ((ctx: C & {
|
825
|
+
[k in K1]: R1;
|
826
|
+
} & {
|
827
|
+
[k in K2]: R2;
|
828
|
+
} & {
|
829
|
+
[k in K3]: R3;
|
830
|
+
} & {
|
831
|
+
[k in K4]: R4;
|
832
|
+
} & {
|
833
|
+
[k in K5]: R5;
|
834
|
+
} & {
|
835
|
+
[k in K6]: R6;
|
836
|
+
} & {
|
837
|
+
[k in K7]: R7;
|
838
|
+
}) => R8);
|
839
|
+
} & {
|
840
|
+
[k in K9]?: R9 | ((ctx: C & {
|
841
|
+
[k in K1]: R1;
|
842
|
+
} & {
|
843
|
+
[k in K2]: R2;
|
844
|
+
} & {
|
845
|
+
[k in K3]: R3;
|
846
|
+
} & {
|
847
|
+
[k in K4]: R4;
|
848
|
+
} & {
|
849
|
+
[k in K5]: R5;
|
850
|
+
} & {
|
851
|
+
[k in K6]: R6;
|
852
|
+
} & {
|
853
|
+
[k in K7]: R7;
|
854
|
+
} & {
|
855
|
+
[k in K8]: R8;
|
856
|
+
}) => R9);
|
857
|
+
} & {
|
858
|
+
[k in K10]?: R10 | ((ctx: C & {
|
859
|
+
[k in K1]: R1;
|
860
|
+
} & {
|
861
|
+
[k in K2]: R2;
|
862
|
+
} & {
|
863
|
+
[k in K3]: R3;
|
864
|
+
} & {
|
865
|
+
[k in K4]: R4;
|
866
|
+
} & {
|
867
|
+
[k in K5]: R5;
|
868
|
+
} & {
|
869
|
+
[k in K6]: R6;
|
870
|
+
} & {
|
871
|
+
[k in K7]: R7;
|
872
|
+
} & {
|
873
|
+
[k in K8]: R8;
|
874
|
+
} & {
|
875
|
+
[k in K9]: R9;
|
876
|
+
}) => R10);
|
877
|
+
}, only?: (K1 | K2 | K3 | K4 | K5 | K6 | K7 | K8 | K9 | K10)[]) => Promise<C & {
|
878
|
+
[k in K1]: R1;
|
879
|
+
} & {
|
880
|
+
[k in K2]: R2;
|
881
|
+
} & {
|
882
|
+
[k in K3]: R3;
|
883
|
+
} & {
|
884
|
+
[k in K4]: R4;
|
885
|
+
} & {
|
886
|
+
[k in K5]: R5;
|
887
|
+
} & {
|
888
|
+
[k in K6]: R6;
|
889
|
+
} & {
|
890
|
+
[k in K7]: R7;
|
891
|
+
} & {
|
892
|
+
[k in K8]: R8;
|
893
|
+
} & {
|
894
|
+
[k in K9]: R9;
|
895
|
+
} & {
|
896
|
+
[k in K10]: R10;
|
897
|
+
}>;
|
898
|
+
export {};
|
package/dist/index.js
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.mut = exports.eff = exports.pure = void 0;
|
4
|
+
exports.klubok = klubok;
|
5
|
+
const pure = (key, fn) => Object.assign(fn, { key, mutable: false });
|
6
|
+
exports.pure = pure;
|
7
|
+
const eff = (key, fn) => Object.assign(fn, { key, mutable: false });
|
8
|
+
exports.eff = eff;
|
9
|
+
const mut = (fn) => Object.assign(fn, { mutable: true });
|
10
|
+
exports.mut = mut;
|
11
|
+
function klubok(...fns) {
|
12
|
+
return (rootCtx = {}, mock, only) => fns.reduce(mock == null && only == null
|
13
|
+
? (acc, fn) => acc.then(ctx => !fn.mutable && Reflect.has(ctx, fn.key)
|
14
|
+
? Promise.reject(new Error(`Try to override existing alias "${fn.key}". Let's rename alias or use "mut" wrapper`))
|
15
|
+
: Promise.resolve(fn(ctx)).then(resp => ({ ...ctx, [fn.key]: resp })))
|
16
|
+
: (acc, fn) => acc.then(ctx => !fn.mutable && Reflect.has(ctx, fn.key) && !Reflect.has(mock ?? {}, fn.key)
|
17
|
+
? Promise.reject(new Error(`Try to override existing alias "${fn.key}". Let's rename alias or use "mut" wrapper`))
|
18
|
+
: (mock && Reflect.has(mock, fn.key) && typeof Reflect.get(mock, fn.key) !== 'function') ||
|
19
|
+
(only && only.length && !only.includes(fn.key))
|
20
|
+
? ctx
|
21
|
+
: Promise.resolve(mock && Reflect.has(mock, fn.key) && typeof Reflect.get(mock, fn.key) === 'function'
|
22
|
+
? Reflect.get(mock, fn.key)(ctx)
|
23
|
+
: fn(ctx)).then(resp => ({ ...ctx, [fn.key]: resp }))), Promise.resolve({ ...rootCtx, ...mock }));
|
24
|
+
}
|
package/package.json
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
{
|
2
|
+
"name": "klubok",
|
3
|
+
"version": "0.1.0",
|
4
|
+
"description": "Do notation pipes for Promise-based or pure functions which easy to mock",
|
5
|
+
"main": "dist/index.js",
|
6
|
+
"types": "dist/index.d.ts",
|
7
|
+
"repository": {
|
8
|
+
"type": "git",
|
9
|
+
"url": "git@github.com:darky/klubok.git"
|
10
|
+
},
|
11
|
+
"files": [
|
12
|
+
"dist/index.js",
|
13
|
+
"dist/index.d.ts"
|
14
|
+
],
|
15
|
+
"scripts": {
|
16
|
+
"build": "rm -rf dist && tsc -p tsconfig.build.json",
|
17
|
+
"test": "node --experimental-strip-types --test ./test.ts",
|
18
|
+
"test:types": "cp index.test-d.ts ./dist/ && npx tsd",
|
19
|
+
"prepublishOnly": "npm run build"
|
20
|
+
},
|
21
|
+
"keywords": [
|
22
|
+
"functional",
|
23
|
+
"programming",
|
24
|
+
"fp",
|
25
|
+
"pipe",
|
26
|
+
"do",
|
27
|
+
"notation",
|
28
|
+
"mock",
|
29
|
+
"unit",
|
30
|
+
"test",
|
31
|
+
"promise"
|
32
|
+
],
|
33
|
+
"author": "Vladislav Botvin",
|
34
|
+
"license": "MIT",
|
35
|
+
"devDependencies": {
|
36
|
+
"@types/node": "^22.8.6",
|
37
|
+
"tsd": "^0.31.2",
|
38
|
+
"typescript": "^5.6.3"
|
39
|
+
}
|
40
|
+
}
|