Skip to content

Commit 56fc147

Browse files
committed
chore(core): refactor accountId for submodules
1 parent 5c03ea1 commit 56fc147

File tree

9 files changed

+387
-108
lines changed

9 files changed

+387
-108
lines changed

codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AddAccountIdEndpointModeRuntimeConfig.java

Lines changed: 98 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -3,102 +3,102 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
package software.amazon.smithy.aws.typescript.codegen;
6+
package software.amazon.smithy.aws.typescript.codegen;
77

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+
}

packages/core/package.json

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"name": "@aws-sdk/core",
3-
"version": "3.556.0",
3+
"version": "3.582.0",
44
"description": "Core functions & classes shared by multiple AWS SDK clients",
55
"scripts": {
6-
"build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",
6+
"build": "yarn lint && concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",
77
"build:cjs": "node ../../scripts/compilation/inline core",
88
"build:es": "tsc -p tsconfig.es.json",
99
"build:include:deps": "lerna run --scope $npm_package_name --include-dependencies build",
@@ -18,22 +18,66 @@
1818
"main": "./dist-cjs/index.js",
1919
"module": "./dist-es/index.js",
2020
"types": "./dist-types/index.d.ts",
21+
"exports": {
22+
".": {
23+
"node": "./dist-cjs/index.js",
24+
"import": "./dist-es/index.js",
25+
"require": "./dist-cjs/index.js",
26+
"types": "./dist-types/index.d.ts"
27+
},
28+
"./package.json": {
29+
"node": "./package.json",
30+
"import": "./package.json",
31+
"require": "./package.json"
32+
},
33+
"./client": {
34+
"node": "./dist-cjs/submodules/client/index.js",
35+
"import": "./dist-es/submodules/client/index.js",
36+
"require": "./dist-cjs/submodules/client/index.js",
37+
"types": "./dist-types/submodules/client/index.d.ts"
38+
},
39+
"./httpAuthSchemes": {
40+
"node": "./dist-cjs/submodules/httpAuthSchemes/index.js",
41+
"import": "./dist-es/submodules/httpAuthSchemes/index.js",
42+
"require": "./dist-cjs/submodules/httpAuthSchemes/index.js",
43+
"types": "./dist-types/submodules/httpAuthSchemes/index.d.ts"
44+
},
45+
"./account-id-endpoint": {
46+
"node": "./dist-cjs/submodules/account-id-endpoint/index.js",
47+
"import": "./dist-es/submodules/account-id-endpoint/index.js",
48+
"require": "./dist-cjs/submodules/account-id-endpoint/index.js",
49+
"types": "./dist-types/submodules/account-id-endpoint/index.d.ts"
50+
},
51+
"./protocols": {
52+
"node": "./dist-cjs/submodules/protocols/index.js",
53+
"import": "./dist-es/submodules/protocols/index.js",
54+
"require": "./dist-cjs/submodules/protocols/index.js",
55+
"types": "./dist-types/submodules/protocols/index.d.ts"
56+
}
57+
},
58+
"files": [
59+
"dist-*/**",
60+
"./client.js",
61+
"./httpAuthSchemes.js",
62+
"./account-id-endpoint.js",
63+
"./protocols.js"
64+
],
2165
"sideEffects": false,
2266
"author": {
2367
"name": "AWS SDK for JavaScript Team",
2468
"url": "https://aws.amazon.com/javascript/"
2569
},
2670
"license": "Apache-2.0",
2771
"dependencies": {
28-
"@smithy/core": "^1.4.2",
29-
"@smithy/protocol-http": "^3.3.0",
30-
"@smithy/signature-v4": "^2.3.0",
31-
"@smithy/smithy-client": "^2.5.1",
32-
"@smithy/types": "^2.12.0",
72+
"@smithy/core": "^2.0.1",
73+
"@smithy/protocol-http": "^4.0.0",
74+
"@smithy/signature-v4": "^3.0.0",
75+
"@smithy/smithy-client": "^3.0.1",
76+
"@smithy/types": "^3.0.0",
3377
"fast-xml-parser": "4.2.5",
3478
"tslib": "^2.6.2",
35-
"@smithy/node-config-provider": "^2.3.0",
36-
"@smithy/util-middleware": "^2.2.0"
79+
"@smithy/node-config-provider": "^3.0.0",
80+
"@smithy/util-middleware": "^3.0.0"
3781
},
3882
"devDependencies": {
3983
"@tsconfig/recommended": "1.0.1",
@@ -43,7 +87,7 @@
4387
"typescript": "~4.9.5"
4488
},
4589
"engines": {
46-
"node": ">=14.0.0"
90+
"node": ">=16.0.0"
4791
},
4892
"typesVersions": {
4993
"<4.0": {
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { Provider } from "@smithy/types";
2+
import { normalizeProvider } from "@smithy/util-middleware";
3+
4+
import {
5+
AccountIdEndpointMode,
6+
DEFAULT_ACCOUNT_ID_ENDPOINT_MODE,
7+
validateAccountIdEndpointMode,
8+
} from "./AccountIdEndpointModeConstants";
9+
10+
/**
11+
* @public
12+
*/
13+
export interface AccountIdEndpointModeInputConfig {
14+
/**
15+
* The account ID endpoint mode to use.
16+
*/
17+
accountIdEndpointMode?: AccountIdEndpointMode | Provider<AccountIdEndpointMode>;
18+
}
19+
20+
/**
21+
* @internal
22+
*/
23+
interface PreviouslyResolved {}
24+
25+
/**
26+
* @internal
27+
*/
28+
export interface AccountIdEndpointModeResolvedConfig {
29+
/**
30+
* Resolved value for input config {config.accountIdEndpointMode}
31+
*/
32+
accountIdEndpointMode: Provider<AccountIdEndpointMode>;
33+
}
34+
35+
/**
36+
* @internal
37+
*/
38+
export const resolveAccountIdEndpointModeConfig = <T>(
39+
input: T & AccountIdEndpointModeInputConfig & PreviouslyResolved
40+
): T & AccountIdEndpointModeResolvedConfig => {
41+
return {
42+
...input,
43+
accountIdEndpointMode: async () => {
44+
const accountIdEndpointModeProvider = normalizeProvider(
45+
input.accountIdEndpointMode ?? DEFAULT_ACCOUNT_ID_ENDPOINT_MODE
46+
);
47+
const accIdMode = await accountIdEndpointModeProvider();
48+
if (!validateAccountIdEndpointMode(accIdMode)) {
49+
throw new Error(
50+
`Invalid value for accountIdEndpointMode: ${accIdMode}. Valid values are: "required", "preferred", "disabled".`
51+
);
52+
}
53+
return accIdMode;
54+
},
55+
};
56+
};
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { validateAccountIdEndpointMode } from "./AccountIdEndpointModeConstants";
2+
3+
describe("validateAccountIdEndpointMode", () => {
4+
it('should return true for "disabled"', () => {
5+
const result = validateAccountIdEndpointMode("disabled");
6+
expect(result).toBe(true);
7+
});
8+
9+
it('should return true for "preferred"', () => {
10+
const result = validateAccountIdEndpointMode("preferred");
11+
expect(result).toBe(true);
12+
});
13+
14+
it('should return true for "required"', () => {
15+
const result = validateAccountIdEndpointMode("required");
16+
expect(result).toBe(true);
17+
});
18+
19+
it("should return false for an invalid value", () => {
20+
const result = validateAccountIdEndpointMode("invalidValue");
21+
expect(result).toBe(false);
22+
});
23+
24+
it("should return false for an empty string", () => {
25+
const result = validateAccountIdEndpointMode("");
26+
expect(result).toBe(false);
27+
});
28+
29+
it("should return false for a number", () => {
30+
const result = validateAccountIdEndpointMode(123);
31+
expect(result).toBe(false);
32+
});
33+
34+
it("should return false for null", () => {
35+
const result = validateAccountIdEndpointMode(null);
36+
expect(result).toBe(false);
37+
});
38+
39+
it("should return false for undefined", () => {
40+
const result = validateAccountIdEndpointMode(undefined);
41+
expect(result).toBe(false);
42+
});
43+
});

0 commit comments

Comments
 (0)