forked from aws/aws-sdk-js-v3
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(config-resolver): add options for utility functions (aws#2712)
- Loading branch information
Showing
5 changed files
with
52 additions
and
44 deletions.
There are no files selected for viewing
32 changes: 0 additions & 32 deletions
32
packages/config-resolver/src/endpointsConfig/configurations.ts
This file was deleted.
Oops, something went wrong.
11 changes: 9 additions & 2 deletions
11
packages/config-resolver/src/endpointsConfig/getEndpointFromRegion.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
export * from "./configurations"; | ||
export * from "./resolveEndpointsConfig"; |
14 changes: 7 additions & 7 deletions
14
packages/config-resolver/src/endpointsConfig/normalizeEndpoint.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
import { Endpoint, Provider } from "@aws-sdk/types"; | ||
import { Endpoint, Provider, UrlParser } from "@aws-sdk/types"; | ||
|
||
import { EndpointsInputConfig, PreviouslyResolved } from "./configurations"; | ||
interface NormalizeEndpointOptions { | ||
endpoint: string | Endpoint | Provider<Endpoint>; | ||
urlParser: UrlParser; | ||
} | ||
|
||
export const normalizeEndpoint = ({ | ||
endpoint, | ||
urlParser, | ||
}: EndpointsInputConfig & PreviouslyResolved): Provider<Endpoint> => { | ||
export const normalizeEndpoint = ({ endpoint, urlParser }: NormalizeEndpointOptions): Provider<Endpoint> => { | ||
if (typeof endpoint === "string") { | ||
const promisified = Promise.resolve(urlParser(endpoint)); | ||
return () => promisified; | ||
} else if (typeof endpoint === "object") { | ||
const promisified = Promise.resolve(endpoint); | ||
return () => promisified; | ||
} | ||
return endpoint!; | ||
return endpoint; | ||
}; |
38 changes: 36 additions & 2 deletions
38
packages/config-resolver/src/endpointsConfig/resolveEndpointsConfig.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,46 @@ | ||
import { EndpointsInputConfig, EndpointsResolvedConfig, PreviouslyResolved } from "./configurations"; | ||
import { Endpoint, Provider, RegionInfoProvider, UrlParser } from "@aws-sdk/types"; | ||
|
||
import { getEndpointFromRegion } from "./getEndpointFromRegion"; | ||
import { normalizeEndpoint } from "./normalizeEndpoint"; | ||
|
||
export interface EndpointsInputConfig { | ||
/** | ||
* 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). | ||
*/ | ||
endpoint?: string | Endpoint | Provider<Endpoint>; | ||
|
||
/** | ||
* Whether TLS is enabled for requests. | ||
*/ | ||
tls?: boolean; | ||
} | ||
|
||
interface PreviouslyResolved { | ||
regionInfoProvider: RegionInfoProvider; | ||
urlParser: UrlParser; | ||
region: Provider<string>; | ||
} | ||
|
||
export interface EndpointsResolvedConfig extends Required<EndpointsInputConfig> { | ||
/** | ||
* Resolved value for input {@link EndpointsResolvedConfig.endpoint} | ||
*/ | ||
endpoint: Provider<Endpoint>; | ||
|
||
/** | ||
* Whether the endpoint is specified by caller. | ||
* @internal | ||
*/ | ||
isCustomEndpoint: boolean; | ||
} | ||
|
||
export const resolveEndpointsConfig = <T>( | ||
input: T & EndpointsInputConfig & PreviouslyResolved | ||
): T & EndpointsResolvedConfig => ({ | ||
...input, | ||
tls: input.tls ?? true, | ||
endpoint: input.endpoint ? normalizeEndpoint(input) : () => getEndpointFromRegion(input), | ||
endpoint: input.endpoint | ||
? normalizeEndpoint({ ...input, endpoint: input.endpoint }) | ||
: () => getEndpointFromRegion(input), | ||
isCustomEndpoint: input.endpoint ? true : false, | ||
}); |