Files
factorio-clusterio/packages/lib/data/messages_mod.js
T
Hornwitser bfe119eaa3 Flatten lib namespace
Move all functions and classes currently available through lib/name and
libName to be under a single flat namespace in lib.  This make
reorganising the lib namespace much simpler as the location of symbols
can move without breaking the consumers of lib.

The multi-entrypoint design was already problematic for the web plugin
system which couldn't effectively use it due to how webpack's shared
module system is awkward to set up with multiple entrypoints per package.
2023-07-28 16:03:29 +02:00

475 lines
8.9 KiB
JavaScript

"use strict";
const ModPack = require("./ModPack");
const ModInfo = require("./ModInfo");
const { jsonArray, JsonString } = require("./composites");
/* @memberof module:lib */
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 */
class ModPackGetDefaultRequest {
static type = "request";
static src = ["instance", "control"];
static dst = "controller";
static permission = "core.mod_pack.get";
static Response = ModPack;
}
/* @memberof module:lib */
class ModPackListRequest {
static type = "request";
static src = "control";
static dst = "controller";
static permission = "core.mod_pack.list";
static Response = jsonArray(ModPack);
}
/** @memberof module:lib */
class ModPackCreateRequest {
static type = "request";
static src = "control";
static dst = "controller";
static permission = "core.mod_pack.create";
/** @type {module:lib.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 */
class ModPackUpdateRequest {
static type = "request";
static src = "control";
static dst = "controller";
static permission = "core.mod_pack.update";
/** @type {module:lib.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 */
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 */
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 */
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 */
class ModListRequest {
static type = "request";
static src = "control";
static dst = "controller";
static permission = "core.mod.list";
static Response = jsonArray(ModInfo);
}
/* @memberof module:lib */
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 */
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 */
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 */
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 */
class ModPackUpdateEvent {
static type = "event";
static src = "controller";
static dst = "control";
/** @type {module:lib.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 */
class ModUpdateEvent {
static type = "event";
static src = "controller";
static dst = "control";
/** @type {module:lib.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,
};