diff --git a/.vscode/settings.json b/.vscode/settings.json index 00bd60b61f71..de93269a3abf 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,4 +2,4 @@ "editor.tabSize": 2, "editor.formatOnSave": true, "editor.defaultFormatter": "esbenp.prettier-vscode" -} \ No newline at end of file +} diff --git a/clients/node/client-rds-data-node/.npmignore b/clients/node/client-rds-data-node/.npmignore index 826dc842e33d..9bda6bbaa691 100644 --- a/clients/node/client-rds-data-node/.npmignore +++ b/clients/node/client-rds-data-node/.npmignore @@ -1,6 +1,4 @@ /coverage/ /docs/ -*.ts -!*.d.ts tsconfig.test.json *.tsbuildinfo \ No newline at end of file diff --git a/clients/node/client-rds-data-node/RDSDataClient.ts b/clients/node/client-rds-data-node/RDSDataClient.ts index 85c9e5a19101..557826e5cee8 100644 --- a/clients/node/client-rds-data-node/RDSDataClient.ts +++ b/clients/node/client-rds-data-node/RDSDataClient.ts @@ -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 { +export class RDSDataClient extends SmithyClient< + HttpOptions, + InputTypesUnion, + OutputTypesUnion +> { readonly config: RDSDataResolvedConfiguration; constructor(configuration: RDSDataConfiguration) { @@ -36,9 +50,7 @@ export class RDSDataClient extends SmithyClient; - -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; + + /** + * Provider function that return promise of a region string + */ + regionDefaultProvider?: (input: any) => Provider; + + /** + * 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; + + /** + * 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 \ No newline at end of file + UserAgentConfig.Resolved; diff --git a/clients/node/client-rds-data-node/commands/ExecuteStatementCommand.ts b/clients/node/client-rds-data-node/commands/ExecuteStatementCommand.ts index 7cdbdb7e3bcd..ad9f4765b4af 100644 --- a/clients/node/client-rds-data-node/commands/ExecuteStatementCommand.ts +++ b/clients/node/client-rds-data-node/commands/ExecuteStatementCommand.ts @@ -19,7 +19,7 @@ type OutputTypesUnion = any; export class ExecuteStatementCommand extends Command< ExecuteStatementRequest, ExecuteStatementResponse - > { +> { constructor(readonly input: ExecuteStatementRequest) { super(); } @@ -28,13 +28,18 @@ export class ExecuteStatementCommand extends Command< clientStack: MiddlewareStack, configuration: RDSDataResolvedConfiguration, options?: HttpOptions - ): Handler< - ExecuteStatementRequest, - ExecuteStatementResponse - > { - const { protocol: { handler } } = configuration; + ): Handler { + const { + protocol: { handler } + } = configuration; - this.use(serdePlugin(configuration, executeStatementSerializer, executeStatementDeserializer)); + this.use( + serdePlugin( + configuration, + executeStatementSerializer, + executeStatementDeserializer + ) + ); const stack = clientStack.concat(this.middlewareStack); diff --git a/clients/node/client-rds-data-node/index.browser.ts b/clients/node/client-rds-data-node/index.browser.ts deleted file mode 100644 index f9f57b235985..000000000000 --- a/clients/node/client-rds-data-node/index.browser.ts +++ /dev/null @@ -1,4 +0,0 @@ - -export * from "./RDSDataClient"; -export * from "./RDSDataConfiguration"; -export * from "./commands/ExecuteStatementCommand"; \ No newline at end of file diff --git a/clients/node/client-rds-data-node/protocol/AwsRestJson1_1.ts b/clients/node/client-rds-data-node/protocol/AwsRestJson1_1.ts index 8acb3dcaf219..0525aae2260c 100644 --- a/clients/node/client-rds-data-node/protocol/AwsRestJson1_1.ts +++ b/clients/node/client-rds-data-node/protocol/AwsRestJson1_1.ts @@ -12,11 +12,11 @@ import { } from "../models/rdsdataservice"; import { HttpRequest, HttpResponse } from "@aws-sdk/protocol-http"; import { SerializerUtils, DeserializerUtils } from "@aws-sdk/types"; -import { ResponseMetadata } from "@aws-sdk/types"; +import { ResponseMetadata, Endpoint } from "@aws-sdk/types"; export function executeStatementAwsRestJson1_1Serialize( input: ExecuteStatementRequest, - utils: SerializerUtils + utils: SerializerUtils & { endpoint: Endpoint } ): HttpRequest { let body: any = {}; if (input.resourceArn !== undefined) { @@ -40,7 +40,10 @@ export function executeStatementAwsRestJson1_1Serialize( } if (input.parameters !== undefined) { - body.parameters = sqlParameterListAwsRestJson1_1Serialize(input.parameters, utils); + body.parameters = sqlParameterListAwsRestJson1_1Serialize( + input.parameters, + utils + ); } if (input.transactionId !== undefined) { @@ -56,6 +59,7 @@ export function executeStatementAwsRestJson1_1Serialize( } return new HttpRequest({ + ...utils.endpoint, body: JSON.stringify(body), path: "/Execute", method: "POST", @@ -133,16 +137,24 @@ const sqlParameterListAwsRestJson1_1Serialize = ( utils: SerializerUtils ): Array => input && - input.map(sqlParameter => sqlParameterAwsRestJson1_1Serialize(sqlParameter, utils)); + input.map(sqlParameter => + sqlParameterAwsRestJson1_1Serialize(sqlParameter, utils) + ); -const sqlParameterAwsRestJson1_1Serialize = (input: SqlParameter, utils: SerializerUtils): any => +const sqlParameterAwsRestJson1_1Serialize = ( + input: SqlParameter, + utils: SerializerUtils +): any => input.name && input.value && { name: input.name, value: fieldAwsRestJson1_1Serialize(input.value, utils) }; -const fieldAwsRestJson1_1Serialize = (input: Field, utils: SerializerUtils): any => +const fieldAwsRestJson1_1Serialize = ( + input: Field, + utils: SerializerUtils +): any => Field.visit(input, { blobValue: value => { value; @@ -249,7 +261,10 @@ const columnMetadataListAwsRestJson1_1Deserialize = ( columnMetadataAwsRestJson1_1Deserialize(columnMetadata, utils) ); -const fieldAwsRestJson1_1Deserialize = (input: any, utils: DeserializerUtils): any => +const fieldAwsRestJson1_1Deserialize = ( + input: any, + utils: DeserializerUtils +): any => Field.visit(input, { blobValue: value => { value; @@ -280,19 +295,33 @@ const fieldAwsRestJson1_1Deserialize = (input: any, utils: DeserializerUtils): a } }); -const generatedFieldsAwsRestJson1_1Deserialize = (input: any, utils: DeserializerUtils): Array => - input && input.map((field: any) => fieldAwsRestJson1_1Deserialize(field, utils)); +const generatedFieldsAwsRestJson1_1Deserialize = ( + input: any, + utils: DeserializerUtils +): Array => + input && + input.map((field: any) => fieldAwsRestJson1_1Deserialize(field, utils)); -const recordsAwsRestJson1_1Deserialize = (input: any, utils: DeserializerUtils): Array> => +const recordsAwsRestJson1_1Deserialize = ( + input: any, + utils: DeserializerUtils +): Array> => input && input.map((recordsList: any) => recordsListAwsRestJson1_1Deserialize(recordsList, utils) ); -const recordsListAwsRestJson1_1Deserialize = (input: any, utils: DeserializerUtils): Array => - input && input.map((field: any) => fieldAwsRestJson1_1Deserialize(field, utils)); +const recordsListAwsRestJson1_1Deserialize = ( + input: any, + utils: DeserializerUtils +): Array => + input && + input.map((field: any) => fieldAwsRestJson1_1Deserialize(field, utils)); -const badRequestExceptionDeserialize = (input: any, utils: DeserializerUtils): BadRequestException => ({ +const badRequestExceptionDeserialize = ( + input: any, + utils: DeserializerUtils +): BadRequestException => ({ __type: "com.amazon.rdsdataservice#BadRequestException", $name: "BadRequestException", $fault: "client", @@ -310,7 +339,10 @@ const statementTimeoutExceptionDeserialize = ( dbConnectionId: input.dbConnectionId }); -const forbiddenExceptionDeserialize = (input: any, utils: DeserializerUtils): ForbiddenException => ({ +const forbiddenExceptionDeserialize = ( + input: any, + utils: DeserializerUtils +): ForbiddenException => ({ __type: "com.amazon.rdsdataservice#ForbiddenException", $name: "ForbiddenException", $fault: "client", diff --git a/clients/node/client-rds-data-node/protocol/ExecuteStatement.ts b/clients/node/client-rds-data-node/protocol/ExecuteStatement.ts index 804b2115e99a..498067f87428 100644 --- a/clients/node/client-rds-data-node/protocol/ExecuteStatement.ts +++ b/clients/node/client-rds-data-node/protocol/ExecuteStatement.ts @@ -33,4 +33,4 @@ export async function executeStatementDeserializer( default: throw new Error("Unknown protocol, use aws.rest-json-1.1"); } -} \ No newline at end of file +} diff --git a/clients/node/client-rds-data-node/rollup.config.js b/clients/node/client-rds-data-node/rollup.config.js deleted file mode 100644 index d305c9009c4d..000000000000 --- a/clients/node/client-rds-data-node/rollup.config.js +++ /dev/null @@ -1,145 +0,0 @@ -import sourcemaps from "rollup-plugin-sourcemaps"; -import replace from "rollup-plugin-replace"; -import resolve from "rollup-plugin-node-resolve"; -import importJson from "rollup-plugin-json"; - -const pkg = require("./package.json"); -const depNames = Object.keys(pkg.dependencies); - -export function browserConfig(test = false, production = false) { - const baseConfig = { - input: "dist/es/index.browser.js", - output: { - file: "dist/browser/rds-data-browser.js", - format: "esm", - sourcemap: true - }, - preserveSymlinks: false, - external: [...depNames], - plugins: [ - replace(dependencyReplacement.base64), - replace(dependencyReplacement.bodyLengthChecker), - replace(dependencyReplacement.credentialProvider), - replace(dependencyReplacement.httpHandler), - replace(dependencyReplacement.regionProvider), - replace(dependencyReplacement.sha256), - replace(dependencyReplacement.streamCollector), - replace(dependencyReplacement.urlParser), - replace(dependencyReplacement.userAgent), - replace(dependencyReplacement.utf8), - importJson(), - resolve(), - sourcemaps() - ] - }; - - return baseConfig; -} - -export const ReplaceLocations = { - CLIENT: "dist/es/*Client.js", - CONFIGURATION: "dist/es/*Configuration.js", -} - -export const dependencyReplacement = { - userAgent: { - include: [ReplaceLocations.CLIENT], - delimiters: ["", ""], - values: { - 'import * as __aws_sdk_util_user_agent_node from "@aws-sdk/util-user-agent-node"': - 'import * as __aws_sdk_util_user_agent_browser from "@aws-sdk/util-user-agent-browser"', - '"User-Agent": __aws_sdk_util_user_agent_node': - '"User-Agent": __aws_sdk_util_user_agent_browser' - } - }, - utf8: { - include: [ReplaceLocations.CONFIGURATION], - delimiters: ["", ""], - values: { - 'import * as __aws_sdk_util_utf8_node from "@aws-sdk/util-utf8-node";': 'import * as __aws_sdk_util_utf8_browser from "@aws-sdk/util-utf8-browser"', - 'defaultValue: __aws_sdk_util_utf8_node': - 'defaultValue: __aws_sdk_util_utf8_browser', - } - }, - regionProvider: { - include: [ReplaceLocations.CONFIGURATION], - delimiters: ["", ""], - values: { - 'import * as __aws_sdk_region_provider from "@aws-sdk/region-provider"': '', - 'defaultProvider: __aws_sdk_region_provider': - 'defaultProvider: {defaultProvider: __aws_sdk_invalid_dependency.invalidFunction("Credentials is required")}', - } - }, - urlParser: { - include: [ReplaceLocations.CONFIGURATION], - delimiters: ["", ""], - values: { - 'import * as __aws_sdk_url_parser_node from "@aws-sdk/url-parser-node"': - 'import * as __aws_sdk_url_parser_browser from "@aws-sdk/url-parser-browser"', - "defaultValue: __aws_sdk_url_parser_node": - "defaultValue: __aws_sdk_url_parser_browser" - } - }, - streamCollector: { - include: [ReplaceLocations.CONFIGURATION], - delimiters: ["", ""], - values: { - 'import * as __aws_sdk_stream_collector_node from "@aws-sdk/stream-collector-node"': - 'import * as __aws_sdk_stream_collector_browser from "@aws-sdk/stream-collector-browser"', - "defaultValue: __aws_sdk_stream_collector_node.streamCollector": - "defaultValue: __aws_sdk_stream_collector_browser.streamCollector" - } - }, - base64: { - include: [ReplaceLocations.CONFIGURATION], - delimiters: ["", ""], - values: { - 'import * as __aws_sdk_util_base64_node from "@aws-sdk/util-base64-node"': - 'import * as __aws_sdk_util_base64_browser from "@aws-sdk/util-base64-browser"', - "defaultValue: __aws_sdk_util_base64_node": - "defaultValue: __aws_sdk_util_base64_browser" - } - }, - bodyLengthChecker: { - include: [ReplaceLocations.CONFIGURATION], - delimiters: ["", ""], - values: { - 'import * as __aws_sdk_util_body_length_node from "@aws-sdk/util-body-length-node"': - 'import * as __aws_sdk_util_body_length_browser from "@aws-sdk/util-body-length-browser"', - "defaultValue: __aws_sdk_util_body_length_node": - "defaultValue: __aws_sdk_util_body_length_browser" - } - }, - sha256: { - include: [ReplaceLocations.CONFIGURATION], - delimiters: ["", ""], - values: { - 'import * as __aws_sdk_hash_node from "@aws-sdk/hash-node"': - 'import * as __aws_crypto_sha256_browser from "@aws-crypto/sha256-browser"', - 'defaultValue: __aws_sdk_hash_node.Hash.bind(null, "sha256")': - "defaultValue: __aws_crypto_sha256_browser.Sha256" - } - }, - credentialProvider: { - include: [ReplaceLocations.CONFIGURATION], - delimiters: ["", ""], - values: { - 'import * as __aws_sdk_credential_provider_node from "@aws-sdk/credential-provider-node"': - 'import * as __aws_sdk_invalid_dependency from "@aws-sdk/invalid-dependency"', - "__aws_sdk_credential_provider_node.defaultProvider": - "__aws_sdk_invalid_dependency.invalidFunction('Credentials is required')" - } - }, - httpHandler: { - include: [ReplaceLocations.CONFIGURATION], - delimiters: ["", ""], - values: { - 'from "@aws-sdk/node-http-handler"': - "from '@aws-sdk/fetch-http-handler'", - "__aws_sdk_http_handler.NodeHttpHandler(configuration)": - "__aws_sdk_http_handler.FetchHttpHandler(configuration)" - } - } -} - -export default browserConfig(false, false); \ No newline at end of file diff --git a/clients/node/client-rds-data-node/runtimeConfig.browser.ts b/clients/node/client-rds-data-node/runtimeConfig.browser.ts new file mode 100644 index 000000000000..1b0b420a864b --- /dev/null +++ b/clients/node/client-rds-data-node/runtimeConfig.browser.ts @@ -0,0 +1,30 @@ +import { invalidFunction } from "@aws-sdk/invalid-dependency"; +import { Sha256 } from "@aws-crypto/sha256-browser"; +import { FetchHttpHandler } from "@aws-sdk/fetch-http-handler"; +import { parseUrl } from "@aws-sdk/url-parser-browser"; +import { calculateBodyLength } from "@aws-sdk/util-body-length-browser"; +import { streamCollector } from "@aws-sdk/stream-collector-browser"; +import { RestJsonProtocol } from "@aws-sdk/protocol-rest-json"; +import { fromUtf8, toUtf8 } from "@aws-sdk/util-utf8-browser"; +import { fromBase64, toBase64 } from "@aws-sdk/util-base64-browser"; +import { defaultUserAgent } from "@aws-sdk/util-user-agent-browser"; +import { name, version } from "./package.json"; +import { RDSDataRuntimeDependencies } from "./RDSDataConfiguration"; + +export const RDSRuntimeConfiguration: Required = { + protocolDefaultProvider: handler => new RestJsonProtocol(handler), + signingName: "rds-data", + service: "rds-data", + httpHandler: new FetchHttpHandler(), + sha256: Sha256, + credentialDefaultProvider: invalidFunction("Credential is missing") as any, + regionDefaultProvider: invalidFunction("Region is missing") as any, + urlParser: parseUrl, + bodyLengthChecker: calculateBodyLength, + streamCollector, + base64Decoder: fromBase64, + base64Encoder: toBase64, + utf8Decoder: fromUtf8, + utf8Encoder: toUtf8, + defaultUserAgent: defaultUserAgent(name, version) +}; diff --git a/clients/node/client-rds-data-node/runtimeConfig.ts b/clients/node/client-rds-data-node/runtimeConfig.ts new file mode 100644 index 000000000000..670cd8ebe69d --- /dev/null +++ b/clients/node/client-rds-data-node/runtimeConfig.ts @@ -0,0 +1,31 @@ +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 { name, version } from "./package.json"; +import { RDSDataRuntimeDependencies } from "./RDSDataConfiguration"; + +export const RDSRuntimeConfiguration: Required = { + 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) +}; diff --git a/clients/node/client-rds-data-node/tsconfig.es.json b/clients/node/client-rds-data-node/tsconfig.es.json index 7692b3069926..60e5ef3e90cd 100644 --- a/clients/node/client-rds-data-node/tsconfig.es.json +++ b/clients/node/client-rds-data-node/tsconfig.es.json @@ -15,4 +15,4 @@ ], "outDir": "dist/es" } -} \ No newline at end of file +} diff --git a/clients/node/client-rds-data-node/tsconfig.json b/clients/node/client-rds-data-node/tsconfig.json index f67fed3509bc..d0d1a7e6f04f 100644 --- a/clients/node/client-rds-data-node/tsconfig.json +++ b/clients/node/client-rds-data-node/tsconfig.json @@ -1,5 +1,6 @@ { "compilerOptions": { + "alwaysStrict": true, "target": "es2017", "module": "commonjs", "declaration": true, @@ -10,7 +11,9 @@ "noEmitHelpers": true, "incremental": true, "resolveJsonModule": true, - "declarationDir": "./types" + "noUnusedLocals": true, + "declarationDir": "./types", + "outDir": "dist/cjs" }, "typedocOptions": { "exclude": "**/node_modules/**", @@ -22,4 +25,4 @@ "out": "./docs", "plugin": "@aws-sdk/client-documentation-generator" } -} \ No newline at end of file +} diff --git a/packages/config-resolver/src/EndpointsConfig.ts b/packages/config-resolver/src/EndpointsConfig.ts new file mode 100644 index 000000000000..79157e40835e --- /dev/null +++ b/packages/config-resolver/src/EndpointsConfig.ts @@ -0,0 +1,64 @@ +import { Provider, UrlParser, Endpoint } from "@aws-sdk/types"; + +export function normalizeEndpoint( + endpoint?: string | Endpoint | Provider, + urlParser?: UrlParser +): Provider { + if (typeof endpoint === "string") { + const promisified = Promise.resolve(urlParser!(endpoint)); + return () => promisified; + } else if (typeof endpoint === "object") { + const promisified = Promise.resolve(endpoint); + return () => promisified; + } + return endpoint!; +} + +export namespace EndpointsConfig { + export interface Input { + /** + * 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). + */ + endpoint?: string | Endpoint | Provider; + + /** + * The endpoint provider to call if no endpoint is provided + */ + endpointProvider?: any; + + /** + * Whether TLS is enabled for requests. + */ + tls?: boolean; + } + interface PreviouslyResolved { + urlParser: UrlParser; + region: Provider; + service: string; + } + export interface Resolved extends Required { + endpoint: Provider; + } + export function resolve( + input: T & Input & PreviouslyResolved + ): T & Resolved { + const tls = input.tls || true; + const defaultProvider = (tls: boolean, region: string) => ({ + protocol: tls ? "https:" : "http:", + path: "/", + hostname: `${input.service}.${region}.amazonaws.com` + }); + const endpointProvider = input.endpointProvider || defaultProvider; + let endpoint: Provider = input.endpoint + ? normalizeEndpoint(input.endpoint, input.urlParser) + : () => input.region().then(region => endpointProvider(tls, region)); + return { + ...input, + endpointProvider, + endpoint, + tls + }; + } +} +//export separately for showing comment block in Intellisense +export type EndpointsConfigInput = EndpointsConfig.Input; diff --git a/packages/config-resolver/src/ProtocolConfig.ts b/packages/config-resolver/src/ProtocolConfig.ts new file mode 100644 index 000000000000..3851ecf3ddd7 --- /dev/null +++ b/packages/config-resolver/src/ProtocolConfig.ts @@ -0,0 +1,29 @@ +import { Protocol, HttpOptions } from "@aws-sdk/types"; +import { HttpHandler, HttpRequest, HttpResponse } from "@aws-sdk/protocol-http"; + +export namespace ProtocolConfig { + export interface Input { + /** + * The serializing protocol to used in request + */ + protocol?: Protocol; + } + interface PreviouslyResolved { + httpHandler: HttpHandler; + protocolDefaultProvider: ( + handler: HttpHandler + ) => Protocol; + } + export type Resolved = Required; + export function resolve( + input: T & Input & PreviouslyResolved + ): T & Resolved { + return { + ...input, + protocol: + input.protocol || input.protocolDefaultProvider(input.httpHandler) + }; + } +} +//export separately for showing comment block in Intellisense +export type ProtocolConfigInput = ProtocolConfig.Input; diff --git a/packages/config-resolver/src/RegionConfig.ts b/packages/config-resolver/src/RegionConfig.ts new file mode 100644 index 000000000000..67be54fd208c --- /dev/null +++ b/packages/config-resolver/src/RegionConfig.ts @@ -0,0 +1,35 @@ +import { Provider } from "@aws-sdk/types"; + +export namespace RegionConfiguration { + export interface Input { + /** + * The AWS region to which this client will send requests + */ + region?: string | Provider; + } + interface PreviouslyResolved { + regionDefaultProvider: (input: any) => Provider; + } + export interface Resolved { + region: Provider; + } + export function resolve( + input: T & Input & PreviouslyResolved + ): T & Resolved { + let region = input.region || input.regionDefaultProvider(input as any); + return { + ...input, + region: normalizeRegion(region) + }; + } +} +//export separately for showing comment block in Intellisense +export type RegionConfigurationInput = RegionConfiguration.Input; + +function normalizeRegion(region: string | Provider): Provider { + if (typeof region === "string") { + const promisified = Promise.resolve(region); + return () => promisified; + } + return region as Provider; +} diff --git a/packages/config-resolver/src/components.ts b/packages/config-resolver/src/components.ts deleted file mode 100644 index 97052e2b54b8..000000000000 --- a/packages/config-resolver/src/components.ts +++ /dev/null @@ -1,222 +0,0 @@ -import { - Credentials, - Provider, - HashConstructor, - UrlParser, - Protocol, - HttpOptions, - StreamCollector, - Decoder, - Encoder -} from "@aws-sdk/types"; -import { - HttpEndpoint, - HttpHandler, - HttpRequest, - HttpResponse -} from "@aws-sdk/protocol-http"; - -export interface RuntimeDependencies { - /** - * 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; - - /** - * Provider function that return promise of a region string - */ - regionDefaultProvider?: (input: any) => Provider; - - /** - * 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; -} - -export interface AWSClientRuntimeConfiguration extends RuntimeDependencies { - /** - * The function that will be used to populate serializing protocol - */ - protocolDefaultProvider?: ( - handler: HttpHandler - ) => Protocol; - - /** - * The service name with which to sign requests. - */ - signingName?: string; - - /** - * The service name with which to construct endpoints. - */ - service?: string; -} - -export function normalizeProvider(input: T | Provider): Provider { - if (typeof input === "object") { - const promisified = Promise.resolve(input); - return () => promisified; - } - return input as Provider; -} - -export function normalizeEndpoint( - endpoint?: string | HttpEndpoint | Provider, - urlParser?: UrlParser -): Provider { - if (typeof endpoint === "string") { - const promisified = Promise.resolve(urlParser!(endpoint)); - return () => promisified; - } else if (typeof endpoint === "object") { - const promisified = Promise.resolve(endpoint); - return () => promisified; - } - return endpoint!; -} - -export namespace RegionConfiguration { - export interface Input { - /** - * The AWS region to which this client will send requests - */ - region?: string | Provider; - } - interface PreviouslyResolved { - regionDefaultProvider: (input: any) => Provider; - } - export interface Resolved { - region: Provider; - } - export function resolve( - input: T & Input & PreviouslyResolved - ): T & Resolved { - let region = input.region || input.regionDefaultProvider(input as any); - return { - ...input, - region: normalizeProvider(region) - }; - } -} -//export separately for showing comment block in Intellisense -export type RegionConfigurationInput = RegionConfiguration.Input; - -export namespace EndpointsConfig { - export interface Input { - /** - * 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). - */ - endpoint?: string | HttpEndpoint | Provider; - - /** - * The endpoint provider to call if no endpoint is provided - */ - endpointProvider?: any; - - /** - * Whether TLS is enabled for requests. - */ - tls?: boolean; - } - interface PreviouslyResolved { - urlParser: UrlParser; - region: Provider; - service: string; - } - export interface Resolved extends Required { - endpoint: Provider; - } - export function resolve( - input: T & Input & PreviouslyResolved - ): T & Resolved { - const tls = input.tls || true; - const defaultProvider = (tls: boolean, region: string) => ({ - protocol: tls ? "https:" : "http:", - path: "/", - hostname: `${input.service}.${region}.amazonaws.com` - }); - const endpointProvider = input.endpointProvider || defaultProvider; - let endpoint: Provider = input.endpoint - ? normalizeEndpoint(input.endpoint, input.urlParser) - : () => input.region().then(region => endpointProvider(tls, region)); - return { - ...input, - endpointProvider, - endpoint, - tls - }; - } -} -//export separately for showing comment block in Intellisense -export type EndpointsConfigInput = EndpointsConfig.Input; - -export namespace ProtocolConfig { - export interface Input { - /** - * The serializing protocol to used in request - */ - protocol?: Protocol; - } - interface PreviouslyResolved { - httpHandler: HttpHandler; - protocolDefaultProvider: ( - handler: HttpHandler - ) => Protocol; - } - export type Resolved = Required; - export function resolve( - input: T & Input & PreviouslyResolved - ): T & Resolved { - return { - ...input, - protocol: - input.protocol || input.protocolDefaultProvider(input.httpHandler) - }; - } -} -//export separately for showing comment block in Intellisense -export type ProtocolConfigInput = ProtocolConfig.Input; diff --git a/packages/config-resolver/src/index.ts b/packages/config-resolver/src/index.ts index 40b494c5f873..629edb514c01 100644 --- a/packages/config-resolver/src/index.ts +++ b/packages/config-resolver/src/index.ts @@ -1 +1,3 @@ -export * from "./components"; +export * from "./EndpointsConfig"; +export * from "./RegionConfig"; +export * from "./ProtocolConfig"; diff --git a/packages/invalid-dependency/src/index.ts b/packages/invalid-dependency/src/index.ts index cf9d0bb000cb..b86c69139c0d 100644 --- a/packages/invalid-dependency/src/index.ts +++ b/packages/invalid-dependency/src/index.ts @@ -1,3 +1,3 @@ -export function invalidFunction(message: string) { +export const invalidFunction = (message: string) => () => { throw new Error(message); -} +}; diff --git a/packages/middleware-serde/src/serdePlugin.ts b/packages/middleware-serde/src/serdePlugin.ts index 38027c966d53..29556e0b16aa 100644 --- a/packages/middleware-serde/src/serdePlugin.ts +++ b/packages/middleware-serde/src/serdePlugin.ts @@ -4,18 +4,20 @@ import { Injectable, Protocol, MetadataBearer, - MiddlewareStack + MiddlewareStack, + EndpointBearer, + Provider } from "@aws-sdk/types"; import { deserializerMiddleware } from "./deserializerMiddleware"; import { serializerMiddleware } from "./serializerMiddleware"; export function serdePlugin< InputType extends object, - SerializerRuntimeUtils, + SerializerRuntimeUtils extends EndpointBearer, OutputType extends MetadataBearer, DeserializerRuntimeUtils >( - config: SerializerRuntimeUtils & + config: PromisifyEndpoint & DeserializerRuntimeUtils & { protocol: Protocol }, serializer: RequestSerializer, deserializer: ResponseDeserializer @@ -31,3 +33,7 @@ export function serdePlugin< }); }; } + +export type PromisifyEndpoint = { + [K in keyof T]: K extends "endpoint" ? Provider : T[K]; +}; diff --git a/packages/middleware-serde/src/serializerMiddleware.ts b/packages/middleware-serde/src/serializerMiddleware.ts index 72adf4249542..8c0fa1610f65 100644 --- a/packages/middleware-serde/src/serializerMiddleware.ts +++ b/packages/middleware-serde/src/serializerMiddleware.ts @@ -4,15 +4,17 @@ import { SerializeHandlerArguments, SerializeHandlerOutput, SerializeMiddleware, - Protocol + Protocol, + EndpointBearer } from "@aws-sdk/types"; +import { PromisifyEndpoint } from "./serdePlugin"; export function serializerMiddleware< Input extends object, Output extends object, - RuntimeUtils = any + RuntimeUtils extends EndpointBearer >( - options: { protocol: Protocol } & RuntimeUtils, + options: { protocol: Protocol } & PromisifyEndpoint, serializer: RequestSerializer ): SerializeMiddleware { return ( @@ -20,7 +22,15 @@ export function serializerMiddleware< ): SerializeHandler => async ( args: SerializeHandlerArguments ): Promise> => { - const request = options.protocol.serialize(serializer, args.input, options); + const endpointResolvedOptions = { + ...options, + endpoint: await options.endpoint() + }; + const request = options.protocol.serialize( + serializer, + args.input, + endpointResolvedOptions + ); return next({ ...args, request diff --git a/packages/types/src/client.ts b/packages/types/src/client.ts index dbff770e57e4..4bcabc6bef03 100644 --- a/packages/types/src/client.ts +++ b/packages/types/src/client.ts @@ -3,7 +3,7 @@ import { Structure } from "./protocol"; import { Provider, Decoder, Encoder, UrlParser } from "./util"; // import { StreamCollector, ResponseParser } from "./unmarshaller"; import { RequestSerializer } from "./serializer"; -import { HttpEndpoint } from "./http"; +import { Endpoint } from "./http"; import { TransferHandler } from "./transfer"; import { Command } from "./command"; import { MetadataBearer } from "./response"; @@ -77,7 +77,7 @@ export interface ClientResolvedConfigurationBase { sslEnabled?: boolean; urlParser?: UrlParser; endpointProvider?: any; - endpoint?: Provider; + endpoint?: Provider; base64Decoder?: Decoder; base64Encoder?: Encoder; utf8Decoder?: Decoder; diff --git a/packages/types/src/http.ts b/packages/types/src/http.ts index fe190e70d82a..44afa7cec2f9 100644 --- a/packages/types/src/http.ts +++ b/packages/types/src/http.ts @@ -61,7 +61,7 @@ export interface QueryParameterBag { [key: string]: string | Array | null; } -export interface HttpEndpoint { +export interface Endpoint { protocol: string; hostname: string; port?: number; @@ -75,7 +75,7 @@ export interface HttpEndpoint { */ export interface HttpRequest extends HttpMessage, - HttpEndpoint { + Endpoint { method: string; } diff --git a/packages/types/src/serializer.ts b/packages/types/src/serializer.ts index 6b2ffd78f3b8..95480de4dc64 100644 --- a/packages/types/src/serializer.ts +++ b/packages/types/src/serializer.ts @@ -1,14 +1,25 @@ import { Decoder, Encoder } from "./util"; +import { Endpoint } from "./http"; + +/** + * Interface for object requires an Endpoint set. + */ +export interface EndpointBearer { + endpoint: Endpoint; +} /** * Response deserializer util functions for AWS services */ -export interface SerializerUtils { +export interface SerializerUtils extends EndpointBearer { utf8Decoder: Decoder; base64Encoder: Encoder; } -export interface RequestSerializer { +export interface RequestSerializer< + Request, + RuntimeUtils extends EndpointBearer = any +> { /** * Converts the provided `input` into a request object * diff --git a/packages/types/src/util.ts b/packages/types/src/util.ts index 24a3c8232712..7ba9e2a0b69d 100644 --- a/packages/types/src/util.ts +++ b/packages/types/src/util.ts @@ -1,4 +1,4 @@ -import { HttpEndpoint } from "./http"; +import { Endpoint } from "./http"; import { FinalizeHandler, FinalizeHandlerArguments, @@ -77,8 +77,8 @@ export interface RetryStrategy { } /** - * Parses a URL in string form into an HttpEndpoint object. + * Parses a URL in string form into an Endpoint object. */ export interface UrlParser { - (url: string): HttpEndpoint; + (url: string): Endpoint; } diff --git a/packages/url-parser-browser/src/index.spec.ts b/packages/url-parser-browser/src/index.spec.ts index c39a8e1e541a..e9a3ba4c9c03 100644 --- a/packages/url-parser-browser/src/index.spec.ts +++ b/packages/url-parser-browser/src/index.spec.ts @@ -1,8 +1,8 @@ import { parseUrl } from "./"; -import { HttpEndpoint } from "@aws-sdk/types"; +import { Endpoint } from "@aws-sdk/types"; describe("parseUrl", () => { - const testCases = new Map([ + const testCases = new Map([ [ "https://www.example.com/path/to%20the/file.ext?snap=cr%C3%A4ckle&snap=p%C3%B4p&fizz=buzz&quux", { diff --git a/packages/url-parser-browser/src/index.ts b/packages/url-parser-browser/src/index.ts index aae556bf9b01..5c60fd615a39 100644 --- a/packages/url-parser-browser/src/index.ts +++ b/packages/url-parser-browser/src/index.ts @@ -1,7 +1,7 @@ import { parseQueryString } from "@aws-sdk/querystring-parser"; -import { HttpEndpoint, QueryParameterBag, UrlParser } from "@aws-sdk/types"; +import { Endpoint, QueryParameterBag, UrlParser } from "@aws-sdk/types"; -export const parseUrl: UrlParser = (url: string): HttpEndpoint => { +export const parseUrl: UrlParser = (url: string): Endpoint => { const { hostname, pathname, port, protocol, search } = new URL(url); let query: QueryParameterBag | undefined; diff --git a/packages/url-parser-node/src/index.spec.ts b/packages/url-parser-node/src/index.spec.ts index 848e78248b61..82aa6e3d82b5 100644 --- a/packages/url-parser-node/src/index.spec.ts +++ b/packages/url-parser-node/src/index.spec.ts @@ -1,8 +1,8 @@ import { parseUrl } from "./"; -import { HttpEndpoint } from "@aws-sdk/types"; +import { Endpoint } from "@aws-sdk/types"; describe("parseUrl", () => { - const testCases = new Map([ + const testCases = new Map([ [ "https://www.example.com/path/to%20the/file.ext?snap=cr%C3%A4ckle&snap=p%C3%B4p&fizz=buzz&quux", { diff --git a/packages/url-parser-node/src/index.ts b/packages/url-parser-node/src/index.ts index 75c150b2df1c..b4edc5141841 100644 --- a/packages/url-parser-node/src/index.ts +++ b/packages/url-parser-node/src/index.ts @@ -1,8 +1,8 @@ import { parseQueryString } from "@aws-sdk/querystring-parser"; -import { HttpEndpoint, QueryParameterBag, UrlParser } from "@aws-sdk/types"; +import { Endpoint, QueryParameterBag, UrlParser } from "@aws-sdk/types"; import { parse } from "url"; -export const parseUrl: UrlParser = (url: string): HttpEndpoint => { +export const parseUrl: UrlParser = (url: string): Endpoint => { const { hostname = "localhost", pathname = "/", diff --git a/packages/url-parser-universal/src/index.spec.ts b/packages/url-parser-universal/src/index.spec.ts index 848e78248b61..82aa6e3d82b5 100644 --- a/packages/url-parser-universal/src/index.spec.ts +++ b/packages/url-parser-universal/src/index.spec.ts @@ -1,8 +1,8 @@ import { parseUrl } from "./"; -import { HttpEndpoint } from "@aws-sdk/types"; +import { Endpoint } from "@aws-sdk/types"; describe("parseUrl", () => { - const testCases = new Map([ + const testCases = new Map([ [ "https://www.example.com/path/to%20the/file.ext?snap=cr%C3%A4ckle&snap=p%C3%B4p&fizz=buzz&quux", { diff --git a/packages/url-parser-universal/src/index.ts b/packages/url-parser-universal/src/index.ts index a42d18c91845..cfc037678a81 100644 --- a/packages/url-parser-universal/src/index.ts +++ b/packages/url-parser-universal/src/index.ts @@ -1,4 +1,4 @@ -import { HttpEndpoint, QueryParameterBag, UrlParser } from "@aws-sdk/types"; +import { UrlParser } from "@aws-sdk/types"; import { parseUrl as browserUrlParser } from "@aws-sdk/url-parser-browser"; import { parseUrl as nodeUrlParser } from "@aws-sdk/url-parser-node"; diff --git a/yarn.lock b/yarn.lock index 36696f4cd2c5..6cddabf117f9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -123,6 +123,14 @@ "@aws-sdk/xml-body-parser" "^0.1.0-preview.9" tslib "^1.8.0" +"@aws-sdk/middleware-serializer@^0.1.0-preview.7": + version "0.1.0-preview.7" + resolved "https://registry.yarnpkg.com/@aws-sdk/middleware-serializer/-/middleware-serializer-0.1.0-preview.7.tgz#7d4ed3d16b47f12f7ed0762ff9594c0f2da9c96c" + integrity sha512-mc5xBnrdDM9k3a78cbTSw+VWTadpDQQBObSuAy4fCxrkPZa+APqRY+y9MMDQ0uWI80e6Ab1pt9wTx1/OM1uMWQ== + dependencies: + "@aws-sdk/types" "^0.1.0-preview.7" + tslib "^1.8.0" + "@aws-sdk/protocol-json-rpc@^0.1.0-preview.8": version "0.1.0-preview.8" resolved "https://registry.yarnpkg.com/@aws-sdk/protocol-json-rpc/-/protocol-json-rpc-0.1.0-preview.8.tgz#b8d52d4bc930bc946a2e0c44414fd55c1d98bd6d" @@ -9284,7 +9292,7 @@ typescript@3.2.x: resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.2.4.tgz#c585cb952912263d915b462726ce244ba510ef3d" integrity sha512-0RNDbSdEokBeEAkgNbxJ+BLwSManFy9TeXz8uW+48j/xhEXv1ePME60olyzw2XzUqUBNAYFeJadIqAgNqIACwg== -typescript@3.7.0-dev.20190926, typescript@^3.7.0-dev.20190926: +typescript@3.7.0-dev.20190926: version "3.7.0-dev.20190926" resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.7.0-dev.20190926.tgz#2e90fa4e56fad0fddb87e4d837cd33c7e4a55e7c" integrity sha512-uOQij3UHJnzxY/8Kv1kdmvWTjghgbCD0kBOgVGbY7Rni8ER51O8iPMmI4YpanZmaiZbPK6zUaS60b04/2C91bA== @@ -9903,10 +9911,10 @@ yargs@~3.5.4: window-size "0.1.0" wordwrap "0.0.2" -yarn@1.19.1: - version "1.19.1" - resolved "https://registry.yarnpkg.com/yarn/-/yarn-1.19.1.tgz#14b92410dd1ba5bab87a12b4a3d807f4569bea97" - integrity sha512-gBnfbL9rYY05Gt0cjJhs/siqQXHYlZalTjK3nXn2QO20xbkIFPob+LlH44ML47GcR4VU9/2dYck1BWFM0Javxw== +yarn@1.17.3: + version "1.17.3" + resolved "https://registry.yarnpkg.com/yarn/-/yarn-1.17.3.tgz#60e0b77d079eb78e753bb616f7592b51b6a9adce" + integrity sha512-CgA8o7nRZaQvmeF/WBx2FC7f9W/0X59T2IaLYqgMo6637wfp5mMEsM3YXoJtKUspnpmDJKl/gGFhnqS+sON7hA== yauzl@2.4.1: version "2.4.1"