* Validate a single source configuration
(source: SourceConfig, configPath: string)
| 371 | * Validate a single source configuration |
| 372 | */ |
| 373 | function validateSourceConfig(source: SourceConfig, configPath: string): void { |
| 374 | const hasConnectionParams = |
| 375 | source.type && (source.type === "sqlite" ? source.database : source.host); |
| 376 | |
| 377 | if (!source.dsn && !hasConnectionParams) { |
| 378 | throw new Error( |
| 379 | `Configuration file ${configPath}: source '${source.id}' must have either:\n` + |
| 380 | ` - 'dsn' field (e.g., dsn = "postgres://user:pass@host:5432/dbname")\n` + |
| 381 | ` - OR connection parameters (type, host, database, user, password)\n` + |
| 382 | ` - For SQLite: type = "sqlite" and database path` |
| 383 | ); |
| 384 | } |
| 385 | |
| 386 | // Validate type if provided |
| 387 | if (source.type) { |
| 388 | const validTypes = ["postgres", "mysql", "mariadb", "sqlserver", "sqlite"]; |
| 389 | if (!validTypes.includes(source.type)) { |
| 390 | throw new Error( |
| 391 | `Configuration file ${configPath}: source '${source.id}' has invalid type '${source.type}'. ` + |
| 392 | `Valid types: ${validTypes.join(", ")}` |
| 393 | ); |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | // Validate AWS IAM auth fields |
| 398 | if ( |
| 399 | source.aws_iam_auth !== undefined && |
| 400 | typeof source.aws_iam_auth !== "boolean" |
| 401 | ) { |
| 402 | throw new Error( |
| 403 | `Configuration file ${configPath}: source '${source.id}' has invalid aws_iam_auth. ` + |
| 404 | `Must be a boolean (true or false).` |
| 405 | ); |
| 406 | } |
| 407 | |
| 408 | if (source.aws_region !== undefined) { |
| 409 | if ( |
| 410 | typeof source.aws_region !== "string" || |
| 411 | source.aws_region.trim().length === 0 |
| 412 | ) { |
| 413 | throw new Error( |
| 414 | `Configuration file ${configPath}: source '${source.id}' has invalid aws_region. ` + |
| 415 | `Must be a non-empty string (e.g., "eu-west-1").` |
| 416 | ); |
| 417 | } |
| 418 | } |
| 419 | |
| 420 | if (source.aws_iam_auth === true) { |
| 421 | const validIamTypes = ["postgres", "mysql", "mariadb"]; |
| 422 | if (!source.type || !validIamTypes.includes(source.type)) { |
| 423 | throw new Error( |
| 424 | `Configuration file ${configPath}: source '${source.id}' has aws_iam_auth enabled, ` + |
| 425 | `but this is only supported for postgres, mysql, and mariadb sources.` |
| 426 | ); |
| 427 | } |
| 428 | if (!source.aws_region) { |
| 429 | throw new Error( |
| 430 | `Configuration file ${configPath}: source '${source.id}' has aws_iam_auth enabled ` + |
no test coverage detected