Files
factorio-clusterio/plugins/subspace_storage/messages.js
T
Hornwitser 790b03bc03 Fix accidentally duplicated imports
Import lib instead of lib/data in the messages files to avoid these
getting packed with the web build.
2023-06-11 17:30:24 +02:00

164 lines
2.6 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 = {
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 = {
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 = {
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 = {
required: ["storage"],
properties: {
"storage": { type: "boolean" },
},
};
static fromJSON(json) {
return new this(json.storage);
}
}
module.exports = {
Item,
PlaceEvent,
RemoveRequest,
GetStorageRequest,
UpdateStorageEvent,
SetStorageSubscriptionRequest,
};