20
20
import java .util .Objects ;
21
21
import java .util .Optional ;
22
22
import java .util .Set ;
23
+ import java .util .function .BiConsumer ;
23
24
import java .util .function .BiPredicate ;
25
+ import java .util .function .Consumer ;
26
+ import java .util .function .UnaryOperator ;
27
+
24
28
import software .amazon .smithy .codegen .core .Symbol ;
25
29
import software .amazon .smithy .codegen .core .SymbolDependency ;
26
30
import software .amazon .smithy .codegen .core .SymbolReference ;
29
33
import software .amazon .smithy .model .shapes .ServiceShape ;
30
34
import software .amazon .smithy .typescript .codegen .TypeScriptDependency ;
31
35
import software .amazon .smithy .typescript .codegen .TypeScriptSettings ;
36
+ import software .amazon .smithy .typescript .codegen .TypeScriptWriter ;
32
37
import software .amazon .smithy .utils .SmithyBuilder ;
33
38
import software .amazon .smithy .utils .SmithyUnstableApi ;
34
39
import software .amazon .smithy .utils .StringUtils ;
35
40
import software .amazon .smithy .utils .ToSmithyBuilder ;
41
+ import software .amazon .smithy .utils .TriConsumer ;
36
42
37
43
/**
38
44
* Represents a runtime plugin for a client that hooks into various aspects
@@ -56,6 +62,8 @@ public final class RuntimeClientPlugin implements ToSmithyBuilder<RuntimeClientP
56
62
private final BiPredicate <Model , ServiceShape > servicePredicate ;
57
63
private final OperationPredicate operationPredicate ;
58
64
private final SettingsPredicate settingsPredicate ;
65
+ private BiConsumer <TypeScriptWriter , BiConsumer <Model , ServiceShape >> clientWriterConsumer = (writer , consumer ) -> {};
66
+ private BiConsumer <TypeScriptWriter , TriConsumer <Model , ServiceShape , OperationShape >> operationWriterConsumer = (writer , consumer ) -> {};
59
67
60
68
private RuntimeClientPlugin (Builder builder ) {
61
69
inputConfig = builder .inputConfig ;
@@ -68,6 +76,8 @@ private RuntimeClientPlugin(Builder builder) {
68
76
operationPredicate = builder .operationPredicate ;
69
77
servicePredicate = builder .servicePredicate ;
70
78
settingsPredicate = builder .settingsPredicate ;
79
+ clientWriterConsumer = builder .clientWriterConsumer ;
80
+ operationWriterConsumer = builder .operationWriterConsumer ;
71
81
72
82
boolean allNull = (inputConfig == null ) && (resolvedConfig == null ) && (resolveFunction == null );
73
83
boolean allSet = (inputConfig != null ) && (resolvedConfig != null ) && (resolveFunction != null );
@@ -326,6 +336,18 @@ public boolean matchesSettings(Model model, ServiceShape service, TypeScriptSett
326
336
return settingsPredicate .test (model , service , settings );
327
337
}
328
338
339
+ /**
340
+ * @return the writer consumer for this RuntimeClientPlugin. May be used to add imports and dependencies
341
+ * used by this plugin.
342
+ */
343
+ public Consumer <TypeScriptWriter > getClientWriterConsumer () {
344
+ return this .clientWriterConsumer ;
345
+ }
346
+
347
+ public Consumer <TypeScriptWriter > getClientWriterConsumer () {
348
+ return this .operationWriterConsumer ;
349
+ }
350
+
329
351
public static Builder builder () {
330
352
return new Builder ();
331
353
}
@@ -398,6 +420,8 @@ public static final class Builder implements SmithyBuilder<RuntimeClientPlugin>
398
420
private BiPredicate <Model , ServiceShape > servicePredicate = (model , service ) -> true ;
399
421
private OperationPredicate operationPredicate = (model , service , operation ) -> false ;
400
422
private SettingsPredicate settingsPredicate = (model , service , settings ) -> true ;
423
+ private BiConsumer <TypeScriptWriter , BiConsumer <Model , ServiceShape >> clientWriterConsumer = (writer , consumer ) -> {};
424
+ private BiConsumer <TypeScriptWriter , TriConsumer <Model , ServiceShape , OperationShape >> operationWriterConsumer = (writer , consumer ) -> {};
401
425
402
426
@ Override
403
427
public RuntimeClientPlugin build () {
@@ -746,6 +770,28 @@ public Builder servicePredicate(BiPredicate<Model, ServiceShape> servicePredicat
746
770
return this ;
747
771
}
748
772
773
+ /**
774
+ * Enables access to the writer for adding imports/dependencies.
775
+ */
776
+ public Builder withClientWriter (
777
+ BiConsumer <TypeScriptWriter ,
778
+ BiConsumer <Model , ServiceShape >> clientWriterConsumer
779
+ ) {
780
+ this .clientWriterConsumer = clientWriterConsumer ;
781
+ return this ;
782
+ }
783
+
784
+ /**
785
+ * Enables access to the writer for adding imports/dependencies.
786
+ */
787
+ public Builder withOperationWriter (
788
+ BiConsumer <TypeScriptWriter ,
789
+ TriConsumer <Model , ServiceShape , OperationShape >> operationWriterConsumer
790
+ ) {
791
+ this .operationWriterConsumer = operationWriterConsumer ;
792
+ return this ;
793
+ }
794
+
749
795
/**
750
796
* Configures various aspects of the builder based on naming conventions
751
797
* defined by the provided {@link Convention} values.
0 commit comments