resultar 3.4.0 → 3.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -742,6 +742,44 @@ interface ResultAsyncAbortSignal {
742
742
  removeEventListener: (type: "abort", listener: () => void) => void;
743
743
  }
744
744
  /**
745
+ * Context passed to `ResultAsync.fromCallback` subscriptions.
746
+ */
747
+ interface ResultAsyncCallbackContext<T> {
748
+ /**
749
+ * Completes the operation with `Ok(value)`.
750
+ */
751
+ readonly resolve: (value: T) => void;
752
+ /**
753
+ * Completes the operation with a cause mapped by the subscription's `catch` function.
754
+ */
755
+ readonly reject: (cause: unknown) => void;
756
+ /**
757
+ * Cooperative cancellation signal for the subscription.
758
+ */
759
+ readonly signal: ResultAsyncAbortSignal;
760
+ }
761
+ /**
762
+ * Synchronous cleanup returned by a `ResultAsync.fromCallback` subscription.
763
+ */
764
+ type ResultAsyncCallbackCleanup = () => void;
765
+ /**
766
+ * Options for adapting a callback or subscription API into `ResultAsync`.
767
+ */
768
+ interface ResultAsyncFromCallbackOptions<T, E> {
769
+ /**
770
+ * Maps callback failures and synchronous subscription throws into the typed error channel.
771
+ */
772
+ readonly catch: (cause: unknown) => E;
773
+ /**
774
+ * Optional external signal that cancels the subscription with `AbortError`.
775
+ */
776
+ readonly signal?: ResultAsyncAbortSignal;
777
+ /**
778
+ * Registers the callback source and optionally returns a synchronous unsubscribe function.
779
+ */
780
+ readonly subscribe: (context: ResultAsyncCallbackContext<T>) => ResultAsyncCallbackCleanup | void;
781
+ }
782
+ /**
745
783
  * Concurrency setting for async collection helpers.
746
784
  *
747
785
  * Use a number for bounded parallelism or `'unbounded'` when every task may start immediately.
@@ -1019,7 +1057,7 @@ declare class DisposableResultAsync<T, E> implements PromiseLike<Result<T, E>>,
1019
1057
  * but operating in an asynchronous context.
1020
1058
  *
1021
1059
  * The class includes methods for:
1022
- * - Creating ResultAsync instances (okAsync, errAsync, fromPromise)
1060
+ * - Creating ResultAsync instances (okAsync, errAsync, fromPromise, fromCallback)
1023
1061
  * - Transforming values (map, mapErr)
1024
1062
  * - Chaining operations (andThen, orElse)
1025
1063
  * - Error handling (tapError)
@@ -1082,6 +1120,13 @@ declare class ResultAsync<T, E> extends Pipeable implements PromiseLike<Result<T
1082
1120
  */
1083
1121
  static fromPromise<T, E>(this: void, promise: PromiseLike<T>, errorFn: (e: unknown) => E): ResultAsync<T, E>;
1084
1122
  /**
1123
+ * Adapts a callback or subscription API into a cancellable ResultAsync.
1124
+ *
1125
+ * The returned cleanup function runs once after resolve, reject, cancellation, or synchronous
1126
+ * subscription failure. Cleanup errors are ignored.
1127
+ */
1128
+ static fromCallback<T, E>(this: void, options: ResultAsyncFromCallbackOptions<T, E>): ResultAsync<T, E | AbortError>;
1129
+ /**
1085
1130
  * Combines many ResultAsync values and stops at the first Err.
1086
1131
  *
1087
1132
  * Arrays return an Ok array, records return an Ok record with the same keys, and iterables return
@@ -1354,6 +1399,10 @@ declare const okAsync: typeof ResultAsync.okAsync;
1354
1399
  */
1355
1400
  declare const errAsync: typeof ResultAsync.errAsync;
1356
1401
  /**
1402
+ * Adapts a callback or subscription API into a cancellable ResultAsync.
1403
+ */
1404
+ declare const fromCallback: typeof ResultAsync.fromCallback;
1405
+ /**
1357
1406
  * Converts an existing promise into a ResultAsync and maps rejection into a typed Err.
1358
1407
  */
1359
1408
  declare const fromPromise: typeof ResultAsync.fromPromise;
@@ -1628,5 +1677,4 @@ declare const matchError: <ErrorType extends Error, ReturnType>(error: ErrorType
1628
1677
  */
1629
1678
  declare const matchErrorPartial: <ErrorType extends Error, ReturnType>(error: ErrorType, handlers: PartialMatchHandlers<ErrorType, ReturnType>, fallback: (error: ErrorType) => ReturnType) => ReturnType;
1630
1679
  //#endregion
1631
- export { AbortError, DisposableResult, DisposableResultAsync, type ErrResult, type OkResult, type Redacted, Result, ResultAsync, type ResultAsyncAbortSignal, type ResultAsyncConcurrency, type ResultAsyncRaceHandle, type ResultAsyncRaceTask, type ResultAsyncResourceAcquire, type ResultAsyncResourceEffect, type ResultAsyncResourceRelease, type ResultAsyncResourceReleaseContext, type ResultAsyncResourceUse, type ResultAsyncRetryContext, type ResultAsyncRetryOptions, type ResultAsyncRetryOrElseOptions, type ResultAsyncRetryTask, type ResultAsyncTimeoutOptions, type ResultAsyncWithResourceOptions, type ResultOperations, type SafeTryAsyncOptions, type SafeTryOptions, type StrictResult, type StrictResultAsync, type TaggedEnum, type TaggedEnumFactory, type TaggedErrorClass, type TaggedErrorInstance, type TaggedErrorOptions, type TryResultAsyncOptions, type TryResultOptions, createTaggedError, tryResult as default, tryResult as try, tryResult, err, errAsync, findCause, fromPromise, fromSafePromise, fromThrowable, fromThrowableAsync, isAbortError, isError, isRedacted, matchError, matchErrorPartial, ok, okAsync, redact, revealRedacted, runPromise, runSync, safeTry, taggedEnum, tryResultAsync as tryAsync, tryResultAsync, tryCatch, tryCatchAsync, unit, unitAsync };
1632
- //# sourceMappingURL=index.d.ts.map
1680
+ export { AbortError, DisposableResult, DisposableResultAsync, type ErrResult, type OkResult, type Redacted, Result, ResultAsync, type ResultAsyncAbortSignal, type ResultAsyncCallbackCleanup, type ResultAsyncCallbackContext, type ResultAsyncConcurrency, type ResultAsyncFromCallbackOptions, type ResultAsyncRaceHandle, type ResultAsyncRaceTask, type ResultAsyncResourceAcquire, type ResultAsyncResourceEffect, type ResultAsyncResourceRelease, type ResultAsyncResourceReleaseContext, type ResultAsyncResourceUse, type ResultAsyncRetryContext, type ResultAsyncRetryOptions, type ResultAsyncRetryOrElseOptions, type ResultAsyncRetryTask, type ResultAsyncTimeoutOptions, type ResultAsyncWithResourceOptions, type ResultOperations, type SafeTryAsyncOptions, type SafeTryOptions, type StrictResult, type StrictResultAsync, type TaggedEnum, type TaggedEnumFactory, type TaggedErrorClass, type TaggedErrorInstance, type TaggedErrorOptions, type TryResultAsyncOptions, type TryResultOptions, createTaggedError, tryResult as default, tryResult as try, tryResult, err, errAsync, findCause, fromCallback, fromPromise, fromSafePromise, fromThrowable, fromThrowableAsync, isAbortError, isError, isRedacted, matchError, matchErrorPartial, ok, okAsync, redact, revealRedacted, runPromise, runSync, safeTry, taggedEnum, tryResultAsync as tryAsync, tryResultAsync, tryCatch, tryCatchAsync, unit, unitAsync };