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 (provided by Smithy-TypeScript) 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 .MIDDLEWARE_ENDPOINTS_V2 .dependency , "Endpoint" , HAS_CONFIG )
63
- .servicePredicate ((m , s ) -> isAwsService (s ) && isEndpointsV2Service (s ))
64
- .build (),
65
- RuntimeClientPlugin .builder ()
66
- .withConventions (AwsDependency .ACCEPT_HEADER .dependency , "AcceptHeader" ,
67
- HAS_MIDDLEWARE )
68
- .servicePredicate ((m , s ) -> testServiceId (s , "API Gateway" ))
69
- .build (),
70
- RuntimeClientPlugin .builder ()
71
- .withConventions (AwsDependency .GLACIER_MIDDLEWARE .dependency ,
72
- "Glacier" , HAS_MIDDLEWARE )
73
- .servicePredicate ((m , s ) -> testServiceId (s , "Glacier" ))
74
- .build (),
75
- RuntimeClientPlugin .builder ()
76
- .withConventions (AwsDependency .EC2_MIDDLEWARE .dependency ,
77
- "CopySnapshotPresignedUrl" , HAS_MIDDLEWARE )
78
- .operationPredicate ((m , s , o ) -> o .getId ().getName (s ).equals ("CopySnapshot" )
79
- && testServiceId (s , "EC2" ))
80
- .build (),
81
- RuntimeClientPlugin .builder ()
82
- .withConventions (AwsDependency .MACHINELEARNING_MIDDLEWARE .dependency , "PredictEndpoint" ,
83
- HAS_MIDDLEWARE )
84
- .operationPredicate ((m , s , o ) -> o .getId ().getName (s ).equals ("Predict" )
85
- && testServiceId (s , "Machine Learning" ))
86
- .build (),
87
- RuntimeClientPlugin .builder ()
88
- .withConventions (AwsDependency .ROUTE53_MIDDLEWARE .dependency ,
89
- "ChangeResourceRecordSets" , HAS_MIDDLEWARE )
90
- .operationPredicate ((m , s , o ) -> o .getId ().getName (s ).equals ("ChangeResourceRecordSets" )
91
- && testServiceId (s , "Route 53" ))
92
- .build (),
93
- RuntimeClientPlugin .builder ()
94
- .withConventions (AwsDependency .ROUTE53_MIDDLEWARE .dependency , "IdNormalizer" ,
95
- HAS_MIDDLEWARE )
96
- .operationPredicate ((m , s , o ) -> testInputContainsMember (m , o , ROUTE_53_ID_MEMBERS )
97
- && testServiceId (s , "Route 53" ))
98
- .build (),
40
+ // Can be in smithy-typescript, but the NPM package is in @aws-sdk
99
41
RuntimeClientPlugin .builder ()
100
42
.withConventions (AwsDependency .MIDDLEWARE_HOST_HEADER .dependency , "HostHeader" )
101
43
.build (),
44
+ // Should be in smithy-typescript, but the NPM package is in @aws-sdk
102
45
RuntimeClientPlugin .builder ()
103
46
.withConventions (AwsDependency .MIDDLEWARE_LOGGER .dependency , "Logger" , HAS_MIDDLEWARE )
104
47
.build (),
@@ -108,19 +51,4 @@ && testServiceId(s, "Route 53"))
108
51
.build ()
109
52
);
110
53
}
111
-
112
- private static boolean testInputContainsMember (
113
- Model model ,
114
- OperationShape operationShape ,
115
- Set <String > expectedMemberNames
116
- ) {
117
- OperationIndex operationIndex = OperationIndex .of (model );
118
- return operationIndex .getInput (operationShape )
119
- .filter (input -> input .getMemberNames ().stream ().anyMatch (expectedMemberNames ::contains ))
120
- .isPresent ();
121
- }
122
-
123
- private static boolean testServiceId (Shape serviceShape , String expectedId ) {
124
- return serviceShape .getTrait (ServiceTrait .class ).map (ServiceTrait ::getSdkId ).orElse ("" ).equals (expectedId );
125
- }
126
54
}
0 commit comments