import type { z } from 'zod'; /** * Validate a heterogeneous candidate (single object, array, or null/undefined) against a * Zod schema, keeping only the items that successfully parse. Returns the surviving * items in input order. Empty input or all-failing input both yield `[]` — callers * decide whether to treat that as fatal. * * Implements the "Lenient parse" policy described in CONTEXT.md. */ export function lenientValidateArray(candidates: unknown, schema: z.ZodType): T[] { const arr = Array.isArray(candidates) ? candidates : candidates ? [candidates] : []; const valid: T[] = []; for (const item of arr) { const result = schema.safeParse(item); if (result.success) valid.push(result.data); } return valid; }