automatic formating
This commit is contained in:
parent
6980b0117b
commit
01b955e6f9
@ -1,55 +1,52 @@
|
||||
|
||||
import { assert } from "chai";
|
||||
import "chai/register-should";
|
||||
import { beforeEach, describe, it } from "mocha";
|
||||
import { getLayer } from "../communication/getLayer.nodejs";
|
||||
import { NopeObservable } from "../observables/nopeObservable";
|
||||
import {
|
||||
NopeRpcManager
|
||||
} from "./NopeRpcManager";
|
||||
import { NopeRpcManager } from "./NopeRpcManager";
|
||||
|
||||
describe("NopeRpcManager", function () {
|
||||
// Describe the required Test:
|
||||
let manager = new NopeRpcManager({
|
||||
let manager = new NopeRpcManager(
|
||||
{
|
||||
communicator: getLayer("event", "", "debug"),
|
||||
},
|
||||
() => new NopeObservable()
|
||||
);
|
||||
beforeEach(() => {
|
||||
// Create a new Observer
|
||||
manager = new NopeRpcManager({
|
||||
manager = new NopeRpcManager(
|
||||
{
|
||||
communicator: getLayer("event", "", "debug"),
|
||||
},
|
||||
() => new NopeObservable()
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
describe("serviceHandeling", function () {
|
||||
const helloWorld = async (greetings: string) => {
|
||||
return "Hello " + greetings + "!"
|
||||
}
|
||||
return "Hello " + greetings + "!";
|
||||
};
|
||||
|
||||
it("registering service", (done) => {
|
||||
const r = manager.registerCallback(helloWorld)
|
||||
const r = manager.registerCallback(helloWorld);
|
||||
done();
|
||||
});
|
||||
|
||||
it("call service", (done) => {
|
||||
const r = manager.registerCallback(helloWorld, {
|
||||
id: "helloworld"
|
||||
})
|
||||
id: "helloworld",
|
||||
});
|
||||
|
||||
manager.performCall("helloworld", ["Mocha"]).then(done).catch(done)
|
||||
manager.performCall("helloworld", ["Mocha"]).then(done).catch(done);
|
||||
});
|
||||
|
||||
it("call service via methodInterface", (done) => {
|
||||
const r = manager.registerCallback(helloWorld, {
|
||||
id: "helloworld"
|
||||
})
|
||||
|
||||
manager.methodInterface.helloworld("Mocha").then(done).catch(done)
|
||||
id: "helloworld",
|
||||
});
|
||||
|
||||
manager.methodInterface.helloworld("Mocha").then(done).catch(done);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -31,7 +31,7 @@ import {
|
||||
ValidSelectorFunction,
|
||||
} from "../types/nope/index";
|
||||
|
||||
import {firstItemSelector} from "./defaultSelectors"
|
||||
import { firstItemSelector } from "./defaultSelectors";
|
||||
|
||||
/**
|
||||
* A Dispatcher to perform a function on a Remote
|
||||
@ -41,7 +41,7 @@ import {firstItemSelector} from "./defaultSelectors"
|
||||
* @export
|
||||
* @class nopeDispatcher
|
||||
*/
|
||||
export class NopeRpcManager<T=any> implements INopeRpcManager {
|
||||
export class NopeRpcManager<T = any> implements INopeRpcManager {
|
||||
public readonly id: string;
|
||||
|
||||
protected _logger: ILogger;
|
||||
@ -55,7 +55,7 @@ export class NopeRpcManager<T=any> implements INopeRpcManager {
|
||||
protected _registeredCallbacks: Map<
|
||||
string,
|
||||
{
|
||||
options: T
|
||||
options: T;
|
||||
func: (...args) => Promise<any>;
|
||||
}
|
||||
>;
|
||||
@ -126,7 +126,11 @@ export class NopeRpcManager<T=any> implements INopeRpcManager {
|
||||
* @type {IMapBasedMergeData<string>}
|
||||
* @memberof INopeRpcManager
|
||||
*/
|
||||
public readonly services: IMapBasedMergeData<string, string, IAvailableServicesMsg>;
|
||||
public readonly services: IMapBasedMergeData<
|
||||
string,
|
||||
string,
|
||||
IAvailableServicesMsg
|
||||
>;
|
||||
|
||||
/**
|
||||
* An event Emitter, which will be called when a task is getting
|
||||
@ -152,7 +156,7 @@ export class NopeRpcManager<T=any> implements INopeRpcManager {
|
||||
clear: () => void;
|
||||
serviceName: string;
|
||||
timeout?: any;
|
||||
target: string
|
||||
target: string;
|
||||
}
|
||||
>;
|
||||
|
||||
@ -546,20 +550,19 @@ export class NopeRpcManager<T=any> implements INopeRpcManager {
|
||||
}
|
||||
}
|
||||
|
||||
const promises: Promise<any>[] = []
|
||||
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))
|
||||
for (const id of _tasksToCancel) {
|
||||
promises.push(this.cancelTask(id, reason));
|
||||
}
|
||||
}
|
||||
|
||||
await Promise.all(promises)
|
||||
await Promise.all(promises);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Cancels all Tasks of the given Dispatcher
|
||||
*
|
||||
@ -584,17 +587,17 @@ export class NopeRpcManager<T=any> implements INopeRpcManager {
|
||||
}
|
||||
}
|
||||
|
||||
const promises: Promise<any>[] = []
|
||||
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))
|
||||
for (const id of _tasksToCancel) {
|
||||
promises.push(this.cancelTask(id, reason));
|
||||
}
|
||||
}
|
||||
|
||||
await Promise.all(promises)
|
||||
await Promise.all(promises);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -714,7 +717,7 @@ export class NopeRpcManager<T=any> implements INopeRpcManager {
|
||||
options: {
|
||||
/** Instead of generating a uuid an id could be provided */
|
||||
id?: string;
|
||||
} & Partial<T>= {}
|
||||
} & Partial<T> = {}
|
||||
): (...args) => Promise<any> {
|
||||
const _this = this;
|
||||
// Define / Use the ID of the Function.
|
||||
@ -761,8 +764,11 @@ export class NopeRpcManager<T=any> implements INopeRpcManager {
|
||||
* @return {*} {boolean} Flag, whether the element was removed (only if found) or not.
|
||||
* @memberof nopeDispatcher
|
||||
*/
|
||||
public async unregisterCallback(func: ((...args) => void) | string): Promise<boolean> {
|
||||
const _id = typeof func === "string" ? func : ((func as any).id as string) || "0";
|
||||
public async unregisterCallback(
|
||||
func: ((...args) => void) | string
|
||||
): Promise<boolean> {
|
||||
const _id =
|
||||
typeof func === "string" ? func : ((func as any).id as string) || "0";
|
||||
|
||||
this._removeRpcSubscription(_id);
|
||||
|
||||
@ -895,11 +901,11 @@ export class NopeRpcManager<T=any> implements INopeRpcManager {
|
||||
taskId: _taskId,
|
||||
type: "requestOfTask",
|
||||
resultSink: _options.resultSink,
|
||||
targetDispatcher: ""
|
||||
targetDispatcher: "",
|
||||
};
|
||||
|
||||
if (typeof options.selector === "undefined"){
|
||||
options.selector = this.options.defaultSelector
|
||||
if (typeof options.selector === "undefined") {
|
||||
options.selector = this.options.defaultSelector;
|
||||
}
|
||||
|
||||
if (typeof options.selector === "function") {
|
||||
@ -908,10 +914,10 @@ export class NopeRpcManager<T=any> implements INopeRpcManager {
|
||||
// during handeling.
|
||||
taskRequest.targetDispatcher = await options.selector({
|
||||
rpcManager: this,
|
||||
serviceName
|
||||
serviceName,
|
||||
});
|
||||
} else {
|
||||
throw Error("A Selector must be provided.")
|
||||
throw Error("A Selector must be provided.");
|
||||
}
|
||||
|
||||
const requestedTask: any = {
|
||||
|
@ -5,10 +5,12 @@ import { ValidSelectorFunction } from "../types/nope";
|
||||
* @param options must contain the serviceName and rpcManager.
|
||||
* @returns
|
||||
*/
|
||||
export const firstItemSelector: ValidSelectorFunction = ({serviceName, rpcManager}) => {
|
||||
return rpcManager.services.originalData.get(serviceName)[0]
|
||||
}
|
||||
|
||||
export const firstItemSelector: ValidSelectorFunction = ({
|
||||
serviceName,
|
||||
rpcManager,
|
||||
}) => {
|
||||
return rpcManager.services.originalData.get(serviceName)[0];
|
||||
};
|
||||
|
||||
// export function _generateSelectorFunction(selector: ValidDefaultSelectors) {
|
||||
// const _this = this;
|
||||
|
@ -112,7 +112,7 @@ export function limitString(
|
||||
* @param maxLength
|
||||
* @returns
|
||||
*/
|
||||
export function insertNewLines(str: string, maxLength= 100){
|
||||
export function insertNewLines(str: string, maxLength = 100) {
|
||||
// now we try to split the string
|
||||
const splitted = str.split(" ");
|
||||
|
||||
@ -120,12 +120,12 @@ export function insertNewLines(str: string, maxLength= 100){
|
||||
|
||||
let length = 0;
|
||||
|
||||
for (const word of splitted){
|
||||
console.log("test")
|
||||
for (const word of splitted) {
|
||||
console.log("test");
|
||||
length += word.length + 1;
|
||||
ret.push(word);
|
||||
|
||||
if (length > maxLength){
|
||||
if (length > maxLength) {
|
||||
ret.push("\n");
|
||||
length = 0;
|
||||
}
|
||||
|
@ -752,7 +752,7 @@ export type IRequestTaskMsg = {
|
||||
/**
|
||||
* Contains the Target description.
|
||||
*/
|
||||
targetDispatcher: string
|
||||
targetDispatcher: string;
|
||||
};
|
||||
|
||||
export type ICallOptions = {
|
||||
|
@ -254,7 +254,7 @@ export type INopeDispatcherOptions = {
|
||||
* @author M.Karkowski
|
||||
* @type {ValidDefaultSelectors}
|
||||
*/
|
||||
defaultSelector?: ValidSelectorFunction
|
||||
defaultSelector?: ValidSelectorFunction;
|
||||
|
||||
/**
|
||||
* Flag to force using the service provider selector
|
||||
|
@ -8,7 +8,7 @@ import { INopeObservable } from "./nopeObservable.interface";
|
||||
* @modify date 2021-11-23 12:31:01
|
||||
* @desc [description]
|
||||
*/
|
||||
export interface IMergeData<T = any, K=any> {
|
||||
export interface IMergeData<T = any, K = any> {
|
||||
/**
|
||||
* Event Emitter, which is called on changes, with the removed and Added Items.
|
||||
*/
|
||||
@ -29,10 +29,10 @@ export interface IMergeData<T = any, K=any> {
|
||||
/**
|
||||
* The Original Data.
|
||||
*/
|
||||
originalData: K
|
||||
originalData: K;
|
||||
}
|
||||
|
||||
export interface IMapBasedMergeData<T=any, K = any, V = any>
|
||||
export interface IMapBasedMergeData<T = any, K = any, V = any>
|
||||
extends IMergeData<T, Map<K, V>> {
|
||||
/**
|
||||
* Adds a dinfition of the Amounts, of the elements.
|
||||
@ -41,7 +41,7 @@ export interface IMapBasedMergeData<T=any, K = any, V = any>
|
||||
/**
|
||||
* Simplifed Data Access.
|
||||
*/
|
||||
simplified: Map<K,T>;
|
||||
simplified: Map<K, T>;
|
||||
/**
|
||||
* A Reverse Mapping
|
||||
*/
|
||||
|
@ -15,13 +15,10 @@ import {
|
||||
import { IMapBasedMergeData } from "./nopeHelpers.interface";
|
||||
import { INopePromise } from "./nopePromise.interface";
|
||||
|
||||
export type ValidSelectorFunction = (
|
||||
options: {
|
||||
serviceName: string,
|
||||
rpcManager: INopeRpcManager,
|
||||
}
|
||||
) => Promise<string>;
|
||||
|
||||
export type ValidSelectorFunction = (options: {
|
||||
serviceName: string;
|
||||
rpcManager: INopeRpcManager;
|
||||
}) => Promise<string>;
|
||||
|
||||
/**
|
||||
* A Manager for Remote Procedure Calls.
|
||||
|
Loading…
Reference in New Issue
Block a user