resultar 3.4.0 → 3.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -45,7 +45,7 @@ Use it when expected failures should be impossible to miss:
45
45
  - Ignored `Result` values can be reported by a type-aware no-discard check.
46
46
 
47
47
  Resultar began as an initial fork of `neverthrow`. The v3 line keeps the explicit wrapper model,
48
- then leans into Resultar-specific tagged errors, strict service-boundary types, TypeScript 7-first
48
+ then leans into Resultar-specific tagged errors, strict service-boundary types, TypeScript >=7
49
49
  diagnostics, and ESM-only packaging.
50
50
 
51
51
  ## Install
@@ -61,7 +61,7 @@ npm install resultar
61
61
  ## Requirements
62
62
 
63
63
  - Node.js 24+
64
- - TypeScript 7 for the canonical Resultar diagnostics workflow
64
+ - TypeScript >=7 for the canonical Resultar diagnostics workflow
65
65
  - ESM only
66
66
 
67
67
  ```ts
@@ -738,6 +738,21 @@ const lines = ResultAsync.withResource({
738
738
  })
739
739
  ```
740
740
 
741
+ Adapt callback and subscription APIs with `ResultAsync.fromCallback`. The callback source can
742
+ resolve or reject once, receives the cooperative signal, and returns a synchronous unsubscribe
743
+ function that runs after success, failure, or cancellation.
744
+
745
+ ```ts
746
+ const nextValue = ResultAsync.fromCallback<number, SubscriptionError>({
747
+ catch: (cause) => new SubscriptionError({ cause }),
748
+ signal,
749
+ subscribe: ({ reject, resolve }) => {
750
+ const subscription = source.subscribe({ error: reject, next: resolve })
751
+ return () => subscription.unsubscribe()
752
+ },
753
+ })
754
+ ```
755
+
741
756
  For pull-based streams, keep the runtime native: expose an `AsyncIterable<Result<T, E>>` and close
742
757
  resources in `finally`. See
743
758
  [DOCUMENTATION.md](../../DOCUMENTATION.md#resourceful-async-iterables) for the full recipe.
@@ -756,6 +771,7 @@ where the failure appears.
756
771
  | Catch thrown sync code now | `tryResult(fn, toError?)` |
757
772
  | Wrap a throwing sync function for later | `fromThrowable(fn, toError?)` |
758
773
  | Catch an existing rejecting promise | `fromPromise(promise, toError)` |
774
+ | Adapt a callback or subscription | `ResultAsync.fromCallback({ subscribe, catch, signal? })` |
759
775
  | Catch a promise or async factory | `tryResultAsync(promiseOrFactory, toError?)` |
760
776
  | Wrap an async function for later | `fromThrowableAsync(fn, toError?)` |
761
777
  | Turn one error into another | `mapErr(fn)` |
@@ -971,11 +987,11 @@ const config = safeTry({
971
987
 
972
988
  ## No-Discard Validation
973
989
 
974
- Resultar values should not be ignored. Use `resultar-check` to run TypeScript 7 and Resultar
990
+ Resultar values should not be ignored. Use `resultar-check` to run TypeScript >=7 and Resultar
975
991
  diagnostics through one command.
976
992
 
977
993
  ```sh
978
- pnpm add -D resultar-check typescript-7@npm:typescript@rc
994
+ pnpm add -D resultar-check "typescript@>=7"
979
995
  ```
980
996
 
981
997
  Add a check script:
@@ -1023,8 +1039,10 @@ Configure Resultar rules in `tsconfig.json`:
1023
1039
  The package-local schema provides editor completion and validation for `resultar-check` plugin
1024
1040
  options.
1025
1041
 
1026
- Oxlint is intentionally not part of the Resultar rules path; use it only for general linting if your
1027
- project wants it.
1042
+ For fast AST-only Oxlint, ESLint, or Deno Lint feedback, use the adapter exports documented in the
1043
+ `resultar-check` package guide. Use the `resultar-check` CLI for the full TypeScript-backed rule set.
1044
+ The `examples/lint` package shows how to compare Oxlint, ESLint, and CLI counts by running the CLI
1045
+ with the same AST-only rule subset.
1028
1046
 
1029
1047
  For VS Code and Zed setup, use the editor integration section in the `resultar-check` package guide.
1030
1048
 
@@ -1039,6 +1057,7 @@ For VS Code and Zed setup, use the editor integration section in the `resultar-c
1039
1057
  | Create an `Ok(undefined)` | `unit()` or `unitAsync()` |
1040
1058
  | Convert throwing sync code | `tryResult` or `fromThrowable` |
1041
1059
  | Convert rejecting async code | `tryResultAsync`, `fromPromise`, or `fromThrowableAsync` |
1060
+ | Convert a callback subscription | `ResultAsync.fromCallback` or `fromCallback` |
1042
1061
  | Treat an `Err` as unrecoverable at an edge | `unwrapOrThrow()` |
1043
1062
  | Transform success | `map` or `asyncMap` |
1044
1063
  | Replace success with a known value | `as(value)` |
@@ -1105,19 +1124,17 @@ More focused material:
1105
1124
  - [Full guide](https://github.com/inaiat/resultar/blob/main/DOCUMENTATION.md)
1106
1125
  - [Type-safe error handling article, English](https://github.com/inaiat/resultar/blob/main/articles/en/type-safe.md)
1107
1126
  - [Artigo sobre tratamento de erros type-safe, Portuguese](https://github.com/inaiat/resultar/blob/main/articles/pt/type-safe.md)
1108
- - [resultar-check package guide](https://github.com/inaiat/resultar/blob/main/packages/resultar-check/README.md)
1127
+ - [resultar-check package guide](https://github.com/inaiat/resultar/blob/main/packages/check/README.md)
1109
1128
 
1110
1129
  ## Repository
1111
1130
 
1112
1131
  This repository is a pnpm workspace:
1113
1132
 
1114
1133
  - `packages/resultar`: Resultar runtime package.
1115
- - `packages/resultar-check`: TypeScript 7 plus Resultar validation.
1116
- - `packages/resultar-lint`: deprecated compatibility wrapper.
1117
- - `packages/resultar-tsgo`: deprecated compatibility wrapper for older installs.
1134
+ - `packages/check`: TypeScript >=7 plus Resultar validation and AST-only lint adapters.
1118
1135
  - `benchmarks`: benchmark package.
1119
1136
  - `examples/resultar`: runnable core Resultar cookbook.
1120
- - `examples/lint`: TypeScript 7 `resultar-check` smoke example.
1137
+ - `examples/lint`: adapter parity smoke for AST-only Resultar rules across Oxlint, ESLint, and `resultar-check` CLI.
1121
1138
 
1122
1139
  Common commands:
1123
1140
 
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 };