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

Conversation

AllanZhengYP
Copy link
Contributor

A demo of refactored service client.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@AllanZhengYP AllanZhengYP added the smithy-codegen Changes regarding supporting smithy model. Will be merged to smithy-codegen branch label Oct 2, 2019
@codecov-io
Copy link

codecov-io commented Oct 2, 2019

Codecov Report

Merging #384 into smithy-codegen will decrease coverage by 0.3%.
The diff coverage is 92.98%.

Impacted file tree graph

@@                Coverage Diff                 @@
##           smithy-codegen     #384      +/-   ##
==================================================
- Coverage           97.28%   96.97%   -0.31%     
==================================================
  Files                  69       69              
  Lines                1177     1156      -21     
  Branches              215      211       -4     
==================================================
- Hits                 1145     1121      -24     
- Misses                 32       35       +3
Impacted Files Coverage Δ
packages/middleware-stack/src/index.ts 100% <ø> (ø) ⬆️
packages/retry-middleware/src/defaultStrategy.ts 100% <100%> (ø)
packages/retry-middleware/src/retryDecider.ts 100% <100%> (ø) ⬆️
...ackages/node-http-handler/src/node-http-handler.ts 96.42% <100%> (ø) ⬆️
packages/stream-collector-node/src/index.ts 100% <100%> (ø) ⬆️
packages/retry-middleware/src/configurations.ts 100% <100%> (ø)
packages/retry-middleware/src/retryMiddleware.ts 92% <71.42%> (-8%) ⬇️
packages/signing-middleware/src/middleware.ts 85.71% <85.71%> (ø)
packages/middleware-header-default/src/index.ts
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c8f5a3a...4c526b0. Read the comment docs.

@AllanZhengYP
Copy link
Contributor Author

One more thought on the config: Now I put all the config in the config-resolver package. I think I would make more sense if I put AuthConfig to signingMiddleware package, put retryConfig to retryMiddleware package, put protocolConfig into httpProtocol package. This make codebase more modularized and show the relationship between middleware and its config

AllanZhengYP and others added 5 commits October 2, 2019 16:34
* use config interface as middleware parameter
* use smithy command as super class of all commands so we can support use() in commands
* 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
@AllanZhengYP
Copy link
Contributor Author

I added a (de)serializer utils function bag to the interface. Check this commit: 72a02d9. I make the utils interface general on purpose because (De)Serializer interfaces are suppose to be share with non-AWS services, so no pre-assumption there.

@AllanZhengYP
Copy link
Contributor Author

We need to add browser client smoke test scripts to this demo client also.

Copy link
Member

@trivikr trivikr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My recommendations for changing to arrow functions are non-blocking, and can be taken up separately.
I thought of suggesting them, as we're rewriting CodeGen anyway

Comment on lines 31 to 40
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);
this.config = intermediaConfig_4;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid usage of temporary variables, can we do this instead?

const initialConfig = ProtocolConfig.resolve({
  ...RDSRuntimeConfiguration,
  ...configuration
});
super(initialConfig);

this.config = RetryConfig.resolve(
  EndpointsConfig.resolve(
    AwsAuthConfiguration.resolve(RegionConfiguration.resolve(initialConfig))
  )
);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This manner is stupidly easy for codegen. The advice looks normal but might be hard to codegen.

HandlerOptions as InjectOptions
} from "@aws-sdk/types";

export class Command<InputType extends object, OutputType extends object> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be called SmithyClientCommand or SmithyCommand?

Suggested change
export class Command<InputType extends object, OutputType extends object> {
export class SmithyClientCommand<InputType extends object, OutputType extends object> {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved by changing SmithyClient to Client

@@ -63,7 +41,7 @@ export class ExecuteStatementCommand {
};

return stack.resolve(
(request: FinalizeHandlerArguments<any>) => {return httpHandler.handle(request.request as HttpRequest, options || {})},
(request: FinalizeHandlerArguments<any>) => { return httpHandler.handle(request.request as HttpRequest, options || {}) },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: arrow functions

Suggested change
(request: FinalizeHandlerArguments<any>) => { return httpHandler.handle(request.request as HttpRequest, options || {}) },
(request: FinalizeHandlerArguments<any>) => (httpHandler.handle(request.request as HttpRequest, options || {})),

Comment on lines 259 to 273
for (let ColumnMetadata of input) {
list.push(columnMetadataAwsRestJson1_1Deserialize(ColumnMetadata));
if (input !== undefined) {
for (let ColumnMetadata of input) {
list.push(columnMetadataAwsRestJson1_1Deserialize(ColumnMetadata));
}
}
return list;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: if interested, this method can be written in a functional programming way to reduce bugs

const columnMetadataListAwsRestJson1_1Deserialize = (
  input: any
): Array<ColumnMetadata> =>
  input &&
  input.map(columnMetadata =>
    columnMetadataAwsRestJson1_1Deserialize(columnMetadata)
  );

Ditto for other methods.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in bed5267

Comment on lines 335 to 341
function deserializeMetadata(output: HttpResponse): ResponseMetadata {
return {
httpStatusCode: output.statusCode,
httpHeaders: output.headers,
requestId: output.headers["x-amzn-requestid"]
};
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: arrow functions?

const deserializeMetadata = (output: HttpResponse): ResponseMetadata => ({
  httpStatusCode: output.statusCode,
  httpHeaders: output.headers,
  requestId: output.headers["x-amzn-requestid"]
});

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in bed5267

export function resolve<T>(input: T & Input): T & Resolved {
return {
...input,
maxRetries: input.maxRetries === undefined ? 3 : input.maxRetries
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
maxRetries: input.maxRetries === undefined ? 3 : input.maxRetries
maxRetries: input.maxRetries || 3

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maxRetries can be set to 0.

) {
const { middleware, step, priority, tags } = injectable;
this.middlewareStack.add(
// @ts-ignore
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add the TypeScript Error code here?
There's no option to ignore specific errors (microsoft/TypeScript#19139), but it's better to document it

Ditto for other places where // @ts-ignore is added

Comment on lines 5 to 9
export const streamCollector: StreamCollector = function streamCollector(
stream: Readable
): Promise<Uint8Array> {
return new Promise((resolve, reject) => {
const collector = new Collector();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Convert to arrow function?

export const streamCollector: StreamCollector = (
  stream: Readable
): Promise<Uint8Array> =>
  new Promise((resolve, reject) => {
    /* Code inside promise */
  });

@AllanZhengYP AllanZhengYP marked this pull request as ready for review October 7, 2019 16:54
@AllanZhengYP AllanZhengYP force-pushed the smithy-codegen-client-refactor branch from bed5267 to 72c5dd2 Compare October 7, 2019 17:28
@AllanZhengYP AllanZhengYP requested a review from mtdowling October 7, 2019 18:18
@srchase srchase merged commit 033f953 into aws:smithy-codegen Oct 8, 2019
@lock
Copy link

lock bot commented Oct 15, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 15, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
smithy-codegen Changes regarding supporting smithy model. Will be merged to smithy-codegen branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants