udic 0.1.5 → 0.2.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/index.d.ts +4 -3
- package/index.js +1 -1
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -18,12 +18,13 @@ export interface Compute<
|
|
|
18
18
|
(c: T): R;
|
|
19
19
|
}
|
|
20
20
|
export type Dependency = Service<any, any> | Compute<any, any>;
|
|
21
|
-
export type
|
|
21
|
+
export type InferResult<T extends Dependency> = T[typeof _t];
|
|
22
|
+
export type InferDependency<T extends Dependency> = Prettify<UnionToIntersection<T[typeof _d]>>;
|
|
22
23
|
/**
|
|
23
24
|
* Create a service
|
|
24
25
|
* @param name - The service name
|
|
25
26
|
*/
|
|
26
|
-
export declare const service: <T extends string | symbol>(name: T) => (<K>() => Service<T, K>);
|
|
27
|
+
export declare const service: <T extends string | symbol>(name: T) => (<K>() => Service<T, K> & T);
|
|
27
28
|
/**
|
|
28
29
|
* Create a compute that relies on other services or computes
|
|
29
30
|
* @param deps - The service dependencies
|
|
@@ -32,7 +33,7 @@ export declare const service: <T extends string | symbol>(name: T) => (<K>() =>
|
|
|
32
33
|
export declare const derive: <
|
|
33
34
|
const T extends Dependency[],
|
|
34
35
|
const R
|
|
35
|
-
>(deps: T, f: (...args: { [K in keyof T] : T[K]
|
|
36
|
+
>(deps: T, f: (...args: { [K in keyof T] : InferResult<T[K]> }) => R) => Compute<InferDependency<T[number]>, R>;
|
|
36
37
|
/**
|
|
37
38
|
* Inject dependencies to the compute
|
|
38
39
|
* @param compute
|
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
let _t=Symbol();;export let service=e=>()=>e;export let derive=(t,n)=>{let r=r=>n(...t.map(t=>typeof t===`function`?r[t[_t]]??=t(r):r[t]));r[_t]=Symbol();return r};export let inject=(e,t)=>n=>e({...n,...t});
|