fixing switch-cases and arrow-functions, that they can be parsed
This commit is contained in:
parent
7f65859258
commit
46b0a49241
@ -1,4 +1,4 @@
|
||||
const { ArgumentParser } = require("argparse");
|
||||
const ArgumentParser = require("argparse").ArgumentParser;
|
||||
|
||||
const parser = new ArgumentParser({
|
||||
// version: "1.0.0",
|
||||
@ -153,4 +153,5 @@ switch (parser.parse_args().mode) {
|
||||
|
||||
default:
|
||||
logger.error("Invalid mode have been provided");
|
||||
break;
|
||||
}
|
||||
|
@ -40,11 +40,8 @@ export async function main() {
|
||||
type: "str",
|
||||
};
|
||||
|
||||
switch (args.mode) {
|
||||
default:
|
||||
case "help":
|
||||
case "none":
|
||||
console.log(`NoPE - Command Line Interface.
|
||||
const showLog = () => {
|
||||
console.log(`NoPE - Command Line Interface.
|
||||
|
||||
Please select the option you want. Therefore add one of the following options:
|
||||
\x1b[4mhelp\x1b[0m Show this help.
|
||||
@ -73,7 +70,18 @@ Have fun using NoPE :)
|
||||
|___________|
|
||||
|
||||
`);
|
||||
return;
|
||||
};
|
||||
|
||||
switch (args.mode) {
|
||||
default:
|
||||
showLog();
|
||||
break;
|
||||
case "help":
|
||||
showLog();
|
||||
break;
|
||||
case "none":
|
||||
showLog();
|
||||
break;
|
||||
case "run":
|
||||
await run([additionalArg]);
|
||||
break;
|
||||
|
@ -385,7 +385,7 @@ export class NopeConnectivityManager implements INopeConnectivityManager {
|
||||
});
|
||||
|
||||
// Wait until the Element is connected.
|
||||
await this._communicator.connected.waitFor((value) => value);
|
||||
await this._communicator.connected.waitFor();
|
||||
|
||||
await this._communicator.on("StatusChanged", (info) => {
|
||||
_this._externalDispatchers.set(info.id, info);
|
||||
|
@ -187,7 +187,7 @@ export class NopeInstanceManager implements INopeInstanceManager {
|
||||
this._rpcManager = new NopeRpcManager(
|
||||
options,
|
||||
_generateObservable,
|
||||
async () => "test",
|
||||
this._defaultSelector,
|
||||
this._id
|
||||
);
|
||||
}
|
||||
@ -226,9 +226,11 @@ export class NopeInstanceManager implements INopeInstanceManager {
|
||||
// Filter the Generators based on the existing services
|
||||
const generators = services.services
|
||||
.filter((svc) =>
|
||||
svc?.id.startsWith(
|
||||
{
|
||||
return svc?.id.startsWith(
|
||||
`nope${SPLITCHAR}core${SPLITCHAR}constructor${SPLITCHAR}`
|
||||
)
|
||||
);
|
||||
}
|
||||
)
|
||||
.map((item) => {
|
||||
return item.id;
|
||||
@ -271,9 +273,10 @@ export class NopeInstanceManager implements INopeInstanceManager {
|
||||
this._communicator.emit("InstancesChanged", {
|
||||
dispatcher: this._id,
|
||||
// We will send the descriptions.
|
||||
instances: Array.from(this._internalInstances).map((identifier) =>
|
||||
// Generate the Module Description for every identifier:
|
||||
_this._instances.get(identifier).instance.toDescription()
|
||||
instances: Array.from(this._internalInstances).map((identifier) => {
|
||||
// Generate the Module Description for every identifier:
|
||||
return _this._instances.get(identifier).instance.toDescription();
|
||||
}
|
||||
),
|
||||
});
|
||||
|
||||
@ -402,9 +405,8 @@ export class NopeInstanceManager implements INopeInstanceManager {
|
||||
.instance.toDescription();
|
||||
} else {
|
||||
// Now extract teh
|
||||
for (const {
|
||||
instances,
|
||||
} of this._mappingOfRemoteDispatchersAndInstances.values()) {
|
||||
for (const item of this._mappingOfRemoteDispatchersAndInstances.values()) {
|
||||
const instances = item.instances;
|
||||
for (const instance of instances) {
|
||||
if (instance.identifier == identifier) {
|
||||
ret.description = instance;
|
||||
@ -668,9 +670,9 @@ export class NopeInstanceManager implements INopeInstanceManager {
|
||||
// If that isnt the case, we will check all dispatchers and search the instance.
|
||||
for (const [
|
||||
dispatcher,
|
||||
{ instances },
|
||||
msg,
|
||||
] of this._mappingOfRemoteDispatchersAndInstances.entries()) {
|
||||
for (const instance of instances) {
|
||||
for (const instance of msg.instances) {
|
||||
if (instance.identifier == identifier) {
|
||||
return this._statusManager.getStatus(dispatcher);
|
||||
}
|
||||
|
@ -28,8 +28,15 @@ export function generateAssignmentChecker(
|
||||
): TValidAsssignmentChecker {
|
||||
switch (selector) {
|
||||
default:
|
||||
throw Error("Please provide an valid selector");
|
||||
case "first":
|
||||
return async () => {
|
||||
return true;
|
||||
};
|
||||
case "cpu-usage":
|
||||
return async () => {
|
||||
return true;
|
||||
};
|
||||
case "free-ram":
|
||||
return async () => {
|
||||
return true;
|
||||
|
@ -333,7 +333,9 @@ export class NopeRpcManager<T extends IFunctionOptions = IFunctionOptions>
|
||||
const args = [];
|
||||
|
||||
// First extract the basic arguments
|
||||
data.params.map((item) => (args[item.idx] = item.data));
|
||||
data.params.map((item) => {
|
||||
args[item.idx] = item.data;
|
||||
});
|
||||
|
||||
// Perform the Task it self.
|
||||
const _resultPromise = _function(...args);
|
||||
@ -343,7 +345,9 @@ export class NopeRpcManager<T extends IFunctionOptions = IFunctionOptions>
|
||||
) {
|
||||
// Push the Callback to the Result.
|
||||
cbs.push((reason) =>
|
||||
(_resultPromise as INopePromise<any>).cancel(reason)
|
||||
{
|
||||
return (_resultPromise as INopePromise<any>).cancel(reason);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@ -501,12 +505,12 @@ export class NopeRpcManager<T extends IFunctionOptions = IFunctionOptions>
|
||||
}
|
||||
});
|
||||
|
||||
await this._communicator.on("RpcRequest", (data) =>
|
||||
_this._handleExternalRequest(data)
|
||||
);
|
||||
await this._communicator.on("RpcResponse", (data) =>
|
||||
_this._handleExternalResponse(data)
|
||||
);
|
||||
await this._communicator.on("RpcRequest", (data) => {
|
||||
_this._handleExternalRequest(data);
|
||||
});
|
||||
await this._communicator.on("RpcResponse", (data) => {
|
||||
_this._handleExternalResponse(data);
|
||||
});
|
||||
|
||||
// We will listen on Cancelations.
|
||||
await this._communicator.on("TaskCancelation", (event) => {
|
||||
|
@ -28,6 +28,7 @@ export function generateSelector(
|
||||
): ValidSelectorFunction {
|
||||
switch (selector) {
|
||||
default:
|
||||
throw Error("Please use a valid selector");
|
||||
case "master":
|
||||
return async (opts) => {
|
||||
const masterId = core.connectivityManager.master.id;
|
||||
@ -79,8 +80,10 @@ export function generateSelector(
|
||||
const items = Array.from(data.get(opts.serviceName));
|
||||
const hosts = items.map(
|
||||
(id) =>
|
||||
core.connectivityManager.dispatchers.originalData.get(id)?.host
|
||||
.name
|
||||
{
|
||||
return core.connectivityManager.dispatchers.originalData.get(id)?.host
|
||||
.name;
|
||||
}
|
||||
);
|
||||
const idx = hosts.indexOf(host);
|
||||
if (idx >= 0) {
|
||||
|
@ -89,7 +89,9 @@ export class NopeDispatcher extends NopeCore implements INopeDispatcher {
|
||||
}
|
||||
|
||||
return items.filter(
|
||||
(item) => comparePatternAndPath(pattern, item).affected
|
||||
(item) =>{
|
||||
return comparePatternAndPath(pattern, item).affected;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -215,6 +215,8 @@ export class NopeEventEmitter<
|
||||
callImmediate(observer.next, value, rest);
|
||||
break;
|
||||
default:
|
||||
observer.next(value, rest as any as Partial<AD>);
|
||||
break;
|
||||
case "sync":
|
||||
observer.next(value, rest as any as Partial<AD>);
|
||||
break;
|
||||
@ -249,6 +251,8 @@ export class NopeEventEmitter<
|
||||
callImmediate(observer, value, rest);
|
||||
break;
|
||||
default:
|
||||
observer(value, rest as any as Partial<AD>);
|
||||
break;
|
||||
case "sync":
|
||||
observer(value, rest as any as Partial<AD>);
|
||||
break;
|
||||
@ -345,8 +349,10 @@ export class NopeEventEmitter<
|
||||
* @param options Additional Options for the Wait Function.
|
||||
*/
|
||||
public waitFor(
|
||||
testCallback: IWaitForCallback<G, AD> = (value) =>
|
||||
(value as any as boolean) == true,
|
||||
testCallback: IWaitForCallback<G, AD> = (value) => {
|
||||
return (value as any as boolean) == true;
|
||||
}
|
||||
,
|
||||
options: INopeWaitForObservableChangeOptions = { testCurrent: true }
|
||||
): Promise<G> {
|
||||
const _this = this;
|
||||
|
@ -175,7 +175,9 @@ export function countElements<T>(array: Array<T>): Map<T, number> {
|
||||
export function flattenDeep<T>(arrayToFlatten) {
|
||||
return arrayToFlatten.reduce(
|
||||
(acc, val) =>
|
||||
Array.isArray(val) ? acc.concat(flattenDeep(val)) : acc.concat(val),
|
||||
{
|
||||
return Array.isArray(val) ? acc.concat(flattenDeep(val)) : acc.concat(val);
|
||||
},
|
||||
[]
|
||||
) as T[];
|
||||
}
|
||||
@ -253,9 +255,9 @@ export function minOfArray<T>(
|
||||
};
|
||||
}
|
||||
|
||||
const arrOfValues = arr.map((item) =>
|
||||
rgetattr(item, path as string, defaultValue)
|
||||
) as number[];
|
||||
const arrOfValues = arr.map((item) =>{
|
||||
return rgetattr<number>(item, path as string, defaultValue);
|
||||
});
|
||||
const min = Math.min(...arrOfValues);
|
||||
return {
|
||||
min,
|
||||
@ -278,9 +280,9 @@ export function maxOfArray(
|
||||
};
|
||||
}
|
||||
|
||||
const arrOfValues = arr.map((item) =>
|
||||
rgetattr(item, path, defaultValue)
|
||||
) as number[];
|
||||
const arrOfValues = arr.map((item) =>{
|
||||
return rgetattr<number>(item, path, defaultValue);
|
||||
});
|
||||
const max = Math.max(...arrOfValues);
|
||||
return {
|
||||
max: max,
|
||||
|
@ -175,7 +175,9 @@ export function convertData<T>(
|
||||
}
|
||||
}
|
||||
|
||||
return Object.getOwnPropertyNames(helper).map((key) => helper[key]) as T[];
|
||||
return Object.getOwnPropertyNames(helper).map((key) => {
|
||||
return helper[key] as T;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -611,11 +613,10 @@ export function deepClone<T>(obj: T): T {
|
||||
return null;
|
||||
}
|
||||
const clone: any = Object.assign({}, obj);
|
||||
Object.keys(clone).forEach(
|
||||
(key) =>
|
||||
(clone[key] =
|
||||
typeof obj[key] === "object" ? deepClone(obj[key]) : obj[key])
|
||||
);
|
||||
Object.keys(clone).forEach((key) => {
|
||||
clone[key] =
|
||||
typeof obj[key] === "object" ? deepClone(obj[key]) : obj[key];
|
||||
});
|
||||
return (
|
||||
Array.isArray(obj) && obj.length
|
||||
? (clone.length = obj.length) && Array.from(clone)
|
||||
|
@ -55,7 +55,9 @@ export function padString(
|
||||
}
|
||||
|
||||
let s = num + "";
|
||||
while (s.length < _size) s = "0" + s;
|
||||
while (s.length < _size) {
|
||||
s = "0" + s;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
|
@ -465,6 +465,7 @@ export class NopeBaseModule implements INopeModule {
|
||||
_this[entry.accessor],
|
||||
entry.options as IEventOptions
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -510,8 +511,11 @@ export class NopeBaseModule implements INopeModule {
|
||||
|
||||
for (const [
|
||||
name,
|
||||
{ observable, options },
|
||||
item,
|
||||
] of this._registeredProperties.entries()) {
|
||||
|
||||
const { observable, options } = item;
|
||||
|
||||
if (observable == propOrFunc) {
|
||||
const _subTopic =
|
||||
typeof options.topic === "string"
|
||||
@ -545,8 +549,9 @@ export class NopeBaseModule implements INopeModule {
|
||||
}
|
||||
for (const [
|
||||
name,
|
||||
{ func, options },
|
||||
item,
|
||||
] of this._registeredFunctions.entries()) {
|
||||
const { func, options } = item;
|
||||
if (func == propOrFunc) {
|
||||
return options.id;
|
||||
}
|
||||
|
@ -397,7 +397,10 @@ export class PubSubSystemBase<
|
||||
// Clears all defined Matches
|
||||
this._matched.clear();
|
||||
// Iterate through all Publishers and
|
||||
for (const [emitter, { pubTopic, subTopic }] of this._emitters.entries()) {
|
||||
for (const [emitter, item] of this._emitters.entries()) {
|
||||
|
||||
const { pubTopic, subTopic } = item;
|
||||
|
||||
// Now, lets Update the Matching for the specific Topics.
|
||||
if (pubTopic) this._updateMatchingForTopic(pubTopic);
|
||||
if (subTopic)
|
||||
@ -515,7 +518,10 @@ export class PubSubSystemBase<
|
||||
_subTopic: string | false
|
||||
): void {
|
||||
// Iterate through all Publishers and
|
||||
for (const { pubTopic } of this._emitters.values()) {
|
||||
for (const item of this._emitters.values()) {
|
||||
// Extract the Pub-Topic
|
||||
const pubTopic = item.pubTopic;
|
||||
|
||||
// Now, lets Update the Matching for the specific Topics.
|
||||
if (mode === "remove" && pubTopic && _subTopic) {
|
||||
this.__deleteMatchingEntry(pubTopic, _subTopic, _emitter);
|
||||
@ -598,10 +604,10 @@ export class PubSubSystemBase<
|
||||
}
|
||||
|
||||
// Find all Matches
|
||||
for (const [emitter, { subTopic }] of this._emitters.entries()) {
|
||||
if (subTopic) {
|
||||
for (const [emitter, item] of this._emitters.entries()) {
|
||||
if (item.subTopic) {
|
||||
// Now lets determine the Path
|
||||
this.__addMatchingEntryIfRequired(topicOfChange, subTopic, emitter);
|
||||
this.__addMatchingEntryIfRequired(topicOfChange, item.subTopic, emitter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user