|
|
@@
-1,21
+1,41
|
|
|
1
|
import { DescriptorBuilder } from "./DescriptorBuilder";
|
|
1
|
import { DescriptorBuilder } from "./DescriptorBuilder";
|
|
|
2
|
import { ConfigurableKeys, ContainerServices, ConfigurableServices, RegistrationBuildersMap, RequiredKeys } from "./interfaces";
|
|
2
|
import { ConfigurableKeys, ContainerServices, ConfigurableServices, RegistrationBuildersMap, ExtractRequired } from "./interfaces";
|
|
|
3
|
import { ServiceContainer } from "./interfaces";
|
|
3
|
import { ServiceContainer } from "./interfaces";
|
|
|
4
|
import { argumentNotNull, each, isKey } from "./traits";
|
|
4
|
import { argumentNotNull, each, isKey } from "./traits";
|
|
|
5
|
|
|
5
|
|
|
|
6
|
export class FluentConfiguration<S extends object, Y extends ConfigurableKeys<S> = ConfigurableKeys<S>> {
|
|
6
|
export class FluentConfiguration<S extends object, Y extends ConfigurableKeys<S> = ConfigurableKeys<S>> {
|
|
|
7
|
|
|
7
|
|
|
|
8
|
_builders: Partial<RegistrationBuildersMap<S>> = {};
|
|
8
|
private _builders: Partial<RegistrationBuildersMap<S>> = {};
|
|
|
9
|
|
|
9
|
|
|
|
|
|
|
10
|
/** Adds a declaration of the services to the current config.
|
|
|
|
|
|
11
|
*
|
|
|
|
|
|
12
|
* @template D The map of the services
|
|
|
|
|
|
13
|
* @returns self
|
|
|
|
|
|
14
|
*/
|
|
|
10
|
declare<D extends Partial<Pick<S, keyof D & keyof S>>>(): FluentConfiguration<S & D, Y | ConfigurableKeys<D>> {
|
|
15
|
declare<D extends Partial<Pick<S, keyof D & keyof S>>>(): FluentConfiguration<S & D, Y | ConfigurableKeys<D>> {
|
|
|
11
|
return this as FluentConfiguration<S & D, Y | ConfigurableKeys<D>>;
|
|
16
|
return this as FluentConfiguration<S & D, Y | ConfigurableKeys<D>>;
|
|
|
12
|
}
|
|
17
|
}
|
|
|
13
|
|
|
18
|
|
|
|
|
|
|
19
|
/** Adds compile-time information about the already provided services
|
|
|
|
|
|
20
|
*
|
|
|
|
|
|
21
|
* @template P The map of the provided services
|
|
|
|
|
|
22
|
* @returns self
|
|
|
|
|
|
23
|
*/
|
|
|
14
|
provided<P extends Pick<S, keyof P & keyof S>>(): FluentConfiguration<S & P, Exclude<Y, keyof P>> {
|
|
24
|
provided<P extends Pick<S, keyof P & keyof S>>(): FluentConfiguration<S & P, Exclude<Y, keyof P>> {
|
|
|
15
|
return this as FluentConfiguration<S & P, Exclude<Y, keyof P>>;
|
|
25
|
return this as FluentConfiguration<S & P, Exclude<Y, keyof P>>;
|
|
|
16
|
}
|
|
26
|
}
|
|
|
17
|
|
|
27
|
|
|
|
|
|
|
28
|
/** Register the service.
|
|
|
|
|
|
29
|
*
|
|
|
|
|
|
30
|
* @param name The name of the service
|
|
|
|
|
|
31
|
* @param builder The service builder
|
|
|
|
|
|
32
|
* @returns self
|
|
|
|
|
|
33
|
*/
|
|
|
18
|
register<K extends Y>(name: K, builder: RegistrationBuildersMap<S>[K]): FluentConfiguration<S, Exclude<Y, K>>;
|
|
34
|
register<K extends Y>(name: K, builder: RegistrationBuildersMap<S>[K]): FluentConfiguration<S, Exclude<Y, K>>;
|
|
|
|
|
|
35
|
/** Registers the collection of services
|
|
|
|
|
|
36
|
* @param config The collection of services to register.
|
|
|
|
|
|
37
|
* @returns self
|
|
|
|
|
|
38
|
*/
|
|
|
19
|
register<K extends Y>(config: RegistrationBuildersMap<S, K>): FluentConfiguration<S, Exclude<Y, K>>;
|
|
39
|
register<K extends Y>(config: RegistrationBuildersMap<S, K>): FluentConfiguration<S, Exclude<Y, K>>;
|
|
|
20
|
register<K extends Y>(nameOrConfig: K | RegistrationBuildersMap<S, K>, builder?: RegistrationBuildersMap<S>[K]) {
|
|
40
|
register<K extends Y>(nameOrConfig: K | RegistrationBuildersMap<S, K>, builder?: RegistrationBuildersMap<S>[K]) {
|
|
|
21
|
if (isKey(nameOrConfig)) {
|
|
41
|
if (isKey(nameOrConfig)) {
|
|
|
@@
-28,9
+48,16
export class FluentConfiguration<S exten
|
|
|
28
|
return this as FluentConfiguration<S, Exclude<Y, K>>;
|
|
48
|
return this as FluentConfiguration<S, Exclude<Y, K>>;
|
|
|
29
|
}
|
|
49
|
}
|
|
|
30
|
|
|
50
|
|
|
|
31
|
done(missing: RequiredKeys<S, Y> extends never ? void : RequiredKeys<S, Y>) {
|
|
51
|
/**
|
|
|
32
|
if (missing !== undefined)
|
|
52
|
* This method is used to enable a compile time check of the configuration.
|
|
|
33
|
throw new Error("The configuration isn't complete");
|
|
53
|
* If there are not configured services in the configuration the compiler
|
|
|
|
|
|
54
|
* will trigger the error.
|
|
|
|
|
|
55
|
*
|
|
|
|
|
|
56
|
* @param missing Empty object literal should always be specified.
|
|
|
|
|
|
57
|
* @returns self
|
|
|
|
|
|
58
|
*/
|
|
|
|
|
|
59
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
|
|
60
|
done<M extends ExtractRequired<S,Y>>(missing: M) {
|
|
|
34
|
return this;
|
|
61
|
return this;
|
|
|
35
|
}
|
|
62
|
}
|
|
|
36
|
|
|
63
|
|