Skip to content

Commit

Permalink
Combine serde context (#418)
Browse files Browse the repository at this point in the history
* feat: combine serde types, cleanup unused imports

* feat: update model location

* feat: change Injectable to Pluggable
  • Loading branch information
Chase Coalwell authored and srchase committed Jun 16, 2023
1 parent 92acf3c commit be75ba9
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 19 deletions.
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
6 changes: 3 additions & 3 deletions packages/smithy-client/src/client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MiddlewareStack } from "@aws-sdk/middleware-stack";
import { Protocol, Command, MetadataBearer, Injectable } from "@aws-sdk/types";
import { Protocol, Command, MetadataBearer, Pluggable } from "@aws-sdk/types";

export interface SmithyConfiguration<HandlerOptions> {
protocol: Protocol<any, any, HandlerOptions>;
Expand All @@ -19,8 +19,8 @@ export class Client<
constructor(config: SmithyConfiguration<HandlerOptions>) {
this.config = config;
}
use(injectable: Injectable<ClientInput, ClientOutput>) {
injectable(this.middlewareStack);
use(pluggable: Pluggable<ClientInput, ClientOutput>) {
pluggable(this.middlewareStack);
}
send<InputType extends ClientInput, OutputType extends ClientOutput>(
command: Command<
Expand Down
6 changes: 3 additions & 3 deletions packages/smithy-client/src/command.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { MiddlewareStack } from "@aws-sdk/middleware-stack";
import { Injectable, HandlerOptions as InjectOptions } from "@aws-sdk/types";
import { Pluggable, HandlerOptions as InjectOptions } from "@aws-sdk/types";

export class Command<InputType extends object, OutputType extends object> {
readonly middlewareStack = new MiddlewareStack<InputType, OutputType>();
use(injectable: Injectable<InputType, OutputType>) {
injectable(this.middlewareStack);
use(pluggable: Pluggable<InputType, OutputType>) {
pluggable(this.middlewareStack);
}
}

0 comments on commit be75ba9

Please sign in to comment.