klubok 0.4.7 → 0.5.1
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.d.ts +1 -1
- package/dist/index.js +5 -5
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
@@ -7,7 +7,7 @@ type KeyedFunction<K extends string, F extends Function> = F & {
|
|
7
7
|
export declare const pure: <K extends string, C, R>(key: K, fn: (ctx: C) => R) => KeyedFunction<K, (ctx: C) => R>;
|
8
8
|
export declare const eff: <K extends string, C, R>(key: K, fn: (ctx: C) => Promise<R>) => KeyedFunction<K, (ctx: C) => Promise<R>>;
|
9
9
|
export declare const mut: <K extends string, C, R>(fn: KeyedFunction<K, (ctx: C) => R>) => KeyedFunction<K, (ctx: C) => R>;
|
10
|
-
export declare const
|
10
|
+
export declare const exitIfNullable: <K extends string, C, R>(fn: KeyedFunction<K, (ctx: C) => Promise<R> | R>) => KeyedFunction<K, (ctx: C) => NonNullable<R>>;
|
11
11
|
export declare const onError: <K extends string, C, R>(key: K, fn: (ctx: C) => R) => KeyedFunction<K, (ctx: C) => R>;
|
12
12
|
export declare function klubok<K1 extends string, C extends object, R1>(fn1: KeyedFunction<K1, (ctx: C) => Promise<R1> | R1>): (ctx: C, mock?: {
|
13
13
|
[k in K1]?: R1 | ((ctx: C) => R1 | Promise<R1>);
|
package/dist/index.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.onError = exports.
|
3
|
+
exports.onError = exports.exitIfNullable = exports.mut = exports.eff = exports.pure = void 0;
|
4
4
|
exports.klubok = klubok;
|
5
5
|
const node_util_1 = require("node:util");
|
6
6
|
const pure = (key, fn) => Object.assign(fn, { exitable: false, key, mutable: false, onError: false });
|
@@ -9,8 +9,8 @@ const eff = (key, fn) => Object.assign(fn, { exitable: false, key, mutable: fals
|
|
9
9
|
exports.eff = eff;
|
10
10
|
const mut = (fn) => Object.assign(fn, { mutable: true });
|
11
11
|
exports.mut = mut;
|
12
|
-
const
|
13
|
-
exports.
|
12
|
+
const exitIfNullable = (fn) => Object.assign(fn, { exitable: true });
|
13
|
+
exports.exitIfNullable = exitIfNullable;
|
14
14
|
const onError = (key, fn) => Object.assign(fn, { exitable: false, key, mutable: false, onError: true });
|
15
15
|
exports.onError = onError;
|
16
16
|
function klubok(...fns) {
|
@@ -31,7 +31,7 @@ function klubok(...fns) {
|
|
31
31
|
}
|
32
32
|
try {
|
33
33
|
const resp = await fn(ctx);
|
34
|
-
if (fn.exitable && resp) {
|
34
|
+
if (fn.exitable && resp == null) {
|
35
35
|
isExit = true;
|
36
36
|
}
|
37
37
|
if (resp === ctx) {
|
@@ -65,7 +65,7 @@ function klubok(...fns) {
|
|
65
65
|
}
|
66
66
|
return await Promise.resolve(mock && Reflect.has(mock, fn.key) && typeof Reflect.get(mock, fn.key) === 'function'
|
67
67
|
? Reflect.get(mock, fn.key)(ctx)
|
68
|
-
: fn(ctx)).then(resp => (fn.exitable && resp && (isExit = true), { ...ctx, [fn.key]: resp }));
|
68
|
+
: fn(ctx)).then(resp => (fn.exitable && resp == null && (isExit = true), { ...ctx, [fn.key]: resp }));
|
69
69
|
}
|
70
70
|
catch (error) {
|
71
71
|
await onError?.({ ...ctx, $error: error });
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "klubok",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.5.1",
|
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",
|
@@ -34,8 +34,8 @@
|
|
34
34
|
"author": "Vladislav Botvin",
|
35
35
|
"license": "MIT",
|
36
36
|
"devDependencies": {
|
37
|
-
"@types/node": "^
|
38
|
-
"klubok": "0.
|
37
|
+
"@types/node": "^24.1.0",
|
38
|
+
"klubok": "0.5.0",
|
39
39
|
"tinybench": "^4.0.1",
|
40
40
|
"tsd": "^0.32.0",
|
41
41
|
"typescript": "^5.8.3"
|