Skip to content
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

feat(types): improve streaming payload types #835

Merged
merged 1 commit into from
Jul 21, 2023

Conversation

kuhe
Copy link
Contributor

@kuhe kuhe commented Jul 17, 2023

closes aws/aws-sdk-js-v3#4933

JSv3 codegen diff: aws/aws-sdk-js-v3#4987

This PR replaces manually constructed unions in streaming payloads with an alias type that has attached explanatory documentation.

Old Streaming input/output types:

export type PutObjectCommandInput = Omit<PutObjectRequest, "Body"> & {
  Body?: PutObjectRequest["Body"] | string | Uint8Array | Buffer;
};

export interface GetObjectCommandOutput extends WithSdkStreamMixin<GetObjectOutput, "Body">, MetadataBearer {}

Note the blob type's base type is Readable | Blob | ReadableStream, making the full union of the input:
string | Uint8Array | Buffer | Readable | Blob | ReadableStream.

The problem with these inlined unions is that it isn't clear why the type is so wide, and what types are truly compatible with a particular streaming payload.

New streaming intput/output types:

export interface PutObjectCommandInput extends Omit<PutObjectRequest, "Body"> {
  Body?: StreamingBlobPayloadInputTypes;
}

export interface GetObjectCommandOutput extends Omit<GetObjectOutput, "Body">, MetadataBearer {
  Body?: StreamingBlobPayloadOutputTypes;
}

The type union aliases provide a description of the union contents, why they are typed this way, and when you might want to use each union member.

@kuhe kuhe requested review from a team as code owners July 17, 2023 20:40
@kuhe kuhe force-pushed the feat/streaming-types branch 2 times, most recently from 348da92 to 26d0451 Compare July 17, 2023 21:11
@kuhe kuhe force-pushed the feat/streaming-types branch 2 times, most recently from e228742 to 321af3b Compare July 18, 2023 19:21
@kuhe kuhe force-pushed the feat/streaming-types branch 4 times, most recently from 0be3fe7 to 5b3fd46 Compare July 19, 2023 18:16
@kuhe kuhe force-pushed the feat/streaming-types branch from 5b3fd46 to a4c9552 Compare July 20, 2023 19:38
@kuhe kuhe force-pushed the feat/streaming-types branch 4 times, most recently from c8990d1 to a6b3f19 Compare July 20, 2023 20:50
@kuhe kuhe force-pushed the feat/streaming-types branch from a6b3f19 to 479e2b3 Compare July 21, 2023 16:59
@kuhe kuhe merged commit d90a45b into smithy-lang:main Jul 21, 2023
@kuhe kuhe deleted the feat/streaming-types branch July 21, 2023 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

create a type alias for http payloads
3 participants