Skip to content

Commit

Permalink
Expose connection params via Client (#896)
Browse files Browse the repository at this point in the history
  • Loading branch information
CarsonF committed Mar 20, 2024
1 parent 3676ed2 commit 78bf38b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
10 changes: 10 additions & 0 deletions packages/driver/src/baseClient.ts
Expand Up @@ -22,6 +22,7 @@ import {
ConnectArgumentsParser,
ConnectConfig,
NormalizedConnectConfig,
ResolvedConnectConfigReadonly,
} from "./conUtils";
import * as errors from "./errors";
import { Cardinality, Executor, OutputFormat, QueryArgs } from "./ifaces";
Expand Down Expand Up @@ -367,6 +368,11 @@ export abstract class BaseClientPool {
);
}

async resolveConnectionParams(): Promise<ResolvedConnectConfigReadonly> {
const config = await this._getNormalizedConnectConfig();
return config.connectionParams;
}

async getNewConnection(): Promise<BaseRawConnection> {
if (this._closing?.done) {
throw new errors.InterfaceError("The client is closed");
Expand Down Expand Up @@ -551,6 +557,10 @@ export class Client implements Executor {
return this;
}

async resolveConnectionParams(): Promise<ResolvedConnectConfigReadonly> {
return this.pool.resolveConnectionParams();
}

isClosed(): boolean {
return this.pool.isClosed();
}
Expand Down
9 changes: 8 additions & 1 deletion packages/driver/src/conUtils.ts
Expand Up @@ -124,6 +124,13 @@ type ConnectConfigParams =
| "tlsSecurity"
| "waitUntilAvailable";

export type ResolvedConnectConfigReadonly = Readonly<
Pick<
ResolvedConnectConfig,
Exclude<keyof ResolvedConnectConfig, `${"_" | "set" | "add"}${string}`>
>
>;

export class ResolvedConnectConfig {
_host: string | null = null;
_hostSource: string | null = null;
Expand Down Expand Up @@ -155,7 +162,7 @@ export class ResolvedConnectConfig {
_waitUntilAvailable: number | null = null;
_waitUntilAvailableSource: string | null = null;

serverSettings: { [key: string]: string } = {};
serverSettings: { readonly [key: string]: string } = {};

constructor() {
this.setHost = this.setHost.bind(this);
Expand Down

0 comments on commit 78bf38b

Please sign in to comment.