Skip to content

Commit 56ab50e

Browse files
authored
fix(config-resolver): add options for utility functions (#2712)
1 parent 705de4e commit 56ab50e

File tree

5 files changed

+52
-44
lines changed

5 files changed

+52
-44
lines changed

packages/config-resolver/src/endpointsConfig/configurations.ts

Lines changed: 0 additions & 32 deletions
This file was deleted.

packages/config-resolver/src/endpointsConfig/getEndpointFromRegion.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
import { EndpointsInputConfig, PreviouslyResolved } from "./configurations";
1+
import { Provider, RegionInfoProvider, UrlParser } from "@aws-sdk/types";
22

3-
export const getEndpointFromRegion = async (input: EndpointsInputConfig & PreviouslyResolved) => {
3+
interface GetEndpointFromRegionOptions {
4+
region: Provider<string>;
5+
tls?: boolean;
6+
regionInfoProvider: RegionInfoProvider;
7+
urlParser: UrlParser;
8+
}
9+
10+
export const getEndpointFromRegion = async (input: GetEndpointFromRegionOptions) => {
411
const { tls = true } = input;
512
const region = await input.region();
613

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
export * from "./configurations";
21
export * from "./resolveEndpointsConfig";
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
import { Endpoint, Provider } from "@aws-sdk/types";
1+
import { Endpoint, Provider, UrlParser } from "@aws-sdk/types";
22

3-
import { EndpointsInputConfig, PreviouslyResolved } from "./configurations";
3+
interface NormalizeEndpointOptions {
4+
endpoint: string | Endpoint | Provider<Endpoint>;
5+
urlParser: UrlParser;
6+
}
47

5-
export const normalizeEndpoint = ({
6-
endpoint,
7-
urlParser,
8-
}: EndpointsInputConfig & PreviouslyResolved): Provider<Endpoint> => {
8+
export const normalizeEndpoint = ({ endpoint, urlParser }: NormalizeEndpointOptions): Provider<Endpoint> => {
99
if (typeof endpoint === "string") {
1010
const promisified = Promise.resolve(urlParser(endpoint));
1111
return () => promisified;
1212
} else if (typeof endpoint === "object") {
1313
const promisified = Promise.resolve(endpoint);
1414
return () => promisified;
1515
}
16-
return endpoint!;
16+
return endpoint;
1717
};
Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,46 @@
1-
import { EndpointsInputConfig, EndpointsResolvedConfig, PreviouslyResolved } from "./configurations";
1+
import { Endpoint, Provider, RegionInfoProvider, UrlParser } from "@aws-sdk/types";
2+
23
import { getEndpointFromRegion } from "./getEndpointFromRegion";
34
import { normalizeEndpoint } from "./normalizeEndpoint";
45

6+
export interface EndpointsInputConfig {
7+
/**
8+
* The fully qualified endpoint of the webservice. This is only required when using a custom endpoint (for example, when using a local version of S3).
9+
*/
10+
endpoint?: string | Endpoint | Provider<Endpoint>;
11+
12+
/**
13+
* Whether TLS is enabled for requests.
14+
*/
15+
tls?: boolean;
16+
}
17+
18+
interface PreviouslyResolved {
19+
regionInfoProvider: RegionInfoProvider;
20+
urlParser: UrlParser;
21+
region: Provider<string>;
22+
}
23+
24+
export interface EndpointsResolvedConfig extends Required<EndpointsInputConfig> {
25+
/**
26+
* Resolved value for input {@link EndpointsResolvedConfig.endpoint}
27+
*/
28+
endpoint: Provider<Endpoint>;
29+
30+
/**
31+
* Whether the endpoint is specified by caller.
32+
* @internal
33+
*/
34+
isCustomEndpoint: boolean;
35+
}
36+
537
export const resolveEndpointsConfig = <T>(
638
input: T & EndpointsInputConfig & PreviouslyResolved
739
): T & EndpointsResolvedConfig => ({
840
...input,
941
tls: input.tls ?? true,
10-
endpoint: input.endpoint ? normalizeEndpoint(input) : () => getEndpointFromRegion(input),
42+
endpoint: input.endpoint
43+
? normalizeEndpoint({ ...input, endpoint: input.endpoint })
44+
: () => getEndpointFromRegion(input),
1145
isCustomEndpoint: input.endpoint ? true : false,
1246
});

0 commit comments

Comments
 (0)