-
Notifications
You must be signed in to change notification settings - Fork 618
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
Smithy codegen Client Refactor #384
Conversation
'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: aws#94
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
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 |
* 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
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. |
We need to add browser client smoke test scripts to this demo client also. |
There was a problem hiding this 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
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; |
There was a problem hiding this comment.
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))
)
);
There was a problem hiding this comment.
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> { |
There was a problem hiding this comment.
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
?
export class Command<InputType extends object, OutputType extends object> { | |
export class SmithyClientCommand<InputType extends object, OutputType extends object> { |
There was a problem hiding this comment.
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 || {}) }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: arrow functions
(request: FinalizeHandlerArguments<any>) => { return httpHandler.handle(request.request as HttpRequest, options || {}) }, | |
(request: FinalizeHandlerArguments<any>) => (httpHandler.handle(request.request as HttpRequest, options || {})), |
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; | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in bed5267
function deserializeMetadata(output: HttpResponse): ResponseMetadata { | ||
return { | ||
httpStatusCode: output.statusCode, | ||
httpHeaders: output.headers, | ||
requestId: output.headers["x-amzn-requestid"] | ||
}; | ||
} |
There was a problem hiding this comment.
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"]
});
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maxRetries: input.maxRetries === undefined ? 3 : input.maxRetries | |
maxRetries: input.maxRetries || 3 |
There was a problem hiding this comment.
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.
packages/smithy-client/src/client.ts
Outdated
) { | ||
const { middleware, step, priority, tags } = injectable; | ||
this.middlewareStack.add( | ||
// @ts-ignore |
There was a problem hiding this comment.
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
export const streamCollector: StreamCollector = function streamCollector( | ||
stream: Readable | ||
): Promise<Uint8Array> { | ||
return new Promise((resolve, reject) => { | ||
const collector = new Collector(); |
There was a problem hiding this comment.
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 */
});
* signing middleware * retry middleware; Also update retry config interface by introducing RetryStrategy class
…llanFly120/aws-sdk-js-v3 into smithy-codegen-client-refactor
bed5267
to
72c5dd2
Compare
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. |
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.