Skip to content

Commit e88ac0e

Browse files
committed
inject sdk stream utility function to the stream response
1 parent 90f6909 commit e88ac0e

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.function.Consumer;
3131
import java.util.logging.Logger;
3232
import java.util.stream.Collectors;
33+
3334
import software.amazon.smithy.codegen.core.CodegenException;
3435
import software.amazon.smithy.codegen.core.Symbol;
3536
import software.amazon.smithy.codegen.core.SymbolProvider;
@@ -2300,8 +2301,8 @@ private HttpBinding readPayload(
23002301

23012302
// Handle streaming shapes differently.
23022303
if (target.hasTrait(StreamingTrait.class)) {
2303-
// If payload is streaming, return raw low-level stream directly.
2304-
writer.write("const data: any = output.body;");
2304+
// If payload is streaming, return low-level stream with the stream utility functions mixin.
2305+
writer.write("const data: any = context.sdkStreamMixin(output.body);");
23052306
} else if (target instanceof BlobShape) {
23062307
// If payload is non-streaming Blob, only need to collect stream to binary data (Uint8Array).
23072308
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)