@driveflux/result 5.0.1 → 5.0.2
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 +28 -23
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -2,18 +2,17 @@ export class Err {
|
|
|
2
2
|
val;
|
|
3
3
|
metadata;
|
|
4
4
|
static EMPTY = new Err(undefined);
|
|
5
|
-
ok;
|
|
6
|
-
err;
|
|
7
|
-
constructor(val, metadata){
|
|
5
|
+
ok = false;
|
|
6
|
+
err = true;
|
|
7
|
+
constructor(val, metadata) {
|
|
8
8
|
this.val = val;
|
|
9
9
|
this.metadata = metadata;
|
|
10
|
-
this.ok = false;
|
|
11
|
-
this.err = true;
|
|
12
10
|
}
|
|
13
11
|
/**
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
* If the result has a value returns that value. Otherwise returns the passed in value.
|
|
13
|
+
* @param val the value to replace the error with
|
|
14
|
+
*/
|
|
15
|
+
else(val) {
|
|
17
16
|
return val;
|
|
18
17
|
}
|
|
19
18
|
expect(msg) {
|
|
@@ -33,18 +32,17 @@ export class Ok {
|
|
|
33
32
|
val;
|
|
34
33
|
metadata;
|
|
35
34
|
static EMPTY = new Ok(undefined);
|
|
36
|
-
ok;
|
|
37
|
-
err;
|
|
38
|
-
constructor(val, metadata){
|
|
35
|
+
ok = true;
|
|
36
|
+
err = false;
|
|
37
|
+
constructor(val, metadata) {
|
|
39
38
|
this.val = val;
|
|
40
39
|
this.metadata = metadata;
|
|
41
|
-
this.ok = true;
|
|
42
|
-
this.err = false;
|
|
43
40
|
}
|
|
44
41
|
/**
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
42
|
+
* If the result has a value returns that value. Otherwise returns the passed in value.
|
|
43
|
+
* @param val the value to replace the error with
|
|
44
|
+
*/
|
|
45
|
+
else(_val) {
|
|
48
46
|
return this.val;
|
|
49
47
|
}
|
|
50
48
|
expect(_msg) {
|
|
@@ -62,25 +60,32 @@ export class Ok {
|
|
|
62
60
|
}
|
|
63
61
|
export function Results(...results) {
|
|
64
62
|
const okResult = [];
|
|
65
|
-
for (const result of results){
|
|
63
|
+
for (const result of results) {
|
|
66
64
|
if (result.ok) {
|
|
67
65
|
okResult.push(result.val);
|
|
68
|
-
}
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
69
68
|
return new Err(result.val);
|
|
70
69
|
}
|
|
71
70
|
}
|
|
72
71
|
return new Ok(okResult);
|
|
73
72
|
}
|
|
74
|
-
export const isResult = (response)=>{
|
|
75
|
-
return typeof response === 'object' &&
|
|
73
|
+
export const isResult = (response) => {
|
|
74
|
+
return (typeof response === 'object' &&
|
|
75
|
+
response &&
|
|
76
|
+
typeof response.ok !== 'undefined' &&
|
|
77
|
+
typeof response.err !== 'undefined');
|
|
76
78
|
};
|
|
77
|
-
export const isErrorWithResult = (response)=>{
|
|
78
|
-
return typeof response === 'object' &&
|
|
79
|
+
export const isErrorWithResult = (response) => {
|
|
80
|
+
return (typeof response === 'object' &&
|
|
81
|
+
response?.result &&
|
|
82
|
+
isResult(response.result));
|
|
79
83
|
};
|
|
80
84
|
export class ErrorWithResult extends Error {
|
|
81
85
|
result;
|
|
82
|
-
constructor(result){
|
|
86
|
+
constructor(result) {
|
|
83
87
|
super('');
|
|
84
88
|
this.result = result;
|
|
85
89
|
}
|
|
86
90
|
}
|
|
91
|
+
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@driveflux/result",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./package.json": "./package.json",
|
|
@@ -13,11 +13,11 @@
|
|
|
13
13
|
"dist"
|
|
14
14
|
],
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@driveflux/problem": "5.0.
|
|
16
|
+
"@driveflux/problem": "5.0.2"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@driveflux/fab": "3.0.
|
|
20
|
-
"@driveflux/tsconfig": "2.0.
|
|
19
|
+
"@driveflux/fab": "3.0.2",
|
|
20
|
+
"@driveflux/tsconfig": "2.0.2",
|
|
21
21
|
"@swc/cli": "0.7.5",
|
|
22
22
|
"@swc/core": "1.11.24",
|
|
23
23
|
"@types/node": "^22.15.16",
|