@j2blasco/ts-result 0.0.4 → 0.0.6

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/README.md CHANGED
Binary file
package/dist/index.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  export * from './result';
2
+ export * from './result-functions';
package/dist/index.js CHANGED
@@ -1 +1,2 @@
1
1
  export * from './result';
2
+ export * from './result-functions';
@@ -0,0 +1,3 @@
1
+ import { ErrorType, Result, SuccessType } from "./result";
2
+ export declare function andThen<TSuccess, TError, TResult extends Result<any, any>>(callback: (value: TSuccess) => TResult): (result: Result<TSuccess, TError>) => Result<SuccessType<TResult>, TError | ErrorType<TResult>>;
3
+ export declare function andThenAsync<TSuccess, TError, TResult extends Result<any, any>>(callback: (value: TSuccess) => Promise<TResult>): (result: Result<TSuccess, TError>) => Promise<Result<SuccessType<TResult>, TError | ErrorType<TResult>>>;
@@ -0,0 +1,6 @@
1
+ export function andThen(callback) {
2
+ return (result) => result.andThen(callback);
3
+ }
4
+ export function andThenAsync(callback) {
5
+ return (result) => result.andThenAsync(callback);
6
+ }
package/dist/result.js CHANGED
@@ -1,12 +1,3 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  export function unwrapSuccessResult(result) {
11
2
  if (result instanceof ResultSuccessImp) {
12
3
  return result['value'];
@@ -43,48 +34,42 @@ export class resultError {
43
34
  }
44
35
  }
45
36
  class ResultSuccessImp {
37
+ value;
46
38
  constructor(value) {
47
39
  this.value = value;
48
40
  }
49
41
  andThen(f) {
50
42
  return f(this.value);
51
43
  }
52
- andThenAsync(f) {
53
- return __awaiter(this, void 0, void 0, function* () {
54
- return yield f(this.value);
55
- });
44
+ async andThenAsync(f) {
45
+ return await f(this.value);
56
46
  }
57
47
  catchError(_f) {
58
48
  return this;
59
49
  }
60
- catchErrorAsync(_f) {
61
- return __awaiter(this, void 0, void 0, function* () {
62
- return this;
63
- });
50
+ async catchErrorAsync(_f) {
51
+ return this;
64
52
  }
65
53
  unwrapOrThrow(_errorCallback) {
66
54
  return this.value;
67
55
  }
68
56
  }
69
57
  class ResultErrorImp {
58
+ error;
70
59
  constructor(error) {
71
60
  this.error = error;
72
61
  }
73
62
  andThen(_f) {
74
63
  return this;
75
64
  }
76
- andThenAsync(_f) {
77
- return __awaiter(this, void 0, void 0, function* () {
78
- return this;
79
- });
65
+ async andThenAsync(_f) {
66
+ return this;
80
67
  }
81
68
  catchError(f) {
82
69
  return f(this.error);
83
70
  }
84
- catchErrorAsync(f) {
85
- return __awaiter(this, void 0, void 0, function* () {
86
- return yield f(this.error);
87
- });
71
+ async catchErrorAsync(f) {
72
+ return await f(this.error);
88
73
  }
89
74
  unwrapOrThrow(errorCallback) {
90
75
  if (errorCallback !== undefined) {
package/package.json CHANGED
@@ -1,10 +1,14 @@
1
1
  {
2
2
  "name": "@j2blasco/ts-result",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "Result Monad for TypeScript",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
- "files": ["dist", "README.md", "LICENSE"],
7
+ "files": [
8
+ "dist",
9
+ "README.md",
10
+ "LICENSE"
11
+ ],
8
12
  "scripts": {
9
13
  "test": "jest",
10
14
  "build": "tsc"
@@ -14,6 +18,7 @@
14
18
  "license": "MIT",
15
19
  "type": "module",
16
20
  "devDependencies": {
21
+ "@j2blasco/ts-pipe": "^0.0.3",
17
22
  "@types/jest": "^29.5.14",
18
23
  "jest": "^29.7.0",
19
24
  "ts-jest": "^29.3.2"