resultar 0.8.2 → 0.8.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,11 +2,9 @@
2
2
 
3
3
  ## About
4
4
 
5
- Resultar is a TypeScript library that is a fork of the excellent [neverthrow](https://github.com/supermacro/neverthrow) library. The neverthrow library provides a robust and type-safe way to handle errors without throwing exceptions, using the Result type.
5
+ Resultar is a TypeScript library for robust, type-safe error handling without throwing exceptions. It's a fork of the excellent [neverthrow](https://github.com/supermacro/neverthrow) library, adding features for more flexibility in error handling
6
6
 
7
- In the spirit of open-source development, **resultar** builds upon the solid foundation laid by neverthrow, extending its functionality to better suit specific needs. It introduces additional methods and functions such as tap, safeTryAsync, and fromThrowableAsync, providing more flexibility and control in error handling.
8
-
9
- While resultar owes its origins to neverthrow, it has evolved to offer its own unique features, making error handling in TypeScript even more powerful and expressive. It's a testament to the power of open-source collaboration and the continuous pursuit of improving code quality and developer experience.
7
+ In the spirit of open-source development, **resultar** builds upon the solid foundation laid by neverthrow, extending its functionality to better suit specific needs. It introduces additional methods and functions such as tap, safeTryAsync, and fromThrowableAsync and finally providing more flexibility and control in error handling.
10
8
 
11
9
  ## Description
12
10
 
@@ -16,9 +14,9 @@ This package contains a `Result` type that represents either success (`Ok`) or f
16
14
 
17
15
  For asynchronous tasks, `resultar` offers a `ResultAsync` class which wraps a `Promise<Result<T, E>>` and gives you the same level of expressivity and control as a regular `Result<T, E>`.
18
16
 
19
- `ResultAsync` is `thenable` meaning it **behaves exactly like a native `Promise<Result>`** ... except you have access to the same methods that `Result` provides without having to `await` or `.then` the promise! Check out [the wiki](https://github.com/inaiat/resultar/wiki/Basic-Usage-Examples#asynchronous-api) for examples and best practices.
17
+ `ResultAsync` is `thenable` meaning it **behaves exactly like a native `Promise<Result>`** ... except you have access to the same methods that `Result` provides without having to `await` or `.then` the promise!
20
18
 
21
- > Need to see real-life examples of how to leverage this package for error handling? See this repo: https://github.com/parlez-vous/server
19
+ ### Check out [the wiki](https://github.com/inaiat/resultar/wiki) for examples and best practices.
22
20
 
23
21
  <div id="toc"></div>
24
22
 
@@ -38,6 +36,8 @@ For asynchronous tasks, `resultar` offers a `ResultAsync` class which wraps a `P
38
36
  - [`Result.andThen` (method)](#resultandthen-method)
39
37
  - [`Result.asyncAndThen` (method)](#resultasyncandthen-method)
40
38
  - [`Result.orElse` (method)](#resultorelse-method)
39
+ - [`Result.tap` (method)](#resulttap-method)
40
+ - [`Result.finally` (method)](#resultfinally-method)
41
41
  - [`Result.match` (method)](#resultmatch-method)
42
42
  - [`Result.asyncMap` (method)](#resultasyncmap-method)
43
43
  - [`Result.fromThrowable` (static class method)](#resultfromthrowable-static-class-method)
@@ -54,6 +54,7 @@ For asynchronous tasks, `resultar` offers a `ResultAsync` class which wraps a `P
54
54
  - [`ResultAsync.unwrapOr` (method)](#resultasyncunwrapor-method)
55
55
  - [`ResultAsync.andThen` (method)](#resultasyncandthen-method)
56
56
  - [`ResultAsync.orElse` (method)](#resultasyncorelse-method)
57
+ - [`Result.tap` (method)](#resultasynctap-method)
57
58
  - [`ResultAsync.match` (method)](#resultasyncmatch-method)
58
59
  - [`ResultAsync.combine` (static class method)](#resultasynccombine-static-class-method)
59
60
  - [`ResultAsync.combineWithAllErrors` (static class method)](#resultasynccombinewithallerrors-static-class-method)
@@ -992,7 +993,34 @@ const mapped = okVal.tap((value) => {
992
993
  console.log(value) // print foo
993
994
  })
994
995
  // mapped.value === 'foo'
996
+ ```
997
+ [⬆️ Back to top](#toc)
998
+ ---
995
999
 
1000
+ ---
1001
+ #### `Result.finally` (method)
1002
+ Executes a cleanup function wether the is ok or error. This method is usefull to cleanup resources.
1003
+ **Signature:**
1004
+ ```typescript
1005
+ class Result<T, E> {
1006
+ finally(f: (value: T, error: E) => void): DisposableResult<T, E> {..}
1007
+ }
1008
+ ```
1009
+
1010
+ **Example:**
1011
+ ```typescript
1012
+ const reader = ok(file) // content file is line 01
1013
+
1014
+ const result = reader.map(it => it.content).finally(_ => {
1015
+ file.close()
1016
+ })
1017
+
1018
+ if (resul.isOk()) {
1019
+ console.log(result.value) // print line 01
1020
+ }
1021
+
1022
+ ```
1023
+ [⬆️ Back to top](#toc)
996
1024
  ---
997
1025
 
998
1026
  #### `ResultAsync.orElse` (method)
@@ -1013,6 +1041,25 @@ class ResultAsync<T, E> {
1013
1041
 
1014
1042
  ---
1015
1043
 
1044
+ #### `ResultAsync.tap` (method)
1045
+
1046
+ Executes a side effect function with the `Ok` value and returns the original `ResultAsync`.
1047
+ This method is useful for performing actions that do not modify the `ResultAsyn` itself, such as logging or updating external state.
1048
+ **Signature:**
1049
+ ```typescript
1050
+ class ResultAsync<T, E> {
1051
+ tap(f: (t: T) => void | Promise<void>): ResultAsync<T, E> {...}
1052
+ }
1053
+ ```
1054
+
1055
+ **Example:**
1056
+ See [`Result.tap` (method)](#resulttap-method)
1057
+
1058
+ ```
1059
+
1060
+ [⬆️ Back to top](#toc)
1061
+ ---
1062
+
1016
1063
  #### `ResultAsync.match` (method)
1017
1064
 
1018
1065
  Given 2 functions (one for the `Ok` variant and one for the `Err` variant) execute the function that matches the `ResultAsync` variant.
@@ -1298,10 +1345,6 @@ _unsafeUnwrapErr({
1298
1345
 
1299
1346
  ---
1300
1347
 
1301
- If you find this package useful, please consider [sponsoring me](https://github.com/sponsors/supermacro/) or simply [buying me a coffee](https://ko-fi.com/gdelgado)!
1302
-
1303
- ---
1304
-
1305
1348
  ### License
1306
1349
 
1307
1350
  The resultar project is available as open source under the terms of the [MIT license](https://github.com/inaiat/resultar/blob/master/LICENSE).
@@ -426,4 +426,4 @@ export {
426
426
  fromThrowable,
427
427
  safeTry
428
428
  };
429
- //# sourceMappingURL=chunk-ZFWL27DT.js.map
429
+ //# sourceMappingURL=chunk-5JXI4NLV.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils.ts","../src/result.ts","../src/result-async.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/ban-types */\nimport { ResultAsync } from './result-async.js'\nimport { Result, ok, err } 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>\n ? 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\n ? V\n : never\n : never\n) extends (_: unknown) => infer W\n ? [...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 }\n ? L extends number\n ? number extends L\n ? 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 []\n ? never\n : NeverArrayToNever extends 1\n ? T extends [never, ...infer Rest]\n ? [EmptyArrayToNever<Rest>] extends [never]\n ? 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.\n type 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[]\n ? PR extends unknown[]\n ? 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 ? []\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]\n ? [UnknownMembersToNever<L>, UnknownMembersToNever<R>]\n : Transpose<CollectResults<T>, [], Depth> extends []\n ? [[], []]\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]\n ? Result<EmptyArrayToNever<Oks>, EmptyArrayToNever<Errs>>\n : never\n\nconst appendValueToEndOfList = <T>(value: T) => (list: T[]): T[] => [...list, value]\n\nexport type CombineResults<\n T extends ReadonlyArray<Result<unknown, unknown>>,\n> = IsLiteralArray<T> extends 1\n ? 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\n ? 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 resultList.reduce<Result<T[], E>>( // eslint-disable-line unicorn/no-array-reduce\n (acc, result) =>\n acc.isOk()\n ? (result.isErr()\n ? err(result.error)\n : acc.map(appendValueToEndOfList(result.value)))\n : acc,\n ok([]),\n )\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 resultList.reduce<Result<T[], E[]>>( // eslint-disable-line unicorn/no-array-reduce\n (acc, result) =>\n result.isErr()\n ? (acc.isErr()\n ? err([...acc.error, result.error])\n : err([result.error]))\n : (acc.isErr()\n ? acc\n : ok([...acc.value, result.value])),\n ok([]),\n )\n\n","import {\n CombineResults, CombineResultsWithAllErrorsArray, combineResultList, combineResultListWithAllErrors,\n} from './utils.js'\nimport { ErrorConfig, createResultarError } from './error.js'\nimport { ResultAsync, errAsync } from './result-async.js'\n\nclass Ok<T> {\n readonly ok = true // eslint-disable-line @typescript-eslint/class-literal-property-style\n constructor(public readonly value: T) {}\n}\n\nclass Err<E> {\n readonly ok = false // eslint-disable-line @typescript-eslint/class-literal-property-style\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\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/**\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 static fromThrowable<Fn extends (...args: readonly any[]) => unknown, E>(\n fn: Fn,\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 static ok<T, E=never>(value: T): Result<T, E> {\n return new Result<T, E>(new Ok(value))\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, Y>(f: (t: T) => X): Result<X, E | Y>\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 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 /**\n * Takes an `Err` value and maps it to a `Result<T, SomeNewType>`.\n *\n * This is useful for error recovery.\n *\n *\n * @param f A function to apply to an `Err` value, leaving `Ok` values\n * untouched.\n */\n orElse<Y>(f: (t: E) => Result<T, Y>): Result<T, Y>\n orElse<Y>(f: (t: E) => Result<T, Y>): Result<T, E | Y> {\n if (this.state.ok) {\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 *\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` variant of `Result`.\n *\n * @param f The function to apply an `OK` value\n * @returns the result of applying `f` or an `Err` untouched\n */\n tap(f: (t: T) => void): Result<T, E> {\n if (this.state.ok) {\n try {\n f(this.value)\n } catch {\n // Dont do anything. Its just a tap\n }\n\n return ok(this.value)\n }\n\n return err(this.error)\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]() // eslint-disable-line no-use-extend-native/no-use-extend-native\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) // eslint-disable-line @typescript-eslint/no-throw-literal\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) // eslint-disable-line @typescript-eslint/no-throw-literal\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>,\n 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\nexport const ok = <T, E = never>(value: T): Result<T, E> => Result.ok(value)\nexport const err = <T = never, E = unknown>(error: E): Result<T, E> => Result.err(error)\nexport const fromThrowable = <Fn extends (...args: readonly any[]) => unknown, E>(\n fn: Fn,\n errorFn?: (e: any) => E,\n): (...args: Parameters<Fn>) => Result<ReturnType<Fn>, E> => Result.fromThrowable(fn, errorFn)\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\n","/* eslint-disable @typescript-eslint/ban-types */\nimport {\n Result,\n} from './result.js'\nimport {\n Combine,\n Dedup,\n EmptyArrayToNever,\n ExtractErrAsyncTypes,\n ExtractOkAsyncTypes,\n InferAsyncErrTypes, InferAsyncOkTypes, InferErrTypes, InferOkTypes,\n IsLiteralArray,\n MemberListOf,\n MembersToUnion,\n combineResultAsyncList,\n combineResultAsyncListWithAllErrors,\n} from './utils.js'\n\nexport class ResultAsync<T, E> implements PromiseLike<Result<T, E>> {\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 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 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 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 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 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 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 {\n // Dont do anything. Its just a tap\n }\n\n return okAsync(res.value)\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\nexport function fromSafePromise<T, E = never>(promise: PromiseLike<T>): ResultAsync<T, E>\nexport function fromSafePromise<T, E = never>(promise:\n| PromiseLike<T>\n| Promise<T>): ResultAsync<T, E> {\n return ResultAsync.fromSafePromise(promise)\n}\n\nexport function fromPromise<T, E>(promise: PromiseLike<T>, errorFn: (e: unknown) => E): ResultAsync<T, E>\nexport function fromPromise<T, E>(promise:\n| PromiseLike<T>\n| Promise<T>, errorFn: (e: unknown) => E): ResultAsync<T, E> {\n return ResultAsync.fromPromise(promise, errorFn)\n}\n\nexport function okAsync<T, E = never>(value: T): ResultAsync<T, E> {\n return new ResultAsync<T, E>(Promise.resolve(Result.ok(value)))\n}\n\nexport function errAsync<T = never, E = unknown>(error: E): ResultAsync<T, E> {\n return new ResultAsync<T, E>(Promise.resolve(Result.err(error)))\n}\n\nexport function fromThrowableAsync<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) => 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\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\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\n ? 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\n ? 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>\n ? HI extends Result<unknown, unknown>\n ? [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>\n ? HI extends Result<infer L, infer R>\n ? 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]\n ? 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[]\n ? 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]\n ? 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[]\n ? 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"],"mappings":";;;;;AAsNA,IAAM,yBAAyB,CAAI,UAAa,CAAC,SAAmB,CAAC,GAAG,MAAM,KAAK;AAoB5E,IAAM,yBAAyB,CACpC,oBAEA,YAAY,gBAAgB,QAAQ,IAAI,eAAe,CAAC,EAAE;AAAA,EACxD;AACF;AAKK,IAAM,oBAAoB,CAC/B,eAEA,WAAW;AAAA;AAAA,EACT,CAAC,KAAK,WACJ,IAAI,KAAK,IACJ,OAAO,MAAM,IACZ,IAAI,OAAO,KAAK,IAChB,IAAI,IAAI,uBAAuB,OAAO,KAAK,CAAC,IAC9C;AAAA,EACN,GAAG,CAAC,CAAC;AACP;AAOK,IAAM,sCAAsC,CACjD,oBACmC;AACnC,QAAM,IAAI,YAAY,gBAAgB,QAAQ,IAAI,eAAe,CAAC,EAAE;AAAA,IAClE;AAAA,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AEO,SAAS,mBACd,IACA,SACmC;AACnC,SAAO,IAAI,SAAS,IAAI;AAAA,KACrB,YAAY;AACX,UAAI;AACF,cAAM,IAAI,MAAM,GAAG,GAAG,IAAI;AAC1B,eAAOA,QAAO,GAAG,CAAC;AAAA,MACpB,SAAS,OAAO;AACd,cAAM,IAAI,UAAU,QAAQ,KAAK,IAAI;AACrC,eAAOA,QAAO,IAAI,CAAM;AAAA,MAC1B;AAAA,IACF,GAAG;AAAA,EACL;AACF;AAEO,SAAS,aACd,MACmB;AACnB,SAAO,IAAI;AAAA,KACR,YAAY;AACX,YAAM,IAAI,MAAM,KAAK,EAAE,KAAK;AAC5B,UAAI,EAAE,MAAM,KAAK,GAAG;AAClB,eAAO,QAAQ,EAAE,MAAM,KAAK;AAAA,MAC9B;AAEA,aAAO,SAAS,EAAE,MAAM,KAAK;AAAA,IAC/B,GAAG;AAAA,EACL;AACF;","names":["Result","Result","ok"]}
package/dist/error.d.cts CHANGED
@@ -1 +1 @@
1
- export { G as ErrorConfig, H as createResultarError } from './index-ph1sfvDU.cjs';
1
+ export { G as ErrorConfig, H as createResultarError } from './index-CC-8SXSn.cjs';
package/dist/error.d.ts CHANGED
@@ -1 +1 @@
1
- export { G as ErrorConfig, H as createResultarError } from './index-ph1sfvDU.js';
1
+ export { G as ErrorConfig, H as createResultarError } from './index-CC-8SXSn.js';
@@ -186,6 +186,12 @@ interface Resultable<T, E> {
186
186
  */
187
187
  _unsafeUnwrapErr(config?: ErrorConfig): E;
188
188
  }
189
+ /**
190
+ * A `Result` is a type that represents either success (`Ok`) or failure (`Err`).
191
+ * It is often used to replace exceptions or `null` returns.
192
+ * `Result` is often used to handle errors in a functional way.
193
+ * The `Result` type is often used to handle errors in a functional way.
194
+ */
189
195
  declare class Result<T, E> implements Resultable<T, E> {
190
196
  private readonly state;
191
197
  /**
@@ -346,7 +352,7 @@ declare class DisposableResult<T, E> implements Resultable<T, E>, Disposable {
346
352
  }
347
353
  declare const ok: <T, E = never>(value: T) => Result<T, E>;
348
354
  declare const err: <T = never, E = unknown>(error: E) => Result<T, E>;
349
- declare const fromThrowable: <Fn extends (...args: readonly any[]) => unknown, E>(fn: Fn, errorFn?: ((e: any) => E) | undefined) => (...args: Parameters<Fn>) => Result<ReturnType<Fn>, E>;
355
+ declare const fromThrowable: <Fn extends (...args: readonly any[]) => unknown, E>(fn: Fn, errorFn?: (e: any) => E) => (...args: Parameters<Fn>) => Result<ReturnType<Fn>, E>;
350
356
  /**
351
357
  * Evaluates the given generator to a Result returned or an Err yielded from it,
352
358
  * whichever comes first.
@@ -186,6 +186,12 @@ interface Resultable<T, E> {
186
186
  */
187
187
  _unsafeUnwrapErr(config?: ErrorConfig): E;
188
188
  }
189
+ /**
190
+ * A `Result` is a type that represents either success (`Ok`) or failure (`Err`).
191
+ * It is often used to replace exceptions or `null` returns.
192
+ * `Result` is often used to handle errors in a functional way.
193
+ * The `Result` type is often used to handle errors in a functional way.
194
+ */
189
195
  declare class Result<T, E> implements Resultable<T, E> {
190
196
  private readonly state;
191
197
  /**
@@ -346,7 +352,7 @@ declare class DisposableResult<T, E> implements Resultable<T, E>, Disposable {
346
352
  }
347
353
  declare const ok: <T, E = never>(value: T) => Result<T, E>;
348
354
  declare const err: <T = never, E = unknown>(error: E) => Result<T, E>;
349
- declare const fromThrowable: <Fn extends (...args: readonly any[]) => unknown, E>(fn: Fn, errorFn?: ((e: any) => E) | undefined) => (...args: Parameters<Fn>) => Result<ReturnType<Fn>, E>;
355
+ declare const fromThrowable: <Fn extends (...args: readonly any[]) => unknown, E>(fn: Fn, errorFn?: (e: any) => E) => (...args: Parameters<Fn>) => Result<ReturnType<Fn>, E>;
350
356
  /**
351
357
  * Evaluates the given generator to a Result returned or an Err yielded from it,
352
358
  * whichever comes first.
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/result-async.ts","../src/utils.ts","../src/error.ts","../src/result.ts"],"sourcesContent":["export * from './result.js'\nexport * from './result-async.js'\n","/* eslint-disable @typescript-eslint/ban-types */\nimport {\n Result,\n} from './result.js'\nimport {\n Combine,\n Dedup,\n EmptyArrayToNever,\n ExtractErrAsyncTypes,\n ExtractOkAsyncTypes,\n InferAsyncErrTypes, InferAsyncOkTypes, InferErrTypes, InferOkTypes,\n IsLiteralArray,\n MemberListOf,\n MembersToUnion,\n combineResultAsyncList,\n combineResultAsyncListWithAllErrors,\n} from './utils.js'\n\nexport class ResultAsync<T, E> implements PromiseLike<Result<T, E>> {\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 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 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 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 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 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 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 {\n // Dont do anything. Its just a tap\n }\n\n return okAsync(res.value)\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\nexport function fromSafePromise<T, E = never>(promise: PromiseLike<T>): ResultAsync<T, E>\nexport function fromSafePromise<T, E = never>(promise:\n| PromiseLike<T>\n| Promise<T>): ResultAsync<T, E> {\n return ResultAsync.fromSafePromise(promise)\n}\n\nexport function fromPromise<T, E>(promise: PromiseLike<T>, errorFn: (e: unknown) => E): ResultAsync<T, E>\nexport function fromPromise<T, E>(promise:\n| PromiseLike<T>\n| Promise<T>, errorFn: (e: unknown) => E): ResultAsync<T, E> {\n return ResultAsync.fromPromise(promise, errorFn)\n}\n\nexport function okAsync<T, E = never>(value: T): ResultAsync<T, E> {\n return new ResultAsync<T, E>(Promise.resolve(Result.ok(value)))\n}\n\nexport function errAsync<T = never, E = unknown>(error: E): ResultAsync<T, E> {\n return new ResultAsync<T, E>(Promise.resolve(Result.err(error)))\n}\n\nexport function fromThrowableAsync<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) => 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\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\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\n ? 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\n ? 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>\n ? HI extends Result<unknown, unknown>\n ? [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>\n ? HI extends Result<infer L, infer R>\n ? 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]\n ? 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[]\n ? 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]\n ? 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[]\n ? 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","/* eslint-disable @typescript-eslint/ban-types */\nimport { ResultAsync } from './result-async.js'\nimport { Result, ok, err } 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>\n ? 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\n ? V\n : never\n : never\n) extends (_: unknown) => infer W\n ? [...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 }\n ? L extends number\n ? number extends L\n ? 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 []\n ? never\n : NeverArrayToNever extends 1\n ? T extends [never, ...infer Rest]\n ? [EmptyArrayToNever<Rest>] extends [never]\n ? 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.\n type 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[]\n ? PR extends unknown[]\n ? 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 ? []\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]\n ? [UnknownMembersToNever<L>, UnknownMembersToNever<R>]\n : Transpose<CollectResults<T>, [], Depth> extends []\n ? [[], []]\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]\n ? Result<EmptyArrayToNever<Oks>, EmptyArrayToNever<Errs>>\n : never\n\nconst appendValueToEndOfList = <T>(value: T) => (list: T[]): T[] => [...list, value]\n\nexport type CombineResults<\n T extends ReadonlyArray<Result<unknown, unknown>>,\n> = IsLiteralArray<T> extends 1\n ? 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\n ? 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 resultList.reduce<Result<T[], E>>( // eslint-disable-line unicorn/no-array-reduce\n (acc, result) =>\n acc.isOk()\n ? (result.isErr()\n ? err(result.error)\n : acc.map(appendValueToEndOfList(result.value)))\n : acc,\n ok([]),\n )\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 resultList.reduce<Result<T[], E[]>>( // eslint-disable-line unicorn/no-array-reduce\n (acc, result) =>\n result.isErr()\n ? (acc.isErr()\n ? err([...acc.error, result.error])\n : err([result.error]))\n : (acc.isErr()\n ? acc\n : ok([...acc.value, result.value])),\n ok([]),\n )\n\n","import { 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","import {\n CombineResults, CombineResultsWithAllErrorsArray, combineResultList, combineResultListWithAllErrors,\n} from './utils.js'\nimport { ErrorConfig, createResultarError } from './error.js'\nimport { ResultAsync, errAsync } from './result-async.js'\n\nclass Ok<T> {\n readonly ok = true // eslint-disable-line @typescript-eslint/class-literal-property-style\n constructor(public readonly value: T) {}\n}\n\nclass Err<E> {\n readonly ok = false // eslint-disable-line @typescript-eslint/class-literal-property-style\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\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\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 static fromThrowable<Fn extends (...args: readonly any[]) => unknown, E>(\n fn: Fn,\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 static ok<T, E=never>(value: T): Result<T, E> {\n return new Result<T, E>(new Ok(value))\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, Y>(f: (t: T) => X): Result<X, E | Y>\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 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 /**\n * Takes an `Err` value and maps it to a `Result<T, SomeNewType>`.\n *\n * This is useful for error recovery.\n *\n *\n * @param f A function to apply to an `Err` value, leaving `Ok` values\n * untouched.\n */\n orElse<Y>(f: (t: E) => Result<T, Y>): Result<T, Y>\n orElse<Y>(f: (t: E) => Result<T, Y>): Result<T, E | Y> {\n if (this.state.ok) {\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 *\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` variant of `Result`.\n *\n * @param f The function to apply an `OK` value\n * @returns the result of applying `f` or an `Err` untouched\n */\n tap(f: (t: T) => void): Result<T, E> {\n if (this.state.ok) {\n try {\n f(this.value)\n } catch {\n // Dont do anything. Its just a tap\n }\n\n return ok(this.value)\n }\n\n return err(this.error)\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]() // eslint-disable-line no-use-extend-native/no-use-extend-native\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) // eslint-disable-line @typescript-eslint/no-throw-literal\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) // eslint-disable-line @typescript-eslint/no-throw-literal\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>,\n 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\nexport const ok = <T, E = never>(value: T): Result<T, E> => Result.ok(value)\nexport const err = <T = never, E = unknown>(error: E): Result<T, E> => Result.err(error)\nexport const fromThrowable = <Fn extends (...args: readonly any[]) => unknown, E>(\n fn: Fn,\n errorFn?: (e: any) => E,\n): (...args: Parameters<Fn>) => Result<ReturnType<Fn>, E> => Result.fromThrowable(fn, errorFn)\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\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACkBO,IAAM,cAAN,MAAM,aAAuD;AAAA,EAElE,OAAO,gB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K;AACtB,MAAI,aAAa,SAAS;AACxB,WAAO,EAAE,KAAK,OAAK,EAAE,KAAK;AAAA,EAC5B;AAEA,SAAO,EAAE;AACX;","names":["ok"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/result-async.ts","../src/utils.ts","../src/error.ts","../src/result.ts"],"sourcesContent":["export * from './result.js'\nexport * from './result-async.js'\n","/* eslint-disable @typescript-eslint/ban-types */\nimport {\n Result,\n} from './result.js'\nimport {\n Combine,\n Dedup,\n EmptyArrayToNever,\n ExtractErrAsyncTypes,\n ExtractOkAsyncTypes,\n InferAsyncErrTypes, InferAsyncOkTypes, InferErrTypes, InferOkTypes,\n IsLiteralArray,\n MemberListOf,\n MembersToUnion,\n combineResultAsyncList,\n combineResultAsyncListWithAllErrors,\n} from './utils.js'\n\nexport class ResultAsync<T, E> implements PromiseLike<Result<T, E>> {\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 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 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 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 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 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 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 {\n // Dont do anything. Its just a tap\n }\n\n return okAsync(res.value)\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\nexport function fromSafePromise<T, E = never>(promise: PromiseLike<T>): ResultAsync<T, E>\nexport function fromSafePromise<T, E = never>(promise:\n| PromiseLike<T>\n| Promise<T>): ResultAsync<T, E> {\n return ResultAsync.fromSafePromise(promise)\n}\n\nexport function fromPromise<T, E>(promise: PromiseLike<T>, errorFn: (e: unknown) => E): ResultAsync<T, E>\nexport function fromPromise<T, E>(promise:\n| PromiseLike<T>\n| Promise<T>, errorFn: (e: unknown) => E): ResultAsync<T, E> {\n return ResultAsync.fromPromise(promise, errorFn)\n}\n\nexport function okAsync<T, E = never>(value: T): ResultAsync<T, E> {\n return new ResultAsync<T, E>(Promise.resolve(Result.ok(value)))\n}\n\nexport function errAsync<T = never, E = unknown>(error: E): ResultAsync<T, E> {\n return new ResultAsync<T, E>(Promise.resolve(Result.err(error)))\n}\n\nexport function fromThrowableAsync<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) => 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\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\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\n ? 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\n ? 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>\n ? HI extends Result<unknown, unknown>\n ? [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>\n ? HI extends Result<infer L, infer R>\n ? 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]\n ? 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[]\n ? 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]\n ? 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[]\n ? 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","/* eslint-disable @typescript-eslint/ban-types */\nimport { ResultAsync } from './result-async.js'\nimport { Result, ok, err } 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>\n ? 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\n ? V\n : never\n : never\n) extends (_: unknown) => infer W\n ? [...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 }\n ? L extends number\n ? number extends L\n ? 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 []\n ? never\n : NeverArrayToNever extends 1\n ? T extends [never, ...infer Rest]\n ? [EmptyArrayToNever<Rest>] extends [never]\n ? 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.\n type 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[]\n ? PR extends unknown[]\n ? 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 ? []\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]\n ? [UnknownMembersToNever<L>, UnknownMembersToNever<R>]\n : Transpose<CollectResults<T>, [], Depth> extends []\n ? [[], []]\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]\n ? Result<EmptyArrayToNever<Oks>, EmptyArrayToNever<Errs>>\n : never\n\nconst appendValueToEndOfList = <T>(value: T) => (list: T[]): T[] => [...list, value]\n\nexport type CombineResults<\n T extends ReadonlyArray<Result<unknown, unknown>>,\n> = IsLiteralArray<T> extends 1\n ? 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\n ? 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 resultList.reduce<Result<T[], E>>( // eslint-disable-line unicorn/no-array-reduce\n (acc, result) =>\n acc.isOk()\n ? (result.isErr()\n ? err(result.error)\n : acc.map(appendValueToEndOfList(result.value)))\n : acc,\n ok([]),\n )\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 resultList.reduce<Result<T[], E[]>>( // eslint-disable-line unicorn/no-array-reduce\n (acc, result) =>\n result.isErr()\n ? (acc.isErr()\n ? err([...acc.error, result.error])\n : err([result.error]))\n : (acc.isErr()\n ? acc\n : ok([...acc.value, result.value])),\n ok([]),\n )\n\n","import { 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","import {\n CombineResults, CombineResultsWithAllErrorsArray, combineResultList, combineResultListWithAllErrors,\n} from './utils.js'\nimport { ErrorConfig, createResultarError } from './error.js'\nimport { ResultAsync, errAsync } from './result-async.js'\n\nclass Ok<T> {\n readonly ok = true // eslint-disable-line @typescript-eslint/class-literal-property-style\n constructor(public readonly value: T) {}\n}\n\nclass Err<E> {\n readonly ok = false // eslint-disable-line @typescript-eslint/class-literal-property-style\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\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/**\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 static fromThrowable<Fn extends (...args: readonly any[]) => unknown, E>(\n fn: Fn,\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 static ok<T, E=never>(value: T): Result<T, E> {\n return new Result<T, E>(new Ok(value))\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, Y>(f: (t: T) => X): Result<X, E | Y>\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 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 /**\n * Takes an `Err` value and maps it to a `Result<T, SomeNewType>`.\n *\n * This is useful for error recovery.\n *\n *\n * @param f A function to apply to an `Err` value, leaving `Ok` values\n * untouched.\n */\n orElse<Y>(f: (t: E) => Result<T, Y>): Result<T, Y>\n orElse<Y>(f: (t: E) => Result<T, Y>): Result<T, E | Y> {\n if (this.state.ok) {\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 *\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` variant of `Result`.\n *\n * @param f The function to apply an `OK` value\n * @returns the result of applying `f` or an `Err` untouched\n */\n tap(f: (t: T) => void): Result<T, E> {\n if (this.state.ok) {\n try {\n f(this.value)\n } catch {\n // Dont do anything. Its just a tap\n }\n\n return ok(this.value)\n }\n\n return err(this.error)\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]() // eslint-disable-line no-use-extend-native/no-use-extend-native\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) // eslint-disable-line @typescript-eslint/no-throw-literal\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) // eslint-disable-line @typescript-eslint/no-throw-literal\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>,\n 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\nexport const ok = <T, E = never>(value: T): Result<T, E> => Result.ok(value)\nexport const err = <T = never, E = unknown>(error: E): Result<T, E> => Result.err(error)\nexport const fromThrowable = <Fn extends (...args: readonly any[]) => unknown, E>(\n fn: Fn,\n errorFn?: (e: any) => E,\n): (...args: Parameters<Fn>) => Result<ReturnType<Fn>, E> => Result.fromThrowable(fn, errorFn)\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\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACkBO,IAAM,cAAN,MAAM,aAAuD;AAAA,EAElE,OAAO,gBAA8B,SAAwC;AAC3E,UAAM,aAAa,QAChB,KAAK,CAAC,UAAa,OAAO,GAAG,KAAK,CAAC;AAEtC,WAAO,IAAI,aAAkB,UAAU;AAAA,EACzC;AAAA,EAGA,OAAO,YAAkB,SAAqB,SAA+C;AAC3F,UAAM,aAAa,QAChB,KAAK,CAAC,UAAa,OAAO,GAAG,KAAK,CAAC,EACnC,MAAM,WAAS,OAAO,IAAI,QAAQ,KAAK,CAAC,CAAC;AAE5C,WAAO,IAAI,aAAkB,UAAU;AAAA,EACzC;AAAA,EAQA,OAAO,QACL,iBACwB;AACxB,WAAQ,uBAAuB,eAAe;AAAA,EAChD;AAAA,EAQA,OAAO,qBACL,iBAC0C;AAC1C,WAAO;AAAA,MACL;AAAA,IACF;AAAA,EACF;AAAA,EAEiB;AAAA,EAEjB,YAAY,KAA4B;AACtC,SAAK,eAAe;AAAA,EACtB;AAAA,EAEA,KACE,iBACA,iBACoB;AACpB,WAAO,KAAK,aAAa,KAAK,iBAAiB,eAAe;AAAA,EAChE;AAAA,EAEA,OAAU,GAAgD;AACxD,WAAO,IAAI,aAAkB,KAAK,aAAa,KAAK,OAAM,QAAO;AAC/D,UAAI,IAAI,KAAK,GAAG;AACd,eAAO,QAAQ,IAAI,KAAK;AAAA,MAC1B;AAEA,aAAO,SAAS,MAAM,EAAE,IAAI,KAAK,CAAC;AAAA,IACpC,CAAC,CAAC;AA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AK,OAAO,SAAS,YAAY;AAAA,EAC1C;AAAA,EAEA,CAAC,OAAO,OAAO,IAAU;AACvB,SAAK,UAAU,KAAK,OAAO,OAAO,KAAK,OAAO,KAAK;AAAA,EACrD;AACF;AAEO,IAAM,KAAK,CAAe,UAA2B,OAAO,GAAG,KAAK;AACpE,IAAM,MAAM,CAAyB,UAA2B,OAAO,IAAI,KAAK;AAChF,IAAM,gBAAgB,CAC3B,IACA,YAC2D,OAAO,cAAc,IAAI,OAAO;AAiCtF,SAAS,QACd,MAGsC;AACtC,QAAM,IAAI,KAAK,EAAE,KAAK;AACtB,MAAI,aAAa,SAAS;AACxB,WAAO,EAAE,KAAK,OAAK,EAAE,KAAK;AAAA,EAC5B;AAEA,SAAO,EAAE;AACX;","names":["ok"]}
package/dist/index.d.cts CHANGED
@@ -1 +1 @@
1
- export { C as CombineResultAsyncs, c as CombineResultsWithAllErrorsArrayAsync, y as DisposableResult, x as Result, R as ResultAsync, A as err, e as errAsync, a as fromPromise, f as fromSafePromise, B as fromThrowable, b as fromThrowableAsync, z as ok, o as okAsync, F as safeTry, s as safeTryAsync } from './index-ph1sfvDU.cjs';
1
+ export { C as CombineResultAsyncs, c as CombineResultsWithAllErrorsArrayAsync, y as DisposableResult, x as Result, R as ResultAsync, A as err, e as errAsync, a as fromPromise, f as fromSafePromise, B as fromThrowable, b as fromThrowableAsync, z as ok, o as okAsync, F as safeTry, s as safeTryAsync } from './index-CC-8SXSn.cjs';
package/dist/index.d.ts CHANGED
@@ -1 +1 @@
1
- export { C as CombineResultAsyncs, c as CombineResultsWithAllErrorsArrayAsync, y as DisposableResult, x as Result, R as ResultAsync, A as err, e as errAsync, a as fromPromise, f as fromSafePromise, B as fromThrowable, b as fromThrowableAsync, z as ok, o as okAsync, F as safeTry, s as safeTryAsync } from './index-ph1sfvDU.js';
1
+ export { C as CombineResultAsyncs, c as CombineResultsWithAllErrorsArrayAsync, y as DisposableResult, x as Result, R as ResultAsync, A as err, e as errAsync, a as fromPromise, f as fromSafePromise, B as fromThrowable, b as fromThrowableAsync, z as ok, o as okAsync, F as safeTry, s as safeTryAsync } from './index-CC-8SXSn.js';
package/dist/index.js CHANGED
@@ -12,7 +12,7 @@ import {
12
12
  okAsync,
13
13
  safeTry,
14
14
  safeTryAsync
15
- } from "./chunk-ZFWL27DT.js";
15
+ } from "./chunk-5JXI4NLV.js";
16
16
  import "./chunk-FBVQYZXO.js";
17
17
  export {
18
18
  DisposableResult,