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:
Alexis Faizeau
2022-04-12 14:21:19 +02:00
committed by GitHub
parent 41e62051d4
commit d1e8243c47
161 changed files with 1131 additions and 1248 deletions
@@ -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";
+9 -10
View File
@@ -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>;
+8 -16
View File
@@ -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>;
+2 -3
View File
@@ -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 {
+9 -10
View File
@@ -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>;