UNPKG

@egodigital/nef

Version:

Managed Extensibility Framework like library written for Node.js

212 lines (211 loc) 5.8 kB
/** * This file is part of the @egodigital/nef distribution. * Copyright (c) e.GO Digital GmbH, Aachen, Germany (https://www.e-go-digital.com/) * * @egodigital/nef is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, version 3. * * @egodigital/nef is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ /// <reference types="node" /> /** * A composable part catalog. */ export interface ComposablePartCatalog { /** * Returns the list of classes. * * @return {Promise<any[]>} The promise with the loaded classes. */ getClasses(): Promise<any[]>; /** * Returns the list of classes. * * @return {any[]} The loaded classes. */ getClassesSync(): any[]; } /** * A disposable object. */ export interface Disposable { /** * Frees all resources of that object. */ dispose(): any; } /** * An export defintion. */ export interface ExportDefintion { /** * The export key. */ key: ServiceKey; } /** * An import definition. */ export interface ImportDefintion { /** * The property. */ property: PropertyKey; /** * The key of export definition. */ service: ServiceKey; } /** * A key for an exported service. */ export declare type ServiceKey = any; /** * Marks a class as exportable. * * @param {ServiceKey} [key] The custom service key. Default: class * * @return {any} The decorator function. */ export declare function Export(key?: ServiceKey): ClassDecorator; /** * Marks a property to load an exported service. * * @param {ServiceKey} service The service key. * * @return {any} The decorator function. */ export declare function Import(service: ServiceKey): any; /** * Marks a property to load an exported services. * * @param {ServiceKey} service The service key. * * @return {any} The decorator function. */ export declare function ImportMany(service: ServiceKey): any; /** * A container, that composes instances. */ export declare class CompositionContainer implements Disposable { private readonly _CATALOGS; private _instances; /** * Adds one or more processes. If you process is defined, the current one is taken. * * @param {NodeJS.Process[]} [processes] One or more processes to add. * * @return {this} */ addApplications(...processes: NodeJS.Process[]): this; /** * Adds one or more catalogs. * * @param {ComposablePartCatalog[]} [catalogs] One or more catalogs. * * @return {this} */ addCatalogs(...catalogs: ComposablePartCatalog[]): this; /** * Adds one or more class (catalogs). * * @param {any[]} [classes] The classes to add. * * @return {this} */ addClasses(...classes: any[]): this; /** * Adds one or more directories. * * @param {string[]} [dirs] The directories (paths) to add. * * @return {this} */ addDirectories(...dirs: string[]): this; /** * Adds one or more files. * * @param {string[]} [files] The files (paths) to add. * * @return {this} */ addFiles(...files: string[]): this; /** * Adds one or more module (catalogs). * * @param {any[]} [mods] The modules to add. * * @return {this} */ addModules(...mods: any[]): this; /** * Composes all @Export() instances. * * @param {any[]} [objs] One or more object, where to write the instances to. */ compose(...objs: any[]): Promise<void>; /** * Composes all @Export() instances. * * @param {any[]} [objs] One or more object, where to write the instances to. * * @return {this} */ composeSync(...objs: any[]): this; /** @inheritdoc */ dispose(): void; private fillInstances; private fillMatchingExports; /** * Returns all services by key. * * @param {ServiceKey} service The service key. * * @return {Promise<TService[]>} The promise with the services. */ getAllServices<TService = any>(service: ServiceKey): Promise<TService[]>; /** * Returns all services by key. * * @param {ServiceKey} service The service key. * * @return {TService[]} The services. */ getAllServicesSync<TService = any>(service: ServiceKey): TService[]; private getAllServicesInner; private getGlobalExportInstances; private getGlobalExportInstancesSync; /** * Returns a single service by key. * * @param {ServiceKey} service The service key. * * @return {Promise<TService>} The promise with the single service. */ getService<TService = any>(service: ServiceKey): Promise<TService>; /** * Returns a single service by key. * * @param {ServiceKey} service The service key. * * @return {TService} The single service. */ getServiceSync<TService = any>(service: ServiceKey): TService; private getServiceInner; private handleDecoratorsOfObjectList; private handleImportManys; private handleImports; } export * from './catalogs/ApplicationCatalog'; export * from './catalogs/ClassCatalog'; export * from './catalogs/DirectoryCatalog'; export * from './catalogs/FileCatalog'; export * from './catalogs/FilteredCatalog'; export * from './catalogs/ModuleCatalog';