Skip to content

Commit

Permalink
Remove deprecated ClientOptions.fallbackHostsUseDefault
Browse files Browse the repository at this point in the history
Part of #1197.
  • Loading branch information
lawrence-forooghian committed Apr 27, 2023
1 parent 6778ff0 commit 6b715a9
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 83 deletions.
5 changes: 0 additions & 5 deletions ably.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,11 +438,6 @@ declare namespace Types {
*/
fallbackHosts?: string[];

/**
* @deprecated This property is deprecated and will be removed in a future version. Enables default fallback hosts to be used.
*/
fallbackHostsUseDefault?: boolean;

/**
* Set of configurable options to set on the HTTP(S) agent used for REST requests.
*
Expand Down
29 changes: 0 additions & 29 deletions src/common/lib/util/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,35 +182,6 @@ export function objectifyOptions(options: ClientOptions | string): ClientOptions
}

export function normaliseOptions(options: InternalClientOptions): NormalisedClientOptions {
if (options.fallbackHostsUseDefault) {
/* fallbackHostsUseDefault and fallbackHosts are mutually exclusive as per TO3k7 */
if (options.fallbackHosts) {
const msg = 'fallbackHosts and fallbackHostsUseDefault cannot both be set';
Logger.logAction(Logger.LOG_ERROR, 'Defaults.normaliseOptions', msg);
throw new ErrorInfo(msg, 40000, 400);
}

/* default fallbacks can't be used with custom ports */
if (options.port || options.tlsPort) {
const msg = 'fallbackHostsUseDefault cannot be set when port or tlsPort are set';
Logger.logAction(Logger.LOG_ERROR, 'Defaults.normaliseOptions', msg);
throw new ErrorInfo(msg, 40000, 400);
}

/* emit an appropriate deprecation warning */
if (options.environment) {
Logger.deprecatedWithMsg(
'fallbackHostsUseDefault',
'There is no longer a need to set this when the environment option is also set since the library will now generate the correct fallback hosts using the environment option.'
);
} else {
Logger.deprecated('fallbackHostsUseDefault', 'fallbackHosts: Ably.Defaults.FALLBACK_HOSTS');
}

/* use the default fallback hosts as requested */
options.fallbackHosts = Defaults.FALLBACK_HOSTS;
}

/* options.recover as a boolean is deprecated, and therefore is not part of the public typing */
if ((options.recover as any) === true) {
Logger.deprecated('{recover: true}', '{recover: function(lastConnectionDetails, cb) { cb(true); }}');
Expand Down
49 changes: 0 additions & 49 deletions test/rest/defaults.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,27 +61,6 @@ define(['ably', 'chai'], function (Ably, chai) {
expect(Defaults.getPort(normalisedOptions)).to.equal(443);
});

/* will emit a deprecation warning */
it('Init with given environment and default fallbacks', function () {
var normalisedOptions = Defaults.normaliseOptions({ environment: 'sandbox', fallbackHostsUseDefault: true });

expect(normalisedOptions.restHost).to.equal('sandbox-rest.ably.io');
expect(normalisedOptions.realtimeHost).to.equal('sandbox-realtime.ably.io');
expect(normalisedOptions.port).to.equal(80);
expect(normalisedOptions.tlsPort).to.equal(443);
expect(normalisedOptions.fallbackHosts.sort()).to.deep.equal(Defaults.FALLBACK_HOSTS.sort());
expect(normalisedOptions.tls).to.equal(true);

expect(Defaults.getHosts(normalisedOptions).length).to.deep.equal(4);
expect(Defaults.getHosts(normalisedOptions)[0]).to.deep.equal(normalisedOptions.restHost);
expect(Defaults.getHost(normalisedOptions, 'sandbox-rest.ably.io', false)).to.deep.equal('sandbox-rest.ably.io');
expect(Defaults.getHost(normalisedOptions, 'sandbox-rest.ably.io', true)).to.deep.equal(
'sandbox-realtime.ably.io'
);

expect(Defaults.getPort(normalisedOptions)).to.equal(443);
});

it('Init with local environment and non-default ports', function () {
var normalisedOptions = Defaults.normaliseOptions({ environment: 'local', port: 8080, tlsPort: 8081 });

Expand Down Expand Up @@ -134,34 +113,6 @@ define(['ably', 'chai'], function (Ably, chai) {
expect(Defaults.getPort(normalisedOptions)).to.equal(443);
});

/* init with given restHost and realtimeHost, using the default fallback hosts */
it('Init with given restHost and realtimeHost, using the default fallback hosts', function () {
var normalisedOptions = Defaults.normaliseOptions({
restHost: 'test.org',
realtimeHost: 'ws.test.org',
fallbackHostsUseDefault: true,
});

expect(normalisedOptions.restHost).to.equal('test.org');
expect(normalisedOptions.realtimeHost).to.equal('ws.test.org');
expect(normalisedOptions.fallbackHosts.sort()).to.deep.equal(Defaults.FALLBACK_HOSTS.sort());
});

it('Throws an error when initiated with fallbackHosts and fallbackHostsUseDefault', function () {
expect(function () {
Defaults.normaliseOptions({ fallbackHosts: ['a.example.com', 'b.example.com'], fallbackHostsUseDefault: true });
}, "Check fallbackHosts and fallbackHostsUseDefault can't both be set").to.throw();
});

it('Throws an error with initiated with fallbackHostsUseDefault and port or tlsPort set', function () {
expect(function () {
Defaults.normaliseOptions({ fallbackHostsUseDefault: true, port: 8080 });
}, "Check fallbackHostsUseDefault and port can't both be set").to.throw;
expect(function () {
Defaults.normaliseOptions({ fallbackHostsUseDefault: true, tlsPort: 8081 });
}, "Check fallbackHostsUseDefault and tlsPort can't both be set").to.throw;
});

it('Init with no endpoint-related options and given default environment', function () {
Defaults.ENVIRONMENT = 'sandbox';
var normalisedOptions = Defaults.normaliseOptions({});
Expand Down

0 comments on commit 6b715a9

Please sign in to comment.