UNPKG

3.48 kBTypeScriptView Raw
1import { Endpoint } from "./http";
2import { RequestHandler } from "./transfer";
3import { Decoder, Encoder, Provider } from "./util";
4/**
5 * @public
6 *
7 * Interface for object requires an Endpoint set.
8 */
9export interface EndpointBearer {
10 endpoint: Provider<Endpoint>;
11}
12/**
13 * @public
14 */
15export interface StreamCollector {
16 /**
17 * A function that converts a stream into an array of bytes.
18 *
19 * @param stream - The low-level native stream from browser or Nodejs runtime
20 */
21 (stream: any): Promise<Uint8Array>;
22}
23/**
24 * @public
25 *
26 * Request and Response serde util functions and settings for AWS services
27 */
28export interface SerdeContext extends EndpointBearer {
29 base64Encoder: Encoder;
30 base64Decoder: Decoder;
31 utf8Encoder: Encoder;
32 utf8Decoder: Decoder;
33 streamCollector: StreamCollector;
34 requestHandler: RequestHandler<any, any>;
35 disableHostPrefix: boolean;
36}
37/**
38 * @public
39 */
40export interface RequestSerializer<Request, Context extends EndpointBearer = any> {
41 /**
42 * Converts the provided `input` into a request object
43 *
44 * @param input - The user input to serialize.
45 *
46 * @param context - Context containing runtime-specific util functions.
47 */
48 (input: any, context: Context): Promise<Request>;
49}
50/**
51 * @public
52 */
53export interface ResponseDeserializer<OutputType, ResponseType = any, Context = any> {
54 /**
55 * Converts the output of an operation into JavaScript types.
56 *
57 * @param output - The HTTP response received from the service
58 *
59 * @param context - context containing runtime-specific util functions.
60 */
61 (output: ResponseType, context: Context): Promise<OutputType>;
62}
63/**
64 * @public
65 *
66 * Declare DOM interfaces in case dom.d.ts is not added to the tsconfig lib, causing
67 * interfaces to not be defined. For developers with dom.d.ts added, the interfaces will
68 * be merged correctly.
69 *
70 * This is also required for any clients with streaming interfaces where the corresponding
71 * types are also referred. The type is only declared here once since this `@aws-sdk/types`
72 * is depended by all `@aws-sdk` packages.
73 */
74declare global {
75 /**
76 * @public
77 */
78 export interface ReadableStream {
79 }
80 /**
81 * @public
82 */
83 export interface Blob {
84 }
85}
86/**
87 * The interface contains mix-in utility functions to transfer the runtime-specific
88 * stream implementation to specified format. Each stream can ONLY be transformed
89 * once.
90 */
91export interface SdkStreamMixin {
92 transformToByteArray: () => Promise<Uint8Array>;
93 transformToString: (encoding?: string) => Promise<string>;
94 transformToWebStream: () => ReadableStream;
95}
96/**
97 * @public
98 *
99 * The type describing a runtime-specific stream implementation with mix-in
100 * utility functions.
101 */
102export type SdkStream<BaseStream> = BaseStream & SdkStreamMixin;
103/**
104 * @public
105 *
106 * Indicates that the member of type T with
107 * key StreamKey have been extended
108 * with the SdkStreamMixin helper methods.
109 */
110export type WithSdkStreamMixin<T, StreamKey extends keyof T> = {
111 [key in keyof T]: key extends StreamKey ? SdkStream<T[StreamKey]> : T[key];
112};
113/**
114 * Interface for internal function to inject stream utility functions
115 * implementation
116 *
117 * @internal
118 */
119export interface SdkStreamMixinInjector {
120 (stream: unknown): SdkStreamMixin;
121}
122/**
123 * @internal
124 */
125export interface SdkStreamSerdeContext {
126 sdkStreamMixin: SdkStreamMixinInjector;
127}