Refactor message registration and validation

Split up the action of registring an event or request data class to be
decoded by the Link class and the action of registring a handler for
those requests and events.  This moves the validation work from Link
instantiation time to startup initialisation which makes logic errors
fail on startup instead of failing instantiation of the link when a
connection attempt is made.

Additionally implement a partial validation logic for messages received
using the newly refactored message registration.  This unfortunately
ended up merged with the registration refactor.
This commit is contained in:
Hornwitser committed 2023-06-03 16:47:47 +02:00
1 parent bcd94709d2
commit 7f8a700716
39 files changed
+648 -332

No files matched your search

+2 -2
View File
@@ -301,8 +301,8 @@ LogQueryRequest.Response = class Response {
/** @memberof module:lib/data */
class LogMessageEvent {
static type = "event";
static src = "host";
static dst = "controller";
static src = ["host", "controller"];
static dst = ["controller", "control"];
/** @type {object} */
info;
+1 -1
View File
@@ -848,7 +848,7 @@ Message.validate = libSchema.compile(Message.jsonSchema);
class PingRequest {
static type = "request";
static src = ["controller", "host", "control"];
static dest = ["controller", "host", "control"];
static dst = ["controller", "host", "control"];
static permission = null;
}
+9 -9
View File
@@ -461,7 +461,7 @@ class InstanceSetSaveListSubscriptionsRequest {
/** @memberof module:lib/data */
class InstanceSaveListUpdateEvent {
static type = "event";
static src = ["instance", "host"];
static src = ["instance", "host", "controller"];
static dst = ["controller", "control"];
/** @type {number} */
@@ -533,8 +533,8 @@ class InstanceCreateSaveRequest {
/** @memberof module:lib/data */
class InstanceRenameSaveRequest {
static type = "request";
static src = "control";
static dst = "host";
static src = ["control", "controller"];
static dst = ["controller", "host"];
static permission = "core.instance.save.rename";
/** @type {number} */
@@ -568,8 +568,8 @@ class InstanceRenameSaveRequest {
/** @memberof module:lib/data */
class InstanceCopySaveRequest {
static type = "request";
static src = "control";
static dst = "host";
static src = ["control", "controller"];
static dst = ["controller", "host"];
static permission = "core.instance.save.copy";
/** @type {number} */
@@ -603,8 +603,8 @@ class InstanceCopySaveRequest {
/** @memberof module:lib/data */
class InstanceDeleteSaveRequest {
static type = "request";
static src = "control";
static dst = "host";
static src = ["control", "controller"];
static dst = ["controller", "host"];
static permission = "core.instance.save.delete";
/** @type {number} */
@@ -667,7 +667,7 @@ class InstanceDownloadSaveRequest {
/** @memberof module:lib/data */
class InstanceTransferSaveRequest {
static type = "request";
static src = "control";
static src = ["control", "controller"];
static dst = ["controller", "host"];
static permission = "core.instance.save.transfer";
@@ -1081,7 +1081,7 @@ class InstanceInitialisedEvent {
/** @memberof module:lib/data */
class InstanceStatusChangedEvent {
static type = "event";
static src = "instance";
static src = ["instance", "host"];
static dst = "controller";
/** @type {integer} */
+19 -1
View File
@@ -266,11 +266,11 @@ class RawUser { // TODO refactor into lib/user.User
properties: {
name: { type: "string" },
roles: { type: "array", items: { type: "integer" } },
instances: { 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: {
@@ -299,6 +299,24 @@ class RawUser { // TODO refactor into lib/user.User
json.isDeleted, playerStats, instanceStats
);
}
toJSON() {
const json = {
name: this.name,
roles: this.roles,
instances: this.instances,
isAdmin: this.isAdmin,
isBanned: this.isBanned,
isWhitelisted: this.isWhitelisted,
banReason: this.banReason,
isDeleted: this.isDeleted,
playerStats: this.playerStats,
};
if (this.instanceStats) {
json.instanceStats = [...this.instanceStats];
}
return json;
}
}
/* @memberof module:lib/data */