udic 0.1.4 → 0.1.5
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 +10 -10
- package/index.js +1 -1
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
declare const
|
|
2
|
-
|
|
1
|
+
declare const _t: unique symbol;
|
|
2
|
+
declare const _d: unique symbol;
|
|
3
3
|
type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends (x: infer I) => void ? I : never;
|
|
4
4
|
type Prettify<T> = { [K in keyof T] : T[K] } & {};
|
|
5
5
|
export interface Service<
|
|
6
6
|
T extends string | symbol,
|
|
7
7
|
K
|
|
8
8
|
> {
|
|
9
|
-
|
|
10
|
-
[
|
|
9
|
+
[_t]: K;
|
|
10
|
+
[_d]: undefined extends K ? { [k in T]? : K } : { [k in T] : K };
|
|
11
11
|
}
|
|
12
12
|
export interface Compute<
|
|
13
13
|
T,
|
|
14
14
|
R
|
|
15
15
|
> {
|
|
16
|
+
[_t]: R;
|
|
17
|
+
[_d]: T;
|
|
16
18
|
(c: T): R;
|
|
17
|
-
0: R;
|
|
18
|
-
[_]: T;
|
|
19
19
|
}
|
|
20
20
|
export type Dependency = Service<any, any> | Compute<any, any>;
|
|
21
|
-
export type InferDependencies<T extends Dependency> = Prettify<UnionToIntersection<T[
|
|
21
|
+
export type InferDependencies<T extends Dependency> = Prettify<UnionToIntersection<T[typeof _d]>>;
|
|
22
22
|
/**
|
|
23
23
|
* Create a service
|
|
24
24
|
* @param name - The service name
|
|
25
25
|
*/
|
|
26
26
|
export declare const service: <T extends string | symbol>(name: T) => (<K>() => Service<T, K>);
|
|
27
27
|
/**
|
|
28
|
-
* Create a
|
|
28
|
+
* Create a compute that relies on other services or computes
|
|
29
29
|
* @param deps - The service dependencies
|
|
30
30
|
* @param f
|
|
31
31
|
*/
|
|
32
32
|
export declare const derive: <
|
|
33
33
|
const T extends Dependency[],
|
|
34
34
|
const R
|
|
35
|
-
>(deps: T, f: (...args: { [K in keyof T] : T[K][
|
|
35
|
+
>(deps: T, f: (...args: { [K in keyof T] : T[K][typeof _t] }) => R) => Compute<InferDependencies<T[number]>, R>;
|
|
36
36
|
/**
|
|
37
|
-
* Inject
|
|
37
|
+
* Inject dependencies to the compute
|
|
38
38
|
* @param compute
|
|
39
39
|
* @param deps - Dependencies to inject
|
|
40
40
|
*/
|
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export let service=e=>()=>e;export let derive=(e,t)=>n=>t(...e.map(e=>typeof e===`function`?n[e]??=e(n):n[e]));export let inject=(e,t)=>n=>e({...n,...t});
|
|
1
|
+
;export let service=e=>()=>e;export let derive=(e,t)=>n=>t(...e.map(e=>typeof e===`function`?n[e]??=e(n):n[e]));export let inject=(e,t)=>n=>e({...n,...t});
|