Skip to content

Commit

Permalink
feat(types): codegen for improved streaming payload types
Browse files Browse the repository at this point in the history
  • Loading branch information
kuhe committed Jul 25, 2023
1 parent 632c5a5 commit 4ede806
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,18 +143,23 @@ static void writeClientCommandStreamingInputType(
MemberShape streamingMember,
String commandName
) {
writer.addImport("StreamingBlobPayloadInputTypes", null, TypeScriptDependency.SMITHY_TYPES);
String memberName = streamingMember.getMemberName();
String optionalSuffix = streamingMember.isRequired() ? "" : "?";
writer.openBlock("export type $LType = Omit<$T, $S> & {", "};", typeName,
containerSymbol, memberName, () -> {
writer.writeDocs(String.format("For *`%1$s[\"%2$s\"]`*, see {@link %1$s.%2$s}.",
containerSymbol.getName(), memberName));
writer.write("$1L$2L: $3T[$1S]|string|Uint8Array|Buffer;", memberName, optionalSuffix,
containerSymbol);
});

writer.writeDocs("@public\n\nThe input for {@link " + commandName + "}.");
writer.write("export interface $1L extends $1LType {}", typeName);
writer.write(
"""
export interface $L extends Omit<$T, $S> {
$L$L: StreamingBlobPayloadInputTypes;
}
""",
typeName,
containerSymbol,
memberName,
memberName,
optionalSuffix
);
}

/**
Expand All @@ -170,16 +175,22 @@ static void writeClientCommandStreamingOutputType(
String commandName
) {
String memberName = streamingMember.getMemberName();
String optionalSuffix = streamingMember.isRequired() ? "" : "?";
writer.addImport("MetadataBearer", "__MetadataBearer", TypeScriptDependency.SMITHY_TYPES);
writer.addImport("SdkStream", "__SdkStream", TypeScriptDependency.SMITHY_TYPES);
writer.addImport("WithSdkStreamMixin", "__WithSdkStreamMixin", TypeScriptDependency.SMITHY_TYPES);
writer.addImport("StreamingBlobPayloadOutputTypes", null, TypeScriptDependency.SMITHY_TYPES);

writer.writeDocs("@public\n\nThe output of {@link " + commandName + "}.");
writer.write(
"export interface $L extends __WithSdkStreamMixin<$T, $S>, __MetadataBearer {}",
"""
export interface $L extends Omit<$T, $S>, __MetadataBearer {
$L$L: StreamingBlobPayloadOutputTypes;
}
""",
typeName,
containerSymbol,
memberName
memberName,
memberName,
optionalSuffix
);
}

Expand All @@ -204,13 +215,13 @@ static void writeClientCommandBlobPayloadInputType(
String memberName = payloadMember.getMemberName();
String optionalSuffix = payloadMember.isRequired() ? "" : "?";

writer.addImport("BlobTypes", null, TypeScriptDependency.AWS_SDK_TYPES);
writer.addImport("BlobPayloadInputTypes", null, TypeScriptDependency.SMITHY_TYPES);

writer.writeDocs("@public");
writer.write(
"""
export type $LType = Omit<$T, $S> & {
$L: BlobTypes;
$L: BlobPayloadInputTypes;
};
""",
typeName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,14 @@ public String toMemberName(MemberShape shape) {
public Symbol blobShape(BlobShape shape) {
if (shape.hasTrait(StreamingTrait.class)) {
// Note: `Readable` needs an import and a dependency.
return createSymbolBuilder(shape, "Readable | ReadableStream | Blob", null)
.addReference(Symbol.builder().name("Readable").namespace("stream", "/").build())
return createSymbolBuilder(shape, "StreamingBlobTypes", null)
.addReference(
Symbol.builder()
.addDependency(TypeScriptDependency.SMITHY_TYPES)
.name("StreamingBlobTypes")
.namespace("@smithy/types", "/")
.build()
)
.build();
}

Expand Down

0 comments on commit 4ede806

Please sign in to comment.