retuple 1.0.0-next.14 → 1.0.0-next.15
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 +39 -5
- package/dist/index.d.cts +41 -6
- package/dist/index.d.ts +41 -6
- package/dist/index.js +35 -1
- package/package.json +2 -12
- package/dist/symbol.cjs +0 -38
- package/dist/symbol.d.cts +0 -36
- package/dist/symbol.d.ts +0 -36
- package/dist/symbol.js +0 -35
package/dist/index.cjs
CHANGED
|
@@ -12,11 +12,45 @@ 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 = void 0;
|
|
15
|
+
exports.RetupleArrayMethodUnavailableError = exports.RetupleInvalidUnionError = exports.RetupleCaughtValueError = exports.RetupleExpectFailed = exports.RetupleUnwrapErrFailed = exports.RetupleUnwrapFailed = exports.ResultLikeSymbol = void 0;
|
|
16
16
|
exports.Result = Result;
|
|
17
17
|
exports.Ok = Ok;
|
|
18
18
|
exports.Err = Err;
|
|
19
|
-
|
|
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");
|
|
20
54
|
/**
|
|
21
55
|
* ## Retuple Unwrap Failed
|
|
22
56
|
*
|
|
@@ -686,7 +720,7 @@ class ResultOk extends RetupleArray {
|
|
|
686
720
|
this[0] = undefined;
|
|
687
721
|
this[1] = value;
|
|
688
722
|
}
|
|
689
|
-
[
|
|
723
|
+
[exports.ResultLikeSymbol]() {
|
|
690
724
|
return this;
|
|
691
725
|
}
|
|
692
726
|
toJSON() {
|
|
@@ -799,7 +833,7 @@ class ResultErr extends RetupleArray {
|
|
|
799
833
|
this[0] = err;
|
|
800
834
|
this[1] = undefined;
|
|
801
835
|
}
|
|
802
|
-
[
|
|
836
|
+
[exports.ResultLikeSymbol]() {
|
|
803
837
|
return this;
|
|
804
838
|
}
|
|
805
839
|
toJSON() {
|
|
@@ -1318,7 +1352,7 @@ _a = ResultRetry, _ResultRetry_f = new WeakMap(), _ResultRetry_promise = new Wea
|
|
|
1318
1352
|
ResultRetry.MAX_TIMEOUT = 3600000;
|
|
1319
1353
|
ResultRetry.MAX_RETRY = 100;
|
|
1320
1354
|
function asResult(resultLike) {
|
|
1321
|
-
return resultLike[
|
|
1355
|
+
return resultLike[exports.ResultLikeSymbol]();
|
|
1322
1356
|
}
|
|
1323
1357
|
function ensureError(err) {
|
|
1324
1358
|
if (err instanceof Error) {
|
package/dist/index.d.cts
CHANGED
|
@@ -1,10 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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;
|
|
5
37
|
export type ResultLike<T, E> = {
|
|
6
38
|
[ResultLikeSymbol](): Result<T, E>;
|
|
7
39
|
};
|
|
40
|
+
export type Ok = typeof Ok;
|
|
41
|
+
export type Err = typeof Err;
|
|
42
|
+
export type Result<T, E> = (OkTuple<T> | ErrTuple<E>) & Retuple<T, E>;
|
|
8
43
|
export { type ResultAsync, type ResultRetry };
|
|
9
44
|
export interface ResultRetryController<E> {
|
|
10
45
|
error: E;
|
|
@@ -78,8 +113,8 @@ export declare class RetupleArrayMethodUnavailableError extends Error {
|
|
|
78
113
|
*/
|
|
79
114
|
export declare function Result<T, E>(resultLike: ResultLike<T, E>): Result<T, E>;
|
|
80
115
|
export declare namespace Result {
|
|
81
|
-
var Ok: typeof import("
|
|
82
|
-
var Err: typeof import("
|
|
116
|
+
var Ok: typeof import(".").Ok;
|
|
117
|
+
var Err: typeof import(".").Err;
|
|
83
118
|
var $from: <T, E>(result: ResultLike<T, E>) => Result<T, E>;
|
|
84
119
|
var $resolve: <T, E>(result: ResultLikeAwaitable<T, E>) => ResultAsync<T, E>;
|
|
85
120
|
var $nonNullable: {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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;
|
|
5
37
|
export type ResultLike<T, E> = {
|
|
6
38
|
[ResultLikeSymbol](): Result<T, E>;
|
|
7
39
|
};
|
|
40
|
+
export type Ok = typeof Ok;
|
|
41
|
+
export type Err = typeof Err;
|
|
42
|
+
export type Result<T, E> = (OkTuple<T> | ErrTuple<E>) & Retuple<T, E>;
|
|
8
43
|
export { type ResultAsync, type ResultRetry };
|
|
9
44
|
export interface ResultRetryController<E> {
|
|
10
45
|
error: E;
|
|
@@ -78,8 +113,8 @@ export declare class RetupleArrayMethodUnavailableError extends Error {
|
|
|
78
113
|
*/
|
|
79
114
|
export declare function Result<T, E>(resultLike: ResultLike<T, E>): Result<T, E>;
|
|
80
115
|
export declare namespace Result {
|
|
81
|
-
var Ok: typeof import("
|
|
82
|
-
var Err: typeof import("
|
|
116
|
+
var Ok: typeof import(".").Ok;
|
|
117
|
+
var Err: typeof import(".").Err;
|
|
83
118
|
var $from: <T, E>(result: ResultLike<T, E>) => Result<T, E>;
|
|
84
119
|
var $resolve: <T, E>(result: ResultLikeAwaitable<T, E>) => ResultAsync<T, E>;
|
|
85
120
|
var $nonNullable: {
|
package/dist/index.js
CHANGED
|
@@ -10,7 +10,41 @@ 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
|
-
|
|
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");
|
|
14
48
|
/**
|
|
15
49
|
* ## Retuple Unwrap Failed
|
|
16
50
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "retuple",
|
|
3
|
-
"version": "1.0.0-next.
|
|
3
|
+
"version": "1.0.0-next.15",
|
|
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",
|
|
@@ -48,11 +43,6 @@
|
|
|
48
43
|
"types": "./dist/index.d.cts",
|
|
49
44
|
"import": "./dist/index.js",
|
|
50
45
|
"require": "./dist/index.cjs"
|
|
51
|
-
},
|
|
52
|
-
"./symbol": {
|
|
53
|
-
"types": "./dist/symbol.d.cts",
|
|
54
|
-
"import": "./dist/symbol.js",
|
|
55
|
-
"require": "./dist/symbol.cjs"
|
|
56
46
|
}
|
|
57
47
|
},
|
|
58
48
|
"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");
|