Skip to content

Commit 8be08fc

Browse files
AllanZhengYPtrivikr
authored andcommitted
feat: add pluggable runtime specific config (#404)
* feat: support pluggable runtime config * export runtimeConfig.runtime.ts to manually set the client to be compatible with specific runtime * get rid of rollup, instead using browser property to swap runtime config * add endpoint to the serializer utilities and insert it when building a request * chore: set prettier-vscode as default formatter
1 parent 1493cc3 commit 8be08fc

32 files changed

+455
-485
lines changed

Diff for: .vscode/settings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"editor.tabSize": 2,
33
"editor.formatOnSave": true,
44
"editor.defaultFormatter": "esbenp.prettier-vscode"
5-
}
5+
}

Diff for: clients/node/client-rds-data-node/.npmignore

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
/coverage/
22
/docs/
3-
*.ts
4-
!*.d.ts
53
tsconfig.test.json
64
*.tsbuildinfo

Diff for: clients/node/client-rds-data-node/RDSDataClient.ts

+22-10
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,34 @@
11
import { contentLengthPlugin } from "@aws-sdk/middleware-content-length";
2-
import { userAgentPlugin, UserAgentConfig } from "@aws-sdk/middleware-user-agent";
2+
import {
3+
userAgentPlugin,
4+
UserAgentConfig
5+
} from "@aws-sdk/middleware-user-agent";
36
import { retryPlugin, RetryConfig } from "@aws-sdk/retry-middleware";
4-
import { awsAuthPlugin, AwsAuthConfiguration } from "@aws-sdk/signing-middleware";
7+
import {
8+
awsAuthPlugin,
9+
AwsAuthConfiguration
10+
} from "@aws-sdk/signing-middleware";
511
import {
612
RDSDataConfiguration,
7-
RDSDataResolvedConfiguration,
8-
RDSRuntimeConfiguration
13+
RDSDataResolvedConfiguration
914
} from "./RDSDataConfiguration";
10-
import { RegionConfiguration, EndpointsConfig, ProtocolConfig } from '@aws-sdk/config-resolver';
11-
import { HttpOptions, MetadataBearer } from '@aws-sdk/types';
15+
import { RDSRuntimeConfiguration } from "./runtimeConfig";
16+
import {
17+
RegionConfiguration,
18+
EndpointsConfig,
19+
ProtocolConfig
20+
} from "@aws-sdk/config-resolver";
21+
import { HttpOptions, MetadataBearer } from "@aws-sdk/types";
1222
import { Client as SmithyClient } from "@aws-sdk/smithy-client";
1323

1424
type InputTypesUnion = any;
1525
type OutputTypesUnion = MetadataBearer;
1626

17-
export class RDSDataClient extends SmithyClient<HttpOptions, InputTypesUnion, OutputTypesUnion> {
27+
export class RDSDataClient extends SmithyClient<
28+
HttpOptions,
29+
InputTypesUnion,
30+
OutputTypesUnion
31+
> {
1832
readonly config: RDSDataResolvedConfiguration;
1933

2034
constructor(configuration: RDSDataConfiguration) {
@@ -36,9 +50,7 @@ export class RDSDataClient extends SmithyClient<HttpOptions, InputTypesUnion, Ou
3650
}
3751

3852
destroy(): void {
39-
if (
40-
typeof this.config.httpHandler.destroy === 'function'
41-
) {
53+
if (typeof this.config.httpHandler.destroy === "function") {
4254
this.config.httpHandler.destroy();
4355
}
4456
}
+106-41
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,125 @@
1-
import { defaultProvider as credentialDefaultProvider } from "@aws-sdk/credential-provider-node";
2-
import { Hash } from "@aws-sdk/hash-node";
3-
import { NodeHttpHandler } from "@aws-sdk/node-http-handler";
4-
import { defaultProvider as regionDefaultProvider } from "@aws-sdk/region-provider";
5-
import { parseUrl } from "@aws-sdk/url-parser-node";
6-
import { calculateBodyLength } from "@aws-sdk/util-body-length-node";
7-
import { streamCollector } from '@aws-sdk/stream-collector-node';
8-
import { RestJsonProtocol } from "@aws-sdk/protocol-rest-json";
9-
import { fromUtf8, toUtf8 } from '@aws-sdk/util-utf8-node';
10-
import { fromBase64, toBase64 } from '@aws-sdk/util-base64-node';
11-
import { defaultUserAgent } from '@aws-sdk/util-user-agent-node';
12-
import { AwsAuthConfiguration, AwsAuthConfigurationInput } from '@aws-sdk/signing-middleware';
13-
import { UserAgentConfig, UserAgentConfigInput } from '@aws-sdk/middleware-user-agent';
14-
import { RetryConfig, RetryConfigInput } from '@aws-sdk/retry-middleware';
15-
import { name, version } from './package.json';
1+
import {
2+
AwsAuthConfiguration,
3+
AwsAuthConfigurationInput
4+
} from "@aws-sdk/signing-middleware";
5+
import {
6+
UserAgentConfig,
7+
UserAgentConfigInput
8+
} from "@aws-sdk/middleware-user-agent";
9+
import { RetryConfig, RetryConfigInput } from "@aws-sdk/retry-middleware";
1610
import {
1711
RegionConfiguration,
1812
RegionConfigurationInput,
1913
EndpointsConfig,
2014
EndpointsConfigInput,
2115
ProtocolConfig,
22-
ProtocolConfigInput,
23-
AWSClientRuntimeConfiguration
24-
} from '@aws-sdk/config-resolver';
25-
26-
export type AWSClientRuntimeResolvedConfiguration = Required<AWSClientRuntimeConfiguration>;
27-
28-
export const RDSRuntimeConfiguration: AWSClientRuntimeResolvedConfiguration = {
29-
protocolDefaultProvider: (handler) => new RestJsonProtocol(handler),
30-
signingName: "rds-data",
31-
service: "rds-data",
32-
httpHandler: new NodeHttpHandler(),
33-
sha256: Hash.bind(null, "sha256"),
34-
credentialDefaultProvider,
35-
regionDefaultProvider,
36-
urlParser: parseUrl,
37-
bodyLengthChecker: calculateBodyLength,
38-
streamCollector,
39-
base64Decoder: fromBase64,
40-
base64Encoder: toBase64,
41-
utf8Decoder: fromUtf8,
42-
utf8Encoder: toUtf8,
43-
defaultUserAgent: defaultUserAgent(name, version)
16+
ProtocolConfigInput
17+
} from "@aws-sdk/config-resolver";
18+
import {
19+
Credentials,
20+
Provider,
21+
HashConstructor,
22+
UrlParser,
23+
Protocol,
24+
StreamCollector,
25+
Decoder,
26+
Encoder
27+
} from "@aws-sdk/types";
28+
import { HttpHandler, HttpRequest, HttpResponse } from "@aws-sdk/protocol-http";
29+
30+
export interface RDSDataRuntimeDependencies {
31+
/**
32+
* The HTTP handler to use. Fetch in browser and Https in Nodejs
33+
*/
34+
httpHandler?: HttpHandler;
35+
36+
/**
37+
* 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
38+
*/
39+
sha256?: HashConstructor;
40+
41+
/**
42+
* Default credentials provider; Not available in browser runtime
43+
*/
44+
credentialDefaultProvider?: (input: any) => Provider<Credentials>;
45+
46+
/**
47+
* Provider function that return promise of a region string
48+
*/
49+
regionDefaultProvider?: (input: any) => Provider<string>;
50+
51+
/**
52+
* The function that will be used to convert strings into HTTP endpoints
53+
*/
54+
urlParser?: UrlParser;
55+
56+
/**
57+
* A function that can calculate the length of a request body.
58+
*/
59+
bodyLengthChecker?: (body: any) => number | undefined;
60+
61+
/**
62+
* A function that converts a stream into an array of bytes.
63+
*/
64+
streamCollector?: StreamCollector;
65+
66+
/**
67+
* The function that will be used to convert a base64-encoded string to a byte array
68+
*/
69+
base64Decoder?: Decoder;
70+
71+
/**
72+
* The function that will be used to convert binary data to a base64-encoded string
73+
*/
74+
base64Encoder?: Encoder;
75+
76+
/**
77+
* The function that will be used to convert a UTF8-encoded string to a byte array
78+
*/
79+
utf8Decoder?: Decoder;
80+
81+
/**
82+
* The function that will be used to convert binary data to a UTF-8 encoded string
83+
*/
84+
utf8Encoder?: Encoder;
85+
86+
/**
87+
* The function that will be used to populate default value in 'User-Agent' header
88+
*/
89+
defaultUserAgent?: string;
90+
91+
/**
92+
* The function that will be used to populate serializing protocol
93+
*/
94+
protocolDefaultProvider?: (
95+
handler: HttpHandler
96+
) => Protocol<HttpRequest, HttpResponse>;
97+
98+
/**
99+
* The service name with which to sign requests.
100+
*/
101+
signingName?: string;
102+
103+
/**
104+
* The service name with which to construct endpoints.
105+
*/
106+
service?: string;
44107
}
45108

46-
export type RDSDataConfiguration = AWSClientRuntimeConfiguration &
109+
export type RDSDataConfiguration = RDSDataRuntimeDependencies &
47110
AwsAuthConfigurationInput &
48111
RegionConfigurationInput &
49112
RetryConfigInput &
50113
EndpointsConfigInput &
51114
ProtocolConfigInput &
52-
UserAgentConfigInput
115+
UserAgentConfigInput;
53116

54-
export type RDSDataResolvedConfiguration = AWSClientRuntimeResolvedConfiguration &
117+
export type RDSDataResolvedConfiguration = Required<
118+
RDSDataRuntimeDependencies
119+
> &
55120
AwsAuthConfiguration.Resolved &
56121
RegionConfiguration.Resolved &
57122
RetryConfig.Resolved &
58123
EndpointsConfig.Resolved &
59124
ProtocolConfig.Resolved &
60-
UserAgentConfig.Resolved
125+
UserAgentConfig.Resolved;

Diff for: clients/node/client-rds-data-node/commands/ExecuteStatementCommand.ts

+12-7
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type OutputTypesUnion = any;
1919
export class ExecuteStatementCommand extends Command<
2020
ExecuteStatementRequest,
2121
ExecuteStatementResponse
22-
> {
22+
> {
2323
constructor(readonly input: ExecuteStatementRequest) {
2424
super();
2525
}
@@ -28,13 +28,18 @@ export class ExecuteStatementCommand extends Command<
2828
clientStack: MiddlewareStack<InputTypesUnion, OutputTypesUnion>,
2929
configuration: RDSDataResolvedConfiguration,
3030
options?: HttpOptions
31-
): Handler<
32-
ExecuteStatementRequest,
33-
ExecuteStatementResponse
34-
> {
35-
const { protocol: { handler } } = configuration;
31+
): Handler<ExecuteStatementRequest, ExecuteStatementResponse> {
32+
const {
33+
protocol: { handler }
34+
} = configuration;
3635

37-
this.use(serdePlugin(configuration, executeStatementSerializer, executeStatementDeserializer));
36+
this.use(
37+
serdePlugin(
38+
configuration,
39+
executeStatementSerializer,
40+
executeStatementDeserializer
41+
)
42+
);
3843

3944
const stack = clientStack.concat(this.middlewareStack);
4045

Diff for: clients/node/client-rds-data-node/index.browser.ts

-4
This file was deleted.

0 commit comments

Comments
 (0)