udic 0.4.0 → 1.0.0
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 +18 -7
- package/index.js +1 -1
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ declare const _t: unique symbol;
|
|
|
2
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
|
+
type List<T> = [T, ...T[]];
|
|
5
6
|
export interface Service<
|
|
6
7
|
K extends string,
|
|
7
8
|
T
|
|
@@ -17,7 +18,7 @@ export interface Compute<
|
|
|
17
18
|
[_d]: T;
|
|
18
19
|
(c: T): R;
|
|
19
20
|
}
|
|
20
|
-
export interface
|
|
21
|
+
export interface Impl<
|
|
21
22
|
K extends string,
|
|
22
23
|
D,
|
|
23
24
|
R
|
|
@@ -41,8 +42,8 @@ export declare const service: <const T extends string>(name: T) => (<K>() => Ser
|
|
|
41
42
|
* @param deps - The service dependencies
|
|
42
43
|
* @param f
|
|
43
44
|
*/
|
|
44
|
-
export declare const
|
|
45
|
-
const T extends
|
|
45
|
+
export declare const use: <
|
|
46
|
+
const T extends List<Service<any, any> | Compute<any, any>>,
|
|
46
47
|
R
|
|
47
48
|
>(deps: T, f: (...args: { [K in keyof T] : InferResult<T[K]> }) => R) => Compute<InferDependency<T[number]>, R>;
|
|
48
49
|
/**
|
|
@@ -55,13 +56,23 @@ export declare const inject: <
|
|
|
55
56
|
R,
|
|
56
57
|
D extends Partial<T>
|
|
57
58
|
>(compute: Compute<T, R>, d: D) => Compute<Prettify<Omit<T, keyof D>>, R>;
|
|
59
|
+
/**
|
|
60
|
+
* Create an implementation of the service that depends on other services
|
|
61
|
+
* @param service
|
|
62
|
+
* @param compute
|
|
63
|
+
*/
|
|
58
64
|
export declare const impl: <
|
|
59
65
|
K extends string,
|
|
60
66
|
T,
|
|
61
67
|
D
|
|
62
|
-
>(service: Service<K, T>, compute: Compute<D, T>) =>
|
|
63
|
-
|
|
64
|
-
|
|
68
|
+
>(service: Service<K, T>, compute: Compute<D, T>) => Impl<K, D, T>;
|
|
69
|
+
/**
|
|
70
|
+
* Provide dependencies to implementations
|
|
71
|
+
* @param impls
|
|
72
|
+
* @param deps
|
|
73
|
+
*/
|
|
74
|
+
export declare const link: <
|
|
75
|
+
const T extends List<Impl<any, any, any>>,
|
|
65
76
|
D extends InferDependency<T[number]>
|
|
66
|
-
>(
|
|
77
|
+
>(impls: T, deps: D) => Prettify<D & InferResult<T[number]>>;
|
|
67
78
|
export {};
|
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
let _t=Symbol();export let service=e=>()=>e;let tag=i=>(i[_t]=Symbol(),i);export let
|
|
1
|
+
let _t=Symbol();export let service=e=>()=>e;let tag=i=>(i[_t]=Symbol(),i);export let use=(i,o)=>tag(a=>o(...i.map(i=>typeof i===`function`?a[i[_t]]??=i(a):a[i])));export let inject=(e,i)=>tag(a=>e({...a,...i}));export let impl=(e,i)=>[e,i];export let link=(e,i)=>{i={...i};for(let a=0;a<e.length;a++)i[e[a][0]]=e[a][1](i);return i};
|