MCPcopy Index your code
hub / github.com/simstudioai/sim / validateTableSchema

Function validateTableSchema

apps/sim/lib/table/validation.ts:178–211  ·  view source on GitHub ↗
(schema: TableSchema)

Source from the content-addressed store, hash-verified

176
177/** Validates table schema structure and column definitions. */
178export 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. */
214export function validateRowAgainstSchema(data: RowData, schema: TableSchema): ValidationResult {

Callers 2

createTableFunction · 0.90
validation.test.tsFile · 0.90

Calls 2

validateColumnDefinitionFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected