@@ -10,7 +10,7 @@ export interface HandlerArguments<Input extends object> {
10
10
input : Input ;
11
11
}
12
12
13
- export interface BuildHandlerArguments <
13
+ export interface SerializeHandlerArguments <
14
14
Input extends object ,
15
15
Stream = Uint8Array
16
16
> extends HandlerArguments < Input > {
@@ -29,13 +29,15 @@ export interface FinalizeHandlerArguments<
29
29
> extends HandlerArguments < Input > {
30
30
/**
31
31
* The user input serialized as an HTTP request.
32
- *
33
- * During the finalize phase of the execution of a middleware stack, a built
34
- * HTTP request will always be available.
35
32
*/
36
33
request : HttpRequest < Stream > ;
37
34
}
38
35
36
+ export interface BuildHandlerArguments <
37
+ Input extends object ,
38
+ Stream = Uint8Array
39
+ > extends FinalizeHandlerArguments < Input , Stream > { }
40
+
39
41
export interface Handler < Input extends object , Output extends object > {
40
42
/**
41
43
* Asynchronously converts an input object into an output object.
@@ -46,7 +48,7 @@ export interface Handler<Input extends object, Output extends object> {
46
48
( args : HandlerArguments < Input > ) : Promise < Output > ;
47
49
}
48
50
49
- export interface BuildHandler <
51
+ export interface SerializeHandler <
50
52
Input extends object ,
51
53
Output extends object ,
52
54
Stream = Uint8Array
@@ -57,7 +59,7 @@ export interface BuildHandler<
57
59
* @param args An object containing a input to the command as well as any
58
60
* associated or previously generated execution artifacts.
59
61
*/
60
- ( args : BuildHandlerArguments < Input , Stream > ) : Promise < Output > ;
62
+ ( args : SerializeHandlerArguments < Input , Stream > ) : Promise < Output > ;
61
63
}
62
64
63
65
export interface FinalizeHandler <
@@ -74,6 +76,12 @@ export interface FinalizeHandler<
74
76
( args : FinalizeHandlerArguments < Input , Stream > ) : Promise < Output > ;
75
77
}
76
78
79
+ export interface BuildHandler <
80
+ Input extends object ,
81
+ Output extends object ,
82
+ Stream = Uint8Array
83
+ > extends FinalizeHandler < Input , Output , Stream > { }
84
+
77
85
/**
78
86
* A factory function that creates functions implementing the {Handler}
79
87
* interface.
@@ -95,7 +103,7 @@ export interface Middleware<Input extends object, Output extends object> {
95
103
* A factory function that creates functions implementing the {BuildHandler}
96
104
* interface.
97
105
*/
98
- export interface BuildMiddleware <
106
+ export interface SerializeMiddleware <
99
107
Input extends object ,
100
108
Output extends object ,
101
109
Stream = Uint8Array
@@ -107,12 +115,11 @@ export interface BuildMiddleware<
107
115
* @param context Invariant data and functions for use by the handler.
108
116
*/
109
117
(
110
- next : BuildHandler < Input , Output , Stream > ,
118
+ next : SerializeHandler < Input , Output , Stream > ,
111
119
context : HandlerExecutionContext
112
- ) : BuildHandler < Input , Output , Stream > ;
120
+ ) : SerializeHandler < Input , Output , Stream > ;
113
121
}
114
122
115
-
116
123
/**
117
124
* A factory function that creates functions implementing the {FinalizeHandler}
118
125
* interface.
@@ -134,6 +141,12 @@ export interface FinalizeMiddleware<
134
141
) : FinalizeHandler < Input , Output , Stream > ;
135
142
}
136
143
144
+ export interface BuildMiddleware <
145
+ Input extends object ,
146
+ Output extends object ,
147
+ Stream = Uint8Array
148
+ > extends FinalizeMiddleware < Input , Output , Stream > { }
149
+
137
150
/**
138
151
* A factory function that creates the terminal handler atop which a middleware
139
152
* stack sits.
@@ -147,20 +160,24 @@ export interface Terminalware<
147
160
) : FinalizeHandler < Input , Output , Stream > ;
148
161
}
149
162
150
- export type Step = 'initialize' | 'build' | 'finalize' ;
163
+ export type Step = 'initialize' | 'serialize' | ' build'| 'finalize' ;
151
164
152
165
export interface HandlerOptions {
153
166
/**
154
167
* Handlers are ordered using a "step" that describes the stage of command
155
168
* execution at which the handler will be executed. The available steps are:
156
169
*
157
- * - initialize: The input is being prepared and validated. Examples of
158
- * typical initialization tasks include injecting default options and
159
- * parameter validation.
160
- * - build: The input is being serialized into an HTTP request. The input
161
- * should not be altered in middleware occupying this step, as it may
162
- * have already been serialized into a request. Examples of typical
163
- * build tasks include request construction and injecting HTTP headers.
170
+ * - initialize: The input is being prepared. Examples of typical
171
+ * initialization tasks include injecting default options computing
172
+ * derived parameters.
173
+ * - serialize: The input is complete and ready to be serialized. Examples
174
+ * of typical serialization tasks include input validation and building
175
+ * an HTTP request from user input.
176
+ * - build: The input has been serialized into an HTTP request, but that
177
+ * request may require further modification. Any request alterations
178
+ * will be applied to all retries. Examples of typical build tasks
179
+ * include injecting HTTP headers that describe a stable aspect of the
180
+ * request, such as `Content-Length` or a body checksum.
164
181
* - finalize: The request is being prepared to be sent over the wire. The
165
182
* request in this stage should already be semantically complete and
166
183
* should therefore only be altered as match the recipient's
@@ -194,6 +211,10 @@ export interface HandlerOptions {
194
211
tags ?: { [ tag : string ] : any } ;
195
212
}
196
213
214
+ export interface SerializeHandlerOptions extends HandlerOptions {
215
+ step : 'serialize' ;
216
+ }
217
+
197
218
export interface BuildHandlerOptions extends HandlerOptions {
198
219
step : 'build' ;
199
220
}
@@ -215,12 +236,21 @@ export interface MiddlewareStack<
215
236
options ?: HandlerOptions & { step ?: 'initialize' }
216
237
) : void ;
217
238
239
+ /**
240
+ * Add middleware to the list to be executed during the "serialize" phase,
241
+ * optionally specifying a priority and tags.
242
+ */
243
+ add (
244
+ middleware : Middleware < Input , Output > ,
245
+ options : SerializeHandlerOptions
246
+ ) : void ;
247
+
218
248
/**
219
249
* Add middleware to the list to be executed during the "build" phase,
220
250
* optionally specifying a priority and tags.
221
251
*/
222
252
add (
223
- middleware : BuildMiddleware < Input , Output , Stream > ,
253
+ middleware : FinalizeMiddleware < Input , Output , Stream > ,
224
254
options : BuildHandlerOptions
225
255
) : void ;
226
256
0 commit comments