yield-result 0.1.0 → 0.1.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.
- package/dist/flow.d.ts +7 -2
- package/dist/flow.js +2 -0
- package/package.json +10 -1
package/dist/flow.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { Result, Err } from "./types.js";
|
|
2
|
+
type InferYieldErr<G> = G extends Generator<infer Y, unknown, unknown> ? Y extends Err<infer E> ? E : never : G extends AsyncGenerator<infer Y, unknown, unknown> ? Y extends Err<infer E> ? E : never : never;
|
|
3
|
+
type InferReturn<G> = G extends Generator<unknown, infer R, unknown> ? R : G extends AsyncGenerator<unknown, infer R, unknown> ? R : never;
|
|
2
4
|
/**
|
|
3
5
|
* Control flow runners for evaluating generator functions with short-circuiting on Err.
|
|
4
6
|
*/
|
|
@@ -6,11 +8,14 @@ export declare const safe: {
|
|
|
6
8
|
/**
|
|
7
9
|
* Evaluates a synchronous generator function, returning Ok(value) on completion,
|
|
8
10
|
* or short-circuiting on the first yielded Err(error).
|
|
11
|
+
* Automatically infers and unifies error types yielded across all steps.
|
|
9
12
|
*/
|
|
10
|
-
sync: <
|
|
13
|
+
sync: <G extends Generator<Err<unknown>, unknown, unknown>>(fn: () => G) => Result<InferReturn<G>, InferYieldErr<G>>;
|
|
11
14
|
/**
|
|
12
15
|
* Evaluates an async generator function, returning Ok(value) on completion,
|
|
13
16
|
* or short-circuiting on the first yielded Err(error).
|
|
17
|
+
* Automatically infers and unifies error types yielded across all steps.
|
|
14
18
|
*/
|
|
15
|
-
async: <
|
|
19
|
+
async: <G extends AsyncGenerator<Err<unknown>, unknown, unknown>>(fn: () => G) => Promise<Result<InferReturn<G>, InferYieldErr<G>>>;
|
|
16
20
|
};
|
|
21
|
+
export {};
|
package/dist/flow.js
CHANGED
|
@@ -6,6 +6,7 @@ export const safe = {
|
|
|
6
6
|
/**
|
|
7
7
|
* Evaluates a synchronous generator function, returning Ok(value) on completion,
|
|
8
8
|
* or short-circuiting on the first yielded Err(error).
|
|
9
|
+
* Automatically infers and unifies error types yielded across all steps.
|
|
9
10
|
*/
|
|
10
11
|
sync: (fn) => {
|
|
11
12
|
let gen;
|
|
@@ -56,6 +57,7 @@ export const safe = {
|
|
|
56
57
|
/**
|
|
57
58
|
* Evaluates an async generator function, returning Ok(value) on completion,
|
|
58
59
|
* or short-circuiting on the first yielded Err(error).
|
|
60
|
+
* Automatically infers and unifies error types yielded across all steps.
|
|
59
61
|
*/
|
|
60
62
|
async: async (fn) => {
|
|
61
63
|
let gen;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yield-result",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Rust-style ? operator for TypeScript using generators (yield*). Zero dependencies, type-safe error handling.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -25,6 +25,14 @@
|
|
|
25
25
|
"bench": "npx vitest bench",
|
|
26
26
|
"prepublishOnly": "npm run test && npm run test:types && npm run build"
|
|
27
27
|
},
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git+https://github.com/Benevalterjr/yield-result.git"
|
|
31
|
+
},
|
|
32
|
+
"homepage": "https://github.com/Benevalterjr/yield-result#readme",
|
|
33
|
+
"bugs": {
|
|
34
|
+
"url": "https://github.com/Benevalterjr/yield-result/issues"
|
|
35
|
+
},
|
|
28
36
|
"keywords": [
|
|
29
37
|
"result",
|
|
30
38
|
"error-handling",
|
|
@@ -43,3 +51,4 @@
|
|
|
43
51
|
}
|
|
44
52
|
}
|
|
45
53
|
|
|
54
|
+
|