Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update updated types #474

Merged
merged 1 commit into from
Nov 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions clients/client-rds-data/commands/ExecuteStatementCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class ExecuteStatementCommand extends Command<
input: ExecuteStatementRequest,
protocol: string,
context: SerdeContext
): HttpRequest {
): Promise<HttpRequest> {
switch (protocol) {
case "aws.rest-json-1.1":
return executeStatementAwsRestJson1_1Serialize(input, context);
Expand All @@ -66,7 +66,7 @@ export class ExecuteStatementCommand extends Command<
}
}

private async deserialize(
private deserialize(
output: HttpResponse,
protocol: string,
context: SerdeContext
Expand Down
4 changes: 2 additions & 2 deletions clients/client-rds-data/protocol/AwsRestJson1_1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import {
import { HttpRequest, HttpResponse } from "@aws-sdk/protocol-http";
import { SerdeContext, ResponseMetadata } from "@aws-sdk/types";

export function executeStatementAwsRestJson1_1Serialize(
export async function executeStatementAwsRestJson1_1Serialize(
input: ExecuteStatementRequest,
context: SerdeContext
): HttpRequest {
): Promise<HttpRequest> {
let body: any = {};
if (input.resourceArn !== undefined) {
body.resourceArn = input.resourceArn;
Expand Down
9 changes: 5 additions & 4 deletions packages/middleware-content-length/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
} from "@aws-sdk/types";
import { HttpRequest } from "@aws-sdk/protocol-http";

const CONTENT_LENGTH_HEADER = "content-length";

export function contentLengthMiddleware(
bodyLengthChecker: BodyLengthCalculator
): BuildMiddleware<any, any> {
Expand All @@ -18,21 +20,20 @@ export function contentLengthMiddleware(
): BuildHandler<any, Output> => async (
args: BuildHandlerArguments<any>
): Promise<BuildHandlerOutput<Output>> => {
let request = { ...args.request };
//TODO: cast request with instanceof
let request = args.request;
if (HttpRequest.isInstance(request)) {
const { body, headers } = request;
if (
body &&
Object.keys(headers)
.map(str => str.toLowerCase())
.indexOf("content-length") === -1
.indexOf(CONTENT_LENGTH_HEADER) === -1
) {
const length = bodyLengthChecker(body);
if (length !== undefined) {
request.headers = {
...request.headers,
"Content-Length": String(length)
CONTENT_LENGTH_HEADER: String(length)
};
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/middleware-serde/src/serializerMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function serializerMiddleware<
...options,
endpoint: await options.endpoint()
};
const request = serializer(
const request = await serializer(
args.input,
options.protocol,
endpointResolvedOptions
Expand Down
2 changes: 1 addition & 1 deletion packages/middleware-serde/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"target": "es5",
"target": "es2016",
"module": "commonjs",
"declaration": true,
"strict": true,
Expand Down
2 changes: 1 addition & 1 deletion packages/middleware-user-agent/src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import { HttpRequest } from "@aws-sdk/protocol-http";
import { UserAgentResolvedConfig } from "./configurations";

const userAgentHeader = "User-Agent";
const userAgentHeader = "user-agent";

export function userAgentMiddleware(options: UserAgentResolvedConfig) {
return <Output extends MetadataBearer>(
Expand Down
6 changes: 2 additions & 4 deletions packages/node-http-handler/src/server.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { HttpResponse } from "@aws-sdk/types";

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

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

export function createContinueResponseFunction(
httpResp: HttpResponse<Readable>
) {
export function createContinueResponseFunction(httpResp: HttpResponse) {
return function(request: IncomingMessage, response: ServerResponse) {
response.writeContinue();
setTimeout(() => {
Expand Down
2 changes: 1 addition & 1 deletion packages/node-http-handler/src/write-request-body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { HttpRequest } from "@aws-sdk/types";

export function writeRequestBody(
httpRequest: ClientRequest | ClientHttp2Stream,
request: HttpRequest<Readable>
request: HttpRequest
) {
const expect = request.headers["Expect"] || request.headers["expect"];
if (expect === "100-continue") {
Expand Down
2 changes: 1 addition & 1 deletion packages/node-http-handler/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"target": "es5",
"target": "es2017",
"module": "commonjs",
"declaration": true,
"strict": true,
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol-http/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"license": "Apache-2.0",
"dependencies": {
"tslib": "^1.8.0",
"@aws-sdk/types": "^0.1.0-preview.4",
"@aws-sdk/types": "^0.1.0-preview.5",
"@aws-sdk/util-uri-escape": "^0.1.0-preview.3"
},
"devDependencies": {
Expand Down
69 changes: 0 additions & 69 deletions packages/protocol-http/src/http.ts

This file was deleted.

45 changes: 38 additions & 7 deletions packages/protocol-http/src/httpRequest.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { escapeUri } from "@aws-sdk/util-uri-escape";
import {
HttpMessage,
HttpEndpoint,
Endpoint,
QueryParameterBag,
HeaderBag
} from "./http";
HeaderBag,
HttpRequest as IHttpRequest
} from "@aws-sdk/types";

type HttpRequestOptions = Partial<HttpMessage> &
Partial<HttpEndpoint> & { method?: string };
Partial<Endpoint> & { method?: string };

export class HttpRequest implements HttpMessage, HttpEndpoint {
export interface HttpRequest extends IHttpRequest {}

export class HttpRequest implements HttpMessage, Endpoint {
public method: string;
public protocol: string;
public hostname: string;
Expand All @@ -18,7 +21,6 @@ export class HttpRequest implements HttpMessage, HttpEndpoint {
public query: QueryParameterBag;
public headers: HeaderBag;
public body?: any;
private readonly isHttpRequest = true;

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

static isInstance(request: unknown): request is HttpRequest {
//determine if request is a valid httpRequest
const req: any = request;
return (
request !== undefined && (request as HttpRequest).isHttpRequest === true
"method" in req &&
"protocol" in req &&
"hostname" in req &&
"path" in req &&
typeof req["query"] === "object" &&
typeof req["headers"] === "object"
);
}

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

clone(): HttpRequest {
const cloned = new HttpRequest({
...this,
headers: { ...this.headers }
});
if (cloned.query) cloned.query = this.cloneQuery(cloned.query);
return cloned;
}

private cloneQuery(query: QueryParameterBag): QueryParameterBag {
return Object.keys(query).reduce(
(carry: QueryParameterBag, paramName: string) => {
const param = query[paramName];
return {
...carry,
[paramName]: Array.isArray(param) ? [...param] : param
};
},
{}
);
}

private buildQueryString(): string {
const parts: string[] = [];
for (let key of Object.keys(this.query || {}).sort()) {
Expand Down
9 changes: 5 additions & 4 deletions packages/protocol-http/src/httpResponse.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import {
HttpMessage,
HttpEndpoint,
QueryParameterBag,
HeaderBag
} from "./http";
HeaderBag,
HttpResponse as IHttpResponse
} from "@aws-sdk/types";

type HttpResponseOptions = Partial<HttpMessage> & {
statusCode: number;
};

export interface HttpResponse extends IHttpResponse {}

export class HttpResponse {
public statusCode: number;
public headers: HeaderBag;
Expand Down
1 change: 0 additions & 1 deletion packages/protocol-http/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from "./httpResponse";
export * from "./httpRequest";
export * from "./httpHandler";
export * from "./http";
1 change: 1 addition & 0 deletions packages/protocol-http/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"importHelpers": true,
"noEmitHelpers": true,
"lib": [
"dom",
"es5",
"es2015.promise",
"es2015.collection",
Expand Down
2 changes: 1 addition & 1 deletion packages/signature-v4/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
},
"devDependencies": {
"@aws-crypto/sha256-js": "^0.1.0-preview.1",
"@aws-sdk/http-serialization": "^0.1.0-preview.5",
"@aws-sdk/util-buffer-from": "^0.1.0-preview.3",
"@aws-sdk/protocol-http": "^0.1.0-preview.1",
"@types/jest": "^24.0.12",
"jest": "^24.7.1",
"typescript": "~3.4.0"
Expand Down
Loading