Skip to content

Commit 4b69f3b

Browse files
committed
feat(codegen): support type import statements
# Conflicts: # smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/StructuredMemberWriter.java # smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/HttpBindingProtocolGenerator.java
1 parent 775cd5b commit 4b69f3b

File tree

166 files changed

+6283
-4877
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

166 files changed

+6283
-4877
lines changed

.changeset/famous-planes-vanish.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

Makefile

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ generate-protocol-tests:
1818
cp -r ./smithy-typescript-protocol-test-codegen/build/smithyprojections/smithy-typescript-protocol-test-codegen/my-local-model/typescript-client-codegen/ ./private/my-local-model
1919
cp -r ./smithy-typescript-protocol-test-codegen/build/smithyprojections/smithy-typescript-protocol-test-codegen/my-local-model-schema/typescript-client-codegen/ ./private/my-local-model-schema
2020
node ./scripts/post-protocol-test-codegen
21-
npx prettier --write ./private/smithy-rpcv2-cbor
22-
npx prettier --write ./private/smithy-rpcv2-cbor-schema
23-
npx prettier --write ./private/my-local-model
24-
npx prettier --write ./private/my-local-model-schema
2521
yarn
2622
yarn turbo run build -F="./private/*" --only
2723

private/my-local-model-schema/src/XYZService.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
// smithy-typescript generated code
2-
import { XYZServiceClient, XYZServiceClientConfig } from "./XYZServiceClient";
3-
import { GetNumbersCommand, GetNumbersCommandInput, GetNumbersCommandOutput } from "./commands/GetNumbersCommand";
2+
import { createAggregatedClient } from "@smithy/smithy-client";
3+
import type { HttpHandlerOptions as __HttpHandlerOptions } from "@smithy/types";
4+
5+
import {
6+
type GetNumbersCommandInput,
7+
type GetNumbersCommandOutput,
8+
GetNumbersCommand,
9+
} from "./commands/GetNumbersCommand";
410
import {
11+
type TradeEventStreamCommandInput,
12+
type TradeEventStreamCommandOutput,
513
TradeEventStreamCommand,
6-
TradeEventStreamCommandInput,
7-
TradeEventStreamCommandOutput,
814
} from "./commands/TradeEventStreamCommand";
9-
import { createAggregatedClient } from "@smithy/smithy-client";
10-
import { HttpHandlerOptions as __HttpHandlerOptions } from "@smithy/types";
15+
import { XYZServiceClient } from "./XYZServiceClient";
1116

1217
const commands = {
1318
GetNumbersCommand,
@@ -19,8 +24,14 @@ export interface XYZService {
1924
* @see {@link GetNumbersCommand}
2025
*/
2126
getNumbers(): Promise<GetNumbersCommandOutput>;
22-
getNumbers(args: GetNumbersCommandInput, options?: __HttpHandlerOptions): Promise<GetNumbersCommandOutput>;
23-
getNumbers(args: GetNumbersCommandInput, cb: (err: any, data?: GetNumbersCommandOutput) => void): void;
27+
getNumbers(
28+
args: GetNumbersCommandInput,
29+
options?: __HttpHandlerOptions
30+
): Promise<GetNumbersCommandOutput>;
31+
getNumbers(
32+
args: GetNumbersCommandInput,
33+
cb: (err: any, data?: GetNumbersCommandOutput) => void
34+
): void;
2435
getNumbers(
2536
args: GetNumbersCommandInput,
2637
options: __HttpHandlerOptions,

private/my-local-model-schema/src/XYZServiceClient.ts

Lines changed: 61 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,91 @@
11
// smithy-typescript generated code
2-
import {
3-
HttpAuthSchemeInputConfig,
4-
HttpAuthSchemeResolvedConfig,
5-
defaultXYZServiceHttpAuthSchemeParametersProvider,
6-
resolveHttpAuthSchemeConfig,
7-
} from "./auth/httpAuthSchemeProvider";
8-
import { GetNumbersCommandInput, GetNumbersCommandOutput } from "./commands/GetNumbersCommand";
9-
import { TradeEventStreamCommandInput, TradeEventStreamCommandOutput } from "./commands/TradeEventStreamCommand";
10-
import {
11-
ClientInputEndpointParameters,
12-
ClientResolvedEndpointParameters,
13-
EndpointParameters,
14-
resolveClientEndpointParameters,
15-
} from "./endpoint/EndpointParameters";
16-
import { getRuntimeConfig as __getRuntimeConfig } from "./runtimeConfig";
17-
import { RuntimeExtension, RuntimeExtensionsConfig, resolveRuntimeExtensions } from "./runtimeExtensions";
182
import {
193
DefaultIdentityProviderConfig,
204
getHttpAuthSchemeEndpointRuleSetPlugin,
215
getHttpSigningPlugin,
226
} from "@smithy/core";
237
import { getSchemaSerdePlugin } from "@smithy/core/schema";
248
import {
25-
EventStreamSerdeInputConfig,
26-
EventStreamSerdeResolvedConfig,
9+
type EventStreamSerdeInputConfig,
10+
type EventStreamSerdeResolvedConfig,
2711
resolveEventStreamSerdeConfig,
2812
} from "@smithy/eventstream-serde-config-resolver";
2913
import { getContentLengthPlugin } from "@smithy/middleware-content-length";
3014
import {
31-
EndpointInputConfig,
32-
EndpointRequiredInputConfig,
33-
EndpointRequiredResolvedConfig,
34-
EndpointResolvedConfig,
15+
type EndpointInputConfig,
16+
type EndpointRequiredInputConfig,
17+
type EndpointRequiredResolvedConfig,
18+
type EndpointResolvedConfig,
3519
resolveEndpointConfig,
3620
resolveEndpointRequiredConfig,
3721
} from "@smithy/middleware-endpoint";
38-
import { RetryInputConfig, RetryResolvedConfig, getRetryPlugin, resolveRetryConfig } from "@smithy/middleware-retry";
39-
import { HttpHandlerUserInput as __HttpHandlerUserInput } from "@smithy/protocol-http";
4022
import {
23+
type RetryInputConfig,
24+
type RetryResolvedConfig,
25+
getRetryPlugin,
26+
resolveRetryConfig,
27+
} from "@smithy/middleware-retry";
28+
import type { HttpHandlerUserInput as __HttpHandlerUserInput } from "@smithy/protocol-http";
29+
import {
30+
type DefaultsMode as __DefaultsMode,
31+
type SmithyConfiguration as __SmithyConfiguration,
32+
type SmithyResolvedConfiguration as __SmithyResolvedConfiguration,
4133
Client as __Client,
42-
DefaultsMode as __DefaultsMode,
43-
SmithyConfiguration as __SmithyConfiguration,
44-
SmithyResolvedConfiguration as __SmithyResolvedConfiguration,
4534
} from "@smithy/smithy-client";
46-
import {
47-
ClientProtocol,
48-
HttpRequest,
49-
HttpResponse,
35+
import type {
5036
BodyLengthCalculator as __BodyLengthCalculator,
5137
CheckOptionalClientConfig as __CheckOptionalClientConfig,
5238
ChecksumConstructor as __ChecksumConstructor,
39+
ClientProtocol,
5340
Decoder as __Decoder,
5441
Encoder as __Encoder,
5542
EventStreamSerdeProvider as __EventStreamSerdeProvider,
5643
HashConstructor as __HashConstructor,
5744
HttpHandlerOptions as __HttpHandlerOptions,
45+
HttpRequest,
46+
HttpResponse,
5847
Logger as __Logger,
5948
Provider as __Provider,
6049
StreamCollector as __StreamCollector,
6150
UrlParser as __UrlParser,
6251
} from "@smithy/types";
6352

53+
import {
54+
type HttpAuthSchemeInputConfig,
55+
type HttpAuthSchemeResolvedConfig,
56+
defaultXYZServiceHttpAuthSchemeParametersProvider,
57+
resolveHttpAuthSchemeConfig,
58+
} from "./auth/httpAuthSchemeProvider";
59+
import type { GetNumbersCommandInput, GetNumbersCommandOutput } from "./commands/GetNumbersCommand";
60+
import type { TradeEventStreamCommandInput, TradeEventStreamCommandOutput } from "./commands/TradeEventStreamCommand";
61+
import {
62+
type ClientInputEndpointParameters,
63+
type ClientResolvedEndpointParameters,
64+
type EndpointParameters,
65+
resolveClientEndpointParameters,
66+
} from "./endpoint/EndpointParameters";
67+
import { getRuntimeConfig as __getRuntimeConfig } from "./runtimeConfig";
68+
import {
69+
type RuntimeExtension,
70+
type RuntimeExtensionsConfig,
71+
resolveRuntimeExtensions,
72+
} from "./runtimeExtensions";
73+
6474
export { __Client };
6575

6676
/**
6777
* @public
6878
*/
69-
export type ServiceInputTypes = GetNumbersCommandInput | TradeEventStreamCommandInput;
79+
export type ServiceInputTypes =
80+
| GetNumbersCommandInput
81+
| TradeEventStreamCommandInput;
7082

7183
/**
7284
* @public
7385
*/
74-
export type ServiceOutputTypes = GetNumbersCommandOutput | TradeEventStreamCommandOutput;
86+
export type ServiceOutputTypes =
87+
| GetNumbersCommandOutput
88+
| TradeEventStreamCommandOutput;
7589

7690
/**
7791
* @public
@@ -184,8 +198,8 @@ export interface ClientDefaults extends Partial<__SmithyConfiguration<__HttpHand
184198
* The {@link @smithy/smithy-client#DefaultsMode} that will be used to determine how certain default configuration options are resolved in the SDK.
185199
*/
186200
defaultsMode?: __DefaultsMode | __Provider<__DefaultsMode>;
187-
}
188201

202+
}
189203
/**
190204
* @public
191205
*/
@@ -239,27 +253,26 @@ export class XYZServiceClient extends __Client<
239253
readonly config: XYZServiceClientResolvedConfig;
240254

241255
constructor(...[configuration]: __CheckOptionalClientConfig<XYZServiceClientConfig>) {
242-
let _config_0 = __getRuntimeConfig(configuration || {});
256+
const _config_0 = __getRuntimeConfig(configuration || {});
243257
super(_config_0 as any);
244258
this.initConfig = _config_0;
245-
let _config_1 = resolveClientEndpointParameters(_config_0);
246-
let _config_2 = resolveRetryConfig(_config_1);
247-
let _config_3 = resolveEndpointConfig(_config_2);
248-
let _config_4 = resolveEndpointRequiredConfig(_config_3);
249-
let _config_5 = resolveEventStreamSerdeConfig(_config_4);
250-
let _config_6 = resolveHttpAuthSchemeConfig(_config_5);
251-
let _config_7 = resolveRuntimeExtensions(_config_6, configuration?.extensions || []);
259+
const _config_1 = resolveClientEndpointParameters(_config_0);
260+
const _config_2 = resolveRetryConfig(_config_1);
261+
const _config_3 = resolveEndpointConfig(_config_2);
262+
const _config_4 = resolveEndpointRequiredConfig(_config_3);
263+
const _config_5 = resolveEventStreamSerdeConfig(_config_4);
264+
const _config_6 = resolveHttpAuthSchemeConfig(_config_5);
265+
const _config_7 = resolveRuntimeExtensions(_config_6, configuration?.extensions || []);
252266
this.config = _config_7;
253267
this.middlewareStack.use(getSchemaSerdePlugin(this.config));
254268
this.middlewareStack.use(getRetryPlugin(this.config));
255269
this.middlewareStack.use(getContentLengthPlugin(this.config));
256-
this.middlewareStack.use(
257-
getHttpAuthSchemeEndpointRuleSetPlugin(this.config, {
270+
this.middlewareStack.use(getHttpAuthSchemeEndpointRuleSetPlugin(this.config,
271+
{
258272
httpAuthSchemeParametersProvider: defaultXYZServiceHttpAuthSchemeParametersProvider,
259-
identityProviderConfigProvider: async (config: XYZServiceClientResolvedConfig) =>
260-
new DefaultIdentityProviderConfig({}),
261-
})
262-
);
273+
identityProviderConfigProvider: async (config: XYZServiceClientResolvedConfig) => new DefaultIdentityProviderConfig({}),
274+
}
275+
));
263276
this.middlewareStack.use(getHttpSigningPlugin(this.config));
264277
}
265278

private/my-local-model-schema/src/auth/httpAuthExtensionConfiguration.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// smithy-typescript generated code
2-
import { XYZServiceHttpAuthSchemeProvider } from "./httpAuthSchemeProvider";
3-
import { HttpAuthScheme } from "@smithy/types";
2+
import type { HttpAuthScheme } from "@smithy/types";
3+
4+
import type { XYZServiceHttpAuthSchemeProvider } from "./httpAuthSchemeProvider";
45

56
/**
67
* @internal
@@ -26,7 +27,7 @@ export type HttpAuthRuntimeConfig = Partial<{
2627
export const getHttpAuthExtensionConfiguration = (
2728
runtimeConfig: HttpAuthRuntimeConfig
2829
): HttpAuthExtensionConfiguration => {
29-
let _httpAuthSchemes = runtimeConfig.httpAuthSchemes!;
30+
const _httpAuthSchemes = runtimeConfig.httpAuthSchemes!;
3031
let _httpAuthSchemeProvider = runtimeConfig.httpAuthSchemeProvider!;
3132
return {
3233
setHttpAuthScheme(httpAuthScheme: HttpAuthScheme): void {

private/my-local-model-schema/src/auth/httpAuthSchemeProvider.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// smithy-typescript generated code
2-
import { XYZServiceClientResolvedConfig } from "../XYZServiceClient";
3-
import {
2+
import type {
43
HandlerExecutionContext,
54
HttpAuthOption,
65
HttpAuthScheme,
@@ -11,6 +10,8 @@ import {
1110
} from "@smithy/types";
1211
import { getSmithyContext, normalizeProvider } from "@smithy/util-middleware";
1312

13+
import type { XYZServiceClientResolvedConfig } from "../XYZServiceClient";
14+
1415
/**
1516
* @internal
1617
*/
@@ -49,7 +50,8 @@ function createSmithyApiNoAuthHttpAuthOption(authParameters: XYZServiceHttpAuthS
4950
/**
5051
* @internal
5152
*/
52-
export interface XYZServiceHttpAuthSchemeProvider extends HttpAuthSchemeProvider<XYZServiceHttpAuthSchemeParameters> {}
53+
export interface XYZServiceHttpAuthSchemeProvider
54+
extends HttpAuthSchemeProvider<XYZServiceHttpAuthSchemeParameters> {}
5355

5456
/**
5557
* @internal

private/my-local-model-schema/src/commands/GetNumbersCommand.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
// smithy-typescript generated code
2-
import { ServiceInputTypes, ServiceOutputTypes, XYZServiceClientResolvedConfig } from "../XYZServiceClient";
3-
import { commonParams } from "../endpoint/EndpointParameters";
4-
import { GetNumbersRequest, GetNumbersResponse } from "../models/models_0";
5-
import { GetNumbers } from "../schemas/schemas_0";
62
import { getEndpointPlugin } from "@smithy/middleware-endpoint";
73
import { Command as $Command } from "@smithy/smithy-client";
8-
import { MetadataBearer as __MetadataBearer } from "@smithy/types";
4+
import type { MetadataBearer as __MetadataBearer } from "@smithy/types";
5+
6+
import { commonParams } from "../endpoint/EndpointParameters";
7+
import type { GetNumbersRequest, GetNumbersResponse } from "../models/models_0";
8+
import { GetNumbers } from "../schemas/schemas_0";
9+
import type {
10+
ServiceInputTypes,
11+
ServiceOutputTypes,
12+
XYZServiceClientResolvedConfig,
13+
} from "../XYZServiceClient";
914

1015
/**
1116
* @public
@@ -82,7 +87,9 @@ export class GetNumbersCommand extends $Command
8287
>()
8388
.ep(commonParams)
8489
.m(function (this: any, Command: any, cs: any, config: XYZServiceClientResolvedConfig, o: any) {
85-
return [getEndpointPlugin(config, Command.getEndpointParameterInstructions())];
90+
return [
91+
getEndpointPlugin(config, Command.getEndpointParameterInstructions()),
92+
];
8693
})
8794
.s("XYZService", "GetNumbers", {})
8895
.n("XYZServiceClient", "GetNumbersCommand")

private/my-local-model-schema/src/commands/TradeEventStreamCommand.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
// smithy-typescript generated code
2-
import { ServiceInputTypes, ServiceOutputTypes, XYZServiceClientResolvedConfig } from "../XYZServiceClient";
3-
import { commonParams } from "../endpoint/EndpointParameters";
4-
import { TradeEventStreamRequest, TradeEventStreamResponse } from "../models/models_0";
5-
import { TradeEventStream } from "../schemas/schemas_0";
62
import { getEndpointPlugin } from "@smithy/middleware-endpoint";
73
import { Command as $Command } from "@smithy/smithy-client";
8-
import { MetadataBearer as __MetadataBearer } from "@smithy/types";
4+
import type { MetadataBearer as __MetadataBearer } from "@smithy/types";
5+
6+
import { commonParams } from "../endpoint/EndpointParameters";
7+
import type { TradeEventStreamRequest, TradeEventStreamResponse } from "../models/models_0";
8+
import { TradeEventStream } from "../schemas/schemas_0";
9+
import type {
10+
ServiceInputTypes,
11+
ServiceOutputTypes,
12+
XYZServiceClientResolvedConfig,
13+
} from "../XYZServiceClient";
914

1015
/**
1116
* @public
@@ -82,7 +87,9 @@ export class TradeEventStreamCommand extends $Command
8287
>()
8388
.ep(commonParams)
8489
.m(function (this: any, Command: any, cs: any, config: XYZServiceClientResolvedConfig, o: any) {
85-
return [getEndpointPlugin(config, Command.getEndpointParameterInstructions())];
90+
return [
91+
getEndpointPlugin(config, Command.getEndpointParameterInstructions()),
92+
];
8693
})
8794
.s("XYZService", "TradeEventStream", {
8895
/**

private/my-local-model-schema/src/endpoint/EndpointParameters.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
// smithy-typescript generated code
2-
import { Endpoint, EndpointV2, Provider, EndpointParameters as __EndpointParameters } from "@smithy/types";
2+
import type {
3+
Endpoint,
4+
EndpointParameters as __EndpointParameters,
5+
EndpointV2,
6+
Provider,
7+
} from "@smithy/types";
38

49
/**
510
* @public
@@ -8,10 +13,16 @@ export interface ClientInputEndpointParameters {
813
endpoint?: string | Provider<string> | Endpoint | Provider<Endpoint> | EndpointV2 | Provider<EndpointV2>;
914
}
1015

16+
/**
17+
* @internal
18+
*/
1119
export type ClientResolvedEndpointParameters = Omit<ClientInputEndpointParameters, "endpoint"> & {
1220
defaultSigningName: string;
1321
};
1422

23+
/**
24+
* @internal
25+
*/
1526
export const resolveClientEndpointParameters = <T>(
1627
options: T & ClientInputEndpointParameters
1728
): T & ClientResolvedEndpointParameters => {
@@ -20,6 +31,9 @@ export const resolveClientEndpointParameters = <T>(
2031
});
2132
};
2233

34+
/**
35+
* @internal
36+
*/
2337
export const commonParams = {
2438
endpoint: { type: "builtInParams", name: "endpoint" },
2539
} as const;

private/my-local-model-schema/src/endpoint/endpointResolver.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
// smithy-typescript generated code
2-
import { EndpointParameters } from "./EndpointParameters";
2+
import type { EndpointV2, Logger } from "@smithy/types";
3+
import {
4+
type EndpointParams,
5+
EndpointCache,
6+
resolveEndpoint,
7+
} from "@smithy/util-endpoints";
8+
9+
import type { EndpointParameters } from "./EndpointParameters";
310
import { ruleSet } from "./ruleset";
4-
import { EndpointV2, Logger } from "@smithy/types";
5-
import { EndpointCache, EndpointParams, resolveEndpoint } from "@smithy/util-endpoints";
611

712
const cache = new EndpointCache({
813
size: 50,

0 commit comments

Comments
 (0)