diff --git a/CHANGELOG.md b/CHANGELOG.md index 31abd31..b410ed1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,7 @@ Inital commit, which is working with the browser # 1.0.26 - Fixes: - - pub-sub-system: Fixed `_notify` and `_partialMatchingUpdate` + - pub-sub-system: Fixed `_notify` and `_updatePartialMatching` - Added: - pub-sub-system: Listeners receive now: topicOfContent (the path of the data that is extracted), topicOfChange (the path of the data that emitted teh update), topicOfSubscription (the subscription.), - nope repl: Added the context `nope` @@ -271,4 +271,25 @@ Inital commit, which is working with the browser - Modified: - `lib\pubSub\nopePubSubSystem.ts`: - throws error if `register` method doest not contain a topic. - - Adapted the behavior of `_patternbasedPullData`. If no default default value is present -> the function returns an empty array. \ No newline at end of file + - Adapted the behavior of `_patternbasedPullData`. If no default default value is present -> the function returns an empty array. + +# 1.4.2 + - Fixes: + - Fixing time based issue in `ConnectivityManager` (using the now synced time for checkups) + - `dispatchers.ConnectivityManager.ConnectivityManager`: fixing `_checkDispatcherHealth` + - Fixing `extractUniqueValues` now it is possible to use different pathes for the `key` and `value` + - `lib\helpers\mapMethods.ts` has been adapted + - `lib\pubSub\nopePubSubSystem.ts` contains the following fixes: + - fixing typo of method `updateMatching` + - Modified: + - Adapted the event-names of the communication. Now starts with lower chars. + - Code clean ups: + - removed `_communcatorCallback` from `dispatcher/RpcManager/NopeRpcManager.ts` + - renamed `quite` to `quiet` + - adapted internal methods of `NopeRpcManager`: + - added: `_cancelHelper` + - > Now the `target`in the Request segement is provided every time! + - renamed `_partialMatchingUpdate` to `_updatePartialMatching` + - adapted `NopePubSub`: + - renamed parameter `mqttBasedPatternSubscriptions` to `mqttPatternBasedSubscriptions` + - `helpers/path` -> in `_getLeastCommonPathSegment` we only iterate over the avaible keys. diff --git a/contribute/VERSION b/contribute/VERSION index 13175fd..c9929e3 100644 --- a/contribute/VERSION +++ b/contribute/VERSION @@ -1 +1 @@ -1.4.1 \ No newline at end of file +1.4.2 \ No newline at end of file diff --git a/lib/cli/runNopeBackend.ts b/lib/cli/runNopeBackend.ts index 5d67de1..d273ba7 100644 --- a/lib/cli/runNopeBackend.ts +++ b/lib/cli/runNopeBackend.ts @@ -476,9 +476,9 @@ export async function main( defaultValue?: any; }[] = [], forcedArgs: Partial = {}, - quite = false + quiet = false ) { - if (!quite) { + if (!quiet) { console.log(NOPELOGO); console.log("\n\n"); } diff --git a/lib/communication/bridge.ts b/lib/communication/bridge.ts index eecb92e..b9f065c 100644 --- a/lib/communication/bridge.ts +++ b/lib/communication/bridge.ts @@ -165,7 +165,7 @@ export class Bridge implements ICommunicationBridge { this._internalEmitter.getMaxListeners() + 1 ); - if (this._logger?.enabledFor(DEBUG) && event !== "StatusChanged") { + if (this._logger?.enabledFor(DEBUG) && event !== "statusChanged") { this._logger.debug("subscribe to", event); // If logging is enable, we subscribe to that. @@ -198,7 +198,7 @@ export class Bridge implements ICommunicationBridge { dataToSend: any, force = false ): void { - if (this._logger?.enabledFor(WARN) && event !== "StatusChanged") { + if (this._logger?.enabledFor(WARN) && event !== "statusChanged") { this._logger.debug("emitting", event, dataToSend); } if (this._useInternalEmitter || force) { diff --git a/lib/communication/layers/EventCommunicationInterface.ts b/lib/communication/layers/EventCommunicationInterface.ts index dd9d45d..9d77eb6 100644 --- a/lib/communication/layers/EventCommunicationInterface.ts +++ b/lib/communication/layers/EventCommunicationInterface.ts @@ -40,7 +40,7 @@ export class EventCommunicationInterface implements ICommunicationInterface { cb: (data: EventnameToEventType[T]) => void ): Promise { this._emitter.on(eventname, cb); - if (eventname !== "StatusChanged" && this._logger?.enabledFor(DEBUG)) { + if (eventname !== "statusChanged" && this._logger?.enabledFor(DEBUG)) { this._emitter.on(eventname, (...args) => { this._logger.debug("received", "'" + eventname + "'", ...args); }); diff --git a/lib/communication/layers/ioSocketServerLayer.ts b/lib/communication/layers/ioSocketServerLayer.ts index 4f74cdf..ffc8bf0 100644 --- a/lib/communication/layers/ioSocketServerLayer.ts +++ b/lib/communication/layers/ioSocketServerLayer.ts @@ -68,7 +68,7 @@ export class ioSocketServerLayer extends EventCommunicationInterface { // are forwarding the data. for (const event of Eventnames) { client.on(event, (data) => { - if (event !== "StatusChanged" && _this._logger?.enabledFor(DEBUG)) { + if (event !== "statusChanged" && _this._logger?.enabledFor(DEBUG)) { _this._logger.debug( "forwarding", "'" + event.toString() + "'", @@ -118,7 +118,7 @@ export class ioSocketServerLayer extends EventCommunicationInterface { } // Now we log the output - if (event !== "StatusUpdate" && this._logger?.enabledFor(DEBUG)) { + if (event !== "statusChanged" && this._logger?.enabledFor(DEBUG)) { this._logger.debug( forwarded ? "forwarded" : "didnt forward", "'" + event.toString() + "'", diff --git a/lib/communication/layers/mqttLayer.ts b/lib/communication/layers/mqttLayer.ts index 2c14c49..d5d81f9 100644 --- a/lib/communication/layers/mqttLayer.ts +++ b/lib/communication/layers/mqttLayer.ts @@ -121,7 +121,7 @@ export class MQTTLayer implements ICommunicationInterface { if (_mqttMatch(subscription, topic)) { if ( _this._logger?.enabledFor(DEBUG) && - !topic.includes("nope/StatusUpdate") + !topic.includes("nope/StatusChanged") ) { _this._logger.debug( "received", @@ -158,27 +158,27 @@ export class MQTTLayer implements ICommunicationInterface { if (this.forwardToCustomTopics) { switch (eventname) { - case "DataChanged": { - let topic = (data as EventnameToEventType["DataChanged"]).path; + case "dataChanged": { + let topic = (data as EventnameToEventType["dataChanged"]).path; topic = this._adaptTopic(topic); await this._emit( topic, - (data as EventnameToEventType["DataChanged"]).data + (data as EventnameToEventType["dataChanged"]).data ); break; } - case "Event": { - let topic = (data as EventnameToEventType["Event"]).path; + case "event": { + let topic = (data as EventnameToEventType["event"]).path; topic = this._adaptTopic(topic); - await this._emit(topic, (data as EventnameToEventType["Event"]).data); + await this._emit(topic, (data as EventnameToEventType["event"]).data); break; } - case "RpcRequest": { - let topic = (data as EventnameToEventType["RpcRequest"]).functionId; + case "rpcRequest": { + let topic = (data as EventnameToEventType["rpcRequest"]).functionId; topic = this._adaptTopic(topic); await this._emit( topic, - (data as EventnameToEventType["RpcRequest"]).params + (data as EventnameToEventType["rpcRequest"]).params ); break; } @@ -281,7 +281,7 @@ export class MQTTLayer implements ICommunicationInterface { try { if ( _this._logger?.enabledFor(DEBUG) && - !_topic.startsWith(_this.preTopic + "/nope/StatusUpdate") + !_topic.startsWith(_this.preTopic + "/nope/StatusChanged") ) { _this._logger.debug("emitting: ", _topic); } diff --git a/lib/dispatcher/ConnectivityManager/ConnectivityManager.ts b/lib/dispatcher/ConnectivityManager/ConnectivityManager.ts index 10da45f..bc961fb 100644 --- a/lib/dispatcher/ConnectivityManager/ConnectivityManager.ts +++ b/lib/dispatcher/ConnectivityManager/ConnectivityManager.ts @@ -387,7 +387,7 @@ export class NopeConnectivityManager implements INopeConnectivityManager { // Wait until the Element is connected. await this._communicator.connected.waitFor(); - await this._communicator.on("StatusChanged", (info) => { + await this._communicator.on("statusChanged", (info) => { _this._externalDispatchers.set(info.id, info); // If there is an update, we have to make shure, that our information @@ -399,7 +399,7 @@ export class NopeConnectivityManager implements INopeConnectivityManager { _this.dispatchers.update(); }); - await this._communicator.on("Bonjour", (opts) => { + await this._communicator.on("bonjour", (opts) => { if (_this.id !== opts.dispatcherId) { if (_this._logger?.enabledFor(DEBUG)) { // If there is a Logger: @@ -413,7 +413,7 @@ export class NopeConnectivityManager implements INopeConnectivityManager { } }); - await this._communicator.on("Aurevoir", (msg) => { + await this._communicator.on("aurevoir", (msg) => { // Remove the Dispatcher. _this._externalDispatchers.delete(msg.dispatcherId); _this.dispatchers.update(); @@ -449,7 +449,7 @@ export class NopeConnectivityManager implements INopeConnectivityManager { // Based on the Difference Determine the Status if (diff > this._timeouts.remove) { - // remove the Dispatcher. But be quite. + // remove the Dispatcher. But be quiet. // Perhaps more dispatchers will be removed this._removeDispatcher(status.id, true); changes = true; @@ -494,15 +494,15 @@ export class NopeConnectivityManager implements INopeConnectivityManager { * @author M.Karkowski * @protected * @param {string} dispatcher The Id of the dispatcher - * @param {boolean} [quite=false] if set to quite, the *dispatchers* attribute wont be udpated. + * @param {boolean} [quiet=false] if set to quiet, the *dispatchers* attribute wont be udpated. * @memberof NopeConnectivityManager */ - protected _removeDispatcher(dispatcher: string, quite = false): void { + protected _removeDispatcher(dispatcher: string, quiet = false): void { // Delete the Generators of the Instances. const dispatcherInfo = this._externalDispatchers.get(dispatcher); const deleted = this._externalDispatchers.delete(dispatcher); - if (!quite) { + if (!quiet) { this.dispatchers.update(); } @@ -530,7 +530,7 @@ export class NopeConnectivityManager implements INopeConnectivityManager { try { const info = this.info; this._externalDispatchers.set(this.id, info); - await this._communicator.emit("StatusChanged", info); + await this._communicator.emit("statusChanged", info); } catch (e) { this._logger.error("Failled to send the status"); } @@ -571,7 +571,7 @@ export class NopeConnectivityManager implements INopeConnectivityManager { */ public async emitBonjour(): Promise { // Emit the Bonjour Message. - this._communicator.emit("Bonjour", { dispatcherId: this.id }); + this._communicator.emit("bonjour", { dispatcherId: this.id }); } /** @@ -687,7 +687,7 @@ export class NopeConnectivityManager implements INopeConnectivityManager { /** * Will dispose the Dispatcher. Must be called on exit for a clean exit. Otherwise it is defined as dirty exits */ - public async dispose(quite = false): Promise { + public async dispose(quiet = false): Promise { if (this._sendInterval) { clearInterval(this._sendInterval); } @@ -699,8 +699,8 @@ export class NopeConnectivityManager implements INopeConnectivityManager { } // Emits the aurevoir Message. - if (!quite) { - this._communicator.emit("Aurevoir", { dispatcherId: this.id }); + if (!quiet) { + this._communicator.emit("aurevoir", { dispatcherId: this.id }); } } } diff --git a/lib/dispatcher/Core/NopeCore.ts b/lib/dispatcher/Core/NopeCore.ts index 5842245..b64c851 100644 --- a/lib/dispatcher/Core/NopeCore.ts +++ b/lib/dispatcher/Core/NopeCore.ts @@ -105,7 +105,7 @@ export class NopeCore implements INopeCore { const rcvExternally = generateId(); // 1. Subscribe to the events: - this.communicator.on("Event", (msg) => { + this.communicator.on("event", (msg) => { if (msg.sender !== this.id) { // split the Message in segments const { path, data, ...options } = msg; @@ -120,7 +120,7 @@ export class NopeCore implements INopeCore { this.eventDistributor.onIncrementalDataChange.subscribe((item) => { if (item.sender !== rcvExternally) { - this.communicator.emit("Event", { + this.communicator.emit("event", { ...item, sender: this.id, }); @@ -129,7 +129,7 @@ export class NopeCore implements INopeCore { // Link the Data-Distributor: // 1. Subscribe to the changes: - this.communicator.on("DataChanged", (msg) => { + this.communicator.on("dataChanged", (msg) => { if (msg.sender !== this.id) { // split the Message in segments const { path: name, data, ...options } = msg; @@ -145,7 +145,7 @@ export class NopeCore implements INopeCore { // 2. Enable emitting the updates this.dataDistributor.onIncrementalDataChange.subscribe((item) => { if (item.sender !== rcvExternally) { - this.communicator.emit("DataChanged", { + this.communicator.emit("dataChanged", { ...item, sender: this.id, }); diff --git a/lib/dispatcher/InstanceManager/InstanceManager.ts b/lib/dispatcher/InstanceManager/InstanceManager.ts index 4db8d8a..ac596d3 100644 --- a/lib/dispatcher/InstanceManager/InstanceManager.ts +++ b/lib/dispatcher/InstanceManager/InstanceManager.ts @@ -270,7 +270,7 @@ export class NopeInstanceManager implements INopeInstanceManager { protected _sendAvailableInstances(): void { const _this = this; // Update the Instances provided by this module. - this._communicator.emit("InstancesChanged", { + this._communicator.emit("instancesChanged", { dispatcher: this._id, // We will send the descriptions. instances: Array.from(this._internalInstances).map((identifier) => { @@ -326,7 +326,7 @@ export class NopeInstanceManager implements INopeInstanceManager { }); // Listen to newly created instances. - await this._communicator.on("InstancesChanged", (message) => { + await this._communicator.on("instancesChanged", (message) => { // Store the instances: _this._mappingOfRemoteDispatchersAndInstances.set( message.dispatcher, diff --git a/lib/dispatcher/RpcManager/NopeRpcManager.ts b/lib/dispatcher/RpcManager/NopeRpcManager.ts index f3216ae..2c6adf7 100644 --- a/lib/dispatcher/RpcManager/NopeRpcManager.ts +++ b/lib/dispatcher/RpcManager/NopeRpcManager.ts @@ -66,15 +66,6 @@ export class NopeRpcManager } >; - protected _communicatorCallbacks: Map< - string, - { - registeredId: string; - type: "request" | "response"; - cb: (data) => any; - } - >; - /** * A Mapping of the Services a dispatcher is hosting. * Key = Dispatcher-ID @@ -376,7 +367,7 @@ export class NopeRpcManager }; // Use the communicator to publish the result. - await this._communicator.emit("RpcResponse", result); + await this._communicator.emit("rpcResponse", result); } } catch (error) { if (this._logger) { @@ -387,6 +378,9 @@ export class NopeRpcManager this._logger.error(error); } + // Remove the requested task. + this._runningExternalRequestedTasks.delete(data.taskId); + // An Error occourd => Forward the Error. const result: IRpcResponseMsg = { error: { @@ -397,7 +391,7 @@ export class NopeRpcManager }; // Send the Error via the communicator to the remote. - await this._communicator.emit("RpcResponse", result); + await this._communicator.emit("rpcResponse", result); } } @@ -475,7 +469,7 @@ export class NopeRpcManager } // Send the Message. - this._communicator.emit("ServicesChanged", message); + this._communicator.emit("servicesChanged", message); } /** @@ -495,31 +489,31 @@ export class NopeRpcManager // Subscribe to the availableServices of Remotes. // If there is a new Service => udpate the External Services - await this._communicator.on("ServicesChanged", (data) => { + await this._communicator.on("servicesChanged", (data) => { try { _this.updateDispatcher(data); } catch (e) { - this._logger.error("Error during handling an onNewServicesAvailable"); + this._logger.error("Error during handling an ServicesChanged"); this._logger.error(e); } }); - await this._communicator.on("RpcRequest", (data) => { + await this._communicator.on("rpcRequest", (data) => { _this._handleExternalRequest(data); }); - await this._communicator.on("RpcResponse", (data) => { + await this._communicator.on("rpcResponse", (data) => { _this._handleExternalResponse(data); }); // We will listen on Cancelations. - await this._communicator.on("TaskCancelation", (event) => { - if (event.dispatcher !== _this._id) { + await this._communicator.on("taskCancelation", (event) => { + if (event.dispatcher === _this._id) { _this.onCancelTask.emit(event); } }); // Now we listen to unregisteredServices - await this._communicator.on("RpcUnregister", (msg) => { + await this._communicator.on("rpcUnregister", (msg) => { if (_this._registeredServices.has(msg.identifier)) { _this._unregisterService(msg.identifier); } @@ -571,9 +565,7 @@ export class NopeRpcManager // Stop executing the requested Tasks. this.cancelRequestedTasksOfDispatcher( dispatcher, - new Error( - "Dispatcher has been removed! Tasks cannot be executed any more." - ) + new Error("Dispatcher has been removed! Tasks are not required any more.") ); } @@ -588,7 +580,7 @@ export class NopeRpcManager public async cancelTask( taskId: string, reason: Error, - quite = false + quiet = false ): Promise { if (this._runningInternalRequestedTasks.has(taskId)) { const task = this._runningInternalRequestedTasks.get(taskId); @@ -601,11 +593,11 @@ export class NopeRpcManager // Propagate the Cancellation externally. // Therefore use the desired Mode. - await this._communicator.emit("TaskCancelation", { + await this._communicator.emit("taskCancelation", { dispatcher: this._id, reason, taskId, - quite, + quiet, }); // Indicate a successful cancelation. @@ -616,8 +608,19 @@ export class NopeRpcManager return false; } + protected async _cancelHelper(toCancel: Set, reason: Error) { + if (toCancel.size) { + const promises: Promise[] = []; + for (const taskId of toCancel) { + promises.push(this.cancelTask(taskId, reason)); + } + + await Promise.all(promises); + } + } + /** - * Internal Helper Function, used to close all tasks with a specific service. + * Helper Function, used to close all tasks with a specific service. * * @protected * @param {string} serviceName The Name of the Service. @@ -626,28 +629,18 @@ export class NopeRpcManager */ public async cancelRunningTasksOfService(serviceName: string, reason: Error) { // Provide a List containing all Tasks, that has to be canceled - const _tasksToCancel: string[] = []; + const toCancel = new Set(); // Filter all Tasks that shoud be canceled. for (const [id, task] of this._runningInternalRequestedTasks.entries()) { // Therefore compare the reuqired Service by the Task if (task.serviceName === serviceName) { // if the service matches, put it to our list. - _tasksToCancel.push(id); + toCancel.add(id); } } - const promises: Promise[] = []; - - if (_tasksToCancel.length > 0) { - // First remove all Tasks. - // Then cancel them to avoid side effects - for (const id of _tasksToCancel) { - promises.push(this.cancelTask(id, reason)); - } - } - - await Promise.all(promises); + return await this._cancelHelper(toCancel, reason); } /** @@ -673,14 +666,7 @@ export class NopeRpcManager } } - const promises: Promise[] = []; - for (const taskId of toCancel) { - promises.push(this.cancelTask(taskId, reason)); - } - - if (promises.length) { - await Promise.all(promises); - } + return await this._cancelHelper(toCancel, reason); } /** @@ -696,28 +682,17 @@ export class NopeRpcManager reason: Error ): Promise { // Provide a List containing all Tasks, that has to be canceled - const _tasksToCancel: string[] = []; - + const toCancel = new Set(); // Filter all Tasks that shoud be canceled. for (const [id, task] of this._runningInternalRequestedTasks.entries()) { // Therefore compare the reuqired Service by the Task if (task.target === dispatcher) { // if the service matches, put it to our list. - _tasksToCancel.push(id); + toCancel.add(id); } } - const promises: Promise[] = []; - - if (_tasksToCancel.length > 0) { - // First remove all Tasks. - // Then cancel them to avoid side effects - for (const id of _tasksToCancel) { - promises.push(this.cancelTask(id, reason)); - } - } - - await Promise.all(promises); + return await this._cancelHelper(toCancel, reason); } /** @@ -758,8 +733,6 @@ export class NopeRpcManager : func : ((func as any).id as string) || "0"; - this._communicatorCallbacks.delete(_id); - // Publish the Available Services. this._sendAvailableServices(); @@ -857,7 +830,7 @@ export class NopeRpcManager * @param {any[]} params * @param {(Partial & { * selector?: ValidSelectorFunction; - * quite?: boolean; + * quiet?: boolean; * })} [options={}] Options for the Call. You can assign a different selector. * @return {*} {INopePromise} The result of the call * @memberof nopeDispatcher @@ -872,9 +845,6 @@ export class NopeRpcManager const _this = this; const _options = { - deletableCallbacks: [], - paramsHasNoCallback: false, - dynamicCallback: false, resultSink: this._getServiceName(serviceName, "response"), ...options, } as ICallOptions; @@ -907,19 +877,27 @@ export class NopeRpcManager // Define a Callback-Function, which will expect the Task. const ret = new NopePromise(async (resolve, reject) => { try { - const requestedTask: any = { + const taskRequest: { + resolve: (value: any) => void; + reject: (error: any) => void; + clear: () => void; + serviceName: string; + timeout?: any; + target: string; + } = { resolve, reject, clear, serviceName, timeout: null, + target: null, }; // Register the Handlers, - _this._runningInternalRequestedTasks.set(_taskId, requestedTask); + _this._runningInternalRequestedTasks.set(_taskId, taskRequest); // Define a Task-Request - const taskRequest: IRequestRpcMsg & IExtraData = { + const packet: IRequestRpcMsg & IExtraData = { functionId: serviceName, params: [], taskId: _taskId, @@ -928,7 +906,7 @@ export class NopeRpcManager }; for (const [idx, contentOfParameter] of params.entries()) { - taskRequest.params.push({ + packet.params.push({ idx, data: contentOfParameter, }); @@ -973,17 +951,23 @@ export class NopeRpcManager // Assign the Selector: taskRequest.target = dispatcherToUse; } + + packet.target = taskRequest.target; + } else { + taskRequest.target = Array.from( + this.services.keyMappingReverse.get(serviceName) + )[0]; } // Send the Message to the specific element: - await _this._communicator.emit("RpcRequest", taskRequest); + await _this._communicator.emit("rpcRequest", packet); if (_this._logger?.enabledFor(DEBUG)) { _this._logger.debug( `Dispatcher "${ this._id }" putting task "${_taskId}" on: "${_this._getServiceName( - taskRequest.functionId, + packet.functionId, "request" )}"` ); @@ -991,7 +975,7 @@ export class NopeRpcManager // If there is a timeout => if (options.timeout > 0) { - requestedTask.timeout = setTimeout(() => { + taskRequest.timeout = setTimeout(() => { _this.cancelTask( _taskId, new Error( @@ -1027,7 +1011,7 @@ export class NopeRpcManager * @param {any[]} params * @param {(Partial & { * selector?: ValidSelectorFunction; - * quite?: boolean; + * quiet?: boolean; * })} [options={}] Options for the Call. You can assign a different selector. * @return {*} {INopePromise} The result of the call * @memberof nopeDispatcher @@ -1077,16 +1061,15 @@ export class NopeRpcManager */ public unregisterAll(): void { if (this._registeredServices) { - for (const id of this._registeredServices.keys()) { + const toUnregister = Array.from(this._registeredServices.keys()); + + for (const id of toUnregister) { this._unregisterService(id); } this._registeredServices.clear(); } else { this._registeredServices = new Map(); } - - // Reset the Callbacks. - this._communicatorCallbacks = new Map(); } /** @@ -1104,5 +1087,8 @@ export class NopeRpcManager this._runningExternalRequestedTasks = new Map(); } - public async dispose(): Promise {} + public async dispose(): Promise { + this.clearTasks(); + this.unregisterAll(); + } } diff --git a/lib/dispatcher/baseServices/data.ts b/lib/dispatcher/baseServices/data.ts index 929d7be..f2991d5 100644 --- a/lib/dispatcher/baseServices/data.ts +++ b/lib/dispatcher/baseServices/data.ts @@ -41,7 +41,7 @@ export async function enablingSyncingData(dispatcher: INopeDispatcher) { const data = dispatcher.dataDistributor.pullData("", {}); // Emit the Data. - dispatcher.communicator.emit("DataChanged", { + dispatcher.communicator.emit("dataChanged", { args: [], data: data, forced: false, diff --git a/lib/helpers/path.ts b/lib/helpers/path.ts index 65093ee..c028934 100644 --- a/lib/helpers/path.ts +++ b/lib/helpers/path.ts @@ -83,7 +83,7 @@ function _getLeastCommonPathSegment( const ret: string[] = []; let idx = 0; - const max = Math.max(p1.length, p2.length); + const max = Math.min(p1.length, p2.length); while (idx < max) { if (p1[idx] == p2[idx]) { diff --git a/lib/pubSub/nopePubSubSystem.ts b/lib/pubSub/nopePubSubSystem.ts index c477115..c91cf62 100644 --- a/lib/pubSub/nopePubSubSystem.ts +++ b/lib/pubSub/nopePubSubSystem.ts @@ -42,7 +42,7 @@ type TMatchting = { dataQuery: Map>; }; -const DEFAULT_OBJ = {id:"default"}; +const DEFAULT_OBJ = { id: "default" }; export class PubSubSystemBase< AD extends ITopicSetContentOptions & { @@ -58,7 +58,7 @@ export class PubSubSystemBase< > implements IPubSubSystem { public _options: IPubSubOptions = { - mqttBasedPatternSubscriptions: true, + mqttPatternBasedSubscriptions: true, forwardChildData: true, forwardParentData: true, }; @@ -135,7 +135,7 @@ export class PubSubSystemBase< ) { this._options = Object.assign( { - mqttBasedPatternSubscriptions: true, + mqttPatternBasedSubscriptions: true, forwardChildData: true, forwardParentData: true, matchTopicsWithoutWildcards: true, @@ -173,9 +173,11 @@ export class PubSubSystemBase< // See interface description public register(emitter: I, options: IEventOptions): O { if (!this._emitters.has(emitter as unknown as O)) { - - if (typeof(options.topic) !== "string" && typeof(options.topic) !== "object"){ - throw Error("A Topic must be provided in the options.") + if ( + typeof options.topic !== "string" && + typeof options.topic !== "object" + ) { + throw Error("A Topic must be provided in the options."); } let pubTopic: string | false = @@ -243,7 +245,7 @@ export class PubSubSystemBase< // Update the Matching Rules. // this.updateMatchting(); - this._partialMatchingUpdate("add", emitter, pubTopic, subTopic); + this._updatePartialMatching("add", emitter, pubTopic, subTopic); if (callback) { // If necessary. Add the Callback. @@ -303,7 +305,7 @@ export class PubSubSystemBase< const data = this._emitters.get(emitter as unknown as O); - this._partialMatchingUpdate( + this._updatePartialMatching( "remove", emitter, data.pubTopic, @@ -317,7 +319,7 @@ export class PubSubSystemBase< this._emitters.set(emitter as unknown as O, data); // Update the Matching Rules. - this._partialMatchingUpdate("add", emitter, pubTopic, subTopic); + this._updatePartialMatching("add", emitter, pubTopic, subTopic); } else { throw Error("Already registered Emitter!"); } @@ -333,7 +335,7 @@ export class PubSubSystemBase< this._emitters.delete(emitter as unknown as O); // Update the Matching Rules. - this._partialMatchingUpdate("remove", emitter, pubTopic, subTopic); + this._updatePartialMatching("remove", emitter, pubTopic, subTopic); return true; } @@ -458,7 +460,7 @@ export class PubSubSystemBase< // - direct change (topic = path) => content // - parent based change => a super change if (result.containsWildcards) { - if (this._options.mqttBasedPatternSubscriptions) { + if (this._options.mqttPatternBasedSubscriptions) { if (result.patternToExtractData) { this.__addToMatchingStructure( "dataQuery", @@ -517,7 +519,7 @@ export class PubSubSystemBase< * @param _pubTopic * @param _subTopic */ - protected _partialMatchingUpdate( + protected _updatePartialMatching( mode: "add" | "remove", _emitter: I, _pubTopic: string | false, @@ -727,7 +729,7 @@ export class PubSubSystemBase< pathOfChange: string, data: T, options: Partial = {}, - quite: boolean = false, + quiet: boolean = false, emitter: O = null ): void { const _options = this._updateOptions(options); @@ -745,7 +747,7 @@ export class PubSubSystemBase< this._notify(pathOfContent, pathOfChange, _options, emitter); } - if (!quite) { + if (!quiet) { // Emit the data change. this.onIncrementalDataChange.emit({ path: pathOfContent, @@ -786,9 +788,9 @@ export class PubSubSystemBase< // Its not a pattern so we will speed up // things. - const data:T = this._pullData(pattern, DEFAULT_OBJ); + const data: T = this._pullData(pattern, DEFAULT_OBJ as any as T); - if (data !== DEFAULT_OBJ) { + if (data !== (DEFAULT_OBJ as any)) { return [ { path: pattern, @@ -804,7 +806,7 @@ export class PubSubSystemBase< ]; } - return [] + return []; } // Now we know, we have to work with the query, diff --git a/lib/types/nope/nopeCommunication.interface.ts b/lib/types/nope/nopeCommunication.interface.ts index 643685e..a95d47a 100644 --- a/lib/types/nope/nopeCommunication.interface.ts +++ b/lib/types/nope/nopeCommunication.interface.ts @@ -130,18 +130,18 @@ export interface ICommunicationBridge extends ICommunicationInterface { } export type EventnameToEventType = { - Aurevoir: IAurevoirMsg; - Bonjour: IBonjourMsg; - InstancesChanged: IAvailableInstancesMsg; - DataChanged: IDataChangedMsg; - ServicesChanged: IAvailableServicesMsg; - StatusChanged: INopeStatusInfo; - TaskCancelation: ITaskCancelationMsg; - Event: IExternalEventMsg; - RpcRequest: IRequestRpcMsg; - RpcResponse: IRpcResponseMsg; - RpcUnregister: IRpcUnregisterMsg; - Tasks; + aurevoir: IAurevoirMsg; + bonjour: IBonjourMsg; + instancesChanged: IAvailableInstancesMsg; + dataChanged: IDataChangedMsg; + servicesChanged: IAvailableServicesMsg; + statusChanged: INopeStatusInfo; + taskCancelation: ITaskCancelationMsg; + event: IExternalEventMsg; + rpcRequest: IRequestRpcMsg; + rpcResponse: IRpcResponseMsg; + rpcUnregister: IRpcUnregisterMsg; + tasks; }; export type Eventname = keyof EventnameToEventType; @@ -149,18 +149,18 @@ export type Eventname = keyof EventnameToEventType; // List containing all valid Eventnames. export const Eventnames: Array = [ // Default emitters - "Aurevoir", - "Bonjour", - "InstancesChanged", - "DataChanged", - "ServicesChanged", - "StatusChanged", - "TaskCancelation", - "Event", - "RpcRequest", - "RpcResponse", - "RpcUnregister", - "Tasks", + "aurevoir", + "bonjour", + "instancesChanged", + "dataChanged", + "servicesChanged", + "statusChanged", + "taskCancelation", + "event", + "rpcRequest", + "rpcResponse", + "rpcUnregister", + "tasks", ]; export interface IAurevoirMsg { @@ -232,12 +232,12 @@ export type ITaskCancelationMsg = { reason: any; /** - * Flag to indicate, that this task should be canceled quite. + * Flag to indicate, that this task should be canceled quiet. * * @author M.Karkowski * @type {boolean} */ - quite?: boolean; + quiet?: boolean; }; export interface IExternalEventMsg extends IIncrementalChange { diff --git a/lib/types/nope/nopeConnectivityManager.interface.ts b/lib/types/nope/nopeConnectivityManager.interface.ts index 5986c97..7c10031 100644 --- a/lib/types/nope/nopeConnectivityManager.interface.ts +++ b/lib/types/nope/nopeConnectivityManager.interface.ts @@ -324,11 +324,11 @@ export interface INopeConnectivityManager { * Disposes the StatusManager and thereby, * * @author M.Karkowski - * @param {boolean} [quite=false] + * @param {boolean} [quiet=false] * @return {*} {Promise} * @memberof INopeStatusManager */ - dispose(quite?: boolean): Promise; + dispose(quiet?: boolean): Promise; /** * Returns the Status of an other Manager. diff --git a/lib/types/nope/nopePubSub.interface.ts b/lib/types/nope/nopePubSub.interface.ts index 423927e..041a3e1 100644 --- a/lib/types/nope/nopePubSub.interface.ts +++ b/lib/types/nope/nopePubSub.interface.ts @@ -51,7 +51,7 @@ export interface IPubSubOptions { * @type {boolean} * @memberof TPubSubOptions */ - mqttBasedPatternSubscriptions?: boolean; + mqttPatternBasedSubscriptions?: boolean; /** * Flag to enable propagation of child data. * Defaults to true diff --git a/lib/types/nope/nopeRpcManager.interface.ts b/lib/types/nope/nopeRpcManager.interface.ts index 25063a9..49cba54 100644 --- a/lib/types/nope/nopeRpcManager.interface.ts +++ b/lib/types/nope/nopeRpcManager.interface.ts @@ -152,10 +152,10 @@ export interface INopeRpcManager< * @author M.Karkowski * @param {string} taskId The ID of the Task * @param {Error} reason The Reason to Cancel the Task - * @param {void} quite Disables Log or not. + * @param {void} quiet Disables Log or not. * @memberof INopeRpcManager */ - cancelTask(taskId: string, reason: Error, quite?: boolean): Promise; + cancelTask(taskId: string, reason: Error, quiet?: boolean): Promise; /** * @@ -230,7 +230,7 @@ export interface INopeRpcManager< * @param {unknown[]} params Parameters * @param {(Partial & { * selector?: ValidSelectorFunction; - * quite?: boolean; + * quiet?: boolean; * preventSelector?: boolean; * })} options * @return {*} {INopePromise} @@ -270,7 +270,7 @@ export interface INopeRpcManager< * Disposes the StatusManager and thereby, * * @author M.Karkowski - * @param {boolean} [quite=false] + * @param {boolean} [quiet=false] * @return {Promise} * @memberof INopeRpcManager */ diff --git a/package-lock.json b/package-lock.json index eee14e2..30140ba 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "nope", - "version": "1.3.12", + "version": "1.4.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "nope", - "version": "1.3.12", + "version": "1.4.1", "license": "MIT", "dependencies": { "argparse": "^2.0.1", diff --git a/package.json b/package.json index 35c4a94..a834446 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nope", - "version": "1.4.1", + "version": "1.4.2", "description": "NoPE Runtime for Nodejs. For Browser-Support please use nope-browser", "files": [ "dist-nodejs/**/*",