Skip to content

Commit a51ca3b

Browse files
jeskewsrchase
authored andcommitted
Create build types package (#65)
* Move middlewarestack interface to @aws/types * Add configuration types * Create a package to house types used at build time but not at runtime and relocate model parser types there
1 parent c2398a2 commit a51ca3b

File tree

1 file changed

+5
-87
lines changed

1 file changed

+5
-87
lines changed

packages/middleware-stack/src/index.ts

Lines changed: 5 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import {
22
Handler,
3+
HandlerOptions,
34
Middleware,
5+
MiddlewareStack as IMiddlewareStack,
46
HandlerExecutionContext,
57
} from '@aws/types';
68

@@ -15,69 +17,12 @@ interface HandlerListEntry<
1517
tags?: Set<string>;
1618
}
1719

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+
{
7123
private readonly entries: Array<HandlerListEntry<T>> = [];
7224
private sorted: boolean = false;
7325

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-
*/
8126
add(
8227
middleware: Middleware<T>,
8328
{
@@ -95,21 +40,12 @@ export class MiddlewareStack<T extends Handler<any, any>> {
9540
});
9641
}
9742

98-
/**
99-
* Create a shallow clone of this list. Step bindings and handler priorities
100-
* and tags are preserved in the copy.
101-
*/
10243
clone(): MiddlewareStack<T> {
10344
const clone = new MiddlewareStack<T>();
10445
clone.entries.push(...this.entries);
10546
return clone;
10647
}
10748

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-
*/
11349
concat(
11450
from: MiddlewareStack<T>
11551
): MiddlewareStack<T> {
@@ -118,14 +54,6 @@ export class MiddlewareStack<T extends Handler<any, any>> {
11854
return clone;
11955
}
12056

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-
*/
12957
remove(toRemove: Middleware<T>|string): boolean {
13058
const {length} = this.entries;
13159
if (typeof toRemove === 'string') {
@@ -137,16 +65,6 @@ export class MiddlewareStack<T extends Handler<any, any>> {
13765
return this.entries.length < length;
13866
}
13967

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-
*/
15068
resolve(handler: T, context: HandlerExecutionContext): T {
15169
if (!this.sorted) {
15270
this.sort();

0 commit comments

Comments
 (0)