@rotomeca/rop 0.0.2 → 1.0.0

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 (46) hide show
  1. package/README.md +9 -0
  2. package/dist/cjs/index.js +29 -0
  3. package/dist/cjs/package.json +1 -0
  4. package/dist/cjs/src/classes/Fail.js +91 -0
  5. package/dist/cjs/src/classes/Success.js +90 -0
  6. package/dist/cjs/src/classes/abstracts/ATresult.js +28 -0
  7. package/dist/cjs/src/decorators/ErrorPath.internal/functions.js +37 -0
  8. package/dist/cjs/src/decorators/ErrorPath.js +29 -0
  9. package/dist/cjs/src/decorators/HappyPath.internal/functions.js +37 -0
  10. package/dist/cjs/src/decorators/HappyPath.js +29 -0
  11. package/dist/cjs/src/decorators/Risky.internal/functions.js +42 -0
  12. package/dist/cjs/src/decorators/Risky.js +28 -0
  13. package/{src/functions/applyMatch.ts → dist/cjs/src/functions/applyMatch.js} +10 -12
  14. package/dist/cjs/src/interfaces/ITResult.js +19 -0
  15. package/dist/cjs/src/types/ResultMatch.js +4 -0
  16. package/dist/cjs/src/types/resultsCallbacks.js +4 -0
  17. package/dist/esm/index.d.ts +8 -0
  18. package/{index.ts → dist/esm/index.js} +2 -5
  19. package/{src/classes/Fail.ts → dist/esm/src/classes/Fail.d.ts} +14 -37
  20. package/dist/esm/src/classes/Fail.js +87 -0
  21. package/{src/classes/Success.ts → dist/esm/src/classes/Success.d.ts} +14 -37
  22. package/dist/esm/src/classes/Success.js +86 -0
  23. package/{src/classes/abstracts/ATresult.ts → dist/esm/src/classes/abstracts/ATresult.d.ts} +11 -19
  24. package/dist/esm/src/classes/abstracts/ATresult.js +24 -0
  25. package/dist/esm/src/decorators/ErrorPath.d.ts +7 -0
  26. package/dist/esm/src/decorators/ErrorPath.internal/functions.d.ts +19 -0
  27. package/{src/decorators/ErrorPath.internal/functions.ts → dist/esm/src/decorators/ErrorPath.internal/functions.js} +9 -14
  28. package/{src/decorators/ErrorPath.ts → dist/esm/src/decorators/ErrorPath.js} +7 -10
  29. package/dist/esm/src/decorators/HappyPath.d.ts +7 -0
  30. package/dist/esm/src/decorators/HappyPath.internal/functions.d.ts +19 -0
  31. package/{src/decorators/HappyPath.internal/functions.ts → dist/esm/src/decorators/HappyPath.internal/functions.js} +9 -14
  32. package/{src/decorators/HappyPath.ts → dist/esm/src/decorators/HappyPath.js} +7 -10
  33. package/dist/esm/src/decorators/Risky.d.ts +5 -0
  34. package/dist/esm/src/decorators/Risky.internal/functions.d.ts +17 -0
  35. package/{src/decorators/Risky.internal/functions.ts → dist/esm/src/decorators/Risky.internal/functions.js} +9 -12
  36. package/{src/decorators/Risky.ts → dist/esm/src/decorators/Risky.js} +6 -9
  37. package/dist/esm/src/functions/applyMatch.d.ts +10 -0
  38. package/dist/esm/src/functions/applyMatch.js +23 -0
  39. package/{src/interfaces/ITResult.ts → dist/esm/src/interfaces/ITResult.d.ts} +12 -17
  40. package/dist/esm/src/interfaces/ITResult.js +16 -0
  41. package/{src/types/ResultMatch.ts → dist/esm/src/types/ResultMatch.d.ts} +2 -7
  42. package/dist/esm/src/types/ResultMatch.js +3 -0
  43. package/{src/types/resultsCallbacks.ts → dist/esm/src/types/resultsCallbacks.d.ts} +7 -11
  44. package/dist/esm/src/types/resultsCallbacks.js +3 -0
  45. package/package.json +22 -5
  46. package/.prettierc.json +0 -9
@@ -1,92 +1,69 @@
1
- // type: class
2
- // description: Class representing a error result.
3
-
4
1
  import { ResultState, ITResult } from "../interfaces/ITResult";
5
2
  import { ResultMatch } from "../types/ResultMatch";
6
3
  import { ChainedCallback, SuccessMapCallback, ErrorMapCallback } from "../types/resultsCallbacks";
7
4
  import { ATresult } from "./abstracts/ATresult";
8
-
9
5
  /**
10
6
  * Class representing a failed result.
11
7
  * @template TSuccess - The type of the success value.
12
8
  * @template TE - The type of the error value (default is Error).
13
9
  */
14
- export class Fail<TSuccess, TE = Error> extends ATresult<TSuccess, TE> {
10
+ export declare class Fail<TSuccess, TE = Error> extends ATresult<TSuccess, TE> {
11
+ readonly error: TE;
15
12
  /**
16
13
  * Creates an instance of Fail.
17
14
  * @param error The error value.
18
15
  */
19
- constructor(public readonly error: TE) { super(); }
20
-
16
+ constructor(error: TE);
21
17
  /**
22
18
  * Returns the state of the result.
23
19
  * @returns The state indicating failure.
24
20
  */
25
- state(): ResultState {
26
- return ResultState.Error;
27
- }
21
+ state(): ResultState;
28
22
  /**
29
23
  * Matches the result with the provided matcher functions.
30
24
  * @param matcher The matcher object containing functions for success and error cases.
31
25
  * @returns The result of the matched function.
32
26
  */
33
- match<Result>(matcher: ResultMatch<TSuccess, TE, Result>): Result {
34
- return matcher.Err(this.error);
35
- }
27
+ match<Result>(matcher: ResultMatch<TSuccess, TE, Result>): Result;
36
28
  /**
37
29
  * Chains the result with another operation that returns a new result.
38
30
  * @param fn The function to apply if the result is successful.
39
31
  * @returns The result of the chained operation.
40
32
  */
41
- andThen<NewSuccess>(_: ChainedCallback<TSuccess, NewSuccess, TE>): ITResult<NewSuccess, TE> {
42
- return new Fail<NewSuccess, TE>(this.error);
43
- }
33
+ andThen<NewSuccess>(_: ChainedCallback<TSuccess, NewSuccess, TE>): ITResult<NewSuccess, TE>;
44
34
  /**
45
35
  * Maps the success value to a new value.
46
36
  * @param fn The function to apply to the success value.
47
37
  * @returns A new Success instance containing the mapped value.
48
38
  */
49
- map<NewSuccess>(_: SuccessMapCallback<TSuccess, NewSuccess>): ITResult<NewSuccess, TE> {
50
- return new Fail<NewSuccess, TE>(this.error);
51
- }
39
+ map<NewSuccess>(_: SuccessMapCallback<TSuccess, NewSuccess>): ITResult<NewSuccess, TE>;
52
40
  /**
53
41
  * Maps the error value to a new error value.
54
42
  * @param _ The function to apply to the error value.
55
43
  * @returns A new Success instance containing the original success value.
56
44
  */
57
- mapError<NewError>(fn: ErrorMapCallback<TE, NewError>): ITResult<TSuccess, NewError> {
58
- return new Fail<TSuccess, NewError>(fn(this.error));
59
- }
60
-
45
+ mapError<NewError>(fn: ErrorMapCallback<TE, NewError>): ITResult<TSuccess, NewError>;
61
46
  /**
62
47
  * Returns the success value or throws an error if the result is an error.
63
48
  * @throws The error value if the result is an error.
64
49
  * @returns The success value.
65
50
  */
66
- throwIfError(): TSuccess {
67
- throw this.error;
68
- }
69
-
51
+ throwIfError(): TSuccess;
70
52
  /**
71
53
  * Retrieves the success value or returns the provided default value if the result is an error.
72
54
  * @param defaultValue The value to return if the result is an error.
73
55
  * @returns The success value if the result is a success, otherwise the default value.
74
56
  */
75
- unwrapOr(defaultValue: TSuccess): TSuccess {
76
- return defaultValue;
77
- }
78
-
57
+ unwrapOr(defaultValue: TSuccess): TSuccess;
79
58
  /**
80
59
  * Creates a new Fail instance.
81
60
  * @param error The error value.
82
61
  * @returns A new Fail instance containing the error.
83
- *
62
+ *
84
63
  * @template TSuccess - The type of the success value.
85
64
  * @template TE - The type of the error value (default is Error).
86
- *
65
+ *
87
66
  * @static
88
67
  */
89
- static Create<TSuccess, TE = Error>(error: TE): Fail<TSuccess, TE> {
90
- return new Fail(error);
91
- }
92
- }
68
+ static Create<TSuccess, TE = Error>(error: TE): Fail<TSuccess, TE>;
69
+ }
@@ -0,0 +1,87 @@
1
+ // type: class
2
+ // description: Class representing a error result.
3
+ import { ResultState } from "../interfaces/ITResult";
4
+ import { ATresult } from "./abstracts/ATresult";
5
+ /**
6
+ * Class representing a failed result.
7
+ * @template TSuccess - The type of the success value.
8
+ * @template TE - The type of the error value (default is Error).
9
+ */
10
+ export class Fail extends ATresult {
11
+ /**
12
+ * Creates an instance of Fail.
13
+ * @param error The error value.
14
+ */
15
+ constructor(error) {
16
+ super();
17
+ this.error = error;
18
+ }
19
+ /**
20
+ * Returns the state of the result.
21
+ * @returns The state indicating failure.
22
+ */
23
+ state() {
24
+ return ResultState.Error;
25
+ }
26
+ /**
27
+ * Matches the result with the provided matcher functions.
28
+ * @param matcher The matcher object containing functions for success and error cases.
29
+ * @returns The result of the matched function.
30
+ */
31
+ match(matcher) {
32
+ return matcher.Err(this.error);
33
+ }
34
+ /**
35
+ * Chains the result with another operation that returns a new result.
36
+ * @param fn The function to apply if the result is successful.
37
+ * @returns The result of the chained operation.
38
+ */
39
+ andThen(_) {
40
+ return new Fail(this.error);
41
+ }
42
+ /**
43
+ * Maps the success value to a new value.
44
+ * @param fn The function to apply to the success value.
45
+ * @returns A new Success instance containing the mapped value.
46
+ */
47
+ map(_) {
48
+ return new Fail(this.error);
49
+ }
50
+ /**
51
+ * Maps the error value to a new error value.
52
+ * @param _ The function to apply to the error value.
53
+ * @returns A new Success instance containing the original success value.
54
+ */
55
+ mapError(fn) {
56
+ return new Fail(fn(this.error));
57
+ }
58
+ /**
59
+ * Returns the success value or throws an error if the result is an error.
60
+ * @throws The error value if the result is an error.
61
+ * @returns The success value.
62
+ */
63
+ throwIfError() {
64
+ throw this.error;
65
+ }
66
+ /**
67
+ * Retrieves the success value or returns the provided default value if the result is an error.
68
+ * @param defaultValue The value to return if the result is an error.
69
+ * @returns The success value if the result is a success, otherwise the default value.
70
+ */
71
+ unwrapOr(defaultValue) {
72
+ return defaultValue;
73
+ }
74
+ /**
75
+ * Creates a new Fail instance.
76
+ * @param error The error value.
77
+ * @returns A new Fail instance containing the error.
78
+ *
79
+ * @template TSuccess - The type of the success value.
80
+ * @template TE - The type of the error value (default is Error).
81
+ *
82
+ * @static
83
+ */
84
+ static Create(error) {
85
+ return new Fail(error);
86
+ }
87
+ }
@@ -1,91 +1,68 @@
1
- // type: class
2
- // description: Class representing a successful result.
3
-
4
1
  import { ResultState, ITResult } from "../interfaces/ITResult";
5
2
  import { ResultMatch } from "../types/ResultMatch";
6
3
  import { ChainedCallback, SuccessMapCallback, ErrorMapCallback } from "../types/resultsCallbacks";
7
4
  import { ATresult } from "./abstracts/ATresult";
8
-
9
5
  /**
10
6
  * Class representing a successful result.
11
7
  * @template TSuccess - The type of the success value.
12
8
  * @template TE - The type of the error value (default is Error).
13
9
  */
14
- export class Success<TSuccess, TE = Error> extends ATresult<TSuccess, TE> {
10
+ export declare class Success<TSuccess, TE = Error> extends ATresult<TSuccess, TE> {
11
+ readonly value: TSuccess;
15
12
  /**
16
13
  * Creates an instance of Success.
17
14
  * @param value The success value.
18
15
  */
19
- constructor(public readonly value: TSuccess) { super(); }
20
-
16
+ constructor(value: TSuccess);
21
17
  /**
22
18
  * Returns the state of the result.
23
19
  * @returns The state indicating success.
24
20
  */
25
- state(): ResultState {
26
- return ResultState.Success;
27
- }
21
+ state(): ResultState;
28
22
  /**
29
23
  * Matches the result with the provided matcher functions.
30
24
  * @param matcher The matcher object containing functions for success and error cases.
31
25
  * @returns The result of the matched function.
32
26
  */
33
- match<Result>(matcher: ResultMatch<TSuccess, TE, Result>): Result {
34
- return matcher.Ok(this.value);
35
- }
27
+ match<Result>(matcher: ResultMatch<TSuccess, TE, Result>): Result;
36
28
  /**
37
29
  * Chains the result with another operation that returns a new result.
38
30
  * @param fn The function to apply if the result is successful.
39
31
  * @returns The result of the chained operation.
40
32
  */
41
- andThen<NewSuccess>(fn: ChainedCallback<TSuccess, NewSuccess, TE>): ITResult<NewSuccess, TE> {
42
- return fn(this.value);
43
- }
33
+ andThen<NewSuccess>(fn: ChainedCallback<TSuccess, NewSuccess, TE>): ITResult<NewSuccess, TE>;
44
34
  /**
45
35
  * Maps the success value to a new value.
46
36
  * @param fn The function to apply to the success value.
47
37
  * @returns A new Success instance containing the mapped value.
48
38
  */
49
- map<NewSuccess>(fn: SuccessMapCallback<TSuccess, NewSuccess>): ITResult<NewSuccess, TE> {
50
- return new Success(fn(this.value));
51
- }
39
+ map<NewSuccess>(fn: SuccessMapCallback<TSuccess, NewSuccess>): ITResult<NewSuccess, TE>;
52
40
  /**
53
41
  * Maps the error value to a new error value.
54
42
  * @param _ The function to apply to the error value.
55
43
  * @returns A new Success instance containing the original success value.
56
44
  */
57
- mapError<NewError>(_: ErrorMapCallback<TE, NewError>): ITResult<TSuccess, NewError> {
58
- return new Success<TSuccess, NewError>(this.value);
59
- }
60
-
45
+ mapError<NewError>(_: ErrorMapCallback<TE, NewError>): ITResult<TSuccess, NewError>;
61
46
  /**
62
47
  * Returns the success value or throws an error if the result is an error.
63
48
  * @returns The success value.
64
49
  */
65
- throwIfError(): TSuccess {
66
- return this.value;
67
- }
68
-
50
+ throwIfError(): TSuccess;
69
51
  /**
70
52
  * Retrieves the success value or returns the provided default value if the result is an error.
71
53
  * @param _ The value to return if the result is an error.
72
54
  * @returns The success value if the result is a success, otherwise the default value.
73
55
  */
74
- unwrapOr(_: TSuccess): TSuccess {
75
- return this.value;
76
- }
77
-
56
+ unwrapOr(_: TSuccess): TSuccess;
78
57
  /**
79
58
  * Creates a new Success instance.
80
59
  * @param value The success value.
81
60
  * @returns A new Success instance containing the value.
82
- *
61
+ *
83
62
  * @template TSuccess - The type of the success value.
84
63
  * @template TE - The type of the error value (default is Error).
85
- *
64
+ *
86
65
  * @static
87
66
  */
88
- static Create<TSuccess, TE = Error>(value: TSuccess): Success<TSuccess, TE> {
89
- return new Success(value);
90
- }
91
- }
67
+ static Create<TSuccess, TE = Error>(value: TSuccess): Success<TSuccess, TE>;
68
+ }
@@ -0,0 +1,86 @@
1
+ // type: class
2
+ // description: Class representing a successful result.
3
+ import { ResultState } from "../interfaces/ITResult";
4
+ import { ATresult } from "./abstracts/ATresult";
5
+ /**
6
+ * Class representing a successful result.
7
+ * @template TSuccess - The type of the success value.
8
+ * @template TE - The type of the error value (default is Error).
9
+ */
10
+ export class Success extends ATresult {
11
+ /**
12
+ * Creates an instance of Success.
13
+ * @param value The success value.
14
+ */
15
+ constructor(value) {
16
+ super();
17
+ this.value = value;
18
+ }
19
+ /**
20
+ * Returns the state of the result.
21
+ * @returns The state indicating success.
22
+ */
23
+ state() {
24
+ return ResultState.Success;
25
+ }
26
+ /**
27
+ * Matches the result with the provided matcher functions.
28
+ * @param matcher The matcher object containing functions for success and error cases.
29
+ * @returns The result of the matched function.
30
+ */
31
+ match(matcher) {
32
+ return matcher.Ok(this.value);
33
+ }
34
+ /**
35
+ * Chains the result with another operation that returns a new result.
36
+ * @param fn The function to apply if the result is successful.
37
+ * @returns The result of the chained operation.
38
+ */
39
+ andThen(fn) {
40
+ return fn(this.value);
41
+ }
42
+ /**
43
+ * Maps the success value to a new value.
44
+ * @param fn The function to apply to the success value.
45
+ * @returns A new Success instance containing the mapped value.
46
+ */
47
+ map(fn) {
48
+ return new Success(fn(this.value));
49
+ }
50
+ /**
51
+ * Maps the error value to a new error value.
52
+ * @param _ The function to apply to the error value.
53
+ * @returns A new Success instance containing the original success value.
54
+ */
55
+ mapError(_) {
56
+ return new Success(this.value);
57
+ }
58
+ /**
59
+ * Returns the success value or throws an error if the result is an error.
60
+ * @returns The success value.
61
+ */
62
+ throwIfError() {
63
+ return this.value;
64
+ }
65
+ /**
66
+ * Retrieves the success value or returns the provided default value if the result is an error.
67
+ * @param _ The value to return if the result is an error.
68
+ * @returns The success value if the result is a success, otherwise the default value.
69
+ */
70
+ unwrapOr(_) {
71
+ return this.value;
72
+ }
73
+ /**
74
+ * Creates a new Success instance.
75
+ * @param value The success value.
76
+ * @returns A new Success instance containing the value.
77
+ *
78
+ * @template TSuccess - The type of the success value.
79
+ * @template TE - The type of the error value (default is Error).
80
+ *
81
+ * @static
82
+ */
83
+ static Create(value) {
84
+ return new Success(value);
85
+ }
86
+ }
@@ -1,44 +1,40 @@
1
- // type: class
2
- // description: Abstract class implementing the ITResult interface.
3
-
4
1
  import { ResultState, ITResult } from "../../interfaces/ITResult";
5
2
  import { ResultMatch } from "../../types/ResultMatch";
6
3
  import { ChainedCallback, ErrorMapCallback, SuccessMapCallback } from "../../types/resultsCallbacks";
7
-
8
4
  /**
9
5
  * Abstract class representing a result that can be either a success or an error.
10
6
  */
11
- export abstract class ATresult<Success, E = Error> implements ITResult<Success, E> {
7
+ export declare abstract class ATresult<Success, E = Error> implements ITResult<Success, E> {
12
8
  /**
13
9
  * Gets the current state of the result.
14
- *
10
+ *
15
11
  * @returns The state of the result, either Success or Error.
16
12
  */
17
13
  abstract state(): ResultState;
18
14
  /**
19
15
  * Matches the result with the provided matcher functions.
20
- *
16
+ *
21
17
  * @param matcher - An object containing callback functions for success and error cases.
22
18
  * @returns The result of applying the appropriate matcher function.
23
19
  */
24
20
  abstract match<Result>(matcher: ResultMatch<Success, E, Result>): Result;
25
21
  /**
26
22
  * Chains the result with another operation that returns a new result.
27
- *
23
+ *
28
24
  * @param fn - A callback function that takes the success value and returns a new result.
29
25
  * @returns A new result after applying the chained operation.
30
26
  */
31
27
  abstract andThen<NewSuccess>(fn: ChainedCallback<Success, NewSuccess, E>): ITResult<NewSuccess, E>;
32
28
  /**
33
29
  * Maps the success value to a new value.
34
- *
30
+ *
35
31
  * @param fn - A callback function that takes the success value and returns a new success value.
36
32
  * @returns A new result with the mapped success value.
37
33
  */
38
34
  abstract map<NewSuccess>(fn: SuccessMapCallback<Success, NewSuccess>): ITResult<NewSuccess, E>;
39
35
  /**
40
36
  * Maps the error value to a new value.
41
- *
37
+ *
42
38
  * @param fn - A callback function that takes the error value and returns a new error value.
43
39
  * @returns A new result with the mapped error value.
44
40
  */
@@ -57,18 +53,14 @@ export abstract class ATresult<Success, E = Error> implements ITResult<Success,
57
53
  abstract unwrapOr(defaultValue: Success): Success;
58
54
  /**
59
55
  * Checks if the result is a success.
60
- *
56
+ *
61
57
  * @returns True if the result is a success, false otherwise.
62
58
  */
63
- isSuccess(): boolean {
64
- return this.state() === ResultState.Success;
65
- }
59
+ isSuccess(): boolean;
66
60
  /**
67
61
  * Checks if the result is an error.
68
- *
62
+ *
69
63
  * @returns True if the result is an error, false otherwise.
70
64
  */
71
- isError(): boolean {
72
- return this.state() === ResultState.Error;
73
- }
74
- }
65
+ isError(): boolean;
66
+ }
@@ -0,0 +1,24 @@
1
+ // type: class
2
+ // description: Abstract class implementing the ITResult interface.
3
+ import { ResultState } from "../../interfaces/ITResult";
4
+ /**
5
+ * Abstract class representing a result that can be either a success or an error.
6
+ */
7
+ export class ATresult {
8
+ /**
9
+ * Checks if the result is a success.
10
+ *
11
+ * @returns True if the result is a success, false otherwise.
12
+ */
13
+ isSuccess() {
14
+ return this.state() === ResultState.Success;
15
+ }
16
+ /**
17
+ * Checks if the result is an error.
18
+ *
19
+ * @returns True if the result is an error, false otherwise.
20
+ */
21
+ isError() {
22
+ return this.state() === ResultState.Error;
23
+ }
24
+ }
@@ -0,0 +1,7 @@
1
+ import { ErrorCallback } from "../types/resultsCallbacks";
2
+ /**
3
+ * Decorator to handle error path operations by executing a callback on errored results.
4
+ * @param fn Error path callback to be executed on errored results.
5
+ * @returns A method decorator that wraps the original method with error path handling.
6
+ */
7
+ export declare function ErrorPath<T>(fn: ErrorCallback<T, void>): (target: any, key: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
@@ -0,0 +1,19 @@
1
+ import { ErrorCallback } from "../../types/resultsCallbacks";
2
+ /**
3
+ * Handles the error path for synchronous functions by executing a callback on errored results.
4
+ * @param this The context in which the original function is called.
5
+ * @param original The original function to be wrapped.
6
+ * @param path The error callback to be executed on errored results.
7
+ * @param args Arguments to be passed to the original function.
8
+ * @returns The result of the original function or the result of the error callback.
9
+ */
10
+ export declare function errorPathSync(this: any, original: Function, path: ErrorCallback<any, any>, ...args: any[]): any;
11
+ /**
12
+ * Handles the error path for asynchronous functions by executing a callback on errored results.
13
+ * @param this The context in which the original function is called.
14
+ * @param original The original function to be wrapped.
15
+ * @param path The error callback to be executed on errored results.
16
+ * @param args Arguments to be passed to the original function.
17
+ * @returns The result of the original function or the result of the error callback.
18
+ */
19
+ export declare function errorPathAsync(this: any, original: Function, path: ErrorCallback<any, any>, ...args: any[]): Promise<any>;
@@ -2,8 +2,6 @@
2
2
  //description: Functions to handle error path operations by executing a callback on errored results.
3
3
  import { ATresult } from "../../classes/abstracts/ATresult";
4
4
  import { applyMatch } from "../../functions/applyMatch";
5
- import { ErrorCallback } from "../../types/resultsCallbacks";
6
-
7
5
  /**
8
6
  * Handles the error path for synchronous functions by executing a callback on errored results.
9
7
  * @param this The context in which the original function is called.
@@ -12,14 +10,12 @@ import { ErrorCallback } from "../../types/resultsCallbacks";
12
10
  * @param args Arguments to be passed to the original function.
13
11
  * @returns The result of the original function or the result of the error callback.
14
12
  */
15
- export function errorPathSync(this: any, original: Function, path: ErrorCallback<any, any>, ...args: any[]): any {
13
+ export function errorPathSync(original, path, ...args) {
16
14
  const result = original.call(this, ...args);
17
-
18
- return result instanceof ATresult
19
- ? applyMatch(result, undefined, path)
20
- : result;
15
+ return result instanceof ATresult
16
+ ? applyMatch(result, undefined, path)
17
+ : result;
21
18
  }
22
-
23
19
  /**
24
20
  * Handles the error path for asynchronous functions by executing a callback on errored results.
25
21
  * @param this The context in which the original function is called.
@@ -28,10 +24,9 @@ export function errorPathSync(this: any, original: Function, path: ErrorCallback
28
24
  * @param args Arguments to be passed to the original function.
29
25
  * @returns The result of the original function or the result of the error callback.
30
26
  */
31
- export async function errorPathAsync(this: any, original: Function, path: ErrorCallback<any, any>, ...args: any[]): any {
27
+ export async function errorPathAsync(original, path, ...args) {
32
28
  const result = await original.call(this, ...args);
33
-
34
- return result instanceof ATresult
35
- ? applyMatch(result, undefined, path)
36
- : result;
37
- }
29
+ return result instanceof ATresult
30
+ ? applyMatch(result, undefined, path)
31
+ : result;
32
+ }
@@ -1,28 +1,25 @@
1
1
  //type: decorator
2
2
  //description: Decorator to handle error path operations by executing a callback on errored results.
3
-
4
- import { ErrorCallback } from "../types/resultsCallbacks";
5
3
  import { errorPathAsync, errorPathSync } from "./ErrorPath.internal/functions";
6
-
7
4
  /**
8
5
  * Decorator to handle error path operations by executing a callback on errored results.
9
6
  * @param fn Error path callback to be executed on errored results.
10
7
  * @returns A method decorator that wraps the original method with error path handling.
11
8
  */
12
- export function ErrorPath<T>(fn: ErrorCallback<T, void>) {
13
- return function (target: any, key: string, descriptor: PropertyDescriptor) {
9
+ export function ErrorPath(fn) {
10
+ return function (target, key, descriptor) {
14
11
  const original = descriptor.value;
15
12
  const isAsync = original.constructor.name === "AsyncFunction";
16
-
17
13
  if (isAsync) {
18
- descriptor.value = async function (this: any, ...args: any[]) {
14
+ descriptor.value = async function (...args) {
19
15
  return await errorPathAsync.call(this, original, fn, ...args);
20
16
  };
21
- } else {
22
- descriptor.value = function (this: any, ...args: any[]) {
17
+ }
18
+ else {
19
+ descriptor.value = function (...args) {
23
20
  return errorPathSync.call(this, original, fn, ...args);
24
21
  };
25
22
  }
26
23
  return descriptor;
27
24
  };
28
- }
25
+ }
@@ -0,0 +1,7 @@
1
+ import { SuccessCallback } from "../types/resultsCallbacks";
2
+ /**
3
+ * Decorator to handle happy path operations by executing a callback on successful results.
4
+ * @param fn Happy path callback to be executed on successful results.
5
+ * @returns A method decorator that wraps the original method with happy path handling.
6
+ */
7
+ export declare function HappyPath<T>(fn: SuccessCallback<T, void>): (target: any, key: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
@@ -0,0 +1,19 @@
1
+ import { SuccessCallback } from "../../types/resultsCallbacks";
2
+ /**
3
+ * Handles the happy path for synchronous functions by executing a callback on successful results.
4
+ * @param this The context in which the original function is called.
5
+ * @param original The original function to be wrapped.
6
+ * @param path The success callback to be executed on successful results.
7
+ * @param args Arguments to be passed to the original function.
8
+ * @returns The result of the original function or the result of the success callback.
9
+ */
10
+ export declare function happyPathSync(this: any, original: Function, path: SuccessCallback<any, any>, ...args: any[]): any;
11
+ /**
12
+ * Handles the happy path for asynchronous functions by executing a callback on successful results.
13
+ * @param this The context in which the original function is called.
14
+ * @param original The original function to be wrapped.
15
+ * @param path The success callback to be executed on successful results.
16
+ * @param args Arguments to be passed to the original function.
17
+ * @returns The result of the original function or the result of the success callback.
18
+ */
19
+ export declare function happyPathASync(this: any, original: Function, path: SuccessCallback<any, any>, ...args: any[]): Promise<any>;
@@ -2,8 +2,6 @@
2
2
  //description: Functions to handle happy path operations by executing a callback on successful results.
3
3
  import { ATresult } from "../../classes/abstracts/ATresult";
4
4
  import { applyMatch } from "../../functions/applyMatch";
5
- import { SuccessCallback } from "../../types/resultsCallbacks";
6
-
7
5
  /**
8
6
  * Handles the happy path for synchronous functions by executing a callback on successful results.
9
7
  * @param this The context in which the original function is called.
@@ -12,14 +10,12 @@ import { SuccessCallback } from "../../types/resultsCallbacks";
12
10
  * @param args Arguments to be passed to the original function.
13
11
  * @returns The result of the original function or the result of the success callback.
14
12
  */
15
- export function happyPathSync(this: any, original: Function, path: SuccessCallback<any, any>, ...args: any[]): any {
13
+ export function happyPathSync(original, path, ...args) {
16
14
  const result = original.call(this, ...args);
17
-
18
- return result instanceof ATresult
19
- ? applyMatch(result, path, undefined)
20
- : result;
15
+ return result instanceof ATresult
16
+ ? applyMatch(result, path, undefined)
17
+ : result;
21
18
  }
22
-
23
19
  /**
24
20
  * Handles the happy path for asynchronous functions by executing a callback on successful results.
25
21
  * @param this The context in which the original function is called.
@@ -28,10 +24,9 @@ export function happyPathSync(this: any, original: Function, path: SuccessCallba
28
24
  * @param args Arguments to be passed to the original function.
29
25
  * @returns The result of the original function or the result of the success callback.
30
26
  */
31
- export async function happyPathASync(this: any, original: Function, path: SuccessCallback<any, any>, ...args: any[]): any {
27
+ export async function happyPathASync(original, path, ...args) {
32
28
  const result = await original.call(this, ...args);
33
-
34
- return result instanceof ATresult
35
- ? applyMatch(result, path, undefined)
36
- : result;
37
- }
29
+ return result instanceof ATresult
30
+ ? applyMatch(result, path, undefined)
31
+ : result;
32
+ }