|
15 | 15 |
|
16 | 16 | package software.amazon.smithy.typescript.codegen.integration;
|
17 | 17 |
|
18 |
| -import static software.amazon.smithy.typescript.codegen.integration.RuntimeClientPlugin.Convention.HAS_CONFIG; |
19 |
| - |
20 | 18 | import java.util.List;
|
21 | 19 | import java.util.Set;
|
22 | 20 |
|
|
26 | 24 | import software.amazon.smithy.model.knowledge.TopDownIndex;
|
27 | 25 | import software.amazon.smithy.model.shapes.OperationShape;
|
28 | 26 | import software.amazon.smithy.model.shapes.ServiceShape;
|
| 27 | +import software.amazon.smithy.model.shapes.Shape; |
29 | 28 | import software.amazon.smithy.typescript.codegen.LanguageTarget;
|
30 | 29 | import software.amazon.smithy.typescript.codegen.TypeScriptDependency;
|
31 | 30 | import software.amazon.smithy.typescript.codegen.TypeScriptSettings;
|
|
37 | 36 | */
|
38 | 37 | public class EventStreamGenerator implements TypeScriptIntegration {
|
39 | 38 |
|
| 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 | + |
40 | 104 | @Override
|
41 | 105 | public List<RuntimeClientPlugin> getClientPlugins() {
|
42 | 106 | return ListUtils.of(
|
43 | 107 | RuntimeClientPlugin.builder()
|
44 | 108 | .withConventions(
|
45 | 109 | TypeScriptDependency.MIDDLEWARE_EVENT_STREAM.dependency,
|
46 | 110 | "EventStream",
|
47 |
| - HAS_CONFIG |
| 111 | + RuntimeClientPlugin.Convention.HAS_CONFIG |
48 | 112 | )
|
49 | 113 | .servicePredicate(EventStreamGenerator::hasEventStream)
|
50 | 114 | .build()
|
@@ -106,51 +170,4 @@ public void addRuntimeConfigValues(
|
106 | 170 | // do nothing
|
107 | 171 | }
|
108 | 172 | }
|
109 |
| - |
110 |
| - public static final boolean hasEventStream( |
111 |
| - Model model, |
112 |
| - ServiceShape service |
113 |
| - ) { |
114 |
| - TopDownIndex topDownIndex = model.getKnowledge(TopDownIndex.class); |
115 |
| - Set<OperationShape> operations = topDownIndex.getContainedOperations(service); |
116 |
| - for (OperationShape operation : operations) { |
117 |
| - if (operationHasEventStream(model, service, operation)) { |
118 |
| - return true; |
119 |
| - } |
120 |
| - } |
121 |
| - return false; |
122 |
| - } |
123 |
| - |
124 |
| - public static final boolean operationHasEventStream( |
125 |
| - Model model, |
126 |
| - ServiceShape service, |
127 |
| - OperationShape operation |
128 |
| - ) { |
129 |
| - if (operationHasEventStreamInput(model, operation) || operationHasEventStreamOutput(model, operation)) { |
130 |
| - return true; |
131 |
| - } |
132 |
| - return false; |
133 |
| - } |
134 |
| - |
135 |
| - public static final boolean operationHasEventStreamInput( |
136 |
| - Model model, |
137 |
| - OperationShape operation |
138 |
| - ) { |
139 |
| - EventStreamIndex eventStreamIndex = model.getKnowledge(EventStreamIndex.class); |
140 |
| - if (eventStreamIndex.getInputInfo(operation).isPresent()) { |
141 |
| - return true; |
142 |
| - } |
143 |
| - return false; |
144 |
| - } |
145 |
| - |
146 |
| - public static final boolean operationHasEventStreamOutput( |
147 |
| - Model model, |
148 |
| - OperationShape operation |
149 |
| - ) { |
150 |
| - EventStreamIndex eventStreamIndex = model.getKnowledge(EventStreamIndex.class); |
151 |
| - if (eventStreamIndex.getOutputInfo(operation).isPresent()) { |
152 |
| - return true; |
153 |
| - } |
154 |
| - return false; |
155 |
| - } |
156 | 173 | }
|
0 commit comments