mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-16 23:30:41 +09:00
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.
This commit is contained in:
1 parent
bb58670597
commit
bfe119eaa3
143 files changed
+1798
-1918
No files matched your search
@@ -2,11 +2,8 @@
|
||||
const fs = require("fs-extra");
|
||||
const path = require("path");
|
||||
|
||||
const libDatabase = require("@clusterio/lib/database");
|
||||
const libFileOps = require("@clusterio/lib/file_ops");
|
||||
const libPlugin = require("@clusterio/lib/plugin");
|
||||
const { Counter, Gauge } = require("@clusterio/lib/prometheus");
|
||||
const RateLimiter = require("@clusterio/lib/RateLimiter");
|
||||
const lib = require("@clusterio/lib");
|
||||
const { Counter, Gauge, RateLimiter } = lib;
|
||||
|
||||
const routes = require("./routes");
|
||||
const dole = require("./dole");
|
||||
@@ -43,12 +40,12 @@ async function loadDatabase(config, logger) {
|
||||
logger.verbose(`Loading ${itemsPath}`);
|
||||
try {
|
||||
let content = await fs.readFile(itemsPath);
|
||||
return new libDatabase.ItemDatabase(JSON.parse(content));
|
||||
return new lib.ItemDatabase(JSON.parse(content));
|
||||
|
||||
} catch (err) {
|
||||
if (err.code === "ENOENT") {
|
||||
logger.verbose("Creating new item database");
|
||||
return new libDatabase.ItemDatabase();
|
||||
return new lib.ItemDatabase();
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
@@ -59,13 +56,13 @@ async function saveDatabase(controllerConfig, items, logger) {
|
||||
let file = path.resolve(controllerConfig.get("controller.database_directory"), "items.json");
|
||||
logger.verbose(`writing ${file}`);
|
||||
let content = JSON.stringify(items.serialize());
|
||||
await libFileOps.safeOutputFile(file, content);
|
||||
await lib.safeOutputFile(file, content);
|
||||
} else if (items) {
|
||||
logger.error(`Item database too large, not saving (${items.size})`);
|
||||
}
|
||||
}
|
||||
|
||||
class ControllerPlugin extends libPlugin.BaseControllerPlugin {
|
||||
class ControllerPlugin extends lib.BaseControllerPlugin {
|
||||
async init() {
|
||||
|
||||
this.items = await loadDatabase(this.controller.config, this.logger);
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
"use strict";
|
||||
const doleNN = require("./dole_nn_base");
|
||||
|
||||
const { Gauge } = require("@clusterio/lib/prometheus");
|
||||
const lib = require("@clusterio/lib");
|
||||
const { Gauge } = lib;
|
||||
|
||||
|
||||
const prometheusNNDoleGauge = new Gauge(
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
"use strict";
|
||||
const { libConfig, libUsers } = require("@clusterio/lib");
|
||||
const lib = require("@clusterio/lib");
|
||||
const messages = require("./messages");
|
||||
|
||||
class ControllerConfigGroup extends libConfig.PluginConfigGroup {}
|
||||
class ControllerConfigGroup extends lib.PluginConfigGroup {}
|
||||
ControllerConfigGroup.defaultAccess = ["controller", "host", "control"];
|
||||
ControllerConfigGroup.groupName = "subspace_storage";
|
||||
ControllerConfigGroup.define({
|
||||
@@ -29,7 +29,7 @@ ControllerConfigGroup.define({
|
||||
});
|
||||
ControllerConfigGroup.finalize();
|
||||
|
||||
class InstanceConfigGroup extends libConfig.PluginConfigGroup {}
|
||||
class InstanceConfigGroup extends lib.PluginConfigGroup {}
|
||||
InstanceConfigGroup.defaultAccess = ["controller", "host", "control"];
|
||||
InstanceConfigGroup.groupName = "subspace_storage";
|
||||
InstanceConfigGroup.define({
|
||||
@@ -41,7 +41,7 @@ InstanceConfigGroup.define({
|
||||
});
|
||||
InstanceConfigGroup.finalize();
|
||||
|
||||
libUsers.definePermission({
|
||||
lib.definePermission({
|
||||
name: "subspace_storage.storage.view",
|
||||
title: "View Subspace Storage",
|
||||
description: "View the items and fluids stored in the shared subspace.",
|
||||
|
||||
@@ -1,17 +1,14 @@
|
||||
"use strict";
|
||||
const libPlugin = require("@clusterio/lib/plugin");
|
||||
const libLuaTools = require("@clusterio/lib/lua_tools");
|
||||
const lib = require("@clusterio/lib");
|
||||
|
||||
const {
|
||||
Item,
|
||||
PlaceEvent,
|
||||
RemoveRequest,
|
||||
GetStorageRequest,
|
||||
UpdateStorageEvent,
|
||||
SetStorageSubscriptionRequest,
|
||||
} = require("./messages");
|
||||
|
||||
class InstancePlugin extends libPlugin.BaseInstancePlugin {
|
||||
class InstancePlugin extends lib.BaseInstancePlugin {
|
||||
unexpectedError(err) {
|
||||
this.logger.error(`Unexpected error:\n${err.stack}`);
|
||||
}
|
||||
@@ -46,7 +43,7 @@ class InstancePlugin extends libPlugin.BaseInstancePlugin {
|
||||
|
||||
let items = await this.instance.sendTo("controller", new GetStorageRequest());
|
||||
// TODO Diff with dump of invdata produce minimal command to sync
|
||||
let itemsJson = libLuaTools.escapeString(JSON.stringify(items));
|
||||
let itemsJson = lib.escapeString(JSON.stringify(items));
|
||||
await this.sendRcon(`/sc __subspace_storage__ UpdateInvData("${itemsJson}", true)`, true);
|
||||
}
|
||||
|
||||
@@ -93,7 +90,7 @@ class InstancePlugin extends libPlugin.BaseInstancePlugin {
|
||||
this.logger.verbose(JSON.stringify(items));
|
||||
}
|
||||
|
||||
let itemsJson = libLuaTools.escapeString(JSON.stringify(items));
|
||||
let itemsJson = lib.escapeString(JSON.stringify(items));
|
||||
await this.sendRcon(`/sc __subspace_storage__ Import("${itemsJson}")`, true);
|
||||
}
|
||||
|
||||
@@ -107,7 +104,7 @@ class InstancePlugin extends libPlugin.BaseInstancePlugin {
|
||||
// XXX this should be moved to instance/clusterio api
|
||||
items.push(["signal-unixtime", Math.floor(Date.now()/1000)]);
|
||||
|
||||
let itemsJson = libLuaTools.escapeString(JSON.stringify(items));
|
||||
let itemsJson = lib.escapeString(JSON.stringify(items));
|
||||
let task = this.sendRcon(`/sc __subspace_storage__ UpdateInvData("${itemsJson}")`, true);
|
||||
this.pendingTasks.add(task);
|
||||
task.finally(() => { this.pendingTasks.delete(task); });
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
"use strict";
|
||||
const { libData } = require("@clusterio/lib");
|
||||
const lib = require("@clusterio/lib");
|
||||
|
||||
class Item {
|
||||
/** @type {string} */
|
||||
@@ -89,7 +89,7 @@ class RemoveRequest {
|
||||
return new this(json.items);
|
||||
}
|
||||
|
||||
static Response = libData.jsonArray(Item);
|
||||
static Response = lib.jsonArray(Item);
|
||||
}
|
||||
|
||||
class GetStorageRequest {
|
||||
@@ -98,7 +98,7 @@ class GetStorageRequest {
|
||||
static dst = "controller";
|
||||
static plugin = "subspace_storage";
|
||||
static permission = "subspace_storage.storage.view";
|
||||
static Response = libData.jsonArray(Item);
|
||||
static Response = lib.jsonArray(Item);
|
||||
}
|
||||
|
||||
class UpdateStorageEvent {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import React, { useContext, useEffect, useState } from "react";
|
||||
import { Input, Table, Typography } from "antd";
|
||||
|
||||
import { libPlugin } from "@clusterio/lib";
|
||||
import * as lib from "@clusterio/lib";
|
||||
import { notifyErrorHandler, useItemMetadata, useLocale, PageLayout, ControlContext } from "@clusterio/web_ui";
|
||||
import { GetStorageRequest, SetStorageSubscriptionRequest } from "../messages";
|
||||
|
||||
@@ -114,7 +114,7 @@ function StoragePage() {
|
||||
</PageLayout>;
|
||||
}
|
||||
|
||||
export class WebPlugin extends libPlugin.BaseWebPlugin {
|
||||
export class WebPlugin extends lib.BaseWebPlugin {
|
||||
async init() {
|
||||
this.pages = [
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user