(value: unknown, outputType: string)
| 71 | * accept so users can specify rich return shapes via a custom validator. |
| 72 | */ |
| 73 | export function validateSchemaOnly(value: unknown, outputType: string): ValidationReport { |
| 74 | const issues: string[] = []; |
| 75 | // File: { path: string, content: string, kind?: string } |
| 76 | if (outputType === "File") { |
| 77 | fileShapeIssues(value, issues, ""); |
| 78 | return finalize(issues, "file"); |
| 79 | } |
| 80 | // list<File> |
| 81 | if (/^list<\s*File\s*>$/.test(outputType)) { |
| 82 | if (!Array.isArray(value)) { |
| 83 | issues.push(`expected list<File>, got ${typeof value}`); |
| 84 | return finalize(issues, "files"); |
| 85 | } |
| 86 | if (value.length === 0) { |
| 87 | issues.push("expected at least one File, got empty array"); |
| 88 | return finalize(issues, "files"); |
| 89 | } |
| 90 | // Defensive: reject duplicate paths early — the consumer will fail later anyway. |
| 91 | const seen = new Set<string>(); |
| 92 | for (let i = 0; i < value.length; i++) { |
| 93 | fileShapeIssues(value[i], issues, `file[${i}]: `); |
| 94 | const f = value[i] as { path?: unknown }; |
| 95 | if (typeof f?.path === "string") { |
| 96 | if (seen.has(f.path)) issues.push(`file[${i}]: duplicate path "${f.path}"`); |
| 97 | seen.add(f.path); |
| 98 | } |
| 99 | } |
| 100 | return finalize(issues, "files"); |
| 101 | } |
| 102 | // Enum: literal set of allowed values. |
| 103 | const enumValues = parseEnumDecl(outputType); |
| 104 | if (enumValues) { |
| 105 | if (typeof value !== "string") { |
| 106 | issues.push(`expected one of [${enumValues.join(", ")}], got ${typeof value}`); |
| 107 | } else if (!enumValues.includes(value)) { |
| 108 | issues.push(`value "${value.slice(0, 64)}" is not in [${enumValues.join(", ")}]`); |
| 109 | } |
| 110 | return finalize(issues, "enum"); |
| 111 | } |
| 112 | // list<T> |
| 113 | const listMatch = outputType.match(/^list<(.+)>$/); |
| 114 | if (listMatch) { |
| 115 | if (!Array.isArray(value)) { |
| 116 | issues.push(`expected list<${listMatch[1]}>, got ${typeof value}`); |
| 117 | } else { |
| 118 | const inner = listMatch[1]; |
| 119 | for (let i = 0; i < value.length; i++) { |
| 120 | const issue = declaredPrimitiveCheck(inner, value[i]); |
| 121 | if (issue) issues.push(`item[${i}]: ${issue}`); |
| 122 | } |
| 123 | } |
| 124 | return finalize(issues, "list"); |
| 125 | } |
| 126 | // Primitive (or json — accepts anything). |
| 127 | const issue = declaredPrimitiveCheck(outputType, value); |
| 128 | if (issue) issues.push(issue); |
| 129 | return finalize(issues, "primitive"); |
| 130 | } |
nothing calls this directly
no test coverage detected