Skip to content

Commit 033f953

Browse files
AllanZhengYPChase Coalwell
authored andcommitted
Smithy codegen Client Refactor (#384)
* feat: remove 'apply' entry from configuration definition 'apply' was used to adjust middleware stack and resolved configuration. It is not relative as we are moving to conposition configuration, and middleware stack should not be altered by configurations. Address: #94 * feat: complete PoC composable configuration * feat: change config resolver to multiple client config components * feat: rename stack finalize step to finalizeRequest * feat: add use() to smithy client to inject middleware * fix: rename resolvedruntime configuration * fix: remove exported reviouslyResolved interface * feat: add metadatabearer to shapes * feat: parse derializing utils as parameters * use config interface as middleware parameter * use smithy command as super class of all commands so we can support use() in commands * feat: parse serialize(deserialize) util functions from client config * Serializers/Deserializers should take utils functions from client config first, if not available then fallback to generated dependencies. This allows configuring the runtime dependencies manually from client config when runtime-specific bundlers' decision is not accountable * feat: add metadata deserializer * docs: add documentation for config properties * feat: add defaultUserAgen config * feat: move some config components to middleware folder * signing middleware * retry middleware; Also update retry config interface by introducing RetryStrategy class * feat: add input type proxy for better intellisense * docs: add config doc block for retry config * feat: add a user agent middleware to support custom useragent
1 parent c8f5a3a commit 033f953

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1718
-2568
lines changed
Lines changed: 25 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -1,153 +1,47 @@
1-
import * as __aws_sdk_config_resolver from "@aws-sdk/config-resolver";
2-
import * as __aws_sdk_middleware_content_length from "@aws-sdk/middleware-content-length";
3-
import * as __aws_sdk_middleware_header_default from "@aws-sdk/middleware-header-default";
4-
import * as __aws_sdk_middleware_stack from "@aws-sdk/middleware-stack";
5-
import * as __aws_sdk_retry_middleware from "@aws-sdk/retry-middleware";
6-
import * as __aws_sdk_signing_middleware from "@aws-sdk/signing-middleware";
7-
import * as __aws_sdk_types from "@aws-sdk/types";
8-
import * as __aws_sdk_util_user_agent_node from "@aws-sdk/util-user-agent-node";
1+
import { contentLengthPlugin } from "@aws-sdk/middleware-content-length";
2+
import { UserAgentPlugin, UserAgentConfig } from "@aws-sdk/middleware-user-agent";
3+
import { retryPlugin, RetryConfig } from "@aws-sdk/retry-middleware";
4+
import { signingPlugin, AwsAuthConfiguration } from "@aws-sdk/signing-middleware";
95
import {
106
RDSDataConfiguration,
117
RDSDataResolvedConfiguration,
12-
configurationProperties
8+
RDSRuntimeConfiguration
139
} from "./RDSDataConfiguration";
14-
import {version as clientVersion} from './package.json'
15-
import {HttpOptions} from '@aws-sdk/types'
16-
17-
/**
18-
* To remove this when move to Smithy model
19-
*/
20-
const ServiceMetadata = {
21-
endpointPrefix: "rds-data",
22-
serviceId: "RDS Data"
23-
};
10+
import { RegionConfiguration, EndpointsConfig, ProtocolConfig } from '@aws-sdk/config-resolver';
11+
import { HttpOptions, MetadataBearer } from '@aws-sdk/types';
12+
import { Client as SmithyClient } from "@aws-sdk/smithy-client";
2413

2514
type InputTypesUnion = any;
26-
type OutputTypesUnion = any;
15+
type OutputTypesUnion = MetadataBearer;
2716

28-
export class RDSDataClient {
17+
export class RDSDataClient extends SmithyClient<HttpOptions, InputTypesUnion, OutputTypesUnion> {
2918
readonly config: RDSDataResolvedConfiguration;
3019

31-
readonly middlewareStack = new __aws_sdk_middleware_stack.MiddlewareStack<
32-
InputTypesUnion,
33-
OutputTypesUnion
34-
>();
35-
3620
constructor(configuration: RDSDataConfiguration) {
37-
this.config = __aws_sdk_config_resolver.resolveConfiguration(
38-
configuration,
39-
configurationProperties,
40-
this.middlewareStack
41-
);
42-
this.middlewareStack.add(
43-
__aws_sdk_middleware_content_length.contentLengthMiddleware(
44-
this.config.bodyLengthChecker
45-
),
46-
{
47-
step: "build",
48-
priority: -80,
49-
tags: { SET_CONTENT_LENGTH: true }
50-
}
51-
);
21+
const intermediaConfig_0 = ProtocolConfig.resolve({
22+
...RDSRuntimeConfiguration,
23+
...configuration
24+
});
25+
super(intermediaConfig_0);
26+
let intermediaConfig_1 = RegionConfiguration.resolve(intermediaConfig_0);
27+
let intermediaConfig_2 = AwsAuthConfiguration.resolve(intermediaConfig_1);
28+
let intermediaConfig_3 = EndpointsConfig.resolve(intermediaConfig_2);
29+
let intermediaConfig_4 = RetryConfig.resolve(intermediaConfig_3);
30+
let intermediaConfig_5 = UserAgentConfig.resolve(intermediaConfig_4);
31+
this.config = intermediaConfig_5;
32+
super.use(contentLengthPlugin(this.config));
5233
if (this.config.maxRetries > 0) {
53-
this.middlewareStack.add(
54-
__aws_sdk_retry_middleware.retryMiddleware(
55-
this.config.maxRetries,
56-
this.config.retryDecider,
57-
this.config.delayDecider
58-
),
59-
{
60-
step: "finalize",
61-
priority: Infinity,
62-
tags: { RETRY: true }
63-
}
64-
);
34+
super.use(retryPlugin(this.config));
6535
}
66-
this.middlewareStack.add(
67-
__aws_sdk_signing_middleware.signingMiddleware<
68-
InputTypesUnion,
69-
OutputTypesUnion
70-
>(this.config.signer),
71-
{
72-
step: "finalize",
73-
priority: 0,
74-
tags: { SIGNATURE: true }
75-
}
76-
);
77-
this.middlewareStack.add(
78-
__aws_sdk_middleware_header_default.headerDefault({
79-
"User-Agent": __aws_sdk_util_user_agent_node.defaultUserAgent(
80-
ServiceMetadata.serviceId || ServiceMetadata.endpointPrefix,
81-
clientVersion
82-
)
83-
}),
84-
{
85-
step: "build",
86-
priority: 0,
87-
tags: { SET_USER_AGENT: true }
88-
}
89-
);
36+
super.use(signingPlugin(this.config));
37+
super.use(UserAgentPlugin(this.config));
9038
}
9139

9240
destroy(): void {
9341
if (
94-
!this.config._user_injected_http_handler &&
9542
typeof this.config.httpHandler.destroy === 'function'
9643
) {
9744
this.config.httpHandler.destroy();
9845
}
9946
}
100-
101-
/**
102-
* This will need to be revised when the command interface lands.
103-
*/
104-
send<InputType extends InputTypesUnion, OutputType extends OutputTypesUnion>(
105-
command: __aws_sdk_types.Command<
106-
InputTypesUnion,
107-
InputType,
108-
OutputTypesUnion,
109-
OutputType,
110-
RDSDataResolvedConfiguration
111-
>,
112-
options?: HttpOptions
113-
): Promise<OutputType>;
114-
send<InputType extends InputTypesUnion, OutputType extends OutputTypesUnion>(
115-
command: __aws_sdk_types.Command<
116-
InputTypesUnion,
117-
InputType,
118-
OutputTypesUnion,
119-
OutputType,
120-
RDSDataResolvedConfiguration
121-
>,
122-
options: HttpOptions,
123-
cb: (err: any, data?: OutputType) => void
124-
): void;
125-
send<InputType extends InputTypesUnion, OutputType extends OutputTypesUnion>(
126-
command: __aws_sdk_types.Command<
127-
InputTypesUnion,
128-
InputType,
129-
OutputTypesUnion,
130-
OutputType,
131-
RDSDataResolvedConfiguration
132-
>,
133-
options?: HttpOptions,
134-
cb?: (err: any, data?: OutputType) => void
135-
): Promise<OutputType> | void {
136-
const handler = command.resolveMiddleware(
137-
this.middlewareStack,
138-
this.config,
139-
options
140-
);
141-
if (cb) {
142-
handler(command)
143-
.then(result => cb(null, result.output), (err: any) => cb(err))
144-
.catch(
145-
// prevent any errors thrown in the callback from triggering an
146-
// unhandled promise rejection
147-
() => {}
148-
);
149-
} else {
150-
return handler(command).then(result => result.output);
151-
}
152-
}
15347
}

0 commit comments

Comments
 (0)