1
1
/*
2
- * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License").
5
- * You may not use this file except in compliance with the License.
6
- * A copy of the License is located at
7
- *
8
- * http://aws.amazon.com/apache2.0
9
- *
10
- * or in the "license" file accompanying this file. This file is distributed
11
- * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12
- * express or implied. See the License for the specific language governing
13
- * permissions and limitations under the License.
2
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
14
4
*/
15
5
16
6
package software .amazon .smithy .aws .typescript .codegen ;
17
7
18
8
import static software .amazon .smithy .aws .typescript .codegen .AwsTraitsUtils .isAwsService ;
19
- import static software .amazon .smithy .aws .typescript .codegen .AwsTraitsUtils .isEndpointsV2Service ;
20
9
import static software .amazon .smithy .aws .typescript .codegen .AwsTraitsUtils .isSigV4Service ;
21
10
import static software .amazon .smithy .typescript .codegen .integration .RuntimeClientPlugin .Convention .HAS_CONFIG ;
22
11
import static software .amazon .smithy .typescript .codegen .integration .RuntimeClientPlugin .Convention .HAS_MIDDLEWARE ;
23
12
24
13
import java .util .List ;
25
- import java .util .Set ;
26
- import software .amazon .smithy .aws .traits .ServiceTrait ;
27
- import software .amazon .smithy .model .Model ;
28
- import software .amazon .smithy .model .knowledge .OperationIndex ;
29
- import software .amazon .smithy .model .shapes .OperationShape ;
30
- import software .amazon .smithy .model .shapes .Shape ;
31
14
import software .amazon .smithy .typescript .codegen .TypeScriptDependency ;
32
15
import software .amazon .smithy .typescript .codegen .integration .RuntimeClientPlugin ;
33
16
import software .amazon .smithy .typescript .codegen .integration .TypeScriptIntegration ;
34
- import software .amazon .smithy .utils .ListUtils ;
35
- import software .amazon .smithy .utils .SetUtils ;
36
17
import software .amazon .smithy .utils .SmithyInternalApi ;
37
18
38
19
/**
39
20
* Adds all built-in runtime client plugins to clients.
21
+ *
22
+ * Note that order is significant because configurations might rely on previously resolved values.
40
23
*/
41
24
@ SmithyInternalApi
42
25
public class AddBuiltinPlugins implements TypeScriptIntegration {
43
- private static final Set <String > ROUTE_53_ID_MEMBERS = SetUtils .of ("DelegationSetId" , "HostedZoneId" , "Id" );
26
+ @ Override
27
+ public List <String > runAfter () {
28
+ return List .of (
29
+ software .amazon .smithy .typescript .codegen .integration .AddBuiltinPlugins .class .getCanonicalName ());
30
+ }
44
31
45
32
@ Override
46
33
public List <RuntimeClientPlugin > getClientPlugins () {
47
- // Note that order is significant because configurations might
48
- // rely on previously resolved values.
49
- return ListUtils .of (
34
+ return List .of (
35
+ // AWS or SigV4
50
36
RuntimeClientPlugin .builder ()
51
37
.withConventions (TypeScriptDependency .CONFIG_RESOLVER .dependency , "Region" , HAS_CONFIG )
52
38
.servicePredicate ((m , s ) -> isAwsService (s ) || isSigV4Service (s ))
53
39
.build (),
54
- // Only one of Endpoints or CustomEndpoints should be used
55
- RuntimeClientPlugin .builder ()
56
- .withConventions (
57
- TypeScriptDependency .CONFIG_RESOLVER .dependency , "Endpoints" , HAS_CONFIG )
58
- .servicePredicate ((m , s ) -> isAwsService (s ) && !isEndpointsV2Service (s ))
59
- .build (),
60
- RuntimeClientPlugin .builder ()
61
- .withConventions (
62
- TypeScriptDependency .CONFIG_RESOLVER .dependency , "CustomEndpoints" , HAS_CONFIG )
63
- .servicePredicate ((m , s ) -> !isAwsService (s ) && !isEndpointsV2Service (s ))
64
- .build (),
65
- RuntimeClientPlugin .builder ()
66
- .withConventions (
67
- TypeScriptDependency .MIDDLEWARE_ENDPOINTS_V2 .dependency , "Endpoint" , HAS_CONFIG )
68
- .servicePredicate ((m , s ) -> isAwsService (s ) && isEndpointsV2Service (s ))
69
- .build (),
70
- RuntimeClientPlugin .builder ()
71
- .withConventions (TypeScriptDependency .MIDDLEWARE_RETRY .dependency , "Retry" )
72
- .build (),
73
- RuntimeClientPlugin .builder ()
74
- .withConventions (TypeScriptDependency .MIDDLEWARE_CONTENT_LENGTH .dependency , "ContentLength" ,
75
- HAS_MIDDLEWARE )
76
- .build (),
77
- RuntimeClientPlugin .builder ()
78
- .withConventions (AwsDependency .ACCEPT_HEADER .dependency , "AcceptHeader" ,
79
- HAS_MIDDLEWARE )
80
- .servicePredicate ((m , s ) -> testServiceId (s , "API Gateway" ))
81
- .build (),
82
- RuntimeClientPlugin .builder ()
83
- .withConventions (AwsDependency .GLACIER_MIDDLEWARE .dependency ,
84
- "Glacier" , HAS_MIDDLEWARE )
85
- .servicePredicate ((m , s ) -> testServiceId (s , "Glacier" ))
86
- .build (),
87
- RuntimeClientPlugin .builder ()
88
- .withConventions (AwsDependency .EC2_MIDDLEWARE .dependency ,
89
- "CopySnapshotPresignedUrl" , HAS_MIDDLEWARE )
90
- .operationPredicate ((m , s , o ) -> o .getId ().getName (s ).equals ("CopySnapshot" )
91
- && testServiceId (s , "EC2" ))
92
- .build (),
93
- RuntimeClientPlugin .builder ()
94
- .withConventions (AwsDependency .MACHINELEARNING_MIDDLEWARE .dependency , "PredictEndpoint" ,
95
- HAS_MIDDLEWARE )
96
- .operationPredicate ((m , s , o ) -> o .getId ().getName (s ).equals ("Predict" )
97
- && testServiceId (s , "Machine Learning" ))
98
- .build (),
99
- RuntimeClientPlugin .builder ()
100
- .withConventions (AwsDependency .ROUTE53_MIDDLEWARE .dependency ,
101
- "ChangeResourceRecordSets" , HAS_MIDDLEWARE )
102
- .operationPredicate ((m , s , o ) -> o .getId ().getName (s ).equals ("ChangeResourceRecordSets" )
103
- && testServiceId (s , "Route 53" ))
104
- .build (),
105
- RuntimeClientPlugin .builder ()
106
- .withConventions (AwsDependency .ROUTE53_MIDDLEWARE .dependency , "IdNormalizer" ,
107
- HAS_MIDDLEWARE )
108
- .operationPredicate ((m , s , o ) -> testInputContainsMember (m , o , ROUTE_53_ID_MEMBERS )
109
- && testServiceId (s , "Route 53" ))
110
- .build (),
40
+ // Can be in smithy-typescript, but the NPM package is in @aws-sdk
111
41
RuntimeClientPlugin .builder ()
112
42
.withConventions (AwsDependency .MIDDLEWARE_HOST_HEADER .dependency , "HostHeader" )
113
43
.build (),
44
+ // Should be in smithy-typescript, but the NPM package is in @aws-sdk
114
45
RuntimeClientPlugin .builder ()
115
46
.withConventions (AwsDependency .MIDDLEWARE_LOGGER .dependency , "Logger" , HAS_MIDDLEWARE )
116
47
.build (),
@@ -120,19 +51,4 @@ && testServiceId(s, "Route 53"))
120
51
.build ()
121
52
);
122
53
}
123
-
124
- private static boolean testInputContainsMember (
125
- Model model ,
126
- OperationShape operationShape ,
127
- Set <String > expectedMemberNames
128
- ) {
129
- OperationIndex operationIndex = OperationIndex .of (model );
130
- return operationIndex .getInput (operationShape )
131
- .filter (input -> input .getMemberNames ().stream ().anyMatch (expectedMemberNames ::contains ))
132
- .isPresent ();
133
- }
134
-
135
- private static boolean testServiceId (Shape serviceShape , String expectedId ) {
136
- return serviceShape .getTrait (ServiceTrait .class ).map (ServiceTrait ::getSdkId ).orElse ("" ).equals (expectedId );
137
- }
138
54
}
0 commit comments