@driveflux/result 3.0.0 → 3.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.
Files changed (2) hide show
  1. package/dist/index.js +87 -80
  2. package/package.json +5 -5
package/dist/index.js CHANGED
@@ -1,88 +1,95 @@
1
- // src/index.ts
2
- var Err = class _Err {
3
- constructor(val) {
4
- this.val = val;
5
- }
6
- static EMPTY = new _Err(void 0);
7
- ok = false;
8
- err = true;
9
- /**
1
+ function _define_property(obj, key, value) {
2
+ if (key in obj) {
3
+ Object.defineProperty(obj, key, {
4
+ value: value,
5
+ enumerable: true,
6
+ configurable: true,
7
+ writable: true
8
+ });
9
+ } else {
10
+ obj[key] = value;
11
+ }
12
+ return obj;
13
+ }
14
+ export class Err {
15
+ /**
10
16
  * If the result has a value returns that value. Otherwise returns the passed in value.
11
17
  * @param val the value to replace the error with
12
- */
13
- else(val) {
14
- return val;
15
- }
16
- expect(msg) {
17
- throw new Error(`${msg} - Error: ${JSON.stringify(this.val)}`);
18
- }
19
- unwrap() {
20
- throw new Error(`Tried to unwrap Error: ${JSON.stringify(this.val)}`);
21
- }
22
- map(_mapper) {
23
- return this;
24
- }
25
- mapErr(mapper) {
26
- return new _Err(mapper(this.val));
27
- }
28
- };
29
- var Ok = class _Ok {
30
- constructor(val) {
31
- this.val = val;
32
- }
33
- static EMPTY = new _Ok(void 0);
34
- ok = true;
35
- err = false;
36
- /**
18
+ */ else(val) {
19
+ return val;
20
+ }
21
+ expect(msg) {
22
+ throw new Error(`${msg} - Error: ${JSON.stringify(this.val)}`);
23
+ }
24
+ unwrap() {
25
+ throw new Error(`Tried to unwrap Error: ${JSON.stringify(this.val)}`);
26
+ }
27
+ map(_mapper) {
28
+ return this;
29
+ }
30
+ mapErr(mapper) {
31
+ return new Err(mapper(this.val));
32
+ }
33
+ constructor(val){
34
+ _define_property(this, "val", void 0);
35
+ _define_property(this, "ok", void 0);
36
+ _define_property(this, "err", void 0);
37
+ this.val = val;
38
+ this.ok = false;
39
+ this.err = true;
40
+ }
41
+ }
42
+ _define_property(Err, "EMPTY", new Err(undefined));
43
+ export class Ok {
44
+ /**
37
45
  * If the result has a value returns that value. Otherwise returns the passed in value.
38
46
  * @param val the value to replace the error with
39
- */
40
- else(_val) {
41
- return this.val;
42
- }
43
- expect(_msg) {
44
- return this.val;
45
- }
46
- unwrap() {
47
- return this.val;
48
- }
49
- map(mapper) {
50
- return new _Ok(mapper(this.val));
51
- }
52
- mapErr(_mapper) {
53
- return this;
54
- }
55
- };
56
- function Results(...results) {
57
- const okResult = [];
58
- for (let result of results) {
59
- if (result.ok) {
60
- okResult.push(result.val);
61
- } else {
62
- return new Err(result.val);
47
+ */ else(_val) {
48
+ return this.val;
49
+ }
50
+ expect(_msg) {
51
+ return this.val;
52
+ }
53
+ unwrap() {
54
+ return this.val;
55
+ }
56
+ map(mapper) {
57
+ return new Ok(mapper(this.val));
58
+ }
59
+ mapErr(_mapper) {
60
+ return this;
61
+ }
62
+ constructor(val){
63
+ _define_property(this, "val", void 0);
64
+ _define_property(this, "ok", void 0);
65
+ _define_property(this, "err", void 0);
66
+ this.val = val;
67
+ this.ok = true;
68
+ this.err = false;
63
69
  }
64
- }
65
- return new Ok(okResult);
66
70
  }
67
- var isResult = (response) => {
68
- return typeof response === "object" && response && typeof response.ok !== "undefined" && typeof response.err !== "undefined";
69
- };
70
- var isErrorWithResult = (response) => {
71
- return response.result && isResult(response.result);
72
- };
73
- var ErrorWithResult = class extends Error {
74
- result;
75
- constructor(result) {
76
- super("");
77
- this.result = result;
78
- }
71
+ _define_property(Ok, "EMPTY", new Ok(undefined));
72
+ export function Results(...results) {
73
+ const okResult = [];
74
+ for (let result of results){
75
+ if (result.ok) {
76
+ okResult.push(result.val);
77
+ } else {
78
+ return new Err(result.val);
79
+ }
80
+ }
81
+ return new Ok(okResult);
82
+ }
83
+ export const isResult = (response)=>{
84
+ return typeof response === 'object' && response && typeof response.ok !== 'undefined' && typeof response.err !== 'undefined';
79
85
  };
80
- export {
81
- Err,
82
- ErrorWithResult,
83
- Ok,
84
- Results,
85
- isErrorWithResult,
86
- isResult
86
+ export const isErrorWithResult = (response)=>{
87
+ return response.result && isResult(response.result);
87
88
  };
88
- //# sourceMappingURL=index.js.map
89
+ export class ErrorWithResult extends Error {
90
+ constructor(result){
91
+ super('');
92
+ _define_property(this, "result", void 0);
93
+ this.result = result;
94
+ }
95
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@driveflux/result",
3
- "version": "3.0.0",
3
+ "version": "3.0.2",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  "./package.json": "./package.json",
@@ -17,18 +17,18 @@
17
17
  ],
18
18
  "types": "dist/index.d.ts",
19
19
  "dependencies": {
20
- "@driveflux/problem": "3.0.0"
20
+ "@driveflux/problem": "3.0.1"
21
21
  },
22
22
  "devDependencies": {
23
- "@types/node": "^20.7.0",
23
+ "@types/node": "^20.8.0",
24
24
  "del-cli": "^5.1.0",
25
- "esbuild": "^0.19.3",
25
+ "esbuild": "^0.19.4",
26
26
  "esbuild-register": "^3.5.0",
27
27
  "typescript": "5.2.2"
28
28
  },
29
29
  "scripts": {
30
30
  "build": "npm run clean && npm run build:types && npm run build:js",
31
- "build:js": "node -r esbuild-register build.js",
31
+ "build:js": "node build.js && swc src --out-dir dist",
32
32
  "build:types": "tsc --build",
33
33
  "clean": "del dist/**/*.js",
34
34
  "type-check": "tsc --noEmit"