| @@ -1,64 +1,36 | |||
|
|
1 | 1 | import { Foo } from "./Foo"; |
|
|
2 | 2 | import { Bar } from "./Bar"; |
|
|
3 | import { ActivationType } from "../di/interfaces"; | |
|
|
4 | import { Builder } from "../di/Annotations"; | |
|
|
5 | 3 | import { Box } from "./Box"; |
|
|
6 | ||
|
|
7 | interface RegistrationOptions { | |
|
|
8 | activation?: ActivationType; | |
|
|
9 | } | |
|
|
10 | ||
|
|
11 | interface Dependency<K extends keyof any> { | |
|
|
12 | $dependency: K; | |
|
|
13 | ||
|
|
14 | lazy?: boolean; | |
|
|
15 | } | |
|
|
4 | import { primitive } from "../safe"; | |
|
|
5 | import { Constructor } from "../interfaces"; | |
|
|
16 | 6 | |
|
|
17 | interface Lazy<K extends keyof any> extends Dependency<K> { | |
|
|
18 | lazy: true; | |
|
|
19 | } | |
|
|
20 | ||
|
|
21 | type PromiseOrValue<T> = T | PromiseLike<T>; | |
|
|
22 | ||
|
|
23 | interface ConfigBuilder<S> { | |
|
|
24 | build<K extends keyof S, T = S[K]>(name: K): Builder<T, S>; | |
|
|
25 | ||
|
|
26 | dependency<K extends keyof S>(name: K): Dependency<K>; | |
|
|
27 | ||
|
|
28 | lazy<K extends keyof S>(name: K): Lazy<K>; | |
|
|
29 | ||
|
|
30 | mapTo<K extends keyof S>(name: K, ctor: () => PromiseOrValue<new (...args: any[]) => S[K]>): ConfigBuilder<S>; | |
|
|
31 | ||
|
|
32 | } | |
|
|
33 | ||
|
|
34 | interface ContainerServices { | |
|
|
35 | barBox: Box<Bar>; | |
|
|
36 | ||
|
|
7 | interface Services { | |
|
|
37 | 8 | foo: Foo; |
|
|
38 | 9 | |
|
|
39 | 10 | bar: Bar; |
|
|
40 | 11 | |
|
|
41 | password: string; | |
|
|
12 | box: Box<Foo>; | |
|
|
13 | ||
|
|
14 | host: string; | |
|
|
42 | 15 | |
|
|
43 | user: string; | |
|
|
16 | } | |
|
|
44 | 17 | |
|
|
45 | timeout: number; | |
|
|
18 | interface TypeDescriptor<T, C extends Constructor<T>> { | |
|
|
19 | $type: C; | |
|
|
20 | ||
|
|
21 | params: Wrap<ConstructorParameters<C>>; | |
|
|
46 | 22 | } |
|
|
47 | 23 | |
|
|
48 | declare function load<M, C extends keyof M>(m: PromiseLike<M>, name: C): () => PromiseLike<M[C]>; | |
|
|
24 | function typeRegistration<T, C extends Constructor<T>>(target: C, params: Wrap<ConstructorParameters<C>>): TypeDescriptor<T, C> { | |
|
|
25 | throw new Error(); | |
|
|
26 | } | |
|
|
49 | 27 | |
|
|
50 | const t = { | |
|
|
51 | barBox: load(import("./Box"), "Box"), | |
|
|
52 | ||
|
|
53 | foo: async () => (await import("./Bar")).Bar, | |
|
|
54 | ||
|
|
55 | bar: Bar, | |
|
|
28 | type Wrap<T> = T extends primitive ? T : | |
|
|
29 | { [k in keyof T]: Wrap<T[k]> } | TypeDescriptor<T, Constructor<T>>; | |
|
|
56 | 30 | |
|
|
57 | password: String, | |
|
|
58 | ||
|
|
59 | user: String, | |
|
|
60 | ||
|
|
61 | timeout: Number | |
|
|
31 | const config: Wrap<Services> = { | |
|
|
32 | foo: typeRegistration(Foo, []), | |
|
|
33 | bar: typeRegistration(Bar, [{ foo: null as any, nested: null as any }]), | |
|
|
34 | box: typeRegistration(Box, [{ $type: Bar, params: [] }]), | |
|
|
35 | host: "" | |
|
|
62 | 36 | }; |
|
|
63 | ||
|
|
64 | export declare const config: ConfigBuilder<ContainerServices>; | |
General Comments 0
You need to be logged in to leave comments.
Login now
