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>;