udic 0.3.1 → 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.
Files changed (3) hide show
  1. package/index.d.ts +19 -8
  2. package/index.js +1 -1
  3. package/package.json +2 -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 Layer<
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 derive: <
45
- const T extends (Service<any, any> | Compute<any, any>)[],
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>;
58
- export declare const layer: <
59
+ /**
60
+ * Create an implementation of the service that depends on other services
61
+ * @param service
62
+ * @param compute
63
+ */
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>) => Layer<K, D, T>;
63
- export declare const provide: <
64
- const T extends Layer<any, any, any>[],
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
- >(layers: T, deps: D) => Prettify<D & InferResult<T[number]>>;
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 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 layer=(e,i)=>[e,i];export let provide=(e,i)=>{for(let a=0;a<e.length;a++)i[e[a][0]]=e[a][1](i);return i};
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};
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "udic",
3
- "version": "0.3.1",
3
+ "version": "1.0.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"