2020-11-06 13:17:13 +00:00
|
|
|
/**
|
|
|
|
* @author Martin Karkowski
|
|
|
|
* @email m.karkowski@zema.de
|
|
|
|
* @desc [description]
|
|
|
|
*/
|
|
|
|
|
2022-07-02 09:30:10 +00:00
|
|
|
import {
|
|
|
|
getCentralDecoratedContainer,
|
|
|
|
IexportFunctionAsNopeServiceParameters,
|
|
|
|
} from "./container";
|
2020-11-06 13:17:13 +00:00
|
|
|
|
2022-07-02 09:30:10 +00:00
|
|
|
const CONTAINER = getCentralDecoratedContainer();
|
2020-11-06 13:17:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Defintion of a Functon.
|
|
|
|
*/
|
|
|
|
export type callable<T> = {
|
2020-12-04 18:10:33 +00:00
|
|
|
(...args): T;
|
|
|
|
};
|
2020-11-06 13:17:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Decorator, that will export the Function to a Dispatcher
|
|
|
|
* @param func The Function
|
|
|
|
* @param options The Options.
|
|
|
|
*/
|
2022-01-26 12:03:03 +00:00
|
|
|
export function exportFunctionAsNopeService<T>(
|
2020-12-04 18:10:33 +00:00
|
|
|
func: T,
|
2022-01-26 12:03:03 +00:00
|
|
|
options: IexportFunctionAsNopeServiceParameters
|
2020-12-04 18:10:33 +00:00
|
|
|
) {
|
2020-11-12 16:07:05 +00:00
|
|
|
// Only add the element if it doesnt exists.
|
2022-07-02 09:30:10 +00:00
|
|
|
if (!CONTAINER.methods.has(options.id)) {
|
|
|
|
CONTAINER.methods.set(options.id, {
|
2020-12-04 18:10:33 +00:00
|
|
|
callback: async (...args) => await (func as any)(...args),
|
2020-11-12 16:07:05 +00:00
|
|
|
options,
|
2021-12-04 07:25:26 +00:00
|
|
|
uri: options.id || (func as any).name,
|
2020-11-12 16:07:05 +00:00
|
|
|
});
|
|
|
|
}
|
2020-11-06 13:17:13 +00:00
|
|
|
return func;
|
|
|
|
}
|