Skip to content

Commit

Permalink
chore: review updates
Browse files Browse the repository at this point in the history
  • Loading branch information
shetzel committed Nov 30, 2022
1 parent 6952b44 commit f947f58
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions src/org/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ export class Connection<S extends Schema = Schema> extends JSForceConnection<S>
// All connections are tied to a username
private username!: string;

// Save the DNS resolution result of this connection's instance URL.
private resolvable!: boolean;
// Save whether we've successfully resolved this connection's instance URL.
private hasResolved = false;

// Save the max API version of this connection's org.
private maxApiVersion!: string;
private maxApiVersion!: Optional<string>;

/**
* Constructor
Expand Down Expand Up @@ -238,16 +238,11 @@ export class Connection<S extends Schema = Schema> extends JSForceConnection<S>
* Retrieves the highest api version that is supported by the target server instance.
*/
public async retrieveMaxApiVersion(): Promise<string> {
if (this.maxApiVersion) {
// Check saved value first, then cache.
if (this.maxApiVersion || (this.maxApiVersion = this.getCachedApiVersion())) {
return this.maxApiVersion;
}

// check API version cache
const cachedApiVersion = this.getCachedApiVersion();
if (cachedApiVersion) {
return cachedApiVersion;
}

await this.isResolvable();
type Versioned = { version: string };

Expand Down Expand Up @@ -291,8 +286,8 @@ export class Connection<S extends Schema = Schema> extends JSForceConnection<S>
* Verify that instance has a reachable DNS entry, otherwise will throw error
*/
public async isResolvable(): Promise<boolean> {
if (this.resolvable !== undefined) {
return this.resolvable;
if (this.hasResolved) {
return this.hasResolved;
}

if (!this.options.connectionOptions?.instanceUrl) {
Expand All @@ -303,10 +298,9 @@ export class Connection<S extends Schema = Schema> extends JSForceConnection<S>
});
try {
await resolver.resolve();
this.resolvable = true;
this.hasResolved = true;
return true;
} catch (e) {
this.resolvable = false;
throw messages.createError('domainNotFoundError', [], [], e as Error);
}
}
Expand Down

0 comments on commit f947f58

Please sign in to comment.