/** * @author Martin Karkowski * @email m.karkowski@zema.de * @create date 2020-10-12 17:25:30 * @modify date 2020-10-12 17:55:40 * @desc [description] */ import { callOptions, externalEvent } from "./Interface.CommunicationInterface"; import { INopeObservable, pipe } from "./Interface.nopeObservebale"; /** * A Dispatcher to perform a function on a Remote * Dispatcher. Therefore a Task is created and forwarded * to the remote. * * @export * @class INopeDispatcher */ export interface INopeDispatcher { readonly id: string; methodInterfaceWithOptions: { [index: string]: (optins: callOptions, ...args) => Promise } methodInterface: { [index: string]: (...args) => Promise } /** * Function to test if a specific Service exists. * * @param {string} id The Id of the Serivce * @return {boolean} The result of the Test. True if either local or remotly a service is known. * @memberof INopeDispatcher */ serviceExists(id: string): boolean; subscriptionExists(topic: string): boolean; /** * Function to register a Function in the Dispatcher * * @param {(...args) => Promise} func The function which should be called if a request is mapped to the Function. * @param {{ * // Flag to enable unregistering the function after calling. * deleteAfterCalling?: boolean, * // Instead of generating a uuid an id could be provided * id?: string; * }} [options={}] Options to enhance the registered ID and enabling unregistering the Element after calling it. * @return {*} {(...args) => Promise} The registered Function * @memberof INopeDispatcher */ registerFunction(func: (...args) => Promise, options?: { /** Flag to enable unregistering the function after calling. */ deleteAfterCalling?: boolean, /** Instead of generating a uuid an id could be provided */ id?: string; /** Flag to enable / disable sending to registery */ preventSendingToRegistery?: boolean; }): (...args) => Promise /** * Function to unregister a Function from the Dispatcher * @param {(((...args) => void) | string | number)} func The Function to unregister * @return {*} {boolean} Flag, whether the element was removed (only if found) or not. * @memberof INopeDispatcher */ unregistFunction(func: ((...args) => void) | string, options?: { /** Flag to enable / disable sending to registery */ preventSendingToRegistery?: boolean; }): boolean /** * Function to register a Oberservable into the element. * * @template T * @template K * @template S * @template G * @param {nopeObservable} observable * @param {({ * mode: 'subscribe' | 'publish' | Array<'subscribe' | 'publish'>, * topic: string | { * subscribe?: string, * publish?: string, * }, * pipe?:{ * pipe?: pipe, * scope?: { [index: string]: any } * }, * preventSendingToRegistery?: boolean * })} options * @return {*} {INopeObservable} * @memberof INopeDispatcher */ registerObservable(observable: INopeObservable, options: { mode: 'subscribe' | 'publish' | Array<'subscribe' | 'publish'>, topic: string | { subscribe?: string, publish?: string, }, pipe?: { pipe?: pipe, scope?: { [index: string]: any } }, preventSendingToRegistery?: boolean }): INopeObservable; /** * Function to unregister a Function from the Dispatcher * @param {(((...args) => void) | string | number)} func The Function to unregister * @return {*} {boolean} Flag, whether the element was removed (only if found) or not. * @memberof INopeDispatcher */ unregistObservable(observable: INopeObservable, options?: { /** Flag to enable / disable sending to registery */ preventSendingToRegistery?: boolean; }): boolean /** * Function which is used to perform a call on the remote. * * @template T * @param {string} functionName The Name / ID of the Function * @param {any[]} params The provided Parameters. * @param {({ * deletableCallbacks: Array; * })} [options={ * deletableCallbacks: [], * paramsHasNoCallback: false, * preventErrorTest: false * }] You could additiona Optionf for the callback. * @return {*} {Promise} The result of the Operation * @memberof INopeDispatcher */ performCall(functionName: string, params: any[], options?: Partial): Promise /** * Function to clear all pending tasks * * @memberof INopeDispatcher */ clearTasks(): void /** * Function to unregister all Functions of the Dispatcher. * * @memberof INopeDispatcher */ unregisterAll(): void /** * Function to reset the Dispatcher. * * @memberof INopeDispatcher */ reset(): void }