skyr 1.0.0 → 1.1.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.
Files changed (54) hide show
  1. package/README.md +82 -54
  2. package/esm/_internal/handlers.d.ts +10 -4
  3. package/esm/_internal/handlers.d.ts.map +1 -1
  4. package/esm/_internal/handlers.js +18 -5
  5. package/esm/async_result.d.ts +3 -3
  6. package/esm/async_result.js +2 -2
  7. package/esm/fn/fn.d.ts.map +1 -1
  8. package/esm/fn/fn.js +15 -12
  9. package/esm/fn/inject.d.ts.map +1 -1
  10. package/esm/fn/inject.js +2 -8
  11. package/esm/fn/types.d.ts +2 -0
  12. package/esm/fn/types.d.ts.map +1 -1
  13. package/esm/fn/use.d.ts +2 -2
  14. package/esm/operators/inspect.d.ts +1 -1
  15. package/esm/operators/inspect.js +1 -1
  16. package/esm/operators/inspect_err.d.ts +1 -1
  17. package/esm/operators/inspect_err.js +1 -1
  18. package/esm/operators/map.d.ts +1 -1
  19. package/esm/operators/map.js +1 -1
  20. package/esm/operators/map_err.d.ts +2 -2
  21. package/esm/operators/map_err.js +2 -2
  22. package/esm/operators/unwrap.d.ts +1 -1
  23. package/esm/operators/unwrap.js +1 -1
  24. package/esm/panic.d.ts +2 -2
  25. package/esm/panic.js +2 -2
  26. package/esm/result.d.ts +2 -2
  27. package/esm/result.d.ts.map +1 -1
  28. package/package.json +1 -1
  29. package/script/_internal/handlers.d.ts +10 -4
  30. package/script/_internal/handlers.d.ts.map +1 -1
  31. package/script/_internal/handlers.js +19 -5
  32. package/script/async_result.d.ts +3 -3
  33. package/script/async_result.js +2 -2
  34. package/script/fn/fn.d.ts.map +1 -1
  35. package/script/fn/fn.js +14 -11
  36. package/script/fn/inject.d.ts.map +1 -1
  37. package/script/fn/inject.js +2 -8
  38. package/script/fn/types.d.ts +2 -0
  39. package/script/fn/types.d.ts.map +1 -1
  40. package/script/fn/use.d.ts +2 -2
  41. package/script/operators/inspect.d.ts +1 -1
  42. package/script/operators/inspect.js +1 -1
  43. package/script/operators/inspect_err.d.ts +1 -1
  44. package/script/operators/inspect_err.js +1 -1
  45. package/script/operators/map.d.ts +1 -1
  46. package/script/operators/map.js +1 -1
  47. package/script/operators/map_err.d.ts +2 -2
  48. package/script/operators/map_err.js +2 -2
  49. package/script/operators/unwrap.d.ts +1 -1
  50. package/script/operators/unwrap.js +1 -1
  51. package/script/panic.d.ts +2 -2
  52. package/script/panic.js +2 -2
  53. package/script/result.d.ts +2 -2
  54. package/script/result.d.ts.map +1 -1
package/README.md CHANGED
@@ -57,19 +57,19 @@ Results are plain objects with a `_tag` discriminant:
57
57
 
58
58
  The `cause` field is `undefined` when not provided.
59
59
 
60
- Every Result comes with methods for transforming and inspecting it type `.` in
60
+ Every Result comes with methods for transforming and inspecting it. Type `.` in
61
61
  your IDE and see what's available.
62
62
 
63
63
  ### Letting TypeScript Infer Result Types
64
64
 
65
65
  There's a subtlety with the example above. Without an explicit return type
66
66
  annotation, TypeScript infers the return type as
67
- `Result<string, never> | Result<never, "INVALID_EMAIL">` a union of two
67
+ `Result<string, never> | Result<never, "INVALID_EMAIL">`, a union of two
68
68
  separate Result types rather than a single unified
69
69
  `Result<string, "INVALID_EMAIL">`.
70
70
 
71
71
  You could fix this by adding a return type annotation, but it's generally safer
72
- to let TypeScript infer return types whenever possible annotations can drift
72
+ to let TypeScript infer return types whenever possible. Annotations can drift
73
73
  out of sync with the implementation and mask bugs.
74
74
 
75
75
  Instead, wrap the function with `fn()`:
@@ -87,7 +87,7 @@ const validateEmail = R.fn((email: string) => {
87
87
  ```
88
88
 
89
89
  `fn()` collapses all the Result branches into a single, clean `Result<T, E>`
90
- type. No annotation needed the ok value type and all possible error codes are
90
+ type. No annotation needed; the ok value type and all possible error codes are
91
91
  inferred automatically.
92
92
 
93
93
  This is the simplest use of `fn()`. It also supports
@@ -123,7 +123,7 @@ considered a Result if it's a non-null object with `_tag` equal to `"Ok"` or
123
123
  ### Method Chaining
124
124
 
125
125
  Every Result has methods for transformation, error handling, and value
126
- extraction. Chain them directly no imports or special syntax needed:
126
+ extraction. Chain them directly, no imports or special syntax needed:
127
127
 
128
128
  ```typescript
129
129
  const message = validateEmail("User@Example.com")
@@ -137,15 +137,14 @@ const message = validateEmail("User@Example.com")
137
137
  console.log(message); // "Welcome, user@example.com!"
138
138
  ```
139
139
 
140
- Methods skip over errors automatically if `validateEmail` returns an error,
141
- the `.map()` calls are never executed, and the error flows straight to
142
- `.match()`.
140
+ Methods skip over errors automatically. If `validateEmail` returns an error, the
141
+ `.map()` calls are never executed and the error flows straight to `.match()`.
143
142
 
144
143
  ### Async Propagation
145
144
 
146
- When any step returns a `Promise`, the result becomes an `AsyncResult` a
145
+ When any step returns a `Promise`, the result becomes an `AsyncResult`, a
147
146
  wrapper around `Promise<Result>` with the same methods. This is called **async
148
- poison** once async, always async (until you `await`).
147
+ poison**: once async, always async (until you `await`).
149
148
 
150
149
  ```typescript
151
150
  const result = validateEmail("user@example.com") // Result<string, ...>
@@ -154,7 +153,7 @@ const result = validateEmail("user@example.com") // Result<string, ...>
154
153
  // Type: AsyncResult<string, ...>
155
154
 
156
155
  const finalResult = await result;
157
- // Type: Result<string, ...> back to sync, methods available again
156
+ // Type: Result<string, ...> (back to sync)
158
157
  ```
159
158
 
160
159
  `AsyncResult` is `PromiseLike`, so you can `await` it to get back a sync
@@ -181,14 +180,16 @@ const message = R.pipe(
181
180
  ```
182
181
 
183
182
  Standalone operators accept both `Result` and `Promise<Result>` as input and
184
- propagate async automatically they work interchangeably with both styles.
183
+ propagate async automatically and work interchangeably with both styles.
185
184
 
186
- ### Panics: Catching Programmer Errors
185
+ ### Panics: Unexpected Throws
187
186
 
188
- Callbacks passed to `map`, `mapErr`, and `match` are expected to be pure
189
- transformation functions. If a callback **throws synchronously**, that's a
190
- programmer error a bug, not a domain error. skyr wraps these in a `Panic`
191
- error to make them instantly recognizable:
187
+ If your code calls something that might throw or reject, or you're unsure
188
+ whether it could, wrap it with `fromThrowable()` to convert it into a Result
189
+ safely. This is the recommended approach for any code you don't fully control.
190
+
191
+ If a callback passed to `map`, `mapErr`, or `match` throws synchronously without
192
+ being wrapped, a `Panic` is thrown, halting execution immediately unless caught:
192
193
 
193
194
  ```typescript
194
195
  R.ok(42).map(() => {
@@ -201,11 +202,12 @@ R.ok(42).map(() => {
201
202
  `Panic` extends `Error`, so you get a full stack trace. Catch it at the top
202
203
  level with `instanceof R.Panic` if needed.
203
204
 
204
- **Promise rejections** are different they represent the outside world failing
205
- (network errors, etc.) and are captured as `UNKNOWN_ERR` results, not Panics.
206
-
207
- If your callback calls code that might throw, wrap it with `fromThrowable()` to
208
- convert it into a Result safely.
205
+ **Async functions** (Promises) returned from callbacks are automatically wrapped
206
+ with `fromThrowable` implicitly, so rejections become `UNKNOWN_ERR` results
207
+ instead of Panics. However, if you use multiple async functions, all their
208
+ errors will share the same `UNKNOWN_ERR` code, making it impossible to
209
+ distinguish between them. Wrapping each one with `fromThrowable` and a dedicated
210
+ error code is the recommended approach.
209
211
 
210
212
  ## Methods
211
213
 
@@ -224,7 +226,7 @@ R.ok(5)
224
226
  ```
225
227
 
226
228
  If `fn` returns a `Result`, it's automatically flattened (no nested Results). If
227
- it returns a `Promise`, the result becomes an `AsyncResult` the Promise is
229
+ it returns a `Promise`, the result becomes an `AsyncResult`. The Promise is
228
230
  automatically handled like `fromThrowable`: resolved values become ok, rejected
229
231
  Promises become `UNKNOWN_ERR`.
230
232
 
@@ -232,7 +234,7 @@ Promises become `UNKNOWN_ERR`.
232
234
 
233
235
  Transforms or recovers from errors. Has two forms:
234
236
 
235
- **Function form** transform all errors:
237
+ **Function form** - transform all errors:
236
238
 
237
239
  ```typescript
238
240
  R.err("NOT_FOUND", "User not found")
@@ -240,7 +242,7 @@ R.err("NOT_FOUND", "User not found")
240
242
  // Result<never, "DEFAULT_ERROR">
241
243
  ```
242
244
 
243
- **Handler object** handle specific error codes with autocomplete:
245
+ **Handler object** - handle specific error codes with autocomplete:
244
246
 
245
247
  ```typescript
246
248
  type AppError = "NOT_FOUND" | "TIMEOUT" | "AUTH_FAILED";
@@ -289,7 +291,7 @@ validateEmail("user@example.com")
289
291
  .map((email) => email.toLowerCase());
290
292
  ```
291
293
 
292
- The callback's return value is ignored the original Result is always returned
294
+ The callback's return value is ignored; the original Result is always returned
293
295
  unchanged. If the callback throws or the returned Promise rejects, the error is
294
296
  silently swallowed and the original Result passes through. Side effects should
295
297
  never break the pipeline.
@@ -363,14 +365,33 @@ safeParse("nope"); // Err("PARSE_ERROR")
363
365
 
364
366
  ## Dependency Injection with `fn()`
365
367
 
366
- For larger applications, `fn()` accepts a generator function to enable
367
- railway-style programming with dependency injection. Inside the generator,
368
- `yield*` unwraps Results (short-circuiting on failure) and `yield* R.use(Dep)`
369
- acquires dependencies. Dependencies are tracked by the type system and must be
370
- injected before the function can be called.
368
+ `fn()` is a function builder. You pass it a generator and get back a function
369
+ you can call just like any other. The difference is that inside the generator
370
+ you get two superpowers:
371
+
372
+ 1. **Dependency requests** - `yield* R.use(Dep)` gives you an implementation of
373
+ a dependency without worrying about how to acquire it. Think of it like a
374
+ function parameter, except you don't have to pass it in at the call site.
375
+ When one `fn()` function calls another, unmet dependencies propagate up
376
+ automatically, no prop drilling required. You can also choose to supply some
377
+ dependencies but not all, and the rest keep propagating.
378
+
379
+ 2. **Result unwrapping** - `yield* someResult` extracts the success value from
380
+ any `Result` or `AsyncResult`. If it's an error, the function short-circuits
381
+ (early return) and the error propagates to the caller, just like the
382
+ non-generator version (`fn(() => ...)`).
383
+
384
+ The return type of an `fn()` function is `Fn<Args, Success, Errors, Deps>`:
385
+
386
+ - **Args** - the parameter list of your generator (e.g. `(email: string)` →
387
+ `[string]`)
388
+ - **Success** - the unwrapped success type
389
+ - **Errors** - a union of all error codes, accumulated from every `yield*` call
390
+ - **Deps** - a union of all unmet dependencies, accumulated from every
391
+ `yield* R.use()` call
371
392
 
372
- Both `ok()` and `err()` are iterable, which is what makes `yield*` work for
373
- Result unwrapping in generators.
393
+ The `Fn` you get back is only callable once all dependencies are injected (via
394
+ `.inject()`), at which point the `Deps` part of the type becomes `never`.
374
395
 
375
396
  ### Declaring Dependencies
376
397
 
@@ -389,9 +410,6 @@ const Logger = R.dependency<{
389
410
 
390
411
  ### Creating Functions
391
412
 
392
- Use `fn()` with a generator. Inside, `yield*` unwraps Results (short-circuiting
393
- on failure) and `yield* R.use(Dep)` acquires dependencies:
394
-
395
413
  ```typescript
396
414
  const GetUser = R.fn(function* (email: string) {
397
415
  const db = yield* R.use(Database);
@@ -411,26 +429,24 @@ const GetUser = R.fn(function* (email: string) {
411
429
 
412
430
  Key points:
413
431
 
414
- - `yield* R.use(Database)` acquires a dependency from the DI context
415
- - `yield* validateEmail(email)` unwraps a Result; short-circuits on failure
416
- - `yield* R.fromThrowable(...)` unwraps an async Result
432
+ - `yield* R.use(Database)` - acquires a dependency from the DI context
433
+ - `yield* validateEmail(email)` - unwraps a Result; short-circuits on failure
434
+ - `yield* R.fromThrowable(...)` - catches throws/rejections, converting them to
435
+ a Result, then unwraps it
417
436
  - Error types accumulate automatically across all `yield*` calls
418
437
  - Dependency types accumulate automatically across all `yield* R.use()` calls
419
438
 
420
439
  ### Injecting Dependencies
421
440
 
422
- Use `inject()` in a `pipe()` to provide implementations:
441
+ Use `.inject()` to provide implementations:
423
442
 
424
443
  ```typescript
425
- const getUser = R.pipe(
426
- GetUser,
427
- R.inject(
428
- Database.impl({ findUser: async (email) => db.query(email) }),
429
- Logger.impl({ info: console.log }),
430
- ),
444
+ const getUser = GetUser.inject(
445
+ Database.impl({ findUser: async (email) => db.query(email) }),
446
+ Logger.impl({ info: console.log }),
431
447
  );
432
448
 
433
- // Now callable all dependencies satisfied
449
+ // All dependencies satisfied, now callable
434
450
  const result = await getUser("user@example.com");
435
451
  ```
436
452
 
@@ -447,13 +463,25 @@ like `Missing dependency: "database". Use inject() to provide this dependency.`
447
463
  Injection can be done incrementally:
448
464
 
449
465
  ```typescript
450
- const withDb = R.pipe(GetUser, R.inject(Database.impl({/* ... */})));
466
+ const withDb = GetUser.inject(Database.impl({/* ... */}));
451
467
  // Still needs Logger
452
468
 
453
- const getUser = R.pipe(withDb, R.inject(Logger.impl({/* ... */})));
469
+ const getUser = withDb.inject(Logger.impl({/* ... */}));
454
470
  // Fully callable
455
471
  ```
456
472
 
473
+ The standalone `inject()` operator works the same way inside `pipe()`:
474
+
475
+ ```typescript
476
+ const getUser = R.pipe(
477
+ GetUser,
478
+ R.inject(
479
+ Database.impl({ findUser: async (email) => db.query(email) }),
480
+ Logger.impl({ info: console.log }),
481
+ ),
482
+ );
483
+ ```
484
+
457
485
  ### Nested Functions
458
486
 
459
487
  When one `fn()` uses another via `yield* R.use(ChildFn)`, the child's
@@ -479,9 +507,8 @@ const LoginUser = R.fn(function* (email: string, password: string) {
479
507
  // Dependencies: Logger | Database (Database inherited from CheckPermissions)
480
508
  ```
481
509
 
482
- The two-step pattern `yield* R.use(Fn)` then `yield* callable(args)`
483
- separates dependency resolution from execution, keeping the control flow
484
- explicit.
510
+ The two-step pattern, `yield* R.use(Fn)` then `yield* callable(args)`, separates
511
+ dependency resolution from execution, keeping the control flow explicit.
485
512
 
486
513
  ## API Reference
487
514
 
@@ -520,7 +547,7 @@ explicit.
520
547
  `AsyncResult<T, E>` wraps a `Promise<Result<T, E>>` and exposes the same methods
521
548
  as `Result`. All methods return `AsyncResult` (async poison), except terminal
522
549
  operations (`.match()`, `.unwrap()`, `.unwrapOr()`) which return `Promise`.
523
- `AsyncResult` is `PromiseLike` `await` it to get a sync `Result`.
550
+ `AsyncResult` is `PromiseLike`; `await` it to get a sync `Result`.
524
551
 
525
552
  ### Standalone Operators (for `pipe()`)
526
553
 
@@ -558,7 +585,8 @@ operations (`.match()`, `.unwrap()`, `.unwrapOr()`) which return `Promise`.
558
585
  | `fn(func)` | Unify Result return type |
559
586
  | `use(dep)` | Acquire dependency inside a generator |
560
587
  | `use(Fn)` | Get contextualized callable for nested Fn |
561
- | `inject(...impls)` | Provide dependency implementations |
588
+ | `.inject(...impls)` | Provide dependency implementations (method) |
589
+ | `inject(...impls)` | Provide dependency implementations (operator) |
562
590
 
563
591
  ## License
564
592
 
@@ -1,9 +1,10 @@
1
1
  /**
2
- * Shared implementation helpers for Result methods and standalone operators.
2
+ * Shared implementation helpers for methods and standalone operators.
3
3
  *
4
- * Both the methods on ok()/err() and the standalone operators (for pipe())
5
- * need the same transformation logic. This module provides the shared core
6
- * so behavior stays consistent and bugs only need fixing in one place.
4
+ * Both chainable methods (e.g. .map(), .inject()) and standalone operators
5
+ * (for pipe()) need the same transformation logic. This module provides
6
+ * the shared core so behavior stays consistent and bugs only need fixing
7
+ * in one place.
7
8
  *
8
9
  * @internal
9
10
  */
@@ -32,4 +33,9 @@ export declare function handleMatch(result: Result<any, any>, handlers: {
32
33
  * wraps in AsyncResult that resolves to the original Result.
33
34
  */
34
35
  export declare function handleInspect(result: Result<any, any>, fn: (value: any) => any): any;
36
+ /**
37
+ * Core inject logic: merge dependency implementations into an Fn,
38
+ * returning a new Fn with those dependencies satisfied.
39
+ */
40
+ export declare function injectDeps(fn: any, impls: readonly any[]): any;
35
41
  //# sourceMappingURL=handlers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"handlers.d.ts","sourceRoot":"","sources":["../../src/_internal/handlers.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,EAAgB,KAAK,MAAM,EAAE,MAAM,cAAc,CAAC;AAGzD;;;GAGG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,GAAG,GAAG,GAAG,CAmBlE;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAC3B,SAAS,EAAE,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,EAC3B,YAAY,EAAE,GAAG,GACf,GAAG,CA6BL;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAC1B,MAAM,EAAE,MAAM,CAAC,GAAG,EAAE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KAAK,EAAE,SAAS,GAAG,EAAE,GAAG,GAAG,CAM9D"}
@@ -1,9 +1,10 @@
1
1
  /**
2
- * Shared implementation helpers for Result methods and standalone operators.
2
+ * Shared implementation helpers for methods and standalone operators.
3
3
  *
4
- * Both the methods on ok()/err() and the standalone operators (for pipe())
5
- * need the same transformation logic. This module provides the shared core
6
- * so behavior stays consistent and bugs only need fixing in one place.
4
+ * Both chainable methods (e.g. .map(), .inject()) and standalone operators
5
+ * (for pipe()) need the same transformation logic. This module provides
6
+ * the shared core so behavior stays consistent and bugs only need fixing
7
+ * in one place.
7
8
  *
8
9
  * @internal
9
10
  */
@@ -11,6 +12,7 @@ import { Panic } from "../panic.js";
11
12
  import { unknownErr } from "./errors.js";
12
13
  import { isResult, ok } from "../result.js";
13
14
  import { asyncResult } from "../async_result.js";
15
+ import { createFn } from "../fn/fn.js";
14
16
  /**
15
17
  * Core map logic: transform an Ok value, handling Result flattening,
16
18
  * Promise→AsyncResult conversion, and Panic on sync throw.
@@ -95,7 +97,18 @@ export function handleInspect(result, fn) {
95
97
  }
96
98
  }
97
99
  catch {
98
- // Swallow side effects never break the pipeline
100
+ // Swallow; side effects never break the pipeline
99
101
  }
100
102
  return result;
101
103
  }
104
+ /**
105
+ * Core inject logic: merge dependency implementations into an Fn,
106
+ * returning a new Fn with those dependencies satisfied.
107
+ */
108
+ export function injectDeps(fn, impls) {
109
+ const newInjectedDeps = { ...fn._fn._injectedDeps };
110
+ for (const impl of impls) {
111
+ newInjectedDeps[impl.key] = impl.value;
112
+ }
113
+ return createFn(fn._fn._generator, newInjectedDeps);
114
+ }
@@ -1,8 +1,8 @@
1
1
  /**
2
- * AsyncResult a Promise<Result<T, E>> with chainable methods.
2
+ * AsyncResult: a Promise<Result<T, E>> with chainable methods.
3
3
  *
4
4
  * All methods return AsyncResult (async poison), except terminal operations
5
- * (match, unwrap, unwrapOr) which return Promise. AsyncResult is PromiseLike
5
+ * (match, unwrap, unwrapOr) which return Promise. AsyncResult is PromiseLike -
6
6
  * await it to get back a sync Result with all its methods.
7
7
  */
8
8
  import type { Err, Result } from "./result.js";
@@ -14,7 +14,7 @@ import type { HandlerErr, HandlerOk, InferHandlerReturns } from "./_internal/typ
14
14
  * All methods return `AsyncResult` (async poison). Terminal operations
15
15
  * (`match`, `unwrap`, `unwrapOr`) return `Promise`.
16
16
  *
17
- * Implements `PromiseLike` `await` it to get back a sync `Result`.
17
+ * Implements `PromiseLike`; `await` it to get back a sync `Result`.
18
18
  */
19
19
  export type AsyncResult<T, E extends string> = PromiseLike<Result<T, E>> & {
20
20
  map<T2, E2 extends string>(fn: (value: T) => Promise<Result<T2, E2>>): AsyncResult<T2, E | E2 | "UNKNOWN_ERR">;
@@ -1,8 +1,8 @@
1
1
  /**
2
- * AsyncResult a Promise<Result<T, E>> with chainable methods.
2
+ * AsyncResult: a Promise<Result<T, E>> with chainable methods.
3
3
  *
4
4
  * All methods return AsyncResult (async poison), except terminal operations
5
- * (match, unwrap, unwrapOr) which return Promise. AsyncResult is PromiseLike
5
+ * (match, unwrap, unwrapOr) which return Promise. AsyncResult is PromiseLike -
6
6
  * await it to get back a sync Result with all its methods.
7
7
  */
8
8
  // ============================================================================
@@ -1 +1 @@
1
- {"version":3,"file":"fn.d.ts","sourceRoot":"","sources":["../../src/fn/fn.ts"],"names":[],"mappings":"AAAA,0DAA0D;AAE1D,OAAO,EAA6B,KAAK,MAAM,EAAE,MAAM,cAAc,CAAC;AAGtE,OAAO,KAAK,EAEX,UAAU,EAEV,sBAAsB,EACtB,mBAAmB,EACnB,EAAE,EAEF,iBAAiB,EACjB,WAAW,EACX,gBAAgB,EAEhB,YAAY,EACZ,MAAM,YAAY,CAAC;AA8LpB,mEAAmE;AACnE,iBAAS,QAAQ,CAChB,IAAI,SAAS,GAAG,EAAE,EAClB,MAAM,EACN,MAAM,SAAS,MAAM,EACrB,IAAI,SAAS,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC,EAEpC,SAAS,EAAE,CAAC,GAAG,IAA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AAE,QAAQ,EAAE,CAAC"}
package/esm/fn/fn.js CHANGED
@@ -2,6 +2,7 @@
2
2
  import { isErr, isOk, isResult, ok } from "../result.js";
3
3
  import { asyncResult } from "../async_result.js";
4
4
  import { unknownErr } from "../_internal/errors.js";
5
+ import { injectDeps } from "../_internal/handlers.js";
5
6
  // ============================================================================
6
7
  // Type Guards
7
8
  // ============================================================================
@@ -22,9 +23,9 @@ function resolveDependency(request, deps, gen) {
22
23
  return gen.next(deps[request.key]);
23
24
  }
24
25
  // ============================================================================
25
- // Generator Execution Shared Helpers
26
+ // Generator Execution - Shared Helpers
26
27
  // ============================================================================
27
- /** Handle a UseRequest resolves dependencies or creates contextualized callables. */
28
+ /** Handle a UseRequest. Resolves dependencies or creates contextualized callables. */
28
29
  function handleUseRequest(request, gen, deps) {
29
30
  if (request.type === "dependency") {
30
31
  const depRequest = {
@@ -34,7 +35,7 @@ function handleUseRequest(request, gen, deps) {
34
35
  };
35
36
  return resolveDependency(depRequest, deps, gen);
36
37
  }
37
- // type === "fn" create contextualized callable
38
+ // type === "fn", create contextualized callable
38
39
  const target = request.target;
39
40
  const contextualizedCallable = (...callArgs) => {
40
41
  const mergedDeps = { ...deps, ...target._fn._injectedDeps };
@@ -79,14 +80,14 @@ function runGenerator(generator, args, deps) {
79
80
  if (isResult(yielded)) {
80
81
  if (isErr(yielded))
81
82
  return yielded;
82
- // Ok with Promise value transition to async
83
+ // Ok with Promise value, transition to async
83
84
  if (isOk(yielded) && yielded.value instanceof Promise) {
84
85
  return asyncResult(runGeneratorAsync(gen, yielded.value, deps));
85
86
  }
86
87
  result = gen.next(isOk(yielded) ? yielded.value : yielded);
87
88
  continue;
88
89
  }
89
- // Bare Promise transition to async
90
+ // Bare Promise, transition to async
90
91
  if (yielded instanceof Promise) {
91
92
  return asyncResult(runGeneratorAsync(gen, yielded, deps));
92
93
  }
@@ -145,7 +146,7 @@ function createFn(generator, injectedDeps = {}) {
145
146
  // The callable and metadata use `any` extensively because TypeScript can't
146
147
  // express the relationship between generator yield types, dependency resolution,
147
148
  // and the final callable signature. The public type safety comes from the Fn<>
148
- // type wrapper and the fn() overload signatures this internal plumbing is
149
+ // type wrapper and the fn() overload signatures. This internal plumbing is
149
150
  // invisible to consumers.
150
151
  const callable = (...args) => {
151
152
  const output = runGenerator(generator, args, injectedDeps);
@@ -156,8 +157,10 @@ function createFn(generator, injectedDeps = {}) {
156
157
  };
157
158
  // Attach metadata
158
159
  callable._fn = metadata;
160
+ // Builder method: .inject()
161
+ callable.inject = (...impls) => injectDeps(callable, impls);
159
162
  // Make Fn iterable so `yield* use(SomeFn)` works in parent generators.
160
- // This generator yields nothing and immediately returns the callable
163
+ // This generator yields nothing and immediately returns the callable.
161
164
  // `yield*` on a generator that only returns (no yields) evaluates to the
162
165
  // return value, so `const f = yield* use(Fn)` gives back the callable.
163
166
  // deno-lint-ignore require-yield
@@ -172,7 +175,7 @@ function createFn(generator, injectedDeps = {}) {
172
175
  /**
173
176
  * Creates a function with optional dependency injection and Result unwrapping.
174
177
  *
175
- * **Regular function** collapses Result return type branches into a single
178
+ * **Regular function** collapses Result return type branches into a single
176
179
  * `Result<T, E>` (no annotation needed):
177
180
  * ```ts
178
181
  * const divide = R.fn((a: number, b: number) =>
@@ -181,7 +184,7 @@ function createFn(generator, injectedDeps = {}) {
181
184
  * // (a: number, b: number) => Result<number, "DIV_ZERO">
182
185
  * ```
183
186
  *
184
- * **Generator function** enables `yield*` for Result unwrapping (short-circuits
187
+ * **Generator function** enables `yield*` for Result unwrapping (short-circuits
185
188
  * on error) and `yield* R.use(Dep)` for dependency injection:
186
189
  * ```ts
187
190
  * const GetUser = R.fn(function* (email: string) {
@@ -198,7 +201,7 @@ function createFn(generator, injectedDeps = {}) {
198
201
  */
199
202
  // Detect generator functions via their constructor (immune to minification).
200
203
  // This uses `instanceof`, which assumes the generator is from the same realm
201
- // (same global context) as this module. Safe in practice users always write
204
+ // (same global context) as this module. Safe in practice; users always write
202
205
  // `fn(function* () { ... })` inline, never across iframes or VM contexts.
203
206
  const GeneratorFunction = (function* () { }).constructor;
204
207
  // Implementation
@@ -209,8 +212,8 @@ export function fn(funcOrGenerator) {
209
212
  }
210
213
  // Regular function: return as-is. The type overload handles
211
214
  // collapsing Result<T, never> | Result<never, E> into Result<T, E>.
212
- // No Fn wrapper needed no generators, no DI, no runtime overhead.
215
+ // No Fn wrapper needed. No generators, no DI, no runtime overhead.
213
216
  return funcOrGenerator;
214
217
  }
215
- // Used by inject.ts not re-exported from mod.ts
218
+ // Used by inject.ts, not re-exported from mod.ts
216
219
  export { createFn };
@@ -1 +1 @@
1
- {"version":3,"file":"inject.d.ts","sourceRoot":"","sources":["../../src/fn/inject.ts"],"names":[],"mappings":"AAAA,2DAA2D;AAG3D,OAAO,KAAK,EACX,UAAU,EACV,cAAc,EACd,EAAE,EACF,QAAQ,EACR,gBAAgB,EAChB,MAAM,YAAY,CAAC;AAEpB;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,MAAM,GACjB,KAAK,CAAC,KAAK,SAAS,SAAS,cAAc,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,EAC1D,GAAG,OAAO,KAAK,MAGf,IAAI,SAAS,GAAG,EAAE,EAClB,MAAM,EACN,MAAM,SAAS,MAAM,EACrB,IAAI,SAAS,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC,EAEpC,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,KAChC,EAAE,CACJ,IAAI,EACJ,MAAM,EACN,MAAM,EACN,gBAAgB,CAAC,IAAI,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,CAevC,CAAC"}
1
+ {"version":3,"file":"inject.d.ts","sourceRoot":"","sources":["../../src/fn/inject.ts"],"names":[],"mappings":"AAAA,2DAA2D;AAE3D,OAAO,KAAK,EACX,UAAU,EACV,cAAc,EACd,EAAE,EACF,QAAQ,EACR,gBAAgB,EAChB,MAAM,YAAY,CAAC;AAGpB;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,MAAM,GACjB,KAAK,CAAC,KAAK,SAAS,SAAS,cAAc,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,EAC1D,GAAG,OAAO,KAAK,MAGf,IAAI,SAAS,GAAG,EAAE,EAClB,MAAM,EACN,MAAM,SAAS,MAAM,EACrB,IAAI,SAAS,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC,EAEpC,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,KAChC,EAAE,CACJ,IAAI,EACJ,MAAM,EACN,MAAM,EACN,gBAAgB,CAAC,IAAI,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,CAGvC,CAAC"}
package/esm/fn/inject.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /** Dependency injection operator for use with `pipe()`. */
2
- import { createFn } from "./fn.js";
2
+ import { injectDeps } from "../_internal/handlers.js";
3
3
  /**
4
4
  * Provides dependency implementations to an `Fn`. Use inside `pipe()`.
5
5
  *
@@ -21,11 +21,5 @@ import { createFn } from "./fn.js";
21
21
  * ```
22
22
  */
23
23
  export const inject = (...impls) => (fn) => {
24
- // Merge new implementations with existing ones
25
- const newInjectedDeps = { ...fn._fn._injectedDeps };
26
- for (const impl of impls) {
27
- newInjectedDeps[impl.key] = impl.value;
28
- }
29
- // Create new Fn with merged dependencies
30
- return createFn(fn._fn._generator, newInjectedDeps);
24
+ return injectDeps(fn, impls);
31
25
  };
package/esm/fn/types.d.ts CHANGED
@@ -61,6 +61,8 @@ export type Fn<Args extends any[], Return, Errors extends string, Deps extends D
61
61
  _: `ERROR - Missing dependencies: ${DepKeys<Deps>}. Use inject() first.`
62
62
  ]): [Deps] extends [never] ? Result<Return, Errors> | Promise<Result<Return, Errors>> : never;
63
63
  readonly _fn: FnMetadata<Args, Return, Errors, Deps>;
64
+ /** Provides dependency implementations, returning a new Fn with those dependencies satisfied. */
65
+ inject<const Impls extends readonly DependencyImpl<any, string>[]>(...impls: Impls): Fn<Args, Return, Errors, RemoveDepsByKeys<Deps, ImplKeys<Impls>>>;
64
66
  [Symbol.iterator](): Generator<Fn<Args, Return, Errors, Deps>, ContextualizedCallable<Args, Return, Errors>, any>;
65
67
  };
66
68
  /** Extracts dependency key strings from a Dependency union (for error messages). */
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/fn/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAMvD,kEAAkE;AAClE,MAAM,WAAW,UAAU,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,GAAG,MAAM;IACvD,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAC5B,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC;IAChB,IAAI,CAAC,KAAK,EAAE,CAAC,GAAG,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACrC,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,SAAS,CAAC,iBAAiB,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;CAC9D;AAED,+FAA+F;AAC/F,MAAM,WAAW,cAAc,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,GAAG,MAAM;IAC3D,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC;IAChB,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;CAClB;AAED,gFAAgF;AAChF,MAAM,WAAW,iBAAiB,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,GAAG,MAAM;IAC9D,QAAQ,CAAC,IAAI,EAAE,mBAAmB,CAAC;IACnC,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC;IAChB,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,CAA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BAAqB,CAAC,CAAC,CAAC,CAAC,CAAC;AAEzE,4DAA4D;AAC5D,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,aAAa,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC,CAAC;AAMrE,MAAM,MAAM,gBAAgB,CAC3B,IAAI,EACJ,IAAI,SAAS,MAAM,IAChB,IAAI,SAAS,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,SAAS,IAAI,GAAG,KAAK,GAAG,IAAI,CAAC,GACxE,KAAK,CAAC;AAET,MAAM,MAAM,QAAQ,CACnB,KAAK,SAAS,SAAS,cAAc,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,IACjD,KAAK,CAAC,MAAM,CAAC,SAAS,cAAc,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC"}
package/esm/fn/use.d.ts CHANGED
@@ -3,8 +3,8 @@ import type { ContextualizedCallable, Dependency, Fn, UseDependencyRequest, UseF
3
3
  /**
4
4
  * Acquires a dependency or nested Fn inside a generator function.
5
5
  *
6
- * - `yield* R.use(Database)` returns the dependency value
7
- * - `yield* R.use(ChildFn)` returns a contextualized callable that inherits
6
+ * - `yield* R.use(Database)` returns the dependency value
7
+ * - `yield* R.use(ChildFn)` returns a contextualized callable that inherits
8
8
  * the parent's dependency context
9
9
  *
10
10
  * For unwrapping Results, use plain `yield*` instead (no `use()` needed).
@@ -22,7 +22,7 @@ type InspectOperator = <R extends AnyResult, U>(fn: (value: InferOk<R>) => U) =>
22
22
  * Runs a side effect on the ok value without changing the Result.
23
23
  *
24
24
  * The callback's return value is ignored. If the callback throws or
25
- * returns a rejected Promise, the error is silently swallowed — side
25
+ * returns a rejected Promise, the error is silently swallowed. Side
26
26
  * effects never break the pipeline.
27
27
  *
28
28
  * @example
@@ -5,7 +5,7 @@ import { asyncResult } from "../async_result.js";
5
5
  * Runs a side effect on the ok value without changing the Result.
6
6
  *
7
7
  * The callback's return value is ignored. If the callback throws or
8
- * returns a rejected Promise, the error is silently swallowed — side
8
+ * returns a rejected Promise, the error is silently swallowed. Side
9
9
  * effects never break the pipeline.
10
10
  *
11
11
  * @example
@@ -24,7 +24,7 @@ type InspectErrOperator = <R extends AnyResult, U>(fn: (err: Extract<Awaited<R>,
24
24
  * Runs a side effect on the error without changing the Result.
25
25
  *
26
26
  * The callback's return value is ignored. If the callback throws or
27
- * returns a rejected Promise, the error is silently swallowed — side
27
+ * returns a rejected Promise, the error is silently swallowed. Side
28
28
  * effects never break the pipeline.
29
29
  *
30
30
  * @example
@@ -5,7 +5,7 @@ import { asyncResult } from "../async_result.js";
5
5
  * Runs a side effect on the error without changing the Result.
6
6
  *
7
7
  * The callback's return value is ignored. If the callback throws or
8
- * returns a rejected Promise, the error is silently swallowed — side
8
+ * returns a rejected Promise, the error is silently swallowed. Side
9
9
  * effects never break the pipeline.
10
10
  *
11
11
  * @example
@@ -30,7 +30,7 @@ type MapOperator = <R extends AnyResult, U>(fn: (value: InferOk<R>) => U) => (re
30
30
  * Transforms the ok value. Skips if the result is an error.
31
31
  *
32
32
  * If `fn` returns a Result, it's automatically flattened (no nesting).
33
- * If `fn` returns a Promise, the pipeline becomes async resolved values
33
+ * If `fn` returns a Promise, the pipeline becomes async. Resolved values
34
34
  * become ok, rejections become `UNKNOWN_ERR`.
35
35
  *
36
36
  * Throws {@link Panic} if `fn` throws synchronously.