AnasSarkiz/usb-c-pd-brushed-motor

USB-C PD-powered motor controller with protected input, selectable 5/9/12 V buck supply, MCU qualification, PWM H-bridge drive, overvoltage sensing, regenerative energy-dump resistors, and safety interlocks.

Version
0.0.1-a48-cloud-pipeline9-unrouted-c41d79a-305b1e7a
License
unset
Stars
0

scripts/relevant-schema-issues.ts

import * as circuitJsonSchemas from "circuit-json"
import { z, type ZodError, type ZodIssue } from "zod"

/** Present only branches for this Circuit JSON type; validation remains unchanged. */
export function relevantSchemaIssues(
  element: { type: string },
  error: ZodError,
): ZodIssue[] {
  const schema = Object.entries(circuitJsonSchemas).find(
    ([schemaName]) => schemaName === element.type,
  )?.[1]
  if (schema instanceof z.ZodType) {
    const parsed = schema.safeParse(element)
    if (!parsed.success) return parsed.error.issues
  }
  // Unknown types retain the complete diagnostic; no validation result is changed.
  return error.issues
}