MCPcopy Create free account
hub / github.com/bytebase/dbhub / resolveSourceConfigs

Function resolveSourceConfigs

src/config/env.ts:656–763  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

654 * Returns array of source configs and the source of the configuration
655 */
656export async function resolveSourceConfigs(): Promise<{ sources: SourceConfig[]; tools?: import("../types/config.js").ToolConfig[]; source: string } | null> {
657 // 1. Try loading from TOML configuration file (skip if --demo flag is set)
658 if (!isDemoMode()) {
659 const tomlConfig = loadTomlConfig();
660 if (tomlConfig) {
661 // Validate that --id flag is not used with TOML config
662 const idData = resolveId();
663 if (idData) {
664 throw new Error(
665 "The --id flag cannot be used with TOML configuration. " +
666 "TOML config defines source IDs directly. " +
667 "Either remove the --id flag or use command-line DSN configuration instead."
668 );
669 }
670 // Note: --readonly flag is deprecated but no longer blocks TOML usage
671 // The warning is shown in isReadOnlyMode() function
672 return tomlConfig;
673 }
674 }
675
676 // 2. Fallback to single DSN configuration (including demo mode)
677 const dsnResult = resolveDSN();
678 if (dsnResult) {
679 // Parse DSN to extract database type
680 let dsnUrl: SafeURL;
681 try {
682 dsnUrl = new SafeURL(dsnResult.dsn);
683 } catch (error) {
684 throw new Error(
685 `Invalid DSN format: ${dsnResult.dsn}. Expected format: protocol://[user[:password]@]host[:port]/database`
686 );
687 }
688
689 const protocol = dsnUrl.protocol.replace(':', '');
690
691 // Map protocol to database type
692 let dbType: "postgres" | "mysql" | "mariadb" | "sqlserver" | "sqlite";
693 if (protocol === 'postgresql' || protocol === 'postgres') {
694 dbType = 'postgres';
695 } else if (protocol === 'mysql') {
696 dbType = 'mysql';
697 } else if (protocol === 'mariadb') {
698 dbType = 'mariadb';
699 } else if (protocol === 'sqlserver') {
700 dbType = 'sqlserver';
701 } else if (protocol === 'sqlite') {
702 dbType = 'sqlite';
703 } else {
704 throw new Error(`Unsupported database type in DSN: ${protocol}`);
705 }
706
707 // Get --id flag value (if specified) to use as source ID
708 // If not specified, use "default" (which will result in no tool name suffix)
709 const idData = resolveId();
710 const sourceId = idData?.id || "default";
711
712 // Create a single source config from the resolved DSN
713 const source: SourceConfig = {

Callers 1

mainFunction · 0.85

Calls 7

isDemoModeFunction · 0.85
loadTomlConfigFunction · 0.85
resolveIdFunction · 0.85
resolveDSNFunction · 0.85
resolveSSHConfigFunction · 0.85

Tested by

no test coverage detected