From d11f5b3b48059ef0cf453c85f69ec65d40b360d8 Mon Sep 17 00:00:00 2001 From: George Fu Date: Thu, 7 Mar 2024 20:36:38 +0000 Subject: [PATCH] fix(types): use optional endpoint for inputs to serializer middleware --- .changeset/many-stingrays-bow.md | 5 +++++ packages/middleware-serde/src/deserializerMiddleware.ts | 7 ++++--- packages/middleware-serde/src/serdePlugin.ts | 8 ++++---- packages/middleware-serde/src/serializerMiddleware.ts | 8 ++++---- 4 files changed, 17 insertions(+), 11 deletions(-) create mode 100644 .changeset/many-stingrays-bow.md diff --git a/.changeset/many-stingrays-bow.md b/.changeset/many-stingrays-bow.md new file mode 100644 index 00000000000..2e38e8322a3 --- /dev/null +++ b/.changeset/many-stingrays-bow.md @@ -0,0 +1,5 @@ +--- +"@smithy/middleware-serde": patch +--- + +use SerdeFunctions as input type and SerdeContext as resolved type for serde plugin diff --git a/packages/middleware-serde/src/deserializerMiddleware.ts b/packages/middleware-serde/src/deserializerMiddleware.ts index ab4c2cf7b11..17c46fde229 100644 --- a/packages/middleware-serde/src/deserializerMiddleware.ts +++ b/packages/middleware-serde/src/deserializerMiddleware.ts @@ -5,6 +5,7 @@ import { DeserializeMiddleware, HandlerExecutionContext, ResponseDeserializer, + SerdeContext, SerdeFunctions, } from "@smithy/types"; @@ -13,9 +14,9 @@ import { * * 3rd type parameter is deprecated and unused. */ -export const deserializerMiddleware = ( +export const deserializerMiddleware = ( options: SerdeFunctions, - deserializer: ResponseDeserializer + deserializer: ResponseDeserializer ): DeserializeMiddleware => ( next: DeserializeHandler, context: HandlerExecutionContext @@ -24,7 +25,7 @@ export const deserializerMiddleware = > => { 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, diff --git a/packages/middleware-serde/src/serdePlugin.ts b/packages/middleware-serde/src/serdePlugin.ts index c6db5c247f7..555054e3732 100644 --- a/packages/middleware-serde/src/serdePlugin.ts +++ b/packages/middleware-serde/src/serdePlugin.ts @@ -1,13 +1,13 @@ import { DeserializeHandlerOptions, Endpoint, - EndpointBearer, MetadataBearer, MiddlewareStack, Pluggable, Provider, RequestSerializer, ResponseDeserializer, + SerdeContext, SerdeFunctions, SerializeHandlerOptions, UrlParser, @@ -45,10 +45,10 @@ export type V1OrV2Endpoint = { * * Note: 2nd type parameter is deprecated and unused. */ -export function getSerdePlugin( +export function getSerdePlugin( config: V1OrV2Endpoint & SerdeFunctions, - serializer: RequestSerializer, - deserializer: ResponseDeserializer + serializer: RequestSerializer, + deserializer: ResponseDeserializer ): Pluggable { return { applyToStack: (commandStack: MiddlewareStack) => { diff --git a/packages/middleware-serde/src/serializerMiddleware.ts b/packages/middleware-serde/src/serializerMiddleware.ts index 777bc4f1aa8..d760e850d48 100644 --- a/packages/middleware-serde/src/serializerMiddleware.ts +++ b/packages/middleware-serde/src/serializerMiddleware.ts @@ -1,7 +1,7 @@ import { - EndpointBearer, HandlerExecutionContext, RequestSerializer, + SerdeContext, SerdeFunctions, SerializeHandler, SerializeHandlerArguments, @@ -16,9 +16,9 @@ import type { V1OrV2Endpoint } from "./serdePlugin"; * * Note: 3rd type parameter is deprecated and unused. */ -export const serializerMiddleware = ( +export const serializerMiddleware = ( options: V1OrV2Endpoint & SerdeFunctions, - serializer: RequestSerializer + serializer: RequestSerializer ): SerializeMiddleware => ( next: SerializeHandler, context: HandlerExecutionContext @@ -34,7 +34,7 @@ export const serializerMiddleware =