resultar 3.3.1 → 3.4.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 +30 -1
- package/dist/index.d.ts +898 -112
- package/dist/index.js +267 -10
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -836,6 +836,27 @@ Use `fromPromise` when you already have a promise and need to map rejection into
|
|
|
836
836
|
const user = fromPromise(loadUserFromRemote(id), (cause) => new FetchUserError({ cause, id }))
|
|
837
837
|
```
|
|
838
838
|
|
|
839
|
+
Use `tryResultAsync` when the async boundary is the thing you want to name and document. The object
|
|
840
|
+
form is useful for infrastructure helpers because the task and error mapper stay together:
|
|
841
|
+
|
|
842
|
+
```ts
|
|
843
|
+
import { createTaggedError, tryResultAsync } from 'resultar'
|
|
844
|
+
import type { StrictResultAsync } from 'resultar'
|
|
845
|
+
|
|
846
|
+
type AsyncTask = () => Promise<void>
|
|
847
|
+
|
|
848
|
+
class TaskError extends createTaggedError({
|
|
849
|
+
name: 'TaskError',
|
|
850
|
+
message: 'Task failed: $label',
|
|
851
|
+
}) {}
|
|
852
|
+
|
|
853
|
+
const tryTask = (label: string, task: AsyncTask): StrictResultAsync<void, TaskError> =>
|
|
854
|
+
tryResultAsync({
|
|
855
|
+
try: task,
|
|
856
|
+
catch: (cause) => new TaskError({ cause, label }),
|
|
857
|
+
})
|
|
858
|
+
```
|
|
859
|
+
|
|
839
860
|
After that edge conversion, keep your own domain functions returning `Result` values instead of
|
|
840
861
|
throwing expected failures.
|
|
841
862
|
|
|
@@ -962,11 +983,13 @@ Add a check script:
|
|
|
962
983
|
```json
|
|
963
984
|
{
|
|
964
985
|
"scripts": {
|
|
965
|
-
"check": "resultar-check
|
|
986
|
+
"check": "resultar-check"
|
|
966
987
|
}
|
|
967
988
|
}
|
|
968
989
|
```
|
|
969
990
|
|
|
991
|
+
`resultar-check` defaults to `tsconfig.json` and runs TypeScript with no emit.
|
|
992
|
+
|
|
970
993
|
These fail in the default `must-use` mode:
|
|
971
994
|
|
|
972
995
|
```ts
|
|
@@ -990,15 +1013,21 @@ Configure Resultar rules in `tsconfig.json`:
|
|
|
990
1013
|
|
|
991
1014
|
```json
|
|
992
1015
|
{
|
|
1016
|
+
"$schema": "./node_modules/resultar-check/schema.json",
|
|
993
1017
|
"compilerOptions": {
|
|
994
1018
|
"plugins": [{ "name": "resultar-check", "noDiscard": "error" }]
|
|
995
1019
|
}
|
|
996
1020
|
}
|
|
997
1021
|
```
|
|
998
1022
|
|
|
1023
|
+
The package-local schema provides editor completion and validation for `resultar-check` plugin
|
|
1024
|
+
options.
|
|
1025
|
+
|
|
999
1026
|
Oxlint is intentionally not part of the Resultar rules path; use it only for general linting if your
|
|
1000
1027
|
project wants it.
|
|
1001
1028
|
|
|
1029
|
+
For VS Code and Zed setup, use the editor integration section in the `resultar-check` package guide.
|
|
1030
|
+
|
|
1002
1031
|
## API Decision Guide
|
|
1003
1032
|
|
|
1004
1033
|
| Need | Use |
|