Skip to content

Commit

Permalink
fix(types): use optional endpoint for inputs to serializer middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
kuhe committed Mar 7, 2024
1 parent 85a275d commit d11f5b3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/many-stingrays-bow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@smithy/middleware-serde": patch
---

use SerdeFunctions as input type and SerdeContext as resolved type for serde plugin
7 changes: 4 additions & 3 deletions packages/middleware-serde/src/deserializerMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
DeserializeMiddleware,
HandlerExecutionContext,
ResponseDeserializer,
SerdeContext,
SerdeFunctions,
} from "@smithy/types";

Expand All @@ -13,9 +14,9 @@ import {
*
* 3rd type parameter is deprecated and unused.
*/
export const deserializerMiddleware = <Input extends object, Output extends object, _ = any>(
export const deserializerMiddleware = <Input extends object, Output extends object, CommandSerdeContext extends SerdeContext = any>(
options: SerdeFunctions,
deserializer: ResponseDeserializer<any, any, SerdeFunctions>
deserializer: ResponseDeserializer<any, any, CommandSerdeContext>
): DeserializeMiddleware<Input, Output> => (
next: DeserializeHandler<Input, Output>,
context: HandlerExecutionContext
Expand All @@ -24,7 +25,7 @@ export const deserializerMiddleware = <Input extends object, Output extends obje
): Promise<DeserializeHandlerOutput<Output>> => {
const { response } = await next(args);
try {
const parsed = await deserializer(response, options);
const parsed = await deserializer(response, options as CommandSerdeContext);
return {
response,
output: parsed as Output,
Expand Down
8 changes: 4 additions & 4 deletions packages/middleware-serde/src/serdePlugin.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {
DeserializeHandlerOptions,
Endpoint,
EndpointBearer,
MetadataBearer,
MiddlewareStack,
Pluggable,
Provider,
RequestSerializer,
ResponseDeserializer,
SerdeContext,
SerdeFunctions,
SerializeHandlerOptions,
UrlParser,
Expand Down Expand Up @@ -45,10 +45,10 @@ export type V1OrV2Endpoint = {
*
* Note: 2nd type parameter is deprecated and unused.
*/
export function getSerdePlugin<InputType extends object, _, OutputType extends MetadataBearer>(
export function getSerdePlugin<InputType extends object, CommandSerdeContext extends SerdeContext, OutputType extends MetadataBearer>(
config: V1OrV2Endpoint & SerdeFunctions,
serializer: RequestSerializer<any, SerdeFunctions & EndpointBearer>,
deserializer: ResponseDeserializer<OutputType, any, SerdeFunctions>
serializer: RequestSerializer<any, CommandSerdeContext>,
deserializer: ResponseDeserializer<OutputType, any, CommandSerdeContext>
): Pluggable<InputType, OutputType> {
return {
applyToStack: (commandStack: MiddlewareStack<InputType, OutputType>) => {
Expand Down
8 changes: 4 additions & 4 deletions packages/middleware-serde/src/serializerMiddleware.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
EndpointBearer,
HandlerExecutionContext,
RequestSerializer,
SerdeContext,
SerdeFunctions,
SerializeHandler,
SerializeHandlerArguments,
Expand All @@ -16,9 +16,9 @@ import type { V1OrV2Endpoint } from "./serdePlugin";
*
* Note: 3rd type parameter is deprecated and unused.
*/
export const serializerMiddleware = <Input extends object, Output extends object, _>(
export const serializerMiddleware = <Input extends object, Output extends object, CommandSerdeContext extends SerdeContext = any>(
options: V1OrV2Endpoint & SerdeFunctions,
serializer: RequestSerializer<any, SerdeFunctions & EndpointBearer>
serializer: RequestSerializer<any, CommandSerdeContext>
): SerializeMiddleware<Input, Output> => (
next: SerializeHandler<Input, Output>,
context: HandlerExecutionContext
Expand All @@ -34,7 +34,7 @@ export const serializerMiddleware = <Input extends object, Output extends object
throw new Error("No valid endpoint provider available.");
}

const request = await serializer(args.input, { ...options, endpoint });
const request = await serializer(args.input, { ...options, endpoint } as CommandSerdeContext);

return next({
...args,
Expand Down

0 comments on commit d11f5b3

Please sign in to comment.