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