udic 2.0.1 → 2.0.3

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 (2) hide show
  1. package/index.d.ts +18 -23
  2. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -1,53 +1,48 @@
1
1
  type ObjectUnionToIntersect<T> = { [K in T as K & string] : K }[any];
2
2
  export type ContextArgs = {
3
3
  [key: string | symbol]: any
4
- } | ((c: {}, ...args: any[]) => any) | Impl;
5
- export type Context<Deps extends ContextArgs> = ObjectUnionToIntersect<Deps extends Impl ? Awaited<Deps["infer"]> : Deps extends (c: infer C, ...args: any[]) => any ? C : Deps>;
6
- export interface Impl<
7
- In = any,
8
- Out extends {} = {}
9
- > {
10
- infer: In & Out;
11
- (c: In): Out;
12
- }
13
- export interface ImplFn {
14
- <const F extends () => {}>(fn: F): F extends (() => infer Out extends {}) ? Impl<{}, Out> : never;
15
- <const F extends (c: any) => {}>(fn: F): F extends ((c: infer In) => infer Out extends {}) ? Impl<In, Out> : never;
16
- <const Out extends ContextArgs>(fn: (c: {}) => Context<Out>): Impl<{}, Context<Out>>;
4
+ } | ((...args: any[]) => any);
5
+ export type Context<Deps extends ContextArgs> = ObjectUnionToIntersect<Deps extends (() => infer Out extends {}) ? Awaited<Out> : Deps extends ((c: infer In extends {}) => infer Out extends {}) ? In & Awaited<Out> : Deps extends (c: infer C, ...args: any[]) => any ? C : Deps>;
6
+ export interface Impl {
7
+ <const F extends () => {}>(fn: F): F;
8
+ <const F extends (c: any) => {}>(fn: F): F;
9
+ <const Out extends ContextArgs>(fn: (c: {}) => Context<Out>): (c: {}) => Context<Out>;
17
10
  <
18
11
  const In extends ContextArgs,
19
12
  const Out extends ContextArgs
20
- >(fn: (c: Context<In>) => Context<Out>): Impl<Context<In>, Context<Out>>;
13
+ >(fn: (c: Context<In>) => Context<Out>): (c: Context<In>) => Context<Out>;
21
14
  }
22
15
  /**
23
16
  * Create a sync implementation of a dependency.
24
17
  */
25
- export declare const impl: ImplFn;
26
- export interface ImplAsyncFn {
27
- <const F extends () => Promise<{}>>(fn: F): F extends (() => infer Out extends {}) ? Impl<{}, Out> : never;
28
- <const F extends (c: any) => Promise<{}>>(fn: F): F extends ((c: infer In) => infer Out extends {}) ? Impl<In, Out> : never;
29
- <const Out extends ContextArgs>(fn: (c: {}) => Promise<Context<Out>>): Impl<{}, Promise<Context<Out>>>;
18
+ export declare const impl: Impl;
19
+ export interface ImplAsync {
20
+ <const F extends () => {} | Promise<{}>>(fn: F): F;
21
+ <const F extends (c: any) => {} | Promise<{}>>(fn: F): F;
22
+ <const Out extends ContextArgs>(fn: (c: {}) => Context<Out> | Promise<Context<Out>>): (c: {}) => Context<Out> | Promise<Context<Out>>;
30
23
  <
31
24
  const In extends ContextArgs,
32
25
  const Out extends ContextArgs
33
- >(fn: (c: Context<In>) => Promise<Context<Out>>): Impl<Context<In>, Promise<Context<Out>>>;
26
+ >(fn: (c: Context<In>) => Context<Out> | Promise<Context<Out>>): (c: Context<In>) => Context<Out> | Promise<Context<Out>>;
34
27
  }
35
28
  /**
36
29
  * Create an async implementation of a dependency.
37
30
  */
38
- export declare const implAsync: ImplAsyncFn;
31
+ export declare const implAsync: ImplAsync;
32
+ type _ImplFn = (() => {} | Promise<{}>) | ((c: any) => {} | Promise<{}>);
33
+ type _ImplFns = [_ImplFn, ..._ImplFn[]];
39
34
  /**
40
35
  * Link sync implementations.
41
36
  */
42
37
  export declare const link: <
43
38
  const In extends {},
44
- Impls extends [Impl<In, any>, ...Impl<In, any>[]]
39
+ Impls extends _ImplFns
45
40
  >(c: In, ...impls: Impls) => In & ReturnType<Impls[number]>;
46
41
  /**
47
42
  * Link async implementations concurrently.
48
43
  */
49
44
  export declare const linkAsync: <
50
45
  const In extends {},
51
- Impls extends [Impl<In, any>, ...Impl<In, any>[]]
46
+ Impls extends _ImplFns
52
47
  >(c: In, ...impls: Impls) => Promise<In & Awaited<ReturnType<Impls[number]>>>;
53
48
  export {};
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"udic","version":"2.0.1","description":"A simple dependency injection library","keywords":["di"],"license":"MIT","homepage":"https://re-utils.pages.dev/di","repository":{"type":"git","url":"git+https://github.com/re-utils/di.git"},"type":"module","main":"./index.js","types":"./index.d.ts","exports":{".":"./index.js"}}
1
+ {"name":"udic","version":"2.0.3","description":"A simple dependency injection library","keywords":["di"],"license":"MIT","homepage":"https://re-utils.pages.dev/di","repository":{"type":"git","url":"git+https://github.com/re-utils/di.git"},"type":"module","main":"./index.js","types":"./index.d.ts","exports":{".":"./index.js"}}