From abddf1e849f1592ecf2484fb31e26c5db8486a4f Mon Sep 17 00:00:00 2001 From: George Fu Date: Tue, 20 Feb 2024 20:37:50 +0000 Subject: [PATCH 1/5] feat: enable ctor arg passthrough for requestHandler --- .changeset/three-paws-add.md | 6 +++++ packages/protocol-http/src/httpHandler.ts | 29 ++++++++++++++++++++--- packages/smithy-client/src/client.ts | 17 ++++++++++--- 3 files changed, 46 insertions(+), 6 deletions(-) create mode 100644 .changeset/three-paws-add.md diff --git a/.changeset/three-paws-add.md b/.changeset/three-paws-add.md new file mode 100644 index 00000000000..73565b2c48a --- /dev/null +++ b/.changeset/three-paws-add.md @@ -0,0 +1,6 @@ +--- +"@smithy/protocol-http": minor +"@smithy/smithy-client": minor +--- + +allow constructor parameters pass-through when initializing requestHandler diff --git a/packages/protocol-http/src/httpHandler.ts b/packages/protocol-http/src/httpHandler.ts index ec1043b3e6a..239a7ff0436 100644 --- a/packages/protocol-http/src/httpHandler.ts +++ b/packages/protocol-http/src/httpHandler.ts @@ -1,7 +1,12 @@ -import { HttpHandlerOptions, RequestHandler } from "@smithy/types"; +import type { + FetchHttpHandlerOptions, + HttpHandlerOptions, + NodeHttpHandlerOptions, + RequestHandler, +} from "@smithy/types"; -import { HttpRequest } from "./httpRequest"; -import { HttpResponse } from "./httpResponse"; +import type { HttpRequest } from "./httpRequest"; +import type { HttpResponse } from "./httpResponse"; /** * @internal @@ -23,3 +28,21 @@ export type HttpHandler = RequestHandler< */ httpHandlerConfigs(): HttpHandlerConfig; }; + +/** + * @public + * + * A type representing the accepted user inputs for the `requestHandler` field + * of a client's constructor object. + * + * You may provide an instance of an HttpHandler, or alternatively + * provide the constructor arguments as an object which will be passed + * to the constructor of the default request handler. + * + * The default class constructor to which your arguments will be passed + * varies. The Node.js default is the NodeHttpHandler and the browser/react-native + * default is the FetchHttpHandler. In rarer cases specific clients may be + * configured to use other default implementations such as Websocket or HTTP2. + * + */ +export type HttpHandlerUserInput = HttpHandler | NodeHttpHandlerOptions | FetchHttpHandlerOptions; diff --git a/packages/smithy-client/src/client.ts b/packages/smithy-client/src/client.ts index c035f83646e..25b2df3dc2e 100644 --- a/packages/smithy-client/src/client.ts +++ b/packages/smithy-client/src/client.ts @@ -1,11 +1,19 @@ import { constructStack } from "@smithy/middleware-stack"; -import { Client as IClient, Command, MetadataBearer, MiddlewareStack, RequestHandler } from "@smithy/types"; +import { + Client as IClient, + Command, + FetchHttpHandlerOptions, + MetadataBearer, + MiddlewareStack, + NodeHttpHandlerOptions, + RequestHandler, +} from "@smithy/types"; /** * @public */ export interface SmithyConfiguration { - requestHandler: RequestHandler; + requestHandler: RequestHandler | NodeHttpHandlerOptions | FetchHttpHandlerOptions | any; /** * The API version set internally by the SDK, and is * not planned to be used by customer code. @@ -17,7 +25,10 @@ export interface SmithyConfiguration { /** * @internal */ -export type SmithyResolvedConfiguration = SmithyConfiguration; +export type SmithyResolvedConfiguration = { + requestHandler: RequestHandler; + readonly apiVersion: string; +}; /** * @public From 157e88b43e030760aefe5bf34488686c144c2fa1 Mon Sep 17 00:00:00 2001 From: George Fu Date: Thu, 22 Feb 2024 18:46:13 +0000 Subject: [PATCH 2/5] use record as requestHandler input type fallback --- packages/smithy-client/src/client.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/smithy-client/src/client.ts b/packages/smithy-client/src/client.ts index 25b2df3dc2e..a953a4813b5 100644 --- a/packages/smithy-client/src/client.ts +++ b/packages/smithy-client/src/client.ts @@ -13,7 +13,7 @@ import { * @public */ export interface SmithyConfiguration { - requestHandler: RequestHandler | NodeHttpHandlerOptions | FetchHttpHandlerOptions | any; + requestHandler: RequestHandler | NodeHttpHandlerOptions | FetchHttpHandlerOptions | Record; /** * The API version set internally by the SDK, and is * not planned to be used by customer code. From 7874efcc2ac228ad6bce08cd3000e10bcc3c7dcf Mon Sep 17 00:00:00 2001 From: George Fu Date: Thu, 22 Feb 2024 18:54:35 +0000 Subject: [PATCH 3/5] chore: formatting --- packages/smithy-client/src/client.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/smithy-client/src/client.ts b/packages/smithy-client/src/client.ts index a953a4813b5..7c7cacbae8c 100644 --- a/packages/smithy-client/src/client.ts +++ b/packages/smithy-client/src/client.ts @@ -13,7 +13,11 @@ import { * @public */ export interface SmithyConfiguration { - requestHandler: RequestHandler | NodeHttpHandlerOptions | FetchHttpHandlerOptions | Record; + requestHandler: + | RequestHandler + | NodeHttpHandlerOptions + | FetchHttpHandlerOptions + | Record; /** * The API version set internally by the SDK, and is * not planned to be used by customer code. From e49647a8702b1dfe8f24eb662840e88b7b211279 Mon Sep 17 00:00:00 2001 From: George Fu Date: Thu, 22 Feb 2024 19:21:59 +0000 Subject: [PATCH 4/5] add Record fallback to httphandler user input --- packages/protocol-http/src/httpHandler.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/protocol-http/src/httpHandler.ts b/packages/protocol-http/src/httpHandler.ts index 239a7ff0436..536a1d50d9a 100644 --- a/packages/protocol-http/src/httpHandler.ts +++ b/packages/protocol-http/src/httpHandler.ts @@ -44,5 +44,7 @@ export type HttpHandler = RequestHandler< * default is the FetchHttpHandler. In rarer cases specific clients may be * configured to use other default implementations such as Websocket or HTTP2. * + * The fallback type Record is part of the union to allow + * passing constructor params to an unknown requestHandler type. */ -export type HttpHandlerUserInput = HttpHandler | NodeHttpHandlerOptions | FetchHttpHandlerOptions; +export type HttpHandlerUserInput = HttpHandler | NodeHttpHandlerOptions | FetchHttpHandlerOptions | Record; From 0c106bc8a21ecbf4360b52441b41f0658db7843d Mon Sep 17 00:00:00 2001 From: George Fu Date: Thu, 22 Feb 2024 19:33:50 +0000 Subject: [PATCH 5/5] chore: formatting --- packages/protocol-http/src/httpHandler.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/protocol-http/src/httpHandler.ts b/packages/protocol-http/src/httpHandler.ts index 536a1d50d9a..906e8d8edaa 100644 --- a/packages/protocol-http/src/httpHandler.ts +++ b/packages/protocol-http/src/httpHandler.ts @@ -47,4 +47,8 @@ export type HttpHandler = RequestHandler< * The fallback type Record is part of the union to allow * passing constructor params to an unknown requestHandler type. */ -export type HttpHandlerUserInput = HttpHandler | NodeHttpHandlerOptions | FetchHttpHandlerOptions | Record; +export type HttpHandlerUserInput = + | HttpHandler + | NodeHttpHandlerOptions + | FetchHttpHandlerOptions + | Record;