nope/lib/types/nopeDispatcher.interface.ts
2020-10-13 15:18:25 +02:00

173 lines
5.9 KiB
TypeScript

/**
* @author Martin Karkowski
* @email m.karkowski@zema.de
* @create date 2020-10-12 18:31:11
* @modify date 2020-10-13 12:40:54
* @desc [description]
*/
import { ICallOptions, IInstanceCreation } from "./communication.interface";
import { IFunctionOptions, INopeModule, INopeModuleDescription, IPropertyOptions } from "./nopeModule.interface";
import { INopeObservable } from "./nopeObservable.interface";
export type IGenerateInstanceCallback<I extends INopeModule> = () => Promise<I>;
export type IGenerateRemoteInstanceCallback<I extends INopeModule> = (dispatcher: INopeDispatcher, description: INopeModuleDescription, ...args) => Promise<I>;
export type IGenerateRemoteInstanceForOtherDispatcherCallback<I extends INopeModule> = (dispatcher: INopeDispatcher, identifier: string, ...args) => Promise<I>;
/**
* Interface for an Dispatcher.
*
* @export
* @interface INopeDispatcher
*/
export interface INopeDispatcher {
/**
* ID of the Dispatcher
*
* @type {string}
* @memberof INopeDispatcher
*/
readonly id: string;
methodInterfaceWithOptions: { [index: string]: <T>(optins: ICallOptions, ...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;
/**
* Element to test, if a subscription for a specific topic exists or not.
*
* @param {string} topic
* @return {*} {boolean}
* @memberof INopeDispatcher
*/
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 {IFunctionOptions} [options] Options to enhance the registered ID and enabling unregistering the Element after calling it.
* @return {*} {(...args) => Promise<any>}
* @memberof INopeDispatcher
*/
registerFunction(func: (...args) => Promise<any>, options?: IFunctionOptions): (...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
*/
unregisterFunction(func: ((...args) => void) | string, options: {
/** Flag to enable / disable sending to registery */
preventSendingToRegistery?: boolean;
}): boolean;
/**
* Function, used to register an observable in the Dispather.
*
* @template T Type of the Observable
* @template K Transformator (used if a Pipe is provided)
* @template S Setter of the Observable
* @template G Getter of the Observable
* @param {INopeObservable<T, S, G>} observable The Observable to register
* @param {IPropertyOptions} options The Options, used to register the Observable.
* @return {*} {INopeObservable<T, S, G>}
* @memberof INopeDispatcher
*/
registerObservable<T, K, S = T, G = T>(observable: INopeObservable<T, S, G>, options: IPropertyOptions): INopeObservable<T, S, G>
/**
* Function to unregister an Observable
*
* @param {INopeObservable<any>} observable The name of the Observable or the observable itself
* @param options Options, to during unregistering
* @return {*} {boolean}
* @memberof INopeDispatcher
*/
unregisterObservable(observable: INopeObservable<any> | string, 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 {Partial<ICallOptions>} [options] You could add additional Options for the callback.
* @return {*} {Promise<T>} The result of the Operation
* @memberof INopeDispatcher
*/
performCall<T>(functionName: string, params: any[], options?: Partial<ICallOptions>): 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;
/**
* Function used to create an Instance
*
* @template I The Type of the Instance.
* @return {*} {Promise<I>} An Instance
* @memberof INopeDispatcher
*/
generateInstance<I extends INopeModule>(description: IInstanceCreation): Promise<I>;
/**
* Function, used to delete a remote instance.
*
* @template I The Type of the Instance.
* @param {I} instance The Instance itself.
* @return {*} {Promise<boolean>} Returns true if done.
* @memberof INopeDispatcher
*/
deleteInstance<I extends INopeModule>(instance: I): Promise<boolean>;
/**
* Function used, to register a Generator for Instances. This generator
* can be used by other dispatchers, to create an corresponding element.
*
* @template I
* @param {string} identifier The Identifier of the Object (Class or Type or ...)
* @param {IGenerateRemoteInstanceForOtherDispatcherCallback<I>} cb
* @memberof INopeDispatcher
*/
provideInstanceGeneratorForExternalDispatchers<I extends INopeModule>(identifier: string, cb: IGenerateRemoteInstanceForOtherDispatcherCallback<I>);
unprovideInstanceGeneratorForExternalDispatchers(identifier: string);
registerInternalInstanceGenerator<I extends INopeModule>(identifier: string, cb: IGenerateRemoteInstanceCallback<I>);
unregisterInternalInstanceGenerator(identifier: string);
}