import { InterfaceSpec, ReferenceSpec } from "./InterfaceSpec"; import { PackageRepr } from "./PackageRepr"; import { ServiceLookupResult, ServicesLookupResult } from "./ServiceLookup"; export type DynamicLookupResult = ServiceLookupResult | UndeclaredDependency; /** * Returned when a dependency is not declared in the package's metadata. */ export interface UndeclaredDependency { type: "undeclared"; } /** * Returned when a package is not found in the application's metadata. */ export interface UnknownPackage { type: "unknown-package"; } export declare class ServiceLayer { private allServices; private requiredServices; private serviceLookup; private serviceDependencies; private declaredDependencies; private state; /** * Constructs a new service layer instance. * Requires the application's set of packages (from which services are taken) * and an optional set of forced references (interfaces whose implementing services will be started unconditionally). * * In its current form, the service layer will start only forced references and references needed by the UI (and their dependencies). */ constructor(packages: readonly PackageRepr[], forcedReferences?: ReferenceSpec[]); destroy(): void; start(): void; /** * Returns a service implementing the given interface. * Checks that the given package actually declared a dependency on that interface * to enforce coding guidelines. * * @param packageName the name of the package requesting the import * @param spec the interface specifier * @param options advanced options to customize lookup * @throws if the service layer is not in 'started' state or if no service implements the interface. */ getService(packageName: string, spec: InterfaceSpec, options?: { ignoreDeclarationCheck?: boolean; }): ServiceLookupResult | UndeclaredDependency | UnknownPackage; /** * Returns all services implementing the given interface. * Requires that the dependency on all implementations has been declared in the package. * * @param packageName the name of the package requesting the import * @param interfaceName the interface name * * @throws if the service layer is not in 'started'. */ getServices(packageName: string, interfaceName: string): ServicesLookupResult | UndeclaredDependency | UnknownPackage; /** * Initializes the given service and its dependencies. * Dependencies are initialized before the service that requires them. */ private createService; /** * Destroys the given service and its dependencies. * The dependencies are destroyed after the service. */ private destroyService; /** Undefined -> everything is okay */ private checkDependency; private getReference; private getServiceDeps; }