Skip to content

Commit 9efac3e

Browse files
AllanZhengYPtrivikr
authored andcommitted
fix: update updated types (#474)
* Use HttpRequest interface instread of class when implementation is not necessary * Make request serializer async just like response deserializer. This makes the serde symmetric
1 parent d41f500 commit 9efac3e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+448
-556
lines changed

Diff for: clients/client-rds-data/commands/ExecuteStatementCommand.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export class ExecuteStatementCommand extends Command<
5757
input: ExecuteStatementRequest,
5858
protocol: string,
5959
context: SerdeContext
60-
): HttpRequest {
60+
): Promise<HttpRequest> {
6161
switch (protocol) {
6262
case "aws.rest-json-1.1":
6363
return executeStatementAwsRestJson1_1Serialize(input, context);
@@ -66,7 +66,7 @@ export class ExecuteStatementCommand extends Command<
6666
}
6767
}
6868

69-
private async deserialize(
69+
private deserialize(
7070
output: HttpResponse,
7171
protocol: string,
7272
context: SerdeContext

Diff for: clients/client-rds-data/protocol/AwsRestJson1_1.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ import {
1313
import { HttpRequest, HttpResponse } from "@aws-sdk/protocol-http";
1414
import { SerdeContext, ResponseMetadata } from "@aws-sdk/types";
1515

16-
export function executeStatementAwsRestJson1_1Serialize(
16+
export async function executeStatementAwsRestJson1_1Serialize(
1717
input: ExecuteStatementRequest,
1818
context: SerdeContext
19-
): HttpRequest {
19+
): Promise<HttpRequest> {
2020
let body: any = {};
2121
if (input.resourceArn !== undefined) {
2222
body.resourceArn = input.resourceArn;

Diff for: packages/middleware-content-length/src/index.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import {
1010
} from "@aws-sdk/types";
1111
import { HttpRequest } from "@aws-sdk/protocol-http";
1212

13+
const CONTENT_LENGTH_HEADER = "content-length";
14+
1315
export function contentLengthMiddleware(
1416
bodyLengthChecker: BodyLengthCalculator
1517
): BuildMiddleware<any, any> {
@@ -18,21 +20,20 @@ export function contentLengthMiddleware(
1820
): BuildHandler<any, Output> => async (
1921
args: BuildHandlerArguments<any>
2022
): Promise<BuildHandlerOutput<Output>> => {
21-
let request = { ...args.request };
22-
//TODO: cast request with instanceof
23+
let request = args.request;
2324
if (HttpRequest.isInstance(request)) {
2425
const { body, headers } = request;
2526
if (
2627
body &&
2728
Object.keys(headers)
2829
.map(str => str.toLowerCase())
29-
.indexOf("content-length") === -1
30+
.indexOf(CONTENT_LENGTH_HEADER) === -1
3031
) {
3132
const length = bodyLengthChecker(body);
3233
if (length !== undefined) {
3334
request.headers = {
3435
...request.headers,
35-
"Content-Length": String(length)
36+
CONTENT_LENGTH_HEADER: String(length)
3637
};
3738
}
3839
}

Diff for: packages/middleware-serde/src/serializerMiddleware.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export function serializerMiddleware<
2828
...options,
2929
endpoint: await options.endpoint()
3030
};
31-
const request = serializer(
31+
const request = await serializer(
3232
args.input,
3333
options.protocol,
3434
endpointResolvedOptions

Diff for: packages/middleware-serde/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"compilerOptions": {
3-
"target": "es5",
3+
"target": "es2016",
44
"module": "commonjs",
55
"declaration": true,
66
"strict": true,

Diff for: packages/middleware-user-agent/src/middleware.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
import { HttpRequest } from "@aws-sdk/protocol-http";
1010
import { UserAgentResolvedConfig } from "./configurations";
1111

12-
const userAgentHeader = "User-Agent";
12+
const userAgentHeader = "user-agent";
1313

1414
export function userAgentMiddleware(options: UserAgentResolvedConfig) {
1515
return <Output extends MetadataBearer>(

Diff for: packages/node-http-handler/src/server.mock.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { HttpResponse } from "@aws-sdk/types";
1717

1818
const fixturesDir = join(__dirname, "..", "fixtures");
1919

20-
export function createResponseFunction(httpResp: HttpResponse<Readable>) {
20+
export function createResponseFunction(httpResp: HttpResponse) {
2121
return function(request: IncomingMessage, response: ServerResponse) {
2222
response.statusCode = httpResp.statusCode;
2323
for (let name of Object.keys(httpResp.headers)) {
@@ -32,9 +32,7 @@ export function createResponseFunction(httpResp: HttpResponse<Readable>) {
3232
};
3333
}
3434

35-
export function createContinueResponseFunction(
36-
httpResp: HttpResponse<Readable>
37-
) {
35+
export function createContinueResponseFunction(httpResp: HttpResponse) {
3836
return function(request: IncomingMessage, response: ServerResponse) {
3937
response.writeContinue();
4038
setTimeout(() => {

Diff for: packages/node-http-handler/src/write-request-body.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { HttpRequest } from "@aws-sdk/types";
55

66
export function writeRequestBody(
77
httpRequest: ClientRequest | ClientHttp2Stream,
8-
request: HttpRequest<Readable>
8+
request: HttpRequest
99
) {
1010
const expect = request.headers["Expect"] || request.headers["expect"];
1111
if (expect === "100-continue") {

Diff for: packages/node-http-handler/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"compilerOptions": {
3-
"target": "es5",
3+
"target": "es2017",
44
"module": "commonjs",
55
"declaration": true,
66
"strict": true,

Diff for: packages/protocol-http/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"license": "Apache-2.0",
1717
"dependencies": {
1818
"tslib": "^1.8.0",
19-
"@aws-sdk/types": "^0.1.0-preview.4",
19+
"@aws-sdk/types": "^0.1.0-preview.5",
2020
"@aws-sdk/util-uri-escape": "^0.1.0-preview.3"
2121
},
2222
"devDependencies": {

Diff for: packages/protocol-http/src/http.ts

-69
This file was deleted.

Diff for: packages/protocol-http/src/httpRequest.ts

+38-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
import { escapeUri } from "@aws-sdk/util-uri-escape";
22
import {
33
HttpMessage,
4-
HttpEndpoint,
4+
Endpoint,
55
QueryParameterBag,
6-
HeaderBag
7-
} from "./http";
6+
HeaderBag,
7+
HttpRequest as IHttpRequest
8+
} from "@aws-sdk/types";
89

910
type HttpRequestOptions = Partial<HttpMessage> &
10-
Partial<HttpEndpoint> & { method?: string };
11+
Partial<Endpoint> & { method?: string };
1112

12-
export class HttpRequest implements HttpMessage, HttpEndpoint {
13+
export interface HttpRequest extends IHttpRequest {}
14+
15+
export class HttpRequest implements HttpMessage, Endpoint {
1316
public method: string;
1417
public protocol: string;
1518
public hostname: string;
@@ -18,7 +21,6 @@ export class HttpRequest implements HttpMessage, HttpEndpoint {
1821
public query: QueryParameterBag;
1922
public headers: HeaderBag;
2023
public body?: any;
21-
private readonly isHttpRequest = true;
2224

2325
constructor(options: HttpRequestOptions) {
2426
this.method = options.method || "GET";
@@ -40,8 +42,15 @@ export class HttpRequest implements HttpMessage, HttpEndpoint {
4042
}
4143

4244
static isInstance(request: unknown): request is HttpRequest {
45+
//determine if request is a valid httpRequest
46+
const req: any = request;
4347
return (
44-
request !== undefined && (request as HttpRequest).isHttpRequest === true
48+
"method" in req &&
49+
"protocol" in req &&
50+
"hostname" in req &&
51+
"path" in req &&
52+
typeof req["query"] === "object" &&
53+
typeof req["headers"] === "object"
4554
);
4655
}
4756

@@ -57,6 +66,28 @@ export class HttpRequest implements HttpMessage, HttpEndpoint {
5766
return `${this.protocol}//${hostname}${this.path}${queryString}`;
5867
}
5968

69+
clone(): HttpRequest {
70+
const cloned = new HttpRequest({
71+
...this,
72+
headers: { ...this.headers }
73+
});
74+
if (cloned.query) cloned.query = this.cloneQuery(cloned.query);
75+
return cloned;
76+
}
77+
78+
private cloneQuery(query: QueryParameterBag): QueryParameterBag {
79+
return Object.keys(query).reduce(
80+
(carry: QueryParameterBag, paramName: string) => {
81+
const param = query[paramName];
82+
return {
83+
...carry,
84+
[paramName]: Array.isArray(param) ? [...param] : param
85+
};
86+
},
87+
{}
88+
);
89+
}
90+
6091
private buildQueryString(): string {
6192
const parts: string[] = [];
6293
for (let key of Object.keys(this.query || {}).sort()) {

Diff for: packages/protocol-http/src/httpResponse.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import {
22
HttpMessage,
3-
HttpEndpoint,
4-
QueryParameterBag,
5-
HeaderBag
6-
} from "./http";
3+
HeaderBag,
4+
HttpResponse as IHttpResponse
5+
} from "@aws-sdk/types";
76

87
type HttpResponseOptions = Partial<HttpMessage> & {
98
statusCode: number;
109
};
1110

11+
export interface HttpResponse extends IHttpResponse {}
12+
1213
export class HttpResponse {
1314
public statusCode: number;
1415
public headers: HeaderBag;

Diff for: packages/protocol-http/src/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
export * from "./httpResponse";
22
export * from "./httpRequest";
33
export * from "./httpHandler";
4-
export * from "./http";

Diff for: packages/protocol-http/tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"importHelpers": true,
1010
"noEmitHelpers": true,
1111
"lib": [
12+
"dom",
1213
"es5",
1314
"es2015.promise",
1415
"es2015.collection",

Diff for: packages/signature-v4/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
},
2727
"devDependencies": {
2828
"@aws-crypto/sha256-js": "^0.1.0-preview.1",
29-
"@aws-sdk/http-serialization": "^0.1.0-preview.7",
3029
"@aws-sdk/util-buffer-from": "^0.1.0-preview.3",
30+
"@aws-sdk/protocol-http": "^0.1.0-preview.1",
3131
"@types/jest": "^24.0.12",
3232
"jest": "^24.7.1",
3333
"typescript": "~3.4.0"

0 commit comments

Comments
 (0)