25
25
import java .util .ServiceLoader ;
26
26
import java .util .Set ;
27
27
import java .util .TreeSet ;
28
+ import java .util .UUID ;
28
29
import java .util .logging .Logger ;
30
+ import software .amazon .smithy .aws .traits .ServiceTrait ;
29
31
import software .amazon .smithy .build .FileManifest ;
30
32
import software .amazon .smithy .build .PluginContext ;
31
33
import software .amazon .smithy .codegen .core .Symbol ;
32
34
import software .amazon .smithy .codegen .core .SymbolDependency ;
33
35
import software .amazon .smithy .codegen .core .SymbolProvider ;
34
36
import software .amazon .smithy .codegen .core .TopologicalIndex ;
37
+ import software .amazon .smithy .codegen .core .trace .ArtifactDefinitions ;
38
+ import software .amazon .smithy .codegen .core .trace .TraceMetadata ;
39
+ import software .amazon .smithy .codegen .core .trace .TracingSymbolProvider ;
35
40
import software .amazon .smithy .model .Model ;
36
41
import software .amazon .smithy .model .knowledge .TopDownIndex ;
37
42
import software .amazon .smithy .model .neighbor .Walker ;
43
+ import software .amazon .smithy .model .node .Node ;
38
44
import software .amazon .smithy .model .shapes .OperationShape ;
39
45
import software .amazon .smithy .model .shapes .ServiceShape ;
40
46
import software .amazon .smithy .model .shapes .Shape ;
@@ -93,6 +99,7 @@ class CodegenVisitor extends ShapeVisitor.Default<Void> {
93
99
runtimePlugins .add (runtimePlugin );
94
100
});
95
101
});
102
+
96
103
// Sort the integrations in specified order.
97
104
integrations .sort (Comparator .comparingInt (TypeScriptIntegration ::getOrder ));
98
105
@@ -113,19 +120,55 @@ class CodegenVisitor extends ShapeVisitor.Default<Void> {
113
120
fileManifest = context .getFileManifest ();
114
121
LOGGER .info (() -> String .format ("Generating TypeScript %s for service %s" ,
115
122
settings .generateClient () ? "client" : "server" , service .getId ()));
123
+ // Resolve the nullable protocol generator and application protocol.
124
+ protocolGenerator = resolveProtocolGenerator (integrations , service , settings );
125
+ applicationProtocol = protocolGenerator == null
126
+ ? ApplicationProtocol .createDefaultHttpApplicationProtocol ()
127
+ : protocolGenerator .getApplicationProtocol ();
116
128
117
129
// Decorate the symbol provider using integrations.
118
130
SymbolProvider resolvedProvider = artifactType .createSymbolProvider (model , settings );
119
131
for (TypeScriptIntegration integration : integrations ) {
120
132
resolvedProvider = integration .decorateSymbolProvider (settings , model , resolvedProvider );
121
133
}
122
- symbolProvider = SymbolProvider .cache (resolvedProvider );
123
134
124
- // Resolve the nullable protocol generator and application protocol.
125
- protocolGenerator = resolveProtocolGenerator (integrations , service , settings );
126
- applicationProtocol = protocolGenerator == null
127
- ? ApplicationProtocol .createDefaultHttpApplicationProtocol ()
128
- : protocolGenerator .getApplicationProtocol ();
135
+ // Make the symbol provider a cachingSymbolProvider.
136
+ SymbolProvider cachedProvider = SymbolProvider .cache (resolvedProvider );
137
+ // Defining Definitions for TraceFile Generation.
138
+ ArtifactDefinitions artifactDefinitions = ArtifactDefinitions .builder ()
139
+ .addType (TypeScriptShapeLinkProvider .FIELD_TYPE ,
140
+ "Field declaration (includes enum constants)" )
141
+ .addType (TypeScriptShapeLinkProvider .METHOD_TYPE , "Method declaration" )
142
+ .addType (TypeScriptShapeLinkProvider .TYPE_TYPE ,
143
+ "Class, interface (including annotation type), or enum declaration" )
144
+ .addTag (TypeScriptShapeLinkProvider .SERVICE_TAG , "Service client" )
145
+ .addTag (TypeScriptShapeLinkProvider .REQUEST_TAG , "AWS SDK request type" )
146
+ .addTag (TypeScriptShapeLinkProvider .RESPONSE_TAG , "AWS SDK response type" )
147
+ .addTag (TypeScriptShapeLinkProvider .SERIALIZER_TAG , "Command serializer" )
148
+ .addTag (TypeScriptShapeLinkProvider .DESERIALIZER_TAG , "Command deserializer" )
149
+ .build ();
150
+
151
+ String serviceId ;
152
+ if (service .hasTrait (ServiceTrait .class )) {
153
+ serviceId = service .getTrait (ServiceTrait .class ).get ().getSdkId ();
154
+ } else {
155
+ serviceId = service .getId ().getName ();
156
+ }
157
+ TraceMetadata artifactMetadata = TraceMetadata .builder ()
158
+ .setTimestampAsNow ()
159
+ .id (serviceId )
160
+ .version (UUID .randomUUID ().toString ())
161
+ .type ("TypeScript" )
162
+ .build ();
163
+
164
+
165
+ // Decorate the symbol provider using the trace file generator.
166
+ symbolProvider = TracingSymbolProvider .builder ()
167
+ .symbolProvider (cachedProvider )
168
+ .metadata (artifactMetadata )
169
+ .artifactDefinitions (artifactDefinitions )
170
+ .shapeLinkCreator (new TypeScriptShapeLinkProvider ())
171
+ .build ();
129
172
130
173
writers = new TypeScriptDelegator (settings , model , fileManifest , symbolProvider , integrations );
131
174
}
@@ -212,6 +255,13 @@ void execute() {
212
255
settings , model , protocol , symbolProvider , writers , protocolGenerator ).run ();
213
256
}
214
257
258
+ // Write the TraceFile.
259
+ TracingSymbolProvider traceProvider = (TracingSymbolProvider ) symbolProvider ;
260
+ String traceName = symbolProvider .toSymbol (service ).getName ().replace ("Client" , "" )
261
+ .toLowerCase () + ".trace.json" ;
262
+ fileManifest .writeFile (traceName ,
263
+ Node .prettyPrintJson (traceProvider .buildTraceFile ().toNode ()));
264
+
215
265
// Write each pending writer.
216
266
LOGGER .fine ("Flushing TypeScript writers" );
217
267
List <SymbolDependency > dependencies = writers .getDependencies ();
@@ -372,6 +422,10 @@ private void generateClient(ServiceShape shape) {
372
422
boolean hasPaginatedOperation = false ;
373
423
374
424
for (OperationShape operation : containedOperations ) {
425
+ OperationShape finalOperation = operation ;
426
+ writers .useShapeWriter (operation , commandWriter -> new CommandGenerator (
427
+ settings , model , finalOperation , symbolProvider , commandWriter ,
428
+ runtimePlugins , protocolGenerator , applicationProtocol ).run ());
375
429
if (operation .hasTrait (PaginatedTrait .ID )) {
376
430
hasPaginatedOperation = true ;
377
431
String outputFilename = PaginationGenerator .getOutputFilelocation (operation );
@@ -428,7 +482,7 @@ private void generateCommands(ServiceShape shape) {
428
482
TopDownIndex topDownIndex = TopDownIndex .of (model );
429
483
Set <OperationShape > containedOperations = new TreeSet <>(topDownIndex .getContainedOperations (shape ));
430
484
for (OperationShape operation : containedOperations ) {
431
- // Right now this only generates stubs
485
+ // Right now this only generates stubs.
432
486
if (settings .generateClient ()) {
433
487
writers .useShapeWriter (operation , commandWriter -> new CommandGenerator (
434
488
settings , model , operation , symbolProvider , commandWriter ,
0 commit comments