nope/lib/module/Interface.nopeDispatcher.ts

156 lines
5.2 KiB
TypeScript
Raw Normal View History

2020-10-12 16:13:10 +00:00
/**
* @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]: <T>(optins: callOptions, ...args) => Promise<T> }
methodInterface: { [index: string]: <T>(...args) => Promise<T> }
/**
* 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<any>} 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<any>} The registered Function
* @memberof INopeDispatcher
*/
registerFunction(func: (...args) => Promise<any>, 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<any>
/**
* 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<T,S,G>} observable
* @param {({
* mode: 'subscribe' | 'publish' | Array<'subscribe' | 'publish'>,
* topic: string | {
* subscribe?: string,
* publish?: string,
* },
* pipe?:{
* pipe?: pipe<externalEvent,K>,
* scope?: { [index: string]: any }
* },
* preventSendingToRegistery?: boolean
* })} options
* @return {*} {INopeObservable<T, S, G>}
* @memberof INopeDispatcher
*/
registerObservable<T, K, S = T, G = T>(observable: INopeObservable<T, S, G>, options: {
mode: 'subscribe' | 'publish' | Array<'subscribe' | 'publish'>,
topic: string | {
subscribe?: string,
publish?: string,
},
pipe?: {
pipe?: pipe<externalEvent, K>,
scope?: { [index: string]: any }
},
preventSendingToRegistery?: boolean
}): INopeObservable<T, S, G>;
/**
* 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<any>, 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<number>;
* })} [options={
* deletableCallbacks: [],
* paramsHasNoCallback: false,
* preventErrorTest: false
* }] You could additiona Optionf for the callback.
* @return {*} {Promise<T>} The result of the Operation
* @memberof INopeDispatcher
*/
performCall<T>(functionName: string, params: any[], options?: Partial<callOptions>): Promise<T>
/**
* 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
}