Skip to content

Commit

Permalink
feat: apply protocol and middleware update
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanZhengYP authored and trivikr committed Jan 3, 2020
1 parent e29478b commit 0de0a22
Show file tree
Hide file tree
Showing 46 changed files with 855 additions and 979 deletions.
159 changes: 22 additions & 137 deletions clients/node/client-rds-data-node/RDSDataConfiguration.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,29 @@
import * as __aws_sdk_core_handler from "@aws-sdk/core-handler";
import * as __aws_sdk_credential_provider_node from "@aws-sdk/credential-provider-node";
import * as __aws_sdk_hash_node from "@aws-sdk/hash-node";
import * as __aws_sdk_json_builder from "@aws-sdk/json-builder";
import * as __aws_sdk_json_error_unmarshaller from "@aws-sdk/json-error-unmarshaller";
import * as __aws_sdk_json_parser from "@aws-sdk/json-parser";
import * as __aws_sdk_middleware_serializer from "@aws-sdk/middleware-serializer";
import * as __aws_sdk_node_http_handler from "@aws-sdk/node-http-handler";
import * as __aws_sdk_protocol_rest from "@aws-sdk/protocol-rest";
import * as __aws_sdk_region_provider from "@aws-sdk/region-provider";
import * as __aws_sdk_signature_v4 from "@aws-sdk/signature-v4";
import * as __aws_sdk_signing_middleware from "@aws-sdk/signing-middleware";
import * as __aws_sdk_stream_collector_node from "@aws-sdk/stream-collector-node";
import * as __aws_sdk_types from "@aws-sdk/types";
import * as __aws_sdk_url_parser_node from "@aws-sdk/url-parser-node";
import * as __aws_sdk_util_base64_node from "@aws-sdk/util-base64-node";
import * as __aws_sdk_util_body_length_node from "@aws-sdk/util-body-length-node";
import * as __aws_sdk_util_utf8_node from "@aws-sdk/util-utf8-node";
import * as _stream from "stream";
import { OutputTypesUnion } from "./types/OutputTypesUnion";
import { Protocol, TransferHandler } from "@aws-sdk/types";
import { HttpRequest, HttpResponse, HttpHandler } from "@aws-sdk/protocol-http";
import { RestJsonProtocol } from "@aws-sdk/protocol-rest-json";

export interface RDSDataConfiguration {
/**
* The function that will be used to convert a base64-encoded string to a byte array
*/
base64Decoder?: __aws_sdk_types.Decoder;

/**
* The function that will be used to convert binary data to a base64-encoded string
*/
base64Encoder?: __aws_sdk_types.Encoder;

/**
* The credentials used to sign requests.
*
* If no static credentials are supplied, the SDK will attempt to credentials from known environment variables, from shared configuration and credentials files, and from the EC2 Instance Metadata Service, in that order.
*/
credentials?:
| __aws_sdk_types.Credentials
| __aws_sdk_types.Provider<__aws_sdk_types.Credentials>;
| __aws_sdk_types.Credentials
| __aws_sdk_types.Provider<__aws_sdk_types.Credentials>;

/**
* A function that determines how long (in milliseconds) the SDK should wait before retrying a request
Expand All @@ -48,24 +34,19 @@ export interface RDSDataConfiguration {
* The fully qualified endpoint of the webservice. This is only required when using a custom endpoint (for example, when using a local version of S3).
*/
endpoint?:
| string
| __aws_sdk_types.HttpEndpoint
| __aws_sdk_types.Provider<__aws_sdk_types.HttpEndpoint>;
| string
| __aws_sdk_types.HttpEndpoint
| __aws_sdk_types.Provider<__aws_sdk_types.HttpEndpoint>;

/**
* The endpoint provider to call if no endpoint is provided
*/
endpointProvider?: any;

/**
* The handler to use as the core of the client's middleware stack
*/
handler?: __aws_sdk_types.Terminalware<any, _stream.Readable>;

/**
* The HTTP handler to use
*/
httpHandler?: __aws_sdk_types.HttpHandler<_stream.Readable>;
httpHandler?: HttpHandler;

/**
* Whether sockets should be kept open even when there are no outstanding requests so that future requests can forgo having to reestablish a TCP or TLS connection. Defaults to true.
Expand Down Expand Up @@ -117,25 +98,15 @@ export interface RDSDataConfiguration {
*/
sslEnabled?: boolean;

/**
* A function that converts a stream into an array of bytes.
*/
streamCollector?: __aws_sdk_types.StreamCollector<_stream.Readable>;

/**
* The function that will be used to convert strings into HTTP endpoints
*/
urlParser?: __aws_sdk_types.UrlParser;

/**
* The function that will be used to convert a UTF8-encoded string to a byte array
*/
utf8Decoder?: __aws_sdk_types.Decoder;

/**
* The function that will be used to convert binary data to a UTF-8 encoded string
*
*/
utf8Encoder?: __aws_sdk_types.Encoder;
protocol?: Protocol<any, any>;
}

export interface RDSDataResolvableConfiguration extends RDSDataConfiguration {
Expand All @@ -148,32 +119,12 @@ export interface RDSDataResolvableConfiguration extends RDSDataConfiguration {
* A function that can calculate the length of a request body.
*/
bodyLengthChecker: (body: any) => number | undefined;

/**
* The parser to use when converting HTTP responses to SDK output types
*/
parser: __aws_sdk_types.ResponseParser<_stream.Readable>;

/**
* The serializer to use when converting SDK input to HTTP requests
*/
serializer: __aws_sdk_types.Provider<
__aws_sdk_types.RequestSerializer<_stream.Readable>
>;
}

export interface RDSDataResolvedConfiguration
extends RDSDataConfiguration,
__aws_sdk_types.ClientResolvedConfigurationBase<
OutputTypesUnion,
_stream.Readable
> {
extends RDSDataConfiguration {
_user_injected_http_handler: boolean;

base64Decoder: __aws_sdk_types.Decoder;

base64Encoder: __aws_sdk_types.Encoder;

bodyLengthChecker: (body: any) => number | undefined;

credentials: __aws_sdk_types.Provider<__aws_sdk_types.Credentials>;
Expand All @@ -182,24 +133,16 @@ export interface RDSDataResolvedConfiguration

endpointProvider: any;

handler: __aws_sdk_types.Terminalware<any, _stream.Readable>;

httpHandler: __aws_sdk_types.HttpHandler<_stream.Readable>;
httpHandler: HttpHandler;

keepAlive: boolean;

maxRedirects: number;

maxRetries: number;

parser: __aws_sdk_types.ResponseParser<_stream.Readable>;

region: __aws_sdk_types.Provider<string>;

serializer: __aws_sdk_types.Provider<
__aws_sdk_types.RequestSerializer<_stream.Readable>
>;

sha256: __aws_sdk_types.HashConstructor;

signer: __aws_sdk_types.RequestSigner;
Expand All @@ -208,13 +151,9 @@ export interface RDSDataResolvedConfiguration

sslEnabled: boolean;

streamCollector: __aws_sdk_types.StreamCollector<_stream.Readable>;

urlParser: __aws_sdk_types.UrlParser;

utf8Decoder: __aws_sdk_types.Decoder;

utf8Encoder: __aws_sdk_types.Encoder;
protocol: Protocol<any, any>;
}

export const configurationProperties: __aws_sdk_types.ConfigurationDefinition<
Expand Down Expand Up @@ -292,58 +231,6 @@ export const configurationProperties: __aws_sdk_types.ConfigurationDefinition<
return value!;
}
},
base64Decoder: {
defaultValue: __aws_sdk_util_base64_node.fromBase64
},
base64Encoder: {
defaultValue: __aws_sdk_util_base64_node.toBase64
},
utf8Decoder: {
defaultValue: __aws_sdk_util_utf8_node.fromUtf8
},
utf8Encoder: {
defaultValue: __aws_sdk_util_utf8_node.toUtf8
},
streamCollector: {
defaultValue: __aws_sdk_stream_collector_node.streamCollector
},
serializer: {
defaultProvider: (configuration: {
base64Encoder: __aws_sdk_types.Encoder;
endpoint: __aws_sdk_types.Provider<__aws_sdk_types.HttpEndpoint>;
utf8Decoder: __aws_sdk_types.Decoder;
}) => {
const promisified = configuration
.endpoint()
.then(
endpoint =>
new __aws_sdk_protocol_rest.RestSerializer<_stream.Readable>(
endpoint,
new __aws_sdk_json_builder.JsonBuilder(
configuration.base64Encoder,
configuration.utf8Decoder
),
configuration.base64Encoder,
configuration.utf8Decoder
)
);
return () => promisified;
}
},
parser: {
defaultProvider: (configuration: {
base64Decoder: __aws_sdk_types.Decoder;
streamCollector: __aws_sdk_types.StreamCollector<_stream.Readable>;
utf8Encoder: __aws_sdk_types.Encoder;
}) =>
new __aws_sdk_protocol_rest.RestParser<_stream.Readable>(
new __aws_sdk_json_parser.JsonParser(configuration.base64Decoder),
configuration.streamCollector,
__aws_sdk_json_error_unmarshaller.jsonErrorUnmarshaller,
configuration.utf8Encoder,
configuration.base64Decoder
)
},
keepAlive: {
defaultValue: true
},
Expand All @@ -355,16 +242,6 @@ export const configurationProperties: __aws_sdk_types.ConfigurationDefinition<
defaultProvider: (configuration: { keepAlive: boolean }) =>
new __aws_sdk_node_http_handler.NodeHttpHandler(configuration)
},
handler: {
defaultProvider: (configuration: {
httpHandler: __aws_sdk_types.HttpHandler<_stream.Readable>;
parser: __aws_sdk_types.ResponseParser<_stream.Readable>;
}) =>
__aws_sdk_core_handler.coreHandler<OutputTypesUnion, _stream.Readable>(
configuration.httpHandler,
configuration.parser
)
},
bodyLengthChecker: {
defaultValue: __aws_sdk_util_body_length_node.calculateBodyLength
},
Expand Down Expand Up @@ -406,5 +283,13 @@ export const configurationProperties: __aws_sdk_types.ConfigurationDefinition<
sha256: configuration.sha256,
uriEscapePath: true
})
},
protocol: {
defaultProvider: (configuration: {
httpHandler: TransferHandler<
HttpRequest,
HttpResponse
>;
}) => new RestJsonProtocol(configuration.httpHandler)
}
};
Original file line number Diff line number Diff line change
@@ -1,53 +1,32 @@
import * as __aws_sdk_middleware_stack from "@aws-sdk/middleware-stack";
import * as __aws_sdk_types from "@aws-sdk/types";
import * as _stream from "stream";
import { ExecuteStatement } from "../model/operations/ExecuteStatement";
import { InputTypesUnion } from "../types/InputTypesUnion";
import { OutputTypesUnion } from "../types/OutputTypesUnion";
import { ExecuteStatementInput } from "../types/ExecuteStatementInput";
import { ExecuteStatementOutput } from "../types/ExecuteStatementOutput";
import {coreHandler} from '@aws-sdk/core-handler';
import { RDSDataResolvedConfiguration } from "../RDSDataConfiguration";
export * from "../types/ExecuteStatementInput";
export * from "../types/ExecuteStatementOutput";
export * from "../types/ExecuteStatementExceptionsUnion";

export class ExecuteStatementCommand
implements
__aws_sdk_types.Command<
InputTypesUnion,
ExecuteStatementInput,
OutputTypesUnion,
ExecuteStatementOutput,
RDSDataResolvedConfiguration,
_stream.Readable
> {
readonly model = ExecuteStatement;
export class ExecuteStatementCommand {
readonly middlewareStack = new __aws_sdk_middleware_stack.MiddlewareStack<
ExecuteStatementInput,
ExecuteStatementOutput,
_stream.Readable
>();

constructor(readonly input: ExecuteStatementInput) {}

resolveMiddleware(
clientStack: __aws_sdk_middleware_stack.MiddlewareStack<
InputTypesUnion,
OutputTypesUnion,
_stream.Readable
OutputTypesUnion
>,
configuration: RDSDataResolvedConfiguration
): __aws_sdk_types.Handler<ExecuteStatementInput, ExecuteStatementOutput> {
const { handler } = configuration;
const { httpHandler } = configuration;
const stack = clientStack.concat(this.middlewareStack);

const handlerExecutionContext: __aws_sdk_types.HandlerExecutionContext = {
logger: {} as any,
model: this.model
logger: {} as any
};

return stack.resolve(
handler<ExecuteStatementInput, ExecuteStatementOutput>(
httpHandler<ExecuteStatementInput, ExecuteStatementOutput>(
handlerExecutionContext
),
handlerExecutionContext
Expand Down
13 changes: 12 additions & 1 deletion packages/fetch-http-handler/src/fetch-http-handler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
BrowserHttpOptions,
HttpOptions,
Handler,
HeaderBag,
HttpHandler,
Expand All @@ -14,6 +14,17 @@ import { buildQueryString } from "@aws-sdk/querystring-builder";

declare var AbortController: any;

/**
* Represents the http options that can be passed to a browser http client.
*/
export interface BrowserHttpOptions extends HttpOptions {
/**
* The number of milliseconds a request can take before being automatically
* terminated.
*/
requestTimeout?: number;
}

export class FetchHttpHandler implements HttpHandler<Blob, BrowserHttpOptions> {
constructor(private readonly httpOptions: BrowserHttpOptions = {}) {}

Expand Down
1 change: 1 addition & 0 deletions packages/middleware-stack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
},
"author": {
"name": "AWS SDK for JavaScript Team",
"email": "",
"url": "https://aws.amazon.com/javascript/"
},
"license": "Apache-2.0",
Expand Down
Loading

0 comments on commit 0de0a22

Please sign in to comment.