Skip to content

Commit

Permalink
Smithy codegen Client Refactor (#384)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
AllanZhengYP authored and Chase Coalwell committed Oct 8, 2019
1 parent c8f5a3a commit 033f953
Show file tree
Hide file tree
Showing 63 changed files with 1,718 additions and 2,568 deletions.
156 changes: 25 additions & 131 deletions clients/node/client-rds-data-node/RDSDataClient.ts
Original file line number Diff line number Diff line change
@@ -1,153 +1,47 @@
import * as __aws_sdk_config_resolver from "@aws-sdk/config-resolver";
import * as __aws_sdk_middleware_content_length from "@aws-sdk/middleware-content-length";
import * as __aws_sdk_middleware_header_default from "@aws-sdk/middleware-header-default";
import * as __aws_sdk_middleware_stack from "@aws-sdk/middleware-stack";
import * as __aws_sdk_retry_middleware from "@aws-sdk/retry-middleware";
import * as __aws_sdk_signing_middleware from "@aws-sdk/signing-middleware";
import * as __aws_sdk_types from "@aws-sdk/types";
import * as __aws_sdk_util_user_agent_node from "@aws-sdk/util-user-agent-node";
import { contentLengthPlugin } from "@aws-sdk/middleware-content-length";
import { UserAgentPlugin, UserAgentConfig } from "@aws-sdk/middleware-user-agent";
import { retryPlugin, RetryConfig } from "@aws-sdk/retry-middleware";
import { signingPlugin, AwsAuthConfiguration } from "@aws-sdk/signing-middleware";
import {
RDSDataConfiguration,
RDSDataResolvedConfiguration,
configurationProperties
RDSRuntimeConfiguration
} from "./RDSDataConfiguration";
import {version as clientVersion} from './package.json'
import {HttpOptions} from '@aws-sdk/types'

/**
* To remove this when move to Smithy model
*/
const ServiceMetadata = {
endpointPrefix: "rds-data",
serviceId: "RDS Data"
};
import { RegionConfiguration, EndpointsConfig, ProtocolConfig } from '@aws-sdk/config-resolver';
import { HttpOptions, MetadataBearer } from '@aws-sdk/types';
import { Client as SmithyClient } from "@aws-sdk/smithy-client";

type InputTypesUnion = any;
type OutputTypesUnion = any;
type OutputTypesUnion = MetadataBearer;

export class RDSDataClient {
export class RDSDataClient extends SmithyClient<HttpOptions, InputTypesUnion, OutputTypesUnion> {
readonly config: RDSDataResolvedConfiguration;

readonly middlewareStack = new __aws_sdk_middleware_stack.MiddlewareStack<
InputTypesUnion,
OutputTypesUnion
>();

constructor(configuration: RDSDataConfiguration) {
this.config = __aws_sdk_config_resolver.resolveConfiguration(
configuration,
configurationProperties,
this.middlewareStack
);
this.middlewareStack.add(
__aws_sdk_middleware_content_length.contentLengthMiddleware(
this.config.bodyLengthChecker
),
{
step: "build",
priority: -80,
tags: { SET_CONTENT_LENGTH: true }
}
);
const intermediaConfig_0 = ProtocolConfig.resolve({
...RDSRuntimeConfiguration,
...configuration
});
super(intermediaConfig_0);
let intermediaConfig_1 = RegionConfiguration.resolve(intermediaConfig_0);
let intermediaConfig_2 = AwsAuthConfiguration.resolve(intermediaConfig_1);
let intermediaConfig_3 = EndpointsConfig.resolve(intermediaConfig_2);
let intermediaConfig_4 = RetryConfig.resolve(intermediaConfig_3);
let intermediaConfig_5 = UserAgentConfig.resolve(intermediaConfig_4);
this.config = intermediaConfig_5;
super.use(contentLengthPlugin(this.config));
if (this.config.maxRetries > 0) {
this.middlewareStack.add(
__aws_sdk_retry_middleware.retryMiddleware(
this.config.maxRetries,
this.config.retryDecider,
this.config.delayDecider
),
{
step: "finalize",
priority: Infinity,
tags: { RETRY: true }
}
);
super.use(retryPlugin(this.config));
}
this.middlewareStack.add(
__aws_sdk_signing_middleware.signingMiddleware<
InputTypesUnion,
OutputTypesUnion
>(this.config.signer),
{
step: "finalize",
priority: 0,
tags: { SIGNATURE: true }
}
);
this.middlewareStack.add(
__aws_sdk_middleware_header_default.headerDefault({
"User-Agent": __aws_sdk_util_user_agent_node.defaultUserAgent(
ServiceMetadata.serviceId || ServiceMetadata.endpointPrefix,
clientVersion
)
}),
{
step: "build",
priority: 0,
tags: { SET_USER_AGENT: true }
}
);
super.use(signingPlugin(this.config));
super.use(UserAgentPlugin(this.config));
}

destroy(): void {
if (
!this.config._user_injected_http_handler &&
typeof this.config.httpHandler.destroy === 'function'
) {
this.config.httpHandler.destroy();
}
}

/**
* This will need to be revised when the command interface lands.
*/
send<InputType extends InputTypesUnion, OutputType extends OutputTypesUnion>(
command: __aws_sdk_types.Command<
InputTypesUnion,
InputType,
OutputTypesUnion,
OutputType,
RDSDataResolvedConfiguration
>,
options?: HttpOptions
): Promise<OutputType>;
send<InputType extends InputTypesUnion, OutputType extends OutputTypesUnion>(
command: __aws_sdk_types.Command<
InputTypesUnion,
InputType,
OutputTypesUnion,
OutputType,
RDSDataResolvedConfiguration
>,
options: HttpOptions,
cb: (err: any, data?: OutputType) => void
): void;
send<InputType extends InputTypesUnion, OutputType extends OutputTypesUnion>(
command: __aws_sdk_types.Command<
InputTypesUnion,
InputType,
OutputTypesUnion,
OutputType,
RDSDataResolvedConfiguration
>,
options?: HttpOptions,
cb?: (err: any, data?: OutputType) => void
): Promise<OutputType> | void {
const handler = command.resolveMiddleware(
this.middlewareStack,
this.config,
options
);
if (cb) {
handler(command)
.then(result => cb(null, result.output), (err: any) => cb(err))
.catch(
// prevent any errors thrown in the callback from triggering an
// unhandled promise rejection
() => {}
);
} else {
return handler(command).then(result => result.output);
}
}
}
Loading

0 comments on commit 033f953

Please sign in to comment.