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
+10 -13
View File
@@ -1,19 +1,16 @@
import * as tg from "generic-type-guard";
import { z } from "zod";
/*
* WARNING! The original file is in /messages/JsonMessages.
* All other files are automatically copied from this file on container startup / build
*/
export const isAdminApiData = new tg.IsInterface()
.withProperties({
userUuid: tg.isString,
email: tg.isNullable(tg.isString),
roomUrl: tg.isString,
mapUrlStart: tg.isString,
})
.withOptionalProperties({
messages: tg.isArray(tg.isUnknown),
})
.get();
export type AdminApiData = tg.GuardedType<typeof isAdminApiData>;
export const isAdminApiData = z.object({
userUuid: z.string(),
email: z.nullable(z.string()),
roomUrl: z.string(),
mapUrlStart: z.string(),
messages: z.optional(z.array(z.unknown())),
});
export type AdminApiData = z.infer<typeof isAdminApiData>;
+21 -25
View File
@@ -1,32 +1,28 @@
import * as tg from "generic-type-guard";
import { isNumber } from "generic-type-guard";
import { z } from "zod";
/*
* WARNING! The original file is in /messages/JsonMessages.
* All other files are automatically copied from this file on container startup / build
*/
export const isMapDetailsData = new tg.IsInterface()
.withProperties({
mapUrl: tg.isString,
policy_type: isNumber, //isNumericEnum(GameRoomPolicyTypes),
tags: tg.isArray(tg.isString),
authenticationMandatory: tg.isUnion(tg.isNullable(tg.isBoolean), tg.isUndefined),
roomSlug: tg.isNullable(tg.isString), // deprecated
contactPage: tg.isNullable(tg.isString),
group: tg.isNullable(tg.isString),
})
.withOptionalProperties({
iframeAuthentication: tg.isNullable(tg.isString),
// The date (in ISO 8601 format) at which the room will expire
expireOn: tg.isString,
// Whether the "report" feature is enabled or not on this room
canReport: tg.isBoolean,
// The URL of the logo image on the loading screen
loadingLogo: tg.isNullable(tg.isString),
// The URL of the logo image on "LoginScene"
loginSceneLogo: tg.isNullable(tg.isString),
})
.get();
export const isMapDetailsData = z.object({
mapUrl: z.string(),
policy_type: z.number(),
tags: z.array(z.string()),
authenticationMandatory: z.optional(z.nullable(z.boolean())),
roomSlug: z.nullable(z.string()), // deprecated
contactPage: z.nullable(z.string()),
group: z.nullable(z.string()),
export type MapDetailsData = tg.GuardedType<typeof isMapDetailsData>;
iframeAuthentication: z.optional(z.nullable(z.string())),
// The date (in ISO 8601 format) at which the room will expire
expireOn: z.optional(z.string()),
// Whether the "report" feature is enabled or not on this room
canReport: z.optional(z.boolean()),
// The URL of the logo image on the loading screen
loadingLogo: z.optional(z.nullable(z.string())),
// The URL of the logo image on "LoginScene"
loginSceneLogo: z.optional(z.nullable(z.string())),
});
export type MapDetailsData = z.infer<typeof isMapDetailsData>;
+11 -11
View File
@@ -1,6 +1,10 @@
import * as tg from "generic-type-guard";
import { z } from "zod";
/*
* WARNING! The original file is in /messages/JsonMessages.
* All other files are automatically copied from this file on container startup / build
*/
//The list of all the player textures, both the default models and the partial textures used for customization
const wokaTexture = z.object({
@@ -33,16 +37,12 @@ export type WokaList = z.infer<typeof wokaList>;
export const wokaPartNames = ["woka", "body", "eyes", "hair", "clothes", "hat", "accessory"];
export const isWokaDetail = new tg.IsInterface()
.withProperties({
id: tg.isString,
})
.withOptionalProperties({
url: tg.isString,
layer: tg.isString,
})
.get();
export const isWokaDetail = z.object({
id: z.string(),
url: z.optional(z.string()),
layer: z.optional(z.string()),
});
export type WokaDetail = tg.GuardedType<typeof isWokaDetail>;
export type WokaDetail = z.infer<typeof isWokaDetail>;
export type WokaDetailsResult = WokaDetail[];
+12 -16
View File
@@ -1,22 +1,18 @@
import * as tg from "generic-type-guard";
//import { isCharacterTexture } from "./CharacterTexture";
import { z } from "zod";
/*
* WARNING! The original file is in /messages/JsonMessages.
* All other files are automatically copied from this file on container startup / build
*/
export const isRegisterData = new tg.IsInterface()
.withProperties({
roomUrl: tg.isString,
email: tg.isNullable(tg.isString),
organizationMemberToken: tg.isNullable(tg.isString),
mapUrlStart: tg.isString,
userUuid: tg.isString,
authToken: tg.isString,
})
.withOptionalProperties({
messages: tg.isArray(tg.isUnknown),
})
.get();
export type RegisterData = tg.GuardedType<typeof isRegisterData>;
export const isRegisterData = z.object({
roomUrl: z.string(),
email: z.nullable(z.string()),
organizationMemberToken: z.nullable(z.string()),
mapUrlStart: z.string(),
userUuid: z.string(),
authToken: z.string(),
messages: z.optional(z.array(z.unknown())),
});
export type RegisterData = z.infer<typeof isRegisterData>;
+6 -7
View File
@@ -1,13 +1,12 @@
import * as tg from "generic-type-guard";
import { z } from "zod";
/*
* WARNING! The original file is in /messages/JsonMessages.
* All other files are automatically copied from this file on container startup / build
*/
export const isRoomRedirect = new tg.IsInterface()
.withProperties({
redirectUrl: tg.isString,
})
.get();
export type RoomRedirect = tg.GuardedType<typeof isRoomRedirect>;
export const isRoomRedirect = z.object({
redirectUrl: z.string(),
});
export type RoomRedirect = z.infer<typeof isRoomRedirect>;