leaky-ships/leaky-ships/lib/zodSchemas.ts
aronmal 61ae4b901d
Game settings and better socket performance
- Added game settings
- Reworked GamePropsSchema for only relevant information
-> Prisma schema and zod object
- Imporved toast notifications
- No duplicate socket connections anymore
- Using now Zustand for the gameProps instead of React Context & State
2023-05-10 21:02:22 +02:00

47 lines
1 KiB
TypeScript

import { GameState, PlayerN } from "@prisma/client"
import { z } from "zod"
export const PlayerSchema = z.object({
id: z.string(),
name: z.string().nullable(),
index: z.nativeEnum(PlayerN),
chats: z
.object({
id: z.string(),
event: z.string().nullable(),
message: z.string().nullable(),
createdAt: z.date(),
})
.array(),
moves: z
.object({
id: z.string(),
index: z.number(),
})
.array(),
})
export const CreateSchema = z
.object({
game: z
.object({
id: z.string(),
state: z.nativeEnum(GameState),
allowSpectators: z.boolean(),
allowSpecials: z.boolean(),
allowChat: z.boolean(),
allowMarkDraw: z.boolean(),
})
.nullable(),
gamePin: z.string().nullable(),
player1: PlayerSchema.nullable(),
player2: PlayerSchema.nullable(),
})
.strict()
export const GamePropsSchema = z.object({
payload: CreateSchema.nullable(),
hash: z.string().nullable(),
})
export type GamePropsSchema = z.infer<typeof GamePropsSchema>