Skip to content

Commit d481a6a

Browse files
committed
feat: move runtime configs to generated client configs
1 parent c76e142 commit d481a6a

File tree

8 files changed

+228
-229
lines changed

8 files changed

+228
-229
lines changed

clients/node/client-rds-data-node/RDSDataConfiguration.ts

Lines changed: 93 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,108 @@ import {
77
EndpointsConfig,
88
EndpointsConfigInput,
99
ProtocolConfig,
10-
ProtocolConfigInput,
11-
AWSClientRuntimeConfiguration
10+
ProtocolConfigInput
1211
} from '@aws-sdk/config-resolver';
12+
import {
13+
Credentials,
14+
Provider,
15+
HashConstructor,
16+
UrlParser,
17+
Protocol,
18+
StreamCollector,
19+
Decoder,
20+
Encoder
21+
} from "@aws-sdk/types";
22+
import { HttpHandler, HttpRequest, HttpResponse } from "@aws-sdk/protocol-http";
23+
24+
export interface RDSDataRuntimeDependencies {
25+
/**
26+
* The HTTP handler to use. Fetch in browser and Https in Nodejs
27+
*/
28+
httpHandler?: HttpHandler;
29+
30+
/**
31+
* A constructor for a class implementing the @aws-sdk/types.Hash interface that computes the SHA-256 HMAC or checksum of a string or binary buffer
32+
*/
33+
sha256?: HashConstructor;
34+
35+
/**
36+
* Default credentials provider; Not available in browser runtime
37+
*/
38+
credentialDefaultProvider?: (input: any) => Provider<Credentials>;
39+
40+
/**
41+
* Provider function that return promise of a region string
42+
*/
43+
regionDefaultProvider?: (input: any) => Provider<string>;
44+
45+
/**
46+
* The function that will be used to convert strings into HTTP endpoints
47+
*/
48+
urlParser?: UrlParser;
49+
50+
/**
51+
* A function that can calculate the length of a request body.
52+
*/
53+
bodyLengthChecker?: (body: any) => number | undefined;
54+
55+
/**
56+
* A function that converts a stream into an array of bytes.
57+
*/
58+
streamCollector?: StreamCollector;
59+
60+
/**
61+
* The function that will be used to convert a base64-encoded string to a byte array
62+
*/
63+
base64Decoder?: Decoder;
64+
65+
/**
66+
* The function that will be used to convert binary data to a base64-encoded string
67+
*/
68+
base64Encoder?: Encoder;
69+
70+
/**
71+
* The function that will be used to convert a UTF8-encoded string to a byte array
72+
*/
73+
utf8Decoder?: Decoder;
74+
75+
/**
76+
* The function that will be used to convert binary data to a UTF-8 encoded string
77+
*/
78+
utf8Encoder?: Encoder;
79+
80+
/**
81+
* The function that will be used to populate default value in 'User-Agent' header
82+
*/
83+
defaultUserAgent?: string;
84+
85+
/**
86+
* The function that will be used to populate serializing protocol
87+
*/
88+
protocolDefaultProvider?: (
89+
handler: HttpHandler
90+
) => Protocol<HttpRequest, HttpResponse>;
91+
92+
/**
93+
* The service name with which to sign requests.
94+
*/
95+
signingName?: string;
96+
97+
/**
98+
* The service name with which to construct endpoints.
99+
*/
100+
service?: string;
101+
}
13102

14-
export type RDSDataConfiguration = AWSClientRuntimeConfiguration &
103+
export type RDSDataConfiguration = RDSDataRuntimeDependencies &
15104
AwsAuthConfigurationInput &
16105
RegionConfigurationInput &
17106
RetryConfigInput &
18107
EndpointsConfigInput &
19108
ProtocolConfigInput &
20109
UserAgentConfigInput
21110

22-
export type RDSDataResolvedConfiguration = Required<AWSClientRuntimeConfiguration> &
111+
export type RDSDataResolvedConfiguration = Required<RDSDataRuntimeDependencies> &
23112
AwsAuthConfiguration.Resolved &
24113
RegionConfiguration.Resolved &
25114
RetryConfig.Resolved &

clients/node/client-rds-data-node/runtimeConfig.browser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import { fromUtf8, toUtf8 } from '@aws-sdk/util-utf8-browser';
99
import { fromBase64, toBase64 } from '@aws-sdk/util-base64-browser';
1010
import { defaultUserAgent } from '@aws-sdk/util-user-agent-browser';
1111
import { name, version } from './package.json';
12-
import { AWSClientRuntimeConfiguration } from '@aws-sdk/config-resolver';
12+
import { RDSDataRuntimeDependencies } from './RDSDataConfiguration';
1313

14-
export const RDSRuntimeConfiguration: Required<AWSClientRuntimeConfiguration> = {
14+
export const RDSRuntimeConfiguration: Required<RDSDataRuntimeDependencies> = {
1515
protocolDefaultProvider: (handler) => new RestJsonProtocol(handler),
1616
signingName: "rds-data",
1717
service: "rds-data",

clients/node/client-rds-data-node/runtimeConfig.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import { fromUtf8, toUtf8 } from '@aws-sdk/util-utf8-node';
1010
import { fromBase64, toBase64 } from '@aws-sdk/util-base64-node';
1111
import { defaultUserAgent } from '@aws-sdk/util-user-agent-node';
1212
import { name, version } from './package.json';
13-
import { AWSClientRuntimeConfiguration } from '@aws-sdk/config-resolver';
13+
import { RDSDataRuntimeDependencies } from './RDSDataConfiguration';
1414

15-
export const RDSRuntimeConfiguration: Required<AWSClientRuntimeConfiguration> = {
15+
export const RDSRuntimeConfiguration: Required<RDSDataRuntimeDependencies> = {
1616
protocolDefaultProvider: (handler) => new RestJsonProtocol(handler),
1717
signingName: "rds-data",
1818
service: "rds-data",
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { Provider, UrlParser, Endpoint } from "@aws-sdk/types";
2+
3+
export function normalizeEndpoint(
4+
endpoint?: string | Endpoint | Provider<Endpoint>,
5+
urlParser?: UrlParser
6+
): Provider<Endpoint> {
7+
if (typeof endpoint === "string") {
8+
const promisified = Promise.resolve(urlParser!(endpoint));
9+
return () => promisified;
10+
} else if (typeof endpoint === "object") {
11+
const promisified = Promise.resolve(endpoint);
12+
return () => promisified;
13+
}
14+
return endpoint!;
15+
}
16+
17+
export namespace EndpointsConfig {
18+
export interface Input {
19+
/**
20+
* 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).
21+
*/
22+
endpoint?: string | Endpoint | Provider<Endpoint>;
23+
24+
/**
25+
* The endpoint provider to call if no endpoint is provided
26+
*/
27+
endpointProvider?: any;
28+
29+
/**
30+
* Whether TLS is enabled for requests.
31+
*/
32+
tls?: boolean;
33+
}
34+
interface PreviouslyResolved {
35+
urlParser: UrlParser;
36+
region: Provider<string>;
37+
service: string;
38+
}
39+
export interface Resolved extends Required<Input> {
40+
endpoint: Provider<Endpoint>;
41+
}
42+
export function resolve<T>(
43+
input: T & Input & PreviouslyResolved
44+
): T & Resolved {
45+
const tls = input.tls || true;
46+
const defaultProvider = (tls: boolean, region: string) => ({
47+
protocol: tls ? "https:" : "http:",
48+
path: "/",
49+
hostname: `${input.service}.${region}.amazonaws.com`
50+
});
51+
const endpointProvider = input.endpointProvider || defaultProvider;
52+
let endpoint: Provider<Endpoint> = input.endpoint
53+
? normalizeEndpoint(input.endpoint, input.urlParser)
54+
: () => input.region().then(region => endpointProvider(tls, region));
55+
return {
56+
...input,
57+
endpointProvider,
58+
endpoint,
59+
tls
60+
};
61+
}
62+
}
63+
//export separately for showing comment block in Intellisense
64+
export type EndpointsConfigInput = EndpointsConfig.Input;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { Protocol, HttpOptions } from "@aws-sdk/types";
2+
import { HttpHandler, HttpRequest, HttpResponse } from "@aws-sdk/protocol-http";
3+
4+
export namespace ProtocolConfig {
5+
export interface Input {
6+
/**
7+
* The serializing protocol to used in request
8+
*/
9+
protocol?: Protocol<any, any>;
10+
}
11+
interface PreviouslyResolved {
12+
httpHandler: HttpHandler;
13+
protocolDefaultProvider: (
14+
handler: HttpHandler
15+
) => Protocol<HttpRequest, HttpResponse, HttpOptions>;
16+
}
17+
export type Resolved = Required<Input>;
18+
export function resolve<T>(
19+
input: T & Input & PreviouslyResolved
20+
): T & Resolved {
21+
return {
22+
...input,
23+
protocol:
24+
input.protocol || input.protocolDefaultProvider(input.httpHandler)
25+
};
26+
}
27+
}
28+
//export separately for showing comment block in Intellisense
29+
export type ProtocolConfigInput = ProtocolConfig.Input;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { Provider } from "@aws-sdk/types";
2+
3+
export namespace RegionConfiguration {
4+
export interface Input {
5+
/**
6+
* The AWS region to which this client will send requests
7+
*/
8+
region?: string | Provider<string>;
9+
}
10+
interface PreviouslyResolved {
11+
regionDefaultProvider: (input: any) => Provider<string>;
12+
}
13+
export interface Resolved {
14+
region: Provider<string>;
15+
}
16+
export function resolve<T>(
17+
input: T & Input & PreviouslyResolved
18+
): T & Resolved {
19+
let region = input.region || input.regionDefaultProvider(input as any);
20+
return {
21+
...input,
22+
region: normalizeRegion(region)
23+
};
24+
}
25+
}
26+
//export separately for showing comment block in Intellisense
27+
export type RegionConfigurationInput = RegionConfiguration.Input;
28+
29+
function normalizeRegion(region: string | Provider<string>): Provider<string> {
30+
if (typeof region === "string") {
31+
const promisified = Promise.resolve(region);
32+
return () => promisified;
33+
}
34+
return region as Provider<string>;
35+
}

0 commit comments

Comments
 (0)