Skip to content

Commit 811dd7c

Browse files
committed
formatting code and add necessary docs
1 parent 2254ee6 commit 811dd7c

File tree

5 files changed

+206
-188
lines changed

5 files changed

+206
-188
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ private CodegenUtils() {}
3232
public static String getOperationSerializerContextType(
3333
TypeScriptWriter writer, Model model, OperationShape operation) {
3434
// add default SerdeContext
35-
List<String> contextInterfaceList = new ArrayList<>();
36-
contextInterfaceList.add(getDefaultOperationSerdeContextTypes(writer));
35+
List<String> contextInterfaceList = getDefaultOperationSerdeContextTypes(writer);
3736
//check if event stream trait exists
3837
if (EventStreamGenerator.operationHasEventStreamInput(model, operation)
3938
) {
@@ -46,8 +45,7 @@ public static String getOperationSerializerContextType(
4645
public static String getOperationDeserializerContextType(
4746
TypeScriptWriter writer, Model model, OperationShape operation) {
4847
// add default SerdeContext
49-
List<String> contextInterfaceList = new ArrayList<>();
50-
contextInterfaceList.add(getDefaultOperationSerdeContextTypes(writer));
48+
List<String> contextInterfaceList = getDefaultOperationSerdeContextTypes(writer);
5149
//check if event stream trait exists
5250
if (EventStreamGenerator.operationHasEventStreamOutput(model, operation)
5351
) {
@@ -57,9 +55,11 @@ public static String getOperationDeserializerContextType(
5755
return String.join(" & ", contextInterfaceList);
5856
}
5957

60-
private static String getDefaultOperationSerdeContextTypes(TypeScriptWriter writer) {
58+
private static List<String> getDefaultOperationSerdeContextTypes(TypeScriptWriter writer) {
59+
List<String> contextInterfaceList = new ArrayList<>();
6160
// add default SerdeContext
6261
writer.addImport("SerdeContext", "__SerdeContext", "@aws-sdk/types");
63-
return "__SerdeContext";
62+
contextInterfaceList.add("__SerdeContext");
63+
return contextInterfaceList;
6464
}
6565
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.util.ArrayList;
1919
import java.util.Collections;
2020
import java.util.List;
21+
2122
import software.amazon.smithy.codegen.core.Symbol;
2223
import software.amazon.smithy.codegen.core.SymbolDependency;
2324
import software.amazon.smithy.codegen.core.SymbolDependencyContainer;
@@ -71,9 +72,9 @@ public enum TypeScriptDependency implements SymbolDependencyContainer {
7172
TYPES_BIG_JS("devDependencies", "@types/big.js", "^4.0.5", false),
7273

7374
// Conditionally added if a event stream shape is found anywhere in the model
74-
AWS_SDK_UTIL_EVENT_STREAM_NODE("dependencies", "@aws-sdk/util-eventstream-node", "^0.1.0-preview.1", false),
75-
// Conditionally added if a event stream shape found in model's input
76-
MIDDLEWARE_EVENT_STREAM("dependencies", "@aws-sdk/middleware-event-stream", "^0.1.0-preview.1", false);
75+
AWS_SDK_EVENTSTREAM_SERDE_CONFIG_RESOLVER("dependencies", "@aws-sdk/eventstream-serde-config-resolver",
76+
"^1.0.0-alpha.0", false),
77+
AWS_SDK_EVENTSTREAM_SERDE_NODE("dependencies", "@aws-sdk/eventstream-serde-node", "^1.0.0-alpha.0", false);
7778

7879
public static final String NORMAL_DEPENDENCY = "dependencies";
7980
public static final String DEV_DEPENDENCY = "devDependencies";

smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/EventStreamGenerator.java

Lines changed: 71 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -36,87 +36,17 @@
3636
*/
3737
public class EventStreamGenerator implements TypeScriptIntegration {
3838

39-
public static final boolean hasEventStream(
40-
Model model,
41-
ServiceShape service
42-
) {
43-
TopDownIndex topDownIndex = model.getKnowledge(TopDownIndex.class);
44-
Set<OperationShape> operations = topDownIndex.getContainedOperations(service);
45-
for (OperationShape operation : operations) {
46-
if (operationHasEventStream(model, service, operation)) {
47-
return true;
48-
}
49-
}
50-
return false;
51-
}
52-
53-
public static final boolean operationHasEventStream(
54-
Model model,
55-
ServiceShape service,
56-
OperationShape operation
57-
) {
58-
if (operationHasEventStreamInput(model, operation) || operationHasEventStreamOutput(model, operation)) {
59-
return true;
60-
}
61-
return false;
62-
}
63-
64-
public static final boolean operationHasEventStreamInput(
65-
Model model,
66-
OperationShape operation
67-
) {
68-
EventStreamIndex eventStreamIndex = model.getKnowledge(EventStreamIndex.class);
69-
if (eventStreamIndex.getInputInfo(operation).isPresent()) {
70-
return true;
71-
}
72-
return false;
73-
}
74-
75-
public static final boolean operationHasEventStreamOutput(
76-
Model model,
77-
OperationShape operation
78-
) {
79-
EventStreamIndex eventStreamIndex = model.getKnowledge(EventStreamIndex.class);
80-
if (eventStreamIndex.getOutputInfo(operation).isPresent()) {
81-
return true;
82-
}
83-
return false;
84-
}
85-
86-
public static String getEventHeaderType(Shape shape) {
87-
switch (shape.getType()) {
88-
case BOOLEAN:
89-
case BYTE:
90-
case SHORT:
91-
case INTEGER:
92-
case LONG:
93-
case STRING:
94-
case TIMESTAMP:
95-
return shape.getType().toString();
96-
case BLOB:
97-
return "binary";
98-
default:
99-
return "binary";
100-
}
101-
102-
}
103-
10439
@Override
10540
public List<RuntimeClientPlugin> getClientPlugins() {
10641
return ListUtils.of(
10742
RuntimeClientPlugin.builder()
10843
.withConventions(
109-
TypeScriptDependency.MIDDLEWARE_EVENT_STREAM.dependency,
44+
TypeScriptDependency.AWS_SDK_EVENTSTREAM_SERDE_CONFIG_RESOLVER.dependency,
11045
"EventStream",
11146
RuntimeClientPlugin.Convention.HAS_CONFIG
11247
)
11348
.servicePredicate(EventStreamGenerator::hasEventStream)
114-
.build(),
115-
RuntimeClientPlugin.builder()
116-
.withConventions(
117-
TypeScriptDependency.MIDDLEWARE_EVENT_STREAM.dependency,
118-
"EventStream"
119-
).operationPredicate((m, s, o) -> operationHasEventStreamInput(m, o)).build()
49+
.build()
12050
);
12151
}
12252

@@ -153,11 +83,11 @@ public void addRuntimeConfigValues(
15383

15484
switch (target) {
15585
case NODE:
156-
writer.addDependency(TypeScriptDependency.AWS_SDK_UTIL_EVENT_STREAM_NODE);
86+
writer.addDependency(TypeScriptDependency.AWS_SDK_EVENTSTREAM_SERDE_NODE);
15787
writer.addImport(
15888
"eventStreamSerdeProvider",
15989
"eventStreamSerdeProvider",
160-
TypeScriptDependency.AWS_SDK_UTIL_EVENT_STREAM_NODE.packageName
90+
TypeScriptDependency.AWS_SDK_EVENTSTREAM_SERDE_NODE.packageName
16191
);
16292
writer.write("eventStreamSerdeProvider");
16393
break;
@@ -175,4 +105,71 @@ public void addRuntimeConfigValues(
175105
// do nothing
176106
}
177107
}
108+
109+
public static final boolean hasEventStream(
110+
Model model,
111+
ServiceShape service
112+
) {
113+
TopDownIndex topDownIndex = model.getKnowledge(TopDownIndex.class);
114+
Set<OperationShape> operations = topDownIndex.getContainedOperations(service);
115+
for (OperationShape operation : operations) {
116+
if (operationHasEventStream(model, service, operation)) {
117+
return true;
118+
}
119+
}
120+
return false;
121+
}
122+
123+
public static final boolean operationHasEventStream(
124+
Model model,
125+
ServiceShape service,
126+
OperationShape operation
127+
) {
128+
if (operationHasEventStreamInput(model, operation) || operationHasEventStreamOutput(model, operation)) {
129+
return true;
130+
}
131+
return false;
132+
}
133+
134+
public static final boolean operationHasEventStreamInput(
135+
Model model,
136+
OperationShape operation
137+
) {
138+
EventStreamIndex eventStreamIndex = model.getKnowledge(EventStreamIndex.class);
139+
if (eventStreamIndex.getInputInfo(operation).isPresent()) {
140+
return true;
141+
}
142+
return false;
143+
}
144+
145+
public static final boolean operationHasEventStreamOutput(
146+
Model model,
147+
OperationShape operation
148+
) {
149+
EventStreamIndex eventStreamIndex = model.getKnowledge(EventStreamIndex.class);
150+
if (eventStreamIndex.getOutputInfo(operation).isPresent()) {
151+
return true;
152+
}
153+
return false;
154+
}
155+
156+
/**
157+
* The value of event header 'type' property of given shape.
158+
*/
159+
public static String getEventHeaderType(Shape shape) {
160+
switch (shape.getType()) {
161+
case BOOLEAN:
162+
case BYTE:
163+
case SHORT:
164+
case INTEGER:
165+
case LONG:
166+
case STRING:
167+
case TIMESTAMP:
168+
return shape.getType().toString();
169+
case BLOB:
170+
return "binary";
171+
default:
172+
return "binary";
173+
}
174+
}
178175
}

0 commit comments

Comments
 (0)