17 lines
368 B
TypeScript
17 lines
368 B
TypeScript
type IssueLike = {
|
|
path: PropertyKey[];
|
|
message: string;
|
|
};
|
|
|
|
export function zodIssuesToRecord(issues: IssueLike[]): Record<string, string[]> {
|
|
const out: Record<string, string[]> = {};
|
|
|
|
for (const issue of issues) {
|
|
const key = issue.path.length ? issue.path.join('.') : 'root';
|
|
out[key] ??= [];
|
|
out[key].push(issue.message);
|
|
}
|
|
|
|
return out;
|
|
}
|