@clipboard-health/util-ts 3.10.0 → 3.11.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.
package/package.json
CHANGED
|
@@ -9,31 +9,35 @@ export interface Failure<E> {
|
|
|
9
9
|
readonly isSuccess: false;
|
|
10
10
|
readonly error: E;
|
|
11
11
|
}
|
|
12
|
+
export type SuccessResult<A> = Right<A> & Success<A>;
|
|
13
|
+
export type FailureResult = Left<ServiceError> & Failure<ServiceError>;
|
|
12
14
|
/**
|
|
13
15
|
* Represents the result of a service operation that may fail.
|
|
16
|
+
*
|
|
17
|
+
* The type is also an {@link Either}, allowing functions built for {@link Either}.
|
|
18
|
+
*
|
|
14
19
|
* @template A The type of the successful result value
|
|
15
20
|
*/
|
|
16
|
-
export type ServiceResult<A> =
|
|
21
|
+
export type ServiceResult<A> = SuccessResult<A> | FailureResult;
|
|
17
22
|
/**
|
|
18
|
-
*
|
|
19
|
-
* `isSuccess`.
|
|
23
|
+
* Creates a successful ServiceResult.
|
|
20
24
|
*/
|
|
21
25
|
export declare function success<A>(value: A): ServiceResult<A>;
|
|
22
26
|
/**
|
|
23
|
-
*
|
|
24
|
-
* `isSuccess`.
|
|
27
|
+
* Creates a failed ServiceResult.
|
|
25
28
|
*/
|
|
26
29
|
export declare function failure<A = never>(params: ServiceErrorParams | ServiceError): ServiceResult<A>;
|
|
27
30
|
/**
|
|
28
|
-
*
|
|
31
|
+
* Type guard for failure results.
|
|
29
32
|
*/
|
|
30
33
|
export declare function isFailure<A>(result: ServiceResult<A>): result is Left<ServiceError> & Failure<ServiceError>;
|
|
31
34
|
/**
|
|
32
|
-
*
|
|
35
|
+
* Type guard for success results.
|
|
33
36
|
*/
|
|
34
37
|
export declare function isSuccess<A>(result: ServiceResult<A>): result is Right<A> & Success<A>;
|
|
35
38
|
/**
|
|
36
|
-
* Alias for {@link mapLeft}
|
|
39
|
+
* Alias for {@link mapLeft}.
|
|
40
|
+
* Note: returns an {@link Either}, not a ServiceResult.
|
|
37
41
|
*/
|
|
38
42
|
export declare function mapFailure<G>(f: (left: ServiceError) => G): <A>(result: ServiceResult<A>) => Either<G, A>;
|
|
39
43
|
/**
|
|
@@ -11,44 +11,43 @@ exports.fromSafeParseReturnType = fromSafeParseReturnType;
|
|
|
11
11
|
const serviceError_1 = require("../errors/serviceError");
|
|
12
12
|
const either_1 = require("./either");
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
15
|
-
* `isSuccess`.
|
|
14
|
+
* Creates a successful ServiceResult.
|
|
16
15
|
*/
|
|
17
16
|
function success(value) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
isSuccess:
|
|
21
|
-
|
|
17
|
+
return Object.freeze({
|
|
18
|
+
isRight: true,
|
|
19
|
+
isSuccess: true,
|
|
20
|
+
right: value,
|
|
21
|
+
value,
|
|
22
22
|
});
|
|
23
|
-
return Object.freeze(base);
|
|
24
23
|
}
|
|
25
24
|
/**
|
|
26
|
-
*
|
|
27
|
-
* `isSuccess`.
|
|
25
|
+
* Creates a failed ServiceResult.
|
|
28
26
|
*/
|
|
29
27
|
function failure(params) {
|
|
30
28
|
const error = params instanceof serviceError_1.ServiceError ? params : new serviceError_1.ServiceError(params);
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
isSuccess:
|
|
34
|
-
|
|
29
|
+
return Object.freeze({
|
|
30
|
+
isRight: false,
|
|
31
|
+
isSuccess: false,
|
|
32
|
+
left: error,
|
|
33
|
+
error,
|
|
35
34
|
});
|
|
36
|
-
return Object.freeze(base);
|
|
37
35
|
}
|
|
38
36
|
/**
|
|
39
|
-
*
|
|
37
|
+
* Type guard for failure results.
|
|
40
38
|
*/
|
|
41
39
|
function isFailure(result) {
|
|
42
40
|
return !result.isSuccess;
|
|
43
41
|
}
|
|
44
42
|
/**
|
|
45
|
-
*
|
|
43
|
+
* Type guard for success results.
|
|
46
44
|
*/
|
|
47
45
|
function isSuccess(result) {
|
|
48
46
|
return result.isSuccess;
|
|
49
47
|
}
|
|
50
48
|
/**
|
|
51
|
-
* Alias for {@link mapLeft}
|
|
49
|
+
* Alias for {@link mapLeft}.
|
|
50
|
+
* Note: returns an {@link Either}, not a ServiceResult.
|
|
52
51
|
*/
|
|
53
52
|
function mapFailure(f) {
|
|
54
53
|
return (0, either_1.mapLeft)(f);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serviceResult.js","sourceRoot":"","sources":["../../../../../../packages/util-ts/src/lib/functional/serviceResult.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"serviceResult.js","sourceRoot":"","sources":["../../../../../../packages/util-ts/src/lib/functional/serviceResult.ts"],"names":[],"mappings":";;AA8BA,0BAOC;AAKD,0BAQC;AAKD,8BAIC;AAKD,8BAEC;AAMD,gCAIC;AA+CD,sCASC;AAuCD,4BASC;AAqCD,0DAIC;AA3ND,yDAA+E;AAC/E,qCAAuE;AAwBvE;;GAEG;AACH,SAAgB,OAAO,CAAI,KAAQ;IACjC,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,IAAI;QACf,KAAK,EAAE,KAAK;QACZ,KAAK;KACG,CAAC,CAAC;AACd,CAAC;AAED;;GAEG;AACH,SAAgB,OAAO,CAAY,MAAyC;IAC1E,MAAM,KAAK,GAAG,MAAM,YAAY,2BAAY,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,2BAAY,CAAC,MAAM,CAAC,CAAC;IACjF,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,OAAO,EAAE,KAAK;QACd,SAAS,EAAE,KAAK;QAChB,IAAI,EAAE,KAAK;QACX,KAAK;KACG,CAAC,CAAC;AACd,CAAC;AAED;;GAEG;AACH,SAAgB,SAAS,CACvB,MAAwB;IAExB,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC;AAC3B,CAAC;AAED;;GAEG;AACH,SAAgB,SAAS,CAAI,MAAwB;IACnD,OAAO,MA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