Skip to content

Commit

Permalink
Add runtime config generation, refactor delegation
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mtdowling committed Nov 7, 2019
1 parent 2281f28 commit a5734d2
Show file tree
Hide file tree
Showing 16 changed files with 574 additions and 339 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,27 @@
public final class ApplicationProtocol {

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

private final String name;
private final SymbolReference optionsType;
private final SymbolReference requestType;
private final SymbolReference responseType;

/**
* Creates a resolved application protocol.
*
* @param name The protocol name (e.g., http, mqtt, etc).
* @param optionsType The type used to provide options to clients and commands.
* @param requestType The type used to represent request messages for the protocol.
* @param responseType The type used to represent response messages for the protocol.
*/
public ApplicationProtocol(
String name,
SymbolReference optionsType,
SymbolReference requestType,
SymbolReference responseType
) {
this.name = name;
this.optionsType = optionsType;
this.requestType = requestType;
this.responseType = responseType;
Expand All @@ -63,6 +66,7 @@ public ApplicationProtocol(
*/
public static ApplicationProtocol createDefaultHttpApplicationProtocol() {
return new ApplicationProtocol(
"http",
SymbolReference.builder()
.symbol(Symbol.builder()
.namespace("@aws-sdk/types", "/")
Expand Down Expand Up @@ -120,6 +124,36 @@ static ApplicationProtocol resolve(
return applicationProtocol;
}

/**
* Gets the protocol name.
*
* <p>All HTTP protocols should start with "http".
* All MQTT protocols should start with "mqtt".
*
* @return Returns the protocol name.
*/
public String getName() {
return name;
}

/**
* Checks if the protocol is an HTTP based protocol.
*
* @return Returns true if it is HTTP based.
*/
public boolean isHttpProtocol() {
return getName().startsWith("http");
}

/**
* Checks if the protocol is an MQTT based protocol.
*
* @return Returns true if it is MQTT based.
*/
public boolean isMqttProtocol() {
return getName().startsWith("mqtt");
}

/**
* Gets the symbol used to refer to options for this protocol.
*
Expand Down

This file was deleted.

Loading

0 comments on commit a5734d2

Please sign in to comment.