# Check Zod usage follows the schema-at-boundary convention: every exported
# schema has a matching `z.infer<typeof X>` type export, and no schema uses
# `z.any()` (an escape hatch that defeats the point of validating boundaries).
# Usage: check_schema_boundary.sh <schema-file-or-dir>
files=$(find "$TARGET" -name '*.ts' 2>/dev/null | xargs grep -l 'z\.object\|z\.union\|z\.discriminatedUnion' 2>/dev/null)
if [[ -z "$files" ]]; then
echo "⚠️ no zod schema files found under $TARGET"
schemas=$(grep -oE 'export const [A-Za-z0-9_]+Schema' "$f" | awk '{print $3}')
if grep -q "z\.infer<typeof ${s}>" "$f"; then
echo "✅ $f: $s has a matching z.infer type export"
echo "❌ $f: $s has no \`z.infer<typeof $s>\` export (expected something like: export type $typename = z.infer<typeof $s>)"
if grep -q 'z\.any()' "$f"; then
echo "❌ $f: uses z.any() — replace with a real shape or z.unknown() + a narrowing check"