SPB Git

Repository Public

schemas.ts 2.0 KB 35 lines typescript

1import { z } from "zod";23export const uuid = z.string().uuid();4export const ids = z.array(uuid).min(1).max(500);5const text = (max: number) => z.string().trim().min(1).max(max);6export const year = z.number().int().min(1000).max(2999).nullable();78export function page(url: URL, def = 50, max = 100) {9  const limit = Math.min(max, Math.max(1, Number(url.searchParams.get("limit")) || def));10  const offset = Math.max(0, Math.min(1_000_000, Number(url.searchParams.get("offset")) || 0));11  return { limit: Math.floor(limit), offset: Math.floor(offset) };12}13export function oneOf<T extends string>(url: URL, name: string, values: readonly T[], def: T): T {14  const v = url.searchParams.get(name) as T | null;15  return v && values.includes(v) ? v : def;16}1718export const trackPatch = z.object({19  title: text(300).optional(), artist: text(200).optional(), album: text(300).optional(), albumArtist: text(200).optional(),20  trackNo: z.number().int().min(0).max(999).nullable().optional(), discNo: z.number().int().min(1).max(99).optional(),21  year: year.optional(), genre: z.string().trim().max(80).optional(),22}).strict().refine((o) => Object.keys(o).length > 0, "Nothing to change");2324export const albumPatch = z.object({ title: text(300).optional(), artist: text(200).optional(), year: year.optional(), genre: z.string().trim().max(80).optional() })25  .strict().refine((o) => Object.keys(o).length > 0, "Nothing to change");2627export const playbackState = z.object({28  queue: z.array(uuid).max(2000), index: z.number().int().min(0).max(2000), positionMs: z.number().int().min(0).max(86_400_000),29  shuffle: z.boolean(), repeat: z.enum(["off", "all", "one"]), volume: z.number().min(0).max(1),30}).strict();3132export const playlistName = z.object({ name: text(120) }).strict();33export const invite = z.object({ email: z.string().trim().toLowerCase().email().max(200), displayName: text(80), role: z.enum(["admin", "listener"]) }).strict();34export const ACCENTS = ["ember", "violet", "ocean", "forest", "rose", "gold"] as const;35
Files main
Menu

Theme