Skip to content

Commit 929801b

Browse files
authored
feat: enable ctor arg passthrough for requestHandler (#1167)
* feat: enable ctor arg passthrough for requestHandler * use record as requestHandler input type fallback * chore: formatting * add Record fallback to httphandler user input * chore: formatting
1 parent d70a00a commit 929801b

File tree

3 files changed

+56
-6
lines changed

3 files changed

+56
-6
lines changed

.changeset/three-paws-add.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@smithy/protocol-http": minor
3+
"@smithy/smithy-client": minor
4+
---
5+
6+
allow constructor parameters pass-through when initializing requestHandler

packages/protocol-http/src/httpHandler.ts

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
import { HttpHandlerOptions, RequestHandler } from "@smithy/types";
1+
import type {
2+
FetchHttpHandlerOptions,
3+
HttpHandlerOptions,
4+
NodeHttpHandlerOptions,
5+
RequestHandler,
6+
} from "@smithy/types";
27

3-
import { HttpRequest } from "./httpRequest";
4-
import { HttpResponse } from "./httpResponse";
8+
import type { HttpRequest } from "./httpRequest";
9+
import type { HttpResponse } from "./httpResponse";
510

611
/**
712
* @internal
@@ -23,3 +28,27 @@ export type HttpHandler<HttpHandlerConfig extends object = {}> = RequestHandler<
2328
*/
2429
httpHandlerConfigs(): HttpHandlerConfig;
2530
};
31+
32+
/**
33+
* @public
34+
*
35+
* A type representing the accepted user inputs for the `requestHandler` field
36+
* of a client's constructor object.
37+
*
38+
* You may provide an instance of an HttpHandler, or alternatively
39+
* provide the constructor arguments as an object which will be passed
40+
* to the constructor of the default request handler.
41+
*
42+
* The default class constructor to which your arguments will be passed
43+
* varies. The Node.js default is the NodeHttpHandler and the browser/react-native
44+
* default is the FetchHttpHandler. In rarer cases specific clients may be
45+
* configured to use other default implementations such as Websocket or HTTP2.
46+
*
47+
* The fallback type Record<string, unknown> is part of the union to allow
48+
* passing constructor params to an unknown requestHandler type.
49+
*/
50+
export type HttpHandlerUserInput =
51+
| HttpHandler
52+
| NodeHttpHandlerOptions
53+
| FetchHttpHandlerOptions
54+
| Record<string, unknown>;

packages/smithy-client/src/client.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
11
import { constructStack } from "@smithy/middleware-stack";
2-
import { Client as IClient, Command, MetadataBearer, MiddlewareStack, RequestHandler } from "@smithy/types";
2+
import {
3+
Client as IClient,
4+
Command,
5+
FetchHttpHandlerOptions,
6+
MetadataBearer,
7+
MiddlewareStack,
8+
NodeHttpHandlerOptions,
9+
RequestHandler,
10+
} from "@smithy/types";
311

412
/**
513
* @public
614
*/
715
export interface SmithyConfiguration<HandlerOptions> {
8-
requestHandler: RequestHandler<any, any, HandlerOptions>;
16+
requestHandler:
17+
| RequestHandler<any, any, HandlerOptions>
18+
| NodeHttpHandlerOptions
19+
| FetchHttpHandlerOptions
20+
| Record<string, unknown>;
921
/**
1022
* The API version set internally by the SDK, and is
1123
* not planned to be used by customer code.
@@ -17,7 +29,10 @@ export interface SmithyConfiguration<HandlerOptions> {
1729
/**
1830
* @internal
1931
*/
20-
export type SmithyResolvedConfiguration<HandlerOptions> = SmithyConfiguration<HandlerOptions>;
32+
export type SmithyResolvedConfiguration<HandlerOptions> = {
33+
requestHandler: RequestHandler<any, any, HandlerOptions>;
34+
readonly apiVersion: string;
35+
};
2136

2237
/**
2338
* @public

0 commit comments

Comments
 (0)