Skip to content

Commit 2a4e609

Browse files
committed
feat: support pluggable runtime config
* export runtimeConfig.runtime.ts to manually set the client to be compatible with specific runtime * get rid of rollup, instead using browser property to swap runtime config * add endpoint to the serializer utilities and insert it when building a request
1 parent 1bb6e37 commit 2a4e609

File tree

29 files changed

+378
-533
lines changed

29 files changed

+378
-533
lines changed
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
/coverage/
22
/docs/
3-
*.ts
4-
!*.d.ts
53
tsconfig.test.json
64
*.tsbuildinfo

clients/node/client-rds-data-node/RDSDataClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { awsAuthPlugin, AwsAuthConfiguration } from "@aws-sdk/signing-middleware
55
import {
66
RDSDataConfiguration,
77
RDSDataResolvedConfiguration,
8-
RDSRuntimeConfiguration
98
} from "./RDSDataConfiguration";
9+
import { RDSRuntimeConfiguration } from './runtimeConfig';
1010
import { RegionConfiguration, EndpointsConfig, ProtocolConfig } from '@aws-sdk/config-resolver';
1111
import { HttpOptions, MetadataBearer } from '@aws-sdk/types';
1212
import { Client as SmithyClient } from "@aws-sdk/smithy-client";
Lines changed: 106 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,125 @@
1-
import { defaultProvider as credentialDefaultProvider } from "@aws-sdk/credential-provider-node";
2-
import { Hash } from "@aws-sdk/hash-node";
3-
import { NodeHttpHandler } from "@aws-sdk/node-http-handler";
4-
import { defaultProvider as regionDefaultProvider } from "@aws-sdk/region-provider";
5-
import { parseUrl } from "@aws-sdk/url-parser-node";
6-
import { calculateBodyLength } from "@aws-sdk/util-body-length-node";
7-
import { streamCollector } from '@aws-sdk/stream-collector-node';
8-
import { RestJsonProtocol } from "@aws-sdk/protocol-rest-json";
9-
import { fromUtf8, toUtf8 } from '@aws-sdk/util-utf8-node';
10-
import { fromBase64, toBase64 } from '@aws-sdk/util-base64-node';
11-
import { defaultUserAgent } from '@aws-sdk/util-user-agent-node';
12-
import { AwsAuthConfiguration, AwsAuthConfigurationInput } from '@aws-sdk/signing-middleware';
13-
import { UserAgentConfig, UserAgentConfigInput } from '@aws-sdk/middleware-user-agent';
14-
import { RetryConfig, RetryConfigInput } from '@aws-sdk/retry-middleware';
15-
import { name, version } from './package.json';
1+
import {
2+
AwsAuthConfiguration,
3+
AwsAuthConfigurationInput
4+
} from "@aws-sdk/signing-middleware";
5+
import {
6+
UserAgentConfig,
7+
UserAgentConfigInput
8+
} from "@aws-sdk/middleware-user-agent";
9+
import { RetryConfig, RetryConfigInput } from "@aws-sdk/retry-middleware";
1610
import {
1711
RegionConfiguration,
1812
RegionConfigurationInput,
1913
EndpointsConfig,
2014
EndpointsConfigInput,
2115
ProtocolConfig,
22-
ProtocolConfigInput,
23-
AWSClientRuntimeConfiguration
24-
} from '@aws-sdk/config-resolver';
25-
26-
export type AWSClientRuntimeResolvedConfiguration = Required<AWSClientRuntimeConfiguration>;
27-
28-
export const RDSRuntimeConfiguration: AWSClientRuntimeResolvedConfiguration = {
29-
protocolDefaultProvider: (handler) => new RestJsonProtocol(handler),
30-
signingName: "rds-data",
31-
service: "rds-data",
32-
httpHandler: new NodeHttpHandler(),
33-
sha256: Hash.bind(null, "sha256"),
34-
credentialDefaultProvider,
35-
regionDefaultProvider,
36-
urlParser: parseUrl,
37-
bodyLengthChecker: calculateBodyLength,
38-
streamCollector,
39-
base64Decoder: fromBase64,
40-
base64Encoder: toBase64,
41-
utf8Decoder: fromUtf8,
42-
utf8Encoder: toUtf8,
43-
defaultUserAgent: defaultUserAgent(name, version)
16+
ProtocolConfigInput
17+
} from "@aws-sdk/config-resolver";
18+
import {
19+
Credentials,
20+
Provider,
21+
HashConstructor,
22+
UrlParser,
23+
Protocol,
24+
StreamCollector,
25+
Decoder,
26+
Encoder
27+
} from "@aws-sdk/types";
28+
import { HttpHandler, HttpRequest, HttpResponse } from "@aws-sdk/protocol-http";
29+
30+
export interface RDSDataRuntimeDependencies {
31+
/**
32+
* The HTTP handler to use. Fetch in browser and Https in Nodejs
33+
*/
34+
httpHandler?: HttpHandler;
35+
36+
/**
37+
* A constructor for a class implementing the @aws-sdk/types.Hash interface that computes the SHA-256 HMAC or checksum of a string or binary buffer
38+
*/
39+
sha256?: HashConstructor;
40+
41+
/**
42+
* Default credentials provider; Not available in browser runtime
43+
*/
44+
credentialDefaultProvider?: (input: any) => Provider<Credentials>;
45+
46+
/**
47+
* Provider function that return promise of a region string
48+
*/
49+
regionDefaultProvider?: (input: any) => Provider<string>;
50+
51+
/**
52+
* The function that will be used to convert strings into HTTP endpoints
53+
*/
54+
urlParser?: UrlParser;
55+
56+
/**
57+
* A function that can calculate the length of a request body.
58+
*/
59+
bodyLengthChecker?: (body: any) => number | undefined;
60+
61+
/**
62+
* A function that converts a stream into an array of bytes.
63+
*/
64+
streamCollector?: StreamCollector;
65+
66+
/**
67+
* The function that will be used to convert a base64-encoded string to a byte array
68+
*/
69+
base64Decoder?: Decoder;
70+
71+
/**
72+
* The function that will be used to convert binary data to a base64-encoded string
73+
*/
74+
base64Encoder?: Encoder;
75+
76+
/**
77+
* The function that will be used to convert a UTF8-encoded string to a byte array
78+
*/
79+
utf8Decoder?: Decoder;
80+
81+
/**
82+
* The function that will be used to convert binary data to a UTF-8 encoded string
83+
*/
84+
utf8Encoder?: Encoder;
85+
86+
/**
87+
* The function that will be used to populate default value in 'User-Agent' header
88+
*/
89+
defaultUserAgent?: string;
90+
91+
/**
92+
* The function that will be used to populate serializing protocol
93+
*/
94+
protocolDefaultProvider?: (
95+
handler: HttpHandler
96+
) => Protocol<HttpRequest, HttpResponse>;
97+
98+
/**
99+
* The service name with which to sign requests.
100+
*/
101+
signingName?: string;
102+
103+
/**
104+
* The service name with which to construct endpoints.
105+
*/
106+
service?: string;
44107
}
45108

46-
export type RDSDataConfiguration = AWSClientRuntimeConfiguration &
109+
export type RDSDataConfiguration = RDSDataRuntimeDependencies &
47110
AwsAuthConfigurationInput &
48111
RegionConfigurationInput &
49112
RetryConfigInput &
50113
EndpointsConfigInput &
51114
ProtocolConfigInput &
52-
UserAgentConfigInput
115+
UserAgentConfigInput;
53116

54-
export type RDSDataResolvedConfiguration = AWSClientRuntimeResolvedConfiguration &
117+
export type RDSDataResolvedConfiguration = Required<
118+
RDSDataRuntimeDependencies
119+
> &
55120
AwsAuthConfiguration.Resolved &
56121
RegionConfiguration.Resolved &
57122
RetryConfig.Resolved &
58123
EndpointsConfig.Resolved &
59124
ProtocolConfig.Resolved &
60-
UserAgentConfig.Resolved
125+
UserAgentConfig.Resolved;

clients/node/client-rds-data-node/index.browser.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

clients/node/client-rds-data-node/package.json

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,18 @@
1414
"test": "exit 0",
1515
"smoke-test": "npm run pretest && node ./test/smoke/index.spec.js",
1616
"build:es": "tsc -p tsconfig.es.json",
17-
"build:browser": "rollup -c",
18-
"build": "yarn pretest && yarn build:es && yarn build:browser"
17+
"build": "yarn pretest && yarn build:es"
1918
},
20-
"main": "./index.js",
19+
"main": "./dist/cjs/index.js",
2120
"types": "./types/index.d.ts",
2221
"author": {
2322
"name": "AWS SDK for JavaScript Team",
2423
"url": "https://aws.amazon.com/javascript/"
2524
},
2625
"module": "./dist/es/index.js",
27-
"browser": "./dist/browser/rds-data-browser.js",
26+
"browser": {
27+
"./runtimeConfig": "./runtimeConfig.browser"
28+
},
2829
"sideEffects": false,
2930
"license": "Apache-2.0",
3031
"dependencies": {
@@ -47,6 +48,7 @@
4748
"@aws-sdk/signature-v4": "^0.1.0-preview.7",
4849
"@aws-sdk/signing-middleware": "^0.1.0-preview.7",
4950
"@aws-sdk/stream-collector-node": "^0.1.0-preview.6",
51+
"@aws-sdk/stream-collector-browser": "^0.1.0-preview.5",
5052
"@aws-sdk/types": "^0.1.0-preview.5",
5153
"@aws-sdk/url-parser-browser": "^0.1.0-preview.5",
5254
"@aws-sdk/url-parser-node": "^0.1.0-preview.5",
@@ -64,11 +66,7 @@
6466
"@aws-sdk/client-documentation-generator": "^0.1.0-preview.3",
6567
"@types/node": "^10.0.0",
6668
"rimraf": "^2.6.2",
67-
"rollup-plugin-json": "^4.0.0",
68-
"rollup-plugin-node-resolve": "^5.2.0",
69-
"rollup-plugin-replace": "^2.2.0",
70-
"rollup-plugin-sourcemaps": "^0.4.2",
7169
"typedoc": "^0.14.2",
7270
"typescript": "^3.7.0-dev.20190926"
7371
}
74-
}
72+
}

clients/node/client-rds-data-node/protocol/AwsRestJson1_1.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ import {
1212
} from "../models/rdsdataservice";
1313
import { HttpRequest, HttpResponse } from "@aws-sdk/protocol-http";
1414
import { SerializerUtils, DeserializerUtils } from "@aws-sdk/types";
15-
import { ResponseMetadata } from "@aws-sdk/types";
15+
import { ResponseMetadata, Endpoint } from "@aws-sdk/types";
1616

1717
export function executeStatementAwsRestJson1_1Serialize(
1818
input: ExecuteStatementRequest,
19-
utils: SerializerUtils
19+
utils: SerializerUtils & { endpoint: Endpoint }
2020
): HttpRequest {
2121
let body: any = {};
2222
if (input.resourceArn !== undefined) {
@@ -56,6 +56,7 @@ export function executeStatementAwsRestJson1_1Serialize(
5656
}
5757

5858
return new HttpRequest({
59+
...utils.endpoint,
5960
body: JSON.stringify(body),
6061
path: "/Execute",
6162
method: "POST",

0 commit comments

Comments
 (0)