Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add pluggable runtime specific config #404

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"editor.tabSize": 2,
"editor.formatOnSave": true
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
2 changes: 0 additions & 2 deletions clients/node/client-rds-data-node/.npmignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/coverage/
/docs/
*.ts
!*.d.ts
tsconfig.test.json
*.tsbuildinfo
32 changes: 22 additions & 10 deletions clients/node/client-rds-data-node/RDSDataClient.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
import { contentLengthPlugin } from "@aws-sdk/middleware-content-length";
import { userAgentPlugin, UserAgentConfig } from "@aws-sdk/middleware-user-agent";
import {
userAgentPlugin,
UserAgentConfig
} from "@aws-sdk/middleware-user-agent";
import { retryPlugin, RetryConfig } from "@aws-sdk/retry-middleware";
import { awsAuthPlugin, AwsAuthConfiguration } from "@aws-sdk/signing-middleware";
import {
awsAuthPlugin,
AwsAuthConfiguration
} from "@aws-sdk/signing-middleware";
import {
RDSDataConfiguration,
RDSDataResolvedConfiguration,
RDSRuntimeConfiguration
RDSDataResolvedConfiguration
} from "./RDSDataConfiguration";
import { RegionConfiguration, EndpointsConfig, ProtocolConfig } from '@aws-sdk/config-resolver';
import { HttpOptions, MetadataBearer } from '@aws-sdk/types';
import { RDSRuntimeConfiguration } from "./runtimeConfig";
import {
RegionConfiguration,
EndpointsConfig,
ProtocolConfig
} from "@aws-sdk/config-resolver";
import { HttpOptions, MetadataBearer } from "@aws-sdk/types";
import { Client as SmithyClient } from "@aws-sdk/smithy-client";

type InputTypesUnion = any;
type OutputTypesUnion = MetadataBearer;

export class RDSDataClient extends SmithyClient<HttpOptions, InputTypesUnion, OutputTypesUnion> {
export class RDSDataClient extends SmithyClient<
HttpOptions,
InputTypesUnion,
OutputTypesUnion
> {
readonly config: RDSDataResolvedConfiguration;

constructor(configuration: RDSDataConfiguration) {
Expand All @@ -36,9 +50,7 @@ export class RDSDataClient extends SmithyClient<HttpOptions, InputTypesUnion, Ou
}

destroy(): void {
if (
typeof this.config.httpHandler.destroy === 'function'
) {
if (typeof this.config.httpHandler.destroy === "function") {
this.config.httpHandler.destroy();
}
}
Expand Down
147 changes: 106 additions & 41 deletions clients/node/client-rds-data-node/RDSDataConfiguration.ts
Original file line number Diff line number Diff line change
@@ -1,60 +1,125 @@
import { defaultProvider as credentialDefaultProvider } from "@aws-sdk/credential-provider-node";
import { Hash } from "@aws-sdk/hash-node";
import { NodeHttpHandler } from "@aws-sdk/node-http-handler";
import { defaultProvider as regionDefaultProvider } from "@aws-sdk/region-provider";
import { parseUrl } from "@aws-sdk/url-parser-node";
import { calculateBodyLength } from "@aws-sdk/util-body-length-node";
import { streamCollector } from '@aws-sdk/stream-collector-node';
import { RestJsonProtocol } from "@aws-sdk/protocol-rest-json";
import { fromUtf8, toUtf8 } from '@aws-sdk/util-utf8-node';
import { fromBase64, toBase64 } from '@aws-sdk/util-base64-node';
import { defaultUserAgent } from '@aws-sdk/util-user-agent-node';
import { AwsAuthConfiguration, AwsAuthConfigurationInput } from '@aws-sdk/signing-middleware';
import { UserAgentConfig, UserAgentConfigInput } from '@aws-sdk/middleware-user-agent';
import { RetryConfig, RetryConfigInput } from '@aws-sdk/retry-middleware';
import { name, version } from './package.json';
import {
AwsAuthConfiguration,
AwsAuthConfigurationInput
} from "@aws-sdk/signing-middleware";
import {
UserAgentConfig,
UserAgentConfigInput
} from "@aws-sdk/middleware-user-agent";
import { RetryConfig, RetryConfigInput } from "@aws-sdk/retry-middleware";
import {
RegionConfiguration,
RegionConfigurationInput,
EndpointsConfig,
EndpointsConfigInput,
ProtocolConfig,
ProtocolConfigInput,
AWSClientRuntimeConfiguration
} from '@aws-sdk/config-resolver';

export type AWSClientRuntimeResolvedConfiguration = Required<AWSClientRuntimeConfiguration>;

export const RDSRuntimeConfiguration: AWSClientRuntimeResolvedConfiguration = {
protocolDefaultProvider: (handler) => new RestJsonProtocol(handler),
signingName: "rds-data",
service: "rds-data",
httpHandler: new NodeHttpHandler(),
sha256: Hash.bind(null, "sha256"),
credentialDefaultProvider,
regionDefaultProvider,
urlParser: parseUrl,
bodyLengthChecker: calculateBodyLength,
streamCollector,
base64Decoder: fromBase64,
base64Encoder: toBase64,
utf8Decoder: fromUtf8,
utf8Encoder: toUtf8,
defaultUserAgent: defaultUserAgent(name, version)
ProtocolConfigInput
} from "@aws-sdk/config-resolver";
import {
Credentials,
Provider,
HashConstructor,
UrlParser,
Protocol,
StreamCollector,
Decoder,
Encoder
} from "@aws-sdk/types";
import { HttpHandler, HttpRequest, HttpResponse } from "@aws-sdk/protocol-http";

export interface RDSDataRuntimeDependencies {
/**
* The HTTP handler to use. Fetch in browser and Https in Nodejs
*/
httpHandler?: HttpHandler;

/**
* 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
*/
sha256?: HashConstructor;

/**
* Default credentials provider; Not available in browser runtime
*/
credentialDefaultProvider?: (input: any) => Provider<Credentials>;

/**
* Provider function that return promise of a region string
*/
regionDefaultProvider?: (input: any) => Provider<string>;

/**
* The function that will be used to convert strings into HTTP endpoints
*/
urlParser?: UrlParser;

/**
* A function that can calculate the length of a request body.
*/
bodyLengthChecker?: (body: any) => number | undefined;

/**
* A function that converts a stream into an array of bytes.
*/
streamCollector?: StreamCollector;

/**
* The function that will be used to convert a base64-encoded string to a byte array
*/
base64Decoder?: Decoder;

/**
* The function that will be used to convert binary data to a base64-encoded string
*/
base64Encoder?: Encoder;

/**
* The function that will be used to convert a UTF8-encoded string to a byte array
*/
utf8Decoder?: Decoder;

/**
* The function that will be used to convert binary data to a UTF-8 encoded string
*/
utf8Encoder?: Encoder;

/**
* The function that will be used to populate default value in 'User-Agent' header
*/
defaultUserAgent?: string;

/**
* The function that will be used to populate serializing protocol
*/
protocolDefaultProvider?: (
handler: HttpHandler
) => Protocol<HttpRequest, HttpResponse>;

/**
* The service name with which to sign requests.
*/
signingName?: string;

/**
* The service name with which to construct endpoints.
*/
service?: string;
}

export type RDSDataConfiguration = AWSClientRuntimeConfiguration &
export type RDSDataConfiguration = RDSDataRuntimeDependencies &
AwsAuthConfigurationInput &
RegionConfigurationInput &
RetryConfigInput &
EndpointsConfigInput &
ProtocolConfigInput &
UserAgentConfigInput
UserAgentConfigInput;

export type RDSDataResolvedConfiguration = AWSClientRuntimeResolvedConfiguration &
export type RDSDataResolvedConfiguration = Required<
RDSDataRuntimeDependencies
> &
AwsAuthConfiguration.Resolved &
RegionConfiguration.Resolved &
RetryConfig.Resolved &
EndpointsConfig.Resolved &
ProtocolConfig.Resolved &
UserAgentConfig.Resolved
UserAgentConfig.Resolved;
1 change: 1 addition & 0 deletions clients/node/client-rds-data-node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
## Description

<fullname>Amazon RDS Data Service</fullname>

<p>Amazon RDS provides an HTTP endpoint to run SQL statements on an Amazon Aurora
Serverless DB cluster. To run these statements, you work with the Data Service
API.</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type OutputTypesUnion = any;
export class ExecuteStatementCommand extends Command<
ExecuteStatementRequest,
ExecuteStatementResponse
> {
> {
constructor(readonly input: ExecuteStatementRequest) {
super();
}
Expand All @@ -28,13 +28,18 @@ export class ExecuteStatementCommand extends Command<
clientStack: MiddlewareStack<InputTypesUnion, OutputTypesUnion>,
configuration: RDSDataResolvedConfiguration,
options?: HttpOptions
): Handler<
ExecuteStatementRequest,
ExecuteStatementResponse
> {
const { protocol: { handler } } = configuration;
): Handler<ExecuteStatementRequest, ExecuteStatementResponse> {
const {
protocol: { handler }
} = configuration;

this.use(serdePlugin(configuration, executeStatementSerializer, executeStatementDeserializer));
this.use(
serdePlugin(
configuration,
executeStatementSerializer,
executeStatementDeserializer
)
);

const stack = clientStack.concat(this.middlewareStack);

Expand Down
4 changes: 0 additions & 4 deletions clients/node/client-rds-data-node/index.browser.ts

This file was deleted.

14 changes: 6 additions & 8 deletions clients/node/client-rds-data-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@
"test": "exit 0",
"smoke-test": "npm run pretest && node ./test/smoke/index.spec.js",
"build:es": "tsc -p tsconfig.es.json",
"build:browser": "rollup -c",
trivikr marked this conversation as resolved.
Show resolved Hide resolved
"build": "yarn pretest && yarn build:es && yarn build:browser"
"build": "yarn pretest && yarn build:es"
},
"main": "./index.js",
"main": "./dist/cjs/index.js",
"types": "./types/index.d.ts",
"author": {
"name": "AWS SDK for JavaScript Team",
"url": "https://aws.amazon.com/javascript/"
},
"module": "./dist/es/index.js",
"browser": "./dist/browser/rds-data-browser.js",
"browser": {
"./runtimeConfig": "./runtimeConfig.browser"
},
"sideEffects": false,
"license": "Apache-2.0",
"dependencies": {
Expand All @@ -47,6 +48,7 @@
"@aws-sdk/signature-v4": "^0.1.0-preview.7",
"@aws-sdk/signing-middleware": "^0.1.0-preview.7",
"@aws-sdk/stream-collector-node": "^0.1.0-preview.6",
"@aws-sdk/stream-collector-browser": "^0.1.0-preview.5",
"@aws-sdk/types": "^0.1.0-preview.5",
"@aws-sdk/url-parser-browser": "^0.1.0-preview.5",
"@aws-sdk/url-parser-node": "^0.1.0-preview.5",
Expand All @@ -64,10 +66,6 @@
"@aws-sdk/client-documentation-generator": "^0.1.0-preview.3",
"@types/node": "^10.0.0",
"rimraf": "^2.6.2",
"rollup-plugin-json": "^4.0.0",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-replace": "^2.2.0",
"rollup-plugin-sourcemaps": "^0.4.2",
"typedoc": "^0.14.2",
"typescript": "^3.7.0-dev.20190926"
}
Expand Down
Loading