updating to version 1.4.6
This commit is contained in:
parent
77630c315b
commit
97a6031d32
25
CHANGELOG.md
25
CHANGELOG.md
@ -326,4 +326,27 @@ Inital commit, which is working with the browser
|
|||||||
- Added:
|
- Added:
|
||||||
- `lib\demo\instances`: Added demo elements. (Instances.)
|
- `lib\demo\instances`: Added demo elements. (Instances.)
|
||||||
|
|
||||||
|
# 1.4.6
|
||||||
|
- Fixes:
|
||||||
|
- `lib\dispatcher\ConnectivityManager\ConnectivityManager.ts`:
|
||||||
|
- Fixing Master Assignment.
|
||||||
|
- Only sending one Status on init.
|
||||||
|
- `lib/dispatcher/InstanceManager/InstanceManager.ts`:
|
||||||
|
- Fixing pathes of `constructors` variable. Now `amountOf` etc is working
|
||||||
|
- Fixing pathes of `constructorExists`. Now working with Type-Name.
|
||||||
|
- Only sending one Status on init.
|
||||||
|
- `lib/helpers/mapMethods.ts`:
|
||||||
|
- Fixing `tranformMap` in the case of only a `pathExtractedValue` or `pathExtractedKey` is given.
|
||||||
|
- `lib/helpers/objectMethods.ts`:
|
||||||
|
- fixing `rgetattr` -> Now correctly returns "null" in all cases.
|
||||||
|
- `lib\demo`:
|
||||||
|
- Fixing imports of demo instances.
|
||||||
|
- Modified:
|
||||||
|
- `lib\types`:
|
||||||
|
- renamed `IFunctionOptions` to `IServiceOptions`
|
||||||
|
- `lib/types/nope/nopeModule.interface.ts`:
|
||||||
|
- `listMethods` now returns a different array, where the attribute is named `method` instead of `func` -> Adaptions affect `BaseModule` and `GenericModule`
|
||||||
|
- Added:
|
||||||
|
- Added Tests for the Properties of NopeRpcManager, NopeConnectivityManager
|
||||||
|
|
||||||
|
|
@ -1 +1 @@
|
|||||||
1.4.5
|
1.4.6
|
@ -9,7 +9,7 @@
|
|||||||
import { ILogger } from "js-logger";
|
import { ILogger } from "js-logger";
|
||||||
import { ISystemElements } from "../../types/ISystemElements";
|
import { ISystemElements } from "../../types/ISystemElements";
|
||||||
import {
|
import {
|
||||||
IFunctionOptions,
|
IServiceOptions,
|
||||||
IEventOptions,
|
IEventOptions,
|
||||||
} from "../../types/nope/nopeModule.interface";
|
} from "../../types/nope/nopeModule.interface";
|
||||||
import {
|
import {
|
||||||
@ -81,7 +81,7 @@ export async function extractDefinitions(
|
|||||||
name: string;
|
name: string;
|
||||||
properties: IEventOptions[];
|
properties: IEventOptions[];
|
||||||
events: IEventOptions[];
|
events: IEventOptions[];
|
||||||
methods: IFunctionOptions[];
|
methods: IServiceOptions[];
|
||||||
} = {
|
} = {
|
||||||
name: mod.className,
|
name: mod.className,
|
||||||
methods: [],
|
methods: [],
|
||||||
@ -96,17 +96,17 @@ export async function extractDefinitions(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const methodDefintion: IFunctionOptions = method.decoratorSettings[
|
const methodDefintion: IServiceOptions = method.decoratorSettings[
|
||||||
NAME_METHOD_DEC
|
NAME_METHOD_DEC
|
||||||
] as IFunctionOptions;
|
] as IServiceOptions;
|
||||||
methodDefintion.id = methodDefintion.id || method.name;
|
methodDefintion.id = methodDefintion.id || method.name;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
(method.decoratorSettings[NAME_METHOD_DEC] as IFunctionOptions)?.schema
|
(method.decoratorSettings[NAME_METHOD_DEC] as IServiceOptions)?.schema
|
||||||
) {
|
) {
|
||||||
// a schema is present => Just use the Provided Schema.
|
// a schema is present => Just use the Provided Schema.
|
||||||
methodDefintion.schema = (
|
methodDefintion.schema = (
|
||||||
method.decoratorSettings[NAME_METHOD_DEC] as IFunctionOptions
|
method.decoratorSettings[NAME_METHOD_DEC] as IServiceOptions
|
||||||
)?.schema;
|
)?.schema;
|
||||||
} else if (method.decoratorSettings[NAME_METHOD_DEC]) {
|
} else if (method.decoratorSettings[NAME_METHOD_DEC]) {
|
||||||
// Assign the Schema
|
// Assign the Schema
|
||||||
|
@ -7,14 +7,14 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { IJsonSchema } from "../../../types/IJSONSchema";
|
import { IJsonSchema } from "../../../types/IJSONSchema";
|
||||||
import { IFunctionOptions } from "../../../types/nope/nopeModule.interface";
|
import { IServiceOptions } from "../../../types/nope/nopeModule.interface";
|
||||||
import { IClassAnalyzeResult } from "./IClassAnalyzeResult";
|
import { IClassAnalyzeResult } from "./IClassAnalyzeResult";
|
||||||
import { IExportedFunctionResult } from "./IExportedFunctionResult";
|
import { IExportedFunctionResult } from "./IExportedFunctionResult";
|
||||||
|
|
||||||
export interface IAnalyzeResult {
|
export interface IAnalyzeResult {
|
||||||
classes: IClassAnalyzeResult[];
|
classes: IClassAnalyzeResult[];
|
||||||
functions: (IExportedFunctionResult & {
|
functions: (IExportedFunctionResult & {
|
||||||
decoratorSettings: IFunctionOptions;
|
decoratorSettings: IServiceOptions;
|
||||||
})[];
|
})[];
|
||||||
generalModel: IJsonSchema;
|
generalModel: IJsonSchema;
|
||||||
}
|
}
|
||||||
|
@ -5,9 +5,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { getSingleton } from "../helpers/singletonMethod";
|
import { getSingleton } from "../helpers/singletonMethod";
|
||||||
import { IFunctionOptions, INopeModule } from "../types";
|
import { IServiceOptions, INopeModule } from "../types";
|
||||||
|
|
||||||
export type IexportAsNopeServiceParameters = IFunctionOptions;
|
export type IexportAsNopeServiceParameters = IServiceOptions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the central loger. This logger is a singleton (see {@link getSingleton})
|
* Return the central loger. This logger is a singleton (see {@link getSingleton})
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
import { rgetattr, rsetattr } from "../helpers/objectMethods";
|
import { rgetattr, rsetattr } from "../helpers/objectMethods";
|
||||||
import {
|
import {
|
||||||
IEventOptions,
|
IEventOptions,
|
||||||
IFunctionOptions,
|
IServiceOptions,
|
||||||
INopeModule,
|
INopeModule,
|
||||||
} from "../types/nope/nopeModule.interface";
|
} from "../types/nope/nopeModule.interface";
|
||||||
import { getCentralDecoratedContainer } from "./container";
|
import { getCentralDecoratedContainer } from "./container";
|
||||||
@ -17,7 +17,7 @@ const CONTAINER = getCentralDecoratedContainer();
|
|||||||
* Decorator, used to export the Method as Service to Nope..
|
* Decorator, used to export the Method as Service to Nope..
|
||||||
* @param options The options used for linking.
|
* @param options The options used for linking.
|
||||||
*/
|
*/
|
||||||
export function nopeMethod(options: IFunctionOptions) {
|
export function nopeMethod(options: IServiceOptions) {
|
||||||
// Now lets make shure, we are using the correct type
|
// Now lets make shure, we are using the correct type
|
||||||
// provide inputs and outputs.
|
// provide inputs and outputs.
|
||||||
rsetattr(options, "schema/type", "function");
|
rsetattr(options, "schema/type", "function");
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { injectable } from "inversify";
|
import { injectable } from "inversify";
|
||||||
import { InjectableNopeBaseModule } from "../module";
|
import { InjectableNopeBaseModule } from "../../module";
|
||||||
import { NopeObservable } from "../observables";
|
import { NopeObservable } from "../../observables";
|
||||||
import { NopePromise } from "../promise";
|
import { NopePromise } from "../../promise";
|
||||||
import { INopeObservable } from "../types";
|
import { INopeObservable } from "../../types";
|
||||||
import { IHelloWorlModule } from "./IHellWorldModule";
|
import { IHelloWorlModule } from "./IHellWorldModule";
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { INopeModule, INopeObservable, IValidPromise } from "../types";
|
import { INopeModule, INopeObservable, IValidPromise } from "../../types";
|
||||||
|
|
||||||
export interface IHelloWorlModule extends INopeModule {
|
export interface IHelloWorlModule extends INopeModule {
|
||||||
testProp: INopeObservable<string>;
|
testProp: INopeObservable<string>;
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
/**
|
/**
|
||||||
* @author Martin Karkowski
|
* @author Martin Karkowski
|
||||||
* @email m.karkowski@zema.de
|
* @email m.karkowski@zema.de
|
||||||
* @create date 2022-01-04 10:03:41
|
|
||||||
* @modify date 2022-01-04 12:38:45
|
|
||||||
* @desc [description]
|
* @desc [description]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -196,7 +194,7 @@ describe("NopeConnectivityManager", function () {
|
|||||||
// Dispose our Delay.
|
// Dispose our Delay.
|
||||||
first.dispose(true);
|
first.dispose(true);
|
||||||
|
|
||||||
expect(end - adapted < 1).to.be.true("There should not be an delta.");
|
assert(end - adapted < 5, "There should not be an delta.");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("master", async () => {
|
it("master", async () => {
|
||||||
|
@ -331,7 +331,7 @@ export class NopeConnectivityManager implements INopeConnectivityManager {
|
|||||||
public get master(): INopeStatusInfo {
|
public get master(): INopeStatusInfo {
|
||||||
const candidates = this._getPossibleMasterCandidates();
|
const candidates = this._getPossibleMasterCandidates();
|
||||||
const masters = candidates.filter((item) => {
|
const masters = candidates.filter((item) => {
|
||||||
return item.isMaster;
|
return item.isMaster && item.isMasterForced;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (masters.length === 0) {
|
if (masters.length === 0) {
|
||||||
@ -419,15 +419,13 @@ export class NopeConnectivityManager implements INopeConnectivityManager {
|
|||||||
_this.dispatchers.update();
|
_this.dispatchers.update();
|
||||||
});
|
});
|
||||||
|
|
||||||
await this._sendStatus();
|
await this.emitBonjour();
|
||||||
|
await this._sendStatus(true);
|
||||||
|
|
||||||
if (this._logger) {
|
if (this._logger) {
|
||||||
this._logger.info("core.connectivity-manager", this.id, "initialized");
|
this._logger.info("core.connectivity-manager", this.id, "initialized");
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.emitBonjour();
|
|
||||||
await this._sendStatus();
|
|
||||||
|
|
||||||
this.ready.setContent(true);
|
this.ready.setContent(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
169
lib/dispatcher/InstanceManager/InstanceManager.spec.ts
Normal file
169
lib/dispatcher/InstanceManager/InstanceManager.spec.ts
Normal file
@ -0,0 +1,169 @@
|
|||||||
|
/**
|
||||||
|
* @author Martin Karkowski
|
||||||
|
* @email m.karkowski@zema.de
|
||||||
|
* @create date 2022-01-05 17:50:44
|
||||||
|
* @modify date 2022-01-05 17:50:44
|
||||||
|
* @desc [description]
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { expect, assert } from "chai";
|
||||||
|
import { describe, it } from "mocha";
|
||||||
|
import "reflect-metadata";
|
||||||
|
import { getLayer } from "../../communication/getLayer.nodejs";
|
||||||
|
import { NopeEventEmitter } from "../../eventEmitter";
|
||||||
|
import { sleep } from "../../helpers/async";
|
||||||
|
import { NopeBaseModule } from "../../module";
|
||||||
|
import { NopeObservable } from "../../observables/nopeObservable";
|
||||||
|
import { NopeInstanceManager } from "./InstanceManager";
|
||||||
|
|
||||||
|
describe("NopeInstanceManager", function () {
|
||||||
|
// Describe the required Test:
|
||||||
|
let manager: NopeInstanceManager;
|
||||||
|
manager = new NopeInstanceManager(
|
||||||
|
{
|
||||||
|
communicator: getLayer("event", "", false),
|
||||||
|
logger: false,
|
||||||
|
},
|
||||||
|
() => new NopeEventEmitter(),
|
||||||
|
() => new NopeObservable(),
|
||||||
|
async () => "test",
|
||||||
|
"test",
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
manager as any
|
||||||
|
);
|
||||||
|
|
||||||
|
it("registering instance", async () => {
|
||||||
|
let called = false;
|
||||||
|
let calledService = false;
|
||||||
|
|
||||||
|
class TestModule extends NopeBaseModule {
|
||||||
|
// We can not provide a service.
|
||||||
|
// @nopeMethod({
|
||||||
|
// id: "service",
|
||||||
|
// schema: {},
|
||||||
|
// })
|
||||||
|
// public async service() {
|
||||||
|
// calledService = true;
|
||||||
|
// return "called";
|
||||||
|
// }
|
||||||
|
|
||||||
|
public async dispose(): Promise<void> {
|
||||||
|
await super.dispose();
|
||||||
|
called = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async init(p1: string, p2: string): Promise<void> {
|
||||||
|
this.author = {
|
||||||
|
forename: "test",
|
||||||
|
surename: "test",
|
||||||
|
mail: "test",
|
||||||
|
};
|
||||||
|
this.version = {
|
||||||
|
date: new Date(),
|
||||||
|
version: 1,
|
||||||
|
};
|
||||||
|
this.description = "test";
|
||||||
|
|
||||||
|
assert(p1 == "p1" && p2 == "p2", "parameters where matched wrong"),
|
||||||
|
await super.init();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await manager.ready.waitFor();
|
||||||
|
|
||||||
|
// Now we register the Service
|
||||||
|
await manager.registerConstructor(
|
||||||
|
"TestModule",
|
||||||
|
async (core, identifier) => {
|
||||||
|
assert(
|
||||||
|
identifier === "instance",
|
||||||
|
"The identifier has not been transmitted"
|
||||||
|
);
|
||||||
|
return new TestModule(core);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
await sleep(10);
|
||||||
|
|
||||||
|
// Check the Constructors
|
||||||
|
const constructors = manager.constructors.extractedKey;
|
||||||
|
expect(constructors).to.include("TestModule");
|
||||||
|
assert(
|
||||||
|
manager.constructors.amountOf.get("TestModule") == 1,
|
||||||
|
"There should be one Provider for this constructor"
|
||||||
|
);
|
||||||
|
assert(
|
||||||
|
manager.constructors.keyMappingReverse.get("TestModule").size == 1,
|
||||||
|
"There should be one Provider for this constructor"
|
||||||
|
);
|
||||||
|
assert(
|
||||||
|
manager.constructors.conflicts.size == 0,
|
||||||
|
"There should be no conflict"
|
||||||
|
);
|
||||||
|
assert(
|
||||||
|
manager.constructorExists("TestModule"),
|
||||||
|
"Constructor should be known!"
|
||||||
|
);
|
||||||
|
assert(
|
||||||
|
manager.constructorExists("unkown") == false,
|
||||||
|
"Constructor should not be known!"
|
||||||
|
);
|
||||||
|
assert(
|
||||||
|
Array.from(manager.constructors.keyMappingReverse.get("TestModule"))[0] ==
|
||||||
|
"test",
|
||||||
|
"The Provider should be 'test'"
|
||||||
|
);
|
||||||
|
|
||||||
|
const instance = await manager.createInstance<TestModule>({
|
||||||
|
identifier: "instance",
|
||||||
|
type: "TestModule",
|
||||||
|
params: ["p1", "p2"],
|
||||||
|
});
|
||||||
|
|
||||||
|
assert(
|
||||||
|
manager.instanceExists("instance", false) == true,
|
||||||
|
"The instance should be known!"
|
||||||
|
);
|
||||||
|
assert(
|
||||||
|
manager.instanceExists("instance", true) == false,
|
||||||
|
"No external manager is present!"
|
||||||
|
);
|
||||||
|
assert(
|
||||||
|
manager.internalInstances.getContent().includes("instance"),
|
||||||
|
"The instance should be listed as internal instance."
|
||||||
|
);
|
||||||
|
assert(
|
||||||
|
Array.from(manager.instances.keyMappingReverse.get("instance"))[0] ==
|
||||||
|
"test",
|
||||||
|
"The Provider should be 'test'"
|
||||||
|
);
|
||||||
|
|
||||||
|
// Now test the instance wrapper
|
||||||
|
// assert(
|
||||||
|
// (await instance.service()) === "called",
|
||||||
|
// "The result should be called"
|
||||||
|
// );
|
||||||
|
// assert(calledService, "The service flag should be different now.");
|
||||||
|
assert(
|
||||||
|
(await instance.listEvents()).length === 0,
|
||||||
|
"No event has been defined"
|
||||||
|
);
|
||||||
|
assert(
|
||||||
|
(await instance.listProperties()).length === 0,
|
||||||
|
"No property has been defined"
|
||||||
|
);
|
||||||
|
assert(
|
||||||
|
(await instance.listMethods()).length === 0,
|
||||||
|
"No Method should be known"
|
||||||
|
);
|
||||||
|
assert(
|
||||||
|
Object.keys(instance.dynamicInstanceMethods).length === 0,
|
||||||
|
"No Method should be known"
|
||||||
|
);
|
||||||
|
assert(
|
||||||
|
Object.keys(instance.methods).length === 0,
|
||||||
|
"No Method should be known"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
@ -206,6 +206,7 @@ export class NopeInstanceManager implements INopeInstanceManager {
|
|||||||
this._mappingOfRemoteDispatchersAndGenerators = new Map();
|
this._mappingOfRemoteDispatchersAndGenerators = new Map();
|
||||||
this.constructors = new MapBasedMergeData(
|
this.constructors = new MapBasedMergeData(
|
||||||
this._mappingOfRemoteDispatchersAndGenerators,
|
this._mappingOfRemoteDispatchersAndGenerators,
|
||||||
|
"+",
|
||||||
"+"
|
"+"
|
||||||
) as MapBasedMergeData<string, string[], string, string>;
|
) as MapBasedMergeData<string, string[], string, string>;
|
||||||
|
|
||||||
@ -219,6 +220,8 @@ export class NopeInstanceManager implements INopeInstanceManager {
|
|||||||
this.internalInstances = new NopeObservable();
|
this.internalInstances = new NopeObservable();
|
||||||
this.internalInstances.setContent([]);
|
this.internalInstances.setContent([]);
|
||||||
|
|
||||||
|
const ctorStart = `nope${SPLITCHAR}core${SPLITCHAR}constructor${SPLITCHAR}`;
|
||||||
|
|
||||||
// We will subscribe to some generators.
|
// We will subscribe to some generators.
|
||||||
this._rpcManager.services.data.subscribe((_) => {
|
this._rpcManager.services.data.subscribe((_) => {
|
||||||
// Clear the Mapping of the Generators
|
// Clear the Mapping of the Generators
|
||||||
@ -230,12 +233,10 @@ export class NopeInstanceManager implements INopeInstanceManager {
|
|||||||
// Filter the Generators based on the existing services
|
// Filter the Generators based on the existing services
|
||||||
const generators = services.services
|
const generators = services.services
|
||||||
.filter((svc) => {
|
.filter((svc) => {
|
||||||
return svc?.id.startsWith(
|
return svc?.id.startsWith(ctorStart);
|
||||||
`nope${SPLITCHAR}core${SPLITCHAR}constructor${SPLITCHAR}`
|
|
||||||
);
|
|
||||||
})
|
})
|
||||||
.map((item) => {
|
.map((item) => {
|
||||||
return item.id;
|
return item.id.slice(ctorStart.length);
|
||||||
});
|
});
|
||||||
|
|
||||||
// If the Dispatcher has a generator we will add it.
|
// If the Dispatcher has a generator we will add it.
|
||||||
@ -479,6 +480,7 @@ export class NopeInstanceManager implements INopeInstanceManager {
|
|||||||
|
|
||||||
// Create an Instance
|
// Create an Instance
|
||||||
const _instance = await cb(_this._core, data.identifier);
|
const _instance = await cb(_this._core, data.identifier);
|
||||||
|
_instance.identifier = data.identifier;
|
||||||
|
|
||||||
// Make shure the Data is expressed as Array.
|
// Make shure the Data is expressed as Array.
|
||||||
if (!Array.isArray(data.params)) {
|
if (!Array.isArray(data.params)) {
|
||||||
@ -698,8 +700,7 @@ export class NopeInstanceManager implements INopeInstanceManager {
|
|||||||
|
|
||||||
// See interface description
|
// See interface description
|
||||||
public constructorExists(typeIdentifier: string): boolean {
|
public constructorExists(typeIdentifier: string): boolean {
|
||||||
const ctorName = this.getServiceName(typeIdentifier, "constructor");
|
return this.constructors.data.getContent().includes(typeIdentifier);
|
||||||
return this.constructors.data.getContent().includes(ctorName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// See interface description
|
// See interface description
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
* @desc [description]
|
* @desc [description]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { expect } from "chai";
|
import { expect, assert } from "chai";
|
||||||
import { beforeEach, describe, it } from "mocha";
|
import { beforeEach, describe, it } from "mocha";
|
||||||
import "reflect-metadata";
|
import "reflect-metadata";
|
||||||
import { getLayer } from "../../communication/getLayer.nodejs";
|
import { getLayer } from "../../communication/getLayer.nodejs";
|
||||||
@ -42,7 +42,7 @@ describe("NopeRpcManager", function () {
|
|||||||
manager.ready.waitFor().then(() => done());
|
manager.ready.waitFor().then(() => done());
|
||||||
});
|
});
|
||||||
|
|
||||||
const helloWorld = async (greetings: string) => {
|
const helloworld = async (greetings: string) => {
|
||||||
return "Hello " + greetings + "!";
|
return "Hello " + greetings + "!";
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -54,8 +54,8 @@ describe("NopeRpcManager", function () {
|
|||||||
it("registering service", async () => {
|
it("registering service", async () => {
|
||||||
await manager.ready.waitFor();
|
await manager.ready.waitFor();
|
||||||
// Now we register the Service
|
// Now we register the Service
|
||||||
const r = manager.registerService(helloWorld, {
|
await manager.registerService(helloworld, {
|
||||||
id: "helloWorld",
|
id: "helloworld",
|
||||||
schema: {
|
schema: {
|
||||||
description: "Hello World Service",
|
description: "Hello World Service",
|
||||||
},
|
},
|
||||||
@ -64,13 +64,36 @@ describe("NopeRpcManager", function () {
|
|||||||
await sleep(10);
|
await sleep(10);
|
||||||
// Get the Services
|
// Get the Services
|
||||||
const services = manager.services.extractedKey;
|
const services = manager.services.extractedKey;
|
||||||
expect(services).to.include("helloWorld");
|
expect(services).to.include("helloworld");
|
||||||
|
|
||||||
|
assert(
|
||||||
|
manager.services.amountOf.get("helloworld") == 1,
|
||||||
|
"There should be one Provider for this service"
|
||||||
|
);
|
||||||
|
assert(
|
||||||
|
manager.services.keyMappingReverse.get("helloworld").size == 1,
|
||||||
|
"There should be one Provider for this service"
|
||||||
|
);
|
||||||
|
assert(
|
||||||
|
manager.services.conflicts.size == 0,
|
||||||
|
"There should be no conflict"
|
||||||
|
);
|
||||||
|
assert(manager.serviceExists("helloworld"), "Service should be known!");
|
||||||
|
assert(
|
||||||
|
manager.serviceExists("helloworld2") == false,
|
||||||
|
"Service should not be known!"
|
||||||
|
);
|
||||||
|
assert(
|
||||||
|
Array.from(manager.services.keyMappingReverse.get("helloworld"))[0] ==
|
||||||
|
"test",
|
||||||
|
"The Provider should be 'test'"
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("call service", async () => {
|
it("call service", async () => {
|
||||||
await manager.ready.waitFor();
|
await manager.ready.waitFor();
|
||||||
|
|
||||||
const r = manager.registerService(helloWorld, {
|
await manager.registerService(helloworld, {
|
||||||
id: "helloworld",
|
id: "helloworld",
|
||||||
schema: {
|
schema: {
|
||||||
description: "Hello World Service",
|
description: "Hello World Service",
|
||||||
@ -86,7 +109,7 @@ describe("NopeRpcManager", function () {
|
|||||||
it("call service via methodInterface", async () => {
|
it("call service via methodInterface", async () => {
|
||||||
await manager.ready.waitFor();
|
await manager.ready.waitFor();
|
||||||
|
|
||||||
const r = manager.registerService(helloWorld, {
|
await manager.registerService(helloworld, {
|
||||||
id: "helloworld",
|
id: "helloworld",
|
||||||
schema: {
|
schema: {
|
||||||
description: "Hello World Service",
|
description: "Hello World Service",
|
||||||
@ -102,7 +125,7 @@ describe("NopeRpcManager", function () {
|
|||||||
it("call service with a timeout", async () => {
|
it("call service with a timeout", async () => {
|
||||||
await manager.ready.waitFor();
|
await manager.ready.waitFor();
|
||||||
|
|
||||||
const r = manager.registerService(delay, {
|
await manager.registerService(delay, {
|
||||||
id: "helloworld",
|
id: "helloworld",
|
||||||
schema: {
|
schema: {
|
||||||
description: "Hello World Service",
|
description: "Hello World Service",
|
||||||
@ -131,13 +154,13 @@ describe("NopeRpcManager", function () {
|
|||||||
it("multi-call", async () => {
|
it("multi-call", async () => {
|
||||||
await manager.ready.waitFor();
|
await manager.ready.waitFor();
|
||||||
|
|
||||||
manager.registerService(helloWorld, {
|
manager.registerService(helloworld, {
|
||||||
id: "helloworld_00",
|
id: "helloworld_00",
|
||||||
schema: {
|
schema: {
|
||||||
description: "Hello World Service",
|
description: "Hello World Service",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
manager.registerService(helloWorld, {
|
manager.registerService(helloworld, {
|
||||||
id: "helloworld_01",
|
id: "helloworld_01",
|
||||||
schema: {
|
schema: {
|
||||||
description: "Hello World Service",
|
description: "Hello World Service",
|
||||||
@ -163,12 +186,16 @@ describe("NopeRpcManager", function () {
|
|||||||
},
|
},
|
||||||
() => new NopeObservable(),
|
() => new NopeObservable(),
|
||||||
async () => "test",
|
async () => "test",
|
||||||
"test"
|
"caller"
|
||||||
);
|
);
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
const communicator = getLayer("event", "", false);
|
const communicator = getLayer("event", "", false);
|
||||||
|
|
||||||
|
if (manager) {
|
||||||
|
manager.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
// Create a new Observer
|
// Create a new Observer
|
||||||
manager = new NopeRpcManager(
|
manager = new NopeRpcManager(
|
||||||
{
|
{
|
||||||
@ -180,6 +207,10 @@ describe("NopeRpcManager", function () {
|
|||||||
"test"
|
"test"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (caller) {
|
||||||
|
caller.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
caller = new NopeRpcManager(
|
caller = new NopeRpcManager(
|
||||||
{
|
{
|
||||||
communicator,
|
communicator,
|
||||||
@ -187,11 +218,11 @@ describe("NopeRpcManager", function () {
|
|||||||
},
|
},
|
||||||
() => new NopeObservable(),
|
() => new NopeObservable(),
|
||||||
async () => "test",
|
async () => "test",
|
||||||
"test"
|
"caller"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
const helloWorld = async (greetings: string) => {
|
const helloworld = async (greetings: string) => {
|
||||||
return "Hello " + greetings + "!";
|
return "Hello " + greetings + "!";
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -204,8 +235,8 @@ describe("NopeRpcManager", function () {
|
|||||||
await manager.ready.waitFor();
|
await manager.ready.waitFor();
|
||||||
await caller.ready.waitFor();
|
await caller.ready.waitFor();
|
||||||
|
|
||||||
const r = manager.registerService(helloWorld, {
|
await manager.registerService(helloworld, {
|
||||||
id: "helloWorld",
|
id: "helloworld",
|
||||||
schema: {
|
schema: {
|
||||||
description: "Hello World Service",
|
description: "Hello World Service",
|
||||||
},
|
},
|
||||||
@ -215,17 +246,41 @@ describe("NopeRpcManager", function () {
|
|||||||
// Get the Services
|
// Get the Services
|
||||||
const services = caller.services.extractedKey;
|
const services = caller.services.extractedKey;
|
||||||
|
|
||||||
expect(services).to.include("helloWorld");
|
expect(caller.services.extractedKey).to.include("helloworld");
|
||||||
|
assert(
|
||||||
|
caller.services.amountOf.get("helloworld") == 1,
|
||||||
|
"There should be one Provider for this service"
|
||||||
|
);
|
||||||
|
assert(
|
||||||
|
caller.services.keyMappingReverse.get("helloworld").size == 1,
|
||||||
|
"There should be one Provider for this service"
|
||||||
|
);
|
||||||
|
assert(
|
||||||
|
caller.services.conflicts.size == 0,
|
||||||
|
"There should be no conflict"
|
||||||
|
);
|
||||||
|
assert(caller.serviceExists("helloworld"), "Service should be known!");
|
||||||
|
assert(
|
||||||
|
caller.serviceExists("helloworld2") == false,
|
||||||
|
"Service should not be known!"
|
||||||
|
);
|
||||||
|
assert(
|
||||||
|
Array.from(caller.services.keyMappingReverse.get("helloworld"))[0] ==
|
||||||
|
"test",
|
||||||
|
"The Provider should be 'test'"
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("registering service - dynamic id", async () => {
|
it("registering service - dynamic id", async () => {
|
||||||
await manager.ready.waitFor();
|
await manager.ready.waitFor();
|
||||||
await caller.ready.waitFor();
|
await caller.ready.waitFor();
|
||||||
|
|
||||||
const r = manager.registerService(helloWorld, {
|
const r = await manager.registerService(helloworld, {
|
||||||
schema: {},
|
schema: {},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
assert((r as any).id !== "helloworld", "There should be an dynamic id");
|
||||||
|
|
||||||
await sleep(10);
|
await sleep(10);
|
||||||
// Get the Services
|
// Get the Services
|
||||||
const services = caller.services.extractedKey;
|
const services = caller.services.extractedKey;
|
||||||
@ -237,7 +292,7 @@ describe("NopeRpcManager", function () {
|
|||||||
await manager.ready.waitFor();
|
await manager.ready.waitFor();
|
||||||
await caller.ready.waitFor();
|
await caller.ready.waitFor();
|
||||||
|
|
||||||
const r = manager.registerService(helloWorld, {
|
await manager.registerService(helloworld, {
|
||||||
id: "helloworld",
|
id: "helloworld",
|
||||||
schema: {
|
schema: {
|
||||||
description: "Hello World Service",
|
description: "Hello World Service",
|
||||||
@ -254,7 +309,7 @@ describe("NopeRpcManager", function () {
|
|||||||
await manager.ready.waitFor();
|
await manager.ready.waitFor();
|
||||||
await caller.ready.waitFor();
|
await caller.ready.waitFor();
|
||||||
|
|
||||||
const r = manager.registerService(helloWorld, {
|
await manager.registerService(helloworld, {
|
||||||
id: "helloworld",
|
id: "helloworld",
|
||||||
schema: {
|
schema: {
|
||||||
description: "Hello World Service",
|
description: "Hello World Service",
|
||||||
@ -271,7 +326,7 @@ describe("NopeRpcManager", function () {
|
|||||||
await manager.ready.waitFor();
|
await manager.ready.waitFor();
|
||||||
await caller.ready.waitFor();
|
await caller.ready.waitFor();
|
||||||
|
|
||||||
const r = manager.registerService(delay, {
|
await manager.registerService(delay, {
|
||||||
id: "helloworld",
|
id: "helloworld",
|
||||||
schema: {
|
schema: {
|
||||||
description: "Hello World Service",
|
description: "Hello World Service",
|
||||||
@ -296,5 +351,94 @@ describe("NopeRpcManager", function () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("providing multiple providers", async () => {
|
||||||
|
await manager.ready.waitFor();
|
||||||
|
await caller.ready.waitFor();
|
||||||
|
|
||||||
|
await manager.registerService(delay, {
|
||||||
|
id: "helloworld",
|
||||||
|
schema: {
|
||||||
|
description: "Hello World Service",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await caller.registerService(delay, {
|
||||||
|
id: "helloworld",
|
||||||
|
schema: {
|
||||||
|
description: "Hello World Service",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await sleep(10);
|
||||||
|
|
||||||
|
expect(manager.services.extractedKey).to.include("helloworld");
|
||||||
|
assert(
|
||||||
|
manager.services.amountOf.get("helloworld") == 2,
|
||||||
|
"There should be two Provider for this service"
|
||||||
|
);
|
||||||
|
assert(
|
||||||
|
manager.services.keyMappingReverse.get("helloworld").size == 2,
|
||||||
|
"There should be two Provider for this service"
|
||||||
|
);
|
||||||
|
assert(
|
||||||
|
manager.services.conflicts.size == 0,
|
||||||
|
"There should be no conflict"
|
||||||
|
);
|
||||||
|
assert(manager.serviceExists("helloworld"), "Service should be known!");
|
||||||
|
assert(
|
||||||
|
manager.serviceExists("helloworld2") == false,
|
||||||
|
"Service should not be known!"
|
||||||
|
);
|
||||||
|
|
||||||
|
let providers = Array.from(
|
||||||
|
manager.services.keyMappingReverse.get("helloworld")
|
||||||
|
);
|
||||||
|
|
||||||
|
assert(providers.includes("test"), "The Provider should be 'test'");
|
||||||
|
assert(providers.includes("caller"), "The Provider should be 'test'");
|
||||||
|
|
||||||
|
expect(caller.services.extractedKey).to.include("helloworld");
|
||||||
|
assert(
|
||||||
|
caller.services.amountOf.get("helloworld") == 2,
|
||||||
|
"There should be two Provider for this service"
|
||||||
|
);
|
||||||
|
assert(
|
||||||
|
caller.services.keyMappingReverse.get("helloworld").size == 2,
|
||||||
|
"There should be two Provider for this service"
|
||||||
|
);
|
||||||
|
assert(
|
||||||
|
caller.services.conflicts.size == 0,
|
||||||
|
"There should be no conflict"
|
||||||
|
);
|
||||||
|
assert(caller.serviceExists("helloworld"), "Service should be known!");
|
||||||
|
assert(
|
||||||
|
caller.serviceExists("helloworld2") == false,
|
||||||
|
"Service should not be known!"
|
||||||
|
);
|
||||||
|
|
||||||
|
providers = Array.from(
|
||||||
|
caller.services.keyMappingReverse.get("helloworld")
|
||||||
|
);
|
||||||
|
|
||||||
|
assert(providers.includes("test"), "The Provider should be 'test'");
|
||||||
|
assert(providers.includes("caller"), "The Provider should be 'test'");
|
||||||
|
|
||||||
|
const err = Error("Error not thrown");
|
||||||
|
|
||||||
|
try {
|
||||||
|
const result = await caller.methodInterfaceWithOptions.helloworld(
|
||||||
|
{
|
||||||
|
timeout: 50,
|
||||||
|
},
|
||||||
|
"Mocha"
|
||||||
|
);
|
||||||
|
throw err;
|
||||||
|
} catch (e) {
|
||||||
|
if (e == err) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -21,7 +21,7 @@ import {
|
|||||||
ICallOptions,
|
ICallOptions,
|
||||||
ICommunicationBridge,
|
ICommunicationBridge,
|
||||||
IExtraData,
|
IExtraData,
|
||||||
IFunctionOptions,
|
IServiceOptions,
|
||||||
IMapBasedMergeData,
|
IMapBasedMergeData,
|
||||||
INopeDispatcherOptions,
|
INopeDispatcherOptions,
|
||||||
INopeEventEmitter,
|
INopeEventEmitter,
|
||||||
@ -47,7 +47,7 @@ import {
|
|||||||
* @export
|
* @export
|
||||||
* @class nopeDispatcher
|
* @class nopeDispatcher
|
||||||
*/
|
*/
|
||||||
export class NopeRpcManager<T extends IFunctionOptions = IFunctionOptions>
|
export class NopeRpcManager<T extends IServiceOptions = IServiceOptions>
|
||||||
implements INopeRpcManager
|
implements INopeRpcManager
|
||||||
{
|
{
|
||||||
protected _logger: ILogger;
|
protected _logger: ILogger;
|
||||||
|
@ -12,7 +12,6 @@ import {
|
|||||||
SPLITCHAR,
|
SPLITCHAR,
|
||||||
} from "./objectMethods";
|
} from "./objectMethods";
|
||||||
import { getLeastCommonPathSegment } from "./path";
|
import { getLeastCommonPathSegment } from "./path";
|
||||||
import { comparePatternAndPath } from "./pathMatchingMethods";
|
|
||||||
|
|
||||||
const __sentinal = {
|
const __sentinal = {
|
||||||
unique: "value",
|
unique: "value",
|
||||||
@ -181,8 +180,8 @@ export function tranformMap<
|
|||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
const data: {
|
const data: {
|
||||||
key: ExtractedKey;
|
key: ExtractedKey[];
|
||||||
value: ExtractedValue;
|
value: ExtractedValue[];
|
||||||
} = {
|
} = {
|
||||||
key: null,
|
key: null,
|
||||||
value: null,
|
value: null,
|
||||||
@ -193,26 +192,37 @@ export function tranformMap<
|
|||||||
|
|
||||||
if (typeof pathExtractedKey === "string") {
|
if (typeof pathExtractedKey === "string") {
|
||||||
if (pathExtractedKey.length > 0) {
|
if (pathExtractedKey.length > 0) {
|
||||||
data.key = rgetattr(v, pathExtractedKey);
|
data.key = rqueryAttr<ExtractedKey>(v, pathExtractedKey).map(
|
||||||
|
(item) => item.data
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
data.key = v;
|
data.key = [v];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
data.key = k as any;
|
data.key = [k] as any;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof pathExtractedValue === "string") {
|
if (typeof pathExtractedValue === "string") {
|
||||||
if (pathExtractedValue.length > 0) {
|
if (pathExtractedValue.length > 0) {
|
||||||
data.value = rgetattr(v, pathExtractedValue);
|
data.value = rqueryAttr<ExtractedValue>(v, pathExtractedValue).map(
|
||||||
|
(item) => item.data
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
data.value = v;
|
data.value = [v];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
data.value = v as any;
|
data.value = [v] as Array<ExtractedValue>;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Manually push the items.
|
// For every key push the data.
|
||||||
extracted.push(data);
|
for (const key of data.key) {
|
||||||
|
data.value.map((item) =>
|
||||||
|
extracted.push({
|
||||||
|
key: key,
|
||||||
|
value: item,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store the Key.
|
// Store the Key.
|
||||||
|
@ -54,6 +54,10 @@ export function rgetattr<T = any>(
|
|||||||
} else {
|
} else {
|
||||||
/** Otherwise just return the Element */
|
/** Otherwise just return the Element */
|
||||||
if (_obj[_path] == null || _obj[_path] == undefined) {
|
if (_obj[_path] == null || _obj[_path] == undefined) {
|
||||||
|
if (_default == _sentinel) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return _default;
|
return _default;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,7 +111,7 @@ export function generateNopeBasicPackage(
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
providedFunctions: [],
|
providedServices: [],
|
||||||
requiredPackages: [],
|
requiredPackages: [],
|
||||||
types: TYPES,
|
types: TYPES,
|
||||||
};
|
};
|
||||||
|
@ -602,9 +602,9 @@ export class NopePackageLoader implements INopePackageLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Iterate over the provided Functions:
|
// Iterate over the provided Functions:
|
||||||
for (const func of element.providedFunctions) {
|
for (const func of element.providedServices) {
|
||||||
await this.dispatcher.rpcManager.registerService(
|
await this.dispatcher.rpcManager.registerService(
|
||||||
func.function,
|
func.service,
|
||||||
func.options
|
func.options
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ import { INopeCore, INopeEventEmitter } from "../types/nope";
|
|||||||
import {
|
import {
|
||||||
IAuthor,
|
IAuthor,
|
||||||
IEventOptions,
|
IEventOptions,
|
||||||
IFunctionOptions,
|
IServiceOptions,
|
||||||
INopeModule,
|
INopeModule,
|
||||||
INopeModuleDescription,
|
INopeModuleDescription,
|
||||||
IVersion,
|
IVersion,
|
||||||
@ -73,7 +73,7 @@ export class NopeBaseModule implements INopeModule {
|
|||||||
string,
|
string,
|
||||||
{
|
{
|
||||||
method: (...args: any[]) => Promise<any>;
|
method: (...args: any[]) => Promise<any>;
|
||||||
options: IFunctionOptions;
|
options: IServiceOptions;
|
||||||
}
|
}
|
||||||
>;
|
>;
|
||||||
|
|
||||||
@ -100,7 +100,7 @@ export class NopeBaseModule implements INopeModule {
|
|||||||
* @memberof BaseModule
|
* @memberof BaseModule
|
||||||
*/
|
*/
|
||||||
public get methods() {
|
public get methods() {
|
||||||
const ret: { [index: string]: IFunctionOptions } = {};
|
const ret: { [index: string]: IServiceOptions } = {};
|
||||||
|
|
||||||
for (const [name, funcs] of this._registeredMethods.entries()) {
|
for (const [name, funcs] of this._registeredMethods.entries()) {
|
||||||
ret[name] = funcs.options;
|
ret[name] = funcs.options;
|
||||||
@ -151,7 +151,7 @@ export class NopeBaseModule implements INopeModule {
|
|||||||
|
|
||||||
public _markedElements: Array<{
|
public _markedElements: Array<{
|
||||||
accessor: string;
|
accessor: string;
|
||||||
options: IEventOptions | IFunctionOptions;
|
options: IEventOptions | IServiceOptions;
|
||||||
type: "method" | "prop" | "event";
|
type: "method" | "prop" | "event";
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
@ -299,14 +299,14 @@ export class NopeBaseModule implements INopeModule {
|
|||||||
*
|
*
|
||||||
* @param {string} name Name of the Method, which is used during registration at the dispatcher
|
* @param {string} name Name of the Method, which is used during registration at the dispatcher
|
||||||
* @param {(...args: any[]) => Promise<any>} method The function itself. It must be async.
|
* @param {(...args: any[]) => Promise<any>} method The function itself. It must be async.
|
||||||
* @param {IFunctionOptions} options The Options, used for registering.
|
* @param {IServiceOptions} options The Options, used for registering.
|
||||||
* @return {*} {Promise<void>}
|
* @return {*} {Promise<void>}
|
||||||
* @memberof NopeBaseModule
|
* @memberof NopeBaseModule
|
||||||
*/
|
*/
|
||||||
public async registerMethod(
|
public async registerMethod(
|
||||||
name: string,
|
name: string,
|
||||||
method: (...args: any[]) => Promise<any>,
|
method: (...args: any[]) => Promise<any>,
|
||||||
options: IFunctionOptions
|
options: IServiceOptions
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
// Unregister the Function
|
// Unregister the Function
|
||||||
await this.unregisterFunction(name);
|
await this.unregisterFunction(name);
|
||||||
@ -386,12 +386,10 @@ export class NopeBaseModule implements INopeModule {
|
|||||||
/**
|
/**
|
||||||
* Function to return all available Methods.
|
* Function to return all available Methods.
|
||||||
*
|
*
|
||||||
* @return {*} {Promise<{ func: (...args: any[]) => Promise<any>; options: IFunctionOptions; }[]>}
|
* @return {*} {Promise<{ func: (...args: any[]) => Promise<any>; options: IServiceOptions; }[]>}
|
||||||
* @memberof NopeBaseModule
|
* @memberof NopeBaseModule
|
||||||
*/
|
*/
|
||||||
public async listMethods(): Promise<
|
public async listMethods() {
|
||||||
{ func: (...args: any[]) => Promise<any>; options: IFunctionOptions }[]
|
|
||||||
> {
|
|
||||||
return Array.from(this._registeredMethods.values());
|
return Array.from(this._registeredMethods.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -467,7 +465,7 @@ export class NopeBaseModule implements INopeModule {
|
|||||||
(...args) => {
|
(...args) => {
|
||||||
return _this[entry.accessor](...args);
|
return _this[entry.accessor](...args);
|
||||||
},
|
},
|
||||||
entry.options as IFunctionOptions
|
entry.options as IServiceOptions
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case "prop":
|
case "prop":
|
||||||
|
@ -8,7 +8,7 @@ import { getNopeLogger } from "../logger/getLogger";
|
|||||||
import { ICallOptions, INopeCore, INopeEventEmitter } from "../types";
|
import { ICallOptions, INopeCore, INopeEventEmitter } from "../types";
|
||||||
import {
|
import {
|
||||||
IEventOptions,
|
IEventOptions,
|
||||||
IFunctionOptions,
|
IServiceOptions,
|
||||||
INopeModuleDescription,
|
INopeModuleDescription,
|
||||||
} from "../types/nope/nopeModule.interface";
|
} from "../types/nope/nopeModule.interface";
|
||||||
import { INopeObservable } from "../types/nope/nopeObservable.interface";
|
import { INopeObservable } from "../types/nope/nopeObservable.interface";
|
||||||
@ -260,14 +260,12 @@ export class NopeGenericWrapper extends NopeBaseModule {
|
|||||||
super(_core);
|
super(_core);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async listMethods(): Promise<
|
public async listMethods() {
|
||||||
{ func: (...args: any[]) => Promise<any>; options: IFunctionOptions }[]
|
|
||||||
> {
|
|
||||||
const _this = this;
|
const _this = this;
|
||||||
return Object.getOwnPropertyNames(this.dynamicInstanceMethods).map(
|
return Object.getOwnPropertyNames(this.dynamicInstanceMethods).map(
|
||||||
(name) => {
|
(name) => {
|
||||||
return {
|
return {
|
||||||
func: _this.dynamicInstanceMethods[name],
|
method: _this.dynamicInstanceMethods[name],
|
||||||
options: null,
|
options: null,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -285,7 +283,7 @@ export class NopeGenericWrapper extends NopeBaseModule {
|
|||||||
public async registerMethod(
|
public async registerMethod(
|
||||||
name: string,
|
name: string,
|
||||||
func: (...args: any[]) => Promise<any>,
|
func: (...args: any[]) => Promise<any>,
|
||||||
options: IFunctionOptions
|
options: IServiceOptions
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
throw Error("Function Should not be called on remote!");
|
throw Error("Function Should not be called on remote!");
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ import { replaceAll } from "../../helpers/stringMethods";
|
|||||||
import { IJsonSchema } from "../../types/IJSONSchema";
|
import { IJsonSchema } from "../../types/IJSONSchema";
|
||||||
import { INopeDescriptorFunctionParameter } from "../../types/nope/nopeDescriptor.interface";
|
import { INopeDescriptorFunctionParameter } from "../../types/nope/nopeDescriptor.interface";
|
||||||
import {
|
import {
|
||||||
IFunctionOptions,
|
IServiceOptions,
|
||||||
IParsableDescription,
|
IParsableDescription,
|
||||||
} from "../../types/nope/nopeModule.interface";
|
} from "../../types/nope/nopeModule.interface";
|
||||||
|
|
||||||
@ -211,7 +211,7 @@ export async function parseModuleToOpenAPI(
|
|||||||
* @param options
|
* @param options
|
||||||
*/
|
*/
|
||||||
export async function parseFunctionToOpenAPI(
|
export async function parseFunctionToOpenAPI(
|
||||||
description: IFunctionOptions,
|
description: IServiceOptions,
|
||||||
options: {
|
options: {
|
||||||
outputDir: string;
|
outputDir: string;
|
||||||
sharedDefinitions: boolean;
|
sharedDefinitions: boolean;
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import { IJsonSchema } from "./IJSONSchema";
|
import { IJsonSchema } from "./IJSONSchema";
|
||||||
import {
|
import {
|
||||||
IFunctionOptions,
|
IServiceOptions,
|
||||||
IParsableDescription,
|
IParsableDescription,
|
||||||
} from "./nope/nopeModule.interface";
|
} from "./nope/nopeModule.interface";
|
||||||
|
|
||||||
export interface ISystemElements {
|
export interface ISystemElements {
|
||||||
modules: IParsableDescription[];
|
modules: IParsableDescription[];
|
||||||
services: IFunctionOptions[];
|
services: IServiceOptions[];
|
||||||
generalInformationModel: IJsonSchema;
|
generalInformationModel: IJsonSchema;
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
import { INopeStatusInfo } from "./nopeConnectivityManager.interface";
|
import { INopeStatusInfo } from "./nopeConnectivityManager.interface";
|
||||||
import {
|
import {
|
||||||
IFunctionOptions,
|
IServiceOptions,
|
||||||
INopeModuleDescription,
|
INopeModuleDescription,
|
||||||
} from "./nopeModule.interface";
|
} from "./nopeModule.interface";
|
||||||
import { INopeObservable } from "./nopeObservable.interface";
|
import { INopeObservable } from "./nopeObservable.interface";
|
||||||
@ -206,7 +206,7 @@ export interface IAvailableServicesMsg {
|
|||||||
*
|
*
|
||||||
* @type {string[]}
|
* @type {string[]}
|
||||||
*/
|
*/
|
||||||
services: IFunctionOptions[];
|
services: IServiceOptions[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ITaskCancelationMsg = {
|
export type ITaskCancelationMsg = {
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
* @modify date 2021-11-13 14:09:15
|
* @modify date 2021-11-13 14:09:15
|
||||||
* @desc [description]
|
* @desc [description]
|
||||||
*/
|
*/
|
||||||
import { IFunctionOptions } from ".";
|
import { IServiceOptions } from ".";
|
||||||
import {
|
import {
|
||||||
IHost,
|
IHost,
|
||||||
INopeINopeConnectivityOptions,
|
INopeINopeConnectivityOptions,
|
||||||
@ -104,7 +104,7 @@ export interface INopeDispatcherDescription extends INopeStatusInfo {
|
|||||||
/**
|
/**
|
||||||
* The hosted Services of the Dispatcher
|
* The hosted Services of the Dispatcher
|
||||||
*/
|
*/
|
||||||
services: IFunctionOptions[];
|
services: IServiceOptions[];
|
||||||
/**
|
/**
|
||||||
* Events
|
* Events
|
||||||
*/
|
*/
|
||||||
|
@ -82,10 +82,10 @@ export interface INopeModuleDescription {
|
|||||||
*
|
*
|
||||||
* > **key** = `id` of the function
|
* > **key** = `id` of the function
|
||||||
*
|
*
|
||||||
* @type {{ [index: string]: IFunctionOptions }}
|
* @type {{ [index: string]: IServiceOptions }}
|
||||||
* @memberof INopeModuleDescription
|
* @memberof INopeModuleDescription
|
||||||
*/
|
*/
|
||||||
readonly methods: { [index: string]: IFunctionOptions };
|
readonly methods: { [index: string]: IServiceOptions };
|
||||||
|
|
||||||
readonly events: { [index: string]: IEventOptions };
|
readonly events: { [index: string]: IEventOptions };
|
||||||
|
|
||||||
@ -110,15 +110,15 @@ export interface INopeModule extends INopeModuleDescription {
|
|||||||
* Function used to register a Function
|
* Function used to register a Function
|
||||||
*
|
*
|
||||||
* @param {string} name Name of the Function
|
* @param {string} name Name of the Function
|
||||||
* @param {(...args) => Promise<any>} func The Function
|
* @param {(...args) => Promise<any>} method The Function
|
||||||
* @param {IFunctionOptions} options The Options used during subscription
|
* @param {IServiceOptions} options The Options used during subscription
|
||||||
* @return {*} {Promise<void>}
|
* @return {*} {Promise<void>}
|
||||||
* @memberof IBaseModule
|
* @memberof IBaseModule
|
||||||
*/
|
*/
|
||||||
registerMethod(
|
registerMethod(
|
||||||
name: string,
|
name: string,
|
||||||
func: (...args) => Promise<any>,
|
method: (...args) => Promise<any>,
|
||||||
options: IFunctionOptions
|
options: IServiceOptions
|
||||||
): Promise<void>;
|
): Promise<void>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -162,11 +162,11 @@ export interface INopeModule extends INopeModuleDescription {
|
|||||||
* Function to list the available Functions of the module. This will hold all available functions
|
* Function to list the available Functions of the module. This will hold all available functions
|
||||||
* (dynamic and static functions).
|
* (dynamic and static functions).
|
||||||
*
|
*
|
||||||
* @return {Promise<Array<{ name: string, schema: IDescriptor, options: IFunctionOptions }>>}
|
* @return {Promise<Array<{ name: string, schema: IDescriptor, options: IServiceOptions }>>}
|
||||||
* @memberof IBaseModule
|
* @memberof IBaseModule
|
||||||
*/
|
*/
|
||||||
listMethods(): Promise<
|
listMethods(): Promise<
|
||||||
Array<{ func: (...args) => Promise<any>; options: IFunctionOptions }>
|
Array<{ method: (...args) => Promise<any>; options: IServiceOptions }>
|
||||||
>;
|
>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -207,12 +207,12 @@ export interface INopeModule extends INopeModuleDescription {
|
|||||||
* Internal Element, which is used to store elements, that should be added
|
* Internal Element, which is used to store elements, that should be added
|
||||||
* automaticallay.
|
* automaticallay.
|
||||||
*
|
*
|
||||||
* @type {(Array<{accessor: string, options:IEventOptions | IFunctionOptions}>)}
|
* @type {(Array<{accessor: string, options:IEventOptions | IServiceOptions}>)}
|
||||||
* @memberof INopeModule
|
* @memberof INopeModule
|
||||||
*/
|
*/
|
||||||
_markedElements: Array<{
|
_markedElements: Array<{
|
||||||
accessor: string;
|
accessor: string;
|
||||||
options: IEventOptions | IFunctionOptions;
|
options: IEventOptions | IServiceOptions;
|
||||||
type: "method" | "prop" | "event";
|
type: "method" | "prop" | "event";
|
||||||
}>;
|
}>;
|
||||||
}
|
}
|
||||||
@ -275,14 +275,14 @@ export interface IEventOptions {
|
|||||||
* Options, used to register a Function.
|
* Options, used to register a Function.
|
||||||
*
|
*
|
||||||
* @export
|
* @export
|
||||||
* @interface IFunctionOptions
|
* @interface IServiceOptions
|
||||||
*/
|
*/
|
||||||
export interface IFunctionOptions<T = any> extends Partial<ICallOptions> {
|
export interface IServiceOptions<T = any> extends Partial<ICallOptions> {
|
||||||
/**
|
/**
|
||||||
* Instead of generating a uuid an id could be provided
|
* Instead of generating a uuid an id could be provided
|
||||||
*
|
*
|
||||||
* @type {string}
|
* @type {string}
|
||||||
* @memberof IFunctionOptions
|
* @memberof IServiceOptions
|
||||||
*/
|
*/
|
||||||
id?: string;
|
id?: string;
|
||||||
|
|
||||||
@ -290,7 +290,7 @@ export interface IFunctionOptions<T = any> extends Partial<ICallOptions> {
|
|||||||
* Schema of the Function.
|
* Schema of the Function.
|
||||||
*
|
*
|
||||||
* @type {INopeDescriptor}
|
* @type {INopeDescriptor}
|
||||||
* @memberof IFunctionOptions
|
* @memberof IServiceOptions
|
||||||
*/
|
*/
|
||||||
schema: INopeDescriptor;
|
schema: INopeDescriptor;
|
||||||
|
|
||||||
@ -322,7 +322,7 @@ export interface IFunctionOptions<T = any> extends Partial<ICallOptions> {
|
|||||||
* Flag, to indicate, that the Item is dynamic.
|
* Flag, to indicate, that the Item is dynamic.
|
||||||
*
|
*
|
||||||
* @type {boolean}
|
* @type {boolean}
|
||||||
* @memberof IFunctionOptions
|
* @memberof IServiceOptions
|
||||||
*/
|
*/
|
||||||
isDynamic?: boolean;
|
isDynamic?: boolean;
|
||||||
}
|
}
|
||||||
@ -333,5 +333,5 @@ export interface IFunctionOptions<T = any> extends Partial<ICallOptions> {
|
|||||||
export interface IParsableDescription {
|
export interface IParsableDescription {
|
||||||
name: string;
|
name: string;
|
||||||
properties: IEventOptions[];
|
properties: IEventOptions[];
|
||||||
methods: IFunctionOptions[];
|
methods: IServiceOptions[];
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ import { interfaces } from "inversify";
|
|||||||
import { TInstanceManagerPage, TRenderInstancePage } from "../ui";
|
import { TInstanceManagerPage, TRenderInstancePage } from "../ui";
|
||||||
import { IInstanceCreationMsg } from "./nopeCommunication.interface";
|
import { IInstanceCreationMsg } from "./nopeCommunication.interface";
|
||||||
import { IValidPromise } from "./nopeDispatcher.interface";
|
import { IValidPromise } from "./nopeDispatcher.interface";
|
||||||
import { IFunctionOptions, INopeModule } from "./nopeModule.interface";
|
import { IServiceOptions, INopeModule } from "./nopeModule.interface";
|
||||||
|
|
||||||
export interface IClassDescriptor<T extends INopeModule = INopeModule> {
|
export interface IClassDescriptor<T extends INopeModule = INopeModule> {
|
||||||
/**
|
/**
|
||||||
@ -111,9 +111,9 @@ export interface IPackageDescription<
|
|||||||
*
|
*
|
||||||
* @memberof IPackageDescription
|
* @memberof IPackageDescription
|
||||||
*/
|
*/
|
||||||
providedFunctions: Array<{
|
providedServices: Array<{
|
||||||
function: (...args) => IValidPromise<any>;
|
service: (...args) => IValidPromise<any>;
|
||||||
options: IFunctionOptions;
|
options: IServiceOptions;
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
* @desc [description]
|
* @desc [description]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { IFunctionOptions, INopeEventEmitter, INopeObservable } from ".";
|
import { IServiceOptions, INopeEventEmitter, INopeObservable } from ".";
|
||||||
import {
|
import {
|
||||||
IAvailableServicesMsg,
|
IAvailableServicesMsg,
|
||||||
ICallOptions,
|
ICallOptions,
|
||||||
@ -69,9 +69,7 @@ export interface IRequestTaskWithCallback extends IRequestRpcMsg {
|
|||||||
* @export
|
* @export
|
||||||
* @interface INopeRpcManager
|
* @interface INopeRpcManager
|
||||||
*/
|
*/
|
||||||
export interface INopeRpcManager<
|
export interface INopeRpcManager<T extends IServiceOptions = IServiceOptions> {
|
||||||
T extends IFunctionOptions = IFunctionOptions
|
|
||||||
> {
|
|
||||||
/**
|
/**
|
||||||
* Flag, to show, that the System is ready
|
* Flag, to show, that the System is ready
|
||||||
*
|
*
|
||||||
@ -209,7 +207,7 @@ export interface INopeRpcManager<
|
|||||||
func: (...args) => Promise<T>,
|
func: (...args) => Promise<T>,
|
||||||
options: {
|
options: {
|
||||||
addNopeServiceIdPrefix?: boolean;
|
addNopeServiceIdPrefix?: boolean;
|
||||||
} & IFunctionOptions
|
} & IServiceOptions
|
||||||
): (...args) => Promise<T>;
|
): (...args) => Promise<T>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -9,7 +9,7 @@ import * as plotly from "plotly.js";
|
|||||||
import { IJsonSchema } from "../IJSONSchema";
|
import { IJsonSchema } from "../IJSONSchema";
|
||||||
import {
|
import {
|
||||||
IClassDescription,
|
IClassDescription,
|
||||||
IFunctionOptions,
|
IServiceOptions,
|
||||||
INopeDispatcher,
|
INopeDispatcher,
|
||||||
INopeObservable,
|
INopeObservable,
|
||||||
} from "../nope/index";
|
} from "../nope/index";
|
||||||
@ -163,7 +163,7 @@ export interface IUiDefinition {
|
|||||||
/**
|
/**
|
||||||
* The provided UI-Functions
|
* The provided UI-Functions
|
||||||
*/
|
*/
|
||||||
ui: IFunctionOptions["ui"];
|
ui: IServiceOptions["ui"];
|
||||||
/**
|
/**
|
||||||
* Original ID of the Function.
|
* Original ID of the Function.
|
||||||
*/
|
*/
|
||||||
@ -198,7 +198,7 @@ export interface IUiDefinition {
|
|||||||
* The Methods of the class
|
* The Methods of the class
|
||||||
*/
|
*/
|
||||||
methods: {
|
methods: {
|
||||||
[index: string]: IFunctionOptions["ui"];
|
[index: string]: IServiceOptions["ui"];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -9,7 +9,7 @@ import "reflect-metadata";
|
|||||||
import { createFile } from "../helpers/fileMethods";
|
import { createFile } from "../helpers/fileMethods";
|
||||||
import {
|
import {
|
||||||
getCentralDecoratedContainer,
|
getCentralDecoratedContainer,
|
||||||
IFunctionOptions,
|
IServiceOptions,
|
||||||
stringifyWithFunctions,
|
stringifyWithFunctions,
|
||||||
} from "../index.browser";
|
} from "../index.browser";
|
||||||
import { listFunctions, listPackages } from "../index.nodejs";
|
import { listFunctions, listPackages } from "../index.nodejs";
|
||||||
@ -63,10 +63,8 @@ export async function writeUiFile(
|
|||||||
CONTAINER.classes.get(cls.description.name)?._markedElements || [];
|
CONTAINER.classes.get(cls.description.name)?._markedElements || [];
|
||||||
|
|
||||||
for (const srv of services) {
|
for (const srv of services) {
|
||||||
if (srv.type === "method" && (srv.options as IFunctionOptions).ui) {
|
if (srv.type === "method" && (srv.options as IServiceOptions).ui) {
|
||||||
itemToAdd.methods[srv.accessor] = (
|
itemToAdd.methods[srv.accessor] = (srv.options as IServiceOptions).ui;
|
||||||
srv.options as IFunctionOptions
|
|
||||||
).ui;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,7 +79,7 @@ export async function writeUiFile(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Iterate over the functions and provide their uis.
|
// Iterate over the functions and provide their uis.
|
||||||
item.package.providedFunctions.map((funcs) => {
|
item.package.providedServices.map((funcs) => {
|
||||||
if (funcs.options.ui) {
|
if (funcs.options.ui) {
|
||||||
// Store the UI definition in the config file.
|
// Store the UI definition in the config file.
|
||||||
uiFile.functions[funcs.options.id] = {
|
uiFile.functions[funcs.options.id] = {
|
||||||
|
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "nope",
|
"name": "nope",
|
||||||
"version": "1.4.1",
|
"version": "1.4.5",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "nope",
|
"name": "nope",
|
||||||
"version": "1.4.1",
|
"version": "1.4.5",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"argparse": "^2.0.1",
|
"argparse": "^2.0.1",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "nope",
|
"name": "nope",
|
||||||
"version": "1.4.3",
|
"version": "1.4.5",
|
||||||
"description": "NoPE Runtime for Nodejs. For Browser-Support please use nope-browser",
|
"description": "NoPE Runtime for Nodejs. For Browser-Support please use nope-browser",
|
||||||
"files": [
|
"files": [
|
||||||
"dist-nodejs/**/*",
|
"dist-nodejs/**/*",
|
||||||
|
Loading…
Reference in New Issue
Block a user