mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-22 08:13:12 +09:00
Port remaining plugins to Typescript (#499)
* .js to .ts * Allow access to _items entries; getItemCount return number * add permission field to PluginPage interface * port plugins to typescript * update Request classes * fix IpcFlowType
This commit is contained in:
1 parent
50f12c719b
commit
0b3550b472
51 files changed
+1033
-1026
No files matched your search
@@ -0,0 +1,172 @@
|
||||
import type { IpcPlayerData } from "./instance";
|
||||
|
||||
import { Type, Static } from "@sinclair/typebox";
|
||||
import { StringEnum } from "@clusterio/lib";
|
||||
|
||||
const jsonPlayerData = Type.Object({
|
||||
generation: Type.Number(),
|
||||
name: Type.String(),
|
||||
})
|
||||
|
||||
class AcquireResponse {
|
||||
constructor(
|
||||
public status: string,
|
||||
public generation?: number,
|
||||
public hasData?: boolean,
|
||||
public message?: string,
|
||||
) {
|
||||
}
|
||||
|
||||
static jsonSchema = Type.Object({
|
||||
"status": StringEnum(["acquired", "error", "busy"]),
|
||||
"generation": Type.Optional(Type.Integer()),
|
||||
"hasData": Type.Optional(Type.Boolean()),
|
||||
"message": Type.Optional(Type.String()),
|
||||
});
|
||||
|
||||
static fromJSON(json: Static<typeof AcquireResponse.jsonSchema>): AcquireResponse {
|
||||
return new this(json.status, json.generation, json.hasData, json.message);
|
||||
}
|
||||
};
|
||||
export class AcquireRequest {
|
||||
declare ["constructor"]: typeof AcquireRequest;
|
||||
static type = "request" as const;
|
||||
static src = "instance" as const;
|
||||
static dst = "controller" as const;
|
||||
static plugin = "inventory_sync" as const;
|
||||
static Response = AcquireResponse;
|
||||
|
||||
constructor(
|
||||
public instanceId: number,
|
||||
public playerName: string,
|
||||
) {
|
||||
}
|
||||
|
||||
static jsonSchema = Type.Object({
|
||||
"instanceId": Type.Number(),
|
||||
"playerName": Type.String(),
|
||||
})
|
||||
|
||||
static fromJSON(json: Static<typeof AcquireRequest.jsonSchema>): AcquireRequest {
|
||||
return new this(json.instanceId, json.playerName);
|
||||
}
|
||||
}
|
||||
|
||||
export class ReleaseRequest {
|
||||
declare ["constructor"]: typeof ReleaseRequest;
|
||||
static type = "request" as const;
|
||||
static src = "instance" as const;
|
||||
static dst = "controller" as const;
|
||||
static plugin = "inventory_sync" as const;
|
||||
|
||||
constructor(
|
||||
public instanceId: number,
|
||||
public playerName: string
|
||||
) {
|
||||
}
|
||||
|
||||
static jsonSchema = Type.Object({
|
||||
"instanceId": Type.Integer(),
|
||||
"playerName": Type.String(),
|
||||
})
|
||||
|
||||
static fromJSON(json: Static<typeof ReleaseRequest.jsonSchema>) {
|
||||
return new this(json.instanceId, json.playerName);
|
||||
}
|
||||
}
|
||||
|
||||
export class UploadRequest {
|
||||
declare ["constructor"]: typeof UploadRequest;
|
||||
static type = "request" as const;
|
||||
static src = "instance" as const;
|
||||
static dst = "controller" as const;
|
||||
static plugin = "inventory_sync" as const;
|
||||
|
||||
constructor(
|
||||
public instanceId: number,
|
||||
public playerName: string,
|
||||
public playerData: IpcPlayerData,
|
||||
) {
|
||||
}
|
||||
|
||||
static jsonSchema = Type.Object({
|
||||
"instanceId": Type.Integer(),
|
||||
"playerName": Type.String(),
|
||||
"playerData": jsonPlayerData,
|
||||
});
|
||||
|
||||
static fromJSON(json: Static<typeof UploadRequest.jsonSchema>) {
|
||||
return new this(json.instanceId, json.playerName, json.playerData as IpcPlayerData);
|
||||
}
|
||||
}
|
||||
|
||||
class DownloadResponse {
|
||||
constructor(
|
||||
public playerData: IpcPlayerData | null
|
||||
) {
|
||||
}
|
||||
|
||||
static jsonSchema = Type.Object({
|
||||
"playerData": Type.Optional(jsonPlayerData),
|
||||
})
|
||||
|
||||
static fromJSON(json: Static<typeof DownloadResponse.jsonSchema>): DownloadResponse {
|
||||
return new this(json.playerData as IpcPlayerData);
|
||||
}
|
||||
}
|
||||
|
||||
export class DownloadRequest {
|
||||
declare ["constructor"]: typeof DownloadRequest;
|
||||
static type = "request" as const;
|
||||
static src = "instance" as const;
|
||||
static dst = "controller" as const;
|
||||
static plugin = "inventory_sync" as const;
|
||||
static Response = DownloadResponse;
|
||||
|
||||
constructor(
|
||||
public instanceId: number,
|
||||
public playerName: string,
|
||||
) {
|
||||
}
|
||||
|
||||
static jsonSchema = Type.Object({
|
||||
"instanceId": Type.Integer(),
|
||||
"playerName": Type.String(),
|
||||
})
|
||||
|
||||
static fromJSON(json: Static<typeof DownloadRequest.jsonSchema>) {
|
||||
return new this(json.instanceId, json.playerName);
|
||||
}
|
||||
}
|
||||
|
||||
class DatabaseStatsResponse {
|
||||
constructor(
|
||||
public databaseSize: number,
|
||||
public databaseEntries: number,
|
||||
public largestEntry: { name: string, size: number },
|
||||
) {
|
||||
}
|
||||
|
||||
static jsonSchema = Type.Object({
|
||||
"databaseSize": Type.Integer(),
|
||||
"databaseEntries": Type.Integer(),
|
||||
"largestEntry": Type.Object({
|
||||
"name": Type.String(),
|
||||
"size": Type.Number(),
|
||||
})
|
||||
})
|
||||
|
||||
static fromJSON(json: Static<typeof DatabaseStatsResponse.jsonSchema>): DatabaseStatsResponse {
|
||||
return new this(json.databaseSize, json.databaseEntries, json.largestEntry);
|
||||
}
|
||||
}
|
||||
|
||||
export class DatabaseStatsRequest {
|
||||
declare ["constructor"]: typeof DatabaseStatsRequest;
|
||||
static type = "request" as const;
|
||||
static src = "control" as const;
|
||||
static dst = "controller" as const;
|
||||
static plugin = "inventory_sync" as const;
|
||||
static permission = "inventory_sync.inventory.view" as const;
|
||||
static Response = DatabaseStatsResponse;
|
||||
}
|
||||
Reference in new issue
Block a user