Skip to content

Commit 9fedaa9

Browse files
authored
feat: refactor middleware stack (#1398)
* feat(middleware-stack): refactor middleware stack implementation and interface * feat: update dedendents with updated middleware interface * feat(middleware-stack): make middleware stack a pluggable, address feedbacks BREAKING CHANGE: addRelativeTo() now doesn't require step in options. The middleware will be injected to the same step as the toMiddleware
1 parent 88e96e6 commit 9fedaa9

File tree

18 files changed

+574
-733
lines changed

18 files changed

+574
-733
lines changed

Diff for: packages/credential-provider-cognito-identity/src/fromCognitoIdentity.spec.ts

+16-16
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ describe("fromCognitoIdentity", () => {
3535
expiration,
3636
});
3737

38-
expect(send.mock.calls[0][0]).toEqual(
39-
new GetCredentialsForIdentityCommand({
40-
IdentityId: identityId,
41-
CustomRoleArn: "myArn",
42-
})
43-
);
38+
const sendParam = send.mock.calls[0][0];
39+
expect(sendParam).toEqual(expect.any(GetCredentialsForIdentityCommand));
40+
expect(sendParam.input).toEqual({
41+
IdentityId: identityId,
42+
CustomRoleArn: "myArn",
43+
});
4444
});
4545

4646
it("should resolve logins to string tokens and pass them to the service", async () => {
@@ -54,16 +54,16 @@ describe("fromCognitoIdentity", () => {
5454
},
5555
})();
5656

57-
expect(send.mock.calls[0][0]).toEqual(
58-
new GetCredentialsForIdentityCommand({
59-
IdentityId: identityId,
60-
CustomRoleArn: "myArn",
61-
Logins: {
62-
myDomain: "token",
63-
"www.amazon.com": "expiring nonce",
64-
},
65-
})
66-
);
57+
const sendParam = send.mock.calls[0][0];
58+
expect(sendParam).toEqual(expect.any(GetCredentialsForIdentityCommand));
59+
expect(sendParam.input).toMatchObject({
60+
IdentityId: identityId,
61+
CustomRoleArn: "myArn",
62+
Logins: {
63+
myDomain: "token",
64+
"www.amazon.com": "expiring nonce",
65+
},
66+
});
6767
});
6868

6969
it("should convert a GetCredentialsForIdentity response without credentials to a provider error", async () => {

Diff for: packages/credential-provider-cognito-identity/src/fromCognitoIdentityPool.spec.ts

+12-10
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ describe("fromCognitoIdentityPool", () => {
5656
});
5757

5858
expect(send.mock.calls.length).toBe(1);
59-
expect(send.mock.calls[0][0]).toEqual(new GetIdCommand({ IdentityPoolId: identityPoolId }));
59+
expect(send.mock.calls[0][0]).toEqual(expect.any(GetIdCommand));
60+
expect(send.mock.calls[0][0].input).toEqual({
61+
IdentityPoolId: identityPoolId,
62+
});
6063

6164
expect((fromCognitoIdentity as any).mock.calls.length).toBe(1);
6265
expect((fromCognitoIdentity as any).mock.calls[0][0]).toEqual({
@@ -76,15 +79,14 @@ describe("fromCognitoIdentityPool", () => {
7679
},
7780
})();
7881

79-
expect(send.mock.calls[0][0]).toEqual(
80-
new GetIdCommand({
81-
IdentityPoolId: identityPoolId,
82-
Logins: {
83-
myDomain: "token",
84-
"www.amazon.com": "expiring nonce",
85-
},
86-
})
87-
);
82+
expect(send.mock.calls[0][0]).toEqual(expect.any(GetIdCommand));
83+
expect(send.mock.calls[0][0].input).toEqual({
84+
IdentityPoolId: identityPoolId,
85+
Logins: {
86+
myDomain: "token",
87+
"www.amazon.com": "expiring nonce",
88+
},
89+
});
8890
});
8991

9092
it("should not invoke GetId a second time once an identityID has been fetched", async () => {

Diff for: packages/eventstream-handler-node/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"@aws-sdk/util-utf8-node": "1.0.0-gamma.4",
2626
"@types/jest": "^26.0.4",
2727
"jest": "^26.1.0",
28-
"typescript": "~3.4.0"
28+
"typescript": "~3.9.3"
2929
},
3030
"engines": {
3131
"node": ">= 10.0.0"

Diff for: packages/middleware-bucket-endpoint/src/bucketEndpointMiddleware.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { MiddlewareStack } from "@aws-sdk/middleware-stack";
1+
import { constructStack } from "@aws-sdk/middleware-stack";
22
import { HttpRequest } from "@aws-sdk/protocol-http";
33

44
import { bucketEndpointMiddleware, bucketEndpointMiddlewareOptions } from "./bucketEndpointMiddleware";
@@ -130,7 +130,7 @@ describe("bucketEndpointMiddleware", () => {
130130
});
131131

132132
it("should be inserted before 'hostheaderMiddleware' if exists", async () => {
133-
const stack = new MiddlewareStack();
133+
const stack = constructStack();
134134
const mockHostheaderMiddleware = (next: any) => (args: any) => {
135135
args.request.arr.push("two");
136136
return next(args);

Diff for: packages/middleware-bucket-endpoint/src/bucketEndpointMiddleware.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@ import { HttpRequest } from "@aws-sdk/protocol-http";
22
import {
33
BuildHandler,
44
BuildHandlerArguments,
5-
BuildHandlerOptions,
65
BuildHandlerOutput,
76
BuildMiddleware,
87
MetadataBearer,
98
Pluggable,
10-
RelativeLocation,
9+
RelativeMiddlewareOptions,
1110
} from "@aws-sdk/types";
1211

1312
import { bucketHostname } from "./bucketHostname";
@@ -49,8 +48,7 @@ export function bucketEndpointMiddleware(options: BucketEndpointResolvedConfig):
4948
};
5049
}
5150

52-
export const bucketEndpointMiddlewareOptions: BuildHandlerOptions & RelativeLocation<any, any> = {
53-
step: "build",
51+
export const bucketEndpointMiddlewareOptions: RelativeMiddlewareOptions = {
5452
tags: ["BUCKET_ENDPOINT"],
5553
name: "bucketEndpointMiddleware",
5654
relation: "before",

Diff for: packages/middleware-eventstream/src/handling-middleware.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { HttpRequest } from "@aws-sdk/protocol-http";
2-
import { FinalizeRequestHandlerOptions, FinalizeRequestMiddleware, RelativeLocation } from "@aws-sdk/types";
2+
import { FinalizeRequestMiddleware, RelativeMiddlewareOptions } from "@aws-sdk/types";
33

44
import { EventStreamResolvedConfig } from "./configuration";
55

@@ -11,8 +11,7 @@ export const eventStreamHandlingMiddleware = (
1111
return options.eventStreamPayloadHandler.handle(next, args, context);
1212
};
1313

14-
export const eventStreamHandlingMiddlewareOptions: FinalizeRequestHandlerOptions & RelativeLocation<any, any> = {
15-
step: "finalizeRequest",
14+
export const eventStreamHandlingMiddlewareOptions: RelativeMiddlewareOptions = {
1615
tags: ["EVENT_STREAM", "SIGNATURE", "HANDLE"],
1716
name: "eventStreamHandlingMiddleware",
1817
relation: "after",

Diff for: packages/middleware-sdk-s3-control/src/prepend-account-id.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@ import { HttpRequest } from "@aws-sdk/protocol-http";
22
import {
33
BuildHandler,
44
BuildHandlerArguments,
5-
BuildHandlerOptions,
65
BuildHandlerOutput,
76
BuildMiddleware,
87
MetadataBearer,
98
Pluggable,
10-
RelativeLocation,
9+
RelativeMiddlewareOptions,
1110
} from "@aws-sdk/types";
1211

1312
export function prependAccountIdMiddleware(): BuildMiddleware<any, any> {
@@ -40,8 +39,7 @@ export function prependAccountIdMiddleware(): BuildMiddleware<any, any> {
4039
};
4140
}
4241

43-
export const prependAccountIdMiddlewareOptions: BuildHandlerOptions & RelativeLocation<any, any> = {
44-
step: "build",
42+
export const prependAccountIdMiddlewareOptions: RelativeMiddlewareOptions = {
4543
tags: ["PREPEND_ACCOUNT_ID_MIDDLEWARE"],
4644
name: "prependAccountIdMiddleware",
4745
relation: "before",

Diff for: packages/middleware-sdk-transcribe-streaming/src/middleware-endpoint.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ import { HttpRequest } from "@aws-sdk/protocol-http";
22
import {
33
BuildHandler,
44
BuildHandlerArguments,
5-
BuildHandlerOptions,
65
BuildMiddleware,
7-
RelativeLocation,
6+
RelativeMiddlewareOptions,
87
RequestHandler,
98
} from "@aws-sdk/types";
109

@@ -54,8 +53,7 @@ export const websocketURLMiddleware = (options: {
5453
return next(args);
5554
};
5655

57-
export const websocketURLMiddlewareOptions: BuildHandlerOptions & RelativeLocation<any, any> = {
58-
step: "build",
56+
export const websocketURLMiddlewareOptions: RelativeMiddlewareOptions = {
5957
name: "websocketURLMiddleware",
6058
tags: ["WEBSOCKET", "EVENT_STREAM"],
6159
relation: "after",

Diff for: packages/middleware-signing/src/middleware.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ import {
33
FinalizeHandler,
44
FinalizeHandlerArguments,
55
FinalizeHandlerOutput,
6-
FinalizeRequestHandlerOptions,
76
FinalizeRequestMiddleware,
87
Pluggable,
9-
RelativeLocation,
8+
RelativeMiddlewareOptions,
109
} from "@aws-sdk/types";
1110

1211
import { AwsAuthResolvedConfig } from "./configurations";
@@ -43,9 +42,8 @@ export function awsAuthMiddleware<Input extends object, Output extends object>(
4342
};
4443
}
4544

46-
export const awsAuthMiddlewareOptions: FinalizeRequestHandlerOptions & RelativeLocation<any, any> = {
45+
export const awsAuthMiddlewareOptions: RelativeMiddlewareOptions = {
4746
name: "awsAuthMiddleware",
48-
step: "finalizeRequest",
4947
tags: ["SIGNATURE", "AWSAUTH"],
5048
relation: "after",
5149
toMiddleware: "retryMiddleware",

0 commit comments

Comments
 (0)