fix(sqlserver): preserve explicit instance ports
This commit is contained in:
12 files changed
+237
-26
No files matched your search
@@ -8,6 +8,7 @@ export interface ConnectionDeepLinkDraft {
|
||||
driverLabel: string;
|
||||
host?: string;
|
||||
port?: number;
|
||||
portExplicit?: boolean;
|
||||
username?: string;
|
||||
password?: string;
|
||||
database?: string;
|
||||
@@ -54,6 +55,7 @@ function draftFromConnectionUrl(value: string, preferredProfile?: string): Conne
|
||||
driverLabel: parsed.driverLabel,
|
||||
host: parsed.host,
|
||||
port: parsed.port,
|
||||
portExplicit: parsed.portExplicit,
|
||||
username: parsed.username,
|
||||
password: parsed.password,
|
||||
database: parsed.database,
|
||||
@@ -94,12 +96,14 @@ export function parseConnectionDeepLink(value: string): ConnectionDeepLinkDraft
|
||||
})();
|
||||
|
||||
const oneTime = optionalBooleanParam(params, "one_time");
|
||||
const explicitPort = optionalNumberParam(params, "port");
|
||||
|
||||
return {
|
||||
...draft,
|
||||
name: optionalParam(params, "name") ?? draft.name,
|
||||
host: optionalParam(params, "host") ?? draft.host,
|
||||
port: optionalNumberParam(params, "port") ?? draft.port,
|
||||
port: explicitPort ?? draft.port,
|
||||
...((explicitPort !== undefined && draft.dbType === "sqlserver") || draft.portExplicit ? { portExplicit: true } : {}),
|
||||
username: optionalParam(params, "user") ?? draft.username,
|
||||
password: optionalParam(params, "password") ?? draft.password,
|
||||
database: optionalParam(params, "database") ?? draft.database,
|
||||
|
||||
@@ -16,6 +16,7 @@ export interface ParsedConnectionUrl {
|
||||
connectionString?: string;
|
||||
oracleConnectionType?: "service_name" | "sid";
|
||||
useMongoUrl?: boolean;
|
||||
portExplicit?: boolean;
|
||||
}
|
||||
|
||||
export type ConnectionProfile = {
|
||||
@@ -276,6 +277,7 @@ function parseJdbcSqlServerUrl(source: string): ParsedConnectionUrl | null {
|
||||
driverLabel: profile.label,
|
||||
host: match[1],
|
||||
port: match[2] ? Number(match[2]) : profile.defaultPort,
|
||||
...(match[2] ? { portExplicit: true } : {}),
|
||||
username: decodeUrlPart(props.get("user") || ""),
|
||||
password: decodeUrlPart(props.get("password") || ""),
|
||||
database: decodeUrlPart(props.get("databasename") || props.get("database") || "") || undefined,
|
||||
@@ -568,6 +570,7 @@ export function parseConnectionUrl(value: string, preferredProfile?: string): Pa
|
||||
driverLabel: profile.label,
|
||||
host: parsed.hostname,
|
||||
port: parsed.port ? Number(parsed.port) : profile.defaultPort,
|
||||
...(profile.type === "sqlserver" && parsed.port ? { portExplicit: true } : {}),
|
||||
username: mysqlCredentials?.username ?? decodeUrlPart(parsed.username),
|
||||
password: mysqlCredentials?.password ?? decodeUrlPart(parsed.password),
|
||||
database: databaseFromPath(parsed.pathname),
|
||||
@@ -598,6 +601,23 @@ function applyParsedPassword(config: Omit<ConnectionConfig, "id">, parsed: Parse
|
||||
return parsed.password;
|
||||
}
|
||||
|
||||
function isRecord(value: unknown): value is Record<string, unknown> {
|
||||
return !!value && typeof value === "object" && !Array.isArray(value);
|
||||
}
|
||||
|
||||
function sqlServerExternalConfig(existing: unknown, parsed: ParsedConnectionUrl): unknown {
|
||||
if (parsed.dbType !== "sqlserver") return existing;
|
||||
|
||||
const next = isRecord(existing) ? { ...existing } : {};
|
||||
delete next.port_explicit;
|
||||
if (parsed.portExplicit) {
|
||||
next.portExplicit = true;
|
||||
} else {
|
||||
delete next.portExplicit;
|
||||
}
|
||||
return Object.keys(next).length > 0 ? next : undefined;
|
||||
}
|
||||
|
||||
export function applyParsedConnectionUrl(config: Omit<ConnectionConfig, "id">, parsed: ParsedConnectionUrl): Omit<ConnectionConfig, "id"> {
|
||||
return {
|
||||
...config,
|
||||
@@ -614,5 +634,6 @@ export function applyParsedConnectionUrl(config: Omit<ConnectionConfig, "id">, p
|
||||
ssl: parsed.ssl,
|
||||
connection_string: parsed.connectionString,
|
||||
oracle_connection_type: parsed.oracleConnectionType,
|
||||
external_config: sqlServerExternalConfig(config.external_config, parsed),
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user