59 lines
1.3 KiB
TypeScript
59 lines
1.3 KiB
TypeScript
import { z } from 'zod'
|
|
|
|
const SystemConfig = z.strictObject({
|
|
logs: z.strictObject({
|
|
debug: z.boolean(),
|
|
warn: z.boolean(),
|
|
error: z.boolean(),
|
|
events: z.boolean(),
|
|
packets: z.boolean()
|
|
}),
|
|
|
|
fps: z
|
|
.strictObject({
|
|
max: z.number(),
|
|
animation: z.number().min(24)
|
|
})
|
|
.refine(
|
|
(ctx) => ctx.animation <= ctx.max,
|
|
(ctx) => ({ message: `Number must not exceed ${ctx.max} max FPS`, path: ['animation'] })
|
|
),
|
|
|
|
pong: z.strictObject({
|
|
manually: z.boolean(),
|
|
interval: z
|
|
.number()
|
|
.min(5 * 1000)
|
|
.max(60 * 1000)
|
|
})
|
|
})
|
|
|
|
const URLConfig = z.strictObject({
|
|
socket: z.string().refine((value) => value.startsWith('ws://') && /\b(?:\d{1,3}\.){3}\d{1,3}:\d{1,5}\b/.test(value), {
|
|
message: 'Invalid socket URL format'
|
|
}),
|
|
client: z
|
|
.string()
|
|
.refine((value) => /^(ht{2}ps?:\/{2})?((([\da-z-]+\.)+[a-z]{2,})|((?:\d{1,3}\.){3}\d{1,3}))(\/.*)?$/i.test(value), {
|
|
message: 'Invalid HTTP URL format'
|
|
})
|
|
})
|
|
|
|
const CommonKeys = {
|
|
enabled: z.boolean()
|
|
}
|
|
|
|
const GameSchema = z.strictObject({
|
|
hc: z.strictObject({ ...CommonKeys }),
|
|
camera: z.strictObject({ ...CommonKeys }),
|
|
pets: z.array(z.string())
|
|
})
|
|
|
|
const GameConfigSchema = z.strictObject({
|
|
system: SystemConfig,
|
|
url: URLConfig,
|
|
game: GameSchema
|
|
})
|
|
|
|
export { GameConfigSchema }
|