42 lines
881 B
TypeScript
42 lines
881 B
TypeScript
/**
|
|
* @author Martin Karkowski
|
|
* @email m.karkowski@zema.de
|
|
* @desc [description]
|
|
*/
|
|
|
|
import {
|
|
getCentralDecoratedContainer,
|
|
IexportFunctionAsNopeServiceParameters,
|
|
} from "./container";
|
|
|
|
const CONTAINER = getCentralDecoratedContainer();
|
|
|
|
/**
|
|
* Defintion of a Functon.
|
|
*/
|
|
export type callable<T> = {
|
|
(...args): T;
|
|
};
|
|
|
|
/**
|
|
* Decorator, that will export the Function to a Dispatcher
|
|
* @param func The Function
|
|
* @param options The Options.
|
|
*/
|
|
export function exportFunctionAsNopeService<T>(
|
|
func: T,
|
|
options: IexportFunctionAsNopeServiceParameters
|
|
) {
|
|
// Only add the element if it doesnt exists.
|
|
if (!CONTAINER.methods.has(options.id)) {
|
|
CONTAINER.methods.set(options.id, {
|
|
callback: async (...args) => {
|
|
return await (func as any)(...args);
|
|
},
|
|
options,
|
|
uri: options.id || (func as any).name,
|
|
});
|
|
}
|
|
return func;
|
|
}
|