Skip to content

Commit 87b0aee

Browse files
Chase Coalwellsrchase
authored andcommitted
Combine serde context (#418)
* feat: combine serde types, cleanup unused imports * feat: update model location * feat: change Injectable to Pluggable
1 parent f514422 commit 87b0aee

File tree

12 files changed

+81
-103
lines changed

12 files changed

+81
-103
lines changed

packages/middleware-content-length/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
BodyLengthCalculator,
66
MetadataBearer,
77
BuildHandlerOutput,
8-
Injectable
8+
Pluggable
99
} from "@aws-sdk/types";
1010
import { HttpRequest } from "@aws-sdk/protocol-http";
1111

@@ -46,7 +46,7 @@ export function contentLengthMiddleware(
4646

4747
export const contentLengthPlugin = (options: {
4848
bodyLengthChecker: BodyLengthCalculator;
49-
}): Injectable<any, any> => clientStack => {
49+
}): Pluggable<any, any> => clientStack => {
5050
clientStack.add(contentLengthMiddleware(options.bodyLengthChecker), {
5151
step: "build",
5252
tags: { SET_CONTENT_LENGTH: true }
Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import {
22
RequestSerializer,
33
ResponseDeserializer,
4-
Injectable,
4+
Pluggable,
55
Protocol,
66
MetadataBearer,
77
MiddlewareStack,
8-
EndpointBearer,
9-
Provider
8+
EndpointBearer
109
} from "@aws-sdk/types";
1110
import { deserializerMiddleware } from "./deserializerMiddleware";
1211
import { serializerMiddleware } from "./serializerMiddleware";
@@ -17,11 +16,11 @@ export function serdePlugin<
1716
OutputType extends MetadataBearer,
1817
DeserializerRuntimeUtils
1918
>(
20-
config: PromisifyEndpoint<SerializerRuntimeUtils> &
19+
config: SerializerRuntimeUtils &
2120
DeserializerRuntimeUtils & { protocol: Protocol<any, any> },
2221
serializer: RequestSerializer<any, SerializerRuntimeUtils>,
2322
deserializer: ResponseDeserializer<OutputType, any, DeserializerRuntimeUtils>
24-
): Injectable<InputType, OutputType> {
23+
): Pluggable<InputType, OutputType> {
2524
return (commandStack: MiddlewareStack<InputType, OutputType>) => {
2625
commandStack.add(deserializerMiddleware(config, deserializer), {
2726
step: "deserialize",
@@ -33,7 +32,3 @@ export function serdePlugin<
3332
});
3433
};
3534
}
36-
37-
export type PromisifyEndpoint<T extends EndpointBearer> = {
38-
[K in keyof T]: K extends "endpoint" ? Provider<T[K]> : T[K];
39-
};

packages/middleware-serde/src/serializerMiddleware.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@ import {
77
Protocol,
88
EndpointBearer
99
} from "@aws-sdk/types";
10-
import { PromisifyEndpoint } from "./serdePlugin";
1110

1211
export function serializerMiddleware<
1312
Input extends object,
1413
Output extends object,
1514
RuntimeUtils extends EndpointBearer
1615
>(
17-
options: { protocol: Protocol<any, any> } & PromisifyEndpoint<RuntimeUtils>,
16+
options: { protocol: Protocol<any, any> } & RuntimeUtils,
1817
serializer: RequestSerializer<any, RuntimeUtils>
1918
): SerializeMiddleware<Input, Output> {
2019
return (

packages/smithy-client/src/client.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { MiddlewareStack } from "@aws-sdk/middleware-stack";
2-
import { Protocol, Command, MetadataBearer, Injectable } from "@aws-sdk/types";
2+
import { Protocol, Command, MetadataBearer, Pluggable } from "@aws-sdk/types";
33

44
export interface SmithyConfiguration<HandlerOptions> {
55
protocol: Protocol<any, any, HandlerOptions>;
@@ -19,8 +19,8 @@ export class Client<
1919
constructor(config: SmithyConfiguration<HandlerOptions>) {
2020
this.config = config;
2121
}
22-
use(injectable: Injectable<ClientInput, ClientOutput>) {
23-
injectable(this.middlewareStack);
22+
use(pluggable: Pluggable<ClientInput, ClientOutput>) {
23+
pluggable(this.middlewareStack);
2424
}
2525
send<InputType extends ClientInput, OutputType extends ClientOutput>(
2626
command: Command<

packages/smithy-client/src/command.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { MiddlewareStack } from "@aws-sdk/middleware-stack";
2-
import { Injectable, HandlerOptions as InjectOptions } from "@aws-sdk/types";
2+
import { Pluggable, HandlerOptions as InjectOptions } from "@aws-sdk/types";
33

44
export class Command<InputType extends object, OutputType extends object> {
55
readonly middlewareStack = new MiddlewareStack<InputType, OutputType>();
6-
use(injectable: Injectable<InputType, OutputType>) {
7-
injectable(this.middlewareStack);
6+
use(pluggable: Pluggable<InputType, OutputType>) {
7+
pluggable(this.middlewareStack);
88
}
99
}

packages/types/src/client.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1-
import { MiddlewareStack, Terminalware } from "./middleware";
2-
import { Structure } from "./protocol";
1+
import { MiddlewareStack } from "./middleware";
32
import { Provider, Decoder, Encoder, UrlParser } from "./util";
4-
// import { StreamCollector, ResponseParser } from "./unmarshaller";
5-
import { RequestSerializer } from "./serializer";
63
import { Endpoint } from "./http";
74
import { TransferHandler } from "./transfer";
85
import { Command } from "./command";
96
import { MetadataBearer } from "./response";
107
import { Credentials } from "./credentials";
118
import { Hash, HashConstructor } from "./crypto";
12-
import { Middleware } from "./middleware";
139

1410
export interface ConfigurationPropertyDefinition<
1511
InputType,
@@ -82,9 +78,6 @@ export interface ClientResolvedConfigurationBase {
8278
base64Encoder?: Encoder;
8379
utf8Decoder?: Decoder;
8480
utf8Incoder?: Encoder;
85-
// streamCollector?: StreamCollector<StreamType>;
86-
// serializer?: Provider<RequestSerializer<StreamType>>;
87-
// parser?: ResponseParser<StreamType>;
8881
_user_injected_http_handler?: boolean;
8982
httpHandler?: TransferHandler<any, any>;
9083
md5?: { new (): Hash };

packages/types/src/deserializer.ts

Lines changed: 0 additions & 38 deletions
This file was deleted.

packages/types/src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ export * from "./crypto";
66
export * from "./exception";
77
export * from "./http";
88
export * from "./logger";
9-
export * from "./serializer";
9+
export * from "./serde";
1010
export * from "./middleware";
1111
export * from "./protocol";
1212
export * from "./response";
1313
export * from "./signature";
14-
export * from "./deserializer";
1514
export * from "./transfer";
1615
export * from "./util";

packages/types/src/middleware.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ export interface HandlerExecutionContext {
366366
logger: Logger;
367367
}
368368

369-
export interface Injectable<Input extends object, Output extends object> {
369+
export interface Pluggable<Input extends object, Output extends object> {
370370
/**
371371
* A function that mutate the passed in middleware stack. Functions implementing
372372
* this interface can add, remove, modify existing middleware stack from clients

packages/types/src/serde.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { Decoder, Encoder, Provider } from "./util";
2+
import { Endpoint } from "./http";
3+
4+
/**
5+
* Interface for object requires an Endpoint set.
6+
*/
7+
export interface EndpointBearer {
8+
endpoint: Provider<Endpoint>;
9+
}
10+
11+
export interface StreamCollector {
12+
/**
13+
* A function that converts a stream into an array of bytes.
14+
*
15+
* @param stream The low-level native stream from browser or Nodejs runtime
16+
*/
17+
(stream: any): Promise<Uint8Array>;
18+
}
19+
20+
/**
21+
* Request and Response serde util functions for AWS services
22+
*/
23+
export interface SerdeContext extends EndpointBearer {
24+
base64Encoder: Encoder;
25+
base64Decoder: Decoder;
26+
utf8Encoder: Encoder;
27+
utf8Decoder: Decoder;
28+
streamCollector: StreamCollector;
29+
}
30+
31+
export interface RequestSerializer<
32+
Request,
33+
Context extends EndpointBearer = any
34+
> {
35+
/**
36+
* Converts the provided `input` into a request object
37+
*
38+
* @param transferProtocol The protocol as the request to be serialized
39+
* to. Like `RestJson`, `RestXML`
40+
* @param input The user input to serialize.
41+
*
42+
* @param context Context containing runtime-specific util functions.
43+
*/
44+
(input: any, transferProtocol: string, context: Context): Request;
45+
}
46+
47+
export interface ResponseDeserializer<
48+
OutputType,
49+
ResponseType = any,
50+
Context = any
51+
> {
52+
/**
53+
* Converts the output of an operation into JavaScript types.
54+
*
55+
* @param operation The operation model describing the structure of the HTTP
56+
* response received
57+
* @param input The HTTP response received from the service
58+
*
59+
* @param context context containing runtime-specific util functions.
60+
*/
61+
(output: ResponseType, protocolName: string, context: Context): Promise<
62+
OutputType
63+
>;
64+
}

packages/types/src/serializer.ts

Lines changed: 0 additions & 33 deletions
This file was deleted.

packages/types/src/transfer.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { RequestSerializer } from "./serializer";
2-
import { ResponseDeserializer } from "./deserializer";
1+
import { RequestSerializer, ResponseDeserializer } from "./serde";
32

43
export type TransferHandlerOutput<ResponseType> = { response: ResponseType };
54

0 commit comments

Comments
 (0)