diff --git a/.changeset/polite-flies-explode.md b/.changeset/polite-flies-explode.md new file mode 100644 index 00000000000..9daf81da319 --- /dev/null +++ b/.changeset/polite-flies-explode.md @@ -0,0 +1,5 @@ +--- +"@smithy/types": minor +--- + +transform inputs for env specific type helpers diff --git a/packages/types/src/transform/client-payload-blob-type-narrow.spec.ts b/packages/types/src/transform/client-payload-blob-type-narrow.spec.ts index 612b3632505..f348e878d60 100644 --- a/packages/types/src/transform/client-payload-blob-type-narrow.spec.ts +++ b/packages/types/src/transform/client-payload-blob-type-narrow.spec.ts @@ -4,9 +4,14 @@ import type { Client } from "../client"; import type { HttpHandlerOptions } from "../http"; import type { MetadataBearer } from "../response"; import type { SdkStream } from "../serde"; +import type { + NodeJsRuntimeStreamingBlobPayloadInputTypes, + StreamingBlobPayloadInputTypes, +} from "../streaming-payload/streaming-blob-payload-input-types"; import type { StreamingBlobPayloadOutputTypes } from "../streaming-payload/streaming-blob-payload-output-types"; import type { BrowserClient, NodeJsClient } from "./client-payload-blob-type-narrow"; import type { Exact } from "./exact"; +import type { Transform } from "./type-transform"; // it should narrow operational methods and the generic send method @@ -14,6 +19,7 @@ type MyInput = Partial<{ a: boolean; b: boolean | number; c: boolean | number | string; + body?: StreamingBlobPayloadInputTypes; }>; type MyOutput = { @@ -37,6 +43,19 @@ interface MyClient extends Client { putObject(args: MyInput, options: HttpHandlerOptions, cb: (err: any, data?: MyOutput) => void): void; } +{ + interface NodeJsMyClient extends NodeJsClient {} + const mockClient = (null as unknown) as NodeJsMyClient; + type Input = Parameters[0]; + + const assert1: Exact< + Input, + Transform + > = true as const; + + const assert2: Exact = false as const; +} + { interface NodeJsMyClient extends NodeJsClient {} const mockClient = (null as unknown) as NodeJsMyClient; diff --git a/packages/types/src/transform/client-payload-blob-type-narrow.ts b/packages/types/src/transform/client-payload-blob-type-narrow.ts index e271ccbdb92..60e97453afa 100644 --- a/packages/types/src/transform/client-payload-blob-type-narrow.ts +++ b/packages/types/src/transform/client-payload-blob-type-narrow.ts @@ -4,7 +4,13 @@ import type { ClientHttp2Stream } from "http2"; import type { InvokeFunction, InvokeMethod } from "../client"; import type { HttpHandlerOptions } from "../http"; import type { SdkStream } from "../serde"; +import type { + BrowserRuntimeStreamingBlobPayloadInputTypes, + NodeJsRuntimeStreamingBlobPayloadInputTypes, + StreamingBlobPayloadInputTypes, +} from "../streaming-payload/streaming-blob-payload-input-types"; import type { NarrowedInvokeFunction, NarrowedInvokeMethod } from "./client-method-transforms"; +import type { Transform } from "./type-transform"; /** * @public @@ -20,7 +26,8 @@ import type { NarrowedInvokeFunction, NarrowedInvokeMethod } from "./client-meth * const client = new YourClient({}) as NodeJsClient; * ``` */ -export type NodeJsClient = NarrowPayloadBlobOutputType< +export type NodeJsClient = NarrowPayloadBlobTypes< + NodeJsRuntimeStreamingBlobPayloadInputTypes, SdkStream, ClientType >; @@ -28,7 +35,8 @@ export type NodeJsClient = NarrowPayloadBlobOutputTyp * @public * Variant of NodeJsClient for node:http2. */ -export type NodeJsHttp2Client = NarrowPayloadBlobOutputType< +export type NodeJsHttp2Client = NarrowPayloadBlobTypes< + NodeJsRuntimeStreamingBlobPayloadInputTypes, SdkStream, ClientType >; @@ -47,7 +55,8 @@ export type NodeJsHttp2Client = NarrowPayloadBlobOutp * const client = new YourClient({}) as BrowserClient; * ``` */ -export type BrowserClient = NarrowPayloadBlobOutputType< +export type BrowserClient = NarrowPayloadBlobTypes< + BrowserRuntimeStreamingBlobPayloadInputTypes, SdkStream, ClientType >; @@ -56,7 +65,8 @@ export type BrowserClient = NarrowPayloadBlobOutputTy * * Variant of BrowserClient for XMLHttpRequest. */ -export type BrowserXhrClient = NarrowPayloadBlobOutputType< +export type BrowserXhrClient = NarrowPayloadBlobTypes< + BrowserRuntimeStreamingBlobPayloadInputTypes, SdkStream, ClientType >; @@ -64,6 +74,8 @@ export type BrowserXhrClient = NarrowPayloadBlobOutpu /** * @public * + * @deprecated use NarrowPayloadBlobTypes. + * * Narrow a given Client's blob payload outputs to the given type T. */ export type NarrowPayloadBlobOutputType = { @@ -75,3 +87,29 @@ export type NarrowPayloadBlobOutputType = { ? NarrowedInvokeMethod : ClientType[key]; }; + +/** + * @public + * + * Narrow a Client's blob payload input and output types to I and O. + */ +export type NarrowPayloadBlobTypes = { + [key in keyof ClientType]: [ClientType[key]] extends [ + InvokeFunction + ] + ? NarrowedInvokeFunction< + O, + HttpHandlerOptions, + Transform, + OutputTypes, + ConfigType + > + : [ClientType[key]] extends [InvokeMethod] + ? NarrowedInvokeMethod< + O, + HttpHandlerOptions, + Transform, + FunctionOutputTypes + > + : ClientType[key]; +};