(schema: TableSchema)
| 176 | |
| 177 | /** Validates table schema structure and column definitions. */ |
| 178 | export function validateTableSchema(schema: TableSchema): ValidationResult { |
| 179 | const errors: string[] = [] |
| 180 | |
| 181 | if (!schema || typeof schema !== 'object') { |
| 182 | errors.push('Schema is required') |
| 183 | return { valid: false, errors } |
| 184 | } |
| 185 | |
| 186 | if (!Array.isArray(schema.columns)) { |
| 187 | errors.push('Schema must have columns array') |
| 188 | return { valid: false, errors } |
| 189 | } |
| 190 | |
| 191 | if (schema.columns.length === 0) { |
| 192 | errors.push('Schema must have at least one column') |
| 193 | } |
| 194 | |
| 195 | if (schema.columns.length > TABLE_LIMITS.MAX_COLUMNS_PER_TABLE) { |
| 196 | errors.push(`Schema exceeds maximum columns (${TABLE_LIMITS.MAX_COLUMNS_PER_TABLE})`) |
| 197 | } |
| 198 | |
| 199 | for (const column of schema.columns) { |
| 200 | const columnResult = validateColumnDefinition(column) |
| 201 | errors.push(...columnResult.errors) |
| 202 | } |
| 203 | |
| 204 | const columnNames = schema.columns.map((c) => c.name.toLowerCase()) |
| 205 | const uniqueNames = new Set(columnNames) |
| 206 | if (uniqueNames.size !== columnNames.length) { |
| 207 | errors.push('Duplicate column names found') |
| 208 | } |
| 209 | |
| 210 | return { valid: errors.length === 0, errors } |
| 211 | } |
| 212 | |
| 213 | /** Validates row data matches schema column types and required fields. */ |
| 214 | export function validateRowAgainstSchema(data: RowData, schema: TableSchema): ValidationResult { |
no test coverage detected