retuple 1.0.0-next.15 → 1.0.0-next.16

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.cjs CHANGED
@@ -12,45 +12,11 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
12
12
  };
13
13
  var _ResultAsync_inner, _a, _ResultRetry_f, _ResultRetry_promise, _ResultRetry_times, _ResultRetry_attempt, _ResultRetry_aborted, _ResultRetry_abort, _ResultRetry_getDelay, _ResultRetry_handler;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.RetupleArrayMethodUnavailableError = exports.RetupleInvalidUnionError = exports.RetupleCaughtValueError = exports.RetupleExpectFailed = exports.RetupleUnwrapErrFailed = exports.RetupleUnwrapFailed = exports.ResultLikeSymbol = void 0;
15
+ exports.RetupleArrayMethodUnavailableError = exports.RetupleInvalidUnionError = exports.RetupleCaughtValueError = exports.RetupleExpectFailed = exports.RetupleUnwrapErrFailed = exports.RetupleUnwrapFailed = void 0;
16
16
  exports.Result = Result;
17
17
  exports.Ok = Ok;
18
18
  exports.Err = Err;
19
- /**
20
- * ## Result Like Symbol
21
- *
22
- * Implement a custom result-like by implementing the `ResultLike` interface
23
- * on a class or object. An object with this implementation can be converted
24
- * to a `Result` and can be used in most places where a `Result` is required.
25
- *
26
- * ```ts
27
- * import { ResultLikeSymbol } from "retuple/symbol";
28
- * import { Result, Ok, Err, type ResultLike } from "retuple";
29
- *
30
- * class CustomResult<T> implements ResultLike<T, CustomError> {
31
- * value: T;
32
- *
33
- * constructor(value: T) {
34
- * this.value = value;
35
- * }
36
- *
37
- * [ResultLikeSymbol](): Result<T, CustomError> {
38
- * return this.value === "test"
39
- * ? Ok(this.value)
40
- * : Err(new CustomError("Value was not test"));
41
- * }
42
- * }
43
- *
44
- * const custom = new CustomResult("test");
45
- * const result: Result<string, Error> = Result(custom);
46
- *
47
- * const chain = Ok()
48
- * .$map(() => "value")
49
- * .$andThen((value) => new CustomResult(value))
50
- * .$or(myresult);
51
- * ```
52
- */
53
- exports.ResultLikeSymbol = Symbol("retuple/result");
19
+ const retuple_symbols_1 = require("retuple-symbols");
54
20
  /**
55
21
  * ## Retuple Unwrap Failed
56
22
  *
@@ -720,8 +686,8 @@ class ResultOk extends RetupleArray {
720
686
  this[0] = undefined;
721
687
  this[1] = value;
722
688
  }
723
- [exports.ResultLikeSymbol]() {
724
- return this;
689
+ [retuple_symbols_1.ResultLikeSymbol]() {
690
+ return { ok: true, value: this[1] };
725
691
  }
726
692
  toJSON() {
727
693
  return this[1];
@@ -833,8 +799,8 @@ class ResultErr extends RetupleArray {
833
799
  this[0] = err;
834
800
  this[1] = undefined;
835
801
  }
836
- [exports.ResultLikeSymbol]() {
837
- return this;
802
+ [retuple_symbols_1.ResultLikeSymbol]() {
803
+ return { ok: false, value: this[0] };
838
804
  }
839
805
  toJSON() {
840
806
  return null;
@@ -1352,7 +1318,11 @@ _a = ResultRetry, _ResultRetry_f = new WeakMap(), _ResultRetry_promise = new Wea
1352
1318
  ResultRetry.MAX_TIMEOUT = 3600000;
1353
1319
  ResultRetry.MAX_RETRY = 100;
1354
1320
  function asResult(resultLike) {
1355
- return resultLike[exports.ResultLikeSymbol]();
1321
+ if (resultLike instanceof ResultOk || resultLike instanceof ResultErr) {
1322
+ return resultLike;
1323
+ }
1324
+ const result = resultLike[retuple_symbols_1.ResultLikeSymbol]();
1325
+ return result.ok ? new ResultOk(result.value) : new ResultErr(result.value);
1356
1326
  }
1357
1327
  function ensureError(err) {
1358
1328
  if (err instanceof Error) {
package/dist/index.d.cts CHANGED
@@ -1,42 +1,4 @@
1
- /**
2
- * ## Result Like Symbol
3
- *
4
- * Implement a custom result-like by implementing the `ResultLike` interface
5
- * on a class or object. An object with this implementation can be converted
6
- * to a `Result` and can be used in most places where a `Result` is required.
7
- *
8
- * ```ts
9
- * import { ResultLikeSymbol } from "retuple/symbol";
10
- * import { Result, Ok, Err, type ResultLike } from "retuple";
11
- *
12
- * class CustomResult<T> implements ResultLike<T, CustomError> {
13
- * value: T;
14
- *
15
- * constructor(value: T) {
16
- * this.value = value;
17
- * }
18
- *
19
- * [ResultLikeSymbol](): Result<T, CustomError> {
20
- * return this.value === "test"
21
- * ? Ok(this.value)
22
- * : Err(new CustomError("Value was not test"));
23
- * }
24
- * }
25
- *
26
- * const custom = new CustomResult("test");
27
- * const result: Result<string, Error> = Result(custom);
28
- *
29
- * const chain = Ok()
30
- * .$map(() => "value")
31
- * .$andThen((value) => new CustomResult(value))
32
- * .$or(myresult);
33
- * ```
34
- */
35
- export declare const ResultLikeSymbol: unique symbol;
36
- export type ResultLikeSymbol = typeof ResultLikeSymbol;
37
- export type ResultLike<T, E> = {
38
- [ResultLikeSymbol](): Result<T, E>;
39
- };
1
+ import { type ResultLike } from "retuple-symbols";
40
2
  export type Ok = typeof Ok;
41
3
  export type Err = typeof Err;
42
4
  export type Result<T, E> = (OkTuple<T> | ErrTuple<E>) & Retuple<T, E>;
package/dist/index.d.ts CHANGED
@@ -1,42 +1,4 @@
1
- /**
2
- * ## Result Like Symbol
3
- *
4
- * Implement a custom result-like by implementing the `ResultLike` interface
5
- * on a class or object. An object with this implementation can be converted
6
- * to a `Result` and can be used in most places where a `Result` is required.
7
- *
8
- * ```ts
9
- * import { ResultLikeSymbol } from "retuple/symbol";
10
- * import { Result, Ok, Err, type ResultLike } from "retuple";
11
- *
12
- * class CustomResult<T> implements ResultLike<T, CustomError> {
13
- * value: T;
14
- *
15
- * constructor(value: T) {
16
- * this.value = value;
17
- * }
18
- *
19
- * [ResultLikeSymbol](): Result<T, CustomError> {
20
- * return this.value === "test"
21
- * ? Ok(this.value)
22
- * : Err(new CustomError("Value was not test"));
23
- * }
24
- * }
25
- *
26
- * const custom = new CustomResult("test");
27
- * const result: Result<string, Error> = Result(custom);
28
- *
29
- * const chain = Ok()
30
- * .$map(() => "value")
31
- * .$andThen((value) => new CustomResult(value))
32
- * .$or(myresult);
33
- * ```
34
- */
35
- export declare const ResultLikeSymbol: unique symbol;
36
- export type ResultLikeSymbol = typeof ResultLikeSymbol;
37
- export type ResultLike<T, E> = {
38
- [ResultLikeSymbol](): Result<T, E>;
39
- };
1
+ import { type ResultLike } from "retuple-symbols";
40
2
  export type Ok = typeof Ok;
41
3
  export type Err = typeof Err;
42
4
  export type Result<T, E> = (OkTuple<T> | ErrTuple<E>) & Retuple<T, E>;
package/dist/index.js CHANGED
@@ -10,41 +10,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
12
  var _ResultAsync_inner, _a, _ResultRetry_f, _ResultRetry_promise, _ResultRetry_times, _ResultRetry_attempt, _ResultRetry_aborted, _ResultRetry_abort, _ResultRetry_getDelay, _ResultRetry_handler;
13
- /**
14
- * ## Result Like Symbol
15
- *
16
- * Implement a custom result-like by implementing the `ResultLike` interface
17
- * on a class or object. An object with this implementation can be converted
18
- * to a `Result` and can be used in most places where a `Result` is required.
19
- *
20
- * ```ts
21
- * import { ResultLikeSymbol } from "retuple/symbol";
22
- * import { Result, Ok, Err, type ResultLike } from "retuple";
23
- *
24
- * class CustomResult<T> implements ResultLike<T, CustomError> {
25
- * value: T;
26
- *
27
- * constructor(value: T) {
28
- * this.value = value;
29
- * }
30
- *
31
- * [ResultLikeSymbol](): Result<T, CustomError> {
32
- * return this.value === "test"
33
- * ? Ok(this.value)
34
- * : Err(new CustomError("Value was not test"));
35
- * }
36
- * }
37
- *
38
- * const custom = new CustomResult("test");
39
- * const result: Result<string, Error> = Result(custom);
40
- *
41
- * const chain = Ok()
42
- * .$map(() => "value")
43
- * .$andThen((value) => new CustomResult(value))
44
- * .$or(myresult);
45
- * ```
46
- */
47
- export const ResultLikeSymbol = Symbol("retuple/result");
13
+ import { ResultLikeSymbol, } from "retuple-symbols";
48
14
  /**
49
15
  * ## Retuple Unwrap Failed
50
16
  *
@@ -709,7 +675,7 @@ class ResultOk extends RetupleArray {
709
675
  this[1] = value;
710
676
  }
711
677
  [ResultLikeSymbol]() {
712
- return this;
678
+ return { ok: true, value: this[1] };
713
679
  }
714
680
  toJSON() {
715
681
  return this[1];
@@ -822,7 +788,7 @@ class ResultErr extends RetupleArray {
822
788
  this[1] = undefined;
823
789
  }
824
790
  [ResultLikeSymbol]() {
825
- return this;
791
+ return { ok: false, value: this[0] };
826
792
  }
827
793
  toJSON() {
828
794
  return null;
@@ -1340,7 +1306,11 @@ _a = ResultRetry, _ResultRetry_f = new WeakMap(), _ResultRetry_promise = new Wea
1340
1306
  ResultRetry.MAX_TIMEOUT = 3600000;
1341
1307
  ResultRetry.MAX_RETRY = 100;
1342
1308
  function asResult(resultLike) {
1343
- return resultLike[ResultLikeSymbol]();
1309
+ if (resultLike instanceof ResultOk || resultLike instanceof ResultErr) {
1310
+ return resultLike;
1311
+ }
1312
+ const result = resultLike[ResultLikeSymbol]();
1313
+ return result.ok ? new ResultOk(result.value) : new ResultErr(result.value);
1344
1314
  }
1345
1315
  function ensureError(err) {
1346
1316
  if (err instanceof Error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "retuple",
3
- "version": "1.0.0-next.15",
3
+ "version": "1.0.0-next.16",
4
4
  "scripts": {
5
5
  "test": "vitest",
6
6
  "lint": "eslint . --ext .ts -c eslint.config.mjs --fix",
@@ -27,16 +27,19 @@
27
27
  "type": "git",
28
28
  "url": "git+https://github.com/traverse1984/retuple.git"
29
29
  },
30
+ "dependencies": {
31
+ "retuple-symbols": "^1.0.0-next.2"
32
+ },
30
33
  "devDependencies": {
31
- "typescript": "^5.9.2",
32
- "zshy": "^0.4.1",
33
- "vitest": "^3.2.4",
34
+ "@typescript-eslint/eslint-plugin": "^8.43.0",
35
+ "@typescript-eslint/parser": "^8.43.0",
34
36
  "@vitest/coverage-v8": "^3.2.4",
35
37
  "eslint": "^9.35.0",
36
38
  "eslint-config-prettier": "^10.1.8",
37
39
  "eslint-plugin-prettier": "^5.5.4",
38
- "@typescript-eslint/eslint-plugin": "^8.43.0",
39
- "@typescript-eslint/parser": "^8.43.0"
40
+ "typescript": "^5.9.2",
41
+ "vitest": "^3.2.4",
42
+ "zshy": "^0.4.1"
40
43
  },
41
44
  "exports": {
42
45
  ".": {