Skip to content

Combine serde context #418

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

Merged
merged 5 commits into from
Oct 23, 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
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import { Command } from "@aws-sdk/smithy-client";
import { serdePlugin } from "@aws-sdk/middleware-serde";
import { HttpOptions, Handler, HandlerExecutionContext } from "@aws-sdk/types";
import {
HttpOptions,
Handler,
HandlerExecutionContext,
FinalizeHandlerArguments,
MiddlewareStack
} from "@aws-sdk/types";
import { RDSDataResolvedConfiguration } from "../RDSDataConfiguration";
import { HttpRequest } from "@aws-sdk/protocol-http";
import {
executeStatementSerializer,
executeStatementDeserializer
} from "../protocol/ExecuteStatement";
import { FinalizeHandlerArguments, MiddlewareStack } from "@aws-sdk/types";
import {
ExecuteStatementRequest,
ExecuteStatementResponse
} from "../models/rdsdataservice";
import { ExecuteStatementRequest, ExecuteStatementResponse } from "../models";

type InputTypesUnion = any;
type OutputTypesUnion = any;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as _smithy from "../../lib/smithy";
import * as _smithy from "../lib/smithy";
import { MetadataBearer as $MetadataBearer } from "@aws-sdk/types";

export type ArrayValue =
Expand Down
44 changes: 20 additions & 24 deletions clients/node/client-rds-data-node/protocol/AwsRestJson1_1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,13 @@ import {
ForbiddenException,
InternalServerErrorException,
ServiceUnavailableError
} from "../models/rdsdataservice";
} from "../models";
import { HttpRequest, HttpResponse } from "@aws-sdk/protocol-http";
import {
SerializerContext,
DeserializerContext,
ResponseMetadata
} from "@aws-sdk/types";
import { SerdeContext, ResponseMetadata } from "@aws-sdk/types";

export function executeStatementAwsRestJson1_1Serialize(
input: ExecuteStatementRequest,
context: SerializerContext
context: SerdeContext
): HttpRequest {
let body: any = {};
if (input.resourceArn !== undefined) {
Expand Down Expand Up @@ -75,7 +71,7 @@ export function executeStatementAwsRestJson1_1Serialize(

export async function executeStatementAwsRestJson1_1Deserialize(
output: HttpResponse,
context: DeserializerContext
context: SerdeContext
): Promise<ExecuteStatementResponse> {
if (output.statusCode !== 200) {
return executeStatementAwsRestJson1_1DeserializeError(output, context);
Expand All @@ -99,7 +95,7 @@ export async function executeStatementAwsRestJson1_1Deserialize(

async function executeStatementAwsRestJson1_1DeserializeError(
output: HttpResponse,
context: DeserializerContext
context: SerdeContext
): Promise<ExecuteStatementResponse> {
let data = await parseBody(output.body, context);
let response: any;
Expand Down Expand Up @@ -137,7 +133,7 @@ async function executeStatementAwsRestJson1_1DeserializeError(

const sqlParameterListAwsRestJson1_1Serialize = (
input: Array<SqlParameter>,
context: SerializerContext
context: SerdeContext
): Array<SqlParameter> =>
input &&
input.map(sqlParameter =>
Expand All @@ -146,7 +142,7 @@ const sqlParameterListAwsRestJson1_1Serialize = (

const sqlParameterAwsRestJson1_1Serialize = (
input: SqlParameter,
context: SerializerContext
context: SerdeContext
): any =>
input.name &&
input.value && {
Expand All @@ -156,7 +152,7 @@ const sqlParameterAwsRestJson1_1Serialize = (

const fieldAwsRestJson1_1Serialize = (
input: Field,
context: SerializerContext
context: SerdeContext
): any =>
Field.visit(input, {
blobValue: value => {
Expand Down Expand Up @@ -190,7 +186,7 @@ const fieldAwsRestJson1_1Serialize = (

export function columnMetadataAwsRestJson1_1Deserialize(
input: any,
context: DeserializerContext
context: SerdeContext
): ColumnMetadata {
let columnMetadata: any = {
$namespace: "com.amazon.rdsdataservice",
Expand Down Expand Up @@ -257,7 +253,7 @@ export function columnMetadataAwsRestJson1_1Deserialize(

const columnMetadataListAwsRestJson1_1Deserialize = (
input: any,
context: DeserializerContext
context: SerdeContext
): Array<ColumnMetadata> =>
input &&
input.map((columnMetadata: any) =>
Expand All @@ -266,7 +262,7 @@ const columnMetadataListAwsRestJson1_1Deserialize = (

const fieldAwsRestJson1_1Deserialize = (
input: any,
context: DeserializerContext
context: SerdeContext
): any =>
Field.visit(input, {
blobValue: value => {
Expand Down Expand Up @@ -300,14 +296,14 @@ const fieldAwsRestJson1_1Deserialize = (

const generatedFieldsAwsRestJson1_1Deserialize = (
input: any,
context: DeserializerContext
context: SerdeContext
): Array<Field> =>
input &&
input.map((field: any) => fieldAwsRestJson1_1Deserialize(field, context));

const recordsAwsRestJson1_1Deserialize = (
input: any,
context: DeserializerContext
context: SerdeContext
): Array<Array<Field>> =>
input &&
input.map((recordsList: any) =>
Expand All @@ -316,14 +312,14 @@ const recordsAwsRestJson1_1Deserialize = (

const recordsListAwsRestJson1_1Deserialize = (
input: any,
context: DeserializerContext
context: SerdeContext
): Array<Field> =>
input &&
input.map((field: any) => fieldAwsRestJson1_1Deserialize(field, context));

const badRequestExceptionDeserialize = (
input: any,
context: DeserializerContext
context: SerdeContext
): BadRequestException => ({
__type: "com.amazon.rdsdataservice#BadRequestException",
$name: "BadRequestException",
Expand All @@ -333,7 +329,7 @@ const badRequestExceptionDeserialize = (

const statementTimeoutExceptionDeserialize = (
input: any,
context: DeserializerContext
context: SerdeContext
): StatementTimeoutException => ({
__type: "com.amazon.rdsdataservice#StatementTimeoutException",
$name: "StatementTimeoutException",
Expand All @@ -344,7 +340,7 @@ const statementTimeoutExceptionDeserialize = (

const forbiddenExceptionDeserialize = (
input: any,
context: DeserializerContext
context: SerdeContext
): ForbiddenException => ({
__type: "com.amazon.rdsdataservice#ForbiddenException",
$name: "ForbiddenException",
Expand All @@ -354,7 +350,7 @@ const forbiddenExceptionDeserialize = (

const internalServerErrorExceptionDeserialize = (
input: any,
context: DeserializerContext
context: SerdeContext
): InternalServerErrorException => ({
__type: "com.amazon.rdsdataservice#InternalServerErrorException",
$name: "InternalServerErrorException",
Expand All @@ -363,7 +359,7 @@ const internalServerErrorExceptionDeserialize = (

const serviceUnavailableErrorDeserialize = (
input: any,
context: DeserializerContext
context: SerdeContext
): ServiceUnavailableError => ({
__type: "com.amazon.rdsdataservice#ServiceUnavailableError",
$name: "ServiceUnavailableError",
Expand All @@ -376,7 +372,7 @@ const deserializeMetadata = (output: HttpResponse): ResponseMetadata => ({
requestId: output.headers["x-amzn-requestid"]
});

const parseBody = (streamBody: any, context: DeserializerContext): any => {
const parseBody = (streamBody: any, context: SerdeContext): any => {
return context.streamCollector(streamBody).then(body => {
return JSON.parse(context.utf8Encoder(body));
});
Expand Down
11 changes: 4 additions & 7 deletions clients/node/client-rds-data-node/protocol/ExecuteStatement.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { HttpRequest, HttpResponse } from "@aws-sdk/protocol-http";
import { SerializerContext, DeserializerContext } from "@aws-sdk/types";
import {
ExecuteStatementRequest,
ExecuteStatementResponse
} from "../models/rdsdataservice";
import { SerdeContext } from "@aws-sdk/types";
import { ExecuteStatementRequest, ExecuteStatementResponse } from "../models";
import {
executeStatementAwsRestJson1_1Serialize,
executeStatementAwsRestJson1_1Deserialize
Expand All @@ -12,7 +9,7 @@ import {
export function executeStatementSerializer(
input: ExecuteStatementRequest,
protocol: string,
utils: SerializerContext
utils: SerdeContext
): HttpRequest {
switch (protocol) {
case "aws.rest-json-1.1":
Expand All @@ -25,7 +22,7 @@ export function executeStatementSerializer(
export async function executeStatementDeserializer(
output: HttpResponse,
protocol: string,
utils: DeserializerContext
utils: SerdeContext
): Promise<ExecuteStatementResponse> {
switch (protocol) {
case "aws.rest-json-1.1":
Expand Down
4 changes: 2 additions & 2 deletions packages/middleware-content-length/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
BodyLengthCalculator,
MetadataBearer,
BuildHandlerOutput,
Injectable
Pluggable
} from "@aws-sdk/types";
import { HttpRequest } from "@aws-sdk/protocol-http";

Expand Down Expand Up @@ -46,7 +46,7 @@ export function contentLengthMiddleware(

export const contentLengthPlugin = (options: {
bodyLengthChecker: BodyLengthCalculator;
}): Injectable<any, any> => clientStack => {
}): Pluggable<any, any> => clientStack => {
clientStack.add(contentLengthMiddleware(options.bodyLengthChecker), {
step: "build",
tags: { SET_CONTENT_LENGTH: true }
Expand Down
13 changes: 4 additions & 9 deletions packages/middleware-serde/src/serdePlugin.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import {
RequestSerializer,
ResponseDeserializer,
Injectable,
Pluggable,
Protocol,
MetadataBearer,
MiddlewareStack,
EndpointBearer,
Provider
EndpointBearer
} from "@aws-sdk/types";
import { deserializerMiddleware } from "./deserializerMiddleware";
import { serializerMiddleware } from "./serializerMiddleware";
Expand All @@ -17,11 +16,11 @@ export function serdePlugin<
OutputType extends MetadataBearer,
DeserializerRuntimeUtils
>(
config: PromisifyEndpoint<SerializerRuntimeUtils> &
config: SerializerRuntimeUtils &
DeserializerRuntimeUtils & { protocol: Protocol<any, any> },
serializer: RequestSerializer<any, SerializerRuntimeUtils>,
deserializer: ResponseDeserializer<OutputType, any, DeserializerRuntimeUtils>
): Injectable<InputType, OutputType> {
): Pluggable<InputType, OutputType> {
return (commandStack: MiddlewareStack<InputType, OutputType>) => {
commandStack.add(deserializerMiddleware(config, deserializer), {
step: "deserialize",
Expand All @@ -33,7 +32,3 @@ export function serdePlugin<
});
};
}

export type PromisifyEndpoint<T extends EndpointBearer> = {
[K in keyof T]: K extends "endpoint" ? Provider<T[K]> : T[K];
};
3 changes: 1 addition & 2 deletions packages/middleware-serde/src/serializerMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ import {
Protocol,
EndpointBearer
} from "@aws-sdk/types";
import { PromisifyEndpoint } from "./serdePlugin";

export function serializerMiddleware<
Input extends object,
Output extends object,
RuntimeUtils extends EndpointBearer
>(
options: { protocol: Protocol<any, any> } & PromisifyEndpoint<RuntimeUtils>,
options: { protocol: Protocol<any, any> } & RuntimeUtils,
serializer: RequestSerializer<any, RuntimeUtils>
): SerializeMiddleware<Input, Output> {
return (
Expand Down
4 changes: 2 additions & 2 deletions packages/middleware-user-agent/src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
BuildHandler,
MetadataBearer,
BuildHandlerOutput,
Injectable
Pluggable
} from "@aws-sdk/types";
import { HttpRequest } from "@aws-sdk/protocol-http";
import { UserAgentConfig } from "./configurations";
Expand Down Expand Up @@ -36,7 +36,7 @@ export function userAgentMiddleware(options: UserAgentConfig.Resolved) {

export const userAgentPlugin = (
config: UserAgentConfig.Resolved
): Injectable<any, any> => clientStack => {
): Pluggable<any, any> => clientStack => {
clientStack.add(userAgentMiddleware(config), {
step: "build",
tags: { SET_USER_AGENT: true }
Expand Down
11 changes: 5 additions & 6 deletions packages/protocol-rest-json/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import {
Protocol,
TransferHandler,
HttpOptions,
SerializerContext,
DeserializerContext
SerdeContext
} from "@aws-sdk/types";
import { HttpRequest, HttpResponse } from "@aws-sdk/protocol-http";

Expand All @@ -20,16 +19,16 @@ export class RestJsonProtocol extends Protocol<
super(handler);
}
serialize(
serializer: RequestSerializer<HttpRequest, SerializerContext>,
serializer: RequestSerializer<HttpRequest, SerdeContext>,
input: any,
utils: SerializerContext
utils: SerdeContext
) {
return serializer(input, "aws.rest-json-1.1", utils);
}
deserialize(
deserializer: ResponseDeserializer<HttpResponse, any, DeserializerContext>,
deserializer: ResponseDeserializer<HttpResponse, any, SerdeContext>,
output: HttpResponse,
utils: DeserializerContext
utils: SerdeContext
) {
return deserializer(output, "aws.rest-json-1.1", utils) as any;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/retry-middleware/src/retryMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
FinalizeHandlerArguments,
MetadataBearer,
FinalizeHandlerOutput,
Injectable
Pluggable
} from "@aws-sdk/types";
import { RetryConfig } from "./configurations";

Expand All @@ -19,7 +19,7 @@ export function retryMiddleware(options: RetryConfig.Resolved) {

export const retryPlugin = (
options: RetryConfig.Resolved
): Injectable<any, any> => clientStack => {
): Pluggable<any, any> => clientStack => {
if (options.maxRetries > 0) {
clientStack.add(retryMiddleware(options), {
step: "finalizeRequest",
Expand Down
4 changes: 2 additions & 2 deletions packages/signing-middleware/src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
FinalizeHandlerArguments,
FinalizeRequestMiddleware,
FinalizeHandlerOutput,
Injectable
Pluggable
} from "@aws-sdk/types";
import { AwsAuthConfiguration } from "./configurations";
import { HttpRequest } from "@aws-sdk/protocol-http";
Expand All @@ -27,7 +27,7 @@ export function signingMiddleware<Input extends object, Output extends object>(

export const awsAuthPlugin = (
options: AwsAuthConfiguration.Resolved
): Injectable<any, any> => clientStack => {
): Pluggable<any, any> => clientStack => {
clientStack.add(signingMiddleware(options), {
step: "finalizeRequest",
tags: { SIGNATURE: true }
Expand Down
Loading