mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-06-01 00:13:20 -05:00
* Initial * CSS lint * Test CI * Add 1v1, 2v2, and 3v3 Tags (#1771) * Initial * CSS lint * Test CI * Rename step --------- Co-authored-by: xi <104683822+ximk@users.noreply.github.com>
39 lines
898 B
TypeScript
39 lines
898 B
TypeScript
import { z } from "zod";
|
|
import { ability, modeShort, safeJSONParse } from "~/utils/zod";
|
|
import { MAX_BUILD_FILTERS } from "./builds-constants";
|
|
|
|
const abilityFilterSchema = z.object({
|
|
type: z.literal("ability"),
|
|
ability: z.string().toUpperCase().pipe(ability),
|
|
value: z.union([z.number(), z.boolean()]),
|
|
comparison: z
|
|
.string()
|
|
.toUpperCase()
|
|
.pipe(z.enum(["AT_LEAST", "AT_MOST"]))
|
|
.optional(),
|
|
});
|
|
|
|
const modeFilterSchema = z.object({
|
|
type: z.literal("mode"),
|
|
mode: modeShort,
|
|
});
|
|
|
|
const dateFilterSchema = z.object({
|
|
type: z.literal("date"),
|
|
date: z.string(),
|
|
});
|
|
|
|
export const buildFiltersSearchParams = z.preprocess(
|
|
safeJSONParse,
|
|
z.union([
|
|
z.null(),
|
|
z
|
|
.array(z.union([abilityFilterSchema, modeFilterSchema, dateFilterSchema]))
|
|
.max(MAX_BUILD_FILTERS),
|
|
]),
|
|
);
|
|
|
|
export type BuildFiltersFromSearchParams = NonNullable<
|
|
z.infer<typeof buildFiltersSearchParams>
|
|
>;
|