mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-20 15:43:13 +09:00
Refactor link system to JSON serialisable class pattern
Reverse the direction of the API for sending messages from
messageDefinition.send(link, { content });
to
link.send(new MessageClass(content));
and convert all message definitions to use the JSON serialisable class
pattern and explicit registration of message handlers, along with a
end-to-end based routing of messages instead of link to link.
The experience I gained from the existing way messages were defined and
sent over links was that it was difficult to understand for people
unfamiliar with the system. The automatic registration of message
handlers ment that code was being called as if by magic from nowhere
with no easy way to discover it. The manual forwarding and rules for
what can be sent where and how obscured its working.
The use of pure JSON as both input and output from message handlers made
it tedious to work with. Data had to be manually converted between the
program representation and the over the wire format, which made handler
code unplesant to write. Particularly because the over the wire format
used snake_case while the program code uses camelCase for variables.
The idea behind the decision to do it this way was to make it more clear
which data came from the wire and which from the program, and while this
worked it didn't make message handlers any nicer to write.
The direction of the API and magic registration of message handlers also
meant that a future migration to TypeScript would be troublesome. While
it may be possible to implement, the degree of TypeScript magic required
would go starkly against the principle of keep it simple stupid.
By refactoring to using the JSON serialisable class pattern most of
these issues go away. There is no longer a need to distinguish the on
wire format of messages with the program representation because the only
place that deals with the wire format of messages are the toJSON and
fromJSON methods on the classes themselves. Message handlers will work
with proper instances of classes instead of raw data, something that
makes them easier to write, and trivial to type with TypeScript.
End-to-end routing also simplifies sending messages that need to do
mulitple hops to reach the destination. And removes the need for having
all messages be specified in plugin's info module, as they can be routed
without having to be parsed completely.
The explicit registration of message handlers is something that I
thought would be tedious boilerplate code that could be automated away.
But experience now shows it to be the opposite. Allthough dull
repetition, the purpose it serves is to link together the code in a way
that humans can easily find. With explicit registration searching the
name of the message handler in the editor will show the registration that
ties it together with the type of message it handles and the kind of
registration. With implicit registration searching the name of the
message handler turns up only the handler with no clue as to what calls
it.
This commit is contained in:
1 parent
9a967a5779
commit
bcd94709d2
106 files changed
+8173
-4928
No files matched your search
@@ -0,0 +1,32 @@
|
||||
"use strict";
|
||||
|
||||
function jsonArray(ItemClass) {
|
||||
return {
|
||||
jsonSchema: {
|
||||
type: "array",
|
||||
items: ItemClass.jsonSchema,
|
||||
},
|
||||
|
||||
fromJSON(json) {
|
||||
return json.map(i => ItemClass.fromJSON(i));
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function jsonPrimitive(type) {
|
||||
return {
|
||||
jsonSchema: { type },
|
||||
fromJSON(json) {
|
||||
return json;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
JsonBoolean: jsonPrimitive("boolean"),
|
||||
JsonNumber: jsonPrimitive("number"),
|
||||
JsonString: jsonPrimitive("string"),
|
||||
|
||||
jsonArray,
|
||||
jsonPrimitive,
|
||||
};
|
||||
@@ -7,11 +7,25 @@
|
||||
const ExportManifest = require("./ExportManifest");
|
||||
const ModInfo = require("./ModInfo");
|
||||
const ModPack = require("./ModPack");
|
||||
const composites = require("./composites");
|
||||
const messagesCore = require("./messages_core");
|
||||
const messagesController = require("./messages_controller");
|
||||
const messagesHost = require("./messages_host");
|
||||
const messagesInstance = require("./messages_instance");
|
||||
const messagesMod = require("./messages_mod");
|
||||
const messagesUser = require("./messages_user");
|
||||
const version = require("./version");
|
||||
|
||||
module.exports = {
|
||||
ExportManifest,
|
||||
ModInfo,
|
||||
ModPack,
|
||||
...composites,
|
||||
...messagesCore,
|
||||
...messagesController,
|
||||
...messagesHost,
|
||||
...messagesInstance,
|
||||
...messagesMod,
|
||||
...messagesUser,
|
||||
...version,
|
||||
};
|
||||
@@ -0,0 +1,384 @@
|
||||
"use strict";
|
||||
const { JsonString } = require("./composites");
|
||||
|
||||
// TODO: remove after config refactor
|
||||
/** @memberof module:lib/data */
|
||||
class RawConfig {
|
||||
/** @type {object} */
|
||||
serializedConfig;
|
||||
|
||||
constructor(serializedConfig) {
|
||||
this.serializedConfig = serializedConfig;
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
type: "object",
|
||||
required: ["serializedConfig"],
|
||||
properties: {
|
||||
"serializedConfig": { type: "object" },
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(json.serializedConfig);
|
||||
}
|
||||
}
|
||||
|
||||
/* @memberof module:lib/data */
|
||||
class ControllerConfigGetRequest {
|
||||
static type = "request";
|
||||
static src = "control";
|
||||
static dst = "controller";
|
||||
static permission = "core.controller.get_config";
|
||||
static Response = RawConfig;
|
||||
}
|
||||
|
||||
/** @memberof module:lib/data */
|
||||
class ControllerConfigSetFieldRequest {
|
||||
static type = "request";
|
||||
static src = "control";
|
||||
static dst = "controller";
|
||||
static permission = "core.controller.update_config";
|
||||
|
||||
/** @type {string} */
|
||||
field;
|
||||
/** @type {string} */
|
||||
value;
|
||||
|
||||
constructor(field, value) {
|
||||
this.field = field;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
type: "object",
|
||||
required: ["field", "value"],
|
||||
properties: {
|
||||
"field": { type: "string" },
|
||||
"value": { type: "string" },
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(json.field, json.value);
|
||||
}
|
||||
}
|
||||
|
||||
/* @memberof module:lib/data */
|
||||
class ControllerConfigSetPropRequest {
|
||||
static type = "request";
|
||||
static src = "control";
|
||||
static dst = "controller";
|
||||
static permission = "core.controller.update_config";
|
||||
|
||||
/** @type {string} */
|
||||
field;
|
||||
/** @type {string} */
|
||||
prop;
|
||||
/** @type {undefined} */
|
||||
value;
|
||||
|
||||
constructor(field, prop, value) {
|
||||
this.field = field;
|
||||
this.prop = prop;
|
||||
if (value) { this.value = value; }
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
type: "object",
|
||||
required: ["field", "prop"],
|
||||
properties: {
|
||||
field: { type: "string" },
|
||||
prop: { type: "string" },
|
||||
value: {},
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(json.field, json.prop, json.value);
|
||||
}
|
||||
}
|
||||
|
||||
/* @memberof module:lib/data */
|
||||
class HostGenerateTokenRequest {
|
||||
static type = "request";
|
||||
static src = "control";
|
||||
static dst = "controller";
|
||||
static permission = "core.host.generate_token";
|
||||
|
||||
/** @type {?number} */
|
||||
hostId;
|
||||
|
||||
constructor(hostId) {
|
||||
this.hostId = hostId;
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
type: "object",
|
||||
required: ["hostId"],
|
||||
properties: {
|
||||
hostId: { type: ["integer", "null"] },
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(json.hostId);
|
||||
}
|
||||
|
||||
static Response = JsonString;
|
||||
}
|
||||
|
||||
/** @memberof module:lib/data */
|
||||
class HostConfigCreateRequest {
|
||||
static type = "request";
|
||||
static src = "control";
|
||||
static dst = "controller";
|
||||
static permission = "core.host.create_config";
|
||||
|
||||
/** @type {?number} */
|
||||
id;
|
||||
/** @type {?string} */
|
||||
name;
|
||||
/** @type {boolean} */
|
||||
generateToken;
|
||||
|
||||
constructor(id, name, generateToken) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.generateToken = generateToken;
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
type: "object",
|
||||
required: ["id", "name", "generateToken"],
|
||||
properties: {
|
||||
"id": { type: ["integer", "null"] },
|
||||
"name": { type: ["string", "null"] },
|
||||
"generateToken": { type: "boolean" },
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(json.id, json.name, json.generateToken);
|
||||
}
|
||||
|
||||
static Response = RawConfig;
|
||||
}
|
||||
|
||||
/* @memberof module:lib/data */
|
||||
class LogSetSubscriptionsRequest {
|
||||
static type = "request";
|
||||
static src = "control";
|
||||
static dst = "controller";
|
||||
static permission = "core.log.follow";
|
||||
|
||||
/** @type {boolean} */
|
||||
all;
|
||||
/** @type {boolean} */
|
||||
controller;
|
||||
/** @type {array} */
|
||||
hostIds;
|
||||
/** @type {array} */
|
||||
instanceIds;
|
||||
/** @type {?string} */
|
||||
maxLevel;
|
||||
|
||||
constructor(all, controller, hostIds, instanceIds, maxLevel) {
|
||||
this.all = all;
|
||||
this.controller = controller;
|
||||
this.hostIds = hostIds;
|
||||
this.instanceIds = instanceIds;
|
||||
this.maxLevel = maxLevel;
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
type: "object",
|
||||
required: ["all", "controller", "hostIds", "instanceIds", "maxLevel"],
|
||||
properties: {
|
||||
all: { type: "boolean" },
|
||||
controller: { type: "boolean" },
|
||||
hostIds: {
|
||||
type: "array",
|
||||
items: { type: "integer" },
|
||||
},
|
||||
instanceIds: {
|
||||
type: "array",
|
||||
items: { type: "integer" },
|
||||
},
|
||||
maxLevel: { type: ["string", "null"] },
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(json.all, json.controller, json.hostIds, json.instanceIds, json.maxLevel);
|
||||
}
|
||||
}
|
||||
|
||||
/* @memberof module:lib/data */
|
||||
class LogQueryRequest {
|
||||
static type = "request";
|
||||
static src = "control";
|
||||
static dst = "controller";
|
||||
static permission = "core.log.query";
|
||||
|
||||
/** @type {boolean} */
|
||||
all;
|
||||
/** @type {boolean} */
|
||||
controller;
|
||||
/** @type {Array<number>} */
|
||||
hostIds;
|
||||
/** @type {Array<number>} */
|
||||
instanceIds;
|
||||
/** @type {?string} */
|
||||
maxLevel;
|
||||
/** @type {integer} */
|
||||
limit;
|
||||
/** @type {undefined} */
|
||||
order;
|
||||
|
||||
constructor(all, controller, hostIds, instanceIds, maxLevel, limit, order) {
|
||||
this.all = all;
|
||||
this.controller = controller;
|
||||
this.hostIds = hostIds;
|
||||
this.instanceIds = instanceIds;
|
||||
this.maxLevel = maxLevel;
|
||||
this.limit = limit;
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
type: "object",
|
||||
required: ["all", "controller", "hostIds", "instanceIds", "maxLevel", "limit", "order"],
|
||||
properties: {
|
||||
all: { type: "boolean" },
|
||||
controller: { type: "boolean" },
|
||||
hostIds: {
|
||||
type: "array",
|
||||
items: { type: "integer" },
|
||||
},
|
||||
instanceIds: {
|
||||
type: "array",
|
||||
items: { type: "integer" },
|
||||
},
|
||||
maxLevel: { type: ["string", "null"] },
|
||||
limit: { type: "integer" },
|
||||
order: {
|
||||
enum: ["asc", "desc"],
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(
|
||||
json.all, json.controller, json.hostIds, json.instanceIds, json.maxLevel, json.limit, json.order
|
||||
);
|
||||
}
|
||||
}
|
||||
LogQueryRequest.Response = class Response {
|
||||
/** @type {Array<object>} */
|
||||
log;
|
||||
|
||||
constructor(log) {
|
||||
this.log = log;
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
type: "object",
|
||||
required: ["log"],
|
||||
properties: {
|
||||
log: {
|
||||
type: "array",
|
||||
items: { type: "object" },
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(json.log);
|
||||
}
|
||||
};
|
||||
|
||||
/** @memberof module:lib/data */
|
||||
class LogMessageEvent {
|
||||
static type = "event";
|
||||
static src = "host";
|
||||
static dst = "controller";
|
||||
|
||||
/** @type {object} */
|
||||
info;
|
||||
|
||||
constructor(info) {
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
type: "object",
|
||||
required: ["info"],
|
||||
properties: {
|
||||
"info": {
|
||||
type: "object",
|
||||
required: ["level", "message"],
|
||||
properties: {
|
||||
"level": { type: "string" },
|
||||
"message": { type: "string" },
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(json.info);
|
||||
}
|
||||
}
|
||||
|
||||
/* @memberof module:lib/data */
|
||||
class DebugDumpWsRequest {
|
||||
static type = "request";
|
||||
static src = "control";
|
||||
static dst = "controller";
|
||||
static permission = "core.debug.dump_ws";
|
||||
}
|
||||
|
||||
/* @memberof module:lib/data */
|
||||
class DebugWsMessageEvent {
|
||||
static type = "event";
|
||||
static src = "controller";
|
||||
static dst = "control";
|
||||
|
||||
/** @type {string} */
|
||||
direction;
|
||||
/** @type {string} */
|
||||
content;
|
||||
|
||||
constructor(direction, content) {
|
||||
this.direction = direction;
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
type: "object",
|
||||
required: ["direction", "content"],
|
||||
properties: {
|
||||
direction: { type: "string" },
|
||||
content: { type: "string" },
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(json.direction, json.content);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
RawConfig,
|
||||
ControllerConfigGetRequest,
|
||||
ControllerConfigSetFieldRequest,
|
||||
ControllerConfigSetPropRequest,
|
||||
HostGenerateTokenRequest,
|
||||
HostConfigCreateRequest,
|
||||
LogSetSubscriptionsRequest,
|
||||
LogQueryRequest,
|
||||
LogMessageEvent,
|
||||
DebugDumpWsRequest,
|
||||
DebugWsMessageEvent,
|
||||
};
|
||||
@@ -0,0 +1,880 @@
|
||||
"use strict";
|
||||
const libSchema = require("../schema");
|
||||
|
||||
|
||||
/** @memberof module:lib/data */
|
||||
class Address {
|
||||
/** Controller address */
|
||||
static controller = 0;
|
||||
/** Instance address */
|
||||
static instance = 1;
|
||||
/** Host address */
|
||||
static host = 2;
|
||||
/** Control address */
|
||||
static control = 3;
|
||||
/** Broadcast */
|
||||
static broadcast = 4;
|
||||
|
||||
/** @type {number} */
|
||||
type;
|
||||
|
||||
/** @type {string} */
|
||||
id;
|
||||
|
||||
/** @type {string|undefined} */
|
||||
requestId;
|
||||
|
||||
constructor(type, id, requestId) {
|
||||
if (typeof type !== "number") {
|
||||
throw Error(`Invalid type ${type}`);
|
||||
}
|
||||
this.type = type;
|
||||
this.id = id;
|
||||
this.requestId = requestId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert from convenient shorthand notation to address.
|
||||
*
|
||||
* Supported notations and their corresponding address:
|
||||
* - `"controller"`: new Address(Address.controller, 0)
|
||||
* - `{ hostId: id }`: new Address(Address.host, id)
|
||||
* - `{ instanceId: id }`: new Address(Address.instance, id)
|
||||
* - `{ controlId: id }`: new Address(Address.control, id)
|
||||
* `"allHosts"`: new Address(Address.broadcast, Address.host)
|
||||
* `"allInstances"`: new Address(Address.broadcast, Address.instance)
|
||||
* `"allControls"`: new Address(Address.broadcast, Address.control)
|
||||
* @param {module:lib/data.Address|string|object} shorthand -
|
||||
* Shorthand to translate with.
|
||||
* @returns {module:lib/data.Address} Translated address.
|
||||
*/
|
||||
static fromShorthand(shorthand) {
|
||||
if (shorthand instanceof Address) { return shorthand; }
|
||||
if (shorthand === "controller") { return new Address(Address.controller, 0); }
|
||||
if (shorthand === "allHosts") { return new Address(Address.broadcast, Address.host); }
|
||||
if (shorthand === "allInstances") { return new Address(Address.broadcast, Address.instance); }
|
||||
if (shorthand === "allControls") { return new Address(Address.broadcast, Address.control); }
|
||||
let entries = Object.entries(shorthand);
|
||||
if (entries.length === 1) {
|
||||
let [name, value] = entries[0];
|
||||
if (name === "hostId") { return new Address(Address.host, value); }
|
||||
if (name === "instanceId") { return new Address(Address.instance, value); }
|
||||
if (name === "controlId") { return new Address(Address.control, value); }
|
||||
}
|
||||
throw Error("Unrecognized shorthand");
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
type: "array",
|
||||
minItems: 2,
|
||||
maxItems: 3,
|
||||
items: [
|
||||
{ type: "integer", minimum: 0, maximum: 4 },
|
||||
{ type: "integer" },
|
||||
{ type: "integer" },
|
||||
],
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(json[0], json[1], json[2]);
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
if (this.requestId !== undefined) {
|
||||
return [this.type, this.id, this.requestId];
|
||||
}
|
||||
return [this.type, this.id];
|
||||
}
|
||||
|
||||
toString() {
|
||||
const typeMap = ["controller", "instance", "host", "control"];
|
||||
const type = typeMap[this.type] || this.type;
|
||||
if (this.type === Address.broadcast) {
|
||||
return `[Address ${type}:${typeMap[this.id] || this.id}]`;
|
||||
}
|
||||
if (this.requestId === undefined) {
|
||||
return `[Address ${type}:${this.id}]`;
|
||||
}
|
||||
return `[Address ${type}:${this.id}:${this.requestId}]`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this address targets the given destination
|
||||
* @param {module:lib/Data.Address} dst - Destination to check
|
||||
* @returns {boolean} true if this address is addressed to the given destination
|
||||
*/
|
||||
addressedTo(dst) {
|
||||
if (this.type !== Address.broadcast) {
|
||||
return (
|
||||
this.type === dst.type
|
||||
&& this.id === dst.id
|
||||
);
|
||||
}
|
||||
return dst.type !== Address.broadcast && this.id === dst.type;
|
||||
}
|
||||
|
||||
equals(other) {
|
||||
return (
|
||||
this.type === other.type
|
||||
&& this.id === other.id
|
||||
&& this.requestId === other.requestId
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/** @memberof module:lib/data */
|
||||
class Message {
|
||||
/** @type {string} */
|
||||
type;
|
||||
|
||||
constructor(type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
static jsonSchema;
|
||||
static validate;
|
||||
|
||||
static fromJSON(json) {
|
||||
/* eslint-disable no-use-before-define */
|
||||
if (json.type === "hello") { return MessageHello.fromJSON(json); }
|
||||
if (json.type === "registerHost") { return MessageRegisterHost.fromJSON(json); }
|
||||
if (json.type === "registerControl") { return MessageRegisterControl.fromJSON(json); }
|
||||
if (json.type === "ready") { return MessageReady.fromJSON(json); }
|
||||
if (json.type === "resume") { return MessageResume.fromJSON(json); }
|
||||
if (json.type === "continue") { return MessageContinue.fromJSON(json); }
|
||||
if (json.type === "invalidate") { return MessageInvalidate.fromJSON(json); }
|
||||
if (json.type === "heartbeat") { return MessageHeartbeat.fromJSON(json); }
|
||||
if (json.type === "request") { return MessageRequest.fromJSON(json); }
|
||||
if (json.type === "response") { return MessageResponse.fromJSON(json); }
|
||||
if (json.type === "responseError") { return MessageResponseError.fromJSON(json); }
|
||||
if (json.type === "event") { return MessageEvent.fromJSON(json); }
|
||||
if (json.type === "disconnect") { return MessageDisconnect.fromJSON(json); }
|
||||
/* eslint-enable no-use-before-define */
|
||||
throw new Error(`Unrecognized message type ${json.type}`);
|
||||
}
|
||||
}
|
||||
|
||||
/** @memberof module:lib/data */
|
||||
class HelloData {
|
||||
/** @type {string} */
|
||||
version;
|
||||
/** @type {object} */
|
||||
plugins;
|
||||
|
||||
constructor(version, plugins) {
|
||||
this.version = version;
|
||||
this.plugins = plugins;
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
required: ["version", "plugins"],
|
||||
properties: {
|
||||
"version": { type: "string" },
|
||||
"plugins": {
|
||||
type: "object",
|
||||
additionalProperties: { type: "string" },
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(json.version, json.plugins);
|
||||
}
|
||||
}
|
||||
|
||||
/** @memberof module:lib/data */
|
||||
class MessageHello extends Message {
|
||||
/** @type {module:lib/data.HelloData} */
|
||||
data;
|
||||
|
||||
constructor(data) {
|
||||
super("hello");
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
type: "object",
|
||||
required: ["type", "data"],
|
||||
properties: {
|
||||
"type": { const: "hello" },
|
||||
"data": HelloData.jsonSchema,
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(HelloData.fromJSON(json.data));
|
||||
}
|
||||
};
|
||||
|
||||
/** @memberof module:lib/data */
|
||||
class RegisterHostData {
|
||||
/** @type {string} */
|
||||
token;
|
||||
/** @type {string} */
|
||||
agent;
|
||||
/** @type {string} */
|
||||
version;
|
||||
/** @type {string} */
|
||||
name;
|
||||
/** @type {string} */
|
||||
id;
|
||||
/** @type {string|undefined} */
|
||||
publicAddress;
|
||||
/** @type {Object<string, string>} */
|
||||
plugins;
|
||||
|
||||
constructor(token, agent, version, name, id, publicAddress, plugins) {
|
||||
this.token = token;
|
||||
this.agent = agent;
|
||||
this.version = version;
|
||||
this.name = name;
|
||||
this.id = id;
|
||||
this.publicAddress = publicAddress;
|
||||
this.plugins = plugins;
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
type: "object",
|
||||
required: ["token", "agent", "version", "name", "id", "plugins"],
|
||||
properties: {
|
||||
"token": { type: "string" },
|
||||
"agent": { type: "string" },
|
||||
"version": { type: "string" },
|
||||
"name": { type: "string" },
|
||||
"id": { type: "integer" },
|
||||
"publicAddress": { type: "string" },
|
||||
"plugins": {
|
||||
type: "object",
|
||||
additionalProperties: { type: "string" },
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(json.token, json.agent, json.version, json.name, json.id, json.publicAddress, json.plugins);
|
||||
}
|
||||
}
|
||||
|
||||
/** @memberof module:lib/data */
|
||||
class MessageRegisterHost extends Message {
|
||||
/** @type {module:lib/data.RegisterHostData} */
|
||||
data;
|
||||
|
||||
constructor(data) {
|
||||
super("registerHost");
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
type: "object",
|
||||
required: ["type", "data"],
|
||||
properties: {
|
||||
"type": { const: "registerHost" },
|
||||
"data": RegisterHostData.jsonSchema,
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(RegisterHostData.fromJSON(json.data));
|
||||
}
|
||||
};
|
||||
|
||||
/** @memberof module:lib/data */
|
||||
class RegisterControlData {
|
||||
/** @type {string} */
|
||||
token;
|
||||
/** @type {string} */
|
||||
agent;
|
||||
/** @type {string} */
|
||||
version;
|
||||
|
||||
constructor(token, agent, version) {
|
||||
this.token = token;
|
||||
this.agent = agent;
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
type: "object",
|
||||
required: ["token", "agent", "version"],
|
||||
properties: {
|
||||
"token": { type: "string" },
|
||||
"agent": { type: "string" },
|
||||
"version": { type: "string" },
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(json.token, json.agent, json.version);
|
||||
}
|
||||
}
|
||||
|
||||
/** @memberof module:lib/data */
|
||||
class MessageRegisterControl extends Message {
|
||||
/** @type {module:lib/data.RegisterControlData} */
|
||||
data;
|
||||
|
||||
constructor(data) {
|
||||
super("registerControl");
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
type: "object",
|
||||
required: ["data"],
|
||||
properties: {
|
||||
"type": { const: "registerControl" },
|
||||
"data": RegisterControlData.jsonSchema,
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(RegisterControlData.fromJSON(json.data));
|
||||
}
|
||||
};
|
||||
|
||||
/** @memberof module:lib/data */
|
||||
class AccountDetails {
|
||||
/** @type {string} */
|
||||
name;
|
||||
/** @type {Array} */
|
||||
roles;
|
||||
|
||||
constructor(name, roles) {
|
||||
this.name = name;
|
||||
this.roles = roles;
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
additionalProperties: false,
|
||||
required: ["name", "roles"],
|
||||
properties: {
|
||||
"name": { type: "string" },
|
||||
"roles": {
|
||||
type: "array",
|
||||
items: {
|
||||
additionalProperties: false,
|
||||
type: "object",
|
||||
required: ["name", "id", "permissions"],
|
||||
properties: {
|
||||
"name": { type: "string" },
|
||||
"id": { type: "integer" },
|
||||
"permissions": {
|
||||
type: "array",
|
||||
items: { type: "string" },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(json.name, json.roles);
|
||||
}
|
||||
}
|
||||
|
||||
/** @memberof module:lib/data */
|
||||
class ReadyData {
|
||||
/** @type {module:lib/data.Address} */
|
||||
src;
|
||||
/** @type {string} */
|
||||
sessionToken;
|
||||
/** @type {number} */
|
||||
sessionTimeout;
|
||||
/** @type {number} */
|
||||
heartbeatInterval;
|
||||
/** @type {AccountDetails|undefined} */
|
||||
account;
|
||||
|
||||
constructor(src, sessionToken, sessionTimeout, heartbeatInterval, account) {
|
||||
this.src = src;
|
||||
this.sessionToken = sessionToken;
|
||||
this.sessionTimeout = sessionTimeout;
|
||||
this.heartbeatInterval = heartbeatInterval;
|
||||
if (account) { this.account = account; }
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
additionalProperties: false,
|
||||
required: ["src", "sessionToken", "sessionTimeout", "heartbeatInterval"],
|
||||
properties: {
|
||||
"src": Address.jsonSchema,
|
||||
"sessionToken": { type: "string" },
|
||||
"sessionTimeout": { type: "number" },
|
||||
"heartbeatInterval": { type: "number" },
|
||||
"account": AccountDetails.jsonSchema,
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
let account;
|
||||
if (json.account) { account = AccountDetails.fromJSON(json.account); }
|
||||
return new this(
|
||||
Address.fromJSON(json.src),
|
||||
json.sessionToken,
|
||||
json.sessionTimeout,
|
||||
json.heartbeatInterval,
|
||||
account
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/** @memberof module:lib/data */
|
||||
class MessageReady extends Message {
|
||||
/** @type {module:lib/data.ReadyData} */
|
||||
data;
|
||||
|
||||
constructor(data) {
|
||||
super("ready");
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
type: "object",
|
||||
required: ["data"],
|
||||
properties: {
|
||||
"type": { const: "ready" },
|
||||
"data": ReadyData.jsonSchema,
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(ReadyData.fromJSON(json.data));
|
||||
}
|
||||
}
|
||||
|
||||
/** @memberof module:lib/data */
|
||||
class ResumeData {
|
||||
/** @type {string} */
|
||||
sessionToken;
|
||||
/** @type {integer|undefined} */
|
||||
lastSeq;
|
||||
|
||||
constructor(sessionToken, lastSeq) {
|
||||
this.sessionToken = sessionToken;
|
||||
if (lastSeq !== undefined) { this.lastSeq = lastSeq; }
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
type: "object",
|
||||
required: ["sessionToken"],
|
||||
properties: {
|
||||
"sessionToken": { type: "string" },
|
||||
"lastSeq": { type: "integer" },
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(json.sessionToken, json.lastSeq);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** @memberof module:lib/data */
|
||||
class MessageResume extends Message {
|
||||
/** @type {module:lib/data.ResumeData} */
|
||||
data;
|
||||
|
||||
constructor(data) {
|
||||
super("resume");
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
type: "object",
|
||||
required: ["data"],
|
||||
properties: {
|
||||
"type": { const: "resume" },
|
||||
"data": ResumeData.jsonSchema,
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(ResumeData.fromJSON(json.data));
|
||||
}
|
||||
}
|
||||
|
||||
/** @memberof module:lib/data */
|
||||
class ContinueData {
|
||||
/** @type {number} */
|
||||
sessionTimeout;
|
||||
/** @type {number} */
|
||||
heartbeatInterval;
|
||||
/** @type {integer|undefined} */
|
||||
lastSeq;
|
||||
|
||||
constructor(sessionTimeout, heartbeatInterval, lastSeq) {
|
||||
this.sessionTimeout = sessionTimeout;
|
||||
this.heartbeatInterval = heartbeatInterval;
|
||||
if (lastSeq !== undefined) { this.lastSeq = lastSeq; }
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
required: ["sessionTimeout", "heartbeatInterval"],
|
||||
properties: {
|
||||
"sessionTimeout": { type: "number" },
|
||||
"heartbeatInterval": { type: "number" },
|
||||
"lastSeq": { type: "integer" },
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(json.sessionTimeout, json.heartbeatInterval, json.lastSeq);
|
||||
}
|
||||
}
|
||||
|
||||
/** @memberof module:lib/data */
|
||||
class MessageContinue extends Message {
|
||||
/** @type {module:lib/data.ContinueData} */
|
||||
data;
|
||||
|
||||
constructor(data) {
|
||||
super("continue");
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
type: "object",
|
||||
required: ["data"],
|
||||
properties: {
|
||||
"type": { const: "continue" },
|
||||
"data": ContinueData.jsonSchema,
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(ContinueData.fromJSON(json.data));
|
||||
}
|
||||
}
|
||||
|
||||
/** @memberof module:lib/data */
|
||||
class MessageInvalidate extends Message {
|
||||
constructor() {
|
||||
super("invalidate");
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
type: "object",
|
||||
properties: {
|
||||
"type": { const: "invalidate" },
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this();
|
||||
}
|
||||
}
|
||||
|
||||
/** @memberof module:lib/data */
|
||||
class MessageHeartbeat extends Message {
|
||||
/** @type {integer|undefined} */
|
||||
seq;
|
||||
|
||||
constructor(seq) {
|
||||
super("heartbeat");
|
||||
this.seq = seq;
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
type: "object",
|
||||
required: ["type"],
|
||||
properties: {
|
||||
"type": { const: "heartbeat" },
|
||||
"seq": { type: "integer" },
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(json.seq);
|
||||
}
|
||||
}
|
||||
|
||||
/** @memberof module:lib/data */
|
||||
class MessageRequest extends Message {
|
||||
/** @type {number} */
|
||||
seq;
|
||||
/** @type {Address} */
|
||||
src;
|
||||
/** @type {Address} */
|
||||
dst;
|
||||
/** @type {string} */
|
||||
name;
|
||||
/** @type {*} */
|
||||
data;
|
||||
|
||||
constructor(seq, src, dst, name, data) {
|
||||
super("request");
|
||||
this.seq = seq;
|
||||
this.src = src;
|
||||
this.dst = dst;
|
||||
this.name = name;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
type: "object",
|
||||
required: ["type", "seq", "src", "dst", "name"],
|
||||
properties: {
|
||||
"type": { const: "request" },
|
||||
"seq": { type: "integer" },
|
||||
"src": Address.jsonSchema,
|
||||
"dst": Address.jsonSchema,
|
||||
"name": { type: "string" },
|
||||
"data": {},
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(
|
||||
json.seq,
|
||||
Address.fromJSON(json.src),
|
||||
Address.fromJSON(json.dst),
|
||||
json.name,
|
||||
json.data,
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
/** @memberof module:lib/data */
|
||||
class MessageResponse extends Message {
|
||||
/** @type {number} */
|
||||
seq;
|
||||
/** @type {Address} */
|
||||
src;
|
||||
/** @type {Address} */
|
||||
dst;
|
||||
/** @type {*} */
|
||||
data;
|
||||
|
||||
constructor(seq, src, dst, data) {
|
||||
super("response");
|
||||
this.seq = seq;
|
||||
this.src = src;
|
||||
this.dst = dst;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
type: "object",
|
||||
required: ["type", "seq", "src", "dst"],
|
||||
properties: {
|
||||
"type": { const: "response" },
|
||||
"seq": { type: "integer" },
|
||||
"src": Address.jsonSchema,
|
||||
"dst": Address.jsonSchema,
|
||||
"data": {},
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(
|
||||
json.seq,
|
||||
Address.fromJSON(json.src),
|
||||
Address.fromJSON(json.dst),
|
||||
json.data,
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
/** @memberof module:lib/data */
|
||||
class ResponseError {
|
||||
/** @type {string} */
|
||||
message;
|
||||
/** @type {string|undefined} */
|
||||
code;
|
||||
/** @type {string|undefined} */
|
||||
stack;
|
||||
|
||||
constructor(message, code, stack) {
|
||||
this.message = message;
|
||||
if (code) { this.code = code; }
|
||||
if (stack) { this.stack = stack; }
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
required: ["message"],
|
||||
properties: {
|
||||
"message": { type: "string" },
|
||||
"code": { type: "string" },
|
||||
"stack": { type: "string" },
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(json.message, json.code, json.stack);
|
||||
}
|
||||
}
|
||||
|
||||
/** @memberof module:lib/data */
|
||||
class MessageResponseError extends Message {
|
||||
/** @type {number} */
|
||||
seq;
|
||||
/** @type {Address} */
|
||||
src;
|
||||
/** @type {Address} */
|
||||
dst;
|
||||
/** @type {module:lib/data.ResponseError} */
|
||||
data;
|
||||
|
||||
constructor(seq, src, dst, data) {
|
||||
super("responseError");
|
||||
this.seq = seq;
|
||||
this.src = src;
|
||||
this.dst = dst;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
type: "object",
|
||||
required: ["type", "seq", "src", "dst", "data"],
|
||||
properties: {
|
||||
"type": { const: "responseError" },
|
||||
"seq": { type: "integer" },
|
||||
"src": Address.jsonSchema,
|
||||
"dst": Address.jsonSchema,
|
||||
"data": ResponseError.jsonSchema,
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(
|
||||
json.seq,
|
||||
Address.fromJSON(json.src),
|
||||
Address.fromJSON(json.dst),
|
||||
ResponseError.fromJSON(json.data),
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
/** @memberof module:lib/data */
|
||||
class MessageEvent extends Message {
|
||||
/** @type {number} */
|
||||
seq;
|
||||
/** @type {Address} */
|
||||
src;
|
||||
/** @type {Address} */
|
||||
dst;
|
||||
/** @type {string} */
|
||||
name;
|
||||
/** @type {*} */
|
||||
data;
|
||||
|
||||
constructor(seq, src, dst, name, data) {
|
||||
super("event");
|
||||
this.seq = seq;
|
||||
this.src = src;
|
||||
this.dst = dst;
|
||||
this.name = name;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
type: "object",
|
||||
required: ["type", "seq", "src", "dst", "name"],
|
||||
properties: {
|
||||
"type": { const: "event" },
|
||||
"seq": { type: "integer" },
|
||||
"src": Address.jsonSchema,
|
||||
"dst": Address.jsonSchema,
|
||||
"name": { type: "string" },
|
||||
"data": {},
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(
|
||||
json.seq,
|
||||
Address.fromJSON(json.src),
|
||||
Address.fromJSON(json.dst),
|
||||
json.name,
|
||||
json.data,
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
/** @memberof module:lib/data */
|
||||
class MessageDisconnect extends Message {
|
||||
/** @type {string} */
|
||||
data;
|
||||
|
||||
constructor(stage) {
|
||||
super("disconnect");
|
||||
this.data = stage;
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
type: "object",
|
||||
required: ["type"],
|
||||
properties: {
|
||||
"type": { const: "disconnect" },
|
||||
"data": { enum: ["prepare", "ready"] },
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(json.data);
|
||||
}
|
||||
};
|
||||
|
||||
Message.jsonSchema = {
|
||||
type: "object",
|
||||
required: ["type"],
|
||||
properties: {
|
||||
"type": { enum: [
|
||||
"hello", "registerHost", "registerControl", "ready", "resume", "continue", "invalidate",
|
||||
"heartbeat", "request", "response", "responseError", "event", "disconnect",
|
||||
] },
|
||||
},
|
||||
oneOf: [
|
||||
MessageHello.jsonSchema,
|
||||
MessageRegisterHost.jsonSchema,
|
||||
MessageRegisterControl.jsonSchema,
|
||||
MessageReady.jsonSchema,
|
||||
MessageResume.jsonSchema,
|
||||
MessageContinue.jsonSchema,
|
||||
MessageInvalidate.jsonSchema,
|
||||
MessageHeartbeat.jsonSchema,
|
||||
MessageRequest.jsonSchema,
|
||||
MessageResponse.jsonSchema,
|
||||
MessageResponseError.jsonSchema,
|
||||
MessageEvent.jsonSchema,
|
||||
MessageDisconnect.jsonSchema,
|
||||
],
|
||||
};
|
||||
Message.validate = libSchema.compile(Message.jsonSchema);
|
||||
|
||||
/** @memberof module:lib/data */
|
||||
class PingRequest {
|
||||
static type = "request";
|
||||
static src = ["controller", "host", "control"];
|
||||
static dest = ["controller", "host", "control"];
|
||||
static permission = null;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
Message,
|
||||
HelloData,
|
||||
MessageHello,
|
||||
RegisterHostData,
|
||||
MessageRegisterHost,
|
||||
RegisterControlData,
|
||||
MessageRegisterControl,
|
||||
AccountDetails,
|
||||
ReadyData,
|
||||
MessageReady,
|
||||
ResumeData,
|
||||
MessageResume,
|
||||
ContinueData,
|
||||
MessageContinue,
|
||||
MessageInvalidate,
|
||||
MessageHeartbeat,
|
||||
Address,
|
||||
MessageRequest,
|
||||
MessageResponse,
|
||||
ResponseError,
|
||||
MessageResponseError,
|
||||
MessageEvent,
|
||||
MessageDisconnect,
|
||||
PingRequest,
|
||||
};
|
||||
@@ -0,0 +1,240 @@
|
||||
"use strict";
|
||||
const { jsonArray } = require("./composites");
|
||||
|
||||
|
||||
/** @memberof module:lib/data */
|
||||
class HostDetails {
|
||||
/** @type {string} */
|
||||
agent;
|
||||
/** @type {string} */
|
||||
version;
|
||||
/** @type {string} */
|
||||
name;
|
||||
/** @type {number} */
|
||||
id;
|
||||
/** @type {boolean} */
|
||||
connected;
|
||||
/** @type {string|undefined} */
|
||||
publicAddress;
|
||||
|
||||
constructor(agent, version, name, id, connected, publicAddress) {
|
||||
this.agent = agent;
|
||||
this.version = version;
|
||||
this.name = name;
|
||||
this.id = id;
|
||||
this.connected = connected;
|
||||
if (publicAddress !== undefined) { this.publicAddress = publicAddress; }
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
required: ["agent", "version", "name", "id", "connected"],
|
||||
properties: {
|
||||
"agent": { type: "string" },
|
||||
"version": { type: "string" },
|
||||
"name": { type: "string" },
|
||||
"id": { type: "integer" },
|
||||
"connected": { type: "boolean" },
|
||||
"publicAddress": { type: "string" },
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(json.agent, json.version, json.name, json.id, json.connected, json.publicAddress);
|
||||
}
|
||||
}
|
||||
|
||||
/** @memberof module:lib/data */
|
||||
class HostListRequest {
|
||||
static type = "request";
|
||||
static src = "control";
|
||||
static dst = "controller";
|
||||
static permission = "core.host.list";
|
||||
static Response = jsonArray(HostDetails);
|
||||
}
|
||||
|
||||
/* @memberof module:lib/data */
|
||||
class HostSetSubscriptionsRequest {
|
||||
static type = "request";
|
||||
static src = "control";
|
||||
static dst = "controller";
|
||||
static permission = "core.host.subscribe";
|
||||
|
||||
/** @type {boolean} */
|
||||
all;
|
||||
/** @type {Array<number>} */
|
||||
hostIds;
|
||||
|
||||
constructor(all, hostIds) {
|
||||
this.all = all;
|
||||
this.hostIds = hostIds;
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
type: "object",
|
||||
required: ["all", "hostIds"],
|
||||
properties: {
|
||||
all: { type: "boolean" },
|
||||
hostIds: {
|
||||
type: "array",
|
||||
items: { type: "integer" },
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(json.all, json.hostIds);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* @memberof module:lib/data */
|
||||
class HostUpdateEvent {
|
||||
static type = "event";
|
||||
static src = "controller";
|
||||
static dst = "control";
|
||||
|
||||
/** @type {module:lib/data.HostDetails} */
|
||||
update;
|
||||
|
||||
constructor(update) {
|
||||
this.update = update;
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
type: "object",
|
||||
required: ["update"],
|
||||
properties: {
|
||||
update: HostDetails.jsonSchema,
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(HostDetails.fromJSON(json.update));
|
||||
}
|
||||
}
|
||||
|
||||
/** @memberof module:lib/data */
|
||||
class HostMetricsRequest {
|
||||
static type = "request";
|
||||
static src = "controller";
|
||||
static dst = "host";
|
||||
}
|
||||
HostMetricsRequest.Response = class Response { // TODO: Use JSON class pattern in Prometheus
|
||||
/** @type {array} */
|
||||
results;
|
||||
|
||||
constructor(results) {
|
||||
this.results = results;
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
type: "object",
|
||||
required: ["results"],
|
||||
properties: {
|
||||
"results": {
|
||||
type: "array",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(json.results);
|
||||
}
|
||||
};
|
||||
|
||||
/** @memberof module:lib/data */
|
||||
class ControllerConnectionEvent {
|
||||
static type = "event";
|
||||
static src = "host";
|
||||
static dst = "instance";
|
||||
|
||||
/** @type {string} */
|
||||
event;
|
||||
|
||||
constructor(event) {
|
||||
this.event = event;
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
required: ["event"],
|
||||
properties: {
|
||||
"event": { type: "string" },
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(json.event);
|
||||
}
|
||||
}
|
||||
|
||||
/* @memberof module:lib/data */
|
||||
class PrepareControllerDisconnectRequest {
|
||||
static type = "request";
|
||||
static src = "host";
|
||||
static dst = "instance";
|
||||
}
|
||||
|
||||
/** @memberof module:lib/data */
|
||||
class SyncUserListsEvent {
|
||||
static type = "event";
|
||||
static src = "controller";
|
||||
static dst = "host";
|
||||
|
||||
/** @type {Set<string>} */
|
||||
adminlist;
|
||||
/** @type {Map<string, string>} */
|
||||
banlist;
|
||||
/** @type {Set<string>} */
|
||||
whitelist;
|
||||
|
||||
constructor(adminlist, banlist, whitelist) {
|
||||
this.adminlist = adminlist;
|
||||
this.banlist = banlist;
|
||||
this.whitelist = whitelist;
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
required: ["adminlist", "banlist", "whitelist"],
|
||||
properties: {
|
||||
"adminlist": {
|
||||
type: "array",
|
||||
items: { type: "string" },
|
||||
},
|
||||
"banlist": {
|
||||
type: "array",
|
||||
items: {
|
||||
type: "array",
|
||||
additionalItems: false,
|
||||
items: [{ type: "string" }, { type: "string" }],
|
||||
},
|
||||
},
|
||||
"whitelist": {
|
||||
type: "array",
|
||||
items: { type: "string" },
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(new Set(json.adminlist), new Set(json.banlist), new Set(json.whitelist));
|
||||
}
|
||||
|
||||
static toJSON() {
|
||||
return {
|
||||
adminlist: [...this.adminlist],
|
||||
banlist: [...this.banlist],
|
||||
whitelist: [...this.whitelist],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
HostDetails,
|
||||
HostListRequest,
|
||||
HostSetSubscriptionsRequest,
|
||||
HostUpdateEvent,
|
||||
HostMetricsRequest,
|
||||
ControllerConnectionEvent,
|
||||
PrepareControllerDisconnectRequest,
|
||||
SyncUserListsEvent,
|
||||
};
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,474 @@
|
||||
"use strict";
|
||||
const ModPack = require("./ModPack");
|
||||
const ModInfo = require("./ModInfo");
|
||||
const { jsonArray, JsonString } = require("./composites");
|
||||
|
||||
|
||||
/* @memberof module:lib/data */
|
||||
class ModPackGetRequest {
|
||||
static type = "request";
|
||||
static src = ["instance", "control"];
|
||||
static dst = "controller";
|
||||
static permission = "core.mod_pack.get";
|
||||
|
||||
/** @type {number} */
|
||||
id;
|
||||
|
||||
constructor(id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
type: "object",
|
||||
required: ["id"],
|
||||
properties: {
|
||||
id: { type: "integer" },
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(json.id);
|
||||
}
|
||||
|
||||
static Response = ModPack;
|
||||
}
|
||||
|
||||
/* @memberof module:lib/data */
|
||||
class ModPackGetDefaultRequest {
|
||||
static type = "request";
|
||||
static src = ["instance", "control"];
|
||||
static dst = "controller";
|
||||
static permission = "core.mod_pack.get";
|
||||
static Response = ModPack;
|
||||
}
|
||||
|
||||
/* @memberof module:lib/data */
|
||||
class ModPackListRequest {
|
||||
static type = "request";
|
||||
static src = "control";
|
||||
static dst = "controller";
|
||||
static permission = "core.mod_pack.list";
|
||||
static Response = jsonArray(ModPack);
|
||||
}
|
||||
|
||||
/** @memberof module:lib/data */
|
||||
class ModPackCreateRequest {
|
||||
static type = "request";
|
||||
static src = "control";
|
||||
static dst = "controller";
|
||||
static permission = "core.mod_pack.create";
|
||||
|
||||
/** @type {module:lib/data.ModPack} */
|
||||
modPack;
|
||||
|
||||
constructor(modPack) {
|
||||
this.modPack = modPack;
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
type: "object",
|
||||
required: ["modPack"],
|
||||
properties: {
|
||||
"modPack": ModPack.jsonSchema,
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(ModPack.fromJSON(json.modPack));
|
||||
}
|
||||
}
|
||||
|
||||
/* @memberof module:lib/data */
|
||||
class ModPackUpdateRequest {
|
||||
static type = "request";
|
||||
static src = "control";
|
||||
static dst = "controller";
|
||||
static permission = "core.mod_pack.update";
|
||||
|
||||
/** @type {module:lib/data.ModPack} */
|
||||
modPack;
|
||||
|
||||
constructor(modPack) {
|
||||
this.modPack = modPack;
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
type: "object",
|
||||
required: ["modPack"],
|
||||
properties: {
|
||||
"modPack": ModPack.jsonSchema,
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(ModPack.fromJSON(json.modPack));
|
||||
}
|
||||
}
|
||||
|
||||
/* @memberof module:lib/data */
|
||||
class ModPackDeleteRequest {
|
||||
static type = "request";
|
||||
static src = "control";
|
||||
static dst = "controller";
|
||||
static permission = "core.mod_pack.delete";
|
||||
|
||||
/** @type {number} */
|
||||
id;
|
||||
|
||||
constructor(id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
type: "object",
|
||||
required: ["id"],
|
||||
properties: {
|
||||
id: { type: "integer" },
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(json.id);
|
||||
}
|
||||
}
|
||||
|
||||
/* @memberof module:lib/data */
|
||||
class ModPackSetSubscriptionsRequest {
|
||||
static type = "request";
|
||||
static src = "control";
|
||||
static dst = "controller";
|
||||
static permission = "core.mod_pack.subscribe";
|
||||
|
||||
/** @type {boolean} */
|
||||
all;
|
||||
/** @type {Array<number>} */
|
||||
modPackIds;
|
||||
|
||||
constructor(all, modPackIds) {
|
||||
this.all = all;
|
||||
this.modPackIds = modPackIds;
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
type: "object",
|
||||
required: ["all", "modPackIds"],
|
||||
properties: {
|
||||
all: { type: "boolean" },
|
||||
modPackIds: {
|
||||
type: "array",
|
||||
items: { type: "integer" },
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(json.all, json.modPackIds);
|
||||
}
|
||||
}
|
||||
|
||||
/* @memberof module:lib/data */
|
||||
class ModGetRequest {
|
||||
static type = "request";
|
||||
static src = "control";
|
||||
static dst = "controller";
|
||||
static permission = "core.mod.get";
|
||||
|
||||
/** @type {string} */
|
||||
name;
|
||||
/** @type {string} */
|
||||
version;
|
||||
|
||||
constructor(name, version) {
|
||||
this.name = name;
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
type: "object",
|
||||
required: ["name", "version"],
|
||||
properties: {
|
||||
name: { type: "string" },
|
||||
version: { type: "string" },
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(json.name, json.version);
|
||||
}
|
||||
|
||||
static Response = ModInfo;
|
||||
}
|
||||
|
||||
/* @memberof module:lib/data */
|
||||
class ModListRequest {
|
||||
static type = "request";
|
||||
static src = "control";
|
||||
static dst = "controller";
|
||||
static permission = "core.mod.list";
|
||||
static Response = jsonArray(ModInfo);
|
||||
}
|
||||
|
||||
/* @memberof module:lib/data */
|
||||
class ModSearchRequest {
|
||||
static type = "request";
|
||||
static src = "control";
|
||||
static dst = "controller";
|
||||
static permission = "core.mod.search";
|
||||
|
||||
/** @type {string} */
|
||||
query;
|
||||
/** @type {string} */
|
||||
factorioVersion;
|
||||
/** @type {number} */
|
||||
page;
|
||||
/** @type {number|undefined} */
|
||||
pageSize;
|
||||
/** @type {string|undefined} */
|
||||
sort;
|
||||
/** @type {string|undefined} */
|
||||
sortOrder;
|
||||
|
||||
constructor(query, factorioVersion, page, pageSize, sort, sortOrder) {
|
||||
this.query = query;
|
||||
this.factorioVersion = factorioVersion;
|
||||
this.page = page;
|
||||
if (pageSize) { this.pageSize = pageSize; }
|
||||
if (sort) { this.sort = sort; }
|
||||
if (sortOrder) { this.sortOrder = sortOrder; }
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
type: "object",
|
||||
required: ["query", "factorioVersion", "page"],
|
||||
properties: {
|
||||
query: { type: "string" },
|
||||
factorioVersion: { type: "string" },
|
||||
pageSize: { type: "integer" },
|
||||
page: { type: "integer" },
|
||||
sort: { type: "string" },
|
||||
sortOrder: { type: "string" },
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(json.query, json.factorioVersion, json.page, json.pageSize, json.sort, json.sortOrder);
|
||||
}
|
||||
}
|
||||
ModSearchRequest.Response = class Response {
|
||||
/** @type {Array<string>} */
|
||||
queryIssues;
|
||||
/** @type {number} */
|
||||
pageCount;
|
||||
/** @type {number} */
|
||||
resultCount;
|
||||
/** @type {Array<object>} */
|
||||
results;
|
||||
|
||||
constructor(queryIssues, pageCount, resultCount, results) {
|
||||
this.queryIssues = queryIssues;
|
||||
this.pageCount = pageCount;
|
||||
this.resultCount = resultCount;
|
||||
this.results = results;
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
type: "object",
|
||||
required: ["queryIssues", "pageCount", "resultCount", "results"],
|
||||
properties: {
|
||||
queryIssues: {
|
||||
type: "array",
|
||||
items: { type: "string" },
|
||||
},
|
||||
pageCount: { type: "integer" },
|
||||
resultCount: { type: "integer" },
|
||||
results: {
|
||||
type: "array",
|
||||
items: {
|
||||
type: "object",
|
||||
properties: {
|
||||
name: { type: "string" },
|
||||
versions: {
|
||||
type: "array",
|
||||
items: ModInfo.jsonSchema,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
let results = json.results.map(
|
||||
({ name, versions }) => ({ name, versions: versions.map(mod => ModInfo.fromJSON(mod)) })
|
||||
);
|
||||
return new this(json.queryIssues, json.pageCount, json.resultCount, results);
|
||||
}
|
||||
};
|
||||
|
||||
/* @memberof module:lib/data */
|
||||
class ModSetSubscriptionsRequest {
|
||||
static type = "request";
|
||||
static src = "control";
|
||||
static dst = "controller";
|
||||
static permission = "core.mod.subscribe";
|
||||
|
||||
/** @type {boolean} */
|
||||
all;
|
||||
/** @type {Array<string>} */
|
||||
modNames;
|
||||
|
||||
constructor(all, modNames) {
|
||||
this.all = all;
|
||||
this.modNames = modNames;
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
type: "object",
|
||||
required: ["all", "modNames"],
|
||||
properties: {
|
||||
all: { type: "boolean" },
|
||||
modNames: {
|
||||
type: "array",
|
||||
items: { type: "string" },
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(json.all, json.modNames);
|
||||
}
|
||||
}
|
||||
|
||||
/* @memberof module:lib/data */
|
||||
class ModDownloadRequest {
|
||||
static type = "request";
|
||||
static src = "control";
|
||||
static dst = "controller";
|
||||
static permission = "core.mod.download";
|
||||
|
||||
/** @type {string} */
|
||||
name;
|
||||
/** @type {string} */
|
||||
version;
|
||||
|
||||
constructor(name, version) {
|
||||
this.name = name;
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
type: "object",
|
||||
required: ["name", "version"],
|
||||
properties: {
|
||||
name: { type: "string" },
|
||||
version: { type: "string" },
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(json.name, json.version);
|
||||
}
|
||||
|
||||
static Response = JsonString;
|
||||
}
|
||||
|
||||
/* @memberof module:lib/data */
|
||||
class ModDeleteRequest {
|
||||
static type = "request";
|
||||
static src = "control";
|
||||
static dst = "controller";
|
||||
static permission = "core.mod.delete";
|
||||
|
||||
/** @type {string} */
|
||||
name;
|
||||
/** @type {string} */
|
||||
version;
|
||||
|
||||
constructor(name, version) {
|
||||
this.name = name;
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
type: "object",
|
||||
required: ["name", "version"],
|
||||
properties: {
|
||||
name: { type: "string" },
|
||||
version: { type: "string" },
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(json.name, json.version);
|
||||
}
|
||||
}
|
||||
|
||||
/* @memberof module:lib/data */
|
||||
class ModPackUpdateEvent {
|
||||
static type = "event";
|
||||
static src = "controller";
|
||||
static dst = "control";
|
||||
|
||||
/** @type {module:lib/data.ModPack} */
|
||||
modPack;
|
||||
|
||||
constructor(modPack) {
|
||||
this.modPack = modPack;
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
type: "object",
|
||||
required: ["modPack"],
|
||||
properties: {
|
||||
modPack: ModPack.jsonSchema,
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(ModPack.fromJSON(json.modPack));
|
||||
}
|
||||
}
|
||||
|
||||
/* @memberof module:lib/data */
|
||||
class ModUpdateEvent {
|
||||
static type = "event";
|
||||
static src = "controller";
|
||||
static dst = "control";
|
||||
|
||||
/** @type {module:lib/data.ModInfo} */
|
||||
mod;
|
||||
|
||||
constructor(mod) {
|
||||
this.mod = mod;
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
type: "object",
|
||||
required: ["mod"],
|
||||
properties: {
|
||||
mod: ModInfo.jsonSchema,
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(ModInfo.fromJSON(json.mod));
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
ModPackGetRequest,
|
||||
ModPackGetDefaultRequest,
|
||||
ModPackListRequest,
|
||||
ModPackCreateRequest,
|
||||
ModPackUpdateRequest,
|
||||
ModPackDeleteRequest,
|
||||
ModPackSetSubscriptionsRequest,
|
||||
ModGetRequest,
|
||||
ModListRequest,
|
||||
ModSearchRequest,
|
||||
ModSetSubscriptionsRequest,
|
||||
ModDownloadRequest,
|
||||
ModDeleteRequest,
|
||||
ModPackUpdateEvent,
|
||||
ModUpdateEvent,
|
||||
};
|
||||
@@ -0,0 +1,688 @@
|
||||
"use strict";
|
||||
const PlayerStats = require("../PlayerStats");
|
||||
const { jsonArray, JsonNumber } = require("./composites");
|
||||
|
||||
/* @memberof module:lib/data */
|
||||
class RawPermission { // TODO refactor into lib/user.Permission
|
||||
/** @type {string} */
|
||||
name;
|
||||
/** @type {string} */
|
||||
title;
|
||||
/** @type {string} */
|
||||
description;
|
||||
|
||||
constructor(name, title, description) {
|
||||
this.name = name;
|
||||
this.title = title;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
required: ["name", "title", "description"],
|
||||
properties: {
|
||||
name: { type: "string" },
|
||||
title: { type: "string" },
|
||||
description: { type: "string" },
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(json.name, json.title, json.description);
|
||||
}
|
||||
}
|
||||
|
||||
/* @memberof module:lib/data */
|
||||
class PermissionListRequest {
|
||||
static type = "request";
|
||||
static src = "control";
|
||||
static dst = "controller";
|
||||
static permission = "core.permission.list";
|
||||
static Response = jsonArray(RawPermission);
|
||||
}
|
||||
|
||||
class RawRole { // TODO refactor into lib/user.Role
|
||||
/** @type {number} */
|
||||
id;
|
||||
/** @type {string} */
|
||||
name;
|
||||
/** @type {string} */
|
||||
description;
|
||||
/** @type {Array<string>} */
|
||||
permissions;
|
||||
|
||||
constructor(id, name, description, permissions) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.permissions = permissions;
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
type: "object",
|
||||
required: ["id", "name", "description", "permissions"],
|
||||
properties: {
|
||||
id: { type: "integer" },
|
||||
name: { type: "string" },
|
||||
description: { type: "string" },
|
||||
permissions: {
|
||||
type: "array",
|
||||
items: { type: "string" },
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(json.id, json.name, json.description, json.permissions);
|
||||
}
|
||||
}
|
||||
|
||||
/* @memberof module:lib/data */
|
||||
class RoleListRequest {
|
||||
static type = "request";
|
||||
static src = "control";
|
||||
static dst = "controller";
|
||||
static permission = "core.role.list";
|
||||
static Response = jsonArray(RawRole);
|
||||
}
|
||||
|
||||
/* @memberof module:lib/data */
|
||||
class RoleCreateRequest {
|
||||
static type = "request";
|
||||
static src = "control";
|
||||
static dst = "controller";
|
||||
static permission = "core.role.create";
|
||||
|
||||
/** @type {string} */
|
||||
name;
|
||||
/** @type {string} */
|
||||
description;
|
||||
/** @type {Array<string>} */
|
||||
permissions;
|
||||
|
||||
constructor(name, description, permissions) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.permissions = permissions;
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
type: "object",
|
||||
required: ["name", "description", "permissions"],
|
||||
properties: {
|
||||
name: { type: "string" },
|
||||
description: { type: "string" },
|
||||
permissions: {
|
||||
type: "array",
|
||||
items: { type: "string" },
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(json.name, json.description, json.permissions);
|
||||
}
|
||||
|
||||
static Response = JsonNumber;
|
||||
}
|
||||
|
||||
/* @memberof module:lib/data */
|
||||
class RoleUpdateRequest {
|
||||
static type = "request";
|
||||
static src = "control";
|
||||
static dst = "controller";
|
||||
static permission = "core.role.update";
|
||||
|
||||
/** @type {number} */
|
||||
id;
|
||||
/** @type {string} */
|
||||
name;
|
||||
/** @type {string} */
|
||||
description;
|
||||
/** @type {Array<string>} */
|
||||
permissions;
|
||||
|
||||
constructor(id, name, description, permissions) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.permissions = permissions;
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
type: "object",
|
||||
required: ["id", "name", "description", "permissions"],
|
||||
properties: {
|
||||
id: { type: "integer" },
|
||||
name: { type: "string" },
|
||||
description: { type: "string" },
|
||||
permissions: {
|
||||
type: "array",
|
||||
items: { type: "string" },
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(json.id, json.name, json.description, json.permissions);
|
||||
}
|
||||
}
|
||||
|
||||
/* @memberof module:lib/data */
|
||||
class RoleGrantDefaultPermissionsRequest {
|
||||
static type = "request";
|
||||
static src = "control";
|
||||
static dst = "controller";
|
||||
static permission = "core.role.update";
|
||||
|
||||
/** @type {number} */
|
||||
id;
|
||||
|
||||
constructor(id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
type: "object",
|
||||
required: ["id"],
|
||||
properties: {
|
||||
id: { type: "integer" },
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(json.id);
|
||||
}
|
||||
}
|
||||
|
||||
/* @memberof module:lib/data */
|
||||
class RoleDeleteRequest {
|
||||
static type = "request";
|
||||
static src = "control";
|
||||
static dst = "controller";
|
||||
static permission = "core.role.delete";
|
||||
|
||||
/** @type {number} */
|
||||
id;
|
||||
|
||||
constructor(id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
type: "object",
|
||||
required: ["id"],
|
||||
properties: {
|
||||
id: { type: "integer" },
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(json.id);
|
||||
}
|
||||
}
|
||||
|
||||
/* @memberof module:lib/data */
|
||||
class RawUser { // TODO refactor into lib/user.User
|
||||
/** @type {string} */
|
||||
name;
|
||||
/** @type {Array<number>} */
|
||||
roles;
|
||||
/** @type {Array<number>} */
|
||||
instances;
|
||||
/** @type {boolean|undefined} */
|
||||
isAdmin;
|
||||
/** @type {boolean|undefined} */
|
||||
isBanned;
|
||||
/** @type {boolean|undefined} */
|
||||
isWhitelisted;
|
||||
/** @type {string|undefined} */
|
||||
banReason;
|
||||
/** @type {boolean|undefined} */
|
||||
isDeleted;
|
||||
/** @type {module:lib/PlayerStats} */
|
||||
playerStats;
|
||||
/** @type {Map<number, module:lib/PlayerStats>|undefined} */
|
||||
instanceStats;
|
||||
|
||||
constructor(
|
||||
name, roles, instances, isAdmin, isBanned, isWhitelisted, banReason,
|
||||
isDeleted, playerStats, instanceStats
|
||||
) {
|
||||
this.name = name;
|
||||
this.roles = roles;
|
||||
this.instances = instances;
|
||||
if (isAdmin !== undefined) { this.isAdmin = isAdmin; }
|
||||
if (isBanned !== undefined) { this.isBanned = isBanned; }
|
||||
if (isWhitelisted !== undefined) { this.isWhitelisted = isWhitelisted; }
|
||||
if (banReason !== undefined) { this.banReason = banReason; }
|
||||
if (isDeleted !== undefined) { this.isDeleted = isDeleted; }
|
||||
if (playerStats !== undefined) { this.playerStats = playerStats; }
|
||||
if (instanceStats !== undefined) { this.instanceStats = instanceStats; }
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
type: "object",
|
||||
required: ["name", "roles", "instances"],
|
||||
properties: {
|
||||
name: { type: "string" },
|
||||
roles: { type: "array", items: { type: "integer" } },
|
||||
isAdmin: { type: "boolean" },
|
||||
isBanned: { type: "boolean" },
|
||||
isWhitelisted: { type: "boolean" },
|
||||
banReason: { type: "string" },
|
||||
instances: { type: "array", items: { type: "integer" } },
|
||||
isDeleted: { type: "boolean" },
|
||||
playerStats: PlayerStats.jsonSchema,
|
||||
instanceStats: {
|
||||
type: "array",
|
||||
items: {
|
||||
type: "array",
|
||||
items: [{ type: "integer" }, PlayerStats.jsonSchema],
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
let playerStats;
|
||||
if (json.playerStats) {
|
||||
playerStats = PlayerStats.fromJSON(json.playerStats);
|
||||
}
|
||||
let instanceStats;
|
||||
if (json.instanceStats) {
|
||||
instanceStats = new Map(
|
||||
json.instanceStats.map(([id, stats]) => [id, PlayerStats.fromJSON(stats)])
|
||||
);
|
||||
}
|
||||
return new this(
|
||||
json.name, json.roles, json.instances, json.isAdmin, json.isBanned, json.isWhitelisted, json.banReason,
|
||||
json.isDeleted, playerStats, instanceStats
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/* @memberof module:lib/data */
|
||||
class UserGetRequest {
|
||||
static type = "request";
|
||||
static src = "control";
|
||||
static dst = "controller";
|
||||
static permission = "core.user.get";
|
||||
|
||||
/** @type {string} */
|
||||
name;
|
||||
|
||||
constructor(name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
type: "object",
|
||||
required: ["name"],
|
||||
properties: {
|
||||
name: { type: "string" },
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(json.name);
|
||||
}
|
||||
|
||||
static Response = RawUser;
|
||||
}
|
||||
|
||||
/* @memberof module:lib/data */
|
||||
class UserListRequest {
|
||||
static type = "request";
|
||||
static src = "control";
|
||||
static dst = "controller";
|
||||
static permission = "core.user.list";
|
||||
static Response = jsonArray(RawUser);
|
||||
}
|
||||
|
||||
/* @memberof module:lib/data */
|
||||
class UserSetSubscriptionsRequest {
|
||||
static type = "request";
|
||||
static src = "control";
|
||||
static dst = "controller";
|
||||
static permission = "core.user.subscribe";
|
||||
|
||||
/** @type {boolean} */
|
||||
all;
|
||||
/** @type {Array<string>} */
|
||||
names;
|
||||
|
||||
constructor(all, names) {
|
||||
this.all = all;
|
||||
this.names = names;
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
type: "object",
|
||||
required: ["all", "names"],
|
||||
properties: {
|
||||
all: { type: "boolean" },
|
||||
names: {
|
||||
type: "array",
|
||||
items: { type: "string" },
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(json.all, json.names);
|
||||
}
|
||||
}
|
||||
|
||||
/* @memberof module:lib/data */
|
||||
class UserCreateRequest {
|
||||
static type = "request";
|
||||
static src = "control";
|
||||
static dst = "controller";
|
||||
static permission = "core.user.create";
|
||||
|
||||
/** @type {string} */
|
||||
name;
|
||||
|
||||
constructor(name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
type: "object",
|
||||
required: ["name"],
|
||||
properties: {
|
||||
name: { type: "string" },
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(json.name);
|
||||
}
|
||||
}
|
||||
|
||||
/* @memberof module:lib/data */
|
||||
class UserRevokeTokenRequest {
|
||||
static type = "request";
|
||||
static src = "control";
|
||||
static dst = "controller";
|
||||
static permission = "core.user.revoke_token";
|
||||
|
||||
/** @type {string} */
|
||||
name;
|
||||
|
||||
constructor(name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
type: "object",
|
||||
required: ["name"],
|
||||
properties: {
|
||||
name: { type: "string" },
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(json.name);
|
||||
}
|
||||
}
|
||||
|
||||
/* @memberof module:lib/data */
|
||||
class UserUpdateRolesRequest {
|
||||
static type = "request";
|
||||
static src = "control";
|
||||
static dst = "controller";
|
||||
static permission = "core.user.update_roles";
|
||||
|
||||
/** @type {string} */
|
||||
name;
|
||||
/** @type {Array<number>} */
|
||||
roles;
|
||||
|
||||
constructor(name, roles) {
|
||||
this.name = name;
|
||||
this.roles = roles;
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
type: "object",
|
||||
required: ["name", "roles"],
|
||||
properties: {
|
||||
name: { type: "string" },
|
||||
roles: {
|
||||
type: "array",
|
||||
items: { type: "integer" },
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(json.name, json.roles);
|
||||
}
|
||||
}
|
||||
|
||||
/* @memberof module:lib/data */
|
||||
class UserSetAdminRequest {
|
||||
static type = "request";
|
||||
static src = "control";
|
||||
static dst = "controller";
|
||||
static permission = "core.user.set_admin";
|
||||
|
||||
/** @type {string} */
|
||||
name;
|
||||
/** @type {boolean} */
|
||||
create;
|
||||
/** @type {boolean} */
|
||||
admin;
|
||||
|
||||
constructor(name, create, admin) {
|
||||
this.name = name;
|
||||
this.create = create;
|
||||
this.admin = admin;
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
type: "object",
|
||||
required: ["name", "create", "admin"],
|
||||
properties: {
|
||||
name: { type: "string" },
|
||||
create: { type: "boolean" },
|
||||
admin: { type: "boolean" },
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(json.name, json.create, json.admin);
|
||||
}
|
||||
}
|
||||
|
||||
/* @memberof module:lib/data */
|
||||
class UserSetWhitelistedRequest {
|
||||
static type = "request";
|
||||
static src = "control";
|
||||
static dst = "controller";
|
||||
static permission = "core.user.set_whitelisted";
|
||||
|
||||
/** @type {string} */
|
||||
name;
|
||||
/** @type {boolean} */
|
||||
create;
|
||||
/** @type {boolean} */
|
||||
whitelisted;
|
||||
|
||||
constructor(name, create, whitelisted) {
|
||||
this.name = name;
|
||||
this.create = create;
|
||||
this.whitelisted = whitelisted;
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
type: "object",
|
||||
required: ["name", "create", "whitelisted"],
|
||||
properties: {
|
||||
name: { type: "string" },
|
||||
create: { type: "boolean" },
|
||||
whitelisted: { type: "boolean" },
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(json.name, json.create, json.whitelisted);
|
||||
}
|
||||
}
|
||||
|
||||
/* @memberof module:lib/data */
|
||||
class UserSetBannedRequest {
|
||||
static type = "request";
|
||||
static src = "control";
|
||||
static dst = "controller";
|
||||
static permission = "core.user.set_banned";
|
||||
|
||||
/** @type {string} */
|
||||
name;
|
||||
/** @type {boolean} */
|
||||
create;
|
||||
/** @type {boolean} */
|
||||
banned;
|
||||
/** @type {string} */
|
||||
reason;
|
||||
|
||||
constructor(name, create, banned, reason) {
|
||||
this.name = name;
|
||||
this.create = create;
|
||||
this.banned = banned;
|
||||
this.reason = reason;
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
type: "object",
|
||||
required: ["name", "create", "banned", "reason"],
|
||||
properties: {
|
||||
name: { type: "string" },
|
||||
create: { type: "boolean" },
|
||||
banned: { type: "boolean" },
|
||||
reason: { type: "string" },
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(json.name, json.create, json.banned, json.reason);
|
||||
}
|
||||
}
|
||||
|
||||
/* @memberof module:lib/data */
|
||||
class UserDeleteRequest {
|
||||
static type = "request";
|
||||
static src = "control";
|
||||
static dst = "controller";
|
||||
static permission = "core.user.delete";
|
||||
|
||||
/** @type {string} */
|
||||
name;
|
||||
|
||||
constructor(name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
type: "object",
|
||||
required: ["name"],
|
||||
properties: {
|
||||
name: { type: "string" },
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(json.name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* @memberof module:lib/data */
|
||||
class AccountUpdateEvent {
|
||||
static type = "event";
|
||||
static src = "controller";
|
||||
static dst = "control";
|
||||
|
||||
/** @type {Array<object>|undefined} */
|
||||
roles;
|
||||
|
||||
constructor(roles) {
|
||||
if (roles) { this.roles = roles; }
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
type: "object",
|
||||
properties: {
|
||||
roles: {
|
||||
type: "array",
|
||||
items: {
|
||||
type: "object",
|
||||
required: ["name", "id", "permissions"],
|
||||
properties: {
|
||||
name: { type: "string" },
|
||||
id: { type: "integer" },
|
||||
permissions: {
|
||||
type: "array",
|
||||
items: { type: "string" },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(json.roles);
|
||||
}
|
||||
}
|
||||
|
||||
/* @memberof module:lib/data */
|
||||
class UserUpdateEvent {
|
||||
static type = "event";
|
||||
static src = "controller";
|
||||
static dst = "control";
|
||||
|
||||
/** @type {module:lib/data.RawUser} */
|
||||
user;
|
||||
|
||||
constructor(user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
static jsonSchema = {
|
||||
type: "object",
|
||||
required: ["user"],
|
||||
properties: {
|
||||
user: RawUser.jsonSchema,
|
||||
},
|
||||
};
|
||||
|
||||
static fromJSON(json) {
|
||||
return new this(RawUser.fromJSON(json.user));
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
RawPermission,
|
||||
PermissionListRequest,
|
||||
RawRole,
|
||||
RoleListRequest,
|
||||
RoleCreateRequest,
|
||||
RoleUpdateRequest,
|
||||
RoleGrantDefaultPermissionsRequest,
|
||||
RoleDeleteRequest,
|
||||
RawUser,
|
||||
UserGetRequest,
|
||||
UserListRequest,
|
||||
UserSetSubscriptionsRequest,
|
||||
UserCreateRequest,
|
||||
UserRevokeTokenRequest,
|
||||
UserUpdateRolesRequest,
|
||||
UserSetAdminRequest,
|
||||
UserSetWhitelistedRequest,
|
||||
UserSetBannedRequest,
|
||||
UserDeleteRequest,
|
||||
AccountUpdateEvent,
|
||||
UserUpdateEvent,
|
||||
};
|
||||
Reference in new issue
Block a user