resultar 1.1.5 → 1.2.0
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 +75 -0
- package/dist/{chunk-UPMJ4PST.js → chunk-BSNOKGZS.js} +41 -5
- package/dist/chunk-BSNOKGZS.js.map +1 -0
- package/dist/{chunk-3NDPPYVV.js → chunk-VBI3T5VS.js} +2 -1
- package/dist/chunk-VBI3T5VS.js.map +1 -0
- package/dist/error.cjs +1 -0
- package/dist/error.cjs.map +1 -1
- package/dist/error.d.cts +1 -1
- package/dist/error.d.ts +1 -1
- package/dist/error.js +1 -1
- package/dist/{index-CKLj0kyj.d.cts → index-CV4S5Ys9.d.cts} +54 -3
- package/dist/{index-CKLj0kyj.d.ts → index-CV4S5Ys9.d.ts} +54 -3
- package/dist/index.cjs +44 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +8 -4
- package/dist/result-async.cjs +42 -5
- package/dist/result-async.cjs.map +1 -1
- package/dist/result-async.d.cts +1 -1
- package/dist/result-async.d.ts +1 -1
- package/dist/result-async.js +6 -4
- package/dist/result.cjs +42 -5
- package/dist/result.cjs.map +1 -1
- package/dist/result.d.cts +1 -1
- package/dist/result.d.ts +1 -1
- package/dist/result.js +6 -4
- package/dist/utils.cjs +38 -3
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +2 -2
- package/package.json +29 -20
- package/dist/chunk-3NDPPYVV.js.map +0 -1
- package/dist/chunk-UPMJ4PST.js.map +0 -1
package/README.md
CHANGED
|
@@ -28,6 +28,7 @@ For asynchronous tasks, `resultar` offers a `ResultAsync` class which wraps a `P
|
|
|
28
28
|
+ [Synchronous API (`Result`)](#synchronous-api-result)
|
|
29
29
|
- [`ok`](#ok)
|
|
30
30
|
- [`err`](#err)
|
|
31
|
+
- [`unit`](#unit)
|
|
31
32
|
- [`Result.isOk` (method)](#resultisok-method)
|
|
32
33
|
- [`Result.isErr` (method)](#resultiserr-method)
|
|
33
34
|
- [`Result.map` (method)](#resultmap-method)
|
|
@@ -38,6 +39,7 @@ For asynchronous tasks, `resultar` offers a `ResultAsync` class which wraps a `P
|
|
|
38
39
|
- [`Result.orElse` (method)](#resultorelse-method)
|
|
39
40
|
- [`Result.tap` (method)](#resulttap-method)
|
|
40
41
|
- [`Result.tapError` (method)](#resulttaperror-method)
|
|
42
|
+
- [`Result.log` (method)](#resultlog-method)
|
|
41
43
|
- [`Result.finally` (method)](#resultfinally-method)
|
|
42
44
|
- [`Result.match` (method)](#resultmatch-method)
|
|
43
45
|
- [`Result.asyncMap` (method)](#resultasyncmap-method)
|
|
@@ -48,6 +50,7 @@ For asynchronous tasks, `resultar` offers a `ResultAsync` class which wraps a `P
|
|
|
48
50
|
+ [Asynchronous API (`ResultAsync`)](#asynchronous-api-resultasync)
|
|
49
51
|
- [`okAsync`](#okasync)
|
|
50
52
|
- [`errAsync`](#errasync)
|
|
53
|
+
- [`unitAsync`](#unitasync)
|
|
51
54
|
- [`ResultAsync.fromPromise` (static class method)](#resultasyncfrompromise-static-class-method)
|
|
52
55
|
- [`ResultAsync.fromSafePromise` (static class method)](#resultasyncfromsafepromise-static-class-method)
|
|
53
56
|
- [`ResultAsync.fromThrowable` (static class method)](#resultasyncfromthrowable-static-class-method)
|
|
@@ -165,7 +168,17 @@ myResult.isErr() // true
|
|
|
165
168
|
```
|
|
166
169
|
|
|
167
170
|
[⬆️ Back to top](#toc)
|
|
171
|
+
---
|
|
172
|
+
|
|
173
|
+
#### `unit`
|
|
168
174
|
|
|
175
|
+
Returns a `Result` with a `value` of `undefined`.
|
|
176
|
+
|
|
177
|
+
**Signature:**
|
|
178
|
+
```typescript
|
|
179
|
+
unit(): Result<undefined, never> { ... }
|
|
180
|
+
```
|
|
181
|
+
[⬆️ Back to top](#toc)
|
|
169
182
|
---
|
|
170
183
|
|
|
171
184
|
#### `Result.isOk` (method)
|
|
@@ -717,6 +730,33 @@ myResult.isErr() // true
|
|
|
717
730
|
|
|
718
731
|
---
|
|
719
732
|
|
|
733
|
+
#### `unitAsync`
|
|
734
|
+
|
|
735
|
+
Constructs a `ResultAsync` with a `value` of `undefined`.
|
|
736
|
+
|
|
737
|
+
**Signature:**
|
|
738
|
+
|
|
739
|
+
```typescript
|
|
740
|
+
unit<E = never>(error: E): ResultAsync<undefined, E>
|
|
741
|
+
```
|
|
742
|
+
|
|
743
|
+
**Example:**
|
|
744
|
+
|
|
745
|
+
```typescript
|
|
746
|
+
import { errAsync } from 'resultar'
|
|
747
|
+
|
|
748
|
+
const myResultAsync =unitAsync() // instance of `ResultAsync`
|
|
749
|
+
|
|
750
|
+
const myResult = await myResultAsync // instance of `Err`
|
|
751
|
+
|
|
752
|
+
myResult.isOk() // false
|
|
753
|
+
myResult.value() // undefined
|
|
754
|
+
```
|
|
755
|
+
|
|
756
|
+
[⬆️ Back to top](#toc)
|
|
757
|
+
|
|
758
|
+
---
|
|
759
|
+
|
|
720
760
|
#### `ResultAsync.fromThrowable` (static class method)
|
|
721
761
|
|
|
722
762
|
Similar to [Result.fromThrowable](#resultfromthrowable-static-class-method), but for functions that return a `Promise`.
|
|
@@ -1072,6 +1112,41 @@ equal(value, "bar")
|
|
|
1072
1112
|
```
|
|
1073
1113
|
[⬆️ Back to top](#toc)
|
|
1074
1114
|
|
|
1115
|
+
---
|
|
1116
|
+
|
|
1117
|
+
---
|
|
1118
|
+
#### `Result.log` (method)
|
|
1119
|
+
|
|
1120
|
+
**Executes a side effect function with the `Ok` or `Err` value and returns the original `Result`.
|
|
1121
|
+
This method is useful for performing actions that do not modify the `Result` itself, such as logging or updating external state.**
|
|
1122
|
+
|
|
1123
|
+
**Signature:**
|
|
1124
|
+
```typescript
|
|
1125
|
+
class Result<T, E> {
|
|
1126
|
+
log(fn: (t?: T, e?: E) => void): this {
|
|
1127
|
+
```
|
|
1128
|
+
|
|
1129
|
+
**Example:**
|
|
1130
|
+
```typescript
|
|
1131
|
+
|
|
1132
|
+
const reader = ok(file) // content file is line 01
|
|
1133
|
+
|
|
1134
|
+
reader
|
|
1135
|
+
.log((value, error) => {
|
|
1136
|
+
console.log("Logging file content:", error ? error : value)
|
|
1137
|
+
})
|
|
1138
|
+
.map(it => it.content)
|
|
1139
|
+
.finally(_ => {
|
|
1140
|
+
console.info('Closing file handle')
|
|
1141
|
+
file.close()
|
|
1142
|
+
})
|
|
1143
|
+
.match((value) => {
|
|
1144
|
+
console.log(value) // print line 01
|
|
1145
|
+
}, (error) => {
|
|
1146
|
+
console.error("Oops, something went wrong", error)
|
|
1147
|
+
})
|
|
1148
|
+
```
|
|
1149
|
+
[⬆️ Back to top](#toc)
|
|
1075
1150
|
|
|
1076
1151
|
---
|
|
1077
1152
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createResultarError
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-VBI3T5VS.js";
|
|
4
4
|
|
|
5
5
|
// src/result.ts
|
|
6
6
|
var Ok = class {
|
|
@@ -47,9 +47,23 @@ var Result = class _Result {
|
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Creates a new `Result` instance representing a successful operation.
|
|
52
|
+
*
|
|
53
|
+
* @param {T} value - The value to be wrapped in the `Result` instance.
|
|
54
|
+
* @return {Result<T, E>} A new `Result` instance with the provided value.
|
|
55
|
+
*/
|
|
50
56
|
static ok(value) {
|
|
51
57
|
return new _Result(new Ok(value));
|
|
52
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* Creates a new `Result` instance representing a successful operation with an undefined value.
|
|
61
|
+
*
|
|
62
|
+
* @return {Result<undefined, E>} A new `Result` instance with an undefined value.
|
|
63
|
+
*/
|
|
64
|
+
static unit() {
|
|
65
|
+
return new _Result(new Ok(void 0));
|
|
66
|
+
}
|
|
53
67
|
static err(error) {
|
|
54
68
|
return new _Result(new Err(error));
|
|
55
69
|
}
|
|
@@ -192,7 +206,7 @@ var Result = class _Result {
|
|
|
192
206
|
return fnErr(this.error);
|
|
193
207
|
}
|
|
194
208
|
/**
|
|
195
|
-
* Performs a side effect
|
|
209
|
+
* Performs a side effect for the `Ok` or `Err` variant of `Result`.
|
|
196
210
|
*
|
|
197
211
|
* @param fn The function to apply an `OK` value
|
|
198
212
|
* @returns the result of applying `f` or an `Err` untouched
|
|
@@ -313,7 +327,7 @@ var DisposableResult = class {
|
|
|
313
327
|
this.finalizer(this.result.value, this.result.error);
|
|
314
328
|
}
|
|
315
329
|
};
|
|
316
|
-
var { ok, err, fromThrowable } = Result;
|
|
330
|
+
var { ok, err, fromThrowable, unit } = Result;
|
|
317
331
|
function safeTry(body) {
|
|
318
332
|
const n = body().next();
|
|
319
333
|
if (n instanceof Promise) {
|
|
@@ -333,9 +347,29 @@ var DisposableResultAsync = class {
|
|
|
333
347
|
}
|
|
334
348
|
};
|
|
335
349
|
var ResultAsync = class _ResultAsync {
|
|
350
|
+
/**
|
|
351
|
+
* Returns a ResultAsync instance that is immediately resolved with a Result.ok(value).
|
|
352
|
+
*
|
|
353
|
+
* @param {T} value - The value to be wrapped in a Result.ok.
|
|
354
|
+
* @return {ResultAsync<T, E>} A ResultAsync instance with the given value and error type E.
|
|
355
|
+
*/
|
|
336
356
|
static okAsync(value) {
|
|
337
357
|
return new _ResultAsync(Promise.resolve(Result.ok(value)));
|
|
338
358
|
}
|
|
359
|
+
/**
|
|
360
|
+
* Returns a ResultAsync that is immediately resolved with a Result.ok(undefined) value.
|
|
361
|
+
*
|
|
362
|
+
* @return {ResultAsync<undefined, E>} A ResultAsync instance with undefined as the value type and E as the error type.
|
|
363
|
+
*/
|
|
364
|
+
static unitAsync() {
|
|
365
|
+
return new _ResultAsync(Promise.resolve(Result.unit()));
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Returns a ResultAsync instance that is immediately resolved with a Result.err(error).
|
|
369
|
+
*
|
|
370
|
+
* @param {E} error - The error to be wrapped in a Result.err.
|
|
371
|
+
* @return {ResultAsync<T, E>} A ResultAsync instance with the given error and value type T.
|
|
372
|
+
*/
|
|
339
373
|
static errAsync(error) {
|
|
340
374
|
return new _ResultAsync(Promise.resolve(Result.err(error)));
|
|
341
375
|
}
|
|
@@ -530,7 +564,7 @@ var ResultAsync = class _ResultAsync {
|
|
|
530
564
|
return yield* await this.innerPromise.then((res) => res.safeUnwrap());
|
|
531
565
|
}
|
|
532
566
|
};
|
|
533
|
-
var { okAsync, errAsync, fromPromise, fromSafePromise } = ResultAsync;
|
|
567
|
+
var { okAsync, errAsync, fromPromise, fromSafePromise, unitAsync } = ResultAsync;
|
|
534
568
|
var fromThrowableAsync = ResultAsync.fromThrowable;
|
|
535
569
|
function safeTryAsync(body) {
|
|
536
570
|
return new ResultAsync(
|
|
@@ -590,6 +624,7 @@ export {
|
|
|
590
624
|
ok,
|
|
591
625
|
err,
|
|
592
626
|
fromThrowable,
|
|
627
|
+
unit,
|
|
593
628
|
safeTry,
|
|
594
629
|
DisposableResultAsync,
|
|
595
630
|
ResultAsync,
|
|
@@ -597,7 +632,8 @@ export {
|
|
|
597
632
|
errAsync,
|
|
598
633
|
fromPromise,
|
|
599
634
|
fromSafePromise,
|
|
635
|
+
unitAsync,
|
|
600
636
|
fromThrowableAsync,
|
|
601
637
|
safeTryAsync
|
|
602
638
|
};
|
|
603
|
-
//# sourceMappingURL=chunk-
|
|
639
|
+
//# sourceMappingURL=chunk-BSNOKGZS.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/result.ts","../src/result-async.ts","../src/utils.ts"],"sourcesContent":["import type { ErrorConfig } from './error.js'\nimport { createResultarError } from './error.js'\nimport { errAsync, ResultAsync } from './result-async.js'\nimport type { CombineResults, CombineResultsWithAllErrorsArray, InferErrTypes, InferOkTypes } from './utils.js'\nimport { combineResultList, combineResultListWithAllErrors } from './utils.js'\n\nclass Ok<T> {\n readonly ok = true\n constructor(public readonly value: T) {}\n}\n\nclass Err<E> {\n readonly ok = false\n constructor(public readonly error: E) {}\n}\n\n/**\n * A Result interface that is used to define the methods that are available on a\n * `Result` object.\n *\n * The immutability of the `Result` object is maintained by the interface.\n */\ninterface Resultable<T, E> {\n get value(): T\n get error(): E\n\n /**\n * Used to check if a `Result` is an `OK`\n *\n * @returns `true` if the result is an `OK` variant of Result\n */\n isOk(): boolean\n\n /**\n * Used to check if a `Result` is an `Err`\n *\n * @returns `true` if the result is an `Err` variant of Result\n */\n isErr(): boolean\n /**\n * Unwrap the `Ok` value, or return the default if there is an `Err`\n *\n * @param v the default value to return if there is an `Err`\n */\n\n unwrapOr<A>(defaultValue: A): T | A\n\n // safeUnwrap(): Generator<Result<never, E>, T>\n\n /**\n * **This method is unsafe, and should only be used in a test environments**\n *\n * Takes a `Result<T, E>` and returns a `T` when the result is an `Ok`, otherwise it throws a custom object.\n *\n * @param config\n */\n _unsafeUnwrap(config?: ErrorConfig): T\n\n /**\n * **This method is unsafe, and should only be used in a test environments**\n *\n * takes a `Result<T, E>` and returns a `E` when the result is an `Err`,\n * otherwise it throws a custom object.\n *\n * @param config\n */\n _unsafeUnwrapErr(config?: ErrorConfig): E\n}\n\n/**\n * A `Result` is a type that represents either success (`Ok`) or failure (`Err`).\n * It is often used to replace exceptions or `null` returns.\n * `Result` is often used to handle errors in a functional way.\n * The `Result` type is often used to handle errors in a functional way.\n */\nexport class Result<T, E> implements Resultable<T, E> {\n /**\n * Wraps a function with a try catch, creating a new function with the same\n * arguments but returning `Ok` if successful, `Err` if the function throws\n *\n * @param fn function to wrap with ok on success or err on failure\n * @param errorFn when an error is thrown, this will wrap the error result if provided\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n static fromThrowable<Fn extends (...args: readonly any[]) => unknown, E>(\n fn: Fn,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n errorFn?: (e: any) => E,\n ): (...args: Parameters<Fn>) => Result<ReturnType<Fn>, E> {\n return (...args) => {\n try {\n const result = fn(...args)\n return ok(result as ReturnType<Fn>)\n } catch (error) {\n if (errorFn) {\n return err(errorFn(error))\n }\n\n return err(error as E)\n }\n }\n }\n\n /**\n * Creates a new `Result` instance representing a successful operation.\n *\n * @param {T} value - The value to be wrapped in the `Result` instance.\n * @return {Result<T, E>} A new `Result` instance with the provided value.\n */\n static ok<T, E = never>(value: T): Result<T, E> {\n return new Result<T, E>(new Ok(value))\n }\n\n /**\n * Creates a new `Result` instance representing a successful operation with an undefined value.\n *\n * @return {Result<undefined, E>} A new `Result` instance with an undefined value.\n */\n static unit<E = never>(): Result<undefined, E> {\n return new Result<undefined, E>(new Ok(undefined))\n }\n\n static err<T = never, E = unknown>(error: E): Result<T, E> {\n return new Result<T, E>(new Err(error))\n }\n\n static combine<\n T extends readonly [Result<unknown, unknown>, ...Array<Result<unknown, unknown>>],\n >(resultList: T): CombineResults<T>\n static combine<T extends ReadonlyArray<Result<unknown, unknown>>>(\n resultList: T,\n ): CombineResults<T>\n static combine<\n T extends readonly [Result<unknown, unknown>, ...Array<Result<unknown, unknown>>],\n >(resultList: T): CombineResults<T> {\n return combineResultList(resultList) as CombineResults<T>\n }\n\n static combineWithAllErrors<\n T extends readonly [Result<unknown, unknown>, ...Array<Result<unknown, unknown>>],\n >(resultList: T): CombineResultsWithAllErrorsArray<T>\n static combineWithAllErrors<T extends ReadonlyArray<Result<unknown, unknown>>>(\n resultList: T,\n ): CombineResultsWithAllErrorsArray<T>\n static combineWithAllErrors<T extends ReadonlyArray<Result<unknown, unknown>>>(\n resultList: T,\n ): CombineResultsWithAllErrorsArray<T> {\n return combineResultListWithAllErrors(resultList) as CombineResultsWithAllErrorsArray<T>\n }\n\n readonly value: T\n readonly error: E\n\n private constructor(private readonly state: Ok<T> | Err<E>) {\n if (state.ok) {\n this.value = state.value\n this.error = undefined as E\n } else {\n this.error = state.error\n this.value = undefined as T\n }\n }\n\n /**\n * Used to check if a `Result` is an `OK`\n *\n * @returns `true` if the result is an `OK` variant of Result\n */\n isOk(): boolean {\n return this.state.ok\n }\n\n /**\n * Used to check if a `Result` is an `Err`\n *\n * @returns `true` if the result is an `Err` variant of Result\n */\n isErr(): boolean {\n return !this.state.ok\n }\n\n /**\n * Maps a `Result<T, E>` to `Result<U, E>`\n * by applying a function to a contained `Ok` value, leaving an `Err` value\n * untouched.\n *\n * @param f The function to apply an `OK` value\n * @returns the result of applying `f` or an `Err` untouched\n */\n map<X>(f: (t: T) => X): Result<X, E> {\n if (this.state.ok) {\n const value = f(this.value)\n return ok(value)\n }\n\n return err(this.error)\n }\n\n /**\n * Maps a `Result<T, E>` to `Result<T, F>` by applying a function to a\n * contained `Err` value, leaving an `Ok` value untouched.\n *\n * This function can be used to pass through a successful result while\n * handling an error.\n *\n * @param f a function to apply to the error `Err` value\n */\n mapErr<X>(fn: (t: E) => X): Result<T, X> {\n if (this.state.ok) {\n return ok(this.value)\n }\n\n return err(fn(this.error))\n }\n\n /**\n * Similar to `map` Except you must return a new `Result`.\n *\n * This is useful for when you need to do a subsequent computation using the\n * inner `T` value, but that computation might fail.\n * Additionally, `andThen` is really useful as a tool to flatten a\n * `Result<Result<A, E2>, E1>` into a `Result<A, E2>` (see example below).\n *\n * @param f The function to apply to the current value\n */\n andThen<X, Y>(f: (t: T) => Result<X, Y>): Result<X, E | Y> {\n if (this.state.ok) {\n return f(this.value)\n }\n\n return err(this.error)\n }\n\n if(fCondition: (t: T) => boolean) {\n return {\n true: <X1, Y1>(fTrue: (t: T) => Result<X1, Y1>) => ({\n false: <X2, Y2>(fFalse: (t: T) => Result<X2, Y2>): Result<X1 | X2, Y1 | Y2 | E> => {\n if (this.state.ok) {\n const condition = fCondition(this.value)\n return condition ? fTrue(this.value) : fFalse(this.value)\n }\n\n return err(this.error)\n },\n }),\n }\n }\n\n /**\n * Takes an `Err` value and maps it to a `Result<T, SomeNewType>`.\n *\n * This is useful for error recovery.\n *\n * @param f A function to apply to an `Err` value, leaving `Ok` values\n * untouched.\n */\n orElse<R extends Result<unknown, unknown>>(\n f: (e: E) => R,\n ): Result<InferOkTypes<R> | T, InferErrTypes<R>>\n orElse<U, A>(f: (e: E) => Result<U, A>): Result<U | T, A> {\n if (this.state.ok) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return ok(this.value as Exclude<T, Promise<any>>)\n }\n\n return f(this.error)\n }\n\n /**\n * Similar to `map` Except you must return a new `Result`.\n *\n * This is useful for when you need to do a subsequent async computation using\n * the inner `T` value, but that computation might fail. Must return a ResultAsync\n *\n * @param f The function that returns a `ResultAsync` to apply to the current\n * value\n */\n asyncAndThen<X, Y>(f: (t: T) => ResultAsync<X, Y>): ResultAsync<X, E | Y>\n asyncAndThen<X, Y>(f: (t: T) => ResultAsync<X, E>): ResultAsync<X, E | Y> {\n if (this.state.ok) {\n return f(this.value)\n }\n\n return errAsync(this.error)\n }\n\n /**\n * Maps a `Result<T, E>` to `ResultAsync<U, E>`\n * by applying an async function to a contained `Ok` value, leaving an `Err`\n * value untouched.\n *\n * @param f An async function to apply an `OK` value\n */\n asyncMap<X>(f: (t: T) => Promise<X>): ResultAsync<X, E> {\n if (this.state.ok) {\n return ResultAsync.fromSafePromise(f(this.value))\n }\n\n return errAsync(this.error)\n }\n\n /**\n * Unwrap the `Ok` value, or return the default if there is an `Err`\n *\n * @param v the default value to return if there is an `Err`\n */\n unwrapOr<A>(defaultValue: A): T | A {\n if (this.state.ok) {\n return this.value\n }\n\n return defaultValue\n }\n\n /**\n * Given 2 functions (one for the `Ok` variant and one for the `Err` variant)\n * execute the function that matches the `Result` variant.\n *\n * Match callbacks do not necessitate to return a `Result`, however you can\n * return a `Result` if you want to.\n *\n * `match` is like chaining `map` and `mapErr`, with the distinction that\n * with `match` both functions must have the same return type.\n *\n * @param ok\n * @param err\n */\n match<X>(fnOk: (t: T) => X, fnErr: (e: E) => X): X {\n if (this.state.ok) {\n return fnOk(this.value)\n }\n\n return fnErr(this.error)\n }\n\n /**\n * Performs a side effect for the `Ok` or `Err` variant of `Result`.\n *\n * @param fn The function to apply an `OK` value\n * @returns the result of applying `f` or an `Err` untouched\n */\n log(fn: (t?: T, e?: E) => void): this {\n try {\n fn(this.value, this.error)\n } catch { /* empty */ }\n\n return this\n }\n\n /**\n * Performs a side effect for the `Ok` variant of `Result`.\n *\n * @param fn The function to apply an `OK` value\n * @returns the result of applying `f` or an `Err` untouched\n */\n tap(fn: (t: T) => void): this {\n if (this.state.ok) {\n try {\n fn(this.value)\n } catch { /* empty */ }\n }\n\n return this\n }\n\n /**\n * Performs a side effect for the `Err` variant of `Result`.\n *\n * @param fn The function to apply an `Err` value\n * @returns the result of applying `f` or an `Ok` untouched\n */\n tapError(fn: (e: E) => void): this {\n if (!this.state.ok) {\n try {\n fn(this.error)\n } catch { /* empty */ }\n }\n\n return this\n }\n\n /**\n * This method is used to clean up and release any resources that the `Result`\n * @param f The function that will be called to clean up the resources\n */\n finally<X = T, Y = E>(f: (value: X, error: Y) => void): DisposableResult<X, Y>\n finally(f: (value: T, error: E) => void): DisposableResult<T, E> {\n const resultDisposable = new DisposableResult(this, f)\n try {\n return resultDisposable\n } finally {\n resultDisposable[Symbol.dispose]()\n }\n }\n\n /**\n * **This method is unsafe, and should only be used in a test environments**\n *\n * Takes a `Result<T, E>` and returns a `T` when the result is an `Ok`, otherwise it throws a custom object.\n *\n * @param config\n */\n _unsafeUnwrap(config?: ErrorConfig): T {\n if (this.state.ok) {\n return this.value\n }\n\n throw createResultarError('Called `_unsafeUnwrap` on an Err', this, config)\n }\n\n /**\n * **This method is unsafe, and should only be used in a test environments**\n *\n * takes a `Result<T, E>` and returns a `E` when the result is an `Err`,\n * otherwise it throws a custom object.\n *\n * @param config\n */\n _unsafeUnwrapErr(config?: ErrorConfig): E {\n if (this.state.ok) {\n throw createResultarError('Called `_unsafeUnwrapErr` on an Ok', this, config)\n }\n\n return this.error\n }\n\n safeUnwrap(): Generator<Result<never, E>, T> {\n if (this.state.ok) {\n const { value } = this\n /* eslint-disable-next-line require-yield */\n return (function*() {\n return value\n })()\n }\n\n const { error } = this\n return (function*() {\n yield err(error)\n\n throw new Error('Do not use this generator out of `safeTry`')\n })()\n }\n}\n\n/**\n * A `Disposable` is an object that has a `dispose` method that can be used to\n * clean up resources.\n */\nexport class DisposableResult<T, E> implements Resultable<T, E>, Disposable {\n constructor(readonly result: Resultable<T, E>, private readonly finalizer: (value: T, error: E) => void) {}\n\n get value(): T {\n return this.result.value\n }\n\n get error(): E {\n return this.result.error\n }\n\n _unsafeUnwrap(config?: ErrorConfig | undefined): T {\n return this.result._unsafeUnwrap(config)\n }\n\n _unsafeUnwrapErr(config?: ErrorConfig | undefined): E {\n return this.result._unsafeUnwrapErr(config)\n }\n\n isOk(): boolean {\n return this.result.isOk()\n }\n\n isErr(): boolean {\n return this.result.isErr()\n }\n\n unwrapOr<A>(defaultValue: A): T | A {\n return this.result.unwrapOr(defaultValue)\n }\n\n [Symbol.dispose](): void {\n this.finalizer(this.result.value, this.result.error)\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/unbound-method\nexport const { ok, err, fromThrowable, unit } = Result\n\n/**\n * Evaluates the given generator to a Result returned or an Err yielded from it,\n * whichever comes first.\n *\n * This function, in combination with `Result.safeUnwrap()`, is intended to emulate\n * Rust's ? operator.\n * See `/tests/safeTry.test.ts` for examples.\n *\n * @param body - What is evaluated. In body, `yield* result.safeUnwrap()` works as\n * Rust's `result?` expression.\n * @returns The first occurence of either an yielded Err or a returned Result.\n */\nexport function safeTry<T, E>(body: () => Generator<Result<never, E>, Result<T, E>>): Result<T, E>\n/**\n * Evaluates the given generator to a Result returned or an Err yielded from it,\n * whichever comes first.\n *\n * This function, in combination with `Result.safeUnwrap()`, is intended to emulate\n * Rust's ? operator.\n * See `/tests/safeTry.test.ts` for examples.\n *\n * @param body - What is evaluated. In body, `yield* result.safeUnwrap()` and\n * `yield* resultAsync.safeUnwrap()` work as Rust's `result?` expression.\n * @returns The first occurence of either an yielded Err or a returned Result.\n */\n// NOTE:\n// Since body is potentially throwable because `await` can be used in it,\n// Promise<Result<T, E>>, not ResultAsync<T, E>, is used as the return type.\nexport function safeTry<T, E>(\n body: () => AsyncGenerator<Result<never, E>, Result<T, E>>,\n): Promise<Result<T, E>>\nexport function safeTry<T, E>(\n body:\n | (() => Generator<Result<never, E>, Result<T, E>>)\n | (() => AsyncGenerator<Result<never, E>, Result<T, E>>),\n): Result<T, E> | Promise<Result<T, E>> {\n const n = body().next()\n if (n instanceof Promise) {\n return n.then(r => r.value)\n }\n\n return n.value\n}\n","import { Result } from './result.js'\nimport type {\n Combine,\n Dedup,\n EmptyArrayToNever,\n ExtractErrAsyncTypes,\n ExtractOkAsyncTypes,\n InferAsyncErrTypes,\n InferAsyncOkTypes,\n InferErrTypes,\n InferOkTypes,\n IsLiteralArray,\n MemberListOf,\n MembersToUnion,\n} from './utils.js'\nimport { combineResultAsyncList, combineResultAsyncListWithAllErrors } from './utils.js'\n\n// Combines the array of async results into one result.\nexport type CombineResultAsyncs<\n T extends ReadonlyArray<ResultAsync<unknown, unknown>>,\n> = IsLiteralArray<T> extends 1 ? TraverseAsync<UnwrapAsync<T>>\n : ResultAsync<ExtractOkAsyncTypes<T>, ExtractErrAsyncTypes<T>[number]>\n\n// Combines the array of async results into one result with all errors.\nexport type CombineResultsWithAllErrorsArrayAsync<\n T extends ReadonlyArray<ResultAsync<unknown, unknown>>,\n> = IsLiteralArray<T> extends 1 ? TraverseWithAllErrorsAsync<UnwrapAsync<T>>\n : ResultAsync<ExtractOkAsyncTypes<T>, Array<ExtractErrAsyncTypes<T>[number]>>\n\n// Unwraps the inner `Result` from a `ResultAsync` for all elements.\ntype UnwrapAsync<T> = IsLiteralArray<T> extends 1\n ? Writable<T> extends [infer H, ...infer Rest]\n ? H extends PromiseLike<infer HI> ? HI extends Result<unknown, unknown> ? [Dedup<HI>, ...UnwrapAsync<Rest>]\n : never\n : never\n : []\n // If we got something too general such as ResultAsync<X, Y>[] then we\n // simply need to map it to ResultAsync<X[], Y[]>. Yet `ResultAsync`\n // itself is a union therefore it would be enough to cast it to Ok.\n : T extends Array<infer A>\n ? A extends PromiseLike<infer HI> ? HI extends Result<infer L, infer R> ? Array<Result<L, R>>\n : never\n : never\n : never\n\n// Traverse through the tuples of the async results and create one\n// `ResultAsync` where the collected tuples are merged.\ntype TraverseAsync<T, Depth extends number = 5> = IsLiteralArray<T> extends 1\n ? Combine<T, Depth> extends [infer Oks, infer Errs] ? ResultAsync<EmptyArrayToNever<Oks>, MembersToUnion<Errs>>\n : never\n // The following check is important if we somehow reach to the point of\n // checking something similar to ResultAsync<X, Y>[]. In this case we don't\n // know the length of the elements, therefore we need to traverse the X and Y\n // in a way that the result should contain X[] and Y[].\n : T extends Array<infer I>\n // The MemberListOf<I> here is to include all possible types. Therefore\n // if we face (ResultAsync<X, Y> | ResultAsync<A, B>)[] this type should\n // handle the case.\n ? Combine<MemberListOf<I>, Depth> extends [infer Oks, infer Errs]\n // The following `extends unknown[]` checks are just to satisfy the TS.\n // we already expect them to be an array.\n ? Oks extends unknown[]\n ? Errs extends unknown[]\n ? ResultAsync<EmptyArrayToNever<Array<Oks[number]>>, MembersToUnion<Array<Errs[number]>>>\n : ResultAsync<EmptyArrayToNever<Array<Oks[number]>>, Errs>\n // The rest of the conditions are to satisfy the TS and support\n // the edge cases which are not really expected to happen.\n : Errs extends unknown[] ? ResultAsync<Oks, MembersToUnion<Array<Errs[number]>>>\n : ResultAsync<Oks, Errs>\n : never\n : never\n\n// This type is similar to the `TraverseAsync` while the errors are also\n// collected in order. For the checks/conditions made here, see that type\n// for the documentation.\ntype TraverseWithAllErrorsAsync<T, Depth extends number = 5> = IsLiteralArray<T> extends 1\n ? Combine<T, Depth> extends [infer Oks, infer Errs] ? ResultAsync<EmptyArrayToNever<Oks>, EmptyArrayToNever<Errs>>\n : never\n : Writable<T> extends Array<infer I>\n ? Combine<MemberListOf<I>, Depth> extends [infer Oks, infer Errs]\n ? Oks extends unknown[]\n ? Errs extends unknown[]\n ? ResultAsync<EmptyArrayToNever<Array<Oks[number]>>, EmptyArrayToNever<Array<Errs[number]>>>\n : ResultAsync<EmptyArrayToNever<Array<Oks[number]>>, Errs>\n : Errs extends unknown[] ? ResultAsync<Oks, EmptyArrayToNever<Array<Errs[number]>>>\n : ResultAsync<Oks, Errs>\n : never\n : never\n\n// Converts a reaodnly array into a writable array\ntype Writable<T> = T extends readonly unknown[] ? [...T] : T\n\nexport class DisposableResultAsync<T, E> implements PromiseLike<Result<T, E>> {\n private readonly innerPromise: Promise<Result<T, E>>\n\n constructor(res: Promise<Result<T, E>>) {\n this.innerPromise = res\n }\n\n then<A, B>( // eslint-disable-line unicorn/no-thenable\n successCallback?: (res: Result<T, E>) => A | PromiseLike<A>,\n failureCallback?: (reason: unknown) => B | PromiseLike<B>,\n ): PromiseLike<A | B> {\n return this.innerPromise.then(successCallback, failureCallback)\n }\n}\n\n/**\n * The ResultAsync type.\n * This is a union of `Result` and `PromiseLike<Result>`\n */\nexport class ResultAsync<T, E> implements PromiseLike<Result<T, E>> {\n /**\n * Returns a ResultAsync instance that is immediately resolved with a Result.ok(value).\n *\n * @param {T} value - The value to be wrapped in a Result.ok.\n * @return {ResultAsync<T, E>} A ResultAsync instance with the given value and error type E.\n */\n static okAsync<T, E = never>(value: T): ResultAsync<T, E> {\n return new ResultAsync<T, E>(Promise.resolve(Result.ok(value)))\n }\n\n /**\n * Returns a ResultAsync that is immediately resolved with a Result.ok(undefined) value.\n *\n * @return {ResultAsync<undefined, E>} A ResultAsync instance with undefined as the value type and E as the error type.\n */\n static unitAsync<E = never>(): ResultAsync<undefined, E> {\n return new ResultAsync<undefined, E>(Promise.resolve(Result.unit()))\n }\n\n /**\n * Returns a ResultAsync instance that is immediately resolved with a Result.err(error).\n *\n * @param {E} error - The error to be wrapped in a Result.err.\n * @return {ResultAsync<T, E>} A ResultAsync instance with the given error and value type T.\n */\n static errAsync<T = never, E = unknown>(error: E): ResultAsync<T, E> {\n return new ResultAsync<T, E>(Promise.resolve(Result.err(error)))\n }\n\n /**\n * Returns a ResultAsync instance that is resolved with a Result.ok(value) or Result.err(error)\n * based on the provided promise.\n *\n * @param {Promise<T>} promise - The promise to be wrapped in a ResultAsync.\n * @return {ResultAsync<T, E>} A ResultAsync instance with the given promise and error type E.\n */\n static fromSafePromise<T, E = never>(promise: PromiseLike<T>): ResultAsync<T, E>\n static fromSafePromise<T, E = never>(promise: Promise<T>): ResultAsync<T, E> {\n const newPromise = promise\n .then((value: T) => Result.ok(value))\n\n return new ResultAsync<T, E>(newPromise)\n }\n\n /**\n * Returns a ResultAsync instance that is resolved with a Result.ok(value) or Result.err(error)\n * based on the provided promise.\n *\n * @param {Promise<T>} promise - The promise to be wrapped in a ResultAsync.\n * @param {(e: unknown) => E} errorFn - A function that transforms the error from the promise into the error type E.\n * @return {ResultAsync<T, E>} A ResultAsync instance with the given promise and error type E.\n */\n static fromPromise<T, E>(promise: PromiseLike<T>, errorFn: (e: unknown) => E): ResultAsync<T, E>\n static fromPromise<T, E>(promise: Promise<T>, errorFn: (e: unknown) => E): ResultAsync<T, E> {\n const newPromise = promise\n .then((value: T) => Result.ok(value))\n .catch(error => Result.err(errorFn(error)))\n\n return new ResultAsync<T, E>(newPromise)\n }\n\n static combine<\n T extends readonly [ResultAsync<unknown, unknown>, ...Array<ResultAsync<unknown, unknown>>],\n >(asyncResultList: T): CombineResultAsyncs<T>\n static combine<T extends ReadonlyArray<ResultAsync<unknown, unknown>>>(\n asyncResultList: T,\n ): CombineResultAsyncs<T>\n static combine<T extends ReadonlyArray<ResultAsync<unknown, unknown>>>(\n asyncResultList: T,\n ): CombineResultAsyncs<T> {\n return (combineResultAsyncList(asyncResultList) as unknown) as CombineResultAsyncs<T>\n }\n\n static combineWithAllErrors<\n T extends readonly [ResultAsync<unknown, unknown>, ...Array<ResultAsync<unknown, unknown>>],\n >(asyncResultList: T): CombineResultsWithAllErrorsArrayAsync<T>\n static combineWithAllErrors<T extends ReadonlyArray<ResultAsync<unknown, unknown>>>(\n asyncResultList: T,\n ): CombineResultsWithAllErrorsArrayAsync<T>\n static combineWithAllErrors<T extends ReadonlyArray<ResultAsync<unknown, unknown>>>(\n asyncResultList: T,\n ): CombineResultsWithAllErrorsArrayAsync<T> {\n return combineResultAsyncListWithAllErrors(\n asyncResultList,\n ) as CombineResultsWithAllErrorsArrayAsync<T>\n }\n\n /**\n * Wraps a async function with a try catch, creating a new function with the same\n * arguments but returning `Ok` if successful, `Err` if the function throws\n *\n * @param fn function to wrap with ok on success or err on failure\n * @param errorFn when an error is thrown, this will wrap the error result if provided\n * @returns a new function that returns a `ResultAsync`\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n static fromThrowable<A extends readonly any[], T, E>(\n fn: (...args: A) => Promise<T>,\n errorFn?: (err: unknown) => E,\n ): (...args: A) => ResultAsync<T, E> {\n return (...args) =>\n new ResultAsync<T, E>(\n (async () => {\n try {\n const v = await fn(...args)\n return Result.ok(v)\n } catch (error) {\n const e = errorFn ? errorFn(error) : error\n return Result.err(e as E)\n }\n })(),\n )\n }\n\n private readonly innerPromise: Promise<Result<T, E>>\n\n constructor(res: Promise<Result<T, E>>) {\n this.innerPromise = res\n }\n\n then<A, B>( // eslint-disable-line unicorn/no-thenable\n successCallback?: (res: Result<T, E>) => A | PromiseLike<A>,\n failureCallback?: (reason: unknown) => B | PromiseLike<B>,\n ): PromiseLike<A | B> {\n return this.innerPromise.then(successCallback, failureCallback)\n }\n\n mapErr<U>(f: (t: E) => U | Promise<U>): ResultAsync<T, U> {\n return new ResultAsync<T, U>(this.innerPromise.then(async res => {\n if (res.isOk()) {\n return okAsync(res.value)\n }\n\n return errAsync(await f(res.error))\n }))\n }\n\n map<X>(f: (t: T) => X | Promise<X>): ResultAsync<X, E> {\n const x = new ResultAsync(\n this.innerPromise.then(async (res: Result<T, E>) => {\n if (res.isErr()) {\n return errAsync(res.error)\n }\n\n return okAsync(await f(res.value))\n }),\n )\n\n return x\n }\n\n andThen<R extends Result<unknown, unknown>>(\n f: (t: T) => R,\n ): ResultAsync<InferOkTypes<R>, InferErrTypes<R> | E>\n andThen<R extends ResultAsync<unknown, unknown>>(\n f: (t: T) => R,\n ): ResultAsync<InferAsyncOkTypes<R>, InferAsyncErrTypes<R> | E>\n andThen<U, F>(f: (t: T) => Result<U, F> | ResultAsync<U, F>): ResultAsync<U, E | F>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n andThen(f: any): any {\n return new ResultAsync(\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n this.innerPromise.then(async res => {\n if (res.isErr()) {\n return errAsync(res.error)\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call\n const newValue = f(res.value) // eslint-disable-line @typescript-eslint/no-unsafe-assignment\n return newValue instanceof ResultAsync ? newValue.innerPromise : newValue // eslint-disable-line @typescript-eslint/no-unsafe-return\n }),\n )\n }\n\n if(fCondition: (t: T) => boolean) {\n return {\n true: <X1, Y1>(fTrue: (t: T) => ResultAsync<X1, Y1>) => ({\n false: <X2, Y2>(fFalse: (t: T) => ResultAsync<X2, Y2>): ResultAsync<X1 | X2, Y1 | Y2 | E> =>\n new ResultAsync(this.innerPromise.then(async res => {\n if (res.isOk()) {\n const condition = fCondition(res.value)\n return condition ? fTrue(res.value) : fFalse(res.value)\n }\n\n return errAsync(res.error)\n })),\n }),\n }\n }\n\n orElse<R extends Result<unknown, unknown>>(\n f: (e: E) => R,\n ): ResultAsync<InferOkTypes<R> | T, InferErrTypes<R>>\n orElse<R extends ResultAsync<unknown, unknown>>(\n f: (e: E) => R,\n ): ResultAsync<InferAsyncOkTypes<R> | T, InferAsyncErrTypes<R>>\n orElse<U, A>(f: (e: E) => Result<U, A> | ResultAsync<U, A>): ResultAsync<U | T, A>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n orElse(f: any): any {\n return new ResultAsync(\n this.innerPromise.then(async (res: Result<T, E>) => { // eslint-disable-line @typescript-eslint/no-unsafe-argument\n if (res.isErr()) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call\n return f(res.error) // eslint-disable-line @typescript-eslint/no-unsafe-return\n }\n\n return okAsync(res.value)\n }),\n )\n }\n\n async match<X>(ok: (t: T) => X, err: (e: E) => X): Promise<X> {\n return this.innerPromise.then(res => res.match(ok, err))\n }\n\n async unwrapOr<A>(t: A): Promise<T | A> {\n return this.innerPromise.then(res => res.unwrapOr(t))\n }\n\n /**\n * Performs a side effect for the `Ok` variant of `ResultAsync`.\n * This function can be used for control flow based on result values.\n * @param f The function to call if the result is `Ok`\n * @returns `self` if the result is `Err`, otherwise the result of `f`\n */\n log(f: (t?: T, e?: E) => void | Promise<void>): ResultAsync<T, E> {\n return new ResultAsync(\n this.innerPromise.then(async res => {\n if (res.isOk()) {\n try {\n await f(res.value)\n } catch { /* empty */ }\n\n return okAsync(res.value)\n }\n\n try {\n await f(undefined, res.error)\n } catch { /* empty */ }\n\n return errAsync(res.error)\n }),\n )\n }\n\n /**\n * Performs a side effect for the `Ok` variant of `ResultAsync`.\n * This function can be used for control flow based on result values.\n * @param f The function to call if the result is `Ok`\n * @returns `self` if the result is `Err`, otherwise the result of `f`\n */\n tap(f: (t: T) => void | Promise<void>): ResultAsync<T, E> {\n return new ResultAsync(\n this.innerPromise.then(async res => {\n if (res.isErr()) {\n return errAsync(res.error)\n }\n\n try {\n await f(res.value)\n } catch { /* empty */ }\n\n return okAsync(res.value)\n }),\n )\n }\n\n /**\n * Performs a side effect for the `Err` variant of `ResultAsync`.\n * This function can be used for control flow based on result values.\n * @param f The function to call if the result is `Err`\n * @returns `self` if the result is `Ok`, otherwise the result of `f`\n * @example\n */\n tapError(f: (e: E) => void | Promise<void>): ResultAsync<T, E> {\n return new ResultAsync(\n this.innerPromise.then(async res => {\n if (res.isErr()) {\n try {\n await f(res.error)\n } catch { /* empty */ }\n\n return errAsync(res.error)\n }\n\n return okAsync(res.value)\n }),\n )\n }\n\n finally(f: (value: T, error: E) => void): DisposableResultAsync<T, E> {\n return new DisposableResultAsync(\n // eslint-disable-next-line @typescript-eslint/require-await\n this.innerPromise.then(async res => {\n try {\n res.finally(f)\n } catch {\n // Dont do anything. Its just a finally\n }\n\n return res\n }),\n )\n }\n\n /**\n * Emulates Rust's `?` operator in `safeTry`'s body. See also `safeTry`.\n */\n async *safeUnwrap(): AsyncGenerator<Result<never, E>, T> {\n return yield* await this.innerPromise.then(res => res.safeUnwrap())\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/unbound-method\nexport const { okAsync, errAsync, fromPromise, fromSafePromise, unitAsync } = ResultAsync\n// eslint-disable-next-line @typescript-eslint/unbound-method\nexport const fromThrowableAsync = ResultAsync.fromThrowable\n\n/**\n * Evaluates the given generator to a Result returned or an Err yielded from it,\n * whichever comes first.\n *\n * This function, in combination with `Result.safeUnwrap()`, is intended to emulate\n * Rust's ? operator.\n * See `/tests/safeTry.test.ts` for examples.\n *\n * @param body - What is evaluated. In body, `yield* result.safeUnwrap()` works as\n * Rust's `result?` expression.\n * @returns The first occurence of either an yielded Err or a returned `ResultAsync`.\n */\nexport function safeTryAsync<T, E>(\n body: () => AsyncGenerator<Result<never, E>, Result<T, E>>,\n): ResultAsync<T, E> {\n return new ResultAsync<T, E>(\n (async () => {\n const n = await body().next()\n if (n.value.isOk()) {\n return okAsync(n.value.value)\n }\n\n return errAsync(n.value.error)\n })(),\n )\n}\n","import { ResultAsync } from './result-async.js'\nimport type { Result } from './result.js'\nimport { err, ok } from './result.js'\n\n// Deduplicates the result, as the result type is a union of Err and Ok types.\nexport type Dedup<T> = T extends Result<infer RL, infer RR> ? Result<RL, RR>\n : T\n\n// Given a union, this gives the array of the union members.\nexport type MemberListOf<T> = (\n (T extends unknown ? (t: T) => T : never) extends infer U\n ? (U extends unknown ? (u: U) => unknown : never) extends (v: infer V) => unknown ? V\n : never\n : never\n) extends (_: unknown) => infer W ? [...MemberListOf<Exclude<T, W>>, W]\n : []\n\n// Given a list of Results, this extracts all the different `T` types from that list\nexport type ExtractOkTypes<T extends ReadonlyArray<Result<unknown, unknown>>> = {\n [idx in keyof T]: T[idx] extends Result<infer U, unknown> ? U : never\n}\n\n// Given a list of ResultAsyncs, this extracts all the different `T` types from that list\nexport type ExtractOkAsyncTypes<T extends ReadonlyArray<ResultAsync<unknown, unknown>>> = {\n [idx in keyof T]: T[idx] extends ResultAsync<infer U, unknown> ? U : never\n}\n\n// Given a list of Results, this extracts all the different `E` types from that list\nexport type ExtractErrTypes<T extends ReadonlyArray<Result<unknown, unknown>>> = {\n [idx in keyof T]: T[idx] extends Result<unknown, infer E> ? E : never\n}\n\n// Given a list of ResultAsyncs, this extracts all the different `E` types from that list\nexport type ExtractErrAsyncTypes<T extends ReadonlyArray<ResultAsync<unknown, unknown>>> = {\n [idx in keyof T]: T[idx] extends ResultAsync<unknown, infer E> ? E : never\n}\n\nexport type InferOkTypes<R> = R extends Result<infer T, unknown> ? T : never\nexport type InferErrTypes<R> = R extends Result<unknown, infer E> ? E : never\n\nexport type InferAsyncOkTypes<R> = R extends ResultAsync<infer T, unknown> ? T : never\nexport type InferAsyncErrTypes<R> = R extends ResultAsync<unknown, infer E> ? E : never\n\n// Checks if the given type is a literal array.\nexport type IsLiteralArray<T> = T extends { length: infer L } ? L extends number ? number extends L ? 0\n : 1\n : 0\n : 0\n\n// Converts an empty array to never.\n//\n// The second type parameter here will affect how to behave to `never[]`s.\n// If a precise type is required, pass `1` here so that it will resolve\n// a literal array such as `[ never, never ]`. Otherwise, set `0` or the default\n// type value will cause this to resolve the arrays containing only `never`\n// items as `never` only.\nexport type EmptyArrayToNever<T, NeverArrayToNever extends number = 0> = T extends [] ? never\n : NeverArrayToNever extends 1 ? T extends [never, ...infer Rest] ? [EmptyArrayToNever<Rest>] extends [never] ? never\n : T\n : T\n : T\n\n// #region Combine - Types\n\n// This is a helper type to prevent infinite recursion in typing rules.\n//\n// Use this with your `depth` variable in your types.\ntype Prev = [\n never,\n 0,\n 1,\n 2,\n 3,\n 4,\n 5,\n 6,\n 7,\n 8,\n 9,\n 10,\n 11,\n 12,\n 13,\n 14,\n 15,\n 16,\n 17,\n 18,\n 19,\n 20,\n 21,\n 22,\n 23,\n 24,\n 25,\n 26,\n 27,\n 28,\n 29,\n 30,\n 31,\n 32,\n 33,\n 34,\n 35,\n 36,\n 37,\n 38,\n 39,\n 40,\n 41,\n 42,\n 43,\n 44,\n 45,\n 46,\n 47,\n 48,\n 49,\n ...Array<0>,\n]\n\n// Transposes an array\n//\n// A - The array source\n// Transposed - The collected transposed array\n// Depth - The maximum depth.\nexport type Transpose<\n A,\n Transposed extends unknown[][] = [],\n Depth extends number = 10,\n> = A extends [infer T, ...infer Rest]\n ? T extends [infer L, infer R]\n ? Transposed extends [infer PL, infer PR]\n ? PL extends unknown[] ? PR extends unknown[] ? Transpose<Rest, [[...PL, L], [...PR, R]], Prev[Depth]>\n : never\n : never\n : Transpose<Rest, [[L], [R]], Prev[Depth]>\n : Transposed\n : Transposed\n\n// Collects the results array into separate tuple array.\n//\n// T - The array of the results\n// Collected - The collected tuples.\n// Depth - The maximum depth.\ntype CollectResults<T, Collected extends unknown[] = [], Depth extends number = 50> = [\n Depth,\n] extends [never] ? []\n : T extends [infer H, ...infer Rest]\n // And test whether the head of the list is a result\n ? H extends Result<infer L, infer R>\n // Continue collecting...\n ? CollectResults<\n // the rest of the elements\n Rest,\n // The collected\n [...Collected, [L, R]],\n // and one less of the current depth\n Prev[Depth]\n >\n : never // Impossible\n : Collected\n\n// Converts the `unknown` items of an array to `never`s.\ntype UnknownMembersToNever<T> = T extends [infer H, ...infer R]\n ? [[unknown] extends [H] ? never : H, ...UnknownMembersToNever<R>]\n : T\n\n// Gets the member type of the array or never.\nexport type MembersToUnion<T> = T extends unknown[] ? T[number] : never\n\n// Combines the both sides of the array of the results into a tuple of the\n// union of the ok types and the union of the err types.\n//\n// T - The array of the results\n// Depth - The maximum depth.\nexport type Combine<T, Depth extends number = 5> = Transpose<CollectResults<T>, [], Depth> extends [\n infer L,\n infer R,\n] ? [UnknownMembersToNever<L>, UnknownMembersToNever<R>]\n : Transpose<CollectResults<T>, [], Depth> extends [] ? [[], []]\n : never\n\n// Traverses an array of results and returns a single result containing\n// the oks and errs union-ed/combined.\ntype Traverse<T, Depth extends number = 5> = Combine<T, Depth> extends [infer Oks, infer Errs]\n ? Result<EmptyArrayToNever<Oks, 1>, MembersToUnion<Errs>>\n : never\n\n// Traverses an array of results and returns a single result containing\n// the oks combined and the array of errors combined.\ntype TraverseWithAllErrors<T, Depth extends number = 5> = Combine<T, Depth> extends [\n infer Oks,\n infer Errs,\n] ? Result<EmptyArrayToNever<Oks>, EmptyArrayToNever<Errs>>\n : never\n\nexport type CombineResults<\n T extends ReadonlyArray<Result<unknown, unknown>>,\n> = IsLiteralArray<T> extends 1 ? Traverse<T>\n : Result<ExtractOkTypes<T>, ExtractErrTypes<T>[number]>\n\n// Combines the array of results into one result with all errors.\nexport type CombineResultsWithAllErrorsArray<\n T extends ReadonlyArray<Result<unknown, unknown>>,\n> = IsLiteralArray<T> extends 1 ? TraverseWithAllErrors<T>\n : Result<ExtractOkTypes<T>, Array<ExtractErrTypes<T>[number]>>\n\n/* This is the typesafe version of Promise.all\n *\n * Takes a list of ResultAsync<T, E> and success if all inner results are Ok values\n * or fails if one (or more) of the inner results are Err values\n */\nexport const combineResultAsyncList = <T, E>(\n asyncResultList: ReadonlyArray<ResultAsync<T, E>>,\n): ResultAsync<readonly T[], E> =>\n ResultAsync.fromSafePromise(Promise.all(asyncResultList)).andThen(\n combineResultList,\n ) as ResultAsync<T[], E>\n\n/**\n * Short circuits on the FIRST Err value that we find\n */\nexport const combineResultList = <T, E>(\n resultList: ReadonlyArray<Result<T, E>>,\n): Result<readonly T[], E> => {\n let acc = ok([]) as Result<T[], E>\n\n for (const result of resultList) {\n if (result.isErr()) {\n acc = err(result.error)\n break\n } else {\n acc.map((list) => list.push(result.value))\n }\n }\n return acc\n}\n/* This is the typesafe version of Promise.all\n *\n * Takes a list of ResultAsync<T, E> and success if all inner results are Ok values\n * or fails if one (or more) of the inner results are Err values\n */\nexport const combineResultAsyncListWithAllErrors = <T, E>(\n asyncResultList: ReadonlyArray<ResultAsync<T, E>>,\n): ResultAsync<readonly T[], E[]> => {\n const x = ResultAsync.fromSafePromise(Promise.all(asyncResultList)).andThen(\n combineResultListWithAllErrors,\n )\n return x as ResultAsync<T[], E[]>\n}\n\n/**\n * Give a list of all the errors we find\n */\nexport const combineResultListWithAllErrors = <T, E>(\n resultList: ReadonlyArray<Result<T, E>>,\n): Result<readonly T[], E[]> => {\n let acc = ok([]) as Result<T[], E[]>\n\n for (const result of resultList) {\n if (result.isErr() && acc.isErr()) {\n acc.error.push(result.error)\n } else if (result.isErr() && acc.isOk()) {\n acc = err([result.error])\n } else if (result.isOk() && acc.isOk()) {\n acc.value.push(result.value)\n }\n // do nothing when result.isOk() && acc.isErr()\n }\n return acc\n}\n"],"mappings":";;;;;AAMA,IAAM,KAAN,MAAY;AAAA,EAEV,YAA4B,OAAU;AAAV;AAAA,EAAW;AAAA,EAD9B,KAAK;AAEhB;AAEA,IAAM,MAAN,MAAa;AAAA,EAEX,YAA4B,OAAU;AAAV;AAAA,EAAW;AAAA,EAD9B,KAAK;AAEhB;AA6DO,IAAM,SAAN,MAAM,QAAyC;AAAA,EA8E5C,YAA6B,OAAuB;AAAvB;AACnC,QAAI,MAAM,IAAI;AACZ,WAAK,QAAQ,MAAM;AACnB,WAAK,QAAQ;AAAA,IACf,OAAO;AACL,WAAK,QAAQ,MAAM;AACnB,WAAK,QAAQ;AAAA,IACf;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA7EA,OAAO,cACL,IAEA,SACwD;AACxD,WAAO,IAAI,SAAS;AAClB,UAAI;AACF,cAAM,SAAS,GAAG,GAAG,IAAI;AACzB,eAAO,GAAG,MAAwB;AAAA,MACpC,SAAS,OAAO;AACd,YAAI,SAAS;AACX,iBAAO,IAAI,QAAQ,KAAK,CAAC;AAAA,QAC3B;AAEA,eAAO,IAAI,KAAU;AAAA,M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ACpC,oBAEA,YAAY,gBAAgB,QAAQ,IAAI,eAAe,CAAC,EAAE;AAAA,EACxD;AACF;AAKK,IAAM,oBAAoB,CAC/B,eAC4B;AAC5B,MAAI,MAAM,GAAG,CAAC,CAAC;AAEf,aAAW,UAAU,YAAY;AAC/B,QAAI,OAAO,MAAM,GAAG;AAClB,YAAM,IAAI,OAAO,KAAK;AACtB;AAAA,IACF,OAAO;AACL,UAAI,IAAI,CAAC,SAAS,KAAK,KAAK,OAAO,KAAK,CAAC;AAAA,IAC3C;AAAA,EACF;AACA,SAAO;AACT;AAMO,IAAM,sCAAsC,CACjD,oBACmC;AACnC,QAAM,IAAI,YAAY,gBAAgB,QAAQ,IAAI,eAAe,CAAC,EAAE;AAAA,IAClE;AAAA,EACF;AACA,SAAO;AACT;AAKO,IAAM,iCAAiC,CAC5C,eAC8B;AAC9B,MAAI,MAAM,GAAG,CAAC,CAAC;AAEf,aAAW,UAAU,YAAY;AAC/B,QAAI,OAAO,MAAM,KAAK,IAAI,MAAM,GAAG;AACjC,UAAI,MAAM,KAAK,OAAO,KAAK;AAAA,IAC7B,WAAW,OAAO,MAAM,KAAK,IAAI,KAAK,GAAG;AACvC,YAAM,IAAI,CAAC,OAAO,KAAK,CAAC;AAAA,IAC1B,WAAW,OAAO,KAAK,KAAK,IAAI,KAAK,GAAG;AACtC,UAAI,MAAM,KAAK,OAAO,KAAK;AAAA,IAC7B;AAAA,EAEF;AACA,SAAO;AACT;","names":["ok","err"]}
|
|
@@ -6,6 +6,7 @@ var createResultarError = (message, result, config = defaultErrorConfig) => {
|
|
|
6
6
|
const data = result.isOk() ? { type: "Ok", value: result.value } : { type: "Err", value: result.error };
|
|
7
7
|
const maybeStack = config.withStackTrace ? new Error().stack : void 0;
|
|
8
8
|
return {
|
|
9
|
+
name: "ResultarError",
|
|
9
10
|
data,
|
|
10
11
|
message,
|
|
11
12
|
stack: maybeStack
|
|
@@ -15,4 +16,4 @@ var createResultarError = (message, result, config = defaultErrorConfig) => {
|
|
|
15
16
|
export {
|
|
16
17
|
createResultarError
|
|
17
18
|
};
|
|
18
|
-
//# sourceMappingURL=chunk-
|
|
19
|
+
//# sourceMappingURL=chunk-VBI3T5VS.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/error.ts"],"sourcesContent":["import type { Result } from './result.js'\n\nexport interface ErrorConfig {\n withStackTrace: boolean\n}\n\nconst defaultErrorConfig: ErrorConfig = {\n withStackTrace: false,\n}\n\ninterface ResultarError<T, E> extends Error {\n data:\n | {\n type: string\n value: T | undefined\n }\n | {\n type: string\n value: E | undefined\n }\n message: string\n stack: string | undefined\n}\n\nexport const createResultarError = <T, E>(\n message: string,\n result: Result<T, E>,\n config: ErrorConfig = defaultErrorConfig,\n): ResultarError<T, E> => {\n const data = result.isOk()\n ? { type: 'Ok', value: result.value }\n : { type: 'Err', value: result.error }\n\n const maybeStack = config.withStackTrace ? new Error().stack : undefined // eslint-disable-line unicorn/error-message\n\n return {\n name: 'ResultarError',\n data,\n message,\n stack: maybeStack,\n }\n}\n"],"mappings":";AAMA,IAAM,qBAAkC;AAAA,EACtC,gBAAgB;AAClB;AAgBO,IAAM,sBAAsB,CACjC,SACA,QACA,SAAsB,uBACE;AACxB,QAAM,OAAO,OAAO,KAAK,IACrB,EAAE,MAAM,MAAM,OAAO,OAAO,MAAM,IAClC,EAAE,MAAM,OAAO,OAAO,OAAO,MAAM;AAEvC,QAAM,aAAa,OAAO,iBAAiB,IAAI,MAAM,EAAE,QAAQ;AAE/D,SAAO;AAAA,IACL,MAAM;AAAA,IACN;AAAA,IACA;AAAA,IACA,OAAO;AAAA,EACT;AACF;","names":[]}
|
package/dist/error.cjs
CHANGED
|
@@ -30,6 +30,7 @@ var createResultarError = (message, result, config = defaultErrorConfig) => {
|
|
|
30
30
|
const data = result.isOk() ? { type: "Ok", value: result.value } : { type: "Err", value: result.error };
|
|
31
31
|
const maybeStack = config.withStackTrace ? new Error().stack : void 0;
|
|
32
32
|
return {
|
|
33
|
+
name: "ResultarError",
|
|
33
34
|
data,
|
|
34
35
|
message,
|
|
35
36
|
stack: maybeStack
|
package/dist/error.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/error.ts"],"sourcesContent":["import type { Result } from './result.js'\n\nexport interface ErrorConfig {\n withStackTrace: boolean\n}\n\nconst defaultErrorConfig: ErrorConfig = {\n withStackTrace: false,\n}\n\ninterface ResultarError<T, E> {\n data:\n | {\n type: string\n value: T | undefined\n }\n | {\n type: string\n value: E | undefined\n }\n message: string\n stack: string | undefined\n}\n\nexport const createResultarError = <T, E>(\n message: string,\n result: Result<T, E>,\n config: ErrorConfig = defaultErrorConfig,\n): ResultarError<T, E> => {\n const data = result.isOk()\n ? { type: 'Ok', value: result.value }\n : { type: 'Err', value: result.error }\n\n const maybeStack = config.withStackTrace ? new Error().stack : undefined // eslint-disable-line unicorn/error-message\n\n return {\n data,\n message,\n stack: maybeStack,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,IAAM,qBAAkC;AAAA,EACtC,gBAAgB;AAClB;AAgBO,IAAM,sBAAsB,CACjC,SACA,QACA,SAAsB,uBACE;AACxB,QAAM,OAAO,OAAO,KAAK,IACrB,EAAE,MAAM,MAAM,OAAO,OAAO,MAAM,IAClC,EAAE,MAAM,OAAO,OAAO,OAAO,MAAM;AAEvC,QAAM,aAAa,OAAO,iBAAiB,IAAI,MAAM,EAAE,QAAQ;AAE/D,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,OAAO;AAAA,EACT;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/error.ts"],"sourcesContent":["import type { Result } from './result.js'\n\nexport interface ErrorConfig {\n withStackTrace: boolean\n}\n\nconst defaultErrorConfig: ErrorConfig = {\n withStackTrace: false,\n}\n\ninterface ResultarError<T, E> extends Error {\n data:\n | {\n type: string\n value: T | undefined\n }\n | {\n type: string\n value: E | undefined\n }\n message: string\n stack: string | undefined\n}\n\nexport const createResultarError = <T, E>(\n message: string,\n result: Result<T, E>,\n config: ErrorConfig = defaultErrorConfig,\n): ResultarError<T, E> => {\n const data = result.isOk()\n ? { type: 'Ok', value: result.value }\n : { type: 'Err', value: result.error }\n\n const maybeStack = config.withStackTrace ? new Error().stack : undefined // eslint-disable-line unicorn/error-message\n\n return {\n name: 'ResultarError',\n data,\n message,\n stack: maybeStack,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,IAAM,qBAAkC;AAAA,EACtC,gBAAgB;AAClB;AAgBO,IAAM,sBAAsB,CACjC,SACA,QACA,SAAsB,uBACE;AACxB,QAAM,OAAO,OAAO,KAAK,IACrB,EAAE,MAAM,MAAM,OAAO,OAAO,MAAM,IAClC,EAAE,MAAM,OAAO,OAAO,OAAO,MAAM;AAEvC,QAAM,aAAa,OAAO,iBAAiB,IAAI,MAAM,EAAE,QAAQ;AAE/D,SAAO;AAAA,IACL,MAAM;AAAA,IACN;AAAA,IACA;AAAA,IACA,OAAO;AAAA,EACT;AACF;","names":[]}
|
package/dist/error.d.cts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { K as ErrorConfig, L as createResultarError } from './index-CV4S5Ys9.cjs';
|
package/dist/error.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { K as ErrorConfig, L as createResultarError } from './index-CV4S5Ys9.js';
|
package/dist/error.js
CHANGED
|
@@ -117,10 +117,47 @@ declare class DisposableResultAsync<T, E> implements PromiseLike<Result<T, E>> {
|
|
|
117
117
|
then<A, B>(// eslint-disable-line unicorn/no-thenable
|
|
118
118
|
successCallback?: (res: Result<T, E>) => A | PromiseLike<A>, failureCallback?: (reason: unknown) => B | PromiseLike<B>): PromiseLike<A | B>;
|
|
119
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* The ResultAsync type.
|
|
122
|
+
* This is a union of `Result` and `PromiseLike<Result>`
|
|
123
|
+
*/
|
|
120
124
|
declare class ResultAsync<T, E> implements PromiseLike<Result<T, E>> {
|
|
125
|
+
/**
|
|
126
|
+
* Returns a ResultAsync instance that is immediately resolved with a Result.ok(value).
|
|
127
|
+
*
|
|
128
|
+
* @param {T} value - The value to be wrapped in a Result.ok.
|
|
129
|
+
* @return {ResultAsync<T, E>} A ResultAsync instance with the given value and error type E.
|
|
130
|
+
*/
|
|
121
131
|
static okAsync<T, E = never>(value: T): ResultAsync<T, E>;
|
|
132
|
+
/**
|
|
133
|
+
* Returns a ResultAsync that is immediately resolved with a Result.ok(undefined) value.
|
|
134
|
+
*
|
|
135
|
+
* @return {ResultAsync<undefined, E>} A ResultAsync instance with undefined as the value type and E as the error type.
|
|
136
|
+
*/
|
|
137
|
+
static unitAsync<E = never>(): ResultAsync<undefined, E>;
|
|
138
|
+
/**
|
|
139
|
+
* Returns a ResultAsync instance that is immediately resolved with a Result.err(error).
|
|
140
|
+
*
|
|
141
|
+
* @param {E} error - The error to be wrapped in a Result.err.
|
|
142
|
+
* @return {ResultAsync<T, E>} A ResultAsync instance with the given error and value type T.
|
|
143
|
+
*/
|
|
122
144
|
static errAsync<T = never, E = unknown>(error: E): ResultAsync<T, E>;
|
|
145
|
+
/**
|
|
146
|
+
* Returns a ResultAsync instance that is resolved with a Result.ok(value) or Result.err(error)
|
|
147
|
+
* based on the provided promise.
|
|
148
|
+
*
|
|
149
|
+
* @param {Promise<T>} promise - The promise to be wrapped in a ResultAsync.
|
|
150
|
+
* @return {ResultAsync<T, E>} A ResultAsync instance with the given promise and error type E.
|
|
151
|
+
*/
|
|
123
152
|
static fromSafePromise<T, E = never>(promise: PromiseLike<T>): ResultAsync<T, E>;
|
|
153
|
+
/**
|
|
154
|
+
* Returns a ResultAsync instance that is resolved with a Result.ok(value) or Result.err(error)
|
|
155
|
+
* based on the provided promise.
|
|
156
|
+
*
|
|
157
|
+
* @param {Promise<T>} promise - The promise to be wrapped in a ResultAsync.
|
|
158
|
+
* @param {(e: unknown) => E} errorFn - A function that transforms the error from the promise into the error type E.
|
|
159
|
+
* @return {ResultAsync<T, E>} A ResultAsync instance with the given promise and error type E.
|
|
160
|
+
*/
|
|
124
161
|
static fromPromise<T, E>(promise: PromiseLike<T>, errorFn: (e: unknown) => E): ResultAsync<T, E>;
|
|
125
162
|
static combine<T extends readonly [ResultAsync<unknown, unknown>, ...Array<ResultAsync<unknown, unknown>>]>(asyncResultList: T): CombineResultAsyncs<T>;
|
|
126
163
|
static combine<T extends ReadonlyArray<ResultAsync<unknown, unknown>>>(asyncResultList: T): CombineResultAsyncs<T>;
|
|
@@ -186,6 +223,7 @@ declare const okAsync: typeof ResultAsync.okAsync;
|
|
|
186
223
|
declare const errAsync: typeof ResultAsync.errAsync;
|
|
187
224
|
declare const fromPromise: typeof ResultAsync.fromPromise;
|
|
188
225
|
declare const fromSafePromise: typeof ResultAsync.fromSafePromise;
|
|
226
|
+
declare const unitAsync: typeof ResultAsync.unitAsync;
|
|
189
227
|
declare const fromThrowableAsync: typeof ResultAsync.fromThrowable;
|
|
190
228
|
/**
|
|
191
229
|
* Evaluates the given generator to a Result returned or an Err yielded from it,
|
|
@@ -262,7 +300,19 @@ declare class Result<T, E> implements Resultable<T, E> {
|
|
|
262
300
|
* @param errorFn when an error is thrown, this will wrap the error result if provided
|
|
263
301
|
*/
|
|
264
302
|
static fromThrowable<Fn extends (...args: readonly any[]) => unknown, E>(fn: Fn, errorFn?: (e: any) => E): (...args: Parameters<Fn>) => Result<ReturnType<Fn>, E>;
|
|
303
|
+
/**
|
|
304
|
+
* Creates a new `Result` instance representing a successful operation.
|
|
305
|
+
*
|
|
306
|
+
* @param {T} value - The value to be wrapped in the `Result` instance.
|
|
307
|
+
* @return {Result<T, E>} A new `Result` instance with the provided value.
|
|
308
|
+
*/
|
|
265
309
|
static ok<T, E = never>(value: T): Result<T, E>;
|
|
310
|
+
/**
|
|
311
|
+
* Creates a new `Result` instance representing a successful operation with an undefined value.
|
|
312
|
+
*
|
|
313
|
+
* @return {Result<undefined, E>} A new `Result` instance with an undefined value.
|
|
314
|
+
*/
|
|
315
|
+
static unit<E = never>(): Result<undefined, E>;
|
|
266
316
|
static err<T = never, E = unknown>(error: E): Result<T, E>;
|
|
267
317
|
static combine<T extends readonly [Result<unknown, unknown>, ...Array<Result<unknown, unknown>>]>(resultList: T): CombineResults<T>;
|
|
268
318
|
static combine<T extends ReadonlyArray<Result<unknown, unknown>>>(resultList: T): CombineResults<T>;
|
|
@@ -366,7 +416,7 @@ declare class Result<T, E> implements Resultable<T, E> {
|
|
|
366
416
|
*/
|
|
367
417
|
match<X>(fnOk: (t: T) => X, fnErr: (e: E) => X): X;
|
|
368
418
|
/**
|
|
369
|
-
* Performs a side effect
|
|
419
|
+
* Performs a side effect for the `Ok` or `Err` variant of `Result`.
|
|
370
420
|
*
|
|
371
421
|
* @param fn The function to apply an `OK` value
|
|
372
422
|
* @returns the result of applying `f` or an `Err` untouched
|
|
@@ -430,6 +480,7 @@ declare class DisposableResult<T, E> implements Resultable<T, E>, Disposable {
|
|
|
430
480
|
declare const ok: typeof Result.ok;
|
|
431
481
|
declare const err: typeof Result.err;
|
|
432
482
|
declare const fromThrowable: typeof Result.fromThrowable;
|
|
483
|
+
declare const unit: typeof Result.unit;
|
|
433
484
|
/**
|
|
434
485
|
* Evaluates the given generator to a Result returned or an Err yielded from it,
|
|
435
486
|
* whichever comes first.
|
|
@@ -460,7 +511,7 @@ declare function safeTry<T, E>(body: () => AsyncGenerator<Result<never, E>, Resu
|
|
|
460
511
|
interface ErrorConfig {
|
|
461
512
|
withStackTrace: boolean;
|
|
462
513
|
}
|
|
463
|
-
interface ResultarError<T, E> {
|
|
514
|
+
interface ResultarError<T, E> extends Error {
|
|
464
515
|
data: {
|
|
465
516
|
type: string;
|
|
466
517
|
value: T | undefined;
|
|
@@ -473,4 +524,4 @@ interface ResultarError<T, E> {
|
|
|
473
524
|
}
|
|
474
525
|
declare const createResultarError: <T, E>(message: string, result: Result<T, E>, config?: ErrorConfig) => ResultarError<T, E>;
|
|
475
526
|
|
|
476
|
-
export {
|
|
527
|
+
export { DisposableResult as A, ok as B, type Combine as C, type Dedup as D, type ExtractOkTypes as E, err as F, fromThrowable as G, unit as H, type InferOkTypes as I, safeTry as J, type ErrorConfig as K, createResultarError as L, type MemberListOf as M, ResultAsync as R, type Transpose as T, type ExtractOkAsyncTypes as a, type ExtractErrTypes as b, type ExtractErrAsyncTypes as c, type InferErrTypes as d, type InferAsyncOkTypes as e, type InferAsyncErrTypes as f, type IsLiteralArray as g, type EmptyArrayToNever as h, type MembersToUnion as i, type CombineResults as j, type CombineResultsWithAllErrorsArray as k, combineResultAsyncList as l, combineResultList as m, combineResultAsyncListWithAllErrors as n, combineResultListWithAllErrors as o, type CombineResultAsyncs as p, type CombineResultsWithAllErrorsArrayAsync as q, DisposableResultAsync as r, okAsync as s, errAsync as t, fromPromise as u, fromSafePromise as v, unitAsync as w, fromThrowableAsync as x, safeTryAsync as y, Result as z };
|
|
@@ -117,10 +117,47 @@ declare class DisposableResultAsync<T, E> implements PromiseLike<Result<T, E>> {
|
|
|
117
117
|
then<A, B>(// eslint-disable-line unicorn/no-thenable
|
|
118
118
|
successCallback?: (res: Result<T, E>) => A | PromiseLike<A>, failureCallback?: (reason: unknown) => B | PromiseLike<B>): PromiseLike<A | B>;
|
|
119
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* The ResultAsync type.
|
|
122
|
+
* This is a union of `Result` and `PromiseLike<Result>`
|
|
123
|
+
*/
|
|
120
124
|
declare class ResultAsync<T, E> implements PromiseLike<Result<T, E>> {
|
|
125
|
+
/**
|
|
126
|
+
* Returns a ResultAsync instance that is immediately resolved with a Result.ok(value).
|
|
127
|
+
*
|
|
128
|
+
* @param {T} value - The value to be wrapped in a Result.ok.
|
|
129
|
+
* @return {ResultAsync<T, E>} A ResultAsync instance with the given value and error type E.
|
|
130
|
+
*/
|
|
121
131
|
static okAsync<T, E = never>(value: T): ResultAsync<T, E>;
|
|
132
|
+
/**
|
|
133
|
+
* Returns a ResultAsync that is immediately resolved with a Result.ok(undefined) value.
|
|
134
|
+
*
|
|
135
|
+
* @return {ResultAsync<undefined, E>} A ResultAsync instance with undefined as the value type and E as the error type.
|
|
136
|
+
*/
|
|
137
|
+
static unitAsync<E = never>(): ResultAsync<undefined, E>;
|
|
138
|
+
/**
|
|
139
|
+
* Returns a ResultAsync instance that is immediately resolved with a Result.err(error).
|
|
140
|
+
*
|
|
141
|
+
* @param {E} error - The error to be wrapped in a Result.err.
|
|
142
|
+
* @return {ResultAsync<T, E>} A ResultAsync instance with the given error and value type T.
|
|
143
|
+
*/
|
|
122
144
|
static errAsync<T = never, E = unknown>(error: E): ResultAsync<T, E>;
|
|
145
|
+
/**
|
|
146
|
+
* Returns a ResultAsync instance that is resolved with a Result.ok(value) or Result.err(error)
|
|
147
|
+
* based on the provided promise.
|
|
148
|
+
*
|
|
149
|
+
* @param {Promise<T>} promise - The promise to be wrapped in a ResultAsync.
|
|
150
|
+
* @return {ResultAsync<T, E>} A ResultAsync instance with the given promise and error type E.
|
|
151
|
+
*/
|
|
123
152
|
static fromSafePromise<T, E = never>(promise: PromiseLike<T>): ResultAsync<T, E>;
|
|
153
|
+
/**
|
|
154
|
+
* Returns a ResultAsync instance that is resolved with a Result.ok(value) or Result.err(error)
|
|
155
|
+
* based on the provided promise.
|
|
156
|
+
*
|
|
157
|
+
* @param {Promise<T>} promise - The promise to be wrapped in a ResultAsync.
|
|
158
|
+
* @param {(e: unknown) => E} errorFn - A function that transforms the error from the promise into the error type E.
|
|
159
|
+
* @return {ResultAsync<T, E>} A ResultAsync instance with the given promise and error type E.
|
|
160
|
+
*/
|
|
124
161
|
static fromPromise<T, E>(promise: PromiseLike<T>, errorFn: (e: unknown) => E): ResultAsync<T, E>;
|
|
125
162
|
static combine<T extends readonly [ResultAsync<unknown, unknown>, ...Array<ResultAsync<unknown, unknown>>]>(asyncResultList: T): CombineResultAsyncs<T>;
|
|
126
163
|
static combine<T extends ReadonlyArray<ResultAsync<unknown, unknown>>>(asyncResultList: T): CombineResultAsyncs<T>;
|
|
@@ -186,6 +223,7 @@ declare const okAsync: typeof ResultAsync.okAsync;
|
|
|
186
223
|
declare const errAsync: typeof ResultAsync.errAsync;
|
|
187
224
|
declare const fromPromise: typeof ResultAsync.fromPromise;
|
|
188
225
|
declare const fromSafePromise: typeof ResultAsync.fromSafePromise;
|
|
226
|
+
declare const unitAsync: typeof ResultAsync.unitAsync;
|
|
189
227
|
declare const fromThrowableAsync: typeof ResultAsync.fromThrowable;
|
|
190
228
|
/**
|
|
191
229
|
* Evaluates the given generator to a Result returned or an Err yielded from it,
|
|
@@ -262,7 +300,19 @@ declare class Result<T, E> implements Resultable<T, E> {
|
|
|
262
300
|
* @param errorFn when an error is thrown, this will wrap the error result if provided
|
|
263
301
|
*/
|
|
264
302
|
static fromThrowable<Fn extends (...args: readonly any[]) => unknown, E>(fn: Fn, errorFn?: (e: any) => E): (...args: Parameters<Fn>) => Result<ReturnType<Fn>, E>;
|
|
303
|
+
/**
|
|
304
|
+
* Creates a new `Result` instance representing a successful operation.
|
|
305
|
+
*
|
|
306
|
+
* @param {T} value - The value to be wrapped in the `Result` instance.
|
|
307
|
+
* @return {Result<T, E>} A new `Result` instance with the provided value.
|
|
308
|
+
*/
|
|
265
309
|
static ok<T, E = never>(value: T): Result<T, E>;
|
|
310
|
+
/**
|
|
311
|
+
* Creates a new `Result` instance representing a successful operation with an undefined value.
|
|
312
|
+
*
|
|
313
|
+
* @return {Result<undefined, E>} A new `Result` instance with an undefined value.
|
|
314
|
+
*/
|
|
315
|
+
static unit<E = never>(): Result<undefined, E>;
|
|
266
316
|
static err<T = never, E = unknown>(error: E): Result<T, E>;
|
|
267
317
|
static combine<T extends readonly [Result<unknown, unknown>, ...Array<Result<unknown, unknown>>]>(resultList: T): CombineResults<T>;
|
|
268
318
|
static combine<T extends ReadonlyArray<Result<unknown, unknown>>>(resultList: T): CombineResults<T>;
|
|
@@ -366,7 +416,7 @@ declare class Result<T, E> implements Resultable<T, E> {
|
|
|
366
416
|
*/
|
|
367
417
|
match<X>(fnOk: (t: T) => X, fnErr: (e: E) => X): X;
|
|
368
418
|
/**
|
|
369
|
-
* Performs a side effect
|
|
419
|
+
* Performs a side effect for the `Ok` or `Err` variant of `Result`.
|
|
370
420
|
*
|
|
371
421
|
* @param fn The function to apply an `OK` value
|
|
372
422
|
* @returns the result of applying `f` or an `Err` untouched
|
|
@@ -430,6 +480,7 @@ declare class DisposableResult<T, E> implements Resultable<T, E>, Disposable {
|
|
|
430
480
|
declare const ok: typeof Result.ok;
|
|
431
481
|
declare const err: typeof Result.err;
|
|
432
482
|
declare const fromThrowable: typeof Result.fromThrowable;
|
|
483
|
+
declare const unit: typeof Result.unit;
|
|
433
484
|
/**
|
|
434
485
|
* Evaluates the given generator to a Result returned or an Err yielded from it,
|
|
435
486
|
* whichever comes first.
|
|
@@ -460,7 +511,7 @@ declare function safeTry<T, E>(body: () => AsyncGenerator<Result<never, E>, Resu
|
|
|
460
511
|
interface ErrorConfig {
|
|
461
512
|
withStackTrace: boolean;
|
|
462
513
|
}
|
|
463
|
-
interface ResultarError<T, E> {
|
|
514
|
+
interface ResultarError<T, E> extends Error {
|
|
464
515
|
data: {
|
|
465
516
|
type: string;
|
|
466
517
|
value: T | undefined;
|
|
@@ -473,4 +524,4 @@ interface ResultarError<T, E> {
|
|
|
473
524
|
}
|
|
474
525
|
declare const createResultarError: <T, E>(message: string, result: Result<T, E>, config?: ErrorConfig) => ResultarError<T, E>;
|
|
475
526
|
|
|
476
|
-
export {
|
|
527
|
+
export { DisposableResult as A, ok as B, type Combine as C, type Dedup as D, type ExtractOkTypes as E, err as F, fromThrowable as G, unit as H, type InferOkTypes as I, safeTry as J, type ErrorConfig as K, createResultarError as L, type MemberListOf as M, ResultAsync as R, type Transpose as T, type ExtractOkAsyncTypes as a, type ExtractErrTypes as b, type ExtractErrAsyncTypes as c, type InferErrTypes as d, type InferAsyncOkTypes as e, type InferAsyncErrTypes as f, type IsLiteralArray as g, type EmptyArrayToNever as h, type MembersToUnion as i, type CombineResults as j, type CombineResultsWithAllErrorsArray as k, combineResultAsyncList as l, combineResultList as m, combineResultAsyncListWithAllErrors as n, combineResultListWithAllErrors as o, type CombineResultAsyncs as p, type CombineResultsWithAllErrorsArrayAsync as q, DisposableResultAsync as r, okAsync as s, errAsync as t, fromPromise as u, fromSafePromise as v, unitAsync as w, fromThrowableAsync as x, safeTryAsync as y, Result as z };
|