3
3
* SPDX-License-Identifier: Apache-2.0
4
4
*/
5
5
6
- package software .amazon .smithy .aws .typescript .codegen ;
6
+ package software .amazon .smithy .aws .typescript .codegen ;
7
7
8
- import static software .amazon .smithy .aws .typescript .codegen .AwsTraitsUtils .isAwsService ;
9
-
10
- import java .util .Collections ;
11
- import java .util .HashMap ;
12
- import java .util .List ;
13
- import java .util .Map ;
14
- import java .util .function .Consumer ;
15
- import java .util .logging .Logger ;
16
- import software .amazon .smithy .aws .traits .ServiceTrait ;
17
- import software .amazon .smithy .codegen .core .SymbolProvider ;
18
- import software .amazon .smithy .model .Model ;
19
- import software .amazon .smithy .model .shapes .ServiceShape ;
20
- import software .amazon .smithy .rulesengine .traits .EndpointRuleSetTrait ;
21
- import software .amazon .smithy .typescript .codegen .endpointsV2 .RuleSetParameterFinder ;
22
- import software .amazon .smithy .typescript .codegen .LanguageTarget ;
23
- import software .amazon .smithy .typescript .codegen .TypeScriptDependency ;
24
- import software .amazon .smithy .typescript .codegen .TypeScriptSettings ;
25
- import software .amazon .smithy .typescript .codegen .TypeScriptWriter ;
26
- import software .amazon .smithy .typescript .codegen .integration .TypeScriptIntegration ;
27
- import software .amazon .smithy .utils .SmithyInternalApi ;
28
-
29
- /**
30
- * Generates accountIdEndpointMode configuration field for service clients that have the eponymous built-in param in the ruleset.
31
- */
32
- @ SmithyInternalApi
33
- public final class AddAccountIdEndpointModeRuntimeConfig implements TypeScriptIntegration {
34
-
35
- private static final Logger LOGGER = Logger .getLogger (AddAccountIdEndpointModeRuntimeConfig .class .getName ());
36
-
37
- @ Override
38
- public void addConfigInterfaceFields (
39
- TypeScriptSettings settings ,
40
- Model model ,
41
- SymbolProvider symbolProvider ,
42
- TypeScriptWriter writer
43
- ) {
44
- if (isAwsService (settings , model )) {
45
- ServiceShape service = settings .getService (model );
46
- EndpointRuleSetTrait endpointRuleSetTrait = service .getTrait (EndpointRuleSetTrait .class );
47
- if (endpointRuleSetTrait .isPresent ()) {
48
- RuleSetParameterFinder ruleSetParameterFinder = new RuleSetParameterFinder (service );
49
- if (ruleSetParameterFinder .getBuiltInParams ().containsKey ("AccountIdEndpointMode" )) {
50
- writer .addDependency (AwsDependency .AWS_SDK_CORE );
51
- writer .addImport ("AccountIdEndpointMode" , "AccountIdEndpointMode" , AwsDependency .AWS_SDK_CORE );
52
- writer .writeDocs ("Defines if the AWS AccountId will be used for endpoint routing." );
53
- writer .write ("accountIdEndpointMode?: AccountIdEndpointMode | __Provider<AccountIdEndpointMode>;\n " );
54
- }
55
- }
56
- }
57
- }
58
-
59
-
60
- @ Override
61
- public Map < String , Consumer < TypeScriptWriter >> getRuntimeConfigWriters (
62
- TypeScriptSettings settings ,
63
- Model model ,
64
- SymbolProvider symbolProvider ,
65
- LanguageTarget target
66
- ) {
67
- ServiceShape service = settings .getService (model );
68
- Map < String , Consumer < TypeScriptWriter >> runtimeConfigs = new HashMap <> ();
69
- if (isAwsService (settings , model )) {
70
- EndpointRuleSetTrait endpointRuleSetTrait = service .getTrait (EndpointRuleSetTrait .class );
71
- if (endpointRuleSetTrait .isPresent ()) {
72
- RuleSetParameterFinder ruleSetParameterFinder = new RuleSetParameterFinder (service );
73
- if (ruleSetParameterFinder .getBuiltInParams ().containsKey ("AccountIdEndpointMode" )) {
74
- switch (target ) {
75
- case BROWSER :
76
- runtimeConfigs .put ("accountIdEndpointMode" , writer -> {
77
- writer .addDependency (AwsDependency .AWS_SDK_CORE );
78
- writer .addImport ("DEFAULT_ACCOUNT_ID_ENDPOINT_MODE" , "DEFAULT_ACCOUNT_ID_ENDPOINT_MODE" ,
79
- AwsDependency .AWS_SDK_CORE );
80
- writer .write ("(() => Promise.resolve(DEFAULT_ACCOUNT_ID_ENDPOINT_MODE))" );
81
- });
82
- break ;
83
- case NODE :
84
- runtimeConfigs .put ("accountIdEndpointMode" , writer -> {
85
- writer .addDependency (TypeScriptDependency .NODE_CONFIG_PROVIDER );
86
- writer .addImport ("loadConfig" , "loadNodeConfig" ,
87
- TypeScriptDependency .NODE_CONFIG_PROVIDER );
88
- writer .addDependency (TypeScriptDependency .CONFIG_RESOLVER );
89
- writer .addImport ("NODE_ACCOUNT_ID_ENDPOINT_MODE_CONFIG_OPTIONS" , "NODE_ACCOUNT_ID_ENDPOINT_MODE_CONFIG_OPTIONS" ,
90
- AwsDependency .AWS_SDK_CORE );
91
- writer .write (
92
- "loadNodeConfig(NODE_ACCOUNT_ID_ENDPOINT_MODE_CONFIG_OPTIONS" );
93
- });
94
- break ;
95
- default :
96
- LOGGER .warning ("AccountIdEndpointMode config not supported for target: " + target );
97
- break ;
98
- }
99
- }
100
- }
101
- }
102
- return runtimeConfigs ;
103
- }
104
- }
8
+ import static software .amazon .smithy .aws .typescript .codegen .AwsTraitsUtils .isAwsService ;
9
+
10
+ import java .util .Collections ;
11
+ import java .util .HashMap ;
12
+ import java .util .List ;
13
+ import java .util .Map ;
14
+ import java .util .function .Consumer ;
15
+ import java .util .logging .Logger ;
16
+ import software .amazon .smithy .aws .traits .ServiceTrait ;
17
+ import software .amazon .smithy .codegen .core .SymbolProvider ;
18
+ import software .amazon .smithy .model .Model ;
19
+ import software .amazon .smithy .model .shapes .ServiceShape ;
20
+ import software .amazon .smithy .rulesengine .traits .EndpointRuleSetTrait ;
21
+ import software .amazon .smithy .typescript .codegen .endpointsV2 .RuleSetParameterFinder ;
22
+ import software .amazon .smithy .typescript .codegen .LanguageTarget ;
23
+ import software .amazon .smithy .typescript .codegen .TypeScriptDependency ;
24
+ import software .amazon .smithy .typescript .codegen .TypeScriptSettings ;
25
+ import software .amazon .smithy .typescript .codegen .TypeScriptWriter ;
26
+ import software .amazon .smithy .typescript .codegen .integration .TypeScriptIntegration ;
27
+ import software .amazon .smithy .utils .SmithyInternalApi ;
28
+
29
+ /**
30
+ * Generates accountIdEndpointMode configuration field for service clients that have the eponymous built-in param in the ruleset.
31
+ */
32
+ @ SmithyInternalApi
33
+ public final class AddAccountIdEndpointModeRuntimeConfig implements TypeScriptIntegration {
34
+
35
+ private static final Logger LOGGER = Logger .getLogger (AddAccountIdEndpointModeRuntimeConfig .class .getName ());
36
+
37
+ @ Override
38
+ public void addConfigInterfaceFields (
39
+ TypeScriptSettings settings ,
40
+ Model model ,
41
+ SymbolProvider symbolProvider ,
42
+ TypeScriptWriter writer
43
+ ) {
44
+ if (isAwsService (settings , model )) {
45
+ ServiceShape service = settings .getService (model );
46
+ EndpointRuleSetTrait endpointRuleSetTrait = service .getTrait (EndpointRuleSetTrait .class );
47
+ if (endpointRuleSetTrait .isPresent ()) {
48
+ RuleSetParameterFinder ruleSetParameterFinder = new RuleSetParameterFinder (service );
49
+ if (ruleSetParameterFinder .getBuiltInParams ().containsKey ("AccountIdEndpointMode" )) {
50
+ writer .addDependency (AwsDependency .AWS_SDK_CORE );
51
+ writer .addImport ("AccountIdEndpointMode" , "AccountIdEndpointMode" , AwsDependency .AWS_SDK_CORE );
52
+ writer .writeDocs ("Defines if the AWS AccountId will be used for endpoint routing." );
53
+ writer .write ("accountIdEndpointMode?: AccountIdEndpointMode | __Provider<AccountIdEndpointMode>;\n " );
54
+ }
55
+ }
56
+ }
57
+ }
58
+
59
+
60
+ @ Override
61
+ public Map < String , Consumer < TypeScriptWriter >> getRuntimeConfigWriters (
62
+ TypeScriptSettings settings ,
63
+ Model model ,
64
+ SymbolProvider symbolProvider ,
65
+ LanguageTarget target
66
+ ) {
67
+ ServiceShape service = settings .getService (model );
68
+ Map < String , Consumer < TypeScriptWriter >> runtimeConfigs = new HashMap < > ();
69
+ if (isAwsService (settings , model )) {
70
+ EndpointRuleSetTrait endpointRuleSetTrait = service .getTrait (EndpointRuleSetTrait .class );
71
+ if (endpointRuleSetTrait .isPresent ()) {
72
+ RuleSetParameterFinder ruleSetParameterFinder = new RuleSetParameterFinder (service );
73
+ if (ruleSetParameterFinder .getBuiltInParams ().containsKey ("AccountIdEndpointMode" )) {
74
+ switch (target ) {
75
+ case BROWSER :
76
+ runtimeConfigs .put ("accountIdEndpointMode" , writer - > {
77
+ writer .addDependency (AwsDependency .AWS_SDK_CORE );
78
+ writer .addImport ("DEFAULT_ACCOUNT_ID_ENDPOINT_MODE" , "DEFAULT_ACCOUNT_ID_ENDPOINT_MODE" ,
79
+ AwsDependency .AWS_SDK_CORE );
80
+ writer .write ("(() => Promise.resolve(DEFAULT_ACCOUNT_ID_ENDPOINT_MODE))" );
81
+ });
82
+ break ;
83
+ case NODE :
84
+ runtimeConfigs .put ("accountIdEndpointMode" , writer - > {
85
+ writer .addDependency (TypeScriptDependency .NODE_CONFIG_PROVIDER );
86
+ writer .addImport ("loadConfig" , "loadNodeConfig" ,
87
+ TypeScriptDependency .NODE_CONFIG_PROVIDER );
88
+ writer .addDependency (TypeScriptDependency .CONFIG_RESOLVER );
89
+ writer .addImport ("NODE_ACCOUNT_ID_ENDPOINT_MODE_CONFIG_OPTIONS" , "NODE_ACCOUNT_ID_ENDPOINT_MODE_CONFIG_OPTIONS" ,
90
+ AwsDependency .AWS_SDK_CORE );
91
+ writer .write (
92
+ "loadNodeConfig(NODE_ACCOUNT_ID_ENDPOINT_MODE_CONFIG_OPTIONS" );
93
+ });
94
+ break ;
95
+ default :
96
+ LOGGER .warning ("AccountIdEndpointMode config not supported for target: " + target );
97
+ break ;
98
+ }
99
+ }
100
+ }
101
+ }
102
+ return runtimeConfigs ;
103
+ }
104
+ }
0 commit comments