Skip to content

Commit 3be6cf9

Browse files
AllanZhengYPsrchase
authored andcommitted
chore: update rds data client (#496)
* feat: update ser-de interface to stop accepting protocol name * fix: update send() signature to support httpHandlerOptions better * feat: remove protocol from smithy client config * fix: remove protocol parameter from middleware serde * chore: update client rds data
1 parent f773a5c commit 3be6cf9

File tree

8 files changed

+102
-37
lines changed

8 files changed

+102
-37
lines changed

packages/middleware-serde/src/deserializerMiddleware.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,15 @@ import {
33
DeserializeMiddleware,
44
DeserializeHandler,
55
DeserializeHandlerArguments,
6-
DeserializeHandlerOutput,
7-
RequestHandler
6+
DeserializeHandlerOutput
87
} from "@aws-sdk/types";
98

109
export function deserializerMiddleware<
1110
Input extends object,
1211
Output extends object,
1312
RuntimeUtils = any
1413
>(
15-
options: {
16-
requestHandler: RequestHandler<any, any, any>;
17-
protocol: string;
18-
} & RuntimeUtils,
14+
options: RuntimeUtils,
1915
deserializer: ResponseDeserializer<any, any, RuntimeUtils>
2016
): DeserializeMiddleware<Input, Output> {
2117
return (
@@ -24,7 +20,7 @@ export function deserializerMiddleware<
2420
args: DeserializeHandlerArguments<Input>
2521
): Promise<DeserializeHandlerOutput<Output>> => {
2622
const { response } = await next(args);
27-
const parsed = await deserializer(response, options.protocol, options);
23+
const parsed = await deserializer(response, options);
2824
return {
2925
response,
3026
output: parsed as Output

packages/middleware-serde/src/serdePlugin.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@ export function getSerdePlugin<
2929
SerDeContext extends EndpointBearer,
3030
OutputType extends MetadataBearer
3131
>(
32-
config: SerDeContext & {
33-
protocol: string;
34-
requestHandler: RequestHandler<any, any, any>;
35-
},
32+
config: SerDeContext,
3633
serializer: RequestSerializer<any, SerDeContext>,
3734
deserializer: ResponseDeserializer<OutputType, any, SerDeContext>
3835
): Pluggable<InputType, OutputType> {

packages/middleware-serde/src/serializerMiddleware.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,15 @@ import {
44
SerializeHandlerArguments,
55
SerializeHandlerOutput,
66
SerializeMiddleware,
7-
EndpointBearer,
8-
RequestHandler
7+
EndpointBearer
98
} from "@aws-sdk/types";
109

1110
export function serializerMiddleware<
1211
Input extends object,
1312
Output extends object,
1413
RuntimeUtils extends EndpointBearer
1514
>(
16-
options: {
17-
requestHandler: RequestHandler<any, any, any>;
18-
protocol: string;
19-
} & RuntimeUtils,
15+
options: RuntimeUtils,
2016
serializer: RequestSerializer<any, RuntimeUtils>
2117
): SerializeMiddleware<Input, Output> {
2218
return (
@@ -28,11 +24,7 @@ export function serializerMiddleware<
2824
...options,
2925
endpoint: await options.endpoint()
3026
};
31-
const request = await serializer(
32-
args.input,
33-
options.protocol,
34-
endpointResolvedOptions
35-
);
27+
const request = await serializer(args.input, endpointResolvedOptions);
3628
return next({
3729
...args,
3830
request

packages/smithy-client/jest.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const base = require("../../jest.config.base.js");
2+
3+
module.exports = {
4+
...base
5+
};
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { Client } from "./client";
2+
3+
describe("SmithyClient", () => {
4+
const mockHandler = jest.fn((args: any) =>
5+
Promise.resolve({ output: "foo" })
6+
);
7+
const mockResolveMiddleware = jest.fn(args => mockHandler);
8+
const getCommandWithOutput = (output: string) => ({
9+
resolveMiddleware: mockResolveMiddleware
10+
});
11+
const client = new Client({} as any);
12+
13+
beforeEach(() => {
14+
jest.clearAllMocks();
15+
});
16+
17+
it("should return response promise when only command is supplied", async () => {
18+
expect.assertions(1);
19+
await expect(
20+
client.send(getCommandWithOutput("foo") as any)
21+
).resolves.toEqual("foo");
22+
});
23+
24+
it("should return response promise when command and options is supplied", async () => {
25+
expect.assertions(3);
26+
const options = {
27+
AbortSignal: "bar"
28+
};
29+
await expect(
30+
client.send(getCommandWithOutput("foo") as any, options)
31+
).resolves.toEqual("foo");
32+
expect(mockResolveMiddleware.mock.calls.length).toEqual(1);
33+
expect(mockResolveMiddleware.mock.calls[0][2 as any]).toEqual(options);
34+
});
35+
36+
it("should apply callback when command and callback is supplied", done => {
37+
const callback = jest.fn((err, response) => {
38+
expect(response).toEqual("foo");
39+
done();
40+
});
41+
client.send(getCommandWithOutput("foo") as any, callback);
42+
});
43+
44+
it("should apply callback when command, options and callback is supplied", done => {
45+
const callback = jest.fn((err, response) => {
46+
expect(response).toEqual("foo");
47+
expect(mockResolveMiddleware.mock.calls.length).toEqual(1);
48+
expect(mockResolveMiddleware.mock.calls[0][2 as any]).toEqual(options);
49+
done();
50+
});
51+
const options = {
52+
AbortSignal: "bar"
53+
};
54+
client.send(getCommandWithOutput("foo") as any, options, callback);
55+
});
56+
});

packages/smithy-client/src/client.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
export interface SmithyConfiguration<HandlerOptions> {
1010
requestHandler: RequestHandler<any, any, HandlerOptions>;
1111
readonly apiVersion: string;
12-
readonly protocol: string;
1312
}
1413

1514
export type SmithyResolvedConfiguration<HandlerOptions> = SmithyConfiguration<
@@ -39,6 +38,16 @@ export class Client<
3938
>,
4039
options?: HandlerOptions
4140
): Promise<OutputType>;
41+
send<InputType extends ClientInput, OutputType extends ClientOutput>(
42+
command: Command<
43+
ClientInput,
44+
InputType,
45+
ClientOutput,
46+
OutputType,
47+
SmithyResolvedConfiguration<HandlerOptions>
48+
>,
49+
cb: (err: any, data?: OutputType) => void
50+
): void;
4251
send<InputType extends ClientInput, OutputType extends ClientOutput>(
4352
command: Command<
4453
ClientInput,
@@ -58,17 +67,25 @@ export class Client<
5867
OutputType,
5968
SmithyResolvedConfiguration<HandlerOptions>
6069
>,
61-
options?: HandlerOptions,
70+
optionsOrCb?: HandlerOptions | ((err: any, data?: OutputType) => void),
6271
cb?: (err: any, data?: OutputType) => void
6372
): Promise<OutputType> | void {
73+
const options = typeof optionsOrCb !== "function" ? optionsOrCb : {};
74+
const callback =
75+
typeof optionsOrCb === "function"
76+
? (optionsOrCb as ((err: any, data?: OutputType) => void))
77+
: cb;
6478
const handler = command.resolveMiddleware(
6579
this.middlewareStack as any,
6680
this.config,
6781
options
6882
);
69-
if (cb) {
83+
if (callback) {
7084
handler(command)
71-
.then(result => cb(null, result.output), (err: any) => cb(err))
85+
.then(
86+
result => callback(null, result.output),
87+
(err: any) => callback(err)
88+
)
7289
.catch(
7390
// prevent any errors thrown in the callback from triggering an
7491
// unhandled promise rejection

packages/smithy-client/src/command.ts

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

49
export abstract class Command<
510
Input extends ClientInput,
@@ -17,7 +22,10 @@ export abstract class Command<
1722
ResolvedClientConfiguration
1823
> {
1924
abstract input: Input;
20-
readonly middlewareStack = new MiddlewareStack<Input, Output>();
25+
readonly middlewareStack: IMiddlewareStack<
26+
Input,
27+
Output
28+
> = new MiddlewareStack<Input, Output>();
2129
abstract resolveMiddleware(
2230
stack: MiddlewareStack<ClientInput, ClientOutput>,
2331
configuration: ResolvedClientConfiguration,

packages/types/src/serde.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,11 @@ export interface RequestSerializer<
3838
/**
3939
* Converts the provided `input` into a request object
4040
*
41-
* @param transferProtocol The protocol as the request to be serialized
42-
* to. Like `RestJson`, `RestXML`
4341
* @param input The user input to serialize.
4442
*
4543
* @param context Context containing runtime-specific util functions.
4644
*/
47-
(input: any, transferProtocol: string, context: Context): Promise<Request>;
45+
(input: any, context: Context): Promise<Request>;
4846
}
4947

5048
export interface ResponseDeserializer<
@@ -55,13 +53,9 @@ export interface ResponseDeserializer<
5553
/**
5654
* Converts the output of an operation into JavaScript types.
5755
*
58-
* @param operation The operation model describing the structure of the HTTP
59-
* response received
60-
* @param input The HTTP response received from the service
56+
* @param output The HTTP response received from the service
6157
*
6258
* @param context context containing runtime-specific util functions.
6359
*/
64-
(output: ResponseType, protocolName: string, context: Context): Promise<
65-
OutputType
66-
>;
60+
(output: ResponseType, context: Context): Promise<OutputType>;
6761
}

0 commit comments

Comments
 (0)