Skip to content

Commit 4daf32c

Browse files
authored
feat(hosts): accept url as string (#1189)
* feat(hosts): accept url as string In v3 the API was `hosts: string[]`. It's easy to miss out on this in the migration guide, and it's also simpler to write just a string in the general case fixes #1188 * chore(bundlesize): loosen
1 parent c45fa4c commit 4daf32c

File tree

4 files changed

+36
-16
lines changed

4 files changed

+36
-16
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@
9797
"bundlesize": [
9898
{
9999
"path": "packages/algoliasearch/dist/algoliasearch.umd.js",
100-
"maxSize": "7.53KB"
100+
"maxSize": "7.56KB"
101101
},
102102
{
103103
"path": "packages/algoliasearch/dist/algoliasearch-lite.umd.js",
104-
"maxSize": "4.29KB"
104+
"maxSize": "4.35KB"
105105
}
106106
]
107107
}

packages/transporter/src/__tests__/unit/hosts.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,14 @@ describe('selection of hosts', (): void => {
6969
protocol: 'https',
7070
});
7171
});
72+
73+
it('allows a string to be passed', () => {
74+
const host = createStatelessHost('foo.com');
75+
76+
expect(host).toEqual({
77+
url: 'foo.com',
78+
accept: CallEnum.Any,
79+
protocol: 'https',
80+
});
81+
});
7282
});

packages/transporter/src/createStatelessHost.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
import { CallEnum, HostOptions, StatelessHost } from '.';
22

33
export function createStatelessHost(options: HostOptions): StatelessHost {
4+
if (typeof options === 'string') {
5+
return {
6+
protocol: 'https',
7+
url: options,
8+
accept: CallEnum.Any,
9+
};
10+
}
11+
412
return {
513
protocol: options.protocol || 'https',
614
url: options.url,
Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
import { CallType } from '.';
22

3-
export type HostOptions = {
4-
/**
5-
* The url of the server, without the protocol.
6-
*/
7-
readonly url: string;
3+
export type HostOptions =
4+
| string
5+
| {
6+
/**
7+
* The url of the server, without the protocol.
8+
*/
9+
readonly url: string;
810

9-
/**
10-
* The type of host. Defaults to `Any`.
11-
*/
12-
readonly accept?: CallType;
11+
/**
12+
* The type of host. Defaults to `Any`.
13+
*/
14+
readonly accept?: CallType;
1315

14-
/**
15-
* The protocol. Defaults to `https`.
16-
*/
17-
readonly protocol?: string;
18-
};
16+
/**
17+
* The protocol. Defaults to `https`.
18+
*/
19+
readonly protocol?: string;
20+
};

0 commit comments

Comments
 (0)