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 d38f9ba
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 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
5 changes: 3 additions & 2 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 @@ -15,7 +16,7 @@ import {
*/
export const deserializerMiddleware = <Input extends object, Output extends object, _ = any>(

Check warning on line 17 in packages/middleware-serde/src/deserializerMiddleware.ts

View workflow job for this annotation

GitHub Actions / TypeScript Lint

'_' is defined but never used
options: SerdeFunctions,
deserializer: ResponseDeserializer<any, any, SerdeFunctions>
deserializer: ResponseDeserializer<any, any, SerdeContext>
): DeserializeMiddleware<Input, Output> => (
next: DeserializeHandler<Input, Output>,
context: HandlerExecutionContext

Check warning on line 22 in packages/middleware-serde/src/deserializerMiddleware.ts

View workflow job for this annotation

GitHub Actions / TypeScript Lint

'context' is defined but never used
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 SerdeContext);
return {
response,
output: parsed as Output,
Expand Down
6 changes: 3 additions & 3 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 @@ -47,8 +47,8 @@ export type V1OrV2Endpoint = {
*/
export function getSerdePlugin<InputType extends object, _, OutputType extends MetadataBearer>(

Check warning on line 48 in packages/middleware-serde/src/serdePlugin.ts

View workflow job for this annotation

GitHub Actions / TypeScript Lint

'_' is defined but never used
config: V1OrV2Endpoint & SerdeFunctions,
serializer: RequestSerializer<any, SerdeFunctions & EndpointBearer>,
deserializer: ResponseDeserializer<OutputType, any, SerdeFunctions>
serializer: RequestSerializer<any, SerdeContext>,
deserializer: ResponseDeserializer<OutputType, any, SerdeContext>
): Pluggable<InputType, OutputType> {
return {
applyToStack: (commandStack: MiddlewareStack<InputType, OutputType>) => {
Expand Down
6 changes: 3 additions & 3 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 @@ -18,7 +18,7 @@ import type { V1OrV2Endpoint } from "./serdePlugin";
*/
export const serializerMiddleware = <Input extends object, Output extends object, _>(

Check warning on line 19 in packages/middleware-serde/src/serializerMiddleware.ts

View workflow job for this annotation

GitHub Actions / TypeScript Lint

'_' is defined but never used
options: V1OrV2Endpoint & SerdeFunctions,
serializer: RequestSerializer<any, SerdeFunctions & EndpointBearer>
serializer: RequestSerializer<any, SerdeContext>
): 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 SerdeContext);

return next({
...args,
Expand Down

0 comments on commit d38f9ba

Please sign in to comment.