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,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>;
|
||||
|
||||
Reference in New Issue
Block a user