@rotomeca/rop 1.0.0 → 1.0.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/cjs/src/decorators/ErrorPath.internal/functions.js +2 -3
- package/dist/cjs/src/decorators/ErrorPath.js +1 -2
- package/dist/cjs/src/decorators/HappyPath.internal/functions.js +2 -3
- package/dist/cjs/src/decorators/HappyPath.js +1 -2
- package/dist/cjs/src/decorators/Risky.internal/functions.js +2 -3
- package/dist/cjs/src/decorators/Risky.js +12 -16
- package/dist/cjs/src/functions/applyMatch.js +1 -2
- package/dist/cjs/src/interfaces/ITResult.js +1 -1
- package/dist/esm/src/decorators/Risky.d.ts +2 -1
- package/dist/esm/src/decorators/Risky.js +11 -14
- package/package.json +2 -2
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.errorPathSync = errorPathSync;
|
|
4
|
+
exports.errorPathAsync = errorPathAsync;
|
|
4
5
|
//type: functions
|
|
5
6
|
//description: Functions to handle error path operations by executing a callback on errored results.
|
|
6
7
|
const ATresult_1 = require("../../classes/abstracts/ATresult");
|
|
@@ -19,7 +20,6 @@ function errorPathSync(original, path, ...args) {
|
|
|
19
20
|
? (0, applyMatch_1.applyMatch)(result, undefined, path)
|
|
20
21
|
: result;
|
|
21
22
|
}
|
|
22
|
-
exports.errorPathSync = errorPathSync;
|
|
23
23
|
/**
|
|
24
24
|
* Handles the error path for asynchronous functions by executing a callback on errored results.
|
|
25
25
|
* @param this The context in which the original function is called.
|
|
@@ -34,4 +34,3 @@ async function errorPathAsync(original, path, ...args) {
|
|
|
34
34
|
? (0, applyMatch_1.applyMatch)(result, undefined, path)
|
|
35
35
|
: result;
|
|
36
36
|
}
|
|
37
|
-
exports.errorPathAsync = errorPathAsync;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
//type: decorator
|
|
3
3
|
//description: Decorator to handle error path operations by executing a callback on errored results.
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.ErrorPath =
|
|
5
|
+
exports.ErrorPath = ErrorPath;
|
|
6
6
|
const functions_1 = require("./ErrorPath.internal/functions");
|
|
7
7
|
/**
|
|
8
8
|
* Decorator to handle error path operations by executing a callback on errored results.
|
|
@@ -26,4 +26,3 @@ function ErrorPath(fn) {
|
|
|
26
26
|
return descriptor;
|
|
27
27
|
};
|
|
28
28
|
}
|
|
29
|
-
exports.ErrorPath = ErrorPath;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.happyPathSync = happyPathSync;
|
|
4
|
+
exports.happyPathASync = happyPathASync;
|
|
4
5
|
//type: functions
|
|
5
6
|
//description: Functions to handle happy path operations by executing a callback on successful results.
|
|
6
7
|
const ATresult_1 = require("../../classes/abstracts/ATresult");
|
|
@@ -19,7 +20,6 @@ function happyPathSync(original, path, ...args) {
|
|
|
19
20
|
? (0, applyMatch_1.applyMatch)(result, path, undefined)
|
|
20
21
|
: result;
|
|
21
22
|
}
|
|
22
|
-
exports.happyPathSync = happyPathSync;
|
|
23
23
|
/**
|
|
24
24
|
* Handles the happy path for asynchronous functions by executing a callback on successful results.
|
|
25
25
|
* @param this The context in which the original function is called.
|
|
@@ -34,4 +34,3 @@ async function happyPathASync(original, path, ...args) {
|
|
|
34
34
|
? (0, applyMatch_1.applyMatch)(result, path, undefined)
|
|
35
35
|
: result;
|
|
36
36
|
}
|
|
37
|
-
exports.happyPathASync = happyPathASync;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
//type: decorator
|
|
3
3
|
//description: Decorator to handle happy path operations by executing a callback on successful results.
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.HappyPath =
|
|
5
|
+
exports.HappyPath = HappyPath;
|
|
6
6
|
const functions_1 = require("./HappyPath.internal/functions");
|
|
7
7
|
/**
|
|
8
8
|
* Decorator to handle happy path operations by executing a callback on successful results.
|
|
@@ -26,4 +26,3 @@ function HappyPath(fn) {
|
|
|
26
26
|
return descriptor;
|
|
27
27
|
};
|
|
28
28
|
}
|
|
29
|
-
exports.HappyPath = HappyPath;
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
// type: functions
|
|
3
3
|
// description: Functions to handle risky operations by converting exceptions into Result types.
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.
|
|
5
|
+
exports.riskySync = riskySync;
|
|
6
|
+
exports.riskyAsync = riskyAsync;
|
|
6
7
|
const ATresult_1 = require("../../classes/abstracts/ATresult");
|
|
7
8
|
const Fail_1 = require("../../classes/Fail");
|
|
8
9
|
const Success_1 = require("../../classes/Success");
|
|
@@ -22,7 +23,6 @@ function riskySync(original, ...args) {
|
|
|
22
23
|
return error instanceof ATresult_1.ATresult ? error : Fail_1.Fail.Create(error);
|
|
23
24
|
}
|
|
24
25
|
}
|
|
25
|
-
exports.riskySync = riskySync;
|
|
26
26
|
/**
|
|
27
27
|
* Handles asynchronous risky operations by converting exceptions into Result types.
|
|
28
28
|
* @param this The context in which the original function is called.
|
|
@@ -39,4 +39,3 @@ async function riskyAsync(original, ...args) {
|
|
|
39
39
|
return error instanceof ATresult_1.ATresult ? error : Fail_1.Fail.Create(error);
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
|
-
exports.riskyAsync = riskyAsync;
|
|
@@ -1,28 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Risky =
|
|
4
|
-
// type: decorator
|
|
5
|
-
// description: Decorator to handle risky operations by converting exceptions into Result types.
|
|
3
|
+
exports.Risky = Risky;
|
|
6
4
|
const functions_1 = require("./Risky.internal/functions");
|
|
7
5
|
/**
|
|
8
6
|
* Decorator to handle risky operations by converting exceptions into Result types.
|
|
9
7
|
* @returns A method decorator that wraps the original method with error handling.
|
|
10
8
|
*/
|
|
11
9
|
function Risky() {
|
|
12
|
-
return function (
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
if (isAsync) {
|
|
16
|
-
descriptor.value = async function (...args) {
|
|
17
|
-
return functions_1.riskyAsync.call(this, original, ...args);
|
|
18
|
-
};
|
|
10
|
+
return function (originalMethod, context) {
|
|
11
|
+
if (context.kind !== "method") {
|
|
12
|
+
throw new Error("Risky can only be applied to methods.");
|
|
19
13
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
14
|
+
const isAsync = originalMethod.constructor.name === "AsyncFunction";
|
|
15
|
+
if (isAsync)
|
|
16
|
+
return async function (...args) {
|
|
17
|
+
return await functions_1.riskyAsync.call(this, originalMethod, ...args);
|
|
18
|
+
};
|
|
19
|
+
else
|
|
20
|
+
return function (...args) {
|
|
21
|
+
return functions_1.riskySync.call(this, originalMethod, ...args);
|
|
23
22
|
};
|
|
24
|
-
}
|
|
25
|
-
return descriptor;
|
|
26
23
|
};
|
|
27
24
|
}
|
|
28
|
-
exports.Risky = Risky;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
//type: function
|
|
3
3
|
//description: Function to apply match on a result with optional callbacks.
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.applyMatch =
|
|
5
|
+
exports.applyMatch = applyMatch;
|
|
6
6
|
/**
|
|
7
7
|
* Applies match on the given result with optional success and error callbacks.
|
|
8
8
|
* @param result Result to apply match on.
|
|
@@ -24,4 +24,3 @@ function applyMatch(result, onSuccess, onError) {
|
|
|
24
24
|
}
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
|
-
exports.applyMatch = applyMatch;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { ATresult } from "../classes/abstracts/ATresult";
|
|
1
2
|
/**
|
|
2
3
|
* Decorator to handle risky operations by converting exceptions into Result types.
|
|
3
4
|
* @returns A method decorator that wraps the original method with error handling.
|
|
4
5
|
*/
|
|
5
|
-
export declare function Risky(): (
|
|
6
|
+
export declare function Risky(): (originalMethod: Function, context: ClassMethodDecoratorContext) => ((this: any, ...args: any[]) => Promise<ATresult<any>>) | ((this: any, ...args: any[]) => ATresult<any>);
|
|
@@ -1,24 +1,21 @@
|
|
|
1
|
-
// type: decorator
|
|
2
|
-
// description: Decorator to handle risky operations by converting exceptions into Result types.
|
|
3
1
|
import { riskyAsync, riskySync } from "./Risky.internal/functions";
|
|
4
2
|
/**
|
|
5
3
|
* Decorator to handle risky operations by converting exceptions into Result types.
|
|
6
4
|
* @returns A method decorator that wraps the original method with error handling.
|
|
7
5
|
*/
|
|
8
6
|
export function Risky() {
|
|
9
|
-
return function (
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (isAsync) {
|
|
13
|
-
descriptor.value = async function (...args) {
|
|
14
|
-
return riskyAsync.call(this, original, ...args);
|
|
15
|
-
};
|
|
7
|
+
return function (originalMethod, context) {
|
|
8
|
+
if (context.kind !== "method") {
|
|
9
|
+
throw new Error("Risky can only be applied to methods.");
|
|
16
10
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
11
|
+
const isAsync = originalMethod.constructor.name === "AsyncFunction";
|
|
12
|
+
if (isAsync)
|
|
13
|
+
return async function (...args) {
|
|
14
|
+
return await riskyAsync.call(this, originalMethod, ...args);
|
|
15
|
+
};
|
|
16
|
+
else
|
|
17
|
+
return function (...args) {
|
|
18
|
+
return riskySync.call(this, originalMethod, ...args);
|
|
20
19
|
};
|
|
21
|
-
}
|
|
22
|
-
return descriptor;
|
|
23
20
|
};
|
|
24
21
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rotomeca/rop",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -30,6 +30,6 @@
|
|
|
30
30
|
"eslint": "^8.57.1",
|
|
31
31
|
"prettier": "^3.8.1",
|
|
32
32
|
"prettier-eslint": "^16.4.2",
|
|
33
|
-
"typescript": "^
|
|
33
|
+
"typescript": "^5.6.3"
|
|
34
34
|
}
|
|
35
35
|
}
|