1
1
import {
2
2
Handler ,
3
+ HandlerOptions ,
3
4
Middleware ,
5
+ MiddlewareStack as IMiddlewareStack ,
4
6
HandlerExecutionContext ,
5
7
} from '@aws/types' ;
6
8
@@ -15,69 +17,12 @@ interface HandlerListEntry<
15
17
tags ?: Set < string > ;
16
18
}
17
19
18
- export interface HandlerOptions {
19
- /**
20
- * Handlers are ordered using a "step" that describes the stage of command
21
- * execution at which the handler will be executed. The available steps are:
22
- *
23
- * - initialize: The input is being prepared and validated. Examples of
24
- * typical initialization tasks include injecting default options and
25
- * parameter validation.
26
- * - build: The input is being serialized into an HTTP request. The input
27
- * should not be altered in middleware occupying this step, as it may
28
- * have already been serialized into a request. Examples of typical
29
- * build tasks include request construction and injecting HTTP headers.
30
- * - finalize: The request is being prepared to be sent over the wire. The
31
- * request in this stage should already be semantically complete and
32
- * should therefore only be altered as match the recipient's
33
- * expectations. Examples of typical finalization tasks include request
34
- * signing and injecting hop-by-hop headers.
35
- *
36
- * Unlike initialization and build handlers, which are executed once
37
- * per operation execution, finalization handlers will be executed for
38
- * each HTTP request sent.
39
- *
40
- * @default 'build'
41
- */
42
- step ?: Step ;
43
-
44
- /**
45
- * A number that specifies how early in a given step of the middleware stack
46
- * a handler should be executed. Higher numeric priorities will be executed
47
- * earlier.
48
- *
49
- * @default 0
50
- */
51
- priority ?: number ;
52
-
53
- /**
54
- * A set of strings that identify the general purpose or important
55
- * characteristics of a given handler.
56
- */
57
- tags ?: Set < string > ;
58
- }
59
-
60
- /**
61
- * Builds a single handler function from zero or more middleware classes and a
62
- * core handler. The core handler is meant to send command objects to AWS
63
- * services and return promises that will resolve with the operation result or
64
- * be rejected with an error.
65
- *
66
- * When a composed handler is invoked, the arguments will pass through all
67
- * middleware in a defined order, and the return from the innermost handler will
68
- * pass through all middleware in the reverse of that order.
69
- */
70
- export class MiddlewareStack < T extends Handler < any , any > > {
20
+ export class MiddlewareStack < T extends Handler < any , any , any > > implements
21
+ IMiddlewareStack < T >
22
+ {
71
23
private readonly entries : Array < HandlerListEntry < T > > = [ ] ;
72
24
private sorted : boolean = false ;
73
25
74
- /**
75
- * Add middleware to the list, optionally specifying a step, priority, and
76
- * tags.
77
- *
78
- * Middleware registered at the same step and with the same priority may be
79
- * executed in any order.
80
- */
81
26
add (
82
27
middleware : Middleware < T > ,
83
28
{
@@ -95,21 +40,12 @@ export class MiddlewareStack<T extends Handler<any, any>> {
95
40
} ) ;
96
41
}
97
42
98
- /**
99
- * Create a shallow clone of this list. Step bindings and handler priorities
100
- * and tags are preserved in the copy.
101
- */
102
43
clone ( ) : MiddlewareStack < T > {
103
44
const clone = new MiddlewareStack < T > ( ) ;
104
45
clone . entries . push ( ...this . entries ) ;
105
46
return clone ;
106
47
}
107
48
108
- /**
109
- * Create a list containing the middlewares in this list as well as the
110
- * middlewares in the `from` list. Neither source is modified, and step
111
- * bindings and handler priorities and tags are preserved in the copy.
112
- */
113
49
concat (
114
50
from : MiddlewareStack < T >
115
51
) : MiddlewareStack < T > {
@@ -118,14 +54,6 @@ export class MiddlewareStack<T extends Handler<any, any>> {
118
54
return clone ;
119
55
}
120
56
121
- /**
122
- * Removes middleware from the stack.
123
- *
124
- * If a string is provided, any entry in the stack whose tags contain that
125
- * string will be removed from the stack.
126
- *
127
- * If a middleware class is provided, all usages thereof will be removed.
128
- */
129
57
remove ( toRemove : Middleware < T > | string ) : boolean {
130
58
const { length} = this . entries ;
131
59
if ( typeof toRemove === 'string' ) {
@@ -137,16 +65,6 @@ export class MiddlewareStack<T extends Handler<any, any>> {
137
65
return this . entries . length < length ;
138
66
}
139
67
140
- /**
141
- * Builds a single handler function from zero or more middleware classes and
142
- * a core handler. The core handler is meant to send command objects to AWS
143
- * services and return promises that will resolve with the operation result
144
- * or be rejected with an error.
145
- *
146
- * When a composed handler is invoked, the arguments will pass through all
147
- * middleware in a defined order, and the return from the innermost handler
148
- * will pass through all middleware in the reverse of that order.
149
- */
150
68
resolve ( handler : T , context : HandlerExecutionContext ) : T {
151
69
if ( ! this . sorted ) {
152
70
this . sort ( ) ;
0 commit comments