Files
factorio-clusterio/plugins/subspace_storage/messages.js
T
Hornwitser 2de029b96e Fix strict mode warnings from Ajv
Add type object to schemas specifying properties and minItems to schemas
specifying tuples. Disable strictTuples because it's desirable to be
able to add additional items to the tuples in the future.
2023-07-27 00:35:26 +02:00

168 lines
2.7 KiB
JavaScript

"use strict";
const { libData } = require("@clusterio/lib");
class Item {
/** @type {string} */
name;
/** @type {number} */
count;
constructor(name, count) {
this.name = name;
this.count = count;
}
static jsonSchema = {
type: "array",
minItems: 2,
maxItems: 2,
items: [
{ type: "string" },
{ type: "integer" },
],
};
toJSON() {
return [this.name, this.count];
}
static fromJSON(json) {
return new this(json[0], json[1]);
}
}
// XXX this should be a request to be reliable
class PlaceEvent {
static type = "event";
static src = "instance";
static dst = "controller";
static plugin = "subspace_storage";
/** @type {Array<Item>} */
items;
constructor(items) {
this.items = items;
}
static jsonSchema = {
type: "object",
required: ["items"],
properties: {
"items": {
type: "array",
items: Item.jsonSchema,
},
},
};
static fromJSON(json) {
return new this(json.items);
}
}
class RemoveRequest {
static type = "request";
static src = "instance";
static dst = "controller";
static plugin = "subspace_storage";
/** @type {Array<Item>} */
items;
constructor(items) {
this.items = items;
}
static jsonSchema = {
type: "object",
required: ["items"],
properties: {
"items": {
type: "array",
items: Item.jsonSchema,
},
},
};
static fromJSON(json) {
return new this(json.items);
}
static Response = libData.jsonArray(Item);
}
class GetStorageRequest {
static type = "request";
static src = ["instance", "control"];
static dst = "controller";
static plugin = "subspace_storage";
static permission = "subspace_storage.storage.view";
static Response = libData.jsonArray(Item);
}
class UpdateStorageEvent {
static type = "request";
static src = "controller";
static dst = ["instance", "control"];
static plugin = "subspace_storage";
/** @type {Array<Item>} */
items;
constructor(items) {
this.items = items;
}
static jsonSchema = {
type: "object",
required: ["items"],
properties: {
"items": {
type: "array",
items: Item.jsonSchema,
},
},
};
static fromJSON(json) {
return new this(json.items);
}
}
class SetStorageSubscriptionRequest {
static type = "request";
static src = "control";
static dst = "controller";
static plugin = "subspace_storage";
static permission = "subspace_storage.storage.view";
/** @type {boolean} */
storage;
constructor(storage) {
this.storage = storage;
}
static jsonSchema = {
type: "object",
required: ["storage"],
properties: {
"storage": { type: "boolean" },
},
};
static fromJSON(json) {
return new this(json.storage);
}
}
module.exports = {
Item,
PlaceEvent,
RemoveRequest,
GetStorageRequest,
UpdateStorageEvent,
SetStorageSubscriptionRequest,
};