Zod EVERYWHERE (#2027)
* Zod EVERYWHERE * Add no-unused-vars rule to eslint in front * Add no-unused-vars rule to eslint in pusher * Add no-unused-vars rule to eslint in back * Remove unused PlayerTexture guards * Fix data providing on room connection Co-authored-by: Alexis Faizeau <a.faizeau@workadventu.re>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { PositionInterface } from "_Model/PositionInterface";
|
||||
import { PositionInterface } from "../Model/PositionInterface";
|
||||
|
||||
/**
|
||||
* A physical object that can be placed into a Zone
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
* number of players around the current player.
|
||||
*/
|
||||
import { Zone, ZoneEventListener } from "./Zone";
|
||||
import { ViewportInterface } from "_Model/Websocket/ViewportMessage";
|
||||
import { ExSocketInterface } from "_Model/Websocket/ExSocketInterface";
|
||||
import { ViewportInterface } from "../Model/Websocket/ViewportMessage";
|
||||
import { ExSocketInterface } from "../Model/Websocket/ExSocketInterface";
|
||||
//import Debug from "debug";
|
||||
|
||||
//const debug = Debug('positiondispatcher');
|
||||
|
||||
@@ -1,28 +1,18 @@
|
||||
import { ExSocketInterface } from "_Model/Websocket/ExSocketInterface";
|
||||
import { ExSocketInterface } from "../Model/Websocket/ExSocketInterface";
|
||||
import { PositionDispatcher } from "./PositionDispatcher";
|
||||
import { ViewportInterface } from "_Model/Websocket/ViewportMessage";
|
||||
import { ViewportInterface } from "../Model/Websocket/ViewportMessage";
|
||||
import { arrayIntersect } from "../Services/ArrayHelper";
|
||||
import { GroupDescriptor, UserDescriptor, ZoneEventListener } from "_Model/Zone";
|
||||
import { ZoneEventListener } from "../Model/Zone";
|
||||
import { apiClientRepository } from "../Services/ApiClientRepository";
|
||||
import {
|
||||
BatchToPusherMessage,
|
||||
BatchToPusherRoomMessage,
|
||||
EmoteEventMessage,
|
||||
ErrorMessage,
|
||||
GroupLeftZoneMessage,
|
||||
GroupUpdateZoneMessage,
|
||||
RoomMessage,
|
||||
SubMessage,
|
||||
UserJoinedZoneMessage,
|
||||
UserLeftZoneMessage,
|
||||
UserMovedMessage,
|
||||
VariableMessage,
|
||||
VariableWithTagMessage,
|
||||
ZoneMessage,
|
||||
} from "../Messages/generated/messages_pb";
|
||||
import Debug from "debug";
|
||||
import { ClientReadableStream } from "grpc";
|
||||
import { ExAdminSocketInterface } from "_Model/Websocket/ExAdminSocketInterface";
|
||||
|
||||
const debug = Debug("room");
|
||||
|
||||
@@ -121,7 +111,7 @@ export class PusherRoom {
|
||||
}
|
||||
});
|
||||
|
||||
this.backConnection.on("error", (e) => {
|
||||
this.backConnection.on("error", (err) => {
|
||||
if (!this.isClosing) {
|
||||
debug("Error on back connection");
|
||||
this.close();
|
||||
@@ -129,6 +119,7 @@ export class PusherRoom {
|
||||
for (const listener of this.listeners) {
|
||||
listener.disconnecting = true;
|
||||
listener.end(1011, "Connection error between pusher and back server");
|
||||
console.error("Connection error between pusher and back server", err);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,30 +1,24 @@
|
||||
import * as tg from "generic-type-guard";
|
||||
import { z } from "zod";
|
||||
|
||||
export const isBanBannedAdminMessageInterface = new tg.IsInterface()
|
||||
.withProperties({
|
||||
type: tg.isSingletonStringUnion("ban", "banned"),
|
||||
message: tg.isString,
|
||||
userUuid: tg.isString,
|
||||
})
|
||||
.get();
|
||||
export const isBanBannedAdminMessageInterface = z.object({
|
||||
type: z.enum(["ban", "banned"]),
|
||||
message: z.string(),
|
||||
userUuid: z.string(),
|
||||
});
|
||||
|
||||
export const isUserMessageAdminMessageInterface = new tg.IsInterface()
|
||||
.withProperties({
|
||||
event: tg.isSingletonString("user-message"),
|
||||
message: isBanBannedAdminMessageInterface,
|
||||
world: tg.isString,
|
||||
jwt: tg.isString,
|
||||
})
|
||||
.get();
|
||||
export const isUserMessageAdminMessageInterface = z.object({
|
||||
event: z.enum(["user-message"]),
|
||||
message: isBanBannedAdminMessageInterface,
|
||||
world: z.string(),
|
||||
jwt: z.string(),
|
||||
});
|
||||
|
||||
export const isListenRoomsMessageInterface = new tg.IsInterface()
|
||||
.withProperties({
|
||||
event: tg.isSingletonString("listen"),
|
||||
roomIds: tg.isArray(tg.isString),
|
||||
jwt: tg.isString,
|
||||
})
|
||||
.get();
|
||||
export const isListenRoomsMessageInterface = z.object({
|
||||
event: z.enum(["listen"]),
|
||||
roomIds: z.array(z.string()),
|
||||
jwt: z.string(),
|
||||
});
|
||||
|
||||
export const isAdminMessageInterface = tg.isUnion(isUserMessageAdminMessageInterface, isListenRoomsMessageInterface);
|
||||
export const isAdminMessageInterface = z.union([isUserMessageAdminMessageInterface, isListenRoomsMessageInterface]);
|
||||
|
||||
export type AdminMessageInterface = tg.GuardedType<typeof isAdminMessageInterface>;
|
||||
export type AdminMessageInterface = z.infer<typeof isAdminMessageInterface>;
|
||||
|
||||
@@ -1,17 +1,6 @@
|
||||
import { PointInterface } from "./PointInterface";
|
||||
import { Identificable } from "./Identificable";
|
||||
import { ViewportInterface } from "_Model/Websocket/ViewportMessage";
|
||||
import {
|
||||
AdminPusherToBackMessage,
|
||||
BatchMessage,
|
||||
PusherToBackMessage,
|
||||
ServerToAdminClientMessage,
|
||||
ServerToClientMessage,
|
||||
SubMessage,
|
||||
} from "../../Messages/generated/messages_pb";
|
||||
import { AdminPusherToBackMessage, ServerToAdminClientMessage } from "../../Messages/generated/messages_pb";
|
||||
import { compressors } from "hyper-express";
|
||||
import { ClientDuplexStream } from "grpc";
|
||||
import { Zone } from "_Model/Zone";
|
||||
|
||||
export type AdminConnection = ClientDuplexStream<AdminPusherToBackMessage, ServerToAdminClientMessage>;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { PointInterface } from "./PointInterface";
|
||||
import { Identificable } from "./Identificable";
|
||||
import { ViewportInterface } from "_Model/Websocket/ViewportMessage";
|
||||
import { ViewportInterface } from "../../Model/Websocket/ViewportMessage";
|
||||
import {
|
||||
BatchMessage,
|
||||
CompanionMessage,
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
SubMessage,
|
||||
} from "../../Messages/generated/messages_pb";
|
||||
import { ClientDuplexStream } from "grpc";
|
||||
import { Zone } from "_Model/Zone";
|
||||
import { Zone } from "../../Model/Zone";
|
||||
import { compressors } from "hyper-express";
|
||||
import { WokaDetail } from "../../Messages/JsonMessages/PlayerTextures";
|
||||
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import * as tg from "generic-type-guard";
|
||||
import { z } from "zod";
|
||||
|
||||
export const isItemEventMessageInterface = new tg.IsInterface()
|
||||
.withProperties({
|
||||
itemId: tg.isNumber,
|
||||
event: tg.isString,
|
||||
state: tg.isUnknown,
|
||||
parameters: tg.isUnknown,
|
||||
})
|
||||
.get();
|
||||
export type ItemEventMessageInterface = tg.GuardedType<typeof isItemEventMessageInterface>;
|
||||
export const isItemEventMessageInterface = z.object({
|
||||
itemId: z.number(),
|
||||
event: z.string(),
|
||||
state: z.unknown(),
|
||||
parameters: z.unknown(),
|
||||
});
|
||||
|
||||
export type ItemEventMessageInterface = z.infer<typeof isItemEventMessageInterface>;
|
||||
|
||||
@@ -1,18 +1,10 @@
|
||||
import * as tg from "generic-type-guard";
|
||||
import { z } from "zod";
|
||||
|
||||
/*export interface PointInterface {
|
||||
readonly x: number;
|
||||
readonly y: number;
|
||||
readonly direction: string;
|
||||
readonly moving: boolean;
|
||||
}*/
|
||||
export const isPointInterface = z.object({
|
||||
x: z.number(),
|
||||
y: z.number(),
|
||||
direction: z.string(),
|
||||
moving: z.boolean(),
|
||||
});
|
||||
|
||||
export const isPointInterface = new tg.IsInterface()
|
||||
.withProperties({
|
||||
x: tg.isNumber,
|
||||
y: tg.isNumber,
|
||||
direction: tg.isString,
|
||||
moving: tg.isBoolean,
|
||||
})
|
||||
.get();
|
||||
export type PointInterface = tg.GuardedType<typeof isPointInterface>;
|
||||
export type PointInterface = z.infer<typeof isPointInterface>;
|
||||
|
||||
@@ -5,10 +5,9 @@ import {
|
||||
PointMessage,
|
||||
PositionMessage,
|
||||
} from "../../Messages/generated/messages_pb";
|
||||
import { ExSocketInterface } from "_Model/Websocket/ExSocketInterface";
|
||||
import Direction = PositionMessage.Direction;
|
||||
import { ItemEventMessageInterface } from "_Model/Websocket/ItemEventMessage";
|
||||
import { PositionInterface } from "_Model/PositionInterface";
|
||||
import { ItemEventMessageInterface } from "../../Model/Websocket/ItemEventMessage";
|
||||
import { PositionInterface } from "../../Model/PositionInterface";
|
||||
import { WokaDetail } from "../../Messages/JsonMessages/PlayerTextures";
|
||||
|
||||
export class ProtobufUtils {
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import * as tg from "generic-type-guard";
|
||||
import { z } from "zod";
|
||||
|
||||
export const isViewport = new tg.IsInterface()
|
||||
.withProperties({
|
||||
left: tg.isNumber,
|
||||
top: tg.isNumber,
|
||||
right: tg.isNumber,
|
||||
bottom: tg.isNumber,
|
||||
})
|
||||
.get();
|
||||
export type ViewportInterface = tg.GuardedType<typeof isViewport>;
|
||||
export const isViewport = z.object({
|
||||
left: z.number(),
|
||||
top: z.number(),
|
||||
right: z.number(),
|
||||
bottom: z.number(),
|
||||
});
|
||||
|
||||
export type ViewportInterface = z.infer<typeof isViewport>;
|
||||
|
||||
@@ -20,7 +20,7 @@ import {
|
||||
SetPlayerDetailsMessage,
|
||||
} from "../Messages/generated/messages_pb";
|
||||
import { ClientReadableStream } from "grpc";
|
||||
import { PositionDispatcher } from "_Model/PositionDispatcher";
|
||||
import { PositionDispatcher } from "../Model/PositionDispatcher";
|
||||
import Debug from "debug";
|
||||
import { BoolValue, UInt32Value } from "google-protobuf/google/protobuf/wrappers_pb";
|
||||
|
||||
@@ -427,7 +427,7 @@ export class Zone {
|
||||
}
|
||||
}
|
||||
|
||||
for (const [groupId, group] of this.groups.entries()) {
|
||||
for (const group of this.groups.values()) {
|
||||
this.socketListener.onGroupEnters(group, listener);
|
||||
}
|
||||
|
||||
@@ -436,13 +436,13 @@ export class Zone {
|
||||
}
|
||||
|
||||
public stopListening(listener: ExSocketInterface): void {
|
||||
for (const [userId, user] of this.users.entries()) {
|
||||
for (const userId of this.users.keys()) {
|
||||
if (userId !== listener.userId) {
|
||||
this.socketListener.onUserLeaves(userId, listener);
|
||||
}
|
||||
}
|
||||
|
||||
for (const [groupId, group] of this.groups.entries()) {
|
||||
for (const groupId of this.groups.keys()) {
|
||||
this.socketListener.onGroupLeaves(groupId, listener);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user