udic 2.0.4 → 2.0.6
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 -13
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -2,24 +2,29 @@ type ObjectUnionToIntersect<T> = { [K in T as K & string] : K }[any];
|
|
|
2
2
|
export type ContextArgs = {
|
|
3
3
|
[key: string | symbol]: any
|
|
4
4
|
} | ((...args: any[]) => any);
|
|
5
|
-
export type Context<Deps extends ContextArgs> = ObjectUnionToIntersect<Deps extends
|
|
5
|
+
export type Context<Deps extends ContextArgs> = ObjectUnionToIntersect<Deps extends ImplTag<infer C> ? C : Deps extends (c: infer C, ...args: any[]) => any ? C : Deps>;
|
|
6
|
+
export interface ImplTag<Context> {
|
|
7
|
+
"~infer": Context;
|
|
8
|
+
}
|
|
6
9
|
export interface Impl {
|
|
7
|
-
<const
|
|
10
|
+
<const F extends (...args: any[]) => any>(fn: F): F & ImplTag<F extends (() => infer Out extends {}) ? Out : F extends ((c: infer In extends {}) => infer Out extends {}) ? In & Out : never>;
|
|
11
|
+
<const Out extends ContextArgs>(fn: () => Context<Out>): (() => Context<Out>) & ImplTag<Context<Out>>;
|
|
8
12
|
<
|
|
9
13
|
const In extends ContextArgs,
|
|
10
14
|
const Out extends ContextArgs
|
|
11
|
-
>(fn: (c: Context<In>) => Context<Out>): (c: Context<In>) => Context<Out
|
|
15
|
+
>(fn: (c: Context<In>) => Context<Out>): ((c: Context<In>) => Context<Out>) & ImplTag<Context<In> & Context<Out>>;
|
|
12
16
|
}
|
|
13
17
|
/**
|
|
14
18
|
* Create a sync implementation of a dependency.
|
|
15
19
|
*/
|
|
16
20
|
export declare const impl: Impl;
|
|
17
21
|
export interface ImplAsync {
|
|
18
|
-
<const
|
|
22
|
+
<const F extends (...args: any[]) => any>(fn: F): F & ImplTag<F extends (() => infer Out extends {} | Promise<{}>) ? Awaited<Out> : F extends ((c: infer In extends {}) => infer Out extends {} | Promise<{}>) ? In & Awaited<Out> : never>;
|
|
23
|
+
<const Out extends ContextArgs>(fn: () => Context<Out> | Promise<Context<Out>>): (() => Context<Out>) & ImplTag<Context<Out>>;
|
|
19
24
|
<
|
|
20
25
|
const In extends ContextArgs,
|
|
21
26
|
const Out extends ContextArgs
|
|
22
|
-
>(fn: (c: Context<In>) => Context<Out> | Promise<Context<Out>>): (c: Context<In>) => Context<Out> | Promise<Context<Out>>;
|
|
27
|
+
>(fn: (c: Context<In>) => Context<Out> | Promise<Context<Out>>): ((c: Context<In>) => Context<Out> | Promise<Context<Out>>) & ImplTag<Context<In> & Context<Out>>;
|
|
23
28
|
}
|
|
24
29
|
/**
|
|
25
30
|
* Create an async implementation of a dependency.
|
|
@@ -27,18 +32,18 @@ export interface ImplAsync {
|
|
|
27
32
|
export declare const implAsync: ImplAsync;
|
|
28
33
|
type _ImplFn = (() => {} | Promise<{}>) | ((c: any) => {} | Promise<{}>);
|
|
29
34
|
type _ImplFns = [_ImplFn, ..._ImplFn[]];
|
|
30
|
-
interface Link {
|
|
31
|
-
<
|
|
32
|
-
const In extends {},
|
|
33
|
-
Impls extends _ImplFns
|
|
34
|
-
>(c: In, ...impls: Impls): Context<Impls[number]>;
|
|
35
|
-
}
|
|
36
35
|
/**
|
|
37
36
|
* Link sync implementations.
|
|
38
37
|
*/
|
|
39
|
-
export declare const link:
|
|
38
|
+
export declare const link: <
|
|
39
|
+
const In extends {},
|
|
40
|
+
Impls extends _ImplFns
|
|
41
|
+
>(c: In, ...impls: Impls) => Context<Impls[number]>;
|
|
40
42
|
/**
|
|
41
43
|
* Link async implementations concurrently.
|
|
42
44
|
*/
|
|
43
|
-
export declare const linkAsync:
|
|
45
|
+
export declare const linkAsync: <
|
|
46
|
+
const In extends {},
|
|
47
|
+
Impls extends _ImplFns
|
|
48
|
+
>(c: In, ...impls: Impls) => Promise<Context<Impls[number]>>;
|
|
44
49
|
export {};
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"udic","version":"2.0.
|
|
1
|
+
{"name":"udic","version":"2.0.6","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"}}
|