udic 0.1.3 → 0.1.4
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 +1 -2
- package/index.d.ts +8 -9
- package/package.json +1 -1
package/README.md
CHANGED
package/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
declare const _: unique symbol;
|
|
2
2
|
type _ = typeof _;
|
|
3
3
|
type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends (x: infer I) => void ? I : never;
|
|
4
|
+
type Prettify<T> = { [K in keyof T] : T[K] } & {};
|
|
4
5
|
export interface Service<
|
|
5
6
|
T extends string | symbol,
|
|
6
7
|
K
|
|
@@ -16,11 +17,8 @@ export interface Compute<
|
|
|
16
17
|
0: R;
|
|
17
18
|
[_]: T;
|
|
18
19
|
}
|
|
19
|
-
export type
|
|
20
|
-
export type
|
|
21
|
-
export type Dependency = AnyService | AnyCompute;
|
|
22
|
-
export type InferDependencies<T extends Dependency[]> = { [K in keyof T] : T[K][0] };
|
|
23
|
-
export type InferRecord<T extends Dependency[]> = UnionToIntersection<T[number][_]>;
|
|
20
|
+
export type Dependency = Service<any, any> | Compute<any, any>;
|
|
21
|
+
export type InferDependencies<T extends Dependency> = Prettify<UnionToIntersection<T[_]>>;
|
|
24
22
|
/**
|
|
25
23
|
* Create a service
|
|
26
24
|
* @param name - The service name
|
|
@@ -34,14 +32,15 @@ export declare const service: <T extends string | symbol>(name: T) => (<K>() =>
|
|
|
34
32
|
export declare const derive: <
|
|
35
33
|
const T extends Dependency[],
|
|
36
34
|
const R
|
|
37
|
-
>(deps: T, f: (...args:
|
|
35
|
+
>(deps: T, f: (...args: { [K in keyof T] : T[K][0] }) => R) => Compute<InferDependencies<T[number]>, R>;
|
|
38
36
|
/**
|
|
39
37
|
* Inject some dependencies to the compute
|
|
40
38
|
* @param compute
|
|
41
39
|
* @param deps - Dependencies to inject
|
|
42
40
|
*/
|
|
43
41
|
export declare const inject: <
|
|
44
|
-
T
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
T,
|
|
43
|
+
R,
|
|
44
|
+
D extends Partial<T>
|
|
45
|
+
>(compute: Compute<T, R>, d: D) => Compute<Prettify<Omit<T, keyof D>>, R>;
|
|
47
46
|
export {};
|