|
|
@@
-1,68
+1,90
|
|
|
1
|
import { primitive } from "../../safe";
|
|
1
|
import { primitive } from "../../safe";
|
|
|
2
|
import { ActivationType } from "../interfaces";
|
|
2
|
import { ActivationType } from "../interfaces";
|
|
|
3
|
import { AnnotaionBuilder } from "../Annotations";
|
|
3
|
import { AnnotaionBuilder } from "../Annotations";
|
|
|
4
|
import { LazyDependencyRegistration, DependencyRegistration } from "../Configuration";
|
|
4
|
import { LazyDependencyRegistration, DependencyRegistration } from "../Configuration";
|
|
|
5
|
import { PromiseOrValue } from "../../interfaces";
|
|
5
|
import { Container } from "../Container";
|
|
|
6
|
|
|
6
|
|
|
|
7
|
export interface DependencyOptions<T> {
|
|
7
|
export interface DependencyOptions<T> {
|
|
|
8
|
optional?: boolean;
|
|
8
|
optional?: boolean;
|
|
|
9
|
default?: T;
|
|
9
|
default?: T;
|
|
|
10
|
}
|
|
10
|
}
|
|
|
11
|
|
|
11
|
|
|
|
12
|
export interface LazyDependencyOptions<T> extends DependencyOptions<T> {
|
|
12
|
export interface LazyDependencyOptions<T> extends DependencyOptions<T> {
|
|
|
13
|
lazy: true;
|
|
13
|
lazy: true;
|
|
|
14
|
}
|
|
14
|
}
|
|
|
15
|
|
|
15
|
|
|
|
16
|
export type ExtractService<K, S> = K extends keyof S ? S[K] : K;
|
|
16
|
export type ExtractService<K, S> = K extends keyof S ? S[K] : K;
|
|
|
17
|
|
|
17
|
|
|
|
18
|
export type ExtractDependency<D, S> = D extends { $dependency: infer K } ?
|
|
18
|
export type ExtractDependency<D, S> = D extends { $dependency: infer K } ?
|
|
|
19
|
D extends { lazy: true } ? () => ExtractService<K, S> : ExtractService<K, S> :
|
|
19
|
D extends { lazy: true } ? () => ExtractService<K, S> : ExtractService<K, S> :
|
|
|
20
|
D extends { $type: new (...args: any[]) => infer I } ? I :
|
|
20
|
D extends { $type: new (...args: any[]) => infer I } ? I :
|
|
|
21
|
D extends { $factory: (...args: any[]) => infer R } ? R :
|
|
21
|
D extends { $factory: (...args: any[]) => infer R } ? R :
|
|
|
22
|
WalkDependencies<D, S>;
|
|
22
|
WalkDependencies<D, S>;
|
|
|
23
|
|
|
23
|
|
|
|
24
|
export type WalkDependencies<D, S> = D extends primitive ? D :
|
|
24
|
export type WalkDependencies<D, S> = D extends primitive ? D :
|
|
|
25
|
{ [K in keyof D]: ExtractDependency<D[K], S> };
|
|
25
|
{ [K in keyof D]: ExtractDependency<D[K], S> };
|
|
|
26
|
|
|
26
|
|
|
|
27
|
export type ServiceModule<T, S extends object, M extends keyof any = "service"> = {
|
|
27
|
export type ServiceModule<T, S extends object, M extends keyof any = "service"> = {
|
|
|
28
|
[m in M]: AnnotaionBuilder<T, S>;
|
|
28
|
[m in M]: AnnotaionBuilder<T, S>;
|
|
|
29
|
};
|
|
29
|
};
|
|
|
30
|
|
|
30
|
|
|
|
31
|
export interface ServiceBuilder<T, S extends object> {
|
|
31
|
export interface ServiceRecordBuilder<T, S extends object> {
|
|
|
32
|
type<P extends any[], C extends new (...args: ExtractDependency<P, S>) => T>(
|
|
32
|
type<P extends any[], C extends new (...args: ExtractDependency<P, S>) => T>(
|
|
|
33
|
target: C, ...params: P): ConstructorBuilder<C, S>;
|
|
33
|
target: C, ...params: P): ConstructorBuilder<C, S>;
|
|
|
34
|
factory<P extends any[], F extends (...args: ExtractDependency<P, S>) => T>(
|
|
34
|
factory<P extends any[], F extends (...args: ExtractDependency<P, S>) => T>(
|
|
|
35
|
target: F, ...params: P): FactoryBuilder<F, S>;
|
|
35
|
target: F, ...params: P): FactoryBuilder<F, S>;
|
|
|
36
|
wired<M extends keyof any>(module: PromiseOrValue<ServiceModule<T, S, M>>, m: M): RegistrationBuilder<T, S>;
|
|
36
|
wired<M extends keyof any>(module: ServiceModule<T, S, M>, m: M): RegistrationBuilder<T, S>;
|
|
|
37
|
wired(module: PromiseOrValue<ServiceModule<T, S>>): RegistrationBuilder<T, S>;
|
|
37
|
wired(module: ServiceModule<T, S>): RegistrationBuilder<T, S>;
|
|
|
|
|
|
38
|
}
|
|
|
|
|
|
39
|
|
|
|
|
|
|
40
|
export interface RegistrationVisitor<S extends object> {
|
|
|
|
|
|
41
|
visitDependency(): void;
|
|
|
|
|
|
42
|
|
|
|
|
|
|
43
|
visitObject(): void;
|
|
|
|
|
|
44
|
|
|
|
|
|
|
45
|
visitTypeRegistration(): void;
|
|
|
|
|
|
46
|
|
|
|
|
|
|
47
|
visitFactoryRegistration(): void;
|
|
|
|
|
|
48
|
|
|
|
|
|
|
49
|
visitBuilder<T>(builder: (t: ServiceRecordBuilder<T, S>) => void): void;
|
|
|
|
|
|
50
|
|
|
|
38
|
}
|
|
51
|
}
|
|
|
39
|
|
|
52
|
|
|
|
40
|
export interface RegistrationBuilder<T, S extends object> {
|
|
53
|
export interface RegistrationBuilder<T, S extends object> {
|
|
|
41
|
override<K extends keyof S>(name: K, builder: S[K] | ((t: ServiceBuilder<S[K], S>) => any)): this;
|
|
54
|
override<K extends keyof S>(name: K, builder: S[K], raw: true): this;
|
|
|
|
|
|
55
|
override<K extends keyof S>(name: K, builder: (t: ServiceRecordBuilder<S[K], S>) => void): this;
|
|
|
|
|
|
56
|
override<K extends keyof S, V>(name: S[K] extends ExtractDependency<V, S> ? K : never, value: V): this;
|
|
|
|
|
|
57
|
|
|
|
42
|
activate(activation: ActivationType): this;
|
|
58
|
activate(activation: ActivationType): this;
|
|
|
43
|
inject<M extends keyof T, P extends any[]>(member: T[M] extends (...params: ExtractDependency<P, S>) => any ? M : never, ...params: P): this;
|
|
59
|
inject<M extends keyof T, P extends any[]>(member: T[M] extends (...params: ExtractDependency<P, S>) => any ? M : never, ...params: P): this;
|
|
|
|
|
|
60
|
|
|
|
|
|
|
61
|
visit(visitor: RegistrationVisitor<S>): void;
|
|
|
44
|
}
|
|
62
|
}
|
|
|
45
|
|
|
63
|
|
|
|
46
|
export interface ConstructorBuilder<C extends new (...args: any[]) => any, S extends object> extends RegistrationBuilder<InstanceType<C>, S> {
|
|
64
|
export interface ConstructorBuilder<C extends new (...args: any[]) => any, S extends object> extends RegistrationBuilder<InstanceType<C>, S> {
|
|
|
47
|
$type: C;
|
|
65
|
$type: C;
|
|
|
48
|
}
|
|
66
|
}
|
|
|
49
|
|
|
67
|
|
|
|
50
|
export interface FactoryBuilder<F extends (...args: any[]) => any, S extends object> extends RegistrationBuilder<ReturnType<F>, S> {
|
|
68
|
export interface FactoryBuilder<F extends (...args: any[]) => any, S extends object> extends RegistrationBuilder<ReturnType<F>, S> {
|
|
|
51
|
$factory: F;
|
|
69
|
$factory: F;
|
|
|
52
|
}
|
|
70
|
}
|
|
|
53
|
|
|
71
|
|
|
|
54
|
export interface ConfigBuilder<S extends object, Y extends keyof S = keyof S> {
|
|
72
|
export interface ConfigBuilder<S extends object, Y extends keyof S = keyof S> {
|
|
|
55
|
register<K extends Y>(name: K, builder: S[K] | ((t: ServiceBuilder<S[K], S>) => any)): ConfigBuilder<S, Exclude<Y, K>>;
|
|
73
|
register<K extends Y>(name: K, builder: (t: ServiceRecordBuilder<S[K], S>) => void | Promise<void>): ConfigBuilder<S, Exclude<Y, K>>;
|
|
|
|
|
|
74
|
register<K extends Y, V>(name: S[K] extends ExtractDependency<V, S> ? K : never, value: V): ConfigBuilder<S, Exclude<Y, K>>;
|
|
|
|
|
|
75
|
register<K extends Y>(name: K, value: S[K], raw: true): ConfigBuilder<S, Exclude<Y, K>>;
|
|
|
|
|
|
76
|
|
|
|
|
|
|
77
|
apply(container: Container<S>): Promise<void>;
|
|
|
56
|
}
|
|
78
|
}
|
|
|
57
|
|
|
79
|
|
|
|
58
|
interface ServicesDeclaration<S extends object> {
|
|
80
|
interface ServicesDeclaration<S extends object> {
|
|
|
59
|
build<T>(this: void): ServiceBuilder<T, S>;
|
|
81
|
build<T>(this: void): ServiceRecordBuilder<T, S>;
|
|
|
60
|
annotate<T>(this: void): AnnotaionBuilder<T, S>;
|
|
82
|
annotate<T>(this: void): AnnotaionBuilder<T, S>;
|
|
|
61
|
|
|
83
|
|
|
|
62
|
dependency<K extends keyof S>(this: void, name: K, opts: LazyDependencyOptions<S[K]>): LazyDependencyRegistration<S, K>;
|
|
84
|
dependency<K extends keyof S>(this: void, name: K, opts: LazyDependencyOptions<S[K]>): LazyDependencyRegistration<S, K>;
|
|
|
63
|
dependency<K extends keyof S>(this: void, name: K, opts?: DependencyOptions<S[K]>): DependencyRegistration<S, K>;
|
|
85
|
dependency<K extends keyof S>(this: void, name: K, opts?: DependencyOptions<S[K]>): DependencyRegistration<S, K>;
|
|
|
64
|
|
|
86
|
|
|
|
65
|
configure(): ConfigBuilder<S>;
|
|
87
|
configure(): ConfigBuilder<S>;
|
|
|
66
|
}
|
|
88
|
}
|
|
|
67
|
|
|
89
|
|
|
|
68
|
export declare function declare<S extends object>(): ServicesDeclaration<S>;
|
|
90
|
export declare function declare<S extends object>(): ServicesDeclaration<S>;
|