retuple 1.0.0-next.14 → 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
@@ -16,7 +16,7 @@ exports.RetupleArrayMethodUnavailableError = exports.RetupleInvalidUnionError =
16
16
  exports.Result = Result;
17
17
  exports.Ok = Ok;
18
18
  exports.Err = Err;
19
- const symbol_js_1 = require("./symbol.cjs");
19
+ const retuple_symbols_1 = require("retuple-symbols");
20
20
  /**
21
21
  * ## Retuple Unwrap Failed
22
22
  *
@@ -686,8 +686,8 @@ class ResultOk extends RetupleArray {
686
686
  this[0] = undefined;
687
687
  this[1] = value;
688
688
  }
689
- [symbol_js_1.ResultLikeSymbol]() {
690
- return this;
689
+ [retuple_symbols_1.ResultLikeSymbol]() {
690
+ return { ok: true, value: this[1] };
691
691
  }
692
692
  toJSON() {
693
693
  return this[1];
@@ -799,8 +799,8 @@ class ResultErr extends RetupleArray {
799
799
  this[0] = err;
800
800
  this[1] = undefined;
801
801
  }
802
- [symbol_js_1.ResultLikeSymbol]() {
803
- return this;
802
+ [retuple_symbols_1.ResultLikeSymbol]() {
803
+ return { ok: false, value: this[0] };
804
804
  }
805
805
  toJSON() {
806
806
  return null;
@@ -1318,7 +1318,11 @@ _a = ResultRetry, _ResultRetry_f = new WeakMap(), _ResultRetry_promise = new Wea
1318
1318
  ResultRetry.MAX_TIMEOUT = 3600000;
1319
1319
  ResultRetry.MAX_RETRY = 100;
1320
1320
  function asResult(resultLike) {
1321
- return resultLike[symbol_js_1.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);
1322
1326
  }
1323
1327
  function ensureError(err) {
1324
1328
  if (err instanceof Error) {
package/dist/index.d.cts CHANGED
@@ -1,10 +1,7 @@
1
- import { ResultLikeSymbol } from "./symbol.cjs";
1
+ import { type ResultLike } from "retuple-symbols";
2
2
  export type Ok = typeof Ok;
3
3
  export type Err = typeof Err;
4
4
  export type Result<T, E> = (OkTuple<T> | ErrTuple<E>) & Retuple<T, E>;
5
- export type ResultLike<T, E> = {
6
- [ResultLikeSymbol](): Result<T, E>;
7
- };
8
5
  export { type ResultAsync, type ResultRetry };
9
6
  export interface ResultRetryController<E> {
10
7
  error: E;
@@ -78,8 +75,8 @@ export declare class RetupleArrayMethodUnavailableError extends Error {
78
75
  */
79
76
  export declare function Result<T, E>(resultLike: ResultLike<T, E>): Result<T, E>;
80
77
  export declare namespace Result {
81
- var Ok: typeof import("./index.js").Ok;
82
- var Err: typeof import("./index.js").Err;
78
+ var Ok: typeof import(".").Ok;
79
+ var Err: typeof import(".").Err;
83
80
  var $from: <T, E>(result: ResultLike<T, E>) => Result<T, E>;
84
81
  var $resolve: <T, E>(result: ResultLikeAwaitable<T, E>) => ResultAsync<T, E>;
85
82
  var $nonNullable: {
package/dist/index.d.ts CHANGED
@@ -1,10 +1,7 @@
1
- import { ResultLikeSymbol } from "./symbol.js";
1
+ import { type ResultLike } from "retuple-symbols";
2
2
  export type Ok = typeof Ok;
3
3
  export type Err = typeof Err;
4
4
  export type Result<T, E> = (OkTuple<T> | ErrTuple<E>) & Retuple<T, E>;
5
- export type ResultLike<T, E> = {
6
- [ResultLikeSymbol](): Result<T, E>;
7
- };
8
5
  export { type ResultAsync, type ResultRetry };
9
6
  export interface ResultRetryController<E> {
10
7
  error: E;
@@ -78,8 +75,8 @@ export declare class RetupleArrayMethodUnavailableError extends Error {
78
75
  */
79
76
  export declare function Result<T, E>(resultLike: ResultLike<T, E>): Result<T, E>;
80
77
  export declare namespace Result {
81
- var Ok: typeof import("./index.js").Ok;
82
- var Err: typeof import("./index.js").Err;
78
+ var Ok: typeof import(".").Ok;
79
+ var Err: typeof import(".").Err;
83
80
  var $from: <T, E>(result: ResultLike<T, E>) => Result<T, E>;
84
81
  var $resolve: <T, E>(result: ResultLikeAwaitable<T, E>) => ResultAsync<T, E>;
85
82
  var $nonNullable: {
package/dist/index.js CHANGED
@@ -10,7 +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
- import { ResultLikeSymbol } from "./symbol.js";
13
+ import { ResultLikeSymbol, } from "retuple-symbols";
14
14
  /**
15
15
  * ## Retuple Unwrap Failed
16
16
  *
@@ -675,7 +675,7 @@ class ResultOk extends RetupleArray {
675
675
  this[1] = value;
676
676
  }
677
677
  [ResultLikeSymbol]() {
678
- return this;
678
+ return { ok: true, value: this[1] };
679
679
  }
680
680
  toJSON() {
681
681
  return this[1];
@@ -788,7 +788,7 @@ class ResultErr extends RetupleArray {
788
788
  this[1] = undefined;
789
789
  }
790
790
  [ResultLikeSymbol]() {
791
- return this;
791
+ return { ok: false, value: this[0] };
792
792
  }
793
793
  toJSON() {
794
794
  return null;
@@ -1306,7 +1306,11 @@ _a = ResultRetry, _ResultRetry_f = new WeakMap(), _ResultRetry_promise = new Wea
1306
1306
  ResultRetry.MAX_TIMEOUT = 3600000;
1307
1307
  ResultRetry.MAX_RETRY = 100;
1308
1308
  function asResult(resultLike) {
1309
- 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);
1310
1314
  }
1311
1315
  function ensureError(err) {
1312
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.14",
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",
@@ -11,12 +11,7 @@
11
11
  "main": "./dist/index.cjs",
12
12
  "types": "./dist/index.d.cts",
13
13
  "module": "./dist/index.js",
14
- "zshy": {
15
- "exports": {
16
- ".": "./src/index.ts",
17
- "./symbol": "./src/symbol.ts"
18
- }
19
- },
14
+ "zshy": "./src/index.ts",
20
15
  "keywords": [
21
16
  "result",
22
17
  "safe",
@@ -32,27 +27,25 @@
32
27
  "type": "git",
33
28
  "url": "git+https://github.com/traverse1984/retuple.git"
34
29
  },
30
+ "dependencies": {
31
+ "retuple-symbols": "^1.0.0-next.2"
32
+ },
35
33
  "devDependencies": {
36
- "typescript": "^5.9.2",
37
- "zshy": "^0.4.1",
38
- "vitest": "^3.2.4",
34
+ "@typescript-eslint/eslint-plugin": "^8.43.0",
35
+ "@typescript-eslint/parser": "^8.43.0",
39
36
  "@vitest/coverage-v8": "^3.2.4",
40
37
  "eslint": "^9.35.0",
41
38
  "eslint-config-prettier": "^10.1.8",
42
39
  "eslint-plugin-prettier": "^5.5.4",
43
- "@typescript-eslint/eslint-plugin": "^8.43.0",
44
- "@typescript-eslint/parser": "^8.43.0"
40
+ "typescript": "^5.9.2",
41
+ "vitest": "^3.2.4",
42
+ "zshy": "^0.4.1"
45
43
  },
46
44
  "exports": {
47
45
  ".": {
48
46
  "types": "./dist/index.d.cts",
49
47
  "import": "./dist/index.js",
50
48
  "require": "./dist/index.cjs"
51
- },
52
- "./symbol": {
53
- "types": "./dist/symbol.d.cts",
54
- "import": "./dist/symbol.js",
55
- "require": "./dist/symbol.cjs"
56
49
  }
57
50
  },
58
51
  "files": [
package/dist/symbol.cjs DELETED
@@ -1,38 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ResultLikeSymbol = void 0;
4
- /**
5
- * ## Result Like Symbol
6
- *
7
- * Implement a custom result-like by implementing the `ResultLike` interface
8
- * on a class or object. An object with this implementation can be converted
9
- * to a `Result` and can be used in most places where a `Result` is required.
10
- *
11
- * ```ts
12
- * import { ResultLikeSymbol } from "retuple/symbol";
13
- * import { Result, Ok, Err, type ResultLike } from "retuple";
14
- *
15
- * class CustomResult<T> implements ResultLike<T, CustomError> {
16
- * value: T;
17
- *
18
- * constructor(value: T) {
19
- * this.value = value;
20
- * }
21
- *
22
- * [ResultLikeSymbol](): Result<T, CustomError> {
23
- * return this.value === "test"
24
- * ? Ok(this.value)
25
- * : Err(new CustomError("Value was not test"));
26
- * }
27
- * }
28
- *
29
- * const custom = new CustomResult("test");
30
- * const result: Result<string, Error> = Result(custom);
31
- *
32
- * const chain = Ok()
33
- * .$map(() => "value")
34
- * .$andThen((value) => new CustomResult(value))
35
- * .$or(myresult);
36
- * ```
37
- */
38
- exports.ResultLikeSymbol = Symbol("retuple/result");
package/dist/symbol.d.cts DELETED
@@ -1,36 +0,0 @@
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;
package/dist/symbol.d.ts DELETED
@@ -1,36 +0,0 @@
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;
package/dist/symbol.js DELETED
@@ -1,35 +0,0 @@
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 const ResultLikeSymbol = Symbol("retuple/result");