updating to version 1.4.2
This commit is contained in:
parent
90783572b4
commit
a4ed621237
23
CHANGELOG.md
23
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`
|
||||
@ -272,3 +272,24 @@ Inital commit, which is working with the browser
|
||||
- `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.
|
||||
|
||||
# 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.
|
||||
|
@ -1 +1 @@
|
||||
1.4.1
|
||||
1.4.2
|
@ -476,9 +476,9 @@ export async function main(
|
||||
defaultValue?: any;
|
||||
}[] = [],
|
||||
forcedArgs: Partial<RunArgs> = {},
|
||||
quite = false
|
||||
quiet = false
|
||||
) {
|
||||
if (!quite) {
|
||||
if (!quiet) {
|
||||
console.log(NOPELOGO);
|
||||
console.log("\n\n");
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -40,7 +40,7 @@ export class EventCommunicationInterface implements ICommunicationInterface {
|
||||
cb: (data: EventnameToEventType[T]) => void
|
||||
): Promise<void> {
|
||||
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);
|
||||
});
|
||||
|
@ -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() + "'",
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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<void> {
|
||||
// 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<void> {
|
||||
public async dispose(quiet = false): Promise<void> {
|
||||
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 });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
});
|
||||
|
@ -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,
|
||||
|
@ -66,15 +66,6 @@ export class NopeRpcManager<T extends IFunctionOptions = IFunctionOptions>
|
||||
}
|
||||
>;
|
||||
|
||||
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<T extends IFunctionOptions = IFunctionOptions>
|
||||
};
|
||||
|
||||
// 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<T extends IFunctionOptions = IFunctionOptions>
|
||||
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<T extends IFunctionOptions = IFunctionOptions>
|
||||
};
|
||||
|
||||
// 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<T extends IFunctionOptions = IFunctionOptions>
|
||||
}
|
||||
|
||||
// Send the Message.
|
||||
this._communicator.emit("ServicesChanged", message);
|
||||
this._communicator.emit("servicesChanged", message);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -495,31 +489,31 @@ export class NopeRpcManager<T extends IFunctionOptions = IFunctionOptions>
|
||||
|
||||
// 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<T extends IFunctionOptions = IFunctionOptions>
|
||||
// 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<T extends IFunctionOptions = IFunctionOptions>
|
||||
public async cancelTask(
|
||||
taskId: string,
|
||||
reason: Error,
|
||||
quite = false
|
||||
quiet = false
|
||||
): Promise<boolean> {
|
||||
if (this._runningInternalRequestedTasks.has(taskId)) {
|
||||
const task = this._runningInternalRequestedTasks.get(taskId);
|
||||
@ -601,11 +593,11 @@ export class NopeRpcManager<T extends IFunctionOptions = IFunctionOptions>
|
||||
|
||||
// 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<T extends IFunctionOptions = IFunctionOptions>
|
||||
return false;
|
||||
}
|
||||
|
||||
protected async _cancelHelper(toCancel: Set<string>, reason: Error) {
|
||||
if (toCancel.size) {
|
||||
const promises: Promise<any>[] = [];
|
||||
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<T extends IFunctionOptions = IFunctionOptions>
|
||||
*/
|
||||
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<string>();
|
||||
|
||||
// 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<any>[] = [];
|
||||
|
||||
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<T extends IFunctionOptions = IFunctionOptions>
|
||||
}
|
||||
}
|
||||
|
||||
const promises: Promise<any>[] = [];
|
||||
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<T extends IFunctionOptions = IFunctionOptions>
|
||||
reason: Error
|
||||
): Promise<void> {
|
||||
// Provide a List containing all Tasks, that has to be canceled
|
||||
const _tasksToCancel: string[] = [];
|
||||
|
||||
const toCancel = new Set<string>();
|
||||
// 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<any>[] = [];
|
||||
|
||||
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<T extends IFunctionOptions = IFunctionOptions>
|
||||
: 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<T extends IFunctionOptions = IFunctionOptions>
|
||||
* @param {any[]} params
|
||||
* @param {(Partial<ICallOptions> & {
|
||||
* selector?: ValidSelectorFunction;
|
||||
* quite?: boolean;
|
||||
* quiet?: boolean;
|
||||
* })} [options={}] Options for the Call. You can assign a different selector.
|
||||
* @return {*} {INopePromise<T>} The result of the call
|
||||
* @memberof nopeDispatcher
|
||||
@ -872,9 +845,6 @@ export class NopeRpcManager<T extends IFunctionOptions = IFunctionOptions>
|
||||
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<T extends IFunctionOptions = IFunctionOptions>
|
||||
// Define a Callback-Function, which will expect the Task.
|
||||
const ret = new NopePromise<T>(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<T extends IFunctionOptions = IFunctionOptions>
|
||||
};
|
||||
|
||||
for (const [idx, contentOfParameter] of params.entries()) {
|
||||
taskRequest.params.push({
|
||||
packet.params.push({
|
||||
idx,
|
||||
data: contentOfParameter,
|
||||
});
|
||||
@ -973,17 +951,23 @@ export class NopeRpcManager<T extends IFunctionOptions = IFunctionOptions>
|
||||
// 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<T extends IFunctionOptions = IFunctionOptions>
|
||||
|
||||
// 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<T extends IFunctionOptions = IFunctionOptions>
|
||||
* @param {any[]} params
|
||||
* @param {(Partial<ICallOptions> & {
|
||||
* selector?: ValidSelectorFunction;
|
||||
* quite?: boolean;
|
||||
* quiet?: boolean;
|
||||
* })} [options={}] Options for the Call. You can assign a different selector.
|
||||
* @return {*} {INopePromise<T>} The result of the call
|
||||
* @memberof nopeDispatcher
|
||||
@ -1077,16 +1061,15 @@ export class NopeRpcManager<T extends IFunctionOptions = IFunctionOptions>
|
||||
*/
|
||||
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<T extends IFunctionOptions = IFunctionOptions>
|
||||
this._runningExternalRequestedTasks = new Map();
|
||||
}
|
||||
|
||||
public async dispose(): Promise<void> {}
|
||||
public async dispose(): Promise<void> {
|
||||
this.clearTasks();
|
||||
this.unregisterAll();
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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]) {
|
||||
|
@ -58,7 +58,7 @@ export class PubSubSystemBase<
|
||||
> implements IPubSubSystem<AD, I, O>
|
||||
{
|
||||
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<AD> = {},
|
||||
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,
|
||||
|
@ -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<Eventname> = [
|
||||
// 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 {
|
||||
|
@ -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<void>}
|
||||
* @memberof INopeStatusManager
|
||||
*/
|
||||
dispose(quite?: boolean): Promise<void>;
|
||||
dispose(quiet?: boolean): Promise<void>;
|
||||
|
||||
/**
|
||||
* Returns the Status of an other Manager.
|
||||
|
@ -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
|
||||
|
@ -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<boolean>;
|
||||
cancelTask(taskId: string, reason: Error, quiet?: boolean): Promise<boolean>;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -230,7 +230,7 @@ export interface INopeRpcManager<
|
||||
* @param {unknown[]} params Parameters
|
||||
* @param {(Partial<ICallOptions> & {
|
||||
* selector?: ValidSelectorFunction;
|
||||
* quite?: boolean;
|
||||
* quiet?: boolean;
|
||||
* preventSelector?: boolean;
|
||||
* })} options
|
||||
* @return {*} {INopePromise<T>}
|
||||
@ -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<void>}
|
||||
* @memberof INopeRpcManager
|
||||
*/
|
||||
|
4
package-lock.json
generated
4
package-lock.json
generated
@ -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",
|
||||
|
@ -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/**/*",
|
||||
|
Loading…
Reference in New Issue
Block a user