Skip to content

Commit

Permalink
feat: remove protocol rest json class (#438)
Browse files Browse the repository at this point in the history
* feat: remove rest-json protocol class

* feat: rename handler to RequestHandler; Consolidate types
  • Loading branch information
AllanZhengYP authored Nov 9, 2019
1 parent 6bd0469 commit 851c122
Show file tree
Hide file tree
Showing 27 changed files with 118 additions and 561 deletions.
33 changes: 13 additions & 20 deletions clients/client-rds-data/RdsDataServiceClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
Provider,
HashConstructor,
UrlParser,
Protocol,
StreamCollector,
Decoder,
Encoder
Expand All @@ -27,10 +26,7 @@ import {
EndpointsConfigInput,
EndpointsConfigResolved,
resolveEndpointsConfig,
ClientProtocolConfigInput,
ClientProtocolConfigResolved,
resolveClientProtocolConfig,
destroyClientProtocolConfig,
destroyRequestHandlerConfig,
RegionConfigInput,
RegionConfigResolved,
resolveRegionConfig
Expand All @@ -54,7 +50,7 @@ import {
resolveAwsAuthConfig,
getAwsAuthPlugin
} from "@aws-sdk/middleware-signing";
import { HttpHandler, HttpRequest, HttpResponse } from "@aws-sdk/protocol-http";
import { HttpHandler } from "@aws-sdk/protocol-http";
import {
Client as SmithyClient,
SmithyResolvedConfiguration
Expand All @@ -78,10 +74,15 @@ export type ServiceOutputTypes =
| BatchExecuteStatementResponse;

export interface RDSDataRuntimeDependencies {
/**
* The function that will be used to populate serializing protocol
*/
protocol: string;

/**
* The HTTP handler to use. Fetch in browser and Https in Nodejs
*/
httpHandler?: HttpHandler;
requestHandler?: HttpHandler;

/**
* A constructor for a class implementing the @aws-sdk/types.Hash interface that computes the SHA-256 HMAC or checksum of a string or binary buffer
Expand Down Expand Up @@ -138,13 +139,6 @@ export interface RDSDataRuntimeDependencies {
*/
defaultUserAgent?: string;

/**
* The function that will be used to populate serializing protocol
*/
protocolDefaultProvider?: (
handler: HttpHandler
) => Protocol<HttpRequest, HttpResponse>;

/**
* The service name with which to sign requests.
*/
Expand All @@ -161,7 +155,6 @@ export type RdsDataServiceConfig = RDSDataRuntimeDependencies &
RegionConfigInput &
RetryConfigInput &
EndpointsConfigInput &
ClientProtocolConfigInput &
UserAgentConfigInput;

export type RdsDataServiceResolvedConfig = SmithyResolvedConfiguration<
Expand All @@ -172,21 +165,21 @@ export type RdsDataServiceResolvedConfig = SmithyResolvedConfiguration<
RegionConfigResolved &
RetryConfigResolved &
EndpointsConfigResolved &
ClientProtocolConfigResolved &
UserAgentConfigResolved;

export class RdsDataService extends SmithyClient<
__HttpOptions,
ServiceInputTypes,
ServiceOutputTypes
ServiceOutputTypes,
RdsDataServiceResolvedConfig
> {
readonly config: RdsDataServiceResolvedConfig;

constructor(configuration: RdsDataServiceConfig) {
const _config_0 = resolveClientProtocolConfig({
const _config_0 = {
...RDSRuntimeConfiguration,
...configuration
});
};
let _config_1 = resolveRegionConfig(_config_0);
let _config_2 = resolveAwsAuthConfig(_config_1);
let _config_3 = resolveEndpointsConfig(_config_2);
Expand All @@ -201,6 +194,6 @@ export class RdsDataService extends SmithyClient<
}

destroy(): void {
destroyClientProtocolConfig(this.config);
destroyRequestHandlerConfig(this.config);
}
}
11 changes: 6 additions & 5 deletions clients/client-rds-data/commands/ExecuteStatementCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ import {
} from "../RdsDataServiceClient";

export class ExecuteStatementCommand extends Command<
ServiceInputTypes,
ExecuteStatementRequest,
ExecuteStatementResponse
ServiceOutputTypes,
ExecuteStatementResponse,
RdsDataServiceResolvedConfig
> {
constructor(readonly input: ExecuteStatementRequest) {
super();
Expand All @@ -33,9 +36,7 @@ export class ExecuteStatementCommand extends Command<
configuration: RdsDataServiceResolvedConfig,
options?: HttpOptions
): Handler<ExecuteStatementRequest, ExecuteStatementResponse> {
const {
protocol: { handler }
} = configuration;
const { requestHandler } = configuration;

this.middlewareStack.use(
getSerdePlugin(configuration, this.serialize, this.deserialize)
Expand All @@ -49,7 +50,7 @@ export class ExecuteStatementCommand extends Command<

return stack.resolve(
(request: FinalizeHandlerArguments<any>) =>
handler.handle(request.request as HttpRequest, options || {}),
requestHandler.handle(request.request as HttpRequest, options || {}),
handlerExecutionContext
);
}
Expand Down
1 change: 0 additions & 1 deletion clients/client-rds-data/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
"@aws-sdk/middleware-user-agent": "^0.1.0-preview.1",
"@aws-sdk/middleware-stack": "^0.1.0-preview.6",
"@aws-sdk/node-http-handler": "^0.1.0-preview.6",
"@aws-sdk/protocol-rest-json": "^0.1.0-preview.5",
"@aws-sdk/region-provider": "^0.1.0-preview.5",
"@aws-sdk/middleware-retry": "^0.1.0-preview.5",
"@aws-sdk/signature-v4": "^0.1.0-preview.7",
Expand Down
5 changes: 2 additions & 3 deletions clients/client-rds-data/runtimeConfig.browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@ import { FetchHttpHandler } from "@aws-sdk/fetch-http-handler";
import { parseUrl } from "@aws-sdk/url-parser-browser";
import { calculateBodyLength } from "@aws-sdk/util-body-length-browser";
import { streamCollector } from "@aws-sdk/stream-collector-browser";
import { RestJsonProtocol } from "@aws-sdk/protocol-rest-json";
import { fromUtf8, toUtf8 } from "@aws-sdk/util-utf8-browser";
import { fromBase64, toBase64 } from "@aws-sdk/util-base64-browser";
import { defaultUserAgent } from "@aws-sdk/util-user-agent-browser";
import { name, version } from "./package.json";
import { RDSDataRuntimeDependencies } from "./RdsDataServiceClient";

export const RDSRuntimeConfiguration: Required<RDSDataRuntimeDependencies> = {
protocolDefaultProvider: handler => new RestJsonProtocol(handler),
protocol: "aws.rest-json-1.1",
signingName: "rds-data",
service: "rds-data",
httpHandler: new FetchHttpHandler(),
requestHandler: new FetchHttpHandler(),
sha256: Sha256,
credentialDefaultProvider: invalidFunction("Credential is missing") as any,
regionDefaultProvider: invalidFunction("Region is missing") as any,
Expand Down
5 changes: 2 additions & 3 deletions clients/client-rds-data/runtimeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@ import { defaultProvider as regionDefaultProvider } from "@aws-sdk/region-provid
import { parseUrl } from "@aws-sdk/url-parser-node";
import { calculateBodyLength } from "@aws-sdk/util-body-length-node";
import { streamCollector } from "@aws-sdk/stream-collector-node";
import { RestJsonProtocol } from "@aws-sdk/protocol-rest-json";
import { fromUtf8, toUtf8 } from "@aws-sdk/util-utf8-node";
import { fromBase64, toBase64 } from "@aws-sdk/util-base64-node";
import { defaultUserAgent } from "@aws-sdk/util-user-agent-node";
import { name, version } from "./package.json";
import { RDSDataRuntimeDependencies } from "./RdsDataServiceClient";

export const RDSRuntimeConfiguration: Required<RDSDataRuntimeDependencies> = {
protocolDefaultProvider: handler => new RestJsonProtocol(handler),
protocol: "aws.rest-json-1.1",
signingName: "rds-data",
service: "rds-data",
httpHandler: new NodeHttpHandler(),
requestHandler: new NodeHttpHandler(),
sha256: Hash.bind(null, "sha256"),
credentialDefaultProvider,
regionDefaultProvider,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"lerna": "3.16.4",
"lint-staged": "^9.0.0",
"prettier": "1.18.2",
"typescript": "3.7.0-dev.20190926",
"typescript": "^3.7.0",
"yarn": "1.17.3"
},
"workspaces": [
Expand Down
7 changes: 7 additions & 0 deletions packages/config-resolver/src/HandlerConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { RequestHandler } from "@aws-sdk/types";

export function destroyRequestHandlerConfig(config: {
requestHandler: RequestHandler<any, any, any>;
}): void {
if (config.requestHandler.destroy) config.requestHandler.destroy();
}
29 changes: 0 additions & 29 deletions packages/config-resolver/src/ProtocolConfig.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/config-resolver/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from "./EndpointsConfig";
export * from "./RegionConfig";
export * from "./ProtocolConfig";
export * from "./HandlerConfig";
13 changes: 6 additions & 7 deletions packages/middleware-serde/src/deserializerMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@ import {
DeserializeHandler,
DeserializeHandlerArguments,
DeserializeHandlerOutput,
Protocol
RequestHandler
} from "@aws-sdk/types";

export function deserializerMiddleware<
Input extends object,
Output extends object,
RuntimeUtils = any
>(
options: { protocol: Protocol<any, any> } & RuntimeUtils,
options: {
requestHandler: RequestHandler<any, any, any>;
protocol: string;
} & RuntimeUtils,
deserializer: ResponseDeserializer<any, any, RuntimeUtils>
): DeserializeMiddleware<Input, Output> {
return (
Expand All @@ -21,11 +24,7 @@ export function deserializerMiddleware<
args: DeserializeHandlerArguments<Input>
): Promise<DeserializeHandlerOutput<Output>> => {
const { response } = await next(args);
const parsed = await options.protocol.deserialize(
deserializer,
response,
options
);
const parsed = await deserializer(response, options.protocol, options);
return {
response,
output: parsed as Output
Expand Down
19 changes: 10 additions & 9 deletions packages/middleware-serde/src/serdePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,25 @@ import {
RequestSerializer,
ResponseDeserializer,
Pluggable,
Protocol,
MetadataBearer,
MiddlewareStack,
EndpointBearer
EndpointBearer,
RequestHandler
} from "@aws-sdk/types";
import { deserializerMiddleware } from "./deserializerMiddleware";
import { serializerMiddleware } from "./serializerMiddleware";

export function getSerdePlugin<
InputType extends object,
SerializerRuntimeUtils extends EndpointBearer,
OutputType extends MetadataBearer,
DeserializerRuntimeUtils
SerDeContext extends EndpointBearer,
OutputType extends MetadataBearer
>(
config: SerializerRuntimeUtils &
DeserializerRuntimeUtils & { protocol: Protocol<any, any> },
serializer: RequestSerializer<any, SerializerRuntimeUtils>,
deserializer: ResponseDeserializer<OutputType, any, DeserializerRuntimeUtils>
config: SerDeContext & {
protocol: string;
requestHandler: RequestHandler<any, any, any>;
},
serializer: RequestSerializer<any, SerDeContext>,
deserializer: ResponseDeserializer<OutputType, any, SerDeContext>
): Pluggable<InputType, OutputType> {
return {
applyToStack: (commandStack: MiddlewareStack<InputType, OutputType>) => {
Expand Down
13 changes: 8 additions & 5 deletions packages/middleware-serde/src/serializerMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@ import {
SerializeHandlerArguments,
SerializeHandlerOutput,
SerializeMiddleware,
Protocol,
EndpointBearer
EndpointBearer,
RequestHandler
} from "@aws-sdk/types";

export function serializerMiddleware<
Input extends object,
Output extends object,
RuntimeUtils extends EndpointBearer
>(
options: { protocol: Protocol<any, any> } & RuntimeUtils,
options: {
requestHandler: RequestHandler<any, any, any>;
protocol: string;
} & RuntimeUtils,
serializer: RequestSerializer<any, RuntimeUtils>
): SerializeMiddleware<Input, Output> {
return (
Expand All @@ -25,9 +28,9 @@ export function serializerMiddleware<
...options,
endpoint: await options.endpoint()
};
const request = options.protocol.serialize(
serializer,
const request = serializer(
args.input,
options.protocol,
endpointResolvedOptions
);
return next({
Expand Down
4 changes: 2 additions & 2 deletions packages/protocol-http/src/httpHandler.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { HttpRequest } from "./httpRequest";
import { HttpResponse } from "./httpResponse";
import { TransferHandler, HttpOptions } from "@aws-sdk/types";
import { RequestHandler, HttpOptions } from "@aws-sdk/types";

export type HttpHandler = TransferHandler<
export type HttpHandler = RequestHandler<
HttpRequest,
HttpResponse,
HttpOptions
Expand Down
8 changes: 0 additions & 8 deletions packages/protocol-rest-json/.gitignore

This file was deleted.

13 changes: 0 additions & 13 deletions packages/protocol-rest-json/.npmignore

This file was deleted.

Loading

0 comments on commit 851c122

Please sign in to comment.