Files
MineGeo/shared/profile-cosmetics.ts
pavel444-byte c541cc09b4
All checks were successful
Deploy MineGeo to Dokploy / deploy (push) Successful in 7m10s
Add public profiles and cosmetic shop
2026-10-15 17:30:10 +05:00

42 lines
1.1 KiB
TypeScript

import { z } from "zod";
import { profileCosmeticIds } from "./profile-cosmetic-ids";
export const profileCosmeticIdSchema = z.enum(profileCosmeticIds);
export type { ProfileCosmeticId } from "./profile-cosmetic-ids";
export const profileCosmeticActionSchema = z.discriminatedUnion("action", [
z
.object({
action: z.literal("purchase"),
cosmeticId: profileCosmeticIdSchema,
})
.strict(),
z
.object({
action: z.literal("equip"),
cosmeticId: profileCosmeticIdSchema.nullable(),
})
.strict(),
]);
export const cosmeticShopStateSchema = z
.object({
balance: z.number().int().nonnegative(),
owned: z.array(profileCosmeticIdSchema),
equipped: profileCosmeticIdSchema.nullable(),
catalog: z.array(
z
.object({
id: profileCosmeticIdSchema,
name: z.string().min(1).max(48),
description: z.string().min(1).max(160),
price: z.number().int().positive(),
rarity: z.enum(["common", "rare", "epic", "legendary"]),
})
.strict(),
),
})
.strict();
export type CosmeticShopState = z.infer<typeof cosmeticShopStateSchema>;