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

Update codegen for package migration #791

Merged
merged 1 commit into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static ApplicationProtocol createDefaultHttpApplicationProtocol() {
return new ApplicationProtocol(
"http",
SymbolReference.builder()
.symbol(createHttpSymbol(TypeScriptDependency.AWS_SDK_TYPES, "HttpHandlerOptions"))
.symbol(createHttpSymbol(TypeScriptDependency.SMITHY_TYPES, "HttpHandlerOptions"))
.alias("__HttpHandlerOptions")
.build(),
SymbolReference.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ public static String getOperationSerializerContextType(
// If event stream trait exists, add corresponding serde context type to the intersection type.
EventStreamIndex eventStreamIndex = EventStreamIndex.of(model);
if (eventStreamIndex.getInputInfo(operation).isPresent()) {
writer.addImport("EventStreamSerdeContext", "__EventStreamSerdeContext", "@aws-sdk/types");
writer.addImport("EventStreamSerdeContext", "__EventStreamSerdeContext",
TypeScriptDependency.SMITHY_TYPES);
contextInterfaceList.add("__EventStreamSerdeContext");
}
return String.join(" & ", contextInterfaceList);
Expand All @@ -97,12 +98,12 @@ public static String getOperationDeserializerContextType(
EventStreamIndex eventStreamIndex = EventStreamIndex.of(model);
if (eventStreamIndex.getOutputInfo(operation).isPresent()) {
writer.addImport("EventStreamSerdeContext", "__EventStreamSerdeContext",
TypeScriptDependency.AWS_SDK_TYPES.packageName);
TypeScriptDependency.SMITHY_TYPES);
contextInterfaceList.add("__EventStreamSerdeContext");
}
if (AddSdkStreamMixinDependency.hasStreamingBlobDeser(settings, model, operation)) {
writer.addImport("SdkStreamSerdeContext", "__SdkStreamSerdeContext",
TypeScriptDependency.AWS_SDK_TYPES.packageName);
TypeScriptDependency.SMITHY_TYPES);
contextInterfaceList.add("__SdkStreamSerdeContext");
}
return String.join(" & ", contextInterfaceList);
Expand Down Expand Up @@ -169,9 +170,9 @@ static void writeClientCommandStreamingOutputType(
String commandName
) {
String memberName = streamingMember.getMemberName();
writer.addImport("MetadataBearer", "__MetadataBearer", TypeScriptDependency.AWS_SDK_TYPES.packageName);
writer.addImport("SdkStream", "__SdkStream", TypeScriptDependency.AWS_SDK_TYPES.packageName);
writer.addImport("WithSdkStreamMixin", "__WithSdkStreamMixin", TypeScriptDependency.AWS_SDK_TYPES.packageName);
writer.addImport("MetadataBearer", "__MetadataBearer", TypeScriptDependency.SMITHY_TYPES);
writer.addImport("SdkStream", "__SdkStream", TypeScriptDependency.SMITHY_TYPES);
writer.addImport("WithSdkStreamMixin", "__WithSdkStreamMixin", TypeScriptDependency.SMITHY_TYPES);

writer.writeDocs("@public\n\nThe output of {@link " + commandName + "}.");
writer.write(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@ private void generateClientCommand() {
writer.addImport(configType, configType, serviceSymbol.getNamespace());
writer.addImport("ServiceInputTypes", "ServiceInputTypes", serviceSymbol.getNamespace());
writer.addImport("ServiceOutputTypes", "ServiceOutputTypes", serviceSymbol.getNamespace());
writer.addImport("Command", "$Command", "@aws-sdk/smithy-client");
writer.addImport("FinalizeHandlerArguments", "FinalizeHandlerArguments", "@aws-sdk/types");
writer.addImport("Handler", "Handler", "@aws-sdk/types");
writer.addImport("HandlerExecutionContext", "HandlerExecutionContext", "@aws-sdk/types");
writer.addImport("MiddlewareStack", "MiddlewareStack", "@aws-sdk/types");
writer.addImport("Command", "$Command", TypeScriptDependency.AWS_SMITHY_CLIENT);
writer.addImport("FinalizeHandlerArguments", "FinalizeHandlerArguments", TypeScriptDependency.SMITHY_TYPES);
writer.addImport("Handler", "Handler", TypeScriptDependency.SMITHY_TYPES);
writer.addImport("HandlerExecutionContext", "HandlerExecutionContext", TypeScriptDependency.SMITHY_TYPES);
writer.addImport("MiddlewareStack", "MiddlewareStack", TypeScriptDependency.SMITHY_TYPES);

String name = symbol.getName();

Expand Down Expand Up @@ -236,7 +236,7 @@ private void generateEndpointParameterInstructionProvider() {
if (!service.hasTrait(EndpointRuleSetTrait.class)) {
return;
}
writer.addImport("EndpointParameterInstructions", null, "@aws-sdk/middleware-endpoint");
writer.addImport("EndpointParameterInstructions", null, "@smithy/middleware-endpoint");
writer.openBlock(
"public static getEndpointParameterInstructions(): EndpointParameterInstructions {", "}",
() -> {
Expand Down Expand Up @@ -302,7 +302,7 @@ private void generateCommandMiddlewareResolver(String configType) {
writer.addImport(
"getEndpointPlugin",
"getEndpointPlugin",
"@aws-sdk/middleware-endpoint");
"@smithy/middleware-endpoint");
writer.openBlock(
"this.middlewareStack.use(getEndpointPlugin(configuration, ",
"));",
Expand Down Expand Up @@ -407,7 +407,7 @@ private void writeInputType(String typeName, Optional<StructureShape> inputShape
private void writeOutputType(String typeName, Optional<StructureShape> outputShape, String commandName) {
// Output types should always be MetadataBearers, possibly in addition
// to a defined output shape.
writer.addImport("MetadataBearer", "__MetadataBearer", TypeScriptDependency.AWS_SDK_TYPES.packageName);
writer.addImport("MetadataBearer", "__MetadataBearer", TypeScriptDependency.SMITHY_TYPES);
if (outputShape.isPresent()) {
StructureShape output = outputShape.get();
List<MemberShape> blobStreamingMembers = getBlobStreamingMembers(model, output);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ private void onlyIfProtocolMatches(HttpMalformedRequestTestCase testCase, Runnab
private void initializeWriterIfNeeded() {
if (writer == null) {
context.getWriterDelegator().useFileWriter(createTestCaseFilename(), writer -> this.writer = writer);
writer.addDependency(TypeScriptDependency.AWS_SDK_TYPES);
writer.addDependency(TypeScriptDependency.SMITHY_TYPES);
writer.addDependency(TypeScriptDependency.SMITHY_TYPES);
writer.addDependency(TypeScriptDependency.PROTOCOL_HTTP);
// Add the template to each generated test.
Expand Down Expand Up @@ -494,7 +494,7 @@ private void writeHttpQueryAssertions(HttpRequestTestCase testCase) {
if (!explicitQueryValues.isEmpty()) {
// Use buildQueryString like the fetch handler will.
writer.addDependency(TypeScriptDependency.AWS_SDK_QUERYSTRING_BUILDER);
writer.addImport("buildQueryString", "buildQueryString", "@aws-sdk/querystring-builder");
writer.addImport("buildQueryString", "buildQueryString", "@smithy/querystring-builder");

writer.write("const queryString = buildQueryString(r.query);");
explicitQueryValues.forEach(explicitQueryValue ->
Expand Down Expand Up @@ -541,7 +541,7 @@ private void writeHttpBodyAssertions(String body, String mediaType, boolean isCl
if (isClientTest) {
writer.write("const utf8Encoder = client.config.utf8Encoder;");
} else {
writer.addImport("toUtf8", "__utf8Encoder", "@aws-sdk/util-utf8");
writer.addImport("toUtf8", "__utf8Encoder", "@smithy/util-utf8");
writer.write("const utf8Encoder = __utf8Encoder;");
}

Expand Down Expand Up @@ -834,7 +834,7 @@ private void writeRequestParamAssertions(OperationShape operation, HttpRequestTe

writeParamAssertions(writer, payloadBinding, () -> {
// TODO: replace this with a collector from the server config once it's available
writer.addImport("streamCollector", "__streamCollector", "@aws-sdk/node-http-handler");
writer.addImport("streamCollector", "__streamCollector", "@smithy/node-http-handler");
writer.write("const comparableBlob = await __streamCollector(r[$S]);",
payloadBinding.get().getMemberName());
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void run() {
writer.addImport(serviceSymbol.getName(), serviceSymbol.getName(), serviceSymbol.getNamespace());

// Import Pagination types
writer.addImport("Paginator", "Paginator", "@aws-sdk/types");
writer.addImport("Paginator", "Paginator", "@smithy/types");
writer.addImport(paginationType, paginationType,
Paths.get(".", PAGINATION_INTERFACE_FILE.replace(".ts", "")).toString());

Expand All @@ -116,7 +116,7 @@ static void generateServicePaginationInterfaces(
Symbol service,
TypeScriptWriter writer
) {
writer.addImport("PaginationConfiguration", "PaginationConfiguration", "@aws-sdk/types");
writer.addImport("PaginationConfiguration", "PaginationConfiguration", "@smithy/types");
writer.addImport(service.getName(), service.getName(), service.getNamespace());

writer.writeDocs("@public")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,73 +45,71 @@ final class RuntimeConfigGenerator {
"requestHandler", writer -> {
writer.addDependency(TypeScriptDependency.AWS_SDK_NODE_HTTP_HANDLER);
writer.addImport("NodeHttpHandler", "RequestHandler",
TypeScriptDependency.AWS_SDK_NODE_HTTP_HANDLER.packageName);
TypeScriptDependency.AWS_SDK_NODE_HTTP_HANDLER);
writer.write("new RequestHandler(defaultConfigProvider)");
},
"sha256", writer -> {
writer.addDependency(TypeScriptDependency.AWS_SDK_HASH_NODE);
writer.addImport("Hash", "Hash",
TypeScriptDependency.AWS_SDK_HASH_NODE.packageName);
TypeScriptDependency.AWS_SDK_HASH_NODE);
writer.write("Hash.bind(null, \"sha256\")");
},
"bodyLengthChecker", writer -> {
writer.addDependency(TypeScriptDependency.AWS_SDK_UTIL_BODY_LENGTH_NODE);
writer.addImport("calculateBodyLength", "calculateBodyLength",
TypeScriptDependency.AWS_SDK_UTIL_BODY_LENGTH_NODE.packageName);
TypeScriptDependency.AWS_SDK_UTIL_BODY_LENGTH_NODE);
writer.write("calculateBodyLength");
},
"streamCollector", writer -> {
writer.addDependency(TypeScriptDependency.AWS_SDK_NODE_HTTP_HANDLER);
writer.addImport("streamCollector", "streamCollector",
TypeScriptDependency.AWS_SDK_NODE_HTTP_HANDLER.packageName);
TypeScriptDependency.AWS_SDK_NODE_HTTP_HANDLER);
writer.write("streamCollector");
}
);
private final Map<String, Consumer<TypeScriptWriter>> browserRuntimeConfigDefaults = MapUtils.of(
"requestHandler", writer -> {
writer.addDependency(TypeScriptDependency.AWS_SDK_FETCH_HTTP_HANDLER);
writer.addImport("FetchHttpHandler", "RequestHandler",
TypeScriptDependency.AWS_SDK_FETCH_HTTP_HANDLER.packageName);
TypeScriptDependency.AWS_SDK_FETCH_HTTP_HANDLER);
writer.write("new RequestHandler(defaultConfigProvider)");
},
"sha256", writer -> {
writer.addDependency(TypeScriptDependency.AWS_CRYPTO_SHA256_BROWSER);
writer.addImport("Sha256", "Sha256",
TypeScriptDependency.AWS_CRYPTO_SHA256_BROWSER.packageName);
writer.addImport("Sha256", "Sha256", TypeScriptDependency.AWS_CRYPTO_SHA256_BROWSER);
writer.write("Sha256");
},
"bodyLengthChecker", writer -> {
writer.addDependency(TypeScriptDependency.AWS_SDK_UTIL_BODY_LENGTH_BROWSER);
writer.addImport("calculateBodyLength", "calculateBodyLength",
TypeScriptDependency.AWS_SDK_UTIL_BODY_LENGTH_BROWSER.packageName);
TypeScriptDependency.AWS_SDK_UTIL_BODY_LENGTH_BROWSER);
writer.write("calculateBodyLength");
},
"streamCollector", writer -> {
writer.addDependency(TypeScriptDependency.AWS_SDK_FETCH_HTTP_HANDLER);
writer.addImport("streamCollector", "streamCollector",
TypeScriptDependency.AWS_SDK_FETCH_HTTP_HANDLER.packageName);
TypeScriptDependency.AWS_SDK_FETCH_HTTP_HANDLER);
writer.write("streamCollector");
}
);
private final Map<String, Consumer<TypeScriptWriter>> reactNativeRuntimeConfigDefaults = MapUtils.of(
"sha256", writer -> {
writer.addDependency(TypeScriptDependency.AWS_CRYPTO_SHA256_JS);
writer.addImport("Sha256", "Sha256",
TypeScriptDependency.AWS_CRYPTO_SHA256_JS.packageName);
writer.addImport("Sha256", "Sha256", TypeScriptDependency.AWS_CRYPTO_SHA256_JS);
writer.write("Sha256");
}
);
private final Map<String, Consumer<TypeScriptWriter>> sharedRuntimeConfigDefaults = MapUtils.of(
"base64Decoder", writer -> {
writer.addDependency(TypeScriptDependency.AWS_SDK_UTIL_BASE64);
writer.addImport("fromBase64", "fromBase64",
TypeScriptDependency.AWS_SDK_UTIL_BASE64.packageName);
TypeScriptDependency.AWS_SDK_UTIL_BASE64);
writer.write("fromBase64");
},
"base64Encoder", writer -> {
writer.addDependency(TypeScriptDependency.AWS_SDK_UTIL_BASE64);
writer.addImport("toBase64", "toBase64",
TypeScriptDependency.AWS_SDK_UTIL_BASE64.packageName);
TypeScriptDependency.AWS_SDK_UTIL_BASE64);
writer.write("toBase64");
},
"disableHostPrefix", writer -> {
Expand All @@ -120,19 +118,19 @@ final class RuntimeConfigGenerator {
"urlParser", writer -> {
writer.addDependency(TypeScriptDependency.AWS_SDK_URL_PARSER);
writer.addImport("parseUrl", "parseUrl",
TypeScriptDependency.AWS_SDK_URL_PARSER.packageName);
TypeScriptDependency.AWS_SDK_URL_PARSER);
writer.write("parseUrl");
},
"utf8Decoder", writer -> {
writer.addDependency(TypeScriptDependency.AWS_SDK_UTIL_UTF8);
writer.addImport("fromUtf8", "fromUtf8",
TypeScriptDependency.AWS_SDK_UTIL_UTF8.packageName);
TypeScriptDependency.AWS_SDK_UTIL_UTF8);
writer.write("fromUtf8");
},
"utf8Encoder", writer -> {
writer.addDependency(TypeScriptDependency.AWS_SDK_UTIL_UTF8);
writer.addImport("toUtf8", "toUtf8",
TypeScriptDependency.AWS_SDK_UTIL_UTF8.packageName);
TypeScriptDependency.AWS_SDK_UTIL_UTF8);
writer.write("toUtf8");
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ private static void addCommonHandlerImports(TypeScriptWriter writer) {
writer.addImport("InternalFailureException", "__InternalFailureException", "@aws-smithy/server-common");
writer.addImport("SerializationException", "__SerializationException", "@aws-smithy/server-common");
writer.addImport("SmithyFrameworkException", "__SmithyFrameworkException", "@aws-smithy/server-common");
writer.addImport("HttpRequest", "__HttpRequest", TypeScriptDependency.PROTOCOL_HTTP.packageName);
writer.addImport("HttpResponse", "__HttpResponse", TypeScriptDependency.PROTOCOL_HTTP.packageName);
writer.addImport("HttpRequest", "__HttpRequest", TypeScriptDependency.PROTOCOL_HTTP);
writer.addImport("HttpResponse", "__HttpResponse", TypeScriptDependency.PROTOCOL_HTTP);
writer.addImport("ServiceException", "__ServiceException", "@aws-smithy/server-common");
writer.addImport("ValidationCustomizer", "__ValidationCustomizer", "@aws-smithy/server-common");
}
Expand Down Expand Up @@ -272,12 +272,12 @@ private static void writeHandleFunction(TypeScriptWriter writer) {

private static void writeSerdeContextBase(TypeScriptWriter writer) {
writer.addImport("ServerSerdeContext", "__ServerSerdeContext", "@aws-smithy/server-common");
writer.addImport("NodeHttpHandler", null, "@aws-sdk/node-http-handler");
writer.addImport("streamCollector", null, "@aws-sdk/node-http-handler");
writer.addImport("fromBase64", null, TypeScriptDependency.AWS_SDK_UTIL_BASE64.packageName);
writer.addImport("toBase64", null, TypeScriptDependency.AWS_SDK_UTIL_BASE64.packageName);
writer.addImport("fromUtf8", null, "@aws-sdk/util-utf8");
writer.addImport("toUtf8", null, "@aws-sdk/util-utf8");
writer.addImport("NodeHttpHandler", null, "@smithy/node-http-handler");
writer.addImport("streamCollector", null, "@smithy/node-http-handler");
writer.addImport("fromBase64", null, TypeScriptDependency.AWS_SDK_UTIL_BASE64);
writer.addImport("toBase64", null, TypeScriptDependency.AWS_SDK_UTIL_BASE64);
writer.addImport("fromUtf8", null, "@smithy/util-utf8");
writer.addImport("toUtf8", null, "@smithy/util-utf8");

writer.openBlock("const serdeContextBase = {", "};", () -> {
writer.write("base64Encoder: toBase64,");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public void run() {
aggregateClientName, serviceSymbol, aggregateClientName
);

writer.addImport("createAggregatedClient", null, "@aws-sdk/smithy-client");
writer.addImport("createAggregatedClient", null, "@smithy/smithy-client");
writer.write("createAggregatedClient(commands, $L);", aggregateClientName);
}
}
Loading