Skip to content

Commit 7a0e89c

Browse files
committed
[FIX] simpler way to noResolve
1 parent a0b6022 commit 7a0e89c

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

nats-base-client/core.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,10 +1411,12 @@ export interface ConnectionOptions {
14111411
noAsyncTraces?: boolean;
14121412

14131413
/**
1414-
* When true, the connect function will remove any name resolution provided by
1415-
* the transport. In some environments (browsers) this is a no-op option.
1414+
* When false, the connect function will not perform any hostname resolution. Note that
1415+
* by default this option will be true if the client supports hostname resolution.
1416+
* Note that on clients that don't supported (mainly the websocket client, setting this
1417+
* option to true, will throw an exception as this option is not available.
14161418
*/
1417-
noResolve?: boolean;
1419+
resolve?: boolean;
14181420
}
14191421

14201422
/**

nats-base-client/options.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ export function parseOptions(opts?: ConnectionOptions): ConnectionOptions {
135135
}
136136
}
137137

138+
// if not set - we set it
139+
if (options.resolve === undefined) {
140+
// set a default based on whether the client can resolve or not
141+
options.resolve = typeof getResolveFn() === "function";
142+
}
143+
138144
if (options.resolve) {
139145
if (typeof getResolveFn() !== "function") {
140146
throw new NatsError(

nats-base-client/protocol.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -594,8 +594,8 @@ export class ProtocolHandler implements Dispatcher<ParserEvent> {
594594
}
595595

596596
async _doDial(srv: Server): Promise<void> {
597-
const resolve = this.options.noResolve !== true;
598-
const alts = this.options.noResolve === true ? [srv] : await srv.resolve({
597+
const { resolve } = this.options;
598+
const alts = await srv.resolve({
599599
fn: getResolveFn(),
600600
debug: this.options.debug,
601601
randomize: !this.options.noRandomize,

tests/basics_test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1437,7 +1437,7 @@ Deno.test("basics - noResolve", async () => {
14371437
const nci = await connect({
14381438
servers: "connect.ngs.global",
14391439
authenticator: jwtAuthenticator(token),
1440-
noResolve: true,
1440+
resolve: false,
14411441
}) as NatsConnectionImpl;
14421442

14431443
const srv = nci.protocol.servers.getCurrentServer();

0 commit comments

Comments
 (0)