Skip to content

Commit 1323d27

Browse files
AllanZhengYPsrchase
authored andcommitted
chore: add updated RDS DATA smithy model (#370)
* chore: add http request type guard for middlewares header default middleware expect continue middleare * chore: add http request type guard for apply body checksum middlewares * chore: only build and test demo smithy client * feat: add isInstance to httpResponse * chore: update rds data model * chore: update to ts3.7; update rds model#3 * chore: update tsconfig to genenerte types only once * chore: update gitignore * chore: parse body with streamCollector * chore: add error deserialization * chore: stub Field union * fix: fix middleware-header-default test * fix: fix retry-middleware unit test
1 parent 4bfb1da commit 1323d27

File tree

8 files changed

+63
-58
lines changed

8 files changed

+63
-58
lines changed

packages/fetch-http-handler/src/fetch-http-handler.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { FetchHttpHandler } from "./fetch-http-handler";
22
import { AbortController } from "@aws-sdk/abort-controller";
33
import * as timeouts from "./request-timeout";
4+
import { HttpRequest } from "@aws-sdk/protocol-http";
45

56
const mockRequest = jest.fn();
67
let mockResponse: any;
@@ -66,14 +67,14 @@ describe("httpHandler", () => {
6667

6768
(global as any).fetch = mockFetch;
6869

69-
let httpRequest = {
70+
let httpRequest = new HttpRequest({
7071
headers: {},
7172
hostname: "foo.amazonaws.com",
7273
method: "GET",
7374
path: "/test/?bar=baz",
7475
protocol: "https:",
7576
port: 443
76-
};
77+
});
7778
const fetchHttpHandler = new FetchHttpHandler();
7879

7980
let response = await fetchHttpHandler.handle(httpRequest, {});

packages/fetch-http-handler/src/fetch-http-handler.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
1-
import {
2-
HttpOptions,
3-
HeaderBag,
4-
HttpHandlerOptions,
5-
HttpRequest,
6-
HttpResponse
7-
} from "@aws-sdk/types";
8-
import { HttpHandler } from "@aws-sdk/protocol-http";
1+
import { HttpOptions, HeaderBag, HttpHandlerOptions } from "@aws-sdk/types";
2+
import { HttpHandler, HttpRequest, HttpResponse } from "@aws-sdk/protocol-http";
93
import { requestTimeout } from "./request-timeout";
104
import { buildQueryString } from "@aws-sdk/querystring-builder";
115

@@ -31,9 +25,9 @@ export class FetchHttpHandler implements HttpHandler {
3125
}
3226

3327
handle(
34-
request: HttpRequest<Blob>,
28+
request: HttpRequest,
3529
options: HttpHandlerOptions
36-
): Promise<{ response: HttpResponse<Blob> }> {
30+
): Promise<{ response: HttpResponse }> {
3731
const abortSignal = options && options.abortSignal;
3832
const requestTimeoutInMs = this.httpOptions.requestTimeout;
3933

@@ -78,12 +72,12 @@ export class FetchHttpHandler implements HttpHandler {
7872
transformedHeaders[pair[0]] = pair[1];
7973
}
8074

81-
return response.blob().then<{ response: HttpResponse<Blob> }>(body => ({
82-
response: {
75+
return response.blob().then<{ response: HttpResponse }>(body => ({
76+
response: new HttpResponse({
8377
headers: transformedHeaders,
8478
statusCode: response.status,
8579
body
86-
}
80+
})
8781
}));
8882
}),
8983
requestTimeout(requestTimeoutInMs)

packages/node-http-handler/src/node-http-handler.spec.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { AbortController } from "@aws-sdk/abort-controller";
2+
import { HttpRequest, HttpResponse } from "@aws-sdk/protocol-http";
23
import { Server as HttpServer } from "http";
34
import { Server as HttpsServer } from "https";
45
import * as https from "https";
@@ -8,7 +9,6 @@ import { ReadFromBuffers } from "./readable.mock";
89
import {
910
createMockHttpServer,
1011
createMockHttpsServer,
11-
createContinueResponseFunction,
1212
createResponseFunction
1313
} from "./server.mock";
1414
import { AddressInfo } from "net";
@@ -38,14 +38,14 @@ describe("NodeHttpHandler", () => {
3838
const nodeHttpHandler = new NodeHttpHandler();
3939

4040
let { response } = await nodeHttpHandler.handle(
41-
{
41+
new HttpRequest({
4242
hostname: "localhost",
4343
method: "GET",
4444
port: (mockHttpServer.address() as AddressInfo).port,
4545
protocol: "http:",
4646
path: "/",
4747
headers: {}
48-
},
48+
}),
4949
{}
5050
);
5151

@@ -247,14 +247,14 @@ describe("NodeHttpHandler", () => {
247247

248248
await expect(
249249
nodeHttpHandler.handle(
250-
{
250+
new HttpRequest({
251251
hostname: "localhost",
252252
method: "GET",
253253
port: (mockHttpsServer.address() as AddressInfo).port,
254254
protocol: "fake:", // trigger a request error
255255
path: "/",
256256
headers: {}
257-
},
257+
}),
258258
{}
259259
)
260260
).rejects.toHaveProperty("message");
@@ -281,14 +281,14 @@ describe("NodeHttpHandler", () => {
281281

282282
await expect(
283283
nodeHttpHandler.handle(
284-
{
284+
new HttpRequest({
285285
hostname: "localhost",
286286
method: "GET",
287287
port: (mockHttpsServer.address() as AddressInfo).port,
288288
protocol: "https:",
289289
path: "/",
290290
headers: {}
291-
},
291+
}),
292292
{
293293
abortSignal: {
294294
aborted: true
@@ -331,14 +331,14 @@ describe("NodeHttpHandler", () => {
331331

332332
await expect(
333333
nodeHttpHandler.handle(
334-
{
334+
new HttpRequest({
335335
hostname: "localhost",
336336
method: "GET",
337337
port: (mockHttpsServer.address() as AddressInfo).port,
338338
protocol: "https:",
339339
path: "/",
340340
headers: {}
341-
},
341+
}),
342342
{
343343
abortSignal: abortController.signal
344344
}

packages/node-http-handler/src/node-http-handler.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,8 @@ import * as https from "https";
22
import * as http from "http";
33
import { Readable } from "stream";
44
import { buildQueryString } from "@aws-sdk/querystring-builder";
5-
import {
6-
HeaderBag,
7-
HttpOptions,
8-
HttpRequest,
9-
HttpResponse,
10-
NodeHttpOptions
11-
} from "@aws-sdk/types";
12-
import { HttpHandler } from "@aws-sdk/protocol-http";
5+
import { HeaderBag, HttpOptions, NodeHttpOptions } from "@aws-sdk/types";
6+
import { HttpHandler, HttpRequest, HttpResponse } from "@aws-sdk/protocol-http";
137
import { setConnectionTimeout } from "./set-connection-timeout";
148
import { setSocketTimeout } from "./set-socket-timeout";
159
import { writeRequestBody } from "./write-request-body";
@@ -30,9 +24,9 @@ export class NodeHttpHandler implements HttpHandler {
3024
}
3125

3226
handle(
33-
request: HttpRequest<Readable>,
27+
request: HttpRequest,
3428
options: HttpOptions
35-
): Promise<{ response: HttpResponse<Readable> }> {
29+
): Promise<{ response: HttpResponse }> {
3630
// determine which http(s) client to use
3731
const isSSL = request.protocol === "https:";
3832
const httpClient = isSSL ? https : http;
@@ -78,11 +72,11 @@ export class NodeHttpHandler implements HttpHandler {
7872
: headerValues;
7973
}
8074

81-
const httpResponse: HttpResponse<Readable> = {
75+
const httpResponse = new HttpResponse({
8276
statusCode: res.statusCode || -1,
8377
headers: transformedHeaders,
8478
body: res
85-
};
79+
});
8680
resolve({ response: httpResponse });
8781
});
8882

packages/protocol-http/src/httpRequest.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class HttpRequest implements HttpMessage, HttpEndpoint {
1818
public query: QueryParameterBag;
1919
public headers: HeaderBag;
2020
public body?: any;
21-
public isHttpRequest = true;
21+
private readonly isHttpRequest = true;
2222

2323
constructor(options: HttpRequestOptions) {
2424
this.method = options.method || "GET";
@@ -40,7 +40,9 @@ export class HttpRequest implements HttpMessage, HttpEndpoint {
4040
}
4141

4242
static isInstance(request: unknown): request is HttpRequest {
43-
return (request as HttpRequest).isHttpRequest;
43+
return (
44+
request !== undefined && (request as HttpRequest).isHttpRequest === true
45+
);
4446
}
4547

4648
getFormatedUrl(): string {

packages/protocol-http/src/httpResponse.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,17 @@ export class HttpResponse {
1313
public statusCode: number;
1414
public headers: HeaderBag;
1515
public body?: any;
16+
private readonly isHttpResponse = true;
17+
1618
constructor(options: HttpResponseOptions) {
1719
this.statusCode = options.statusCode;
1820
this.headers = options.headers || {};
1921
this.body = options.body;
2022
}
23+
24+
static isInstance(request: unknown): request is HttpResponse {
25+
return (
26+
request !== undefined && (request as HttpResponse).isHttpResponse === true
27+
);
28+
}
2129
}

packages/types/src/client.ts

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { Command } from "./command";
99
import { MetadataBearer } from "./response";
1010
import { Credentials } from "./credentials";
1111
import { Hash, HashConstructor } from "./crypto";
12+
import { Middleware } from "./middleware";
1213

1314
export interface ConfigurationPropertyDefinition<
1415
InputType,
@@ -80,10 +81,7 @@ export type ConfigurationDefinition<
8081
* A general interface for service clients' configuration interface.
8182
* It is idempotent among browser or node clients
8283
*/
83-
export interface ClientResolvedConfigurationBase<
84-
OutputTypes extends object,
85-
StreamType
86-
> {
84+
export interface ClientResolvedConfigurationBase {
8785
credentials?: Provider<Credentials>;
8886
profile?: string;
8987
maxRedirects?: number;
@@ -98,7 +96,7 @@ export interface ClientResolvedConfigurationBase<
9896
utf8Decoder?: Decoder;
9997
utf8Incoder?: Encoder;
10098
// streamCollector?: StreamCollector<StreamType>;
101-
serializer?: Provider<RequestSerializer<StreamType>>;
99+
// serializer?: Provider<RequestSerializer<StreamType>>;
102100
// parser?: ResponseParser<StreamType>;
103101
_user_injected_http_handler?: boolean;
104102
httpHandler?: TransferHandler<any, any>;
@@ -111,16 +109,15 @@ export interface ClientResolvedConfigurationBase<
111109
*/
112110
interface InvokeFunction<
113111
InputTypes extends object,
114-
OutputTypes extends MetadataBearer,
115-
StreamType
112+
OutputTypes extends MetadataBearer
116113
> {
117114
<InputType extends InputTypes, OutputType extends OutputTypes>(
118115
command: Command<
119116
InputTypes,
120117
InputType,
121118
OutputTypes,
122119
OutputType,
123-
ClientResolvedConfigurationBase<OutputTypes, StreamType>
120+
ClientResolvedConfigurationBase
124121
>,
125122
options?: any
126123
): Promise<OutputType>;
@@ -130,7 +127,7 @@ interface InvokeFunction<
130127
InputType,
131128
OutputTypes,
132129
OutputType,
133-
ClientResolvedConfigurationBase<OutputTypes, StreamType>
130+
ClientResolvedConfigurationBase
134131
>,
135132
options: any,
136133
cb: (err: any, data?: OutputType) => void
@@ -141,7 +138,7 @@ interface InvokeFunction<
141138
InputType,
142139
OutputTypes,
143140
OutputType,
144-
ClientResolvedConfigurationBase<OutputTypes, StreamType>
141+
ClientResolvedConfigurationBase
145142
>,
146143
options?: any,
147144
cb?: (err: any, data?: OutputType) => void
@@ -151,12 +148,21 @@ interface InvokeFunction<
151148
/**
152149
* A general interface for service clients, idempotent to browser or node clients
153150
*/
154-
export interface AWSClient<
155-
InputTypes extends object,
156-
OutputTypes extends MetadataBearer,
157-
StreamType
158-
> {
159-
readonly config: ClientResolvedConfigurationBase<OutputTypes, StreamType>;
160-
middlewareStack: MiddlewareStack<InputTypes, OutputTypes>;
161-
send: InvokeFunction<InputTypes, OutputTypes, StreamType>;
151+
export interface AWSClient {
152+
readonly config: ClientResolvedConfigurationBase;
153+
middlewareStack: MiddlewareStack<any, any>;
154+
send: InvokeFunction<any, any>;
155+
}
156+
157+
export interface Injectable {
158+
injectTo: (client: AWSClient) => AWSClient;
159+
}
160+
161+
export interface ClientPlugin<
162+
ConfigType extends object,
163+
ResolvedConfig = Required<ConfigType>
164+
> extends Injectable {
165+
clientConfig: ConfigType;
166+
resolvedClientConfig: ResolvedConfig;
167+
middleware: Middleware<any, any>;
162168
}

packages/types/src/unmarshaller.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ import { ServiceException } from "./exception";
1515
// parse<OutputType>(shape: Member, input: SerializedType): OutputType;
1616
// }
1717

18-
export interface ResponseDeserializer<ResponseType> {
18+
export interface ResponseDeserializer<OutputType, ResponseType = any> {
1919
/**
2020
* Converts the output of an operation into JavaScript types.
2121
*
2222
* @param operation The operation model describing the structure of the HTTP
2323
* response received
2424
* @param input The HTTP response received from the service
2525
*/
26-
<OutputType>(output: ResponseType, protocolName: string): Promise<OutputType>;
26+
(output: ResponseType, protocolName: string): Promise<OutputType>;
2727
}
2828

2929
/**

0 commit comments

Comments
 (0)