klubok 0.4.4 → 0.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +11 -2
- package/package.json +2 -2
package/dist/index.js
CHANGED
@@ -16,11 +16,13 @@ exports.onError = onError;
|
|
16
16
|
function klubok(...fns) {
|
17
17
|
const funcs = fns.filter(f => !f.onError);
|
18
18
|
const onError = fns.find(f => f.onError);
|
19
|
+
const funcsLength = funcs.length;
|
19
20
|
return async (rootCtx = {}, mock, only) => {
|
20
21
|
let isExit = false;
|
21
22
|
if (mock == null && only == null) {
|
22
23
|
let ctx = rootCtx;
|
23
|
-
for (
|
24
|
+
for (let i = 0; i < funcsLength; i++) {
|
25
|
+
const fn = funcs[i];
|
24
26
|
if (!fn.mutable && ctx[fn.key]) {
|
25
27
|
throw new Error(`Try to override existing alias "${fn.key}". Let's rename alias or use "mut" wrapper`);
|
26
28
|
}
|
@@ -32,7 +34,8 @@ function klubok(...fns) {
|
|
32
34
|
if (fn.exitable && resp) {
|
33
35
|
isExit = true;
|
34
36
|
}
|
35
|
-
|
37
|
+
;
|
38
|
+
ctx[fn.key] = resp;
|
36
39
|
}
|
37
40
|
catch (error) {
|
38
41
|
await onError?.({ ...ctx, $error: error });
|
@@ -42,6 +45,12 @@ function klubok(...fns) {
|
|
42
45
|
throw error;
|
43
46
|
}
|
44
47
|
}
|
48
|
+
for (const key of Object.keys(ctx)) {
|
49
|
+
if (ctx[key] === ctx) {
|
50
|
+
;
|
51
|
+
ctx[key] = '<root>';
|
52
|
+
}
|
53
|
+
}
|
45
54
|
return ctx;
|
46
55
|
}
|
47
56
|
return funcs.reduce((acc, fn) => acc.then(ctx => !fn.mutable && Reflect.has(ctx, fn.key) && !Reflect.has(mock ?? {}, fn.key)
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "klubok",
|
3
|
-
"version": "0.4.
|
3
|
+
"version": "0.4.6",
|
4
4
|
"description": "Do notation pipes for Promise-based or pure functions which easy to mock",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"types": "dist/index.d.ts",
|
@@ -35,7 +35,7 @@
|
|
35
35
|
"license": "MIT",
|
36
36
|
"devDependencies": {
|
37
37
|
"@types/node": "^22.15.3",
|
38
|
-
"klubok": "0.4.
|
38
|
+
"klubok": "0.4.4",
|
39
39
|
"tinybench": "^4.0.1",
|
40
40
|
"tsd": "^0.32.0",
|
41
41
|
"typescript": "^5.8.3"
|