import { ConfigurationMap, ConfigurationMapConstraint, ContainerServices, ContainerServicesConstraint, ExtractRequiredKeys, IContainerBuilder } from "./interfaces"; import { argumentNotNull, each, isKey } from "./traits"; type ContainerExtensionConstraint = ContainerServicesConstraint>; export class FluentConfiguration, Y extends keyof S = keyof S> { private _builders: Partial, keyof S, keyof S>> = {}; /** Adds a declaration of the services to the current config. * * @template D The map of the services * @returns self */ declare>(): FluentConfiguration { return this as unknown as FluentConfiguration; } /** Adds compile-time information about the already provided services * * @template P The map of the provided services * @returns self */ provided

>(): FluentConfiguration> { return this as unknown as FluentConfiguration>; } /** Register the service. * * @param name The name of the service * @param builder The service builder * @returns self */ register(name: K, builder: ConfigurationMap,Y, keyof S>[K]): FluentConfiguration>; /** Registers the collection of services * @param config The collection of services to register. * @returns self */ register, Y, keyof X>>(config: X): FluentConfiguration>; register(nameOrConfig: K | ConfigurationMap, K, keyof S>, builder?: ConfigurationMap, Y, keyof S>[K]) { if (isKey(nameOrConfig)) { argumentNotNull(builder, "builder"); this._builders[nameOrConfig] = builder; } else { each(nameOrConfig, (v, k) => this.register(k, v)); } return this; // as FluentConfiguration>; } /** * This method is used to enable a compile time check of the configuration. * If there are not configured services in the configuration the compiler * will trigger the error. * * @param missing Empty object literal should always be specified. * @returns self */ // eslint-disable-next-line @typescript-eslint/no-unused-vars done(...args: ExtractRequiredKeys extends never ? [] : [services: {[ k in ExtractRequiredKeys]: "required"}]) { //done() { return this; } configure, keyof S>>(builder: C) { each(this._builders, (v, k) => { v(builder.createServiceBuilder(k)); }); return builder.build(); } }