udic 0.1.4 → 0.2.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 +12 -11
  2. package/index.js +1 -1
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -1,40 +1,41 @@
1
- declare const _: unique symbol;
2
- type _ = typeof _;
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
- 0: K;
10
- [_]: undefined extends K ? { [k in T]? : K } : { [k in T] : K };
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 InferResult<T extends Dependency> = T[typeof _t];
22
+ export type InferDependency<T extends Dependency> = Prettify<UnionToIntersection<T[typeof _d]>>;
22
23
  /**
23
24
  * Create a service
24
25
  * @param name - The service name
25
26
  */
26
- export declare const service: <T extends string | symbol>(name: T) => (<K>() => Service<T, K>);
27
+ export declare const service: <T extends string | symbol>(name: T) => (<K>() => Service<T, K> & T);
27
28
  /**
28
- * Create a service that relies on other services
29
+ * Create a compute that relies on other services or computes
29
30
  * @param deps - The service dependencies
30
31
  * @param f
31
32
  */
32
33
  export declare const derive: <
33
34
  const T extends Dependency[],
34
35
  const R
35
- >(deps: T, f: (...args: { [K in keyof T] : T[K][0] }) => R) => Compute<InferDependencies<T[number]>, R>;
36
+ >(deps: T, f: (...args: { [K in keyof T] : InferResult<T[K]> }) => R) => Compute<InferDependency<T[number]>, R>;
36
37
  /**
37
- * Inject some dependencies to the compute
38
+ * Inject dependencies to the compute
38
39
  * @param compute
39
40
  * @param deps - Dependencies to inject
40
41
  */
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});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "udic",
3
- "version": "0.1.4",
3
+ "version": "0.2.0",
4
4
  "description": "A simple dependency injection library",
5
5
  "keywords": ["di"],
6
6
  "license": "MIT",