@praha/byethrow 0.7.0 → 0.7.2

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.
Files changed (53) hide show
  1. package/dist/cjs/exports.d.ts +23 -23
  2. package/dist/cjs/functions/and-then.d.ts +1 -1
  3. package/dist/cjs/functions/and-through.d.ts +1 -1
  4. package/dist/cjs/functions/assert-failure.d.ts +1 -1
  5. package/dist/cjs/functions/assert-success.d.ts +1 -1
  6. package/dist/cjs/functions/bind.d.ts +1 -1
  7. package/dist/cjs/functions/combine.d.ts +1 -1
  8. package/dist/cjs/functions/do.d.ts +1 -1
  9. package/dist/cjs/functions/fail.d.ts +1 -1
  10. package/dist/cjs/functions/inspect-error.cjs +4 -1
  11. package/dist/cjs/functions/inspect-error.d.ts +3 -3
  12. package/dist/cjs/functions/inspect.cjs +4 -1
  13. package/dist/cjs/functions/inspect.d.ts +3 -3
  14. package/dist/cjs/functions/is-failure.d.ts +1 -1
  15. package/dist/cjs/functions/is-result.d.ts +1 -1
  16. package/dist/cjs/functions/is-success.d.ts +1 -1
  17. package/dist/cjs/functions/map-error.d.ts +1 -1
  18. package/dist/cjs/functions/map.d.ts +1 -1
  19. package/dist/cjs/functions/or-else.d.ts +1 -1
  20. package/dist/cjs/functions/parse.d.ts +1 -1
  21. package/dist/cjs/functions/succeed.d.ts +1 -1
  22. package/dist/cjs/functions/try.d.ts +1 -1
  23. package/dist/cjs/functions/unwrap-error.d.ts +2 -2
  24. package/dist/cjs/functions/unwrap.d.ts +2 -2
  25. package/dist/cjs/index.d.ts +2 -2
  26. package/dist/cjs/result.d.ts +1 -1
  27. package/dist/esm/exports.d.ts +23 -23
  28. package/dist/esm/functions/and-then.d.ts +1 -1
  29. package/dist/esm/functions/and-through.d.ts +1 -1
  30. package/dist/esm/functions/assert-failure.d.ts +1 -1
  31. package/dist/esm/functions/assert-success.d.ts +1 -1
  32. package/dist/esm/functions/bind.d.ts +1 -1
  33. package/dist/esm/functions/combine.d.ts +1 -1
  34. package/dist/esm/functions/do.d.ts +1 -1
  35. package/dist/esm/functions/fail.d.ts +1 -1
  36. package/dist/esm/functions/inspect-error.d.ts +3 -3
  37. package/dist/esm/functions/inspect-error.js +4 -1
  38. package/dist/esm/functions/inspect.d.ts +3 -3
  39. package/dist/esm/functions/inspect.js +4 -1
  40. package/dist/esm/functions/is-failure.d.ts +1 -1
  41. package/dist/esm/functions/is-result.d.ts +1 -1
  42. package/dist/esm/functions/is-success.d.ts +1 -1
  43. package/dist/esm/functions/map-error.d.ts +1 -1
  44. package/dist/esm/functions/map.d.ts +1 -1
  45. package/dist/esm/functions/or-else.d.ts +1 -1
  46. package/dist/esm/functions/parse.d.ts +1 -1
  47. package/dist/esm/functions/succeed.d.ts +1 -1
  48. package/dist/esm/functions/try.d.ts +1 -1
  49. package/dist/esm/functions/unwrap-error.d.ts +2 -2
  50. package/dist/esm/functions/unwrap.d.ts +2 -2
  51. package/dist/esm/index.d.ts +2 -2
  52. package/dist/esm/result.d.ts +1 -1
  53. package/package.json +6 -6
@@ -1,23 +1,23 @@
1
- export * from './result';
2
- export * from './functions/and-then';
3
- export * from './functions/and-through';
4
- export * from './functions/assert-failure';
5
- export * from './functions/assert-success';
6
- export * from './functions/bind';
7
- export * from './functions/combine';
8
- export * from './functions/do';
9
- export * from './functions/fail';
10
- export * from './functions/inspect';
11
- export * from './functions/inspect-error';
12
- export * from './functions/is-failure';
13
- export * from './functions/is-result';
14
- export * from './functions/is-success';
15
- export * from './functions/map';
16
- export * from './functions/map-error';
17
- export * from './functions/or-else';
18
- export * from './functions/parse';
19
- export * from './functions/pipe';
20
- export * from './functions/succeed';
21
- export * from './functions/try';
22
- export * from './functions/unwrap';
23
- export * from './functions/unwrap-error';
1
+ export * from './result.js';
2
+ export * from './functions/and-then.js';
3
+ export * from './functions/and-through.js';
4
+ export * from './functions/assert-failure.js';
5
+ export * from './functions/assert-success.js';
6
+ export * from './functions/bind.js';
7
+ export * from './functions/combine.js';
8
+ export * from './functions/do.js';
9
+ export * from './functions/fail.js';
10
+ export * from './functions/inspect.js';
11
+ export * from './functions/inspect-error.js';
12
+ export * from './functions/is-failure.js';
13
+ export * from './functions/is-result.js';
14
+ export * from './functions/is-success.js';
15
+ export * from './functions/map.js';
16
+ export * from './functions/map-error.js';
17
+ export * from './functions/or-else.js';
18
+ export * from './functions/parse.js';
19
+ export * from './functions/pipe.js';
20
+ export * from './functions/succeed.js';
21
+ export * from './functions/try.js';
22
+ export * from './functions/unwrap.js';
23
+ export * from './functions/unwrap-error.js';
@@ -1,4 +1,4 @@
1
- import type { InferFailure, InferSuccess, ResultFor, ResultMaybeAsync } from '../result';
1
+ import type { InferFailure, InferSuccess, ResultFor, ResultMaybeAsync } from '../result.js';
2
2
  /**
3
3
  * Chains the next computation using the success value of a {@link Result} or {@link ResultAsync}.
4
4
  * If the original result is a {@link Failure}, it is returned unchanged.
@@ -1,4 +1,4 @@
1
- import type { InferFailure, InferSuccess, ResultFor, ResultMaybeAsync } from '../result';
1
+ import type { InferFailure, InferSuccess, ResultFor, ResultMaybeAsync } from '../result.js';
2
2
  /**
3
3
  * Runs an additional computation using the success value of a {@link Result} or {@link ResultAsync},
4
4
  * but **returns the original result** if the additional computation is successful.
@@ -1,4 +1,4 @@
1
- import type { Failure, InferFailure, Result, ResultAsync } from '../result';
1
+ import type { Failure, InferFailure, Result, ResultAsync } from '../result.js';
2
2
  /**
3
3
  * Asserts that a {@link Result} or {@link ResultAsync} is a {@link Failure} and returns it.
4
4
  * If the result is a {@link Success}, throws an error.
@@ -1,4 +1,4 @@
1
- import type { InferSuccess, Result, ResultAsync, Success } from '../result';
1
+ import type { InferSuccess, Result, ResultAsync, Success } from '../result.js';
2
2
  /**
3
3
  * Asserts that a {@link Result} or {@link ResultAsync} is a {@link Success} and returns it.
4
4
  * If the result is a {@link Failure}, throws an error.
@@ -1,4 +1,4 @@
1
- import type { InferFailure, InferSuccess, ResultFor, ResultMaybeAsync } from '../result';
1
+ import type { InferFailure, InferSuccess, ResultFor, ResultMaybeAsync } from '../result.js';
2
2
  /**
3
3
  * Chains another {@link Result}-producing computation and **merges its success value**
4
4
  * into the existing object under the specified key.
@@ -1,4 +1,4 @@
1
- import type { InferFailure, InferSuccess, ResultFor, ResultMaybeAsync } from '../result';
1
+ import type { InferFailure, InferSuccess, ResultFor, ResultMaybeAsync } from '../result.js';
2
2
  /**
3
3
  * Combines multiple {@link Result} or {@link ResultAsync} values into a single result.
4
4
  * If all inputs are {@link Success}, returns a {@link Success} with combined values.
@@ -13,5 +13,5 @@
13
13
  *
14
14
  * @category Creators
15
15
  */
16
- declare const do_: () => import("../result").Result<{}, never>;
16
+ declare const do_: () => import("../result.js").Result<{}, never>;
17
17
  export { do_ as do };
@@ -1,4 +1,4 @@
1
- import type { ResultFor } from '../result';
1
+ import type { ResultFor } from '../result.js';
2
2
  /**
3
3
  * Creates a {@link Failure} result from a given error.
4
4
  * Automatically wraps the error in a `Promise` if it is asynchronous.
@@ -30,7 +30,10 @@ const external_is_failure_cjs_namespaceObject = require("./is-failure.cjs");
30
30
  const is_promise_cjs_namespaceObject = require("../internals/helpers/is-promise.cjs");
31
31
  const inspectError = (fn)=>(result)=>{
32
32
  const apply = (r)=>{
33
- if ((0, external_is_failure_cjs_namespaceObject.isFailure)(r)) fn(r.error);
33
+ if ((0, external_is_failure_cjs_namespaceObject.isFailure)(r)) {
34
+ const next = fn(r.error);
35
+ if ((0, is_promise_cjs_namespaceObject.isPromise)(next)) return next.then(()=>r);
36
+ }
34
37
  return r;
35
38
  };
36
39
  return (0, is_promise_cjs_namespaceObject.isPromise)(result) ? result.then(apply) : apply(result);
@@ -1,4 +1,4 @@
1
- import type { InferFailure, ResultMaybeAsync } from '../result';
1
+ import type { InferFailure, InferSuccess, ResultFor, ResultMaybeAsync } from '../result.js';
2
2
  /**
3
3
  * Executes a side effect function on the error value of a {@link Result} or {@link ResultAsync},
4
4
  * without modifying the original result. This is useful for debugging, logging, or performing
@@ -37,6 +37,6 @@ import type { InferFailure, ResultMaybeAsync } from '../result';
37
37
  * @category Combinators
38
38
  */
39
39
  export declare const inspectError: {
40
- <R1 extends ResultMaybeAsync<any, any>>(fn: (a: InferFailure<R1>) => unknown): (result: R1) => R1;
41
- <F extends (a: any) => unknown>(fn: F): <R1 extends ResultMaybeAsync<any, Parameters<F>[0]>>(result: R1) => R1;
40
+ <R1 extends ResultMaybeAsync<any, any>, R2>(fn: (a: InferFailure<R1>) => R2): (result: R1) => ResultFor<R1 | R2, InferSuccess<R1>, InferFailure<R1>>;
41
+ <F extends (a: any) => unknown>(fn: F): <R1 extends ResultMaybeAsync<any, Parameters<F>[0]>>(result: R1) => ResultFor<R1 | ReturnType<F>, InferSuccess<R1>, InferFailure<R1>>;
42
42
  };
@@ -30,7 +30,10 @@ const external_is_success_cjs_namespaceObject = require("./is-success.cjs");
30
30
  const is_promise_cjs_namespaceObject = require("../internals/helpers/is-promise.cjs");
31
31
  const inspect = (fn)=>(result)=>{
32
32
  const apply = (r)=>{
33
- if ((0, external_is_success_cjs_namespaceObject.isSuccess)(r)) fn(r.value);
33
+ if ((0, external_is_success_cjs_namespaceObject.isSuccess)(r)) {
34
+ const next = fn(r.value);
35
+ if ((0, is_promise_cjs_namespaceObject.isPromise)(next)) return next.then(()=>r);
36
+ }
34
37
  return r;
35
38
  };
36
39
  return (0, is_promise_cjs_namespaceObject.isPromise)(result) ? result.then(apply) : apply(result);
@@ -1,4 +1,4 @@
1
- import type { InferSuccess, ResultMaybeAsync } from '../result';
1
+ import type { InferFailure, InferSuccess, ResultFor, ResultMaybeAsync } from '../result.js';
2
2
  /**
3
3
  * Executes a side effect function on the success value of a {@link Result} or {@link ResultAsync},
4
4
  * without modifying the original result. This is useful for debugging, logging, or performing
@@ -37,6 +37,6 @@ import type { InferSuccess, ResultMaybeAsync } from '../result';
37
37
  * @category Combinators
38
38
  */
39
39
  export declare const inspect: {
40
- <R1 extends ResultMaybeAsync<any, any>>(fn: (a: InferSuccess<R1>) => unknown): (result: R1) => R1;
41
- <F extends (a: any) => unknown>(fn: F): <R1 extends ResultMaybeAsync<Parameters<F>[0], any>>(result: R1) => R1;
40
+ <R1 extends ResultMaybeAsync<any, any>, R2>(fn: (a: InferSuccess<R1>) => R2): (result: R1) => ResultFor<R1 | R2, InferSuccess<R1>, InferFailure<R1>>;
41
+ <F extends (a: any) => unknown>(fn: F): <R1 extends ResultMaybeAsync<Parameters<F>[0], any>>(result: R1) => ResultFor<R1 | ReturnType<F>, InferSuccess<R1>, InferFailure<R1>>;
42
42
  };
@@ -1,4 +1,4 @@
1
- import type { Failure, Result } from '../result';
1
+ import type { Failure, Result } from '../result.js';
2
2
  /**
3
3
  * Type guard to check if a {@link Result} is a {@link Failure}.
4
4
  *
@@ -1,4 +1,4 @@
1
- import type { Result } from '../result';
1
+ import type { Result } from '../result.js';
2
2
  /**
3
3
  * Type guard to check if a value is a {@link Result}.
4
4
  *
@@ -1,4 +1,4 @@
1
- import type { Result, Success } from '../result';
1
+ import type { Result, Success } from '../result.js';
2
2
  /**
3
3
  * Type guard to check if a {@link Result} is a {@link Success}.
4
4
  *
@@ -1,4 +1,4 @@
1
- import type { InferFailure, InferSuccess, ResultFor, ResultMaybeAsync } from '../result';
1
+ import type { InferFailure, InferSuccess, ResultFor, ResultMaybeAsync } from '../result.js';
2
2
  /**
3
3
  * Applies a transformation function to the error value of a {@link Result} or {@link ResultAsync}.
4
4
  * If the input is a {@link Success}, it will be returned unchanged.
@@ -1,4 +1,4 @@
1
- import type { InferFailure, InferSuccess, ResultFor, ResultMaybeAsync } from '../result';
1
+ import type { InferFailure, InferSuccess, ResultFor, ResultMaybeAsync } from '../result.js';
2
2
  /**
3
3
  * Applies a transformation function to the success value of a {@link Result} or {@link ResultAsync}.
4
4
  * If the input is a {@link Failure}, it will be returned unchanged.
@@ -1,4 +1,4 @@
1
- import type { InferFailure, InferSuccess, ResultFor, ResultMaybeAsync } from '../result';
1
+ import type { InferFailure, InferSuccess, ResultFor, ResultMaybeAsync } from '../result.js';
2
2
  /**
3
3
  * Chains the next computation using the error value of a {@link Result} or {@link ResultAsync}.
4
4
  * If the original result is a {@link Success}, it is returned unchanged.
@@ -1,4 +1,4 @@
1
- import type { Result } from '../result';
1
+ import type { Result } from '../result.js';
2
2
  import type { StandardSchemaV1 } from '@standard-schema/spec';
3
3
  /**
4
4
  * Parses a value using a {@link https://github.com/standard-schema/standard-schema Standard Schema} compatible schema.
@@ -1,4 +1,4 @@
1
- import type { ResultFor } from '../result';
1
+ import type { ResultFor } from '../result.js';
2
2
  /**
3
3
  * Creates a {@link Success} result from a given value.
4
4
  * Automatically wraps the value in a `Promise` if it is asynchronous.
@@ -1,4 +1,4 @@
1
- import type { Result, ResultAsync } from '../result';
1
+ import type { Result, ResultAsync } from '../result.js';
2
2
  /**
3
3
  * Wraps a function execution (sync or async) or a Promise in a {@link Result} or {@link ResultAsync} type,
4
4
  * capturing errors and returning them in a structured way.
@@ -1,5 +1,5 @@
1
- import type { HasPromise } from '../internals/types/has-promise';
2
- import type { InferFailure, ResultMaybeAsync } from '../result';
1
+ import type { HasPromise } from '../internals/types/has-promise.js';
2
+ import type { InferFailure, ResultMaybeAsync } from '../result.js';
3
3
  /**
4
4
  * Extracts the error value from a {@link Result} or {@link ResultAsync}.
5
5
  *
@@ -1,5 +1,5 @@
1
- import type { HasPromise } from '../internals/types/has-promise';
2
- import type { InferSuccess, ResultMaybeAsync } from '../result';
1
+ import type { HasPromise } from '../internals/types/has-promise.js';
2
+ import type { InferSuccess, ResultMaybeAsync } from '../result.js';
3
3
  /**
4
4
  * Extracts the success value from a {@link Result} or {@link ResultAsync}.
5
5
  *
@@ -62,8 +62,8 @@
62
62
  * }
63
63
  * ```
64
64
  */
65
- export * as Result from './exports';
65
+ export * as Result from './exports.js';
66
66
  /**
67
67
  * Shorthand alias for {@link Result}.
68
68
  */
69
- export * as R from './exports';
69
+ export * as R from './exports.js';
@@ -1,4 +1,4 @@
1
- import type { HasPromise } from './internals/types/has-promise';
1
+ import type { HasPromise } from './internals/types/has-promise.js';
2
2
  /**
3
3
  * Represents a successful result.
4
4
  *
@@ -1,23 +1,23 @@
1
- export * from './result';
2
- export * from './functions/and-then';
3
- export * from './functions/and-through';
4
- export * from './functions/assert-failure';
5
- export * from './functions/assert-success';
6
- export * from './functions/bind';
7
- export * from './functions/combine';
8
- export * from './functions/do';
9
- export * from './functions/fail';
10
- export * from './functions/inspect';
11
- export * from './functions/inspect-error';
12
- export * from './functions/is-failure';
13
- export * from './functions/is-result';
14
- export * from './functions/is-success';
15
- export * from './functions/map';
16
- export * from './functions/map-error';
17
- export * from './functions/or-else';
18
- export * from './functions/parse';
19
- export * from './functions/pipe';
20
- export * from './functions/succeed';
21
- export * from './functions/try';
22
- export * from './functions/unwrap';
23
- export * from './functions/unwrap-error';
1
+ export * from './result.js';
2
+ export * from './functions/and-then.js';
3
+ export * from './functions/and-through.js';
4
+ export * from './functions/assert-failure.js';
5
+ export * from './functions/assert-success.js';
6
+ export * from './functions/bind.js';
7
+ export * from './functions/combine.js';
8
+ export * from './functions/do.js';
9
+ export * from './functions/fail.js';
10
+ export * from './functions/inspect.js';
11
+ export * from './functions/inspect-error.js';
12
+ export * from './functions/is-failure.js';
13
+ export * from './functions/is-result.js';
14
+ export * from './functions/is-success.js';
15
+ export * from './functions/map.js';
16
+ export * from './functions/map-error.js';
17
+ export * from './functions/or-else.js';
18
+ export * from './functions/parse.js';
19
+ export * from './functions/pipe.js';
20
+ export * from './functions/succeed.js';
21
+ export * from './functions/try.js';
22
+ export * from './functions/unwrap.js';
23
+ export * from './functions/unwrap-error.js';
@@ -1,4 +1,4 @@
1
- import type { InferFailure, InferSuccess, ResultFor, ResultMaybeAsync } from '../result';
1
+ import type { InferFailure, InferSuccess, ResultFor, ResultMaybeAsync } from '../result.js';
2
2
  /**
3
3
  * Chains the next computation using the success value of a {@link Result} or {@link ResultAsync}.
4
4
  * If the original result is a {@link Failure}, it is returned unchanged.
@@ -1,4 +1,4 @@
1
- import type { InferFailure, InferSuccess, ResultFor, ResultMaybeAsync } from '../result';
1
+ import type { InferFailure, InferSuccess, ResultFor, ResultMaybeAsync } from '../result.js';
2
2
  /**
3
3
  * Runs an additional computation using the success value of a {@link Result} or {@link ResultAsync},
4
4
  * but **returns the original result** if the additional computation is successful.
@@ -1,4 +1,4 @@
1
- import type { Failure, InferFailure, Result, ResultAsync } from '../result';
1
+ import type { Failure, InferFailure, Result, ResultAsync } from '../result.js';
2
2
  /**
3
3
  * Asserts that a {@link Result} or {@link ResultAsync} is a {@link Failure} and returns it.
4
4
  * If the result is a {@link Success}, throws an error.
@@ -1,4 +1,4 @@
1
- import type { InferSuccess, Result, ResultAsync, Success } from '../result';
1
+ import type { InferSuccess, Result, ResultAsync, Success } from '../result.js';
2
2
  /**
3
3
  * Asserts that a {@link Result} or {@link ResultAsync} is a {@link Success} and returns it.
4
4
  * If the result is a {@link Failure}, throws an error.
@@ -1,4 +1,4 @@
1
- import type { InferFailure, InferSuccess, ResultFor, ResultMaybeAsync } from '../result';
1
+ import type { InferFailure, InferSuccess, ResultFor, ResultMaybeAsync } from '../result.js';
2
2
  /**
3
3
  * Chains another {@link Result}-producing computation and **merges its success value**
4
4
  * into the existing object under the specified key.
@@ -1,4 +1,4 @@
1
- import type { InferFailure, InferSuccess, ResultFor, ResultMaybeAsync } from '../result';
1
+ import type { InferFailure, InferSuccess, ResultFor, ResultMaybeAsync } from '../result.js';
2
2
  /**
3
3
  * Combines multiple {@link Result} or {@link ResultAsync} values into a single result.
4
4
  * If all inputs are {@link Success}, returns a {@link Success} with combined values.
@@ -13,5 +13,5 @@
13
13
  *
14
14
  * @category Creators
15
15
  */
16
- declare const do_: () => import("../result").Result<{}, never>;
16
+ declare const do_: () => import("../result.js").Result<{}, never>;
17
17
  export { do_ as do };
@@ -1,4 +1,4 @@
1
- import type { ResultFor } from '../result';
1
+ import type { ResultFor } from '../result.js';
2
2
  /**
3
3
  * Creates a {@link Failure} result from a given error.
4
4
  * Automatically wraps the error in a `Promise` if it is asynchronous.
@@ -1,4 +1,4 @@
1
- import type { InferFailure, ResultMaybeAsync } from '../result';
1
+ import type { InferFailure, InferSuccess, ResultFor, ResultMaybeAsync } from '../result.js';
2
2
  /**
3
3
  * Executes a side effect function on the error value of a {@link Result} or {@link ResultAsync},
4
4
  * without modifying the original result. This is useful for debugging, logging, or performing
@@ -37,6 +37,6 @@ import type { InferFailure, ResultMaybeAsync } from '../result';
37
37
  * @category Combinators
38
38
  */
39
39
  export declare const inspectError: {
40
- <R1 extends ResultMaybeAsync<any, any>>(fn: (a: InferFailure<R1>) => unknown): (result: R1) => R1;
41
- <F extends (a: any) => unknown>(fn: F): <R1 extends ResultMaybeAsync<any, Parameters<F>[0]>>(result: R1) => R1;
40
+ <R1 extends ResultMaybeAsync<any, any>, R2>(fn: (a: InferFailure<R1>) => R2): (result: R1) => ResultFor<R1 | R2, InferSuccess<R1>, InferFailure<R1>>;
41
+ <F extends (a: any) => unknown>(fn: F): <R1 extends ResultMaybeAsync<any, Parameters<F>[0]>>(result: R1) => ResultFor<R1 | ReturnType<F>, InferSuccess<R1>, InferFailure<R1>>;
42
42
  };
@@ -2,7 +2,10 @@ import { isFailure } from "./is-failure.js";
2
2
  import { isPromise } from "../internals/helpers/is-promise.js";
3
3
  const inspectError = (fn)=>(result)=>{
4
4
  const apply = (r)=>{
5
- if (isFailure(r)) fn(r.error);
5
+ if (isFailure(r)) {
6
+ const next = fn(r.error);
7
+ if (isPromise(next)) return next.then(()=>r);
8
+ }
6
9
  return r;
7
10
  };
8
11
  return isPromise(result) ? result.then(apply) : apply(result);
@@ -1,4 +1,4 @@
1
- import type { InferSuccess, ResultMaybeAsync } from '../result';
1
+ import type { InferFailure, InferSuccess, ResultFor, ResultMaybeAsync } from '../result.js';
2
2
  /**
3
3
  * Executes a side effect function on the success value of a {@link Result} or {@link ResultAsync},
4
4
  * without modifying the original result. This is useful for debugging, logging, or performing
@@ -37,6 +37,6 @@ import type { InferSuccess, ResultMaybeAsync } from '../result';
37
37
  * @category Combinators
38
38
  */
39
39
  export declare const inspect: {
40
- <R1 extends ResultMaybeAsync<any, any>>(fn: (a: InferSuccess<R1>) => unknown): (result: R1) => R1;
41
- <F extends (a: any) => unknown>(fn: F): <R1 extends ResultMaybeAsync<Parameters<F>[0], any>>(result: R1) => R1;
40
+ <R1 extends ResultMaybeAsync<any, any>, R2>(fn: (a: InferSuccess<R1>) => R2): (result: R1) => ResultFor<R1 | R2, InferSuccess<R1>, InferFailure<R1>>;
41
+ <F extends (a: any) => unknown>(fn: F): <R1 extends ResultMaybeAsync<Parameters<F>[0], any>>(result: R1) => ResultFor<R1 | ReturnType<F>, InferSuccess<R1>, InferFailure<R1>>;
42
42
  };
@@ -2,7 +2,10 @@ import { isSuccess } from "./is-success.js";
2
2
  import { isPromise } from "../internals/helpers/is-promise.js";
3
3
  const inspect = (fn)=>(result)=>{
4
4
  const apply = (r)=>{
5
- if (isSuccess(r)) fn(r.value);
5
+ if (isSuccess(r)) {
6
+ const next = fn(r.value);
7
+ if (isPromise(next)) return next.then(()=>r);
8
+ }
6
9
  return r;
7
10
  };
8
11
  return isPromise(result) ? result.then(apply) : apply(result);
@@ -1,4 +1,4 @@
1
- import type { Failure, Result } from '../result';
1
+ import type { Failure, Result } from '../result.js';
2
2
  /**
3
3
  * Type guard to check if a {@link Result} is a {@link Failure}.
4
4
  *
@@ -1,4 +1,4 @@
1
- import type { Result } from '../result';
1
+ import type { Result } from '../result.js';
2
2
  /**
3
3
  * Type guard to check if a value is a {@link Result}.
4
4
  *
@@ -1,4 +1,4 @@
1
- import type { Result, Success } from '../result';
1
+ import type { Result, Success } from '../result.js';
2
2
  /**
3
3
  * Type guard to check if a {@link Result} is a {@link Success}.
4
4
  *
@@ -1,4 +1,4 @@
1
- import type { InferFailure, InferSuccess, ResultFor, ResultMaybeAsync } from '../result';
1
+ import type { InferFailure, InferSuccess, ResultFor, ResultMaybeAsync } from '../result.js';
2
2
  /**
3
3
  * Applies a transformation function to the error value of a {@link Result} or {@link ResultAsync}.
4
4
  * If the input is a {@link Success}, it will be returned unchanged.
@@ -1,4 +1,4 @@
1
- import type { InferFailure, InferSuccess, ResultFor, ResultMaybeAsync } from '../result';
1
+ import type { InferFailure, InferSuccess, ResultFor, ResultMaybeAsync } from '../result.js';
2
2
  /**
3
3
  * Applies a transformation function to the success value of a {@link Result} or {@link ResultAsync}.
4
4
  * If the input is a {@link Failure}, it will be returned unchanged.
@@ -1,4 +1,4 @@
1
- import type { InferFailure, InferSuccess, ResultFor, ResultMaybeAsync } from '../result';
1
+ import type { InferFailure, InferSuccess, ResultFor, ResultMaybeAsync } from '../result.js';
2
2
  /**
3
3
  * Chains the next computation using the error value of a {@link Result} or {@link ResultAsync}.
4
4
  * If the original result is a {@link Success}, it is returned unchanged.
@@ -1,4 +1,4 @@
1
- import type { Result } from '../result';
1
+ import type { Result } from '../result.js';
2
2
  import type { StandardSchemaV1 } from '@standard-schema/spec';
3
3
  /**
4
4
  * Parses a value using a {@link https://github.com/standard-schema/standard-schema Standard Schema} compatible schema.
@@ -1,4 +1,4 @@
1
- import type { ResultFor } from '../result';
1
+ import type { ResultFor } from '../result.js';
2
2
  /**
3
3
  * Creates a {@link Success} result from a given value.
4
4
  * Automatically wraps the value in a `Promise` if it is asynchronous.
@@ -1,4 +1,4 @@
1
- import type { Result, ResultAsync } from '../result';
1
+ import type { Result, ResultAsync } from '../result.js';
2
2
  /**
3
3
  * Wraps a function execution (sync or async) or a Promise in a {@link Result} or {@link ResultAsync} type,
4
4
  * capturing errors and returning them in a structured way.
@@ -1,5 +1,5 @@
1
- import type { HasPromise } from '../internals/types/has-promise';
2
- import type { InferFailure, ResultMaybeAsync } from '../result';
1
+ import type { HasPromise } from '../internals/types/has-promise.js';
2
+ import type { InferFailure, ResultMaybeAsync } from '../result.js';
3
3
  /**
4
4
  * Extracts the error value from a {@link Result} or {@link ResultAsync}.
5
5
  *
@@ -1,5 +1,5 @@
1
- import type { HasPromise } from '../internals/types/has-promise';
2
- import type { InferSuccess, ResultMaybeAsync } from '../result';
1
+ import type { HasPromise } from '../internals/types/has-promise.js';
2
+ import type { InferSuccess, ResultMaybeAsync } from '../result.js';
3
3
  /**
4
4
  * Extracts the success value from a {@link Result} or {@link ResultAsync}.
5
5
  *
@@ -62,8 +62,8 @@
62
62
  * }
63
63
  * ```
64
64
  */
65
- export * as Result from './exports';
65
+ export * as Result from './exports.js';
66
66
  /**
67
67
  * Shorthand alias for {@link Result}.
68
68
  */
69
- export * as R from './exports';
69
+ export * as R from './exports.js';
@@ -1,4 +1,4 @@
1
- import type { HasPromise } from './internals/types/has-promise';
1
+ import type { HasPromise } from './internals/types/has-promise.js';
2
2
  /**
3
3
  * Represents a successful result.
4
4
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@praha/byethrow",
3
- "version": "0.7.0",
3
+ "version": "0.7.2",
4
4
  "description": "A lightweight, tree-shakable Result type package with a simple, consistent API designed",
5
5
  "keywords": [
6
6
  "javascript",
@@ -44,11 +44,11 @@
44
44
  "@standard-schema/spec": "^1.0.0"
45
45
  },
46
46
  "devDependencies": {
47
- "@rslib/core": "0.13.0",
48
- "eslint": "9.35.0",
49
- "typedoc": "0.28.12",
50
- "typedoc-plugin-markdown": "4.8.1",
51
- "typescript": "5.9.2",
47
+ "@rslib/core": "0.15.0",
48
+ "eslint": "9.37.0",
49
+ "typedoc": "0.28.13",
50
+ "typedoc-plugin-markdown": "4.9.0",
51
+ "typescript": "5.9.3",
52
52
  "vitest": "3.2.4"
53
53
  },
54
54
  "publishConfig": {