1
4
5import { z } from "zod";
6
7import { LIMITS } from "../constants.js";
8
9
10export const searchTypeSchema = z.enum([
11 "page",
12 "block",
13 "database",
14 "record",
15 "comment",
16 "file",
17 "user",
18]);
19export type SearchType = z.infer<typeof searchTypeSchema>;
20
21const isoDate = z
22 .string()
23 .refine((s) => Number.isFinite(Date.parse(s)), { message: "invalid ISO date" });
24
25export const searchRequestSchema = z
26 .object({
27 query: z.string().min(1, "Query is required").max(500),
28 types: z.array(searchTypeSchema).min(1).max(7).optional(),
29 workspaceId: z.string().min(1).optional(),
30 teamId: z.string().min(1).optional(),
31 updatedFrom: isoDate.optional(),
32 updatedTo: isoDate.optional(),
33
34 cursor: z.string().min(1).optional(),
35 limit: z.number().int().min(1).max(LIMITS.MAX_SEARCH_LIMIT).default(20),
36 })
37 .strict();
38export type SearchRequest = z.infer<typeof searchRequestSchema>;
39