udic 0.3.0 → 0.4.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 +14 -15
- package/index.js +1 -1
- package/package.json +2 -1
package/index.d.ts
CHANGED
|
@@ -17,14 +17,13 @@ export interface Compute<
|
|
|
17
17
|
[_d]: T;
|
|
18
18
|
(c: T): R;
|
|
19
19
|
}
|
|
20
|
-
export interface
|
|
20
|
+
export interface ServiceImpl<
|
|
21
21
|
K extends string,
|
|
22
|
-
|
|
22
|
+
D,
|
|
23
|
+
R
|
|
23
24
|
> {
|
|
24
|
-
[_t]: { [k in K] :
|
|
25
|
-
[_d]:
|
|
26
|
-
0: K;
|
|
27
|
-
1: C;
|
|
25
|
+
[_t]: { [k in K] : R };
|
|
26
|
+
[_d]: D;
|
|
28
27
|
}
|
|
29
28
|
export type InferResult<T extends {
|
|
30
29
|
[_t]: any
|
|
@@ -36,7 +35,7 @@ export type InferDependency<T extends {
|
|
|
36
35
|
* Create a service
|
|
37
36
|
* @param name - The service name
|
|
38
37
|
*/
|
|
39
|
-
export declare const service: <T extends string>(name: T) => (<K>() => Service<T, K> & T);
|
|
38
|
+
export declare const service: <const T extends string>(name: T) => (<K>() => Service<T, K> & T);
|
|
40
39
|
/**
|
|
41
40
|
* Create a compute that relies on other services or computes
|
|
42
41
|
* @param deps - The service dependencies
|
|
@@ -44,7 +43,7 @@ export declare const service: <T extends string>(name: T) => (<K>() => Service<T
|
|
|
44
43
|
*/
|
|
45
44
|
export declare const derive: <
|
|
46
45
|
const T extends (Service<any, any> | Compute<any, any>)[],
|
|
47
|
-
|
|
46
|
+
R
|
|
48
47
|
>(deps: T, f: (...args: { [K in keyof T] : InferResult<T[K]> }) => R) => Compute<InferDependency<T[number]>, R>;
|
|
49
48
|
/**
|
|
50
49
|
* Inject dependencies to the compute
|
|
@@ -56,13 +55,13 @@ export declare const inject: <
|
|
|
56
55
|
R,
|
|
57
56
|
D extends Partial<T>
|
|
58
57
|
>(compute: Compute<T, R>, d: D) => Compute<Prettify<Omit<T, keyof D>>, R>;
|
|
59
|
-
export declare const
|
|
60
|
-
T,
|
|
58
|
+
export declare const impl: <
|
|
61
59
|
K extends string,
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const
|
|
60
|
+
T,
|
|
61
|
+
D
|
|
62
|
+
>(service: Service<K, T>, compute: Compute<D, T>) => ServiceImpl<K, D, T>;
|
|
63
|
+
export declare const merge: <
|
|
64
|
+
const T extends ServiceImpl<any, any, any>[],
|
|
65
|
+
D extends InferDependency<T[number]>
|
|
67
66
|
>(layers: T, deps: D) => Prettify<D & InferResult<T[number]>>;
|
|
68
67
|
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 derive=(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
|
|
1
|
+
let _t=Symbol();export let service=e=>()=>e;let tag=i=>(i[_t]=Symbol(),i);export let derive=(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 merge=(e,i)=>{i={...i};for(let a=0;a<e.length;a++)i[e[a][0]]=e[a][1](i);return i};
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "udic",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "A simple dependency injection library",
|
|
5
5
|
"keywords": ["di"],
|
|
6
6
|
"license": "MIT",
|
|
7
|
+
"homepage": "https://re-utils.pages.dev/di",
|
|
7
8
|
"repository": {
|
|
8
9
|
"type": "git",
|
|
9
10
|
"url": "git+https://github.com/re-utils/di.git"
|