UNPKG

nope-js-browser

Version:

NoPE Runtime for the Browser. For nodejs please use nope-js-node

1,014 lines (986 loc) 480 kB
// Generated by dts-bundle v0.7.3 // Dependencies for this module: // js-logger // events // rxjs // inversify // mqtt // gojs // plotly.js declare module 'nope-browser' { /** * @author Martin Karkowski * @email m.karkowski@zema.de */ import "reflect-metadata"; import * as communcation from "nope-browser/dist-browser/communication/index.browser"; import * as decorators from "nope-browser/dist-browser/decorators"; import * as dispatcher from "nope-browser/dist-browser/dispatcher/index"; import * as eventEmitter from "nope-browser/dist-browser/eventEmitter"; import * as helpers from "nope-browser/dist-browser/helpers/index.browser"; import * as loader from "nope-browser/dist-browser/loader/index.browser"; import * as logger from "nope-browser/dist-browser/logger/index.browser"; import * as modules from "nope-browser/dist-browser/module/index"; import * as observables from "nope-browser/dist-browser/observables/index"; import * as promise from "nope-browser/dist-browser/promise/index"; import * as pubSub from "nope-browser/dist-browser/pubSub"; import * as types from "nope-browser/dist-browser/types/index"; import * as ui from "nope-browser/dist-browser/ui/index.browser"; import * as plugins from "nope-browser/dist-browser/plugins/index"; export * from "nope-browser/dist-browser/communication/index.browser"; export * from "nope-browser/dist-browser/decorators"; export * from "nope-browser/dist-browser/dispatcher/index"; export * from "nope-browser/dist-browser/eventEmitter"; export * from "nope-browser/dist-browser/helpers/index.browser"; export * from "nope-browser/dist-browser/loader/index.browser"; export * from "nope-browser/dist-browser/logger/index.browser"; export * from "nope-browser/dist-browser/module/index"; export * from "nope-browser/dist-browser/observables/index"; export * from "nope-browser/dist-browser/promise/index"; export * from "nope-browser/dist-browser/pubSub"; export * from "nope-browser/dist-browser/types/index"; export * from "nope-browser/dist-browser/types/nope"; export * from "nope-browser/dist-browser/ui/index.browser"; export { communcation, decorators, dispatcher, eventEmitter, helpers, loader, logger, types, modules, observables, promise, pubSub, ui, plugins, }; } declare module 'nope-browser/dist-browser/communication/index.browser' { /** * @author Martin Karkowski * @email m.karkowski@zema.de * @create date 2021-08-04 15:30:10 * @modify date 2022-01-10 16:01:13 * @desc [description] */ import * as layers from "nope-browser/dist-browser/communication/layers/index.browser"; export { Bridge } from "nope-browser/dist-browser/communication/bridge"; export { getLayer, validLayers } from "nope-browser/dist-browser/communication/getLayer.browser"; export { layers }; } declare module 'nope-browser/dist-browser/decorators' { /** * @author Martin Karkowski * @email m.karkowski@zema.de */ export { getCentralDecoratedContainer, IexportAsNopeServiceParameters, } from "nope-browser/dist-browser/decorators/container"; export { exportAsNopeService } from "nope-browser/dist-browser/decorators/functionDecorators"; export { nopeEmitter, nopeMethod, nopeProperty } from "nope-browser/dist-browser/decorators/moduleDecorators"; } declare module 'nope-browser/dist-browser/dispatcher/index' { /** * @module dispatcher * @author Martin Karkowski * @email m.karkowski@zema.de * # NoPE - Dispatcher * *The NoPE-Dispatcher is designed as Layer between the different Modules / Dispatchers. They allow distributed computing or just a simple ***Service oriented Architecture*** (*SOA*). A dispatcher is used to link the modules, share data and events and provide a remote procedure call (rpc) interface. * *## Building Blocks of a Dispatcher: * *| element | description | *|-|-| *| `connectivityManager`: {@link connectivityManager} | establishes a connection to other dispatchers and manages the status of the remotely connected dispatchers. It checks their health and removes dead dispatchers. | *| `eventDistributor`: {@link PubSubSystem} | shares events accross the network (or internally). You can use this element to listen for specific events. The subscription to those events allows `mqtt`-patterns. Additionaly, you are allowed to emit event on specific topics, or pattern based topics | *| `dataDistributor`: {@link DataPubSubSystem} | shares data accross the network (or internally). In comperisson to events, data is persistent and is available all the time. You can use this sub-module to listen for specific data-changes (install data-hooks), pull specific data or push data. You can pull / push data using a `mqtt`-pattern based path. | *| `rpcManager`: {@link rpcManager} | Used to perform `remote procedure calls` (see [here](https://de.wikipedia.org/wiki/Remote_Procedure_Call)). The manager keeps track of the available services. You must use the sub-module to register/unregister (new) services. | *| `instanceManager`: {@link instanceManager} | Used to create/dispose (remote) instances. The manager keeps track of the available instances in the network, allows to create `wrappers` for those instances. You must use the sub-module to register/unregister (new) instances. To allow the system to provide a service for creating instances of as specific type, you can provide a generator and provide it as `service`. | * *## Create a Dispatcher * *To start exploring the capabilities of the dispatcher we will firstly create a dispatcher with the code below: * * *```javascript * // First lets install nope using npm * const nope = require("../dist-nodejs/index.nodejs") * * // Lets create our dispatcher * const dispatcher = nope.dispatcher.getDispatcher({ * // We will use the event layer (which just runs internally) * communicator: nope.getLayer("event"), * * // We will adapt the timings (normally, we send a hartbeat and check for dead dispatchers) * timings: { * * // Interval for the alive message given in [ms]. If "0" is provided, * // no alive messages are provided * sendAliveInterval: 0, * * // Interval, to check the other dispatcher for being slow, dead, etc.. * // should be lager then the "sendAliveInterval". The value is given in [ms] * // If "0" is provided, no alive messages are provided * checkInterval: 0 * * } * }); *``` * *## Settings for creating: * *The relevant Settings are described by the {@link INopeDispatcherOptions}. This options allows to define: * * the communication bridge. (use `getLayer` to receive a bridge with the specified layer) * * define a specific `id` * * provide a logger (otherwise the dispatcher wont log anything) * * define the timings for `heartbeats` and `checks` (see {@link INopeINopeConnectivityTimeOptions} for more details) * * a `defaultSelector` which is used as selector for a service provide * *## Playing with the dispatcher: * *To play with a dispatcher, you can use the `nope-js` repl tool. this tool creates a `dispatcher` and you are able to interact with the dispatcher in an interactive console. * * */ import * as baseServices from "nope-browser/dist-browser/dispatcher/baseServices"; import * as connectivityManager from "nope-browser/dist-browser/dispatcher/ConnectivityManager"; import * as instanceManager from "nope-browser/dist-browser/dispatcher/InstanceManager"; import * as rpcManager from "nope-browser/dist-browser/dispatcher/RpcManager"; export { generateSelector } from "nope-browser/dist-browser/dispatcher/RpcManager"; export { exportAsNopeService, IexportAsNopeServiceParameters, nopeEmitter, nopeMethod, nopeProperty, } from "nope-browser/dist-browser/decorators/index"; export * from "nope-browser/dist-browser/types/nope/nopeDispatcher.interface"; export { getDispatcher } from "nope-browser/dist-browser/dispatcher/getDispatcher"; export { baseServices, connectivityManager, instanceManager, rpcManager }; } declare module 'nope-browser/dist-browser/eventEmitter' { /** * @author Martin Karkowski * @email m.karkowski@zema.de * @create date 2021-08-27 20:29:38 * @modify date 2021-08-27 20:29:38 * @desc [description] */ export * from "nope-browser/dist-browser/types/nope/nopeEventEmitter.interface"; export { NopeEventEmitter } from "nope-browser/dist-browser/eventEmitter/nopeEventEmitter"; export { InjectableNopeEventEmitter } from "nope-browser/dist-browser/eventEmitter/nopeEventEmitter.injectable"; } declare module 'nope-browser/dist-browser/helpers/index.browser' { /** * @author Martin Karkowski * @email m.karkowski@zema.de */ import * as arrays from "nope-browser/dist-browser/helpers/arrayMethods"; import * as async from "nope-browser/dist-browser/helpers/async"; import * as descriptors from "nope-browser/dist-browser/helpers/descriptors"; import * as dispatcherPathes from "nope-browser/dist-browser/helpers/dispatcherPathes"; import * as functions from "nope-browser/dist-browser/helpers/functionMethods"; import * as subject from "nope-browser/dist-browser/helpers/getSubject"; import * as hashs from "nope-browser/dist-browser/helpers/hash"; import * as ids from "nope-browser/dist-browser/helpers/idMethods"; import * as json from "nope-browser/dist-browser/helpers/jsonMethods"; import * as schema from "nope-browser/dist-browser/helpers/jsonSchemaMethods"; import * as lazy from "nope-browser/dist-browser/helpers/lazyMethods"; import * as limit from "nope-browser/dist-browser/helpers/limit"; import * as lists from "nope-browser/dist-browser/helpers/lists"; import * as objects from "nope-browser/dist-browser/helpers/objectMethods"; import * as pathes from "nope-browser/dist-browser/helpers/pathMatchingMethods"; import * as runtime from "nope-browser/dist-browser/helpers/runtimeMethods"; import * as sets from "nope-browser/dist-browser/helpers/setMethods"; import * as singletons from "nope-browser/dist-browser/helpers/singletonMethod"; import * as strings from "nope-browser/dist-browser/helpers/stringMethods"; import * as taskQueues from "nope-browser/dist-browser/helpers/taskQueue"; export * from "nope-browser/dist-browser/helpers/arrayMethods"; export * from "nope-browser/dist-browser/helpers/async"; export * from "nope-browser/dist-browser/helpers/descriptors"; export * from "nope-browser/dist-browser/helpers/dispatcherPathes"; export * from "nope-browser/dist-browser/helpers/functionMethods"; export * from "nope-browser/dist-browser/helpers/getSubject"; export * from "nope-browser/dist-browser/helpers/hash"; export * from "nope-browser/dist-browser/helpers/idMethods"; export * from "nope-browser/dist-browser/helpers/jsonMethods"; export * from "nope-browser/dist-browser/helpers/jsonSchemaMethods"; export * from "nope-browser/dist-browser/helpers/lazyMethods"; export * from "nope-browser/dist-browser/helpers/limit"; export * from "nope-browser/dist-browser/helpers/lists"; export * from "nope-browser/dist-browser/helpers/objectMethods"; export * from "nope-browser/dist-browser/helpers/pathMatchingMethods"; export * from "nope-browser/dist-browser/helpers/runtimeMethods"; export * from "nope-browser/dist-browser/helpers/setMethods"; export * from "nope-browser/dist-browser/helpers/singletonMethod"; export * from "nope-browser/dist-browser/helpers/stringMethods"; export * from "nope-browser/dist-browser/helpers/taskQueue"; export { forceGarbageCollection, registerGarbageCallback } from "nope-browser/dist-browser/helpers/gc"; export { async, arrays, dispatcherPathes, ids, json, lazy, objects, sets, schema, singletons, strings, pathes, runtime, subject, descriptors, functions, limit, hashs, taskQueues, lists, }; } declare module 'nope-browser/dist-browser/loader/index.browser' { /** * @author Martin Karkowski * @email m.karkowski@zema.de * @desc [description] */ export { generateNopeBasicPackage } from "nope-browser/dist-browser/loader/generateNopeBasicPackage"; export { getPackageLoader } from "nope-browser/dist-browser/loader/getPackageLoader.browser"; export { NopePackageLoader } from "nope-browser/dist-browser/loader/nopePackageLoader"; } declare module 'nope-browser/dist-browser/logger/index.browser' { /** * Tracing Logger-Level */ export const TRACE: any; /** * Debug Logger-Level */ export const DEBUG: any; /** * Info Logger-Level */ export const INFO: any; /** * Warn Logger-Level */ export const WARN: any; /** * Error Logger-Level */ export const ERROR: any; /** * The valid log-levels */ export const LEVELS: { trace: any; debug: any; info: any; warn: any; error: any; }; /** * The Logger-Interface */ export { ILogger } from "js-logger"; export { getLogerAsEventEmitter, LoggerAsEventEmitter, TCallback, TCallbackWithLevel, useEventLogger, } from "nope-browser/dist-browser/logger/eventLogging"; export { defineNopeLogger, getCentralNopeLogger, getNopeLogger, ValidLoggerDefinition, } from "nope-browser/dist-browser/logger/getLogger"; export { enabledFor, enableFor, LoggerLevel, LoggerLevels, shouldLog, } from "nope-browser/dist-browser/logger/nopeLogger"; export { setGlobalLoggerLevel } from "nope-browser/dist-browser/logger/setGlobalLoggerLevel"; } declare module 'nope-browser/dist-browser/module/index' { /** * @author Martin Karkowski * @email m.karkowski@zema.de */ export * from "nope-browser/dist-browser/types/nope/nopeModule.interface"; export { NopeBaseModule } from "nope-browser/dist-browser/module/BaseModule"; export { InjectableNopeBaseModule } from "nope-browser/dist-browser/module/BaseModule.injectable"; export { NopeGenericWrapper } from "nope-browser/dist-browser/module/GenericWrapper"; export { InjectableNopeGenericWrapper } from "nope-browser/dist-browser/module/GenericWrapper.injectable"; } declare module 'nope-browser/dist-browser/observables/index' { /** * @module observables * @author Martin Karkowski * @email m.karkowski@zema.de * This module contains a default implementation for a {@link INopeObservable}. * * Please checkout the {@link INopeObservable} for an example. */ export * from "nope-browser/dist-browser/types/nope/nopeObservable.interface"; export { NopeObservable } from "nope-browser/dist-browser/observables/nopeObservable"; export { InjectableNopeObservable } from "nope-browser/dist-browser/observables/nopeObservable.injectable"; } declare module 'nope-browser/dist-browser/promise/index' { /** * @author Martin Karkowski * @email m.karkowski@zema.de * @create date 2021-08-27 20:31:04 * @modify date 2021-08-27 20:31:04 * @desc [description] */ export * from "nope-browser/dist-browser/types/nope/nopePromise.interface"; export { NopePromise } from "nope-browser/dist-browser/promise/nopePromise"; } declare module 'nope-browser/dist-browser/pubSub' { /** * @author Martin Karkowski * @email m.karkowski@zema.de * @create date 2022-01-06 07:22:12 * @modify date 2022-01-06 07:22:12 * @desc [description] */ export { DataPubSubSystem } from "nope-browser/dist-browser/pubSub/nopeDataPubSubSystem"; export { PubSubSystemBase as PubSubSystem } from "nope-browser/dist-browser/pubSub/nopePubSubSystem"; } declare module 'nope-browser/dist-browser/types/index' { /** * @author Martin Karkowski * @email m.karkowski@zema.de * @desc [description] */ import * as nope from "nope-browser/dist-browser/types/nope/index"; import * as ui from "nope-browser/dist-browser/types/ui/index"; export * from "nope-browser/dist-browser/types/IJSONSchema"; export * from "nope-browser/dist-browser/types/nope/index"; export * from "nope-browser/dist-browser/types/ui/index"; export { nope, ui }; export type toConstructor<T> = { new (...args: any[]): T; }; } declare module 'nope-browser/dist-browser/ui/index.browser' { export * from "nope-browser/dist-browser/ui/helpers.browser"; } declare module 'nope-browser/dist-browser/plugins/index' { import { plugin, installPlugins, allPlugins } from "nope-browser/dist-browser/plugins/plugin"; export { plugin, installPlugins, allPlugins }; export const availablePlugins: { ackMessages: import("./plugin").Plugin; hello: import("./plugin").Plugin; rpcWithCallbacks: import("./plugin").Plugin; }; } declare module 'nope-browser/dist-browser/types/nope' { /** * @author Martin Karkowski * @email m.karkowski@zema.de * @create date 2021-08-27 20:24:15 * @modify date 2021-08-27 20:24:15 * @desc [description] */ export * from "nope-browser/dist-browser/types/nope/nopeCommunication.interface"; export * from "nope-browser/dist-browser/types/nope/nopeConnectivityManager.interface"; export * from "nope-browser/dist-browser/types/nope/nopeCore.interface"; export * from "nope-browser/dist-browser/types/nope/nopeDescriptor.interface"; export * from "nope-browser/dist-browser/types/nope/nopeDispatcher.interface"; export * from "nope-browser/dist-browser/types/nope/nopeEventEmitter.interface"; export * from "nope-browser/dist-browser/types/nope/nopeHelpers.interface"; export * from "nope-browser/dist-browser/types/nope/nopeInstanceManager.interface"; export * from "nope-browser/dist-browser/types/nope/nopeModule.interface"; export * from "nope-browser/dist-browser/types/nope/nopeObservable.interface"; export * from "nope-browser/dist-browser/types/nope/nopePackage.interface"; export * from "nope-browser/dist-browser/types/nope/nopePackageLoader.interface"; export * from "nope-browser/dist-browser/types/nope/nopePromise.interface"; export * from "nope-browser/dist-browser/types/nope/nopePubSub.interface"; export * from "nope-browser/dist-browser/types/nope/nopeRpcManager.interface"; export * from "nope-browser/dist-browser/types/nope/remoteInstance.interface"; } declare module 'nope-browser/dist-browser/communication/layers/index.browser' { /** * @author Martin Karkowski * @email m.karkowski@zema.de * @create date 2021-08-04 15:31:05 * @modify date 2022-01-10 15:56:47 * @desc [description] */ export { EventCommunicationInterface } from "nope-browser/dist-browser/communication/layers/EventCommunicationInterface"; export { IoSocketClientLayer } from "nope-browser/dist-browser/communication/layers/IoSocketClientLayer"; export { MQTTLayer } from "nope-browser/dist-browser/communication/layers/mqttLayer"; } declare module 'nope-browser/dist-browser/communication/bridge' { /** * @author Martin Karkowski * @email m.karkowski@zema.de */ import { EventEmitter } from "events"; import { ILogger } from "js-logger"; import { ValidLoggerDefinition } from "nope-browser/dist-browser/logger/index.browser"; import { Eventname, EventnameToEventType, ICommunicationBridge, ICommunicationInterface, INopeObservable } from "nope-browser/dist-browser/types/nope"; export class Bridge implements ICommunicationBridge { connected: INopeObservable<boolean>; considerConnection: boolean; ownDispatcherId: string; id: string; protected _useInternalEmitter: boolean; protected _logger: ILogger; protected _internalEmitter: EventEmitter; protected _layers: Map<string, { layer: ICommunicationInterface; considerConnection: boolean; forwardData: boolean; }>; protected _callbacks: Map<Eventname, Array<(...args: any[]) => any>>; /** * Creates an instance of Bridge. * @param {*} [id=generateId()] The ID. (this can be adapted later and is only used to simplify debugging) * @param {string} [loggerName="bridge"] The Name of the Logger. * @param {LoggerLevel} [level="info"] The Level of the Logger. * @memberof Bridge */ constructor(id?: string, logger?: ValidLoggerDefinition); on<T extends keyof EventnameToEventType>(eventname: T, cb: (data: EventnameToEventType[T]) => void): Promise<void>; emit<T extends keyof EventnameToEventType>(eventname: T, data: EventnameToEventType[T]): Promise<void>; detailListeners(type: "event" | "rpc" | "data" | "response", listeners: string[]): void; get receivesOwnMessages(): boolean; dispose(): Promise<void>; protected _checkInternalEmitter(): void; /** * Helper Function, which will internally subscribe to the Events of the Layer. * * @protected * @param {ICommunicationInterface} layer The Layer to consinder, on this layer, we will subscribe to the events * @param {keyof ICommunicationInterface} method The method used for subscription * @param {string} event The name of the Event * @param {boolean} forwardData Flag, showing whether data will be forwarded or not. * @memberof BridgeV2 */ protected _subscribeToCallback(layer: ICommunicationInterface, event: Eventname, forwardData: boolean): void; protected _on(event: Eventname, cb: any): void; protected _emit(event: Eventname, toExclude: ICommunicationInterface, dataToSend: any, force?: boolean): void; addCommunicationLayer(layer: ICommunicationInterface, forwardData?: boolean, considerConnection?: boolean): Promise<void>; removeCommunicationLayer(layer: ICommunicationInterface): Promise<void>; toDescription(): { connected: boolean; layers: { forwardData: boolean; receivesOwnMessages: boolean; id: string; considerConnection: boolean; }[]; }; } } declare module 'nope-browser/dist-browser/communication/getLayer.browser' { /** * @author Martin Karkowski * @email m.karkowski@zema.de * @create date 2021-03-23 07:30:19 * @modify date 2022-01-03 17:33:53 * @desc [description] */ import { ValidLoggerDefinition } from "nope-browser/dist-browser/logger/getLogger"; import { ICommunicationBridge } from "nope-browser/dist-browser/types/nope/nopeCommunication.interface"; import { Bridge } from "nope-browser/dist-browser/communication/bridge"; import { IoSocketClientLayer } from "nope-browser/dist-browser/communication/layers/index.browser"; export type validLayerOrMirror = "event" | "io-client" | "mqtt"; export const validLayers: { event: typeof Bridge; "io-client": typeof IoSocketClientLayer; }; export const layerDefaultParameters: { "io-client": string; }; /** * Function, that will create a Bridge, based on the provided function. * Based on the parameter "layer", a corresponding layer or mirror will * be added to the bridge. You can provide custom parameters using the * parameter "parameter". This will receive either the uri or ports. * Additionally you are able to assign a log-level to the bridge. * * @export * @param {validLayerOrMirror} layer the layer to add * @param {(number | string)} [parameter=null] the parameter required for the additonal layer / mirror * @param {LoggerLevel} [level=false] the level of the debugger * @return {ICommunicationBridge} */ export function getLayer(layer: validLayerOrMirror, parameter?: number | string, logger?: ValidLoggerDefinition): ICommunicationBridge; } declare module 'nope-browser/dist-browser/decorators/container' { /** * @author Martin Karkowski * @email m.karkowski@zema.de * @desc [description] */ import { IServiceOptions, INopeModule } from "nope-browser/dist-browser/types"; export type IexportAsNopeServiceParameters = IServiceOptions; /** * Return the central loger. This logger is a singleton (see {@link getSingleton}) * * @author M.Karkowski * @export * @return {NopeLogger} A Returns the Logger {@link NopeLogger} */ export function getCentralDecoratedContainer(): { services: Map<string, { uri: string; callback: (...args: any[]) => Promise<any>; options: IexportAsNopeServiceParameters; }>; classes: Map<string, INopeModule>; }; } declare module 'nope-browser/dist-browser/decorators/functionDecorators' { /** * @author Martin Karkowski * @email m.karkowski@zema.de * @desc [description] */ import { IexportAsNopeServiceParameters } from "nope-browser/dist-browser/decorators/container"; /** * Defintion of a Functon. */ export type callable<T> = { (...args: any[]): T; }; /** * Decorator, that will export the Function to a Dispatcher * @param func The Function * @param options The Options. */ export function exportAsNopeService<T>(func: T, options: IexportAsNopeServiceParameters): T & { options: IexportAsNopeServiceParameters; }; } declare module 'nope-browser/dist-browser/decorators/moduleDecorators' { /** * @author Martin Karkowski * @email m.karkowski@zema.de */ import { IEventOptions, IServiceOptions, INopeModule } from "nope-browser/dist-browser/types/nope/nopeModule.interface"; /** * Decorator, used to export the Method as Service to Nope.. * @param options The options used for linking. */ export function nopeMethod(options: IServiceOptions): (target: INopeModule, methodName: string, descriptor: PropertyDescriptor) => void; /** * Decorator, will link the Parameter to Nope and make it available. it available as * Nope-Property. * @param options The Options, describing the settings for linking. */ export function nopeProperty(options: IEventOptions): (target: INopeModule, propertyKey: string, descriptor: PropertyDescriptor) => void; /** * Decorator, that will link the Parameter to Nope and make it available as * Event Emitter. * @param options The Options, describing the settings for linking. */ export function nopeEmitter(options: IEventOptions): (target: INopeModule, propertyKey: string, descriptor: PropertyDescriptor) => void; } declare module 'nope-browser/dist-browser/dispatcher/baseServices' { /** * @author Martin Karkowski * @email m.karkowski@zema.de * @desc [description] */ import { INopeDispatcher } from "nope-browser/dist-browser/types/nope"; import { enableTimeSyncing, generateDefineMaster, generatePingServices, waitForDispatcher } from "nope-browser/dist-browser/dispatcher/baseServices/connectivy"; import { enablingSyncingData } from "nope-browser/dist-browser/dispatcher/baseServices/data"; export { generateDefineMaster, generatePingServices, enableTimeSyncing as generateSyncServices, enablingSyncingData, waitForDispatcher, }; /** * Helper to define simpler names for the Services */ export const SERVICES_NAME: { defineMaster: typeof generateDefineMaster; pingService: typeof generatePingServices; timeSyncingService: typeof enableTimeSyncing; syncingDataService: typeof enablingSyncingData; }; /** * Helper, which will enable all BaseServices * * @author M.Karkowski * @export * @param {INopeDispatcher} dispatcher The Dispatcher to use. * @param {{ * services?: Array<keyof typeof SERVICES_NAME>; * }} [opts] * @return The provided Functions. */ export function addAllBaseServices(dispatcher: INopeDispatcher, opts?: { services?: Array<keyof typeof SERVICES_NAME>; }): Promise<{ manualSyncTime?: () => Promise<void>; determinePing?: (target: string) => Promise<{ requestId: string; dispatcherId: string; timestamp: number; isMaster: boolean; ping: number; }>; pingAll?: () => Promise<{ pings: Promise<{ requestId: string; dispatcherId: string; timestamp: number; isMaster: boolean; ping: number; }>[]; avg: number; max: { max: number; index: number; }; min: { min: number; index: number; }; }>; setMaster?: () => Promise<void>; }>; } declare module 'nope-browser/dist-browser/dispatcher/ConnectivityManager' { /** * @module connectivityManager * @author Martin Karkowski * @email m.karkowski@zema.de * * # NoPE - Connectivity Manager * * The following elements are exported: * - {@link INopeConnectivityManager}, * - {@link INopeINopeConnectivityOptions}, * - {@link INopeINopeConnectivityTimeOptions}, * - {@link NopeConnectivityManager} * * The NoPE-Dispatcher uses one `ConnectivityManager`. The manager observes the connection and remotly connected dispatchers (and their `ConnectivityManager`). * The Manager detects newly connected dispatchers and disconnected dispatchers. Additionally, it sends a StatusMessage (in the form of `INopeStatusInfo`). * This status message is interpreted as heartbeat. The `ConnectivityManager` checks those heartbeats with a defined interval. If a specific amount of time is * ellapsed, the remote dispatcher is marked as `slow` -> `warning` -> `dead`. After an additional delay in the state `dead` the dispatcher is altough removed. * * ## Master * * Defaultly a `ConnectivityManager` is elected as `master`. The master is defined as the `ConnectivityManager` with the highest `upTime`. * * > Alternativly a master can be forced. * * ## Synchronizing time * * Because we asume, that **NoPE** is running on different computing nodes, we have to be able to synchronize the time between those elements. Therefore the * `ConnectivityManager` is able to sync the time (by providing a `timestamp` and an additional `delay` that was needed to get to the call (for instance `ping / 2`)) * * * * ```javascript * // First lets install nope using npm * const nope = require("../dist-nodejs/index.nodejs") * * // Create a communicator: * // We will use the event layer (which just runs internally) * const communicator = nope.getLayer("event"); * * // Lets create our dispatcher * * // 1. Dispatcher simulates our local system * const localDispatcher = nope.dispatcher.getDispatcher({ * communicator, * id: "local" * }, { * singleton: false, * useBaseServices: false * }); * ``` * * > For Jupyter we need an extra async wrapper to wait for initalizing the dispatcher: * * see here for the details in Jupyter: https://n-riesco.github.io/ijavascript/doc/async.ipynb.html * * * ```javascript * $$.async(); * // Lets wait for our element to be ready. * localDispatcher.ready.waitFor().then($$.done); * ``` * * Now we want to listen to newly connected dispatchers. For this purpose, we create an observer, which will listen to changes. * * * ```javascript * // Subscribe to changes * const observer = localDispatcher.connectivityManager.dispatchers.onChange.subscribe(data => { * // Log the changes * console.log((new Date()).toISOString(),"onChange - listener"); * console.log("\tadded =", data.added); * console.log("\tremoved =", data.removed); * }); * ``` * * Additionally we want to show the currently connected dispatchers. In this data the own dispatcher will **allways** be included: * * * ```javascript * // Show our connected Dispatchers * let connectedDispatchers = localDispatcher.connectivityManager.dispatchers.data.getContent(); * let localDispatcherIncluded = connectedDispatchers.includes(localDispatcher.id); * * // Now lets log our results. * console.log("connectedDispatchers =", connectedDispatchers); * console.log("localDispatcherIncluded =", localDispatcherIncluded); * ``` * * >``` * > connectedDispatchers = [ 'local' ] * > localDispatcherIncluded = true * >``` * * Now that we have implemented our listeners and have seen the connected dispatchers (which is only the `"local"`-dispatchre), We will add an additional dispatcher. This should result in calling our `onChange`-listener. Additionally, we wait until our `remoteDispatcher` is initalized * * * ```javascript * // 2. Dispatcher simulates our remote system * const remoteDispatcher = nope.dispatcher.getDispatcher({ * communicator, * id: "remote" * }, { * singleton: false, * useBaseServices: false * }); * * ``` * * >``` * > 2022-01-20T11:39:55.766Z onChange - listener * > added = [ 'remote' ] * > removed = [] * >``` * * Now we want to see, which system is the current master. This should be our `local`. * * * ```javascript * // We expect to be the master, because the localDispatcher has been created first. * console.log("master =", localDispatcher.connectivityManager.master.id); * ``` * * > `master = local` * * * We can now force the remote dispatcher to be our master, by setting the master. (For this purpose we can later use a base service ==> then we just have to call the service) * * * ```javascript * $$.async(); * * remoteDispatcher.connectivityManager.isMaster = true; * localDispatcher.connectivityManager.isMaster = false; * * // Our messaging is async ==> we wait an amount of time * setTimeout(() => $$.done(),1000); * ``` * * * ```javascript * // We expect the master to be the remote. * console.log("master =", localDispatcher.connectivityManager.master.id); * console.log("master-info =", localDispatcher.connectivityManager.master); * ``` * * >``` * > master = remote * > master-info = { * > id: 'remote', * > env: 'javascript', * > version: '1.0.0', * > isMaster: true, * > host: { * > cores: 8, * > cpu: { * > model: 'Intel(R) Core(TM) i7-8565U CPU', * > speed: 1992, * > usage: 0.0038778477944740875 * > }, * > os: 'win32', * > ram: { usedPerc: 0.362681220626356, free: 20676, total: 32442 }, * > name: 'nz-078' * > }, * > pid: 18068, * > timestamp: 1642678798813, * > upTime: 3049, * > status: 0 * > } * >``` * * * Now lets see what happens if we adapt the heartbeat intervall of our *local* instance. We want to receive every 50 ms a heartbeat: * * * ```javascript * $$.async() * * const renderStatus = () => { * console.log((new Date()).toISOString(),"master-info =", localDispatcher.connectivityManager.master.status) * } * * setTimeout(renderStatus, 50); * setTimeout(renderStatus, 750); * setTimeout(renderStatus, 1500); * setTimeout(renderStatus, 2500); * * * localDispatcher.connectivityManager.setTimings({ * // our system will send every 50 ms an heartbeat. * sendAliveInterval: 250, * // we will check that after * checkInterval: 125, * // will mark dispatchers as slow after not receiving heartbeats for 50ms * slow: 500, * // we will mark dispatchers with a warning flag after 50 ms * warn: 1000, * // we mark it as dead after 0.5 s * dead: 2000, * // We will remove the dispatcher after 1 s * remove: 3000, * }); * * remoteDispatcher.connectivityManager.setTimings({ * // our system will send every 50 ms an heartbeat. * sendAliveInterval: 5000, * }); * * * * // We reset the timeouts. * setTimeout(() => localDispatcher.connectivityManager.setTimings({}), 3000); * setTimeout(() => remoteDispatcher.connectivityManager.setTimings({}), 3000); * setTimeout(() => $$.done(), 5000); * * ``` * * >``` * > 2022-01-20T11:40:01.089Z master-info = 0 * > 2022-01-20T11:40:01.789Z master-info = 1 * > 2022-01-20T11:40:02.536Z master-info = 2 * > 2022-01-20T11:40:03.543Z master-info = 3 * > 2022-01-20T11:40:03.977Z onChange - listener * > added = [] * > removed = [ 'remote' ] * > 2022-01-20T11:40:04.547Z onChange - listener * > added = [ 'remote' ] * > removed = [] * >``` * */ export { INopeConnectivityManager, INopeINopeConnectivityOptions, INopeINopeConnectivityTimeOptions, } from "nope-browser/dist-browser/types/nope/nopeConnectivityManager.interface"; export { NopeConnectivityManager } from "nope-browser/dist-browser/dispatcher/ConnectivityManager/ConnectivityManager"; } declare module 'nope-browser/dist-browser/dispatcher/InstanceManager' { /** * @author Martin Karkowski * @email m.karkowski@zema.de * @create date 2022-01-06 07:27:43 * @modify date 2022-01-06 07:27:43 * @desc [description] */ export { generateAssignmentChecker } from "nope-browser/dist-browser/dispatcher/InstanceManager/assignmentCheckers"; export { NopeInstanceManager } from "nope-browser/dist-browser/dispatcher/InstanceManager/InstanceManager"; } declare module 'nope-browser/dist-browser/dispatcher/RpcManager' { /** * @author Martin Karkowski * @email m.karkowski@zema.de * @create date 2022-01-04 13:32:29 * @modify date 2022-01-04 13:32:29 * @desc [description] */ export { INopeRpcManager, ValidDefaultSelectors, ValidSelectorFunction, } from "nope-browser/dist-browser/types/nope"; export { NopeRpcManager } from "nope-browser/dist-browser/dispatcher/RpcManager/NopeRpcManager"; export { generateSelector } from "nope-browser/dist-browser/dispatcher/RpcManager/selectors"; } declare module 'nope-browser/dist-browser/decorators/index' { /** * @author Martin Karkowski * @email m.karkowski@zema.de */ export { getCentralDecoratedContainer, IexportAsNopeServiceParameters, } from "nope-browser/dist-browser/decorators/container"; export { exportAsNopeService } from "nope-browser/dist-browser/decorators/functionDecorators"; export { nopeEmitter, nopeMethod, nopeProperty } from "nope-browser/dist-browser/decorators/moduleDecorators"; } declare module 'nope-browser/dist-browser/types/nope/nopeDispatcher.interface' { import { IHost, INopeINopeConnectivityOptions } from "nope-browser/dist-browser/types/nope/nopeConnectivityManager.interface"; import { INopeCore } from "nope-browser/dist-browser/types/nope/nopeCore.interface"; import { INopeDescriptor } from "nope-browser/dist-browser/types/nope/nopeDescriptor.interface"; import { IEventAdditionalData, IEventCallback, INopeEventEmitter, INopeObserver } from "nope-browser/dist-browser/types/nope/nopeEventEmitter.interface"; import { INopeModule, INopeModuleDescription } from "nope-browser/dist-browser/types/nope/nopeModule.interface"; import { INopeObservable } from "nope-browser/dist-browser/types/nope/nopeObservable.interface"; import { INopePromise } from "nope-browser/dist-browser/types/nope/nopePromise.interface"; import { ValidDefaultSelectors } from "nope-browser/dist-browser/types/nope/nopeRpcManager.interface"; export type IGenerateInstanceCallback<I extends INopeModule> = () => Promise<I>; export type IGenerateRemoteInstanceCallback<I extends INopeModule> = (dispatcher: INopeDispatcher, description: INopeModuleDescription, ...args: any[]) => Promise<I>; export type IGenerateRemoteInstanceForOtherDispatcherCallback<I extends INopeModule> = (dispatcher: INopeDispatcher, identifier: string, ...args: any[]) => Promise<I>; export type IValidPromise<T> = Promise<T> | INopePromise<T>; export type INopeDispatcherOptions = { /** * The Id of the Dispatcher * * @author M.Karkowski * @type {string} */ id?: string; /** * The default-selector to select the service providers * * @author M.Karkowski * @type {ValidDefaultSelectors} */ defaultSelector?: ValidDefaultSelectors; /** * Flag to force using the service provider selector * functionalities. * * @author M.Karkowski * @type {boolean} */ forceUsingSelectors?: boolean; /** * Flag to ensure, that every path used is corrcet and could be * used as variable in another system. * * @author M.Karkowski * @type {boolean} */ forceUsingValidVarNames?: boolean; /** * Flag to indicate, whether methodes with the call {@link nope.exportAsNopeService} are * provided by the instance or not. */ useExportedServices?: boolean; } & INopeINopeConnectivityOptions; export interface IHostOverview extends IHost { dispatchers: { id: string; pid: number | string; }[]; instances: INopeModuleDescription[]; services: { name: string; schema: INopeDescriptor; }[]; } export interface IDispatcherConstructor { new (options: INopeDispatcherOptions, _generateEmitter: <T>() => INopeEventEmitter<T>, _generateObservable: <T>() => INopeObservable<T>): INopeDispatcher; } /** * # NoPE - Dispatcher * * The NoPE-Dispatcher is designed as Layer between the different Modules / Dispatchers. They allow distributed computing or just a simple ***Service oriented Architecture*** (*SOA*). A dispatcher is used to link the modules, share data and events and provide a remote procedure call (rpc) interface. * * ## Building Blocks of a Dispatcher: * * | element | description | * |-|-| * | `connectivityManager` | establishes a connection to other dispatchers and manages the status of the remotely connected dispatchers. It checks their health and removes dead dispatchers. | * | `eventDistributor` | shares events accross the network (or internally). You can use this element to listen for specific events. The subscription to those events allows `mqtt`-patterns. Additionaly, you are allowed to emit event on specific topics, or pattern based topics | * | `dataDistributor` | shares data accross the network (or internally). In comperisson to events, data is persistent and is available all the time. You can use this sub-module to listen for specific data-changes (install data-hooks), pull specific data or push data. You can pull / push data using a `mqtt`-pattern based path. | * | `rpcManager` | Used to perform `remote procedure calls` (see [here](https://de.wikipedia.org/wiki/Remote_Procedure_Call)). The manager keeps track of the available services. You must use the sub-module to register/unregister (new) services. | * | `instanceManager` | Used to create/dispose (remote) instances. The manager keeps track of the available instances in the network, allows to create `wrappers` for those instances. You must use the sub-module to register/unregister (new) instances. To allow the system to provide a service for creating instances of as specific type, you can provide a generator and provide it as `service`. | * @export * @interface INopeDispatcher */ export interface INopeDispatcher extends INopeCore { readonly options: INopeDispatcherOptions; /** * Pushs the desired data into the system. * @param path The path to the Data. * @param content The Content to Push * @param options The Options during pushing */ pushData<T = unknown>(path: string, content: T, options: IEventAdditionalData): void; /** * Helper to pull some data from the system. * @param path The path to the Data. * @param _default The value to use if no data has been found. If not provided an error is thrown. Defaults to None. */ pullData<T = unknown, D = null>(path: string, _default?: D): T; /** * Helper to subscribe to specific events. * @param event Name of the relevant event * @param subscription the Callback to use. */ subscribeToEvent<T = unknown>(event: string, subscription: IEventCallback<T>): INopeObserver; /** * Emits an event with the given name. All * event-subscriber, where the topic matches * will receive this notification. * @param eventName * @param data */ emitEvent(eventName: string, data: any): any; /** * Receive the "instances" | "services" | "properties" | "events" * which matches with the given pattern. Therefore the user provides * the pattern and tyle. * * @author M.Karkowski * @param {string} pattern Pattern to query the provided type. * @param {("instances" | "services" | "properties" | "events")} type Type which should be querried * @return {string[]} List of the matching items. * @memberof INopeDispatcher */ query(pattern: string, type: "instances" | "services" | "properties" | "events"): string[]; /** * Function used to dispose the Dispatcher. This will * dispose all instances an remove the them. They wont * be available in the NoPE-Network. * * @auth