upgrade to zod 4 (#1161)

## Description:
updates zod to v4
closes #873 

## Please complete the following:

- [x] I have added screenshots for all UI updates
- [x] I process any text displayed to the user through translateText()
and I've added it to the en.json file
- [x] I have added relevant tests to the test directory
- [x] I confirm I have thoroughly tested these changes and take full
responsibility for any bugs introduced
- [x] I understand that submitting code with bugs that could have been
caught through manual testing blocks releases and new features for all
contributors

## Please put your Discord username so you can be contacted if a bug or
regression is found:

omrih

---------

Co-authored-by: Scott Anderson <662325+scottanderson@users.noreply.github.com>
This commit is contained in:
Omri
2025-06-19 19:34:05 +00:00
committed by GitHub
co-authored by Scott Anderson
parent e58bc89b67
commit 3597f7b326
9 changed files with 84 additions and 74 deletions
+15 -15
View File
@@ -1,4 +1,4 @@
import { z } from "zod";
import { z } from "zod/v4";
import quickChatData from "../../resources/QuickChat.json" with { type: "json" };
import {
AllPlayers,
@@ -76,14 +76,14 @@ export type ClientMessage =
| ClientLogMessage
| ClientHashMessage;
export type ServerMessage =
| ServerSyncMessage
| ServerTurnMessage
| ServerStartGameMessage
| ServerPingMessage
| ServerDesyncMessage
| ServerPrestartMessage
| ServerErrorMessage;
export type ServerSyncMessage = z.infer<typeof ServerTurnMessageSchema>;
export type ServerTurnMessage = z.infer<typeof ServerTurnMessageSchema>;
export type ServerStartGameMessage = z.infer<
typeof ServerStartGameMessageSchema
>;
@@ -101,7 +101,7 @@ export type ClientHashMessage = z.infer<typeof ClientHashSchema>;
export type AllPlayersStats = z.infer<typeof AllPlayersStatsSchema>;
export type Player = z.infer<typeof PlayerSchema>;
export type GameStartInfo = z.infer<typeof GameStartInfoSchema>;
const PlayerTypeSchema = z.nativeEnum(PlayerType);
const PlayerTypeSchema = z.enum(PlayerType);
export interface GameInfo {
gameID: GameID;
@@ -127,18 +127,18 @@ export enum LogSeverity {
//
export const GameConfigSchema = z.object({
gameMap: z.nativeEnum(GameMapType),
difficulty: z.nativeEnum(Difficulty),
gameType: z.nativeEnum(GameType),
gameMode: z.nativeEnum(GameMode),
gameMap: z.enum(GameMapType),
difficulty: z.enum(Difficulty),
gameType: z.enum(GameType),
gameMode: z.enum(GameMode),
disableNPCs: z.boolean(),
bots: z.number().int().min(0).max(400),
infiniteGold: z.boolean(),
infiniteTroops: z.boolean(),
instantBuild: z.boolean(),
maxPlayers: z.number().optional(),
disabledUnits: z.nativeEnum(UnitType).array().optional(),
playerTeams: z.union([z.number().optional(), z.literal(Duos)]),
disabledUnits: z.enum(UnitType).array().optional(),
playerTeams: z.union([z.number(), z.literal(Duos)]).optional(),
});
export const TeamSchema = z.string();
@@ -150,8 +150,8 @@ const SafeString = z
)
.max(1000);
export const PersistentIdSchema = z.string().uuid();
const JwtTokenSchema = z.string().jwt();
export const PersistentIdSchema = z.uuid();
const JwtTokenSchema = z.jwt();
const TokenSchema = z
.string()
.refine(
@@ -268,14 +268,14 @@ export const TargetTroopRatioIntentSchema = BaseIntentSchema.extend({
export const BuildUnitIntentSchema = BaseIntentSchema.extend({
type: z.literal("build_unit"),
unit: z.nativeEnum(UnitType),
unit: z.enum(UnitType),
x: z.number(),
y: z.number(),
});
export const UpgradeStructureIntentSchema = BaseIntentSchema.extend({
type: z.literal("upgrade_structure"),
unit: z.nativeEnum(UnitType),
unit: z.enum(UnitType),
unitId: z.number(),
});
@@ -426,7 +426,7 @@ export const ClientHashSchema = z.object({
export const ClientLogMessageSchema = z.object({
type: z.literal("log"),
severity: z.nativeEnum(LogSeverity),
severity: z.enum(LogSeverity),
log: ID,
});