Skip to content

Commit 3e8876d

Browse files
committed
inject sdk stream utility function to the stream response
1 parent cb79c0a commit 3e8876d

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/SymbolVisitor.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,11 @@ public String toMemberName(MemberShape shape) {
138138
@Override
139139
public Symbol blobShape(BlobShape shape) {
140140
if (shape.hasTrait(StreamingTrait.class)) {
141-
// Note: `Readable` needs an import and a dependency.
142-
return createSymbolBuilder(shape, "Readable | ReadableStream | Blob", null)
141+
// Note: `Readable` and `SdkStream` needs an import and a dependency.
142+
return createSymbolBuilder(shape, "SdkStream<Readable | ReadableStream | Blob>", null)
143143
.addReference(Symbol.builder().name("Readable").namespace("stream", "/").build())
144+
.addReference(Symbol.builder().name("SdkStream").namespace(
145+
TypeScriptDependency.AWS_SDK_TYPES.packageName, "/").build())
144146
.build();
145147
}
146148

smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/HttpBindingProtocolGenerator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2361,8 +2361,8 @@ private HttpBinding readPayload(
23612361
// Don't generate non-eventstream payload shape again.
23622362
return null;
23632363
}
2364-
// If payload is streaming, return raw low-level stream directly.
2365-
writer.write("const data: any = output.body;");
2364+
// If payload is streaming, return low-level stream with the stream utility functions mixin.
2365+
writer.write("const data: any = context.sdkStreamMixin(output.body);");
23662366
} else if (target instanceof BlobShape) {
23672367
// If payload is non-streaming Blob, only need to collect stream to binary data (Uint8Array).
23682368
writer.write("const data: any = await collectBody(output.body, context);");

smithy-typescript-codegen/src/main/resources/META-INF/services/software.amazon.smithy.typescript.codegen.integration.TypeScriptIntegration

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ software.amazon.smithy.typescript.codegen.integration.AddChecksumRequiredDepende
33
software.amazon.smithy.typescript.codegen.integration.AddDefaultsModeDependency
44
software.amazon.smithy.typescript.codegen.integration.AddHttpApiKeyAuthPlugin
55
software.amazon.smithy.typescript.codegen.integration.AddBaseServiceExceptionClass
6+
software.amazon.smithy.typescript.codegen.integration.SdkStreamUtilsMixin

0 commit comments

Comments
 (0)