Skip to content

Commit 355af1d

Browse files
AllanZhengYPsrchase
authored andcommitted
feat: remove protocol rest json class (#438)
* feat: remove rest-json protocol class * feat: rename handler to RequestHandler; Consolidate types
1 parent 7235e25 commit 355af1d

File tree

13 files changed

+90
-207
lines changed

13 files changed

+90
-207
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { RequestHandler } from "@aws-sdk/types";
2+
3+
export function destroyRequestHandlerConfig(config: {
4+
requestHandler: RequestHandler<any, any, any>;
5+
}): void {
6+
if (config.requestHandler.destroy) config.requestHandler.destroy();
7+
}

packages/config-resolver/src/ProtocolConfig.ts

Lines changed: 0 additions & 29 deletions
This file was deleted.

packages/config-resolver/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export * from "./EndpointsConfig";
22
export * from "./RegionConfig";
3-
export * from "./ProtocolConfig";
3+
export * from "./HandlerConfig";

packages/middleware-serde/src/deserializerMiddleware.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,18 @@ import {
44
DeserializeHandler,
55
DeserializeHandlerArguments,
66
DeserializeHandlerOutput,
7-
Protocol
7+
RequestHandler
88
} from "@aws-sdk/types";
99

1010
export function deserializerMiddleware<
1111
Input extends object,
1212
Output extends object,
1313
RuntimeUtils = any
1414
>(
15-
options: { protocol: Protocol<any, any> } & RuntimeUtils,
15+
options: {
16+
requestHandler: RequestHandler<any, any, any>;
17+
protocol: string;
18+
} & RuntimeUtils,
1619
deserializer: ResponseDeserializer<any, any, RuntimeUtils>
1720
): DeserializeMiddleware<Input, Output> {
1821
return (
@@ -21,11 +24,7 @@ export function deserializerMiddleware<
2124
args: DeserializeHandlerArguments<Input>
2225
): Promise<DeserializeHandlerOutput<Output>> => {
2326
const { response } = await next(args);
24-
const parsed = await options.protocol.deserialize(
25-
deserializer,
26-
response,
27-
options
28-
);
27+
const parsed = await deserializer(response, options.protocol, options);
2928
return {
3029
response,
3130
output: parsed as Output

packages/middleware-serde/src/serdePlugin.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,25 @@ import {
22
RequestSerializer,
33
ResponseDeserializer,
44
Pluggable,
5-
Protocol,
65
MetadataBearer,
76
MiddlewareStack,
8-
EndpointBearer
7+
EndpointBearer,
8+
RequestHandler
99
} from "@aws-sdk/types";
1010
import { deserializerMiddleware } from "./deserializerMiddleware";
1111
import { serializerMiddleware } from "./serializerMiddleware";
1212

1313
export function getSerdePlugin<
1414
InputType extends object,
15-
SerializerRuntimeUtils extends EndpointBearer,
16-
OutputType extends MetadataBearer,
17-
DeserializerRuntimeUtils
15+
SerDeContext extends EndpointBearer,
16+
OutputType extends MetadataBearer
1817
>(
19-
config: SerializerRuntimeUtils &
20-
DeserializerRuntimeUtils & { protocol: Protocol<any, any> },
21-
serializer: RequestSerializer<any, SerializerRuntimeUtils>,
22-
deserializer: ResponseDeserializer<OutputType, any, DeserializerRuntimeUtils>
18+
config: SerDeContext & {
19+
protocol: string;
20+
requestHandler: RequestHandler<any, any, any>;
21+
},
22+
serializer: RequestSerializer<any, SerDeContext>,
23+
deserializer: ResponseDeserializer<OutputType, any, SerDeContext>
2324
): Pluggable<InputType, OutputType> {
2425
return {
2526
applyToStack: (commandStack: MiddlewareStack<InputType, OutputType>) => {

packages/middleware-serde/src/serializerMiddleware.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,19 @@ import {
44
SerializeHandlerArguments,
55
SerializeHandlerOutput,
66
SerializeMiddleware,
7-
Protocol,
8-
EndpointBearer
7+
EndpointBearer,
8+
RequestHandler
99
} from "@aws-sdk/types";
1010

1111
export function serializerMiddleware<
1212
Input extends object,
1313
Output extends object,
1414
RuntimeUtils extends EndpointBearer
1515
>(
16-
options: { protocol: Protocol<any, any> } & RuntimeUtils,
16+
options: {
17+
requestHandler: RequestHandler<any, any, any>;
18+
protocol: string;
19+
} & RuntimeUtils,
1720
serializer: RequestSerializer<any, RuntimeUtils>
1821
): SerializeMiddleware<Input, Output> {
1922
return (
@@ -25,9 +28,9 @@ export function serializerMiddleware<
2528
...options,
2629
endpoint: await options.endpoint()
2730
};
28-
const request = options.protocol.serialize(
29-
serializer,
31+
const request = serializer(
3032
args.input,
33+
options.protocol,
3134
endpointResolvedOptions
3235
);
3336
return next({

packages/protocol-http/src/httpHandler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { HttpRequest } from "./httpRequest";
22
import { HttpResponse } from "./httpResponse";
3-
import { TransferHandler, HttpOptions } from "@aws-sdk/types";
3+
import { RequestHandler, HttpOptions } from "@aws-sdk/types";
44

5-
export type HttpHandler = TransferHandler<
5+
export type HttpHandler = RequestHandler<
66
HttpRequest,
77
HttpResponse,
88
HttpOptions

packages/smithy-client/src/client.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,30 @@
11
import { MiddlewareStack } from "@aws-sdk/middleware-stack";
2-
import { Protocol, Command, MetadataBearer } from "@aws-sdk/types";
2+
import {
3+
RequestHandler,
4+
MetadataBearer,
5+
Command,
6+
Client as IClient
7+
} from "@aws-sdk/types";
38

49
export interface SmithyConfiguration<HandlerOptions> {
5-
protocol: Protocol<any, any, HandlerOptions>;
10+
requestHandler: RequestHandler<any, any, HandlerOptions>;
611
}
712

813
export type SmithyResolvedConfiguration<HandlerOptions> = SmithyConfiguration<
914
HandlerOptions
1015
>;
1116

1217
export class Client<
13-
HandlerOptions = any,
14-
ClientInput extends object = any,
15-
ClientOutput extends MetadataBearer = any
16-
> {
18+
HandlerOptions,
19+
ClientInput extends object,
20+
ClientOutput extends MetadataBearer,
21+
ResolvedClientConfiguration extends SmithyResolvedConfiguration<
22+
HandlerOptions
23+
>
24+
> implements IClient<ClientInput, ClientOutput, ResolvedClientConfiguration> {
1725
public middlewareStack = new MiddlewareStack<ClientInput, ClientOutput>();
18-
readonly config: SmithyResolvedConfiguration<HandlerOptions>;
19-
constructor(config: SmithyConfiguration<HandlerOptions>) {
26+
readonly config: ResolvedClientConfiguration;
27+
constructor(config: ResolvedClientConfiguration) {
2028
this.config = config;
2129
}
2230
send<InputType extends ClientInput, OutputType extends ClientOutput>(

packages/smithy-client/src/command.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
11
import { MiddlewareStack } from "@aws-sdk/middleware-stack";
2+
import { Command as ICommand, MetadataBearer, Handler } from "@aws-sdk/types";
23

3-
export class Command<InputType extends object, OutputType extends object> {
4-
readonly middlewareStack = new MiddlewareStack<InputType, OutputType>();
4+
export abstract class Command<
5+
ClientInput extends object,
6+
Input extends ClientInput,
7+
ClientOutput extends MetadataBearer,
8+
Output extends ClientOutput,
9+
ResolvedClientConfiguration
10+
>
11+
implements
12+
ICommand<
13+
ClientInput,
14+
Input,
15+
ClientOutput,
16+
Output,
17+
ResolvedClientConfiguration
18+
> {
19+
abstract input: Input;
20+
readonly middlewareStack = new MiddlewareStack<Input, Output>();
21+
abstract resolveMiddleware(
22+
stack: MiddlewareStack<ClientInput, ClientOutput>,
23+
configuration: ResolvedClientConfiguration,
24+
options: any
25+
): Handler<Input, Output>;
526
}

packages/types/src/client.ts

Lines changed: 13 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,22 @@
11
import { MiddlewareStack } from "./middleware";
2-
import { Provider, Decoder, Encoder, UrlParser } from "./util";
3-
import { Endpoint } from "./http";
4-
import { TransferHandler } from "./transfer";
52
import { Command } from "./command";
63
import { MetadataBearer } from "./response";
7-
import { Credentials } from "./credentials";
8-
import { Hash, HashConstructor } from "./crypto";
9-
10-
export interface ConfigurationPropertyDefinition<
11-
InputType,
12-
ResolvedType extends InputType,
13-
ServiceConfiguration extends { [key: string]: any },
14-
ResolvedConfiguration extends ServiceConfiguration
15-
> {
16-
/**
17-
* Whether this property must be supplied by the user of a client. If value
18-
* must be resolved but a default is available, this property should be
19-
* `false` or undefined.
20-
*/
21-
required?: boolean;
22-
23-
/**
24-
* A static value to use as the default should none be supplied.
25-
*/
26-
defaultValue?: ResolvedType;
27-
28-
/**
29-
* A function that returns a default value for this property. It will be
30-
* called if no value is supplied.
31-
*/
32-
defaultProvider?: {
33-
(config: ResolvedConfiguration): ResolvedType;
34-
};
35-
36-
/**
37-
* A function that normalizes input to the subtype expected by the SDK.
38-
*/
39-
normalize?: {
40-
(value: InputType, config: Partial<ResolvedConfiguration>): ResolvedType;
41-
};
42-
}
43-
44-
/**
45-
* A map of configuration property names to configuration property definitions.
46-
*
47-
* Order is significant in the definition provided, as the config object passed
48-
* to any `defaultProvider` and `apply` functions will only include properties
49-
* that have already been resolved.
50-
*/
51-
export type ConfigurationDefinition<
52-
Configuration extends { [key: string]: any },
53-
ResolvedConfiguration extends Configuration
54-
> = {
55-
readonly [P in keyof Configuration]: ConfigurationPropertyDefinition<
56-
Configuration[P],
57-
ResolvedConfiguration[P],
58-
Configuration,
59-
ResolvedConfiguration
60-
>;
61-
};
62-
63-
/**
64-
* A general interface for service clients' configuration interface.
65-
* It is idempotent among browser or node clients
66-
*/
67-
export interface ClientResolvedConfigurationBase {
68-
credentials?: Provider<Credentials>;
69-
profile?: string;
70-
maxRedirects?: number;
71-
maxRetries?: number;
72-
region?: Provider<string>;
73-
sslEnabled?: boolean;
74-
urlParser?: UrlParser;
75-
endpointProvider?: any;
76-
endpoint?: Provider<Endpoint>;
77-
base64Decoder?: Decoder;
78-
base64Encoder?: Encoder;
79-
utf8Decoder?: Decoder;
80-
utf8Incoder?: Encoder;
81-
_user_injected_http_handler?: boolean;
82-
httpHandler?: TransferHandler<any, any>;
83-
md5?: { new (): Hash };
84-
sha256?: HashConstructor;
85-
}
864

875
/**
886
* function definition for different overrides of client's 'send' function.
897
*/
908
interface InvokeFunction<
919
InputTypes extends object,
92-
OutputTypes extends MetadataBearer
10+
OutputTypes extends MetadataBearer,
11+
ResolvedClientConfiguration
9312
> {
9413
<InputType extends InputTypes, OutputType extends OutputTypes>(
9514
command: Command<
9615
InputTypes,
9716
InputType,
9817
OutputTypes,
9918
OutputType,
100-
ClientResolvedConfigurationBase
19+
ResolvedClientConfiguration
10120
>,
10221
options?: any
10322
): Promise<OutputType>;
@@ -107,7 +26,7 @@ interface InvokeFunction<
10726
InputType,
10827
OutputTypes,
10928
OutputType,
110-
ClientResolvedConfigurationBase
29+
ResolvedClientConfiguration
11130
>,
11231
options: any,
11332
cb: (err: any, data?: OutputType) => void
@@ -118,7 +37,7 @@ interface InvokeFunction<
11837
InputType,
11938
OutputTypes,
12039
OutputType,
121-
ClientResolvedConfigurationBase
40+
ResolvedClientConfiguration
12241
>,
12342
options?: any,
12443
cb?: (err: any, data?: OutputType) => void
@@ -128,8 +47,12 @@ interface InvokeFunction<
12847
/**
12948
* A general interface for service clients, idempotent to browser or node clients
13049
*/
131-
export interface AWSClient {
132-
// readonly config: ClientResolvedConfigurationBase;
133-
middlewareStack: MiddlewareStack<any, any>;
134-
send: InvokeFunction<any, any>;
50+
export interface Client<
51+
Input extends object,
52+
Output extends MetadataBearer,
53+
ResolvedClientConfiguration
54+
> {
55+
readonly config: ResolvedClientConfiguration;
56+
middlewareStack: MiddlewareStack<Input, Output>;
57+
send: InvokeFunction<Input, Output, ResolvedClientConfiguration>;
13558
}

0 commit comments

Comments
 (0)