Skip to content

Commit

Permalink
feat: enable ctor arg passthrough for requestHandler (Java codegen) (#…
Browse files Browse the repository at this point in the history
…1168)

* feat: enable ctor arg passthrough for requestHandler

* add checked access to config object

* make config value prefix supply-able from TypeScriptIntegration

* move default impl of config value prefix

* static config value prefix instructions

* unused import
  • Loading branch information
kuhe authored Feb 22, 2024
1 parent 7baf4b1 commit 3b37740
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .changeset/orange-beans-deliver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ final class RuntimeConfigGenerator {
writer.addDependency(TypeScriptDependency.AWS_SDK_NODE_HTTP_HANDLER);
writer.addImport("NodeHttpHandler", "RequestHandler",
TypeScriptDependency.AWS_SDK_NODE_HTTP_HANDLER);
writer.write("new RequestHandler(defaultConfigProvider)");
writer.write("RequestHandler.create(config?.requestHandler ?? defaultConfigProvider)");
},
"sha256", writer -> {
writer.addDependency(TypeScriptDependency.AWS_SDK_HASH_NODE);
Expand All @@ -81,7 +81,7 @@ final class RuntimeConfigGenerator {
writer.addDependency(TypeScriptDependency.AWS_SDK_FETCH_HTTP_HANDLER);
writer.addImport("FetchHttpHandler", "RequestHandler",
TypeScriptDependency.AWS_SDK_FETCH_HTTP_HANDLER);
writer.write("new RequestHandler(defaultConfigProvider)");
writer.write("RequestHandler.create(config?.requestHandler ?? defaultConfigProvider)");
},
"sha256", writer -> {
writer.addDependency(TypeScriptDependency.AWS_CRYPTO_SHA256_BROWSER);
Expand Down Expand Up @@ -145,6 +145,9 @@ final class RuntimeConfigGenerator {
writer.write("[]");
}
);
private final Map<String, String> runtimeConfigDefaultValuePrefixes = MapUtils.of(
"requestHandler", ""
);

RuntimeConfigGenerator(
TypeScriptSettings settings,
Expand Down Expand Up @@ -184,10 +187,13 @@ void generate(LanguageTarget target) {
writer.indent().onSection("customizations", original -> {
// Start with defaults, use a TreeMap for keeping entries sorted.
Map<String, Consumer<TypeScriptWriter>> configs =
new TreeMap<>(getDefaultRuntimeConfigs(target));
new TreeMap<>(getDefaultRuntimeConfigs(target));

// Add any integration supplied runtime config writers.
for (TypeScriptIntegration integration : integrations) {
configs.putAll(integration.getRuntimeConfigWriters(settings, model, symbolProvider, target));
configs.putAll(
integration.getRuntimeConfigWriters(settings, model, symbolProvider, target)
);
}
// feat(experimentalIdentityAndAuth): add config writers for httpAuthScheme and httpAuthSchemes
// Needs a separate integration point since not all the information is accessible in
Expand All @@ -197,11 +203,18 @@ void generate(LanguageTarget target) {
}
int indentation = target.equals(LanguageTarget.SHARED) ? 1 : 2;
configs.forEach((key, value) -> {
writer.indent(indentation).disableNewlines().openBlock("$1L: config?.$1L ?? ", ",\n", key,
() -> {
value.accept(writer);
});
writer.dedent(indentation);
String valuePrefix =
runtimeConfigDefaultValuePrefixes.getOrDefault(key, "config?.$1L ?? ");
writer
.indent(indentation)
.disableNewlines()
.openBlock(
"$1L: " + valuePrefix, ",\n", key,
() -> {
value.accept(writer);
}
)
.dedent(indentation);
});
});
writer.dedent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,13 @@ private void generateClientDefaults() {

writer.writeDocs("@public")
.openBlock("export interface ClientDefaults\n"
+ " extends Partial<__SmithyResolvedConfiguration<$T>> {", "}",
+ " extends Partial<__SmithyConfiguration<$T>> {", "}",
applicationProtocol.getOptionsType(), () -> {
writer.addImport("HttpHandler", "__HttpHandler", TypeScriptDependency.PROTOCOL_HTTP);
writer.writeDocs("The HTTP handler to use. Fetch in browser and Https in Nodejs.");
writer.write("requestHandler?: __HttpHandler;\n");
writer.addImport("HttpHandlerUserInput", "__HttpHandlerUserInput", TypeScriptDependency.PROTOCOL_HTTP);
writer.writeDocs(
"The HTTP handler to use or its constructor options. Fetch in browser and Https in Nodejs."
);
writer.write("requestHandler?: __HttpHandlerUserInput;\n");

writer.addImport("HashConstructor", "__HashConstructor", TypeScriptDependency.SMITHY_TYPES);
writer.addImport("ChecksumConstructor", "__ChecksumConstructor", TypeScriptDependency.SMITHY_TYPES);
Expand Down

0 comments on commit 3b37740

Please sign in to comment.