@skyblock-finance/schemas
Version:
This package uses [`zod`](https://www.npmjs.com/package/zod) to validate the format of Hypixel Skyblock API responses
59 lines (53 loc) • 1.09 kB
text/typescript
import { z } from 'zod'
import { apiResponseSchema } from '../../common'
import { perkSchema, yearSchema } from './common'
enum MayorKey {
DERP = 'derp',
DUNGEONS = 'dungeons',
ECONOMIST = 'economist',
EVENTS = 'events',
FARMING = 'farming',
FISHING = 'fishing',
JERRY = 'jerry',
MINING = 'mining',
PETS = 'pets',
SHADY = 'shady',
SLAYER = 'slayer',
WIZARD = 'wizard',
}
const candidateSchema = z
.object({
key: z.nativeEnum(MayorKey),
name: z.string(),
perks: z.array(perkSchema.strict()),
votes: z.number().int(),
})
.strict()
export const electionResponseSchemaStrict = apiResponseSchema
.extend({
current: z
.object({
candidates: z.array(candidateSchema),
year: yearSchema,
})
.strict()
.optional(),
mayor: z
.object({
election: z
.object({
candidates: z.array(
candidateSchema.extend({
votes: z.number(),
}),
),
year: yearSchema,
})
.strict(),
key: z.nativeEnum(MayorKey),
name: z.string(),
perks: z.array(perkSchema.strict()),
})
.strict(),
})
.strict()