Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose connection params via Client #896

Merged
merged 1 commit into from Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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