updating to version 1.4.5
This commit is contained in:
parent
dbeb3cd689
commit
77630c315b
133
CHANGELOG.md
133
CHANGELOG.md
@ -50,10 +50,10 @@ Inital commit, which is working with the browser
|
||||
# 1.0.33
|
||||
- Modified:
|
||||
- cli.runNopeBackend: added the flag "noBaseServices" to prevent providing the base-services
|
||||
- communication.getLayer.nodejs/browser: adding default value for logger
|
||||
- communication.getLayer.nodejs\browser: adding default value for logger
|
||||
- dispatcher.getDispatcher: changed option "constructorClass" to "dispatcherConstructorClass"
|
||||
- helpers.limit.spec: Adapted Timings
|
||||
- loader.getPackageLoader.nodejs/browser: Changed the options.
|
||||
- loader.getPackageLoader.nodejs\browser: Changed the options.
|
||||
|
||||
# 1.0.34
|
||||
- Fixes:
|
||||
@ -109,33 +109,33 @@ Inital commit, which is working with the browser
|
||||
|
||||
# 1.2.0
|
||||
- Added:
|
||||
- `lib/cli/nope` adding scan for ui service
|
||||
- `lib/decorators/container`: Main Container, holding all `methods` and `classes`. Use `getCentralDecoratedContainer()` to get this decorator.
|
||||
- `types/nope/nopePackage.interface` added `IClassDescription` which contains the class description used in the Package Description.
|
||||
- `logger/nopeLogger`: added methods: `enabledFor`, `enableFor`, `shouldLog`
|
||||
- `lib\cli\nope` adding scan for ui service
|
||||
- `lib\decorators\container`: Main Container, holding all `methods` and `classes`. Use `getCentralDecoratedContainer()` to get this decorator.
|
||||
- `types\nope\nopePackage.interface` added `IClassDescription` which contains the class description used in the Package Description.
|
||||
- `logger\nopeLogger`: added methods: `enabledFor`, `enableFor`, `shouldLog`
|
||||
- `package.json`: installed types of `ace` text editor.
|
||||
- `ui/helpers.browser`: Created `convertInstanceRenderPage` and `IUiDefinition`
|
||||
- `ui/helpers.nodejs`: Added a Helper to write the Ui-File (`writeUiFile`) and parse its arguments (`readInwriteUiFileArgs`)
|
||||
- `ui/index.*`: Crated the corresponding exports.
|
||||
- `ui\helpers.browser`: Created `convertInstanceRenderPage` and `IUiDefinition`
|
||||
- `ui\helpers.nodejs`: Added a Helper to write the Ui-File (`writeUiFile`) and parse its arguments (`readInwriteUiFileArgs`)
|
||||
- `ui\index.*`: Crated the corresponding exports.
|
||||
- Modified:
|
||||
- `lib/decorators/*` Adding the main `container` where every function, service method etc is added. All decorators now safe the decorated elements in the container.
|
||||
- `helpers/json`: Adding `BEGIN_STR` and `END_STR` for parsing functions as constants.
|
||||
- `logger/eventLogging`: simplify `useEventLogger`
|
||||
- `logger/index.browser`: Adating exports.
|
||||
- `loader/loadPackages`: Modifing `IPackageConfig` now extends Partial the `IPackageDescription`
|
||||
- `types/ui/editor/IEditPage`: adapting Type of `getData` to `T`->`any`. Adapting the return of `getPorts` (The Ports will be generated in the ui then)
|
||||
- `types/ui/editor/helpers.interface`: Adapting the `w2ui` and added `w2uiHelpers` and added `ace`. Rearanging `IRenderData` element. to compact the data.
|
||||
- `types/ui/editor/render.callbacks`: Rearange the Generic Type of `TRenderInstancePage` and Renaming `TCreatorPage` to `TInstanceManagerPage`. Adapting the `option` of `TInstanceManagerPage` regarding the `createInstance` and `instances`
|
||||
- `types/ui/editor/index`: Adapting the Exports.
|
||||
- `lib/index.browser`: Exporting `ui` elements
|
||||
- `lib/index.nodejs`: Exporting `ui` elements
|
||||
- `lib/types/index`: Exporting `ui` elements
|
||||
- `lib\decorators\*` Adding the main `container` where every function, service method etc is added. All decorators now safe the decorated elements in the container.
|
||||
- `helpers\json`: Adding `BEGIN_STR` and `END_STR` for parsing functions as constants.
|
||||
- `logger\eventLogging`: simplify `useEventLogger`
|
||||
- `logger\index.browser`: Adating exports.
|
||||
- `loader\loadPackages`: Modifing `IPackageConfig` now extends Partial the `IPackageDescription`
|
||||
- `types\ui\editor\IEditPage`: adapting Type of `getData` to `T`->`any`. Adapting the return of `getPorts` (The Ports will be generated in the ui then)
|
||||
- `types\ui\editor\helpers.interface`: Adapting the `w2ui` and added `w2uiHelpers` and added `ace`. Rearanging `IRenderData` element. to compact the data.
|
||||
- `types\ui\editor\render.callbacks`: Rearange the Generic Type of `TRenderInstancePage` and Renaming `TCreatorPage` to `TInstanceManagerPage`. Adapting the `option` of `TInstanceManagerPage` regarding the `createInstance` and `instances`
|
||||
- `types\ui\editor\index`: Adapting the Exports.
|
||||
- `lib\index.browser`: Exporting `ui` elements
|
||||
- `lib\index.nodejs`: Exporting `ui` elements
|
||||
- `lib\types\index`: Exporting `ui` elements
|
||||
- Fixes:
|
||||
- `types/nope/nopeInstanceManager.interface`: Fixing Type of createInstance. Now the Type `I` extends `INopeModule` instead of being set to `IGenericNopeModule`
|
||||
- `types\nope\nopeInstanceManager.interface`: Fixing Type of createInstance. Now the Type `I` extends `INopeModule` instead of being set to `IGenericNopeModule`
|
||||
|
||||
# 1.2.1
|
||||
- Added:
|
||||
- `types/ui/helpers.interface`: Added the ui section in `IRenderData`. This contains the following props: `fullscreen` (INopeObservable<boolean>) to controll the fullscreen / ge the state. Additionally the functions `openFullscreen`, `closeFullScreen` and `getTheme` have been added. Added type `IUiTheme`
|
||||
- `types\ui\helpers.interface`: Added the ui section in `IRenderData`. This contains the following props: `fullscreen` (INopeObservable<boolean>) to controll the fullscreen \ ge the state. Additionally the functions `openFullscreen`, `closeFullScreen` and `getTheme` have been added. Added type `IUiTheme`
|
||||
- Modified:
|
||||
- Renamed `IEditPage` to `IServiceEditPage`
|
||||
- Renamed `NODE_TYPE_COMPOSED` to `NODE_TYPE_GROUP`
|
||||
@ -144,7 +144,7 @@ Inital commit, which is working with the browser
|
||||
|
||||
# 1.2.2
|
||||
- Modified:
|
||||
- renaming the following constants in `lib/types/ui/editor/INodes`:
|
||||
- renaming the following constants in `lib\types\ui\editor\INodes`:
|
||||
- NODE_TYPE_CONSTANT = "node:data:constant";
|
||||
- NODE_TYPE_DATA_TO_TOKEN = "node:logic:data-to-token";
|
||||
- NODE_TYPE_FLOW_OPERATION = "node:logic:flow";
|
||||
@ -153,9 +153,9 @@ Inital commit, which is working with the browser
|
||||
- NODE_TYPE_TRANSITION = "node:logic:transition";
|
||||
- NODE_TYPE_VAR = "node:data:constant";
|
||||
- NODE_TYPE_MODULE = "node:module";
|
||||
- updating `TServiceGetPortsReturn` (adding `label` and removing `type`)and `IServiceEditPage` (remove `getPorts`) in `lib/types/ui/editor/IServiceEditPage`
|
||||
- relocating `IUiDefinition` to `lib/types/ui/helpers.interface`
|
||||
- influences `lib/ui/helpers.browser` and `lib/ui/helpers.nodejs`
|
||||
- updating `TServiceGetPortsReturn` (adding `label` and removing `type`)and `IServiceEditPage` (remove `getPorts`) in `lib\types\ui\editor\IServiceEditPage`
|
||||
- relocating `IUiDefinition` to `lib\types\ui\helpers.interface`
|
||||
- influences `lib\ui\helpers.browser` and `lib\ui\helpers.nodejs`
|
||||
|
||||
# 1.3.0
|
||||
- Fixes:
|
||||
@ -170,77 +170,77 @@ Inital commit, which is working with the browser
|
||||
|
||||
# 1.3.2
|
||||
- Fixes:
|
||||
- `helpers/objectMethods`: The function `convertData` no converts not matching items as well
|
||||
- `helpers/objectMethods`: The function `tranformMap` no works with empty pathes like `""`
|
||||
- `helpers\objectMethods`: The function `convertData` no converts not matching items as well
|
||||
- `helpers\objectMethods`: The function `tranformMap` no works with empty pathes like `""`
|
||||
|
||||
# 1.3.3
|
||||
- Fixes:
|
||||
- `dispatcher/instanceManager/InstanceManager`: Fixing the Mapbased item
|
||||
- `dispatcher/RpcManager/RpcManager`: Fixing the Mapbased item
|
||||
- `dispatcher\instanceManager\InstanceManager`: Fixing the Mapbased item
|
||||
- `dispatcher\RpcManager\RpcManager`: Fixing the Mapbased item
|
||||
|
||||
# 1.3.4
|
||||
- reverting 1.3.3
|
||||
- Fixes:
|
||||
- `dispatcher/instanceManager/InstanceManager`: Fixing the Mapbased item
|
||||
- `dispatcher/RpcManager/RpcManager`: Fixing the Mapbased item
|
||||
- `helpers/mapMethods*`: Fixing `extractUniqueValues` and some tests. If you want to extract the data of an array please use `+`
|
||||
- `helpers/mergeData*`: Fixing the Mapbased item
|
||||
- `helpers/objectMethods*`: Fixing `convertData` function
|
||||
- `dispatcher\instanceManager\InstanceManager`: Fixing the Mapbased item
|
||||
- `dispatcher\RpcManager\RpcManager`: Fixing the Mapbased item
|
||||
- `helpers\mapMethods*`: Fixing `extractUniqueValues` and some tests. If you want to extract the data of an array please use `+`
|
||||
- `helpers\mergeData*`: Fixing the Mapbased item
|
||||
- `helpers\objectMethods*`: Fixing `convertData` function
|
||||
|
||||
# 1.3.5
|
||||
- reverting 1.3.3
|
||||
- Added:
|
||||
- `helpers/stringMethods`: Added the function `varifyString`
|
||||
- `helpers\stringMethods`: Added the function `varifyString`
|
||||
- Modified:
|
||||
- `dispatcher/instanceManager/InstanceManager`: Adapting the name of the instance to use a valid instance name.
|
||||
- `dispatcher/rpcManager/rpcManager`: Adapting the name of the service to use a valid service name.
|
||||
- `cli/runNopeBackend`: Adapting the name of the service to use a valid service name.
|
||||
- `dispatcher\instanceManager\InstanceManager`: Adapting the name of the instance to use a valid instance name.
|
||||
- `dispatcher\rpcManager\rpcManager`: Adapting the name of the service to use a valid service name.
|
||||
- `cli\runNopeBackend`: Adapting the name of the service to use a valid service name.
|
||||
|
||||
# 1.3.6
|
||||
- Added:
|
||||
- `cli/runNopeBackend`: Added the a helper to add varify the `name`. (see modifications in `dispatcher/InstanceManager/InstanceManager`, `dispatcher/RpcManager/NopeRpcManager`)
|
||||
- `cli\runNopeBackend`: Added the a helper to add varify the `name`. (see modifications in `dispatcher\InstanceManager\InstanceManager`, `dispatcher\RpcManager\NopeRpcManager`)
|
||||
- Modified:
|
||||
- `helpers/stringMethods`: added function `union` and `difference`.
|
||||
- `helpers/setMethods`: added function `varifyString`.
|
||||
- `types/nope/nopeDispatcher.interface`: Added option `forceUsingValidVarNames`
|
||||
- `helpers\stringMethods`: added function `union` and `difference`.
|
||||
- `helpers\setMethods`: added function `varifyString`.
|
||||
- `types\nope\nopeDispatcher.interface`: Added option `forceUsingValidVarNames`
|
||||
- Fixes:
|
||||
- `types/nope/nopeInstanceManager.interface`: Fixed the typing of `getInstancesOfType` and `createInstance`
|
||||
- `types\nope\nopeInstanceManager.interface`: Fixed the typing of `getInstancesOfType` and `createInstance`
|
||||
|
||||
# 1.3.7
|
||||
- Fixes:
|
||||
- `helpers/mapMethods`: Fixing `tranformMap`. Now correctly assigning `onlyValidProps`
|
||||
- `helpers\mapMethods`: Fixing `tranformMap`. Now correctly assigning `onlyValidProps`
|
||||
|
||||
# 1.3.8
|
||||
- Modified:
|
||||
- `helpers/limit`: Now providing an logger level in the options, results in creating a logger and logging the desired messages in the provided level.
|
||||
- `helpers\limit`: Now providing an logger level in the options, results in creating a logger and logging the desired messages in the provided level.
|
||||
|
||||
# 1.3.9
|
||||
- Fixing:
|
||||
- `helpers/limit`: Now enrows all functions provided.
|
||||
- `helpers\limit`: Now enrows all functions provided.
|
||||
|
||||
# 1.3.10
|
||||
- Modified:
|
||||
- `helpers/limit`: Adding parameter `assignControlFunction` to assing the controll function.
|
||||
- `helpers/index`: modified the export of the `limit` stuff.
|
||||
- `helpers\limit`: Adding parameter `assignControlFunction` to assing the controll function.
|
||||
- `helpers\index`: modified the export of the `limit` stuff.
|
||||
- Added:
|
||||
- `helpers/functionMethods*`: Added helpers for functions
|
||||
- `helpers\functionMethods*`: Added helpers for functions
|
||||
|
||||
# 1.3.11
|
||||
- Modified:
|
||||
- `helpers/functionMethods`: Adding `asnyc` detection
|
||||
- `helpers\functionMethods`: Adding `asnyc` detection
|
||||
|
||||
# 1.3.12
|
||||
- Modified:
|
||||
- `helpers/limit`: added the option `minDelay`. If provided, the calles are ensured to be delayed with this options. If `0` or smaller -> no delay is added.
|
||||
- `helpers\limit`: added the option `minDelay`. If provided, the calles are ensured to be delayed with this options. If `0` or smaller -> no delay is added.
|
||||
|
||||
# 1.3.13
|
||||
- Fixes:
|
||||
- `cli/runNopeBackend`: Fixing parameter `preventVarifiedNames` no works correctly.
|
||||
- `cli\runNopeBackend`: Fixing parameter `preventVarifiedNames` no works correctly.
|
||||
|
||||
# 1.3.14
|
||||
- Fixes:
|
||||
- `helpers/ui/helpers.nodejs`: Adding the option `upload-ui`
|
||||
- `helpers/ui/helpers.nodejs`: Adding the option `upload-ui`
|
||||
- `helpers\ui\helpers.nodejs`: Adding the option `upload-ui`
|
||||
- `helpers\ui\helpers.nodejs`: Adding the option `upload-ui`
|
||||
|
||||
# 1.4.0
|
||||
- Modified:
|
||||
@ -248,8 +248,8 @@ Inital commit, which is working with the browser
|
||||
- Adapted ui-defintion of functions:
|
||||
- `autoGenBySchema` Helper to enable auto generating a configuration
|
||||
- `requiresProviderForRendering` Flag to indicate, that rendering the service configuration requires a provider itself. This for instance is the case, if some needs to be called.
|
||||
- `types/ui/editor/IServiceEditPage.ts`: Asnycify the Calls
|
||||
- `types/ui/editor/render.callbacks.ts`: Asnycify the Calls
|
||||
- `types\ui\editor\IServiceEditPage.ts`: Asnycify the Calls
|
||||
- `types\ui\editor\render.callbacks.ts`: Asnycify the Calls
|
||||
|
||||
# 1.4.1
|
||||
- Modified:
|
||||
@ -284,7 +284,7 @@ Inital commit, which is working with the browser
|
||||
- Modified:
|
||||
- Adapted the event-names of the communication. Now starts with lower chars.
|
||||
- Code clean ups:
|
||||
- removed `_communcatorCallback` from `dispatcher/RpcManager/NopeRpcManager.ts`
|
||||
- removed `_communcatorCallback` from `dispatcher\RpcManager\NopeRpcManager.ts`
|
||||
- renamed `quite` to `quiet`
|
||||
- adapted internal methods of `NopeRpcManager`:
|
||||
- added: `_cancelHelper`
|
||||
@ -292,7 +292,7 @@ Inital commit, which is working with the browser
|
||||
- renamed `_partialMatchingUpdate` to `_updatePartialMatching`
|
||||
- adapted `NopePubSub`:
|
||||
- renamed parameter `mqttBasedPatternSubscriptions` to `mqttPatternBasedSubscriptions`
|
||||
- `helpers/path` -> in `_getLeastCommonPathSegment` we only iterate over the avaible keys.
|
||||
- `helpers\path` -> in `_getLeastCommonPathSegment` we only iterate over the avaible keys.
|
||||
|
||||
# 1.4.4
|
||||
- Modified:
|
||||
@ -312,5 +312,18 @@ Inital commit, which is working with the browser
|
||||
- Added:
|
||||
- `NopeModule`: Added the method `listEvents` (to show the available Emitters registered as Properties.)
|
||||
|
||||
# 1.4.5
|
||||
- Modified:
|
||||
- `lib\dispatcher\ConnectivityManager\ConnectivityManager.ts`:
|
||||
- Status is only send if required (if no other item)
|
||||
- Dispatcher Health is only checked if required.
|
||||
- `lib\dispatcher\InstanceManager\InstanceManager.ts`:
|
||||
- Made: `getServiceName` public
|
||||
- `lib/dispatcher/RpcManager/NopeRpcManager.ts`:
|
||||
- The following functions are now async:
|
||||
- `_sendAvailableServices` -> it is awaited in some functions now (hasnt before)
|
||||
- `unregisterService` -> now returns a boolean for sucess
|
||||
- Added:
|
||||
- `lib\demo\instances`: Added demo elements. (Instances.)
|
||||
|
||||
|
@ -1 +1 @@
|
||||
1.4.3
|
||||
1.4.5
|
161
lib/demo/instances/DecoratedHelloWorld.ts
Normal file
161
lib/demo/instances/DecoratedHelloWorld.ts
Normal file
@ -0,0 +1,161 @@
|
||||
import { injectable } from "inversify";
|
||||
import { InjectableNopeBaseModule } from "../../module";
|
||||
import { NopeObservable } from "../../observables";
|
||||
import { NopePromise } from "../../promise";
|
||||
import { IHelloWorlModule } from "./IHellWorldModule";
|
||||
import { nopeMethod, nopeProperty } from "../../decorators";
|
||||
import { getNopeLogger, ILogger } from "../../logger/index.browser";
|
||||
|
||||
@injectable()
|
||||
export class HelloWorldModuleWithDecorators
|
||||
extends InjectableNopeBaseModule
|
||||
implements IHelloWorlModule
|
||||
{
|
||||
@nopeProperty({
|
||||
mode: ["publish"],
|
||||
topic: "testProp",
|
||||
schema: {},
|
||||
})
|
||||
public testProp = new NopeObservable<string>();
|
||||
|
||||
@nopeProperty({
|
||||
mode: ["publish"],
|
||||
topic: "currentTime",
|
||||
schema: {
|
||||
type: "string",
|
||||
},
|
||||
})
|
||||
public currentTime = new NopeObservable<string>();
|
||||
|
||||
/**
|
||||
* Custom Function
|
||||
*
|
||||
* @param {string} greetingsTo
|
||||
* @return {*}
|
||||
* @memberof TestModule
|
||||
*/
|
||||
@nopeMethod({
|
||||
schema: {
|
||||
type: "function",
|
||||
inputs: [
|
||||
{
|
||||
name: "greetingsTo",
|
||||
schema: {
|
||||
type: "string",
|
||||
description: "Name who should be greeted.",
|
||||
},
|
||||
},
|
||||
],
|
||||
outputs: {
|
||||
type: "string",
|
||||
description: "The Greeting",
|
||||
},
|
||||
},
|
||||
})
|
||||
async helloWorld(greetingsTo: string) {
|
||||
return "Hello " + greetingsTo + "! Greetings from " + this.identifier;
|
||||
}
|
||||
|
||||
_logger: ILogger;
|
||||
|
||||
/**
|
||||
* Test Function to Update the Property.
|
||||
*
|
||||
* @memberof HelloWorldModuleWithDecorator
|
||||
*/
|
||||
@nopeMethod({
|
||||
schema: {
|
||||
type: "function",
|
||||
inputs: [],
|
||||
outputs: {
|
||||
type: "null",
|
||||
},
|
||||
},
|
||||
})
|
||||
async updateTestProp() {
|
||||
this.testProp.setContent("Internally Updated using updateTestProp()");
|
||||
}
|
||||
|
||||
/**
|
||||
* Function which will delay the Execution.
|
||||
*
|
||||
* @param {number} n
|
||||
* @return {*}
|
||||
* @memberof HelloWorldModuleWithDecorator
|
||||
*/
|
||||
@nopeMethod({
|
||||
schema: {
|
||||
type: "function",
|
||||
inputs: [
|
||||
{
|
||||
name: "amount",
|
||||
schema: {
|
||||
type: "number",
|
||||
},
|
||||
},
|
||||
],
|
||||
outputs: {
|
||||
type: "null",
|
||||
},
|
||||
},
|
||||
})
|
||||
public sleep(n: number) {
|
||||
let timer: any = null;
|
||||
const _this = this;
|
||||
return new NopePromise<void>(
|
||||
(resolve, reject) => {
|
||||
timer = setTimeout(resolve, n);
|
||||
},
|
||||
(reason) => {
|
||||
_this._logger.info("Canceling Sleep Function because of:", reason);
|
||||
if (timer != null) {
|
||||
clearTimeout(timer);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
protected _interval: any;
|
||||
|
||||
async init() {
|
||||
this._logger = getNopeLogger("HelloWorldModule");
|
||||
this._logger.info("Created by dispatcher:", this._core.id);
|
||||
|
||||
this.author = {
|
||||
forename: "Martin",
|
||||
mail: "m.karkowski@zema.de",
|
||||
surename: "karkowski",
|
||||
};
|
||||
this.description = "Test Hello World Module for Nope 2.0";
|
||||
this.version = {
|
||||
date: new Date("12.10.2020"),
|
||||
version: 1,
|
||||
};
|
||||
|
||||
await super.init();
|
||||
|
||||
// Every 1000 ms publish an update of the current time.
|
||||
this._interval = setInterval(() => {
|
||||
_this.currentTime.setContent(new Date().toISOString());
|
||||
}, 1000);
|
||||
|
||||
const _this = this;
|
||||
this.testProp.setContent("INITAL_VALUE");
|
||||
|
||||
this.testProp.subscribe((value, sender) => {
|
||||
_this._logger.info(
|
||||
_this.identifier,
|
||||
'got update for "testProp" = ',
|
||||
value,
|
||||
"from",
|
||||
sender
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
async dispose() {
|
||||
clearInterval(this._interval);
|
||||
this._logger.info("Deleting Module");
|
||||
await super.dispose();
|
||||
}
|
||||
}
|
140
lib/demo/instances/HelloWorld.ts
Normal file
140
lib/demo/instances/HelloWorld.ts
Normal file
@ -0,0 +1,140 @@
|
||||
import { injectable } from "inversify";
|
||||
import { InjectableNopeBaseModule } from "../module";
|
||||
import { NopeObservable } from "../observables";
|
||||
import { NopePromise } from "../promise";
|
||||
import { INopeObservable } from "../types";
|
||||
import { IHelloWorlModule } from "./IHellWorldModule";
|
||||
|
||||
@injectable()
|
||||
export class HelloWorldModule
|
||||
extends InjectableNopeBaseModule
|
||||
implements IHelloWorlModule
|
||||
{
|
||||
public testProp: INopeObservable<string>;
|
||||
|
||||
/**
|
||||
* Custom Function
|
||||
*
|
||||
* @param {string} greetingsTo
|
||||
* @return {*}
|
||||
* @memberof TestModule
|
||||
*/
|
||||
public async helloWorld(greetingsTo: string) {
|
||||
return "Hello " + greetingsTo + "! Greetings from " + this.identifier;
|
||||
}
|
||||
|
||||
public async updateTestProp() {
|
||||
this.testProp.setContent("Internally Updated");
|
||||
}
|
||||
|
||||
public sleep(n: number) {
|
||||
let timer: any = null;
|
||||
return new NopePromise<void>(
|
||||
(resolve, reject) => {
|
||||
timer = setTimeout(resolve, n);
|
||||
},
|
||||
(reason) => {
|
||||
console.log("Canceling Sleep Function because of:", reason);
|
||||
if (timer != null) {
|
||||
clearTimeout(timer);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public async init() {
|
||||
this.author = {
|
||||
forename: "Martin",
|
||||
mail: "m.karkowski@zema.de",
|
||||
surename: "karkowski",
|
||||
};
|
||||
this.description = "Test Hello World Module for Nope 2.0";
|
||||
this.version = {
|
||||
date: new Date("12.10.2020"),
|
||||
version: 1,
|
||||
};
|
||||
|
||||
await super.init();
|
||||
|
||||
const _this = this;
|
||||
|
||||
this.testProp = new NopeObservable();
|
||||
|
||||
this.testProp.subscribe((value, sender) => {
|
||||
console.log(
|
||||
_this.identifier,
|
||||
'got update for "testProp" = ',
|
||||
value,
|
||||
"from",
|
||||
sender
|
||||
);
|
||||
});
|
||||
|
||||
// Register the Function Manually.
|
||||
await this.registerMethod(
|
||||
"helloWorld",
|
||||
(...args) => _this.helloWorld(args[0]),
|
||||
{
|
||||
schema: {
|
||||
type: "function",
|
||||
inputs: [
|
||||
{
|
||||
name: "greetingsTo",
|
||||
schema: {
|
||||
type: "string",
|
||||
description: "Name who should be greeted.",
|
||||
},
|
||||
},
|
||||
],
|
||||
outputs: {
|
||||
type: "string",
|
||||
description: "The Greeting",
|
||||
},
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
await this.registerMethod("updateTestProp", () => _this.updateTestProp(), {
|
||||
schema: {
|
||||
type: "function",
|
||||
inputs: [],
|
||||
outputs: {
|
||||
type: "null",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
await this.registerMethod(
|
||||
"sleep",
|
||||
(amount: number) => _this.sleep(amount),
|
||||
{
|
||||
schema: {
|
||||
type: "function",
|
||||
inputs: [
|
||||
{
|
||||
name: "amount",
|
||||
schema: {
|
||||
type: "number",
|
||||
},
|
||||
},
|
||||
],
|
||||
outputs: {
|
||||
type: "null",
|
||||
},
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
await this.registerProperty("testProp", this.testProp, {
|
||||
mode: ["publish", "subscribe"],
|
||||
schema: {
|
||||
type: "string",
|
||||
},
|
||||
topic: "testProp",
|
||||
});
|
||||
}
|
||||
|
||||
public async dispose() {
|
||||
console.log("Deleting Module");
|
||||
}
|
||||
}
|
8
lib/demo/instances/IHellWorldModule.ts
Normal file
8
lib/demo/instances/IHellWorldModule.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { INopeModule, INopeObservable, IValidPromise } from "../types";
|
||||
|
||||
export interface IHelloWorlModule extends INopeModule {
|
||||
testProp: INopeObservable<string>;
|
||||
helloWorld(greetingsTo: string): IValidPromise<string>;
|
||||
updateTestProp(): IValidPromise<void>;
|
||||
sleep(n: number): IValidPromise<void>;
|
||||
}
|
@ -409,7 +409,7 @@ export class NopeConnectivityManager implements INopeConnectivityManager {
|
||||
}
|
||||
|
||||
// Say Hello by sending the Status
|
||||
_this._sendStatus();
|
||||
_this._sendStatus(true);
|
||||
}
|
||||
});
|
||||
|
||||
@ -440,6 +440,12 @@ export class NopeConnectivityManager implements INopeConnectivityManager {
|
||||
* @memberof NopeConnectivityManager
|
||||
*/
|
||||
protected _checkDispatcherHealth(): void {
|
||||
// If no other Dispatcher is present,
|
||||
// This test is Obsolete
|
||||
if (this._externalDispatchers.size <= 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
const currentTime = this.now;
|
||||
let changes = false;
|
||||
|
||||
@ -524,13 +530,17 @@ export class NopeConnectivityManager implements INopeConnectivityManager {
|
||||
* @protected
|
||||
* @memberof NopeConnectivityManager
|
||||
*/
|
||||
protected async _sendStatus(): Promise<void> {
|
||||
protected async _sendStatus(forced = false): Promise<void> {
|
||||
// Test if we are connected
|
||||
if (this._communicator.connected.getContent()) {
|
||||
try {
|
||||
const info = this.info;
|
||||
this._externalDispatchers.set(this.id, info);
|
||||
await this._communicator.emit("statusChanged", info);
|
||||
|
||||
// Only Send the Update if there are multiple Dispatchers.
|
||||
if (forced || this._externalDispatchers.size > 1) {
|
||||
await this._communicator.emit("statusChanged", info);
|
||||
}
|
||||
} catch (e) {
|
||||
this._logger.error("Failled to send the status");
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ import { expect } from "chai";
|
||||
import { beforeEach, describe, it } from "mocha";
|
||||
import "reflect-metadata";
|
||||
import { getLayer } from "../../communication/getLayer.nodejs";
|
||||
import { NopeEventEmitter } from "../../eventEmitter";
|
||||
import { INopeObserver, NopeEventEmitter } from "../../eventEmitter";
|
||||
import { NopeObservable } from "../../observables/nopeObservable";
|
||||
import { NopeCore } from "./NopeCore";
|
||||
|
||||
@ -95,11 +95,17 @@ describe("NopeCore", function () {
|
||||
});
|
||||
|
||||
it("subscribe", (done) => {
|
||||
let sub = null;
|
||||
let sub: INopeObserver = null;
|
||||
sub = remote.eventDistributor.registerSubscription<string>(
|
||||
"test",
|
||||
(data) => {
|
||||
expect(data).to.equal("test");
|
||||
|
||||
sub.unsubscribe();
|
||||
|
||||
core.dispose();
|
||||
remote.dispose();
|
||||
|
||||
done();
|
||||
}
|
||||
);
|
||||
|
@ -361,7 +361,7 @@ export class NopeInstanceManager implements INopeInstanceManager {
|
||||
* @param {"constructor" | "dispose"} type The desired type of the requested service name
|
||||
* @returns {string} the name.
|
||||
*/
|
||||
protected _getServiceName(name: string, type: "constructor" | "dispose") {
|
||||
public getServiceName(name: string, type: "constructor" | "dispose") {
|
||||
switch (type) {
|
||||
case "constructor":
|
||||
return `nope${SPLITCHAR}core${SPLITCHAR}constructor${SPLITCHAR}${name}`;
|
||||
@ -517,13 +517,13 @@ export class NopeInstanceManager implements INopeInstanceManager {
|
||||
|
||||
// Remove the Function itself
|
||||
_this._rpcManager.unregisterService(
|
||||
_this._getServiceName(data.identifier, "dispose")
|
||||
_this.getServiceName(data.identifier, "dispose")
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
id: _this._getServiceName(data.identifier, "dispose"),
|
||||
id: _this.getServiceName(data.identifier, "dispose"),
|
||||
schema: {
|
||||
description: `Service, which will destructor for the instance "${data.identifier}". This function will be called internal only.`,
|
||||
type: "function",
|
||||
@ -585,7 +585,7 @@ export class NopeInstanceManager implements INopeInstanceManager {
|
||||
},
|
||||
{
|
||||
// We will add the Name to our service.
|
||||
id: this._getServiceName(identifier, "constructor"),
|
||||
id: this.getServiceName(identifier, "constructor"),
|
||||
// We dont want to add a prefix
|
||||
addNopeServiceIdPrefix: false,
|
||||
schema: {
|
||||
@ -698,7 +698,7 @@ export class NopeInstanceManager implements INopeInstanceManager {
|
||||
|
||||
// See interface description
|
||||
public constructorExists(typeIdentifier: string): boolean {
|
||||
const ctorName = this._getServiceName(typeIdentifier, "constructor");
|
||||
const ctorName = this.getServiceName(typeIdentifier, "constructor");
|
||||
return this.constructors.data.getContent().includes(ctorName);
|
||||
}
|
||||
|
||||
@ -811,7 +811,7 @@ export class NopeInstanceManager implements INopeInstanceManager {
|
||||
const definedInstance =
|
||||
await this._rpcManager.performCall<IInstanceDescriptionMsg>(
|
||||
// Extract our Service Name:
|
||||
this._getServiceName(_description.type, "constructor"),
|
||||
this.getServiceName(_description.type, "constructor"),
|
||||
// We will use our Description as Parameter.
|
||||
[_description],
|
||||
// Additionally we share the options:
|
||||
|
@ -455,7 +455,7 @@ export class NopeRpcManager<T extends IFunctionOptions = IFunctionOptions>
|
||||
* @protected
|
||||
* @memberof nopeDispatcher
|
||||
*/
|
||||
protected _sendAvailableServices(): void {
|
||||
protected async _sendAvailableServices(): Promise<void> {
|
||||
// Define the Message
|
||||
const message: IAvailableServicesMsg = {
|
||||
dispatcher: this._id,
|
||||
@ -469,7 +469,7 @@ export class NopeRpcManager<T extends IFunctionOptions = IFunctionOptions>
|
||||
}
|
||||
|
||||
// Send the Message.
|
||||
this._communicator.emit("servicesChanged", message);
|
||||
await this._communicator.emit("servicesChanged", message);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -515,7 +515,7 @@ export class NopeRpcManager<T extends IFunctionOptions = IFunctionOptions>
|
||||
// Now we listen to unregisteredServices
|
||||
await this._communicator.on("rpcUnregister", (msg) => {
|
||||
if (_this._registeredServices.has(msg.identifier)) {
|
||||
_this._unregisterService(msg.identifier);
|
||||
_this.unregisterService(msg.identifier);
|
||||
}
|
||||
});
|
||||
|
||||
@ -725,7 +725,9 @@ export class NopeRpcManager<T extends IFunctionOptions = IFunctionOptions>
|
||||
* @return {*} {boolean} Flag, whether the element was removed (only if found) or not.
|
||||
* @memberof nopeDispatcher
|
||||
*/
|
||||
protected _unregisterService(func: ((...args) => void) | string): boolean {
|
||||
public async unregisterService(
|
||||
func: ((...args) => void) | string
|
||||
): Promise<boolean> {
|
||||
const _id =
|
||||
typeof func === "string"
|
||||
? this.options.forceUsingValidVarNames
|
||||
@ -734,14 +736,18 @@ export class NopeRpcManager<T extends IFunctionOptions = IFunctionOptions>
|
||||
: ((func as any).id as string) || "0";
|
||||
|
||||
// Publish the Available Services.
|
||||
this._sendAvailableServices();
|
||||
const promise = this._sendAvailableServices();
|
||||
|
||||
if (this._logger?.enabledFor(DEBUG)) {
|
||||
// If there is a Logger:
|
||||
this._logger.debug(`Dispatcher "${this._id}" unregistered: "${_id}"`);
|
||||
}
|
||||
|
||||
return this._registeredServices.delete(_id);
|
||||
await promise;
|
||||
|
||||
const res = this._registeredServices.delete(_id);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
public adaptServiceId(name: string) {
|
||||
@ -795,7 +801,7 @@ export class NopeRpcManager<T extends IFunctionOptions = IFunctionOptions>
|
||||
|
||||
// Define the callback.
|
||||
(_func as any).unregister = () => {
|
||||
return _this._unregisterService(_id);
|
||||
return _this.unregisterService(_id);
|
||||
};
|
||||
|
||||
// Reister the Function
|
||||
@ -815,12 +821,6 @@ export class NopeRpcManager<T extends IFunctionOptions = IFunctionOptions>
|
||||
return _func;
|
||||
}
|
||||
|
||||
public async unregisterService(
|
||||
func: string | ((...args: any[]) => any)
|
||||
): Promise<void> {
|
||||
this._unregisterService(func);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function which is used to perform a call on the remote.
|
||||
*
|
||||
@ -1064,7 +1064,7 @@ export class NopeRpcManager<T extends IFunctionOptions = IFunctionOptions>
|
||||
const toUnregister = Array.from(this._registeredServices.keys());
|
||||
|
||||
for (const id of toUnregister) {
|
||||
this._unregisterService(id);
|
||||
this.unregisterService(id);
|
||||
}
|
||||
this._registeredServices.clear();
|
||||
} else {
|
||||
|
@ -217,10 +217,10 @@ export interface INopeRpcManager<
|
||||
*
|
||||
* @author M.Karkowski
|
||||
* @param {(string | ((...args) => any))} func
|
||||
* @return {*} {Promise<void>}
|
||||
* @return {Promise<boolean>} Success of the Operation
|
||||
* @memberof INopeRpcManager
|
||||
*/
|
||||
unregisterService(func: string | ((...args) => any)): Promise<void>;
|
||||
unregisterService(func: string | ((...args) => any)): Promise<boolean>;
|
||||
|
||||
/**
|
||||
* The Method, which will perform an action.
|
||||
|
Loading…
Reference in New Issue
Block a user