58 lines
1.3 KiB
JavaScript
58 lines
1.3 KiB
JavaScript
const EventEmitter = require("events");
|
|
// Func
|
|
|
|
class OperatorStorage extends Array {
|
|
constructor () {
|
|
super();
|
|
this._indexObject = {};
|
|
this._indexObjectIndexOf = {};
|
|
}
|
|
|
|
push (item) {
|
|
if (item instanceof Operator) {
|
|
if (!this._indexObject[item.operator]) {
|
|
super.push(item);
|
|
this._indexObject[item.operator] = item;
|
|
}
|
|
}
|
|
else
|
|
throw new TypeError("Into OperatorStorage you can add only Operator's instances");
|
|
}
|
|
|
|
includes (item) {
|
|
if (item instanceof Operator) {
|
|
return this._indexObject[item.operator] !== undefined;
|
|
}
|
|
else
|
|
throw new TypeError("Into OperatorStorage storage only Operator type");
|
|
}
|
|
}
|
|
|
|
// API
|
|
|
|
class Operator {
|
|
constructor (operatorName, argvHandler = () => true, exec = (argv, module) => {}) {
|
|
this.operator = operatorName;
|
|
this.handlers = {
|
|
argv: argvHandler,
|
|
exec
|
|
};
|
|
}
|
|
}
|
|
|
|
class NetHelperModule extends EventEmitter {
|
|
constructor () {
|
|
super();
|
|
this.operators = new OperatorStorage();
|
|
|
|
this.statics = { Operator };
|
|
this.serverType = null;
|
|
}
|
|
|
|
bind (typeInstance) {
|
|
this.serverType = typeInstance;
|
|
}
|
|
}
|
|
|
|
module.exports = { NetHelperModule };
|