/** * @author Martin Karkowski * @email m.karkowski@zema.de * @create date 2020-11-06 08:52:55 * @modify date 2020-12-02 08:56:37 * @desc [description] */ import { getSingleton } from "../helpers/singletonMethod"; import { IFunctionOptions } from "../types/nope/nopeModule.interface"; export type IExportFunctionToDispatcherParameters = IFunctionOptions; const container = getSingleton("nopeBackendDispatcher.container", () => { return new Map< string, { uri: string; callback: (...args) => Promise; options: IExportFunctionToDispatcherParameters; } >(); }); /** * Defintion of a Functon. */ export type callable = { (...args): T; }; /** * Decorator, that will export the Function to a Dispatcher * @param func The Function * @param options The Options. */ export function exportFunctionToDispatcher( func: T, options: IExportFunctionToDispatcherParameters ) { // Only add the element if it doesnt exists. if (!container.instance.has(options.id)) { container.instance.set(options.id, { callback: async (...args) => await (func as any)(...args), options, uri: options.id || (func as any).name }); } return func; }