import { z } from "zod/mini" import { NestableContentSchema } from "./nestable" import type { NestableContent } from "./nestable" // Item export const GroupItemContentType = "GroupItemContent" as const export const GroupItemContentSchema: z.ZodMiniType = z.object({ __TYPE__: z.literal(GroupItemContentType), key: z.string(), value: z.array( z.tuple([ z.string(), z.union([ NestableContentSchema, // `lazy` is used to handle circular dependency on GroupContentSchema z.lazy(() => GroupContentSchema), ]), ]), ), }) // Manual type definition to handle circular dependency on GroupItemContentSchema export type GroupItemContent = { __TYPE__: typeof GroupItemContentType key: string value: [string, NestableContent | GroupContent][] } // Group export const GroupContentType = "GroupContentType" as const export const GroupContentSchema = z.object({ __TYPE__: z.literal(GroupContentType), value: z.array(GroupItemContentSchema), }) export type GroupContent = z.infer export const NestableAndGroupContentSchema = z.discriminatedUnion("__TYPE__", [ NestableContentSchema, GroupContentSchema, ]) export type NestableAndGroupContent = NestableContent | GroupContent