import { constructStack } from "@aws-sdk/middleware-stack"; import { Client as IClient, Command, MetadataBearer, MiddlewareStack, RequestHandler } from "@aws-sdk/types"; export interface SmithyConfiguration { requestHandler: RequestHandler; /** * The API version set internally by the SDK, and is * not planned to be used by customer code. * @internal */ readonly apiVersion: string; } export type SmithyResolvedConfiguration = SmithyConfiguration; export class Client< HandlerOptions, ClientInput extends object, ClientOutput extends MetadataBearer, ResolvedClientConfiguration extends SmithyResolvedConfiguration > implements IClient { public middlewareStack: MiddlewareStack = constructStack(); readonly config: ResolvedClientConfiguration; constructor(config: ResolvedClientConfiguration) { this.config = config; } send( command: Command>, options?: HandlerOptions ): Promise; send( command: Command>, cb: (err: any, data?: OutputType) => void ): void; send( command: Command>, options: HandlerOptions, cb: (err: any, data?: OutputType) => void ): void; send( command: Command>, optionsOrCb?: HandlerOptions | ((err: any, data?: OutputType) => void), cb?: (err: any, data?: OutputType) => void ): Promise | void { const options = typeof optionsOrCb !== "function" ? optionsOrCb : undefined; const callback = typeof optionsOrCb === "function" ? (optionsOrCb as (err: any, data?: OutputType) => void) : cb; const handler = command.resolveMiddleware(this.middlewareStack as any, this.config, options); if (callback) { handler(command) .then( (result) => callback(null, result.output), (err: any) => callback(err) ) .catch( // prevent any errors thrown in the callback from triggering an // unhandled promise rejection () => {} ); } else { return handler(command).then((result) => result.output); } } destroy() { if (this.config.requestHandler.destroy) this.config.requestHandler.destroy(); } }