mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-11-16 16:30:42 +09:00
Same changes the other packages got in #475 and #476. The permissions move from definePermission calls into the plugin declaration, with the Permissions augmentation in messages.ts so the web build sees it. "type": "module", .js entrypoints and imports, webpack.config.cjs, and the tap tests use import with --type-strip-only. The web plugin now uses a default export function instead of the deprecated BaseWebPlugin class, like exp_roles. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
233 lines
5.3 KiB
TypeScript
233 lines
5.3 KiB
TypeScript
import * as lib from "@clusterio/lib";
|
|
import { Type, Static } from "@sinclair/typebox";
|
|
|
|
declare module "@clusterio/lib" {
|
|
export interface Permissions {
|
|
"exp_reports.report.get": never;
|
|
"exp_reports.report.list": never;
|
|
"exp_reports.report.subscribe": never;
|
|
"exp_reports.report.create": never;
|
|
"exp_reports.report.delete": never;
|
|
}
|
|
}
|
|
|
|
/*
|
|
Data records
|
|
*/
|
|
|
|
/**
|
|
* A report made against a player.
|
|
*
|
|
* Reports are immutable, so until it is deleted updatedAtMs is when the
|
|
* report was made.
|
|
*/
|
|
export class ReportRecord {
|
|
constructor(
|
|
public id: number,
|
|
public playerName: string,
|
|
public byPlayerName: string,
|
|
public reason: string,
|
|
/** Name of the instance the report was made on, empty when made from the web ui. */
|
|
public instanceName: string,
|
|
public updatedAtMs: number = 0,
|
|
public isDeleted: boolean = false,
|
|
) {}
|
|
|
|
static jsonSchema = Type.Object({
|
|
id: Type.Integer(),
|
|
player_name: Type.String(),
|
|
by_player_name: Type.String(),
|
|
reason: Type.String(),
|
|
instance_name: Type.String(),
|
|
updated_at_ms: Type.Optional(Type.Number()),
|
|
is_deleted: Type.Optional(Type.Boolean()),
|
|
});
|
|
|
|
toJSON() {
|
|
const json: Static<typeof ReportRecord.jsonSchema> = {
|
|
id: this.id,
|
|
player_name: this.playerName,
|
|
by_player_name: this.byPlayerName,
|
|
reason: this.reason,
|
|
instance_name: this.instanceName,
|
|
};
|
|
|
|
if (this.updatedAtMs) {
|
|
json.updated_at_ms = this.updatedAtMs;
|
|
}
|
|
|
|
if (this.isDeleted) {
|
|
json.is_deleted = true;
|
|
}
|
|
|
|
return json;
|
|
}
|
|
|
|
static fromJSON(json: Static<typeof this.jsonSchema>) {
|
|
return new this(
|
|
json.id,
|
|
json.player_name,
|
|
json.by_player_name,
|
|
json.reason,
|
|
json.instance_name,
|
|
json.updated_at_ms ?? 0,
|
|
json.is_deleted ?? false,
|
|
);
|
|
}
|
|
}
|
|
|
|
/*
|
|
Update events
|
|
*/
|
|
|
|
export class ReportUpdatedEvent {
|
|
declare ["constructor"]: typeof ReportUpdatedEvent;
|
|
static plugin = "exp_reports" as const;
|
|
static type = "event" as const;
|
|
static src = "controller" as const;
|
|
static dst = "control" as const;
|
|
static permission = "exp_reports.report.subscribe" as const;
|
|
|
|
constructor(
|
|
public updates: ReportRecord[],
|
|
) {}
|
|
|
|
static jsonSchema = Type.Object({
|
|
updates: Type.Array(ReportRecord.jsonSchema),
|
|
});
|
|
|
|
toJSON() {
|
|
return { updates: this.updates.map(report => report.toJSON()) };
|
|
}
|
|
|
|
static fromJSON(json: Static<typeof this.jsonSchema>) {
|
|
return new this(json.updates.map(report => ReportRecord.fromJSON(report)));
|
|
}
|
|
}
|
|
|
|
/*
|
|
Report requests
|
|
*/
|
|
|
|
/** List every report, or only those against one player. */
|
|
export class ReportListRequest {
|
|
declare ["constructor"]: typeof ReportListRequest;
|
|
static plugin = "exp_reports" as const;
|
|
static type = "request" as const;
|
|
static src = ["control", "instance"] as const;
|
|
static dst = "controller" as const;
|
|
static permission = "exp_reports.report.list" as const;
|
|
static Response = lib.jsonArray(ReportRecord);
|
|
|
|
constructor(
|
|
public playerName?: string,
|
|
) {}
|
|
|
|
static jsonSchema = Type.Object({
|
|
player_name: Type.Optional(Type.String()),
|
|
});
|
|
|
|
toJSON() {
|
|
const json: Static<typeof ReportListRequest.jsonSchema> = {};
|
|
if (this.playerName !== undefined) {
|
|
json.player_name = this.playerName;
|
|
}
|
|
return json;
|
|
}
|
|
|
|
static fromJSON(json: Static<typeof this.jsonSchema>) {
|
|
return new this(json.player_name);
|
|
}
|
|
}
|
|
|
|
export class ReportGetRequest {
|
|
declare ["constructor"]: typeof ReportGetRequest;
|
|
static plugin = "exp_reports" as const;
|
|
static type = "request" as const;
|
|
static src = ["control", "instance"] as const;
|
|
static dst = "controller" as const;
|
|
static permission = "exp_reports.report.get" as const;
|
|
static Response = ReportRecord;
|
|
|
|
constructor(
|
|
public id: number,
|
|
) {}
|
|
|
|
static jsonSchema = Type.Object({
|
|
id: Type.Integer(),
|
|
});
|
|
|
|
toJSON() {
|
|
return { id: this.id };
|
|
}
|
|
|
|
static fromJSON(json: Static<typeof this.jsonSchema>) {
|
|
return new this(json.id);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Report a player.
|
|
*
|
|
* From an instance byPlayerName is the player who made the report. From the
|
|
* web ui it is ignored and the report is made by the user of the connection.
|
|
*/
|
|
export class ReportCreateRequest {
|
|
declare ["constructor"]: typeof ReportCreateRequest;
|
|
static plugin = "exp_reports" as const;
|
|
static type = "request" as const;
|
|
static src = ["control", "instance"] as const;
|
|
static dst = "controller" as const;
|
|
static permission = "exp_reports.report.create" as const;
|
|
static Response = ReportRecord;
|
|
|
|
constructor(
|
|
public playerName: string,
|
|
public reason: string,
|
|
public byPlayerName: string = "",
|
|
) {}
|
|
|
|
static jsonSchema = Type.Object({
|
|
player_name: Type.String(),
|
|
reason: Type.String(),
|
|
by_player_name: Type.String(),
|
|
});
|
|
|
|
toJSON() {
|
|
return {
|
|
player_name: this.playerName,
|
|
reason: this.reason,
|
|
by_player_name: this.byPlayerName,
|
|
};
|
|
}
|
|
|
|
static fromJSON(json: Static<typeof this.jsonSchema>) {
|
|
return new this(json.player_name, json.reason, json.by_player_name);
|
|
}
|
|
}
|
|
|
|
export class ReportDeleteRequest {
|
|
declare ["constructor"]: typeof ReportDeleteRequest;
|
|
static plugin = "exp_reports" as const;
|
|
static type = "request" as const;
|
|
static src = ["control", "instance"] as const;
|
|
static dst = "controller" as const;
|
|
static permission = "exp_reports.report.delete" as const;
|
|
|
|
constructor(
|
|
public id: number,
|
|
) {}
|
|
|
|
static jsonSchema = Type.Object({
|
|
id: Type.Integer(),
|
|
});
|
|
|
|
toJSON() {
|
|
return { id: this.id };
|
|
}
|
|
|
|
static fromJSON(json: Static<typeof this.jsonSchema>) {
|
|
return new this(json.id);
|
|
}
|
|
}
|