Skip to content

Commit 7235e25

Browse files
AllanZhengYPsrchase
authored andcommitted
feat: standardize plugins (#422)
1 parent 87b0aee commit 7235e25

30 files changed

+923
-123
lines changed

packages/config-resolver/src/EndpointsConfig.ts

Lines changed: 42 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -14,51 +14,48 @@ export function normalizeEndpoint(
1414
return endpoint!;
1515
}
1616

17-
export namespace EndpointsConfig {
18-
export interface Input {
19-
/**
20-
* The fully qualified endpoint of the webservice. This is only required when using a custom endpoint (for example, when using a local version of S3).
21-
*/
22-
endpoint?: string | Endpoint | Provider<Endpoint>;
17+
export interface EndpointsConfigInput {
18+
/**
19+
* The fully qualified endpoint of the webservice. This is only required when using a custom endpoint (for example, when using a local version of S3).
20+
*/
21+
endpoint?: string | Endpoint | Provider<Endpoint>;
2322

24-
/**
25-
* The endpoint provider to call if no endpoint is provided
26-
*/
27-
endpointProvider?: any;
23+
/**
24+
* The endpoint provider to call if no endpoint is provided
25+
*/
26+
endpointProvider?: any;
2827

29-
/**
30-
* Whether TLS is enabled for requests.
31-
*/
32-
tls?: boolean;
33-
}
34-
interface PreviouslyResolved {
35-
urlParser: UrlParser;
36-
region: Provider<string>;
37-
service: string;
38-
}
39-
export interface Resolved extends Required<Input> {
40-
endpoint: Provider<Endpoint>;
41-
}
42-
export function resolve<T>(
43-
input: T & Input & PreviouslyResolved
44-
): T & Resolved {
45-
const tls = input.tls || true;
46-
const defaultProvider = (tls: boolean, region: string) => ({
47-
protocol: tls ? "https:" : "http:",
48-
path: "/",
49-
hostname: `${input.service}.${region}.amazonaws.com`
50-
});
51-
const endpointProvider = input.endpointProvider || defaultProvider;
52-
let endpoint: Provider<Endpoint> = input.endpoint
53-
? normalizeEndpoint(input.endpoint, input.urlParser)
54-
: () => input.region().then(region => endpointProvider(tls, region));
55-
return {
56-
...input,
57-
endpointProvider,
58-
endpoint,
59-
tls
60-
};
61-
}
28+
/**
29+
* Whether TLS is enabled for requests.
30+
*/
31+
tls?: boolean;
32+
}
33+
interface PreviouslyResolved {
34+
urlParser: UrlParser;
35+
region: Provider<string>;
36+
service: string;
37+
}
38+
export interface EndpointsConfigResolved
39+
extends Required<EndpointsConfigInput> {
40+
endpoint: Provider<Endpoint>;
41+
}
42+
export function resolveEndpointsConfig<T>(
43+
input: T & EndpointsConfigInput & PreviouslyResolved
44+
): T & EndpointsConfigResolved {
45+
const tls = input.tls || true;
46+
const defaultProvider = (tls: boolean, region: string) => ({
47+
protocol: tls ? "https:" : "http:",
48+
path: "/",
49+
hostname: `${input.service}.${region}.amazonaws.com`
50+
});
51+
const endpointProvider = input.endpointProvider || defaultProvider;
52+
const endpoint: Provider<Endpoint> = input.endpoint
53+
? normalizeEndpoint(input.endpoint, input.urlParser)
54+
: () => input.region().then(region => endpointProvider(tls, region));
55+
return {
56+
...input,
57+
endpointProvider,
58+
endpoint,
59+
tls
60+
};
6261
}
63-
//export separately for showing comment block in Intellisense
64-
export type EndpointsConfigInput = EndpointsConfig.Input;
Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
import { Protocol, HttpOptions } from "@aws-sdk/types";
22
import { HttpHandler, HttpRequest, HttpResponse } from "@aws-sdk/protocol-http";
33

4-
export namespace ProtocolConfig {
5-
export interface Input {
6-
/**
7-
* The serializing protocol to used in request
8-
*/
9-
protocol?: Protocol<any, any>;
10-
}
11-
interface PreviouslyResolved {
12-
httpHandler: HttpHandler;
13-
protocolDefaultProvider: (
14-
handler: HttpHandler
15-
) => Protocol<HttpRequest, HttpResponse, HttpOptions>;
16-
}
17-
export type Resolved = Required<Input>;
18-
export function resolve<T>(
19-
input: T & Input & PreviouslyResolved
20-
): T & Resolved {
21-
return {
22-
...input,
23-
protocol:
24-
input.protocol || input.protocolDefaultProvider(input.httpHandler)
25-
};
26-
}
4+
export interface ClientProtocolConfigInput {
5+
/**
6+
* The serializing protocol to used in request
7+
*/
8+
protocol?: Protocol<any, any>;
9+
}
10+
interface PreviouslyResolved {
11+
httpHandler: HttpHandler;
12+
protocolDefaultProvider: (
13+
handler: HttpHandler
14+
) => Protocol<HttpRequest, HttpResponse, HttpOptions>;
15+
}
16+
export type ClientProtocolConfigResolved = Required<ClientProtocolConfigInput>;
17+
export function resolveClientProtocolConfig<T>(
18+
input: T & ClientProtocolConfigInput & PreviouslyResolved
19+
): T & ClientProtocolConfigResolved {
20+
return {
21+
...input,
22+
protocol: input.protocol || input.protocolDefaultProvider(input.httpHandler)
23+
};
24+
}
25+
export function destroyClientProtocolConfig(
26+
config: ClientProtocolConfigResolved
27+
): void {
28+
config.protocol.destroy();
2729
}
28-
//export separately for showing comment block in Intellisense
29-
export type ProtocolConfigInput = ProtocolConfig.Input;

packages/config-resolver/src/RegionConfig.ts

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,26 @@
11
import { Provider } from "@aws-sdk/types";
22

3-
export namespace RegionConfiguration {
4-
export interface Input {
5-
/**
6-
* The AWS region to which this client will send requests
7-
*/
8-
region?: string | Provider<string>;
9-
}
10-
interface PreviouslyResolved {
11-
regionDefaultProvider: (input: any) => Provider<string>;
12-
}
13-
export interface Resolved {
14-
region: Provider<string>;
15-
}
16-
export function resolve<T>(
17-
input: T & Input & PreviouslyResolved
18-
): T & Resolved {
19-
let region = input.region || input.regionDefaultProvider(input as any);
20-
return {
21-
...input,
22-
region: normalizeRegion(region)
23-
};
24-
}
3+
export interface RegionConfigInput {
4+
/**
5+
* The AWS region to which this client will send requests
6+
*/
7+
region?: string | Provider<string>;
8+
}
9+
interface PreviouslyResolved {
10+
regionDefaultProvider: (input: any) => Provider<string>;
11+
}
12+
export interface RegionConfigResolved {
13+
region: Provider<string>;
14+
}
15+
export function resolveRegionConfig<T>(
16+
input: T & RegionConfigInput & PreviouslyResolved
17+
): T & RegionConfigResolved {
18+
let region = input.region || input.regionDefaultProvider(input as any);
19+
return {
20+
...input,
21+
region: normalizeRegion(region)
22+
};
2523
}
26-
//export separately for showing comment block in Intellisense
27-
export type RegionConfigurationInput = RegionConfiguration.Input;
2824

2925
function normalizeRegion(region: string | Provider<string>): Provider<string> {
3026
if (typeof region === "string") {

packages/middleware-content-length/src/index.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,13 @@ export function contentLengthMiddleware(
4444
};
4545
}
4646

47-
export const contentLengthPlugin = (options: {
47+
export const getContentLengthPlugin = (options: {
4848
bodyLengthChecker: BodyLengthCalculator;
49-
}): Pluggable<any, any> => clientStack => {
50-
clientStack.add(contentLengthMiddleware(options.bodyLengthChecker), {
51-
step: "build",
52-
tags: { SET_CONTENT_LENGTH: true }
53-
});
54-
};
49+
}): Pluggable<any, any> => ({
50+
applyToStack: clientStack => {
51+
clientStack.add(contentLengthMiddleware(options.bodyLengthChecker), {
52+
step: "build",
53+
tags: { SET_CONTENT_LENGTH: true }
54+
});
55+
}
56+
});

packages/middleware-retry/.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/node_modules/
2+
/build/
3+
/coverage/
4+
/docs/
5+
*.tsbuildinfo
6+
*.tgz
7+
*.log
8+
package-lock.json

packages/middleware-retry/.npmignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/src/
2+
/coverage/
3+
/docs/
4+
tsconfig.test.json
5+
*.tsbuildinfo
6+
7+
*.spec.js
8+
*.spec.d.ts
9+
*.spec.js.map
10+
11+
*.fixture.js
12+
*.fixture.d.ts
13+
*.fixture.js.map
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# Change Log
2+
3+
All notable changes to this project will be documented in this file.
4+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5+
6+
# [0.1.0-preview.7](https://github.com/aws/aws-sdk-js-v3/compare/@aws-sdk/[email protected]...@aws-sdk/[email protected]) (2019-10-30)
7+
8+
9+
10+
# 0.3.0 (2019-09-09)
11+
12+
13+
### Features
14+
15+
* commit all clients ([#324](https://github.com/aws/aws-sdk-js-v3/issues/324)) ([cb268ed](https://github.com/aws/aws-sdk-js-v3/commit/cb268ed))
16+
17+
18+
19+
# 0.2.0 (2019-07-12)
20+
21+
22+
### Features
23+
24+
* add npm badges for individual packages ([#251](https://github.com/aws/aws-sdk-js-v3/issues/251)) ([8adc10c](https://github.com/aws/aws-sdk-js-v3/commit/8adc10c))
25+
* update jest v20 to v24 ([#243](https://github.com/aws/aws-sdk-js-v3/issues/243)) ([1e156ab](https://github.com/aws/aws-sdk-js-v3/commit/1e156ab))
26+
27+
28+
29+
# 0.1.0 (2019-04-19)
30+
31+
32+
33+
34+
35+
# [0.1.0-preview.6](https://github.com/aws/aws-sdk-js-v3/compare/@aws-sdk/[email protected]...@aws-sdk/[email protected]) (2019-10-29)
36+
37+
38+
39+
# 0.3.0 (2019-09-09)
40+
41+
42+
### Features
43+
44+
* commit all clients ([#324](https://github.com/aws/aws-sdk-js-v3/issues/324)) ([cb268ed](https://github.com/aws/aws-sdk-js-v3/commit/cb268ed))
45+
46+
47+
48+
# 0.2.0 (2019-07-12)
49+
50+
51+
### Features
52+
53+
* add npm badges for individual packages ([#251](https://github.com/aws/aws-sdk-js-v3/issues/251)) ([8adc10c](https://github.com/aws/aws-sdk-js-v3/commit/8adc10c))
54+
* update jest v20 to v24 ([#243](https://github.com/aws/aws-sdk-js-v3/issues/243)) ([1e156ab](https://github.com/aws/aws-sdk-js-v3/commit/1e156ab))
55+
56+
57+
58+
# 0.1.0 (2019-04-19)
59+
60+
61+
62+
63+
64+
# [0.1.0-preview.5](https://github.com/aws/aws-sdk-js-v3/compare/@aws-sdk/[email protected]...@aws-sdk/[email protected]) (2019-09-09)
65+
66+
67+
### Features
68+
69+
* commit all clients ([#324](https://github.com/aws/aws-sdk-js-v3/issues/324)) ([cb268ed](https://github.com/aws/aws-sdk-js-v3/commit/cb268ed))
70+
71+
72+
73+
# 0.2.0 (2019-07-12)
74+
75+
76+
### Features
77+
78+
* add npm badges for individual packages ([#251](https://github.com/aws/aws-sdk-js-v3/issues/251)) ([8adc10c](https://github.com/aws/aws-sdk-js-v3/commit/8adc10c))
79+
* update jest v20 to v24 ([#243](https://github.com/aws/aws-sdk-js-v3/issues/243)) ([1e156ab](https://github.com/aws/aws-sdk-js-v3/commit/1e156ab))
80+
81+
82+
83+
# 0.1.0 (2019-04-19)
84+
85+
86+
87+
88+
89+
# [0.1.0-preview.4](https://github.com/aws/aws-sdk-js-v3/compare/@aws-sdk/[email protected]...@aws-sdk/[email protected]) (2019-07-12)
90+
91+
92+
### Features
93+
94+
* add npm badges for individual packages ([#251](https://github.com/aws/aws-sdk-js-v3/issues/251)) ([8adc10c](https://github.com/aws/aws-sdk-js-v3/commit/8adc10c))
95+
* update jest v20 to v24 ([#243](https://github.com/aws/aws-sdk-js-v3/issues/243)) ([1e156ab](https://github.com/aws/aws-sdk-js-v3/commit/1e156ab))
96+
97+
98+
99+
# 0.1.0 (2019-04-19)
100+
101+
102+
103+
104+
105+
# [0.1.0-preview.3](https://github.com/aws/aws-sdk-js-v3/compare/@aws-sdk/[email protected]...@aws-sdk/[email protected]) (2019-04-19)
106+
107+
**Note:** Version bump only for package @aws-sdk/retry-middleware
108+
109+
# [0.1.0-preview.2](https://github.com/aws/aws-sdk-js-v3/compare/@aws-sdk/[email protected]...@aws-sdk/[email protected]) (2019-03-27)
110+
111+
**Note:** Version bump only for package @aws-sdk/retry-middleware

0 commit comments

Comments
 (0)