Barazo AppView backend barazo.forum
at main 95 lines 3.0 kB view raw
1import { z } from 'zod/v4' 2 3// --------------------------------------------------------------------------- 4// Self-label schemas (com.atproto.label.defs#selfLabels) 5// --------------------------------------------------------------------------- 6 7const selfLabelSchema = z.object({ 8 val: z.string().max(128), 9}) 10 11const selfLabelsSchema = z.object({ 12 values: z.array(selfLabelSchema).max(10), 13}) 14 15// --------------------------------------------------------------------------- 16// Request schemas 17// --------------------------------------------------------------------------- 18 19/** Schema for creating a new reply to a topic. */ 20export const createReplySchema = z.object({ 21 content: z 22 .string() 23 .min(1, 'Content is required') 24 .max(50000, 'Content must be at most 50,000 characters'), 25 parentUri: z.string().min(1, 'Parent URI must not be empty').optional(), 26 labels: selfLabelsSchema.optional(), 27}) 28 29export type CreateReplyInput = z.infer<typeof createReplySchema> 30 31/** Schema for updating an existing reply (content and optional labels). */ 32export const updateReplySchema = z.object({ 33 content: z 34 .string() 35 .min(1, 'Content must not be empty') 36 .max(50000, 'Content must be at most 50,000 characters'), 37 labels: selfLabelsSchema.optional(), 38}) 39 40export type UpdateReplyInput = z.infer<typeof updateReplySchema> 41 42// --------------------------------------------------------------------------- 43// Query schemas 44// --------------------------------------------------------------------------- 45 46/** Schema for listing replies with pagination. */ 47export const replyQuerySchema = z.object({ 48 cursor: z.string().optional(), 49 limit: z 50 .string() 51 .transform((val) => Number(val)) 52 .pipe(z.number().int().min(1).max(100)) 53 .optional() 54 .default(25), 55 depth: z 56 .string() 57 .transform((val) => Number(val)) 58 .pipe(z.number().int().min(1).max(100)) 59 .optional() 60 .default(10), 61}) 62 63export type ReplyQueryInput = z.infer<typeof replyQuerySchema> 64 65// --------------------------------------------------------------------------- 66// Response schemas (for OpenAPI documentation) 67// --------------------------------------------------------------------------- 68 69/** Schema describing a single reply in API responses. */ 70export const replyResponseSchema = z.object({ 71 uri: z.string(), 72 rkey: z.string(), 73 authorDid: z.string(), 74 content: z.string(), 75 rootUri: z.string(), 76 rootCid: z.string(), 77 parentUri: z.string(), 78 parentCid: z.string(), 79 labels: z.object({ values: z.array(z.object({ val: z.string() })) }).nullable(), 80 communityDid: z.string(), 81 cid: z.string(), 82 reactionCount: z.number(), 83 createdAt: z.string(), 84 indexedAt: z.string(), 85}) 86 87export type ReplyResponse = z.infer<typeof replyResponseSchema> 88 89/** Schema for a paginated reply list response. */ 90export const replyListResponseSchema = z.object({ 91 replies: z.array(replyResponseSchema), 92 cursor: z.string().nullable(), 93}) 94 95export type ReplyListResponse = z.infer<typeof replyListResponseSchema>