import { z } from "zod" const FamilySchema = z.enum(["ip", "ip6"]) const NativeIdSchema = z.string().regex(/^\*[A-Za-z0-9]+$/).max(100) export const AddressKeySchema = z.object({ serverId: z.string().min(1), family: FamilySchema, rosId: NativeIdSchema, }) export const AddressWriteSchema = z.object({ serverId: z.string().min(1), family: FamilySchema, rosId: NativeIdSchema.optional(), list: z.string().min(1), address: z.string().min(1), comment: z.string().optional(), timeout: z.string().optional(), disabled: z.boolean().optional(), }) export const AddressPatchSchema = AddressKeySchema.extend({ disabled: z.boolean(), }) function toRosBody(obj: Record): Record { const out: Record = {} for (const [k, v] of Object.entries(obj)) { if (v !== undefined && v !== "") out[k] = v } return out } export function addressToRos(d: z.infer): Record { return toRosBody({ list: d.list, address: d.address, comment: d.comment, timeout: d.timeout, disabled: d.disabled === true ? "yes" : d.disabled === false ? "no" : undefined, }) }