Skip to content

Commit 0675afe

Browse files
committed
refactor types to have any middleware
1 parent ccfd462 commit 0675afe

File tree

2 files changed

+25
-26
lines changed

2 files changed

+25
-26
lines changed

packages/core/src/shared/awsClientBuilderV3.ts

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
HandlerExecutionContext,
1616
HttpHandlerOptions,
1717
MetadataBearer,
18-
MiddlewareStack,
18+
//MiddlewareStack,
1919
Provider,
2020
RetryStrategy,
2121
UserAgent,
@@ -32,11 +32,11 @@ import { Client, SmithyResolvedConfiguration } from '@aws-sdk/smithy-client'
3232
export type AwsClient = Client<HttpHandlerOptions, any, MetadataBearer, SmithyResolvedConfiguration<HttpHandlerOptions>>
3333
export type AwsClientConstructor<C> = new (o: AwsClientOptions) => C
3434

35-
interface AwsClient2 {
36-
middlewareStack: AwsMiddlewareStack
35+
interface AwsClient2<Input extends object, Output extends MetadataBearer> {
36+
middlewareStack: AwsMiddlewareStack<Input, Output>
3737
}
3838

39-
type AwsMiddlewareStack = any
39+
type AwsMiddlewareStack<Input extends object, Output extends object> = any
4040
interface AwsConfigOptions {
4141
credentials: AwsCredentialIdentityProvider
4242
region: string | Provider<string>
@@ -48,17 +48,17 @@ interface AwsConfigOptions {
4848
}
4949
export type AwsClientOptions = AwsConfigOptions
5050

51-
export interface AWSClientBuilderV3 {
52-
createAwsService<C extends AwsClient2>(
53-
type: AwsClientConstructor<C>,
54-
options?: Partial<AwsClientOptions>,
55-
region?: string,
56-
userAgent?: boolean,
57-
settings?: DevSettings
58-
): Promise<C>
59-
}
60-
61-
export class DefaultAWSClientBuilderV3 implements AWSClientBuilderV3 {
51+
// export interface AWSClientBuilderV3 {
52+
// createAwsService<Input extends object, Output extends MetadataBearer, C extends AwsClient2<Input, Output>>(
53+
// type: AwsClientConstructor<C>,
54+
// options?: Partial<AwsClientOptions>,
55+
// region?: string,
56+
// userAgent?: boolean,
57+
// settings?: DevSettings
58+
// ): Promise<C>
59+
// }
60+
61+
export class DefaultAWSClientBuilderV3 {
6262
public constructor(private readonly context: AwsContext) {}
6363

6464
private getShim(): CredentialsShim {
@@ -69,7 +69,11 @@ export class DefaultAWSClientBuilderV3 implements AWSClientBuilderV3 {
6969
return shim
7070
}
7171

72-
public async createAwsService<C extends AwsClient2>(
72+
public async createAwsService<
73+
Input extends object,
74+
Output extends MetadataBearer,
75+
C extends AwsClient2<Input, Output>,
76+
>(
7377
type: AwsClientConstructor<C>,
7478
options?: Partial<AwsClientOptions>,
7579
region?: string,
@@ -102,7 +106,7 @@ export class DefaultAWSClientBuilderV3 implements AWSClientBuilderV3 {
102106

103107
const service = new type(opt)
104108
// TODO: add middleware for logging, telemetry, endpoints.
105-
service.middlewareStack.add(telemetryMiddleware, { step: 'deserialize' } as DeserializeHandlerOptions)
109+
service.middlewareStack.add!(telemetryMiddleware, { step: 'deserialize' } as DeserializeHandlerOptions)
106110
return service
107111
}
108112
}

packages/core/src/test/shared/defaultAwsClientBuilderV3.test.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,20 @@ import { getClientId } from '../../shared/telemetry/util'
99
import { FakeMemento } from '../fakeExtensionContext'
1010
import { FakeAwsContext } from '../utilities/fakeAwsContext'
1111
import { GlobalState } from '../../shared/globalState'
12-
import {
13-
AwsClient,
14-
AwsClientConstructor,
15-
DefaultAWSClientBuilderV3,
16-
getServiceId,
17-
recordErrorTelemetry,
18-
} from '../../shared/awsClientBuilderV3'
12+
import { DefaultAWSClientBuilderV3, getServiceId, recordErrorTelemetry } from '../../shared/awsClientBuilderV3'
1913
import { Client } from '@aws-sdk/smithy-client'
2014
import { extensionVersion } from '../../shared'
2115
import { assertTelemetry } from '../testUtil'
2216
import { telemetry } from '../../shared/telemetry'
23-
import { CloudFormationClient } from '@aws-sdk/client-cloudformation'
17+
//import { ActivateOrganizationsAccessCommand, CloudFormationClient } from '@aws-sdk/client-cloudformation'
2418

2519
describe('DefaultAwsClientBuilderV3', function () {
2620
let builder: DefaultAWSClientBuilderV3
2721

2822
beforeEach(async function () {
2923
builder = new DefaultAWSClientBuilderV3(new FakeAwsContext())
30-
const c = await builder.createAwsService(CloudFormationClient, undefined, 'us-east-1')
24+
//const c = await builder.createAwsService(CloudFormationClient, undefined, 'us-east-1')
25+
//await c.send(new ActivateOrganizationsAccessCommand({ dryRun: true }))
3126
})
3227

3328
describe('createAndConfigureSdkClient', function () {

0 commit comments

Comments
 (0)