Barazo AppView backend
barazo.forum
1import { z } from 'zod/v4'
2
3// ---------------------------------------------------------------------------
4// Query schemas
5// ---------------------------------------------------------------------------
6
7/** Schema for validating search query parameters. */
8export const searchQuerySchema = z.object({
9 q: z
10 .string()
11 .min(1, 'Search query is required')
12 .max(500, 'Search query must be at most 500 characters'),
13 category: z.string().optional(),
14 author: z.string().optional(),
15 dateFrom: z.iso.datetime().optional(),
16 dateTo: z.iso.datetime().optional(),
17 type: z.enum(['topics', 'replies', 'all']).default('all'),
18 limit: z
19 .string()
20 .transform((val) => Number(val))
21 .pipe(z.number().int().min(1).max(100))
22 .optional()
23 .default(25),
24 cursor: z.string().optional(),
25})
26
27export type SearchQueryInput = z.infer<typeof searchQuerySchema>
28
29// ---------------------------------------------------------------------------
30// Response schemas (for OpenAPI documentation)
31// ---------------------------------------------------------------------------
32
33/** Schema describing a single search result in API responses. */
34export const searchResultSchema = z.object({
35 type: z.enum(['topic', 'reply']),
36 uri: z.string(),
37 rkey: z.string(),
38 authorDid: z.string(),
39 title: z.string().nullable(),
40 content: z.string(),
41 category: z.string().nullable(),
42 communityDid: z.string(),
43 replyCount: z.number().nullable(),
44 reactionCount: z.number(),
45 createdAt: z.string(),
46 rank: z.number(),
47 // Reply-specific context
48 rootUri: z.string().nullable(),
49 rootTitle: z.string().nullable(),
50})
51
52export type SearchResult = z.infer<typeof searchResultSchema>
53
54/** Schema for the search response. */
55export const searchResponseSchema = z.object({
56 results: z.array(searchResultSchema),
57 cursor: z.string().nullable(),
58 total: z.number(),
59 searchMode: z.enum(['fulltext', 'hybrid']),
60})
61
62export type SearchResponse = z.infer<typeof searchResponseSchema>