feat(codegen): general data mapping function #576
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem:
Object field names are often repeated multiple times per line in code that is only transferring fields from one object to another (mapping), with repetitive checks.
Examples
Request headers
Response headers
Body deserialization
... and more.
Proposed solution:
A general purpose data mapping function. It accepts transfer instructions in a brevity form:
Where the key's value in the target object is created with a combination of the filter and the value, both of which can be value expressions or lazy functional providers.
source: https://github.com/aws/aws-sdk-js-v3/blob/800e8e97ea1f184111e2a85208b07d68fb7297b2/packages/smithy-client/src/object-mapping.ts
Also targeted were the following repeated patterns:
Resolved path construction, XML node creation, and default error deserialization. These were turned into helper functions.
Effects
The change for S3 in for example dist-cjs and dist-es:
dist-cjs/protocols -> 568kb to 440kb
dist-es/protocols -> 692kb to 556kb
overall reduction is approximately 0.1mb out of 1.2 to 1.3mb.