Skip to content

Commit a5734d2

Browse files
committed
Add runtime config generation, refactor delegation
This change adds support for generting client runtime configs and dependencies. It required that arbitrary TypeScript files could be written that aren't specific to a shape being generated, so TypeScriptIntegration and CodeWriterDelegator were refactored to support delegating and intercepting the creation of arbitrary files. The idea of a generic CodeWriterDelegator was scrapped in favor of just making a custom flyweight factory style delegator for TypeScript. This simplified how everything works, but it does mean that other language implementations will likely need similar but slightly different abstractions. This can potentially be revisited in the future if needed. TypeScriptIntegration was updated to allow the *creation* of a TypeScriptWriter to be intercepted separate from the *use* of a writer for the purpose of generating a shape. The creation hook can be used to add custom interceptors, license headers, etc. The use hook can be used to modify how a shape is generated, and the callback actually has the context as to which shape is being generated (and it handles de-registering any interceptors of mutations made to the writer once the callback has exited). Because the runtime config needs to know more information about the application protocol like if it's HTTP or not, I added methods that are meant to answer the basic question of if a protocol is HTTP based, MQTT based, etc. There's potential here for describing protocol characteristics in Smithy's core libraries, but that can be revisited later as we roll out more generators. The code for generating the filename of a Symbol we overly complicated for some reason. I simplified it by removing the pointless code and just appending ".ts" to the namespace of a Symbol. The TypeScriptWriter now gracefully handles formatting imports when there are imports explicitly written to the writer in addition to imports that are managed by the writer.
1 parent 2281f28 commit a5734d2

16 files changed

+574
-339
lines changed

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

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,27 @@
3333
public final class ApplicationProtocol {
3434

3535
private static final Logger LOGGER = Logger.getLogger(ApplicationProtocol.class.getName());
36-
private static final String HTTP_PROTOCOL_VERSION = "^0.1.0-preview.1";
3736

37+
private final String name;
3838
private final SymbolReference optionsType;
3939
private final SymbolReference requestType;
4040
private final SymbolReference responseType;
4141

4242
/**
4343
* Creates a resolved application protocol.
4444
*
45+
* @param name The protocol name (e.g., http, mqtt, etc).
4546
* @param optionsType The type used to provide options to clients and commands.
4647
* @param requestType The type used to represent request messages for the protocol.
4748
* @param responseType The type used to represent response messages for the protocol.
4849
*/
4950
public ApplicationProtocol(
51+
String name,
5052
SymbolReference optionsType,
5153
SymbolReference requestType,
5254
SymbolReference responseType
5355
) {
56+
this.name = name;
5457
this.optionsType = optionsType;
5558
this.requestType = requestType;
5659
this.responseType = responseType;
@@ -63,6 +66,7 @@ public ApplicationProtocol(
6366
*/
6467
public static ApplicationProtocol createDefaultHttpApplicationProtocol() {
6568
return new ApplicationProtocol(
69+
"http",
6670
SymbolReference.builder()
6771
.symbol(Symbol.builder()
6872
.namespace("@aws-sdk/types", "/")
@@ -120,6 +124,36 @@ static ApplicationProtocol resolve(
120124
return applicationProtocol;
121125
}
122126

127+
/**
128+
* Gets the protocol name.
129+
*
130+
* <p>All HTTP protocols should start with "http".
131+
* All MQTT protocols should start with "mqtt".
132+
*
133+
* @return Returns the protocol name.
134+
*/
135+
public String getName() {
136+
return name;
137+
}
138+
139+
/**
140+
* Checks if the protocol is an HTTP based protocol.
141+
*
142+
* @return Returns true if it is HTTP based.
143+
*/
144+
public boolean isHttpProtocol() {
145+
return getName().startsWith("http");
146+
}
147+
148+
/**
149+
* Checks if the protocol is an MQTT based protocol.
150+
*
151+
* @return Returns true if it is MQTT based.
152+
*/
153+
public boolean isMqttProtocol() {
154+
return getName().startsWith("mqtt");
155+
}
156+
123157
/**
124158
* Gets the symbol used to refer to options for this protocol.
125159
*

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

Lines changed: 0 additions & 158 deletions
This file was deleted.

0 commit comments

Comments
 (0)