Skip to content

Smithy codegen Client Refactor #384

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
67f0792
feat: remove 'apply' entry from configuration definition
AllanZhengYP Sep 29, 2019
044e94d
feat: complete PoC composable configuration
AllanZhengYP Sep 30, 2019
5378332
feat: change config resolver to multiple client config components
AllanZhengYP Oct 2, 2019
f084181
feat: rename stack finalize step to finalizeRequest
AllanZhengYP Oct 2, 2019
6203448
feat: add use() to smithy client to inject middleware
AllanZhengYP Oct 2, 2019
2c3dc2c
fix: rename resolvedruntime configuration
AllanZhengYP Oct 2, 2019
57c2c29
fix: remove exported reviouslyResolved interface
AllanZhengYP Oct 2, 2019
5d966ec
fix: request path
Oct 3, 2019
5cae1e2
feat: add metadatabearer to shapes
Oct 3, 2019
7fbf9d0
feat: parse derializing utils as parameters
AllanZhengYP Oct 4, 2019
72a02d9
feat: parse serialize(deserialize) util functions from client config
AllanZhengYP Oct 4, 2019
cbe55c3
feat: add metadata deserializer
Oct 4, 2019
423a7d1
fix: await body parsing
Oct 4, 2019
64ed628
docs: add documentation for config properties
AllanZhengYP Oct 5, 2019
a3808f0
feat: add defaultUserAgen config
AllanZhengYP Oct 5, 2019
a86e44f
feat: move some config components to middleware folder
AllanZhengYP Oct 7, 2019
4a76cc3
feat: add input type proxy for better intellisense
AllanZhengYP Oct 7, 2019
1f1cd82
docs: add config doc block for retry config
AllanZhengYP Oct 7, 2019
a3fdc01
feat: add a user agent middleware to support custom useragent
AllanZhengYP Oct 7, 2019
7ee70a7
fix: address style suggestions--FP
AllanZhengYP Oct 7, 2019
a7332b8
Merge branch 'smithy-codegen-client-refactor' of https://github.com/A…
AllanZhengYP Oct 7, 2019
72c5dd2
fix: use arrow functions
Oct 7, 2019
4c526b0
Merge branch 'smithy-codegen' into smithy-codegen-client-refactor
AllanZhengYP Oct 8, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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