Skip to content

Commit e99dc90

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 457dc91 commit e99dc90

File tree

8 files changed

+71
-61
lines changed

8 files changed

+71
-61
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/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
}

0 commit comments

Comments
 (0)