mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-17 23:33:12 +09:00
Merge pull request #510 from Cooldude2606/refactor/subscriptions
Refactor/subscriptions - Create a generalized event subscription class
This commit is contained in:
20 files changed
+1048
-696
No files matched your search
@@ -36,34 +36,12 @@ export class HostListRequest {
|
||||
static Response = jsonArray(HostDetails);
|
||||
}
|
||||
|
||||
export class HostSetSubscriptionsRequest {
|
||||
declare ["constructor"]: typeof HostSetSubscriptionsRequest;
|
||||
static type = "request" as const;
|
||||
static src = "control" as const;
|
||||
static dst = "controller" as const;
|
||||
static permission = "core.host.subscribe" as const;
|
||||
|
||||
constructor(
|
||||
public all: boolean,
|
||||
public hostIds: number[],
|
||||
) { }
|
||||
|
||||
static jsonSchema = Type.Object({
|
||||
"all": Type.Boolean(),
|
||||
"hostIds": Type.Array(Type.Integer()),
|
||||
});
|
||||
|
||||
static fromJSON(json: Static<typeof this.jsonSchema>) {
|
||||
return new this(json.all, json.hostIds);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export class HostUpdateEvent {
|
||||
declare ["constructor"]: typeof HostUpdateEvent;
|
||||
static type = "event" as const;
|
||||
static src = "controller" as const;
|
||||
static dst = "control" as const;
|
||||
static permission = "core.host.subscribe" as const;
|
||||
|
||||
constructor(
|
||||
public update: HostDetails,
|
||||
@@ -76,6 +54,10 @@ export class HostUpdateEvent {
|
||||
static fromJSON(json: Static<typeof this.jsonSchema>) {
|
||||
return new this(HostDetails.fromJSON(json.update));
|
||||
}
|
||||
|
||||
get subscriptionChannel() {
|
||||
return this.update.id;
|
||||
}
|
||||
}
|
||||
|
||||
export class HostMetricsRequest {
|
||||
|
||||
@@ -67,33 +67,12 @@ export class InstanceDetailsListRequest {
|
||||
static Response = jsonArray(InstanceDetails);
|
||||
};
|
||||
|
||||
export class InstanceDetailsSetSubscriptionsRequest {
|
||||
declare ["constructor"]: typeof InstanceDetailsSetSubscriptionsRequest;
|
||||
static type = "request" as const;
|
||||
static src = "control" as const;
|
||||
static dst = "controller" as const;
|
||||
static permission = "core.instance.subscribe" as const;
|
||||
|
||||
constructor(
|
||||
public all: boolean = false,
|
||||
public instanceIds: number[] = [],
|
||||
) { }
|
||||
|
||||
static jsonSchema = Type.Object({
|
||||
"all": Type.Boolean(),
|
||||
"instanceIds": Type.Array(Type.Integer()),
|
||||
});
|
||||
|
||||
static fromJSON(json: Static<typeof this.jsonSchema>) {
|
||||
return new this(json.all, json.instanceIds);
|
||||
}
|
||||
};
|
||||
|
||||
export class InstanceDetailsUpdateEvent {
|
||||
declare ["constructor"]: typeof InstanceDetailsUpdateEvent;
|
||||
static type = "event" as const;
|
||||
static src = "controller" as const;
|
||||
static dst = "control" as const;
|
||||
static permission = "core.instance.subscribe" as const;
|
||||
|
||||
constructor(
|
||||
public details: InstanceDetails,
|
||||
@@ -108,6 +87,10 @@ export class InstanceDetailsUpdateEvent {
|
||||
static fromJSON(json: Static<typeof this.jsonSchema>) {
|
||||
return new this(InstanceDetails.fromJSON(json));
|
||||
}
|
||||
|
||||
get subscriptionChannel() {
|
||||
return this.details.id;
|
||||
}
|
||||
};
|
||||
|
||||
export class InstanceCreateRequest {
|
||||
@@ -299,33 +282,12 @@ export class InstanceListSavesRequest {
|
||||
static Response = jsonArray(SaveDetails);
|
||||
}
|
||||
|
||||
export class InstanceSetSaveListSubscriptionsRequest {
|
||||
declare ["constructor"]: typeof InstanceSetSaveListSubscriptionsRequest;
|
||||
static type = "request" as const;
|
||||
static src = "control" as const;
|
||||
static dst = "controller" as const;
|
||||
static permission = "core.instance.save.list_subscribe" as const;
|
||||
|
||||
constructor(
|
||||
public all: boolean = false,
|
||||
public instanceIds: number[] = [],
|
||||
) { }
|
||||
|
||||
static jsonSchema = Type.Object({
|
||||
"all": Type.Boolean(),
|
||||
"instanceIds": Type.Array(Type.Integer()),
|
||||
});
|
||||
|
||||
static fromJSON(json: Static<typeof this.jsonSchema>) {
|
||||
return new this(json.all, json.instanceIds);
|
||||
}
|
||||
};
|
||||
|
||||
export class InstanceSaveListUpdateEvent {
|
||||
declare ["constructor"]: typeof InstanceSaveListUpdateEvent;
|
||||
static type = "event" as const;
|
||||
static src = ["instance", "host", "controller"] as const;
|
||||
static dst = ["controller", "control"] as const;
|
||||
static permission = "core.instance.save.list_subscribe" as const;
|
||||
|
||||
constructor(
|
||||
public instanceId: number,
|
||||
@@ -340,6 +302,10 @@ export class InstanceSaveListUpdateEvent {
|
||||
static fromJSON(json: Static<typeof this.jsonSchema>) {
|
||||
return new this(json.instanceId, json.saves.map(i => SaveDetails.fromJSON(i)));
|
||||
}
|
||||
|
||||
get subscriptionChannel() {
|
||||
return this.instanceId;
|
||||
}
|
||||
}
|
||||
|
||||
export class InstanceCreateSaveRequest {
|
||||
|
||||
@@ -104,28 +104,6 @@ export class ModPackDeleteRequest {
|
||||
}
|
||||
}
|
||||
|
||||
export class ModPackSetSubscriptionsRequest {
|
||||
declare ["constructor"]: typeof ModPackSetSubscriptionsRequest;
|
||||
static type = "request" as const;
|
||||
static src = "control" as const;
|
||||
static dst = "controller" as const;
|
||||
static permission = "core.mod_pack.subscribe" as const;
|
||||
|
||||
constructor(
|
||||
public all: boolean,
|
||||
public modPackIds: number[],
|
||||
) { }
|
||||
|
||||
static jsonSchema = Type.Object({
|
||||
"all": Type.Boolean(),
|
||||
"modPackIds": Type.Array(Type.Integer()),
|
||||
});
|
||||
|
||||
static fromJSON(json: Static<typeof this.jsonSchema>) {
|
||||
return new this(json.all, json.modPackIds);
|
||||
}
|
||||
}
|
||||
|
||||
export class ModGetRequest {
|
||||
declare ["constructor"]: typeof ModGetRequest;
|
||||
static type = "request" as const;
|
||||
@@ -217,28 +195,6 @@ export class ModSearchRequest {
|
||||
};
|
||||
}
|
||||
|
||||
export class ModSetSubscriptionsRequest {
|
||||
declare ["constructor"]: typeof ModSetSubscriptionsRequest;
|
||||
static type = "request" as const;
|
||||
static src = "control" as const;
|
||||
static dst = "controller" as const;
|
||||
static permission = "core.mod.subscribe" as const;
|
||||
|
||||
constructor(
|
||||
public all: boolean,
|
||||
public modNames: string[],
|
||||
) { }
|
||||
|
||||
static jsonSchema = Type.Object({
|
||||
"all": Type.Boolean(),
|
||||
"modNames": Type.Array(Type.String()),
|
||||
});
|
||||
|
||||
static fromJSON(json: Static<typeof this.jsonSchema>) {
|
||||
return new this(json.all, json.modNames);
|
||||
}
|
||||
}
|
||||
|
||||
export class ModDownloadRequest {
|
||||
declare ["constructor"]: typeof ModDownloadRequest;
|
||||
static type = "request" as const;
|
||||
@@ -290,6 +246,7 @@ export class ModPackUpdateEvent {
|
||||
static type = "event" as const;
|
||||
static src = "controller" as const;
|
||||
static dst = "control" as const;
|
||||
static permission = "core.mod_pack.subscribe" as const;
|
||||
|
||||
constructor(
|
||||
public modPack: ModPack,
|
||||
@@ -302,6 +259,10 @@ export class ModPackUpdateEvent {
|
||||
static fromJSON(json: Static<typeof this.jsonSchema>) {
|
||||
return new this(ModPack.fromJSON(json.modPack));
|
||||
}
|
||||
|
||||
get subscriptionChannel() {
|
||||
return this.modPack.id;
|
||||
}
|
||||
}
|
||||
|
||||
export class ModUpdateEvent {
|
||||
@@ -309,6 +270,7 @@ export class ModUpdateEvent {
|
||||
static type = "event" as const;
|
||||
static src = "controller" as const;
|
||||
static dst = "control" as const;
|
||||
static permission = "core.mod.subscribe" as const;
|
||||
|
||||
constructor(
|
||||
public mod: ModInfo,
|
||||
@@ -321,4 +283,8 @@ export class ModUpdateEvent {
|
||||
static fromJSON(json: Static<typeof this.jsonSchema>) {
|
||||
return new this(ModInfo.fromJSON(json.mod));
|
||||
}
|
||||
|
||||
get subscriptionChannel() {
|
||||
return this.mod.name;
|
||||
}
|
||||
}
|
||||
@@ -251,28 +251,6 @@ export class UserListRequest {
|
||||
static Response = jsonArray(RawUser);
|
||||
}
|
||||
|
||||
export class UserSetSubscriptionsRequest {
|
||||
declare ["constructor"]: typeof UserSetSubscriptionsRequest;
|
||||
static type = "request" as const;
|
||||
static src = "control" as const;
|
||||
static dst = "controller" as const;
|
||||
static permission = "core.user.subscribe" as const;
|
||||
|
||||
constructor(
|
||||
public all: boolean,
|
||||
public names: string[],
|
||||
) { }
|
||||
|
||||
static jsonSchema = Type.Object({
|
||||
"all": Type.Boolean(),
|
||||
"names": Type.Array(Type.String()),
|
||||
});
|
||||
|
||||
static fromJSON(json: Static<typeof this.jsonSchema>) {
|
||||
return new this(json.all, json.names);
|
||||
}
|
||||
}
|
||||
|
||||
export class UserCreateRequest {
|
||||
declare ["constructor"]: typeof UserCreateRequest;
|
||||
static type = "request" as const;
|
||||
@@ -460,6 +438,7 @@ export class UserUpdateEvent {
|
||||
static type = "event" as const;
|
||||
static src = "controller" as const;
|
||||
static dst = "control" as const;
|
||||
static permission = "core.user.subscribe" as const;
|
||||
|
||||
constructor(
|
||||
public user: RawUser,
|
||||
@@ -472,4 +451,8 @@ export class UserUpdateEvent {
|
||||
static fromJSON(json: Static<typeof this.jsonSchema>) {
|
||||
return new this(RawUser.fromJSON(json.user));
|
||||
}
|
||||
|
||||
get subscriptionChannel() {
|
||||
return this.user.name;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user