(column: ColumnDefinition)
| 662 | |
| 663 | /** Validates column definition format and type. */ |
| 664 | export function validateColumnDefinition(column: ColumnDefinition): ValidationResult { |
| 665 | const errors: string[] = [] |
| 666 | |
| 667 | if (!column.name || typeof column.name !== 'string') { |
| 668 | errors.push('Column name is required') |
| 669 | return { valid: false, errors } |
| 670 | } |
| 671 | |
| 672 | if (column.name.length > TABLE_LIMITS.MAX_COLUMN_NAME_LENGTH) { |
| 673 | errors.push( |
| 674 | `Column name "${column.name}" exceeds maximum length (${TABLE_LIMITS.MAX_COLUMN_NAME_LENGTH} characters)` |
| 675 | ) |
| 676 | } |
| 677 | |
| 678 | if (!NAME_PATTERN.test(column.name)) { |
| 679 | errors.push( |
| 680 | `Column name "${column.name}" must start with letter or underscore, followed by alphanumeric or underscore` |
| 681 | ) |
| 682 | } |
| 683 | |
| 684 | if (!COLUMN_TYPES.includes(column.type)) { |
| 685 | errors.push( |
| 686 | `Column "${column.name}" has invalid type "${column.type}". Valid types: ${COLUMN_TYPES.join(', ')}` |
| 687 | ) |
| 688 | } |
| 689 | |
| 690 | return { valid: errors.length === 0, errors } |
| 691 | } |
no test coverage detected